src/mess/machine/lisa.c
| r2457 | r2458 | |
| 277 | 277 | if (VTIR != value) |
| 278 | 278 | { |
| 279 | 279 | VTIR = value; |
| 280 | | lisa_field_interrupts(machine); |
| 280 | if (VTIR==1) |
| 281 | lisa_field_interrupts(machine); |
| 281 | 282 | } |
| 282 | 283 | } |
| 283 | 284 | |
| r2457 | r2458 | |
| 337 | 338 | { |
| 338 | 339 | if ((! hold_COPS_data) && fifo_size && (! COPS_Ready)) |
| 339 | 340 | { |
| 340 | | /*logerror("Pushing one byte of data to VIA\n");*/ |
| 341 | logerror("Pushing one byte of data to VIA\n"); |
| 341 | 342 | |
| 342 | 343 | via_set_input_a(0, fifo_data[fifo_head]); /* output data */ |
| 343 | 344 | if (fifo_head == mouse_data_offset) |
| r2457 | r2458 | |
| 366 | 367 | #endif |
| 367 | 368 | |
| 368 | 369 | { |
| 369 | | /*logerror("Adding %d bytes of data to FIFO\n", len);*/ |
| 370 | logerror("Adding %d bytes of data to FIFO\n", len); |
| 370 | 371 | |
| 371 | 372 | while (len--) |
| 372 | 373 | { |
| r2457 | r2458 | |
| 390 | 391 | /* keyboard matrix to detect transition */ |
| 391 | 392 | static int key_matrix[8]; |
| 392 | 393 | |
| 393 | | static void scan_keyboard(running_machine *machine) |
| 394 | static void scan_keyboard( void ) |
| 394 | 395 | { |
| 395 | 396 | int i, j; |
| 396 | 397 | int keybuf; |
| r2457 | r2458 | |
| 399 | 400 | if (! COPS_force_unplug) |
| 400 | 401 | for (i=0; i<8; i++) |
| 401 | 402 | { |
| 402 | | keybuf = input_port_read_indexed(machine, i+2); |
| 403 | keybuf = readinputport(i+2); |
| 403 | 404 | |
| 404 | 405 | if (keybuf != key_matrix[i]) |
| 405 | 406 | { /* if state has changed, find first bit which has changed */ |
| r2457 | r2458 | |
| 444 | 445 | /*if (COPS_force_unplug) |
| 445 | 446 | return;*/ /* ???? */ |
| 446 | 447 | |
| 447 | | new_mx = input_port_read_indexed(machine, 0); |
| 448 | | new_my = input_port_read_indexed(machine, 1); |
| 448 | new_mx = readinputport(0); |
| 449 | new_my = readinputport(1); |
| 449 | 450 | |
| 450 | 451 | /* see if it moved in the x coord */ |
| 451 | 452 | if (new_mx != last_mx) |
| r2457 | r2458 | |
| 915 | 916 | for (y = 0; y < resy; y++) |
| 916 | 917 | { |
| 917 | 918 | for (x = 0; x < resx; x++) |
| 918 | | line_buffer[x] = (v[(x+y*resx)>>4] & (0x8000 >> ((x+y*resx) & 0xf))) ? 0 : 1; |
| 919 | // line_buffer[x] = (v[(x+y*resx)>>4] & (0x8000 >> ((x+y*resx) & 0xf))) ? 0 : 1; |
| 920 | line_buffer[x] = (v[(x+y*resx)>>4] & (0x8000 >> (x & 0xf))) ? 0 : 1; |
| 919 | 921 | draw_scanline8(bitmap, 0, y, resx, line_buffer, screen->machine->pens, -1); |
| 920 | 922 | } |
| 921 | 923 | return 0; |
| r2457 | r2458 | |
| 937 | 939 | { |
| 938 | 940 | if (address & 0x004000) |
| 939 | 941 | { |
| 940 | | the_seg = 0; /* correct ??? */ |
| 942 | // the_seg = 0; /* correct ??? */ |
| 941 | 943 | } |
| 942 | 944 | else |
| 943 | 945 | { |
| r2457 | r2458 | |
| 1297 | 1299 | /* set VBI */ |
| 1298 | 1300 | if (VTMSK) |
| 1299 | 1301 | set_VTIR(machine, 1); |
| 1300 | | |
| 1302 | else |
| 1303 | set_VTIR(machine, 0); |
| 1304 | |
| 1301 | 1305 | /* do keyboard scan */ |
| 1302 | | scan_keyboard(machine); |
| 1306 | scan_keyboard(); |
| 1303 | 1307 | } |
| 1304 | 1308 | |
| 1305 | 1309 | /* |
| r2457 | r2458 | |
| 1487 | 1491 | { /* special setup mode */ |
| 1488 | 1492 | if (offset & 0x002000) |
| 1489 | 1493 | { |
| 1490 | | the_seg = 0; /* correct ??? */ |
| 1494 | // the_seg = 0; /* correct ??? */ |
| 1491 | 1495 | } |
| 1492 | 1496 | else |
| 1493 | 1497 | { |
| r2457 | r2458 | |
| 1588 | 1592 | /* problem : due to collisions with video, timings of the LISA CPU |
| 1589 | 1593 | are slightly different from timings of a bare 68k */ |
| 1590 | 1594 | /* so we use a kludge... */ |
| 1591 | | #if 0 |
| 1592 | | /* theory - probably partially wrong, anyway */ |
| 1593 | | int time_in_frame = cpu_getcurrentcycles(); |
| 1594 | | int videoROM_address; |
| 1595 | | |
| 1596 | | videoROM_address = (time_in_frame / 4) & 0x7f; |
| 1597 | | |
| 1598 | | if ((time_in_frame >= 70000) || (time_in_frame <= 74000)) /* these values are approximative */ |
| 1599 | | { /* if VSyncing, read ROM 2nd half ? */ |
| 1600 | | videoROM_address |= 0x80; |
| 1601 | | } |
| 1602 | | #else |
| 1603 | | /* kludge */ |
| 1604 | | /* this code assumes the program always tries to read consecutive bytes */ |
| 1605 | | #if 0 |
| 1606 | | int time_in_frame = cpu_getcurrentcycles(); |
| 1607 | | static int videoROM_address = 0; |
| 1608 | | |
| 1609 | | videoROM_address = (videoROM_address + 1) & 0x7f; |
| 1610 | | /* the BOOT ROM only reads 56 bits, so there must be some wrap-around for |
| 1611 | | videoROM_address <= 56 */ |
| 1612 | | /* pixel clock 20MHz, memory access rate 1.25MHz, horizontal clock 22.7kHz |
| 1613 | | according to Apple, which must stand for 1.25MHz/55 = 22727kHz, vertical |
| 1614 | | clock approximately 60Hz, which means there are about 380 lines, including VBlank */ |
| 1615 | | if (videoROM_address == 55) |
| 1616 | | videoROM_address = 0; |
| 1617 | | |
| 1618 | | if ((time_in_frame >= 70000) && (time_in_frame <= 74000)) /* these values are approximative */ |
| 1619 | | { /* if VSyncing, read ROM 2nd half ? */ |
| 1620 | | videoROM_address |= 0x80; |
| 1621 | | } |
| 1622 | | #else |
| 1623 | 1595 | int time_in_frame = video_screen_get_vpos(machine->primary_screen); |
| 1624 | 1596 | static int videoROM_address = 0; |
| 1625 | 1597 | |
| 1626 | | videoROM_address = (videoROM_address + 1) & 0x7f; |
| 1627 | 1598 | /* the BOOT ROM only reads 56 bits, so there must be some wrap-around for |
| 1628 | 1599 | videoROM_address <= 56 */ |
| 1629 | 1600 | /* pixel clock 20MHz, memory access rate 1.25MHz, horizontal clock 22.7kHz |
| r2457 | r2458 | |
| 1631 | 1602 | clock approximately 60Hz, which means there are about 380 lines, including VBlank */ |
| 1632 | 1603 | /* The values are different on the Mac XL, and I don't know the correct values |
| 1633 | 1604 | for sure. */ |
| 1634 | | if (videoROM_address == ((lisa_features.has_mac_xl_video) ? 48/* ??? */ : 55)) |
| 1635 | | videoROM_address = 0; |
| 1636 | 1605 | |
| 1637 | 1606 | /* Something appears to be wrong with the timings, since we expect to read the |
| 1638 | 1607 | 2nd half when v-syncing, i.e. for lines beyond the 431th or 364th one (provided |
| r2457 | r2458 | |
| 1642 | 1611 | if (lisa_features.has_mac_xl_video) |
| 1643 | 1612 | { |
| 1644 | 1613 | if ((time_in_frame >= 374) && (time_in_frame <= 392)) /* these values have not been tested */ |
| 1645 | | { /* if VSyncing, read ROM 2nd half ? */ |
| 1646 | | videoROM_address |= 0x80; |
| 1647 | | } |
| 1614 | answer = videoROM_ptr[videoROM_address|0x80] << 8; |
| 1615 | else |
| 1616 | answer = videoROM_ptr[videoROM_address] << 8; |
| 1648 | 1617 | } |
| 1649 | 1618 | else |
| 1650 | 1619 | { |
| 1651 | | if ((time_in_frame >= 319) && (time_in_frame <= 338)) /* these values are approximative */ |
| 1652 | | { /* if VSyncing, read ROM 2nd half ? */ |
| 1653 | | videoROM_address |= 0x80; |
| 1620 | if ((time_in_frame >= 364) && (time_in_frame <= 375)) |
| 1621 | { |
| 1622 | answer = videoROM_ptr[videoROM_address|0x80] << 8; |
| 1623 | logerror("reading1 %06X=%04x PC=%06x time=%d\n", address, answer,safe_activecpu_get_pc(),time_in_frame); |
| 1654 | 1624 | } |
| 1625 | else |
| 1626 | { |
| 1627 | answer = videoROM_ptr[videoROM_address] << 8; |
| 1628 | logerror("reading2 %06X=%04x PC=%06x time=%d\n", address, answer,safe_activecpu_get_pc(),time_in_frame); |
| 1629 | } |
| 1655 | 1630 | } |
| 1656 | | #endif |
| 1657 | 1631 | |
| 1658 | | #endif |
| 1659 | 1632 | |
| 1660 | | answer = videoROM_ptr[videoROM_address] << 8; |
| 1633 | videoROM_address = (videoROM_address + 1) & 0x7f; |
| 1634 | if (videoROM_address == ((lisa_features.has_mac_xl_video) ? 48 : 56)) { |
| 1635 | logerror("loop %d\n", videoROM_address); |
| 1636 | videoROM_address = 0; |
| 1637 | } |
| 1661 | 1638 | |
| 1662 | | /*logerror("%X %X\n", videoROM_address, answer);*/ |
| 1663 | 1639 | } |
| 1664 | 1640 | break; |
| 1665 | 1641 | } |
| r2457 | r2458 | |
| 1683 | 1659 | { |
| 1684 | 1660 | if (offset & 0x002000) |
| 1685 | 1661 | { |
| 1686 | | the_seg = 0; /* correct ??? */ |
| 1662 | // the_seg = 0; /* correct ??? */ |
| 1687 | 1663 | } |
| 1688 | 1664 | else |
| 1689 | 1665 | { |
| 1690 | 1666 | if (offset & 0x004000) |
| 1691 | 1667 | { /* write to MMU register */ |
| 1692 | | /*logerror("write to segment registers (%X:%X) ", the_seg, segment);*/ |
| 1668 | logerror("write to segment registers (%X:%X) ", the_seg, segment); |
| 1693 | 1669 | if (offset & 0x000004) |
| 1694 | 1670 | { /* sorg register */ |
| 1695 | | /*logerror("sorg, data = %X\n", data);*/ |
| 1696 | | real_mmu_regs[the_seg][segment].sorg = data; |
| 1671 | logerror("sorg, data = %X\n", data); |
| 1672 | real_mmu_regs[the_seg][segment].sorg = data & 0xFFF; |
| 1697 | 1673 | mmu_regs[the_seg][segment].sorg = (data & 0x0fff) << 9; |
| 1698 | 1674 | } |
| 1699 | 1675 | else |
| 1700 | 1676 | { /* slim register */ |
| 1701 | | /*logerror("slim, data = %X\n", data);*/ |
| 1702 | | real_mmu_regs[the_seg][segment].slim = data; |
| 1677 | logerror("slim, data = %X\n", data); |
| 1678 | real_mmu_regs[the_seg][segment].slim = data & 0xFFF; |
| 1703 | 1679 | mmu_regs[the_seg][segment].slim = (~ (data << 9)) & 0x01ffff; |
| 1704 | 1680 | switch ((data & 0x0f00) >> 8) |
| 1705 | 1681 | { |
| r2457 | r2458 | |
| 1729 | 1705 | mmu_regs[the_seg][segment].type = invalid; |
| 1730 | 1706 | break; |
| 1731 | 1707 | case 0xF: |
| 1732 | | /*logerror("type : special I/O\n");*/ |
| 1708 | logerror("type : special I/O\n"); |
| 1733 | 1709 | mmu_regs[the_seg][segment].type = special_IO; |
| 1734 | 1710 | break; |
| 1735 | 1711 | default: /* "unpredictable results" */ |
| 1736 | | /*logerror("type : unknown\n");*/ |
| 1712 | logerror("type : unknown\n"); |
| 1737 | 1713 | mmu_regs[the_seg][segment].type = invalid; |
| 1738 | 1714 | break; |
| 1739 | 1715 | } |
| r2457 | r2458 | |
| 1770 | 1746 | COMBINE_DATA((UINT16 *) (lisa_ram_ptr + address)); |
| 1771 | 1747 | if (diag2) |
| 1772 | 1748 | { |
| 1773 | | if ((ACCESSING_BITS_0_7) |
| 1749 | if ((ACCESSING_LSB) |
| 1774 | 1750 | && ! (bad_parity_table[address >> 3] & (0x1 << (address & 0x7)))) |
| 1775 | 1751 | { |
| 1776 | 1752 | bad_parity_table[address >> 3] |= 0x1 << (address & 0x7); |
| 1777 | 1753 | bad_parity_count++; |
| 1778 | 1754 | } |
| 1779 | | if ((ACCESSING_BITS_8_15) |
| 1755 | if ((ACCESSING_MSB) |
| 1780 | 1756 | && ! (bad_parity_table[address >> 3] & (0x2 << (address & 0x7)))) |
| 1781 | 1757 | { |
| 1782 | 1758 | bad_parity_table[address >> 3] |= 0x2 << (address & 0x7); |
| r2457 | r2458 | |
| 1785 | 1761 | } |
| 1786 | 1762 | else if (bad_parity_table[address >> 3] & (0x3 << (address & 0x7))) |
| 1787 | 1763 | { |
| 1788 | | if ((ACCESSING_BITS_0_7) |
| 1764 | if ((ACCESSING_LSB) |
| 1789 | 1765 | && (bad_parity_table[address >> 3] & (0x1 << (address & 0x7)))) |
| 1790 | 1766 | { |
| 1791 | 1767 | bad_parity_table[address >> 3] &= ~ (0x1 << (address & 0x7)); |
| 1792 | 1768 | bad_parity_count--; |
| 1793 | 1769 | } |
| 1794 | | if ((ACCESSING_BITS_8_15) |
| 1770 | if ((ACCESSING_MSB) |
| 1795 | 1771 | && (bad_parity_table[address >> 3] & (0x2 << (address & 0x7)))) |
| 1796 | 1772 | { |
| 1797 | 1773 | bad_parity_table[address >> 3] &= ~ (0x2 << (address & 0x7)); |
| r2457 | r2458 | |
| 1809 | 1785 | COMBINE_DATA((UINT16 *) (lisa_ram_ptr + address)); |
| 1810 | 1786 | if (diag2) |
| 1811 | 1787 | { |
| 1812 | | if ((ACCESSING_BITS_0_7) |
| 1788 | if ((ACCESSING_LSB) |
| 1813 | 1789 | && ! (bad_parity_table[address >> 3] & (0x1 << (address & 0x7)))) |
| 1814 | 1790 | { |
| 1815 | 1791 | bad_parity_table[address >> 3] |= 0x1 << (address & 0x7); |
| 1816 | 1792 | bad_parity_count++; |
| 1817 | 1793 | } |
| 1818 | | if ((ACCESSING_BITS_8_15) |
| 1794 | if ((ACCESSING_MSB) |
| 1819 | 1795 | && ! (bad_parity_table[address >> 3] & (0x2 << (address & 0x7)))) |
| 1820 | 1796 | { |
| 1821 | 1797 | bad_parity_table[address >> 3] |= 0x2 << (address & 0x7); |
| r2457 | r2458 | |
| 1824 | 1800 | } |
| 1825 | 1801 | else if (bad_parity_table[address >> 3] & (0x3 << (address & 0x7))) |
| 1826 | 1802 | { |
| 1827 | | if ((ACCESSING_BITS_0_7) |
| 1803 | if ((ACCESSING_LSB) |
| 1828 | 1804 | && (bad_parity_table[address >> 3] & (0x1 << (address & 0x7)))) |
| 1829 | 1805 | { |
| 1830 | 1806 | bad_parity_table[address >> 3] &= ~ (0x1 << (address & 0x7)); |
| 1831 | 1807 | bad_parity_count--; |
| 1832 | 1808 | } |
| 1833 | | if ((ACCESSING_BITS_8_15) |
| 1809 | if ((ACCESSING_MSB) |
| 1834 | 1810 | && (bad_parity_table[address >> 3] & (0x2 << (address & 0x7)))) |
| 1835 | 1811 | { |
| 1836 | 1812 | bad_parity_table[address >> 3] &= ~ (0x2 << (address & 0x7)); |
| r2457 | r2458 | |
| 1909 | 1885 | seg &= ~2; |
| 1910 | 1886 | break; |
| 1911 | 1887 | case 0x0010: /* SETUP register SET */ |
| 1888 | logerror("setup SET PC=%x\n", safe_activecpu_get_pc()); |
| 1912 | 1889 | setup = 1; |
| 1913 | 1890 | break; |
| 1914 | 1891 | case 0x0012: /* SETUP register RESET */ |
| 1892 | logerror("setup UNSET PC=%x\n", safe_activecpu_get_pc()); |
| 1915 | 1893 | setup = 0; |
| 1916 | 1894 | break; |
| 1917 | 1895 | case 0x001A: /* Enable Vertical Retrace Interrupt */ |
| 1896 | logerror("enable retrace PC=%x\n", safe_activecpu_get_pc()); |
| 1918 | 1897 | VTMSK = 1; |
| 1919 | 1898 | break; |
| 1920 | 1899 | case 0x0018: /* Disable Vertical Retrace Interrupt */ |
| 1900 | logerror("disable retrace PC=%x\n", safe_activecpu_get_pc()); |
| 1921 | 1901 | VTMSK = 0; |
| 1922 | | set_VTIR(machine, 0); |
| 1902 | set_VTIR(machine, 2); |
| 1923 | 1903 | break; |
| 1924 | 1904 | case 0x0016: /* Enable Soft Error Detect. */ |
| 1925 | 1905 | case 0x0014: /* Disable Soft Error Detect. */ |
| r2457 | r2458 | |
| 1969 | 1949 | { |
| 1970 | 1950 | if (! (offset & 0x400)) |
| 1971 | 1951 | { |
| 1972 | | /*if (ACCESSING_BITS_0_7)*/ /* Geez, who cares ? */ |
| 1952 | /*if (ACCESSING_LSB)*/ /* Geez, who cares ? */ |
| 1973 | 1953 | answer = lisa_fdc_ram[offset & 0x03ff] & 0xff; /* right ??? */ |
| 1974 | 1954 | } |
| 1975 | 1955 | } |
| r2457 | r2458 | |
| 1986 | 1966 | |
| 1987 | 1967 | case 2: /* parallel port */ |
| 1988 | 1968 | /* 1 VIA located at 0xD901 */ |
| 1989 | | if (ACCESSING_BITS_0_7) |
| 1969 | if (ACCESSING_LSB) |
| 1990 | 1970 | return via_read(1, (offset >> 2) & 0xf); |
| 1991 | 1971 | break; |
| 1992 | 1972 | |
| 1993 | 1973 | case 3: /* keyboard/mouse cops via */ |
| 1994 | 1974 | /* 1 VIA located at 0xDD81 */ |
| 1995 | | if (ACCESSING_BITS_0_7) |
| 1975 | if (ACCESSING_LSB) |
| 1996 | 1976 | return via_read(0, offset & 0xf); |
| 1997 | 1977 | break; |
| 1998 | 1978 | } |
| r2457 | r2458 | |
| 2019 | 1999 | answer = 0; |
| 2020 | 2000 | if (! parity_error_pending) |
| 2021 | 2001 | answer |= 0x02; |
| 2022 | | if (! VTIR) |
| 2023 | | answer |= 0x04; |
| 2002 | if (VTIR<=1) |
| 2003 | // GFE : needs to be in phase with Serial NUM |
| 2004 | { |
| 2005 | int time_in_frame = video_screen_get_vpos(machine->primary_screen); |
| 2006 | if (lisa_features.has_mac_xl_video) |
| 2007 | { |
| 2008 | if ((time_in_frame >= 374) && (time_in_frame <= 392)) /* these values have not been tested */ |
| 2009 | { /* if VSyncing, read ROM 2nd half ? */ |
| 2010 | } |
| 2011 | else |
| 2012 | { |
| 2013 | VTIR=0; |
| 2014 | answer |= 0x04; |
| 2015 | } |
| 2016 | } |
| 2017 | else |
| 2018 | { |
| 2019 | logerror("read status time=%x\n", time_in_frame); |
| 2020 | if ((time_in_frame >= 364) && (time_in_frame <= 383)) /* these values are approximative */ |
| 2021 | { /* if VSyncing, read ROM 2nd half ? */ |
| 2022 | } |
| 2023 | else |
| 2024 | { |
| 2025 | VTIR=0; |
| 2026 | answer |= 0x04; |
| 2027 | } |
| 2028 | } |
| 2029 | |
| 2030 | } |
| 2031 | else |
| 2032 | answer |= 0x04; |
| 2024 | 2033 | /* huh... we need to emulate some other bits */ |
| 2034 | logerror("read status PC=%x val=%x\n", safe_activecpu_get_pc(),answer); |
| 2035 | |
| 2025 | 2036 | break; |
| 2026 | 2037 | } |
| 2027 | 2038 | break; |
| r2457 | r2458 | |
| 2064 | 2075 | /* Floppy Disk Controller shared RAM */ |
| 2065 | 2076 | if (! (offset & 0x0400)) |
| 2066 | 2077 | { |
| 2067 | | if (ACCESSING_BITS_0_7) |
| 2078 | if (ACCESSING_LSB) |
| 2068 | 2079 | lisa_fdc_ram[offset & 0x03ff] = data & 0xff; |
| 2069 | 2080 | } |
| 2070 | 2081 | } |
| r2457 | r2458 | |
| 2077 | 2088 | break; |
| 2078 | 2089 | |
| 2079 | 2090 | case 2: /* paralel port */ |
| 2080 | | if (ACCESSING_BITS_0_7) |
| 2091 | if (ACCESSING_LSB) |
| 2081 | 2092 | via_write(1, (offset >> 2) & 0xf, data & 0xff); |
| 2082 | 2093 | break; |
| 2083 | 2094 | |
| 2084 | 2095 | case 3: /* keyboard/mouse cops via */ |
| 2085 | | if (ACCESSING_BITS_0_7) |
| 2096 | if (ACCESSING_LSB) |
| 2086 | 2097 | via_write(0, offset & 0xf, data & 0xff); |
| 2087 | 2098 | break; |
| 2088 | 2099 | } |