trunk/src/mame/machine/snes.c
| r21698 | r21699 | |
| 676 | 676 | |
| 677 | 677 | */ |
| 678 | 678 | |
| 679 | static UINT8 snes_rom_access(running_machine &machine, UINT32 offset) |
| 680 | { |
| 681 | snes_state *state = machine.driver_data<snes_state>(); |
| 682 | UINT32 addr; |
| 683 | UINT8 value = 0xff; |
| 684 | UINT8 base_bank = (offset < 0x800000) ? 0x80 : 0x00; |
| 685 | |
| 686 | switch (state->m_cart[0].mode) |
| 687 | { |
| 688 | case SNES_MODE_20: |
| 689 | case SNES_MODE_22: |
| 690 | addr = (state->m_cart[0].rom_bank_map[offset/0x10000] * 0x8000) + (offset & 0x7fff); |
| 691 | value = state->m_cart[0].m_rom[addr]; |
| 692 | break; |
| 693 | case SNES_MODE_21: |
| 694 | case SNES_MODE_25: |
| 695 | offset &= 0x3fffff; |
| 696 | addr = (state->m_cart[0].rom_bank_map[base_bank + (offset/0x8000)] * 0x8000) + (offset & 0x7fff); |
| 697 | value = state->m_cart[0].m_rom[addr]; |
| 698 | break; |
| 699 | } |
| 700 | |
| 701 | return value; |
| 702 | } |
| 703 | |
| 679 | 704 | /* 0x000000 - 0x7dffff */ |
| 680 | 705 | READ8_HANDLER( snes_r_bank1 ) |
| 681 | 706 | { |
| r21698 | r21699 | |
| 702 | 727 | value = snes_open_bus_r(space, 0); /* Reserved */ |
| 703 | 728 | } |
| 704 | 729 | else |
| 705 | | value = snes_ram[offset]; //ROM |
| 730 | value = snes_rom_access(space.machine(), offset); //ROM |
| 706 | 731 | } |
| 707 | 732 | else if (offset < 0x700000) |
| 708 | 733 | { |
| 709 | 734 | if (state->m_cart[0].mode & 5 && address < 0x8000) /* Mode 20 & 22 in 0x0000-0x7fff */ |
| 710 | 735 | value = snes_open_bus_r(space, 0); |
| 711 | 736 | else |
| 712 | | value = snes_ram[offset]; //ROM |
| 737 | value = snes_rom_access(space.machine(), offset); //ROM |
| 713 | 738 | } |
| 714 | 739 | else |
| 715 | 740 | { |
| r21698 | r21699 | |
| 734 | 759 | } |
| 735 | 760 | } |
| 736 | 761 | else |
| 737 | | value = snes_ram[offset]; //ROM |
| 762 | value = snes_rom_access(space.machine(), offset); //ROM |
| 738 | 763 | } |
| 739 | | |
| 764 | |
| 740 | 765 | return value; |
| 741 | 766 | } |
| 742 | 767 | |
| r21698 | r21699 | |
| 753 | 778 | if (address < 0x8000) |
| 754 | 779 | value = space.read_byte(offset); |
| 755 | 780 | else |
| 756 | | value = snes_ram[0x800000 + offset]; //ROM |
| 781 | value = snes_rom_access(space.machine(), 0x800000 + offset); //ROM |
| 757 | 782 | } |
| 758 | 783 | else |
| 759 | 784 | { |
| r21698 | r21699 | |
| 783 | 808 | } |
| 784 | 809 | } |
| 785 | 810 | else |
| 786 | | value = snes_ram[0x800000 + offset]; //ROM |
| 811 | value = snes_rom_access(space.machine(), 0x800000 + offset); //ROM |
| 787 | 812 | } |
| 788 | | |
| 813 | |
| 789 | 814 | return value; |
| 790 | 815 | } |
| 791 | 816 | |
| r21698 | r21699 | |
| 813 | 838 | } |
| 814 | 839 | else |
| 815 | 840 | logerror("(PC=%06x) snes_w_bank1: Attempt to write to reserved address: %X = %02X\n", space.device().safe_pc(), offset, data); |
| 816 | | } |
| 841 | } |
| 817 | 842 | else |
| 818 | 843 | logerror("(PC=%06x) Attempt to write to ROM address: %X\n", space.device().safe_pc(), offset); |
| 819 | 844 | } |
| r21698 | r21699 | |
| 853 | 878 | { |
| 854 | 879 | snes_state *state = space.machine().driver_data<snes_state>(); |
| 855 | 880 | UINT16 address = offset & 0xffff; |
| 856 | | |
| 881 | |
| 857 | 882 | if (offset < 0x400000) |
| 858 | 883 | { |
| 859 | 884 | if (address < 0x8000) |
| r21698 | r21699 | |
| 1158 | 1183 | } |
| 1159 | 1184 | |
| 1160 | 1185 | |
| 1186 | void snes_state::rom_map_setup(UINT32 size) |
| 1187 | { |
| 1188 | int i; |
| 1189 | // setup the rom_bank_map array to faster ROM read |
| 1190 | for (i = 0; i < size / 0x8000; i++) |
| 1191 | m_cart[0].rom_bank_map[i] = i; |
| 1192 | |
| 1193 | // fill up remaining blocks with mirrors |
| 1194 | while (i % 256) |
| 1195 | { |
| 1196 | int j = 0, repeat_banks; |
| 1197 | while ((i % (256 >> j)) && j < 8) |
| 1198 | j++; |
| 1199 | repeat_banks = i % (256 >> (j - 1)); |
| 1200 | for (int k = 0; k < repeat_banks; k++) |
| 1201 | m_cart[0].rom_bank_map[i + k] = m_cart[0].rom_bank_map[i + k - repeat_banks]; |
| 1202 | i += repeat_banks; |
| 1203 | } |
| 1204 | } |
| 1205 | |
| 1161 | 1206 | /* for mame we use an init, maybe we will need more for the different games */ |
| 1162 | 1207 | DRIVER_INIT_MEMBER(snes_state,snes) |
| 1163 | 1208 | { |
| 1164 | | UINT16 total_blocks, read_blocks; |
| 1165 | | UINT8 *rom; |
| 1166 | | |
| 1167 | | rom = memregion("user3")->base(); |
| 1209 | UINT8 *rom = memregion("user3")->base(); |
| 1168 | 1210 | snes_ram = auto_alloc_array_clear(machine(), UINT8, 0x1400000); |
| 1169 | 1211 | |
| 1170 | 1212 | m_cart[0].m_rom_size = memregion("user3")->bytes(); |
| 1171 | 1213 | m_cart[0].m_rom = auto_alloc_array_clear(machine(), UINT8, m_cart[0].m_rom_size); |
| 1172 | 1214 | memcpy(m_cart[0].m_rom, rom, m_cart[0].m_rom_size); |
| 1215 | rom_map_setup(m_cart[0].m_rom_size); |
| 1173 | 1216 | |
| 1174 | 1217 | m_cart[0].m_nvram_size = 0; |
| 1175 | 1218 | if (rom[0x7fd8] > 0) |
| r21698 | r21699 | |
| 1185 | 1228 | /* all NSS games seem to use MODE 20 */ |
| 1186 | 1229 | m_cart[0].mode = SNES_MODE_20; |
| 1187 | 1230 | m_has_addon_chip = HAS_NONE; |
| 1188 | | |
| 1189 | | /* Find the number of blocks in this ROM */ |
| 1190 | | total_blocks = (memregion("user3")->bytes() / 0x8000); |
| 1191 | | read_blocks = 0; |
| 1192 | | |
| 1193 | | /* Loading all the data blocks from cart, we only partially cover banks 0x00 to 0x7f. Therefore, we |
| 1194 | | * have to mirror the blocks until we reach the end. E.g. for a 11Mbits image (44 blocks), we proceed |
| 1195 | | * as follows: |
| 1196 | | * 11 Mbits = 8 Mbits (blocks 1->32) + 2 Mbits (blocks 33->40) + 1 Mbit (blocks 41->44). |
| 1197 | | * Hence, we fill memory up to 16 Mbits (banks 0x00 to 0x3f) mirroring the final part: |
| 1198 | | * 8 Mbits (blocks 1->32) + 2 Mbits (blocks 33->40) + 1 Mbit (blocks 41->44) + 1 Mbit (blocks 41->44) |
| 1199 | | * + 2 Mbits (blocks 33->40) + 1 Mbit (blocks 41->44) + 1 Mbit (blocks 41->44). |
| 1200 | | * And we repeat the same blocks in the second half of the banks (banks 0x40 to 0x7f). |
| 1201 | | * This is likely what happens in the real SNES as well, because the unit cannot be aware of the exact |
| 1202 | | * size of data in the cart (procedure confirmed by byuu) |
| 1203 | | */ |
| 1204 | | |
| 1205 | | /* LoROM carts load data in banks 0x00 to 0x7f at address 0x8000 (actually up to 0x7d, because 0x7e and |
| 1206 | | * 0x7f are overwritten by WRAM). Each block is also mirrored in banks 0x80 to 0xff (up to 0xff for real) |
| 1207 | | */ |
| 1208 | | while (read_blocks < 128 && read_blocks < total_blocks) |
| 1209 | | { |
| 1210 | | /* Loading data */ |
| 1211 | | memcpy(&snes_ram[0x008000 + read_blocks * 0x10000], &rom[read_blocks * 0x08000], 0x8000); |
| 1212 | | /* Mirroring */ |
| 1213 | | memcpy(&snes_ram[0x808000 + read_blocks * 0x10000], &snes_ram[0x8000 + read_blocks * 0x10000], 0x8000); |
| 1214 | | read_blocks++; |
| 1215 | | } |
| 1216 | | /* Filling banks up to 0x7f and their mirrors */ |
| 1217 | | while (read_blocks % 128) |
| 1218 | | { |
| 1219 | | int j = 0, repeat_blocks; |
| 1220 | | while ((read_blocks % (128 >> j)) && j < 7) |
| 1221 | | j++; |
| 1222 | | repeat_blocks = read_blocks % (128 >> (j - 1)); |
| 1223 | | |
| 1224 | | memcpy(&snes_ram[read_blocks * 0x10000], &snes_ram[(read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000); |
| 1225 | | memcpy(&snes_ram[0x800000 + read_blocks * 0x10000], &snes_ram[0x800000 + (read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000); |
| 1226 | | |
| 1227 | | read_blocks += repeat_blocks; |
| 1228 | | } |
| 1229 | 1231 | } |
| 1230 | 1232 | |
| 1231 | 1233 | DRIVER_INIT_MEMBER(snes_state,snes_hirom) |
| 1232 | 1234 | { |
| 1233 | | UINT16 total_blocks, read_blocks; |
| 1234 | | UINT8 *rom; |
| 1235 | | |
| 1236 | | rom = memregion("user3")->base(); |
| 1235 | UINT8 *rom = memregion("user3")->base(); |
| 1237 | 1236 | snes_ram = auto_alloc_array(machine(), UINT8, 0x1400000); |
| 1238 | 1237 | memset(snes_ram, 0, 0x1400000); |
| 1239 | 1238 | |
| 1240 | 1239 | m_cart[0].m_rom_size = memregion("user3")->bytes(); |
| 1241 | 1240 | m_cart[0].m_rom = auto_alloc_array_clear(machine(), UINT8, m_cart[0].m_rom_size); |
| 1242 | 1241 | memcpy(m_cart[0].m_rom, rom, m_cart[0].m_rom_size); |
| 1242 | rom_map_setup(m_cart[0].m_rom_size); |
| 1243 | 1243 | |
| 1244 | 1244 | m_cart[0].m_nvram_size = 0; |
| 1245 | 1245 | if (rom[0xffd8] > 0) |
| r21698 | r21699 | |
| 1254 | 1254 | |
| 1255 | 1255 | m_cart[0].mode = SNES_MODE_21; |
| 1256 | 1256 | m_has_addon_chip = HAS_NONE; |
| 1257 | | |
| 1258 | | /* Find the number of blocks in this ROM */ |
| 1259 | | total_blocks = (memregion("user3")->bytes() / 0x10000); |
| 1260 | | read_blocks = 0; |
| 1261 | | |
| 1262 | | /* See above for details about the way we fill banks 0x00 to 0x7f */ |
| 1263 | | |
| 1264 | | /* HiROM carts load data in banks 0xc0 to 0xff. Each bank is fully mirrored in banks 0x40 to 0x7f |
| 1265 | | * (actually up to 0x7d, because 0x7e and 0x7f are overwritten by WRAM). The top half (address |
| 1266 | | * range 0x8000 - 0xffff) of each bank is also mirrored in banks 0x00 to 0x3f and 0x80 to 0xbf. |
| 1267 | | */ |
| 1268 | | while (read_blocks < 64 && read_blocks < total_blocks) |
| 1269 | | { |
| 1270 | | /* Loading data */ |
| 1271 | | memcpy(&snes_ram[0xc00000 + read_blocks * 0x10000], &rom[read_blocks * 0x10000], 0x10000); |
| 1272 | | /* Mirroring */ |
| 1273 | | memcpy(&snes_ram[0x008000 + read_blocks * 0x10000], &snes_ram[0xc08000 + read_blocks * 0x10000], 0x8000); |
| 1274 | | memcpy(&snes_ram[0x400000 + read_blocks * 0x10000], &snes_ram[0xc00000 + read_blocks * 0x10000], 0x10000); |
| 1275 | | memcpy(&snes_ram[0x808000 + read_blocks * 0x10000], &snes_ram[0xc08000 + read_blocks * 0x10000], 0x8000); |
| 1276 | | read_blocks++; |
| 1277 | | } |
| 1278 | | /* Filling banks up to 0x7f and their mirrors */ |
| 1279 | | while (read_blocks % 64) |
| 1280 | | { |
| 1281 | | int j = 0, repeat_blocks; |
| 1282 | | while ((read_blocks % (64 >> j)) && j < 6) |
| 1283 | | j++; |
| 1284 | | repeat_blocks = read_blocks % (64 >> (j - 1)); |
| 1285 | | |
| 1286 | | memcpy(&snes_ram[0xc00000 + read_blocks * 0x10000], &snes_ram[0xc00000 + (read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000); |
| 1287 | | memcpy(&snes_ram[read_blocks * 0x10000], &snes_ram[(read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000); |
| 1288 | | memcpy(&snes_ram[0x400000 + read_blocks * 0x10000], &snes_ram[0x400000 + (read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000); |
| 1289 | | memcpy(&snes_ram[0x800000 + read_blocks * 0x10000], &snes_ram[0x800000 + (read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000); |
| 1290 | | read_blocks += repeat_blocks; |
| 1291 | | } |
| 1292 | 1257 | } |
| 1293 | 1258 | |
| 1294 | 1259 | |
trunk/src/mess/drivers/snes.c
| r21698 | r21699 | |
| 61 | 61 | DECLARE_READ8_MEMBER( superfx_r_bank2 ); |
| 62 | 62 | DECLARE_READ8_MEMBER( superfx_r_bank3 ); |
| 63 | 63 | DECLARE_WRITE8_MEMBER( superfx_w_bank3 ); |
| 64 | DECLARE_READ8_MEMBER( sufami_r ); |
| 65 | DECLARE_WRITE8_MEMBER( sufami_w ); |
| 64 | 66 | CUSTOM_INPUT_MEMBER( snes_mouse_speed_input ); |
| 65 | 67 | CUSTOM_INPUT_MEMBER( snes_superscope_offscreen_input ); |
| 66 | 68 | TIMER_CALLBACK_MEMBER( lightgun_tick ); |
| r21698 | r21699 | |
| 138 | 140 | m_upd96050->dataram_w(addr/2, temp); |
| 139 | 141 | } |
| 140 | 142 | |
| 141 | | |
| 142 | 143 | READ8_MEMBER( snes_console_state::sfx_r ) |
| 143 | 144 | { |
| 144 | 145 | UINT16 address = offset & 0xffff; |
| r21698 | r21699 | |
| 156 | 157 | else if (address < 0x8000) |
| 157 | 158 | return superfx_access_ram(m_superfx) ? m_sfx_ram[offset & 0x1fff] : snes_open_bus_r(space, 0); |
| 158 | 159 | else |
| 159 | | return snes_ram[offset]; |
| 160 | return m_cart[0].m_rom[m_cart[0].rom_bank_map[offset / 0x10000] * 0x8000 + (offset & 0x7fff)]; |
| 160 | 161 | } |
| 161 | 162 | else if (offset < 0x600000) |
| 162 | 163 | { |
| 163 | 164 | if (superfx_access_rom(m_superfx)) |
| 164 | | return snes_ram[offset]; |
| 165 | return m_cart[0].m_rom[m_cart[0].rom_bank_map[(offset - 0x400000) / 0x8000] * 0x8000 + (offset & 0x7fff)]; |
| 165 | 166 | else |
| 166 | 167 | { |
| 167 | 168 | static const UINT8 sfx_data[16] = { |
| r21698 | r21699 | |
| 468 | 469 | snes_w_bank2(space, offset, data, 0xff); |
| 469 | 470 | } |
| 470 | 471 | |
| 472 | READ8_MEMBER( snes_console_state::sufami_r ) |
| 473 | { |
| 474 | UINT16 address = offset & 0xffff; |
| 475 | if (offset < 0x200000) |
| 476 | { |
| 477 | if (address < 0x2000) |
| 478 | return space.read_byte(0x7e0000 + address); |
| 479 | else if (address < 0x6000) |
| 480 | return snes_r_io(space, address); |
| 481 | else if (address < 0x8000) |
| 482 | return snes_open_bus_r(space, 0); |
| 483 | else |
| 484 | { |
| 485 | UINT8 *ROM = memregion("sufami")->base(); |
| 486 | int bank = (offset / 0x10000) & 7; |
| 487 | return ROM[bank * 0x8000 + (offset & 0x7fff)]; // SUFAMI ROM |
| 488 | } |
| 489 | } |
| 490 | else if (offset < 0x400000) |
| 491 | { |
| 492 | if (address < 0x2000) |
| 493 | return space.read_byte(0x7e0000 + address); |
| 494 | else if (address < 0x6000) |
| 495 | return snes_r_io(space, address); |
| 496 | else if (address < 0x8000) |
| 497 | return snes_open_bus_r(space, 0); |
| 498 | else if (m_cart[0].slot_in_use) |
| 499 | { |
| 500 | int bank = (offset - 0x200000) / 0x10000; |
| 501 | return m_cart[0].m_rom[m_cart[0].rom_bank_map[bank] * 0x8000 + (offset & 0x7fff)]; // SUFAMI SLOT1 |
| 502 | } |
| 503 | } |
| 504 | else if (offset < 0x600000) |
| 505 | { |
| 506 | if (address < 0x8000) |
| 507 | return snes_open_bus_r(space, 0); |
| 508 | else if (m_cart[1].slot_in_use) |
| 509 | { |
| 510 | int bank = (offset - 0x400000) / 0x10000; |
| 511 | return m_cart[1].m_rom[m_cart[1].rom_bank_map[bank] * 0x8000 + (offset & 0x7fff)]; // SUFAMI SLOT2 |
| 512 | } |
| 513 | } |
| 514 | else if (address >= 0x8000 && ((offset >= 0x600000 && offset < 0x640000) || (offset >= 0x700000 && offset < 0x740000))) |
| 515 | { |
| 516 | int slot_id = (offset & 0x100000) ? 1 : 0; |
| 517 | if (m_cart[slot_id].slot_in_use) |
| 518 | { |
| 519 | int bank = (offset & 0x3ffff) / 0x10000; |
| 520 | return m_cart[slot_id].m_nvram[bank * 0x8000 + (offset & 0x7fff)]; // SLOT RAM |
| 521 | } |
| 522 | } |
| 523 | return snes_open_bus_r(space, 0); |
| 524 | } |
| 525 | |
| 526 | WRITE8_MEMBER( snes_console_state::sufami_w ) |
| 527 | { |
| 528 | UINT16 address = offset & 0xffff; |
| 529 | if (offset < 0x400000) |
| 530 | { |
| 531 | if (address < 0x2000) |
| 532 | space.write_byte(0x7e0000 + address, data); |
| 533 | else if (address < 0x6000) |
| 534 | snes_w_io(space, address, data); |
| 535 | } |
| 536 | else if (address >= 0x8000 && ((offset >= 0x600000 && offset < 0x640000) || (offset >= 0x700000 && offset < 0x740000))) |
| 537 | { |
| 538 | int slot_id = (offset & 0x100000) ? 1 : 0; |
| 539 | if (m_cart[slot_id].slot_in_use) |
| 540 | { |
| 541 | int bank = (offset & 0x3ffff) / 0x10000; |
| 542 | m_cart[slot_id].m_nvram[bank * 0x8000 + (offset & 0x7fff)] = data; // SLOT RAM |
| 543 | } |
| 544 | } |
| 545 | } |
| 546 | |
| 471 | 547 | READ8_MEMBER( snes_console_state::superfx_r_bank1 ) |
| 472 | 548 | { |
| 473 | | return snes_ram[offset | 0x8000]; |
| 549 | return m_cart[0].m_rom[m_cart[0].rom_bank_map[offset / 0x10000] * 0x8000 + (offset & 0x7fff)]; |
| 474 | 550 | } |
| 475 | 551 | |
| 476 | 552 | READ8_MEMBER( snes_console_state::superfx_r_bank2 ) |
| 477 | 553 | { |
| 478 | | return snes_ram[0x400000 + offset]; |
| 554 | return m_cart[0].m_rom[m_cart[0].rom_bank_map[offset / 0x8000] * 0x8000 + (offset & 0x7fff)]; |
| 479 | 555 | } |
| 480 | 556 | |
| 481 | 557 | READ8_MEMBER( snes_console_state::superfx_r_bank3 ) |
| 482 | 558 | { |
| 483 | 559 | /* IMPORTANT: SFX RAM sits in 0x600000-0x7fffff, and it's mirrored in 0xe00000-0xffffff. However, SNES |
| 484 | 560 | has only access to 0x600000-0x7dffff (because there is WRAM after that). */ |
| 485 | | //printf("superfx_r_bank3: %08x = %02x\n", offset, snes_ram[0xe00000 + offset]); |
| 561 | //printf("superfx_r_bank3: %08x = %02x\n", offset, m_sfx_ram[offset & 0xfffff]); |
| 486 | 562 | return m_sfx_ram[offset & 0xfffff]; |
| 487 | 563 | } |
| 488 | 564 | |
| r21698 | r21699 | |
| 506 | 582 | AM_RANGE(0x800000, 0xffffff) AM_READWRITE(snes_hi_r, snes_hi_w) |
| 507 | 583 | ADDRESS_MAP_END |
| 508 | 584 | |
| 585 | static ADDRESS_MAP_START( snesst_map, AS_PROGRAM, 8, snes_console_state ) |
| 586 | AM_RANGE(0x000000, 0x7dffff) AM_READWRITE(sufami_r, sufami_w) |
| 587 | AM_RANGE(0x7e0000, 0x7fffff) AM_RAM /* 8KB Low RAM, 24KB High RAM, 96KB Expanded RAM */ |
| 588 | AM_RANGE(0x800000, 0xffffff) AM_READWRITE(sufami_r, sufami_w) |
| 589 | ADDRESS_MAP_END |
| 590 | |
| 509 | 591 | static ADDRESS_MAP_START( superfx_map, AS_PROGRAM, 8, snes_console_state ) |
| 510 | 592 | AM_RANGE(0x000000, 0x3fffff) AM_READ(superfx_r_bank1) |
| 511 | 593 | AM_RANGE(0x400000, 0x5fffff) AM_READ(superfx_r_bank2) |
| r21698 | r21699 | |
| 1295 | 1377 | MACHINE_CONFIG_END |
| 1296 | 1378 | |
| 1297 | 1379 | static MACHINE_CONFIG_DERIVED( snesst, snes_base ) |
| 1380 | MCFG_CPU_MODIFY( "maincpu" ) |
| 1381 | MCFG_CPU_PROGRAM_MAP(snesst_map) |
| 1298 | 1382 | |
| 1299 | 1383 | MCFG_MACHINE_START(snesst) |
| 1300 | 1384 | |
| r21698 | r21699 | |
| 1584 | 1668 | |
| 1585 | 1669 | if (m_type == SNES_SUFAMITURBO && address >= 0x8000 && ((offset >= 0x600000 && offset < 0x640000) || (offset >= 0x700000 && offset < 0x740000))) |
| 1586 | 1670 | { m_slotcart->m_cart->write_h(space, offset, data); return; } |
| 1587 | | |
| 1671 | |
| 1588 | 1672 | if (offset < 0x400000) |
| 1589 | 1673 | { |
| 1590 | 1674 | if (address < 0x2000) |
| r21698 | r21699 | |
| 1631 | 1715 | { |
| 1632 | 1716 | if (m_type == SNES_SUFAMITURBO && address >= 0x8000 && offset < 0x740000) |
| 1633 | 1717 | return m_slotcart->m_cart->read_l(space, offset); |
| 1634 | | |
| 1718 | |
| 1635 | 1719 | // here usually there is SRAM mirrored in the whole range, but if ROM is very large then arrives here too (see tokimeki and wizardg4) |
| 1636 | 1720 | if (m_slotcart->m_cart->get_rom_size() > 0x200000 && address >= 0x8000) |
| 1637 | 1721 | return m_slotcart->m_cart->read_l(space, offset); |
| r21698 | r21699 | |
| 1741 | 1825 | int mask = (m_slotcart->m_cart->get_nvram_size() - 1) & 0x7fff; |
| 1742 | 1826 | return m_slotcart->m_cart->read_ram(space, (offset - 0x6000) & mask); |
| 1743 | 1827 | } |
| 1744 | | |
| 1828 | |
| 1745 | 1829 | if (m_slotcart->m_cart->get_nvram_size() && offset >= 0x300000) |
| 1746 | 1830 | { |
| 1747 | 1831 | /* Donkey Kong Country checks this and detects a copier if 0x800 is not masked out due to sram size */ |
| r21698 | r21699 | |
| 1805 | 1889 | } |
| 1806 | 1890 | else if (address < 0x8000) |
| 1807 | 1891 | return m_slotcart->m_cart->read_ram(space, offset & 0x1fff); |
| 1808 | | else |
| 1892 | else |
| 1809 | 1893 | return m_slotcart->m_cart->read_h(space, offset); |
| 1810 | 1894 | } |
| 1811 | 1895 | else if (offset < 0x600000) |
| r21698 | r21699 | |
| 1986 | 2070 | } |
| 1987 | 2071 | else if (offset >= 0x700000 && address < 0x8000 && m_slotcart->m_cart->get_nvram_size()) // NVRAM access |
| 1988 | 2072 | return m_slotcart->m_cart->read_ram(space, offset); |
| 1989 | | else // ROM access |
| 2073 | else // ROM access |
| 1990 | 2074 | return m_slotcart->m_cart->read_l(space, offset); |
| 1991 | 2075 | } |
| 1992 | 2076 | |
| r21698 | r21699 | |
| 2096 | 2180 | READ8_MEMBER( snsnew_state::snesbsx_lo_r ) |
| 2097 | 2181 | { |
| 2098 | 2182 | UINT16 address = offset & 0xffff; |
| 2099 | | |
| 2183 | |
| 2100 | 2184 | if (offset < 0x400000) |
| 2101 | 2185 | { |
| 2102 | 2186 | if (address < 0x2000) |
| r21698 | r21699 | |
| 2458 | 2542 | switch (state->m_type) |
| 2459 | 2543 | { |
| 2460 | 2544 | case SNES_MODE21: |
| 2461 | | // 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)); |
| 2462 | | // 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)); |
| 2463 | | // set_5a22_map(*state->m_maincpu); |
| 2545 | // 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)); |
| 2546 | // 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)); |
| 2547 | // set_5a22_map(*state->m_maincpu); |
| 2464 | 2548 | break; |
| 2465 | 2549 | case SNES_DSP_MODE21: |
| 2466 | | // 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)); |
| 2467 | | // 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)); |
| 2468 | | // 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)); |
| 2469 | | // 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)); |
| 2470 | | // set_5a22_map(*state->m_maincpu); |
| 2550 | // 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)); |
| 2551 | // 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)); |
| 2552 | // 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)); |
| 2553 | // 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)); |
| 2554 | // set_5a22_map(*state->m_maincpu); |
| 2471 | 2555 | break; |
| 2472 | 2556 | case SNES_SRTC: |
| 2473 | | // 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)); |
| 2474 | | // 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)); |
| 2475 | | // 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)); |
| 2476 | | // 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)); |
| 2477 | | // set_5a22_map(*state->m_maincpu); |
| 2557 | // 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)); |
| 2558 | // 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)); |
| 2559 | // 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)); |
| 2560 | // 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)); |
| 2561 | // set_5a22_map(*state->m_maincpu); |
| 2478 | 2562 | break; |
| 2479 | 2563 | } |
| 2480 | 2564 | } |
trunk/src/mess/machine/snescart.c
| r21698 | r21699 | |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | /* Saves the battery backed RAM from the appropriate memory area */ |
| 131 | | static void snes_save_sram(running_machine &machine) |
| 132 | | { |
| 133 | | snes_state *state = machine.driver_data<snes_state>(); |
| 134 | | device_image_interface *image = dynamic_cast<device_image_interface *>(machine.device("cart")); |
| 135 | | image->battery_save(state->m_cart[0].m_nvram, state->m_cart[0].m_nvram_size); |
| 136 | | } |
| 137 | | |
| 138 | 131 | void snes_machine_stop(running_machine &machine) |
| 139 | 132 | { |
| 140 | 133 | snes_state *state = machine.driver_data<snes_state>(); |
| 141 | 134 | |
| 142 | 135 | /* Save SRAM */ |
| 143 | 136 | if (state->m_cart[0].m_nvram_size > 0) |
| 144 | | snes_save_sram(machine); |
| 137 | { |
| 138 | device_image_interface *image = dynamic_cast<device_image_interface *>(machine.device("cart")); |
| 139 | image->battery_save(state->m_cart[0].m_nvram, state->m_cart[0].m_nvram_size); |
| 140 | } |
| 145 | 141 | } |
| 146 | 142 | |
| 147 | 143 | |
| 148 | 144 | static void sufami_load_sram(running_machine &machine, const char *cart_tag) |
| 149 | 145 | { |
| 150 | | UINT8 ii; |
| 151 | | UINT8 *battery_ram, *ptr; |
| 152 | | int st_sram_offset = 0; |
| 153 | | |
| 154 | | battery_ram = (UINT8*)malloc(0x20000); |
| 155 | | ptr = battery_ram; |
| 146 | snes_state *state = machine.driver_data<snes_state>(); |
| 147 | int slot_id = 0; |
| 156 | 148 | device_image_interface *image = dynamic_cast<device_image_interface *>(machine.device(cart_tag)); |
| 157 | | image->battery_load(battery_ram, 0x20000, 0); |
| 158 | 149 | |
| 159 | 150 | if (strcmp(cart_tag, ":slot_a") == 0) |
| 160 | | st_sram_offset = 0x608000; |
| 151 | slot_id = 0; |
| 161 | 152 | |
| 162 | 153 | if (strcmp(cart_tag, ":slot_b") == 0) |
| 163 | | st_sram_offset = 0x708000; |
| 154 | slot_id = 1; |
| 164 | 155 | |
| 165 | | /* Cart RAM is at 0x60-0x63:0x8000-0xffff (+0x10 for slot2) */ |
| 166 | | for (ii = 0; ii < 4; ii++) |
| 167 | | { |
| 168 | | /* loading */ |
| 169 | | memcpy(&snes_ram[st_sram_offset + (ii * 0x010000)], ptr + (ii * 0x8000), 0x8000); |
| 170 | | /* mirroring */ |
| 171 | | memcpy(&snes_ram[0x800000 + st_sram_offset + (ii * 0x010000)], &snes_ram[st_sram_offset + (ii * 0x010000)], 0x8000); |
| 172 | | } |
| 173 | | |
| 174 | | free(battery_ram); |
| 156 | image->battery_load(state->m_cart[slot_id].m_nvram, state->m_cart[slot_id].m_nvram_size, 0xff); |
| 175 | 157 | } |
| 176 | 158 | |
| 177 | 159 | void sufami_machine_stop(running_machine &machine) |
| 178 | 160 | { |
| 179 | 161 | snes_state *state = machine.driver_data<snes_state>(); |
| 180 | | UINT8 ii; |
| 181 | | UINT8 *battery_ram, *ptr; |
| 182 | 162 | |
| 183 | | battery_ram = (UINT8*)malloc(0x20000); |
| 184 | | ptr = battery_ram; |
| 185 | | |
| 186 | | if (state->m_cart[0].slot_in_use) |
| 163 | if (state->m_cart[0].slot_in_use && state->m_cart[0].m_nvram_size) |
| 187 | 164 | { |
| 188 | | for (ii = 0; ii < 4; ii++) |
| 189 | | { |
| 190 | | memmove(ptr + ii * 0x8000, &snes_ram[0x608000 + (ii * 0x010000)], 0x8000); |
| 191 | | } |
| 192 | 165 | device_image_interface *image = dynamic_cast<device_image_interface *>(machine.device("slot_a")); |
| 193 | | image->battery_save(battery_ram, 0x20000); |
| 166 | image->battery_save(state->m_cart[0].m_nvram, state->m_cart[0].m_nvram_size); |
| 194 | 167 | } |
| 195 | 168 | |
| 196 | | if (state->m_cart[1].slot_in_use) |
| 169 | if (state->m_cart[1].slot_in_use && state->m_cart[1].m_nvram_size) |
| 197 | 170 | { |
| 198 | | for (ii = 0; ii < 4; ii++) |
| 199 | | { |
| 200 | | memmove(ptr + ii * 0x8000, &snes_ram[0x708000 + (ii * 0x010000)], 0x8000); |
| 201 | | } |
| 202 | 171 | device_image_interface *image = dynamic_cast<device_image_interface *>(machine.device("slot_b")); |
| 203 | | image->battery_save(battery_ram, 0x20000); |
| 172 | image->battery_save(state->m_cart[1].m_nvram, state->m_cart[1].m_nvram_size); |
| 204 | 173 | } |
| 205 | | |
| 206 | | free(battery_ram); |
| 207 | 174 | } |
| 208 | 175 | |
| 209 | 176 | |
| r21698 | r21699 | |
| 594 | 561 | return supported_type; |
| 595 | 562 | } |
| 596 | 563 | |
| 597 | | static void snes_cart_log_info( running_machine &machine, UINT8* ROM, int total_blocks, int supported ) |
| 564 | static void snes_cart_log_info( running_machine &machine, UINT8* ROM, int supported ) |
| 598 | 565 | { |
| 599 | 566 | snes_state *state = machine.driver_data<snes_state>(); |
| 600 | 567 | device_image_interface *image = dynamic_cast<device_image_interface *>(machine.device("cart")); |
| r21698 | r21699 | |
| 602 | 569 | int i, company, has_ram = 0, has_sram = 0; |
| 603 | 570 | UINT32 offset = snes_skip_header(*image, state->m_cart_size); |
| 604 | 571 | UINT32 hilo_mode = snes_find_hilo_mode(*image, ROM, offset, 0); |
| 605 | | |
| 572 | |
| 606 | 573 | /* Company */ |
| 607 | 574 | for (i = 0; i < 2; i++) |
| 608 | 575 | company_id[i] = ROM[hilo_mode - 0x10 + i]; |
| r21698 | r21699 | |
| 631 | 598 | ((ROM[hilo_mode + 0x16] & 0xf) == 6)) |
| 632 | 599 | has_sram = 1; |
| 633 | 600 | |
| 601 | int total_blocks = (state->m_cart[0].m_rom_size - offset) / (state->m_cart[0].mode & 0xa5 ? 0x8000 : 0x10000); |
| 602 | |
| 634 | 603 | logerror( "ROM DETAILS\n" ); |
| 635 | 604 | logerror( "===========\n\n" ); |
| 636 | 605 | logerror( "\tTotal blocks: %d (%dmb)\n", total_blocks, total_blocks / (state->m_cart[0].mode & 5 ? 32 : 16) ); |
| r21698 | r21699 | |
| 662 | 631 | logerror( "\tVersion: 1.%d\n", ROM[hilo_mode + 0x1b] ); |
| 663 | 632 | logerror( "\tInv Checksum: %X %X\n", ROM[hilo_mode + 0x1d], ROM[hilo_mode + 0x1c] ); |
| 664 | 633 | logerror( "\tChecksum: %X %X\n", ROM[hilo_mode + 0x1f], ROM[hilo_mode + 0x1e] ); |
| 665 | | logerror( "\tNMI Address: %2X%2Xh\n", ROM[hilo_mode + 0x3b], ROM[hilo_mode + 0x3a]); |
| 666 | | logerror( "\tStart Address: %2X%2Xh\n\n", ROM[hilo_mode + 0x3d], ROM[hilo_mode + 0x3c]); |
| 634 | logerror( "\tNMI Address: %2X%2Xh\n", ROM[hilo_mode + 0x3b], ROM[hilo_mode + 0x3a] ); |
| 635 | logerror( "\tStart Address: %2X%2Xh\n\n", ROM[hilo_mode + 0x3d], ROM[hilo_mode + 0x3c] ); |
| 667 | 636 | |
| 668 | 637 | logerror( "\tMode: %d\n", state->m_cart[0].mode); |
| 669 | 638 | |
| r21698 | r21699 | |
| 675 | 644 | { |
| 676 | 645 | int supported_type = 1; |
| 677 | 646 | running_machine &machine = image.device().machine(); |
| 678 | | int total_blocks, read_blocks, has_bsx_slot = 0, st_bios = 0; |
| 647 | int has_bsx_slot = 0, st_bios = 0; |
| 679 | 648 | UINT32 offset, int_header_offs; |
| 680 | 649 | UINT8 *ROM = memregion("cart")->base(); |
| 681 | 650 | |
| r21698 | r21699 | |
| 700 | 669 | m_cart[0].m_rom_size = m_cart_size; |
| 701 | 670 | m_cart[0].m_rom = auto_alloc_array_clear(machine, UINT8, m_cart[0].m_rom_size); |
| 702 | 671 | memcpy(m_cart[0].m_rom, ROM, m_cart[0].m_rom_size - offset); |
| 672 | rom_map_setup(m_cart[0].m_rom_size); |
| 703 | 673 | |
| 704 | 674 | /* First, look if the cart is HiROM or LoROM (and set snes_cart accordingly) */ |
| 705 | 675 | int_header_offs = snes_find_hilo_mode(image, ROM, offset, 0); |
| r21698 | r21699 | |
| 760 | 730 | |
| 761 | 731 | if (SNES_CART_DEBUG) mame_printf_error("mode %d\n", m_cart[0].mode); |
| 762 | 732 | |
| 763 | | /* FIXME: Insert crc check here? */ |
| 764 | | |
| 765 | | /* How many blocks of data are available to be loaded? */ |
| 766 | | total_blocks = ((m_cart_size - offset) / (m_cart[0].mode & 0xa5 ? 0x8000 : 0x10000)); |
| 767 | | read_blocks = 0; |
| 768 | | |
| 769 | | if (SNES_CART_DEBUG) mame_printf_error("blocks %d\n", total_blocks); |
| 770 | | |
| 771 | | /* Loading all the data blocks from cart, we only partially cover banks 0x00 to 0x7f. Therefore, we |
| 772 | | * have to mirror the blocks until we reach the end. E.g. for a 11Mbits image (44 blocks), we proceed |
| 773 | | * as follows: |
| 774 | | * 11 Mbits = 8 Mbits (blocks 1->32) + 2 Mbits (blocks 33->40) + 1 Mbit (blocks 41->44). |
| 775 | | * Hence, we fill memory up to 16 Mbits (banks 0x00 to 0x3f) mirroring as follows |
| 776 | | * 8 Mbits (blocks 1->32) + 2 Mbits (blocks 33->40) + 1 Mbit (blocks 41->44) + 1 Mbit (blocks 41->44) |
| 777 | | * + 2 Mbits (blocks 33->40) + 1 Mbit (blocks 41->44) + 1 Mbit (blocks 41->44) |
| 778 | | * and we repeat the same blocks in the second half of the banks (banks 0x40 to 0x7f). |
| 779 | | * This is likely what happens in the real SNES as well, because the unit cannot be aware of the exact |
| 780 | | * size of data in the cart (procedure confirmed by byuu) |
| 781 | | */ |
| 782 | | switch (m_cart[0].mode) |
| 783 | | { |
| 784 | | case SNES_MODE_21: |
| 785 | | /* HiROM carts load data in banks 0xc0 to 0xff. Each bank is fully mirrored in banks 0x40 to 0x7f |
| 786 | | * (actually up to 0x7d, because 0x7e and 0x7f are overwritten by WRAM). The top half (address |
| 787 | | * range 0x8000 - 0xffff) of each bank is also mirrored in banks 0x00 to 0x3f and 0x80 to 0xbf. |
| 788 | | */ |
| 789 | | /* SPC7110 games needs this different loading routine */ |
| 790 | | if ((ROM[0x00ffd6] == 0xf9 || ROM[0x00ffd6] == 0xf5) && (ROM[0x00ffd5] == 0x3a)) |
| 791 | | { |
| 792 | | while (read_blocks < 16 && read_blocks < total_blocks) |
| 793 | | { |
| 794 | | /* Loading data */ |
| 795 | | memcpy(&snes_ram[0xc00000 + read_blocks * 0x10000], &ROM[0x000000 + read_blocks * 0x10000], 0x10000); |
| 796 | | /* Mirroring */ |
| 797 | | memcpy(&snes_ram[0x008000 + read_blocks * 0x10000], &snes_ram[0xc08000 + read_blocks * 0x10000], 0x8000); |
| 798 | | memcpy(&snes_ram[0x808000 + read_blocks * 0x10000], &snes_ram[0xc08000 + read_blocks * 0x10000], 0x8000); |
| 799 | | read_blocks++; |
| 800 | | } |
| 801 | | } |
| 802 | | else |
| 803 | | { |
| 804 | | while (read_blocks < 64 && read_blocks < total_blocks) |
| 805 | | { |
| 806 | | /* Loading data */ |
| 807 | | memcpy(&snes_ram[0xc00000 + read_blocks * 0x10000], &ROM[0x000000 + read_blocks * 0x10000], 0x10000); |
| 808 | | /* Mirroring */ |
| 809 | | memcpy(&snes_ram[0x008000 + read_blocks * 0x10000], &snes_ram[0xc08000 + read_blocks * 0x10000], 0x8000); |
| 810 | | memcpy(&snes_ram[0x400000 + read_blocks * 0x10000], &snes_ram[0xc00000 + read_blocks * 0x10000], 0x10000); |
| 811 | | memcpy(&snes_ram[0x808000 + read_blocks * 0x10000], &snes_ram[0xc08000 + read_blocks * 0x10000], 0x8000); |
| 812 | | read_blocks++; |
| 813 | | } |
| 814 | | /* Filling banks up to 0xff and their mirrors */ |
| 815 | | while (read_blocks % 64) |
| 816 | | { |
| 817 | | int j = 0, repeat_blocks; |
| 818 | | while ((read_blocks % (64 >> j)) && j < 6) |
| 819 | | j++; |
| 820 | | repeat_blocks = read_blocks % (64 >> (j - 1)); |
| 821 | | |
| 822 | | memcpy(&snes_ram[0xc00000 + read_blocks * 0x10000], &snes_ram[0xc00000 + (read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000); |
| 823 | | memcpy(&snes_ram[read_blocks * 0x10000], &snes_ram[(read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000); |
| 824 | | memcpy(&snes_ram[0x400000 + read_blocks * 0x10000], &snes_ram[0x400000 + (read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000); |
| 825 | | memcpy(&snes_ram[0x800000 + read_blocks * 0x10000], &snes_ram[0x800000 + (read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000); |
| 826 | | read_blocks += repeat_blocks; |
| 827 | | } |
| 828 | | } |
| 829 | | break; |
| 830 | | |
| 831 | | case SNES_MODE_25: |
| 832 | | /* Extendend HiROM carts start to load data in banks 0xc0 to 0xff. However, they exceed the |
| 833 | | * available space in these banks, and continue loading at banks 0x40 to 0x7f. The top half |
| 834 | | * (address range 0x8000 - 0xffff) of each bank is also mirrored either to banks 0x00 to 0x3f |
| 835 | | * (for data in banks 0x40 to 0x7f) or to banks 0x80 to 0xbf (for data in banks 0xc0 to 0xff). |
| 836 | | * Notice that banks 0x7e and 0x7f are overwritten by WRAM, but they could contain data at |
| 837 | | * address > 0x8000 because the mirrors at 0x3e and 0x3f are not overwritten. |
| 838 | | */ |
| 839 | | /* Reading the first 64 blocks */ |
| 840 | | while (read_blocks < 64 && read_blocks < total_blocks) |
| 841 | | { |
| 842 | | /* Loading data */ |
| 843 | | memcpy(&snes_ram[0xc00000 + read_blocks * 0x10000], &ROM[0x000000 + read_blocks * 0x10000], 0x10000); |
| 844 | | /* Mirroring */ |
| 845 | | memcpy(&snes_ram[0x808000 + read_blocks * 0x10000], &snes_ram[0xc08000 + read_blocks * 0x10000], 0x8000); |
| 846 | | read_blocks++; |
| 847 | | } |
| 848 | | /* ExHiROMs are supposed to be larger than 32Mbits! */ |
| 849 | | if (read_blocks < 64) |
| 850 | | { |
| 851 | | logerror("This image has been identified as ExHiROM, but it's too small!\n"); |
| 852 | | logerror("Please verify if it's corrupted. If it's not please report this as a bug.\n"); |
| 853 | | return IMAGE_INIT_FAIL; |
| 854 | | } |
| 855 | | /* Scaling down the counter */ |
| 856 | | read_blocks -= 64; |
| 857 | | /* Reading the next blocks */ |
| 858 | | while (read_blocks < 64 && read_blocks < (total_blocks - 64)) |
| 859 | | { |
| 860 | | /* Loading data */ |
| 861 | | memcpy(&snes_ram[0x400000 + read_blocks * 0x10000], &ROM[0x400000 + read_blocks * 0x10000], 0x10000); |
| 862 | | /* Mirroring */ |
| 863 | | memcpy(&snes_ram[0x8000 + read_blocks * 0x10000], &snes_ram[0x408000 + read_blocks * 0x10000], 0x8000); |
| 864 | | read_blocks++; |
| 865 | | } |
| 866 | | /* Filling banks up to 0x7f and their mirrors */ |
| 867 | | while (read_blocks % 64) |
| 868 | | { |
| 869 | | int j = 0, repeat_blocks; |
| 870 | | while ((read_blocks % (64 >> j)) && j < 6) |
| 871 | | j++; |
| 872 | | repeat_blocks = read_blocks % (64 >> (j - 1)); |
| 873 | | |
| 874 | | memcpy(&snes_ram[0x400000 + read_blocks * 0x10000], &snes_ram[0x400000 + (read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000); |
| 875 | | memcpy(&snes_ram[read_blocks * 0x10000], &snes_ram[(read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000); |
| 876 | | read_blocks += repeat_blocks; |
| 877 | | } |
| 878 | | break; |
| 879 | | |
| 880 | | case SNES_MODE_22: |
| 881 | | /* "Extendend LoROM" carts have their data loaded in banks 0x00 to 0x3f at address 0x8000. |
| 882 | | * These are then mirrored in banks 0x40 to 0x7f, both at address 0x0000 and at address |
| 883 | | * 0x8000, in banks 0x80 to 0xbf at address 0x8000 and in banks 0xc0 to 0xff, both at address |
| 884 | | * 0x0000 and at address 0x8000. Notice that SDD-1 games (Star Ocean and Street Fighter Zero 2) |
| 885 | | * use SNES_MODE_22 |
| 886 | | */ |
| 887 | | while (read_blocks < 64 && read_blocks < total_blocks) |
| 888 | | { |
| 889 | | /* Loading and mirroring data */ |
| 890 | | memcpy(&snes_ram[0x008000 + read_blocks * 0x10000], &ROM[0x000000 + read_blocks * 0x8000], 0x8000); |
| 891 | | memcpy(&snes_ram[0x808000 + read_blocks * 0x10000], &ROM[0x000000 + read_blocks * 0x8000], 0x8000); |
| 892 | | memcpy(&snes_ram[0x400000 + read_blocks * 0x10000], &ROM[0x000000 + read_blocks * 0x10000], 0x10000); |
| 893 | | memcpy(&snes_ram[0xc00000 + read_blocks * 0x10000], &ROM[0x000000 + read_blocks * 0x10000], 0x10000); |
| 894 | | read_blocks++; |
| 895 | | } |
| 896 | | /* Filling banks up to 0x3f and their mirrors */ |
| 897 | | while (read_blocks % 64) |
| 898 | | { |
| 899 | | int j = 0, repeat_blocks; |
| 900 | | while ((read_blocks % (64 >> j)) && j < 6) |
| 901 | | j++; |
| 902 | | repeat_blocks = read_blocks % (64 >> (j - 1)); |
| 903 | | |
| 904 | | memcpy(&snes_ram[read_blocks * 0x10000], &snes_ram[(read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000); |
| 905 | | memcpy(&snes_ram[0x800000 + read_blocks * 0x10000], &snes_ram[0x800000 + (read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000); |
| 906 | | memcpy(&snes_ram[0x400000 + read_blocks * 0x10000], &snes_ram[0x400000 + (read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000); |
| 907 | | memcpy(&snes_ram[0xc00000 + read_blocks * 0x10000], &snes_ram[0xc00000 + (read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000); |
| 908 | | read_blocks += repeat_blocks; |
| 909 | | } |
| 910 | | break; |
| 911 | | |
| 912 | | case SNES_MODE_ST: |
| 913 | | if (!st_bios) |
| 914 | | { |
| 915 | | mame_printf_error("This is a Sufami Turbo data cart and cannot be loaded for snes/snespal in MESS.\n"); |
| 916 | | mame_printf_error("Please use snesst driver to load it, instead.\n"); |
| 917 | | return IMAGE_INIT_FAIL; |
| 918 | | } |
| 919 | | else |
| 920 | | { |
| 921 | | // The Base ST cart consists of 8 * 0x8000 block which have to be loaded (and mirrored) |
| 922 | | // at 0x00-0x1f:0x8000-0xffff and 0x80-0x9f:0x8000-0xffff |
| 923 | | int i = 0; |
| 924 | | for (i = 0; i < 8; i++) |
| 925 | | { |
| 926 | | /* Loading data */ |
| 927 | | memcpy(&snes_ram[0x008000 + i * 0x10000], &ROM[0x000000 + i * 0x8000], 0x8000); |
| 928 | | /* Mirroring */ |
| 929 | | memcpy(&snes_ram[0x808000 + i * 0x10000], &snes_ram[0x8000 + (i * 0x10000)], 0x8000); |
| 930 | | |
| 931 | | /* Additional mirrors (to fill snes_ram up to 0x1fffff) */ |
| 932 | | int j = 0; |
| 933 | | for (j = 1; j < 4; j++) |
| 934 | | { |
| 935 | | memcpy(&snes_ram[0x008000 + i * 0x10000 + j * 0x80000], &snes_ram[0x8000 + (i * 0x10000)], 0x8000); |
| 936 | | memcpy(&snes_ram[0x808000 + i * 0x10000 + j * 0x80000], &snes_ram[0x8000 + (i * 0x10000)], 0x8000); |
| 937 | | } |
| 938 | | } |
| 939 | | } |
| 940 | | break; |
| 941 | | |
| 942 | | case SNES_MODE_BSX: |
| 943 | | case SNES_MODE_BSLO: |
| 944 | | case SNES_MODE_BSHI: |
| 945 | | /* not handled yet */ |
| 946 | | mame_printf_error("This is a BS-X Satellaview image: MESS does not support these yet, sorry.\n"); |
| 947 | | /* so treat it like MODE_20 */ |
| 948 | | m_cart[0].mode = SNES_MODE_20; |
| 949 | | /* and load it as such... */ |
| 950 | | |
| 951 | | default: |
| 952 | | case SNES_MODE_20: |
| 953 | | /* LoROM carts load data in banks 0x00 to 0x7f at address 0x8000 (actually up to 0x7d, because 0x7e and |
| 954 | | * 0x7f are overwritten by WRAM). Each block is also mirrored in banks 0x80 to 0xff (up to 0xff for real) |
| 955 | | */ |
| 956 | | /* SuperFX games needs this different loading routine */ |
| 957 | | if (((ROM[0x007fd6] >= 0x13 && ROM[0x007fd6] <= 0x15) || ROM[0x007fd6] == 0x1a) && (ROM[0x007fd5] == 0x20)) |
| 958 | | { |
| 959 | | while (read_blocks < 64 && read_blocks < total_blocks) |
| 960 | | { |
| 961 | | /* Loading data primary: banks 0-3f from 8000-ffff*/ |
| 962 | | memcpy(&snes_ram[0x008000 + read_blocks * 0x10000], &ROM[0x000000 + read_blocks * 0x8000], 0x8000); |
| 963 | | /* Mirroring at banks 80-bf from 8000-ffff */ |
| 964 | | memcpy(&snes_ram[0x808000 + read_blocks * 0x10000], &snes_ram[0x8000 + (read_blocks * 0x10000)], 0x8000); |
| 965 | | /* Mirroring at banks 40-5f and c0-df */ |
| 966 | | memcpy(&snes_ram[0x400000 + read_blocks * 0x8000], &snes_ram[0x8000 + (read_blocks * 0x10000)], total_blocks * 0x8000); |
| 967 | | memcpy(&snes_ram[0xc00000 + read_blocks * 0x8000], &snes_ram[0x8000 + (read_blocks * 0x10000)], total_blocks * 0x8000); |
| 968 | | |
| 969 | | read_blocks++; |
| 970 | | } |
| 971 | | /* SuperFX games are supposed to contain 64 blocks! */ |
| 972 | | if (read_blocks < total_blocks) |
| 973 | | { |
| 974 | | logerror("This image has been identified as a SuperFX game, but it's too large!\n"); |
| 975 | | logerror("Please verify if it's corrupted. If it's not please report this as a bug.\n"); |
| 976 | | return IMAGE_INIT_FAIL; |
| 977 | | } |
| 978 | | } |
| 979 | | else |
| 980 | | { |
| 981 | | while (read_blocks < 128 && read_blocks < total_blocks) |
| 982 | | { |
| 983 | | /* Loading data */ |
| 984 | | memcpy(&snes_ram[0x008000 + read_blocks * 0x10000], &ROM[0x000000 + read_blocks * 0x8000], 0x8000); |
| 985 | | /* Mirroring */ |
| 986 | | memcpy(&snes_ram[0x808000 + read_blocks * 0x10000], &snes_ram[0x8000 + (read_blocks * 0x10000)], 0x8000); |
| 987 | | read_blocks++; |
| 988 | | } |
| 989 | | /* Filling banks up to 0x7f and their mirrors */ |
| 990 | | while (read_blocks % 128) |
| 991 | | { |
| 992 | | int j = 0, repeat_blocks; |
| 993 | | while ((read_blocks % (128 >> j)) && j < 7) |
| 994 | | j++; |
| 995 | | repeat_blocks = read_blocks % (128 >> (j - 1)); |
| 996 | | |
| 997 | | memcpy(&snes_ram[read_blocks * 0x10000], &snes_ram[(read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000); |
| 998 | | memcpy(&snes_ram[0x800000 + read_blocks * 0x10000], &snes_ram[(read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000); |
| 999 | | read_blocks += repeat_blocks; |
| 1000 | | } |
| 1001 | | } |
| 1002 | | break; |
| 1003 | | } |
| 1004 | | |
| 1005 | 733 | /* Detect special chips */ |
| 1006 | 734 | supported_type = snes_find_addon_chip(machine, ROM, int_header_offs); |
| 1007 | 735 | |
| r21698 | r21699 | |
| 1013 | 741 | if ((m_has_addon_chip != HAS_SUPERFX)) |
| 1014 | 742 | nvram_size = ROM[int_header_offs + 0x18]; |
| 1015 | 743 | else |
| 1016 | | nvram_size = (ROM[0x00ffbd] & 0x07); |
| 744 | nvram_size = (ROM[0x007fbd] & 0x07); |
| 1017 | 745 | |
| 1018 | 746 | if (nvram_size > 0) |
| 1019 | 747 | { |
| r21698 | r21699 | |
| 1044 | 772 | m_cart[0].m_nvram = auto_alloc_array_clear(machine, UINT8, m_cart[0].m_nvram_size); |
| 1045 | 773 | |
| 1046 | 774 | /* Log snes_cart information */ |
| 1047 | | snes_cart_log_info(machine, ROM, total_blocks, supported_type); |
| 775 | snes_cart_log_info(machine, ROM, supported_type); |
| 1048 | 776 | |
| 1049 | 777 | /* Load SRAM */ |
| 1050 | 778 | if (m_cart[0].m_nvram_size > 0) |
| r21698 | r21699 | |
| 1057 | 785 | DEVICE_IMAGE_LOAD_MEMBER( snes_state,sufami_cart ) |
| 1058 | 786 | { |
| 1059 | 787 | running_machine &machine = image.device().machine(); |
| 1060 | | int total_blocks, read_blocks; |
| 1061 | 788 | int st_bios = 0, slot_id = 0; |
| 1062 | | UINT32 offset, st_data_offset = 0; |
| 789 | UINT32 offset; |
| 1063 | 790 | UINT8 *ROM = image.device().machine().root_device().memregion(image.device().tag())->base(); |
| 1064 | 791 | |
| 1065 | | snes_ram = memregion("maincpu")->base(); |
| 1066 | | |
| 1067 | 792 | if (strcmp(image.device().tag(), ":slot_a") == 0) |
| 1068 | | { |
| 1069 | | st_data_offset = 0x200000; |
| 1070 | 793 | slot_id = 0; |
| 1071 | | } |
| 1072 | 794 | |
| 1073 | 795 | if (strcmp(image.device().tag(), ":slot_b") == 0) |
| 1074 | | { |
| 1075 | | st_data_offset = 0x400000; |
| 1076 | 796 | slot_id = 1; |
| 1077 | | } |
| 1078 | 797 | |
| 1079 | 798 | if (image.software_entry() == NULL) |
| 1080 | 799 | m_cart_size = image.length(); |
| r21698 | r21699 | |
| 1115 | 834 | return IMAGE_INIT_FAIL; |
| 1116 | 835 | } |
| 1117 | 836 | |
| 1118 | | /* FIXME: Insert crc check here? */ |
| 1119 | 837 | |
| 1120 | | /* How many blocks of data are available to be loaded? */ |
| 1121 | | total_blocks = (m_cart_size - offset) / 0x8000; |
| 1122 | | read_blocks = 0; |
| 838 | m_cart[slot_id].m_rom_size = m_cart_size; |
| 839 | m_cart[slot_id].m_rom = auto_alloc_array_clear(machine, UINT8, m_cart[0].m_rom_size); |
| 840 | memcpy(m_cart[slot_id].m_rom, ROM, m_cart[slot_id].m_rom_size - offset); |
| 841 | rom_map_setup(m_cart[slot_id].m_rom_size); |
| 1123 | 842 | |
| 1124 | | if (SNES_CART_DEBUG) |
| 1125 | | mame_printf_error("blocks %d\n", total_blocks); |
| 843 | m_cart[slot_id].m_nvram_size = 0x20000; |
| 844 | m_cart[slot_id].m_nvram = auto_alloc_array_clear(machine, UINT8, m_cart[slot_id].m_nvram_size); |
| 1126 | 845 | |
| 1127 | | // actually load the cart |
| 1128 | | while (read_blocks < 32 && read_blocks < total_blocks) |
| 1129 | | { |
| 1130 | | /* Loading data */ |
| 1131 | | // CART (either A or B) |
| 1132 | | memcpy(&snes_ram[0x008000 + st_data_offset + read_blocks * 0x10000], &ROM[0x000000 + read_blocks * 0x8000], 0x8000); |
| 1133 | | /* Mirroring */ |
| 1134 | | memcpy(&snes_ram[0x808000 + st_data_offset + read_blocks * 0x10000], &snes_ram[0x8000 + st_data_offset + (read_blocks * 0x10000)], 0x8000); |
| 1135 | | |
| 1136 | | read_blocks++; |
| 1137 | | } |
| 1138 | | |
| 1139 | | /* Filling banks up to 0x1f and their mirrors */ |
| 1140 | | while (read_blocks % 32) |
| 1141 | | { |
| 1142 | | int j = 0, repeat_blocks; |
| 1143 | | while ((read_blocks % (32 >> j)) && j < 5) |
| 1144 | | j++; |
| 1145 | | repeat_blocks = read_blocks % (32 >> (j - 1)); |
| 1146 | | |
| 1147 | | memcpy(&snes_ram[st_data_offset + read_blocks * 0x10000], &snes_ram[st_data_offset + (read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000); |
| 1148 | | memcpy(&snes_ram[0x800000 + st_data_offset + read_blocks * 0x10000], &snes_ram[st_data_offset + (read_blocks - repeat_blocks) * 0x10000], repeat_blocks * 0x10000); |
| 1149 | | read_blocks += repeat_blocks; |
| 1150 | | } |
| 1151 | | |
| 1152 | | // currently we still use snes_ram for STROM ram... |
| 1153 | | // m_cart[slot_id].m_nvram_size = 0x20000; |
| 1154 | | // m_cart[slot_id].m_nvram = auto_alloc_array_clear(machine, UINT8, m_cart[slot_id].m_nvram_size); |
| 1155 | | m_cart[slot_id].m_nvram_size = 0; |
| 1156 | | |
| 1157 | 846 | sufami_load_sram(machine, image.device().tag()); |
| 1158 | 847 | |
| 1159 | 848 | m_cart[slot_id].slot_in_use = 1; // aknowledge the cart in this slot, for saving sram at exit |
| 1160 | 849 | |
| 1161 | | auto_free(image.device().machine(), ROM); |
| 1162 | | |
| 1163 | 850 | return IMAGE_INIT_PASS; |
| 1164 | 851 | } |
| 1165 | 852 | |
| r21698 | r21699 | |
| 1212 | 899 | |
| 1213 | 900 | DRIVER_INIT_MEMBER(snes_state,snesst) |
| 1214 | 901 | { |
| 1215 | | UINT8 *STBIOS = memregion("sufami")->base(); |
| 1216 | | int i, j; |
| 1217 | | |
| 1218 | 902 | m_cart[0].slot_in_use = 0; |
| 1219 | 903 | m_cart[1].slot_in_use = 0; |
| 1220 | 904 | |
| 1221 | 905 | DRIVER_INIT_CALL(snes_mess); |
| 1222 | | |
| 1223 | | // the Base ST cart consists of 8 * 0x8000 block which have to be loaded (and mirrored) |
| 1224 | | // at 0x00-0x1f:0x8000-0xffff and 0x80-0x9f:0x8000-0xffff |
| 1225 | | for (i = 0; i < 8; i++) |
| 1226 | | { |
| 1227 | | /* Loading data */ |
| 1228 | | memcpy(&snes_ram[0x008000 + i * 0x10000], &STBIOS[0x000000 + i * 0x8000], 0x8000); |
| 1229 | | /* Mirroring */ |
| 1230 | | memcpy(&snes_ram[0x808000 + i * 0x10000], &snes_ram[0x8000 + (i * 0x10000)], 0x8000); |
| 1231 | | |
| 1232 | | /* Additional mirrors (to fill snes_ram up to 0x1fffff) */ |
| 1233 | | for (j = 1; j < 4; j++) |
| 1234 | | { |
| 1235 | | memcpy(&snes_ram[0x008000 + i * 0x10000 + j * 0x80000], &snes_ram[0x8000 + (i * 0x10000)], 0x8000); |
| 1236 | | memcpy(&snes_ram[0x808000 + i * 0x10000 + j * 0x80000], &snes_ram[0x8000 + (i * 0x10000)], 0x8000); |
| 1237 | | } |
| 1238 | | } |
| 1239 | | |
| 1240 | 906 | } |
| 1241 | 907 | |
| 1242 | 908 | // add-on chip emulators |