summaryrefslogblamecommitdiffstatshomepage
path: root/src/mame/machine/midtunit.c
blob: b9fa00434f13511c8f7c960be7eb03baa0882996 (plain) (tree)
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




















































































































































































































































































































































































































































































































































































































































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

    Driver for Midway T-unit games.

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

#include "driver.h"
#include "cpu/tms34010/tms34010.h"
#include "cpu/m6809/m6809.h"
#include "audio/williams.h"
#include "audio/dcs.h"
#include "midtunit.h"


/* compile-time constants */
#define ENABLE_ALL_JDREDD_LEVELS	0


/* constant definitions */
#define SOUND_ADPCM					1
#define SOUND_ADPCM_LARGE			2
#define SOUND_DCS					3


/* CMOS-related variables */
static UINT8	cmos_write_enable;

/* sound-related variables */
static UINT8	chip_type;
static UINT8	fake_sound_state;

/* protection */
static UINT8 	mk_prot_index;
static UINT16 	mk2_prot_data;

static const UINT32 *nbajam_prot_table;
static UINT16	nbajam_prot_queue[5];
static UINT8	nbajam_prot_index;

static const UINT8 *jdredd_prot_table;
static UINT8 	jdredd_prot_index;
static UINT8 	jdredd_prot_max;



/*************************************
 *
 *  State saving
 *
 *************************************/

static void register_state_saving(void)
{
	state_save_register_global(cmos_write_enable);
	state_save_register_global(fake_sound_state);
	state_save_register_global(mk_prot_index);
	state_save_register_global(mk2_prot_data);
	state_save_register_global_array(nbajam_prot_queue);
	state_save_register_global(nbajam_prot_index);
	state_save_register_global(jdredd_prot_index);
	state_save_register_global(jdredd_prot_max);
}



/*************************************
 *
 *  CMOS reads/writes
 *
 *************************************/

WRITE16_HANDLER( midtunit_cmos_enable_w )
{
	cmos_write_enable = 1;
}


WRITE16_HANDLER( midtunit_cmos_w )
{
	if (1)/*cmos_write_enable)*/
	{
		COMBINE_DATA(generic_nvram16+offset);
		cmos_write_enable = 0;
	}
	else
	{
		logerror("%08X:Unexpected CMOS W @ %05X\n", activecpu_get_pc(), offset);
		popmessage("Bad CMOS write");
	}
}


READ16_HANDLER( midtunit_cmos_r )
{
	return generic_nvram16[offset];
}



/*************************************
 *
 *  Generic input ports
 *
 *************************************/

READ16_HANDLER( midtunit_input_r )
{
	return readinputport(offset);
}



/*************************************
 *
 *  Mortal Kombat (T-unit) protection
 *
 *************************************/

static const UINT8 mk_prot_values[] =
{
	0x13, 0x27, 0x0f, 0x1f, 0x3e, 0x3d, 0x3b, 0x37,
	0x2e, 0x1c, 0x38, 0x31, 0x22, 0x05, 0x0a, 0x15,
	0x2b, 0x16, 0x2d, 0x1a, 0x34, 0x28, 0x10, 0x21,
	0x03, 0x06, 0x0c, 0x19, 0x32, 0x24, 0x09, 0x13,
	0x27, 0x0f, 0x1f, 0x3e, 0x3d, 0x3b, 0x37, 0x2e,
	0x1c, 0x38, 0x31, 0x22, 0x05, 0x0a, 0x15, 0x2b,
	0x16, 0x2d, 0x1a, 0x34, 0x28, 0x10, 0x21, 0x03,
	0xff
};

static READ16_HANDLER( mk_prot_r )
{
	logerror("%08X:Protection R @ %05X = %04X\n", activecpu_get_pc(), offset, mk_prot_values[mk_prot_index] << 9);

	/* just in case */
	if (mk_prot_index >= sizeof(mk_prot_values))
	{
		logerror("%08X:Unexpected protection R @ %05X\n", activecpu_get_pc(), offset);
		mk_prot_index = 0;
	}

	return mk_prot_values[mk_prot_index++] << 9;
}

