diff --git a/Core/BizhawkMovie.cpp b/Core/BizhawkMovie.cpp index ec0d57f6..ca33d277 100644 --- a/Core/BizhawkMovie.cpp +++ b/Core/BizhawkMovie.cpp @@ -5,7 +5,8 @@ #include "VsSystemActionManager.h" #include "BizhawkMovie.h" #include "VsControlManager.h" -#include "FDS.h" +#include "Console.h" +#include "NotificationManager.h" BizhawkMovie::BizhawkMovie(shared_ptr console) { @@ -97,7 +98,7 @@ bool BizhawkMovie::InitializeGameData(ZipReader &reader) return false; } - _console->GetControlManager()->ResetPollCounter(); + _console->GetControlManager()->SetPollCounter(0); while(!fileData.eof()) { string line; @@ -187,13 +188,12 @@ bool BizhawkMovie::Play(VirtualFile &file) file.ReadFile(ss); reader.LoadArchive(ss); - _console->GetControlManager()->RegisterInputProvider(this); + + _console->GetNotificationManager()->RegisterNotificationListener(shared_from_this()); + EmulationSettings::SetRamPowerOnState(RamPowerOnState::AllOnes); if(InitializeInputData(reader) && InitializeGameData(reader)) { //NesHawk initializes memory to 1s - EmulationSettings::SetRamPowerOnState(RamPowerOnState::AllOnes); _isPlaying = true; - } else { - _console->GetControlManager()->UnregisterInputProvider(this); } _console->Resume(); return _isPlaying; @@ -203,3 +203,10 @@ bool BizhawkMovie::IsPlaying() { return _isPlaying; } + +void BizhawkMovie::ProcessNotification(ConsoleNotificationType type, void* parameter) +{ + if(type == ConsoleNotificationType::GameLoaded) { + _console->GetControlManager()->RegisterInputProvider(this); + } +} diff --git a/Core/BizhawkMovie.h b/Core/BizhawkMovie.h index e75185d0..e577a77a 100644 --- a/Core/BizhawkMovie.h +++ b/Core/BizhawkMovie.h @@ -2,11 +2,12 @@ #include "stdafx.h" #include "MovieManager.h" #include "../Utilities/ZipReader.h" +#include "INotificationListener.h" class VirtualFile; class Console; -class BizhawkMovie : public IMovie +class BizhawkMovie : public IMovie, public INotificationListener, public std::enable_shared_from_this { private: bool InitializeGameData(ZipReader &reader); @@ -28,4 +29,7 @@ public: bool SetInput(BaseControlDevice *device) override; bool Play(VirtualFile &file) override; bool IsPlaying() override; + + // Inherited via INotificationListener + virtual void ProcessNotification(ConsoleNotificationType type, void * parameter) override; }; \ No newline at end of file diff --git a/Core/Console.cpp b/Core/Console.cpp index e85316cf..ce7b9ee1 100644 --- a/Core/Console.cpp +++ b/Core/Console.cpp @@ -279,12 +279,20 @@ bool Console::Initialize(VirtualFile &romFile, VirtualFile &patchFile) //Temporarely disable battery saves to prevent battery files from being created for the wrong game (for Battle Box & Turbo File) BatteryManager::SetSaveEnabled(false); + + uint32_t pollCounter = 0; + if(_controlManager && !isDifferentGame) { + //When power cycling, poll counter must be preserved to allow movies to playback properly + pollCounter = _controlManager->GetPollCounter(); + } if(system == GameSystem::VsUniSystem) { _controlManager.reset(new VsControlManager(shared_from_this(), _systemActionManager, _mapper->GetMapperControlDevice())); } else { _controlManager.reset(new ControlManager(shared_from_this(), _systemActionManager, _mapper->GetMapperControlDevice())); } + _controlManager->SetPollCounter(pollCounter); _controlManager->UpdateControlDevices(); + //Re-enable battery saves BatteryManager::SetSaveEnabled(true); diff --git a/Core/ControlManager.cpp b/Core/ControlManager.cpp index 847986bb..1b6ecdb2 100644 --- a/Core/ControlManager.cpp +++ b/Core/ControlManager.cpp @@ -305,9 +305,9 @@ uint32_t ControlManager::GetPollCounter() return ControlManager::_pollCounter; } -void ControlManager::ResetPollCounter() +void ControlManager::SetPollCounter(uint32_t value) { - _pollCounter = 0; + _pollCounter = value; } uint8_t ControlManager::ReadRAM(uint16_t addr) diff --git a/Core/ControlManager.h b/Core/ControlManager.h index 60e603bd..ff77ca3d 100644 --- a/Core/ControlManager.h +++ b/Core/ControlManager.h @@ -54,7 +54,7 @@ public: void ResetLagCounter(); uint32_t GetPollCounter(); - void ResetPollCounter(); + void SetPollCounter(uint32_t value); virtual void Reset(bool softReset); diff --git a/Core/FceuxMovie.cpp b/Core/FceuxMovie.cpp index 7b574d59..dc6a05a4 100644 --- a/Core/FceuxMovie.cpp +++ b/Core/FceuxMovie.cpp @@ -6,6 +6,7 @@ #include "ControlManager.h" #include "FceuxMovie.h" #include "Console.h" +#include "NotificationManager.h" bool FceuxMovie::InitializeData(stringstream &filestream) { @@ -16,7 +17,7 @@ bool FceuxMovie::InitializeData(stringstream &filestream) _dataByFrame[2].push_back(""); _dataByFrame[3].push_back(""); - _console->GetControlManager()->ResetPollCounter(); + _console->GetControlManager()->SetPollCounter(0); while(!filestream.eof()) { string line; @@ -25,6 +26,7 @@ bool FceuxMovie::InitializeData(stringstream &filestream) vector md5array = Base64::Decode(line.substr(19, line.size() - 20)); HashInfo hashInfo; hashInfo.PrgChrMd5Hash = HexUtilities::ToHex(md5array); + EmulationSettings::SetRamPowerOnState(RamPowerOnState::AllZeros); if(_console->LoadMatchingRom("", hashInfo)) { result = true; } else { @@ -65,9 +67,8 @@ bool FceuxMovie::Play(VirtualFile &file) std::stringstream ss; file.ReadFile(ss); + _console->GetNotificationManager()->RegisterNotificationListener(shared_from_this()); if(InitializeData(ss)) { - EmulationSettings::SetRamPowerOnState(RamPowerOnState::AllZeros); - _console->GetControlManager()->RegisterInputProvider(this); _console->Reset(false); _isPlaying = true; } diff --git a/Core/MesenMovie.cpp b/Core/MesenMovie.cpp index f0e9c1ce..cfb78199 100644 --- a/Core/MesenMovie.cpp +++ b/Core/MesenMovie.cpp @@ -112,7 +112,7 @@ bool MesenMovie::Play(VirtualFile &file) //Disable auto-configure input option (otherwise the movie file's input types are ignored) bool autoConfigureInput = EmulationSettings::CheckFlag(EmulationFlags::AutoConfigureInput); EmulationSettings::ClearFlags(EmulationFlags::AutoConfigureInput); - _console->GetControlManager()->ResetPollCounter(); + _console->GetControlManager()->SetPollCounter(0); bool gameLoaded = LoadGame(); EmulationSettings::SetFlagState(EmulationFlags::AutoConfigureInput, autoConfigureInput); @@ -127,7 +127,7 @@ bool MesenMovie::Play(VirtualFile &file) _console->Resume(); return false; } else { - _console->GetControlManager()->ResetPollCounter(); + _console->GetControlManager()->SetPollCounter(0); } }