mirror of
https://github.com/GearsProgress/Poke_Transporter_GB.git
synced 2026-03-21 17:34:42 -05:00
Add a binary table format and convert the text entries into this format in text_helper/main.py. It then gets compressed with zx0. The new text_data_table and streamed_data_table classes exist to read the various entries from this binary table. streamed_data_table specifically exists to use a decompression buffer that is smaller than the actual binary table. But it requires a decompression buffer that is still larger than ZX0_DEFAULT_WINDOW_SIZE (default: 2048 bytes) and will only be able to decompress in chunks of (<decompression_buffer_size> - <ZX0_DEFAULT_WINDOW_SIZE>) bytes Try to keep the binary text tables sufficiently small though, because since zx0 doesn't actually support random access, getting to the last entry is significantly more expensive than reading the first one. And unless you use streamed_data_table, it also requires <uncompressed_size> bytes of stack space, therefore IWRAM to decompress them. I also had to rework script_array because it can no longer reference the strings directly. Instead we now reference the DIA_* "enum" values. We also no longer store an array of script_obj instances, because these were getting stored in IWRAM since they're non-const global variables originally. Instead we now have const arrays of script_obj_params structs, which should end up in .rodata -> therefore EWRAM. Right now, script_obj only supports the PTGB text table (originally the dialogue array). But if the need arises to support other tables as well, I'd consider adding a separate enum to script_obj_params to indicate the specific table. The compilation process will also output .su files in the build folder from now on. These files indicate the stack frame size for every function in every compilation unit, so be sure to check them from time to time. Note that they will only show the stack consumption for that specific function. So to get the worst case stack consumption, you need to manually add all the functions in a certain stack flow.
83 lines
2.6 KiB
C++
83 lines
2.6 KiB
C++
#ifndef _TEXT_DATA_TABLE_H
|
|
#define _TEXT_DATA_TABLE_H
|
|
|
|
#include <cstdint>
|
|
|
|
/**
|
|
* This class fully decompresses a text table in the specified decompression_buffer
|
|
* and then gives you utility functions to retrieve the text entries
|
|
*
|
|
* But it requires a buffer large enough to contain the entire decompressed table.
|
|
* It will also completely decompress the table, which may not what you want.
|
|
*
|
|
* If you want to use a text table in a streamed manner (use smaller decompression buffer and only decompress what's needed)
|
|
* consider using streamed_text_data_table instead.
|
|
*/
|
|
class text_data_table
|
|
{
|
|
public:
|
|
text_data_table(uint8_t *decompression_buffer);
|
|
|
|
/**
|
|
* This function will start the full decompression for the specified compressed_table
|
|
* and stores it in the decompression_buffer_
|
|
*/
|
|
void decompress(const uint8_t *compressed_table);
|
|
|
|
/**
|
|
* Returns the number of text entries in the decompression_buffer_
|
|
*/
|
|
uint16_t get_number_of_text_entries() const;
|
|
|
|
/**
|
|
* This function returns a pointer to a text entry in the decompression_buffer
|
|
*/
|
|
const uint8_t* get_text_entry(uint8_t index) const;
|
|
private:
|
|
uint8_t *decompression_buffer_;
|
|
};
|
|
|
|
/**
|
|
* This class is an alternative to translated_text table.
|
|
* It provides the same functionality, yet in a streamed manner.
|
|
*
|
|
* This allows you to use a decompression_buffer that is smaller than the fully decoded text table and only decompress until
|
|
* you have what you need.
|
|
*
|
|
* To make sure we have access to the table index at all times, you need to specify a buffer to hold the table index as well.
|
|
*
|
|
* REQUIREMENT: decompression_buffer needs to be larger than the zx0 window size!!
|
|
*/
|
|
class streamed_text_data_table
|
|
{
|
|
public:
|
|
streamed_text_data_table(uint8_t *decompression_buffer, uint32_t decompression_buffer_size, uint8_t *index_buffer);
|
|
|
|
/**
|
|
* This function sets up the zx0 decompressor and decompresses the index into the index_buffer
|
|
*/
|
|
void decompress(const uint8_t *compressed_table);
|
|
|
|
/**
|
|
* Returns the number of text entries in the decompression_buffer_
|
|
*/
|
|
uint16_t get_number_of_text_entries() const;
|
|
|
|
/**
|
|
* This function returns a pointer to a text entry in the decompression_buffer
|
|
*/
|
|
const uint8_t* get_text_entry(uint8_t index);
|
|
private:
|
|
uint8_t* get_window_start() const;
|
|
uint8_t* get_window_end() const;
|
|
uint16_t get_current_zx0_window_size() const;
|
|
|
|
const uint8_t *compressed_table_;
|
|
uint8_t *decompression_buffer_;
|
|
uint32_t decompression_buffer_size_;
|
|
uint8_t *index_buffer_;
|
|
mutable uint16_t bytes_decompressed_;
|
|
uint16_t last_chunk_size_;
|
|
};
|
|
|
|
#endif |