gamebridge: Twitch Control #2
|
@ -29,6 +29,7 @@ struct ConfigOption {
|
||||||
/*
|
/*
|
||||||
*Config options and default values
|
*Config options and default values
|
||||||
*/
|
*/
|
||||||
|
bool configGameBridge = false;
|
||||||
bool configFullscreen = false;
|
bool configFullscreen = false;
|
||||||
// Keyboard mappings (scancode values)
|
// Keyboard mappings (scancode values)
|
||||||
unsigned int configKeyA = 0x26;
|
unsigned int configKeyA = 0x26;
|
||||||
|
@ -47,6 +48,7 @@ unsigned int configKeyStickRight = 0x20;
|
||||||
|
|
||||||
|
|
||||||
static const struct ConfigOption options[] = {
|
static const struct ConfigOption options[] = {
|
||||||
|
{.name = "gamebridge", .type = CONFIG_TYPE_BOOL, .boolValue = &configGameBridge},
|
||||||
{.name = "fullscreen", .type = CONFIG_TYPE_BOOL, .boolValue = &configFullscreen},
|
{.name = "fullscreen", .type = CONFIG_TYPE_BOOL, .boolValue = &configFullscreen},
|
||||||
{.name = "key_a", .type = CONFIG_TYPE_UINT, .uintValue = &configKeyA},
|
{.name = "key_a", .type = CONFIG_TYPE_UINT, .uintValue = &configKeyA},
|
||||||
{.name = "key_b", .type = CONFIG_TYPE_UINT, .uintValue = &configKeyB},
|
{.name = "key_b", .type = CONFIG_TYPE_UINT, .uintValue = &configKeyB},
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#ifndef CONFIGFILE_H
|
#ifndef CONFIGFILE_H
|
||||||
#define CONFIGFILE_H
|
#define CONFIGFILE_H
|
||||||
|
|
||||||
|
extern bool configGameBridge;
|
||||||
extern bool configFullscreen;
|
extern bool configFullscreen;
|
||||||
extern unsigned int configKeyA;
|
extern unsigned int configKeyA;
|
||||||
extern unsigned int configKeyB;
|
extern unsigned int configKeyB;
|
||||||
|
|
|
@ -5,11 +5,13 @@
|
||||||
#include "controller_keyboard.h"
|
#include "controller_keyboard.h"
|
||||||
|
|
||||||
#include "controller_sdl.h"
|
#include "controller_sdl.h"
|
||||||
|
#include "controller_gamebridge.h"
|
||||||
|
|
||||||
static struct ControllerAPI *controller_implementations[] = {
|
static struct ControllerAPI *controller_implementations[] = {
|
||||||
&controller_recorded_tas,
|
&controller_recorded_tas,
|
||||||
&controller_sdl,
|
&controller_sdl,
|
||||||
&controller_keyboard,
|
&controller_keyboard,
|
||||||
|
&controller_gamebridge,
|
||||||
};
|
};
|
||||||
|
|
||||||
s32 osContInit(OSMesgQueue *mq, u8 *controllerBits, OSContStatus *status) {
|
s32 osContInit(OSMesgQueue *mq, u8 *controllerBits, OSContStatus *status) {
|
||||||
|
|
|
@ -0,0 +1,69 @@
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <ultra64.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
#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
|
||||||
|
};
|
|
@ -0,0 +1,8 @@
|
||||||
|
#ifndef CONTROLLER_GAMEBRIDGE_H
|
||||||
|
#define CONTROLLER_GAMEBRIDGE_H
|
||||||
|
|
||||||
|
#include "controller_api.h"
|
||||||
|
|
||||||
|
extern struct ControllerAPI controller_gamebridge;
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue