VOGONS


First post, by videogamer555

User metadata
Rank Member
Rank
Member

In CGA 320x200 4-color modes (video modes 4 and 5), what exactly are the starting memory addresses for the 2 fields? I know it is divided into 2 fields of alternating lines, rather than one continuous picture like in VGA mode. I know that the first field (lines 0, 2, 4, 6, etc) start at address 0xB8000, and I assumed the second field (lines 1, 3, 5, 7, etc) started IMMEDIATELY after this. However, I'm not so sure about this assumption, after I wrote a program in assembly language that was based on that assumption, and second field doesn't line up correctly with the first field.The first field is correctly aligned with the screen, so I am 100% certain that the first field's starting address is 0xB8000. However has assumed that the second field started at address 0xB9F40 (exactly 8000 bytes after the start of the first field, which is the number of bytes in the first field, such that the starting address of the second field occurred immediately after the end of the first field). If it does not in fact start at 0xB9F40, then where does the second field start?

Reply 1 of 2, by videogamer555

User metadata
Rank Member
Rank
Member

Ok, well I couldn't find it anywhere on the net (guess not enough people into programming retro PC graphics software to bother documenting CGA addresses), but through trial and error, I eventually discovered what the address of the second image field is. It is 0xBA000 (or BA00h:0000h if using segment:offset notation).
First byte of first CGA image field is 0xB8000
Last byte of first CGA image field is 0xB9F3F
First byte of second CGA image field is 0xBA000
Last byte of second CGA image field is 0xBBF3F

Of course this leaves the question, what does a CGA graphics card use addresses from 0xB9F40 to 0xB9FFF for?

Reply 2 of 2, by reenigne

User metadata
Rank Oldbie
Rank
Oldbie
videogamer555 wrote:
Ok, well I couldn't find it anywhere on the net (guess not enough people into programming retro PC graphics software to bother d […]
Show full quote

Ok, well I couldn't find it anywhere on the net (guess not enough people into programming retro PC graphics software to bother documenting CGA addresses), but through trial and error, I eventually discovered what the address of the second image field is. It is 0xBA000 (or BA00h:0000h if using segment:offset notation).
First byte of first CGA image field is 0xB8000
Last byte of first CGA image field is 0xB9F3F
First byte of second CGA image field is 0xBA000
Last byte of second CGA image field is 0xBBF3F

Confirmed. The addresses are generated by the CRTC, but in graphics modes that only generates 12 bits of addresses. The discrete logic implements address bit 0 (which just toggles every 4 low-res or 8 high-res pixels) and address bit 13 (which comes from the CRTC's "row address bit 0" - the low bit of the scanline within the character).

videogamer555 wrote:

Of course this leaves the question, what does a CGA graphics card use addresses from 0xB9F40 to 0xB9FFF for?

Usually they are just left unused. They aren't useful as scratch space as they're slow (like all CGA RAM) and small (only 384 bytes). However, they are useful for tweak modes (656x198, 328x198, 640x204, 320x204) and are needed for doing hardware scrolling (as they'll be made visible before the address wraps back to the start of the page).