Mercurial > repos > blastem
comparison io.c @ 1028:56b1748a8473
Initial stab at Saturn keyboard support
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Wed, 11 May 2016 01:15:54 -0700 |
parents | 7267bc1ab547 |
children | 284d905ca582 |
comparison
equal
deleted
inserted
replaced
1027:276cd582b728 | 1028:56b1748a8473 |
---|---|
256 } | 256 } |
257 } | 257 } |
258 | 258 |
259 void store_key_event(uint16_t code) | 259 void store_key_event(uint16_t code) |
260 { | 260 { |
261 if (keyboard_port) { | 261 if (keyboard_port && keyboard_port->device.keyboard.write_pos != keyboard_port->device.keyboard.read_pos) { |
262 //there's room in the buffer, record this event | |
263 keyboard_port->device.keyboard.events[keyboard_port->device.keyboard.write_pos] = code; | |
264 if (keyboard_port->device.keyboard.read_pos == 0xFF) { | |
265 //ring buffer was empty, update read_pos to indicate there is now data | |
266 keyboard_port->device.keyboard.read_pos = keyboard_port->device.keyboard.write_pos; | |
267 } | |
262 keyboard_port->device.keyboard.write_pos = (keyboard_port->device.keyboard.write_pos + 1) & 7; | 268 keyboard_port->device.keyboard.write_pos = (keyboard_port->device.keyboard.write_pos + 1) & 7; |
263 if (keyboard_port->device.keyboard.write_pos == keyboard_port->device.keyboard.read_pos) { | 269 } |
264 //we've wrapped around to the read position, drop this event | 270 } |
265 keyboard_port->device.keyboard.write_pos = (keyboard_port->device.keyboard.write_pos - 1) & 7; | 271 |
266 return; | 272 void handle_keydown(int keycode, uint8_t scancode) |
267 } | |
268 keyboard_port->device.keyboard.events[keyboard_port->device.keyboard.write_pos] = code; | |
269 } | |
270 } | |
271 | |
272 void handle_keydown(int keycode, char scancode) | |
273 { | 273 { |
274 int bucket = keycode >> 15 & 0xFFFF; | 274 int bucket = keycode >> 15 & 0xFFFF; |
275 if (!bindings[bucket]) { | 275 if (!bindings[bucket]) { |
276 return; | 276 return; |
277 } | 277 } |
402 } | 402 } |
403 break; | 403 break; |
404 } | 404 } |
405 } | 405 } |
406 | 406 |
407 void handle_keyup(int keycode, char scancode) | 407 void handle_keyup(int keycode, uint8_t scancode) |
408 { | 408 { |
409 int bucket = keycode >> 15 & 0xFFFF; | 409 int bucket = keycode >> 15 & 0xFFFF; |
410 if (!bindings[bucket]) { | 410 if (!bindings[bucket]) { |
411 return; | 411 return; |
412 } | 412 } |
679 port->device.mouse.cur_y = 0; | 679 port->device.mouse.cur_y = 0; |
680 port->device.mouse.latched_x = 0; | 680 port->device.mouse.latched_x = 0; |
681 port->device.mouse.latched_y = 0; | 681 port->device.mouse.latched_y = 0; |
682 port->device.mouse.ready_cycle = CYCLE_NEVER; | 682 port->device.mouse.ready_cycle = CYCLE_NEVER; |
683 port->device.mouse.tr_counter = 0; | 683 port->device.mouse.tr_counter = 0; |
684 } else if(!strcmp(device_type, "saturn keyboard")) { | |
685 port->device_type = IO_SATURN_KEYBOARD; | |
686 port->device.keyboard.read_pos = 0xFF; | |
687 port->device.keyboard.write_pos = 0; | |
684 } else if(!strcmp(device_type, "sega_parallel")) { | 688 } else if(!strcmp(device_type, "sega_parallel")) { |
685 port->device_type = IO_SEGA_PARALLEL; | 689 port->device_type = IO_SEGA_PARALLEL; |
686 port->device.stream.data_fd = -1; | 690 port->device.stream.data_fd = -1; |
687 port->device.stream.listen_fd = -1; | 691 port->device.stream.listen_fd = -1; |
688 } else if(!strcmp(device_type, "generic")) { | 692 } else if(!strcmp(device_type, "generic")) { |
1279 int delay_index = port->device.mouse.tr_counter >= sizeof(mouse_delays) ? sizeof(mouse_delays)-1 : port->device.mouse.tr_counter; | 1283 int delay_index = port->device.mouse.tr_counter >= sizeof(mouse_delays) ? sizeof(mouse_delays)-1 : port->device.mouse.tr_counter; |
1280 port->device.mouse.ready_cycle = current_cycle + mouse_delays[delay_index]; | 1284 port->device.mouse.ready_cycle = current_cycle + mouse_delays[delay_index]; |
1281 } | 1285 } |
1282 } | 1286 } |
1283 break; | 1287 break; |
1288 case IO_SATURN_KEYBOARD: | |
1289 if (output & TH) { | |
1290 //request is over | |
1291 if (port->device.keyboard.tr_counter >= 10 && port->device.keyboard.read_pos != 0xFF) { | |
1292 //remove scan code from buffer | |
1293 port->device.keyboard.read_pos++; | |
1294 port->device.keyboard.read_pos &= 7; | |
1295 if (port->device.keyboard.read_pos == port->device.keyboard.write_pos) { | |
1296 port->device.keyboard.read_pos = 0xFF; | |
1297 } | |
1298 } | |
1299 port->device.keyboard.tr_counter = 0; | |
1300 } else { | |
1301 if ((output & TR) != (old_output & TR)) { | |
1302 port->device.keyboard.tr_counter++; | |
1303 } | |
1304 } | |
1305 break; | |
1284 #ifndef _WIN32 | 1306 #ifndef _WIN32 |
1285 case IO_GENERIC: | 1307 case IO_GENERIC: |
1286 wait_for_connection(port); | 1308 wait_for_connection(port); |
1287 port->input[IO_STATE] = IO_WRITE_PENDING; | 1309 port->input[IO_STATE] = IO_WRITE_PENDING; |
1288 service_socket(port); | 1310 service_socket(port); |
1395 } | 1417 } |
1396 input |= ((port->device.mouse.tr_counter & 1) == 0) << 4; | 1418 input |= ((port->device.mouse.tr_counter & 1) == 0) << 4; |
1397 } | 1419 } |
1398 break; | 1420 break; |
1399 } | 1421 } |
1422 case IO_SATURN_KEYBOARD: | |
1423 { | |
1424 if (th) { | |
1425 input = 0x11; | |
1426 } else { | |
1427 uint8_t tr = output & TR; | |
1428 uint16_t code = port->device.keyboard.read_pos == 0xFF ? 0 | |
1429 : port->device.keyboard.events[port->device.keyboard.read_pos]; | |
1430 switch (port->device.keyboard.tr_counter) | |
1431 { | |
1432 case 0: | |
1433 input = 1; | |
1434 break; | |
1435 case 1: | |
1436 //Saturn peripheral ID | |
1437 input = 3; | |
1438 break; | |
1439 case 2: | |
1440 //data size | |
1441 input = 4; | |
1442 break; | |
1443 case 3: | |
1444 //d-pad | |
1445 //TODO: set these based on keyboard state | |
1446 input = 0xF; | |
1447 break; | |
1448 case 4: | |
1449 //Start ABC | |
1450 //TODO: set these based on keyboard state | |
1451 input = 0xF; | |
1452 break; | |
1453 case 5: | |
1454 //R XYZ | |
1455 //TODO: set these based on keyboard state | |
1456 input = 0xF; | |
1457 break; | |
1458 case 6: | |
1459 //L and KBID | |
1460 //TODO: set L based on keyboard state | |
1461 input = 0x8; | |
1462 break; | |
1463 case 7: | |
1464 //Capslock, Numlock, Scrolllock | |
1465 //TODO: set these based on keyboard state | |
1466 input = 0; | |
1467 break; | |
1468 case 8: | |
1469 input = 6; | |
1470 if (code & 0x100) { | |
1471 //break | |
1472 input |= 1; | |
1473 } else if (code) { | |
1474 input |= 8; | |
1475 } | |
1476 break; | |
1477 case 9: | |
1478 input = code >> 4 & 0xF; | |
1479 break; | |
1480 case 10: | |
1481 input = code & 0xF; | |
1482 break; | |
1483 case 11: | |
1484 input = 0; | |
1485 break; | |
1486 default: | |
1487 input = 1; | |
1488 break; | |
1489 } | |
1490 input |= ((port->device.keyboard.tr_counter & 1) == 0) << 4; | |
1491 } | |
1492 break; | |
1493 } | |
1400 #ifndef _WIN32 | 1494 #ifndef _WIN32 |
1401 case IO_SEGA_PARALLEL: | 1495 case IO_SEGA_PARALLEL: |
1402 if (!th) | 1496 if (!th) |
1403 { | 1497 { |
1404 service_pipe(port); | 1498 service_pipe(port); |