src/mame/machine/n64.c
| r14462 | r14463 | |
| 102 | 102 | si_pif_addr = 0; |
| 103 | 103 | si_status = 0; |
| 104 | 104 | |
| 105 | | memset(eeprom, 0, sizeof(eeprom)); |
| 106 | | memset(mempack, 0, sizeof(mempack)); |
| 105 | memset(m_save_data.eeprom, 0, 2048); |
| 107 | 106 | |
| 108 | 107 | dp_clock = 0; |
| 109 | 108 | |
| r14462 | r14463 | |
| 1239 | 1238 | if(cart_addr & 0x04000000) |
| 1240 | 1239 | { |
| 1241 | 1240 | cart16 = (UINT16*)n64_sram; |
| 1242 | | cart_addr = (pi_cart_addr & 0x00007fff) >> 1; |
| 1241 | cart_addr = (pi_cart_addr & 0x0001ffff) >> 1; |
| 1243 | 1242 | } |
| 1244 | 1243 | |
| 1245 | 1244 | cart_addr &= ((machine().region("user2")->bytes() >> 1) - 1); |
| r14462 | r14463 | |
| 1460 | 1459 | } |
| 1461 | 1460 | |
| 1462 | 1461 | // Serial Interface |
| 1463 | | UINT8 n64_periphs::calc_mempack_crc(UINT8 *buffer, int length) |
| 1462 | UINT8 n64_periphs::calc_mempak_crc(UINT8 *buffer, int length) |
| 1464 | 1463 | { |
| 1465 | 1464 | UINT32 crc = 0; |
| 1466 | 1465 | UINT32 temp2 = 0; |
| r14462 | r14463 | |
| 1499 | 1498 | return crc; |
| 1500 | 1499 | } |
| 1501 | 1500 | |
| 1501 | INLINE UINT8 convert_to_bcd(int val) |
| 1502 | { |
| 1503 | return ((val / 10) << 4) | (val % 10); |
| 1504 | } |
| 1505 | |
| 1502 | 1506 | int n64_periphs::pif_channel_handle_command(int channel, int slength, UINT8 *sdata, int rlength, UINT8 *rdata) |
| 1503 | 1507 | { |
| 1504 | 1508 | UINT8 command = sdata[0]; |
| r14462 | r14463 | |
| 1512 | 1516 | case 0: |
| 1513 | 1517 | case 1: |
| 1514 | 1518 | { |
| 1519 | printf("Read controller %d status\n", channel + 1); |
| 1515 | 1520 | rdata[0] = 0x05; |
| 1516 | 1521 | rdata[1] = 0x00; |
| 1517 | | rdata[2] = 0x02; |
| 1522 | rdata[2] = 0x01; |
| 1518 | 1523 | return 0; |
| 1519 | 1524 | } |
| 1520 | 1525 | case 2: |
| 1521 | 1526 | case 3: |
| 1522 | 1527 | { |
| 1528 | printf("Read controller %d status (NC)\n", channel + 1); |
| 1523 | 1529 | // not connected |
| 1524 | 1530 | return 1; |
| 1525 | 1531 | } |
| 1526 | 1532 | case 4: |
| 1527 | 1533 | { |
| 1534 | printf("Read EEPROM status\n"); |
| 1528 | 1535 | rdata[0] = 0x00; |
| 1529 | | rdata[1] = 0x80; |
| 1536 | rdata[1] = 0xc0; |
| 1530 | 1537 | rdata[2] = 0x00; |
| 1531 | 1538 | |
| 1532 | 1539 | return 1; |
| r14462 | r14463 | |
| 1558 | 1565 | case 0: //p1 inputs |
| 1559 | 1566 | case 1: //p2 inputs |
| 1560 | 1567 | { |
| 1568 | printf("Read p%d inputs\n", channel + 1); |
| 1561 | 1569 | buttons = input_port_read(machine(), portnames[(channel*3) + 0]); |
| 1562 | 1570 | x = input_port_read(machine(), portnames[(channel*3) + 1]) - 128; |
| 1563 | 1571 | y = input_port_read(machine(), portnames[(channel*3) + 2]) - 128; |
| r14462 | r14463 | |
| 1571 | 1579 | case 2: |
| 1572 | 1580 | case 3: |
| 1573 | 1581 | { |
| 1582 | printf("Controller %d not connected\n", channel + 1); |
| 1574 | 1583 | // not connected |
| 1575 | 1584 | return 1; |
| 1576 | 1585 | } |
| r14462 | r14463 | |
| 1579 | 1588 | break; |
| 1580 | 1589 | } |
| 1581 | 1590 | |
| 1582 | | case 0x02: |
| 1591 | case 0x02: // Read mempak |
| 1583 | 1592 | { |
| 1584 | 1593 | UINT32 address; |
| 1585 | 1594 | |
| 1586 | 1595 | address = (sdata[1] << 8) | (sdata[2]); |
| 1587 | 1596 | address &= ~0x1f; |
| 1588 | 1597 | |
| 1589 | | if(address == 0x400) |
| 1598 | printf("Read mempak at %04x\n", address); |
| 1599 | |
| 1600 | if(address == 0x8000) |
| 1590 | 1601 | { |
| 1591 | 1602 | for(int i = 0; i < rlength-1; i++) |
| 1592 | 1603 | { |
| 1593 | 1604 | rdata[i] = 0x00; |
| 1594 | 1605 | } |
| 1595 | 1606 | |
| 1596 | | rdata[rlength-1] = calc_mempack_crc(rdata, rlength-1); |
| 1607 | rdata[rlength-1] = calc_mempak_crc(rdata, rlength-1); |
| 1608 | return 0; |
| 1597 | 1609 | } |
| 1598 | 1610 | else if(address < 0x7fe0) |
| 1599 | 1611 | { |
| 1600 | 1612 | for(int i = 0; i < rlength-1; i++) |
| 1601 | 1613 | { |
| 1602 | | rdata[i] = mempack[address+i]; |
| 1614 | rdata[i] = m_save_data.mempak[channel & 1][address+i]; |
| 1603 | 1615 | } |
| 1604 | 1616 | |
| 1605 | | rdata[rlength-1] = calc_mempack_crc(rdata, rlength-1); |
| 1617 | rdata[rlength-1] = calc_mempak_crc(rdata, rlength-1); |
| 1618 | return 0; |
| 1606 | 1619 | } |
| 1620 | |
| 1607 | 1621 | return 1; |
| 1608 | 1622 | } |
| 1609 | | case 0x03: |
| 1623 | case 0x03: // Write mempak |
| 1610 | 1624 | { |
| 1611 | 1625 | UINT32 address = (sdata[1] << 8) | (sdata[2]); |
| 1612 | 1626 | address &= ~0x1f; |
| 1613 | 1627 | |
| 1614 | | if (address == 0x8000) |
| 1628 | printf("Write mempak at %04x\n", address); |
| 1629 | if (address >= 0x8000) |
| 1615 | 1630 | { |
| 1616 | 1631 | |
| 1617 | 1632 | } |
| r14462 | r14463 | |
| 1619 | 1634 | { |
| 1620 | 1635 | for(int i = 3; i < slength; i++) |
| 1621 | 1636 | { |
| 1622 | | mempack[address++] = sdata[i]; |
| 1637 | m_save_data.mempak[channel & 1][address++] = sdata[i]; |
| 1623 | 1638 | } |
| 1624 | 1639 | } |
| 1625 | 1640 | |
| 1626 | | rdata[0] = calc_mempack_crc(&sdata[3], slength-3); |
| 1641 | rdata[0] = calc_mempak_crc(&sdata[3], slength-3); |
| 1627 | 1642 | |
| 1628 | | return 1; |
| 1643 | return 0; |
| 1629 | 1644 | } |
| 1630 | 1645 | |
| 1631 | 1646 | case 0x04: // Read from EEPROM |
| r14462 | r14463 | |
| 1640 | 1655 | fatalerror("handle_pif: write EEPROM (bytes to send %d, bytes to receive %d)\n", slength, rlength); |
| 1641 | 1656 | } |
| 1642 | 1657 | |
| 1643 | | UINT8 block_offset = sdata[1] * 8; |
| 1658 | UINT16 block_offset = sdata[1] * 8; |
| 1644 | 1659 | |
| 1660 | printf("Read EEPROM at %04x\n", block_offset); |
| 1661 | |
| 1645 | 1662 | for(int i=0; i < 8; i++) |
| 1646 | 1663 | { |
| 1647 | | rdata[i] = eeprom[block_offset+i]; |
| 1664 | rdata[i] = m_save_data.eeprom[block_offset+i]; |
| 1648 | 1665 | } |
| 1649 | 1666 | |
| 1650 | | return 1; |
| 1667 | return 0; |
| 1651 | 1668 | } |
| 1652 | 1669 | |
| 1653 | 1670 | case 0x05: // Write to EEPROM |
| r14462 | r14463 | |
| 1662 | 1679 | fatalerror("handle_pif: write EEPROM (bytes to send %d, bytes to receive %d)\n", slength, rlength); |
| 1663 | 1680 | } |
| 1664 | 1681 | |
| 1665 | | UINT8 block_offset = sdata[1] * 8; |
| 1682 | UINT16 block_offset = sdata[1] * 8; |
| 1683 | |
| 1684 | printf("Write EEPROM at %04x\n", block_offset); |
| 1685 | |
| 1666 | 1686 | for(int i = 0; i < 8; i++) |
| 1667 | 1687 | { |
| 1668 | | eeprom[block_offset+i] = sdata[2+i]; |
| 1688 | m_save_data.eeprom[block_offset+i] = sdata[2+i]; |
| 1669 | 1689 | } |
| 1670 | 1690 | |
| 1691 | return 0; |
| 1692 | } |
| 1693 | |
| 1694 | case 0x06: // Read RTC Status |
| 1695 | { |
| 1696 | printf("Read RTC Status\n"); |
| 1697 | rdata[0] = 0x00; |
| 1698 | rdata[1] = 0x10; |
| 1699 | rdata[2] = 0x00; |
| 1700 | return 0; |
| 1701 | } |
| 1702 | |
| 1703 | case 0x07: // Read RTC Block |
| 1704 | { |
| 1705 | switch(sdata[1]) |
| 1706 | { |
| 1707 | case 0: |
| 1708 | printf("Read RTC Block Header\n"); |
| 1709 | rdata[0] = 0x00; |
| 1710 | rdata[1] = 0x02; |
| 1711 | rdata[8] = 0x00; |
| 1712 | return 0; |
| 1713 | |
| 1714 | case 1: |
| 1715 | return 0; |
| 1716 | |
| 1717 | case 2: |
| 1718 | system_time systime; |
| 1719 | machine().base_datetime(systime); |
| 1720 | rdata[0] = convert_to_bcd(systime.local_time.second); // Seconds |
| 1721 | rdata[1] = convert_to_bcd(systime.local_time.minute); // Minutes |
| 1722 | rdata[2] = 0x80 | convert_to_bcd(systime.local_time.hour); // Hours |
| 1723 | rdata[3] = convert_to_bcd(systime.local_time.mday); // Day of month |
| 1724 | rdata[4] = convert_to_bcd(systime.local_time.weekday); // Day of week |
| 1725 | rdata[5] = convert_to_bcd(systime.local_time.month + 1); // Month |
| 1726 | rdata[6] = convert_to_bcd(systime.local_time.year % 100); // Year |
| 1727 | rdata[7] = convert_to_bcd(systime.local_time.year / 100); // Century |
| 1728 | rdata[8] = 0x00; |
| 1729 | printf("Read RTC Time\n"); |
| 1730 | return 0; |
| 1731 | } |
| 1671 | 1732 | return 1; |
| 1672 | 1733 | } |
| 1673 | 1734 | |
| 1674 | 1735 | case 0xff: // reset |
| 1675 | 1736 | { |
| 1737 | printf("Reset\n"); |
| 1676 | 1738 | rdata[0] = 0xff; |
| 1677 | 1739 | rdata[1] = 0xff; |
| 1678 | 1740 | rdata[2] = 0xff; |
| r14462 | r14463 | |
| 1691 | 1753 | |
| 1692 | 1754 | void n64_periphs::handle_pif() |
| 1693 | 1755 | { |
| 1756 | printf("Before:\n"); |
| 1757 | for(int i = 0; i < 0x40; i++) |
| 1758 | { |
| 1759 | printf("%02x ", pif_cmd[i]); |
| 1760 | if((i & 0xf) == 0xf) |
| 1761 | { |
| 1762 | printf("\n"); |
| 1763 | } |
| 1764 | } |
| 1694 | 1765 | if(pif_cmd[0x3f] == 0x1) // only handle the command if the last byte is 1 |
| 1695 | 1766 | { |
| 1696 | 1767 | int channel = 0; |
| r14462 | r14463 | |
| 1699 | 1770 | |
| 1700 | 1771 | while(cmd_ptr < 0x3f && !end) |
| 1701 | 1772 | { |
| 1702 | | UINT8 bytes_to_send = pif_cmd[cmd_ptr++]; |
| 1773 | INT8 bytes_to_send = (INT8)pif_cmd[cmd_ptr++]; |
| 1774 | printf("bytes to send: 0x%02x\n", bytes_to_send); |
| 1703 | 1775 | |
| 1704 | | if (bytes_to_send == 0xfe) |
| 1776 | if (bytes_to_send == -2) |
| 1705 | 1777 | { |
| 1706 | 1778 | end = 1; |
| 1779 | printf("end\n"); |
| 1707 | 1780 | } |
| 1708 | | else if (bytes_to_send == 0xff) |
| 1781 | else if (bytes_to_send < 0) |
| 1709 | 1782 | { |
| 1783 | printf("do nothing\n"); |
| 1710 | 1784 | // do nothing |
| 1711 | 1785 | } |
| 1712 | 1786 | else |
| r14462 | r14463 | |
| 1716 | 1790 | UINT8 recv_buffer[0x40]; |
| 1717 | 1791 | UINT8 send_buffer[0x40]; |
| 1718 | 1792 | |
| 1719 | | UINT8 bytes_to_recv = pif_cmd[cmd_ptr++]; |
| 1793 | INT8 bytes_to_recv = pif_cmd[cmd_ptr++]; |
| 1794 | printf("bytes to receive: 0x%02x\n", bytes_to_recv); |
| 1720 | 1795 | |
| 1796 | if (bytes_to_recv == -2) |
| 1797 | { |
| 1798 | break; // Hack, shouldn't need to do this |
| 1799 | } |
| 1800 | |
| 1721 | 1801 | for(int j = 0; j < bytes_to_send; j++) |
| 1722 | 1802 | { |
| 1723 | 1803 | send_buffer[j] = pif_cmd[cmd_ptr++]; |
| 1724 | 1804 | } |
| 1725 | 1805 | |
| 1726 | 1806 | int res = pif_channel_handle_command(channel, bytes_to_send, send_buffer, bytes_to_recv, recv_buffer); |
| 1807 | printf("result: %d\n", res); |
| 1727 | 1808 | |
| 1728 | 1809 | if (res == 0) |
| 1729 | 1810 | { |
| 1811 | printf("cmd_ptr (%d) + bytes_to_recv (%d) = %d\n", cmd_ptr, bytes_to_recv, cmd_ptr + bytes_to_recv); |
| 1730 | 1812 | if (cmd_ptr + bytes_to_recv > 0x3f) |
| 1731 | 1813 | { |
| 1732 | 1814 | fatalerror("cmd_ptr overflow\n"); |
| r14462 | r14463 | |
| 1749 | 1831 | |
| 1750 | 1832 | pif_ram[0x3f] = 0; |
| 1751 | 1833 | } |
| 1834 | |
| 1835 | printf("After:\n"); |
| 1836 | for(int i = 0; i < 0x40; i++) |
| 1837 | { |
| 1838 | printf("%02x ", pif_ram[i]); |
| 1839 | if((i & 0xf) == 0xf) |
| 1840 | { |
| 1841 | printf("\n"); |
| 1842 | } |
| 1843 | } |
| 1752 | 1844 | } |
| 1753 | 1845 | |
| 1754 | 1846 | void n64_periphs::pif_dma(int direction) |
| r14462 | r14463 | |
| 1799 | 1891 | |
| 1800 | 1892 | READ32_MEMBER( n64_periphs::si_reg_r ) |
| 1801 | 1893 | { |
| 1802 | | //printf("si_reg_r %08x\n", offset * 4); |
| 1894 | printf("si_reg_r %08x\n", offset * 4); |
| 1803 | 1895 | switch (offset) |
| 1804 | 1896 | { |
| 1805 | 1897 | //case 0x00/4: // SI_DRAM_ADDR_REG |
| r14462 | r14463 | |
| 1813 | 1905 | |
| 1814 | 1906 | WRITE32_MEMBER( n64_periphs::si_reg_w ) |
| 1815 | 1907 | { |
| 1816 | | //printf("si_reg_w %08x %08x %08x\n", offset * 4, data, mem_mask); |
| 1908 | printf("si_reg_w %08x %08x %08x\n", offset * 4, data, mem_mask); |
| 1817 | 1909 | switch (offset) |
| 1818 | 1910 | { |
| 1819 | 1911 | case 0x00/4: // SI_DRAM_ADDR_REG |
| r14462 | r14463 | |
| 1883 | 1975 | signal_rcp_interrupt(SI_INTERRUPT); |
| 1884 | 1976 | } |
| 1885 | 1977 | |
| 1886 | | //static UINT16 crc_seed = 0x3f; |
| 1978 | static void n64_machine_stop(running_machine &machine) |
| 1979 | { |
| 1980 | n64_periphs *periphs = machine.device<n64_periphs>("rcp"); |
| 1887 | 1981 | |
| 1982 | device_image_interface *image = dynamic_cast<device_image_interface *>(periphs->m_nvram_image); |
| 1983 | . //printf("Saving stuff\n"); |
| 1984 | UINT8 data[0x30800]; |
| 1985 | memcpy(data, n64_sram, 0x20000); |
| 1986 | memcpy(data + 0x20000, periphs->m_save_data.eeprom, 0x800); |
| 1987 | memcpy(data + 0x20800, periphs->m_save_data.mempak[0], 0x8000); |
| 1988 | memcpy(data + 0x28800, periphs->m_save_data.mempak[1], 0x8000); |
| 1989 | image->battery_save(data, 0x30800); |
| 1990 | } |
| 1991 | |
| 1888 | 1992 | MACHINE_START( n64 ) |
| 1889 | 1993 | { |
| 1890 | | mips3drc_set_options(machine.device("maincpu"), MIPS3DRC_FASTEST_OPTIONS + MIPS3DRC_STRICT_VERIFY + MIPS3DRC_STRICT_COP1); |
| 1994 | mips3drc_set_options(machine.device("maincpu"), MIPS3DRC_COMPATIBLE_OPTIONS); |
| 1891 | 1995 | |
| 1892 | 1996 | /* configure fast RAM regions for DRC */ |
| 1893 | 1997 | mips3drc_add_fastram(machine.device("maincpu"), 0x00000000, 0x007fffff, FALSE, rdram); |
| r14462 | r14463 | |
| 1896 | 2000 | rspdrc_flush_drc_cache(machine.device("rsp")); |
| 1897 | 2001 | rspdrc_add_dmem(machine.device("rsp"), rsp_dmem); |
| 1898 | 2002 | rspdrc_add_imem(machine.device("rsp"), rsp_imem); |
| 2003 | |
| 2004 | /* add a hook for battery save */ |
| 2005 | machine.add_notifier(MACHINE_NOTIFY_EXIT, machine_notify_delegate(FUNC(n64_machine_stop),&machine)); |
| 1899 | 2006 | } |
| 1900 | 2007 | |
| 1901 | 2008 | MACHINE_RESET( n64 ) |
src/mess/drivers/n64.c
| r14462 | r14463 | |
| 28 | 28 | AM_RANGE(0x04600000, 0x046fffff) AM_DEVREADWRITE_MODERN("rcp", n64_periphs, pi_reg_r, pi_reg_w) // Peripheral Interface |
| 29 | 29 | AM_RANGE(0x04700000, 0x047fffff) AM_DEVREADWRITE_MODERN("rcp", n64_periphs, ri_reg_r, ri_reg_w) // RDRAM Interface |
| 30 | 30 | AM_RANGE(0x04800000, 0x048fffff) AM_DEVREADWRITE_MODERN("rcp", n64_periphs, si_reg_r, si_reg_w) // Serial Interface |
| 31 | | AM_RANGE(0x08000000, 0x08007fff) AM_RAM AM_BASE(&n64_sram) // Cartridge SRAM |
| 31 | AM_RANGE(0x08000000, 0x0801ffff) AM_RAM AM_BASE(&n64_sram) // Cartridge SRAM |
| 32 | 32 | AM_RANGE(0x10000000, 0x13ffffff) AM_ROM AM_REGION("user2", 0) // Cartridge |
| 33 | 33 | AM_RANGE(0x1fc00000, 0x1fc007bf) AM_ROM AM_REGION("user1", 0) // PIF ROM |
| 34 | 34 | AM_RANGE(0x1fc007c0, 0x1fc007ff) AM_DEVREADWRITE_MODERN("rcp", n64_periphs, pif_ram_r, pif_ram_w) |
| r14462 | r14463 | |
| 98 | 98 | 62500000 /* system clock */ |
| 99 | 99 | }; |
| 100 | 100 | |
| 101 | static void mempak_format(UINT8* pak) |
| 102 | { |
| 103 | unsigned char pak_header[] = |
| 104 | { |
| 105 | 0x81,0x01,0x02,0x03, 0x04,0x05,0x06,0x07, 0x08,0x09,0x0a,0x0b, 0x0c,0x0d,0x0e,0x0f, |
| 106 | 0x10,0x11,0x12,0x13, 0x14,0x15,0x16,0x17, 0x18,0x19,0x1a,0x1b, 0x1c,0x1d,0x1e,0x1f, |
| 107 | 0xff,0xff,0xff,0xff, 0x05,0x1a,0x5f,0x13, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, |
| 108 | 0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, 0xff,0xff,0x01,0xff, 0x66,0x25,0x99,0xcd, |
| 109 | 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, |
| 110 | 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, |
| 111 | 0xff,0xff,0xff,0xff, 0x05,0x1a,0x5f,0x13, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, |
| 112 | 0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, 0xff,0xff,0x01,0xff, 0x66,0x25,0x99,0xcd, |
| 113 | 0xff,0xff,0xff,0xff, 0x05,0x1a,0x5f,0x13, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, |
| 114 | 0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, 0xff,0xff,0x01,0xff, 0x66,0x25,0x99,0xcd, |
| 115 | 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, |
| 116 | 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, |
| 117 | 0xff,0xff,0xff,0xff, 0x05,0x1a,0x5f,0x13, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, |
| 118 | 0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, 0xff,0xff,0x01,0xff, 0x66,0x25,0x99,0xcd, |
| 119 | 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, |
| 120 | 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, |
| 121 | 0x00,0x71,0x00,0x03, 0x00,0x03,0x00,0x03, 0x00,0x03,0x00,0x03, 0x00,0x03,0x00,0x03 |
| 122 | }; |
| 123 | |
| 124 | for (int i = 0; i < 0x8000; i += 2) |
| 125 | { |
| 126 | pak[i+0] = 0x00; |
| 127 | pak[i+1] = 0x03; |
| 128 | } |
| 129 | memcpy(pak, pak_header, 272); |
| 130 | } |
| 131 | |
| 101 | 132 | static DEVICE_IMAGE_LOAD(n64_cart) |
| 102 | 133 | { |
| 103 | 134 | int i, length; |
| 135 | n64_periphs *periphs = image.device().machine().device<n64_periphs>("rcp"); |
| 104 | 136 | UINT8 *cart = image.device().machine().region("user2")->base(); |
| 105 | 137 | |
| 106 | 138 | if (image.software_entry() == NULL) |
| r14462 | r14463 | |
| 142 | 174 | } |
| 143 | 175 | } |
| 144 | 176 | |
| 177 | periphs->m_nvram_image = image; |
| 178 | |
| 145 | 179 | logerror("cart length = %d\n", length); |
| 180 | |
| 181 | device_image_interface *battery_image = dynamic_cast<device_image_interface *>(periphs->m_nvram_image); |
| 182 | if(battery_image) |
| 183 | { |
| 184 | printf("Loading\n"); |
| 185 | UINT8 data[0x30800]; |
| 186 | battery_image->battery_load(data, 0x30800, 0x00); |
| 187 | memcpy(n64_sram, data, 0x20000); |
| 188 | memcpy(periphs->m_save_data.eeprom, data + 0x20000, 0x800); |
| 189 | memcpy(periphs->m_save_data.mempak[0], data + 0x20800, 0x8000); |
| 190 | memcpy(periphs->m_save_data.mempak[1], data + 0x28800, 0x8000); |
| 191 | } |
| 192 | else |
| 193 | { |
| 194 | memset(periphs->m_save_data.eeprom, 0, 0x800); |
| 195 | mempak_format(periphs->m_save_data.mempak[0]); |
| 196 | mempak_format(periphs->m_save_data.mempak[1]); |
| 197 | } |
| 146 | 198 | return IMAGE_INIT_PASS; |
| 147 | 199 | } |
| 148 | 200 | |