diff --git a/Core/Core.vcxproj b/Core/Core.vcxproj index 5ead938e..40787070 100644 --- a/Core/Core.vcxproj +++ b/Core/Core.vcxproj @@ -55,6 +55,7 @@ + diff --git a/Core/Core.vcxproj.filters b/Core/Core.vcxproj.filters index 9c7bc658..1b8d670d 100644 --- a/Core/Core.vcxproj.filters +++ b/Core/Core.vcxproj.filters @@ -733,6 +733,7 @@ + diff --git a/Core/FirmwareHelper.h b/Core/FirmwareHelper.h index 37e4f4af..388a4c69 100644 --- a/Core/FirmwareHelper.h +++ b/Core/FirmwareHelper.h @@ -3,6 +3,7 @@ #include "Shared/Emulator.h" #include "Shared/NotificationManager.h" #include "Utilities/FolderUtilities.h" +#include "SNES/CartTypes.h" struct MissingFirmwareMessage { diff --git a/Core/Gameboy/Gameboy.cpp b/Core/Gameboy/Gameboy.cpp index 770f1042..21debb2d 100644 --- a/Core/Gameboy/Gameboy.cpp +++ b/Core/Gameboy/Gameboy.cpp @@ -348,13 +348,15 @@ void Gameboy::Stop() void Gameboy::Reset() { + //The GB has no reset button, behave like power cycle + _emu->ReloadRom(true); } void Gameboy::OnBeforeRun() { } -bool Gameboy::LoadRom(VirtualFile& romFile, VirtualFile& patchFile) +bool Gameboy::LoadRom(VirtualFile& romFile) { vector romData; romFile.ReadFile(romData); @@ -427,12 +429,6 @@ double Gameboy::GetFps() return 59.72750056960583; } -RomInfo Gameboy::GetRomInfo() -{ - //TODO - return RomInfo(); -} - void Gameboy::RunSingleFrame() { //TODO diff --git a/Core/Gameboy/Gameboy.h b/Core/Gameboy/Gameboy.h index a5e5c950..97114e54 100644 --- a/Core/Gameboy/Gameboy.h +++ b/Core/Gameboy/Gameboy.h @@ -101,14 +101,13 @@ public: virtual void Stop() override; virtual void Reset() override; virtual void OnBeforeRun() override; - virtual bool LoadRom(VirtualFile& romFile, VirtualFile& patchFile) override; + virtual bool LoadRom(VirtualFile& romFile) override; virtual void Init() override; virtual void RunFrame() override; virtual shared_ptr GetControlManager() override; virtual ConsoleType GetConsoleType() override; virtual double GetFrameDelay() override; virtual double GetFps() override; - virtual RomInfo GetRomInfo() override; virtual void RunSingleFrame() override; virtual PpuFrameInfo GetPpuFrame() override; virtual vector GetCpuTypes() override; diff --git a/Core/NES/BaseMapper.cpp b/Core/NES/BaseMapper.cpp index f619dd26..ea285cc3 100644 --- a/Core/NES/BaseMapper.cpp +++ b/Core/NES/BaseMapper.cpp @@ -11,6 +11,7 @@ #include "Shared/CheatManager.h" #include "Shared/BatteryManager.h" #include "Shared/EmuSettings.h" +#include "Shared/RomInfo.h" #include "Utilities/FolderUtilities.h" #include "Utilities/Patches/IpsPatcher.h" #include "Utilities/Serializer.h" @@ -1158,7 +1159,7 @@ void BaseMapper::GetRomFileData(vector &out, bool asIpsFile, uint8_t* h //Get edited rom if(asIpsFile) { vector originalFile; - _console->GetRomInfo().RomFile.ReadFile(originalFile); + _emu->GetRomInfo().RomFile.ReadFile(originalFile); vector patchData = IpsPatcher::CreatePatch(originalFile, newFile); out.insert(out.end(), patchData.begin(), patchData.end()); diff --git a/Core/NES/NesConsole.cpp b/Core/NES/NesConsole.cpp index 15509bc5..75642e21 100644 --- a/Core/NES/NesConsole.cpp +++ b/Core/NES/NesConsole.cpp @@ -78,9 +78,10 @@ void NesConsole::OnBeforeRun() //TODO } -bool NesConsole::LoadRom(VirtualFile& romFile, VirtualFile& patchFile) +bool NesConsole::LoadRom(VirtualFile& romFile) { RomData romData; + shared_ptr mapper = MapperFactory::InitializeFromFile(shared_from_this(), romFile, romData); if(mapper) { shared_ptr previousMapper = _mapper; @@ -206,12 +207,6 @@ double NesConsole::GetFps() return 60; } -RomInfo NesConsole::GetRomInfo() -{ - //TODO - return RomInfo(); -} - void NesConsole::RunSingleFrame() { //TODO diff --git a/Core/NES/NesConsole.h b/Core/NES/NesConsole.h index 10d57949..bfc5811d 100644 --- a/Core/NES/NesConsole.h +++ b/Core/NES/NesConsole.h @@ -63,13 +63,12 @@ public: virtual void Stop() override; virtual void Reset() override; virtual void OnBeforeRun() override; - virtual bool LoadRom(VirtualFile& romFile, VirtualFile& patchFile) override; + virtual bool LoadRom(VirtualFile& romFile) override; virtual void Init() override; virtual void RunFrame() override; virtual shared_ptr GetControlManager() override; virtual double GetFrameDelay() override; virtual double GetFps() override; - virtual RomInfo GetRomInfo() override; virtual void RunSingleFrame() override; virtual PpuFrameInfo GetPpuFrame() override; virtual ConsoleType GetConsoleType() override; diff --git a/Core/SNES/BaseCartridge.cpp b/Core/SNES/BaseCartridge.cpp index f36a6b7e..28d04b48 100644 --- a/Core/SNES/BaseCartridge.cpp +++ b/Core/SNES/BaseCartridge.cpp @@ -23,6 +23,7 @@ #include "Shared/BatteryManager.h" #include "Shared/MessageManager.h" #include "Shared/Emulator.h" +#include "Shared/RomInfo.h" #include "Utilities/HexUtilities.h" #include "Utilities/VirtualFile.h" #include "Utilities/FolderUtilities.h" @@ -39,16 +40,10 @@ BaseCartridge::~BaseCartridge() delete[] _saveRam; } -shared_ptr BaseCartridge::CreateCartridge(Console* console, VirtualFile &romFile, VirtualFile &patchFile) +shared_ptr BaseCartridge::CreateCartridge(Console* console, VirtualFile &romFile) { if(romFile.IsValid()) { shared_ptr cart(new BaseCartridge()); - if(patchFile.IsValid()) { - cart->_patchPath = patchFile; - if(romFile.ApplyPatch(patchFile)) { - MessageManager::DisplayMessage("Patch", "ApplyingPatch", patchFile.GetFileName()); - } - } vector romData; romFile.ReadFile(romData); @@ -68,7 +63,7 @@ shared_ptr BaseCartridge::CreateCartridge(Console* console, Virtu return nullptr; } } else if(fileExt == ".gb" || fileExt == ".gbc") { - if(cart->LoadGameboy(romFile, patchFile)) { + if(cart->LoadGameboy(romFile)) { return cart; } else { return nullptr; @@ -324,18 +319,19 @@ void BaseCartridge::Reset() RomInfo BaseCartridge::GetRomInfo() { RomInfo info; - info.Header = _cartInfo; - info.HeaderOffset = _headerOffset; + //TODO + //info.Header = _cartInfo; + //info.HeaderOffset = _headerOffset; + //info.Coprocessor = _coprocessorType; info.RomFile = static_cast(_romPath); - info.PatchFile = static_cast(_patchPath); - info.Coprocessor = _coprocessorType; return info; } vector BaseCartridge::GetOriginalPrgRom() { RomInfo romInfo = GetRomInfo(); - shared_ptr originalCart = BaseCartridge::CreateCartridge(_console, romInfo.RomFile, romInfo.PatchFile); + //TODO + shared_ptr originalCart = BaseCartridge::CreateCartridge(_console, romInfo.RomFile); if(originalCart->_gameboy) { uint8_t* orgPrgRom = originalCart->_gameboy->DebugGetMemory(SnesMemoryType::GbPrgRom); uint32_t orgRomSize = originalCart->_gameboy->DebugGetMemorySize(SnesMemoryType::GbPrgRom); @@ -622,7 +618,7 @@ void BaseCartridge::LoadSpc() SetupCpuHalt(); } -bool BaseCartridge::LoadGameboy(VirtualFile& romFile, VirtualFile& patchFile) +bool BaseCartridge::LoadGameboy(VirtualFile& romFile) { _cartInfo = { }; _headerOffset = Gameboy::HeaderOffset; @@ -633,7 +629,7 @@ bool BaseCartridge::LoadGameboy(VirtualFile& romFile, VirtualFile& patchFile) LoadRom(); if(_coprocessorType == CoprocessorType::SGB) { _gameboy.reset(new Gameboy(_emu, true)); - if(_gameboy->LoadRom(romFile, patchFile)) { + if(_gameboy->LoadRom(romFile)) { return _gameboy->IsSgb(); } } diff --git a/Core/SNES/BaseCartridge.h b/Core/SNES/BaseCartridge.h index 0b52b255..ee02c771 100644 --- a/Core/SNES/BaseCartridge.h +++ b/Core/SNES/BaseCartridge.h @@ -4,6 +4,7 @@ #include "CartTypes.h" #include "Coprocessors/BaseCoprocessor.h" #include "Utilities/ISerializable.h" +#include "Shared/RomInfo.h" class MemoryMappings; class VirtualFile; @@ -49,7 +50,6 @@ private: bool _hasBattery = false; bool _hasRtc = false; string _romPath; - string _patchPath; uint8_t* _prgRom = nullptr; uint8_t* _saveRam = nullptr; @@ -76,7 +76,7 @@ private: void LoadRom(); void LoadSpc(); - bool LoadGameboy(VirtualFile& romFile, VirtualFile& patchFile); + bool LoadGameboy(VirtualFile& romFile); void SetupCpuHalt(); void InitCoprocessor(); void LoadEmbeddedFirmware(); @@ -87,7 +87,7 @@ private: public: virtual ~BaseCartridge(); - static shared_ptr CreateCartridge(Console* console, VirtualFile &romFile, VirtualFile &patchFile); + static shared_ptr CreateCartridge(Console* console, VirtualFile &romFile); void Reset(); diff --git a/Core/SNES/CartTypes.h b/Core/SNES/CartTypes.h index eddc542a..8773d5d5 100644 --- a/Core/SNES/CartTypes.h +++ b/Core/SNES/CartTypes.h @@ -68,15 +68,6 @@ enum class FirmwareType SGB2 }; -struct RomInfo -{ - SnesCartInformation Header; - uint32_t HeaderOffset; - VirtualFile RomFile; - VirtualFile PatchFile; - CoprocessorType Coprocessor; -}; - namespace CartFlags { enum CartFlags diff --git a/Core/SNES/Console.cpp b/Core/SNES/Console.cpp index a64fd698..685c1d51 100644 --- a/Core/SNES/Console.cpp +++ b/Core/SNES/Console.cpp @@ -59,7 +59,9 @@ void Console::RunFrame() void Console::OnBeforeRun() { _memoryManager->IncMasterClockStartup(); - _controlManager->UpdateInputState(); + + //TODO? + //_controlManager->UpdateInputState(); } void Console::ProcessEndOfFrame() @@ -72,8 +74,8 @@ void Console::ProcessEndOfFrame() _emu->ProcessEndOfFrame(); - _controlManager->UpdateInputState(); _controlManager->UpdateControlDevices(); + _controlManager->UpdateInputState(); _internalRegisters->ProcessAutoJoypadRead(); #endif _frameRunning = false; @@ -132,11 +134,11 @@ void Console::Reset() } } -bool Console::LoadRom(VirtualFile& romFile, VirtualFile& patchFile) +bool Console::LoadRom(VirtualFile& romFile) { bool result = false; EmulationConfig orgConfig = _settings->GetEmulationConfig(); //backup emulation config (can be temporarily overriden to control the power on RAM state) - shared_ptr cart = BaseCartridge::CreateCartridge(this, romFile, patchFile); + shared_ptr cart = BaseCartridge::CreateCartridge(this, romFile); if(cart) { _cart = cart; @@ -180,16 +182,6 @@ void Console::Init() { } -RomInfo Console::GetRomInfo() -{ - shared_ptr cart = _cart; - if(cart) { - return cart->GetRomInfo(); - } else { - return {}; - } -} - uint64_t Console::GetMasterClock() { return _memoryManager->GetMasterClock(); diff --git a/Core/SNES/Console.h b/Core/SNES/Console.h index e50c41a3..f141fea1 100644 --- a/Core/SNES/Console.h +++ b/Core/SNES/Console.h @@ -7,6 +7,7 @@ #include "Utilities/Timer.h" #include "Utilities/VirtualFile.h" #include "Utilities/SimpleLock.h" +#include "Shared/RomInfo.h" class Cpu; class Ppu; @@ -81,10 +82,9 @@ public: void ProcessEndOfFrame(); - bool LoadRom(VirtualFile& romFile, VirtualFile& patchFile) override; + bool LoadRom(VirtualFile& romFile) override; void Init() override; - RomInfo GetRomInfo() override; uint64_t GetMasterClock() override; uint32_t GetMasterClockRate(); ConsoleRegion GetRegion(); diff --git a/Core/Shared/BaseControlManager.h b/Core/Shared/BaseControlManager.h index 5c592260..194cb012 100644 --- a/Core/Shared/BaseControlManager.h +++ b/Core/Shared/BaseControlManager.h @@ -29,8 +29,8 @@ public: BaseControlManager(Emulator* emu); virtual ~BaseControlManager(); - virtual void UpdateControlDevices() {} - virtual void UpdateInputState(); + void UpdateControlDevices() override {} + void UpdateInputState() override; uint32_t GetPollCounter() override; void SetPollCounter(uint32_t value) override; diff --git a/Core/Shared/Emulator.cpp b/Core/Shared/Emulator.cpp index a069090d..be7a9a9a 100644 --- a/Core/Shared/Emulator.cpp +++ b/Core/Shared/Emulator.cpp @@ -292,6 +292,7 @@ void Emulator::Reset() _runLock.Acquire(); _console->Reset(); + GetControlManager()->UpdateInputState(); _notificationManager->SendNotification(ConsoleNotificationType::GameReset); ProcessEvent(EventType::Reset); @@ -325,6 +326,18 @@ void Emulator::PowerCycle() bool Emulator::LoadRom(VirtualFile romFile, VirtualFile patchFile, bool stopRom, bool forPowerCycle) { + if(!romFile.IsValid()) { + return false; + } + + if(patchFile.IsValid()) { + //TODO + //_patchPath = patchFile; + if(romFile.ApplyPatch(patchFile)) { + MessageManager::DisplayMessage("Patch", "ApplyingPatch", patchFile.GetFileName()); + } + } + if(_console) { //Make sure the battery is saved to disk before we load another game (or reload the same game) //TODO @@ -336,81 +349,87 @@ bool Emulator::LoadRom(VirtualFile romFile, VirtualFile patchFile, bool stopRom, memset(_consoleMemory, 0, sizeof(_consoleMemory)); shared_ptr console = shared_ptr(new NesConsole(this)); - if(!console->LoadRom(romFile, patchFile)) { + if(!console->LoadRom(romFile)) { memset(_consoleMemory, 0, sizeof(_consoleMemory)); console.reset(new Console(this)); - if(!console->LoadRom(romFile, patchFile)) { + if(!console->LoadRom(romFile)) { memset(_consoleMemory, 0, sizeof(_consoleMemory)); console.reset(new Gameboy(this, false)); - if(!console->LoadRom(romFile, patchFile)) { + if(!console->LoadRom(romFile)) { memset(_consoleMemory, 0, sizeof(_consoleMemory)); + MessageManager::DisplayMessage("Error", "CouldNotLoadFile", romFile.GetFileName()); + + //TODO + _settings->SetEmulationConfig(orgConfig); return false; } } } - if(console) { - bool debuggerActive = _debugger != nullptr; - if(stopRom) { - KeyManager::UpdateDevices(); - Stop(false); - } + _romFile = romFile; + _patchFile = patchFile; - _cheatManager->ClearCheats(false); - - auto lock = _debuggerLock.AcquireSafe(); - if(_debugger) { - //Reset debugger if it was running before - _debugger->Release(); - _debugger.reset(); - } - - _batteryManager->Initialize(FolderUtilities::GetFilename(romFile.GetFileName(), false)); - - //TODO - //UpdateRegion(); - - _console = console; - console->Init(); - - if(debuggerActive) { - GetDebugger(); - } - - _rewindManager.reset(new RewindManager(shared_from_this())); - _notificationManager->RegisterNotificationListener(_rewindManager); - - //TODO - GetControlManager()->UpdateControlDevices(); - //UpdateRegion(); - - _notificationManager->SendNotification(ConsoleNotificationType::GameLoaded, (void*)forPowerCycle); - - _paused = false; - - if(!forPowerCycle) { - string modelName = _region == ConsoleRegion::Pal ? "PAL" : "NTSC"; - string messageTitle = MessageManager::Localize("GameLoaded") + " (" + modelName + ")"; - MessageManager::DisplayMessage(messageTitle, FolderUtilities::GetFilename(GetRomInfo().RomFile.GetFileName(), false)); - } - - if(stopRom) { - #ifndef LIBRETRO - _emuThread.reset(new thread(&Emulator::Run, this)); - #endif - } - result = true; - } else { - MessageManager::DisplayMessage("Error", "CouldNotLoadFile", romFile.GetFileName()); + bool debuggerActive = _debugger != nullptr; + if(stopRom) { + KeyManager::UpdateDevices(); + Stop(false); } - _settings->SetEmulationConfig(orgConfig); + _cheatManager->ClearCheats(false); + + auto lock = _debuggerLock.AcquireSafe(); + if(_debugger) { + //Reset debugger if it was running before + _debugger->Release(); + _debugger.reset(); + } + + _batteryManager->Initialize(FolderUtilities::GetFilename(romFile.GetFileName(), false)); + + //TODO + //UpdateRegion(); + + _console = console; + console->Init(); + + if(debuggerActive) { + GetDebugger(); + } + + _rewindManager.reset(new RewindManager(shared_from_this())); + _notificationManager->RegisterNotificationListener(_rewindManager); + + //TODO + GetControlManager()->UpdateControlDevices(); + GetControlManager()->UpdateInputState(); + //UpdateRegion(); + + _notificationManager->SendNotification(ConsoleNotificationType::GameLoaded, (void*)forPowerCycle); + + _paused = false; + + if(!forPowerCycle) { + string modelName = _region == ConsoleRegion::Pal ? "PAL" : "NTSC"; + string messageTitle = MessageManager::Localize("GameLoaded") + " (" + modelName + ")"; + MessageManager::DisplayMessage(messageTitle, FolderUtilities::GetFilename(GetRomInfo().RomFile.GetFileName(), false)); + } + + if(stopRom) { + #ifndef LIBRETRO + _emuThread.reset(new thread(&Emulator::Run, this)); + #endif + } + result = true; + return result; } RomInfo Emulator::GetRomInfo() { - return _console->GetRomInfo(); + RomInfo romInfo = {}; + romInfo.RomFile = _romFile; + romInfo.PatchFile = _patchFile; + return romInfo; } string Emulator::GetHash(HashType type) diff --git a/Core/Shared/Emulator.h b/Core/Shared/Emulator.h index 991cc3e4..ee429573 100644 --- a/Core/Shared/Emulator.h +++ b/Core/Shared/Emulator.h @@ -81,6 +81,9 @@ private: atomic _isRunAheadFrame; bool _frameRunning = false; + string _romFile; + string _patchFile; + ConsoleMemoryInfo _consoleMemory[(int)SnesMemoryType::Register] = {}; unique_ptr _stats; diff --git a/Core/Shared/Interfaces/IConsole.h b/Core/Shared/Interfaces/IConsole.h index b3178056..64ee0e00 100644 --- a/Core/Shared/Interfaces/IConsole.h +++ b/Core/Shared/Interfaces/IConsole.h @@ -2,7 +2,7 @@ #include "stdafx.h" #include "Utilities/ISerializable.h" #include "Core/Debugger/DebugTypes.h" -#include "Core/SNES/CartTypes.h" +#include "Shared/RomInfo.h" class IControlManager; class VirtualFile; @@ -25,7 +25,7 @@ public: virtual void OnBeforeRun() = 0; - virtual bool LoadRom(VirtualFile& romFile, VirtualFile& patchFile) = 0; + virtual bool LoadRom(VirtualFile& romFile) = 0; virtual void Init() = 0; //virtual void RunFrameWithRunAhead() = 0; @@ -41,8 +41,6 @@ public: virtual double GetFrameDelay() = 0; virtual double GetFps() = 0; - virtual RomInfo GetRomInfo() = 0; - virtual void RunSingleFrame() = 0; virtual PpuFrameInfo GetPpuFrame() = 0; diff --git a/Core/Shared/Interfaces/IControlManager.h b/Core/Shared/Interfaces/IControlManager.h index ce0c2dcb..b96a4bf6 100644 --- a/Core/Shared/Interfaces/IControlManager.h +++ b/Core/Shared/Interfaces/IControlManager.h @@ -17,4 +17,5 @@ public: virtual void SetPollCounter(uint32_t pollCounter) = 0; virtual uint32_t GetPollCounter() = 0; virtual void UpdateControlDevices() = 0; + virtual void UpdateInputState() = 0; }; \ No newline at end of file diff --git a/Core/Shared/RomInfo.h b/Core/Shared/RomInfo.h new file mode 100644 index 00000000..0b0960c9 --- /dev/null +++ b/Core/Shared/RomInfo.h @@ -0,0 +1,9 @@ +#pragma once +#include "stdafx.h" + #include "Utilities/VirtualFile.h" + +struct RomInfo +{ + VirtualFile RomFile; + VirtualFile PatchFile; +}; diff --git a/InteropDLL/EmuApiWrapper.cpp b/InteropDLL/EmuApiWrapper.cpp index ebee16e2..d7e7ee94 100644 --- a/InteropDLL/EmuApiWrapper.cpp +++ b/InteropDLL/EmuApiWrapper.cpp @@ -42,8 +42,9 @@ struct InteropRomInfo { const char* RomPath; const char* PatchPath; - CoprocessorType Coprocessor; - SnesCartInformation Header; + //TODO + //CoprocessorType Coprocessor; + //SnesCartInformation Header; char Sha1[40]; }; @@ -126,10 +127,11 @@ extern "C" { _romPath = romInfo.RomFile; _patchPath = romInfo.PatchFile; - info.Header = romInfo.Header; info.RomPath = _romPath.c_str(); info.PatchPath = _patchPath.c_str(); - info.Coprocessor = romInfo.Coprocessor; + //TODO + //info.Header = romInfo.Header; + //info.Coprocessor = romInfo.Coprocessor; memcpy(info.Sha1, sha1.c_str(), sha1.size()); }