diff --git a/Core/Console.cpp b/Core/Console.cpp index 59d759d..d0918e0 100644 --- a/Core/Console.cpp +++ b/Core/Console.cpp @@ -224,11 +224,13 @@ bool Console::LoadRom(VirtualFile romFile, VirtualFile patchFile, bool stopRom) MessageManager::DisplayMessage("SPC", "spc700.rom not found, cannot launch game."); return false; } + + _cart = cart; + UpdateRegion(); _internalRegisters.reset(new InternalRegisters(shared_from_this())); _ppu.reset(new Ppu(shared_from_this())); _spc.reset(new Spc(shared_from_this(), spcRomData)); - _cart = cart; _controlManager.reset(new ControlManager(shared_from_this())); _memoryManager.reset(new MemoryManager()); _dmaController.reset(new DmaController(_memoryManager.get())); @@ -236,12 +238,7 @@ bool Console::LoadRom(VirtualFile romFile, VirtualFile patchFile, bool stopRom) _memoryManager->Initialize(shared_from_this()); _cpu.reset(new Cpu(this)); - - _rewindManager.reset(new RewindManager(shared_from_this())); - _notificationManager->RegisterNotificationListener(_rewindManager); - - _controlManager->UpdateControlDevices(); - + if(_debugger) { //Reset debugger if it was running before auto lock = _debuggerLock.AcquireSafe(); @@ -249,10 +246,17 @@ bool Console::LoadRom(VirtualFile romFile, VirtualFile patchFile, bool stopRom) GetDebugger(); _debugger->Step(1); } - - UpdateRegion(); + + _cpu->PowerOn(); _memoryManager->IncrementMasterClockValue<170>(); + _rewindManager.reset(new RewindManager(shared_from_this())); + _notificationManager->RegisterNotificationListener(_rewindManager); + + _controlManager->UpdateControlDevices(); + + UpdateRegion(); + _paused = false; _notificationManager->SendNotification(ConsoleNotificationType::GameLoaded); diff --git a/Core/Cpu.cpp b/Core/Cpu.cpp index 6ec24a7..b1345ac 100644 --- a/Core/Cpu.cpp +++ b/Core/Cpu.cpp @@ -10,6 +10,14 @@ Cpu::Cpu(Console *console) { _console = console; _memoryManager = console->GetMemoryManager().get(); +} + +Cpu::~Cpu() +{ +} + +void Cpu::PowerOn() +{ _state = {}; _state.PC = ReadDataWord(Cpu::ResetVector); _state.SP = 0x1FF; @@ -24,10 +32,6 @@ Cpu::Cpu(Console *console) SetFlags(ProcFlags::IndexMode8); } -Cpu::~Cpu() -{ -} - void Cpu::Reset() { _state.EmulationMode = true; @@ -57,9 +61,8 @@ void Cpu::Exec() //WAI if(!_state.IrqSource && !_state.NmiFlag) { #ifndef DUMMYCPU - _memoryManager->IncrementMasterClockValue<4>(); + Idle(); #endif - return; } else { Idle(); Idle(); diff --git a/Core/Cpu.h b/Core/Cpu.h index 5039959..88ca6c1 100644 --- a/Core/Cpu.h +++ b/Core/Cpu.h @@ -291,6 +291,8 @@ public: Cpu(Console *console); ~Cpu(); + void PowerOn(); + void Reset(); void Exec();