Page 1 of 1

VGA Ignoring Text Colour Attribute

Posted: Fri Jan 30, 2009 11:00 am
by AJ
Hi,

I have only just started playing with VGA, but have just come up with a question (more for information - I have solved the bug).

I originally found the problem when I was installing a new 256 byte text mode font to VGA plane 2. I saved registers SC2, SC4, GC4, GC5 and GC6, switched to plane 2, wrote the font and restored the registers. My mistake was that I then manually switched back to plane 0 (didn't need to because I had already restored the necessary VGA registers).

On Bochs, everything worked fine - 16 colour text mode with odd/even bytes representing text and attributes as expeced. However, on VirtualBox, all my text came out grey on black.

My first thought was that my manual plane switch had obliterated the Odd/Even disable bit in SC4. The only catch with this was that my plane switching routine only messes with GC4 and SC2, so that shouldn't happen. Also, the text displayed formatted correctly, and I would expect that if the planes were not switching automatically, I'd get colour codes displayed as characters - that didn't happen. Obviously removing the manual switch to plane 0 removed the bug.

So, could someone who knows about VGA tell me what was happening? I know that VGA emulations are often broken, but which emulator/VM acted correctly - Bochs or VirtualBox? Unfortunately, I haven't had a chance to try this on actual hardware yet, but I'll give that a go when I can.

Cheers,
Adam

Re: VGA Ignoring Text Colour Attribute

Posted: Fri Jan 30, 2009 12:40 pm
by os64dev
Dunno which of the two emulates better. I had some issues with bochs but it seemed to work ok.
I would compare it only to real hardware, because manipulation on that level might even give something different on the real thing.

Re: VGA Ignoring Text Colour Attribute

Posted: Fri Jan 30, 2009 10:57 pm
by AndrewAPrice
Can you show us some code?

I use VirtualBox almost exclusively (I use to use Bochs on the rare kernel bug). Both output the text colour fine for me.

Re: VGA Ignoring Text Colour Attribute

Posted: Sat Jan 31, 2009 2:12 am
by Combuster
If you're talking about the plane mask register, it selects which planes are being allowed to written to. If you select plane 0, it should only write the character bytes, not the attribute bytes. The odd-even addressing works together by initially selecting the plane that could potentially be written, then passing it though the plane mask.

Bochs' VGA generally sucks - at pretty much any time it will just emulate the closest common mode - text, cga, ega, vga mode 13h or mode-x. So if you make a decent attempt at setting text mode, it will be text mode as far as bochs' concerned. Real hardware is much more picky.

Hope that explains things.

Re: VGA Ignoring Text Colour Attribute

Posted: Sat Jan 31, 2009 3:12 am
by AJ
Thank you! Of course that's it #-o

So the odd/even thing is working OK, but plane 1 is masked off, so every other byte gets lost in "the ether" - the controller attempts to send bits to plane 0/1/0/1...., but the writes to plane 1 are ignored because of the masking. As you correctly say, Bochs is just doing a "closest known mode" emulation.

My real hardware acted the same as VirtualBox, by the way. I may even get the hang of this VGA thing one day :)

Cheers,
Adam