PageRenderTime 26ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/user/games/xmame/xmame-0.106/src/drivers/dragrace.c

https://bitbucket.org/thelearninglabs/uclinux-distro-tll-public
C | 377 lines | 271 code | 64 blank | 42 comment | 8 complexity | 0d343e55e901df3753ab40d0463d0a73 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause, MPL-2.0-no-copyleft-exception, LGPL-3.0, Unlicense, GPL-2.0, GPL-3.0, CC-BY-SA-3.0, AGPL-1.0, ISC, MIT, 0BSD, LGPL-2.0
  1. /***************************************************************************
  2. Atari Drag Race Driver
  3. ***************************************************************************/
  4. #include "driver.h"
  5. #include "dragrace.h"
  6. #include "sound/discrete.h"
  7. static unsigned dragrace_misc_flags = 0;
  8. static int dragrace_gear[2];
  9. static void dragrace_frame_callback(int dummy)
  10. {
  11. int i;
  12. for (i = 0; i < 2; i++)
  13. {
  14. switch (readinputport(5 + i))
  15. {
  16. case 0x01: dragrace_gear[i] = 1; break;
  17. case 0x02: dragrace_gear[i] = 2; break;
  18. case 0x04: dragrace_gear[i] = 3; break;
  19. case 0x08: dragrace_gear[i] = 4; break;
  20. case 0x10: dragrace_gear[i] = 0; break;
  21. }
  22. }
  23. /* watchdog is disabled during service mode */
  24. watchdog_enable(readinputport(0) & 0x20);
  25. }
  26. static MACHINE_RESET( dragrace )
  27. {
  28. timer_pulse(cpu_getscanlinetime(0), 0, dragrace_frame_callback);
  29. }
  30. static void dragrace_update_misc_flags(void)
  31. {
  32. /* 0x0900 = set 3SPEED1 0x00000001
  33. * 0x0901 = set 4SPEED1 0x00000002
  34. * 0x0902 = set 5SPEED1 0x00000004
  35. * 0x0903 = set 6SPEED1 0x00000008
  36. * 0x0904 = set 7SPEED1 0x00000010
  37. * 0x0905 = set EXPLOSION1 0x00000020
  38. * 0x0906 = set SCREECH1 0x00000040
  39. * 0x0920 - 0x0927 = clear 0x0900 - 0x0907
  40. * 0x0909 = set KLEXPL1 0x00000200
  41. * 0x090b = set MOTOR1 0x00000800
  42. * 0x090c = set ATTRACT 0x00001000
  43. * 0x090d = set LOTONE 0x00002000
  44. * 0x090f = set Player 1 Start Lamp 0x00008000
  45. * 0x0928 - 0x092f = clear 0x0908 - 0x090f
  46. * 0x0910 = set 3SPEED2 0x00010000
  47. * 0x0911 = set 4SPEED2 0x00020000
  48. * 0x0912 = set 5SPEED2 0x00040000
  49. * 0x0913 = set 6SPEED2 0x00080000
  50. * 0x0914 = set 7SPEED2 0x00100000
  51. * 0x0915 = set EXPLOSION2 0x00200000
  52. * 0x0916 = set SCREECH2 0x00400000
  53. * 0x0930 = clear 0x0910 - 0x0917
  54. * 0x0919 = set KLEXPL2 0x02000000
  55. * 0x091b = set MOTOR2 0x08000000
  56. * 0x091d = set HITONE 0x20000000
  57. * 0x091f = set Player 2 Start Lamp 0x80000000
  58. * 0x0938 = clear 0x0918 - 0x091f
  59. */
  60. set_led_status(0, dragrace_misc_flags & 0x00008000);
  61. set_led_status(1, dragrace_misc_flags & 0x80000000);
  62. discrete_sound_w(DRAGRACE_MOTOR1_DATA, ~dragrace_misc_flags & 0x0000001f); /* Speed1 data* */
  63. discrete_sound_w(DRAGRACE_EXPLODE1_EN, (dragrace_misc_flags & 0x00000020) ? 1: 0); /* Explosion1 enable */
  64. discrete_sound_w(DRAGRACE_SCREECH1_EN, (dragrace_misc_flags & 0x00000040) ? 1: 0); /* Screech1 enable */
  65. discrete_sound_w(DRAGRACE_KLEXPL1_EN, (dragrace_misc_flags & 0x00000200) ? 1: 0); /* KLEXPL1 enable */
  66. discrete_sound_w(DRAGRACE_MOTOR1_EN, (dragrace_misc_flags & 0x00000800) ? 1: 0); /* Motor1 enable */
  67. discrete_sound_w(DRAGRACE_MOTOR2_DATA, (~dragrace_misc_flags & 0x001f0000) >> 0x10); /* Speed2 data* */
  68. discrete_sound_w(DRAGRACE_EXPLODE2_EN, (dragrace_misc_flags & 0x00200000) ? 1: 0); /* Explosion2 enable */
  69. discrete_sound_w(DRAGRACE_SCREECH2_EN, (dragrace_misc_flags & 0x00400000) ? 1: 0); /* Screech2 enable */
  70. discrete_sound_w(DRAGRACE_KLEXPL2_EN, (dragrace_misc_flags & 0x02000000) ? 1: 0); /* KLEXPL2 enable */
  71. discrete_sound_w(DRAGRACE_MOTOR2_EN, (dragrace_misc_flags & 0x08000000) ? 1: 0); /* Motor2 enable */
  72. discrete_sound_w(DRAGRACE_ATTRACT_EN, (dragrace_misc_flags & 0x00001000) ? 1: 0); /* Attract enable */
  73. discrete_sound_w(DRAGRACE_LOTONE_EN, (dragrace_misc_flags & 0x00002000) ? 1: 0); /* LoTone enable */
  74. discrete_sound_w(DRAGRACE_HITONE_EN, (dragrace_misc_flags & 0x20000000) ? 1: 0); /* HiTone enable */
  75. }
  76. WRITE8_HANDLER( dragrace_misc_w )
  77. {
  78. /* Set/clear individual bit */
  79. UINT32 mask = 1 << offset;
  80. if (data & 0x01)
  81. dragrace_misc_flags |= mask;
  82. else
  83. dragrace_misc_flags &= (~mask);
  84. logerror("Set %#6x, Mask=%#10x, Flag=%#10x, Data=%x\n", 0x0900+offset, mask, dragrace_misc_flags, data & 0x01);
  85. dragrace_update_misc_flags();
  86. }
  87. WRITE8_HANDLER( dragrace_misc_clear_w )
  88. {
  89. /* Clear 8 bits */
  90. UINT32 mask = 0xff << (((offset >> 3) & 0x03) * 8);
  91. dragrace_misc_flags &= (~mask);
  92. logerror("Clear %#6x, Mask=%#10x, Flag=%#10x, Data=%x\n", 0x0920+offset, mask, dragrace_misc_flags, data & 0x01);
  93. dragrace_update_misc_flags();
  94. }
  95. READ8_HANDLER( dragrace_input_r )
  96. {
  97. int val = readinputport(2);
  98. UINT8 maskA = 1 << (offset % 8);
  99. UINT8 maskB = 1 << (offset / 8);
  100. int i;
  101. for (i = 0; i < 2; i++)
  102. {
  103. int in = readinputport(i);
  104. if (dragrace_gear[i] != 0)
  105. {
  106. in &= ~(1 << dragrace_gear[i]);
  107. }
  108. if (in & maskA)
  109. {
  110. val |= 1 << i;
  111. }
  112. }
  113. return (val & maskB) ? 0xFF : 0x7F;
  114. }
  115. READ8_HANDLER( dragrace_steering_r )
  116. {
  117. int bitA[2];
  118. int bitB[2];
  119. int i;
  120. for (i = 0; i < 2; i++)
  121. {
  122. int dial = readinputport(3 + i);
  123. bitA[i] = ((dial + 1) / 2) & 1;
  124. bitB[i] = ((dial + 0) / 2) & 1;
  125. }
  126. return
  127. (bitA[0] << 0) | (bitB[0] << 1) |
  128. (bitA[1] << 2) | (bitB[1] << 3);
  129. }
  130. READ8_HANDLER( dragrace_scanline_r )
  131. {
  132. return (cpu_getscanline() ^ 0xf0) | 0x0f;
  133. }
  134. static ADDRESS_MAP_START( dragrace_readmem, ADDRESS_SPACE_PROGRAM, 8 )
  135. AM_RANGE(0x0080, 0x00ff) AM_READ(MRA8_RAM)
  136. AM_RANGE(0x0800, 0x083f) AM_READ(dragrace_input_r)
  137. AM_RANGE(0x0c00, 0x0c00) AM_READ(dragrace_steering_r)
  138. AM_RANGE(0x0d00, 0x0d00) AM_READ(dragrace_scanline_r)
  139. AM_RANGE(0x1000, 0x1fff) AM_READ(MRA8_ROM) /* program */
  140. AM_RANGE(0xf800, 0xffff) AM_READ(MRA8_ROM) /* program mirror */
  141. ADDRESS_MAP_END
  142. static ADDRESS_MAP_START( dragrace_writemem, ADDRESS_SPACE_PROGRAM, 8 )
  143. AM_RANGE(0x0080, 0x00ff) AM_WRITE(MWA8_RAM)
  144. AM_RANGE(0x0900, 0x091f) AM_WRITE(dragrace_misc_w)
  145. AM_RANGE(0x0920, 0x093f) AM_WRITE(dragrace_misc_clear_w)
  146. AM_RANGE(0x0a00, 0x0aff) AM_WRITE(MWA8_RAM) AM_BASE(&dragrace_playfield_ram)
  147. AM_RANGE(0x0b00, 0x0bff) AM_WRITE(MWA8_RAM) AM_BASE(&dragrace_position_ram)
  148. AM_RANGE(0x0e00, 0x0eff) AM_WRITE(watchdog_reset_w)
  149. AM_RANGE(0x1000, 0x1fff) AM_WRITE(MWA8_ROM) /* program */
  150. AM_RANGE(0xf800, 0xffff) AM_WRITE(MWA8_ROM) /* program mirror */
  151. ADDRESS_MAP_END
  152. INPUT_PORTS_START( dragrace )
  153. PORT_START /* IN0 */
  154. PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_NAME("Player 1 Gas") PORT_PLAYER(1)
  155. PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_UNUSED ) /* player 1 gear 1 */
  156. PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNUSED ) /* player 1 gear 2 */
  157. PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNUSED ) /* player 1 gear 3 */
  158. PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_UNUSED ) /* player 1 gear 4 */
  159. PORT_SERVICE( 0x20, IP_ACTIVE_LOW )
  160. PORT_DIPNAME( 0xc0, 0x80, "Extended Play" )
  161. PORT_DIPSETTING( 0x00, "6.9 seconds" )
  162. PORT_DIPSETTING( 0x80, "5.9 seconds" )
  163. PORT_DIPSETTING( 0x40, "4.9 seconds" )
  164. PORT_DIPSETTING( 0xc0, "Never" )
  165. PORT_START /* IN1 */
  166. PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_NAME("Player 2 Gas") PORT_PLAYER(2)
  167. PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_UNUSED ) /* player 2 gear 1 */
  168. PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNUSED ) /* player 2 gear 2 */
  169. PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNUSED ) /* player 2 gear 3 */
  170. PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_UNUSED ) /* player 2 gear 4 */
  171. PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNUSED )
  172. PORT_DIPNAME( 0xc0, 0x80, "Number Of Heats" )
  173. PORT_DIPSETTING( 0xc0, "3" )
  174. PORT_DIPSETTING( 0x80, "4" )
  175. PORT_DIPSETTING( 0x00, "5" )
  176. PORT_START /* IN2 */
  177. PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_UNUSED ) /* IN0 connects here */
  178. PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_UNUSED ) /* IN1 connects here */
  179. PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_COIN1 )
  180. PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_COIN2 )
  181. PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_START1 )
  182. PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_START2 )
  183. PORT_DIPNAME( 0xc0, 0x40, DEF_STR( Coinage ) )
  184. PORT_DIPSETTING( 0xc0, DEF_STR( 2C_1C ) )
  185. PORT_DIPSETTING( 0x40, DEF_STR( 1C_1C ) )
  186. PORT_DIPSETTING( 0x80, DEF_STR( 1C_2C ) )
  187. PORT_DIPSETTING( 0x00, DEF_STR( Free_Play ) )
  188. PORT_START /* IN3 */
  189. PORT_BIT( 0xff, 0x00, IPT_DIAL_V ) PORT_SENSITIVITY(25) PORT_KEYDELTA(10) PORT_PLAYER(1)
  190. PORT_START /* IN4 */
  191. PORT_BIT( 0xff, 0x00, IPT_DIAL_V ) PORT_SENSITIVITY(25) PORT_KEYDELTA(10) PORT_PLAYER(2)
  192. PORT_START /* IN5 */
  193. PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_NAME("Player 1 Gear 1") PORT_PLAYER(1)
  194. PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_BUTTON3 ) PORT_NAME("Player 1 Gear 2") PORT_PLAYER(1)
  195. PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_BUTTON4 ) PORT_NAME("Player 1 Gear 3") PORT_PLAYER(1)
  196. PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_BUTTON5 ) PORT_NAME("Player 1 Gear 4") PORT_PLAYER(1)
  197. PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_BUTTON6 ) PORT_NAME("Player 1 Neutral") PORT_PLAYER(1)
  198. PORT_START /* IN6 */
  199. PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_NAME("Player 2 Gear 1") PORT_PLAYER(2)
  200. PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_BUTTON3 ) PORT_NAME("Player 2 Gear 2") PORT_PLAYER(2)
  201. PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_BUTTON4 ) PORT_NAME("Player 2 Gear 3") PORT_PLAYER(2)
  202. PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_BUTTON5 ) PORT_NAME("Player 2 Gear 4") PORT_PLAYER(2)
  203. PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_BUTTON6 ) PORT_NAME("Player 2 Neutral") PORT_PLAYER(2)
  204. PORT_START
  205. PORT_ADJUSTER( 81, "Motor 1 RPM" )
  206. PORT_START
  207. PORT_ADJUSTER( 85, "Motor 2 RPM" )
  208. INPUT_PORTS_END
  209. static const gfx_layout dragrace_tile_layout1 =
  210. {
  211. 16, 16, /* width, height */
  212. 0x40, /* total */
  213. 1, /* planes */
  214. { 0 }, /* plane offsets */
  215. {
  216. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  217. 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87
  218. },
  219. {
  220. 0x00, 0x08, 0x10, 0x18, 0x20, 0x28, 0x30, 0x38,
  221. 0x40, 0x48, 0x50, 0x58, 0x60, 0x68, 0x70, 0x78
  222. },
  223. 0x100 /* increment */
  224. };
  225. static const gfx_layout dragrace_tile_layout2 =
  226. {
  227. 16, 16, /* width, height */
  228. 0x20, /* total */
  229. 2, /* planes */
  230. { /* plane offsets */
  231. 0x0000, 0x2000
  232. },
  233. {
  234. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  235. 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87
  236. },
  237. {
  238. 0x00, 0x08, 0x10, 0x18, 0x20, 0x28, 0x30, 0x38,
  239. 0x40, 0x48, 0x50, 0x58, 0x60, 0x68, 0x70, 0x78
  240. },
  241. 0x100 /* increment */
  242. };
  243. static const gfx_decode dragrace_gfx_decode_info[] =
  244. {
  245. { REGION_GFX1, 0, &dragrace_tile_layout1, 0, 4 },
  246. { REGION_GFX2, 0, &dragrace_tile_layout2, 8, 2 },
  247. { -1 } /* end of array */
  248. };
  249. static PALETTE_INIT( dragrace )
  250. {
  251. palette_set_color(0, 0xFF, 0xFF, 0xFF); /* 2 color tiles */
  252. palette_set_color(1, 0x00, 0x00, 0x00);
  253. palette_set_color(2, 0x00, 0x00, 0x00);
  254. palette_set_color(3, 0xFF, 0xFF, 0xFF);
  255. palette_set_color(4, 0x00, 0x00, 0x00);
  256. palette_set_color(5, 0x00, 0x00, 0x00);
  257. palette_set_color(6, 0xFF, 0xFF, 0xFF);
  258. palette_set_color(7, 0xFF, 0xFF, 0xFF);
  259. palette_set_color(8, 0xFF, 0xFF, 0xFF); /* 4 color tiles */
  260. palette_set_color(9, 0xB0, 0xB0, 0xB0);
  261. palette_set_color(10,0x5F, 0x5F, 0x5F);
  262. palette_set_color(11,0x00, 0x00, 0x00);
  263. palette_set_color(12,0xFF, 0xFF, 0xFF);
  264. palette_set_color(13,0x5F, 0x5F, 0x5F);
  265. palette_set_color(14,0xB0, 0xB0, 0xB0);
  266. palette_set_color(15,0x00, 0x00, 0x00);
  267. }
  268. static MACHINE_DRIVER_START( dragrace )
  269. /* basic machine hardware */
  270. MDRV_CPU_ADD(M6800, 12096000 / 12)
  271. MDRV_CPU_PROGRAM_MAP(dragrace_readmem, dragrace_writemem)
  272. MDRV_CPU_VBLANK_INT(irq0_line_hold, 4)
  273. MDRV_WATCHDOG_VBLANK_INIT(8)
  274. MDRV_FRAMES_PER_SECOND(60)
  275. MDRV_VBLANK_DURATION((int) ((22. * 1000000) / (262. * 60) + 0.5))
  276. MDRV_MACHINE_RESET(dragrace)
  277. /* video hardware */
  278. MDRV_VIDEO_ATTRIBUTES(VIDEO_TYPE_RASTER)
  279. MDRV_SCREEN_SIZE(256, 240)
  280. MDRV_VISIBLE_AREA(0, 255, 0, 239)
  281. MDRV_GFXDECODE(dragrace_gfx_decode_info)
  282. MDRV_PALETTE_LENGTH(16)
  283. MDRV_PALETTE_INIT(dragrace)
  284. MDRV_VIDEO_START(dragrace)
  285. MDRV_VIDEO_UPDATE(dragrace)
  286. /* sound hardware */
  287. MDRV_SPEAKER_STANDARD_STEREO("left", "right")
  288. MDRV_SOUND_ADD_TAG("discrete", DISCRETE, 0)
  289. MDRV_SOUND_CONFIG(dragrace_discrete_interface)
  290. MDRV_SOUND_ROUTE(0, "left", 1.0)
  291. MDRV_SOUND_ROUTE(1, "right", 1.0)
  292. MACHINE_DRIVER_END
  293. ROM_START( dragrace )
  294. ROM_REGION( 0x10000, REGION_CPU1, 0 )
  295. ROM_LOAD( "8513.c1", 0x1000, 0x0800, CRC(543bbb30) SHA1(646a41d1124c8365f07a93de38af007895d7d263) )
  296. ROM_LOAD( "8514.a1", 0x1800, 0x0800, CRC(ad218690) SHA1(08ba5f4fa4c75d8dad1a7162888d44b3349cbbe4) )
  297. ROM_RELOAD( 0xF800, 0x0800 )
  298. ROM_REGION( 0x800, REGION_GFX1, ROMREGION_DISPOSE ) /* 2 color tiles */
  299. ROM_LOAD( "8519dr.j0", 0x000, 0x200, CRC(aa221ba0) SHA1(450acbf349d77a790a25f3e303c31b38cc426a38) )
  300. ROM_LOAD( "8521dr.k0", 0x200, 0x200, CRC(0cb33f12) SHA1(d50cb55391aec03e064eecad1624d50d4c30ccab) )
  301. ROM_LOAD( "8520dr.r0", 0x400, 0x200, CRC(ee1ae6a7) SHA1(83491095260c8b7c616ff17ec1e888d05620f166) )
  302. ROM_REGION( 0x800, REGION_GFX2, ROMREGION_DISPOSE ) /* 4 color tiles */
  303. ROM_LOAD( "8515dr.e0", 0x000, 0x200, CRC(9510a59e) SHA1(aea0782b919279efe55a07007bd55a16f7f59239) )
  304. ROM_LOAD( "8517dr.h0", 0x200, 0x200, CRC(8b5bff1f) SHA1(fdcd719c66bff7c4b9f3d56d1e635259dd8add61) )
  305. ROM_LOAD( "8516dr.l0", 0x400, 0x200, CRC(d1e74af1) SHA1(f55a3bfd7d152ac9af128697f55c9a0c417779f5) )
  306. ROM_LOAD( "8518dr.n0", 0x600, 0x200, CRC(b1369028) SHA1(598a8779982d532c9f34345e793a79fcb29cac62) )
  307. ROM_END
  308. GAME( 1977, dragrace, 0, dragrace, dragrace, 0, 0, "Atari", "Drag Race", 0 )