1 // FB Alpha Metal Soldier Isaac II driver module
2 // Based on MAME driver by Jarek Burczynski
3 
4 #include "tiles_generic.h"
5 #include "z80_intf.h"
6 #include "msm5232.h"
7 #include "ay8910.h"
8 
9 static UINT8 *AllMem;
10 static UINT8 *MemEnd;
11 static UINT8 *AllRam;
12 static UINT8 *RamEnd;
13 static UINT8 *DrvZ80ROM0;
14 static UINT8 *DrvZ80ROM1;
15 static UINT8 *DrvGfxROM0;
16 static UINT8 *DrvGfxROM1;
17 static UINT8 *DrvZ80RAM0;
18 static UINT8 *DrvZ80RAM1;
19 static UINT8 *DrvPalRAM;
20 static UINT8 *DrvSprRAM;
21 static UINT8 *DrvFgRAM;
22 static UINT8 *DrvBgRAM0;
23 static UINT8 *DrvBgRAM1;
24 
25 static UINT32 *DrvPalette;
26 static UINT8 DrvRecalc;
27 
28 static UINT8 pending_nmi;
29 static UINT8 nmi_enable;
30 static UINT8 sound_control[2];
31 static UINT8 soundlatch;
32 static UINT8 mcu_value;
33 static UINT8 direction;
34 static UINT8 bg1_textbank;
35 static UINT8 scrollx[3];
36 static UINT8 scrolly[3];
37 
38 static INT32 m_vol_ctrl[16];
39 
40 static UINT8 DrvJoy1[8];
41 static UINT8 DrvJoy2[8];
42 static UINT8 DrvJoy3[8];
43 static UINT8 DrvDips[3];
44 static UINT8 DrvInputs[3];
45 static UINT8 DrvReset;
46 
47 static struct BurnInputInfo MsisaacInputList[] = {
48 	{"P1 Coin",		BIT_DIGITAL,	DrvJoy1 + 4,	"p1 coin"	},
49 	{"P1 Start",		BIT_DIGITAL,	DrvJoy1 + 0,	"p1 start"	},
50 	{"P1 Up",		BIT_DIGITAL,	DrvJoy2 + 5,	"p1 up"		},
51 	{"P1 Down",		BIT_DIGITAL,	DrvJoy2 + 4,	"p1 down"	},
52 	{"P1 Left",		BIT_DIGITAL,	DrvJoy2 + 2,	"p1 left"	},
53 	{"P1 Right",		BIT_DIGITAL,	DrvJoy2 + 3,	"p1 right"	},
54 	{"P1 Button 1",		BIT_DIGITAL,	DrvJoy2 + 0,	"p1 fire 1"	},
55 	{"P1 Button 2",		BIT_DIGITAL,	DrvJoy2 + 1,	"p1 fire 2"	},
56 
57 	{"P2 Coin",		BIT_DIGITAL,	DrvJoy1 + 5,	"p2 coin"	},
58 	{"P2 Start",		BIT_DIGITAL,	DrvJoy1 + 1,	"p2 start"	},
59 	{"P2 Up",		BIT_DIGITAL,	DrvJoy3 + 5,	"p2 up"		},
60 	{"P2 Down",		BIT_DIGITAL,	DrvJoy3 + 4,	"p2 down"	},
61 	{"P2 Left",		BIT_DIGITAL,	DrvJoy3 + 2,	"p2 left"	},
62 	{"P2 Right",		BIT_DIGITAL,	DrvJoy3 + 3,	"p2 right"	},
63 	{"P2 Button 1",		BIT_DIGITAL,	DrvJoy3 + 0,	"p2 fire 1"	},
64 	{"P2 Button 2",		BIT_DIGITAL,	DrvJoy3 + 1,	"p2 fire 2"	},
65 
66 	{"Reset",		BIT_DIGITAL,	&DrvReset,	"reset"		},
67 	{"Tilt",		BIT_DIGITAL,	DrvJoy1 + 3,	"tilt"		},
68 	{"Dip A",		BIT_DIPSWITCH,	DrvDips + 0,	"dip"		},
69 	{"Dip B",		BIT_DIPSWITCH,	DrvDips + 1,	"dip"		},
70 	{"Dip C",		BIT_DIPSWITCH,	DrvDips + 2,	"dip"		},
71 };
72 
73 STDINPUTINFO(Msisaac)
74 
75 static struct BurnDIPInfo MsisaacDIPList[]=
76 {
77 	{0x12, 0xff, 0xff, 0x14, NULL				},
78 	{0x13, 0xff, 0xff, 0x00, NULL				},
79 	{0x14, 0xff, 0xff, 0x84, NULL				},
80 
81 	{0   , 0xfe, 0   ,    2, "Free Play"			},
82 	{0x12, 0x01, 0x04, 0x04, "Off"				},
83 	{0x12, 0x01, 0x04, 0x00, "On"				},
84 
85 	{0   , 0xfe, 0   ,    4, "Lives"			},
86 	{0x12, 0x01, 0x18, 0x00, "1"				},
87 	{0x12, 0x01, 0x18, 0x08, "2"				},
88 	{0x12, 0x01, 0x18, 0x10, "3"				},
89 	{0x12, 0x01, 0x18, 0x18, "4"				},
90 
91 	{0   , 0xfe, 0   ,    16, "Coin A"			},
92 	{0x13, 0x01, 0x0f, 0x0f, "9 Coins 1 Credits"		},
93 	{0x13, 0x01, 0x0f, 0x0e, "8 Coins 1 Credits"		},
94 	{0x13, 0x01, 0x0f, 0x0d, "7 Coins 1 Credits"		},
95 	{0x13, 0x01, 0x0f, 0x0c, "6 Coins 1 Credits"		},
96 	{0x13, 0x01, 0x0f, 0x0b, "5 Coins 1 Credits"		},
97 	{0x13, 0x01, 0x0f, 0x0a, "4 Coins 1 Credits"		},
98 	{0x13, 0x01, 0x0f, 0x09, "3 Coins 1 Credits"		},
99 	{0x13, 0x01, 0x0f, 0x08, "2 Coins 1 Credits"		},
100 	{0x13, 0x01, 0x0f, 0x00, "1 Coin  1 Credits"		},
101 	{0x13, 0x01, 0x0f, 0x01, "1 Coin  2 Credits"		},
102 	{0x13, 0x01, 0x0f, 0x02, "1 Coin  3 Credits"		},
103 	{0x13, 0x01, 0x0f, 0x03, "1 Coin  4 Credits"		},
104 	{0x13, 0x01, 0x0f, 0x04, "1 Coin  5 Credits"		},
105 	{0x13, 0x01, 0x0f, 0x05, "1 Coin  6 Credits"		},
106 	{0x13, 0x01, 0x0f, 0x06, "1 Coin  7 Credits"		},
107 	{0x13, 0x01, 0x0f, 0x07, "1 Coin  8 Credits"		},
108 
109 	{0   , 0xfe, 0   ,    16, "Coin B"			},
110 	{0x13, 0x01, 0xf0, 0xf0, "9 Coins 1 Credits"		},
111 	{0x13, 0x01, 0xf0, 0xe0, "8 Coins 1 Credits"		},
112 	{0x13, 0x01, 0xf0, 0xd0, "7 Coins 1 Credits"		},
113 	{0x13, 0x01, 0xf0, 0xc0, "6 Coins 1 Credits"		},
114 	{0x13, 0x01, 0xf0, 0xb0, "5 Coins 1 Credits"		},
115 	{0x13, 0x01, 0xf0, 0xa0, "4 Coins 1 Credits"		},
116 	{0x13, 0x01, 0xf0, 0x90, "3 Coins 1 Credits"		},
117 	{0x13, 0x01, 0xf0, 0x80, "2 Coins 1 Credits"		},
118 	{0x13, 0x01, 0xf0, 0x00, "1 Coin  1 Credits"		},
119 	{0x13, 0x01, 0xf0, 0x10, "1 Coin  2 Credits"		},
120 	{0x13, 0x01, 0xf0, 0x20, "1 Coin  3 Credits"		},
121 	{0x13, 0x01, 0xf0, 0x30, "1 Coin  4 Credits"		},
122 	{0x13, 0x01, 0xf0, 0x40, "1 Coin  5 Credits"		},
123 	{0x13, 0x01, 0xf0, 0x50, "1 Coin  6 Credits"		},
124 	{0x13, 0x01, 0xf0, 0x60, "1 Coin  7 Credits"		},
125 	{0x13, 0x01, 0xf0, 0x70, "1 Coin  8 Credits"		},
126 
127 	{0   , 0xfe, 0   ,    2, "Demo Sounds"			},
128 	{0x14, 0x01, 0x01, 0x01, "Off"				},
129 	{0x14, 0x01, 0x01, 0x00, "On"				},
130 
131 	{0   , 0xfe, 0   ,    2, "DSW3 Unknown 1"		},
132 	{0x14, 0x01, 0x02, 0x00, "00"				},
133 	{0x14, 0x01, 0x02, 0x02, "02"				},
134 
135 	{0   , 0xfe, 0   ,    2, "Invulnerability (Cheat)"	},
136 	{0x14, 0x01, 0x04, 0x04, "Off"				},
137 	{0x14, 0x01, 0x04, 0x00, "On"				},
138 
139 	{0   , 0xfe, 0   ,    2, "DSW3 Unknown 3"		},
140 	{0x14, 0x01, 0x08, 0x00, "00"				},
141 	{0x14, 0x01, 0x08, 0x08, "08"				},
142 
143 	{0   , 0xfe, 0   ,    4, "Copyright Notice"		},
144 	{0x14, 0x01, 0x30, 0x00, "(C) 1985 Taito Corporation"	},
145 	{0x14, 0x01, 0x30, 0x10, "(C) Taito Corporation"	},
146 	{0x14, 0x01, 0x30, 0x20, "(C) Taito Corp. MCMLXXXV"	},
147 	{0x14, 0x01, 0x30, 0x30, "(C) Taito Corporation"	},
148 
149 	{0   , 0xfe, 0   ,    2, "Coinage Display"		},
150 	{0x14, 0x01, 0x40, 0x40, "Insert Coin"			},
151 	{0x14, 0x01, 0x40, 0x00, "Coins/Credits"		},
152 
153 	{0   , 0xfe, 0   ,    2, "Coinage"			},
154 	{0x14, 0x01, 0x80, 0x80, "A and B"			},
155 	{0x14, 0x01, 0x80, 0x00, "A only"			},
156 };
157 
STDDIPINFO(Msisaac)158 STDDIPINFO(Msisaac)
159 
160 static void ta7630_init()
161 {
162 	double db 	= 0.0;
163 	double db_step 	= 0.50;
164 	for (INT32 i = 0; i < 16; i++)
165 	{
166 		double max = 100.0 / pow(10.0, db/20.0);
167 		m_vol_ctrl[15 - i] = (INT32)max;
168 
169 		db += db_step;
170 		db_step += 0.275;
171 	}
172 }
173 
msisaac_main_write(UINT16 address,UINT8 data)174 static void __fastcall msisaac_main_write(UINT16 address, UINT8 data)
175 {
176 	switch (address)
177 	{
178 		case 0xf000:
179 			bg1_textbank = (data >> 3) & 1;
180 		return;
181 
182 		case 0xf001: // nop
183 		case 0xf002: // nop
184 		case 0xf061: // sound reset?
185 		case 0xf0a3: // ?
186 		return;
187 
188 		case 0xf060:
189 			soundlatch = data;
190 			if (nmi_enable) {
191 				ZetNmi(1);
192 			} else {
193 				pending_nmi = 1;
194 			}
195 		return;
196 
197 		case 0xf0c0:
198 			scrollx[0] = data;
199 		return;
200 
201 		case 0xf0c1:
202 			scrolly[0] = data;
203 		return;
204 
205 		case 0xf0c2:
206 			scrollx[2] = data;
207 		return;
208 
209 		case 0xf0c3:
210 			scrolly[2] = data;
211 		return;
212 
213 		case 0xf0c4:
214 			scrollx[1] = data;
215 		return;
216 
217 		case 0xf0c5:
218 			scrolly[1] = data;
219 		return;
220 
221 		case 0xf0e0:
222 			mcu_value = data;
223 		return;
224 	}
225 }
226 
msisaac_mcu_read()227 static UINT8 msisaac_mcu_read()
228 {
229 	switch (mcu_value)
230 	{
231 		case 0x5f:
232 			return mcu_value + 0x6b;
233 
234 		case 0x02:
235 		{
236 			static const INT8 table[16] = { -1, 2, 6, -1, 0, 1, 7, 0, 4, 3, 5, 4, -1, 2, 6, -1 };
237 
238 			INT32 val = table[(DrvInputs[1] >> 2) & 0x0f];
239 
240 			if (val >= 0) direction = val;
241 
242 			return direction;
243 		}
244 
245 		case 0x07:
246 			return 0x45;
247 	}
248 
249 	return 0;
250 }
251 
msisaac_main_read(UINT16 address)252 static UINT8 __fastcall msisaac_main_read(UINT16 address)
253 {
254 	switch (address)
255 	{
256 		case 0xf0e0:
257 			return msisaac_mcu_read();
258 
259 		case 0xf0e1:
260 			return 0x03; // mcu status
261 
262 		case 0xf080:
263 			return DrvDips[0];
264 
265 		case 0xf081:
266 			return DrvDips[1];
267 
268 		case 0xf082:
269 			return DrvDips[2];
270 
271 		case 0xf083:
272 			return DrvInputs[0];
273 
274 		case 0xf084:
275 			return DrvInputs[1];
276 	}
277 
278 	return 0;
279 }
280 
ta7630_set_channel_volume()281 static void ta7630_set_channel_volume()
282 {
283 	double vol = m_vol_ctrl[sound_control[0] & 0xf] / 100.0;
284 	MSM5232SetRoute(vol, BURN_SND_MSM5232_ROUTE_0);
285 	MSM5232SetRoute(vol, BURN_SND_MSM5232_ROUTE_1);
286 	MSM5232SetRoute(vol, BURN_SND_MSM5232_ROUTE_2);
287 	MSM5232SetRoute(vol, BURN_SND_MSM5232_ROUTE_3);
288 
289 	vol = m_vol_ctrl[sound_control[0] >> 4] / 100.0;
290 	MSM5232SetRoute(vol, BURN_SND_MSM5232_ROUTE_4);
291 	MSM5232SetRoute(vol, BURN_SND_MSM5232_ROUTE_5);
292 	MSM5232SetRoute(vol, BURN_SND_MSM5232_ROUTE_6);
293 	MSM5232SetRoute(vol, BURN_SND_MSM5232_ROUTE_7);
294 }
295 
msisaac_sound_write(UINT16 address,UINT8 data)296 static void __fastcall msisaac_sound_write(UINT16 address, UINT8 data)
297 {
298 	if (address >= 0x8010 && address <= 0x801d) {
299 		MSM5232Write(address & 0x1f, data);
300 		return;
301 	}
302 
303 	switch (address)
304 	{
305 		case 0x8000:
306 		case 0x8001:
307 		case 0x8002:
308 		case 0x8003:
309 			AY8910Write((address / 2) & 1, address & 1, data);
310 		return;
311 
312 		case 0x8020:
313 			sound_control[0] = data;
314 			ta7630_set_channel_volume();
315 		return;
316 
317 		case 0x8030:
318 			sound_control[1] = data;
319 		return;
320 
321 		case 0xc001:
322 			nmi_enable = 1;
323 			if (pending_nmi) {
324 				ZetNmi();
325 				pending_nmi = 0;
326 			}
327 		return;
328 
329 		case 0xc002:
330 			nmi_enable = 0;
331 		return;
332 
333 		case 0xc003:
334 		return;	// nop
335 	}
336 }
337 
msisaac_sound_read(UINT16 address)338 static UINT8 __fastcall msisaac_sound_read(UINT16 address)
339 {
340 	switch (address)
341 	{
342 		case 0xc000:
343 			return soundlatch;
344 	}
345 
346 	return 0;
347 }
348 
tilemap_callback(fg)349 static tilemap_callback( fg )
350 {
351 	TILE_SET_INFO(0, DrvFgRAM[offs], 0x10, 0);
352 }
353 
tilemap_callback(bg0)354 static tilemap_callback( bg0 )
355 {
356 	TILE_SET_INFO(0, DrvBgRAM0[offs] + 0x500, 0x30, 0);
357 }
358 
tilemap_callback(bg1)359 static tilemap_callback( bg1 )
360 {
361 	TILE_SET_INFO(0, DrvBgRAM1[offs] + (bg1_textbank * 0x400), 0x20, 0);
362 }
363 
DrvDoReset()364 static INT32 DrvDoReset()
365 {
366 	DrvReset = 0;
367 	memset (AllRam, 0, RamEnd - AllRam);
368 
369 	ZetReset(0);
370 	ZetReset(1);
371 
372 	AY8910Reset(0);
373 	AY8910Reset(1);
374 	MSM5232Reset();
375 
376 	pending_nmi = 0;
377 	nmi_enable = 0;
378 	memset (sound_control, 0, 2);
379 	soundlatch = 0;
380 	mcu_value = 0;
381 	direction = 0;
382 	bg1_textbank = 0;
383 	memset (scrollx, 0, 3);
384 	memset (scrolly, 0, 3);
385 
386 	return 0;
387 }
388 
MemIndex()389 static INT32 MemIndex()
390 {
391 	UINT8 *Next; Next = AllMem;
392 
393 	DrvZ80ROM0		= Next; Next += 0x00e000;
394 	DrvZ80ROM1		= Next; Next += 0x004000;
395 
396 	DrvGfxROM0		= Next; Next += 0x020000;
397 	DrvGfxROM1		= Next; Next += 0x020000;
398 
399 	DrvPalette		= (UINT32*)Next; Next += 0x0400 * sizeof(UINT32);
400 
401 	AllRam			= Next;
402 
403 	DrvZ80RAM0		= Next; Next += 0x000800;
404 	DrvZ80RAM1		= Next; Next += 0x000800;
405 	DrvPalRAM		= Next; Next += 0x000800;
406 	DrvSprRAM		= Next; Next += 0x000100;
407 	DrvFgRAM		= Next; Next += 0x000400;
408 	DrvBgRAM0		= Next; Next += 0x000400;
409 	DrvBgRAM1		= Next; Next += 0x000400;
410 
411 	RamEnd			= Next;
412 
413 	MemEnd			= Next;
414 
415 	return 0;
416 }
417 
DrvGfxDecode()418 static INT32 DrvGfxDecode()
419 {
420 	INT32 Plane[4]  = { STEP4(0,0x4000*8) };
421 	INT32 XOffs[16] = { STEP8(7,-1), STEP8(64+7,-1) };
422 	INT32 YOffs[16] = { STEP8(0,8), STEP8(16*8,8) };
423 
424 	UINT8 *tmp = (UINT8*)BurnMalloc(0x10000);
425 	if (tmp == NULL) {
426 		return 1;
427 	}
428 
429 	memcpy (tmp, DrvGfxROM0, 0x10000);
430 
431 	GfxDecode(0x0800, 4,  8,  8, Plane, XOffs, YOffs, 0x040, tmp, DrvGfxROM0);
432 	GfxDecode(0x0200, 4, 16, 16, Plane, XOffs, YOffs, 0x100, tmp, DrvGfxROM1);
433 
434 	BurnFree (tmp);
435 
436 	return 0;
437 }
438 
DrvInit()439 static INT32 DrvInit()
440 {
441 	AllMem = NULL;
442 	MemIndex();
443 	INT32 nLen = MemEnd - (UINT8 *)0;
444 	if ((AllMem = (UINT8 *)BurnMalloc(nLen)) == NULL) return 1;
445 	memset(AllMem, 0, nLen);
446 	MemIndex();
447 
448 	{
449 		if (BurnLoadRom(DrvZ80ROM0 + 0x00000,  0, 1)) return 1;
450 		if (BurnLoadRom(DrvZ80ROM0 + 0x04000,  1, 1)) return 1;
451 		if (BurnLoadRom(DrvZ80ROM0 + 0x08000,  2, 1)) return 1;
452 		if (BurnLoadRom(DrvZ80ROM0 + 0x0c000,  3, 1)) return 1;
453 
454 		if (BurnLoadRom(DrvZ80ROM1 + 0x00000,  4, 1)) return 1;
455 
456 		// mcu rom (not used)
457 
458 		if (BurnLoadRom(DrvGfxROM0 + 0x00000,  6, 1)) return 1;
459 		if (BurnLoadRom(DrvGfxROM0 + 0x04000,  7, 1)) return 1;
460 		if (BurnLoadRom(DrvGfxROM0 + 0x08000,  8, 1)) return 1;
461 		if (BurnLoadRom(DrvGfxROM0 + 0x0c000,  9, 1)) return 1;
462 		if (BurnLoadRom(DrvGfxROM0 + 0x02000, 10, 1)) return 1;
463 		if (BurnLoadRom(DrvGfxROM0 + 0x06000, 11, 1)) return 1;
464 		if (BurnLoadRom(DrvGfxROM0 + 0x0a000, 12, 1)) return 1;
465 		if (BurnLoadRom(DrvGfxROM0 + 0x0e000, 13, 1)) return 1;
466 
467 		DrvGfxDecode();
468 	}
469 
470 	ZetInit(0);
471 	ZetOpen(0);
472 	ZetMapMemory(DrvZ80ROM0,		0x0000, 0xdfff, MAP_ROM);
473 	ZetMapMemory(DrvZ80RAM0,		0xe000, 0xe7ff, MAP_RAM);
474 	ZetMapMemory(DrvPalRAM,			0xe800, 0xefff, MAP_RAM);
475 	ZetMapMemory(DrvSprRAM,			0xf100, 0xf1ff, MAP_RAM); // 0-7f
476 	ZetMapMemory(DrvFgRAM,			0xf400, 0xf7ff, MAP_RAM);
477 	ZetMapMemory(DrvBgRAM1,			0xf800, 0xfbff, MAP_RAM);
478 	ZetMapMemory(DrvBgRAM0,			0xfc00, 0xffff, MAP_RAM);
479 	ZetSetWriteHandler(msisaac_main_write);
480 	ZetSetReadHandler(msisaac_main_read);
481 	ZetClose();
482 
483 	ZetInit(1);
484 	ZetOpen(1);
485 	ZetMapMemory(DrvZ80ROM1,		0x0000, 0x3fff, MAP_ROM);
486 	ZetMapMemory(DrvZ80RAM1,		0x4000, 0x47ff, MAP_RAM);
487 	ZetSetWriteHandler(msisaac_sound_write);
488 	ZetSetReadHandler(msisaac_sound_read);
489 	ZetClose();
490 
491 	AY8910Init(0, 2000000, 0);
492 	AY8910Init(1, 2000000, 1);
493 	AY8910SetAllRoutes(0, 0.10, BURN_SND_ROUTE_BOTH);
494 	AY8910SetAllRoutes(1, 0.10, BURN_SND_ROUTE_BOTH);
495 
496 	MSM5232Init(2000000, 1);
497 	MSM5232SetCapacitors(0.65e-6, 0.65e-6, 0.65e-6, 0.65e-6, 0.65e-6, 0.65e-6, 0.65e-6, 0.65e-6);
498 	MSM5232SetRoute(1.00, BURN_SND_MSM5232_ROUTE_0);
499 	MSM5232SetRoute(1.00, BURN_SND_MSM5232_ROUTE_1);
500 	MSM5232SetRoute(1.00, BURN_SND_MSM5232_ROUTE_2);
501 	MSM5232SetRoute(1.00, BURN_SND_MSM5232_ROUTE_3);
502 	MSM5232SetRoute(1.00, BURN_SND_MSM5232_ROUTE_4);
503 	MSM5232SetRoute(1.00, BURN_SND_MSM5232_ROUTE_5);
504 	MSM5232SetRoute(1.00, BURN_SND_MSM5232_ROUTE_6);
505 	MSM5232SetRoute(1.00, BURN_SND_MSM5232_ROUTE_7);
506 
507 	ta7630_init();
508 
509 	GenericTilesInit();
510 	GenericTilemapInit(0, TILEMAP_SCAN_ROWS, fg_map_callback,  8, 8, 32, 32);
511 	GenericTilemapInit(1, TILEMAP_SCAN_ROWS, bg0_map_callback, 8, 8, 32, 32);
512 	GenericTilemapInit(2, TILEMAP_SCAN_ROWS, bg1_map_callback, 8, 8, 32, 32);
513 	GenericTilemapSetGfx(0, DrvGfxROM0, 4, 8, 8, 0x20000, 0, 0x30);
514 	GenericTilemapSetOffsets(TMAP_GLOBAL, 0, -8);
515 	GenericTilemapSetTransparent(0, 0);
516 	GenericTilemapSetTransparent(2, 0);
517 
518 	DrvDoReset();
519 
520 	return 0;
521 }
522 
DrvExit()523 static INT32 DrvExit()
524 {
525 	GenericTilesExit();
526 
527 	ZetExit();
528 
529 	AY8910Exit(0);
530 	AY8910Exit(1);
531 	MSM5232Exit();
532 
533 	BurnFree (AllMem);
534 
535 	return 0;
536 }
537 
DrvPaletteUpdate()538 static void DrvPaletteUpdate()
539 {
540 	for (INT32 i = 0; i < 0x800; i+=2)
541 	{
542 		UINT8 r = DrvPalRAM[i + 1] & 0xf;
543 		UINT8 g = DrvPalRAM[i + 0] >> 4;
544 		UINT8 b = DrvPalRAM[i + 0] & 0xf;
545 
546 		DrvPalette[i/2] = BurnHighCol(r+r*16, g+g*16, b+b*16, 0);
547 	}
548 }
549 
draw_single_sprite(INT32 code,INT32 color,INT32 sx,INT32 sy,INT32 flipx,INT32 flipy)550 static void draw_single_sprite(INT32 code, INT32 color, INT32 sx, INT32 sy, INT32 flipx, INT32 flipy)
551 {
552 	if (flipy) {
553 		if (flipx) {
554 			Render16x16Tile_Mask_FlipXY_Clip(pTransDraw, code, sx, sy, color, 4, 0, 0, DrvGfxROM1);
555 		} else {
556 			Render16x16Tile_Mask_FlipY_Clip(pTransDraw, code, sx, sy, color, 4, 0, 0, DrvGfxROM1);
557 		}
558 	} else {
559 		if (flipx) {
560 			Render16x16Tile_Mask_FlipX_Clip(pTransDraw, code, sx, sy, color, 4, 0, 0, DrvGfxROM1);
561 		} else {
562 			Render16x16Tile_Mask_Clip(pTransDraw, code, sx, sy, color, 4, 0, 0, DrvGfxROM1);
563 		}
564 	}
565 }
566 
draw_sprites()567 static void draw_sprites()
568 {
569 	for (INT32 i = 128 - 4; i >= 0; i -= 4)
570 	{
571 		int attr  = DrvSprRAM[i + 2];
572 		int sx    = DrvSprRAM[i + 0];
573 		int sy    = (240 - DrvSprRAM[i + 1] - 1) - 8;
574 		int code  = DrvSprRAM[i + 3] + ((attr & 0x04) << 6);
575 		int color = attr >> 4;
576 		int flipx = attr & 0x01;
577 		int flipy = attr & 0x02;
578 
579 		if (attr & 0x08)
580 		{
581 			if (flipy) {
582 				draw_single_sprite(code + 0, color, sx, sy - 16, flipx, flipy);
583 				draw_single_sprite(code + 1, color, sx, sy - 0,  flipx, flipy);
584 			} else {
585 				draw_single_sprite(code + 1, color, sx, sy - 16, flipx, flipy);
586 				draw_single_sprite(code + 0, color, sx, sy - 0,  flipx, flipy);
587 			}
588 		}
589 		else
590 		{
591 			draw_single_sprite(code + 0, color, sx, sy - 0,  flipx, flipy);
592 		}
593 	}
594 }
595 
DrvDraw()596 static INT32 DrvDraw()
597 {
598 	if (DrvRecalc) {
599 		DrvPaletteUpdate();
600 		DrvRecalc = 1;
601 	}
602 
603 	GenericTilemapSetScrollX(0, scrollx[0] + 9);
604 	GenericTilemapSetScrollY(0, scrolly[0]);
605 	GenericTilemapSetScrollX(1, scrollx[1] + 9 + 4);
606 	GenericTilemapSetScrollY(1, scrolly[1]);
607 	GenericTilemapSetScrollX(2, scrollx[2] + 9 + 2);
608 	GenericTilemapSetScrollY(2, scrolly[2]);
609 
610 	GenericTilemapDraw(1, pTransDraw, 0);
611 	GenericTilemapDraw(2, pTransDraw, 0);
612 
613 	draw_sprites();
614 
615 	GenericTilemapDraw(0, pTransDraw, 0);
616 
617 	BurnTransferCopy(DrvPalette);
618 
619 	return 0;
620 }
621 
DrvFrame()622 static INT32 DrvFrame()
623 {
624 	if (DrvReset) {
625 		DrvDoReset();
626 	}
627 
628 	{
629 		memset (DrvInputs, 0xff, 3);
630 		DrvInputs[0] = 0x08;
631 
632 		for (INT32 i = 0; i < 8; i++) {
633 			DrvInputs[0] ^= (DrvJoy1[i] & 1) << i;
634 			DrvInputs[1] ^= (DrvJoy2[i] & 1) << i;
635 			DrvInputs[2] ^= (DrvJoy3[i] & 1) << i;
636 		}
637 	}
638 
639 	INT32 nInterleave = 256;
640 	INT32 nCyclesTotal[2] = { 4000000 / 60, 4000000 / 60 };
641 	INT32 nCyclesDone[2]  = { 0, 0 };
642 
643 	for (INT32 i = 0; i < nInterleave; i++)
644 	{
645 		ZetOpen(0);
646 		nCyclesDone[0] += ZetRun(nCyclesTotal[0] / nInterleave);
647 		if (i == 248) ZetSetIRQLine(0, CPU_IRQSTATUS_HOLD);
648 		ZetClose();
649 
650 		ZetOpen(1);
651 		nCyclesDone[1] += ZetRun(nCyclesTotal[1] / nInterleave);
652 		if (i == 248) ZetSetIRQLine(0, CPU_IRQSTATUS_HOLD);
653 		ZetClose();
654 	}
655 
656 	if (pBurnSoundOut) {
657 		AY8910Render(pBurnSoundOut, nBurnSoundLen);
658 		MSM5232Update(pBurnSoundOut, nBurnSoundLen);
659 	}
660 
661 	if (pBurnDraw) {
662 		BurnDrvRedraw();
663 	}
664 
665 	return 0;
666 }
667 
DrvScan(INT32 nAction,INT32 * pnMin)668 static INT32 DrvScan(INT32 nAction, INT32 *pnMin)
669 {
670 	struct BurnArea ba;
671 
672 	if (pnMin) {
673 		*pnMin = 0x029707;
674 	}
675 
676 	if (nAction & ACB_VOLATILE) {
677 		memset(&ba, 0, sizeof(ba));
678 
679 		ba.Data	  = AllRam;
680 		ba.nLen	  = RamEnd - AllRam;
681 		ba.szName = "All Ram";
682 		BurnAcb(&ba);
683 
684 		ZetScan(nAction);
685 		AY8910Scan(nAction, pnMin);
686 		MSM5232Scan(nAction, pnMin);
687 
688 		SCAN_VAR(pending_nmi);
689 		SCAN_VAR(nmi_enable);
690 		SCAN_VAR(sound_control);
691 		SCAN_VAR(soundlatch);
692 		SCAN_VAR(mcu_value);
693 		SCAN_VAR(direction);
694 		SCAN_VAR(bg1_textbank);
695 		SCAN_VAR(scrollx);
696 		SCAN_VAR(scrolly);
697 	}
698 
699 	if (nAction & ACB_WRITE) {
700 		ta7630_set_channel_volume();
701 	}
702 
703 	return 0;
704 }
705 
706 
707 // Metal Soldier Isaac II
708 
709 static struct BurnRomInfo msisaacRomDesc[] = {
710 	{ "a34_11.bin",		0x4000, 0x40819334, 1 | BRF_PRG | BRF_ESS }, //  0 Z80 #0 Code
711 	{ "a34_12.bin",		0x4000, 0x4c50b298, 1 | BRF_PRG | BRF_ESS }, //  1
712 	{ "a34_13.bin",		0x4000, 0x2e2b09b3, 1 | BRF_PRG | BRF_ESS }, //  2
713 	{ "a34_10.bin",		0x2000, 0xa2c53dc1, 1 | BRF_PRG | BRF_ESS }, //  3
714 
715 	{ "a34_01.bin",		0x4000, 0x545e45e7, 2 | BRF_PRG | BRF_ESS }, //  4 Z80 #1 Code
716 
717 	{ "a34.mcu",		0x0800, 0, 3 | BRF_NODUMP | BRF_OPT },       //  5 MCU (not dumped)
718 
719 	{ "a34_02.bin",		0x2000, 0x50da1a81, 4 | BRF_GRA },           //  6 Tiles
720 	{ "a34_03.bin",		0x2000, 0x728a549e, 4 | BRF_GRA },           //  7
721 	{ "a34_04.bin",		0x2000, 0xe7d19f1c, 4 | BRF_GRA },           //  8
722 	{ "a34_05.bin",		0x2000, 0xbed2107d, 4 | BRF_GRA },           //  9
723 
724 	{ "a34_06.bin",		0x2000, 0x4ec71687, 5 | BRF_GRA },           // 10 Sprites
725 	{ "a34_07.bin",		0x2000, 0x24922abf, 5 | BRF_GRA },           // 11
726 	{ "a34_08.bin",		0x2000, 0x3ddbf4c0, 5 | BRF_GRA },           // 12
727 	{ "a34_09.bin",		0x2000, 0x23eb089d, 5 | BRF_GRA },           // 13
728 };
729 
730 STD_ROM_PICK(msisaac)
731 STD_ROM_FN(msisaac)
732 
733 struct BurnDriver BurnDrvMsisaac = {
734 	"msisaac", NULL, NULL, NULL, "1985",
735 	"Metal Soldier Isaac II\0", NULL, "Taito Corporation", "Miscellaneous",
736 	NULL, NULL, NULL, NULL,
737 	BDF_GAME_WORKING | BDF_ORIENTATION_VERTICAL, 2, HARDWARE_PREFIX_TAITO, GBF_SHOOT, 0,
738 	NULL, msisaacRomInfo, msisaacRomName, NULL, NULL, NULL, NULL, MsisaacInputInfo, MsisaacDIPInfo,
739 	DrvInit, DrvExit, DrvFrame, DrvDraw, DrvScan, &DrvRecalc, 0x400,
740 	240, 256, 3, 4
741 };
742