gamebridge: Twitch Control #2

Merged
cadey merged 29 commits from gamebridge into master 2020-05-11 22:40:05 +00:00
1 changed files with 17 additions and 7 deletions
Showing only changes of commit 5e138304d8 - Show all commits

View File

@ -1,25 +1,35 @@
#include <stdio.h> #include <stdio.h>
#include <ultra64.h> #include <ultra64.h>
#include <assert.h>
#include <fcntl.h>
#include "controller_api.h" #include "controller_api.h"
static FILE *fp; static int fd;
static int counter;
#define OFFSET 0x400
static void tas_init(void) { static void tas_init(void) {
fp = fopen("cont.m64", "rb"); fd = open("cont.m64", O_RDONLY);
if (fp != NULL) { if (fd != 0) {
uint8_t buf[0x400]; uint8_t buf[OFFSET];
fread(buf, 1, sizeof(buf), fp); read(fd, buf, sizeof(buf));
counter = 0;
} }
} }
static void tas_read(OSContPad *pad) { static void tas_read(OSContPad *pad) {
if (fp != NULL) { if (fd != 0) {
uint8_t bytes[4] = {0}; uint8_t bytes[4] = {0};
fread(bytes, 1, 4, fp); int result = read(fd, bytes, 4);
assert(result > 0);
pad->button = (bytes[0] << 8) | bytes[1]; pad->button = (bytes[0] << 8) | bytes[1];
pad->stick_x = bytes[2]; pad->stick_x = bytes[2];
pad->stick_y = bytes[3]; pad->stick_y = bytes[3];
counter+=4;
printf("%x called %04x %d %d\n", (counter + OFFSET), pad->button, bytes[2], bytes[3]);
fflush(stdout);
} }
} }