A starting topic is at hand:
The VDP (Video Display Processor) Questions Topic
Welcome to the thread for VDP related questions, if you have a question referring to VDP specifically, then check this thread first to see if your question has already been asked before, if not, then ask away, and we will try our best to explain how and why it works and hopefully answer your question.
The main function of this thread is to provide a record of information regarding the Megadrive/Genesis's VDP, that way should a question arise about the VDP, we'll have the answer already jotted down in a hard format that's easy enough to read.
Do not ask questions that are related to hacking in general, we're trying to keep this directed at VDP only.
Setting the VDP on a Megadrive/Genesis.
The Megadrive/Genesis has a 16-bit processor that can perform 32-bit operations, this allows us to move a long-word of data to the VDP ports, the VDP ports are mapped to the MC68 memory map location from 00C00000 to 00C00007, 00C00000 to 00C00003 is the "VDP Data Port" (Long-word) and 00C00004 to 00C00007 is the "VDP Address Port" (Long-word).
The VDP has it's own memory map space for V-Ram, this opens up a lot of memory map space for the MC68000 for other operations (Mainly for devices that may be used for the Megadrive/Genesis). What this means is that if we want to move data to the VDP's ram space, we need to tell the VDP, where we're moving the data to, and what that data is.
We start with a long-word of data, this will be moved to the "VDP Address Port" (00C00004):
The hyphen character (a.k.a. " - ") will be used to represent null bits (In other words, if you see the " - " character, it means " 0 ")
40000000 as an example.
Now to understand exactly how this works, we need to break the long-word up into bits:
RRAA AAAA AAAA AAAA ---- ---- RRRR --AA
The - are to remain blank (0), first let's look at the A's:
--DC BA98 7654 3210 ---- ---- ---- --FE
The A's are the "Address" or the location where we're dumping or reading the data in V-Ram, arrange them:
FEDC BA98 7654 3210
Then read in hex insted of bits and you have the V-Ram location you want to write to or read from, let's now look at the R's:
10-- ---- ---- ---- ---- ---- 5432 ----
Each R number represents the code/settings for the VDP, it tells the VDP what it's doing with the location:
If all R's are 0, then V-Ram read mode is set.
If R's 1 to 5 are 0, but R 0 is 1, then V-Ram write mode is set.
If R's 0, 1, 2, 4 and 5 are 0, but R 3 is 1, then C-Ram read mode is set.
If R's 2 to 5 are 0, but R's 0 and 1 are 1, then C-Ram write mode is set.
If R's 0, 1, 3, 4 and 5 are 0, but R 2 is 1, then VS-Ram read mode is set.
If R's 1, 3, 4 and 5 are 0, but R's 0 and 2 are 1, then VS-Ram write mode is set.
V-Ram (Video) read mode, the data in V-Ram at location "AAAA AAAA AAAA AAAA" will be present in "00C00000".
V-Ram (Video) write mode, the data you move to "00C00000" will be moved to location "AAAA AAAA AAAA AAAA" in V-Ram.
C-Ram (Colour) read mode, the data in C-Ram at location "AAAA AAAA AAAA AAAA" will be present in "00C00000".
C-Ram (Colour) write mode, the data you move to "00C00000" will be moved to location "AAAA AAAA AAAA AAAA" in C-Ram.
VS-Ram (Vertical Scroll) read mode, the data in VS-Ram at location "AAAA AAAA AAAA AAAA" will be present in "00C00000".
VS-Ram (Vertical Scroll) write mode, the data you move to "00C00000" will be moved to location "AAAA AAAA AAAA AAAA" in VS-Ram.
And that is the basic principle, so let's say I want to mode art to V-Ram location F000:
F000 = 1111 0000 0000 0000 (a.k.a. "AAAA AAAA AAAA AAAA").
Arrange it correctly:
--11 0000 0000 0000 ---- ---- ---- --11
Now we need to set V-Ram write mode, so R's 1 to 5 will be set 0 and R 0 will be set 1:
01-- ---- ---- ---- ---- ---- 0000 ----
Put the location and settings together:
0111 0000 0000 0000 ---- ---- 0000 --11
Convert to hexadecimal:
And there's the value to move to the "VDP Address Port" (00C00004):
Next, move your data (word or long-word at a time) to "00C00000", though make sure register 8F of the VDP is set auto increment (Which in Sonic games it usually already is set so no need to worry).