diff --git a/python_scripts/joypad_test.py b/python_scripts/joypad_test.py new file mode 100644 index 00000000..f9697f76 --- /dev/null +++ b/python_scripts/joypad_test.py @@ -0,0 +1,6 @@ +import emu +import joypad + +while True: + print(f"PY: {joypad.read(1)}") + emu.frameadvance() \ No newline at end of file diff --git a/src/python-engine.cpp b/src/python-engine.cpp index 730c8057..9dee0da6 100644 --- a/src/python-engine.cpp +++ b/src/python-engine.cpp @@ -10,6 +10,7 @@ namespace py = pybind11; #include "fceupython.h" #include "movie.h" +#include "state.h" // Are we running any code right now? static char* pythonScriptName = NULL; @@ -25,6 +26,12 @@ std::mutex mtx; std::condition_variable cv; +// Look in fceu.h for macros named like JOY_UP to determine the order. +static const char *button_mappings[] = { + "A", "B", "select", "start", "up", "down", "left", "right" +}; + + static void emu_frameadvance() { // Can't call if a frameAdvance is already waiting @@ -47,12 +54,46 @@ static int emu_framecount() return FCEUMOV_GetFrame(); } +// dict joypad.read(int which = 1) +// +// Reads the joypads as inputted by the user. +static py::dict joy_get_internal(int player, bool reportUp, bool reportDown) { + // Use the OS-specific code to do the reading. + extern SFORMAT FCEUCTRL_STATEINFO[]; + uint8 buttons = ((uint8*) FCEUCTRL_STATEINFO[1].v)[player - 1]; + + py::dict input; + + for (int i = 0; i < 8; i++) { + bool pressed = (buttons & (1<