diff --git a/Reuse-filler-save-space-for-Variables-and-Flags.md b/Reuse-filler-save-space-for-Variables-and-Flags.md index 14f9929..1781589 100644 --- a/Reuse-filler-save-space-for-Variables-and-Flags.md +++ b/Reuse-filler-save-space-for-Variables-and-Flags.md @@ -6,24 +6,22 @@ The Tutorial linked above will increase the already existing SaveBlock areas, wh in `include/save.h`, add: ```c -#define N_ADDITIONAL_SAVE_PAYLOAD_SIZE_PER_SLOT 116 -#define N_ADDITIONAL_SAVE_PAYLOAD_SIZE (N_ADDITIONAL_SAVE_PAYLOAD_SIZE_PER_SLOT*NUM_SECTORS_PER_SLOT) -extern u8 gnAdditionalSaveData[]; +#define ADDITIONAL_SAVE_PAYLOAD_SIZE_PER_SLOT 116 +#define ADDITIONAL_SAVE_PAYLOAD_SIZE (ADDITIONAL_SAVE_PAYLOAD_SIZE_PER_SLOT*NUM_SECTORS_PER_SLOT) +extern u8 gAdditionalSaveData[]; ``` in `src/save.c`, add (before the `gSaveDataBuffer` at the start): ```c -#if NCHI__ADDITIONAL_SAVE_PAYLOAD -EWRAM_DATA u8 gnAdditionalSaveData[N_ADDITIONAL_SAVE_PAYLOAD_SIZE]; -#endif +EWRAM_DATA u8 gAdditionalSaveData[ADDITIONAL_SAVE_PAYLOAD_SIZE]; ``` ## Saving the data then, still in `src/save.c`, add this at the end of `HandleWriteSector` (right before the `return` line): ```c -for (i = 0; i < N_ADDITIONAL_SAVE_PAYLOAD_SIZE_PER_SLOT; i++) - gReadWriteSector->unused[i] = gnAdditionalSaveData[i + N_ADDITIONAL_SAVE_PAYLOAD_SIZE_PER_SLOT*sectorId]; +for (i = 0; i < ADDITIONAL_SAVE_PAYLOAD_SIZE_PER_SLOT; i++) + gReadWriteSector->unused[i] = gAdditionalSaveData[i + ADDITIONAL_SAVE_PAYLOAD_SIZE_PER_SLOT*sectorId]; ``` also add the exact same code again in `HandleReplaceSector`, right before the `EraseFlashSector(sector);` line. @@ -31,8 +29,8 @@ also add the exact same code again in `HandleReplaceSector`, right before the `E still in `src/save.c`, add this in `CopySaveSlotData`, right before the end of the `if` block (and after the end of the inner `for` loop): ```c -for (j = 0; j < N_ADDITIONAL_SAVE_PAYLOAD_SIZE_PER_SLOT; j++) - gnAdditionalSaveData[j + N_ADDITIONAL_SAVE_PAYLOAD_SIZE_PER_SLOT*id] = gReadWriteSector->unused[j]; +for (j = 0; j < ADDITIONAL_SAVE_PAYLOAD_SIZE_PER_SLOT; j++) + gAdditionalSaveData[j + ADDITIONAL_SAVE_PAYLOAD_SIZE_PER_SLOT*id] = gReadWriteSector->unused[j]; ``` # Accessing Variables and Flags @@ -45,13 +43,13 @@ in `src/event_data.c`, add this at the top to the includes: then, in the same file, in `GetVarPointer`, add this right before the last `else`: ```c else if (id >= 0xF000) - return &gnAdditionalSaveData[(id - 0xF000)*2]; + return &gAdditionalSaveData[(id - 0xF000)*2]; ``` and in `GetFlagPointer`, again before the last `else`: ```c else if (id >= 0xF000) - return &gnAdditionalSaveData[(id - 0xF000)/8]; + return &gAdditionalSaveData[(id - 0xF000)/8]; ``` # Defining Variables and Flags