trunk/src/mess/machine/snescart.c
| r21747 | r21748 | |
| 330 | 330 | /* This determines if a cart is in Mode 20, 21, 22 or 25; sets state->m_cart[0].mode and |
| 331 | 331 | state->m_cart[0].sram_max accordingly; and returns the offset of the internal header |
| 332 | 332 | (needed to detect BSX and ST carts) */ |
| 333 | | static UINT32 snes_find_hilo_mode( device_image_interface &image, UINT8 *buffer, UINT32 len, UINT32 offset, int cartid ) |
| 333 | static UINT32 snes_find_hilo_mode( device_image_interface &image, UINT8 *buffer, UINT32 len, int cartid ) |
| 334 | 334 | { |
| 335 | 335 | snes_state *state = image.device().machine().driver_data<snes_state>(); |
| 336 | 336 | UINT8 valid_mode20, valid_mode21, valid_mode25; |
| r21747 | r21748 | |
| 347 | 347 | |
| 348 | 348 | if ((valid_mode20 >= valid_mode21) && (valid_mode20 >= valid_mode25)) |
| 349 | 349 | { |
| 350 | | if ((buffer[0x007fd5] == 0x32) || ((state->m_cart_size - offset) > 0x401000)) |
| 350 | if (buffer[0x007fd5] == 0x32 || len > 0x401000) |
| 351 | 351 | state->m_cart[cartid].mode = SNES_MODE_22; // ExLoRom |
| 352 | 352 | else |
| 353 | 353 | state->m_cart[cartid].mode = SNES_MODE_20; // LoRom |
| r21747 | r21748 | |
| 567 | 567 | device_image_interface *image = dynamic_cast<device_image_interface *>(machine.device("cart")); |
| 568 | 568 | char title[21], rom_id[4], company_id[2]; |
| 569 | 569 | int i, company, has_ram = 0, has_sram = 0; |
| 570 | | UINT32 offset = snes_skip_header(*image, state->m_cart_size); |
| 571 | | UINT32 hilo_mode = snes_find_hilo_mode(*image, ROM, len, offset, 0); |
| 570 | UINT32 hilo_mode = snes_find_hilo_mode(*image, ROM, len, 0); |
| 572 | 571 | |
| 573 | 572 | /* Company */ |
| 574 | 573 | for (i = 0; i < 2; i++) |
| r21747 | r21748 | |
| 598 | 597 | ((ROM[hilo_mode + 0x16] & 0xf) == 6)) |
| 599 | 598 | has_sram = 1; |
| 600 | 599 | |
| 601 | | int total_blocks = (state->m_cart[0].m_rom_size - offset) / (state->m_cart[0].mode & 0xa5 ? 0x8000 : 0x10000); |
| 600 | int total_blocks = len / (state->m_cart[0].mode & 0xa5 ? 0x8000 : 0x10000); |
| 602 | 601 | |
| 603 | 602 | logerror( "ROM DETAILS\n" ); |
| 604 | 603 | logerror( "===========\n\n" ); |
| r21747 | r21748 | |
| 647 | 646 | UINT32 offset, int_header_offs; |
| 648 | 647 | |
| 649 | 648 | if (image.software_entry() == NULL) |
| 650 | | m_cart_size = image.length(); |
| 649 | m_cart[0].m_rom_size = image.length(); |
| 651 | 650 | else |
| 652 | | m_cart_size = image.get_software_region_length("rom"); |
| 651 | m_cart[0].m_rom_size = image.get_software_region_length("rom"); |
| 653 | 652 | |
| 654 | 653 | // Check for a header (512 bytes), and skip it if found |
| 655 | | offset = snes_skip_header(image, m_cart_size); |
| 654 | offset = snes_skip_header(image, m_cart[0].m_rom_size); |
| 655 | m_cart[0].m_rom_size -= offset; |
| 656 | 656 | |
| 657 | 657 | // Allocate rom pointer |
| 658 | | m_cart[0].m_rom_size = m_cart_size - offset; |
| 659 | 658 | m_cart[0].m_rom = auto_alloc_array_clear(machine(), UINT8, m_cart[0].m_rom_size); |
| 660 | 659 | |
| 661 | 660 | if (image.software_entry() == NULL) |
| 662 | 661 | { |
| 663 | 662 | image.fseek(offset, SEEK_SET); |
| 664 | | image.fread(m_cart[0].m_rom, m_cart_size - offset); |
| 663 | image.fread(m_cart[0].m_rom, m_cart[0].m_rom_size); |
| 665 | 664 | } |
| 666 | 665 | else |
| 667 | | memcpy(m_cart[0].m_rom, image.get_software_region("rom") + offset, m_cart_size - offset); |
| 666 | memcpy(m_cart[0].m_rom, image.get_software_region("rom") + offset, m_cart[0].m_rom_size); |
| 668 | 667 | |
| 669 | | if (SNES_CART_DEBUG) mame_printf_error("size %08X\n", m_cart_size - offset); |
| 668 | if (SNES_CART_DEBUG) mame_printf_error("size %08X\n", m_cart[0].m_rom_size); |
| 670 | 669 | |
| 671 | 670 | // Setup the bank map to handle mirroring of ROM up to 8MB of accessible memory |
| 672 | 671 | rom_map_setup(m_cart[0].m_rom_size); |
| 673 | 672 | |
| 674 | 673 | // Check if the cart is HiROM or LoROM (and set variables accordingly) |
| 675 | | int_header_offs = snes_find_hilo_mode(image, m_cart[0].m_rom, m_cart[0].m_rom_size, offset, 0); |
| 674 | int_header_offs = snes_find_hilo_mode(image, m_cart[0].m_rom, m_cart[0].m_rom_size, 0); |
| 676 | 675 | |
| 677 | 676 | // Detect BS-X carts: |
| 678 | 677 | // 1. Detect BS-X Flash Cart |
| r21747 | r21748 | |
| 803 | 802 | slot_id = 1; |
| 804 | 803 | |
| 805 | 804 | if (image.software_entry() == NULL) |
| 806 | | m_cart_size = image.length(); |
| 805 | m_cart[slot_id].m_rom_size = image.length(); |
| 807 | 806 | else |
| 808 | | m_cart_size = image.get_software_region_length("rom"); |
| 807 | m_cart[slot_id].m_rom_size = image.get_software_region_length("rom"); |
| 809 | 808 | |
| 810 | 809 | // Check for a header (512 bytes), and skip it if found |
| 811 | | offset = snes_skip_header(image, m_cart_size); |
| 810 | offset = snes_skip_header(image, m_cart[slot_id].m_rom_size); |
| 811 | m_cart[slot_id].m_rom_size -= offset; |
| 812 | 812 | |
| 813 | 813 | // Allocate rom pointer |
| 814 | | m_cart[slot_id].m_rom_size = m_cart_size; |
| 815 | 814 | m_cart[slot_id].m_rom = auto_alloc_array_clear(machine(), UINT8, m_cart[slot_id].m_rom_size); |
| 816 | 815 | |
| 817 | 816 | if (image.software_entry() == NULL) |
| 818 | 817 | { |
| 819 | 818 | image.fseek(offset, SEEK_SET); |
| 820 | | image.fread(m_cart[slot_id].m_rom, m_cart_size - offset); |
| 819 | image.fread(m_cart[slot_id].m_rom, m_cart[slot_id].m_rom_size); |
| 821 | 820 | } |
| 822 | 821 | else |
| 823 | | memcpy(m_cart[slot_id].m_rom, image.get_software_region("rom") + offset, m_cart_size - offset); |
| 822 | memcpy(m_cart[slot_id].m_rom, image.get_software_region("rom") + offset, m_cart[slot_id].m_rom_size); |
| 824 | 823 | |
| 825 | | if (SNES_CART_DEBUG) mame_printf_error("size %08X\n", m_cart_size - offset); |
| 824 | if (SNES_CART_DEBUG) mame_printf_error("size %08X\n", m_cart[slot_id].m_rom_size); |
| 826 | 825 | |
| 827 | 826 | // Setup the bank map to handle mirroring of ROM |
| 828 | 827 | rom_map_setup(m_cart[slot_id].m_rom_size); |