From 26c9eb79583bfb2c8f17f2cc9391ded909099949 Mon Sep 17 00:00:00 2001 From: jcm <6864788+jcm93@users.noreply.github.com> Date: Sun, 19 Jan 2025 21:13:37 -0600 Subject: [PATCH] mia, desktop-ui: Add basic error handling to ROM loading Move LoadResult to ares.hpp, handle modal cancellation handle firmware errors more gooder, add invalid rom error --- ares/ares/ares.hpp | 30 +++++++++++ desktop-ui/emulator/arcade.cpp | 18 ++++--- desktop-ui/emulator/atari-2600.cpp | 16 +++--- desktop-ui/emulator/colecovision.cpp | 21 +++++--- desktop-ui/emulator/emulator.cpp | 52 +++++++++++++++----- desktop-ui/emulator/emulator.hpp | 3 +- desktop-ui/emulator/famicom-disk-system.cpp | 25 +++++++--- desktop-ui/emulator/famicom.cpp | 16 +++--- desktop-ui/emulator/game-boy-advance.cpp | 21 +++++--- desktop-ui/emulator/game-boy-color.cpp | 16 +++--- desktop-ui/emulator/game-boy.cpp | 16 +++--- desktop-ui/emulator/game-gear.cpp | 22 ++++++--- desktop-ui/emulator/master-system.cpp | 24 ++++++--- desktop-ui/emulator/mega-32x.cpp | 31 ++++++++---- desktop-ui/emulator/mega-cd-32x.cpp | 26 +++++++--- desktop-ui/emulator/mega-cd.cpp | 24 ++++++--- desktop-ui/emulator/mega-drive.cpp | 29 +++++++---- desktop-ui/emulator/msx.cpp | 22 ++++++--- desktop-ui/emulator/msx2.cpp | 19 ++++--- desktop-ui/emulator/myvision.cpp | 16 +++--- desktop-ui/emulator/neo-geo-aes.cpp | 22 ++++++--- desktop-ui/emulator/neo-geo-mvs.cpp | 22 ++++++--- desktop-ui/emulator/neo-geo-pocket-color.cpp | 22 ++++++--- desktop-ui/emulator/neo-geo-pocket.cpp | 22 ++++++--- desktop-ui/emulator/nintendo-64.cpp | 38 +++++++++----- desktop-ui/emulator/nintendo-64dd.cpp | 26 +++++++--- desktop-ui/emulator/pc-engine-cd.cpp | 25 +++++++--- desktop-ui/emulator/pc-engine.cpp | 16 +++--- desktop-ui/emulator/playstation.cpp | 24 ++++++--- desktop-ui/emulator/pocket-challenge-v2.cpp | 16 +++--- desktop-ui/emulator/saturn.cpp | 20 ++++++-- desktop-ui/emulator/sg-1000.cpp | 16 +++--- desktop-ui/emulator/super-famicom.cpp | 24 +++++---- desktop-ui/emulator/supergrafx-cd.cpp | 25 +++++++--- desktop-ui/emulator/supergrafx.cpp | 16 +++--- desktop-ui/emulator/wonderswan-color.cpp | 16 +++--- desktop-ui/emulator/wonderswan.cpp | 16 +++--- desktop-ui/emulator/zx-spectrum-128.cpp | 16 +++--- desktop-ui/emulator/zx-spectrum.cpp | 16 +++--- mia/CMakeLists.txt | 2 +- mia/medium/arcade.cpp | 16 +++--- mia/medium/atari-2600.cpp | 10 ++-- mia/medium/bs-memory.cpp | 12 ++--- mia/medium/colecovision.cpp | 10 ++-- mia/medium/famicom-disk-system.cpp | 8 +-- mia/medium/famicom.cpp | 10 ++-- mia/medium/game-boy-advance.cpp | 10 ++-- mia/medium/game-boy.cpp | 10 ++-- mia/medium/game-gear.cpp | 10 ++-- mia/medium/master-system.cpp | 10 ++-- mia/medium/mega-32x.cpp | 10 ++-- mia/medium/mega-cd.cpp | 10 ++-- mia/medium/mega-drive.cpp | 10 ++-- mia/medium/msx.cpp | 22 ++++----- mia/medium/myvision.cpp | 10 ++-- mia/medium/neo-geo-pocket.cpp | 10 ++-- mia/medium/neo-geo.cpp | 20 ++++---- mia/medium/nintendo-64.cpp | 10 ++-- mia/medium/nintendo-64dd.cpp | 16 +++--- mia/medium/pc-engine-cd.cpp | 10 ++-- mia/medium/pc-engine.cpp | 10 ++-- mia/medium/playstation.cpp | 10 ++-- mia/medium/saturn.cpp | 10 ++-- mia/medium/sg-1000.cpp | 10 ++-- mia/medium/sufami-turbo.cpp | 12 ++--- mia/medium/super-famicom.cpp | 12 ++--- mia/medium/wonderswan.cpp | 10 ++-- mia/medium/zx-spectrum.cpp | 26 +++++----- mia/mia.cpp | 6 +-- mia/mia.hpp | 1 + mia/pak/pak.hpp | 2 +- mia/system/arcade.cpp | 6 +-- mia/system/atari-2600.cpp | 6 +-- mia/system/colecovision.cpp | 8 +-- mia/system/famicom.cpp | 6 +-- mia/system/game-boy-advance.cpp | 8 +-- mia/system/game-boy-color.cpp | 6 +-- mia/system/game-boy.cpp | 6 +-- mia/system/game-gear.cpp | 6 +-- mia/system/master-system.cpp | 6 +-- mia/system/mega-32x.cpp | 6 +-- mia/system/mega-cd-32x.cpp | 8 +-- mia/system/mega-cd.cpp | 8 +-- mia/system/mega-drive.cpp | 6 +-- mia/system/msx.cpp | 8 +-- mia/system/myvision.cpp | 6 +-- mia/system/neo-geo-aes.cpp | 8 +-- mia/system/neo-geo-mvs.cpp | 8 +-- mia/system/neo-geo-pocket-color.cpp | 8 +-- mia/system/neo-geo-pocket.cpp | 8 +-- mia/system/nintendo-64.cpp | 6 +-- mia/system/nintendo-64dd.cpp | 8 +-- mia/system/pc-engine.cpp | 6 +-- mia/system/playstation.cpp | 8 +-- mia/system/pocket-challenge-v2.cpp | 6 +-- mia/system/saturn.cpp | 8 +-- mia/system/sc-3000.cpp | 6 +-- mia/system/sg-1000.cpp | 6 +-- mia/system/super-famicom.cpp | 10 ++-- mia/system/supergrafx.cpp | 6 +-- mia/system/wonderswan-color.cpp | 6 +-- mia/system/wonderswan.cpp | 6 +-- mia/system/zx-spectrum-128.cpp | 6 +-- mia/system/zx-spectrum.cpp | 6 +-- 104 files changed, 875 insertions(+), 541 deletions(-) diff --git a/ares/ares/ares.hpp b/ares/ares/ares.hpp index 78ea449a52..f49a52e8c8 100644 --- a/ares/ares/ares.hpp +++ b/ares/ares/ares.hpp @@ -79,3 +79,33 @@ namespace ares { #include #include #include + +enum ResultEnum { + successful, + noFileSelected, + databaseNotFound, + romNotFoundInDatabase, + romNotFound, + invalidRom, + couldNotParseManifest, + noFirmware, + otherError +}; + +struct LoadResult { + ResultEnum result; + + string info; + string firmwareType; + string firmwareSystemName; + string firmwareRegion; + + LoadResult(ResultEnum r) : result(r), info(0) {} + + bool operator==(const LoadResult& other) { + return result == other.result; + } + bool operator!=(const LoadResult& other) { + return result != other.result; + } +}; diff --git a/desktop-ui/emulator/arcade.cpp b/desktop-ui/emulator/arcade.cpp index c9cb96a3a9..a18fb3f336 100644 --- a/desktop-ui/emulator/arcade.cpp +++ b/desktop-ui/emulator/arcade.cpp @@ -1,6 +1,6 @@ struct Arcade : Emulator { Arcade(); - auto load() -> bool override; + auto load() -> LoadResult override; auto save() -> bool override; auto pak(ares::Node::Object) -> shared_pointer override; auto group() -> string override { return "Arcade"; } @@ -33,17 +33,21 @@ Arcade::Arcade() { } } -auto Arcade::load() -> bool { +auto Arcade::load() -> LoadResult { game = mia::Medium::create("Arcade"); - if(!game->load(Emulator::load(game, configuration.game))) return false; + string location = Emulator::load(game, configuration.game); + if(!location) return LoadResult(noFileSelected); + LoadResult result = game->load(location); + if(result != LoadResult(successful)) return result; system = mia::System::create("Arcade"); - if(!system->load()) return false; + result = system->load(); + if(result != LoadResult(successful)) return result; //Determine from the game manifest which core to use for the given arcade rom #ifdef CORE_SG if(game->pak->attribute("board") == "sega/sg1000a") { - if(!ares::SG1000::load(root, {"[Sega] SG-1000A"})) return false; + if(!ares::SG1000::load(root, {"[Sega] SG-1000A"})) return LoadResult(otherError); systemPakName = "SG-1000A"; gamePakName = "Arcade Cartridge"; @@ -51,11 +55,11 @@ auto Arcade::load() -> bool { port->allocate(); port->connect(); } - return true; + return LoadResult(successful); } #endif - return false; + return LoadResult(otherError); } auto Arcade::save() -> bool { diff --git a/desktop-ui/emulator/atari-2600.cpp b/desktop-ui/emulator/atari-2600.cpp index 00e922d080..1a0b2ce735 100644 --- a/desktop-ui/emulator/atari-2600.cpp +++ b/desktop-ui/emulator/atari-2600.cpp @@ -1,6 +1,6 @@ struct Atari2600 : Emulator { Atari2600(); - auto load() -> bool override; + auto load() -> LoadResult override; auto save() -> bool override; auto pak(ares::Node::Object) -> shared_pointer override; }; @@ -38,15 +38,19 @@ Atari2600::Atari2600() { } } -auto Atari2600::load() -> bool { +auto Atari2600::load() -> LoadResult { game = mia::Medium::create("Atari 2600"); - if(!game->load(Emulator::load(game, configuration.game))) return false; + string location = Emulator::load(game, configuration.game); + if(!location) return LoadResult(noFileSelected); + LoadResult result = game->load(location); + if(result != LoadResult(successful)) return result; system = mia::System::create("Atari 2600"); - if(!system->load()) return false; + result = system->load(); + if(result != LoadResult(successful)) return result; auto region = Emulator::region(); - if(!ares::Atari2600::load(root, {"[Atari] Atari 2600 (", region, ")"})) return false; + if(!ares::Atari2600::load(root, {"[Atari] Atari 2600 (", region, ")"})) return LoadResult(otherError); if(auto port = root->find("Cartridge Slot")) { port->allocate(); @@ -63,7 +67,7 @@ auto Atari2600::load() -> bool { port->connect(); } - return true; + return LoadResult(successful); } auto Atari2600::save() -> bool { diff --git a/desktop-ui/emulator/colecovision.cpp b/desktop-ui/emulator/colecovision.cpp index 223c5e9b53..f606171816 100644 --- a/desktop-ui/emulator/colecovision.cpp +++ b/desktop-ui/emulator/colecovision.cpp @@ -1,6 +1,6 @@ struct ColecoVision : Emulator { ColecoVision(); - auto load() -> bool override; + auto load() -> LoadResult override; auto save() -> bool override; auto pak(ares::Node::Object) -> shared_pointer override; }; @@ -39,15 +39,24 @@ ColecoVision::ColecoVision() { } } -auto ColecoVision::load() -> bool { +auto ColecoVision::load() -> LoadResult { game = mia::Medium::create("ColecoVision"); - if(!game->load(Emulator::load(game, configuration.game))) return false; + string location = Emulator::load(game, configuration.game); + if(!location) return LoadResult(noFileSelected); + LoadResult result = game->load(location); + if(result != LoadResult(successful)) return result; system = mia::System::create("ColecoVision"); - if(!system->load(firmware[0].location)) return errorFirmware(firmware[0]), false; + if(system->load(firmware[0].location) != LoadResult(successful)) { + result.firmwareSystemName = "ColecoVision"; + result.firmwareType = firmware[0].type; + result.firmwareRegion = firmware[0].region; + result.result = noFirmware; + return result; + } auto region = Emulator::region(); - if(!ares::ColecoVision::load(root, {"[Coleco] ColecoVision (", region, ")"})) return false; + if(!ares::ColecoVision::load(root, {"[Coleco] ColecoVision (", region, ")"})) return LoadResult(otherError); if(auto port = root->find("Cartridge Slot")) { port->allocate(); @@ -64,7 +73,7 @@ auto ColecoVision::load() -> bool { port->connect(); } - return true; + return LoadResult(successful); } auto ColecoVision::save() -> bool { diff --git a/desktop-ui/emulator/emulator.cpp b/desktop-ui/emulator/emulator.cpp index 623faf26c9..a77fa5d041 100644 --- a/desktop-ui/emulator/emulator.cpp +++ b/desktop-ui/emulator/emulator.cpp @@ -54,12 +54,48 @@ auto Emulator::region() -> string { return {}; } +auto Emulator::handleLoadResult(LoadResult result) -> void { + switch (result.result) { + case successful: + break; + case noFileSelected: + break; + case couldNotParseManifest: + error("An error was encountered while parsing the manifest. \n" + ""); + break; + case databaseNotFound: + error("The database file for the system was not found. \n" + "Make sure that you have installed or packaged ares correctly."); + break; + case noFirmware: + if(MessageDialog().setText({ + "Error: firmware is missing or invalid.\n", + result.firmwareSystemName, " - ", result.firmwareType, " (", result.firmwareRegion, ") is required to play this game.\n" + "Would you like to configure firmware settings now?" + }).question() == "Yes") { + settingsWindow.show("Firmware"); + firmwareSettings.select(emulator->name, result.firmwareType, result.firmwareRegion); + } + break; + case romNotFound: + error("A required ROM file was not found."); + break; + case romNotFoundInDatabase: + error("The selected ROM was not found in the database."); + break; + case otherError: + error("Failed to load the selected system and ROM."); + break; + } +} + auto Emulator::load(const string& location) -> bool { if(inode::exists(location)) locationQueue.append(location); - - if(!load()) { - error("Failed to load system! Database files may have been incorrectly \n" - "installed. Make sure you have packaged or installed ares correctly."); + + LoadResult result = load(); + handleLoadResult(result); + if(result != LoadResult(successful)) { return false; } setBoolean("Color Emulation", settings.video.colorEmulation); @@ -180,14 +216,6 @@ auto Emulator::error(const string& text) -> void { auto Emulator::errorFirmware(const Firmware& firmware, string system) -> void { if(!system) system = emulator->name; - if(MessageDialog().setText({ - "Error: firmware is missing or invalid.\n", - system, " - ", firmware.type, " (", firmware.region, ") is required to play this game.\n" - "Would you like to configure firmware settings now?" - }).question() == "Yes") { - settingsWindow.show("Firmware"); - firmwareSettings.select(system, firmware.type, firmware.region); - } } auto Emulator::input(ares::Node::Input::Input input) -> void { diff --git a/desktop-ui/emulator/emulator.hpp b/desktop-ui/emulator/emulator.hpp index ff6b71dec1..584c670134 100644 --- a/desktop-ui/emulator/emulator.hpp +++ b/desktop-ui/emulator/emulator.hpp @@ -24,8 +24,9 @@ struct Emulator { auto save(mia::Pak& node, string name) -> bool; virtual auto input(ares::Node::Input::Input) -> void; auto inputKeyboard(string name) -> bool; + auto handleLoadResult(LoadResult result) -> void; virtual auto load(Menu) -> void {} - virtual auto load() -> bool = 0; + virtual auto load() -> LoadResult = 0; virtual auto save() -> bool { return true; } virtual auto pak(ares::Node::Object) -> shared_pointer = 0; virtual auto notify(const string& message) -> void {} diff --git a/desktop-ui/emulator/famicom-disk-system.cpp b/desktop-ui/emulator/famicom-disk-system.cpp index fabbcd3064..7d8d9cbaf3 100644 --- a/desktop-ui/emulator/famicom-disk-system.cpp +++ b/desktop-ui/emulator/famicom-disk-system.cpp @@ -1,7 +1,7 @@ struct FamicomDiskSystem : Emulator { FamicomDiskSystem(); auto load(Menu) -> void override; - auto load() -> bool override; + auto load() -> LoadResult override; auto save() -> bool override; auto pak(ares::Node::Object) -> shared_pointer override; auto notify(const string& message) -> void override; @@ -65,17 +65,28 @@ auto FamicomDiskSystem::load(Menu menu) -> void { return (void)disk1sideA.setChecked(); } -auto FamicomDiskSystem::load() -> bool { +auto FamicomDiskSystem::load() -> LoadResult { game = mia::Medium::create("Famicom Disk System"); - if(!game->load(Emulator::load(game, configuration.game))) return false; + string location = Emulator::load(game, configuration.game); + if(!location) return LoadResult(noFileSelected); + LoadResult result = game->load(location); + if(result != LoadResult(successful)) return result; bios = mia::Medium::create("Famicom"); - if(!bios->load(firmware[0].location)) return errorFirmware(firmware[0]), false; + result = bios->load(firmware[0].location); + if(result != LoadResult(successful)) { + result.firmwareSystemName = "Famicom"; + result.firmwareType = firmware[0].type; + result.firmwareRegion = firmware[0].region; + result.result = noFirmware; + return result; + } system = mia::System::create("Famicom"); - if(!system->load()) return false; + result = system->load(); + if(result != LoadResult(successful)) return result; - if(!ares::Famicom::load(root, "[Nintendo] Famicom (NTSC-J)")) return false; + if(!ares::Famicom::load(root, "[Nintendo] Famicom (NTSC-J)")) return LoadResult(otherError); if(auto port = root->find("Cartridge Slot")) { port->allocate(); @@ -101,7 +112,7 @@ auto FamicomDiskSystem::load() -> bool { port->connect(); } - return true; + return LoadResult(successful); } auto FamicomDiskSystem::save() -> bool { diff --git a/desktop-ui/emulator/famicom.cpp b/desktop-ui/emulator/famicom.cpp index 109e698587..eb5b53f7c4 100644 --- a/desktop-ui/emulator/famicom.cpp +++ b/desktop-ui/emulator/famicom.cpp @@ -1,6 +1,6 @@ struct Famicom : Emulator { Famicom(); - auto load() -> bool override; + auto load() -> LoadResult override; auto save() -> bool override; auto pak(ares::Node::Object) -> shared_pointer override; }; @@ -35,15 +35,19 @@ Famicom::Famicom() { } } -auto Famicom::load() -> bool { +auto Famicom::load() -> LoadResult { game = mia::Medium::create("Famicom"); - if(!game->load(Emulator::load(game, configuration.game))) return false; + string location = Emulator::load(game, configuration.game); + if(!location) return LoadResult(noFileSelected); + LoadResult result = game->load(location); + if(result != LoadResult(successful)) return result; system = mia::System::create("Famicom"); - if(!system->load()) return false; + result = system->load(); + if(result != LoadResult(successful)) return result; auto region = Emulator::region(); - if(!ares::Famicom::load(root, {"[Nintendo] Famicom (", region, ")"})) return false; + if(!ares::Famicom::load(root, {"[Nintendo] Famicom (", region, ")"})) return LoadResult(otherError); if(auto port = root->find("Cartridge Slot")) { port->allocate(); @@ -67,7 +71,7 @@ auto Famicom::load() -> bool { } } - return true; + return LoadResult(successful); } auto Famicom::save() -> bool { diff --git a/desktop-ui/emulator/game-boy-advance.cpp b/desktop-ui/emulator/game-boy-advance.cpp index 4546e4035d..2c4f5a4484 100644 --- a/desktop-ui/emulator/game-boy-advance.cpp +++ b/desktop-ui/emulator/game-boy-advance.cpp @@ -1,7 +1,7 @@ struct GameBoyAdvance : Emulator { GameBoyAdvance(); auto load(Menu) -> void override; - auto load() -> bool override; + auto load() -> LoadResult override; auto save() -> bool override; auto pak(ares::Node::Object) -> shared_pointer override; }; @@ -50,23 +50,32 @@ auto GameBoyAdvance::load(Menu menu) -> void { } } -auto GameBoyAdvance::load() -> bool { +auto GameBoyAdvance::load() -> LoadResult { game = mia::Medium::create("Game Boy Advance"); - if(!game->load(Emulator::load(game, configuration.game))) return false; + string location = Emulator::load(game, configuration.game); + if(!location) return LoadResult(noFileSelected); + LoadResult result = game->load(location); + if(result != LoadResult(successful)) return result; system = mia::System::create("Game Boy Advance"); - if(!system->load(firmware[0].location)) return errorFirmware(firmware[0]), false; + if(system->load(firmware[0].location) != LoadResult(successful)) { + result.firmwareSystemName = "Game Boy Advance"; + result.firmwareType = firmware[0].type; + result.firmwareRegion = firmware[0].region; + result.result = noFirmware; + return result; + } ares::GameBoyAdvance::option("Pixel Accuracy", settings.video.pixelAccuracy); - if(!ares::GameBoyAdvance::load(root, "[Nintendo] Game Boy Advance")) return false; + if(!ares::GameBoyAdvance::load(root, "[Nintendo] Game Boy Advance")) return LoadResult(otherError); if(auto port = root->find("Cartridge Slot")) { port->allocate(); port->connect(); } - return true; + return LoadResult(successful); } auto GameBoyAdvance::save() -> bool { diff --git a/desktop-ui/emulator/game-boy-color.cpp b/desktop-ui/emulator/game-boy-color.cpp index ea53a98506..d33f64857d 100644 --- a/desktop-ui/emulator/game-boy-color.cpp +++ b/desktop-ui/emulator/game-boy-color.cpp @@ -1,6 +1,6 @@ struct GameBoyColor : Emulator { GameBoyColor(); - auto load() -> bool override; + auto load() -> LoadResult override; auto save() -> bool override; auto pak(ares::Node::Object) -> shared_pointer override; }; @@ -27,14 +27,18 @@ GameBoyColor::GameBoyColor() { } } -auto GameBoyColor::load() -> bool { +auto GameBoyColor::load() -> LoadResult { game = mia::Medium::create("Game Boy Color"); - if(!game->load(Emulator::load(game, configuration.game))) return false; + string location = Emulator::load(game, configuration.game); + if(!location) return LoadResult(noFileSelected); + LoadResult result = game->load(location); + if(result != LoadResult(successful)) return result; system = mia::System::create("Game Boy Color"); - if(!system->load()) return false; + result = system->load(); + if(result != LoadResult(successful)) return result; - if(!ares::GameBoy::load(root, "[Nintendo] Game Boy Color")) return false; + if(!ares::GameBoy::load(root, "[Nintendo] Game Boy Color")) return LoadResult(otherError); if(auto port = root->find("Cartridge Slot")) { port->allocate(); @@ -45,7 +49,7 @@ auto GameBoyColor::load() -> bool { fastBoot->setValue(settings.boot.fast); } - return true; + return LoadResult(successful); } auto GameBoyColor::save() -> bool { diff --git a/desktop-ui/emulator/game-boy.cpp b/desktop-ui/emulator/game-boy.cpp index ad8d2c2034..1241209cc9 100644 --- a/desktop-ui/emulator/game-boy.cpp +++ b/desktop-ui/emulator/game-boy.cpp @@ -1,6 +1,6 @@ struct GameBoy : Emulator { GameBoy(); - auto load() -> bool override; + auto load() -> LoadResult override; auto load(Menu) -> void override; auto save() -> bool override; auto pak(ares::Node::Object) -> shared_pointer override; @@ -28,14 +28,18 @@ GameBoy::GameBoy() { } } -auto GameBoy::load() -> bool { +auto GameBoy::load() -> LoadResult { game = mia::Medium::create("Game Boy"); - if(!game->load(Emulator::load(game, configuration.game))) return false; + string location = Emulator::load(game, configuration.game); + if(!location) return LoadResult(noFileSelected); + LoadResult result = game->load(location); + if(result != LoadResult(successful)) return result; system = mia::System::create("Game Boy"); - if(!system->load()) return false; + result = system->load(); + if(result != LoadResult(successful)) return result; - if(!ares::GameBoy::load(root, "[Nintendo] Game Boy")) return false; + if(!ares::GameBoy::load(root, "[Nintendo] Game Boy")) return LoadResult(otherError); if(auto port = root->find("Cartridge Slot")) { port->allocate(); @@ -46,7 +50,7 @@ auto GameBoy::load() -> bool { fastBoot->setValue(settings.boot.fast); } - return true; + return LoadResult(successful); } auto GameBoy::load(Menu menu) -> void { diff --git a/desktop-ui/emulator/game-gear.cpp b/desktop-ui/emulator/game-gear.cpp index 7d909dc2bd..a3a603f440 100644 --- a/desktop-ui/emulator/game-gear.cpp +++ b/desktop-ui/emulator/game-gear.cpp @@ -1,6 +1,6 @@ struct GameGear : Emulator { GameGear(); - auto load() -> bool override; + auto load() -> LoadResult override; auto save() -> bool override; auto pak(ares::Node::Object) -> shared_pointer override; }; @@ -27,23 +27,33 @@ GameGear::GameGear() { } } -auto GameGear::load() -> bool { +auto GameGear::load() -> LoadResult { game = mia::Medium::create("Game Gear"); - if(!game->load(Emulator::load(game, configuration.game))) return false; + string location = Emulator::load(game, configuration.game); + if(!location) return LoadResult(noFileSelected); + LoadResult result = game->load(location); + if(result != LoadResult(successful)) return result; auto region = Emulator::region(); system = mia::System::create("Game Gear"); - if(!system->load(firmware[0].location)) return false; + result = system->load(firmware[0].location); + if(result != LoadResult(successful)) { + result.firmwareSystemName = "Game Gear"; + result.firmwareType = firmware[0].type; + result.firmwareRegion = firmware[0].region; + result.result = noFirmware; + return result; + } - if(!ares::MasterSystem::load(root, {"[Sega] Game Gear (", region, ")"})) return false; + if(!ares::MasterSystem::load(root, {"[Sega] Game Gear (", region, ")"})) return LoadResult(otherError); if(auto port = root->find("Cartridge Slot")) { port->allocate(); port->connect(); } - return true; + return LoadResult(successful); } auto GameGear::save() -> bool { diff --git a/desktop-ui/emulator/master-system.cpp b/desktop-ui/emulator/master-system.cpp index 7095418600..fa2d69c8c7 100644 --- a/desktop-ui/emulator/master-system.cpp +++ b/desktop-ui/emulator/master-system.cpp @@ -1,6 +1,6 @@ struct MasterSystem : Emulator { MasterSystem(); - auto load() -> bool override; + auto load() -> LoadResult override; auto save() -> bool override; auto pak(ares::Node::Object) -> shared_pointer override; @@ -90,9 +90,12 @@ MasterSystem::MasterSystem() { } } -auto MasterSystem::load() -> bool { +auto MasterSystem::load() -> LoadResult { game = mia::Medium::create("Master System"); - if(!game->load(Emulator::load(game, configuration.game))) return false; + string location = Emulator::load(game, configuration.game); + if(!location) return LoadResult(noFileSelected); + LoadResult result = game->load(location); + if(result != LoadResult(successful)) return result; auto region = Emulator::region(); //if statements below are ordered by lowest to highest priority @@ -101,10 +104,17 @@ auto MasterSystem::load() -> bool { if(region == "NTSC-U") regionID = 0; system = mia::System::create("Master System"); - if(!system->load(firmware[regionID].location)) return false; - if(!game->pak && !system->pak->read("bios.rom")) return false; + result = system->load(firmware[regionID].location); + if(result != LoadResult(successful)) { + result.firmwareSystemName = "Master System"; + result.firmwareType = firmware[regionID].type; + result.firmwareRegion = firmware[regionID].region; + result.result = noFirmware; + return result; + } + if(!game->pak && !system->pak->read("bios.rom")) return LoadResult(otherError); - if(!ares::MasterSystem::load(root, {"[Sega] Master System (", region, ")"})) return false; + if(!ares::MasterSystem::load(root, {"[Sega] Master System (", region, ")"})) return LoadResult(otherError); if(auto port = root->find("Cartridge Slot")) { port->allocate(); @@ -130,7 +140,7 @@ auto MasterSystem::load() -> bool { port->connect(); } - return true; + return LoadResult(successful); } auto MasterSystem::save() -> bool { diff --git a/desktop-ui/emulator/mega-32x.cpp b/desktop-ui/emulator/mega-32x.cpp index d43fe1f6d0..a89c964f74 100644 --- a/desktop-ui/emulator/mega-32x.cpp +++ b/desktop-ui/emulator/mega-32x.cpp @@ -1,6 +1,6 @@ struct Mega32X : Emulator { Mega32X(); - auto load() -> bool override; + auto load() -> LoadResult override; auto save() -> bool override; auto pak(ares::Node::Object) -> shared_pointer override; @@ -43,10 +43,13 @@ Mega32X::Mega32X() { } } -auto Mega32X::load() -> bool { +auto Mega32X::load() -> LoadResult { game = mia::Medium::create("Mega 32X"); - if(!game->load(Emulator::load(game, configuration.game))) return false; - + string location = Emulator::load(game, configuration.game); + if(!location) return LoadResult(noFileSelected); + LoadResult result = game->load(location); + if(result != LoadResult(successful)) return result; + auto region = Emulator::region(); //if statements below are ordered by lowest to highest priority if(region == "PAL" ) regionID = 2; @@ -60,22 +63,30 @@ auto Mega32X::load() -> bool { for(auto& emulator : emulators) { if(emulator->name == "Mega CD") firmware = emulator->firmware; } - if(!firmware) return false; //should never occur + if(!firmware) return LoadResult(otherError); //should never occur name = "Mega CD 32X"; system = mia::System::create("Mega CD 32X"); - if(!system->load(firmware[regionID].location)) return errorFirmware(firmware[regionID], "Mega CD"), false; + result = system->load(firmware[regionID].location); + if(result != LoadResult(successful)) { + result.firmwareSystemName = "Mega CD 32X"; + result.firmwareType = firmware[regionID].type; + result.firmwareRegion = firmware[regionID].region; + result.result = noFirmware; + return result; + } disc = mia::Medium::create("Mega CD"); - if(!disc->load(Emulator::load(disc, configuration.game))) disc.reset(); + if(disc->load(Emulator::load(disc, configuration.game)) != LoadResult(successful)) disc.reset(); } else { name = "Mega 32X"; system = mia::System::create("Mega 32X"); - if(!system->load()) return false; + result = system->load(); + if(result != LoadResult(successful)) return result; } ares::MegaDrive::option("Recompiler", !settings.general.forceInterpreter); - if(!ares::MegaDrive::load(root, {"[Sega] ", name, " (", region, ")"})) return false; + if(!ares::MegaDrive::load(root, {"[Sega] ", name, " (", region, ")"})) return LoadResult(otherError); if(auto port = root->find("Cartridge Slot")) { port->allocate(); @@ -97,7 +108,7 @@ auto Mega32X::load() -> bool { port->connect(); } - return true; + return LoadResult(successful); } auto Mega32X::save() -> bool { diff --git a/desktop-ui/emulator/mega-cd-32x.cpp b/desktop-ui/emulator/mega-cd-32x.cpp index 96a6f666d4..814518eaab 100644 --- a/desktop-ui/emulator/mega-cd-32x.cpp +++ b/desktop-ui/emulator/mega-cd-32x.cpp @@ -1,6 +1,6 @@ struct MegaCD32X : Emulator { MegaCD32X(); - auto load() -> bool override; + auto load() -> LoadResult override; auto load(Menu) -> void override; auto unload() -> void override; auto save() -> bool override; @@ -45,9 +45,12 @@ MegaCD32X::MegaCD32X() { } } -auto MegaCD32X::load() -> bool { +auto MegaCD32X::load() -> LoadResult { game = mia::Medium::create("Mega CD"); - if(!game->load(Emulator::load(game, configuration.game))) return false; + string location = Emulator::load(game, configuration.game); + if(!location) return LoadResult(noFileSelected); + LoadResult result = game->load(location); + if(result != LoadResult(successful)) return result; auto region = Emulator::region(); //if statements below are ordered by lowest to highest priority @@ -60,14 +63,21 @@ auto MegaCD32X::load() -> bool { for(auto& emulator : emulators) { if(emulator->name == "Mega CD") firmware = emulator->firmware; } - if(!firmware) return false; //should never occur + if(!firmware) return LoadResult(noFirmware); //should never occur system = mia::System::create("Mega CD 32X"); - if(!system->load(firmware[regionID].location)) return errorFirmware(firmware[regionID], "Mega CD"), false; + result = system->load(firmware[regionID].location); + if(result != LoadResult(successful)) { + result.firmwareSystemName = "Mega CD 32X"; + result.firmwareType = firmware[regionID].type; + result.firmwareRegion = firmware[regionID].region; + result.result = noFirmware; + return result; + } ares::MegaDrive::option("Recompiler", !settings.general.forceInterpreter); - if(!ares::MegaDrive::load(root, {"[Sega] Mega CD 32X (", region, ")"})) return false; + if(!ares::MegaDrive::load(root, {"[Sega] Mega CD 32X (", region, ")"})) return LoadResult(otherError); if(auto port = root->find("Cartridge Slot")) { port->allocate(); @@ -98,7 +108,7 @@ auto MegaCD32X::load() -> bool { discTrayTimer = Timer{}; - return true; + return LoadResult(successful); } @@ -110,7 +120,7 @@ auto MegaCD32X::load(Menu menu) -> void { auto tray = root->find("Mega CD/Disc Tray"); tray->disconnect(); - if(!game->load(Emulator::load(game, configuration.game))) { + if(game->load(Emulator::load(game, configuration.game)) != LoadResult(successful)) { return; } diff --git a/desktop-ui/emulator/mega-cd.cpp b/desktop-ui/emulator/mega-cd.cpp index acefa19156..145fc2cab7 100644 --- a/desktop-ui/emulator/mega-cd.cpp +++ b/desktop-ui/emulator/mega-cd.cpp @@ -1,6 +1,6 @@ struct MegaCD : Emulator { MegaCD(); - auto load() -> bool override; + auto load() -> LoadResult override; auto load(Menu) -> void override; auto unload() -> void override; auto save() -> bool override; @@ -60,9 +60,12 @@ MegaCD::MegaCD() { } } -auto MegaCD::load() -> bool { +auto MegaCD::load() -> LoadResult { game = mia::Medium::create("Mega CD"); - if(!game->load(Emulator::load(game, configuration.game))) return false; + string location = Emulator::load(game, configuration.game); + if(!location) return LoadResult(noFileSelected); + LoadResult result = game->load(location); + if(result != LoadResult(successful)) return result; auto region = Emulator::region(); //if statements below are ordered by lowest to highest priority @@ -71,9 +74,16 @@ auto MegaCD::load() -> bool { if(region == "NTSC-U") regionID = 0; system = mia::System::create("Mega CD"); - if(!system->load(firmware[regionID].location)) return errorFirmware(firmware[regionID]), false; + result = system->load(firmware[regionID].location); + if(result != LoadResult(successful)) { + result.firmwareSystemName = "Mega CD"; + result.firmwareType = firmware[regionID].type; + result.firmwareRegion = firmware[regionID].region; + result.result = noFirmware; + return result; + } - if(!ares::MegaDrive::load(root, {"[Sega] Mega CD (", region, ")"})) return false; + if(!ares::MegaDrive::load(root, {"[Sega] Mega CD (", region, ")"})) return LoadResult(otherError); if(auto port = root->find("Cartridge Slot")) { port->allocate(); @@ -104,7 +114,7 @@ auto MegaCD::load() -> bool { discTrayTimer = Timer{}; - return true; + return LoadResult(successful); } auto MegaCD::load(Menu menu) -> void { @@ -115,7 +125,7 @@ auto MegaCD::load(Menu menu) -> void { auto tray = root->find("Mega CD/Disc Tray"); tray->disconnect(); - if(!game->load(Emulator::load(game, configuration.game))) { + if(game->load(Emulator::load(game, configuration.game)) != LoadResult(successful)) { return; } diff --git a/desktop-ui/emulator/mega-drive.cpp b/desktop-ui/emulator/mega-drive.cpp index 01b30380ac..45dd2913d7 100644 --- a/desktop-ui/emulator/mega-drive.cpp +++ b/desktop-ui/emulator/mega-drive.cpp @@ -1,6 +1,6 @@ struct MegaDrive : Emulator { MegaDrive(); - auto load() -> bool override; + auto load() -> LoadResult override; auto save() -> bool override; auto pak(ares::Node::Object) -> shared_pointer override; @@ -54,9 +54,12 @@ MegaDrive::MegaDrive() { } } -auto MegaDrive::load() -> bool { +auto MegaDrive::load() -> LoadResult { game = mia::Medium::create("Mega Drive"); - if(!game->load(Emulator::load(game, configuration.game))) return false; + string location = Emulator::load(game, configuration.game); + if(!location) return LoadResult(noFileSelected); + LoadResult result = game->load(location); + if(result != LoadResult(successful)) return result; auto region = Emulator::region(); //if statements below are ordered by lowest to highest priority @@ -71,22 +74,30 @@ auto MegaDrive::load() -> bool { for(auto& emulator : emulators) { if(emulator->name == "Mega CD") firmware = emulator->firmware; } - if(!firmware) return false; //should never occur + if(!firmware) return LoadResult(otherError); //should never occur name = "Mega CD"; system = mia::System::create("Mega CD"); - if(!system->load(firmware[regionID].location)) return errorFirmware(firmware[regionID], "Mega CD"), false; + result = system->load(firmware[regionID].location); + if(result != LoadResult(successful)) { + result.firmwareSystemName = "Mega CD"; + result.firmwareType = firmware[regionID].type; + result.firmwareRegion = firmware[regionID].region; + result.result = noFirmware; + return result; + } disc = mia::Medium::create("Mega CD"); - if(!disc->load(Emulator::load(disc, configuration.game))) disc.reset(); + if(disc->load(Emulator::load(disc, configuration.game)) != LoadResult(successful)) disc.reset(); } else { name = "Mega Drive"; system = mia::System::create("Mega Drive"); - if(!system->load()) return false; + result = system->load(); + if(result != LoadResult(successful)) return result; } ares::MegaDrive::option("TMSS", settings.megadrive.tmss); - if(!ares::MegaDrive::load(root, {"[Sega] ", name, " (", region, ")"})) return false; + if(!ares::MegaDrive::load(root, {"[Sega] ", name, " (", region, ")"})) return LoadResult(otherError); if(auto port = root->find("Cartridge Slot")) { port->allocate(); @@ -108,7 +119,7 @@ auto MegaDrive::load() -> bool { port->connect(); } - return true; + return LoadResult(successful); } auto MegaDrive::save() -> bool { diff --git a/desktop-ui/emulator/msx.cpp b/desktop-ui/emulator/msx.cpp index 55bc7119af..c15a636bd2 100644 --- a/desktop-ui/emulator/msx.cpp +++ b/desktop-ui/emulator/msx.cpp @@ -1,6 +1,6 @@ struct MSX : Emulator { MSX(); - auto load() -> bool override; + auto load() -> LoadResult override; auto load(Menu) -> void override; auto save() -> bool override; auto pak(ares::Node::Object) -> shared_pointer override; @@ -37,16 +37,26 @@ MSX::MSX() { } } -auto MSX::load() -> bool { +auto MSX::load() -> LoadResult { game = mia::Medium::create("MSX"); - if(!game->load(Emulator::load(game, configuration.game))) return false; + string location = Emulator::load(game, configuration.game); + if(!location) return LoadResult(noFileSelected); + LoadResult result = game->load(location); + if(result != LoadResult(successful)) return result; bool isTape = game->pak->attribute("tape").boolean(); system = mia::System::create("MSX"); - if(!system->load(firmware[0].location)) return errorFirmware(firmware[0]), false; + result = system->load(firmware[0].location); + if(result != LoadResult(successful)) { + result.firmwareSystemName = "MSX"; + result.firmwareType = firmware[0].type; + result.firmwareRegion = firmware[0].region; + result.result = noFirmware; + return result; + } auto region = Emulator::region(); - if(!ares::MSX::load(root, {"[Microsoft] MSX (", region, ")"})) return false; + if(!ares::MSX::load(root, {"[Microsoft] MSX (", region, ")"})) return LoadResult(otherError); if(auto port = root->find("Cartridge Slot")) { port->allocate(); @@ -76,7 +86,7 @@ auto MSX::load() -> bool { port->connect(); } - return true; + return LoadResult(successful); } auto MSX::load(Menu menu) -> void { diff --git a/desktop-ui/emulator/msx2.cpp b/desktop-ui/emulator/msx2.cpp index db4967c95b..99e29e9a31 100644 --- a/desktop-ui/emulator/msx2.cpp +++ b/desktop-ui/emulator/msx2.cpp @@ -1,6 +1,6 @@ struct MSX2 : MSX { MSX2(); - auto load() -> bool override; + auto load() -> LoadResult override; auto save() -> bool override; auto pak(ares::Node::Object) -> shared_pointer override; auto input(ares::Node::Input::Input) -> void override; @@ -31,18 +31,25 @@ MSX2::MSX2() { } } -auto MSX2::load() -> bool { +auto MSX2::load() -> LoadResult { game = mia::Medium::create("MSX2"); - if(!game->load(Emulator::load(game, configuration.game))) return false; + string location = Emulator::load(game, configuration.game); + if(!location) return LoadResult(noFileSelected); + LoadResult result = game->load(location); + if(result != LoadResult(successful)) return result; bool isTape = game->pak->attribute("tape").boolean(); system = mia::System::create("MSX2"); if(!system->loadMultiple({firmware[0].location, firmware[1].location})) { - return errorFirmware(firmware[0]), false; + result.result = noFirmware; + result.firmwareType = firmware[0].type; + result.firmwareRegion = firmware[0].region; + result.firmwareSystemName = "MSX2"; + return result; } auto region = Emulator::region(); - if(!ares::MSX::load(root, {"[Microsoft] MSX2 (", region, ")"})) return false; + if(!ares::MSX::load(root, {"[Microsoft] MSX2 (", region, ")"})) return LoadResult(otherError); if(auto port = root->find("Cartridge Slot")) { port->allocate(); @@ -69,7 +76,7 @@ auto MSX2::load() -> bool { port->connect(); } - return true; + return LoadResult(successful); } auto MSX2::save() -> bool { diff --git a/desktop-ui/emulator/myvision.cpp b/desktop-ui/emulator/myvision.cpp index bc09c05c48..0edf99faec 100644 --- a/desktop-ui/emulator/myvision.cpp +++ b/desktop-ui/emulator/myvision.cpp @@ -1,6 +1,6 @@ struct MyVision: Emulator { MyVision(); - auto load() -> bool override; + auto load() -> LoadResult override; auto save() -> bool override; auto pak(ares::Node::Object) -> shared_pointer < vfs::directory > override; }; @@ -42,23 +42,27 @@ MyVision::MyVision() { } } -auto MyVision::load() -> bool { +auto MyVision::load() -> LoadResult { game = mia::Medium::create("MyVision"); - if (!game -> load(Emulator::load(game, configuration.game))) return false; + string location = Emulator::load(game, configuration.game); + if(!location) return LoadResult(noFileSelected); + LoadResult result = game->load(location); + if(result != LoadResult(successful)) return result; system = mia::System::create("MyVision"); - if(!system->load()) return false; + result = system->load(); + if(result != LoadResult(successful)) return result; if (!ares::MyVision::load(root, { "[Nichibutsu] MyVision" - })) return false; + })) return LoadResult(otherError); if (auto port = root -> find < ares::Node::Port > ("Cartridge Slot")) { port -> allocate(); port -> connect(); } - return true; + return LoadResult(successful); } auto MyVision::save() -> bool { diff --git a/desktop-ui/emulator/neo-geo-aes.cpp b/desktop-ui/emulator/neo-geo-aes.cpp index 8125f96517..c56814a067 100644 --- a/desktop-ui/emulator/neo-geo-aes.cpp +++ b/desktop-ui/emulator/neo-geo-aes.cpp @@ -1,6 +1,6 @@ struct NeoGeoAES : Emulator { NeoGeoAES(); - auto load() -> bool override; + auto load() -> LoadResult override; auto save() -> bool override; auto pak(ares::Node::Object) -> shared_pointer override; auto arcade() -> bool override { return true; } @@ -34,14 +34,24 @@ NeoGeoAES::NeoGeoAES() { } } -auto NeoGeoAES::load() -> bool { +auto NeoGeoAES::load() -> LoadResult { game = mia::Medium::create("Neo Geo"); - if(!game->load(Emulator::load(game, configuration.game))) return false; + string location = Emulator::load(game, configuration.game); + if(!location) return LoadResult(noFileSelected); + LoadResult result = game->load(location); + if(result != LoadResult(successful)) return result; system = mia::System::create("Neo Geo AES"); - if(!system->load(firmware[0].location)) return errorFirmware(firmware[0]), false; + result = system->load(firmware[0].location); + if(result != LoadResult(successful)) { + result.firmwareSystemName = "Neo Geo AES"; + result.firmwareType = firmware[0].type; + result.firmwareRegion = firmware[0].region; + result.result = noFirmware; + return result; + } - if(!ares::NeoGeo::load(root, "[SNK] Neo Geo AES")) return false; + if(!ares::NeoGeo::load(root, "[SNK] Neo Geo AES")) return LoadResult(otherError); if(auto port = root->find("Cartridge Slot")) { port->allocate(); @@ -63,7 +73,7 @@ auto NeoGeoAES::load() -> bool { port->connect(); } - return true; + return LoadResult(successful); } auto NeoGeoAES::save() -> bool { diff --git a/desktop-ui/emulator/neo-geo-mvs.cpp b/desktop-ui/emulator/neo-geo-mvs.cpp index cc0e46719a..251bd0c21e 100644 --- a/desktop-ui/emulator/neo-geo-mvs.cpp +++ b/desktop-ui/emulator/neo-geo-mvs.cpp @@ -1,6 +1,6 @@ struct NeoGeoMVS : Emulator { NeoGeoMVS(); - auto load() -> bool override; + auto load() -> LoadResult override; auto save() -> bool override; auto pak(ares::Node::Object) -> shared_pointer override; auto group() -> string override { return "Arcade"; } @@ -35,14 +35,24 @@ NeoGeoMVS::NeoGeoMVS() { } } -auto NeoGeoMVS::load() -> bool { +auto NeoGeoMVS::load() -> LoadResult { game = mia::Medium::create("Neo Geo"); - if(!game->load(Emulator::load(game, configuration.game))) return false; + string location = Emulator::load(game, configuration.game); + if(!location) return LoadResult(noFileSelected); + LoadResult result = game->load(location); + if(result != LoadResult(successful)) return result; system = mia::System::create("Neo Geo MVS"); - if(!system->load(firmware[0].location)) return errorFirmware(firmware[0]), false; + result = system->load(firmware[0].location); + if(result != LoadResult(successful)) { + result.firmwareSystemName = "Neo Geo MVS"; + result.firmwareType = firmware[0].type; + result.firmwareRegion = firmware[0].region; + result.result = noFirmware; + return result; + } - if(!ares::NeoGeo::load(root, "[SNK] Neo Geo MVS")) return false; + if(!ares::NeoGeo::load(root, "[SNK] Neo Geo MVS")) return LoadResult(otherError); if(auto port = root->find("Cartridge Slot")) { port->allocate(); @@ -64,7 +74,7 @@ auto NeoGeoMVS::load() -> bool { port->connect(); } - return true; + return LoadResult(successful); } auto NeoGeoMVS::save() -> bool { diff --git a/desktop-ui/emulator/neo-geo-pocket-color.cpp b/desktop-ui/emulator/neo-geo-pocket-color.cpp index eeae7a802f..9e82444026 100644 --- a/desktop-ui/emulator/neo-geo-pocket-color.cpp +++ b/desktop-ui/emulator/neo-geo-pocket-color.cpp @@ -1,6 +1,6 @@ struct NeoGeoPocketColor : Emulator { NeoGeoPocketColor(); - auto load() -> bool override; + auto load() -> LoadResult override; auto save() -> bool override; auto pak(ares::Node::Object) -> shared_pointer override; }; @@ -29,14 +29,24 @@ NeoGeoPocketColor::NeoGeoPocketColor() { } } -auto NeoGeoPocketColor::load() -> bool { +auto NeoGeoPocketColor::load() -> LoadResult { game = mia::Medium::create("Neo Geo Pocket Color"); - if(!game->load(Emulator::load(game, configuration.game))) return false; + string location = Emulator::load(game, configuration.game); + if(!location) return LoadResult(noFileSelected); + LoadResult result = game->load(location); + if(result != LoadResult(successful)) return result; system = mia::System::create("Neo Geo Pocket Color"); - if(!system->load(firmware[0].location)) return errorFirmware(firmware[0]), false; + result = system->load(firmware[0].location); + if(result != LoadResult(successful)) { + result.firmwareSystemName = "Neo Geo Pocket Color"; + result.firmwareType = firmware[0].type; + result.firmwareRegion = firmware[0].region; + result.result = noFirmware; + return result; + } - if(!ares::NeoGeoPocket::load(root, "[SNK] Neo Geo Pocket Color")) return false; + if(!ares::NeoGeoPocket::load(root, "[SNK] Neo Geo Pocket Color")) return LoadResult(otherError); if(auto port = root->find("Cartridge Slot")) { port->allocate(); @@ -47,7 +57,7 @@ auto NeoGeoPocketColor::load() -> bool { fastBoot->setValue(settings.boot.fast); } - return true; + return LoadResult(successful); } auto NeoGeoPocketColor::save() -> bool { diff --git a/desktop-ui/emulator/neo-geo-pocket.cpp b/desktop-ui/emulator/neo-geo-pocket.cpp index b4ed9d67c4..ddeaecdd4c 100644 --- a/desktop-ui/emulator/neo-geo-pocket.cpp +++ b/desktop-ui/emulator/neo-geo-pocket.cpp @@ -1,6 +1,6 @@ struct NeoGeoPocket : Emulator { NeoGeoPocket(); - auto load() -> bool override; + auto load() -> LoadResult override; auto save() -> bool override; auto pak(ares::Node::Object) -> shared_pointer override; }; @@ -29,14 +29,24 @@ NeoGeoPocket::NeoGeoPocket() { } } -auto NeoGeoPocket::load() -> bool { +auto NeoGeoPocket::load() -> LoadResult { game = mia::Medium::create("Neo Geo Pocket"); - if(!game->load(Emulator::load(game, configuration.game))) return false; + string location = Emulator::load(game, configuration.game); + if(!location) return LoadResult(noFileSelected); + LoadResult result = game->load(location); + if(result != LoadResult(successful)) return result; system = mia::System::create("Neo Geo Pocket"); - if(!system->load(firmware[0].location)) return errorFirmware(firmware[0]), false; + result = system->load(firmware[0].location); + if(result != LoadResult(successful)) { + result.firmwareSystemName = "Neo Geo Pocket"; + result.firmwareType = firmware[0].type; + result.firmwareRegion = firmware[0].region; + result.result = noFirmware; + return result; + } - if(!ares::NeoGeoPocket::load(root, "[SNK] Neo Geo Pocket")) return false; + if(!ares::NeoGeoPocket::load(root, "[SNK] Neo Geo Pocket")) return LoadResult(otherError);; if(auto port = root->find("Cartridge Slot")) { port->allocate(); @@ -47,7 +57,7 @@ auto NeoGeoPocket::load() -> bool { fastBoot->setValue(settings.boot.fast); } - return true; + return LoadResult(successful); } auto NeoGeoPocket::save() -> bool { diff --git a/desktop-ui/emulator/nintendo-64.cpp b/desktop-ui/emulator/nintendo-64.cpp index 1b8be315c4..db580d9420 100644 --- a/desktop-ui/emulator/nintendo-64.cpp +++ b/desktop-ui/emulator/nintendo-64.cpp @@ -1,6 +1,6 @@ struct Nintendo64 : Emulator { Nintendo64(); - auto load() -> bool override; + auto load() -> LoadResult override; auto load(Menu) -> void override; auto portMenu(Menu& portMenu, ares::Node::Port port) -> void override; auto unload() -> void override; @@ -54,9 +54,12 @@ Nintendo64::Nintendo64() { } } -auto Nintendo64::load() -> bool { +auto Nintendo64::load() -> LoadResult { game = mia::Medium::create("Nintendo 64"); - if(!game->load(Emulator::load(game, configuration.game))) return false; + string location = Emulator::load(game, configuration.game); + if(!location) return LoadResult(noFileSelected); + LoadResult result = game->load(location); + if(result != LoadResult(successful)) return result; auto region = Emulator::region(); @@ -67,15 +70,16 @@ auto Nintendo64::load() -> bool { for(auto& emulator : emulators) { if(emulator->name == "Nintendo 64DD") firmware = emulator->firmware; } - if(!firmware) return false; //should never occur + if(!firmware) return LoadResult(noFirmware); //should never occur name = "Nintendo 64DD"; disk = mia::Medium::create("Nintendo 64DD"); - if(!disk->load(Emulator::load(disk, configuration.game))) { + if(disk->load(Emulator::load(disk, configuration.game)) != LoadResult(successful)) { disk.reset(); name = "Nintendo 64"; system = mia::System::create("Nintendo 64"); - if(!system->load()) return false; + result = system->load(); + if(result != LoadResult(successful)) return result; } else { region = disk->pak->attribute("region"); //if statements below are ordered by lowest to highest priority @@ -84,12 +88,20 @@ auto Nintendo64::load() -> bool { if (region == "NTSC-J") regionID = 0; system = mia::System::create(name); - if(!system->load(firmware[regionID].location)) return errorFirmware(firmware[regionID], "Nintendo 64DD"), false; + result = system->load(firmware[regionID].location); + if(result != LoadResult(successful)) { + result.firmwareSystemName = "Nintendo 64"; + result.firmwareType = firmware[regionID].type; + result.firmwareRegion = firmware[regionID].region; + result.result = noFirmware; + return result; + } } } else { name = "Nintendo 64"; system = mia::System::create("Nintendo 64"); - if(!system->load()) return false; + result = system->load(); + if(result != LoadResult(successful)) return result; } ares::Nintendo64::option("Quality", settings.video.quality); @@ -105,7 +117,7 @@ auto Nintendo64::load() -> bool { ares::Nintendo64::option("Recompiler", !settings.general.forceInterpreter); ares::Nintendo64::option("Expansion Pak", settings.nintendo64.expansionPak); - if(!ares::Nintendo64::load(root, {"[Nintendo] ", name, " (", region, ")"})) return false; + if(!ares::Nintendo64::load(root, {"[Nintendo] ", name, " (", region, ")"})) return LoadResult(otherError); if(auto port = root->find("Cartridge Slot")) { port->allocate(); @@ -135,7 +147,7 @@ auto Nintendo64::load() -> bool { if(auto slot = transferPak->find("Cartridge Slot")) { gb = mia::Medium::create("Game Boy"); string tmpPath; - if(gb->load(Emulator::load(gb, tmpPath))) { + if(gb->load(Emulator::load(gb, tmpPath)) == LoadResult(successful)) { slot->allocate(); slot->connect(); transferPakConnected = true; @@ -165,7 +177,7 @@ auto Nintendo64::load() -> bool { diskInsertTimer = Timer{}; - return true; + return LoadResult(successful); } auto Nintendo64::load(Menu menu) -> void { @@ -177,7 +189,7 @@ auto Nintendo64::load(Menu menu) -> void { auto drive = root->find("Nintendo 64DD/Disk Drive"); drive->disconnect(); - if(!disk->load(Emulator::load(disk, configuration.game))) { + if(disk->load(Emulator::load(disk, configuration.game)) != LoadResult(successful)) { return; } @@ -278,7 +290,7 @@ auto Nintendo64::portMenu(Menu& portMenu, ares::Node::Port port) -> void { if(auto slot = transferPak->find("Cartridge Slot")) { emulator->gb = mia::Medium::create("Game Boy"); string tmpPath; - if(emulator->gb->load(emulator->load(emulator->gb, tmpPath))) { + if(emulator->gb->load(emulator->load(emulator->gb, tmpPath)) == LoadResult(successful)) { slot->allocate(); slot->connect(); } else { diff --git a/desktop-ui/emulator/nintendo-64dd.cpp b/desktop-ui/emulator/nintendo-64dd.cpp index 8711716625..8397221946 100644 --- a/desktop-ui/emulator/nintendo-64dd.cpp +++ b/desktop-ui/emulator/nintendo-64dd.cpp @@ -1,6 +1,6 @@ struct Nintendo64DD : Nintendo64 { Nintendo64DD(); - auto load() -> bool override; + auto load() -> LoadResult override; auto load(Menu) -> void override; auto unload() -> void override; auto save() -> bool override; @@ -56,9 +56,12 @@ Nintendo64DD::Nintendo64DD() { } } -auto Nintendo64DD::load() -> bool { +auto Nintendo64DD::load() -> LoadResult { game = mia::Medium::create("Nintendo 64DD"); - if(!game->load(Emulator::load(game, configuration.game))) return false; + string location = Emulator::load(game, configuration.game); + if(!location) return LoadResult(noFileSelected); + LoadResult result = game->load(location); + if(result != LoadResult(successful)) return result; auto region = game->pak->attribute("region"); //if statements below are ordered by lowest to highest priority @@ -67,7 +70,14 @@ auto Nintendo64DD::load() -> bool { if (region == "NTSC-J" ) regionID = 0; system = mia::System::create("Nintendo 64DD"); - if(!system->load(firmware[regionID].location)) return errorFirmware(firmware[regionID]), false; + result = system->load(firmware[regionID].location); + if(result != LoadResult(successful)) { + result.firmwareSystemName = "Nintendo 64DD"; + result.firmwareType = firmware[regionID].type; + result.firmwareRegion = firmware[regionID].region; + result.result = noFirmware; + return result; + } ares::Nintendo64::option("Quality", settings.video.quality); ares::Nintendo64::option("Supersampling", settings.video.supersampling); @@ -82,7 +92,7 @@ auto Nintendo64DD::load() -> bool { ares::Nintendo64::option("Recompiler", !settings.general.forceInterpreter); ares::Nintendo64::option("Expansion Pak", settings.nintendo64.expansionPak); - if(!ares::Nintendo64::load(root, {"[Nintendo] Nintendo 64DD (", region, ")"})) return false; + if(!ares::Nintendo64::load(root, {"[Nintendo] Nintendo 64DD (", region, ")"})) return LoadResult(otherError); if(auto port = root->find("Nintendo 64DD/Disk Drive")) { port->allocate(); @@ -104,7 +114,7 @@ auto Nintendo64DD::load() -> bool { if(auto slot = transferPak->find("Cartridge Slot")) { gb = mia::Medium::create("Game Boy"); string tmpPath; - if(gb->load(Emulator::load(gb, tmpPath))) { + if(gb->load(Emulator::load(gb, tmpPath)) == LoadResult(successful)) { slot->allocate(); slot->connect(); transferPakConnected = true; @@ -134,7 +144,7 @@ auto Nintendo64DD::load() -> bool { diskInsertTimer = Timer{}; - return true; + return LoadResult(successful); } auto Nintendo64DD::load(Menu menu) -> void { @@ -145,7 +155,7 @@ auto Nintendo64DD::load(Menu menu) -> void { auto drive = root->find("Nintendo 64DD/Disk Drive"); drive->disconnect(); - if(!game->load(Emulator::load(game, configuration.game))) { + if(game->load(Emulator::load(game, configuration.game)) != LoadResult(successful)) { return; } diff --git a/desktop-ui/emulator/pc-engine-cd.cpp b/desktop-ui/emulator/pc-engine-cd.cpp index fbc069d05f..cde01d4525 100644 --- a/desktop-ui/emulator/pc-engine-cd.cpp +++ b/desktop-ui/emulator/pc-engine-cd.cpp @@ -1,6 +1,6 @@ struct PCEngineCD : PCEngine { PCEngineCD(); - auto load() -> bool override; + auto load() -> LoadResult override; auto save() -> bool override; auto pak(ares::Node::Object) -> shared_pointer override; @@ -20,9 +20,12 @@ PCEngineCD::PCEngineCD() { allocatePorts(); } -auto PCEngineCD::load() -> bool { +auto PCEngineCD::load() -> LoadResult { game = mia::Medium::create("PC Engine CD"); - if(!game->load(Emulator::load(game, configuration.game))) return false; + string location = Emulator::load(game, configuration.game); + if(!location) return LoadResult(noFileSelected); + LoadResult result = game->load(location); + if(result != LoadResult(successful)) return result; auto region = Emulator::region(); //if statements below are ordered by lowest to highest priority @@ -39,15 +42,23 @@ auto PCEngineCD::load() -> bool { } bios = mia::Medium::create("PC Engine"); - if(!bios->load(firmware[biosID].location)) return errorFirmware(firmware[biosID]), false; + result = bios->load(firmware[biosID].location); + if(result != LoadResult(successful)) { + result.firmwareSystemName = "PC Engine"; + result.firmwareType = firmware[biosID].type; + result.firmwareRegion = firmware[biosID].region; + result.result = noFirmware; + return result; + } system = mia::System::create("PC Engine"); - if(!system->load()) return false; + result = system->load(); + if(result != LoadResult(successful)) return result; ares::PCEngine::option("Pixel Accuracy", settings.video.pixelAccuracy); auto name = region == "NTSC-J" ? "PC Engine Duo" : "TurboDuo"; - if(!ares::PCEngine::load(root, {"[NEC] ", name, " (", region, ")"})) return false; + if(!ares::PCEngine::load(root, {"[NEC] ", name, " (", region, ")"})) return LoadResult(otherError); if(auto port = root->find("Cartridge Slot")) { port->allocate(); @@ -61,7 +72,7 @@ auto PCEngineCD::load() -> bool { connectPorts(); - return true; + return LoadResult(successful); } auto PCEngineCD::save() -> bool { diff --git a/desktop-ui/emulator/pc-engine.cpp b/desktop-ui/emulator/pc-engine.cpp index cb4deb46aa..bb5fbca997 100644 --- a/desktop-ui/emulator/pc-engine.cpp +++ b/desktop-ui/emulator/pc-engine.cpp @@ -1,6 +1,6 @@ struct PCEngine : Emulator { PCEngine(); - auto load() -> bool override; + auto load() -> LoadResult override; auto save() -> bool override; auto pak(ares::Node::Object) -> shared_pointer override; auto allocatePorts() -> void; @@ -87,18 +87,22 @@ auto PCEngine::connectPorts() -> void { } } -auto PCEngine::load() -> bool { +auto PCEngine::load() -> LoadResult { game = mia::Medium::create("PC Engine"); - if(!game->load(Emulator::load(game, configuration.game))) return false; + string location = Emulator::load(game, configuration.game); + if(!location) return LoadResult(noFileSelected); + LoadResult result = game->load(location); + if(result != LoadResult(successful)) return result; system = mia::System::create("PC Engine"); - if(!system->load()) return false; + result = system->load(); + if(result != LoadResult(successful)) return result; ares::PCEngine::option("Pixel Accuracy", settings.video.pixelAccuracy); auto region = Emulator::region(); string name = region == "NTSC-J" ? "PC Engine" : "TurboGrafx 16"; - if(!ares::PCEngine::load(root, {"[NEC] ", name, " (", region, ")"})) return false; + if(!ares::PCEngine::load(root, {"[NEC] ", name, " (", region, ")"})) return LoadResult(otherError); if(auto port = root->find("Cartridge Slot")) { port->allocate(); @@ -107,7 +111,7 @@ auto PCEngine::load() -> bool { connectPorts(); - return true; + return LoadResult(successful); } auto PCEngine::save() -> bool { diff --git a/desktop-ui/emulator/playstation.cpp b/desktop-ui/emulator/playstation.cpp index 01e8756ca4..0baa569fbc 100644 --- a/desktop-ui/emulator/playstation.cpp +++ b/desktop-ui/emulator/playstation.cpp @@ -1,6 +1,6 @@ struct PlayStation : Emulator { PlayStation(); - auto load() -> bool override; + auto load() -> LoadResult override; auto load(Menu) -> void override; auto unload() -> void override; auto save() -> bool override; @@ -75,9 +75,12 @@ PlayStation::PlayStation() { } } -auto PlayStation::load() -> bool { +auto PlayStation::load() -> LoadResult { game = mia::Medium::create("PlayStation"); - if(!game->load(Emulator::load(game, configuration.game))) return false; + string location = Emulator::load(game, configuration.game); + if(!location) return LoadResult(noFileSelected); + LoadResult result = game->load(location); + if(result != LoadResult(successful)) return result; auto region = Emulator::region(); //if statements below are ordered by lowest to highest priority @@ -86,11 +89,18 @@ auto PlayStation::load() -> bool { if(region == "NTSC-U") regionID = 0; system = mia::System::create("PlayStation"); - if(!system->load(firmware[regionID].location)) return errorFirmware(firmware[regionID]), false; + result = system->load(firmware[regionID].location); + if(result != LoadResult(successful)) { + result.firmwareSystemName = "PlayStation"; + result.firmwareType = firmware[regionID].type; + result.firmwareRegion = firmware[regionID].region; + result.result = noFirmware; + return result; + } ares::PlayStation::option("Recompiler", !settings.general.forceInterpreter); - if(!ares::PlayStation::load(root, {"[Sony] PlayStation (", region, ")"})) return false; + if(!ares::PlayStation::load(root, {"[Sony] PlayStation (", region, ")"})) return LoadResult(otherError); if(auto fastBoot = root->find("Fast Boot")) { fastBoot->setValue(settings.boot.fast); @@ -121,7 +131,7 @@ auto PlayStation::load() -> bool { discTrayTimer = Timer{}; - return true; + return LoadResult(successful); } auto PlayStation::load(Menu menu) -> void { @@ -132,7 +142,7 @@ auto PlayStation::load(Menu menu) -> void { auto tray = root->find("PlayStation/Disc Tray"); tray->disconnect(); - if(!game->load(Emulator::load(game, configuration.game))) { + if(game->load(Emulator::load(game, configuration.game)) != LoadResult(successful)) { return; } diff --git a/desktop-ui/emulator/pocket-challenge-v2.cpp b/desktop-ui/emulator/pocket-challenge-v2.cpp index 66f1be2f18..d378da136f 100644 --- a/desktop-ui/emulator/pocket-challenge-v2.cpp +++ b/desktop-ui/emulator/pocket-challenge-v2.cpp @@ -1,7 +1,7 @@ struct PocketChallengeV2 : Emulator { PocketChallengeV2(); auto load(Menu) -> void override; - auto load() -> bool override; + auto load() -> LoadResult override; auto save() -> bool override; auto pak(ares::Node::Object) -> shared_pointer override; }; @@ -34,23 +34,27 @@ auto PocketChallengeV2::load(Menu menu) -> void { //as such, neither the ares::WonderSwan core nor desktop-ui provide an orientation setting. } -auto PocketChallengeV2::load() -> bool { +auto PocketChallengeV2::load() -> LoadResult { game = mia::Medium::create("Pocket Challenge V2"); - if(!game->load(Emulator::load(game, configuration.game))) return false; + string location = Emulator::load(game, configuration.game); + if(!location) return LoadResult(noFileSelected); + LoadResult result = game->load(location); + if(result != LoadResult(successful)) return result; system = mia::System::create("Pocket Challenge V2"); - if(!system->load()) return false; + result = system->load(); + if(result != LoadResult(successful)) return result; ares::WonderSwan::option("Pixel Accuracy", settings.video.pixelAccuracy); - if(!ares::WonderSwan::load(root, "[Benesse] Pocket Challenge V2")) return false; + if(!ares::WonderSwan::load(root, "[Benesse] Pocket Challenge V2")) return LoadResult(otherError); if(auto port = root->find("Cartridge Slot")) { port->allocate(); port->connect(); } - return true; + return LoadResult(successful); } auto PocketChallengeV2::save() -> bool { diff --git a/desktop-ui/emulator/saturn.cpp b/desktop-ui/emulator/saturn.cpp index 53e6d8bf8e..ec23032ed1 100644 --- a/desktop-ui/emulator/saturn.cpp +++ b/desktop-ui/emulator/saturn.cpp @@ -1,6 +1,6 @@ struct Saturn : Emulator { Saturn(); - auto load() -> bool override; + auto load() -> LoadResult override; auto save() -> bool override; auto pak(ares::Node::Object) -> shared_pointer override; @@ -16,9 +16,12 @@ Saturn::Saturn() { firmware.append({"BIOS", "Europe"}); //PAL } -auto Saturn::load() -> bool { +auto Saturn::load() -> LoadResult { game = mia::Medium::create("Saturn"); - if(!game->load(Emulator::load(game, configuration.game))) return false; + string location = Emulator::load(game, configuration.game); + if(!location) return LoadResult(noFileSelected); + LoadResult result = game->load(location); + if(result != LoadResult(successful)) return result; auto region = Emulator::region(); //if statements below are ordered by lowest to highest priority @@ -27,9 +30,16 @@ auto Saturn::load() -> bool { if(region == "NTSC-U") regionID = 0; system = mia::System::create("Saturn"); - if(!system->load(firmware[regionID].location)) return errorFirmware(firmware[regionID]), false; + result = system->load(firmware[regionID].location); + if(result != LoadResult(successful)) { + result.firmwareSystemName = "Saturn"; + result.firmwareType = firmware[regionID].type; + result.firmwareRegion = firmware[regionID].region; + result.result = noFirmware; + return result; + } - if(!ares::Saturn::load(root, {"[Sega] Saturn (", region, ")"})) return false; + if(!ares::Saturn::load(root, {"[Sega] Saturn (", region, ")"})) return LoadResult(otherError); if(auto port = root->find("Saturn/Disc Tray")) { port->allocate(); diff --git a/desktop-ui/emulator/sg-1000.cpp b/desktop-ui/emulator/sg-1000.cpp index 3b85846492..64e900566b 100644 --- a/desktop-ui/emulator/sg-1000.cpp +++ b/desktop-ui/emulator/sg-1000.cpp @@ -1,6 +1,6 @@ struct SG1000 : Emulator { SG1000(); - auto load() -> bool override; + auto load() -> LoadResult override; auto save() -> bool override; auto pak(ares::Node::Object) -> shared_pointer override; }; @@ -25,15 +25,19 @@ SG1000::SG1000() { } } -auto SG1000::load() -> bool { +auto SG1000::load() -> LoadResult { game = mia::Medium::create("SG-1000"); - if(!game->load(Emulator::load(game, configuration.game))) return false; + string location = Emulator::load(game, configuration.game); + if(!location) return LoadResult(noFileSelected); + LoadResult result = game->load(location); + if(result != LoadResult(successful)) return result; system = mia::System::create("SG-1000"); - if(!system->load()) return false; + result = system->load(); + if(result != LoadResult(successful)) return result; auto region = Emulator::region(); - if(!ares::SG1000::load(root, {"[Sega] SG-1000 (", region, ")"})) return false; + if(!ares::SG1000::load(root, {"[Sega] SG-1000 (", region, ")"})) return LoadResult(otherError); if(auto port = root->find("Cartridge Slot")) { port->allocate(); @@ -50,7 +54,7 @@ auto SG1000::load() -> bool { port->connect(); } - return true; + return LoadResult(successful); } auto SG1000::save() -> bool { diff --git a/desktop-ui/emulator/super-famicom.cpp b/desktop-ui/emulator/super-famicom.cpp index acedd99bb4..71c9e83c20 100644 --- a/desktop-ui/emulator/super-famicom.cpp +++ b/desktop-ui/emulator/super-famicom.cpp @@ -1,6 +1,6 @@ struct SuperFamicom : Emulator { SuperFamicom(); - auto load() -> bool override; + auto load() -> LoadResult override; auto save() -> bool override; auto pak(ares::Node::Object) -> shared_pointer override; @@ -93,17 +93,21 @@ SuperFamicom::SuperFamicom() { inputBlacklist = {"Justifiers", "Super Multitap"}; } -auto SuperFamicom::load() -> bool { +auto SuperFamicom::load() -> LoadResult { game = mia::Medium::create("Super Famicom"); - if(!game->load(Emulator::load(game, configuration.game))) return false; + string location = Emulator::load(game, configuration.game); + if(!location) return LoadResult(noFileSelected); + LoadResult result = game->load(location); + if(result != LoadResult(successful)) return result; system = mia::System::create("Super Famicom"); - if(!system->load()) return false; + result = system->load(); + if(result != LoadResult(successful)) return result; ares::SuperFamicom::option("Pixel Accuracy", settings.video.pixelAccuracy); auto region = Emulator::region(); - if(!ares::SuperFamicom::load(root, {"[Nintendo] Super Famicom (", region, ")"})) return false; + if(!ares::SuperFamicom::load(root, {"[Nintendo] Super Famicom (", region, ")"})) return LoadResult(otherError); if(auto port = root->find("Cartridge Slot")) { auto cartridge = port->allocate(); @@ -111,7 +115,7 @@ auto SuperFamicom::load() -> bool { if(auto slot = cartridge->find("Super Game Boy/Cartridge Slot")) { gb = mia::Medium::create("Game Boy"); - if(gb->load(Emulator::load(gb, settings.paths.superFamicom.gameBoy))) { + if(gb->load(Emulator::load(gb, settings.paths.superFamicom.gameBoy)) != LoadResult(successful)) { slot->allocate(); slot->connect(); } else { @@ -121,7 +125,7 @@ auto SuperFamicom::load() -> bool { if(auto slot = cartridge->find("BS Memory Slot")) { bs = mia::Medium::create("BS Memory"); - if(bs->load(Emulator::load(bs, settings.paths.superFamicom.bsMemory))) { + if(bs->load(Emulator::load(bs, settings.paths.superFamicom.bsMemory)) != LoadResult(successful)) { slot->allocate(); slot->connect(); } else { @@ -131,7 +135,7 @@ auto SuperFamicom::load() -> bool { if(auto slot = cartridge->find("Sufami Turbo Slot A")) { stA = mia::Medium::create("Sufami Turbo"); - if(stA->load(Emulator::load(stA, settings.paths.superFamicom.sufamiTurbo))) { + if(stA->load(Emulator::load(stA, settings.paths.superFamicom.sufamiTurbo)) != LoadResult(successful)) { slot->allocate(); slot->connect(); } else { @@ -141,7 +145,7 @@ auto SuperFamicom::load() -> bool { if(auto slot = cartridge->find("Sufami Turbo Slot B")) { stB = mia::Medium::create("Sufami Turbo"); - if(stB->load(Emulator::load(stB, settings.paths.superFamicom.sufamiTurbo))) { + if(stB->load(Emulator::load(stB, settings.paths.superFamicom.sufamiTurbo)) != LoadResult(successful)) { slot->allocate(); slot->connect(); } else { @@ -160,7 +164,7 @@ auto SuperFamicom::load() -> bool { port->connect(); } - return true; + return LoadResult(successful); } auto SuperFamicom::save() -> bool { diff --git a/desktop-ui/emulator/supergrafx-cd.cpp b/desktop-ui/emulator/supergrafx-cd.cpp index 53c5f7df0d..8053571a18 100644 --- a/desktop-ui/emulator/supergrafx-cd.cpp +++ b/desktop-ui/emulator/supergrafx-cd.cpp @@ -1,6 +1,6 @@ struct SuperGrafxCD : PCEngine { SuperGrafxCD(); - auto load() -> bool override; + auto load() -> LoadResult override; auto save() -> bool override; auto pak(ares::Node::Object) -> shared_pointer override; @@ -17,19 +17,30 @@ SuperGrafxCD::SuperGrafxCD() { allocatePorts(); } -auto SuperGrafxCD::load() -> bool { +auto SuperGrafxCD::load() -> LoadResult { game = mia::Medium::create("PC Engine CD"); - if(!game->load(Emulator::load(game, configuration.game))) return false; + string location = Emulator::load(game, configuration.game); + if(!location) return LoadResult(noFileSelected); + LoadResult result = game->load(location); + if(result != LoadResult(successful)) return result; bios = mia::Medium::create("PC Engine"); - if(!bios->load(firmware[0].location)) return errorFirmware(firmware[0]), false; + result = bios->load(firmware[0].location); + if(result != LoadResult(successful)) { + result.firmwareSystemName = "SuperGrafx CD"; + result.firmwareType = firmware[0].type; + result.firmwareRegion = firmware[0].region; + result.result = noFirmware; + return result; + } system = mia::System::create("SuperGrafx"); - if(!system->load()) return false; + result = system->load(); + if(result != LoadResult(successful)) return result; ares::PCEngine::option("Pixel Accuracy", settings.video.pixelAccuracy); - if(!ares::PCEngine::load(root, "[NEC] SuperGrafx (NTSC-J)")) return false; + if(!ares::PCEngine::load(root, "[NEC] SuperGrafx (NTSC-J)")) return LoadResult(otherError); if(auto port = root->find("Cartridge Slot")) { port->allocate(); @@ -43,7 +54,7 @@ auto SuperGrafxCD::load() -> bool { connectPorts(); - return true; + return LoadResult(successful); } auto SuperGrafxCD::save() -> bool { diff --git a/desktop-ui/emulator/supergrafx.cpp b/desktop-ui/emulator/supergrafx.cpp index 41d8921fa1..8288fb1b8a 100644 --- a/desktop-ui/emulator/supergrafx.cpp +++ b/desktop-ui/emulator/supergrafx.cpp @@ -1,6 +1,6 @@ struct SuperGrafx : PCEngine { SuperGrafx(); - auto load() -> bool override; + auto load() -> LoadResult override; auto save() -> bool override; auto pak(ares::Node::Object) -> shared_pointer override; }; @@ -12,16 +12,20 @@ SuperGrafx::SuperGrafx() { allocatePorts(); } -auto SuperGrafx::load() -> bool { +auto SuperGrafx::load() -> LoadResult { game = mia::Medium::create("SuperGrafx"); - if(!game->load(Emulator::load(game, configuration.game))) return false; + string location = Emulator::load(game, configuration.game); + if(!location) return LoadResult(noFileSelected); + LoadResult result = game->load(location); + if(result != LoadResult(successful)) return result; system = mia::System::create("SuperGrafx"); - if(!system->load()) return false; + result = system->load(); + if(result != LoadResult(successful)) return result; ares::PCEngine::option("Pixel Accuracy", settings.video.pixelAccuracy); - if(!ares::PCEngine::load(root, "[NEC] SuperGrafx (NTSC-J)")) return false; + if(!ares::PCEngine::load(root, "[NEC] SuperGrafx (NTSC-J)")) return LoadResult(otherError); if(auto port = root->find("Cartridge Slot")) { port->allocate(); @@ -30,7 +34,7 @@ auto SuperGrafx::load() -> bool { connectPorts(); - return true; + return LoadResult(successful); } auto SuperGrafx::save() -> bool { diff --git a/desktop-ui/emulator/wonderswan-color.cpp b/desktop-ui/emulator/wonderswan-color.cpp index c22bf176fb..e1caf8acef 100644 --- a/desktop-ui/emulator/wonderswan-color.cpp +++ b/desktop-ui/emulator/wonderswan-color.cpp @@ -1,7 +1,7 @@ struct WonderSwanColor : Emulator { WonderSwanColor(); auto load(Menu) -> void override; - auto load() -> bool override; + auto load() -> LoadResult override; auto save() -> bool override; auto pak(ares::Node::Object) -> shared_pointer override; }; @@ -57,23 +57,27 @@ auto WonderSwanColor::load(Menu menu) -> void { } } -auto WonderSwanColor::load() -> bool { +auto WonderSwanColor::load() -> LoadResult { game = mia::Medium::create("WonderSwan Color"); - if(!game->load(Emulator::load(game, configuration.game))) return false; + string location = Emulator::load(game, configuration.game); + if(!location) return LoadResult(noFileSelected); + LoadResult result = game->load(location); + if(result != LoadResult(successful)) return result; system = mia::System::create("WonderSwan Color"); - if(!system->load()) return false; + result = system->load(); + if(result != LoadResult(successful)) return result; ares::WonderSwan::option("Pixel Accuracy", settings.video.pixelAccuracy); - if(!ares::WonderSwan::load(root, "[Bandai] WonderSwan Color")) return false; + if(!ares::WonderSwan::load(root, "[Bandai] WonderSwan Color")) return LoadResult(otherError); if(auto port = root->find("Cartridge Slot")) { port->allocate(); port->connect(); } - return true; + return LoadResult(successful); } auto WonderSwanColor::save() -> bool { diff --git a/desktop-ui/emulator/wonderswan.cpp b/desktop-ui/emulator/wonderswan.cpp index f1159f00b0..7eaa915174 100644 --- a/desktop-ui/emulator/wonderswan.cpp +++ b/desktop-ui/emulator/wonderswan.cpp @@ -1,7 +1,7 @@ struct WonderSwan : Emulator { WonderSwan(); auto load(Menu) -> void override; - auto load() -> bool override; + auto load() -> LoadResult override; auto save() -> bool override; auto pak(ares::Node::Object) -> shared_pointer override; }; @@ -57,23 +57,27 @@ auto WonderSwan::load(Menu menu) -> void { } } -auto WonderSwan::load() -> bool { +auto WonderSwan::load() -> LoadResult { game = mia::Medium::create("WonderSwan"); - if(!game->load(Emulator::load(game, configuration.game))) return false; + string location = Emulator::load(game, configuration.game); + if(!location) return LoadResult(noFileSelected); + LoadResult result = game->load(location); + if(result != LoadResult(successful)) return result; system = mia::System::create("WonderSwan"); - if(!system->load()) return false; + result = system->load(); + if(result != LoadResult(successful)) return result; ares::WonderSwan::option("Pixel Accuracy", settings.video.pixelAccuracy); - if(!ares::WonderSwan::load(root, "[Bandai] WonderSwan")) return false; + if(!ares::WonderSwan::load(root, "[Bandai] WonderSwan")) return LoadResult(otherError); if(auto port = root->find("Cartridge Slot")) { port->allocate(); port->connect(); } - return true; + return LoadResult(successful); } auto WonderSwan::save() -> bool { diff --git a/desktop-ui/emulator/zx-spectrum-128.cpp b/desktop-ui/emulator/zx-spectrum-128.cpp index 1cba4d36ef..436460474e 100644 --- a/desktop-ui/emulator/zx-spectrum-128.cpp +++ b/desktop-ui/emulator/zx-spectrum-128.cpp @@ -1,6 +1,6 @@ struct ZXSpectrum128 : ZXSpectrum { ZXSpectrum128(); - auto load() -> bool override; + auto load() -> LoadResult override; auto pak(ares::Node::Object) -> shared_pointer override; }; @@ -9,14 +9,18 @@ ZXSpectrum128::ZXSpectrum128() { name = "ZX Spectrum 128"; } -auto ZXSpectrum128::load() -> bool { +auto ZXSpectrum128::load() -> LoadResult { game = mia::Medium::create("ZX Spectrum"); - if(!game->load(Emulator::load(game, configuration.game))) return false; + string location = Emulator::load(game, configuration.game); + if(!location) return LoadResult(noFileSelected); + LoadResult result = game->load(location); + if(result != LoadResult(successful)) return result; system = mia::System::create("ZX Spectrum 128"); - if(!system->load()) return false; + result = system->load(); + if(result != LoadResult(successful)) return result; - if(!ares::ZXSpectrum::load(root, "[Sinclair] ZX Spectrum 128")) return false; + if(!ares::ZXSpectrum::load(root, "[Sinclair] ZX Spectrum 128")) return LoadResult(otherError); if(auto port = root->find("Tape Deck/Tray")) { port->allocate(); @@ -28,7 +32,7 @@ auto ZXSpectrum128::load() -> bool { port->connect(); } - return true; + return LoadResult(successful); } auto ZXSpectrum128::pak(ares::Node::Object node) -> shared_pointer { diff --git a/desktop-ui/emulator/zx-spectrum.cpp b/desktop-ui/emulator/zx-spectrum.cpp index e678ab58d2..6ca0c749cf 100644 --- a/desktop-ui/emulator/zx-spectrum.cpp +++ b/desktop-ui/emulator/zx-spectrum.cpp @@ -1,6 +1,6 @@ struct ZXSpectrum : Emulator { ZXSpectrum(); - auto load() -> bool override; + auto load() -> LoadResult override; auto load(Menu) -> void override; auto save() -> bool override; auto pak(ares::Node::Object) -> shared_pointer override; @@ -12,14 +12,18 @@ ZXSpectrum::ZXSpectrum() { name = "ZX Spectrum"; } -auto ZXSpectrum::load() -> bool { +auto ZXSpectrum::load() -> LoadResult { game = mia::Medium::create("ZX Spectrum"); - if(!game->load(Emulator::load(game, configuration.game))) return false; + string location = Emulator::load(game, configuration.game); + if(!location) return LoadResult(noFileSelected); + LoadResult result = game->load(location); + if(result != LoadResult(successful)) return result; system = mia::System::create("ZX Spectrum"); - if(!system->load()) return false; + result = system->load(); + if(result != LoadResult(successful)) return result; - if(!ares::ZXSpectrum::load(root, "[Sinclair] ZX Spectrum")) return false; + if(!ares::ZXSpectrum::load(root, "[Sinclair] ZX Spectrum")) return LoadResult(otherError); if(auto port = root->find("Tape Deck/Tray")) { port->allocate(); @@ -31,7 +35,7 @@ auto ZXSpectrum::load() -> bool { port->connect(); } - return true; + return LoadResult(successful); } auto ZXSpectrum::load(Menu menu) -> void { diff --git a/mia/CMakeLists.txt b/mia/CMakeLists.txt index 85e0fc03ae..041fca48c9 100644 --- a/mia/CMakeLists.txt +++ b/mia/CMakeLists.txt @@ -1,4 +1,4 @@ -add_library(mia STATIC mia.cpp resource/resource.cpp) +add_library(mia STATIC mia.cpp mia.hpp resource/resource.cpp) add_library(ares::mia ALIAS mia) target_sources( diff --git a/mia/medium/arcade.cpp b/mia/medium/arcade.cpp index f57770847e..636f624cf2 100644 --- a/mia/medium/arcade.cpp +++ b/mia/medium/arcade.cpp @@ -1,23 +1,23 @@ struct Arcade : Mame { auto name() -> string override { return "Arcade"; } auto extensions() -> vector override { return {}; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; }; -auto Arcade::load(string location) -> bool { +auto Arcade::load(string location) -> LoadResult { auto foundDatabase = Medium::loadDatabase(); - if(!foundDatabase) return false; + if(!foundDatabase) return LoadResult(databaseNotFound); manifest = manifestDatabaseArcade(Medium::name(location)); - if(!manifest) return false; + if(!manifest) return LoadResult(romNotFoundInDatabase); auto document = BML::unserialize(manifest); - if(!document) return false; + if(!document) return LoadResult(couldNotParseManifest); //Sega SG-1000 based arcade if(document["game/board"].string() == "sega/sg1000a") { vector rom = loadRoms(location, document, "maincpu"); - if(!rom) return false; + if(!rom) return romNotFound; this->location = location; @@ -28,10 +28,10 @@ auto Arcade::load(string location) -> bool { pak->append("manifest.bml", manifest); pak->append("program.rom", rom); - return true; + return LoadResult(successful); } - return false; + return LoadResult(otherError); } auto Arcade::save(string location) -> bool { diff --git a/mia/medium/atari-2600.cpp b/mia/medium/atari-2600.cpp index 04a97ff1db..3193753f03 100644 --- a/mia/medium/atari-2600.cpp +++ b/mia/medium/atari-2600.cpp @@ -1,28 +1,28 @@ struct Atari2600 : Cartridge { auto name() -> string override { return "Atari 2600"; } auto extensions() -> vector override { return {"a26", "bin"}; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; auto analyze(vector& rom, string location) -> string; auto match(vector& rom, vector pattern, u8 target_matches = 1) -> bool; }; -auto Atari2600::load(string location) -> bool { +auto Atari2600::load(string location) -> LoadResult { vector rom; if(directory::exists(location)) { append(rom, {location, "program.rom"}); } else if(file::exists(location)) { rom = Cartridge::read(location); } - if(!rom) return false; + if(!rom) return LoadResult(romNotFound); this->sha256 = Hash::SHA256(rom).digest(); this->location = location; this->manifest = Medium::manifestDatabase(sha256); if(!manifest) manifest = analyze(rom, location); auto document = BML::unserialize(manifest); - if(!document) return false; + if(!document) return LoadResult(couldNotParseManifest); pak = new vfs::directory; pak->setAttribute("title", document["game/title"].string()); @@ -31,7 +31,7 @@ auto Atari2600::load(string location) -> bool { pak->append("manifest.bml", manifest); pak->append("program.rom", rom); - return true; + return LoadResult(successful); } auto Atari2600::save(string location) -> bool { diff --git a/mia/medium/bs-memory.cpp b/mia/medium/bs-memory.cpp index bb4c74083e..ba2bdf70fb 100644 --- a/mia/medium/bs-memory.cpp +++ b/mia/medium/bs-memory.cpp @@ -1,12 +1,12 @@ struct BSMemory : Cartridge { auto name() -> string override { return "BS Memory"; } auto extensions() -> vector override { return {"bs"}; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; auto analyze(vector& rom) -> string; }; -auto BSMemory::load(string location) -> bool { +auto BSMemory::load(string location) -> LoadResult { vector rom; if(directory::exists(location)) { append(rom, {location, "program.rom"}); @@ -14,16 +14,16 @@ auto BSMemory::load(string location) -> bool { } else if(file::exists(location)) { rom = Cartridge::read(location); } - if(!rom) return false; + if(!rom) return LoadResult(romNotFound); this->sha256 = Hash::SHA256(rom).digest(); this->location = location; auto foundDatabase = Medium::loadDatabase(); - if(!foundDatabase) return false; + if(!foundDatabase) return LoadResult(databaseNotFound); this->manifest = Medium::manifestDatabase(sha256); if(!manifest) manifest = analyze(rom); auto document = BML::unserialize(manifest); - if(!document) return false; + if(!document) return LoadResult(couldNotParseManifest); pak = new vfs::directory; pak->setAttribute("title", document["game/title"].string()); @@ -36,7 +36,7 @@ auto BSMemory::load(string location) -> bool { Pak::load("program.flash", ".sav"); } - return true; + return LoadResult(successful); } auto BSMemory::save(string location) -> bool { diff --git a/mia/medium/colecovision.cpp b/mia/medium/colecovision.cpp index 9f08252581..7337f84827 100644 --- a/mia/medium/colecovision.cpp +++ b/mia/medium/colecovision.cpp @@ -1,24 +1,24 @@ struct ColecoVision : Cartridge { auto name() -> string override { return "ColecoVision"; } auto extensions() -> vector override { return {"cv", "col"}; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; auto analyze(vector& rom) -> string; }; -auto ColecoVision::load(string location) -> bool { +auto ColecoVision::load(string location) -> LoadResult { vector rom; if(directory::exists(location)) { append(rom, {location, "program.rom"}); } else if(file::exists(location)) { rom = Cartridge::read(location); } - if(!rom) return false; + if(!rom) return LoadResult(romNotFound); this->location = location; this->manifest = analyze(rom); auto document = BML::unserialize(manifest); - if(!document) return false; + if(!document) return LoadResult(couldNotParseManifest); pak = new vfs::directory; pak->setAttribute("board", document["game/board" ].string()); @@ -27,7 +27,7 @@ auto ColecoVision::load(string location) -> bool { pak->append("manifest.bml", manifest); pak->append("program.rom", rom); - return true; + return LoadResult(successful); } auto ColecoVision::save(string location) -> bool { diff --git a/mia/medium/famicom-disk-system.cpp b/mia/medium/famicom-disk-system.cpp index 35ffe94396..fe343cd0d8 100644 --- a/mia/medium/famicom-disk-system.cpp +++ b/mia/medium/famicom-disk-system.cpp @@ -1,13 +1,13 @@ struct FamicomDiskSystem : FloppyDisk { auto name() -> string override { return "Famicom Disk System"; } auto extensions() -> vector override { return {"fds"}; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; auto analyze() -> string; auto transform(array_view input) -> vector; }; -auto FamicomDiskSystem::load(string location) -> bool { +auto FamicomDiskSystem::load(string location) -> LoadResult { if(directory::exists(location)) { this->location = location; this->manifest = analyze(); @@ -42,14 +42,14 @@ auto FamicomDiskSystem::load(string location) -> bool { } } - if(!pak) return false; + if(!pak) return LoadResult(romNotFound); Pak::load("disk1.sideA", ".d1a"); Pak::load("disk1.sideB", ".d1b"); Pak::load("disk2.sideA", ".d2a"); Pak::load("disk2.sideB", ".d2b"); - return true; + return LoadResult(successful); } auto FamicomDiskSystem::save(string location) -> bool { diff --git a/mia/medium/famicom.cpp b/mia/medium/famicom.cpp index 5210c955a6..8586c46271 100644 --- a/mia/medium/famicom.cpp +++ b/mia/medium/famicom.cpp @@ -1,7 +1,7 @@ struct Famicom : Cartridge { auto name() -> string override { return "Famicom"; } auto extensions() -> vector override { return {"fc", "nes", "unf", "unif", "unh"}; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; auto analyze(vector& data) -> string; auto analyzeFDS(vector& data) -> string; @@ -9,7 +9,7 @@ struct Famicom : Cartridge { auto analyzeUNIF(vector& data) -> string; }; -auto Famicom::load(string location) -> bool { +auto Famicom::load(string location) -> LoadResult { vector rom; if(directory::exists(location)) { append(rom, {location, "ines.rom"}); @@ -18,12 +18,12 @@ auto Famicom::load(string location) -> bool { } else if(file::exists(location)) { rom = Cartridge::read(location); } - if(!rom) return false; + if(!rom) return LoadResult(romNotFound); this->location = location; this->manifest = analyze(rom); auto document = BML::unserialize(manifest); - if(!document) return false; + if(!document) return LoadResult(couldNotParseManifest); pak = new vfs::directory; pak->setAttribute("title", document["game/title"].string()); @@ -70,7 +70,7 @@ auto Famicom::load(string location) -> bool { Medium::load(node, ".chr"); } - return true; + return LoadResult(successful); } auto Famicom::save(string location) -> bool { diff --git a/mia/medium/game-boy-advance.cpp b/mia/medium/game-boy-advance.cpp index 3d72b64985..a5307c54e1 100644 --- a/mia/medium/game-boy-advance.cpp +++ b/mia/medium/game-boy-advance.cpp @@ -1,25 +1,25 @@ struct GameBoyAdvance : Cartridge { auto name() -> string override { return "Game Boy Advance"; } auto extensions() -> vector override { return {"gba"}; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; auto analyze(vector& rom) -> string; }; -auto GameBoyAdvance::load(string location) -> bool { +auto GameBoyAdvance::load(string location) -> LoadResult { vector rom; if(directory::exists(location)) { append(rom, {location, "program.rom"}); } else if(file::exists(location)) { rom = Cartridge::read(location); } - if(!rom) return false; + if(!rom) return LoadResult(romNotFound); this->sha256 = Hash::SHA256(rom).digest(); this->location = location; this->manifest = analyze(rom); auto document = BML::unserialize(manifest); - if(!document) return false; + if(!document) return LoadResult(couldNotParseManifest); pak = new vfs::directory; pak->setAttribute("title", document["game/title"].string()); @@ -45,7 +45,7 @@ auto GameBoyAdvance::load(string location) -> bool { } pak->setAttribute("mirror", mirror); - return true; + return LoadResult(successful); } auto GameBoyAdvance::save(string location) -> bool { diff --git a/mia/medium/game-boy.cpp b/mia/medium/game-boy.cpp index ae724d7e20..7938ecbf21 100644 --- a/mia/medium/game-boy.cpp +++ b/mia/medium/game-boy.cpp @@ -1,24 +1,24 @@ struct GameBoy : Cartridge { auto name() -> string override { return "Game Boy"; } auto extensions() -> vector override { return {"gb"}; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; auto analyze(vector& rom) -> string; }; -auto GameBoy::load(string location) -> bool { +auto GameBoy::load(string location) -> LoadResult { vector rom; if(directory::exists(location)) { append(rom, {location, "program.rom"}); } else if(file::exists(location)) { rom = Cartridge::read(location); } - if(!rom) return false; + if(!rom) return LoadResult(romNotFound); this->location = location; this->manifest = analyze(rom); auto document = BML::unserialize(manifest); - if(!document) return false; + if(!document) return LoadResult(couldNotParseManifest); pak = new vfs::directory; pak->setAttribute("title", document["game/title"].string()); @@ -42,7 +42,7 @@ auto GameBoy::load(string location) -> bool { Medium::load(node, ".rtc"); } - return true; + return LoadResult(successful); } auto GameBoy::save(string location) -> bool { diff --git a/mia/medium/game-gear.cpp b/mia/medium/game-gear.cpp index 7f8ec4cb67..b287995424 100644 --- a/mia/medium/game-gear.cpp +++ b/mia/medium/game-gear.cpp @@ -1,25 +1,25 @@ struct GameGear : Cartridge { auto name() -> string override { return "Game Gear"; } auto extensions() -> vector override { return {"gg"}; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; auto analyze(vector& rom, string location) -> string; }; -auto GameGear::load(string location) -> bool { +auto GameGear::load(string location) -> LoadResult { vector rom; if(directory::exists(location)) { append(rom, {location, "program.rom"}); } else if(file::exists(location)) { rom = Cartridge::read(location); } else { - return false; + return LoadResult(romNotFound); } this->location = location; this->manifest = analyze(rom, location); auto document = BML::unserialize(manifest); - if(!document) return false; + if(!document) return LoadResult(couldNotParseManifest); pak = new vfs::directory; pak->setAttribute("board", document["game/board" ].string()); @@ -33,7 +33,7 @@ auto GameGear::load(string location) -> bool { Medium::load(node, ".ram"); } - return true; + return LoadResult(successful); } auto GameGear::save(string location) -> bool { diff --git a/mia/medium/master-system.cpp b/mia/medium/master-system.cpp index 1b3aa15d2d..e83d9729a5 100644 --- a/mia/medium/master-system.cpp +++ b/mia/medium/master-system.cpp @@ -1,25 +1,25 @@ struct MasterSystem : Cartridge { auto name() -> string override { return "Master System"; } auto extensions() -> vector override { return {"ms", "sms"}; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; auto analyze(vector& rom) -> string; }; -auto MasterSystem::load(string location) -> bool { +auto MasterSystem::load(string location) -> LoadResult { vector rom; if(directory::exists(location)) { append(rom, {location, "program.rom"}); } else if(file::exists(location)) { rom = Cartridge::read(location); } else { - return false; + return LoadResult(romNotFound); } this->location = location; this->manifest = analyze(rom); auto document = BML::unserialize(manifest); - if(!document) return false; + if(!document) return LoadResult(couldNotParseManifest); pak = new vfs::directory; pak->setAttribute("board", document["game/board" ].string()); @@ -34,7 +34,7 @@ auto MasterSystem::load(string location) -> bool { Medium::load(node, ".ram"); } - return true; + return LoadResult(successful); } auto MasterSystem::save(string location) -> bool { diff --git a/mia/medium/mega-32x.cpp b/mia/medium/mega-32x.cpp index 2ddc927980..bbd1e0a302 100644 --- a/mia/medium/mega-32x.cpp +++ b/mia/medium/mega-32x.cpp @@ -1,7 +1,7 @@ struct Mega32X : Cartridge { auto name() -> string override { return "Mega 32X"; } auto extensions() -> vector override { return {"32x"}; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; auto analyze(vector& rom) -> string; auto analyzeStorage(vector& rom, string hash) -> void; @@ -25,19 +25,19 @@ struct Mega32X : Cartridge { } eeprom; }; -auto Mega32X::load(string location) -> bool { +auto Mega32X::load(string location) -> LoadResult { vector rom; if(directory::exists(location)) { append(rom, {location, "program.rom"}); } else if(file::exists(location)) { rom = Cartridge::read(location); } - if(!rom) return false; + if(!rom) return LoadResult(romNotFound); this->location = location; this->manifest = analyze(rom); auto document = BML::unserialize(manifest); - if(!document) return false; + if(!document) return LoadResult(couldNotParseManifest); pak = new vfs::directory; pak->setAttribute("title", document["game/title"].string()); @@ -67,7 +67,7 @@ auto Mega32X::load(string location) -> bool { } } - return true; + return LoadResult(successful); } auto Mega32X::save(string location) -> bool { diff --git a/mia/medium/mega-cd.cpp b/mia/medium/mega-cd.cpp index dea98ccc6a..c16581f06d 100644 --- a/mia/medium/mega-cd.cpp +++ b/mia/medium/mega-cd.cpp @@ -1,18 +1,18 @@ struct MegaCD : CompactDisc { auto name() -> string override { return "Mega CD"; } auto extensions() -> vector override { return {"cue", "chd"}; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; auto analyze(string location) -> string; }; -auto MegaCD::load(string location) -> bool { - if(!inode::exists(location)) return false; +auto MegaCD::load(string location) -> LoadResult { + if(!inode::exists(location)) return LoadResult(romNotFound); this->location = location; this->manifest = analyze(location); auto document = BML::unserialize(manifest); - if(!document) return false; + if(!document) return LoadResult(couldNotParseManifest); pak = new vfs::directory; pak->setAttribute("title", document["game/title"].string()); @@ -27,7 +27,7 @@ auto MegaCD::load(string location) -> bool { pak->append("cd.rom", vfs::cdrom::open(location)); } - return true; + return LoadResult(successful); } auto MegaCD::save(string location) -> bool { diff --git a/mia/medium/mega-drive.cpp b/mia/medium/mega-drive.cpp index d61ada7ee6..7b907b8c04 100644 --- a/mia/medium/mega-drive.cpp +++ b/mia/medium/mega-drive.cpp @@ -1,7 +1,7 @@ struct MegaDrive : Cartridge { auto name() -> string override { return "Mega Drive"; } auto extensions() -> vector override { return {"md", "gen", "bin"}; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; auto analyze(vector& rom) -> string; auto analyzeStorage(vector& rom, string hash) -> void; @@ -37,19 +37,19 @@ struct MegaDrive : Cartridge { } peripherals; }; -auto MegaDrive::load(string location) -> bool { +auto MegaDrive::load(string location) -> LoadResult { vector rom; if(directory::exists(location)) { append(rom, {location, "program.rom"}); } else if(file::exists(location)) { rom = Cartridge::read(location); } - if(!rom) return false; + if(!rom) return LoadResult(romNotFound); this->location = location; this->manifest = analyze(rom); auto document = BML::unserialize(manifest); - if(!document) return false; + if(!document) return LoadResult(couldNotParseManifest); pak = new vfs::directory; pak->setAttribute("title", document["game/title"].string()); @@ -100,7 +100,7 @@ auto MegaDrive::load(string location) -> bool { pak->setAttribute("jcart", true); } - return true; + return LoadResult(successful); } auto MegaDrive::save(string location) -> bool { diff --git a/mia/medium/msx.cpp b/mia/medium/msx.cpp index 996c08ad44..243d0500c8 100644 --- a/mia/medium/msx.cpp +++ b/mia/medium/msx.cpp @@ -1,14 +1,14 @@ struct MSX : Cartridge { auto name() -> string override { return "MSX"; } auto extensions() -> vector override { return {"msx", "rom", "wav"}; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; auto analyze(vector& rom) -> string; - auto loadTape(string location) -> bool; + auto loadTape(string location) -> LoadResult; auto analyzeTape(string location) -> string; }; -auto MSX::load(string location) -> bool { +auto MSX::load(string location) -> LoadResult { if(location.iendsWith(".wav")) { return loadTape(location); } @@ -19,16 +19,16 @@ auto MSX::load(string location) -> bool { } else if(file::exists(location)) { rom = Cartridge::read(location); } - if(!rom) return false; + if(!rom) return LoadResult(romNotFound); this->sha256 = Hash::SHA256(rom).digest(); this->location = location; auto foundDatabase = Medium::loadDatabase(); - if(!foundDatabase) return false; + if(!foundDatabase) return LoadResult(databaseNotFound); this->manifest = Medium::manifestDatabase(sha256); if(!manifest) manifest = analyze(rom); auto document = BML::unserialize(manifest); - if(!document) return false; + if(!document) return LoadResult(couldNotParseManifest); pak = new vfs::directory; pak->setAttribute("title", document["game/title"].string()); @@ -38,7 +38,7 @@ auto MSX::load(string location) -> bool { pak->append("manifest.bml", manifest); pak->append("program.rom", rom); - return true; + return LoadResult(successful); } auto MSX::save(string location) -> bool { @@ -141,13 +141,13 @@ auto MSX::analyze(vector& rom) -> string { } -auto MSX::loadTape(string location) -> bool { - if(!inode::exists(location)) return false; +auto MSX::loadTape(string location) -> LoadResult { + if(!inode::exists(location)) return LoadResult(romNotFound); this->location = location; this->manifest = analyzeTape(location); auto document = BML::unserialize(manifest); - if(!document) return false; + if(!document) return LoadResult(couldNotParseManifest); pak = new vfs::directory; pak->setAttribute("title", document["game/title"].string()); @@ -177,7 +177,7 @@ auto MSX::loadTape(string location) -> bool { } } - return true; + return LoadResult(successful); } auto MSX::analyzeTape(string location) -> string { diff --git a/mia/medium/myvision.cpp b/mia/medium/myvision.cpp index e63c47ae5d..fa29ff8cf9 100644 --- a/mia/medium/myvision.cpp +++ b/mia/medium/myvision.cpp @@ -4,32 +4,32 @@ struct MyVision : Cartridge { auto name() -> string override { return "MyVision"; } auto extensions() -> vector override { return {"myv"}; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; auto analyze(vector& rom) -> string; }; -auto MyVision::load(string location) -> bool { +auto MyVision::load(string location) -> LoadResult { vector rom; if(directory::exists(location)) { append(rom, {location, "program.rom"}); } else if(file::exists(location)) { rom = Cartridge::read(location); } - if(!rom) return false; + if(!rom) return LoadResult(romNotFound); this->sha256 = Hash::SHA256(rom).digest(); this->location = location; this->manifest = analyze(rom); auto document = BML::unserialize(manifest); - if(!document) return false; + if(!document) return LoadResult(couldNotParseManifest); pak = new vfs::directory; pak->setAttribute("title", document["game/title"].string()); pak->append("manifest.bml", manifest); pak->append("program.rom", rom); - return true; + return LoadResult(successful); } auto MyVision::save(string location) -> bool { diff --git a/mia/medium/neo-geo-pocket.cpp b/mia/medium/neo-geo-pocket.cpp index 0d20a03efb..7e5ae0d1ef 100644 --- a/mia/medium/neo-geo-pocket.cpp +++ b/mia/medium/neo-geo-pocket.cpp @@ -1,25 +1,25 @@ struct NeoGeoPocket : Cartridge { auto name() -> string override { return "Neo Geo Pocket"; } auto extensions() -> vector override { return {"ngp"}; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; auto analyze(vector& rom) -> string; auto label(vector& data) -> string; }; -auto NeoGeoPocket::load(string location) -> bool { +auto NeoGeoPocket::load(string location) -> LoadResult { vector rom; if(directory::exists(location)) { append(rom, {location, "program.flash"}); } else if(file::exists(location)) { rom = Cartridge::read(location); } - if(!rom) return false; + if(!rom) return LoadResult(romNotFound); this->location = location; this->manifest = analyze(rom); auto document = BML::unserialize(manifest); - if(!document) return false; + if(!document) return LoadResult(couldNotParseManifest); pak = new vfs::directory; pak->setAttribute("title", document["game/title"].string()); @@ -28,7 +28,7 @@ auto NeoGeoPocket::load(string location) -> bool { Pak::load("program.flash", ".sav"); - return true; + return LoadResult(successful); } auto NeoGeoPocket::save(string location) -> bool { diff --git a/mia/medium/neo-geo.cpp b/mia/medium/neo-geo.cpp index cc2795db96..c4bc4b06c5 100644 --- a/mia/medium/neo-geo.cpp +++ b/mia/medium/neo-geo.cpp @@ -6,7 +6,7 @@ struct NeoGeo : Mame { auto name() -> string override { return "Neo Geo"; } auto extensions() -> vector override { return {"ng"}; } auto read(string location, string match) -> vector; - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto board() -> string; auto save(string location) -> bool override; auto analyze(vector& p, vector& m, vector& c, vector& s, vector& vA, vector& vB) -> string; @@ -58,7 +58,7 @@ auto NeoGeo::read(string location, string match) -> vector { return {}; } -auto NeoGeo::load(string location) -> bool { +auto NeoGeo::load(string location) -> LoadResult { vector programROM; //P ROM (68K CPU program) vector musicROM; //M ROM (Z80 APU program) vector characterROM; //C ROM (sprite and background character graphics) @@ -67,7 +67,7 @@ auto NeoGeo::load(string location) -> bool { vector voiceBROM; //V ROM (ADPCM-B voice samples) auto foundDatabase = Medium::loadDatabase(); - if(!foundDatabase) return false; + if(!foundDatabase) return LoadResult(databaseNotFound); this->info = BML::unserialize(manifestDatabaseArcade(Medium::name(location))); if(file::exists(location)) { @@ -79,11 +79,11 @@ auto NeoGeo::load(string location) -> bool { voiceBROM = NeoGeo::read(location, "voice-b.rom"); } - if(!programROM ) return false; - if(!musicROM ) return false; - if(!characterROM) return false; - if(!staticROM ) return false; - if(!voiceAROM ) return false; + if(!programROM ) return LoadResult(romNotFound); + if(!musicROM ) return LoadResult(romNotFound); + if(!characterROM) return LoadResult(romNotFound); + if(!staticROM ) return LoadResult(romNotFound); + if(!voiceAROM ) return LoadResult(romNotFound); //voiceB is optional //many games have encrypted roms, so let's decrypt them here @@ -101,7 +101,7 @@ auto NeoGeo::load(string location) -> bool { this->location = location; this->manifest = analyze(programROM, musicROM, characterROM, staticROM, voiceAROM, voiceBROM); auto document = BML::unserialize(manifest); - if(!document) return false; + if(!document) return LoadResult(couldNotParseManifest); pak = new vfs::directory; pak->setAttribute("sha256", sha256); @@ -114,7 +114,7 @@ auto NeoGeo::load(string location) -> bool { pak->append("static.rom", staticROM); pak->append("voice-a.rom", voiceAROM); pak->append("voice-b.rom", voiceBROM); - return true; + return LoadResult(successful); } auto NeoGeo::save(string location) -> bool { diff --git a/mia/medium/nintendo-64.cpp b/mia/medium/nintendo-64.cpp index 47bed77b94..e6e86c5e6e 100644 --- a/mia/medium/nintendo-64.cpp +++ b/mia/medium/nintendo-64.cpp @@ -1,7 +1,7 @@ struct Nintendo64 : Cartridge { auto name() -> string override { return "Nintendo 64"; } auto extensions() -> vector override { return {"n64", "v64", "z64"}; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; auto analyze(vector& rom) -> string; auto ipl2checksum(u32 seed, array_view rom) -> u64; @@ -82,21 +82,21 @@ auto Nintendo64::ipl2checksum(u32 seed, array_view rom) -> u64 { return checksum & 0xffffffffffffull; } -auto Nintendo64::load(string location) -> bool { +auto Nintendo64::load(string location) -> LoadResult { vector rom; if(directory::exists(location)) { append(rom, {location, "program.rom"}); } else if(file::exists(location)) { rom = Cartridge::read(location); } - if(!rom) return false; + if(!rom) return LoadResult(romNotFound); this->sha256 = Hash::SHA256(rom).digest(); this->location = location; this->manifest = analyze(rom); auto document = BML::unserialize(manifest); - if(!document) return false; + if(!document) return LoadResult(couldNotParseManifest); pak = new vfs::directory; pak->setAttribute("id", document["game/id"].string()); @@ -123,7 +123,7 @@ auto Nintendo64::load(string location) -> bool { Medium::load(node, ".rtc"); } - return true; + return LoadResult(successful); } auto Nintendo64::save(string location) -> bool { diff --git a/mia/medium/nintendo-64dd.cpp b/mia/medium/nintendo-64dd.cpp index 1906a6db4d..de49b38e48 100644 --- a/mia/medium/nintendo-64dd.cpp +++ b/mia/medium/nintendo-64dd.cpp @@ -1,7 +1,7 @@ struct Nintendo64DD : FloppyDisk { auto name() -> string override { return "Nintendo 64DD"; } auto extensions() -> vector override { return {"n64dd", "ndd", "d64"}; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; auto analyze(vector& rom, vector errorTable) -> string; auto transform(array_view input, vector errorTable) -> vector; @@ -10,24 +10,24 @@ struct Nintendo64DD : FloppyDisk { auto createErrorTable(array_view input) -> vector; }; -auto Nintendo64DD::load(string location) -> bool { +auto Nintendo64DD::load(string location) -> LoadResult { vector input; if(directory::exists(location)) { append(input, {location, "program.disk"}); } else if(file::exists(location)) { input = FloppyDisk::read(location); } - if(!input) return false; + if(!input) return LoadResult(romNotFound); array_view view{input}; auto errorTable = createErrorTable(view); - if(!errorTable) return false; + if(!errorTable) return LoadResult(invalidRom); auto sizeValid = sizeCheck(view); - if(!sizeValid) return false; + if(!sizeValid) return LoadResult(invalidRom); this->location = location; this->manifest = analyze(input, errorTable); auto document = BML::unserialize(manifest); - if(!document) return false; + if(!document) return LoadResult(couldNotParseManifest); pak = shared_pointer{new vfs::directory}; pak->setAttribute("title", document["game/title"].string()); pak->setAttribute("region", document["game/region"].string()); @@ -38,11 +38,11 @@ auto Nintendo64DD::load(string location) -> bool { pak->append("program.disk", output); } - if(!pak) return false; + if(!pak) return LoadResult(otherError); Pak::load("program.disk", ".disk"); - return true; + return LoadResult(successful); } auto Nintendo64DD::save(string location) -> bool { diff --git a/mia/medium/pc-engine-cd.cpp b/mia/medium/pc-engine-cd.cpp index bdf64bd743..fa109759cf 100644 --- a/mia/medium/pc-engine-cd.cpp +++ b/mia/medium/pc-engine-cd.cpp @@ -1,18 +1,18 @@ struct PCEngineCD : CompactDisc { auto name() -> string override { return "PC Engine CD"; } auto extensions() -> vector override { return {"cue", "chd"}; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; auto analyze(string location) -> string; }; -auto PCEngineCD::load(string location) -> bool { - if(!inode::exists(location)) return false; +auto PCEngineCD::load(string location) -> LoadResult { + if(!inode::exists(location)) return LoadResult(romNotFound); this->location = location; this->manifest = analyze(location); auto document = BML::unserialize(manifest); - if(!document) return false; + if(!document) return LoadResult(couldNotParseManifest); pak = new vfs::directory; pak->setAttribute("title", document["game/title"].string()); @@ -27,7 +27,7 @@ auto PCEngineCD::load(string location) -> bool { pak->append("cd.rom", vfs::cdrom::open(location)); } - return true; + return LoadResult(successful); } auto PCEngineCD::save(string location) -> bool { diff --git a/mia/medium/pc-engine.cpp b/mia/medium/pc-engine.cpp index 204db2ea32..ffd2581722 100644 --- a/mia/medium/pc-engine.cpp +++ b/mia/medium/pc-engine.cpp @@ -1,24 +1,24 @@ struct PCEngine : Cartridge { auto name() -> string override { return "PC Engine"; } auto extensions() -> vector override { return {"pce"}; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; auto analyze(vector& rom) -> string; }; -auto PCEngine::load(string location) -> bool { +auto PCEngine::load(string location) -> LoadResult { vector rom; if(directory::exists(location)) { append(rom, {location, "program.rom"}); } else if(file::exists(location)) { rom = Cartridge::read(location); } - if(!rom) return false; + if(!rom) return LoadResult(romNotFound); this->location = location; this->manifest = analyze(rom); auto document = BML::unserialize(manifest); - if(!document) return false; + if(!document) return LoadResult(couldNotParseManifest); pak = new vfs::directory; pak->setAttribute("title", document["game/title"].string()); @@ -37,7 +37,7 @@ auto PCEngine::load(string location) -> bool { Medium::load(node, ".wram"); } - return true; + return LoadResult(successful); } auto PCEngine::save(string location) -> bool { diff --git a/mia/medium/playstation.cpp b/mia/medium/playstation.cpp index 043e0497dc..a18b276955 100644 --- a/mia/medium/playstation.cpp +++ b/mia/medium/playstation.cpp @@ -1,19 +1,19 @@ struct PlayStation : CompactDisc { auto name() -> string override { return "PlayStation"; } auto extensions() -> vector override { return {"cue", "chd", "exe"}; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; auto analyze(string location) -> string; auto cdFromExecutable(string location) -> vector; }; -auto PlayStation::load(string location) -> bool { - if(!inode::exists(location)) return false; +auto PlayStation::load(string location) -> LoadResult { + if(!inode::exists(location)) return LoadResult(romNotFound); this->location = location; this->manifest = analyze(location); auto document = BML::unserialize(manifest); - if(!document) return false; + if(!document) return LoadResult(couldNotParseManifest); pak = new vfs::directory; pak->setAttribute("title", document["game/title"].string()); @@ -36,7 +36,7 @@ auto PlayStation::load(string location) -> bool { } } - return true; + return LoadResult(successful); } auto PlayStation::save(string location) -> bool { diff --git a/mia/medium/saturn.cpp b/mia/medium/saturn.cpp index 2361f61931..64fca07844 100644 --- a/mia/medium/saturn.cpp +++ b/mia/medium/saturn.cpp @@ -1,18 +1,18 @@ struct Saturn : CompactDisc { auto name() -> string override { return "Saturn"; } auto extensions() -> vector override { return {"cue", "chd"}; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; auto analyze(string location) -> string; }; -auto Saturn::load(string location) -> bool { - if(!inode::exists(location)) return false; +auto Saturn::load(string location) -> LoadResult { + if(!inode::exists(location)) return LoadResult(romNotFound); this->location = location; this->manifest = analyze(location); auto document = BML::unserialize(manifest); - if(!document) return false; + if(!document) return LoadResult(couldNotParseManifest); pak = new vfs::directory; pak->setAttribute("title", document["game/title"].string()); @@ -26,7 +26,7 @@ auto Saturn::load(string location) -> bool { pak->append("cd.rom", vfs::cdrom::open(location)); } - return true; + return LoadResult(successful); } auto Saturn::save(string location) -> bool { diff --git a/mia/medium/sg-1000.cpp b/mia/medium/sg-1000.cpp index d8bef675da..7ea9c5c43c 100644 --- a/mia/medium/sg-1000.cpp +++ b/mia/medium/sg-1000.cpp @@ -1,24 +1,24 @@ struct SG1000 : Cartridge { auto name() -> string override { return "SG-1000"; } auto extensions() -> vector override { return {"sg1000", "sg"}; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; auto analyze(vector& rom) -> string; }; -auto SG1000::load(string location) -> bool { +auto SG1000::load(string location) -> LoadResult { vector rom; if(directory::exists(location)) { append(rom, {location, "program.rom"}); } else if(file::exists(location)) { rom = Cartridge::read(location); } - if(!rom) return false; + if(!rom) return LoadResult(romNotFound); this->location = location; this->manifest = analyze(rom); auto document = BML::unserialize(manifest); - if(!document) return false; + if(!document) return LoadResult(couldNotParseManifest); pak = new vfs::directory; pak->setAttribute("board", document["game/board" ].string()); @@ -31,7 +31,7 @@ auto SG1000::load(string location) -> bool { Medium::load(node, ".ram"); } - return true; + return LoadResult(successful); } auto SG1000::save(string location) -> bool { diff --git a/mia/medium/sufami-turbo.cpp b/mia/medium/sufami-turbo.cpp index 5bbacb2953..71d3b30d3c 100644 --- a/mia/medium/sufami-turbo.cpp +++ b/mia/medium/sufami-turbo.cpp @@ -1,28 +1,28 @@ struct SufamiTurbo : Cartridge { auto name() -> string override { return "Sufami Turbo"; } auto extensions() -> vector override { return {"st"}; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; auto analyze(vector& data) -> string; }; -auto SufamiTurbo::load(string location) -> bool { +auto SufamiTurbo::load(string location) -> LoadResult { vector rom; if(directory::exists(location)) { append(rom, {location, "program.rom"}); } else if(file::exists(location)) { rom = Cartridge::read(location); } - if(!rom) return false; + if(!rom) return LoadResult(romNotFound); this->sha256 = Hash::SHA256(rom).digest(); this->location = location; auto foundDatabase = Medium::loadDatabase(); - if(!foundDatabase) return false; + if(!foundDatabase) return LoadResult(databaseNotFound); this->manifest = Medium::manifestDatabase(sha256); if(!manifest) manifest = analyze(rom); auto document = BML::unserialize(manifest); - if(!document) return false; + if(!document) return LoadResult(couldNotParseManifest); pak = new vfs::directory; pak->setAttribute("title", document["game/title"].string()); @@ -33,7 +33,7 @@ auto SufamiTurbo::load(string location) -> bool { Medium::load(node, ".ram"); } - return true; + return LoadResult(successful); } auto SufamiTurbo::save(string location) -> bool { diff --git a/mia/medium/super-famicom.cpp b/mia/medium/super-famicom.cpp index de272869f5..c14f5b36b4 100644 --- a/mia/medium/super-famicom.cpp +++ b/mia/medium/super-famicom.cpp @@ -1,7 +1,7 @@ struct SuperFamicom : Cartridge { auto name() -> string override { return "Super Famicom"; } auto extensions() -> vector override { return {"sfc", "smc", "swc", "fig"}; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; auto analyze(vector& rom) -> string; @@ -33,7 +33,7 @@ struct SuperFamicom : Cartridge { u32 headerAddress = 0; }; -auto SuperFamicom::load(string location) -> bool { +auto SuperFamicom::load(string location) -> LoadResult { vector rom; string directory = location; bool local_firmware = false; @@ -75,7 +75,7 @@ auto SuperFamicom::load(string location) -> bool { directory = Location::dir(location); } - if(!rom) return false; + if(!rom) return LoadResult(romNotFound); //append firmware to the ROM if it is missing auto tmp_manifest = analyze(rom); @@ -85,7 +85,7 @@ auto SuperFamicom::load(string location) -> bool { this->sha256 = Hash::SHA256(rom).digest(); this->location = location; auto foundDatabase = Medium::loadDatabase(); - if(!foundDatabase) return false; + if(!foundDatabase) return LoadResult(databaseNotFound); this->manifest = Medium::manifestDatabase(sha256); if(!manifest) { @@ -102,7 +102,7 @@ auto SuperFamicom::load(string location) -> bool { if(!manifest) manifest = analyze(rom); document = BML::unserialize(manifest); - if(!document) return false; + if(!document) return LoadResult(couldNotParseManifest); pak = new vfs::directory; pak->setAttribute("title", document["game/title"].string()); @@ -182,7 +182,7 @@ auto SuperFamicom::load(string location) -> bool { Medium::load(node, ".dram"); } - return true; + return LoadResult(successful); } auto SuperFamicom::save(string location) -> bool { diff --git a/mia/medium/wonderswan.cpp b/mia/medium/wonderswan.cpp index d52982362d..506d82428d 100644 --- a/mia/medium/wonderswan.cpp +++ b/mia/medium/wonderswan.cpp @@ -1,25 +1,25 @@ struct WonderSwan : Cartridge { auto name() -> string override { return "WonderSwan"; } auto extensions() -> vector override { return {"ws"}; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; auto analyze(vector& rom) -> string; virtual auto mapper(vector& rom) -> string; }; -auto WonderSwan::load(string location) -> bool { +auto WonderSwan::load(string location) -> LoadResult { vector rom; if(directory::exists(location)) { append(rom, {location, "program.rom"}); } else if(file::exists(location)) { rom = Cartridge::read(location); } - if(!rom) return false; + if(!rom) return LoadResult(romNotFound); this->location = location; this->manifest = analyze(rom); auto document = BML::unserialize(manifest); - if(!document) return false; + if(!document) return LoadResult(couldNotParseManifest); pak = new vfs::directory; pak->setAttribute("title", document["game/title"].string()); @@ -43,7 +43,7 @@ auto WonderSwan::load(string location) -> bool { Medium::load(node, ".rtc"); } - return true; + return LoadResult(successful); } auto WonderSwan::save(string location) -> bool { diff --git a/mia/medium/zx-spectrum.cpp b/mia/medium/zx-spectrum.cpp index 9a5442f802..4698f687c1 100644 --- a/mia/medium/zx-spectrum.cpp +++ b/mia/medium/zx-spectrum.cpp @@ -1,30 +1,30 @@ struct ZXSpectrum : Medium { auto name() -> string override { return "ZX Spectrum"; } auto extensions() -> vector override { return {"wav", "tzx", "tap" }; } - auto load(string location) -> bool override; - auto loadWav(string location) -> bool; - auto loadTzx(string location) -> bool; + auto load(string location) -> LoadResult override; + auto loadWav(string location) -> LoadResult; + auto loadTzx(string location) -> LoadResult; auto save(string location) -> bool override; auto analyze(string location) -> string; }; -auto ZXSpectrum::load(string location) -> bool { - if(!inode::exists(location)) return false; +auto ZXSpectrum::load(string location) -> LoadResult { + if(!inode::exists(location)) return LoadResult(romNotFound); if(location.iendsWith(".tap") || location.iendsWith(".tzx")) return loadTzx(location); if(location.iendsWith(".wav")) return loadWav(location); - return false; + return LoadResult(invalidRom); } -auto ZXSpectrum::loadTzx(string location) -> bool { +auto ZXSpectrum::loadTzx(string location) -> LoadResult { this->location = location; this->manifest = analyze(location); auto document = BML::unserialize(manifest); - if (!document) return false; + if(!document) return LoadResult(couldNotParseManifest); vector input = file::read(location); TZXFile tzx; - if(tzx.DecodeFile(input.data(), input.size()) == FileTypeUndetermined) return false; + if(tzx.DecodeFile(input.data(), input.size()) == FileTypeUndetermined) return LoadResult(invalidRom); tzx.GenerateAudioData(); pak = new vfs::directory; @@ -45,14 +45,14 @@ auto ZXSpectrum::loadTzx(string location) -> bool { } pak->append("program.tape", output); - return true; + return LoadResult(successful); } -auto ZXSpectrum::loadWav(string location) -> bool { +auto ZXSpectrum::loadWav(string location) -> LoadResult { this->location = location; this->manifest = analyze(location); auto document = BML::unserialize(manifest); - if(!document) return false; + if(!document) return LoadResult(couldNotParseManifest); pak = new vfs::directory; pak->setAttribute("title", document["game/title"].string()); @@ -80,7 +80,7 @@ auto ZXSpectrum::loadWav(string location) -> bool { } } - return true; + return LoadResult(successful); } auto ZXSpectrum::save(string location) -> bool { diff --git a/mia/mia.cpp b/mia/mia.cpp index 228f944690..6b5512543b 100644 --- a/mia/mia.cpp +++ b/mia/mia.cpp @@ -144,7 +144,7 @@ auto identify(const string& filename) -> string { for(auto& medium : media) { auto pak = mia::Medium::create(medium); if(pak->extensions().find(extension)) { - if(!pak->load(filename)) continue; // Skip medium that the system cannot load + if(pak->load(filename) != LoadResult(successful)) continue; // Skip medium that the system cannot load if(pak->pak->attribute("audio").boolean()) continue; // Skip audio-only media to give the next system a chance to match return pak->name(); } @@ -154,7 +154,7 @@ auto identify(const string& filename) -> string { } auto import(shared_pointer pak, const string& filename) -> bool { - if(pak->load(filename)) { + if(pak->load(filename) == LoadResult(successful)) { string pathname = {Path::user(), "Emulation/", pak->name(), "/", Location::prefix(filename), ".", pak->extensions().first(), "/"}; if(!directory::create(pathname)) return false; for(auto& node : *pak->pak) { @@ -194,7 +194,7 @@ auto main(Arguments arguments) -> void { if(!pak) return; if(string manifest; arguments.take("--manifest", manifest)) { - if(pak->load(manifest)) { + if(pak->load(manifest) == LoadResult(successful)) { if(auto fp = pak->pak->read("manifest.bml")) return print(fp->reads()); } return; diff --git a/mia/mia.hpp b/mia/mia.hpp index cbc58a62d3..a8764adbae 100644 --- a/mia/mia.hpp +++ b/mia/mia.hpp @@ -33,4 +33,5 @@ namespace mia { auto construct() -> void; auto identify(const string& filename) -> string; auto import(shared_pointer, const string& filename) -> bool; + } diff --git a/mia/pak/pak.hpp b/mia/pak/pak.hpp index 3fab950325..6bf457ead4 100644 --- a/mia/pak/pak.hpp +++ b/mia/pak/pak.hpp @@ -5,7 +5,7 @@ struct Pak { virtual auto type() -> string { return pak->attribute("type"); } virtual auto name() -> string { return pak->attribute("name"); } virtual auto extensions() -> vector { return {}; } - virtual auto load(string location = {}) -> bool { return true; } + virtual auto load(string location = {}) -> LoadResult { return LoadResult(successful); } virtual auto loadMultiple(vector location = {}) -> bool { return true; } virtual auto save(string location = {}) -> bool { return true; } diff --git a/mia/system/arcade.cpp b/mia/system/arcade.cpp index 0a691fcebe..ba9bb19547 100644 --- a/mia/system/arcade.cpp +++ b/mia/system/arcade.cpp @@ -1,13 +1,13 @@ struct Arcade : System { auto name() -> string override { return "Arcade"; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; }; -auto Arcade::load(string location) -> bool { +auto Arcade::load(string location) -> LoadResult { this->location = locate(); pak = new vfs::directory; - return true; + return LoadResult(successful); } auto Arcade::save(string location) -> bool { diff --git a/mia/system/atari-2600.cpp b/mia/system/atari-2600.cpp index 41efb378fe..9cabd11b4c 100644 --- a/mia/system/atari-2600.cpp +++ b/mia/system/atari-2600.cpp @@ -1,13 +1,13 @@ struct Atari2600 : System { auto name() -> string override { return "Atari 2600"; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; }; -auto Atari2600::load(string location) -> bool { +auto Atari2600::load(string location) -> LoadResult { this->location = locate(); pak = new vfs::directory; - return true; + return LoadResult(successful); } auto Atari2600::save(string location) -> bool { diff --git a/mia/system/colecovision.cpp b/mia/system/colecovision.cpp index b81d60befd..c6b779f49a 100644 --- a/mia/system/colecovision.cpp +++ b/mia/system/colecovision.cpp @@ -1,17 +1,17 @@ struct ColecoVision : System { auto name() -> string override { return "ColecoVision"; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; }; -auto ColecoVision::load(string location) -> bool { +auto ColecoVision::load(string location) -> LoadResult { auto bios = Pak::read(location); - if(!bios) return false; + if(!bios) return LoadResult(romNotFound); this->location = locate(); pak = new vfs::directory; pak->append("bios.rom", bios); - return true; + return LoadResult(successful); } auto ColecoVision::save(string location) -> bool { diff --git a/mia/system/famicom.cpp b/mia/system/famicom.cpp index 19b77d70b4..da50011e95 100644 --- a/mia/system/famicom.cpp +++ b/mia/system/famicom.cpp @@ -1,13 +1,13 @@ struct Famicom : System { auto name() -> string override { return "Famicom"; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; }; -auto Famicom::load(string location) -> bool { +auto Famicom::load(string location) -> LoadResult { this->location = locate(); pak = new vfs::directory; - return true; + return LoadResult(successful); } auto Famicom::save(string location) -> bool { diff --git a/mia/system/game-boy-advance.cpp b/mia/system/game-boy-advance.cpp index 2eff570ec8..c2e101085b 100644 --- a/mia/system/game-boy-advance.cpp +++ b/mia/system/game-boy-advance.cpp @@ -1,17 +1,17 @@ struct GameBoyAdvance : System { auto name() -> string override { return "Game Boy Advance"; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; }; -auto GameBoyAdvance::load(string location) -> bool { +auto GameBoyAdvance::load(string location) -> LoadResult { auto bios = Pak::read(location); - if(!bios) return false; + if(!bios) return LoadResult(romNotFound); this->location = locate(); pak = new vfs::directory; pak->append("bios.rom", bios); - return true; + return LoadResult(successful); } auto GameBoyAdvance::save(string location) -> bool { diff --git a/mia/system/game-boy-color.cpp b/mia/system/game-boy-color.cpp index 1f1a9741ae..116c74ae82 100644 --- a/mia/system/game-boy-color.cpp +++ b/mia/system/game-boy-color.cpp @@ -1,14 +1,14 @@ struct GameBoyColor : System { auto name() -> string override { return "Game Boy Color"; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; }; -auto GameBoyColor::load(string location) -> bool { +auto GameBoyColor::load(string location) -> LoadResult { this->location = locate(); pak = new vfs::directory; pak->append("boot.rom", Resource::GameBoyColor::BootCGB0); - return true; + return LoadResult(successful); } auto GameBoyColor::save(string location) -> bool { diff --git a/mia/system/game-boy.cpp b/mia/system/game-boy.cpp index 9ec031eb4d..628560332c 100644 --- a/mia/system/game-boy.cpp +++ b/mia/system/game-boy.cpp @@ -1,14 +1,14 @@ struct GameBoy : System { auto name() -> string override { return "Game Boy"; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; }; -auto GameBoy::load(string location) -> bool { +auto GameBoy::load(string location) -> LoadResult { this->location = locate(); pak = new vfs::directory; pak->append("boot.rom", Resource::GameBoy::BootDMG1); - return true; + return LoadResult(successful); } auto GameBoy::save(string location) -> bool { diff --git a/mia/system/game-gear.cpp b/mia/system/game-gear.cpp index c3260fca64..8563e9df5a 100644 --- a/mia/system/game-gear.cpp +++ b/mia/system/game-gear.cpp @@ -1,17 +1,17 @@ struct GameGear : System { auto name() -> string override { return "Game Gear"; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; }; -auto GameGear::load(string location) -> bool { +auto GameGear::load(string location) -> LoadResult { auto bios = Pak::read(location); //optional this->location = locate(); pak = new vfs::directory; if(bios) pak->append("bios.rom", bios); - return true; + return LoadResult(successful); } auto GameGear::save(string location) -> bool { diff --git a/mia/system/master-system.cpp b/mia/system/master-system.cpp index 414e86eb64..4073275b8c 100644 --- a/mia/system/master-system.cpp +++ b/mia/system/master-system.cpp @@ -1,17 +1,17 @@ struct MasterSystem : System { auto name() -> string override { return "Master System"; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; }; -auto MasterSystem::load(string location) -> bool { +auto MasterSystem::load(string location) -> LoadResult { auto bios = Pak::read(location); //optional this->location = locate(); pak = new vfs::directory; if(bios) pak->append("bios.rom", bios); - return true; + return LoadResult(successful); } auto MasterSystem::save(string location) -> bool { diff --git a/mia/system/mega-32x.cpp b/mia/system/mega-32x.cpp index 1299f4bbea..eead05b9b2 100644 --- a/mia/system/mega-32x.cpp +++ b/mia/system/mega-32x.cpp @@ -1,17 +1,17 @@ struct Mega32X : System { auto name() -> string override { return "Mega 32X"; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; }; -auto Mega32X::load(string location) -> bool { +auto Mega32X::load(string location) -> LoadResult { this->location = locate(); pak = new vfs::directory; pak->append("tmss.rom", Resource::MegaDrive::TMSS); pak->append("vector.rom", Resource::Mega32X::Vector); pak->append("sh2.boot.mrom", Resource::Mega32X::SH2BootM); pak->append("sh2.boot.srom", Resource::Mega32X::SH2BootS); - return true; + return LoadResult(successful); } auto Mega32X::save(string location) -> bool { diff --git a/mia/system/mega-cd-32x.cpp b/mia/system/mega-cd-32x.cpp index a6f7619ae0..1b1b1d1398 100644 --- a/mia/system/mega-cd-32x.cpp +++ b/mia/system/mega-cd-32x.cpp @@ -1,6 +1,6 @@ struct MegaCD32X : System { auto name() -> string override { return "Mega CD 32X"; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; static constexpr u8 bram[64] = { @@ -11,9 +11,9 @@ struct MegaCD32X : System { }; }; -auto MegaCD32X::load(string location) -> bool { +auto MegaCD32X::load(string location) -> LoadResult { auto bios = Pak::read(location); - if(!bios) return false; + if(!bios) return LoadResult(romNotFound); this->location = locate(); pak = new vfs::directory; @@ -32,7 +32,7 @@ auto MegaCD32X::load(string location) -> bool { Pak::load("backup.ram", ".bram"); - return true; + return LoadResult(successful); } auto MegaCD32X::save(string location) -> bool { diff --git a/mia/system/mega-cd.cpp b/mia/system/mega-cd.cpp index d672aecbde..dc481d3e78 100644 --- a/mia/system/mega-cd.cpp +++ b/mia/system/mega-cd.cpp @@ -1,6 +1,6 @@ struct MegaCD : System { auto name() -> string override { return "Mega CD"; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; static constexpr u8 bram[64] = { @@ -11,9 +11,9 @@ struct MegaCD : System { }; }; -auto MegaCD::load(string location) -> bool { +auto MegaCD::load(string location) -> LoadResult { auto bios = Pak::read(location); - if(!bios) return false; + if(!bios) return LoadResult(romNotFound); this->location = locate(); pak = new vfs::directory; @@ -29,7 +29,7 @@ auto MegaCD::load(string location) -> bool { Pak::load("backup.ram", ".bram"); - return true; + return LoadResult(successful); } auto MegaCD::save(string location) -> bool { diff --git a/mia/system/mega-drive.cpp b/mia/system/mega-drive.cpp index 601a470d48..ddf4b9431d 100644 --- a/mia/system/mega-drive.cpp +++ b/mia/system/mega-drive.cpp @@ -1,14 +1,14 @@ struct MegaDrive : System { auto name() -> string override { return "Mega Drive"; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; }; -auto MegaDrive::load(string location) -> bool { +auto MegaDrive::load(string location) -> LoadResult { this->location = locate(); pak = new vfs::directory; pak->append("tmss.rom", Resource::MegaDrive::TMSS); - return true; + return LoadResult(successful); } auto MegaDrive::save(string location) -> bool { diff --git a/mia/system/msx.cpp b/mia/system/msx.cpp index 1c3a98cc0a..a1103074ab 100644 --- a/mia/system/msx.cpp +++ b/mia/system/msx.cpp @@ -1,17 +1,17 @@ struct MSX : System { auto name() -> string override { return "MSX"; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; }; -auto MSX::load(string location) -> bool { +auto MSX::load(string location) -> LoadResult { auto bios = Pak::read(location); - if(!bios) return false; + if(!bios) return LoadResult(romNotFound); this->location = locate(); pak = new vfs::directory; pak->append("bios.rom", bios); - return true; + return LoadResult(successful); } auto MSX::save(string location) -> bool { diff --git a/mia/system/myvision.cpp b/mia/system/myvision.cpp index 123259624f..4646336ec6 100644 --- a/mia/system/myvision.cpp +++ b/mia/system/myvision.cpp @@ -1,15 +1,15 @@ struct MyVision : System { auto name() -> string override { return "MyVision"; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; }; -auto MyVision::load(string location) -> bool { +auto MyVision::load(string location) -> LoadResult { this->location = locate(); pak = new vfs::directory; - return true; + return LoadResult(successful); } auto MyVision::save(string location) -> bool { diff --git a/mia/system/neo-geo-aes.cpp b/mia/system/neo-geo-aes.cpp index 4e595b83c7..a0e8114957 100644 --- a/mia/system/neo-geo-aes.cpp +++ b/mia/system/neo-geo-aes.cpp @@ -1,11 +1,11 @@ struct NeoGeoAES : System { auto name() -> string override { return "Neo Geo AES"; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; auto endianSwap(vector&) -> void; }; -auto NeoGeoAES::load(string location) -> bool { +auto NeoGeoAES::load(string location) -> LoadResult { this->location = locate(); pak = new vfs::directory; @@ -26,9 +26,9 @@ auto NeoGeoAES::load(string location) -> bool { if (bios) pak->append("bios.rom", bios); } - if(pak->count() != 1) return false; + if(pak->count() != 1) return LoadResult(romNotFound); - return true; + return LoadResult(successful); } auto NeoGeoAES::save(string location) -> bool { diff --git a/mia/system/neo-geo-mvs.cpp b/mia/system/neo-geo-mvs.cpp index e42d056bce..fb95f531c7 100644 --- a/mia/system/neo-geo-mvs.cpp +++ b/mia/system/neo-geo-mvs.cpp @@ -1,11 +1,11 @@ struct NeoGeoMVS : System { auto name() -> string override { return "Neo Geo MVS"; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; auto endianSwap(vector&) -> void; }; -auto NeoGeoMVS::load(string location) -> bool { +auto NeoGeoMVS::load(string location) -> LoadResult { this->location = locate(); pak = new vfs::directory; @@ -26,9 +26,9 @@ auto NeoGeoMVS::load(string location) -> bool { if(bios) pak->append("bios.rom", bios); } - if(pak->count() != 1) return false; + if(pak->count() != 1) return LoadResult(romNotFound); - return true; + return LoadResult(successful); } auto NeoGeoMVS::save(string location) -> bool { diff --git a/mia/system/neo-geo-pocket-color.cpp b/mia/system/neo-geo-pocket-color.cpp index f65c895c5c..a45f77c391 100644 --- a/mia/system/neo-geo-pocket-color.cpp +++ b/mia/system/neo-geo-pocket-color.cpp @@ -1,12 +1,12 @@ struct NeoGeoPocketColor : System { auto name() -> string override { return "Neo Geo Pocket Color"; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; }; -auto NeoGeoPocketColor::load(string location) -> bool { +auto NeoGeoPocketColor::load(string location) -> LoadResult { auto bios = Pak::read(location); - if(!bios) return false; + if(!bios) return LoadResult(romNotFound); this->location = locate(); pak = new vfs::directory; @@ -17,7 +17,7 @@ auto NeoGeoPocketColor::load(string location) -> bool { Pak::load("cpu.ram", ".cram"); Pak::load("apu.ram", ".aram"); - return true; + return LoadResult(successful); } auto NeoGeoPocketColor::save(string location) -> bool { diff --git a/mia/system/neo-geo-pocket.cpp b/mia/system/neo-geo-pocket.cpp index 08885a8a54..9f98fbd8d1 100644 --- a/mia/system/neo-geo-pocket.cpp +++ b/mia/system/neo-geo-pocket.cpp @@ -1,12 +1,12 @@ struct NeoGeoPocket : System { auto name() -> string override { return "Neo Geo Pocket"; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; }; -auto NeoGeoPocket::load(string location) -> bool { +auto NeoGeoPocket::load(string location) -> LoadResult { auto bios = Pak::read(location); - if(!bios) return false; + if(!bios) return LoadResult(romNotFound); this->location = locate(); pak = new vfs::directory; @@ -17,7 +17,7 @@ auto NeoGeoPocket::load(string location) -> bool { Pak::load("cpu.ram", ".cram"); Pak::load("apu.ram", ".aram"); - return true; + return LoadResult(successful); } auto NeoGeoPocket::save(string location) -> bool { diff --git a/mia/system/nintendo-64.cpp b/mia/system/nintendo-64.cpp index dba2540d4a..4d4c9144fb 100644 --- a/mia/system/nintendo-64.cpp +++ b/mia/system/nintendo-64.cpp @@ -1,16 +1,16 @@ struct Nintendo64 : System { auto name() -> string override { return "Nintendo 64"; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; }; -auto Nintendo64::load(string location) -> bool { +auto Nintendo64::load(string location) -> LoadResult { this->location = locate(); pak = new vfs::directory; pak->append("pif.ntsc.rom", Resource::Nintendo64::PIFNTSC); pak->append("pif.pal.rom", Resource::Nintendo64::PIFPAL ); pak->append("pif.sm5.rom", Resource::Nintendo64::PIFSM5 ); - return true; + return LoadResult(successful); } auto Nintendo64::save(string location) -> bool { diff --git a/mia/system/nintendo-64dd.cpp b/mia/system/nintendo-64dd.cpp index 686b465dfd..c975abfe0f 100644 --- a/mia/system/nintendo-64dd.cpp +++ b/mia/system/nintendo-64dd.cpp @@ -1,12 +1,12 @@ struct Nintendo64DD : System { auto name() -> string override { return "Nintendo 64DD"; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; }; -auto Nintendo64DD::load(string location) -> bool { +auto Nintendo64DD::load(string location) -> LoadResult { auto bios = Pak::read(location); - if(!bios) return false; + if(!bios) return LoadResult(romNotFound); this->location = locate(); pak = new vfs::directory; @@ -21,7 +21,7 @@ auto Nintendo64DD::load(string location) -> bool { } Pak::load("time.rtc", ".rtc"); - return true; + return LoadResult(successful); } auto Nintendo64DD::save(string location) -> bool { diff --git a/mia/system/pc-engine.cpp b/mia/system/pc-engine.cpp index ffe3ef01ab..f873084b1f 100644 --- a/mia/system/pc-engine.cpp +++ b/mia/system/pc-engine.cpp @@ -1,17 +1,17 @@ struct PCEngine : System { auto name() -> string override { return "PC Engine"; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; }; -auto PCEngine::load(string location) -> bool { +auto PCEngine::load(string location) -> LoadResult { this->location = locate(); pak = new vfs::directory; pak->append("backup.ram", 2_KiB); Pak::load("backup.ram", ".bram"); - return true; + return LoadResult(successful); } auto PCEngine::save(string location) -> bool { diff --git a/mia/system/playstation.cpp b/mia/system/playstation.cpp index 2377b7baef..f35ccbb2e1 100644 --- a/mia/system/playstation.cpp +++ b/mia/system/playstation.cpp @@ -1,18 +1,18 @@ struct PlayStation : System { auto name() -> string override { return "PlayStation"; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; }; -auto PlayStation::load(string location) -> bool { +auto PlayStation::load(string location) -> LoadResult { auto bios = Pak::read(location); - if(!bios) return false; + if(!bios) return LoadResult(romNotFound); this->location = locate(); pak = new vfs::directory; pak->append("bios.rom", bios); - return true; + return LoadResult(successful); } auto PlayStation::save(string location) -> bool { diff --git a/mia/system/pocket-challenge-v2.cpp b/mia/system/pocket-challenge-v2.cpp index 56d015fd6e..2c3a3eb666 100644 --- a/mia/system/pocket-challenge-v2.cpp +++ b/mia/system/pocket-challenge-v2.cpp @@ -1,15 +1,15 @@ struct PocketChallengeV2 : System { auto name() -> string override { return "Pocket Challenge V2"; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; }; -auto PocketChallengeV2::load(string location) -> bool { +auto PocketChallengeV2::load(string location) -> LoadResult { this->location = locate(); pak = new vfs::directory; pak->append("boot.rom", Resource::PocketChallengeV2::Boot); - return true; + return LoadResult(successful); } auto PocketChallengeV2::save(string location) -> bool { diff --git a/mia/system/saturn.cpp b/mia/system/saturn.cpp index 3a69885b52..c3e5b0b457 100644 --- a/mia/system/saturn.cpp +++ b/mia/system/saturn.cpp @@ -1,18 +1,18 @@ struct Saturn : System { auto name() -> string override { return "Saturn"; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; }; -auto Saturn::load(string location) -> bool { +auto Saturn::load(string location) -> LoadResult { auto bios = Pak::read(location); - if(!bios) return false; + if(!bios) return LoadResult(romNotFound); this->location = locate(); pak = new vfs::directory; pak->append("bios.rom", bios); - return true; + return LoadResult(successful); } auto Saturn::save(string location) -> bool { diff --git a/mia/system/sc-3000.cpp b/mia/system/sc-3000.cpp index 5430067710..5ff1c2684c 100644 --- a/mia/system/sc-3000.cpp +++ b/mia/system/sc-3000.cpp @@ -1,13 +1,13 @@ struct SC3000 : System { auto name() -> string override { return "SC-3000"; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; }; -auto SC3000::load(string location) -> bool { +auto SC3000::load(string location) -> LoadResult { this->location = locate(); pak = new vfs::directory; - return true; + return LoadResult(successful); } auto SC3000::save(string location) -> bool { diff --git a/mia/system/sg-1000.cpp b/mia/system/sg-1000.cpp index 31ac9214ee..d35cab0ec5 100644 --- a/mia/system/sg-1000.cpp +++ b/mia/system/sg-1000.cpp @@ -1,13 +1,13 @@ struct SG1000 : System { auto name() -> string override { return "SG-1000"; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; }; -auto SG1000::load(string location) -> bool { +auto SG1000::load(string location) -> LoadResult { this->location = locate(); pak = new vfs::directory; - return true; + return LoadResult(successful); } auto SG1000::save(string location) -> bool { diff --git a/mia/system/super-famicom.cpp b/mia/system/super-famicom.cpp index 8f97172261..9b2a41ab9e 100644 --- a/mia/system/super-famicom.cpp +++ b/mia/system/super-famicom.cpp @@ -1,15 +1,17 @@ struct SuperFamicom : System { auto name() -> string override { return "Super Famicom"; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; }; -auto SuperFamicom::load(string location) -> bool { +auto SuperFamicom::load(string location) -> LoadResult { this->location = locate(); pak = new vfs::directory; pak->append("ipl.rom", Resource::SuperFamicom::IPLROM); - pak->append("boards.bml", file::read(mia::locate("Database/Super Famicom Boards.bml"))); - return true; + auto romLocation = mia::locate("Database/Super Famicom Boards.bml"); + if(!romLocation) return LoadResult(databaseNotFound); + pak->append("boards.bml", file::read(romLocation)); + return LoadResult(successful); } auto SuperFamicom::save(string location) -> bool { diff --git a/mia/system/supergrafx.cpp b/mia/system/supergrafx.cpp index 0f44eba5b6..3f59240f59 100644 --- a/mia/system/supergrafx.cpp +++ b/mia/system/supergrafx.cpp @@ -1,17 +1,17 @@ struct SuperGrafx : System { auto name() -> string override { return "SuperGrafx"; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; }; -auto SuperGrafx::load(string location) -> bool { +auto SuperGrafx::load(string location) -> LoadResult { this->location = locate(); pak = new vfs::directory; pak->append("backup.ram", 2_KiB); Pak::load("backup.ram", ".bram"); - return true; + return LoadResult(successful); } auto SuperGrafx::save(string location) -> bool { diff --git a/mia/system/wonderswan-color.cpp b/mia/system/wonderswan-color.cpp index a76966208d..a4bab5ecac 100644 --- a/mia/system/wonderswan-color.cpp +++ b/mia/system/wonderswan-color.cpp @@ -1,10 +1,10 @@ struct WonderSwanColor : System { auto name() -> string override { return "WonderSwan Color"; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; }; -auto WonderSwanColor::load(string location) -> bool { +auto WonderSwanColor::load(string location) -> LoadResult { this->location = locate(); pak = new vfs::directory; pak->append("boot.rom", Resource::WonderSwanColor::Boot); @@ -12,7 +12,7 @@ auto WonderSwanColor::load(string location) -> bool { Pak::load("save.eeprom", ".eeprom"); - return true; + return LoadResult(successful); } auto WonderSwanColor::save(string location) -> bool { diff --git a/mia/system/wonderswan.cpp b/mia/system/wonderswan.cpp index 4dc0707be9..64edc39ea5 100644 --- a/mia/system/wonderswan.cpp +++ b/mia/system/wonderswan.cpp @@ -1,10 +1,10 @@ struct WonderSwan : System { auto name() -> string override { return "WonderSwan"; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; }; -auto WonderSwan::load(string location) -> bool { +auto WonderSwan::load(string location) -> LoadResult { this->location = locate(); pak = new vfs::directory; pak->append("boot.rom", Resource::WonderSwan::Boot); @@ -12,7 +12,7 @@ auto WonderSwan::load(string location) -> bool { Pak::load("save.eeprom", ".eeprom"); - return true; + return LoadResult(successful); } auto WonderSwan::save(string location) -> bool { diff --git a/mia/system/zx-spectrum-128.cpp b/mia/system/zx-spectrum-128.cpp index 099846ae8e..7f004b5b23 100644 --- a/mia/system/zx-spectrum-128.cpp +++ b/mia/system/zx-spectrum-128.cpp @@ -1,15 +1,15 @@ struct ZXSpectrum128 : System { auto name() -> string override { return "ZX Spectrum 128"; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; }; -auto ZXSpectrum128::load(string location) -> bool { +auto ZXSpectrum128::load(string location) -> LoadResult { this->location = locate(); pak = new vfs::directory; pak->append("bios.rom", Resource::ZXSpectrum128::BIOS); pak->append("sub.rom", Resource::ZXSpectrum128::Sub); - return true; + return LoadResult(successful); } auto ZXSpectrum128::save(string location) -> bool { diff --git a/mia/system/zx-spectrum.cpp b/mia/system/zx-spectrum.cpp index c28f18d672..58805087cc 100644 --- a/mia/system/zx-spectrum.cpp +++ b/mia/system/zx-spectrum.cpp @@ -1,14 +1,14 @@ struct ZXSpectrum : System { auto name() -> string override { return "ZX Spectrum"; } - auto load(string location) -> bool override; + auto load(string location) -> LoadResult override; auto save(string location) -> bool override; }; -auto ZXSpectrum::load(string location) -> bool { +auto ZXSpectrum::load(string location) -> LoadResult { this->location = locate(); pak = new vfs::directory; pak->append("bios.rom", Resource::ZXSpectrum::BIOS); - return true; + return LoadResult(successful); } auto ZXSpectrum::save(string location) -> bool {