diff --git a/src/pc/controller/controller_recorded_tas.c b/src/pc/controller/controller_recorded_tas.c index 4f5c1bb..c55c533 100644 --- a/src/pc/controller/controller_recorded_tas.c +++ b/src/pc/controller/controller_recorded_tas.c @@ -1,25 +1,35 @@ #include #include +#include +#include #include "controller_api.h" -static FILE *fp; +static int fd; +static int counter; + +#define OFFSET 0x400 static void tas_init(void) { - fp = fopen("cont.m64", "rb"); - if (fp != NULL) { - uint8_t buf[0x400]; - fread(buf, 1, sizeof(buf), fp); + fd = open("cont.m64", O_RDONLY); + if (fd != 0) { + uint8_t buf[OFFSET]; + read(fd, buf, sizeof(buf)); + counter = 0; } } static void tas_read(OSContPad *pad) { - if (fp != NULL) { + if (fd != 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->stick_x = bytes[2]; pad->stick_y = bytes[3]; + counter+=4; + printf("%x called %04x %d %d\n", (counter + OFFSET), pad->button, bytes[2], bytes[3]); + fflush(stdout); } }