static WRITE16_HANDLER( mk_prot_w )
{
	if (ACCESSING_MSB)
	{
		int first_val = (data >> 9) & 0x3f;
		int i;

		/* find the desired first value and stop then */
		for (i = 0; i < sizeof(mk_prot_values); i++)
			if (mk_prot_values[i] == first_val)
			{
				mk_prot_index = i;
				break;
			}

		/* just in case */
		if (i == sizeof(mk_prot_values))
		{
			logerror("%08X:Unhandled protection W @ %05X = %04X\n", activecpu_get_pc(), offset, data);
			mk_prot_index = 0;
		}

		logerror("%08X:Protection W @ %05X = %04X\n", activecpu_get_pc(), offset, data);
	}
}



/*************************************
 *
 *  Mortal Kombat 2 protection
 *
 *************************************/

static READ16_HANDLER( mk2_prot_const_r )
{
	return 2;
}

static READ16_HANDLER( mk2_prot_r )
{
	return mk2_prot_data;
}

static READ16_HANDLER( mk2_prot_shift_r )
{
	return mk2_prot_data >> 1;
}

static WRITE16_HANDLER( mk2_prot_w )
{
	COMBINE_DATA(&mk2_prot_data);
}



/*************************************
 *
 *  NBA Jam protection
 *
 *************************************/

static const UINT32 nbajam_prot_values[128] =
{
	0x21283b3b, 0x2439383b, 0x31283b3b, 0x302b3938, 0x31283b3b, 0x302b3938, 0x232f2f2f, 0x26383b3b,
	0x21283b3b, 0x2439383b, 0x312a1224, 0x302b1120, 0x312a1224, 0x302b1120, 0x232d283b, 0x26383b3b,
	0x2b3b3b3b, 0x2e2e2e2e, 0x39383b1b, 0x383b3b1b, 0x3b3b3b1b, 0x3a3a3a1a, 0x2b3b3b3b, 0x2e2e2e2e,
	0x2b39383b, 0x2e2e2e2e, 0x393a1a18, 0x383b1b1b, 0x3b3b1b1b, 0x3a3a1a18, 0x2b39383b, 0x2e2e2e2e,
	0x01202b3b, 0x0431283b, 0x11202b3b, 0x1021283b, 0x11202b3b, 0x1021283b, 0x03273b3b, 0x06302b39,
	0x09302b39, 0x0c232f2f, 0x19322e06, 0x18312a12, 0x19322e06, 0x18312a12, 0x0b31283b, 0x0e26383b,
	0x03273b3b, 0x06302b39, 0x11202b3b, 0x1021283b, 0x13273938, 0x12243938, 0x03273b3b, 0x06302b39,
	0x0b31283b, 0x0e26383b, 0x19322e06, 0x18312a12, 0x1b332f05, 0x1a302b11, 0x0b31283b,	0x0e26383b,
	0x21283b3b, 0x2439383b, 0x31283b3b, 0x302b3938, 0x31283b3b, 0x302b3938, 0x232f2f2f, 0x26383b3b,
	0x21283b3b, 0x2439383b, 0x312a1224, 0x302b1120, 0x312a1224, 0x302b1120, 0x232d283b, 0x26383b3b,
	0x2b3b3b3b, 0x2e2e2e2e, 0x39383b1b, 0x383b3b1b, 0x3b3b3b1b, 0x3a3a3a1a, 0x2b3b3b3b, 0x2e2e2e2e,
	0x2b39383b, 0x2e2e2e2e, 0x393a1a18, 0x383b1b1b, 0x3b3b1b1b, 0x3a3a1a18, 0x2b39383b, 0x2e2e2e2e,
	0x01202b3b, 0x0431283b, 0x11202b3b, 0x1021283b, 0x11202b3b, 0x1021283b, 0x03273b3b, 0x06302b39,
	0x09302b39, 0x0c232f2f, 0x19322e06, 0x18312a12, 0x19322e06, 0x18312a12, 0x0b31283b, 0x0e26383b,
	0x03273b3b, 0x06302b39, 0x11202b3b, 0x1021283b, 0x13273938, 0x12243938, 0x03273b3b, 0x06302b39,
	0x0b31283b, 0x0e26383b, 0x19322e06, 0x18312a12, 0x1b332f05, 0x1a302b11, 0x0b31283b,	0x0e26383b
};

