From acf2dab66ff223ce6a1c5b2c01bf3d7ce7face85 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Fri, 2 Feb 2018 17:00:21 -1000 Subject: [PATCH] Fix NES memory card saves --- NESEmulator/CNESEmulator.cpp | 22 +++++++++------------- NESEmulator/CNESEmulator.hpp | 2 +- Runtime/CGameOptions.cpp | 11 +++++------ Runtime/MP1/CFrontEndUI.cpp | 5 ++++- 4 files changed, 19 insertions(+), 21 deletions(-) diff --git a/NESEmulator/CNESEmulator.cpp b/NESEmulator/CNESEmulator.cpp index c5a4e4777..3532e79bf 100644 --- a/NESEmulator/CNESEmulator.cpp +++ b/NESEmulator/CNESEmulator.cpp @@ -397,9 +397,8 @@ size_t CNESEmulator::supplyAudio(boo::IAudioVoice& voice, size_t frames, int16_t static int catchupFrames = 0; #endif -bool CNESEmulator::NesEmuMainLoop() +void CNESEmulator::NesEmuMainLoop(bool forceDraw) { - bool drawFrame = false; int start = GetTickCount(); int loopCount = 0; do @@ -411,7 +410,6 @@ bool CNESEmulator::NesEmuMainLoop() #endif //printf("LC RENDER: %d\n", loopCount); m_texture->load(textureImage, visibleImg); - drawFrame = true; emuRenderFrame = false; #if CATCHUP_SKIP if (catchupFrames) @@ -431,7 +429,7 @@ bool CNESEmulator::NesEmuMainLoop() //runs every 8th cpu clock if(apuClock == 8) { - if(!apuCycleURDE()) + if(!apuCycleURDE() && !forceDraw) { #if (WINDOWS_BUILD && DEBUG_MAIN_CALLS) emuMainTimesSkipped++; @@ -515,7 +513,7 @@ bool CNESEmulator::NesEmuMainLoop() } #if 1 - if ((loopCount % 10000) == 0 && GetTickCount() - start >= 14) + if (!forceDraw && (loopCount % 10000) == 0 && GetTickCount() - start >= 14) { #if CATCHUP_SKIP if (catchupFrames < 50) @@ -547,8 +545,6 @@ bool CNESEmulator::NesEmuMainLoop() } emuMainFrameStart = end; #endif - - return drawFrame; } static void nesEmuFdsSetup(uint8_t *src, uint8_t *dst) @@ -884,11 +880,11 @@ bool CNESEmulator::SetPasswordIntoEntryScreen(u8* vram, u8* wram, const u8* pass ++encOff; break; case 1: - lastWord = (lastWord >> 6) | (password[encOff] << 2); + lastWord = (lastWord >> 6) | (u32(password[encOff]) << 2); ++encOff; break; case 2: - lastWord = (lastWord >> 4) | (password[encOff] << 4); + lastWord = (lastWord >> 6) | (u32(password[encOff]) << 4); ++encOff; break; case 3: @@ -898,9 +894,9 @@ bool CNESEmulator::SetPasswordIntoEntryScreen(u8* vram, u8* wram, const u8* pass break; } - u8 name = u8(lastWord & 0x3f); - wram[0x99a + i] = name; - vram[0x109 + chOff] = name; + u8 chName = u8(lastWord & 0x3f); + wram[0x99a + i] = chName; + vram[0x109 + chOff] = chName; ++chOff; if (chOff == 0x6 || chOff == 0x46) ++chOff; // mid-line space @@ -932,7 +928,7 @@ void CNESEmulator::Update() } if (gameOver && !x20_gameOver) for (int i=0 ; i<3 ; ++i) // Three draw loops to ensure password display - while (!NesEmuMainLoop()) {} + NesEmuMainLoop(true); else NesEmuMainLoop(); x20_gameOver = gameOver; diff --git a/NESEmulator/CNESEmulator.hpp b/NESEmulator/CNESEmulator.hpp index ac14b89f4..f717eb1bc 100644 --- a/NESEmulator/CNESEmulator.hpp +++ b/NESEmulator/CNESEmulator.hpp @@ -66,7 +66,7 @@ private: u32 checkDataLen = 0x1FFFC, u32 checksumMagic = 0xA663); void InitializeEmulator(); void DeinitializeEmulator(); - bool NesEmuMainLoop(); + void NesEmuMainLoop(bool forceDraw = false); static bool CheckForGameOver(const u8* vram, u8* passwordOut = nullptr); static EPasswordEntryState CheckForPasswordEntryScreen(const uint8_t* vram); static bool SetPasswordIntoEntryScreen(u8* vram, u8* wram, const u8* password); diff --git a/Runtime/CGameOptions.cpp b/Runtime/CGameOptions.cpp index 7a594b929..307bdbd5d 100644 --- a/Runtime/CGameOptions.cpp +++ b/Runtime/CGameOptions.cpp @@ -62,10 +62,10 @@ const std::pair GameOptionsRegistry[] = CPersistentOptions::CPersistentOptions(CBitStreamReader& stream) { for (int b=0 ; b<98 ; ++b) - x0_[b] = stream.ReadEncoded(1); + x0_[b] = stream.ReadEncoded(8); for (int b=0 ; b<64 ; ++b) - x68_[b] = stream.ReadEncoded(1); + x68_[b] = stream.ReadEncoded(8); xc0_frozenFpsCount = stream.ReadEncoded(2); xc4_frozenBallCount = stream.ReadEncoded(2); @@ -75,7 +75,7 @@ CPersistentOptions::CPersistentOptions(CBitStreamReader& stream) xd0_25_normalModeBeat = stream.ReadEncoded(1); xd0_26_hardModeBeat = stream.ReadEncoded(1); xd0_27_fusionBeat = stream.ReadEncoded(1); - xd0_28_fusionSuitActive = stream.ReadEncoded(1); + xd0_28_fusionSuitActive = false; xd0_29_allItemsCollected = stream.ReadEncoded(1); xbc_autoMapperKeyState = stream.ReadEncoded(2); @@ -108,10 +108,10 @@ CPersistentOptions::CPersistentOptions(CBitStreamReader& stream) void CPersistentOptions::PutTo(CBitStreamWriter& w) const { for (int b=0 ; b<98 ; ++b) - w.WriteEncoded(x0_[b], 1); + w.WriteEncoded(x0_[b], 8); for (int b=0 ; b<64 ; ++b) - w.WriteEncoded(x68_[b], 1); + w.WriteEncoded(x68_[b], 8); w.WriteEncoded(xc0_frozenFpsCount, 2); w.WriteEncoded(xc4_frozenBallCount, 2); @@ -121,7 +121,6 @@ void CPersistentOptions::PutTo(CBitStreamWriter& w) const w.WriteEncoded(xd0_25_normalModeBeat, 1); w.WriteEncoded(xd0_26_hardModeBeat, 1); w.WriteEncoded(xd0_27_fusionBeat, 1); - w.WriteEncoded(xd0_28_fusionSuitActive, 1); w.WriteEncoded(xd0_29_allItemsCollected, 1); w.WriteEncoded(xbc_autoMapperKeyState, 2); diff --git a/Runtime/MP1/CFrontEndUI.cpp b/Runtime/MP1/CFrontEndUI.cpp index 82b5de22d..46c29ae40 100644 --- a/Runtime/MP1/CFrontEndUI.cpp +++ b/Runtime/MP1/CFrontEndUI.cpp @@ -1586,7 +1586,10 @@ void CFrontEndUI::SNesEmulatorFrame::Draw(CSaveGameScreen* saveUi) const return; if (xc_textSupport->GetIsTextSupportFinishedLoading()) { - CGraphics::SetModelMatrix(zeus::CTransform::Translate(-280.f, 0.f, -160.f)); + float aspect = g_Viewport.x8_width / float(g_Viewport.xc_height) / 1.33f; + CGraphics::SetOrtho(-320.f * aspect, 320.f * aspect, 240.f, -240.f, -4096.f, 4096.f); + CGraphics::SetViewPointMatrix(zeus::CTransform::Identity()); + CGraphics::SetModelMatrix(zeus::CTransform::Translate(-220.f, 0.f, -200.f)); xc_textSupport->Render(); } }