Applying formatting and moving libraries into specific folders

This commit is contained in:
GearsProgress
2026-10-18 11:07:35 -04:00
parent 1e90aa40ce
commit f1e2b62e4a
74 changed files with 6147 additions and 5199 deletions

View File

@@ -1,10 +1,10 @@
#include <tonc.h>
#include "libstd_replacements.h"
#include "flash_mem.h"
#include "libraries/Pokemon-Gen3-to-Gen-X/include/save.h"
#include "libstd_replacements.h"
#include "pokemon_data.h"
#include "rom_data.h"
#include "libraries/Pokemon-Gen3-to-Gen-X/include/save.h"
#include "text_engine.h"
#include <tonc.h>
#define READ_SAVE_SECTIONS 14
#define TOTAL_SAVE_SECTIONS 14
@@ -23,7 +23,8 @@ 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.
// Save indices are little-endian in-sector; decode directly without byte
// swapping.
const u32 saveAIndex = static_cast<u32>(save_A_index[0]) |
(static_cast<u32>(save_A_index[1]) << 8) |
(static_cast<u32>(save_A_index[2]) << 16) |
@@ -40,8 +41,9 @@ 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++)
@@ -55,14 +57,17 @@ 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<unsigned>(memory_section_array[mem_section] + mem_start)));
tte_write(ptgb::to_string(static_cast<unsigned>(
memory_section_array[mem_section] + mem_start)));
tte_write("\n");
for (int i = mem_start; i < (128 + mem_start); i++)
{
@@ -113,7 +118,8 @@ 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);
*/
@@ -135,12 +141,15 @@ 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: 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;
// 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;
// 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<u32>(sector_buffer[offset]) |
@@ -150,43 +159,56 @@ 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;
sector_buffer[checksum_offset + 1] = (small_checksum & 0xFF00) >> 8;
}
bool read_flag(u16 flag_id)
{
if (false)
{
//tte_set_pos(0, 0);
// 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)], &global_memory_buffer[0], 0x1000);
u8 flags = global_memory_buffer[(curr_GBA_rom.offset_flags + (flag_id / 8)) % 0xF80];
copy_save_to_ram(
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];
tte_write(ptgb::to_string((flags >> (flag_id % 8)) & 0b1));
while (true)
{
};
}
copy_save_to_ram(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];
copy_save_to_ram(
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];
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);