src/mess/drivers/snes.c
| r7533 | r7534 | |
| 33 | 33 | #include "cpu/g65816/g65816.h" |
| 34 | 34 | #include "includes/snes.h" |
| 35 | 35 | #include "machine/snescart.h" |
| 36 | #include "crsshair.h" |
| 36 | 37 | |
| 37 | 38 | #define MAX_SNES_CART_SIZE 0x600000 |
| 38 | 39 | |
| r7533 | r7534 | |
| 109 | 110 | return state->mouse[port].speed; |
| 110 | 111 | } |
| 111 | 112 | |
| 112 | | static INPUT_PORTS_START( snes ) |
| 113 | | PORT_START("CTRLSEL") /* Select Controller Type */ |
| 114 | | PORT_CATEGORY_CLASS( 0x0f, 0x01, "P1 Controller") |
| 115 | | PORT_CATEGORY_ITEM( 0x00, "Unconnected", 10 ) |
| 116 | | PORT_CATEGORY_ITEM( 0x01, "Gamepad", 11 ) |
| 117 | | PORT_CATEGORY_ITEM( 0x02, "Mouse", 12 ) |
| 118 | | // PORT_CATEGORY_ITEM( 0x03, "Superscope", 13 ) |
| 119 | | // PORT_CATEGORY_ITEM( 0x04, "Justfier", 14 ) |
| 120 | | // PORT_CATEGORY_ITEM( 0x05, "Multitap", 15 ) |
| 121 | | PORT_CATEGORY_CLASS( 0xf0, 0x10, "P2 Controller") |
| 122 | | PORT_CATEGORY_ITEM( 0x00, "Unconnected", 20 ) |
| 123 | | PORT_CATEGORY_ITEM( 0x10, "Gamepad", 21 ) |
| 124 | | PORT_CATEGORY_ITEM( 0x20, "Mouse", 22 ) |
| 125 | | // PORT_CATEGORY_ITEM( 0x30, "Superscope", 23 ) |
| 126 | | // PORT_CATEGORY_ITEM( 0x40, "Justfier", 24 ) |
| 127 | | // PORT_CATEGORY_ITEM( 0x50, "Multitap", 25 ) |
| 113 | static CUSTOM_INPUT( snes_superscope_offscreen_input ) |
| 114 | { |
| 115 | snes_state *state = (snes_state *)field->port->machine->driver_data; |
| 116 | int port = (FPTR)param; |
| 117 | static const char *const portnames[2][3] = |
| 118 | { |
| 119 | { "SUPERSCOPE1", "SUPERSCOPE1_X", "SUPERSCOPE1_Y" }, |
| 120 | { "SUPERSCOPE2", "SUPERSCOPE2_X", "SUPERSCOPE2_Y" }, |
| 121 | }; |
| 128 | 122 | |
| 123 | UINT16 x = input_port_read(field->port->machine, portnames[port][1]); |
| 124 | UINT16 y = input_port_read(field->port->machine, portnames[port][2]); |
| 125 | |
| 126 | /* these are the theoretical boundaries */ |
| 127 | if (x < 0 || x >= SNES_SCR_WIDTH || y < 0 || y >= snes_ppu.beam.last_visible_line) |
| 128 | state->scope[port].offscreen = 1; |
| 129 | else |
| 130 | state->scope[port].offscreen = 0; |
| 131 | |
| 132 | return state->scope[port].offscreen; |
| 133 | } |
| 134 | |
| 135 | static TIMER_CALLBACK( lightgun_tick ) |
| 136 | { |
| 137 | if ((input_port_read(machine, "CTRLSEL") & 0x0f) == 0x03 || (input_port_read(machine, "CTRLSEL") & 0x0f) == 0x04) |
| 138 | { |
| 139 | /* enable lightpen crosshair */ |
| 140 | crosshair_set_screen(machine, 0, CROSSHAIR_SCREEN_ALL); |
| 141 | } |
| 142 | else |
| 143 | { |
| 144 | /* disable lightpen crosshair */ |
| 145 | crosshair_set_screen(machine, 0, CROSSHAIR_SCREEN_NONE); |
| 146 | } |
| 147 | |
| 148 | if ((input_port_read(machine, "CTRLSEL") & 0xf0) == 0x30 || (input_port_read(machine, "CTRLSEL") & 0xf0) == 0x40) |
| 149 | { |
| 150 | /* enable lightpen crosshair */ |
| 151 | crosshair_set_screen(machine, 1, CROSSHAIR_SCREEN_ALL); |
| 152 | } |
| 153 | else |
| 154 | { |
| 155 | /* disable lightpen crosshair */ |
| 156 | crosshair_set_screen(machine, 1, CROSSHAIR_SCREEN_NONE); |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | |
| 161 | static INPUT_PORTS_START( snes_joypads ) |
| 129 | 162 | PORT_START("SERIAL1_DATA1_L") |
| 130 | 163 | PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_BUTTON3 ) PORT_NAME("P1 Button A") PORT_PLAYER(1) PORT_CATEGORY(11) |
| 131 | 164 | PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON4 ) PORT_NAME("P1 Button X") PORT_PLAYER(1) PORT_CATEGORY(11) |
| r7533 | r7534 | |
| 165 | 198 | PORT_BIT( 0xff, IP_ACTIVE_HIGH, IPT_UNUSED ) |
| 166 | 199 | PORT_START("SERIAL2_DATA2_H") |
| 167 | 200 | PORT_BIT( 0xff, IP_ACTIVE_HIGH, IPT_UNUSED ) |
| 201 | INPUT_PORTS_END |
| 168 | 202 | |
| 203 | static INPUT_PORTS_START( snes_mouse ) |
| 169 | 204 | PORT_START("MOUSE1") |
| 170 | 205 | /* bits 0,3 = mouse signature (must be 1) */ |
| 171 | 206 | PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_UNUSED ) |
| r7533 | r7534 | |
| 201 | 236 | |
| 202 | 237 | PORT_START("MOUSE2_Y") |
| 203 | 238 | PORT_BIT( 0xff, 0x00, IPT_TRACKBALL_Y) PORT_SENSITIVITY(100) PORT_KEYDELTA(0) PORT_PLAYER(2) PORT_CATEGORY(22) |
| 239 | INPUT_PORTS_END |
| 204 | 240 | |
| 241 | static INPUT_PORTS_START( snes_superscope ) |
| 242 | PORT_START("SUPERSCOPE1") |
| 243 | PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_UNUSED ) // Noise |
| 244 | PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(snes_superscope_offscreen_input, (void *)0) |
| 245 | PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_UNUSED ) |
| 246 | PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_UNUSED ) |
| 247 | PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_BUTTON4 ) PORT_NAME("Port1 Superscope Pause") PORT_PLAYER(1) PORT_CATEGORY(13) |
| 248 | PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_BUTTON3 ) PORT_NAME("Port1 Superscope Turbo") PORT_TOGGLE PORT_PLAYER(1) PORT_CATEGORY(13) |
| 249 | PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_NAME("Port1 Superscope Cursor") PORT_PLAYER(1) PORT_CATEGORY(13) |
| 250 | PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_NAME("Port1 Superscope Fire") PORT_PLAYER(1) PORT_CATEGORY(13) |
| 251 | |
| 252 | PORT_START("SUPERSCOPE1_X") |
| 253 | PORT_BIT( 0xff, 0x80, IPT_LIGHTGUN_X ) PORT_NAME("Port1 Superscope X Axis") PORT_CROSSHAIR(X, 1.0, 0.0, 0) PORT_SENSITIVITY(25) PORT_KEYDELTA(15) PORT_PLAYER(1) PORT_CATEGORY(13) |
| 254 | |
| 255 | PORT_START("SUPERSCOPE1_Y") |
| 256 | PORT_BIT( 0xff, 0x80, IPT_LIGHTGUN_Y) PORT_NAME("Port1 Superscope Y Axis") PORT_CROSSHAIR(Y, 1.0, 0.0, 0) PORT_SENSITIVITY(25) PORT_KEYDELTA(15) PORT_PLAYER(1) PORT_CATEGORY(13) |
| 257 | |
| 258 | PORT_START("SUPERSCOPE2") |
| 259 | PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_UNUSED ) // Noise |
| 260 | PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_CUSTOM(snes_superscope_offscreen_input, (void *)1) |
| 261 | PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_UNUSED ) |
| 262 | PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_UNUSED ) |
| 263 | PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_BUTTON4 ) PORT_NAME("Port2 Superscope Pause") PORT_PLAYER(2) PORT_CATEGORY(23) |
| 264 | PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_BUTTON3 ) PORT_NAME("Port2 Superscope Turbo") PORT_PLAYER(2) PORT_CATEGORY(23) |
| 265 | PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_NAME("Port2 Superscope Cursor") PORT_PLAYER(2) PORT_CATEGORY(23) |
| 266 | PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_NAME("Port2 Superscope Fire") PORT_PLAYER(2) PORT_CATEGORY(23) |
| 267 | |
| 268 | PORT_START("SUPERSCOPE2_X") |
| 269 | PORT_BIT( 0xff, 0x80, IPT_LIGHTGUN_X ) PORT_NAME("Port2 Superscope X Axis") PORT_CROSSHAIR(X, 1.0, 0.0, 0) PORT_SENSITIVITY(25) PORT_KEYDELTA(15) PORT_PLAYER(2) PORT_CATEGORY(23) |
| 270 | |
| 271 | PORT_START("SUPERSCOPE2_Y") |
| 272 | PORT_BIT( 0xff, 0x80, IPT_LIGHTGUN_Y) PORT_NAME("Port2 Superscope Y Axis") PORT_CROSSHAIR(Y, 1.0, 0.0, 0) PORT_SENSITIVITY(25) PORT_KEYDELTA(15) PORT_PLAYER(2) PORT_CATEGORY(23) |
| 273 | INPUT_PORTS_END |
| 274 | |
| 275 | static INPUT_PORTS_START( snes ) |
| 276 | PORT_START("CTRLSEL") /* Select Controller Type */ |
| 277 | PORT_CATEGORY_CLASS( 0x0f, 0x01, "P1 Controller") |
| 278 | PORT_CATEGORY_ITEM( 0x00, "Unconnected", 10 ) |
| 279 | PORT_CATEGORY_ITEM( 0x01, "Gamepad", 11 ) |
| 280 | PORT_CATEGORY_ITEM( 0x02, "Mouse", 12 ) |
| 281 | PORT_CATEGORY_ITEM( 0x03, "Superscope", 13 ) |
| 282 | // PORT_CATEGORY_ITEM( 0x04, "Justfier", 14 ) |
| 283 | // PORT_CATEGORY_ITEM( 0x05, "Multitap", 15 ) |
| 284 | PORT_CATEGORY_CLASS( 0xf0, 0x10, "P2 Controller") |
| 285 | PORT_CATEGORY_ITEM( 0x00, "Unconnected", 20 ) |
| 286 | PORT_CATEGORY_ITEM( 0x10, "Gamepad", 21 ) |
| 287 | PORT_CATEGORY_ITEM( 0x20, "Mouse", 22 ) |
| 288 | PORT_CATEGORY_ITEM( 0x30, "Superscope", 23 ) |
| 289 | // PORT_CATEGORY_ITEM( 0x40, "Justfier", 24 ) |
| 290 | // PORT_CATEGORY_ITEM( 0x50, "Multitap", 25 ) |
| 291 | |
| 292 | PORT_INCLUDE(snes_joypads) |
| 293 | PORT_INCLUDE(snes_mouse) |
| 294 | PORT_INCLUDE(snes_superscope) |
| 295 | |
| 296 | |
| 205 | 297 | #ifdef SNES_LAYER_DEBUG |
| 206 | 298 | PORT_START("INTERNAL") |
| 207 | 299 | PORT_CONFNAME( 0x1, 0x1, "Enforce 32 sprites/line" ) |
| r7533 | r7534 | |
| 254 | 346 | * |
| 255 | 347 | *************************************/ |
| 256 | 348 | |
| 349 | static void snes_gun_latch( running_machine *machine, INT16 x, INT16 y ) |
| 350 | { |
| 351 | /* these are the theoretical boundaries */ |
| 352 | if (x < 0) |
| 353 | x = 0; |
| 354 | if (x > (SNES_SCR_WIDTH - 1)) |
| 355 | x = SNES_SCR_WIDTH - 1; |
| 356 | |
| 357 | if (y < 0) |
| 358 | y = 0; |
| 359 | if (y > (snes_ppu.beam.last_visible_line - 1)) |
| 360 | y = snes_ppu.beam.last_visible_line - 1; |
| 361 | |
| 362 | snes_ppu.beam.latch_horz = x; |
| 363 | snes_ppu.beam.latch_vert = y; |
| 364 | snes_ram[STAT78] |= 0x40; |
| 365 | } |
| 366 | |
| 257 | 367 | static void snes_input_read_joy( running_machine *machine, int port ) |
| 258 | 368 | { |
| 259 | 369 | snes_state *state = (snes_state *)machine->driver_data; |
| r7533 | r7534 | |
| 329 | 439 | } |
| 330 | 440 | } |
| 331 | 441 | |
| 442 | static void snes_input_read_superscope( running_machine *machine, int port ) |
| 443 | { |
| 444 | snes_state *state = (snes_state *)machine->driver_data; |
| 445 | static const char *const portnames[2][3] = |
| 446 | { |
| 447 | { "SUPERSCOPE1", "SUPERSCOPE1_X", "SUPERSCOPE1_Y" }, |
| 448 | { "SUPERSCOPE2", "SUPERSCOPE2_X", "SUPERSCOPE2_Y" }, |
| 449 | }; |
| 450 | UINT8 input; |
| 451 | |
| 452 | /* first read input bits */ |
| 453 | state->scope[port].x = input_port_read(machine, portnames[port][1]); |
| 454 | state->scope[port].y = input_port_read(machine, portnames[port][2]); |
| 455 | input = input_port_read(machine, portnames[port][0]); |
| 456 | |
| 457 | /* then start elaborating input bits: only keep old turbo value */ |
| 458 | state->scope[port].buttons &= 0x20; |
| 459 | |
| 460 | /* set onscreen/offscreen */ |
| 461 | state->scope[port].buttons |= BIT(input, 1); |
| 462 | |
| 463 | /* turbo is a switch; toggle is edge sensitive */ |
| 464 | if (BIT(input, 5) && !state->scope[port].turbo_lock) |
| 465 | { |
| 466 | state->scope[port].buttons ^= 0x20; |
| 467 | state->scope[port].turbo_lock = 1; |
| 468 | } |
| 469 | else if (!BIT(input, 5)) |
| 470 | state->scope[port].turbo_lock = 0; |
| 471 | |
| 472 | /* fire is a button; if turbo is active, trigger is level sensitive; otherwise it is edge sensitive */ |
| 473 | if (BIT(input, 7) && (BIT(state->scope[port].buttons, 5) || !state->scope[port].fire_lock)) |
| 474 | { |
| 475 | state->scope[port].buttons |= 0x80; |
| 476 | state->scope[port].fire_lock = 1; |
| 477 | } |
| 478 | else if (!BIT(input, 7)) |
| 479 | state->scope[port].fire_lock = 0; |
| 480 | |
| 481 | /* cursor is a button; it is always level sensitive */ |
| 482 | state->scope[port].buttons |= BIT(input, 6); |
| 483 | |
| 484 | /* pause is a button; it is always edge sensitive */ |
| 485 | if (BIT(input, 4) && !state->scope[port].pause_lock) |
| 486 | { |
| 487 | state->scope[port].buttons |= 0x10; |
| 488 | state->scope[port].pause_lock = 1; |
| 489 | } |
| 490 | else if (!BIT(input, 4)) |
| 491 | state->scope[port].pause_lock = 0; |
| 492 | |
| 493 | /* If we have pressed fire or cursor and we are on-screen and SuperScope is in Port2, then latch video signal. |
| 494 | Notice that we only latch Port2 because its IOBit pin is connected to bit7 of the IO Port, while Port1 has |
| 495 | IOBit pin connected to bit6 of the IO Port, and the latter is not detected by the H/V Counters. In other |
| 496 | words, you can connect SuperScope to Port1, but there is no way SNES could detect its on-screen position */ |
| 497 | if ((state->scope[port].buttons & 0xc0) && !(state->scope[port].buttons & 0x02) && port == 1) |
| 498 | snes_gun_latch(machine, state->scope[port].x, state->scope[port].y); |
| 499 | } |
| 500 | |
| 332 | 501 | static void snes_input_read( running_machine *machine ) |
| 333 | 502 | { |
| 334 | 503 | snes_state *state = (snes_state *)machine->driver_data; |
| r7533 | r7534 | |
| 336 | 505 | UINT8 ctrl2 = (input_port_read(machine, "CTRLSEL") & 0xf0) >> 4; |
| 337 | 506 | int i; |
| 338 | 507 | |
| 508 | /* Check if lightgun has been chosen as input: if so, enable crosshair */ |
| 509 | timer_set(machine, attotime_zero, NULL, 0, lightgun_tick); |
| 510 | |
| 339 | 511 | switch (ctrl1) |
| 340 | 512 | { |
| 341 | | case 1: /* joystick */ |
| 513 | case 1: /* SNES joypad */ |
| 342 | 514 | snes_input_read_joy(machine, 0); |
| 343 | 515 | break; |
| 344 | 516 | case 2: /* SNES Mouse */ |
| 345 | 517 | snes_input_read_mouse(machine, 0); |
| 346 | 518 | break; |
| 519 | case 3: /* SNES Superscope */ |
| 520 | snes_input_read_superscope(machine, 0); |
| 521 | break; |
| 347 | 522 | case 0: /* no controller in port1 */ |
| 348 | 523 | default: |
| 349 | 524 | break; |
| r7533 | r7534 | |
| 351 | 526 | |
| 352 | 527 | switch (ctrl2) |
| 353 | 528 | { |
| 354 | | case 1: /* joystick */ |
| 529 | case 1: /* SNES joypad */ |
| 355 | 530 | snes_input_read_joy(machine, 1); |
| 356 | 531 | break; |
| 357 | 532 | case 2: /* SNES Mouse */ |
| 358 | 533 | snes_input_read_mouse(machine, 1); |
| 359 | 534 | break; |
| 535 | case 3: /* SNES Superscope */ |
| 536 | snes_input_read_superscope(machine, 1); |
| 537 | break; |
| 360 | 538 | case 0: /* no controller in port2 */ |
| 361 | 539 | default: |
| 362 | 540 | break; |
| r7533 | r7534 | |
| 378 | 556 | { |
| 379 | 557 | switch (ctrl1) |
| 380 | 558 | { |
| 381 | | case 1: /* joystick */ |
| 559 | case 1: /* SNES joypad */ |
| 382 | 560 | state->joy1l = state->joypad[0].low; |
| 383 | 561 | state->joy1h = state->joypad[0].high; |
| 384 | 562 | state->joy3l = state->joypad[2].low; |
| r7533 | r7534 | |
| 390 | 568 | state->joy3l = 0; |
| 391 | 569 | state->joy3h = 0; |
| 392 | 570 | break; |
| 571 | case 3: /* SNES Superscope */ |
| 572 | state->joy1l = 0xff; |
| 573 | state->joy1h = state->scope[0].buttons; |
| 574 | state->joy3l = 0; |
| 575 | state->joy3h = 0; |
| 576 | break; |
| 393 | 577 | case 0: /* no controller in port2 */ |
| 394 | 578 | default: |
| 395 | 579 | state->joy1l = 0; |
| r7533 | r7534 | |
| 401 | 585 | |
| 402 | 586 | switch (ctrl2) |
| 403 | 587 | { |
| 404 | | case 1: /* joystick */ |
| 588 | case 1: /* SNES joypad */ |
| 405 | 589 | state->joy2l = state->joypad[1].low; |
| 406 | 590 | state->joy2h = state->joypad[1].high; |
| 407 | 591 | state->joy4l = state->joypad[3].low; |
| r7533 | r7534 | |
| 413 | 597 | state->joy4l = 0; |
| 414 | 598 | state->joy4h = 0; |
| 415 | 599 | break; |
| 600 | case 3: /* SNES Superscope */ |
| 601 | state->joy2l = 0xff; |
| 602 | state->joy2h = state->scope[1].buttons; |
| 603 | state->joy4l = 0; |
| 604 | state->joy4h = 0; |
| 605 | break; |
| 416 | 606 | case 0: /* no controller in port2 */ |
| 417 | 607 | default: |
| 418 | 608 | state->joy2l = 0; |
| r7533 | r7534 | |
| 422 | 612 | break; |
| 423 | 613 | } |
| 424 | 614 | |
| 425 | | // make sure oldrol starts returning all 1s because the auto-read reads it :-) |
| 615 | // make sure read_idx starts returning all 1s because the auto-read reads it :-) |
| 426 | 616 | state->read_idx[0] = 16; |
| 427 | 617 | state->read_idx[1] = 16; |
| 428 | 618 | } |
| r7533 | r7534 | |
| 437 | 627 | |
| 438 | 628 | switch (ctrl1) |
| 439 | 629 | { |
| 440 | | case 1: /* joystick */ |
| 630 | case 1: /* SNES joypad */ |
| 441 | 631 | if (state->read_idx[0] >= 16) |
| 442 | 632 | res = 0x01; |
| 443 | 633 | else |
| r7533 | r7534 | |
| 455 | 645 | else |
| 456 | 646 | res = 0; |
| 457 | 647 | break; |
| 648 | case 3: /* SNES Superscope */ |
| 649 | if (state->read_idx[0] >= 8) |
| 650 | res = 0x01; |
| 651 | else |
| 652 | res = (state->scope[0].buttons >> (7 - state->read_idx[0]++)) & 0x01; |
| 653 | break; |
| 458 | 654 | case 0: /* no controller in port2 */ |
| 459 | 655 | default: |
| 460 | 656 | break; |
| r7533 | r7534 | |
| 471 | 667 | |
| 472 | 668 | switch (ctrl2) |
| 473 | 669 | { |
| 474 | | case 1: /* joystick */ |
| 670 | case 1: /* SNES joypad */ |
| 475 | 671 | if (state->read_idx[1] >= 16) |
| 476 | 672 | res = 0x01; |
| 477 | 673 | else |
| r7533 | r7534 | |
| 489 | 685 | else |
| 490 | 686 | res = 0; |
| 491 | 687 | break; |
| 688 | case 3: /* SNES Superscope */ |
| 689 | if (state->read_idx[1] >= 8) |
| 690 | res = 0x01; |
| 691 | else |
| 692 | res = (state->scope[1].buttons >> (7 - state->read_idx[1]++)) & 0x01; |
| 693 | break; |
| 492 | 694 | case 0: /* no controller in port2 */ |
| 493 | 695 | default: |
| 494 | 696 | break; |