sequenceDiagram
    participant UI as MainActivity (save/load button)
    participant Pending as g_pending_save_state / g_pending_load_state
    participant Refresh as video_canvas_refresh (VICE thread)
    participant Trap as interrupt_maincpu_trigger_trap
    participant CPU as 6510core.c DO_INTERRUPT(IK_TRAP)

    UI->>Pending: saveState(path) / loadState(path)  [mutex-guarded]
    Refresh->>Pending: drain pending path next frame
    Refresh->>Trap: schedule save_state_trap / load_state_trap
    CPU->>CPU: EXPORT_REGISTERS()
    CPU->>Trap: run trap function
    Trap->>Trap: machine_write_snapshot() / machine_read_snapshot()
    CPU->>CPU: IMPORT_REGISTERS()
    Note over CPU: reg_pc now matches the saved/restored maincpu_regs.pc
