trunk/src/mess/drivers/snes.c
| r21643 | r21644 | |
| 195 | 195 | return space.read_byte(offset + 0x800000); // [00-7f] same as [80-ff] |
| 196 | 196 | |
| 197 | 197 | // base cart access |
| 198 | | if (offset < 0x300000) |
| 199 | | return snes_r_bank1(space, offset, 0xff); |
| 200 | | else if (offset < 0x400000) |
| 201 | | return snes_r_bank2(space, offset - 0x300000, 0xff); |
| 202 | | else if (offset < 0x600000) |
| 203 | | return snes_r_bank3(space, offset - 0x400000, 0xff); |
| 204 | | else if (offset < 0x700000) |
| 205 | | return snes_r_bank4(space, offset - 0x600000, 0xff); |
| 206 | | else |
| 207 | | return snes_r_bank5(space, offset - 0x700000, 0xff); |
| 198 | return snes_r_bank1(space, offset, 0xff); |
| 208 | 199 | } |
| 209 | 200 | |
| 210 | 201 | READ8_MEMBER( snes_console_state::snes_hi_r ) |
| r21643 | r21644 | |
| 290 | 281 | return superfx_access_ram(m_superfx) ? m_sfx_ram[offset & 0xfffff] : snes_open_bus_r(space, 0); |
| 291 | 282 | |
| 292 | 283 | // base cart access |
| 293 | | if (offset < 0x400000) |
| 294 | | return snes_r_bank6(space, offset, 0xff); |
| 295 | | else |
| 296 | | return snes_r_bank7(space, offset - 0x400000, 0xff); |
| 284 | return snes_r_bank2(space, offset, 0xff); |
| 297 | 285 | } |
| 298 | 286 | |
| 299 | 287 | WRITE8_MEMBER( snes_console_state::snes_lo_w ) |
| r21643 | r21644 | |
| 367 | 355 | { space.write_byte(offset + 0x800000, data); return; } // [00-7f] same as [80-ff] |
| 368 | 356 | |
| 369 | 357 | // base cart access |
| 370 | | if (offset < 0x300000) |
| 371 | | snes_w_bank1(space, offset, data, 0xff); |
| 372 | | else if (offset < 0x400000) |
| 373 | | snes_w_bank2(space, offset - 0x300000, data, 0xff); |
| 374 | | else if (offset < 0x600000) |
| 375 | | return; |
| 376 | | else if (offset < 0x700000) |
| 377 | | snes_w_bank4(space, offset - 0x600000, data, 0xff); |
| 378 | | else |
| 379 | | snes_w_bank5(space, offset - 0x700000, data, 0xff); |
| 358 | snes_w_bank1(space, offset, data, 0xff); |
| 380 | 359 | } |
| 381 | 360 | |
| 382 | 361 | WRITE8_MEMBER( snes_console_state::snes_hi_w ) |
| r21643 | r21644 | |
| 459 | 438 | { m_sfx_ram[offset & 0xfffff] = data; return; } |
| 460 | 439 | |
| 461 | 440 | // base cart access |
| 462 | | if (offset < 0x400000) |
| 463 | | snes_w_bank6(space, offset, data, 0xff); |
| 464 | | else |
| 465 | | snes_w_bank7(space, offset, data - 0x400000, 0xff); |
| 441 | snes_w_bank2(space, offset, data, 0xff); |
| 466 | 442 | } |
| 467 | 443 | |
| 468 | 444 | READ8_MEMBER( snes_console_state::superfx_r_bank1 ) |
| r21643 | r21644 | |
| 2398 | 2374 | switch (state->m_type) |
| 2399 | 2375 | { |
| 2400 | 2376 | case SNES_MODE21: |
| 2401 | | machine.device("maincpu")->memory().space(AS_PROGRAM).install_readwrite_handler(0x000000, 0x7dffff, read8_delegate(FUNC(snsnew_state::snes21_lo_r),state), write8_delegate(FUNC(snsnew_state::snes21_lo_w),state)); |
| 2402 | | machine.device("maincpu")->memory().space(AS_PROGRAM).install_readwrite_handler(0x800000, 0xffffff, read8_delegate(FUNC(snsnew_state::snes21_hi_r),state), write8_delegate(FUNC(snsnew_state::snes21_hi_w),state)); |
| 2403 | | set_5a22_map(*state->m_maincpu); |
| 2377 | // machine.device("maincpu")->memory().space(AS_PROGRAM).install_readwrite_handler(0x000000, 0x7dffff, read8_delegate(FUNC(snsnew_state::snes21_lo_r),state), write8_delegate(FUNC(snsnew_state::snes21_lo_w),state)); |
| 2378 | // machine.device("maincpu")->memory().space(AS_PROGRAM).install_readwrite_handler(0x800000, 0xffffff, read8_delegate(FUNC(snsnew_state::snes21_hi_r),state), write8_delegate(FUNC(snsnew_state::snes21_hi_w),state)); |
| 2379 | // set_5a22_map(*state->m_maincpu); |
| 2404 | 2380 | break; |
| 2405 | 2381 | case SNES_DSP_MODE21: |
| 2406 | | // machine.device("maincpu")->memory().space(AS_PROGRAM).install_readwrite_handler(0x000000, 0x7dffff, read8_delegate(FUNC(snsnew_state::snes21_lo_r),state), write8_delegate(FUNC(snsnew_state::snes21_lo_w),state)); |
| 2407 | | // machine.device("maincpu")->memory().space(AS_PROGRAM).install_readwrite_handler(0x800000, 0xffffff, read8_delegate(FUNC(snsnew_state::snes21_hi_r),state), write8_delegate(FUNC(snsnew_state::snes21_hi_w),state)); |
| 2408 | | // machine.device("maincpu")->memory().space(AS_PROGRAM).install_read_handler(0x006000, 0x007fff, 0x9f0000, 0, read8_delegate(FUNC(device_sns_cart_interface::chip_read),state->m_slotcart->m_cart)); |
| 2409 | | // machine.device("maincpu")->memory().space(AS_PROGRAM).install_write_handler(0x006000, 0x007fff, 0x9f0000, 0, write8_delegate(FUNC(device_sns_cart_interface::chip_write),state->m_slotcart->m_cart)); |
| 2410 | | // set_5a22_map(*state->m_maincpu); |
| 2382 | // machine.device("maincpu")->memory().space(AS_PROGRAM).install_readwrite_handler(0x000000, 0x7dffff, read8_delegate(FUNC(snsnew_state::snes21_lo_r),state), write8_delegate(FUNC(snsnew_state::snes21_lo_w),state)); |
| 2383 | // machine.device("maincpu")->memory().space(AS_PROGRAM).install_readwrite_handler(0x800000, 0xffffff, read8_delegate(FUNC(snsnew_state::snes21_hi_r),state), write8_delegate(FUNC(snsnew_state::snes21_hi_w),state)); |
| 2384 | // machine.device("maincpu")->memory().space(AS_PROGRAM).install_read_handler(0x006000, 0x007fff, 0, 0x9f0000, read8_delegate(FUNC(device_sns_cart_interface::chip_read),state->m_slotcart->m_cart)); |
| 2385 | // machine.device("maincpu")->memory().space(AS_PROGRAM).install_write_handler(0x006000, 0x007fff, 0, 0x9f0000, write8_delegate(FUNC(device_sns_cart_interface::chip_write),state->m_slotcart->m_cart)); |
| 2386 | // set_5a22_map(*state->m_maincpu); |
| 2411 | 2387 | break; |
| 2412 | 2388 | case SNES_SRTC: |
| 2413 | | // machine.device("maincpu")->memory().space(AS_PROGRAM).install_readwrite_handler(0x000000, 0x7dffff, read8_delegate(FUNC(snsnew_state::snes21_lo_r),state), write8_delegate(FUNC(snsnew_state::snes21_lo_w),state)); |
| 2414 | | // machine.device("maincpu")->memory().space(AS_PROGRAM).install_readwrite_handler(0x800000, 0xffffff, read8_delegate(FUNC(snsnew_state::snes21_hi_r),state), write8_delegate(FUNC(snsnew_state::snes21_hi_w),state)); |
| 2415 | | // machine.device("maincpu")->memory().space(AS_PROGRAM).install_read_handler(0x002800, 0x002800, 0xbf0000, 0, read8_delegate(FUNC(device_sns_cart_interface::chip_read),state->m_slotcart->m_cart)); |
| 2416 | | // machine.device("maincpu")->memory().space(AS_PROGRAM).install_write_handler(0x002801, 0x002801, 0xbf0000, 0, write8_delegate(FUNC(device_sns_cart_interface::chip_write),state->m_slotcart->m_cart)); |
| 2417 | | // set_5a22_map(*state->m_maincpu); |
| 2389 | // machine.device("maincpu")->memory().space(AS_PROGRAM).install_readwrite_handler(0x000000, 0x7dffff, read8_delegate(FUNC(snsnew_state::snes21_lo_r),state), write8_delegate(FUNC(snsnew_state::snes21_lo_w),state)); |
| 2390 | // machine.device("maincpu")->memory().space(AS_PROGRAM).install_readwrite_handler(0x800000, 0xffffff, read8_delegate(FUNC(snsnew_state::snes21_hi_r),state), write8_delegate(FUNC(snsnew_state::snes21_hi_w),state)); |
| 2391 | // machine.device("maincpu")->memory().space(AS_PROGRAM).install_read_handler(0x002800, 0x002800, 0, 0xbf0000, read8_delegate(FUNC(device_sns_cart_interface::chip_read),state->m_slotcart->m_cart)); |
| 2392 | // machine.device("maincpu")->memory().space(AS_PROGRAM).install_write_handler(0x002801, 0x002801, 0, 0xbf0000, write8_delegate(FUNC(device_sns_cart_interface::chip_write),state->m_slotcart->m_cart)); |
| 2393 | // set_5a22_map(*state->m_maincpu); |
| 2418 | 2394 | break; |
| 2419 | 2395 | } |
| 2420 | 2396 | } |
trunk/src/mame/machine/snes.c
| r21643 | r21644 | |
| 676 | 676 | |
| 677 | 677 | */ |
| 678 | 678 | |
| 679 | | /* 0x000000 - 0x2fffff */ |
| 679 | /* 0x000000 - 0x7dffff */ |
| 680 | 680 | READ8_HANDLER( snes_r_bank1 ) |
| 681 | 681 | { |
| 682 | 682 | snes_state *state = space.machine().driver_data<snes_state>(); |
| 683 | 683 | UINT8 value = 0xff; |
| 684 | 684 | UINT16 address = offset & 0xffff; |
| 685 | 685 | |
| 686 | | if (address < 0x2000) /* Mirror of Low RAM */ |
| 687 | | value = space.read_byte(0x7e0000 + address); |
| 688 | | else if (address < 0x6000) /* I/O */ |
| 689 | | value = state->snes_r_io(space, address); |
| 690 | | else if (address < 0x8000) |
| 686 | if (offset < 0x400000) |
| 691 | 687 | { |
| 692 | | logerror("(PC=%06x) snes_r_bank1: Unmapped external chip read: %04x\n", space.device().safe_pc(), address); |
| 693 | | value = snes_open_bus_r(space, 0); /* Reserved */ |
| 694 | | } |
| 695 | | else |
| 696 | | value = snes_ram[offset]; //ROM |
| 697 | | |
| 698 | | return value; |
| 699 | | } |
| 700 | | |
| 701 | | /* 0x300000 - 0x3fffff */ |
| 702 | | READ8_HANDLER( snes_r_bank2 ) |
| 703 | | { |
| 704 | | snes_state *state = space.machine().driver_data<snes_state>(); |
| 705 | | UINT8 value = 0xff; |
| 706 | | UINT16 address = offset & 0xffff; |
| 707 | | |
| 708 | | if (address < 0x2000) /* Mirror of Low RAM */ |
| 709 | | value = space.read_byte(0x7e0000 + address); |
| 710 | | else if (address < 0x6000) /* I/O */ |
| 711 | | value = state->snes_r_io(space, address); |
| 712 | | else if (address < 0x8000) /* SRAM for mode_21, Reserved othewise */ |
| 713 | | { |
| 714 | | if (state->m_cart[0].mode == SNES_MODE_21 && state->m_cart[0].m_nvram_size > 0) |
| 688 | if (address < 0x2000) /* Mirror of Low RAM */ |
| 689 | value = space.read_byte(0x7e0000 + address); |
| 690 | else if (address < 0x6000) /* I/O */ |
| 691 | value = state->snes_r_io(space, address); |
| 692 | else if (address < 0x8000) |
| 715 | 693 | { |
| 716 | | /* Donkey Kong Country checks this and detects a copier if 0x800 is not masked out due to sram size */ |
| 717 | | /* OTOH Secret of Mana does not work properly if sram is not mirrored on later banks */ |
| 718 | | int mask = (state->m_cart[0].m_nvram_size - 1) & 0x7fff; /* Limit SRAM size to what's actually present */ |
| 719 | | value = state->m_cart[0].m_nvram[(offset - 0x6000) & mask]; |
| 694 | if (offset >= 0x300000 && state->m_cart[0].mode == SNES_MODE_21 && state->m_cart[0].m_nvram_size > 0) |
| 695 | { |
| 696 | /* Donkey Kong Country checks this and detects a copier if 0x800 is not masked out due to sram size */ |
| 697 | /* OTOH Secret of Mana does not work properly if sram is not mirrored on later banks */ |
| 698 | int mask = (state->m_cart[0].m_nvram_size - 1) & 0x7fff; /* Limit SRAM size to what's actually present */ |
| 699 | value = state->m_cart[0].m_nvram[(offset - 0x6000) & mask]; |
| 700 | } |
| 701 | else |
| 702 | value = snes_open_bus_r(space, 0); /* Reserved */ |
| 720 | 703 | } |
| 721 | 704 | else |
| 722 | | { |
| 723 | | logerror("(PC=%06x) snes_r_bank2: Unmapped external chip read: %04x\n", space.device().safe_pc(), address ); |
| 724 | | value = snes_open_bus_r(space, 0); |
| 725 | | } |
| 705 | value = snes_ram[offset]; //ROM |
| 726 | 706 | } |
| 727 | | else |
| 728 | | value = snes_ram[0x300000 + offset]; //ROM |
| 729 | | |
| 730 | | return value; |
| 731 | | } |
| 732 | | |
| 733 | | /* 0x400000 - 0x5fffff */ |
| 734 | | READ8_HANDLER( snes_r_bank3 ) |
| 735 | | { |
| 736 | | snes_state *state = space.machine().driver_data<snes_state>(); |
| 737 | | UINT8 value = 0xff; |
| 738 | | UINT16 address = offset & 0xffff; |
| 739 | | |
| 740 | | if (state->m_cart[0].mode & 5) /* Mode 20 & 22 */ |
| 707 | else if (offset < 0x700000) |
| 741 | 708 | { |
| 742 | | if (address < 0x8000 && state->m_cart[0].mode == SNES_MODE_20) |
| 743 | | value = snes_open_bus_r(space, 0); /* Reserved */ |
| 709 | if (state->m_cart[0].mode & 5 && address < 0x8000) /* Mode 20 & 22 in 0x0000-0x7fff */ |
| 710 | value = snes_open_bus_r(space, 0); |
| 744 | 711 | else |
| 745 | | value = snes_ram[0x400000 + offset]; //ROM |
| 712 | value = snes_ram[offset]; //ROM |
| 746 | 713 | } |
| 747 | | else /* Mode 21 & 25 */ |
| 748 | | value = snes_ram[0x400000 + offset]; //ROM |
| 749 | | |
| 750 | | return value; |
| 751 | | } |
| 752 | | |
| 753 | | /* 0x600000 - 0x6fffff */ |
| 754 | | READ8_HANDLER( snes_r_bank4 ) |
| 755 | | { |
| 756 | | snes_state *state = space.machine().driver_data<snes_state>(); |
| 757 | | UINT8 value = 0xff; |
| 758 | | UINT16 address = offset & 0xffff; |
| 759 | | |
| 760 | | if (state->m_cart[0].mode & 5) /* Mode 20 & 22 */ |
| 761 | | { |
| 762 | | if (address >= 0x8000) |
| 763 | | value = snes_ram[0x600000 + offset]; //ROM |
| 764 | | else |
| 765 | | { |
| 766 | | logerror("(PC=%06x) snes_r_bank4: Unmapped external chip read: %04x\n", space.device().safe_pc(), address); |
| 767 | | value = snes_open_bus_r(space, 0); /* Reserved */ |
| 768 | | } |
| 769 | | } |
| 770 | | else if (state->m_cart[0].mode & 0x0a) /* Mode 21 & 25 */ |
| 771 | | value = snes_ram[0x600000 + offset]; //ROM |
| 772 | | |
| 773 | | return value; |
| 774 | | } |
| 775 | | |
| 776 | | /* 0x700000 - 0x7dffff */ |
| 777 | | READ8_HANDLER( snes_r_bank5 ) |
| 778 | | { |
| 779 | | snes_state *state = space.machine().driver_data<snes_state>(); |
| 780 | | UINT8 value; |
| 781 | | UINT16 address = offset & 0xffff; |
| 782 | | |
| 783 | | if (state->m_cart[0].mode & 5 && address < 0x8000) /* Mode 20 & 22 */ |
| 784 | | { |
| 785 | | if (state->m_cart[0].m_nvram_size > 0x8000) |
| 786 | | { |
| 787 | | // In this case, SRAM is mapped in 0x8000 chunks at diff offsets: 0x700000-0x707fff, 0x710000-0x717fff, etc. |
| 788 | | int mask = state->m_cart[0].m_nvram_size - 1; |
| 789 | | offset = (offset / 0x10000) * 0x8000 + (offset & 0x7fff); |
| 790 | | value = state->m_cart[0].m_nvram[offset & mask]; |
| 791 | | } |
| 792 | | else if (state->m_cart[0].m_nvram_size > 0) |
| 793 | | { |
| 794 | | int mask = state->m_cart[0].m_nvram_size - 1; /* Limit SRAM size to what's actually present */ |
| 795 | | value = state->m_cart[0].m_nvram[offset & mask]; |
| 796 | | } |
| 797 | | else |
| 798 | | { |
| 799 | | logerror("(PC=%06x) snes_r_bank5: Unmapped external chip read: %04x\n", space.device().safe_pc(), address); |
| 800 | | value = snes_open_bus_r(space, 0); /* Reserved */ |
| 801 | | } |
| 802 | | } |
| 803 | 714 | else |
| 804 | | value = snes_ram[0x700000 + offset]; //ROM |
| 805 | | |
| 806 | | return value; |
| 807 | | } |
| 808 | | |
| 809 | | /* 0x800000 - 0xbfffff */ |
| 810 | | READ8_HANDLER( snes_r_bank6 ) |
| 811 | | { |
| 812 | | UINT8 value = 0; |
| 813 | | |
| 814 | | if ((offset & 0xffff) < 0x8000) |
| 815 | | value = space.read_byte(offset); |
| 816 | | else |
| 817 | | value = snes_ram[0x800000 + offset]; //ROM |
| 818 | | |
| 819 | | return value; |
| 820 | | } |
| 821 | | |
| 822 | | /* 0xc00000 - 0xffffff */ |
| 823 | | READ8_HANDLER( snes_r_bank7 ) |
| 824 | | { |
| 825 | | snes_state *state = space.machine().driver_data<snes_state>(); |
| 826 | | UINT8 value = 0; |
| 827 | | UINT16 address = offset & 0xffff; |
| 828 | | |
| 829 | | if (state->m_cart[0].mode & 5 && address < 0x8000) /* Mode 20 & 22 in 0x0000-0x7fff */ |
| 830 | 715 | { |
| 831 | | if (offset < 0x300000) |
| 832 | | value = space.read_byte(0x400000 + offset); |
| 833 | | else |
| 716 | if (state->m_cart[0].mode & 5 && address < 0x8000) /* Mode 20 & 22 */ |
| 834 | 717 | { |
| 835 | 718 | if (state->m_cart[0].m_nvram_size > 0x8000) |
| 836 | 719 | { |
| r21643 | r21644 | |
| 846 | 729 | } |
| 847 | 730 | else |
| 848 | 731 | { |
| 849 | | logerror("(PC=%06x) snes_r_bank7: Unmapped external chip read: %04x\n", space.device().safe_pc(), address); |
| 732 | logerror("(PC=%06x) snes_r_bank1: Unmapped external chip read: %X\n", space.device().safe_pc(), offset); |
| 850 | 733 | value = snes_open_bus_r(space, 0); /* Reserved */ |
| 851 | 734 | } |
| 852 | 735 | } |
| 736 | else |
| 737 | value = snes_ram[offset]; //ROM |
| 853 | 738 | } |
| 854 | | else |
| 855 | | value = snes_ram[0xc00000 + offset]; //ROM |
| 856 | | |
| 739 | |
| 857 | 740 | return value; |
| 858 | 741 | } |
| 859 | 742 | |
| 860 | 743 | |
| 861 | | /* 0x000000 - 0x2fffff */ |
| 862 | | WRITE8_HANDLER( snes_w_bank1 ) |
| 744 | /* 0x800000 - 0xffffff */ |
| 745 | READ8_HANDLER( snes_r_bank2 ) |
| 863 | 746 | { |
| 864 | 747 | snes_state *state = space.machine().driver_data<snes_state>(); |
| 748 | UINT8 value = 0; |
| 865 | 749 | UINT16 address = offset & 0xffff; |
| 866 | 750 | |
| 867 | | if (address < 0x2000) /* Mirror of Low RAM */ |
| 868 | | space.write_byte(0x7e0000 + address, data); |
| 869 | | else if (address < 0x6000) /* I/O */ |
| 870 | | state->snes_w_io(space, address, data); |
| 871 | | else if (address < 0x8000) |
| 872 | | logerror("(PC=%06x) snes_w_bank1: Attempt to write to reserved address: %x = %02x\n", space.device().safe_pc(), offset, data); |
| 751 | if (offset < 0x400000) |
| 752 | { |
| 753 | if (address < 0x8000) |
| 754 | value = space.read_byte(offset); |
| 755 | else |
| 756 | value = snes_ram[0x800000 + offset]; //ROM |
| 757 | } |
| 873 | 758 | else |
| 874 | | logerror("(PC=%06x) Attempt to write to ROM address: %X\n", space.device().safe_pc(), offset); |
| 875 | | } |
| 876 | | |
| 877 | | /* 0x300000 - 0x3fffff */ |
| 878 | | WRITE8_HANDLER( snes_w_bank2 ) |
| 879 | | { |
| 880 | | snes_state *state = space.machine().driver_data<snes_state>(); |
| 881 | | UINT16 address = offset & 0xffff; |
| 882 | | |
| 883 | | if (address < 0x2000) /* Mirror of Low RAM */ |
| 884 | | space.write_byte(0x7e0000 + address, data); |
| 885 | | else if (address < 0x6000) /* I/O */ |
| 886 | | state->snes_w_io(space, address, data); |
| 887 | | else if (address < 0x8000) /* SRAM for mode_21, Reserved othewise */ |
| 888 | 759 | { |
| 889 | | if (state->m_cart[0].mode == SNES_MODE_21 && state->m_cart[0].m_nvram_size > 0) |
| 760 | if (state->m_cart[0].mode & 5 && address < 0x8000) /* Mode 20 & 22 in 0x0000-0x7fff */ |
| 890 | 761 | { |
| 891 | | /* Donkey Kong Country checks this and detects a copier if 0x800 is not masked out due to sram size */ |
| 892 | | /* OTOH Secret of Mana does not work properly if sram is not mirrored on later banks */ |
| 893 | | int mask = (state->m_cart[0].m_nvram_size - 1) & 0x7fff; /* Limit SRAM size to what's actually present */ |
| 894 | | state->m_cart[0].m_nvram[(offset - 0x6000) & mask] = data; |
| 762 | if (offset < 0x700000) |
| 763 | value = space.read_byte(offset); |
| 764 | else |
| 765 | { |
| 766 | if (state->m_cart[0].m_nvram_size > 0x8000) |
| 767 | { |
| 768 | // In this case, SRAM is mapped in 0x8000 chunks at diff offsets: 0x700000-0x707fff, 0x710000-0x717fff, etc. |
| 769 | int mask = state->m_cart[0].m_nvram_size - 1; |
| 770 | offset = (offset / 0x10000) * 0x8000 + (offset & 0x7fff); |
| 771 | value = state->m_cart[0].m_nvram[offset & mask]; |
| 772 | } |
| 773 | else if (state->m_cart[0].m_nvram_size > 0) |
| 774 | { |
| 775 | int mask = state->m_cart[0].m_nvram_size - 1; /* Limit SRAM size to what's actually present */ |
| 776 | value = state->m_cart[0].m_nvram[offset & mask]; |
| 777 | } |
| 778 | else |
| 779 | { |
| 780 | logerror("(PC=%06x) snes_r_bank2: Unmapped external chip read: %X\n", space.device().safe_pc(), offset); |
| 781 | value = snes_open_bus_r(space, 0); /* Reserved */ |
| 782 | } |
| 783 | } |
| 895 | 784 | } |
| 896 | 785 | else |
| 897 | | logerror("(PC=%06x) snes_w_bank2: Attempt to write to reserved address: %X = %02x\n", space.device().safe_pc(), offset + 0x300000, data); |
| 786 | value = snes_ram[0x800000 + offset]; //ROM |
| 898 | 787 | } |
| 899 | | else |
| 900 | | logerror("(PC=%06x) Attempt to write to ROM address: %X\n", space.device().safe_pc(), offset + 0x300000); |
| 788 | |
| 789 | return value; |
| 901 | 790 | } |
| 902 | 791 | |
| 903 | | /* 0x600000 - 0x6fffff */ |
| 904 | | WRITE8_HANDLER( snes_w_bank4 ) |
| 792 | |
| 793 | /* 0x000000 - 0x7dffff */ |
| 794 | WRITE8_HANDLER( snes_w_bank1 ) |
| 905 | 795 | { |
| 906 | 796 | snes_state *state = space.machine().driver_data<snes_state>(); |
| 907 | 797 | UINT16 address = offset & 0xffff; |
| 908 | 798 | |
| 909 | | if (state->m_cart[0].mode & 5) /* Mode 20 & 22 */ |
| 799 | if (offset < 0x400000) |
| 910 | 800 | { |
| 911 | | if (address >= 0x8000) |
| 912 | | logerror("(PC=%06x) Attempt to write to ROM address: %X\n", space.device().safe_pc(), offset + 0x600000); |
| 801 | if (address < 0x2000) /* Mirror of Low RAM */ |
| 802 | space.write_byte(0x7e0000 + address, data); |
| 803 | else if (address < 0x6000) /* I/O */ |
| 804 | state->snes_w_io(space, address, data); |
| 805 | else if (address < 0x8000) |
| 806 | { |
| 807 | if (offset >= 0x300000 && state->m_cart[0].mode == SNES_MODE_21 && state->m_cart[0].m_nvram_size > 0) |
| 808 | { |
| 809 | /* Donkey Kong Country checks this and detects a copier if 0x800 is not masked out due to sram size */ |
| 810 | /* OTOH Secret of Mana does not work properly if sram is not mirrored on later banks */ |
| 811 | int mask = (state->m_cart[0].m_nvram_size - 1) & 0x7fff; /* Limit SRAM size to what's actually present */ |
| 812 | state->m_cart[0].m_nvram[(offset - 0x6000) & mask] = data; |
| 813 | } |
| 814 | else |
| 815 | logerror("(PC=%06x) snes_w_bank1: Attempt to write to reserved address: %X = %02X\n", space.device().safe_pc(), offset, data); |
| 816 | } |
| 913 | 817 | else |
| 914 | | logerror("(PC=%06x) snes_w_bank4: Attempt to write to reserved address: %X = %02x\n", space.device().safe_pc(), offset + 0x600000, data); |
| 818 | logerror("(PC=%06x) Attempt to write to ROM address: %X\n", space.device().safe_pc(), offset); |
| 915 | 819 | } |
| 916 | | else if (state->m_cart[0].mode & 0x0a) |
| 917 | | logerror("(PC=%06x) Attempt to write to ROM address: %X\n", space.device().safe_pc(), offset + 0x600000); |
| 918 | | } |
| 919 | | |
| 920 | | /* 0x700000 - 0x7dffff */ |
| 921 | | WRITE8_HANDLER( snes_w_bank5 ) |
| 922 | | { |
| 923 | | snes_state *state = space.machine().driver_data<snes_state>(); |
| 924 | | UINT16 address = offset & 0xffff; |
| 925 | | |
| 926 | | if (state->m_cart[0].mode & 5 && address < 0x8000) /* Mode 20 & 22 */ |
| 820 | else if (offset >= 0x600000 && offset < 0x700000) |
| 927 | 821 | { |
| 928 | | if (state->m_cart[0].m_nvram_size > 0x8000) |
| 929 | | { |
| 930 | | // In this case, SRAM is mapped in 0x8000 chunks at diff offsets: 0x700000-0x707fff, 0x710000-0x717fff, etc. |
| 931 | | int mask = state->m_cart[0].m_nvram_size - 1; |
| 932 | | offset = (offset / 0x10000) * 0x8000 + (offset & 0x7fff); |
| 933 | | state->m_cart[0].m_nvram[offset & mask] = data; |
| 934 | | } |
| 935 | | else if (state->m_cart[0].m_nvram_size > 0) |
| 936 | | { |
| 937 | | int mask = state->m_cart[0].m_nvram_size - 1; /* Limit SRAM size to what's actually present */ |
| 938 | | state->m_cart[0].m_nvram[offset & mask] = data; |
| 939 | | } |
| 822 | if (state->m_cart[0].mode & 5 && address < 0x8000) /* Mode 20 & 22 */ |
| 823 | logerror("(PC=%06x) snes_w_bank1: Attempt to write to reserved address: %X = %02X\n", space.device().safe_pc(), offset, data); |
| 940 | 824 | else |
| 941 | | logerror("(PC=%06x) snes_w_bank5: Attempt to write to reserved address: %X = %02x\n", space.device().safe_pc(), offset + 0x700000, data); |
| 825 | logerror("(PC=%06x) Attempt to write to ROM address: %X\n", space.device().safe_pc(), offset); |
| 942 | 826 | } |
| 943 | | else |
| 944 | | logerror("(PC=%06x) Attempt to write to ROM address: %X\n", space.device().safe_pc(), offset + 0x700000); |
| 945 | | } |
| 946 | | |
| 947 | | |
| 948 | | /* 0x800000 - 0xbfffff */ |
| 949 | | WRITE8_HANDLER( snes_w_bank6 ) |
| 950 | | { |
| 951 | | if ((offset & 0xffff) < 0x8000) |
| 952 | | space.write_byte(offset, data); |
| 953 | | else |
| 954 | | logerror("(PC=%06x) Attempt to write to ROM address: %X\n", space.device().safe_pc(), offset + 0x800000); |
| 955 | | } |
| 956 | | |
| 957 | | |
| 958 | | /* 0xc00000 - 0xffffff */ |
| 959 | | WRITE8_HANDLER( snes_w_bank7 ) |
| 960 | | { |
| 961 | | snes_state *state = space.machine().driver_data<snes_state>(); |
| 962 | | UINT16 address = offset & 0xffff; |
| 963 | | |
| 964 | | if (state->m_cart[0].mode & 5 && address < 0x8000) /* Mode 20 & 22 in 0x0000-0x7fff */ |
| 827 | else if (offset >= 0x700000) |
| 965 | 828 | { |
| 966 | | if (offset >= 0x300000) |
| 829 | if (state->m_cart[0].mode & 5 && address < 0x8000) /* Mode 20 & 22 */ |
| 967 | 830 | { |
| 968 | 831 | if (state->m_cart[0].m_nvram_size > 0x8000) |
| 969 | 832 | { |
| r21643 | r21644 | |
| 971 | 834 | int mask = state->m_cart[0].m_nvram_size - 1; |
| 972 | 835 | offset = (offset / 0x10000) * 0x8000 + (offset & 0x7fff); |
| 973 | 836 | state->m_cart[0].m_nvram[offset & mask] = data; |
| 974 | | return; |
| 975 | 837 | } |
| 976 | 838 | else if (state->m_cart[0].m_nvram_size > 0) |
| 977 | 839 | { |
| 978 | 840 | int mask = state->m_cart[0].m_nvram_size - 1; /* Limit SRAM size to what's actually present */ |
| 979 | 841 | state->m_cart[0].m_nvram[offset & mask] = data; |
| 980 | | return; |
| 981 | 842 | } |
| 843 | else |
| 844 | logerror("(PC=%06x) snes_w_bank1: Attempt to write to reserved address: %X = %02X\n", space.device().safe_pc(), offset, data); |
| 982 | 845 | } |
| 983 | 846 | else |
| 984 | | logerror("(PC=%06x) snes_w_bank7: Attempt to write to ROM address: %X = %02x\n", space.device().safe_pc(), offset + 0xc00000, data); |
| 847 | logerror("(PC=%06x) Attempt to write to ROM address: %X\n", space.device().safe_pc(), offset); |
| 985 | 848 | } |
| 986 | | else if (state->m_cart[0].mode & 0x0a) |
| 987 | | logerror("(PC=%06x) Attempt to write to ROM address: %X\n", space.device().safe_pc(), offset + 0xc00000); |
| 988 | 849 | } |
| 989 | 850 | |
| 851 | /* 0x800000 - 0xffffff */ |
| 852 | WRITE8_HANDLER( snes_w_bank2 ) |
| 853 | { |
| 854 | snes_state *state = space.machine().driver_data<snes_state>(); |
| 855 | UINT16 address = offset & 0xffff; |
| 856 | |
| 857 | if (offset < 0x400000) |
| 858 | { |
| 859 | if (address < 0x8000) |
| 860 | space.write_byte(offset, data); |
| 861 | else |
| 862 | logerror("(PC=%06x) Attempt to write to ROM address: %X\n", space.device().safe_pc(), offset + 0x800000); |
| 863 | } |
| 864 | else |
| 865 | { |
| 866 | if (state->m_cart[0].mode & 5 && address < 0x8000) /* Mode 20 & 22 in 0x0000-0x7fff */ |
| 867 | { |
| 868 | if (offset < 0x700000) |
| 869 | space.write_byte(offset, data); |
| 870 | else |
| 871 | { |
| 872 | if (state->m_cart[0].m_nvram_size > 0x8000) |
| 873 | { |
| 874 | // In this case, SRAM is mapped in 0x8000 chunks at diff offsets: 0x700000-0x707fff, 0x710000-0x717fff, etc. |
| 875 | int mask = state->m_cart[0].m_nvram_size - 1; |
| 876 | offset = (offset / 0x10000) * 0x8000 + (offset & 0x7fff); |
| 877 | state->m_cart[0].m_nvram[offset & mask] = data; |
| 878 | } |
| 879 | else if (state->m_cart[0].m_nvram_size > 0) |
| 880 | { |
| 881 | int mask = state->m_cart[0].m_nvram_size - 1; /* Limit SRAM size to what's actually present */ |
| 882 | state->m_cart[0].m_nvram[offset & mask] = data; |
| 883 | } |
| 884 | else |
| 885 | logerror("(PC=%06x) snes_w_bank2: Attempt to write to reserved address: %X = %02X\n", space.device().safe_pc(), offset, data); |
| 886 | } |
| 887 | } |
| 888 | else |
| 889 | logerror("(PC=%06x) Attempt to write to ROM address: %X\n", space.device().safe_pc(), offset); |
| 890 | } |
| 891 | } |
| 990 | 892 | |
| 893 | |
| 991 | 894 | /************************************* |
| 992 | 895 | |
| 993 | 896 | Input Callbacks |