Merge branch 'tasing' into gamebridge

This commit is contained in:
Cadey Ratio 2020-05-09 11:00:24 -04:00
commit 09f51531cc
4 changed files with 96 additions and 12 deletions

View File

@ -3,15 +3,16 @@
#include "controller_recorded_tas.h" #include "controller_recorded_tas.h"
#include "controller_keyboard.h" #include "controller_keyboard.h"
#include "controller_sdl.h" #include "controller_sdl.h"
#include "controller_gamebridge.h" #include "controller_gamebridge.h"
#include "controller_tas_recorder.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, &controller_gamebridge,
&controller_tas_recorder,
}; };
s32 osContInit(OSMesgQueue *mq, u8 *controllerBits, OSContStatus *status) { s32 osContInit(OSMesgQueue *mq, u8 *controllerBits, OSContStatus *status) {

View File

@ -1,26 +1,48 @@
#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 FILE *fin;
static int counter;
#define OFFSET 0x400
#define fname "cont.m64"
static void tas_init(void) { static void tas_init(void) {
fp = fopen("cont.m64", "rb"); fin = fopen(fname, "rb");
if (fp != NULL) { if (fin == NULL) {
uint8_t buf[0x400]; return;
fread(buf, 1, sizeof(buf), fp);
} }
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 (fp != NULL) { if (fin == NULL) {
uint8_t bytes[4] = {0}; return;
fread(bytes, 1, 4, fp);
pad->button = (bytes[0] << 8) | bytes[1];
pad->stick_x = bytes[2];
pad->stick_y = bytes[3];
} }
uint8_t bytes[4] = {0};
int result = fread(bytes, 1, 4, fin);
if (feof(fin)) {
printf("[tas_playback] end of tas input\n");
fclose(fin);
fin = NULL;
return;
}
pad->button = (bytes[0] << 8) | bytes[1];
pad->stick_x = bytes[2];
pad->stick_y = bytes[3];
counter+=4;
printf("[tas_playback] %08x called %04x %02x%02x\n", (counter + OFFSET), pad->button, bytes[2], bytes[3]);
fflush(stdout);
} }
struct ControllerAPI controller_recorded_tas = { struct ControllerAPI controller_recorded_tas = {

View File

@ -0,0 +1,53 @@
#include <stdio.h>
#include <ultra64.h>
#include <assert.h>
#include <fcntl.h>
#include "controller_api.h"
static FILE *fout;
static int counter;
#define OFFSET 0x400
#define fname "rec.m64"
static void tas_recorder_close(void) {
fclose(fout);
printf("[tas_recorder] saving tas data to %s\n", fname);
}
static void tas_recorder_init(void) {
if (fname == NULL) {
fout = NULL;
return;
}
unlink(fname);
printf("[tas_recorder] writing output to %s\n", fname);
fout = fopen(fname, "wb");
assert(fout != NULL);
uint8_t buf[OFFSET];
memset(buf, 0, sizeof(buf));
fwrite(buf, 1, sizeof(buf), fout);
atexit(tas_recorder_close);
}
static void tas_recorder_read(OSContPad *pad) {
if (fout == NULL) {
return;
}
uint8_t bytes[4] = {0};
int button1 = pad->button;
int button2 = pad->button;
bytes[0] = button1 >> 8;
bytes[1] = button2 & 0x00FF;
bytes[2] = pad->stick_x;
bytes[3] = pad->stick_y;
fwrite(bytes, 1, 4, fout);
}
struct ControllerAPI controller_tas_recorder = {
tas_recorder_init,
tas_recorder_read
};

View File

@ -0,0 +1,8 @@
#ifndef CONTROLLER_TAS_RECORDER_H
#define CONTROLLER_TAS_RECORDER_H
#include "controller_api.h"
extern struct ControllerAPI controller_tas_recorder;
#endif