From 6bef2b58f285df0ea59bdee3abd2eaf40d0a869d Mon Sep 17 00:00:00 2001 From: Remnants of Forgotten Disney Date: Wed, 27 Mar 2024 12:04:18 -0500 Subject: [PATCH] Reworking global frames --- include/debug_mode.h | 6 +++--- include/global_frame_controller.h | 8 +++++++ include/global_frame_counter.h | 9 -------- include/main_menu.h | 2 ++ include/sprite_data.h | 3 ++- source/gameboy_colour.cpp | 4 ++-- source/global_frame_controller.cpp | 28 ++++++++++++++++++++++++ source/global_frame_counter.cpp | 11 ---------- source/main.cpp | 34 +++++++----------------------- source/main_menu.cpp | 20 ++++++++++++++++-- source/pokedex.cpp | 2 +- source/sprite_data.cpp | 2 -- 12 files changed, 72 insertions(+), 57 deletions(-) create mode 100644 include/global_frame_controller.h delete mode 100644 include/global_frame_counter.h create mode 100644 source/global_frame_controller.cpp delete mode 100644 source/global_frame_counter.cpp diff --git a/include/debug_mode.h b/include/debug_mode.h index 5430df2..9439113 100644 --- a/include/debug_mode.h +++ b/include/debug_mode.h @@ -1,9 +1,9 @@ #ifndef DEBUG_MODE_H #define DEBUG_MODE_H -#define DEBUG_MODE true -#define IGNORE_GAME_PAK false -#define IGNORE_LINK_CABLE false +#define DEBUG_MODE false +#define IGNORE_GAME_PAK true +#define IGNORE_LINK_CABLE true #define IGNORE_MG_E4_FLAGS true #define DEBUG_GAME RUBY_ID diff --git a/include/global_frame_controller.h b/include/global_frame_controller.h new file mode 100644 index 0000000..262efb3 --- /dev/null +++ b/include/global_frame_controller.h @@ -0,0 +1,8 @@ +#ifndef GLOBAL_FRAME_CONTROLLER_H +#define GLOBAL_FRAME_CONTROLLER_H + +void global_next_frame(); +int get_frame_count(); + + +#endif diff --git a/include/global_frame_counter.h b/include/global_frame_counter.h deleted file mode 100644 index 6a34a07..0000000 --- a/include/global_frame_counter.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef GLOBAL_FRAME_COUNTER_H -#define GLOBAL_FRAME_COUNTER_H - - -void global_next_frame(); -int get_frame_count(); - -#endif - diff --git a/include/main_menu.h b/include/main_menu.h index 128ced8..8ac3e1f 100644 --- a/include/main_menu.h +++ b/include/main_menu.h @@ -32,6 +32,8 @@ void main_menu_enter(); void main_menu_exit(); void show_lang_btns(); void hide_lang_btns(); +void show_main_btns(); +void hide_main_btns(); void highlight_lang_btn(int index, bool highlight); void set_arrow_point(int index); diff --git a/include/sprite_data.h b/include/sprite_data.h index d0b3cef..5dc05e7 100644 --- a/include/sprite_data.h +++ b/include/sprite_data.h @@ -47,4 +47,5 @@ void load_btn_lang_ita(); void load_btn_lang_ger(); void load_btn_lang_spa(); void load_btn_lang_kor(); -void load_lang_arrow(); \ No newline at end of file +void load_lang_arrow(); +#define NUM_SPRITES 35 \ No newline at end of file diff --git a/source/gameboy_colour.cpp b/source/gameboy_colour.cpp index 91c41e6..07fa27c 100644 --- a/source/gameboy_colour.cpp +++ b/source/gameboy_colour.cpp @@ -11,6 +11,7 @@ #include "payload.h" #include "interrupt.h" #include "text_engine.h" +#include "global_frame_controller.h" #define TIMEOUT 2 #define TIMEOUT_ONE_LENGTH 1000000 // Maybe keep a 10:1 ratio between ONE and TWO? @@ -233,8 +234,7 @@ int loop(byte *box_data_storage) counter++; for (int i = 0; i < mosi_delay; i++) { - key_poll(); - VBlankIntrWait(); + global_next_frame(); } if (counter > (60 * 10)) diff --git a/source/global_frame_controller.cpp b/source/global_frame_controller.cpp new file mode 100644 index 0000000..724f286 --- /dev/null +++ b/source/global_frame_controller.cpp @@ -0,0 +1,28 @@ +#include + +#include "global_frame_controller.h" +#include "random.h" +#include "background_engine.h" +#include "text_engine.h" +#include "sprite_data.h" + +int global_frame_count = 0; + +void global_next_frame() +{ + key_poll(); + rand_next_frame(); + // tte_set_pos(0, 0); + // tte_write(std::to_string(get_rand_u32()).c_str()); + background_frame(); + text_next_frame(); + oam_copy(oam_mem, obj_buffer, NUM_SPRITES); + VBlankIntrWait(); + // mmFrame(); //Music + global_frame_count++; +}; + +int get_frame_count() +{ + return global_frame_count; +} \ No newline at end of file diff --git a/source/global_frame_counter.cpp b/source/global_frame_counter.cpp deleted file mode 100644 index f58bd91..0000000 --- a/source/global_frame_counter.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include "global_frame_counter.h" - -int global_frame_count = 0; - -void global_next_frame(){ - global_frame_count++; -} - -int get_frame_count(){ - return global_frame_count; -} \ No newline at end of file diff --git a/source/main.cpp b/source/main.cpp index 2c83653..06e6d0a 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -21,7 +21,7 @@ #include "soundbank_bin.h" #include "dex_handler.h" #include "pokedex.h" -#include "global_frame_counter.h" +#include "global_frame_controller.h" #include "pkmn_font.h" #include "save_data_manager.h" #include "mystery_gift_injector.h" @@ -178,8 +178,7 @@ void game_load_error(void) key_poll(); while (!key_hit(KEY_A)) { - key_poll(); - VBlankIntrWait(); + global_next_frame(); } tte_erase_screen(); delay_counter = 0; @@ -187,7 +186,7 @@ void game_load_error(void) while (delay_counter < 60) { delay_counter++; - VBlankIntrWait(); + global_next_frame(); } } @@ -196,11 +195,9 @@ void first_load_message(void) tte_set_pos(8, 0); tte_set_ink(10); tte_write("#{cx:0xE000}Hello! Thank you for using\nPok@ Transporter GB!\n\nJust as a word of caution- \nPok@ Transporter GB WILL modify\nyour generation 3 save file.\nThe program is designed to\nnot corrupt anything, but if\nyou do not wish to modify\nyour save file, please turn\noff your Game Boy Advance.\n\nPlease note that Pok@mon\nMirror is still in beta, so\nsave file backups are HIGHLY\nrecommended before using.\nWith that all out of the\nway, please enjoy!\n\n -The Gears of Progress"); - key_poll(); while (!key_hit(KEY_A)) { - key_poll(); - VBlankIntrWait(); + global_next_frame(); } tte_erase_rect(0, 0, H_MAX, V_MAX); } @@ -233,16 +230,13 @@ int main(void) tte_write("#{cx:0xF000}"); // Set the color to grey while (delay_counter < (15 * 60)) { + global_next_frame(); delay_counter++; - rand_next_frame(); - key_poll(); if (key_hit(KEY_A)) { delay_counter = (15 * 60); } - VBlankIntrWait(); } - key_poll(); // Gears of Progress tte_erase_rect(0, 0, 240, 160); @@ -250,20 +244,19 @@ int main(void) delay_counter = 0; while (delay_counter < (15 * 60)) { + global_next_frame(); delay_counter++; - rand_next_frame(); - key_poll(); if (key_hit(KEY_A)) { delay_counter = (15 * 60); } - VBlankIntrWait(); } - key_poll(); REG_BG1CNT = REG_BG1CNT | BG_PRIO(3); // Set up blend to fade to white/black + global_next_frame(); + show_main_btns(); int curr_lang_btn_num = get_def_lang_num(); int old_lang_btn_num = -1; set_arrow_point(curr_lang_btn_num); @@ -378,17 +371,6 @@ int main(void) } break; } - - key_poll(); - rand_next_frame(); - tte_set_pos(0, 0); - // tte_write(std::to_string(get_rand_u32()).c_str()); - background_frame(); - text_next_frame(); - oam_copy(oam_mem, obj_buffer, 35); - - VBlankIntrWait(); - // mmFrame(); //Music global_next_frame(); } } \ No newline at end of file diff --git a/source/main_menu.cpp b/source/main_menu.cpp index b534123..2e13756 100644 --- a/source/main_menu.cpp +++ b/source/main_menu.cpp @@ -3,7 +3,7 @@ #include "button_handler.h" #include "save_data_manager.h" -#define MAX_X_CORD 72 //128 +#define MAX_X_CORD 72 // 128 int menu_slot = 1; int old_menu_slot = 0; @@ -22,7 +22,7 @@ void main_menu_btn_init(Button nButton, int index) { wide_button_array[index] = nButton; wide_button_array[index].set_location(MAX_X_CORD, 7 + (38 * (index - 1))); - wide_button_array[index].show(); + wide_button_array[index].hide(); } else { @@ -134,6 +134,22 @@ void hide_lang_btns() } } +void show_main_btns() +{ + for (int i = 0; i < WIDE_BUTTON_ARRAY_SIZE; i++) + { + wide_button_array[i].show(); + } +} + +void hide_main_btns() +{ + for (int i = 0; i < WIDE_BUTTON_ARRAY_SIZE; i++) + { + wide_button_array[i].hide(); + } +} + void highlight_lang_btn(int index, bool highlight) { lang_button_array[index].set_highlight(highlight); diff --git a/source/pokedex.cpp b/source/pokedex.cpp index 853e6ed..22fdd10 100644 --- a/source/pokedex.cpp +++ b/source/pokedex.cpp @@ -6,7 +6,7 @@ #include "dex_handler.h" #include "sprite_data.h" #include "pokemon_data.h" -#include "global_frame_counter.h" +#include "global_frame_controller.h" #include "save_data_manager.h" Dex dex_array[DEX_MAX]; diff --git a/source/sprite_data.cpp b/source/sprite_data.cpp index de74149..10225a2 100644 --- a/source/sprite_data.cpp +++ b/source/sprite_data.cpp @@ -480,5 +480,3 @@ void load_lang_arrow() // obj_unhide(lang_arrow, 0); } - -// Don't forget to increase the number of sprites loaded in main!! \ No newline at end of file