src/mess/machine/mac.c
| r3696 | r3697 | |
| 1253 | 1253 | |
| 1254 | 1254 | // ADB mouse state |
| 1255 | 1255 | static int adb_mouseaddr = 3; |
| 1256 | | static int adb_lastmousex, adb_lastmousey; |
| 1256 | static int adb_lastmousex, adb_lastmousey, adb_mouse_wanted_srq, adb_mouse_initialized; |
| 1257 | 1257 | |
| 1258 | // ADB keyboard state |
| 1259 | static int adb_keybaddr = 2; |
| 1260 | static int adb_keybinitialized, adb_keyb_wanted_srq; |
| 1261 | |
| 1258 | 1262 | #if LOG_ADB |
| 1259 | 1263 | static const char *adb_statenames[4] = { "NEW", "EVEN", "ODD", "IDLE" }; |
| 1260 | 1264 | #endif |
| 1261 | 1265 | |
| 1266 | static void mac_adb_pollmouse(running_machine *machine) |
| 1267 | { |
| 1268 | int NewX, NewY; |
| 1269 | |
| 1270 | NewX = input_port_read(machine, "MOUSE2"); |
| 1271 | NewY = input_port_read(machine, "MOUSE1"); |
| 1272 | |
| 1273 | if ((NewX != adb_lastmousex) || (NewY != adb_lastmousey)) |
| 1274 | { |
| 1275 | adb_mouse_wanted_srq = 1; |
| 1276 | } |
| 1277 | } |
| 1278 | |
| 1262 | 1279 | static void mac_adb_accummouse( running_machine *machine, UINT8 *MouseX, UINT8 *MouseY ) |
| 1263 | 1280 | { |
| 1264 | 1281 | int MouseCountX = 0, MouseCountY = 0; |
| r3696 | r3697 | |
| 1297 | 1314 | adb_lastmousey = NewY; |
| 1298 | 1315 | } |
| 1299 | 1316 | |
| 1317 | adb_mouse_wanted_srq = 0; |
| 1318 | |
| 1300 | 1319 | *MouseX = (UINT8)MouseCountX; |
| 1301 | 1320 | *MouseY = (UINT8)MouseCountY; |
| 1302 | 1321 | } |
| r3696 | r3697 | |
| 1366 | 1385 | adb_buffer[0] = 0x60 | ((adb_mouseaddr<<8)&0xf); // SRQ enable, no exceptional event |
| 1367 | 1386 | adb_buffer[1] = 0x01; // handler 1 |
| 1368 | 1387 | adb_datasize = 2; |
| 1388 | |
| 1389 | adb_mouse_initialized = 1; |
| 1369 | 1390 | break; |
| 1370 | 1391 | |
| 1371 | 1392 | default: |
| 1372 | 1393 | break; |
| 1373 | 1394 | } |
| 1374 | 1395 | } |
| 1396 | else if (addr == adb_keybaddr) |
| 1397 | { |
| 1398 | // printf("Talking to keyboard, register %x\n", reg); |
| 1399 | |
| 1400 | switch (reg) |
| 1401 | { |
| 1402 | // read keyboard |
| 1403 | case 0: |
| 1404 | adb_buffer[0] = adb_buffer[1] = 0x80; // nothing pressed |
| 1405 | adb_datasize = 2; |
| 1406 | break; |
| 1407 | |
| 1408 | // read modifier keys |
| 1409 | case 2: |
| 1410 | adb_buffer[0] = 0xff; // nothing pressed |
| 1411 | adb_buffer[1] = 0; |
| 1412 | adb_datasize = 2; |
| 1413 | break; |
| 1414 | |
| 1415 | // get ID/handler |
| 1416 | case 3: |
| 1417 | adb_buffer[0] = 0x60 | ((adb_keybaddr<<8)&0xf); // SRQ enable, no exceptional event |
| 1418 | adb_buffer[1] = 0x01; // handler 1 |
| 1419 | adb_datasize = 2; |
| 1420 | |
| 1421 | adb_keybinitialized = 1; |
| 1422 | break; |
| 1423 | |
| 1424 | default: |
| 1425 | break; |
| 1426 | } |
| 1427 | } |
| 1428 | |
| 1429 | // if the mouse has new data and it's not what we're polling, yank SRQ |
| 1430 | if ((addr != adb_mouseaddr) && (adb_mouse_initialized)) |
| 1431 | { |
| 1432 | mac_adb_pollmouse(machine); |
| 1433 | } |
| 1375 | 1434 | break; |
| 1376 | 1435 | } |
| 1377 | 1436 | |
| r3696 | r3697 | |
| 1480 | 1539 | } |
| 1481 | 1540 | } |
| 1482 | 1541 | |
| 1542 | static void adb_vblank(running_machine *machine) |
| 1543 | { |
| 1544 | // if any device has a service request, show it on the VIA |
| 1545 | // (no need to actually generate an IRQ, the Mac will see it) |
| 1546 | if ((adb_mouse_wanted_srq) || (adb_keyb_wanted_srq)) |
| 1547 | { |
| 1548 | adb_irq_pending = 1; |
| 1549 | } |
| 1550 | else |
| 1551 | { |
| 1552 | adb_irq_pending = 0; |
| 1553 | } |
| 1554 | } |
| 1555 | |
| 1483 | 1556 | static void adb_reset(void) |
| 1484 | 1557 | { |
| 1485 | 1558 | adb_irq_pending = 0; // no interrupt |
| r3696 | r3697 | |
| 1495 | 1568 | // mouse |
| 1496 | 1569 | adb_mouseaddr = 3; |
| 1497 | 1570 | adb_lastmousex = adb_lastmousey = 0; |
| 1571 | adb_mouse_wanted_srq = 0; |
| 1572 | adb_mouse_initialized = 0; |
| 1573 | |
| 1574 | // keyboard |
| 1575 | adb_keybaddr = 2; |
| 1576 | adb_keyb_wanted_srq = 0; |
| 1577 | adb_keybinitialized = 0; |
| 1498 | 1578 | } |
| 1499 | 1579 | |
| 1500 | 1580 | /* ************************************************************************* |
| r3696 | r3697 | |
| 1826 | 1906 | { |
| 1827 | 1907 | static int irq_count = 0, ca1_data = 0, ca2_data = 0; |
| 1828 | 1908 | |
| 1909 | /* handle ADB keyboard/mouse */ |
| 1910 | if (has_adb()) |
| 1911 | { |
| 1912 | adb_vblank(machine); |
| 1913 | } |
| 1914 | |
| 1829 | 1915 | /* handle keyboard */ |
| 1830 | 1916 | if (kbd_comm == TRUE) |
| 1831 | 1917 | { |