Research / Megadrive Programming / DMA
What's DMA? DMA stands for Direct Memory Access. There are 3 types of
DMA: 68k memory to VDP memory copy, VDP memory to VDP memory copy, VDP
68k to VDP copy
It's used to copy data from 68000 memory (meaning ROM, SRAM, RAM etc.,
all 68k memory =P) to VDP memory (Video RAM, Vertical Scroll RAM or
Color RAM). Remember to set the auto increment register ($F) to $2
before doing this. First, you need to specify the DMA length using
registers $13 and $14:
$13: L07 L06 L05 L04 L03 L02 L01 L00
Length = number of bytes transferred / 2 (or >>1)
Next, you need to specify the source address (in 68k). Here's how you should set registers $15-$17:
$15: S08 S07 S06 S05 S04 S03 S02 S01
The source address is also shifted to the right by one (divided by 2).
Now, to begin the DMA, you write a longword command to the control port:
Bits 31-24: CD1 CD0 A13 A12 A11 A10 A09 A08
A15-A00 is the destination address in VRAM, VSRAM or CRAM.
001 - VRAM
011 - CRAM
101 - VSRAM
After doing the above, the DMA will start and until it's done, 68000 will be frozen. For the lazy, the code:
;length = length (original, not shifted)
If you're too lazy to even do that, use the calculator...
This DMA is used to copy VRAM to VRAM.
Note: auto increment register ($F) has to be set to $01 before the DMA.
Register $14 contains the higher 8 bits of fill length (shifted by one
to the right), register $13 contains the lower 8 bits. Registers $16
and $15 are the source address in VRAM. Register $17 has to be set to
$C0. The DMA is started when this command is written to the
Bits 31-24: 0 0 A13 A12 A11 A10 A09 A08
A15-A00 - Destination address in VRAM
The code for the lazy:
If you dreamed about filling VRAM with a random word, VRAM fill is for you. It fills VRAM with a specified byte:
Registers $14, $13 - how many bytes to fill
Register $17 - #$80
Register $F - #$01
After setting the registers, you have to write a command to the VDP:
Bits 31-24: 0 1 A13 A12 A11 A10 A09 A08
A15-A00 - the address in VRAM where the fill will start
Finally, you have to write a word to the data port ($C00000). First byte is the byte that will be copied everywhere, the
other byte is written to the address (only once).
That's all folks. If you have problems with calculating all the stuff, use the calculator.
Back | Printer friendly
<< 5. VDP | 7. VDP programming calculator >>