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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
|
// license:BSD-3-Clause
// copyright-holders:Curt Coder
/**********************************************************************
Zilog Z8536 Counter/Timer and Parallel I/O emulation
**********************************************************************
_____ _____
D4 1 |* \_/ | 40 D3
D5 2 | | 39 D2
D6 3 | | 38 D1
D7 4 | | 37 D0
_RD 5 | | 36 _CE
_WR 6 | | 35 A1
GND 7 | | 34 A0
PB0 8 | | 33 PA0
PB1 9 | | 32 PA1
PB2 10 | Z8536 | 31 PA2
PB3 11 | | 30 PA3
PB4 12 | | 29 PA4
PB5 13 | | 28 PA5
PB6 14 | | 27 PA6
PB7 15 | | 26 PA7
PCLK 16 | | 25 _INTACK
IEI 17 | | 24 _INT
IEO 18 | | 23 +5 V
PC0 19 | | 22 PC3
PC1 20 |_____________| 21 PC2
**********************************************************************/
#pragma once
#ifndef __Z8536__
#define __Z8536__
#include "emu.h"
#include "cpu/z80/z80daisy.h"
//**************************************************************************
// INTERFACE CONFIGURATION MACROS
//**************************************************************************
#define MCFG_Z8536_IRQ_CALLBACK(_write) \
devcb = &z8536_device::set_irq_wr_callback(*device, DEVCB_##_write);
#define MCFG_Z8536_PA_IN_CALLBACK(_read) \
devcb = &z8536_device::set_pa_rd_callback(*device, DEVCB_##_read);
#define MCFG_Z8536_PA_OUT_CALLBACK(_write) \
devcb = &z8536_device::set_pa_wr_callback(*device, DEVCB_##_write);
#define MCFG_Z8536_PB_IN_CALLBACK(_read) \
devcb = &z8536_device::set_pb_rd_callback(*device, DEVCB_##_read);
#define MCFG_Z8536_PB_OUT_CALLBACK(_write) \
devcb = &z8536_device::set_pb_wr_callback(*device, DEVCB_##_write);
#define MCFG_Z8536_PC_IN_CALLBACK(_read) \
devcb = &z8536_device::set_pc_rd_callback(*device, DEVCB_##_read);
#define MCFG_Z8536_PC_OUT_CALLBACK(_write) \
devcb = &z8536_device::set_pc_wr_callback(*device, DEVCB_##_write);
//**************************************************************************
// TYPE DEFINITIONS
//**************************************************************************
// ======================> z8536_device
class z8536_device : public device_t,
public device_z80daisy_interface
{
public:
// construction/destruction
z8536_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
template<class _Object> static devcb_base &set_irq_wr_callback(device_t &device, _Object object) { return downcast<z8536_device &>(device).m_write_irq.set_callback(object); }
template<class _Object> static devcb_base &set_pa_rd_callback(device_t &device, _Object object) { return downcast<z8536_device &>(device).m_read_pa.set_callback(object); }
template<class _Object> static devcb_base &set_pa_wr_callback(device_t &device, _Object object) { return downcast<z8536_device &>(device).m_write_pa.set_callback(object); }
template<class _Object> static devcb_base &set_pb_rd_callback(device_t &device, _Object object) { return downcast<z8536_device &>(device).m_read_pb.set_callback(object); }
template<class _Object> static devcb_base &set_pb_wr_callback(device_t &device, _Object object) { return downcast<z8536_device &>(device).m_write_pb.set_callback(object); }
template<class _Object> static devcb_base &set_pc_rd_callback(device_t &device, _Object object) { return downcast<z8536_device &>(device).m_read_pc.set_callback(object); }
template<class _Object> static devcb_base &set_pc_wr_callback(device_t &device, _Object object) { return downcast<z8536_device &>(device).m_write_pc.set_callback(object); }
DECLARE_READ8_MEMBER( read );
DECLARE_WRITE8_MEMBER( write );
int intack_r();
DECLARE_WRITE_LINE_MEMBER( pa0_w ) { external_port_w(PORT_A, 0, state); }
DECLARE_WRITE_LINE_MEMBER( pa1_w ) { external_port_w(PORT_A, 1, state); }
DECLARE_WRITE_LINE_MEMBER( pa2_w ) { external_port_w(PORT_A, 2, state); }
DECLARE_WRITE_LINE_MEMBER( pa3_w ) { external_port_w(PORT_A, 3, state); }
DECLARE_WRITE_LINE_MEMBER( pa4_w ) { external_port_w(PORT_A, 4, state); }
DECLARE_WRITE_LINE_MEMBER( pa5_w ) { external_port_w(PORT_A, 5, state); }
DECLARE_WRITE_LINE_MEMBER( pa6_w ) { external_port_w(PORT_A, 6, state); }
DECLARE_WRITE_LINE_MEMBER( pa7_w ) { external_port_w(PORT_A, 7, state); }
DECLARE_WRITE_LINE_MEMBER( pb0_w ) { external_port_w(PORT_B, 0, state); }
DECLARE_WRITE_LINE_MEMBER( pb1_w ) { external_port_w(PORT_B, 1, state); }
DECLARE_WRITE_LINE_MEMBER( pb2_w ) { external_port_w(PORT_B, 2, state); }
DECLARE_WRITE_LINE_MEMBER( pb3_w ) { external_port_w(PORT_B, 3, state); }
DECLARE_WRITE_LINE_MEMBER( pb4_w ) { external_port_w(PORT_B, 4, state); }
DECLARE_WRITE_LINE_MEMBER( pb5_w ) { external_port_w(PORT_B, 5, state); }
DECLARE_WRITE_LINE_MEMBER( pb6_w ) { external_port_w(PORT_B, 6, state); }
DECLARE_WRITE_LINE_MEMBER( pb7_w ) { external_port_w(PORT_B, 7, state); }
DECLARE_WRITE_LINE_MEMBER( pc0_w ) { external_port_w(PORT_C, 0, state); }
DECLARE_WRITE_LINE_MEMBER( pc1_w ) { external_port_w(PORT_C, 1, state); }
DECLARE_WRITE_LINE_MEMBER( pc2_w ) { external_port_w(PORT_C, 2, state); }
DECLARE_WRITE_LINE_MEMBER( pc3_w ) { external_port_w(PORT_C, 3, state); }
protected:
// device-level overrides
virtual void device_start();
virtual void device_reset();
virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
// device_z80daisy_interface overrides
virtual int z80daisy_irq_state();
virtual int z80daisy_irq_ack();
virtual void z80daisy_irq_reti();
private:
enum
{
TIMER_1 = 0,
TIMER_2,
TIMER_3
};
// states
enum
{
STATE_RESET = -1,
STATE_0,
STATE_1
};
// ports
enum
{
PORT_C = 0,
PORT_B,
PORT_A,
CONTROL
};
// registers
enum
{
MASTER_INTERRUPT_CONTROL = 0,
MASTER_CONFIGURATION_CONTROL,
PORT_A_INTERRUPT_VECTOR,
PORT_B_INTERRUPT_VECTOR,
COUNTER_TIMER_INTERRUPT_VECTOR,
PORT_C_DATA_PATH_POLARITY,
PORT_C_DATA_DIRECTION,
PORT_C_SPECIAL_IO_CONTROL,
PORT_A_COMMAND_AND_STATUS,
PORT_B_COMMAND_AND_STATUS,
COUNTER_TIMER_1_COMMAND_AND_STATUS,
COUNTER_TIMER_2_COMMAND_AND_STATUS,
COUNTER_TIMER_3_COMMAND_AND_STATUS,
PORT_A_DATA,
PORT_B_DATA,
PORT_C_DATA,
COUNTER_TIMER_1_CURRENT_COUNT_MS_BYTE,
COUNTER_TIMER_1_CURRENT_COUNT_LS_BYTE,
COUNTER_TIMER_2_CURRENT_COUNT_MS_BYTE,
COUNTER_TIMER_2_CURRENT_COUNT_LS_BYTE,
COUNTER_TIMER_3_CURRENT_COUNT_MS_BYTE,
COUNTER_TIMER_3_CURRENT_COUNT_LS_BYTE,
COUNTER_TIMER_1_TIME_CONSTANT_MS_BYTE,
COUNTER_TIMER_1_TIME_CONSTANT_LS_BYTE,
COUNTER_TIMER_2_TIME_CONSTANT_MS_BYTE,
COUNTER_TIMER_2_TIME_CONSTANT_LS_BYTE,
COUNTER_TIMER_3_TIME_CONSTANT_MS_BYTE,
COUNTER_TIMER_3_TIME_CONSTANT_LS_BYTE,
COUNTER_TIMER_1_MODE_SPECIFICATION,
COUNTER_TIMER_2_MODE_SPECIFICATION,
COUNTER_TIMER_3_MODE_SPECIFICATION,
CURRENT_VECTOR,
PORT_A_MODE_SPECIFICATION,
PORT_A_HANDSHAKE_SPECIFICATION,
PORT_A_DATA_PATH_POLARITY,
PORT_A_DATA_DIRECTION,
PORT_A_SPECIAL_IO_CONTROL,
PORT_A_PATTERN_POLARITY,
PORT_A_PATTERN_TRANSITION,
PORT_A_PATTERN_MASK,
PORT_B_MODE_SPECIFICATION,
PORT_B_HANDSHAKE_SPECIFICATION,
PORT_B_DATA_PATH_POLARITY,
PORT_B_DATA_DIRECTION,
PORT_B_SPECIAL_IO_CONTROL,
PORT_B_PATTERN_POLARITY,
PORT_B_PATTERN_TRANSITION,
PORT_B_PATTERN_MASK
};
// interrupt control
enum
{
IC_NULL = 0,
IC_CLEAR_IP_IUS,
IC_SET_IUS,
IC_CLEAR_IUS,
IC_SET_IP,
IC_CLEAR_IP,
IC_SET_IE,
IC_CLEAR_IE
};
// counter/timer link control
enum
{
LC_INDEPENDENT = 0,
LC_CT1_GATES_CT2,
LC_CT1_TRIGGERS_CT2,
LC_CT1_COUNTS_CT2
};
// port type select
enum
{
PTS_BIT = 0,
PTS_INPUT,
PTS_OUTPUT,
PTS_BIDIRECTIONAL
};
// pattern mode specification
enum
{
PMS_DISABLE = 0,
PMS_AND,
PMS_OR,
PMS_OR_PEV
};
// handshake specification
enum
{
HTS_INTERLOCKED = 0,
HTS_STROBED,
HTS_PULSED,
HTS_3_WIRE
};
// request/wait specification
enum
{
RWS_DISABLED = 0,
RWS_OUTPUT_WAIT,
RWS_INPUT_WAIT = 3,
RWS_SPECIAL_REQUEST,
RWS_OUTPUT_REQUEST,
RWS_INPUT_REQUEST = 7
};
// pattern specification
enum
{
BIT_MASKED_OFF = 0,
ANY_TRANSITION,
ZERO = 4,
ONE,
ONE_TO_ZERO,
ZERO_TO_ONE
};
// output duty cycle
enum
{
DCS_PULSE,
DCS_ONE_SHOT,
DCS_SQUARE_WAVE,
DCS_DO_NOT_USE
};
void get_interrupt_vector();
void check_interrupt();
UINT8 read_register(offs_t offset);
UINT8 read_register(offs_t offset, UINT8 mask);
void write_register(offs_t offset, UINT8 data);
void write_register(offs_t offset, UINT8 data, UINT8 mask);
bool counter_enabled(device_timer_id id);
bool counter_external_output(device_timer_id id);
bool counter_external_count(device_timer_id id);
bool counter_external_trigger(device_timer_id id);
bool counter_external_gate(device_timer_id id);
bool counter_gated(device_timer_id id);
void count(device_timer_id id);
void trigger(device_timer_id id);
void gate(device_timer_id id, int state);
void match_pattern(int port);
void external_port_w(int port, int bit, int state);
devcb_write_line m_write_irq;
devcb_read8 m_read_pa;
devcb_write8 m_write_pa;
devcb_read8 m_read_pb;
devcb_write8 m_write_pb;
devcb_read8 m_read_pc;
devcb_write8 m_write_pc;
// interrupt state
int m_irq;
// register state
int m_state;
UINT8 m_register[48];
UINT8 m_pointer;
// input/output port state
UINT8 m_input[3];
UINT8 m_output[3];
UINT8 m_buffer[3];
UINT8 m_match[3];
// timers
emu_timer *m_timer;
UINT16 m_counter[3];
};
// device type definition
extern const device_type Z8536;
#endif
|