sm64pc/src/pc/controller/controller_recorded_tas.c

43 lines
878 B
C
Raw Normal View History

2020-05-05 12:15:53 +00:00
#include <stdio.h>
#include <ultra64.h>
2020-05-08 03:30:08 +00:00
#include <assert.h>
#include <fcntl.h>
2020-05-05 12:15:53 +00:00
#include "controller_api.h"
2020-05-08 03:30:08 +00:00
static int fd;
static int counter;
#define OFFSET 0x400
2020-05-05 12:15:53 +00:00
static void tas_init(void) {
2020-05-08 03:30:08 +00:00
fd = open("cont.m64", O_RDONLY);
if (fd != 0) {
uint8_t buf[OFFSET];
read(fd, buf, sizeof(buf));
counter = 0;
2020-05-05 12:15:53 +00:00
}
}
static void tas_read(OSContPad *pad) {
2020-05-08 03:30:08 +00:00
if (fd != 0) {
2020-05-05 12:15:53 +00:00
uint8_t bytes[4] = {0};
2020-05-08 03:30:08 +00:00
int result = read(fd, bytes, 4);
2020-05-08 10:48:52 +00:00
if (result < 0) {
return;
}
2020-05-05 12:15:53 +00:00
pad->button = (bytes[0] << 8) | bytes[1];
pad->stick_x = bytes[2];
pad->stick_y = bytes[3];
2020-05-08 03:30:08 +00:00
counter+=4;
printf("%x called %04x %d %d\n", (counter + OFFSET), pad->button, bytes[2], bytes[3]);
fflush(stdout);
2020-05-05 12:15:53 +00:00
}
}
struct ControllerAPI controller_recorded_tas = {
tas_init,
tas_read
};