src/mame/machine/snes.c
| r7543 | r7544 | |
| 1938 | 1938 | static void nss_io_read( running_machine *machine ) |
| 1939 | 1939 | { |
| 1940 | 1940 | snes_state *state = (snes_state *)machine->driver_data; |
| 1941 | | int i; |
| 1941 | static const char *const portnames[2][4] = |
| 1942 | { |
| 1943 | { "SERIAL1_DATA1_L", "SERIAL1_DATA1_H", "SERIAL1_DATA2_L", "SERIAL1_DATA2_H" }, |
| 1944 | { "SERIAL2_DATA1_L", "SERIAL2_DATA1_H", "SERIAL2_DATA2_L", "SERIAL2_DATA2_H" }, |
| 1945 | }; |
| 1946 | int port; |
| 1942 | 1947 | |
| 1943 | | state->joypad[0].low = input_port_read(machine, "SERIAL1_DATA1_L"); |
| 1944 | | state->joypad[0].high = input_port_read(machine, "SERIAL1_DATA1_H"); |
| 1945 | | state->joypad[1].low = input_port_read(machine, "SERIAL2_DATA1_L"); |
| 1946 | | state->joypad[1].high = input_port_read(machine, "SERIAL2_DATA1_H"); |
| 1947 | | state->joypad[2].low = input_port_read(machine, "SERIAL1_DATA2_L"); |
| 1948 | | state->joypad[2].high = input_port_read(machine, "SERIAL1_DATA2_H"); |
| 1949 | | state->joypad[3].low = input_port_read(machine, "SERIAL2_DATA2_L"); |
| 1950 | | state->joypad[3].high = input_port_read(machine, "SERIAL2_DATA2_H"); |
| 1948 | for (port = 0; port < 2; port++) |
| 1949 | { |
| 1950 | state->data1[port] = input_port_read(machine, portnames[port][0]) | (input_port_read(machine, portnames[port][1]) << 8); |
| 1951 | state->data2[port] = input_port_read(machine, portnames[port][2]) | (input_port_read(machine, portnames[port][3]) << 8); |
| 1951 | 1952 | |
| 1952 | | // avoid sending signals that could crash games |
| 1953 | | for (i = 0; i < 4; i++) |
| 1954 | | { |
| 1953 | // avoid sending signals that could crash games |
| 1955 | 1954 | // if left, no right |
| 1956 | | if (state->joypad[i].high & 2) |
| 1957 | | state->joypad[i].high &= ~1; |
| 1955 | if (state->data1[port] & 0x200) |
| 1956 | state->data1[port] &= ~0x100; |
| 1958 | 1957 | // if up, no down |
| 1959 | | if (state->joypad[i].high & 8) |
| 1960 | | state->joypad[i].high &= ~4; |
| 1958 | if (state->data1[port] & 0x800) |
| 1959 | state->data1[port] &= ~0x400; |
| 1960 | |
| 1961 | state->joypad[port].buttons = state->data1[port]; |
| 1961 | 1962 | } |
| 1962 | 1963 | |
| 1963 | | // is automatic reading on? |
| 1964 | // is automatic reading on? if so, copy port data1/data2 to joy1l->joy4h |
| 1965 | // this actually works like reading the first 16bits from oldjoy1/2 in reverse order |
| 1964 | 1966 | if (snes_ram[NMITIMEN] & 1) |
| 1965 | 1967 | { |
| 1966 | | state->joy1l = state->joypad[0].low; |
| 1967 | | state->joy1h = state->joypad[0].high; |
| 1968 | | state->joy2l = state->joypad[1].low; |
| 1969 | | state->joy2h = state->joypad[1].high; |
| 1970 | | state->joy3l = state->joypad[2].low; |
| 1971 | | state->joy3h = state->joypad[2].high; |
| 1972 | | state->joy4l = state->joypad[3].low; |
| 1973 | | state->joy4h = state->joypad[3].high; |
| 1968 | state->joy1l = (state->data1[0] & 0x00ff) >> 0; |
| 1969 | state->joy1h = (state->data1[0] & 0xff00) >> 8; |
| 1970 | state->joy2l = (state->data1[1] & 0x00ff) >> 0; |
| 1971 | state->joy2h = (state->data1[1] & 0xff00) >> 8; |
| 1972 | state->joy3l = (state->data2[0] & 0x00ff) >> 0; |
| 1973 | state->joy3h = (state->data2[0] & 0xff00) >> 8; |
| 1974 | state->joy4l = (state->data2[1] & 0x00ff) >> 0; |
| 1975 | state->joy4h = (state->data2[1] & 0xff00) >> 8; |
| 1974 | 1976 | |
| 1975 | 1977 | // make sure read_idx starts returning all 1s because the auto-read reads it :-) |
| 1976 | 1978 | state->read_idx[0] = 16; |
| r7543 | r7544 | |
| 1984 | 1986 | snes_state *state = (snes_state *)machine->driver_data; |
| 1985 | 1987 | UINT8 res; |
| 1986 | 1988 | |
| 1987 | | // joysticks |
| 1988 | 1989 | if (state->read_idx[0] >= 16) |
| 1989 | 1990 | res = 0x01; |
| 1990 | 1991 | else |
| 1991 | | res = ((state->joypad[0].low | (state->joypad[0].high << 8)) >> (15 - state->read_idx[0]++)) & 0x01; |
| 1992 | res = (state->joypad[0].buttons >> (15 - state->read_idx[0]++)) & 0x01; |
| 1992 | 1993 | |
| 1993 | 1994 | return res; |
| 1994 | 1995 | } |
| r7543 | r7544 | |
| 2001 | 2002 | if (state->read_idx[1] >= 16) |
| 2002 | 2003 | res = 0x01; |
| 2003 | 2004 | else |
| 2004 | | res = ((state->joypad[1].low | (state->joypad[1].high << 8)) >> (15 - state->read_idx[1]++)) & 0x01; |
| 2005 | res = (state->joypad[1].buttons >> (15 - state->read_idx[1]++)) & 0x01; |
| 2005 | 2006 | |
| 2006 | 2007 | return res; |
| 2007 | 2008 | } |
src/mess/drivers/snes.c
| r7543 | r7544 | |
| 373 | 373 | { "SERIAL2_DATA1_L", "SERIAL2_DATA1_H", "SERIAL2_DATA2_L", "SERIAL2_DATA2_H" }, |
| 374 | 374 | }; |
| 375 | 375 | |
| 376 | | state->joypad[port + 0].low = input_port_read(machine, portnames[port][0]); |
| 377 | | state->joypad[port + 0].high = input_port_read(machine, portnames[port][1]); |
| 378 | | state->joypad[port + 2].low = input_port_read(machine, portnames[port][2]); |
| 379 | | state->joypad[port + 2].high = input_port_read(machine, portnames[port][3]); |
| 376 | state->data1[port] = input_port_read(machine, portnames[port][0]) | (input_port_read(machine, portnames[port][1]) << 8); |
| 377 | state->data2[port] = input_port_read(machine, portnames[port][2]) | (input_port_read(machine, portnames[port][3]) << 8); |
| 378 | |
| 379 | // avoid sending signals that could crash games |
| 380 | // if left, no right |
| 381 | if (state->data1[port] & 0x200) |
| 382 | state->data1[port] &= ~0x100; |
| 383 | // if up, no down |
| 384 | if (state->data1[port] & 0x800) |
| 385 | state->data1[port] &= ~0x400; |
| 386 | |
| 387 | state->joypad[port].buttons = state->data1[port]; |
| 380 | 388 | } |
| 381 | 389 | |
| 382 | 390 | static void snes_input_read_mouse( running_machine *machine, int port ) |
| r7543 | r7544 | |
| 437 | 445 | state->mouse[port].deltay = var & 0xff; |
| 438 | 446 | state->mouse[port].oldy = state->mouse[port].y; |
| 439 | 447 | } |
| 448 | |
| 449 | state->data1[port] = state->mouse[port].buttons | (0x00 << 8); |
| 450 | state->data2[port] = 0; |
| 440 | 451 | } |
| 441 | 452 | |
| 442 | 453 | static void snes_input_read_superscope( running_machine *machine, int port ) |
| r7543 | r7544 | |
| 496 | 507 | words, you can connect SuperScope to Port1, but there is no way SNES could detect its on-screen position */ |
| 497 | 508 | if ((state->scope[port].buttons & 0xc0) && !(state->scope[port].buttons & 0x02) && port == 1) |
| 498 | 509 | snes_gun_latch(machine, state->scope[port].x, state->scope[port].y); |
| 510 | |
| 511 | state->data1[port] = 0xff | (state->scope[port].buttons << 8); |
| 512 | state->data2[port] = 0; |
| 499 | 513 | } |
| 500 | 514 | |
| 501 | 515 | static void snes_input_read( running_machine *machine ) |
| r7543 | r7544 | |
| 503 | 517 | snes_state *state = (snes_state *)machine->driver_data; |
| 504 | 518 | UINT8 ctrl1 = input_port_read(machine, "CTRLSEL") & 0x0f; |
| 505 | 519 | UINT8 ctrl2 = (input_port_read(machine, "CTRLSEL") & 0xf0) >> 4; |
| 506 | | int i; |
| 507 | 520 | |
| 508 | 521 | /* Check if lightgun has been chosen as input: if so, enable crosshair */ |
| 509 | 522 | timer_set(machine, attotime_zero, NULL, 0, lightgun_tick); |
| r7543 | r7544 | |
| 521 | 534 | break; |
| 522 | 535 | case 0: /* no controller in port1 */ |
| 523 | 536 | default: |
| 537 | state->data1[0] = 0; |
| 538 | state->data2[0] = 0; |
| 524 | 539 | break; |
| 525 | 540 | } |
| 526 | 541 | |
| r7543 | r7544 | |
| 537 | 552 | break; |
| 538 | 553 | case 0: /* no controller in port2 */ |
| 539 | 554 | default: |
| 555 | state->data1[1] = 0; |
| 556 | state->data2[1] = 0; |
| 540 | 557 | break; |
| 541 | 558 | } |
| 542 | 559 | |
| 543 | | // avoid sending signals that could crash games |
| 544 | | for (i = 0; i < 4; i++) |
| 545 | | { |
| 546 | | // if left, no right |
| 547 | | if (state->joypad[i].high & 2) |
| 548 | | state->joypad[i].high &= ~1; |
| 549 | | // if up, no down |
| 550 | | if (state->joypad[i].high & 8) |
| 551 | | state->joypad[i].high &= ~4; |
| 552 | | } |
| 553 | | |
| 554 | | // is automatic reading on? |
| 560 | // is automatic reading on? if so, copy port data1/data2 to joy1l->joy4h |
| 561 | // this actually works like reading the first 16bits from oldjoy1/2 in reverse order |
| 555 | 562 | if (snes_ram[NMITIMEN] & 1) |
| 556 | 563 | { |
| 557 | | switch (ctrl1) |
| 558 | | { |
| 559 | | case 1: /* SNES joypad */ |
| 560 | | state->joy1l = state->joypad[0].low; |
| 561 | | state->joy1h = state->joypad[0].high; |
| 562 | | state->joy3l = state->joypad[2].low; |
| 563 | | state->joy3h = state->joypad[2].high; |
| 564 | | break; |
| 565 | | case 2: /* SNES Mouse */ |
| 566 | | state->joy1l = state->mouse[0].buttons; |
| 567 | | state->joy1h = 0; |
| 568 | | state->joy3l = 0; |
| 569 | | state->joy3h = 0; |
| 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; |
| 577 | | case 0: /* no controller in port2 */ |
| 578 | | default: |
| 579 | | state->joy1l = 0; |
| 580 | | state->joy1h = 0; |
| 581 | | state->joy3l = 0; |
| 582 | | state->joy3h = 0; |
| 583 | | break; |
| 584 | | } |
| 564 | state->joy1l = (state->data1[0] & 0x00ff) >> 0; |
| 565 | state->joy1h = (state->data1[0] & 0xff00) >> 8; |
| 566 | state->joy2l = (state->data1[1] & 0x00ff) >> 0; |
| 567 | state->joy2h = (state->data1[1] & 0xff00) >> 8; |
| 568 | state->joy3l = (state->data2[0] & 0x00ff) >> 0; |
| 569 | state->joy3h = (state->data2[0] & 0xff00) >> 8; |
| 570 | state->joy4l = (state->data2[1] & 0x00ff) >> 0; |
| 571 | state->joy4h = (state->data2[1] & 0xff00) >> 8; |
| 585 | 572 | |
| 586 | | switch (ctrl2) |
| 587 | | { |
| 588 | | case 1: /* SNES joypad */ |
| 589 | | state->joy2l = state->joypad[1].low; |
| 590 | | state->joy2h = state->joypad[1].high; |
| 591 | | state->joy4l = state->joypad[3].low; |
| 592 | | state->joy4h = state->joypad[3].high; |
| 593 | | break; |
| 594 | | case 2: /* SNES Mouse */ |
| 595 | | state->joy2l = state->mouse[1].buttons; |
| 596 | | state->joy2h = 0; |
| 597 | | state->joy4l = 0; |
| 598 | | state->joy4h = 0; |
| 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; |
| 606 | | case 0: /* no controller in port2 */ |
| 607 | | default: |
| 608 | | state->joy2l = 0; |
| 609 | | state->joy2h = 0; |
| 610 | | state->joy4l = 0; |
| 611 | | state->joy4h = 0; |
| 612 | | break; |
| 613 | | } |
| 614 | | |
| 615 | 573 | // make sure read_idx starts returning all 1s because the auto-read reads it :-) |
| 616 | 574 | state->read_idx[0] = 16; |
| 617 | 575 | state->read_idx[1] = 16; |
| r7543 | r7544 | |
| 631 | 589 | if (state->read_idx[0] >= 16) |
| 632 | 590 | res = 0x01; |
| 633 | 591 | else |
| 634 | | res = ((state->joypad[0].low | (state->joypad[0].high << 8)) >> (15 - state->read_idx[0]++)) & 0x01; |
| 592 | res = (state->joypad[0].buttons >> (15 - state->read_idx[0]++)) & 0x01; |
| 635 | 593 | break; |
| 636 | 594 | case 2: /* SNES Mouse */ |
| 637 | 595 | if (state->read_idx[0] >= 32) |
| r7543 | r7544 | |
| 671 | 629 | if (state->read_idx[1] >= 16) |
| 672 | 630 | res = 0x01; |
| 673 | 631 | else |
| 674 | | res = ((state->joypad[1].low | (state->joypad[1].high << 8)) >> (15 - state->read_idx[1]++)) & 0x01; |
| 632 | res = (state->joypad[1].buttons >> (15 - state->read_idx[1]++)) & 0x01; |
| 675 | 633 | break; |
| 676 | 634 | case 2: /* SNES Mouse */ |
| 677 | 635 | if (state->read_idx[1] >= 32) |