BitMagic X16 Oscar64
Debug C programs for the Commander X16 in VS Code, at the level of the C source. Programs are compiled with Oscar64 and run on the BitMagic emulator.
- Breakpoints on C lines, with conditions (
i == 5), hit counts and log points (i={i}).
- Stepping by C line: into, over and out, through recursion. Stepping into a call to your own assembler stops on its first instruction, and from there you step the 6502.
- The call stack of C functions, each with its line. Runtime and ROM frames are shown too, greyed out, with the disassembly.
- Variables with their real types: integers signed or not, floats, bools, enums by name, pointers (expand to what they point at), arrays (paged), structs. Locals in scope at the line, parameters, the function's statics, and globals. Change them while stopped.
- Watches and hovers take C expressions:
p->next->x, a[i] * 2, *(unsigned int *)&l, sizeof(struct Point), casts and arithmetic with Oscar64's 16 bit int.
- Stop on a BRK at the C line it was on, with the call stack and variables as they were. Continue, and it goes on to the X16's monitor as it would on the machine.
- The X16 Screen tab shows the display and takes your typing, and the X16 Oscar64 Live view shows where the program is and its globals while it runs.
- Compiler errors and warnings go in the Problems view.
- BitMagic's own views (memory, VERA layers, sprites, palette and the rest) work alongside, as they do for assembler.
Getting started
Open a folder with a C file and press F5, or use Debug C File on the X16 from the editor's run button. Or run X16 Oscar64: Create X16 Oscar64 Project for a program to try it on; with no folder open, the Explorer has a button for it too.
The extension compiles with -tm=x16 -g -n -O0 into a build folder next to the program, then debugs the result. If Oscar64 isn't on your PATH (or set in bitMagicX16Oscar64.compilerPath), it offers to download it.
To debug a .prg you've built yourself, point program at it. It needs Oscar64's -g, which writes the .dbj debug information next to it.
{
"type": "oscar64",
"request": "launch",
"name": "Debug C on the X16",
"program": "${workspaceFolder}/main.c"
}
| Option |
|
program |
The C file to compile, or a .prg with its .dbj. |
compile |
Compile first (default true). |
compilerArgs |
Extra Oscar64 arguments, added to the bitMagicX16Oscar64.compilerArgs setting. An -O option replaces -O0. |
outputFolder |
Where the .prg and .dbj go; build next to the program by default. |
project |
A BitMagic project.json to take the ROM, SD card and so on from. |
stopOnEntry |
Stop on main's first line. |
run |
Load the program at BASIC's READY and RUN it (default true). |
onProgramEnd |
ready (default) or terminate when main returns. |
renderOnStop |
Draw the whole screen when stopping, so output shows straight away (default true). |
romFile |
The ROM to use, if not BitMagic's. |
sourceFolder |
Where to find sources when the .dbj's paths don't exist here. |
Commands and settings
| Command |
|
| Debug C File on the X16 |
Compile the open C file and debug it. Also on the editor's run button. |
| Run C File on the X16 |
The same, without debugging. |
| Compile C File with Oscar64 |
Just compile, with the messages in the Problems view. |
| Show the X16 Screen |
Open the X16 Screen tab. |
| Create X16 Oscar64 Project |
Write a main.c and launch.json into a folder, to try it on. Also in the Explorer when no folder is open. |
| Setting |
|
bitMagicX16Oscar64.compilerPath |
oscar64.exe, or the folder it's in. If empty, oscar64 on the PATH, or else the extension offers to download it. |
bitMagicX16Oscar64.compilerArgs |
Oscar64 arguments for every build, eg ["-i=include"]. |
bitMagicX16Oscar64.showRunButtons |
Show the Debug and Run buttons in the editor title for C files (default true). |
bitMagicX16Oscar64.openScreen |
Open the X16 Screen tab when a program starts debugging (default true). |
bitMagicX16Oscar64.debugModePath |
A debugger build to use instead of the extension's, for working on the debugger. |
Good to know
- Build with
-O0 (the default here). With optimisation Oscar64 inlines functions and keeps locals in registers, so they can't be shown, and stepping jumps about.
- Even at
-O0 Oscar64 reorders a little: in a for loop the increment can run before the body's first line, so the loop variable already reads one more.
- A function with one parameter gets it in the A and X registers, so after the first line it's shown as "not available".
- Bytecode (
-bc) can't be debugged. You'll get a warning listing the bytecode functions; __native functions in a bytecode build still can be.
- Unions are shown as bytes, as Oscar64 doesn't describe their members.
- Open Disassembly View on a C frame shows its machine code, but not yet with the C lines between the instructions or the C names of globals. Stepping there still goes a C line at a time; single instruction steps work once you're in your own assembler.
Requirements
The BitMagic extension, which is installed with this one, and Windows for the downloaded Oscar64 (elsewhere, build Oscar64 and set bitMagicX16Oscar64.compilerPath).
Licence
GPL-3.0, the same as BitMagic.
| |