diff --git a/doc/gamebridge.org b/doc/gamebridge.org new file mode 100644 index 0000000..d2bdfc5 --- /dev/null +++ b/doc/gamebridge.org @@ -0,0 +1,47 @@ +#+TITLE: gamebridge + +An interface between Super Mario 64 and just about anything else your heart +desires. + +* High level ideas + +the rust program has two threads, one is getting the inputs from $SOMEWHERE and +the other is doing the file I/O to the game \\ +the game bridge thread has two file descriptors open, a fifo for feeding inputs +to the game and a fifo opened by the game for signaling vblanks \\ +the game will then write a readiness signal to the rust program and read the +button data fifo \\ +then things will progress normally \\ +the getting the input thread of the rust program will have some logic for +telling how long ago it got liveness of the input source (explicitly vaguely +defined to allow a controller to sit there and do nothing as long as it still +exists), and then "sticking" it until, say, 10 frames have passed and then it +will block infinitely, freezing the game in place + +* Goals + ++ Blocking, synchronous rust as much as possible ++ unix fifos are great, let's use them + +* Protocol + +The protocol between the game and the bridge will be as follows (based on the +[[http://tasvideos.org/EmulatorResources/Mupen/M64.html][Mupen64 demo format]]). Two unix fifos will be created by the bridge. + +The game and the bridge will both need to take care that the files are opened in +*unbuffered I/O modes*. This can be done with +=setvbuf( f, (char *)NULL, _IONBF, 0 );= in C and is the default in Rust. + +The first one will be called =vblank= and will then be opened by the game in +write mode when it starts. The bridge will open this fifo in read mode. + +The second one will be called =input= and will be opened by the game in read +mode. The bridge will open this fifo in write mode. + +On every frame, the game will write the text ="OK\n"= to the vblank fifo. This +will signal the bridge that it should write four bytes of data to the input +fifo, conforming to the [[http://tasvideos.org/EmulatorResources/Mupen/M64.html#ControllerData][Controller Data]] specification of the Mupen64 format. +This data will be interpreted by the game as actions for Mario to take. + +The bridge *MUST* block on waiting for the vblank fifo to be written to by the +game and the game *MUST* block on the input fifo being written to by the bridge. diff --git a/gamebridge/.gitignore b/gamebridge/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/gamebridge/.gitignore @@ -0,0 +1 @@ +/target diff --git a/gamebridge/Cargo.toml b/gamebridge/Cargo.toml new file mode 100644 index 0000000..be21824 --- /dev/null +++ b/gamebridge/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "gamebridge" +version = "0.1.0" +authors = ["Christine Dodrill "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/gamebridge/src/main.rs b/gamebridge/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/gamebridge/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +}