Version of Robotron arcade game using LPC1768, a Gameduino shield, a serial EEPROM (for high scores), two microswitch joysticks and two buttons plus a box to put it in. 20 levels of mayhem.
Dependencies: 25LCxxx_SPI CommonTypes Gameduino mbed
HighScoreTable.h@3:a6a0cd726ca0, 2013-06-07 (annotated)
- Committer:
- RichardE
- Date:
- Fri Jun 07 20:29:59 2013 +0000
- Revision:
- 3:a6a0cd726ca0
- Parent:
- 2:bb0f631a6068
- Child:
- 17:194789db2215
Abandoned writing serial EEPROM class and used Ser25LCxxx library instead. HighScoreTable class appears to be reading and writing correctly to EEPROM and high scores are displayed correctly.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
RichardE | 0:5fa232ee5fdf | 1 | /* |
RichardE | 0:5fa232ee5fdf | 2 | * SOURCE FILE : HighScoreTable.h |
RichardE | 0:5fa232ee5fdf | 3 | * |
RichardE | 0:5fa232ee5fdf | 4 | * Definition of class HighScoreTable. |
RichardE | 0:5fa232ee5fdf | 5 | * Maintains a table of high scores with a name and a score for each entry in the table. |
RichardE | 0:5fa232ee5fdf | 6 | * |
RichardE | 0:5fa232ee5fdf | 7 | */ |
RichardE | 0:5fa232ee5fdf | 8 | |
RichardE | 0:5fa232ee5fdf | 9 | #ifndef HighScoreTableDefined |
RichardE | 0:5fa232ee5fdf | 10 | |
RichardE | 0:5fa232ee5fdf | 11 | #define HighScoreTableDefined |
RichardE | 0:5fa232ee5fdf | 12 | |
RichardE | 0:5fa232ee5fdf | 13 | #include "Types.h" |
RichardE | 0:5fa232ee5fdf | 14 | #include "PlayerName.h" |
RichardE | 3:a6a0cd726ca0 | 15 | #include "Ser25lcxxx.h" // serial EEPROM routines. Also work for 25AAxxx EEPROMs. |
RichardE | 0:5fa232ee5fdf | 16 | |
RichardE | 0:5fa232ee5fdf | 17 | class HighScoreTable { |
RichardE | 0:5fa232ee5fdf | 18 | |
RichardE | 0:5fa232ee5fdf | 19 | public : |
RichardE | 0:5fa232ee5fdf | 20 | |
RichardE | 0:5fa232ee5fdf | 21 | /***************/ |
RichardE | 0:5fa232ee5fdf | 22 | /* CONSTRUCTOR */ |
RichardE | 0:5fa232ee5fdf | 23 | /***************/ |
RichardE | 3:a6a0cd726ca0 | 24 | // Pass pointer to an SPI EEPROM which contains the high scores. |
RichardE | 3:a6a0cd726ca0 | 25 | HighScoreTable( Ser25LCxxx *e ); |
RichardE | 0:5fa232ee5fdf | 26 | |
RichardE | 0:5fa232ee5fdf | 27 | /**************/ |
RichardE | 0:5fa232ee5fdf | 28 | /* DESTRUCTOR */ |
RichardE | 0:5fa232ee5fdf | 29 | /**************/ |
RichardE | 0:5fa232ee5fdf | 30 | virtual ~HighScoreTable(); |
RichardE | 0:5fa232ee5fdf | 31 | |
RichardE | 2:bb0f631a6068 | 32 | /***************************************/ |
RichardE | 2:bb0f631a6068 | 33 | /* GET EEPROM USED BY HIGH SCORE TABLE */ |
RichardE | 2:bb0f631a6068 | 34 | /***************************************/ |
RichardE | 3:a6a0cd726ca0 | 35 | Ser25LCxxx *GetEEPROM( void ) const { |
RichardE | 2:bb0f631a6068 | 36 | return eeprom; |
RichardE | 2:bb0f631a6068 | 37 | } |
RichardE | 0:5fa232ee5fdf | 38 | |
RichardE | 0:5fa232ee5fdf | 39 | /****************************************/ |
RichardE | 0:5fa232ee5fdf | 40 | /* VALIDATE EEPROM USED FOR HIGH SCORES */ |
RichardE | 0:5fa232ee5fdf | 41 | /****************************************/ |
RichardE | 0:5fa232ee5fdf | 42 | // Checks EEPROM used for high scores and |
RichardE | 0:5fa232ee5fdf | 43 | // if any of it looks like nonsense it |
RichardE | 0:5fa232ee5fdf | 44 | // rewrites the whole table with defaults. |
RichardE | 0:5fa232ee5fdf | 45 | void ValidateEEPROM( void ); |
RichardE | 0:5fa232ee5fdf | 46 | |
RichardE | 0:5fa232ee5fdf | 47 | /********************************/ |
RichardE | 0:5fa232ee5fdf | 48 | /* DETERMINE IF EEPROM IS VALID */ |
RichardE | 0:5fa232ee5fdf | 49 | /********************************/ |
RichardE | 0:5fa232ee5fdf | 50 | // Returns true if EEPROM is valid. |
RichardE | 0:5fa232ee5fdf | 51 | bool EEPROMValid( void ); |
RichardE | 0:5fa232ee5fdf | 52 | |
RichardE | 3:a6a0cd726ca0 | 53 | /*************************/ |
RichardE | 0:5fa232ee5fdf | 54 | /* GET CAPACITY OF TABLE */ |
RichardE | 0:5fa232ee5fdf | 55 | /*************************/ |
RichardE | 0:5fa232ee5fdf | 56 | // Returns capacity of table. |
RichardE | 0:5fa232ee5fdf | 57 | UInt8 GetCapacity( void ) const { |
RichardE | 0:5fa232ee5fdf | 58 | return capacity; |
RichardE | 0:5fa232ee5fdf | 59 | } |
RichardE | 0:5fa232ee5fdf | 60 | |
RichardE | 0:5fa232ee5fdf | 61 | /**********************************************/ |
RichardE | 0:5fa232ee5fdf | 62 | /* DETERMINE POSITION OF A SCORE IN THE TABLE */ |
RichardE | 0:5fa232ee5fdf | 63 | /**********************************************/ |
RichardE | 0:5fa232ee5fdf | 64 | // Pass score in score. |
RichardE | 0:5fa232ee5fdf | 65 | // Returns position in table (0 is top score). |
RichardE | 0:5fa232ee5fdf | 66 | // If position returned is >= capacity of table then score is not high |
RichardE | 0:5fa232ee5fdf | 67 | // enough to place in table. |
RichardE | 0:5fa232ee5fdf | 68 | UInt8 GetPositionInTable( UInt32 score ) const; |
RichardE | 0:5fa232ee5fdf | 69 | |
RichardE | 0:5fa232ee5fdf | 70 | /*********************************/ |
RichardE | 0:5fa232ee5fdf | 71 | /* ADD ENTRY TO HIGH SCORE TABLE */ |
RichardE | 0:5fa232ee5fdf | 72 | /*********************************/ |
RichardE | 0:5fa232ee5fdf | 73 | // Pass position in table to put entry in pos. |
RichardE | 0:5fa232ee5fdf | 74 | // Pass name of player in name. |
RichardE | 0:5fa232ee5fdf | 75 | // Pass score in score. |
RichardE | 0:5fa232ee5fdf | 76 | void Add( UInt8 pos, const PlayerName *name, UInt32 score ); |
RichardE | 0:5fa232ee5fdf | 77 | |
RichardE | 0:5fa232ee5fdf | 78 | /****************************/ |
RichardE | 0:5fa232ee5fdf | 79 | /* GET ENTRY FROM THE TABLE */ |
RichardE | 0:5fa232ee5fdf | 80 | /****************************/ |
RichardE | 0:5fa232ee5fdf | 81 | // Pass position to fetch from in pos. |
RichardE | 0:5fa232ee5fdf | 82 | // Player name is returned in object pointed to by name. |
RichardE | 0:5fa232ee5fdf | 83 | // Player score is returned in integer pointed to by score. |
RichardE | 0:5fa232ee5fdf | 84 | void Get( UInt8 pos, PlayerName *name, UInt32 *score ) const; |
RichardE | 0:5fa232ee5fdf | 85 | |
RichardE | 0:5fa232ee5fdf | 86 | private : |
RichardE | 0:5fa232ee5fdf | 87 | |
RichardE | 0:5fa232ee5fdf | 88 | // Change the following to suit. |
RichardE | 0:5fa232ee5fdf | 89 | enum { |
RichardE | 2:bb0f631a6068 | 90 | eepromAddress = 0, // address in EEPROM where high score table starts |
RichardE | 2:bb0f631a6068 | 91 | capacity = 10, // number of entries in table |
RichardE | 2:bb0f631a6068 | 92 | // Amount of memory used in EEPROM. |
RichardE | 2:bb0f631a6068 | 93 | // You need capacity bytes for the index and then |
RichardE | 2:bb0f631a6068 | 94 | // eight bytes for each high score and name. |
RichardE | 2:bb0f631a6068 | 95 | memoryUsed = capacity + ( capacity << 3 ), |
RichardE | 0:5fa232ee5fdf | 96 | }; |
RichardE | 0:5fa232ee5fdf | 97 | |
RichardE | 2:bb0f631a6068 | 98 | // Pointer to EEPROM that holds high scores. |
RichardE | 3:a6a0cd726ca0 | 99 | Ser25LCxxx *eeprom; |
RichardE | 0:5fa232ee5fdf | 100 | |
RichardE | 0:5fa232ee5fdf | 101 | /****************************/ |
RichardE | 0:5fa232ee5fdf | 102 | /* WRITE DEFAULTS TO EEPROM */ |
RichardE | 0:5fa232ee5fdf | 103 | /****************************/ |
RichardE | 0:5fa232ee5fdf | 104 | void WriteEEPROMDefaults( void ); |
RichardE | 0:5fa232ee5fdf | 105 | |
RichardE | 0:5fa232ee5fdf | 106 | }; |
RichardE | 0:5fa232ee5fdf | 107 | |
RichardE | 0:5fa232ee5fdf | 108 | #endif |
RichardE | 0:5fa232ee5fdf | 109 | |
RichardE | 0:5fa232ee5fdf | 110 | /* END of HighScoreTable.h */ |