PEEKing Bitmap Color?

Started by mikeebean, January 10, 2009, 04:02 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

mikeebean

I'm trying to write a simple program in BASIC which plots squares on the Bitmap screen, and I've run into a snag which I haven't found an answer for.

My program uses GRAPHIC2,1 to set up a split screen, and CHAR1,X,Y," ",1 to place squares on the screen.

I want to use the PEEK command to discover the color of a square before I plot a new square over it. Locations 7168-8167 are supposed to be the bitmap color memory, but PEEKing them after a screen clear doesn't give me my expected result. I typically get a result of 16 (white bitmap on a black background) or 32 (red bitmap on a black background), when what I hoped for was 0 (black bitmap on black background).

Any thoughts would be greatly appreciated!

Michael

mikeebean

#1
I figured out how to do it, almost by chance;

COLOR0,1 : COLOR1,1 : GRAPHIC2,1 : COLOR1,2

I set the background and foreground colors to black, clear the text/graphics split screen, then set foreground color back to white so my text is visible.

Michael

SmallCleverDinosaur

I think you are understanding it more or less correctly. Only a few details that you've missed :) As follows:

When you do a GRAPHIC 2,1, the 2 is for setting a standard bitmap with split screen and the one is for clearing the screen. The color memory is cleared at the same time. But what does "cleared" mean in this situation? The bitmap data is cleared, i.e filled with zeroes. The colordata are also cleared but the computer has to know what a "cleared" color is supposed to be.

And that's decided by the previously issued COLOR command. If no COLOR command has been issued the clearing of the color memory uses the default colors of the C128 screen which is a grey background (or dark grey, as opposed to medium grey and light grey which also exist) with light green characters.

The color information at 7168 ($1C00) is stored like this; the first 4 bits of each byte contains the foreground color of each pixel and the last 4 bits contains the background color. So, if no COLOR command has been issued, the color memory is being cleared with the value 219 ($DB). In binary this is 11011011. So the foreground will be set to 1101 (13) and the background to 1011 (11). 13 and 11 are light green and dark grey respectively.

Mapping the C128 is one of the greatest books for the C128 ever. It explains all this in detail. Have a look at page 345, there are the bitmap modes described. (Note that the pagenumbers in the original scan of the book doesn't correspond to the pages in the pdf-file).
Ignorance is a precious thing. Once lost, it can never be regained.

mikeebean

SmallCleverDinosaur,

Thanks, that makes sense. The System Guide just doesn't explain some things very well in my opinion. Sometimes the forums are the best place to get answers!

Michael

Edwing

...maybe I'm thick, but you surely have a reason to use the bitmap screen for your color cards rather than using the same CHAR command in text mode?

Regards,
Edwing

mikeebean

Edwing- The reason was I was trying to convert an Apple II PLOTting program. I wanted to use the split screen mode, so the user could type PLOT commands in the bottom section while the top section would use CHAR to place colored blocks at specified areas.  -Michael