1
0
Fork 0
forked from len0rd/rockbox

Gigabeat gets rockblox ! Thanks to the RedZZR Gary Allen.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11918 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Steve Gotthardt 2007-01-05 16:32:20 +00:00
parent 504c040c08
commit d850db102f
5 changed files with 97 additions and 5 deletions

View file

@ -9,7 +9,7 @@ logo.c
mosaique.c mosaique.c
properties.c properties.c
random_folder_advance_config.c random_folder_advance_config.c
#if (LCD_WIDTH != 240) && ((LCD_WIDTH != 128) || (LCD_HEIGHT != 64)) && !defined(SANSA_E200) #if !defined(SANSA_E200)
rockblox.c rockblox.c
#endif #endif
rockbox_flash.c rockbox_flash.c

View file

@ -312,6 +312,8 @@ brickmania_break.176x132x16.bmp
/* Rockblox */ /* Rockblox */
#if (LCD_WIDTH == 320) && (LCD_HEIGHT == 240) && (LCD_DEPTH == 16) #if (LCD_WIDTH == 320) && (LCD_HEIGHT == 240) && (LCD_DEPTH == 16)
rockblox_background.320x240x16.bmp rockblox_background.320x240x16.bmp
#elif (LCD_WIDTH == 240) && (LCD_HEIGHT == 320) && (LCD_DEPTH == 16)
rockblox_background.240x320x16.bmp
#elif (LCD_WIDTH >= 220) && (LCD_HEIGHT >= 176) && (LCD_DEPTH == 16) #elif (LCD_WIDTH >= 220) && (LCD_HEIGHT >= 176) && (LCD_DEPTH == 16)
rockblox_background.220x176x16.bmp rockblox_background.220x176x16.bmp
#elif (LCD_WIDTH == 176) && (LCD_HEIGHT == 132) && (LCD_DEPTH == 16) #elif (LCD_WIDTH == 176) && (LCD_HEIGHT == 132) && (LCD_DEPTH == 16)

View file

@ -61,11 +61,12 @@ int highscore_load(char *filename, struct highscore *scores, int num_scores)
char *ptr; char *ptr;
fd = rb->open(filename, O_RDONLY); fd = rb->open(filename, O_RDONLY);
rb->memset(scores, 0, sizeof(struct highscore)*(num_scores+1));
if(fd < 0) if(fd < 0)
return -1; return -1;
rb->memset(scores, 0, sizeof(struct highscore)*num_scores);
i = -1; i = -1;
while(rb->read_line(fd, buf, sizeof(buf)-1) && i < num_scores) while(rb->read_line(fd, buf, sizeof(buf)-1) && i < num_scores)
{ {
@ -97,3 +98,31 @@ int highscore_load(char *filename, struct highscore *scores, int num_scores)
} }
return 0; return 0;
} }
int highscore_update(int score, int level, struct highscore *scores, int num_scores)
{
int i, j;
int new = 0;
/* look through the scores and see if this one is in the top ones */
for(i = num_scores-1;i >= 0; i--)
{
if ((score > scores[i].score))
{
/* Move the rest down one... */
if (i > 0)
{
for (j=1; j<=i; j++)
{
rb->memcpy((void *)&scores[j-1], (void *)&scores[j], sizeof(struct highscore));
}
}
scores[i].score = score;
scores[i].level = level;
/* Need to sort out entering a name... maybe old three letter arcade style */
new = 1;
break;
}
}
return new;
}

View file

@ -29,5 +29,6 @@ struct highscore
void highscore_init(struct plugin_api* newrb); void highscore_init(struct plugin_api* newrb);
int highscore_save(char *filename, struct highscore *scores, int num_scores); int highscore_save(char *filename, struct highscore *scores, int num_scores);
int highscore_load(char *filename, struct highscore *scores, int num_scores); int highscore_load(char *filename, struct highscore *scores, int num_scores);
int highscore_update(int score, int level, struct highscore *scores, int num_scores);
#endif #endif

View file

