mirror of
https://github.com/SourMesen/Mesen2.git
synced 2025-04-02 10:21:44 -04:00
Tweak load order/priority + use file ext. to select core
This commit is contained in:
parent
667782647e
commit
4d092bc07b
13 changed files with 75 additions and 48 deletions
|
@ -366,13 +366,13 @@ void Gameboy::OnBeforeRun()
|
|||
{
|
||||
}
|
||||
|
||||
bool Gameboy::LoadRom(VirtualFile& romFile)
|
||||
LoadRomResult Gameboy::LoadRom(VirtualFile& romFile)
|
||||
{
|
||||
vector<uint8_t> romData;
|
||||
romFile.ReadFile(romData);
|
||||
|
||||
if(romData.size() < Gameboy::HeaderOffset + sizeof(GameboyHeader)) {
|
||||
return false;
|
||||
return LoadRomResult::Failure;
|
||||
}
|
||||
|
||||
GbsHeader gbsHeader = {};
|
||||
|
@ -393,7 +393,7 @@ bool Gameboy::LoadRom(VirtualFile& romFile)
|
|||
Init(cart, gbsRomData, 0x5000, false, false);
|
||||
cart->InitPlayback(gbsHeader.FirstTrack - 1);
|
||||
|
||||
return true;
|
||||
return LoadRomResult::Success;
|
||||
} else {
|
||||
GameboyHeader header;
|
||||
memcpy(&header, romData.data() + Gameboy::HeaderOffset, sizeof(GameboyHeader));
|
||||
|
@ -419,11 +419,11 @@ bool Gameboy::LoadRom(VirtualFile& romFile)
|
|||
|
||||
if(cart) {
|
||||
Init(cart, romData, header.GetCartRamSize(), header.HasBattery(), (header.CgbFlag & 0x80) != false);
|
||||
return true;
|
||||
return LoadRomResult::Success;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return LoadRomResult::UnknownType;
|
||||
}
|
||||
|
||||
void Gameboy::Init()
|
||||
|
|
|
@ -104,7 +104,7 @@ public:
|
|||
void Stop() override;
|
||||
void Reset() override;
|
||||
void OnBeforeRun() override;
|
||||
bool LoadRom(VirtualFile& romFile) override;
|
||||
LoadRomResult LoadRom(VirtualFile& romFile) override;
|
||||
void Init() override;
|
||||
void RunFrame() override;
|
||||
shared_ptr<IControlManager> GetControlManager() override;
|
||||
|
|
|
@ -667,7 +667,7 @@ BaseMapper* MapperFactory::GetMapperFromID(RomData &romData)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
unique_ptr<BaseMapper> MapperFactory::InitializeFromFile(NesConsole* console, VirtualFile &romFile, RomData &romData)
|
||||
unique_ptr<BaseMapper> MapperFactory::InitializeFromFile(NesConsole* console, VirtualFile &romFile, RomData &romData, LoadRomResult& result)
|
||||
{
|
||||
RomLoader loader;
|
||||
|
||||
|
@ -686,12 +686,14 @@ unique_ptr<BaseMapper> MapperFactory::InitializeFromFile(NesConsole* console, Vi
|
|||
|
||||
unique_ptr<BaseMapper> mapper(GetMapperFromID(romData));
|
||||
if(mapper) {
|
||||
result = LoadRomResult::Success;
|
||||
return mapper;
|
||||
} else {
|
||||
//File is a valid NES file, but it couldn't be loaded
|
||||
result = LoadRomResult::Failure;
|
||||
}
|
||||
} else if(loader.GetRomData().BiosMissing) {
|
||||
//TODO NES
|
||||
//console->GetNotificationManager()->SendNotification(ConsoleNotificationType::BiosNotFound, (void*)loader.GetRomData().Info.Format);
|
||||
}
|
||||
result = LoadRomResult::UnknownType;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ class NesConsole;
|
|||
class BaseMapper;
|
||||
class VirtualFile;
|
||||
struct RomData;
|
||||
enum class LoadRomResult;
|
||||
|
||||
class MapperFactory
|
||||
{
|
||||
|
@ -16,5 +17,5 @@ class MapperFactory
|
|||
static constexpr uint16_t NsfMapperID = 65534;
|
||||
static constexpr uint16_t StudyBoxMapperID = 65533;
|
||||
|
||||
static unique_ptr<BaseMapper> InitializeFromFile(NesConsole* console, VirtualFile &romFile, RomData &outRomData);
|
||||
static unique_ptr<BaseMapper> InitializeFromFile(NesConsole* console, VirtualFile &romFile, RomData &outRomData, LoadRomResult& result);
|
||||
};
|
||||
|
|
|
@ -107,18 +107,20 @@ void NesConsole::OnBeforeRun()
|
|||
//TODO
|
||||
}
|
||||
|
||||
bool NesConsole::LoadRom(VirtualFile& romFile)
|
||||
LoadRomResult NesConsole::LoadRom(VirtualFile& romFile)
|
||||
{
|
||||
RomData romData;
|
||||
|
||||
unique_ptr<BaseMapper> mapper = MapperFactory::InitializeFromFile(this, romFile, romData);
|
||||
LoadRomResult result = LoadRomResult::UnknownType;
|
||||
unique_ptr<BaseMapper> mapper = MapperFactory::InitializeFromFile(this, romFile, romData, result);
|
||||
if(mapper) {
|
||||
if(!_vsMainConsole && romData.Info.VsType == VsSystemType::VsDualSystem) {
|
||||
//Create 2nd console (sub) dualsystem games
|
||||
_vsSubConsole.reset(new NesConsole(_emu));
|
||||
_vsSubConsole->_vsMainConsole = this;
|
||||
if(!_vsSubConsole->LoadRom(romFile)) {
|
||||
return false;
|
||||
LoadRomResult result = _vsSubConsole->LoadRom(romFile);
|
||||
if(result != LoadRomResult::Success) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -195,10 +197,8 @@ bool NesConsole::LoadRom(VirtualFile& romFile)
|
|||
_memoryManager->Reset(false);
|
||||
_controlManager->Reset(false);
|
||||
_cpu->Reset(false, _region);
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return result;
|
||||
}
|
||||
|
||||
void NesConsole::UpdateRegion()
|
||||
|
|
|
@ -70,7 +70,7 @@ public:
|
|||
void Stop() override;
|
||||
void Reset() override;
|
||||
void OnBeforeRun() override;
|
||||
bool LoadRom(VirtualFile& romFile) override;
|
||||
LoadRomResult LoadRom(VirtualFile& romFile) override;
|
||||
void Init() override;
|
||||
void RunFrame() override;
|
||||
shared_ptr<IControlManager> GetControlManager() override;
|
||||
|
|
|
@ -629,7 +629,7 @@ bool BaseCartridge::LoadGameboy(VirtualFile& romFile)
|
|||
LoadRom();
|
||||
if(_coprocessorType == CoprocessorType::SGB) {
|
||||
_gameboy.reset(new Gameboy(_emu, true));
|
||||
if(_gameboy->LoadRom(romFile)) {
|
||||
if(_gameboy->LoadRom(romFile) == LoadRomResult::Success) {
|
||||
return _gameboy->IsSgb();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -120,10 +120,8 @@ void Console::Reset()
|
|||
_cpu->Reset();
|
||||
}
|
||||
|
||||
bool Console::LoadRom(VirtualFile& romFile)
|
||||
LoadRomResult 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<BaseCartridge> cart = BaseCartridge::CreateCartridge(this, romFile);
|
||||
if(cart) {
|
||||
_cart = cart;
|
||||
|
@ -159,11 +157,10 @@ bool Console::LoadRom(VirtualFile& romFile)
|
|||
|
||||
UpdateRegion();
|
||||
|
||||
result = true;
|
||||
return LoadRomResult::Success;
|
||||
}
|
||||
|
||||
_settings->SetEmulationConfig(orgConfig);
|
||||
return result;
|
||||
return LoadRomResult::UnknownType;
|
||||
}
|
||||
|
||||
void Console::Init()
|
||||
|
|
|
@ -83,7 +83,7 @@ public:
|
|||
|
||||
void ProcessEndOfFrame();
|
||||
|
||||
bool LoadRom(VirtualFile& romFile) override;
|
||||
LoadRomResult LoadRom(VirtualFile& romFile) override;
|
||||
void Init() override;
|
||||
|
||||
uint64_t GetMasterClock() override;
|
||||
|
|
|
@ -355,26 +355,42 @@ bool Emulator::LoadRom(VirtualFile romFile, VirtualFile patchFile, bool stopRom,
|
|||
//TODO need to restore name if load fails
|
||||
_batteryManager->Initialize(FolderUtilities::GetFilename(romFile.GetFileName(), false));
|
||||
|
||||
bool result = false;
|
||||
EmulationConfig orgConfig = _settings->GetEmulationConfig(); //backup emulation config (can be temporarily overriden to control the power on RAM state)
|
||||
//TODO fix
|
||||
//backup emulation config (can be temporarily overriden to control the power on RAM state)
|
||||
EmulationConfig orgConfig = _settings->GetEmulationConfig();
|
||||
|
||||
static const vector<string> _nesExtensions = { { ".nes", ".fds", ".unif", ".unf", ".nsf", ".nsfe", ".studybox" } };
|
||||
static const vector<string> _snesExtensions = { { ".sfc", ".swc", ".fig", ".smc", ".bs", ".gb", ".gbc", ".spc" } };
|
||||
static const vector<string> _gbExtensions = { { ".gb", ".gbc", ".gbs" } };
|
||||
|
||||
shared_ptr<IConsole> console;
|
||||
string romExt = romFile.GetFileExtension();
|
||||
LoadRomResult result = LoadRomResult::UnknownType;
|
||||
|
||||
if(std::find(_nesExtensions.begin(), _nesExtensions.end(), romExt) != _nesExtensions.end()) {
|
||||
//TODO consolememory rework
|
||||
memset(_consoleMemory, 0, sizeof(_consoleMemory));
|
||||
console.reset(new NesConsole(this));
|
||||
result = console->LoadRom(romFile);
|
||||
}
|
||||
|
||||
memset(_consoleMemory, 0, sizeof(_consoleMemory));
|
||||
shared_ptr<IConsole> console = shared_ptr<IConsole>(new NesConsole(this));
|
||||
if(!console->LoadRom(romFile)) {
|
||||
if(result == LoadRomResult::UnknownType && std::find(_snesExtensions.begin(), _snesExtensions.end(), romExt) != _snesExtensions.end()) {
|
||||
memset(_consoleMemory, 0, sizeof(_consoleMemory));
|
||||
console.reset(new Console(this));
|
||||
if(!console->LoadRom(romFile)) {
|
||||
memset(_consoleMemory, 0, sizeof(_consoleMemory));
|
||||
console.reset(new Gameboy(this, false));
|
||||
if(!console->LoadRom(romFile)) {
|
||||
memset(_consoleMemory, 0, sizeof(_consoleMemory));
|
||||
MessageManager::DisplayMessage("Error", "CouldNotLoadFile", romFile.GetFileName());
|
||||
|
||||
//TODO
|
||||
_settings->SetEmulationConfig(orgConfig);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
result = console->LoadRom(romFile);
|
||||
}
|
||||
|
||||
if(result == LoadRomResult::UnknownType && std::find(_gbExtensions.begin(), _gbExtensions.end(), romExt) != _gbExtensions.end()) {
|
||||
memset(_consoleMemory, 0, sizeof(_consoleMemory));
|
||||
console.reset(new Gameboy(this, false));
|
||||
result = console->LoadRom(romFile);
|
||||
}
|
||||
|
||||
_settings->SetEmulationConfig(orgConfig);
|
||||
|
||||
if(result != LoadRomResult::Success) {
|
||||
MessageManager::DisplayMessage("Error", "CouldNotLoadFile", romFile.GetFileName());
|
||||
return false;
|
||||
}
|
||||
|
||||
bool debuggerActive = _debugger != nullptr;
|
||||
|
@ -444,10 +460,8 @@ bool Emulator::LoadRom(VirtualFile romFile, VirtualFile patchFile, bool stopRom,
|
|||
|
||||
_videoDecoder->StartThread();
|
||||
_videoRenderer->StartThread();
|
||||
|
||||
result = true;
|
||||
|
||||
return result;
|
||||
return true;
|
||||
}
|
||||
|
||||
RomInfo Emulator::GetRomInfo()
|
||||
|
|
|
@ -12,6 +12,13 @@ enum class ConsoleType;
|
|||
enum class ConsoleRegion;
|
||||
enum class CpuType : uint8_t;
|
||||
|
||||
enum class LoadRomResult
|
||||
{
|
||||
Success,
|
||||
Failure,
|
||||
UnknownType
|
||||
};
|
||||
|
||||
struct PpuFrameInfo
|
||||
{
|
||||
uint32_t Width;
|
||||
|
@ -28,7 +35,7 @@ public:
|
|||
|
||||
virtual void OnBeforeRun() = 0;
|
||||
|
||||
virtual bool LoadRom(VirtualFile& romFile) = 0;
|
||||
virtual LoadRomResult LoadRom(VirtualFile& romFile) = 0;
|
||||
virtual void Init() = 0;
|
||||
|
||||
//virtual void RunFrameWithRunAhead() = 0;
|
||||
|
|
|
@ -141,6 +141,11 @@ string VirtualFile::GetFileName()
|
|||
return _innerFile.empty() ? FolderUtilities::GetFilename(_path, true) : _innerFile;
|
||||
}
|
||||
|
||||
string VirtualFile::GetFileExtension()
|
||||
{
|
||||
return FolderUtilities::GetExtension(GetFileName());
|
||||
}
|
||||
|
||||
string VirtualFile::GetSha1Hash()
|
||||
{
|
||||
LoadFile();
|
||||
|
|
|
@ -29,6 +29,7 @@ public:
|
|||
string GetFilePath();
|
||||
string GetFolderPath();
|
||||
string GetFileName();
|
||||
string GetFileExtension();
|
||||
string GetSha1Hash();
|
||||
|
||||
size_t GetSize();
|
||||
|
|
Loading…
Add table
Reference in a new issue