let tas playback and input coexist

This commit is contained in:
Cadey Ratio 2020-05-08 08:47:25 -04:00
parent 0a4f693fdc
commit cf7c89e31f
3 changed files with 33 additions and 23 deletions

View File

@ -8,9 +8,9 @@
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_tas_recorder, */ &controller_tas_recorder,
}; };
s32 osContInit(OSMesgQueue *mq, u8 *controllerBits, OSContStatus *status) { s32 osContInit(OSMesgQueue *mq, u8 *controllerBits, OSContStatus *status) {

View File

@ -5,25 +5,35 @@
#include "controller_api.h" #include "controller_api.h"
static int fd; static FILE *fin;
static int counter; static int counter;
#define OFFSET 0x400 #define OFFSET 0x400
#define fname "cont.m64"
static void tas_init(void) { static void tas_init(void) {
fd = open("cont.m64", O_RDONLY); fin = fopen(fname, "rb");
if (fd != 0) { if (fin == NULL) {
uint8_t buf[OFFSET]; return;
read(fd, buf, sizeof(buf));
counter = 0;
} }
printf("[tas_playback] loading %s\n", fname);
uint8_t buf[OFFSET];
fread(buf, 1, sizeof(buf), fin);
counter = 0;
} }
static void tas_read(OSContPad *pad) { static void tas_read(OSContPad *pad) {
if (fd != 0) { if (fin == NULL) {
return;
}
uint8_t bytes[4] = {0}; uint8_t bytes[4] = {0};
int result = read(fd, bytes, 4); int result = fread(bytes, 1, 4, fin);
if (result < 0) { if (feof(fin)) {
printf("[tas_playback] end of tas input\n");
fclose(fin);
fin = NULL;
return; return;
} }
@ -31,10 +41,9 @@ static void tas_read(OSContPad *pad) {
pad->stick_x = bytes[2]; pad->stick_x = bytes[2];
pad->stick_y = bytes[3]; pad->stick_y = bytes[3];
counter+=4; counter+=4;
printf("%x called %04x %d %d\n", (counter + OFFSET), pad->button, bytes[2], bytes[3]); printf("[tas_playback] %08x called %04x %02x%02x\n", (counter + OFFSET), pad->button, bytes[2], bytes[3]);
fflush(stdout); fflush(stdout);
} }
}
struct ControllerAPI controller_recorded_tas = { struct ControllerAPI controller_recorded_tas = {
tas_init, tas_init,

View File

@ -13,6 +13,7 @@ static int counter;
static void tas_recorder_close(void) { static void tas_recorder_close(void) {
fclose(fout); fclose(fout);
printf("[tas_recorder] saving tas data to %s\n", fname);
} }
static void tas_recorder_init(void) { static void tas_recorder_init(void) {