Match func_801457CC (z_sram_NES.c OK) (#1472)

* Match func_801457CC

* cleanup

* pads

* ITEM_NUM_SLOTS

* fix macro
This commit is contained in:
engineer124 2023-11-12 09:08:39 +11:00 committed by GitHub
parent 8d33d36a9b
commit 71d83a5e15
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 69 additions and 71 deletions

View File

@ -3121,7 +3121,7 @@ void Inventory_UnequipItem(s16 item) {
s32 Inventory_ReplaceItem(PlayState* play, u8 oldItem, u8 newItem) {
u8 i;
for (i = 0; i < 24; i++) {
for (i = 0; i < ITEM_NUM_SLOTS; i++) {
if (gSaveContext.save.saveInfo.inventory.items[i] == oldItem) {
gSaveContext.save.saveInfo.inventory.items[i] = newItem;

View File

@ -1,6 +1,7 @@
#include "global.h"
#include "z64horse.h"
#include "overlays/gamestates/ovl_file_choose/z_file_select.h"
#include "overlays/kaleido_scope/ovl_kaleido_scope/z_kaleido_scope.h"
void Sram_SyncWriteToFlash(SramContext* sramCtx, s32 curPage, s32 numPages);
void func_80147314(SramContext* sramCtx, s32 fileNum);
@ -270,7 +271,7 @@ u32 gSramSlotOffsets[] = {
OOT_SLOT_OFFSET(5),
};
u8 gAmmoItems[] = {
u8 gAmmoItems[ITEM_NUM_SLOTS] = {
ITEM_NONE, // SLOT_OCARINA
ITEM_BOW, // SLOT_BOW
ITEM_NONE, // SLOT_ARROW_FIRE
@ -529,7 +530,7 @@ void Sram_SaveEndOfCycle(PlayState* play) {
}
}
for (i = 0; i < ARRAY_COUNT(gAmmoItems); i++) {
for (i = 0; i < ITEM_NUM_SLOTS; i++) {
if (gAmmoItems[i] != ITEM_NONE) {
if ((gSaveContext.save.saveInfo.inventory.items[i] != ITEM_NONE) && (i != SLOT_PICTOGRAPH_BOX)) {
item = gSaveContext.save.saveInfo.inventory.items[i];
@ -1375,18 +1376,17 @@ void func_80145698(SramContext* sramCtx) {
}
// Verifies save and use backup if corrupted?
#ifdef NON_EQUIVALENT
void func_801457CC(GameState* gameState, SramContext* sramCtx) {
FileSelectState* fileSelect = (FileSelectState*)gameState;
u16 sp7A;
u16 oldCheckSum; // s2
u16 oldCheckSum;
u16 sp76;
u16 sp64; // sp74?
u16 sp64;
u16 phi_s2;
u16 phi_s7;
u16 pad;
u16 sp6E;
u16 newCheckSum; // v0
u16 phi_a0; // maskCount
u16 newCheckSum;
u16 maskCount;
if (gSaveContext.flashSaveAvailable) {
D_801F6AF0 = gSaveContext.save.time;
@ -1424,23 +1424,23 @@ void func_801457CC(GameState* gameState, SramContext* sramCtx) {
Lib_MemCpy(&gSaveContext, sramCtx->saveBuf, gFlashSaveSizes[sp64]);
// test checksum of main save
oldCheckSum = gSaveContext.save.saveInfo.checksum;
phi_s2 = gSaveContext.save.saveInfo.checksum;
gSaveContext.save.saveInfo.checksum = 0;
newCheckSum = Sram_CalcChecksum(&gSaveContext, gFlashSaveSizes[sp64]);
gSaveContext.save.saveInfo.checksum = oldCheckSum;
gSaveContext.save.saveInfo.checksum = phi_s2;
if (CHECK_NEWF(gSaveContext.save.saveInfo.playerData.newf) || (oldCheckSum != newCheckSum)) {
if (CHECK_NEWF(gSaveContext.save.saveInfo.playerData.newf) || (newCheckSum != phi_s2)) {
// checksum didnt match, try backup save
sp6E = 1;
if ((gSaveContext.save.saveInfo.playerData.newf[0] == 'Z') &&
(gSaveContext.save.saveInfo.playerData.newf[1] == 'E')) {
phi_s2 = false;
}
// phi_s2 = false;
(gSaveContext.save.saveInfo.playerData.newf[1] == 'E') &&
(gSaveContext.save.saveInfo.playerData.newf[2] == 'L') &&
(gSaveContext.save.saveInfo.playerData.newf[3] == 'D') &&
(gSaveContext.save.saveInfo.playerData.newf[4] == 'A')) {}
// read backup save from flash
phi_s2 = false;
if (SysFlashrom_ReadData(sramCtx->saveBuf, gFlashSaveStartPages[sp64 + 1],
gFlashSaveNumPages[sp64 + 1]) != 0) {
// backup save didn't work
@ -1453,9 +1453,8 @@ void func_801457CC(GameState* gameState, SramContext* sramCtx) {
oldCheckSum = gSaveContext.save.saveInfo.checksum;
gSaveContext.save.saveInfo.checksum = 0;
//! FAKE: (s32)sp64
if (phi_s2 || CHECK_NEWF(gSaveContext.save.saveInfo.playerData.newf) ||
(oldCheckSum != Sram_CalcChecksum(&gSaveContext, gFlashSaveSizes[(s32)sp64]))) {
(oldCheckSum != Sram_CalcChecksum(&gSaveContext, gFlashSaveSizes[sp64]))) {
// backup save didn't work
bzero(sramCtx->saveBuf, SAVE_BUFFER_SIZE);
Lib_MemCpy(&gSaveContext.save, sramCtx->saveBuf, sizeof(Save));
@ -1465,9 +1464,8 @@ void func_801457CC(GameState* gameState, SramContext* sramCtx) {
}
gSaveContext.save.saveInfo.checksum = 0;
// FAKE: Needed?
gSaveContext.save.saveInfo.checksum =
Sram_CalcChecksum(&gSaveContext, gFlashSaveSizes[sp64 & 0xFFFFFFFF]);
//! FAKE: [sp64 + 0]?
gSaveContext.save.saveInfo.checksum = Sram_CalcChecksum(&gSaveContext, gFlashSaveSizes[sp64 + 0]);
for (sp7A = 0; sp7A < ARRAY_COUNT(gSaveContext.save.saveInfo.playerData.newf); sp7A++) {
fileSelect->newf[sp76][sp7A] = gSaveContext.save.saveInfo.playerData.newf[sp7A];
@ -1490,14 +1488,14 @@ void func_801457CC(GameState* gameState, SramContext* sramCtx) {
fileSelect->rupees[sp76] = gSaveContext.save.saveInfo.playerData.rupees;
fileSelect->walletUpgrades[sp76] = CUR_UPG_VALUE(UPG_WALLET);
for (sp7A = 0, phi_a0 = 0; sp7A < 24; sp7A++) {
if (gSaveContext.save.saveInfo.inventory.items[sp7A + 24] != 0xFF) {
phi_a0++;
for (sp7A = 0, maskCount = 0; sp7A < MASK_NUM_SLOTS; sp7A++) {
if (gSaveContext.save.saveInfo.inventory.items[sp7A + ITEM_NUM_SLOTS] == ITEM_NONE) {
continue;
}
maskCount++;
}
fileSelect->maskCount[sp76] = phi_a0;
fileSelect->heartPieceCount[sp76] =
((gSaveContext.save.saveInfo.inventory.questItems & 0xF0000000) >> 0x1C);
fileSelect->maskCount[sp76] = maskCount;
fileSelect->heartPieceCount[sp76] = GET_QUEST_HEART_PIECE_COUNT;
}
if (sp6E == 1) {
@ -1506,20 +1504,20 @@ void func_801457CC(GameState* gameState, SramContext* sramCtx) {
Sram_SyncWriteToFlash(sramCtx, gFlashSaveStartPages[sp64], gFlashSpecialSaveNumPages[sp64]);
} else if (!sp6E) {
// main save
phi_s7 = gSaveContext.save.saveInfo.checksum;
oldCheckSum = gSaveContext.save.saveInfo.checksum;
if (SysFlashrom_ReadData(sramCtx->saveBuf, gFlashSaveStartPages[sp64 + 1],
gFlashSaveNumPages[sp64 + 1]) != 0) {
oldCheckSum = 1;
phi_s2 = 1;
} else {
Lib_MemCpy(&gSaveContext.save, sramCtx->saveBuf, sizeof(Save));
oldCheckSum = gSaveContext.save.saveInfo.checksum;
phi_s2 = gSaveContext.save.saveInfo.checksum;
gSaveContext.save.saveInfo.checksum = 0;
sp7A = Sram_CalcChecksum(&gSaveContext.save, sizeof(Save));
}
if (CHECK_NEWF(gSaveContext.save.saveInfo.playerData.newf) || (oldCheckSum != sp7A) ||
(oldCheckSum != phi_s7)) {
if (CHECK_NEWF(gSaveContext.save.saveInfo.playerData.newf) || (sp7A != phi_s2) ||
(oldCheckSum != phi_s2)) {
SysFlashrom_ReadData(sramCtx->saveBuf, gFlashSaveStartPages[sp64], gFlashSaveNumPages[sp64]);
Lib_MemCpy(&gSaveContext.save, sramCtx->saveBuf, sizeof(Save));
Lib_MemCpy(&sramCtx->saveBuf[0x2000], &gSaveContext.save, sizeof(Save));
@ -1539,24 +1537,26 @@ void func_801457CC(GameState* gameState, SramContext* sramCtx) {
Lib_MemCpy(&gSaveContext, sramCtx->saveBuf, gFlashSaveSizes[sp64]);
} else {
Lib_MemCpy(&gSaveContext, sramCtx->saveBuf, gFlashSaveSizes[sp64]);
oldCheckSum = gSaveContext.save.saveInfo.checksum;
phi_s2 = gSaveContext.save.saveInfo.checksum;
// test checksum of main save
gSaveContext.save.saveInfo.checksum = 0;
newCheckSum = Sram_CalcChecksum(&gSaveContext, gFlashSaveSizes[sp64]);
gSaveContext.save.saveInfo.checksum = oldCheckSum;
gSaveContext.save.saveInfo.checksum = phi_s2;
if (CHECK_NEWF(gSaveContext.save.saveInfo.playerData.newf) || (oldCheckSum != newCheckSum)) {
if (CHECK_NEWF(gSaveContext.save.saveInfo.playerData.newf) || (newCheckSum != phi_s2)) {
// checksum didnt match, try backup save
sp6E = 1;
if ((gSaveContext.save.saveInfo.playerData.newf[0] == 'Z') &&
(gSaveContext.save.saveInfo.playerData.newf[1] == 'E')) {
phi_s2 = false;
}
(gSaveContext.save.saveInfo.playerData.newf[1] == 'E') &&
(gSaveContext.save.saveInfo.playerData.newf[2] == 'L') &&
(gSaveContext.save.saveInfo.playerData.newf[3] == 'D') &&
(gSaveContext.save.saveInfo.playerData.newf[4] == 'A')) {}
phi_s2 = false;
// read backup save from flash
if (SysFlashrom_ReadData(sramCtx->saveBuf, gFlashSaveStartPages[sp64 + 1],
gFlashSaveNumPages[sp64 + 1])) {
gFlashSaveNumPages[sp64 + 1]) != 0) {
// backup save didn't work
phi_s2 = true;
}
@ -1577,9 +1577,8 @@ void func_801457CC(GameState* gameState, SramContext* sramCtx) {
}
gSaveContext.save.saveInfo.checksum = 0;
// FAKE: Needed?
gSaveContext.save.saveInfo.checksum =
Sram_CalcChecksum(&gSaveContext, gFlashSaveSizes[sp64 & 0xFFFFFFFF]);
// FAKE: [sp64 + 0]?
gSaveContext.save.saveInfo.checksum = Sram_CalcChecksum(&gSaveContext, gFlashSaveSizes[sp64 + 0]);
for (sp7A = 0; sp7A < ARRAY_COUNT(gSaveContext.save.saveInfo.playerData.newf); sp7A++) {
fileSelect->newf[sp76][sp7A] = gSaveContext.save.saveInfo.playerData.newf[sp7A];
@ -1589,7 +1588,8 @@ void func_801457CC(GameState* gameState, SramContext* sramCtx) {
fileSelect->threeDayResetCount[sp76] = gSaveContext.save.saveInfo.playerData.threeDayResetCount;
for (sp7A = 0; sp7A < ARRAY_COUNT(gSaveContext.save.saveInfo.playerData.playerName); sp7A++) {
fileSelect->fileNames[sp76][sp7A] = gSaveContext.save.saveInfo.playerData.playerName[sp7A];
fileSelect->fileNames[sp76][sp7A] =
(u32)gSaveContext.save.saveInfo.playerData.playerName[sp7A];
}
fileSelect->healthCapacity[sp76] = gSaveContext.save.saveInfo.playerData.healthCapacity;
@ -1602,14 +1602,14 @@ void func_801457CC(GameState* gameState, SramContext* sramCtx) {
fileSelect->rupees[sp76] = gSaveContext.save.saveInfo.playerData.rupees;
fileSelect->walletUpgrades[sp76] = CUR_UPG_VALUE(UPG_WALLET);
for (sp7A = 0, phi_a0 = 0; sp7A < 24; sp7A++) {
if (gSaveContext.save.saveInfo.inventory.items[sp7A + 24] != 0xFF) {
phi_a0++;
for (sp7A = 0, maskCount = 0; sp7A < MASK_NUM_SLOTS; sp7A++) {
if (gSaveContext.save.saveInfo.inventory.items[sp7A + ITEM_NUM_SLOTS] == ITEM_NONE) {
continue;
}
maskCount++;
}
fileSelect->maskCount[sp76] = phi_a0;
fileSelect->heartPieceCount[sp76] =
((gSaveContext.save.saveInfo.inventory.questItems & 0xF0000000) >> 0x1C);
fileSelect->maskCount[sp76] = maskCount;
fileSelect->heartPieceCount[sp76] = GET_QUEST_HEART_PIECE_COUNT;
}
if (sp6E == 1) {
@ -1618,20 +1618,20 @@ void func_801457CC(GameState* gameState, SramContext* sramCtx) {
Sram_SyncWriteToFlash(sramCtx, gFlashSaveStartPages[sp64 + 1], gFlashSaveNumPages[sp64 + 1]);
} else if (!sp6E) {
// main save
phi_s7 = gSaveContext.save.saveInfo.checksum;
oldCheckSum = gSaveContext.save.saveInfo.checksum;
if (SysFlashrom_ReadData(sramCtx->saveBuf, gFlashSaveStartPages[sp64 + 1],
gFlashSaveNumPages[sp64 + 1])) {
oldCheckSum = 1;
gFlashSaveNumPages[sp64 + 1]) != 0) {
phi_s2 = 1;
} else {
Lib_MemCpy(&gSaveContext, sramCtx->saveBuf, gFlashSaveSizes[sp64]);
oldCheckSum = gSaveContext.save.saveInfo.checksum;
phi_s2 = gSaveContext.save.saveInfo.checksum;
gSaveContext.save.saveInfo.checksum = 0;
sp7A = Sram_CalcChecksum(&gSaveContext, gFlashSaveSizes[sp64]);
}
if (CHECK_NEWF(gSaveContext.save.saveInfo.playerData.newf) || (oldCheckSum != sp7A) ||
(oldCheckSum != phi_s7)) {
if (CHECK_NEWF(gSaveContext.save.saveInfo.playerData.newf) || (sp7A != phi_s2) ||
(oldCheckSum != phi_s2)) {
SysFlashrom_ReadData(sramCtx->saveBuf, gFlashSaveStartPages[sp64],
gFlashSaveNumPages[sp64]);
Lib_MemCpy(&gSaveContext, sramCtx->saveBuf, gFlashSaveSizes[sp64]);
@ -1673,9 +1673,6 @@ void func_801457CC(GameState* gameState, SramContext* sramCtx) {
gSaveContext.options.language = LANGUAGE_ENG;
}
#else
#pragma GLOBAL_ASM("asm/non_matchings/code/z_sram_NES/func_801457CC.s")
#endif
void Sram_EraseSave(FileSelectState* fileSelect2, SramContext* sramCtx, s32 fileNum) {
FileSelectState* fileSelect = fileSelect2;
@ -1722,8 +1719,8 @@ void Sram_CopySave(FileSelectState* fileSelect2, SramContext* sramCtx) {
fileSelect->rupees[fileSelect->copyDestFileIndex + 2] = gSaveContext.save.saveInfo.playerData.rupees;
fileSelect->walletUpgrades[fileSelect->copyDestFileIndex + 2] = CUR_UPG_VALUE(UPG_WALLET);
for (i = 0, maskCount = 0; i < 24; i++) {
if (gSaveContext.save.saveInfo.inventory.items[i + 24] != ITEM_NONE) {
for (i = 0, maskCount = 0; i < MASK_NUM_SLOTS; i++) {
if (gSaveContext.save.saveInfo.inventory.items[i + ITEM_NUM_SLOTS] != ITEM_NONE) {
maskCount++;
}
}
@ -1763,8 +1760,8 @@ void Sram_CopySave(FileSelectState* fileSelect2, SramContext* sramCtx) {
fileSelect->rupees[fileSelect->copyDestFileIndex] = gSaveContext.save.saveInfo.playerData.rupees;
fileSelect->walletUpgrades[fileSelect->copyDestFileIndex] = CUR_UPG_VALUE(UPG_WALLET);
for (i = 0, maskCount = 0; i < 24; i++) {
if (gSaveContext.save.saveInfo.inventory.items[i + 24] != ITEM_NONE) {
for (i = 0, maskCount = 0; i < MASK_NUM_SLOTS; i++) {
if (gSaveContext.save.saveInfo.inventory.items[i + ITEM_NUM_SLOTS] != ITEM_NONE) {
maskCount++;
}
}
@ -1827,8 +1824,8 @@ void Sram_InitSave(FileSelectState* fileSelect2, SramContext* sramCtx) {
fileSelect->rupees[fileSelect->buttonIndex] = gSaveContext.save.saveInfo.playerData.rupees;
fileSelect->walletUpgrades[fileSelect->buttonIndex] = CUR_UPG_VALUE(UPG_WALLET);
for (i = 0, maskCount = 0; i < 24; i++) {
if (gSaveContext.save.saveInfo.inventory.items[i + 24] != ITEM_NONE) {
for (i = 0, maskCount = 0; i < MASK_NUM_SLOTS; i++) {
if (gSaveContext.save.saveInfo.inventory.items[i + ITEM_NUM_SLOTS] != ITEM_NONE) {
maskCount++;
}
}

View File

@ -7,6 +7,7 @@
#include "prevent_bss_reordering.h"
#include "z_en_thiefbird.h"
#include "overlays/actors/ovl_En_Clear_Tag/z_en_clear_tag.h"
#include "overlays/kaleido_scope/ovl_kaleido_scope/z_kaleido_scope.h"
#define FLAGS \
(ACTOR_FLAG_TARGETABLE | ACTOR_FLAG_UNFRIENDLY | ACTOR_FLAG_200 | ACTOR_FLAG_IGNORE_QUAKE | ACTOR_FLAG_80000000)
@ -224,7 +225,7 @@ s32 func_80C10B0C(EnThiefbird* this, PlayState* play) {
s32 itemId1;
s16 itemId2 = 0;
for (; slotId < 24; slotId++) {
for (; slotId < ITEM_NUM_SLOTS; slotId++) {
if ((gSaveContext.save.saveInfo.inventory.items[slotId] >= ITEM_BOTTLE) &&
(gSaveContext.save.saveInfo.inventory.items[slotId] <= ITEM_POTION_BLUE)) {
isItemFound = true;

View File

@ -422,9 +422,9 @@ void KaleidoScope_DrawInventoryEditor(PlayState* play) {
// Items
// Loop over rows (i)
for (slot = 0, i = 0, rectTop = 38; i < 4; i++, rectTop += 14) {
for (slot = 0, i = 0, rectTop = 38; i < ITEM_GRID_ROWS; i++, rectTop += 14) {
// Loop over columns (j)
for (j = 0, rectLeft = 44; j < 6; j++, slot++, rectLeft += 23) {
for (j = 0, rectLeft = 44; j < ITEM_GRID_COLS; j++, slot++, rectLeft += 23) {
counterDigits[3] = 0;
counterDigits[2] = 0;
if ((slot == SLOT_BOW) || ((slot >= SLOT_BOMB) && (slot <= SLOT_DEKU_NUT)) || (slot == SLOT_POWDER_KEG) ||
@ -456,12 +456,12 @@ void KaleidoScope_DrawInventoryEditor(PlayState* play) {
// Masks
// Loop over rows (i)
for (slot = 0, i = 0, rectTop = 38; i < 4; i++, rectTop += 14) {
for (slot = 0, i = 0, rectTop = 38; i < MASK_GRID_ROWS; i++, rectTop += 14) {
// Loop over columns (j)
for (j = 0, rectLeft = 204; j < 6; j++, slot++, rectLeft += 14) {
for (j = 0, rectLeft = 204; j < MASK_GRID_COLS; j++, slot++, rectLeft += 14) {
counterDigits[2] = 0;
if (gSaveContext.save.saveInfo.inventory.items[SLOT_MASK_POSTMAN + slot] != ITEM_NONE) {
if (gSaveContext.save.saveInfo.inventory.items[slot + ITEM_NUM_SLOTS] != ITEM_NONE) {
counterDigits[2] = 1;
}
KaleidoScope_DrawDigit(play, counterDigits[2], rectLeft, rectTop);