summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/machine/tnzs.c
blob: a439f2eef4581b6b35087f3f186334cc532d0942 (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
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
/***************************************************************************

  machine.c

  Functions to emulate general aspects of the machine (RAM, ROM, interrupts,
  I/O ports)

  The I8742 MCU takes care of handling the coin inputs and the tilt switch.
  To simulate this, we read the status in the interrupt handler for the main
  CPU and update the counters appropriately. We also must take care of
  handling the coin/credit settings ourselves.

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

#include "emu.h"
#include "cpu/mcs48/mcs48.h"
#include "includes/tnzs.h"



READ8_MEMBER(tnzs_state::mcu_tnzs_r)
{
	UINT8 data;

	data = m_mcu->upi41_master_r(space, offset & 1);
	space.device().execute().yield();

//  logerror("PC %04x: read %02x from mcu $c00%01x\n", space.device().safe_pcbase(), data, offset);

	return data;
}

WRITE8_MEMBER(tnzs_state::mcu_tnzs_w)
{
//  logerror("PC %04x: write %02x to mcu $c00%01x\n", space.device().safe_pcbase(), data, offset);

	m_mcu->upi41_master_w(space, offset & 1, data);
}


READ8_MEMBER(tnzs_state::tnzs_port1_r)
{
	int data = 0;

	switch (m_input_select & 0x0f)
	{
		case 0x0a:  data = ioport("IN2")->read(); break;
		case 0x0c:  data = ioport("IN0")->read(); break;
		case 0x0d:  data = ioport("IN1")->read(); break;
		default:    data = 0xff; break;
	}

//  logerror("I8742:%04x  Read %02x from port 1\n", space.device().safe_pcbase(), data);

	return data;
}

READ8_MEMBER(tnzs_state::tnzs_port2_r)
{
	int data = ioport("IN2")->read();

//  logerror("I8742:%04x  Read %02x from port 2\n", space.device().safe_pcbase(), data);

	return data;
}

WRITE8_MEMBER(tnzs_state::tnzs_port2_w)
{
//  logerror("I8742:%04x  Write %02x to port 2\n", space.device().safe_pcbase(), data);

	coin_lockout_w(machine(), 0, (data & 0x40));
	coin_lockout_w(machine(), 1, (data & 0x80));
	coin_counter_w(machine(), 0, (~data & 0x10));
	coin_counter_w(machine(), 1, (~data & 0x20));

	m_input_select = data;
}



READ8_MEMBER(tnzs_state::arknoid2_sh_f000_r)
{
	int val;

//  logerror("PC %04x: read input %04x\n", space.device().safe_pc(), 0xf000 + offset);

	val = ioport((offset / 2) ? "AN2" : "AN1")->read_safe(0);
	if (offset & 1)
		return ((val >> 8) & 0xff);
	else
		return val & 0xff;
}


void tnzs_state::mcu_reset(  )
{
	m_mcu_initializing = 3;
	m_mcu_coinage_init = 0;
	m_mcu_coinage[0] = 1;
	m_mcu_coinage[1] = 1;
	m_mcu_coinage[2] = 1;
	m_mcu_coinage[3] = 1;
	m_mcu_coins_a = 0;
	m_mcu_coins_b = 0;
	m_mcu_credits = 0;
	m_mcu_reportcoin = 0;
	m_mcu_command = 0;
}

void tnzs_state::mcu_handle_coins( int coin )
{
	/* The coin inputs and coin counters are managed by the i8742 mcu. */
	/* Here we simulate it. */
	/* Credits are limited to 9, so more coins should be rejected */
	/* Coin/Play settings must also be taken into consideration */

	if (coin & 0x08)    /* tilt */
		m_mcu_reportcoin = coin;
	else if (coin && coin != m_insertcoin)
	{
		if (coin & 0x01)    /* coin A */
		{
//          logerror("Coin dropped into slot A\n");
			coin_counter_w(machine(),0,1); coin_counter_w(machine(),0,0); /* Count slot A */
			m_mcu_coins_a++;
			if (m_mcu_coins_a >= m_mcu_coinage[0])
			{
				m_mcu_coins_a -= m_mcu_coinage[0];
				m_mcu_credits += m_mcu_coinage[1];
				if (m_mcu_credits >= 9)
				{
					m_mcu_credits = 9;
					coin_lockout_global_w(machine(), 1); /* Lock all coin slots */
				}
				else
				{
					coin_lockout_global_w(machine(), 0); /* Unlock all coin slots */
				}
			}
		}

		if (coin & 0x02)    /* coin B */
		{
//          logerror("Coin dropped into slot B\n");
			coin_counter_w(machine(),1,1); coin_counter_w(machine(),1,0); /* Count slot B */
			m_mcu_coins_b++;
			if (m_mcu_coins_b >= m_mcu_coinage[2])
			{
				m_mcu_coins_b -= m_mcu_coinage[2];
				m_mcu_credits += m_mcu_coinage[3];
				if (m_mcu_credits >= 9)
				{
					m_mcu_credits = 9;
					coin_lockout_global_w(machine(), 1); /* Lock all coin slots */
				}
				else
				{
					coin_lockout_global_w(machine(), 0); /* Unlock all coin slots */
				}
			}
		}

		if (coin & 0x04)    /* service */
		{
//          logerror("Coin dropped into service slot C\n");
			m_mcu_credits++;
		}

		m_mcu_reportcoin = coin;
	}
	else
	{
		if (m_mcu_credits < 9)
			coin_lockout_global_w(machine(), 0); /* Unlock all coin slots */

		m_mcu_reportcoin = 0;
	}
	m_insertcoin = coin;
}


