EGA palette, BSAVE, BLOAD

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
r00tb33r
Newbie
Posts: 1
Joined: Sun Jan 19, 2014 4:49 am

EGA palette, BSAVE, BLOAD

Post by r00tb33r »

As you folks know, most graphics libraries and image loaders have been written for mode 13h (screen 13). Unfortunately it appears that many of those techniques simply do not work with EGA modes. Screen 7 and 9 are of interest due to availability of multiple pages for page flipping.

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
Draws a purple circle, and dumps memory to the file.

Code: Select all

SCREEN 9
DEF SEG = &HA000
BLOAD "test.bsv"
DEF SEG
Loads memory from the file, but now the circle is white, even though the palette is still default. What the...?

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.
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Re: EGA palette, BSAVE, BLOAD

Post by burger2227 »

You have to read all of the colors to get the Red, Green and Blue attributes of the image. Then you have to load that information into the same array that GET loads the pixel data into after that color information offset.

SCREEN modes 0, 7 and 9 are DAC screen modes which means you cannot just go and change some color attributes using OUT. Some are locked and must be unlocked or use PALETTE. You can find out more in Chapter 13 of my Qbasics tutorial in my signature.
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
Post Reply