VDP2
The VDP2 (Video Display Processor 2) is one of the two graphics processors for the Sega Saturn. Unlike the VDP1 where its mainly used for drawing sprites and polygons, the VDP2 is used for pretty much everything else, whether it be drawing background screens, setting priority settings, or even palettes. And because of that, it is also much more difficult to use compared to the VDP1. The VDP2 has 512kb of RAM available to it for use with cells/maps/bitmaps/etc. and 4kb of Color RAM for setting palettes for VDP1 sprites and VDP2 screens.
Contents
Memory map
VDP2 Description | Address | Size |
---|---|---|
VDP2 I/O register address | 0x25F80000 | |
VDP2 VRAM Bank A0 | 0x25E00000 | 128 kb |
VDP2 VRAM Bank A1 | 0x25E20000 | 128 kb |
VDP2 VRAM Bank B0 | 0x25E40000 | 128 kb |
VDP2 VRAM Bank B1 | 0x25E60000 | 128 kb |
VDP2 Color RAM | 0x25F00000 | 4 kb |
Screens
Basically the VDP2 consists of several different background layers, called "Screens". These can be split up into several different types of screens - Normal Scroll, Rotation, and Line Screens. Normal Scroll Screens are meant for general-purpose displays and for scrolling images. Rotation Screens are meant for doing two and three dimensional rotation of an image(which is handy for doing large levels, flooring, etc. in 3D). Line Screens just allows the programmer to set a single color to the whole screen, or a color for every line. Here's a list of all the screens:
Scroll Screens
- NBG0(Can display bitmaps and cells)
- NBG1(Can display bitmaps and cells)
- NBG2(Can only display cells)
- NBG3(Can only display cells)
Rotation Screens
- RBG0(Can display bitmaps and cells)
- RBG1(Can display bitmaps and cells)
Line Screens
- Back(is displayed underneath all the other screens)
- Line Color(is used only for color calculations)
Note: If RBG1 is enabled, you can no longer use NBG0-NBG3, so keep that in mind.
Display Format
The VDP2 generates the following types of displays:
- NTSC - 60 frames per second, 263 lines per frame
- PAL - 50 frames per second, 313 lines per frame
Here's a description of how each frame is composed. The NTSC displays have been visually inspected and therefore have more details about them, whereas for the PAL modes only divide the display into the active display and blanking/border/sync areas.
NTSC, 224 lines:
224 lines for the active display area 8 lines for the bottom border area 5 lines for the bottom blanking area 3 lines for the vertical sync area 15 lines for the top blanking area 8 lines for the top border area
NTSC, 240 lines:
240 lines for the active display area 5 lines for the bottom blanking area 3 lines for the vertical sync area 15 lines for the top blanking area
PAL, 224 lines:
224 lines for the active display area 32 lines for the bottom border area 25 lines for blanking and sync 32 lines for the top border area
PAL, 240 lines:
240 lines for the active display area 24 lines for the bottom border area 25 lines for blanking and sync 24 lines for the top border area
PAL, 256 lines:
256 lines for the active display area 16 lines for the bottom border area 25 lines for blanking and sync 16 lines for the top border area
A typical display frame looks like this:
+----------------+ Scanline 0 | | | Active display | Graphics data is shown here. | | +----------------+ | | Either black (BDCLMD=0) or set to the border color | Bottom border | as defined by the back screen. The bottom border is | | optional. +----------------+ | | | Bottom blanking| Appears as light black. | | +----------------+ | | | Vertical sync | Appears as pure black. | | +----------------+ | | | Top blanking | Appears as light black. | | +----------------+ | | Either black (BDCLMD=0) or set to the border color | Top border | as defined by the back screen. The top border is | | optional. | | +----------------+ Scanline 262 or 313
Exclusive Monitor display modes
When bit 2 of the HRESOx field is set, the exclusive monitor modes are enabled. It's not exactly clear what kind of monitor these modes are supposed to be used with, I would guess HDTV or possibly VGA.
Depending on the screen width, the following types of displays are generated:
320 or 640 pixels: (31kHz monitor)
480 active display lines 45 VBlank lines 525 lines total
352 or 704 pixels: (Hi-Vision monitor)
479 active display lines 82 VBlank lines 561 lines total
These display settings are identical between a NTSC and PAL Saturn. The VRESOx bits have no effect on the display size.
It seems that while the LSMDx bits will enable an interlaced display, this is not required for the exclusive monitor modes. It's likely that enabling interlacing might adversely affect the display. The VDP2 manual recommends turning interlacing off entirely.
Bitmap Mode
(finish me)
Cell Mode
This mode is for displaying cell(also called tile) maps. Basically each it consists of 4 planes(16 for rotation screens) which are in a 2x2 grid(or 4x4 for rotation screens). They're arranged as follows:
1 2 3 4
In each of those planes, there's are a number of pages(specified by the plane size register) which can be as many as 4. They're also arranged as follows:
1 2 3 4
In each of those pages, there consists a 64x64 character pattern grid. Each character pattern can be either 1x1 or 2x2 cells(specified by the screen's Character Control Register). Each cell is 8x8 pixels.
Color RAM
The VDP2 has 4K of on-chip color RAM. This memory is mapped to the address range of 0x05F00000-0x05F7FFFF, mirrored every 4K.
Bits 13,12 of the RAMCTL register configure the CRAM mode:
- 0 = CRAM is organized as 1024 words, color data stored in 5:5:5 format.
- 1 = CRAM is organized as 2048 words, color data stored in 5:5:5 format.
- 2 = CRAM is organized as 1024 longs, color data stored in 8:8:8 format.
- 3 = CRAM is organized as 1024 longs, color data stored in 8:8:8 format.
Mode 3 is undocumented, but appears to be identical to mode 2.
In mode 0, values written to CRAM offsets $000-7FF are also written to offsets 0x800-0xFFF. Likewise, values written to offsets 0x800-0xFFF are written to offsets 0x000-0x7FF. So write mirroring is done for both parts of CRAM.
In mode 1 there is no mirroring and the entire CRAM region can be accessed normally.
In mode 2 and 3 the CRAM address bus has some bits shuffled around:
MSB | LSB | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Intended offset | A11 | A10 | A09 | A08 | A07 | A06 | A05 | A04 | A03 | A02 | A01 | A00 |
Actual offset | A10 | A09 | A08 | A07 | A06 | A05 | A04 | A03 | A02 | A01 | A11 | A00 |
This arrangement has the first two bytes of each four byte entry at CRAM offsets 0x000-0x7FF, and the last two bytes at offset 0x800-0xFFF.
This distinction between how CRAM is addressed is important if a program reads or writes data in one mode that is to be used in a different mode.
Operation Flow
This is for the most part how the draw cycle works(may need some tweaking):
How to setup a scroll screen
The following will give a step by step process on enabling the NBG0 as a 256 color scroll screen.
- Enable display by writing 0x8000 (DISP) to 0x25F80000 (TVMD).
- Enable the scroll screen by writing 0x0001 (N0ON) bit to 0x25F80020 (BGON).
- Set the character count to 8-bits by writing 0x0010 (N0CHCN0) to 0x25F80028 (CHCTLA).
- Write to the VDP2 priority registers.
- Write to the VDP2 cycle pattern registers.
Notes
- When the VDP2 fetches the color offset for the pixel it is to draw, it fetches whatever was last written in the Color Offset registers. So hypothetically, you could actually apply color offset effects per scanline during horizontal blanking. In fact, Albert Odyssey uses this as a cheap way of doing a gradient effect.
- It looks as though V-blank in/out interrupts will not be sent if 0x8000 (DISP) bit is not set in 0x25F80000 (TVMD). More investigation should be done.
- If 0x25F80000 (TVMD) does not have 0x8000 (DISP) set to 1, and 0x0100 (BDCLMD) bit is also not set, the back screen will not be displayed at all (instead black is drawn to the screen). However if 0x0100 (BDCLMD) is set, the back screen still is drawn.
- Instead of adjusting the pixel density when changing between 224 and 240 line vertical resolutions, 8 pixels above and below the screen are used as a border(when using 224) or are used as a drawable area(when using 240). Looks like 256(only available on PAL systems) uses the same thing, but it'll need to be verified. As for horizontal resolutions, it looks like pixel density is adjusted, but so also the border appears to be adjusted too(by 8 pixels on each side).