coloX Debugger
The host-side Lua debugging + test automation channel is not a cartridge API—it is unavailable inside .clx files.
It is for developers/testers and requires a build with debugging support (enabled by default in Xcode's coloXtest;
usually absent from ordinary device firmware).
- Desktop / device: Text protocol over TCP port
3563, one command per line; - wasm: The same commands through a page bridge.
Commands can be sent while the game runs without setting a breakpoint first; they also arrive while stopped at a breakpoint
(and can refresh the display). Responses are framed with >-> / <-<:
>-> btn
btn inj=0x20 [LEFT ] left=-1
<-< btn
Contents
- Connection
- Multiple-VM routing
- Lua debugging commands
- Test automation: button injection
- Test automation: gamepad injection
- Test automation: mouse/touch and keyboard injection
- Test automation: screenshots
- Querying input state
- Example session
- Behavior and boundaries
1. Connection
nc 127.0.0.1 3563
help # Full command list
Any TCP-capable script/tool (python/telnet) works; one command per line, terminated by \n.
2. Multiple-VM Routing
The BIOS menu VM and game cartridge VM share port 3563. The first VM to start claims the channel by default; to target a specific VM, list and select:
vmlist # idx cart frame target
# 0 play_menu.clx 1234
# 1 mygame.clx 567 *
vm 1 # Subsequent commands target the game VM
Destroying the target VM (switching cartridges) releases the channel automatically; the next VM to start claims it.
3. Lua Debugging Commands
| Command | Action |
|---|---|
bt | Call stack |
b <file:line \| func> [if cond] | Breakpoint (line/function/conditional) |
i b / i local | Breakpoint list / locals and upvalues |
n / s / fin / c / pause | Step over / step into / step out / continue / pause |
l [width] | List source |
src [file] | Source file list / contents |
p <expression> | Print ([var] accesses upvalues) |
set <var=value> | Assign a value |
r <code> | Execute code in the paused frame |
f <level> | Select a stack frame |
dis / en / d | Disable / enable / delete a breakpoint |
u | Refresh display (while stopped) |
4. Test Automation: Button Injection
btn <keys...> [duration] Inject coloX button input
btn 0 Stop injection
btn Query current state (physical + injected)
- Key names (case-insensitive, matching the 8
btn()positions):X Y A B CENTER LEFT RIGHT SYS; decimal/0xmasks are also accepted. - Duration: a plain number means frames; a number with
msmeans milliseconds (converted to frames using cartridge target FPS, rounded up); no duration = held untilbtn 0.
btn LEFT A 30 # Hold Left+A for 30 frames
btn LEFT 500ms # Hold Left for 500ms
btn SYS 1 # Hold SYS for one frame (open the system menu)
btn 0 # Stop
Injection behaves exactly like physical buttons: btnp() triggers once on the first frame, holding repeats according to the cartridge's
custom repeat settings; SYS triggers for only one frame. Injection overrides only
the specified keys, while other keys continue passing physical input through.
5. Test Automation: Gamepad Injection
padset <player> <keys...> [duration] Inject input into a player's gamepad slot
padset <player> 0 Stop injection into that slot
padset Query injection state for every slot
- Key names come from the
PADtable ofusemod('pad'):A B X Y L R L2 R2 L3 R3 UP DOWN LEFT RIGHT SELECT START MENU, or a numeric mask. - This command exists only in builds with gamepad support.
- Injects only buttons and connection state; sticks remain centered.
pad_state/pad_btn/pad_stickand the emulator's 2P path all see it—test player 2 without connecting a gamepad (NES two-player mode, gamepad input merging).
padset 1 START 1 # Press Start for one frame on player 2
padset 0 LEFT A 60 # Hold Left+A for one second on player 1 (60fps)
6. Test Automation: Mouse/Touch and Keyboard Injection
mouse <x> <y> [buttons] [duration] Inject mouse/touch position and button state
mouse 0 Stop injection
mouse Query
key <keyname> [duration] Inject a held key
key 0 Stop injection
key Query
- Coordinates use the cartridge VM coordinate system (as read by cartridge
mouse()), not host screen pixels; buttonsis a bitmask; bit 0 = left button/touch pressed, used for simulated touch clicks (middle/right bits match host mouse state);- Duration follows
btn: frames /mssuffix / omitted = held until stopped; physical input resumes automatically on the next frame after stopping; keyinjects a held state, with a string key name (a,up, etc.), read by the cartridge keyboard API; the cartridge's own semantics determine whether it is newly pressed.
mouse 240 120 # Move to the center and hold (not pressed)
mouse 240 120 1 30 # Hold a touch at the center for 30 frames
mouse 100 200 1 500ms # Hold for 500ms
key a 500ms # Hold a for half a second
mouse 0 # Stop (restore both position and buttons)
7. Test Automation: Screenshots
shot # Save coloX_shot_<frame>.bmp in the working directory
shot /tmp/a.bmp # Specify a path (spaces allowed)
- 24bit BMP; resolution/bit depth follow the cartridge spec (1/2/4/8/16/32bpp supported).
- Colors use the same source as the screen (including
pal()changes), independent of host scaling/round cropping; comparison concerns what the cartridge actually drew. - Responses contain pixel data md5, usable directly in CI golden-image comparisons without reading the file:
>-> shot
shot: /tmp/a.bmp 480x480 bpp=4 md5=5f2a...c901 frame=1234
<-< shot
8. Querying Input State
input?
All in one view: frame/FPS/cartridge name, btn() positions (merged physical and injected states), mouse
(including injection state), keyboard, and each gamepad slot (connection/buttons/sticks/injection):
frame=1234 fps=target_fps cart=mygame.clx
KDown=0x20 KHeld=0x20 [LEFT ] inj=0x20 left=18
mouse=240,130 btn=0x00 hotid=0
kb=0 key='' inj(mouse)=240,130,0x01 left=15 inj(key)='' left=0
pad0: conn=1 down=0x0 lx=0 ly=0 rx=0 ry=0 inj=0x0
pad1: conn=0 down=0x0 lx=0 ly=0 rx=0 ry=0 inj=0x10
9. Example Session
$ nc 127.0.0.1 3563
vmlist
vm 1
btn RIGHT 90
shot /tmp/menu_open.bmp
mouse 240 120 1 15 # Tap the center
btn 0
input?
10. Behavior and Boundaries
- Commands are processed at frame boundaries: once before each frame begins and once after drawing;
injection commands (
btn/padset) take effect that frame, and screenshots capture complete frames. - Injection is frame-exact: it occurs after physical input is committed for that frame and before cartridge code reads
btn(), with no window for observing a partially updated state. - Injection applies only to frames with input: while paused or without button permissions, all input is empty, so injection also has no effect (consistent with that frame having no input).
- Injection is consistent across hosts: it acts directly on the VM's button channel, with identical desktop/device/web behavior regardless of host input peripherals.
- md5 definition: pixel data bytes (BGR, 4-byte row alignment, BMP bottom-up storage), excluding the file header; the same image has the same md5 across platforms unless palettes differ.
- A target VM stopped at a breakpoint still processes commands.