#include #include #include #include #include #include #include #include #include #include #include "controller_api.h" #include "../configfile.h" static FILE *vblank; static FILE *input; #define vblank_fname "vblank" #define input_fname "input" static void gamebridge_init(void) { if (!configGameBridge) { return; } unlink(vblank_fname); unlink(input_fname); int result; result = mkfifo(vblank_fname, S_IRUSR|S_IWUSR); if (result < 0) { perror("mkfifo "vblank_fname); assert(result < 0); } result = mkfifo(input_fname, S_IRUSR| S_IWUSR); if (result < 0) { perror("mkfifo "input_fname); assert(result < 0); } vblank = fopen(vblank_fname, "w"); input = fopen(input_fname, "rb"); assert(vblank); assert(input); setvbuf(vblank, NULL, _IONBF, 0); setvbuf(input, NULL, _IONBF, 0); } static void gamebridge_read(OSContPad *pad) { if (!configGameBridge) { return; } char* ok = "OK\n"; fwrite(ok, 1, sizeof(ok), vblank); uint8_t bytes[4] = {0}; fread(bytes, 1, 4, input); pad->button = (bytes[0] << 8) | bytes[1]; pad->stick_x = bytes[2]; pad->stick_y = bytes[3]; } struct ControllerAPI controller_gamebridge = { gamebridge_init, gamebridge_read };