|
@@ -18,17 +18,18 @@
|
18
|
18
|
*/
|
19
|
19
|
|
20
|
20
|
#include <gbdk/platform.h>
|
21
|
|
-
|
22
|
|
-#include "maps.h"
|
23
|
|
-
|
|
21
|
+#include <string.h>
|
24
|
22
|
#include "gb/gb.h"
|
25
|
23
|
#include "score.h"
|
26
|
24
|
#include "title_map.h"
|
27
|
25
|
#include "bg_map.h"
|
28
|
26
|
#include "numbers_fnt.h"
|
29
|
27
|
#include "text_fnt.h"
|
|
28
|
+#include "git.h"
|
|
29
|
+#include "maps.h"
|
30
|
30
|
|
31
|
31
|
#define MAX_DIGITS 7
|
|
32
|
+#define LINE_WIDTH 10
|
32
|
33
|
|
33
|
34
|
// TODO inverted score color not visible on DMG
|
34
|
35
|
|
|
@@ -122,21 +123,6 @@ static void str3(uint16_t name, uint8_t x_off, uint8_t y_off,
|
122
|
123
|
character((name >> 0) & 0x1F, 2, x_off, y_off, is_black_c);
|
123
|
124
|
}
|
124
|
125
|
|
125
|
|
-static void str(const char *s, uint8_t x_off, uint8_t y_off, uint8_t is_black) NONBANKED {
|
126
|
|
- uint8_t n = 0;
|
127
|
|
- while (*s) {
|
128
|
|
- char c = *(s++);
|
129
|
|
- if ((c >= 'A') && (c <= 'Z')) {
|
130
|
|
- c = c - 'A' + 'a';
|
131
|
|
- }
|
132
|
|
- if ((c < 'a') || (c > 'z')) {
|
133
|
|
- n++;
|
134
|
|
- continue;
|
135
|
|
- }
|
136
|
|
- character(c - 'a', n++, x_off, y_off, is_black);
|
137
|
|
- }
|
138
|
|
-}
|
139
|
|
-
|
140
|
126
|
static void digit(uint8_t val, uint8_t pos, uint8_t x_off, uint8_t y_off, uint8_t is_black) NONBANKED {
|
141
|
127
|
uint8_t off = val * numbers_fnt_WIDTH / numbers_fnt_TILE_W;
|
142
|
128
|
|
|
@@ -151,6 +137,39 @@ static void digit(uint8_t val, uint8_t pos, uint8_t x_off, uint8_t y_off, uint8_
|
151
|
137
|
(is_black ? num_attr_2 : num_attr_1) + off, BANK(maps));
|
152
|
138
|
}
|
153
|
139
|
|
|
140
|
+static void str_l(const char *s, uint8_t len, uint8_t x_off, uint8_t y_off, uint8_t is_black) NONBANKED {
|
|
141
|
+ for (uint8_t n = 0; (*s) && (n < LINE_WIDTH) && (n < len); n++) {
|
|
142
|
+ char c = *(s++);
|
|
143
|
+ if ((c >= 'A') && (c <= 'Z')) {
|
|
144
|
+ c = c - 'A' + 'a';
|
|
145
|
+ }
|
|
146
|
+ if ((c >= '0') && (c <= '9')) {
|
|
147
|
+ digit(c - '0', n, x_off, y_off, is_black);
|
|
148
|
+ } else if ((c >= 'a') && (c <= 'z')) {
|
|
149
|
+ character(c - 'a', n, x_off, y_off, is_black);
|
|
150
|
+ }
|
|
151
|
+ }
|
|
152
|
+}
|
|
153
|
+
|
|
154
|
+static void str(const char *s, uint8_t x_off, uint8_t y_off, uint8_t is_black) NONBANKED {
|
|
155
|
+ str_l(s, 0xFF, x_off, y_off, is_black);
|
|
156
|
+}
|
|
157
|
+
|
|
158
|
+static void str_center(const char *s, uint8_t y_off, uint8_t is_black) NONBANKED {
|
|
159
|
+ uint8_t n = strlen(s);
|
|
160
|
+ if (n > LINE_WIDTH) n = LINE_WIDTH;
|
|
161
|
+ str(s, LINE_WIDTH - n, y_off, is_black);
|
|
162
|
+}
|
|
163
|
+
|
|
164
|
+static void str_lines(const char *s, uint8_t y_off, uint8_t is_black) NONBANKED {
|
|
165
|
+ if (strlen(s) > 10) {
|
|
166
|
+ str(s, 0, y_off, is_black);
|
|
167
|
+ str_center(s + 10, y_off + 2, is_black);
|
|
168
|
+ } else {
|
|
169
|
+ str_center(s, y_off, is_black);
|
|
170
|
+ }
|
|
171
|
+}
|
|
172
|
+
|
154
|
173
|
static uint8_t number(int32_t score, uint8_t x_off, uint8_t y_off, uint8_t is_black) NONBANKED {
|
155
|
174
|
// TODO can not set numbers larger than int16 max?!
|
156
|
175
|
//score = 32767 + 1; // wtf?!
|
|
@@ -170,7 +189,7 @@ static uint8_t number(int32_t score, uint8_t x_off, uint8_t y_off, uint8_t is_bl
|
170
|
189
|
return 0;
|
171
|
190
|
}
|
172
|
191
|
|
173
|
|
- uint8_t off = (x_off == 0xFF) ? (10 - len) : ((x_off == 0xFE) ? (20 - (len * 2)) : x_off);
|
|
192
|
+ uint8_t off = (x_off == 0xFF) ? (LINE_WIDTH - len) : ((x_off == 0xFE) ? ((LINE_WIDTH * 2) - (len * 2)) : x_off);
|
174
|
193
|
for (uint8_t i = 0; i < len; i++) {
|
175
|
194
|
digit(digits[len - i - 1], i, off, y_off, is_black);
|
176
|
195
|
}
|
|
@@ -199,7 +218,7 @@ void win_score_clear(uint8_t is_black) NONBANKED {
|
199
|
218
|
title_map_WIDTH / title_map_TILE_W, title_map_HEIGHT / title_map_TILE_H,
|
200
|
219
|
title_map_map, 0, BANK(title_map), title_map_MAP_ATTRIBUTES, BANK(title_map));
|
201
|
220
|
|
202
|
|
- str(is_black ? "black" : "white", 10 - 5, 1, is_black);
|
|
221
|
+ str_center(is_black ? "black" : "white", 1, is_black);
|
203
|
222
|
}
|
204
|
223
|
|
205
|
224
|
void win_score_draw(struct scores score, uint8_t off, uint8_t is_black) NONBANKED {
|
|
@@ -207,22 +226,43 @@ void win_score_draw(struct scores score, uint8_t off, uint8_t is_black) NONBANKE
|
207
|
226
|
number(is_black ? -score.score : score.score, 7, 4 + off * 3, is_black);
|
208
|
227
|
}
|
209
|
228
|
|
|
229
|
+void win_about(void) NONBANKED {
|
|
230
|
+ set_win_based(0, 0,
|
|
231
|
+ title_map_WIDTH / title_map_TILE_W, title_map_HEIGHT / title_map_TILE_H,
|
|
232
|
+ title_map_map, 0, BANK(title_map), title_map_MAP_ATTRIBUTES, BANK(title_map));
|
|
233
|
+
|
|
234
|
+ str_center("Duality", 0, 1);
|
|
235
|
+ str_center("xythobuz", 2, 1);
|
|
236
|
+
|
|
237
|
+ SWITCH_ROM(BANK(git));
|
|
238
|
+ char line_buff[2 * LINE_WIDTH + 1] = {0};
|
|
239
|
+ strncpy(line_buff, git_version, 2 * LINE_WIDTH);
|
|
240
|
+
|
|
241
|
+ str_lines(line_buff, 7, 0);
|
|
242
|
+
|
|
243
|
+ str_l(&__DATE__[7], 4, 0, 14, 1); // year (4)
|
|
244
|
+ str_l(&__DATE__[0], 3, (4 * 2) + 1, 14, 1); // month (3)
|
|
245
|
+ str_l(&__DATE__[4], 2, (7 * 2) + 2, 14, 1); // day (2)
|
|
246
|
+
|
|
247
|
+ str(__TIME__, 4, 16, 0);
|
|
248
|
+}
|
|
249
|
+
|
210
|
250
|
void win_name(int32_t score) NONBANKED {
|
211
|
251
|
set_win_based(0, 0,
|
212
|
252
|
title_map_WIDTH / title_map_TILE_W, title_map_HEIGHT / title_map_TILE_H,
|
213
|
253
|
title_map_map, 0, BANK(title_map), title_map_MAP_ATTRIBUTES, BANK(title_map));
|
214
|
254
|
|
215
|
|
- str("score", 10 - 5, 1, score < 0);
|
|
255
|
+ str_center("score", 1, score < 0);
|
216
|
256
|
number(score < 0 ? -score : score, 0xFF, 3, score < 0);
|
217
|
257
|
|
218
|
|
- str("enter", 10 - 5, 6, score < 0);
|
219
|
|
- str("name", 10 - 4, 8, score < 0);
|
|
258
|
+ str_center("enter", 6, score < 0);
|
|
259
|
+ str_center("name", 8, score < 0);
|
220
|
260
|
|
221
|
|
- str("start ok", 10 - 8, 16, score < 0);
|
|
261
|
+ str_center("start ok", 16, score < 0);
|
222
|
262
|
}
|
223
|
263
|
|
224
|
264
|
void win_name_draw(uint16_t name, uint8_t is_black, uint8_t pos) NONBANKED {
|
225
|
|
- str3(name, 10 - 3, 12,
|
|
265
|
+ str3(name, LINE_WIDTH - 3, 12,
|
226
|
266
|
(pos == 0) ? !is_black : is_black,
|
227
|
267
|
(pos == 1) ? !is_black : is_black,
|
228
|
268
|
(pos == 2) ? !is_black : is_black);
|