BitMagic The Complete Development Environment for the Commander X16.

Prog8

You can debug Prog8 programs for the X16 in VSCode at the level of the Prog8 source: breakpoints on Prog8 lines, stepping a line at a time, the call stack of subroutines, and your variables shown with their real types. The programs are compiled with Prog8 and run on the BitMagic emulator.

It’s a separate extension, BitMagic X16 Prog8, built on the debugger. Prog8 doesn’t write debug information as such, so the debugger puts it together from what the compiler leaves behind: the source lines it writes into the assembly, the assembler’s listing and labels, and its dump of the variables.

What you can do

  • Breakpoints on Prog8 lines, with conditions (i == 5), hit counts and log points (i is {i}). A %breakpoint in your program stops too.
  • Step a line at a time: into, over and out. Calls into the Prog8 library run through, or you can step into it with its source.
  • The call stack shows each subroutine and the line it’s on, nested subroutines included.
  • Variables with their real types: signed and unsigned bytes and words, longs, floats, bools, strings (PETSCII or ISO), arrays (in pages, with split word arrays put back together), pointers and structs. Constants show their values.
  • Watches and hovers take Prog8 expressions: points[i].x, ptr^^, total as uword * 2, lsb(w), len(name).
  • Change a variable while stopped.
  • Stop on a BRK at the Prog8 line it was on.
  • See the X16’s screen in a VSCode tab, and type into it.

Compiler errors and warnings show in the Problems view.

Getting started

Prog8 needs Java 17 or later and the 64tass assembler, so install those first if you haven’t already. The extension finds them on your PATH, or you can tell it where they are in Settings.

  1. Install BitMagic X16 Prog8 from the VSCode Marketplace, or from Open VSX for VSCodium. It installs the BitMagic extension too, if you don’t have it already.
  2. Open a folder with a .p8 file.
  3. Press F5.

The file is compiled into a build folder next to it, loaded into the emulator and run. If the Prog8 compiler isn’t installed, the extension offers to download it.

Here’s something to try it on:

%import textio
%zeropage basicsafe

main {
    sub start() {
        uword total
        ubyte i
        for i in 0 to 3 {
            total += square(i)   ; put a breakpoint here
        }
        txt.print_uw(total)
    }

    sub square(ubyte n) -> uword {
        return n as uword * n
    }
}

Put a breakpoint on the total += square(i) line, press F5, and you’ll stop with total and i in the Variables pane. Press F11 to step into square, and the call stack shows it called from main.start.

There’s a slightly bigger example in a project the extension can make.

Creating a project

To start from scratch, let the extension write a project for you:

  1. Run X16 Prog8: Create X16 Prog8 Project from the command palette (Ctrl+Shift+P). With no folder open, there’s also a Create X16 Prog8 Project button in the Explorer.
  2. Pick a folder for it, an empty one or one you’ve just made.
  3. The folder opens, in a new window if you already had one open.

It writes three files:

File What it is
main.p8 A small program with a struct, an array, a subroutine and a loop, to try breakpoints, stepping and the Variables pane on.
.vscode/launch.json A launch configuration that compiles and debugs main.p8.
.gitignore Leaves the build folder out of git, as it’s all made again on each build.

Files that are already there are left alone, and you’re told which. Open main.p8, set a breakpoint and press F5.

The launch.json is the simplest there is:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "prog8",
            "request": "launch",
            "name": "Debug main.p8 on the X16",
            "program": "${workspaceFolder}/main.p8"
        }
    ]
}

You don’t need one to debug a Prog8 file (F5 works without), but it’s where you add settings such as extra compiler arguments.

Find out more

  • Debugging: breakpoints, stepping, the call stack, variables and watches, and what Prog8 does that you’ll notice.
  • Settings: the launch.json settings, the extension’s own, and the tools it uses.

The debugger is made and tested with Prog8 12.3.5, which is what the extension downloads. Other versions may work, but the files it reads aren’t a fixed format, so a newer Prog8 can change them.