Software

Overview

The Game-o-Tron 3000 software is written in C and consists of two main parts: shared functions and games. The source for the sharded functions is in files starting "pl_" (for platform, because I hadn't thought of a name at that point) and the source files for the games are prefixed with "mode_". The menu system and option screens operate in the same way as the games and are named the same way.

When the device is switched on it first reads the settings for volume and brightness from the Teensy's EEPROM, initialises the display and sets up an interrupt to handle the audio. Once this is done the main loop starts executing which does a number of things:

  • Polls the buttons
  • Updates the audio
  • Changes the current mode (if required)
  • Calls the update function of the currrent mode

The "mode" refered to here is either a game, the menu system or the options menu. a mode update is an iteration of a typical game loop. i.e. update the game state and redraw the screen.

Shared functions

There isn't really an operating system as such, as each game has more or less full contol of the hardware, although it should return control to the main loop after each frame (see above). There are however a set of shared functions are provided for the following:

Video - Two options are provided for displaying graphics: a sixteen colour palettised bitmap mode and a two colour text mode. In both modes the data is held in RAM and the colours used can be changed. Functions are provided to write the data to the LCD. The two colour mode is used by the options menu only to reduce memory requirements as this can be called up at any time by pressing the options button and needs to run alongside a game or the menu system. Everything else uses the sixteem colour mode. Functions are also provided for filled or unfilled lines boxes or circles and there is a single built in font. In sixteen colour mode it is also possible to set a callback function that is called at the start of every horizontal line. This can get used to change colour palette entries to produce effects similar to the Amiga's "copper" co-processor. The main menu makes entensive use of this.

The game graphics were drawn in mtpaint and saved as .bmp files. I wrote a small program called bmpconv that would convert the.bmp files to a C data structure that could be included in the program source. The bmpconv program converts the bitmap data only, the colour palette entries are manually entered into the source code.

Audio - Audio is output on the Teensy's analogue out pin and runs in an interrupt handler. A simple player system is provided that can play a series of notes of different pitches and lengths. Square, sawtooth, triangle and noise waveforms are supports with basic envelope control, that is, attach and decay only.

Buttons - Buttons are connected to GPIO pins and are read on each update by a common routine. This keeps track of whether the buttons are currently up or down and whether they have been pressed or released since the last update.

Touchscreen - The LCD's touchscreen can be read but this is only used in the test mode at the moment, not in any of the games.

EEPROM - Functions are provided to read and write the EEPROM and this is used the store settings and game high scores.

Debugging - Some basic functions to allow debugging messages to be sent to the host development system.

Options menu

The options menu can be called up at any time by pressing the option button and allows you to change the brightness and volume. Execution of the current game is suspended whilst in option mode. Because the current game will probably be using sixteen colour mode, the options menu used two colour mode, otherwise there would not be enough memory.

Main Menu

The main manu consists of two screens: the startup screen that you get on power up and the game selection screen. The first one shows some basic information about the device and plays the startup jingle. The second one allows you to scroll through the list of games and start one.

Test Mode

Display some hardware test information including the state of the buttons and touchscreen.

Snake

The classic snake game with a bit of a twist: The numbers on the balls that you need to collect count down and if they reach zero they explode leaving a hole on the playing area that you cannot cross. This is a rewrite of a version of snake that I wrote in AMOS Basic on the Amiga many years ago (and appeared on AMOS PD disk 234).

Little Green Men

They're invading, possible from space. Better shoot them then.