Your #1 source for Atari Lynx news and information!
Atari GamerAtari GamerAtari Gamer

We are moving all Atari Lynx related content over to Atari Lynx Vault and all our shop content over to K-Retro Gaming. Please update your bookmarks!

As a result of this change, the following will no longer be available: Online Lynx Emulator, Collection Tracker, Game Ratings, News. If you are interested in contributing content to Atari Lynx Vault, we are seeking editors and maintainers.

Why is this happening? First - the Atari Gamer branding is changing to K-Retro Gaming to allow us to expand to providing games, replacement parts, and mod services to other game consoles. And second - The content management system running Atari Gamer is out of date and Google AppEngine (where the website runs) will no longer allow it to run after the 30th January 2024, so in order to preserve all content we switched to a new and modern content management system and chose a website domain that better suits the subject matter. Since we are operating this website in our spare time, on top of full time family and job committments, some features had to be dropped.

  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!
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
We have an online shop that has lots of Atari Lynx related goodies - including LCD mod kits, flash carts, display stands and other fun things for your Lynx! Check it out here.

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