VGA Ignoring Text Colour Attribute

Programming, for all ages and all languages.
Post Reply
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

VGA Ignoring Text Colour Attribute

Post 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
User avatar
os64dev
Member
Member
Posts: 553
Joined: Sat Jan 27, 2007 3:21 pm
Location: Best, Netherlands

Re: VGA Ignoring Text Colour Attribute

Post 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.
Author of COBOS
User avatar
AndrewAPrice
Member
Member
Posts: 2299
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Re: VGA Ignoring Text Colour Attribute

Post 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.
My OS is Perception.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: VGA Ignoring Text Colour Attribute

Post 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.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: VGA Ignoring Text Colour Attribute

Post 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
Post Reply