diff options
Diffstat (limited to 'plugins/bladesio1')
| -rw-r--r-- | plugins/bladesio1/connection.c | 16 | ||||
| -rw-r--r-- | plugins/bladesio1/sio1.c | 23 |
2 files changed, 26 insertions, 13 deletions
diff --git a/plugins/bladesio1/connection.c b/plugins/bladesio1/connection.c index c922f2f2..bf083e92 100644 --- a/plugins/bladesio1/connection.c +++ b/plugins/bladesio1/connection.c @@ -25,6 +25,7 @@ #if defined _WINDOWS #include <winsock2.h> #else +#include <fcntl.h> #include <sys/socket.h> #include <netinet/in.h> #include <netinet/tcp.h> @@ -68,14 +69,14 @@ int connectionOpen() { #endif return -1; } - + setsockopt(serversock, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuse_addr, sizeof(reuse_addr)); setsockopt(serversock, IPPROTO_TCP, TCP_NODELAY, (const char*)&one, sizeof(one)); memset(&address, 0, sizeof(address)); address.sin_family = AF_INET; address.sin_addr.s_addr = INADDR_ANY; - address.sin_port = settings.port; + address.sin_port = htons(settings.port); if(bind(serversock,(struct sockaddr*)&address,sizeof(address)) == -1) { #if defined _WINDOWS @@ -167,9 +168,16 @@ int connectionSend(u8 *pdata, s32 size) { int connectionRecv(u8 *pdata, s32 size) { int bytes = 0; - if(clientsock >= 0) - if((bytes = (int)recv(clientsock, (char*)pdata, size, 0)) < 0) + if(clientsock >= 0) { + int flags = fcntl(clientsock, F_GETFL, 0); + + fcntl(clientsock, F_SETFL, flags | O_NONBLOCK); + if((bytes = (int)recv(clientsock, (char*)pdata, size, 0)) < 0) { + fcntl(clientsock, F_SETFL, flags); return 0; + } + fcntl(clientsock, F_SETFL, flags); + } return bytes; } diff --git a/plugins/bladesio1/sio1.c b/plugins/bladesio1/sio1.c index feab1bb6..6c16e964 100644 --- a/plugins/bladesio1/sio1.c +++ b/plugins/bladesio1/sio1.c @@ -55,8 +55,6 @@ static const unsigned char build = 1; static void (CALLBACK *irqCallback)() = 0; -Settings settings; - /* sio status flags. */ enum { @@ -210,6 +208,8 @@ void Exchange(s32 data) { exc_data_send.len = 1; exc_data_send.data = data; + connectionSend((u8*)&exc_data_send.data, exc_data_send.len); + if(ctrlReg & CR_TXIEN) { if(!(statReg & SR_IRQ)) { #if defined SIO1_DEBUG @@ -221,6 +221,7 @@ void Exchange(s32 data) { } } +#if 0 if(settings.player == PLAYER_MASTER) { connectionSend((u8*)&exc_data_send, sizeof(exc_data_send)); connectionRecv((u8*)&exc_data_recv, sizeof(exc_data_recv)); @@ -229,7 +230,7 @@ void Exchange(s32 data) { connectionRecv((u8*)&exc_data_recv, sizeof(exc_data_recv)); connectionSend((u8*)&exc_data_send, sizeof(exc_data_send)); } - +#endif if(exc_data_recv.reg & CR_DTR) statReg |= SR_DSR; else @@ -240,6 +241,10 @@ void Exchange(s32 data) { else statReg &= ~SR_CTS; + if (SR_CTS & SR_CTS) { + exc_data_recv.len = connectionRecv((u8*)&exc_data_recv.data, 1); + } + if(exc_data_recv.len) { fifoPush(exc_data_recv.data); @@ -249,7 +254,7 @@ void Exchange(s32 data) { } if(ctrlReg & CR_RXIEN) { - if(fifoEmployment() == fifoIrqVals[(ctrlReg >> 8) & 0x03]) { + if(fifoEmployment() >= fifoIrqVals[(ctrlReg >> 8) & 0x03]) { if(!(statReg & SR_IRQ)) { #if defined SIO1_DEBUG printf("irqCallback() : CR_RXIEN\n"); @@ -352,7 +357,7 @@ void CALLBACK SIO1writeCtrl16(u16 ctrl) { if(ctrlReg & CR_ERRRST) { ctrlReg &= ~CR_ERRRST; statReg &= ~(SR_PERROR | SR_OE | SR_FE | SR_IRQ); - + fifoResetErr(); } @@ -363,15 +368,15 @@ void CALLBACK SIO1writeCtrl16(u16 ctrl) { ctrlReg = 0; baudReg = 0; } - + // FIXME: buffer not cleared and overrun possible, but flag must be cleared. //if(!(ctrlReg & CR_RXEN)) // statReg &= ~SR_RXRDY; - + // FIXME: ugly hack for C&C: RA and C&C: RAR. if(((ctrlReg >> 8) & 0x03) != ((ctrlSaved >> 8) & 0x03)) fifoReset(); - + // FIXME: move to Exchange. if(ctrlReg & CR_TXIEN) { if(!(statReg & SR_IRQ)) { @@ -382,7 +387,7 @@ void CALLBACK SIO1writeCtrl16(u16 ctrl) { statReg |= SR_IRQ; } } - + Exchange(-1); } |
