Browse Source

some dmg optimizations

Thomas B 2 weeks ago
parent
commit
2c2537c56e
16 changed files with 276 additions and 151 deletions
  1. 3
    1
      src/config.ba0.c
  2. 8
    4
      src/config.h
  3. 94
    67
      src/game.c
  4. 7
    5
      src/game.h
  5. 41
    20
      src/main.c
  6. 15
    4
      src/main.h
  7. 18
    15
      src/maps.c
  8. 4
    1
      src/sample.c
  9. 0
    4
      src/sgb_border.c
  10. 18
    12
      src/sprites.c
  11. 3
    1
      src/strings.c
  12. 1
    0
      src/strings.h
  13. 16
    12
      src/text.c
  14. 2
    0
      src/timer.h
  15. 28
    5
      src/window.c
  16. 18
    0
      util/palette.py

+ 3
- 1
src/config.ba0.c View File

53
 
53
 
54
     if (calc_crc() != mem.crc) {
54
     if (calc_crc() != mem.crc) {
55
         mem.config.debug_flags = 0;
55
         mem.config.debug_flags = 0;
56
-        mem.config.sfx_vol = 0x03;
56
+        //mem.config.sfx_vol = 0x03;
57
         mem.config.music_vol = 0x07;
57
         mem.config.music_vol = 0x07;
58
 
58
 
59
         if (_cpu == CGB_TYPE) {
59
         if (_cpu == CGB_TYPE) {
62
             mem.config.game_bg = 1;
62
             mem.config.game_bg = 1;
63
         }
63
         }
64
 
64
 
65
+        mem.config.dmg_bg_inv = 1;
66
+
65
         score_reset();
67
         score_reset();
66
     }
68
     }
67
 }
69
 }

+ 8
- 4
src/config.h View File

34
     DBG_NO_OBJ      = (1 << 3),
34
     DBG_NO_OBJ      = (1 << 3),
35
     DBG_NO_FUEL     = (1 << 4),
35
     DBG_NO_FUEL     = (1 << 4),
36
     DBG_FAST        = (1 << 5),
36
     DBG_FAST        = (1 << 5),
37
-    DBG_SHOW_FRAMES = (1 << 6),
38
-    DBG_SHOW_TIMER  = (1 << 7),
39
-    DBG_SHOW_STACK  = (1 << 8),
37
+    DBG_SHOW_FPS    = (1 << 6),
38
+    DBG_SHOW_FRAMES = (1 << 7),
39
+    DBG_SHOW_TIMER  = (1 << 8),
40
+    DBG_SHOW_STACK  = (1 << 9),
40
 };
41
 };
41
 
42
 
43
+#define DBG_OUT_ON (DBG_SHOW_FPS | DBG_SHOW_FRAMES | DBG_SHOW_TIMER | DBG_SHOW_STACK)
44
+
42
 struct config {
45
 struct config {
43
     enum debug_flag debug_flags;
46
     enum debug_flag debug_flags;
44
-    uint8_t sfx_vol;
47
+    //uint8_t sfx_vol;
45
     uint8_t music_vol;
48
     uint8_t music_vol;
46
     uint8_t game_bg;
49
     uint8_t game_bg;
50
+    uint8_t dmg_bg_inv;
47
 };
51
 };
48
 
52
 
49
 void conf_init(void) BANKED;
53
 void conf_init(void) BANKED;

+ 94
- 67
src/game.c View File

17
  * See <http://www.gnu.org/licenses/>.
17
  * See <http://www.gnu.org/licenses/>.
18
  */
18
  */
19
 
19
 
20
-#include <gbdk/platform.h>
21
 #include <gbdk/metasprites.h>
20
 #include <gbdk/metasprites.h>
22
 #include <rand.h>
21
 #include <rand.h>
23
 #include <stdint.h>
22
 #include <stdint.h>
35
 #include "multiplayer.h"
34
 #include "multiplayer.h"
36
 #include "table_speed_shot.h"
35
 #include "table_speed_shot.h"
37
 #include "table_speed_move.h"
36
 #include "table_speed_move.h"
37
+#include "timer.h"
38
 #include "game.h"
38
 #include "game.h"
39
 
39
 
40
 #define BAR_OFFSET_X (4 - 80)
40
 #define BAR_OFFSET_X (4 - 80)
74
 static int32_t score = 0;
74
 static int32_t score = 0;
75
 static uint16_t frame_count = 0;
75
 static uint16_t frame_count = 0;
76
 
76
 
77
-static uint8_t pause_screen(void) NONBANKED {
77
+static uint8_t pause_screen(void) {
78
     snd_music_off();
78
     snd_music_off();
79
     snd_note_off();
79
     snd_note_off();
80
 
80
 
95
         spr_draw(SPR_PAUSE, FLIP_NONE, 0, 0, (n < (PAUSE_BLINK_FRAMES / 2)) ? 0 : 1, &hiwater);
95
         spr_draw(SPR_PAUSE, FLIP_NONE, 0, 0, (n < (PAUSE_BLINK_FRAMES / 2)) ? 0 : 1, &hiwater);
96
         hide_sprites_range(hiwater, MAX_HARDWARE_SPRITES);
96
         hide_sprites_range(hiwater, MAX_HARDWARE_SPRITES);
97
 
97
 
98
+        if ((_cpu == CGB_TYPE) && (conf_get()->debug_flags & DBG_OUT_ON)) {
99
+            uint8_t x_off = win_game_draw(score, 0);
100
+            move_win(MINWNDPOSX + DEVICE_SCREEN_PX_WIDTH - x_off, MINWNDPOSY + DEVICE_SCREEN_PX_HEIGHT - 16);
101
+        }
102
+
98
         vsync();
103
         vsync();
99
     }
104
     }
100
 
105
 
101
     return 0;
106
     return 0;
102
 }
107
 }
103
 
108
 
104
-static void status(uint8_t health, uint8_t power, uint8_t *hiwater) NONBANKED {
109
+static void status(uint8_t health, uint8_t power, uint8_t *hiwater) {
105
     if (health > 0) {
110
     if (health > 0) {
106
         switch (health >> 6) {
111
         switch (health >> 6) {
107
             case 3:
112
             case 3:
137
     }
142
     }
138
 }
143
 }
139
 
144
 
140
-static void show_explosion(uint16_t power) NONBANKED {
145
+static void show_explosion(uint16_t power) {
141
     snd_music_off();
146
     snd_music_off();
142
     snd_note_off();
147
     snd_note_off();
143
     sample_play(SFX_EXPL_SHIP);
148
     sample_play(SFX_EXPL_SHIP);
153
     }
158
     }
154
 }
159
 }