static const UINT32 nbajamte_prot_values[128] =
{
	0x00000000, 0x04081020, 0x08102000, 0x0c183122, 0x10200000, 0x14281020, 0x18312204, 0x1c393326,
	0x20000001, 0x24081021, 0x28102000, 0x2c183122, 0x30200001, 0x34281021, 0x38312204, 0x3c393326,
	0x00000102, 0x04081122, 0x08102102, 0x0c183122, 0x10200000, 0x14281020, 0x18312204, 0x1c393326,
	0x20000103, 0x24081123, 0x28102102, 0x2c183122, 0x30200001, 0x34281021, 0x38312204, 0x3c393326,
	0x00010204, 0x04091224, 0x08112204, 0x0c193326, 0x10210204, 0x14291224, 0x18312204, 0x1c393326,
	0x20000001, 0x24081021, 0x28102000, 0x2c183122, 0x30200001, 0x34281021, 0x38312204, 0x3c393326,
	0x00010306, 0x04091326, 0x08112306, 0x0c193326, 0x10210204, 0x14291224, 0x18312204, 0x1c393326,
	0x20000103, 0x24081123, 0x28102102, 0x2c183122, 0x30200001, 0x34281021, 0x38312204, 0x3c393326,
	0x00000000, 0x01201028, 0x02213018, 0x03012030, 0x04223138, 0x05022110, 0x06030120, 0x07231108,
	0x08042231, 0x09243219, 0x0a251229, 0x0b050201, 0x0c261309, 0x0d060321, 0x0e072311, 0x0f273339,
	0x10080422, 0x1128140a, 0x1229343a, 0x13092412, 0x142a351a, 0x150a2532, 0x160b0502, 0x172b152a,
	0x180c2613, 0x192c363b, 0x1a2d160b, 0x1b0d0623, 0x1c2e172b, 0x1d0e0703, 0x1e0f2733, 0x1f2f371b,
	0x20100804, 0x2130182c, 0x2231381c, 0x23112834, 0x2432393c, 0x25122914, 0x26130924, 0x2733190c,
	0x28142a35, 0x29343a1d, 0x2a351a2d, 0x2b150a05, 0x2c361b0d, 0x2d160b25, 0x2e172b15, 0x2f373b3d,
	0x30180c26, 0x31381c0e, 0x32393c3e, 0x33192c16, 0x343a3d1e, 0x351a2d36, 0x361b0d06, 0x373b1d2e,
	0x381c2e17, 0x393c3e3f, 0x3a3d1e0f, 0x3b1d0e27, 0x3c3e1f2f, 0x3d1e0f07, 0x3e1f2f37, 0x3f3f3f1f
};

static READ16_HANDLER( nbajam_prot_r )
{
	int result = nbajam_prot_queue[nbajam_prot_index];
	if (nbajam_prot_index < 4)
		nbajam_prot_index++;
	return result;
}

static WRITE16_HANDLER( nbajam_prot_w )
{
	int table_index = (offset >> 6) & 0x7f;
	UINT32 protval = nbajam_prot_table[table_index];

	nbajam_prot_queue[0] = data;
	nbajam_prot_queue[1] = ((protval >> 24) & 0xff) << 9;
	nbajam_prot_queue[2] = ((protval >> 16) & 0xff) << 9;
	nbajam_prot_queue[3] = ((protval >> 8) & 0xff) << 9;
	nbajam_prot_queue[4] = ((protval >> 0) & 0xff) << 9;
	nbajam_prot_index = 0;
}



/*************************************
 *
 *  Judge Dredd protection
 *
 *************************************/

static const UINT8 jdredd_prot_values_10740[] =
{
	0x14,0x2A,0x15,0x0A,0x25,0x32,0x39,0x1C,
	0x2E,0x37,0x3B,0x1D,0x2E,0x37,0x1B,0x0D,
	0x26,0x33,0x39,0x3C,0x1E,0x2F,0x37,0x3B,
	0x3D,0x3E,0x3F,0x1F,0x2F,0x17,0x0B,0x25,
	0x32,0x19,0x0C,0x26,0x33,0x19,0x2C,0x16,
	0x2B,0x15,0x0A,0x05,0x22,0x00
};

static const UINT8 jdredd_prot_values_13240[] =
{
	0x28
};

