Inside ArcadeSlam

The hardware

wiring
ArcadeSlam run on a TIMSP430 microcontroller. This little computer has 16kilobytes of program memory (ROM) and 512 bytes of data memory (RAM). Somewhat surprisingly this is sufficient to run the games (just about).
The display is a TFT LCD display with a resolution of 240×320. The display connects to the MSP430 using the high speed Serial Peripheral Interface (SPI). This greatly reduces the amount of wiring required but limits the write speed to the display (but only a little).
The remaining components are buttons, a couple of resistors to limit current flow, some wires and a breadboard to build it on.

How the code works
The code is based around a number of collections of related functions called interfaces. There are interfaces for the buttons, the display and for sprites. A “sprite” is a graphical object that plays a role in a game. It consists of an image and a number of functions to manipulate it on screen.

The button interface
SetupButtons() : Configures the port pins for use as button inputs
LeftPressed() : returns 1 if the left button was pressed. Otherwise returns 0.
RightPressed() : returns 1 if the right button was pressed. Otherwise returns 0.
FirePressed() : returns 1 if the fire button was pressed. Otherwise returns 0.

The Screen interface
putPixel( x, y, colour);
putImage( x, y, width, height, Image);
fillRectangle( x, y, width, height, Colour);
putText(Text, length, x, y, ForeColour, BackColour);
putNumber(Number, x, y, ForeColour, BackColour);

The Sprite interface
Sprite(Image, x, y, width, height) : This constructor builds the Sprite object. Supply an image, its dimensions and location
show() : show the sprite
hide() : hide the sprite
redraw() : redraw the sprite (useful if has been obscured by another sprite)
visible() : returns 1 is the sprite is visible, zero otherwise
move( x, y) : move the sprite to the new location
getX() : returns the current X location
getY() : returns the current Y location
getWidth() : returns the width of the sprite
getHeight() : returns the height of the sprite.
touching( x, y ) : returns 1 if the point specified by x,y is touching the edge of the sprite
within( x, y ) : returns 1 if the point specified by x,y is within the sprite

Advertisements