src/mame/machine/snes.c
| r7667 | r7668 | |
| 38 | 38 | static void snes_dma(const address_space *space, UINT8 channels); |
| 39 | 39 | static void snes_hdma_init(const address_space *space); |
| 40 | 40 | static void snes_hdma(const address_space *space); |
| 41 | static READ8_HANDLER(snes_open_bus_r); |
| 41 | 42 | |
| 42 | 43 | struct snes_cart_info snes_cart; |
| 43 | 44 | |
| r7667 | r7668 | |
| 606 | 607 | { |
| 607 | 608 | if (offset == 0x2800 || offset == 0x2801) |
| 608 | 609 | { |
| 609 | | return srtc_read(space->machine, offset); |
| 610 | return srtc_read(space, offset); |
| 610 | 611 | } |
| 611 | 612 | } |
| 612 | 613 | else if (snes_has_addon_chip == HAS_SDD1) |
| r7667 | r7668 | |
| 625 | 626 | UINT16 limit = (snes_has_addon_chip == HAS_SPC7110_RTC) ? 0x4842 : 0x483f; |
| 626 | 627 | if (offset >= 0x4800 && offset <= limit) |
| 627 | 628 | { |
| 628 | | return spc7110_mmio_read(space->machine, offset); |
| 629 | return spc7110_mmio_read(space, offset); |
| 629 | 630 | } |
| 630 | 631 | } |
| 631 | 632 | |
| r7667 | r7668 | |
| 1603 | 1604 | /* 0x000000 - 0x2fffff */ |
| 1604 | 1605 | READ8_HANDLER( snes_r_bank1 ) |
| 1605 | 1606 | { |
| 1607 | snes_state *state = (snes_state *)space->machine->driver_data; |
| 1606 | 1608 | UINT8 value = 0xff; |
| 1607 | 1609 | UINT16 address = offset & 0xffff; |
| 1608 | 1610 | |
| r7667 | r7668 | |
| 1612 | 1614 | value = snes_r_io(space, address); |
| 1613 | 1615 | else if (address < 0x8000) |
| 1614 | 1616 | { |
| 1615 | | if (snes_has_addon_chip == HAS_SUPERFX) |
| 1616 | | value = snes_ram[0xf00000 + (address & 0x1fff)]; // here it should be 0xe00000 but there are mirroring issues |
| 1617 | if (snes_has_addon_chip == HAS_SUPERFX && state->superfx !=NULL) |
| 1618 | { |
| 1619 | if (superfx_access_ram(state->superfx)) |
| 1620 | value = snes_ram[0xf00000 + (offset & 0x1fff)]; // here it should be 0xe00000 but there are mirroring issues |
| 1621 | else |
| 1622 | value = snes_open_bus_r(space, 0); |
| 1623 | } |
| 1617 | 1624 | else if (snes_has_addon_chip == HAS_OBC1) |
| 1618 | 1625 | value = obc1_read(space, offset); |
| 1619 | 1626 | else if ((snes_cart.mode == SNES_MODE_21) && (snes_has_addon_chip == HAS_DSP1) && (offset < 0x100000)) |
| r7667 | r7668 | |
| 1628 | 1635 | else |
| 1629 | 1636 | { |
| 1630 | 1637 | logerror("snes_r_bank1: Unmapped external chip read: %04x\n", address); |
| 1631 | | value = 0xff; /* Reserved */ |
| 1638 | value = snes_open_bus_r(space, 0); /* Reserved */ |
| 1632 | 1639 | } |
| 1633 | 1640 | } |
| 1634 | 1641 | else if ((snes_cart.mode == SNES_MODE_20) && (snes_has_addon_chip == HAS_DSP1) && (offset >= 0x200000)) |
| r7667 | r7668 | |
| 1646 | 1653 | /* 0x300000 - 0x3fffff */ |
| 1647 | 1654 | READ8_HANDLER( snes_r_bank2 ) |
| 1648 | 1655 | { |
| 1656 | snes_state *state = (snes_state *)space->machine->driver_data; |
| 1649 | 1657 | UINT8 value = 0xff; |
| 1650 | 1658 | UINT16 address = offset & 0xffff; |
| 1651 | 1659 | |
| r7667 | r7668 | |
| 1655 | 1663 | value = snes_r_io(space, address); |
| 1656 | 1664 | else if (address < 0x8000) /* SRAM for mode_21, Reserved othewise */ |
| 1657 | 1665 | { |
| 1658 | | if (snes_has_addon_chip == HAS_SUPERFX) |
| 1659 | | value = snes_ram[0xf00000 + (address & 0x1fff)]; // here it should be 0xe00000 but there are mirroring issues |
| 1666 | if (snes_has_addon_chip == HAS_SUPERFX && state->superfx != NULL) |
| 1667 | { |
| 1668 | if (superfx_access_ram(state->superfx)) |
| 1669 | value = snes_ram[0xf00000 + (offset & 0x1fff)]; // here it should be 0xe00000 but there are mirroring issues |
| 1670 | else |
| 1671 | value = snes_open_bus_r(space, 0); |
| 1672 | } |
| 1660 | 1673 | else if (snes_has_addon_chip == HAS_OBC1) |
| 1661 | 1674 | value = obc1_read (space, offset); |
| 1662 | 1675 | else if (snes_has_addon_chip == HAS_CX4) |
| r7667 | r7668 | |
| 1675 | 1688 | else |
| 1676 | 1689 | { |
| 1677 | 1690 | logerror( "snes_r_bank2: Unmapped external chip read: %04x\n", address ); |
| 1678 | | value = 0xff; |
| 1691 | value = snes_open_bus_r(space, 0); |
| 1679 | 1692 | } |
| 1680 | 1693 | } |
| 1681 | 1694 | /* some dsp1 games use these banks 0x30 to 0x3f at address 0x8000 */ |
| r7667 | r7668 | |
| 1696 | 1709 | /* 0x400000 - 0x5fffff */ |
| 1697 | 1710 | READ8_HANDLER( snes_r_bank3 ) |
| 1698 | 1711 | { |
| 1712 | snes_state *state = (snes_state *)space->machine->driver_data; |
| 1699 | 1713 | UINT8 value = 0xff; |
| 1700 | 1714 | UINT16 address = offset & 0xffff; |
| 1701 | 1715 | |
| 1702 | | if ((snes_has_addon_chip == HAS_SPC7110 || snes_has_addon_chip == HAS_SPC7110_RTC)) |
| 1716 | if (snes_has_addon_chip == HAS_SUPERFX && state->superfx != NULL) |
| 1703 | 1717 | { |
| 1718 | if (superfx_access_rom(state->superfx)) |
| 1719 | value = snes_ram[0x400000 + offset]; |
| 1720 | else |
| 1721 | { |
| 1722 | static const UINT8 sfx_data[16] = { |
| 1723 | 0x00, 0x01, 0x00, 0x01, 0x04, 0x01, 0x00, 0x01, |
| 1724 | 0x00, 0x01, 0x08, 0x01, 0x00, 0x01, 0x0c, 0x01, |
| 1725 | }; |
| 1726 | return sfx_data[offset & 0x0f]; |
| 1727 | } |
| 1728 | } |
| 1729 | else if ((snes_has_addon_chip == HAS_SPC7110 || snes_has_addon_chip == HAS_SPC7110_RTC)) |
| 1730 | { |
| 1704 | 1731 | if (offset >= 0x100000 && offset < 0x110000) |
| 1705 | | value = spc7110_mmio_read(space->machine, 0x4800); |
| 1732 | value = spc7110_mmio_read(space, 0x4800); |
| 1706 | 1733 | } |
| 1707 | 1734 | else if ((snes_cart.mode & 5) && !(snes_has_addon_chip == HAS_SUPERFX)) /* Mode 20 & 22 */ |
| 1708 | 1735 | { |
| 1709 | 1736 | if ((address < 0x8000) && (snes_cart.mode == SNES_MODE_20)) |
| 1710 | | value = 0xff; /* Reserved */ |
| 1737 | value = snes_open_bus_r(space, 0); /* Reserved */ |
| 1711 | 1738 | else |
| 1712 | 1739 | value = snes_ram[0x400000 + offset]; |
| 1713 | 1740 | } |
| r7667 | r7668 | |
| 1720 | 1747 | /* 0x600000 - 0x6fffff */ |
| 1721 | 1748 | READ8_HANDLER( snes_r_bank4 ) |
| 1722 | 1749 | { |
| 1750 | snes_state *state = (snes_state *)space->machine->driver_data; |
| 1723 | 1751 | UINT8 value = 0xff; |
| 1724 | 1752 | UINT16 address = offset & 0xffff; |
| 1725 | 1753 | |
| 1726 | | if (snes_has_addon_chip == HAS_SUPERFX) |
| 1727 | | value = snes_ram[0xe00000 + offset]; |
| 1754 | if (snes_has_addon_chip == HAS_SUPERFX && state->superfx != NULL) |
| 1755 | { |
| 1756 | if (superfx_access_ram(state->superfx)) |
| 1757 | value = snes_ram[0xe00000 + offset]; |
| 1758 | else |
| 1759 | value = snes_open_bus_r(space, 0); |
| 1760 | } |
| 1728 | 1761 | else if (snes_has_addon_chip == HAS_ST010 && offset >= 0x80000 && address < 0x1000) |
| 1729 | 1762 | value = st010_read(address); |
| 1730 | 1763 | else if (snes_cart.mode & 5) /* Mode 20 & 22 */ |
| r7667 | r7668 | |
| 1737 | 1770 | else |
| 1738 | 1771 | { |
| 1739 | 1772 | logerror("snes_r_bank4: Unmapped external chip read: %04x\n", address); |
| 1740 | | value = 0xff; /* Reserved */ |
| 1773 | value = snes_open_bus_r(space, 0); /* Reserved */ |
| 1741 | 1774 | } |
| 1742 | 1775 | } |
| 1743 | 1776 | else if (snes_cart.mode & 0x0a) /* Mode 21 & 25 */ |
| r7667 | r7668 | |
| 1749 | 1782 | /* 0x700000 - 0x7dffff */ |
| 1750 | 1783 | READ8_HANDLER( snes_r_bank5 ) |
| 1751 | 1784 | { |
| 1785 | snes_state *state = (snes_state *)space->machine->driver_data; |
| 1752 | 1786 | UINT8 value; |
| 1753 | 1787 | UINT16 address = offset & 0xffff; |
| 1754 | 1788 | |
| 1755 | | if (snes_has_addon_chip == HAS_SUPERFX) |
| 1756 | | value = snes_ram[0xf00000 + offset]; |
| 1789 | if (snes_has_addon_chip == HAS_SUPERFX && state->superfx != NULL) |
| 1790 | { |
| 1791 | if (superfx_access_ram(state->superfx)) |
| 1792 | value = snes_ram[0xf00000 + offset]; |
| 1793 | else |
| 1794 | value = snes_open_bus_r(space, 0); |
| 1795 | } |
| 1757 | 1796 | else if ((snes_cart.mode & 5) && (address < 0x8000)) /* Mode 20 & 22 */ |
| 1758 | 1797 | { |
| 1759 | 1798 | if (snes_cart.sram > 0) |
| r7667 | r7668 | |
| 1764 | 1803 | else |
| 1765 | 1804 | { |
| 1766 | 1805 | logerror("snes_r_bank5: Unmapped external chip read: %04x\n", address); |
| 1767 | | value = 0xff; /* Reserved */ |
| 1806 | value = snes_open_bus_r(space, 0); /* Reserved */ |
| 1768 | 1807 | } |
| 1769 | 1808 | } |
| 1770 | 1809 | else |
| r7667 | r7668 | |
| 1800 | 1839 | else /* Area 0x6000-0x8000 with offset < 0x300000 is reserved */ |
| 1801 | 1840 | { |
| 1802 | 1841 | logerror("snes_r_bank6: Unmapped external chip read: %04x\n", address); |
| 1803 | | value = 0xff; |
| 1842 | value = snes_open_bus_r(space, 0); |
| 1804 | 1843 | } |
| 1805 | 1844 | } |
| 1806 | 1845 | } |
| r7667 | r7668 | |
| 1821 | 1860 | /* 0xc00000 - 0xffffff */ |
| 1822 | 1861 | READ8_HANDLER( snes_r_bank7 ) |
| 1823 | 1862 | { |
| 1863 | snes_state *state = (snes_state *)space->machine->driver_data; |
| 1824 | 1864 | UINT8 value = 0; |
| 1825 | 1865 | UINT16 address = offset & 0xffff; |
| 1826 | 1866 | |
| 1827 | | if ((snes_has_addon_chip == HAS_SPC7110 || snes_has_addon_chip == HAS_SPC7110_RTC) && offset >= 0x100000) |
| 1828 | | value = spc7110_bank7_read(space->machine, offset); |
| 1867 | if (snes_has_addon_chip == HAS_SUPERFX && state->superfx != NULL) |
| 1868 | { |
| 1869 | if (offset < 0x200000) // ROM |
| 1870 | { |
| 1871 | if (superfx_access_rom(state->superfx)) |
| 1872 | value = snes_ram[0xc00000 + offset]; |
| 1873 | else |
| 1874 | { |
| 1875 | static const UINT8 sfx_data[16] = { |
| 1876 | 0x00, 0x01, 0x00, 0x01, 0x04, 0x01, 0x00, 0x01, |
| 1877 | 0x00, 0x01, 0x08, 0x01, 0x00, 0x01, 0x0c, 0x01, |
| 1878 | }; |
| 1879 | return sfx_data[offset & 0x0f]; |
| 1880 | } |
| 1881 | } |
| 1882 | else // RAM |
| 1883 | { |
| 1884 | offset -= 0x200000; |
| 1885 | if (superfx_access_ram(state->superfx)) |
| 1886 | value = snes_ram[0xe00000 + offset]; |
| 1887 | else |
| 1888 | value = snes_open_bus_r(space, 0); |
| 1889 | } |
| 1890 | } |
| 1891 | else if ((snes_has_addon_chip == HAS_SPC7110 || snes_has_addon_chip == HAS_SPC7110_RTC) && offset >= 0x100000) |
| 1892 | value = spc7110_bank7_read(space, offset); |
| 1829 | 1893 | else if (snes_has_addon_chip == HAS_SDD1) |
| 1830 | 1894 | value = sdd1_read(space->machine, offset); |
| 1831 | 1895 | else if (snes_has_addon_chip == HAS_ST010 && offset >= 0x280000 && offset < 0x300000 && address < 0x1000) |
| r7667 | r7668 | |
| 1856 | 1920 | else if (address < 0x8000) |
| 1857 | 1921 | { |
| 1858 | 1922 | if (snes_has_addon_chip == HAS_SUPERFX) |
| 1859 | | snes_ram[0xf00000 + (address & 0x1fff)] = data; // here it should 0xe00000 but there are mirroring issues |
| 1923 | snes_ram[0xf00000 + (offset & 0x1fff)] = data; // here it should be 0xe00000 but there are mirroring issues |
| 1860 | 1924 | else if (snes_has_addon_chip == HAS_OBC1) |
| 1861 | 1925 | obc1_write(space, offset, data); |
| 1862 | 1926 | else if ((snes_cart.mode == SNES_MODE_21) && (snes_has_addon_chip == HAS_DSP1) && (offset < 0x100000)) |
| r7667 | r7668 | |
| 1898 | 1962 | else if (address < 0x8000) /* SRAM for mode_21, Reserved othewise */ |
| 1899 | 1963 | { |
| 1900 | 1964 | if (snes_has_addon_chip == HAS_SUPERFX) |
| 1901 | | snes_ram[0xf00000 + (address & 0x1fff)] = data; // here it should be 0xe00000 but there are mirroring issues |
| 1965 | snes_ram[0xf00000 + (offset & 0x1fff)] = data; // here it should be 0xe00000 but there are mirroring issues |
| 1902 | 1966 | else if (snes_has_addon_chip == HAS_OBC1) |
| 1903 | 1967 | obc1_write(space, offset, data); |
| 1904 | 1968 | else if (snes_has_addon_chip == HAS_CX4) |
| r7667 | r7668 | |
| 2032 | 2096 | if (snes_has_addon_chip == HAS_SUPERFX) |
| 2033 | 2097 | { |
| 2034 | 2098 | if (offset >= 0x200000) |
| 2035 | | snes_ram[0xc00000 + offset] = data; // SFX RAM |
| 2099 | { |
| 2100 | offset -= 0x200000; |
| 2101 | snes_ram[0xe00000 + offset] = data; // SFX RAM |
| 2102 | } |
| 2036 | 2103 | else |
| 2037 | 2104 | logerror("Attempt to write to ROM address: %X\n", offset + 0xc00000); |
| 2038 | 2105 | } |
| r7667 | r7668 | |
| 2830 | 2897 | READ8_HANDLER( superfx_r_bank3 ) |
| 2831 | 2898 | { |
| 2832 | 2899 | /* IMPORTANT: SFX RAM sits in 0x600000-0x7fffff, and it's mirrored in 0xe00000-0xffffff. However, SNES |
| 2833 | | has only access to 0x600000-0x7d00000 (because there is WRAM after that), hence we directly use the mirror |
| 2900 | has only access to 0x600000-0x7dffff (because there is WRAM after that), hence we directly use the mirror |
| 2834 | 2901 | as the place where to write & read SFX RAM. SNES handlers have been setup accordingly. */ |
| 2835 | 2902 | //printf("superfx_r_bank3: %08x = %02x\n", offset, snes_ram[0xe00000 + offset]); |
| 2836 | 2903 | return snes_ram[0xe00000 + offset]; |
| r7667 | r7668 | |
| 2850 | 2917 | |
| 2851 | 2918 | WRITE8_HANDLER( superfx_w_bank3 ) |
| 2852 | 2919 | { |
| 2853 | | /* IMPORTANT: SFX RAM sits in 0x600000-0x7f00000, and it's mirrored in 0xe00000-0xff00000. However, SNES |
| 2854 | | has only access to 0x600000-0x7d00000 (because there is WRAM after that), hence we directly use the mirror |
| 2920 | /* IMPORTANT: SFX RAM sits in 0x600000-0x7fffff, and it's mirrored in 0xe00000-0xffffff. However, SNES |
| 2921 | has only access to 0x600000-0x7dffff (because there is WRAM after that), hence we directly use the mirror |
| 2855 | 2922 | as the place where to write & read SFX RAM. SNES handlers have been setup accordingly. */ |
| 2856 | 2923 | //printf("superfx_w_bank3: %08x = %02x\n", offset, data); |
| 2857 | 2924 | snes_ram[0xe00000 + offset] = data; |