static const UINT8 jdredd_prot_values_76540[] =
{
	0x04,0x08
};

static const UINT8 jdredd_prot_values_77760[] =
{
	0x14,0x2A,0x14,0x2A,0x35,0x2A,0x35,0x1A,
	0x35,0x1A,0x2D,0x1A,0x2D,0x36,0x2D,0x36,
	0x1B,0x36,0x1B,0x36,0x2C,0x36,0x2C,0x18,
	0x2C,0x18,0x31,0x18,0x31,0x22,0x31,0x22,
	0x04,0x22,0x04,0x08,0x04,0x08,0x10,0x08,
	0x10,0x20,0x10,0x20,0x00,0x20,0x00,0x00,
	0x00,0x00,0x01,0x00,0x01,0x02,0x01,0x02,
	0x05,0x02,0x05,0x0B,0x05,0x0B,0x16,0x0B,
	0x16,0x2C,0x16,0x2C,0x18,0x2C,0x18,0x31,
	0x18,0x31,0x22,0x31,0x22,0x04,0x22,0x04,
	0x08,0x04,0x08,0x10,0x08,0x10,0x20,0x10,
	0x20,0x00,0x00
};

static const UINT8 jdredd_prot_values_80020[] =
{
	0x3A,0x1D,0x2E,0x37,0x00,0x00,0x2C,0x1C,
	0x39,0x33,0x00,0x00,0x00,0x00,0x00,0x00
};

static WRITE16_HANDLER( jdredd_prot_w )
{
	logerror("%08X:jdredd_prot_w(%04X,%04X)\n", activecpu_get_previouspc(), offset*16, data);

	switch (offset)
	{
		case TOWORD(0x10740):
			jdredd_prot_index = 0;
			jdredd_prot_table = jdredd_prot_values_10740;
			jdredd_prot_max = sizeof(jdredd_prot_values_10740);
			logerror("-- reset prot table 10740\n");
			break;

		case TOWORD(0x13240):
			jdredd_prot_index = 0;
			jdredd_prot_table = jdredd_prot_values_13240;
			jdredd_prot_max = sizeof(jdredd_prot_values_13240);
			logerror("-- reset prot table 13240\n");
			break;

		case TOWORD(0x76540):
			jdredd_prot_index = 0;
			jdredd_prot_table = jdredd_prot_values_76540;
			jdredd_prot_max = sizeof(jdredd_prot_values_76540);
			logerror("-- reset prot table 76540\n");
			break;

		case TOWORD(0x77760):
			jdredd_prot_index = 0;
			jdredd_prot_table = jdredd_prot_values_77760;
			jdredd_prot_max = sizeof(jdredd_prot_values_77760);
			logerror("-- reset prot table 77760\n");
			break;

		case TOWORD(0x80020):
			jdredd_prot_index = 0;
			jdredd_prot_table = jdredd_prot_values_80020;
			jdredd_prot_max = sizeof(jdredd_prot_values_80020);
			logerror("-- reset prot table 80020\n");
			break;
	}
}

static READ16_HANDLER( jdredd_prot_r )
{
	UINT16 result = 0xffff;

	if (jdredd_prot_table && jdredd_prot_index < jdredd_prot_max)
		result = jdredd_prot_table[jdredd_prot_index++] << 9;

	logerror("%08X:jdredd_prot_r(%04X) = %04X\n", activecpu_get_previouspc(), offset*16, result);
	return result;
}


#if ENABLE_ALL_JDREDD_LEVELS
static UINT16 *jdredd_hack;
static READ16_HANDLER( jdredd_hack_r )
{
	if (activecpu_get_pc() == 0xFFBA7EB0)
	{
		fprintf(stderr, "jdredd_hack_r\n");
		return 0;
	}

	return jdredd_hack[offset];
}
#endif



/*************************************
 *
 *  Generic driver init
 *
 *************************************/