155
 
160
 
156
-void game_get_mp_state(void) NONBANKED {
161
+void game_get_mp_state(void) BANKED {
157
     static struct mp_player_state state;
162
     static struct mp_player_state state;
158
 
163
 
159
     // TODO pass own pos to mp
164
     // TODO pass own pos to mp
166
     mp_new_state(&state);
171
     mp_new_state(&state);
167
 }
172
 }
168
 
173
 
169
-void game_set_mp_player2(struct mp_player_state *state) NONBANKED {
174
+void game_set_mp_player2(struct mp_player_state *state) BANKED {
170
     // TODO update p2 pos
175
     // TODO update p2 pos
171
 }
176
 }
172
 
177
 
173
-void game_set_mp_shot(struct mp_shot_state *state) NONBANKED {
178
+void game_set_mp_shot(struct mp_shot_state *state) BANKED {
174
     // TODO add shot
179
     // TODO add shot
175
 }
180
 }
176
 
181
 
177
-static inline void get_max_spd(int16_t *max_spd_x, int16_t *max_spd_y) NONBANKED {
182
+static void get_max_spd(int16_t *max_spd_x, int16_t *max_spd_y) NONBANKED {
178
     START_ROM_BANK(BANK(table_speed_move)) {
183
     START_ROM_BANK(BANK(table_speed_move)) {
179
         *max_spd_x = table_speed_move[(rot * table_speed_move_WIDTH) + 0];
184
         *max_spd_x = table_speed_move[(rot * table_speed_move_WIDTH) + 0];
180
         *max_spd_y = -table_speed_move[(rot * table_speed_move_WIDTH) + 1];
185
         *max_spd_y = -table_speed_move[(rot * table_speed_move_WIDTH) + 1];
181
     } END_ROM_BANK;
186
     } END_ROM_BANK;
182
 }
187
 }
183
 
188
 
184
-static inline void handle_acceleration(void) NONBANKED {
185
-    int16_t max_spd_x;
186
-    int16_t max_spd_y;
187
-    get_max_spd(&max_spd_x, &max_spd_y);
188
-
189
-    if (conf_get()->debug_flags & DBG_FAST) {
190
-        if (max_spd_x > 0) {
191
-            max_spd_x = SPEED_MAX_DBG;
192
-        } else if (max_spd_x < 0) {
193
-            max_spd_x = -SPEED_MAX_DBG;
194
-        }
195
-
196
-        if (max_spd_y > 0) {
197
-            max_spd_y = SPEED_MAX_DBG;
198
-        } else if (max_spd_y < 0) {
199
-            max_spd_y = -SPEED_MAX_DBG;
200
-        }
201
-    }
202
-
203
-    if (max_spd_x != 0) {
204
-        if (max_spd_x > 0) {
205
-            spd_x += SPEED_INC;
206
-            if (spd_x > max_spd_x) {
207
-                spd_x = max_spd_x;
208
-            }
209
-        } else {
210
-            spd_x -= SPEED_INC;
211
-            if (spd_x < max_spd_x) {
212
-                spd_x = max_spd_x;
213
-            }
214
-        }
189
+static void get_shot_spd(int16_t *shot_spd_x, int16_t *shot_spd_y) NONBANKED {
190
+    START_ROM_BANK(BANK(table_speed_shot)) {
191
+        *shot_spd_x = table_speed_shot[(rot * table_speed_move_WIDTH) + 0];
192
+        *shot_spd_y = -table_speed_shot[(rot * table_speed_move_WIDTH) + 1];
193
+    } END_ROM_BANK;
194
+}
215
 
195
 
216
-        acc |= ACC_X;
196
+static uint8_t fps_count = 0;
197
+static uint16_t prev_fps_start = 0;
198
+static uint8_t prev_fps = 0;
199
+
200
+static inline void calc_fps(void) {
201
+    fps_count++;
202
+    uint16_t diff = timer_get() - prev_fps_start;
203
+    if (diff >= TIMER_HZ) {
204
+        prev_fps_start = timer_get();
205
+        prev_fps = fps_count;
206
+        fps_count = 0;
217
     }
207
     }
208
+}
218
 
209
 
219
-    if (max_spd_y != 0) {
220
-        if (max_spd_y > 0) {
221
-            spd_y += SPEED_INC;
222
-            if (spd_y > max_spd_y) {
223
-                spd_y = max_spd_y;
224
-            }
225
-        } else {
226
-            spd_y -= SPEED_INC;
227
-            if (spd_y < max_spd_y) {
228
-                spd_y = max_spd_y;
229
-            }
230
-        }
210
+uint8_t game_get_fps(void) BANKED {
211
+    return prev_fps;
212
+}
231
 
213
 
232
-        acc |= ACC_Y;
233
-    }
214
+uint16_t game_get_framecount(void) BANKED {
215
+    return frame_count;
234
 }
216
 }
235
 
217
 
236
-int32_t game(enum GAME_MODE mode) NONBANKED {
218
+int32_t game(enum GAME_MODE mode) BANKED {
237
     snd_music_off();
219
     snd_music_off();
238
     snd_note_off();
220
     snd_note_off();
239
 
221
 
290
         }
272
         }
291
 
273
 
