VOGONS


First post, by vladstamate

User metadata
Rank Oldbie
Rank
Oldbie

Hi,

I am having a problem fully understanding when should I deal with chained mode vs odd/even plane mode in VGA emulation.

The memory mode register (port 3C5h index 4) controls this.

Looking at this (ftp://ftp.apple.asimov.net/pub/apple_II/docum … 20Registers.pdf) and this (http://www.osdever.net/FreeVGA/vga/seqreg.htm) I do not understand the difference between bits 2 and 3. They both seem to do the same thing yet I see in some games they are not set the same. For example in Eye of the Beholder I see them both set but for Wolfenstein 3D I see only bit 2 set and not 3.

(BTW there is a mistake on osdever in that they got the A0 and A1 switched)
============
Chain 4 -- Chain 4 Enable
"This bit controls the map selected during system read operations. When set to 0, this bit enables system addresses to sequentially access data within a bit map by using the Map Mask register. When setto 1, this bit causes the two low-order bits to select the map accessed as shown below.
Address Bits
A0 A1 Map Selected
0 0 0
0 1 1
1 0 2
1 1 3"
O/E Dis. -- Odd/Even Host Memory Write Adressing Disable
"When this bit is set to 0, even system addresses access maps 0 and 2, while odd system addresses access maps 1 and 3. When this bit is set to 1, system addresses sequentially access data within a bit map, and the maps are accessed according to the value in the Map Mask register (index 0x02)."
===========

Why do VGA cards provide 2 bits to accomplish the same thing?

Regards,
Vlad.

YouTube channel: https://www.youtube.com/channel/UC7HbC_nq8t1S9l7qGYL0mTA
Collection: http://www.digiloguemuseum.com/index.html
Emulator: https://sites.google.com/site/capex86/
Raytracer: https://sites.google.com/site/opaqueraytracer/

Reply 1 of 6, by Jepael

User metadata
Rank Oldbie
Rank
Oldbie

They are not the same thing.

If chain4 bit is 0, then the odd/even bit controls the access mode.
If chain4 bit is 1, then the odd/even bit is ignored, and planes are in chained mode.

Only standard mode 13h uses chain4=1. Because the mode is chained, the odd/even bit is ignored.

Wolf3d should run in unchained mode, therefore chain4=0. And since it must use the plane select register, the odd/even bit must be 1.

IIRC, possibly only text modes utilize that odd/even bit (this is one of the several bits controlling different things called odd/even).
In text mode, even addresses are the characters and they are in plane 0, and odd addresses are the color attributes so they are in plane 1. Also the character font is loaded on either plane 2 or 3 so that hides it from the user by default.

IIRC, there's another bit then which selects whether the accesses go to planes 0&1 (cannot access planes 2&3), or to planes 2&3 (cannot access planes 0&1).
Somehow, also CGA modes only use two planes, not four, so this odd/even bit may be used on CGA modes as well.

Reply 3 of 6, by Scali

User metadata
Rank l33t
Rank
l33t
Jepael wrote:

Somehow, also CGA modes only use two planes, not four, so this odd/even bit may be used on CGA modes as well.

CGA works differently.
The pixel format is 'chunky', as in, you have 2 4-bit pixels packed into each byte.
They store even and odd scanlines in two separate buffers though. This is done to circumvent the limitations of the 6845. It is meant for textmode and only supports up to 127 rows. To get 200 lines of bitmap, it programs the 6845 to a 100-row mode, and alternates between the two buffers for each scanline.

http://scalibq.wordpress.com/just-keeping-it- … ro-programming/

Reply 4 of 6, by Jepael

User metadata
Rank Oldbie
Rank
Oldbie
Scali wrote:

CGA works differently.
The pixel format is 'chunky', as in, you have 2 4-bit pixels packed into each byte.
They store even and odd scanlines in two separate buffers though. This is done to circumvent the limitations of the 6845. It is meant for textmode and only supports up to 127 rows. To get 200 lines of bitmap, it programs the 6845 to a 100-row mode, and alternates between the two buffers for each scanline.

Yes, but a VGA has to emulate CGA in a certain way. It does not work like real CGA.
And this odd/even bit we are talking about is not about CGA even/odd scanlines, read on 😀

Basically, CGA mode on a VGA is still a 16-color mode (4 bits per pixel), as everything on VGA is 4 bits per pixel (even the 256 color mode, it just has to fetch two 4-bit pixels to generate 8-bit pixels).

In CGA mode, the VGA fetches a byte from each of the four color planes, like it does in 16-color modes.
The odd/even bit discussed earlier limits the CPU data write access to write to VGA plane0 and plane1 only, instead of all four planes. So basically, you can only set two color bits per pixel, instead of four.

Also in CGA mode, the VGA sequencer is configured to mangle the fetched data from all four color planes so that a bytes are combined so that only plane0 and plane1 is used for 2 bits per pixel in CGA compatible way.
So when a CGA mode program writes to video ram, it is written to only two planes, and the sequencer combines the data from all four planes in CGA compatible fashion.

In fact the bytes from plane2 and plane3 would be the remaining 2 bits per pixel, but they are just zero because video memory is cleared when CGA mode is initialized.
Changing the mode to access plane2&3 instead of plane0&1 can set the other 2 bits per pixel in similar mapping like the original 2 bits per pixel.

Reply 5 of 6, by Scali

User metadata
Rank l33t
Rank
l33t

Yes, in fact, VGA is 99% EGA. EGA implements CGA compatibility in pretty much the same way.
In unchained mode you basically manipulate the 4 'EGA' bitplanes, VGA just interprets the data differently to make it into a 256 colour chunky mode instead of a planar mode.

http://scalibq.wordpress.com/just-keeping-it- … ro-programming/

Reply 6 of 6, by Vic3Dexe

User metadata
Rank Newbie
Rank
Newbie

VGA chain4:

address in plane:   0     1   2   3   4
plane 0: byte0 | x | x | x | byte4
plane 1: byte1 | x | x | x | byte5
plane 2: byte2 | x | x | x | byte6
plane 3: byte3 | x | x | x | byte7
CPU addr: 0/1/2/3 4/5/6/7

EGA/VGA o/e:

address in plane:   0     1     2     3   4
plane 0/2: byte0 | x | byte2 | x | byte4
plane 1/3: byte1 | x | byte3 | x | byte5
CPU addr: 0/1 2/3 4/5

And bit "chain" in graphics controller/register 6 is bit more complex as it allows you to use these "x" (holes) in memory.