proof of concept: pipe a demo into the game

This commit is contained in:
Cadey Ratio 2020-05-08 18:18:45 -04:00
parent 1fd397d89c
commit 4357cd0494
3 changed files with 22 additions and 4 deletions

1
.gitignore vendored
View File

@ -75,3 +75,4 @@ sm64config.txt
/target
vblank
input
*.m64

View File

@ -7,16 +7,22 @@ use std::{
fn main() -> anyhow::Result<()> {
pretty_env_logger::try_init()?;
let controller_data = [0; 4];
let mut controller_data = [0; 4];
let mut vblank = File::open("vblank")?;
let mut input = OpenOptions::new().write(true).open("input")?;
let mut demofile = File::open("demo.m64")?;
{
let mut buf = [0; 1024];
demofile.read(&mut buf)?;
}
info!("ready");
loop {
let mut data = [0; 3];
info!("waiting for vblank");
debug!("waiting for vblank");
vblank.read(&mut data)?;
let str = from_utf8(&data)?;
debug!("got data: {}", str);
@ -24,6 +30,7 @@ fn main() -> anyhow::Result<()> {
warn!("asked to exit by the game");
return Ok(());
}
demofile.read(&mut controller_data)?;
input.write(&controller_data)?;
}
}

View File

@ -21,7 +21,17 @@ static FILE *input;
#define bye "BYE"
static void gamebridge_close(void) {
if (!configGameBridge) {
return;
}
printf("[gamebridge] exiting\n");
fwrite(bye, 1, strlen(bye), vblank);
fclose(vblank);
fclose(input);
unlink(vblank_fname);
unlink(input_fname);
}
static void gamebridge_init(void) {
@ -68,14 +78,14 @@ static void gamebridge_read(OSContPad *pad) {
return;
}
printf("[gamebridge] waiting for input\n");
//printf("[gamebridge] waiting for input\n");
fwrite(ok, 1, strlen(ok), vblank);
uint8_t bytes[4] = {0};
fread(bytes, 1, 4, input);
pad->button = (bytes[0] << 8) | bytes[1];
pad->stick_x = bytes[2];
pad->stick_y = bytes[3];
printf("[gamebridge] %02x%02x %02x%02x\n", bytes[0], bytes[1], bytes[2], bytes[3]);
//printf("[gamebridge] %02x%02x %02x%02x\n", bytes[0], bytes[1], bytes[2], bytes[3]);
fflush(stdout);
}