Redux basic API
All of the settings are exposed to Lua via the
PCSX.settings table. It contains pseudo-tables that are reflections of the internal objects, and can be used to read and write the settings. The exact list of settings can vary quickly over time, so making a full list here would be fruitless. It is possible however to traverse the settings using
pprint for example. The semantic of the settings is the same as from within the GUI, with the same caveats. For example, disabling the dynamic recompiler requires a reboot of the emulator.
PCSX-Redux will periodically try to call the Lua function
DrawImguiFrame to allow the Lua code to draw some widgets on screen. The function will be called exactly once per actual UI frame draw, which, when the emulator is running, will correspond to the emulated GPU's vsync. If the function throws an exception however, it will be disabled until recompiled with new code.
Events Engine interaction & Execution Contexts
LuaJIT C callbacks aren't called from a safe execution context that can allow for coroutine resuming, and luv's execution context doesn't have any error handling.
It is possible to defer executing code to the main loop of PCSX-Redux, which can (a) resume coroutines and (b) execute code in a safe context. The function
PCSX.nextTick(func) will execute the given function in the next main loop iteration. Here's some examples of how to use it:
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
Of course, this can also delay processing significantly, as the main loop is usually bound to the speed of the UI, which can mean up to 20ms of delay.
PCSX.CONSTS contains numerical constants used throughout the rest of the API. Keeping an up to date list here is too exhausting, and it's simpler to print them using
You can access the pads API through
s is the slot number and
p is the pad number, both indexed from 1, Lua-style. So
PCSX.SIO0.slots.pads accesses the first pad, and
PCSX.SIO0.slots.pads accesses the second pad.
Each Pad table has the following functions:
1 2 3 4 5
The button constants can be found in
You can for instance press the button Down on the first pad using the following code:
The Lua code has the following API functions available to it in order to control the execution flow of the emulator:
It's also possible to manipulate savestates using the following functions:
PCSX.createSaveState() -- returns a slice representing the savestate
Additionally, the following function returns a string containing the .proto file used to serialize the savestate:
Note that the actual savestates made from the UI are gzip-compressed, but the functions above don't compress or decompress the data, so if trying to reload a savestate made from the UI, it'll need to be decompressed first, possibly through the zReader File object.
Overall, this means the following is possible:
1 2 3 4 5 6 7 8
printError are available, and will display logs in the Lua Console. You can also use
PCSX.log to display a line in the general Log window. All three functions should behave the way you'd expect from the normal
You can move the cursor within the assembly window and the first memory view using the following functions:
You can take a screenshot of the current view of the emulated display using the following:
This will return a struct that has the following fields:
1 2 3 4 5
Slice will contain the raw bytes of the screenshot data. It's meant to be written out using the
:writeMoveSlice() method on a
File object. The
height will be the width and height of the screenshot, in pixels. The
bpp will be either
BPP_24, depending on the color depth of the screenshot. The size of the
data Slice will be
height * width multiplied by the number of bytes per pixel, depending on the
PCSX.quit([code])schedules the emulator to quit. It's not instantaneous, and will only quit after the current block of Lua code has finished executing, which will be before the next main loop iteration. The
codeparameter is optional, and will be the exit code of the emulator. If not specified, it'll default to 0.