1 /***************************************************************************
2 
3 	Atari Bad Lands hardware
4 
5     driver by Aaron Giles
6 
7 	Games supported:
8 		* Bad Lands (1989)
9 
10 	Known bugs:
11 		* none at this time
12 
13 ****************************************************************************
14 
15 	Memory map
16 
17 ****************************************************************************
18 
19 	========================================================================
20 	MAIN CPU
21 	========================================================================
22 	000000-03FFFF   R     xxxxxxxx xxxxxxxx   Program ROM
23 	FC0000          R     -------x --------   Sound command buffer full
24 	FC0000            W   -------- --------   Sound CPU reset
25 	FD0000-FD1FFF   R/W   -------- xxxxxxxx   EEPROM
26 	FE0000            W   -------- --------   Watchdog reset
27 	FE2000            W   -------- --------   VBLANK IRQ acknowledge
28 	FE4000          R     -------- xxxx----   Switch inputs
29 	                R     -------- x-------      (Self test)
30 	                R     -------- -x------      (VBLANK)
31 	                R     -------- --x-----      (Player 2 button)
32 	                R     -------- ---x----      (Player 1 button)
33 	FE6000          R     -------- xxxxxxxx   Player 1 steering
34 	FE6002          R     -------- xxxxxxxx   Player 2 steering
35 	FE6004          R     -------- xxxxxxxx   Player 1 pedal
36 	FE6006          R     -------- xxxxxxxx   Player 2 pedal
37 	FE8000            W   xxxxxxxx --------   Sound command write
38 	FEA000          R     xxxxxxxx --------   Sound response read
39 	FEC000            W   -------- -------x   Playfield tile bank select
40 	FEE000            W   -------- --------   EEPROM enable
41 	FFC000-FFC0FF   R/W   xxxxxxxx xxxxxxxx   Playfield palette RAM (128 entries)
42 	                R/W   x------- --------      (RGB 1 LSB)
43 	                R/W   -xxxxx-- --------      (Red 5 MSB)
44 	                R/W   ------xx xxx-----      (Green 5 MSB)
45 	                R/W   -------- ---xxxxx      (Blue 5 MSB)
46 	FFC100-FFC1FF   R/W   xxxxxxxx xxxxxxxx   Motion object palette RAM (128 entries)
47 	FFC200-FFC3FF   R/W   xxxxxxxx xxxxxxxx   Extra palette RAM (256 entries)
48 	FFE000-FFEFFF   R/W   xxxxxxxx xxxxxxxx   Playfield RAM (64x32 tiles)
49 	                R/W   xxx----- --------      (Palette select)
50 	                R/W   ---x---- --------      (Tile bank select)
51 	                R/W   ----xxxx xxxxxxxx      (Tile index)
52 	FFF000-FFFFFF   R/W   xxxxxxxx xxxxxxxx   Motion object RAM (32 entries x 4 words)
53 	                R/W   ----xxxx xxxxxxxx      (0: Tile index)
54 	                R/W   xxxxxxxx x-------      (1: Y position)
55 	                R/W   -------- ----xxxx      (1: Number of Y tiles - 1)
56 	                R/W   xxxxxxxx x-------      (3: X position)
57 	                R/W   -------- ----x---      (3: Priority)
58 	                R/W   -------- -----xxx      (3: Palette select)
59 	========================================================================
60 	Interrupts:
61 		IRQ1 = VBLANK
62 		IRQ2 = sound CPU communications
63 	========================================================================
64 
65 
66 	========================================================================
67 	SOUND CPU (based on JSA II, but implemented onboard)
68 	========================================================================
69 	0000-1FFF   R/W   xxxxxxxx   Program RAM
70 	2000-2001   R/W   xxxxxxxx   YM2151 communications
71 	2802        R     xxxxxxxx   Sound command read
72 	2804        R     xxxx--xx   Status input
73 	            R     x-------      (Self test)
74 	            R     -x------      (Sound command buffer full)
75 	            R     --x-----      (Sound response buffer full)
76 	            R     ---x----      (Self test)
77 	            R     ------xx      (Coin inputs)
78 	2806        R/W   --------   IRQ acknowledge
79 	2A02          W   xxxxxxxx   Sound response write
80 	2A04          W   xxxx---x   Sound control
81 	              W   xx------      (ROM bank select)
82 	              W   --xx----      (Coin counters)
83 	              W   -------x      (YM2151 reset)
84 	3000-3FFF   R     xxxxxxxx   Banked ROM
85 	4000-FFFF   R     xxxxxxxx   Program ROM
86 	========================================================================
87 	Interrupts:
88 		IRQ = timed interrupt ORed with YM2151 interrupt
89 		NMI = latch on sound command
90 	========================================================================
91 
92 ****************************************************************************/
93 
94 
95 #include "driver.h"
96 #include "machine/atarigen.h"
97 #include "badlands.h"
98 
99 
100 
101 /*************************************
102  *
103  *	Statics
104  *
105  *************************************/
106 
107 static UINT8 pedal_value[2];
108 
109 static UINT8 *bank_base;
110 static UINT8 *bank_source_data;
111 
112 
113 
114 /*************************************
115  *
116  *	Initialization
117  *
118  *************************************/
119 
update_interrupts(void)120 static void update_interrupts(void)
121 {
122 	int newstate = 0;
123 
124 	if (atarigen_video_int_state)
125 		newstate = 1;
126 	if (atarigen_sound_int_state)
127 		newstate = 2;
128 
129 	if (newstate)
130 		cpu_set_irq_line(0, newstate, ASSERT_LINE);
131 	else
132 		cpu_set_irq_line(0, 7, CLEAR_LINE);
133 }
134 
135 
scanline_update(int scanline)136 static void scanline_update(int scanline)
137 {
138 	/* sound IRQ is on 32V */
139 	if (scanline & 32)
140 		atarigen_6502_irq_ack_r(0);
141 	else if (!(readinputport(0) & 0x40))
142 		atarigen_6502_irq_gen();
143 }
144 
145 
MACHINE_INIT(badlands)146 static MACHINE_INIT( badlands )
147 {
148 	pedal_value[0] = pedal_value[1] = 0x80;
149 
150 	atarigen_eeprom_reset();
151 	atarigen_interrupt_reset(update_interrupts);
152 	atarigen_scanline_timer_reset(scanline_update, 32);
153 
154 	atarigen_sound_io_reset(1);
155 	memcpy(bank_base, &bank_source_data[0x0000], 0x1000);
156 }
157 
158 
159 
160 /*************************************
161  *
162  *	Interrupt handling
163  *
164  *************************************/
165 
INTERRUPT_GEN(vblank_int)166 static INTERRUPT_GEN( vblank_int )
167 {
168 	int pedal_state = input_port_4_r(0);
169 	int i;
170 
171 	/* update the pedals once per frame */
172     for (i = 0; i < 2; i++)
173 	{
174 		pedal_value[i]--;
175 		if (pedal_state & (1 << i))
176 			pedal_value[i]++;
177 	}
178 
179 	atarigen_video_int_gen();
180 }
181 
182 
183 
184 /*************************************
185  *
186  *	I/O read dispatch
187  *
188  *************************************/
189 
READ16_HANDLER(sound_busy_r)190 static READ16_HANDLER( sound_busy_r )
191 {
192 	int temp = 0xfeff;
193 	if (atarigen_cpu_to_sound_ready) temp ^= 0x0100;
194 	return temp;
195 }
196 
197 
READ16_HANDLER(pedal_0_r)198 static READ16_HANDLER( pedal_0_r )
199 {
200 	return pedal_value[0];
201 }
202 
203 
READ16_HANDLER(pedal_1_r)204 static READ16_HANDLER( pedal_1_r )
205 {
206 	return pedal_value[1];
207 }
208 
209 
210 
211 /*************************************
212  *
213  *	Audio I/O handlers
214  *
215  *************************************/
216 
READ_HANDLER(audio_io_r)217 static READ_HANDLER( audio_io_r )
218 {
219 	int result = 0xff;
220 
221 	switch (offset & 0x206)
222 	{
223 		case 0x000:		/* n/c */
224 			log_cb(RETRO_LOG_DEBUG, LOGPRE "audio_io_r: Unknown read at %04X\n", offset & 0x206);
225 			break;
226 
227 		case 0x002:		/* /RDP */
228 			result = atarigen_6502_sound_r(offset);
229 			break;
230 
231 		case 0x004:		/* /RDIO */
232 			/*
233 				0x80 = self test
234 				0x40 = NMI line state (active low)
235 				0x20 = sound output full
236 				0x10 = self test
237 				0x08 = +5V
238 				0x04 = +5V
239 				0x02 = coin 2
240 				0x01 = coin 1
241 			*/
242 			result = readinputport(3);
243 			if (!(readinputport(0) & 0x0080)) result ^= 0x90;
244 			if (atarigen_cpu_to_sound_ready) result ^= 0x40;
245 			if (atarigen_sound_to_cpu_ready) result ^= 0x20;
246 			result ^= 0x10;
247 			break;
248 
249 		case 0x006:		/* /IRQACK */
250 			atarigen_6502_irq_ack_r(0);
251 			break;
252 
253 		case 0x200:		/* /VOICE */
254 		case 0x202:		/* /WRP */
255 		case 0x204:		/* /WRIO */
256 		case 0x206:		/* /MIX */
257 			log_cb(RETRO_LOG_DEBUG, LOGPRE "audio_io_r: Unknown read at %04X\n", offset & 0x206);
258 			break;
259 	}
260 
261 	return result;
262 }
263 
264 
WRITE_HANDLER(audio_io_w)265 static WRITE_HANDLER( audio_io_w )
266 {
267 	switch (offset & 0x206)
268 	{
269 		case 0x000:		/* n/c */
270 		case 0x002:		/* /RDP */
271 		case 0x004:		/* /RDIO */
272 			log_cb(RETRO_LOG_DEBUG, LOGPRE "audio_io_w: Unknown write (%02X) at %04X\n", data & 0xff, offset & 0x206);
273 			break;
274 
275 		case 0x006:		/* /IRQACK */
276 			atarigen_6502_irq_ack_r(0);
277 			break;
278 
279 		case 0x200:		/* n/c */
280 		case 0x206:		/* n/c */
281 			break;
282 
283 		case 0x202:		/* /WRP */
284 			atarigen_6502_sound_w(offset, data);
285 			break;
286 
287 		case 0x204:		/* WRIO */
288 			/*
289 				0xc0 = bank address
290 				0x20 = coin counter 2
291 				0x10 = coin counter 1
292 				0x08 = n/c
293 				0x04 = n/c
294 				0x02 = n/c
295 				0x01 = YM2151 reset (active low)
296 			*/
297 
298 			/* update the bank */
299 			memcpy(bank_base, &bank_source_data[0x1000 * ((data >> 6) & 3)], 0x1000);
300 			break;
301 	}
302 }
303 
304 
305 
306 /*************************************
307  *
308  *	Main CPU memory handlers
309  *
310  *************************************/
311 
MEMORY_READ16_START(main_readmem)312 static MEMORY_READ16_START( main_readmem )
313 	{ 0x000000, 0x03ffff, MRA16_ROM },
314 	{ 0xfc0000, 0xfc1fff, sound_busy_r },
315 	{ 0xfd0000, 0xfd1fff, atarigen_eeprom_r },
316 	{ 0xfe4000, 0xfe5fff, input_port_0_word_r },
317 	{ 0xfe6000, 0xfe6001, input_port_1_word_r },
318 	{ 0xfe6002, 0xfe6003, input_port_2_word_r },
319 	{ 0xfe6004, 0xfe6005, pedal_0_r },
320 	{ 0xfe6006, 0xfe6007, pedal_1_r },
321 	{ 0xfea000, 0xfebfff, atarigen_sound_upper_r },
322 	{ 0xffc000, 0xffc3ff, MRA16_RAM },
323 	{ 0xffe000, 0xffffff, MRA16_RAM },
324 MEMORY_END
325 
326 
327 static MEMORY_WRITE16_START( main_writemem )
328 	{ 0x000000, 0x03ffff, MWA16_ROM },
329 	{ 0xfc0000, 0xfc1fff, atarigen_sound_reset_w },
330 	{ 0xfd0000, 0xfd1fff, atarigen_eeprom_w, &atarigen_eeprom, &atarigen_eeprom_size },
331 	{ 0xfe0000, 0xfe1fff, watchdog_reset16_w },
332 	{ 0xfe2000, 0xfe3fff, atarigen_video_int_ack_w },
333 	{ 0xfe8000, 0xfe9fff, atarigen_sound_upper_w },
334 	{ 0xfec000, 0xfedfff, badlands_pf_bank_w },
335 	{ 0xfee000, 0xfeffff, atarigen_eeprom_enable_w },
336 	{ 0xffc000, 0xffc3ff, atarigen_expanded_666_paletteram_w, &paletteram16 },
337 	{ 0xffe000, 0xffefff, atarigen_playfield_w, &atarigen_playfield },
338 	{ 0xfff000, 0xfff1ff, atarimo_0_spriteram_expanded_w, &atarimo_0_spriteram },
339 	{ 0xfff200, 0xffffff, MWA16_RAM },
340 MEMORY_END
341 
342 
343 
344 /*************************************
345  *
346  *	Sound CPU memory handlers
347  *
348  *************************************/
349 
350 static MEMORY_READ_START( audio_readmem )
351 	{ 0x0000, 0x1fff, MRA_RAM },
352 	{ 0x2000, 0x2001, YM2151_status_port_0_r },
353 	{ 0x2800, 0x2bff, audio_io_r },
354 	{ 0x3000, 0xffff, MRA_ROM },
355 MEMORY_END
356 
357 
358 static MEMORY_WRITE_START( audio_writemem )
359 	{ 0x0000, 0x1fff, MWA_RAM },
360 	{ 0x2000, 0x2000, YM2151_register_port_0_w },
361 	{ 0x2001, 0x2001, YM2151_data_port_0_w },
362 	{ 0x2800, 0x2bff, audio_io_w },
363 	{ 0x3000, 0xffff, MWA_ROM },
364 MEMORY_END
365 
366 
367 
368 /*************************************
369  *
370  *	Port definitions
371  *
372  *************************************/
373 
374 INPUT_PORTS_START( badlands )
375 	PORT_START		/* fe4000 */
376 	PORT_BIT( 0x000f, IP_ACTIVE_LOW, IPT_UNUSED )
377 	PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON2 | IPF_PLAYER1 )
378 	PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_START1 )
379 	PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON2 | IPF_PLAYER2 )
380 	PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_START2 )
381 	PORT_BIT( 0x0040, IP_ACTIVE_HIGH, IPT_VBLANK )
382 	PORT_SERVICE( 0x0080, IP_ACTIVE_LOW )
383 	PORT_BIT( 0xff00, IP_ACTIVE_LOW, IPT_UNUSED )
384 
385 	PORT_START      /* fe6000 */
386 	PORT_ANALOG( 0x00ff, 0, IPT_DIAL | IPF_PLAYER1, 50, 10, 0, 0 )
387 	PORT_BIT( 0xff00, IP_ACTIVE_LOW, IPT_UNUSED )
388 
389 	PORT_START      /* fe6002 */
390 	PORT_ANALOG( 0x00ff, 0, IPT_DIAL | IPF_PLAYER2, 50, 10, 0, 0 )
391 	PORT_BIT( 0xff00, IP_ACTIVE_LOW, IPT_UNUSED )
392 
393 	PORT_START		/* audio port */
394 	PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_COIN1 )
395 	PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_COIN2 )
396 	PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_COIN3 )
397 	PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_UNUSED )
398 	PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_SPECIAL )	/* self test */
399 	PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_SPECIAL )	/* response buffer full */
400 	PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_SPECIAL )	/* command buffer full */
401 	PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_SPECIAL )	/* self test */
402 
403 	PORT_START      /* fake for pedals */
404 	PORT_BIT( 0x0001, IP_ACTIVE_HIGH, IPT_BUTTON1 | IPF_PLAYER1 )
405 	PORT_BIT( 0x0002, IP_ACTIVE_HIGH, IPT_BUTTON1 | IPF_PLAYER2 )
406 	PORT_BIT( 0xfffe, IP_ACTIVE_HIGH, IPT_UNUSED )
407 INPUT_PORTS_END
408 
409 
410 
411 /*************************************
412  *
413  *	Graphics definitions
414  *
415  *************************************/
416 
417 static struct GfxLayout pflayout =
418 {
419 	8,8,
420 	RGN_FRAC(1,1),
421 	4,
422 	{ 0, 1, 2, 3 },
423 	{ 0, 4, 8, 12, 16, 20, 24, 28 },
424 	{ 0*8, 4*8, 8*8, 12*8, 16*8, 20*8, 24*8, 28*8 },
425 	32*8
426 };
427 
428 
429 static struct GfxLayout molayout =
430 {
431 	16,8,
432 	RGN_FRAC(1,1),
433 	4,
434 	{ 0, 1, 2, 3 },
435 	{ 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60 },
436 	{ 0*8, 8*8, 16*8, 24*8, 32*8, 40*8, 48*8, 56*8 },
437 	64*8
438 };
439 
440 
441 static struct GfxDecodeInfo gfxdecodeinfo[] =
442 {
443 	{ REGION_GFX1, 0, &pflayout,    0, 8 },
444 	{ REGION_GFX2, 0, &molayout,  128, 8 },
445 	{ -1 }
446 };
447 
448 
449 
450 /*************************************
451  *
452  *	Sound definitions
453  *
454  *************************************/
455 
456 static struct YM2151interface ym2151_interface =
457 {
458 	1,
459 	ATARI_CLOCK_14MHz/4,
460 	{ YM3012_VOL(30,MIXER_PAN_CENTER,30,MIXER_PAN_CENTER) },
461 	{ 0 }
462 };
463 
464 
465 
466 /*************************************
467  *
468  *	Machine driver
469  *
470  *************************************/
471 
472 static MACHINE_DRIVER_START( badlands )
473 
474 	/* basic machine hardware */
475 	MDRV_CPU_ADD(M68000, ATARI_CLOCK_14MHz/2)
MDRV_CPU_MEMORY(main_readmem,main_writemem)476 	MDRV_CPU_MEMORY(main_readmem,main_writemem)
477 	MDRV_CPU_VBLANK_INT(vblank_int,1)
478 
479 	MDRV_CPU_ADD(M6502, ATARI_CLOCK_14MHz/8)
480 	MDRV_CPU_MEMORY(audio_readmem,audio_writemem)
481 
482 	MDRV_FRAMES_PER_SECOND(60)
483 	MDRV_VBLANK_DURATION(DEFAULT_REAL_60HZ_VBLANK_DURATION)
484 
485 	MDRV_MACHINE_INIT(badlands)
486 	MDRV_NVRAM_HANDLER(atarigen)
487 
488 	/* video hardware */
489 	MDRV_VIDEO_ATTRIBUTES(VIDEO_TYPE_RASTER | VIDEO_NEEDS_6BITS_PER_GUN | VIDEO_UPDATE_BEFORE_VBLANK)
490 	MDRV_SCREEN_SIZE(42*8, 30*8)
491 	MDRV_VISIBLE_AREA(0*8, 42*8-1, 0*8, 30*8-1)
492 	MDRV_GFXDECODE(gfxdecodeinfo)
493 	MDRV_PALETTE_LENGTH(256)
494 
495 	MDRV_VIDEO_START(badlands)
496 	MDRV_VIDEO_UPDATE(badlands)
497 
498 	/* sound hardware */
499 	MDRV_SOUND_ADD(YM2151, ym2151_interface)
500 MACHINE_DRIVER_END
501 
502 
503 
504 /*************************************
505  *
506  *	ROM definition(s)
507  *
508  *************************************/
509 
510 ROM_START( badlands )
511 	ROM_REGION( 0x40000, REGION_CPU1, 0 )	/* 4*64k for 68000 code */
512 	ROM_LOAD16_BYTE( "1008.20f",  0x00000, 0x10000, CRC(a3da5774) SHA1(5ab1eb61d25594b2d7c40400cb57e7f47a717598) )
513 	ROM_LOAD16_BYTE( "1006.27f",  0x00001, 0x10000, CRC(aa03b4f3) SHA1(5eda60c715ffcefd4ad34bdb90579e8671dc384a) )
514 	ROM_LOAD16_BYTE( "1009.17f",  0x20000, 0x10000, CRC(0e2e807f) SHA1(5b61de066dca12c44335aa68a13c821845657866) )
515 	ROM_LOAD16_BYTE( "1007.24f",  0x20001, 0x10000, CRC(99a20c2c) SHA1(9b0a5a5dafb8816e72330d302c60339b600b49a8) )
516 
517 	ROM_REGION( 0x14000, REGION_CPU2, 0 )	/* 64k for 6502 code */
518 	ROM_LOAD( "1018.9c", 0x10000, 0x4000, CRC(a05fd146) SHA1(d97abbcf7897ca720cc18ff3a323f41cd3b23c34) )
519 	ROM_CONTINUE(        0x04000, 0xc000 )
520 
521 	ROM_REGION( 0x60000, REGION_GFX1, ROMREGION_DISPOSE | ROMREGION_INVERT )
522 	ROM_LOAD( "1012.4n",  0x000000, 0x10000, CRC(5d124c6c) SHA1(afebaaf90b3751f5e873fc4c45f1d5385ef86a6e) )	/* playfield */
523 	ROM_LOAD( "1013.2n",  0x010000, 0x10000, CRC(b1ec90d6) SHA1(8d4c7db8e1bf9c050f5869eb38fa573867fdc12b) )
524 	ROM_LOAD( "1014.4s",  0x020000, 0x10000, CRC(248a6845) SHA1(086ef0840b889e790ce3fcd09f98589aae932456) )
525 	ROM_LOAD( "1015.2s",  0x030000, 0x10000, CRC(792296d8) SHA1(833cdb968064151ca77bb3dbe416ff7127a12de4) )
526 	ROM_LOAD( "1016.4u",  0x040000, 0x10000, CRC(878f7c66) SHA1(31159bea5d6aac8100fca8f3860220b97d63e72e) )
527 	ROM_LOAD( "1017.2u",  0x050000, 0x10000, CRC(ad0071a3) SHA1(472b197e5d320b3424d8a8d8c051b1023a07ae08) )
528 
529 	ROM_REGION( 0x30000, REGION_GFX2, ROMREGION_DISPOSE | ROMREGION_INVERT )
530 	ROM_LOAD( "1010.14r", 0x000000, 0x10000, CRC(c15f629e) SHA1(944e3479dce6e420cf9a3f4c1438c5ca66e5cb97) )	/* mo */
531 	ROM_LOAD( "1011.10r", 0x010000, 0x10000, CRC(fb0b6717) SHA1(694ab0f04d673682831a24027757d4b3c40a4e0e) )
532 	ROM_LOAD( "1019.14t", 0x020000, 0x10000, CRC(0e26bff6) SHA1(ee018dd37a27c7e7c16a57ea0d32aeb9cdf26bb4) )
533 ROM_END
534 
535 
536 
537 /*************************************
538  *
539  *	Driver initialization
540  *
541  *************************************/
542 
543 static DRIVER_INIT( badlands )
544 {
545 	atarigen_eeprom_default = NULL;
546 	atarigen_init_6502_speedup(1, 0x4155, 0x416d);
547 
548 	/* initialize the audio system */
549 	bank_base = &memory_region(REGION_CPU2)[0x03000];
550 	bank_source_data = &memory_region(REGION_CPU2)[0x10000];
551 }
552 
553 
554 
555 /*************************************
556  *
557  *	Game driver(s)
558  *
559  *************************************/
560 
561 GAME( 1989, badlands, 0, badlands, badlands, badlands, ROT0, "Atari Games", "Bad Lands" )
562