diff --git a/src/lindbergh/baseboard.c b/src/lindbergh/baseboard.c index a88e6eb..700a1f5 100644 --- a/src/lindbergh/baseboard.c +++ b/src/lindbergh/baseboard.c @@ -3,11 +3,25 @@ #include #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include "baseboard.h" #include "config.h" #include "jvs.h" +#include "serial.h" #define SERIAL_STRING "FE11-X018012022X" @@ -55,6 +69,7 @@ unsigned int sharedMemoryIndex = 0; uint8_t sharedMemory[1024 * 32] = {0}; int selectReply = -1; +int jvsFileDescriptor = -1; int initBaseboard() { @@ -75,6 +90,16 @@ int initBaseboard() fseek(sram, 0, SEEK_SET); + if (getConfig()->emulateJVS == 0 && strcmp(getConfig()->jvsPath, "none") != 0) + { + jvsFileDescriptor = open(getConfig()->jvsPath, O_RDWR | O_NOCTTY | O_SYNC | O_NDELAY); + if (jvsFileDescriptor < 0) + { + printf("Error: Failed to open %s for JVS\n", getConfig()->jvsPath); + } + setSerialAttributes(jvsFileDescriptor, B115200); + } + return 0; } @@ -174,7 +199,31 @@ int baseboardIoctl(int fd, unsigned int request, void *data) jvsCommand.destAddress = _data[3]; jvsCommand.destSize = _data[4]; memcpy(inputBuffer, &sharedMemory[jvsCommand.srcAddress], jvsCommand.srcSize); - processPacket(); + if (getConfig()->emulateJVS) + { + processPacket(); + } + else if (jvsFileDescriptor >= 0) + { + write(jvsFileDescriptor, inputBuffer, jvsCommand.srcSize); + for (int i = 0; i < jvsCommand.srcSize; i++) + printf("%X ", inputBuffer[i]); + printf("\n"); + + for (int i = 0; i < jvsCommand.srcSize; i++) + { + if (inputBuffer[i] == 0xF0) + { + printf("SENSE LINE 3\n"); + setSenseLine(3); + } + else if (inputBuffer[i] == 0xF1) + { + setSenseLine(1); + printf("SENSE LINE 1\n"); + } + } + } } break; @@ -213,9 +262,21 @@ int baseboardIoctl(int fd, unsigned int request, void *data) case BASEBOARD_PROCESS_JVS: { - memcpy(&sharedMemory[jvsCommand.destAddress], outputBuffer, outputPacket.length + 3); - _data[2] = jvsCommand.destAddress; - _data[3] = outputPacket.length + 3; + if (getConfig()->emulateJVS) + { + memcpy(&sharedMemory[jvsCommand.destAddress], outputBuffer, outputPacket.length + 3); + _data[2] = jvsCommand.destAddress; + _data[3] = outputPacket.length + 3; + } + else if (jvsFileDescriptor >= 0) + { + int count = read(jvsFileDescriptor, &sharedMemory[jvsCommand.destAddress], 255); + _data[2] = jvsCommand.destAddress; + _data[3] = count; + for (int i = 0; i < count; i++) + printf("%X ", sharedMemory[jvsCommand.destAddress + i]); + printf("\n"); + } } break; diff --git a/src/lindbergh/config.c b/src/lindbergh/config.c index 2eb0ded..f062ef8 100644 --- a/src/lindbergh/config.c +++ b/src/lindbergh/config.c @@ -136,7 +136,10 @@ int initConfig() config.fullscreen = 0; strcpy(config.eepromPath, "eeprom.bin"); strcpy(config.sramPath, "sram.bin"); - strcpy(config.jvsPath, "/dev/ttyUSB0"); + strcpy(config.jvsPath, "none"); + strcpy(config.driveboardPath, "none"); + strcpy(config.motionboardPath, "none"); + strcpy(config.rideboardPath, "none"); config.width = 1024; config.height = 768; if (detectGame() != 0) diff --git a/src/lindbergh/config.h b/src/lindbergh/config.h index d044de7..c73d767 100644 --- a/src/lindbergh/config.h +++ b/src/lindbergh/config.h @@ -19,6 +19,9 @@ typedef struct char eepromPath[MAX_PATH_LENGTH]; char sramPath[MAX_PATH_LENGTH]; char jvsPath[MAX_PATH_LENGTH]; + char rideboardPath[MAX_PATH_LENGTH]; + char motionboardPath[MAX_PATH_LENGTH]; + char driveboardPath[MAX_PATH_LENGTH]; int width; int height; Game game; diff --git a/src/lindbergh/jvs.c b/src/lindbergh/jvs.c index 5d3d2fb..988a105 100644 --- a/src/lindbergh/jvs.c +++ b/src/lindbergh/jvs.c @@ -638,3 +638,7 @@ int setAnalogue(JVSInput channel, int value) io.state.analogueChannel[channel] = value; return 1; } + +void setSenseLine(int _senseLine) { + senseLine = _senseLine; +} diff --git a/src/lindbergh/jvs.h b/src/lindbergh/jvs.h index bab7acc..d31c553 100644 --- a/src/lindbergh/jvs.h +++ b/src/lindbergh/jvs.h @@ -235,6 +235,7 @@ extern JVSPacket inputPacket, outputPacket; extern unsigned char outputBuffer[JVS_MAX_PACKET_SIZE], inputBuffer[JVS_MAX_PACKET_SIZE]; int getSenseLine(); +void setSenseLine(int senseLine); JVSCapabilities *getCapabilities(); JVSState *getState(); diff --git a/src/lindbergh/serial.c b/src/lindbergh/serial.c new file mode 100644 index 0000000..0eb0257 --- /dev/null +++ b/src/lindbergh/serial.c @@ -0,0 +1,66 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#include "serial.h" + +int setSerialAttributes(int fd, int myBaud) +{ + struct termios options; + int status; + tcgetattr(fd, &options); + + cfmakeraw(&options); + cfsetispeed(&options, myBaud); + cfsetospeed(&options, myBaud); + + options.c_cflag |= (CLOCAL | CREAD); + options.c_cflag &= ~PARENB; + options.c_cflag &= ~CSTOPB; + options.c_cflag &= ~CSIZE; + options.c_cflag |= CS8; + options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); + options.c_oflag &= ~OPOST; + + options.c_cc[VMIN] = 10; + options.c_cc[VTIME] = 10; // One seconds (10 deciseconds) + + tcsetattr(fd, TCSANOW, &options); + + ioctl(fd, TIOCMGET, &status); + + status |= TIOCM_DTR; + status |= TIOCM_RTS; + + ioctl(fd, TIOCMSET, &status); + + usleep(100 * 1000); // 10mS + + struct serial_struct serial_settings; + + ioctl(fd, TIOCGSERIAL, &serial_settings); + + serial_settings.flags |= ASYNC_LOW_LATENCY; + ioctl(fd, TIOCSSERIAL, &serial_settings); + + tcflush(fd, TCIOFLUSH); + usleep(100 * 1000); // Required to make flush work, for some reason + + return 0; +} diff --git a/src/lindbergh/serial.h b/src/lindbergh/serial.h new file mode 100644 index 0000000..9680c4f --- /dev/null +++ b/src/lindbergh/serial.h @@ -0,0 +1,2 @@ + +int setSerialAttributes(int fd, int myBaud);