Browse Source

tweak text rendering and menu stuff

Thomas B 2 weeks ago
parent
commit
584e5c5cad
7 changed files with 38 additions and 36 deletions
  1. 2
    2
      src/gbprinter.c
  2. 4
    10
      src/obj.c
  3. 2
    0
      src/strings.c
  4. 3
    0
      src/strings.h
  5. 6
    0
      src/text.c
  6. 20
    23
      src/window.c
  7. 1
    1
      src/window.h

+ 2
- 2
src/gbprinter.c View File

26
 #include <string.h>
26
 #include <string.h>
27
 
27
 
28
 #include "input.h"
28
 #include "input.h"
29
-#include "window.h"
29
+#include "text.h"
30
 #include "gbprinter.h"
30
 #include "gbprinter.h"
31
 
31
 
32
 BANKREF(gbprinter)
32
 BANKREF(gbprinter)
170
     static char line_buff[11];
170
     static char line_buff[11];
171
     strncpy(line_buff, s, 10);
171
     strncpy(line_buff, s, 10);
172
     line_buff[10] = '\0';
172
     line_buff[10] = '\0';
173
-    win_str_center(line_buff, y_pos, 0);
173
+    str_center(line_buff, y_pos, 0);
174
 }
174
 }
175
 
175
 
176
 enum PRN_STATUS gbprinter_screenshot(uint8_t win, uint8_t palette) BANKED {
176
 enum PRN_STATUS gbprinter_screenshot(uint8_t win, uint8_t palette) BANKED {

+ 4
- 10
src/obj.c View File

160
     }
160
     }
161
 }
161
 }
162
 
162
 
163
-static void obj_respawn(int8_t center_dist) {
164
-    for (uint8_t spr = SPR_LIGHT; spr <= SPR_SHOT_DARK; spr++) {
165
-        if (spr == SPR_SHOT) {
166
-            continue;
167
-        }
168
-        obj_respawn_type(spr, center_dist);
169
-    }
170
-}
171
-
172
 void obj_spawn(void) BANKED {
163
 void obj_spawn(void) BANKED {
173
-    obj_respawn(INITIAL_DISTANCE);
164
+    obj_respawn_type(SPR_LIGHT, INITIAL_DISTANCE);
165
+    obj_respawn_type(SPR_DARK, INITIAL_DISTANCE);
166
+    obj_respawn_type(SPR_SHOT_LIGHT, INITIAL_DISTANCE);
167
+    obj_respawn_type(SPR_SHOT_DARK, INITIAL_DISTANCE);
174
 }
168
 }
175
 
169
 
176
 enum OBJ_STATE obj_add(enum SPRITES sprite, int16_t off_x, int16_t off_y, int16_t spd_x, int16_t spd_y) BANKED {
170
 enum OBJ_STATE obj_add(enum SPRITES sprite, int16_t off_x, int16_t off_y, int16_t spd_x, int16_t spd_y) BANKED {

+ 2
- 0
src/strings.c View File

54
 static const char   string_printf_timer[] = " Timer: 0x%x";
54
 static const char   string_printf_timer[] = " Timer: 0x%x";
55
 static const char   string_printf_stack[] = " Stack: 0x%x";
55
 static const char   string_printf_stack[] = " Stack: 0x%x";
56
 static const char     string_printf_fps[] = "   FPS: %hd";
56
 static const char     string_printf_fps[] = "   FPS: %hd";
57
+static const char        string_spinner[] = "/-\\|";
57
 
58
 
58
 static const char * const strings[COUNT_STRINGS] = {
59
 static const char * const strings[COUNT_STRINGS] = {
59
     string_top,            // STR_TOP
60
     string_top,            // STR_TOP
86
     string_printf_timer,   // STR_PRINTF_TIMER
87
     string_printf_timer,   // STR_PRINTF_TIMER
87
     string_printf_stack,   // STR_PRINTF_STACK
88
     string_printf_stack,   // STR_PRINTF_STACK
88
     string_printf_fps,     // STR_PRINTF_FPS
89
     string_printf_fps,     // STR_PRINTF_FPS
90
+    string_spinner,        // STR_SPINNER
89
 };
91
 };
90
 
92
 
91
 #define MAX_STR_LEN 32
93
 #define MAX_STR_LEN 32

+ 3
- 0
src/strings.h View File

53
     STR_PRINTF_TIMER,
53
     STR_PRINTF_TIMER,
54
     STR_PRINTF_STACK,
54
     STR_PRINTF_STACK,
55
     STR_PRINTF_FPS,
55
     STR_PRINTF_FPS,
56
+    STR_SPINNER,
56
 
57
 
57
     COUNT_STRINGS
58
     COUNT_STRINGS
58
 };
59
 };
