Fix issue with EZ Flash Multiboot saving not clearing data

This commit is contained in:
Lorenzooone 2023-05-26 13:01:21 +02:00
parent 2b16e6d360
commit 4b00d24f35

View File

@ -13,6 +13,7 @@
#define FRAMES_BETWEEN_CHECKS ((1*FPS)/12)
#define MAGIC_NUMBER 0x08012025
#define INVALID_MAGIC_NUMBER 0xFFFFFFFF
#define NUM_SLOTS 2
#define INVALID_SLOT NUM_SLOTS
#define SAVE_SLOT_INDEX_POS 0xDFFC
@ -79,6 +80,7 @@ void trade_reorder_party_entries(struct game_data_t*, struct gen3_mon_data_unenc
u32 calc_checksum_save_buffer(u32*, u16);
static void start_gen3_save_data_transfer(void);
static void end_gen3_save_data_transfer(void);
void write_magic_number(u8, u8, u32);
const u16 summable_bytes[SECTION_TOTAL] = {3884, MAX_SECTION_SIZE, MAX_SECTION_SIZE, MAX_SECTION_SIZE, 3848, MAX_SECTION_SIZE, MAX_SECTION_SIZE, MAX_SECTION_SIZE, MAX_SECTION_SIZE, MAX_SECTION_SIZE, MAX_SECTION_SIZE, MAX_SECTION_SIZE, MAX_SECTION_SIZE, 2000};
const u16 summable_bytes_section0[NUM_MAIN_GAME_ID] = {0x890, 0xF24, 0xF2C};
@ -723,9 +725,17 @@ u8 pre_update_save(struct game_data_t* game_data, struct game_data_priv_t* game_
u8 complete_save(u8 base_slot, struct game_data_t* game_data) {
u8 target_slot = get_next_slot(base_slot);
for(int i = 0; i < SECTION_TOTAL; i++)
for(int i = 0; i < SECTION_TOTAL; i++) {
// Clear sector
erase_sector((base_slot * SAVE_SLOT_SIZE) + (i * SECTION_SIZE));
// Fix issue with EZ Flash not really deleting the data...
// Maybe other Flashcarts too... :/
if((i == 0) && (read_magic_number(base_slot, i) == MAGIC_NUMBER))
// Invalidate the slot
write_magic_number(base_slot, i, INVALID_MAGIC_NUMBER);
}
if(get_slot(&game_data->game_identifier) != target_slot)
return 0;
return 1;
@ -790,6 +800,10 @@ IWRAM_CODE u32 read_magic_number(u8 slot, u8 section){
return read_int_save((slot * SAVE_SLOT_SIZE) + MAGIC_NUMBER_POS + (section * SECTION_SIZE));
}
IWRAM_CODE void write_magic_number(u8 slot, u8 section, u32 value){
write_int_save((slot * SAVE_SLOT_SIZE) + MAGIC_NUMBER_POS + (section * SECTION_SIZE), value);
}
IWRAM_CODE u8 has_cartridge_been_removed(){
u8 retval = 0;
if(get_is_cartridge_loaded()) {