summaryrefslogtreecommitdiffstats
path: root/src/mame/machine/taitoio.cpp
blob: b4b94bdf69ac7498fc9403bd5443017b51c7f086 (plain) (blame)
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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
// license:BSD-3-Clause
// copyright-holders:Nicola Salmoria
/***************************************************************************

TC0040IOC
---------
Taito's first custom I/O interface differs a bit from its successors,
being a 64-pin DIP with an address port and a data port. Besides digital
inputs, coin-related outputs and an integrated watchdog, this chip also
handles steering wheel and trackball input conversion in various games (not
emulated here yet).


TC0220IOC
---------
A simple I/O interface with integrated watchdog in a 80-pin flat package.
It has four address inputs, which would suggest 16 bytes of addressing space,
but only the first 8 seem to be used.

000 R  IN00-07 (DSA)
000  W watchdog reset
001 R  IN08-15 (DSB)
002 R  IN16-23 (1P)
002  W unknown. Usually written on startup: initialize?
003 R  IN24-31 (2P)
004 RW coin counters and lockout
005  W unknown
006  W unknown
007 R  INB0-7 (coin)


TC0510NIO
---------
Newer QFP100 version of the I/O chip

000 R  DSWA
000  W watchdog reset
001 R  DSWB
001  W unknown (ssi)
002 R  1P
003 R  2P
003  W unknown (yuyugogo, qzquest and qzchikyu use it a lot)
004 RW coin counters and lockout
005  W unknown
006  W unknown (koshien and pulirula use it a lot)
007 R  coin


TC0640FIO
---------
Newer version of the I/O chip ?


***************************************************************************/

#include "emu.h"
#include "machine/taitoio.h"


/***************************************************************************/
/*                                                                         */
/*                              TC0040IOC                                  */
/*                                                                         */
/***************************************************************************/

DEFINE_DEVICE_TYPE(TC0040IOC, tc0040ioc_device, "tc0040ioc", "Taito TC0040IOC")

tc0040ioc_device::tc0040ioc_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
	device_t(mconfig, TC0040IOC, tag, owner, clock),
	m_regs{ 0, 0, 0, 0, 0, 0, 0, 0 },
	m_port(0),
	m_watchdog(*this, "watchdog"),
	m_read_0_cb(*this),
	m_read_1_cb(*this),
	m_read_2_cb(*this),
	m_read_3_cb(*this),
	m_write_4_cb(*this),
	m_read_7_cb(*this)
{
}

//-------------------------------------------------
//  device_start - device-specific startup
//-------------------------------------------------

void tc0040ioc_device::device_start()
{
	m_read_0_cb.resolve_safe(0);
	m_read_1_cb.resolve_safe(0);
	m_read_2_cb.resolve_safe(0);
	m_read_3_cb.resolve_safe(0);
	m_write_4_cb.resolve_safe();
	m_read_7_cb.resolve_safe(0);

	save_item(NAME(m_regs));
	save_item(NAME(m_port));
}

//-------------------------------------------------
//  device_reset - device-specific reset
//-------------------------------------------------

void tc0040ioc_device::device_reset()
{
	m_port = 0;

	for (auto & elem : m_regs)
		elem = 0;
}

//-------------------------------------------------
//  device_add_mconfig - add device configuration
//-------------------------------------------------

MACHINE_CONFIG_MEMBER( tc0040ioc_device::device_add_mconfig )
	MCFG_WATCHDOG_ADD("watchdog")
MACHINE_CONFIG_END

/*****************************************************************************
    DEVICE HANDLERS
*****************************************************************************/

READ8_MEMBER( tc0040ioc_device::read )
{
	if (offset & 1)
		return watchdog_r(space, 0);
	else
		return portreg_r(space, 0);
}

WRITE8_MEMBER( tc0040ioc_device::write )
{
	if (offset & 1)
		port_w(space, 0, data);
	else
		portreg_w(space, 0, data);
}

READ8_MEMBER( tc0040ioc_device::watchdog_r )
{
	m_watchdog->watchdog_reset();
	return 0;
}

