/
a2memexp.cpp
269 lines (215 loc) · 8.03 KB
/
a2memexp.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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
// license:BSD-3-Clause
// copyright-holders:R. Belmont
/*********************************************************************
a2memexp.c
Implementation of the Apple II Memory Expansion Card
*********************************************************************/
#include "emu.h"
#include "a2memexp.h"
namespace {
/***************************************************************************
PARAMETERS
***************************************************************************/
#define MEMEXP_ROM_REGION "memexp_rom"
ROM_START( memexp )
ROM_REGION(0x1000, MEMEXP_ROM_REGION, 0)
ROM_LOAD( "341-0344a.bin", 0x0000, 0x1000, CRC(1e994e17) SHA1(6e823a1fa40ed37eeddcef23f5df24da2ea1463e) )
ROM_END
ROM_START( ramfactor )
ROM_REGION(0x8000, MEMEXP_ROM_REGION, 0)
ROM_LOAD( "ae ramfactor rom v1.4.bin", 0x0000, 0x2000, CRC(1c56d646) SHA1(32cb02a6a915dd3962bfa1f0184a94253e03ba6b) )
ROM_LOAD( "ae ramfactor rom v1.3.bin", 0x2000, 0x2000, CRC(434f5c45) SHA1(cf31a370951bd9a10d5b77f179134b358683b8fa) )
ROM_LOAD( "ae ramfactor rom v1.1.bin", 0x4000, 0x2000, CRC(328907a3) SHA1(dc25b4133a52609799098d8918a289fd973d28d9) )
ROM_LOAD( "ae ramfactor rom v1.0.bin", 0x6000, 0x2000, CRC(39c2162a) SHA1(9286d35907939aadb1fffd3e1d75603fe3e846ad) )
ROM_END
//**************************************************************************
// TYPE DEFINITIONS
//**************************************************************************
class a2bus_memexp_device:
public device_t,
public device_a2bus_card_interface
{
public:
bool m_isramfactor;
uint8_t m_bankhior;
int m_addrmask;
protected:
// construction/destruction
a2bus_memexp_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock);
virtual void device_start() override;
virtual void device_reset() override;
virtual void device_add_mconfig(machine_config &config) override;
virtual const tiny_rom_entry *device_rom_region() const override;
// overrides of standard a2bus slot functions
virtual uint8_t read_c0nx(uint8_t offset) override;
virtual void write_c0nx(uint8_t offset, uint8_t data) override;
virtual uint8_t read_cnxx(uint8_t offset) override;
virtual uint8_t read_c800(uint16_t offset) override;
private:
required_region_ptr<uint8_t> m_rom;
uint8_t m_regs[0x10];
uint8_t m_ram[8*1024*1024];
int m_wptr, m_liveptr;
};
class a2bus_memexpapple_device : public a2bus_memexp_device
{
public:
a2bus_memexpapple_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
};
class a2bus_ramfactor_device : public a2bus_memexp_device
{
public:
a2bus_ramfactor_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
protected:
virtual const tiny_rom_entry *device_rom_region() const override;
};
/***************************************************************************
FUNCTION PROTOTYPES
***************************************************************************/
//-------------------------------------------------
// device_add_mconfig - add device configuration
//-------------------------------------------------
void a2bus_memexp_device::device_add_mconfig(machine_config &config)
{
}
//-------------------------------------------------
// rom_region - device-specific ROM region
//-------------------------------------------------
const tiny_rom_entry *a2bus_memexp_device::device_rom_region() const
{
return ROM_NAME( memexp );
}
const tiny_rom_entry *a2bus_ramfactor_device::device_rom_region() const
{
return ROM_NAME( ramfactor );
}
//**************************************************************************
// LIVE DEVICE
//**************************************************************************
a2bus_memexp_device::a2bus_memexp_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock) :
device_t(mconfig, type, tag, owner, clock),
device_a2bus_card_interface(mconfig, *this), m_isramfactor(false), m_bankhior(0), m_addrmask(0),
m_rom(*this, MEMEXP_ROM_REGION),
m_wptr(0), m_liveptr(0)
{
}
a2bus_memexpapple_device::a2bus_memexpapple_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
a2bus_memexp_device(mconfig, A2BUS_MEMEXP, tag, owner, clock)
{
m_isramfactor = false;
m_bankhior = 0xf0;
m_addrmask = 0xfffff;
}
a2bus_ramfactor_device::a2bus_ramfactor_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
a2bus_memexp_device(mconfig, A2BUS_RAMFACTOR, tag, owner, clock)
{
m_isramfactor = true;
m_bankhior = 0x00;
m_addrmask = 0x7fffff;
}
//-------------------------------------------------
// device_start - device-specific startup
//-------------------------------------------------
void a2bus_memexp_device::device_start()
{
memset(m_ram, 0xff, 1024*1024*sizeof(uint8_t));
save_item(NAME(m_regs));
save_item(NAME(m_ram));
save_item(NAME(m_wptr));
save_item(NAME(m_liveptr));
}
void a2bus_memexp_device::device_reset()
{
memset(m_regs, 0, sizeof(uint8_t) * 0x10);
m_wptr = m_liveptr = 0;
}
/*-------------------------------------------------
read_c0nx - called for reads from this card's c0nx space
-------------------------------------------------*/
uint8_t a2bus_memexp_device::read_c0nx(uint8_t offset)
{
uint8_t retval = m_regs[offset];
if (offset == 3)
{
retval = m_ram[m_liveptr&m_addrmask];
// printf("Read RAM[%x] = %02x\n", m_liveptr, retval);
m_liveptr++;
m_regs[0] = m_liveptr & 0xff;
m_regs[1] = (m_liveptr>>8) & 0xff;
m_regs[2] = ((m_liveptr>>16) & 0xff) | m_bankhior;
}
return retval;
}
/*-------------------------------------------------
write_c0nx - called for writes to this card's c0nx space
-------------------------------------------------*/
void a2bus_memexp_device::write_c0nx(uint8_t offset, uint8_t data)
{
switch (offset)
{
case 0:
m_wptr &= ~0xff;
m_wptr |= data;
m_regs[0] = m_wptr & 0xff;
m_regs[1] = (m_wptr>>8) & 0xff;
m_regs[2] = ((m_wptr>>16) & 0xff) | m_bankhior;
m_liveptr = m_wptr;
break;
case 1:
m_wptr &= ~0xff00;
m_wptr |= (data<<8);
m_regs[0] = m_wptr & 0xff;
m_regs[1] = (m_wptr>>8) & 0xff;
m_regs[2] = ((m_wptr>>16) & 0xff) | m_bankhior;
m_liveptr = m_wptr;
break;
case 2:
m_wptr &= ~0xff0000;
m_wptr |= (data<<16);
m_regs[0] = m_wptr & 0xff;
m_regs[1] = (m_wptr>>8) & 0xff;
m_regs[2] = ((m_wptr>>16) & 0xff) | m_bankhior;
m_liveptr = m_wptr;
break;
case 3:
// printf("Write %02x to RAM[%x]\n", data, m_liveptr);
m_ram[(m_liveptr&m_addrmask)] = data;
m_liveptr++;
m_regs[0] = m_liveptr & 0xff;
m_regs[1] = (m_liveptr>>8) & 0xff;
m_regs[2] = ((m_liveptr>>16) & 0xff) | m_bankhior;
break;
default:
m_regs[offset] = data;
break;
}
}
/*-------------------------------------------------
read_cnxx - called for reads from this card's cnxx space
-------------------------------------------------*/
uint8_t a2bus_memexp_device::read_cnxx(uint8_t offset)
{
int const slotimg = slotno() * 0x100;
// first 0x400 of ROM contains a CnXX image for each of slots 1-7, last 0x400 is c800 image
if ((m_isramfactor) && (m_regs[0xf] & 0x01))
return m_rom[offset+slotimg+0x1000];
else
return m_rom[offset+slotimg];
}
/*-------------------------------------------------
read_c800 - called for reads from this card's c800 space
-------------------------------------------------*/
uint8_t a2bus_memexp_device::read_c800(uint16_t offset)
{
// c70a diags confirm: bit 1 of cn0F banks in the second half of the ROM
if ((m_isramfactor) && (m_regs[0xf] & 0x01))
return m_rom[offset+0x1800];
else
return m_rom[offset+0x800];
}
} // anonymous namespace
//**************************************************************************
// GLOBAL VARIABLES
//**************************************************************************
DEFINE_DEVICE_TYPE_PRIVATE(A2BUS_MEMEXP, device_a2bus_card_interface, a2bus_memexpapple_device, "a2memexp", "Apple II Memory Expansion Card")
DEFINE_DEVICE_TYPE_PRIVATE(A2BUS_RAMFACTOR, device_a2bus_card_interface, a2bus_ramfactor_device, "a2ramfac", "Applied Engineering RamFactor")