Browse Source

can enter name for score

Thomas B 1 month ago
parent
commit
972740cc98
4 changed files with 60 additions and 20 deletions
  1. 34
    9
      src/main.c
  2. 13
    8
      src/maps.c
  3. 1
    0
      src/maps.h
  4. 12
    3
      src/score.ba0.c

+ 34
- 9
src/main.c View File

26
 #include <stdint.h>
26
 #include <stdint.h>
27
 
27
 
28
 #include "asm/types.h"
28
 #include "asm/types.h"
29
+#include "gb/gb.h"
29
 #include "maps.h"
30
 #include "maps.h"
30
 #include "obj.h"
31
 #include "obj.h"
31
 #include "sprites.h"
32
 #include "sprites.h"
134
     win_init(1);
135
     win_init(1);
135
     win_name(score);
136
     win_name(score);
136
 
137
 
137
-    // TODO ask for name
138
-
139
     move_win(MINWNDPOSX, MINWNDPOSY);
138
     move_win(MINWNDPOSX, MINWNDPOSY);
140
     SHOW_WIN;
139
     SHOW_WIN;
141
 
140
 
142
     DISPLAY_ON;
141
     DISPLAY_ON;
143
     enable_interrupts();
142
     enable_interrupts();
144
 
143
 
145
-    uint16_t name = convert_name('a', 'a', 'a');
144
+    char name[3] = { 'a', 'a', 'a' };
145
+    uint8_t pos = 0;
146
+    win_name_draw(convert_name(name[0], name[1], name[2]), score < 0, pos);
146
 
147
 
147
     while (1) {
148
     while (1) {
148
         key_read();
149
         key_read();
149
 
150
 
150
         if (key_pressed(J_LEFT)) {
151
         if (key_pressed(J_LEFT)) {
151
-            // TODO
152
+            if (pos > 0) {
153
+                pos--;
154
+                win_name_draw(convert_name(name[0], name[1], name[2]), score < 0, pos);
155
+            }
152
         } else if (key_pressed(J_RIGHT)) {
156
         } else if (key_pressed(J_RIGHT)) {
153
-            // TODO
157
+            if (pos < 3) {
158
+                pos++;
159
+                win_name_draw(convert_name(name[0], name[1], name[2]), score < 0, pos);
160
+            }
154
         } else if (key_pressed(J_UP)) {
161
         } else if (key_pressed(J_UP)) {
155
-            // TODO
162
+            if (pos < 3) {
163
+                name[pos]++;
164
+                if (name[pos] > 'z') {
165
+                    name[pos] -= 'z' - 'a' + 1;
166
+                }
167
+                win_name_draw(convert_name(name[0], name[1], name[2]), score < 0, pos);
168
+            }
156
         } else if (key_pressed(J_DOWN)) {
169
         } else if (key_pressed(J_DOWN)) {
157
-            // TODO
170
+            if (pos < 3) {
171
+                name[pos]--;
172
+                if (name[pos] < 'a') {
173
+                    name[pos] += 'z' - 'a' + 1;
174
+                }
175
+                win_name_draw(convert_name(name[0], name[1], name[2]), score < 0, pos);
176
+            }
158
         } else if (key_pressed(J_A)) {
177
         } else if (key_pressed(J_A)) {
159
-            // TODO
178
+            if (pos < 3) {
179
+                pos++;
180
+                win_name_draw(convert_name(name[0], name[1], name[2]), score < 0, pos);
181
+            } else {
182
+                break;
183
+            }
184
+        } else if (key_pressed(J_START)) {
160
             break;
185
             break;
161
         }
186
         }
162
 
187
 
163
         vsync();
188
         vsync();
164
     }
189
     }
165
 
190
 
166
-    return name;
191
+    return convert_name(name[0], name[1], name[2]);
167
 }
192
 }
168
 
193
 
169
 static void sgb_init(void) NONBANKED {
194
 static void sgb_init(void) NONBANKED {

+ 13
- 8
src/maps.c View File

115
                   (is_black ? num_attr_2 : num_attr_1) + off, BANK(maps));
115
                   (is_black ? num_attr_2 : num_attr_1) + off, BANK(maps));
116
 }
116
 }
117
 
117
 
118
-static void str3(uint16_t name, uint8_t x_off, uint8_t y_off, uint8_t is_black) NONBANKED {
119
-    character((name >> 10) & 0x1F, 0, x_off, y_off, is_black);
120
-    character((name >>  5) & 0x1F, 1, x_off, y_off, is_black);
121
-    character((name >>  0) & 0x1F, 2, x_off, y_off, is_black);
118
+static void str3(uint16_t name, uint8_t x_off, uint8_t y_off,
119
+                 uint8_t is_black_a, uint8_t is_black_b, uint8_t is_black_c) NONBANKED {
120
+    character((name >> 10) & 0x1F, 0, x_off, y_off, is_black_a);
121
+    character((name >>  5) & 0x1F, 1, x_off, y_off, is_black_b);
122
+    character((name >>  0) & 0x1F, 2, x_off, y_off, is_black_c);
122
 }
123
 }
