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
|
// license:BSD-3-Clause
// copyright-holders:Curt Coder
/**********************************************************************
Commodore PET 64KB RAM Expansion emulation
**********************************************************************/
#include "emu.h"
#include "64k.h"
//**************************************************************************
// DEVICE DEFINITIONS
//**************************************************************************
DEFINE_DEVICE_TYPE(PET_64K, pet_64k_expansion_device, "pet_64k", "PET 64KB RAM")
//**************************************************************************
// INLINE HELPERS
//**************************************************************************
//-------------------------------------------------
// read_ram -
//-------------------------------------------------
inline uint8_t pet_64k_expansion_device::read_ram(offs_t offset)
{
uint8_t data;
if (offset < 0xc000)
{
data = m_ram[(BIT(m_ctrl, 2) << 14) | (offset & 0x3fff)];
}
else
{
data = m_ram[0x8000 | (BIT(m_ctrl, 3) << 14) | (offset & 0x3fff)];
}
return data;
}
//-------------------------------------------------
// write_ram -
//-------------------------------------------------
inline void pet_64k_expansion_device::write_ram(offs_t offset, uint8_t data)
{
if (offset < 0xc000)
{
if (!BIT(m_ctrl, 0))
{
m_ram[(BIT(m_ctrl, 2) << 14) | (offset & 0x3fff)] = data;
}
}
else
{
if (!BIT(m_ctrl, 1))
{
m_ram[0x8000 | (BIT(m_ctrl, 3) << 14) | (offset & 0x3fff)] = data;
}
}
}
//**************************************************************************
// LIVE DEVICE
//**************************************************************************
//-------------------------------------------------
// pet_64k_expansion_device - constructor
//-------------------------------------------------
pet_64k_expansion_device::pet_64k_expansion_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
device_t(mconfig, PET_64K, tag, owner, clock),
device_pet_expansion_card_interface(mconfig, *this),
m_ram(*this, "ram"),
m_ctrl(0)
{
}
//-------------------------------------------------
// device_start - device-specific startup
//-------------------------------------------------
void pet_64k_expansion_device::device_start()
{
// allocate memory
m_ram.allocate(0x10000);
// state saving
save_item(NAME(m_ctrl));
}
//-------------------------------------------------
// device_reset - device-specific reset
//-------------------------------------------------
void pet_64k_expansion_device::device_reset()
{
m_ctrl = 0;
}
//-------------------------------------------------
// pet_norom_r - NO ROM read
//-------------------------------------------------
int pet_64k_expansion_device::pet_norom_r(offs_t offset, int sel)
{
return !BIT(m_ctrl, 7);
}
//-------------------------------------------------
// pet_bd_r - buffered data read
//-------------------------------------------------
uint8_t pet_64k_expansion_device::pet_bd_r(offs_t offset, uint8_t data, int &sel)
{
if (BIT(m_ctrl, 7))
{
switch (sel)
{
case pet_expansion_slot_device::SEL8:
if (!BIT(m_ctrl, 5))
{
data = read_ram(offset);
sel = pet_expansion_slot_device::SEL_NONE;
}
break;
case pet_expansion_slot_device::SELE:
if (!BIT(m_ctrl, 6) || !BIT(offset, 11))
{
data = read_ram(offset);
sel = pet_expansion_slot_device::SEL_NONE;
}
break;
case pet_expansion_slot_device::SEL9:
case pet_expansion_slot_device::SELA:
case pet_expansion_slot_device::SELB:
case pet_expansion_slot_device::SELC:
case pet_expansion_slot_device::SELD:
case pet_expansion_slot_device::SELF:
data = read_ram(offset);
break;
}
}
return data;
}
//-------------------------------------------------
// pet_bd_w - buffered data write
//-------------------------------------------------
void pet_64k_expansion_device::pet_bd_w(offs_t offset, uint8_t data, int &sel)
{
if (BIT(m_ctrl, 7))
{
switch (sel)
{
case pet_expansion_slot_device::SEL8:
if (!BIT(m_ctrl, 5))
{
write_ram(offset, data);
sel = pet_expansion_slot_device::SEL_NONE;
}
break;
case pet_expansion_slot_device::SELE:
if (!BIT(m_ctrl, 6) || !BIT(offset, 11))
{
write_ram(offset, data);
sel = pet_expansion_slot_device::SEL_NONE;
}
break;
case pet_expansion_slot_device::SEL9:
case pet_expansion_slot_device::SELA:
case pet_expansion_slot_device::SELB:
case pet_expansion_slot_device::SELC:
case pet_expansion_slot_device::SELD:
case pet_expansion_slot_device::SELF:
write_ram(offset, data);
break;
}
}
if (offset == 0xfff0)
{
m_ctrl = data;
}
}
|