From 6743221e8e1a85ff8aa0637dfc98f54b6b68687e Mon Sep 17 00:00:00 2001 From: Christian Kroll Date: Fri, 23 Mar 2012 23:21:46 +0000 Subject: [PATCH] New tool chain reordered the global arrays for the high score values and the champion's initials, therefore I packed them into a struct to prevent further annoyances. --- games/tetris/highscore.c | 13 +++++------- games/tetris/highscore.h | 43 ++++++++++++++++++++++++-------------- games/tetris/tetris_main.c | 8 +++---- 3 files changed, 36 insertions(+), 28 deletions(-) diff --git a/games/tetris/highscore.c b/games/tetris/highscore.c index ce6b9eb..42c867e 100644 --- a/games/tetris/highscore.c +++ b/games/tetris/highscore.c @@ -8,11 +8,8 @@ #include "../../compat/eeprom.h" #include "highscore.h" -// global array for the high score -uint16_t tetris_highscore[TETRIS_HISCORE_END] EEMEM; -// global array for the champion's initials -uint16_t tetris_highscore_name[TETRIS_HISCORE_END] EEMEM; +tetris_highscore_table_t g_highScoreTable EEMEM; uint16_t tetris_highscore_inputName(void) @@ -95,11 +92,11 @@ uint16_t tetris_highscore_inputName(void) } -uint16_t tetris_highscore_retrieveHighscore(tetris_highscore_index_t nIndex) +uint16_t tetris_highscore_retrieveHighScore(tetris_highscore_index_t nIndex) { - uint16_t nHighscore = - eeprom_read_word(&tetris_highscore[nIndex]); + uint16_t nHighScore = + eeprom_read_word(&g_highScoreTable.nHighScore[nIndex]); // a score of 65535 is most likely caused by uninitialized EEPROM addresses - return nHighscore == UINT16_MAX ? 0 : nHighscore; + return nHighScore == UINT16_MAX ? 0 : nHighScore; } diff --git a/games/tetris/highscore.h b/games/tetris/highscore.h index 10e2994..8ec035e 100644 --- a/games/tetris/highscore.h +++ b/games/tetris/highscore.h @@ -8,7 +8,7 @@ /** * indexes for different tetris variants */ -enum tetris_highscore_index +enum tetris_highscore_index_e { TETRIS_HISCORE_TETRIS, /**< high score index for the standard variant */ TETRIS_HISCORE_BASTET, /**< high score index for the bastet variant */ @@ -23,10 +23,21 @@ enum tetris_highscore_index #endif -// global array for the high score -extern uint16_t tetris_highscore[TETRIS_HISCORE_END] EEMEM; -// global array for the champion's initials -extern uint16_t tetris_highscore_name[TETRIS_HISCORE_END] EEMEM; +/** + * type for global high score table + */ +typedef struct tetris_highscore_table_s +{ + uint16_t nHighScoreName[TETRIS_HISCORE_END]; /**< champions' initials */ + uint16_t nHighScore[TETRIS_HISCORE_END]; /**< actual high scores */ +} +tetris_highscore_table_t; + + +/** + * the actual high score table + */ +extern tetris_highscore_table_t g_highScoreTable EEMEM; /** @@ -41,7 +52,7 @@ uint16_t tetris_highscore_inputName(void); * @param nIndex the variant dependent index of the high score * @return the high score */ -uint16_t tetris_highscore_retrieveHighscore(tetris_highscore_index_t nIndex); +uint16_t tetris_highscore_retrieveHighScore(tetris_highscore_index_t nIndex); /** @@ -50,12 +61,12 @@ uint16_t tetris_highscore_retrieveHighscore(tetris_highscore_index_t nIndex); * @param nHighscoreName the high score */ inline static -void tetris_highscore_saveHighscore(tetris_highscore_index_t nIndex, - uint16_t nHighscore) +void tetris_highscore_saveHighScore(tetris_highscore_index_t nIndex, + uint16_t nHighScore) { - if (nHighscore > tetris_highscore_retrieveHighscore(nIndex)) + if (nHighScore > tetris_highscore_retrieveHighScore(nIndex)) { - eeprom_write_word(&tetris_highscore[nIndex], nHighscore); + eeprom_write_word(&g_highScoreTable.nHighScore[nIndex], nHighScore); } } @@ -66,12 +77,12 @@ void tetris_highscore_saveHighscore(tetris_highscore_index_t nIndex, * @return the initials of the champion packed into a uint16_t */ inline static -uint16_t tetris_highscore_retrieveHighscoreName(tetris_highscore_index_t nIdx) +uint16_t tetris_highscore_retrieveHighScoreName(tetris_highscore_index_t nIdx) { - uint16_t nHighscoreName = - eeprom_read_word(&tetris_highscore_name[nIdx]); + uint16_t nHighScoreName = + eeprom_read_word(&g_highScoreTable.nHighScoreName[nIdx]); - return nHighscoreName; + return nHighScoreName; } @@ -81,10 +92,10 @@ uint16_t tetris_highscore_retrieveHighscoreName(tetris_highscore_index_t nIdx) * @param nHighscoreName the initials of the champion packed into a uint16_t */ inline static -void tetris_highscore_saveHighscoreName(tetris_highscore_index_t nIndex, +void tetris_highscore_saveHighScoreName(tetris_highscore_index_t nIndex, uint16_t nHighscoreName) { - eeprom_write_word(&tetris_highscore_name[nIndex], nHighscoreName); + eeprom_write_word(&g_highScoreTable.nHighScoreName[nIndex], nHighscoreName); } diff --git a/games/tetris/tetris_main.c b/games/tetris/tetris_main.c index 0d94ee9..6ff9642 100644 --- a/games/tetris/tetris_main.c +++ b/games/tetris/tetris_main.c @@ -31,9 +31,9 @@ void tetris_main(tetris_variant_t const *const pVariantMethods) tetris_highscore_index_t nHighscoreIndex = pVariantMethods->getHighscoreIndex(pVariantData); uint16_t nHighscore = - tetris_highscore_retrieveHighscore(nHighscoreIndex); + tetris_highscore_retrieveHighScore(nHighscoreIndex); uint16_t nHighscoreName = - tetris_highscore_retrieveHighscoreName(nHighscoreIndex); + tetris_highscore_retrieveHighScoreName(nHighscoreIndex); // the view only monitors the variant data and the bucket object for the // game status so we must put information like the next piece or the current @@ -195,8 +195,8 @@ void tetris_main(tetris_variant_t const *const pVariantMethods) { nHighscore = nScore; nHighscoreName = tetris_highscore_inputName(); - tetris_highscore_saveHighscore(nHighscoreIndex, nHighscore); - tetris_highscore_saveHighscoreName(nHighscoreIndex, nHighscoreName); + tetris_highscore_saveHighScore(nHighscoreIndex, nHighscore); + tetris_highscore_saveHighScoreName(nHighscoreIndex, nHighscoreName); } // cleanup