Browse Source

add a simple 8x8 font (for gbc mode only)

Thomas B 1 month ago
parent
commit
35a463b224
6 changed files with 75 additions and 33 deletions
  1. 2
    1
      Makefile
  2. 2
    0
      README.md
  3. 0
    0
      data/numbers_fnt16.png
  4. 0
    0
      data/text_fnt16.png
  5. BIN
      data/vincent_fnt8.png
  6. 71
    32
      src/window.c

+ 2
- 1
Makefile View File

@@ -122,12 +122,13 @@ $(BUILD_DIR)/$(DATA_DIR)/%.c $(BUILD_DIR)/$(DATA_DIR)/%.h: $(DATA_DIR)/%.wav
122 122
 $(BUILD_DIR)/$(DATA_DIR)/%.c $(BUILD_DIR)/$(DATA_DIR)/%.h: $(DATA_DIR)/%.png
123 123
 	@mkdir -p $(@D)
124 124
 	$(eval SPRFLAG = $(shell echo "$<" | sed -n 's/.*_spr\([0-9]\+\).*/\-sw \1 \-sh \1/p'))
125
+	$(eval FNTFLAG = $(shell echo "$<" | sed -n 's/.*_fnt\([0-9]\+\).*/\-sw \1 \-sh \1/p'))
125 126
 	$(if $(findstring _map,$<),                                                             \
126 127
 		@echo "Converting map $<" &&                                                    \
127 128
 		$(PNGA) $< -o $@ -spr8x8 -map -noflip                                           \
128 129
 	,$(if $(findstring _fnt,$<),                                                            \
129 130
 		@echo "Converting font $<" &&                                                   \
130
-		$(PNGA) $< -o $@ -spr8x8 -sw 16 -sh 16 -map -noflip                             \
131
+		$(PNGA) $< -o $@ -spr8x8 $(FNTFLAG) -map -noflip                                \
131 132
 	,$(if $(findstring _spr,$<),                                                            \
132 133
 		@echo "Converting 8x8 sprite $<" &&                                             \
133 134
 		$(PNGA) $< -o $@ -spr8x8 $(SPRFLAG) -noflip                                     \

+ 2
- 0
README.md View File

@@ -90,6 +90,8 @@ The files `sgb_border.c` and `sgb_border.h` are copied directly from their `sgb_
90 90
 
91 91
 The `util/cvtsample.py` script is based on a [GBDK example](https://github.com/gbdk-2020/gbdk-2020/blob/develop/gbdk-lib/examples/gb/wav_sample/utils/cvtsample.py).
92 92
 
93
+The [8x8 font](https://github.com/DavidDiPaola/font_vincent) is public domain.
94
+
93 95
 The included cartridge label graphic in `artwork/cart_label.xcf` is based on the ['Cartridge-Label-Templates' by Dinierto](https://github.com/Dinierto/Cartridge-Label-Templates) licensed as CC0.
94 96
 
95 97
 The included cartridge graphic in `artwork/cartridge.xcf` is based on the ['Front-End-Assets' by Duimon](https://github.com/Duimon/Front-End-Assets).

data/numbers_fnt.png → data/numbers_fnt16.png View File


data/text_fnt.png → data/text_fnt16.png View File


BIN
data/vincent_fnt8.png View File


+ 71
- 32
src/window.c View File

@@ -26,8 +26,9 @@
26 26
 #include "score.h"
27 27
 #include "title_map.h"
28 28
 #include "bg_map.h"
29
-#include "numbers_fnt.h"
30
-#include "text_fnt.h"
29
+#include "numbers_fnt16.h"
30
+#include "text_fnt16.h"
31
+#include "vincent_fnt8.h"
31 32
 #include "git.h"
32 33
 #include "main.h"
33 34
 #include "window.h"
@@ -36,6 +37,7 @@
36 37
 #define LINE_WIDTH 10
37 38
 
38 39
 // TODO inverted score color not visible on DMG
40
+// TODO 8x8 font only available on GBC
39 41
 
40 42
 BANKREF(window)
41 43
 
@@ -49,19 +51,31 @@ static uint8_t fnt_off = 0;
49 51
 void win_init(uint8_t is_splash) NONBANKED {
50 52
     fnt_off = is_splash ? title_map_TILE_COUNT : bg_map_TILE_COUNT;
51 53
 
52
-    START_ROM_BANK(BANK(numbers_fnt)) {
53
-        set_bkg_palette(OAMF_CGB_PAL0 + bg_map_PALETTE_COUNT, numbers_fnt_PALETTE_COUNT, numbers_fnt_palettes);
54
-        set_win_data(fnt_off, numbers_fnt_TILE_COUNT, numbers_fnt_tiles);
54
+    START_ROM_BANK(BANK(numbers_fnt16)) {
55
+        set_bkg_palette(OAMF_CGB_PAL0 + bg_map_PALETTE_COUNT,
56
+                        numbers_fnt16_PALETTE_COUNT, numbers_fnt16_palettes);
57
+        set_win_data(fnt_off, numbers_fnt16_TILE_COUNT, numbers_fnt16_tiles);
55 58
     } END_ROM_BANK
56 59
 
57 60
     START_ROM_BANK_2(BANK(window)) {
58
-        set_bkg_palette(OAMF_CGB_PAL0 + bg_map_PALETTE_COUNT + numbers_fnt_PALETTE_COUNT, numbers_fnt_PALETTE_COUNT, num_pal_inv);
61
+        set_bkg_palette(OAMF_CGB_PAL0 + bg_map_PALETTE_COUNT + numbers_fnt16_PALETTE_COUNT,
62
+                        numbers_fnt16_PALETTE_COUNT, num_pal_inv);
59 63
     } END_ROM_BANK
60 64
 
61 65
     if (is_splash) {
62
-        START_ROM_BANK_2(BANK(text_fnt)) {
63
-            set_win_data(fnt_off + numbers_fnt_TILE_COUNT, text_fnt_TILE_COUNT, text_fnt_tiles);
66
+        START_ROM_BANK_2(BANK(text_fnt16)) {
67
+            set_win_data(fnt_off + numbers_fnt16_TILE_COUNT,
68
+                         text_fnt16_TILE_COUNT, text_fnt16_tiles);
64 69
         } END_ROM_BANK
70
+
71
+        if (_cpu == CGB_TYPE) {
72
+            VBK_REG = VBK_BANK_1;
73
+            START_ROM_BANK_2(BANK(vincent_fnt8)) {
74
+                set_win_data(0, vincent_fnt8_TILE_COUNT, vincent_fnt8_tiles);
75
+                set_bkg_palette(OAMF_CGB_PAL0 + bg_map_PALETTE_COUNT + (2 * numbers_fnt16_PALETTE_COUNT),
76
+                                vincent_fnt8_PALETTE_COUNT, vincent_fnt8_palettes);
77
+            } END_ROM_BANK
78
+        }
65 79
     }
66 80
 }
67 81
 
@@ -97,17 +111,23 @@ static void set_win_based_attr(uint8_t x, uint8_t y, uint8_t w, uint8_t h,
97 111
 }
98 112
 
99 113
 static void character(uint8_t c, uint8_t pos, uint8_t x_off, uint8_t y_off, uint8_t is_black) {
100
-    uint8_t off = c * text_fnt_WIDTH / text_fnt_TILE_W;
114
+    uint8_t off = c * text_fnt16_WIDTH / text_fnt16_TILE_W;
115
+
116
+    set_win_based_attr(x_off + (pos * text_fnt16_WIDTH / text_fnt16_TILE_W), y_off,
117
+                       text_fnt16_WIDTH / text_fnt16_TILE_W, 1,
118
+                       text_fnt16_map + off, fnt_off + numbers_fnt16_TILE_COUNT,
119
+                       BANK(text_fnt16), is_black ? 0x82 : 0x81);
101 120
 
102
-    set_win_based_attr(x_off + (pos * text_fnt_WIDTH / text_fnt_TILE_W), y_off,
103
-                       text_fnt_WIDTH / text_fnt_TILE_W, 1,
104
-                       text_fnt_map + off, fnt_off + numbers_fnt_TILE_COUNT,
105
-                       BANK(text_fnt), is_black ? 0x82 : 0x81);
121
+    set_win_based_attr(x_off + (pos * text_fnt16_WIDTH / text_fnt16_TILE_W), y_off + 1,
122
+                       text_fnt16_WIDTH / text_fnt16_TILE_W, 1,
123
+                       text_fnt16_map + off + (sizeof(text_fnt16_map) / 2), fnt_off + numbers_fnt16_TILE_COUNT,
124
+                       BANK(text_fnt16), is_black ? 0x82 : 0x81);
125
+}
106 126
 
107
-    set_win_based_attr(x_off + (pos * text_fnt_WIDTH / text_fnt_TILE_W), y_off + 1,
108
-                       text_fnt_WIDTH / text_fnt_TILE_W, 1,
109
-                       text_fnt_map + off + (sizeof(text_fnt_map) / 2), fnt_off + numbers_fnt_TILE_COUNT,
110
-                       BANK(text_fnt), is_black ? 0x82 : 0x81);
127
+static void char_ascii(uint8_t c, uint8_t pos, uint8_t x_off, uint8_t y_off) {
128
+    set_win_based_attr(x_off + pos, y_off, 1, 1,
129
+                       vincent_fnt8_map + c, 0,
130
+                       BANK(vincent_fnt8), 0x8B);
111 131
 }
112 132
 
113 133
 static void str3(uint16_t name, uint8_t x_off, uint8_t y_off,
@@ -118,17 +138,17 @@ static void str3(uint16_t name, uint8_t x_off, uint8_t y_off,
118 138
 }
119 139
 
120 140
 static void digit(uint8_t val, uint8_t pos, uint8_t x_off, uint8_t y_off, uint8_t is_black) {
121
-    uint8_t off = val * numbers_fnt_WIDTH / numbers_fnt_TILE_W;
141
+    uint8_t off = val * numbers_fnt16_WIDTH / numbers_fnt16_TILE_W;
122 142
 
123
-    set_win_based_attr(x_off + (pos * numbers_fnt_WIDTH / numbers_fnt_TILE_W), y_off,
124
-                       numbers_fnt_WIDTH / numbers_fnt_TILE_W, 1,
125
-                       numbers_fnt_map + off, fnt_off,
126
-                       BANK(numbers_fnt), is_black ? 0x82 : 0x81);
143
+    set_win_based_attr(x_off + (pos * numbers_fnt16_WIDTH / numbers_fnt16_TILE_W), y_off,
144
+                       numbers_fnt16_WIDTH / numbers_fnt16_TILE_W, 1,
145
+                       numbers_fnt16_map + off, fnt_off,
146
+                       BANK(numbers_fnt16), is_black ? 0x82 : 0x81);
127 147
 
128
-    set_win_based_attr(x_off + (pos * numbers_fnt_WIDTH / numbers_fnt_TILE_W), y_off + 1,
129
-                       numbers_fnt_WIDTH / numbers_fnt_TILE_W, 1,
130
-                       numbers_fnt_map + off + (sizeof(numbers_fnt_map) / 2), fnt_off,
131
-                       BANK(numbers_fnt), is_black ? 0x82 : 0x81);
148
+    set_win_based_attr(x_off + (pos * numbers_fnt16_WIDTH / numbers_fnt16_TILE_W), y_off + 1,
149
+                       numbers_fnt16_WIDTH / numbers_fnt16_TILE_W, 1,
150
+                       numbers_fnt16_map + off + (sizeof(numbers_fnt16_map) / 2), fnt_off,
151
+                       BANK(numbers_fnt16), is_black ? 0x82 : 0x81);
132 152
 }
133 153
 
134 154
 static void str_l(const char *s, uint8_t len, uint8_t x_off, uint8_t y_off, uint8_t is_black) {
@@ -149,6 +169,13 @@ static void str(const char *s, uint8_t x_off, uint8_t y_off, uint8_t is_black) {
149 169
     str_l(s, 0xFF, x_off, y_off, is_black);
150 170
 }
151 171
 
172
+static void str_ascii(const char *s, uint8_t x_off, uint8_t y_off) {
173
+    for (uint8_t n = 0; (*s) && (n < (2 * LINE_WIDTH)); n++) {
174
+        char c = *(s++);
175
+        char_ascii(c, n, x_off, y_off);
176
+    }
177
+}
178
+
152 179
 static void str_center(const char *s, uint8_t y_off, uint8_t is_black) {
153 180
     uint8_t n = strlen(s);
154 181
     if (n > LINE_WIDTH) n = LINE_WIDTH;
@@ -243,13 +270,25 @@ void win_about(void) BANKED {
243 270
     char line_buff[2 * LINE_WIDTH + 1] = {0};
244 271
     get_git(line_buff);
245 272
 
246
-    str_lines(line_buff, 7, 0);
273
+    if (_cpu == CGB_TYPE) {
274
+        str_ascii("Git Commit Hash:", 0, 6);
275
+        str_ascii(line_buff, 0, 7);
276
+
277
+        str_ascii("Build Date:", 0, 10);
278
+        str_ascii(__DATE__, 0, 11);
279
+        str_ascii(__TIME__, 0, 12);
247 280
 
248
-    str_l(&__DATE__[7], 4,           0, 14, 1); // year (4)
249
-    str_l(&__DATE__[0], 3, (4 * 2) + 1, 14, 1); // month (3)
250
-    str_l(&__DATE__[4], 2, (7 * 2) + 2, 14, 1); // day (2)
281
+        str_ascii("Visit:", 0, 15);
282
+        str_ascii("https://xythobuz.de", 0, 16);
283
+    } else {
284
+        str_lines(line_buff, 7, 0);
285
+
286
+        str_l(&__DATE__[7], 4,           0, 14, 1); // year (4)
287
+        str_l(&__DATE__[0], 3, (4 * 2) + 1, 14, 1); // month (3)
288
+        str_l(&__DATE__[4], 2, (7 * 2) + 2, 14, 1); // day (2)
251 289
 
252
-    str(__TIME__, 4, 16, 0);
290
+        str(__TIME__, 4, 16, 0);
291
+    }
253 292
 }
254 293
 
255 294
 static uint8_t get_debug(char *name_buff, uint8_t i) NONBANKED {
@@ -349,7 +388,7 @@ void win_name_draw(uint16_t name, uint8_t is_black, uint8_t pos) BANKED {
349 388
 }
350 389
 
351 390
 uint8_t win_game_draw(int32_t score) BANKED {
352
-    fill_win(0, 0, 10, 2, fnt_off + numbers_fnt_TILE_COUNT, 0x81);
391
+    fill_win(0, 0, 10, 2, fnt_off + numbers_fnt16_TILE_COUNT, 0x81);
353 392
 
354 393
     uint8_t is_black = 0;
355 394
     if (score < 0) {

Loading…
Cancel
Save