Mercurial > repos > blastem
comparison io.c @ 747:85c98a222fea
Merge
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Thu, 28 May 2015 23:05:32 -0700 |
parents | daa31ee7d8cd |
children | 1b2f8280ba81 |
comparison
equal
deleted
inserted
replaced
740:25c9e9d39997 | 747:85c98a222fea |
---|---|
1 /* | 1 /* |
2 Copyright 2013 Michael Pavone | 2 Copyright 2013 Michael Pavone |
3 This file is part of BlastEm. | 3 This file is part of BlastEm. |
4 BlastEm is free software distributed under the terms of the GNU General Public License version 3 or greater. See COPYING for full license text. | 4 BlastEm is free software distributed under the terms of the GNU General Public License version 3 or greater. See COPYING for full license text. |
5 */ | 5 */ |
6 #ifndef _WIN32 | |
6 #include <unistd.h> | 7 #include <unistd.h> |
7 #include <fcntl.h> | 8 #include <fcntl.h> |
8 #include <sys/socket.h> | 9 #include <sys/socket.h> |
9 #include <sys/un.h> | 10 #include <sys/un.h> |
10 #include <sys/types.h> | 11 #include <sys/types.h> |
11 #include <sys/stat.h> | 12 #include <sys/stat.h> |
12 #include <errno.h> | 13 #include <errno.h> |
14 #endif | |
13 #include <string.h> | 15 #include <string.h> |
16 #include <stdlib.h> | |
14 | 17 |
15 #include "io.h" | 18 #include "io.h" |
16 #include "blastem.h" | 19 #include "blastem.h" |
17 #include "render.h" | 20 #include "render.h" |
18 | 21 |
542 process_device(io_2, ports+1); | 545 process_device(io_2, ports+1); |
543 process_device(io_ext, ports+2); | 546 process_device(io_ext, ports+2); |
544 | 547 |
545 for (int i = 0; i < 3; i++) | 548 for (int i = 0; i < 3; i++) |
546 { | 549 { |
547 | 550 #ifndef _WIN32 |
548 if (ports[i].device_type == IO_SEGA_PARALLEL) | 551 if (ports[i].device_type == IO_SEGA_PARALLEL) |
549 { | 552 { |
550 char *pipe_name = tern_find_ptr(config, "ioparallel_pipe"); | 553 char *pipe_name = tern_find_ptr(config, "ioparallel_pipe"); |
551 if (!pipe_name) | 554 if (!pipe_name) |
552 { | 555 { |
604 unlink(sock_name); | 607 unlink(sock_name); |
605 cleanup_sock: | 608 cleanup_sock: |
606 close(ports[i].device.stream.listen_fd); | 609 close(ports[i].device.stream.listen_fd); |
607 ports[i].device_type = IO_NONE; | 610 ports[i].device_type = IO_NONE; |
608 } | 611 } |
609 } else if (ports[i].device_type == IO_GAMEPAD3 || ports[i].device_type == IO_GAMEPAD6) { | 612 } else |
613 #endif | |
614 if (ports[i].device_type == IO_GAMEPAD3 || ports[i].device_type == IO_GAMEPAD6) { | |
610 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]); | 615 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]); |
611 } else { | 616 } else { |
612 printf("IO port %s connected to device '%s'\n", io_name(i), device_type_names[ports[i].device_type]); | 617 printf("IO port %s connected to device '%s'\n", io_name(i), device_type_names[ports[i].device_type]); |
613 } | 618 } |
614 } | 619 } |
768 port->device.pad.timeout_cycle -= deduction; | 773 port->device.pad.timeout_cycle -= deduction; |
769 } | 774 } |
770 } | 775 } |
771 } | 776 } |
772 | 777 |
778 #ifndef _WIN32 | |
773 static void wait_for_connection(io_port * port) | 779 static void wait_for_connection(io_port * port) |
774 { | 780 { |
775 if (port->device.stream.data_fd == -1) | 781 if (port->device.stream.data_fd == -1) |
776 { | 782 { |
777 puts("Waiting for socket connection..."); | 783 puts("Waiting for socket connection..."); |
867 } | 873 } |
868 } | 874 } |
869 } | 875 } |
870 } | 876 } |
871 } | 877 } |
878 #endif | |
872 | 879 |
873 void io_data_write(io_port * port, uint8_t value, uint32_t current_cycle) | 880 void io_data_write(io_port * port, uint8_t value, uint32_t current_cycle) |
874 { | 881 { |
875 switch (port->device_type) | 882 switch (port->device_type) |
876 { | 883 { |
887 port->device.pad.timeout_cycle = current_cycle + TH_TIMEOUT; | 894 port->device.pad.timeout_cycle = current_cycle + TH_TIMEOUT; |
888 } | 895 } |
889 } | 896 } |
890 port->output = value; | 897 port->output = value; |
891 break; | 898 break; |
899 #ifndef _WIN32 | |
892 case IO_GENERIC: | 900 case IO_GENERIC: |
893 wait_for_connection(port); | 901 wait_for_connection(port); |
894 port->input[IO_STATE] = IO_WRITE_PENDING; | 902 port->input[IO_STATE] = IO_WRITE_PENDING; |
895 port->output = value; | 903 port->output = value; |
896 service_socket(port); | 904 service_socket(port); |
897 break; | 905 break; |
906 #endif | |
898 default: | 907 default: |
899 port->output = value; | 908 port->output = value; |
900 } | 909 } |
901 | 910 |
902 } | 911 } |
936 input = port->input[GAMEPAD_TH0] | 0xC; | 945 input = port->input[GAMEPAD_TH0] | 0xC; |
937 } | 946 } |
938 } | 947 } |
939 break; | 948 break; |
940 } | 949 } |
950 #ifndef _WIN32 | |
941 case IO_SEGA_PARALLEL: | 951 case IO_SEGA_PARALLEL: |
942 if (!th) | 952 if (!th) |
943 { | 953 { |
944 service_pipe(port); | 954 service_pipe(port); |
945 } | 955 } |
952 port->input[IO_STATE] = IO_READ_PENDING; | 962 port->input[IO_STATE] = IO_READ_PENDING; |
953 } | 963 } |
954 service_socket(port); | 964 service_socket(port); |
955 input = ~port->input[IO_TH0]; | 965 input = ~port->input[IO_TH0]; |
956 break; | 966 break; |
967 #endif | |
957 default: | 968 default: |
958 input = 0; | 969 input = 0; |
959 break; | 970 break; |
960 } | 971 } |
961 uint8_t value = ((~input) & (~control)) | (port->output & control); | 972 uint8_t value = ((~input) & (~control)) | (port->output & control); |