// only used now for "input bypass" hacks
READ8_MEMBER( tc0040ioc_device::port_r )
{
	return m_port;
}

WRITE8_MEMBER( tc0040ioc_device::port_w )
{
	m_port = data;
}

READ8_MEMBER( tc0040ioc_device::portreg_r )
{
	switch (m_port)
	{
		case 0x00:
			return m_read_0_cb(0);

		case 0x01:
			return m_read_1_cb(0);

		case 0x02:
			return m_read_2_cb(0);

		case 0x03:
			return m_read_3_cb(0);

		case 0x04:  /* coin counters and lockout */
			return m_regs[4];

		case 0x07:
			return m_read_7_cb(0);

		default:
//logerror("PC %06x: warning - read TC0040IOC address %02x\n",space.device().safe_pc(),m_port);
			return 0xff;
	}
}

WRITE8_MEMBER( tc0040ioc_device::portreg_w )
{
	if (m_port < ARRAY_LENGTH(m_regs))
		m_regs[m_port] = data;
	switch (m_port)
	{
		case 0x04:  /* coin counters and lockout, hi nibble irrelevant */
			m_write_4_cb(data & 0x0f);

//if (data & 0xf0)
//logerror("PC %06x: warning - write %02x to TC0040IOC address %02x\n",space.device().safe_pc(),data,m_port);

			break;

		default:
//logerror("PC %06x: warning - write %02x to TC0040IOC address %02x\n",space.device().safe_pc(),data,m_port);
			break;
	}
}


/***************************************************************************/
/*                                                                         */
/*                              TC0220IOC                                  */
/*                                                                         */
/***************************************************************************/

DEFINE_DEVICE_TYPE(TC0220IOC, tc0220ioc_device, "tc0220ioc", "Taito TC0220IOC")

tc0220ioc_device::tc0220ioc_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
	device_t(mconfig, TC0220IOC, tag, owner, clock),
	m_regs{ 0, 0, 0, 0, 0, 0, 0, 0 },
	m_watchdog(*this, "watchdog"),
	m_read_0_cb(*this),
	m_read_1_cb(*this),
	m_read_2_cb(*this),
	m_read_3_cb(*this),
	m_write_3_cb(*this),
	m_write_4_cb(*this),
	m_read_7_cb(*this)
{
}

//-------------------------------------------------
//  device_start - device-specific startup
//-------------------------------------------------

void tc0220ioc_device::device_start()
{
	m_read_0_cb.resolve_safe(0);
	m_read_1_cb.resolve_safe(0);
	m_read_2_cb.resolve_safe(0);
	m_read_3_cb.resolve_safe(0);
	m_write_3_cb.resolve_safe();
	m_write_4_cb.resolve_safe();
	m_read_7_cb.resolve_safe(0);

	save_item(NAME(m_regs));
}

//-------------------------------------------------
//  device_reset - device-specific reset
//-------------------------------------------------

void tc0220ioc_device::device_reset()
{
	for (auto & elem : m_regs)
		elem = 0;
}

//-------------------------------------------------
//  device_add_mconfig - add device configuration
//-------------------------------------------------

MACHINE_CONFIG_MEMBER( tc0220ioc_device::device_add_mconfig )
	MCFG_WATCHDOG_ADD("watchdog")
//	MCFG_WATCHDOG_TIME_INIT(attotime::from_msec(3200))
MACHINE_CONFIG_END

/*****************************************************************************
    DEVICE HANDLERS
*****************************************************************************/

READ8_MEMBER( tc0220ioc_device::read )
{
	switch (offset)
	{
		case 0x00:
			return m_read_0_cb(0);

		case 0x01:
			return m_read_1_cb(0);

		case 0x02:
			return m_read_2_cb(0);

		case 0x03:
			return m_read_3_cb(0);

		case 0x04:  /* coin counters and lockout */
			return m_regs[4];

		case 0x07:
			return m_read_7_cb(0);

		default:
//logerror("PC %06x: warning - read TC0220IOC address %02x\n",space.device().safe_pc(),offset);
			return 0xff;
	}
}