READ8_MEMBER(tnzs_state::mcu_arknoid2_r)
{
	static const char mcu_startup[] = "\x55\xaa\x5a";

//  logerror("PC %04x: read mcu %04x\n", space.device().safe_pc(), 0xc000 + offset);

	if (offset == 0)
	{
		/* if the mcu has just been reset, return startup code */
		if (m_mcu_initializing)
		{
			m_mcu_initializing--;
			return mcu_startup[2 - m_mcu_initializing];
		}

		switch (m_mcu_command)
		{
			case 0x41:
				return m_mcu_credits;

			case 0xc1:
				/* Read the credit counter or the inputs */
				if (m_mcu_readcredits == 0)
				{
					m_mcu_readcredits = 1;
					if (m_mcu_reportcoin & 0x08)
					{
						m_mcu_initializing = 3;
						return 0xee;    /* tilt */
					}
					else return m_mcu_credits;
				}
				else return ioport("IN0")->read();  /* buttons */

			default:
				logerror("error, unknown mcu command\n");
				/* should not happen */
				return 0xff;
		}
	}
	else
	{
		/*
		status bits:
		0 = mcu is ready to send data (read from c000)
		1 = mcu has read data (from c000)
		2 = unused
		3 = unused
		4-7 = coin code
		      0 = nothing
		      1,2,3 = coin switch pressed
		      e = tilt
		*/
		if (m_mcu_reportcoin & 0x08) return 0xe1;   /* tilt */
		if (m_mcu_reportcoin & 0x01) return 0x11;   /* coin 1 (will trigger "coin inserted" sound) */
		if (m_mcu_reportcoin & 0x02) return 0x21;   /* coin 2 (will trigger "coin inserted" sound) */
		if (m_mcu_reportcoin & 0x04) return 0x31;   /* coin 3 (will trigger "coin inserted" sound) */
		return 0x01;
	}
}

