1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2024-11-10 19:20:13 +00:00

Match retail z_sram.c (#1722)

This commit is contained in:
cadmic 2024-02-07 07:41:12 -08:00 committed by GitHub
parent 300b3a8ffd
commit be4f3142e0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 18 additions and 9 deletions

View file

@ -1155,10 +1155,10 @@ void Sram_WriteSramHeader(SramContext* sramCtx);
void Sram_InitSram(GameState* gameState, SramContext* sramCtx); void Sram_InitSram(GameState* gameState, SramContext* sramCtx);
void Sram_Alloc(GameState* gameState, SramContext* sramCtx); void Sram_Alloc(GameState* gameState, SramContext* sramCtx);
void Sram_Init(PlayState* play, SramContext* sramCtx); void Sram_Init(PlayState* play, SramContext* sramCtx);
void SsSram_Init(u32 addr, u8 handleType, u8 handleDomain, u8 handleLatency, u8 handlePageSize, u8 handleRelDuration, void SsSram_Init(s32 addr, u8 handleType, u8 handleDomain, u8 handleLatency, u8 handlePageSize, u8 handleRelDuration,
u8 handlePulse, u32 handleSpeed); u8 handlePulse, u32 handleSpeed);
void SsSram_Dma(void* dramAddr, size_t size, s32 direction); void SsSram_Dma(void* dramAddr, size_t size, s32 direction);
void SsSram_ReadWrite(u32 addr, void* dramAddr, size_t size, s32 direction); void SsSram_ReadWrite(s32 addr, void* dramAddr, size_t size, s32 direction);
View* View_New(GraphicsContext* gfxCtx); View* View_New(GraphicsContext* gfxCtx);
void View_Free(View* view); void View_Free(View* view);
void View_Init(View*, GraphicsContext*); void View_Init(View*, GraphicsContext*);

View file

@ -511,8 +511,7 @@ void Sram_WriteSave(SramContext* sramCtx) {
gSaveContext.save.info.checksum = 0; gSaveContext.save.info.checksum = 0;
ptr = (u16*)&gSaveContext; ptr = (u16*)&gSaveContext;
checksum = 0; checksum = j = 0;
j = 0;
for (offset = 0; offset < CHECKSUM_SIZE; offset++) { for (offset = 0; offset < CHECKSUM_SIZE; offset++) {
if (++j == 0x20) { if (++j == 0x20) {
@ -618,6 +617,7 @@ void Sram_VerifyAndLoadAllSaves(FileSelectState* fileSelect, SramContext* sramCt
bzero(&gSaveContext.save.totalDays, sizeof(s32)); bzero(&gSaveContext.save.totalDays, sizeof(s32));
bzero(&gSaveContext.save.bgsDayCount, sizeof(s32)); bzero(&gSaveContext.save.bgsDayCount, sizeof(s32));
#if OOT_DEBUG
if (!slotNum) { if (!slotNum) {
Sram_InitDebugSave(); Sram_InitDebugSave();
gSaveContext.save.info.playerData.newf[0] = 'Z'; gSaveContext.save.info.playerData.newf[0] = 'Z';
@ -633,6 +633,9 @@ void Sram_VerifyAndLoadAllSaves(FileSelectState* fileSelect, SramContext* sramCt
} else { } else {
Sram_InitNewSave(); Sram_InitNewSave();
} }
#else
Sram_InitNewSave();
#endif
ptr = (u16*)&gSaveContext; ptr = (u16*)&gSaveContext;
PRINTF("\n--------------------------------------------------------------\n"); PRINTF("\n--------------------------------------------------------------\n");
@ -718,20 +721,26 @@ void Sram_InitSave(FileSelectState* fileSelect, SramContext* sramCtx) {
u16* ptr; u16* ptr;
u16 checksum; u16 checksum;
#if OOT_DEBUG
if (fileSelect->buttonIndex != 0) { if (fileSelect->buttonIndex != 0) {
Sram_InitNewSave(); Sram_InitNewSave();
} else { } else {
Sram_InitDebugSave(); Sram_InitDebugSave();
} }
#else
Sram_InitNewSave();
#endif
gSaveContext.save.entranceIndex = ENTR_LINKS_HOUSE_0; gSaveContext.save.entranceIndex = ENTR_LINKS_HOUSE_0;
gSaveContext.save.linkAge = LINK_AGE_CHILD; gSaveContext.save.linkAge = LINK_AGE_CHILD;
gSaveContext.save.dayTime = CLOCK_TIME(10, 0); gSaveContext.save.dayTime = CLOCK_TIME(10, 0);
gSaveContext.save.cutsceneIndex = 0xFFF1; gSaveContext.save.cutsceneIndex = 0xFFF1;
#if OOT_DEBUG
if (fileSelect->buttonIndex == 0) { if (fileSelect->buttonIndex == 0) {
gSaveContext.save.cutsceneIndex = 0; gSaveContext.save.cutsceneIndex = 0;
} }
#endif
for (offset = 0; offset < 8; offset++) { for (offset = 0; offset < 8; offset++) {
gSaveContext.save.info.playerData.playerName[offset] = fileSelect->fileNames[fileSelect->buttonIndex][offset]; gSaveContext.save.info.playerData.playerName[offset] = fileSelect->fileNames[fileSelect->buttonIndex][offset];
@ -753,10 +762,8 @@ void Sram_InitSave(FileSelectState* fileSelect, SramContext* sramCtx) {
PRINTF("\n$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n"); PRINTF("\n$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n");
ptr = (u16*)&gSaveContext; ptr = (u16*)&gSaveContext;
j = 0;
checksum = 0;
for (offset = 0; offset < CHECKSUM_SIZE; offset++) { for (j = 0, checksum = 0, offset = 0; offset < CHECKSUM_SIZE; offset++) {
PRINTF("%x ", *ptr); PRINTF("%x ", *ptr);
checksum += *ptr++; checksum += *ptr++;
if (++j == 0x20) { if (++j == 0x20) {
@ -893,6 +900,7 @@ void Sram_InitSram(GameState* gameState, SramContext* sramCtx) {
Sram_WriteSramHeader(sramCtx); Sram_WriteSramHeader(sramCtx);
} }
#if OOT_DEBUG
if (CHECK_BTN_ANY(gameState->input[2].cur.button, BTN_DRIGHT)) { if (CHECK_BTN_ANY(gameState->input[2].cur.button, BTN_DRIGHT)) {
bzero(sramCtx->readBuff, SRAM_SIZE); bzero(sramCtx->readBuff, SRAM_SIZE);
for (i = 0; i < CHECKSUM_SIZE; i++) { for (i = 0; i < CHECKSUM_SIZE; i++) {
@ -901,6 +909,7 @@ void Sram_InitSram(GameState* gameState, SramContext* sramCtx) {
SsSram_ReadWrite(OS_K1_TO_PHYSICAL(0xA8000000), sramCtx->readBuff, SRAM_SIZE, OS_WRITE); SsSram_ReadWrite(OS_K1_TO_PHYSICAL(0xA8000000), sramCtx->readBuff, SRAM_SIZE, OS_WRITE);
PRINTF("SRAM破壊!!!!!!\n"); // "SRAM destruction! ! ! ! ! !" PRINTF("SRAM破壊!!!!!!\n"); // "SRAM destruction! ! ! ! ! !"
} }
#endif
// "GOOD! GOOD! Size = %d + %d = %d" // "GOOD! GOOD! Size = %d + %d = %d"
PRINTF(" サイズ=%d + %d %d\n", sizeof(SaveInfo), 4, sizeof(SaveInfo) + 4); PRINTF(" サイズ=%d + %d %d\n", sizeof(SaveInfo), 4, sizeof(SaveInfo) + 4);

View file

@ -9,7 +9,7 @@ typedef struct {
SsSramContext sSsSramContext = { 0 }; SsSramContext sSsSramContext = { 0 };
void SsSram_Init(u32 addr, u8 handleType, u8 handleDomain, u8 handleLatency, u8 handlePageSize, u8 handleRelDuration, void SsSram_Init(s32 addr, u8 handleType, u8 handleDomain, u8 handleLatency, u8 handlePageSize, u8 handleRelDuration,
u8 handlePulse, u32 handleSpeed) { u8 handlePulse, u32 handleSpeed) {
u32 prevInt; u32 prevInt;
OSPiHandle* handle = &sSsSramContext.piHandle; OSPiHandle* handle = &sSsSramContext.piHandle;
@ -49,7 +49,7 @@ void SsSram_Dma(void* dramAddr, size_t size, s32 direction) {
osInvalDCache(dramAddr, size); osInvalDCache(dramAddr, size);
} }
void SsSram_ReadWrite(u32 addr, void* dramAddr, size_t size, s32 direction) { void SsSram_ReadWrite(s32 addr, void* dramAddr, size_t size, s32 direction) {
PRINTF("ssSRAMReadWrite:%08x %08x %08x %d\n", addr, dramAddr, size, direction); PRINTF("ssSRAMReadWrite:%08x %08x %08x %d\n", addr, dramAddr, size, direction);
SsSram_Init(addr, DEVICE_TYPE_SRAM, PI_DOMAIN2, 5, 0xD, 2, 0xC, 0); SsSram_Init(addr, DEVICE_TYPE_SRAM, PI_DOMAIN2, 5, 0xD, 2, 0xC, 0);
SsSram_Dma(dramAddr, size, direction); SsSram_Dma(dramAddr, size, direction);