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,7 +23,9 @@
23 23
 #include <gbdk/platform.h>
24 24
 #include <gbdk/metasprites.h>
25 25
 #include <rand.h>
26
+#include <stdint.h>
26 27
 
28
+#include "asm/types.h"
27 29
 #include "maps.h"
28 30
 #include "obj.h"
29 31
 #include "sprites.h"
@@ -38,7 +40,7 @@ static void highscore(uint8_t is_black) NONBANKED {
38 40
     hide_sprites_range(SPR_NUM_START, MAX_HARDWARE_SPRITES);
39 41
     win_score_clear(is_black);
40 42
 
41
-    move_win(MINWNDPOSX + 0, MINWNDPOSY);
43
+    move_win(MINWNDPOSX, MINWNDPOSY);
42 44
     SHOW_WIN;
43 45
 
44 46
     for (uint8_t i = 0; i < SCORE_NUM; i++) {
@@ -70,7 +72,7 @@ static void splash_win(void) NONBANKED {
70 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 76
     SHOW_WIN;
75 77
 }
76 78
 
@@ -113,6 +115,48 @@ static void splash(void) NONBANKED {
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 160
 void main(void) NONBANKED {
117 161
     spr_init();
118 162
     snd_init();
@@ -127,9 +171,11 @@ void main(void) NONBANKED {
127 171
     while (1) {
128 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 180
         splash();
135 181
     }

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

@@ -24,7 +24,7 @@
24 24
 static struct scores scores[SCORE_NUM * 2];
25 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 28
     // convert to lowercase
29 29
     if ((a >= 'A') && (a <= 'Z')) a = a - 'A' + 'a';
30 30
     if ((b >= 'A') && (b <= 'Z')) b = b - 'A' + 'a';
@@ -98,6 +98,22 @@ static void score_init(void) NONBANKED {
98 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 117
 void score_add(struct scores score) NONBANKED {
102 118
     ENABLE_RAM;
103 119
     SWITCH_RAM(0);

+ 2
- 0
src/score.h View File

@@ -29,6 +29,8 @@ struct scores {
29 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 34
 void score_add(struct scores score);
33 35
 struct scores score_highest(uint8_t off);
34 36
 struct scores score_lowest(uint8_t off);

Loading…
Cancel
Save