Browse Source

add debug counter print options and move lots of stuff from bank zero

Thomas B 3 weeks ago
parent
commit
0e27e40595
7 changed files with 151 additions and 127 deletions
  1. 9
    10
      src/config.h
  2. 2
    1
      src/game.c
  3. 80
    81
      src/main.c
  4. 1
    1
      src/main.h
  5. 31
    29
      src/strings.c
  6. 1
    0
      src/strings.h
  7. 27
    5
      src/window.c

+ 9
- 10
src/config.h View File

@@ -28,16 +28,15 @@
28 28
 enum debug_flag {
29 29
     DBG_NONE = 0,
30 30
 
31
-    DBG_MENU = (1 << 0),
32
-    DBG_MARKER = (1 << 1),
33
-    DBG_GOD_MODE = (1 << 2),
34
-    DBG_NO_OBJ = (1 << 3),
35
-    DBG_NO_FUEL = (1 << 4),
36
-    DBG_FAST = (1 << 5),
37
-
38
-    // TODO could be something other than flags
39
-    DBG_CLEAR_SCORE = (1 << 6),
40
-    DBG_ZERO_SCORE = (1 << 7),
31
+    DBG_MENU        = (1 << 0),
32
+    DBG_MARKER      = (1 << 1),
33
+    DBG_GOD_MODE    = (1 << 2),
34
+    DBG_NO_OBJ      = (1 << 3),
35
+    DBG_NO_FUEL     = (1 << 4),
36
+    DBG_FAST        = (1 << 5),
37
+    DBG_SHOW_FRAMES = (1 << 6),
38
+    DBG_SHOW_TIMER  = (1 << 7),
39
+    DBG_SHOW_STACK  = (1 << 8),
41 40
 };
42 41
 
