Page 1 of 1

Discrepancies in COLOR constants

Posted: Wed Dec 17, 2025 2:37 pm
by pioj
Hi guys! I'm joining this topic because I've found discrepancies in the COLOR constants (iex. COLOR WHITE), as they don't seem to match for every platform supported. Check the image, may be related to the thread...

Image

My friend and I started developing a text adventure targetting both C64 & CPC464 a couple days ago, and we discovered ugBASIC and Retrogamecoder's IDE almost at the same time. We loved both and we think they need as much feedback as possible.

@spotlessmind1975 If you guys manage to fix those constants so colors match between computers, that will help us a lot and make things easier. Also, a few examples make use of PNG images but you should clarify when they need to be 2,4,or 16 color for them to work in the guide.

@retrogamecoders your C examples for C64 and NES are incredible, thank you so much for that. I was hoping to test some samples for the GameGear and MasterSystem but none seem to run yet, or make them freeze the emulator and do nothing. Anyways, great job!

Thanks a lot for the support.

Re: Discrepancies in COLOR constants

Posted: Fri Dec 19, 2025 6:33 pm
by spotlessmind1975
Hi pioj, and welcome on the forum! :D
pioj wrote: Wed Dec 17, 2025 2:37 pm Hi guys! I'm joining this topic because I've found discrepancies in the COLOR constants (iex. COLOR WHITE), as they don't seem to match for every platform supported. Check the image, may be related to the thread...
First of all, thank you so much for the example! Thanks to your code, I identified and fixed a bug in the compiler. So, please update it in the IDE by going to Configuration > Compilers... , clicking on the letter C, and then clicking on the cloud icon to download the latest CPC hotfix.

At this point, I'd like to point out that the COLOR statement doesn't set the color to draw with (that's done with PEN and PAPER), but it's a statement used to set the color register on systems that have one. If you use it in that sense, you must supply two parameters. Otherwise, if ugBASIC's isomorphic color management is enough for you, you can use the PEN (INK) and PAPER commands. The manual page for COLOR is here online, or on the 17.102 chapter of the User Manual.

I'll send you the rest of the instructions as soon as possible! 8-)

Re: Discrepancies in COLOR constants

Posted: Fri Dec 19, 2025 10:12 pm
by spotlessmind1975
Hi pioj, here I am again! :D
pioj wrote: Wed Dec 17, 2025 2:37 pm Also, a few examples make use of PNG images but you should clarify when they need to be 2,4,or 16 color for them to work in the guide.
Image processing is hardware-dependent.

The ugBASIC language provides no abstractions for image processing, ensuring maximum performance. This means you should use images optimized for each hardware, placing them in subdirectories named after the target, so the code remains the same but the image is loaded as efficiently as possible, since the compiler will look for the dedicated resource. For example, if you use an image that uses 16 colors, you can use it on both the c64 and the cpc. However, the c64 version must take into account that, in an 8x8 pixel area, only three different colors (plus the background) can be used. Therefore, you cannot have as many local variances as you can with the cpc. Moreover, ugBASIC will calculate the optimal palette for every loaded image, in order to minimize the "palette clash" during drawing the image. This means that few colors should be used for each image, in order to have an optimal palette usage. On the examples directory on the repository you have many examples about that.


I hope this helps!

Re: Discrepancies in COLOR constants

Posted: Sun Dec 21, 2025 7:50 am
by pioj
Thanks a lot for the fix! I can provide a unified color palette for two computers now, awesome.

Is there any example to print bitmap font characters or custom-defined ones provided by a new charset? I'd like to display some text on the screen using a small font.

Re: Discrepancies in COLOR constants

Posted: Sun Dec 21, 2025 3:21 pm
by spotlessmind1975
Hi pioj!
pioj wrote: Sun Dec 21, 2025 7:50 am Is there any example to print bitmap font characters or custom-defined ones provided by a new charset?
Yes, of course, there are some basic examples here and here for this type of task. I recommend updating your compiler first, as a related issue with COLDFIX was fixed just this afternoon, so it's worth downloading the latest version.

In any case, there are several examples in the repository, and they all revolve around some ugBASIC commands that allow you to change the standard character font. The beta version, however, introduces a command that allows you to print a font composed of images. But let's go in order. The command for changing the font is the FONT LOAD command. This command simply replaces one or more characters in the system font with a graphic representation, which is loaded from an image file. The main feature of this command is that it works with monochrome 8x8 pixel fonts, which is the standard font size on almost all platforms. The main scope is to specify an image containing the various characters: the compiler will automatically crop the characters from the image, transform them into small monochrome bitmaps, and assign them to the various SCREENCODES. There are two syntaxes.

Code: Select all

FONT LOAD "image.png"
The first syntax allows you to load the entire character set, from position 0 onwards.

Code: Select all

FONT LOAD "image.png" TO 42
The second syntax, however, allows you to load characters starting from a specific position (42, in this case).

Code: Select all

DEFINE FONT COMPLETE
If desired, you can specify a starting font other than the standard one to begin working with. In this case, simply use the DEFINE FONT directive. The allowed parameters for DEFINE FONT are in the User Manual (see chapter 18.8.2).

Anyway, these instructions work with the PRINT command, which prints text in multiples of 8 pixels, vertically and horizontally, and is also subject to the limitations of the CONSOLE command. In the beta version, support for writing on the screen using a font of any size and in any vertical position has been added. The instruction is called GR PRINT, and must be used when loading an ATLAS. The syntax is as follows:

Code: Select all

font := LOAD ATLAS("fonts_4x8.png") FRAME SIZE(4,8)
GR PRINT "EXAMPLE" AT 42, 42 WITH font
pioj wrote: Sun Dec 21, 2025 7:50 am I'd like to display some text on the screen using a small font.
Note that writing with the PRINT command or equivalent maintains a minimum size of 8x8 pixels, while GR PRINT does not suffer from this limitation but, on the other hand, it may not be able to draw characters smaller than 8x8 pixels due to other limitations related to the graphics hardware. In fact, ugBASIC does not provide any kind of abstraction, and therefore does not guarantee that a functionality will be implemented identically everywhere.

I hope this helps! :)