Skip to content

Commit

Permalink
Cleanup so things around the save manager
Browse files Browse the repository at this point in the history
  • Loading branch information
Archez committed Jan 8, 2025
1 parent 5d514ef commit 984dbf5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
6 changes: 5 additions & 1 deletion mm/2s2h/BenJsonConversions.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#ifndef BenJsonConversions_hpp
#define BenJsonConversions_hpp

#include "z64.h"
#include <nlohmann/json.hpp>

extern "C" {
#include "z64save.h"
#include "macros.h"
}

using json = nlohmann::json;

void to_json(json& j, const DpadSaveInfo& dpadEquips) {
Expand Down
17 changes: 12 additions & 5 deletions mm/2s2h/SaveManager/SaveManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
#include <nlohmann/json.hpp>
#include <libultraship/libultraship.h>

#include "macros.h"
#include "BenJsonConversions.hpp"
#include "BenPort.h"

extern "C" {
#include "z64save.h"
#include "macros.h"
#include "src/overlays/gamestates/ovl_file_choose/z_file_select.h"
extern FileSelectState* gFileSelectState;

u16 Sram_CalcChecksum(void* data, size_t count);
}

// This entire thing is temporary until we have a more robust save system that
Expand All @@ -30,9 +29,13 @@ typedef enum FlashSlotFile {
/* 7 */ FLASH_SLOT_FILE_2_OWL_SAVE_BACKUP,
/* 8 */ FLASH_SLOT_FILE_SRAM_HEADER,
/* 9 */ FLASH_SLOT_FILE_SRAM_HEADER_BACKUP,
/* 10 */ FLASH_SLOT_MAX,
} FlashSlotFile;

#undef GET_NEWF

#define GET_NEWF(save, index) (save.saveInfo.playerData.newf[index])

#define IS_VALID_FILE(save) \
((GET_NEWF(save, 0) == 'Z') && (GET_NEWF(save, 1) == 'E') && (GET_NEWF(save, 2) == 'L') && \
(GET_NEWF(save, 3) == 'D') && (GET_NEWF(save, 4) == 'A') && (GET_NEWF(save, 5) == '3'))
Expand Down Expand Up @@ -184,7 +187,7 @@ int SaveManager_GetOpenFileSlot() {
FlashSlotFile SaveManager_GetFlashSlotFileFromPages(u32 pageNum, u32 pageCount) {
FlashSlotFile flashSlotFile = FLASH_SLOT_FILE_UNAVAILABLE;

for (u32 i = 0; i < ARRAY_COUNT(gFlashSaveStartPages) - 1; i++) {
for (u32 i = 0; i < FLASH_SLOT_MAX; i++) {
// Verify that the requested pages align with expected values
if (pageNum == (u32)gFlashSaveStartPages[i] &&
(pageCount == (u32)gFlashSaveNumPages[i] || pageCount == (u32)gFlashSpecialSaveNumPages[i])) {
Expand Down Expand Up @@ -299,7 +302,9 @@ extern "C" void SaveManager_SysFlashrom_WriteData(u8* saveBuffer, u32 pageNum, u
}

// A new cycle save with the "special" page count means that both the regular slot and the backup slot should be
// saved together. We replicate that here by running the save again on the matching backup slot
// saved together. We replicate that here by running the save again on the matching backup slot.
// Note: This is not accounting for the sram header writing a disk backup. It does not feel important to do so.
// If we ever feel like we want a global save backup, then we just need to add it to this condition.
if ((flashSlotFile == FLASH_SLOT_FILE_1_NEW_CYCLE || flashSlotFile == FLASH_SLOT_FILE_2_NEW_CYCLE) &&
pageCount == (u32)gFlashSpecialSaveNumPages[flashSlotFile]) {
SaveManager_SysFlashrom_WriteData(saveBuffer, gFlashSaveStartPages[flashSlotFile + 1],
Expand Down Expand Up @@ -393,6 +398,8 @@ extern "C" void SaveManager_SysFlashrom_WriteData(u8* saveBuffer, u32 pageNum, u
}
break;
}
default:
break;
}
}

Expand Down
2 changes: 1 addition & 1 deletion mm/include/z64save.h
Original file line number Diff line number Diff line change
Expand Up @@ -1762,7 +1762,7 @@ void func_80147314(SramContext* sramCtx, s32 fileNum); // Removes Owl Saves

extern u32 gSramSlotOffsets[];
extern u8 gAmmoItems[];
extern s32 gFlashSaveStartPages[10];
extern s32 gFlashSaveStartPages[];
extern s32 gFlashSaveNumPages[];
extern s32 gFlashSpecialSaveNumPages[];
extern s32 gFlashOwlSaveStartPages[];
Expand Down
2 changes: 1 addition & 1 deletion mm/src/code/z_sram_NES.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ u8 gAmmoItems[ITEM_NUM_SLOTS] = {
};

// Stores flash start page number
s32 gFlashSaveStartPages[10] = {
s32 gFlashSaveStartPages[] = {
0, // File 1 New Cycle Save
0x40, // File 1 New Cycle Save Backup
0x80, // File 2 New Cycle Save
Expand Down

0 comments on commit 984dbf5

Please sign in to comment.