VGA long color modification
T Chap
Posts: 4,223
Is there a way in spin to modify the 2 colors in the longs for a 1 bit vga color? I would like to be able to change the colors of each ff and bg in spin on the fly versus having to change the longs or have a long list to choose from.
'ff bg ff bg ff = graphic, bg = background
'ff ff bg bg
'ff bg ff bg ff = graphic, bg = background
'ff ff bg bg
DAT vgacolors long $FC00FC00 'white graphics blk bg long $FCFC0000
Comments
-Phil
This makes it much easier to assign colors for use later.
I use this method to change VGA colors in one of my touchscreen programs.
Here are some of the global variables used in the above object.
This still requires a list of colors to choose from. I have the list in a "DAT" section.
The list of names under "Color enumeration" corresponds with the byte sized color codes in "colorPalete". For example, element #3 of "colorPallete" is "$08". "_Blue2" is the constant name associated with this color since the value of "_Blue2" is 3.
Instead of having to remember to use "$08" whenever the second alternative blue color is to be used, I can use "colorPalete[_Blue2]". The first method I listed takes the byte color codes for the text and the background color and fills these values into the long "gobalColor".
The first portion of the method "SetColor" allows me to keep track of which color combinations are being used in the current menu. You probably don't need this book keeping code yourself.
What do you mean, "on the fly?"
When using the color palette method to assign colors, there are two layers to it. One is the tile to palette assignment. The other is the palette entry to color value assignment.
If you assign all your tiles to one palette, you've got a 4 color screen at that point. Only one palette entry is then required, no list. This simplifies the colors down to just the palette entry values.
From there, if you want to change a color mid-screen, you could wait for the VBLANK, then change it sometime afterword basically using one palette entry for two color values. Of course, if you do that, you also need to put it back during VBLANK so that the original value, not the secondary one is present for the drawing of the upper part of the screen.
That's complicated though, requires timing and complexity.
You might mean, just being able to change the color anytime when you say, "on the fly". In that case, just change the palette entry directly anytime you want! Again, if you've set all your tiles to the same palette, you have a 4 color screen. Changing the palette entry would just change one of those four colors.
That's the minimum for filling the screen with pixels in color.
If you want to then have more than 4 colors on the screen, simply add another palette entry, and assign tiles to that palette. Say that's 4 colors for the top half, and four colors for the bottom. Assign the top half to palette 0, bottom to palette 1.
Then change the entries as you need. The more colors you require, and the more screen regions you find necessary, the more palettes you define. The "Parallax Colors Simplified" in my signature highlights doing this. It's for graphics_demo.spin, but the general technique is applicable for any Parallax style tile drivers. That's VGA.spin and TV.spin for sure. I am pretty sure it's the HEL driver found on the HYDRA CD as well, and there are probably others.
IMHO, this color flexibility is actually very useful. Most drivers out there don't include the color redirection capability, either being limited in colors on screen, or requiring absolute colors, which don't allow for image changes without also redrawing all the pixels.
Here's the code that sets the colors:
And here are the default color definitions:
You can just make your own "palette" definitions, say "palette2" and then call SetColors(palette2)
Sometimes "on the fly" can get complicated, because it can mean, "while the image is being drawn." In any case, the palettes are not static. The moment you change them, the on screen color will change on the very next tile that references that palette.