src/mess/machine/mac.c
| r6210 | r6211 | |
| 1365 | 1365 | |
| 1366 | 1366 | // ADB mouse state |
| 1367 | 1367 | static int adb_mouseaddr = 3; |
| 1368 | | static int adb_lastmousex, adb_lastmousey, adb_mouse_wanted_srq, adb_mouse_initialized; |
| 1368 | static int adb_lastmousex, adb_lastmousey, adb_lastbutton, adb_mouse_wanted_srq, adb_mouse_initialized; |
| 1369 | 1369 | |
| 1370 | 1370 | // ADB keyboard state |
| 1371 | 1371 | static int adb_keybaddr = 2; |
| r6210 | r6211 | |
| 1377 | 1377 | |
| 1378 | 1378 | static void mac_adb_pollmouse(running_machine *machine) |
| 1379 | 1379 | { |
| 1380 | | int NewX, NewY; |
| 1380 | int NewX, NewY, NewButton; |
| 1381 | 1381 | |
| 1382 | NewButton = input_port_read(machine, "MOUSE0") & 0x01; |
| 1382 | 1383 | NewX = input_port_read(machine, "MOUSE2"); |
| 1383 | 1384 | NewY = input_port_read(machine, "MOUSE1"); |
| 1384 | 1385 | |
| 1385 | | if ((NewX != adb_lastmousex) || (NewY != adb_lastmousey)) |
| 1386 | if ((NewX != adb_lastmousex) || (NewY != adb_lastmousey) || (NewButton != adb_lastbutton)) |
| 1386 | 1387 | { |
| 1387 | 1388 | adb_mouse_wanted_srq = 1; |
| 1388 | 1389 | } |
| r6210 | r6211 | |
| 1426 | 1427 | adb_lastmousey = NewY; |
| 1427 | 1428 | } |
| 1428 | 1429 | |
| 1430 | adb_lastbutton = input_port_read(machine, "MOUSE0") & 0x01; |
| 1431 | |
| 1429 | 1432 | adb_mouse_wanted_srq = 0; |
| 1430 | 1433 | |
| 1431 | 1434 | *MouseX = (UINT8)MouseCountX; |
| r6210 | r6211 | |
| 1439 | 1442 | addr = (adb_command>>4); |
| 1440 | 1443 | reg = (adb_command & 3); |
| 1441 | 1444 | |
| 1442 | | // printf("Mac sent %x\n", adb_command); |
| 1445 | // printf("Mac sent %x (cmd %d addr %d reg %d mr %d kr %d)\n", adb_command, (adb_command>>2)&3, addr, reg, adb_mouseaddr, adb_keybaddr); |
| 1443 | 1446 | |
| 1444 | 1447 | if (adb_waiting_cmd) |
| 1445 | 1448 | { |
| 1449 | const device_config *via_0 = devtag_get_device(machine, "via6522_0"); |
| 1450 | |
| 1446 | 1451 | switch ((adb_command>>2)&3) |
| 1447 | 1452 | { |
| 1448 | 1453 | case 0: |
| r6210 | r6211 | |
| 1457 | 1462 | case ADB_CMD_FLUSH: |
| 1458 | 1463 | adb_direction = 0; |
| 1459 | 1464 | adb_send = 0; |
| 1465 | |
| 1466 | adb_buffer[0] = 0xff; |
| 1467 | adb_datasize = 1; |
| 1468 | |
| 1469 | // it's not documented how to respond, but yanking SRQ seems to work |
| 1470 | adb_extclock ^= 1; |
| 1471 | via_cb1_w(via_0, 0, adb_extclock); |
| 1472 | adb_extclock ^= 1; |
| 1473 | via_cb1_w(via_0, 0, adb_extclock); |
| 1460 | 1474 | break; |
| 1461 | 1475 | |
| 1462 | 1476 | default: // reserved/unused |
| r6210 | r6211 | |
| 1537 | 1551 | break; |
| 1538 | 1552 | } |
| 1539 | 1553 | } |
| 1554 | else |
| 1555 | { |
| 1556 | // printf("talking to unconnected device\n"); |
| 1557 | adb_buffer[0] = adb_buffer[1] = 0xff; |
| 1558 | adb_datasize = 0; |
| 1559 | } |
| 1540 | 1560 | |
| 1541 | 1561 | // if the mouse has new data and it's not what we're polling, yank SRQ |
| 1542 | 1562 | if ((addr != adb_mouseaddr) && (adb_mouse_initialized)) |
| r6210 | r6211 | |
| 1587 | 1607 | ret = (adb_send & 0x80)>>7; |
| 1588 | 1608 | adb_send <<= 1; |
| 1589 | 1609 | |
| 1590 | | // printf("IN CB2 = %x\n", ret); |
| 1610 | // printf("IN CB2 = %x\n", ret); |
| 1591 | 1611 | |
| 1592 | 1612 | return ret; |
| 1593 | 1613 | } |
| r6210 | r6211 | |
| 1616 | 1636 | adb_command = adb_send = 0; |
| 1617 | 1637 | adb_direction = 1; // Mac is shifting us a command |
| 1618 | 1638 | adb_waiting_cmd = 1; // we're going to get a command |
| 1639 | timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0); |
| 1619 | 1640 | break; |
| 1620 | 1641 | |
| 1621 | 1642 | case ADB_STATE_XFER_EVEN: |
| r6210 | r6211 | |
| 1640 | 1661 | } |
| 1641 | 1662 | else |
| 1642 | 1663 | { |
| 1643 | | adb_send = 0; |
| 1664 | adb_send = 0xff; // try pulling up? |
| 1644 | 1665 | } |
| 1666 | timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0); |
| 1645 | 1667 | break; |
| 1646 | 1668 | |
| 1647 | 1669 | case ADB_STATE_IDLE: |
| 1670 | adb_send = 0xff; |
| 1648 | 1671 | break; |
| 1649 | 1672 | } |
| 1650 | 1673 | |
| 1651 | 1674 | // no matter what, generate 8 clocks (should this happen on IDLE?) |
| 1652 | | timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0); |
| 1675 | // timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0); |
| 1653 | 1676 | } |
| 1654 | 1677 | } |
| 1655 | 1678 | |
| r6210 | r6211 | |
| 1659 | 1682 | // (no need to actually generate an IRQ, the Mac will see it) |
| 1660 | 1683 | if ((adb_mouse_wanted_srq) || (adb_keyb_wanted_srq)) |
| 1661 | 1684 | { |
| 1685 | // printf("ADB IRQ: kb %d ms %d\n", adb_keyb_wanted_srq, adb_mouse_wanted_srq); |
| 1662 | 1686 | adb_irq_pending = 1; |
| 1663 | 1687 | } |
| 1664 | 1688 | else |
| 1665 | 1689 | { |
| 1666 | 1690 | adb_irq_pending = 0; |
| 1691 | mac_adb_pollmouse(machine); |
| 1692 | |
| 1693 | if ((adb_state == ADB_STATE_IDLE) && (adb_mouse_wanted_srq)) |
| 1694 | { |
| 1695 | adb_timer_ticks = 8; |
| 1696 | timer_adjust_oneshot(mac_adb_timer, attotime_make(0, ATTOSECONDS_IN_USEC(100)), 0); |
| 1697 | adb_mouse_wanted_srq = 0; |
| 1698 | } |
| 1667 | 1699 | } |
| 1668 | 1700 | } |
| 1669 | 1701 | |
| r6210 | r6211 | |
| 1681 | 1713 | |
| 1682 | 1714 | // mouse |
| 1683 | 1715 | adb_mouseaddr = 3; |
| 1684 | | adb_lastmousex = adb_lastmousey = 0; |
| 1716 | adb_lastmousex = adb_lastmousey = adb_lastbutton = 0; |
| 1685 | 1717 | adb_mouse_wanted_srq = 0; |
| 1686 | 1718 | adb_mouse_initialized = 0; |
| 1687 | 1719 | |