123
 
124
 
124
 static void str(const char *s, uint8_t x_off, uint8_t y_off, uint8_t is_black) NONBANKED {
125
 static void str(const char *s, uint8_t x_off, uint8_t y_off, uint8_t is_black) NONBANKED {
202
 }
203
 }
203
 
204
 
204
 void win_score_draw(struct scores score, uint8_t off, uint8_t is_black) NONBANKED {
205
 void win_score_draw(struct scores score, uint8_t off, uint8_t is_black) NONBANKED {
205
-    str3(score.name, 0, 4 + off * 3, is_black);
206
+    str3(score.name, 0, 4 + off * 3, is_black, is_black, is_black);
206
     number(is_black ? -score.score : score.score, 7, 4 + off * 3, is_black);
207
     number(is_black ? -score.score : score.score, 7, 4 + off * 3, is_black);
207
 }
208
 }
208
 
209
 
217
     str("enter", 10 - 5, 6, score < 0);
218
     str("enter", 10 - 5, 6, score < 0);
218
     str("name", 10 - 4, 8, score < 0);
219
     str("name", 10 - 4, 8, score < 0);
219
 
220
 
220
-    // placeholder
221
-    str("aaa", 10 - 3, 12, score < 0);
222
-
223
     str("start ok", 10 - 8, 16, score < 0);
221
     str("start ok", 10 - 8, 16, score < 0);
224
 }
222
 }
225
 
223
 
224
+void win_name_draw(uint16_t name, uint8_t is_black, uint8_t pos) NONBANKED {
225
+    str3(name, 10 - 3, 12,
226
+         (pos == 0) ? !is_black : is_black,
227
+         (pos == 1) ? !is_black : is_black,
228
+         (pos == 2) ? !is_black : is_black);
229
+}
230
+
226
 uint8_t win_game_draw(int32_t score) NONBANKED {
231
 uint8_t win_game_draw(int32_t score) NONBANKED {
227
     fill_win(0, 0, 10, 2, fnt_off + numbers_fnt_TILE_COUNT, 0x81);
232
     fill_win(0, 0, 10, 2, fnt_off + numbers_fnt_TILE_COUNT, 0x81);
228
 
233
 

+ 1
- 0
src/maps.h View File

31
 void win_score_clear(uint8_t is_black);
31
 void win_score_clear(uint8_t is_black);
32
 void win_score_draw(struct scores score, uint8_t off, uint8_t is_black);
32
 void win_score_draw(struct scores score, uint8_t off, uint8_t is_black);
33
 void win_name(int32_t score);
33
 void win_name(int32_t score);
34
+void win_name_draw(uint16_t name, uint8_t is_black, uint8_t pos);
34
 uint8_t win_game_draw(int32_t score);
35
 uint8_t win_game_draw(int32_t score);
35
 
36
 
36
 BANKREF_EXTERN(maps)
37
 BANKREF_EXTERN(maps)

+ 12
- 3
src/score.ba0.c View File

98
     scores_crc = calc_crc();
98
     scores_crc = calc_crc();
99
 }
99
 }
100
 
100
 
101
+static uint8_t score_pos(int32_t score) NONBANKED {
102
+    // TODO find place for new score
103
+    return (score < 0) ? 9 : 0;
104
+}
105
+
101
 uint8_t score_ranking(int32_t score) NONBANKED {
106
 uint8_t score_ranking(int32_t score) NONBANKED {
102
     ENABLE_RAM;
107
     ENABLE_RAM;
103
     SWITCH_RAM(0);
108
     SWITCH_RAM(0);
107
         score_init();
112
         score_init();
108
     }
113
     }
109
 
114
 
110
-    // TODO
111
-    uint8_t r = 1;
115
+    uint8_t r = (score_pos(score) < (SCORE_NUM * 2)) ? 1 : 0;
112
 
116
 
113
     DISABLE_RAM;
117
     DISABLE_RAM;
114
     return r;
118
     return r;
123
         score_init();
127
         score_init();
124
     }
128
     }
125
 
129
 
126
-    // TODO
130
+    uint8_t new = score_pos(score.score);
131
+
132
+    // TODO move old scores out of the way
133
+
134
+    scores[new] = score;
135
+    scores_crc = calc_crc();
127
 
136
 
128
     DISABLE_RAM;
137
     DISABLE_RAM;
129
 }
138
 }

Loading…
Cancel
Save