VGA Hardware: Difference between revisions

Jump to navigation Jump to search
several additions, more details, added more specific todos
[unchecked revision][unchecked revision]
(added sequencer shift modes)
(several additions, more details, added more specific todos)
Line 173:
These modes seem to be consistent among all VGA compatibles and emulators I've tested:
* Mode 3 (Text mode) (right now I can only set it by keeping a state dump of VGA registers of the old mode)
* Mode 04h11h (4Planar 16 color mode) - Not tried
* Mode 13h (Linear 256 color mode)
* Mode X (Planar 256 color mode)
 
I have yet to write code that enters the following standard modes on all hardware
 
* Mode 13h (Linear 256 color mode) - GC part seems ok, however, I cant get the sequencer to work properly (Video output is bogus)
* Mode 11h04h (Planar 164 color mode) - Not tried, should be achieved by setting interleaved shift mode and ignoring planes 2 & 3.
* Mode 04h (4 color mode) - Not tried
 
The Graphics Controller consists of of some addressing logic, and some specific read/write logic.
Line 391 ⟶ 392:
 
== The Sequencer ==
The Sequencer is responsible to convert video memory to color indexes. Like the graphics controller, it has some special addressing logic, which is designed to iterate over the memory in a sensible manner to produce images out of video memory data.
 
The Sequencer either operates in text (alphanumeric) mode or graphics mode
 
=== Alphanumeric Mode ===
In alphanumeric mode the four planes are assigned distinct tasks. Plane 0 contains character data, while plane 1 contains Attribute data. In a standard text mode, these planes are interleaved into host memory. Plane 2 holds the font data. The addressing logic loads character/attribute pairs in order. It then looks up the corresponding font in plane 2, then pops out the bits in order, generating a foreground color when a 1 is encountered, and a background color when a 0 is encountered.
'''TODO'''
 
'''TODO: schematics'''
 
'''TODO: testing'''
 
=== Graphics Mode ===
Line 402 ⟶ 407:
The shift logic has three operating modes: single, interleaved and 256-color shift. Although the VGA 'supports' various color depths, these are basically varations on 16-color modes.
 
==== 256-Color Shift Modemodes ====
'''TODO: address calculation'''
While going through memory, the sequencer reads in a 4 bytes at a time from each of the four planes, then outputs 8 pixel colors. The VGA has three distinct modes of grouping this data into pixel values. The setting depends on two bits in a VGA register: the 256-color shift and interleaved shift bits. when both are off, Single shift mode is selected, otherwise the corresponding mode is used (256 color shift mode takes precedence over interleaved shift mode)
 
'''TODO: table of registers involved'''
==== Single shift mode ====
 
This mode is used in 16 color modes. For each pixel, one bit is popped off each plane and put together to form the value of a pixel.
====* Single shift mode ====
:This mode is used in 16 color modes. For each pixel, one bit is popped off each plane and put together to form the value of a pixel.
An example is given in [[VGA Hardware#Memory Layout in 16-color graphics modes|Memory Layout in 16-color graphics modes]]
 
====* Interleaved Shift Mode ====
:This mode makes 4-color modes relatively easy: 2 bits are popped off the most significant side of plane 0. The same is done with plane 2, which become the most significant bits (in 4-color modes, these are zero) After 4 pixels being popped from planes 0 and 2, the same is done with plane 1 and 3, until all 8 pixels have been generated.
 
* 256-Color Shift Mode
:This mode causes 4 bits to be popped of each time. Plane 0 gives the first two pixels, Plane 1 the next two and so on. However, it is not defined in which order this happens. Because this mode is normally used solely in 256-color modes where the color logic will merge two 4-bits pixels together to form one 8-bit pixel, the communication inbetween is acertain. However, the bits can only be shifted out one of two possible sides, and supporting two possibilities can be overseen. Another problem to this method is, you can not detect which method is used without user intervention or keeping a list. Either way, this method either shifts left (from the msb) or right (from the lsb). If you know the ordering of your video card, you can create a linear 16-bit color mode.
 
=== Address Calculation ===
 
For each group of pixels, the sequencer calculates the address in video memory where to load the data from. This address is calculated in three steps:
 
First the starting address of video memory is calculated: '''TODO'''
==== 256-Color Shift Mode ====
This mode causes 4 bits to be popped of each time. Plane 0 gives the first two pixels, Plane 1 the next two and so on. However, it is not defined in which order this happens. Because this mode is normally used solely in 256-color modes where the color logic will merge two 4-bits pixels together to form one 8-bit pixel, the communication inbetween is acertain. However, the bits can only be shifted out one of two possible sides, and supporting two possibilities can be overseen. Another problem to this method is, you can not detect which method is used without user intervention or keeping a list. Either way, this method either shifts left (from the msb) or right (from the lsb).
 
After that a scanline is rendered. The first address is read and the contents is split into pixels. Then the address is incremented by either 1, 2 or 4 for the next set of pixels until the scanline completes (the consequence of this is that each scanline is a multiple of eight pixels wide). The increment depends on wether the VGA is operating in "byte mode", "word mode", or "doubleword mode". These can be set using two bits: (doubleword modes takes precedence over byte/word mode)
'''TODO: 256-color Shift Mode is more tricky than this, I have to run a few more tests to see what is going on. One should be able to create a linear 16-color mode based on this'''
'''TODO: Registers'''
 
Once a scanline is complete, the original value at the start of the scanline is loaded, and the scanline counter is incremented. The VGA then does one of the following:
* Add the virtual width to the offset (and going to the next sequence of pixel data in memory). You can change the virtual width to change the amount of free data between scanlines, which can be useful for scrolling screens.
* Leave the value unchanged (and draw the same scanline again, identically). This is done when doublescanning '''TODO'''
* Reset the address to 0 (and start rendering from a different location in video memory) This can be used to create splitscreens '''TODO'''
 
== Color Logic ==
Line 614 ⟶ 633:
* Blanking (Bottom): 2 scan lines
Which should be VGA compatible
 
== Sample Register Settings ==
 
These are the register values that can be loaded into the VGA to set a standard mode. Note that you should unlock the CRTC and disable output before loading these registers, and afterwards restoring these to be nice for old monitors that are around.
 
The pseudocode for changing modes is roughly as follows:
 
DisableDisplay // disable output
UnlockCRTC // unlock registers
LoadRegisters // load registers
ClearScreen // clear the screen contents
LoadFonts // and for text mode, load fonts
// note that this may need to alter GC settings
// so be sure to restore those after that
LockCRTC // optional: lock the registers again
EnableDisplay // make sure there is output
 
=== List of register settings ===
 
{| {{wikitable}}
|-
! port
! index
! mode 3h (80x25 text mode)
! mode 11h (640x400 planar 16-bit color mode)
! mode 13h (320x200 linear 256-color mode)
! mode X (320x240 planar 256 color mode)
|}
 
'''TODO: filling in lookup table for the common graphics modes'''
 
[[Category:Stubs]]
1,490

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu