Hi
jjarrell, and thank you for your report!
jjarrell wrote: ↑Thu Jan 30, 2025 6:02 pm
When this code prints out index 7, the program starts coloring text a few lines above. And at one point, colors all of the text at the top.
Actually, the only real mistake is that the colors are recycled.
This should not happen, so in the
HOTFIX I fixed this behavior.
Anyway, color management is subject to some
principles of isomorphism, which make the behavior encountered completely correct even if, perhaps, counterintuitive. In a nutshell,
ugBASIC has two working modes when using colors: implicit mode and explicit mode (the default).
With explicit mode, the command
PEN 4 (for example) does not mean to select register no. 4 but the color equivalent to the shade represented by the value 4 in that video chipset. In the case of GIME, it means
DARK RED. Since the GIME chipset in text mode has 8 foreground colors and 8 background colors registers available, when you use the command
PEN DARK RED (or
PEN 4),
ugBASIC will select the first available register and associate that color. So you can manage a maximum of 8 colors at once (the graphics modes allows to use up to 16 colors). Using this technique, the
PEN DARK RED command produces the same result on other targets, such as the Commodore 64 or the ZX Spectrum.
Code: Select all
PEN DARK RED: PRINT "I AM DARK RED EVERYWHERE!"
PEN 4: PRINT "I AM DARK RED UNDER GIME!"
To use the implicit method, you need to use the
COLOR and/or
PALETTE commands, and then use things like
PEN COLOR(register), where register is the register number to use to store the color gradient:
Code: Select all
COLOR 2, DARK RED
COLOR 3, BLUE
PEN COLOR(2): PRINT "I AM DARK RED!"
There would be an implicit color management, that is, managed directly using the colors of the registers on the graphics primitives, but this is a mode that is still under development and it is available only for a few registers and under some targets. It can be enabled using the following directive:
The rationale for this behaviour is that the registers are limited in number, and when it comes to managing graphics, it is appropriate that the color palettes are optimized as much as possible.
ugBASIC takes care of this during the compilation phase of the images, which selects an optimized palette, valid for all the images in use. You can, of course, get around this optimization, but you do so by knowing what you are doing, that is, by using (always in isomorphic terms) the palette, therefore assuming that the chipset has one.
For a more precise explanation, feel free to read the chapter
5.3 Implicit vs explicit colors of the
user manual.