1 // FB Alpha Ashita No Joe / Success Joe driver module
2 // Based on MAME driver by driver by David Haywood and Pierpaolo Prazzoli
3 
4 #include "tiles_generic.h"
5 #include "m68000_intf.h"
6 #include "z80_intf.h"
7 #include "burn_ym2203.h"
8 #include "msm5205.h"
9 
10 static UINT8 *AllMem;
11 static UINT8 *MemEnd;
12 static UINT8 *AllRam;
13 static UINT8 *RamEnd;
14 static UINT8 *Drv68KROM;
15 static UINT8 *DrvZ80ROM;
16 static UINT8 *DrvGfxROM0;
17 static UINT8 *DrvGfxROM1;
18 static UINT8 *DrvGfxROM2;
19 static UINT8 *DrvGfxROM3;
20 static UINT8 *DrvGfxROM4;
21 static UINT8 *DrvZ80Banks;
22 static UINT8 *DrvPfRAM;
23 static UINT8 *Drv68KRAM;
24 static UINT8 *DrvZ80RAM;
25 static UINT8 *DrvPalRAM;
26 
27 static UINT32 *DrvPalette;
28 
29 static UINT8 *soundlatch;
30 static UINT8 *soundstatus;
31 static UINT8 *tilemap_reg;
32 
33 static UINT16 *scrollx;
34 static UINT16 *scrolly;
35 
36 static INT32 flipscreen;
37 
38 static UINT8 adpcm_byte = 0;
39 static UINT8 MSM5205_vclk_toggle = 0;
40 
41 static UINT8 DrvJoy1[16];
42 static UINT8 DrvJoy2[16];
43 static UINT8 DrvDips[2];
44 static UINT8 DrvReset;
45 static UINT16 DrvInputs[2];
46 
47 static struct BurnInputInfo AshnojoeInputList[] = {
48 	{"P1 Coin",		BIT_DIGITAL,	DrvJoy1 + 11,	"p1 coin"	},
49 	{"P1 Start",		BIT_DIGITAL,	DrvJoy1 + 13,	"p1 start"	},
50 	{"P1 Up",		BIT_DIGITAL,	DrvJoy1 + 0,	"p1 up"		},
51 	{"P1 Down",		BIT_DIGITAL,	DrvJoy1 + 1,	"p1 down"	},
52 	{"P1 Left",		BIT_DIGITAL,	DrvJoy1 + 2,	"p1 left"	},
53 	{"P1 Right",		BIT_DIGITAL,	DrvJoy1 + 3,	"p1 right"	},
54 	{"P1 Button 1",		BIT_DIGITAL,	DrvJoy1 + 4,	"p1 fire 1"	},
55 	{"P1 Button 2",		BIT_DIGITAL,	DrvJoy1 + 5,	"p1 fire 2"	},
56 
57 	{"P2 Coin",		BIT_DIGITAL,	DrvJoy1 + 12,	"p2 coin"	},
58 	{"P2 Start",		BIT_DIGITAL,	DrvJoy1 + 14,	"p2 start"	},
59 	{"P2 Up",		BIT_DIGITAL,	DrvJoy2 + 0,	"p2 up"		},
60 	{"P2 Down",		BIT_DIGITAL,	DrvJoy2 + 1,	"p2 down"	},
61 	{"P2 Left",		BIT_DIGITAL,	DrvJoy2 + 2,	"p2 left"	},
62 	{"P2 Right",		BIT_DIGITAL,	DrvJoy2 + 3,	"p2 right"	},
63 	{"P2 Button 1",		BIT_DIGITAL,	DrvJoy2 + 4,	"p2 fire 1"	},
64 	{"P2 Button 2",		BIT_DIGITAL,	DrvJoy2 + 5,	"p2 fire 2"	},
65 
66 	{"Reset",		BIT_DIGITAL,	&DrvReset,	"reset"		},
67 	{"Service",		BIT_DIGITAL,	DrvJoy1 + 8,	"service"	},
68 	{"Dip A",		BIT_DIPSWITCH,	DrvDips + 0,	"dip"		},
69 	{"Dip B",		BIT_DIPSWITCH,	DrvDips + 1,	"dip"		},
70 };
71 
72 STDINPUTINFO(Ashnojoe)
73 
74 static struct BurnDIPInfo AshnojoeDIPList[]=
75 {
76 	{0x12, 0xff, 0xff, 0x00, NULL			},
77 	{0x13, 0xff, 0xff, 0x00, NULL			},
78 
79 	{0   , 0xfe, 0   ,    2, "Cabinet"		},
80 	{0x12, 0x01, 0x01, 0x00, "Upright"		},
81 	{0x12, 0x01, 0x01, 0x01, "Cocktail"		},
82 
83 	{0   , 0xfe, 0   ,    2, "Flip Screen"		},
84 	{0x12, 0x01, 0x02, 0x00, "Off"			},
85 	{0x12, 0x01, 0x02, 0x02, "On"			},
86 
87 	{0   , 0xfe, 0   ,    2, "Service Mode"		},
88 	{0x12, 0x01, 0x04, 0x00, "Off"			},
89 	{0x12, 0x01, 0x04, 0x04, "On"			},
90 
91 	{0   , 0xfe, 0   ,    2, "Demo Sounds"		},
92 	{0x12, 0x01, 0x08, 0x08, "Off"			},
93 	{0x12, 0x01, 0x08, 0x00, "On"			},
94 
95 	{0   , 0xfe, 0   ,    4, "Coinage"		},
96 	{0x12, 0x01, 0x30, 0x20, "2 Coins 1 Credits"	},
97 	{0x12, 0x01, 0x30, 0x00, "1 Coin  1 Credits"	},
98 	{0x12, 0x01, 0x30, 0x30, "2 Coins 3 Credits"	},
99 	{0x12, 0x01, 0x30, 0x10, "1 Coin  2 Credits"	},
100 
101 	{0   , 0xfe, 0   ,    4, "Difficulty"		},
102 	{0x13, 0x01, 0x03, 0x01, "Easy"			},
103 	{0x13, 0x01, 0x03, 0x00, "Normal"		},
104 	{0x13, 0x01, 0x03, 0x02, "Medium"		},
105 	{0x13, 0x01, 0x03, 0x03, "Hard"			},
106 
107 	{0   , 0xfe, 0   ,    2, "Number of controller"	},
108 	{0x13, 0x01, 0x04, 0x00, "2"			},
109 	{0x13, 0x01, 0x04, 0x04, "1"			},
110 };
111 
STDDIPINFO(Ashnojoe)112 STDDIPINFO(Ashnojoe)
113 
114 void __fastcall ashnojoe_write_byte(UINT32 a, UINT8 d)
115 {
116 	bprintf (0, _T("%5.5x, %2.2x wb\n"), a, d);
117 }
118 
ashnojoe_write_word(UINT32 a,UINT16 d)119 void __fastcall ashnojoe_write_word(UINT32 a, UINT16 d)
120 {
121 	switch (a)
122 	{
123 		case 0x4a006:
124 			*tilemap_reg = d & 0xff;
125 		return;
126 
127 		case 0x4a008:
128 			*soundlatch = d & 0xff;
129 			*soundstatus = 1;
130 		return;
131 
132 		case 0x4a010:
133 		case 0x4a012:
134 		case 0x4a014:
135 		case 0x4a016:
136 		case 0x4a018:
137 			scrollx[(a & 0x0f) / 2] = d;
138 		return;
139 
140 		case 0x4a020:
141 		case 0x4a022:
142 		case 0x4a024:
143 		case 0x4a026:
144 		case 0x4a028:
145 			scrolly[(a & 0x0f) / 2] = d;
146 		return;
147 	}
148 }
149 
ashnojoe_read_byte(UINT32 a)150 UINT8 __fastcall ashnojoe_read_byte(UINT32 a)
151 {
152 	bprintf (0, _T("%5.5x, rb\n"), a);
153 
154 	return 0;
155 }
156 
ashnojoe_read_word(UINT32 a)157 UINT16 __fastcall ashnojoe_read_word(UINT32 a)
158 {
159 	switch (a)
160 	{
161 		case 0x4a000:
162 			return DrvInputs[0];
163 
164 		case 0x4a002:
165 			return DrvInputs[1];
166 
167 		case 0x4a004:
168 			return ((DrvDips[1] << 8) | (DrvDips[0]));
169 
170 		case 0x4a00a:
171 			return 0; // debug? 1 kills sound
172 	}
173 
174 	return 0;
175 }
176 
ashnojoe_sound_write_port(UINT16 p,UINT8 d)177 void __fastcall ashnojoe_sound_write_port(UINT16 p, UINT8 d)
178 {
179 	switch (p & 0xff)
180 	{
181 		case 0x00:
182 			BurnYM2203Write(0, 0, d);
183 		return;
184 
185 		case 0x01:
186 			BurnYM2203Write(0, 1, d);
187 		return;
188 
189 		case 0x02:
190 			adpcm_byte = d;
191 		return;
192 	}
193 }
194 
ashnojoe_sound_read_port(UINT16 p)195 UINT8 __fastcall ashnojoe_sound_read_port(UINT16 p)
196 {
197 	switch (p & 0xff)
198 	{
199 		case 0x00:
200 			return BurnYM2203Read(0, 0);
201 
202 		case 0x01:
203 			return BurnYM2203Read(0, 1);
204 
205 		case 0x04:
206 			*soundstatus = 0;
207 			return *soundlatch;
208 
209 		case 0x06:
210 			return *soundstatus;
211 	}
212 
213 	return 0;
214 }
215 
DrvYM2203WritePortA(UINT32,UINT32 d)216 void DrvYM2203WritePortA(UINT32, UINT32 d)
217 {
218 	MSM5205ResetWrite(0, !(d & 0x01));
219 }
220 
DrvYM2203WritePortB(UINT32,UINT32 d)221 void DrvYM2203WritePortB(UINT32, UINT32 d)
222 {
223 	if (ZetGetActive() == -1) return; // fix crash on init
224 
225 	INT32 bank = (d & 0x0f) * 0x8000;
226 
227 	ZetMapArea(0x8000, 0xffff, 0, DrvZ80Banks + bank);
228 	ZetMapArea(0x8000, 0xffff, 2, DrvZ80Banks + bank);
229 }
230 
DrvIRQHandler(INT32,INT32 nStatus)231 inline static void DrvIRQHandler(INT32, INT32 nStatus)
232 {
233 	ZetSetIRQLine(0, (nStatus) ? CPU_IRQSTATUS_ACK : CPU_IRQSTATUS_NONE);
234 }
235 
DrvSynchroniseStream(INT32 nSoundRate)236 static INT32 DrvSynchroniseStream(INT32 nSoundRate) // msm5205
237 {
238 	if (ZetGetActive() == -1) return 0;
239 
240 	return (INT64)(double)ZetTotalCycles() * nSoundRate / 4000000;
241 }
242 
ashnojoe_vclk_cb()243 static void ashnojoe_vclk_cb()
244 {
245 	if (MSM5205_vclk_toggle == 0)
246 	{
247 		MSM5205DataWrite(0, adpcm_byte >> 4);
248 	}
249 	else
250 	{
251 		MSM5205DataWrite(0, adpcm_byte & 0xf);
252 		ZetNmi();
253 	}
254 
255 	MSM5205_vclk_toggle ^= 1;
256 }
257 
DrvDoReset()258 static INT32 DrvDoReset()
259 {
260 	memset (AllRam, 0, RamEnd - AllRam);
261 
262 	SekOpen(0);
263 	SekReset();
264 	SekClose();
265 
266 	ZetOpen(0);
267 	ZetReset();
268 
269 	BurnYM2203Reset();
270 	MSM5205Reset();
271 
272 	ZetClose();
273 
274 	adpcm_byte = 0;
275 	MSM5205_vclk_toggle = 0;
276 
277 	return 0;
278 }
279 
MemIndex()280 static INT32 MemIndex()
281 {
282 	UINT8 *Next; Next = AllMem;
283 
284 	Drv68KROM		= Next; Next += 0x100000;
285 	DrvZ80ROM		= Next; Next += 0x010000;
286 	DrvZ80Banks		= Next; Next += 0x080000;
287 
288 	DrvGfxROM0		= Next; Next += 0x040000;
289 	DrvGfxROM1		= Next; Next += 0x040000;
290 	DrvGfxROM2		= Next; Next += 0x040000;
291 	DrvGfxROM3		= Next; Next += 0x200000;
292 	DrvGfxROM4		= Next; Next += 0x600000;
293 
294 	DrvPalette		= (UINT32*)Next; Next += 0x0800 * sizeof(UINT32);
295 
296 	AllRam			= Next;
297 
298 	DrvPfRAM		= Next; Next += 0x009000;
299 	Drv68KRAM		= Next; Next += 0x004000;
300 	DrvPalRAM		= Next; Next += 0x001000;
301 
302 	DrvZ80RAM		= Next; Next += 0x002000;
303 
304 	soundlatch		= Next; Next += 0x000001;
305 	soundstatus		= Next; Next += 0x000001;
306 
307 	tilemap_reg		= Next; Next += 0x000001;
308 
309 	scrollx			= (UINT16*)Next; Next += 0x000008 * sizeof(UINT16);
310 	scrolly			= (UINT16*)Next; Next += 0x000008 * sizeof(UINT16);
311 
312 	RamEnd			= Next;
313 
314 	MemEnd			= Next;
315 
316 	return 0;
317 }
318 
DrvGfxExpand(UINT8 * gfx,INT32 len,INT32 bs)319 static void DrvGfxExpand(UINT8 *gfx, INT32 len, INT32 bs) //0,1,2 -8x8, 3,4 16x16
320 {
321 	if (bs) BurnByteswap(gfx, len);
322 
323 	for (INT32 i = len-1; i >= 0; i--) {
324 		gfx[i * 2 + 1] = gfx[i] & 0x0f;
325 		gfx[i * 2 + 0] = gfx[i] >> 4;
326 	}
327 }
328 
DrvInit()329 static INT32 DrvInit()
330 {
331 	AllMem = NULL;
332 	MemIndex();
333 	INT32 nLen = MemEnd - (UINT8 *)0;
334 	if ((AllMem = (UINT8 *)BurnMalloc(nLen)) == NULL) return 1;
335 	memset(AllMem, 0, nLen);
336 	MemIndex();
337 
338 	{
339 		if (BurnLoadRom(Drv68KROM  + 0x000001,  0, 2)) return 1;
340 		if (BurnLoadRom(Drv68KROM  + 0x000000,  1, 2)) return 1;
341 		if (BurnLoadRom(Drv68KROM  + 0x080000,  2, 1)) return 1;
342 
343 		if (BurnLoadRom(DrvZ80ROM  + 0x000000,  3, 1)) return 1;
344 
345 		if (BurnLoadRom(DrvGfxROM0 + 0x000000,  4, 1)) return 1;
346 		if (BurnLoadRom(DrvGfxROM0 + 0x010000,  5, 1)) return 1;
347 
348 		if (BurnLoadRom(DrvGfxROM1 + 0x000000,  6, 1)) return 1;
349 		if (BurnLoadRom(DrvGfxROM1 + 0x010000,  7, 1)) return 1;
350 
351 		if (BurnLoadRom(DrvGfxROM2 + 0x000000,  8, 1)) return 1;
352 		if (BurnLoadRom(DrvGfxROM2 + 0x010000,  9, 1)) return 1;
353 
354 		if (BurnLoadRom(DrvGfxROM3 + 0x000000, 10, 1)) return 1;
355 		if (BurnLoadRom(DrvGfxROM3 + 0x080000, 11, 1)) return 1;
356 
357 		if (BurnLoadRom(DrvGfxROM4 + 0x000000, 12, 1)) return 1;
358 		if (BurnLoadRom(DrvGfxROM4 + 0x080000, 13, 1)) return 1;
359 		if (BurnLoadRom(DrvGfxROM4 + 0x100000, 14, 1)) return 1;
360 		if (BurnLoadRom(DrvGfxROM4 + 0x180000, 15, 1)) return 1;
361 		if (BurnLoadRom(DrvGfxROM4 + 0x200000, 16, 1)) return 1;
362 		if (BurnLoadRom(DrvGfxROM4 + 0x280000, 17, 1)) return 1;
363 
364 		if (BurnLoadRom(DrvZ80Banks + 0x000000,  18, 1)) return 1;
365 
366 		DrvGfxExpand(DrvGfxROM0, 0x020000, 0);
367 		DrvGfxExpand(DrvGfxROM1, 0x020000, 0);
368 		DrvGfxExpand(DrvGfxROM2, 0x020000, 0);
369 		DrvGfxExpand(DrvGfxROM3, 0x100000, 1);
370 		DrvGfxExpand(DrvGfxROM4, 0x300000, 1);
371 	}
372 
373 	SekInit(0, 0x68000);
374 	SekOpen(0);
375 	SekMapMemory(Drv68KROM,			0x000000, 0x03ffff, MAP_ROM);
376 	SekMapMemory(DrvPfRAM,			0x040000, 0x048fff, MAP_RAM);
377 	SekMapMemory(DrvPalRAM,			0x049000, 0x049fff, MAP_RAM);
378 	SekMapMemory(Drv68KRAM,			0x04c000, 0x04ffff, MAP_RAM);
379 	SekMapMemory(Drv68KROM + 0x080000,	0x080000, 0x0bffff, MAP_ROM);
380 	SekSetWriteWordHandler(0,		ashnojoe_write_word);
381 	SekSetWriteByteHandler(0,		ashnojoe_write_byte);
382 	SekSetReadWordHandler(0,		ashnojoe_read_word);
383 	SekSetReadByteHandler(0,		ashnojoe_read_byte);
384 	SekClose();
385 
386 	ZetInit(0);
387 	ZetOpen(0);
388 	ZetMapArea(0x0000, 0x5fff, 0, DrvZ80ROM);
389 	ZetMapArea(0x0000, 0x5fff, 2, DrvZ80ROM);
390 	ZetMapArea(0x6000, 0x7fff, 0, DrvZ80RAM);
391 	ZetMapArea(0x6000, 0x7fff, 1, DrvZ80RAM);
392 	ZetMapArea(0x6000, 0x7fff, 2, DrvZ80RAM);
393 	ZetSetOutHandler(ashnojoe_sound_write_port);
394 	ZetSetInHandler(ashnojoe_sound_read_port);
395 
396 	MSM5205Init(0, DrvSynchroniseStream, 384000, ashnojoe_vclk_cb, MSM5205_S48_4B, 1);
397 	MSM5205SetRoute(0, 1.00, BURN_SND_ROUTE_BOTH);
398 
399 	BurnYM2203Init(1, 4000000, &DrvIRQHandler, 0);
400 	BurnYM2203SetPorts(0, NULL, NULL, &DrvYM2203WritePortA, &DrvYM2203WritePortB);
401 	BurnTimerAttachZet(4000000);
402 	BurnYM2203SetAllRoutes(0, 0.10, BURN_SND_ROUTE_BOTH);
403 
404 	ZetClose();
405 
406 	GenericTilesInit();
407 
408 	DrvDoReset();
409 
410 	return 0;
411 }
412 
DrvExit()413 static INT32 DrvExit()
414 {
415 	GenericTilesExit();
416 
417 	SekExit();
418 	ZetExit();
419 
420 	BurnYM2203Exit();
421 	MSM5205Exit();
422 
423 	BurnFree(AllMem);
424 
425 	return 0;
426 }
427 
DrvRecalcPalette()428 static inline void DrvRecalcPalette()
429 {
430 	UINT8 r,g,b;
431 	UINT16 *p = (UINT16*)DrvPalRAM;
432 
433 	for (INT32 i = 0; i < 0x1000/2; i++) {
434 		INT32 d = p[i];
435 
436 		r = (d >> 10) & 0x1f;
437 		g = (d >>  5) & 0x1f;
438 		b = (d >>  0) & 0x1f;
439 
440 		r = (r << 3) | (r >> 2);
441 		g = (g << 3) | (g >> 2);
442 		b = (b << 3) | (b >> 2);
443 
444 		DrvPalette[i] = BurnHighCol(r, g, b, 0);
445 	}
446 }
447 
draw_16x16_layer(UINT8 * ram,UINT8 * gfx,INT32 color_off,INT32 scroll_off,INT32 mask,INT32 transparent)448 static void draw_16x16_layer(UINT8 *ram, UINT8 *gfx, INT32 color_off, INT32 scroll_off, INT32 mask, INT32 transparent)
449 {
450 	INT32 xscroll = (scrollx[scroll_off] + 112) & 0x1ff;
451 	INT32 yscroll = (scrolly[scroll_off] +  24) & 0x1ff;
452 
453 	UINT16 *vram = (UINT16*)ram;
454 
455 	for (INT32 offs = 0; offs < 32 * 32; offs++)
456 	{
457 		INT32 sx = (offs & 0x1f) << 4;
458 		INT32 sy = (offs >> 5) << 4;
459 
460 		sx -= xscroll;
461 		if (sx < -15) sx += 512;
462 		sy -= yscroll;
463 		if (sy < -15) sy += 512;
464 
465 		if (sx >= nScreenWidth || sy >= nScreenHeight) continue;
466 
467 		INT32 code  =   vram[offs * 2 + 0] & mask;
468 		INT32 color = ((vram[offs * 2 + 1] >> 8) & 0x1f) + color_off;
469 
470 		if (flipscreen) {
471 			if (transparent) {
472 				Render16x16Tile_Mask_FlipXY_Clip(pTransDraw, code, 272 - sx, 192 - sy, color, 4, 15, 0, gfx);
473 			} else {
474 				Render16x16Tile_FlipXY_Clip(pTransDraw, code, 272 - sx, 192 - sy, color, 4, 0, gfx);
475 			}
476 		} else {
477 			if (transparent) {
478 				Render16x16Tile_Mask_Clip(pTransDraw, code, sx, sy, color, 4, 15, 0, gfx);
479 			} else {
480 				Render16x16Tile_Clip(pTransDraw, code, sx, sy, color, 4, 0, gfx);
481 			}
482 		}
483 	}
484 }
485 
draw_8x8_layer(UINT8 * ram,UINT8 * gfx,INT32 color_off,INT32 scroll_off,INT32 high)486 static void draw_8x8_layer(UINT8 *ram, UINT8 *gfx, INT32 color_off, INT32 scroll_off, INT32 high)
487 {
488 	INT32 xscroll = (scrollx[scroll_off] + 112) & 0x1ff;
489 	INT32 yscroll = (scrolly[scroll_off] +  24) & (high ? 0x1ff : 0x0ff);
490 
491 	UINT16 *vram = (UINT16*)ram;
492 
493 	for (INT32 offs = 0; offs < 64 * (32 << high); offs++)
494 	{
495 		INT32 sx = (offs & 0x3f) << 3;
496 		INT32 sy = (offs >> 6) << 3;
497 
498 		sx -= xscroll;
499 		if (sx < -7) sx += 512;
500 		sy -= yscroll;
501 		if (sy < -7) sy += 256 << high;
502 
503 		if (sx >= nScreenWidth || sy >= nScreenHeight) continue;
504 
505 		INT32 code  =  vram[offs] & 0x0fff;
506 		INT32 color = (vram[offs] >> 12) + color_off;
507 
508 		if (flipscreen) {
509 			Render8x8Tile_Mask_FlipXY_Clip(pTransDraw, code, 280 - sx, 200 - sy, color, 4, 15, 0, gfx);
510 		} else {
511 			Render8x8Tile_Mask_Clip(pTransDraw, code, sx, sy, color, 4, 15, 0, gfx);
512 		}
513 	}
514 }
515 
DrvDraw()516 static INT32 DrvDraw()
517 {
518 	DrvRecalcPalette();
519 
520 	flipscreen = *tilemap_reg & 0x01;
521 
522 	INT32 backlayer = (*tilemap_reg & 0x02) ? 0x7000 : 0x6000;
523 
524 	if (nSpriteEnable & 0x01) draw_16x16_layer(DrvPfRAM + backlayer, DrvGfxROM3, 0x70, 4, 0x1fff, 0);
525 
526 	if (nSpriteEnable & 0x02) draw_8x8_layer(DrvPfRAM + 0x2000, DrvGfxROM1, 0x60, 3, 1);
527 
528 	if (nSpriteEnable & 0x04) draw_16x16_layer(DrvPfRAM + 0x5000, DrvGfxROM4, 0x40, 2, 0x7fff, 1);
529 
530 	if (nSpriteEnable & 0x08) draw_16x16_layer(DrvPfRAM + 0x4000, DrvGfxROM4, 0x20, 1, 0x7fff, 1);
531 
532 	if (nSpriteEnable & 0x10) draw_8x8_layer(DrvPfRAM + 0x0000, DrvGfxROM0, 0x10, 0, 1);
533 
534 	if (nSpriteEnable & 0x20) draw_8x8_layer(DrvPfRAM + 0x8000, DrvGfxROM2, 0x00, 5, 1);
535 
536 	BurnTransferCopy(DrvPalette);
537 
538 	return 0;
539 }
540 
DrvFrame()541 static INT32 DrvFrame()
542 {
543 	if (DrvReset) {
544 		DrvDoReset();
545 	}
546 
547 	ZetNewFrame();
548 
549 	{
550 		memset (DrvInputs, 0, 2 * sizeof(INT16));
551 
552 		for (INT32 i = 0; i < 16; i++) {
553 			DrvInputs[0] ^= (DrvJoy1[i] & 1) << i;
554 			DrvInputs[1] ^= (DrvJoy2[i] & 1) << i;
555 		}
556 
557 	}
558 
559 	INT32 nInterleave = MSM5205CalcInterleave(0, 4000000);
560 	INT32 nCyclesTotal[2] = { 8000000 / 60, 4000000 / 60 };
561 	INT32 nCyclesDone[2] = { 0, 0 };
562 	INT32 nNext[2] = { 0, 0 };
563 
564 	SekOpen(0);
565 	ZetOpen(0);
566 
567 	for (INT32 i = 0; i < nInterleave; i++) {
568 		nNext[0] += nCyclesTotal[0] / nInterleave;
569 
570 		nCyclesDone[0] += SekRun(nNext[0] - nCyclesDone[0]);
571 		if (i == (nInterleave - 1)) SekSetIRQLine(1, CPU_IRQSTATUS_AUTO);
572 
573 		nNext[1] += nCyclesTotal[1] / nInterleave;
574 		BurnTimerUpdate(nNext[1]);
575 		MSM5205Update();
576 		nCyclesDone[1] += nNext[1];
577 	}
578 
579 	BurnTimerEndFrame(nCyclesTotal[1]);
580 
581 	if (pBurnSoundOut) {
582 		BurnYM2203Update(pBurnSoundOut, nBurnSoundLen);
583 		MSM5205Render(0, pBurnSoundOut, nBurnSoundLen);
584 	}
585 
586 	ZetClose();
587 	SekClose();
588 
589 	if (pBurnDraw) {
590 		DrvDraw();
591 	}
592 
593 	return 0;
594 }
595 
DrvScan(INT32 nAction,INT32 * pnMin)596 static INT32 DrvScan(INT32 nAction, INT32 *pnMin)
597 {
598 	struct BurnArea ba;
599 
600 	if (pnMin != NULL) {
601 		*pnMin = 0x029698;
602 	}
603 
604 	if (nAction & ACB_MEMORY_RAM) {
605 		memset(&ba, 0, sizeof(ba));
606 		ba.Data	  = AllRam;
607 		ba.nLen	  = RamEnd-AllRam;
608 		ba.szName = "All Ram";
609 		BurnAcb(&ba);
610 	}
611 
612 	if (nAction & ACB_DRIVER_DATA) {
613 		SekScan(nAction);
614 		ZetScan(nAction);
615 
616 		BurnYM2203Scan(nAction, pnMin);
617 		MSM5205Scan(nAction, pnMin);
618 	}
619 
620 	return 0;
621 }
622 
623 
624 // Success Joe (World)
625 
626 static struct BurnRomInfo scessjoeRomDesc[] = {
627 	{ "5.4q",		0x10000, 0xc805f9e7, 1 | BRF_PRG | BRF_ESS }, //  0 68K Code
628 	{ "6.4s",		0x10000, 0xeda7a537, 1 | BRF_PRG | BRF_ESS }, //  1
629 	{ "sj201-nw.6m",	0x40000, 0x5a64ca42, 1 | BRF_PRG | BRF_ESS }, //  2
630 
631 	{ "9.8q",		0x08000, 0x8767e212, 2 | BRF_PRG | BRF_ESS }, //  3 Z80 Code
632 
633 	{ "8.5e",		0x10000, 0x9bcb160e, 3 | BRF_GRA },           //  4 Character Tiles
634 	{ "7.5c",		0x10000, 0xb250c69d, 3 | BRF_GRA },           //  5
635 
636 	{ "4.4e",		0x10000, 0xaa6336d3, 4 | BRF_GRA },           //  6 Character Tiles
637 	{ "3.4c",		0x10000, 0x7e2d86b5, 4 | BRF_GRA },           //  7
638 
639 	{ "2.3m",		0x10000, 0xc3254938, 5 | BRF_GRA },           //  8 Character Tiles
640 	{ "1.1m",		0x10000, 0x5d16a6fa, 5 | BRF_GRA },           //  9
641 
642 	{ "sj402-nw.8e",	0x80000, 0xb6d33d06, 6 | BRF_GRA },           // 10 Background Tiles
643 	{ "sj403-nw.7e",	0x80000, 0x07143f56, 6 | BRF_GRA },           // 11
644 
645 	{ "sj404-nw.7a",	0x80000, 0x8f134128, 7 | BRF_GRA },           // 12 Foreground Tiles
646 	{ "sj405-nw.7c",	0x80000, 0x6fd81699, 7 | BRF_GRA },           // 13
647 	{ "sj406-nw.7d",	0x80000, 0x634e33e6, 7 | BRF_GRA },           // 14
648 	{ "sj407-nw.7f",	0x80000, 0x5c66ff06, 7 | BRF_GRA },           // 15
649 	{ "sj408-nw.7g",	0x80000, 0x6a3b1ea1, 7 | BRF_GRA },           // 16
650 	{ "sj409-nw.7j",	0x80000, 0xd8764213, 7 | BRF_GRA },           // 17
651 
652 	{ "sj401-nw.10r",	0x80000, 0x25dfab59, 8 | BRF_PRG | BRF_ESS }, // 18 Z80 Banks
653 };
654 
655 STD_ROM_PICK(scessjoe)
656 STD_ROM_FN(scessjoe)
657 
658 struct BurnDriver BurnDrvScessjoe = {
659 	"scessjoe", NULL, NULL, NULL, "1990",
660 	"Success Joe (World)\0", "Incomplete sound", "Taito Corporation / Wave", "Miscellaneous",
661 	NULL, NULL, NULL, NULL,
662 	BDF_GAME_WORKING, 2, HARDWARE_TAITO_MISC, GBF_VSFIGHT, 0,
663 	NULL, scessjoeRomInfo, scessjoeRomName, NULL, NULL, NULL, NULL, AshnojoeInputInfo, AshnojoeDIPInfo,
664 	DrvInit, DrvExit, DrvFrame, DrvDraw, DrvScan, NULL, 0x800,
665 	288, 208, 4, 3
666 };
667 
668 
669 // Ashita no Joe (Japan)
670 
671 static struct BurnRomInfo ashnojoeRomDesc[] = {
672 	{ "5.bin",		0x10000, 0xc61e1569, 1 | BRF_PRG | BRF_ESS }, //  0 68K Code
673 	{ "6.bin",		0x10000, 0xc0a16338, 1 | BRF_PRG | BRF_ESS }, //  1
674 	{ "sj201-nw.6m",	0x40000, 0x5a64ca42, 1 | BRF_PRG | BRF_ESS }, //  2
675 
676 	{ "9.8q",		0x08000, 0x8767e212, 2 | BRF_PRG | BRF_ESS }, //  3 Z80 Code
677 
678 	{ "8.5e",		0x10000, 0x9bcb160e, 3 | BRF_GRA },           //  4 Character Tiles
679 	{ "7.bin",		0x10000, 0x7e1efc42, 3 | BRF_GRA },           //  5
680 
681 	{ "4.4e",		0x10000, 0xaa6336d3, 4 | BRF_GRA },           //  6 Character Tiles
682 	{ "3.4c",		0x10000, 0x7e2d86b5, 4 | BRF_GRA },           //  7
683 
684 	{ "2.3m",		0x10000, 0xc3254938, 5 | BRF_GRA },           //  8 Character Tiles
685 	{ "1.bin",		0x10000, 0x1bf585f0, 5 | BRF_GRA },           //  9
686 
687 	{ "sj402-nw.8e",	0x80000, 0xb6d33d06, 6 | BRF_GRA },           // 10 Background Tiles
688 	{ "sj403-nw.7e",	0x80000, 0x07143f56, 6 | BRF_GRA },           // 11
689 
690 	{ "sj404-nw.7a",	0x80000, 0x8f134128, 7 | BRF_GRA },           // 12 Foreground Tiles
691 	{ "sj405-nw.7c",	0x80000, 0x6fd81699, 7 | BRF_GRA },           // 13
692 	{ "sj406-nw.7d",	0x80000, 0x634e33e6, 7 | BRF_GRA },           // 14
693 	{ "sj407-nw.7f",	0x80000, 0x5c66ff06, 7 | BRF_GRA },           // 15
694 	{ "sj408-nw.7g",	0x80000, 0x6a3b1ea1, 7 | BRF_GRA },           // 16
695 	{ "sj409-nw.7j",	0x80000, 0xd8764213, 7 | BRF_GRA },           // 17
696 
697 	{ "sj401-nw.10r",	0x80000, 0x25dfab59, 8 | BRF_PRG | BRF_ESS }, // 18 Z80 Banks
698 };
699 
700 STD_ROM_PICK(ashnojoe)
701 STD_ROM_FN(ashnojoe)
702 
703 struct BurnDriver BurnDrvAshnojoe = {
704 	"ashnojoe", "scessjoe", NULL, NULL, "1990",
705 	"Ashita no Joe (Japan)\0", "Incomplete sound", "Taito Corporation / Wave", "Miscellaneous",
706 	NULL, NULL, NULL, NULL,
707 	BDF_GAME_WORKING | BDF_CLONE, 2, HARDWARE_TAITO_MISC, GBF_VSFIGHT, 0,
708 	NULL, ashnojoeRomInfo, ashnojoeRomName, NULL, NULL, NULL, NULL, AshnojoeInputInfo, AshnojoeDIPInfo,
709 	DrvInit, DrvExit, DrvFrame, DrvDraw, DrvScan, NULL, 0x800,
710 	288, 208, 4, 3
711 };
712