Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Reverse debugging

Copperline supports reverse stepping and reverse execution. Because emulation is deterministic, the emulator maintains a ring of in-memory snapshots (see save states) and reconstructs earlier execution states by restoring the nearest preceding snapshot and replaying forward to the exact requested instruction or beam cycle.

Reverse debugging is available through:

Headless “last writer” reverse watchpoints

When diagnosing memory corruption or unexpected state transitions, a reverse watchpoint identifies the instruction that last wrote to a target memory location.

Set COPPERLINE_DBG_RWATCH to the target address and COPPERLINE_DBG_UNTIL to the time at which the check should run:

RUST_LOG=info \
COPPERLINE_RTC_FIXED_SECS=1000000000 \
COPPERLINE_DBG_RWATCH=DE488 \
COPPERLINE_DBG_UNTIL=12.5 \
./target/release/copperline --config demo.toml --noaudio \
  --screenshot-after 13 /tmp/out.png

Example log output:

DBG RWATCH last writer of $0DE488: CAFE->0000 by pc=0x00FA37D8 pos=561401 f=40 cck=2864664

The output identifies the program counter (PC), value before and after the write, video frame, and colour-clock cycle of the write.

Environment variables

Interactive reverse controls

In the debugger window, reverse transport controls are located on the right:

ButtonFunction
< FrameStep backward to previous video frame
< StepStep backward by one CPU instruction
< RunRun backward until a breakpoint or watchpoint condition is met

< Run (and the console command RRUN) evaluates all active breakpoints, memory watchpoints, Copper breakpoints, and custom register traps in reverse order, stopping at the most recent triggering event.

Rewind in normal sessions

Rewind functionality can be used during gameplay:

Determinism requirements for reverse replay

For reverse replay to be exact:

  1. RTC synchronization: Use --rtc-time or COPPERLINE_RTC_FIXED_SECS so time reads do not drift with host wall-clock time.

  2. Deterministic input: Input events must be repeatable (scripted input and recorded interactive inputs are handled automatically).

  3. Storage: RAM contents and floppy disk states are captured directly in memory snapshots. However, hard drive and CD images are accessed live from the host filesystem and are not rolled back on restore; guest disk writes or host-side image modifications occurring after a snapshot point will cause replayed execution to diverge.