2010-08-22 03:07:46 +00:00
|
|
|
#ifndef TETRIS_HIGHSCORE_H_
|
|
|
|
#define TETRIS_HIGHSCORE_H_
|
|
|
|
|
2010-08-28 15:13:35 +00:00
|
|
|
#include <stdint.h>
|
2011-03-07 00:32:38 +00:00
|
|
|
#include "../../compat/eeprom.h"
|
|
|
|
|
2010-08-28 15:13:35 +00:00
|
|
|
|
2010-08-22 03:07:46 +00:00
|
|
|
/**
|
|
|
|
* indexes for different tetris variants
|
|
|
|
*/
|
2012-03-23 23:21:46 +00:00
|
|
|
enum tetris_highscore_index_e
|
2010-08-22 03:07:46 +00:00
|
|
|
{
|
|
|
|
TETRIS_HISCORE_TETRIS, /**< high score index for the standard variant */
|
|
|
|
TETRIS_HISCORE_BASTET, /**< high score index for the bastet variant */
|
|
|
|
TETRIS_HISCORE_FP, /**< high score index for the first person variant */
|
|
|
|
TETRIS_HISCORE_PAD, /**< don't use (padding for an even array boundary)*/
|
|
|
|
TETRIS_HISCORE_END /**< boundary for the high score array */
|
2011-02-25 04:31:34 +00:00
|
|
|
};
|
|
|
|
#ifdef NDEBUG
|
|
|
|
typedef uint8_t tetris_highscore_index_t;
|
|
|
|
#else
|
|
|
|
typedef enum tetris_highscore_index tetris_highscore_index_t;
|
|
|
|
#endif
|
2010-08-22 03:07:46 +00:00
|
|
|
|
2011-03-07 00:32:38 +00:00
|
|
|
|
2012-03-23 23:21:46 +00:00
|
|
|
/**
|
|
|
|
* 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;
|
2011-03-07 00:32:38 +00:00
|
|
|
|
|
|
|
|
2010-08-22 03:07:46 +00:00
|
|
|
/**
|
|
|
|
* lets the user enter his initials (three characters)
|
|
|
|
* @return name packed into a uint16_t
|
|
|
|
*/
|
|
|
|
uint16_t tetris_highscore_inputName(void);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* retrieves the high score from storage (EEPROM)
|
|
|
|
* @param nIndex the variant dependent index of the high score
|
|
|
|
* @return the high score
|
|
|
|
*/
|
2012-03-23 23:21:46 +00:00
|
|
|
uint16_t tetris_highscore_retrieveHighScore(tetris_highscore_index_t nIndex);
|
2010-08-22 03:07:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* saves the high score into the storage (EEPROM)
|
2011-03-07 00:32:38 +00:00
|
|
|
* @param nIdx the variant dependent index of the high score
|
2010-08-22 03:07:46 +00:00
|
|
|
* @param nHighscoreName the high score
|
|
|
|
*/
|
2011-03-07 00:32:38 +00:00
|
|
|
inline static
|
2012-03-23 23:21:46 +00:00
|
|
|
void tetris_highscore_saveHighScore(tetris_highscore_index_t nIndex,
|
|
|
|
uint16_t nHighScore)
|
2011-03-07 00:32:38 +00:00
|
|
|
{
|
2012-03-23 23:21:46 +00:00
|
|
|
if (nHighScore > tetris_highscore_retrieveHighScore(nIndex))
|
2011-03-07 00:32:38 +00:00
|
|
|
{
|
2012-03-23 23:21:46 +00:00
|
|
|
eeprom_write_word(&g_highScoreTable.nHighScore[nIndex], nHighScore);
|
2011-03-07 00:32:38 +00:00
|
|
|
}
|
|
|
|
}
|
2010-08-22 03:07:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* retrieves the champion's initials from storage (EEPROM)
|
|
|
|
* @param nIdx the variant dependent index of the high score
|
|
|
|
* @return the initials of the champion packed into a uint16_t
|
|
|
|
*/
|
2011-03-07 00:32:38 +00:00
|
|
|
inline static
|
2012-03-23 23:21:46 +00:00
|
|
|
uint16_t tetris_highscore_retrieveHighScoreName(tetris_highscore_index_t nIdx)
|
2011-03-07 00:32:38 +00:00
|
|
|
{
|
2012-03-23 23:21:46 +00:00
|
|
|
uint16_t nHighScoreName =
|
|
|
|
eeprom_read_word(&g_highScoreTable.nHighScoreName[nIdx]);
|
2011-03-07 00:32:38 +00:00
|
|
|
|
2012-03-23 23:21:46 +00:00
|
|
|
return nHighScoreName;
|
2011-03-07 00:32:38 +00:00
|
|
|
}
|
2010-08-22 03:07:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* saves the champion's initials into the storage (EEPROM)
|
|
|
|
* @param nIndex the variant dependent index of the high score
|
|
|
|
* @param nHighscoreName the initials of the champion packed into a uint16_t
|
|
|
|
*/
|
2011-03-07 00:32:38 +00:00
|
|
|
inline static
|
2012-03-23 23:21:46 +00:00
|
|
|
void tetris_highscore_saveHighScoreName(tetris_highscore_index_t nIndex,
|
2011-03-07 00:32:38 +00:00
|
|
|
uint16_t nHighscoreName)
|
|
|
|
{
|
2012-03-23 23:21:46 +00:00
|
|
|
eeprom_write_word(&g_highScoreTable.nHighScoreName[nIndex], nHighscoreName);
|
2011-03-07 00:32:38 +00:00
|
|
|
}
|
|
|
|
|
2010-08-22 03:07:46 +00:00
|
|
|
|
|
|
|
#endif /*TETRIS_HIGHSCORE_H_*/
|