VDP command reference
Set register
Writing to a VDP register is done by writing a 16-bit value (a single
word) to $C00004
(VdpCtrl
) with this format:
$8000
OR
(register << 8) OR
value
For a full list of registers and their values, check the VDP register reference.
Setting a VDP register will unset the current address, so if you need to keep writing or reading video memory then you'll need to set the address again.
Set write address
To write to video memory you need to write a 32-bit value to $C00004
(VdpCtrl
), either as a longword or two
separate words. Bits 13-10 of the address are placed in the high word,
bits 15-14 are placed in the low word's bits 1-0:
((address AND $3FFF
) << 16) OR
((address AND $C000
) >> 14) OR
command
The command is one of the following:
Memory space | OR with |
---|---|
Write VRAM address | $40000000
|
Write CRAM address | $C0000000
|
Write VSRAM address | $40000010
|
After that, you can write the data to $C00000
(VdpData
), either words or longwords (the latter are seen as
two words). After every word written the address is automatically
incremented by the autoincrement amount.
Iwis says
In the case of 128KB VRAM mode (on machines that support it, e.g. Teradrive) bits 16-14 of the address are in the low word's bits 2-0 (as would be expected). Everything else is identical.
Set read address
Reading from video memory is similar to writing, the main difference is the command:
Memory space | OR with |
---|---|
Read VRAM address | $00000000
|
Read CRAM address | $00000020
|
Read VSRAM address | $00000010
|
After that, you can read the data from $C00000
(VdpData
), either words or longwords (the latter are seen as
two words). After every word read the address is automatically
incremented by the autoincrement amount.
Start DMA
Again, setting the DMA destination address is similar to setting up an address for writing, with the only difference being the command used (in fact, they're the same aside from setting bit 7 of the command's second word):
Memory space | OR with |
---|---|
DMA to VRAM address | $40000080
|
DMA to CRAM address | $C0000080
|
DMA to VSRAM address | $40000090
|
In the case of DMA transfer or DMA copy, the operation will start
immediately after writing this value. In the case of DMA fill, you need
to write the fill value to $C00000
(VdpData
)
after this to initiate the DMA fill.