BitMagic The Complete Development Environment for the Commander X16.

Remote Debugging

You can debug a program running on a real X16 from VSCode, the same way you’d debug it in the emulator. Set breakpoints on source lines, step, watch your variables and look at memory, while the code runs on the machine itself. The X16 talks to VSCode over its WiFi card.

It’s a separate extension, BitMagic X16 Remote. It builds your BitMagic project as normal, sends it to the X16 and runs it there.

Why debug on the machine?

The emulator is the quickest way to work, so use it while you can. Some things can only be tested on the real thing, though:

  • Hardware the emulator doesn’t have. An expansion card you’re building, a prototype board, a new peripheral or a revision of an existing one. The emulator can’t run code for hardware it knows nothing about, but the X16 can, and now you can step through that code as it talks to the hardware. See Debugging New Hardware.
  • Behaviour the emulator gets wrong, or doesn’t model: timing, a real SD card, a particular VERA or SMC firmware.
  • Bugs that only happen on the machine. If it works in the emulator and not on the X16, you can now find out why.

What you can do

  • Breakpoints on source lines, and on addresses in the disassembly view.
  • Step into, over and out, continue and pause. The X16’s NMI button stops the program too.
  • Variables in the same layout as the debugger: CPU (registers and flags), Kernal (R0 to R15), Locals and Globals, with your .var and .padvar data typed and read from the X16. Change numbers while it’s stopped.
  • Your hardware’s registers, in an I/O view, for the parts of the I/O area you allow. See Debugging New Hardware.
  • The call stack, from the jsr return addresses on the X16’s stack.
  • Memory and disassembly views, read from the X16, and hovers that show a label’s address and value.
  • The screen is left alone. While it’s stopped, the debugger doesn’t touch VERA, so whatever your program drew is still there.
  • The SD card, in an X16 SD Card view in VSCode’s Explorer, or over FTP from the command line tool. See Files and Unloading.

Getting started

  1. Install BitMagic X16 Remote from the VSCode Marketplace, or from Open VSX for VSCodium. It installs the BitMagic extension too.
  2. Put the debugger on the X16’s SD card with X16 Remote: Write the Debugger to an SD Card. See Setting Up for that and the WiFi card.
  3. On the X16, LOAD "DEBUG.PRG" and RUN. It dials VSCode, and keeps trying until you start debugging.
  4. Open your BitMagic project in VSCode and press F5.

If there’s no launch.json, F5 debugs the folder’s project.json, or the open .bmasm file. To make one, add this:

{
    "type": "x16remote",
    "request": "launch",
    "name": "Debug on the X16",
    "program": "${workspaceFolder}/project.json",
    "stopOnEntry": true
}
Name Type Optional Description
program string false The project.json or .bmasm file to build and debug.
stopOnEntry bool true Stop on the program’s first instruction.
port number true The port the X16 dials. Defaults to the x16remote.port setting, 6464.
ioAccess string array true Parts of the I/O area the debugger may read and write, eg [ "$9f60-$9f6f" ]. None by default. See Debugging New Hardware.

When you stop debugging, the X16 stops your program and waits. Press F5 again and it carries on with the next session, with no need to touch the X16. To take the debugger off the X16, see Files and Unloading.

Trying it without an X16

The BitMagic emulator has the WiFi card too, so you can try the whole thing on one machine. Run the stub project from the extension’s repository, x16/stub/project.json, in the emulator: its DEBUGHOST.TXT makes it dial 127.0.0.1:6464. Then press F5 on your project in a second VSCode window.

What it can’t do

  • Your program can’t use the WiFi card while it’s being debugged, as that’s how it talks to VSCode.
  • Time doesn’t stop. While the program is stopped, timers, audio and your hardware carry on, and interrupts that come in are lost rather than replayed.
  • It needs the IRQ, BRK and NMI vectors. A program that replaces them takes the debugger with it. How It Works lists everything it uses.
  • Breakpoints can’t go in ROM, and stepping treats a jsr into ROM as a single step.
  • I/O is only read where you say. The memory view, variables and watches skip $9f00 to $9fff, as reading a register can change it, unless you list a range in ioAccess. The WiFi card is always off limits. See Debugging New Hardware.

So far it’s been tested against the emulator’s WiFi card. If something doesn’t work on your X16, let me know.