Bochs Graphics Adaptor in 4 bits-per-pixel mode
Posted: Tue Oct 21, 2008 8:15 pm
Hi,
I want to share some of my experiments. I'm playing around with Bochs Graphics Adaptor for the moment. I've got most of it working. In 8, 15, 16, 24 and 32 BPP modes it behaved like I expected, but I stumbled upon a few funny things in 4 BPP mode.
Initially I believed the 4 BPP mode would have a memory layout like this:
Ie. using a half byte per pixel. I couldn't be more wrong and naive. It didn't work. Actually it gave some wierd images with a lot of vertical lines. I went ahead to read the wiki here and here. Of course it sounds like a lot of hassle splitting up the color bits of a single pixel to 4 different planes, but it just requires some coding. But again, it didn't work. Instead I ended of with my drawing multiple times on the screen in various colors. What I've found out is that the memory layout of BGA in 4 BPP mode is like this:
Ie. byte 0 represents 8 pixels in plane 0, byte 1 represents the same 8 pixels in plane 1, byte 2 is plane 2, byte 3 is plane 3, byte 4 is plane 0 (just the next 8 pixels), etc.
Is that normal behaviour or is it a bug in BGA? On the vgabios news site (updated some time in 2006??) they say they fixed a lot of bugs relating to 4 BPP, but maybe they newer really got it right?
When that worked I also wanted to play with the DAC palette. I already got it to work nicely in 8 BPP mode, where you have 256 colors. If you draw pixel with the value X you have to update DAC palette entry no. X. Plain and simple. But not in 4 BPP mode! Here is a table representing pixel values and their DAC palette entry, when using BGA in 4 BPP mode:
I made a test drawing with colors extracted from DAC (converted into 8 bit using formula x*255/63 because DAC use 6 bit colors): screenshot.
Maybe I should add this info to the wiki on Bochs VBE extensions.
I want to share some of my experiments. I'm playing around with Bochs Graphics Adaptor for the moment. I've got most of it working. In 8, 15, 16, 24 and 32 BPP modes it behaved like I expected, but I stumbled upon a few funny things in 4 BPP mode.
Initially I believed the 4 BPP mode would have a memory layout like this:
Code: Select all
Color bit: 3 2 1 0 3 2 1 0 3 2 1 0 3 2 1 0 3 2 1 0 3 2 1 0 3 2 1 0 3 2 1 0
,-------.-------. ,-------.-------. ,-------.-------. ,-------.-------.
|MSB X X|X X LSB| |X X X X|X X X X| |X X X X|X X X X| |X X X X|X X X X|
`-------'-------' `-------'-------' `-------'-------' `-------'-------'
Pixel 1 Pixel 0 Pixel 3 Pixel 2 Pixel 5 Pixel 4 Pixel 7 Pixel 6
Color bit: 3 2 1 0 3 2 1 0 3 2 1 0 3 2 1 0 3 2 1 0 3 2 1 0 3 2 1 0 3 2 1 0
,-------.-------. ,-------.-------. ,-------.-------. ,-------.-------.
|X X X X|X X X X| |X X X X|X X X X| |X X X X|X X X X| |X X X X|X X X X|
`-------'-------' `-------'-------' `-------'-------' `-------'-------'
Pixel 9 Pixel 8 Pixel11 Pixel10 Pixel13 Pixel12 Pixel15 Pixel14
Code: Select all
Color bit 0 Color bit 1 Color bit 2 Color bit 3
,---------------. ,---------------. ,---------------. ,---------------.
|MSB X X X X LSB| |X X X X X X X X| |X X X X X X X X| |X X X X X X X X|
`---------------' `---------------' `---------------' `---------------'
Pixel: 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
Color bit 0 Color bit 1 Color bit 2 Color bit 3
,---------------. ,---------------. ,---------------. ,---------------.
|X X X X X X X X| |X X X X X X X X| |X X X X X X X X| |X X X X X X X X|
`---------------' `---------------' `---------------' `---------------'
Pixel: 8 9 101112131415 8 9 101112131415 8 9 101112131415 8 9 101112131415
Is that normal behaviour or is it a bug in BGA? On the vgabios news site (updated some time in 2006??) they say they fixed a lot of bugs relating to 4 BPP, but maybe they newer really got it right?
When that worked I also wanted to play with the DAC palette. I already got it to work nicely in 8 BPP mode, where you have 256 colors. If you draw pixel with the value X you have to update DAC palette entry no. X. Plain and simple. But not in 4 BPP mode! Here is a table representing pixel values and their DAC palette entry, when using BGA in 4 BPP mode:
Code: Select all
Pixel value: DAC palette entry:
------------ ------------------
0 0
1 1
2 2
3 3
4 4
5 5
6 20 <-- how wierd is that?
7 7
8 56
9 57
10 58
11 59
12 60
13 61
14 62
15 63
Maybe I should add this info to the wiki on Bochs VBE extensions.