WRITE8_MEMBER( tc0220ioc_device::write )
{
	m_regs[offset] = data;
	switch (offset)
	{
		case 0x00:
			m_watchdog->watchdog_reset();
			break;

		case 0x03:
			m_write_3_cb(data);
			break;

		case 0x04:  /* coin counters and lockout, hi nibble irrelevant */
			m_write_4_cb(data & 0x0f);

//if (data & 0xf0)
//logerror("PC %06x: warning - write %02x to TC0220IOC address %02x\n",space.device().safe_pc(),data,offset);

			break;

		default:
//logerror("PC %06x: warning - write %02x to TC0220IOC address %02x\n",space.device().safe_pc(),data,offset);
			break;
	}
}

/***************************************************************************/
/*                                                                         */
/*                              TC0510NIO                                  */
/*                                                                         */
/***************************************************************************/


DEFINE_DEVICE_TYPE(TC0510NIO, tc0510nio_device, "tc0510nio", "Taito TC0510NIO")

tc0510nio_device::tc0510nio_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: device_t(mconfig, TC0510NIO, tag, owner, clock),
	m_watchdog(*this, "watchdog"),
	m_read_0_cb(*this),
	m_read_1_cb(*this),
	m_read_2_cb(*this),
	m_read_3_cb(*this),
	m_write_3_cb(*this),
	m_write_4_cb(*this),
	m_read_7_cb(*this)
{
}

//-------------------------------------------------
//  device_start - device-specific startup
//-------------------------------------------------

void tc0510nio_device::device_start()
{
	m_read_0_cb.resolve_safe(0);
	m_read_1_cb.resolve_safe(0);
	m_read_2_cb.resolve_safe(0);
	m_read_3_cb.resolve_safe(0);
	m_write_3_cb.resolve_safe();
	m_write_4_cb.resolve_safe();
	m_read_7_cb.resolve_safe(0);

	save_item(NAME(m_regs));
}

//-------------------------------------------------
//  device_reset - device-specific reset
//-------------------------------------------------

void tc0510nio_device::device_reset()
{
	for (auto & elem : m_regs)
		elem = 0;
}

//-------------------------------------------------
//  device_add_mconfig - add device configuration
//-------------------------------------------------

MACHINE_CONFIG_MEMBER( tc0510nio_device::device_add_mconfig )
	MCFG_WATCHDOG_ADD("watchdog")
MACHINE_CONFIG_END

/*****************************************************************************
    DEVICE HANDLERS
*****************************************************************************/

READ8_MEMBER( tc0510nio_device::read )
{
	switch (offset)
	{
		case 0x00:
			return m_read_0_cb(0);

		case 0x01:
			return m_read_1_cb(0);

		case 0x02:
			return m_read_2_cb(0);

		case 0x03:
			return m_read_3_cb(0);

		case 0x04:  /* coin counters and lockout */
			return m_regs[4];

		case 0x07:
			return m_read_7_cb(0);

		default:
//logerror("PC %06x: warning - read TC0510NIO address %02x\n",space.device().safe_pc(),offset);
			return 0xff;
	}
}

WRITE8_MEMBER( tc0510nio_device::write )
{
	m_regs[offset] = data;

	switch (offset)
	{
		case 0x00:
			m_watchdog->watchdog_reset();
			break;

		case 0x03:
			m_write_3_cb(data);
			break;

		case 0x04:  /* coin counters and lockout */
			m_write_4_cb(data & 0x0f);
			break;

		default:
//logerror("PC %06x: warning - write %02x to TC0510NIO address %02x\n",space.device().safe_pc(),data,offset);
			break;
	}
}

READ16_MEMBER( tc0510nio_device::halfword_r )
{
	return read(space, offset);
}

WRITE16_MEMBER( tc0510nio_device::halfword_w )
{
	if (ACCESSING_BITS_0_7)
		write(space, offset, data & 0xff);
	else
	{
		/* driftout writes the coin counters here - bug? */
//logerror("CPU #0 PC %06x: warning - write to MSB of TC0510NIO address %02x\n",space.device().safe_pc(),offset);
		write(space, offset, (data >> 8) & 0xff);
	}
}

