diff --git a/README.md b/README.md index 2ff2eff..2656280 100644 --- a/README.md +++ b/README.md @@ -53,26 +53,4 @@ This is an emulation of the driver that games use to route sound out of the Crea ## Config -### EMULATE_JVS - -This turns on the JVS emulation layer, which will use X11s input capabilities to read your mouse/keyboard. When this is turned off the JVS traffic will be passed through to a serial port defined by `JVS_PATH`. - -### JVS_PATH - -This defines the path of the serial port that is connected to the JVS IO. - -### FULLSCREEN - -This defines if the game should open in full screen mode. - -### EMULATE_RIDEBOARD - -This turns on the Rideboard emulation layer used in the games The House Of The Dead 4 Special, and Let's Go Jungle Special! - -### EMULATE_DRIVEBOARD - -This turns on the Driveboard emulation layer used in the games Outrun 2 SP SDX, SEGA Race TV, Initial D 4 and Initial D 5. - -### EMULATE_MOTIONBOARD - -This turns on the motionboard emulation layer used in the game Outrun 2 SP SDX in its SDX setting. +A default configuration file is provided in `docs/lindbergh.conf`. It should be placed in the same folder as the game is run from. If no config file is present a default setting will be used. diff --git a/docs/configs/config.jvs-passthrough b/docs/configs/config.jvs-passthrough deleted file mode 100644 index 17e63ff..0000000 --- a/docs/configs/config.jvs-passthrough +++ /dev/null @@ -1,5 +0,0 @@ -# Turn off JVS emulation and default to JVS Passthrough -EMULATE_JVS 0 - -# The path to the real JVS IO you'd like to use -JVS_PATH /dev/ttyUSB0 diff --git a/docs/configs/config.outrun b/docs/configs/config.outrun deleted file mode 100644 index a1c9eda..0000000 --- a/docs/configs/config.outrun +++ /dev/null @@ -1,2 +0,0 @@ -EMULATE_DRIVEBOARD 1 -EMULATE_RIDEBOARD 1 diff --git a/docs/configs/config.the-house-of-the-dead-4-special b/docs/configs/config.the-house-of-the-dead-4-special deleted file mode 100644 index 340c2d5..0000000 --- a/docs/configs/config.the-house-of-the-dead-4-special +++ /dev/null @@ -1,2 +0,0 @@ -# Emulate the special rideboard -EMULATE_RIDEBOARD 1 diff --git a/src/lindbergh/config.c b/src/lindbergh/config.c index 2c6ef0c..5e458af 100644 --- a/src/lindbergh/config.c +++ b/src/lindbergh/config.c @@ -1,11 +1,33 @@ #include #include +#include #include #include "config.h" EmulatorConfig config = {0}; +FILE *configFile = NULL; + +#define CONFIG_PATH "lindbergh.conf" +#define MAX_LINE_LENGTH 1024 + +static char *getNextToken(char *buffer, char *seperator, char **saveptr) +{ + char *token = strtok_r(buffer, seperator, saveptr); + if (token == NULL) + return NULL; + + for (int i = 0; i < (int)strlen(token); i++) + { + if ((token[i] == '\n') || (token[i] == '\r')) + { + token[i] = 0; + } + } + return token; +} + static int detectGame() { @@ -54,6 +76,48 @@ char *getGameName() return "Unknown Game"; } +int readConfig(FILE *configFile, EmulatorConfig *config) +{ + char buffer[MAX_LINE_LENGTH]; + char *saveptr = NULL; + + while (fgets(buffer, MAX_LINE_LENGTH, configFile)) + { + + /* Check for comments */ + if (buffer[0] == '#' || buffer[0] == 0 || buffer[0] == ' ' || buffer[0] == '\r' || buffer[0] == '\n') + continue; + + char *command = getNextToken(buffer, " ", &saveptr); + + if (strcmp(command, "WIDTH") == 0) + config->width = atoi(getNextToken(NULL, " ", &saveptr)); + + else if (strcmp(command, "HEIGHT") == 0) + config->height = atoi(getNextToken(NULL, " ", &saveptr)); + + else if (strcmp(command, "EEPROM_PATH") == 0) + strcpy(config->eepromPath, getNextToken(NULL, " ", &saveptr)); + + else if (strcmp(command, "SRAM_PATH") == 0) + strcpy(config->eepromPath, getNextToken(NULL, " ", &saveptr)); + + else if (strcmp(command, "EMULATE_RIDEBOARD") == 0) + config->emulateRideboard = atoi(getNextToken(NULL, " ", &saveptr)); + + else if (strcmp(command, "EMULATE_DRIVEBOARD") == 0) + config->emulateDriveboard = atoi(getNextToken(NULL, " ", &saveptr)); + + else if (strcmp(command, "EMULATE_MOTIONBOARD") == 0) + config->emulateMotionboard = atoi(getNextToken(NULL, " ", &saveptr)); + + else + printf("Error: Unknown settings command %s\n", command); + } + + return 0; +} + int initConfig() { config.emulateRideboard = 0; @@ -67,6 +131,19 @@ int initConfig() { printf("Warning: Unsure what game this is, using default configuration values"); } + + configFile = fopen(CONFIG_PATH, "r"); + + if (configFile == NULL) + { + printf("Error: Cannot open %s, using default values\n", CONFIG_PATH); + return 1; + } + + readConfig(configFile, &config); + + fclose(configFile); + return 0; } diff --git a/src/lindbergh/graphics.c b/src/lindbergh/graphics.c index 6e9817f..05096f2 100644 --- a/src/lindbergh/graphics.c +++ b/src/lindbergh/graphics.c @@ -116,7 +116,6 @@ int XNextEvent(Display *display, XEvent *event_return) int (*_XNextEvent)(Display * display, XEvent * event_return) = dlsym(RTLD_NEXT, "XNextEvent"); int returnValue = _XNextEvent(display, event_return); - switch (event_return->type) { case KeyPress: @@ -124,7 +123,6 @@ int XNextEvent(Display *display, XEvent *event_return) { case 28: securityBoardSetSwitch(BUTTON_TEST, 1); - abort(); break; case 39: securityBoardSetSwitch(BUTTON_SERVICE, 1); diff --git a/src/lindbergh/hook.c b/src/lindbergh/hook.c index ab5bb7e..e12e87f 100644 --- a/src/lindbergh/hook.c +++ b/src/lindbergh/hook.c @@ -94,7 +94,7 @@ static void handleSegfault(int signal, siginfo_t *info, void *ptr) default: printf("Warning: Skipping SEGFAULT %X\n", *code); ctx->uc_mcontext.gregs[REG_EIP]++; - // abort(); + //abort(); } } @@ -317,16 +317,15 @@ int system(const char *command) if (strcmp(command, "mkdir /tmp/segaboot > /dev/null") == 0) return system("mkdir tmp/segaboot > /dev/null"); - /* - if (strcmp(command, "lspci | grep \"Multimedia audio controller: %Creative\" > /dev/null") == 0) + if (strcmp(command, "lspci | grep \"Multimedia audio controller: %Creative\" > /dev/null") == 0) return 0; - if (strcmp(command, "lsmod | grep ctaud") == 0) + if (strcmp(command, "lsmod | grep ctaud") == 0) return 0; - if (strcmp(command, "lspci | grep MPC8272 > /dev/null") == 0) + if (strcmp(command, "lspci | grep MPC8272 > /dev/null") == 0) return 0; - */ + return _system(command); } diff --git a/src/lindbergh/securityboard.c b/src/lindbergh/securityboard.c index 3a36366..e2e4238 100644 --- a/src/lindbergh/securityboard.c +++ b/src/lindbergh/securityboard.c @@ -5,6 +5,7 @@ #include "config.h" #define SECURITY_BOARD_FRONT_PANEL 0x38 +#define SECURITY_BOARD_FRONT_PANEL_NON_ROOT 0x1038 #define SECURITY_BOARD_KEYCHIP 0xFF #define DIP_SWITCH_ROTATION 3 @@ -101,6 +102,7 @@ int securityBoardIn(uint16_t port, uint32_t *data) { switch (port) { + case SECURITY_BOARD_FRONT_PANEL_NON_ROOT: case SECURITY_BOARD_FRONT_PANEL: { uint32_t result = 0xFFFFFFFF;