Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Gameduino mbed CommonTypes
GameduinoTest.cpp
00001 /* 00002 * SOURCE FILE : GameduinoTest.cpp 00003 * 00004 * Definition of class GameduinoTest. 00005 * Tests a Gameduino object. 00006 * 00007 */ 00008 00009 #include "GameduinoTest.h" // this module's prototypes 00010 #include "mbed.h" // mbed library 00011 #include "sprite.h" // sprite data 00012 00013 /***************/ 00014 /* CONSTRUCTOR */ 00015 /***************/ 00016 GameduinoTest::GameduinoTest() { 00017 } 00018 00019 /**************/ 00020 /* DESTRUCTOR */ 00021 /**************/ 00022 GameduinoTest::~GameduinoTest() { 00023 } 00024 00025 /*********************/ 00026 /* DO ANIMATION TEST */ 00027 /*********************/ 00028 // Pass pointer to Gameduino to use in gd. 00029 void GameduinoTest::AnimationTest( Gameduino *gd ) { 00030 Int16 x = 0; 00031 Int8 dir = 1; 00032 for( UInt16 i = 0; i < 1000; ++i ) { 00033 gd->waitvblank(); 00034 gd->sprite( 100, x, 100, 0, 0 ); 00035 x += dir; 00036 if( x > 200 ) { 00037 dir = -1; 00038 } 00039 else if( x < 0 ) { 00040 dir = 1; 00041 } 00042 } 00043 } 00044 00045 /*********************/ 00046 /* TEST PLOTS METHOD */ 00047 /*********************/ 00048 // Pass pointer to Gameduino to use in gd. 00049 void GameduinoTest::TestPlots( Gameduino *gd ) { 00050 #define PLOTLEN 3 00051 Gameduino::sprplot records[ PLOTLEN ] = { 00052 { 0, 0, 26, 0 }, 00053 { 16, 1, 27, 0 }, 00054 { 32, 2, 28, 0 }, 00055 }; 00056 gd->__wstartspr( 110 ); 00057 gd->plots( 170, 0, records, PLOTLEN ); 00058 gd->__end(); 00059 } 00060 00061 /****************/ 00062 /* RUN THE TEST */ 00063 /****************/ 00064 void GameduinoTest::Run( void ) { 00065 // Make a serial port for communicating with PC. 00066 Serial pc( USBTX, USBRX ); 00067 // Sign on message. 00068 pc.printf( "Up and running!\r\n" ); 00069 // Make a digital output for use with Gameduino. 00070 DigitalOut cs( p8 ); 00071 // Initialise an SPI link for communications with Gameduino. 00072 // Use pin 5 for MOSI. 00073 // Use pin 6 for MISO. 00074 // Use pin 7 for SCK. 00075 SPI spi( p5, p6, p7 ); 00076 // 8MHz clock should be OK. 00077 spi.frequency( 8000000 ); 00078 // Set SPI format to use. 00079 // Use 8 bits per SPI frame. 00080 // Use SPI mode 0. 00081 spi.format( 8, 0 ); 00082 // Make a Gameduino and pass SPI link and digital output for chip select. 00083 Gameduino gd( &spi, &cs ); 00084 // Reset the Gameduino. 00085 gd.begin(); 00086 // Lets have a default ASCII character set. 00087 gd.ascii(); 00088 // Fill sprite image and palette memory. 00089 gd.copy( Gameduino::RAM_SPRIMG, sprite_sprimg, sizeof( sprite_sprimg ) ); 00090 gd.copy( Gameduino::RAM_SPRPAL, sprite_sprpal, sizeof( sprite_sprpal ) ); 00091 // Read from ident register. 00092 UInt8 id = gd.rd( Gameduino::IDENT ); 00093 // Report back to PC. 00094 pc.printf( "Gameduino ID is 0x%02X.\r\n", (int)id ); 00095 // Write something to character memory. 00096 gd.__wstart( Gameduino::RAM_PIC ); 00097 for( UInt8 c = 'A'; c <= 'Z'; ++c ) { 00098 gd.__tr8( c ); 00099 } 00100 gd.__end(); 00101 // Test copy method. 00102 UInt8 copyData[] = "HELLO"; 00103 gd.copy( Gameduino::RAM_PIC + 64, copyData, 5 ); 00104 // Test putstr method. 00105 gd.putstr( 3, 10, "Ambidextrous!" ); 00106 // Show some sprites. 00107 UInt16 y = 140; 00108 UInt8 spriteNum = 0; 00109 for( UInt8 rot = 0; rot < 8; ++rot ) { 00110 UInt16 x = 0; 00111 for( UInt8 spriteImage = 0; spriteImage < 10; ++spriteImage ) { 00112 gd.sprite( spriteNum++, x, y, spriteImage, 0, (Gameduino::Rotation)rot ); 00113 x += 18; 00114 } 00115 y += 18; 00116 } 00117 // Test out sprite2x2 method. 00118 gd.sprite2x2( 90, 150, 16, 38, 0, Gameduino::None, 0 ); 00119 // Test out __wstartspr method. 00120 gd.__wstartspr( 95 ); 00121 y = 32; 00122 for( UInt8 imageNum = 15; imageNum < 19; ++imageNum ) { 00123 gd.TransferSprite( 150, y, imageNum, 0 ); 00124 y += 16; 00125 } 00126 gd.__end(); 00127 // Test out plots method. 00128 TestPlots( &gd ); 00129 // Do some sprite animation. 00130 AnimationTest( &gd ); 00131 // Make a noise. 00132 gd.voice( 25, Gameduino::SineWave, 8000, 127, 127 ); 00133 wait_ms( 1000 ); 00134 gd.voice( 25, Gameduino::SineWave, 0, 0, 0 ); 00135 // Make another noise. 00136 gd.voice( 25, Gameduino::WhiteNoise, 8000, 127, 127 ); 00137 wait_ms( 1000 ); 00138 gd.voice( 25, Gameduino::WhiteNoise, 0, 0, 0 ); 00139 // Finished with Gameduino. 00140 gd.end(); 00141 }
Generated on Sun Jul 31 2022 01:31:22 by
1.7.2