1 // FB Alpha Mustache Boy driver module
2 // Based on MAME drver by Tomasz Slanina
3 
4 #include "tiles_generic.h"
5 #include "z80_intf.h"
6 #include "burn_ym2151.h"
7 #include "t5182.h"
8 #include "bitswap.h"
9 
10 static UINT8 *AllMem;
11 static UINT8 *MemEnd;
12 static UINT8 *AllRam;
13 static UINT8 *RamEnd;
14 static UINT8 *DrvZ80ROM;
15 static UINT8 *DrvZ80ROMDec;
16 static UINT8 *DrvGfxROM0;
17 static UINT8 *DrvGfxROM1;
18 static UINT8 *DrvColPROM;
19 static UINT8 *DrvZ80RAM;
20 static UINT8 *DrvVidRAM;
21 static UINT8 *DrvSprRAM;
22 
23 static UINT32 *DrvPalette;
24 static UINT8 DrvRecalc;
25 
26 static UINT8 scroll = 0;
27 static UINT8 video_control = 0;
28 static UINT8 flipscreen = 0;
29 
30 static UINT8 DrvJoy1[8];
31 static UINT8 DrvJoy2[8];
32 static UINT8 DrvJoy3[8];
33 static UINT8 DrvJoy4[2];
34 static UINT8 DrvDips[2];
35 static UINT8 DrvReset;
36 static UINT8 DrvInputs[3];
37 
38 static struct BurnInputInfo MustacheInputList[] = {
39 	{"P1 Coin",		BIT_DIGITAL,	DrvJoy4 + 0,	"p1 coin"	},
40 	{"P1 Start",		BIT_DIGITAL,	DrvJoy3 + 1,	"p1 start"	},
41 	{"P1 Up",		BIT_DIGITAL,	DrvJoy1 + 0,	"p1 up"		},
42 	{"P1 Down",		BIT_DIGITAL,	DrvJoy1 + 1,	"p1 down"	},
43 	{"P1 Left",		BIT_DIGITAL,	DrvJoy1 + 2,	"p1 left"	},
44 	{"P1 Right",		BIT_DIGITAL,	DrvJoy1 + 3,	"p1 right"	},
45 	{"P1 Button 1",		BIT_DIGITAL,	DrvJoy1 + 4,	"p1 fire 1"	},
46 	{"P1 Button 2",		BIT_DIGITAL,	DrvJoy1 + 5,	"p1 fire 2"	},
47 
48 	{"P2 Coin",		BIT_DIGITAL,	DrvJoy4 + 1,	"p2 coin"	},
49 	{"P2 Start",		BIT_DIGITAL,	DrvJoy3 + 2,	"p2 start"}	,
50 	{"P2 Up",		BIT_DIGITAL,	DrvJoy2 + 0,	"p2 up"		},
51 	{"P2 Down",		BIT_DIGITAL,	DrvJoy2 + 1,	"p2 down"	},
52 	{"P2 Left",		BIT_DIGITAL,	DrvJoy2 + 2,	"p2 left"	},
53 	{"P2 Right",		BIT_DIGITAL,	DrvJoy2 + 3,	"p2 right"	},
54 	{"P2 Button 1",		BIT_DIGITAL,	DrvJoy2 + 4,	"p2 fire 1"	},
55 	{"P2 Button 2",		BIT_DIGITAL,	DrvJoy2 + 5,	"p2 fire 2"	},
56 
57 	{"Reset",		BIT_DIGITAL,	&DrvReset,	"reset"		},
58 	{"Dip A",		BIT_DIPSWITCH,	DrvDips + 0,	"dip"		},
59 	{"Dip B",		BIT_DIPSWITCH,	DrvDips + 1,	"dip"		},
60 };
61 
62 STDINPUTINFO(Mustache)
63 
64 static struct BurnDIPInfo MustacheDIPList[]=
65 {
66 	{0x11, 0xff, 0xff, 0x1d, NULL			},
67 	{0x12, 0xff, 0xff, 0x7f, NULL			},
68 
69 	{0   , 0xfe, 0   ,    2, "Cabinet"		},
70 	{0x11, 0x01, 0x01, 0x01, "Upright"		},
71 	{0x11, 0x01, 0x01, 0x00, "Cocktail"		},
72 
73 	{0   , 0xfe, 0   ,    4, "Difficulty"		},
74 	{0x11, 0x01, 0x06, 0x06, "Easy"			},
75 	{0x11, 0x01, 0x06, 0x04, "Normal"		},
76 	{0x11, 0x01, 0x06, 0x02, "Hard"			},
77 	{0x11, 0x01, 0x06, 0x00, "Hardest"		},
78 
79 	{0   , 0xfe, 0   ,    4, "Lives"		},
80 	{0x11, 0x01, 0x18, 0x10, "1"			},
81 	{0x11, 0x01, 0x18, 0x18, "3"			},
82 	{0x11, 0x01, 0x18, 0x08, "4"			},
83 	{0x11, 0x01, 0x18, 0x00, "5"			},
84 
85 	{0   , 0xfe, 0   ,    2, "Demo Sounds"		},
86 	{0x11, 0x01, 0x20, 0x20, "Off"			},
87 	{0x11, 0x01, 0x20, 0x00, "On"			},
88 
89 	{0   , 0xfe, 0   ,    8, "Coin A"		},
90 	{0x12, 0x01, 0x07, 0x00, "5 Coins 1 Credits"	},
91 	{0x12, 0x01, 0x07, 0x04, "4 Coins 1 Credits"	},
92 	{0x12, 0x01, 0x07, 0x02, "3 Coins 1 Credits"	},
93 	{0x12, 0x01, 0x07, 0x06, "2 Coins 1 Credits"	},
94 	{0x12, 0x01, 0x07, 0x07, "1 Coin  1 Credits"	},
95 	{0x12, 0x01, 0x07, 0x03, "1 Coin  2 Credits"	},
96 	{0x12, 0x01, 0x07, 0x05, "1 Coin  3 Credits"	},
97 	{0x12, 0x01, 0x07, 0x01, "1 Coin  5 Credits"	},
98 
99 	{0   , 0xfe, 0   ,    4, "Coin B"		},
100 	{0x12, 0x01, 0x18, 0x10, "2 Coins 1 Credits"	},
101 	{0x12, 0x01, 0x18, 0x18, "1 Coin  1 Credits"	},
102 	{0x12, 0x01, 0x18, 0x00, "2 Coins 3 Credits"	},
103 	{0x12, 0x01, 0x18, 0x08, "1 Coin  2 Credits"	},
104 
105 	{0   , 0xfe, 0   ,    2, "Service Mode"		},
106 	{0x12, 0x01, 0x20, 0x20, "Off"			},
107 	{0x12, 0x01, 0x20, 0x00, "On"			},
108 
109 	{0   , 0xfe, 0   ,    2, "Free Play"		},
110 	{0x12, 0x01, 0x40, 0x40, "Off"			},
111 	{0x12, 0x01, 0x40, 0x00, "On"			},
112 };
113 
STDDIPINFO(Mustache)114 STDDIPINFO(Mustache)
115 
116 static UINT8 __fastcall mustache_main_read(UINT16 a)
117 {
118 	switch (a)
119 	{
120 		case 0xd001:
121 			return t5182_semaphore_snd;
122 
123 		case 0xd800:
124 			return DrvInputs[0];
125 
126 		case 0xd801:
127 			return DrvInputs[1];
128 
129 		case 0xd802:
130 			return DrvInputs[2];
131 
132 		case 0xd803:
133 			return DrvDips[0];
134 
135 		case 0xd804:
136 			return DrvDips[1];
137 	}
138 
139 	return 0;
140 }
141 
mustache_main_write(UINT16 a,UINT8 d)142 static void __fastcall mustache_main_write(UINT16 a, UINT8 d)
143 {
144 	switch (a)
145 	{
146 		case 0xd000:
147 			ZetClose();
148 			ZetOpen(1);
149 			t5182_setirq_callback(CPU_ASSERT);
150 			ZetClose();
151 			ZetOpen(0);
152 		return;
153 
154 		case 0xd002:
155 		case 0xd003:
156 			t5182_semaphore_main = ~a & 1;
157 		return;
158 
159 		case 0xd806:
160 			scroll = d;
161 		return;
162 
163 		case 0xd807:
164 			flipscreen = d & 0x01;
165 			video_control = d;
166 		return;
167 	}
168 }
169 
MemIndex()170 static INT32 MemIndex()
171 {
172 	UINT8 *Next; Next = AllMem;
173 
174 	DrvZ80ROM	= Next; Next += 0x010000;
175 	DrvZ80ROMDec	= Next; Next += 0x008000;
176 
177 	t5182ROM	= Next; Next += 0x010000;
178 
179 	DrvGfxROM0	= Next; Next += 0x020000;
180 	DrvGfxROM1	= Next; Next += 0x040000;
181 
182 	DrvColPROM	= Next; Next += 0x000300;
183 
184 	DrvPalette	= (UINT32*)Next; Next += 0x0100 * sizeof(UINT32);
185 
186 	AllRam		= Next;
187 
188 	DrvZ80RAM	= Next; Next += 0x001000;
189 	DrvVidRAM	= Next; Next += 0x001000;
190 	DrvSprRAM	= Next; Next += 0x000800;
191 
192 	t5182SharedRAM	= Next; Next += 0x000100;
193 
194 	RamEnd		= Next;
195 
196 	MemEnd		= Next;
197 
198 	return 0;
199 }
200 
DrvDoReset()201 static INT32 DrvDoReset()
202 {
203 	memset (AllRam, 0, RamEnd - AllRam);
204 
205 	ZetOpen(0);
206 	ZetReset();
207 	ZetClose();
208 
209 	t5182Reset();
210 
211 	scroll = 0;
212 	video_control = 0;
213 	flipscreen = 0;
214 
215 	HiscoreReset();
216 
217 	return 0;
218 }
219 
decrypt_byte(INT32 op,INT32 a,INT32 src)220 static UINT8 decrypt_byte(INT32 op, INT32 a, INT32 src)
221 {
222 	if ( BIT(a,9)  &  BIT(a,8))             src ^= 0x80;
223 	if ( BIT(a,11) &  BIT(a,4) &  BIT(a,1)) src ^= 0x40;
224 
225 	if (op) // opcode only
226 	{
227 		if (~BIT(a,13) & BIT(a,12))             src ^= 0x20;
228 		if (~BIT(a,6)  &  BIT(a,1))             src ^= 0x10;
229 		if (~BIT(a,12) &  BIT(a,2))             src ^= 0x08;
230 	}
231 
232 	if ( BIT(a,11) & ~BIT(a,8) &  BIT(a,1)) src ^= 0x04;
233 	if ( BIT(a,13) & ~BIT(a,6) &  BIT(a,4)) src ^= 0x02;
234 	if (~BIT(a,11) &  BIT(a,9) &  BIT(a,2)) src ^= 0x01;
235 
236 	if (BIT(a,13) &  BIT(a,4)) src = BITSWAP08(src,7,6,5,4,3,2,0,1);
237 	if (BIT(a, 8) &  BIT(a,4)) src = BITSWAP08(src,7,6,5,4,2,3,1,0);
238 
239 	if (op) // opcode only
240 	{
241 		if (BIT(a,12) &  BIT(a,9)) src = BITSWAP08(src,7,6,4,5,3,2,1,0);
242 		if (BIT(a,11) & ~BIT(a,6)) src = BITSWAP08(src,6,7,5,4,3,2,1,0);
243 	}
244 
245 	return src;
246 }
247 
seibu_decrypt()248 static void seibu_decrypt()
249 {
250 	for (INT32 i = 0; i < 0x8000; i++)
251 	{
252 		DrvZ80ROMDec[i] = decrypt_byte(1,i,DrvZ80ROM[i]);
253 		DrvZ80ROM[i]    = decrypt_byte(0,i,DrvZ80ROM[i]);
254 	}
255 }
256 
decode_gfx()257 static void decode_gfx()
258 {
259 	INT32 i;
260 	INT32 G1 = 0xc000/3;
261 	INT32 G2 = 0x20000/2;
262 	UINT8 *gfx1 = DrvGfxROM0;
263 	UINT8 *gfx2 = DrvGfxROM1;
264 	UINT8 *buf = (UINT8*)BurnMalloc(0x20000);
265 
266 	/* BG data lines */
267 	for (i=0;i<G1; i++)
268 	{
269 		UINT16 w;
270 
271 		buf[i] = BITSWAP08(gfx1[i], 0,5,2,6,4,1,7,3);
272 
273 		w = (gfx1[i+G1] << 8) | gfx1[i+G1*2];
274 		w = BITSWAP16(w, 14,1,13,5,9,2,10,6, 3,8,4,15,0,11,12,7);
275 
276 		buf[i+G1]   = w >> 8;
277 		buf[i+G1*2] = w & 0xff;
278 	}
279 
280 	/* BG address lines */
281 	for (i = 0; i < 3*G1; i++)
282 		gfx1[i] = buf[BITSWAP16(i,15,14,13,2,1,0,12,11,10,9,8,7,6,5,4,3)];
283 
284 	/* SPR data lines */
285 	for (i=0;i<G2; i++)
286 	{
287 		UINT16 w;
288 
289 		w = (gfx2[i] << 8) | gfx2[i+G2];
290 		w = BITSWAP16(w, 5,7,11,4,15,10,3,14, 9,2,13,8,1,12,0,6 );
291 
292 		buf[i]    = w >> 8;
293 		buf[i+G2] = w & 0xff;
294 	}
295 
296 	/* SPR address lines */
297 	for (i = 0; i < 2*G2; i++)
298 		gfx2[i] = buf[BITSWAP24(i,23,22,21,20,19,18,17,16,15,12,11,10,9,8,7,6,5,4,13,14,3,2,1,0)];
299 
300 	BurnFree(buf);
301 }
302 
DrvGfxDecode()303 static INT32 DrvGfxDecode()
304 {
305 	INT32 Plane0[3]  = { 0x00000, 0x20000, 0x40000 };
306 	INT32 Plane1[4]  = { 0x40000, 0xc0000, 0x00000, 0x80000 };
307 	INT32 XOffs0[8]  = { STEP8(7,-1) };
308 	INT32 XOffs1[16] = { STEP16(15,-1) };
309 	INT32 YOffs0[8]  = { STEP8(0,8) };
310 	INT32 YOffs1[16] = { STEP16(0,16) };
311 
312 	UINT8 *tmp = (UINT8*)BurnMalloc(0x20000);
313 	if (tmp == NULL) {
314 		return 1;
315 	}
316 
317 	memcpy (tmp, DrvGfxROM0, 0x0c000);
318 
319 	GfxDecode(0x0800, 3,  8,  8, Plane0, XOffs0, YOffs0, 0x40, tmp, DrvGfxROM0);
320 
321 	memcpy (tmp, DrvGfxROM1, 0x20000);
322 
323 	GfxDecode(0x0400, 4, 16, 16, Plane1, XOffs1, YOffs1, 0x100, tmp, DrvGfxROM1);
324 
325 	BurnFree (tmp);
326 
327 	return 0;
328 }
329 
DrvPaletteInit()330 static void DrvPaletteInit()
331 {
332 	for (INT32 i = 0;i < 256;i++)
333 	{
334 		INT32 bit0,bit1,bit2,bit3,r,g,b;
335 
336 		/* red component */
337 		bit0 = (DrvColPROM[i] >> 0) & 0x01;
338 		bit1 = (DrvColPROM[i] >> 1) & 0x01;
339 		bit2 = (DrvColPROM[i] >> 2) & 0x01;
340 		bit3 = (DrvColPROM[i] >> 3) & 0x01;
341 		r = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
342 
343 		/* green component */
344 		bit0 = (DrvColPROM[i + 256] >> 0) & 0x01;
345 		bit1 = (DrvColPROM[i + 256] >> 1) & 0x01;
346 		bit2 = (DrvColPROM[i + 256] >> 2) & 0x01;
347 		bit3 = (DrvColPROM[i + 256] >> 3) & 0x01;
348 		g = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
349 
350 		/* blue component */
351 		bit0 = (DrvColPROM[i + 512] >> 0) & 0x01;
352 		bit1 = (DrvColPROM[i + 512] >> 1) & 0x01;
353 		bit2 = (DrvColPROM[i + 512] >> 2) & 0x01;
354 		bit3 = (DrvColPROM[i + 512] >> 3) & 0x01;
355 		b = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
356 
357 		DrvPalette[i] = BurnHighCol(r,g,b,0);
358 	}
359 }
360 
DrvInit()361 static INT32 DrvInit()
362 {
363 	BurnSetRefreshRate(56.747);
364 
365 	AllMem = NULL;
366 	MemIndex();
367 	INT32 nLen = MemEnd - (UINT8 *)0;
368 	if ((AllMem = (UINT8 *)BurnMalloc(nLen)) == NULL) return 1;
369 	memset(AllMem, 0, nLen);
370 	MemIndex();
371 
372 	{
373 		if (BurnLoadRom(DrvZ80ROM  + 0x00000,  0, 1)) return 1;
374 		if (BurnLoadRom(DrvZ80ROM  + 0x08000,  1, 1)) return 1;
375 
376 		if (BurnLoadRom(t5182ROM   + 0x00000,  2, 1)) return 1;
377 		if (BurnLoadRom(t5182ROM   + 0x08000,  3, 1)) return 1;
378 
379 		if (BurnLoadRom(DrvGfxROM0 + 0x00000,  4, 1)) return 1;
380 		if (BurnLoadRom(DrvGfxROM0 + 0x04000,  5, 1)) return 1;
381 		if (BurnLoadRom(DrvGfxROM0 + 0x08000,  6, 1)) return 1;
382 
383 		if (BurnLoadRom(DrvGfxROM1 + 0x00000,  7, 1)) return 1;
384 		if (BurnLoadRom(DrvGfxROM1 + 0x08000,  8, 1)) return 1;
385 		if (BurnLoadRom(DrvGfxROM1 + 0x10000,  9, 1)) return 1;
386 		if (BurnLoadRom(DrvGfxROM1 + 0x18000, 10, 1)) return 1;
387 
388 		if (BurnLoadRom(DrvColPROM + 0x00000, 11, 1)) return 1;
389 		if (BurnLoadRom(DrvColPROM + 0x00100, 12, 1)) return 1;
390 		if (BurnLoadRom(DrvColPROM + 0x00200, 13, 1)) return 1;
391 
392 		seibu_decrypt();
393 		decode_gfx();
394 		DrvGfxDecode();
395 		DrvPaletteInit();
396 	}
397 
398 	ZetInit(0);
399 	ZetOpen(0);
400 	ZetMapMemory(DrvZ80ROM,		0x0000, 0xbfff, MAP_ROM);
401 	ZetMapMemory(DrvZ80ROMDec,	0x0000, 0x7fff, MAP_FETCHOP);
402 	ZetMapMemory(DrvVidRAM,		0xc000, 0xcfff, MAP_RAM);
403 	ZetMapMemory(t5182SharedRAM,	0xd400, 0xd4ff, MAP_RAM);
404 	ZetMapMemory(DrvSprRAM,		0xe800, 0xefff, MAP_RAM);
405 	ZetMapMemory(DrvZ80RAM,		0xf000, 0xffff, MAP_RAM);
406 	ZetSetWriteHandler(mustache_main_write);
407 	ZetSetReadHandler(mustache_main_read);
408 	ZetClose();
409 
410 	t5182Init(1, 14318180/4);
411 
412 	GenericTilesInit();
413 
414 	DrvDoReset();
415 
416 	return 0;
417 }
418 
DrvExit()419 static INT32 DrvExit()
420 {
421 	GenericTilesExit();
422 
423 	ZetExit();
424 	t5182Exit();
425 
426 	BurnFree (AllMem);
427 
428 	return 0;
429 }
430 
draw_layer(INT32 rows_start,INT32 rows_end)431 static void draw_layer(INT32 rows_start, INT32 rows_end)
432 {
433 	INT32 scrollx[4] = { 0x100 - scroll, 0x100 - scroll, 0x100 - scroll, 0x100 };
434 
435 	for (INT32 offs = rows_start * 64; offs < 64 * rows_end; offs++)
436 	{
437 		INT32 sx = (~offs & 0x3f) * 8;
438 		INT32 sy = (offs / 0x40) * 8;
439 
440 		sx -= scrollx[(sy / 0x40) & 3] + 8;
441 		if (sx < -7) sx += 512;
442 		sy -= 8;
443 
444 		if (sx >= nScreenWidth || sy >= nScreenHeight || sy <= -7) continue;
445 
446 		INT32 attr  = DrvVidRAM[offs * 2 + 1];
447 		INT32 code  = DrvVidRAM[offs * 2 + 0] + ((attr & 0x60) << 3) + ((video_control & 0x08) << 7);
448 		INT32 color = attr & 0x0f;
449 
450 		INT32 flipx = attr & 0x10;
451 		INT32 flipy = attr & 0x80;
452 
453 		if (flipscreen) {
454 			sx = 232 - sx;
455 			sy = 240 - sy;
456 
457 			flipx ^= 0x10;
458 			flipy ^= 0x80;
459 		}
460 
461 		if (flipy) {
462 			if (flipx) {
463 				Render8x8Tile_FlipXY_Clip(pTransDraw, code, sx, sy, color, 3, 0, DrvGfxROM0);
464 			} else {
465 				Render8x8Tile_FlipY_Clip(pTransDraw, code, sx, sy, color, 3, 0, DrvGfxROM0);
466 			}
467 		} else {
468 			if (flipx) {
469 				Render8x8Tile_FlipX_Clip(pTransDraw, code, sx, sy, color, 3, 0, DrvGfxROM0);
470 			} else {
471 				Render8x8Tile_Clip(pTransDraw, code, sx, sy, color, 3, 0, DrvGfxROM0);
472 			}
473 		}
474 	}
475 }
476 
draw_sprites()477 static void draw_sprites()
478 {
479 	for (INT32 offs = 0; offs < 0x0800; offs += 4)
480 	{
481 		INT32 sy = (240-DrvSprRAM[offs]) ;
482 		INT32 sx = (240-DrvSprRAM[offs+3]) - 8;
483 		INT32 attr = DrvSprRAM[offs+1];
484 		INT32 code = DrvSprRAM[offs+2] + ((attr & 0x0c) << 6);
485 		INT32 color = (attr & 0xe0)>>5;
486 
487 		if (flipscreen)
488 		{
489 			Render16x16Tile_Mask_FlipXY_Clip(pTransDraw, code, (232 - sx) - 8, (232 - sy) + 8, color, 4, 0, 0x80, DrvGfxROM1);
490 		}
491 		else
492 		{
493 			Render16x16Tile_Mask_Clip(pTransDraw, code, sx, sy - 8, color, 4, 0, 0x80, DrvGfxROM1);
494 		}
495 	}
496 }
497 
DrvDraw()498 static INT32 DrvDraw()
499 {
500 	if (DrvRecalc) {
501 		DrvRecalc = 0;
502 		DrvPaletteInit();
503 	}
504 
505 	// Hack-ish - should clip sprites rather than just draw over them
506 	INT32 all_rows = (video_control & 0x0a) ? 1 : 0;
507 
508 	draw_layer(0, (all_rows) ? 32: 24);
509 	draw_sprites();
510 	if (all_rows == 0) draw_layer(24,32);
511 
512 	BurnTransferCopy(DrvPalette);
513 
514 	return 0;
515 }
516 
DrvFrame()517 static INT32 DrvFrame()
518 {
519 	if (DrvReset) {
520 		DrvDoReset();
521 	}
522 
523 	ZetNewFrame();
524 
525 	{
526 		memset (DrvInputs, 0xff, 3);
527 
528 		for (INT32 i = 0; i < 8; i++) {
529 			DrvInputs[0] ^= (DrvJoy1[i] & 1) << i;
530 			DrvInputs[1] ^= (DrvJoy2[i] & 1) << i;
531 			DrvInputs[2] ^= (DrvJoy3[i] & 1) << i;
532 		}
533 
534 		t5182_coin_input = (DrvJoy4[0] << 0) | (DrvJoy4[1] << 1);
535 	}
536 
537 	INT32 nSegment;
538 	INT32 nInterleave = 16;
539 	INT32 nSoundBufferPos = 0;
540 	INT32 nCyclesTotal[2] = { 105732, 63079 };
541 	INT32 nCyclesDone[2] = { 0, 0 };
542 
543 	for (INT32 i = 0; i < nInterleave; i++)
544 	{
545 		ZetOpen(0);
546 
547 		nSegment = ((nCyclesTotal[0] / nInterleave) * (i + 1)) - ZetTotalCycles();
548 
549 		nCyclesDone[0] += ZetRun(nSegment);
550 
551 		if (i == 0) {
552 			ZetSetVector(0x08);
553 			ZetSetIRQLine(0, CPU_IRQSTATUS_AUTO);
554 		}
555 
556 		if (i == 12) {
557 			ZetSetVector(0x10);
558 			ZetSetIRQLine(0, CPU_IRQSTATUS_AUTO);
559 		}
560 
561 		ZetClose();
562 
563 		ZetOpen(1); // t5182
564 
565 		nSegment = ((nCyclesTotal[1] / nInterleave) * (i + 1)) - ZetTotalCycles();
566 
567 		nCyclesDone[1] += ZetRun(nSegment);
568 
569 		if (pBurnSoundOut) {
570 			nSegment = nBurnSoundLen / nInterleave;
571 
572 			BurnYM2151Render(pBurnSoundOut + (nSoundBufferPos << 1), nSegment);
573 
574 			nSoundBufferPos += nSegment;
575 		}
576 
577 		ZetClose();
578 	}
579 
580 	ZetOpen(1); // t5182
581 
582 	if (pBurnSoundOut) {
583 		nSegment = nBurnSoundLen - nSoundBufferPos;
584 		if (nSegment > 0) {
585 			BurnYM2151Render(pBurnSoundOut + (nSoundBufferPos << 1), nSegment);
586 		}
587 	}
588 
589 	ZetClose();
590 
591 	if (pBurnDraw) {
592 		DrvDraw();
593 	}
594 
595 	return 0;
596 }
597 
DrvScan(INT32 nAction,INT32 * pnMin)598 static INT32 DrvScan(INT32 nAction, INT32 *pnMin)
599 {
600 	struct BurnArea ba;
601 
602 	if (pnMin != NULL) {
603 		*pnMin = 0x029729;
604 	}
605 
606 	if (nAction & ACB_MEMORY_RAM) {
607 		memset(&ba, 0, sizeof(ba));
608 		ba.Data	  = AllRam;
609 		ba.nLen	  = RamEnd-AllRam;
610 		ba.szName = "All Ram";
611 		BurnAcb(&ba);
612 	}
613 
614 	if (nAction & ACB_DRIVER_DATA) {
615 		ZetScan(nAction);
616 
617 		t5182Scan(nAction, pnMin);
618 
619 		SCAN_VAR(scroll);
620 		SCAN_VAR(video_control);
621 		SCAN_VAR(flipscreen);
622 	}
623 
624 	return 0;
625 }
626 
627 
628 // Mustache Boy (Japan)
629 
630 static struct BurnRomInfo mustacheRomDesc[] = {
631 	{ "mustache.h18",	0x8000, 0x123bd9b8, 1 | BRF_PRG | BRF_ESS }, //  0 Z80 Code
632 	{ "mustache.h16",	0x4000, 0x62552beb, 1 | BRF_PRG | BRF_ESS }, //  1
633 
634 #if !defined (ROM_VERIFY)
635 	{ "t5182.rom",		0x2000, 0xd354c8fc, 2 | BRF_PRG | BRF_ESS }, //  2 t5182 (Z80 #1) Code
636 #else
637 	{ "",				0x0000, 0x00000000, 2 | BRF_PRG | BRF_ESS }, //  2 t5182 (Z80 #1) Code
638 #endif
639 	{ "mustache.e5",	0x8000, 0xefbb1943, 2 | BRF_PRG | BRF_ESS }, //  3
640 
641 	{ "mustache.a13",	0x4000, 0x9baee4a7, 3 | BRF_GRA },           //  4 Background Tiles
642 	{ "mustache.a14",	0x4000, 0x8155387d, 3 | BRF_GRA },           //  5
643 	{ "mustache.a16",	0x4000, 0x4db4448d, 3 | BRF_GRA },           //  6
644 
645 	{ "mustache.a4",	0x8000, 0xd5c3bbbf, 4 | BRF_GRA },           //  7 Sprites
646 	{ "mustache.a7",	0x8000, 0xe2a6012d, 4 | BRF_GRA },           //  8
647 	{ "mustache.a5",	0x8000, 0xc975fb06, 4 | BRF_GRA },           //  9
648 	{ "mustache.a8",	0x8000, 0x2e180ee4, 4 | BRF_GRA },           // 10
649 
650 	{ "mustache.c3",	0x0100, 0x68575300, 5 | BRF_GRA },           // 11 Color PROMs
651 	{ "mustache.c2",	0x0100, 0xeb008d62, 5 | BRF_GRA },           // 12
652 	{ "mustache.c1",	0x0100, 0x65da3604, 5 | BRF_GRA },           // 13
653 
654 	{ "mustache.b6",	0x1000, 0x5f83fa35, 5 | BRF_GRA | BRF_OPT }, // 14
655 };
656 
657 STD_ROM_PICK(mustache)
658 STD_ROM_FN(mustache)
659 
660 struct BurnDriver BurnDrvMustache = {
661 	"mustache", NULL, NULL, NULL, "1987",
662 	"Mustache Boy (Japan)\0", NULL, "Seibu Kaihatsu (March license)", "Miscellaneous",
663 	NULL, NULL, NULL, NULL,
664 	BDF_GAME_WORKING | BDF_ORIENTATION_VERTICAL | BDF_ORIENTATION_FLIPPED | BDF_HISCORE_SUPPORTED, 2, HARDWARE_MISC_PRE90S, GBF_MAZE, 0,
665 	NULL, mustacheRomInfo, mustacheRomName, NULL, NULL, NULL, NULL, MustacheInputInfo, MustacheDIPInfo,
666 	DrvInit, DrvExit, DrvFrame, DrvDraw, DrvScan, &DrvRecalc, 0x100,
667 	248, 240, 3, 4
668 };
669 
670 
671 // Mustache Boy (Italy)
672 
673 static struct BurnRomInfo mustacheiRomDesc[] = {
674 	{ "1.h18",			0x8000, 0x22893fbc, 1 | BRF_PRG | BRF_ESS }, //  0 Z80 Code
675 	{ "2.h16",			0x4000, 0xec70cfd3, 1 | BRF_PRG | BRF_ESS }, //  1
676 
677 #if !defined (ROM_VERIFY)
678 	{ "t5182.rom",		0x2000, 0xd354c8fc, 2 | BRF_PRG | BRF_ESS }, //  2 t5182 (Z80 #1) Code
679 #else
680 	{ "",				0x0000, 0x00000000, 2 | BRF_PRG | BRF_ESS }, //  2 t5182 (Z80 #1) Code
681 #endif
682 	{ "10.e5",			0x8000, 0xefbb1943, 2 | BRF_PRG | BRF_ESS }, //  3
683 
684 	{ "5.a13",			0x4000, 0x9baee4a7, 3 | BRF_GRA },           //  4 Background Tiles
685 	{ "4.a15",			0x4000, 0x8155387d, 3 | BRF_GRA },           //  5
686 	{ "3.a16",			0x4000, 0x4db4448d, 3 | BRF_GRA },           //  6
687 
688 	{ "6.a4",			0x8000, 0x4a95a89c, 4 | BRF_GRA },           //  7 Sprites
689 	{ "8.a7",			0x8000, 0x3e6be0fb, 4 | BRF_GRA },           //  8
690 	{ "7.a5",			0x8000, 0x8ad38884, 4 | BRF_GRA },           //  9
691 	{ "9.a8",			0x8000, 0x3568c158, 4 | BRF_GRA },           // 10
692 
693 	{ "d.c3",			0x0100, 0x68575300, 5 | BRF_GRA },           // 11 Color PROMs
694 	{ "c.c2",			0x0100, 0xeb008d62, 5 | BRF_GRA },           // 12
695 	{ "b.c1",			0x0100, 0x65da3604, 5 | BRF_GRA },           // 13
696 
697 	{ "a.b6",			0x1000, 0x5f83fa35, 5 | BRF_GRA | BRF_OPT }, // 14
698 };
699 
700 STD_ROM_PICK(mustachei)
701 STD_ROM_FN(mustachei)
702 
703 struct BurnDriver BurnDrvMustachei = {
704 	"mustachei", "mustache", NULL, NULL, "1987",
705 	"Mustache Boy (Italy)\0", NULL, "Seibu Kaihatsu (IG SPA licence)", "Miscellaneous",
706 	NULL, NULL, NULL, NULL,
707 	BDF_GAME_WORKING | BDF_CLONE | BDF_ORIENTATION_VERTICAL | BDF_ORIENTATION_FLIPPED | BDF_HISCORE_SUPPORTED, 2, HARDWARE_MISC_PRE90S, GBF_MAZE, 0,
708 	NULL, mustacheiRomInfo, mustacheiRomName, NULL, NULL, NULL, NULL, MustacheInputInfo, MustacheDIPInfo,
709 	DrvInit, DrvExit, DrvFrame, DrvDraw, DrvScan, &DrvRecalc, 0x100,
710 	248, 240, 3, 4
711 };
712