src/mame/machine/snes.c
| r5568 | r5569 | |
| 8 | 8 | Anthony Kruize |
| 9 | 9 | Based on the original code by Lee Hammerton (aka Savoury Snax) |
| 10 | 10 | Thanks to Anomie for invaluable technical information. |
| 11 | Thanks to byuu for invaluable technical information. |
| 11 | 12 | |
| 12 | 13 | ***************************************************************************/ |
| 13 | 14 | #define __MACHINE_SNES_C |
| 14 | 15 | |
| 15 | 16 | #include "driver.h" |
| 16 | 17 | #include "includes/snes.h" |
| 18 | #include "cpu/superfx/superfx.h" |
| 17 | 19 | #include "cpu/g65816/g65816.h" |
| 18 | 20 | |
| 19 | | // add-on chip emulators |
| 20 | | #include "machine/snesdsp1.c" |
| 21 | | #include "machine/snesdsp2.c" |
| 22 | | #include "machine/snesobc1.c" |
| 23 | | |
| 24 | 21 | /* -- Globals -- */ |
| 25 | 22 | UINT8 *snes_ram = NULL; /* 65816 ram */ |
| 26 | 23 | UINT8 *spc_ram = NULL; /* spc700 ram */ |
| r5568 | r5569 | |
| 58 | 55 | UINT8 oldrol; |
| 59 | 56 | } joypad[4]; |
| 60 | 57 | |
| 58 | // add-on chip emulators |
| 59 | #include "machine/snesdsp1.c" |
| 60 | #include "machine/snesdsp2.c" |
| 61 | #include "machine/snesobc1.c" |
| 62 | #include "machine/snesrtc.c" |
| 63 | #include "machine/snessdd1.c" |
| 61 | 64 | |
| 62 | 65 | /************************************* |
| 63 | 66 | |
| r5568 | r5569 | |
| 348 | 351 | return spc_port_out[offset & 0x3]; |
| 349 | 352 | } |
| 350 | 353 | |
| 354 | if(snes_has_addon_chip == HAS_SUPERFX && cputag_get_cpu(space->machine, "superfx") != NULL) |
| 355 | { |
| 356 | if(offset >= 0x3000 && offset < 0x3300) |
| 357 | { |
| 358 | return superfx_mmio_read(cputag_get_cpu(space->machine, "superfx"), offset); |
| 359 | } |
| 360 | } |
| 361 | else if(snes_has_addon_chip == HAS_RTC) |
| 362 | { |
| 363 | if(offset == 0x2800 || offset == 0x2801) |
| 364 | { |
| 365 | return srtc_mmio_read(space->machine, offset); |
| 366 | } |
| 367 | } |
| 368 | else if(snes_has_addon_chip == HAS_SDD1) |
| 369 | { |
| 370 | if(offset >= 0x4800 && offset < 0x4808) |
| 371 | { |
| 372 | return sdd1_mmio_read(space->machine, offset); |
| 373 | } |
| 374 | } |
| 375 | |
| 351 | 376 | /* offset is from 0x000000 */ |
| 352 | 377 | switch( offset ) |
| 353 | 378 | { |
| r5568 | r5569 | |
| 665 | 690 | |
| 666 | 691 | } |
| 667 | 692 | |
| 693 | //printf("unsupported read: offset == %08x\n", offset); |
| 694 | |
| 668 | 695 | /* Unsupported reads returns open bus */ |
| 669 | 696 | // printf("%02x %02x\n",offset,snes_open_bus_r(space,0)); |
| 670 | 697 | return snes_open_bus_r(space,0); |
| r5568 | r5569 | |
| 687 | 714 | return; |
| 688 | 715 | } |
| 689 | 716 | |
| 717 | if(snes_has_addon_chip == HAS_SUPERFX && cputag_get_cpu(space->machine, "superfx") != NULL) |
| 718 | { |
| 719 | if(offset >= 0x3000 && offset < 0x3300) |
| 720 | { |
| 721 | superfx_mmio_write(cputag_get_cpu(space->machine, "superfx"), offset, data); |
| 722 | return; |
| 723 | } |
| 724 | } |
| 725 | else if(snes_has_addon_chip == HAS_RTC) |
| 726 | { |
| 727 | if(offset == 0x2800 || offset == 0x2801) |
| 728 | { |
| 729 | srtc_mmio_write(space->machine, offset, data); |
| 730 | return; |
| 731 | } |
| 732 | } |
| 733 | else if(snes_has_addon_chip == HAS_SDD1) |
| 734 | { |
| 735 | if((offset >= 0x4300 && offset < 0x4380) || |
| 736 | (offset >= 0x4800 && offset < 0x4808)) |
| 737 | { |
| 738 | sdd1_mmio_write(space->machine, offset, data); |
| 739 | return; |
| 740 | } |
| 741 | } |
| 742 | |
| 690 | 743 | /* offset is from 0x000000 */ |
| 691 | 744 | switch( offset ) |
| 692 | 745 | { |
| r5568 | r5569 | |
| 729 | 782 | break; |
| 730 | 783 | default: |
| 731 | 784 | /* Unknown size so default to 8 & 16 */ |
| 732 | | printf( "Object size unsupported: %d\n", (data & 0xe0) >> 5 ); |
| 785 | logerror( "Object size unsupported: %d\n", (data & 0xe0) >> 5 ); |
| 733 | 786 | |
| 734 | 787 | snes_ppu.oam.size[0] = 1; |
| 735 | 788 | snes_ppu.oam.size[1] = 2; |
| r5568 | r5569 | |
| 1301 | 1354 | break; |
| 1302 | 1355 | } |
| 1303 | 1356 | |
| 1357 | logerror("Unsupported MMIO write: offset %08x = %02x\n", offset, data); |
| 1358 | |
| 1304 | 1359 | snes_ram[offset] = data; |
| 1305 | 1360 | } |
| 1306 | 1361 | |
| 1362 | WRITE_LINE_DEVICE_HANDLER( snes_extern_irq_w ) |
| 1363 | { |
| 1364 | cputag_set_input_line(device->machine, "maincpu", G65816_LINE_IRQ, state); |
| 1365 | } |
| 1366 | |
| 1307 | 1367 | /************************************* |
| 1308 | 1368 | |
| 1309 | 1369 | Memory Handlers |
| r5568 | r5569 | |
| 1391 | 1451 | value = snes_r_io(space, address); |
| 1392 | 1452 | else if (address < 0x8000) |
| 1393 | 1453 | { |
| 1394 | | if (snes_has_addon_chip == HAS_OBC1) |
| 1454 | if (snes_has_addon_chip == HAS_SUPERFX && cputag_get_cpu(space->machine, "superfx") != NULL) |
| 1455 | value = snes_ram[0x700000 + (address & 0x1fff)]; |
| 1456 | else if (snes_has_addon_chip == HAS_OBC1) |
| 1395 | 1457 | value = obc1_read(space, offset); |
| 1396 | 1458 | else if ((snes_has_addon_chip == HAS_DSP2) && (offset >= 0x200000)) |
| 1397 | 1459 | value = (address < 0x7000) ? DSP2_read() : 0x00; |
| 1398 | 1460 | else if ((snes_cart.mode == SNES_MODE_21) && (snes_has_addon_chip == HAS_DSP1) && (offset < 0x100000)) |
| 1399 | 1461 | value = (address < 0x7000) ? DSP1_getDr() : DSP1_getSr(); |
| 1400 | 1462 | else |
| 1463 | { |
| 1464 | logerror( "snes_r_bank1: Unmapped external chip read: %04x\n", address ); |
| 1401 | 1465 | value = 0xff; /* Reserved */ |
| 1466 | } |
| 1402 | 1467 | } |
| 1403 | 1468 | else if ((snes_cart.mode == SNES_MODE_20) && (snes_has_addon_chip == HAS_DSP1) && (offset >= 0x200000)) |
| 1404 | 1469 | value = (address < 0xc000) ? DSP1_getDr() : DSP1_getSr(); |
| r5568 | r5569 | |
| 1433 | 1498 | value = snes_ram[0x306000 + (offset & mask)]; |
| 1434 | 1499 | } |
| 1435 | 1500 | else |
| 1501 | { |
| 1502 | logerror( "snes_r_bank2: Unmapped external chip read: %04x\n", address ); |
| 1436 | 1503 | value = 0xff; |
| 1504 | } |
| 1437 | 1505 | } |
| 1438 | 1506 | /* some dsp1 games use these banks 0x30 to 0x3f at address 0x8000 */ |
| 1439 | 1507 | else if ((snes_cart.mode == SNES_MODE_20) && (snes_has_addon_chip == HAS_DSP1)) |
| r5568 | r5569 | |
| 1471 | 1539 | UINT8 value = 0xff; |
| 1472 | 1540 | UINT16 address = offset & 0xffff; |
| 1473 | 1541 | |
| 1474 | | if (snes_cart.mode & 5) /* Mode 20 & 22 */ |
| 1542 | if (snes_has_addon_chip == HAS_SUPERFX && cputag_get_cpu(space->machine, "superfx") != NULL) |
| 1475 | 1543 | { |
| 1544 | value = snes_ram[0x600000 + offset]; |
| 1545 | } |
| 1546 | else if (snes_cart.mode & 5) /* Mode 20 & 22 */ |
| 1547 | { |
| 1476 | 1548 | if (address >= 0x8000) |
| 1477 | 1549 | value = snes_ram[0x600000 + offset]; |
| 1478 | 1550 | /* some other dsp1 games use these banks 0x60 to 0x6f at address 0x0000 */ |
| 1479 | 1551 | else if (snes_has_addon_chip == HAS_DSP1) |
| 1480 | 1552 | value = (address >= 0x4000) ? DSP1_getSr() : DSP1_getDr(); |
| 1481 | 1553 | else |
| 1554 | { |
| 1555 | logerror( "snes_r_bank4: Unmapped external chip read: %04x\n", address ); |
| 1482 | 1556 | value = 0xff; /* Reserved */ |
| 1557 | } |
| 1483 | 1558 | } |
| 1484 | 1559 | else if (snes_cart.mode & 0x0a) /* Mode 21 & 25 */ |
| 1485 | 1560 | value = snes_ram[0x600000 + offset]; |
| r5568 | r5569 | |
| 1493 | 1568 | UINT8 value; |
| 1494 | 1569 | UINT16 address = offset & 0xffff; |
| 1495 | 1570 | |
| 1496 | | if ((snes_cart.mode & 5) &&(address < 0x8000)) /* Mode 20 & 22 */ |
| 1571 | if (snes_has_addon_chip == HAS_SUPERFX && cputag_get_cpu(space->machine, "superfx") != NULL) |
| 1497 | 1572 | { |
| 1573 | value = snes_ram[0x700000 + offset]; |
| 1574 | } |
| 1575 | else if ((snes_cart.mode & 5) &&(address < 0x8000)) /* Mode 20 & 22 */ |
| 1576 | { |
| 1498 | 1577 | if (snes_cart.sram > 0) |
| 1499 | 1578 | { |
| 1500 | 1579 | int mask = ((snes_cart.sram * 1024) - 1) | 0xff0000; /* Limit SRAM size to what's actually present */ |
| 1501 | 1580 | value = snes_ram[0x700000 + (offset & mask)]; |
| 1502 | 1581 | } |
| 1503 | 1582 | else |
| 1583 | { |
| 1584 | logerror( "snes_r_bank5: Unmapped external chip read: %04x\n", address ); |
| 1504 | 1585 | value = 0xff; /* Reserved */ |
| 1586 | } |
| 1505 | 1587 | } |
| 1506 | 1588 | else |
| 1589 | { |
| 1507 | 1590 | value = snes_ram[0x700000 + offset]; |
| 1591 | } |
| 1508 | 1592 | |
| 1509 | 1593 | return value; |
| 1510 | 1594 | } |
| r5568 | r5569 | |
| 1517 | 1601 | |
| 1518 | 1602 | if (address < 0x8000) |
| 1519 | 1603 | { |
| 1520 | | if (snes_cart.mode != SNES_MODE_25) |
| 1604 | if(address >= 0x6000 && snes_has_addon_chip == HAS_SUPERFX && cputag_get_cpu(space->machine, "superfx") != NULL) |
| 1605 | logerror( "snes_r_bank6 hit in Super FX mode, please fix me\n" ); |
| 1606 | else if (snes_cart.mode != SNES_MODE_25) |
| 1521 | 1607 | value = memory_read_byte(space, offset); |
| 1522 | 1608 | else /* Mode 25 has SRAM not mirrored from lower banks */ |
| 1523 | 1609 | { |
| r5568 | r5569 | |
| 1530 | 1616 | value = snes_ram[0x806000 + (offset & mask)]; /* SRAM */ |
| 1531 | 1617 | } |
| 1532 | 1618 | else /* Area 0x6000-0x8000 with offset < 0x300000 is reserved */ |
| 1619 | { |
| 1620 | logerror( "snes_r_bank6: Unmapped external chip read: %04x\n", address ); |
| 1533 | 1621 | value = 0xff; |
| 1622 | } |
| 1534 | 1623 | } |
| 1535 | 1624 | } |
| 1536 | 1625 | else if ((snes_cart.mode == SNES_MODE_20) && (snes_has_addon_chip == HAS_DSP1) && (offset >= 0x200000)) |
| r5568 | r5569 | |
| 1549 | 1638 | UINT8 value; |
| 1550 | 1639 | UINT16 address = offset & 0xffff; |
| 1551 | 1640 | |
| 1641 | if(snes_has_addon_chip == HAS_SUPERFX && cputag_get_cpu(space->machine, "superfx") != NULL) |
| 1642 | { |
| 1643 | logerror( "snes_r_bank7 hit in Super FX mode, please fix me\n" ); |
| 1644 | } |
| 1552 | 1645 | if (snes_cart.mode & 5) /* Mode 20 & 22 */ |
| 1553 | 1646 | { |
| 1554 | 1647 | if (address < 0x8000) |
| r5568 | r5569 | |
| 1583 | 1676 | else if ((snes_cart.mode == SNES_MODE_21) && (snes_has_addon_chip == HAS_DSP1) && (offset < 0x100000)) |
| 1584 | 1677 | DSP1_setDr(data); |
| 1585 | 1678 | else |
| 1586 | | logerror( "Attempt to write to reserved address: %X\n", offset ); |
| 1679 | logerror( "snes_w_bank1: Attempt to write to reserved address: %x = %02x\n", offset, data ); |
| 1587 | 1680 | } |
| 1588 | 1681 | else if ((snes_cart.mode == SNES_MODE_20) && (snes_has_addon_chip == HAS_DSP1) && (offset >= 0x200000)) |
| 1589 | 1682 | DSP1_setDr(data); |
| r5568 | r5569 | |
| 1611 | 1704 | else if ((snes_cart.mode == SNES_MODE_21) && (snes_cart.sram > 0)) |
| 1612 | 1705 | { |
| 1613 | 1706 | int mask = ((snes_cart.sram * 1024) - 1); /* Limit SRAM size to what's actually present */ |
| 1707 | logerror( "snes_w_bank2 hit in Super FX mode, please fix me if necessary\n" ); |
| 1614 | 1708 | offset -= 0x6000; |
| 1615 | 1709 | snes_ram[0x306000 + (offset & mask)] = data; |
| 1616 | 1710 | } |
| 1617 | 1711 | else |
| 1618 | | logerror("Attempt to write to reserved address: %X\n", offset + 0x300000); |
| 1712 | logerror("snes_w_bank2: Attempt to write to reserved address: %X = %02x\n", offset + 0x300000, data); |
| 1619 | 1713 | } |
| 1620 | 1714 | /* some dsp1 games use these banks 0x30 to 0x3f at address 0x8000 */ |
| 1621 | 1715 | else if ((snes_cart.mode == SNES_MODE_20) && (snes_has_addon_chip == HAS_DSP1)) |
| r5568 | r5569 | |
| 1631 | 1725 | { |
| 1632 | 1726 | UINT16 address = offset & 0xffff; |
| 1633 | 1727 | |
| 1634 | | if (snes_cart.mode & 5) /* Mode 20 & 22 */ |
| 1728 | if (snes_has_addon_chip == HAS_SUPERFX && cputag_get_cpu(space->machine, "superfx") != NULL) |
| 1635 | 1729 | { |
| 1730 | snes_ram[0x600000 + offset] = data; |
| 1731 | } |
| 1732 | else if (snes_cart.mode & 5) /* Mode 20 & 22 */ |
| 1733 | { |
| 1636 | 1734 | if (address >= 0x8000) |
| 1735 | { |
| 1637 | 1736 | logerror("Attempt to write to ROM address: %X\n", offset + 0x600000); |
| 1737 | } |
| 1638 | 1738 | else if (snes_has_addon_chip == HAS_DSP1) |
| 1739 | { |
| 1639 | 1740 | DSP1_setDr(data); |
| 1741 | } |
| 1640 | 1742 | else |
| 1641 | | logerror("Attempt to write to reserved address: %X\n", offset + 0x600000); |
| 1743 | { |
| 1744 | logerror("snes_w_bank4: Attempt to write to reserved address: %X = %02x\n", offset + 0x600000, data); |
| 1745 | } |
| 1642 | 1746 | } |
| 1643 | 1747 | else if (snes_cart.mode & 0x0a) |
| 1748 | { |
| 1644 | 1749 | logerror("Attempt to write to ROM address: %X\n", offset + 0x600000); |
| 1750 | } |
| 1645 | 1751 | } |
| 1646 | 1752 | |
| 1647 | 1753 | /* 0x700000 - 0x7dffff */ |
| r5568 | r5569 | |
| 1649 | 1755 | { |
| 1650 | 1756 | UINT16 address = offset & 0xffff; |
| 1651 | 1757 | |
| 1652 | | if ((snes_cart.mode & 5) && (address < 0x8000)) /* Mode 20 & 22 */ |
| 1758 | if (snes_has_addon_chip == HAS_SUPERFX && cputag_get_cpu(space->machine, "superfx") != NULL) |
| 1653 | 1759 | { |
| 1760 | snes_ram[0x700000 + offset] = data; |
| 1761 | } |
| 1762 | else if ((snes_cart.mode & 5) && (address < 0x8000)) /* Mode 20 & 22 */ |
| 1763 | { |
| 1654 | 1764 | if (snes_cart.sram > 0) |
| 1655 | 1765 | { |
| 1656 | 1766 | int mask = ((snes_cart.sram * 1024) - 1) | 0xff0000; /* Limit SRAM size to what's actually present */ |
| 1657 | 1767 | snes_ram[0x700000 + (offset & mask)] = data; |
| 1658 | 1768 | } |
| 1659 | 1769 | else |
| 1660 | | logerror("Attempt to write to reserved address: %X\n", offset + 0x600000); |
| 1770 | { |
| 1771 | logerror("snes_w_bank5: Attempt to write to reserved address: %X = %02x\n", offset + 0x700000, data); |
| 1772 | } |
| 1661 | 1773 | } |
| 1662 | 1774 | else if (snes_cart.mode & 0x0a) |
| 1775 | { |
| 1663 | 1776 | logerror("Attempt to write to ROM address: %X\n", offset + 0x700000); |
| 1777 | } |
| 1664 | 1778 | } |
| 1665 | 1779 | |
| 1666 | 1780 | |
| r5568 | r5569 | |
| 1671 | 1785 | |
| 1672 | 1786 | if (address < 0x8000) |
| 1673 | 1787 | { |
| 1788 | if (address >= 0x6000 && snes_has_addon_chip == HAS_SUPERFX && cputag_get_cpu(space->machine, "superfx") != NULL) |
| 1789 | { |
| 1790 | logerror( "snes_w_bank6 hit (RAM) in Super FX mode, please fix me\n" ); |
| 1791 | } |
| 1674 | 1792 | if (snes_cart.mode != SNES_MODE_25) |
| 1675 | 1793 | { |
| 1676 | 1794 | if (offset < 0x300000) |
| r5568 | r5569 | |
| 1694 | 1812 | snes_ram[0xb06000 + (offset & mask)] = data; |
| 1695 | 1813 | } |
| 1696 | 1814 | else /* Area in 0x6000-0x8000 && offset < 0x300000 is Reserved! */ |
| 1697 | | logerror("Attempt to write to reserved address: %X\n", offset + 0x800000); |
| 1815 | logerror("snes_w_bank6: Attempt to write to reserved address: %X = %02x\n", offset + 0x800000, data); |
| 1698 | 1816 | } |
| 1699 | 1817 | } |
| 1700 | 1818 | else if ((snes_cart.mode == SNES_MODE_20) && (snes_has_addon_chip == HAS_DSP1) && (offset >= 0x200000)) |
| 1701 | 1819 | DSP1_setDr(data); |
| 1702 | 1820 | else if ((snes_cart.mode == SNES_MODE_20) && (snes_has_addon_chip == HAS_DSP2) && (offset >= 0x200000) && (address < 0xc000)) |
| 1703 | 1821 | DSP2_write(data); |
| 1822 | else if (snes_has_addon_chip == HAS_SUPERFX && cputag_get_cpu(space->machine, "superfx") != NULL) |
| 1823 | logerror( "snes_w_bank6 hit (ROM) in Super FX mode, please fix me\n" ); |
| 1704 | 1824 | else |
| 1705 | 1825 | logerror("Attempt to write to ROM address: %X\n", offset + 0x800000); |
| 1706 | 1826 | } |
| r5568 | r5569 | |
| 1711 | 1831 | { |
| 1712 | 1832 | UINT16 address = offset & 0xffff; |
| 1713 | 1833 | |
| 1714 | | if (snes_cart.mode & 5) /* Mode 20 & 22 */ |
| 1834 | if (snes_has_addon_chip == HAS_SUPERFX && cputag_get_cpu(space->machine, "superfx") != NULL) |
| 1715 | 1835 | { |
| 1836 | if (offset >= 0x200000) |
| 1837 | { |
| 1838 | logerror( "snes_w_bank7 hit (ROM) in Super FX mode, please fix me\n" ); |
| 1839 | } |
| 1840 | else |
| 1841 | { |
| 1842 | logerror( "snes_w_bank7 hit (RAM) in Super FX mode, please fix me\n" ); |
| 1843 | } |
| 1844 | } |
| 1845 | else if (snes_cart.mode & 5) /* Mode 20 & 22 */ |
| 1846 | { |
| 1716 | 1847 | if (address < 0x8000) |
| 1717 | 1848 | { |
| 1718 | 1849 | if (offset >= 0x3e0000) |
| r5568 | r5569 | |
| 1723 | 1854 | snes_w_bank4(space, offset - 0x200000, data); |
| 1724 | 1855 | } |
| 1725 | 1856 | else |
| 1726 | | logerror("Attempt to write to ROM address: %X\n", offset + 0xc00000); |
| 1857 | logerror("snes_w_bank7: Attempt to write to ROM address: %X = %02x\n", offset + 0xc00000, data); |
| 1727 | 1858 | } |
| 1728 | 1859 | else if (snes_cart.mode & 0x0a) |
| 1729 | 1860 | logerror("Attempt to write to ROM address: %X\n", offset + 0xc00000); |
| r5568 | r5569 | |
| 1872 | 2003 | snes_ram[WRMPYA] = 0xff; |
| 1873 | 2004 | snes_ram[WRDIVL] = 0xff; |
| 1874 | 2005 | snes_ram[WRDIVH] = 0xff; |
| 2006 | |
| 2007 | sdd1_init(machine); |
| 1875 | 2008 | } |
| 1876 | 2009 | |
| 1877 | 2010 | MACHINE_RESET( snes ) |
| r5568 | r5569 | |
| 1894 | 2027 | snes_htmult = 1; |
| 1895 | 2028 | snes_ppu.interlace = 1; |
| 1896 | 2029 | snes_ppu.obj_interlace = 1; |
| 2030 | |
| 2031 | srtc_reset(machine); |
| 2032 | sdd1_reset(machine); |
| 1897 | 2033 | } |
| 1898 | 2034 | |
| 1899 | 2035 | |
| r5568 | r5569 | |
| 2314 | 2450 | mask <<= 1; |
| 2315 | 2451 | } |
| 2316 | 2452 | } |
| 2453 | |
| 2454 | READ8_HANDLER( superfx_r_bank1 ) |
| 2455 | { |
| 2456 | return snes_ram[offset | 0x8000]; |
| 2457 | } |
| 2458 | |
| 2459 | READ8_HANDLER( superfx_r_bank2 ) |
| 2460 | { |
| 2461 | return snes_ram[0x400000 + offset]; |
| 2462 | } |
| 2463 | |
| 2464 | READ8_HANDLER( superfx_r_bank3 ) |
| 2465 | { |
| 2466 | return snes_ram[0x600000 + offset]; |
| 2467 | } |
| 2468 | |
| 2469 | WRITE8_HANDLER( superfx_w_bank1 ) |
| 2470 | { |
| 2471 | // Do nothing; can't write to cart ROM. |
| 2472 | } |
| 2473 | |
| 2474 | WRITE8_HANDLER( superfx_w_bank2 ) |
| 2475 | { |
| 2476 | // Do nothing; can't write to cart ROM. |
| 2477 | } |
| 2478 | |
| 2479 | WRITE8_HANDLER( superfx_w_bank3 ) |
| 2480 | { |
| 2481 | snes_ram[0x600000 + offset] = data; |
| 2482 | } |
src/emu/cpu/superfx/superfx.c
| r5568 | r5569 | |
| 18 | 18 | typedef struct _superfx_state superfx_state; |
| 19 | 19 | struct _superfx_state |
| 20 | 20 | { |
| 21 | superfx_config config; |
| 22 | |
| 23 | devcb_resolved_write_line out_irq_func; |
| 24 | |
| 21 | 25 | UINT8 pipeline; |
| 26 | UINT16 ramaddr; // RAM Address |
| 22 | 27 | |
| 23 | 28 | UINT16 r[16]; // GPRs |
| 24 | 29 | UINT16 sfr; // Status Flag Register |
| r5568 | r5569 | |
| 41 | 46 | UINT32 ramcl; // Clock ticks until RAMDR is valid; |
| 42 | 47 | UINT16 ramar; // RAM Buffer Address Register |
| 43 | 48 | UINT8 ramdr; // RAM Buffer Data Register |
| 44 | | UINT16 ramaddr; // RAM Address |
| 45 | 49 | |
| 46 | 50 | UINT16 *sreg; // Source Register (From) |
| 47 | 51 | UINT8 sreg_idx;// Source Register (To), index |
| r5568 | r5569 | |
| 73 | 77 | |
| 74 | 78 | /*****************************************************************************/ |
| 75 | 79 | |
| 76 | | static void superfx_regs_reset(superfx_state *cpustate); |
| 80 | INLINE void superfx_regs_reset(superfx_state *cpustate); |
| 77 | 81 | static void superfx_update_speed(superfx_state *cpustate); |
| 78 | 82 | static void superfx_cache_flush(superfx_state *cpustate); |
| 79 | | static UINT8 superfx_cache_mmio_read(superfx_state *cpustate, UINT16 addr); |
| 83 | static UINT8 superfx_cache_mmio_read(superfx_state *cpustate, UINT32 addr); |
| 80 | 84 | static void superfx_cache_mmio_write(superfx_state *cpustate, UINT32 addr, UINT8 data); |
| 81 | 85 | static void superfx_memory_reset(superfx_state *cpustate); |
| 82 | | static UINT8 superfx_bus_read(superfx_state *cpustate, UINT32 addr); |
| 83 | | static void superfx_bus_write(superfx_state *cpustate, UINT32 addr, UINT8 data); |
| 84 | | static void superfx_pixelcache_flush(superfx_state *cpustate, INT32 line); |
| 85 | | static void superfx_plot(superfx_state *cpustate, UINT8 x, UINT8 y); |
| 86 | | static UINT8 superfx_rpix(superfx_state *cpustate, UINT16 r1, UINT16 r2); |
| 87 | | static UINT8 superfx_color(superfx_state *cpustate, UINT8 source); |
| 88 | | static UINT8 superfx_rambuffer_sync(superfx_state *cpustate); |
| 89 | | static UINT8 superfx_rambuffer_read(superfx_state *cpustate, UINT16 addr); |
| 90 | | static void superfx_rambuffer_write(superfx_state *cpustate, UINT16 addr, UINT8 val); |
| 91 | | static void superfx_rombuffer_sync(superfx_state *cpustate); |
| 92 | | static void superfx_rombuffer_update(superfx_state *cpustate); |
| 93 | | static UINT8 superfx_rombuffer_read(superfx_state *cpustate); |
| 94 | | static void superfx_gpr_write(superfx_state *cpustate, UINT8 r, UINT16 data); |
| 86 | INLINE UINT8 superfx_bus_read(superfx_state *cpustate, UINT32 addr); |
| 87 | INLINE void superfx_bus_write(superfx_state *cpustate, UINT32 addr, UINT8 data); |
| 88 | INLINE void superfx_pixelcache_flush(superfx_state *cpustate, INT32 line); |
| 89 | INLINE void superfx_plot(superfx_state *cpustate, UINT8 x, UINT8 y); |
| 90 | static UINT8 superfx_rpix(superfx_state *cpustate, UINT8 r1, UINT8 r2); |
| 91 | INLINE UINT8 superfx_color(superfx_state *cpustate, UINT8 source); |
| 92 | |
| 93 | INLINE void superfx_rambuffer_sync(superfx_state *cpustate); |
| 94 | INLINE UINT8 superfx_rambuffer_read(superfx_state *cpustate, UINT16 addr); |
| 95 | INLINE void superfx_rambuffer_write(superfx_state *cpustate, UINT16 addr, UINT8 val); |
| 96 | |
| 97 | INLINE void superfx_rombuffer_sync(superfx_state *cpustate); |
| 98 | INLINE void superfx_rombuffer_update(superfx_state *cpustate); |
| 99 | INLINE UINT8 superfx_rombuffer_read(superfx_state *cpustate); |
| 100 | |
| 101 | INLINE void superfx_gpr_write(superfx_state *cpustate, UINT8 r, UINT16 data); |
| 95 | 102 | INLINE UINT8 superfx_op_read(superfx_state *cpustate, UINT16 addr); |
| 96 | 103 | INLINE UINT8 superfx_peekpipe(superfx_state *cpustate); |
| 97 | 104 | INLINE UINT8 superfx_pipe(superfx_state *cpustate); |
| 98 | | static void superfx_add_clocks_internal(superfx_state *cpustate, INT32 clocks); |
| 105 | INLINE void superfx_add_clocks_internal(superfx_state *cpustate, UINT32 clocks); |
| 99 | 106 | static void superfx_timing_reset(superfx_state *cpustate); |
| 100 | 107 | |
| 101 | 108 | /*****************************************************************************/ |
| r5568 | r5569 | |
| 109 | 116 | #define SUPERFX_SFR_Z_SET ((cpustate->sfr & SUPERFX_SFR_Z) ? 1 : 0) |
| 110 | 117 | #define SUPERFX_SFR_Z_CLEAR ((cpustate->sfr & SUPERFX_SFR_Z) ? 0 : 1) |
| 111 | 118 | |
| 112 | | static void superfx_regs_reset(superfx_state *cpustate) |
| 119 | INLINE void superfx_regs_reset(superfx_state *cpustate) |
| 113 | 120 | { |
| 114 | 121 | cpustate->sfr &= ~(SUPERFX_SFR_B | SUPERFX_SFR_ALT3); |
| 115 | 122 | |
| r5568 | r5569 | |
| 138 | 145 | } |
| 139 | 146 | } |
| 140 | 147 | |
| 141 | | static UINT8 superfx_cache_mmio_read(superfx_state *cpustate, UINT16 addr) |
| 148 | static UINT8 superfx_cache_mmio_read(superfx_state *cpustate, UINT32 addr) |
| 142 | 149 | { |
| 143 | 150 | addr = (addr + cpustate->cbr) & 0x1ff; |
| 144 | 151 | return cpustate->cache.buffer[addr]; |
| r5568 | r5569 | |
| 172 | 179 | } |
| 173 | 180 | } |
| 174 | 181 | |
| 175 | | static UINT8 superfx_bus_read(superfx_state *cpustate, UINT32 addr) |
| 182 | INLINE UINT8 superfx_bus_read(superfx_state *cpustate, UINT32 addr) |
| 176 | 183 | { |
| 177 | | //printf( "superfx_bus_read: %08x\n", addr ); |
| 178 | 184 | return memory_read_byte(cpustate->program, addr); |
| 179 | 185 | } |
| 180 | 186 | |
| 181 | | static void superfx_bus_write(superfx_state *cpustate, UINT32 addr, UINT8 data) |
| 187 | INLINE void superfx_bus_write(superfx_state *cpustate, UINT32 addr, UINT8 data) |
| 182 | 188 | { |
| 183 | 189 | memory_write_byte(cpustate->program, addr, data); |
| 184 | | //printf( "superfx_bus_write: %08x = %02x\n", addr, data ); |
| 185 | | // TODO: Hook up to the same memory map as the main 65C816 CPU. See src/chip/superfx/bus/bus.cpp in the bsnes source code. |
| 186 | 190 | } |
| 187 | 191 | |
| 188 | | static void superfx_pixelcache_flush(superfx_state *cpustate, INT32 line) |
| 192 | INLINE void superfx_pixelcache_flush(superfx_state *cpustate, INT32 line) |
| 189 | 193 | { |
| 190 | 194 | UINT8 x = cpustate->pixelcache[line].offset << 3; |
| 191 | 195 | UINT8 y = cpustate->pixelcache[line].offset >> 5; |
| r5568 | r5569 | |
| 199 | 203 | return; |
| 200 | 204 | } |
| 201 | 205 | |
| 202 | | switch((cpustate->por & SUPERFX_POR_OBJ) ? SUPERFX_SCMR_HT3 : (cpustate->scmr & SUPERFX_SCMR_HT_MASK)) |
| 206 | switch(((cpustate->por & SUPERFX_POR_OBJ) ? SUPERFX_SCMR_HT3 : (cpustate->scmr & SUPERFX_SCMR_HT_MASK))) |
| 203 | 207 | { |
| 204 | 208 | case SUPERFX_SCMR_HT0: |
| 205 | 209 | cn = ((x & 0xf8) << 1) + ((y & 0xf8) >> 3); |
| 206 | 210 | break; |
| 207 | 211 | case SUPERFX_SCMR_HT1: |
| 208 | | cn = ((x & 0xf8) << 1) + ((y & 0xf8) >> 1) + ((y & 0xf8) >> 3); |
| 212 | cn = ((x & 0xf8) << 1) + ((x & 0xf8) >> 1) + ((y & 0xf8) >> 3); |
| 209 | 213 | break; |
| 210 | 214 | case SUPERFX_SCMR_HT2: |
| 211 | | cn = ((x & 0xf8) << 1) + ((y & 0xf8) >> 0) + ((y & 0xf8) >> 3); |
| 215 | cn = ((x & 0xf8) << 1) + ((x & 0xf8) << 0) + ((y & 0xf8) >> 3); |
| 212 | 216 | break; |
| 213 | 217 | case SUPERFX_SCMR_HT3: |
| 214 | | cn = ((y & 0x80) << 2) + ((x & 0x80) << 1) + ((y & 0x78) << 1) + ((x & 0x78) >> 2); |
| 218 | cn = ((y & 0x80) << 2) + ((x & 0x80) << 1) + ((y & 0x78) << 1) + ((x & 0x78) >> 3); |
| 215 | 219 | break; |
| 216 | 220 | } |
| 217 | 221 | |
| r5568 | r5569 | |
| 219 | 223 | |
| 220 | 224 | for(n = 0; n < bpp; n++) |
| 221 | 225 | { |
| 222 | | UINT8 byte = ((n >> 1) << 4) + (n & 1); // = [n]{ 0, 1, 16, 17, 32, 33, 48, 49 }; |
| 226 | UINT32 byte = ((n >> 1) << 4) + (n & 1); // = [n]{ 0, 1, 16, 17, 32, 33, 48, 49 }; |
| 223 | 227 | UINT8 data = 0x00; |
| 224 | 228 | UINT32 x = 0; |
| 225 | 229 | for(x = 0; x < 8; x++) |
| r5568 | r5569 | |
| 230 | 234 | { |
| 231 | 235 | superfx_add_clocks_internal(cpustate, cpustate->memory_access_speed); |
| 232 | 236 | data &= cpustate->pixelcache[line].bitpend; |
| 233 | | //printf( "superfx_pixelcache_flush: calling superfx_bus_read\n" ); |
| 234 | 237 | data |= superfx_bus_read(cpustate, addr + byte) & ~cpustate->pixelcache[line].bitpend; |
| 235 | 238 | } |
| 236 | 239 | superfx_add_clocks_internal(cpustate, cpustate->memory_access_speed); |
| r5568 | r5569 | |
| 240 | 243 | cpustate->pixelcache[line].bitpend = 0x00; |
| 241 | 244 | } |
| 242 | 245 | |
| 243 | | static void superfx_plot(superfx_state *cpustate, UINT8 x, UINT8 y) |
| 246 | INLINE void superfx_plot(superfx_state *cpustate, UINT8 x, UINT8 y) |
| 244 | 247 | { |
| 245 | 248 | UINT8 color = cpustate->colr; |
| 246 | 249 | UINT16 offset = (y << 5) + (x >> 3); |
| 247 | 250 | |
| 248 | | printf( "plot: %02x at %d, %d\n", color, x, y ); |
| 249 | | |
| 250 | | if((cpustate->por & SUPERFX_POR_DITHER) && ((cpustate->scmr & SUPERFX_SCMR_MD) != 3)) |
| 251 | if((cpustate->por & SUPERFX_POR_DITHER) != 0 && (cpustate->scmr & SUPERFX_SCMR_MD) != 3) |
| 251 | 252 | { |
| 252 | 253 | if((x ^ y) & 1) |
| 253 | 254 | { |
| r5568 | r5569 | |
| 256 | 257 | color &= 0x0f; |
| 257 | 258 | } |
| 258 | 259 | |
| 259 | | if(!(cpustate->por & SUPERFX_POR_TRANSPARENT)) |
| 260 | if((cpustate->por & SUPERFX_POR_TRANSPARENT) == 0) |
| 260 | 261 | { |
| 261 | 262 | if((cpustate->scmr & SUPERFX_SCMR_MD) == 3) |
| 262 | 263 | { |
| r5568 | r5569 | |
| 303 | 304 | } |
| 304 | 305 | } |
| 305 | 306 | |
| 306 | | static UINT8 superfx_rpix(superfx_state *cpustate, UINT16 x, UINT16 y) |
| 307 | static UINT8 superfx_rpix(superfx_state *cpustate, UINT8 x, UINT8 y) |
| 307 | 308 | { |
| 308 | 309 | UINT32 cn = 0; |
| 309 | | UINT32 bpp = 2 << ((cpustate->scmr & SUPERFX_SCMR_MD) - ((cpustate->scmr & SUPERFX_SCMR_MD) >> 1)); // = [regs.scmr.md]{ 2, 4, 4, 8 }; |
| 310 | UINT32 bpp = 0; |
| 310 | 311 | UINT32 addr = 0; |
| 311 | 312 | UINT8 data = 0x00; |
| 312 | 313 | UINT32 n = 0; |
| r5568 | r5569 | |
| 314 | 315 | superfx_pixelcache_flush(cpustate, 1); |
| 315 | 316 | superfx_pixelcache_flush(cpustate, 0); |
| 316 | 317 | |
| 318 | bpp = 2 << ((cpustate->scmr & SUPERFX_SCMR_MD) - ((cpustate->scmr & SUPERFX_SCMR_MD) >> 1)); // = [regs.scmr.md]{ 2, 4, 4, 8 }; |
| 319 | |
| 317 | 320 | switch((cpustate->por & SUPERFX_POR_OBJ) ? SUPERFX_SCMR_HT3 : (cpustate->scmr & SUPERFX_SCMR_HT_MASK)) |
| 318 | 321 | { |
| 319 | 322 | case SUPERFX_SCMR_HT0: |
| 320 | 323 | cn = ((x & 0xf8) << 1) + ((y & 0xf8) >> 3); |
| 321 | 324 | break; |
| 322 | 325 | case SUPERFX_SCMR_HT1: |
| 323 | | cn = ((x & 0xf8) << 1) + ((y & 0xf8) >> 1) + ((y & 0xf8) >> 3); |
| 326 | cn = ((x & 0xf8) << 1) + ((x & 0xf8) >> 1) + ((y & 0xf8) >> 3); |
| 324 | 327 | break; |
| 325 | 328 | case SUPERFX_SCMR_HT2: |
| 326 | | cn = ((x & 0xf8) << 1) + ((y & 0xf8) >> 0) + ((y & 0xf8) >> 3); |
| 327 | | break; |
| 329 | cn = ((x & 0xf8) << 1) + ((x & 0xf8) << 0) + ((y & 0xf8) >> 3); |
| 330 | break; |
| 328 | 331 | case SUPERFX_SCMR_HT3: |
| 329 | | cn = ((y & 0x80) << 2) + ((x & 0x80) << 1) + ((y & 0x78) << 1) + ((x & 0x78) >> 2); |
| 332 | cn = ((y & 0x80) << 2) + ((x & 0x80) << 1) + ((y & 0x78) << 1) + ((x & 0x78) >> 3); |
| 330 | 333 | break; |
| 331 | 334 | } |
| 332 | 335 | |
| r5568 | r5569 | |
| 335 | 338 | |
| 336 | 339 | for(n = 0; n < bpp; n++) |
| 337 | 340 | { |
| 338 | | UINT8 byte = ((n >> 1) << 4) + (n & 1); // = [n]{ 0, 1, 16, 17, 32, 33, 48, 49 }; |
| 341 | UINT32 byte = ((n >> 1) << 4) + (n & 1); // = [n]{ 0, 1, 16, 17, 32, 33, 48, 49 }; |
| 339 | 342 | superfx_add_clocks_internal(cpustate, cpustate->memory_access_speed); |
| 340 | | //printf( "superfx_rpix: calling superfx_bus_read\n" ); |
| 341 | 343 | data |= ((superfx_bus_read(cpustate, addr + byte) >> x) & 1) << n; |
| 342 | 344 | } |
| 343 | 345 | |
| 344 | 346 | return data; |
| 345 | 347 | } |
| 346 | 348 | |
| 347 | | static UINT8 superfx_color(superfx_state *cpustate, UINT8 source) |
| 349 | INLINE UINT8 superfx_color(superfx_state *cpustate, UINT8 source) |
| 348 | 350 | { |
| 349 | 351 | if(cpustate->por & SUPERFX_POR_HIGHNIBBLE) |
| 350 | 352 | { |
| r5568 | r5569 | |
| 357 | 359 | return source; |
| 358 | 360 | } |
| 359 | 361 | |
| 360 | | static UINT8 superfx_rambuffer_sync(superfx_state *cpustate) |
| 362 | INLINE void superfx_rambuffer_sync(superfx_state *cpustate) |
| 361 | 363 | { |
| 362 | 364 | if(cpustate->ramcl) |
| 363 | 365 | { |
| 364 | 366 | superfx_add_clocks_internal(cpustate, cpustate->ramcl); |
| 365 | 367 | } |
| 366 | | return 0; |
| 367 | 368 | } |
| 368 | 369 | |
| 369 | | static UINT8 superfx_rambuffer_read(superfx_state *cpustate, UINT16 addr) |
| 370 | INLINE UINT8 superfx_rambuffer_read(superfx_state *cpustate, UINT16 addr) |
| 370 | 371 | { |
| 371 | | //superfx_rambuffer_sync(cpustate); |
| 372 | | //printf( "superfx_rambuffer_read: calling superfx_bus_read\n" ); |
| 372 | superfx_rambuffer_sync(cpustate); |
| 373 | 373 | return superfx_bus_read(cpustate, 0x700000 + (cpustate->rambr << 16) + addr); |
| 374 | 374 | } |
| 375 | 375 | |
| 376 | | static void superfx_rambuffer_write(superfx_state *cpustate, UINT16 addr, UINT8 data) |
| 376 | INLINE void superfx_rambuffer_write(superfx_state *cpustate, UINT16 addr, UINT8 data) |
| 377 | 377 | { |
| 378 | | superfx_bus_write(cpustate, 0x700000 + (cpustate->rambr << 16) + cpustate->ramar, cpustate->ramdr); |
| 379 | | //superfx_rambuffer_sync(cpustate); |
| 380 | | //cpustate->ramcl = cpustate->memory_access_speed; |
| 381 | | //cpustate->ramar = addr; |
| 382 | | //cpustate->ramdr = data; |
| 378 | superfx_rambuffer_sync(cpustate); |
| 379 | cpustate->ramcl = cpustate->memory_access_speed; |
| 380 | cpustate->ramar = addr; |
| 381 | cpustate->ramdr = data; |
| 383 | 382 | } |
| 384 | 383 | |
| 385 | 384 | static void superfx_rombuffer_sync(superfx_state *cpustate) |
| 386 | 385 | { |
| 387 | | //printf( "superfx_rombuffer_sync\n" ); |
| 388 | 386 | if(cpustate->romcl) |
| 389 | 387 | { |
| 390 | | printf( "calling add_clocks_internal\n" ); |
| 391 | 388 | superfx_add_clocks_internal(cpustate, cpustate->romcl); |
| 392 | 389 | } |
| 393 | 390 | } |
| r5568 | r5569 | |
| 395 | 392 | static void superfx_rombuffer_update(superfx_state *cpustate) |
| 396 | 393 | { |
| 397 | 394 | cpustate->sfr |= SUPERFX_SFR_R; |
| 398 | | //printf( "superfx_rombuffer_update: setting romcl\n" ); |
| 399 | 395 | cpustate->romcl = cpustate->memory_access_speed; |
| 400 | 396 | } |
| 401 | 397 | |
| 402 | 398 | static UINT8 superfx_rombuffer_read(superfx_state *cpustate) |
| 403 | 399 | { |
| 404 | 400 | superfx_rombuffer_sync(cpustate); |
| 405 | | printf( "superfx_rombuffer_read: %02x\n", cpustate->romdr); |
| 406 | 401 | return cpustate->romdr; |
| 407 | 402 | } |
| 408 | 403 | |
| 409 | | static void superfx_gpr_write(superfx_state *cpustate, UINT8 r, UINT16 data) |
| 404 | INLINE void superfx_gpr_write(superfx_state *cpustate, UINT8 r, UINT16 data) |
| 410 | 405 | { |
| 411 | 406 | cpustate->r[r] = data; |
| 412 | 407 | if(r == 14) |
| r5568 | r5569 | |
| 432 | 427 | for(n = 0; n < 16; n++) |
| 433 | 428 | { |
| 434 | 429 | superfx_add_clocks_internal(cpustate, cpustate->memory_access_speed); |
| 435 | | //printf( "superfx_op_read: caching superfx_bus_read value\n" ); |
| 436 | 430 | cpustate->cache.buffer[dp++] = superfx_bus_read(cpustate, sp++); |
| 437 | 431 | } |
| 438 | 432 | cpustate->cache.valid[offset >> 4] = 1; |
| r5568 | r5569 | |
| 449 | 443 | //$[00-5f]:[0000-ffff] ROM |
| 450 | 444 | superfx_rombuffer_sync(cpustate); |
| 451 | 445 | superfx_add_clocks_internal(cpustate, cpustate->memory_access_speed); |
| 452 | | //printf( "superfx_op_read: reading from rom, calling superfx_bus_read\n" ); |
| 453 | 446 | return superfx_bus_read(cpustate, (cpustate->pbr << 16) + addr); |
| 454 | 447 | } |
| 455 | 448 | else |
| r5568 | r5569 | |
| 457 | 450 | //$[60-7f]:[0000-ffff] RAM |
| 458 | 451 | superfx_rambuffer_sync(cpustate); |
| 459 | 452 | superfx_add_clocks_internal(cpustate, cpustate->memory_access_speed); |
| 460 | | //printf( "superfx_op_read: reading from ram, calling superfx_bus_read\n" ); |
| 461 | 453 | return superfx_bus_read(cpustate, (cpustate->pbr << 16) + addr); |
| 462 | 454 | } |
| 463 | 455 | } |
| r5568 | r5569 | |
| 486 | 478 | |
| 487 | 479 | addr &= 0xffff; |
| 488 | 480 | |
| 489 | | if(addr != 0x3030) |
| 490 | | { |
| 491 | | //printf( "superfx_mmio_read: %08x\n", addr ); |
| 492 | | } |
| 493 | | |
| 494 | 481 | if(addr >= 0x3100 && addr <= 0x32ff) |
| 495 | 482 | { |
| 496 | 483 | return superfx_cache_mmio_read(cpustate, addr - 0x3100); |
| r5568 | r5569 | |
| 511 | 498 | UINT8 r = cpustate->sfr >> 8; |
| 512 | 499 | cpustate->sfr &= ~SUPERFX_SFR_IRQ; |
| 513 | 500 | cpustate->irq = 0; |
| 501 | devcb_call_write_line(&cpustate->out_irq_func, cpustate->irq); |
| 514 | 502 | return r; |
| 515 | 503 | } |
| 516 | 504 | |
| r5568 | r5569 | |
| 540 | 528 | { |
| 541 | 529 | superfx_state *cpustate = get_safe_token(cpu); |
| 542 | 530 | |
| 543 | | //printf( "superfx_mmio_write: %08x = %02x\n", addr, data ); |
| 544 | | |
| 545 | 531 | addr &= 0xffff; |
| 546 | 532 | |
| 547 | 533 | if(addr >= 0x3100 && addr <= 0x32ff) |
| r5568 | r5569 | |
| 615 | 601 | } |
| 616 | 602 | } |
| 617 | 603 | |
| 618 | | static void superfx_add_clocks_internal(superfx_state *cpustate, INT32 clocks) |
| 604 | INLINE void superfx_add_clocks_internal(superfx_state *cpustate, UINT32 clocks) |
| 619 | 605 | { |
| 620 | | //printf( "superfx_add_clocks: %d\n", clocks); |
| 621 | | /* |
| 622 | | if(cpustate->romcl) |
| 623 | | { |
| 624 | | printf( "ROM is accessing\n" ); |
| 625 | | printf( "romcl = %d, -= MIN(%d, %d) (= %d)\n", cpustate->romcl, clocks, cpustate->romcl, MIN(clocks, cpustate->romcl)); |
| 626 | | cpustate->romcl -= MIN(clocks, cpustate->romcl); |
| 627 | | if(cpustate->romcl == 0) |
| 628 | | { |
| 629 | | cpustate->sfr &= ~SUPERFX_SFR_R; |
| 630 | | printf( "superfx_op_read: reading from rom, calling superfx_bus_read: %08x\n", (cpustate->rombr << 16) + cpustate->r[14] ); |
| 631 | | cpustate->romdr = superfx_bus_read(cpustate, (cpustate->rombr << 16) + cpustate->r[14]); |
| 632 | | } |
| 633 | | } |
| 634 | | */ |
| 606 | if(cpustate->romcl) |
| 607 | { |
| 608 | cpustate->romcl -= MIN(clocks, cpustate->romcl); |
| 609 | if(cpustate->romcl == 0) |
| 610 | { |
| 611 | cpustate->sfr &= ~SUPERFX_SFR_R; |
| 612 | cpustate->romdr = superfx_bus_read(cpustate, (cpustate->rombr << 16) + cpustate->r[14]); |
| 613 | } |
| 614 | } |
| 635 | 615 | |
| 636 | 616 | if(cpustate->ramcl) |
| 637 | 617 | { |
| 638 | 618 | cpustate->ramcl -= MIN(clocks, cpustate->ramcl); |
| 639 | 619 | if(cpustate->ramcl == 0) |
| 640 | 620 | { |
| 641 | | printf( "Writing %02x to %08x\n", cpustate->ramdr, 0x700000 + (cpustate->rambr << 16) + cpustate->ramar ); |
| 642 | 621 | superfx_bus_write(cpustate, 0x700000 + (cpustate->rambr << 16) + cpustate->ramar, cpustate->ramdr); |
| 643 | 622 | } |
| 644 | 623 | } |
| r5568 | r5569 | |
| 699 | 678 | |
| 700 | 679 | cpustate->device = device; |
| 701 | 680 | cpustate->program = memory_find_address_space(device, ADDRESS_SPACE_PROGRAM); |
| 681 | |
| 682 | if (device->static_config != NULL) |
| 683 | { |
| 684 | cpustate->config = *(superfx_config *)device->static_config; |
| 685 | } |
| 686 | |
| 687 | devcb_resolve_write_line(&cpustate->out_irq_func, &cpustate->config.out_irq_func, device); |
| 702 | 688 | } |
| 703 | 689 | |
| 704 | 690 | static CPU_EXIT( superfx ) |
| r5568 | r5569 | |
| 769 | 755 | |
| 770 | 756 | op = superfx_peekpipe(cpustate); |
| 771 | 757 | |
| 772 | | printf( "Executing op at %06x: %02x\n", (cpustate->pbr << 16) | cpustate->r[15], op ); |
| 773 | 758 | switch(op) |
| 774 | 759 | { |
| 775 | 760 | case 0x00: // STOP |
| 776 | | if(!(cpustate->cfgr & SUPERFX_CFGR_IRQ)) |
| 761 | if((cpustate->cfgr & SUPERFX_CFGR_IRQ) == 0) |
| 777 | 762 | { |
| 778 | 763 | cpustate->sfr |= SUPERFX_SFR_IRQ; |
| 779 | 764 | cpustate->irq = 1; |
| 765 | devcb_call_write_line(&cpustate->out_irq_func, cpustate->irq ? ASSERT_LINE : CLEAR_LINE ); |
| 780 | 766 | } |
| 781 | 767 | cpustate->sfr &= ~SUPERFX_SFR_G; |
| 782 | 768 | cpustate->pipeline = 0x01; |
| r5568 | r5569 | |
| 909 | 895 | |
| 910 | 896 | case 0x10: case 0x11: case 0x12: case 0x13: case 0x14: case 0x15: case 0x16: case 0x17: |
| 911 | 897 | case 0x18: case 0x19: case 0x1a: case 0x1b: case 0x1c: case 0x1d: case 0x1e: case 0x1f: // TO |
| 912 | | if(!(cpustate->sfr & SUPERFX_SFR_B)) |
| 898 | if((cpustate->sfr & SUPERFX_SFR_B) == 0) |
| 913 | 899 | { |
| 914 | 900 | cpustate->dreg = &cpustate->r[op & 0xf]; |
| 915 | 901 | cpustate->dreg_idx = op & 0xf; |
| r5568 | r5569 | |
| 978 | 964 | { // LDW_IR |
| 979 | 965 | UINT16 data = 0; |
| 980 | 966 | cpustate->ramaddr = cpustate->r[op & 0xf]; |
| 981 | | data = superfx_rambuffer_read(cpustate, (cpustate->ramaddr ^ 0) << 0); |
| 982 | | data |= superfx_rambuffer_read(cpustate, (cpustate->ramaddr ^ 1) << 8); |
| 967 | data = superfx_rambuffer_read(cpustate, cpustate->ramaddr ^ 0) << 0; |
| 968 | data |= superfx_rambuffer_read(cpustate, cpustate->ramaddr ^ 1) << 8; |
| 983 | 969 | superfx_gpr_write(cpustate, cpustate->dreg_idx, data); |
| 984 | 970 | superfx_regs_reset(cpustate); |
| 985 | 971 | } |
| r5568 | r5569 | |
| 1066 | 1052 | case 0x60: case 0x61: case 0x62: case 0x63: case 0x64: case 0x65: case 0x66: case 0x67: |
| 1067 | 1053 | case 0x68: case 0x69: case 0x6a: case 0x6b: case 0x6c: case 0x6d: case 0x6e: case 0x6f: // SUB / SBC / SUBI / CMP |
| 1068 | 1054 | { |
| 1069 | | INT32 r = *(cpustate->sreg); |
| 1055 | INT32 r = 0; |
| 1070 | 1056 | cpustate->sfr &= ~(SUPERFX_SFR_OV | SUPERFX_SFR_S | SUPERFX_SFR_CY | SUPERFX_SFR_Z); |
| 1071 | 1057 | switch(cpustate->sfr & SUPERFX_SFR_ALT) |
| 1072 | 1058 | { |
| 1073 | 1059 | case SUPERFX_SFR_ALT0: // SUB |
| 1074 | | r -= cpustate->r[op & 0xf]; |
| 1060 | r = *(cpustate->sreg) - cpustate->r[op & 0xf]; |
| 1075 | 1061 | cpustate->sfr |= ((*(cpustate->sreg) ^ cpustate->r[op & 0xf]) & (*(cpustate->sreg) ^ r) & 0x8000) ? SUPERFX_SFR_OV : 0; |
| 1076 | 1062 | superfx_gpr_write(cpustate, cpustate->dreg_idx, r); |
| 1077 | 1063 | break; |
| 1078 | 1064 | case SUPERFX_SFR_ALT1: // SBC |
| 1079 | | r -= cpustate->r[op & 0xf] - ((cpustate->sfr & SUPERFX_SFR_CY) ? 0 : 1); |
| 1065 | r = *(cpustate->sreg) - cpustate->r[op & 0xf] - ((cpustate->sfr & SUPERFX_SFR_CY) ? 0 : 1); |
| 1080 | 1066 | cpustate->sfr |= ((*(cpustate->sreg) ^ cpustate->r[op & 0xf]) & (*(cpustate->sreg) ^ r) & 0x8000) ? SUPERFX_SFR_OV : 0; |
| 1081 | 1067 | superfx_gpr_write(cpustate, cpustate->dreg_idx, r); |
| 1082 | 1068 | break; |
| 1083 | 1069 | case SUPERFX_SFR_ALT2: // SUBI |
| 1084 | | r -= op & 0xf; |
| 1070 | r = *(cpustate->sreg) - (op & 0xf); |
| 1085 | 1071 | cpustate->sfr |= ((*(cpustate->sreg) ^ (op & 0xf)) & (*(cpustate->sreg) ^ r) & 0x8000) ? SUPERFX_SFR_OV : 0; |
| 1086 | 1072 | superfx_gpr_write(cpustate, cpustate->dreg_idx, r); |
| 1087 | 1073 | break; |
| 1088 | 1074 | case SUPERFX_SFR_ALT3: // CMP |
| 1089 | | r -= cpustate->r[op & 0xf]; |
| 1075 | r = *(cpustate->sreg) - cpustate->r[op & 0xf]; |
| 1090 | 1076 | cpustate->sfr |= ((*(cpustate->sreg) ^ cpustate->r[op & 0xf]) & (*(cpustate->sreg) ^ r) & 0x8000) ? SUPERFX_SFR_OV : 0; |
| 1091 | 1077 | break; |
| 1092 | 1078 | } |
| 1093 | 1079 | cpustate->sfr |= (r & 0x8000) ? SUPERFX_SFR_S : 0; |
| 1094 | | cpustate->sfr |= (r >= 0x10000) ? SUPERFX_SFR_CY : 0; |
| 1080 | cpustate->sfr |= (r >= 0x0) ? SUPERFX_SFR_CY : 0; |
| 1095 | 1081 | cpustate->sfr |= ((UINT16)r == 0) ? SUPERFX_SFR_Z : 0; |
| 1096 | 1082 | superfx_regs_reset(cpustate); |
| 1097 | 1083 | break; |
| r5568 | r5569 | |
| 1175 | 1161 | { // ASR |
| 1176 | 1162 | cpustate->sfr &= ~SUPERFX_SFR_CY; |
| 1177 | 1163 | cpustate->sfr |= (*(cpustate->sreg) & 1) ? SUPERFX_SFR_CY : 0; |
| 1178 | | superfx_gpr_write(cpustate, cpustate->dreg_idx, (INT16)(*(cpustate->sreg) >> 1)); |
| 1164 | superfx_gpr_write(cpustate, cpustate->dreg_idx, (INT16)(*(cpustate->sreg)) >> 1); |
| 1179 | 1165 | superfx_dreg_sfr_sz_update(cpustate); |
| 1180 | 1166 | superfx_regs_reset(cpustate); |
| 1181 | 1167 | } |
| r5568 | r5569 | |
| 1183 | 1169 | { // DIV2 |
| 1184 | 1170 | cpustate->sfr &= ~SUPERFX_SFR_CY; |
| 1185 | 1171 | cpustate->sfr |= (*(cpustate->sreg) & 1) ? SUPERFX_SFR_CY : 0; |
| 1186 | | superfx_gpr_write(cpustate, cpustate->dreg_idx, ((INT16)(*(cpustate->sreg) >> 1)) + ((*(cpustate->sreg) + 1) >> 16)); |
| 1172 | superfx_gpr_write(cpustate, cpustate->dreg_idx, ((INT16)(*(cpustate->sreg)) >> 1) + ((*(cpustate->sreg) + 1) >> 16)); |
| 1187 | 1173 | superfx_dreg_sfr_sz_update(cpustate); |
| 1188 | 1174 | superfx_regs_reset(cpustate); |
| 1189 | 1175 | } |
| r5568 | r5569 | |
| 1192 | 1178 | case 0x97: // ROR |
| 1193 | 1179 | { |
| 1194 | 1180 | UINT16 carry = *(cpustate->sreg) & 1; |
| 1195 | | superfx_gpr_write(cpustate, cpustate->dreg_idx, (((cpustate->sfr & SUPERFX_SFR_CY) ? 1 : 0) << 15) | (*(cpustate->sreg) >> 1)); |
| 1181 | superfx_gpr_write(cpustate, cpustate->dreg_idx, (SUPERFX_SFR_CY_SET << 15) | ((UINT16)(*(cpustate->sreg)) >> 1)); |
| 1196 | 1182 | cpustate->sfr &= ~SUPERFX_SFR_CY; |
| 1197 | 1183 | cpustate->sfr |= carry ? SUPERFX_SFR_CY : 0; |
| 1198 | 1184 | superfx_dreg_sfr_sz_update(cpustate); |
| r5568 | r5569 | |
| 1217 | 1203 | break; |
| 1218 | 1204 | |
| 1219 | 1205 | case 0x9e: // LOB |
| 1220 | | superfx_gpr_write(cpustate, cpustate->dreg_idx, *(cpustate->sreg) & 0xff); |
| 1206 | superfx_gpr_write(cpustate, cpustate->dreg_idx, (UINT16)(*(cpustate->sreg)) & 0x00ff); |
| 1221 | 1207 | cpustate->sfr &= ~(SUPERFX_SFR_S | SUPERFX_SFR_Z); |
| 1222 | 1208 | cpustate->sfr |= (*(cpustate->dreg) & 0x80) ? SUPERFX_SFR_S : 0; |
| 1223 | 1209 | cpustate->sfr |= (*(cpustate->dreg) == 0) ? SUPERFX_SFR_Z : 0; |
| r5568 | r5569 | |
| 1226 | 1212 | |
| 1227 | 1213 | case 0x9f: // FMULT / LMULT |
| 1228 | 1214 | { |
| 1229 | | UINT32 result = (INT16)(*(cpustate->sreg)) * (INT16)cpustate->r[6]; |
| 1215 | UINT32 result = (INT16)(*(cpustate->sreg)) * (INT16)(cpustate->r[6]); |
| 1230 | 1216 | if(cpustate->sfr & SUPERFX_SFR_ALT1) |
| 1231 | 1217 | { // LMULT |
| 1232 | 1218 | superfx_gpr_write(cpustate, 4, result); |
| r5568 | r5569 | |
| 1270 | 1256 | |
| 1271 | 1257 | case 0xb0: case 0xb1: case 0xb2: case 0xb3: case 0xb4: case 0xb5: case 0xb6: case 0xb7: |
| 1272 | 1258 | case 0xb8: case 0xb9: case 0xba: case 0xbb: case 0xbc: case 0xbd: case 0xbe: case 0xbf: // FROM |
| 1273 | | if(!(cpustate->sfr & SUPERFX_SFR_B)) |
| 1259 | if((cpustate->sfr & SUPERFX_SFR_B) == 0) |
| 1274 | 1260 | { |
| 1275 | 1261 | cpustate->sreg = &(cpustate->r[op & 0xf]); |
| 1276 | 1262 | cpustate->sreg_idx = op & 0xf; |
| r5568 | r5569 | |
| 1286 | 1272 | break; |
| 1287 | 1273 | |
| 1288 | 1274 | case 0xc0: // HIB |
| 1289 | | superfx_gpr_write(cpustate, cpustate->dreg_idx, *(cpustate->sreg) >> 8); |
| 1290 | | superfx_dreg_sfr_sz_update(cpustate); |
| 1275 | superfx_gpr_write(cpustate, cpustate->dreg_idx, (*(cpustate->sreg)) >> 8); |
| 1276 | cpustate->sfr &= ~(SUPERFX_SFR_S | SUPERFX_SFR_Z); |
| 1277 | cpustate->sfr |= (*(cpustate->dreg) & 0x80) ? SUPERFX_SFR_S : 0; |
| 1278 | cpustate->sfr |= (*(cpustate->dreg) == 0) ? SUPERFX_SFR_Z : 0; |
| 1291 | 1279 | superfx_regs_reset(cpustate); |
| 1292 | 1280 | break; |
| 1293 | 1281 | |
| r5568 | r5569 | |
| 1353 | 1341 | |
| 1354 | 1342 | case 0xef: // GETB / GETBH / GETBL / GETBS |
| 1355 | 1343 | { |
| 1356 | | UINT8 byte = superfx_bus_read(cpustate, (cpustate->rombr << 16) + cpustate->r[14]); |
| 1344 | UINT8 byte = superfx_rombuffer_read(cpustate); |
| 1357 | 1345 | switch(cpustate->sfr & SUPERFX_SFR_ALT) |
| 1358 | 1346 | { |
| 1359 | 1347 | case SUPERFX_SFR_ALT0: // GETB |
| r5568 | r5569 | |
| 1366 | 1354 | superfx_gpr_write(cpustate, cpustate->dreg_idx, (*(cpustate->sreg) & 0xff00) | (byte << 0)); |
| 1367 | 1355 | break; |
| 1368 | 1356 | case SUPERFX_SFR_ALT3: // GETBS |
| 1369 | | superfx_gpr_write(cpustate, cpustate->dreg_idx, (INT16)((INT8)byte)); |
| 1357 | superfx_gpr_write(cpustate, cpustate->dreg_idx, (INT8)byte); |
| 1370 | 1358 | break; |
| 1371 | 1359 | } |
| 1372 | 1360 | superfx_regs_reset(cpustate); |
src/emu/cpu/avr8/avr8.c
| r5568 | r5569 | |
| 128 | 128 | UINT16 sp = SPREG; |
| 129 | 129 | WRITE_IO_8(cpustate, sp, val); |
| 130 | 130 | sp--; |
| 131 | //printf( "PUSH %02x, new SP = %04x\n", val, sp ); |
| 131 | 132 | WRITE_IO_8(cpustate, AVR8_IO_SPH, (sp >> 8) & 0x00ff); |
| 132 | 133 | WRITE_IO_8(cpustate, AVR8_IO_SPL, sp & 0x00ff); |
| 133 | 134 | } |
| r5568 | r5569 | |
| 138 | 139 | sp++; |
| 139 | 140 | WRITE_IO_8(cpustate, AVR8_IO_SPH, (sp >> 8) & 0x00ff); |
| 140 | 141 | WRITE_IO_8(cpustate, AVR8_IO_SPL, sp & 0x00ff); |
| 142 | //printf( "POP %02x, new SP = %04x\n", READ_IO_8(cpustate, sp), sp ); |
| 141 | 143 | return READ_IO_8(cpustate, sp); |
| 142 | 144 | } |
| 143 | 145 | |
| 146 | static void avr8_set_irq_line(avr8_state *cpustate, UINT16 vector, int state) |
| 147 | { |
| 148 | //printf( "OMFG SETTING IRQ LINE\n" ); |
| 149 | // Horrible hack, not accurate |
| 150 | if(state) |
| 151 | { |
| 152 | SREG_W(AVR8_SREG_I, 0); |
| 153 | PUSH(cpustate, (cpustate->pc >> 8) & 0x00ff); |
| 154 | PUSH(cpustate, cpustate->pc & 0x00ff); |
| 155 | cpustate->pc = vector; |
| 156 | } |
| 157 | } |
| 158 | |
| 144 | 159 | /*****************************************************************************/ |
| 145 | 160 | |
| 146 | 161 | static CPU_INIT( avr8 ) |
| r5568 | r5569 | |
| 176 | 191 | UINT8 rr = 0; |
| 177 | 192 | UINT8 res = 0; |
| 178 | 193 | UINT16 pd = 0; |
| 194 | INT16 sd = 0; |
| 195 | INT32 opcycles = 1; |
| 179 | 196 | //UINT16 pr = 0; |
| 180 | 197 | avr8_state *cpustate = get_safe_token(device); |
| 181 | 198 | |
| r5568 | r5569 | |
| 195 | 212 | switch(op & 0x0f00) |
| 196 | 213 | { |
| 197 | 214 | case 0x0000: // NOP |
| 198 | | //output += sprintf( output, "NOP" ); |
| 199 | | unimplemented_opcode(cpustate, op); |
| 200 | 215 | break; |
| 201 | 216 | case 0x0100: // MOVW Rd+1:Rd,Rr+1:Rd |
| 202 | | //output += sprintf( output, "MOVW R%d:R%d, R%d:R%d", RD4(op)+1, RD4(op), RR4(op)+1, RR4(op) ); |
| 203 | | unimplemented_opcode(cpustate, op); |
| 217 | WRITE_IO_8(cpustate, (RD4(op) << 1)+1, READ_IO_8(cpustate, (RR4(op) << 1)+1)); |
| 218 | WRITE_IO_8(cpustate, RD4(op) << 1, READ_IO_8(cpustate, RR4(op) << 1)); |
| 204 | 219 | break; |
| 205 | 220 | case 0x0200: // MULS Rd,Rr |
| 206 | 221 | //output += sprintf( output, "MULS R%d, R%d", 16+RD4(op), 16+RR4(op) ); |
| 207 | 222 | unimplemented_opcode(cpustate, op); |
| 208 | 223 | break; |
| 209 | 224 | case 0x0300: // MULSU Rd,Rr |
| 210 | | //output += sprintf( output, "MULSU R%d, R%d", 16+RD4(op), 16+RR4(op) ); |
| 211 | | unimplemented_opcode(cpustate, op); |
| 225 | sd = (INT8)READ_IO_8(cpustate, 16+RD4(op)) * (UINT8)READ_IO_8(cpustate, 16+RR4(op)); |
| 226 | WRITE_IO_8(cpustate, 1, (sd >> 8) & 0x00ff); |
| 227 | WRITE_IO_8(cpustate, 0, sd & 0x00ff); |
| 228 | SREG_W(AVR8_SREG_C, (sd & 0x8000) ? 1 : 0); |
| 229 | SREG_W(AVR8_SREG_Z, (sd == 0) ? 1 : 0); |
| 230 | opcycles = 2; |
| 212 | 231 | break; |
| 213 | 232 | case 0x0400: |
| 214 | 233 | case 0x0500: |
| r5568 | r5569 | |
| 228 | 247 | case 0x0900: |
| 229 | 248 | case 0x0a00: |
| 230 | 249 | case 0x0b00: // SBC Rd,Rr |
| 231 | | //output += sprintf( output, "SBC R%d, R%d", RD5(op), RR5(op) ); |
| 232 | | unimplemented_opcode(cpustate, op); |
| 250 | rd = READ_IO_8(cpustate, RD5(op)); |
| 251 | rr = READ_IO_8(cpustate, RR5(op)); |
| 252 | res = rd - (rr + SREG_R(AVR8_SREG_C)); |
| 253 | WRITE_IO_8(cpustate, RD5(op), res); |
| 254 | SREG_W(AVR8_SREG_H, (NOT(BIT(rd,3)) & BIT(rr,3)) | (BIT(rr,3) & BIT(res,3)) | (BIT(res,3) & NOT(BIT(rd,3)))); |
| 255 | SREG_W(AVR8_SREG_V, (BIT(rd,7) & NOT(BIT(rr,7)) & NOT(BIT(res,7))) | (NOT(BIT(rd,7)) & BIT(rr,7) & BIT(res,7))); |
| 256 | SREG_W(AVR8_SREG_N, BIT(res,7)); |
| 257 | SREG_W(AVR8_SREG_S, SREG_R(AVR8_SREG_N) ^ SREG_R(AVR8_SREG_V)); |
| 258 | SREG_W(AVR8_SREG_Z, (res == 0) ? 1 : 0); |
| 259 | SREG_W(AVR8_SREG_C, (NOT(BIT(rd,7)) & BIT(rr,7)) | (BIT(rr,7) & BIT(res,7)) | (BIT(res,7) & NOT(BIT(rd,7)))); |
| 233 | 260 | break; |
| 234 | 261 | case 0x0c00: |
| 235 | 262 | case 0x0d00: |
| r5568 | r5569 | |
| 267 | 294 | SREG_W(AVR8_SREG_C, (NOT(BIT(rd,7)) & BIT(rr,7)) | (BIT(rr,7) & BIT(res,7)) | (BIT(res,7) & NOT(BIT(rd,7)))); |
| 268 | 295 | break; |
| 269 | 296 | case 0x0800: // SUB Rd,Rr |
| 270 | | //output += sprintf( output, "SUB R%d, R%d", RD5(op), RR5(op) ); |
| 271 | | unimplemented_opcode(cpustate, op); |
| 297 | rd = READ_IO_8(cpustate, RD5(op)); |
| 298 | rr = READ_IO_8(cpustate, RR5(op)); |
| 299 | res = rd - rr; |
| 300 | WRITE_IO_8(cpustate, RD5(op), res); |
| 301 | SREG_W(AVR8_SREG_H, (NOT(BIT(rd,3)) & BIT(rr,3)) | (BIT(rr,3) & BIT(res,3)) | (BIT(res,3) & NOT(BIT(rd,3)))); |
| 302 | SREG_W(AVR8_SREG_V, (BIT(rd,7) & NOT(BIT(rr,7)) & NOT(BIT(res,7))) | (NOT(BIT(rd,7)) & BIT(rr,7) & BIT(res,7))); |
| 303 | SREG_W(AVR8_SREG_N, BIT(res,7)); |
| 304 | SREG_W(AVR8_SREG_S, SREG_R(AVR8_SREG_N) ^ SREG_R(AVR8_SREG_V)); |
| 305 | SREG_W(AVR8_SREG_Z, (res == 0) ? 1 : 0); |
| 306 | SREG_W(AVR8_SREG_C, (NOT(BIT(rd,7)) & BIT(rr,7)) | (BIT(rr,7) & BIT(res,7)) | (BIT(res,7) & NOT(BIT(rd,7)))); |
| 272 | 307 | break; |
| 273 | 308 | case 0x0c00: // ADC Rd,Rr |
| 274 | 309 | rd = READ_IO_8(cpustate, RD5(op)); |
| r5568 | r5569 | |
| 361 | 396 | unimplemented_opcode(cpustate, op); |
| 362 | 397 | break; |
| 363 | 398 | case 0x0008: // LDD Rd,Y+q |
| 364 | | //output += sprintf( output, "LD(D) R%d, Y+%02x", RD5(op), QCONST6(op) ); |
| 365 | | unimplemented_opcode(cpustate, op); |
| 399 | WRITE_IO_8(cpustate, RD5(op), YREG + QCONST6(op)); |
| 400 | opcycles = 2; |
| 366 | 401 | break; |
| 367 | 402 | case 0x0200: // STD Z+q,Rr |
| 368 | 403 | //output += sprintf( output, "ST(D) Z+%02x, R%d", QCONST6(op), RD5(op) ); |
| 369 | 404 | unimplemented_opcode(cpustate, op); |
| 370 | 405 | break; |
| 371 | | case 0x0208: // STD Z+q,Rr |
| 372 | | //output += sprintf( output, "ST(D) Y+%02x, R%d", QCONST6(op), RD5(op) ); |
| 373 | | unimplemented_opcode(cpustate, op); |
| 406 | case 0x0208: // STD Y+q,Rr |
| 407 | WRITE_IO_8(cpustate, YREG + QCONST6(op), READ_IO_8(cpustate, RD5(op))); |
| 408 | opcycles = 2; |
| 374 | 409 | break; |
| 375 | 410 | } |
| 376 | 411 | break; |
| r5568 | r5569 | |
| 386 | 421 | cpustate->pc++; |
| 387 | 422 | op |= READ_PRG_16(cpustate, cpustate->pc); |
| 388 | 423 | WRITE_IO_8(cpustate, RD5(op >> 16), READ_IO_8(cpustate, op & 0x0000ffff)); |
| 424 | opcycles = 2; |
| 389 | 425 | break; |
| 390 | 426 | case 0x0001: // LD Rd,Z+ |
| 391 | 427 | unimplemented_opcode(cpustate, op); |
| r5568 | r5569 | |
| 396 | 432 | break; |
| 397 | 433 | case 0x0004: // LPM Rd,Z |
| 398 | 434 | WRITE_IO_8(cpustate, RD5(op), READ_PRG_8(cpustate, ZREG)); |
| 435 | opcycles = 3; |
| 399 | 436 | break; |
| 400 | 437 | case 0x0005: // LPM Rd,Z+ |
| 401 | 438 | pd = ZREG; |
| r5568 | r5569 | |
| 403 | 440 | pd++; |
| 404 | 441 | WRITE_IO_8(cpustate, 31, (pd >> 8) & 0x00ff); |
| 405 | 442 | WRITE_IO_8(cpustate, 30, pd & 0x00ff); |
| 443 | opcycles = 3; |
| 406 | 444 | break; |
| 407 | 445 | case 0x0006: // ELPM Rd,Z |
| 408 | 446 | //output += sprintf( output, "ELPM R%d, Z", RD5(op) ); |
| r5568 | r5569 | |
| 425 | 463 | unimplemented_opcode(cpustate, op); |
| 426 | 464 | break; |
| 427 | 465 | case 0x000d: // LD Rd,X+ |
| 428 | | //output += sprintf( output, "LD R%d, X+", RD5(op) ); |
| 429 | | unimplemented_opcode(cpustate, op); |
| 466 | pd = XREG; |
| 467 | WRITE_IO_8(cpustate, RD5(op), READ_IO_8(cpustate, pd)); |
| 468 | pd++; |
| 469 | WRITE_IO_8(cpustate, 27, (pd >> 8) & 0x00ff); |
| 470 | WRITE_IO_8(cpustate, 26, pd & 0x00ff); |
| 471 | opcycles = 2; |
| 430 | 472 | break; |
| 431 | 473 | case 0x000e: // LD Rd,-X |
| 432 | 474 | //output += sprintf( output, "LD R%d,-X", RD5(op) ); |
| 433 | 475 | unimplemented_opcode(cpustate, op); |
| 434 | 476 | break; |
| 435 | 477 | case 0x000f: // POP Rd |
| 436 | | //output += sprintf( output, "POP R%d", RD5(op) ); |
| 437 | | unimplemented_opcode(cpustate, op); |
| 478 | WRITE_IO_8(cpustate, RD5(op), POP(cpustate)); |
| 479 | opcycles = 2; |
| 438 | 480 | break; |
| 439 | 481 | default: |
| 440 | 482 | unimplemented_opcode(cpustate, op); |
| r5568 | r5569 | |
| 451 | 493 | cpustate->pc++; |
| 452 | 494 | op |= READ_PRG_16(cpustate, cpustate->pc); |
| 453 | 495 | WRITE_IO_8(cpustate, op & 0x0000ffff, READ_IO_8(cpustate, RD5(op >> 16))); |
| 496 | opcycles = 2; |
| 454 | 497 | break; |
| 455 | 498 | case 0x0001: // ST Z+,Rd |
| 456 | 499 | //output += sprintf( output, "ST Z+, R%d", RD5(op) ); |
| r5568 | r5569 | |
| 471 | 514 | case 0x000c: // ST X,Rd |
| 472 | 515 | rd = READ_IO_8(cpustate, RD5(op)); |
| 473 | 516 | WRITE_IO_8(cpustate, XREG, rd); |
| 517 | opcycles = 2; |
| 474 | 518 | break; |
| 475 | 519 | case 0x000d: // ST X+,Rd |
| 476 | 520 | pd = XREG; |
| r5568 | r5569 | |
| 478 | 522 | pd++; |
| 479 | 523 | WRITE_IO_8(cpustate, 27, (pd >> 8) & 0x00ff); |
| 480 | 524 | WRITE_IO_8(cpustate, 26, pd & 0x00ff); |
| 525 | opcycles = 2; |
| 481 | 526 | break; |
| 482 | 527 | case 0x000e: // ST -X,Rd |
| 483 | 528 | //output += sprintf( output, "ST -X , R%d", RD5(op) ); |
| 484 | 529 | unimplemented_opcode(cpustate, op); |
| 485 | 530 | break; |
| 486 | 531 | case 0x000f: // PUSH Rd |
| 487 | | //output += sprintf( output, "PUSH R%d", RD5(op) ); |
| 488 | | unimplemented_opcode(cpustate, op); |
| 532 | PUSH(cpustate, READ_IO_8(cpustate, RD5(op))); |
| 533 | opcycles = 2; |
| 489 | 534 | break; |
| 490 | 535 | default: |
| 491 | 536 | unimplemented_opcode(cpustate, op); |
| r5568 | r5569 | |
| 497 | 542 | switch(op & 0x000f) |
| 498 | 543 | { |
| 499 | 544 | case 0x0000: // COM Rd |
| 500 | | //output += sprintf( output, "COM R%d", RD5(op) ); |
| 501 | | unimplemented_opcode(cpustate, op); |
| 545 | rd = READ_IO_8(cpustate, RD5(op)); |
| 546 | rd = ~rd; |
| 547 | SREG_W(AVR8_SREG_C, 1); |
| 548 | SREG_W(AVR8_SREG_Z, (res == 0) ? 1 : 0); |
| 549 | SREG_W(AVR8_SREG_N, BIT(res,7)); |
| 550 | SREG_W(AVR8_SREG_V, 0); |
| 551 | SREG_W(AVR8_SREG_S, SREG_R(AVR8_SREG_N) | SREG_R(AVR8_SREG_V)); |
| 502 | 552 | break; |
| 503 | 553 | case 0x0001: // NEG Rd |
| 504 | | //output += sprintf( output, "NEG R%d", RD5(op) ); |
| 505 | | unimplemented_opcode(cpustate, op); |
| 554 | rd = READ_IO_8(cpustate, RD5(op)); |
| 555 | res = 0 - rd; |
| 556 | SREG_W(AVR8_SREG_C, (res == 0) ? 0 : 1); |
| 557 | SREG_W(AVR8_SREG_Z, (res == 0) ? 1 : 0); |
| 558 | SREG_W(AVR8_SREG_N, BIT(res,7)); |
| 559 | SREG_W(AVR8_SREG_V, (res == 0x80) ? 1 : 0); |
| 560 | SREG_W(AVR8_SREG_S, SREG_R(AVR8_SREG_N) | SREG_R(AVR8_SREG_V)); |
| 561 | SREG_W(AVR8_SREG_H, BIT(res,3) | BIT(rd,3)); |
| 506 | 562 | break; |
| 507 | 563 | case 0x0002: // SWAP Rd |
| 508 | 564 | //output += sprintf( output, "SWAP R%d", RD5(op) ); |
| r5568 | r5569 | |
| 522 | 578 | unimplemented_opcode(cpustate, op); |
| 523 | 579 | break; |
| 524 | 580 | case 0x0006: // LSR Rd |
| 525 | | //output += sprintf( output, "LSR R%d", RD5(op) ); |
| 526 | | unimplemented_opcode(cpustate, op); |
| 581 | rd = READ_IO_8(cpustate, RD5(op)); |
| 582 | res = rd >> 1; |
| 583 | SREG_W(AVR8_SREG_C, rd & 0x01); |
| 584 | SREG_W(AVR8_SREG_Z, (res == 0) ? 1 :0); |
| 585 | SREG_W(AVR8_SREG_N, 0); |
| 586 | SREG_W(AVR8_SREG_V, SREG_R(AVR8_SREG_N) ^ SREG_R(AVR8_SREG_C)); |
| 587 | SREG_W(AVR8_SREG_S, SREG_R(AVR8_SREG_N) ^ SREG_R(AVR8_SREG_V)); |
| 527 | 588 | break; |
| 528 | 589 | case 0x0007: // ROR Rd |
| 529 | 590 | //output += sprintf( output, "ROR R%d", RD5(op) ); |
| r5568 | r5569 | |
| 559 | 620 | { |
| 560 | 621 | case 0x0000: // IJMP |
| 561 | 622 | cpustate->pc = ZREG - 1; |
| 623 | opcycles = 2; |
| 562 | 624 | break; |
| 563 | 625 | case 0x0010: // EIJMP |
| 564 | 626 | //output += sprintf( output, "EIJMP" ); |
| 565 | 627 | unimplemented_opcode(cpustate, op); |
| 566 | 628 | break; |
| 567 | 629 | default: |
| 568 | | unimplemented_opcode(cpustate, op); |
| 569 | 630 | //output += sprintf( output, "Undefined (%04x)", op ); |
| 570 | 631 | unimplemented_opcode(cpustate, op); |
| 571 | 632 | break; |
| 572 | 633 | } |
| 573 | 634 | break; |
| 574 | 635 | case 0x000a: // DEC Rd |
| 575 | | //output += sprintf( output, "DEC R%d", RD5(op) ); |
| 576 | | unimplemented_opcode(cpustate, op); |
| 636 | rd = READ_IO_8(cpustate, RD5(op)); |
| 637 | res = rd - 1; |
| 638 | SREG_W(AVR8_SREG_V, (rd == 0x7f) ? 1 : 0); |
| 639 | SREG_W(AVR8_SREG_N, BIT(res,7)); |
| 640 | SREG_W(AVR8_SREG_S, SREG_R(AVR8_SREG_N) ^ SREG_R(AVR8_SREG_V)); |
| 641 | SREG_W(AVR8_SREG_Z, (res == 0) ? 1 : 0); |
| 642 | WRITE_IO_8(cpustate, RD5(op), res); |
| 577 | 643 | break; |
| 578 | 644 | case 0x000c: |
| 579 | 645 | case 0x000d: // JMP k |
| r5568 | r5569 | |
| 603 | 669 | switch(op & 0x000f) |
| 604 | 670 | { |
| 605 | 671 | case 0x0000: // COM Rd |
| 606 | | //output += sprintf( output, "COM R%d", RD5(op) ); |
| 607 | | unimplemented_opcode(cpustate, op); |
| 672 | rd = READ_IO_8(cpustate, RD5(op)); |
| 673 | rd = ~rd; |
| 674 | SREG_W(AVR8_SREG_C, 1); |
| 675 | SREG_W(AVR8_SREG_Z, (res == 0) ? 1 : 0); |
| 676 | SREG_W(AVR8_SREG_N, BIT(res,7)); |
| 677 | SREG_W(AVR8_SREG_V, 0); |
| 678 | SREG_W(AVR8_SREG_S, SREG_R(AVR8_SREG_N) | SREG_R(AVR8_SREG_V)); |
| 608 | 679 | break; |
| 609 | 680 | case 0x0001: // NEG Rd |
| 610 | | //output += sprintf( output, "NEG R%d", RD5(op) ); |
| 611 | | unimplemented_opcode(cpustate, op); |
| 681 | rd = READ_IO_8(cpustate, RD5(op)); |
| 682 | res = 0 - rd; |
| 683 | WRITE_IO_8(cpustate, RD5(op), res); |
| 684 | SREG_W(AVR8_SREG_C, (res == 0) ? 0 : 1); |
| 685 | SREG_W(AVR8_SREG_Z, (res == 0) ? 1 : 0); |
| 686 | SREG_W(AVR8_SREG_N, BIT(res,7)); |
| 687 | SREG_W(AVR8_SREG_V, (res == 0x80) ? 1 : 0); |
| 688 | SREG_W(AVR8_SREG_S, SREG_R(AVR8_SREG_N) | SREG_R(AVR8_SREG_V)); |
| 689 | SREG_W(AVR8_SREG_H, BIT(res,3) | BIT(rd,3)); |
| 612 | 690 | break; |
| 613 | 691 | case 0x0002: // SWAP Rd |
| 614 | 692 | //output += sprintf( output, "SWAP R%d", RD5(op) ); |
| r5568 | r5569 | |
| 628 | 706 | unimplemented_opcode(cpustate, op); |
| 629 | 707 | break; |
| 630 | 708 | case 0x0006: // LSR Rd |
| 631 | | //output += sprintf( output, "LSR R%d", RD5(op) ); |
| 632 | | unimplemented_opcode(cpustate, op); |
| 709 | rd = READ_IO_8(cpustate, RD5(op)); |
| 710 | res = rd >> 1; |
| 711 | SREG_W(AVR8_SREG_C, rd & 0x01); |
| 712 | SREG_W(AVR8_SREG_Z, (res == 0) ? 1 :0); |
| 713 | SREG_W(AVR8_SREG_N, 0); |
| 714 | SREG_W(AVR8_SREG_V, SREG_R(AVR8_SREG_N) ^ SREG_R(AVR8_SREG_C)); |
| 715 | SREG_W(AVR8_SREG_S, SREG_R(AVR8_SREG_N) ^ SREG_R(AVR8_SREG_V)); |
| 633 | 716 | break; |
| 634 | 717 | case 0x0007: // ROR Rd |
| 635 | 718 | //output += sprintf( output, "ROR R%d", RD5(op) ); |
| r5568 | r5569 | |
| 642 | 725 | cpustate->pc = POP(cpustate); |
| 643 | 726 | cpustate->pc |= POP(cpustate) << 8; |
| 644 | 727 | cpustate->pc--; |
| 728 | opcycles = 4; |
| 645 | 729 | break; |
| 646 | 730 | case 0x0010: // RETI |
| 647 | | //output += sprintf( output, "RETI" ); |
| 648 | | unimplemented_opcode(cpustate, op); |
| 731 | cpustate->pc = POP(cpustate); |
| 732 | cpustate->pc |= POP(cpustate) << 8; |
| 733 | cpustate->pc--; |
| 734 | SREG_W(AVR8_SREG_I, 1); |
| 735 | opcycles = 4; |
| 649 | 736 | break; |
| 650 | 737 | case 0x0080: // SLEEP |
| 651 | 738 | //output += sprintf( output, "SLEEP" ); |
| r5568 | r5569 | |
| 661 | 748 | break; |
| 662 | 749 | case 0x00c0: // LPM |
| 663 | 750 | WRITE_IO_8(cpustate, 0, READ_PRG_8(cpustate, ZREG)); |
| 751 | opcycles = 3; |
| 664 | 752 | break; |
| 665 | 753 | case 0x00d0: // ELPM |
| 666 | 754 | //output += sprintf( output, "ELPM" ); |
| r5568 | r5569 | |
| 698 | 786 | } |
| 699 | 787 | break; |
| 700 | 788 | case 0x000a: // DEC Rd |
| 701 | | //output += sprintf( output, "DEC R%d", RD5(op) ); |
| 702 | | unimplemented_opcode(cpustate, op); |
| 789 | rd = READ_IO_8(cpustate, RD5(op)); |
| 790 | res = rd - 1; |
| 791 | SREG_W(AVR8_SREG_V, (rd == 0x7f) ? 1 : 0); |
| 792 | SREG_W(AVR8_SREG_N, BIT(res,7)); |
| 793 | SREG_W(AVR8_SREG_S, SREG_R(AVR8_SREG_N) ^ SREG_R(AVR8_SREG_V)); |
| 794 | SREG_W(AVR8_SREG_Z, (res == 0) ? 1 : 0); |
| 795 | WRITE_IO_8(cpustate, RD5(op), res); |
| 703 | 796 | break; |
| 704 | 797 | case 0x000c: |
| 705 | 798 | case 0x000d: // JMP k |
| r5568 | r5569 | |
| 727 | 820 | break; |
| 728 | 821 | case 0x0700: // SBIW Rd+1:Rd,K |
| 729 | 822 | //output += sprintf( output, "SBIW R%d:R%d, 0x%02x", 24+(RD2(op) << 1)+1, 24+(RD2(op) << 1), KCONST6(op) ); |
| 823 | unimplemented_opcode(cpustate, op); |
| 730 | 824 | break; |
| 731 | 825 | case 0x0800: // CBI A,b |
| 732 | 826 | //output += sprintf( output, "CBI 0x%02x, %d", ACONST5(op), RR3(op) ); |
| 827 | WRITE_IO_8(cpustate, ACONST5(op), READ_IO_8(cpustate, ACONST5(op)) &~ (1 << RR3(op))); |
| 828 | opcycles = 2; |
| 733 | 829 | break; |
| 734 | 830 | case 0x0900: // SBIC A,b |
| 735 | 831 | //output += sprintf( output, "SBIC 0x%02x, %d", ACONST5(op), RR3(op) ); |
| 832 | unimplemented_opcode(cpustate, op); |
| 736 | 833 | break; |
| 737 | 834 | case 0x0a00: // SBI A,b |
| 738 | 835 | //output += sprintf( output, "SBI 0x%02x, %d", ACONST5(op), RR3(op) ); |
| 836 | WRITE_IO_8(cpustate, ACONST5(op), READ_IO_8(cpustate, ACONST5(op)) | (1 << RR3(op))); |
| 837 | opcycles = 2; |
| 739 | 838 | break; |
| 740 | 839 | case 0x0b00: // SBIS A,b |
| 741 | 840 | //output += sprintf( output, "SBIS 0x%02x, %d", ACONST5(op), RR3(op) ); |
| 841 | unimplemented_opcode(cpustate, op); |
| 742 | 842 | break; |
| 743 | 843 | case 0x0c00: |
| 744 | 844 | case 0x0d00: |
| 745 | 845 | case 0x0e00: |
| 746 | 846 | case 0x0f00: // MUL Rd,Rr |
| 747 | 847 | //output += sprintf( output, "MUL R%d, R%d", RD5(op), RR5(op) ); |
| 848 | unimplemented_opcode(cpustate, op); |
| 748 | 849 | break; |
| 749 | 850 | } |
| 750 | 851 | break; |
| 751 | 852 | case 0xb000: |
| 752 | | unimplemented_opcode(cpustate, op); |
| 753 | 853 | if(op & 0x0800) // OUT A,Rr |
| 754 | 854 | { |
| 755 | | //output += sprintf( output, "OUT 0x%02x, R%d", ACONST6(op), RD5(op) ); |
| 855 | WRITE_IO_8(cpustate, 0x20 + ACONST6(op), READ_IO_8(cpustate, RD5(op))); |
| 756 | 856 | } |
| 757 | 857 | else // IN Rd,A |
| 758 | 858 | { |
| 759 | | //output += sprintf( output, "IN R%d, 0x%02x", RD5(op), ACONST6(op) ); |
| 859 | WRITE_IO_8(cpustate, RD5(op), READ_IO_8(cpustate, 0x20 + ACONST6(op))); |
| 760 | 860 | } |
| 761 | 861 | break; |
| 762 | 862 | case 0xc000: // RJMP k |
| 763 | 863 | offs = (INT32)((op & 0x0800) ? ((op & 0x0fff) | 0xfffff000) : (op & 0x0fff)); |
| 764 | 864 | cpustate->pc += offs; |
| 865 | opcycles = 2; |
| 765 | 866 | break; |
| 766 | 867 | case 0xd000: // RCALL k |
| 767 | 868 | offs = (INT32)((op & 0x0800) ? ((op & 0x0fff) | 0xfffff000) : (op & 0x0fff)); |
| 768 | 869 | PUSH(cpustate, ((cpustate->pc + 1) >> 8) & 0x00ff); |
| 769 | 870 | PUSH(cpustate, (cpustate->pc + 1) & 0x00ff); |
| 770 | 871 | cpustate->pc += offs; |
| 872 | opcycles = 3; |
| 771 | 873 | break; |
| 772 | 874 | case 0xe000: // LDI Rd,K |
| 773 | 875 | rd = KCONST8(op); |
| r5568 | r5569 | |
| 785 | 887 | offs |= 0xffffff80; |
| 786 | 888 | } |
| 787 | 889 | cpustate->pc += offs; |
| 890 | opcycles = 2; |
| 788 | 891 | } |
| 789 | 892 | break; |
| 790 | 893 | case 0x0400: // BRSH through BRID |
| r5568 | r5569 | |
| 796 | 899 | offs |= 0xffffff80; |
| 797 | 900 | } |
| 798 | 901 | cpustate->pc += offs; |
| 902 | opcycles = 2; |
| 799 | 903 | } |
| 800 | 904 | break; |
| 801 | 905 | case 0x0800: |
| 802 | | unimplemented_opcode(cpustate, op); |
| 803 | 906 | if(op & 0x0200) // BST Rd, b |
| 804 | 907 | { |
| 805 | | //output += sprintf( output, "BST R%d, %d", RD5(op), RR3(op) ); |
| 908 | SREG_W(AVR8_SREG_T, (BIT(READ_IO_8(cpustate, RD5(op)),RR3(op))) ? 1 : 0); |
| 806 | 909 | } |
| 807 | 910 | else // BLD Rd, b |
| 808 | 911 | { |
| 809 | | //output += sprintf( output, "BLD R%d, %d", RD5(op), RR3(op) ); |
| 912 | if(SREG_R(AVR8_SREG_T)) |
| 913 | { |
| 914 | WRITE_IO_8(cpustate, RD5(op), READ_IO_8(cpustate, RD5(op)) | (1 << RR3(op))); |
| 915 | } |
| 916 | else |
| 917 | { |
| 918 | WRITE_IO_8(cpustate, RD5(op), READ_IO_8(cpustate, RD5(op)) &~ (1 << RR3(op))); |
| 919 | } |
| 810 | 920 | } |
| 811 | 921 | break; |
| 812 | 922 | case 0x0c00: |
| 813 | | unimplemented_opcode(cpustate, op); |
| 814 | 923 | if(op & 0x0200) // SBRS Rd, b |
| 815 | 924 | { |
| 816 | | //output += sprintf( output, "SBRS R%d, %d", RD5(op), RR3(op) ); |
| 925 | if(BIT(READ_IO_8(cpustate, RD5(op)),RR3(op))) |
| 926 | { |
| 927 | op = (UINT32)READ_PRG_16(cpustate, cpustate->pc++); |
| 928 | opcycles = 2; |
| 929 | if((op & 0xfe0c) == 0x940c || |
| 930 | (op & 0xfe0f) == 0xfe0f) |
| 931 | { |
| 932 | cpustate->pc++; |
| 933 | opcycles = 3; |
| 934 | } |
| 935 | } |
| 817 | 936 | } |
| 818 | 937 | else // SBRC Rd, b |
| 819 | 938 | { |
| 820 | | //output += sprintf( output, "SBRC R%d, %d", RD5(op), RR3(op) ); |
| 939 | if(!BIT(READ_IO_8(cpustate, RD5(op)),RR3(op))) |
| 940 | { |
| 941 | op = (UINT32)READ_PRG_16(cpustate, cpustate->pc++); |
| 942 | opcycles = 2; |
| 943 | if((op & 0xfe0c) == 0x940c || |
| 944 | (op & 0xfc0f) == 0x9000) |
| 945 | { |
| 946 | cpustate->pc++; |
| 947 | opcycles = 3; |
| 948 | } |
| 949 | } |
| 821 | 950 | } |
| 822 | 951 | break; |
| 823 | 952 | } |
| r5568 | r5569 | |
| 826 | 955 | |
| 827 | 956 | cpustate->pc++; |
| 828 | 957 | |
| 829 | | --cpustate->icount; |
| 958 | cpustate->icount -= opcycles; |
| 830 | 959 | } |
| 831 | 960 | |
| 832 | 961 | return cycles - cpustate->icount; |
| r5568 | r5569 | |
| 840 | 969 | |
| 841 | 970 | switch (state) |
| 842 | 971 | { |
| 972 | |
| 973 | /* interrupt lines/exceptions */ |
| 974 | case CPUINFO_INT_INPUT_STATE + AVR8_INT_RESET: avr8_set_irq_line(cpustate, AVR8_INT_RESET, info->i); break; |
| 975 | case CPUINFO_INT_INPUT_STATE + AVR8_INT_INT0: avr8_set_irq_line(cpustate, AVR8_INT_INT0, info->i); break; |
| 976 | case CPUINFO_INT_INPUT_STATE + AVR8_INT_INT1: avr8_set_irq_line(cpustate, AVR8_INT_INT1, info->i); break; |
| 977 | case CPUINFO_INT_INPUT_STATE + AVR8_INT_PCINT0: avr8_set_irq_line(cpustate, AVR8_INT_PCINT0, info->i); break; |
| 978 | case CPUINFO_INT_INPUT_STATE + AVR8_INT_PCINT1: avr8_set_irq_line(cpustate, AVR8_INT_PCINT1, info->i); break; |
| 979 | case CPUINFO_INT_INPUT_STATE + AVR8_INT_PCINT2: avr8_set_irq_line(cpustate, AVR8_INT_PCINT2, info->i); break; |
| 980 | case CPUINFO_INT_INPUT_STATE + AVR8_INT_WDT: avr8_set_irq_line(cpustate, AVR8_INT_WDT, info->i); break; |
| 981 | case CPUINFO_INT_INPUT_STATE + AVR8_INT_T2COMPA: avr8_set_irq_line(cpustate, AVR8_INT_T2COMPA, info->i); break; |
| 982 | case CPUINFO_INT_INPUT_STATE + AVR8_INT_T2COMPB: avr8_set_irq_line(cpustate, AVR8_INT_T2COMPB, info->i); break; |
| 983 | case CPUINFO_INT_INPUT_STATE + AVR8_INT_T2OVF: avr8_set_irq_line(cpustate, AVR8_INT_T2OVF, info->i); break; |
| 984 | case CPUINFO_INT_INPUT_STATE + AVR8_INT_T1CAPT: avr8_set_irq_line(cpustate, AVR8_INT_T1CAPT, info->i); break; |
| 985 | case CPUINFO_INT_INPUT_STATE + AVR8_INT_T1COMPA: avr8_set_irq_line(cpustate, AVR8_INT_T1COMPA, info->i); break; |
| 986 | case CPUINFO_INT_INPUT_STATE + AVR8_INT_T1COMPB: avr8_set_irq_line(cpustate, AVR8_INT_T1COMPB, info->i); break; |
| 987 | case CPUINFO_INT_INPUT_STATE + AVR8_INT_T1OVF: avr8_set_irq_line(cpustate, AVR8_INT_T1OVF, info->i); break; |
| 988 | case CPUINFO_INT_INPUT_STATE + AVR8_INT_T0COMPA: avr8_set_irq_line(cpustate, AVR8_INT_T0COMPA, info->i); break; |
| 989 | case CPUINFO_INT_INPUT_STATE + AVR8_INT_T0COMPB: avr8_set_irq_line(cpustate, AVR8_INT_T0COMPB, info->i); break; |
| 990 | case CPUINFO_INT_INPUT_STATE + AVR8_INT_T0OVF: avr8_set_irq_line(cpustate, AVR8_INT_T0OVF, info->i); break; |
| 991 | case CPUINFO_INT_INPUT_STATE + AVR8_INT_SPI_STC: avr8_set_irq_line(cpustate, AVR8_INT_SPI_STC, info->i); break; |
| 992 | case CPUINFO_INT_INPUT_STATE + AVR8_INT_USART_RX: avr8_set_irq_line(cpustate, AVR8_INT_USART_RX, info->i); break; |
| 993 | case CPUINFO_INT_INPUT_STATE + AVR8_INT_USART_UDRE: avr8_set_irq_line(cpustate, AVR8_INT_USART_UDRE, info->i); break; |
| 994 | case CPUINFO_INT_INPUT_STATE + AVR8_INT_USART_TX: avr8_set_irq_line(cpustate, AVR8_INT_USART_TX, info->i); break; |
| 995 | case CPUINFO_INT_INPUT_STATE + AVR8_INT_ADC: avr8_set_irq_line(cpustate, AVR8_INT_ADC, info->i); break; |
| 996 | case CPUINFO_INT_INPUT_STATE + AVR8_INT_EE_RDY: avr8_set_irq_line(cpustate, AVR8_INT_EE_RDY, info->i); break; |
| 997 | case CPUINFO_INT_INPUT_STATE + AVR8_INT_ANALOG_COMP: avr8_set_irq_line(cpustate, AVR8_INT_ANALOG_COMP, info->i); break; |
| 998 | case CPUINFO_INT_INPUT_STATE + AVR8_INT_TWI: avr8_set_irq_line(cpustate, AVR8_INT_TWI, info->i); break; |
| 999 | case CPUINFO_INT_INPUT_STATE + AVR8_INT_SPM_RDY: avr8_set_irq_line(cpustate, AVR8_INT_SPM_RDY, info->i); break; |
| 1000 | |
| 843 | 1001 | /* --- the following bits of info are set as 64-bit signed integers --- */ |
| 844 | 1002 | case CPUINFO_INT_PC: /* intentional fallthrough */ |
| 845 | 1003 | case CPUINFO_INT_REGISTER + AVR8_PC: cpustate->pc = info->i; break; |
| r5568 | r5569 | |
| 966 | 1124 | case CPUINFO_STR_REGISTER + AVR8_X: sprintf(info->s, "X: %04x", XREG ); break; |
| 967 | 1125 | case CPUINFO_STR_REGISTER + AVR8_Y: sprintf(info->s, "Y: %04x", YREG ); break; |
| 968 | 1126 | case CPUINFO_STR_REGISTER + AVR8_Z: sprintf(info->s, "Z: %04x", ZREG ); break; |
| 1127 | case CPUINFO_STR_REGISTER + AVR8_SP: sprintf(info->s, "SP: %04x", SPREG ); break; |
| 969 | 1128 | } |
| 970 | 1129 | } |
src/emu/cpu/mips/mips3com.c
| r5568 | r5569 | |
| 558 | 558 | case CPUINFO_STR_REGISTER + MIPS3_WIRED: sprintf(info->s, "Wired:%08X", (UINT32)mips->cpr[0][COP0_Wired]); break; |
| 559 | 559 | case CPUINFO_STR_REGISTER + MIPS3_BADVADDR: sprintf(info->s, "BadVAddr:%08X", (UINT32)mips->cpr[0][COP0_BadVAddr]); break; |
| 560 | 560 | |
| 561 | | case CPUINFO_STR_REGISTER + MIPS3_R0: sprintf(info->s, "R0: %08X%08X", (UINT32)(mips->r[0] >> 32), (UINT32)mips->r[0]); break; |
| 562 | | case CPUINFO_STR_REGISTER + MIPS3_R1: sprintf(info->s, "R1: %08X%08X", (UINT32)(mips->r[1] >> 32), (UINT32)mips->r[1]); break; |
| 563 | | case CPUINFO_STR_REGISTER + MIPS3_R2: sprintf(info->s, "R2: %08X%08X", (UINT32)(mips->r[2] >> 32), (UINT32)mips->r[2]); break; |
| 564 | | case CPUINFO_STR_REGISTER + MIPS3_R3: sprintf(info->s, "R3: %08X%08X", (UINT32)(mips->r[3] >> 32), (UINT32)mips->r[3]); break; |
| 565 | | case CPUINFO_STR_REGISTER + MIPS3_R4: sprintf(info->s, "R4: %08X%08X", (UINT32)(mips->r[4] >> 32), (UINT32)mips->r[4]); break; |
| 566 | | case CPUINFO_STR_REGISTER + MIPS3_R5: sprintf(info->s, "R5: %08X%08X", (UINT32)(mips->r[5] >> 32), (UINT32)mips->r[5]); break; |
| 567 | | case CPUINFO_STR_REGISTER + MIPS3_R6: sprintf(info->s, "R6: %08X%08X", (UINT32)(mips->r[6] >> 32), (UINT32)mips->r[6]); break; |
| 568 | | case CPUINFO_STR_REGISTER + MIPS3_R7: sprintf(info->s, "R7: %08X%08X", (UINT32)(mips->r[7] >> 32), (UINT32)mips->r[7]); break; |
| 569 | | case CPUINFO_STR_REGISTER + MIPS3_R8: sprintf(info->s, "R8: %08X%08X", (UINT32)(mips->r[8] >> 32), (UINT32)mips->r[8]); break; |
| 570 | | case CPUINFO_STR_REGISTER + MIPS3_R9: sprintf(info->s, "R9: %08X%08X", (UINT32)(mips->r[9] >> 32), (UINT32)mips->r[9]); break; |
| 571 | | case CPUINFO_STR_REGISTER + MIPS3_R10: sprintf(info->s, "R10:%08X%08X", (UINT32)(mips->r[10] >> 32), (UINT32)mips->r[10]); break; |
| 572 | | case CPUINFO_STR_REGISTER + MIPS3_R11: sprintf(info->s, "R11:%08X%08X", (UINT32)(mips->r[11] >> 32), (UINT32)mips->r[11]); break; |
| 573 | | case CPUINFO_STR_REGISTER + MIPS3_R12: sprintf(info->s, "R12:%08X%08X", (UINT32)(mips->r[12] >> 32), (UINT32)mips->r[12]); break; |
| 574 | | case CPUINFO_STR_REGISTER + MIPS3_R13: sprintf(info->s, "R13:%08X%08X", (UINT32)(mips->r[13] >> 32), (UINT32)mips->r[13]); break; |
| 575 | | case CPUINFO_STR_REGISTER + MIPS3_R14: sprintf(info->s, "R14:%08X%08X", (UINT32)(mips->r[14] >> 32), (UINT32)mips->r[14]); break; |
| 576 | | case CPUINFO_STR_REGISTER + MIPS3_R15: sprintf(info->s, "R15:%08X%08X", (UINT32)(mips->r[15] >> 32), (UINT32)mips->r[15]); break; |
| 577 | | case CPUINFO_STR_REGISTER + MIPS3_R16: sprintf(info->s, "R16:%08X%08X", (UINT32)(mips->r[16] >> 32), (UINT32)mips->r[16]); break; |
| 578 | | case CPUINFO_STR_REGISTER + MIPS3_R17: sprintf(info->s, "R17:%08X%08X", (UINT32)(mips->r[17] >> 32), (UINT32)mips->r[17]); break; |
| 579 | | case CPUINFO_STR_REGISTER + MIPS3_R18: sprintf(info->s, "R18:%08X%08X", (UINT32)(mips->r[18] >> 32), (UINT32)mips->r[18]); break; |
| 580 | | case CPUINFO_STR_REGISTER + MIPS3_R19: sprintf(info->s, "R19:%08X%08X", (UINT32)(mips->r[19] >> 32), (UINT32)mips->r[19]); break; |
| 581 | | case CPUINFO_STR_REGISTER + MIPS3_R20: sprintf(info->s, "R20:%08X%08X", (UINT32)(mips->r[20] >> 32), (UINT32)mips->r[20]); break; |
| 582 | | case CPUINFO_STR_REGISTER + MIPS3_R21: sprintf(info->s, "R21:%08X%08X", (UINT32)(mips->r[21] >> 32), (UINT32)mips->r[21]); break; |
| 583 | | case CPUINFO_STR_REGISTER + MIPS3_R22: sprintf(info->s, "R22:%08X%08X", (UINT32)(mips->r[22] >> 32), (UINT32)mips->r[22]); break; |
| 584 | | case CPUINFO_STR_REGISTER + MIPS3_R23: sprintf(info->s, "R23:%08X%08X", (UINT32)(mips->r[23] >> 32), (UINT32)mips->r[23]); break; |
| 585 | | case CPUINFO_STR_REGISTER + MIPS3_R24: sprintf(info->s, "R24:%08X%08X", (UINT32)(mips->r[24] >> 32), (UINT32)mips->r[24]); break; |
| 586 | | case CPUINFO_STR_REGISTER + MIPS3_R25: sprintf(info->s, "R25:%08X%08X", (UINT32)(mips->r[25] >> 32), (UINT32)mips->r[25]); break; |
| 587 | | case CPUINFO_STR_REGISTER + MIPS3_R26: sprintf(info->s, "R26:%08X%08X", (UINT32)(mips->r[26] >> 32), (UINT32)mips->r[26]); break; |
| 588 | | case CPUINFO_STR_REGISTER + MIPS3_R27: sprintf(info->s, "R27:%08X%08X", (UINT32)(mips->r[27] >> 32), (UINT32)mips->r[27]); break; |
| 589 | | case CPUINFO_STR_REGISTER + MIPS3_R28: sprintf(info->s, "R28:%08X%08X", (UINT32)(mips->r[28] >> 32), (UINT32)mips->r[28]); break; |
| 590 | | case CPUINFO_STR_REGISTER + MIPS3_R29: sprintf(info->s, "R29:%08X%08X", (UINT32)(mips->r[29] >> 32), (UINT32)mips->r[29]); break; |
| 591 | | case CPUINFO_STR_REGISTER + MIPS3_R30: sprintf(info->s, "R30:%08X%08X", (UINT32)(mips->r[30] >> 32), (UINT32)mips->r[30]); break; |
| 592 | | case CPUINFO_STR_REGISTER + MIPS3_R31: sprintf(info->s, "R31:%08X%08X", (UINT32)(mips->r[31] >> 32), (UINT32)mips->r[31]); break; |
| 561 | case CPUINFO_STR_REGISTER + MIPS3_R0: sprintf(info->s, "$zero: %08X%08X", (UINT32)(mips->r[0] >> 32), (UINT32)mips->r[0]); break; |
| 562 | case CPUINFO_STR_REGISTER + MIPS3_R1: sprintf(info->s, " $at: %08X%08X", (UINT32)(mips->r[1] >> 32), (UINT32)mips->r[1]); break; |
| 563 | case CPUINFO_STR_REGISTER + MIPS3_R2: sprintf(info->s, " $v0: %08X%08X", (UINT32)(mips->r[2] >> 32), (UINT32)mips->r[2]); break; |
| 564 | case CPUINFO_STR_REGISTER + MIPS3_R3: sprintf(info->s, " $v1: %08X%08X", (UINT32)(mips->r[3] >> 32), (UINT32)mips->r[3]); break; |
| 565 | case CPUINFO_STR_REGISTER + MIPS3_R4: sprintf(info->s, " $a0: %08X%08X", (UINT32)(mips->r[4] >> 32), (UINT32)mips->r[4]); break; |
| 566 | case CPUINFO_STR_REGISTER + MIPS3_R5: sprintf(info->s, " $a1: %08X%08X", (UINT32)(mips->r[5] >> 32), (UINT32)mips->r[5]); break; |
| 567 | case CPUINFO_STR_REGISTER + MIPS3_R6: sprintf(info->s, " $a2: %08X%08X", (UINT32)(mips->r[6] >> 32), (UINT32)mips->r[6]); break; |
| 568 | case CPUINFO_STR_REGISTER + MIPS3_R7: sprintf(info->s, " $a3: %08X%08X", (UINT32)(mips->r[7] >> 32), (UINT32)mips->r[7]); break; |
| 569 | case CPUINFO_STR_REGISTER + MIPS3_R8: sprintf(info->s, " $t0: %08X%08X", (UINT32)(mips->r[8] >> 32), (UINT32)mips->r[8]); break; |
| 570 | case CPUINFO_STR_REGISTER + MIPS3_R9: sprintf(info->s, " $t1: %08X%08X", (UINT32)(mips->r[9] >> 32), (UINT32)mips->r[9]); break; |
| 571 | case CPUINFO_STR_REGISTER + MIPS3_R10: sprintf(info->s, " $t2:%08X%08X", (UINT32)(mips->r[10] >> 32), (UINT32)mips->r[10]); break; |
| 572 | case CPUINFO_STR_REGISTER + MIPS3_R11: sprintf(info->s, " $t3:%08X%08X", (UINT32)(mips->r[11] >> 32), (UINT32)mips->r[11]); break; |
| 573 | case CPUINFO_STR_REGISTER + MIPS3_R12: sprintf(info->s, " $t4:%08X%08X", (UINT32)(mips->r[12] >> 32), (UINT32)mips->r[12]); break; |
| 574 | case CPUINFO_STR_REGISTER + MIPS3_R13: sprintf(info->s, " $t5:%08X%08X", (UINT32)(mips->r[13] >> 32), (UINT32)mips->r[13]); break; |
| 575 | case CPUINFO_STR_REGISTER + MIPS3_R14: sprintf(info->s, " $t6:%08X%08X", (UINT32)(mips->r[14] >> 32), (UINT32)mips->r[14]); break; |
| 576 | case CPUINFO_STR_REGISTER + MIPS3_R15: sprintf(info->s, " $t7:%08X%08X", (UINT32)(mips->r[15] >> 32), (UINT32)mips->r[15]); break; |
| 577 | case CPUINFO_STR_REGISTER + MIPS3_R16: sprintf(info->s, " $s0:%08X%08X", (UINT32)(mips->r[16] >> 32), (UINT32)mips->r[16]); break; |
| 578 | case CPUINFO_STR_REGISTER + MIPS3_R17: sprintf(info->s, " $s1:%08X%08X", (UINT32)(mips->r[17] >> 32), (UINT32)mips->r[17]); break; |
| 579 | case CPUINFO_STR_REGISTER + MIPS3_R18: sprintf(info->s, " $s2:%08X%08X", (UINT32)(mips->r[18] >> 32), (UINT32)mips->r[18]); break; |
| 580 | case CPUINFO_STR_REGISTER + MIPS3_R19: sprintf(info->s, " $s3:%08X%08X", (UINT32)(mips->r[19] >> 32), (UINT32)mips->r[19]); break; |
| 581 | case CPUINFO_STR_REGISTER + MIPS3_R20: sprintf(info->s, " $s4:%08X%08X", (UINT32)(mips->r[20] >> 32), (UINT32)mips->r[20]); break; |
| 582 | case CPUINFO_STR_REGISTER + MIPS3_R21: sprintf(info->s, " $s5:%08X%08X", (UINT32)(mips->r[21] >> 32), (UINT32)mips->r[21]); break; |
| 583 | case CPUINFO_STR_REGISTER + MIPS3_R22: sprintf(info->s, " $s6:%08X%08X", (UINT32)(mips->r[22] >> 32), (UINT32)mips->r[22]); break; |
| 584 | case CPUINFO_STR_REGISTER + MIPS3_R23: sprintf(info->s, " $s7:%08X%08X", (UINT32)(mips->r[23] >> 32), (UINT32)mips->r[23]); break; |
| 585 | case CPUINFO_STR_REGISTER + MIPS3_R24: sprintf(info->s, " $t8:%08X%08X", (UINT32)(mips->r[24] >> 32), (UINT32)mips->r[24]); break; |
| 586 | case CPUINFO_STR_REGISTER + MIPS3_R25: sprintf(info->s, " $t9:%08X%08X", (UINT32)(mips->r[25] >> 32), (UINT32)mips->r[25]); break; |
| 587 | case CPUINFO_STR_REGISTER + MIPS3_R26: sprintf(info->s, " $k0:%08X%08X", (UINT32)(mips->r[26] >> 32), (UINT32)mips->r[26]); break; |
| 588 | case CPUINFO_STR_REGISTER + MIPS3_R27: sprintf(info->s, " $k1:%08X%08X", (UINT32)(mips->r[27] >> 32), (UINT32)mips->r[27]); break; |
| 589 | case CPUINFO_STR_REGISTER + MIPS3_R28: sprintf(info->s, " $gp:%08X%08X", (UINT32)(mips->r[28] >> 32), (UINT32)mips->r[28]); break; |
| 590 | case CPUINFO_STR_REGISTER + MIPS3_R29: sprintf(info->s, " $sp:%08X%08X", (UINT32)(mips->r[29] >> 32), (UINT32)mips->r[29]); break; |
| 591 | case CPUINFO_STR_REGISTER + MIPS3_R30: sprintf(info->s, " $fp:%08X%08X", (UINT32)(mips->r[30] >> 32), (UINT32)mips->r[30]); break; |
| 592 | case CPUINFO_STR_REGISTER + MIPS3_R31: sprintf(info->s, " $ra:%08X%08X", (UINT32)(mips->r[31] >> 32), (UINT32)mips->r[31]); break; |
| 593 | 593 | case CPUINFO_STR_REGISTER + MIPS3_HI: sprintf(info->s, "HI: %08X%08X", (UINT32)(mips->r[REG_HI] >> 32), (UINT32)mips->r[REG_HI]); break; |
| 594 | 594 | case CPUINFO_STR_REGISTER + MIPS3_LO: sprintf(info->s, "LO: %08X%08X", (UINT32)(mips->r[REG_LO] >> 32), (UINT32)mips->r[REG_LO]); break; |
| 595 | 595 | |
src/mess/machine/snescart.c
| r5568 | r5569 | |
| 42 | 42 | /* Some known countries */ |
| 43 | 43 | static const char *const countries[] = |
| 44 | 44 | { |
| 45 | | /* 0*/ "Japan (NTSC)", "USA & Canada (NTSC)", "Europe, Oceania & Asia (PAL)", "Sweden (PAL)", |
| 46 | | /* 4*/ "Finland (PAL)", "Denmark (PAL)", "France (PAL)", "Holland (PAL)", |
| 45 | /* 0*/ "Japan (NTSC)", "USA & Canada (NTSC)", "Europe, Oceania & Asia (PAL)", "Sweden (PAL)", |
| 46 | /* 4*/ "Finland (PAL)", "Denmark (PAL)", "France (PAL)", "Holland (PAL)", |
| 47 | 47 | /* 8*/ "Spain (PAL)", "Germany, Austria & Switzerland (PAL)", "Italy (PAL)", "Hong Kong & China (PAL)", |
| 48 | 48 | /* c*/ "Indonesia (PAL)", "South Korea (NTSC)", UNK, UNK, |
| 49 | 49 | }; |
| r5568 | r5569 | |
| 51 | 51 | /* Some known companies (integrations to the list from Snes9x) */ |
| 52 | 52 | static const char *const companies[] = |
| 53 | 53 | { |
| 54 | | /* 0*/ "Invalid", "Nintendo", "Ajinomoto", "Imagineer-Zoom", "Chris Gray Enterprises Inc.", "Zamuse", "Falcom", UNK, |
| 55 | | /* 8*/ "Capcom", "HOT-B", "Jaleco", "Coconuts", "Rage Software", "Micronet", "Technos", "Mebio Software", |
| 56 | | /*10*/ "SHOUEi System", "Starfish", "Gremlin Graphics", "Electronic Arts", "NCS / Masaya", "COBRA Team", "Human/Field", "KOEI", |
| 57 | | /*18*/ "Hudson Soft", "Game Village", "Yanoman", UNK, "Tecmo", UNK, "Open System", "Virgin Games", |
| 54 | /* 0*/ "Invalid", "Nintendo", "Ajinomoto", "Imagineer-Zoom", "Chris Gray Enterprises Inc.", "Zamuse", "Falcom", UNK, |
| 55 | /* 8*/ "Capcom", "HOT-B", "Jaleco", "Coconuts", "Rage Software", "Micronet", "Technos", "Mebio Software", |
| 56 | /*10*/ "SHOUEi System", "Starfish", "Gremlin Graphics", "Electronic Arts", "NCS / Masaya", "COBRA Team", "Human/Field", "KOEI", |
| 57 | /*18*/ "Hudson Soft", "Game Village", "Yanoman", UNK, "Tecmo", UNK, "Open System", "Virgin Games", |
| 58 | 58 | /*20*/ "KSS", "Sunsoft", "POW", "Micro World", UNK, UNK, "Enix", "Loriciel/Electro Brain", |
| 59 | 59 | /*28*/ "Kemco", "Seta Co.,Ltd.", "Culture Brain", "Irem Japan", "Pal Soft", "Visit Co.,Ltd.", "INTEC Inc.", "System Sacom Corp.", |
| 60 | | /*30*/ "Viacom New Media", "Carrozzeria", "Dynamic", "Nintendo", "Magifact", "Hect", UNK, UNK, |
| 61 | | /*38*/ "Capcom Europe", "Accolade Europe", UNK, "Arcade Zone", "Empire Software", "Loriciel", "Gremlin Graphics", UNK, |
| 62 | | /*40*/ "Seika Corp.", "UBI Soft", UNK, UNK, "LifeFitness Exertainment", UNK, "System 3", "Spectrum Holobyte", |
| 63 | | /*48*/ UNK, "Irem", UNK, "Raya Systems/Sculptured Software", "Renovation Products", "Malibu Games/Black Pearl", UNK, "U.S. Gold", |
| 64 | | /*50*/ "Absolute Entertainment", "Acclaim", "Activision", "American Sammy", "GameTek", "Hi Tech Expressions", "LJN Toys", UNK, |
| 65 | | /*58*/ UNK, UNK, "Mindscape", "Romstar, Inc.", UNK, "Tradewest", UNK, "American Softworks Corp.", |
| 66 | | /*60*/ "Titus", "Virgin Interactive Entertainment", "Maxis", "Origin/FCI/Pony Canyon", UNK, UNK, UNK, "Ocean", |
| 67 | | /*68*/ UNK, "Electronic Arts", UNK, "Laser Beam", UNK, UNK, "Elite", "Electro Brain", |
| 68 | | /*70*/ "Infogrames", "Interplay", "LucasArts", "Parker Brothers", "Konami", "STORM", UNK, UNK, |
| 69 | | /*78*/ "THQ Software", "Accolade Inc.", "Triffix Entertainment", UNK, "Microprose", UNK, UNK, "Kemco", |
| 60 | /*30*/ "Viacom New Media", "Carrozzeria", "Dynamic", "Nintendo", "Magifact", "Hect", UNK, UNK, |
| 61 | /*38*/ "Capcom Europe", "Accolade Europe", UNK, "Arcade Zone", "Empire Software", "Loriciel", "Gremlin Graphics", UNK, |
| 62 | /*40*/ "Seika Corp.", "UBI Soft", UNK, UNK, "LifeFitness Exertainment", UNK, "System 3", "Spectrum Holobyte", |
| 63 | /*48*/ UNK, "Irem", UNK, "Raya Systems/Sculptured Software", "Renovation Products", "Malibu Games/Black Pearl", UNK, "U.S. Gold", |
| 64 | /*50*/ "Absolute Entertainment", "Acclaim", "Activision", "American Sammy", "GameTek", "Hi Tech Expressions", "LJN Toys", UNK, |
| 65 | /*58*/ UNK, UNK, "Mindscape", "Romstar, Inc.", UNK, "Tradewest", UNK, "American Softworks Corp.", |
| 66 | /*60*/ "Titus", "Virgin Interactive Entertainment", "Maxis", "Origin/FCI/Pony Canyon", UNK, UNK, UNK, "Ocean", |
| 67 | /*68*/ UNK, "Electronic Arts", UNK, "Laser Beam", UNK, UNK, "Elite", "Electro Brain", |
| 68 | /*70*/ "Infogrames", "Interplay", "LucasArts", "Parker Brothers", "Konami", "STORM", UNK, UNK, |
| 69 | /*78*/ "THQ Software", "Accolade Inc.", "Triffix Entertainment", UNK, "Microprose", UNK, UNK, "Kemco", |
| 70 | 70 | /*80*/ "Misawa", "Teichio", "Namco Ltd.", "Lozc", "Koei", UNK, "Tokuma Shoten Intermedia", "Tsukuda Original", |
| 71 | | /*88*/ "DATAM-Polystar", UNK, UNK, "Bullet-Proof Software", "Vic Tokai", UNK, "Character Soft", "I\'\'Max", |
| 72 | | /*90*/ "Takara", "CHUN Soft", "Video System Co., Ltd.", "BEC", UNK, "Varie", "Yonezawa / S'Pal Corp.", "Kaneco", |
| 73 | | /*98*/ UNK, "Pack in Video", "Nichibutsu", "TECMO", "Imagineer Co.", UNK, UNK, UNK, |
| 74 | | /*a0*/ "Telenet", "Hori", UNK, UNK, "Konami", "K.Amusement Leasing Co.", UNK, "Takara", |
| 75 | | /*a8*/ UNK, "Technos Jap.", "JVC", UNK, "Toei Animation", "Toho", UNK, "Namco Ltd.", |
| 76 | | /*b0*/ "Media Rings Corp.", "ASCII Co. Activison", "Bandai", UNK, "Enix America", UNK, "Halken", UNK, |
| 77 | | /*b8*/ UNK, UNK, "Culture Brain", "Sunsoft", "Toshiba EMI", "Sony Imagesoft", UNK, "Sammy", |
| 78 | | /*c0*/ "Taito", UNK, "Kemco", "Square", "Tokuma Soft", "Data East", "Tonkin House", UNK, |
| 79 | | /*c8*/ "KOEI", UNK, "Konami USA", "NTVIC", UNK, "Meldac", "Pony Canyon", "Sotsu Agency/Sunrise", |
| 80 | | /*d0*/ "Disco/Taito", "Sofel", "Quest Corp.", "Sigma", "Ask Kodansha Co., Ltd.", UNK, "Naxat", UNK, |
| 81 | | /*d8*/ "Capcom Co., Ltd.", "Banpresto", "Tomy", "Acclaim", UNK, "NCS", "Human Entertainment", "Altron", |
| 82 | | /*e0*/ "Jaleco", UNK, "Yutaka", UNK, "T&ESoft", "EPOCH Co.,Ltd.", UNK, "Athena", |
| 83 | | /*e8*/ "Asmik", "Natsume", "King Records", "Atlus", "Sony Music Entertainment", UNK, "IGS", UNK, |
| 84 | | /*f0*/ UNK, "Motown Software", "Left Field Entertainment", "Beam Software", "Tec Magik", UNK, UNK, UNK, |
| 71 | /*88*/ "DATAM-Polystar", UNK, UNK, "Bullet-Proof Software", "Vic Tokai", UNK, "Character Soft", "I\'\'Max", |
| 72 | /*90*/ "Takara", "CHUN Soft", "Video System Co., Ltd.", "BEC", UNK, "Varie", "Yonezawa / S'Pal Corp.", "Kaneco", |
| 73 | /*98*/ UNK, "Pack in Video", "Nichibutsu", "TECMO", "Imagineer Co.", UNK, UNK, UNK, |
| 74 | /*a0*/ "Telenet", "Hori", UNK, UNK, "Konami", "K.Amusement Leasing Co.", UNK, "Takara", |
| 75 | /*a8*/ UNK, "Technos Jap.", "JVC", UNK, "Toei Animation", "Toho", UNK, "Namco Ltd.", |
| 76 | /*b0*/ "Media Rings Corp.", "ASCII Co. Activison", "Bandai", UNK, "Enix America", UNK, "Halken", UNK, |
| 77 | /*b8*/ UNK, UNK, "Culture Brain", "Sunsoft", "Toshiba EMI", "Sony Imagesoft", UNK, "Sammy", |
| 78 | /*c0*/ "Taito", UNK, "Kemco", "Square", "Tokuma Soft", "Data East", "Tonkin House", UNK, |
| 79 | /*c8*/ "KOEI", UNK, "Konami USA", "NTVIC", UNK, "Meldac", "Pony Canyon", "Sotsu Agency/Sunrise", |
| 80 | /*d0*/ "Disco/Taito", "Sofel", "Quest Corp.", "Sigma", "Ask Kodansha Co., Ltd.", UNK, "Naxat", UNK, |
| 81 | /*d8*/ "Capcom Co., Ltd.", "Banpresto", "Tomy", "Acclaim", UNK, "NCS", "Human Entertainment", "Altron", |
| 82 | /*e0*/ "Jaleco", UNK, "Yutaka", UNK, "T&ESoft", "EPOCH Co.,Ltd.", UNK, "Athena", |
| 83 | /*e8*/ "Asmik", "Natsume", "King Records", "Atlus", "Sony Music Entertainment", UNK, "IGS", UNK, |
| 84 | /*f0*/ UNK, "Motown Software", "Left Field Entertainment", "Beam Software", "Tec Magik", UNK, UNK, UNK, |
| 85 | 85 | /*f8*/ UNK, "Cybersoft", UNK, "Psygnosis", UNK, UNK, "Davidson", UNK, |
| 86 | 86 | }; |
| 87 | 87 | |
| r5568 | r5569 | |
| 107 | 107 | else if (id == 'E') value = 0x0e; |
| 108 | 108 | else if (id == 'F') value = 0x0f; |
| 109 | 109 | else value = 0x00; |
| 110 | | |
| 110 | |
| 111 | 111 | return value; |
| 112 | 112 | } |
| 113 | 113 | |
| r5568 | r5569 | |
| 130 | 130 | |
| 131 | 131 | if (snes_cart.mode == SNES_MODE_20) |
| 132 | 132 | { |
| 133 | | /* There could be some larger image needing banks 0x70 to 0x7f at address 0x8000 for ROM |
| 133 | /* There could be some larger image needing banks 0x70 to 0x7f at address 0x8000 for ROM |
| 134 | 134 | * mirroring. These should be treated separately or data would be overwritten by SRAM */ |
| 135 | 135 | for (ii = 0; ii < 16; ii++) |
| 136 | 136 | { |
| r5568 | r5569 | |
| 237 | 237 | |
| 238 | 238 | /* $00:[000-7fff] contains uninitialized RAM and MMIO. |
| 239 | 239 | reset vector must point to ROM at $00:[8000-ffff] to be considered valid. */ |
| 240 | | if (reset_vector < 0x8000) |
| 240 | if (reset_vector < 0x8000) |
| 241 | 241 | return 0; |
| 242 | 242 | |
| 243 | 243 | /* some images duplicate the header in multiple locations, and others have completely |
| 244 | | invalid header information that cannot be relied upon. The code below will analyze |
| 245 | | the first opcode executed at the specified reset vector to determine the probability |
| 244 | invalid header information that cannot be relied upon. The code below will analyze |
| 245 | the first opcode executed at the specified reset vector to determine the probability |
| 246 | 246 | that this is the correct header. Score is assigned accordingly. */ |
| 247 | 247 | |
| 248 | 248 | /* most likely opcodes */ |
| r5568 | r5569 | |
| 252 | 252 | || reset_opcode == 0x9c //stz $nnnn (stz $4200) |
| 253 | 253 | || reset_opcode == 0x4c //jmp $nnnn |
| 254 | 254 | || reset_opcode == 0x5c //jml $nnnnnn |
| 255 | | ) |
| 255 | ) |
| 256 | 256 | score += 8; |
| 257 | 257 | |
| 258 | 258 | /* plausible opcodes */ |
| r5568 | r5569 | |
| 267 | 267 | || reset_opcode == 0xa0 //ldy #$nn |
| 268 | 268 | || reset_opcode == 0x20 //jsr $nnnn |
| 269 | 269 | || reset_opcode == 0x22 //jsl $nnnnnn |
| 270 | | ) |
| 270 | ) |
| 271 | 271 | score += 4; |
| 272 | 272 | |
| 273 | 273 | /* implausible opcodes */ |
| r5568 | r5569 | |
| 277 | 277 | || reset_opcode == 0xcd //cmp $nnnn |
| 278 | 278 | || reset_opcode == 0xec //cpx $nnnn |
| 279 | 279 | || reset_opcode == 0xcc //cpy $nnnn |
| 280 | | ) |
| 280 | ) |
| 281 | 281 | score -= 4; |
| 282 | 282 | |
| 283 | 283 | /* least likely opcodes */ |
| r5568 | r5569 | |
| 286 | 286 | || reset_opcode == 0xdb //stp |
| 287 | 287 | || reset_opcode == 0x42 //wdm |
| 288 | 288 | || reset_opcode == 0xff //sbc $nnnnnn,x |
| 289 | | ) |
| 289 | ) |
| 290 | 290 | score -= 8; |
| 291 | 291 | |
| 292 | 292 | /* Sometimes, both the header and reset vector's first opcode will match ... |
| 293 | 293 | fallback and rely on info validity in these cases to determine more likely header. */ |
| 294 | 294 | |
| 295 | 295 | /* a valid checksum is the biggest indicator of a valid header. */ |
| 296 | | if ((checksum + ichecksum) == 0xffff && (checksum != 0) && (ichecksum != 0)) |
| 296 | if ((checksum + ichecksum) == 0xffff && (checksum != 0) && (ichecksum != 0)) |
| 297 | 297 | score += 4; |
| 298 | 298 | |
| 299 | 299 | /* then there are the expected mapper values */ |
| r5568 | r5569 | |
| 307 | 307 | score += 2; |
| 308 | 308 | |
| 309 | 309 | if (offset == 0x40ffc0 && mapper == 0x25) // 0x25 is usually ExHiROM |
| 310 | | score += 2; |
| 310 | score += 2; |
| 311 | 311 | |
| 312 | 312 | /* finally, there are valid values in the Company, Region etc. fields */ |
| 313 | 313 | if (infoblock[offset + 0x1a] == 0x33) // Company field: 0x33 indicates extended header |
| 314 | | score += 2; |
| 314 | score += 2; |
| 315 | 315 | |
| 316 | 316 | if (infoblock[offset + 0x16] < 0x08) // ROM Type field |
| 317 | 317 | score++; |
| 318 | 318 | |
| 319 | | if (infoblock[offset + 0x17] < 0x10) // ROM Size field |
| 319 | if (infoblock[offset + 0x17] < 0x10) // ROM Size field |
| 320 | 320 | score++; |
| 321 | 321 | |
| 322 | | if (infoblock[offset + 0x18] < 0x08) // SRAM Size field |
| 322 | if (infoblock[offset + 0x18] < 0x08) // SRAM Size field |
| 323 | 323 | score++; |
| 324 | 324 | |
| 325 | | if (infoblock[offset + 0x19] < 14) // Region field |
| 325 | if (infoblock[offset + 0x19] < 14) // Region field |
| 326 | 326 | score++; |
| 327 | 327 | |
| 328 | 328 | /* do we still have a positive score? */ |
| 329 | | if (score < 0) |
| 329 | if (score < 0) |
| 330 | 330 | score = 0; |
| 331 | 331 | |
| 332 | 332 | return score; |
| r5568 | r5569 | |
| 377 | 377 | image_fseek(image, offset, SEEK_SET); |
| 378 | 378 | } |
| 379 | 379 | |
| 380 | | /* We need to take a sample to test what mode we need to be in (the |
| 380 | /* We need to take a sample to test what mode we need to be in (the |
| 381 | 381 | sample has to be quite large to cope with large carts in ExHiRom) */ |
| 382 | 382 | image_fread(image, temp_buffer, 0x40ffff); |
| 383 | 383 | image_fseek(image, offset, SEEK_SET); /* Rewind */ |
| r5568 | r5569 | |
| 406 | 406 | snes_cart.mode = SNES_MODE_21; // HiRom |
| 407 | 407 | snes_cart.sram_max = 0x20000; |
| 408 | 408 | } |
| 409 | | else |
| 409 | else |
| 410 | 410 | { |
| 411 | 411 | snes_cart.mode = SNES_MODE_25; // ExHiRom |
| 412 | 412 | snes_cart.sram_max = 0x20000; |
| r5568 | r5569 | |
| 418 | 418 | total_blocks = ((image_length(image) - offset) / (snes_cart.mode & 0x05 ? 0x8000 : 0x10000)); |
| 419 | 419 | read_blocks = 0; |
| 420 | 420 | |
| 421 | | /* Loading all the data blocks from cart, we only partially cover banks 0x00 to 0x7f. Therefore, we |
| 422 | | * have to mirror the blocks until we reach the end. E.g. for a 11Mbits image (44 blocks), we proceed |
| 423 | | * as follows: |
| 421 | /* Loading all the data blocks from cart, we only partially cover banks 0x00 to 0x7f. Therefore, we |
| 422 | * have to mirror the blocks until we reach the end. E.g. for a 11Mbits image (44 blocks), we proceed |
| 423 | * as follows: |
| 424 | 424 | * 11 Mbits = 8 Mbits (blocks 1->32) + 2 Mbits (blocks 33->40) + 1 Mbit (blocks 41->44). |
| 425 | 425 | * Hence, we fill memory up to 16 Mbits (banks 0x00 to 0x3f) mirroring as follows |
| 426 | 426 | * 8 Mbits (blocks 1->32) + 2 Mbits (blocks 33->40) + 1 Mbit (blocks 41->44) + 1 Mbit (blocks 41->44) |
| 427 | 427 | * + 2 Mbits (blocks 33->40) + 1 Mbit (blocks 41->44) + 1 Mbit (blocks 41->44) |
| 428 | 428 | * and we repeat the same blocks in the second half of the banks (banks 0x40 to 0x7f). |
| 429 | | * This is likely what happens in the real SNES as well, because the unit cannot be aware of the exact |
| 429 | * This is likely what happens in the real SNES as well, because the unit cannot be aware of the exact |
| 430 | 430 | * size of data in the cart (procedure confirmed by byuu) |
| 431 | 431 | */ |
| 432 | 432 | switch (snes_cart.mode) |
| 433 | 433 | { |
| 434 | 434 | case SNES_MODE_21: |
| 435 | | /* HiROM carts load data in banks 0xc0 to 0xff. Each bank is fully mirrored in banks 0x40 to 0x7f |
| 436 | | * (actually up to 0x7d, because 0x7e and 0x7f are overwritten by WRAM). The top half (address |
| 437 | | * range 0x8000 - 0xffff) of each bank is also mirrored in banks 0x00 to 0x3f and 0x80 to 0xbf. |
| 435 | /* HiROM carts load data in banks 0xc0 to 0xff. Each bank is fully mirrored in banks 0x40 to 0x7f |
| 436 | * (actually up to 0x7d, because 0x7e and 0x7f are overwritten by WRAM). The top half (address |
| 437 | * range 0x8000 - 0xffff) of each bank is also mirrored in banks 0x00 to 0x3f and 0x80 to 0xbf. |
| 438 | 438 | */ |
| 439 | 439 | while (read_blocks < 64 && read_blocks < total_blocks) |
| 440 | 440 | { |
| r5568 | r5569 | |
| 463 | 463 | break; |
| 464 | 464 | |
| 465 | 465 | case SNES_MODE_25: |
| 466 | | /* Extendend HiROM carts start to load data in banks 0xc0 to 0xff. However, they exceed the |
| 467 | | * available space in these banks, and continue loading at banks 0x40 to 0x7f. The top half |
| 466 | /* Extendend HiROM carts start to load data in banks 0xc0 to 0xff. However, they exceed the |
| 467 | * available space in these banks, and continue loading at banks 0x40 to 0x7f. The top half |
| 468 | 468 | * (address range 0x8000 - 0xffff) of each bank is also mirrored either to banks 0x00 to 0x3f |
| 469 | 469 | * (for data in banks 0x40 to 0x7f) or to banks 0x80 to 0xbf (for data in banks 0xc0 to 0xff). |
| 470 | | * Notice that banks 0x7e and 0x7f are overwritten by WRAM, but they could contain data at |
| 471 | | * address > 0x8000 because the mirrors at 0x3e and 0x3f are not overwritten. |
| 470 | * Notice that banks 0x7e and 0x7f are overwritten by WRAM, but they could contain data at |
| 471 | * address > 0x8000 because the mirrors at 0x3e and 0x3f are not overwritten. |
| 472 | 472 | */ |
| 473 | 473 | /* Reading the first 64 blocks */ |
| 474 | 474 | while (read_blocks < 64 && read_blocks < total_blocks) |
| r5568 | r5569 | |
| 512 | 512 | break; |
| 513 | 513 | |
| 514 | 514 | case SNES_MODE_22: |
| 515 | | /* "Extendend LoROM" carts have their data loaded in banks 0x00 to 0x3f at address 0x8000. |
| 515 | /* "Extendend LoROM" carts have their data loaded in banks 0x00 to 0x3f at address 0x8000. |
| 516 | 516 | * These are then mirrored in banks 0x40 to 0x7f, both at address 0x0000 and at address |
| 517 | | * 0x8000, in banks 0x80 to 0xbf at address 0x8000 and in banks 0xc0 to 0xff, both at address |
| 517 | * 0x8000, in banks 0x80 to 0xbf at address 0x8000 and in banks 0xc0 to 0xff, both at address |
| 518 | 518 | * 0x0000 and at address 0x8000. Notice that SDD-1 games (Star Ocean and Street Fighter Zero 2) |
| 519 | | * also use SNES_MODE_22, but we still don't support their bankswitch mechanism: the content |
| 520 | | * of banks at 0xc0 to 0xff changes according to MMC registers $4804-$4807 |
| 519 | * also use SNES_MODE_22, but we still don't support their bankswitch mechanism: the content |
| 520 | * of banks at 0xc0 to 0xff changes according to MMC registers $4804-$4807 |
| 521 | 521 | */ |
| 522 | 522 | while (read_blocks < 64 && read_blocks < total_blocks) |
| 523 | 523 | { |
| r5568 | r5569 | |
| 549 | 549 | |
| 550 | 550 | default: |
| 551 | 551 | case SNES_MODE_20: |
| 552 | | /* LoROM carts load data in banks 0x00 to 0x7f at address 0x8000 (actually up to 0x7d, because 0x7e and |
| 553 | | * 0x7f are overwritten by WRAM). Each block is also mirrored in banks 0x80 to 0xff (up to 0xff for real) |
| 552 | /* LoROM carts load data in banks 0x00 to 0x7f at address 0x8000 (actually up to 0x7d, because 0x7e and |
| 553 | * 0x7f are overwritten by WRAM). Each block is also mirrored in banks 0x80 to 0xff (up to 0xff for real) |
| 554 | 554 | */ |
| 555 | 555 | while (read_blocks < 128 && read_blocks < total_blocks) |
| 556 | 556 | { |
| r5568 | r5569 | |
| 632 | 632 | case 0x1a: // GSU-1 (21 MHz at start) |
| 633 | 633 | if (snes_r_bank1(space, 0x00ffd5) == 0x20) |
| 634 | 634 | snes_has_addon_chip = HAS_SUPERFX; |
| 635 | supported_type = 1; |
| 635 | 636 | break; |
| 636 | 637 | |
| 637 | 638 | case 0x25: |
| r5568 | r5569 | |
| 662 | 663 | break; |
| 663 | 664 | |
| 664 | 665 | case 0xf3: |
| 665 | | snes_has_addon_chip = HAS_C4; |
| 666 | snes_has_addon_chip = HAS_CX4; |
| 666 | 667 | break; |
| 667 | | |
| 668 | |
| 668 | 669 | case 0xf5: |
| 669 | 670 | if (snes_r_bank1(space, 0x00ffd5) == 0x30) |
| 670 | 671 | snes_has_addon_chip = HAS_ST018; |
| r5568 | r5569 | |
| 673 | 674 | break; |
| 674 | 675 | |
| 675 | 676 | case 0xf6: |
| 676 | | /* These Seta ST-01X chips have both 0x30 at 0x00ffd5, |
| 677 | /* These Seta ST-01X chips have both 0x30 at 0x00ffd5, |
| 677 | 678 | they only differ for the 'size' at 0x00ffd7 */ |
| 678 | 679 | if (snes_r_bank1(space, 0x00ffd7) < 0x0a) |
| 679 | 680 | snes_has_addon_chip = HAS_ST011; |
| r5568 | r5569 | |
| 685 | 686 | if (snes_r_bank1(space, 0x00ffd5) == 0x3a) |
| 686 | 687 | snes_has_addon_chip = HAS_SPC7110_RTC; |
| 687 | 688 | break; |
| 688 | | |
| 689 | |
| 689 | 690 | default: |
| 690 | 691 | snes_has_addon_chip = HAS_UNK; |
| 691 | 692 | break; |
| r5568 | r5569 | |
| 700 | 701 | for( i = 0; i < 2; i++ ) |
| 701 | 702 | company_id[i] = snes_r_bank1(space, 0x00ffb0 + i); |
| 702 | 703 | company = (char_to_int_conv(company_id[0]) << 4) + char_to_int_conv(company_id[1]); |
| 703 | | if (company == 0) |
| 704 | if (company == 0) |
| 704 | 705 | company = snes_r_bank1(space, 0x00ffda); |
| 705 | 706 | |
| 706 | 707 | /* ROM ID */ |
| r5568 | r5569 | |
| 727 | 728 | logerror( "ROM DETAILS\n" ); |
| 728 | 729 | logerror( "===========\n\n" ); |
| 729 | 730 | logerror( "\tTotal blocks: %d (%dmb)\n", total_blocks, total_blocks / (snes_cart.mode & 5 ? 32 : 16) ); |
| 730 | | logerror( "\tROM bank size: %s (LoROM: %d , HiROM: %d, ExHiROM: %d)\n", |
| 731 | | (snes_cart.mode == SNES_MODE_20) ? "LoROM" : ((snes_cart.mode == SNES_MODE_21) ? "HiROM" : "ExHiROM"), |
| 731 | logerror( "\tROM bank size: %s (LoROM: %d , HiROM: %d, ExHiROM: %d)\n", |
| 732 | (snes_cart.mode == SNES_MODE_20) ? "LoROM" : ((snes_cart.mode == SNES_MODE_21) ? "HiROM" : "ExHiROM"), |
| 732 | 733 | valid_mode20, valid_mode21, valid_mode25); |
| 733 | 734 | logerror( "\tCompany: %s [%.2s]\n", companies[company], company_id ); |
| 734 | 735 | logerror( "\tROM ID: %.4s\n\n", rom_id ); |
src/mess/drivers/craft.c
| r5568 | r5569 | |
| 6 | 6 | |
| 7 | 7 | #include "driver.h" |
| 8 | 8 | #include "cpu/avr8/avr8.h" |
| 9 | #include "sound/dac.h" |
| 9 | 10 | |
| 11 | #define MASTER_CLOCK 20000000 |
| 12 | |
| 10 | 13 | /****************************************************\ |
| 11 | 14 | * I/O devices * |
| 12 | 15 | \****************************************************/ |
| r5568 | r5569 | |
| 74 | 77 | |
| 75 | 78 | UINT8 res7[5]; |
| 76 | 79 | |
| 77 | | UINT8 spl; |
| 78 | | UINT8 sph; |
| 80 | UINT16 sp; |
| 79 | 81 | UINT8 sreg; |
| 80 | 82 | |
| 81 | 83 | UINT8 wdtcsr; |
| r5568 | r5569 | |
| 121 | 123 | |
| 122 | 124 | UINT8 res14; |
| 123 | 125 | |
| 124 | | UINT8 tcnt1l; |
| 125 | | UINT8 tcnt1h; |
| 126 | | UINT8 icr1l; |
| 127 | | UINT8 icr1h; |
| 128 | | UINT8 ocr1al; |
| 129 | | UINT8 ocr1ah; |
| 130 | | UINT8 ocr1bl; |
| 131 | | UINT8 ocr1bh; |
| 126 | UINT16 tcnt1; |
| 127 | UINT16 icr1; |
| 128 | UINT16 ocr1a; |
| 129 | UINT16 ocr1b; |
| 132 | 130 | |
| 133 | 131 | UINT8 res15[36]; |
| 134 | 132 | |
| r5568 | r5569 | |
| 164 | 162 | UINT8 udr0; |
| 165 | 163 | |
| 166 | 164 | UINT8 res20[57]; |
| 165 | |
| 166 | UINT8 hidden_high; |
| 167 | |
| 168 | INT64 last_tcnt1_cycle; |
| 169 | |
| 170 | emu_timer *ocr1a_timer; |
| 171 | emu_timer *ocr1b_timer; |
| 167 | 172 | } avr8_regs; |
| 168 | 173 | |
| 169 | 174 | static avr8_regs regs; |
| 170 | 175 | |
| 176 | #define AVR8_TIMSK1_OCIE1A 0x02 |
| 177 | #define AVR8_TIMSK1_OCIE1B 0x04 |
| 178 | |
| 179 | static UINT64 avr8_get_timer_1_frequency(avr8_regs *device) |
| 180 | { |
| 181 | UINT64 frequency = 0; |
| 182 | switch(device->tccr1b & 0x07) |
| 183 | { |
| 184 | case 0: // No clock source (Timer/Counter stopped). |
| 185 | case 6: // External clock source on T1 pin. Clock on falling edge. |
| 186 | case 7: // External clock source on T1 pin. Clock on rising edge. |
| 187 | frequency = 0; |
| 188 | break; |
| 189 | |
| 190 | case 1: // clk / 1 (No prescaling) |
| 191 | frequency = MASTER_CLOCK; |
| 192 | break; |
| 193 | |
| 194 | case 2: // clk / 8 (From prescaler) |
| 195 | frequency = MASTER_CLOCK / 8; |
| 196 | break; |
| 197 | |
| 198 | case 3: // clk / 64 (From prescaler) |
| 199 | frequency = MASTER_CLOCK / 64; |
| 200 | break; |
| 201 | |
| 202 | case 4: // clk / 256 (From prescaler) |
| 203 | frequency = MASTER_CLOCK / 256; |
| 204 | break; |
| 205 | |
| 206 | case 5: // clk / 1024 (From prescaler) |
| 207 | frequency = MASTER_CLOCK / 1024; |
| 208 | break; |
| 209 | |
| 210 | default: |
| 211 | frequency = 0; |
| 212 | printf( "device->tccr1b & 0x07 returned a value not in the range of 0 to 7. This is\n" ); |
| 213 | printf( "impossible. Please ensure that your walls are not bleeding and your bathroom\n" ); |
| 214 | printf( "has not turned into a psychokinetic vortex.\n" ); |
| 215 | break; |
| 216 | } |
| 217 | |
| 218 | return frequency; |
| 219 | } |
| 220 | |
| 221 | static void avr8_maybe_start_timer_1(avr8_regs *device) |
| 222 | { |
| 223 | UINT64 frequency = avr8_get_timer_1_frequency(device); |
| 224 | if(frequency == 0) |
| 225 | { |
| 226 | timer_adjust_oneshot(device->ocr1a_timer, attotime_never, 0); |
| 227 | timer_adjust_oneshot(device->ocr1b_timer, attotime_never, 0); |
| 228 | } |
| 229 | else |
| 230 | { |
| 231 | UINT16 wrap_count_a = (UINT16)(((UINT32)device->ocr1a - (UINT32)device->tcnt1) & 0x0000ffff); |
| 232 | UINT16 wrap_count_b = (UINT16)(((UINT32)device->ocr1b - (UINT32)device->tcnt1) & 0x0000ffff); |
| 233 | attotime period_a = attotime_mul(ATTOTIME_IN_HZ(frequency), wrap_count_a); |
| 234 | attotime period_b = attotime_mul(ATTOTIME_IN_HZ(frequency), wrap_count_b); |
| 235 | if(device->timsk1 & AVR8_TIMSK1_OCIE1A) |
| 236 | { |
| 237 | timer_adjust_oneshot(device->ocr1a_timer, period_a, 0); |
| 238 | } |
| 239 | if(device->timsk1 & AVR8_TIMSK1_OCIE1B) |
| 240 | { |
| 241 | timer_adjust_oneshot(device->ocr1b_timer, period_b, 0); |
| 242 | } |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | static TIMER_CALLBACK( ocr1a_timer_compare ) |
| 247 | { |
| 248 | static int blah = 0; |
| 249 | printf( "ocr1a_timer_compare %d\n", blah++ ); |
| 250 | avr8_maybe_start_timer_1(®s); |
| 251 | |
| 252 | // Inaccurate |
| 253 | cpu_set_input_line(cputag_get_cpu(machine, "maincpu"), AVR8_INT_T1COMPA, ASSERT_LINE); |
| 254 | } |
| 255 | |
| 256 | static TIMER_CALLBACK( ocr1b_timer_compare ) |
| 257 | { |
| 258 | printf( "ocr1b_timer_compare\n" ); |
| 259 | avr8_maybe_start_timer_1(®s); |
| 260 | |
| 261 | // Inaccurate |
| 262 | cpu_set_input_line(cputag_get_cpu(machine, "maincpu"), AVR8_INT_T1COMPB, ASSERT_LINE); |
| 263 | } |
| 264 | |
| 171 | 265 | static READ8_HANDLER( avr8_read ) |
| 172 | 266 | { |
| 173 | 267 | switch( offset ) |
| r5568 | r5569 | |
| 197 | 291 | return regs.spsr; |
| 198 | 292 | case 0x5d: |
| 199 | 293 | //printf( "AVR8: R: regs.spl (%02x)\n", regs.spl ); |
| 200 | | return regs.spl; |
| 294 | return regs.sp & 0x00ff; |
| 201 | 295 | case 0x5e: |
| 202 | 296 | //printf( "AVR8: R: regs.sph (%02x)\n", regs.sph ); |
| 203 | | return regs.sph; |
| 297 | return (regs.sp >> 8) & 0x00ff; |
| 204 | 298 | case 0x5f: |
| 205 | 299 | return regs.sreg; |
| 206 | 300 | case 0x6f: |
| r5568 | r5569 | |
| 212 | 306 | case 0x81: |
| 213 | 307 | printf( "AVR8: R: regs.tccr1b (%02x)\n", regs.tccr1b ); |
| 214 | 308 | return regs.tccr1b; |
| 309 | case 0x84: |
| 310 | { |
| 311 | //INT64 divisor = 1; |
| 312 | /*INT64 update = (INT64)(cpu_get_total_cycles(space->cpu)) - last_tcnt1_cycle; |
| 313 | switch(device->tccr1b & 0x07) |
| 314 | { |
| 315 | case 0: // No clock source (Timer/Counter stopped). |
| 316 | case 1: // clk / 1 (No prescaling) |
| 317 | case 6: // External clock source on T1 pin. Clock on falling edge. |
| 318 | case 7: // External clock source on T1 pin. Clock on rising edge. |
| 319 | divisor = 1; |
| 320 | break; |
| 321 | |
| 322 | case 2: // clk / 8 (From prescaler) |
| 323 | divisor = 8; |
| 324 | break; |
| 325 | |
| 326 | case 3: // clk / 64 (From prescaler) |
| 327 | divisor = 64; |
| 328 | break; |
| 329 | |
| 330 | case 4: // clk / 256 (From prescaler) |
| 331 | divisor = 256; |
| 332 | break; |
| 333 | |
| 334 | case 5: // clk / 1024 (From prescaler) |
| 335 | divisor = 1024; |
| 336 | break; |
| 337 | |
| 338 | default: |
| 339 | divisor = 1; |
| 340 | printf( "device->tccr1b & 0x07 returned a value not in the range of 0 to 7. This is\n" ); |
| 341 | printf( "impossible. Please ensure that your walls are not bleeding and your bathroom\n" ); |
| 342 | printf( "has not turned into a psychokinetic vortex.\n" ); |
| 343 | break; |
| 344 | } |
| 345 | diff /= divisor; |
| 346 | diff %= regs.ocr1a; |
| 347 | printf( "AVR8: R: regs.tcnt1l read: %04x\n", ); |
| 348 | */break; |
| 349 | } |
| 350 | |
| 351 | case 0x85: |
| 352 | printf( "AVR8: R: regs.tcnt1h\n" ); |
| 353 | break; |
| 215 | 354 | case 0x88: |
| 216 | | printf( "AVR8: R: regs.ocr1al (%02x)\n", regs.ocr1al ); |
| 217 | | return regs.ocr1al; |
| 355 | printf( "AVR8: R: regs.ocr1al (%02x)\n", regs.ocr1a & 0x00ff ); |
| 356 | return regs.ocr1a & 0x00ff; |
| 218 | 357 | case 0x89: |
| 219 | | printf( "AVR8: R: regs.ocr1ah (%02x)\n", regs.ocr1ah ); |
| 220 | | return regs.ocr1ah; |
| 358 | printf( "AVR8: R: regs.ocr1ah (%02x)\n", (regs.ocr1a >> 8) & 0x00ff ); |
| 359 | return (regs.ocr1a >> 8) & 0x00ff; |
| 221 | 360 | case 0x8a: |
| 222 | | printf( "AVR8: R: regs.ocr1bl (%02x)\n", regs.ocr1bl ); |
| 223 | | return regs.ocr1bl; |
| 361 | printf( "AVR8: R: regs.ocr1bl (%02x)\n", regs.ocr1b & 0x00ff ); |
| 362 | return regs.ocr1b & 0x00ff; |
| 224 | 363 | case 0x8b: |
| 225 | | printf( "AVR8: R: regs.ocr1bh (%02x)\n", regs.ocr1bh ); |
| 226 | | return regs.ocr1bh; |
| 364 | printf( "AVR8: R: regs.ocr1bh (%02x)\n", (regs.ocr1b >> 8) & 0x00ff ); |
| 365 | return (regs.ocr1b >> 8) & 0x00ff; |
| 227 | 366 | case 0xb0: |
| 228 | 367 | printf( "AVR8: R: regs.tccr2a (%02x)\n", regs.tccr2a ); |
| 229 | 368 | return regs.tccr2a; |
| r5568 | r5569 | |
| 262 | 401 | printf( "AVR8: W: regs.ddrd = %02x\n", data ); |
| 263 | 402 | regs.ddrd = data; |
| 264 | 403 | break; |
| 404 | case 0x2b: |
| 405 | dac_data_w(devtag_get_device(space->machine, "dac"), data); |
| 406 | break; |
| 265 | 407 | case 0x4c: |
| 266 | 408 | printf( "AVR8: W: regs.spcr = %02x\n", data ); |
| 267 | 409 | regs.spcr = data; |
| r5568 | r5569 | |
| 271 | 413 | regs.spsr = data; |
| 272 | 414 | break; |
| 273 | 415 | case 0x5d: |
| 274 | | //printf( "AVR8: W: regs.spl = %02x\n", data ); |
| 275 | | regs.spl = data; |
| 416 | //printf( "AVR8: W: regs.sp(L) = %02x\n", data ); |
| 417 | regs.sp = (regs.hidden_high << 8) | data; |
| 276 | 418 | break; |
| 277 | 419 | case 0x5e: |
| 278 | | //printf( "AVR8: W: regs.sph = %02x\n", data ); |
| 279 | | regs.sph = data & 0x07; |
| 420 | //printf( "AVR8: W: regs.sp(H) = %02x\n", data ); |
| 421 | regs.hidden_high = data & 0x07; |
| 280 | 422 | break; |
| 281 | 423 | case 0x5f: |
| 282 | 424 | regs.sreg = data; |
| r5568 | r5569 | |
| 284 | 426 | case 0x6f: |
| 285 | 427 | printf( "AVR8: W: regs.timsk1 = %02x\n", data ); |
| 286 | 428 | regs.timsk1 = data; |
| 429 | avr8_maybe_start_timer_1(®s); |
| 287 | 430 | break; |
| 288 | 431 | case 0x80: |
| 289 | 432 | printf( "AVR8: W: regs.tccr1a = %02x\n", data ); |
| r5568 | r5569 | |
| 294 | 437 | regs.tccr1b = data; |
| 295 | 438 | break; |
| 296 | 439 | case 0x88: |
| 297 | | printf( "AVR8: W: regs.ocr1al = %02x\n", data ); |
| 298 | | regs.ocr1al = data; |
| 440 | printf( "AVR8: W: regs.ocr1a(L) = %02x\n", data ); |
| 441 | regs.ocr1a = (regs.hidden_high << 8) | data; |
| 442 | avr8_maybe_start_timer_1(®s); |
| 299 | 443 | break; |
| 300 | 444 | case 0x89: |
| 301 | | printf( "AVR8: W: regs.ocr1ah = %02x\n", data ); |
| 302 | | regs.ocr1ah = data; |
| 445 | printf( "AVR8: W: regs.ocr1a(H) = %02x\n", data ); |
| 446 | regs.hidden_high = data; |
| 303 | 447 | break; |
| 304 | 448 | case 0x8a: |
| 305 | | printf( "AVR8: W: regs.ocr1bl = %02x\n", data ); |
| 306 | | regs.ocr1bl = data; |
| 449 | printf( "AVR8: W: regs.ocr1b(L) = %02x\n", data ); |
| 450 | regs.ocr1b = (regs.hidden_high << 8) | data; |
| 451 | avr8_maybe_start_timer_1(®s); |
| 307 | 452 | break; |
| 308 | 453 | case 0x8b: |
| 309 | | printf( "AVR8: W: regs.ocr1bh = %02x\n", data ); |
| 310 | | regs.ocr1bh = data; |
| 454 | printf( "AVR8: W: regs.ocr1b(H) = %02x\n", data ); |
| 455 | regs.hidden_high = data; |
| 311 | 456 | break; |
| 312 | 457 | case 0xb0: |
| 313 | 458 | printf( "AVR8: W: regs.tccr2a = %02x\n", data ); |
| r5568 | r5569 | |
| 357 | 502 | * Machine definition * |
| 358 | 503 | \****************************************************/ |
| 359 | 504 | |
| 505 | static DRIVER_INIT( craft ) |
| 506 | { |
| 507 | regs.ocr1a_timer = timer_alloc(machine, ocr1a_timer_compare, 0); |
| 508 | regs.ocr1b_timer = timer_alloc(machine, ocr1b_timer_compare, 0); |
| 509 | } |
| 510 | |
| 360 | 511 | static MACHINE_RESET( craft ) |
| 361 | 512 | { |
| 513 | regs.timsk1 = 0; |
| 514 | regs.tcnt1 = 0; |
| 515 | regs.ocr1a = 0; |
| 516 | regs.ocr1b = 0; |
| 517 | regs.icr1 = 0; |
| 518 | regs.last_tcnt1_cycle = 0; |
| 519 | |
| 520 | dac_data_w(devtag_get_device(machine, "dac"), 0x00); |
| 362 | 521 | } |
| 363 | 522 | |
| 364 | 523 | static MACHINE_DRIVER_START( craft ) |
| 365 | 524 | /* basic machine hardware */ |
| 366 | | MDRV_CPU_ADD("maincpu", AVR8, 20000000) |
| 525 | MDRV_CPU_ADD("maincpu", AVR8, MASTER_CLOCK) |
| 367 | 526 | MDRV_CPU_PROGRAM_MAP(craft_prg_map) |
| 368 | 527 | MDRV_CPU_IO_MAP(craft_io_map) |
| 369 | 528 | |
| r5568 | r5569 | |
| 371 | 530 | |
| 372 | 531 | /* video hardware */ |
| 373 | 532 | MDRV_SCREEN_ADD("screen", RASTER) |
| 374 | | MDRV_SCREEN_REFRESH_RATE(60) |
| 375 | | MDRV_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(0)) |
| 533 | //MDRV_SCREEN_RAW_PARAMS( MASTER_CLOCK, 634, 0, 633, 525, 0, 481 ) |
| 534 | MDRV_SCREEN_REFRESH_RATE(60.08) |
| 535 | MDRV_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(1395)) /* accurate */ |
| 376 | 536 | MDRV_SCREEN_FORMAT(BITMAP_FORMAT_RGB32) |
| 377 | | MDRV_SCREEN_SIZE(640, 480) |
| 378 | | MDRV_SCREEN_VISIBLE_AREA(0, 639, 0, 479) |
| 537 | MDRV_SCREEN_SIZE(634, 480) |
| 538 | MDRV_SCREEN_VISIBLE_AREA(0, 633, 0, 479) |
| 379 | 539 | MDRV_PALETTE_LENGTH(0x1000) |
| 380 | 540 | |
| 381 | 541 | MDRV_VIDEO_START(generic_bitmapped) |
| 382 | 542 | MDRV_VIDEO_UPDATE(craft) |
| 543 | |
| 544 | /* sound hardware */ |
| 545 | MDRV_SPEAKER_STANDARD_MONO("avr8") |
| 546 | MDRV_SOUND_ADD("dac", DAC, 0) |
| 547 | MDRV_SOUND_ROUTE(0, "avr8", 1.00) |
| 383 | 548 | MACHINE_DRIVER_END |
| 384 | 549 | |
| 385 | 550 | ROM_START( craft ) |
| r5568 | r5569 | |
| 390 | 555 | ROM_END |
| 391 | 556 | |
| 392 | 557 | /* YEAR NAME PARENT COMPAT MACHINE INPUT INIT CONFIG COMPANY FULLNAME */ |
| 393 | | CONS(2008, craft, 0, 0, craft, craft, 0, 0, "Linus Akesson", "Craft", GAME_NO_SOUND | GAME_NOT_WORKING) |
| 558 | CONS(2008, craft, 0, 0, craft, craft, craft, 0, "Linus Akesson", "Craft", GAME_NO_SOUND | GAME_NOT_WORKING) |