@ -118,6 +118,17 @@ PLUGIN_HEADER
#define ROCKBLOX_DROP BUTTON_FF #define ROCKBLOX_DROP BUTTON_FF
#define ROCKBLOX_RESTART BUTTON_PLAY #define ROCKBLOX_RESTART BUTTON_PLAY
#elif CONFIG_KEYPAD == GIGABEAT_PAD
#define ROCKBLOX_OFF BUTTON_A
#define ROCKBLOX_ROTATE_RIGHT BUTTON_VOL_DOWN
#define ROCKBLOX_ROTATE_LEFT BUTTON_VOL_UP
#define ROCKBLOX_ROTATE BUTTON_UP
#define ROCKBLOX_DOWN BUTTON_DOWN
#define ROCKBLOX_LEFT BUTTON_LEFT
#define ROCKBLOX_RIGHT BUTTON_RIGHT
#define ROCKBLOX_DROP BUTTON_SELECT
#define ROCKBLOX_RESTART BUTTON_MENU
#endif #endif
#define BLOCKS_NUM 7 #define BLOCKS_NUM 7
@ -142,6 +153,24 @@ PLUGIN_HEADER
#define LEVEL_Y 70 #define LEVEL_Y 70
#define LINES_Y 105 #define LINES_Y 105
#elif (LCD_WIDTH == 240) && (LCD_HEIGHT == 320)
#define BLOCK_WIDTH 12
#define BLOCK_HEIGHT 12
#define BOARD_X 86
#define BOARD_Y 0
#define PREVIEW_X 12
#define PREVIEW_Y 11
#define LABEL_X 20
#define SCORE_Y 80
#define LEVEL_Y 110
#define LEVEL_X 46
#define LINES_X 16
#define LINES_Y 110
#define HIGH_SCORE_Y 184
#define HIGH_LEVEL_Y 193
#define HIGH_LABEL_X 7
#elif (LCD_WIDTH == 220) && (LCD_HEIGHT == 176) #elif (LCD_WIDTH == 220) && (LCD_HEIGHT == 176)
#define BLOCK_WIDTH 8 #define BLOCK_WIDTH 8
@ -227,6 +256,10 @@ PLUGIN_HEADER
#define LEVEL_X LABEL_X #define LEVEL_X LABEL_X
#endif #endif
#ifndef LINES_X
#define LINES_X LABEL_X
#endif
#define MYLCD(fn) rb->lcd_ ## fn #define MYLCD(fn) rb->lcd_ ## fn
extern const fb_data rockblox_background[]; extern const fb_data rockblox_background[];
@ -282,7 +315,7 @@ static struct plugin_api *rb;
static bool gameover = false; static bool gameover = false;
/* c=current f=figure o=orientation n=next */ /* c=current f=figure o=orientation n=next */
static int lines, level, score, cx, cy, cf, co, nf; static int lines = 0, level = 0, score = 0, cx, cy, cf, co, nf;
static short board[BOARD_HEIGHT][BOARD_WIDTH]; /* 20 rows of 10 blocks */ static short board[BOARD_HEIGHT][BOARD_WIDTH]; /* 20 rows of 10 blocks */
#ifdef SCROLL_WHEEL #ifdef SCROLL_WHEEL
@ -395,6 +428,12 @@ figures[BLOCKS_NUM] = {
} }
}; };
/* Rockbox File System only supports full filenames inc dir */
#define HIGH_SCORE "/.rockbox/rocks/rockblox.score"
#define MAX_HIGH_SCORES 5
/* Default High Scores... */
struct highscore Highest[MAX_HIGH_SCORES];
/* get random number from (0) to (range-1) */ /* get random number from (0) to (range-1) */
static int t_rand (int range) static int t_rand (int range)
{ {
@ -425,7 +464,7 @@ static void show_details (void)
rb->snprintf (str, sizeof (str), "%d", level); rb->snprintf (str, sizeof (str), "%d", level);
rb->lcd_putsxy (LEVEL_X, LEVEL_Y, str); rb->lcd_putsxy (LEVEL_X, LEVEL_Y, str);
rb->snprintf (str, sizeof (str), "%d", lines); rb->snprintf (str, sizeof (str), "%d", lines);
rb->lcd_putsxy (LABEL_X, LINES_Y, str); rb->lcd_putsxy (LINES_X, LINES_Y, str);
#else /* HAVE_LCD_CHARCELLS */ #else /* HAVE_LCD_CHARCELLS */
rb->snprintf (str, sizeof (str), "L%d/%d", level, lines); rb->snprintf (str, sizeof (str), "L%d/%d", level, lines);
rb->lcd_puts (5, 0, str); rb->lcd_puts (5, 0, str);
@ -436,6 +475,10 @@ static void show_details (void)
static void init_rockblox (void) static void init_rockblox (void)
{ {
int i;
char str[25]; /* for strings */
highscore_update(score, level, Highest, MAX_HIGH_SCORES);
level = 1; level = 1;
lines = 0; lines = 0;
score = 0; score = 0;
@ -454,6 +497,13 @@ static void init_rockblox (void)
pgfx_update(); pgfx_update();
#endif #endif
show_details (); show_details ();
#ifdef HIGH_SCORE_Y
for (i = MAX_HIGH_SCORES-1; i>=0; i--)
{
rb->snprintf (str, sizeof (str), "%06d L%1d", Highest[i].score, Highest[i].level);
rb->lcd_putsxy (HIGH_LABEL_X, HIGH_SCORE_Y + (10 * ((MAX_HIGH_SCORES-1) - i)), str);
}
#endif
} }
static inline int level_speed(int level) static inline int level_speed(int level)
@ -781,6 +831,9 @@ static int rockblox_loop (void)
case ROCKBLOX_OFF: case ROCKBLOX_OFF:
return PLUGIN_OK; return PLUGIN_OK;
#if defined(ROCKBLOX_ROTATE)
case ROCKBLOX_ROTATE:
#endif
case ROCKBLOX_ROTATE_RIGHT: case ROCKBLOX_ROTATE_RIGHT:
case ROCKBLOX_ROTATE_RIGHT | BUTTON_REPEAT: case ROCKBLOX_ROTATE_RIGHT | BUTTON_REPEAT:
#ifdef SCROLL_WHEEL #ifdef SCROLL_WHEEL
@ -910,6 +963,11 @@ enum plugin_status plugin_start (struct plugin_api *api, void *parameter)
rb = api; rb = api;
rb->srand (*rb->current_tick); rb->srand (*rb->current_tick);
/* Load HighScore if any */
highscore_init(rb);
highscore_load(HIGH_SCORE,Highest,MAX_HIGH_SCORES);
#if LCD_DEPTH > 1 #if LCD_DEPTH > 1
rb->lcd_set_backdrop(NULL); rb->lcd_set_backdrop(NULL);
#endif #endif
@ -935,6 +993,8 @@ enum plugin_status plugin_start (struct plugin_api *api, void *parameter)
#else #else
pgfx_release(); pgfx_release();
#endif #endif
/* Save user's HighScore */
highscore_save(HIGH_SCORE,Highest,MAX_HIGH_SCORES);
/* Restore user's original backlight setting */ /* Restore user's original backlight setting */
rb->backlight_set_timeout (rb->global_settings->backlight_timeout); rb->backlight_set_timeout (rb->global_settings->backlight_timeout);