diff --git a/include/FileContainerReader.h b/include/FileContainerReader.h index f439dbd..2515fcf 100644 --- a/include/FileContainerReader.h +++ b/include/FileContainerReader.h @@ -7,33 +7,43 @@ #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); + public: + 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); @@ -44,10 +54,10 @@ public: /** * @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); + const char *getFileName(u32 fileIndex); /** * @brief This function returns the size of the file at the given index. @@ -55,26 +65,33 @@ public: 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); @@ -85,25 +102,28 @@ public: 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) */ void readFile(u32 fileIndex, u8 *buffer); -protected: -private: + + 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 dc10807..8c198a1 100644 --- a/include/Gen3CartridgeSaveReader.h +++ b/include/Gen3CartridgeSaveReader.h @@ -7,29 +7,30 @@ /** * @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. - * - * 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. - * + * + * 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. + * + * 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. */ class Gen3CartridgeSaveReader { -public: + public: Gen3CartridgeSaveReader(u8 *sector_buffer); ~Gen3CartridgeSaveReader(); void read(u8 *buffer, u32 size); - void readUint8(u8& outByte); - void readUint16(u16& outWord, Endianness fieldEndianness); - void readUint32(u32& outDWord, Endianness fieldEndianness); + void readUint8(u8 &outByte); + void readUint16(u16 &outWord, Endianness fieldEndianness); + void readUint32(u32 &outDWord, Endianness fieldEndianness); void write(const u8 *buffer, u32 size); void writeUint8(u8 value); @@ -38,8 +39,8 @@ public: 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); @@ -49,11 +50,13 @@ public: 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; -protected: -private: + + protected: + private: uintptr_t sector_start_; u8 *sector_buffer_; u8 *cur_; diff --git a/include/background_engine.h b/include/background_engine.h index b782175..dd07854 100644 --- a/include/background_engine.h +++ b/include/background_engine.h @@ -1,9 +1,9 @@ #ifndef BG_ENGINE_H #define BG_ENGINE_H +#include "global_frame_controller.h" #include "sprite_data.h" #include "text_engine.h" -#include "global_frame_controller.h" // This order does matter, as if two backgrounds are on the same layer, // the lowest number will be the one that is displayed @@ -15,9 +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); @@ -27,11 +28,13 @@ 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. + * @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 6e76126..da7bc4e 100644 --- a/include/box_menu.h +++ b/include/box_menu.h @@ -1,17 +1,17 @@ #ifndef BOX_MENU_H #define BOX_MENU_H -#include -#include "string.h" -#include "button_handler.h" -#include "string_view" -#include "button_handler.h" #include "PokeBox.h" +#include "button_handler.h" +#include "string.h" +#include "string_view" +#include #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 @@ -24,14 +24,14 @@ class Box_Menu { -public: + public: Box_Menu(); - int box_main(PokeBox* box, Version vers); -private: + int box_main(PokeBox *box, Version vers); + + private: int curr_button; int x; int y; - }; #endif \ No newline at end of file diff --git a/include/button_handler.h b/include/button_handler.h index d4ce3ef..3951e75 100644 --- a/include/button_handler.h +++ b/include/button_handler.h @@ -5,7 +5,7 @@ class Button { -public: + public: Button(); Button(OBJ_ATTR *L, OBJ_ATTR *R, int nLeft_button_width); // wide buttons Button(OBJ_ATTR *B); // short button @@ -17,7 +17,7 @@ public: int x; int y; -private: + private: int left_button_width; bool highlighted; OBJ_ATTR *button_L; diff --git a/include/button_menu.h b/include/button_menu.h index 0aea43c..275c785 100644 --- a/include/button_menu.h +++ b/include/button_menu.h @@ -1,8 +1,8 @@ #ifndef MAIN_MENU_H #define MAIN_MENU_H -#include #include "libstd_replacements.h" +#include #include "button_handler.h" @@ -19,8 +19,9 @@ class Button_Menu { -public: - Button_Menu(int nRows, int nColumns, int nButton_width, int nButton_height, bool enable_cancel); + public: + 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(); @@ -34,7 +35,7 @@ public: void set_bottom_row_offset(int nBottom_offset); void clear_vector(); -private: + private: ptgb::vector