READ16_MEMBER( tc0510nio_device::halfword_wordswap_r )
{
	return halfword_r(space, offset ^ 1, mem_mask);
}

WRITE16_MEMBER( tc0510nio_device::halfword_wordswap_w )
{
	halfword_w(space, offset ^ 1,data, mem_mask);
}


/***************************************************************************/
/*                                                                         */
/*                              TC0640FIO                                  */
/*                                                                         */
/***************************************************************************/


DEFINE_DEVICE_TYPE(TC0640FIO, tc0640fio_device, "tc0640fio", "Taito TC0640FIO")

tc0640fio_device::tc0640fio_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
	: device_t(mconfig, TC0640FIO, tag, owner, clock),
	m_watchdog(*this, "watchdog"),
	m_read_0_cb(*this),
	m_read_1_cb(*this),
	m_read_2_cb(*this),
	m_read_3_cb(*this),
	m_write_4_cb(*this),
	m_read_7_cb(*this)
{
}

//-------------------------------------------------
//  device_start - device-specific startup
//-------------------------------------------------

void tc0640fio_device::device_start()
{
	m_read_0_cb.resolve_safe(0);
	m_read_1_cb.resolve_safe(0);
	m_read_2_cb.resolve_safe(0);
	m_read_3_cb.resolve_safe(0);
	m_write_4_cb.resolve_safe();
	m_read_7_cb.resolve_safe(0);

	save_item(NAME(m_regs));
}

//-------------------------------------------------
//  device_reset - device-specific reset
//-------------------------------------------------

void tc0640fio_device::device_reset()
{
	for (auto & elem : m_regs)
		elem = 0;
}

//-------------------------------------------------
//  device_add_mconfig - add device configuration
//-------------------------------------------------

MACHINE_CONFIG_MEMBER( tc0640fio_device::device_add_mconfig )
	MCFG_WATCHDOG_ADD("watchdog")
MACHINE_CONFIG_END


/*****************************************************************************
    DEVICE HANDLERS
*****************************************************************************/

READ8_MEMBER( tc0640fio_device::read )
{
	switch (offset)
	{
		case 0x00:
			return m_read_0_cb(0);

		case 0x01:
			return m_read_1_cb(0);

		case 0x02:
			return m_read_2_cb(0);

		case 0x03:
			return m_read_3_cb(0);

		case 0x04:  /* coin counters and lockout */
			return m_regs[4];

		case 0x07:
			return m_read_7_cb(0);

		default:
//logerror("PC %06x: warning - read TC0640FIO address %02x\n",space.device().safe_pc(),offset);
			return 0xff;
	}
}

WRITE8_MEMBER( tc0640fio_device::write )
{
	m_regs[offset] = data;
	switch (offset)
	{
		case 0x00:
			m_watchdog->watchdog_reset();
			break;

		case 0x04:  /* coin counters and lockout */
			m_write_4_cb(data & 0x0f);
			break;

		default:
//logerror("PC %06x: warning - write %02x to TC0640FIO address %02x\n",space.device().safe_pc(),data,offset);
			break;
	}
}

READ16_MEMBER( tc0640fio_device::halfword_r )
{
	return read(space, offset);
}

WRITE16_MEMBER( tc0640fio_device::halfword_w )
{
	if (ACCESSING_BITS_0_7)
		write(space, offset, data & 0xff);
	else
	{
		write(space, offset, (data >> 8) & 0xff);
//logerror("CPU #0 PC %06x: warning - write to MSB of TC0640FIO address %02x\n",space.device().safe_pc(),offset);
	}
}

READ16_MEMBER( tc0640fio_device::halfword_byteswap_r )
{
	return halfword_r(space, offset, mem_mask) << 8;
}

WRITE16_MEMBER( tc0640fio_device::halfword_byteswap_w )
{
	if (ACCESSING_BITS_8_15)
		write(space, offset, (data >> 8) & 0xff);
	else
	{
		write(space, offset, data & 0xff);
//logerror("CPU #0 PC %06x: warning - write to LSB of TC0640FIO address %02x\n",space.device().safe_pc(),offset);
	}
}