Browse Source

start work on score entry

Thomas B 1 month ago
parent
commit
e0b0efca06
3 changed files with 70 additions and 6 deletions
  1. 51
    5
      src/main.c
  2. 17
    1
      src/score.ba0.c
  3. 2
    0
      src/score.h

+ 51
- 5
src/main.c View File

23
 #include <gbdk/platform.h>
23
 #include <gbdk/platform.h>
24
 #include <gbdk/metasprites.h>
24
 #include <gbdk/metasprites.h>
25
 #include <rand.h>
25
 #include <rand.h>
26
+#include <stdint.h>
26
 
27
 
28
+#include "asm/types.h"
27
 #include "maps.h"
29
 #include "maps.h"
28
 #include "obj.h"
30
 #include "obj.h"
29
 #include "sprites.h"
31
 #include "sprites.h"
38
     hide_sprites_range(SPR_NUM_START, MAX_HARDWARE_SPRITES);
40
     hide_sprites_range(SPR_NUM_START, MAX_HARDWARE_SPRITES);
39
     win_score_clear(is_black);
41
     win_score_clear(is_black);
40
 
42
 
41
-    move_win(MINWNDPOSX + 0, MINWNDPOSY);
43
+    move_win(MINWNDPOSX, MINWNDPOSY);
42
     SHOW_WIN;
44
     SHOW_WIN;
43
 
45
 
44
     for (uint8_t i = 0; i < SCORE_NUM; i++) {
46
     for (uint8_t i = 0; i < SCORE_NUM; i++) {
70
         win_splash_draw(-low, high);
72
         win_splash_draw(-low, high);
71
     }
73
     }
72
 
74
 
73
-    move_win(MINWNDPOSX + 0, MINWNDPOSY + DEVICE_SCREEN_PX_HEIGHT - 16);
75
+    move_win(MINWNDPOSX, MINWNDPOSY + DEVICE_SCREEN_PX_HEIGHT - 16);
74
     SHOW_WIN;
76
     SHOW_WIN;
75
 }
77
 }
76
 
78
 
113
     }
115
     }
114
 }
116
 }
115
 
117
 
118
+uint16_t ask_name(void) NONBANKED {
119
+    disable_interrupts();
120
+    DISPLAY_OFF;
121
+    map_title();
122
+    SHOW_BKG;
123
+    SHOW_SPRITES;
124
+    SPRITES_8x8;
125
+
126
+    hide_sprites_range(SPR_NUM_START, MAX_HARDWARE_SPRITES);
127
+
128
+    // TODO ask for name
129
+
130
+    move_win(MINWNDPOSX, MINWNDPOSY);
131
+    SHOW_WIN;
132
+
133
+    DISPLAY_ON;
134
+    enable_interrupts();
135
+
136
+    uint16_t name = convert_name('a', 'a', 'a');
137
+
138
+    while (1) {
139
+        key_read();
140
+
141
+        if (key_pressed(J_LEFT)) {
142
+            // TODO
143
+        } else if (key_pressed(J_RIGHT)) {
144
+            // TODO
145
+        } else if (key_pressed(J_UP)) {
146
+            // TODO
147
+        } else if (key_pressed(J_DOWN)) {
148
+            // TODO
149
+        } else if (key_pressed(J_A)) {
150
+            // TODO
151
+            break;
152
+        }
153
+
154
+        vsync();
155
+    }
156
+
157
+    return name;
158
+}
159
+
116
 void main(void) NONBANKED {
160
 void main(void) NONBANKED {
117
     spr_init();
161
     spr_init();
118
     snd_init();
162
     snd_init();
127
     while (1) {
171
     while (1) {
128
         int32_t score = game();
172
         int32_t score = game();
129
 
173
 
130
-        // TODO ask for name of player
131
-        struct scores s = { .name = 0x00, .score = score };
132
-        score_add(s);
174
+        if (score_ranking(score)) {
175
+            uint16_t name = ask_name();
176
+            struct scores s = { .name = name, .score = score };
177
+            score_add(s);
178
+        }
133
 
179
 
134
         splash();
180
         splash();
135
     }
181
     }

+ 17
- 1
src/score.ba0.c View File

24
 static struct scores scores[SCORE_NUM * 2];
24
 static struct scores scores[SCORE_NUM * 2];
25
 static uint32_t scores_crc;
25
 static uint32_t scores_crc;
26
 
26
 
27
-static uint16_t convert_name(char a, char b, char c) {
27
+uint16_t convert_name(char a, char b, char c) NONBANKED {
28
     // convert to lowercase
28
     // convert to lowercase
29
     if ((a >= 'A') && (a <= 'Z')) a = a - 'A' + 'a';
29
     if ((a >= 'A') && (a <= 'Z')) a = a - 'A' + 'a';
30
     if ((b >= 'A') && (b <= 'Z')) b = b - 'A' + 'a';
30
     if ((b >= 'A') && (b <= 'Z')) b = b - 'A' + 'a';
98
     scores_crc = calc_crc();
98
     scores_crc = calc_crc();
99
 }
99
 }
100
 
100
 
101
+uint8_t score_ranking(int32_t score) NONBANKED {
102
+    ENABLE_RAM;
103
+    SWITCH_RAM(0);
104
+
105
+    // initialize score table when data is invalid
106
+    if (!check_crc()) {
107
+        score_init();
108
+    }
109
+
110
+    // TODO
111
+    uint8_t r = 1;
112
+
113
+    DISABLE_RAM;
114
+    return r;
115
+}
116
+
101
 void score_add(struct scores score) NONBANKED {
117
 void score_add(struct scores score) NONBANKED {
102
     ENABLE_RAM;
118
     ENABLE_RAM;
103
     SWITCH_RAM(0);
119
     SWITCH_RAM(0);

+ 2
- 0
src/score.h View File

29
     int32_t score;
29
     int32_t score;
30
 };
30
 };
31
 
31
 
32
+uint16_t convert_name(char a, char b, char c);
33
+uint8_t score_ranking(int32_t score);
32
 void score_add(struct scores score);
34
 void score_add(struct scores score);
33
 struct scores score_highest(uint8_t off);
35
 struct scores score_highest(uint8_t off);
34
 struct scores score_lowest(uint8_t off);
36
 struct scores score_lowest(uint8_t off);

Loading…
Cancel
Save