src/mame/machine/snes.c
| r5806 | r5807 | |
| 6 | 6 | |
| 7 | 7 | R. Belmont |
| 8 | 8 | Anthony Kruize |
| 9 | Harmony |
| 9 | 10 | Based on the original code by Lee Hammerton (aka Savoury Snax) |
| 10 | 11 | Thanks to Anomie for invaluable technical information. |
| 11 | 12 | Thanks to byuu for invaluable technical information. |
| r5806 | r5807 | |
| 38 | 39 | static UINT16 hblank_offset; |
| 39 | 40 | UINT16 snes_htmult; /* in 512 wide, we run HTOTAL double and halve it on latching */ |
| 40 | 41 | UINT8 snes_has_addon_chip; |
| 42 | UINT32 snes_rom_size; |
| 41 | 43 | |
| 42 | 44 | // full graphic variables |
| 43 | 45 | static UINT16 vram_fgr_high, vram_fgr_increment, vram_fgr_count, vram_fgr_mask, vram_fgr_shift, vram_read_buffer; |
| r5806 | r5807 | |
| 64 | 66 | #include "machine/snescx4.c" |
| 65 | 67 | #include "machine/snesrtc.c" |
| 66 | 68 | #include "machine/snessdd1.c" |
| 69 | #include "machine/snes7110.c" |
| 70 | #include "machine/snesst10.c" |
| 67 | 71 | |
| 68 | 72 | /************************************* |
| 69 | 73 | |
| r5806 | r5807 | |
| 379 | 383 | offset += 0x4300; |
| 380 | 384 | } |
| 381 | 385 | } |
| 386 | else if(snes_has_addon_chip == HAS_SPC7110 || snes_has_addon_chip == HAS_SPC7110_RTC) |
| 387 | { |
| 388 | UINT16 limit = (snes_has_addon_chip == HAS_SPC7110_RTC) ? 0x4842 : 0x483f; |
| 389 | if(offset >= 0x4800 && offset < limit) |
| 390 | { |
| 391 | return spc7110_mmio_read(space->machine, offset); |
| 392 | } |
| 393 | } |
| 382 | 394 | |
| 383 | 395 | /* offset is from 0x000000 */ |
| 384 | 396 | switch( offset ) |
| r5806 | r5807 | |
| 750 | 762 | offset += 0x4300; |
| 751 | 763 | } |
| 752 | 764 | } |
| 765 | else if(snes_has_addon_chip == HAS_SPC7110 || snes_has_addon_chip == HAS_SPC7110_RTC) |
| 766 | { |
| 767 | UINT16 limit = (snes_has_addon_chip == HAS_SPC7110_RTC) ? 0x4842 : 0x483f; |
| 768 | if(offset >= 0x4800 && offset < limit) |
| 769 | { |
| 770 | spc7110_mmio_write(space->machine, (UINT32)offset, data); |
| 771 | return; |
| 772 | } |
| 773 | } |
| 753 | 774 | |
| 754 | 775 | /* offset is from 0x000000 */ |
| 755 | 776 | switch( offset ) |
| r5806 | r5807 | |
| 1470 | 1491 | value = (address < 0x7000) ? DSP1_getDr() : DSP1_getSr(); |
| 1471 | 1492 | else if (snes_has_addon_chip == HAS_CX4) |
| 1472 | 1493 | value = CX4_read(address - 0x6000); |
| 1494 | else if (snes_has_addon_chip == HAS_SPC7110 || snes_has_addon_chip == HAS_SPC7110_RTC) |
| 1495 | { |
| 1496 | value = snes_ram[0x306000 + (offset & 0x1fff)]; |
| 1497 | } |
| 1473 | 1498 | else |
| 1474 | 1499 | { |
| 1475 | 1500 | logerror( "snes_r_bank1: Unmapped external chip read: %04x\n", address ); |
| r5806 | r5807 | |
| 1504 | 1529 | value = obc1_read (space, offset); |
| 1505 | 1530 | else if (snes_has_addon_chip == HAS_DSP2) |
| 1506 | 1531 | value = (address < 0x7000) ? DSP2_read() : 0x00; |
| 1532 | else if (snes_has_addon_chip == HAS_SPC7110 || snes_has_addon_chip == HAS_SPC7110_RTC) |
| 1533 | { |
| 1534 | value = snes_ram[0x306000 + (offset & 0x1fff)]; |
| 1535 | } |
| 1507 | 1536 | else if ((snes_cart.mode == SNES_MODE_21) && (snes_cart.sram > 0)) |
| 1508 | 1537 | { |
| 1509 | 1538 | int mask = ((snes_cart.sram * 1024) - 1); /* Limit SRAM size to what's actually present */ |
| r5806 | r5807 | |
| 1565 | 1594 | { |
| 1566 | 1595 | value = snes_ram[0x600000 + offset]; |
| 1567 | 1596 | } |
| 1597 | else if (snes_has_addon_chip == HAS_ST010 && offset >= 0x80000 && address < 0x1000) |
| 1598 | { |
| 1599 | value = st010_read(address); |
| 1600 | } |
| 1568 | 1601 | else if (snes_cart.mode & 5) /* Mode 20 & 22 */ |
| 1569 | 1602 | { |
| 1570 | 1603 | if (address >= 0x8000) |
| r5806 | r5807 | |
| 1627 | 1660 | logerror( "snes_r_bank6 hit in Super FX mode, please fix me\n" ); |
| 1628 | 1661 | else if (snes_cart.mode != SNES_MODE_25) |
| 1629 | 1662 | value = memory_read_byte(space, offset); |
| 1663 | else if (snes_has_addon_chip == HAS_CX4) |
| 1664 | { |
| 1665 | //printf( "R: CX4 hit from 0x800000\n" ); |
| 1666 | } |
| 1630 | 1667 | else /* Mode 25 has SRAM not mirrored from lower banks */ |
| 1631 | 1668 | { |
| 1632 | 1669 | if (address < 0x6000) |
| r5806 | r5807 | |
| 1672 | 1709 | { |
| 1673 | 1710 | logerror( "snes_r_bank7 hit in Super FX mode, please fix me\n" ); |
| 1674 | 1711 | } |
| 1712 | else if (snes_has_addon_chip == HAS_ST010 && offset >= 0x280000 && offset < 0x300000 && address < 0x1000) |
| 1713 | { |
| 1714 | value = st010_read(address); |
| 1715 | } |
| 1675 | 1716 | else if (snes_cart.mode & 5) /* Mode 20 & 22 */ |
| 1676 | 1717 | { |
| 1677 | 1718 | if (address < 0x8000) |
| r5806 | r5807 | |
| 1709 | 1750 | DSP1_setDr(data); |
| 1710 | 1751 | else if (snes_has_addon_chip == HAS_CX4) |
| 1711 | 1752 | CX4_write(space->machine, address - 0x6000, data); |
| 1753 | else if (snes_has_addon_chip == HAS_SPC7110 || snes_has_addon_chip == HAS_SPC7110_RTC) |
| 1754 | { |
| 1755 | snes_ram[0x306000 + (offset & 0x1fff)] = data; |
| 1756 | } |
| 1712 | 1757 | else |
| 1713 | 1758 | logerror( "snes_w_bank1: Attempt to write to reserved address: %x = %02x\n", offset, data ); |
| 1714 | 1759 | } |
| r5806 | r5807 | |
| 1737 | 1782 | obc1_write(space, offset, data); |
| 1738 | 1783 | else if (snes_has_addon_chip == HAS_DSP2) |
| 1739 | 1784 | DSP2_write(data); |
| 1785 | else if (snes_has_addon_chip == HAS_SPC7110 || snes_has_addon_chip == HAS_SPC7110_RTC) |
| 1786 | { |
| 1787 | snes_ram[0x306000 + (offset & 0x1fff)] = data; |
| 1788 | } |
| 1740 | 1789 | else if ((snes_cart.mode == SNES_MODE_21) && (snes_cart.sram > 0)) |
| 1741 | 1790 | { |
| 1742 | 1791 | int mask = ((snes_cart.sram * 1024) - 1); /* Limit SRAM size to what's actually present */ |
| r5806 | r5807 | |
| 1767 | 1816 | |
| 1768 | 1817 | if (snes_has_addon_chip == HAS_SUPERFX && cputag_get_cpu(space->machine, "superfx") != NULL) |
| 1769 | 1818 | { |
| 1770 | | //printf( "Writing %02x to %08x\n", data, 0x600000 + offset ); |
| 1771 | 1819 | snes_ram[0x600000 + offset] = data; |
| 1772 | 1820 | } |
| 1821 | else if (snes_has_addon_chip == HAS_ST010 && offset >= 0x80000 && address < 0x1000) |
| 1822 | { |
| 1823 | st010_write(address, data); |
| 1824 | } |
| 1773 | 1825 | else if (snes_cart.mode & 5) /* Mode 20 & 22 */ |
| 1774 | 1826 | { |
| 1775 | 1827 | if (address >= 0x8000) |
| r5806 | r5807 | |
| 1830 | 1882 | { |
| 1831 | 1883 | logerror( "snes_w_bank6 hit (RAM) in Super FX mode, please fix me\n" ); |
| 1832 | 1884 | } |
| 1885 | else if(snes_has_addon_chip == HAS_CX4) |
| 1886 | { |
| 1887 | //printf( "R: CX4 hit from 0x800000\n" ); |
| 1888 | } |
| 1833 | 1889 | if (snes_cart.mode != SNES_MODE_25) |
| 1834 | 1890 | { |
| 1835 | 1891 | if (offset < 0x300000) |
| r5806 | r5807 | |
| 1887 | 1943 | logerror( "snes_w_bank7 hit (RAM) in Super FX mode, please fix me\n" ); |
| 1888 | 1944 | } |
| 1889 | 1945 | } |
| 1946 | else if (snes_has_addon_chip == HAS_ST010 && offset >= 0x280000 && offset < 0x300000 && address < 0x1000) |
| 1947 | { |
| 1948 | st010_write(address, data); |
| 1949 | } |
| 1890 | 1950 | else if (snes_cart.mode & 5) /* Mode 20 & 22 */ |
| 1891 | 1951 | { |
| 1892 | 1952 | if (address < 0x8000) |
| r5806 | r5807 | |
| 1993 | 2053 | InitDSP4(); |
| 1994 | 2054 | break; |
| 1995 | 2055 | |
| 2056 | case HAS_RTC: |
| 2057 | srtc_reset(machine); |
| 2058 | break; |
| 2059 | |
| 2060 | case HAS_SDD1: |
| 2061 | sdd1_reset(machine); |
| 2062 | break; |
| 2063 | |
| 1996 | 2064 | case HAS_OBC1: |
| 1997 | 2065 | obc1_init(); |
| 1998 | 2066 | break; |
| 1999 | 2067 | |
| 2068 | case HAS_ST010: |
| 2069 | st010_reset(); |
| 2070 | break; |
| 2071 | |
| 2000 | 2072 | default: |
| 2001 | 2073 | break; |
| 2002 | 2074 | } |
| r5806 | r5807 | |
| 2059 | 2131 | snes_ram[WRDIVH] = 0xff; |
| 2060 | 2132 | |
| 2061 | 2133 | sdd1_init(machine); |
| 2134 | spc7110_init(machine); |
| 2135 | st010_init(machine); |
| 2062 | 2136 | } |
| 2063 | 2137 | |
| 2064 | 2138 | MACHINE_RESET( snes ) |
| r5806 | r5807 | |
| 2081 | 2155 | snes_htmult = 1; |
| 2082 | 2156 | snes_ppu.interlace = 1; |
| 2083 | 2157 | snes_ppu.obj_interlace = 1; |
| 2084 | | |
| 2085 | | srtc_reset(machine); |
| 2086 | | sdd1_reset(machine); |
| 2087 | 2158 | } |
| 2088 | 2159 | |
| 2089 | 2160 | |
| r5806 | r5807 | |
| 2095 | 2166 | UINT8 *rom; |
| 2096 | 2167 | |
| 2097 | 2168 | rom = memory_region(machine, "user3"); |
| 2098 | | snes_ram = auto_alloc_array(machine, UINT8, 0x1000000); |
| 2099 | | memset(snes_ram, 0, 0x1000000); |
| 2169 | snes_ram = auto_alloc_array(machine, UINT8, 0x1400000); |
| 2170 | memset(snes_ram, 0, 0x1400000); |
| 2100 | 2171 | |
| 2101 | 2172 | /* all NSS games seem to use MODE 20 */ |
| 2102 | 2173 | snes_cart.mode = SNES_MODE_20; |
| r5806 | r5807 | |
| 2161 | 2232 | UINT8 *rom; |
| 2162 | 2233 | |
| 2163 | 2234 | rom = memory_region(machine, "user3"); |
| 2164 | | snes_ram = auto_alloc_array(machine, UINT8, 0x1000000); |
| 2165 | | memset(snes_ram, 0, 0x1000000); |
| 2235 | snes_ram = auto_alloc_array(machine, UINT8, 0x1400000); |
| 2236 | memset(snes_ram, 0, 0x1400000); |
| 2166 | 2237 | |
| 2167 | 2238 | snes_cart.mode = SNES_MODE_21; |
| 2168 | 2239 | snes_cart.sram_max = 0x40000; |
src/mess/machine/snescart.c
| r5806 | r5807 | |
| 351 | 351 | snes_ram = memory_region(machine, "maincpu"); |
| 352 | 352 | memset( snes_ram, 0, 0x1000000 ); |
| 353 | 353 | |
| 354 | snes_rom_size = image_length(image); |
| 355 | |
| 354 | 356 | /* Check for a header (512 bytes) */ |
| 355 | 357 | offset = 512; |
| 356 | 358 | image_fread(image, header, 512); |
| r5806 | r5807 | |
| 359 | 361 | /* Found an SWC identifier */ |
| 360 | 362 | logerror("Found header(SWC) - Skipped\n"); |
| 361 | 363 | } |
| 362 | | else if ((header[0] | (header[1] << 8)) == (((image_length(image) - 512) / 1024) / 8)) |
| 364 | else if ((header[0] | (header[1] << 8)) == (((snes_rom_size - 512) / 1024) / 8)) |
| 363 | 365 | { |
| 364 | 366 | /* Some headers have the rom size at the start, if this matches with the |
| 365 | 367 | * actual rom size, we probably have a header */ |
| 366 | 368 | logerror("Found header(size) - Skipped\n"); |
| 367 | 369 | } |
| 368 | | else if ((image_length(image) % 0x8000) == 512) |
| 370 | else if ((snes_rom_size % 0x8000) == 512) |
| 369 | 371 | { |
| 370 | 372 | /* As a last check we'll see if there's exactly 512 bytes extra to this |
| 371 | 373 | * image. */ |
| r5806 | r5807 | |
| 379 | 381 | image_fseek(image, offset, SEEK_SET); |
| 380 | 382 | } |
| 381 | 383 | |
| 384 | snes_rom_size -= offset; |
| 385 | |
| 382 | 386 | /* We need to take a sample to test what mode we need to be in (the |
| 383 | 387 | sample has to be quite large to cope with large carts in ExHiRom) */ |
| 384 | 388 | image_fread(image, temp_buffer, 0x40ffff); |
| r5806 | r5807 | |
| 395 | 399 | |
| 396 | 400 | if ((valid_mode20 >= valid_mode21) && (valid_mode20 >= valid_mode25)) |
| 397 | 401 | { |
| 398 | | if ((temp_buffer[0x007fd5] == 0x32) || ((image_length(image) - offset) > 0x401000)) |
| 402 | if ((temp_buffer[0x007fd5] == 0x32) || ((snes_rom_size - offset) > 0x401000)) |
| 399 | 403 | snes_cart.mode = SNES_MODE_22; // ExLoRom |
| 400 | 404 | else |
| 401 | 405 | snes_cart.mode = SNES_MODE_20; // LoRom |
| r5806 | r5807 | |
| 416 | 420 | |
| 417 | 421 | /* Loading data */ |
| 418 | 422 | ROM = memory_region(image->machine, "cart"); |
| 419 | | length = image_fread(image, ROM, image_length(image) - offset); |
| 423 | length = image_fread(image, ROM, snes_rom_size - offset); |
| 420 | 424 | |
| 421 | 425 | /* FIXME: Insert crc check here */ |
| 422 | 426 | |
| 423 | 427 | /* How many blocks of data are available to be loaded? */ |
| 424 | | total_blocks = ((image_length(image) - offset) / (snes_cart.mode & 0x05 ? 0x8000 : 0x10000)); |
| 428 | total_blocks = ((snes_rom_size - offset) / (snes_cart.mode & 0x05 ? 0x8000 : 0x10000)); |
| 425 | 429 | read_blocks = 0; |
| 426 | 430 | |
| 427 | 431 | /* Loading all the data blocks from cart, we only partially cover banks 0x00 to 0x7f. Therefore, we |
| r5806 | r5807 | |
| 499 | 503 | { |
| 500 | 504 | /* Loading data */ |
| 501 | 505 | memcpy(&snes_ram[0x400000 + read_blocks * 0x10000], &ROM[0x400000 + read_blocks * 0x10000], 0x10000); |
| 506 | memcpy(&snes_ram[0x1000000 + read_blocks * 0x10000], &snes_ram[0x400000 + read_blocks * 0x10000], 0x10000); |
| 502 | 507 | /* Mirroring */ |
| 503 | 508 | memcpy(&snes_ram[0x8000 + read_blocks * 0x10000], &snes_ram[0x408000 + read_blocks * 0x10000], 0x8000); |
| 504 | 509 | read_blocks++; |
| r5806 | r5807 | |
| 652 | 657 | case 0x34: |
| 653 | 658 | case 0x35: |
| 654 | 659 | if (snes_r_bank1(space, 0x00ffd5) == 0x23) |
| 655 | | { |
| 660 | { |
| 656 | 661 | snes_has_addon_chip = HAS_SA1; |
| 657 | 662 | supported_type = 0; |
| 658 | 663 | } |
| r5806 | r5807 | |
| 661 | 666 | case 0x43: |
| 662 | 667 | case 0x45: |
| 663 | 668 | if (snes_r_bank1(space, 0x00ffd5) == 0x32) |
| 669 | { |
| 664 | 670 | snes_has_addon_chip = HAS_SDD1; |
| 671 | } |
| 665 | 672 | break; |
| 666 | 673 | |
| 667 | 674 | case 0x55: |
| 668 | 675 | if (snes_r_bank1(space, 0x00ffd5) == 0x35) |
| 669 | | { |
| 676 | { |
| 670 | 677 | snes_has_addon_chip = HAS_RTC; |
| 671 | 678 | supported_type = 0; |
| 672 | 679 | } |
| r5806 | r5807 | |
| 690 | 697 | else if (snes_r_bank1(space, 0x00ffd5) == 0x3a) |
| 691 | 698 | { |
| 692 | 699 | snes_has_addon_chip = HAS_SPC7110; |
| 693 | | supported_type = 0; |
| 694 | 700 | } |
| 695 | 701 | break; |
| 696 | 702 | |
| r5806 | r5807 | |
| 705 | 711 | else |
| 706 | 712 | { |
| 707 | 713 | snes_has_addon_chip = HAS_ST010; |
| 708 | | supported_type = 0; |
| 709 | 714 | } |
| 710 | 715 | break; |
| 711 | 716 | |
| r5806 | r5807 | |
| 760 | 765 | logerror( "===========\n\n" ); |
| 761 | 766 | logerror( "\tTotal blocks: %d (%dmb)\n", total_blocks, total_blocks / (snes_cart.mode & 5 ? 32 : 16) ); |
| 762 | 767 | logerror( "\tROM bank size: %s (LoROM: %d , HiROM: %d, ExHiROM: %d)\n", |
| 763 | | (snes_cart.mode == SNES_MODE_20) ? "LoROM" : |
| 768 | (snes_cart.mode == SNES_MODE_20) ? "LoROM" : |
| 764 | 769 | (snes_cart.mode == SNES_MODE_21) ? "HiROM" : |
| 765 | 770 | (snes_cart.mode == SNES_MODE_22) ? "ExLoROM" : "ExHiROM", |
| 766 | 771 | valid_mode20, valid_mode21, valid_mode25); |