diff --git a/source/Card.cpp b/source/Card.cpp index 723b7ed7..7be26e06 100644 --- a/source/Card.cpp +++ b/source/Card.cpp @@ -25,7 +25,44 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "Mockingboard.h" #include "ParallelPrinter.h" #include "z80emu.h" +#include "FourPlay.h" +#include "Joystick.h" +#include "LanguageCard.h" +#include "MouseInterface.h" +#include "SAM.h" +#include "SerialComms.h" +#include "SNESMAX.h" +#include "VidHD.h" +#include + +void Card::ThrowErrorInvalidSlot() +{ + ThrowErrorInvalidSlot(m_type, m_slot); +} + +void Card::ThrowErrorInvalidSlot(SS_CARDTYPE type, UINT slot) +{ + std::ostringstream msg; + msg << "The card '" << GetCardName(type); + msg << "' is not allowed in Slot " << slot << "."; + + throw std::runtime_error(msg.str()); +} + +void Card::ThrowErrorInvalidVersion(UINT version) +{ + ThrowErrorInvalidVersion(m_type, version); +} + +void Card::ThrowErrorInvalidVersion(SS_CARDTYPE type, UINT version) +{ + std::ostringstream msg; + msg << "Version " << version; + msg << " is not supported for card '" << GetCardName(type) << "'."; + + throw std::runtime_error(msg.str()); +} void DummyCard::InitializeIO(LPBYTE pCxRomPeripheral) { @@ -110,3 +147,121 @@ bool DummyCard::LoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT version) } return false; } + +std::string Card::GetCardName(void) +{ + return GetCardName(m_type); +} + +std::string Card::GetCardName(const SS_CARDTYPE cardType) +{ + switch (cardType) + { + case CT_Empty: + return "Empty"; + case CT_LanguageCard: + return LanguageCardSlot0::GetSnapshotCardName(); + case CT_Saturn128K: + return Saturn128K::GetSnapshotCardName(); + case CT_Disk2: + return Disk2InterfaceCard::GetSnapshotCardName(); + case CT_SSC: + return CSuperSerialCard::GetSnapshotCardName(); + case CT_MockingboardC: + return MB_GetSnapshotCardName(); + case CT_GenericPrinter: + return Printer_GetSnapshotCardName(); + case CT_GenericHDD: + return HarddiskInterfaceCard::GetSnapshotCardName(); + case CT_GenericClock: + return "Clock"; + case CT_MouseInterface: + return CMouseInterface::GetSnapshotCardName(); + case CT_Z80: + return Z80_GetSnapshotCardName(); + case CT_Phasor: + return Phasor_GetSnapshotCardName(); + case CT_Echo: + return "Echo"; + case CT_SAM: + return SAMCard::GetSnapshotCardName(); + case CT_Uthernet: + return tfe_GetSnapshotCardName(); + case CT_FourPlay: + return FourPlayCard::GetSnapshotCardName(); + case CT_SNESMAX: + return SNESMAXCard::GetSnapshotCardName(); + case CT_VidHD: + return VidHDCard::GetSnapshotCardName(); + default: + return "Unknown"; + } +} + +SS_CARDTYPE Card::GetCardType(const std::string & card) +{ + if (card == Printer_GetSnapshotCardName()) + { + return CT_GenericPrinter; + } + else if (card == CSuperSerialCard::GetSnapshotCardName()) + { + return CT_SSC; + } + else if (card == CMouseInterface::GetSnapshotCardName()) + { + return CT_MouseInterface; + } + else if (card == Z80_GetSnapshotCardName()) + { + return CT_Z80; + } + else if (card == MB_GetSnapshotCardName()) + { + return CT_MockingboardC; + } + else if (card == Phasor_GetSnapshotCardName()) + { + return CT_Phasor; + } + else if (card == SAMCard::GetSnapshotCardName()) + { + return CT_SAM; + } + else if (card == Disk2InterfaceCard::GetSnapshotCardName()) + { + return CT_Disk2; + } + else if (card == HarddiskInterfaceCard::GetSnapshotCardName()) + { + return CT_GenericHDD; + } + else if (card == tfe_GetSnapshotCardName()) + { + return CT_Uthernet; + } + else if (card == LanguageCardSlot0::GetSnapshotCardName()) + { + return CT_LanguageCard; + } + else if (card == Saturn128K::GetSnapshotCardName()) + { + return CT_Saturn128K; + } + else if (card == FourPlayCard::GetSnapshotCardName()) + { + return CT_FourPlay; + } + else if (card == SNESMAXCard::GetSnapshotCardName()) + { + return CT_SNESMAX; + } + else if (card == VidHDCard::GetSnapshotCardName()) + { + return CT_VidHD; + } + else + { + throw std::runtime_error("Slots: Unknown card: " + card); // todo: don't throw - just ignore & continue + } +} \ No newline at end of file diff --git a/source/Card.h b/source/Card.h index f9707a1e..47be1f99 100644 --- a/source/Card.h +++ b/source/Card.h @@ -46,9 +46,20 @@ public: SS_CARDTYPE QueryType(void) { return m_type; } + std::string GetCardName(void); + static std::string GetCardName(const SS_CARDTYPE cardType); + static SS_CARDTYPE GetCardType(const std::string & card); + + // static versions for non-Card cards + static void ThrowErrorInvalidSlot(SS_CARDTYPE type, UINT slot); + static void ThrowErrorInvalidVersion(SS_CARDTYPE type, UINT version); + protected: UINT m_slot; + void ThrowErrorInvalidSlot(); + void ThrowErrorInvalidVersion(UINT version); + private: SS_CARDTYPE m_type; }; diff --git a/source/Configuration/PropertySheetHelper.cpp b/source/Configuration/PropertySheetHelper.cpp index 426c0597..809f41ec 100644 --- a/source/Configuration/PropertySheetHelper.cpp +++ b/source/Configuration/PropertySheetHelper.cpp @@ -494,63 +494,22 @@ std::string CPropertySheetHelper::GetSlot(const UINT uSlot) { if (NewCardType == CT_Empty) { - strMsg += GetCardName(OldCardType); + strMsg += Card::GetCardName(OldCardType); strMsg += " card removed\n"; } else { - strMsg += GetCardName(NewCardType); + strMsg += Card::GetCardName(NewCardType); strMsg += " card added\n"; } } else { - strMsg += GetCardName(OldCardType); + strMsg += Card::GetCardName(OldCardType); strMsg += " card removed & "; - strMsg += GetCardName(NewCardType); + strMsg += Card::GetCardName(NewCardType); strMsg += " card added\n"; } return strMsg; } - -std::string CPropertySheetHelper::GetCardName(const SS_CARDTYPE CardType) -{ - switch (CardType) - { - case CT_Empty: - return "Empty"; - case CT_Disk2: // Apple Disk][ - return "Disk]["; - case CT_SSC: // Apple Super Serial Card - return "Super Serial"; - case CT_MockingboardC: // Soundcard - return "Mockingboard"; - case CT_GenericPrinter: - return "Printer"; - case CT_GenericHDD: // Hard disk - return "Hard Disk"; - case CT_GenericClock: - return "Clock"; - case CT_MouseInterface: - return "Mouse"; - case CT_Z80: - return "CP/M"; - case CT_Phasor: // Soundcard - return "Phasor"; - case CT_Echo: // Soundcard - return "Echo"; - case CT_SAM: // Soundcard: Software Automated Mouth - return "SAM"; - case CT_Uthernet: - return "Uthernet"; - case CT_FourPlay: - return "4Play"; - case CT_SNESMAX: - return "SNES MAX"; - case CT_VidHD: - return "VidHD"; - default: - return "Unknown"; - } -} diff --git a/source/Configuration/PropertySheetHelper.h b/source/Configuration/PropertySheetHelper.h index 9cf26465..63873462 100644 --- a/source/Configuration/PropertySheetHelper.h +++ b/source/Configuration/PropertySheetHelper.h @@ -48,7 +48,6 @@ private: void ApplyNewConfig(void); void RestoreCurrentConfig(void); std::string GetSlot(const UINT uSlot); - std::string GetCardName(const SS_CARDTYPE CardType); PAGETYPE m_LastPage; UINT32 m_bmPages; diff --git a/source/Disk.cpp b/source/Disk.cpp index 620b031a..ea0f88b8 100644 --- a/source/Disk.cpp +++ b/source/Disk.cpp @@ -61,7 +61,7 @@ Disk2InterfaceCard::Disk2InterfaceCard(UINT slot) : Card(CT_Disk2, slot) { if (m_slot != 5 && m_slot != 6) // fixme - throw std::runtime_error("Card: wrong slot"); + ThrowErrorInvalidSlot(); ResetSwitches(); @@ -2208,7 +2208,7 @@ void Disk2InterfaceCard::LoadSnapshotDriveUnit(YamlLoadHelper& yamlLoadHelper, U bool Disk2InterfaceCard::LoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT version) { if (version < 1 || version > kUNIT_VERSION) - throw std::runtime_error("Card: wrong version"); + ThrowErrorInvalidVersion(version); m_currDrive = yamlLoadHelper.LoadUint(SS_YAML_KEY_CURRENT_DRIVE); m_magnetStates = yamlLoadHelper.LoadUint(SS_YAML_KEY_PHASES); diff --git a/source/FourPlay.cpp b/source/FourPlay.cpp index 82e90846..2a3783ca 100644 --- a/source/FourPlay.cpp +++ b/source/FourPlay.cpp @@ -149,7 +149,7 @@ void FourPlayCard::SaveSnapshot(YamlSaveHelper& yamlSaveHelper) bool FourPlayCard::LoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT version) { if (version < 1 || version > kUNIT_VERSION) - throw std::runtime_error("Card: wrong version"); + ThrowErrorInvalidVersion(version); return true; } diff --git a/source/Harddisk.cpp b/source/Harddisk.cpp index fb834f50..0fdb4d0c 100644 --- a/source/Harddisk.cpp +++ b/source/Harddisk.cpp @@ -131,7 +131,7 @@ HarddiskInterfaceCard::HarddiskInterfaceCard(UINT slot) : Card(CT_GenericHDD, slot) { if (m_slot != SLOT7) // fixme - throw std::runtime_error("Card: wrong slot"); + ThrowErrorInvalidSlot(); m_unitNum = HARDDISK_1 << 7; // b7=unit @@ -888,7 +888,7 @@ bool HarddiskInterfaceCard::LoadSnapshotHDDUnit(YamlLoadHelper& yamlLoadHelper, bool HarddiskInterfaceCard::LoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT version) { if (version < 1 || version > kUNIT_VERSION) - throw std::runtime_error("Card: wrong version"); + ThrowErrorInvalidVersion(version); if (version <= 2 && (regs.pc >> 8) == (0xC0|m_slot)) throw std::runtime_error("HDD card: 6502 is running old HDD firmware"); diff --git a/source/LanguageCard.cpp b/source/LanguageCard.cpp index 1c8a57e5..7e14f8a0 100644 --- a/source/LanguageCard.cpp +++ b/source/LanguageCard.cpp @@ -48,7 +48,7 @@ LanguageCardUnit::LanguageCardUnit(SS_CARDTYPE type, UINT slot) : m_uLastRamWrite(0) { if (m_slot != LanguageCardUnit::kSlot0) - throw std::runtime_error("Language Card: wrong slot"); // throws to the top-level catch-handler, and shuts down + ThrowErrorInvalidSlot(); SetMemMainLanguageCard(NULL, true); } @@ -221,7 +221,7 @@ void LanguageCardSlot0::SaveSnapshot(YamlSaveHelper& yamlSaveHelper) bool LanguageCardSlot0::LoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT version) { if (version != kUNIT_LANGUAGECARD_VER) - throw std::runtime_error("Card: wrong version"); + ThrowErrorInvalidVersion(version); // "State" LoadLCState(yamlLoadHelper); @@ -419,7 +419,7 @@ void Saturn128K::SaveSnapshot(YamlSaveHelper& yamlSaveHelper) bool Saturn128K::LoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT version) { if (version != kUNIT_SATURN_VER) - throw std::runtime_error("Card: wrong version"); + ThrowErrorInvalidVersion(version); // "State" LoadLCState(yamlLoadHelper); diff --git a/source/Mockingboard.cpp b/source/Mockingboard.cpp index a35d8e1e..6dd9f595 100644 --- a/source/Mockingboard.cpp +++ b/source/Mockingboard.cpp @@ -1968,10 +1968,10 @@ static void LoadSnapshotSY6522(YamlLoadHelper& yamlLoadHelper, SY6522& sy6522, U bool MB_LoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT slot, UINT version) { if (slot != 4 && slot != 5) // fixme - throw std::runtime_error("Card: wrong slot"); + Card::ThrowErrorInvalidSlot(CT_MockingboardC, slot); if (version < 1 || version > kUNIT_VERSION) - throw std::runtime_error("Card: wrong version"); + Card::ThrowErrorInvalidVersion(CT_MockingboardC, version); AY8910UpdateSetCycles(); @@ -2091,10 +2091,10 @@ void Phasor_SaveSnapshot(YamlSaveHelper& yamlSaveHelper, const UINT uSlot) bool Phasor_LoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT slot, UINT version) { if (slot != 4) // fixme - throw std::runtime_error("Card: wrong slot"); + Card::ThrowErrorInvalidSlot(CT_Phasor, slot); if (version < 1 || version > kUNIT_VERSION) - throw std::runtime_error("Card: wrong version"); + Card::ThrowErrorInvalidVersion(CT_Phasor, version); if (version < 6) yamlLoadHelper.LoadUint(SS_YAML_KEY_PHASOR_CLOCK_SCALE_FACTOR); // Consume redundant data diff --git a/source/MouseInterface.cpp b/source/MouseInterface.cpp index b902be4a..ecffe888 100644 --- a/source/MouseInterface.cpp +++ b/source/MouseInterface.cpp @@ -139,7 +139,7 @@ CMouseInterface::CMouseInterface(UINT slot) : m_syncEvent(slot, 0, SyncEventCallback) // use slot# as "unique" id for MouseInterfaces { if (m_slot != 4) // fixme - throw std::runtime_error("Card: wrong slot"); + ThrowErrorInvalidSlot(); m_6821.SetListenerB( this, M6821_Listener_B ); m_6821.SetListenerA( this, M6821_Listener_A ); @@ -716,7 +716,7 @@ void CMouseInterface::LoadSnapshotMC6821(YamlLoadHelper& yamlLoadHelper, std::st bool CMouseInterface::LoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT version) { if (version != 1) - throw std::runtime_error("Card: wrong version"); + ThrowErrorInvalidVersion(version); LoadSnapshotMC6821(yamlLoadHelper, SS_YAML_KEY_MC6821); diff --git a/source/ParallelPrinter.cpp b/source/ParallelPrinter.cpp index 38fff52c..18429666 100644 --- a/source/ParallelPrinter.cpp +++ b/source/ParallelPrinter.cpp @@ -230,10 +230,10 @@ void Printer_SaveSnapshot(class YamlSaveHelper& yamlSaveHelper, const UINT uSlot bool Printer_LoadSnapshot(class YamlLoadHelper& yamlLoadHelper, UINT slot, UINT version) { if (slot != 1) // fixme - throw std::runtime_error("Card: wrong slot"); + Card::ThrowErrorInvalidSlot(CT_GenericPrinter, slot); if (version != 1) - throw std::runtime_error("Card: wrong version"); + Card::ThrowErrorInvalidVersion(CT_GenericPrinter, version); inactivity = yamlLoadHelper.LoadUint(SS_YAML_KEY_INACTIVITY); g_PrinterIdleLimit = yamlLoadHelper.LoadUint(SS_YAML_KEY_IDLELIMIT); diff --git a/source/SAM.cpp b/source/SAM.cpp index 4a20c56c..b78b93f3 100644 --- a/source/SAM.cpp +++ b/source/SAM.cpp @@ -113,7 +113,7 @@ void SAMCard::SaveSnapshot(YamlSaveHelper& yamlSaveHelper) bool SAMCard::LoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT version) { if (version < 1 || version > kUNIT_VERSION) - throw std::runtime_error("Card: wrong version"); + ThrowErrorInvalidVersion(version); return true; } diff --git a/source/SNESMAX.cpp b/source/SNESMAX.cpp index ede7f12b..7dc9f70d 100644 --- a/source/SNESMAX.cpp +++ b/source/SNESMAX.cpp @@ -230,7 +230,7 @@ void SNESMAXCard::SaveSnapshot(YamlSaveHelper& yamlSaveHelper) bool SNESMAXCard::LoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT version) { if (version < 1 || version > kUNIT_VERSION) - throw std::runtime_error("Card: wrong version"); + ThrowErrorInvalidVersion(version); m_buttonIndex = yamlLoadHelper.LoadUint(SS_YAML_KEY_BUTTON_INDEX); diff --git a/source/SaveState.cpp b/source/SaveState.cpp index a217608b..7d99fa63 100644 --- a/source/SaveState.cpp +++ b/source/SaveState.cpp @@ -33,25 +33,14 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "Interface.h" #include "CardManager.h" -#include "CPU.h" #include "Debug.h" -#include "Disk.h" -#include "FourPlay.h" #include "Joystick.h" #include "Keyboard.h" -#include "LanguageCard.h" #include "Memory.h" #include "Mockingboard.h" -#include "MouseInterface.h" -#include "ParallelPrinter.h" #include "Pravets.h" -#include "SAM.h" -#include "SerialComms.h" -#include "SNESMAX.h" #include "Speaker.h" #include "Speech.h" -#include "VidHD.h" -#include "z80emu.h" #include "Configuration/Config.h" #include "Configuration/IPropertySheet.h" @@ -317,74 +306,9 @@ static void ParseSlots(YamlLoadHelper& yamlLoadHelper, UINT unitVersion) if (!yamlLoadHelper.GetSubMap(std::string(SS_YAML_KEY_STATE), true)) // NB. For some cards, State can be null throw std::runtime_error(SS_YAML_KEY_UNIT ": Expected sub-map name: " SS_YAML_KEY_STATE); - SS_CARDTYPE type = CT_Empty; + SS_CARDTYPE type = Card::GetCardType(card); bool bRes = false; - if (card == Printer_GetSnapshotCardName()) - { - type = CT_GenericPrinter; - } - else if (card == CSuperSerialCard::GetSnapshotCardName()) - { - type = CT_SSC; - } - else if (card == CMouseInterface::GetSnapshotCardName()) - { - type = CT_MouseInterface; - } - else if (card == Z80_GetSnapshotCardName()) - { - type = CT_Z80; - } - else if (card == MB_GetSnapshotCardName()) - { - type = CT_MockingboardC; - } - else if (card == Phasor_GetSnapshotCardName()) - { - type = CT_Phasor; - } - else if (card == SAMCard::GetSnapshotCardName()) - { - type = CT_SAM; - } - else if (card == Disk2InterfaceCard::GetSnapshotCardName()) - { - type = CT_Disk2; - } - else if (card == HarddiskInterfaceCard::GetSnapshotCardName()) - { - type = CT_GenericHDD; - } - else if (card == tfe_GetSnapshotCardName()) - { - type = CT_Uthernet; - } - else if (card == LanguageCardSlot0::GetSnapshotCardName()) - { - type = CT_LanguageCard; - } - else if (card == Saturn128K::GetSnapshotCardName()) - { - type = CT_Saturn128K; - } - else if (card == FourPlayCard::GetSnapshotCardName()) - { - type = CT_FourPlay; - } - else if (card == SNESMAXCard::GetSnapshotCardName()) - { - type = CT_SNESMAX; - } - else if (card == VidHDCard::GetSnapshotCardName()) - { - type = CT_VidHD; - } - else - { - throw std::runtime_error("Slots: Unknown card: " + card); // todo: don't throw - just ignore & continue - } - if (slot == 0) { SetExpansionMemType(type); // calls GetCardMgr().Insert() & InsertAux() diff --git a/source/SerialComms.cpp b/source/SerialComms.cpp index ed49f66a..2df721f6 100644 --- a/source/SerialComms.cpp +++ b/source/SerialComms.cpp @@ -72,7 +72,7 @@ CSuperSerialCard::CSuperSerialCard(UINT slot) : m_pExpansionRom(NULL) { if (m_slot != 2) // fixme - throw std::runtime_error("Card: wrong slot"); + ThrowErrorInvalidSlot(); m_dwSerialPortItem = 0; @@ -1482,7 +1482,7 @@ void CSuperSerialCard::LoadSnapshotDIPSW(YamlLoadHelper& yamlLoadHelper, std::st bool CSuperSerialCard::LoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT version) { if (version < 1 || version > kUNIT_VERSION) - throw std::runtime_error("Card: wrong version"); + ThrowErrorInvalidVersion(version); LoadSnapshotDIPSW(yamlLoadHelper, SS_YAML_KEY_DIPSWDEFAULT, m_DIPSWDefault); LoadSnapshotDIPSW(yamlLoadHelper, SS_YAML_KEY_DIPSWCURRENT, m_DIPSWCurrent); diff --git a/source/Tfe/tfe.cpp b/source/Tfe/tfe.cpp index 95a05947..c0688284 100644 --- a/source/Tfe/tfe.cpp +++ b/source/Tfe/tfe.cpp @@ -1507,10 +1507,10 @@ void tfe_SaveSnapshot(class YamlSaveHelper& yamlSaveHelper, const UINT uSlot) bool tfe_LoadSnapshot(class YamlLoadHelper& yamlLoadHelper, UINT slot, UINT version) { if (slot != SLOT3) // fixme - throw std::runtime_error("Card: wrong slot"); + Card::ThrowErrorInvalidSlot(CT_Uthernet, slot); if (version < 1 || version > kUNIT_VERSION) - throw std::runtime_error("Card: wrong version"); + Card::ThrowErrorInvalidVersion(CT_Uthernet, version); tfe_enabled = yamlLoadHelper.LoadBool(SS_YAML_KEY_ENABLED) ? true : false; set_tfe_interface(yamlLoadHelper.LoadString(SS_YAML_KEY_NETWORK_INTERFACE)); diff --git a/source/VidHD.cpp b/source/VidHD.cpp index 1eb8e758..14447028 100644 --- a/source/VidHD.cpp +++ b/source/VidHD.cpp @@ -219,7 +219,7 @@ void VidHDCard::SaveSnapshot(YamlSaveHelper& yamlSaveHelper) bool VidHDCard::LoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT version) { if (version < 1 || version > kUNIT_VERSION) - throw std::runtime_error("Card: wrong version"); + ThrowErrorInvalidVersion(version); m_memMode = yamlLoadHelper.LoadUint(SS_YAML_KEY_MEMORYMODE); m_SCREENCOLOR = yamlLoadHelper.LoadUint(SS_YAML_KEY_SCREEN_COLOR); diff --git a/source/Z80VICE/z80.cpp b/source/Z80VICE/z80.cpp index 62026d74..44800867 100644 --- a/source/Z80VICE/z80.cpp +++ b/source/Z80VICE/z80.cpp @@ -6525,10 +6525,10 @@ void Z80_SaveSnapshot(class YamlSaveHelper& yamlSaveHelper, const UINT uSlot) bool Z80_LoadSnapshot(class YamlLoadHelper& yamlLoadHelper, UINT uSlot, UINT version) { if (uSlot != 4 && uSlot != 5) // fixme - throw std::runtime_error("Card: wrong slot"); + Card::ThrowErrorInvalidSlot(CT_Z80, uSlot); if (version != 1) - throw std::runtime_error("Card: wrong version"); + Card::ThrowErrorInvalidVersion(CT_Z80, version); reg_a = yamlLoadHelper.LoadUint(SS_YAML_KEY_REGA); reg_b = yamlLoadHelper.LoadUint(SS_YAML_KEY_REGB);