WRITE8_MEMBER(tnzs_state::mcu_arknoid2_w)
{
	if (offset == 0)
	{
//      logerror("PC %04x: write %02x to mcu %04x\n", space.device().safe_pc(), data, 0xc000 + offset);
		if (m_mcu_command == 0x41)
		{
			m_mcu_credits = (m_mcu_credits + data) & 0xff;
		}
	}
	else
	{
		/*
		0xc1: read number of credits, then buttons
		0x54+0x41: add value to number of credits
		0x15: sub 1 credit (when "Continue Play" only)
		0x84: coin 1 lockout (issued only in test mode)
		0x88: coin 2 lockout (issued only in test mode)
		0x80: release coin lockout (issued only in test mode)
		during initialization, a sequence of 4 bytes sets coin/credit settings
		*/
//      logerror("PC %04x: write %02x to mcu %04x\n", space.device().safe_pc(), data, 0xc000 + offset);

		if (m_mcu_initializing)
		{
			/* set up coin/credit settings */
			m_mcu_coinage[m_mcu_coinage_init++] = data;
			if (m_mcu_coinage_init == 4)
				m_mcu_coinage_init = 0; /* must not happen */
		}

		if (data == 0xc1)
			m_mcu_readcredits = 0;  /* reset input port number */

		if (data == 0x15)
		{
			m_mcu_credits = (m_mcu_credits - 1) & 0xff;
			if (m_mcu_credits == 0xff)
				m_mcu_credits = 0;
		}
		m_mcu_command = data;
	}
}


READ8_MEMBER(tnzs_state::mcu_extrmatn_r)
{
	static const char mcu_startup[] = "\x5a\xa5\x55";

//  logerror("PC %04x: read mcu %04x\n", space.device().safe_pc(), 0xc000 + offset);

	if (offset == 0)
	{
		/* if the mcu has just been reset, return startup code */
		if (m_mcu_initializing)
		{
			m_mcu_initializing--;
			return mcu_startup[2 - m_mcu_initializing];
		}

		switch (m_mcu_command)
		{
			case 0x01:
				return ioport("IN0")->read() ^ 0xff;    /* player 1 joystick + buttons */

			case 0x02:
				return ioport("IN1")->read() ^ 0xff;    /* player 2 joystick + buttons */

			case 0x1a:
				return (ioport("COIN1")->read() | (ioport("COIN2")->read() << 1));

			case 0x21:
				return ioport("IN2")->read() & 0x0f;

			case 0x41:
				return m_mcu_credits;

			case 0xa0:
				/* Read the credit counter */
				if (m_mcu_reportcoin & 0x08)
				{
					m_mcu_initializing = 3;
					return 0xee;    /* tilt */
				}
				else return m_mcu_credits;

			case 0xa1:
				/* Read the credit counter or the inputs */
				if (m_mcu_readcredits == 0)
				{
					m_mcu_readcredits = 1;
					if (m_mcu_reportcoin & 0x08)
					{
						m_mcu_initializing = 3;
						return 0xee;    /* tilt */
//                      return 0x64;    /* theres a reset input somewhere */
					}
					else return m_mcu_credits;
				}
				/* buttons */
				else return ((ioport("IN0")->read() & 0xf0) | (ioport("IN1")->read() >> 4)) ^ 0xff;

			default:
				logerror("error, unknown mcu command\n");
				/* should not happen */
				return 0xff;
		}
	}
	else
	{
		/*
		status bits:
		0 = mcu is ready to send data (read from c000)
		1 = mcu has read data (from c000)
		2 = unused
		3 = unused
		4-7 = coin code
		      0 = nothing
		      1,2,3 = coin switch pressed
		      e = tilt
		*/
		if (m_mcu_reportcoin & 0x08) return 0xe1;   /* tilt */
		if (m_mcu_reportcoin & 0x01) return 0x11;   /* coin 1 (will trigger "coin inserted" sound) */
		if (m_mcu_reportcoin & 0x02) return 0x21;   /* coin 2 (will trigger "coin inserted" sound) */
		if (m_mcu_reportcoin & 0x04) return 0x31;   /* coin 3 (will trigger "coin inserted" sound) */
		return 0x01;
	}
}

