2019-12-19 19:42:30 +00:00
|
|
|
/*
|
|
|
|
AppleWin : An Apple //e emulator for Windows
|
|
|
|
|
|
|
|
Copyright (C) 1994-1996, Michael O'Brien
|
|
|
|
Copyright (C) 1999-2001, Oliver Schmidt
|
|
|
|
Copyright (C) 2002-2005, Tom Charlesworth
|
|
|
|
Copyright (C) 2006-2019, Tom Charlesworth, Michael Pohoreski, Nick Westgate
|
|
|
|
|
|
|
|
AppleWin is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
AppleWin is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with AppleWin; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Description: Card Manager
|
|
|
|
*
|
|
|
|
* Author: Various
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "StdAfx.h"
|
|
|
|
|
|
|
|
#include "CardManager.h"
|
2020-11-26 21:50:06 +00:00
|
|
|
#include "Core.h"
|
2021-09-17 19:43:10 +00:00
|
|
|
#include "Registry.h"
|
2019-12-19 19:42:30 +00:00
|
|
|
|
|
|
|
#include "Disk.h"
|
2021-09-10 12:57:55 +00:00
|
|
|
#include "FourPlay.h"
|
2021-11-01 20:12:42 +00:00
|
|
|
#include "Harddisk.h"
|
2019-12-19 19:42:30 +00:00
|
|
|
#include "MouseInterface.h"
|
2021-09-18 10:55:29 +00:00
|
|
|
#include "SAM.h"
|
2019-12-19 19:42:30 +00:00
|
|
|
#include "SerialComms.h"
|
2021-09-10 12:57:55 +00:00
|
|
|
#include "SNESMAX.h"
|
2021-11-30 21:41:02 +00:00
|
|
|
#include "VidHD.h"
|
2021-12-11 15:26:09 +00:00
|
|
|
#include "LanguageCard.h"
|
|
|
|
#include "Memory.h"
|
2019-12-19 19:42:30 +00:00
|
|
|
|
2021-09-17 19:43:10 +00:00
|
|
|
void CardManager::InsertInternal(UINT slot, SS_CARDTYPE type)
|
2019-12-19 19:42:30 +00:00
|
|
|
{
|
|
|
|
RemoveInternal(slot);
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
2021-09-17 19:43:10 +00:00
|
|
|
case CT_Empty:
|
2021-11-11 21:45:55 +00:00
|
|
|
m_slot[slot] = new EmptyCard(slot);
|
2021-09-17 19:43:10 +00:00
|
|
|
break;
|
2019-12-19 19:42:30 +00:00
|
|
|
case CT_Disk2:
|
2020-05-25 19:21:36 +00:00
|
|
|
m_slot[slot] = new Disk2InterfaceCard(slot);
|
2019-12-19 19:42:30 +00:00
|
|
|
break;
|
|
|
|
case CT_SSC:
|
|
|
|
_ASSERT(m_pSSC == NULL);
|
|
|
|
if (m_pSSC) break; // Only support one SSC
|
2020-05-25 19:21:36 +00:00
|
|
|
m_slot[slot] = m_pSSC = new CSuperSerialCard(slot);
|
2019-12-19 19:42:30 +00:00
|
|
|
break;
|
|
|
|
case CT_MockingboardC:
|
2021-11-01 21:01:28 +00:00
|
|
|
m_slot[slot] = new DummyCard(type, slot);
|
2019-12-19 19:42:30 +00:00
|
|
|
break;
|
|
|
|
case CT_GenericPrinter:
|
2021-11-01 21:01:28 +00:00
|
|
|
m_slot[slot] = new DummyCard(type, slot);
|
2019-12-19 19:42:30 +00:00
|
|
|
break;
|
|
|
|
case CT_GenericHDD:
|
2021-11-01 20:12:42 +00:00
|
|
|
m_slot[slot] = new HarddiskInterfaceCard(slot);
|
2019-12-19 19:42:30 +00:00
|
|
|
break;
|
|
|
|
case CT_GenericClock:
|
2021-11-01 21:01:28 +00:00
|
|
|
m_slot[slot] = new DummyCard(type, slot);
|
2019-12-19 19:42:30 +00:00
|
|
|
break;
|
|
|
|
case CT_MouseInterface:
|
|
|
|
_ASSERT(m_pMouseCard == NULL);
|
|
|
|
if (m_pMouseCard) break; // Only support one Mouse card
|
|
|
|
m_slot[slot] = m_pMouseCard = new CMouseInterface(slot);
|
|
|
|
break;
|
|
|
|
case CT_Z80:
|
2021-11-01 21:01:28 +00:00
|
|
|
m_slot[slot] = new DummyCard(type, slot);
|
2019-12-19 19:42:30 +00:00
|
|
|
break;
|
|
|
|
case CT_Phasor:
|
2021-11-01 21:01:28 +00:00
|
|
|
m_slot[slot] = new DummyCard(type, slot);
|
2019-12-19 19:42:30 +00:00
|
|
|
break;
|
|
|
|
case CT_Echo:
|
2021-11-01 21:01:28 +00:00
|
|
|
m_slot[slot] = new DummyCard(type, slot);
|
2019-12-19 19:42:30 +00:00
|
|
|
break;
|
|
|
|
case CT_SAM:
|
2021-09-18 10:55:29 +00:00
|
|
|
m_slot[slot] = new SAMCard(slot);
|
2019-12-19 19:42:30 +00:00
|
|
|
break;
|
|
|
|
case CT_Uthernet:
|
2021-11-01 21:01:28 +00:00
|
|
|
m_slot[slot] = new DummyCard(type, slot);
|
2019-12-19 19:42:30 +00:00
|
|
|
break;
|
2021-09-10 12:57:55 +00:00
|
|
|
case CT_FourPlay:
|
|
|
|
m_slot[slot] = new FourPlayCard(slot);
|
|
|
|
break;
|
|
|
|
case CT_SNESMAX:
|
|
|
|
m_slot[slot] = new SNESMAXCard(slot);
|
|
|
|
break;
|
2021-11-30 21:41:02 +00:00
|
|
|
case CT_VidHD:
|
|
|
|
m_slot[slot] = new VidHDCard(slot);
|
|
|
|
break;
|
2019-12-19 19:42:30 +00:00
|
|
|
|
|
|
|
case CT_LanguageCard:
|
2021-12-11 15:26:09 +00:00
|
|
|
_ASSERT(m_pLanguageCard == NULL);
|
|
|
|
if (m_pLanguageCard) break; // Only support one language card
|
|
|
|
m_slot[slot] = m_pLanguageCard = LanguageCardSlot0::create(slot);
|
|
|
|
break;
|
2019-12-19 19:42:30 +00:00
|
|
|
case CT_Saturn128K:
|
2021-12-11 15:26:09 +00:00
|
|
|
_ASSERT(m_pLanguageCard == NULL);
|
|
|
|
if (m_pLanguageCard) break; // Only support one language card
|
|
|
|
m_slot[slot] = m_pLanguageCard = new Saturn128K(slot, Saturn128K::GetSaturnMemorySize());
|
|
|
|
break;
|
|
|
|
case CT_LanguageCardIIe:
|
|
|
|
_ASSERT(m_pLanguageCard == NULL);
|
|
|
|
if (m_pLanguageCard) break; // Only support one language card
|
|
|
|
m_slot[slot] = m_pLanguageCard = LanguageCardUnit::create(slot);
|
2019-12-19 19:42:30 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
_ASSERT(0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_slot[slot] == NULL)
|
2021-09-17 19:43:10 +00:00
|
|
|
Remove(slot); // creates a new EmptyCard
|
|
|
|
}
|
|
|
|
|
|
|
|
void CardManager::Insert(UINT slot, SS_CARDTYPE type, bool updateRegistry/*=true*/)
|
|
|
|
{
|
|
|
|
InsertInternal(slot, type);
|
|
|
|
if (updateRegistry)
|
|
|
|
RegSetConfigSlotNewCardType(slot, type);
|
2019-12-19 19:42:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CardManager::RemoveInternal(UINT slot)
|
|
|
|
{
|
2021-12-11 15:26:09 +00:00
|
|
|
if (m_slot[slot])
|
|
|
|
{
|
|
|
|
// NB. object deleted below: delete m_slot[slot]
|
|
|
|
switch (m_slot[slot]->QueryType())
|
|
|
|
{
|
|
|
|
case CT_MouseInterface:
|
|
|
|
m_pMouseCard = NULL;
|
|
|
|
break;
|
|
|
|
case CT_SSC:
|
|
|
|
m_pSSC = NULL;
|
|
|
|
break;
|
|
|
|
case CT_LanguageCard:
|
|
|
|
case CT_Saturn128K:
|
|
|
|
case CT_LanguageCardIIe:
|
|
|
|
m_pLanguageCard = NULL;
|
|
|
|
break;
|
|
|
|
}
|
2019-12-19 19:42:30 +00:00
|
|
|
|
2021-12-11 15:26:09 +00:00
|
|
|
delete m_slot[slot];
|
|
|
|
m_slot[slot] = NULL;
|
|
|
|
}
|
2019-12-19 19:42:30 +00:00
|
|
|
}
|
|
|
|
|
2021-10-19 20:56:19 +00:00
|
|
|
void CardManager::Remove(UINT slot, bool updateRegistry/*=true*/)
|
2019-12-19 19:42:30 +00:00
|
|
|
{
|
2021-10-19 20:56:19 +00:00
|
|
|
Insert(slot, CT_Empty, updateRegistry);
|
2019-12-19 19:42:30 +00:00
|
|
|
}
|
|
|
|
|
2021-09-17 19:43:10 +00:00
|
|
|
void CardManager::InsertAuxInternal(SS_CARDTYPE type)
|
2019-12-19 19:42:30 +00:00
|
|
|
{
|
2020-12-06 18:43:18 +00:00
|
|
|
RemoveAuxInternal();
|
|
|
|
|
2019-12-19 19:42:30 +00:00
|
|
|
switch (type)
|
|
|
|
{
|
2021-09-17 19:43:10 +00:00
|
|
|
case CT_Empty:
|
2021-11-11 21:45:55 +00:00
|
|
|
m_aux = new EmptyCard(SLOT_AUX);
|
2021-09-17 19:43:10 +00:00
|
|
|
break;
|
2019-12-19 19:42:30 +00:00
|
|
|
case CT_80Col:
|
2021-11-01 21:01:28 +00:00
|
|
|
m_aux = new DummyCard(type, SLOT_AUX);
|
2019-12-19 19:42:30 +00:00
|
|
|
break;
|
|
|
|
case CT_Extended80Col:
|
2021-11-01 21:01:28 +00:00
|
|
|
m_aux = new DummyCard(type, SLOT_AUX);
|
2019-12-19 19:42:30 +00:00
|
|
|
break;
|
|
|
|
case CT_RamWorksIII:
|
2021-11-01 21:01:28 +00:00
|
|
|
m_aux = new DummyCard(type, SLOT_AUX);
|
2019-12-19 19:42:30 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
_ASSERT(0);
|
|
|
|
break;
|
|
|
|
}
|
2020-12-06 18:43:18 +00:00
|
|
|
|
|
|
|
// for consistency m_aux must never be NULL
|
|
|
|
_ASSERT(m_aux != NULL);
|
2021-09-17 19:43:10 +00:00
|
|
|
if (m_aux == NULL)
|
|
|
|
RemoveAux(); // creates a new EmptyCard
|
|
|
|
}
|
|
|
|
|
|
|
|
void CardManager::InsertAux(SS_CARDTYPE type)
|
|
|
|
{
|
|
|
|
InsertAuxInternal(type);
|
|
|
|
RegSetConfigSlotNewCardType(SLOT_AUX, type);
|
2019-12-19 19:42:30 +00:00
|
|
|
}
|
|
|
|
|
2020-12-09 20:19:49 +00:00
|
|
|
void CardManager::RemoveAuxInternal()
|
|
|
|
{
|
|
|
|
delete m_aux;
|
|
|
|
m_aux = NULL;
|
|
|
|
}
|
|
|
|
|
2019-12-19 19:42:30 +00:00
|
|
|
void CardManager::RemoveAux(void)
|
|
|
|
{
|
2021-09-17 19:43:10 +00:00
|
|
|
InsertAux(CT_Empty);
|
2019-12-19 19:42:30 +00:00
|
|
|
}
|
2021-11-11 21:45:55 +00:00
|
|
|
|
|
|
|
void CardManager::InitializeIO(LPBYTE pCxRomPeripheral)
|
|
|
|
{
|
2021-12-11 15:26:09 +00:00
|
|
|
// if it is a //e then SLOT0 must be CT_LanguageCardIIe (and the other way round)
|
|
|
|
_ASSERT(IsApple2PlusOrClone(GetApple2Type()) != (m_slot[SLOT0]->QueryType() == CT_LanguageCardIIe));
|
|
|
|
|
2021-12-18 21:31:17 +00:00
|
|
|
for (UINT i = SLOT0; i < NUM_SLOTS; ++i)
|
2021-11-11 21:45:55 +00:00
|
|
|
{
|
|
|
|
if (m_slot[i])
|
|
|
|
{
|
|
|
|
m_slot[i]->InitializeIO(pCxRomPeripheral);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-11-13 18:13:01 +00:00
|
|
|
|
|
|
|
void CardManager::Update(const ULONG nExecutedCycles)
|
|
|
|
{
|
2021-12-18 21:31:17 +00:00
|
|
|
for (UINT i = SLOT0; i < NUM_SLOTS; ++i)
|
|
|
|
{
|
|
|
|
if (m_slot[i])
|
|
|
|
{
|
|
|
|
m_slot[i]->Update(nExecutedCycles);
|
|
|
|
}
|
|
|
|
}
|
2021-11-13 18:13:01 +00:00
|
|
|
}
|
2021-11-25 20:23:21 +00:00
|
|
|
|
|
|
|
void CardManager::SaveSnapshot(YamlSaveHelper& yamlSaveHelper)
|
|
|
|
{
|
2021-12-18 21:31:17 +00:00
|
|
|
for (UINT i = SLOT0; i < NUM_SLOTS; ++i)
|
2021-11-25 20:23:21 +00:00
|
|
|
{
|
|
|
|
if (m_slot[i])
|
|
|
|
{
|
|
|
|
m_slot[i]->SaveSnapshot(yamlSaveHelper);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|