static void init_tunit_generic(int sound)
{
	offs_t gfx_chunk = midyunit_gfx_rom_size / 4;
	UINT8 *base;
	int i;

	/* register for state saving */
	register_state_saving();

	/* load the graphics ROMs -- quadruples */
	base = memory_region(REGION_GFX1);
	for (i = 0; i < midyunit_gfx_rom_size; i += 4)
	{
		midyunit_gfx_rom[i + 0] = base[0 * gfx_chunk + i / 4];
		midyunit_gfx_rom[i + 1] = base[1 * gfx_chunk + i / 4];
		midyunit_gfx_rom[i + 2] = base[2 * gfx_chunk + i / 4];
		midyunit_gfx_rom[i + 3] = base[3 * gfx_chunk + i / 4];
	}

	/* load sound ROMs and set up sound handlers */
	chip_type = sound;
	switch (sound)
	{
		case SOUND_ADPCM:
		case SOUND_ADPCM_LARGE:
			williams_adpcm_init();
			break;

		case SOUND_DCS:
			dcs_init();
			break;
	}

	/* default graphics functionality */
	midtunit_gfx_rom_large = 0;
}



/*************************************
 *
 *  T-unit init (ADPCM)
 *
 *  music: 6809 driving YM2151, DAC, and OKIM6295
 *
 *************************************/

DRIVER_INIT( mktunit )
{
	/* common init */
	init_tunit_generic(SOUND_ADPCM);

	/* protection */
	memory_install_read16_handler(0, ADDRESS_SPACE_PROGRAM, 0x1b00000, 0x1b6ffff, 0, 0, mk_prot_r);
	memory_install_write16_handler(0, ADDRESS_SPACE_PROGRAM, 0x1b00000, 0x1b6ffff, 0, 0, mk_prot_w);

	/* sound chip protection (hidden RAM) */
	memory_install_write8_handler(1, ADDRESS_SPACE_PROGRAM, 0xfb9c, 0xfbc6, 0, 0, MWA8_RAM);
}

static void init_nbajam_common(int te_protection)
{
	/* common init */
	init_tunit_generic(SOUND_ADPCM_LARGE);

	/* protection */
	if (!te_protection)
	{
		nbajam_prot_table = nbajam_prot_values;
		memory_install_read16_handler(0, ADDRESS_SPACE_PROGRAM, 0x1b14020, 0x1b2503f, 0, 0, nbajam_prot_r);
		memory_install_write16_handler(0, ADDRESS_SPACE_PROGRAM, 0x1b14020, 0x1b2503f, 0, 0, nbajam_prot_w);
	}
	else
	{
		nbajam_prot_table = nbajamte_prot_values;
		memory_install_read16_handler(0, ADDRESS_SPACE_PROGRAM, 0x1b15f40, 0x1b37f5f, 0, 0, nbajam_prot_r);
		memory_install_read16_handler(0, ADDRESS_SPACE_PROGRAM, 0x1b95f40, 0x1bb7f5f, 0, 0, nbajam_prot_r);
		memory_install_write16_handler(0, ADDRESS_SPACE_PROGRAM, 0x1b15f40, 0x1b37f5f, 0, 0, nbajam_prot_w);
		memory_install_write16_handler(0, ADDRESS_SPACE_PROGRAM, 0x1b95f40, 0x1bb7f5f, 0, 0, nbajam_prot_w);
	}

	/* sound chip protection (hidden RAM) */
	if (!te_protection)
		memory_install_write8_handler(1, ADDRESS_SPACE_PROGRAM, 0xfbaa, 0xfbd4, 0, 0, MWA8_RAM);
	else
		memory_install_write8_handler(1, ADDRESS_SPACE_PROGRAM, 0xfbec, 0xfc16, 0, 0, MWA8_RAM);
}

DRIVER_INIT( nbajam )
{
	init_nbajam_common(0);
}

DRIVER_INIT( nbajamte )
{
	init_nbajam_common(1);
}

DRIVER_INIT( jdreddp )
{
	/* common init */
	init_tunit_generic(SOUND_ADPCM_LARGE);

	/* looks like the watchdog needs to be disabled */
	memory_install_write16_handler(0, ADDRESS_SPACE_PROGRAM, 0x01d81060, 0x01d8107f, 0, 0, MWA16_NOP);

	/* protection */
	memory_install_read16_handler(0, ADDRESS_SPACE_PROGRAM, 0x1b00000, 0x1bfffff, 0, 0, jdredd_prot_r);
	memory_install_write16_handler(0, ADDRESS_SPACE_PROGRAM, 0x1b00000, 0x1bfffff, 0, 0, jdredd_prot_w);

	/* sound chip protection (hidden RAM) */
	memory_install_write8_handler(1, ADDRESS_SPACE_PROGRAM, 0xfbcf, 0xfbf9, 0, 0, MWA8_RAM);

#if ENABLE_ALL_JDREDD_LEVELS
	/* how about the final levels? */
	jdredd_hack = memory_install_read16_handler(0, ADDRESS_SPACE_PROGRAM, 0xFFBA7FF0, 0xFFBA7FFf, 0, 0, jdredd_hack_r);
#endif
}



