Discussion about software development for the old-school Gameboys, ranging from the "Gray brick" to Gameboy Color
(Launched in 2008)
You are not logged in.
about the dma Transfer time
the pandocs say it's about 200ms. how to calculate it?
FF46 - DMA - DMA Transfer and Start Address (W)
Writing to this register launches a DMA transfer from ROM or RAM to OAM memory (sprite attribute table). The written value specifies the transfer source address divided by 100h, ie. source & destination are:
Source: XX00-XX9F ;XX in range from 00-F1h
Destination: FE00-FE9F
It takes 160 microseconds until the transfer has completed (80 microseconds in CGB Double Speed Mode), during this time the CPU can access only HRAM (memory at FF80-FFFE). For this reason, the programmer must copy a short procedure into HRAM, and use this procedure to start the transfer from inside HRAM, and wait until the transfer has finished:
ld (0FF46h),a ;start DMA transfer, a=start address/100h
ld a,28h ;delay...
wait: ;total 5x40 cycles, approx 200ms
dec a ;1 cycle
jr nz,wait ;4 cycles
Most programs are executing this procedure from inside of their VBlank procedure, but it is possible to execute it during display redraw also, allowing to display more than 40 sprites on the screen (ie. for example 40 sprites in upper half, and other 40 sprites in lower half of the screen).
Offline
Yes, it's possible to perform an OAM DMA mid-frame.
- Sprites will be invisible for the duration of the OAM DMA
- The OAM copy will correctly go through
If you know how to convert from and to hexadecimal you'll know that OAM spans $FE00-$FE9F -> it's $A0 bytes long: 10 * 16 = 160.
That oddly corresponds to the 160 microseconds delay! Because the OAM DMA copies one byte per microsecond.
By the way, since the CPU runs at 1 MHz, 1 CPU cycle lasts 1 microsecond (this is not a coincidence, either).
tl;dr: the OAM DMA lasts for 160 CPU cycles.
Offline