1 // FB Alpha Aliens driver module
2 // Based on MAME driver by Manuel Abadia
3 
4 #include "tiles_generic.h"
5 #include "z80_intf.h"
6 #include "konami_intf.h"
7 #include "konamiic.h"
8 #include "burn_ym2151.h"
9 #include "k007232.h"
10 
11 static UINT8 *AllMem;
12 static UINT8 *MemEnd;
13 static UINT8 *AllRam;
14 static UINT8 *RamEnd;
15 static UINT8 *DrvKonROM;
16 static UINT8 *DrvZ80ROM;
17 static UINT8 *DrvGfxROM0;
18 static UINT8 *DrvGfxROM1;
19 static UINT8 *DrvGfxROMExp0;
20 static UINT8 *DrvGfxROMExp1;
21 static UINT8 *DrvSndROM;
22 static UINT8 *DrvBankRAM;
23 static UINT8 *DrvKonRAM;
24 static UINT8 *DrvPalRAM;
25 static UINT8 *DrvZ80RAM;
26 static UINT32 *DrvPalette;
27 static UINT8 DrvRecalc;
28 
29 static UINT8 *soundlatch;
30 static UINT8 *nDrvRamBank;
31 static UINT8 *nDrvKonamiBank;
32 
33 static UINT8 DrvJoy1[8];
34 static UINT8 DrvJoy2[8];
35 static UINT8 DrvJoy3[8];
36 static UINT8 DrvDips[3];
37 static UINT8 DrvInputs[2];
38 static UINT8 DrvReset;
39 
40 static struct BurnInputInfo AliensInputList[] = {
41 	{"P1 Coin",		BIT_DIGITAL,	DrvJoy1 + 6,	"p1 coin"	},
42 	{"P1 Start",		BIT_DIGITAL,	DrvJoy1 + 7,	"p1 start"	},
43 	{"P1 Up",		BIT_DIGITAL,	DrvJoy1 + 2,	"p1 up"		},
44 	{"P1 Down",		BIT_DIGITAL,	DrvJoy1 + 3,	"p1 down"	},
45 	{"P1 Left",		BIT_DIGITAL,	DrvJoy1 + 0,	"p1 left"	},
46 	{"P1 Right",		BIT_DIGITAL,	DrvJoy1 + 1,	"p1 right"	},
47 	{"P1 Button 1",		BIT_DIGITAL,	DrvJoy1 + 4,	"p1 fire 1"	},
48 	{"P1 Button 2",		BIT_DIGITAL,	DrvJoy1 + 5,	"p1 fire 2"	},
49 
50 	{"P2 Coin",		BIT_DIGITAL,	DrvJoy2 + 6,	"p2 coin"	},
51 	{"P2 Start",		BIT_DIGITAL,	DrvJoy2 + 7,	"p2 start"	},
52 	{"P2 Up",		BIT_DIGITAL,	DrvJoy2 + 2,	"p2 up"		},
53 	{"P2 Down",		BIT_DIGITAL,	DrvJoy2 + 3,	"p2 down"	},
54 	{"P2 Left",		BIT_DIGITAL,	DrvJoy2 + 0,	"p2 left"	},
55 	{"P2 Right",		BIT_DIGITAL,	DrvJoy2 + 1,	"p2 right"	},
56 	{"P2 Button 1",		BIT_DIGITAL,	DrvJoy2 + 4,	"p2 fire 1"	},
57 	{"P2 Button 2",		BIT_DIGITAL,	DrvJoy2 + 5,	"p2 fire 2"	},
58 
59 	{"Reset",		BIT_DIGITAL,	&DrvReset,	"reset"		},
60 	{"Service",		BIT_DIGITAL,	DrvJoy3 + 4,	"service"	},
61 	{"Dip A",		BIT_DIPSWITCH,	DrvDips + 0,	"dip"		},
62 	{"Dip B",		BIT_DIPSWITCH,	DrvDips + 1,	"dip"		},
63 	{"Dip C",		BIT_DIPSWITCH,	DrvDips + 2,	"dip"		},
64 };
65 
66 STDINPUTINFO(Aliens)
67 
68 static struct BurnDIPInfo AliensDIPList[]=
69 {
70 	{0x12, 0xff, 0xff, 0xff, NULL			},
71 	{0x13, 0xff, 0xff, 0x5e, NULL			},
72 	{0x14, 0xff, 0xff, 0xff, NULL			},
73 
74 	{0   , 0xfe, 0   ,    16, "Coin A"		},
75 	{0x12, 0x01, 0x0f, 0x02, "4 Coins 1 Credit"	  },
76 	{0x12, 0x01, 0x0f, 0x05, "3 Coins 1 Credit"	  },
77 	{0x12, 0x01, 0x0f, 0x08, "2 Coins 1 Credit"	  },
78 	{0x12, 0x01, 0x0f, 0x04, "3 Coins 2 Credits"	},
79 	{0x12, 0x01, 0x0f, 0x01, "4 Coins 3 Credits"	},
80 	{0x12, 0x01, 0x0f, 0x0f, "1 Coin  1 Credit"	  },
81 	{0x12, 0x01, 0x0f, 0x03, "3 Coins 4 Credits"	},
82 	{0x12, 0x01, 0x0f, 0x07, "2 Coins 3 Credits"	},
83 	{0x12, 0x01, 0x0f, 0x0e, "1 Coin  2 Credits"	},
84 	{0x12, 0x01, 0x0f, 0x06, "2 Coins 5 Credits"	},
85 	{0x12, 0x01, 0x0f, 0x0d, "1 Coin  3 Credits"	},
86 	{0x12, 0x01, 0x0f, 0x0c, "1 Coin  4 Credits"	},
87 	{0x12, 0x01, 0x0f, 0x0b, "1 Coin  5 Credits"	},
88 	{0x12, 0x01, 0x0f, 0x0a, "1 Coin  6 Credits"	},
89 	{0x12, 0x01, 0x0f, 0x09, "1 Coin  7 Credits"	},
90 	{0x12, 0x01, 0x0f, 0x00, "Free Play"		},
91 
92 	{0   , 0xfe, 0   ,    16, "Coin B"		},
93 	{0x12, 0x01, 0xf0, 0x20, "4 Coins 1 Credit"	  },
94 	{0x12, 0x01, 0xf0, 0x50, "3 Coins 1 Credit"	  },
95 	{0x12, 0x01, 0xf0, 0x80, "2 Coins 1 Credit"	  },
96 	{0x12, 0x01, 0xf0, 0x40, "3 Coins 2 Credits"	},
97 	{0x12, 0x01, 0xf0, 0x10, "4 Coins 3 Credits"	},
98 	{0x12, 0x01, 0xf0, 0xf0, "1 Coin  1 Credit"	  },
99 	{0x12, 0x01, 0xf0, 0x30, "3 Coins 4 Credits"	},
100 	{0x12, 0x01, 0xf0, 0x70, "2 Coins 3 Credits"	},
101 	{0x12, 0x01, 0xf0, 0xe0, "1 Coin  2 Credits"	},
102 	{0x12, 0x01, 0xf0, 0x60, "2 Coins 5 Credits"	},
103 	{0x12, 0x01, 0xf0, 0xd0, "1 Coin  3 Credits"	},
104 	{0x12, 0x01, 0xf0, 0xc0, "1 Coin  4 Credits"	},
105 	{0x12, 0x01, 0xf0, 0xb0, "1 Coin  5 Credits"	},
106 	{0x12, 0x01, 0xf0, 0xa0, "1 Coin  6 Credits"	},
107 	{0x12, 0x01, 0xf0, 0x90, "1 Coin  7 Credits"	},
108 	{0x12, 0x01, 0xf0, 0x00, "No Credits"		},
109 
110 	{0   , 0xfe, 0   ,    4, "Lives"		},
111 	{0x13, 0x01, 0x03, 0x03, "1"			},
112 	{0x13, 0x01, 0x03, 0x02, "2"			},
113 	{0x13, 0x01, 0x03, 0x01, "3"			},
114 	{0x13, 0x01, 0x03, 0x00, "5"			},
115 
116 	{0   , 0xfe, 0   ,    4, "Difficulty"		},
117 	{0x13, 0x01, 0x60, 0x60, "Easy"			},
118 	{0x13, 0x01, 0x60, 0x40, "Normal"		},
119 	{0x13, 0x01, 0x60, 0x20, "Hard"			},
120 	{0x13, 0x01, 0x60, 0x00, "Very Hard"		},
121 
122 	{0   , 0xfe, 0   ,    2, "Demo Sounds"		},
123 	{0x13, 0x01, 0x80, 0x80, "Off"			},
124 	{0x13, 0x01, 0x80, 0x00, "On"			},
125 
126 //	{0   , 0xfe, 0   ,    2, "Flip Screen"		},
127 //	{0x14, 0x01, 0x01, 0x01, "Off"			},
128 //	{0x14, 0x01, 0x01, 0x00, "On"			},
129 
130 	{0   , 0xfe, 0   ,    2, "Service Mode"		},
131 	{0x14, 0x01, 0x04, 0x04, "Off"			},
132 	{0x14, 0x01, 0x04, 0x00, "On"			},
133 };
134 
STDDIPINFO(Aliens)135 STDDIPINFO(Aliens)
136 
137 static void set_ram_bank(INT32 data)
138 {
139 	nDrvRamBank[0] = data;
140 
141 	if (data & 0x20) {
142 		konamiMapMemory(DrvPalRAM,  0x0000, 0x03ff, MAP_RAM);
143 	} else {
144 		konamiMapMemory(DrvBankRAM, 0x0000, 0x03ff, MAP_RAM);
145 	}
146 }
147 
aliens_main_write(UINT16 address,UINT8 data)148 void aliens_main_write(UINT16 address, UINT8 data)
149 {
150 	switch (address)
151 	{
152 		case 0x5f88:
153 			set_ram_bank(data & 0x20);
154 			K052109RMRDLine = data & 0x40;
155 		return;
156 
157 		case 0x5f8c:
158 			*soundlatch = data;
159 			ZetSetVector(0xff);
160 			ZetSetIRQLine(0, CPU_IRQSTATUS_ACK);
161 		return;
162 	}
163 
164 	if ((address & 0xc000) == 0x4000) {
165 		K052109_051960_w(address & 0x3fff, data);
166 		return;
167 	}
168 }
169 
aliens_main_read(UINT16 address)170 UINT8 aliens_main_read(UINT16 address)
171 {
172 	switch (address)
173 	{
174 		case 0x5f80:
175 			return DrvDips[2];
176 
177 		case 0x5f81:
178 			return DrvInputs[0];
179 
180 		case 0x5f82:
181 			return DrvInputs[1];
182 
183 		case 0x5f83:
184 			return DrvDips[1];
185 
186 		case 0x5f84:
187 			return DrvDips[0];
188 
189 		case 0x5f88:
190 			// watchdog reset
191 			return 0;
192 	}
193 
194 	if ((address & 0xc000) == 0x4000) {
195 		return K052109_051960_r(address & 0x3fff);
196 	}
197 
198 	return 0;
199 }
200 
aliens_sound_write(UINT16 address,UINT8 data)201 void __fastcall aliens_sound_write(UINT16 address, UINT8 data)
202 {
203 	if ((address & 0xfff0) == 0xe000) {
204 		K007232WriteReg(0, address & 0x0f, data);
205 		return;
206 	}
207 
208 	switch (address)
209 	{
210 		case 0xa000:
211 			BurnYM2151SelectRegister(data);
212 		return;
213 
214 		case 0xa001:
215 			BurnYM2151WriteRegister(data);
216 		return;
217 	}
218 }
219 
aliens_sound_read(UINT16 address)220 UINT8 __fastcall aliens_sound_read(UINT16 address)
221 {
222 	if ((address & 0xfff0) == 0xe000) {
223 		return K007232ReadReg(0, address & 0x0f);
224 	}
225 
226 	switch (address)
227 	{
228 		case 0xa000:
229 		case 0xa001:
230 			return BurnYM2151Read();
231 
232 		case 0xc000:
233 			ZetSetIRQLine(0, CPU_IRQSTATUS_NONE);
234 			return *soundlatch;
235 	}
236 
237 	return 0;
238 }
239 
DrvYM2151WritePort(UINT32,UINT32 data)240 static void DrvYM2151WritePort(UINT32, UINT32 data)
241 {
242 	INT32 bank_A = ((data >> 1) & 0x01);
243 	INT32 bank_B = ((data) & 0x01);
244 
245 	k007232_set_bank(0, bank_A, bank_B );
246 }
247 
DrvK007232VolCallback(INT32 v)248 static void DrvK007232VolCallback(INT32 v)
249 {
250 	K007232SetVolume(0, 0, (v >> 0x4) * 0x11, 0);
251 	K007232SetVolume(0, 1, 0, (v & 0x0f) * 0x11);
252 }
253 
aliens_set_lines(INT32 lines)254 static void aliens_set_lines(INT32 lines)
255 {
256 	nDrvKonamiBank[0] = lines;
257 
258 	INT32 nBank = (lines & 0x1f) * 0x2000;
259 
260 	konamiMapMemory(DrvKonROM + 0x10000 + nBank, 0x2000, 0x3fff, MAP_ROM);
261 }
262 
K052109Callback(INT32 layer,INT32 bank,INT32 * code,INT32 * color,INT32 *,INT32 *)263 static void K052109Callback(INT32 layer, INT32 bank, INT32 *code, INT32 *color, INT32 *, INT32 *)
264 {
265 	*code |= ((*color & 0x3f) << 8) | (bank << 14);
266 	*code &= 0xffff;
267 	*color = (layer << 2) + ((*color & 0xc0) >> 6);
268 }
269 
K051960Callback(INT32 * code,INT32 * color,INT32 * priority,INT32 * shadow)270 static void K051960Callback(INT32 *code, INT32 *color,INT32 *priority, INT32 *shadow)
271 {
272 	switch (*color & 0x70)
273 	{
274 		case 0x10: *priority = 0x00; break;
275 		case 0x00: *priority = 0xf0; break;
276 		case 0x40: *priority = 0xfc; break;
277 		case 0x20:
278 		case 0x60: *priority = 0xfe; break;
279 		case 0x50: *priority = 0xcc; break;
280 		case 0x30:
281 		case 0x70: *priority = 0xee; break;
282 	}
283 
284 	*code |= (*color & 0x80) << 6;
285 	*code &= 0x3fff;
286 	*color = 16 + (*color & 0x0f);
287 	*shadow = 0;
288 }
289 
DrvDoReset()290 static INT32 DrvDoReset()
291 {
292 	DrvReset = 0;
293 
294 	memset (AllRam, 0, RamEnd - AllRam);
295 
296 	konamiOpen(0);
297 	konamiReset();
298 	konamiClose();
299 
300 	ZetOpen(0);
301 	ZetReset();
302 	ZetClose();
303 
304 	K007232Reset(0);
305 	BurnYM2151Reset();
306 
307 	KonamiICReset();
308 
309 	return 0;
310 }
311 
MemIndex()312 static INT32 MemIndex()
313 {
314 	UINT8 *Next; Next = AllMem;
315 
316 	DrvKonROM		= Next; Next += 0x040000;
317 	DrvZ80ROM		= Next; Next += 0x010000;
318 
319 	DrvGfxROM0		= Next; Next += 0x200000;
320 	DrvGfxROM1		= Next; Next += 0x200000;
321 	DrvGfxROMExp0		= Next; Next += 0x400000;
322 	DrvGfxROMExp1		= Next; Next += 0x400000;
323 
324 	DrvSndROM		= Next; Next += 0x040000;
325 
326 	DrvPalette		= (UINT32*)Next; Next += 0x200 * sizeof(UINT32);
327 
328 	AllRam			= Next;
329 
330 	DrvBankRAM		= Next; Next += 0x000400;
331 	DrvKonRAM		= Next; Next += 0x001c00;
332 	DrvPalRAM		= Next; Next += 0x000400;
333 
334 	DrvZ80RAM		= Next; Next += 0x000800;
335 
336 	soundlatch		= Next; Next += 0x000001;
337 
338 	nDrvRamBank		= Next; Next += 0x000001;
339 	nDrvKonamiBank		= Next; Next += 0x000001;
340 
341 	RamEnd			= Next;
342 	MemEnd			= Next;
343 
344 	return 0;
345 }
346 
DrvInit()347 static INT32 DrvInit()
348 {
349 	GenericTilesInit();
350 
351 	AllMem = NULL;
352 	MemIndex();
353 	INT32 nLen = MemEnd - (UINT8 *)0;
354 	if ((AllMem = (UINT8 *)BurnMalloc(nLen)) == NULL) return 1;
355 	memset(AllMem, 0, nLen);
356 	MemIndex();
357 
358 	{
359 		if (BurnLoadRom(DrvKonROM  + 0x030000,  0, 1)) return 1;
360 		if (BurnLoadRom(DrvKonROM  + 0x010000,  1, 1)) return 1;
361 		memcpy (DrvKonROM + 0x08000, DrvKonROM + 0x38000, 0x8000);
362 
363 		if (BurnLoadRom(DrvZ80ROM  + 0x000000,  2, 1)) return 1;
364 
365 		if (BurnLoadRomExt(DrvGfxROM0 + 0x000000,  3, 4, LD_GROUP(2))) return 1;
366 		if (BurnLoadRomExt(DrvGfxROM0 + 0x000002,  4, 4, LD_GROUP(2))) return 1;
367 		if (BurnLoadRomExt(DrvGfxROM0 + 0x100000,  5, 4, LD_GROUP(2))) return 1;
368 		if (BurnLoadRomExt(DrvGfxROM0 + 0x100002,  6, 4, LD_GROUP(2))) return 1;
369 
370 		if (BurnLoadRomExt(DrvGfxROM1 + 0x000000,  7, 4, LD_GROUP(2))) return 1;
371 		if (BurnLoadRomExt(DrvGfxROM1 + 0x000002,  8, 4, LD_GROUP(2))) return 1;
372 		if (BurnLoadRomExt(DrvGfxROM1 + 0x100000,  9, 4, LD_GROUP(2))) return 1;
373 		if (BurnLoadRomExt(DrvGfxROM1 + 0x100002, 10, 4, LD_GROUP(2))) return 1;
374 
375 		if (BurnLoadRom(DrvSndROM  + 0x000000, 11, 1)) return 1;
376 
377 		K052109GfxDecode(DrvGfxROM0, DrvGfxROMExp0, 0x200000);
378 		K051960GfxDecode(DrvGfxROM1, DrvGfxROMExp1, 0x200000);
379 	}
380 
381 	konamiInit(0);
382 	konamiOpen(0);
383 	konamiMapMemory(DrvBankRAM,          0x0000, 0x03ff, MAP_RAM);
384 	konamiMapMemory(DrvKonRAM,           0x0400, 0x1fff, MAP_RAM);
385 	konamiMapMemory(DrvKonROM + 0x10000, 0x2000, 0x3fff, MAP_ROM);
386 	konamiMapMemory(DrvKonROM + 0x08000, 0x8000, 0xffff, MAP_ROM);
387 	konamiSetWriteHandler(aliens_main_write);
388 	konamiSetReadHandler(aliens_main_read);
389 	konamiSetlinesCallback(aliens_set_lines);
390 	konamiClose();
391 
392 	ZetInit(0);
393 	ZetOpen(0);
394 	ZetMapArea(0x0000, 0x7fff, 0, DrvZ80ROM);
395 	ZetMapArea(0x0000, 0x7fff, 2, DrvZ80ROM);
396 	ZetMapArea(0x8000, 0x87ff, 0, DrvZ80RAM);
397 	ZetMapArea(0x8000, 0x87ff, 1, DrvZ80RAM);
398 	ZetMapArea(0x8000, 0x87ff, 2, DrvZ80RAM);
399 	ZetSetWriteHandler(aliens_sound_write);
400 	ZetSetReadHandler(aliens_sound_read);
401 	ZetClose();
402 
403 	K052109Init(DrvGfxROM0, DrvGfxROMExp0, 0x1fffff);
404 	K052109SetCallback(K052109Callback);
405 	K052109AdjustScroll(8, 0);
406 
407 	K051960Init(DrvGfxROM1, DrvGfxROMExp1, 0x1fffff);
408 	K051960SetCallback(K051960Callback);
409 	K051960SetSpriteOffset(8, 0);
410 
411 	BurnYM2151Init(3579545);
412 	BurnYM2151SetPortHandler(&DrvYM2151WritePort);
413 	BurnYM2151SetAllRoutes(0.60, BURN_SND_ROUTE_BOTH);
414 
415 	K007232Init(0, 3579545, DrvSndROM, 0x40000);
416 	K007232SetPortWriteHandler(0, DrvK007232VolCallback);
417 	K007232PCMSetAllRoutes(0, 0.20, BURN_SND_ROUTE_BOTH);
418 
419 	DrvDoReset();
420 
421 	return 0;
422 }
423 
DrvExit()424 static INT32 DrvExit()
425 {
426 	GenericTilesExit();
427 
428 	KonamiICExit();
429 
430 	konamiExit();
431 	ZetExit();
432 
433 	K007232Exit();
434 	BurnYM2151Exit();
435 
436 	BurnFree (AllMem);
437 
438 	return 0;
439 }
440 
DrvDraw()441 static INT32 DrvDraw()
442 {
443 	KonamiRecalcPalette(DrvPalRAM, DrvPalette, 0x400);
444 
445 	K052109UpdateScroll();
446 
447 	KonamiClearBitmaps(DrvPalette[0x0040]);
448 
449 	if (nBurnLayer & 1) K052109RenderLayer(1, 0, 1);
450 	if (nBurnLayer & 2) K052109RenderLayer(2, 0, 2);
451 	if (nBurnLayer & 4) K052109RenderLayer(0, 0, 4);
452 
453 	if (nSpriteEnable & 1) K051960SpritesRender(-1, -1);
454 
455 	KonamiBlendCopy(DrvPalette);
456 
457 	return 0;
458 }
459 
DrvFrame()460 static INT32 DrvFrame()
461 {
462 	if (DrvReset) {
463 		DrvDoReset();
464 	}
465 
466 	{
467 		memset (DrvInputs, 0xff, sizeof ( DrvInputs ));
468 
469 		for (INT32 i = 0; i < 8; i++)
470 		{
471 			DrvInputs[0] ^= (DrvJoy1[i] & 1) << i;
472 			DrvInputs[1] ^= (DrvJoy2[i] & 1) << i;
473 			DrvDips[2] ^= (DrvJoy3[i] & 1) << i;
474 		}
475 
476 		// Clear opposites
477 		if ((DrvInputs[0] & 0x03) == 0) DrvInputs[0] |= 0x03;
478 		if ((DrvInputs[0] & 0x0c) == 0) DrvInputs[0] |= 0x0c;
479 		if ((DrvInputs[1] & 0x03) == 0) DrvInputs[1] |= 0x03;
480 		if ((DrvInputs[1] & 0x0c) == 0) DrvInputs[1] |= 0x0c;
481 	}
482 
483 	konamiNewFrame();
484 	ZetNewFrame();
485 
486 	INT32 nSoundBufferPos = 0;
487 	INT32 nInterleave = nBurnSoundLen;
488 	INT32 nCyclesTotal[2] = { 6000000 / 60, 3579545 / 60 };
489 	INT32 nCyclesDone[2] = { 0, 0 };
490 
491 	ZetOpen(0);
492 	konamiOpen(0);
493 
494 	for (INT32 i = 0; i < nInterleave; i++)
495 	{
496 		INT32 nSegment = (nCyclesTotal[0] / nInterleave) * (i + 1);
497 
498 		nCyclesDone[0] += konamiRun(nSegment - nCyclesDone[0]);
499 
500 		nSegment = (nCyclesTotal[1] / nInterleave) * (i + 1);
501 
502 		nCyclesDone[1] += ZetRun(nSegment - nCyclesDone[1]);
503 
504 		if (pBurnSoundOut) {
505 			INT32 nSegmentLength = nBurnSoundLen / nInterleave;
506 			INT16* pSoundBuf = pBurnSoundOut + (nSoundBufferPos << 1);
507 			BurnYM2151Render(pSoundBuf, nSegmentLength);
508 			K007232Update(0, pSoundBuf, nSegmentLength);
509 			nSoundBufferPos += nSegmentLength;
510 		}
511 	}
512 
513 	if (K051960_irq_enabled) konamiSetIrqLine(KONAMI_IRQ_LINE, CPU_IRQSTATUS_AUTO);
514 
515 	if (pBurnSoundOut) {
516 		INT32 nSegmentLength = nBurnSoundLen - nSoundBufferPos;
517 		if (nSegmentLength) {
518 			INT16* pSoundBuf = pBurnSoundOut + (nSoundBufferPos << 1);
519 			BurnYM2151Render(pSoundBuf, nSegmentLength);
520 			K007232Update(0, pSoundBuf, nSegmentLength);
521 		}
522 	}
523 
524 	konamiClose();
525 	ZetClose();
526 
527 	if (pBurnDraw) {
528 		DrvDraw();
529 	}
530 
531 	return 0;
532 }
533 
DrvScan(INT32 nAction,INT32 * pnMin)534 static INT32 DrvScan(INT32 nAction,INT32 *pnMin)
535 {
536 	struct BurnArea ba;
537 
538 	if (pnMin) {
539 		*pnMin = 0x029704;
540 	}
541 
542 	if (nAction & ACB_VOLATILE) {
543 		memset(&ba, 0, sizeof(ba));
544 
545 		ba.Data	  = AllRam;
546 		ba.nLen	  = RamEnd - AllRam;
547 		ba.szName = "All Ram";
548 		BurnAcb(&ba);
549 
550 		konamiCpuScan(nAction);
551 		ZetScan(nAction);
552 
553 		BurnYM2151Scan(nAction, pnMin);
554 		K007232Scan(nAction, pnMin);
555 
556 		KonamiICScan(nAction);
557 	}
558 
559 	if (nAction & ACB_WRITE) {
560 		konamiOpen(0);
561 		set_ram_bank(nDrvRamBank[0]);
562 		aliens_set_lines(nDrvKonamiBank[0]);
563 		konamiClose();
564 	}
565 
566 	return 0;
567 }
568 
569 
570 // Aliens (World set 1)
571 
572 static struct BurnRomInfo aliensRomDesc[] = {
573 	{ "875_j02.e24",	0x10000, 0x56c20971, 1 | BRF_PRG | BRF_ESS }, //  0 Konami CPU Code
574 	{ "875_j01.c24",	0x20000, 0x6a529cd6, 1 | BRF_PRG | BRF_ESS }, //  1
575 
576 	{ "875_b03.g04",	0x08000, 0x1ac4d283, 2 | BRF_PRG | BRF_ESS }, //  2 Z80 Code
577 
578 	{ "875b11.k13",		0x80000, 0x89c5c885, 3 | BRF_GRA },           //  3 Background Tiles
579 	{ "875b12.k19",		0x80000, 0xea6bdc17, 3 | BRF_GRA },           //  4
580 	{ "875b07.j13",		0x40000, 0xe9c56d66, 3 | BRF_GRA },           //  5
581 	{ "875b08.j19",		0x40000, 0xf9387966, 3 | BRF_GRA },           //  6
582 
583 	{ "875b10.k08",		0x80000, 0x0b1035b1, 4 | BRF_GRA },           //  7 Sprites
584 	{ "875b09.k02",		0x80000, 0xe76b3c19, 4 | BRF_GRA },           //  8
585 	{ "875b06.j08",		0x40000, 0x081a0566, 4 | BRF_GRA },           //  9
586 	{ "875b05.j02",		0x40000, 0x19a261f2, 4 | BRF_GRA },           // 10
587 
588 	{ "875b04.e05",		0x40000, 0x4e209ac8, 5 | BRF_SND },           // 11 K007232 Samples
589 
590 	{ "821a08.h14",		0x00100, 0x7da55800, 6 | BRF_OPT },           // 12 Timing Proms
591 };
592 
593 STD_ROM_PICK(aliens)
594 STD_ROM_FN(aliens)
595 
596 struct BurnDriver BurnDrvAliens = {
597 	"aliens", NULL, NULL, NULL, "1990",
598 	"Aliens (World set 1)\0", NULL, "Konami", "GX875",
599 	NULL, NULL, NULL, NULL,
600 	BDF_GAME_WORKING, 2, HARDWARE_PREFIX_KONAMI, GBF_PLATFORM | GBF_HORSHOOT, 0,
601 	NULL, aliensRomInfo, aliensRomName, NULL, NULL, NULL, NULL, AliensInputInfo, AliensDIPInfo,
602 	DrvInit, DrvExit, DrvFrame, DrvDraw, DrvScan, &DrvRecalc, 0x200,
603 	288, 224, 4, 3
604 };
605 
606 
607 // Aliens (World set 2)
608 
609 static struct BurnRomInfo aliens2RomDesc[] = {
610 	{ "875_p02.e24",	0x10000, 0x4edd707d, 1 | BRF_PRG | BRF_ESS }, //  0 Konami CPU Code
611 	{ "875_n01.c24",	0x20000, 0x106cf59c, 1 | BRF_PRG | BRF_ESS }, //  1
612 
613 	{ "875_b03.g04",	0x08000, 0x1ac4d283, 2 | BRF_PRG | BRF_ESS }, //  2 Z80 Code
614 
615 	{ "875b11.k13",		0x80000, 0x89c5c885, 3 | BRF_GRA },           //  3 Background Tiles
616 	{ "875b12.k19",		0x80000, 0xea6bdc17, 3 | BRF_GRA },           //  4
617 	{ "875b07.j13",		0x40000, 0xe9c56d66, 3 | BRF_GRA },           //  5
618 	{ "875b08.j19",		0x40000, 0xf9387966, 3 | BRF_GRA },           //  6
619 
620 	{ "875b10.k08",		0x80000, 0x0b1035b1, 4 | BRF_GRA },           //  7 Sprites
621 	{ "875b09.k02",		0x80000, 0xe76b3c19, 4 | BRF_GRA },           //  8
622 	{ "875b06.j08",		0x40000, 0x081a0566, 4 | BRF_GRA },           //  9
623 	{ "875b05.j02",		0x40000, 0x19a261f2, 4 | BRF_GRA },           // 10
624 
625 	{ "875b04.e05",		0x40000, 0x4e209ac8, 5 | BRF_SND },           // 11 K007232 Samples
626 
627 	{ "821a08.h14",		0x00100, 0x7da55800, 6 | BRF_OPT },           // 12 Timing Proms
628 };
629 
630 STD_ROM_PICK(aliens2)
631 STD_ROM_FN(aliens2)
632 
633 struct BurnDriver BurnDrvAliens2 = {
634 	"aliens2", "aliens", NULL, NULL, "1990",
635 	"Aliens (World set 2)\0", NULL, "Konami", "GX875",
636 	NULL, NULL, NULL, NULL,
637 	BDF_GAME_WORKING | BDF_CLONE, 2, HARDWARE_PREFIX_KONAMI, GBF_PLATFORM | GBF_HORSHOOT, 0,
638 	NULL, aliens2RomInfo, aliens2RomName, NULL, NULL, NULL, NULL, AliensInputInfo, AliensDIPInfo,
639 	DrvInit, DrvExit, DrvFrame, DrvDraw, DrvScan, &DrvRecalc, 0x200,
640 	288, 224, 4, 3
641 };
642 
643 
644 // Aliens (World set 3)
645 
646 static struct BurnRomInfo aliens3RomDesc[] = {
647 	{ "875_w3_2.e24",	0x10000, 0xf917f7b5, 1 | BRF_PRG | BRF_ESS }, //  0 Konami CPU Code
648 	{ "875_w3_1.c24",	0x20000, 0x3c0006fb, 1 | BRF_PRG | BRF_ESS }, //  1
649 
650 	{ "875_b03.g04",	0x08000, 0x1ac4d283, 2 | BRF_PRG | BRF_ESS }, //  2 Z80 Code
651 
652 	{ "875b11.k13",		0x80000, 0x89c5c885, 3 | BRF_GRA },           //  3 Background Tiles
653 	{ "875b12.k19",		0x80000, 0xea6bdc17, 3 | BRF_GRA },           //  4
654 	{ "875b07.j13",		0x40000, 0xe9c56d66, 3 | BRF_GRA },           //  5
655 	{ "875b08.j19",		0x40000, 0xf9387966, 3 | BRF_GRA },           //  6
656 
657 	{ "875b10.k08",		0x80000, 0x0b1035b1, 4 | BRF_GRA },           //  7 Sprites
658 	{ "875b09.k02",		0x80000, 0xe76b3c19, 4 | BRF_GRA },           //  8
659 	{ "875b06.j08",		0x40000, 0x081a0566, 4 | BRF_GRA },           //  9
660 	{ "875b05.j02",		0x40000, 0x19a261f2, 4 | BRF_GRA },           // 10
661 
662 	{ "875b04.e05",		0x40000, 0x4e209ac8, 5 | BRF_SND },           // 11 K007232 Samples
663 
664 	{ "821a08.h14",		0x00100, 0x7da55800, 6 | BRF_OPT },           // 12 Timing Proms
665 };
666 
667 STD_ROM_PICK(aliens3)
668 STD_ROM_FN(aliens3)
669 
670 struct BurnDriver BurnDrvAliens3 = {
671 	"aliens3", "aliens", NULL, NULL, "1990",
672 	"Aliens (World set 3)\0", NULL, "Konami", "GX875",
673 	NULL, NULL, NULL, NULL,
674 	BDF_GAME_WORKING | BDF_CLONE, 2, HARDWARE_PREFIX_KONAMI, GBF_PLATFORM | GBF_HORSHOOT, 0,
675 	NULL, aliens3RomInfo, aliens3RomName, NULL, NULL, NULL, NULL, AliensInputInfo, AliensDIPInfo,
676 	DrvInit, DrvExit, DrvFrame, DrvDraw, DrvScan, &DrvRecalc, 0x200,
677 	288, 224, 4, 3
678 };
679 
680 
681 // Aliens (US)
682 
683 static struct BurnRomInfo aliensuRomDesc[] = {
684 	{ "875_n02.e24",	0x10000, 0x24dd612e, 1 | BRF_PRG | BRF_ESS }, //  0 Konami CPU Code
685 	{ "875_n01.c24",	0x20000, 0x106cf59c, 1 | BRF_PRG | BRF_ESS }, //  1
686 
687 	{ "875_b03.g04",	0x08000, 0x1ac4d283, 2 | BRF_PRG | BRF_ESS }, //  2 Z80 Code
688 
689 	{ "875b11.k13",		0x80000, 0x89c5c885, 3 | BRF_GRA },           //  3 Background Tiles
690 	{ "875b12.k19",		0x80000, 0xea6bdc17, 3 | BRF_GRA },           //  4
691 	{ "875b07.j13",		0x40000, 0xe9c56d66, 3 | BRF_GRA },           //  5
692 	{ "875b08.j19",		0x40000, 0xf9387966, 3 | BRF_GRA },           //  6
693 
694 	{ "875b10.k08",		0x80000, 0x0b1035b1, 4 | BRF_GRA },           //  7 Sprites
695 	{ "875b09.k02",		0x80000, 0xe76b3c19, 4 | BRF_GRA },           //  8
696 	{ "875b06.j08",		0x40000, 0x081a0566, 4 | BRF_GRA },           //  9
697 	{ "875b05.j02",		0x40000, 0x19a261f2, 4 | BRF_GRA },           // 10
698 
699 	{ "875b04.e05",		0x40000, 0x4e209ac8, 5 | BRF_SND },           // 11 K007232 Samples
700 
701 	{ "821a08.h14",		0x00100, 0x7da55800, 6 | BRF_OPT },           // 12 Timing Proms
702 };
703 
704 STD_ROM_PICK(aliensu)
705 STD_ROM_FN(aliensu)
706 
707 struct BurnDriver BurnDrvAliensu = {
708 	"aliensu", "aliens", NULL, NULL, "1990",
709 	"Aliens (US)\0", NULL, "Konami", "GX875",
710 	NULL, NULL, NULL, NULL,
711 	BDF_GAME_WORKING | BDF_CLONE, 2, HARDWARE_PREFIX_KONAMI, GBF_PLATFORM | GBF_HORSHOOT, 0,
712 	NULL, aliensuRomInfo, aliensuRomName, NULL, NULL, NULL, NULL, AliensInputInfo, AliensDIPInfo,
713 	DrvInit, DrvExit, DrvFrame, DrvDraw, DrvScan, &DrvRecalc, 0x200,
714 	288, 224, 4, 3
715 };
716 
717 
718 // Aliens (Japan set 1)
719 
720 static struct BurnRomInfo aliensjRomDesc[] = {
721 	{ "875_m02.e24",	0x10000, 0x54a774e5, 1 | BRF_PRG | BRF_ESS }, //  0 Konami CPU Code
722 	{ "875_m01.c24",	0x20000, 0x1663d3dc, 1 | BRF_PRG | BRF_ESS }, //  1
723 
724 	{ "875_k03.g04",	0x08000, 0xbd86264d, 2 | BRF_PRG | BRF_ESS }, //  2 Z80 Code
725 
726 	{ "875b11.k13",		0x80000, 0x89c5c885, 3 | BRF_GRA },           //  3 Background Tiles
727 	{ "875b12.k19",		0x80000, 0xea6bdc17, 3 | BRF_GRA },           //  4
728 	{ "875b07.j13",		0x40000, 0xe9c56d66, 3 | BRF_GRA },           //  5
729 	{ "875b08.j19",		0x40000, 0xf9387966, 3 | BRF_GRA },           //  6
730 
731 	{ "875b10.k08",		0x80000, 0x0b1035b1, 4 | BRF_GRA },           //  7 Sprites
732 	{ "875b09.k02",		0x80000, 0xe76b3c19, 4 | BRF_GRA },           //  8
733 	{ "875b06.j08",		0x40000, 0x081a0566, 4 | BRF_GRA },           //  9
734 	{ "875b05.j02",		0x40000, 0x19a261f2, 4 | BRF_GRA },           // 10
735 
736 	{ "875b04.e05",		0x40000, 0x4e209ac8, 5 | BRF_SND },           // 11 K007232 Samples
737 
738 	{ "821a08.h14",		0x00100, 0x7da55800, 6 | BRF_OPT },           // 12 Timing Proms
739 };
740 
741 STD_ROM_PICK(aliensj)
742 STD_ROM_FN(aliensj)
743 
744 struct BurnDriver BurnDrvAliensj = {
745 	"aliensj", "aliens", NULL, NULL, "1990",
746 	"Aliens (Japan set 1)\0", NULL, "Konami", "GX875",
747 	NULL, NULL, NULL, NULL,
748 	BDF_GAME_WORKING | BDF_CLONE, 2, HARDWARE_PREFIX_KONAMI, GBF_PLATFORM | GBF_HORSHOOT, 0,
749 	NULL, aliensjRomInfo, aliensjRomName, NULL, NULL, NULL, NULL, AliensInputInfo, AliensDIPInfo,
750 	DrvInit, DrvExit, DrvFrame, DrvDraw, DrvScan, &DrvRecalc, 0x200,
751 	288, 224, 4, 3
752 };
753 
754 
755 // Aliens (Japan set 2)
756 
757 static struct BurnRomInfo aliensj2RomDesc[] = {
758 	{ "875_j2_2.e24",	0x10000, 0x4bb84952, 1 | BRF_PRG | BRF_ESS }, //  0 Konami CPU Code
759 	{ "875_m01.c24",	0x20000, 0x1663d3dc, 1 | BRF_PRG | BRF_ESS }, //  1
760 
761 	{ "875_k03.g04",	0x08000, 0xbd86264d, 2 | BRF_PRG | BRF_ESS }, //  2 Z80 Code
762 
763 	{ "875b11.k13",		0x80000, 0x89c5c885, 3 | BRF_GRA },           //  3 Background Tiles
764 	{ "875b12.k19",		0x80000, 0xea6bdc17, 3 | BRF_GRA },           //  4
765 	{ "875b07.j13",		0x40000, 0xe9c56d66, 3 | BRF_GRA },           //  5
766 	{ "875b08.j19",		0x40000, 0xf9387966, 3 | BRF_GRA },           //  6
767 
768 	{ "875b10.k08",		0x80000, 0x0b1035b1, 4 | BRF_GRA },           //  7 Sprites
769 	{ "875b09.k02",		0x80000, 0xe76b3c19, 4 | BRF_GRA },           //  8
770 	{ "875b06.j08",		0x40000, 0x081a0566, 4 | BRF_GRA },           //  9
771 	{ "875b05.j02",		0x40000, 0x19a261f2, 4 | BRF_GRA },           // 10
772 
773 	{ "875b04.e05",		0x40000, 0x4e209ac8, 5 | BRF_SND },           // 11 K007232 Samples
774 
775 	{ "821a08.h14",		0x00100, 0x7da55800, 6 | BRF_OPT },           // 12 Timing Proms
776 };
777 
778 STD_ROM_PICK(aliensj2)
779 STD_ROM_FN(aliensj2)
780 
781 struct BurnDriver BurnDrvAliensj2 = {
782 	"aliensj2", "aliens", NULL, NULL, "1990",
783 	"Aliens (Japan set 2)\0", NULL, "Konami", "GX875",
784 	NULL, NULL, NULL, NULL,
785 	BDF_GAME_WORKING | BDF_CLONE, 2, HARDWARE_PREFIX_KONAMI, GBF_PLATFORM | GBF_HORSHOOT, 0,
786 	NULL, aliensj2RomInfo, aliensj2RomName, NULL, NULL, NULL, NULL, AliensInputInfo, AliensDIPInfo,
787 	DrvInit, DrvExit, DrvFrame, DrvDraw, DrvScan, &DrvRecalc, 0x200,
788 	288, 224, 4, 3
789 };
790 
791 
792 // Aliens (Asia)
793 
794 static struct BurnRomInfo aliensaRomDesc[] = {
795 	{ "875_r02.e24",	0x10000, 0x973e4f11, 1 | BRF_PRG | BRF_ESS }, //  0 Konami CPU Code
796 	{ "875_m01.c24",	0x20000, 0x1663d3dc, 1 | BRF_PRG | BRF_ESS }, //  1
797 
798 	{ "875_k03.g04",	0x08000, 0xbd86264d, 2 | BRF_PRG | BRF_ESS }, //  2 Z80 Code
799 
800 	{ "875b11.k13",		0x80000, 0x89c5c885, 3 | BRF_GRA },           //  3 Background Tiles
801 	{ "875b12.k19",		0x80000, 0xea6bdc17, 3 | BRF_GRA },           //  4
802 	{ "875b07.j13",		0x40000, 0xe9c56d66, 3 | BRF_GRA },           //  5
803 	{ "875b08.j19",		0x40000, 0xf9387966, 3 | BRF_GRA },           //  6
804 
805 	{ "875b10.k08",		0x80000, 0x0b1035b1, 4 | BRF_GRA },           //  7 Sprites
806 	{ "875b09.k02",		0x80000, 0xe76b3c19, 4 | BRF_GRA },           //  8
807 	{ "875b06.j08",		0x40000, 0x081a0566, 4 | BRF_GRA },           //  9
808 	{ "875b05.j02",		0x40000, 0x19a261f2, 4 | BRF_GRA },           // 10
809 
810 	{ "875b04.e05",		0x40000, 0x4e209ac8, 5 | BRF_SND },           // 11 K007232 Samples
811 
812 	{ "821a08.h14",		0x00100, 0x7da55800, 6 | BRF_OPT },           // 12 Timing Proms
813 };
814 
815 STD_ROM_PICK(aliensa)
816 STD_ROM_FN(aliensa)
817 
818 struct BurnDriver BurnDrvAliensa = {
819 	"aliensa", "aliens", NULL, NULL, "1990",
820 	"Aliens (Asia)\0", NULL, "Konami", "GX875",
821 	NULL, NULL, NULL, NULL,
822 	BDF_GAME_WORKING | BDF_CLONE, 2, HARDWARE_PREFIX_KONAMI, GBF_PLATFORM | GBF_HORSHOOT, 0,
823 	NULL, aliensaRomInfo, aliensaRomName, NULL, NULL, NULL, NULL, AliensInputInfo, AliensDIPInfo,
824 	DrvInit, DrvExit, DrvFrame, DrvDraw, DrvScan, &DrvRecalc, 0x200,
825 	288, 224, 4, 3
826 };
827