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
|
/**********************************************************************
Wang PC-PM031-B Extended Memory Board emulation
Copyright MESS Team.
Visit http://mamedev.org for licensing and usage restrictions.
**********************************************************************/
#include "wangpc_emb.h"
//**************************************************************************
// MACROS/CONSTANTS
//**************************************************************************
#define LOG 0
#define OPTION_ID 0x3f
#define RAM_SIZE 0x40000
#define A19_A18_A17 ((offset >> 16) & 0x07)
#define BASE(bank) ((m_option >> (bank * 4)) & 0x07)
#define ENABLE(bank) BIT(m_option, (bank * 4) + 3)
#define RAM_BANK(bank) m_ram[(bank * 0x10000) | (offset & 0xffff)]
//**************************************************************************
// DEVICE DEFINITIONS
//**************************************************************************
const device_type WANGPC_EMB = &device_creator<wangpc_emb_device>;
//**************************************************************************
// LIVE DEVICE
//**************************************************************************
//-------------------------------------------------
// wangpc_emb_device - constructor
//-------------------------------------------------
wangpc_emb_device::wangpc_emb_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) :
device_t(mconfig, WANGPC_EMB, "Wang PC-PM031-B", tag, owner, clock, "wangpc_emb", __FILE__),
device_wangpcbus_card_interface(mconfig, *this),
m_ram(*this, "ram")
{
}
//-------------------------------------------------
// device_start - device-specific startup
//-------------------------------------------------
void wangpc_emb_device::device_start()
{
// allocate memory
m_ram.allocate(RAM_SIZE);
// state saving
save_item(NAME(m_option));
save_item(NAME(m_parity_error));
save_item(NAME(m_parity_odd));
}
//-------------------------------------------------
// device_reset - device-specific reset
//-------------------------------------------------
void wangpc_emb_device::device_reset()
{
m_option = 0;
m_parity_error = 0;
m_parity_odd = 1;
}
//-------------------------------------------------
// wangpcbus_mrdc_r - memory read
//-------------------------------------------------
UINT16 wangpc_emb_device::wangpcbus_mrdc_r(address_space &space, offs_t offset, UINT16 mem_mask)
{
UINT16 data = 0xffff;
for (int bank = 0; bank < 4; bank++)
{
if (ENABLE(bank) && (A19_A18_A17 == BASE(bank)))
{
data &= RAM_BANK(bank);
}
}
return data;
}
//-------------------------------------------------
// wangpcbus_amwc_w - memory write
//-------------------------------------------------
void wangpc_emb_device::wangpcbus_amwc_w(address_space &space, offs_t offset, UINT16 mem_mask, UINT16 data)
{
for (int bank = 0; bank < 4; bank++)
{
if (ENABLE(bank) && (A19_A18_A17 == BASE(bank)))
{
RAM_BANK(bank) = data;
}
}
}
//-------------------------------------------------
// wangpcbus_iorc_r - I/O read
//-------------------------------------------------
UINT16 wangpc_emb_device::wangpcbus_iorc_r(address_space &space, offs_t offset, UINT16 mem_mask)
{
UINT16 data = 0xffff;
if (sad(offset))
{
switch (offset & 0x7f)
{
case 0xc0/2:
data = m_option;
break;
case 0xfe/2:
data = 0xfc00 | (m_parity_odd << 9) | (m_parity_error << 8) | OPTION_ID;
break;
}
logerror("emb read %06x:%02x\n", offset*2, data);
}
return data;
}
//-------------------------------------------------
// wangpcbus_aiowc_w - I/O write
//-------------------------------------------------
void wangpc_emb_device::wangpcbus_aiowc_w(address_space &space, offs_t offset, UINT16 mem_mask, UINT16 data)
{
if (sad(offset))
{
logerror("emb write %06x:%02x\n", offset*2, data);
switch (offset & 0x7f)
{
case 0xc0/2:
m_option = data;
break;
case 0xce/2:
m_parity_error = 0;
break;
case 0xfc/2:
device_reset();
break;
case 0xfe/2:
m_parity_odd = BIT(data, 9);
break;
}
}
}
|