src/mame/machine/n64.c
| r14463 | r14464 | |
| 118 | 118 | if (boot_checksum == U64(0x000000d057e84864)) |
| 119 | 119 | { |
| 120 | 120 | // CIC-NUS-6101 |
| 121 | | printf("CIC-NUS-6102 detected\n"); |
| 121 | //printf("CIC-NUS-6102 detected\n"); |
| 122 | 122 | pif_ram[0x24] = 0x00; |
| 123 | 123 | pif_ram[0x25] = 0x02; |
| 124 | 124 | pif_ram[0x26] = 0x3f; |
| r14463 | r14464 | |
| 128 | 128 | else if (boot_checksum == U64(0x000000cffb830843) || boot_checksum == U64(0x000000d0027fdf31)) |
| 129 | 129 | { |
| 130 | 130 | // CIC-NUS-6103 |
| 131 | | printf("CIC-NUS-6101 detected\n"); |
| 131 | //printf("CIC-NUS-6101 detected\n"); |
| 132 | 132 | // crc_seed = 0x78; |
| 133 | 133 | pif_ram[0x24] = 0x00; |
| 134 | 134 | pif_ram[0x25] = 0x06; |
| r14463 | r14464 | |
| 138 | 138 | else if (boot_checksum == U64(0x000000d6499e376b)) |
| 139 | 139 | { |
| 140 | 140 | // CIC-NUS-6103 |
| 141 | | printf("CIC-NUS-6103 detected\n"); |
| 141 | //printf("CIC-NUS-6103 detected\n"); |
| 142 | 142 | // crc_seed = 0x78; |
| 143 | 143 | pif_ram[0x24] = 0x00; |
| 144 | 144 | pif_ram[0x25] = 0x02; |
| r14463 | r14464 | |
| 148 | 148 | else if (boot_checksum == U64(0x0000011a4a1604b6)) |
| 149 | 149 | { |
| 150 | 150 | // CIC-NUS-6105 |
| 151 | | printf("CIC-NUS-6105 detected\n"); |
| 151 | //printf("CIC-NUS-6105 detected\n"); |
| 152 | 152 | // crc_seed = 0x91; |
| 153 | 153 | |
| 154 | 154 | // first_rsp = 0; |
| r14463 | r14464 | |
| 160 | 160 | else if (boot_checksum == U64(0x000000d6d5de4ba0)) |
| 161 | 161 | { |
| 162 | 162 | // CIC-NUS-6106 |
| 163 | | printf("CIC-NUS-6106 detected\n"); |
| 163 | //printf("CIC-NUS-6106 detected\n"); |
| 164 | 164 | // crc_seed = 0x85; |
| 165 | 165 | pif_ram[0x24] = 0x00; |
| 166 | 166 | pif_ram[0x25] = 0x02; |
| r14463 | r14464 | |
| 169 | 169 | } |
| 170 | 170 | else |
| 171 | 171 | { |
| 172 | | printf("Unknown BootCode Checksum %08X%08X\n", (UINT32)(boot_checksum>>32),(UINT32)(boot_checksum)); |
| 172 | //printf("Unknown BootCode Checksum %08X%08X\n", (UINT32)(boot_checksum>>32),(UINT32)(boot_checksum)); |
| 173 | 173 | } |
| 174 | 174 | } |
| 175 | 175 | |
| r14463 | r14464 | |
| 350 | 350 | case 0x0014/4: |
| 351 | 351 | for(i = 0x20; i < (0x20 + data); i++) |
| 352 | 352 | { |
| 353 | | printf( "%c", is64_buffer[i] ); |
| 353 | //printf( "%c", is64_buffer[i] ); |
| 354 | 354 | if(is64_buffer[i] == 0x0a) |
| 355 | 355 | { |
| 356 | | printf( "%c", 0x0d ); |
| 356 | //printf( "%c", 0x0d ); |
| 357 | 357 | } |
| 358 | 358 | is64_buffer[i] = 0; |
| 359 | 359 | } |
| r14463 | r14464 | |
| 436 | 436 | |
| 437 | 437 | if ((sp_mem_addr & 0xfff) + (sp_dma_length) > 0x1000) |
| 438 | 438 | { |
| 439 | | printf("sp_dma: dma out of memory area: %08X, %08X\n", sp_mem_addr, sp_dma_length); |
| 439 | //printf("sp_dma: dma out of memory area: %08X, %08X\n", sp_mem_addr, sp_dma_length); |
| 440 | 440 | //fatalerror("sp_dma: dma out of memory area: %08X, %08X\n", sp_mem_addr, sp_dma_length); |
| 441 | 441 | sp_dma_length = 0x1000 - (sp_mem_addr & 0xfff); |
| 442 | 442 | } |
| r14463 | r14464 | |
| 1516 | 1516 | case 0: |
| 1517 | 1517 | case 1: |
| 1518 | 1518 | { |
| 1519 | | printf("Read controller %d status\n", channel + 1); |
| 1519 | //printf("Read controller %d status\n", channel + 1); |
| 1520 | 1520 | rdata[0] = 0x05; |
| 1521 | 1521 | rdata[1] = 0x00; |
| 1522 | 1522 | rdata[2] = 0x01; |
| r14463 | r14464 | |
| 1525 | 1525 | case 2: |
| 1526 | 1526 | case 3: |
| 1527 | 1527 | { |
| 1528 | | printf("Read controller %d status (NC)\n", channel + 1); |
| 1528 | //printf("Read controller %d status (NC)\n", channel + 1); |
| 1529 | 1529 | // not connected |
| 1530 | 1530 | return 1; |
| 1531 | 1531 | } |
| 1532 | 1532 | case 4: |
| 1533 | 1533 | { |
| 1534 | | printf("Read EEPROM status\n"); |
| 1534 | //printf("Read EEPROM status\n"); |
| 1535 | 1535 | rdata[0] = 0x00; |
| 1536 | 1536 | rdata[1] = 0xc0; |
| 1537 | 1537 | rdata[2] = 0x00; |
| r14463 | r14464 | |
| 1565 | 1565 | case 0: //p1 inputs |
| 1566 | 1566 | case 1: //p2 inputs |
| 1567 | 1567 | { |
| 1568 | | printf("Read p%d inputs\n", channel + 1); |
| 1568 | //printf("Read p%d inputs\n", channel + 1); |
| 1569 | 1569 | buttons = input_port_read(machine(), portnames[(channel*3) + 0]); |
| 1570 | 1570 | x = input_port_read(machine(), portnames[(channel*3) + 1]) - 128; |
| 1571 | 1571 | y = input_port_read(machine(), portnames[(channel*3) + 2]) - 128; |
| r14463 | r14464 | |
| 1579 | 1579 | case 2: |
| 1580 | 1580 | case 3: |
| 1581 | 1581 | { |
| 1582 | | printf("Controller %d not connected\n", channel + 1); |
| 1582 | //printf("Controller %d not connected\n", channel + 1); |
| 1583 | 1583 | // not connected |
| 1584 | 1584 | return 1; |
| 1585 | 1585 | } |
| r14463 | r14464 | |
| 1595 | 1595 | address = (sdata[1] << 8) | (sdata[2]); |
| 1596 | 1596 | address &= ~0x1f; |
| 1597 | 1597 | |
| 1598 | | printf("Read mempak at %04x\n", address); |
| 1598 | //printf("Read mempak at %04x\n", address); |
| 1599 | 1599 | |
| 1600 | 1600 | if(address == 0x8000) |
| 1601 | 1601 | { |
| r14463 | r14464 | |
| 1625 | 1625 | UINT32 address = (sdata[1] << 8) | (sdata[2]); |
| 1626 | 1626 | address &= ~0x1f; |
| 1627 | 1627 | |
| 1628 | | printf("Write mempak at %04x\n", address); |
| 1628 | //printf("Write mempak at %04x\n", address); |
| 1629 | 1629 | if (address >= 0x8000) |
| 1630 | 1630 | { |
| 1631 | 1631 | |
| r14463 | r14464 | |
| 1657 | 1657 | |
| 1658 | 1658 | UINT16 block_offset = sdata[1] * 8; |
| 1659 | 1659 | |
| 1660 | | printf("Read EEPROM at %04x\n", block_offset); |
| 1660 | //printf("Read EEPROM at %04x\n", block_offset); |
| 1661 | 1661 | |
| 1662 | 1662 | for(int i=0; i < 8; i++) |
| 1663 | 1663 | { |
| r14463 | r14464 | |
| 1681 | 1681 | |
| 1682 | 1682 | UINT16 block_offset = sdata[1] * 8; |
| 1683 | 1683 | |
| 1684 | | printf("Write EEPROM at %04x\n", block_offset); |
| 1684 | //printf("Write EEPROM at %04x\n", block_offset); |
| 1685 | 1685 | |
| 1686 | 1686 | for(int i = 0; i < 8; i++) |
| 1687 | 1687 | { |
| r14463 | r14464 | |
| 1693 | 1693 | |
| 1694 | 1694 | case 0x06: // Read RTC Status |
| 1695 | 1695 | { |
| 1696 | | printf("Read RTC Status\n"); |
| 1696 | //printf("Read RTC Status\n"); |
| 1697 | 1697 | rdata[0] = 0x00; |
| 1698 | 1698 | rdata[1] = 0x10; |
| 1699 | 1699 | rdata[2] = 0x00; |
| r14463 | r14464 | |
| 1705 | 1705 | switch(sdata[1]) |
| 1706 | 1706 | { |
| 1707 | 1707 | case 0: |
| 1708 | | printf("Read RTC Block Header\n"); |
| 1708 | //printf("Read RTC Block Header\n"); |
| 1709 | 1709 | rdata[0] = 0x00; |
| 1710 | 1710 | rdata[1] = 0x02; |
| 1711 | 1711 | rdata[8] = 0x00; |
| r14463 | r14464 | |
| 1726 | 1726 | rdata[6] = convert_to_bcd(systime.local_time.year % 100); // Year |
| 1727 | 1727 | rdata[7] = convert_to_bcd(systime.local_time.year / 100); // Century |
| 1728 | 1728 | rdata[8] = 0x00; |
| 1729 | | printf("Read RTC Time\n"); |
| 1729 | //printf("Read RTC Time\n"); |
| 1730 | 1730 | return 0; |
| 1731 | 1731 | } |
| 1732 | 1732 | return 1; |
| r14463 | r14464 | |
| 1734 | 1734 | |
| 1735 | 1735 | case 0xff: // reset |
| 1736 | 1736 | { |
| 1737 | | printf("Reset\n"); |
| 1737 | //printf("Reset\n"); |
| 1738 | 1738 | rdata[0] = 0xff; |
| 1739 | 1739 | rdata[1] = 0xff; |
| 1740 | 1740 | rdata[2] = 0xff; |
| r14463 | r14464 | |
| 1753 | 1753 | |
| 1754 | 1754 | void n64_periphs::handle_pif() |
| 1755 | 1755 | { |
| 1756 | | printf("Before:\n"); |
| 1757 | | for(int i = 0; i < 0x40; i++) |
| 1756 | //printf("Before:\n"); |
| 1757 | /*for(int i = 0; i < 0x40; i++) |
| 1758 | 1758 | { |
| 1759 | 1759 | printf("%02x ", pif_cmd[i]); |
| 1760 | 1760 | if((i & 0xf) == 0xf) |
| 1761 | 1761 | { |
| 1762 | 1762 | printf("\n"); |
| 1763 | 1763 | } |
| 1764 | | } |
| 1764 | }*/ |
| 1765 | 1765 | if(pif_cmd[0x3f] == 0x1) // only handle the command if the last byte is 1 |
| 1766 | 1766 | { |
| 1767 | 1767 | int channel = 0; |
| r14463 | r14464 | |
| 1771 | 1771 | while(cmd_ptr < 0x3f && !end) |
| 1772 | 1772 | { |
| 1773 | 1773 | INT8 bytes_to_send = (INT8)pif_cmd[cmd_ptr++]; |
| 1774 | | printf("bytes to send: 0x%02x\n", bytes_to_send); |
| 1774 | //printf("bytes to send: 0x%02x\n", bytes_to_send); |
| 1775 | 1775 | |
| 1776 | 1776 | if (bytes_to_send == -2) |
| 1777 | 1777 | { |
| 1778 | 1778 | end = 1; |
| 1779 | | printf("end\n"); |
| 1779 | //printf("end\n"); |
| 1780 | 1780 | } |
| 1781 | 1781 | else if (bytes_to_send < 0) |
| 1782 | 1782 | { |
| 1783 | | printf("do nothing\n"); |
| 1783 | //printf("do nothing\n"); |
| 1784 | 1784 | // do nothing |
| 1785 | 1785 | } |
| 1786 | 1786 | else |
| r14463 | r14464 | |
| 1791 | 1791 | UINT8 send_buffer[0x40]; |
| 1792 | 1792 | |
| 1793 | 1793 | INT8 bytes_to_recv = pif_cmd[cmd_ptr++]; |
| 1794 | | printf("bytes to receive: 0x%02x\n", bytes_to_recv); |
| 1794 | //printf("bytes to receive: 0x%02x\n", bytes_to_recv); |
| 1795 | 1795 | |
| 1796 | 1796 | if (bytes_to_recv == -2) |
| 1797 | 1797 | { |
| r14463 | r14464 | |
| 1804 | 1804 | } |
| 1805 | 1805 | |
| 1806 | 1806 | int res = pif_channel_handle_command(channel, bytes_to_send, send_buffer, bytes_to_recv, recv_buffer); |
| 1807 | | printf("result: %d\n", res); |
| 1807 | //printf("result: %d\n", res); |
| 1808 | 1808 | |
| 1809 | 1809 | if (res == 0) |
| 1810 | 1810 | { |
| 1811 | | printf("cmd_ptr (%d) + bytes_to_recv (%d) = %d\n", cmd_ptr, bytes_to_recv, cmd_ptr + bytes_to_recv); |
| 1811 | //printf("cmd_ptr (%d) + bytes_to_recv (%d) = %d\n", cmd_ptr, bytes_to_recv, cmd_ptr + bytes_to_recv); |
| 1812 | 1812 | if (cmd_ptr + bytes_to_recv > 0x3f) |
| 1813 | 1813 | { |
| 1814 | 1814 | fatalerror("cmd_ptr overflow\n"); |
| r14463 | r14464 | |
| 1832 | 1832 | pif_ram[0x3f] = 0; |
| 1833 | 1833 | } |
| 1834 | 1834 | |
| 1835 | | printf("After:\n"); |
| 1835 | /*printf("After:\n"); |
| 1836 | 1836 | for(int i = 0; i < 0x40; i++) |
| 1837 | 1837 | { |
| 1838 | 1838 | printf("%02x ", pif_ram[i]); |
| r14463 | r14464 | |
| 1840 | 1840 | { |
| 1841 | 1841 | printf("\n"); |
| 1842 | 1842 | } |
| 1843 | | } |
| 1843 | }*/ |
| 1844 | 1844 | } |
| 1845 | 1845 | |
| 1846 | 1846 | void n64_periphs::pif_dma(int direction) |
| r14463 | r14464 | |
| 1891 | 1891 | |
| 1892 | 1892 | READ32_MEMBER( n64_periphs::si_reg_r ) |
| 1893 | 1893 | { |
| 1894 | | printf("si_reg_r %08x\n", offset * 4); |
| 1894 | //printf("si_reg_r %08x\n", offset * 4); |
| 1895 | 1895 | switch (offset) |
| 1896 | 1896 | { |
| 1897 | 1897 | //case 0x00/4: // SI_DRAM_ADDR_REG |
| r14463 | r14464 | |
| 1905 | 1905 | |
| 1906 | 1906 | WRITE32_MEMBER( n64_periphs::si_reg_w ) |
| 1907 | 1907 | { |
| 1908 | | 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); |
| 1909 | 1909 | switch (offset) |
| 1910 | 1910 | { |
| 1911 | 1911 | case 0x00/4: // SI_DRAM_ADDR_REG |