A test program which communicates with a Gameduino shield and writes some text on a VGA display.

Dependencies:   Gameduino CommonTypes mbed

Simple test program to show how to use the Gameduino library.

Files at this revision

API Documentation at this revision

Comitter:
RichardE
Date:
Wed Nov 07 21:37:21 2012 +0000
Child:
1:cca56a112665
Commit message:
Simple test program which uses a Gameduino to write some text on a VGA display.

Changed in this revision

Gameduino.cpp Show annotated file Show diff for this revision Revisions of this file
Gameduino.h Show annotated file Show diff for this revision Revisions of this file
Types.h Show annotated file Show diff for this revision Revisions of this file
font8x8.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Gameduino.cpp	Wed Nov 07 21:37:21 2012 +0000
@@ -0,0 +1,394 @@
+/*
+ * SOURCE FILE : Gameduino.cpp
+ *
+ * Definition of class Gameduino.
+ * Each instance of this class allows communication with
+ * a Gameduino shield over an SPI communications link.
+ *
+ */
+
+#include "Gameduino.h"      // this module's prototypes
+#include "font8x8.h"        // default font
+
+/***************/
+/* CONSTRUCTOR */
+/***************/
+// Pass pointer to SPI datalink in spi.
+// Pass pointer to chip select in cs.
+Gameduino::Gameduino( SPI *spi, DigitalOut *cs ) :
+    spi( spi ),
+    cs( cs ),
+    spr( 0 )
+{
+}
+
+/**************/
+/* DESTRUCTOR */
+/**************/
+Gameduino::~Gameduino() {
+}
+
+/*****************************************************/
+/* INITIALISE CONNECTION TO ADAPTER AND RESET THINGS */
+/*****************************************************/
+void Gameduino::begin( void ) {
+    // Wait a bit to allow Gameduino to boot.
+    wait_ms( 250 );
+    // Deselect the Gameduino.
+    *cs = 1;
+    wr( J1_RESET, 1 );               // HALT coprocessor
+    wr( VIDEO_MODE, MODE_800x600_72 );
+    __wstart( RAM_SPR );             // Hide all sprites
+    for( int i = 0; i < 512; i++ ) {
+        xhide();
+    }
+    __end();
+    fill( RAM_PIC, 0, 1024 * 10 );  // Zero all character RAM
+    fill( RAM_SPRPAL, 0, 2048 );    // Sprite palletes black
+    fill( RAM_SPRIMG, 0, 64 * 256 );// Clear all sprite data
+    fill( VOICES, 0, 256 );         // Silence
+    fill( PALETTE16A, 0, 128 );     // Black 16-, 4-palletes and COMM
+    wr16( SCROLL_X, 0 );
+    wr16( SCROLL_Y, 0 );
+    wr( JK_MODE, 0 );
+    wr( SPR_DISABLE, 0 );
+    wr( SPR_PAGE, 0 );
+    wr( IOMODE, 0 );
+    wr16( BG_COLOR, 0 );
+    wr16( SAMPLE_L, 0 );
+    wr16( SAMPLE_R, 0 );
+    wr16( SCREENSHOT_Y, 0 );
+    wr( MODULATOR, 64 );
+}
+
+static const UInt8 stretch[16] = {
+  0x00, 0x03, 0x0c, 0x0f,
+  0x30, 0x33, 0x3c, 0x3f,
+  0xc0, 0xc3, 0xcc, 0xcf,
+  0xf0, 0xf3, 0xfc, 0xff
+};
+
+/***********************************************/
+/* SET DEFAULT ASCII CHARACTER SET AND PALETTE */
+/***********************************************/
+void Gameduino::ascii( void ) {
+    UInt8 b, h, l;
+    UInt16 address;
+    const UInt8 *ptr = font8x8;
+    for( UInt16 i = 0; i < 768; ++i ) {
+        b = *ptr++;
+        h = stretch[ b >> 4 ];
+        l = stretch[ b & 0xf ];
+        address = RAM_CHR + ( ' ' << 4 ) + ( i << 1 );
+        wr( address++, h );
+        wr( address, l );
+    }
+    for( UInt16 i = 0x20; i < 0x80; ++ i) {
+        setpal( 4 * i + 0, TRANSPARENT );
+        setpal( 4 * i + 3, RGB (255, 255, 255 ) );
+    }
+    fill( RAM_PIC, ' ', 4096 );
+}
+
+/****************************/
+/* START AN SPI TRANSACTION */
+/****************************/
+// Pass address to read or write to in address.
+// Bit 15 must be set for a write.
+void Gameduino::__start( UInt16 address ) {
+    *cs = 0;                                // select Gameduino
+    spi->write( ( address >> 8 ) & 0xFF );  // send bits 8 to 15 of address
+    spi->write( address & 0xFF );           // send bits 0 to 7 of address
+}
+
+/**********************************/
+/* START AN SPI WRITE TRANSACTION */
+/**********************************/
+// Pass address write to in address.
+void Gameduino::__wstart( UInt16 address ) {
+    __start( 0x8000 | address );
+}
+
+/******************************/
+/* START A SPRITE TRANSACTION */
+/******************************/
+// Use this before calling xhide, xsprite or TransferSprite.
+// Pass sprite number to start at in sprnum.
+void Gameduino::__wstartspr( UInt8 sprnum ) {
+    __wstart( RAM_SPR + ( sprnum << 2 ) );
+    spr = 0;
+}
+
+/*************************/
+/* TRANSFER BYTE VIA SPI */
+/*************************/
+// Use only after a call to __start or __wstart.
+// Pass data to send in data.
+UInt8 Gameduino::__tr8( UInt8 data ) {
+    return (UInt8)spi->write( data );
+}
+
+/********************************/
+/* TRANSFER 16 BIT WORD VIA SPI */
+/********************************/
+// Use only after a call to __start or __wstart.
+// Pass data to send in data.
+UInt8 Gameduino::__tr16( UInt16 data ) {
+    UInt16 result;
+    result = spi->write( data & 0xFF );                         // send and get bits 0 to 7
+    result |= ( spi->write( ( data >> 8 ) & 0xFF ) << 8 );      // send and get bits 8 to 15
+    return result;                          // return word read    
+}
+
+/**************************/
+/* END AN SPI TRANSACTION */
+/**************************/
+void Gameduino::__end( void ) {
+    *cs = 1;                                // deselect Gameduino
+}
+    
+/***************/
+/* READ A BYTE */
+/***************/
+// Pass address in Gameduino memory to read from.
+// Returns byte at that address.    
+UInt8 Gameduino::rd( UInt16 address ) {
+    __start( address );                     // start SPI read operation
+    UInt8 data = __tr8( 0 );                // read byte from Gameduino
+    __end();                                // end of SPI operation
+    return data;                            // return byte read
+}
+
+/**********************/
+/* READ A 16 BIT WORD */
+/**********************/
+// Pass address in Gameduino memory to read from.
+// Returns byte at that address.    
+UInt16 Gameduino::rd16( UInt16 address ) {
+    __start( address );                     // start SPI read operation
+    UInt16 data = __tr16( 0 );
+    __end();                                // end of SPI operation
+    return data;                            // return word read    
+}
+
+/****************/
+/* WRITE A BYTE */
+/****************/
+// Pass address to write to in address.
+// Pass data to write in data.
+void Gameduino::wr( UInt16 address, UInt8 data ) {
+    __wstart( address );                    // start SPI write operation
+    __tr8( data );
+    __end();                                // end of SPI operation
+}
+
+/***********************/
+/* WRITE A 16 BIT WORD */
+/***********************/
+// Pass address to write to in address.
+// Pass data to write in data.
+void Gameduino::wr16( UInt16 address, UInt16 data ) {
+    __wstart( address );
+    __tr16( data );
+    __end();
+}
+
+/*********************************/
+/* FILL AREA OF GAMEDUINO MEMORY */
+/*********************************/
+// Pass address to write to in address.
+// Pass data to write to entire area in data.
+// Pass number of bytes to write in count.
+void Gameduino::fill( UInt16 address, UInt8 data, UInt16 count ) {
+    __wstart( address );
+    while( count-- ) {
+        __tr8( data );
+    }
+    __end();
+}
+
+/***********************************/
+/* COPY DATA INTO GAMEDUINO MEMORY */
+/***********************************/
+// Pass address to write to in address.
+// Pass pointer to source of data in src.
+// Pass number of bytes to copy in count.
+void Gameduino::copy( UInt16 address, const UInt8 *src, UInt16 count ) {
+    __wstart( address );
+    while( count-- ) {
+        __tr8( *src++ );
+    }
+    __end();
+}
+
+/*****************/
+/* HIDE A SPRITE */
+/*****************/
+// Use only after specifying address to write to.
+// Basically just writes 400 twice to SPI.
+void Gameduino::xhide( void ) {
+    __tr16( 400 );
+    __tr16( 400 );
+    spr++;
+}
+
+/****************************************/
+/* SEND SPRITE INFORMATION TO GAMEDUINO */
+/****************************************/
+// Use only after specifying address to write to.
+// Pass coordinates in x and y.
+// Pass sprite image number in image.
+// Pass palette selection information in palette (use 0 for 256 colour palette).
+// Pass rotation and flip setting in rot.
+// Pass JK collision information in jk (0 or 1).
+void Gameduino::TransferSprite( Int16 x, Int16 y, UInt8 image, UInt8 palette, Rotation rot, UInt8 jk ) {
+    __tr8( x & 0xFF );
+    __tr8( ( palette << 4 ) | ( rot << 1 ) | ( ( x >> 8 ) & 1 ) );
+    __tr8( y & 0xFF );
+    __tr8( ( jk << 7 ) | ( image << 1 ) | ( ( y >> 8 ) & 1 ) );
+}
+
+/**************************************************************************/
+/* DRAW A SPRITE AT AN OFFSET FROM AN ORIGIN TAKING INTO ACCOUNT ROTATION */
+/**************************************************************************/
+// Use only after specifying address to write to.
+// Pass origin coordinates in ox and oy.
+// Pass offset from origin in x and y.
+// Pass sprite image number in image.
+// Pass palette selection information in palette (use 0 for 256 colour palette).
+// Pass rotation and flip setting in rot.
+// Pass JK collision information in jk (0 or 1).
+void Gameduino::xsprite( Int16 ox, Int16 oy, Int8 x, Int8 y, UInt8 image, UInt8 palette, Rotation rot, UInt8 jk ) {
+    if( rot & 2 ) {
+        // Flip X.
+        x = -16 - x;
+    }
+    if( rot & 4 ) {
+        // Flip Y.
+        y = -16 - y;
+    }
+    if( rot & 1 ) {
+        // Swap X and Y.
+        int s;
+        s = x; x = y; y = s;
+    }
+    ox += x;
+    oy += y;
+    TransferSprite( ox, oy, image, palette, rot, jk );
+    spr++;
+}
+
+/***********************/
+/* CONSTRUCT RGB VALUE */
+/***********************/
+// Pass red level in r.
+// Pass green level in g.
+// Pass blue level in b.
+// Returns RGB value.
+UInt16 Gameduino::RGB( UInt8 r, UInt8 g, UInt8 b ) {
+    return ((((r) >> 3) << 10) | (((g) >> 3) << 5) | ((b) >> 3));
+}
+
+/*********************/
+/* SET PALETTE ENTRY */
+/*********************/
+// Pass pallete entry to set in pal.
+// Pass RGB value to store in rgb.
+void Gameduino::setpal( UInt16 pal, UInt16 rgb ) {
+    wr16( RAM_PAL + ( pal << 1 ), rgb );
+}
+
+/***********************************/
+/* WRITE TEXT AT GIVEN COORDINATES */
+/***********************************/
+// Pass X coordinate in x.
+// Pass Y coordinate in y.
+// Pass pointer to zero terminated text in s.
+void Gameduino::putstr( UInt8 x, UInt8 y, const char *s ) {
+    __wstart( RAM_PIC + ( y << 6 ) + x );
+    while( *s ) {
+        __tr8( *s++ );
+    }
+    __end();
+}
+
+/*********************/
+/* POSITION A SPRITE */
+/*********************/
+// Pass sprite number in spr.
+// Pass X and Y coordinates in x and y.
+// Pass sprite image number in image.
+// Pass palette selection information in palette (use 0 for 256 colour palette).
+// Pass rotation and flip setting in rot.
+// Pass JK collision information in jk (0 or 1).
+void Gameduino::sprite( UInt8 spr, Int16 x, Int16 y, UInt8 image, UInt8 palette, Rotation rot, UInt8 jk ) {
+    __wstart( RAM_SPR + ( spr << 2 ) );
+    TransferSprite( x, y, image, palette, rot, jk );
+    __end();
+}
+
+/***********************************/
+/* DRAW 4 SPRITES AS A 2 X 2 BLOCK */
+/***********************************/
+// Pass sprite number for first sprite in spr.
+// Pass X and Y coordinates in x and y. These are coordinates of centre of group.
+// Pass sprite image number for first image in image.
+// Pass palette selection information in palette (use 0 for 256 colour palette).
+// Pass rotation and flip setting in rot.
+// Pass JK collision information in jk (0 or 1).
+void Gameduino::sprite2x2( UInt8 spr, Int16 x, Int16 y, UInt8 image, UInt8 palette, Rotation rot, UInt8 jk ) {
+    __wstart( RAM_SPR + ( spr << 2 ) );
+    xsprite( x, y, -16, -16, image + 0, palette, rot, jk );
+    xsprite( x, y,   0, -16, image + 1, palette, rot, jk );
+    xsprite( x, y, -16,   0, image + 2, palette, rot, jk );
+    xsprite( x, y,   0,   0, image + 3, palette, rot, jk );
+    __end();
+}
+
+/**************************************************/
+/* PLOT A NUMBER OF SPRITES RELATIVE TO AN ORIGIN */
+/**************************************************/
+// Use only after calling __wstartspr.
+// Pass X and Y coordinates of origin in ox and oy.
+// Pass pointer to an array of sprplot structures in psp.
+// Pass number of structures in array in count.
+// Pass rotation and flip setting in rot.
+// Pass JK collision information in jk (0 or 1).
+void Gameduino::plots( Int16 ox, Int16 oy, const sprplot *psp, UInt8 count, Rotation rot, UInt8 jk ) {
+    while( count-- ) {
+        xsprite( ox, oy, psp->x, psp->y, psp->image, psp->palette, rot, jk );
+        psp++;
+    }
+}
+
+/******************************/
+/* WAIT FOR VERTICAL BLANKING */
+/******************************/
+void Gameduino::waitvblank( void ) {
+    // Wait until VBLANK register is zero.
+    while( rd( VBLANK ) ) {
+        // do nothing.
+    }
+    // Wait until VBLANK register is non-zero.
+    while( ! rd( VBLANK ) ) {
+        // do nothing.
+    }
+    // Exit just at the moment VBLANK goes from zero to non-zero.
+}
+
+/****************/
+/* MAKE A NOISE */
+/****************/
+// Pass voice number in v.
+// Pass waveform type in wave.
+// Pass frequency in quarter Hz (so 100 Hz is 400) in freq.
+// Pass amplitude for left channel in lamp.
+// Pass amplitude for right channel in ramp.
+void Gameduino::voice( UInt8 v, WaveForm wave, UInt16 freq, UInt8 lamp, UInt8 ramp ) {
+    __wstart( VOICES + ( v << 2 ) );
+    __tr8( freq & 0xFF );
+    __tr8( ( ( freq >> 8 ) & 0xFF ) | ( wave << 7 ) );
+    __tr8( lamp );
+    __tr8( ramp );
+    __end();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Gameduino.h	Wed Nov 07 21:37:21 2012 +0000
@@ -0,0 +1,350 @@
+/*
+ * SOURCE FILE : Gameduino.h
+ *
+ * Definition of class Gameduino.
+ * Each instance of this class allows communication with
+ * a Gameduino shield over an SPI communications link.
+ *
+ */
+
+#ifndef GameduinoDefined
+
+  #define GameduinoDefined
+
+  #include "mbed.h"     // mbed library
+  #include "Types.h"    // integer types
+  
+  // These #defines allow you to use data arrays from an Arduino background that make
+  // use of program memory.
+  #define PROGMEM const
+  #define prog_uchar UInt8
+  
+/** Gameduino class to support SPI communications with the Gameduino game adapter
+ *
+ * Example:
+ * @code
+ * #include "mbed.h"
+ * #include "Gameduino.h"
+ * 
+ * int main() {
+ *     // Make a digital output for use with Gameduino.
+ *     DigitalOut cs( p8 );
+ *     // Initialise an SPI link for communications with Gameduino.
+ *     // Use pin 5 for MOSI.
+ *     // Use pin 6 for MISO.
+ *     // Use pin 7 for SCK.
+ *     SPI spi( p5, p6, p7 );
+ *     // 8MHz clock should be OK.
+ *     spi.frequency( 8000000 );
+ *     // Set SPI format to use.
+ *     // Use 8 bits per SPI frame.
+ *     // Use SPI mode 0.
+ *     spi.format( 8, 0 );
+ *     // Make a Gameduino and pass SPI link and digital output for chip select.
+ *     Gameduino gd( &spi, &cs );
+ *     // Reset the Gameduino.
+ *     gd.begin();
+ *     // Lets have a default ASCII character set.
+ *     gd.ascii();
+ *     // Write something to character memory.
+ *     gd.__wstart( Gameduino::RAM_PIC );
+ *     for( UInt8 c = 'A'; c <= 'Z'; ++c ) {
+ *         gd.__tr8( c );
+ *     }
+ *     gd.__end();
+ *     // Test copy method.
+ *     UInt8 copyData[] = "HELLO";
+ *     gd.copy( Gameduino::RAM_PIC + 64, copyData, 5 );
+ *     // Test putstr method.
+ *     gd.putstr( 3, 10, "Ambidextrous!" );
+ *     // Finished with Gameduino.
+ *     gd.end();
+ * }
+ * @endcode
+ */
+  class Gameduino {
+
+  public :
+
+    // Registers on Gameduino.
+    enum Reg {
+        RAM_PIC         = 0x0000,    // Screen Picture, 64 x 64 = 4096 bytes
+        RAM_CHR         = 0x1000,    // Screen Characters, 256 x 16 = 4096 bytes
+        RAM_PAL         = 0x2000,    // Screen Character Palette, 256 x 8 = 2048 bytes
+        IDENT           = 0x2800,
+        REV             = 0x2801,
+        FRAME           = 0x2802,
+        VBLANK          = 0x2803,
+        SCROLL_X        = 0x2804,
+        SCROLL_Y        = 0x2806,
+        JK_MODE         = 0x2808,
+        J1_RESET        = 0x2809,
+        SPR_DISABLE     = 0x280a,
+        SPR_PAGE        = 0x280b,
+        IOMODE          = 0x280c,
+        BG_COLOR        = 0x280e,
+        SAMPLE_L        = 0x2810,
+        SAMPLE_R        = 0x2812,
+        MODULATOR       = 0x2814,
+        VIDEO_MODE      = 0x2815,
+        SCREENSHOT_Y    = 0x281e,
+        PALETTE16A      = 0x2840,   // 16-color palette RAM A, 32 bytes
+        PALETTE16B      = 0x2860,   // 16-color palette RAM B, 32 bytes
+        PALETTE4A       = 0x2880,   // 4-color palette RAM A, 8 bytes
+        PALETTE4B       = 0x2888,   // 4-color palette RAM A, 8 bytes
+        COMM            = 0x2890,   // Communication buffer
+        COLLISION       = 0x2900,   // Collision detection RAM, 256 bytes
+        VOICES          = 0x2a00,   // Voice controls
+        J1_CODE         = 0x2b00,   // J1 coprocessor microcode RAM
+        SCREENSHOT      = 0x2c00,   // screenshot line RAM
+        RAM_SPR         = 0x3000,   // Sprite Control, 512 x 4 = 2048 bytes
+        RAM_SPRPAL      = 0x3800,   // Sprite Palettes, 4 x 256 = 2048 bytes
+        RAM_SPRIMG      = 0x4000,   // Sprite Image, 64 x 256 = 16384 bytes
+    };
+
+    // Modes of operation.
+    enum Mode {
+        MODE_800x600_72  = 0,
+        MODE_800x600_60  = 1,
+    };
+
+    // Sprite rotations.
+    enum Rotation {
+        None = 0,
+        SwapXY = 1,
+        FlipX = 2,
+        FlipXSwapXY = 3,
+        FlipY = 4,
+        FlipYSwapXY = 5,
+        FlipYFlipX = 6,
+        FlipYFlipXSwapXY = 7,
+    };
+    
+    // Sound waveforms used with voice method.
+    enum WaveForm {
+        SineWave,
+        WhiteNoise,
+    };
+    
+    // Other constants.
+    enum {
+        TRANSPARENT     = ( 1 << 15 ),
+    };
+    
+    // Structure used with plots method.
+    struct sprplot {
+        Int8 x, y;              // offsets from origin
+        UInt8 image, palette;   // sprite image number and palette information
+    };
+    
+    /** Constructor.
+     * @param spi Pointer to SPI datalink to use for comms.
+     * @param cs Pointer to digital output used Gameduino as chip select. 
+     */
+    Gameduino( SPI *spi, DigitalOut *cs );
+
+    /** Destructor.
+     */
+    virtual ~Gameduino();
+    
+    /** Initialise connection to adapter and reset things.
+     */
+    void begin( void );
+    
+    /** Close down connection.
+     */
+    void end( void ) {
+        // Can't think of anything to do.
+    }
+    
+    /** Set default ASCII character set and palette.
+     */
+    void ascii( void );
+    
+    /** Start an SPI transaction.
+     *
+     * @param address Address to read or write to. Bit 15 must be set for a write.
+     */
+    void __start( UInt16 address );
+    
+    /** Start an SPI write transaction.
+     *
+     * @param address Address to write to.
+     */
+    void __wstart( UInt16 address );
+    
+    /** Start a sprite transaction.
+     * Use this before calling xhide, xsprite or TransferSprite.
+     * @param sprnum Sprite number to start at.
+     */
+    void __wstartspr( UInt8 sprnum );
+    
+    /** Transfer byte via SPI.
+     * Use only after a call to __start or __wstart.
+     * @param data Data to send.
+     */
+    UInt8 __tr8( UInt8 data );
+    
+    /** Transfer 16 bit word via SPI.
+     * Use only after a call to __start or __wstart.
+     * @param data Data to send.
+     */
+    UInt8 __tr16( UInt16 data );
+
+    /** End an SPI transaction.
+     */
+    void __end( void );
+    
+    /** Read a byte.
+     * @param address Address in Gameduino memory to read from.
+     * @param returns Byte at that address.    
+     */
+    UInt8 rd( UInt16 address );
+    
+    /** Read a 16 bit word.
+     * @param address Address in Gameduino memory to read from.
+     * @param returns Word at that address.    
+     */
+    UInt16 rd16( UInt16 address );
+    
+    /** Write a byte.
+     * @param address Address to write to.
+     * @param data Data to write.
+     */
+    void wr( UInt16 address, UInt8 data );
+    
+    /** Write a 16 bit word.
+     * @param address Address to write to.
+     * @param data Data to write.
+     */
+    void wr16( UInt16 address, UInt16 data );
+
+    /** Fill area of Gameduino memory.
+     * @param address Address to write to.
+     * @param data Data to write to entire area.
+     * @param count Number of bytes to write.
+     */
+    void fill( UInt16 address, UInt8 data, UInt16 count );
+    
+    /** Copy data into Gameduino memory.
+     * @param address Address to write to.
+     * @param src Pointer to data to copy from.
+     * @param count Number of bytes to write.
+     */
+    void copy( UInt16 address, const UInt8 *src, UInt16 count );
+    
+    /** Hide a sprite.
+     * Use only after specifying address to write to.
+     * Basically just writes 400 twice to SPI.
+     */
+    void xhide( void );
+
+    /** Send sprite information to Gameduino.
+     * Use only after specifying address to write to.
+     * @param x X coordinate.
+     * @param y Y coordinate.
+     * @param image Sprite image number.
+     * @param palette Palette selection information (use 0 for 256 colour palette).
+     * @param rot Rotation and flip setting.
+     * @param jk JK collision information.
+     */
+    void TransferSprite( Int16 x, Int16 y, UInt8 image, UInt8 palette, Rotation rot=None, UInt8 jk=0 );
+
+    /** Draw a sprite at an offset from an origin taking into account rotation.
+     * Use only after specifying address to write to.
+     * @param ox Origin X coordinate.
+     * @param oy Origin Y coordinate.
+     * @param x X offset from origin.
+     * @param y Y offset from origin.
+     * @param image Sprite image number.
+     * @param palette Palette selection information (use 0 for 256 colour palette).
+     * @param rot Rotation and flip setting.
+     * @param jk JK collision information.
+     */
+    void xsprite( Int16 ox, Int16 oy, Int8 x, Int8 y, UInt8 image, UInt8 palette, Rotation rot=None, UInt8 jk=0 );
+    
+    /** Construct RGB value.
+     * @param r Red level.
+     * @param g Green level.
+     * @param b Blue level.
+     * @param returns RGB value.
+     */
+    static UInt16 RGB( UInt8 r, UInt8 g, UInt8 b );
+
+    /** Set palette entry.
+     * @param Pallete entry.
+     * @param rgb RGB value to store.
+     */
+    void setpal( UInt16 pal, UInt16 rgb );
+
+    /** Write text at given coordinates.
+     * @param x X coordinate.
+     * @param y Y coordinate.
+     * @param s pointer to zero terminated text.
+     */
+    void putstr( UInt8 x, UInt8 y, const char *s );
+
+    /** Position a sprite.
+     * @param spr Sprite number.
+     * @param x X coordinate.
+     * @param y Y coordinate.
+     * @param image Sprite image number.
+     * @param palette Palette selection information (use 0 for 256 colour palette).
+     * @param rot Rotation and flip setting.
+     * @param jk JK collision information.
+     */
+    void sprite( UInt8 spr, Int16 x, Int16 y, UInt8 image, UInt8 palette, Rotation rot=None, UInt8 jk=0 );
+
+    /** Draw 4 sprites as a 2 by 2 block.
+     * @param spr Sprite number for first sprite.
+     * @param x X coordinate for centre of group.
+     * @param y Y coordinate for centre of group.
+     * @param image Sprite image number for first image.
+     * @param palette Palette selection information (use 0 for 256 colour palette).
+     * @param rot Rotation and flip setting.
+     * @param jk JK collision information.
+     */
+    void sprite2x2( UInt8 spr, Int16 x, Int16 y, UInt8 image, UInt8 palette, Rotation rot=None, UInt8 jk=0 );
+
+    /** Plot a number of sprites relative to an origin.
+     * @param x X coordinate of origin.
+     * @param y Y coordinate of origin.
+     * @param psp Pointer to an array of sprplot structures.
+     * @param count Number of structures in the psp array.
+     * @param rot Rotation and flip setting.
+     * @param jk JK collision information.
+     */
+    void plots( Int16 ox, Int16 oy, const sprplot *psp, UInt8 count, Rotation rot=None, UInt8 jk=0 );
+    
+    /** Wait for vertical blanking.
+     */
+    void waitvblank( void );
+
+    /****************/
+    /* MAKE A NOISE */
+    /****************/
+    /** Make a noise.
+     * @param v Voice number.
+     * @param wave Waveform type.
+     * @param freq Frequency in quarter Hz (so 100 Hz is 400).
+     * @param lamp Amplitude for left channel.
+     * @param ramp Amplitude for right channel.
+     */
+    void voice( UInt8 v, WaveForm wave, UInt16 freq, UInt8 lamp, UInt8 ramp );
+                       
+  private :
+  
+    // Pointer to SPI datalink.
+    SPI *spi;
+    
+    // Pointer to chip select digital output.
+    DigitalOut *cs;  
+
+    // Current sprite. Used by xsprite and xhide etc.
+    UInt8 spr;
+    
+  };
+
+#endif
+
+/* END of Gameduino.h */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Types.h	Wed Nov 07 21:37:21 2012 +0000
@@ -0,0 +1,22 @@
+/*
+ * SOURCE FILE : Types.h
+ *
+ * Various types defined for portability.
+ *
+ */
+
+#ifndef TypesIncluded
+  
+  #define TypesIncluded
+
+  typedef unsigned char UInt8;
+  typedef signed char Int8;
+  typedef unsigned short UInt16;
+  typedef signed short Int16;
+  typedef unsigned long UInt32;
+  typedef signed long Int32;
+  
+#endif
+
+/* END of Types.h */
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/font8x8.h	Wed Nov 07 21:37:21 2012 +0000
@@ -0,0 +1,53 @@
+static const UInt8 font8x8[] = {
+
+0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x18,  0x18,  0x18,  0x18,  0x18,  0x00,  0x18,  0x00, 
+0x6c,  0x6c,  0x6c,  0x00,  0x00,  0x00,  0x00,  0x00,  0x36,  0x36,  0x7f,  0x36,  0x7f,  0x36,  0x36,  0x00, 
+0x0c,  0x3f,  0x68,  0x3e,  0x0b,  0x7e,  0x18,  0x00,  0x60,  0x66,  0x0c,  0x18,  0x30,  0x66,  0x06,  0x00, 
+0x38,  0x6c,  0x6c,  0x38,  0x6d,  0x66,  0x3b,  0x00,  0x0c,  0x18,  0x30,  0x00,  0x00,  0x00,  0x00,  0x00, 
+0x0c,  0x18,  0x30,  0x30,  0x30,  0x18,  0x0c,  0x00,  0x30,  0x18,  0x0c,  0x0c,  0x0c,  0x18,  0x30,  0x00, 
+0x00,  0x18,  0x7e,  0x3c,  0x7e,  0x18,  0x00,  0x00,  0x00,  0x18,  0x18,  0x7e,  0x18,  0x18,  0x00,  0x00, 
+0x00,  0x00,  0x00,  0x00,  0x00,  0x18,  0x18,  0x30,  0x00,  0x00,  0x00,  0x7e,  0x00,  0x00,  0x00,  0x00, 
+0x00,  0x00,  0x00,  0x00,  0x00,  0x18,  0x18,  0x00,  0x00,  0x06,  0x0c,  0x18,  0x30,  0x60,  0x00,  0x00, 
+0x3c,  0x66,  0x6e,  0x7e,  0x76,  0x66,  0x3c,  0x00,  0x18,  0x38,  0x18,  0x18,  0x18,  0x18,  0x7e,  0x00, 
+0x3c,  0x66,  0x06,  0x0c,  0x18,  0x30,  0x7e,  0x00,  0x3c,  0x66,  0x06,  0x1c,  0x06,  0x66,  0x3c,  0x00, 
+0x0c,  0x1c,  0x3c,  0x6c,  0x7e,  0x0c,  0x0c,  0x00,  0x7e,  0x60,  0x7c,  0x06,  0x06,  0x66,  0x3c,  0x00, 
+0x1c,  0x30,  0x60,  0x7c,  0x66,  0x66,  0x3c,  0x00,  0x7e,  0x06,  0x0c,  0x18,  0x30,  0x30,  0x30,  0x00, 
+0x3c,  0x66,  0x66,  0x3c,  0x66,  0x66,  0x3c,  0x00,  0x3c,  0x66,  0x66,  0x3e,  0x06,  0x0c,  0x38,  0x00, 
+0x00,  0x00,  0x18,  0x18,  0x00,  0x18,  0x18,  0x00,  0x00,  0x00,  0x18,  0x18,  0x00,  0x18,  0x18,  0x30, 
+0x0c,  0x18,  0x30,  0x60,  0x30,  0x18,  0x0c,  0x00,  0x00,  0x00,  0x7e,  0x00,  0x7e,  0x00,  0x00,  0x00, 
+0x30,  0x18,  0x0c,  0x06,  0x0c,  0x18,  0x30,  0x00,  0x3c,  0x66,  0x0c,  0x18,  0x18,  0x00,  0x18,  0x00, 
+
+0x3c,  0x66,  0x6e,  0x6a,  0x6e,  0x60,  0x3c,  0x00,  0x3c,  0x66,  0x66,  0x7e,  0x66,  0x66,  0x66,  0x00, 
+0x7c,  0x66,  0x66,  0x7c,  0x66,  0x66,  0x7c,  0x00,  0x3c,  0x66,  0x60,  0x60,  0x60,  0x66,  0x3c,  0x00, 
+0x78,  0x6c,  0x66,  0x66,  0x66,  0x6c,  0x78,  0x00,  0x7e,  0x60,  0x60,  0x7c,  0x60,  0x60,  0x7e,  0x00, 
+0x7e,  0x60,  0x60,  0x7c,  0x60,  0x60,  0x60,  0x00,  0x3c,  0x66,  0x60,  0x6e,  0x66,  0x66,  0x3c,  0x00, 
+0x66,  0x66,  0x66,  0x7e,  0x66,  0x66,  0x66,  0x00,  0x7e,  0x18,  0x18,  0x18,  0x18,  0x18,  0x7e,  0x00, 
+0x3e,  0x0c,  0x0c,  0x0c,  0x0c,  0x6c,  0x38,  0x00,  0x66,  0x6c,  0x78,  0x70,  0x78,  0x6c,  0x66,  0x00, 
+0x60,  0x60,  0x60,  0x60,  0x60,  0x60,  0x7e,  0x00,  0x63,  0x77,  0x7f,  0x6b,  0x6b,  0x63,  0x63,  0x00, 
+0x66,  0x66,  0x76,  0x7e,  0x6e,  0x66,  0x66,  0x00,  0x3c,  0x66,  0x66,  0x66,  0x66,  0x66,  0x3c,  0x00, 
+0x7c,  0x66,  0x66,  0x7c,  0x60,  0x60,  0x60,  0x00,  0x3c,  0x66,  0x66,  0x66,  0x6a,  0x6c,  0x36,  0x00, 
+0x7c,  0x66,  0x66,  0x7c,  0x6c,  0x66,  0x66,  0x00,  0x3c,  0x66,  0x60,  0x3c,  0x06,  0x66,  0x3c,  0x00, 
+0x7e,  0x18,  0x18,  0x18,  0x18,  0x18,  0x18,  0x00,  0x66,  0x66,  0x66,  0x66,  0x66,  0x66,  0x3c,  0x00, 
+0x66,  0x66,  0x66,  0x66,  0x66,  0x3c,  0x18,  0x00,  0x63,  0x63,  0x6b,  0x6b,  0x7f,  0x77,  0x63,  0x00, 
+0x66,  0x66,  0x3c,  0x18,  0x3c,  0x66,  0x66,  0x00,  0x66,  0x66,  0x66,  0x3c,  0x18,  0x18,  0x18,  0x00, 
+0x7e,  0x06,  0x0c,  0x18,  0x30,  0x60,  0x7e,  0x00,  0x7c,  0x60,  0x60,  0x60,  0x60,  0x60,  0x7c,  0x00, 
+0x00,  0x60,  0x30,  0x18,  0x0c,  0x06,  0x00,  0x00,  0x3e,  0x06,  0x06,  0x06,  0x06,  0x06,  0x3e,  0x00, 
+0x18,  0x3c,  0x66,  0x42,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0xff, 
+
+0x1c,  0x36,  0x30,  0x7c,  0x30,  0x30,  0x7e,  0x00,  0x00,  0x00,  0x3c,  0x06,  0x3e,  0x66,  0x3e,  0x00, 
+0x60,  0x60,  0x7c,  0x66,  0x66,  0x66,  0x7c,  0x00,  0x00,  0x00,  0x3c,  0x66,  0x60,  0x66,  0x3c,  0x00, 
+0x06,  0x06,  0x3e,  0x66,  0x66,  0x66,  0x3e,  0x00,  0x00,  0x00,  0x3c,  0x66,  0x7e,  0x60,  0x3c,  0x00, 
+0x1c,  0x30,  0x30,  0x7c,  0x30,  0x30,  0x30,  0x00,  0x00,  0x00,  0x3e,  0x66,  0x66,  0x3e,  0x06,  0x3c, 
+0x60,  0x60,  0x7c,  0x66,  0x66,  0x66,  0x66,  0x00,  0x18,  0x00,  0x38,  0x18,  0x18,  0x18,  0x3c,  0x00, 
+0x18,  0x00,  0x38,  0x18,  0x18,  0x18,  0x18,  0x70,  0x60,  0x60,  0x66,  0x6c,  0x78,  0x6c,  0x66,  0x00, 
+0x38,  0x18,  0x18,  0x18,  0x18,  0x18,  0x3c,  0x00,  0x00,  0x00,  0x36,  0x7f,  0x6b,  0x6b,  0x63,  0x00, 
+0x00,  0x00,  0x7c,  0x66,  0x66,  0x66,  0x66,  0x00,  0x00,  0x00,  0x3c,  0x66,  0x66,  0x66,  0x3c,  0x00, 
+0x00,  0x00,  0x7c,  0x66,  0x66,  0x7c,  0x60,  0x60,  0x00,  0x00,  0x3e,  0x66,  0x66,  0x3e,  0x06,  0x07, 
+0x00,  0x00,  0x6c,  0x76,  0x60,  0x60,  0x60,  0x00,  0x00,  0x00,  0x3e,  0x60,  0x3c,  0x06,  0x7c,  0x00, 
+0x30,  0x30,  0x7c,  0x30,  0x30,  0x30,  0x1c,  0x00,  0x00,  0x00,  0x66,  0x66,  0x66,  0x66,  0x3e,  0x00, 
+0x00,  0x00,  0x66,  0x66,  0x66,  0x3c,  0x18,  0x00,  0x00,  0x00,  0x63,  0x6b,  0x6b,  0x7f,  0x36,  0x00, 
+0x00,  0x00,  0x66,  0x3c,  0x18,  0x3c,  0x66,  0x00,  0x00,  0x00,  0x66,  0x66,  0x66,  0x3e,  0x06,  0x3c, 
+0x00,  0x00,  0x7e,  0x0c,  0x18,  0x30,  0x7e,  0x00,  0x0c,  0x18,  0x18,  0x70,  0x18,  0x18,  0x0c,  0x00, 
+0x18,  0x18,  0x18,  0x00,  0x18,  0x18,  0x18,  0x00,  0x30,  0x18,  0x18,  0x0e,  0x18,  0x18,  0x30,  0x00, 
+0x31,  0x6b,  0x46,  0x00,  0x00,  0x00,  0x00,  0x00,  0xff,  0xff,  0xff,  0xff,  0xff,  0xff,  0xff,  0xff, 
+};
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Nov 07 21:37:21 2012 +0000
@@ -0,0 +1,37 @@
+#include "mbed.h"
+#include "Gameduino.h"
+
+int main() {
+    // Make a digital output for use with Gameduino.
+    DigitalOut cs( p8 );
+    // Initialise an SPI link for communications with Gameduino.
+    // Use pin 5 for MOSI.
+    // Use pin 6 for MISO.
+    // Use pin 7 for SCK.
+    SPI spi( p5, p6, p7 );
+    // 8MHz clock should be OK.
+    spi.frequency( 8000000 );
+    // Set SPI format to use.
+    // Use 8 bits per SPI frame.
+    // Use SPI mode 0.
+    spi.format( 8, 0 );
+    // Make a Gameduino and pass SPI link and digital output for chip select.
+    Gameduino gd( &spi, &cs );
+    // Reset the Gameduino.
+    gd.begin();
+    // Lets have a default ASCII character set.
+    gd.ascii();
+    // Write something to character memory.
+    gd.__wstart( Gameduino::RAM_PIC );
+    for( UInt8 c = 'A'; c <= 'Z'; ++c ) {
+        gd.__tr8( c );
+    }
+    gd.__end();
+    // Test copy method.
+    UInt8 copyData[] = "HELLO";
+    gd.copy( Gameduino::RAM_PIC + 64, copyData, 5 );
+    // Test putstr method.
+    gd.putstr( 3, 10, "Ambidextrous!" );
+    // Finished with Gameduino.
+    gd.end();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Nov 07 21:37:21 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/e2ed12d17f06
\ No newline at end of file