Wanting to stick true to the design of the original G&W style games and their segmented style LCD displays, I didn't want to use the generic font that the TGI driver bundled with CC65 had. So, based on the Haiku font for Atari Lynx, I decided to create a number-only 7-segment font to use in my game and now I've updated some of the functionality to make it more universal.
Each of the segments is made up of a 5x9 sprite. This isn't the most optimal way of storing this font, but it works. I'm also using 4 bits per pixel, which isn't necessary and can be reduced to 1 bit per pixel if you really need to reduce how much memory is taken up. The reason I went with this approach is so I can reuse the colour palette that the rest of my game used and since the game was so small I wasn't too worried about wasting some memory.
I drew each of the segments in GIMP and exported them as BMP files. These were converted using sprpck into sprite data. Inside the code I had an array of all of the SCBs as the SCB_RENONE struct, which was the simplest I could use. To draw a number, the draw7SegNumber() function is used. This function requires the x and y coordinates to start drawing at, as well as the x and y width/spacing to leave between each digit. You can create overlapping numbers this way, but you can also draw diagonally if you really wanted to. The final parameter is an integer value to draw.
Here's an example of how it's used...draw7SegNumber(3, 40, 7, 0, 123);
This will draw the number "123" starting at the (3, 40) screen position with 7px horizontal spacing between each digit and no vertical spacing.
When drawing digits, the input number has to be broken down to its components e.g. "123" is split into "1", "2" and "3". Due to how this is achieved, we actually get the sequence "3", "2", "1". So to get numbers looking right on screen, they are drawn in reverse order. Each digit is drawn as a sprite and since its corresponding SCB is created with the REUSEPAL flag, it will reuse the currently selected palette.
Because the Atari Lynx sprite engine requires a palette to be set in the first place, if the first thing we do is draw a 7-segment number, the results will probably not show up. For this reason, the set7SegColor() function must be called to set the colour of the digits. This function manipulates the current palette mapping to set the 0xB nibble to the colour we want to use. This is done by drawing a 1-pixel off-screen sprite that defines a palette to use. The reason the 0xB nibble is set is simply because the original BMP file uses the 0xB (position 12) value for the colour index for each of the segments.
Here's an example on setting/changing colours of the digits...set7SegColor(2);
That's all there is to it. I might change the font in the future to optimise it for memory a little better, if I do, this article will be updated.-AG