WRITE8_MEMBER(tnzs_state::mcu_extrmatn_w)
{
	if (offset == 0)
	{
//      logerror("PC %04x: write %02x to mcu %04x\n", space.device().safe_pc(), data, 0xc000 + offset);
		if (m_mcu_command == 0x41)
		{
			m_mcu_credits = (m_mcu_credits + data) & 0xff;
		}
	}
	else
	{
		/*
		0xa0: read number of credits
		0xa1: read number of credits, then buttons
		0x01: read player 1 joystick + buttons
		0x02: read player 2 joystick + buttons
		0x1a: read coin switches
		0x21: read service & tilt switches
		0x4a+0x41: add value to number of credits
		0x84: coin 1 lockout (issued only in test mode)
		0x88: coin 2 lockout (issued only in test mode)
		0x80: release coin lockout (issued only in test mode)
		during initialization, a sequence of 4 bytes sets coin/credit settings
		*/

//      logerror("PC %04x: write %02x to mcu %04x\n", space.device().safe_pc(), data, 0xc000 + offset);

		if (m_mcu_initializing)
		{
			/* set up coin/credit settings */
			m_mcu_coinage[m_mcu_coinage_init++] = data;
			if (m_mcu_coinage_init == 4)
				m_mcu_coinage_init = 0; /* must not happen */
		}

		if (data == 0xa1)
			m_mcu_readcredits = 0;  /* reset input port number */

		/* Dr Toppel decrements credits differently. So handle it */
		if ((data == 0x09) && (m_mcu_type == MCU_DRTOPPEL || m_mcu_type == MCU_PLUMPOP))
			m_mcu_credits = (m_mcu_credits - 1) & 0xff;     /* Player 1 start */
		if ((data == 0x18) && (m_mcu_type == MCU_DRTOPPEL || m_mcu_type == MCU_PLUMPOP))
			m_mcu_credits = (m_mcu_credits - 2) & 0xff;     /* Player 2 start */

		m_mcu_command = data;
	}
}



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

TNZS sync bug kludge

In all TNZS versions there is code like this:

0C5E: ld   ($EF10),a
0C61: ld   a,($EF10)
0C64: inc  a
0C65: ret  nz
0C66: jr   $0C61

which is sometimes executed by the main cpu when it writes to shared RAM a
command for the second CPU. The intended purpose of the code is to wait an
acknowledge from the sub CPU: the sub CPU writes FF to the same location
after reading the command.

However the above code is wrong. The "ret nz" instruction means that the
loop will be exited only when the contents of $EF10 are *NOT* $FF!!
On the real board, this casues little harm: the main CPU will just write
the command, read it back and, since it's not $FF, return immediately. There
is a chance that the command might go lost, but this will cause no major
harm, the worse that can happen is that the background tune will not change.

In MAME, however, since CPU interleaving is not perfect, it can happen that
the main CPU ends its timeslice after writing to EF10 but before reading it
back. In the meantime, the sub CPU will run, read the command and write FF
there - therefore causing the main CPU to enter an endless loop.

Unlike the usual sync problems in MAME, which can be fixed by increasing the
interleave factor, in this case increasing it will actually INCREASE the
chance of entering the endless loop - because it will increase the chances of
the main CPU ending its timeslice at the wrong moment.

So what we do here is catch writes by the main CPU to the RAM location, and
process them using a timer, in order to
a) force a resync of the two CPUs
b) make sure the main CPU will be the first one to run after the location is
   changed

Since the answer from the sub CPU is ignored, we don't even need to boost
interleave.

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

/*
TIMER_CALLBACK_MEMBER(tnzs_state::kludge_callback)
{
    tnzs_sharedram[0x0f10] = param;
}

WRITE8_MEMBER(tnzs_state::tnzs_sync_kludge_w)
{
    machine().scheduler().synchronize(timer_expired_delegate(FUNC(tnzs_state::kludge_callback),this), data);
}
*/



DRIVER_INIT_MEMBER(tnzs_state,plumpop)
{
	m_mcu_type = MCU_PLUMPOP;
}

DRIVER_INIT_MEMBER(tnzs_state,extrmatn)
{
	m_mcu_type = MCU_EXTRMATN;
}

DRIVER_INIT_MEMBER(tnzs_state,arknoid2)
{
	m_mcu_type = MCU_ARKANOID;
}

DRIVER_INIT_MEMBER(tnzs_state,drtoppel)
{
	m_mcu_type = MCU_DRTOPPEL;

	/* drtoppel writes to the palette RAM area even if it has PROMs! We have to patch it out. */
	m_maincpu->space(AS_PROGRAM).nop_write(0xf800, 0xfbff);
}

