Mercurial > repos > blastem
comparison io.c @ 1146:3e24de8d8073
Add support for SMS controllers
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Tue, 03 Jan 2017 21:18:52 -0800 |
parents | be3df2d8530a |
children | 6a4503fad67e |
comparison
equal
deleted
inserted
replaced
1145:494234e7e88f | 1146:3e24de8d8073 |
---|---|
23 | 23 |
24 #define CYCLE_NEVER 0xFFFFFFFF | 24 #define CYCLE_NEVER 0xFFFFFFFF |
25 #define MIN_POLL_INTERVAL 6840 | 25 #define MIN_POLL_INTERVAL 6840 |
26 | 26 |
27 const char * device_type_names[] = { | 27 const char * device_type_names[] = { |
28 "SMS gamepad", | |
28 "3-button gamepad", | 29 "3-button gamepad", |
29 "6-button gamepad", | 30 "6-button gamepad", |
30 "Mega Mouse", | 31 "Mega Mouse", |
31 "Saturn Keyboard", | 32 "Saturn Keyboard", |
32 "Menacer", | 33 "Menacer", |
651 const int gamepad_len = strlen("gamepad"); | 652 const int gamepad_len = strlen("gamepad"); |
652 const int mouse_len = strlen("mouse"); | 653 const int mouse_len = strlen("mouse"); |
653 if (!strncmp(device_type, "gamepad", gamepad_len)) | 654 if (!strncmp(device_type, "gamepad", gamepad_len)) |
654 { | 655 { |
655 if ( | 656 if ( |
656 (device_type[gamepad_len] != '3' && device_type[gamepad_len] != '6') | 657 (device_type[gamepad_len] != '3' && device_type[gamepad_len] != '6' && device_type[gamepad_len] != '2') |
657 || device_type[gamepad_len+1] != '.' || device_type[gamepad_len+2] < '1' | 658 || device_type[gamepad_len+1] != '.' || device_type[gamepad_len+2] < '1' |
658 || device_type[gamepad_len+2] > '8' || device_type[gamepad_len+3] != 0 | 659 || device_type[gamepad_len+2] > '8' || device_type[gamepad_len+3] != 0 |
659 ) | 660 ) { |
660 { | |
661 warning("%s is not a valid gamepad type\n", device_type); | 661 warning("%s is not a valid gamepad type\n", device_type); |
662 } else if (device_type[gamepad_len] == '3') | 662 } else if (device_type[gamepad_len] == '3') { |
663 { | |
664 port->device_type = IO_GAMEPAD3; | 663 port->device_type = IO_GAMEPAD3; |
664 } else if (device_type[gamepad_len] == '2') { | |
665 port->device_type = IO_GAMEPAD2; | |
665 } else { | 666 } else { |
666 port->device_type = IO_GAMEPAD6; | 667 port->device_type = IO_GAMEPAD6; |
667 } | 668 } |
668 port->device.pad.gamepad_num = device_type[gamepad_len+2] - '1'; | 669 port->device.pad.gamepad_num = device_type[gamepad_len+2] - '1'; |
669 } else if(!strncmp(device_type, "mouse", mouse_len)) { | 670 } else if(!strncmp(device_type, "mouse", mouse_len)) { |
801 close(ports[i].device.stream.listen_fd); | 802 close(ports[i].device.stream.listen_fd); |
802 ports[i].device_type = IO_NONE; | 803 ports[i].device_type = IO_NONE; |
803 } | 804 } |
804 } else | 805 } else |
805 #endif | 806 #endif |
806 if (ports[i].device_type == IO_GAMEPAD3 || ports[i].device_type == IO_GAMEPAD6) { | 807 if (ports[i].device_type == IO_GAMEPAD3 || ports[i].device_type == IO_GAMEPAD6 || ports[i].device_type == IO_GAMEPAD2) { |
807 printf("IO port %s connected to gamepad #%d with type '%s'\n", io_name(i), ports[i].device.pad.gamepad_num + 1, device_type_names[ports[i].device_type]); | 808 printf("IO port %s connected to gamepad #%d with type '%s'\n", io_name(i), ports[i].device.pad.gamepad_num + 1, device_type_names[ports[i].device_type]); |
808 } else { | 809 } else { |
809 printf("IO port %s connected to device '%s'\n", io_name(i), device_type_names[ports[i].device_type]); | 810 printf("IO port %s connected to device '%s'\n", io_name(i), device_type_names[ports[i].device_type]); |
810 } | 811 } |
811 } | 812 } |
819 { | 820 { |
820 int num = bindings[i].bind_type - BIND_GAMEPAD1; | 821 int num = bindings[i].bind_type - BIND_GAMEPAD1; |
821 for (int j = 0; j < 3; j++) | 822 for (int j = 0; j < 3; j++) |
822 { | 823 { |
823 if ((ports[j].device_type == IO_GAMEPAD3 | 824 if ((ports[j].device_type == IO_GAMEPAD3 |
824 || ports[j].device_type ==IO_GAMEPAD6) | 825 || ports[j].device_type == IO_GAMEPAD6 |
826 || ports[j].device_type == IO_GAMEPAD2) | |
825 && ports[j].device.pad.gamepad_num == num | 827 && ports[j].device.pad.gamepad_num == num |
826 ) | 828 ) |
827 { | 829 { |
828 memset(ports[j].input, 0, sizeof(ports[j].input)); | 830 memset(ports[j].input, 0, sizeof(ports[j].input)); |
829 bindings[i].port = ports + j; | 831 bindings[i].port = ports + j; |
1362 process_events(); | 1364 process_events(); |
1363 last_poll_cycle = current_cycle; | 1365 last_poll_cycle = current_cycle; |
1364 } | 1366 } |
1365 switch (port->device_type) | 1367 switch (port->device_type) |
1366 { | 1368 { |
1369 case IO_GAMEPAD2: | |
1370 input = ~port->input[GAMEPAD_TH1]; | |
1371 break; | |
1367 case IO_GAMEPAD3: | 1372 case IO_GAMEPAD3: |
1368 { | 1373 { |
1369 input = port->input[th ? GAMEPAD_TH1 : GAMEPAD_TH0]; | 1374 input = port->input[th ? GAMEPAD_TH1 : GAMEPAD_TH0]; |
1370 if (!th) { | 1375 if (!th) { |
1371 input |= 0xC; | 1376 input |= 0xC; |