(:toc:) !!Overview The registers of the VDP chip are used to control its operation. Registers $00 and $01 control basic functions of the VDP. Registers $02 to $06 are used to define the lead address of various tables stored in VRAM. The size of these tables are different between the [=TMS9918=] and SMS display [[modes]], so as a result not all of the bits in a bitfield of a particular register are used the same way between modes. Some address bits are taken into account differently by the VDP in Mode 4 when generating addresses for reading table data. Conceptually you can think of the bit being an input to a logic gate gate where the other input is a VRAM address bus bit. On the SMS1 VDP, this gate is like an AND; If the bit is set to 1, the output follows the input. Otherwise the output is forced to 0 at all times; Because of this behaviour, they are referred to as 'mask' bits. On the SMS2 VDP, the gate always gets a 1 from the register, so no addresses get masked off. Registers $07 to $0A are used for various extensions to the [[TMS9918a]] chip upon which the VDP is based. !![[#reg0]]Register $00 - Mode Control No. 1 ||border=1 ||! Bit ||! Code ||!Function (SMS/GG ||!Function (TMS9918a) ||!Recommended value || || 7 || ||Vertical [[scroll(ing)]] lock ||No effect ||Usually @@0@@ || || 6 || ||Horizontal [[scroll(ing)]] lock ||No effect ||Usually @@0@@ || || 5 || ||Hide leftmost 8 pixels ||No effect ||Usually @@1@@ || || 4 || `IE1 ||Enable [[line interrupts]] ||No effect ||Usually @@0@@ || || 3 || EC ||Shift sprites left 8 pixels ||No effect ||Usually @@0@@ || || 2 || M4 ||[[modes|Mode 4 enable]] ||No effect ||Usually @@1@@ || || 1 || M3 ||[[modes|Extra height enable/TMS9918 mode select]] ||Select [[modes|Graphics 2 mode]] ||Usually @@0@@ || || 0 || ||Sync disable ||Enable external video sync ||Always @@0@@ || *Set bit 7 to @@1@@ to make the rightmost eight columns of the screen fixed with vertical [[scroll(ing)]] value 0. Vertically scrolling games can use this to give a fixed status display on the right of the screen. *Set bit 6 to @@1@@ to make the top two rows (16 pixels) fixed with horizontal [[scroll(ing)]] value 0. Horizontally scrolling games can use this to give a fixed status display on the top of the screen. Since this is not shown on the GG screen (in GG mode), it is of no use there. *Bit 5 is used to avoid displaying invalid data when using horizontal [[scrolling]]. Since this is not shown on the GG screen, it is of no use there. Note that because sprite X positions are in the range 0..255, if you display the left column then sprites cannot smoothly scroll off-screen on either the left or right sides of the screen (depending on the value in bit 3). It is also off-screen on most CRTs, and the remaining 248 pixels are centred on a CRT, so it is recommended to always hide it. *Bit 3 is used to allow [[sprites]] to be correctly drawn when their left side is to the left of the screen, when bit 5 is not being used. *Bit 2 enables Mode 4 when set to @@1@@, according to Sega's official documentation. *Bit 1 should also always be set to @@1@@ when using Mode 4, according to Sega's official documentation. *Bit 0 has no effect on the GG. On the [[TMS9918a]] it was used for overlaying external video, hence using it for synchronisation. According to Sega's official documentation, it should always be set to @@0@@. !![[#reg1]]Register $01 - Mode Control No. 2 ||border=1 ||! Bit ||! Code ||!Function (Mode 4) ||!Function (TMS9918a modes) ||!Recommended value || || 7 || ||No effect ||VRAM size select: 1 = 16KB, 0 = 4KB ||Always @@1@@ || || 6 || BLK ||Enable display ||Enable display ||Usually @@0@@ on startup || || 5 || `IE0 ||Enable frame interrupts ||Enable frame interrupts ||Usually @@1@@ || || 4 || M1 ||[[modes|224-line mode]] ||Select [[modes|Text mode]] ||Usually @@0@@ || || 3 || M2 ||[[modes|240-line mode]] ||Select [[modes|Multicolor mode]] ||Usually @@0@@ || || 2 || ||No effect ||No effect ||Always @@0@@ || || 1 || ||[[sprites|Tall (tiled, 8x16) sprites]] ||[[sprites|Large (16x16) sprites]] ||Usually @@0@@ || || 0 || ||[[sprites|Doubled (stretched) sprites]] ||[[sprites|Doubled (stretched) sprites]] || || *Bit 7 should always be set to @@1@@, according to Sega's official documentation. *Bit 4: Extra height modes work only on the SMS 2. Set this bit to @@0@@ for maximum compatibility accross all VDP variants. *Bit 3: Extra height modes work only on the SMS 2. Set this bit to @@0@@ for maximum compatibility accross all VDP variants. *Bit 2, while it doesn't seem to have any effect on either version of the SMS, will break compatibility with the Mega Drive hardware if set. It should always be set to @@0@@, according to Sega's official documentation. *Bit 0: When in mode 4, on the Megadrive, sprites are never doubled. On the SMS1, sprites are always doubled vertically, but only some sprites are doubled horizontally: if N sprites on are a scanline, the first N minus 4 are double-width. Fully works on GG and SMS2. !!Register $02 - [[Tilemap|Name Table]] Base Address ||border=1 ||! VDP type ||! Bits |||||||||||||||| || ||!7||!6||!5||!4||!3||!2||!1||!0|| || [[TMS9918]] || Unused |||||||| [[Tilemap|Name table]] base address |||||||| || [[SMS1]] || Unused |||||||| [[Tilemap|Name table]] base address |||||| Mask bit || || [[SMS2]]/[[GG]] || Unused |||||||| [[Tilemap|Name table]] base address |||||| Unused || !!!Mode 4, 192-line display mode If [[mode(s)]] 4 is used in the 192-line display mode, the [[Tilemap|name table]] base address bits are combined with row/column coordinates to give the VRAM address of the specified name table entry: [@ VRAM address bus layout for name table fetch MSB LSB --bb byyy yyxx xxxw : b= Table base address, y= Row, x= Column ---- -x-- ---- ---- : x= SMS1 Mask bit (bit 0 of register $02) @] The mask bit is ANDed with the high bit of the y coordinate. This leads to [[tilemap mirroring]] with the [[SMS1]] VDP. In a math approach, bits 1-3 of this register are multiplied by $800 to get the base address - for example if bits 1-3 are all set, the address is 7 * $800 = $3800. For the majority of cases, all bits of this register may be set to @@1@@ to give a name table at VRAM address $3800. !!!Mode 4, 224 and 240-line display modes If Mode 4 is used in the 224 or 240-line display mode, only bits 3 and 2 are used to calculate the table address, and an offset of @@$700@@ is added to the address value: ||border=1 ||!Bit 3||!Bit2||!Address|| ||0||0||@@$0700@@|| ||0||1||@@$1700@@|| ||1||0||@@$2700@@|| ||1||1||@@$3700@@|| In a math approach, bits 2-3 of this register are multiplied by $1000 to get the base address and then $700 is added to the total - for example if bits 2-3 are all set, the address is (3 * $1000) + $700 = $3700. For the majority of cases, all bits of this register may be set to @@1@@ to give a name table at VRAM address $3700. !![[#reg3]]Register $03 - Color Table Base Address This register defines the VRAM location of a table which defines foreground/background colours in some [[TMS9918a]] [[modes]]. For Mode 4 on the [[SMS1]] VDP, all bits should be @@1@@ to give normal operation. VRAM address of the corresponding pattern generator (tile): [@ VRAM address bus layout for tile pattern generator fetch MSB LSB --nn nnnn nnny yypp : n= Tile number (0-511) y= Tile line, p= Bitplane select (0-3) --xx xxxx xx-- --0- : x= SMS1 Mask bits (bits 7-0 of register $03), only applied when pp={0,1} @] !![[#reg4]]Register $04 - Pattern Generator Table Base Address This register defines the VRAM location of a table which defines patterns (tiles) in [[TMS9918a]] [[modes]]. For the [[SMS1]] VDP, at least the low three bits should be @@1@@ to give normal operation. VRAM address of the corresponding pattern generator (tile): [@ VRAM address bus layout for tile pattern generator fetch MSB LSB --nn nnnn nnny yypp : n= Tile number (0-511) y= Tile line, p= Bitplane select (0-3) --xx x--- ---- --1- : x= SMS1 Mask bits (bits 2-0 of register $04), only applied when pp={2,3} @] !![[#reg5]]Register $05 - Sprite Attribute Table Base Address ||border=1 ||! VDP type ||! Bits |||||||||||||||| || ||!7||!6||!5||!4||!3||!2||!1||!0|| || [[TMS9918]] || Unused || [[Sprites|Sprite attribute table]] base address |||||||||||||| || [[SMS1]] || Unused || [[Sprites|Sprite attribute table]] base address |||||||||||| Mask bit || || [[SMS2]]/[[GG]] || Unused || [[Sprites|Sprite attribute table]] base address |||||||||||| Unused || In [[mode(s)]] 4, the [[Sprites|sprite attribute table]] base address bits are combined with the [[sprite(s)]] number to give the VRAM address of a given sprite's attributes: [@ VRAM address bus layout for sprite data fetches MSB LSB --bb bbbb 00iii iii : y-coordinate b= Table base --bb bbbb 1iii iii0 : x-coordinate 0/1 = Fixed '0' or '1' bit --bb bbbb 1iii iii1 : tile number i= Sprite number (0-63) ---- ---- x--- ---- : SMS1 Mask bit (bit 0 of register $05) @] The mask bit is `ANDed with the address; thus, the x-coordinates and tile numbers will incorrectly map to the first half of the [[Sprites|sprite attribute table]] if the mask bit is @@0@@. It should therefore always be set to @@1@@. For the majority of cases, all bits of this register may be set to @@1@@ to give a sprite attribute table at VRAM address $3f00. The possible addresses for the sprite attribute table occur every 256 bytes in VRAM, so it could be at an address like @@$0000@@, @@$0100@@, @@$0200@@ ... @@$3d00@@, @@$3e00@@, @@$3f00@@. !![[#reg6]]Register $06 - Sprite Pattern Generator Table Base Address The register bits are: ||border=1 ||! VDP type ||! Bits |||||||||||||||| || ||!7||!6||!5||!4||!3||!2||!1||!0|| || [[TMS9918]] || Unused |||||||||| Sprite pattern generator table base address |||||| || [[SMS1]] || Unused |||||||||| Sprite pattern generator table base address || Mask bits |||| || [[SMS2]]/[[GG]] || Unused |||||||||| Sprite pattern generator table base address || Unused |||| In [[mode(s)]] 4, the sprite pattern generator table base address bit is combined with a [[sprite(s)]]'s tile number to give the VRAM address of the corresponding pattern generator (tile): [@ VRAM address bus layout for sprite pattern generator fetch MSB LSB --bn nnnn nnny yypp : b= Table base address, n= Tile number (0-255) y= Tile line, p= Bitplane select (0-3) ---x x--- ---- ---- : x= SMS1 Mask bits (bits 1,0 of register $06) @] The mask bits are `ANDed with the address, which will have the effect of restricting effective tile set from 255 down to 128 or 64 tiles accordingly. They should therefore always be set to @@1@@. As the sprite pattern generator table base address is determined by Bit 2, sprites can therefore use pattern graphics from either of these two addresses: ||border=1 ||!Bit 2||!Address|| ||0||@@$0000@@|| ||1||@@$2000@@|| If Bit 2 is set and the start address is $2000, this also limits the numer of pattern tiles which can be used for sprites to 192 rather than 256, as the [[Tilemap|Name Table]] and Sprite Attribute Table usually occupy the upper part VRAM from $3800 onwards. !![[#reg7]]Register $07 - Overscan/Backdrop Color In [[modes|mode 4]], this selects the colour to use for the backgrop/overscan area from the sprite [[palette]]. It is thus a 4-bit number, the upper 4 bits having no effect. !![[#reg8]]Register $08 - Background X Scroll All eight bits define the horizontal [[scroll(ing)]] value. !![[#reg9]]Register $09 - Background Y Scroll All eight bits define the vertical [[scroll(ing)]] value. !![[#regA]]Register $0A - Line counter All eight bits define the line counter value used for [[line interrupts]]. !![[#otherregs]]Register $0B-$0F - no effect The VDP is unaffected when register $0B and above are written to. !![[#misc]]Miscellany I recall register $03 and $02 had some other unusual side effects, such as disabling certain bitplanes from being shown. Register $03 affected the X/Y offsets into the name table so you could reduce the name table size from 32x32 down to smaller sizes like 16x16, 4x4, and even non-square dimensions too. Generally speaking register $04 did not function identically to $06 though you think they should. I'll get these tested at some point and update this section accordingly. - [[~Charles MacDonald]] ---- !!References *[[http://www.techno-junk.org/txt/msvdp.txt|Sega Master System VDP documentation]] by [[~Charles MacDonald]] *[[http://www.smspower.org/dev/docs/tms9918a.txt|Texas Instruments TMS9918A VDP: Almost complete description including undocumented features]] by Sean Young