Browse Source

show frame and timer values in debug mode

Thomas B 3 weeks ago
parent
commit
e358258d81
7 changed files with 46 additions and 13 deletions
  1. 8
    1
      src/game.c
  2. 1
    0
      src/game.h
  3. 4
    0
      src/strings.c
  4. 2
    0
      src/strings.h
  5. 1
    1
      src/timer.c
  6. 1
    1
      src/timer.h
  7. 29
    10
      src/window.c

+ 8
- 1
src/game.c View File

@@ -72,6 +72,7 @@ static enum ACCELERATION acc = 0;
72 72
 static uint16_t health = HEALTH_MAX;
73 73
 static uint16_t power = POWER_MAX;
74 74
 static int32_t score = 0;
75
+static uint16_t frame_count = 0;
75 76
 
76 77
 static uint8_t pause_screen(void) NONBANKED {
77 78
     snd_music_off();
@@ -251,6 +252,7 @@ int32_t game(enum GAME_MODE mode) NONBANKED {
251 252
     health = HEALTH_MAX;
252 253
     power = POWER_MAX;
253 254
     score = 0;
255
+    frame_count = 0;
254 256
 
255 257
     obj_init();
256 258
 
@@ -494,13 +496,18 @@ int32_t game(enum GAME_MODE mode) NONBANKED {
494 496
 
495 497
         hide_sprites_range(hiwater, MAX_HARDWARE_SPRITES);
496 498
 
497
-        if (score != prev_score) {
499
+        if ((score != prev_score) || ((_cpu == CGB_TYPE) && (conf_get()->debug_flags))) {
498 500
             uint8_t x_off = win_game_draw(score);
499 501
             move_win(MINWNDPOSX + DEVICE_SCREEN_PX_WIDTH - x_off, MINWNDPOSY + DEVICE_SCREEN_PX_HEIGHT - 16);
500 502
         }
501 503
 
502 504
         vsync();
505
+        frame_count++;
503 506
     }
504 507
 
505 508
     return score;
506 509
 }
510
+
511
+uint16_t game_get_framecount(void) NONBANKED {
512
+    return frame_count;
513
+}

+ 1
- 0
src/game.h View File

@@ -43,6 +43,7 @@ void game_set_mp_player2(struct mp_player_state *state);
43 43
 void game_set_mp_shot(struct mp_shot_state *state);
44 44
 
45 45
 int32_t game(enum GAME_MODE mode);
46
+uint16_t game_get_framecount(void);
46 47
 
47 48
 BANKREF_EXTERN(game)
48 49
 

+ 4
- 0
src/strings.c View File

@@ -50,6 +50,8 @@ static const char string_gb_printer[] = "GB Printer";
50 50
 static const char string_score_printout[] = "Score Printout";
51 51
 static const char string_result[] = "Result:";
52 52
 static const char string_printf_error[] = "error: 0x%04x";
53
+static const char string_printf_frames[] = "Frames: %u";
54
+static const char string_printf_timer[] = "Timer: %u";
53 55
 
54 56
 static const char * const strings[COUNT_STRINGS] = {
55 57
     string_top,            // STR_TOP
@@ -78,6 +80,8 @@ static const char * const strings[COUNT_STRINGS] = {
78 80
     string_score_printout, // STR_SCORE_PRINTOUT
79 81
     string_result,         // STR_RESULT
80 82
     string_printf_error,   // STR_PRINTF_ERROR
83
+    string_printf_frames,  // STR_PRINTF_FRAMES,
84
+    string_printf_timer,   // STR_PRINTF_TIMER,
81 85
 };
82 86
 
83 87
 #define MAX_STR_LEN 32

+ 2
- 0
src/strings.h View File

@@ -49,6 +49,8 @@ enum STRINGS {
49 49
     STR_SCORE_PRINTOUT,
50 50
     STR_RESULT,
51 51
     STR_PRINTF_ERROR,
52
+    STR_PRINTF_FRAMES,
53
+    STR_PRINTF_TIMER,
52 54
 
53 55
     COUNT_STRINGS
54 56
 };

+ 1
- 1
src/timer.c View File

@@ -44,7 +44,7 @@ void timer_init(void) BANKED {
44 44
     }
45 45
 }
46 46
 
47
-uint16_t timer_get(void) BANKED {
47
+uint16_t timer_get(void) NONBANKED {
48 48
     uint16_t r;
49 49
     CRITICAL {
50 50
         r = count;

+ 1
- 1
src/timer.h View File

@@ -24,6 +24,6 @@
24 24
 #include <stdint.h>
25 25
 
26 26
 void timer_init(void) BANKED;
27
-uint16_t timer_get(void) BANKED;
27
+uint16_t timer_get(void);
28 28
 
29 29
 #endif // __TIMER_H__

+ 29
- 10
src/window.c View File

@@ -23,6 +23,7 @@
23 23
 
24 24
 #include "banks.h"
25 25
 #include "config.h"
26
+#include "gb/hardware.h"
26 27
 #include "score.h"
27 28
 #include "text.h"
28 29
 #include "git.h"
@@ -32,10 +33,14 @@
32 33
 #include "gbprinter.h"
33 34
 #include "multiplayer.h"
34 35
 #include "strings.h"
36
+#include "timer.h"
37
+#include "game.h"
35 38
 #include "window.h"
36 39
 
37 40
 BANKREF(window)
38 41
 
42
+static char str_buff[128];
43
+
39 44
 static void fill_win(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t tile, uint8_t attr) {
40 45
     VBK_REG = VBK_ATTRIBUTES;
41 46
     fill_win_rect(x, y, w, h, attr);
@@ -67,7 +72,7 @@ void win_splash_mp(void) BANKED {
67 72
 
68 73
 void win_score_clear(uint8_t is_black, uint8_t no_bg) BANKED {
69 74
     if (no_bg) {
70
-        fill_win(0, 0, DEVICE_SCREEN_WIDTH, DEVICE_SCREEN_HEIGHT, 1, 0x00);
75
+        fill_win(0, 0, DEVICE_SCREEN_WIDTH, DEVICE_SCREEN_HEIGHT, 1, BKGF_CGB_PAL0);
71 76
     } else {
72 77
         map_fill(MAP_TITLE, 0);
73 78
     }
@@ -83,8 +88,6 @@ void win_score_draw(struct scores score, uint8_t off, uint8_t is_black) BANKED {
83 88
 }
84 89
 
85 90
 void win_score_print(enum PRN_STATUS status) BANKED {
86
-    static char buff[128];
87
-
88 91
     if (_cpu == CGB_TYPE) {
89 92
         str_ascii(get_string(STR_GB_PRINTER), 0, 0, 0);
90 93
         str_ascii(get_string(STR_SCORE_PRINTOUT), 0, 1, 0);
@@ -93,11 +96,11 @@ void win_score_print(enum PRN_STATUS status) BANKED {
93 96
         if (status == PRN_STATUS_OK) {
94 97
             str_ascii(get_string(STR_SUCCESS), 0, 8, 0);
95 98
         } else {
96
-            sprintf(buff, get_string(STR_PRINTF_ERROR), (uint16_t)status);
97
-            str_ascii(buff, 0, 5, 0);
99
+            sprintf(str_buff, get_string(STR_PRINTF_ERROR), (uint16_t)status);
100
+            str_ascii(str_buff, 0, 5, 0);
98 101
 
99
-            gbprinter_error(status, buff);
100
-            str_ascii_lines(buff, 6, 0);
102
+            gbprinter_error(status, str_buff);
103
+            str_ascii_lines(str_buff, 6, 0);
101 104
         }
102 105
     } else {
103 106
         str(get_string(STR_PRINTOUT), 0, 4, 0);
@@ -256,13 +259,29 @@ void win_name_draw(uint16_t name, uint8_t is_black, uint8_t pos) BANKED {
256 259
 }
257 260
 
258 261
 uint8_t win_game_draw(int32_t score) BANKED {
259
-    fill_win(0, 0, 10, 2, maps[FNT_ASCII_8].tile_offset, 0x81);
260
-
261 262
     uint8_t is_black = 0;
262 263
     if (score < 0) {
263 264
         score = -score;
264 265
         is_black = 1;
265 266
     }
266 267
 
267
-    return number(score, 0, 0, is_black);
268
+    if ((_cpu == CGB_TYPE) && (conf_get()->debug_flags)) {
269
+        // TODO hard-coded black bg tile
270
+        fill_win(0, 0, 20, 2, 0x80, BKGF_CGB_PAL3);
271
+
272
+        uint8_t x_off = number(score, 0, 0, is_black) >> 3;
273
+
274
+        sprintf(str_buff, get_string(STR_PRINTF_FRAMES), (uint16_t)game_get_framecount());
275
+        str_ascii(str_buff, x_off + 1, 0, 1);
276
+
277
+        sprintf(str_buff, get_string(STR_PRINTF_TIMER), (uint16_t)timer_get());
278
+        str_ascii(str_buff, x_off + 1, 1, 1);
279
+
280
+        return DEVICE_SCREEN_PX_WIDTH;
281
+    } else {
282
+        // TODO hard-coded black bg tile
283
+        fill_win(0, 0, 10, 2, 0x80, BKGF_CGB_PAL3);
284
+
285
+        return number(score, 0, 0, is_black);
286
+    }
268 287
 }

Loading…
Cancel
Save