Your #1 source for Atari Lynx news and information!
Atari GamerAtari GamerAtari Gamer
  1. Home >
  2. Articles >
  3. Making a 7-segment number font to use with CC65 for Atari Lynx games

Just prior to Easter this year I started work on a new LCD Game and Watch style game for Atari Lynx called Eggsavier's Cackleberry Rescue. Gameplay and objective in these types of games are very straight forward. In this case you have to catch falling eggs and action speeds up as you catch more and more eggs. The three different game types are differentiated by how many eggs can fall at one time.

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.


The source code for this font is available over on GitHub - demo/7segmentfont. The font has ten numbers - "0123456789" and it can display integer values from 0 to 65535. If you need to display larger numbers, you can always modify its draw routine to handle them. The provided functionality can draw the font in any direction, though the most common would be left-to-right and top-to-bottom.

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
Did we get something wrong or you have something to contribute? Please tell us about it!
Did you like what you just read? Please take a moment to see how you can support Atari Gamer. With your help we can keep this retro gaming website going and develop new content! Or just check out what else we have for you...
You can find Atari Gamer on...
Be sure to follow for the latest Atari Lynx news, updates, stories and photos!
[ Don't show again ][ Dismiss ]
Loading...
10
Find out how you can support Atari Gamer so we can keep delivering quality retro gaming content, news and amazing games to you!

If your download doesn't start automatically after 10 seconds, please click here.
Cookie Consent
By continuing to browse or by clicking ‘Accept’, you agree to storing of cookies on your device to enhance your site experience and for analytical purposes. To learn more about how we use cookies, please see our privacy policy.
Accept and Close