DRIVER_INIT_MEMBER(tnzs_state,chukatai)
{
	m_mcu_type = MCU_CHUKATAI;
}

DRIVER_INIT_MEMBER(tnzs_state,tnzs)
{
	m_mcu_type = MCU_TNZS;
	/* we need to install a kludge to avoid problems with a bug in the original code */
//  m_maincpu->space(AS_PROGRAM).install_write_handler(0xef10, 0xef10, write8_delegate(FUNC(tnzs_state::tnzs_sync_kludge_w), this));
}

DRIVER_INIT_MEMBER(tnzs_state,tnzsb)
{
	m_mcu_type = MCU_NONE_TNZSB;

	/* we need to install a kludge to avoid problems with a bug in the original code */
//  m_maincpu->space(AS_PROGRAM).install_write_handler(0xef10, 0xef10, write8_delegate(FUNC(tnzs_state::tnzs_sync_kludge_w), this));
}

DRIVER_INIT_MEMBER(tnzs_state,kabukiz)
{
	UINT8 *SOUND = memregion("audiocpu")->base();
	m_mcu_type = MCU_NONE_KABUKIZ;

	membank("audiobank")->configure_entries(0, 8, &SOUND[0x00000], 0x4000);
}

DRIVER_INIT_MEMBER(tnzs_state,insectx)
{
	m_mcu_type = MCU_NONE_INSECTX;

	/* this game has no mcu, replace the handler with plain input port handlers */
	m_subcpu->space(AS_PROGRAM).install_read_port(0xc000, 0xc000, "IN0" );
	m_subcpu->space(AS_PROGRAM).install_read_port(0xc001, 0xc001, "IN1" );
	m_subcpu->space(AS_PROGRAM).install_read_port(0xc002, 0xc002, "IN2" );
}

DRIVER_INIT_MEMBER(tnzs_state,kageki)
{
	m_mcu_type = MCU_NONE_KAGEKI;
}


READ8_MEMBER(tnzs_state::tnzs_mcu_r)
{
	switch (m_mcu_type)
	{
		case MCU_TNZS:
		case MCU_CHUKATAI:
			return mcu_tnzs_r(space, offset);
		case MCU_ARKANOID:
			return mcu_arknoid2_r(space, offset);
		case MCU_EXTRMATN:
		case MCU_DRTOPPEL:
		case MCU_PLUMPOP:
			return mcu_extrmatn_r(space, offset);
		default:
			return 0xff;
	}
}

WRITE8_MEMBER(tnzs_state::tnzs_mcu_w)
{
	switch (m_mcu_type)
	{
		case MCU_TNZS:
		case MCU_CHUKATAI:
			mcu_tnzs_w(space, offset, data);
			break;
		case MCU_ARKANOID:
			mcu_arknoid2_w(space, offset, data);
			break;
		case MCU_EXTRMATN:
		case MCU_DRTOPPEL:
		case MCU_PLUMPOP:
			mcu_extrmatn_w(space, offset, data);
			break;
		default:
			break;
	}
}

INTERRUPT_GEN_MEMBER(tnzs_state::arknoid2_interrupt)
{
	int coin;

	switch (m_mcu_type)
	{
		case MCU_ARKANOID:
		case MCU_EXTRMATN:
		case MCU_DRTOPPEL:
		case MCU_PLUMPOP:
			coin  = 0;
			coin |= ((ioport("COIN1")->read() & 1) << 0);
			coin |= ((ioport("COIN2")->read() & 1) << 1);
			coin |= ((ioport("IN2")->read() & 3) << 2);
			coin ^= 0x0c;
			mcu_handle_coins(coin);
			break;
		default:
			break;
	}

	device.execute().set_input_line(0, HOLD_LINE);
}

MACHINE_RESET_MEMBER(tnzs_state,tnzs)
{
	/* initialize the mcu simulation */
	switch (m_mcu_type)
	{
		case MCU_ARKANOID:
		case MCU_EXTRMATN:
		case MCU_DRTOPPEL:
		case MCU_PLUMPOP:
			mcu_reset();
			break;
		default:
			break;
	}

	m_kageki_csport_sel = 0;
	m_input_select = 0;
	m_mcu_readcredits = 0;  // this might belong to mcu_reset
	m_insertcoin = 0;       // this might belong to mcu_reset
}