59
 
60
 
61
+#define SPINNER_LENGTH 4
62
+
60
 const char *get_string(enum STRINGS s) BANKED;
63
 const char *get_string(enum STRINGS s) BANKED;
61
 
64
 
62
 BANKREF_EXTERN(strings)
65
 BANKREF_EXTERN(strings)

+ 6
- 0
src/text.c View File

24
 #include "banks.h"
24
 #include "banks.h"
25
 #include "maps.h"
25
 #include "maps.h"
26
 #include "map_data.h"
26
 #include "map_data.h"
27
+#include "window.h"
27
 #include "text.h"
28
 #include "text.h"
28
 
29
 
29
 // TODO inverted score color not visible on DMG
30
 // TODO inverted score color not visible on DMG
114
             digit(c - '0', n, x_off, y_off, is_black);
115
             digit(c - '0', n, x_off, y_off, is_black);
115
         } else if ((c >= 'a') && (c <= 'z')) {
116
         } else if ((c >= 'a') && (c <= 'z')) {
116
             character(c - 'a', n, x_off, y_off, is_black);
117
             character(c - 'a', n, x_off, y_off, is_black);
118
+        } else {
119
+            // TODO inverted color on DMG?
120
+            fill_win(x_off + (n * maps[FNT_TEXT_16].width), y_off,
121
+                     maps[FNT_TEXT_16].width, maps[FNT_TEXT_16].width,
122
+                     0, 0);
117
         }
123
         }
118
     }
124
     }
119
 }
125
 }

+ 20
- 23
src/window.c View File

48
     __endasm;
48
     __endasm;
49
 }
49
 }
50
 
50
 
51
-static void fill_win(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t tile, uint8_t attr) {
52
-    VBK_REG = VBK_ATTRIBUTES;
53
-    fill_win_rect(x, y, w, h, attr);
51
+void fill_win(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t tile, uint8_t attr) BANKED {
52
+    if (_cpu == CGB_TYPE) {
53
+        VBK_REG = VBK_ATTRIBUTES;
54
+        fill_win_rect(x, y, w, h, attr);
55
+    }
56
+
54
     VBK_REG = VBK_TILES;
57
     VBK_REG = VBK_TILES;
55
     fill_win_rect(x, y, w, h, tile);
58
     fill_win_rect(x, y, w, h, tile);
56
 }
59
 }
72
     static uint8_t prev = 0;
75
     static uint8_t prev = 0;
73
     if ((_cpu == CGB_TYPE) && (mp_connection_status != prev)) {
76
     if ((_cpu == CGB_TYPE) && (mp_connection_status != prev)) {
74
         prev = mp_connection_status;
77
         prev = mp_connection_status;
75
-        char c = mp_connection_status & 0x1F;
76
-        str_ascii_l(&c, 1, 19, 0, 1);
78
+        char c = mp_connection_status % SPINNER_LENGTH;
79
+        str_ascii_l(&get_string(STR_SPINNER)[c], 1, 19, 0, 0);
77
     }
80
     }
78
 }
81
 }
79
 
82
 
126
     } END_ROM_BANK
129
     } END_ROM_BANK
127
 }
130
 }
128
 
131
 
