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
 static uint16_t health = HEALTH_MAX;
72
 static uint16_t health = HEALTH_MAX;
73
 static uint16_t power = POWER_MAX;
73
 static uint16_t power = POWER_MAX;
74
 static int32_t score = 0;
74
 static int32_t score = 0;
75
+static uint16_t frame_count = 0;
75
 
76
 
76
 static uint8_t pause_screen(void) NONBANKED {
77
 static uint8_t pause_screen(void) NONBANKED {
77
     snd_music_off();
78
     snd_music_off();
251
     health = HEALTH_MAX;
252
     health = HEALTH_MAX;
252
     power = POWER_MAX;
253
     power = POWER_MAX;
253
     score = 0;
254
     score = 0;
255
+    frame_count = 0;
254
 
256
 
255
     obj_init();
257
     obj_init();
256
 
258
 
494
 
496
 
495
         hide_sprites_range(hiwater, MAX_HARDWARE_SPRITES);
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
             uint8_t x_off = win_game_draw(score);
500
             uint8_t x_off = win_game_draw(score);
499
             move_win(MINWNDPOSX + DEVICE_SCREEN_PX_WIDTH - x_off, MINWNDPOSY + DEVICE_SCREEN_PX_HEIGHT - 16);
501
             move_win(MINWNDPOSX + DEVICE_SCREEN_PX_WIDTH - x_off, MINWNDPOSY + DEVICE_SCREEN_PX_HEIGHT - 16);
500
         }
502
         }
501
 
503
 
502
         vsync();
504
         vsync();
505
+        frame_count++;
503
     }
506
     }
504
 
507
 
505
     return score;
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
 void game_set_mp_shot(struct mp_shot_state *state);
43
 void game_set_mp_shot(struct mp_shot_state *state);
44
 
44
 
45
 int32_t game(enum GAME_MODE mode);
45
 int32_t game(enum GAME_MODE mode);
46
+uint16_t game_get_framecount(void);
46
 
47
 
47
 BANKREF_EXTERN(game)
48
 BANKREF_EXTERN(game)
48
 
49
 

+ 4
- 0
src/strings.c View File

50
 static const char string_score_printout[] = "Score Printout";
50
 static const char string_score_printout[] = "Score Printout";
51
 static const char string_result[] = "Result:";
51
 static const char string_result[] = "Result:";
52
 static const char string_printf_error[] = "error: 0x%04x";
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
 static const char * const strings[COUNT_STRINGS] = {
56
 static const char * const strings[COUNT_STRINGS] = {
55
     string_top,            // STR_TOP
57
     string_top,            // STR_TOP
78
     string_score_printout, // STR_SCORE_PRINTOUT
80
     string_score_printout, // STR_SCORE_PRINTOUT
79
     string_result,         // STR_RESULT
81
     string_result,         // STR_RESULT
80
     string_printf_error,   // STR_PRINTF_ERROR
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
 #define MAX_STR_LEN 32
87
 #define MAX_STR_LEN 32

+ 2
- 0
src/strings.h View File

49
     STR_SCORE_PRINTOUT,
49
     STR_SCORE_PRINTOUT,
50
     STR_RESULT,
50
     STR_RESULT,
51
     STR_PRINTF_ERROR,
51
     STR_PRINTF_ERROR,
52
+    STR_PRINTF_FRAMES,
53
+    STR_PRINTF_TIMER,
52
 
54
 
53
     COUNT_STRINGS
55
     COUNT_STRINGS
54
 };
56
 };

+ 1
- 1
src/timer.c View File

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

+ 1
- 1
src/timer.h View File

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

+ 29
- 10
src/window.c View File

23
 
23
 
24
 #include "banks.h"
24
 #include "banks.h"
25
 #include "config.h"
25
 #include "config.h"
26
+#include "gb/hardware.h"
26
 #include "score.h"
27
 #include "score.h"
27
 #include "text.h"
28
 #include "text.h"
28
 #include "git.h"
29
 #include "git.h"
32
 #include "gbprinter.h"
33
 #include "gbprinter.h"
33
 #include "multiplayer.h"
34
 #include "multiplayer.h"
34
 #include "strings.h"
35
 #include "strings.h"
36
+#include "timer.h"
37
+#include "game.h"
35
 #include "window.h"
38
 #include "window.h"
36
 
39
 
37
 BANKREF(window)
40
 BANKREF(window)
38
 
41
 
42
+static char str_buff[128];
43
+
39
 static void fill_win(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t tile, uint8_t attr) {
44
 static void fill_win(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t tile, uint8_t attr) {
40
     VBK_REG = VBK_ATTRIBUTES;
45
     VBK_REG = VBK_ATTRIBUTES;
41
     fill_win_rect(x, y, w, h, attr);
46
     fill_win_rect(x, y, w, h, attr);
67
 
72
 
68
 void win_score_clear(uint8_t is_black, uint8_t no_bg) BANKED {
73
 void win_score_clear(uint8_t is_black, uint8_t no_bg) BANKED {
69
     if (no_bg) {
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
     } else {
76
     } else {
72
         map_fill(MAP_TITLE, 0);
77
         map_fill(MAP_TITLE, 0);
73
     }
78
     }
83
 }
88
 }
84
 
89
 
85
 void win_score_print(enum PRN_STATUS status) BANKED {
90
 void win_score_print(enum PRN_STATUS status) BANKED {
86
-    static char buff[128];
87
-
88
     if (_cpu == CGB_TYPE) {
91
     if (_cpu == CGB_TYPE) {
89
         str_ascii(get_string(STR_GB_PRINTER), 0, 0, 0);
92
         str_ascii(get_string(STR_GB_PRINTER), 0, 0, 0);
90
         str_ascii(get_string(STR_SCORE_PRINTOUT), 0, 1, 0);
93
         str_ascii(get_string(STR_SCORE_PRINTOUT), 0, 1, 0);
93
         if (status == PRN_STATUS_OK) {
96
         if (status == PRN_STATUS_OK) {
94
             str_ascii(get_string(STR_SUCCESS), 0, 8, 0);
97
             str_ascii(get_string(STR_SUCCESS), 0, 8, 0);
95
         } else {
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
     } else {
105
     } else {
103
         str(get_string(STR_PRINTOUT), 0, 4, 0);
106
         str(get_string(STR_PRINTOUT), 0, 4, 0);
256
 }
259
 }
257
 
260
 
258
 uint8_t win_game_draw(int32_t score) BANKED {
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
     uint8_t is_black = 0;
262
     uint8_t is_black = 0;
262
     if (score < 0) {
263
     if (score < 0) {
263
         score = -score;
264
         score = -score;
264
         is_black = 1;
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