forked from audetto/AppleWin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CardManager.cpp
223 lines (196 loc) · 4.79 KB
/
CardManager.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/*
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"
#include "Core.h"
#include "Registry.h"
#include "Disk.h"
#include "FourPlay.h"
#include "Harddisk.h"
#include "MouseInterface.h"
#include "SAM.h"
#include "SerialComms.h"
#include "SNESMAX.h"
void CardManager::InsertInternal(UINT slot, SS_CARDTYPE type)
{
RemoveInternal(slot);
switch (type)
{
case CT_Empty:
m_slot[slot] = new EmptyCard(slot);
break;
case CT_Disk2:
m_slot[slot] = new Disk2InterfaceCard(slot);
break;
case CT_SSC:
_ASSERT(m_pSSC == NULL);
if (m_pSSC) break; // Only support one SSC
m_slot[slot] = m_pSSC = new CSuperSerialCard(slot);
break;
case CT_MockingboardC:
m_slot[slot] = new DummyCard(type, slot);
break;
case CT_GenericPrinter:
m_slot[slot] = new DummyCard(type, slot);
break;
case CT_GenericHDD:
m_slot[slot] = new HarddiskInterfaceCard(slot);
break;
case CT_GenericClock:
m_slot[slot] = new DummyCard(type, slot);
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:
m_slot[slot] = new DummyCard(type, slot);
break;
case CT_Phasor:
m_slot[slot] = new DummyCard(type, slot);
break;
case CT_Echo:
m_slot[slot] = new DummyCard(type, slot);
break;
case CT_SAM:
m_slot[slot] = new SAMCard(slot);
break;
case CT_Uthernet:
m_slot[slot] = new DummyCard(type, slot);
break;
case CT_FourPlay:
m_slot[slot] = new FourPlayCard(slot);
break;
case CT_SNESMAX:
m_slot[slot] = new SNESMAXCard(slot);
break;
case CT_LanguageCard:
case CT_Saturn128K:
{
if (slot != 0)
{
_ASSERT(0);
break;
}
}
m_slot[slot] = new DummyCard(type, slot);
break;
case CT_LanguageCardIIe: // not a card
default:
_ASSERT(0);
break;
}
if (m_slot[slot] == NULL)
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);
}
void CardManager::RemoveInternal(UINT slot)
{
if (m_slot[slot] && m_slot[slot]->QueryType() == CT_MouseInterface)
m_pMouseCard = NULL; // NB. object deleted below: delete m_slot[slot]
if (m_slot[slot] && m_slot[slot]->QueryType() == CT_SSC)
m_pSSC = NULL; // NB. object deleted below: delete m_slot[slot]
delete m_slot[slot];
m_slot[slot] = NULL;
}
void CardManager::Remove(UINT slot, bool updateRegistry/*=true*/)
{
Insert(slot, CT_Empty, updateRegistry);
}
void CardManager::InsertAuxInternal(SS_CARDTYPE type)
{
RemoveAuxInternal();
switch (type)
{
case CT_Empty:
m_aux = new EmptyCard(SLOT_AUX);
break;
case CT_80Col:
m_aux = new DummyCard(type, SLOT_AUX);
break;
case CT_Extended80Col:
m_aux = new DummyCard(type, SLOT_AUX);
break;
case CT_RamWorksIII:
m_aux = new DummyCard(type, SLOT_AUX);
break;
default:
_ASSERT(0);
break;
}
// for consistency m_aux must never be NULL
_ASSERT(m_aux != NULL);
if (m_aux == NULL)
RemoveAux(); // creates a new EmptyCard
}
void CardManager::InsertAux(SS_CARDTYPE type)
{
InsertAuxInternal(type);
RegSetConfigSlotNewCardType(SLOT_AUX, type);
}
void CardManager::RemoveAuxInternal()
{
delete m_aux;
m_aux = NULL;
}
void CardManager::RemoveAux(void)
{
InsertAux(CT_Empty);
}
void CardManager::InitializeIO(LPBYTE pCxRomPeripheral)
{
for (UINT i = 0; i < NUM_SLOTS; ++i)
{
if (m_slot[i])
{
m_slot[i]->InitializeIO(pCxRomPeripheral);
}
}
}
void CardManager::Update(const ULONG nExecutedCycles)
{
for (UINT i = 0; i < NUM_SLOTS; ++i)
{
if (m_slot[i])
{
m_slot[i]->Update(nExecutedCycles);
}
}
}
void CardManager::SaveSnapshot(YamlSaveHelper& yamlSaveHelper)
{
for (UINT i = 1; i < NUM_SLOTS; ++i)
{
if (m_slot[i])
{
m_slot[i]->SaveSnapshot(yamlSaveHelper);
}
}
}