Fix NES memory card saves

This commit is contained in:
Jack Andersen 2018-02-02 17:00:21 -10:00
parent 15e5b4bbb8
commit acf2dab66f
4 changed files with 19 additions and 21 deletions

View File

@ -397,9 +397,8 @@ size_t CNESEmulator::supplyAudio(boo::IAudioVoice& voice, size_t frames, int16_t
static int catchupFrames = 0; static int catchupFrames = 0;
#endif #endif
bool CNESEmulator::NesEmuMainLoop() void CNESEmulator::NesEmuMainLoop(bool forceDraw)
{ {
bool drawFrame = false;
int start = GetTickCount(); int start = GetTickCount();
int loopCount = 0; int loopCount = 0;
do do
@ -411,7 +410,6 @@ bool CNESEmulator::NesEmuMainLoop()
#endif #endif
//printf("LC RENDER: %d\n", loopCount); //printf("LC RENDER: %d\n", loopCount);
m_texture->load(textureImage, visibleImg); m_texture->load(textureImage, visibleImg);
drawFrame = true;
emuRenderFrame = false; emuRenderFrame = false;
#if CATCHUP_SKIP #if CATCHUP_SKIP
if (catchupFrames) if (catchupFrames)
@ -431,7 +429,7 @@ bool CNESEmulator::NesEmuMainLoop()
//runs every 8th cpu clock //runs every 8th cpu clock
if(apuClock == 8) if(apuClock == 8)
{ {
if(!apuCycleURDE()) if(!apuCycleURDE() && !forceDraw)
{ {
#if (WINDOWS_BUILD && DEBUG_MAIN_CALLS) #if (WINDOWS_BUILD && DEBUG_MAIN_CALLS)
emuMainTimesSkipped++; emuMainTimesSkipped++;
@ -515,7 +513,7 @@ bool CNESEmulator::NesEmuMainLoop()
} }
#if 1 #if 1
if ((loopCount % 10000) == 0 && GetTickCount() - start >= 14) if (!forceDraw && (loopCount % 10000) == 0 && GetTickCount() - start >= 14)
{ {
#if CATCHUP_SKIP #if CATCHUP_SKIP
if (catchupFrames < 50) if (catchupFrames < 50)
@ -547,8 +545,6 @@ bool CNESEmulator::NesEmuMainLoop()
} }
emuMainFrameStart = end; emuMainFrameStart = end;
#endif #endif
return drawFrame;
} }
static void nesEmuFdsSetup(uint8_t *src, uint8_t *dst) static void nesEmuFdsSetup(uint8_t *src, uint8_t *dst)
@ -884,11 +880,11 @@ bool CNESEmulator::SetPasswordIntoEntryScreen(u8* vram, u8* wram, const u8* pass
++encOff; ++encOff;
break; break;
case 1: case 1:
lastWord = (lastWord >> 6) | (password[encOff] << 2); lastWord = (lastWord >> 6) | (u32(password[encOff]) << 2);
++encOff; ++encOff;
break; break;
case 2: case 2:
lastWord = (lastWord >> 4) | (password[encOff] << 4); lastWord = (lastWord >> 6) | (u32(password[encOff]) << 4);
++encOff; ++encOff;
break; break;
case 3: case 3:
@ -898,9 +894,9 @@ bool CNESEmulator::SetPasswordIntoEntryScreen(u8* vram, u8* wram, const u8* pass
break; break;
} }
u8 name = u8(lastWord & 0x3f); u8 chName = u8(lastWord & 0x3f);
wram[0x99a + i] = name; wram[0x99a + i] = chName;
vram[0x109 + chOff] = name; vram[0x109 + chOff] = chName;
++chOff; ++chOff;
if (chOff == 0x6 || chOff == 0x46) if (chOff == 0x6 || chOff == 0x46)
++chOff; // mid-line space ++chOff; // mid-line space
@ -932,7 +928,7 @@ void CNESEmulator::Update()
} }
if (gameOver && !x20_gameOver) if (gameOver && !x20_gameOver)
for (int i=0 ; i<3 ; ++i) // Three draw loops to ensure password display for (int i=0 ; i<3 ; ++i) // Three draw loops to ensure password display
while (!NesEmuMainLoop()) {} NesEmuMainLoop(true);
else else
NesEmuMainLoop(); NesEmuMainLoop();
x20_gameOver = gameOver; x20_gameOver = gameOver;

View File

@ -66,7 +66,7 @@ private:
u32 checkDataLen = 0x1FFFC, u32 checksumMagic = 0xA663); u32 checkDataLen = 0x1FFFC, u32 checksumMagic = 0xA663);
void InitializeEmulator(); void InitializeEmulator();
void DeinitializeEmulator(); void DeinitializeEmulator();
bool NesEmuMainLoop(); void NesEmuMainLoop(bool forceDraw = false);
static bool CheckForGameOver(const u8* vram, u8* passwordOut = nullptr); static bool CheckForGameOver(const u8* vram, u8* passwordOut = nullptr);
static EPasswordEntryState CheckForPasswordEntryScreen(const uint8_t* vram); static EPasswordEntryState CheckForPasswordEntryScreen(const uint8_t* vram);
static bool SetPasswordIntoEntryScreen(u8* vram, u8* wram, const u8* password); static bool SetPasswordIntoEntryScreen(u8* vram, u8* wram, const u8* password);

