VDP - Video Display ProcessorOverviewThe VDP contains all the circuitry
necessary to generate the video display. It appears to the Z80 as two
I/O ports called the Data Port and the Command Port. Although the VDP
has its own 16 KB of VRAM (Video RAM), the contents of which define the
screen image, this cannot be directly accessed by the Z80. Instead it
must use the two I/O ports to modify the VRAM and to set the various VDP
operating conditions.
The VDP uses a 10.738MHz crystal. It
generates all required internatl clock signal. The CPU clock is supplied
by the VDP and is obtained by dividing the 10.738MHz clock by 3. Video Display ModesThe VDP displays an image on the screen
that can best be envisioned as a set of display planes sandwiched
together. Objects on planes closest to the viewer have higher priority.
In case where two entities on two different planes are occupying the
same spot on the screen, the entity on the higher priority plane will
show at that point. For an entity on a specific plane to show through,
all planes in front of that plane must be transparent at that point.
Data portThe Data Port is used to read or write
single bytes to the VRAM. The VDP possesses an internal address register
pointing to a location in the VRAM. Reading the Data Port will input the
byte from this VRAM location while writing to the Data Port will store a
byte there. After a read or write the address register is automatically
incremented to point to the next VRAM location. Sequential bytes can be
accessed simply by continuous reads or writes to the Data Port. Command portThe Command Port is used for three purposes:
|
Bit | Name | Description |
0 | EV | The External VDP bit determines whether external VDP input is to be enabled or disabled: 0=Disabled, 1=Enabled. |
1 | M3 | The M3 bit is one of the three VDP mode selection bits, see Register 1. |
2-7 | Not used |
Bit | Name | Description |
0 | MAG | The Magnification bit determines whether sprites will be normal or doubled in size: 0=Normal, 1=Doubled. |
1 | SIZE | The Size bit determines whether each sprite pattern will be 8x8 bits or 16x16 bits: 0=8x8, 1=16x16. |
2 | Not used | |
3 | M2 | The M2 bit is one of the three VDP mode selection bits, see Mode Register 1. |
4 | M1 | The M1 bit is one of the three VDP mode selection bits, see Mode Register 1. |
5 | IE | The Interrupt Enable bit enables or disables the interrupt output signal from the VDP: 0=Disable, 1=Enable. |
6 | Blank | The Blank bit is used to enable or disable the entire video display: 0=Disable, 1=Enable. When the display is blanked it will be the same Color as the border. |
7 | 4/16K | The 4/16K bit alters the VDP VRAM addressing characteristics to suit either 4 KB or 16 KB chips: 0=4 KB, 1=16 KB. |
The M1 and M2 bits determine the VDP operating mode in conjunction with the M3 bit from Register 0.
M1 | M2 | M3 | Description | Characters | Pixels | Colors | Sprites | |
0 | 0 | 0 | Text mode (not available on SV-328/318) | 32 x 24 | 16 | Yes | ||
0 | 0 | 1 | Graphics mode | 256 x 192 | 16 | Yes | ||
0 | 1 | 0 | Multicolor mode | 64 x 48 | 16 | Yes | ||
1 | 0 | 0 | Text mode | 40 x 24 | 2 | No |
Bit | Name | Description |
0-4 | PN | Name Table base address |
5-7 | Not used |
Register 2 defines the starting address of
the Name Table in the VDP VRAM. The four available bits only specify
positions 00BB BB00 0000 0000 of the full address so register contents
of 0FH would result in a base address of 3C00H.
This register contains bits 13 through 10 of the pattern name table. You
can calculate the pattern name table address by multiplying the value of
this register by 400H (1024).
Bit | Name | Description |
0-7 | CT | Color Table base address |
Register 3 defines the starting address of
the Color Table in the VDP VRAM. The eight available bits only specify
positions 00BB BBBB BB00 0000 of the full address so register contents
of FFH would result in a base address of 3FC0H. In Graphics Mode only
bit 7 is effective thus offering a base of 0000H or 2000H. Bits 0 to 6
must be 1.
This register contain bits 13 through 6 of the pattern Color table. You
can calculate the pattern Color table address by multiplying the value
of this register by 40h (64). In screen mode 2, this register has a
different function.
Bit | Name | Description |
0-2 | PG | Pattern Generator (Character Pattern) |
3-7 | Not used |
Register 4 defines the starting address of
the Character Pattern Table in the VDP VRAM. The three available bits
only specify positions 00BB B000 0000 0000 of the full address so
register contents of 07H would result in a base address of 3800H. In
Graphics Mode only bit 2 is effective thus offering a base of 0000H or
2000H. Bits 0 and 1 must be 1.
This register contain bits 13 through 11 of the pattern generator table.
You can calculate the pattern table address by multiplying the value of
this register by 200H (512). In screen mode 2, this register has a
different function.
Bit | Name | Description |
0-6 | SA | Sprite Attribute Table base address |
7 | Not used |
Register 5 defines the starting address of
the Sprite Attribute Table in the VDP VRAM. The seven available bits
only specify positions 00BB BBBB B000 0000 of the full address so
register contents of 7FH would result in a base address of 3F80H.
This register contain bits 13 through 7 of the sprite attribute table.
You can calculate the sprite attribute table address by multiplying the
value of this register by 80H (128).
Bit | Name | Description |
0-2 | SG | Sprite Pattern Generator base address |
3-7 | Not used |
Register 6 defines the starting address of
the Sprite Pattern Table in the VDP VRAM. The three available bits only
specify positions 00BB B000 0000 0000 of the full address so register
contents of 07H would result in a base address of 3800H.
This register contain bits 13 through 11 of the sprite pattern generator
table. You can calculate the sprite pattern table address by multiplying
the value of this register by 200h (512).
Bit | Name | Description |
0-3 | BD | Backdrop. Color number of color around screen, and color 0. |
4-7 | TC | Text color. Color of text in screen mode 0. |
The Border Color bits determine the Color
of the region surrounding the active video area in all four VDP modes.
They also determine the Color of all 0 pixels on the screen in 40x24
Text Mode. Note that the border region actually extends across the
entire screen but will only become visible in the active area if the
overlying pixel is transparent.
The Text Color 1 bits determine the Color of all 1 pixels in 40x24 Text
Mode. They have no effect in the other three modes where greater
flexibility is provided through the use of the Color Table. The VDP
Color codes are:
0 Transparent 4 Dark Blue 8 Red 12 Dark Green 1 Black 5 Light Blue 9 Bright Red 13 Magenta 2 Green 6 Dark Red 10 Yellow 14 Grey 3 Light Green 7 Cyan 11 Light Yellow 15 White
The VDP has four operating modes, each one
offering a slightly different set of capabilities. The Graphics Mode is
capable of adequately performing all the functions of the other modes
with only minor reservations.
An added difficulty in using the VDP arises because insufficient
allowance was made in its design for the overscanning used by most
televisions. The resulting loss of
characters at the screen edges has forced all the video-related MSX
software into being based on peculiar screen sizes. PAL machines
normally use only the central thirty-seven characters available in 40x24
Text Mode. Japanese machines, with NTSC (National Television Standards
Committee) video outputs, use the
central thirty-nine characters.
The central element in the VDP, from the programmer's point of view, is
the Name Table. This is a simple list of single- byte character codes
held in VRAM. It is 960 bytes long in 40x24 Text Mode, 768 bytes long in
32x24 Text Mode, Graphics Mode and MultiColor Mode. Each position in the
Name Table corresponds to a particular location on the screen.
During a video frame the VDP will sequentially read every character code
from the Name Table, starting at the base. As each character code is
read the corresponding 8x8 pattern of pixels is looked up in the
Character Pattern Table and displayed on the screen. The appearance of
the screen can thus
be modified by either changing the character codes in the Name Table or
the pixel patterns in the Character Pattern Table.
Note that the VDP has no hardware cursor facility, if one is required it
must be software generated.
You must use an internal register in the
VDP to read or write data. This register is used as adressregister, and
decides where data will be written or read. Because the VDP can adress
16KB VRAM, the register is 14 bits (2 * 14 = 16384). To set the
read/write address, write it to port 1 (I/O port 99h on the MSX and 81h
for SVI-328). You must write two bytes (totaly 16 bits) to the VDP. The
extra 2 bits are used to decide if it's a read or write operation to
VRAM, and also if it's a register write.
Reg. | bit 7 | bit 6 | bit 5 | bit 4 | bit 3 | bit 2 | bit 1 | bit 0 |
---|---|---|---|---|---|---|---|---|
0 | (none) | (none) | (none) | (none) | (none) | (none) | Mode 2 | B/W |
1 | (none) | blank | INT | Mode 1 | Mode 3 | (none) | SI | MAG |
2 | (none) | (none) | (none) | (none) | PN13 | PN12 | PN11 | PN10 |
3 | CT13 | CT12 | CT11 | CT10 | CT9 | CT8 | CT7 | CT6 |
4 | (none) | (none) | (none) | (none) | (none) | PG13 | PG12 | PG11 |
5 | (none) | SA13 | SA12 | SA11 | SA10 | SA9 | SA8 | SA7 |
6 | (none) | (none) | (none) | (none) | (none) | SG13 | SG12 | SG11 |
7 | TC3 | TC3 | TC2 | TC0 | BD3 | BD2 | BD1 | BD0 |
8 | INT | 5S | C | FS4 | FS3 | FS2 | FS1 | FS0 |
Registers 0 through 7 can only be written
to, while register 8 can only be read.
This is the status register.
There are four screen modes.
In this text mode, the sprite system is disabled. Also, the pattern Color table is not used.
Patterns are area of 6 x 8 pixels. There are 256 patterns stored in the pattern table. Each pattern consists of 8 bytes. The last two bits of each byte are ignored.
The screen has 40 x 24 entries. The resolution is (40 * 6 = 240) x (24 * 8 = 192) pixels. Thus, the pattern name table contains 40 x 24 = 960 bytes. The first byte of the pattern name table is the name (=pattern number) of the top left pattern, the second the one the one on the left of it. To calculate the address in VRAM of the pattern, use this formula:
address = pattern generator table address + 8 * pattern name
The screen has the Color of the backdrop
(BD in register 7), and the text of the text Color (TC in register 7).
In this text mode, the sprite system is active. All the tables are used.
The full length of the pattern bytes are
used (8 x 8 pixels). Each pattern has a thingy.
The VDP is controlled through 2 I/O ports,
which both can be read and written to.
Dispite what the manuals say, there is only one address the VDP uses for reading and writing.
To set the read/write address, write it to port 1 (I/O port 99h on the MSX). You must write two bytes:
byte | bit 7 | bit 6 | bit 5 | bit 4 | bit 3 | bit 2 | bit 1 | bit 0 |
---|---|---|---|---|---|---|---|---|
first | A7 | A6 | A5 | A4 | A3 | A2 | A1 | A0 |
second | 0 | Read/Write | A13 | A12 | A11 | A10 | A9 | A8 |
What happens next depends on bit 6 of the second byte:
bit 6 | effect |
---|---|
0 (Read) | Read ahead the byte from VRAM address specified, increase the address and set |
1 (Write) | Set the address to the one specified |
Now you can read and write data to and from the VRAM by reading and writing to port 0 (I/O port 98h on the MSX)
Action Port 0 | Effect |
---|---|
Read | Return read-ahead value, increase address and read ahead again |
Write | Write given value to address and increase it |
Note that the address raps around at
beyond 3FFFh to 0.
If you read port 1 (I/O port 99h), you'll get the value of register 8.
To write to a register, write the following values to port 1 (I/O port 99h):
byte | bit 7 | bit 6 | bit 5 | bit 4 | bit 3 | bit 2 | bit 1 | bit 0 |
---|---|---|---|---|---|---|---|---|
first | V7 | V6 | V5 | V4 | V3 | V2 | V1 | V0 |
second | 1 | 0 | 0 | 0 | 0 | R2 | R1 | R0 |
Where V is the value and R the register. Actually, when bit 7 of the second byte is high, bit 6 through bit 3 are ignored.
Please note that to maintain compatibility
with the V9938 and V9958, you must set all the unused/ignored bits to
zero in the register values and in the second byte.
As you've probably seem, when you write to
port 1, you always do it in packets of two bytes.
But what happens if an interrupt occurs in your program, when you've
written the first byte but not the second ? If the interrupt program
attempts to change an register or something like that, it'll surely
screw things up. That's why you must always disable interrupts before
writing your data to port 1.
Another weird phoneme is this: when you're in MSX BASIC, type the following:
OUT (&H99),0
You'd expect things to be screwed up severely, but it doesn't happen. What does ?
I have found the following explanation:
The VDP has a flag which is low if it is expecting a first byte of a
packet, and high when its expecting the second byte.
But every time any VDP port is read or written to, the flag is
reset. (except, of course, when it's a packet written to port 1.)
The VDP provides the only interrupt in the MSX system. It is issued every time the screen is sent to the TV. (that is, 50Hz on a European machine (PAL) and 60Hz on any reasonable machine (NTSC).
I have found the following rules:
No value is put on the data bus when the
interrupt is acknowledged by the Z80. That's why it seems there's FFh on
the data bus, making
IM 0
behave
the same as
IM 1
. (FFh =
RST 38H
)
SCREEN 0 (Text mode, 40 column):
0000-03BF | Name table (char positions) (See note A) |
0800-0FFF | Character patterns (font) (See note B) |
SCREEN 1 (Colored text mode, 32 column):
0000-07FF | Character patterns (font) (See note B) |
1800-1AFF | Name table (char positions) (See note A) |
1B00-1B7F | Sprite attribute table (See note C) |
2000-201F | Characters Color table (8/byte) (See note F) |
3800-3FFF | Sprite character patterns (See note D) |
SCREEN 2 (256*192 Graphics mode):
0000-17FF | Charcter patterns (See note B) |
1800-1AFF | Name table (char positions) |
1B00-1B7F | Sprite attribute table (See note C) |
2000-37FF | PixelByte Color table (See note E) |
3800-3FFF | Sprite character patterns (See note D |
SCREEN 3 (4x4 pixel blocks/MultiColor mode):
0000-05FF | Charcter Color patterns |
0800-0AFF | Name table (char positions) |
1B00-1B7F | Sprite attribute table (See note C) |
3800-3FFF | Sprite character patterns (See note D) |
Sources of this document:
The Service & Technical Manual for SVI 318/382
Sean Young's MSX Net
The MSX Red Book