The 80C32 snake project was done in January 2007 in collaboration with Nina Mühleis as part of the Studies at Carl von Ossietzky University of Oldenburg. Aim of the project was to realize hardware-based, snake-like game. An adapter for a PS/2 keyboard as well as a LED matrix display was provided. The remaining system including software as well as hardware has to be build.
The game itself is implemented in C. The snake moves along the direction, given by the user by pressing the corresponding keys on the keyboard. While the snake moves across the board, some food appears. The food can be eaten by the snake, by running through it. Each time the snake eats a piece of food it grows and a new piece appears. If the snake hits the boarders of the board or its own body it dies and the game is over.
Heart of the system is the 80C32 micro controller from ATMEL. It runs at about 11 MHz and executes the software. The variables of the software are limited to 128 Bytes of RAM as this is the amount of RAM provided by the micro controller. The software itself is stored in an AT29C256 flash ROM also from ATMEL. Due to limitation of the micro controller the flash memory is accessed using a 74HC573 latch from Philips. The LED-matrix is memory mapped. Therefore, a GAL16V8 programmable logic device is used as address decoder to distinguish between accesses to the flash ROM and accesses to the LED-matrix.
The system is powered by a laboratory power supply, which delivers five volts as supply voltage. The user controls the game using a usual PS/2 keyboard, which is connected using a simple adapter that was provided. As display a 20-by-14 LED-matrix is used, which also has been provided.
The code of the key pressed by the user is captured by an ISR. This value is used to determine the direction the snake should move. On each movement the new position of the snakes head is calculated and collision detection with the borders of the board is performed. Subsequently collision detection with the body of the snake is performed. If a collision had occurred, the game is over and a new game starts immediately. If no collisions have occurred, the new head is added to the snake. If the snake has made a given number of moves, it grows. In this case only the head is added. Otherwise the tail of the snake is removed. So the snake has moved one position forward. All movements of the snake as well as the food are drawn to a frame buffer. This is displayed in on the LED-Matrix by a second ISR.
The application is implemented using C. It runs directly on the hardware with no underlying operation systems. High-level constructs as semaphores or the like are not available. Therefore, waiting is done by polling a hardware counter. That counter is used for determining the time between two consecutive steps of the snake. Besides the ISR for capturing the key-codes from the keyboard, a second ISR has been implemented. That particular ISR is responsible for drawing the frame buffer to the LED-matrix and is automatically triggered by a second hardware counter.