/*************************************
 *
 *  T-unit init (DCS)
 *
 *  music: ADSP2105
 *
 *************************************/

DRIVER_INIT( mk2 )
{
	/* common init */
	init_tunit_generic(SOUND_DCS);
	midtunit_gfx_rom_large = 1;

	/* protection */
	memory_install_write16_handler(0, ADDRESS_SPACE_PROGRAM, 0x00f20c60, 0x00f20c7f, 0, 0, mk2_prot_w);
	memory_install_write16_handler(0, ADDRESS_SPACE_PROGRAM, 0x00f42820, 0x00f4283f, 0, 0, mk2_prot_w);
	memory_install_read16_handler(0, ADDRESS_SPACE_PROGRAM, 0x01a190e0, 0x01a190ff, 0, 0, mk2_prot_r);
	memory_install_read16_handler(0, ADDRESS_SPACE_PROGRAM, 0x01a191c0, 0x01a191df, 0, 0, mk2_prot_shift_r);
	memory_install_read16_handler(0, ADDRESS_SPACE_PROGRAM, 0x01a3d0c0, 0x01a3d0ff, 0, 0, mk2_prot_r);
	memory_install_read16_handler(0, ADDRESS_SPACE_PROGRAM, 0x01d9d1e0, 0x01d9d1ff, 0, 0, mk2_prot_const_r);
	memory_install_read16_handler(0, ADDRESS_SPACE_PROGRAM, 0x01def920, 0x01def93f, 0, 0, mk2_prot_const_r);
}



/*************************************
 *
 *  Machine init
 *
 *************************************/

MACHINE_RESET( midtunit )
{
	/* reset sound */
	switch (chip_type)
	{
		case SOUND_ADPCM:
		case SOUND_ADPCM_LARGE:
			williams_adpcm_reset_w(1);
			williams_adpcm_reset_w(0);
			break;

		case SOUND_DCS:
			dcs_reset_w(1);
			dcs_reset_w(0);
			break;
	}
}



/*************************************
 *
 *  Sound write handlers
 *
 *************************************/

READ16_HANDLER( midtunit_sound_state_r )
{
/*  logerror("%08X:Sound status read\n", activecpu_get_pc());*/

	if (chip_type == SOUND_DCS)
		return dcs_control_r() >> 4;

	if (fake_sound_state)
	{
		fake_sound_state--;
		return 0;
	}
	return ~0;
}

READ16_HANDLER( midtunit_sound_r )
{
	logerror("%08X:Sound data read\n", activecpu_get_pc());

	if (chip_type == SOUND_DCS)
		return dcs_data_r() & 0xff;

	return ~0;
}

WRITE16_HANDLER( midtunit_sound_w )
{
	/* check for out-of-bounds accesses */
	if (!offset)
	{
		logerror("%08X:Unexpected write to sound (lo) = %04X\n", activecpu_get_pc(), data);
		return;
	}

	/* call through based on the sound type */
	if (ACCESSING_LSB && ACCESSING_MSB)
		switch (chip_type)
		{
			case SOUND_ADPCM:
			case SOUND_ADPCM_LARGE:
				williams_adpcm_reset_w(~data & 0x100);
				williams_adpcm_data_w(data & 0xff);

				/* the games seem to check for $82 loops, so this should be just barely enough */
				fake_sound_state = 128;
				break;

			case SOUND_DCS:
				logerror("%08X:Sound write = %04X\n", activecpu_get_pc(), data);
				dcs_reset_w(~data & 0x100);
				dcs_data_w(data & 0xff);
				/* the games seem to check for $82 loops, so this should be just barely enough */
				fake_sound_state = 128;
				break;
		}
}