diff --git a/source/CardManager.cpp b/source/CardManager.cpp index 979483e0..789f061c 100644 --- a/source/CardManager.cpp +++ b/source/CardManager.cpp @@ -36,6 +36,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "Disk.h" #include "FourPlay.h" #include "MouseInterface.h" +#include "SAM.h" #include "SerialComms.h" #include "SNESMAX.h" @@ -83,7 +84,7 @@ void CardManager::InsertInternal(UINT slot, SS_CARDTYPE type) m_slot[slot] = new DummyCard(type); break; case CT_SAM: - m_slot[slot] = new DummyCard(type); + m_slot[slot] = new SAMCard(slot); break; case CT_Uthernet: m_slot[slot] = new DummyCard(type); diff --git a/source/CardManager.h b/source/CardManager.h index 909b89b0..3c808975 100644 --- a/source/CardManager.h +++ b/source/CardManager.h @@ -33,10 +33,16 @@ public: SS_CARDTYPE QuerySlot(UINT slot) { _ASSERT(slotQueryType(); } Card& GetRef(UINT slot) { - SS_CARDTYPE t=QuerySlot(slot); _ASSERT((t==CT_SSC || t==CT_MouseInterface || t==CT_Disk2 || t == CT_FourPlay || t == CT_SNESMAX) && m_slot[slot]); + SS_CARDTYPE t=QuerySlot(slot); + _ASSERT((t==CT_SSC || t==CT_MouseInterface || t==CT_Disk2 || t == CT_FourPlay || t == CT_SNESMAX || t == CT_SAM) && m_slot[slot]); return *m_slot[slot]; } - Card* GetObj(UINT slot) { SS_CARDTYPE t=QuerySlot(slot); _ASSERT(t==CT_SSC || t==CT_MouseInterface || t==CT_Disk2 || t == CT_FourPlay || t == CT_SNESMAX); return m_slot[slot]; } + Card* GetObj(UINT slot) + { + SS_CARDTYPE t=QuerySlot(slot); + _ASSERT(t==CT_SSC || t==CT_MouseInterface || t==CT_Disk2 || t == CT_FourPlay || t == CT_SNESMAX || t == CT_SAM); + return m_slot[slot]; + } void InsertAux(SS_CARDTYPE type); void RemoveAux(void); diff --git a/source/Memory.cpp b/source/Memory.cpp index 3defaa3e..ec077b72 100644 --- a/source/Memory.cpp +++ b/source/Memory.cpp @@ -1771,7 +1771,7 @@ void MemInitializeIO(void) } else if (GetCardMgr().QuerySlot(SLOT5) == CT_SAM) { - ConfigureSAM(pCxRomPeripheral, SLOT5); // $C500 : SAM card + dynamic_cast(GetCardMgr().GetRef(SLOT5)).InitializeIO(pCxRomPeripheral, SLOT5); } else if (GetCardMgr().QuerySlot(SLOT5) == CT_FourPlay) { diff --git a/source/SAM.cpp b/source/SAM.cpp index 8394d3b5..aefae2b8 100644 --- a/source/SAM.cpp +++ b/source/SAM.cpp @@ -35,13 +35,14 @@ #include "SAM.h" #include "Memory.h" #include "Speaker.h" +#include "YamlHelper.h" // // Write 8 bit data to speaker. Emulates a "SAM" speech card DAC // -static BYTE __stdcall IOWrite_SAM(WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG nExecutedCycles) +BYTE __stdcall SAMCard::IOWrite(WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG nExecutedCycles) { // Emulate audio from a SAM / 8 bit DAC card // Only supportable if AppleWin is using WAVE output @@ -86,7 +87,33 @@ static BYTE __stdcall IOWrite_SAM(WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG return res; } -void ConfigureSAM(LPBYTE pCxRomPeripheral, UINT uSlot) +void SAMCard::InitializeIO(LPBYTE pCxRomPeripheral, UINT slot) { - RegisterIoHandler(uSlot, IO_Null, IOWrite_SAM, IO_Null, IO_Null, NULL, NULL); + RegisterIoHandler(slot, IO_Null, IOWrite, IO_Null, IO_Null, NULL, NULL); +} + +//=========================================================================== + +static const UINT kUNIT_VERSION = 1; + +std::string SAMCard::GetSnapshotCardName(void) +{ + static const std::string name("SAM"); + return name; +} + +void SAMCard::SaveSnapshot(YamlSaveHelper& yamlSaveHelper) +{ + YamlSaveHelper::Slot slot(yamlSaveHelper, GetSnapshotCardName(), m_slot, kUNIT_VERSION); + + YamlSaveHelper::Label unit(yamlSaveHelper, "%s: null\n", SS_YAML_KEY_STATE); + // NB. No state for this card +} + +bool SAMCard::LoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT slot, UINT version) +{ + if (version < 1 || version > kUNIT_VERSION) + throw std::string("Card: wrong version"); + + return true; } diff --git a/source/SAM.h b/source/SAM.h index 291ac5c0..82ac4f79 100644 --- a/source/SAM.h +++ b/source/SAM.h @@ -1,3 +1,28 @@ #pragma once -void ConfigureSAM(LPBYTE pCxRomPeripheral, UINT uSlot); +#include "Card.h" + +class SAMCard : public Card +{ +public: + SAMCard(UINT slot) : + Card(CT_SAM), + m_slot(slot) + { + } + virtual ~SAMCard(void) {} + + virtual void Init(void) {}; + virtual void Reset(const bool powerCycle) {}; + + void InitializeIO(LPBYTE pCxRomPeripheral, UINT slot); + + static BYTE __stdcall IOWrite(WORD pc, WORD addr, BYTE bWrite, BYTE value, ULONG nExecutedCycles); + + static std::string GetSnapshotCardName(void); + void SaveSnapshot(class YamlSaveHelper& yamlSaveHelper); + bool LoadSnapshot(class YamlLoadHelper& yamlLoadHelper, UINT slot, UINT version); + +private: + UINT m_slot; +}; diff --git a/source/SaveState.cpp b/source/SaveState.cpp index 8cef0499..e2aca71f 100644 --- a/source/SaveState.cpp +++ b/source/SaveState.cpp @@ -45,6 +45,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "MouseInterface.h" #include "ParallelPrinter.h" #include "Pravets.h" +#include "SAM.h" #include "SerialComms.h" #include "SNESMAX.h" #include "Speaker.h" @@ -361,6 +362,12 @@ static void ParseSlots(YamlLoadHelper& yamlLoadHelper, UINT unitVersion) GetCardMgr().Insert(slot, type); bRes = Phasor_LoadSnapshot(yamlLoadHelper, slot, cardVersion); } + else if (card == SAMCard::GetSnapshotCardName()) + { + type = CT_SAM; + GetCardMgr().Insert(slot, type); + bRes = dynamic_cast(GetCardMgr().GetRef(slot)).LoadSnapshot(yamlLoadHelper, slot, cardVersion); + } else if (card == Disk2InterfaceCard::GetSnapshotCardName()) { type = CT_Disk2; @@ -626,6 +633,9 @@ void Snapshot_SaveState(void) if (GetCardMgr().QuerySlot(SLOT4) == CT_Phasor) Phasor_SaveSnapshot(yamlSaveHelper, SLOT4); + if (GetCardMgr().QuerySlot(SLOT5) == CT_SAM) + dynamic_cast(GetCardMgr().GetRef(SLOT5)).SaveSnapshot(yamlSaveHelper); + if (GetCardMgr().QuerySlot(SLOT5) == CT_Disk2) dynamic_cast(GetCardMgr().GetRef(SLOT5)).SaveSnapshot(yamlSaveHelper);