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,7 +26,7 @@
26 26
 #include <string.h>
27 27
 
28 28
 #include "input.h"
29
-#include "window.h"
29
+#include "text.h"
30 30
 #include "gbprinter.h"
31 31
 
32 32
 BANKREF(gbprinter)
@@ -170,7 +170,7 @@ static void win_str_helper(const char *s, uint8_t y_pos) {
170 170
     static char line_buff[11];
171 171
     strncpy(line_buff, s, 10);
172 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 176
 enum PRN_STATUS gbprinter_screenshot(uint8_t win, uint8_t palette) BANKED {

+ 4
- 10
src/obj.c View File

@@ -160,17 +160,11 @@ static void obj_respawn_type(enum SPRITES spr, int8_t center_dist) {
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 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 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,6 +54,7 @@ static const char  string_printf_frames[] = "Frames: 0x%x";
54 54
 static const char   string_printf_timer[] = " Timer: 0x%x";
55 55
 static const char   string_printf_stack[] = " Stack: 0x%x";
56 56
 static const char     string_printf_fps[] = "   FPS: %hd";
57
+static const char        string_spinner[] = "/-\\|";
57 58
 
58 59
 static const char * const strings[COUNT_STRINGS] = {
59 60
     string_top,            // STR_TOP
@@ -86,6 +87,7 @@ static const char * const strings[COUNT_STRINGS] = {
86 87
     string_printf_timer,   // STR_PRINTF_TIMER
87 88
     string_printf_stack,   // STR_PRINTF_STACK
88 89
     string_printf_fps,     // STR_PRINTF_FPS
90
+    string_spinner,        // STR_SPINNER
89 91
 };
90 92
 
91 93
 #define MAX_STR_LEN 32

+ 3
- 0
src/strings.h View File

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

+ 6
- 0
src/text.c View File

@@ -24,6 +24,7 @@
24 24
 #include "banks.h"
25 25
 #include "maps.h"
26 26
 #include "map_data.h"
27
+#include "window.h"
27 28
 #include "text.h"
28 29
 
29 30
 // TODO inverted score color not visible on DMG
@@ -114,6 +115,11 @@ void str_l(const char *s, uint8_t len, uint8_t x_off, uint8_t y_off, uint8_t is_
114 115
             digit(c - '0', n, x_off, y_off, is_black);
115 116
         } else if ((c >= 'a') && (c <= 'z')) {
116 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,9 +48,12 @@ static void get_sp(void) {
48 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 57
     VBK_REG = VBK_TILES;
55 58
     fill_win_rect(x, y, w, h, tile);
56 59
 }
@@ -72,8 +75,8 @@ void win_splash_mp(void) BANKED {
72 75
     static uint8_t prev = 0;
73 76
     if ((_cpu == CGB_TYPE) && (mp_connection_status != prev)) {
74 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,12 +129,6 @@ static void get_git(char *line_buff) NONBANKED {
126 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 132
 void win_about(void) BANKED {
136 133
     map_fill(MAP_TITLE, 0);
137 134
 
@@ -170,8 +167,8 @@ void win_about_mp(void) BANKED {
170 167
     static uint8_t prev = 0;
171 168
     if ((_cpu == CGB_TYPE) && (mp_connection_status != prev)) {
172 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,15 +197,12 @@ static uint8_t get_debug(char *name_buff, uint8_t i) NONBANKED {
200 197
 void win_debug(void) BANKED {
201 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 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 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,9 +282,12 @@ uint8_t win_game_draw(int32_t score, uint8_t initial) BANKED {
288 282
 
289 283
     // TODO support one debug value on DMG
290 284
     if ((_cpu == CGB_TYPE) && (conf_get()->debug_flags & DBG_OUT_ON)) {
285
+        uint8_t redraw = 0;
286
+
291 287
         static int32_t prev_score = 0;
292 288
         if (initial || (score != prev_score)) {
293 289
             prev_score = score;
290
+            redraw = 1;
294 291
 
295 292
             // TODO hard-coded black bg tile
296 293
             fill_win(0, 0, 20, 2, 0x80, BKGF_CGB_PAL3);
@@ -302,7 +299,7 @@ uint8_t win_game_draw(int32_t score, uint8_t initial) BANKED {
302 299
         if ((conf_get()->debug_flags & DBG_SHOW_FPS) && (y_off < 2)) {
303 300
             static uint8_t prev_fps = 0;
304 301
             uint8_t fps = game_get_fps();
305
-            if (fps != prev_fps) {
302
+            if ((fps != prev_fps) || redraw) {
306 303
                 prev_fps = fps;
307 304
                 sprintf(str_buff, get_string(STR_PRINTF_FPS), (uint8_t)fps);
308 305
                 str_ascii(str_buff, x_off, y_off, 1);
@@ -313,7 +310,7 @@ uint8_t win_game_draw(int32_t score, uint8_t initial) BANKED {
313 310
         if ((conf_get()->debug_flags & DBG_SHOW_FRAMES) && (y_off < 2)) {
314 311
             static uint16_t prev_framecount = 0;
315 312
             uint16_t framecount = game_get_framecount();
316
-            if (framecount != prev_framecount) {
313
+            if ((framecount != prev_framecount) || redraw) {
317 314
                 prev_framecount = framecount;
318 315
                 sprintf(str_buff, get_string(STR_PRINTF_FRAMES), (uint16_t)framecount);
319 316
                 str_ascii(str_buff, x_off, y_off, 1);
@@ -324,7 +321,7 @@ uint8_t win_game_draw(int32_t score, uint8_t initial) BANKED {
324 321
         if ((conf_get()->debug_flags & DBG_SHOW_TIMER) && (y_off < 2)) {
325 322
             static uint16_t prev_timer = 0;
326 323
             uint16_t timer = timer_get();
327
-            if (timer != prev_timer) {
324
+            if ((timer != prev_timer) || redraw) {
328 325
                 sprintf(str_buff, get_string(STR_PRINTF_TIMER), (uint16_t)timer);
329 326
                 str_ascii(str_buff, x_off, y_off, 1);
330 327
             }
@@ -334,7 +331,7 @@ uint8_t win_game_draw(int32_t score, uint8_t initial) BANKED {
334 331
         if ((conf_get()->debug_flags & DBG_SHOW_STACK) && (y_off < 2)) {
335 332
             static uint16_t prev_stack_pointer = 0;
336 333
             get_sp();
337
-            if (stack_pointer != prev_stack_pointer) {
334
+            if ((stack_pointer != prev_stack_pointer) || redraw) {
338 335
                 prev_stack_pointer = stack_pointer;
339 336
                 sprintf(str_buff, get_string(STR_PRINTF_STACK), (uint16_t)stack_pointer);
340 337
                 str_ascii(str_buff, x_off, y_off, 1);

+ 1
- 1
src/window.h View File

@@ -39,7 +39,7 @@ void win_name(int32_t score) BANKED;
39 39
 void win_name_draw(uint16_t name, uint8_t is_black, uint8_t pos) BANKED;
40 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 44
 BANKREF_EXTERN(window)
45 45
 

Loading…
Cancel
Save