MACHINE_RESET_MEMBER(tnzs_state,jpopnics)
{
	m_mcu_type = -1;
}


MACHINE_START_MEMBER(tnzs_state,tnzs_common)
{
	UINT8 *SUB = memregion("sub")->base();
	
	membank("subbank")->configure_entries(0, 4, &SUB[0x08000], 0x2000);
	membank("subbank")->set_entry(m_bank2);

	m_bank2 = 0;
	m_mainbank->set_bank(2);

	save_item(NAME(m_bank2));
}

MACHINE_START_MEMBER(tnzs_state,tnzs)
{
	MACHINE_START_CALL_MEMBER( tnzs_common );

	save_item(NAME(m_kageki_csport_sel));
	save_item(NAME(m_input_select));
	save_item(NAME(m_mcu_readcredits));
	save_item(NAME(m_insertcoin));
	save_item(NAME(m_mcu_initializing));
	save_item(NAME(m_mcu_coinage_init));
	save_item(NAME(m_mcu_coinage));
	save_item(NAME(m_mcu_coins_a));
	save_item(NAME(m_mcu_coins_b));
	save_item(NAME(m_mcu_credits));
	save_item(NAME(m_mcu_reportcoin));
	save_item(NAME(m_mcu_command));

}


WRITE8_MEMBER(tnzs_state::tnzs_ramrom_bankswitch_w)
{
//  logerror("PC %04x: writing %02x to bankswitch\n", space.device().safe_pc(),data);

	/* bit 4 resets the second CPU */
	if (data & 0x10)
		m_subcpu->set_input_line(INPUT_LINE_RESET, CLEAR_LINE);
	else
		m_subcpu->set_input_line(INPUT_LINE_RESET, ASSERT_LINE);

	/* bits 0-2 select RAM/ROM bank */
	m_mainbank->set_bank(data & 0x07);
}

WRITE8_MEMBER(tnzs_state::tnzs_bankswitch1_w)
{
//  logerror("PC %04x: writing %02x to bankswitch 1\n", space.device().safe_pc(),data);

	switch (m_mcu_type)
	{
		case MCU_TNZS:
		case MCU_CHUKATAI:
				/* bit 2 resets the mcu */
				if (data & 0x04)
				{
					if (m_mcu != NULL && m_mcu->type() == I8742)
						m_mcu->set_input_line(INPUT_LINE_RESET, PULSE_LINE);
				}
				/* Coin count and lockout is handled by the i8742 */
				break;
		case MCU_NONE_INSECTX:
				coin_lockout_w(machine(), 0, (~data & 0x04));
				coin_lockout_w(machine(), 1, (~data & 0x08));
				coin_counter_w(machine(), 0, (data & 0x10));
				coin_counter_w(machine(), 1, (data & 0x20));
				break;
		case MCU_NONE_TNZSB:
		case MCU_NONE_KABUKIZ:
				coin_lockout_w(machine(), 0, (~data & 0x10));
				coin_lockout_w(machine(), 1, (~data & 0x20));
				coin_counter_w(machine(), 0, (data & 0x04));
				coin_counter_w(machine(), 1, (data & 0x08));
				break;
		case MCU_NONE_KAGEKI:
				coin_lockout_global_w(machine(), (~data & 0x20));
				coin_counter_w(machine(), 0, (data & 0x04));
				coin_counter_w(machine(), 1, (data & 0x08));
				break;
		case MCU_ARKANOID:
		case MCU_EXTRMATN:
		case MCU_DRTOPPEL:
		case MCU_PLUMPOP:
				/* bit 2 resets the mcu */
				if (data & 0x04)
					mcu_reset();
				break;
		default:
				break;
	}

	/* bits 0-1 select ROM bank */
	m_bank2 = data & 0x03;
	membank("subbank")->set_entry(m_bank2);
}