Browse Source

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.

feature/2015
Christian Kroll 13 years ago
parent
commit
6743221e8e
  1. 13
      games/tetris/highscore.c
  2. 43
      games/tetris/highscore.h
  3. 8
      games/tetris/tetris_main.c

13
games/tetris/highscore.c

@ -8,11 +8,8 @@
#include "../../compat/eeprom.h" #include "../../compat/eeprom.h"
#include "highscore.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 tetris_highscore_table_t g_highScoreTable EEMEM;
uint16_t tetris_highscore_name[TETRIS_HISCORE_END] EEMEM;
uint16_t tetris_highscore_inputName(void) 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 = uint16_t nHighScore =
eeprom_read_word(&tetris_highscore[nIndex]); eeprom_read_word(&g_highScoreTable.nHighScore[nIndex]);
// a score of 65535 is most likely caused by uninitialized EEPROM addresses // a score of 65535 is most likely caused by uninitialized EEPROM addresses
return nHighscore == UINT16_MAX ? 0 : nHighscore; return nHighScore == UINT16_MAX ? 0 : nHighScore;
} }

43
games/tetris/highscore.h

@ -8,7 +8,7 @@
/** /**
* indexes for different tetris variants * 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_TETRIS, /**< high score index for the standard variant */
TETRIS_HISCORE_BASTET, /**< high score index for the bastet variant */ TETRIS_HISCORE_BASTET, /**< high score index for the bastet variant */
@ -23,10 +23,21 @@ enum tetris_highscore_index
#endif #endif
// global array for the high score /**
extern uint16_t tetris_highscore[TETRIS_HISCORE_END] EEMEM; * type for global high score table
// global array for the champion's initials */
extern uint16_t tetris_highscore_name[TETRIS_HISCORE_END] EEMEM; 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 * @param nIndex the variant dependent index of the high score
* @return 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 * @param nHighscoreName the high score
*/ */
inline static inline static
void tetris_highscore_saveHighscore(tetris_highscore_index_t nIndex, void tetris_highscore_saveHighScore(tetris_highscore_index_t nIndex,
uint16_t nHighscore) 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 * @return the initials of the champion packed into a uint16_t
*/ */
inline static 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 = uint16_t nHighScoreName =
eeprom_read_word(&tetris_highscore_name[nIdx]); 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 * @param nHighscoreName the initials of the champion packed into a uint16_t
*/ */
inline static inline static
void tetris_highscore_saveHighscoreName(tetris_highscore_index_t nIndex, void tetris_highscore_saveHighScoreName(tetris_highscore_index_t nIndex,
uint16_t nHighscoreName) uint16_t nHighscoreName)
{ {
eeprom_write_word(&tetris_highscore_name[nIndex], nHighscoreName); eeprom_write_word(&g_highScoreTable.nHighScoreName[nIndex], nHighscoreName);
} }

8
games/tetris/tetris_main.c

@ -31,9 +31,9 @@ void tetris_main(tetris_variant_t const *const pVariantMethods)
tetris_highscore_index_t nHighscoreIndex = tetris_highscore_index_t nHighscoreIndex =
pVariantMethods->getHighscoreIndex(pVariantData); pVariantMethods->getHighscoreIndex(pVariantData);
uint16_t nHighscore = uint16_t nHighscore =
tetris_highscore_retrieveHighscore(nHighscoreIndex); tetris_highscore_retrieveHighScore(nHighscoreIndex);
uint16_t nHighscoreName = uint16_t nHighscoreName =
tetris_highscore_retrieveHighscoreName(nHighscoreIndex); tetris_highscore_retrieveHighScoreName(nHighscoreIndex);
// the view only monitors the variant data and the bucket object for the // 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 // 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; nHighscore = nScore;
nHighscoreName = tetris_highscore_inputName(); nHighscoreName = tetris_highscore_inputName();
tetris_highscore_saveHighscore(nHighscoreIndex, nHighscore); tetris_highscore_saveHighScore(nHighscoreIndex, nHighscore);
tetris_highscore_saveHighscoreName(nHighscoreIndex, nHighscoreName); tetris_highscore_saveHighScoreName(nHighscoreIndex, nHighscoreName);
} }
// cleanup // cleanup

Loading…
Cancel
Save