sm64pc/doc/gamebridge.org

55 lines
2.3 KiB
Org Mode
Raw Normal View History

2020-05-08 20:30:43 +00:00
#+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
2020-05-08 22:03:34 +00:00
the other is doing the file I/O to the game
2020-05-08 20:30:43 +00:00
the game bridge thread has two file descriptors open, a fifo for feeding inputs
2020-05-08 22:03:34 +00:00
to the game and a fifo opened by the game for signaling vblanks
2020-05-08 20:30:43 +00:00
the game will then write a readiness signal to the rust program and read the
2020-05-08 22:03:34 +00:00
button data fifo
then things will progress normally
2020-05-08 20:30:43 +00:00
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
2020-05-08 21:54:57 +00:00
=setvbuf(f, (char *)NULL, _IONBF, 0);= in C and is the default in Rust.
2020-05-08 20:30:43 +00:00
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.
2020-05-08 21:54:57 +00:00
On every frame, the game *MUST* write the text ="OK\n"= to the vblank fifo. This
will signal the bridge that it *MUST* write four bytes of data to the input
2020-05-08 20:30:43 +00:00
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.
2020-05-08 21:54:57 +00:00
When the game is exiting, the game *SHOULD* write ="BYE"= to the vblank fifo.
When the bridge recieves a ="BYE"= message, it *MUST* exit.