More complicated test program that generates text, coloured sprites and sound.
Dependencies: Gameduino mbed CommonTypes
GameduinoTest.cpp
- Committer:
- RichardE
- Date:
- 2012-05-05
- Revision:
- 1:c8ec5f958f3c
- Parent:
- 0:13f69384ff8a
- Child:
- 2:5604e16b78bd
File content as of revision 1:c8ec5f958f3c:
/* * SOURCE FILE : GameduinoTest.cpp * * Definition of class GameduinoTest. * Tests a Gameduino object. * */ #include "GameduinoTest.h" // this module's prototypes #include "mbed.h" // mbed library #include "sprite.h" // sprite data /***************/ /* CONSTRUCTOR */ /***************/ GameduinoTest::GameduinoTest() { } /**************/ /* DESTRUCTOR */ /**************/ GameduinoTest::~GameduinoTest() { } /*********************/ /* DO ANIMATION TEST */ /*********************/ // Pass pointer to Gameduino to use in gd. void GameduinoTest::AnimationTest( Gameduino *gd ) { Int16 x = 0; Int8 dir = 1; for( UInt16 i = 0; i < 1000; ++i ) { gd->waitvblank(); gd->sprite( 100, x, 100, 0, 0 ); x += dir; if( x > 200 ) { dir = -1; } else if( x < 0 ) { dir = 1; } } } /****************/ /* RUN THE TEST */ /****************/ void GameduinoTest::Run( void ) { // Make a serial port for communicating with PC. Serial pc( USBTX, USBRX ); // Sign on message. pc.printf( "Up and running!\r\n" ); // 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 ); // 4MHz clock should be OK since this is default on an Arduino. spi.frequency( 4000000 ); // 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(); // Fill sprite image and palette memory. gd.copy( Gameduino::RAM_SPRIMG, sprite_sprimg, sizeof( sprite_sprimg ) ); gd.copy( Gameduino::RAM_SPRPAL, sprite_sprpal, sizeof( sprite_sprpal ) ); // Read from ident register. UInt8 id = gd.rd( Gameduino::IDENT ); // Report back to PC. pc.printf( "Gameduino ID is 0x%02X.\r\n", (int)id ); // 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!" ); // Show some sprites. UInt16 y = 140; UInt8 spriteNum = 0; for( UInt8 rot = 0; rot < 8; ++rot ) { UInt16 x = 0; for( UInt8 spriteImage = 0; spriteImage < 10; ++spriteImage ) { gd.sprite( spriteNum++, x, y, spriteImage, 0, (Gameduino::Rotation)rot ); x += 18; } y += 18; } // Do some sprite animation. AnimationTest( &gd ); // Finished with Gameduino. gd.end(); }