129
-void win_str_center(const char *s, uint8_t y_off, uint8_t is_black) NONBANKED {
130
-    START_ROM_BANK(BANK(text)) {
131
-        str_center(s, y_off, is_black);
132
-    } END_ROM_BANK
133
-}
134
-
135
 void win_about(void) BANKED {
132
 void win_about(void) BANKED {
136
     map_fill(MAP_TITLE, 0);
133
     map_fill(MAP_TITLE, 0);
137
 
134
 
170
     static uint8_t prev = 0;
167
     static uint8_t prev = 0;
171
     if ((_cpu == CGB_TYPE) && (mp_connection_status != prev)) {
168
     if ((_cpu == CGB_TYPE) && (mp_connection_status != prev)) {
172
         prev = mp_connection_status;
169
         prev = mp_connection_status;
173
-        char c = mp_connection_status & 0x7F;
174
-        str_ascii_l(&c, 1, 19, 12, 1);
170
+        uint8_t c = mp_connection_status % SPINNER_LENGTH;
171
+        str_ascii_l(&get_string(STR_SPINNER)[c], 1, 19, 12, 1);
175
     }
172
     }
176
 }
173
 }
177
 
174
 
200
 void win_debug(void) BANKED {
197
 void win_debug(void) BANKED {
201
     map_fill(MAP_TITLE, 0);
198
     map_fill(MAP_TITLE, 0);
202
 
199
 
203
-    // TODO prettier pagination
204
-    uint8_t off = (10 - (DEBUG_ENTRY_COUNT - debug_menu_index)) / 2;
205
-
206
     str_center(get_string(STR_DEBUG_MENU), 0, 0);
200
     str_center(get_string(STR_DEBUG_MENU), 0, 0);
207
 
201
 
208
-    for (uint8_t i = debug_menu_index; (i < DEBUG_ENTRY_COUNT) && (i < (8 + debug_menu_index)); i++) {
202
+    for (uint8_t i = debug_menu_index; i < (8 + debug_menu_index); i++) {
209
         char name_buff[ENTRY_NAME_LEN + 2 + 1] = {0};
203
         char name_buff[ENTRY_NAME_LEN + 2 + 1] = {0};
210
-        uint8_t n_len = get_debug(name_buff, i);
211
-        str(name_buff, (TEXT_LINE_WIDTH - n_len) * 2, ((i - debug_menu_index) * 2) + 3 + off, (debug_menu_index == i) ? 1 : 0);
204
+        uint8_t n_len = get_debug(name_buff, i % DEBUG_ENTRY_COUNT);
205
+        str(name_buff, (TEXT_LINE_WIDTH - n_len) * 2, ((i - debug_menu_index) * 2) + 3, (debug_menu_index == i) ? 1 : 0);
212
     }
206
     }
213
 }
207
 }
214
 
208
 
288
 
282
 
289
     // TODO support one debug value on DMG
283
     // TODO support one debug value on DMG
