I spent an evening re-writing a bitmap (.bmp) loader to work in EGA modes with correct colors from the .bmp palette in the header. The greatest challenge lied in the fact that unlike simplicity of 256-color mode, the 16 color image and mode represent a pixel as a nibble (half byte). I was able to separate file bytes into nibbles and write them to the screen. I had to make some control changes for some reason, I had to write each palette color number to &H3C8, followed by three color channels to &H3C9. All code examples on the web only write color 0 to &H3C8, but with EGA that simply doesn't work. Also, after the palette is written to memory, I also have to loop through PALETTE statement for colors 0 through 15 in both old and new color. I guess when the palette is written to memory only the block with 64 available colors is updated, I still have to update them in the 16 active colors.
I haven't programmed in QuickBasic in many years, I've since gotten CS and CE degrees in college, so most of my programming was done in Java and C.
Upon my return to QuickBasic I was very surprised there are no dedicated data type for byte (it's a char), and no type for a nibble or bit. There aren't even bitwise shift operations.
Now, the baddies. For some reason when I BSAVE from screen 9 (or 7 for that matter), the image I BLOAD comes out always in monochrome, the 16 colors are gone, even if default palette is used. I tried the color switch in screen 9, it doesn't have the desired effect.
The following two programs reproduce the problem (MS QuickBasic 4.5):
Code: Select all
SCREEN 9
CLS
CIRCLE (320, 175), 100, 5
PAINT (320, 175), 5
DEF SEG = &HA000
BSAVE "test.bsv", 0, 64000
DEF SEG
Code: Select all
SCREEN 9
DEF SEG = &HA000
BLOAD "test.bsv"
DEF SEG
So what's the solution to this color/palette problem? I realize that for screen 9 the memory page is larger than 64K, however this exact issue is also present in screen 7.
Also, where is the &HA000 offset documented, and where is the port documentation for &H3C7, &H3C8, &H3C9? I see people using these but I haven't found the official source of documentation for these. I'd certainly like to know more useful ports and memory offsets.