|
@@ -17,52 +17,11 @@
|
17
|
17
|
* See <http://www.gnu.org/licenses/>.
|
18
|
18
|
*/
|
19
|
19
|
|
20
|
|
-#include <gbdk/platform.h>
|
21
|
|
-#include <string.h>
|
22
|
|
-
|
23
|
20
|
#include "banks.h"
|
24
|
|
-#include "config.h"
|
25
|
|
-#include "score.h"
|
26
|
21
|
#include "title_map.h"
|
27
|
22
|
#include "bg_map.h"
|
28
|
|
-#include "numbers_fnt.h"
|
29
|
|
-#include "text_fnt.h"
|
30
|
|
-#include "git.h"
|
31
|
|
-#include "main.h"
|
32
|
23
|
#include "maps.h"
|
33
|
24
|
|
34
|
|
-#define MAX_DIGITS 7
|
35
|
|
-#define LINE_WIDTH 10
|
36
|
|
-
|
37
|
|
-// TODO inverted score color not visible on DMG
|
38
|
|
-
|
39
|
|
-BANKREF(maps)
|
40
|
|
-
|
41
|
|
-const unsigned char num_attr_1[104] = {
|
42
|
|
- 0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,
|
43
|
|
- 0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,
|
44
|
|
- 0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,
|
45
|
|
- 0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,
|
46
|
|
- 0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,
|
47
|
|
- 0x81,0x81,0x81,0x81,
|
48
|
|
-};
|
49
|
|
-
|
50
|
|
-const unsigned char num_attr_2[104] = {
|
51
|
|
- 0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,
|
52
|
|
- 0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,
|
53
|
|
- 0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,
|
54
|
|
- 0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,
|
55
|
|
- 0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,
|
56
|
|
- 0x82,0x82,0x82,0x82,
|
57
|
|
-};
|
58
|
|
-
|
59
|
|
-const palette_color_t num_pal_inv[4] = {
|
60
|
|
- //RGB8( 0, 0, 0), RGB8(248,252,248), RGB8( 0, 0, 0), RGB8( 0, 0, 0)
|
61
|
|
- RGB8( 0, 0, 0), RGB8( 0, 0, 0), RGB8(248,252,248), RGB8( 0, 0, 0)
|
62
|
|
-};
|
63
|
|
-
|
64
|
|
-static uint8_t fnt_off = 0;
|
65
|
|
-
|
66
|
25
|
void map_title(void) NONBANKED {
|
67
|
26
|
START_ROM_BANK(BANK(title_map));
|
68
|
27
|
set_bkg_palette(OAMF_CGB_PAL0, title_map_PALETTE_COUNT, title_map_palettes);
|
|
@@ -100,293 +59,3 @@ void map_game(void) NONBANKED {
|
100
|
59
|
set_bkg_tiles(0, 0, bg_map_WIDTH / bg_map_TILE_W, bg_map_HEIGHT / bg_map_TILE_H, bg_map_map);
|
101
|
60
|
END_ROM_BANK();
|
102
|
61
|
}
|
103
|
|
-
|
104
|
|
-void win_init(uint8_t is_splash) NONBANKED {
|
105
|
|
- fnt_off = is_splash ? title_map_TILE_COUNT : bg_map_TILE_COUNT;
|
106
|
|
-
|
107
|
|
- START_ROM_BANK(BANK(numbers_fnt));
|
108
|
|
- set_bkg_palette(OAMF_CGB_PAL0 + bg_map_PALETTE_COUNT, numbers_fnt_PALETTE_COUNT, numbers_fnt_palettes);
|
109
|
|
- set_win_data(fnt_off, numbers_fnt_TILE_COUNT, numbers_fnt_tiles);
|
110
|
|
- END_ROM_BANK();
|
111
|
|
-
|
112
|
|
- START_ROM_BANK_2(BANK(maps));
|
113
|
|
- set_bkg_palette(OAMF_CGB_PAL0 + bg_map_PALETTE_COUNT + numbers_fnt_PALETTE_COUNT, numbers_fnt_PALETTE_COUNT, num_pal_inv);
|
114
|
|
- END_ROM_BANK();
|
115
|
|
-
|
116
|
|
- if (is_splash) {
|
117
|
|
- START_ROM_BANK_2(BANK(text_fnt));
|
118
|
|
- set_win_data(fnt_off + numbers_fnt_TILE_COUNT, text_fnt_TILE_COUNT, text_fnt_tiles);
|
119
|
|
- END_ROM_BANK();
|
120
|
|
- }
|
121
|
|
-}
|
122
|
|
-
|
123
|
|
-static void set_win_based(uint8_t x, uint8_t y, uint8_t w, uint8_t h,
|
124
|
|
- const uint8_t *tiles, uint8_t base_tile, uint8_t tile_bank,
|
125
|
|
- const uint8_t *attributes, uint8_t attr_bank) NONBANKED {
|
126
|
|
- if (attributes != NULL) {
|
127
|
|
- START_ROM_BANK(attr_bank);
|
128
|
|
- VBK_REG = VBK_ATTRIBUTES;
|
129
|
|
- set_win_tiles(x, y, w, h, attributes);
|
130
|
|
- END_ROM_BANK();
|
131
|
|
- } else {
|
132
|
|
- VBK_REG = VBK_ATTRIBUTES;
|
133
|
|
- fill_win_rect(x, y, w, h, 0x00);
|
134
|
|
- }
|
135
|
|
-
|
136
|
|
- START_ROM_BANK(tile_bank);
|
137
|
|
- VBK_REG = VBK_TILES;
|
138
|
|
- set_win_based_tiles(x, y, w, h, tiles, base_tile);
|
139
|
|
- END_ROM_BANK();
|
140
|
|
-}
|
141
|
|
-
|
142
|
|
-static void character(uint8_t c, uint8_t pos, uint8_t x_off, uint8_t y_off, uint8_t is_black) NONBANKED {
|
143
|
|
- uint8_t off = c * text_fnt_WIDTH / text_fnt_TILE_W;
|
144
|
|
-
|
145
|
|
- set_win_based(x_off + (pos * text_fnt_WIDTH / text_fnt_TILE_W), y_off,
|
146
|
|
- text_fnt_WIDTH / text_fnt_TILE_W, 1,
|
147
|
|
- text_fnt_map + off, fnt_off + numbers_fnt_TILE_COUNT, BANK(text_fnt),
|
148
|
|
- (is_black ? num_attr_2 : num_attr_1) + off, BANK(maps));
|
149
|
|
-
|
150
|
|
- set_win_based(x_off + (pos * text_fnt_WIDTH / text_fnt_TILE_W), y_off + 1,
|
151
|
|
- text_fnt_WIDTH / text_fnt_TILE_W, 1,
|
152
|
|
- text_fnt_map + off + (sizeof(text_fnt_map) / 2), fnt_off + numbers_fnt_TILE_COUNT, BANK(text_fnt),
|
153
|
|
- (is_black ? num_attr_2 : num_attr_1) + off, BANK(maps));
|
154
|
|
-}
|
155
|
|
-
|
156
|
|
-static void str3(uint16_t name, uint8_t x_off, uint8_t y_off,
|
157
|
|
- uint8_t is_black_a, uint8_t is_black_b, uint8_t is_black_c) NONBANKED {
|
158
|
|
- character((name >> 10) & 0x1F, 0, x_off, y_off, is_black_a);
|
159
|
|
- character((name >> 5) & 0x1F, 1, x_off, y_off, is_black_b);
|
160
|
|
- character((name >> 0) & 0x1F, 2, x_off, y_off, is_black_c);
|
161
|
|
-}
|
162
|
|
-
|
163
|
|
-static void digit(uint8_t val, uint8_t pos, uint8_t x_off, uint8_t y_off, uint8_t is_black) NONBANKED {
|
164
|
|
- uint8_t off = val * numbers_fnt_WIDTH / numbers_fnt_TILE_W;
|
165
|
|
-
|
166
|
|
- set_win_based(x_off + (pos * numbers_fnt_WIDTH / numbers_fnt_TILE_W), y_off,
|
167
|
|
- numbers_fnt_WIDTH / numbers_fnt_TILE_W, 1,
|
168
|
|
- numbers_fnt_map + off, fnt_off, BANK(numbers_fnt),
|
169
|
|
- (is_black ? num_attr_2 : num_attr_1) + off, BANK(maps));
|
170
|
|
-
|
171
|
|
- set_win_based(x_off + (pos * numbers_fnt_WIDTH / numbers_fnt_TILE_W), y_off + 1,
|
172
|
|
- numbers_fnt_WIDTH / numbers_fnt_TILE_W, 1,
|
173
|
|
- numbers_fnt_map + off + (sizeof(numbers_fnt_map) / 2), fnt_off, BANK(numbers_fnt),
|
174
|
|
- (is_black ? num_attr_2 : num_attr_1) + off, BANK(maps));
|
175
|
|
-}
|
176
|
|
-
|
177
|
|
-static void str_l(const char *s, uint8_t len, uint8_t x_off, uint8_t y_off, uint8_t is_black) NONBANKED {
|
178
|
|
- for (uint8_t n = 0; (*s) && (n < LINE_WIDTH) && (n < len); n++) {
|
179
|
|
- char c = *(s++);
|
180
|
|
- if ((c >= 'A') && (c <= 'Z')) {
|
181
|
|
- c = c - 'A' + 'a';
|
182
|
|
- }
|
183
|
|
- if ((c >= '0') && (c <= '9')) {
|
184
|
|
- digit(c - '0', n, x_off, y_off, is_black);
|
185
|
|
- } else if ((c >= 'a') && (c <= 'z')) {
|
186
|
|
- character(c - 'a', n, x_off, y_off, is_black);
|
187
|
|
- }
|
188
|
|
- }
|
189
|
|
-}
|
190
|
|
-
|
191
|
|
-static void str(const char *s, uint8_t x_off, uint8_t y_off, uint8_t is_black) NONBANKED {
|
192
|
|
- str_l(s, 0xFF, x_off, y_off, is_black);
|
193
|
|
-}
|
194
|
|
-
|
195
|
|
-static void str_center(const char *s, uint8_t y_off, uint8_t is_black) NONBANKED {
|
196
|
|
- uint8_t n = strlen(s);
|
197
|
|
- if (n > LINE_WIDTH) n = LINE_WIDTH;
|
198
|
|
- str(s, LINE_WIDTH - n, y_off, is_black);
|
199
|
|
-}
|
200
|
|
-
|
201
|
|
-static void str_lines(const char *s, uint8_t y_off, uint8_t is_black) NONBANKED {
|
202
|
|
- if (strlen(s) > 10) {
|
203
|
|
- str(s, 0, y_off, is_black);
|
204
|
|
- str_center(s + 10, y_off + 2, is_black);
|
205
|
|
- } else {
|
206
|
|
- str_center(s, y_off, is_black);
|
207
|
|
- }
|
208
|
|
-}
|
209
|
|
-
|
210
|
|
-static uint8_t number(int32_t score, uint8_t x_off, uint8_t y_off, uint8_t is_black) NONBANKED {
|
211
|
|
- // TODO can not set numbers larger than int16 max?!
|
212
|
|
- //score = 32767 + 1; // wtf?!
|
213
|
|
-
|
214
|
|
- uint8_t len = 0;
|
215
|
|
- uint8_t digits[MAX_DIGITS];
|
216
|
|
- do {
|
217
|
|
- digits[len++] = score % 10L;
|
218
|
|
- score = score / 10L;
|
219
|
|
- if (len >= MAX_DIGITS) {
|
220
|
|
- break;
|
221
|
|
- }
|
222
|
|
- } while (score > 0);
|
223
|
|
-
|
224
|
|
- // if the number was too large for our buffer don't draw anything
|
225
|
|
- if (score > 0) {
|
226
|
|
- return 0;
|
227
|
|
- }
|
228
|
|
-
|
229
|
|
- uint8_t off = (x_off == 0xFF) ? (LINE_WIDTH - len) : ((x_off == 0xFE) ? ((LINE_WIDTH * 2) - (len * 2)) : x_off);
|
230
|
|
- for (uint8_t i = 0; i < len; i++) {
|
231
|
|
- digit(digits[len - i - 1], i, off, y_off, is_black);
|
232
|
|
- }
|
233
|
|
-
|
234
|
|
- return 8 * len * 2;
|
235
|
|
-}
|
236
|
|
-
|
237
|
|
-static void fill_win(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t tile, uint8_t attr) NONBANKED {
|
238
|
|
- VBK_REG = VBK_ATTRIBUTES;
|
239
|
|
- fill_win_rect(x, y, w, h, attr);
|
240
|
|
- VBK_REG = VBK_TILES;
|
241
|
|
- fill_win_rect(x, y, w, h, tile);
|
242
|
|
-}
|
243
|
|
-
|
244
|
|
-void win_splash_draw(int32_t lowest, int32_t highest) NONBANKED {
|
245
|
|
- // reuse full black and white tiles at 0 and 1 from splash bg
|
246
|
|
- fill_win(0, 0, 10, 4, 0, 0x00);
|
247
|
|
- fill_win(10, 0, 10, 4, 1, 0x00);
|
248
|
|
-
|
249
|
|
- // only show on splash if they fit
|
250
|
|
- if ((lowest <= 99999) && (highest <= 99999)) {
|
251
|
|
- number(lowest, 0, 0, 1);
|
252
|
|
- number(highest, 0xFE, 0, 0);
|
253
|
|
-
|
254
|
|
- str("top", 0, 2, 1);
|
255
|
|
- str("score", 10, 2, 0);
|
256
|
|
- }
|
257
|
|
-}
|
258
|
|
-
|
259
|
|
-void win_score_clear(uint8_t is_black) NONBANKED {
|
260
|
|
- set_win_based(0, 0,
|
261
|
|
- title_map_WIDTH / title_map_TILE_W, title_map_HEIGHT / title_map_TILE_H,
|
262
|
|
- title_map_map, 0, BANK(title_map), title_map_MAP_ATTRIBUTES, BANK(title_map));
|
263
|
|
-
|
264
|
|
- str_center(is_black ? "black" : "white", 1, is_black);
|
265
|
|
-}
|
266
|
|
-
|
267
|
|
-void win_score_draw(struct scores score, uint8_t off, uint8_t is_black) NONBANKED {
|
268
|
|
- str3(score.name, 0, 4 + off * 3, is_black, is_black, is_black);
|
269
|
|
- number(is_black ? -score.score : score.score, 7, 4 + off * 3, is_black);
|
270
|
|
-}
|
271
|
|
-
|
272
|
|
-void win_about(void) NONBANKED {
|
273
|
|
- set_win_based(0, 0,
|
274
|
|
- title_map_WIDTH / title_map_TILE_W, title_map_HEIGHT / title_map_TILE_H,
|
275
|
|
- title_map_map, 0, BANK(title_map), title_map_MAP_ATTRIBUTES, BANK(title_map));
|
276
|
|
-
|
277
|
|
- str_center("Duality", 0, 1);
|
278
|
|
- str_center("xythobuz", 2, 1);
|
279
|
|
-
|
280
|
|
- char line_buff[2 * LINE_WIDTH + 1] = {0};
|
281
|
|
-
|
282
|
|
- START_ROM_BANK(BANK(git));
|
283
|
|
- strncpy(line_buff, git_version, 2 * LINE_WIDTH);
|
284
|
|
- END_ROM_BANK();
|
285
|
|
-
|
286
|
|
- str_lines(line_buff, 7, 0);
|
287
|
|
-
|
288
|
|
- str_l(&__DATE__[7], 4, 0, 14, 1); // year (4)
|
289
|
|
- str_l(&__DATE__[0], 3, (4 * 2) + 1, 14, 1); // month (3)
|
290
|
|
- str_l(&__DATE__[4], 2, (7 * 2) + 2, 14, 1); // day (2)
|
291
|
|
-
|
292
|
|
- str(__TIME__, 4, 16, 0);
|
293
|
|
-}
|
294
|
|
-
|
295
|
|
-void win_debug(void) NONBANKED {
|
296
|
|
- set_win_based(0, 0,
|
297
|
|
- title_map_WIDTH / title_map_TILE_W, title_map_HEIGHT / title_map_TILE_H,
|
298
|
|
- title_map_map, 0, BANK(title_map), title_map_MAP_ATTRIBUTES, BANK(title_map));
|
299
|
|
-
|
300
|
|
- // TODO paging when more options added
|
301
|
|
- uint8_t off = (10 - DEBUG_ENTRY_COUNT) / 2;
|
302
|
|
-
|
303
|
|
- str_center("Debug Menu", 0, 0);
|
304
|
|
-
|
305
|
|
- for (uint8_t i = 0; (i < DEBUG_ENTRY_COUNT) && (i < 7); i++) {
|
306
|
|
- char name_buff[ENTRY_NAME_LEN + 2 + 1] = {0};
|
307
|
|
-
|
308
|
|
- START_ROM_BANK(BANK(main));
|
309
|
|
- strncpy(name_buff, debug_entries[i].name, ENTRY_NAME_LEN + 1);
|
310
|
|
-
|
311
|
|
- uint8_t n_len = strlen(name_buff);
|
312
|
|
- name_buff[n_len] = ' ';
|
313
|
|
- if (debug_entries[i].flag == DBG_NONE) {
|
314
|
|
- if (debug_menu_index == i) {
|
315
|
|
- name_buff[n_len + 1] = debug_special_value + '0';
|
316
|
|
- } else {
|
317
|
|
- name_buff[n_len + 1] = '0';
|
318
|
|
- }
|
319
|
|
- } else {
|
320
|
|
- name_buff[n_len + 1] = (conf_get()->debug_flags & debug_entries[i].flag) ? '1' : '0';
|
321
|
|
- }
|
322
|
|
- name_buff[n_len + 2] = '\0';
|
323
|
|
- n_len += 2;
|
324
|
|
- END_ROM_BANK();
|
325
|
|
-
|
326
|
|
- str(name_buff, (LINE_WIDTH - n_len) * 2, (i * 2) + 3 + off, (debug_menu_index == i) ? 1 : 0);
|
327
|
|
- }
|
328
|
|
-}
|
329
|
|
-
|
330
|
|
-void win_conf(void) NONBANKED {
|
331
|
|
- set_win_based(0, 0,
|
332
|
|
- title_map_WIDTH / title_map_TILE_W, title_map_HEIGHT / title_map_TILE_H,
|
333
|
|
- title_map_map, 0, BANK(title_map), title_map_MAP_ATTRIBUTES, BANK(title_map));
|
334
|
|
-
|
335
|
|
- // TODO paging when more options added
|
336
|
|
- uint8_t off = (10 - CONF_ENTRY_COUNT) / 2;
|
337
|
|
-
|
338
|
|
- str_center("Conf Menu", 0, 0);
|
339
|
|
-
|
340
|
|
- for (uint8_t i = 0; (i < CONF_ENTRY_COUNT) && (i < 7); i++) {
|
341
|
|
- char name_buff[ENTRY_NAME_LEN + 2 + 1] = {0};
|
342
|
|
-
|
343
|
|
- START_ROM_BANK(BANK(main));
|
344
|
|
- strncpy(name_buff, conf_entries[i].name, ENTRY_NAME_LEN + 1);
|
345
|
|
-
|
346
|
|
- uint8_t n_len = strlen(name_buff);
|
347
|
|
- name_buff[n_len] = ' ';
|
348
|
|
- if (*conf_entries[i].var < 10) {
|
349
|
|
- name_buff[n_len + 1] = *conf_entries[i].var + '0';
|
350
|
|
- } else {
|
351
|
|
- name_buff[n_len + 1] = *conf_entries[i].var - 10 + 'A';
|
352
|
|
- }
|
353
|
|
- name_buff[n_len + 2] = '\0';
|
354
|
|
- n_len += 2;
|
355
|
|
- END_ROM_BANK();
|
356
|
|
-
|
357
|
|
- str(name_buff, (LINE_WIDTH - n_len) * 2, (i * 2) + 3 + off, (debug_menu_index == i) ? 1 : 0);
|
358
|
|
- }
|
359
|
|
-}
|
360
|
|
-
|
361
|
|
-void win_name(int32_t score) NONBANKED {
|
362
|
|
- set_win_based(0, 0,
|
363
|
|
- title_map_WIDTH / title_map_TILE_W, title_map_HEIGHT / title_map_TILE_H,
|
364
|
|
- title_map_map, 0, BANK(title_map), title_map_MAP_ATTRIBUTES, BANK(title_map));
|
365
|
|
-
|
366
|
|
- str_center("score", 1, score < 0);
|
367
|
|
- number(score < 0 ? -score : score, 0xFF, 3, score < 0);
|
368
|
|
-
|
369
|
|
- str_center("enter", 6, score < 0);
|
370
|
|
- str_center("name", 8, score < 0);
|
371
|
|
-
|
372
|
|
- str_center("start ok", 16, score < 0);
|
373
|
|
-}
|
374
|
|
-
|
375
|
|
-void win_name_draw(uint16_t name, uint8_t is_black, uint8_t pos) NONBANKED {
|
376
|
|
- str3(name, LINE_WIDTH - 3, 12,
|
377
|
|
- (pos == 0) ? !is_black : is_black,
|
378
|
|
- (pos == 1) ? !is_black : is_black,
|
379
|
|
- (pos == 2) ? !is_black : is_black);
|
380
|
|
-}
|
381
|
|
-
|
382
|
|
-uint8_t win_game_draw(int32_t score) NONBANKED {
|
383
|
|
- fill_win(0, 0, 10, 2, fnt_off + numbers_fnt_TILE_COUNT, 0x81);
|
384
|
|
-
|
385
|
|
- uint8_t is_black = 0;
|
386
|
|
- if (score < 0) {
|
387
|
|
- score = -score;
|
388
|
|
- is_black = 1;
|
389
|
|
- }
|
390
|
|
-
|
391
|
|
- return number(score, 0, 0, is_black);
|
392
|
|
-}
|