summaryrefslogtreecommitdiff
path: root/apps/plugins/lib
diff options
context:
space:
mode:
authorSteve Gotthardt <gotthardt@rockbox.org>2007-01-05 16:32:20 +0000
committerSteve Gotthardt <gotthardt@rockbox.org>2007-01-05 16:32:20 +0000
commitd850db102f2fb8abad0c7c318015883125aab336 (patch)
tree54384e358fef0bf6edf6d5589f4299c9c71c270f /apps/plugins/lib
parent504c040c08af37c77f8834d88ec768cb985456e2 (diff)
downloadrockbox-d850db102f2fb8abad0c7c318015883125aab336.zip
rockbox-d850db102f2fb8abad0c7c318015883125aab336.tar.gz
rockbox-d850db102f2fb8abad0c7c318015883125aab336.tar.bz2
rockbox-d850db102f2fb8abad0c7c318015883125aab336.tar.xz
Gigabeat gets rockblox ! Thanks to the RedZZR Gary Allen.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11918 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/lib')
-rw-r--r--apps/plugins/lib/highscore.c33
-rw-r--r--apps/plugins/lib/highscore.h1
2 files changed, 32 insertions, 2 deletions
diff --git a/apps/plugins/lib/highscore.c b/apps/plugins/lib/highscore.c
index 9fbcdf2..df7a71b 100644
--- a/apps/plugins/lib/highscore.c
+++ b/apps/plugins/lib/highscore.c
@@ -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;
+}
diff --git a/apps/plugins/lib/highscore.h b/apps/plugins/lib/highscore.h
index ff19213..ba7da24 100644
--- a/apps/plugins/lib/highscore.h
+++ b/apps/plugins/lib/highscore.h
@@ -29,5 +29,6 @@ struct highscore
void highscore_init(struct plugin_api* newrb);
int highscore_save(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