diff --git a/.clang-format b/.clang-format index 01aed9a..b8dbeef 100644 --- a/.clang-format +++ b/.clang-format @@ -1,6 +1,11 @@ +BasedOnStyle: LLVM # Make the defaults explicit instead of implicit IndentWidth: 4 TabWidth: 4 UseTab: Never ContinuationIndentWidth: 4 +ColumnLimit: 100 # Applies to code and comments alike +ReflowComments: true # Wrap comments that go past ColumnLimit +SortIncludes: CaseSensitive # Sort includes within each block +IncludeBlocks: Preserve # Blank lines separate blocks; order across blocks is kept AlignAfterOpenBracket: DontAlign # Ensure a tabulation first inside a bracket BreakBeforeBraces: Allman # Ensure opening bracket goes to newline for a statement diff --git a/Dockerfile b/Dockerfile index 2fdec8b..8496459 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,7 +13,7 @@ RUN useradd -m -u ${UID} -g ${GID} ${USER} ENV DEBIAN_FRONTEND="noninteractive" ENV IS_PTGB=true -RUN apt-get update && apt-get install -y sudo build-essential cmake bison flex pkg-config libpng-dev git python3-pip jq && pip install --root-user-action=ignore pandas requests openpyxl debugpy pypng --break-system-packages +RUN apt-get update && apt-get install -y sudo build-essential cmake bison flex pkg-config libpng-dev git python3-pip jq clang-format-19 && pip install --root-user-action=ignore pandas requests openpyxl debugpy pypng --break-system-packages RUN echo "${USER} ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/${USER} && chmod 0440 /etc/sudoers.d/${USER} diff --git a/Makefile b/Makefile index a11c8a3..a9f77d3 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,7 @@ help: # Display this help message @tabs 2 @printf "\033[1;4mTargets\033[0m\n" # shows help for all targets that follow the format of "target: #", where target includes a-z, A-Z, 0-9, and _ characters - @grep -E '^[a-zA-Z0-9_]+: #' Makefile | while read -r l; do printf "\t\033[1;32m$$(echo $$l | cut -f 1 -d':')\033[00m:$$(echo $$l | cut -f 2- -d'#')\n"; done + @grep -E '^[a-zA-Z0-9_-]+: #' Makefile | while read -r l; do printf "\t\033[1;32m$$(echo $$l | cut -f 1 -d':')\033[00m:$$(echo $$l | cut -f 2- -d'#')\n"; done # if [ $(id | grep -c docker) = 0 ]; then # $1 = command name @@ -124,6 +124,22 @@ _setup: # jq $(call check_package,jq,jq) +# Install the formatter in existing containers as well as new images. + if ! command -v clang-format-19 >/dev/null 2>&1; then + sudo apt-get update && sudo apt-get install -y clang-format-19 || exit $$? + fi + +.PHONY: format check-format +format: FORMAT_FLAGS := -i +check-format: FORMAT_FLAGS := --dry-run --Werror +format: # Format only PTGB source and include folders +check-format: # Check only PTGB formatting without changing files +format check-format: + @find source include \ + -type f \( -name '*.c' -o -name '*.cc' -o -name '*.cpp' -o -name '*.cxx' \ + -o -name '*.h' -o -name '*.hh' -o -name '*.hpp' -o -name '*.hxx' \) -print0 | \ + xargs -0 -r clang-format-19 --style=file --fallback-style=none $(FORMAT_FLAGS) + # $1 = command name # $2 = package name define check_package_host @@ -249,7 +265,7 @@ configure: # Specify ROM Language, ROM Type, and Text Source --arg type "$$TYPE" \ --arg xlsx "$$XLSX" \ '.selected.lang = $$lang | .selected.type = $$type | .selected.xlsx = $$xlsx' \ - $(SRCDIR)/options.json > "$$tmp" && mv "$$tmp" $(SRCDIR)/options.json + $(SRCDIR)/options.json > "$$tmp" && mv "$$tmp" $(SRCDIR)/options.json @printf "\033[1;32mBuild configured!\033[0m\n" @@ -279,4 +295,4 @@ build_no_docker: source $(SRCDIR)/.venv/bin/activate fi @echo "Building..." - make -f $(SRCDIR)/container.mk all SRCDIR="$(SRCDIR)" + make -f $(SRCDIR)/container.mk all SRCDIR="$(SRCDIR)" diff --git a/PCCS b/PCCS index 9cd6bc9..73d1857 160000 --- a/PCCS +++ b/PCCS @@ -1 +1 @@ -Subproject commit 9cd6bc9bd1250013ceb1b1a70d96569985a87543 +Subproject commit 73d1857c5991f4da9308a9b7ff2e6869840af6b0 diff --git a/include/FileContainerReader.h b/include/FileContainerReader.h index 2515fcf..62e75d6 100644 --- a/include/FileContainerReader.h +++ b/include/FileContainerReader.h @@ -7,43 +7,38 @@ #define DEFAULT_CHUNK_SIZE 2048 /** - * @brief This class provides functionality to read files from the file - * container format created by the make-file-container tool. + * @brief This class provides functionality to read files from the file container format + * created by the make-file-container tool. * * This format consists of multiple compressed chunks. * - * It is done this way to keep the decompression buffer small (because we can't - * afford to consume too much IWRAM) but still allow for large file containers - * and bundling files together. (which you might want to do to improve - * compression ratios) The chunk size can be configured when creating the file - * container, and the FileContainerReader will read and decompress chunks on - * demand when seeking or reading data. + * It is done this way to keep the decompression buffer small (because we can't afford to consume + * too much IWRAM) but still allow for large file containers and bundling files together. (which you + * might want to do to improve compression ratios) The chunk size can be configured when creating + * the file container, and the FileContainerReader will read and decompress chunks on demand when + * seeking or reading data. */ class FileContainerReader { public: - FileContainerReader(const u8 **chunkList, u32 chunkCount, - u32 chunkSize = DEFAULT_CHUNK_SIZE); + FileContainerReader(const u8 **chunkList, u32 chunkCount, u32 chunkSize = DEFAULT_CHUNK_SIZE); ~FileContainerReader(); /** - * @brief This function initializes the FileContainerReader. It should be - * called before any other function is used. The reason for this - * initialization step is to give you control over the moment when the first - * chunk is decompressed. This can be useful if you want to perform some - * setup or checks before the decompression process begins. By calling - * init() explicitly, you can ensure that the FileContainerReader is ready - * to handle file reading operations at the appropriate time in your - * application. + * @brief This function initializes the FileContainerReader. It should be called before any + * other function is used. The reason for this initialization step is to give you control over + * the moment when the first chunk is decompressed. This can be useful if you want to perform + * some setup or checks before the decompression process begins. By calling init() explicitly, + * you can ensure that the FileContainerReader is ready to handle file reading operations at the + * appropriate time in your application. * * Note: because of this, we also only pass the decompression buffer here * If the decompression buffer is not large enough to hold the chunks, - * the function will return false and the FileContainerReader will not be - * initialized. In this case, you should provide a larger decompression - * buffer and call init() again. + * the function will return false and the FileContainerReader will not be initialized. In this + * case, you should provide a larger decompression buffer and call init() again. * - * If it DOES return true, please note that the FileContainerReader will - * keep using the decompressionBuffer_ until it gets destroyed. + * If it DOES return true, please note that the FileContainerReader will keep using the + * decompressionBuffer_ until it gets destroyed. */ bool init(u8 *decompressionBuffer, u32 decompressionBufferSize); @@ -54,8 +49,8 @@ class FileContainerReader /** * @brief IF the file container stores the file names, - * this function returns a pointer to the file name of the file at the given - * index. Otherwise, it returns nullptr. + * this function returns a pointer to the file name of the file at the given index. + * Otherwise, it returns nullptr. */ const char *getFileName(u32 fileIndex); @@ -65,33 +60,29 @@ class FileContainerReader u32 getFileSize(u32 fileIndex) const; /** - * @brief This function seeks to the beginning of the file at the given - * index. + * @brief This function seeks to the beginning of the file at the given index. */ void seekToFile(u32 fileIndex); /** - * @brief Read data from the current position in the file container into the - * provided buffer. + * @brief Read data from the current position in the file container into the provided buffer. */ void read(u8 *buffer, u32 size); /** - * @brief Gives you a direct pointer to the specified file in the - * decompression buffer. (unsafe!) + * @brief Gives you a direct pointer to the specified file in the decompression buffer. + * (unsafe!) * - * This is useful to use data directly from the decompression buffer without - * having to allocate and copy another buffer. This is essential in high - * memory pressure scenarios, such as mystery_gift_builder. We can't afford - * to keep multiple linebuffers in memory in addition to the decompression - * buffer and all the other variables there. + * This is useful to use data directly from the decompression buffer without having to allocate + * and copy another buffer. This is essential in high memory pressure scenarios, such as + * mystery_gift_builder. We can't afford to keep multiple linebuffers in memory in addition to + * the decompression buffer and all the other variables there. * - * WARNING: this is only safe if you know the file is stored fully in the - * current chunk, because files may span multiple chunks. Or if the - * container only consists of a single chunk. Pointers acquired this way - * will become stale whenever a seek is done to a position in a different - * chunk, as that will cause the decompression buffer to be overwritten with - * the new chunk's data. + * WARNING: this is only safe if you know the file is stored fully in the current chunk, because + * files may span multiple chunks. Or if the container only consists of a single chunk. Pointers + * acquired this way will become stale whenever a seek is done to a position in a different + * chunk, as that will cause the decompression buffer to be overwritten with the new chunk's + * data. */ u8 *getPointerToFileInDecompressionBuffer(u32 fileIndex); @@ -102,9 +93,8 @@ class FileContainerReader void seekAndRead(u32 fileIndex, u8 *buffer, u32 size); /** - * @brief Even shorter variant of seekAndRead that reads the entire file at - * once. But it assumes you have provided a large enough buffer to hold the - * entire file. + * @brief Even shorter variant of seekAndRead that reads the entire file at once. + * But it assumes you have provided a large enough buffer to hold the entire file. * * (useful for text table reading) */ @@ -113,17 +103,16 @@ class FileContainerReader protected: private: /** - * @brief This function calculates the file offset for the specified file - * index The file offset is determined by reading the file index (which - * contains the file entry sizes) and summing up the sizes of all previous - * entries + header size + optional name table size (if names are stored). + * @brief This function calculates the file offset for the specified file index + * The file offset is determined by reading the file index (which contains the file entry sizes) + * and summing up the sizes of all previous entries + header size + optional name table size + * (if names are stored). */ u32 getFileOffset(u32 fileIndex) const; /** - * @brief This function seeks to the specified absolute offset in the file - * container data. Absolute offset refers to an offset across the file - * container chunks. + * @brief This function seeks to the specified absolute offset in the file container data. + * Absolute offset refers to an offset across the file container chunks. */ void seek(u32 offset); diff --git a/include/Gen3CartridgeSaveReader.h b/include/Gen3CartridgeSaveReader.h index 8c198a1..abe6596 100644 --- a/include/Gen3CartridgeSaveReader.h +++ b/include/Gen3CartridgeSaveReader.h @@ -8,15 +8,14 @@ * @brief This class is an adapter implementation for Gen3SaveManager, * which is used by libPCCS' Gen3SaveManager class. * - * This specific implementation will allow read/write operations to the - * cartridge save. That way, actual data origin is abstracted away from libPCCS' - * Gen3SaveManager. + * This specific implementation will allow read/write operations to the cartridge save. + * That way, actual data origin is abstracted away from libPCCS' Gen3SaveManager. * - * Note: to avoid runtime bounds-checking overhead, we assume that the caller - * takes care not to cross sector boundaries with its read/write operations. + * Note: to avoid runtime bounds-checking overhead, we assume that the caller takes care + * not to cross sector boundaries with its read/write operations. * - * When moving to a different sector with seek(), flush() will get called if - * there are pending changes in the current buffer. + * When moving to a different sector with seek(), flush() will get called if there are pending + * changes in the current buffer. * * Note: this class won't automatically load any sector when initialized. * Make sure to trigger seek() before doing anything with it. @@ -39,8 +38,8 @@ class Gen3CartridgeSaveReader void seek(u32 offset); - // WARNING: advance and rewind won't cross sector boundaries, so make sure - // to trigger seek() if you want to move to a different sector. + // WARNING: advance and rewind won't cross sector boundaries, so make sure to trigger seek() + // if you want to move to a different sector. void advance(u32 numBytes); void rewind(u32 numBytes); @@ -50,8 +49,8 @@ class Gen3CartridgeSaveReader void flush(); /** - * @brief Indicates whether the Gen3SaveManager should recalculate checksums - * when finishSave is called. + * @brief Indicates whether the Gen3SaveManager should recalculate checksums when finishSave is + * called. */ bool shouldRecalculateChecksumsOnFinish() const; diff --git a/include/background_engine.h b/include/background_engine.h index dd07854..febf3eb 100644 --- a/include/background_engine.h +++ b/include/background_engine.h @@ -15,10 +15,10 @@ void background_frame(int global_frame_count); /** - * @brief This function draws the textbox (=copies the tiles) for a specific - * text table and text key. Each text table entry could have a different type of - * textbox associated with it. This function will look up the textbox type for - * the given text table and text key, and then draw the textbox accordingly. + * @brief This function draws the textbox (=copies the tiles) for a specific text table and text + * key. Each text table entry could have a different type of textbox associated with it. This + * function will look up the textbox type for the given text table and text key, and then draw the + * textbox accordingly. */ void create_textbox(int text_section, int text_key, bool eraseMainBox); @@ -28,13 +28,12 @@ void create_textbox(int text_section, int text_key, bool eraseMainBox); void create_textbox(u8 textbox_type, bool eraseMainBox); /** - * @brief This function draws a textbox at the specified tile coordinates, with - * the specified text space dimensions. This is the most low-level version of - * the create_textbox function, and it doesn't do any lookup for textbox types. - * It just draws a textbox with the given parameters. + * @brief This function draws a textbox at the specified tile coordinates, with the specified text + * space dimensions. This is the most low-level version of the create_textbox function, and it + * doesn't do any lookup for textbox types. It just draws a textbox with the given parameters. */ -void create_textbox(int startTileX, int startTileY, int text_space_width, - int text_space_height, bool eraseMainBox); +void create_textbox( + int startTileX, int startTileY, int text_space_width, int text_space_height, bool eraseMainBox); void show_textbox(); void hide_textbox(); #endif \ No newline at end of file diff --git a/include/box_menu.h b/include/box_menu.h index da7bc4e..649a4d3 100644 --- a/include/box_menu.h +++ b/include/box_menu.h @@ -10,8 +10,7 @@ #define CANCEL_BUTTON 1 #define CONFIRM_BUTTON 2 -// Box is 144 x 104, top left is 88 32, sprite is 16x16, sprites are not -// centered +// Box is 144 x 104, top left is 88 32, sprite is 16x16, sprites are not centered #define BOXMENU_TOP (32 - 12) #define BOXMENU_LEFT 88 #define BOXMENU_VSPACE -4 diff --git a/include/button_menu.h b/include/button_menu.h index 275c785..82dffcf 100644 --- a/include/button_menu.h +++ b/include/button_menu.h @@ -20,8 +20,7 @@ class Button_Menu { public: - Button_Menu(int nRows, int nColumns, int nButton_width, int nButton_height, - bool enable_cancel); + Button_Menu(int nRows, int nColumns, int nButton_width, int nButton_height, bool enable_cancel); int button_main(); void add_button(Button btn, int return_val); void hide_buttons(); diff --git a/include/custom_malloc.h b/include/custom_malloc.h index 5ae0477..45956e1 100644 --- a/include/custom_malloc.h +++ b/include/custom_malloc.h @@ -10,10 +10,9 @@ extern "C" #include #include - /// malloc.c defines a custom bitmap allocator implementation that replaces - /// newlibs' if the USE_CUSTOM_MALLOC flag is set. That makes sure the - /// linker won't pull in all the malloc related code in newlibc (alongside - /// the 1KB IWRAM __malloc_av variable) + /// malloc.c defines a custom bitmap allocator implementation that replaces newlibs' + /// if the USE_CUSTOM_MALLOC flag is set. That makes sure the linker won't pull in all the + /// malloc related code in newlibc (alongside the 1KB IWRAM __malloc_av variable) void malloc_init_default_pool(void); diff --git a/include/dbg/debug_menu.h b/include/dbg/debug_menu.h index ffaa49d..5e3b55d 100644 --- a/include/dbg/debug_menu.h +++ b/include/dbg/debug_menu.h @@ -14,8 +14,8 @@ typedef void (*on_execute_callback)(void *context, unsigned user_param); /** - * @brief This struct represents the metadata associated to a single toggle - * option of a single row in the debug menu. + * @brief This struct represents the metadata associated to a single toggle option of a single row + * in the debug menu. */ typedef struct option_data { @@ -24,8 +24,8 @@ typedef struct option_data } option_data; /** - * @brief This struct represents a single row in the debug menu. Each row has a - * label and a set of options. + * @brief This struct represents a single row in the debug menu. Each row has a label and a set of + * options. * */ typedef struct debug_menu_row_data @@ -45,68 +45,65 @@ typedef struct debug_menu_row_data struct { /** - * @brief Number of options. If this is 0, then this row will just be a - * label with no options to select. + * @brief Number of options. If this is 0, then this row will just be a label with no + * options to select. */ u8 num_options; /** * @brief The actual array of options alongside their values. - * Note: if you want the widget to free() the array when the widget is - * getting destroyed, set the should_free_on_destruct flag. + * Note: if you want the widget to free() the array when the widget is getting destroyed, + * set the should_free_on_destruct flag. */ const option_data *options; /** - * @brief This callback will be fired when the user selects an option. - * (just with LEFT/RIGHT) + * @brief This callback will be fired when the user selects an option. (just with + * LEFT/RIGHT) */ on_execute_callback on_option_activate; /** * @brief The initial selected option index. - * But this field will get maintained by the widget to track the current - * selected index. + * But this field will get maintained by the widget to track the current selected index. */ u8 selected_option_index; /** - * @brief This flag indicates whether the widget should call free() on - * the options pointer when the widget is getting destroyed. + * @brief This flag indicates whether the widget should call free() on the options pointer + * when the widget is getting destroyed. */ bool should_free_on_destruct; } option_section; /** - * @brief A callback that you can set to execute when the user selects this - * row and presses the A button. (optional) + * @brief A callback that you can set to execute when the user selects this row and presses the + * A button. (optional) */ on_execute_callback on_execute; /** - * @brief Context for the on_option-activate and on_execute callbacks. - * (optional) + * @brief Context for the on_option-activate and on_execute callbacks. (optional) */ void *context; /** - * @brief This user_param will be passed as an argument to the on_execute - * callback. (optional) + * @brief This user_param will be passed as an argument to the on_execute callback. (optional) */ unsigned user_param; } debug_menu_row_data; /** - * @brief This class is responsible for rendering and handling input for a - * single row in the vertical_menu based debug menu. + * @brief This class is responsible for rendering and handling input for a single row in the + * vertical_menu based debug menu. */ class debug_menu_row_widget : public i_item_widget { public: debug_menu_row_widget(const debug_menu_row_data &data); virtual ~debug_menu_row_widget(); - void render_item(FileContainerReader &text_table, unsigned x, unsigned y, - bool is_focused) override; + void render_item( + FileContainerReader &text_table, unsigned x, unsigned y, bool is_focused) override; MenuInputHandleState handle_input() override; protected: diff --git a/include/dbg/debug_menu_entries.h b/include/dbg/debug_menu_entries.h index a069854..3bb9822 100644 --- a/include/dbg/debug_menu_entries.h +++ b/include/dbg/debug_menu_entries.h @@ -12,8 +12,7 @@ enum class DebugMenuSection }; /** - * @brief This function pointer is used to define a function filling a specifi - * DebugMenuSection + * @brief This function pointer is used to define a function filling a specifi DebugMenuSection */ typedef void (*fill_menu_entries_func)(vertical_menu &menu, u16 *charset); @@ -24,10 +23,9 @@ typedef struct MenuSectionMapEntry } MenuSectionMapEntry; /** - * @brief This function constructs the actual debug menu entries and fills the - * provided menu with them. + * @brief This function constructs the actual debug menu entries and fills the provided menu with + * them. */ -void fill_debug_menu_with_entries( - vertical_menu &menu, u16 *charset, DebugMenuSection section); +void fill_debug_menu_with_entries(vertical_menu &menu, u16 *charset, DebugMenuSection section); #endif \ No newline at end of file diff --git a/include/dbg/debug_menu_functions.h b/include/dbg/debug_menu_functions.h index c1c6275..6502b00 100644 --- a/include/dbg/debug_menu_functions.h +++ b/include/dbg/debug_menu_functions.h @@ -1,14 +1,13 @@ #ifndef _DEBUG_MENU_FUNCTIONS_H #define _DEBUG_MENU_FUNCTIONS_H -// Here we define debug menu callback functions, to be used as -// on_execute_callback or on_option_activate in the debug menu entries. +// Here we define debug menu callback functions, to be used as on_execute_callback or +// on_option_activate in the debug menu entries. /** * @brief Shows a submenu * - * @param user_param the DebugMenuSection enum value corresponding to the - * submenu to show. + * @param user_param the DebugMenuSection enum value corresponding to the submenu to show. */ void show_debug_menu_section(void *context, unsigned user_param); @@ -18,8 +17,8 @@ void show_debug_menu_section(void *context, unsigned user_param); void show_text_debug_screen(void *context, unsigned user_param); /** - * @brief This function will show the debug info screen, which contains various - * flags and info about the current game state. + * @brief This function will show the debug info screen, which contains various flags and info about + * the current game state. */ void show_debug_info_screen(void *context, unsigned user_param); @@ -27,8 +26,7 @@ void show_debug_info_screen(void *context, unsigned user_param); * @brief This is a generic u8/bool value set callback * * @param context a (u8* or bool*) pointer to the flag you want to set/unset. - * @param user_param the value to set the flag to. 0 -> false, anything else -> - * true. + * @param user_param the value to set the flag to. 0 -> false, anything else -> true. */ void dbg_set_byte_val(void *context, unsigned user_param); diff --git a/include/dbg/debug_mode.h b/include/dbg/debug_mode.h index 61ed133..9bc4fe2 100644 --- a/include/dbg/debug_mode.h +++ b/include/dbg/debug_mode.h @@ -28,105 +28,97 @@ enum WriteCableDataMode */ typedef struct debug_options { - /** This option will print the link cable data. Pause the transfer with L, - * resume with R. Skip printing with DOWN. */ + /** This option will print the link cable data. Pause the transfer with L, resume with R. Skip + * printing with DOWN. */ bool print_link_data; - /** This option will print the link cable packets. Pause the transfer with - * L, resume with R. Skip printing with DOWN. */ + /** This option will print the link cable packets. Pause the transfer with L, resume with R. + * Skip printing with DOWN. */ bool print_link_packets; /** - * @brief If this option has been set, we won't animate the text, but show - * the full text immediately. + * @brief If this option has been set, we won't animate the text, but show the full text + * immediately. */ bool instant_text_speed; /** - * @brief If this option is set, we won't try to access a game cartridge. - * Instead, we'll pretend we're using a game cartridge with predefined data. - * (DEBUG_GAME, DEBUG_VERS, DEBUG_LANG) We won't show game sprites either. + * @brief If this option is set, we won't try to access a game cartridge. Instead, we'll pretend + * we're using a game cartridge with predefined data. (DEBUG_GAME, DEBUG_VERS, DEBUG_LANG) We + * won't show game sprites either. * - * This is useful for testing our code in an emulator or without a game - * cartridge. + * This is useful for testing our code in an emulator or without a game cartridge. */ bool ignore_game_pak; /** - * @brief If this option is set, we won't try to show sprites that are - * stored on the game cartridge. This is useful for testing our code in an - * emulator or without a game cartridge. + * @brief If this option is set, we won't try to show sprites that are stored on the game + * cartridge. This is useful for testing our code in an emulator or without a game cartridge. */ bool ignore_game_pak_sprites; /** * @brief If this flag is set, we won't actually do a link cable connection. - * Instead, we pretend the connection was successful and use - * gen1_rb_debug_box_data or gen2_debug_box_data. + * Instead, we pretend the connection was successful and use gen1_rb_debug_box_data or + * gen2_debug_box_data. */ bool ignore_link_cable; /** - * @brief If this option is set, we won't block the user from proceeding if - * he/she hasn't beat the E4 or hasn't activated Mystery Gift yet. This is - * mostly useful for debug purposes. + * @brief If this option is set, we won't block the user from proceeding if he/she hasn't beat + * the E4 or hasn't activated Mystery Gift yet. This is mostly useful for debug purposes. */ bool ignore_mg_e4_flags; /** - * @brief If this option is set, we won't block the transfer from finishing - * if the player hasn't collected the pokémon from previous transfers. - * Instead those will get overwritten. This does make you lose those - * pokémon. But it can be useful for debugging. (because you wouldn't need + * @brief If this option is set, we won't block the transfer from finishing if the player hasn't + * collected the pokémon from previous transfers. Instead those will get overwritten. This does + * make you lose those pokémon. But it can be useful for debugging. (because you wouldn't need * to boot into the game everytime between transfer attempts) */ bool ignore_unreceived_pkmn; /** - * @brief This option will make PTGB show the tutorial even if the tutorial - * completion flag was already set before. Useful for debugging purposes. + * @brief This option will make PTGB show the tutorial even if the tutorial completion flag was + * already set before. Useful for debugging purposes. */ bool force_tutorial; /** - * @brief This option will show the pokémon even if not a single one is - * valid. Once again, this can be useful for debugging purposes. + * @brief This option will show the pokémon even if not a single one is valid. + * Once again, this can be useful for debugging purposes. */ bool dont_hide_invalid_pkmn; /** - * @brief This option will avoid blocking the transfer if the player hasn't - * caught enough pokémon yet. + * @brief This option will avoid blocking the transfer if the player hasn't caught enough + * pokémon yet. */ bool ignore_dex_completion; /** - * @brief This option will pretend as if the player caught all pokémon. This - * is useful to get past the dex completion check + * @brief This option will pretend as if the player caught all pokémon. This is useful to get + * past the dex completion check */ bool force_all_caught; /** - * @brief If this option is set, we will write the data received over the - * link cable to SRAM. Please make sure to only use this with - * loader.gba/Poke_Transporter_GB_standalone.gba and make sure to - * ignore_game_pak and ignore_game_pak_sprites too! + * @brief If this option is set, we will write the data received over the link cable to SRAM. + * Please make sure to only use this with loader.gba/Poke_Transporter_GB_standalone.gba and + * make sure to ignore_game_pak and ignore_game_pak_sprites too! * - * Also: you may need to reboot to your flashcart menu to make it update the - * .sav file. + * Also: you may need to reboot to your flashcart menu to make it update the .sav file. */ u8 write_cable_data_to_save; /** - * @brief If this option is set, we will load the data -written by - * write_cable_data_to_save- from the SRAM instead of actually communicating - * over the link cable. + * @brief If this option is set, we will load the data -written by write_cable_data_to_save- + * from the SRAM instead of actually communicating over the link cable. */ u8 load_cable_data_from_save; /** - * @brief If this option is enabled, we will show control characters in the - * text. + * @brief If this option is enabled, we will show control characters in the text. */ bool display_control_char; } debug_options; @@ -158,13 +150,12 @@ extern debug_options g_debug_options; // needs to be a value divisible by 4 #define CUSTOM_MALLOC_POOL_SIZE 8192 -// This option enables PTGB_MGBA_XYZ() log messages. These get printed to the -// mgba log window. This option can only be enabled in debug builds because it -// relies on mgba_printf, which will only get included in debug builds for -// licensing reasons. Compiling with this option enabled in release builds will -// cause a static_assert failure. But the && DEBUG_MODE check will already -// prevent this from being enabled in release builds accidentally, so as long as -// no-one removes that, it should be fine. +// This option enables PTGB_MGBA_XYZ() log messages. These get printed to the mgba log window. +// This option can only be enabled in debug builds because it relies on mgba_printf, +// which will only get included in debug builds for licensing reasons. +// Compiling with this option enabled in release builds will cause a static_assert failure. +// But the && DEBUG_MODE check will already prevent this from being enabled in release builds +// accidentally, so as long as no-one removes that, it should be fine. #define DEBUG_USE_MGBA_PRINT (true && DEBUG_MODE) #endif \ No newline at end of file diff --git a/include/dbg/eon_ticket_rs.h b/include/dbg/eon_ticket_rs.h index 6067d16..efc7fbc 100644 --- a/include/dbg/eon_ticket_rs.h +++ b/include/dbg/eon_ticket_rs.h @@ -2,88 +2,67 @@ // array size is 1012 // Downloaded from the projectpokemon.org website -static const u8 RS_Item_Eon_Ticket_e_Card_ENG_US_[] = {0x10, 0xea, 0x00, 0x00, - 0x33, 0x08, 0x01, 0x01, 0xb8, 0x61, 0x00, 0x00, 0x02, 0x47, 0x13, 0x01, - 0x01, 0x00, 0x21, 0x0d, 0x80, 0x01, 0x00, 0xbb, 0x01, 0xbf, 0x00, 0x00, - 0x02, 0x4a, 0x13, 0x01, 0x01, 0x00, 0x21, 0x0d, 0x80, 0x01, 0x00, 0xbb, - 0x01, 0xbf, 0x00, 0x00, 0x02, 0x2b, 0xce, 0x00, 0xbb, 0x01, 0xbf, 0x00, - 0x00, 0x02, 0x6a, 0x5a, 0xbd, 0xc9, 0x00, 0x00, 0x02, 0x66, 0x6d, 0x46, - 0x13, 0x01, 0x01, 0x00, 0x21, 0x0d, 0x80, 0x00, 0x00, 0xbb, 0x01, 0xc0, - 0x00, 0x00, 0x02, 0x1a, 0x00, 0x80, 0x13, 0x01, 0x1a, 0x01, 0x80, 0x01, - 0x00, 0x09, 0x00, 0x29, 0x53, 0x08, 0xbd, 0x04, 0x01, 0x00, 0x02, 0x66, - 0x6d, 0x6c, 0x0d, 0xbd, 0x83, 0x01, 0x00, 0x02, 0x66, 0x6d, 0x6c, 0x02, - 0xbe, 0xbb, 0xbe, 0xb1, 0xfd, 0x01, 0xab, 0x00, 0xc1, 0xe3, 0xe3, 0xd8, - 0x00, 0xe8, 0xe3, 0x00, 0xe7, 0xd9, 0xd9, 0x00, 0xed, 0xe3, 0xe9, 0xab, - 0xfe, 0xce, 0xdc, 0xd9, 0xe6, 0xd9, 0xb4, 0xe7, 0x00, 0xd5, 0x00, 0xe0, - 0xd9, 0xe8, 0xe8, 0xd9, 0xe6, 0x00, 0xdc, 0xd9, 0xe6, 0xd9, 0x00, 0xda, - 0xe3, 0xe6, 0x00, 0xed, 0xe3, 0xe9, 0xb8, 0xfd, 0x01, 0xad, 0xff, 0xbe, - 0xbb, 0xbe, 0xb1, 0xc3, 0xe8, 0x00, 0xd5, 0xe4, 0xe4, 0xd9, 0xd5, 0xe6, - 0xe7, 0x00, 0xe8, 0xe3, 0x00, 0xd6, 0xd9, 0x00, 0xd5, 0x00, 0xda, 0xd9, - 0xe6, 0xe6, 0xed, 0x00, 0xce, 0xc3, 0xbd, 0xc5, 0xbf, 0xce, 0xad, 0xfe, - 0xd6, 0xe9, 0xe8, 0x00, 0xc3, 0xb4, 0xea, 0xd9, 0x00, 0xe2, 0xd9, 0xea, - 0xd9, 0xe6, 0x00, 0xe7, 0xd9, 0xd9, 0xe2, 0x00, 0xe3, 0xe2, 0xd9, 0x00, - 0xe0, 0xdd, 0xdf, 0xd9, 0x00, 0xdd, 0xe8, 0x00, 0xd6, 0xd9, 0xda, 0xe3, - 0xe6, 0xd9, 0xad, 0xfa, 0xd3, 0xe3, 0xe9, 0x00, 0xe7, 0xdc, 0xe3, 0xe9, - 0xe0, 0xd8, 0x00, 0xea, 0xdd, 0xe7, 0xdd, 0xe8, 0x00, 0xc6, 0xc3, 0xc6, - 0xd3, 0xbd, 0xc9, 0xd0, 0xbf, 0x00, 0xd5, 0xe2, 0xd8, 0x00, 0xd5, 0xe7, - 0xdf, 0xfe, 0xd5, 0xd6, 0xe3, 0xe9, 0xe8, 0x00, 0xdd, 0xe8, 0x00, 0xe8, - 0xdc, 0xd9, 0xe6, 0xd9, 0xad, 0xff, 0xbe, 0xbb, 0xbe, 0xb1, 0xfd, 0x01, - 0xb4, 0x00, 0xe8, 0xdc, 0xd9, 0x00, 0xc5, 0xbf, 0xd3, 0x00, 0xc3, 0xce, - 0xbf, 0xc7, 0xcd, 0x00, 0xca, 0xc9, 0xbd, 0xc5, 0xbf, 0xce, 0x00, 0xdd, - 0xe2, 0xfe, 0xed, 0xe3, 0xe9, 0xe6, 0x00, 0xbc, 0xbb, 0xc1, 0x00, 0xdd, - 0xe7, 0x00, 0xda, 0xe9, 0xe0, 0xe0, 0xad, 0xfb, 0xc7, 0xe3, 0xea, 0xd9, - 0x00, 0xe7, 0xe3, 0xe1, 0xd9, 0x00, 0xdf, 0xd9, 0xed, 0x00, 0xdd, 0xe8, - 0xd9, 0xe1, 0xe7, 0x00, 0xda, 0xe3, 0xe6, 0x00, 0xe7, 0xd5, 0xda, 0xd9, - 0xdf, 0xd9, 0xd9, 0xe4, 0xdd, 0xe2, 0xdb, 0xfe, 0xdd, 0xe2, 0x00, 0xed, - 0xe3, 0xe9, 0xe6, 0x00, 0xca, 0xbd, 0xb4, 0x00, 0xe8, 0xdc, 0xd9, 0xe2, - 0x00, 0xd7, 0xe3, 0xe1, 0xd9, 0x00, 0xe7, 0xd9, 0xd9, 0x00, 0xe1, 0xd9, - 0xad, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x33, 0x00, 0x00, 0x00, 0x01, 0x1e, 0x13, 0x01}; \ No newline at end of file +static const u8 RS_Item_Eon_Ticket_e_Card_ENG_US_[] = {0x10, 0xea, 0x00, 0x00, 0x33, 0x08, 0x01, + 0x01, 0xb8, 0x61, 0x00, 0x00, 0x02, 0x47, 0x13, 0x01, 0x01, 0x00, 0x21, 0x0d, 0x80, 0x01, 0x00, + 0xbb, 0x01, 0xbf, 0x00, 0x00, 0x02, 0x4a, 0x13, 0x01, 0x01, 0x00, 0x21, 0x0d, 0x80, 0x01, 0x00, + 0xbb, 0x01, 0xbf, 0x00, 0x00, 0x02, 0x2b, 0xce, 0x00, 0xbb, 0x01, 0xbf, 0x00, 0x00, 0x02, 0x6a, + 0x5a, 0xbd, 0xc9, 0x00, 0x00, 0x02, 0x66, 0x6d, 0x46, 0x13, 0x01, 0x01, 0x00, 0x21, 0x0d, 0x80, + 0x00, 0x00, 0xbb, 0x01, 0xc0, 0x00, 0x00, 0x02, 0x1a, 0x00, 0x80, 0x13, 0x01, 0x1a, 0x01, 0x80, + 0x01, 0x00, 0x09, 0x00, 0x29, 0x53, 0x08, 0xbd, 0x04, 0x01, 0x00, 0x02, 0x66, 0x6d, 0x6c, 0x0d, + 0xbd, 0x83, 0x01, 0x00, 0x02, 0x66, 0x6d, 0x6c, 0x02, 0xbe, 0xbb, 0xbe, 0xb1, 0xfd, 0x01, 0xab, + 0x00, 0xc1, 0xe3, 0xe3, 0xd8, 0x00, 0xe8, 0xe3, 0x00, 0xe7, 0xd9, 0xd9, 0x00, 0xed, 0xe3, 0xe9, + 0xab, 0xfe, 0xce, 0xdc, 0xd9, 0xe6, 0xd9, 0xb4, 0xe7, 0x00, 0xd5, 0x00, 0xe0, 0xd9, 0xe8, 0xe8, + 0xd9, 0xe6, 0x00, 0xdc, 0xd9, 0xe6, 0xd9, 0x00, 0xda, 0xe3, 0xe6, 0x00, 0xed, 0xe3, 0xe9, 0xb8, + 0xfd, 0x01, 0xad, 0xff, 0xbe, 0xbb, 0xbe, 0xb1, 0xc3, 0xe8, 0x00, 0xd5, 0xe4, 0xe4, 0xd9, 0xd5, + 0xe6, 0xe7, 0x00, 0xe8, 0xe3, 0x00, 0xd6, 0xd9, 0x00, 0xd5, 0x00, 0xda, 0xd9, 0xe6, 0xe6, 0xed, + 0x00, 0xce, 0xc3, 0xbd, 0xc5, 0xbf, 0xce, 0xad, 0xfe, 0xd6, 0xe9, 0xe8, 0x00, 0xc3, 0xb4, 0xea, + 0xd9, 0x00, 0xe2, 0xd9, 0xea, 0xd9, 0xe6, 0x00, 0xe7, 0xd9, 0xd9, 0xe2, 0x00, 0xe3, 0xe2, 0xd9, + 0x00, 0xe0, 0xdd, 0xdf, 0xd9, 0x00, 0xdd, 0xe8, 0x00, 0xd6, 0xd9, 0xda, 0xe3, 0xe6, 0xd9, 0xad, + 0xfa, 0xd3, 0xe3, 0xe9, 0x00, 0xe7, 0xdc, 0xe3, 0xe9, 0xe0, 0xd8, 0x00, 0xea, 0xdd, 0xe7, 0xdd, + 0xe8, 0x00, 0xc6, 0xc3, 0xc6, 0xd3, 0xbd, 0xc9, 0xd0, 0xbf, 0x00, 0xd5, 0xe2, 0xd8, 0x00, 0xd5, + 0xe7, 0xdf, 0xfe, 0xd5, 0xd6, 0xe3, 0xe9, 0xe8, 0x00, 0xdd, 0xe8, 0x00, 0xe8, 0xdc, 0xd9, 0xe6, + 0xd9, 0xad, 0xff, 0xbe, 0xbb, 0xbe, 0xb1, 0xfd, 0x01, 0xb4, 0x00, 0xe8, 0xdc, 0xd9, 0x00, 0xc5, + 0xbf, 0xd3, 0x00, 0xc3, 0xce, 0xbf, 0xc7, 0xcd, 0x00, 0xca, 0xc9, 0xbd, 0xc5, 0xbf, 0xce, 0x00, + 0xdd, 0xe2, 0xfe, 0xed, 0xe3, 0xe9, 0xe6, 0x00, 0xbc, 0xbb, 0xc1, 0x00, 0xdd, 0xe7, 0x00, 0xda, + 0xe9, 0xe0, 0xe0, 0xad, 0xfb, 0xc7, 0xe3, 0xea, 0xd9, 0x00, 0xe7, 0xe3, 0xe1, 0xd9, 0x00, 0xdf, + 0xd9, 0xed, 0x00, 0xdd, 0xe8, 0xd9, 0xe1, 0xe7, 0x00, 0xda, 0xe3, 0xe6, 0x00, 0xe7, 0xd5, 0xda, + 0xd9, 0xdf, 0xd9, 0xd9, 0xe4, 0xdd, 0xe2, 0xdb, 0xfe, 0xdd, 0xe2, 0x00, 0xed, 0xe3, 0xe9, 0xe6, + 0x00, 0xca, 0xbd, 0xb4, 0x00, 0xe8, 0xdc, 0xd9, 0xe2, 0x00, 0xd7, 0xe3, 0xe1, 0xd9, 0x00, 0xe7, + 0xd9, 0xd9, 0x00, 0xe1, 0xd9, 0xad, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x33, 0x00, 0x00, 0x00, 0x01, 0x1e, 0x13, 0x01}; \ No newline at end of file diff --git a/include/dbg/old_sea_map.h b/include/dbg/old_sea_map.h index 1d6f6d8..096956f 100644 --- a/include/dbg/old_sea_map.h +++ b/include/dbg/old_sea_map.h @@ -1,124 +1,94 @@ #include "typeDefs.h" // array size is 1420 -// Taken from WC3Tool 0.1f: -// https://github.com/projectpokemon/Gen3-WCTool/releases/tag/0.1f -static const u8 OldSeaMap_E_custom[] = {0xcf, 0xa6, 0x00, 0x00, 0xba, 0xb4, - 0xbe, 0xb9, 0x00, 0x00, 0x00, 0x00, 0x8c, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0xb1, 0xc9, 0xc6, 0xbe, 0x00, 0xcd, 0xbf, 0xbb, 0x00, - 0xc7, 0xbb, 0xca, 0xb2, 0x00, 0xbd, 0xe9, 0xe7, 0xe8, 0xe3, 0xe1, 0x00, - 0xbd, 0xd5, 0xe6, 0xd8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0xce, 0xdc, 0xdd, 0xe7, 0x00, 0xd1, 0xe3, 0xe2, 0xd8, 0xd9, - 0xe6, 0xd7, 0xd5, 0xe6, 0xd8, 0x00, 0xdd, 0xe7, 0x00, 0xdd, 0xe0, 0xe0, - 0xd9, 0xdb, 0xd5, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xc1, 0xe3, 0x00, 0xe8, 0xe3, 0x00, 0xe8, 0xdc, - 0xd9, 0x00, 0xe7, 0xd9, 0xd7, 0xe3, 0xe2, 0xd8, 0x00, 0xda, 0xe0, 0xe3, - 0xe3, 0xe6, 0x00, 0xe3, 0xda, 0x00, 0xe8, 0xdc, 0xd9, 0x00, 0xca, 0xc9, - 0xc5, 0x1b, 0xc7, 0xc9, 0xc8, 0x00, 0x00, 0x00, 0xbd, 0xbf, 0xc8, 0xce, - 0xbf, 0xcc, 0x00, 0xd5, 0xe2, 0xd8, 0x00, 0xe1, 0xd9, 0xd9, 0xe8, 0x00, - 0xe8, 0xdc, 0xd9, 0x00, 0xd8, 0xd9, 0xe0, 0xdd, 0xea, 0xd9, 0xe6, 0xed, - 0x00, 0xe4, 0xd9, 0xe6, 0xe7, 0xe3, 0xe2, 0x00, 0xdd, 0xe2, 0x00, 0x00, - 0xdb, 0xe6, 0xd9, 0xd9, 0xe2, 0xad, 0x00, 0xcc, 0xd9, 0xd7, 0xd9, 0xdd, - 0xea, 0xd9, 0x00, 0xe8, 0xdc, 0xd9, 0x00, 0xc9, 0xc6, 0xbe, 0x00, 0xcd, - 0xbf, 0xbb, 0x00, 0xc7, 0xbb, 0xca, 0x00, 0xd5, 0xe2, 0xd8, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xe8, 0xdc, 0xd9, 0xe2, 0x00, 0xe7, 0xd5, 0xea, - 0xd9, 0x00, 0xe8, 0xdc, 0xd9, 0x00, 0xdb, 0xd5, 0xe1, 0xd9, 0xab, 0xab, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbe, 0xe3, 0x00, 0xe2, - 0xe3, 0xe8, 0x00, 0xe8, 0xe3, 0xe7, 0xe7, 0x00, 0xe8, 0xdc, 0xdd, 0xe7, - 0x00, 0xbf, 0xec, 0xd7, 0xdc, 0xd5, 0xe2, 0xdb, 0xd9, 0x00, 0xbd, 0xd5, - 0xe6, 0xd8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xd6, 0xd9, 0xda, 0xe3, 0xe6, 0xd9, 0x00, 0xe6, 0xd9, 0xd7, 0xd9, 0xdd, - 0xea, 0xdd, 0xe2, 0xdb, 0x00, 0xe8, 0xdc, 0xd9, 0x00, 0xc9, 0xc6, 0xbe, - 0x00, 0xcd, 0xbf, 0xbb, 0x00, 0xc7, 0xbb, 0xca, 0xab, 0xab, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x88, 0x37, 0x00, 0x00, 0x33, 0xff, 0xff, 0xff, 0xb8, 0xf4, - 0x57, 0x67, 0x08, 0x6a, 0x5a, 0x2b, 0x3c, 0x01, 0xbb, 0x01, 0x58, 0x58, - 0x67, 0x08, 0x2b, 0xca, 0x01, 0xbb, 0x01, 0x58, 0x58, 0x67, 0x08, 0x47, - 0x78, 0x01, 0x01, 0x00, 0x21, 0x0d, 0x80, 0x01, 0x00, 0xbb, 0x01, 0x58, - 0x58, 0x67, 0x08, 0xbd, 0x61, 0x58, 0x67, 0x08, 0x66, 0x6d, 0x46, 0x78, - 0x01, 0x01, 0x00, 0x21, 0x0d, 0x80, 0x00, 0x00, 0xbb, 0x01, 0x4f, 0x58, - 0x67, 0x08, 0x1a, 0x00, 0x80, 0x78, 0x01, 0x1a, 0x01, 0x80, 0x01, 0x00, - 0x09, 0x00, 0x29, 0xd6, 0x08, 0x29, 0x3c, 0x01, 0xbd, 0xd9, 0x58, 0x67, - 0x08, 0x66, 0x6d, 0x6c, 0x02, 0xbd, 0x6a, 0x59, 0x67, 0x08, 0x66, 0x6d, - 0x6c, 0x02, 0xbd, 0x3d, 0x59, 0x67, 0x08, 0x66, 0x6d, 0x6c, 0x02, 0xce, - 0xdc, 0xd5, 0xe2, 0xdf, 0x00, 0xed, 0xe3, 0xe9, 0x00, 0xda, 0xe3, 0xe6, - 0x00, 0xe9, 0xe7, 0xdd, 0xe2, 0xdb, 0x00, 0xe8, 0xdc, 0xd9, 0x00, 0xc7, - 0xd3, 0xcd, 0xce, 0xbf, 0xcc, 0xd3, 0xfe, 0xc1, 0xc3, 0xc0, 0xce, 0x00, - 0xcd, 0xed, 0xe7, 0xe8, 0xd9, 0xe1, 0xad, 0xfb, 0xc6, 0xd9, 0xe8, 0x00, - 0xe1, 0xd9, 0x00, 0xd7, 0xe3, 0xe2, 0xda, 0xdd, 0xe6, 0xe1, 0xae, 0xae, - 0xed, 0xe3, 0xe9, 0x00, 0xd5, 0xe6, 0xd9, 0x00, 0xfd, 0x01, 0xac, 0xfb, - 0xd1, 0xd9, 0x00, 0xe6, 0xd9, 0xd7, 0xd9, 0xdd, 0xea, 0xd9, 0xd8, 0x00, - 0xe8, 0xdc, 0xdd, 0xe7, 0x00, 0xc9, 0xc6, 0xbe, 0x00, 0xcd, 0xbf, 0xbb, - 0x00, 0xc7, 0xbb, 0xca, 0xfe, 0xd5, 0xd8, 0xd8, 0xe6, 0xd9, 0xe7, 0xe7, - 0xd9, 0xd8, 0x00, 0xe8, 0xe3, 0x00, 0xed, 0xe3, 0xe9, 0xad, 0xff, 0xc3, - 0xe8, 0x00, 0xd5, 0xe4, 0xe4, 0xd9, 0xd5, 0xe6, 0xe7, 0x00, 0xe8, 0xe3, - 0x00, 0xd6, 0xd9, 0x00, 0xda, 0xe3, 0xe6, 0x00, 0xe9, 0xe7, 0xd9, 0x00, - 0xd5, 0xe8, 0x00, 0xe8, 0xdc, 0xd9, 0xfe, 0xc6, 0xc3, 0xc6, 0xd3, 0xbd, - 0xc9, 0xd0, 0xbf, 0x00, 0xbd, 0xc3, 0xce, 0xd3, 0x00, 0xe4, 0xe3, 0xe6, - 0xe8, 0xad, 0xfb, 0xd1, 0xdc, 0xed, 0x00, 0xe2, 0xe3, 0xe8, 0x00, 0xdb, - 0xdd, 0xea, 0xd9, 0x00, 0xdd, 0xe8, 0x00, 0xd5, 0x00, 0xe8, 0xe6, 0xed, - 0x00, 0xd5, 0xe2, 0xd8, 0x00, 0xe7, 0xd9, 0xd9, 0x00, 0xeb, 0xdc, 0xd5, - 0xe8, 0xfe, 0xdd, 0xe8, 0x00, 0xdd, 0xe7, 0x00, 0xd5, 0xd6, 0xe3, 0xe9, - 0xe8, 0xac, 0xff, 0xce, 0xdc, 0xd5, 0xe2, 0xdf, 0x00, 0xed, 0xe3, 0xe9, - 0x00, 0xda, 0xe3, 0xe6, 0x00, 0xe9, 0xe7, 0xdd, 0xe2, 0xdb, 0x00, 0xe8, - 0xdc, 0xd9, 0x00, 0xc7, 0xd3, 0xcd, 0xce, 0xbf, 0xcc, 0xd3, 0xfe, 0xc1, - 0xc3, 0xc0, 0xce, 0x00, 0xcd, 0xed, 0xe7, 0xe8, 0xd9, 0xe1, 0xad, 0xff, - 0xc9, 0xdc, 0xb8, 0x00, 0xc3, 0xb4, 0xe1, 0x00, 0xe7, 0xe3, 0xe6, 0xe6, - 0xed, 0xb8, 0x00, 0xfd, 0x01, 0xad, 0xfe, 0xd3, 0xe3, 0xe9, 0xe6, 0x00, - 0xbc, 0xbb, 0xc1, 0xb4, 0xe7, 0x00, 0xc5, 0xbf, 0xd3, 0x00, 0xc3, 0xce, - 0xbf, 0xc7, 0xcd, 0x00, 0xca, 0xc9, 0xbd, 0xc5, 0xbf, 0xce, 0x00, 0xdd, - 0xe7, 0x00, 0xda, 0xe9, 0xe0, 0xe0, 0xad, 0xfb, 0xca, 0xe0, 0xd9, 0xd5, - 0xe7, 0xd9, 0x00, 0xe7, 0xe8, 0xe3, 0xe6, 0xd9, 0x00, 0xe7, 0xe3, 0xe1, - 0xd9, 0xe8, 0xdc, 0xdd, 0xe2, 0xdb, 0x00, 0xe3, 0xe2, 0x00, 0xed, 0xe3, - 0xe9, 0xe6, 0x00, 0xca, 0xbd, 0xb8, 0xfe, 0xe8, 0xdc, 0xd9, 0xe2, 0x00, - 0xd7, 0xe3, 0xe1, 0xd9, 0x00, 0xd6, 0xd5, 0xd7, 0xdf, 0x00, 0xda, 0xe3, - 0xe6, 0x00, 0xe8, 0xdc, 0xdd, 0xe7, 0xad, 0xff, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; \ No newline at end of file +// Taken from WC3Tool 0.1f: https://github.com/projectpokemon/Gen3-WCTool/releases/tag/0.1f +static const u8 OldSeaMap_E_custom[] = {0xcf, 0xa6, 0x00, 0x00, 0xba, 0xb4, 0xbe, 0xb9, 0x00, 0x00, + 0x00, 0x00, 0x8c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb1, 0xc9, 0xc6, 0xbe, 0x00, + 0xcd, 0xbf, 0xbb, 0x00, 0xc7, 0xbb, 0xca, 0xb2, 0x00, 0xbd, 0xe9, 0xe7, 0xe8, 0xe3, 0xe1, 0x00, + 0xbd, 0xd5, 0xe6, 0xd8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xce, 0xdc, + 0xdd, 0xe7, 0x00, 0xd1, 0xe3, 0xe2, 0xd8, 0xd9, 0xe6, 0xd7, 0xd5, 0xe6, 0xd8, 0x00, 0xdd, 0xe7, + 0x00, 0xdd, 0xe0, 0xe0, 0xd9, 0xdb, 0xd5, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xc1, 0xe3, 0x00, 0xe8, 0xe3, 0x00, 0xe8, 0xdc, 0xd9, 0x00, 0xe7, 0xd9, + 0xd7, 0xe3, 0xe2, 0xd8, 0x00, 0xda, 0xe0, 0xe3, 0xe3, 0xe6, 0x00, 0xe3, 0xda, 0x00, 0xe8, 0xdc, + 0xd9, 0x00, 0xca, 0xc9, 0xc5, 0x1b, 0xc7, 0xc9, 0xc8, 0x00, 0x00, 0x00, 0xbd, 0xbf, 0xc8, 0xce, + 0xbf, 0xcc, 0x00, 0xd5, 0xe2, 0xd8, 0x00, 0xe1, 0xd9, 0xd9, 0xe8, 0x00, 0xe8, 0xdc, 0xd9, 0x00, + 0xd8, 0xd9, 0xe0, 0xdd, 0xea, 0xd9, 0xe6, 0xed, 0x00, 0xe4, 0xd9, 0xe6, 0xe7, 0xe3, 0xe2, 0x00, + 0xdd, 0xe2, 0x00, 0x00, 0xdb, 0xe6, 0xd9, 0xd9, 0xe2, 0xad, 0x00, 0xcc, 0xd9, 0xd7, 0xd9, 0xdd, + 0xea, 0xd9, 0x00, 0xe8, 0xdc, 0xd9, 0x00, 0xc9, 0xc6, 0xbe, 0x00, 0xcd, 0xbf, 0xbb, 0x00, 0xc7, + 0xbb, 0xca, 0x00, 0xd5, 0xe2, 0xd8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe8, 0xdc, 0xd9, 0xe2, + 0x00, 0xe7, 0xd5, 0xea, 0xd9, 0x00, 0xe8, 0xdc, 0xd9, 0x00, 0xdb, 0xd5, 0xe1, 0xd9, 0xab, 0xab, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xbe, 0xe3, 0x00, 0xe2, 0xe3, 0xe8, 0x00, 0xe8, 0xe3, 0xe7, 0xe7, 0x00, + 0xe8, 0xdc, 0xdd, 0xe7, 0x00, 0xbf, 0xec, 0xd7, 0xdc, 0xd5, 0xe2, 0xdb, 0xd9, 0x00, 0xbd, 0xd5, + 0xe6, 0xd8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd6, 0xd9, 0xda, 0xe3, + 0xe6, 0xd9, 0x00, 0xe6, 0xd9, 0xd7, 0xd9, 0xdd, 0xea, 0xdd, 0xe2, 0xdb, 0x00, 0xe8, 0xdc, 0xd9, + 0x00, 0xc9, 0xc6, 0xbe, 0x00, 0xcd, 0xbf, 0xbb, 0x00, 0xc7, 0xbb, 0xca, 0xab, 0xab, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x37, 0x00, 0x00, 0x33, 0xff, 0xff, 0xff, 0xb8, 0xf4, + 0x57, 0x67, 0x08, 0x6a, 0x5a, 0x2b, 0x3c, 0x01, 0xbb, 0x01, 0x58, 0x58, 0x67, 0x08, 0x2b, 0xca, + 0x01, 0xbb, 0x01, 0x58, 0x58, 0x67, 0x08, 0x47, 0x78, 0x01, 0x01, 0x00, 0x21, 0x0d, 0x80, 0x01, + 0x00, 0xbb, 0x01, 0x58, 0x58, 0x67, 0x08, 0xbd, 0x61, 0x58, 0x67, 0x08, 0x66, 0x6d, 0x46, 0x78, + 0x01, 0x01, 0x00, 0x21, 0x0d, 0x80, 0x00, 0x00, 0xbb, 0x01, 0x4f, 0x58, 0x67, 0x08, 0x1a, 0x00, + 0x80, 0x78, 0x01, 0x1a, 0x01, 0x80, 0x01, 0x00, 0x09, 0x00, 0x29, 0xd6, 0x08, 0x29, 0x3c, 0x01, + 0xbd, 0xd9, 0x58, 0x67, 0x08, 0x66, 0x6d, 0x6c, 0x02, 0xbd, 0x6a, 0x59, 0x67, 0x08, 0x66, 0x6d, + 0x6c, 0x02, 0xbd, 0x3d, 0x59, 0x67, 0x08, 0x66, 0x6d, 0x6c, 0x02, 0xce, 0xdc, 0xd5, 0xe2, 0xdf, + 0x00, 0xed, 0xe3, 0xe9, 0x00, 0xda, 0xe3, 0xe6, 0x00, 0xe9, 0xe7, 0xdd, 0xe2, 0xdb, 0x00, 0xe8, + 0xdc, 0xd9, 0x00, 0xc7, 0xd3, 0xcd, 0xce, 0xbf, 0xcc, 0xd3, 0xfe, 0xc1, 0xc3, 0xc0, 0xce, 0x00, + 0xcd, 0xed, 0xe7, 0xe8, 0xd9, 0xe1, 0xad, 0xfb, 0xc6, 0xd9, 0xe8, 0x00, 0xe1, 0xd9, 0x00, 0xd7, + 0xe3, 0xe2, 0xda, 0xdd, 0xe6, 0xe1, 0xae, 0xae, 0xed, 0xe3, 0xe9, 0x00, 0xd5, 0xe6, 0xd9, 0x00, + 0xfd, 0x01, 0xac, 0xfb, 0xd1, 0xd9, 0x00, 0xe6, 0xd9, 0xd7, 0xd9, 0xdd, 0xea, 0xd9, 0xd8, 0x00, + 0xe8, 0xdc, 0xdd, 0xe7, 0x00, 0xc9, 0xc6, 0xbe, 0x00, 0xcd, 0xbf, 0xbb, 0x00, 0xc7, 0xbb, 0xca, + 0xfe, 0xd5, 0xd8, 0xd8, 0xe6, 0xd9, 0xe7, 0xe7, 0xd9, 0xd8, 0x00, 0xe8, 0xe3, 0x00, 0xed, 0xe3, + 0xe9, 0xad, 0xff, 0xc3, 0xe8, 0x00, 0xd5, 0xe4, 0xe4, 0xd9, 0xd5, 0xe6, 0xe7, 0x00, 0xe8, 0xe3, + 0x00, 0xd6, 0xd9, 0x00, 0xda, 0xe3, 0xe6, 0x00, 0xe9, 0xe7, 0xd9, 0x00, 0xd5, 0xe8, 0x00, 0xe8, + 0xdc, 0xd9, 0xfe, 0xc6, 0xc3, 0xc6, 0xd3, 0xbd, 0xc9, 0xd0, 0xbf, 0x00, 0xbd, 0xc3, 0xce, 0xd3, + 0x00, 0xe4, 0xe3, 0xe6, 0xe8, 0xad, 0xfb, 0xd1, 0xdc, 0xed, 0x00, 0xe2, 0xe3, 0xe8, 0x00, 0xdb, + 0xdd, 0xea, 0xd9, 0x00, 0xdd, 0xe8, 0x00, 0xd5, 0x00, 0xe8, 0xe6, 0xed, 0x00, 0xd5, 0xe2, 0xd8, + 0x00, 0xe7, 0xd9, 0xd9, 0x00, 0xeb, 0xdc, 0xd5, 0xe8, 0xfe, 0xdd, 0xe8, 0x00, 0xdd, 0xe7, 0x00, + 0xd5, 0xd6, 0xe3, 0xe9, 0xe8, 0xac, 0xff, 0xce, 0xdc, 0xd5, 0xe2, 0xdf, 0x00, 0xed, 0xe3, 0xe9, + 0x00, 0xda, 0xe3, 0xe6, 0x00, 0xe9, 0xe7, 0xdd, 0xe2, 0xdb, 0x00, 0xe8, 0xdc, 0xd9, 0x00, 0xc7, + 0xd3, 0xcd, 0xce, 0xbf, 0xcc, 0xd3, 0xfe, 0xc1, 0xc3, 0xc0, 0xce, 0x00, 0xcd, 0xed, 0xe7, 0xe8, + 0xd9, 0xe1, 0xad, 0xff, 0xc9, 0xdc, 0xb8, 0x00, 0xc3, 0xb4, 0xe1, 0x00, 0xe7, 0xe3, 0xe6, 0xe6, + 0xed, 0xb8, 0x00, 0xfd, 0x01, 0xad, 0xfe, 0xd3, 0xe3, 0xe9, 0xe6, 0x00, 0xbc, 0xbb, 0xc1, 0xb4, + 0xe7, 0x00, 0xc5, 0xbf, 0xd3, 0x00, 0xc3, 0xce, 0xbf, 0xc7, 0xcd, 0x00, 0xca, 0xc9, 0xbd, 0xc5, + 0xbf, 0xce, 0x00, 0xdd, 0xe7, 0x00, 0xda, 0xe9, 0xe0, 0xe0, 0xad, 0xfb, 0xca, 0xe0, 0xd9, 0xd5, + 0xe7, 0xd9, 0x00, 0xe7, 0xe8, 0xe3, 0xe6, 0xd9, 0x00, 0xe7, 0xe3, 0xe1, 0xd9, 0xe8, 0xdc, 0xdd, + 0xe2, 0xdb, 0x00, 0xe3, 0xe2, 0x00, 0xed, 0xe3, 0xe9, 0xe6, 0x00, 0xca, 0xbd, 0xb8, 0xfe, 0xe8, + 0xdc, 0xd9, 0xe2, 0x00, 0xd7, 0xe3, 0xe1, 0xd9, 0x00, 0xd6, 0xd5, 0xd7, 0xdf, 0x00, 0xda, 0xe3, + 0xe6, 0x00, 0xe8, 0xdc, 0xdd, 0xe7, 0xad, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00}; \ No newline at end of file diff --git a/include/flash_mem.h b/include/flash_mem.h index 89d9aff..3691699 100644 --- a/include/flash_mem.h +++ b/include/flash_mem.h @@ -16,13 +16,11 @@ extern u8 global_memory_buffer[0x1000]; extern rom_data curr_GBA_rom; /** - * @brief Given that the save sections within a save slot are not saved in a - * fixed order, This function will walk through the save slot to fill the - * memory_section_array map. + * @brief Given that the save sections within a save slot are not saved in a fixed order, + * This function will walk through the save slot to fill the memory_section_array map. * - * After calling this, memory_section_array will point to the save offset by - * each section ID. So memory_section_array[0] will point to the save offset of - * section 0, etc. + * After calling this, memory_section_array will point to the save offset by each section ID. + * So memory_section_array[0] will point to the save offset of section 0, etc. */ void initialize_memory_locations(); @@ -35,8 +33,8 @@ void reverse_endian(u8 *data, size_t size); * It assumes that the sector buffer contains one of the save data sections. * * @param sector_buffer The buffer containing the save data section. - * @param hall_of_fame This is needed to indicate if you're trying to save the - * hall of fame section. The checksum offset is slightly different there. + * @param hall_of_fame This is needed to indicate if you're trying to save the hall of fame section. + * The checksum offset is slightly different there. */ void update_memory_buffer_checksum(u8 *sector_buffer, bool hall_of_fame); bool read_flag(u16 flag_id); diff --git a/include/gb_rom_values/base_gb_rom_struct.h b/include/gb_rom_values/base_gb_rom_struct.h index b3913ed..d1a0d4b 100644 --- a/include/gb_rom_values/base_gb_rom_struct.h +++ b/include/gb_rom_values/base_gb_rom_struct.h @@ -44,23 +44,20 @@ extern "C" #define GB_TILE_WIDTH 20 -// TODO? : Since we moved payload_builder into data-generator, we no longer need -// most of the fields of GB_ROM in our PTGB rom. It might be better to split it -// up into a struct that contains everything for data-generator and a separate -// one that gets included into the ptgb rom, which only includes whatever PTGB -// needs at runtime. (which is probably a fraction of the data) However, right -// now the compressed gb_rom_values_eng file is only 353 bytes and the -// gb_rom_values_fre is only 351 bytes. Therefore we'd save at most about 0,5 KB -// if we do this optimization. So it might not be worth it right now. If we -// expand the data at some point, however, it might be! +// TODO? : Since we moved payload_builder into data-generator, we no longer need most of the fields +// of GB_ROM in our PTGB rom. It might be better to split it up into a struct that contains +// everything for data-generator and a separate one that gets included into the ptgb rom, which only +// includes whatever PTGB needs at runtime. (which is probably a fraction of the data) However, +// right now the compressed gb_rom_values_eng file is only 353 bytes and the gb_rom_values_fre is +// only 351 bytes. Therefore we'd save at most about 0,5 KB if we do this optimization. So it might +// not be worth it right now. If we expand the data at some point, however, it might be! -// WARNING: We must be explicit in the type declarations of the struct members -// here. After all: data-generator runs on x86 and the structs will be read by -// the GBA's ARM processor. So we must ensure the sizes of the struct members, -// as well as padding, remains consistent across platforms. So please make sure -// to use data types which are explicit in their size. (such as uint32_t, -// uint8_t, etc.) Because the regular "int", "bool", "char" etc are -// platform-dependent in size. +// WARNING: We must be explicit in the type declarations of the struct members here. +// After all: data-generator runs on x86 and the structs will be read by the GBA's ARM processor. +// So we must ensure the sizes of the struct members, as well as padding, remains consistent across +// platforms. So please make sure to use data types which are explicit in their size. (such as +// uint32_t, uint8_t, etc.) Because the regular "int", "bool", "char" etc are platform-dependent in +// size. struct GB_ROM { public: @@ -72,30 +69,25 @@ struct GB_ROM int32_t box_data_size; u16 print_string_start; // Start of where text is written in VRAM - u16 stack_overwrite_location; // The part of the stack that we're - // overwriting - u8 short_pkmn_name; // The name of the Pokemon that moves us through RAM - u8 pointer_pkmn_name; // The name of the Pokemon that overwrites the stack + u16 stack_overwrite_location; // The part of the stack that we're overwriting + u8 short_pkmn_name; // The name of the Pokemon that moves us through RAM + u8 pointer_pkmn_name; // The name of the Pokemon that overwrites the stack u16 padding_1; - u32 clearScreen; // location of the clearScreen function in the ROM - u32 CableClub_TextBoxBorder; // location of the CableClub_TextBoxBorder - // function in the ROM - u32 placeString; // location of the placeString function in the ROM - u32 Serial_ExchangeBytes; // location of the Serial_ExchangeBytes function - // in the ROM - u32 _RemovePokemon; // location of the _RemovePokemon function in the ROM - u32 SaveSAVtoSRAM1; // location of the SaveSAVtoSRAM1 function in the ROM - u32 SaveSAVtoSRAM2; // location of the SaveSAVtoSRAM2 function in the ROM - u32 LoadCurrentBoxData; // location of the LoadCurrentBoxData function in - // the ROM - u32 OpenSRAM; // location of the OpenSRAM function in the ROM - u32 SaveBox; // location of the SaveBox function in the ROM - u32 Bankswitch; // location of the BankswitchCommon function in the ROM - u32 SoftReset; // location of the SoftReset function in the ROM - u32 CloseSRAM; // location of the OpenSRAM function in the ROM - u32 garbageDataLocation; // location of random data starting with 0xFD in - // the ROM + u32 clearScreen; // location of the clearScreen function in the ROM + u32 CableClub_TextBoxBorder; // location of the CableClub_TextBoxBorder function in the ROM + u32 placeString; // location of the placeString function in the ROM + u32 Serial_ExchangeBytes; // location of the Serial_ExchangeBytes function in the ROM + u32 _RemovePokemon; // location of the _RemovePokemon function in the ROM + u32 SaveSAVtoSRAM1; // location of the SaveSAVtoSRAM1 function in the ROM + u32 SaveSAVtoSRAM2; // location of the SaveSAVtoSRAM2 function in the ROM + u32 LoadCurrentBoxData; // location of the LoadCurrentBoxData function in the ROM + u32 OpenSRAM; // location of the OpenSRAM function in the ROM + u32 SaveBox; // location of the SaveBox function in the ROM + u32 Bankswitch; // location of the BankswitchCommon function in the ROM + u32 SoftReset; // location of the SoftReset function in the ROM + u32 CloseSRAM; // location of the OpenSRAM function in the ROM + u32 garbageDataLocation; // location of random data starting with 0xFD in the ROM u32 wRemoveMonFromBox; // location of wRemoveMonFromBox in RAM u32 wCurrentBoxNum; // location of wCurrentBoxNum in RAM @@ -106,19 +98,15 @@ struct GB_ROM u32 wSerialEnemyDataBlock; // location of wSerialEnemyDataBlock in RAM u32 wEnemyMonSpecies; // location of wEnemyMonSpecies in RAM - u32 wSerialEnemyMonsPatchList; // location of wSerialEnemyMonsPatchList in - // RAM + u32 wSerialEnemyMonsPatchList; // location of wSerialEnemyMonsPatchList in RAM u32 wSerialOtherGameboyRandomNumberListBlock; // location of - // wSerialOtherGameboyRandomNumberListBlock - // in RAM - u32 hSerialConnectionStatus; // location of hSerialConnectionStatus in RAM + // wSerialOtherGameboyRandomNumberListBlock in RAM + u32 hSerialConnectionStatus; // location of hSerialConnectionStatus in RAM - u16 transferStringLocation; // location in VRAM to start writing the - // transfer string to - u16 textBorderUppLeft; // location in VRAM to put the upper left corner of - // the border - u8 textBorderWidth; // the width of the text box border - u8 textBorderHeight; // the height of the text box border + u16 transferStringLocation; // location in VRAM to start writing the transfer string to + u16 textBorderUppLeft; // location in VRAM to put the upper left corner of the border + u8 textBorderWidth; // the width of the text box border + u8 textBorderHeight; // the height of the text box border u16 padding_2; }; diff --git a/include/global_frame_controller.h b/include/global_frame_controller.h index 43a9742..eca4c5d 100644 --- a/include/global_frame_controller.h +++ b/include/global_frame_controller.h @@ -14,8 +14,7 @@ enum LinkAnimationState // TODO: This is kinda a silly spot for this // make sure outBuffer is large enough! Should be at least hex_len + 1 -template -void n2hexstr(char *outBuffer, I w, size_t hex_len = sizeof(I) << 1) +template void n2hexstr(char *outBuffer, I w, size_t hex_len = sizeof(I) << 1) { static const char *digits = "0123456789ABCDEF"; memset(outBuffer, '0', hex_len); diff --git a/include/libstd_replacements.h b/include/libstd_replacements.h index ae0641e..02c44ef 100644 --- a/include/libstd_replacements.h +++ b/include/libstd_replacements.h @@ -22,8 +22,7 @@ namespace ptgb * In case you want to convert more than one int to string within the same call, * consider using npf_snprintf instead! * - * Also: if you want to hold on to the converted value, consider copying the - * returned string + * Also: if you want to hold on to the converted value, consider copying the returned string */ const char *to_string(int intVal); @@ -36,8 +35,7 @@ const char *to_string(int intVal); * In case you want to convert more than one int to string within the same call, * consider using npf_snprintf instead! * - * Also: if you want to hold on to the converted value, consider copying the - * returned string + * Also: if you want to hold on to the converted value, consider copying the returned string */ const char *to_string(unsigned int wordVal); @@ -48,8 +46,7 @@ template class vector vector() : buffer_(), capacity_(default_capacity), count_(0) { - buffer_ = static_cast( - ::operator new(sizeof(ValueType) * capacity_)); + buffer_ = static_cast(::operator new(sizeof(ValueType) * capacity_)); if (!buffer_) { return; // allocation failed @@ -59,8 +56,7 @@ template class vector vector(const ValueType *valueList, uint16_t listSize) : buffer_(), capacity_(listSize), count_(0) { - buffer_ = static_cast( - ::operator new(sizeof(ValueType) * capacity_)); + buffer_ = static_cast(::operator new(sizeof(ValueType) * capacity_)); if (!buffer_) { return; // allocation failed @@ -71,8 +67,7 @@ template class vector vector(const vector &otherList) : buffer_(), capacity_(otherList.capacity_), count_(0) { - buffer_ = static_cast( - ::operator new(sizeof(ValueType) * capacity_)); + buffer_ = static_cast(::operator new(sizeof(ValueType) * capacity_)); if (!buffer_) { return; // allocation failed @@ -92,8 +87,8 @@ template class vector { return; } - ValueType *new_buffer = static_cast( - ::operator new(sizeof(ValueType) * newSize)); + ValueType *new_buffer = + static_cast(::operator new(sizeof(ValueType) * newSize)); if (!new_buffer) { return; // allocation failed, keep the old buffer @@ -188,10 +183,7 @@ template class vector ValueType &operator[](uint16_t index) { return *(buffer_ + index); } - const ValueType &operator[](uint16_t index) const - { - return *(buffer_ + index); - } + const ValueType &operator[](uint16_t index) const { return *(buffer_ + index); } private: ValueType *buffer_; diff --git a/include/link_handler.h b/include/link_handler.h index 1aa97c7..caf4f27 100644 --- a/include/link_handler.h +++ b/include/link_handler.h @@ -313,48 +313,36 @@ enum LinkConnectionError enum PayloadCommand { - CMD_NONE = 0x7F, // Using 0x7F instead of -1, since that ends up being 0xFE. - CMD_ReloadCurrentBox = - 0, // no arguments used. Reloads the current box from SRAM. Use this as - // the first command byte before performing other commands. - CMD_TransferPokemon, // 1st argument = secondary payload size, 2nd argument - // = box that should be transferred from. This command - // uses a secondary payload. The size of this secondary - // payload needs to be declared beforehand. Prior to - // requesting a secondary payload, the program will use - // the second argument to load a specific box from - // SRAM. Box numbers are 0-indexed and range from 0x00 - // (box 1) to 0x0B(box 12). This load procedure - // currently cannot be skipped. Once the secondary - // payload arrives, the program will verify its - // integrity and align the payload. Afterwards, it will - // use the information within this payload to remove - // pokémon from the current box. Once all transferred - // pokémon have been removed, the program will save the - // current box. - CMD_SoftReset, // no arguments used. Instantly soft resets the game. - CMD_ModifySRAMAccess, // 1st argument = SRAM dis/enable. set to 0x0A to open - // access, set to 0x00 to close access. Second - // argument = SRAM bank. When closing SRAM access, set - // to 0x00. SRAM remains open until closed by this - // command or until closed by - // CMD_TransferPokemon/CMD_ReloadCurrentBox. - CMD_RunSecondaryPayload, // 1st argument = secondary payload size. This - // command uses a secondary payload. The size of - // this secondary payload needs to be declared - // beforehand. Once the secondary payload arrives, - // the program will verify its integrity and align - // the payload. Afterwards, it will jump to the - // secondary payload and execute it. IMPORTANT: if - // you want to report an error when executing this - // secondary payload, return with carry flag set. - // IMPORTANT: if you want to report that the - // payload was executed safely, return with carry - // flag reset.*/ - CMD_ReadDataRequest, // a request to read data starting from the address - // defined by the 16-bit pointer. - CMD_SecondaryPayload = - 0xFF, // Used whenever a packet is for a secondary payload. + CMD_NONE = 0x7F, // Using 0x7F instead of -1, since that ends up being 0xFE. + CMD_ReloadCurrentBox = 0, // no arguments used. Reloads the current box from SRAM. Use this as + // the first command byte before performing other commands. + CMD_TransferPokemon, // 1st argument = secondary payload size, 2nd argument = box that should be + // transferred from. This command uses a secondary payload. The size of + // this secondary payload needs to be declared beforehand. Prior to + // requesting a secondary payload, the program will use the second argument + // to load a specific box from SRAM. Box numbers are 0-indexed and range + // from 0x00 (box 1) to 0x0B(box 12). This load procedure currently cannot + // be skipped. Once the secondary payload arrives, the program will verify + // its integrity and align the payload. Afterwards, it will use the + // information within this payload to remove pokémon from the current box. + // Once all transferred pokémon have been removed, the program will save + // the current box. + CMD_SoftReset, // no arguments used. Instantly soft resets the game. + CMD_ModifySRAMAccess, // 1st argument = SRAM dis/enable. set to 0x0A to open access, set to 0x00 + // to close access. Second argument = SRAM bank. When closing SRAM access, + // set to 0x00. SRAM remains open until closed by this command or until + // closed by CMD_TransferPokemon/CMD_ReloadCurrentBox. + CMD_RunSecondaryPayload, // 1st argument = secondary payload size. This command uses a secondary + // payload. The size of this secondary payload needs to be declared + // beforehand. Once the secondary payload arrives, the program will + // verify its integrity and align the payload. Afterwards, it will jump + // to the secondary payload and execute it. IMPORTANT: if you want to + // report an error when executing this secondary payload, return with + // carry flag set. IMPORTANT: if you want to report that the payload + // was executed safely, return with carry flag reset.*/ + CMD_ReadDataRequest, // a request to read data starting from the address defined by the 16-bit + // pointer. + CMD_SecondaryPayload = 0xFF, // Used whenever a packet is for a secondary payload. }; #define OUTP_PREAMBLE_INDEX 0 @@ -392,9 +380,8 @@ struct LinkPacket byte *secondaryPayloadData = nullptr; int secondaryPayloadDataSize = 0; byte secondaryPayloadSizeChecksum = 0; -#define SECONDARY_PAYLOAD_HEADER_SIZE \ - 4 // The size of a secondary packet, not including the data bytes or - // checksum +#define SECONDARY_PAYLOAD_HEADER_SIZE \ + 4 // The size of a secondary packet, not including the data bytes or checksum LinkPacket() {}; LinkPacket(PayloadCommand cmd, byte arg1, byte arg2, u16 addr); @@ -414,18 +401,16 @@ class LinkConnection uint8_t outData = 0xFF; uint8_t nextOutData = 0xFF; - int globalStateCounter = - 0; // The counter for the total number of bytes sent - int subStateCounter = - 0; // The counter for the total number of bytes sent in this substate + int globalStateCounter = 0; // The counter for the total number of bytes sent + int subStateCounter = 0; // The counter for the total number of bytes sent in this substate int gen = 0; // The generation we are trading with Language lang = LANGUAGE_UNKNOWN; // The language we are trading with Version vers = VERSION_UNKNOWN; // The version we are trading with - GameBoyROM currROM = NO_GB_ROM; // The GameBoy ROM we're communicating with - const GB_ROM *pccsROMptr = nullptr; // A pointer to the ROM data for the - // game we're communicating with - byte boxNum = 0; // The current box the user has selected + GameBoyROM currROM = NO_GB_ROM; // The GameBoy ROM we're communicating with + const GB_ROM *pccsROMptr = + nullptr; // A pointer to the ROM data for the game we're communicating with + byte boxNum = 0; // The current box the user has selected int FF_count = 0; // The number of 0xFF bytes that have been in a row int zero_count = 0; // The number of 0x00 bytes that have been in a row @@ -446,18 +431,16 @@ class LinkConnection LinkPacket *currOutgoingPacket; LinkPacket *currIncomingPacket; LinkPacket dummyPacket = LinkPacket(); - byte linkPacketArrIndex = - LINK_PACKET_ARRAY_SIZE; // We want to avoid starting at zero, since that - // is a common value sent back in error. + byte linkPacketArrIndex = LINK_PACKET_ARRAY_SIZE; // We want to avoid starting at zero, since + // that is a common value sent back in error. u16 linkPacketDataAddr = 0; u16 linkPacketDataStart = 0; int linkPacketDataSize = 0; byte *outDataArrayPtr; - bool pauseOnByte = false; // Used for pausing and sending one byte at a time - bool pauseOnPacket = - false; // Used for pausing and sending one packet at a time - bool skipPrint = false; // Skips printing to the screen + bool pauseOnByte = false; // Used for pausing and sending one byte at a time + bool pauseOnPacket = false; // Used for pausing and sending one packet at a time + bool skipPrint = false; // Skips printing to the screen void setup(const u16 *debug_charset); void startConnection(LinkState startState); @@ -472,19 +455,18 @@ class LinkConnection // These are all the Link Commands bool LinkCommand_InitalizeConnection(bool waitForCompletion = true); bool LinkCommand_ReloadCurrentBox(bool waitForCompletion = true); - bool LinkCommand_TransferPokemon(int boxNumber, byte removalArray[], - int removalArrayLength, bool waitForCompletion = true); + bool LinkCommand_TransferPokemon( + int boxNumber, byte removalArray[], int removalArrayLength, bool waitForCompletion = true); bool LinkCommand_SoftReset(bool waitForCompletion = true); bool LinkCommand_ModifySRAMAccess( bool enableSRAM, byte SRAMbank, bool waitForCompletion = true); bool LinkCommand_RunSecondaryPayload( byte payload[], int payloadLength, bool waitForCompletion = true); - bool LinkCommand_ReadMemorySection(u32 dataPointer, byte outArray[], - int outArraySize, bool waitForCompletion = true); + bool LinkCommand_ReadMemorySection( + u32 dataPointer, byte outArray[], int outArraySize, bool waitForCompletion = true); // Some operations are too long to be done within the IRQ. - // So we need to handle them in the main loop instead to avoid data - // corruption. + // So we need to handle them in the main loop instead to avoid data corruption. void handleCartIO(); private: diff --git a/include/multiboot_upload.h b/include/multiboot_upload.h index 0466fd9..45d86e6 100644 --- a/include/multiboot_upload.h +++ b/include/multiboot_upload.h @@ -4,8 +4,7 @@ /** * @brief Shows the multiboot upload screen. * If the user presses A in this screen/popup, - * the GBA will upload the whole EWRAM as a multiboot rom to another GBA over - * the link cable. + * the GBA will upload the whole EWRAM as a multiboot rom to another GBA over the link cable. */ void multiboot_upload_screen(); diff --git a/include/ptgb_save_data_manager.h b/include/ptgb_save_data_manager.h index 5a597d0..ad77eba 100644 --- a/include/ptgb_save_data_manager.h +++ b/include/ptgb_save_data_manager.h @@ -6,20 +6,18 @@ #define HALL_OF_FAME 0x01C000 #define HOF_SECTION 2032 -// NOTE: This module doesn't manage the _game_ save. It manages -// Poke_Transporter's specific save data. This save data is stored at an unused -// section (HOF_SECTION) of the HALL OF FAME save section. +// NOTE: This module doesn't manage the _game_ save. It manages Poke_Transporter's specific save +// data. This save data is stored at an unused section (HOF_SECTION) of the HALL OF FAME save +// section. // Data map: // There are 1936 (0x790) unused bytes starting at 0x1D7F0 // | Offset | Size | Contents // -------------------------- -#define CAUGHT_DATA 0x00 // | 0x0 | 32 | Flags for each Pokemon species -#define TUTORIAL_FLAG \ - 0x20 // | 0x21 | 1 | Has made it through the tutorial -#define DEFAULT_LANGUAGE \ - 0x21 // | 0x22 | 1 | Default international language +#define CAUGHT_DATA 0x00 // | 0x0 | 32 | Flags for each Pokemon species +#define TUTORIAL_FLAG 0x20 // | 0x21 | 1 | Has made it through the tutorial +#define DEFAULT_LANGUAGE 0x21 // | 0x22 | 1 | Default international language #define SAVE_DATA_SIZE 0x22 extern rom_data curr_GBA_rom; diff --git a/include/rom_data.h b/include/rom_data.h index 1e45604..6f05789 100644 --- a/include/rom_data.h +++ b/include/rom_data.h @@ -44,23 +44,18 @@ class rom_data int loc_gMonShinyPaletteTable; int loc_gMonIconTable; int loc_gMonIconPaletteIndices; - int offset_flags; // Flag offset as found within the SaveBlock1 struct in - // global.h + int offset_flags; // Flag offset as found within the SaveBlock1 struct in global.h int offset_wondercard; int offset_script; - // PKHeX's list of flags is useful for making sure the detection is - // accurate: + // PKHeX's list of flags is useful for making sure the detection is accurate: // https://github.com/kwsch/PKHeX/blob/78a557c3cdaa6f48b42cc96df8ccb4d20b897937/PKHeX.Core/Resources/text/other/flags_rs.txt - int e4_flag; // The flag that is set when you become champion. Often listed - // as "GAME_CLEAR" - int mg_flag; // The flag that is set when you enable Mystery Gift. Known as - // "EXDATA_ENABLE" in RS - int unused_flag_start; // The start of the unused flags and must have 31 - // open flags in a row + int e4_flag; // The flag that is set when you become champion. Often listed as "GAME_CLEAR" + int mg_flag; // The flag that is set when you enable Mystery Gift. Known as "EXDATA_ENABLE" in + // RS + int unused_flag_start; // The start of the unused flags and must have 31 open flags in a row int all_collected_flag; // The flag for if everything has been collected - int pkmn_collected_flag_start; // The beginning of the flags for each of the - // Pokemon + int pkmn_collected_flag_start; // The beginning of the flags for each of the Pokemon u8 map_bank; u8 map_id; diff --git a/include/script_array.h b/include/script_array.h index 09ba691..808e03b 100644 --- a/include/script_array.h +++ b/include/script_array.h @@ -5,15 +5,14 @@ #include "script_obj.h" #include "translated_text.h" -extern bool newPkmn; // This is stupid and dumb and stupid but we're storing it - // like this until this whole mess gets rewritten. +extern bool newPkmn; // This is stupid and dumb and stupid but we're storing it like this until this + // whole mess gets rewritten. // Commands #define T_SCRIPT_START DIA_END + 0 #define E_SCRIPT_START DIA_END + 1 #define CMD_START_LINK DIA_END + 2 -#define CMD_IMPORT_POKEMON \ - DIA_END + 3 // This one is special because it can be true or false +#define CMD_IMPORT_POKEMON DIA_END + 3 // This one is special because it can be true or false #define CMD_BACK_TO_MENU DIA_END + 4 #define CMD_SHOW_PROF DIA_END + 5 #define CMD_HIDE_PROF DIA_END + 6 @@ -34,16 +33,13 @@ extern bool newPkmn; // This is stupid and dumb and stupid but we're storing it #define CMDS_END DIA_END + CMD_SIZE // Conditionals -#define COND_ERROR_TIMEOUT_ONE \ - CMDS_END + 0 // Didn't talk to the Cable Club attendant fast enough or cable - // not connected -#define COND_ERROR_DISCONNECT \ - CMDS_END + 1 // If you unplug the cable after starting SPI +#define COND_ERROR_TIMEOUT_ONE \ + CMDS_END + 0 // Didn't talk to the Cable Club attendant fast enough or cable not connected +#define COND_ERROR_DISCONNECT CMDS_END + 1 // If you unplug the cable after starting SPI #define COND_ERROR_COM_ENDED CMDS_END + 2 // If you don't save the game #define COND_ERROR_TIMEOUT_TWO CMDS_END + 3 // ??? -#define COND_ERROR_COLOSSEUM \ - CMDS_END + 4 // If the player selects the battle colosseum (shouldn't be - // possible) +#define COND_ERROR_COLOSSEUM \ + CMDS_END + 4 // If the player selects the battle colosseum (shouldn't be possible) #define COND_BEAT_E4 CMDS_END + 5 #define COND_MG_ENABLED CMDS_END + 6 #define COND_TUTORIAL_COMPLETE CMDS_END + 7 @@ -75,207 +71,162 @@ bool run_conditional(int index); // These should be removed eventually, or added to PCCS. -static const byte gen1_rb_debug_box_data[0x462] = {// Num of Pokemon +static const byte gen1_rb_debug_box_data[0x462] = { + // Num of Pokemon 0x14, // Pokemon 1-20 - 0x02, 0x1F, 0x70, 0x70, 0x71, 0x71, 0x70, 0x71, 0x7B, 0x71, 0x71, 0x7C, - 0x71, 0x71, 0x71, 0x94, 0x24, 0x24, 0xA5, 0x15, 0xFF, + 0x02, 0x1F, 0x70, 0x70, 0x71, 0x71, 0x70, 0x71, 0x7B, 0x71, 0x71, 0x7C, 0x71, 0x71, 0x71, 0x94, + 0x24, 0x24, 0xA5, 0x15, 0xFF, // Pokemon list - 0x02, 0x00, 0x11, 0x64, 0x00, 0x07, 0x03, 0xFF, 0x28, 0x51, 0x00, 0x00, - 0x6F, 0xC6, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0xE6, 0xDE, 0x23, 0x28, 0x00, 0x00, 0x1F, 0x00, 0x12, - 0x04, 0x00, 0x07, 0x03, 0xFF, 0x28, 0x51, 0x00, 0x00, 0x6F, 0xC6, 0x00, - 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x5D, 0xD8, 0x23, 0x28, 0x00, 0x00, 0x70, 0x00, 0x12, 0x04, 0x00, 0x07, - 0x03, 0xFF, 0x28, 0x51, 0x00, 0x00, 0x6F, 0xC6, 0x00, 0x00, 0x40, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x34, 0x13, 0x23, - 0x28, 0x00, 0x00, 0x70, 0x00, 0x0F, 0x03, 0x00, 0x07, 0x03, 0xFF, 0x28, - 0x51, 0x00, 0x00, 0x6F, 0xC6, 0x00, 0x00, 0x1B, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xDA, 0x81, 0x23, 0x28, 0x00, 0x00, - 0x71, 0x00, 0x14, 0x05, 0x00, 0x07, 0x03, 0x78, 0x6A, 0x00, 0x00, 0x00, - 0x6F, 0xC6, 0x00, 0x00, 0x7D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0xD6, 0x80, 0x1E, 0x00, 0x00, 0x00, 0x71, 0x00, 0x15, - 0x05, 0x00, 0x07, 0x03, 0x78, 0x6A, 0x00, 0x00, 0x00, 0x6F, 0xC6, 0x00, - 0x00, 0x7D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xF7, 0x95, 0x1E, 0x00, 0x00, 0x00, 0x70, 0x00, 0x13, 0x05, 0x00, 0x07, - 0x03, 0xFF, 0x28, 0x51, 0x00, 0x00, 0x6F, 0xC6, 0x00, 0x00, 0x7D, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC9, 0xCC, 0x23, - 0x28, 0x00, 0x00, 0x71, 0x00, 0x11, 0x04, 0x00, 0x07, 0x03, 0x78, 0x6A, - 0x00, 0x00, 0x00, 0x6F, 0xC6, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xCE, 0x7A, 0x1E, 0x00, 0x00, 0x00, - 0x7B, 0x00, 0x10, 0x03, 0x00, 0x07, 0x07, 0xFF, 0x21, 0x51, 0x00, 0x00, - 0x6F, 0xC6, 0x00, 0x00, 0x1B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x5C, 0x84, 0x23, 0x28, 0x00, 0x00, 0x71, 0x00, 0x15, - 0x06, 0x00, 0x07, 0x03, 0x78, 0x6A, 0x00, 0x00, 0x00, 0x6F, 0xC6, 0x00, - 0x00, 0xD8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xAC, 0x64, 0x1E, 0x00, 0x00, 0x00, 0x71, 0x00, 0x13, 0x05, 0x00, 0x07, - 0x03, 0x78, 0x6A, 0x00, 0x00, 0x00, 0x6F, 0xC6, 0x00, 0x00, 0x7D, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC4, 0x1D, 0x1E, - 0x00, 0x00, 0x00, 0x7C, 0x00, 0x12, 0x04, 0x00, 0x07, 0x07, 0x78, 0x6A, - 0x00, 0x00, 0x00, 0x6F, 0xC6, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x31, 0x1E, 0x00, 0x00, 0x00, - 0x71, 0x00, 0x12, 0x04, 0x00, 0x07, 0x03, 0x78, 0x6A, 0x00, 0x00, 0x00, - 0x6F, 0xC6, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0xF6, 0x40, 0x1E, 0x00, 0x00, 0x00, 0x71, 0x00, 0x16, - 0x06, 0x00, 0x07, 0x03, 0x78, 0x6A, 0x00, 0x00, 0x00, 0x6F, 0xC6, 0x00, - 0x00, 0xD8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x97, 0xAA, 0x1E, 0x00, 0x00, 0x00, 0x71, 0x00, 0x12, 0x04, 0x00, 0x07, - 0x03, 0x78, 0x6A, 0x00, 0x00, 0x00, 0x6F, 0xC6, 0x00, 0x00, 0x40, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x72, 0xE9, 0x1E, - 0x00, 0x00, 0x00, 0x94, 0x00, 0x14, 0x05, 0x00, 0x07, 0x03, 0x78, 0x6A, - 0x00, 0x00, 0x00, 0x6F, 0xC6, 0x00, 0x00, 0x7D, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFB, 0xEC, 0x1E, 0x00, 0x00, 0x00, - 0x24, 0x00, 0x12, 0x04, 0x00, 0x00, 0x02, 0xFF, 0x10, 0x00, 0x00, 0x00, - 0x6F, 0xC6, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x35, 0xC2, 0x23, 0x00, 0x00, 0x00, 0x24, 0x00, 0x11, - 0x04, 0x00, 0x00, 0x02, 0xFF, 0x10, 0x00, 0x00, 0x00, 0x6F, 0xC6, 0x00, - 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x4D, 0x2A, 0x23, 0x00, 0x00, 0x00, 0xA5, 0x00, 0x0E, 0x03, 0x00, 0x00, - 0x00, 0xFF, 0x21, 0x27, 0x00, 0x00, 0x6F, 0xC6, 0x00, 0x00, 0x1B, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2C, 0xBE, 0x23, - 0x1E, 0x00, 0x00, 0x15, 0x00, 0x0F, 0x03, 0x00, 0x00, 0x02, 0xFF, 0x10, - 0x00, 0x39, 0x3B, 0x6F, 0xC6, 0x00, 0x00, 0x39, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x67, 0xE6, 0x23, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x11, 0x64, 0x00, 0x07, 0x03, 0xFF, 0x28, 0x51, 0x00, 0x00, 0x6F, 0xC6, 0x00, 0x00, + 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE6, 0xDE, 0x23, 0x28, 0x00, + 0x00, 0x1F, 0x00, 0x12, 0x04, 0x00, 0x07, 0x03, 0xFF, 0x28, 0x51, 0x00, 0x00, 0x6F, 0xC6, 0x00, + 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5D, 0xD8, 0x23, 0x28, + 0x00, 0x00, 0x70, 0x00, 0x12, 0x04, 0x00, 0x07, 0x03, 0xFF, 0x28, 0x51, 0x00, 0x00, 0x6F, 0xC6, + 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x34, 0x13, 0x23, + 0x28, 0x00, 0x00, 0x70, 0x00, 0x0F, 0x03, 0x00, 0x07, 0x03, 0xFF, 0x28, 0x51, 0x00, 0x00, 0x6F, + 0xC6, 0x00, 0x00, 0x1B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xDA, 0x81, + 0x23, 0x28, 0x00, 0x00, 0x71, 0x00, 0x14, 0x05, 0x00, 0x07, 0x03, 0x78, 0x6A, 0x00, 0x00, 0x00, + 0x6F, 0xC6, 0x00, 0x00, 0x7D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD6, + 0x80, 0x1E, 0x00, 0x00, 0x00, 0x71, 0x00, 0x15, 0x05, 0x00, 0x07, 0x03, 0x78, 0x6A, 0x00, 0x00, + 0x00, 0x6F, 0xC6, 0x00, 0x00, 0x7D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xF7, 0x95, 0x1E, 0x00, 0x00, 0x00, 0x70, 0x00, 0x13, 0x05, 0x00, 0x07, 0x03, 0xFF, 0x28, 0x51, + 0x00, 0x00, 0x6F, 0xC6, 0x00, 0x00, 0x7D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xC9, 0xCC, 0x23, 0x28, 0x00, 0x00, 0x71, 0x00, 0x11, 0x04, 0x00, 0x07, 0x03, 0x78, 0x6A, + 0x00, 0x00, 0x00, 0x6F, 0xC6, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xCE, 0x7A, 0x1E, 0x00, 0x00, 0x00, 0x7B, 0x00, 0x10, 0x03, 0x00, 0x07, 0x07, 0xFF, + 0x21, 0x51, 0x00, 0x00, 0x6F, 0xC6, 0x00, 0x00, 0x1B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x5C, 0x84, 0x23, 0x28, 0x00, 0x00, 0x71, 0x00, 0x15, 0x06, 0x00, 0x07, 0x03, + 0x78, 0x6A, 0x00, 0x00, 0x00, 0x6F, 0xC6, 0x00, 0x00, 0xD8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xAC, 0x64, 0x1E, 0x00, 0x00, 0x00, 0x71, 0x00, 0x13, 0x05, 0x00, 0x07, + 0x03, 0x78, 0x6A, 0x00, 0x00, 0x00, 0x6F, 0xC6, 0x00, 0x00, 0x7D, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xC4, 0x1D, 0x1E, 0x00, 0x00, 0x00, 0x7C, 0x00, 0x12, 0x04, 0x00, + 0x07, 0x07, 0x78, 0x6A, 0x00, 0x00, 0x00, 0x6F, 0xC6, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x31, 0x1E, 0x00, 0x00, 0x00, 0x71, 0x00, 0x12, 0x04, + 0x00, 0x07, 0x03, 0x78, 0x6A, 0x00, 0x00, 0x00, 0x6F, 0xC6, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF6, 0x40, 0x1E, 0x00, 0x00, 0x00, 0x71, 0x00, 0x16, + 0x06, 0x00, 0x07, 0x03, 0x78, 0x6A, 0x00, 0x00, 0x00, 0x6F, 0xC6, 0x00, 0x00, 0xD8, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x97, 0xAA, 0x1E, 0x00, 0x00, 0x00, 0x71, 0x00, + 0x12, 0x04, 0x00, 0x07, 0x03, 0x78, 0x6A, 0x00, 0x00, 0x00, 0x6F, 0xC6, 0x00, 0x00, 0x40, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x72, 0xE9, 0x1E, 0x00, 0x00, 0x00, 0x94, + 0x00, 0x14, 0x05, 0x00, 0x07, 0x03, 0x78, 0x6A, 0x00, 0x00, 0x00, 0x6F, 0xC6, 0x00, 0x00, 0x7D, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFB, 0xEC, 0x1E, 0x00, 0x00, 0x00, + 0x24, 0x00, 0x12, 0x04, 0x00, 0x00, 0x02, 0xFF, 0x10, 0x00, 0x00, 0x00, 0x6F, 0xC6, 0x00, 0x00, + 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x35, 0xC2, 0x23, 0x00, 0x00, + 0x00, 0x24, 0x00, 0x11, 0x04, 0x00, 0x00, 0x02, 0xFF, 0x10, 0x00, 0x00, 0x00, 0x6F, 0xC6, 0x00, + 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4D, 0x2A, 0x23, 0x00, + 0x00, 0x00, 0xA5, 0x00, 0x0E, 0x03, 0x00, 0x00, 0x00, 0xFF, 0x21, 0x27, 0x00, 0x00, 0x6F, 0xC6, + 0x00, 0x00, 0x1B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2C, 0xBE, 0x23, + 0x1E, 0x00, 0x00, 0x15, 0x00, 0x0F, 0x03, 0x00, 0x00, 0x02, 0xFF, 0x10, 0x00, 0x39, 0x3B, 0x6F, + 0xC6, 0x00, 0x00, 0x39, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x67, 0xE6, + 0x23, 0x00, 0x00, 0x00, // Trainer names - 0x80, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, - 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x50, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x50, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x50, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x50, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x50, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x80, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x80, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x80, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x50, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x80, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x50, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x80, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x50, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x80, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x50, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x80, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, + 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x50, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x80, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x50, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x80, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, - 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x50, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x50, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x50, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x50, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x50, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, // Nicknames - 0x96, 0x84, 0x84, 0x83, 0x8B, 0x84, 0x50, 0x50, 0x50, 0x50, 0x50, 0x96, - 0x84, 0x84, 0x83, 0x8B, 0x84, 0x50, 0x50, 0x50, 0x50, 0x50, 0x96, 0x84, - 0x84, 0x83, 0x8B, 0x84, 0x50, 0x50, 0x50, 0x50, 0x50, 0x96, 0x84, 0x84, - 0x83, 0x8B, 0x84, 0x50, 0x50, 0x50, 0x50, 0x50, 0x8A, 0x80, 0x8A, 0x94, - 0x8D, 0x80, 0x50, 0x50, 0x50, 0x50, 0x50, 0x8A, 0x80, 0x8A, 0x94, 0x8D, - 0x80, 0x50, 0x50, 0x50, 0x50, 0x50, 0x96, 0x84, 0x84, 0x83, 0x8B, 0x84, - 0x50, 0x50, 0x50, 0x50, 0x50, 0x8A, 0x80, 0x8A, 0x94, 0x8D, 0x80, 0x50, - 0x50, 0x50, 0x50, 0x50, 0x82, 0x80, 0x93, 0x84, 0x91, 0x8F, 0x88, 0x84, - 0x50, 0x50, 0x50, 0x8A, 0x80, 0x8A, 0x94, 0x8D, 0x80, 0x50, 0x50, 0x50, - 0x50, 0x50, 0x8A, 0x80, 0x8A, 0x94, 0x8D, 0x80, 0x50, 0x50, 0x50, 0x50, - 0x50, 0x8C, 0x84, 0x93, 0x80, 0x8F, 0x8E, 0x83, 0x50, 0x50, 0x50, 0x50, - 0x8A, 0x80, 0x8A, 0x94, 0x8D, 0x80, 0x50, 0x50, 0x50, 0x50, 0x50, 0x8A, - 0x80, 0x8A, 0x94, 0x8D, 0x80, 0x50, 0x50, 0x50, 0x50, 0x50, 0x8A, 0x80, - 0x8A, 0x94, 0x8D, 0x80, 0x50, 0x50, 0x50, 0x50, 0x50, 0x8A, 0x80, 0x8A, - 0x94, 0x8D, 0x80, 0x50, 0x50, 0x50, 0x50, 0x50, 0x8F, 0x88, 0x83, 0x86, - 0x84, 0x98, 0x50, 0x50, 0x50, 0x50, 0x50, 0x8F, 0x88, 0x83, 0x86, 0x84, - 0x98, 0x50, 0x50, 0x50, 0x50, 0x50, 0x91, 0x80, 0x93, 0x93, 0x80, 0x93, - 0x80, 0x50, 0x50, 0x50, 0x50, 0x8F, 0x88, 0x83, 0x86, 0x84, 0x98, 0x50, - 0x50, 0x50, 0x50, 0x50}; + 0x96, 0x84, 0x84, 0x83, 0x8B, 0x84, 0x50, 0x50, 0x50, 0x50, 0x50, 0x96, 0x84, 0x84, 0x83, 0x8B, + 0x84, 0x50, 0x50, 0x50, 0x50, 0x50, 0x96, 0x84, 0x84, 0x83, 0x8B, 0x84, 0x50, 0x50, 0x50, 0x50, + 0x50, 0x96, 0x84, 0x84, 0x83, 0x8B, 0x84, 0x50, 0x50, 0x50, 0x50, 0x50, 0x8A, 0x80, 0x8A, 0x94, + 0x8D, 0x80, 0x50, 0x50, 0x50, 0x50, 0x50, 0x8A, 0x80, 0x8A, 0x94, 0x8D, 0x80, 0x50, 0x50, 0x50, + 0x50, 0x50, 0x96, 0x84, 0x84, 0x83, 0x8B, 0x84, 0x50, 0x50, 0x50, 0x50, 0x50, 0x8A, 0x80, 0x8A, + 0x94, 0x8D, 0x80, 0x50, 0x50, 0x50, 0x50, 0x50, 0x82, 0x80, 0x93, 0x84, 0x91, 0x8F, 0x88, 0x84, + 0x50, 0x50, 0x50, 0x8A, 0x80, 0x8A, 0x94, 0x8D, 0x80, 0x50, 0x50, 0x50, 0x50, 0x50, 0x8A, 0x80, + 0x8A, 0x94, 0x8D, 0x80, 0x50, 0x50, 0x50, 0x50, 0x50, 0x8C, 0x84, 0x93, 0x80, 0x8F, 0x8E, 0x83, + 0x50, 0x50, 0x50, 0x50, 0x8A, 0x80, 0x8A, 0x94, 0x8D, 0x80, 0x50, 0x50, 0x50, 0x50, 0x50, 0x8A, + 0x80, 0x8A, 0x94, 0x8D, 0x80, 0x50, 0x50, 0x50, 0x50, 0x50, 0x8A, 0x80, 0x8A, 0x94, 0x8D, 0x80, + 0x50, 0x50, 0x50, 0x50, 0x50, 0x8A, 0x80, 0x8A, 0x94, 0x8D, 0x80, 0x50, 0x50, 0x50, 0x50, 0x50, + 0x8F, 0x88, 0x83, 0x86, 0x84, 0x98, 0x50, 0x50, 0x50, 0x50, 0x50, 0x8F, 0x88, 0x83, 0x86, 0x84, + 0x98, 0x50, 0x50, 0x50, 0x50, 0x50, 0x91, 0x80, 0x93, 0x93, 0x80, 0x93, 0x80, 0x50, 0x50, 0x50, + 0x50, 0x8F, 0x88, 0x83, 0x86, 0x84, 0x98, 0x50, 0x50, 0x50, 0x50, 0x50}; -static const byte gen2_debug_box_data[0x44E] = {// Num of Pokemon +static const byte gen2_debug_box_data[0x44E] = { + // Num of Pokemon 0x14, // Pokemon 1-20 - 0xD5, 0x7B, 0xE3, 0x9D, 0xC3, 0xD5, 0xD5, 0xC9, 0xC9, 0x2E, 0xFA, 0xFA, - 0xD5, 0xD5, 0xD5, 0xD5, 0xD5, 0xD5, 0xD5, 0xFC, 0xFF, + 0xD5, 0x7B, 0xE3, 0x9D, 0xC3, 0xD5, 0xD5, 0xC9, 0xC9, 0x2E, 0xFA, 0xFA, 0xD5, 0xD5, 0xD5, 0xD5, + 0xD5, 0xD5, 0xD5, 0xFC, 0xFF, // Pokemon list - 0xD5, 0x00, 0x84, 0x6E, 0x23, 0xE3, 0xBB, 0x4C, 0x00, 0x0A, 0x4E, 0x00, - 0x20, 0x00, 0x32, 0x00, 0x23, 0x00, 0x34, 0x00, 0x28, 0x9C, 0x90, 0x23, - 0x28, 0x14, 0x05, 0x58, 0x00, 0x00, 0x00, 0x10, 0x7B, 0x00, 0x62, 0x2B, - 0x74, 0xE4, 0xBB, 0x4C, 0x00, 0x08, 0x95, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0xBA, 0xF9, 0x1E, 0x1E, 0x1E, 0x14, 0x46, - 0x00, 0x00, 0x00, 0x0D, 0xE3, 0x00, 0x13, 0xA8, 0x81, 0x61, 0xBB, 0x4C, - 0x01, 0xC5, 0x71, 0x17, 0x99, 0x1D, 0x33, 0x1B, 0x77, 0x19, 0x7F, 0x18, - 0xB9, 0xDF, 0x87, 0x0F, 0x0A, 0x14, 0x1E, 0xFF, 0x00, 0x00, 0x00, 0x2D, - 0x9D, 0x00, 0xAC, 0x09, 0x59, 0x46, 0xBB, 0x4C, 0x01, 0xAA, 0xDE, 0x23, - 0xE8, 0x2C, 0xCF, 0x29, 0x00, 0x2C, 0xD4, 0x28, 0x55, 0xF6, 0xD7, 0x19, - 0x0F, 0x0A, 0x0F, 0xFF, 0x00, 0x00, 0x00, 0x30, 0xC3, 0x1B, 0xD6, 0x27, - 0x15, 0x37, 0xBB, 0x4C, 0x00, 0x1F, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x8B, 0x10, 0x0A, 0x1E, 0x14, 0x19, 0x4C, - 0x00, 0x00, 0x00, 0x14, 0xD5, 0x00, 0x84, 0x6E, 0x23, 0xE3, 0xBB, 0x4C, - 0x00, 0x0A, 0x4E, 0x00, 0x20, 0x00, 0x32, 0x00, 0x23, 0x00, 0x34, 0x00, - 0x28, 0x2A, 0xAA, 0x23, 0x28, 0x14, 0x05, 0x58, 0x00, 0x00, 0x00, 0x10, - 0xD5, 0x00, 0x84, 0x6E, 0x23, 0xE3, 0xBB, 0x4C, 0x00, 0x0A, 0x4E, 0x00, - 0x20, 0x00, 0x32, 0x00, 0x23, 0x00, 0x34, 0x00, 0x28, 0x9C, 0x90, 0x23, - 0x28, 0x14, 0x05, 0x58, 0x00, 0x00, 0x00, 0x10, 0xC9, 0x00, 0x84, 0x6E, - 0x23, 0xE3, 0xBB, 0x4C, 0x00, 0x0A, 0x4E, 0x00, 0x20, 0x00, 0x32, 0x00, - 0x23, 0x00, 0x34, 0x00, 0x28, 0x22, 0x22, 0x23, 0x28, 0x14, 0x05, 0x58, - 0x00, 0x00, 0x00, 0x10, 0xC9, 0x00, 0x84, 0x6E, 0x23, 0xE3, 0xBB, 0x4C, - 0x00, 0x0A, 0x4E, 0x00, 0x20, 0x00, 0x32, 0x00, 0x23, 0x00, 0x34, 0x00, - 0x28, 0x44, 0x44, 0x23, 0x28, 0x14, 0x05, 0x58, 0x00, 0x00, 0x00, 0x10, - 0x2E, 0x00, 0x84, 0x6E, 0x23, 0xE3, 0xBB, 0x4C, 0x00, 0x0A, 0x4E, 0x00, - 0x20, 0x00, 0x32, 0x00, 0x23, 0x00, 0x34, 0x00, 0x28, 0x9C, 0x90, 0x23, - 0x28, 0x14, 0x05, 0x58, 0x00, 0x00, 0x00, 0x10, 0xFA, 0x00, 0x84, 0x6E, - 0x23, 0xE3, 0xBB, 0x4C, 0x00, 0x0A, 0x4E, 0x00, 0x20, 0x00, 0x32, 0x00, - 0x23, 0x00, 0x34, 0x00, 0x28, 0x2A, 0xAA, 0x23, 0x28, 0x14, 0x05, 0x58, - 0x00, 0x00, 0x00, 0x10, 0xFA, 0x00, 0x84, 0x6E, 0x23, 0xE3, 0xBB, 0x4C, - 0x00, 0x0A, 0x4E, 0x00, 0x20, 0x00, 0x32, 0x00, 0x23, 0x00, 0x34, 0x00, - 0x28, 0x9C, 0x90, 0x23, 0x28, 0x14, 0x05, 0x58, 0x00, 0x00, 0x00, 0x10, - 0xD5, 0x00, 0x84, 0x6E, 0x23, 0xE3, 0xBB, 0x4C, 0x00, 0x0A, 0x4E, 0x00, - 0x20, 0x00, 0x32, 0x00, 0x23, 0x00, 0x34, 0x00, 0x28, 0x9C, 0x90, 0x23, - 0x28, 0x14, 0x05, 0x58, 0x00, 0x00, 0x00, 0x10, 0xD5, 0x00, 0x84, 0x6E, - 0x23, 0xE3, 0xBB, 0x4C, 0x00, 0x0A, 0x4E, 0x00, 0x20, 0x00, 0x32, 0x00, - 0x23, 0x00, 0x34, 0x00, 0x28, 0x9C, 0x90, 0x23, 0x28, 0x14, 0x05, 0x58, - 0x00, 0x00, 0x00, 0x10, 0xD5, 0x00, 0x84, 0x6E, 0x23, 0xE3, 0xBB, 0x4C, - 0x00, 0x0A, 0x4E, 0x00, 0x20, 0x00, 0x32, 0x00, 0x23, 0x00, 0x34, 0x00, - 0x28, 0x9C, 0x90, 0x23, 0x28, 0x14, 0x05, 0x58, 0x00, 0x00, 0x00, 0x10, - 0xD5, 0x00, 0x84, 0x6E, 0x23, 0xE3, 0xBB, 0x4C, 0x00, 0x0A, 0x4E, 0x00, - 0x20, 0x00, 0x32, 0x00, 0x23, 0x00, 0x34, 0x00, 0x28, 0x9C, 0x90, 0x23, - 0x28, 0x14, 0x05, 0x58, 0x00, 0x00, 0x00, 0x10, 0xD5, 0x00, 0x84, 0x6E, - 0x23, 0xE3, 0xBB, 0x4C, 0x00, 0x0A, 0x4E, 0x00, 0x20, 0x00, 0x32, 0x00, - 0x23, 0x00, 0x34, 0x00, 0x28, 0x9C, 0x90, 0x23, 0x28, 0x14, 0x05, 0x58, - 0x00, 0x00, 0x00, 0x10, 0xD5, 0x00, 0x84, 0x6E, 0x23, 0xE3, 0xBB, 0x4C, - 0x00, 0x0A, 0x4E, 0x00, 0x20, 0x00, 0x32, 0x00, 0x23, 0x00, 0x34, 0x00, - 0x28, 0x9C, 0x90, 0x23, 0x28, 0x14, 0x05, 0x58, 0x00, 0x00, 0x00, 0x10, - 0xD5, 0x00, 0x84, 0x6E, 0x23, 0xE3, 0xBB, 0x4C, 0x00, 0x0A, 0x4E, 0x00, - 0x20, 0x00, 0x32, 0x00, 0x23, 0x00, 0x34, 0x00, 0x28, 0x9C, 0x90, 0x23, - 0x28, 0x14, 0x05, 0x58, 0x00, 0x00, 0x00, 0x10, 0xFC, 0x00, 0x84, 0x6E, - 0x23, 0xE3, 0xBB, 0x4C, 0x00, 0x0A, 0x4E, 0x00, 0x20, 0x00, 0x32, 0x00, - 0x23, 0x00, 0x34, 0x00, 0x28, 0x9C, 0x90, 0x23, 0x28, 0x14, 0x05, 0x58, - 0x00, 0x00, 0x00, 0x10, + 0xD5, 0x00, 0x84, 0x6E, 0x23, 0xE3, 0xBB, 0x4C, 0x00, 0x0A, 0x4E, 0x00, 0x20, 0x00, 0x32, 0x00, + 0x23, 0x00, 0x34, 0x00, 0x28, 0x9C, 0x90, 0x23, 0x28, 0x14, 0x05, 0x58, 0x00, 0x00, 0x00, 0x10, + 0x7B, 0x00, 0x62, 0x2B, 0x74, 0xE4, 0xBB, 0x4C, 0x00, 0x08, 0x95, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xBA, 0xF9, 0x1E, 0x1E, 0x1E, 0x14, 0x46, 0x00, 0x00, 0x00, 0x0D, + 0xE3, 0x00, 0x13, 0xA8, 0x81, 0x61, 0xBB, 0x4C, 0x01, 0xC5, 0x71, 0x17, 0x99, 0x1D, 0x33, 0x1B, + 0x77, 0x19, 0x7F, 0x18, 0xB9, 0xDF, 0x87, 0x0F, 0x0A, 0x14, 0x1E, 0xFF, 0x00, 0x00, 0x00, 0x2D, + 0x9D, 0x00, 0xAC, 0x09, 0x59, 0x46, 0xBB, 0x4C, 0x01, 0xAA, 0xDE, 0x23, 0xE8, 0x2C, 0xCF, 0x29, + 0x00, 0x2C, 0xD4, 0x28, 0x55, 0xF6, 0xD7, 0x19, 0x0F, 0x0A, 0x0F, 0xFF, 0x00, 0x00, 0x00, 0x30, + 0xC3, 0x1B, 0xD6, 0x27, 0x15, 0x37, 0xBB, 0x4C, 0x00, 0x1F, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x8B, 0x10, 0x0A, 0x1E, 0x14, 0x19, 0x4C, 0x00, 0x00, 0x00, 0x14, + 0xD5, 0x00, 0x84, 0x6E, 0x23, 0xE3, 0xBB, 0x4C, 0x00, 0x0A, 0x4E, 0x00, 0x20, 0x00, 0x32, 0x00, + 0x23, 0x00, 0x34, 0x00, 0x28, 0x2A, 0xAA, 0x23, 0x28, 0x14, 0x05, 0x58, 0x00, 0x00, 0x00, 0x10, + 0xD5, 0x00, 0x84, 0x6E, 0x23, 0xE3, 0xBB, 0x4C, 0x00, 0x0A, 0x4E, 0x00, 0x20, 0x00, 0x32, 0x00, + 0x23, 0x00, 0x34, 0x00, 0x28, 0x9C, 0x90, 0x23, 0x28, 0x14, 0x05, 0x58, 0x00, 0x00, 0x00, 0x10, + 0xC9, 0x00, 0x84, 0x6E, 0x23, 0xE3, 0xBB, 0x4C, 0x00, 0x0A, 0x4E, 0x00, 0x20, 0x00, 0x32, 0x00, + 0x23, 0x00, 0x34, 0x00, 0x28, 0x22, 0x22, 0x23, 0x28, 0x14, 0x05, 0x58, 0x00, 0x00, 0x00, 0x10, + 0xC9, 0x00, 0x84, 0x6E, 0x23, 0xE3, 0xBB, 0x4C, 0x00, 0x0A, 0x4E, 0x00, 0x20, 0x00, 0x32, 0x00, + 0x23, 0x00, 0x34, 0x00, 0x28, 0x44, 0x44, 0x23, 0x28, 0x14, 0x05, 0x58, 0x00, 0x00, 0x00, 0x10, + 0x2E, 0x00, 0x84, 0x6E, 0x23, 0xE3, 0xBB, 0x4C, 0x00, 0x0A, 0x4E, 0x00, 0x20, 0x00, 0x32, 0x00, + 0x23, 0x00, 0x34, 0x00, 0x28, 0x9C, 0x90, 0x23, 0x28, 0x14, 0x05, 0x58, 0x00, 0x00, 0x00, 0x10, + 0xFA, 0x00, 0x84, 0x6E, 0x23, 0xE3, 0xBB, 0x4C, 0x00, 0x0A, 0x4E, 0x00, 0x20, 0x00, 0x32, 0x00, + 0x23, 0x00, 0x34, 0x00, 0x28, 0x2A, 0xAA, 0x23, 0x28, 0x14, 0x05, 0x58, 0x00, 0x00, 0x00, 0x10, + 0xFA, 0x00, 0x84, 0x6E, 0x23, 0xE3, 0xBB, 0x4C, 0x00, 0x0A, 0x4E, 0x00, 0x20, 0x00, 0x32, 0x00, + 0x23, 0x00, 0x34, 0x00, 0x28, 0x9C, 0x90, 0x23, 0x28, 0x14, 0x05, 0x58, 0x00, 0x00, 0x00, 0x10, + 0xD5, 0x00, 0x84, 0x6E, 0x23, 0xE3, 0xBB, 0x4C, 0x00, 0x0A, 0x4E, 0x00, 0x20, 0x00, 0x32, 0x00, + 0x23, 0x00, 0x34, 0x00, 0x28, 0x9C, 0x90, 0x23, 0x28, 0x14, 0x05, 0x58, 0x00, 0x00, 0x00, 0x10, + 0xD5, 0x00, 0x84, 0x6E, 0x23, 0xE3, 0xBB, 0x4C, 0x00, 0x0A, 0x4E, 0x00, 0x20, 0x00, 0x32, 0x00, + 0x23, 0x00, 0x34, 0x00, 0x28, 0x9C, 0x90, 0x23, 0x28, 0x14, 0x05, 0x58, 0x00, 0x00, 0x00, 0x10, + 0xD5, 0x00, 0x84, 0x6E, 0x23, 0xE3, 0xBB, 0x4C, 0x00, 0x0A, 0x4E, 0x00, 0x20, 0x00, 0x32, 0x00, + 0x23, 0x00, 0x34, 0x00, 0x28, 0x9C, 0x90, 0x23, 0x28, 0x14, 0x05, 0x58, 0x00, 0x00, 0x00, 0x10, + 0xD5, 0x00, 0x84, 0x6E, 0x23, 0xE3, 0xBB, 0x4C, 0x00, 0x0A, 0x4E, 0x00, 0x20, 0x00, 0x32, 0x00, + 0x23, 0x00, 0x34, 0x00, 0x28, 0x9C, 0x90, 0x23, 0x28, 0x14, 0x05, 0x58, 0x00, 0x00, 0x00, 0x10, + 0xD5, 0x00, 0x84, 0x6E, 0x23, 0xE3, 0xBB, 0x4C, 0x00, 0x0A, 0x4E, 0x00, 0x20, 0x00, 0x32, 0x00, + 0x23, 0x00, 0x34, 0x00, 0x28, 0x9C, 0x90, 0x23, 0x28, 0x14, 0x05, 0x58, 0x00, 0x00, 0x00, 0x10, + 0xD5, 0x00, 0x84, 0x6E, 0x23, 0xE3, 0xBB, 0x4C, 0x00, 0x0A, 0x4E, 0x00, 0x20, 0x00, 0x32, 0x00, + 0x23, 0x00, 0x34, 0x00, 0x28, 0x9C, 0x90, 0x23, 0x28, 0x14, 0x05, 0x58, 0x00, 0x00, 0x00, 0x10, + 0xD5, 0x00, 0x84, 0x6E, 0x23, 0xE3, 0xBB, 0x4C, 0x00, 0x0A, 0x4E, 0x00, 0x20, 0x00, 0x32, 0x00, + 0x23, 0x00, 0x34, 0x00, 0x28, 0x9C, 0x90, 0x23, 0x28, 0x14, 0x05, 0x58, 0x00, 0x00, 0x00, 0x10, + 0xFC, 0x00, 0x84, 0x6E, 0x23, 0xE3, 0xBB, 0x4C, 0x00, 0x0A, 0x4E, 0x00, 0x20, 0x00, 0x32, 0x00, + 0x23, 0x00, 0x34, 0x00, 0x28, 0x9C, 0x90, 0x23, 0x28, 0x14, 0x05, 0x58, 0x00, 0x00, 0x00, 0x10, // Trainer names - 0x80, 0x94, 0x92, 0x93, 0x88, 0x8D, 0x50, 0x50, 0x00, 0x00, 0x00, 0x80, - 0x94, 0x92, 0x93, 0x88, 0x8D, 0x50, 0x50, 0x00, 0x00, 0x00, 0x80, 0x94, - 0x92, 0x93, 0x88, 0x8D, 0x50, 0x50, 0x00, 0x00, 0x00, 0x80, 0x94, 0x92, - 0x93, 0x88, 0x8D, 0x50, 0x50, 0x00, 0x00, 0x00, 0x80, 0x94, 0x92, 0x93, - 0x88, 0x8D, 0x50, 0x50, 0x00, 0x00, 0x00, 0x80, 0x94, 0x92, 0x93, 0x88, - 0x8D, 0x50, 0x50, 0x00, 0x00, 0x00, 0x80, 0x94, 0x92, 0x93, 0x88, 0x8D, - 0x50, 0x50, 0x00, 0x00, 0x00, 0x80, 0x94, 0x92, 0x93, 0x88, 0x8D, 0x50, - 0x50, 0x00, 0x00, 0x00, 0x80, 0x94, 0x92, 0x93, 0x88, 0x8D, 0x50, 0x50, - 0x00, 0x00, 0x00, 0x80, 0x94, 0x92, 0x93, 0x88, 0x8D, 0x50, 0x50, 0x00, - 0x00, 0x00, 0x80, 0x94, 0x92, 0x93, 0x88, 0x8D, 0x50, 0x50, 0x00, 0x00, + 0x80, 0x94, 0x92, 0x93, 0x88, 0x8D, 0x50, 0x50, 0x00, 0x00, 0x00, 0x80, 0x94, 0x92, 0x93, 0x88, + 0x8D, 0x50, 0x50, 0x00, 0x00, 0x00, 0x80, 0x94, 0x92, 0x93, 0x88, 0x8D, 0x50, 0x50, 0x00, 0x00, + 0x00, 0x80, 0x94, 0x92, 0x93, 0x88, 0x8D, 0x50, 0x50, 0x00, 0x00, 0x00, 0x80, 0x94, 0x92, 0x93, + 0x88, 0x8D, 0x50, 0x50, 0x00, 0x00, 0x00, 0x80, 0x94, 0x92, 0x93, 0x88, 0x8D, 0x50, 0x50, 0x00, + 0x00, 0x00, 0x80, 0x94, 0x92, 0x93, 0x88, 0x8D, 0x50, 0x50, 0x00, 0x00, 0x00, 0x80, 0x94, 0x92, + 0x93, 0x88, 0x8D, 0x50, 0x50, 0x00, 0x00, 0x00, 0x80, 0x94, 0x92, 0x93, 0x88, 0x8D, 0x50, 0x50, + 0x00, 0x00, 0x00, 0x80, 0x94, 0x92, 0x93, 0x88, 0x8D, 0x50, 0x50, 0x00, 0x00, 0x00, 0x80, 0x94, + 0x92, 0x93, 0x88, 0x8D, 0x50, 0x50, 0x00, 0x00, 0x00, 0x80, 0x94, 0x92, 0x93, 0x88, 0x8D, 0x50, + 0x50, 0x00, 0x00, 0x00, 0x80, 0x94, 0x92, 0x93, 0x88, 0x8D, 0x50, 0x50, 0x00, 0x00, 0x00, 0x80, + 0x94, 0x92, 0x93, 0x88, 0x8D, 0x50, 0x50, 0x00, 0x00, 0x00, 0x80, 0x94, 0x92, 0x93, 0x88, 0x8D, + 0x50, 0x50, 0x00, 0x00, 0x00, 0x80, 0x94, 0x92, 0x93, 0x88, 0x8D, 0x50, 0x50, 0x00, 0x00, 0x00, + 0x80, 0x94, 0x92, 0x93, 0x88, 0x8D, 0x50, 0x50, 0x00, 0x00, 0x00, 0x80, 0x94, 0x92, 0x93, 0x88, + 0x8D, 0x50, 0x50, 0x00, 0x00, 0x00, 0x80, 0x94, 0x92, 0x93, 0x88, 0x8D, 0x50, 0x50, 0x00, 0x00, 0x00, 0x80, 0x94, 0x92, 0x93, 0x88, 0x8D, 0x50, 0x50, 0x00, 0x00, 0x00, - 0x80, 0x94, 0x92, 0x93, 0x88, 0x8D, 0x50, 0x50, 0x00, 0x00, 0x00, 0x80, - 0x94, 0x92, 0x93, 0x88, 0x8D, 0x50, 0x50, 0x00, 0x00, 0x00, 0x80, 0x94, - 0x92, 0x93, 0x88, 0x8D, 0x50, 0x50, 0x00, 0x00, 0x00, 0x80, 0x94, 0x92, - 0x93, 0x88, 0x8D, 0x50, 0x50, 0x00, 0x00, 0x00, 0x80, 0x94, 0x92, 0x93, - 0x88, 0x8D, 0x50, 0x50, 0x00, 0x00, 0x00, 0x80, 0x94, 0x92, 0x93, 0x88, - 0x8D, 0x50, 0x50, 0x00, 0x00, 0x00, 0x80, 0x94, 0x92, 0x93, 0x88, 0x8D, - 0x50, 0x50, 0x00, 0x00, 0x00, 0x80, 0x94, 0x92, 0x93, 0x88, 0x8D, 0x50, - 0x50, 0x00, 0x00, 0x00, // Nicknames - 0x92, 0x87, 0x94, 0x82, 0x8A, 0x8B, 0x84, 0x50, 0x80, 0x81, 0x82, 0x92, - 0x82, 0x98, 0x93, 0x87, 0x84, 0x91, 0x50, 0x50, 0x50, 0x50, 0x82, 0x80, - 0x8C, 0x84, 0x8B, 0x8E, 0x93, 0x50, 0x50, 0x50, 0x50, 0x93, 0x88, 0x8C, - 0x8D, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x90, 0xF3, 0x80, 0x9B, - 0xE6, 0x9C, 0x91, 0x9E, 0x50, 0x50, 0x50, 0x92, 0x87, 0x94, 0x82, 0x8A, - 0x8B, 0x84, 0x50, 0x50, 0x50, 0x50, 0x92, 0x87, 0x94, 0x82, 0x8A, 0x8B, - 0x84, 0x50, 0x50, 0x50, 0x50, 0x92, 0x87, 0x94, 0x82, 0x8A, 0x8B, 0x84, - 0x50, 0x50, 0x50, 0x50, 0x92, 0x87, 0x94, 0x82, 0x8A, 0x8B, 0x84, 0x50, - 0x50, 0x50, 0x50, 0x92, 0x87, 0x94, 0x82, 0x8A, 0x8B, 0x84, 0x50, 0x50, - 0x50, 0x50, 0x92, 0x87, 0x94, 0x82, 0x8A, 0x8B, 0x84, 0x50, 0x50, 0x50, - 0x50, 0x92, 0x87, 0x94, 0x82, 0x8A, 0x8B, 0x84, 0x50, 0x50, 0x50, 0x50, - 0x92, 0x87, 0x94, 0x82, 0x8A, 0x8B, 0x84, 0x50, 0x50, 0x50, 0x50, 0x92, - 0x87, 0x94, 0x82, 0x8A, 0x8B, 0x84, 0x50, 0x50, 0x50, 0x50, 0x92, 0x87, - 0x94, 0x82, 0x8A, 0x8B, 0x84, 0x50, 0x50, 0x50, 0x50, 0x92, 0x87, 0x94, - 0x82, 0x8A, 0x8B, 0x84, 0x50, 0x50, 0x50, 0x50, 0x92, 0x87, 0x94, 0x82, - 0x8A, 0x8B, 0x84, 0x50, 0x50, 0x50, 0x50, 0x92, 0x87, 0x94, 0x82, 0x8A, - 0x8B, 0x84, 0x50, 0x50, 0x50, 0x50, 0x92, 0x87, 0x94, 0x82, 0x8A, 0x8B, - 0x84, 0x50, 0x50, 0x50, 0x50, 0x92, 0x87, 0x94, 0x82, 0x8A, 0x8B, 0x84, - 0x50, 0x50, 0x50, 0x50}; + 0x92, 0x87, 0x94, 0x82, 0x8A, 0x8B, 0x84, 0x50, 0x80, 0x81, 0x82, 0x92, 0x82, 0x98, 0x93, 0x87, + 0x84, 0x91, 0x50, 0x50, 0x50, 0x50, 0x82, 0x80, 0x8C, 0x84, 0x8B, 0x8E, 0x93, 0x50, 0x50, 0x50, + 0x50, 0x93, 0x88, 0x8C, 0x8D, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x90, 0xF3, 0x80, 0x9B, + 0xE6, 0x9C, 0x91, 0x9E, 0x50, 0x50, 0x50, 0x92, 0x87, 0x94, 0x82, 0x8A, 0x8B, 0x84, 0x50, 0x50, + 0x50, 0x50, 0x92, 0x87, 0x94, 0x82, 0x8A, 0x8B, 0x84, 0x50, 0x50, 0x50, 0x50, 0x92, 0x87, 0x94, + 0x82, 0x8A, 0x8B, 0x84, 0x50, 0x50, 0x50, 0x50, 0x92, 0x87, 0x94, 0x82, 0x8A, 0x8B, 0x84, 0x50, + 0x50, 0x50, 0x50, 0x92, 0x87, 0x94, 0x82, 0x8A, 0x8B, 0x84, 0x50, 0x50, 0x50, 0x50, 0x92, 0x87, + 0x94, 0x82, 0x8A, 0x8B, 0x84, 0x50, 0x50, 0x50, 0x50, 0x92, 0x87, 0x94, 0x82, 0x8A, 0x8B, 0x84, + 0x50, 0x50, 0x50, 0x50, 0x92, 0x87, 0x94, 0x82, 0x8A, 0x8B, 0x84, 0x50, 0x50, 0x50, 0x50, 0x92, + 0x87, 0x94, 0x82, 0x8A, 0x8B, 0x84, 0x50, 0x50, 0x50, 0x50, 0x92, 0x87, 0x94, 0x82, 0x8A, 0x8B, + 0x84, 0x50, 0x50, 0x50, 0x50, 0x92, 0x87, 0x94, 0x82, 0x8A, 0x8B, 0x84, 0x50, 0x50, 0x50, 0x50, + 0x92, 0x87, 0x94, 0x82, 0x8A, 0x8B, 0x84, 0x50, 0x50, 0x50, 0x50, 0x92, 0x87, 0x94, 0x82, 0x8A, + 0x8B, 0x84, 0x50, 0x50, 0x50, 0x50, 0x92, 0x87, 0x94, 0x82, 0x8A, 0x8B, 0x84, 0x50, 0x50, 0x50, + 0x50, 0x92, 0x87, 0x94, 0x82, 0x8A, 0x8B, 0x84, 0x50, 0x50, 0x50, 0x50}; #endif \ No newline at end of file diff --git a/include/select_menu.h b/include/select_menu.h index 7deb53f..cff76a9 100644 --- a/include/select_menu.h +++ b/include/select_menu.h @@ -7,20 +7,17 @@ #define LANG_MENU 1 #define CART_MENU 2 -class Select_Menu : public vertical_menu_cursor_handler, - public i_run_cycle_handler +class Select_Menu : public vertical_menu_cursor_handler, public i_run_cycle_handler { public: - Select_Menu( - bool enable_cancel, u8 nMenu_type, unsigned nStartX, unsigned nStartY); + Select_Menu(bool enable_cancel, u8 nMenu_type, unsigned nStartX, unsigned nStartY); int select_menu_main(); void add_option(const u8 option, u8 return_value); void clear_options(); void set_lang(u8 nLang); void on_hide() override; - void on_selection_changed( - unsigned new_index, unsigned x, unsigned y) override; + void on_selection_changed(unsigned new_index, unsigned x, unsigned y) override; void on_run_cycle() override; diff --git a/include/sound.h b/include/sound.h index 5ad8d49..7487f79 100644 --- a/include/sound.h +++ b/include/sound.h @@ -13,22 +13,21 @@ extern "C" typedef unsigned short PTGBSFXHandle; /** - * @brief The API's defined here are a thin abstraction layer over the sound - * engine functions. This allows the underlying sound engine to be swapped - * out without affecting the rest of the codebase. + * @brief The API's defined here are a thin abstraction layer over the sound engine functions. + * This allows the underlying sound engine to be swapped out without affecting the rest of the + * codebase. */ /** - * @brief This function initializes the sound engine and sets up a VBLANK - * handler to process audio every frame. It should be called during the - * initialization phase of the program. + * @brief This function initializes the sound engine and sets up a VBLANK handler + * to process audio every frame. It should be called during the initialization phase of the + * program. */ bool sound_init(void); /** * @brief This function starts playing the song at the given index. - * If loop is true, the song will loop indefinitely until stopped or another - * song is played. + * If loop is true, the song will loop indefinitely until stopped or another song is played. * * @param song_index The index of the song to play. * @param loop Whether the song should loop indefinitely. @@ -49,9 +48,9 @@ extern "C" /** * @brief This function plays the sound effect at the given index. - * Sound effects are typically short audio clips that play in response to - * specific events in the game, such as button presses or character actions. - * These are usually raw PCM samples (e.g., WAV files) + * Sound effects are typically short audio clips that play in response to specific events in the + * game, such as button presses or character actions. These are usually raw PCM samples (e.g., + * WAV files) * * To play a MOD- S3M- XM- or IT format based sound effect, * use the play_jingle function instead. @@ -59,8 +58,7 @@ extern "C" PTGBSFXHandle play_sound_effect(u32 sound_effect_index); /** - * @brief This function stops the given sound effect from playing and - * invalidates the handle + * @brief This function stops the given sound effect from playing and invalidates the handle */ void stop_sound_effect(PTGBSFXHandle handle); @@ -71,20 +69,18 @@ extern "C" /** * @brief This function marks the sound effect as unimportant, - * allowing the sound engine to stop it if it needs to free up channels for - * new sound effects. + * allowing the sound engine to stop it if it needs to free up channels for new sound effects. * - * It also invalidates the handle, so it should not be used after calling - * this function. + * It also invalidates the handle, so it should not be used after calling this function. */ void release_sound_effect(PTGBSFXHandle handle); /** * @brief This function plays a jingle at the given index. - * A jingle is a sound effect that is based on a tracker format like MOD, - * S3M, XM, or IT. They can be played simultaneously with songs. If you want - * to play PCM-based sound effects (e.g., WAV files), use the - * play_sound_effect function instead. + * A jingle is a sound effect that is based on a tracker format like MOD, S3M, XM, or IT. + * They can be played simultaneously with songs. + * If you want to play PCM-based sound effects (e.g., WAV files), use the play_sound_effect + * function instead. * * Note that jingles must be limited to 4 channels only. * (https://blocksds.skylyrac.net/maxmod/group__gba__jingle__playback.html) diff --git a/include/sprite_data.h b/include/sprite_data.h index a81cba4..78e38e6 100644 --- a/include/sprite_data.h +++ b/include/sprite_data.h @@ -155,20 +155,18 @@ enum FlexBackground extern rom_data curr_GBA_rom; -void load_sprite(OBJ_ATTR *sprite, const unsigned int objTiles[], - int objTilesLen, u32 &tile_id, u32 pal_bank, int attr0, int attr1, - u32 priority); +void load_sprite(OBJ_ATTR *sprite, const unsigned int objTiles[], int objTilesLen, u32 &tile_id, + u32 pal_bank, int attr0, int attr1, u32 priority); -void load_sprite_compressed(OBJ_ATTR *sprite, const unsigned int objTiles[], - u32 &tile_id, u32 pal_bank, int attr0, int attr1, u32 priority); +void load_sprite_compressed(OBJ_ATTR *sprite, const unsigned int objTiles[], u32 &tile_id, + u32 pal_bank, int attr0, int attr1, u32 priority); void load_background(); void set_background_pal(int curr_rom_id, bool dark, bool fade); void load_textbox_background(); void load_flex_background(FlexBackground background_id, int layer); void load_eternal_sprites(); void load_temp_box_sprites(PokeBox *box); -void load_type_sprites( - const u8 *pkmn_type_table, int pkmn_index, int dex_offset, bool is_caught); +void load_type_sprites(const u8 *pkmn_type_table, int pkmn_index, int dex_offset, bool is_caught); void add_menu_box(int options, int startTileX, int startTileY); void add_menu_box(int startTileX, int startTileY, int width, int height); void reload_textbox_background(); diff --git a/include/text_engine.h b/include/text_engine.h index ca94547..9571eb9 100644 --- a/include/text_engine.h +++ b/include/text_engine.h @@ -19,13 +19,12 @@ void init_text_engine(); int text_loop(int script); int text_next_obj_id(script_obj current_line); void set_text_exit(); -int ptgb_write_textbox(const byte *text, bool instant, bool waitForUser, - int text_section, int text_key, bool eraseMainBox); +int ptgb_write_textbox(const byte *text, bool instant, bool waitForUser, int text_section, + int text_key, bool eraseMainBox); int ptgb_write_simple(const byte *text, bool instant); int ptgb_write(const byte *text, bool instant, int length, int box_type); int ptgb_write_debug(const u16 *charset, const char *text, bool instant); void wait_for_user_to_continue(int right, int bottom); -void scroll_text(bool instant, TTC *tc, bool scrollUp, int left, int top, - int right, int bottom); +void scroll_text(bool instant, TTC *tc, bool scrollUp, int left, int top, int right, int bottom); #endif \ No newline at end of file diff --git a/include/text_tables.h b/include/text_tables.h index a6e7f11..6306cd2 100644 --- a/include/text_tables.h +++ b/include/text_tables.h @@ -7,8 +7,8 @@ extern "C" { /** - * @brief This function returns a list of pointers to the text table chunks - * and the number of chunks. + * @brief This function returns a list of pointers to the text table chunks and the number of + * chunks. */ void get_text_table_chunks( u32 tableIndex, const u8 ***chunkList, u32 *numChunks, u32 *chunkSize); diff --git a/include/vertical_menu.h b/include/vertical_menu.h index 8f15258..db92b32 100644 --- a/include/vertical_menu.h +++ b/include/vertical_menu.h @@ -16,9 +16,8 @@ enum class MenuInputHandleState */ HANDLED, /** - * @brief Same as HANDLED, but also indicates that the viewport should be - * updated. degrades to HANDLED after passing through - * vertical_menu::handle_input() + * @brief Same as HANDLED, but also indicates that the viewport should be updated. + * degrades to HANDLED after passing through vertical_menu::handle_input() */ HANDLED_UPDATE_VIEWPORT, /** @@ -42,8 +41,8 @@ class i_item_widget { public: virtual ~i_item_widget(); - virtual void render_item(FileContainerReader &text_table, unsigned x, - unsigned y, bool is_focused) = 0; + virtual void render_item( + FileContainerReader &text_table, unsigned x, unsigned y, bool is_focused) = 0; virtual MenuInputHandleState handle_input() = 0; protected: @@ -62,8 +61,7 @@ class i_vertical_menu_state_changed_handler virtual void on_show() = 0; virtual void on_hide() = 0; - virtual void on_selection_changed( - unsigned new_index, unsigned x, unsigned y) = 0; + virtual void on_selection_changed(unsigned new_index, unsigned x, unsigned y) = 0; protected: private: @@ -93,14 +91,12 @@ typedef struct vertical_menu_settings unsigned height; /** - * @brief The top margin (in pixels) after which we start rendering the - * first menu item. + * @brief The top margin (in pixels) after which we start rendering the first menu item. */ unsigned margin_top; /** - * @brief The bottom margin (in pixels) after which we stop rendering the - * last menu item. + * @brief The bottom margin (in pixels) after which we stop rendering the last menu item. */ unsigned margin_bottom; @@ -110,8 +106,7 @@ typedef struct vertical_menu_settings unsigned initial_focus_index; /** - * @brief The height of each menu item in pixels. Will be used to position - * the items. + * @brief The height of each menu item in pixels. Will be used to position the items. */ unsigned item_height; @@ -173,8 +168,7 @@ class vertical_menu * @brief This function adds an item widget to the menu. * The menu will take ownership of the pointer, if * settings_.should_delete_item_widgets_on_destruct is true. - * Otherwise, the caller is responsible for managing the memory of the item - * widgets. + * Otherwise, the caller is responsible for managing the memory of the item widgets. */ void add_item_widget(i_item_widget *item_widget); @@ -220,8 +214,8 @@ class vertical_menu * manually. * * @return Will return the index of the chosen item if a choice was made, - * or UINT32_MAX if no choice was made and the menu was exited in some other - * way (ex: B button). + * or UINT32_MAX if no choice was made and the menu was exited in some other way + * (ex: B button). */ unsigned run(); @@ -229,8 +223,7 @@ class vertical_menu * @brief Sets the optional state changed handler. * This is useful for managing external components, such as a cursor. */ - void set_state_changed_handler( - i_vertical_menu_state_changed_handler *handler); + void set_state_changed_handler(i_vertical_menu_state_changed_handler *handler); /** * @brief This function sets a handler that will run on every @@ -264,8 +257,8 @@ typedef struct simple_item_widget_data struct { /** - * @brief The index of the text table (see vertical_menu_settings) entry - * to use as the label of this item. + * @brief The index of the text table (see vertical_menu_settings) entry to use as the label + * of this item. */ unsigned text_table_index; @@ -280,25 +273,24 @@ typedef struct simple_item_widget_data } text; /** - * @brief The value this widget represents. This is useful for choice/input - * handling. But it won't be used if an on_execute_callback is set. + * @brief The value this widget represents. This is useful for choice/input handling. + * But it won't be used if an on_execute_callback is set. */ unsigned value; /** - * @brief Optional execute callback. This will be executed when the user - * presses A while this item is focused. If this is nullptr, then - * MenuInputHandleState::CHOICE_MADE will be returned when the user presses - * A, and the caller can check the value field to know what choice was made. + * @brief Optional execute callback. This will be executed when the user presses A while this + * item is focused. If this is nullptr, then MenuInputHandleState::CHOICE_MADE will be returned + * when the user presses A, and the caller can check the value field to know what choice was + * made. */ void (*on_execute_callback)(void *context); } simple_item_widget_data; /** - * @brief This is the simplest possible item widget, which will just render a - * single line of text for a single item and allow you to press A to execute a - * callback. It's useful for simple menus that don't require toggles or multiple - * options. + * @brief This is the simplest possible item widget, which will just render a single line of text + * for a single item and allow you to press A to execute a callback. It's useful for simple menus + * that don't require toggles or multiple options. */ class simple_item_renderer : public i_item_widget { @@ -308,8 +300,8 @@ class simple_item_renderer : public i_item_widget const simple_item_widget_data &get_data() const; - void render_item(FileContainerReader &text_table, unsigned x, unsigned y, - bool is_focused) override; + void render_item( + FileContainerReader &text_table, unsigned x, unsigned y, bool is_focused) override; MenuInputHandleState handle_input() override; protected: diff --git a/include/vertical_menu_cursor_handler.h b/include/vertical_menu_cursor_handler.h index 60ba6c7..22a764e 100644 --- a/include/vertical_menu_cursor_handler.h +++ b/include/vertical_menu_cursor_handler.h @@ -6,8 +6,7 @@ /** * @brief This class handles the cursor behavior for a vertical menu. */ -class vertical_menu_cursor_handler - : public i_vertical_menu_state_changed_handler +class vertical_menu_cursor_handler : public i_vertical_menu_state_changed_handler { public: vertical_menu_cursor_handler(s16 cursor_offset_x, s16 cursor_offset_y); @@ -15,8 +14,7 @@ class vertical_menu_cursor_handler void on_show() override; void on_hide() override; - void on_selection_changed( - unsigned new_index, unsigned x, unsigned y) override; + void on_selection_changed(unsigned new_index, unsigned x, unsigned y) override; protected: private: diff --git a/source/FileContainerReader.cpp b/source/FileContainerReader.cpp index 4174405..5da18b2 100644 --- a/source/FileContainerReader.cpp +++ b/source/FileContainerReader.cpp @@ -6,11 +6,10 @@ #define FILE_CONTAINER_HEADER_SIZE 4 #define FILE_INDEX_ENTRY_SIZE 2 -FileContainerReader::FileContainerReader( - const u8 **chunkList, u32 chunkCount, u32 chunkSize) +FileContainerReader::FileContainerReader(const u8 **chunkList, u32 chunkCount, u32 chunkSize) : fileNameBuffer_(), decompressionBuffer_(nullptr), chunkList_(chunkList), - chunkCount_(chunkCount), chunkSize_(chunkSize), fileIndex_(nullptr), - curChunkIndex_(0), curPos_(0), fileCount_(0), hasNames_(false) + chunkCount_(chunkCount), chunkSize_(chunkSize), fileIndex_(nullptr), curChunkIndex_(0), + curPos_(0), fileCount_(0), hasNames_(false) { } @@ -23,8 +22,7 @@ FileContainerReader::~FileContainerReader() } } -bool FileContainerReader::init( - u8 *decompressionBuffer, u32 decompressionBufferSize) +bool FileContainerReader::init(u8 *decompressionBuffer, u32 decompressionBufferSize) { if (decompressionBufferSize < chunkSize_) { @@ -60,15 +58,14 @@ const char *FileContainerReader::getFileName(u32 fileIndex) return nullptr; } - // the file names are stored right after the file index, and each name is 16 - // bytes long. + // the file names are stored right after the file index, and each name is 16 bytes long. const u32 indexSize = fileCount_ * FILE_INDEX_ENTRY_SIZE; const u32 nameTableStartPos = FILE_CONTAINER_HEADER_SIZE + indexSize; seek(nameTableStartPos + (fileIndex * FILE_NAME_LENGTH)); // Now copy the file name to a local buffer. - // the reason is that not every string is necessarily null terminated in the - // fileocontainer data. + // the reason is that not every string is necessarily null terminated in the fileocontainer + // data. read((u8 *)fileNameBuffer_, FILE_NAME_LENGTH); fileNameBuffer_[FILE_NAME_LENGTH] = '\0'; return fileNameBuffer_; @@ -101,9 +98,8 @@ void FileContainerReader::read(u8 *buffer, u32 size) } const u32 bytesRemainingInChunk = chunkSize_ - curPos_; - const u32 bytesToRead = bytesRemaining < bytesRemainingInChunk - ? bytesRemaining - : bytesRemainingInChunk; + const u32 bytesToRead = + bytesRemaining < bytesRemainingInChunk ? bytesRemaining : bytesRemainingInChunk; memcpy(buffer, decompressionBuffer_ + curPos_, bytesToRead); bytesRemaining -= bytesToRead; @@ -137,8 +133,7 @@ u32 FileContainerReader::getFileOffset(u32 entryIndex) const // - file index (fileCount * 2 bytes) // - optional name table (fileCount * 16 bytes) // - u32 offset = - FILE_CONTAINER_HEADER_SIZE + (fileCount_ * FILE_INDEX_ENTRY_SIZE); + u32 offset = FILE_CONTAINER_HEADER_SIZE + (fileCount_ * FILE_INDEX_ENTRY_SIZE); if (hasNames_) { offset += fileCount_ * FILE_NAME_LENGTH; diff --git a/source/Gen3CartridgeSaveReader.cpp b/source/Gen3CartridgeSaveReader.cpp index d585eca..867920a 100644 --- a/source/Gen3CartridgeSaveReader.cpp +++ b/source/Gen3CartridgeSaveReader.cpp @@ -6,8 +6,7 @@ #define HALL_OF_FAME 0x01C000 Gen3CartridgeSaveReader::Gen3CartridgeSaveReader(u8 *sector_buffer) - : sector_start_(0xFFFFFFFF), sector_buffer_(sector_buffer), - cur_(sector_buffer), dirty_(false) + : sector_start_(0xFFFFFFFF), sector_buffer_(sector_buffer), cur_(sector_buffer), dirty_(false) { seek(0); } @@ -26,27 +25,24 @@ void Gen3CartridgeSaveReader::readUint8(u8 &outByte) ++cur_; } -void Gen3CartridgeSaveReader::readUint16( - u16 &outWord, Endianness fieldEndianness) +void Gen3CartridgeSaveReader::readUint16(u16 &outWord, Endianness fieldEndianness) { // Right now we only support little endian (no need for big endian thus far) (void)fieldEndianness; - // The read is implemented this way to avoid any issues with unaligned - // reads. see writeUint16 for more details. + // The read is implemented this way to avoid any issues with unaligned reads. + // see writeUint16 for more details. outWord = static_cast(cur_[0]) | (static_cast(cur_[1]) << 8); cur_ += sizeof(u16); } -void Gen3CartridgeSaveReader::readUint32( - u32 &outDWord, Endianness fieldEndianness) +void Gen3CartridgeSaveReader::readUint32(u32 &outDWord, Endianness fieldEndianness) { // Right now we only support little endian (no need for big endian thus far) (void)fieldEndianness; - // The read is implemented this way to avoid any issues with unaligned - // reads. see writeUint16 for more details. + // The read is implemented this way to avoid any issues with unaligned reads. + // see writeUint16 for more details. outDWord = static_cast(cur_[0]) | (static_cast(cur_[1]) << 8) | - (static_cast(cur_[2]) << 16) | - (static_cast(cur_[3]) << 24); + (static_cast(cur_[2]) << 16) | (static_cast(cur_[3]) << 24); cur_ += sizeof(u32); } @@ -68,12 +64,11 @@ void Gen3CartridgeSaveReader::writeUint16(u16 value, Endianness fieldEndianness) { // Right now we only support little endian (no need for big endian thus far) (void)fieldEndianness; - // The write is implemented this way to avoid any issues with unaligned - // writes. I tried + // The write is implemented this way to avoid any issues with unaligned writes. + // I tried // *((u16*)cur_) = value; - // earlier, but when cur_ was set to 0x0019, this caused undefined - // behaviour. (specifically the word was written 1 byte earlier than it - // should've been) + // earlier, but when cur_ was set to 0x0019, this caused undefined behaviour. + // (specifically the word was written 1 byte earlier than it should've been) cur_[0] = static_cast(value & 0xFF); cur_[1] = static_cast(value >> 8); cur_ += sizeof(u16); @@ -84,8 +79,8 @@ void Gen3CartridgeSaveReader::writeUint32(u32 value, Endianness fieldEndianness) { // Right now we only support little endian (no need for big endian thus far) (void)fieldEndianness; - // The write is implemented this way to avoid any issues with unaligned - // writes. see writeUint16 for more details. + // The write is implemented this way to avoid any issues with unaligned writes. + // see writeUint16 for more details. cur_[0] = static_cast(value & 0xFF); cur_[1] = static_cast((value >> 8) & 0xFF); cur_[2] = static_cast((value >> 16) & 0xFF); @@ -138,16 +133,11 @@ void Gen3CartridgeSaveReader::flush() return; } - update_memory_buffer_checksum( - sector_buffer_, (sector_start_ == HALL_OF_FAME)); - // Real flash requires erase before rewriting bytes that may need 0->1 - // transitions. + update_memory_buffer_checksum(sector_buffer_, (sector_start_ == HALL_OF_FAME)); + // Real flash requires erase before rewriting bytes that may need 0->1 transitions. erase_sector(sector_start_); copy_ram_to_save(sector_buffer_, sector_start_, SECTOR_SIZE); dirty_ = false; } -bool Gen3CartridgeSaveReader::shouldRecalculateChecksumsOnFinish() const -{ - return false; -} \ No newline at end of file +bool Gen3CartridgeSaveReader::shouldRecalculateChecksumsOnFinish() const { return false; } \ No newline at end of file diff --git a/source/background_engine.cpp b/source/background_engine.cpp index 037d9da..68437ba 100644 --- a/source/background_engine.cpp +++ b/source/background_engine.cpp @@ -19,8 +19,8 @@ void background_frame(int global_frame_count) } } -// This could honestly be an object... might want to do that in the future, -// depending on how complex using this gets +// This could honestly be an object... might want to do that in the future, depending on how complex +// using this gets void create_textbox(int text_section, int text_key, bool eraseMainBox) { const u8 box_type = text_box_type_tables[text_section][text_key]; @@ -29,32 +29,25 @@ void create_textbox(int text_section, int text_key, bool eraseMainBox) void create_textbox(u8 textbox_type, bool eraseMainBox) { - const int startTileX = - box_type_info[textbox_type][BOX_TYPE_VAL_START_TILE_X]; - const int startTileY = - box_type_info[textbox_type][BOX_TYPE_VAL_START_TILE_Y]; - const int text_space_width = - box_type_info[textbox_type][BOX_TYPE_VAL_PIXELS_PER_LINE]; - const int text_space_height = - box_type_info[textbox_type][BOX_TYPE_VAL_NUM_OF_LINES] * 16; + const int startTileX = box_type_info[textbox_type][BOX_TYPE_VAL_START_TILE_X]; + const int startTileY = box_type_info[textbox_type][BOX_TYPE_VAL_START_TILE_Y]; + const int text_space_width = box_type_info[textbox_type][BOX_TYPE_VAL_PIXELS_PER_LINE]; + const int text_space_height = box_type_info[textbox_type][BOX_TYPE_VAL_NUM_OF_LINES] * 16; - create_textbox(startTileX, startTileY, text_space_width, text_space_height, - eraseMainBox); + create_textbox(startTileX, startTileY, text_space_width, text_space_height, eraseMainBox); } -void create_textbox(int startTileX, int startTileY, int text_space_width, - int text_space_height, bool eraseMainBox) +void create_textbox( + int startTileX, int startTileY, int text_space_width, int text_space_height, bool eraseMainBox) { if (eraseMainBox) { erase_textbox_tiles(); } - add_menu_box( - startTileX, startTileY, text_space_width + 16, text_space_height + 16); + add_menu_box(startTileX, startTileY, text_space_width + 16, text_space_height + 16); tte_set_pos((startTileX + 1) * 8, (startTileY + 1) * 8); tte_set_margins((startTileX + 1) * 8, (startTileY + 1) * 8, - ((startTileX + 1) * 8) + text_space_width, - ((startTileY + 1) * 8) + text_space_height); + ((startTileX + 1) * 8) + text_space_width, ((startTileY + 1) * 8) + text_space_height); tte_erase_rect(0, 0, H_MAX, V_MAX); show_textbox(); } diff --git a/source/box_menu.cpp b/source/box_menu.cpp index 22fe0de..014c20a 100644 --- a/source/box_menu.cpp +++ b/source/box_menu.cpp @@ -55,8 +55,7 @@ int Box_Menu::box_main(PokeBox *box, Version vers) obj_unhide(box_select, 0); int index = 0; - namesReader.init( - names_decompression_buffer, sizeof(names_decompression_buffer)); + namesReader.init(names_decompression_buffer, sizeof(names_decompression_buffer)); while (true) { @@ -146,8 +145,7 @@ int Box_Menu::box_main(PokeBox *box, Version vers) if (update_pos) { index = x + (y * BOXMENU_HNUM); - obj_set_pos(box_select, - BOXMENU_LEFT + (x * (BOXMENU_SPRITE_WIDTH + BOXMENU_HSPACE)), + obj_set_pos(box_select, BOXMENU_LEFT + (x * (BOXMENU_SPRITE_WIDTH + BOXMENU_HSPACE)), BOXMENU_TOP + (y * (BOXMENU_SPRITE_HEIGHT + BOXMENU_VSPACE))); tte_erase_rect(6, 16, 80, 152); GBPokemon *curr_pkmn = box->getGBPokemon(index); @@ -159,12 +157,9 @@ int Box_Menu::box_main(PokeBox *box, Version vers) tte_set_pos(6, 88); if ( - // Only the name if the language is either both Japanese or - // neither is Japanese - ((curr_pkmn->getLanguage() == JAPANESE) && - (PTGB_BUILD_LANGUAGE == JPN_ID)) || - ((curr_pkmn->getLanguage() != JAPANESE) && - (PTGB_BUILD_LANGUAGE != JPN_ID))) + // Only the name if the language is either both Japanese or neither is Japanese + ((curr_pkmn->getLanguage() == JAPANESE) && (PTGB_BUILD_LANGUAGE == JPN_ID)) || + ((curr_pkmn->getLanguage() != JAPANESE) && (PTGB_BUILD_LANGUAGE != JPN_ID))) { curr_pkmn->externalConvertNickname(&pkmnTables, val); ptgb_write_simple(val, true); @@ -192,8 +187,8 @@ int Box_Menu::box_main(PokeBox *box, Version vers) val[3] = 0x00; // " " val[4] = 0xFF; // endline ptgb_write_simple(val, true); - convert_int_to_ptgb_str(curr_pkmn->getLevel(), - val); // Val should never go out of bounds + convert_int_to_ptgb_str( + curr_pkmn->getLevel(), val); // Val should never go out of bounds ptgb_write_simple(val, true); update_front_box_sprite(curr_pkmn, true); diff --git a/source/button_menu.cpp b/source/button_menu.cpp index f1e7580..ba4f8b6 100644 --- a/source/button_menu.cpp +++ b/source/button_menu.cpp @@ -5,8 +5,8 @@ #include "string" #include -Button_Menu::Button_Menu(int nRows, int nColumns, int nButton_width, - int nButton_height, bool enable_cancel) +Button_Menu::Button_Menu( + int nRows, int nColumns, int nButton_width, int nButton_height, bool enable_cancel) { columns = nColumns; rows = nRows; @@ -62,8 +62,7 @@ int Button_Menu::button_main() } } else if (key_hit(KEY_LEFT) && - ((curr_x > 0) || ((curr_x == 0) && (curr_y == rows - 1) && - (offset_value > 0)))) + ((curr_x > 0) || ((curr_x == 0) && (curr_y == rows - 1) && (offset_value > 0)))) { if (curr_x == 0 && offset_value > 0) { @@ -128,31 +127,23 @@ void Button_Menu::hide_buttons() void Button_Menu::organize_buttons() { - // Total space, minus the space taken up by the buttons, divided by the - // spaces between the buttons. - int vertical_space = - ((y_max - y_min) - (rows * button_height)) / (rows + 1); - int horizontal_space = - ((x_max - x_min) - (columns * button_width)) / (columns + 1); - bottom_offset = ((horizontal_space + button_width) * - ((rows * columns) - button_vector.size()) / 2); + // Total space, minus the space taken up by the buttons, divided by the spaces between the + // buttons. + int vertical_space = ((y_max - y_min) - (rows * button_height)) / (rows + 1); + int horizontal_space = ((x_max - x_min) - (columns * button_width)) / (columns + 1); + bottom_offset = + ((horizontal_space + button_width) * ((rows * columns) - button_vector.size()) / 2); offset_value = (rows * columns) - button_vector.size(); for (unsigned int i = 0; i < button_vector.size(); i++) { button_vector.at(i).set_location( - ((horizontal_space + button_width) * get_x_from_pos(i)) + - horizontal_space + x_min + - (get_y_from_pos(i) == (unsigned int)(rows - 1) ? bottom_offset - : 0), - ((vertical_space + button_height) * get_y_from_pos(i)) + - vertical_space + y_min); + ((horizontal_space + button_width) * get_x_from_pos(i)) + horizontal_space + x_min + + (get_y_from_pos(i) == (unsigned int)(rows - 1) ? bottom_offset : 0), + ((vertical_space + button_height) * get_y_from_pos(i)) + vertical_space + y_min); } } -unsigned int Button_Menu::get_pos_from_xy(int nX, int nY) -{ - return (nY * columns) + nX; -} +unsigned int Button_Menu::get_pos_from_xy(int nX, int nY) { return (nY * columns) + nX; } unsigned int Button_Menu::get_x_from_pos(int nPos) { return (nPos % columns); } @@ -164,9 +155,6 @@ void Button_Menu::set_rows_and_columns(int nRows, int nColumns) columns = nColumns; } -void Button_Menu::set_bottom_row_offset(int nBottom_offset) -{ - bottom_offset = nBottom_offset; -} +void Button_Menu::set_bottom_row_offset(int nBottom_offset) { bottom_offset = nBottom_offset; } void Button_Menu::clear_vector() { button_vector.clear(); } \ No newline at end of file diff --git a/source/custom_malloc.cpp b/source/custom_malloc.cpp index 9ad0937..21d5e4d 100644 --- a/source/custom_malloc.cpp +++ b/source/custom_malloc.cpp @@ -5,37 +5,32 @@ #include #include /// -/// This module is implemented to reduce the rom size and reduce IWRAM -/// consumption (__malloc_av -> 1 KB) However, we need to be careful to make a -/// heap available at the right times. This implementation stubs malloc_r, which -/// is called by newlib c internally That means we MUST avoid using: printf, -/// sprintf, fprintf, etc. (use iprintf from libtonc, nanoprintf or dprint -/// alternatives) fopen, freopen strdup locale / setlocale atexit / exit / -/// __cxa_atexit (especially in C++) +/// This module is implemented to reduce the rom size and reduce IWRAM consumption (__malloc_av -> 1 +/// KB) However, we need to be careful to make a heap available at the right times. This +/// implementation stubs malloc_r, which is called by newlib c internally That means we MUST avoid +/// using: printf, sprintf, fprintf, etc. (use iprintf from libtonc, nanoprintf or dprint +/// alternatives) fopen, freopen strdup locale / setlocale atexit / exit / __cxa_atexit (especially +/// in C++) /// /// This module implements a bitmap block allocator. -/// We define a page size (mem_page_size), which is the minimum allocation unit -/// for this malloc() implementation. The allocator has a bitmap (g_alloc_map) -/// which tracks the allocation of each page in the pool as a single bit. 1 -/// means allocated, 0 means free The alloc map is structured to have a list of -/// 32 bit unsigned integers, as that is the native unit the ARM cpu and memory -/// bus work with. So using these is the most efficient way to do it. The -/// allocator keeps track of the last position it was at while scanning and -/// wraps around to the beginning of the allocation map if necessary to find -/// free space. +/// We define a page size (mem_page_size), which is the minimum allocation unit for this malloc() +/// implementation. The allocator has a bitmap (g_alloc_map) which tracks the allocation of each +/// page in the pool as a single bit. 1 means allocated, 0 means free The alloc map is structured to +/// have a list of 32 bit unsigned integers, as that is the native unit the ARM cpu and memory bus +/// work with. So using these is the most efficient way to do it. +/// The allocator keeps track of the last position it was at while scanning and wraps around to the +/// beginning of the allocation map if necessary to find free space. #define ALLOC_MAP_START_BIT 0x80000000 #define MALLOC_MEM_POOL_PAGE_SIZE 4 extern char __end__; -// warning: this static allocation of g_alloc_map limits the maximum g_mem_pool -// size to 8192 bytes. -// TODO: if this is not enough, we could change the code to allow a user to set -// their g_alloc_map with malloc_set_mem_pool() -static EWRAM_DATA uint32_t - g_alloc_map[CUSTOM_MALLOC_POOL_SIZE / (32 * MALLOC_MEM_POOL_PAGE_SIZE)]; +// warning: this static allocation of g_alloc_map limits the maximum g_mem_pool size to 8192 bytes. +// TODO: if this is not enough, we could change the code to allow a user to set their g_alloc_map +// with malloc_set_mem_pool() +static EWRAM_DATA uint32_t g_alloc_map[CUSTOM_MALLOC_POOL_SIZE / (32 * MALLOC_MEM_POOL_PAGE_SIZE)]; static uint32_t *g_alloc_map_ptr = g_alloc_map; static uint32_t g_alloc_map_bit = ALLOC_MAP_START_BIT; @@ -43,14 +38,13 @@ static const uint32_t mem_page_size = MALLOC_MEM_POOL_PAGE_SIZE; // For some reason, __end__ only gives the right value if we use it directly. // We can't store it in a variable. -// But if we create an inline function, then we're basically doing the same -// thing as using it directly. +// But if we create an inline function, then we're basically doing the same thing as using it +// directly. static inline uint8_t *get_heap_start(void) { return (uint8_t *)&__end__; } -/// @brief This function calculates the absolute page offset/count from the -/// start of the alloc_map until the specified position in the alloc map -static uint16_t calculate_page_offset( - uint32_t *alloc_map_ptr, uint32_t alloc_map_bit) +/// @brief This function calculates the absolute page offset/count from the start of the alloc_map +/// until the specified position in the alloc map +static uint16_t calculate_page_offset(uint32_t *alloc_map_ptr, uint32_t alloc_map_bit) { uint16_t num_pages = (alloc_map_ptr - g_alloc_map) * 32; uint32_t bit_check = ALLOC_MAP_START_BIT; @@ -64,22 +58,20 @@ static uint16_t calculate_page_offset( return num_pages; } -/// @brief This function converts a position in the alloc map into the -/// associated pointer in the actual memory pool. -static uint8_t *convert_alloc_map_position_into_mem_pool_ptr( - uint32_t *start, uint32_t bit_start) +/// @brief This function converts a position in the alloc map into the associated pointer in the +/// actual memory pool. +static uint8_t *convert_alloc_map_position_into_mem_pool_ptr(uint32_t *start, uint32_t bit_start) { const uint16_t page_offset = calculate_page_offset(start, bit_start); return get_heap_start() + (page_offset * mem_page_size); } -/// @brief This function converts a memory pool pointer into a position in the -/// associated allocation map. +/// @brief This function converts a memory pool pointer into a position in the associated allocation +/// map. /// @param ptr pointer in the memory pool -/// @param alloc_start output variable to indicate the start of the alloc map +/// @param alloc_start output variable to indicate the start of the alloc map entry. +/// @param bit_start output variable to indcate the specific bit position inside that alloc map /// entry. -/// @param bit_start output variable to indcate the specific bit position inside -/// that alloc map entry. static void convert_mem_pool_ptr_into_alloc_map_position( uint8_t *ptr, uint32_t **alloc_start, uint32_t *bit_start) { @@ -88,16 +80,14 @@ static void convert_mem_pool_ptr_into_alloc_map_position( *bit_start = ALLOC_MAP_START_BIT >> (page_offset % 32); } -/// @brief This function implements a speedup while scanning the allocation map -/// for free space: If the current bit position is the first one, it will try to -/// skip entire alloc map entries if all bits are set. This is much faster than -/// walking through each bit individually. -/// @param end_entry Since the function can loop, we need to provide an entry -/// position as a stop condition to avoid an infinite loop +/// @brief This function implements a speedup while scanning the allocation map for free space: +/// If the current bit position is the first one, it will try to skip entire alloc map entries if +/// all bits are set. This is much faster than walking through each bit individually. +/// @param end_entry Since the function can loop, we need to provide an entry position as a stop +/// condition to avoid an infinite loop static void skip_wholy_allocated_map_entries(uint32_t *end_entry) { - const uint32_t *g_alloc_map_end = - g_alloc_map + (sizeof(g_alloc_map) / sizeof(uint32_t)); + const uint32_t *g_alloc_map_end = g_alloc_map + (sizeof(g_alloc_map) / sizeof(uint32_t)); if (g_alloc_map_ptr == end_entry) { return; @@ -117,17 +107,14 @@ static void skip_wholy_allocated_map_entries(uint32_t *end_entry) } } -/// @brief This function advances the alloc_map_bit and possibly the alloc_map -/// entry itself. It also takes care of wraparound when we reach the end with -/// alloc_map_ptr -static void advance_alloc_map_bit( - uint32_t **alloc_map_ptr, uint32_t *alloc_map_bit, bool *looped) +/// @brief This function advances the alloc_map_bit and possibly the alloc_map entry itself. +/// It also takes care of wraparound when we reach the end with alloc_map_ptr +static void advance_alloc_map_bit(uint32_t **alloc_map_ptr, uint32_t *alloc_map_bit, bool *looped) { (*alloc_map_bit) >>= 1; if (!(*alloc_map_bit)) { - const uint32_t *g_alloc_map_end = - g_alloc_map + (sizeof(g_alloc_map) / sizeof(uint32_t)); + const uint32_t *g_alloc_map_end = g_alloc_map + (sizeof(g_alloc_map) / sizeof(uint32_t)); ++(*alloc_map_ptr); if ((*alloc_map_ptr) >= g_alloc_map_end) { @@ -142,8 +129,7 @@ static void advance_alloc_map_bit( } } -/// @brief This function checks for num_pages of free space at the specified -/// alloc map position. +/// @brief This function checks for num_pages of free space at the specified alloc map position. static bool check_block_free( uint32_t **cur_entry, uint32_t *cur_bit, uint16_t num_pages, bool *looped) { @@ -162,8 +148,8 @@ static bool check_block_free( else { // the page we're currently considering is already allocated. - // advance the bit position again for the next call, but the result - // of this function is that we didn't find a large enough free block + // advance the bit position again for the next call, but the result of this function + // is that we didn't find a large enough free block advance_alloc_map_bit(cur_entry, cur_bit, looped); break; } @@ -171,10 +157,9 @@ static bool check_block_free( return !num_pages; } -/// @brief This function marks a block of pages as "allocated" in the allocation -/// map at the specified map position -static void mark_block_allocated( - uint32_t *cur_entry, uint32_t cur_bit, size_t num_pages) +/// @brief This function marks a block of pages as "allocated" in the allocation map at the +/// specified map position +static void mark_block_allocated(uint32_t *cur_entry, uint32_t cur_bit, size_t num_pages) { while (num_pages) { @@ -184,10 +169,9 @@ static void mark_block_allocated( } } -/// @brief This function marks a block of pages as "free" in the allocation map -/// at the specified map position -static void mark_block_free( - uint32_t *cur_entry, uint32_t cur_bit, size_t num_pages) +/// @brief This function marks a block of pages as "free" in the allocation map at the specified map +/// position +static void mark_block_free(uint32_t *cur_entry, uint32_t cur_bit, size_t num_pages) { while (num_pages) { @@ -198,15 +182,13 @@ static void mark_block_free( } } -/// @brief This function calculates the number of pages needed to allocate at -/// least the requested size. It does add 1 additional page for storing the -/// allocation size (in pages) and may add another one to ensure the returned -/// allocation is aligned to mem_page_size +/// @brief This function calculates the number of pages needed to allocate at least the requested +/// size. It does add 1 additional page for storing the allocation size (in pages) and may add +/// another one to ensure the returned allocation is aligned to mem_page_size static uint16_t get_num_pages_for_size(size_t size) { - // reserve 1 additional page for storing the number of pages (and use/waste - // a whole page because of alignment) we need this as a "header" to be able - // to know how many pages to free(). + // reserve 1 additional page for storing the number of pages (and use/waste a whole page because + // of alignment) we need this as a "header" to be able to know how many pages to free(). uint16_t num_pages = (size / mem_page_size) + 1; if (size % mem_page_size) { @@ -223,8 +205,8 @@ void malloc_init_default_pool(void) extern "C" { - /// @brief The custom implementation of the bitmap allocator described at - /// the top of this module. + /// @brief The custom implementation of the bitmap allocator described at the top of this + /// module. void *malloc(size_t size) { uint32_t *const alloc_start = g_alloc_map_ptr; @@ -239,13 +221,11 @@ extern "C" { current_start = g_alloc_map_ptr; current_bit_start = g_alloc_map_bit; - if (check_block_free( - &g_alloc_map_ptr, &g_alloc_map_bit, num_pages, &looped)) + if (check_block_free(&g_alloc_map_ptr, &g_alloc_map_bit, num_pages, &looped)) { - mark_block_allocated( - current_start, current_bit_start, num_pages); - pool_ptr = convert_alloc_map_position_into_mem_pool_ptr( - current_start, current_bit_start); + mark_block_allocated(current_start, current_bit_start, num_pages); + pool_ptr = + convert_alloc_map_position_into_mem_pool_ptr(current_start, current_bit_start); // store the number of pages as a header in the first page *((uint16_t *)pool_ptr) = num_pages; // return a pointer beyond the first page @@ -253,22 +233,20 @@ extern "C" } else { - if (looped && g_alloc_map_ptr == alloc_start && - g_alloc_map_bit <= alloc_bit_start) + if (looped && g_alloc_map_ptr == alloc_start && g_alloc_map_bit <= alloc_bit_start) { - // we looped back to our start position. Ran out of memory I - // suppose + // we looped back to our start position. Ran out of memory I suppose return NULL; } - // if we're at the start of an alloc_map 32 bit entry then avoid - // walking through each bit one-by-one if all bits are set + // if we're at the start of an alloc_map 32 bit entry then avoid walking through + // each bit one-by-one if all bits are set skip_wholy_allocated_map_entries(alloc_start); } } } - /// @brief The custom implementation of free() of the bitmap allocator - /// described at the top of this module. + /// @brief The custom implementation of free() of the bitmap allocator described at the top of + /// this module. void free(void *ptr) { uint8_t *const pool_ptr = ((uint8_t *)ptr) - mem_page_size; @@ -276,13 +254,12 @@ extern "C" uint32_t alloc_map_bit; const uint16_t num_pages = *((uint16_t *)pool_ptr); - convert_mem_pool_ptr_into_alloc_map_position( - pool_ptr, &alloc_map_entry, &alloc_map_bit); + convert_mem_pool_ptr_into_alloc_map_position(pool_ptr, &alloc_map_entry, &alloc_map_bit); mark_block_free(alloc_map_entry, alloc_map_bit, num_pages); } - /// @brief The custom implementation of realloc() of the bitmap allocator - /// described at the top of this module. + /// @brief The custom implementation of realloc() of the bitmap allocator described at the top + /// of this module. void *realloc(void *ptr, size_t new_size) { if (!ptr) @@ -296,22 +273,20 @@ extern "C" const uint16_t original_num_pages = *((uint16_t *)pool_ptr); const uint16_t new_num_pages = get_num_pages_for_size(new_size); - convert_mem_pool_ptr_into_alloc_map_position( - pool_ptr, &alloc_map_entry, &alloc_map_bit); + convert_mem_pool_ptr_into_alloc_map_position(pool_ptr, &alloc_map_entry, &alloc_map_bit); - // first mark the associated allocmap bits as free in order make sure - // the current block is correctly detected as free + // first mark the associated allocmap bits as free in order make sure the current block is + // correctly detected as free mark_block_free(alloc_map_entry, alloc_map_bit, original_num_pages); - if (check_block_free( - &alloc_map_entry, &alloc_map_bit, new_num_pages, NULL)) + if (check_block_free(&alloc_map_entry, &alloc_map_bit, new_num_pages, NULL)) { // reset the entry and bit because check_block_free advanced it. convert_mem_pool_ptr_into_alloc_map_position( pool_ptr, &alloc_map_entry, &alloc_map_bit); - // allright, we can simply extend/contract the allocation because - // there's enough consecutive trailing space free + // allright, we can simply extend/contract the allocation because there's enough + // consecutive trailing space free mark_block_allocated(alloc_map_entry, alloc_map_bit, new_num_pages); *((uint16_t *)pool_ptr) = new_num_pages; @@ -320,28 +295,24 @@ extern "C" } else { - // not enough space to extend the allocation. allocate a new block - // and copy the content + // not enough space to extend the allocation. allocate a new block and copy the content void *new_block = malloc(new_size); - uint16_t copy_pages = (original_num_pages < new_num_pages) - ? original_num_pages - : new_num_pages; + uint16_t copy_pages = + (original_num_pages < new_num_pages) ? original_num_pages : new_num_pages; if (!new_block) { - // even though we can't return the requested block, the old - // pointer should remain valid. but we already marked it as - // free. Let's correct that. + // even though we can't return the requested block, the old pointer should remain + // valid. but we already marked it as free. Let's correct that. // reset the entry and bit because check_block_free advanced it. convert_mem_pool_ptr_into_alloc_map_position( pool_ptr, &alloc_map_entry, &alloc_map_bit); - mark_block_allocated( - alloc_map_entry, alloc_map_bit, original_num_pages); + mark_block_allocated(alloc_map_entry, alloc_map_bit, original_num_pages); return NULL; } memcpy(new_block, ptr, (copy_pages - 1) * mem_page_size); - // Okay, the original block's data was copied over to a newly - // allocated block and the original block was marked as free. + // Okay, the original block's data was copied over to a newly allocated block + // and the original block was marked as free. return new_block; } } @@ -358,22 +329,20 @@ extern "C" return result; } - /// dummy implementation to ensure the linker doesn't pull newlibs' malloc - /// code (which also pulls in a 1 KB __malloc_av buffer) WARNING: Please - /// consider the warning at the top of this module: We should avoid certain - /// functionality in newlib as it may try to call this function to allocate - /// memory. We don't want to establish a permanent heap in this project. + /// dummy implementation to ensure the linker doesn't pull newlibs' malloc code (which also + /// pulls in a 1 KB __malloc_av buffer) WARNING: Please consider the warning at the top of this + /// module: We should avoid certain functionality in newlib as it may try to call this function + /// to allocate memory. We don't want to establish a permanent heap in this project. void *_malloc_r(struct _reent *r, size_t size) { (void)r; return malloc(size); } - /// dummy implementation to ensure the linker doesn't pull newlibs' malloc - /// code (which also pulls in a 1 KB __malloc_av buffer) WARNING: Please - /// consider the warning at the top of this module: We should avoid certain - /// functionality in newlib as it may try to call this function to allocate - /// memory. We don't want to establish a permanent heap in this project. + /// dummy implementation to ensure the linker doesn't pull newlibs' malloc code (which also + /// pulls in a 1 KB __malloc_av buffer) WARNING: Please consider the warning at the top of this + /// module: We should avoid certain functionality in newlib as it may try to call this function + /// to allocate memory. We don't want to establish a permanent heap in this project. void _free_r(struct _reent *r, void *ptr) { (void)r; diff --git a/source/dbg/debug_menu.cpp b/source/dbg/debug_menu.cpp index 29af1c9..814d656 100644 --- a/source/dbg/debug_menu.cpp +++ b/source/dbg/debug_menu.cpp @@ -18,8 +18,7 @@ static unsigned current_menu_section_stack_size; static void pop_submenu() { --current_menu_section_stack_size; } -static __attribute__((noinline)) void show_debug_menu_internal( - DebugMenuSection sectionType) +static __attribute__((noinline)) void show_debug_menu_internal(DebugMenuSection sectionType) { u16 charset[256]; const s16 cursor_offset_x = 3; @@ -47,8 +46,7 @@ static __attribute__((noinline)) void show_debug_menu_internal( .should_delete_item_widgets_on_destruct = true, .should_hide_state_changed_handler_on_not_focused = true}; - vertical_menu_cursor_handler cursor_handler( - cursor_offset_x, cursor_offset_y); + vertical_menu_cursor_handler cursor_handler(cursor_offset_x, cursor_offset_y); vertical_menu debug_menu(menu_settings); debug_menu.set_state_changed_handler(&cursor_handler); @@ -63,21 +61,20 @@ static __attribute__((noinline)) void show_debug_menu_internal( hide_textbox(); tte_erase_rect(0, 0, H_MAX, V_MAX); - // execute any callback that was delayed by pressing the A button on an - // executable row. This is done to make sure the debug menu is fully hidden - // before executing the callback, to avoid rendering issues. + // execute any callback that was delayed by pressing the A button on an executable row. + // This is done to make sure the debug menu is fully hidden before executing the callback, + // to avoid rendering issues. if (delayed_execute_callback) { - delayed_execute_callback( - delayed_execute_context, delayed_execute_user_param); + delayed_execute_callback(delayed_execute_context, delayed_execute_user_param); delayed_execute_callback = nullptr; delayed_execute_context = nullptr; delayed_execute_user_param = 0; } else if (ret == UINT32_MAX) { - // if the user cancelled out of the menu, we pop the submenu stack to go - // back to the previous menu. + // if the user cancelled out of the menu, we pop the submenu stack to go back to the + // previous menu. pop_submenu(); } } @@ -90,16 +87,12 @@ void show_debug_menu() push_debug_menu_section(DebugMenuSection::MAIN); while (current_menu_section_stack_size > 0) { - curr_section = - current_menu_section[current_menu_section_stack_size - 1]; + curr_section = current_menu_section[current_menu_section_stack_size - 1]; show_debug_menu_internal(curr_section); } } -debug_menu_row_widget::debug_menu_row_widget(const debug_menu_row_data &data) - : data_(data) -{ -} +debug_menu_row_widget::debug_menu_row_widget(const debug_menu_row_data &data) : data_(data) {} debug_menu_row_widget::~debug_menu_row_widget() { @@ -125,20 +118,19 @@ void debug_menu_row_widget::render_item( if (data_.option_section.num_options > 0) { - const u8 selected_option_index = - data_.option_section.selected_option_index; + const u8 selected_option_index = data_.option_section.selected_option_index; tte_set_pos(x + option_margin_left, y + margin_top); if (data_.option_section.options[selected_option_index].text) { - ptgb_write_debug(data_.charset, - data_.option_section.options[selected_option_index].text, true); + ptgb_write_debug( + data_.charset, data_.option_section.options[selected_option_index].text, true); } else { char buf[32]; - npf_snprintf(buf, sizeof(buf), "%u", - data_.option_section.options[selected_option_index].value); + npf_snprintf( + buf, sizeof(buf), "%u", data_.option_section.options[selected_option_index].value); ptgb_write_debug(data_.charset, buf, true); } } @@ -147,19 +139,14 @@ void debug_menu_row_widget::render_item( { if (data_.option_section.num_options > 0) { - const int toggle_arrow_left_x = static_cast(x) + - option_margin_left + - toggle_arrow_left_offset_x; - const int toggle_arrow_right_x = static_cast(x) + - option_margin_left + - toggle_arrow_right_offset_x; - const int toggle_arrows_y = - static_cast(y) + margin_top + toggle_arrows_offset_y; + const int toggle_arrow_left_x = + static_cast(x) + option_margin_left + toggle_arrow_left_offset_x; + const int toggle_arrow_right_x = + static_cast(x) + option_margin_left + toggle_arrow_right_offset_x; + const int toggle_arrows_y = static_cast(y) + margin_top + toggle_arrows_offset_y; - obj_set_pos( - toggle_arrow_left, toggle_arrow_left_x, toggle_arrows_y); - obj_set_pos( - toggle_arrow_right, toggle_arrow_right_x, toggle_arrows_y); + obj_set_pos(toggle_arrow_left, toggle_arrow_left_x, toggle_arrows_y); + obj_set_pos(toggle_arrow_right, toggle_arrow_right_x, toggle_arrows_y); obj_unhide(toggle_arrow_left, 0); obj_unhide(toggle_arrow_right, 0); } @@ -179,18 +166,15 @@ MenuInputHandleState debug_menu_row_widget::handle_input() if (key_hit(KEY_RIGHT)) { data_.option_section.selected_option_index = - (data_.option_section.selected_option_index + 1) % - data_.option_section.num_options; + (data_.option_section.selected_option_index + 1) % data_.option_section.num_options; handled = true; } if (key_hit(KEY_LEFT)) { --data_.option_section.selected_option_index; - if (data_.option_section.selected_option_index >= - data_.option_section.num_options) + if (data_.option_section.selected_option_index >= data_.option_section.num_options) { - data_.option_section.selected_option_index = - data_.option_section.num_options - 1; + data_.option_section.selected_option_index = data_.option_section.num_options - 1; } handled = true; } @@ -198,9 +182,7 @@ MenuInputHandleState debug_menu_row_widget::handle_input() if (handled && data_.option_section.on_option_activate) { data_.option_section.on_option_activate(data_.context, - data_.option_section - .options[data_.option_section.selected_option_index] - .value); + data_.option_section.options[data_.option_section.selected_option_index].value); } if (handled) @@ -222,8 +204,7 @@ MenuInputHandleState debug_menu_row_widget::handle_input() void push_debug_menu_section(DebugMenuSection section) { - constexpr size_t num_levels = - sizeof(current_menu_section) / sizeof(current_menu_section[0]); + constexpr size_t num_levels = sizeof(current_menu_section) / sizeof(current_menu_section[0]); if (current_menu_section_stack_size < num_levels) { current_menu_section[current_menu_section_stack_size] = section; diff --git a/source/dbg/debug_menu_entries.cpp b/source/dbg/debug_menu_entries.cpp index 307643e..20731d5 100644 --- a/source/dbg/debug_menu_entries.cpp +++ b/source/dbg/debug_menu_entries.cpp @@ -15,33 +15,26 @@ static const option_data toggle_options[] = { {.text = "Off", .value = 0}, {.text = "On", .value = 1}}; -static void fill_debug_menu_with_main_menu_entries( - vertical_menu &menu, u16 *charset); -static void fill_debug_menu_with_injection_entries( - vertical_menu &menu, u16 *charset); +static void fill_debug_menu_with_main_menu_entries(vertical_menu &menu, u16 *charset); +static void fill_debug_menu_with_injection_entries(vertical_menu &menu, u16 *charset); static const MenuSectionMapEntry menu_section_map[] = { - {.section = DebugMenuSection::MAIN, - .fill_func = fill_debug_menu_with_main_menu_entries}, - {.section = DebugMenuSection::INJECTION, - .fill_func = fill_debug_menu_with_injection_entries}}; + {.section = DebugMenuSection::MAIN, .fill_func = fill_debug_menu_with_main_menu_entries}, + {.section = DebugMenuSection::INJECTION, .fill_func = fill_debug_menu_with_injection_entries}}; -static const option_data cbl_data_options[] = { - {.text = "Off", .value = WRITE_CABLE_DATA_MODE_OFF}, +static const option_data cbl_data_options[] = {{.text = "Off", .value = WRITE_CABLE_DATA_MODE_OFF}, {.text = "SRAM", .value = WRITE_CABLE_DATA_MODE_SRAM}, {.text = "CART", .value = WRITE_CABLE_DATA_MODE_CART}}; #define CBL_DATA_OPTIONS_COUNT (sizeof(cbl_data_options) / sizeof(option_data)) /** - * @brief This helper function makes it easy to define a multiple choice debug - * row. + * @brief This helper function makes it easy to define a multiple choice debug row. */ -static debug_menu_row_widget *__attribute__((noinline)) define_debug_choice_row( - const u16 *charset, const char *labelText, - on_execute_callback option_activate_callback, - const option_data *options_metadata, u8 num_options, - bool should_delete_options, u8 default_option_index, void *context) +static debug_menu_row_widget *__attribute__((noinline)) define_debug_choice_row(const u16 *charset, + const char *labelText, on_execute_callback option_activate_callback, + const option_data *options_metadata, u8 num_options, bool should_delete_options, + u8 default_option_index, void *context) { const debug_menu_row_data row_data = {.charset = charset, .labelText = labelText, @@ -59,23 +52,21 @@ static debug_menu_row_widget *__attribute__((noinline)) define_debug_choice_row( /** * @brief This helper function makes it easy to define a toggle row. */ -static debug_menu_row_widget *define_toggle_row(const u16 *charset, - const char *labelText, on_execute_callback on_toggle_callback, - bool default_value, void *context) +static debug_menu_row_widget *define_toggle_row(const u16 *charset, const char *labelText, + on_execute_callback on_toggle_callback, bool default_value, void *context) { - return define_debug_choice_row(charset, labelText, on_toggle_callback, - toggle_options, 2, false, default_value ? 1 : 0, context); + return define_debug_choice_row(charset, labelText, on_toggle_callback, toggle_options, 2, false, + default_value ? 1 : 0, context); } /** - * @brief This helper function will define the song row, which will let you - * toggle between any available maxmod song or None at all. + * @brief This helper function will define the song row, which will let you toggle between any + * available maxmod song or None at all. */ -[[maybe_unused]] static debug_menu_row_widget *__attribute__((noinline)) -define_song_row(const u16 *charset, const char *labelText) +[[maybe_unused]] static debug_menu_row_widget *__attribute__((noinline)) define_song_row( + const u16 *charset, const char *labelText) { - option_data *song_options = - (option_data *)malloc(sizeof(option_data) * (MSL_NSONGS + 1)); + option_data *song_options = (option_data *)malloc(sizeof(option_data) * (MSL_NSONGS + 1)); song_options[0] = {.text = "None", .value = UINT32_MAX}; for (unsigned i = 0; i < MSL_NSONGS; ++i) @@ -83,17 +74,16 @@ define_song_row(const u16 *charset, const char *labelText) song_options[i + 1] = {.text = nullptr, .value = i}; } - return define_debug_choice_row(charset, labelText, dbg_play_song, - song_options, MSL_NSONGS + 1, true, 0, nullptr); + return define_debug_choice_row( + charset, labelText, dbg_play_song, song_options, MSL_NSONGS + 1, true, 0, nullptr); } /** - * @brief This helper function makes it easy to define a row that executes a - * function when you select it and press A. + * @brief This helper function makes it easy to define a row that executes a function when you + * select it and press A. */ -static debug_menu_row_widget *__attribute__((noinline)) define_executable_row( - const u16 *charset, const char *labelText, on_execute_callback on_execute, - unsigned user_param, void *context) +static debug_menu_row_widget *__attribute__((noinline)) define_executable_row(const u16 *charset, + const char *labelText, on_execute_callback on_execute, unsigned user_param, void *context) { const debug_menu_row_data row_data = {.charset = charset, .labelText = labelText, @@ -108,84 +98,64 @@ static debug_menu_row_widget *__attribute__((noinline)) define_executable_row( return new debug_menu_row_widget(row_data); } -/// Here we define the actual entries of the main debug menu, using the helper -/// functions defined above. -static void fill_debug_menu_with_main_menu_entries( - vertical_menu &menu, u16 *charset) +/// Here we define the actual entries of the main debug menu, using the helper functions defined +/// above. +static void fill_debug_menu_with_main_menu_entries(vertical_menu &menu, u16 *charset) { i_item_widget *item_widgets[] = { #if ENABLE_TEXT_DEBUG_SCREEN - define_executable_row( - charset, "Text Debug", show_text_debug_screen, 0, nullptr), + define_executable_row(charset, "Text Debug", show_text_debug_screen, 0, nullptr), #endif - define_executable_row( - charset, "Info", show_debug_info_screen, 0, nullptr), + define_executable_row(charset, "Info", show_debug_info_screen, 0, nullptr), define_executable_row(charset, "Injection", show_debug_menu_section, static_cast(DebugMenuSection::INJECTION), nullptr), #if ENABLE_MYSTERY_GIFT - define_executable_row( - charset, "Unlock MystE", dbg_unlock_mystery, 0, nullptr), - define_executable_row( - charset, "Unlock MystG", dbg_unlock_mystery, 1, nullptr), + define_executable_row(charset, "Unlock MystE", dbg_unlock_mystery, 0, nullptr), + define_executable_row(charset, "Unlock MystG", dbg_unlock_mystery, 1, nullptr), #endif #if ENABLE_SOUND define_song_row(charset, "Song"), #endif - define_toggle_row(charset, "Print Link", dbg_set_byte_val, - g_debug_options.print_link_data, &g_debug_options.print_link_data), + define_toggle_row(charset, "Print Link", dbg_set_byte_val, g_debug_options.print_link_data, + &g_debug_options.print_link_data), define_toggle_row(charset, "Instant Text", dbg_set_byte_val, - g_debug_options.instant_text_speed, - &g_debug_options.instant_text_speed), - define_toggle_row(charset, "Ign Cart", dbg_set_byte_val, - g_debug_options.ignore_game_pak, &g_debug_options.ignore_game_pak), + g_debug_options.instant_text_speed, &g_debug_options.instant_text_speed), + define_toggle_row(charset, "Ign Cart", dbg_set_byte_val, g_debug_options.ignore_game_pak, + &g_debug_options.ignore_game_pak), define_toggle_row(charset, "Ign Sprites", dbg_set_byte_val, - g_debug_options.ignore_game_pak_sprites, - &g_debug_options.ignore_game_pak_sprites), - define_toggle_row(charset, "Ign Link", dbg_set_byte_val, - g_debug_options.ignore_link_cable, + g_debug_options.ignore_game_pak_sprites, &g_debug_options.ignore_game_pak_sprites), + define_toggle_row(charset, "Ign Link", dbg_set_byte_val, g_debug_options.ignore_link_cable, &g_debug_options.ignore_link_cable), define_toggle_row(charset, "Ign MG/E4", dbg_set_byte_val, - g_debug_options.ignore_mg_e4_flags, - &g_debug_options.ignore_mg_e4_flags), + g_debug_options.ignore_mg_e4_flags, &g_debug_options.ignore_mg_e4_flags), define_toggle_row(charset, "Ign Unrec PKMN", dbg_set_byte_val, - g_debug_options.ignore_unreceived_pkmn, - &g_debug_options.ignore_unreceived_pkmn), - define_toggle_row(charset, "Force Tut", dbg_set_byte_val, - g_debug_options.force_tutorial, &g_debug_options.force_tutorial), + g_debug_options.ignore_unreceived_pkmn, &g_debug_options.ignore_unreceived_pkmn), + define_toggle_row(charset, "Force Tut", dbg_set_byte_val, g_debug_options.force_tutorial, + &g_debug_options.force_tutorial), define_toggle_row(charset, "Show Invalid", dbg_set_byte_val, - g_debug_options.dont_hide_invalid_pkmn, - &g_debug_options.dont_hide_invalid_pkmn), + g_debug_options.dont_hide_invalid_pkmn, &g_debug_options.dont_hide_invalid_pkmn), define_toggle_row(charset, "Ign Dex Compl", dbg_set_byte_val, - g_debug_options.ignore_dex_completion, - &g_debug_options.ignore_dex_completion), + g_debug_options.ignore_dex_completion, &g_debug_options.ignore_dex_completion), define_toggle_row(charset, "Force Caught", dbg_set_byte_val, - g_debug_options.force_all_caught, - &g_debug_options.force_all_caught), + g_debug_options.force_all_caught, &g_debug_options.force_all_caught), define_toggle_row(charset, "Write Cbl Data", dbg_set_byte_val, - g_debug_options.write_cable_data_to_save, - &g_debug_options.write_cable_data_to_save), + g_debug_options.write_cable_data_to_save, &g_debug_options.write_cable_data_to_save), define_toggle_row(charset, "Disp CtrlChr", dbg_set_byte_val, - g_debug_options.display_control_char, - &g_debug_options.display_control_char)}; + g_debug_options.display_control_char, &g_debug_options.display_control_char)}; - menu.add_item_widgets( - item_widgets, sizeof(item_widgets) / sizeof(item_widgets[0])); + menu.add_item_widgets(item_widgets, sizeof(item_widgets) / sizeof(item_widgets[0])); } /// This function defines the entries of the injection submenu -static void fill_debug_menu_with_injection_entries( - vertical_menu &menu, u16 *charset) +static void fill_debug_menu_with_injection_entries(vertical_menu &menu, u16 *charset) { i_item_widget *item_widgets[] = { #if ENABLE_DEBUG_PKMN_INJECTION - define_executable_row( - charset, "Inject Celebi", dbg_inject_pkmn, 0, nullptr), + define_executable_row(charset, "Inject Celebi", dbg_inject_pkmn, 0, nullptr), #endif #if ENABLE_MYSTERY_GIFT - define_executable_row( - charset, "Unlock MystE", dbg_unlock_mystery, 0, nullptr), - define_executable_row( - charset, "Unlock MystG", dbg_unlock_mystery, 1, nullptr), + define_executable_row(charset, "Unlock MystE", dbg_unlock_mystery, 0, nullptr), + define_executable_row(charset, "Unlock MystG", dbg_unlock_mystery, 1, nullptr), define_executable_row(charset, "Inj OldSeaMap(E)", dbg_inject_wc3, sizeof(OldSeaMap_E_custom), const_cast(OldSeaMap_E_custom)), define_executable_row(charset, "Inj Eon Ticket(RS)", dbg_inject_me3, @@ -194,15 +164,12 @@ static void fill_debug_menu_with_injection_entries( #endif }; - menu.add_item_widgets( - item_widgets, sizeof(item_widgets) / sizeof(item_widgets[0])); + menu.add_item_widgets(item_widgets, sizeof(item_widgets) / sizeof(item_widgets[0])); } -void fill_debug_menu_with_entries( - vertical_menu &menu, u16 *charset, DebugMenuSection section) +void fill_debug_menu_with_entries(vertical_menu &menu, u16 *charset, DebugMenuSection section) { - const size_t num_sections = - sizeof(menu_section_map) / sizeof(menu_section_map[0]); + const size_t num_sections = sizeof(menu_section_map) / sizeof(menu_section_map[0]); size_t i = 0; while (i < num_sections) { diff --git a/source/dbg/debug_menu_functions.cpp b/source/dbg/debug_menu_functions.cpp index 768605d..53189d5 100644 --- a/source/dbg/debug_menu_functions.cpp +++ b/source/dbg/debug_menu_functions.cpp @@ -25,14 +25,12 @@ extern rom_data curr_GBA_rom; extern u32 global_tile_id_end; -static const byte RSEFL_10_ANIV_Celebi_0BF5_ENG_[] = {0xbe, 0x2b, 0x28, 0x78, - 0x0a, 0x00, 0x00, 0x00, 0xbd, 0xbf, 0xc6, 0xbf, 0xbc, 0xc3, 0xff, 0x34, - 0x01, 0x31, 0x02, 0x02, 0xa2, 0xa1, 0x00, 0xbb, 0xc8, 0xc3, 0xd0, 0x00, - 0x17, 0x35, 0x00, 0x00, 0xfb, 0x00, 0x00, 0x00, 0x80, 0x43, 0x05, 0x00, - 0x00, 0x64, 0x00, 0x00, 0xf6, 0x00, 0xf8, 0x00, 0xe2, 0x00, 0xc3, 0x00, - 0x05, 0x0f, 0x28, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x46, 0x21, 0xe2, 0x31, 0xaf, 0x22, - 0x00, 0x00, 0x00, 0x00}; +static const byte RSEFL_10_ANIV_Celebi_0BF5_ENG_[] = {0xbe, 0x2b, 0x28, 0x78, 0x0a, 0x00, 0x00, + 0x00, 0xbd, 0xbf, 0xc6, 0xbf, 0xbc, 0xc3, 0xff, 0x34, 0x01, 0x31, 0x02, 0x02, 0xa2, 0xa1, 0x00, + 0xbb, 0xc8, 0xc3, 0xd0, 0x00, 0x17, 0x35, 0x00, 0x00, 0xfb, 0x00, 0x00, 0x00, 0x80, 0x43, 0x05, + 0x00, 0x00, 0x64, 0x00, 0x00, 0xf6, 0x00, 0xf8, 0x00, 0xe2, 0x00, 0xc3, 0x00, 0x05, 0x0f, 0x28, + 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x46, + 0x21, 0xe2, 0x31, 0xaf, 0x22, 0x00, 0x00, 0x00, 0x00}; static Game convert_rom_game_id_to_ptgb_game(int game_id) { @@ -49,8 +47,7 @@ static Game convert_rom_game_id_to_ptgb_game(int game_id) case EMERALD_ID: return EMERALD; default: - return GAME_UNKNOWN; // Default to unknown if the game ID is - // unrecognized + return GAME_UNKNOWN; // Default to unknown if the game ID is unrecognized } } @@ -71,18 +68,15 @@ static Language convert_rom_lang_to_ptgb_lang(int rom_lang) case LANG_SPA: return SPANISH; default: - return LANGUAGE_UNKNOWN; // Default to unknown if the language is - // unrecognized + return LANGUAGE_UNKNOWN; // Default to unknown if the language is unrecognized } } /** * The trainer OT is encoded in the gen3 proprietary charset. - * But if we want to print it with npf_snprintf, we need to convert it to UTF-8 - * first. + * But if we want to print it with npf_snprintf, we need to convert it to UTF-8 first. */ -static void convert_OT_to_utf8( - const u8 *encoded_OT, u8 *output_buffer, const u16 *gen3_charset) +static void convert_OT_to_utf8(const u8 *encoded_OT, u8 *output_buffer, const u16 *gen3_charset) { u16 current_char; u32 num_bytes; @@ -91,12 +85,11 @@ static void convert_OT_to_utf8( for (u32 i = 0; i < 7 && encoded_OT[i] != 0xFF; ++i) { - // the charset maps each gen 3 character (represented as a byte) to a - // UTF-16 codepoint. So we first convert the encoded OT character to - // UTF-16, and then convert that UTF-16 codepoint to UTF-8. + // the charset maps each gen 3 character (represented as a byte) to a UTF-16 codepoint. + // So we first convert the encoded OT character to UTF-16, and then convert that UTF-16 + // codepoint to UTF-8. current_char = convert_gen_3_char_to_utf16(gen3_charset, encoded_OT[i]); - num_bytes = - convert_utf16_to_utf8_char(current_char, utf8_codepoint_buffer); + num_bytes = convert_utf16_to_utf8_char(current_char, utf8_codepoint_buffer); memcpy(cur_out, utf8_codepoint_buffer, num_bytes); cur_out += num_bytes; @@ -107,8 +100,7 @@ static void convert_OT_to_utf8( void show_debug_menu_section(void *context, unsigned user_param) { (void)context; // unused - const DebugMenuSection section_to_show = - static_cast(user_param); + const DebugMenuSection section_to_show = static_cast(user_param); push_debug_menu_section(section_to_show); } @@ -145,8 +137,7 @@ void show_debug_info_screen(void *context, unsigned user_param) bool all_collected_flag = read_flag(curr_GBA_rom.all_collected_flag); for (int i = 0; i < 30; i++) { - pkmn_flags |= - (read_flag(curr_GBA_rom.pkmn_collected_flag_start + i) << i); + pkmn_flags |= (read_flag(curr_GBA_rom.pkmn_collected_flag_start + i) << i); } bool tutorial = get_tutorial_flag(); @@ -181,10 +172,9 @@ void show_debug_info_screen(void *context, unsigned user_param) show_textbox(); npf_snprintf(text_buffer, sizeof(text_buffer), - "Debug info:\n\nG: %d%s%d\nF: %d%d%d-%s\nS: %d-%s\n%s%s", - curr_GBA_rom.language, game_code, curr_GBA_rom.version, e4_flag, - mg_flag, all_collected_flag, flags_hex_str, tutorial, def_lang_hex_str, - BUILD_INFO, get_treecko_enabled() ? ".T" : ""); + "Debug info:\n\nG: %d%s%d\nF: %d%d%d-%s\nS: %d-%s\n%s%s", curr_GBA_rom.language, + game_code, curr_GBA_rom.version, e4_flag, mg_flag, all_collected_flag, flags_hex_str, + tutorial, def_lang_hex_str, BUILD_INFO, get_treecko_enabled() ? ".T" : ""); ptgb_write_debug(charset, text_buffer, true); @@ -218,10 +208,8 @@ void dbg_play_song(void *context, unsigned user_param) void dbg_inject_pkmn(void *context, unsigned user_param) { - const Game game_type = - convert_rom_game_id_to_ptgb_game(curr_GBA_rom.gamecode); - const Language game_lang = - convert_rom_lang_to_ptgb_lang(curr_GBA_rom.language); + const Game game_type = convert_rom_game_id_to_ptgb_game(curr_GBA_rom.gamecode); + const Language game_lang = convert_rom_lang_to_ptgb_lang(curr_GBA_rom.language); u32 ret; char text_buffer[256]; u8 encoded_OT[8]; @@ -238,15 +226,12 @@ void dbg_inject_pkmn(void *context, unsigned user_param) celebi.loadData(RSEFL_10_ANIV_Celebi_0BF5_ENG_, false); // front_sprite_tile_id is reserved behind the box sprites - if (!g_debug_options.ignore_game_pak && - !g_debug_options.ignore_game_pak_sprites) + if (!g_debug_options.ignore_game_pak && !g_debug_options.ignore_game_pak_sprites) { u32 front_sprite_tile_id = global_tile_id_end + (30 * 16); load_sprite_compressed(grabbed_front_sprite, - (const unsigned int *)*( - u32 *)(curr_GBA_rom.loc_gMonFrontPicTable + (0 * 8)), - front_sprite_tile_id, PULLED_SPRITE_PAL, ATTR0_SQUARE, - ATTR1_SIZE_64x64, 1); + (const unsigned int *)*(u32 *)(curr_GBA_rom.loc_gMonFrontPicTable + (0 * 8)), + front_sprite_tile_id, PULLED_SPRITE_PAL, ATTR0_SQUARE, ATTR1_SIZE_64x64, 1); update_front_box_sprite(&celebi, false); obj_set_pos(grabbed_front_sprite, 88, 16); obj_unhide(grabbed_front_sprite, 0); @@ -267,8 +252,8 @@ void dbg_inject_pkmn(void *context, unsigned user_param) if (ret == UINT32_MAX) { - // Failed to inject the Pokémon, all boxes are full. You can handle this - // case as needed (e.g., show an error message). + // Failed to inject the Pokémon, all boxes are full. You can handle this case as needed + // (e.g., show an error message). return; } @@ -284,14 +269,12 @@ void dbg_inject_pkmn(void *context, unsigned user_param) convert_OT_to_utf8(encoded_OT, decoded_OT_utf8, tables.gen3_charset); npf_snprintf(text_buffer, sizeof(text_buffer), - "%s received a Celebi!\n Celebi was sent to box %d!", decoded_OT_utf8, - boxIndex); + "%s received a Celebi!\n Celebi was sent to box %d!", decoded_OT_utf8, boxIndex); ptgb_write_debug(tables.gen3_charset, text_buffer, false); wait_for_user_to_continue(H_MAX, V_MAX); - if (!g_debug_options.ignore_game_pak && - !g_debug_options.ignore_game_pak_sprites) + if (!g_debug_options.ignore_game_pak && !g_debug_options.ignore_game_pak_sprites) { obj_hide(grabbed_front_sprite); } @@ -302,10 +285,8 @@ void dbg_inject_pkmn(void *context, unsigned user_param) void dbg_unlock_mystery(void *context, unsigned user_param) { - const Game game_type = - convert_rom_game_id_to_ptgb_game(curr_GBA_rom.gamecode); - const Language game_lang = - convert_rom_lang_to_ptgb_lang(curr_GBA_rom.language); + const Game game_type = convert_rom_game_id_to_ptgb_game(curr_GBA_rom.gamecode); + const Language game_lang = convert_rom_lang_to_ptgb_lang(curr_GBA_rom.language); Gen3CartridgeSaveReader reader(global_memory_buffer); Gen3SaveManager save_manager(game_type, game_lang, reader); @@ -342,15 +323,13 @@ void dbg_inject_wc3(void *context, unsigned user_param) return; } - const Game game_type = - convert_rom_game_id_to_ptgb_game(curr_GBA_rom.gamecode); + const Game game_type = convert_rom_game_id_to_ptgb_game(curr_GBA_rom.gamecode); if (game_type != EMERALD) { return; } - const Language game_lang = - convert_rom_lang_to_ptgb_lang(curr_GBA_rom.language); + const Language game_lang = convert_rom_lang_to_ptgb_lang(curr_GBA_rom.language); Gen3CartridgeSaveReader reader(global_memory_buffer); Gen3SaveManager save_manager(game_type, game_lang, reader); @@ -370,15 +349,13 @@ void dbg_inject_me3(void *context, unsigned user_param) return; } - const Game game_type = - convert_rom_game_id_to_ptgb_game(curr_GBA_rom.gamecode); + const Game game_type = convert_rom_game_id_to_ptgb_game(curr_GBA_rom.gamecode); if (game_type != RUBY && game_type != SAPPHIRE) { return; } - const Language game_lang = - convert_rom_lang_to_ptgb_lang(curr_GBA_rom.language); + const Language game_lang = convert_rom_lang_to_ptgb_lang(curr_GBA_rom.language); Gen3CartridgeSaveReader reader(global_memory_buffer); Gen3SaveManager save_manager(game_type, game_lang, reader); diff --git a/source/flash_mem.cpp b/source/flash_mem.cpp index 5dcc4c8..2f3efbf 100644 --- a/source/flash_mem.cpp +++ b/source/flash_mem.cpp @@ -23,16 +23,13 @@ void initialize_memory_locations() copy_save_to_ram(SAVE_A_OFFSET + SAVE_INDEX_OFFSET, &save_A_index[0], 0x04); copy_save_to_ram(SAVE_B_OFFSET + SAVE_INDEX_OFFSET, &save_B_index[0], 0x04); - // Save indices are little-endian in-sector; decode directly without byte - // swapping. - const u32 saveAIndex = static_cast(save_A_index[0]) | - (static_cast(save_A_index[1]) << 8) | - (static_cast(save_A_index[2]) << 16) | - (static_cast(save_A_index[3]) << 24); - const u32 saveBIndex = static_cast(save_B_index[0]) | - (static_cast(save_B_index[1]) << 8) | - (static_cast(save_B_index[2]) << 16) | - (static_cast(save_B_index[3]) << 24); + // Save indices are little-endian in-sector; decode directly without byte swapping. + const u32 saveAIndex = + static_cast(save_A_index[0]) | (static_cast(save_A_index[1]) << 8) | + (static_cast(save_A_index[2]) << 16) | (static_cast(save_A_index[3]) << 24); + const u32 saveBIndex = + static_cast(save_B_index[0]) | (static_cast(save_B_index[1]) << 8) | + (static_cast(save_B_index[2]) << 16) | (static_cast(save_B_index[3]) << 24); // Determines if save A or B is more recent if (saveBIndex > saveAIndex) @@ -41,9 +38,8 @@ void initialize_memory_locations() } // Populates the memory_section_array with the correct pointer locations - // The sections within the save slot are rotated on every save. So it - // doesn't start at the first section. However, the next sections follow - // sequentially. + // The sections within the save slot are rotated on every save. So it doesn't + // start at the first section. However, the next sections follow sequentially. // https://bulbapedia.bulbagarden.net/wiki/Save_data_structure_(Generation_III)#Section_ID copy_save_to_ram(newest_save_offset + SECTION_ID_OFFSET, &mem_id, 1); for (int i = 0; i < TOTAL_SAVE_SECTIONS; i++) @@ -57,17 +53,15 @@ void initialize_memory_locations() // Bring the Memory ID back to the first one mem_id = (mem_id + 1) % TOTAL_SAVE_SECTIONS; - if (false) // This will print out a section of the FLASH mem for debugging - // purposes + if (false) // This will print out a section of the FLASH mem for debugging purposes { int mem_start = 0xF80; int mem_section = 1; - copy_save_to_ram(memory_section_array[mem_section], - &global_memory_buffer[0], 0x1000); + copy_save_to_ram(memory_section_array[mem_section], &global_memory_buffer[0], 0x1000); tte_set_pos(8, 0); tte_write("loc: "); - tte_write(ptgb::to_string(static_cast( - memory_section_array[mem_section] + mem_start))); + tte_write( + ptgb::to_string(static_cast(memory_section_array[mem_section] + mem_start))); tte_write("\n"); for (int i = mem_start; i < (128 + mem_start); i++) { @@ -118,8 +112,7 @@ void print_mem_section() out[0] = get_char_from_charset(charset, mem_name); out[1] = get_char_from_charset(charset, '-'); - out[2] = get_char_from_charset(charset, mem_id + 0xA1); // Kinda a dumb way - to + out[2] = get_char_from_charset(charset, mem_id + 0xA1); // Kinda a dumb way to //tte_set_pos(0, 0); ptgb_write_simple(out, true); */ @@ -141,15 +134,13 @@ void update_memory_buffer_checksum(u8 *sector_buffer, bool hall_of_fame) { u32 checksum = 0x00; - // Section 13 is the last PC buffer (I) and that one only has 2000 bytes of - // data. source: + // Section 13 is the last PC buffer (I) and that one only has 2000 bytes of data. + // source: // https://bulbapedia.bulbagarden.net/wiki/Save_data_structure_(Generation_III)#Section_ID - const u32 num_of_bytes = - (sector_buffer[SECTION_ID_OFFSET] != 13) ? 3968 : 2000; + const u32 num_of_bytes = (sector_buffer[SECTION_ID_OFFSET] != 13) ? 3968 : 2000; // Assemble words manually to avoid alignment and aliasing issues when the - // sector buffer is only guaranteed to be byte-aligned. So not 32-bit - // aligned. + // sector buffer is only guaranteed to be byte-aligned. So not 32-bit aligned. for (u32 offset = 0; offset < num_of_bytes; offset += sizeof(u32)) { const u32 cur = static_cast(sector_buffer[offset]) | @@ -159,8 +150,7 @@ void update_memory_buffer_checksum(u8 *sector_buffer, bool hall_of_fame) checksum += cur; } - const u16 small_checksum = - ((checksum & 0xFFFF0000) >> 16) + (checksum & 0x0000FFFF); + const u16 small_checksum = ((checksum & 0xFFFF0000) >> 16) + (checksum & 0x0000FFFF); const u32 checksum_offset = hall_of_fame ? 0x0FF4 : 0x0FF6; sector_buffer[checksum_offset] = small_checksum & 0x00FF; @@ -173,21 +163,16 @@ bool read_flag(u16 flag_id) { // tte_set_pos(0, 0); tte_write("#{cx:0xD000}Attempting to read byte "); - tte_write(ptgb::to_string( - (curr_GBA_rom.offset_flags + (flag_id / 8)) % 0xF80)); + tte_write(ptgb::to_string((curr_GBA_rom.offset_flags + (flag_id / 8)) % 0xF80)); tte_write(" of memory section "); - tte_write(ptgb::to_string( - 1 + ((curr_GBA_rom.offset_flags + (flag_id / 8)) / 0xF80))); + tte_write(ptgb::to_string(1 + ((curr_GBA_rom.offset_flags + (flag_id / 8)) / 0xF80))); tte_write(" for flag "); tte_write(ptgb::to_string(flag_id)); tte_write(". Flag is "); copy_save_to_ram( - memory_section_array - [1 + ((curr_GBA_rom.offset_flags + (flag_id / 8)) / 0xF80)], + memory_section_array[1 + ((curr_GBA_rom.offset_flags + (flag_id / 8)) / 0xF80)], &global_memory_buffer[0], 0x1000); - u8 flags = - global_memory_buffer[(curr_GBA_rom.offset_flags + (flag_id / 8)) % - 0xF80]; + u8 flags = global_memory_buffer[(curr_GBA_rom.offset_flags + (flag_id / 8)) % 0xF80]; tte_write(ptgb::to_string((flags >> (flag_id % 8)) & 0b1)); while (true) { @@ -195,20 +180,16 @@ bool read_flag(u16 flag_id) } copy_save_to_ram( - memory_section_array[1 + ((curr_GBA_rom.offset_flags + (flag_id / 8)) / - 0xF80)], + memory_section_array[1 + ((curr_GBA_rom.offset_flags + (flag_id / 8)) / 0xF80)], &global_memory_buffer[0], 0x1000); - u8 flags = - global_memory_buffer[(curr_GBA_rom.offset_flags + (flag_id / 8)) % - 0xF80]; + u8 flags = global_memory_buffer[(curr_GBA_rom.offset_flags + (flag_id / 8)) % 0xF80]; return (flags >> (flag_id % 8)) & 0b1; } bool compare_map_and_npc_data(int map_bank, int map_id, int npc_id) { copy_save_to_ram(memory_section_array[4], &global_memory_buffer[0], 0x1000); - return (global_memory_buffer[curr_GBA_rom.offset_script + 4] == - MGSCRIPT_MAGIC_VALUE && + return (global_memory_buffer[curr_GBA_rom.offset_script + 4] == MGSCRIPT_MAGIC_VALUE && global_memory_buffer[curr_GBA_rom.offset_script + 5] == map_bank && global_memory_buffer[curr_GBA_rom.offset_script + 6] == map_id && global_memory_buffer[curr_GBA_rom.offset_script + 7] == npc_id); diff --git a/source/global_frame_controller.cpp b/source/global_frame_controller.cpp index 4594b08..0d7aa6a 100644 --- a/source/global_frame_controller.cpp +++ b/source/global_frame_controller.cpp @@ -21,9 +21,9 @@ int fennel_blink_state = 0; bool missingno_enabled = false; bool treecko_enabled = false; -// split off from global_next_frame to limit the stack usage of the -// general_text_table_buffer to the execution of this function the noinline -// attribute prevents the compiler from inlining this function back into the +// split off from global_next_frame to limit the stack usage of the general_text_table_buffer to +// the execution of this function +// the noinline attribute prevents the compiler from inlining this function back into the // global_next_frame function static void __attribute__((noinline)) show_pulled_cart_error() { @@ -35,13 +35,11 @@ static void __attribute__((noinline)) show_pulled_cart_error() get_text_table_chunks(GENERAL_INDEX, &chunkList, &numChunks, &chunkSize); FileContainerReader general_text_reader(chunkList, numChunks, chunkSize); - general_text_reader.init( - decompression_buffer, sizeof(decompression_buffer)); + general_text_reader.init(decompression_buffer, sizeof(decompression_buffer)); ptgb_write_textbox( - general_text_reader.getPointerToFileInDecompressionBuffer( - GENERAL_pulled_cart_error), - true, true, GENERAL_INDEX, GENERAL_pulled_cart_error, true); + general_text_reader.getPointerToFileInDecompressionBuffer(GENERAL_pulled_cart_error), true, + true, GENERAL_INDEX, GENERAL_pulled_cart_error, true); } void global_next_frame() @@ -78,9 +76,8 @@ void global_next_frame() set_menu_sprite_pal(1); } - // This way of determining the animation speed is stupid and will be - // changed, but leaving it for now since the whole animation will be - // changing. + // This way of determining the animation speed is stupid and will be changed, but leaving it for + // now since the whole animation will be changing. if (curr_link_animation_state != state_off && global_frame_count % (40 / curr_link_animation_state) == 0) { @@ -100,16 +97,11 @@ void enable_auto_random() { rand_enabled = true; } void disable_auto_random() { rand_enabled = false; } const unsigned short MENU_PALS[5][4] = { - {RGB15(31, 31, 31), RGB15(31, 19, 10), RGB15(31, 7, 01), - RGB15(00, 00, 00)}, // Red - {RGB15(31, 31, 31), RGB15(31, 19, 10), RGB15(10, 9, 31), - RGB15(00, 00, 00)}, // Blue - {RGB15(31, 31, 31), RGB15(31, 19, 10), RGB15(07, 23, 03), - RGB15(00, 00, 00)}, // Green - {RGB15(31, 31, 31), RGB15(31, 19, 10), RGB15(15, 10, 03), - RGB15(00, 00, 00)}, // Brown - {RGB15(31, 31, 31), RGB15(31, 19, 10), RGB15(29, 5, 13), - RGB15(00, 00, 00)}, // Pink + {RGB15(31, 31, 31), RGB15(31, 19, 10), RGB15(31, 7, 01), RGB15(00, 00, 00)}, // Red + {RGB15(31, 31, 31), RGB15(31, 19, 10), RGB15(10, 9, 31), RGB15(00, 00, 00)}, // Blue + {RGB15(31, 31, 31), RGB15(31, 19, 10), RGB15(07, 23, 03), RGB15(00, 00, 00)}, // Green + {RGB15(31, 31, 31), RGB15(31, 19, 10), RGB15(15, 10, 03), RGB15(00, 00, 00)}, // Brown + {RGB15(31, 31, 31), RGB15(31, 19, 10), RGB15(29, 5, 13), RGB15(00, 00, 00)}, // Pink }; void set_menu_sprite_pal(int frame) @@ -140,9 +132,8 @@ void set_menu_sprite_pal(int frame) } } -static const int path[12][2] = {{19, 18}, {19, 19}, {18, 19}, {17, 19}, - {16, 19}, {15, 19}, {14, 19}, {13, 19}, {12, 19}, {11, 19}, {10, 19}, - {24, 24}}; +static const int path[12][2] = {{19, 18}, {19, 19}, {18, 19}, {17, 19}, {16, 19}, {15, 19}, + {14, 19}, {13, 19}, {12, 19}, {11, 19}, {10, 19}, {24, 24}}; void run_link_cable_animation(int frame) { @@ -346,7 +337,4 @@ void convert_int_to_ptgb_str(int val, byte str[], int min_length) str[count] = 0xFF; } -void convert_int_to_ptgb_str(int val, byte str[]) -{ - convert_int_to_ptgb_str(val, str, 0); -} +void convert_int_to_ptgb_str(int val, byte str[]) { convert_int_to_ptgb_str(val, str, 0); } diff --git a/source/libstd_replacements.cpp b/source/libstd_replacements.cpp index 3a00aaf..5c503f6 100644 --- a/source/libstd_replacements.cpp +++ b/source/libstd_replacements.cpp @@ -16,8 +16,7 @@ // recommended for a 32 bit system to have at least 33 bytes available // source: https://cplusplus.com/reference/cstdlib/itoa/ -// unfortunately itoa is not standardized, so we'll have to make do with -// snprintf +// unfortunately itoa is not standardized, so we'll have to make do with snprintf static char conversion_buffer[33]; const char *ptgb::to_string(int intVal) @@ -32,8 +31,8 @@ const char *ptgb::to_string(unsigned int wordVal) return conversion_buffer; } -// when compiling with -nostdlib++, we need to provide our own operator new and -// delete implementations Regular operator new +// when compiling with -nostdlib++, we need to provide our own operator new and delete +// implementations Regular operator new void *operator new(std::size_t size) { void *ptr = malloc(size); @@ -49,10 +48,7 @@ void *operator new(std::size_t size) } // nothrow version -void *operator new(std::size_t size, const std::nothrow_t &) noexcept -{ - return malloc(size); -} +void *operator new(std::size_t size, const std::nothrow_t &) noexcept { return malloc(size); } // regular array operator new void *operator new[](std::size_t size) @@ -66,10 +62,7 @@ void *operator new[](std::size_t size) } // nothrow array operator new -void *operator new[](std::size_t size, const std::nothrow_t &) noexcept -{ - return malloc(size); -} +void *operator new[](std::size_t size, const std::nothrow_t &) noexcept { return malloc(size); } // operator delete void operator delete(void *ptr) noexcept { free(ptr); } @@ -81,10 +74,7 @@ void operator delete[](void *ptr) noexcept { free(ptr); } void operator delete(void *ptr, const std::nothrow_t &) noexcept { free(ptr); } // nothrow array delete -void operator delete[](void *ptr, const std::nothrow_t &) noexcept -{ - free(ptr); -} +void operator delete[](void *ptr, const std::nothrow_t &) noexcept { free(ptr); } // sized delete void operator delete(void *ptr, std::size_t size) noexcept diff --git a/source/link_handler.cpp b/source/link_handler.cpp index b9c5b29..e6bd6e8 100644 --- a/source/link_handler.cpp +++ b/source/link_handler.cpp @@ -40,9 +40,9 @@ LinkSPI *linkSPI = &linkSPIInstance; #define DISCOVERY_TIMEOUT_TRANSFERS 2048 #define DISCOVERY_CONFIRM_TIMEOUT_TRANSFERS 180 -// Here's a compilation check to ensure that the size of these structs match our -// expectations. Just update it if you changed the struct members. The -// data-generator process prints their actual sizes. +// Here's a compilation check to ensure that the size of these structs match our expectations. +// Just update it if you changed the struct members. The data-generator process prints their actual +// sizes. static_assert(sizeof(struct GB_ROM) == 140); static_assert(sizeof(struct ROM_DATA) == 164); @@ -51,16 +51,12 @@ LinkConnection globalLinkCable; /** * @brief This function determines the expected packet arrival address. * - * PTGB sends packets with an additional read pointer. For packets intended to - * run commands, this address is set to the address the packet is supposed to - * arrive at. + * PTGB sends packets with an additional read pointer. For packets intended to run commands, + * this address is set to the address the packet is supposed to arrive at. * * This address depends on the generation of the Game Boy ROM being used. */ -static u16 determinePacketArrivalAddress(int gen) -{ - return (gen == 1) ? 0xC6DC : 0xC8DC; -} +static u16 determinePacketArrivalAddress(int gen) { return (gen == 1) ? 0xC6DC : 0xC8DC; } void linkCableIRQ() { @@ -68,18 +64,17 @@ void linkCableIRQ() ---------------- This handshake process can be a bit weird, so let's break it down: - First we exchange the bytes via handshake. inData will be set to the - recieved byte, and the byte we send out will be outData. + First we exchange the bytes via handshake. inData will be set to the recieved byte, and the byte + we send out will be outData. - Then we determining what byte we will be sending out next, based on - enterState and inByte in handleStateLogic(). This will set exitState and - nextOutByte. + Then we determining what byte we will be sending out next, based on enterState and inByte in + handleStateLogic(). This will set exitState and nextOutByte. Then we print our information in the following format: globalCounter enterState:stateCounter:exitState inData outData - We then prepare for the next cycle. Counters are incremented (or reset), - enterState is set to exitState, and outByte is set to nextOutByte. + We then prepare for the next cycle. Counters are incremented (or reset), enterState is set to + exitState, and outByte is set to nextOutByte. ---------------- */ if (!globalLinkCable.earlyExit()) @@ -88,8 +83,7 @@ void linkCableIRQ() globalLinkCable.handleStateLogic(); - if (g_debug_options.print_link_data || - g_debug_options.print_link_packets) + if (g_debug_options.print_link_data || g_debug_options.print_link_packets) { globalLinkCable.printData(); } @@ -122,10 +116,8 @@ void LinkPacket::loadSecondaryPayload(byte *payload, int payloadSize) } secondaryPayloadSizeChecksum = 0x100 - secondaryPayloadSizeChecksum; - PTGB_MGBA_INFO( - "Secondary payload loaded: dataSize=%d packetSizeArg=%d checksum=%X", - secondaryPayloadDataSize, - secondaryPayloadDataSize + SECONDARY_PAYLOAD_HEADER_SIZE, + PTGB_MGBA_INFO("Secondary payload loaded: dataSize=%d packetSizeArg=%d checksum=%X", + secondaryPayloadDataSize, secondaryPayloadDataSize + SECONDARY_PAYLOAD_HEADER_SIZE, secondaryPayloadSizeChecksum); } @@ -151,8 +143,8 @@ void LinkConnection::setup(const u16 *debug_charset) if (g_debug_options.write_cable_data_to_save == WRITE_CABLE_DATA_MODE_SRAM) { - // if we're writing the cable data to SRAM, we should clear the SRAM - // first to make sure there's no leftover data from previous transfers + // if we're writing the cable data to SRAM, we should clear the SRAM first to make sure + // there's no leftover data from previous transfers volatile u8 *cur = SRAM_PTR; volatile u8 *end = SRAM_PTR + 0x10000; while (cur < end) @@ -161,8 +153,7 @@ void LinkConnection::setup(const u16 *debug_charset) ++cur; } } - else if (g_debug_options.write_cable_data_to_save == - WRITE_CABLE_DATA_MODE_CART) + else if (g_debug_options.write_cable_data_to_save == WRITE_CABLE_DATA_MODE_CART) { // before each write, we need to erase the sector. // so, let's do that for the first one before we start writing anything. @@ -269,8 +260,7 @@ void LinkConnection::exchangeBytes() int timeout_frames = 10; inData = linkSPI->transfer(outData, [&timeout_frames]() { - // In the mGBA Lua bridge, replies arrive via emulator callbacks between - frames. + // In the mGBA Lua bridge, replies arrive via emulator callbacks between frames. // Waiting here prevents valid bytes from being reported as timeouts. global_next_frame(); return --timeout_frames <= 0; }); @@ -283,8 +273,8 @@ void LinkConnection::exchangeBytes() // PTGB_MGBA_INFO("in: %X, out: %X", inData, outData); break; case WRITE_CABLE_DATA_MODE_SRAM: - // Pretend transfer, by loading the bytes from SRAM (where we stored - // them with writeData() in a previous transfer) + // Pretend transfer, by loading the bytes from SRAM (where we stored them with writeData() + // in a previous transfer) inData = (*(SRAM_PTR + link_cable_array_index)); ++link_cable_array_index; outData = (*(SRAM_PTR + link_cable_array_index)); @@ -292,22 +282,22 @@ void LinkConnection::exchangeBytes() break; case WRITE_CABLE_DATA_MODE_CART: { - // Pretend transfer, by loading the bytes from the cartridge save. - // (where we stored them with writeData() in a previous transfer) skip - // the first 6 bytes, which are for human consumption + // Pretend transfer, by loading the bytes from the cartridge save. (where we stored them + // with writeData() in a previous transfer) skip the first 6 bytes, which are for human + // consumption link_cable_array_index += 6; - inData = read_byte_save((0x1000 * link_cable_memory_section_index) + - link_cable_array_index); + inData = + read_byte_save((0x1000 * link_cable_memory_section_index) + link_cable_array_index); ++link_cable_array_index; - outData = read_byte_save((0x1000 * link_cable_memory_section_index) + - link_cable_array_index); + outData = + read_byte_save((0x1000 * link_cable_memory_section_index) + link_cable_array_index); ++link_cable_array_index; if (link_cable_array_index >= 0x1000) { - // if we reached the end of the section, we need to load the next - // section (if there is one) + // if we reached the end of the section, we need to load the next section (if there is + // one) ++link_cable_memory_section_index; link_cable_array_index = 0; } @@ -321,8 +311,7 @@ void LinkConnection::startConnection(LinkState startState) switch (startState) { case INITIAL_CONNECTION: - // Start searching and make sure the first byte sent requests the - // external clock + // Start searching and make sure the first byte sent requests the external clock irq_disable(II_TIMER3); REG_TM3CNT = 0; REG_IF = (1 << II_TIMER3); @@ -384,8 +373,7 @@ void LinkConnection::printData() ptgb_write_debug(this->debug_charset, line, true); } - // TODO: This is pretty rough, but it's the best we can do until the - // text engine rewrite. + // TODO: This is pretty rough, but it's the best we can do until the text engine rewrite. if (g_debug_options.print_link_packets && currIncomingPacket != nullptr) { tte_erase_rect(160, 16, H_MAX, V_MAX); @@ -446,23 +434,17 @@ void LinkConnection::writeData() { // save the data to the cartridge in chunks of 4 KB // WARNING: If you want to add or remove fields here, - // make sure to keep the number of bytes a clean divider of 4096 - // (global_memory_buffer_size) + // make sure to keep the number of bytes a clean divider of 4096 (global_memory_buffer_size) - // the next 6 bytes are for human consumption when viewed in a hex - // editor. they can be useful to correlate the current LinkConnection - // state with the data that was sent over the cable. but they're not - // needed for reconstructing the conversation with + // the next 6 bytes are for human consumption when viewed in a hex editor. + // they can be useful to correlate the current LinkConnection state with the data that was + // sent over the cable. but they're not needed for reconstructing the conversation with // load_cable_data_from_save - global_memory_buffer[writeBufferOffset + 0] = - (u8)(globalStateCounter >> 8) & 0xFF; - global_memory_buffer[writeBufferOffset + 1] = - (u8)(globalStateCounter >> 0) & 0xFF; + global_memory_buffer[writeBufferOffset + 0] = (u8)(globalStateCounter >> 8) & 0xFF; + global_memory_buffer[writeBufferOffset + 1] = (u8)(globalStateCounter >> 0) & 0xFF; global_memory_buffer[writeBufferOffset + 2] = (u8)enterState; - global_memory_buffer[writeBufferOffset + 3] = - (u8)(subStateCounter >> 8) & 0xFF; - global_memory_buffer[writeBufferOffset + 4] = - (u8)(subStateCounter >> 0) & 0xFF; + global_memory_buffer[writeBufferOffset + 3] = (u8)(subStateCounter >> 8) & 0xFF; + global_memory_buffer[writeBufferOffset + 4] = (u8)(subStateCounter >> 0) & 0xFF; global_memory_buffer[writeBufferOffset + 5] = (u8)exitState; // actual data bytes start here. @@ -492,8 +474,7 @@ void LinkConnection::handleStateLogic() linkSPI->activate(LinkSPI::Mode::MASTER_256KBPS); outData = 0x01; nextOutData = 0x01; - REG_TM3D = -(DISCOVERY_TIMER_MIN + - (globalStateCounter & DISCOVERY_TIMER_PHASE_MASK)); + REG_TM3D = -(DISCOVERY_TIMER_MIN + (globalStateCounter & DISCOVERY_TIMER_PHASE_MASK)); REG_TM3CNT = TM_FREQ_1024 | TM_IRQ | TM_ENABLE; exitState = CLOCK_ACQUIRE; break; @@ -503,16 +484,15 @@ void LinkConnection::handleStateLogic() if (inData == 0x02) { - // Receiving 0x02 while sending 0x01 means the other Game Boy - // offered external-clock mode and should now have selected the GBA - // as master. + // Receiving 0x02 while sending 0x01 means the other Game Boy offered + // external-clock mode and should now have selected the GBA as master. REG_TM3D = -INITIAL_LINK_TIMER; exitState = CLOCK_CONFIRM; } else if (inData == 0xFE) { - // Keep compatibility with an already-established connection where - // the role-selection byte was completed before discovery began. + // Keep compatibility with an already-established connection where the + // role-selection byte was completed before discovery began. REG_TM3D = -INITIAL_LINK_TIMER; exitState = SAVE_SUCCESS; nextOutData = 0x01; @@ -523,8 +503,7 @@ void LinkConnection::handleStateLogic() } else { - REG_TM3D = -(DISCOVERY_TIMER_MIN + - (subStateCounter & DISCOVERY_TIMER_PHASE_MASK)); + REG_TM3D = -(DISCOVERY_TIMER_MIN + (subStateCounter & DISCOVERY_TIMER_PHASE_MASK)); } break; @@ -649,8 +628,7 @@ void LinkConnection::handleStateLogic() case GET_CHECKSUM: if (inData != 0xFD) { - dataOutBuffer[dataOutBufferCurrIndex % DATA_OUT_BUFFER_SIZE] = - inData; + dataOutBuffer[dataOutBufferCurrIndex % DATA_OUT_BUFFER_SIZE] = inData; dataOutBufferCurrIndex++; nextOutData = 0x01; } @@ -662,8 +640,8 @@ void LinkConnection::handleStateLogic() while (true) { } - // Add in an error message thrown here once we, ya know, rewrite - // the text engine to make that possible + // Add in an error message thrown here once we, ya know, rewrite the text engine to + // make that possible } loadPayloadByROM(currROM); exitState = SEND_SPECIFIC_PAYLOAD; @@ -698,8 +676,7 @@ void LinkConnection::handleStateLogic() break; case SEND_FIRST_PACKET: - // In order to make sure everything is set to go, we need to send a - // dummy packet. + // In order to make sure everything is set to go, we need to send a dummy packet. currOutgoingPacket = &dummyPacket; nextOutData = 0xFF; exitState = STANDARD_PACKET_EXCHANGE; @@ -725,8 +702,7 @@ void LinkConnection::handleStateLogic() nextOutData = currOutgoingPacket->command; if (currOutgoingPacket->command == CMD_SoftReset) { - // Immedaitely remove the Soft Reset packet from in use, it will - // not get a response. + // Immedaitely remove the Soft Reset packet from in use, it will not get a response. currOutgoingPacket->inUse = false; } break; @@ -743,18 +719,14 @@ void LinkConnection::handleStateLogic() nextOutData = currOutgoingPacket->pointer >> 8; break; case TOTAL_PACKET_LENGTH: - PTGB_MGBA_INFO("Sent packet: cmd=[%X], args=[%X, %X], ptr=[%X], " - "ID=[%X], Data=[%X, %X, %X, %X, %X, %X, %X, %X]", + PTGB_MGBA_INFO("Sent packet: cmd=[%X], args=[%X, %X], ptr=[%X], ID=[%X], Data=[%X, %X, " + "%X, %X, %X, %X, %X, %X]", currOutgoingPacket->command, currOutgoingPacket->argument[0], currOutgoingPacket->argument[1], currOutgoingPacket->pointer, - currOutgoingPacket->packetID, - currOutgoingPacket->recievedData[0], - currOutgoingPacket->recievedData[1], - currOutgoingPacket->recievedData[2], - currOutgoingPacket->recievedData[3], - currOutgoingPacket->recievedData[4], - currOutgoingPacket->recievedData[5], - currOutgoingPacket->recievedData[6], + currOutgoingPacket->packetID, currOutgoingPacket->recievedData[0], + currOutgoingPacket->recievedData[1], currOutgoingPacket->recievedData[2], + currOutgoingPacket->recievedData[3], currOutgoingPacket->recievedData[4], + currOutgoingPacket->recievedData[5], currOutgoingPacket->recievedData[6], currOutgoingPacket->recievedData[7]); exitState = RUNNING_CODE_DELAY; nextOutData = 0xFF; @@ -769,8 +741,7 @@ void LinkConnection::handleStateLogic() case RUNNING_CODE_DELAY: { - // We are currently processing something, we need to wait for that to - // finish. + // We are currently processing something, we need to wait for that to finish. if (inData == 0xFE) { nextOutData = 0xFF; @@ -779,8 +750,7 @@ void LinkConnection::handleStateLogic() { if (currOutgoingPacket->secondaryPayloadData != nullptr) { - // We get our response after the GB gets the secondary payload, - // send that first. + // We get our response after the GB gets the secondary payload, send that first. exitState = SECONDARY_PACKET_EXCHANGE; } else @@ -797,37 +767,31 @@ void LinkConnection::handleStateLogic() { case 0: nextOutData = 0xFD; - PTGB_MGBA_INFO("Secondary byte: sub=%d phase=preamble out=%X in=%X " - "packet=%X cmd=%d", - subStateCounter, nextOutData, inData, - currOutgoingPacket->packetID, currOutgoingPacket->command); + PTGB_MGBA_INFO("Secondary byte: sub=%d phase=preamble out=%X in=%X packet=%X cmd=%d", + subStateCounter, nextOutData, inData, currOutgoingPacket->packetID, + currOutgoingPacket->command); break; case 1: nextOutData = linkPacketArrIndex; currOutgoingPacket->packetID = linkPacketArrIndex; - PTGB_MGBA_INFO("Secondary byte: sub=%d phase=counter out=%X in=%X " - "packet=%X cmd=%d", - subStateCounter, nextOutData, inData, - currOutgoingPacket->packetID, currOutgoingPacket->command); + PTGB_MGBA_INFO("Secondary byte: sub=%d phase=counter out=%X in=%X packet=%X cmd=%d", + subStateCounter, nextOutData, inData, currOutgoingPacket->packetID, + currOutgoingPacket->command); break; case 2: // The command ID matches the saftey byte (0xFF) nextOutData = 0xFF; - PTGB_MGBA_INFO("Secondary byte: sub=%d phase=safety out=%X in=%X " - "packet=%X cmd=%d", - subStateCounter, nextOutData, inData, - currOutgoingPacket->packetID, currOutgoingPacket->command); + PTGB_MGBA_INFO("Secondary byte: sub=%d phase=safety out=%X in=%X packet=%X cmd=%d", + subStateCounter, nextOutData, inData, currOutgoingPacket->packetID, + currOutgoingPacket->command); break; case 3: - nextOutData = - currOutgoingPacket->secondaryPayloadDataSize + - 1; // We need to include the checksum value here as well - PTGB_MGBA_INFO("Secondary byte: sub=%d phase=dataSize out=%X in=%X " - "dataSize=%d packetSizeArg=%d", - subStateCounter, nextOutData, inData, - currOutgoingPacket->secondaryPayloadDataSize, - currOutgoingPacket->secondaryPayloadDataSize + - SECONDARY_PAYLOAD_HEADER_SIZE); + nextOutData = currOutgoingPacket->secondaryPayloadDataSize + + 1; // We need to include the checksum value here as well + PTGB_MGBA_INFO( + "Secondary byte: sub=%d phase=dataSize out=%X in=%X dataSize=%d packetSizeArg=%d", + subStateCounter, nextOutData, inData, currOutgoingPacket->secondaryPayloadDataSize, + currOutgoingPacket->secondaryPayloadDataSize + SECONDARY_PAYLOAD_HEADER_SIZE); break; default: // We're through all the constant values, let's do the rest. @@ -836,23 +800,18 @@ void LinkConnection::handleStateLogic() { nextOutData = currOutgoingPacket - ->secondaryPayloadData[subStateCounter - - SECONDARY_PAYLOAD_HEADER_SIZE]; - PTGB_MGBA_INFO("Secondary byte: sub=%d phase=data index=%d " - "out=%X in=%X packet=%X", - subStateCounter, - subStateCounter - SECONDARY_PAYLOAD_HEADER_SIZE, - nextOutData, inData, currOutgoingPacket->packetID); + ->secondaryPayloadData[subStateCounter - SECONDARY_PAYLOAD_HEADER_SIZE]; + PTGB_MGBA_INFO("Secondary byte: sub=%d phase=data index=%d out=%X in=%X packet=%X", + subStateCounter, subStateCounter - SECONDARY_PAYLOAD_HEADER_SIZE, nextOutData, + inData, currOutgoingPacket->packetID); } else if ((subStateCounter - SECONDARY_PAYLOAD_HEADER_SIZE) == currOutgoingPacket->secondaryPayloadDataSize) { // Add the checksum and we're done with the packet. nextOutData = currOutgoingPacket->secondaryPayloadSizeChecksum; - PTGB_MGBA_INFO("Secondary byte: sub=%d phase=checksum out=%X " - "in=%X packet=%X", - subStateCounter, nextOutData, inData, - currOutgoingPacket->packetID); + PTGB_MGBA_INFO("Secondary byte: sub=%d phase=checksum out=%X in=%X packet=%X", + subStateCounter, nextOutData, inData, currOutgoingPacket->packetID); } else if (inData != currOutgoingPacket->packetID) { @@ -861,13 +820,12 @@ void LinkConnection::handleStateLogic() } else { - PTGB_MGBA_INFO("Secondary response counter seen: sub=%d " - "packet=%X cmd=%d in=%X", - subStateCounter, currOutgoingPacket->packetID, - currOutgoingPacket->command, inData); - // Great, the secondary payload has been processed and we are - // currently receiving the response. Let's log the first - // response byte and head back to the normal packet talk + PTGB_MGBA_INFO("Secondary response counter seen: sub=%d packet=%X cmd=%d in=%X", + subStateCounter, currOutgoingPacket->packetID, currOutgoingPacket->command, + inData); + // Great, the secondary payload has been processed and we are currently receiving + // the response. Let's log the first response byte and head back to the normal + // packet talk exitState = STANDARD_PACKET_EXCHANGE; // Use a dummy packet to flush it out @@ -880,12 +838,11 @@ void LinkConnection::handleStateLogic() break; case PROCESS_PACKET: - currIncomingPacket = &linkPacketArr[dataOutBuffer[INP_COUNTER_INDEX] % - LINK_PACKET_ARRAY_SIZE]; + currIncomingPacket = + &linkPacketArr[dataOutBuffer[INP_COUNTER_INDEX] % LINK_PACKET_ARRAY_SIZE]; if (allPacketsProcessed()) { - // We have no valid responses that we are looking for, go to the - // end. + // We have no valid responses that we are looking for, go to the end. exitState = END; } else if (processPacket()) @@ -952,57 +909,52 @@ void LinkConnection::prepareForNextCycle() /* * So, dealing with writing to the cartridge in the IRQ handler was a no-go. - * It just caused too many issues with data corruption, probably because the - * write and erase_sector operation was taking too long. + * It just caused too many issues with data corruption, probably because the write and erase_sector + * operation was taking too long. * * So, I moved it to the main loop through this function. - * However, we need to be aware that this function can get interrupted by the - * IRQ handler at any time. + * However, we need to be aware that this function can get interrupted by the IRQ handler at any + * time. * - * We also need to take care to not have global_memory_buffer overflow as the - * IRQ handler just keeps adding to it. + * We also need to take care to not have global_memory_buffer overflow as the IRQ handler just keeps + * adding to it. */ void LinkConnection::handleCartIO() { u8 writeBuffer[0x1000]; unsigned curBufDepth = writeBufferOffset; - // first copy the current data to a local buffer. Note: the IRQ handler - // could append new data to global_memory_buffer during this call! + // first copy the current data to a local buffer. Note: the IRQ handler could append new data to + // global_memory_buffer during this call! memcpy(writeBuffer, global_memory_buffer, curBufDepth); - // by updating the writeBufferOffset already, we allow the IRQ handler to - // start writing at the new right position immediately. + // by updating the writeBufferOffset already, we allow the IRQ handler to start writing at the + // new right position immediately. writeBufferOffset -= curBufDepth; - // now move any data received during the memcpy to before writeBufferOffset, - // so it will be included in the next batch. Note: keep in mind, here too - // the IRQ handler may be appending new data to global_memory_buffer and - // increase writeBufferOffset. but it's harmless. - memmove(global_memory_buffer, global_memory_buffer + curBufDepth, - writeBufferOffset); + // now move any data received during the memcpy to before writeBufferOffset, so it will be + // included in the next batch. Note: keep in mind, here too the IRQ handler may be appending new + // data to global_memory_buffer and increase writeBufferOffset. but it's harmless. + memmove(global_memory_buffer, global_memory_buffer + curBufDepth, writeBufferOffset); u8 *curWriteBuf = writeBuffer; const u8 *const endWriteBuf = writeBuffer + curBufDepth; while (curWriteBuf < endWriteBuf) { - // make sure not to write beyond the current flash sector's boundaries. - // We'll need an erase_sector() call before we write to the next sector. + // make sure not to write beyond the current flash sector's boundaries. We'll need an + // erase_sector() call before we write to the next sector. const unsigned bytesRemainingInSector = 0x1000 - link_cable_array_index; - const unsigned bytesToWrite = (curBufDepth < bytesRemainingInSector) - ? curBufDepth - : bytesRemainingInSector; + const unsigned bytesToWrite = + (curBufDepth < bytesRemainingInSector) ? curBufDepth : bytesRemainingInSector; copy_ram_to_save(curWriteBuf, - (0x1000 * link_cable_memory_section_index) + link_cable_array_index, - bytesToWrite); + (0x1000 * link_cable_memory_section_index) + link_cable_array_index, bytesToWrite); curWriteBuf += bytesToWrite; curBufDepth -= bytesToWrite; link_cable_array_index += bytesToWrite; if (link_cable_array_index >= 0x1000) { - // we have reached the end of our current sector. Let's erase the - // next one. + // we have reached the end of our current sector. Let's erase the next one. link_cable_array_index = 0; ++link_cable_memory_section_index; erase_sector(0x1000 * link_cable_memory_section_index); @@ -1017,32 +969,27 @@ bool LinkConnection::earlyExit() pauseOnByte = true; pauseOnPacket = false; } - else if (g_debug_options.print_link_packets && !skipPrint && - key_held(KEY_RIGHT)) + else if (g_debug_options.print_link_packets && !skipPrint && key_held(KEY_RIGHT)) { pauseOnPacket = true; pauseOnByte = false; } - else if (g_debug_options.print_link_data && !skipPrint && - key_held(KEY_SELECT)) + else if (g_debug_options.print_link_data && !skipPrint && key_held(KEY_SELECT)) { pauseOnByte = false; } - else if (g_debug_options.print_link_packets && !skipPrint && - key_held(KEY_START)) + else if (g_debug_options.print_link_packets && !skipPrint && key_held(KEY_START)) { pauseOnPacket = false; } - else if ((g_debug_options.print_link_data || - g_debug_options.print_link_packets) && + else if ((g_debug_options.print_link_data || g_debug_options.print_link_packets) && key_held(KEY_UP)) { skipPrint = true; pauseOnPacket = false; pauseOnByte = false; } - else if ((g_debug_options.print_link_data || - g_debug_options.print_link_packets) && + else if ((g_debug_options.print_link_data || g_debug_options.print_link_packets) && key_held(KEY_DOWN)) { skipPrint = false; @@ -1056,8 +1003,7 @@ bool LinkConnection::earlyExit() } } - if (pauseOnPacket && (enterState == LOAD_NEXT_PACKET) && - g_debug_options.print_link_packets) + if (pauseOnPacket && (enterState == LOAD_NEXT_PACKET) && g_debug_options.print_link_packets) { if (key_hit(KEY_A)) { @@ -1071,12 +1017,11 @@ bool LinkConnection::earlyExit() bool LinkConnection::processPacket() { - PTGB_MGBA_INFO("Recieved raw data: Data=[%X, %X, %X, %X, %X, %X, %X, %X, " - "%X, %X, %X, %X, %X, %X, %X, %X]", - dataOutBuffer[0], dataOutBuffer[1], dataOutBuffer[2], dataOutBuffer[3], - dataOutBuffer[4], dataOutBuffer[5], dataOutBuffer[6], dataOutBuffer[7], - dataOutBuffer[8], dataOutBuffer[9], dataOutBuffer[10], - dataOutBuffer[11], dataOutBuffer[12], dataOutBuffer[13], + PTGB_MGBA_INFO( + "Recieved raw data: Data=[%X, %X, %X, %X, %X, %X, %X, %X, %X, %X, %X, %X, %X, %X, %X, %X]", + dataOutBuffer[0], dataOutBuffer[1], dataOutBuffer[2], dataOutBuffer[3], dataOutBuffer[4], + dataOutBuffer[5], dataOutBuffer[6], dataOutBuffer[7], dataOutBuffer[8], dataOutBuffer[9], + dataOutBuffer[10], dataOutBuffer[11], dataOutBuffer[12], dataOutBuffer[13], dataOutBuffer[14], dataOutBuffer[15]); int checksum = 0; @@ -1102,37 +1047,28 @@ bool LinkConnection::processPacket() checksum &= 0x7F; - byte lsbByte = - dataOutBuffer[INP_LSB_INDEX] | dataOutBuffer[INP_LSB_INDEX + 1]; + byte lsbByte = dataOutBuffer[INP_LSB_INDEX] | dataOutBuffer[INP_LSB_INDEX + 1]; for (int i = 0; i < 8; i++) { currIncomingPacket->recievedData[i] = - (dataOutBuffer[INP_DATA_INDEX + i] << 1) | - ((lsbByte >> (7 - i)) & 0b1); + (dataOutBuffer[INP_DATA_INDEX + i] << 1) | ((lsbByte >> (7 - i)) & 0b1); } - PTGB_MGBA_INFO( - "Packet decoded: packet=%u cmd=%d lsb=%X/%X checksumExpected=%X " - "checksumGot=%X recv=%X %X %X %X %X %X %X %X", - currIncomingPacket->packetID, currIncomingPacket->command, - dataOutBuffer[INP_LSB_INDEX], dataOutBuffer[INP_LSB_INDEX + 1], - checksum, dataOutBuffer[INP_CHECKSUM_INDEX], - currIncomingPacket->recievedData[0], - currIncomingPacket->recievedData[1], - currIncomingPacket->recievedData[2], - currIncomingPacket->recievedData[3], - currIncomingPacket->recievedData[4], - currIncomingPacket->recievedData[5], - currIncomingPacket->recievedData[6], - currIncomingPacket->recievedData[7]); + PTGB_MGBA_INFO("Packet decoded: packet=%u cmd=%d lsb=%X/%X checksumExpected=%X checksumGot=%X " + "recv=%X %X %X %X %X %X %X %X", + currIncomingPacket->packetID, currIncomingPacket->command, dataOutBuffer[INP_LSB_INDEX], + dataOutBuffer[INP_LSB_INDEX + 1], checksum, dataOutBuffer[INP_CHECKSUM_INDEX], + currIncomingPacket->recievedData[0], currIncomingPacket->recievedData[1], + currIncomingPacket->recievedData[2], currIncomingPacket->recievedData[3], + currIncomingPacket->recievedData[4], currIncomingPacket->recievedData[5], + currIncomingPacket->recievedData[6], currIncomingPacket->recievedData[7]); if (checksum != dataOutBuffer[INP_CHECKSUM_INDEX]) { - // The checksum has to match in order for it to be valid, if we've made - // it this far down the line. + // The checksum has to match in order for it to be valid, if we've made it this far down the + // line. currIncomingPacket->latestError = CHECKSUM_MISMATCH; - PTGB_MGBA_INFO( - "Packet checksum mismatch: packet=%u cmd=%d expected=%X got=%X", + PTGB_MGBA_INFO("Packet checksum mismatch: packet=%u cmd=%d expected=%X got=%X", currIncomingPacket->packetID, currIncomingPacket->command, checksum, dataOutBuffer[INP_CHECKSUM_INDEX]); return false; @@ -1142,8 +1078,8 @@ bool LinkConnection::processPacket() (dataOutBuffer[INP_DATA_INDEX] & 0x80)) { currIncomingPacket->latestError = ERROR_FLAG; - PTGB_MGBA_INFO("Packet reports GB command failure: packet=%u cmd=%d " - "encodedFirstData=%X decodedFirstData=%X", + PTGB_MGBA_INFO("Packet reports GB command failure: packet=%u cmd=%d encodedFirstData=%X " + "decodedFirstData=%X", currIncomingPacket->packetID, currIncomingPacket->command, dataOutBuffer[INP_DATA_INDEX], currIncomingPacket->recievedData[0]); return false; @@ -1151,52 +1087,36 @@ bool LinkConnection::processPacket() if (currIncomingPacket->command != CMD_ReadDataRequest) { - // These command types will echo the first 8 bytes of the packet back to - // verify they were recieved correctly. Make sure that's the case. This - // will also fail if a secondary packet fails - if (currIncomingPacket->recievedData[0] != - currIncomingPacket->packetID || - currIncomingPacket->recievedData[1] != - currIncomingPacket->command || - currIncomingPacket->recievedData[2] != - currIncomingPacket->argument[0] || - currIncomingPacket->recievedData[3] != - currIncomingPacket->argument[1] || - currIncomingPacket->recievedData[4] != - ((currIncomingPacket->pointer >> 0) & 0xFF) || - currIncomingPacket->recievedData[5] != - ((currIncomingPacket->pointer >> 8) & 0xFF) || + // These command types will echo the first 8 bytes of the packet back to verify they were + // recieved correctly. Make sure that's the case. This will also fail if a secondary packet + // fails + if (currIncomingPacket->recievedData[0] != currIncomingPacket->packetID || + currIncomingPacket->recievedData[1] != currIncomingPacket->command || + currIncomingPacket->recievedData[2] != currIncomingPacket->argument[0] || + currIncomingPacket->recievedData[3] != currIncomingPacket->argument[1] || + currIncomingPacket->recievedData[4] != ((currIncomingPacket->pointer >> 0) & 0xFF) || + currIncomingPacket->recievedData[5] != ((currIncomingPacket->pointer >> 8) & 0xFF) || currIncomingPacket->recievedData[6] != 0xFF || currIncomingPacket->recievedData[7] != 0xFF) { currIncomingPacket->latestError = ECHO_MISMATCH; - PTGB_MGBA_INFO("Packet echo mismatch: packet=%u cmd=%d recv=%X %X " - "%X %X %X %X %X %X", + PTGB_MGBA_INFO("Packet echo mismatch: packet=%u cmd=%d recv=%X %X %X %X %X %X %X %X", currIncomingPacket->packetID, currIncomingPacket->command, - currIncomingPacket->recievedData[0], - currIncomingPacket->recievedData[1], - currIncomingPacket->recievedData[2], - currIncomingPacket->recievedData[3], - currIncomingPacket->recievedData[4], - currIncomingPacket->recievedData[5], - currIncomingPacket->recievedData[6], - currIncomingPacket->recievedData[7]); + currIncomingPacket->recievedData[0], currIncomingPacket->recievedData[1], + currIncomingPacket->recievedData[2], currIncomingPacket->recievedData[3], + currIncomingPacket->recievedData[4], currIncomingPacket->recievedData[5], + currIncomingPacket->recievedData[6], currIncomingPacket->recievedData[7]); return false; } } currIncomingPacket->latestError = PACKET_SUCCESS; - PTGB_MGBA_INFO( - "Packet success: packet=%u cmd=%d recv=%X %X %X %X %X %X %X %X", + PTGB_MGBA_INFO("Packet success: packet=%u cmd=%d recv=%X %X %X %X %X %X %X %X", currIncomingPacket->packetID, currIncomingPacket->command, - currIncomingPacket->recievedData[0], - currIncomingPacket->recievedData[1], - currIncomingPacket->recievedData[2], - currIncomingPacket->recievedData[3], - currIncomingPacket->recievedData[4], - currIncomingPacket->recievedData[5], - currIncomingPacket->recievedData[6], - currIncomingPacket->recievedData[7]); + currIncomingPacket->recievedData[0], currIncomingPacket->recievedData[1], + currIncomingPacket->recievedData[2], currIncomingPacket->recievedData[3], + currIncomingPacket->recievedData[4], currIncomingPacket->recievedData[5], + currIncomingPacket->recievedData[6], currIncomingPacket->recievedData[7]); return true; } @@ -1204,46 +1124,40 @@ void LinkConnection::consumePacket() { /* ---------------- - For this part, the LinkConnection has an array of 4 packets that it will - send. The current packet will be sent and a response will be recieved at the - same time. If the recieved packet is successful, the data will be moved to - the outArray and the packet will be replaced by a packet asking for the next - data section. If the packet was not successful it will stay in the list and - be ran again down the line. If packets have been sent for all the data - sections, a completed packet will be replaced with an empty packet. Once the - array is full of empty packets, the data has all been read and we are - finished. + For this part, the LinkConnection has an array of 4 packets that it will send. + The current packet will be sent and a response will be recieved at the same time. If the + recieved packet is successful, the data will be moved to the outArray and the packet will be + replaced by a packet asking for the next data section. If the packet was not successful it will + stay in the list and be ran again down the line. If packets have been sent for all the data + sections, a completed packet will be replaced with an empty packet. Once the array is full of + empty packets, the data has all been read and we are finished. ---------------- */ if (currIncomingPacket->latestError == PACKET_SUCCESS) { // Packet was successful, Find which packet sent it and mark it. - // If this was data, then save the data and replace it with the next one - // in line + // If this was data, then save the data and replace it with the next one in line currIncomingPacket->latestError = PACKET_READ; if (currIncomingPacket->command == CMD_ReadDataRequest) { for (int i = 0; i < 8; i++) { - if (((currIncomingPacket->pointer - linkPacketDataStart) + i) < - linkPacketDataSize) + if (((currIncomingPacket->pointer - linkPacketDataStart) + i) < linkPacketDataSize) { - outDataArrayPtr[(currIncomingPacket->pointer - - linkPacketDataStart) + - i] = currIncomingPacket->recievedData[i]; + outDataArrayPtr[(currIncomingPacket->pointer - linkPacketDataStart) + i] = + currIncomingPacket->recievedData[i]; } } // Do we have more data to read? if ((linkPacketDataAddr - linkPacketDataStart) < linkPacketDataSize) { - *currIncomingPacket = LinkPacket( - CMD_ReadDataRequest, 0x00, 0x00, linkPacketDataAddr); + *currIncomingPacket = + LinkPacket(CMD_ReadDataRequest, 0x00, 0x00, linkPacketDataAddr); linkPacketDataAddr += 8; } else { - // Mark the packet as out of use, we've gotten all the data we - // need. + // Mark the packet as out of use, we've gotten all the data we need. currIncomingPacket->inUse = false; } } @@ -1264,8 +1178,7 @@ bool LinkConnection::prepareNextPacket() { linkPacketArrIndex = (linkPacketArrIndex + 1) & LINK_PACKET_INDEX_MASK; - LinkPacket *candidate = - &linkPacketArr[linkPacketArrIndex % LINK_PACKET_ARRAY_SIZE]; + LinkPacket *candidate = &linkPacketArr[linkPacketArrIndex % LINK_PACKET_ARRAY_SIZE]; if (candidate->inUse && candidate->latestError != PACKET_READ) { @@ -1282,8 +1195,7 @@ bool LinkConnection::allPacketsProcessed() { for (int i = 0; i < LINK_PACKET_ARRAY_SIZE; i++) { - if (linkPacketArr[i].inUse && - linkPacketArr[i].latestError != PACKET_READ) + if (linkPacketArr[i].inUse && linkPacketArr[i].latestError != PACKET_READ) { return false; } @@ -1306,8 +1218,7 @@ void LinkConnection::resetLinkPackets() // Set the current outgoing packet to be the first in order. currOutgoingPacket = &linkPacketArr[0]; - // And set the incoming packet to nullptr since we don't know what that is - // yet. + // And set the incoming packet to nullptr since we don't know what that is yet. currIncomingPacket = nullptr; for (int i = 0; i < DATA_OUT_BUFFER_SIZE; i++) @@ -1363,8 +1274,8 @@ bool LinkConnection::LinkCommand_ReloadCurrentBox(bool waitForCompletion) resetLinkPackets(); - linkPacketArr[0] = LinkPacket( - CMD_ReloadCurrentBox, 0x00, 0x00, determinePacketArrivalAddress(gen)); + linkPacketArr[0] = + LinkPacket(CMD_ReloadCurrentBox, 0x00, 0x00, determinePacketArrivalAddress(gen)); globalLinkCable.startConnection(PACKET_EXCHANGE); if (waitForCompletion) @@ -1374,8 +1285,8 @@ bool LinkConnection::LinkCommand_ReloadCurrentBox(bool waitForCompletion) return true; }; -bool LinkConnection::LinkCommand_TransferPokemon(int boxNumber, - byte removalArray[], int removalArrayLength, bool waitForCompletion) +bool LinkConnection::LinkCommand_TransferPokemon( + int boxNumber, byte removalArray[], int removalArrayLength, bool waitForCompletion) { if (g_debug_options.ignore_link_cable) { @@ -1419,9 +1330,9 @@ bool LinkConnection::LinkCommand_TransferPokemon(int boxNumber, resetLinkPackets(); - linkPacketArr[0] = LinkPacket(CMD_TransferPokemon, - removalArrayLength + SECONDARY_PAYLOAD_HEADER_SIZE, boxNumber, - determinePacketArrivalAddress(gen)); + linkPacketArr[0] = + LinkPacket(CMD_TransferPokemon, removalArrayLength + SECONDARY_PAYLOAD_HEADER_SIZE, + boxNumber, determinePacketArrivalAddress(gen)); linkPacketArr[0].loadSecondaryPayload(removalArray, removalArrayLength); // REG_TM3D = -0x4000 / 60; @@ -1449,8 +1360,7 @@ bool LinkConnection::LinkCommand_SoftReset(bool waitForCompletion) resetLinkPackets(); - linkPacketArr[0] = LinkPacket( - CMD_SoftReset, 0x00, 0x00, determinePacketArrivalAddress(gen)); + linkPacketArr[0] = LinkPacket(CMD_SoftReset, 0x00, 0x00, determinePacketArrivalAddress(gen)); globalLinkCable.startConnection(PACKET_EXCHANGE); if (waitForCompletion) @@ -1483,13 +1393,13 @@ bool LinkConnection::LinkCommand_ModifySRAMAccess( if (enableSRAM) { - linkPacketArr[0] = LinkPacket(CMD_ModifySRAMAccess, 0x0A, SRAMbank, - determinePacketArrivalAddress(gen)); + linkPacketArr[0] = + LinkPacket(CMD_ModifySRAMAccess, 0x0A, SRAMbank, determinePacketArrivalAddress(gen)); } else { - linkPacketArr[0] = LinkPacket(CMD_ModifySRAMAccess, 0x00, 0x00, - determinePacketArrivalAddress(gen)); + linkPacketArr[0] = + LinkPacket(CMD_ModifySRAMAccess, 0x00, 0x00, determinePacketArrivalAddress(gen)); } globalLinkCable.startConnection(PACKET_EXCHANGE); @@ -1517,8 +1427,7 @@ bool LinkConnection::LinkCommand_RunSecondaryPayload( resetLinkPackets(); linkPacketArr[0] = LinkPacket(CMD_RunSecondaryPayload, - payloadLength + SECONDARY_PAYLOAD_HEADER_SIZE, 0x00, - determinePacketArrivalAddress(gen)); + payloadLength + SECONDARY_PAYLOAD_HEADER_SIZE, 0x00, determinePacketArrivalAddress(gen)); linkPacketArr[0].loadSecondaryPayload(payload, payloadLength); globalLinkCable.startConnection(PACKET_EXCHANGE); @@ -1543,8 +1452,8 @@ bool LinkConnection::LinkCommand_ReadMemorySection( if (dataPointer > 0xFFFF) { - waitForCompletion = true; // We have to wait for completion with the - // SRAM bank loading, so we can close it + waitForCompletion = + true; // We have to wait for completion with the SRAM bank loading, so we can close it LinkCommand_ModifySRAMAccess(true, dataPointer >> 16); } @@ -1561,8 +1470,7 @@ bool LinkConnection::LinkCommand_ReadMemorySection( { if ((i * 8) < linkPacketDataSize) { - linkPacketArr[i] = - LinkPacket(CMD_ReadDataRequest, 0x00, 0x00, linkPacketDataAddr); + linkPacketArr[i] = LinkPacket(CMD_ReadDataRequest, 0x00, 0x00, linkPacketDataAddr); linkPacketDataAddr += 8; } else diff --git a/source/linker_optimizations.cpp b/source/linker_optimizations.cpp index 4c90fbe..9215d28 100644 --- a/source/linker_optimizations.cpp +++ b/source/linker_optimizations.cpp @@ -6,21 +6,18 @@ #include // Okay, let's go over the basics of this file for a moment. -// By default, a lot of code is getting pulled in by the linker from static -// libraries such as newlibc and libtonc. The problem is that everytime a single -// symbol/function is needed from one of the .o files inside one of these static -// libs, the entire .o file is getting pulled in, alongside all of ITS -// dependencies. This cascades pretty quickly. So this pulls in a lot of -// unnecessary code, but also (global) variables. To solve that, we can try to -// override these functions by defining a custom version of them here. But to -// avoid still pulling in the .o file, we have to define every symbol that could -// be referenced somehow in either our code or the static libraries themselves. -// Worst case, this means we have to redefine every single function that is -// defined in that .o file. But doing so, means we can modify the code slightly -// to avoid pulling in a lot of bloat. we don't need. +// By default, a lot of code is getting pulled in by the linker from static libraries such as +// newlibc and libtonc. The problem is that everytime a single symbol/function is needed from one of +// the .o files inside one of these static libs, the entire .o file is getting pulled in, alongside +// all of ITS dependencies. This cascades pretty quickly. So this pulls in a lot of unnecessary +// code, but also (global) variables. To solve that, we can try to override these functions by +// defining a custom version of them here. But to avoid still pulling in the .o file, we have to +// define every symbol that could be referenced somehow in either our code or the static libraries +// themselves. Worst case, this means we have to redefine every single function that is defined in +// that .o file. But doing so, means we can modify the code slightly to avoid pulling in a lot of +// bloat. we don't need. -// HACK: Avoid pulling in a large handles buffer, which we don't need. Only -// define the minimum. +// HACK: Avoid pulling in a large handles buffer, which we don't need. Only define the minimum. #define MAX_HANDLES 3 @@ -28,23 +25,20 @@ static __handle __stdin_handle = {0, 1, NULL}; static __handle __stdout_handle = {1, 1, NULL}; static __handle __stderr_handle = {2, 1, NULL}; -static __handle *handles[MAX_HANDLES] = { - &__stdin_handle, &__stdout_handle, &__stderr_handle}; +static __handle *handles[MAX_HANDLES] = {&__stdin_handle, &__stdout_handle, &__stderr_handle}; extern "C" { // HACK: - // Unfortunately, libtonc references siscanf, which in turn causes a "lot" - // of binary bloat from newlibc (in regards to locale support) to be pulled - // in by the linker. However, if you look at what it is actually used for - // (in libtonc's tte_iohook.c), is just to extract 1 or 2 integers from a - // string by specifying a custom -extremely simplified- version, we can - // avoid pulling in the version from libc (alongside all the symbols IT - // references) Obviously it doesn't support everything it should. Just - // enough to support libtonc's current iteration. + // Unfortunately, libtonc references siscanf, which in turn causes a "lot" of binary bloat from + // newlibc (in regards to locale support) to be pulled in by the linker. However, if you look at + // what it is actually used for (in libtonc's tte_iohook.c), is just to extract 1 or 2 integers + // from a string by specifying a custom -extremely simplified- version, we can avoid pulling in + // the version from libc (alongside all the symbols IT references) Obviously it doesn't support + // everything it should. Just enough to support libtonc's current iteration. // - // Anyway, doing this optimizes away a lot of scanf related functions from - // newlib and locale support among which a 13KB "categories" symbol. + // Anyway, doing this optimizes away a lot of scanf related functions from newlib and locale + // support among which a 13KB "categories" symbol. int siscanf(const char *str, const char *format, ...) { bool expectingFormatSpecifier = false; @@ -73,8 +67,8 @@ extern "C" (*resultVal) += (*str) - '0'; ++str; } - // go back to the last character of the int, because we'll - // forward by one again at the end of the outer loop + // go back to the last character of the int, because we'll forward by one again + // at the end of the outer loop --str; ++ret; } @@ -94,9 +88,9 @@ extern "C" } // HACK: stub the libsysbase_libsysbase_a-handle_manager.o functions - // this, alongside the -Wl,--wrap linker options ensures that this object - // file and its 4KB IWRAM "handles" buffer is not getting pulled in by the - // linker. We don't need it and we could use the 4KB of extra IWRAM! + // this, alongside the -Wl,--wrap linker options ensures that this object file + // and its 4KB IWRAM "handles" buffer is not getting pulled in by the linker. + // We don't need it and we could use the 4KB of extra IWRAM! __handle *__wrap___get_handle(int fd) { if (fd < 0 || fd >= MAX_HANDLES) @@ -107,9 +101,9 @@ extern "C" int __wrap__close_r(struct _reent *ptr, int fd) { return 0; } -// HACK: The functions below were defined here to avoid pulling in the verdana9 -// font (4 KB) into the rom, which we're not using. The original function in -// libtonc would use verdana9 as a default if the specified font was NULL. +// HACK: The functions below were defined here to avoid pulling in the verdana9 font (4 KB) into the +// rom, which we're not using. The original function in libtonc would use verdana9 as a default if +// the specified font was NULL. #include #include #include @@ -125,8 +119,8 @@ extern "C" \param font Font to initialize with. \param proc Glyph renderer */ - void tte_init_chr4c(int bgnr, u16 bgcnt, u16 se0, u32 cattrs, u32 clrs, - const TFont *font, fnDrawg proc) + void tte_init_chr4c( + int bgnr, u16 bgcnt, u16 se0, u32 cattrs, u32 clrs, const TFont *font, fnDrawg proc) { if (proc == NULL) proc = chr4c_drawg_default; @@ -136,8 +130,7 @@ extern "C" TTC *tc = tte_get_context(); TSurface *srf = &tc->dst; - srf_init(srf, SRF_CHR4C, - &tile_mem[BFN_GET(bgcnt, BG_CBB)][se0 & SE_ID_MASK], SCREEN_WIDTH, + srf_init(srf, SRF_CHR4C, &tile_mem[BFN_GET(bgcnt, BG_CBB)][se0 & SE_ID_MASK], SCREEN_WIDTH, SCREEN_HEIGHT, 4, pal_bg_mem); schr4c_prep_map(srf, se_mem[BFN_GET(bgcnt, BG_SBB)], se0); @@ -170,10 +163,9 @@ extern "C" schr4c_rect(&tc->dst, left, top, right, bottom, tc->cattr[TTE_PAPER]); } - // HACK: We need to replace the entirety of tte_main.c in libtonc to avoid - // pulling in sys8font (because it's used as a default in tte_init_base() if - // the specified font is NULL) So here's a modified version of tte_main.c - // (only tte_init_base() is really changed though): + // HACK: We need to replace the entirety of tte_main.c in libtonc to avoid pulling in sys8font + // (because it's used as a default in tte_init_base() if the specified font is NULL) So here's a + // modified version of tte_main.c (only tte_init_base() is really changed though): //////////////////////// tte_main.c //////////////////////// // -------------------------------------------------------------------- @@ -204,10 +196,7 @@ extern "C" // -------------------------------------------------------------------- //! Set the master context pointer. - void tte_set_context(TTC *tc) - { - gp_tte_context = tc ? tc : &__tte_main_context; - } + void tte_set_context(TTC *tc) { gp_tte_context = tc ? tc : &__tte_main_context; } //! Set color attribute of \a type to \a cattr. void tte_set_color_attr(eint type, u16 cattr) @@ -265,8 +254,7 @@ extern "C" tc->eraseProc = eraseProc; // Default is SBB 0 - const TSurface srf = { - (u8 *)se_mem, 32 * 2, 32, 32, 8, SRF_BMP16, 256, pal_bg_mem}; + const TSurface srf = {(u8 *)se_mem, 32 * 2, 32, 32, 8, SRF_BMP16, 256, pal_bg_mem}; tc->dst = srf; tc->cattr[TTE_INK] = 0xF1; @@ -428,8 +416,7 @@ extern "C" Examples:
- #{X:32} Move to \e x = 32; - #{ci:0x7FFF} Set ink color to white. - - #{w:120;es;P} Wait 120 frames, clear screen, return to top of - screen. + - #{w:120;es;P} Wait 120 frames, clear screen, return to top of screen. \param str Start of command. Assumes the initial "\{" is lobbed off already. \return pointer to after the parsed command. @@ -459,12 +446,10 @@ extern "C" { // --- Absolute Positions --- case 'X': - tc->cursorX = curr[1] == ':' ? strtol(curr + 2, &next, 0) - : tc->marginLeft; + tc->cursorX = curr[1] == ':' ? strtol(curr + 2, &next, 0) : tc->marginLeft; break; case 'Y': - tc->cursorY = - curr[1] == ':' ? strtol(curr + 2, &next, 0) : tc->marginTop; + tc->cursorY = curr[1] == ':' ? strtol(curr + 2, &next, 0) : tc->marginTop; break; case 'P': { @@ -540,12 +525,12 @@ extern "C" tte_erase_line(); break; case 'f': // line up to cursorX - tte_erase_rect(tc->cursorX, tc->cursorY, tc->marginRight, - tc->cursorY + tc->font->charH); + tte_erase_rect( + tc->cursorX, tc->cursorY, tc->marginRight, tc->cursorY + tc->font->charH); break; case 'b': // line from cursorX - tte_erase_rect(tc->marginLeft, tc->cursorY, tc->cursorX, - tc->cursorY + tc->font->charH); + tte_erase_rect( + tc->marginLeft, tc->cursorY, tc->cursorX, tc->cursorY + tc->font->charH); break; case 'r': // rectangle { @@ -790,8 +775,7 @@ extern "C" TTC *tc = tte_get_context(); if (tc->eraseProc) - tc->eraseProc(tc->marginLeft, tc->marginTop, tc->marginRight, - tc->marginBottom); + tc->eraseProc(tc->marginLeft, tc->marginTop, tc->marginRight, tc->marginBottom); } //! Erase the whole line (within the margins). @@ -804,8 +788,7 @@ extern "C" int height = tc->font->charH; if (tc->eraseProc) - tc->eraseProc(tc->marginLeft, tc->cursorY, tc->marginRight, - tc->cursorY + height); + tc->eraseProc(tc->marginLeft, tc->cursorY, tc->marginRight, tc->cursorY + height); } //! Get the size taken up by a string. diff --git a/source/main.cpp b/source/main.cpp index 962016b..b00b04c 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -73,8 +73,8 @@ void load_graphics() void initialization_script(void) { // Initializations - REG_DISPCNT = DCNT_BLANK | DCNT_MODE0 | DCNT_BG0 | DCNT_BG1 | DCNT_BG2 | - DCNT_BG3 | DCNT_OBJ | DCNT_OBJ_1D; + REG_DISPCNT = DCNT_BLANK | DCNT_MODE0 | DCNT_BG0 | DCNT_BG1 | DCNT_BG2 | DCNT_BG3 | DCNT_OBJ | + DCNT_OBJ_1D; // Disable for save data read/write REG_IME = 0; @@ -112,8 +112,8 @@ void initialization_script(void) PTGB_MGBA_INFO("Hello from PTGB!"); }; -// attribute noinline is used to make sure it doesn't get inlined and -// permanently use IWRAM for the decompression_buffer +// attribute noinline is used to make sure it doesn't get inlined and permanently use IWRAM for the +// decompression_buffer void __attribute__((noinline)) game_load_error(void) { u8 general_text_buffer[2048]; @@ -129,8 +129,7 @@ void __attribute__((noinline)) game_load_error(void) BG_TEXTBOX = (BG_TEXTBOX & ~BG_PRIO_MASK) | BG_PRIO(1); text_reader.readFile(GENERAL_cart_load_error, lineBuffer); - ptgb_write_textbox( - lineBuffer, true, false, GENERAL_INDEX, GENERAL_cart_load_error, false); + ptgb_write_textbox(lineBuffer, true, false, GENERAL_INDEX, GENERAL_cart_load_error, false); // key_poll(); do @@ -143,15 +142,13 @@ void __attribute__((noinline)) game_load_error(void) if (key_hit(KEY_SELECT)) { - // We also want to give the option in this screen to upload the - // multiboot rom to another GBA. This can be useful when the user wants - // to work with a flashcart in single rom mode. The EZ Flash Omega (DE) - // for instance, triggers a reset of the gba if you insert it while the - // GBA is turned on. So the only way to work with it, is to boot Poke - // Transporter GB over multiboot and have the flashcart already - // inserted. It would be a shame not to support this flashcart, because - // it's awesome for pokémon fans. After all: it supports ds transfer and - // should support connecting with the gamecube games. + // We also want to give the option in this screen to upload the multiboot rom to another + // GBA. This can be useful when the user wants to work with a flashcart in single rom mode. + // The EZ Flash Omega (DE) for instance, triggers a reset of the gba if you insert it while + // the GBA is turned on. So the only way to work with it, is to boot Poke Transporter GB + // over multiboot and have the flashcart already inserted. It would be a shame not to + // support this flashcart, because it's awesome for pokémon fans. After all: it supports ds + // transfer and should support connecting with the gamecube games. multiboot_upload_screen(); return; } @@ -164,8 +161,8 @@ void __attribute__((noinline)) game_load_error(void) } }; -// attribute noinline is used to make sure it doesn't get inlined and -// permanently use IWRAM for the decompression_buffer +// attribute noinline is used to make sure it doesn't get inlined and permanently use IWRAM for the +// decompression_buffer void __attribute__((noinline)) lang_mismatch_error(void) { u8 general_text_buffer[2048]; @@ -181,8 +178,8 @@ void __attribute__((noinline)) lang_mismatch_error(void) BG_TEXTBOX = (BG_TEXTBOX & ~BG_PRIO_MASK) | BG_PRIO(1); text_reader.readFile(GENERAL_lang_mismatch_warning, lineBuffer); - ptgb_write_textbox(lineBuffer, true, false, GENERAL_INDEX, - GENERAL_lang_mismatch_warning, false); + ptgb_write_textbox( + lineBuffer, true, false, GENERAL_INDEX, GENERAL_lang_mismatch_warning, false); // key_poll(); do @@ -194,8 +191,7 @@ void __attribute__((noinline)) lang_mismatch_error(void) erase_textbox_tiles(); }; -// avoid inlining to avoid permanently storing the credits_decompression_buffer -// in IWRAM +// avoid inlining to avoid permanently storing the credits_decompression_buffer in IWRAM int __attribute__((noinline)) credits() { u8 credits_decompression_buffer[2048]; @@ -208,8 +204,7 @@ int __attribute__((noinline)) credits() FileContainerReader creditsReader(chunkList, numChunks, chunkSize); u32 curr_credits_num = 0; - creditsReader.init( - credits_decompression_buffer, sizeof(credits_decompression_buffer)); + creditsReader.init(credits_decompression_buffer, sizeof(credits_decompression_buffer)); bool update = true; while (true) @@ -217,8 +212,7 @@ int __attribute__((noinline)) credits() if (update) { creditsReader.readFile(curr_credits_num, lineBuffer); - ptgb_write_textbox(lineBuffer, true, false, CREDITS_INDEX, - curr_credits_num, false); + ptgb_write_textbox(lineBuffer, true, false, CREDITS_INDEX, curr_credits_num, false); update = false; } @@ -234,8 +228,7 @@ int __attribute__((noinline)) credits() curr_credits_num--; update = true; } - if (key_hit(KEY_RIGHT) && - curr_credits_num < (creditsReader.getNumberOfFiles() - 1)) + if (key_hit(KEY_RIGHT) && curr_credits_num < (creditsReader.getNumberOfFiles() - 1)) { curr_credits_num++; update = true; @@ -245,8 +238,7 @@ int __attribute__((noinline)) credits() } }; -// avoid inlining to avoid permanently storing the tutorial_decompression_buffer -// in IWRAM +// avoid inlining to avoid permanently storing the tutorial_decompression_buffer in IWRAM int __attribute__((noinline)) tutorial() { @@ -260,8 +252,7 @@ int __attribute__((noinline)) tutorial() FileContainerReader tutorialReader(chunkList, numChunks, chunkSize); u32 curr_tutorial_num = 0; - tutorialReader.init( - tutorial_decompression_buffer, sizeof(tutorial_decompression_buffer)); + tutorialReader.init(tutorial_decompression_buffer, sizeof(tutorial_decompression_buffer)); bool update = true; while (true) @@ -269,8 +260,7 @@ int __attribute__((noinline)) tutorial() if (update) { tutorialReader.readFile(curr_tutorial_num, lineBuffer); - ptgb_write_textbox(lineBuffer, true, false, TUTORIAL_INDEX, - curr_tutorial_num, false); + ptgb_write_textbox(lineBuffer, true, false, TUTORIAL_INDEX, curr_tutorial_num, false); update = false; } @@ -286,8 +276,7 @@ int __attribute__((noinline)) tutorial() curr_tutorial_num--; update = true; } - if (key_hit(KEY_RIGHT) && - curr_tutorial_num < (tutorialReader.getNumberOfFiles() - 1)) + if (key_hit(KEY_RIGHT) && curr_tutorial_num < (tutorialReader.getNumberOfFiles() - 1)) { curr_tutorial_num++; update = true; @@ -297,18 +286,15 @@ int __attribute__((noinline)) tutorial() } }; -// attribute noinline is used to avoid permanently storing the -// general_text_table_buffer in IWRAM +// attribute noinline is used to avoid permanently storing the general_text_table_buffer in IWRAM int __attribute__((noinline)) main_menu_loop() { uint8_t general_text_table_buffer[2048]; u8 lineBuffer[1024]; #define NUM_MENU_OPTIONS 4 const uint8_t menu_options[NUM_MENU_OPTIONS] = {GENERAL_option_transfer, - GENERAL_option_dreamdex, GENERAL_option_credits, - GENERAL_option_tutorial}; - int return_values[NUM_MENU_OPTIONS] = { - BTN_TRANSFER, BTN_POKEDEX, BTN_CREDITS, BTN_TUTORIAL}; + GENERAL_option_dreamdex, GENERAL_option_credits, GENERAL_option_tutorial}; + int return_values[NUM_MENU_OPTIONS] = {BTN_TRANSFER, BTN_POKEDEX, BTN_CREDITS, BTN_TUTORIAL}; const u8 **chunkList; u32 numChunks; u32 chunkSize; @@ -318,8 +304,7 @@ int __attribute__((noinline)) main_menu_loop() bool update = true; u16 test = 0; - text_reader.init( - general_text_table_buffer, sizeof(general_text_table_buffer)); + text_reader.init(general_text_table_buffer, sizeof(general_text_table_buffer)); while (true) { @@ -357,8 +342,7 @@ int __attribute__((noinline)) main_menu_loop() } else { - curr_selection = ((curr_selection + (NUM_MENU_OPTIONS - 1)) % - NUM_MENU_OPTIONS); + curr_selection = ((curr_selection + (NUM_MENU_OPTIONS - 1)) % NUM_MENU_OPTIONS); } } else if (key_hit(KEY_A)) @@ -394,12 +378,11 @@ static void show_gears_of_progress() } } -// split off from the main function in order to keep the scope of the variables -// limited to the execution of this function otherwise they stick around for the -// entire runtime of the program the attribute noinline is used to prevent the -// compiler from inlining this function back into the main function this -// decision was based on the output of build/main.su after adding the -// -fstack-usage compile flag +// split off from the main function in order to keep the scope of the variables limited to the +// execution of this function otherwise they stick around for the entire runtime of the program the +// attribute noinline is used to prevent the compiler from inlining this function back into the main +// function this decision was based on the output of build/main.su after adding the -fstack-usage +// compile flag static void __attribute__((noinline)) show_intro() { u8 general_text_table_buffer[2048]; @@ -412,13 +395,11 @@ static void __attribute__((noinline)) show_intro() FileContainerReader general_text_reader(chunkList, numChunks, chunkSize); bool start_pressed = false; - general_text_reader.init( - general_text_table_buffer, sizeof(general_text_table_buffer)); + general_text_reader.init(general_text_table_buffer, sizeof(general_text_table_buffer)); tte_set_ink(INK_ROM_COLOR); general_text_reader.readFile(GENERAL_intro_legal, lineBuffer); - ptgb_write_textbox( - lineBuffer, true, true, GENERAL_INDEX, GENERAL_intro_legal, true); + ptgb_write_textbox(lineBuffer, true, true, GENERAL_INDEX, GENERAL_intro_legal, true); show_gears_of_progress(); @@ -506,8 +487,8 @@ int main(void) load_flex_background(FBG_Fennel, 2); text_loop(BTN_TRANSFER); initialize_save_data(); - // TODO: We should be able to test for a Bootleg rom in here- if the - // save data isn't written, then it is bootleg. + // TODO: We should be able to test for a Bootleg rom in here- if the save data isn't + // written, then it is bootleg. } obj_unhide_multi(ptgb_logo_l, 1, 2); diff --git a/source/multiboot_upload.cpp b/source/multiboot_upload.cpp index 6d87ee6..a2269b2 100644 --- a/source/multiboot_upload.cpp +++ b/source/multiboot_upload.cpp @@ -20,14 +20,12 @@ void multiboot_upload_screen() FileContainerReader general_text_reader(chunkList, numChunks, chunkSize); LinkCableMultiboot linkCableMultiboot; - general_text_reader.init( - decompression_buffer, sizeof(decompression_buffer)); + general_text_reader.init(decompression_buffer, sizeof(decompression_buffer)); // multiboot_show_textbox(); - general_text_reader.readFile( - GENERAL_send_multiboot_instructions, lineBuffer); - ptgb_write_textbox(lineBuffer, true, false, GENERAL_INDEX, - GENERAL_send_multiboot_instructions, false); + general_text_reader.readFile(GENERAL_send_multiboot_instructions, lineBuffer); + ptgb_write_textbox( + lineBuffer, true, false, GENERAL_INDEX, GENERAL_send_multiboot_instructions, false); // wait for key press do @@ -44,8 +42,7 @@ void multiboot_upload_screen() // start upload // multiboot_show_textbox(); general_text_reader.readFile(GENERAL_send_multiboot_wait, lineBuffer); - ptgb_write_textbox(lineBuffer, true, false, GENERAL_INDEX, - GENERAL_send_multiboot_wait, false); + ptgb_write_textbox(lineBuffer, true, false, GENERAL_INDEX, GENERAL_send_multiboot_wait, false); VBlankIntrWait(); const u32 romSize = 256 * 1024; // EWRAM = 256 KB @@ -64,8 +61,7 @@ void multiboot_upload_screen() : GENERAL_send_multiboot_failure; general_text_reader.readFile(fileIndex, lineBuffer); - ptgb_write_textbox( - lineBuffer, true, false, GENERAL_INDEX, fileIndex, false); + ptgb_write_textbox(lineBuffer, true, false, GENERAL_INDEX, fileIndex, false); // wait for keypress again. do diff --git a/source/mystery_gift_injector.cpp b/source/mystery_gift_injector.cpp index 5543407..8a18bf3 100644 --- a/source/mystery_gift_injector.cpp +++ b/source/mystery_gift_injector.cpp @@ -28,8 +28,7 @@ extern "C" // These defines are there because rom_data defines values that // occupy more bytes/bits than needed. // We use these to create a table with a packed key below: patchFileTable -// also refer to the comment on PACK_PATCH_KEY() for more details on how the key -// is packed. +// also refer to the comment on PACK_PATCH_KEY() for more details on how the key is packed. #define MAP_RUBY 0 #define MAP_SAPPHIRE 1 #define MAP_FIRERED 2 @@ -43,15 +42,14 @@ extern "C" #define MAP_ITALIAN 4 #define MAP_SPANISH 5 -// So, we need to associate the rom_data values with a specific patch file to -// convert the game-based payload to our specific language variant. But we only -// have indexes and their enum namings. So we need to map them. The thing is: -// using the existing RUBY_ID and LANG_ENG defines, would make this table much -// larger than it needs to be. There are 5 game variants (3 bits), and 6 -// languages (3 bits) and the highest version of those roms is 1.2 (2 bits) So -// we can pack this data into a single byte. -#define PACK_PATCH_KEY(game, lang, version) \ - (((game) << 5) | ((lang) << 2) | (version)) +// So, we need to associate the rom_data values with a specific patch file to convert the +// game-based payload to our specific language variant. +// But we only have indexes and their enum namings. +// So we need to map them. +// The thing is: using the existing RUBY_ID and LANG_ENG defines, would make this table much larger +// than it needs to be. There are 5 game variants (3 bits), and 6 languages (3 bits) and the highest +// version of those roms is 1.2 (2 bits) So we can pack this data into a single byte. +#define PACK_PATCH_KEY(game, lang, version) (((game) << 5) | ((lang) << 2) | (version)) #define SKIP_PATCH_INDEX 0xFF @@ -62,14 +60,13 @@ typedef struct PatchFileTableEntry u8 specificPatchIndex; } PatchFileTableEntry; -// We only need to have a single map of the patch files, because the order and -// size of the section30 and script patches are exactly the same. +// We only need to have a single map of the patch files, because the order and size of the section30 +// and script patches are exactly the same. static constexpr PatchFileTableEntry patchFileTable[] = { // english: game-specific transformation happens outside of this table // no language specific transformation required // only version-specific one - {PACK_PATCH_KEY(MAP_RUBY, MAP_ENGLISH, VERS_1_0), SKIP_PATCH_INDEX, - SKIP_PATCH_INDEX}, + {PACK_PATCH_KEY(MAP_RUBY, MAP_ENGLISH, VERS_1_0), SKIP_PATCH_INDEX, SKIP_PATCH_INDEX}, {PACK_PATCH_KEY(MAP_RUBY, MAP_ENGLISH, VERS_1_1), SKIP_PATCH_INDEX, (u8)Script_patchesFiles::SCRIPT_RUBY_ENGLISH_1_1}, {PACK_PATCH_KEY(MAP_RUBY, MAP_ENGLISH, VERS_1_2), SKIP_PATCH_INDEX, @@ -80,21 +77,18 @@ static constexpr PatchFileTableEntry patchFileTable[] = { (u8)Script_patchesFiles::SCRIPT_SAPPHIRE_ENGLISH_1_1}, {PACK_PATCH_KEY(MAP_SAPPHIRE, MAP_ENGLISH, VERS_1_2), SKIP_PATCH_INDEX, (u8)Script_patchesFiles::SCRIPT_SAPPHIRE_ENGLISH_1_2}, - {PACK_PATCH_KEY(MAP_EMERALD, MAP_ENGLISH, VERS_1_0), SKIP_PATCH_INDEX, - SKIP_PATCH_INDEX}, - {PACK_PATCH_KEY(MAP_FIRERED, MAP_ENGLISH, VERS_1_0), SKIP_PATCH_INDEX, - SKIP_PATCH_INDEX}, + {PACK_PATCH_KEY(MAP_EMERALD, MAP_ENGLISH, VERS_1_0), SKIP_PATCH_INDEX, SKIP_PATCH_INDEX}, + {PACK_PATCH_KEY(MAP_FIRERED, MAP_ENGLISH, VERS_1_0), SKIP_PATCH_INDEX, SKIP_PATCH_INDEX}, {PACK_PATCH_KEY(MAP_FIRERED, MAP_ENGLISH, VERS_1_1), SKIP_PATCH_INDEX, (u8)Script_patchesFiles::SCRIPT_FIRERED_ENGLISH_1_1}, {PACK_PATCH_KEY(MAP_LEAFGREEN, MAP_ENGLISH, VERS_1_0), SKIP_PATCH_INDEX, (u8)Script_patchesFiles::SCRIPT_LEAFGREEN_ENGLISH_1_0}, {PACK_PATCH_KEY(MAP_LEAFGREEN, MAP_ENGLISH, VERS_1_1), SKIP_PATCH_INDEX, (u8)Script_patchesFiles::SCRIPT_LEAFGREEN_ENGLISH_1_1}, - // Other languages: game-specific transformation (e.g. english ruby -> - // english fire red) happens outside of this table language-specific - // transformation transforms the english game specific payload to the french - // one version-specific transformation transforms ruby->sapphire or 1.0->1.1 - // or both. French: + // Other languages: game-specific transformation (e.g. english ruby -> english fire red) happens + // outside of this table language-specific transformation transforms the english game specific + // payload to the french one version-specific transformation transforms ruby->sapphire + // or 1.0->1.1 or both. French: {PACK_PATCH_KEY(MAP_RUBY, MAP_FRENCH, VERS_1_0), (u8)Script_patchesFiles::SCRIPT_RUBY_FRENCH_1_0, SKIP_PATCH_INDEX}, {PACK_PATCH_KEY(MAP_RUBY, MAP_FRENCH, VERS_1_1), @@ -208,92 +202,73 @@ static const u8 **RSEFRLG_spanish_chunk_list = RSEFRLG_spanishEU_chunk_list; #endif // This will need to be modified for the JP releases -static constexpr u8 em_wonder_card[0x14E] = {0x08, 0x6E, 0x00, 0x00, 0xBA, 0xB4, - 0xBE, 0xB9, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, 0xCA, 0xCC, - 0xC9, 0xC0, 0xBF, 0xCD, 0xCD, 0xC9, 0xCC, 0x00, 0xC0, 0xBF, 0xC8, 0xC8, - 0xBF, 0xC6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0xCE, 0xE6, 0xD5, 0xE2, 0xE7, 0xDA, 0xD9, 0xE6, 0x00, 0xBD, - 0xD9, 0xE6, 0xE8, 0xDD, 0xDA, 0xDD, 0xD7, 0xD5, 0xE8, 0xD9, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xD0, 0xDD, 0xE7, 0xDD, 0xE8, 0x00, 0xE8, 0xDC, - 0xD9, 0x00, 0xDC, 0xE3, 0xE9, 0xE7, 0xD9, 0x00, 0xE7, 0xE3, 0xE9, 0xE8, - 0xDC, 0xD9, 0xD5, 0xE7, 0xE8, 0x00, 0xE3, 0xDA, 0x00, 0xE8, 0xDC, 0xD9, - 0x00, 0xCA, 0xC9, 0xC5, 0x1B, 0xC7, 0xC9, 0xC8, 0xBD, 0xBF, 0xC8, 0xCE, - 0xBF, 0xCC, 0x00, 0xDD, 0xE2, 0x00, 0xCD, 0xE3, 0xE3, 0xE8, 0xE3, 0xE4, - 0xE3, 0xE0, 0xDD, 0xE7, 0x00, 0xBD, 0xDD, 0xE8, 0xED, 0x00, 0xE8, 0xE3, - 0x00, 0xE6, 0xD9, 0xD7, 0xDD, 0xD9, 0xEA, 0xD9, 0x00, 0x00, 0x00, 0x00, - 0xED, 0xE3, 0xE9, 0xE6, 0x00, 0xE8, 0xE6, 0xD5, 0xE2, 0xE7, 0xDA, 0xD9, - 0xE6, 0xD9, 0xD8, 0x00, 0xCA, 0xC9, 0xC5, 0x1B, 0xC7, 0xC9, 0xC8, 0xAB, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xBE, 0xE3, 0x00, 0xE2, - 0xE3, 0xE8, 0x00, 0xE8, 0xE3, 0xE7, 0xE7, 0x00, 0xE8, 0xDC, 0xDD, 0xE7, - 0x00, 0xBF, 0xEC, 0xD7, 0xDC, 0xD5, 0xE2, 0xDB, 0xD9, 0x00, 0xBD, 0xD5, - 0xE6, 0xD8, 0x00, 0xD6, 0xD9, 0xDA, 0xE3, 0xE6, 0xD9, 0x00, 0x00, 0x00, - 0xE6, 0xD9, 0xD7, 0xD9, 0xDD, 0xEA, 0xDD, 0xE2, 0xDB, 0x00, 0xED, 0xE3, - 0xE9, 0xE6, 0x00, 0xE8, 0xE6, 0xD5, 0xE2, 0xE7, 0xDA, 0xD9, 0xE6, 0xD9, - 0xD8, 0x00, 0xCA, 0xC9, 0xC5, 0x1B, 0xC7, 0xC9, 0xC8, 0xAB, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00}; +static constexpr u8 em_wonder_card[0x14E] = {0x08, 0x6E, 0x00, 0x00, 0xBA, 0xB4, 0xBE, 0xB9, 0x00, + 0x00, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, 0xCA, 0xCC, 0xC9, 0xC0, 0xBF, 0xCD, 0xCD, 0xC9, 0xCC, + 0x00, 0xC0, 0xBF, 0xC8, 0xC8, 0xBF, 0xC6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xCE, + 0xE6, 0xD5, 0xE2, 0xE7, 0xDA, 0xD9, 0xE6, 0x00, 0xBD, 0xD9, 0xE6, 0xE8, 0xDD, 0xDA, 0xDD, 0xD7, + 0xD5, 0xE8, 0xD9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xD0, 0xDD, 0xE7, 0xDD, 0xE8, 0x00, 0xE8, 0xDC, 0xD9, 0x00, 0xDC, + 0xE3, 0xE9, 0xE7, 0xD9, 0x00, 0xE7, 0xE3, 0xE9, 0xE8, 0xDC, 0xD9, 0xD5, 0xE7, 0xE8, 0x00, 0xE3, + 0xDA, 0x00, 0xE8, 0xDC, 0xD9, 0x00, 0xCA, 0xC9, 0xC5, 0x1B, 0xC7, 0xC9, 0xC8, 0xBD, 0xBF, 0xC8, + 0xCE, 0xBF, 0xCC, 0x00, 0xDD, 0xE2, 0x00, 0xCD, 0xE3, 0xE3, 0xE8, 0xE3, 0xE4, 0xE3, 0xE0, 0xDD, + 0xE7, 0x00, 0xBD, 0xDD, 0xE8, 0xED, 0x00, 0xE8, 0xE3, 0x00, 0xE6, 0xD9, 0xD7, 0xDD, 0xD9, 0xEA, + 0xD9, 0x00, 0x00, 0x00, 0x00, 0xED, 0xE3, 0xE9, 0xE6, 0x00, 0xE8, 0xE6, 0xD5, 0xE2, 0xE7, 0xDA, + 0xD9, 0xE6, 0xD9, 0xD8, 0x00, 0xCA, 0xC9, 0xC5, 0x1B, 0xC7, 0xC9, 0xC8, 0xAB, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xBE, 0xE3, 0x00, 0xE2, 0xE3, 0xE8, 0x00, 0xE8, 0xE3, 0xE7, 0xE7, + 0x00, 0xE8, 0xDC, 0xDD, 0xE7, 0x00, 0xBF, 0xEC, 0xD7, 0xDC, 0xD5, 0xE2, 0xDB, 0xD9, 0x00, 0xBD, + 0xD5, 0xE6, 0xD8, 0x00, 0xD6, 0xD9, 0xDA, 0xE3, 0xE6, 0xD9, 0x00, 0x00, 0x00, 0xE6, 0xD9, 0xD7, + 0xD9, 0xDD, 0xEA, 0xDD, 0xE2, 0xDB, 0x00, 0xED, 0xE3, 0xE9, 0xE6, 0x00, 0xE8, 0xE6, 0xD5, 0xE2, + 0xE7, 0xDA, 0xD9, 0xE6, 0xD9, 0xD8, 0x00, 0xCA, 0xC9, 0xC5, 0x1B, 0xC7, 0xC9, 0xC8, 0xAB, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00}; // static u8 rs_wonder_card[0x14E] = { -// 0xCE, 0x7C, 0x00, 0x00, 0xBA, 0xB4, 0xBE, 0xB9, 0x00, 0x00, 0x00, 0x00, -// 0x1C, 0x00, 0x00, 0x00, 0xCA, 0xCC, 0xC9, 0xC0, 0xBF, 0xCD, 0xCD, 0xC9, -// 0xCC, 0x00, 0xC0, 0xBF, 0xC8, 0xC8, 0xBF, 0xC6, 0x00, 0x00, 0x00, 0x00, -// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xCE, 0xE6, 0xD5, 0xE2, -// 0xE7, 0xDA, 0xD9, 0xE6, 0x00, 0xBD, 0xD9, 0xE6, 0xE8, 0xDD, 0xDA, 0xDD, -// 0xD7, 0xD5, 0xE8, 0xD9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD0, 0xDD, -// 0xE7, 0xDD, 0xE8, 0x00, 0xE8, 0xDC, 0xD9, 0x00, 0xDC, 0xE3, 0xE9, 0xE7, -// 0xD9, 0x00, 0xE7, 0xE3, 0xE9, 0xE8, 0xDC, 0xD9, 0xD5, 0xE7, 0xE8, 0x00, -// 0xE3, 0xDA, 0x00, 0xE8, 0xDC, 0xD9, 0x00, 0xCA, 0xC9, 0xC5, 0x1B, 0xC7, -// 0xC9, 0xC8, 0xBD, 0xBF, 0xC8, 0xCE, 0xBF, 0xCC, 0x00, 0xDD, 0xE2, 0x00, -// 0xC7, 0xE3, 0xE7, 0xE7, 0xD8, 0xD9, 0xD9, 0xE4, 0x00, 0xBD, 0xDD, 0xE8, -// 0xED, 0x00, 0xE8, 0xE3, 0x00, 0xE6, 0xD9, 0xD7, 0xDD, 0xD9, 0xEA, 0xD9, -// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xED, 0xE3, 0xE9, 0xE6, 0x00, 0xE8, -// 0xE6, 0xD5, 0xE2, 0xE7, 0xDA, 0xD9, 0xE6, 0xD9, 0xD8, 0x00, 0xCA, 0xC9, -// 0xC5, 0x1B, 0xC7, 0xC9, 0xC8, 0xAB, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -// 0x00, 0x00, 0xBE, 0xE3, 0x00, 0xE2, 0xE3, 0xE8, 0x00, 0xE8, 0xE3, 0xE7, -// 0xE7, 0x00, 0xE8, 0xDC, 0xDD, 0xE7, 0x00, 0xBF, 0xEC, 0xD7, 0xDC, 0xD5, -// 0xE2, 0xDB, 0xD9, 0x00, 0xBD, 0xD5, 0xE6, 0xD8, 0x00, 0xD6, 0xD9, 0xDA, -// 0xE3, 0xE6, 0xD9, 0x00, 0x00, 0x00, 0xE6, 0xD9, 0xD7, 0xD9, 0xDD, 0xEA, -// 0xDD, 0xE2, 0xDB, 0x00, 0xED, 0xE3, 0xE9, 0xE6, 0x00, 0xE8, 0xE6, 0xD5, -// 0xE2, 0xE7, 0xDA, 0xD9, 0xE6, 0xD9, 0xD8, 0x00, 0xCA, 0xC9, 0xC5, 0x1B, -// 0xC7, 0xC9, 0xC8, 0xAB, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; // checksum -static constexpr u8 frlg_wonder_card[0x14E] = {0x67, 0x18, 0x00, 0x00, 0xBA, - 0xB4, 0xBE, 0xB9, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, 0xCA, - 0xCC, 0xC9, 0xC0, 0xBF, 0xCD, 0xCD, 0xC9, 0xCC, 0x00, 0xC0, 0xBF, 0xC8, - 0xC8, 0xBF, 0xC6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0xCE, 0xE6, 0xD5, 0xE2, 0xE7, 0xDA, 0xD9, 0xE6, 0x00, - 0xBD, 0xD9, 0xE6, 0xE8, 0xDD, 0xDA, 0xDD, 0xD7, 0xD5, 0xE8, 0xD9, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0xD0, 0xDD, 0xE7, 0xDD, 0xE8, 0x00, 0xE8, - 0xDC, 0xD9, 0x00, 0xDC, 0xE3, 0xE9, 0xE7, 0xD9, 0x00, 0xE7, 0xE3, 0xE9, - 0xE8, 0xDC, 0x00, 0xE3, 0xDA, 0x00, 0xE8, 0xDC, 0xD9, 0x00, 0xCA, 0xC9, - 0xC5, 0x1B, 0xC7, 0xC9, 0xC8, 0x00, 0x00, 0x00, 0x00, 0xBD, 0xBF, 0xC8, - 0xCE, 0xBF, 0xCC, 0x00, 0xE3, 0xE2, 0x00, 0xCD, 0xD9, 0xEA, 0xD9, 0xE2, - 0x00, 0xC3, 0xE7, 0xE0, 0xD5, 0xE2, 0xD8, 0x00, 0xE8, 0xE3, 0x00, 0xE6, - 0xD9, 0xD7, 0xDD, 0xD9, 0xEA, 0xD9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0xED, 0xE3, 0xE9, 0xE6, 0x00, 0xE8, 0xE6, 0xD5, 0xE2, 0xE7, 0xDA, - 0xD9, 0xE6, 0xD9, 0xD8, 0x00, 0xCA, 0xC9, 0xC5, 0x1B, 0xC7, 0xC9, 0xC8, - 0xAB, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xBE, 0xE3, 0x00, - 0xE2, 0xE3, 0xE8, 0x00, 0xE8, 0xE3, 0xE7, 0xE7, 0x00, 0xE8, 0xDC, 0xDD, - 0xE7, 0x00, 0xBF, 0xEC, 0xD7, 0xDC, 0xD5, 0xE2, 0xDB, 0xD9, 0x00, 0xBD, - 0xD5, 0xE6, 0xD8, 0x00, 0xD6, 0xD9, 0xDA, 0xE3, 0xE6, 0xD9, 0x00, 0x00, - 0x00, 0xE6, 0xD9, 0xD7, 0xD9, 0xDD, 0xEA, 0xDD, 0xE2, 0xDB, 0x00, 0xED, - 0xE3, 0xE9, 0xE6, 0x00, 0xE8, 0xE6, 0xD5, 0xE2, 0xE7, 0xDA, 0xD9, 0xE6, - 0xD9, 0xD8, 0x00, 0xCA, 0xC9, 0xC5, 0x1B, 0xC7, 0xC9, 0xC8, 0xAB, 0x00, +// 0xCE, 0x7C, 0x00, 0x00, 0xBA, 0xB4, 0xBE, 0xB9, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x00, 0x00, +// 0x00, 0xCA, 0xCC, 0xC9, 0xC0, 0xBF, 0xCD, 0xCD, 0xC9, 0xCC, 0x00, 0xC0, 0xBF, 0xC8, 0xC8, +// 0xBF, 0xC6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xCE, 0xE6, 0xD5, 0xE2, +// 0xE7, 0xDA, 0xD9, 0xE6, 0x00, 0xBD, 0xD9, 0xE6, 0xE8, 0xDD, 0xDA, 0xDD, 0xD7, 0xD5, 0xE8, +// 0xD9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +// 0x00, 0x00, 0x00, 0x00, 0xD0, 0xDD, 0xE7, 0xDD, 0xE8, 0x00, 0xE8, 0xDC, 0xD9, 0x00, 0xDC, +// 0xE3, 0xE9, 0xE7, 0xD9, 0x00, 0xE7, 0xE3, 0xE9, 0xE8, 0xDC, 0xD9, 0xD5, 0xE7, 0xE8, 0x00, +// 0xE3, 0xDA, 0x00, 0xE8, 0xDC, 0xD9, 0x00, 0xCA, 0xC9, 0xC5, 0x1B, 0xC7, 0xC9, 0xC8, 0xBD, +// 0xBF, 0xC8, 0xCE, 0xBF, 0xCC, 0x00, 0xDD, 0xE2, 0x00, 0xC7, 0xE3, 0xE7, 0xE7, 0xD8, 0xD9, +// 0xD9, 0xE4, 0x00, 0xBD, 0xDD, 0xE8, 0xED, 0x00, 0xE8, 0xE3, 0x00, 0xE6, 0xD9, 0xD7, 0xDD, +// 0xD9, 0xEA, 0xD9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xED, 0xE3, 0xE9, 0xE6, 0x00, 0xE8, +// 0xE6, 0xD5, 0xE2, 0xE7, 0xDA, 0xD9, 0xE6, 0xD9, 0xD8, 0x00, 0xCA, 0xC9, 0xC5, 0x1B, 0xC7, +// 0xC9, 0xC8, 0xAB, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xBE, +// 0xE3, 0x00, 0xE2, 0xE3, 0xE8, 0x00, 0xE8, 0xE3, 0xE7, 0xE7, 0x00, 0xE8, 0xDC, 0xDD, 0xE7, +// 0x00, 0xBF, 0xEC, 0xD7, 0xDC, 0xD5, 0xE2, 0xDB, 0xD9, 0x00, 0xBD, 0xD5, 0xE6, 0xD8, 0x00, +// 0xD6, 0xD9, 0xDA, 0xE3, 0xE6, 0xD9, 0x00, 0x00, 0x00, 0xE6, 0xD9, 0xD7, 0xD9, 0xDD, 0xEA, +// 0xDD, 0xE2, 0xDB, 0x00, 0xED, 0xE3, 0xE9, 0xE6, 0x00, 0xE8, 0xE6, 0xD5, 0xE2, 0xE7, 0xDA, +// 0xD9, 0xE6, 0xD9, 0xD8, 0x00, 0xCA, 0xC9, 0xC5, 0x1B, 0xC7, 0xC9, 0xC8, 0xAB, 0x00, 0x00, +// 0x00, 0x00, 0x00, 0x00}; // checksum +static constexpr u8 frlg_wonder_card[0x14E] = {0x67, 0x18, 0x00, 0x00, 0xBA, 0xB4, 0xBE, 0xB9, 0x00, + 0x00, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, 0xCA, 0xCC, 0xC9, 0xC0, 0xBF, 0xCD, 0xCD, 0xC9, 0xCC, + 0x00, 0xC0, 0xBF, 0xC8, 0xC8, 0xBF, 0xC6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xCE, + 0xE6, 0xD5, 0xE2, 0xE7, 0xDA, 0xD9, 0xE6, 0x00, 0xBD, 0xD9, 0xE6, 0xE8, 0xDD, 0xDA, 0xDD, 0xD7, + 0xD5, 0xE8, 0xD9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xD0, 0xDD, 0xE7, 0xDD, 0xE8, 0x00, 0xE8, 0xDC, 0xD9, 0x00, 0xDC, + 0xE3, 0xE9, 0xE7, 0xD9, 0x00, 0xE7, 0xE3, 0xE9, 0xE8, 0xDC, 0x00, 0xE3, 0xDA, 0x00, 0xE8, 0xDC, + 0xD9, 0x00, 0xCA, 0xC9, 0xC5, 0x1B, 0xC7, 0xC9, 0xC8, 0x00, 0x00, 0x00, 0x00, 0xBD, 0xBF, 0xC8, + 0xCE, 0xBF, 0xCC, 0x00, 0xE3, 0xE2, 0x00, 0xCD, 0xD9, 0xEA, 0xD9, 0xE2, 0x00, 0xC3, 0xE7, 0xE0, + 0xD5, 0xE2, 0xD8, 0x00, 0xE8, 0xE3, 0x00, 0xE6, 0xD9, 0xD7, 0xDD, 0xD9, 0xEA, 0xD9, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xED, 0xE3, 0xE9, 0xE6, 0x00, 0xE8, 0xE6, 0xD5, 0xE2, 0xE7, 0xDA, + 0xD9, 0xE6, 0xD9, 0xD8, 0x00, 0xCA, 0xC9, 0xC5, 0x1B, 0xC7, 0xC9, 0xC8, 0xAB, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xBE, 0xE3, 0x00, 0xE2, 0xE3, 0xE8, 0x00, 0xE8, 0xE3, 0xE7, 0xE7, + 0x00, 0xE8, 0xDC, 0xDD, 0xE7, 0x00, 0xBF, 0xEC, 0xD7, 0xDC, 0xD5, 0xE2, 0xDB, 0xD9, 0x00, 0xBD, + 0xD5, 0xE6, 0xD8, 0x00, 0xD6, 0xD9, 0xDA, 0xE3, 0xE6, 0xD9, 0x00, 0x00, 0x00, 0xE6, 0xD9, 0xD7, + 0xD9, 0xDD, 0xEA, 0xDD, 0xE2, 0xDB, 0x00, 0xED, 0xE3, 0xE9, 0xE6, 0x00, 0xE8, 0xE6, 0xD5, 0xE2, + 0xE7, 0xDA, 0xD9, 0xE6, 0xD9, 0xD8, 0x00, 0xCA, 0xC9, 0xC5, 0x1B, 0xC7, 0xC9, 0xC8, 0xAB, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; // checksum /// function to calculate a 32-bit checksum of a script buffer. @@ -311,8 +286,7 @@ static u32 calc_checksum32(const u8 *buffer, u32 size) } /// function to calculate a 16-bit CRC of a script buffer. -static u16 calc_crc16( - const u8 *buffer, u32 size) // Implementation taken from PokeEmerald Decomp +static u16 calc_crc16(const u8 *buffer, u32 size) // Implementation taken from PokeEmerald Decomp { u32 i, j; u16 crc = 0x1121; @@ -380,33 +354,29 @@ static void pickRSEFRLGChunks(Language lang, const u8 **&chunkList, u32 &size) } /** - * @brief This one loads the specified textEntry index into a newly malloc'ed - * outBuffer. It removes the colored text from the text entry if necessary and - * stores the actual buffer depth into outBufferDepth + * @brief This one loads the specified textEntry index into a newly malloc'ed outBuffer. + * It removes the colored text from the text entry if necessary and stores the actual buffer depth + * into outBufferDepth * - * WARNING: the caller becomes owner of the outBuffer pointer. Make sure to - * free() it! + * WARNING: the caller becomes owner of the outBuffer pointer. Make sure to free() it! */ -static void loadProcessedTextEntry(const u16 *charset, - FileContainerReader &textReader, u16 entryIndex, u8 *&outBuffer, - u32 &outBufferDepth) +static void loadProcessedTextEntry(const u16 *charset, FileContainerReader &textReader, + u16 entryIndex, u8 *&outBuffer, u32 &outBufferDepth) { - const u8 *curText = - textReader.getPointerToFileInDecompressionBuffer(entryIndex); + const u8 *curText = textReader.getPointerToFileInDecompressionBuffer(entryIndex); u8 *curBuffer; outBuffer = (u8 *)malloc(textReader.getFileSize(entryIndex)); curBuffer = outBuffer; - // Process the text entry and copy it into a temporary buffer, removing any - // colored text if necessary. + // Process the text entry and copy it into a temporary buffer, removing any colored text if + // necessary. while ((*curText) != 0xFF) { if (curr_GBA_rom.is_hoenn()) { - if (*curText == 0xFC && - (get_char_from_charset(charset, (u16)(*(curText + 1))) == - 0x01)) // Removes colored text + if (*curText == 0xFC && (get_char_from_charset(charset, (u16)(*(curText + 1))) == + 0x01)) // Removes colored text { curText += 2; continue; @@ -424,22 +394,21 @@ static void loadProcessedTextEntry(const u16 *charset, } /** - * @brief This function injects a text entry generated by text_helper into the - * provided buffer. NOTE: bufferPos should point to the exact location at which - * the text entry should be injected. NOTE: this code originated from - * text_var::insert_text() and has been adapted for use in this context. + * @brief This function injects a text entry generated by text_helper into the provided buffer. + * NOTE: bufferPos should point to the exact location at which the text entry should be injected. + * NOTE: this code originated from text_var::insert_text() and has been adapted for use in this + * context. * - * @param charset a charset buffer to use hen injecting the text entry. It's - * used to detect colored text and remove it if necessary. - * @param bufferPos an offset into the buffer where the text entry should be - * injected. + * @param charset a charset buffer to use hen injecting the text entry. It's used to detect colored + * text and remove it if necessary. + * @param bufferPos an offset into the buffer where the text entry should be injected. * @param textReader a FileContainerReader instance used to read the text entry. * @param entryIndex the index of the text entry to inject. * @return u32 the number of bytes injected into the buffer. */ -static u32 __attribute__((noinline)) injectTextEntryIntoBuffer( - const u16 *charset, u8 *buffer, u32 bufferSize, u32 bufferPos, - FileContainerReader &textReader, u16 entryIndex, bool isFirstTime) +static u32 __attribute__((noinline)) injectTextEntryIntoBuffer(const u16 *charset, u8 *buffer, + u32 bufferSize, u32 bufferPos, FileContainerReader &textReader, u16 entryIndex, + bool isFirstTime) { u8 *curBuffer = buffer + bufferPos; u8 *tempBuffer; @@ -448,13 +417,10 @@ static u32 __attribute__((noinline)) injectTextEntryIntoBuffer( u16 otherEntryIndex; u32 otherBufferDepth; - // if this is a first_time related text, determine which entry to inject - // first. + // if this is a first_time related text, determine which entry to inject first. selectedEntryIndex = entryIndex; otherEntryIndex = UINT16_MAX; - for (u32 i = 0; i < sizeof(firstTimeTextEntryPairs) / - sizeof(firstTimeTextEntryPairs[0]); - ++i) + for (u32 i = 0; i < sizeof(firstTimeTextEntryPairs) / sizeof(firstTimeTextEntryPairs[0]); ++i) { if (entryIndex == firstTimeTextEntryPairs[i].first) { @@ -470,25 +436,21 @@ static u32 __attribute__((noinline)) injectTextEntryIntoBuffer( } } - loadProcessedTextEntry( - charset, textReader, selectedEntryIndex, tempBuffer, bufferDepth); + loadProcessedTextEntry(charset, textReader, selectedEntryIndex, tempBuffer, bufferDepth); // Move the existing buffer content to make room for the new text entry - memmove(curBuffer + bufferDepth, curBuffer, - bufferSize - bufferPos - bufferDepth); + memmove(curBuffer + bufferDepth, curBuffer, bufferSize - bufferPos - bufferDepth); // now copy the processed text into the buffer at the current position memcpy(curBuffer, tempBuffer, bufferDepth); free(tempBuffer); - // mystery_gift_builder in gba-payload-generator reserves space for the - // largest entry of the first_time/second_time pair. this is done to make - // sure the pointer references within the payload remain the same, no matter - // which one we inject. however, we need to take this into account, so we - // inject the next entry at the right offset as well, taking that - // reservation of space into account. + // mystery_gift_builder in gba-payload-generator reserves space for the largest entry of the + // first_time/second_time pair. this is done to make sure the pointer references within the + // payload remain the same, no matter which one we inject. however, we need to take this into + // account, so we inject the next entry at the right offset as well, taking that reservation of + // space into account. if (otherEntryIndex != UINT16_MAX) { - loadProcessedTextEntry( - charset, textReader, otherEntryIndex, tempBuffer, otherBufferDepth); + loadProcessedTextEntry(charset, textReader, otherEntryIndex, tempBuffer, otherBufferDepth); free(tempBuffer); if (bufferDepth < otherBufferDepth) { @@ -500,13 +462,11 @@ static u32 __attribute__((noinline)) injectTextEntryIntoBuffer( } /** - * @brief This function re-injects the RSEFRLG text table entries into the - * section30 and script payload buffers. In gba-payload-generator, we are - * stripping those texts after payload generation to improve compression and - * while keeping the pointers/offsets inside the payload intact. + * @brief This function re-injects the RSEFRLG text table entries into the section30 and script + * payload buffers. In gba-payload-generator, we are stripping those texts after payload generation + * to improve compression and while keeping the pointers/offsets inside the payload intact. * - * But in order to use the payload, we actually need to reinsert those at - * runtime. + * But in order to use the payload, we actually need to reinsert those at runtime. */ static void __attribute__((noinline)) reinjectMysteryGiftPayloadTexts( u8 *section30Buffer, u8 *mgScriptBuffer, bool isFirstTime) @@ -514,8 +474,8 @@ static void __attribute__((noinline)) reinjectMysteryGiftPayloadTexts( u8 decompressionBuffer[4096]; u16 gen3Charset[256]; u32 bytesInjected; - // the reason for using std::array for these is simply to be able to use - // initializer lists below. + // the reason for using std::array for these is simply to be able to use initializer lists + // below. std::array section30TextSequence; std::array scriptTextSequence; u8 textGreetEntryIndex; @@ -527,19 +487,16 @@ static void __attribute__((noinline)) reinjectMysteryGiftPayloadTexts( Language lang = convertLangCodeIntoLanguage(curr_GBA_rom.language); pickRSEFRLGChunks(lang, chunklist, chunkListSize); - FileContainerReader textReader( - chunklist, chunkListSize, sizeof(decompressionBuffer)); + FileContainerReader textReader(chunklist, chunkListSize, sizeof(decompressionBuffer)); textReader.init(decompressionBuffer, sizeof(decompressionBuffer)); - // make the section30Buffer and mgScriptBuffer pointers point to the exact - // insertion position within them. the section30 text offset (0x97E) remains - // consistent across languages and games in the payload. the script text - // offset shifts depending on the game version. (observed based on logs from - // gba-payload-generator) + // make the section30Buffer and mgScriptBuffer pointers point to the exact insertion position + // within them. the section30 text offset (0x97E) remains consistent across languages and games + // in the payload. the script text offset shifts depending on the game version. (observed based + // on logs from gba-payload-generator) - // Also construct text entry sequences, because we need to maintain the same - // order of injection as during the payload generation with - // gba-payload-generator + // Also construct text entry sequences, because we need to maintain the same order of injection + // as during the payload generation with gba-payload-generator section30Offset = 0x97E; switch (curr_GBA_rom.gamecode) @@ -549,67 +506,59 @@ static void __attribute__((noinline)) reinjectMysteryGiftPayloadTexts( mgScriptOffset = 0x268; textGreetEntryIndex = RSEFRLG_dia_textGreet_rse; iAmEntryIndex = RSEFRLG_dia_textIAm_first_rs; - section30TextSequence = {RSEFRLG_dia_textThank_rs, - RSEFRLG_dia_textPCFull_rs, RSEFRLG_dia_textWeHere_rs, - RSEFRLG_dia_textPCConvo_rs, RSEFRLG_dia_textPCThanks_rs, - RSEFRLG_dia_textLookerFull_rs, RSEFRLG_dia_textMoveBox_rs, - RSEFRLG_dia_textRecieved_rs}; + section30TextSequence = {RSEFRLG_dia_textThank_rs, RSEFRLG_dia_textPCFull_rs, + RSEFRLG_dia_textWeHere_rs, RSEFRLG_dia_textPCConvo_rs, RSEFRLG_dia_textPCThanks_rs, + RSEFRLG_dia_textLookerFull_rs, RSEFRLG_dia_textMoveBox_rs, RSEFRLG_dia_textRecieved_rs}; break; case FIRERED_ID: case LEAFGREEN_ID: mgScriptOffset = 0x278; textGreetEntryIndex = RSEFRLG_dia_textGreet_frlg; iAmEntryIndex = RSEFRLG_dia_textIAm_first_frlge; - section30TextSequence = {RSEFRLG_dia_textThank_frlge, - RSEFRLG_dia_textPCFull_frlge, RSEFRLG_dia_textWeHere_frlg, - RSEFRLG_dia_textPCConvo_frlge, RSEFRLG_dia_textPCThanks_frlge, - RSEFRLG_dia_textLookerFull_frlge, RSEFRLG_dia_textMoveBox_frlg, - RSEFRLG_dia_textRecieved_frlge}; + section30TextSequence = {RSEFRLG_dia_textThank_frlge, RSEFRLG_dia_textPCFull_frlge, + RSEFRLG_dia_textWeHere_frlg, RSEFRLG_dia_textPCConvo_frlge, + RSEFRLG_dia_textPCThanks_frlge, RSEFRLG_dia_textLookerFull_frlge, + RSEFRLG_dia_textMoveBox_frlg, RSEFRLG_dia_textRecieved_frlge}; break; default: mgScriptOffset = 0x298; textGreetEntryIndex = RSEFRLG_dia_textGreet_rse; iAmEntryIndex = RSEFRLG_dia_textIAm_first_frlge; - section30TextSequence = {RSEFRLG_dia_textThank_frlge, - RSEFRLG_dia_textPCFull_frlge, RSEFRLG_dia_textWeHere_e, - RSEFRLG_dia_textPCConvo_frlge, RSEFRLG_dia_textPCThanks_frlge, + section30TextSequence = {RSEFRLG_dia_textThank_frlge, RSEFRLG_dia_textPCFull_frlge, + RSEFRLG_dia_textWeHere_e, RSEFRLG_dia_textPCConvo_frlge, RSEFRLG_dia_textPCThanks_frlge, RSEFRLG_dia_textLookerFull_frlge, RSEFRLG_dia_textMoveBox_e, RSEFRLG_dia_textRecieved_frlge}; break; } - scriptTextSequence = { - textGreetEntryIndex, RSEFRLG_dia_textYouMustBe_first, iAmEntryIndex}; + scriptTextSequence = {textGreetEntryIndex, RSEFRLG_dia_textYouMustBe_first, iAmEntryIndex}; load_localized_charset(gen3Charset, 3, lang); for (unsigned i = 0; i < 8; ++i) { - bytesInjected = injectTextEntryIntoBuffer(gen3Charset, section30Buffer, - 0x1000, section30Offset, textReader, section30TextSequence[i], - isFirstTime); + bytesInjected = injectTextEntryIntoBuffer(gen3Charset, section30Buffer, 0x1000, + section30Offset, textReader, section30TextSequence[i], isFirstTime); section30Offset += bytesInjected; } for (unsigned i = 0; i < 3; ++i) { - bytesInjected = injectTextEntryIntoBuffer(gen3Charset, mgScriptBuffer, - MG_SCRIPT_SIZE, mgScriptOffset, textReader, scriptTextSequence[i], - isFirstTime); + bytesInjected = injectTextEntryIntoBuffer(gen3Charset, mgScriptBuffer, MG_SCRIPT_SIZE, + mgScriptOffset, textReader, scriptTextSequence[i], isFirstTime); mgScriptOffset += bytesInjected; } } /** - * @brief This function injects the PokeBox pokémons into section30 at offset - * 0x0, which is what the payload expects. It assumes that all the pokemons in - * the box are already converted. (should be done by script_array.cpp) + * @brief This function injects the PokeBox pokémons into section30 at offset 0x0, which is what the + * payload expects. It assumes that all the pokemons in the box are already converted. (should be + * done by script_array.cpp) * * @param box pointer to the PokeBox instance containing the Pokémon to inject. * @param section30Buffer The buffer representing section 30 of the save file. */ -static void __attribute__((noinline)) injectBoxIntoSection30( - PokeBox *box, u8 *section30Buffer) +static void __attribute__((noinline)) injectBoxIntoSection30(PokeBox *box, u8 *section30Buffer) { u8 dex_nums[MAX_PKMN_IN_BOX] = {}; u8 *curSection30 = section30Buffer; @@ -632,8 +581,7 @@ static void __attribute__((noinline)) injectBoxIntoSection30( tonccpy(curSection30, dex_nums, MAX_PKMN_IN_BOX); } -static void pickPatchFiles( - u32 &gamePatchFile, u32 &languagePatchFile, u32 &specificPatchFile) +static void pickPatchFiles(u32 &gamePatchFile, u32 &languagePatchFile, u32 &specificPatchFile) { u32 simplifiedGameCode; u32 simplifiedLanguageCode; @@ -688,8 +636,8 @@ static void pickPatchFiles( break; } - const u8 mapKey = PACK_PATCH_KEY( - simplifiedGameCode, simplifiedLanguageCode, (u8)curr_GBA_rom.version); + const u8 mapKey = + PACK_PATCH_KEY(simplifiedGameCode, simplifiedLanguageCode, (u8)curr_GBA_rom.version); for (u32 i = 0; i < sizeof(patchFileTable) / sizeof(patchFileTable[0]); ++i) { if (patchFileTable[i].key == mapKey) @@ -702,30 +650,27 @@ static void pickPatchFiles( } /** - * @brief This helper function will apply the BPS patch with index - * patchFileIndex stored in reader to the srcBuffer data and store the result in - * dstBuffer. srcBuffer remains untouched. + * @brief This helper function will apply the BPS patch with index patchFileIndex stored in reader + * to the srcBuffer data and store the result in dstBuffer. srcBuffer remains untouched. */ static void __attribute__((noinline)) applyBPSPatchToBuffer( - FileContainerReader &reader, u8 *dstBuffer, u8 *srcBuffer, - u32 patchFileIndex) + FileContainerReader &reader, u8 *dstBuffer, u8 *srcBuffer, u32 patchFileIndex) { - // Note: you may think it's peculiar that we're malloc'ing patchBuffer - // below. But here's the dilemma: the files in the file container may span - // multiple chunks. (mostly the last file in each chunk) Therefore using - // getPointerToFileInDecompressionBuffer() would be unsafe. We could've used - // the @noSpanChunks directive in the .containerdef file to overcome that. - // However, then we're hit by an additional problem: We've constructed - // patchFileTable above using the script_patches indexes, relying on those - // to be consistent/representative for both the section30 and script patch - // filecontainers. but section30 is much larger than script. Therefore the - // patches don't have the same filesizes either. This would result in - // @noSpanChunks injecting a different number of dummy files in each - // filecontainer, which would break the index consistency. + // Note: you may think it's peculiar that we're malloc'ing patchBuffer below. + // But here's the dilemma: the files in the file container may span multiple chunks. + // (mostly the last file in each chunk) + // Therefore using getPointerToFileInDecompressionBuffer() would be unsafe. + // We could've used the @noSpanChunks directive in the .containerdef file to overcome that. + // However, then we're hit by an additional problem: We've constructed patchFileTable above + // using the script_patches indexes, relying on those to be consistent/representative for both + // the section30 and script patch filecontainers. but section30 is much larger than script. + // Therefore the patches don't have the same filesizes either. This would result in + // @noSpanChunks injecting a different number of dummy files in each filecontainer, which would + // break the index consistency. // - // You might argue that we might as well use a statically allocated buffer - // for the patch. However, our IWRAM consumption is already quite high here. - // And malloc() will just use unused space at the end of EWRAM. + // You might argue that we might as well use a statically allocated buffer for the patch. + // However, our IWRAM consumption is already quite high here. And malloc() will just use unused + // space at the end of EWRAM. // (=where our multiboot rom resides) const u32 patchFileSize = reader.getFileSize(patchFileIndex); u8 *patchBuffer = (u8 *)malloc(patchFileSize); @@ -734,9 +679,8 @@ static void __attribute__((noinline)) applyBPSPatchToBuffer( free(patchBuffer); } -static void __attribute__((noinline)) patchBuffer(FileContainerReader &reader, - u8 *buffer, u32 bufferSize, u32 gamePatchFileIndex, - u32 languagePatchFileIndex, u32 specificPatchFileIndex) +static void __attribute__((noinline)) patchBuffer(FileContainerReader &reader, u8 *buffer, + u32 bufferSize, u32 gamePatchFileIndex, u32 languagePatchFileIndex, u32 specificPatchFileIndex) { u8 tempBuffer[4096]; memset(tempBuffer, 0, bufferSize); @@ -747,8 +691,7 @@ static void __attribute__((noinline)) patchBuffer(FileContainerReader &reader, // that's what the magic SKIP_SPECIFIC_PAYLOAD_PATCH_INDEX value is for. if (languagePatchFileIndex != SKIP_PATCH_INDEX) { - applyBPSPatchToBuffer( - reader, buffer, tempBuffer, languagePatchFileIndex); + applyBPSPatchToBuffer(reader, buffer, tempBuffer, languagePatchFileIndex); } else { @@ -757,48 +700,40 @@ static void __attribute__((noinline)) patchBuffer(FileContainerReader &reader, if (specificPatchFileIndex != SKIP_PATCH_INDEX) { - // now turn the english payload into the specific language - // payload. the result will be stored in tempBuffer - applyBPSPatchToBuffer( - reader, tempBuffer, buffer, specificPatchFileIndex); + // now turn the english payload into the specific language payload. + // the result will be stored in tempBuffer + applyBPSPatchToBuffer(reader, tempBuffer, buffer, specificPatchFileIndex); memcpy(buffer, tempBuffer, bufferSize); } } /** - * @brief This function reconstructs the pregenerated payload for section30 and - * the script buffer. The way it works is this: - * - We have stored the english ruby 1.0 payload (section30 + scriptbuffer) in - * compressed form. - * - We have created BPS patches to convert this payload from english ruby to - * english for 3 variants (ruby, emerald and fire red) - * - There's another BPS patch to convert the english variant to the - * language specific variant (for 3 game types: ruby, emerald and fire red) - * - Finally, there's another BPS patch to convert the language specific base - * payload to the final payload (for example: from french ruby 1.0 to french - * sapphire 1.1) + * @brief This function reconstructs the pregenerated payload for section30 and the script buffer. + * The way it works is this: + * - We have stored the english ruby 1.0 payload (section30 + scriptbuffer) in compressed form. + * - We have created BPS patches to convert this payload from english ruby to english for + * 3 variants (ruby, emerald and fire red) + * - There's another BPS patch to convert the english variant to the language specific + * variant (for 3 game types: ruby, emerald and fire red) + * - Finally, there's another BPS patch to convert the language specific base payload to the final + * payload (for example: from french ruby 1.0 to french sapphire 1.1) * - * This is all done to conserve space as much as possible and benefit most from - * compression. + * This is all done to conserve space as much as possible and benefit most from compression. * - * So, in order to reconstruct the payload for a specific game and language, we - * need to: + * So, in order to reconstruct the payload for a specific game and language, we need to: * 1. Decompress the english ruby payload into section30Buffer and scriptBuffer. - * 2. Determine the 3 patch sets required (transform to right gametype, - * transform to right language, transform to final version) for both - * scriptBuffer and section30Buffer. + * 2. Determine the 3 patch sets required (transform to right gametype, transform to right language, + * transform to final version) for both scriptBuffer and section30Buffer. * 3. uncompress these patches from the filecontainer. * 4. Apply these patches. * - * This function attempts to do it in a way that requires the least amount of - * IWRAM possible. One way we do that is by reusing the same decompression - * buffer for both file containers. + * This function attempts to do it in a way that requires the least amount of IWRAM possible. + * One way we do that is by reusing the same decompression buffer for both file containers. * - * WARNING: This function will require more than 6KB of additional IWRAM for - * decompression buffer and temp buffer! NOTE: __attribute__((noinline)) is used - * to ensure this function gets its own stack frame and therefore the local - * buffers don't leak into the caller's stack frame. This is important because - * IWRAM consumption is a big concern in PTGB. + * WARNING: This function will require more than 6KB of additional IWRAM for decompression buffer + * and temp buffer! NOTE: __attribute__((noinline)) is used to ensure this function gets its own + * stack frame and therefore the local buffers don't leak into the caller's stack frame. This is + * important because IWRAM consumption is a big concern in PTGB. */ static void __attribute__((noinline)) reconstructPregeneratedPayloads( u8 *section30Buffer, u8 *scriptBuffer) @@ -811,16 +746,13 @@ static void __attribute__((noinline)) reconstructPregeneratedPayloads( u32 specificPatchFile = (u8)Script_patchesFiles::SCRIPT_RUBY_ENGLISH_1_0; FileContainerReader section30PatchesReader(section30_patches_chunk_list, - sizeof(section30_patches_chunk_list) / - sizeof(section30_patches_chunk_list[0]), + sizeof(section30_patches_chunk_list) / sizeof(section30_patches_chunk_list[0]), BPS_PATCH_FILECONTAINER_CHUNK_SIZE); FileContainerReader scriptPatchesReader(script_patches_chunk_list, - sizeof(script_patches_chunk_list) / - sizeof(script_patches_chunk_list[0]), + sizeof(script_patches_chunk_list) / sizeof(script_patches_chunk_list[0]), BPS_PATCH_FILECONTAINER_CHUNK_SIZE); - // first determine the patch indexes needed to convert the base payloads to - // the specific game. + // first determine the patch indexes needed to convert the base payloads to the specific game. pickPatchFiles(gamePatchFile, languagePatchFile, specificPatchFile); // assume we found the entry. @@ -831,13 +763,13 @@ static void __attribute__((noinline)) reconstructPregeneratedPayloads( // patch section30 section30PatchesReader.init(decompressionBuffer, patchContainerChunkSize); - patchBuffer(section30PatchesReader, section30Buffer, 0x1000, gamePatchFile, - languagePatchFile, specificPatchFile); + patchBuffer(section30PatchesReader, section30Buffer, 0x1000, gamePatchFile, languagePatchFile, + specificPatchFile); // patch script scriptPatchesReader.init(decompressionBuffer, patchContainerChunkSize); - patchBuffer(scriptPatchesReader, scriptBuffer, MG_SCRIPT_SIZE, - gamePatchFile, languagePatchFile, specificPatchFile); + patchBuffer(scriptPatchesReader, scriptBuffer, MG_SCRIPT_SIZE, gamePatchFile, languagePatchFile, + specificPatchFile); } bool inject_mystery(PokeBox *box, bool isFirstTime) @@ -846,11 +778,10 @@ bool inject_mystery(PokeBox *box, bool isFirstTime) u8 script_buffer[MG_SCRIPT_SIZE]; reconstructPregeneratedPayloads(global_memory_buffer, script_buffer); - reinjectMysteryGiftPayloadTexts( - global_memory_buffer, script_buffer, isFirstTime); + reinjectMysteryGiftPayloadTexts(global_memory_buffer, script_buffer, isFirstTime); - // One thing our pregeneration process obviously leaves out is the pokemon - // data. so let's add that in now. + // One thing our pregeneration process obviously leaves out is the pokemon data. + // so let's add that in now. injectBoxIntoSection30(box, global_memory_buffer); if (curr_GBA_rom.is_ruby_sapphire()) @@ -863,16 +794,16 @@ bool inject_mystery(PokeBox *box, bool isFirstTime) } // Add in Pokemon and Dex data - // In the steps after this, we will be recycling the global_memory_buffer to - // read and write data to other sections of the save. So we really MUST - // write the generated data now, before we lose it. + // In the steps after this, we will be recycling the global_memory_buffer to read and write data + // to other sections of the save. So we really MUST write the generated data now, before we lose + // it. update_memory_buffer_checksum(global_memory_buffer, false); erase_sector(0x1E000); copy_ram_to_save(&global_memory_buffer[0], 0x1E000, 0x1000); - // section_30 data has been stored, so now we can safely re-use the - // global_memory_buffer for other sections. Let's move on to the next step. + // section_30 data has been stored, so now we can safely re-use the global_memory_buffer for + // other sections. Let's move on to the next step. // Add in Wonder Card copy_save_to_ram(memory_section_array[4], &global_memory_buffer[0], 0x1000); @@ -884,13 +815,11 @@ bool inject_mystery(PokeBox *box, bool isFirstTime) break; case FIRERED_ID: case LEAFGREEN_ID: - memcpy(global_memory_buffer + curr_GBA_rom.offset_wondercard, - frlg_wonder_card, 0x14E); + memcpy(global_memory_buffer + curr_GBA_rom.offset_wondercard, frlg_wonder_card, 0x14E); break; case EMERALD_ID: default: - memcpy(global_memory_buffer + curr_GBA_rom.offset_wondercard, - em_wonder_card, 0x14E); + memcpy(global_memory_buffer + curr_GBA_rom.offset_wondercard, em_wonder_card, 0x14E); break; } @@ -901,45 +830,37 @@ bool inject_mystery(PokeBox *box, bool isFirstTime) global_memory_buffer[curr_GBA_rom.offset_script + 3] = checksum >> 24; // Add in Mystery Script data - memcpy(global_memory_buffer + curr_GBA_rom.offset_script + 4, script_buffer, - MG_SCRIPT_SIZE); + memcpy(global_memory_buffer + curr_GBA_rom.offset_script + 4, script_buffer, MG_SCRIPT_SIZE); update_memory_buffer_checksum(global_memory_buffer, false); erase_sector(memory_section_array[4]); copy_ram_to_save(&global_memory_buffer[0], memory_section_array[4], 0x1000); // Set flags - int memory_section = - 1 + - ((curr_GBA_rom.offset_flags + (curr_GBA_rom.unused_flag_start / 8)) / - 0xF80); // This sets the correct memory section, since flags stretch - // between section 1 and 2. - copy_save_to_ram( - memory_section_array[memory_section], &global_memory_buffer[0], 0x1000); - global_memory_buffer[(curr_GBA_rom.offset_flags + - (curr_GBA_rom.all_collected_flag / 8)) % - 0xF80] &= ~(1 << (curr_GBA_rom.all_collected_flag % - 8)); // Set "collected all" flag to 0 + int memory_section = 1 + ((curr_GBA_rom.offset_flags + (curr_GBA_rom.unused_flag_start / 8)) / + 0xF80); // This sets the correct memory section, since flags + // stretch between section 1 and 2. + copy_save_to_ram(memory_section_array[memory_section], &global_memory_buffer[0], 0x1000); + global_memory_buffer[(curr_GBA_rom.offset_flags + (curr_GBA_rom.all_collected_flag / 8)) % + 0xF80] &= + ~(1 << (curr_GBA_rom.all_collected_flag % 8)); // Set "collected all" flag to 0 for (int i = 0; i < box->getNumInBox(); i++) { int curr_flag; curr_flag = curr_GBA_rom.pkmn_collected_flag_start + i; - global_memory_buffer[(curr_GBA_rom.offset_flags + (curr_flag / 8)) % - 0xF80] &= + global_memory_buffer[(curr_GBA_rom.offset_flags + (curr_flag / 8)) % 0xF80] &= ~(1 << (curr_flag % 8)); // Reset the flag if (box->getGen3Pokemon(i)->isValid) { - global_memory_buffer[(curr_GBA_rom.offset_flags + (curr_flag / 8)) % - 0xF80] |= + global_memory_buffer[(curr_GBA_rom.offset_flags + (curr_flag / 8)) % 0xF80] |= (1 << (curr_flag % 8)); // Set flag accordingly } } update_memory_buffer_checksum(global_memory_buffer, false); erase_sector(memory_section_array[memory_section]); - copy_ram_to_save( - &global_memory_buffer[0], memory_section_array[memory_section], 0x1000); + copy_ram_to_save(&global_memory_buffer[0], memory_section_array[memory_section], 0x1000); // Save custom save data write_custom_save_data(); diff --git a/source/pokedex.cpp b/source/pokedex.cpp index 569e3cc..300b11f 100644 --- a/source/pokedex.cpp +++ b/source/pokedex.cpp @@ -30,8 +30,8 @@ bool mew_caught; bool celebi_caught; bool missingno_caught = false; -static void load_general_table_text_entries(u8 *decompression_buffer, - u32 decompression_buffer_size, u8 *kanto_buffer, u8 *johto_buffer) +static void load_general_table_text_entries( + u8 *decompression_buffer, u32 decompression_buffer_size, u8 *kanto_buffer, u8 *johto_buffer) { const u8 **chunkList; u32 numChunks; @@ -48,9 +48,9 @@ void pokedex_init() { for (int i = 0; i < DEX_MAX; i++) { - // dex_array[i] = Dex(dex_sprites[DEX_SPRITE_LEFT][i], - // dex_sprites[DEX_SPRITE_MID][i], dex_sprites[DEX_SPRITE_RIGHT][i]); - // dex_array[i].set_location(dex_x_cord, (i * (8 * 3)) + 8); + // dex_array[i] = Dex(dex_sprites[DEX_SPRITE_LEFT][i], dex_sprites[DEX_SPRITE_MID][i], + // dex_sprites[DEX_SPRITE_RIGHT][i]); dex_array[i].set_location(dex_x_cord, (i * (8 * 3)) + + // 8); } // kanto_count = Button(button_blank_left, button_blank_right, 64); // johto_count = Button(button_blank_left_2, button_blank_right_2, 64); @@ -89,8 +89,8 @@ void pokedex_init() #include "gen_3_charsets_lz10_bin.h" #include "libstd_replacements.h" -// attribute noinline is used to make sure it doesn't get inlined and -// permanently use IWRAM for the decompression_buffer +// attribute noinline is used to make sure it doesn't get inlined and permanently use IWRAM for the +// decompression_buffer int __attribute__((noinline)) pokedex_loop() { u8 TYPES[POKEMON_ARRAY_SIZE][2]; @@ -106,13 +106,11 @@ int __attribute__((noinline)) pokedex_loop() LZ77UnCompWram(TYPES_lz10_bin, (u8 *)TYPES); // LZ77UnCompWram(gen_3_charsets_lz10_bin, (u8*)charset); - load_general_table_text_entries(decompression_buffer, - sizeof(decompression_buffer), kanto_name, johto_name); + load_general_table_text_entries( + decompression_buffer, sizeof(decompression_buffer), kanto_name, johto_name); - get_text_table_chunks( - PKMN_NAMES_INDEX, &namesChunkList, &namesNumChunks, &namesChunkSize); - FileContainerReader PKMN_NAMES( - namesChunkList, namesNumChunks, namesChunkSize); + get_text_table_chunks(PKMN_NAMES_INDEX, &namesChunkList, &namesNumChunks, &namesChunkSize); + FileContainerReader PKMN_NAMES(namesChunkList, namesNumChunks, namesChunkSize); PKMN_NAMES.init(decompression_buffer, sizeof(decompression_buffer)); pokedex_init(); @@ -121,10 +119,9 @@ int __attribute__((noinline)) pokedex_loop() const byte undiscovered_text[] = { 0xAE, 0xAE, 0xAE, 0xAE, 0xAE, 0xAE, 0xAE, 0xAE, 0xAE, 0xAE, 0xFF}; - byte temp_string[4] = - {}; // Should never be longer than 4 characters (including endline) - // TODO: For some reason there is screen tearing here. Probably not - // noticable on console, but it should be removed at some point + byte temp_string[4] = {}; // Should never be longer than 4 characters (including endline) + // TODO: For some reason there is screen tearing here. Probably not + // noticable on console, but it should be removed at some point tte_set_ink(INK_DARK_GREY); tte_set_pos(8, 146); @@ -264,27 +261,22 @@ int __attribute__((noinline)) pokedex_loop() } tte_set_pos(dex_x_cord + (3 * 8), (i * 8 * 2) + 28); - convert_int_to_ptgb_str( - dex_shift + i + 1 + mythic_skip, temp_string, 3); + convert_int_to_ptgb_str(dex_shift + i + 1 + mythic_skip, temp_string, 3); ptgb_write_simple(temp_string, true); tte_set_pos(dex_x_cord + (7 * 8), (i * 8 * 2) + 28); - PKMN_NAMES.readFile( - dex_shift + i + 1 + mythic_skip, name_buffer); - ptgb_write_simple(is_caught(dex_shift + i + 1 + mythic_skip) - ? name_buffer - : undiscovered_text, + PKMN_NAMES.readFile(dex_shift + i + 1 + mythic_skip, name_buffer); + ptgb_write_simple( + is_caught(dex_shift + i + 1 + mythic_skip) ? name_buffer : undiscovered_text, true); } - // global_next_frame(); // This is a bit silly, but it works. Makes - // the types one frame off from the text, but that's 'fine' - // Eventually it could be optimized to move the labels around, but - // this honestly makes the most sense. Less code but one frame - // different + // global_next_frame(); // This is a bit silly, but it works. Makes the types one frame + // off from the text, but that's 'fine' + // Eventually it could be optimized to move the labels around, but this honestly makes + // the most sense. Less code but one frame different for (int i = 0; i < DEX_MAX; i++) { - load_type_sprites((const u8 *)TYPES, - dex_shift + i + 1 + mythic_skip, i, + load_type_sprites((const u8 *)TYPES, dex_shift + i + 1 + mythic_skip, i, is_caught(dex_shift + i + 1 + mythic_skip)); } update = false; diff --git a/source/ptgb_save_data_manager.cpp b/source/ptgb_save_data_manager.cpp index 181a3f5..1718aff 100644 --- a/source/ptgb_save_data_manager.cpp +++ b/source/ptgb_save_data_manager.cpp @@ -27,8 +27,7 @@ void write_custom_save_data() bool is_caught(int dex_num) { - return (((save_data_array[CAUGHT_DATA + (dex_num / 8)]) >> dex_num % 8) & - 1) || + return (((save_data_array[CAUGHT_DATA + (dex_num / 8)]) >> dex_num % 8) & 1) || g_debug_options.force_all_caught; } @@ -77,8 +76,8 @@ bool check_can_save() byte data_buffer[8] = {}; byte test_buffer[8] = {0xC7, 0xCF, 0xCA, 0xCA, 0xBF, 0xCE, 0xA4, 0xBE}; - // Copy the current bytes and save them to the data buffer, and replace them - // with the test_buffer + // Copy the current bytes and save them to the data buffer, and replace them with the + // test_buffer copy_save_to_ram(HALL_OF_FAME + 0x1000, &global_memory_buffer[0], 0x1000); for (int i = 0; i < 8; i++) { @@ -88,8 +87,8 @@ bool check_can_save() erase_sector(HALL_OF_FAME + 0x1000); copy_ram_to_save(&global_memory_buffer[0], HALL_OF_FAME + 0x1000, 0x1000); - // Overwrite the data in the global memory buffer to make sure that it isn't - // still there when testing + // Overwrite the data in the global memory buffer to make sure that it isn't still there when + // testing for (int i = 0; i < 8; i++) { global_memory_buffer[HOF_SECTION + i] = 0; @@ -104,8 +103,7 @@ bool check_can_save() // Did not save correctly, return false return false; } - // Set the byte in the memory buffer back in preperation for saving it - // back again + // Set the byte in the memory buffer back in preperation for saving it back again global_memory_buffer[HOF_SECTION + i] = data_buffer[i]; } diff --git a/source/random.cpp b/source/random.cpp index a3bb96d..c7d8633 100644 --- a/source/random.cpp +++ b/source/random.cpp @@ -9,8 +9,7 @@ unsigned int rand_get_seed() { return u32_rand; } void rand_next_frame() { - u32_rand = (0x41C64E6D * u32_rand) + - 0x6073; // This is the randomization method used in Gen 3 + u32_rand = (0x41C64E6D * u32_rand) + 0x6073; // This is the randomization method used in Gen 3 } u32 get_rand_u32() @@ -30,15 +29,13 @@ u32 get_rev_rand_u32(u32 input) { return (input - 24691) * 4005161829; } u16 get_rev_rand_u16(u32 input) { return (get_rev_rand_u32(input) >> 16); } // Force ARM mode. In Thumb mode this imports __aeabi_lmul. -__attribute__((target("arm"), noinline)) static unsigned multiply_high( - unsigned x, unsigned y) +__attribute__((target("arm"), noinline)) static unsigned multiply_high(unsigned x, unsigned y) { return ((unsigned long long)x * y) >> 32; // umull } unsigned get_rand_range(unsigned inc_min, unsigned exc_max) { - // fixed point: get_rand_u32() / (float)0x100000000 * (exc_max - inc_min) + - // inc_min + // fixed point: get_rand_u32() / (float)0x100000000 * (exc_max - inc_min) + inc_min return multiply_high(get_rand_u32(), exc_max - inc_min) + inc_min; } \ No newline at end of file diff --git a/source/rom_data.cpp b/source/rom_data.cpp index 970d942..924a942 100644 --- a/source/rom_data.cpp +++ b/source/rom_data.cpp @@ -30,8 +30,7 @@ bool rom_data::load_rom(bool debug) } else { - gamecode = (*(vu8 *)(0x80000AC)) << 0x10 | - (*(vu8 *)(0x80000AD)) << 0x08 | + gamecode = (*(vu8 *)(0x80000AC)) << 0x10 | (*(vu8 *)(0x80000AD)) << 0x08 | (*(vu8 *)(0x80000AE)) << 0x00; language = (*(vu8 *)(0x80000AF)); version = (*(vu8 *)(0x80000BC)); @@ -69,8 +68,8 @@ bool rom_data::load_rom(bool debug) }*/ // byte 2-4 of the compressed data store the decompressed size - rom_list_size = compressed_rom_list[1] | (compressed_rom_list[2] << 8) | - (compressed_rom_list[3] << 16); + rom_list_size = + compressed_rom_list[1] | (compressed_rom_list[2] << 8) | (compressed_rom_list[3] << 16); LZ77UnCompWram(compressed_rom_list, rom_list_buffer); cur = rom_list_buffer; @@ -79,8 +78,7 @@ bool rom_data::load_rom(bool debug) { const ROM_DATA *rom_values = reinterpret_cast(cur); if (rom_values->is_valid && rom_values->gamecode == gamecode && - rom_values->version == version && - (rom_values->entrypoint == entrypoint || debug)) + rom_values->version == version && (rom_values->entrypoint == entrypoint || debug)) { fill_values(rom_values); rom_loaded = true; @@ -105,20 +103,16 @@ void rom_data::fill_values(const ROM_DATA *rom_values) offset_wondercard = rom_values->offset_wondercard; offset_script = rom_values->offset_script; - e4_flag = rom_values->e4_flag; // The flag that is set when you become - // champion. Often listed as "GAME_CLEAR" - mg_flag = - rom_values->mg_flag; // The flag that is set when you enable Mystery - // Gift. Known as "EXDATA_ENABLE" in RS - unused_flag_start = - rom_values->unused_flag_start; // The start of the unused flags and must - // have 31 open flags in a row + e4_flag = rom_values->e4_flag; // The flag that is set when you become champion. Often listed as + // "GAME_CLEAR" + mg_flag = rom_values->mg_flag; // The flag that is set when you enable Mystery Gift. Known as + // "EXDATA_ENABLE" in RS + unused_flag_start = rom_values->unused_flag_start; // The start of the unused flags and must + // have 31 open flags in a row all_collected_flag = - rom_values->unused_flag_start; // The flag for if everything has been - // collected + rom_values->unused_flag_start; // The flag for if everything has been collected pkmn_collected_flag_start = - rom_values->unused_flag_start + - 1; // The beginning of the flags for each of the Pokemon + rom_values->unused_flag_start + 1; // The beginning of the flags for each of the Pokemon map_bank = rom_values->map_bank; map_id = rom_values->map_id; @@ -131,14 +125,10 @@ void rom_data::fill_values(const ROM_DATA *rom_values) bool rom_data::is_hoenn() { - return (gamecode == RUBY_ID || gamecode == SAPPHIRE_ID || - gamecode == EMERALD_ID); + return (gamecode == RUBY_ID || gamecode == SAPPHIRE_ID || gamecode == EMERALD_ID); } -bool rom_data::is_ruby_sapphire() -{ - return (gamecode == RUBY_ID || gamecode == SAPPHIRE_ID); -} +bool rom_data::is_ruby_sapphire() { return (gamecode == RUBY_ID || gamecode == SAPPHIRE_ID); } void rom_data::print_rom_info() { @@ -166,8 +156,7 @@ void rom_data::print_rom_info() break; } - npf_snprintf( - buffer, sizeof(buffer), "%c-%d-%c", gameTypeChar, version, language); + npf_snprintf(buffer, sizeof(buffer), "%c-%d-%c", gameTypeChar, version, language); ptgb_write_simple(reinterpret_cast(buffer), true); } @@ -176,9 +165,7 @@ bool rom_data::verify_rom() { // This should really be replaced with a "cart pulled" interrupt return !rom_loaded || g_debug_options.ignore_game_pak || - ((gamecode == - ((*(vu8 *)(0x80000AC)) << 0x10 | (*(vu8 *)(0x80000AD)) << 0x08 | - (*(vu8 *)(0x80000AE)) << 0x00)) && - (language == (*(vu8 *)(0x80000AF))) && - (version == (*(vu8 *)(0x80000BC)))); + ((gamecode == ((*(vu8 *)(0x80000AC)) << 0x10 | (*(vu8 *)(0x80000AD)) << 0x08 | + (*(vu8 *)(0x80000AE)) << 0x00)) && + (language == (*(vu8 *)(0x80000AF))) && (version == (*(vu8 *)(0x80000BC)))); } \ No newline at end of file diff --git a/source/script_array.cpp b/source/script_array.cpp index b08aacd..40fefc2 100644 --- a/source/script_array.cpp +++ b/source/script_array.cpp @@ -110,7 +110,8 @@ Box_Menu box_viewer; // values So if adding a new dia, command or condition, make sure to add it in // the right position/index. defining it this way does not generate an expensive // function. It's all stored as read-only data in EWRAM. -const script_obj_params transfer_script_params[SCRIPT_SIZE] = {// PTGB_DIA_OPEN +const script_obj_params transfer_script_params[SCRIPT_SIZE] = { + // PTGB_DIA_OPEN {.text_entry_index = PTGB_DIA_OPEN, .next_if_true = CMD_SET_TUTOR_TRUE}, // PTGB_DIA_E4 {.text_entry_index = PTGB_DIA_E4, .next_if_true = CMD_END_SCRIPT}, @@ -129,92 +130,67 @@ const script_obj_params transfer_script_params[SCRIPT_SIZE] = {// PTGB_DIA_OPEN // PTGB_DIA_NO_NEW_DEX {.text_entry_index = PTGB_DIA_NO_NEW_DEX, .next_if_true = COND_IS_HOENN_RS}, // PTGB_DIA_SEND_FRIEND_KANTO - {.text_entry_index = PTGB_DIA_SEND_FRIEND_KANTO, - .next_if_true = PTGB_DIA_THANK}, + {.text_entry_index = PTGB_DIA_SEND_FRIEND_KANTO, .next_if_true = PTGB_DIA_THANK}, // PTGB_DIA_SEND_FRIEND_HOENN_RS - {.text_entry_index = PTGB_DIA_SEND_FRIEND_HOENN_RS, - .next_if_true = PTGB_DIA_THANK}, + {.text_entry_index = PTGB_DIA_SEND_FRIEND_HOENN_RS, .next_if_true = PTGB_DIA_THANK}, // PTGB_DIA_SEND_FRIEND_HOENN_E - {.text_entry_index = PTGB_DIA_SEND_FRIEND_HOENN_E, - .next_if_true = PTGB_DIA_THANK}, + {.text_entry_index = PTGB_DIA_SEND_FRIEND_HOENN_E, .next_if_true = PTGB_DIA_THANK}, // PTGB_DIA_THANK {.text_entry_index = PTGB_DIA_THANK, .next_if_true = CMD_END_SCRIPT}, // PTGB_DIA_GET_MON (unused) {.text_entry_index = PTGB_DIA_GET_MON, .next_if_true = CMD_END_SCRIPT}, // PTGB_DIA_MG_OTHER_EVENT - {.text_entry_index = PTGB_DIA_MG_OTHER_EVENT, - .next_if_true = PTGB_DIA_LETS_START}, + {.text_entry_index = PTGB_DIA_MG_OTHER_EVENT, .next_if_true = PTGB_DIA_LETS_START}, // PTGB_DIA_PKMN_TO_COLLECT - {.text_entry_index = PTGB_DIA_PKMN_TO_COLLECT, - .next_if_true = CMD_END_SCRIPT}, + {.text_entry_index = PTGB_DIA_PKMN_TO_COLLECT, .next_if_true = CMD_END_SCRIPT}, // PTGB_DIA_NO_VALID_PKMN - {.text_entry_index = PTGB_DIA_NO_VALID_PKMN, - .next_if_true = CMD_CANCEL_LINK}, + {.text_entry_index = PTGB_DIA_NO_VALID_PKMN, .next_if_true = CMD_CANCEL_LINK}, // PTGB_DIA_ASK_QUEST - {.text_entry_index = PTGB_DIA_ASK_QUEST, - .next_if_true = CMD_SLIDE_PROF_LEFT}, + {.text_entry_index = PTGB_DIA_ASK_QUEST, .next_if_true = CMD_SLIDE_PROF_LEFT}, // PTGB_DIA_WHAT_GAME_TRANS - {.text_entry_index = PTGB_DIA_WHAT_GAME_TRANS, - .next_if_true = CMD_GAME_MENU}, + {.text_entry_index = PTGB_DIA_WHAT_GAME_TRANS, .next_if_true = CMD_GAME_MENU}, // PTGB_DIA_WHAT_LANG_TRANS - {.text_entry_index = PTGB_DIA_WHAT_LANG_TRANS, - .next_if_true = CMD_LANG_MENU}, + {.text_entry_index = PTGB_DIA_WHAT_LANG_TRANS, .next_if_true = CMD_LANG_MENU}, // PTGB_DIA_NO_GB_ROM - {.text_entry_index = PTGB_DIA_NO_GB_ROM, - .next_if_true = PTGB_DIA_WHAT_LANG_TRANS}, + {.text_entry_index = PTGB_DIA_NO_GB_ROM, .next_if_true = PTGB_DIA_WHAT_LANG_TRANS}, // PTGB_DIA_IN_BOX {.text_entry_index = PTGB_DIA_IN_BOX, .next_if_true = CMD_BOX_MENU}, // PTGB_DIA_MYTHIC_CONVERT - {.text_entry_index = PTGB_DIA_MYTHIC_CONVERT, - .next_if_true = CMD_MYTHIC_MENU}, + {.text_entry_index = PTGB_DIA_MYTHIC_CONVERT, .next_if_true = CMD_MYTHIC_MENU}, // PTGB_DIA_CANCEL {.text_entry_index = PTGB_DIA_CANCEL, .next_if_true = CMD_CANCEL_LINK}, // PTGB_DIA_SOME_INVALID_PKMN - {.text_entry_index = PTGB_DIA_SOME_INVALID_PKMN, - .next_if_true = COND_CHECK_MYTHIC}, + {.text_entry_index = PTGB_DIA_SOME_INVALID_PKMN, .next_if_true = COND_CHECK_MYTHIC}, // PTGB_DIA_MENU_BACK {.text_entry_index = PTGB_DIA_MENU_BACK, .next_if_true = CMD_END_SCRIPT}, // PTGB_DIA_IS_MISSINGNO - {.text_entry_index = PTGB_DIA_IS_MISSINGNO, - .next_if_true = PTGB_DIA_IN_BOX}, + {.text_entry_index = PTGB_DIA_IS_MISSINGNO, .next_if_true = PTGB_DIA_IN_BOX}, // PTGB_DIA_ERROR_COLOSSEUM - {.text_entry_index = PTGB_DIA_ERROR_COLOSSEUM, - .next_if_true = PTGB_DIA_START}, + {.text_entry_index = PTGB_DIA_ERROR_COLOSSEUM, .next_if_true = PTGB_DIA_START}, // PTGB_DIA_ERROR_COM_ENDED - {.text_entry_index = PTGB_DIA_ERROR_COM_ENDED, - .next_if_true = PTGB_DIA_START}, + {.text_entry_index = PTGB_DIA_ERROR_COM_ENDED, .next_if_true = PTGB_DIA_START}, // PTGB_DIA_ERROR_DISCONNECT - {.text_entry_index = PTGB_DIA_ERROR_DISCONNECT, - .next_if_true = PTGB_DIA_START}, + {.text_entry_index = PTGB_DIA_ERROR_DISCONNECT, .next_if_true = PTGB_DIA_START}, // PTGB_DIA_ERROR_TIME_ONE - {.text_entry_index = PTGB_DIA_ERROR_TIME_ONE, - .next_if_true = PTGB_DIA_START}, + {.text_entry_index = PTGB_DIA_ERROR_TIME_ONE, .next_if_true = PTGB_DIA_START}, // PTGB_DIA_ERROR_TIME_TWO - {.text_entry_index = PTGB_DIA_ERROR_TIME_TWO, - .next_if_true = PTGB_DIA_START}, + {.text_entry_index = PTGB_DIA_ERROR_TIME_TWO, .next_if_true = PTGB_DIA_START}, // PTGB_DIA_WHAT_LANG_EVENT - {.text_entry_index = PTGB_DIA_WHAT_LANG_EVENT, - .next_if_true = CMD_LANG_MENU}, + {.text_entry_index = PTGB_DIA_WHAT_LANG_EVENT, .next_if_true = CMD_LANG_MENU}, // PTGB_DIA_WHAT_GAME_EVENT - {.text_entry_index = PTGB_DIA_WHAT_GAME_EVENT, - .next_if_true = CMD_GAME_MENU}, + {.text_entry_index = PTGB_DIA_WHAT_GAME_EVENT, .next_if_true = CMD_GAME_MENU}, // PTGB_DIA_K_DEX_NOT_FULL - {.text_entry_index = PTGB_DIA_K_DEX_NOT_FULL, - .next_if_true = CMD_END_SCRIPT}, + {.text_entry_index = PTGB_DIA_K_DEX_NOT_FULL, .next_if_true = CMD_END_SCRIPT}, // PTGB_DIA_J_DEX_NOT_FULL - {.text_entry_index = PTGB_DIA_J_DEX_NOT_FULL, - .next_if_true = CMD_END_SCRIPT}, + {.text_entry_index = PTGB_DIA_J_DEX_NOT_FULL, .next_if_true = CMD_END_SCRIPT}, // T_SCRIPT_START - {.conditional_index = CMD_SHOW_PROF, - .next_if_true = COND_TUTORIAL_COMPLETE}, + {.conditional_index = CMD_SHOW_PROF, .next_if_true = COND_TUTORIAL_COMPLETE}, // E_SCRIPT_START {.conditional_index = CMD_SHOW_PROF, .next_if_true = PTGB_DIA_LETS_START}, // CMD_START_LINK - {.conditional_index = CMD_START_LINK, - .next_if_true = COND_ERROR_TIMEOUT_ONE}, + {.conditional_index = CMD_START_LINK, .next_if_true = COND_ERROR_TIMEOUT_ONE}, // CMD_IMPORT_POKEMON - {.conditional_index = CMD_IMPORT_POKEMON, - .next_if_true = CMD_CONTINUE_LINK}, + {.conditional_index = CMD_IMPORT_POKEMON, .next_if_true = CMD_CONTINUE_LINK}, // CMD_BACK_TO_MENU {.conditional_index = CMD_BACK_TO_MENU, .next_if_true = T_SCRIPT_START}, // CMD_SHOW_PROF (unused in this manner (not used in a next_if_true). @@ -238,11 +214,9 @@ const script_obj_params transfer_script_params[SCRIPT_SIZE] = {// PTGB_DIA_OPEN .next_if_true = PTGB_DIA_WHAT_GAME_TRANS, .next_if_false = PTGB_DIA_CANCEL}, // CMD_SLIDE_PROF_LEFT - {.conditional_index = CMD_SLIDE_PROF_LEFT, - .next_if_true = PTGB_DIA_WHAT_LANG_TRANS}, + {.conditional_index = CMD_SLIDE_PROF_LEFT, .next_if_true = PTGB_DIA_WHAT_LANG_TRANS}, // CMD_SLIDE_PROF_RIGHT - {.conditional_index = CMD_SLIDE_PROF_RIGHT, - .next_if_true = PTGB_DIA_LETS_START}, + {.conditional_index = CMD_SLIDE_PROF_RIGHT, .next_if_true = PTGB_DIA_LETS_START}, // CMD_CONTINUE_LINK {.conditional_index = CMD_CONTINUE_LINK, .next_if_true = CMD_END_MISSINGNO}, // CMD_BOX_MENU @@ -250,8 +224,7 @@ const script_obj_params transfer_script_params[SCRIPT_SIZE] = {// PTGB_DIA_OPEN .next_if_true = CMD_IMPORT_POKEMON, .next_if_false = PTGB_DIA_CANCEL}, // CMD_MYTHIC_MENU - {.conditional_index = CMD_MYTHIC_MENU, - .next_if_true = COND_CHECK_MISSINGNO}, + {.conditional_index = CMD_MYTHIC_MENU, .next_if_true = COND_CHECK_MISSINGNO}, // CMD_IS_A_VALID_PKMN {.conditional_index = CMD_IS_A_VALID_PKMN, .next_if_true = COND_SOME_INVALID_PKMN, @@ -259,8 +232,7 @@ const script_obj_params transfer_script_params[SCRIPT_SIZE] = {// PTGB_DIA_OPEN // CMD_CANCEL_LINK {.conditional_index = CMD_CANCEL_LINK, .next_if_true = CMD_END_SCRIPT}, // CMD_END_MISSINGNO - {.conditional_index = CMD_END_MISSINGNO, - .next_if_true = PTGB_DIA_TRANS_GOOD}, + {.conditional_index = CMD_END_MISSINGNO, .next_if_true = PTGB_DIA_TRANS_GOOD}, // COND_ERROR_TIMEOUT_ONE {.conditional_index = COND_ERROR_TIMEOUT_ONE, .next_if_true = COND_ERROR_TIMEOUT_TWO, @@ -322,9 +294,7 @@ const script_obj_params transfer_script_params[SCRIPT_SIZE] = {// PTGB_DIA_OPEN .next_if_true = PTGB_DIA_MYTHIC_CONVERT, .next_if_false = COND_CHECK_MISSINGNO}, // COND_CHECK_DEX - {.conditional_index = COND_CHECK_DEX, - .next_if_true = 0, - .next_if_false = COND_CHECK_KANTO}, + {.conditional_index = COND_CHECK_DEX, .next_if_true = 0, .next_if_false = COND_CHECK_KANTO}, // COND_CHECK_KANTO {.conditional_index = COND_CHECK_KANTO, .next_if_true = PTGB_DIA_K_DEX_NOT_FULL, @@ -396,13 +366,11 @@ const script_obj_params event_script_params[SCRIPT_SIZE] = { {}, // PTGB_DIA_PKMN_TO_COLLECT {}, // PTGB_DIA_NO_VALID_PKMN // PTGB_DIA_ASK_QUEST - {.text_entry_index = PTGB_DIA_ASK_QUEST, - .next_if_true = CMD_SLIDE_PROF_LEFT}, + {.text_entry_index = PTGB_DIA_ASK_QUEST, .next_if_true = CMD_SLIDE_PROF_LEFT}, {}, // PTGB_DIA_WHAT_GAME_TRANS {}, // PTGB_DIA_WHAT_LANG_TRANS // PTGB_DIA_NO_GB_ROM - {.text_entry_index = PTGB_DIA_NO_GB_ROM, - .next_if_true = PTGB_DIA_WHAT_LANG_EVENT}, + {.text_entry_index = PTGB_DIA_NO_GB_ROM, .next_if_true = PTGB_DIA_WHAT_LANG_EVENT}, {}, // PTGB_DIA_IN_BOX {}, // PTGB_DIA_MYTHIC_CONVERT {}, // PTGB_DIA_CANCEL @@ -415,26 +383,20 @@ const script_obj_params event_script_params[SCRIPT_SIZE] = { {}, // PTGB_DIA_ERROR_TIME_ONE {}, // PTGB_DIA_ERROR_TIME_TWO // PTGB_DIA_WHAT_LANG_EVENT - {.text_entry_index = PTGB_DIA_WHAT_LANG_EVENT, - .next_if_true = CMD_LANG_MENU}, + {.text_entry_index = PTGB_DIA_WHAT_LANG_EVENT, .next_if_true = CMD_LANG_MENU}, // PTGB_DIA_WHAT_GAME_EVENT - {.text_entry_index = PTGB_DIA_WHAT_GAME_EVENT, - .next_if_true = CMD_GAME_MENU}, + {.text_entry_index = PTGB_DIA_WHAT_GAME_EVENT, .next_if_true = CMD_GAME_MENU}, // PTGB_DIA_K_DEX_NOT_FULL - {.text_entry_index = PTGB_DIA_K_DEX_NOT_FULL, - .next_if_true = CMD_END_SCRIPT}, + {.text_entry_index = PTGB_DIA_K_DEX_NOT_FULL, .next_if_true = CMD_END_SCRIPT}, // PTGB_DIA_J_DEX_NOT_FULL - {.text_entry_index = PTGB_DIA_J_DEX_NOT_FULL, - .next_if_true = CMD_END_SCRIPT}, + {.text_entry_index = PTGB_DIA_J_DEX_NOT_FULL, .next_if_true = CMD_END_SCRIPT}, {}, // T_SCRIPT_START // E_SCRIPT_START - {.conditional_index = CMD_SHOW_PROF, .next_if_true = PTGB_DIA_ASK_QUEST}, - {}, // CMD_START_LINK + {.conditional_index = CMD_SHOW_PROF, .next_if_true = PTGB_DIA_ASK_QUEST}, {}, // CMD_START_LINK {}, // CMD_IMPORT_POKEMON // CMD_BACK_TO_MENU - {.conditional_index = CMD_BACK_TO_MENU, .next_if_true = T_SCRIPT_START}, - {}, // CMD_SHOW_PROF - {}, // CMD_HIDE_PROF + {.conditional_index = CMD_BACK_TO_MENU, .next_if_true = T_SCRIPT_START}, {}, // CMD_SHOW_PROF + {}, // CMD_HIDE_PROF {}, // CMD_SET_TUTOR_TRUE // CMD_END_SCRIPT {.conditional_index = CMD_END_SCRIPT, .next_if_true = CMD_BACK_TO_MENU}, @@ -443,11 +405,9 @@ const script_obj_params event_script_params[SCRIPT_SIZE] = { .next_if_true = COND_GB_ROM_EXISTS, .next_if_false = PTGB_DIA_WHAT_LANG_EVENT}, // CMD_LANG_MENU - {.conditional_index = CMD_LANG_MENU, - .next_if_true = PTGB_DIA_WHAT_GAME_EVENT}, + {.conditional_index = CMD_LANG_MENU, .next_if_true = PTGB_DIA_WHAT_GAME_EVENT}, // CMD_SLIDE_PROF_LEFT - {.conditional_index = CMD_SLIDE_PROF_LEFT, - .next_if_true = PTGB_DIA_WHAT_LANG_EVENT}, + {.conditional_index = CMD_SLIDE_PROF_LEFT, .next_if_true = PTGB_DIA_WHAT_LANG_EVENT}, // CMD_SLIDE_PROF_RIGHT {.conditional_index = CMD_SLIDE_PROF_RIGHT, .next_if_true = COND_CHECK_DEX}, {}, // CMD_CONTINUE_LINK @@ -475,9 +435,7 @@ const script_obj_params event_script_params[SCRIPT_SIZE] = { .next_if_false = PTGB_DIA_NO_GB_ROM}, {}, // COND_CHECK_MYTHIC // COND_CHECK_DEX - {.conditional_index = COND_CHECK_DEX, - .next_if_true = 0, - .next_if_false = COND_CHECK_KANTO}, + {.conditional_index = COND_CHECK_DEX, .next_if_true = 0, .next_if_false = COND_CHECK_KANTO}, // COND_CHECK_KANTO {.conditional_index = COND_CHECK_KANTO, .next_if_true = PTGB_DIA_K_DEX_NOT_FULL, @@ -534,12 +492,10 @@ bool run_conditional(int index) return globalLinkCable.lastError != COND_ERROR_COLOSSEUM; case COND_BEAT_E4: - return read_flag(curr_GBA_rom.e4_flag) || - g_debug_options.ignore_mg_e4_flags; + return read_flag(curr_GBA_rom.e4_flag) || g_debug_options.ignore_mg_e4_flags; case COND_MG_ENABLED: - return read_flag(curr_GBA_rom.mg_flag) || - g_debug_options.ignore_mg_e4_flags; + return read_flag(curr_GBA_rom.mg_flag) || g_debug_options.ignore_mg_e4_flags; case COND_TUTORIAL_COMPLETE: return get_tutorial_flag() && !g_debug_options.force_tutorial; @@ -555,13 +511,13 @@ bool run_conditional(int index) return !curr_GBA_rom.is_ruby_sapphire(); case COND_MG_OTHER_EVENT: - return compare_map_and_npc_data(curr_GBA_rom.def_map_bank, - curr_GBA_rom.def_map_id, curr_GBA_rom.def_npc_id) && + return compare_map_and_npc_data( + curr_GBA_rom.def_map_bank, curr_GBA_rom.def_map_id, curr_GBA_rom.def_npc_id) && !g_debug_options.ignore_mg_e4_flags; case COND_PKMN_TO_COLLECT: - return compare_map_and_npc_data(curr_GBA_rom.map_bank, - curr_GBA_rom.map_id, curr_GBA_rom.npc_id) && + return compare_map_and_npc_data( + curr_GBA_rom.map_bank, curr_GBA_rom.map_id, curr_GBA_rom.npc_id) && !read_flag(curr_GBA_rom.all_collected_flag) && !g_debug_options.ignore_unreceived_pkmn; @@ -574,13 +530,11 @@ bool run_conditional(int index) case COND_CHECK_DEX: if (globalLinkCable.gen == 1) { - return (get_dex_completion(1, false) == 150) || - g_debug_options.ignore_dex_completion; + return (get_dex_completion(1, false) == 150) || g_debug_options.ignore_dex_completion; } else { - return (get_dex_completion(1, false) == 99) || - g_debug_options.ignore_dex_completion; + return (get_dex_completion(1, false) == 99) || g_debug_options.ignore_dex_completion; } case COND_CHECK_KANTO: @@ -619,17 +573,13 @@ bool run_conditional(int index) u32 numChunks; u32 chunkSize; - get_text_table_chunks( - GENERAL_INDEX, &chunkList, &numChunks, &chunkSize); + get_text_table_chunks(GENERAL_INDEX, &chunkList, &numChunks, &chunkSize); - FileContainerReader general_text_reader( - chunkList, numChunks, chunkSize); - general_text_reader.init( - general_text_table_buffer, sizeof(general_text_table_buffer)); + FileContainerReader general_text_reader(chunkList, numChunks, chunkSize); + general_text_reader.init(general_text_table_buffer, sizeof(general_text_table_buffer)); general_text_reader.readFile(GENERAL_connecting, lineBuffer); - ptgb_write_textbox(lineBuffer, true, false, GENERAL_INDEX, - GENERAL_connecting, false); + ptgb_write_textbox(lineBuffer, true, false, GENERAL_INDEX, GENERAL_connecting, false); load_select_sprites(NO_GB_ROM); obj_unhide(gba_cart, 0); @@ -651,22 +601,19 @@ bool run_conditional(int index) globalLinkCable.LinkCommand_InitalizeConnection(false); while (globalLinkCable.exitState != END) { - if (globalLinkCable.subStateChanged && - !g_debug_options.print_link_data) + if (globalLinkCable.subStateChanged && !g_debug_options.print_link_data) { switch (globalLinkCable.exitState) { case SAVE_SUCCESS: - general_text_reader.readFile( - GENERAL_link_success, lineBuffer); - ptgb_write_textbox(lineBuffer, true, false, - GENERAL_INDEX, GENERAL_link_success, false); + general_text_reader.readFile(GENERAL_link_success, lineBuffer); + ptgb_write_textbox( + lineBuffer, true, false, GENERAL_INDEX, GENERAL_link_success, false); break; case TRADE_PREAMBLE: - general_text_reader.readFile( - GENERAL_transferring, lineBuffer); - ptgb_write_textbox(lineBuffer, true, false, - GENERAL_INDEX, GENERAL_transferring, false); + general_text_reader.readFile(GENERAL_transferring, lineBuffer); + ptgb_write_textbox( + lineBuffer, true, false, GENERAL_INDEX, GENERAL_transferring, false); break; default: break; @@ -695,16 +642,13 @@ bool run_conditional(int index) obj_set_pos(gb_flag, 1.5 * 8, 14 * 8); globalLinkCable.LinkCommand_ReadMemorySection( - globalLinkCable.pccsROMptr->wCurrentBoxNum, - &globalLinkCable.boxNum, 1); + globalLinkCable.pccsROMptr->wCurrentBoxNum, &globalLinkCable.boxNum, 1); byte boxDataArray[globalLinkCable.pccsROMptr->box_data_size]; - globalLinkCable.LinkCommand_ReadMemorySection( - globalLinkCable.pccsROMptr->wBoxDataStart, boxDataArray, - globalLinkCable.pccsROMptr->box_data_size); + globalLinkCable.LinkCommand_ReadMemorySection(globalLinkCable.pccsROMptr->wBoxDataStart, + boxDataArray, globalLinkCable.pccsROMptr->box_data_size); - box.loadData( - globalLinkCable.gen, globalLinkCable.lang, boxDataArray); + box.loadData(globalLinkCable.gen, globalLinkCable.lang, boxDataArray); } reload_textbox_background(); load_flex_background(FBG_Fennel, 2); @@ -786,8 +730,7 @@ bool run_conditional(int index) if (box.getGen3Pokemon(i)->isValid) { box.removePokemon(i); - if (!(DONT_TRANSFER_POKEMON_AT_INDEX_X && - i == POKEMON_INDEX_TO_SKIP)) + if (!(DONT_TRANSFER_POKEMON_AT_INDEX_X && i == POKEMON_INDEX_TO_SKIP)) { boxRemovalPayload[arrayIndex] = i; arrayIndex++; @@ -803,8 +746,7 @@ bool run_conditional(int index) case CMD_BOX_MENU: hide_textbox(); - ret = - (box_viewer.box_main(&box, globalLinkCable.vers) == CONFIRM_BUTTON); + ret = (box_viewer.box_main(&box, globalLinkCable.vers) == CONFIRM_BUTTON); show_textbox(); return ret; diff --git a/source/script_obj.cpp b/source/script_obj.cpp index 6ecaa85..08c30d3 100644 --- a/source/script_obj.cpp +++ b/source/script_obj.cpp @@ -6,11 +6,11 @@ script_obj::script_obj(const script_obj_params ¶ms) : params_(params) {} bool script_obj::has_text() const { - // So the thing is: when conditional_index is set, its value will always be - // higher than 0 because the way these integer defines have been set up. So - // that means that if conditional_index IS 0, then we must have a text entry - // index defined instead! We can't base this check on the text_entry_index - // itself since unfortunately its value being zero can be legit. + // So the thing is: when conditional_index is set, its value will always be higher than 0 + // because the way these integer defines have been set up. + // So that means that if conditional_index IS 0, then we must have a text entry index defined + // instead! We can't base this check on the text_entry_index itself since unfortunately its + // value being zero can be legit. return (params_.conditional_index == 0); } diff --git a/source/select_menu.cpp b/source/select_menu.cpp index 940cd8e..dd0a8b0 100644 --- a/source/select_menu.cpp +++ b/source/select_menu.cpp @@ -8,11 +8,10 @@ #define TILE_HEIGHT 8 #define TILE_WIDTH 8 -Select_Menu::Select_Menu(bool enable_cancel, u8 nMenu_type, - unsigned nStartTileX, unsigned nStartTileY) +Select_Menu::Select_Menu( + bool enable_cancel, u8 nMenu_type, unsigned nStartTileX, unsigned nStartTileY) : vertical_menu_cursor_handler(TEXT_WIDTH, 3), - menu_widget_(vertical_menu_settings{ - .x = static_cast(nStartTileX * TILE_WIDTH), + menu_widget_(vertical_menu_settings{.x = static_cast(nStartTileX * TILE_WIDTH), .y = static_cast(nStartTileY * TILE_HEIGHT), .width = 10 * TEXT_WIDTH, .height = TILE_HEIGHT * 2, // to account for the margins @@ -33,9 +32,7 @@ Select_Menu::Select_Menu(bool enable_cancel, u8 nMenu_type, void Select_Menu::add_option(const u8 option, u8 return_value) { const simple_item_widget_data item_data = { - .text = {.text_table_index = option, - .margin_left = 2 * TILE_WIDTH, - .margin_top = 0}, + .text = {.text_table_index = option, .margin_left = 2 * TILE_WIDTH, .margin_top = 0}, .value = return_value, .on_execute_callback = nullptr}; menu_widget_.add_item_widget(new simple_item_renderer(item_data)); @@ -65,8 +62,7 @@ int Select_Menu::select_menu_main() if (choice_index != UINT32_MAX) { - widget = static_cast( - menu_widget_.get_item_widget_at(choice_index)); + widget = static_cast(menu_widget_.get_item_widget_at(choice_index)); } item_value = (widget) ? widget->get_data().value : UINT8_MAX; @@ -87,14 +83,13 @@ void Select_Menu::on_hide() obj_hide(gb_flag); } -void Select_Menu::on_selection_changed( - unsigned new_index, unsigned x, unsigned y) +void Select_Menu::on_selection_changed(unsigned new_index, unsigned x, unsigned y) { // call the base implementation to move the cursor vertical_menu_cursor_handler::on_selection_changed(new_index, x, y); - simple_item_renderer *widget = static_cast( - menu_widget_.get_item_widget_at(new_index)); + simple_item_renderer *widget = + static_cast(menu_widget_.get_item_widget_at(new_index)); const unsigned item_value = (widget) ? widget->get_data().value : UINT8_MAX; if (item_value == UINT8_MAX) diff --git a/source/sprite_data.cpp b/source/sprite_data.cpp index 66d7fbe..242694b 100644 --- a/source/sprite_data.cpp +++ b/source/sprite_data.cpp @@ -23,12 +23,11 @@ void load_background() // Load palette tonccpy(pal_bg_mem, backgroundPal, backgroundPalLen); // Load tiles into CBB 0 - LZ77UnCompVram( - backgroundTiles, &tile_mem[TILESET_PTGB][TILESET_OFFSET_BACKDROP]); + LZ77UnCompVram(backgroundTiles, &tile_mem[TILESET_PTGB][TILESET_OFFSET_BACKDROP]); // Load map into SBB 0 LZ77UnCompVram(backgroundMap, &se_mem[TILEMAP_BACKDROP][0]); - BG_BACKDROP = BG_CBB(TILESET_PTGB) | BG_SBB(TILEMAP_BACKDROP) | BG_4BPP | - BG_REG_32x32 | BG_PRIO(3); + BG_BACKDROP = + BG_CBB(TILESET_PTGB) | BG_SBB(TILEMAP_BACKDROP) | BG_4BPP | BG_REG_32x32 | BG_PRIO(3); } void set_background_pal(int curr_rom_id, bool dark, bool fade) @@ -98,16 +97,15 @@ void set_background_pal(int curr_rom_id, bool dark, bool fade) old_pal[b] = (curr_pal_bg[i] >> (b * 5)) & 0b11111; new_pal[b] = (new_pal_bg[i] >> (b * 5)) & 0b11111; } - pal_bg_mem[i] = - RGB15(((((NUM_CYCLES - n) * INV_NUM_CYCLES) * old_pal[0]) + - ((n * INV_NUM_CYCLES) * new_pal[0])) >> - 16, - ((((NUM_CYCLES - n) * INV_NUM_CYCLES) * old_pal[1]) + - ((n * INV_NUM_CYCLES) * new_pal[1])) >> - 16, - ((((NUM_CYCLES - n) * INV_NUM_CYCLES) * old_pal[2]) + - ((n * INV_NUM_CYCLES) * new_pal[2])) >> - 16); + pal_bg_mem[i] = RGB15(((((NUM_CYCLES - n) * INV_NUM_CYCLES) * old_pal[0]) + + ((n * INV_NUM_CYCLES) * new_pal[0])) >> + 16, + ((((NUM_CYCLES - n) * INV_NUM_CYCLES) * old_pal[1]) + + ((n * INV_NUM_CYCLES) * new_pal[1])) >> + 16, + ((((NUM_CYCLES - n) * INV_NUM_CYCLES) * old_pal[2]) + + ((n * INV_NUM_CYCLES) * new_pal[2])) >> + 16); } VBlankIntrWait(); } @@ -257,8 +255,7 @@ void load_flex_background(FlexBackground background_id, int layer) #endif tonccpy(pal_bg_mem + 32, flex->palette, flex->palette_len); // Load tiles - LZ77UnCompVram( - flex->tileset, &tile_mem[TILESET_PTGB][TILESET_OFFSET_FLEXBG]); + LZ77UnCompVram(flex->tileset, &tile_mem[TILESET_PTGB][TILESET_OFFSET_FLEXBG]); // Give it a frame to uncompress the data global_next_frame(); // Load map into the tilemap @@ -267,8 +264,8 @@ void load_flex_background(FlexBackground background_id, int layer) REG_BG1VOFS = flex->voffset; } - BG_FLEX = BG_CBB(TILESET_PTGB) | BG_SBB(TILEMAP_FLEXBG) | BG_4BPP | - BG_REG_32x32 | BG_PRIO(layer); + BG_FLEX = + BG_CBB(TILESET_PTGB) | BG_SBB(TILEMAP_FLEXBG) | BG_4BPP | BG_REG_32x32 | BG_PRIO(layer); curr_flex_background = background_id; } #include "textBoxBG.h" @@ -277,20 +274,16 @@ void load_textbox_background() // Load palette tonccpy(pal_bg_mem + 16, textBoxBGPal, textBoxBGPalLen); // Load tiles into CBB 0 - LZ77UnCompVram( - textBoxBGTiles, &tile_mem[TILESET_PTGB][TILESET_OFFSET_TEXTBOX]); + LZ77UnCompVram(textBoxBGTiles, &tile_mem[TILESET_PTGB][TILESET_OFFSET_TEXTBOX]); // Load map into SBB 0 reload_textbox_background(); REG_BG2VOFS = 96; - BG_TEXTBOX = BG_CBB(TILESET_PTGB) | BG_SBB(TILEMAP_TEXTBOX) | BG_4BPP | - BG_REG_32x32 | BG_PRIO(3); + BG_TEXTBOX = + BG_CBB(TILESET_PTGB) | BG_SBB(TILEMAP_TEXTBOX) | BG_4BPP | BG_REG_32x32 | BG_PRIO(3); } -void reload_textbox_background() -{ - LZ77UnCompVram(textBoxBGMap, &se_mem[TILEMAP_TEXTBOX][0]); -} +void reload_textbox_background() { LZ77UnCompVram(textBoxBGMap, &se_mem[TILEMAP_TEXTBOX][0]); } // tile ID, VH Flip, Palette Bank #define TILE_OFFSET TILESET_OFFSET_TEXTBOX @@ -326,30 +319,24 @@ void reload_textbox_background() #define MENU_WIDTH 11 - 1 // Currently static -static const u16 TILE_SE_U_ARR[4] = { - TILE_SE_0, TILE_SE_2, TILE_SE_4U, TILE_SE_6U}; +static const u16 TILE_SE_U_ARR[4] = {TILE_SE_0, TILE_SE_2, TILE_SE_4U, TILE_SE_6U}; static const u16 TILE_S_U_ARR[4] = {TILE_S_0, TILE_S_2, TILE_S_4U, TILE_S_6U}; -static const u16 TILE_SW_U_ARR[4] = { - TILE_SW_0, TILE_SW_2, TILE_SW_4U, TILE_SW_6U}; -static const u16 TILE_SE_L_ARR[4] = { - TILE_CLEAR, TILE_CLEAR, TILE_SE_4L, TILE_SE_6L}; -static const u16 TILE_S_L_ARR[4] = { - TILE_CLEAR, TILE_CLEAR, TILE_S_4L, TILE_S_6L}; -static const u16 TILE_SW_L_ARR[4] = { - TILE_CLEAR, TILE_CLEAR, TILE_SW_4L, TILE_SW_6L}; +static const u16 TILE_SW_U_ARR[4] = {TILE_SW_0, TILE_SW_2, TILE_SW_4U, TILE_SW_6U}; +static const u16 TILE_SE_L_ARR[4] = {TILE_CLEAR, TILE_CLEAR, TILE_SE_4L, TILE_SE_6L}; +static const u16 TILE_S_L_ARR[4] = {TILE_CLEAR, TILE_CLEAR, TILE_S_4L, TILE_S_6L}; +static const u16 TILE_SW_L_ARR[4] = {TILE_CLEAR, TILE_CLEAR, TILE_SW_4L, TILE_SW_6L}; void add_menu_box(int options, int startTileX, int startTileY) { add_menu_box(startTileX, startTileY, (MENU_WIDTH) * 8, (options * 10) + 16); } -// TODO: clean this mess. manual masking used for now but there is a buffer -// overflow in how the bottom row is calculated. -void add_menu_box( - int startTileX, int startTileY, int full_width, int full_height) +// TODO: clean this mess. manual masking used for now but there is a buffer overflow in how the +// bottom row is calculated. +void add_menu_box(int startTileX, int startTileY, int full_width, int full_height) { - // We can't check the current offset very easily, so we'll just assume it's - // in the text box position. + // We can't check the current offset very easily, so we'll just assume it's in the text box + // position. startTileY += 12; int start = (32 * startTileY) + startTileX; @@ -360,10 +347,8 @@ void add_menu_box( // Corners se_mem[TILEMAP_TEXTBOX][start] = TILE_NW; se_mem[TILEMAP_TEXTBOX][start + full_width] = TILE_NE; - se_mem[TILEMAP_TEXTBOX][(start + (32 * (tiles))) & 0x3ff] = - TILE_SW_U_ARR[vert_rem / 2]; - se_mem[TILEMAP_TEXTBOX][(start + (32 * (tiles + 1))) & 0x3ff] = - TILE_SW_L_ARR[vert_rem / 2]; + se_mem[TILEMAP_TEXTBOX][(start + (32 * (tiles))) & 0x3ff] = TILE_SW_U_ARR[vert_rem / 2]; + se_mem[TILEMAP_TEXTBOX][(start + (32 * (tiles + 1))) & 0x3ff] = TILE_SW_L_ARR[vert_rem / 2]; se_mem[TILEMAP_TEXTBOX][(start + (32 * (tiles)) + full_width) & 0x3ff] = TILE_SE_U_ARR[vert_rem / 2]; se_mem[TILEMAP_TEXTBOX][(start + (32 * (tiles + 1)) + full_width) & 0x3ff] = @@ -382,8 +367,7 @@ void add_menu_box( // Sides for (int i = 1; i < tiles; i++) { - se_mem[TILEMAP_TEXTBOX][(start + (32 * i) + full_width) & 0x3ff] = - TILE_E; + se_mem[TILEMAP_TEXTBOX][(start + (32 * i) + full_width) & 0x3ff] = TILE_E; se_mem[TILEMAP_TEXTBOX][(start + (32 * i)) & 0x3ff] = TILE_W; } @@ -400,8 +384,8 @@ void add_menu_box( void erase_textbox_tiles() { - // We can't check the current offset very easily, so we'll just assume it's - // in the text box position. + // We can't check the current offset very easily, so we'll just assume it's in the text box + // position. int startTileY = 12; int start = (32 * startTileY); @@ -511,11 +495,9 @@ OBJ_ATTR *grabbed_front_sprite = &obj_buffer[num_sprites++]; u32 global_tile_id_end = 0; -inline void BitUnPack( - const void *src, void *dst, uint16_t len, uint8_t from, uint8_t to) +inline void BitUnPack(const void *src, void *dst, uint16_t len, uint8_t from, uint8_t to) { - BUP bupInfo = { - .src_len = len, .src_bpp = from, .dst_bpp = to, .dst_ofs = 0}; + BUP bupInfo = {.src_len = len, .src_bpp = from, .dst_bpp = to, .dst_ofs = 0}; BitUnPack(src, dst, &bupInfo); } @@ -525,58 +507,56 @@ void load_eternal_sprites() tonccpy(pal_obj_mem + (BTN_LIT_PAL * 16), button_yesPal, button_yesPalLen); tonccpy(pal_obj_mem + (LOGO_PAL * 16), ptgb_logo_lPal, ptgb_logo_lPalLen); tonccpy(pal_obj_mem + (TYPES_PAL1 * 16), typesPal, typesPalLen); - tonccpy( - pal_obj_mem + (LINK_CABLE_PAL * 16), link_frame1Pal, link_frame1PalLen); + tonccpy(pal_obj_mem + (LINK_CABLE_PAL * 16), link_frame1Pal, link_frame1PalLen); u32 curr_tile_id = 0; - load_sprite_compressed(ptgb_logo_l, ptgb_logo_lTiles, curr_tile_id, - LOGO_PAL, ATTR0_SQUARE, ATTR1_SIZE_64x64, 1); - load_sprite_compressed(ptgb_logo_r, ptgb_logo_rTiles, curr_tile_id, - LOGO_PAL, ATTR0_SQUARE, ATTR1_SIZE_64x64, 1); - load_sprite_compressed(button_yes, button_yesTiles, curr_tile_id, BTN_PAL, - ATTR0_WIDE, ATTR1_SIZE_64x32, 1); - load_sprite_compressed(button_no, button_noTiles, curr_tile_id, BTN_PAL, - ATTR0_WIDE, ATTR1_SIZE_64x32, 1); - load_sprite_compressed(cart_label, Label_GreenTiles, curr_tile_id, - GB_CART_PAL, ATTR0_SQUARE, ATTR1_SIZE_32x32, 1); + load_sprite_compressed( + ptgb_logo_l, ptgb_logo_lTiles, curr_tile_id, LOGO_PAL, ATTR0_SQUARE, ATTR1_SIZE_64x64, 1); + load_sprite_compressed( + ptgb_logo_r, ptgb_logo_rTiles, curr_tile_id, LOGO_PAL, ATTR0_SQUARE, ATTR1_SIZE_64x64, 1); + load_sprite_compressed( + button_yes, button_yesTiles, curr_tile_id, BTN_PAL, ATTR0_WIDE, ATTR1_SIZE_64x32, 1); + load_sprite_compressed( + button_no, button_noTiles, curr_tile_id, BTN_PAL, ATTR0_WIDE, ATTR1_SIZE_64x32, 1); + load_sprite_compressed( + cart_label, Label_GreenTiles, curr_tile_id, GB_CART_PAL, ATTR0_SQUARE, ATTR1_SIZE_32x32, 1); /** * @brief Okay, the next lines to load the arrows are a bit confusing. * Be aware that tempTileBuf is NOT a u8 array, but a u32 array! - * The incoming arrows image is 1bpp, but we convert it into 4bpp in - * tempTileBuf. So every pixel is a nibble. + * The incoming arrows image is 1bpp, but we convert it into 4bpp in tempTileBuf. So every pixel + * is a nibble. * - * Still, every index of tempTileBuf is a full 32 bit integer, yet the third - * argument of load_sprite is a size_in_bytes. This is why those indexes - * look off. But they are correct. + * Still, every index of tempTileBuf is a full 32 bit integer, yet the third argument of + * load_sprite is a size_in_bytes. This is why those indexes look off. But they are correct. */ unsigned int tempTileBuf[48]; BitUnPack(arrowsTiles, tempTileBuf, arrowsTilesLen, 1, 4); - load_sprite(point_arrow, &tempTileBuf[32], 32, curr_tile_id, BTN_PAL, - ATTR0_SQUARE, ATTR1_SIZE_8x8, 1); - load_sprite(toggle_arrow_right, &tempTileBuf[40], 32, curr_tile_id, BTN_PAL, - ATTR0_SQUARE, ATTR1_SIZE_8x8, 1); - load_sprite(toggle_arrow_left, &tempTileBuf[40], 32, curr_tile_id, BTN_PAL, - ATTR0_SQUARE, ATTR1_SIZE_8x8 | ATTR1_HFLIP, 1); - load_sprite(down_arrow, &tempTileBuf[0], 64, curr_tile_id, BTN_PAL, - ATTR0_WIDE, ATTR1_SIZE_16x8, 1); - load_sprite(up_arrow, &tempTileBuf[16], 64, curr_tile_id, BTN_PAL, - ATTR0_WIDE, ATTR1_SIZE_16x8, 1); + load_sprite( + point_arrow, &tempTileBuf[32], 32, curr_tile_id, BTN_PAL, ATTR0_SQUARE, ATTR1_SIZE_8x8, 1); + load_sprite(toggle_arrow_right, &tempTileBuf[40], 32, curr_tile_id, BTN_PAL, ATTR0_SQUARE, + ATTR1_SIZE_8x8, 1); + load_sprite(toggle_arrow_left, &tempTileBuf[40], 32, curr_tile_id, BTN_PAL, ATTR0_SQUARE, + ATTR1_SIZE_8x8 | ATTR1_HFLIP, 1); + load_sprite( + down_arrow, &tempTileBuf[0], 64, curr_tile_id, BTN_PAL, ATTR0_WIDE, ATTR1_SIZE_16x8, 1); + load_sprite( + up_arrow, &tempTileBuf[16], 64, curr_tile_id, BTN_PAL, ATTR0_WIDE, ATTR1_SIZE_16x8, 1); - load_sprite_compressed(link_frame1, link_frame1Tiles, curr_tile_id, - LINK_CABLE_PAL, ATTR0_SQUARE, ATTR1_SIZE_32x32, 1); - load_sprite_compressed(link_frame2, link_frame2Tiles, curr_tile_id, - LINK_CABLE_PAL, ATTR0_WIDE, ATTR1_SIZE_8x32, 1); - load_sprite_compressed(link_frame3, link_frame3Tiles, curr_tile_id, - LINK_CABLE_PAL, ATTR0_WIDE, ATTR1_SIZE_16x32, 1); + load_sprite_compressed(link_frame1, link_frame1Tiles, curr_tile_id, LINK_CABLE_PAL, + ATTR0_SQUARE, ATTR1_SIZE_32x32, 1); + load_sprite_compressed(link_frame2, link_frame2Tiles, curr_tile_id, LINK_CABLE_PAL, ATTR0_WIDE, + ATTR1_SIZE_8x32, 1); + load_sprite_compressed(link_frame3, link_frame3Tiles, curr_tile_id, LINK_CABLE_PAL, ATTR0_WIDE, + ATTR1_SIZE_16x32, 1); BitUnPack(link_blobsTiles, tempTileBuf, link_blobsTilesLen, 1, 4); - load_sprite(link_blob1, &tempTileBuf[0], 32, curr_tile_id, LINK_CABLE_PAL, - ATTR0_SQUARE, ATTR1_SIZE_8x8, 1); - load_sprite(link_blob2, &tempTileBuf[8], 32, curr_tile_id, LINK_CABLE_PAL, - ATTR0_SQUARE, ATTR1_SIZE_8x8, 1); - load_sprite(link_blob3, &tempTileBuf[16], 32, curr_tile_id, LINK_CABLE_PAL, - ATTR0_SQUARE, ATTR1_SIZE_8x8, 1); + load_sprite(link_blob1, &tempTileBuf[0], 32, curr_tile_id, LINK_CABLE_PAL, ATTR0_SQUARE, + ATTR1_SIZE_8x8, 1); + load_sprite(link_blob2, &tempTileBuf[8], 32, curr_tile_id, LINK_CABLE_PAL, ATTR0_SQUARE, + ATTR1_SIZE_8x8, 1); + load_sprite(link_blob3, &tempTileBuf[16], 32, curr_tile_id, LINK_CABLE_PAL, ATTR0_SQUARE, + ATTR1_SIZE_8x8, 1); global_tile_id_end = curr_tile_id; obj_set_pos(down_arrow, 14 * 8, 17 * 8); @@ -587,8 +567,7 @@ void load_temp_box_sprites(PokeBox *box) { u32 curr_tile_id = global_tile_id_end; - if (!(g_debug_options.ignore_game_pak || - g_debug_options.ignore_game_pak_sprites)) + if (!(g_debug_options.ignore_game_pak || g_debug_options.ignore_game_pak_sprites)) { for (int i = 0; i < 30; i++) { @@ -605,19 +584,14 @@ void load_temp_box_sprites(PokeBox *box) dex_num = 0; } - u32 sprite_location = - (*(u32 *)(curr_GBA_rom.loc_gMonIconTable + (dex_num * 4))); - int pal_num = *( - byte *)(curr_GBA_rom.loc_gMonIconPaletteIndices + dex_num); - load_sprite(party_sprites[i], - (const unsigned int *)sprite_location, 512, curr_tile_id, - MENU_PAL_RED + pal_num, ATTR0_SQUARE, ATTR1_SIZE_32x32, 1); + u32 sprite_location = (*(u32 *)(curr_GBA_rom.loc_gMonIconTable + (dex_num * 4))); + int pal_num = *(byte *)(curr_GBA_rom.loc_gMonIconPaletteIndices + dex_num); + load_sprite(party_sprites[i], (const unsigned int *)sprite_location, 512, + curr_tile_id, MENU_PAL_RED + pal_num, ATTR0_SQUARE, ATTR1_SIZE_32x32, 1); obj_set_pos(party_sprites[i], - ((BOXMENU_SPRITE_WIDTH + BOXMENU_HSPACE) * - (i % BOXMENU_HNUM)) + + ((BOXMENU_SPRITE_WIDTH + BOXMENU_HSPACE) * (i % BOXMENU_HNUM)) + (BOXMENU_LEFT + BOXMENU_SPRITE_HOFFSET), - ((BOXMENU_SPRITE_HEIGHT + BOXMENU_VSPACE) * - (i / BOXMENU_HNUM)) + + ((BOXMENU_SPRITE_HEIGHT + BOXMENU_VSPACE) * (i / BOXMENU_HNUM)) + (BOXMENU_TOP + BOXMENU_SPRITE_VOFFSET)); obj_unhide(party_sprites[i], 0); } @@ -630,32 +604,28 @@ void load_temp_box_sprites(PokeBox *box) for (int i = 0; i < 3; i++) { tonccpy((pal_obj_mem + ((MENU_PAL_RED + i) * 16)), - (const unsigned short *)(curr_GBA_rom.loc_gMonIconPalettes + - (i * 32)), - 32); + (const unsigned short *)(curr_GBA_rom.loc_gMonIconPalettes + (i * 32)), 32); } load_sprite_compressed(grabbed_front_sprite, - (const unsigned int *)*( - u32 *)(curr_GBA_rom.loc_gMonFrontPicTable + (0 * 8)), + (const unsigned int *)*(u32 *)(curr_GBA_rom.loc_gMonFrontPicTable + (0 * 8)), curr_tile_id, PULLED_SPRITE_PAL, ATTR0_SQUARE, ATTR1_SIZE_64x64, 1); obj_set_pos(grabbed_front_sprite, 8, 16); } - load_sprite_compressed(box_select, box_selectTiles, curr_tile_id, BTN_PAL, - ATTR0_SQUARE, ATTR1_SIZE_32x32, 0); - load_sprite_compressed(button_cancel_left, button_cancel_leftTiles, - curr_tile_id, BTN_PAL, ATTR0_WIDE, ATTR1_SIZE_64x32, 1); - load_sprite_compressed(button_cancel_right, button_edgeTiles, curr_tile_id, - BTN_PAL, ATTR0_TALL, ATTR1_SIZE_8x32, 1); - load_sprite_compressed(button_confirm_left, button_confirm_leftTiles, - curr_tile_id, BTN_PAL, ATTR0_WIDE, ATTR1_SIZE_64x32, 1); - load_sprite_compressed(button_confirm_right, button_edgeTiles, curr_tile_id, - BTN_PAL, ATTR0_TALL, ATTR1_SIZE_8x32, 1); + load_sprite_compressed( + box_select, box_selectTiles, curr_tile_id, BTN_PAL, ATTR0_SQUARE, ATTR1_SIZE_32x32, 0); + load_sprite_compressed(button_cancel_left, button_cancel_leftTiles, curr_tile_id, BTN_PAL, + ATTR0_WIDE, ATTR1_SIZE_64x32, 1); + load_sprite_compressed(button_cancel_right, button_edgeTiles, curr_tile_id, BTN_PAL, ATTR0_TALL, + ATTR1_SIZE_8x32, 1); + load_sprite_compressed(button_confirm_left, button_confirm_leftTiles, curr_tile_id, BTN_PAL, + ATTR0_WIDE, ATTR1_SIZE_64x32, 1); + load_sprite_compressed(button_confirm_right, button_edgeTiles, curr_tile_id, BTN_PAL, + ATTR0_TALL, ATTR1_SIZE_8x32, 1); } -void load_type_sprites( - const u8 *pkmn_type_table, int pkmn_index, int dex_offset, bool is_caught) +void load_type_sprites(const u8 *pkmn_type_table, int pkmn_index, int dex_offset, bool is_caught) { if (is_caught) { @@ -663,19 +633,13 @@ void load_type_sprites( u16 type1 = pkmn_type_table[pkmn_index * 2]; u16 type2 = pkmn_type_table[pkmn_index * 2 + 1]; - load_sprite(type_sprites[(dex_offset * 2) + 0], - &typesTiles[(type1 * 32)], 128, curr_tile_id, - (type1 < 13 ? TYPES_PAL1 : TYPES_PAL2), ATTR0_WIDE, ATTR1_SIZE_32x8, - 1); - load_sprite(type_sprites[(dex_offset * 2) + 1], - &typesTiles[(type2 * 32)], 128, curr_tile_id, - (type2 < 13 ? TYPES_PAL1 : TYPES_PAL2), ATTR0_WIDE, ATTR1_SIZE_32x8, - 1); + load_sprite(type_sprites[(dex_offset * 2) + 0], &typesTiles[(type1 * 32)], 128, + curr_tile_id, (type1 < 13 ? TYPES_PAL1 : TYPES_PAL2), ATTR0_WIDE, ATTR1_SIZE_32x8, 1); + load_sprite(type_sprites[(dex_offset * 2) + 1], &typesTiles[(type2 * 32)], 128, + curr_tile_id, (type2 < 13 ? TYPES_PAL1 : TYPES_PAL2), ATTR0_WIDE, ATTR1_SIZE_32x8, 1); - obj_set_pos(type_sprites[(dex_offset * 2) + 0], 19 * 8, - (8 * 2 * dex_offset) + (8 * 4)); - obj_set_pos(type_sprites[(dex_offset * 2) + 1], 23 * 8, - (8 * 2 * dex_offset) + (8 * 4)); + obj_set_pos(type_sprites[(dex_offset * 2) + 0], 19 * 8, (8 * 2 * dex_offset) + (8 * 4)); + obj_set_pos(type_sprites[(dex_offset * 2) + 1], 23 * 8, (8 * 2 * dex_offset) + (8 * 4)); obj_unhide(type_sprites[(dex_offset * 2) + 0], 0); if (type1 != type2) @@ -690,25 +654,22 @@ void load_type_sprites( } } -void load_sprite(OBJ_ATTR *sprite, const unsigned int objTiles[], - int objTilesLen, u32 &tile_id, u32 pal_bank, int attr0, int attr1, - u32 priority) +void load_sprite(OBJ_ATTR *sprite, const unsigned int objTiles[], int objTilesLen, u32 &tile_id, + u32 pal_bank, int attr0, int attr1, u32 priority) { tonccpy(&tile_mem[SPRITE_CHAR_BLOCK][tile_id], objTiles, objTilesLen); - obj_set_attr(sprite, attr0, attr1, - ATTR2_PALBANK(pal_bank) | tile_id | ATTR2_PRIO(priority)); + obj_set_attr(sprite, attr0, attr1, ATTR2_PALBANK(pal_bank) | tile_id | ATTR2_PRIO(priority)); tile_id += objTilesLen / 32; obj_hide(sprite); }; -void load_sprite_compressed(OBJ_ATTR *sprite, const unsigned int objTiles[], - u32 &tile_id, u32 pal_bank, int attr0, int attr1, u32 priority) +void load_sprite_compressed(OBJ_ATTR *sprite, const unsigned int objTiles[], u32 &tile_id, + u32 pal_bank, int attr0, int attr1, u32 priority) { // bits 8-31 of the header are the length int objTilesLen = objTiles[0] >> 8; LZ77UnCompVram(objTiles, &tile_mem[SPRITE_CHAR_BLOCK][tile_id]); - obj_set_attr(sprite, attr0, attr1, - ATTR2_PALBANK(pal_bank) | tile_id | ATTR2_PRIO(priority)); + obj_set_attr(sprite, attr0, attr1, ATTR2_PALBANK(pal_bank) | tile_id | ATTR2_PRIO(priority)); tile_id += objTilesLen / 32; obj_hide(sprite); }; @@ -716,29 +677,26 @@ void load_sprite_compressed(OBJ_ATTR *sprite, const unsigned int objTiles[], void load_select_sprites(GameBoyROM currROM) { u32 curr_tile_id = global_tile_id_end; - // Alpha Shadow Main - // Color Grey Black Mid - const unsigned short jpn_gb_pal[6] = {RGB15(0, 0, 0), RGB15(10, 9, 10), - RGB15(17, 17, 17), RGB15(22, 22, 22), RGB15(0, 0, 0), - RGB15(14, 13, 14)}; - const unsigned short eng_red_pal[6] = {RGB15(0, 0, 0), RGB15(16, 1, 0), - RGB15(27, 6, 5), RGB15(22, 22, 22), RGB15(0, 0, 0), RGB15(23, 3, 2)}; - const unsigned short eng_blue_pal[6] = {RGB15(0, 0, 0), RGB15(0, 4, 16), - RGB15(5, 10, 24), RGB15(22, 22, 22), RGB15(0, 0, 0), RGB15(1, 6, 20)}; - const unsigned short eng_yellow_pal[6] = {RGB15(0, 0, 0), RGB15(18, 12, 0), - RGB15(27, 21, 5), RGB15(22, 22, 22), RGB15(0, 0, 0), RGB15(22, 16, 1)}; - const unsigned short eng_gold_pal[6] = {RGB15(0, 0, 0), RGB15(13, 10, 2), - RGB15(22, 18, 8), RGB15(22, 22, 22), RGB15(0, 0, 0), RGB15(17, 14, 4)}; - const unsigned short eng_silver_pal[6] = {RGB15(0, 0, 0), RGB15(11, 12, 14), - RGB15(20, 22, 23), RGB15(22, 22, 22), RGB15(0, 0, 0), - RGB15(15, 16, 19)}; - const unsigned short crystal_pal[6] = {RGB15(0, 0, 0), RGB15(9, 13, 17), - RGB15(16, 21, 25), RGB15(22, 22, 22), RGB15(0, 0, 0), - RGB15(12, 17, 22)}; - const unsigned short jpn_gold_pal[6] = {RGB15(0, 0, 0), RGB15(0, 0, 0), - RGB15(5, 7, 12), RGB15(22, 22, 22), RGB15(0, 0, 0), RGB15(3, 4, 8)}; - const unsigned short jpn_silver_pal[6] = {RGB15(0, 0, 0), RGB15(5, 4, 5), - RGB15(11, 10, 10), RGB15(22, 22, 22), RGB15(0, 0, 0), RGB15(8, 7, 7)}; + // Alpha Shadow Main Color Grey Black + // Mid + const unsigned short jpn_gb_pal[6] = {RGB15(0, 0, 0), RGB15(10, 9, 10), RGB15(17, 17, 17), + RGB15(22, 22, 22), RGB15(0, 0, 0), RGB15(14, 13, 14)}; + const unsigned short eng_red_pal[6] = {RGB15(0, 0, 0), RGB15(16, 1, 0), RGB15(27, 6, 5), + RGB15(22, 22, 22), RGB15(0, 0, 0), RGB15(23, 3, 2)}; + const unsigned short eng_blue_pal[6] = {RGB15(0, 0, 0), RGB15(0, 4, 16), RGB15(5, 10, 24), + RGB15(22, 22, 22), RGB15(0, 0, 0), RGB15(1, 6, 20)}; + const unsigned short eng_yellow_pal[6] = {RGB15(0, 0, 0), RGB15(18, 12, 0), RGB15(27, 21, 5), + RGB15(22, 22, 22), RGB15(0, 0, 0), RGB15(22, 16, 1)}; + const unsigned short eng_gold_pal[6] = {RGB15(0, 0, 0), RGB15(13, 10, 2), RGB15(22, 18, 8), + RGB15(22, 22, 22), RGB15(0, 0, 0), RGB15(17, 14, 4)}; + const unsigned short eng_silver_pal[6] = {RGB15(0, 0, 0), RGB15(11, 12, 14), RGB15(20, 22, 23), + RGB15(22, 22, 22), RGB15(0, 0, 0), RGB15(15, 16, 19)}; + const unsigned short crystal_pal[6] = {RGB15(0, 0, 0), RGB15(9, 13, 17), RGB15(16, 21, 25), + RGB15(22, 22, 22), RGB15(0, 0, 0), RGB15(12, 17, 22)}; + const unsigned short jpn_gold_pal[6] = {RGB15(0, 0, 0), RGB15(0, 0, 0), RGB15(5, 7, 12), + RGB15(22, 22, 22), RGB15(0, 0, 0), RGB15(3, 4, 8)}; + const unsigned short jpn_silver_pal[6] = {RGB15(0, 0, 0), RGB15(5, 4, 5), RGB15(11, 10, 10), + RGB15(22, 22, 22), RGB15(0, 0, 0), RGB15(8, 7, 7)}; const unsigned int *label_tiles = 0; const unsigned short *label_palette = 0; @@ -888,10 +846,10 @@ void load_select_sprites(GameBoyROM currROM) tonccpy(pal_obj_mem + (GB_CART_PAL * 16), cart_palette, 12); tonccpy(pal_obj_mem + (GB_CART_PAL * 16) + 6, label_palette + 6, 20); - load_sprite_compressed(cart_shell, cart_tiles, curr_tile_id, GB_CART_PAL, - ATTR0_SQUARE, ATTR1_SIZE_64x64, 1); - load_sprite_compressed(cart_label, label_tiles, curr_tile_id, GB_CART_PAL, - ATTR0_SQUARE, ATTR1_SIZE_32x32, 1); + load_sprite_compressed( + cart_shell, cart_tiles, curr_tile_id, GB_CART_PAL, ATTR0_SQUARE, ATTR1_SIZE_64x64, 1); + load_sprite_compressed( + cart_label, label_tiles, curr_tile_id, GB_CART_PAL, ATTR0_SQUARE, ATTR1_SIZE_32x32, 1); const unsigned int *gb_flag_tiles = 0; const unsigned short *gb_flag_palette = 0; @@ -979,12 +937,11 @@ void load_select_sprites(GameBoyROM currROM) break; } - load_sprite_compressed(gb_flag, gb_flag_tiles, curr_tile_id, GB_FLAG_PAL, - ATTR0_WIDE, ATTR1_SIZE_32x64, 1); - load_sprite_compressed(gba_flag, gb_flag_tiles, curr_tile_id, GBA_FLAG_PAL, - ATTR0_WIDE, ATTR1_SIZE_32x64, 1); - tonccpy(pal_obj_mem + (GB_FLAG_PAL * 16), gb_flag_palette, - 16); // Grit is being stupid. + load_sprite_compressed( + gb_flag, gb_flag_tiles, curr_tile_id, GB_FLAG_PAL, ATTR0_WIDE, ATTR1_SIZE_32x64, 1); + load_sprite_compressed( + gba_flag, gb_flag_tiles, curr_tile_id, GBA_FLAG_PAL, ATTR0_WIDE, ATTR1_SIZE_32x64, 1); + tonccpy(pal_obj_mem + (GB_FLAG_PAL * 16), gb_flag_palette, 16); // Grit is being stupid. const unsigned int *gba_cart_tiles = 0; const unsigned short *gba_cart_palette = 0; @@ -1013,8 +970,8 @@ void load_select_sprites(GameBoyROM currROM) break; } - load_sprite_compressed(gba_cart, gba_cart_tiles, curr_tile_id, GBA_CART_PAL, - ATTR0_WIDE, ATTR1_SIZE_32x64, 1); + load_sprite_compressed( + gba_cart, gba_cart_tiles, curr_tile_id, GBA_CART_PAL, ATTR0_WIDE, ATTR1_SIZE_32x64, 1); tonccpy(pal_obj_mem + (GBA_CART_PAL * 16), gba_cart_palette, 32); const unsigned int *gba_flag_tiles = 0; @@ -1057,12 +1014,11 @@ void load_select_sprites(GameBoyROM currROM) break; } - load_sprite_compressed(gba_flag, gba_flag_tiles, curr_tile_id, GBA_FLAG_PAL, - ATTR0_WIDE, ATTR1_SIZE_32x64, 1); - load_sprite_compressed(gba_flag, gba_flag_tiles, curr_tile_id, GBA_FLAG_PAL, - ATTR0_WIDE, ATTR1_SIZE_32x64, 1); - tonccpy(pal_obj_mem + (GBA_FLAG_PAL * 16), gba_flag_palette, - 16); // Grit is being stupid. + load_sprite_compressed( + gba_flag, gba_flag_tiles, curr_tile_id, GBA_FLAG_PAL, ATTR0_WIDE, ATTR1_SIZE_32x64, 1); + load_sprite_compressed( + gba_flag, gba_flag_tiles, curr_tile_id, GBA_FLAG_PAL, ATTR0_WIDE, ATTR1_SIZE_32x64, 1); + tonccpy(pal_obj_mem + (GBA_FLAG_PAL * 16), gba_flag_palette, 16); // Grit is being stupid. } // tile ID, VH Flip, Palette Bank #define FEN_BLI_L00 ((TILESET_OFFSET_FLEXBG + 34) | (0b00 << 0xA) | (2 << 0xC)) @@ -1091,29 +1047,20 @@ void fennel_blink(int frame) switch (frame) { case 0: - se_mem[TILEMAP_FLEXBG][12 + (5 * 32)] = - missingno ? FEN_SPE_00 | FEN_BLI_L20 : FEN_BLI_L20; - se_mem[TILEMAP_FLEXBG][13 + (5 * 32)] = - missingno ? FEN_SPE_01 | FEN_BLI_L21 : FEN_BLI_L21; - se_mem[TILEMAP_FLEXBG][15 + (5 * 32)] = - missingno ? FEN_SPE_10 | FEN_BLI_R2 : FEN_BLI_R2; + se_mem[TILEMAP_FLEXBG][12 + (5 * 32)] = missingno ? FEN_SPE_00 | FEN_BLI_L20 : FEN_BLI_L20; + se_mem[TILEMAP_FLEXBG][13 + (5 * 32)] = missingno ? FEN_SPE_01 | FEN_BLI_L21 : FEN_BLI_L21; + se_mem[TILEMAP_FLEXBG][15 + (5 * 32)] = missingno ? FEN_SPE_10 | FEN_BLI_R2 : FEN_BLI_R2; break; case 1: case 3: - se_mem[TILEMAP_FLEXBG][12 + (5 * 32)] = - missingno ? FEN_SPE_11 | FEN_BLI_L10 : FEN_BLI_L10; - se_mem[TILEMAP_FLEXBG][13 + (5 * 32)] = - missingno ? FEN_SPE_20 | FEN_BLI_L11 : FEN_BLI_L11; - se_mem[TILEMAP_FLEXBG][15 + (5 * 32)] = - missingno ? FEN_SPE_21 | FEN_BLI_R1 : FEN_BLI_R1; + se_mem[TILEMAP_FLEXBG][12 + (5 * 32)] = missingno ? FEN_SPE_11 | FEN_BLI_L10 : FEN_BLI_L10; + se_mem[TILEMAP_FLEXBG][13 + (5 * 32)] = missingno ? FEN_SPE_20 | FEN_BLI_L11 : FEN_BLI_L11; + se_mem[TILEMAP_FLEXBG][15 + (5 * 32)] = missingno ? FEN_SPE_21 | FEN_BLI_R1 : FEN_BLI_R1; break; case 2: - se_mem[TILEMAP_FLEXBG][12 + (5 * 32)] = - missingno ? FEN_SPE_30 | FEN_BLI_L00 : FEN_BLI_L00; - se_mem[TILEMAP_FLEXBG][13 + (5 * 32)] = - missingno ? FEN_SPE_31 | FEN_BLI_L01 : FEN_BLI_L01; - se_mem[TILEMAP_FLEXBG][15 + (5 * 32)] = - missingno ? FEN_SPE_00 | FEN_BLI_R0 : FEN_BLI_R0; + se_mem[TILEMAP_FLEXBG][12 + (5 * 32)] = missingno ? FEN_SPE_30 | FEN_BLI_L00 : FEN_BLI_L00; + se_mem[TILEMAP_FLEXBG][13 + (5 * 32)] = missingno ? FEN_SPE_31 | FEN_BLI_L01 : FEN_BLI_L01; + se_mem[TILEMAP_FLEXBG][15 + (5 * 32)] = missingno ? FEN_SPE_00 | FEN_BLI_R0 : FEN_BLI_R0; break; } } @@ -1124,29 +1071,21 @@ void fennel_speak(int frame) switch (frame) { case 0: - se_mem[TILEMAP_FLEXBG][14 + (6 * 32)] = - missingno ? FEN_SPE_00 | FEN_BLI_L20 : FEN_SPE_00; - se_mem[TILEMAP_FLEXBG][14 + (7 * 32)] = - missingno ? FEN_SPE_01 | FEN_BLI_L21 : FEN_SPE_01; + se_mem[TILEMAP_FLEXBG][14 + (6 * 32)] = missingno ? FEN_SPE_00 | FEN_BLI_L20 : FEN_SPE_00; + se_mem[TILEMAP_FLEXBG][14 + (7 * 32)] = missingno ? FEN_SPE_01 | FEN_BLI_L21 : FEN_SPE_01; break; case 1: - se_mem[TILEMAP_FLEXBG][14 + (6 * 32)] = - missingno ? FEN_SPE_10 | FEN_BLI_R2 : FEN_SPE_10; - se_mem[TILEMAP_FLEXBG][14 + (7 * 32)] = - missingno ? FEN_SPE_11 | FEN_BLI_L10 : FEN_SPE_11; + se_mem[TILEMAP_FLEXBG][14 + (6 * 32)] = missingno ? FEN_SPE_10 | FEN_BLI_R2 : FEN_SPE_10; + se_mem[TILEMAP_FLEXBG][14 + (7 * 32)] = missingno ? FEN_SPE_11 | FEN_BLI_L10 : FEN_SPE_11; break; case 2: case 4: - se_mem[TILEMAP_FLEXBG][14 + (6 * 32)] = - missingno ? FEN_SPE_01 | FEN_BLI_L21 : FEN_SPE_20; - se_mem[TILEMAP_FLEXBG][14 + (7 * 32)] = - missingno ? FEN_SPE_01 | FEN_BLI_L21 : FEN_SPE_21; + se_mem[TILEMAP_FLEXBG][14 + (6 * 32)] = missingno ? FEN_SPE_01 | FEN_BLI_L21 : FEN_SPE_20; + se_mem[TILEMAP_FLEXBG][14 + (7 * 32)] = missingno ? FEN_SPE_01 | FEN_BLI_L21 : FEN_SPE_21; break; case 3: - se_mem[TILEMAP_FLEXBG][14 + (6 * 32)] = - missingno ? FEN_SPE_30 | FEN_BLI_L00 : FEN_SPE_30; - se_mem[TILEMAP_FLEXBG][14 + (7 * 32)] = - missingno ? FEN_SPE_31 | FEN_BLI_L01 : FEN_SPE_31; + se_mem[TILEMAP_FLEXBG][14 + (6 * 32)] = missingno ? FEN_SPE_30 | FEN_BLI_L00 : FEN_SPE_30; + se_mem[TILEMAP_FLEXBG][14 + (7 * 32)] = missingno ? FEN_SPE_31 | FEN_BLI_L01 : FEN_SPE_31; break; } } @@ -1181,15 +1120,13 @@ void update_y_offset() void update_front_box_sprite(Pokemon *curr_pkmn, bool make_greyscale) { - if (g_debug_options.ignore_game_pak || - g_debug_options.ignore_game_pak_sprites) + if (g_debug_options.ignore_game_pak || g_debug_options.ignore_game_pak_sprites) { return; // We don't want to look into garbage data, get out of here. } - // in load_temp_sprites(), we reserve 30 box sprite icons after - // global_tile_id_end. Each of them occupy 16 tiles. the - // grabbed_front_sprite comes right after it. And we load the pokémon front + // in load_temp_sprites(), we reserve 30 box sprite icons after global_tile_id_end. Each of them + // occupy 16 tiles. the grabbed_front_sprite comes right after it. And we load the pokémon front // sprite directly into its tiles. u32 curr_tile_id = global_tile_id_end + (30 * 16); @@ -1210,17 +1147,16 @@ void update_front_box_sprite(Pokemon *curr_pkmn, bool make_greyscale) dex_num = 277; } - u32 sprite_location = - *(u32 *)(curr_GBA_rom.loc_gMonFrontPicTable + (dex_num * 8)); - u32 palette_location = *( - u32 *)((curr_pkmn->getIsShiny() ? curr_GBA_rom.loc_gMonShinyPaletteTable - : curr_GBA_rom.loc_gMonPaletteTable) + - (curr_pkmn->getSpeciesIndexNumber() * 8)); + u32 sprite_location = *(u32 *)(curr_GBA_rom.loc_gMonFrontPicTable + (dex_num * 8)); + u32 palette_location = + *(u32 *)((curr_pkmn->getIsShiny() ? curr_GBA_rom.loc_gMonShinyPaletteTable + : curr_GBA_rom.loc_gMonPaletteTable) + + (curr_pkmn->getSpeciesIndexNumber() * 8)); unsigned short buffer[16]; LZ77UnCompWram((const unsigned short *)palette_location, - buffer); // This is a little silly, but it's being weird with bytes vs - // shorts when we copy it directly + buffer); // This is a little silly, but it's being weird with bytes vs shorts when we copy + // it directly if (make_greyscale) { @@ -1229,9 +1165,7 @@ void update_front_box_sprite(Pokemon *curr_pkmn, bool make_greyscale) unsigned red = (buffer[i] >> 0) & 0b11111; unsigned green = (buffer[i] >> 5) & 0b11111; unsigned blue = (buffer[i] >> 10) & 0b11111; - unsigned grey = ((QF(0.299f) * red) + (QF(0.587f) * green) + - (QF(0.114f) * blue)) >> - 16; + unsigned grey = ((QF(0.299f) * red) + (QF(0.587f) * green) + (QF(0.114f) * blue)) >> 16; // buffer[i] = RGB15_SAFE(red, ((int)green >> 1), 0); buffer[i] = RGB15_SAFE(grey, (grey >> 1), 0); @@ -1239,14 +1173,13 @@ void update_front_box_sprite(Pokemon *curr_pkmn, bool make_greyscale) } tonccpy((pal_obj_mem + (PULLED_SPRITE_PAL * 16)), buffer, 32); - LZ77UnCompVram((const unsigned int *)sprite_location, - &tile_mem[SPRITE_CHAR_BLOCK][curr_tile_id]); + LZ77UnCompVram( + (const unsigned int *)sprite_location, &tile_mem[SPRITE_CHAR_BLOCK][curr_tile_id]); } void update_menu_sprite(PokeBox *box, int index, int frame) { - if (g_debug_options.ignore_game_pak || - g_debug_options.ignore_game_pak_sprites) + if (g_debug_options.ignore_game_pak || g_debug_options.ignore_game_pak_sprites) { return; // We don't want to look into garbage data, get out of here. } @@ -1273,8 +1206,6 @@ void update_menu_sprite(PokeBox *box, int index, int frame) } u32 sprite_location = - (*(u32 *)(curr_GBA_rom.loc_gMonIconTable + (dex_num * 4))) + - (frame == 0 ? 0 : 512); - tonccpy(&tile_mem[SPRITE_CHAR_BLOCK][curr_tile_id], - (const unsigned int *)sprite_location, 512); + (*(u32 *)(curr_GBA_rom.loc_gMonIconTable + (dex_num * 4))) + (frame == 0 ? 0 : 512); + tonccpy(&tile_mem[SPRITE_CHAR_BLOCK][curr_tile_id], (const unsigned int *)sprite_location, 512); } \ No newline at end of file diff --git a/source/text_engine.cpp b/source/text_engine.cpp index ce519e5..4c8ebf5 100644 --- a/source/text_engine.cpp +++ b/source/text_engine.cpp @@ -20,16 +20,14 @@ uint line_char_index; const byte *curr_text; bool text_exit; -// This function was separated from text_loop to reduce the scope of the -// text_decompression_buffer. if we didn't do this, the decompression_buffer -// would be kept on the stack (=IWRAM) for the entire duration of the -// text_loop() call. This is particularly bad because the whole -// mystery_gift_builder sequence is being triggered from within text_loop(). And -// there we need all the IWRAM we can muster. Doing it this way does mean that -// we need to completely restart decompression whenever we switch from dialog -// entry. but given that it requires user input to do so, I believe it's worth -// it and not time-critical. attribute noinline was used to make sure the -// compiler doesn't inline this code back into text_loop() +// This function was separated from text_loop to reduce the scope of the text_decompression_buffer. +// if we didn't do this, the decompression_buffer would be kept on the stack (=IWRAM) for the entire +// duration of the text_loop() call. This is particularly bad because the whole mystery_gift_builder +// sequence is being triggered from within text_loop(). And there we need all the IWRAM we can +// muster. Doing it this way does mean that we need to completely restart decompression whenever we +// switch from dialog entry. but given that it requires user input to do so, I believe it's worth it +// and not time-critical. attribute noinline was used to make sure the compiler doesn't inline this +// code back into text_loop() static __attribute__((noinline)) const u8 *read_dialogue_text_entry( u32 index, u32 text_section, u8 *output_buffer) { @@ -41,16 +39,14 @@ static __attribute__((noinline)) const u8 *read_dialogue_text_entry( get_text_table_chunks(text_section, &chunkList, &numChunks, &chunkSize); FileContainerReader dialogueTable(chunkList, numChunks, chunkSize); - dialogueTable.init( - text_decompression_buffer, sizeof(text_decompression_buffer)); + dialogueTable.init(text_decompression_buffer, sizeof(text_decompression_buffer)); dialogueTable.readFile(index, output_buffer); return output_buffer; } -// This will have to be changed to be dynamic to support nicknamed Pokemon that -// are in a different language than the current build. Maybe combine Japanese -// and Latin into one larger font? +// This will have to be changed to be dynamic to support nicknamed Pokemon that are in a different +// language than the current build. Maybe combine Japanese and Latin into one larger font? #if PTGB_BUILD_LANGUAGE == 1 #define BUILD_FONT &japanese_normalFont @@ -61,21 +57,20 @@ static __attribute__((noinline)) const u8 *read_dialogue_text_entry( void init_text_engine() { // Load the TTE - // tte_init_se(3, BG_CBB(TEXT_CBB) | BG_SBB(TEXT_SBB) | BG_PRIO(0), 0, - // CLR_WHITE, 14, &japanese_smallFont, NULL); + // tte_init_se(3, BG_CBB(TEXT_CBB) | BG_SBB(TEXT_SBB) | BG_PRIO(0), 0, CLR_WHITE, 14, + // &japanese_smallFont, NULL); - tte_init_chr4c(3, // BG 3 - BG_CBB(TILESET_TEXT) | - BG_SBB(TILEMAP_TEXT), // Charblock 0; screenblock 10 - 0xF000, // Screen-entry offset - bytes2word( // Color attributes: - 13, // Text color - 15, // Shadow color - 0, // Paper - 0), // Special - CLR_WHITE, // White text - BUILD_FONT, // Custom font - NULL // Use default chr4 renderer + tte_init_chr4c(3, // BG 3 + BG_CBB(TILESET_TEXT) | BG_SBB(TILEMAP_TEXT), // Charblock 0; screenblock 10 + 0xF000, // Screen-entry offset + bytes2word( // Color attributes: + 13, // Text color + 15, // Shadow color + 0, // Paper + 0), // Special + CLR_WHITE, // White text + BUILD_FONT, // Custom font + NULL // Use default chr4 renderer ); tte_init_con(); @@ -91,9 +86,8 @@ void init_text_engine() int text_loop(int script) { - // we have restricted the dialog entries to 1024 bytes in the text_helper - // main.py so we shouldn't run into problems when we only use 1 KB to - // contain a text entry. + // we have restricted the dialog entries to 1024 bytes in the text_helper main.py + // so we shouldn't run into problems when we only use 1 KB to contain a text entry. u8 diag_entry_text_buffer[1024]; switch (script) { @@ -110,21 +104,19 @@ int text_loop(int script) break; } - curr_text = (curr_line.has_text()) - ? read_dialogue_text_entry(curr_line.get_text_entry_index(), - PTGB_INDEX, diag_entry_text_buffer) - : NULL; + curr_text = (curr_line.has_text()) ? read_dialogue_text_entry(curr_line.get_text_entry_index(), + PTGB_INDEX, diag_entry_text_buffer) + : NULL; // tte_set_margins(LEFT, TOP, RIGHT, BOTTOM); if (script != SCRIPT_DEBUG) { while (true) // This loops through all the connected script objects { - if (curr_text != NULL && curr_text[char_index] != 0xFF && - curr_text[char_index] != 0xFB) + if (curr_text != NULL && curr_text[char_index] != 0xFF && curr_text[char_index] != 0xFB) { - ptgb_write_textbox(curr_text, false, true, PTGB_INDEX, - curr_line.get_text_entry_index(), false); + ptgb_write_textbox( + curr_text, false, true, PTGB_INDEX, curr_line.get_text_entry_index(), false); } // wait_for_user_to_continue(); @@ -140,11 +132,10 @@ int text_loop(int script) break; } - curr_text = - (curr_line.has_text()) - ? read_dialogue_text_entry(curr_line.get_text_entry_index(), - PTGB_INDEX, diag_entry_text_buffer) - : NULL; + curr_text = (curr_line.has_text()) + ? read_dialogue_text_entry(curr_line.get_text_entry_index(), PTGB_INDEX, + diag_entry_text_buffer) + : NULL; char_index = 0; if (text_exit) @@ -174,15 +165,13 @@ int text_loop(int script) { if (key_hit(KEY_LEFT)) { - text_key = - (text_key + (text_section_lengths[text_section] - 1)) % - text_section_lengths[text_section]; + text_key = (text_key + (text_section_lengths[text_section] - 1)) % + text_section_lengths[text_section]; update_text = true; } else if (key_hit(KEY_RIGHT)) { - text_key = - (text_key + 1) % text_section_lengths[text_section]; + text_key = (text_key + 1) % text_section_lengths[text_section]; update_text = true; } else if (key_hit(KEY_UP)) @@ -194,21 +183,18 @@ int text_loop(int script) else { text_section = - ((text_section + (NUM_TEXT_SECTIONS - 1)) % - NUM_TEXT_SECTIONS); + ((text_section + (NUM_TEXT_SECTIONS - 1)) % NUM_TEXT_SECTIONS); } update_text = true; } else if (key_hit(KEY_DOWN)) { - text_section = (text_section + (NUM_TEXT_SECTIONS - 1)) % - NUM_TEXT_SECTIONS; + text_section = (text_section + (NUM_TEXT_SECTIONS - 1)) % NUM_TEXT_SECTIONS; update_text = true; } else if (key_hit(KEY_START) || key_hit(KEY_SELECT)) { - instant_text = key_hit( - KEY_START); // instant with start, not with select + instant_text = key_hit(KEY_START); // instant with start, not with select exit = true; tte_erase_line(); } @@ -225,11 +211,9 @@ int text_loop(int script) tte_set_pos(0, 0); tte_erase_rect(0, 0, 240, 160); ptgb_write_debug(debug_charset, "(", true); - ptgb_write_debug( - debug_charset, ptgb::to_string(text_section), true); + ptgb_write_debug(debug_charset, ptgb::to_string(text_section), true); ptgb_write_debug(debug_charset, ", ", true); - ptgb_write_debug( - debug_charset, ptgb::to_string(text_key), true); + ptgb_write_debug(debug_charset, ptgb::to_string(text_key), true); ptgb_write_debug(debug_charset, ")", true); update_text = false; } @@ -237,15 +221,12 @@ int text_loop(int script) } line_char_index = 0; - curr_text = read_dialogue_text_entry( - text_key, text_section, diag_entry_text_buffer); + curr_text = read_dialogue_text_entry(text_key, text_section, diag_entry_text_buffer); char_index = 0; - if (curr_text != NULL && curr_text[char_index] != 0xFF && - curr_text[char_index] != 0xFB) + if (curr_text != NULL && curr_text[char_index] != 0xFF && curr_text[char_index] != 0xFB) { - ptgb_write_textbox(curr_text, instant_text, true, text_section, - text_key, true); + ptgb_write_textbox(curr_text, instant_text, true, text_section, text_key, true); } update_text = true; @@ -286,8 +267,8 @@ void set_text_exit() } // Implement a version that creates the textbox as well -int ptgb_write_textbox(const byte *text, bool instant, bool waitForUser, - int text_section, int text_key, bool eraseMainBox) +int ptgb_write_textbox(const byte *text, bool instant, bool waitForUser, int text_section, + int text_key, bool eraseMainBox) { tte_erase_rect(0, 0, H_MAX, V_MAX); erase_textbox_tiles(); @@ -298,8 +279,7 @@ int ptgb_write_textbox(const byte *text, bool instant, bool waitForUser, load_flex_background(FBG_Fennel, 2); } int out = ptgb_write(text, instant, 9999, - text_box_type_tables[text_section] - [text_key]); // This is kinda silly but it'll work. + text_box_type_tables[text_section][text_key]); // This is kinda silly but it'll work. if (waitForUser) { @@ -319,8 +299,7 @@ int ptgb_write_textbox(const byte *text, bool instant, bool waitForUser, // Implement a version that just writes the whole string int ptgb_write_simple(const byte *text, bool instant) { - return ptgb_write( - text, instant, 9999, -1); // This is kinda silly but it'll work. + return ptgb_write(text, instant, 9999, -1); // This is kinda silly but it'll work. } // Re-implementing TTE's "tte_write" to use the gen 3 character encoding chart @@ -355,8 +334,7 @@ int ptgb_write(const byte *text, bool instant, int length, int box_type) while ((ch = *str) != 0xFF && num < length) { - if (get_frame_count() % 2 == 0 || key_held(KEY_B) || key_held(KEY_A) || - instant) + if (get_frame_count() % 2 == 0 || key_held(KEY_B) || key_held(KEY_A) || instant) { str++; switch (ch) @@ -451,13 +429,12 @@ int ptgb_write_debug(const u16 *charset, const char *text, bool instant) else { u16 utf16_char; - // we need to use this conversion function in order to convert char - // values >= 0x80 correctly to UTF-16 (which is used by the charset) + // we need to use this conversion function in order to convert char values >= 0x80 + // correctly to UTF-16 (which is used by the charset) convert_utf8_to_utf16_char((const u8 *)(text + i), utf16_char); - // WARNING: the conversion of the text characters from u8 to u16 - // done here, is incorrect for every character value >= 0x80. The - // character set uses UTF-16 to represent characters. But the input - // text is in UTF-8. + // WARNING: the conversion of the text characters from u8 to u16 done here, is incorrect + // for every character value >= 0x80. The character set uses UTF-16 to represent + // characters. But the input text is in UTF-8. temp_holding[i] = get_char_from_charset(charset, utf16_char); } } @@ -503,40 +480,36 @@ void wait_for_user_to_continue(int right, int bottom) // obj_hide(scroll_indicator_gray); } -void scroll_text(bool instant, TTC *tc, bool scrollUp, int left, int top, - int right, int bottom) +void scroll_text(bool instant, TTC *tc, bool scrollUp, int left, int top, int right, int bottom) { int direction = scrollUp ? 1 : -1; for (int i = 1; i <= tc->font->charH; i++) { REG_BG3VOFS = i * direction; - tte_erase_rect( - left, top - tc->font->charH, right, top + (i * direction)); - if (!instant) // This is somewhat of a silly way to do this - can be - // optimized + tte_erase_rect(left, top - tc->font->charH, right, top + (i * direction)); + if (!instant) // This is somewhat of a silly way to do this - can be optimized { VBlankIntrWait(); } } REG_BG3VOFS = 0; - // The map starts at tile 0 in the top left, increases by 1 as you go down, - // and then loops back at the top. + // The map starts at tile 0 in the top left, increases by 1 as you go down, and then loops back + // at the top. if (scrollUp) { for (int i = 0; i < 30; i++) { - tonccpy(&tile_mem[TILESET_TEXT][0 + (i * 20)], - &tile_mem[TILESET_TEXT][2 + (i * 20)], 20 * 32); + tonccpy(&tile_mem[TILESET_TEXT][0 + (i * 20)], &tile_mem[TILESET_TEXT][2 + (i * 20)], + 20 * 32); } } else { for (int i = 29; i >= 0; i--) { - // Due to the order of tonccpy, we need to store the data in a - // temporary buffer + // Due to the order of tonccpy, we need to store the data in a temporary buffer byte buffer[20 * 32]; tonccpy(&buffer, &tile_mem[TILESET_TEXT][0 + (i * 20)], 20 * 32); tonccpy(&tile_mem[TILESET_TEXT][2 + (i * 20)], &buffer, 20 * 32); @@ -547,7 +520,6 @@ void scroll_text(bool instant, TTC *tc, bool scrollUp, int left, int top, scrollUp ? top : (bottom + tc->font->charH)); tc->cursorY = (scrollUp ? bottom - tc->font->charH - : top); // The newline will trigger after this and - // move it down a line + : top); // The newline will trigger after this and move it down a line tc->cursorX = left; } \ No newline at end of file diff --git a/source/text_tables.cpp b/source/text_tables.cpp index c7084fc..0abd5e0 100644 --- a/source/text_tables.cpp +++ b/source/text_tables.cpp @@ -2,11 +2,10 @@ #include "compression_chunks.h" #include "translated_text.h" -void get_text_table_chunks( - u32 tableIndex, const u8 ***chunkList, u32 *numChunks, u32 *chunkSize) +void get_text_table_chunks(u32 tableIndex, const u8 ***chunkList, u32 *numChunks, u32 *chunkSize) { - // every table except for RSEFRLG is 2048 bytes per chunk, so we can set - // that by default and only change it for RSEFRLG + // every table except for RSEFRLG is 2048 bytes per chunk, so we can set that by default and + // only change it for RSEFRLG *chunkSize = 2048; switch (tableIndex) { @@ -28,13 +27,11 @@ void get_text_table_chunks( break; case PKMN_NAMES_INDEX: *chunkList = PKMN_NAMES_chunk_list; - *numChunks = - sizeof(PKMN_NAMES_chunk_list) / sizeof(PKMN_NAMES_chunk_list[0]); + *numChunks = sizeof(PKMN_NAMES_chunk_list) / sizeof(PKMN_NAMES_chunk_list[0]); break; case TUTORIAL_INDEX: *chunkList = TUTORIAL_chunk_list; - *numChunks = - sizeof(TUTORIAL_chunk_list) / sizeof(TUTORIAL_chunk_list[0]); + *numChunks = sizeof(TUTORIAL_chunk_list) / sizeof(TUTORIAL_chunk_list[0]); break; default: *chunkList = NULL; diff --git a/source/vertical_menu.cpp b/source/vertical_menu.cpp index 3752c30..003a10f 100644 --- a/source/vertical_menu.cpp +++ b/source/vertical_menu.cpp @@ -10,20 +10,18 @@ i_item_widget::~i_item_widget() {} -i_vertical_menu_state_changed_handler::~i_vertical_menu_state_changed_handler() -{ -} +i_vertical_menu_state_changed_handler::~i_vertical_menu_state_changed_handler() {} i_run_cycle_handler::~i_run_cycle_handler() {} -static unsigned get_num_visible_items(unsigned vertical_menu_height, - unsigned margin_top, unsigned margin_bottom, unsigned item_height) +static unsigned get_num_visible_items(unsigned vertical_menu_height, unsigned margin_top, + unsigned margin_bottom, unsigned item_height) { return ((vertical_menu_height - margin_top - margin_bottom) / item_height); } -static unsigned get_viewport_end_index(unsigned viewport_start_index, - unsigned num_visible_items, unsigned total_items) +static unsigned get_viewport_end_index( + unsigned viewport_start_index, unsigned num_visible_items, unsigned total_items) { unsigned end_index = viewport_start_index + num_visible_items; // bounds check to make sure we don't go past the total number of items @@ -33,9 +31,9 @@ static unsigned get_viewport_end_index(unsigned viewport_start_index, } vertical_menu::vertical_menu(const vertical_menu_settings &settings) - : settings_(settings), state_changed_handler_(nullptr), - run_cycle_handler_(nullptr), focused_index_(settings.initial_focus_index), - viewport_start_index_(0), items_(), is_focused_(true) + : settings_(settings), state_changed_handler_(nullptr), run_cycle_handler_(nullptr), + focused_index_(settings.initial_focus_index), viewport_start_index_(0), items_(), + is_focused_(true) { } @@ -43,8 +41,8 @@ vertical_menu::~vertical_menu() { clear_item_widgets(); } void vertical_menu::show() { - add_menu_box(settings_.x / TILE_WIDTH, settings_.y / TILE_HEIGHT, - settings_.width, settings_.height); + add_menu_box( + settings_.x / TILE_WIDTH, settings_.y / TILE_HEIGHT, settings_.width, settings_.height); update_viewport(); @@ -56,8 +54,7 @@ void vertical_menu::show() // initial selection change notification const unsigned render_index = focused_index_ - viewport_start_index_; handle_selection_change(focused_index_, settings_.x, - settings_.y + settings_.margin_top + - (render_index * settings_.item_height)); + settings_.y + settings_.margin_top + (render_index * settings_.item_height)); } i_item_widget *vertical_menu::get_item_widget_at(unsigned index) const @@ -81,18 +78,11 @@ void vertical_menu::hide() reload_textbox_background(); } -const vertical_menu_settings &vertical_menu::get_settings() const -{ - return settings_; -} +const vertical_menu_settings &vertical_menu::get_settings() const { return settings_; } -void vertical_menu::set_settings(const vertical_menu_settings &settings) -{ - settings_ = settings; -} +void vertical_menu::set_settings(const vertical_menu_settings &settings) { settings_ = settings; } -void vertical_menu::add_item_widgets( - i_item_widget **item_widgets, unsigned num_widgets) +void vertical_menu::add_item_widgets(i_item_widget **item_widgets, unsigned num_widgets) { items_.reserve(items_.size() + num_widgets); for (unsigned i = 0; i < num_widgets; ++i) @@ -101,10 +91,7 @@ void vertical_menu::add_item_widgets( } } -void vertical_menu::add_item_widget(i_item_widget *item_widget) -{ - items_.push_back(item_widget); -} +void vertical_menu::add_item_widget(i_item_widget *item_widget) { items_.push_back(item_widget); } void vertical_menu::clear_item_widgets() { @@ -123,8 +110,7 @@ void vertical_menu::clear_item_widgets() void vertical_menu::set_focused(bool is_focused) { is_focused_ = is_focused; - if (state_changed_handler_ && - settings_.should_hide_state_changed_handler_on_not_focused) + if (state_changed_handler_ && settings_.should_hide_state_changed_handler_on_not_focused) { if (is_focused_) { @@ -156,11 +142,9 @@ MenuInputHandleState vertical_menu::handle_input() { // the child widget is requesting that we update the viewport. // so we do that here and then degrade the result to HANDLED, - // since we've already done the viewport update that the child widget - // requested. + // since we've already done the viewport update that the child widget requested. update_viewport(); - result = MenuInputHandleState::HANDLED; // degrade to HANDLED after - // updating the viewport + result = MenuInputHandleState::HANDLED; // degrade to HANDLED after updating the viewport } if (result != MenuInputHandleState::NOT_HANDLED) { @@ -168,8 +152,8 @@ MenuInputHandleState vertical_menu::handle_input() } // if the user presses B, and the current settings allow it, - // we will return the CANCELLED state, which the caller can use to know that - // they should exit the menu. + // we will return the CANCELLED state, which the caller can use to know that they should exit + // the menu. if (settings_.allow_cancel && key_hit(KEY_B)) { return MenuInputHandleState::CANCELLED; @@ -177,11 +161,10 @@ MenuInputHandleState vertical_menu::handle_input() if (key_hit(KEY_DOWN)) { - const unsigned num_visible_items = - get_num_visible_items(settings_.height, settings_.margin_top, - settings_.margin_bottom, settings_.item_height); - const unsigned current_viewport_end_index = get_viewport_end_index( - viewport_start_index_, num_visible_items, items_.size()); + const unsigned num_visible_items = get_num_visible_items( + settings_.height, settings_.margin_top, settings_.margin_bottom, settings_.item_height); + const unsigned current_viewport_end_index = + get_viewport_end_index(viewport_start_index_, num_visible_items, items_.size()); ++focused_index_; if (focused_index_ == current_viewport_end_index) { @@ -201,11 +184,9 @@ MenuInputHandleState vertical_menu::handle_input() { if (focused_index_ == 0) { - // currently the first item was selected, so do wrap around to the - // end. - const unsigned num_visible_items = - get_num_visible_items(settings_.height, settings_.margin_top, - settings_.margin_bottom, settings_.item_height); + // currently the first item was selected, so do wrap around to the end. + const unsigned num_visible_items = get_num_visible_items(settings_.height, + settings_.margin_top, settings_.margin_bottom, settings_.item_height); const unsigned max_index = items_.size() - 1; viewport_start_index_ = (max_index - num_visible_items) + 1; @@ -219,8 +200,7 @@ MenuInputHandleState vertical_menu::handle_input() did_navigate = true; } - // if we did navigate, we need to update the viewport and state changed - // handler. + // if we did navigate, we need to update the viewport and state changed handler. if (did_navigate) { const unsigned render_index = focused_index_ - viewport_start_index_; @@ -229,8 +209,7 @@ MenuInputHandleState vertical_menu::handle_input() update_viewport(); } handle_selection_change(focused_index_, settings_.x, - settings_.y + settings_.margin_top + - (render_index * settings_.item_height)); + settings_.y + settings_.margin_top + (render_index * settings_.item_height)); return MenuInputHandleState::HANDLED; } @@ -244,10 +223,9 @@ void vertical_menu::update_viewport() u32 textTableNumChunks; u32 textTableChunkSize; - get_text_table_chunks(settings_.text_table_index, &textTableChunkList, - &textTableNumChunks, &textTableChunkSize); - FileContainerReader text_table( - textTableChunkList, textTableNumChunks, textTableChunkSize); + get_text_table_chunks( + settings_.text_table_index, &textTableChunkList, &textTableNumChunks, &textTableChunkSize); + FileContainerReader text_table(textTableChunkList, textTableNumChunks, textTableChunkSize); clear_viewport(); @@ -256,26 +234,24 @@ void vertical_menu::update_viewport() text_table.init(decompression_buffer, sizeof(decompression_buffer)); } - const unsigned num_visible_items = get_num_visible_items(settings_.height, - settings_.margin_top, settings_.margin_bottom, settings_.item_height); - const unsigned viewport_end_index = get_viewport_end_index( - viewport_start_index_, num_visible_items, items_.size()); + const unsigned num_visible_items = get_num_visible_items( + settings_.height, settings_.margin_top, settings_.margin_bottom, settings_.item_height); + const unsigned viewport_end_index = + get_viewport_end_index(viewport_start_index_, num_visible_items, items_.size()); unsigned cur_y = settings_.y + settings_.margin_top; for (unsigned i = viewport_start_index_; i < viewport_end_index; ++i) { - items_[i]->render_item( - text_table, settings_.x, cur_y, (i == focused_index_)); + items_[i]->render_item(text_table, settings_.x, cur_y, (i == focused_index_)); cur_y += settings_.item_height; } } void vertical_menu::clear_viewport() { - // tte_erase_rect expects (left, top, right, bottom), not (x, y, width, - // height) - tte_erase_rect(settings_.x, settings_.y, settings_.x + settings_.width, - settings_.y + settings_.height); + // tte_erase_rect expects (left, top, right, bottom), not (x, y, width, height) + tte_erase_rect( + settings_.x, settings_.y, settings_.x + settings_.width, settings_.y + settings_.height); } unsigned vertical_menu::run() @@ -312,8 +288,7 @@ unsigned vertical_menu::run() return UINT32_MAX; } -void vertical_menu::set_state_changed_handler( - i_vertical_menu_state_changed_handler *handler) +void vertical_menu::set_state_changed_handler(i_vertical_menu_state_changed_handler *handler) { state_changed_handler_ = handler; } @@ -323,8 +298,7 @@ void vertical_menu::set_run_cycle_handler(i_run_cycle_handler *handler) run_cycle_handler_ = handler; } -void vertical_menu::handle_selection_change( - unsigned new_index, unsigned x, unsigned y) +void vertical_menu::handle_selection_change(unsigned new_index, unsigned x, unsigned y) { if (state_changed_handler_) { @@ -332,17 +306,11 @@ void vertical_menu::handle_selection_change( } } -simple_item_renderer::simple_item_renderer(const simple_item_widget_data &data) - : data_(data) -{ -} +simple_item_renderer::simple_item_renderer(const simple_item_widget_data &data) : data_(data) {} simple_item_renderer::~simple_item_renderer() {} -const simple_item_widget_data &simple_item_renderer::get_data() const -{ - return data_; -} +const simple_item_widget_data &simple_item_renderer::get_data() const { return data_; } void simple_item_renderer::render_item( FileContainerReader &text_table, unsigned x, unsigned y, bool is_focused) diff --git a/source/vertical_menu_cursor_handler.cpp b/source/vertical_menu_cursor_handler.cpp index 8ace884..135722f 100644 --- a/source/vertical_menu_cursor_handler.cpp +++ b/source/vertical_menu_cursor_handler.cpp @@ -1,8 +1,7 @@ #include "vertical_menu_cursor_handler.h" #include "sprite_data.h" -vertical_menu_cursor_handler::vertical_menu_cursor_handler( - s16 cursor_offset_x, s16 cursor_offset_y) +vertical_menu_cursor_handler::vertical_menu_cursor_handler(s16 cursor_offset_x, s16 cursor_offset_y) : cursor_offset_x_(cursor_offset_x), cursor_offset_y_(cursor_offset_y) { } @@ -13,8 +12,7 @@ void vertical_menu_cursor_handler::on_show() { obj_unhide(point_arrow, 0); } void vertical_menu_cursor_handler::on_hide() { obj_hide(point_arrow); } -void vertical_menu_cursor_handler::on_selection_changed( - unsigned new_index, unsigned x, unsigned y) +void vertical_menu_cursor_handler::on_selection_changed(unsigned new_index, unsigned x, unsigned y) { // set the cursor pos accordingly const int cursor_x = static_cast(x) + cursor_offset_x_;