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

@ -61,11 +61,12 @@ int highscore_load(char *filename, struct highscore *scores, int num_scores)
char *ptr;
fd = rb->open(filename, O_RDONLY);
rb->memset(scores, 0, sizeof(struct highscore)*(num_scores+1));
if(fd < 0)
return -1;
rb->memset(scores, 0, sizeof(struct highscore)*num_scores);
i = -1;
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;
}
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;
}