Browse Source

add about screen with version info

Thomas B 1 month ago
parent
commit
95b1df3919
7 changed files with 154 additions and 31 deletions
  1. 11
    4
      Makefile
  2. 24
    0
      data/git.c
  3. BIN
      data/text_fnt.png
  4. 29
    0
      src/git.h
  5. 24
    2
      src/main.c
  6. 65
    25
      src/maps.c
  7. 1
    0
      src/maps.h

+ 11
- 4
Makefile View File

@@ -26,6 +26,10 @@ BUILD_DIR := build
26 26
 DATA_DIR := data
27 27
 
28 28
 SRCS := $(wildcard $(SRC_DIR)/*.c)
29
+
30
+GIT := $(BUILD_DIR)/$(DATA_DIR)/git.c
31
+SRCS += $(GIT)
32
+
29 33
 OBJS := $(SRCS:%.c=$(BUILD_DIR)/%.o)
30 34
 
31 35
 ASSETS := $(wildcard $(DATA_DIR)/*.png)
@@ -40,7 +44,7 @@ SGB_EMU := sameboy
40 44
 FLASHER := flashgbx
41 45
 
42 46
 LCCFLAGS := -Wa-l -Wl-m -Wp-MMD -Wf--opt-code-speed
43
-LCCFLAGS += -I$(BUILD_DIR)/$(DATA_DIR)
47
+LCCFLAGS += -I$(SRC_DIR) -I$(BUILD_DIR)/$(DATA_DIR)
44 48
 LCCFLAGS += -Wm"-yn Duality" -Wm-yt0x1B -Wm-yoA -Wm-ya16 -Wm-yc -Wm-ys
45 49
 LCCFLAGS += -autobank -Wb-ext=.rel -Wb-v -Wf-bo255
46 50
 
@@ -62,7 +66,7 @@ $(info BUILD_TYPE is $(BUILD_TYPE))
62 66
 #DEPS=$(OBJS:%.o=%.d)
63 67
 #-include $(DEPS)
64 68
 
65
-.PHONY: all run sgb_run flash clean compile_commands.json usage
69
+.PHONY: all run sgb_run flash clean compile_commands.json usage $(GIT)
66 70
 .PRECIOUS: $(BUILD_DIR)/$(DATA_DIR)/%.c $(BUILD_DIR)/$(DATA_DIR)/%.h
67 71
 
68 72
 all: $(BIN)
@@ -76,6 +80,10 @@ compile_commands.json:
76 80
 	@bear --config bear.cfg -- make -j4
77 81
 	@rm -rf bear.cfg
78 82
 
83
+$(GIT): $(DATA_DIR)/git.c
84
+	@echo Generating $@ from $<
85
+	sed 's/GIT_VERSION/$(shell git describe --abbrev=7 --dirty --always --tags)/g' $< > $@
86
+
79 87
 usage: $(BUILD_DIR)/$(BIN)
80 88
 	@echo Analyzing $<
81 89
 	@$(ROMU) $(BUILD_DIR)/$(BIN:%.gb=%.map)
@@ -137,9 +145,8 @@ $(BUILD_DIR)/$(BIN): $(OBJS)
137 145
 	@echo Linking $@
138 146
 	@$(LCC) $(LCCFLAGS) -o $@ $(OBJS)
139 147
 
140
-$(BIN): $(BUILD_DIR)/$(BIN)
148
+$(BIN): $(BUILD_DIR)/$(BIN) usage
141 149
 	@cp $< $@
142
-	@make usage
143 150
 
144 151
 clean:
145 152
 	rm -rf $(BUILD_DIR) $(BIN)

+ 24
- 0
data/git.c View File

@@ -0,0 +1,24 @@
1
+/*
2
+ * git.c
3
+ * Duality
4
+ *
5
+ * Copyright (C) 2025 Thomas Buck <thomas@xythobuz.de>
6
+ *
7
+ * This program is free software: you can redistribute it and/or modify
8
+ * it under the terms of the GNU General Public License as published by
9
+ * the Free Software Foundation, either version 3 of the License, or
10
+ * (at your option) any later version.
11
+ *
12
+ * This program is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
+ * GNU General Public License for more details.
16
+ *
17
+ * See <http://www.gnu.org/licenses/>.
18
+ */
19
+
20
+#include "git.h"
21
+
22
+BANKREF(git)
23
+
24
+const char git_version[] = "GIT_VERSION";

BIN
data/text_fnt.png View File


+ 29
- 0
src/git.h View File

@@ -0,0 +1,29 @@
1
+/*
2
+ * git.h
3
+ * Duality
4
+ *
5
+ * Copyright (C) 2025 Thomas Buck <thomas@xythobuz.de>
6
+ *
7
+ * This program is free software: you can redistribute it and/or modify
8
+ * it under the terms of the GNU General Public License as published by
9
+ * the Free Software Foundation, either version 3 of the License, or
10
+ * (at your option) any later version.
11
+ *
12
+ * This program is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
+ * GNU General Public License for more details.
16
+ *
17
+ * See <http://www.gnu.org/licenses/>.
18
+ */
19
+
20
+#ifndef __GIT_H__
21
+#define __GIT_H__
22
+
23
+#include <gbdk/platform.h>
24
+
25
+BANKREF_EXTERN(git)
26
+
27
+extern const char git_version[];
28
+
29
+#endif // __GIT_H__

+ 24
- 2
src/main.c View File

@@ -40,14 +40,13 @@
40 40
 static void highscore(uint8_t is_black) NONBANKED {
41 41
     HIDE_WIN;
42 42
 
43
+    move_win(MINWNDPOSX, MINWNDPOSY);
43 44
     hide_sprites_range(SPR_NUM_START, MAX_HARDWARE_SPRITES);
44 45
     win_score_clear(is_black ? 1 : 0);
45 46
 
46
-    move_win(MINWNDPOSX, MINWNDPOSY);
47 47
     SHOW_WIN;
48 48
 
49 49
     for (uint8_t i = 0; i < SCORE_NUM; i++) {
50
-
51 50
         struct scores score = is_black ? score_lowest(i) : score_highest(i);
52 51
         win_score_draw(score, i, is_black);
53 52
     }
@@ -63,6 +62,26 @@ static void highscore(uint8_t is_black) NONBANKED {
63 62
     }
64 63
 }
65 64
 
65
+static void about_screen(void) NONBANKED {
66
+    HIDE_WIN;
67
+
68
+    move_win(MINWNDPOSX, MINWNDPOSY);
69
+    hide_sprites_range(SPR_NUM_START, MAX_HARDWARE_SPRITES);
70
+    win_about();
71
+
72
+    SHOW_WIN;
73
+
74
+    while (1) {
75
+        key_read();
76
+
77
+        if (key_pressed(J_A) || key_pressed(J_B) || key_pressed(J_SELECT)) {
78
+            break;
79
+        }
80
+
81
+        vsync();
82
+    }
83
+}
84
+
66 85
 static void splash_win(void) NONBANKED {
67 86
     HIDE_WIN;
68 87
 
@@ -108,6 +127,9 @@ static void splash(void) NONBANKED {
108 127
         } else if (key_pressed(J_RIGHT)) {
109 128
             highscore(0);
110 129
             splash_win();
130
+        } else if (key_pressed(J_SELECT)) {
131
+            about_screen();
132
+            splash_win();
111 133
         } else if (key_pressed(0xFF)) {
112 134
             break;
113 135
         }

+ 65
- 25
src/maps.c View File

@@ -18,17 +18,18 @@
18 18
  */
19 19
 
20 20
 #include <gbdk/platform.h>
21
-
22
-#include "maps.h"
23
-
21
+#include <string.h>
24 22
 #include "gb/gb.h"
25 23
 #include "score.h"
26 24
 #include "title_map.h"
27 25
 #include "bg_map.h"
28 26
 #include "numbers_fnt.h"
29 27
 #include "text_fnt.h"
28
+#include "git.h"
29
+#include "maps.h"
30 30
 
31 31
 #define MAX_DIGITS 7
32
+#define LINE_WIDTH 10
32 33
 
33 34
 // TODO inverted score color not visible on DMG
34 35
 
@@ -122,21 +123,6 @@ static void str3(uint16_t name, uint8_t x_off, uint8_t y_off,
122 123
     character((name >>  0) & 0x1F, 2, x_off, y_off, is_black_c);
123 124
 }
124 125
 
125
-static void str(const char *s, uint8_t x_off, uint8_t y_off, uint8_t is_black) NONBANKED {
126
-    uint8_t n = 0;
127
-    while (*s) {
128
-        char c = *(s++);
129
-        if ((c >= 'A') && (c <= 'Z')) {
130
-            c = c - 'A' + 'a';
131
-        }
132
-        if ((c < 'a') || (c > 'z')) {
133
-            n++;
134
-            continue;
135
-        }
136
-        character(c - 'a', n++, x_off, y_off, is_black);
137
-    }
138
-}
139
-
140 126
 static void digit(uint8_t val, uint8_t pos, uint8_t x_off, uint8_t y_off, uint8_t is_black) NONBANKED {
141 127
     uint8_t off = val * numbers_fnt_WIDTH / numbers_fnt_TILE_W;
142 128
 
@@ -151,6 +137,39 @@ static void digit(uint8_t val, uint8_t pos, uint8_t x_off, uint8_t y_off, uint8_
151 137
                   (is_black ? num_attr_2 : num_attr_1) + off, BANK(maps));
152 138
 }
153 139
 
140
+static void str_l(const char *s, uint8_t len, uint8_t x_off, uint8_t y_off, uint8_t is_black) NONBANKED {
141
+    for (uint8_t n = 0; (*s) && (n < LINE_WIDTH) && (n < len); n++) {
142
+        char c = *(s++);
143
+        if ((c >= 'A') && (c <= 'Z')) {
144
+            c = c - 'A' + 'a';
145
+        }
146
+        if ((c >= '0') && (c <= '9')) {
147
+            digit(c - '0', n, x_off, y_off, is_black);
148
+        } else if ((c >= 'a') && (c <= 'z')) {
149
+            character(c - 'a', n, x_off, y_off, is_black);
150
+        }
151
+    }
152
+}
153
+
154
+static void str(const char *s, uint8_t x_off, uint8_t y_off, uint8_t is_black) NONBANKED {
155
+    str_l(s, 0xFF, x_off, y_off, is_black);
156
+}
157
+
158
+static void str_center(const char *s, uint8_t y_off, uint8_t is_black) NONBANKED {
159
+    uint8_t n = strlen(s);
160
+    if (n > LINE_WIDTH) n = LINE_WIDTH;
161
+    str(s, LINE_WIDTH - n, y_off, is_black);
162
+}
163
+
164
+static void str_lines(const char *s, uint8_t y_off, uint8_t is_black) NONBANKED {
165
+    if (strlen(s) > 10) {
166
+        str(s, 0, y_off, is_black);
167
+        str_center(s + 10, y_off + 2, is_black);
168
+    } else {
169
+        str_center(s, y_off, is_black);
170
+    }
171
+}
172
+
154 173
 static uint8_t number(int32_t score, uint8_t x_off, uint8_t y_off, uint8_t is_black) NONBANKED {
155 174
     // TODO can not set numbers larger than int16 max?!
156 175
     //score = 32767 + 1; // wtf?!
@@ -170,7 +189,7 @@ static uint8_t number(int32_t score, uint8_t x_off, uint8_t y_off, uint8_t is_bl
170 189
         return 0;
171 190
     }
172 191
 
173
-    uint8_t off = (x_off == 0xFF) ? (10 - len) : ((x_off == 0xFE) ? (20 - (len * 2)) : x_off);
192
+    uint8_t off = (x_off == 0xFF) ? (LINE_WIDTH - len) : ((x_off == 0xFE) ? ((LINE_WIDTH * 2) - (len * 2)) : x_off);
174 193
     for (uint8_t i = 0; i < len; i++) {
175 194
         digit(digits[len - i - 1], i, off, y_off, is_black);
176 195
     }
@@ -199,7 +218,7 @@ void win_score_clear(uint8_t is_black) NONBANKED {
199 218
                   title_map_WIDTH / title_map_TILE_W, title_map_HEIGHT / title_map_TILE_H,
200 219
                   title_map_map, 0, BANK(title_map), title_map_MAP_ATTRIBUTES, BANK(title_map));
201 220
 
202
-    str(is_black ? "black" : "white", 10 - 5, 1, is_black);
221
+    str_center(is_black ? "black" : "white", 1, is_black);
203 222
 }
204 223
 
205 224
 void win_score_draw(struct scores score, uint8_t off, uint8_t is_black) NONBANKED {
@@ -207,22 +226,43 @@ void win_score_draw(struct scores score, uint8_t off, uint8_t is_black) NONBANKE
207 226
     number(is_black ? -score.score : score.score, 7, 4 + off * 3, is_black);
208 227
 }
209 228
 
229
+void win_about(void) NONBANKED {
230
+    set_win_based(0, 0,
231
+                  title_map_WIDTH / title_map_TILE_W, title_map_HEIGHT / title_map_TILE_H,
232
+                  title_map_map, 0, BANK(title_map), title_map_MAP_ATTRIBUTES, BANK(title_map));
233
+
234
+    str_center("Duality", 0, 1);
235
+    str_center("xythobuz", 2, 1);
236
+
237
+    SWITCH_ROM(BANK(git));
238
+    char line_buff[2 * LINE_WIDTH + 1] = {0};
239
+    strncpy(line_buff, git_version, 2 * LINE_WIDTH);
240
+
241
+    str_lines(line_buff, 7, 0);
242
+
243
+    str_l(&__DATE__[7], 4,           0, 14, 1); // year (4)
244
+    str_l(&__DATE__[0], 3, (4 * 2) + 1, 14, 1); // month (3)
245
+    str_l(&__DATE__[4], 2, (7 * 2) + 2, 14, 1); // day (2)
246
+
247
+    str(__TIME__, 4, 16, 0);
248
+}
249
+
210 250
 void win_name(int32_t score) NONBANKED {
211 251
     set_win_based(0, 0,
212 252
                   title_map_WIDTH / title_map_TILE_W, title_map_HEIGHT / title_map_TILE_H,
213 253
                   title_map_map, 0, BANK(title_map), title_map_MAP_ATTRIBUTES, BANK(title_map));
214 254
 
215
-    str("score", 10 - 5, 1, score < 0);
255
+    str_center("score", 1, score < 0);
216 256
     number(score < 0 ? -score : score, 0xFF, 3, score < 0);
217 257
 
218
-    str("enter", 10 - 5, 6, score < 0);
219
-    str("name", 10 - 4, 8, score < 0);
258
+    str_center("enter", 6, score < 0);
259
+    str_center("name", 8, score < 0);
220 260
 
221
-    str("start ok", 10 - 8, 16, score < 0);
261
+    str_center("start ok", 16, score < 0);
222 262
 }
223 263
 
224 264
 void win_name_draw(uint16_t name, uint8_t is_black, uint8_t pos) NONBANKED {
225
-    str3(name, 10 - 3, 12,
265
+    str3(name, LINE_WIDTH - 3, 12,
226 266
          (pos == 0) ? !is_black : is_black,
227 267
          (pos == 1) ? !is_black : is_black,
228 268
          (pos == 2) ? !is_black : is_black);

+ 1
- 0
src/maps.h View File

@@ -30,6 +30,7 @@ void win_init(uint8_t is_splash);
30 30
 void win_splash_draw(int32_t lowest, int32_t highest);
31 31
 void win_score_clear(uint8_t is_black);
32 32
 void win_score_draw(struct scores score, uint8_t off, uint8_t is_black);
33
+void win_about(void);
33 34
 void win_name(int32_t score);
34 35
 void win_name_draw(uint16_t name, uint8_t is_black, uint8_t pos);
35 36
 uint8_t win_game_draw(int32_t score);

Loading…
Cancel
Save