292
         if (key_down(J_A) && (power > 0)) {
274
         if (key_down(J_A) && (power > 0)) {
293
-            handle_acceleration();
275
+            int16_t max_spd_x;
276
+            int16_t max_spd_y;
277
+            get_max_spd(&max_spd_x, &max_spd_y);
278
+
279
+            if (conf_get()->debug_flags & DBG_FAST) {
280
+                if (max_spd_x > 0) {
281
+                    max_spd_x = SPEED_MAX_DBG;
282
+                } else if (max_spd_x < 0) {
283
+                    max_spd_x = -SPEED_MAX_DBG;
284
+                }
285
+
286
+                if (max_spd_y > 0) {
287
+                    max_spd_y = SPEED_MAX_DBG;
288
+                } else if (max_spd_y < 0) {
289
+                    max_spd_y = -SPEED_MAX_DBG;
290
+                }
291
+            }
292
+
293
+            if (max_spd_x != 0) {
294
+                if (max_spd_x > 0) {
295
+                    spd_x += SPEED_INC;
296
+                    if (spd_x > max_spd_x) {
297
+                        spd_x = max_spd_x;
298
+                    }
299
+                } else {
300
+                    spd_x -= SPEED_INC;
301
+                    if (spd_x < max_spd_x) {
302
+                        spd_x = max_spd_x;
303
+                    }
304
+                }
305
+
306
+                acc |= ACC_X;
307
+            }
308
+
309
+            if (max_spd_y != 0) {
310
+                if (max_spd_y > 0) {
311
+                    spd_y += SPEED_INC;
312
+                    if (spd_y > max_spd_y) {
313
+                        spd_y = max_spd_y;
314
+                    }
315
+                } else {
316
+                    spd_y -= SPEED_INC;
317
+                    if (spd_y < max_spd_y) {
318
+                        spd_y = max_spd_y;
319
+                    }
320
+                }
321
+
322
+                acc |= ACC_Y;
323
+            }
294
 
324
 
295
             if (!(conf_get()->debug_flags & DBG_NO_FUEL)) {
325
             if (!(conf_get()->debug_flags & DBG_NO_FUEL)) {
296
                 if (power >= POWER_DEC) {
326
                 if (power >= POWER_DEC) {
332
         if (key_pressed(J_B)) {
362
         if (key_pressed(J_B)) {
333
             int16_t shot_spd_x;
363
             int16_t shot_spd_x;
334
             int16_t shot_spd_y;
364
             int16_t shot_spd_y;
335
-            START_ROM_BANK(BANK(table_speed_shot)) {
336
-                shot_spd_x = spd_x + table_speed_shot[(rot * table_speed_shot_WIDTH) + 0];
337
-                shot_spd_y = spd_y - table_speed_shot[(rot * table_speed_shot_WIDTH) + 1];
338
-            } END_ROM_BANK;
365
+            get_shot_spd(&shot_spd_x, &shot_spd_y);
366
+            shot_spd_x += spd_x;
367
+            shot_spd_y += spd_y;
339
 
368
 
340
             // TODO ugly hard-coded offsets?!
369
             // TODO ugly hard-coded offsets?!
341
             int16_t shot_pos_x = 0, shot_pos_y = 0;
370
             int16_t shot_pos_x = 0, shot_pos_y = 0;
496
 
525
 
497
         hide_sprites_range(hiwater, MAX_HARDWARE_SPRITES);
526
         hide_sprites_range(hiwater, MAX_HARDWARE_SPRITES);
498
 
527
 
499
-        if ((score != prev_score) || ((_cpu == CGB_TYPE)
500
-                && (conf_get()->debug_flags & (DBG_SHOW_FRAMES | DBG_SHOW_TIMER | DBG_SHOW_STACK)))) {
528
+        if ((score != prev_score)
529
+                || ((_cpu == CGB_TYPE) && (conf_get()->debug_flags & DBG_OUT_ON))) {
501
             uint8_t x_off = win_game_draw(score, 0);
530
             uint8_t x_off = win_game_draw(score, 0);
502
             move_win(MINWNDPOSX + DEVICE_SCREEN_PX_WIDTH - x_off, MINWNDPOSY + DEVICE_SCREEN_PX_HEIGHT - 16);
531
             move_win(MINWNDPOSX + DEVICE_SCREEN_PX_WIDTH - x_off, MINWNDPOSY + DEVICE_SCREEN_PX_HEIGHT - 16);
503
         }
532
         }
504
 
533
 
505
-        vsync();
534
+        calc_fps();
506
         frame_count++;
535
         frame_count++;
536
+
537
+        vsync();
507
     }
538
     }
508
 
539
 
509
     return score;
540
     return score;
510
 }
541
 }
511
-
512
-uint16_t game_get_framecount(void) NONBANKED {
513
-    return frame_count;
514
-}

+ 7
- 5
src/game.h View File

20
 #ifndef __GAME_H__
20
 #ifndef __GAME_H__
21
 #define __GAME_H__
21
 #define __GAME_H__
22
 
22
 
23
+#include <gbdk/platform.h>
23
 #include <stdint.h>
24
 #include <stdint.h>
24
 #include "multiplayer.h"
25
 #include "multiplayer.h"
25
 
26
 
38
     GM_MULTI,
39
     GM_MULTI,
39
 };
40
 };
40
 
41
 
41
-void game_get_mp_state(void);
42
-void game_set_mp_player2(struct mp_player_state *state);
43
-void game_set_mp_shot(struct mp_shot_state *state);
42
+void game_get_mp_state(void) BANKED;
43
+void game_set_mp_player2(struct mp_player_state *state) BANKED;
44
+void game_set_mp_shot(struct mp_shot_state *state) BANKED;
44
 
45
 
45
-int32_t game(enum GAME_MODE mode);
46
-uint16_t game_get_framecount(void);
46
+uint8_t game_get_fps(void) BANKED;
47
+uint16_t game_get_framecount(void) BANKED;
48
+int32_t game(enum GAME_MODE mode) BANKED;
47
 
49
 
48
 BANKREF_EXTERN(game)
50
 BANKREF_EXTERN(game)
49
 
51
 

+ 41
- 20
src/main.c View File

48
 
48
 
49
 static uint8_t anim_frame = 0;
49
 static uint8_t anim_frame = 0;
50
 static uint8_t anim_state = 0;
50
 static uint8_t anim_state = 0;
51
+static enum HW_TYPE hw_type = HW_UNKNOWN;
51
 
52
 
52
 BANKREF(main)
53
 BANKREF(main)
53
 
54
 
54
 const struct conf_entry conf_entries[CONF_ENTRY_COUNT] = {
55
 const struct conf_entry conf_entries[CONF_ENTRY_COUNT] = {
55
-    //{ .name = "sfx-vol",  .var = &mem.config.sfx_vol,   .max = 3 },
56
-    { .name = "musi-vol", .var = &mem.config.music_vol, .max = 15 },
57
-    { .name = "game-map", .var = &mem.config.game_bg,   .max = 1 },
56
+  //{ .name = "sfx-vol",  .var = &mem.config.sfx_vol,    .max = 3,  .type = HW_ALL },
57
+    { .name = "musi-vol", .var = &mem.config.music_vol,  .max = 15, .type = HW_ALL },
58
+    { .name = "game-map", .var = &mem.config.game_bg,    .max = 1,  .type = HW_ALL },
59
+    { .name = "invt-map", .var = &mem.config.dmg_bg_inv, .max = 1,  .type = HW_DMG },
58
 };
60
 };
59
 
61
 
60
 const struct debug_entry debug_entries[DEBUG_ENTRY_COUNT] = {
62
 const struct debug_entry debug_entries[DEBUG_ENTRY_COUNT] = {
63
     { .name = "no-spawn", .flag = DBG_NO_OBJ,      .max = 1         }, // 2
65
     { .name = "no-spawn", .flag = DBG_NO_OBJ,      .max = 1         }, // 2
64
     { .name = "no-fuel",  .flag = DBG_NO_FUEL,     .max = 1         }, // 3
66
     { .name = "no-fuel",  .flag = DBG_NO_FUEL,     .max = 1         }, // 3
65
     { .name = "fastmove", .flag = DBG_FAST,        .max = 1         }, // 4
67
     { .name = "fastmove", .flag = DBG_FAST,        .max = 1         }, // 4
66
-    { .name = "s-frames", .flag = DBG_SHOW_FRAMES, .max = 1         }, // 5
67
-    { .name = "s-timer",  .flag = DBG_SHOW_TIMER,  .max = 1         }, // 6
68
-    { .name = "s-stack",  .flag = DBG_SHOW_STACK,  .max = 1         }, // 7
68
+    { .name = "show-fps", .flag = DBG_SHOW_FPS,    .max = 1         }, // 5
69
+    { .name = "s-frames", .flag = DBG_SHOW_FRAMES, .max = 1         }, // 6
70
+    { .name = "sh-timer", .flag = DBG_SHOW_TIMER,  .max = 1         }, // 7
71
+    { .name = "sh-stack", .flag = DBG_SHOW_STACK,  .max = 1         }, // 8
69
 
72
 
70
     // keep at end
73
     // keep at end
71
-    { .name = "music",    .flag = DBG_NONE,        .max = SND_COUNT }, // 8
72
-    { .name = "sfx-test", .flag = DBG_NONE,        .max = SFX_COUNT }, // 9
73
-    { .name = "cl score", .flag = DBG_NONE,        .max = 1         }, // 10
74
-    { .name = "0 scores", .flag = DBG_NONE,        .max = 1         }, // 11
74
+    { .name = "music",    .flag = DBG_NONE,        .max = SND_COUNT }, // 9
75
+    { .name = "sfx-test", .flag = DBG_NONE,        .max = SFX_COUNT }, // 10
76
+    { .name = "cl score", .flag = DBG_NONE,        .max = 1         }, // 11
77
+    { .name = "0 scores", .flag = DBG_NONE,        .max = 1         }, // 12
75
 };
78
 };
76
 
79
 
77
 #define DEBUG_MENU_MUSIC_INDEX (DEBUG_ENTRY_COUNT - 4)
80
 #define DEBUG_MENU_MUSIC_INDEX (DEBUG_ENTRY_COUNT - 4)
79
 #define DEBUG_MENU_CLEAR_INDEX (DEBUG_ENTRY_COUNT - 2)
82
 #define DEBUG_MENU_CLEAR_INDEX (DEBUG_ENTRY_COUNT - 2)
80
 #define DEBUG_MENU_ZERO_INDEX  (DEBUG_ENTRY_COUNT - 1)
83
 #define DEBUG_MENU_ZERO_INDEX  (DEBUG_ENTRY_COUNT - 1)
81
 
84
 
85
+enum HW_TYPE get_hw(void) BANKED {
86
+    return hw_type;
87
+}
88
+
82
 static void list_scores(uint8_t is_black) {
89
 static void list_scores(uint8_t is_black) {
83
     for (uint8_t i = 0; i < SCORE_NUM; i++) {
90
     for (uint8_t i = 0; i < SCORE_NUM; i++) {
84
         struct scores score;
91
         struct scores score;
172
             about_screen();
179
             about_screen();
173
             break;
180
             break;
174
         } else if (key_pressed(J_UP)) {
181
         } else if (key_pressed(J_UP)) {
175
-            if (debug_menu_index > 0) {
176
-                debug_menu_index--;
177
-            } else {
178
-                debug_menu_index = CONF_ENTRY_COUNT - 1;
179
-            }
182
+            do {
183
+                if (debug_menu_index > 0) {
184
+                    debug_menu_index--;
185
+                } else {
186
+                    debug_menu_index = CONF_ENTRY_COUNT - 1;
187
+                }
188
+            } while ((conf_entries[debug_menu_index].type != HW_ALL)
189
+                    && (conf_entries[debug_menu_index].type != hw_type));
180
             win_conf();
190
             win_conf();
181
         } else if (key_pressed(J_DOWN)) {
191
         } else if (key_pressed(J_DOWN)) {
182
-            if (debug_menu_index < (CONF_ENTRY_COUNT - 1)) {
183
-                debug_menu_index++;
184
-            } else {
185
-                debug_menu_index = 0;
186
-            }
192
+            do {
193
+                if (debug_menu_index < (CONF_ENTRY_COUNT - 1)) {
194
+                    debug_menu_index++;
195
+                } else {
196
+                    debug_menu_index = 0;
197
+                }
198
+            } while ((conf_entries[debug_menu_index].type != HW_ALL)
199
+                    && (conf_entries[debug_menu_index].type != hw_type));
187
             win_conf();
200
             win_conf();
188
         } else if (key_pressed(J_LEFT)) {
201
         } else if (key_pressed(J_LEFT)) {
189
             if (*conf_entries[debug_menu_index].var > 0) {
202
             if (*conf_entries[debug_menu_index].var > 0) {
568
 
581
 
569
     DISPLAY_ON;
582
     DISPLAY_ON;
570
 
583
 
584
+    if (!sgb_check()) {
585
+        hw_type = (_cpu == CGB_TYPE) ? HW_GBC : HW_DMG;
586
+        DISPLAY_OFF;
587
+        return;
588
+    } else {
589
+        hw_type = HW_SGB;
590
+    }
591
+
571
     START_ROM_BANK(BANK(border_sgb)) {
592
     START_ROM_BANK(BANK(border_sgb)) {
572
         set_sgb_border((const uint8_t *)border_sgb_tiles, sizeof(border_sgb_tiles),
593
         set_sgb_border((const uint8_t *)border_sgb_tiles, sizeof(border_sgb_tiles),
573
                        (const uint8_t *)border_sgb_map, sizeof(border_sgb_map),
594
                        (const uint8_t *)border_sgb_map, sizeof(border_sgb_map),

+ 15
- 4
src/main.h View File

24
 #include <stdint.h>
24
 #include <stdint.h>
25
 
25
 
26
 #define ENTRY_NAME_LEN 8
26
 #define ENTRY_NAME_LEN 8
27
+#define CONF_ENTRY_COUNT 3
28
+#define DEBUG_ENTRY_COUNT 13
29
+
30
+enum HW_TYPE {
31
+    HW_DMG = 0,
32
+    HW_SGB,
33
+    HW_GBC,
34
+
35
+    HW_UNKNOWN,
36
+    HW_ALL = HW_UNKNOWN,
37
+};
27
 
38
 
28
 struct conf_entry {
39
 struct conf_entry {
29
     char name[ENTRY_NAME_LEN + 1];
40
     char name[ENTRY_NAME_LEN + 1];
30
     uint8_t *var;
41
     uint8_t *var;
31
     uint8_t max;
42
     uint8_t max;
43
+    enum HW_TYPE type;
32
 };
44
 };
33
 
45
 
34
 struct debug_entry {
46
 struct debug_entry {
37
     uint8_t max;
49
     uint8_t max;
38
 };
50
 };
39
 
51
 
52
+enum HW_TYPE get_hw(void) BANKED;
53
+
40
 BANKREF_EXTERN(main)
54
 BANKREF_EXTERN(main)
41
 
55
 
42
-#define CONF_ENTRY_COUNT 2
43
 extern const struct conf_entry conf_entries[CONF_ENTRY_COUNT];
56
 extern const struct conf_entry conf_entries[CONF_ENTRY_COUNT];
57
+extern const struct debug_entry debug_entries[DEBUG_ENTRY_COUNT];
44
 
58
 
45
 extern uint8_t debug_menu_index;
59
 extern uint8_t debug_menu_index;
46
 extern uint8_t debug_special_value;
60
 extern uint8_t debug_special_value;
47
 
61
 
48
-#define DEBUG_ENTRY_COUNT 12
49
-extern const struct debug_entry debug_entries[DEBUG_ENTRY_COUNT];
50
-
51
 #endif // __MAIN_H__
62
 #endif // __MAIN_H__

+ 18
- 15
src/maps.c View File

21
  */
21
  */
22
 
22
 
23
 #include "banks.h"
23
 #include "banks.h"
24
-#include "gb/cgb.h"
25
-#include "gb/gb.h"
24
+#include "config.h"
26
 #include "util.h"
25
 #include "util.h"
27
 #include "map_data.h"
26
 #include "map_data.h"
28
 #include "maps.h"
27
 #include "maps.h"
63
         }
62
         }
64
     } END_ROM_BANK
63
     } END_ROM_BANK
65
 
64
 
66
-    uint8_t bank = maps[i].bank;
67
-    if (maps[i].palettes == num_pal_inv) {
68
-        bank = BANK(map_data);
69
-    }
70
-
71
-    START_ROM_BANK_2(bank) {
72
-        if (maps[i].palettes != NULL) {
73
-            set_bkg_palette(maps[i].palette_index, maps[i].palette_count, maps[i].palettes);
65
+    if (_cpu == CGB_TYPE) {
66
+        uint8_t bank = maps[i].bank;
67
+        if (maps[i].palettes == num_pal_inv) {
68
+            bank = BANK(map_data);
74
         }
69
         }
75
-    } END_ROM_BANK
70
+
71
+        START_ROM_BANK_2(bank) {
72
+            if (maps[i].palettes != NULL) {
73
+                set_bkg_palette(maps[i].palette_index, maps[i].palette_count, maps[i].palettes);
74
+            }
75
+        } END_ROM_BANK
76
+    }
76
 }
77
 }
77
 
78
 
78
 void map_load(uint8_t is_splash) BANKED {
79
 void map_load(uint8_t is_splash) BANKED {
114
         map_load_helper(i);
115
         map_load_helper(i);
115
     }
116
     }
116
 
117
 
117
-    if (is_splash) {
118
+    if (is_splash || (conf_get()->dmg_bg_inv == 0)) {
118
         BGP_REG = 0b11100100;
119
         BGP_REG = 0b11100100;
119
     } else {
120
     } else {
120
         // invert BGP for DMG in-game
121
         // invert BGP for DMG in-game
124
 
125
 
125
 void map_fill(enum MAPS map, uint8_t bkg) NONBANKED {
126
 void map_fill(enum MAPS map, uint8_t bkg) NONBANKED {
126
     START_ROM_BANK(maps[map].bank) {
127
     START_ROM_BANK(maps[map].bank) {
127
-        VBK_REG = VBK_ATTRIBUTES;
128
-        bkg ? fill_bkg_rect(0, 0, maps[map].width, maps[map].height, maps[map].palette_index)
129
-            : fill_win_rect(0, 0, maps[map].width, maps[map].height, maps[map].palette_index);
128
+        if (_cpu == CGB_TYPE) {
129
+            VBK_REG = VBK_ATTRIBUTES;
130
+            bkg ? fill_bkg_rect(0, 0, maps[map].width, maps[map].height, maps[map].palette_index)
131
+                : fill_win_rect(0, 0, maps[map].width, maps[map].height, maps[map].palette_index);
132
+        }
130
 
133
 
131
         VBK_REG = VBK_TILES;
134
         VBK_REG = VBK_TILES;
132
         bkg ? set_bkg_based_tiles(0, 0, maps[map].width, maps[map].height, maps[map].map, maps[map].tile_offset)
135
         bkg ? set_bkg_based_tiles(0, 0, maps[map].width, maps[map].height, maps[map].map, maps[map].tile_offset)

+ 4
- 1
src/sample.c View File

53
     if (sfx >= SFX_COUNT) {
53
     if (sfx >= SFX_COUNT) {
54
         return;
54
         return;
55
     }
55
     }
56
+
57
+    /*
56
     if (conf_get()->sfx_vol == 0) {
58
     if (conf_get()->sfx_vol == 0) {
57
         return;
59
         return;
58
     }
60
     }
61
+    */
59
 
62
 
60
     CRITICAL {
63
     CRITICAL {
61
         play_bank = sfxs[sfx].bank;
64
         play_bank = sfxs[sfx].bank;
89
 
92
 
90
     NR30_REG = 0x80; // turn DAC on
93
     NR30_REG = 0x80; // turn DAC on
91
     NR31_REG = 0xFE; // length of wave, 2nd shortest
94
     NR31_REG = 0xFE; // length of wave, 2nd shortest
92
-    NR32_REG = (4 - conf_get()->sfx_vol) << 5;
95
+    NR32_REG = (4 - /*conf_get()->sfx_vol*/0x03) << 5;
93
     NR33_REG = 0x00; // low freq bits are zero
96
     NR33_REG = 0x00; // low freq bits are zero
94
     NR34_REG = 0xC7; // start, no loop, high freq bits are 111
97
     NR34_REG = 0xC7; // start, no loop, high freq bits are 111
95
     NR51_REG = 0xFF; // turn all channels on
98
     NR51_REG = 0xFF; // turn all channels on

+ 0
- 4
src/sgb_border.c View File

23
 void set_sgb_border(const uint8_t *tiledata, size_t tiledata_size,
23
 void set_sgb_border(const uint8_t *tiledata, size_t tiledata_size,
24
                     const uint8_t *tilemap, size_t tilemap_size,
24
                     const uint8_t *tilemap, size_t tilemap_size,
25
                     const uint8_t *palette, size_t palette_size) NONBANKED {
25
                     const uint8_t *palette, size_t palette_size) NONBANKED {
26
-    if (!sgb_check()) {
27
-        return;
28
-    }
29
-
30
     unsigned char map_buf[20];
26
     unsigned char map_buf[20];
31
     memset(map_buf, 0, sizeof(map_buf));
27
     memset(map_buf, 0, sizeof(map_buf));
32
 
28
 

+ 18
- 12
src/sprites.c View File

39
 }
39
 }
40
 
40
 
41
 void spr_init_pal(void) NONBANKED {
41
 void spr_init_pal(void) NONBANKED {
42
+    if (_cpu != CGB_TYPE) {
43
+        return;
44
+    }
45
+
42
     for (uint8_t i = 0; i < SPRITE_COUNT; i++) {
46
     for (uint8_t i = 0; i < SPRITE_COUNT; i++) {
43
         uint8_t bank = metasprites[i].bank;
47
         uint8_t bank = metasprites[i].bank;
44
         if (metasprites[i].pa == power_palettes) {
48
         if (metasprites[i].pa == power_palettes) {
68
 
72
 
69
     uint8_t pa_off = 0;
73
     uint8_t pa_off = 0;
70
 
74
 
71
-    if ((metasprites[sprite].pa_i & PALETTE_ALL_FLAGS) == PALETTE_DYNAMIC_LOAD) {
72
-        uint8_t pa_i = frame;
73
-        if (pa_i >= metasprites[sprite].pa_n) {
74
-            pa_i = 0;
75
-        }
75
+    if (_cpu == CGB_TYPE) {
76
+        if ((metasprites[sprite].pa_i & PALETTE_ALL_FLAGS) == PALETTE_DYNAMIC_LOAD) {
77
+            uint8_t pa_i = frame;
78
+            if (pa_i >= metasprites[sprite].pa_n) {
79
+                pa_i = 0;
80
+            }
76
 
81
 
77
-        set_sprite_palette((metasprites[sprite].pa_i & PALETTE_NO_FLAGS) + pa_i, 1, metasprites[sprite].pa + (pa_i * 4));
78
-    } else if ((metasprites[sprite].pa_i & PALETTE_ALL_FLAGS) == PALETTE_DYNAMIC_LOAD_IP) {
79
-        pa_off = frame;
80
-        if (pa_off >= metasprites[sprite].pa_n) {
81
-            pa_off = 0;
82
-        }
82
+            set_sprite_palette((metasprites[sprite].pa_i & PALETTE_NO_FLAGS) + pa_i, 1, metasprites[sprite].pa + (pa_i * 4));
83
+        } else if ((metasprites[sprite].pa_i & PALETTE_ALL_FLAGS) == PALETTE_DYNAMIC_LOAD_IP) {
84
+            pa_off = frame;
85
+            if (pa_off >= metasprites[sprite].pa_n) {
86
+                pa_off = 0;
87
+            }
83
 
88
 
84
-        set_sprite_palette((metasprites[sprite].pa_i & PALETTE_NO_FLAGS), 1, metasprites[sprite].pa + (pa_off * 4));
89
+            set_sprite_palette((metasprites[sprite].pa_i & PALETTE_NO_FLAGS), 1, metasprites[sprite].pa + (pa_off * 4));
90
+        }
85
     }
91
     }
86
 
92
 
87
     switch (flip) {
93
     switch (flip) {

+ 3
- 1
src/strings.c View File

40
 static const char           string_date[] = __DATE__;
40
 static const char           string_date[] = __DATE__;
41
 static const char           string_time[] = __TIME__;
41
 static const char           string_time[] = __TIME__;
42
 static const char          string_mp_tx[] = "MP Tx:";
42
 static const char          string_mp_tx[] = "MP Tx:";
43
-static const char           string_wait[] = "Wait";
43
+static const char           string_wait[] = "Wait ";
44
 static const char          string_visit[] = "Visit:";
44
 static const char          string_visit[] = "Visit:";
45
 static const char            string_url[] = "https://xythobuz.de";
45
 static const char            string_url[] = "https://xythobuz.de";
46
 static const char       string_printout[] = "printout";
46
 static const char       string_printout[] = "printout";
53
 static const char  string_printf_frames[] = "Frames: 0x%x";
53
 static const char  string_printf_frames[] = "Frames: 0x%x";
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
 
57
 
57
 static const char * const strings[COUNT_STRINGS] = {
58
 static const char * const strings[COUNT_STRINGS] = {
58
     string_top,            // STR_TOP
59
     string_top,            // STR_TOP
84
     string_printf_frames,  // STR_PRINTF_FRAMES
85
     string_printf_frames,  // STR_PRINTF_FRAMES
85
     string_printf_timer,   // STR_PRINTF_TIMER
86
     string_printf_timer,   // STR_PRINTF_TIMER
86
     string_printf_stack,   // STR_PRINTF_STACK
87
     string_printf_stack,   // STR_PRINTF_STACK
88
+    string_printf_fps,     // STR_PRINTF_FPS
87
 };
89
 };
88
 
90
 
89
 #define MAX_STR_LEN 32
91
 #define MAX_STR_LEN 32

+ 1
- 0
src/strings.h View File

52
     STR_PRINTF_FRAMES,
52
     STR_PRINTF_FRAMES,
53
     STR_PRINTF_TIMER,
53
     STR_PRINTF_TIMER,
54
     STR_PRINTF_STACK,
54
     STR_PRINTF_STACK,
55
+    STR_PRINTF_FPS,
55
 
56
 
56
     COUNT_STRINGS
57
     COUNT_STRINGS
57
 };
58
 };

+ 16
- 12
src/text.c View File

27
 #include "text.h"
27
 #include "text.h"
28
 
28
 
29
 // TODO inverted score color not visible on DMG
29
 // TODO inverted score color not visible on DMG
30
-// TODO 8x8 font only available on GBC
30
+// TODO selected menu entry not visible on DMG
31
 
31
 
32
 #define TEXT_PALETTE_WHITE BKGF_CGB_PAL3
32
 #define TEXT_PALETTE_WHITE BKGF_CGB_PAL3
33
 #define TEXT_PALETTE_BLACK BKGF_CGB_PAL4
33
 #define TEXT_PALETTE_BLACK BKGF_CGB_PAL4
35
 #define TEXT_ATTR_WHITE    (BKGF_PRI | TEXT_PALETTE_WHITE)
35
 #define TEXT_ATTR_WHITE    (BKGF_PRI | TEXT_PALETTE_WHITE)
36
 #define TEXT_ATTR_BLACK    (BKGF_PRI | TEXT_PALETTE_BLACK)
36
 #define TEXT_ATTR_BLACK    (BKGF_PRI | TEXT_PALETTE_BLACK)
37
 
37
 
38
-#define ASCI_ATTR_DARK     (BKGF_PRI | BKGF_BANK1 | BKGF_CGB_PAL6) // TODO?
39
-#define ASCI_ATTR_LIGHT    (BKGF_PRI | BKGF_BANK1 | BKGF_CGB_PAL5) // TODO?
38
+#define ASCI_ATTR_DARK     (BKGF_PRI | BKGF_BANK1 | BKGF_CGB_PAL6)
39
+#define ASCI_ATTR_LIGHT    (BKGF_PRI | BKGF_BANK1 | BKGF_CGB_PAL5)
40
 
40
 
41
 BANKREF(text)
41
 BANKREF(text)
42
 
42
 
45
 static void set_win_based(uint8_t x, uint8_t y, uint8_t w, uint8_t h,
45
 static void set_win_based(uint8_t x, uint8_t y, uint8_t w, uint8_t h,
46
                           const uint8_t *tiles, uint8_t base_tile, uint8_t tile_bank,
46
                           const uint8_t *tiles, uint8_t base_tile, uint8_t tile_bank,
47
                           const uint8_t *attributes, uint8_t attr_bank) NONBANKED {
47
                           const uint8_t *attributes, uint8_t attr_bank) NONBANKED {
48
-    if (attributes != NULL) {
49
-        START_ROM_BANK(attr_bank) {
48
+    if (_cpu == CGB_TYPE) {
49
+        if (attributes != NULL) {
50
+            START_ROM_BANK(attr_bank) {
51
+                VBK_REG = VBK_ATTRIBUTES;
52
+                set_win_tiles(x, y, w, h, attributes);
53
+            } END_ROM_BANK
54
+        } else {
50
             VBK_REG = VBK_ATTRIBUTES;
55
             VBK_REG = VBK_ATTRIBUTES;
51
-            set_win_tiles(x, y, w, h, attributes);
52
-        } END_ROM_BANK
53
-    } else {
54
-        VBK_REG = VBK_ATTRIBUTES;
55
-        fill_win_rect(x, y, w, h, 0x00);
56
+            fill_win_rect(x, y, w, h, 0x00);
57
+        }
56
     }
58
     }
57
 
59
 
58
     START_ROM_BANK(tile_bank) {
60
     START_ROM_BANK(tile_bank) {
64
 static void set_win_based_attr(uint8_t x, uint8_t y, uint8_t w, uint8_t h,
66
 static void set_win_based_attr(uint8_t x, uint8_t y, uint8_t w, uint8_t h,
65
                                const uint8_t *tiles, uint8_t base_tile, uint8_t tile_bank,
67
                                const uint8_t *tiles, uint8_t base_tile, uint8_t tile_bank,
66
                                const uint8_t attr) NONBANKED {
68
                                const uint8_t attr) NONBANKED {
67
-    VBK_REG = VBK_ATTRIBUTES;
68
-    fill_win_rect(x, y, w, h, attr);
69
+    if (_cpu == CGB_TYPE) {
70
+        VBK_REG = VBK_ATTRIBUTES;
71
+        fill_win_rect(x, y, w, h, attr);
72
+    }
69
 
73
 
70
     START_ROM_BANK(tile_bank) {
74
     START_ROM_BANK(tile_bank) {
71
         VBK_REG = VBK_TILES;
75
         VBK_REG = VBK_TILES;

+ 2
- 0
src/timer.h View File

23
 #include <gbdk/platform.h>
23
 #include <gbdk/platform.h>
24
 #include <stdint.h>
24
 #include <stdint.h>
25
 
25
 
26
+#define TIMER_HZ (256 * 4)
27
+
26
 void timer_init(void) BANKED;
28
 void timer_init(void) BANKED;
27
 uint16_t timer_get(void);
29
 uint16_t timer_get(void);
28
 
30
 

+ 28
- 5
src/window.c View File

205
 
205
 
206
     str_center(get_string(STR_DEBUG_MENU), 0, 0);
206
     str_center(get_string(STR_DEBUG_MENU), 0, 0);
207
 
207
 
208
-    for (uint8_t i = debug_menu_index; (i < DEBUG_ENTRY_COUNT) && (i < (7 + debug_menu_index)); i++) {
208
+    for (uint8_t i = debug_menu_index; (i < DEBUG_ENTRY_COUNT) && (i < (8 + debug_menu_index)); i++) {
209
         char name_buff[ENTRY_NAME_LEN + 2 + 1] = {0};
209
         char name_buff[ENTRY_NAME_LEN + 2 + 1] = {0};
210
         uint8_t n_len = get_debug(name_buff, i);
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);
211
         str(name_buff, (TEXT_LINE_WIDTH - n_len) * 2, ((i - debug_menu_index) * 2) + 3 + off, (debug_menu_index == i) ? 1 : 0);
212
     }
212
     }
213
 }
213
 }
214
 
214
 
215
+static uint8_t is_conf_hw(uint8_t i) NONBANKED {
216
+    uint8_t r;
217
+    START_ROM_BANK(BANK(main)) {
218
+        r = (conf_entries[i].type == HW_ALL) || (conf_entries[i].type == get_hw());
219
+    } END_ROM_BANK
220
+    return r;
221
+}
222
+
215
 static uint8_t get_conf(char *name_buff, uint8_t i) NONBANKED {
223
 static uint8_t get_conf(char *name_buff, uint8_t i) NONBANKED {
216
     uint8_t n_len;
224
     uint8_t n_len;
217
     START_ROM_BANK(BANK(main)) {
225
     START_ROM_BANK(BANK(main)) {
233
 void win_conf(void) BANKED {
241
 void win_conf(void) BANKED {
234
     map_fill(MAP_TITLE, 0);
242
     map_fill(MAP_TITLE, 0);
235
 
243
 
236
-    // TODO paging when more options added
244
+    // TODO paging when more options added?!
237
     static_assert(CONF_ENTRY_COUNT <= 7, "too many conf menu entries");
245
     static_assert(CONF_ENTRY_COUNT <= 7, "too many conf menu entries");
238
-    uint8_t off = (10 - CONF_ENTRY_COUNT) / 2;
246
+    uint8_t off = ((10 - CONF_ENTRY_COUNT) / 2) + 3;
239
 
247
 
240
     str_center(get_string(STR_CONF_MENU), 0, 0);
248
     str_center(get_string(STR_CONF_MENU), 0, 0);
241
 
249
 
242
     for (uint8_t i = 0; (i < CONF_ENTRY_COUNT) && (i < 7); i++) {
250
     for (uint8_t i = 0; (i < CONF_ENTRY_COUNT) && (i < 7); i++) {
251
+        if (!is_conf_hw(i)) {
252
+            continue;
253
+        }
254
+
243
         char name_buff[ENTRY_NAME_LEN + 2 + 1] = {0};
255
         char name_buff[ENTRY_NAME_LEN + 2 + 1] = {0};
244
         uint8_t n_len = get_conf(name_buff, i);
256
         uint8_t n_len = get_conf(name_buff, i);
245
-        str(name_buff, (TEXT_LINE_WIDTH - n_len) * 2, (i * 2) + 3 + off, (debug_menu_index == i) ? 1 : 0);
257
+        str(name_buff, (TEXT_LINE_WIDTH - n_len) * 2, off, (debug_menu_index == i) ? 1 : 0);
258
+
259
+        off += 2;
246
     }
260
     }
247
 }
261
 }
248
 
262
 
272
         is_black = 1;
286
         is_black = 1;
273
     }
287
     }
274
 
288
 
289
+    // TODO support one debug value on DMG
275
     if ((_cpu == CGB_TYPE)
290
     if ((_cpu == CGB_TYPE)
276
-            && (conf_get()->debug_flags & (DBG_SHOW_FRAMES | DBG_SHOW_TIMER | DBG_SHOW_STACK))) {
291
+            && (conf_get()->debug_flags & DBG_OUT_ON)) {
277
         static int32_t prev_score = 0;
292
         static int32_t prev_score = 0;
278
         if (initial || (score != prev_score)) {
293
         if (initial || (score != prev_score)) {
279
             prev_score = score;
294
             prev_score = score;
285
         uint8_t x_off = number(score, 0, 0, is_black) >> 3;
300
         uint8_t x_off = number(score, 0, 0, is_black) >> 3;
286
         uint8_t y_off = 0;
301
         uint8_t y_off = 0;
287
 
302
 
303
+        // TODO only re-draw when value has changed!
304
+
305
+        if (conf_get()->debug_flags & DBG_SHOW_FPS) {
306
+            sprintf(str_buff, get_string(STR_PRINTF_FPS), (uint8_t)game_get_fps());
307
+            str_ascii(str_buff, x_off, y_off, 1);
308
+            y_off++;
309
+        }
310
+
288
         if (conf_get()->debug_flags & DBG_SHOW_FRAMES) {
311
         if (conf_get()->debug_flags & DBG_SHOW_FRAMES) {
289
             sprintf(str_buff, get_string(STR_PRINTF_FRAMES), (uint16_t)game_get_framecount());
312
             sprintf(str_buff, get_string(STR_PRINTF_FRAMES), (uint16_t)game_get_framecount());
290
             str_ascii(str_buff, x_off, y_off, 1);
313
             str_ascii(str_buff, x_off, y_off, 1);

+ 18
- 0
util/palette.py View File

1
+#!/usr/bin/env python3
2
+
3
+colors = [
4
+#    (8, 24, 32),
5
+#    (52, 104, 86),
6
+#    (136, 192, 112),
7
+#    (224, 248, 208),
8
+    (15, 56, 15),
9
+    (48, 98, 48),
10
+    (139, 172, 15),
11
+    (155, 188, 15),
12
+]
13
+
14
+def convert(c):
15
+    return (round(c[0] / 8), round(c[1] / 4), round(c[2]/ 8))
16
+
17
+for c in colors:
18
+    print(f"{c} -> {convert(c)}")

Loading…
Cancel
Save