View File

@ -62,10 +62,10 @@ const std::pair<int, const SGameOption*> GameOptionsRegistry[] =
CPersistentOptions::CPersistentOptions(CBitStreamReader& stream) CPersistentOptions::CPersistentOptions(CBitStreamReader& stream)
{ {
for (int b=0 ; b<98 ; ++b) for (int b=0 ; b<98 ; ++b)
x0_[b] = stream.ReadEncoded(1); x0_[b] = stream.ReadEncoded(8);
for (int b=0 ; b<64 ; ++b) for (int b=0 ; b<64 ; ++b)
x68_[b] = stream.ReadEncoded(1); x68_[b] = stream.ReadEncoded(8);
xc0_frozenFpsCount = stream.ReadEncoded(2); xc0_frozenFpsCount = stream.ReadEncoded(2);
xc4_frozenBallCount = stream.ReadEncoded(2); xc4_frozenBallCount = stream.ReadEncoded(2);
@ -75,7 +75,7 @@ CPersistentOptions::CPersistentOptions(CBitStreamReader& stream)
xd0_25_normalModeBeat = stream.ReadEncoded(1); xd0_25_normalModeBeat = stream.ReadEncoded(1);
xd0_26_hardModeBeat = stream.ReadEncoded(1); xd0_26_hardModeBeat = stream.ReadEncoded(1);
xd0_27_fusionBeat = 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); xd0_29_allItemsCollected = stream.ReadEncoded(1);
xbc_autoMapperKeyState = stream.ReadEncoded(2); xbc_autoMapperKeyState = stream.ReadEncoded(2);
@ -108,10 +108,10 @@ CPersistentOptions::CPersistentOptions(CBitStreamReader& stream)
void CPersistentOptions::PutTo(CBitStreamWriter& w) const void CPersistentOptions::PutTo(CBitStreamWriter& w) const
{ {
for (int b=0 ; b<98 ; ++b) for (int b=0 ; b<98 ; ++b)
w.WriteEncoded(x0_[b], 1); w.WriteEncoded(x0_[b], 8);
for (int b=0 ; b<64 ; ++b) for (int b=0 ; b<64 ; ++b)
w.WriteEncoded(x68_[b], 1); w.WriteEncoded(x68_[b], 8);
w.WriteEncoded(xc0_frozenFpsCount, 2); w.WriteEncoded(xc0_frozenFpsCount, 2);
w.WriteEncoded(xc4_frozenBallCount, 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_25_normalModeBeat, 1);
w.WriteEncoded(xd0_26_hardModeBeat, 1); w.WriteEncoded(xd0_26_hardModeBeat, 1);
w.WriteEncoded(xd0_27_fusionBeat, 1); w.WriteEncoded(xd0_27_fusionBeat, 1);
w.WriteEncoded(xd0_28_fusionSuitActive, 1);
w.WriteEncoded(xd0_29_allItemsCollected, 1); w.WriteEncoded(xd0_29_allItemsCollected, 1);
w.WriteEncoded(xbc_autoMapperKeyState, 2); w.WriteEncoded(xbc_autoMapperKeyState, 2);

View File

@ -1586,7 +1586,10 @@ void CFrontEndUI::SNesEmulatorFrame::Draw(CSaveGameScreen* saveUi) const
return; return;
if (xc_textSupport->GetIsTextSupportFinishedLoading()) 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(); xc_textSupport->Render();
} }
} }