diff --git a/Core/Console.cpp b/Core/Console.cpp index 83065e8..b4efb70 100644 --- a/Core/Console.cpp +++ b/Core/Console.cpp @@ -87,6 +87,8 @@ void Console::Run() _videoDecoder->StartThread(); _emulationThreadId = std::this_thread::get_id(); + _memoryManager->IncrementMasterClockValue<182>(); + auto lock = _runLock.AcquireSafe(); while(!_stopFlag) { _cpu->Exec(); @@ -192,8 +194,9 @@ void Console::Reset() //_controlManager->Reset(); _notificationManager->SendNotification(ConsoleNotificationType::GameReset); + ProcessEvent(EventType::Reset); - _memoryManager->IncrementMasterClockValue<166>(); + _memoryManager->IncrementMasterClockValue<182>(); Unlock(); } @@ -263,8 +266,6 @@ bool Console::LoadRom(VirtualFile romFile, VirtualFile patchFile, bool stopRom) _notificationManager->SendNotification(ConsoleNotificationType::GameLoaded); - _memoryManager->IncrementMasterClockValue<166>(); - _rewindManager.reset(new RewindManager(shared_from_this())); _notificationManager->RegisterNotificationListener(_rewindManager); diff --git a/Core/Cpu.cpp b/Core/Cpu.cpp index 86ad5e9..6eeeb2e 100644 --- a/Core/Cpu.cpp +++ b/Core/Cpu.cpp @@ -21,7 +21,7 @@ Cpu::~Cpu() void Cpu::PowerOn() { _state = {}; - _state.PC = ReadDataWord(Cpu::ResetVector); + _state.PC = _memoryManager->PeekWord(Cpu::ResetVector); _state.SP = 0x1FF; _state.PS = ProcFlags::IrqDisable; _state.EmulationMode = true; @@ -44,7 +44,7 @@ void Cpu::Reset() _state.StopState = CpuStopState::Running; SetSP(_state.SP); _state.K = 0; - _state.PC = ReadDataWord(Cpu::ResetVector); + _state.PC = _memoryManager->PeekWord(Cpu::ResetVector); } void Cpu::Exec() diff --git a/Core/Debugger.cpp b/Core/Debugger.cpp index aa5d8bd..380f1e1 100644 --- a/Core/Debugger.cpp +++ b/Core/Debugger.cpp @@ -84,6 +84,12 @@ void Debugger::Release() } } +void Debugger::Reset() +{ + _prevOpCode = 0xFF; + _spcPrevOpCode = 0xFF; +} + void Debugger::ProcessCpuRead(uint32_t addr, uint8_t value, MemoryOperationType type) { AddressInfo addressInfo = _memoryManager->GetAbsoluteAddress(addr); @@ -353,6 +359,10 @@ void Debugger::ProcessEvent(EventType type) _console->GetNotificationManager()->SendNotification(ConsoleNotificationType::EventViewerRefresh); _eventManager->ClearFrameEvents(); break; + + case EventType::Reset: + Reset(); + break; } } diff --git a/Core/Debugger.h b/Core/Debugger.h index afc59dc..24051a4 100644 --- a/Core/Debugger.h +++ b/Core/Debugger.h @@ -64,12 +64,13 @@ private: atomic _spcBreakAddress; atomic _breakScanline; - uint8_t _prevOpCode = 0; + uint8_t _prevOpCode = 0xFF; uint32_t _prevProgramCounter = 0; - uint8_t _spcPrevOpCode = 0; + uint8_t _spcPrevOpCode = 0xFF; uint32_t _spcPrevProgramCounter = 0; + void Reset(); void SleepUntilResume(); void ProcessStepConditions(uint8_t opCode, uint32_t currentPc); void ProcessBreakConditions(MemoryOperationInfo &operation, AddressInfo &addressInfo); diff --git a/Core/EventType.h b/Core/EventType.h index 31daebf..3411840 100644 --- a/Core/EventType.h +++ b/Core/EventType.h @@ -5,5 +5,6 @@ enum class EventType Nmi = 0, Irq = 1, StartFrame = 2, - EndFrame = 3 + EndFrame = 3, + Reset = 4 }; \ No newline at end of file