43 42
 struct config {

+ 2
- 1
src/game.c View File

@@ -496,7 +496,8 @@ int32_t game(enum GAME_MODE mode) NONBANKED {
496 496
 
497 497
         hide_sprites_range(hiwater, MAX_HARDWARE_SPRITES);
498 498
 
499
-        if ((score != prev_score) || ((_cpu == CGB_TYPE) && (conf_get()->debug_flags))) {
499
+        if ((score != prev_score) || ((_cpu == CGB_TYPE)
500
+                && (conf_get()->debug_flags & (DBG_SHOW_FRAMES | DBG_SHOW_TIMER | DBG_SHOW_STACK)))) {
500 501
             uint8_t x_off = win_game_draw(score, 0);
501 502
             move_win(MINWNDPOSX + DEVICE_SCREEN_PX_WIDTH - x_off, MINWNDPOSY + DEVICE_SCREEN_PX_HEIGHT - 16);
502 503
         }

+ 80
- 81
src/main.c View File

@@ -58,18 +58,28 @@ const struct conf_entry conf_entries[CONF_ENTRY_COUNT] = {
58 58
 };
59 59
 
60 60
 const struct debug_entry debug_entries[DEBUG_ENTRY_COUNT] = {
61
-    { .name = "marker",   .flag = DBG_MARKER,      .max = 1 }, // 0
62
-    { .name = "invuln",   .flag = DBG_GOD_MODE,    .max = 1 }, // 1
63
-    { .name = "no-spawn", .flag = DBG_NO_OBJ,      .max = 1 }, // 2
64
-    { .name = "no-fuel",  .flag = DBG_NO_FUEL,     .max = 1 }, // 3
65
-    { .name = "fastmove", .flag = DBG_FAST,        .max = 1 }, // 4
66
-    { .name = "music",    .flag = DBG_NONE,        .max = SND_COUNT }, // 5
67
-    { .name = "sfx-test", .flag = DBG_NONE,        .max = SFX_COUNT }, // 6
68
-    { .name = "cl score", .flag = DBG_CLEAR_SCORE, .max = 1 }, // 7
69
-    { .name = "0 scores", .flag = DBG_ZERO_SCORE,  .max = 1 }, // 8
61
+    { .name = "marker",   .flag = DBG_MARKER,      .max = 1         }, // 0
62
+    { .name = "invuln",   .flag = DBG_GOD_MODE,    .max = 1         }, // 1
63
+    { .name = "no-spawn", .flag = DBG_NO_OBJ,      .max = 1         }, // 2
64
+    { .name = "no-fuel",  .flag = DBG_NO_FUEL,     .max = 1         }, // 3
65
+    { .name = "fastmove", .flag = DBG_FAST,        .max = 1         }, // 4
66
+    { .name = "s-frames", .flag = DBG_SHOW_FRAMES, .max = 1         }, // 5
67
+    { .name = "s-timer",  .flag = DBG_SHOW_TIMER,  .max = 1         }, // 6
68
+    { .name = "s-stack",  .flag = DBG_SHOW_STACK,  .max = 1         }, // 7
69
+
70
+    // keep at end
71
+    { .name = "music",    .flag = DBG_NONE,        .max = SND_COUNT }, // 8
72
+    { .name = "sfx-test", .flag = DBG_NONE,        .max = SFX_COUNT }, // 9
73
+    { .name = "cl score", .flag = DBG_NONE,        .max = 1         }, // 10
74
+    { .name = "0 scores", .flag = DBG_NONE,        .max = 1         }, // 11
70 75
 };
71 76
 
72
-static void list_scores(uint8_t is_black) NONBANKED {
77
+#define DEBUG_MENU_MUSIC_INDEX (DEBUG_ENTRY_COUNT - 4)
78
+#define DEBUG_MENU_SFX_INDEX   (DEBUG_ENTRY_COUNT - 3)
79
+#define DEBUG_MENU_CLEAR_INDEX (DEBUG_ENTRY_COUNT - 2)
80
+#define DEBUG_MENU_ZERO_INDEX  (DEBUG_ENTRY_COUNT - 1)
81
+
82
+static void list_scores(uint8_t is_black) {
73 83
     for (uint8_t i = 0; i < SCORE_NUM; i++) {
74 84
         struct scores score;
75 85
         is_black ? score_lowest(i, &score) : score_highest(i, &score);
@@ -77,7 +87,7 @@ static void list_scores(uint8_t is_black) NONBANKED {
77 87
     }
78 88
 }
79 89
 
80
-static void highscore(uint8_t is_black) NONBANKED {
90
+static void highscore(uint8_t is_black) {
81 91
     HIDE_WIN;
82 92
 
83 93
     move_win(MINWNDPOSX, MINWNDPOSY);
@@ -118,7 +128,7 @@ static void highscore(uint8_t is_black) NONBANKED {
118 128
     }
119 129
 }
120 130
 
121
-static void about_screen(void) NONBANKED {
131
+static void about_screen(void) {
122 132
     HIDE_WIN;
123 133
 
124 134
     move_win(MINWNDPOSX, MINWNDPOSY);
@@ -144,7 +154,7 @@ static void about_screen(void) NONBANKED {
144 154
     }
145 155
 }
146 156
 
147
-static void conf_screen(void) NONBANKED {
157
+static void conf_screen(void) {
148 158
     HIDE_WIN;
149 159
 
150 160
     debug_menu_index = 0;
@@ -176,24 +186,20 @@ static void conf_screen(void) NONBANKED {
176 186
             }
177 187
             win_conf();
178 188
         } else if (key_pressed(J_LEFT)) {
179
-            START_ROM_BANK(BANK(main)) {
180
-                if (*conf_entries[debug_menu_index].var > 0) {
181
-                    (*conf_entries[debug_menu_index].var)--;
182
-                } else {
183
-                    *conf_entries[debug_menu_index].var = conf_entries[debug_menu_index].max;
184
-                }
185
-                conf_write_crc();
186
-            } END_ROM_BANK
189
+            if (*conf_entries[debug_menu_index].var > 0) {
190
+                (*conf_entries[debug_menu_index].var)--;
191
+            } else {
192
+                *conf_entries[debug_menu_index].var = conf_entries[debug_menu_index].max;
193
+            }
194
+            conf_write_crc();
187 195
             win_conf();
188 196
         } else if (key_pressed(J_RIGHT)) {
189
-            START_ROM_BANK(BANK(main)) {
190
-                if (*conf_entries[debug_menu_index].var < conf_entries[debug_menu_index].max) {
191
-                    (*conf_entries[debug_menu_index].var)++;
192
-                } else {
193
-                    *conf_entries[debug_menu_index].var = 0;
194
-                }
195
-                conf_write_crc();
196
-            } END_ROM_BANK
197
+            if (*conf_entries[debug_menu_index].var < conf_entries[debug_menu_index].max) {
198
+                (*conf_entries[debug_menu_index].var)++;
199
+            } else {
200
+                *conf_entries[debug_menu_index].var = 0;
201
+            }
202
+            conf_write_crc();
197 203
             win_conf();
198 204
         } else if (key_pressed(J_A) || key_pressed(J_B) || key_pressed(J_START)) {
199 205
             break;
@@ -205,7 +211,7 @@ static void conf_screen(void) NONBANKED {
205 211
     debug_menu_index = 0;
206 212
 }
207 213
 
208
-static void splash_win(void) NONBANKED {
214
+static void splash_win(void) {
209 215
     HIDE_WIN;
210 216
 
211 217
     if (conf_get()->debug_flags & DBG_MENU) {
@@ -309,7 +315,7 @@ static void splash_anim(uint8_t *hiwater) NONBANKED {
309 315
     }
310 316
 }
311 317
 
312
-static void splash(void) NONBANKED {
318
+void splash(void) BANKED {
313 319
     snd_music_off();
314 320
     snd_note_off();
315 321
 
@@ -368,20 +374,6 @@ static void splash(void) NONBANKED {
368 374
             }
369 375
         } else {
370 376
             if (conf_get()->debug_flags & DBG_MENU) {
371
-                // do it here so you quickly see the flag going to 1 and back to 0
372
-                if (conf_get()->debug_flags & DBG_CLEAR_SCORE) {
373
-                    score_reset();
374
-                    conf_get()->debug_flags &= ~DBG_CLEAR_SCORE;
375
-                    conf_write_crc();
376
-                    splash_win();
377
-                }
378
-                if (conf_get()->debug_flags & DBG_ZERO_SCORE) {
379
-                    score_zero();
380
-                    conf_get()->debug_flags &= ~DBG_ZERO_SCORE;
381
-                    conf_write_crc();
382
-                    splash_win();
383
-                }
384
-
385 377
                 uint8_t switch_special = 0;
386 378
 
387 379
                 if (key_pressed(J_UP)) {
@@ -405,49 +397,43 @@ static void splash(void) NONBANKED {
405 397
                     snd_note_off();
406 398
                     splash_win();
407 399
                 } else if (key_pressed(J_LEFT)) {
408
-                    START_ROM_BANK(BANK(main)) {
409
-                        if (debug_entries[debug_menu_index].flag != DBG_NONE) {
410
-                            conf_get()->debug_flags ^= debug_entries[debug_menu_index].flag;
411
-                            conf_write_crc();
400
+                    if (debug_entries[debug_menu_index].flag != DBG_NONE) {
401
+                        conf_get()->debug_flags ^= debug_entries[debug_menu_index].flag;
402
+                        conf_write_crc();
403
+                    } else {
404
+                        if (debug_special_value > 0) {
405
+                            debug_special_value--;
412 406
                         } else {
413
-                            if (debug_special_value > 0) {
414
-                                debug_special_value--;
415
-                            } else {
416
-                                debug_special_value = debug_entries[debug_menu_index].max;
417
-                            }
418
-                            switch_special = 1;
407
+                            debug_special_value = debug_entries[debug_menu_index].max;
419 408
                         }
420
-                    } END_ROM_BANK
409
+                        switch_special = 1;
410
+                    }
421 411
                     splash_win();
422 412
                 } else if (key_pressed(J_RIGHT)) {
423
-                    START_ROM_BANK(BANK(main)) {
424
-                        if (debug_entries[debug_menu_index].flag != DBG_NONE) {
425
-                            conf_get()->debug_flags ^= debug_entries[debug_menu_index].flag;
426
-                            conf_write_crc();
413
+                    if (debug_entries[debug_menu_index].flag != DBG_NONE) {
414
+                        conf_get()->debug_flags ^= debug_entries[debug_menu_index].flag;
415
+                        conf_write_crc();
416
+                    } else {
417
+                        if (debug_special_value < debug_entries[debug_menu_index].max) {
418
+                            debug_special_value++;
427 419
                         } else {
428
-                            if (debug_special_value < debug_entries[debug_menu_index].max) {
429
-                                debug_special_value++;
430
-                            } else {
431
-                                debug_special_value = 0;
432
-                            }
433
-                            switch_special = 1;
420
+                            debug_special_value = 0;
434 421
                         }
435
-                    } END_ROM_BANK
422
+                        switch_special = 1;
423
+                    }
436 424
                     splash_win();
437 425
                 } else if (key_pressed(J_A)) {
438
-                    START_ROM_BANK(BANK(main)) {
439
-                        if (debug_entries[debug_menu_index].flag != DBG_NONE) {
440
-                            conf_get()->debug_flags ^= debug_entries[debug_menu_index].flag;
441
-                            conf_write_crc();
426
+                    if (debug_entries[debug_menu_index].flag != DBG_NONE) {
427
+                        conf_get()->debug_flags ^= debug_entries[debug_menu_index].flag;
428
+                        conf_write_crc();
429
+                    } else {
430
+                        if (debug_special_value < debug_entries[debug_menu_index].max) {
431
+                            debug_special_value++;
442 432
                         } else {
443
-                            if (debug_special_value < debug_entries[debug_menu_index].max) {
444
-                                debug_special_value++;
445
-                            } else {
446
-                                debug_special_value = 0;
447
-                            }
448
-                            switch_special = 1;
433
+                            debug_special_value = 0;
449 434
                         }
450
-                    } END_ROM_BANK
435
+                        switch_special = 1;
436
+                    }
451 437
                     splash_win();
452 438
                 } else if (key_pressed(J_B)) {
453 439
                     conf_get()->debug_flags &= ~DBG_MENU;
@@ -457,16 +443,29 @@ static void splash(void) NONBANKED {
457 443
                     snd_music(SND_MENU);
458 444
                 }
459 445
 
460
-                if (switch_special && (debug_menu_index == 5)) {
446
+                if (switch_special && (debug_menu_index == DEBUG_MENU_MUSIC_INDEX)) {
461 447
                     snd_music_off();
462 448
                     if (debug_special_value > 0) {
463 449
                         snd_music(debug_special_value - 1);
464 450
                     }
465 451
                     snd_note_off();
466
-                } else if ((switch_special || (!sample_running())) && (debug_menu_index == 6)) {
452
+                } else if ((switch_special || (!sample_running()))
453
+                        && (debug_menu_index == DEBUG_MENU_SFX_INDEX)) {
467 454
                     if (debug_special_value > 0) {
468 455
                         sample_play(debug_special_value - 1);
469 456
                     }
457
+                } else if (switch_special && debug_special_value
458
+                        && (debug_menu_index == DEBUG_MENU_CLEAR_INDEX)) {
459
+                    debug_special_value = 0;
460
+                    score_reset();
461
+                    conf_write_crc();
462
+                    splash_win();
463
+                } else if (switch_special && debug_special_value
464
+                        && (debug_menu_index == DEBUG_MENU_ZERO_INDEX)) {
465
+                    debug_special_value = 0;
466
+                    score_zero();
467
+                    conf_write_crc();
468
+                    splash_win();
470 469
                 }
471 470
             }
472 471
         }
@@ -498,7 +497,7 @@ static void splash(void) NONBANKED {
498 497
     }
499 498
 }
500 499
 
501
-static uint16_t ask_name(int32_t score) NONBANKED {
500
+uint16_t ask_name(int32_t score) BANKED {
502 501
     snd_music_off();
503 502
     snd_note_off();
504 503
 

+ 1
- 1
src/main.h View File

@@ -45,7 +45,7 @@ extern const struct conf_entry conf_entries[CONF_ENTRY_COUNT];
45 45
 extern uint8_t debug_menu_index;
46 46
 extern uint8_t debug_special_value;
47 47
 
48
-#define DEBUG_ENTRY_COUNT 9
48
+#define DEBUG_ENTRY_COUNT 12
49 49
 extern const struct debug_entry debug_entries[DEBUG_ENTRY_COUNT];
50 50
 
51 51
 #endif // __MAIN_H__

+ 31
- 29
src/strings.c View File

@@ -24,34 +24,35 @@
24 24
 
25 25
 BANKREF(strings)
26 26
 
27
-static const char string_top[] = "top";
28
-static const char string_score[] = "score";
29
-static const char string_black[] = "black";
30
-static const char string_white[] = "white";
31
-static const char string_enter[] = "enter";
32
-static const char string_name[] = "name";
33
-static const char string_start_ok[] = "start ok";
34
-static const char string_conf_menu[] = "Conf Menu";
35
-static const char string_debug_menu[] = "Debug Menu";
36
-static const char string_duality[] = "Duality";
37
-static const char string_xythobuz[] = "xythobuz";
38
-static const char string_git[] = "Git Commit Hash:";
39
-static const char string_build_date[] = "Build Date:";
40
-static const char string_date[] = __DATE__;
41
-static const char string_time[] = __TIME__;
42
-static const char string_mp_tx[] = "MP Tx:";
43
-static const char string_wait[] = "Wait";
44
-static const char string_visit[] = "Visit:";
45
-static const char string_url[] = "https://xythobuz.de";
46
-static const char string_printout[] = "printout";
47
-static const char string_success[] = "success";
48
-static const char string_error[] = "error";
49
-static const char string_gb_printer[] = "GB Printer";
27
+static const char            string_top[] = "top";
28
+static const char          string_score[] = "score";
29
+static const char          string_black[] = "black";
30
+static const char          string_white[] = "white";
31
+static const char          string_enter[] = "enter";
32
+static const char           string_name[] = "name";
33
+static const char       string_start_ok[] = "start ok";
34
+static const char      string_conf_menu[] = "Conf Menu";
35
+static const char     string_debug_menu[] = "Debug Menu";
36
+static const char        string_duality[] = "Duality";
37
+static const char       string_xythobuz[] = "xythobuz";
38
+static const char            string_git[] = "Git Commit Hash:";
39
+static const char     string_build_date[] = "Build Date:";
40
+static const char           string_date[] = __DATE__;
41
+static const char           string_time[] = __TIME__;
42
+static const char          string_mp_tx[] = "MP Tx:";
43
+static const char           string_wait[] = "Wait";
44
+static const char          string_visit[] = "Visit:";
45
+static const char            string_url[] = "https://xythobuz.de";
46
+static const char       string_printout[] = "printout";
47
+static const char        string_success[] = "success";
48
+static const char          string_error[] = "error";
49
+static const char     string_gb_printer[] = "GB Printer";
50 50
 static const char string_score_printout[] = "Score Printout";
51
-static const char string_result[] = "Result:";
52
-static const char string_printf_error[] = "error: 0x%x";
53
-static const char string_printf_frames[] = "Frames: 0x%x";
54
-static const char string_printf_timer[] = " Timer: 0x%x";
51
+static const char         string_result[] = "Result:";
52
+static const char   string_printf_error[] = "error: 0x%x";
53
+static const char  string_printf_frames[] = "Frames: 0x%x";
54
+static const char   string_printf_timer[] = " Timer: 0x%x";
55
+static const char   string_printf_stack[] = " Stack: 0x%x";
55 56
 
56 57
 static const char * const strings[COUNT_STRINGS] = {
57 58
     string_top,            // STR_TOP
@@ -80,8 +81,9 @@ static const char * const strings[COUNT_STRINGS] = {
80 81
     string_score_printout, // STR_SCORE_PRINTOUT
81 82
     string_result,         // STR_RESULT
82 83
     string_printf_error,   // STR_PRINTF_ERROR
83
-    string_printf_frames,  // STR_PRINTF_FRAMES,
84
-    string_printf_timer,   // STR_PRINTF_TIMER,
84
+    string_printf_frames,  // STR_PRINTF_FRAMES
85
+    string_printf_timer,   // STR_PRINTF_TIMER
86
+    string_printf_stack,   // STR_PRINTF_STACK
85 87
 };
86 88
 
87 89
 #define MAX_STR_LEN 32

+ 1
- 0
src/strings.h View File

@@ -51,6 +51,7 @@ enum STRINGS {
51 51
     STR_PRINTF_ERROR,
52 52
     STR_PRINTF_FRAMES,
53 53
     STR_PRINTF_TIMER,
54
+    STR_PRINTF_STACK,
54 55
 
55 56
     COUNT_STRINGS
56 57
 };

+ 27
- 5
src/window.c View File

@@ -40,6 +40,13 @@
40 40
 BANKREF(window)
41 41
 
42 42
 static char str_buff[128];
43
+static uint16_t stack_pointer = 0;
44
+
45
+static void get_sp(void) {
46
+    __asm
47
+    ld (_stack_pointer), sp
48
+    __endasm;
49
+}
43 50
 
44 51
 static void fill_win(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t tile, uint8_t attr) {
45 52
     VBK_REG = VBK_ATTRIBUTES;
@@ -265,7 +272,8 @@ uint8_t win_game_draw(int32_t score, uint8_t initial) BANKED {
265 272
         is_black = 1;
266 273
     }
267 274
 
268
-    if ((_cpu == CGB_TYPE) && (conf_get()->debug_flags)) {
275
+    if ((_cpu == CGB_TYPE)
276
+            && (conf_get()->debug_flags & (DBG_SHOW_FRAMES | DBG_SHOW_TIMER | DBG_SHOW_STACK))) {
269 277
         static int32_t prev_score = 0;
270 278
         if (initial || (score != prev_score)) {
271 279
             prev_score = score;
@@ -275,12 +283,26 @@ uint8_t win_game_draw(int32_t score, uint8_t initial) BANKED {
275 283
         }
276 284
 
277 285
         uint8_t x_off = number(score, 0, 0, is_black) >> 3;
286
+        uint8_t y_off = 0;
287
+
288
+        if (conf_get()->debug_flags & DBG_SHOW_FRAMES) {
289
+            sprintf(str_buff, get_string(STR_PRINTF_FRAMES), (uint16_t)game_get_framecount());
290
+            str_ascii(str_buff, x_off, y_off, 1);
291
+            y_off++;
292
+        }
278 293
 
279
-        sprintf(str_buff, get_string(STR_PRINTF_FRAMES), (uint16_t)game_get_framecount());
280
-        str_ascii(str_buff, x_off, 0, 1);
294
+        if (conf_get()->debug_flags & DBG_SHOW_TIMER) {
295
+            sprintf(str_buff, get_string(STR_PRINTF_TIMER), (uint16_t)timer_get());
296
+            str_ascii(str_buff, x_off, y_off, 1);
297
+            y_off++;
298
+        }
281 299
 
282
-        sprintf(str_buff, get_string(STR_PRINTF_TIMER), (uint16_t)timer_get());
283
-        str_ascii(str_buff, x_off, 1, 1);
300
+        if (conf_get()->debug_flags & DBG_SHOW_STACK) {
301
+            get_sp();
302
+            sprintf(str_buff, get_string(STR_PRINTF_STACK), (uint16_t)stack_pointer);
303
+            str_ascii(str_buff, x_off, y_off, 1);
304
+            y_off++;
305
+        }
284 306
 
285 307
         return DEVICE_SCREEN_PX_WIDTH;
286 308
     } else {

Loading…
Cancel
Save