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
|
/***************************************************************************
i8243.c
Intel 8243 Port Expander
Copyright Aaron Giles
***************************************************************************/
#include "emu.h"
#include "i8243.h"
#include "devhelpr.h"
//**************************************************************************
// LIVE DEVICE
//**************************************************************************
// device type definition
const device_type I8243 = &device_creator<i8243_device>;
//-------------------------------------------------
// i8243_device - constructor
//-------------------------------------------------
i8243_device::i8243_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
: device_t(mconfig, I8243, "I8243", tag, owner, clock)
{
}
//-------------------------------------------------
// static_set_read_handler - configuration helper
// to set the read handler
//-------------------------------------------------
void i8243_device::static_set_read_handler(device_t &device, read8_device_func callback)
{
i8243_device &i8243 = downcast<i8243_device &>(device);
if(callback != NULL)
{
i8243.m_readhandler_cb.type = DEVCB_TYPE_DEVICE;
i8243.m_readhandler_cb.index = 0;
i8243.m_readhandler_cb.tag = "";
i8243.m_readhandler_cb.readdevice = callback;
}
else
{
i8243.m_readhandler_cb.type = DEVCB_TYPE_NULL;
}
}
//-------------------------------------------------
// static_set_write_handler - configuration helper
// to set the write handler
//-------------------------------------------------
void i8243_device::static_set_write_handler(device_t &device, write8_device_func callback)
{
i8243_device &i8243 = downcast<i8243_device &>(device);
if(callback != NULL)
{
i8243.m_writehandler_cb.type = DEVCB_TYPE_DEVICE;
i8243.m_writehandler_cb.index = 0;
i8243.m_writehandler_cb.tag = "";
i8243.m_writehandler_cb.writedevice = callback;
}
else
{
i8243.m_writehandler_cb.type = DEVCB_TYPE_NULL;
}
}
//-------------------------------------------------
// device_start - device-specific startup
//-------------------------------------------------
void i8243_device::device_start()
{
m_readhandler.resolve(m_readhandler_cb, *this);
m_writehandler.resolve(m_writehandler_cb, *this);
}
//-------------------------------------------------
// device_reset - device-specific reset
//-------------------------------------------------
void i8243_device::device_reset()
{
m_p2 = 0x0f;
m_p2out = 0x0f;
m_prog = 1;
}
/*-------------------------------------------------
i8243_p2_r - handle a read from port 2
-------------------------------------------------*/
READ8_DEVICE_HANDLER_TRAMPOLINE(i8243, i8243_p2_r)
{
return m_p2out;
}
/*-------------------------------------------------
i8243_p2_r - handle a write to port 2
-------------------------------------------------*/
WRITE8_DEVICE_HANDLER_TRAMPOLINE(i8243, i8243_p2_w)
{
m_p2 = data & 0x0f;
}
/*-------------------------------------------------
i8243_prog_w - handle a change in the PROG
line state
-------------------------------------------------*/
WRITE8_DEVICE_HANDLER_TRAMPOLINE(i8243, i8243_prog_w)
{
/* only care about low bit */
data &= 1;
/* on high->low transition state, latch opcode/port */
if(m_prog && !data)
{
m_opcode = m_p2;
/* if this is a read opcode, copy result to p2out */
if((m_opcode >> 2) == MCS48_EXPANDER_OP_READ)
{
if (m_readhandler.isnull())
{
m_p[m_opcode & 3] = m_readhandler(m_opcode & 3);
}
m_p2out = m_p[m_opcode & 3] & 0x0f;
}
}
/* on low->high transition state, act on opcode */
else if(!m_prog && data)
{
switch(m_opcode >> 2)
{
case MCS48_EXPANDER_OP_WRITE:
m_p[m_opcode & 3] = m_p2 & 0x0f;
m_writehandler(m_opcode & 3, m_p[m_opcode & 3]);
break;
case MCS48_EXPANDER_OP_OR:
m_p[m_opcode & 3] |= m_p2 & 0x0f;
m_writehandler(m_opcode & 3, m_p[m_opcode & 3]);
break;
case MCS48_EXPANDER_OP_AND:
m_p[m_opcode & 3] &= m_p2 & 0x0f;
m_writehandler(m_opcode & 3, m_p[m_opcode & 3]);
break;
}
}
/* remember the state */
m_prog = data;
}
|