Browse Source

gamebridge: use a match here

gamebridge
Cadey Ratio 11 months ago
parent
commit
70338a9b47
  1. 29
      gamebridge/src/main.rs

29
gamebridge/src/main.rs

@ -1,22 +1,17 @@
use log::{debug, info, warn};
use anyhow::{anyhow, Result};
use log::{debug, error, info, warn};
use std::{
fs::{File, OpenOptions},
io::{Read, Write},
str::from_utf8,
};
fn main() -> anyhow::Result<()> {
fn main() -> Result<()> {
pretty_env_logger::try_init()?;
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");
@ -26,11 +21,17 @@ fn main() -> anyhow::Result<()> {
vblank.read(&mut data)?;
let str = from_utf8(&data)?;
debug!("got data: {}", str);
if str == "BYE" {
warn!("asked to exit by the game");
return Ok(());
}
demofile.read(&mut controller_data)?;
input.write(&controller_data)?;
match str {
"OK\n" => input.write(&controller_data)?,
"BYE" => {
warn!("asked to exit by the game");
return Ok(());
},
_ => {
error!("got unknown FIFO data {}", str);
return Err(anyhow!("unknown FIFO data received"));
}
};
}
}
Loading…
Cancel
Save