290
     if ((_cpu == CGB_TYPE) && (conf_get()->debug_flags & DBG_OUT_ON)) {
284
     if ((_cpu == CGB_TYPE) && (conf_get()->debug_flags & DBG_OUT_ON)) {
285
+        uint8_t redraw = 0;
286
+
291
         static int32_t prev_score = 0;
287
         static int32_t prev_score = 0;
292
         if (initial || (score != prev_score)) {
288
         if (initial || (score != prev_score)) {
293
             prev_score = score;
289
             prev_score = score;
290
+            redraw = 1;
294
 
291
 
295
             // TODO hard-coded black bg tile
292
             // TODO hard-coded black bg tile
296
             fill_win(0, 0, 20, 2, 0x80, BKGF_CGB_PAL3);
293
             fill_win(0, 0, 20, 2, 0x80, BKGF_CGB_PAL3);
302
         if ((conf_get()->debug_flags & DBG_SHOW_FPS) && (y_off < 2)) {
299
         if ((conf_get()->debug_flags & DBG_SHOW_FPS) && (y_off < 2)) {
303
             static uint8_t prev_fps = 0;
300
             static uint8_t prev_fps = 0;
304
             uint8_t fps = game_get_fps();
301
             uint8_t fps = game_get_fps();
305
-            if (fps != prev_fps) {
302
+            if ((fps != prev_fps) || redraw) {
306
                 prev_fps = fps;
303
                 prev_fps = fps;
307
                 sprintf(str_buff, get_string(STR_PRINTF_FPS), (uint8_t)fps);
304
                 sprintf(str_buff, get_string(STR_PRINTF_FPS), (uint8_t)fps);
308
                 str_ascii(str_buff, x_off, y_off, 1);
305
                 str_ascii(str_buff, x_off, y_off, 1);
313
         if ((conf_get()->debug_flags & DBG_SHOW_FRAMES) && (y_off < 2)) {
310
         if ((conf_get()->debug_flags & DBG_SHOW_FRAMES) && (y_off < 2)) {
314
             static uint16_t prev_framecount = 0;
311
             static uint16_t prev_framecount = 0;
315
             uint16_t framecount = game_get_framecount();
312
             uint16_t framecount = game_get_framecount();
316
-            if (framecount != prev_framecount) {
313
+            if ((framecount != prev_framecount) || redraw) {
317
                 prev_framecount = framecount;
314
                 prev_framecount = framecount;
318
                 sprintf(str_buff, get_string(STR_PRINTF_FRAMES), (uint16_t)framecount);
315
                 sprintf(str_buff, get_string(STR_PRINTF_FRAMES), (uint16_t)framecount);
319
                 str_ascii(str_buff, x_off, y_off, 1);
316
                 str_ascii(str_buff, x_off, y_off, 1);
324
         if ((conf_get()->debug_flags & DBG_SHOW_TIMER) && (y_off < 2)) {
321
         if ((conf_get()->debug_flags & DBG_SHOW_TIMER) && (y_off < 2)) {
325
             static uint16_t prev_timer = 0;
322
             static uint16_t prev_timer = 0;
326
             uint16_t timer = timer_get();
323
             uint16_t timer = timer_get();
327
-            if (timer != prev_timer) {
324
+            if ((timer != prev_timer) || redraw) {
328
                 sprintf(str_buff, get_string(STR_PRINTF_TIMER), (uint16_t)timer);
325
                 sprintf(str_buff, get_string(STR_PRINTF_TIMER), (uint16_t)timer);
329
                 str_ascii(str_buff, x_off, y_off, 1);
326
                 str_ascii(str_buff, x_off, y_off, 1);
330
             }
327
             }
334
         if ((conf_get()->debug_flags & DBG_SHOW_STACK) && (y_off < 2)) {
331
         if ((conf_get()->debug_flags & DBG_SHOW_STACK) && (y_off < 2)) {
335
             static uint16_t prev_stack_pointer = 0;
332
             static uint16_t prev_stack_pointer = 0;
336
             get_sp();
333
             get_sp();
337
-            if (stack_pointer != prev_stack_pointer) {
334
+            if ((stack_pointer != prev_stack_pointer) || redraw) {
338
                 prev_stack_pointer = stack_pointer;
335
                 prev_stack_pointer = stack_pointer;
339
                 sprintf(str_buff, get_string(STR_PRINTF_STACK), (uint16_t)stack_pointer);
336
                 sprintf(str_buff, get_string(STR_PRINTF_STACK), (uint16_t)stack_pointer);
340
                 str_ascii(str_buff, x_off, y_off, 1);
337
                 str_ascii(str_buff, x_off, y_off, 1);

+ 1
- 1
src/window.h View File

39
 void win_name_draw(uint16_t name, uint8_t is_black, uint8_t pos) BANKED;
39
 void win_name_draw(uint16_t name, uint8_t is_black, uint8_t pos) BANKED;
40
 uint8_t win_game_draw(int32_t score, uint8_t initial) BANKED;
40
 uint8_t win_game_draw(int32_t score, uint8_t initial) BANKED;
41
 
41
 
42
-void win_str_center(const char *s, uint8_t y_off, uint8_t is_black);
42
+void fill_win(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t tile, uint8_t attr) BANKED;
43
 
43
 
44
 BANKREF_EXTERN(window)
44
 BANKREF_EXTERN(window)
45
 
45
 

Loading…
Cancel
Save