|
@@ -18,12 +18,42 @@
|
18
|
18
|
*/
|
19
|
19
|
|
20
|
20
|
#include <gbdk/platform.h>
|
|
21
|
+#include <string.h>
|
21
|
22
|
|
22
|
23
|
#include "score.h"
|
|
24
|
+#include "gb/gb.h"
|
23
|
25
|
|
24
|
26
|
static struct scores scores[SCORE_NUM * 2];
|
25
|
27
|
static uint32_t scores_crc;
|
26
|
28
|
|
|
29
|
+BANKREF(score)
|
|
30
|
+
|
|
31
|
+#define NAME(a, b, c) (((uint16_t)(a - 'a') << 10) | ((uint16_t)(b - 'a') << 5) | (uint16_t)(c - 'a'))
|
|
32
|
+
|
|
33
|
+const struct scores initial_scores[SCORE_NUM * 2] = {
|
|
34
|
+ //{ .name = NAME('a', 'd', 'z'), .score = 10000 },
|
|
35
|
+ //{ .name = NAME('c', 'a', 'n'), .score = 7500 },
|
|
36
|
+ //{ .name = NAME('i', 'm', 'y'), .score = 5000 },
|
|
37
|
+ //{ .name = NAME('w', 'i', 'l'), .score = 2500 },
|
|
38
|
+ { .name = NAME('d', 'b', 'p'), .score = 1000 },
|
|
39
|
+ { .name = NAME('d', 'a', 'v'), .score = 750 },
|
|
40
|
+ { .name = NAME('d', 'o', 'd'), .score = 500 },
|
|
41
|
+ //{ .name = NAME('n', 'f', '.'), .score = 250 },
|
|
42
|
+ { .name = NAME('k', 'm', 'b'), .score = 175 },
|
|
43
|
+ { .name = NAME('s', 'j', 'l'), .score = 100 },
|
|
44
|
+
|
|
45
|
+ { .name = NAME('j', 'u', 'd'), .score = -100 },
|
|
46
|
+ //{ .name = NAME('1', '0', '1'), .score = -175 },
|
|
47
|
+ { .name = NAME('g', 'a', 'z'), .score = -250 },
|
|
48
|
+ { .name = NAME('n', 'o', 'n'), .score = -500 },
|
|
49
|
+ { .name = NAME('l', 'r', 'g'), .score = -750 },
|
|
50
|
+ { .name = NAME('d', 'a', 'n'), .score = -1000 },
|
|
51
|
+ //{ .name = NAME('w', 'd', 'y'), .score = -2500 },
|
|
52
|
+ //{ .name = NAME('s', 'i', 's'), .score = -5000 },
|
|
53
|
+ //{ .name = NAME('k', 'r', 'y'), .score = -7500 },
|
|
54
|
+ //{ .name = NAME('d', 'j', '.'), .score = -10000 },
|
|
55
|
+};
|
|
56
|
+
|
27
|
57
|
uint16_t convert_name(char a, char b, char c) NONBANKED {
|
28
|
58
|
// convert to lowercase
|
29
|
59
|
if ((a >= 'A') && (a <= 'Z')) a = a - 'A' + 'a';
|
|
@@ -64,43 +94,27 @@ static uint8_t check_crc(void) NONBANKED {
|
64
|
94
|
}
|
65
|
95
|
|
66
|
96
|
static void score_init(void) NONBANKED {
|
67
|
|
- // TODO
|
68
|
|
- scores[0].name = convert_name('a', 'b', 'c');
|
69
|
|
- scores[0].score = 10000;
|
70
|
|
-
|
71
|
|
- scores[1].name = convert_name('d', 'e', 'f');
|
72
|
|
- scores[1].score = 8765;
|
73
|
|
-
|
74
|
|
- scores[2].name = convert_name('g', 'h', 'i');
|
75
|
|
- scores[2].score = 6999;
|
76
|
|
-
|
77
|
|
- scores[3].name = convert_name('j', 'k', 'l');
|
78
|
|
- scores[3].score = 4321;
|
79
|
|
-
|
80
|
|
- scores[4].name = convert_name('m', 'n', 'o');
|
81
|
|
- scores[4].score = 2000;
|
82
|
|
-
|
83
|
|
- scores[5].name = convert_name('p', 'q', 'r');
|
84
|
|
- scores[5].score = -2000;
|
85
|
|
-
|
86
|
|
- scores[6].name = convert_name('s', 't', 'u');
|
87
|
|
- scores[6].score = -4321;
|
88
|
|
-
|
89
|
|
- scores[7].name = convert_name('v', 'w', 'x');
|
90
|
|
- scores[7].score = -6999;
|
91
|
|
-
|
92
|
|
- scores[8].name = convert_name('y', 'z', 'c');
|
93
|
|
- scores[8].score = -8765;
|
94
|
|
-
|
95
|
|
- scores[9].name = convert_name('a', 'b', 'c');
|
96
|
|
- scores[9].score = -10000;
|
97
|
|
-
|
|
97
|
+ SWITCH_ROM(BANK(score));
|
|
98
|
+ memcpy(scores, initial_scores, sizeof(scores));
|
98
|
99
|
scores_crc = calc_crc();
|
99
|
100
|
}
|
100
|
101
|
|
101
|
102
|
static uint8_t score_pos(int32_t score) NONBANKED {
|
102
|
|
- // TODO find place for new score
|
103
|
|
- return (score < 0) ? 9 : 0;
|
|
103
|
+ if (score > 0) {
|
|
104
|
+ for (uint8_t i = 0; i < SCORE_NUM; i++) {
|
|
105
|
+ if (score > scores[i].score) {
|
|
106
|
+ return i;
|
|
107
|
+ }
|
|
108
|
+ }
|
|
109
|
+ } else if (score < 0) {
|
|
110
|
+ for (uint8_t i = (SCORE_NUM * 2) - 1; i >= 5; i--) {
|
|
111
|
+ if (score < scores[i].score) {
|
|
112
|
+ return i;
|
|
113
|
+ }
|
|
114
|
+ }
|
|
115
|
+ }
|
|
116
|
+
|
|
117
|
+ return 0xFF;
|
104
|
118
|
}
|
105
|
119
|
|
106
|
120
|
uint8_t score_ranking(int32_t score) NONBANKED {
|
|
@@ -128,11 +142,17 @@ void score_add(struct scores score) NONBANKED {
|
128
|
142
|
}
|
129
|
143
|
|
130
|
144
|
uint8_t new = score_pos(score.score);
|
|
145
|
+ if (new < (SCORE_NUM * 2)) {
|
|
146
|
+ // move old scores out of the way
|
|
147
|
+ if ((score.score > 0) && (new < (SCORE_NUM - 1))) {
|
|
148
|
+ memmove(scores + new + 1, scores + new, sizeof(struct scores) * (SCORE_NUM - 1 - new));
|
|
149
|
+ } else if ((score.score < 0) && (new > SCORE_NUM)) {
|
|
150
|
+ memmove(scores + new - 1, scores + new, sizeof(struct scores) * (new - SCORE_NUM));
|
|
151
|
+ }
|
131
|
152
|
|
132
|
|
- // TODO move old scores out of the way
|
133
|
|
-
|
134
|
|
- scores[new] = score;
|
135
|
|
- scores_crc = calc_crc();
|
|
153
|
+ scores[new] = score;
|
|
154
|
+ scores_crc = calc_crc();
|
|
155
|
+ }
|
136
|
156
|
|
137
|
157
|
DISABLE_RAM;
|
138
|
158
|
}
|