From 137c7424bb2d6421d6a82fa4c7d6f3bcb85127a3 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Fri, 9 Feb 2018 21:42:17 -1000 Subject: [PATCH] Implement "ENGAGE RIDLEY MOTHER FUCKER" NES password failsafe. See https://youtu.be/cFNGtxs2BXc?t=481 for details. --- NESEmulator/CNESEmulator.cpp | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/NESEmulator/CNESEmulator.cpp b/NESEmulator/CNESEmulator.cpp index 2387e18db..f3eb4f060 100644 --- a/NESEmulator/CNESEmulator.cpp +++ b/NESEmulator/CNESEmulator.cpp @@ -183,10 +183,12 @@ CNESEmulator::CNESEmulator() void CNESEmulator::InitializeEmulator() { - emuNesROMsize = 0x20000; - emuNesROM = (uint8_t*)malloc(emuNesROMsize); - DecompressROM(m_nesEmuPBuf.get(), emuNesROM); - m_nesEmuPBuf.reset(); + nesPause = false; + ppuDebugPauseFrame = false; + mainClock = 1; + apuClock = 1; + ppuClock = 1; + vrc7Clock = 1; puts(VERSION_STRING); strcpy(window_title, VERSION_STRING); @@ -229,7 +231,6 @@ void CNESEmulator::InitializeEmulator() if(!mapperInit(mapper, prgROM, prgROMsize, emuPrgRAM, emuPrgRAMsize, chrROM, chrROMsize)) { printf("Mapper init failed!\n"); - free(emuNesROM); return; } #if DEBUG_LOAD_INFO @@ -303,9 +304,7 @@ void CNESEmulator::DeinitializeEmulator() fclose(save); } } - free(emuNesROM); } - emuNesROM = NULL; if(emuPrgRAM != NULL) { if(emuSaveEnabled) @@ -329,6 +328,11 @@ CNESEmulator::~CNESEmulator() { if (EmulatorInst) DeinitializeEmulator(); + if (emuNesROM) + { + free(emuNesROM); + emuNesROM = nullptr; + } EmulatorConstructed = false; } @@ -908,11 +912,22 @@ void CNESEmulator::Update() if (m_dvdReq && m_dvdReq->IsComplete()) { m_dvdReq.reset(); + emuNesROMsize = 0x20000; + emuNesROM = (uint8_t*)malloc(emuNesROMsize); + DecompressROM(m_nesEmuPBuf.get(), emuNesROM); + m_nesEmuPBuf.reset(); InitializeEmulator(); } } else { + if (nesPause) + { + DeinitializeEmulator(); + InitializeEmulator(); + return; + } + bool gameOver = CheckForGameOver(ppuGetVRAM(), x21_passwordFromNES); x34_passwordEntryState = CheckForPasswordEntryScreen(ppuGetVRAM()); if (x34_passwordEntryState == EPasswordEntryState::NotEntered && x38_passwordPending)