Skip to content

C Programs

WacKEDmaN edited this page Oct 31, 2026 · 2 revisions

C programs

The assembler window also builds C programs. Open a .c file as a program: F9 then builds it with a C compiler instead of RASM.

What you need

  • SDCC (sdcc.sourceforge.net). It is not included: install it.
  • Optional: CPCtelera (the cpctelera_next branch): its library and its asset tools. You do not need Cygwin, make or bash: the program builds the library once from its src folder.
  • Or z88dk (z88dk.org) as the compiler in place of SDCC.

C settings

C settings... (in the assembler window's toolbar, for a .c program):

Setting What it is
Compiler SDCC / CPCtelera or z88dk
SDCC folder Empty: C:\Program Files\SDCC, or the PATH
CPCtelera folder Empty: plain SDCC, no library. It must have src/cpctelera.h.
Code address Where the code goes (hex). A CPCtelera project's cfg/build_config.mk (Z80CODELOC) wins.
Extra sdcc flags More options for sdcc
z88dk folder Empty: C:\z88dk, beside the program, or the PATH
Compile with zsdcc z88dk's SDCC: C lines can be stepped in the debugger. Off: z88dk's own sccz80 (no line stepping).
Extra zcc flags More options for zcc

The settings line shows if each tool was found.

Build and run

Button Key What it does
Build F9 Saves the edited tabs of the program, then builds it on a background thread. The window stays usable.
Build + run Ctrl+F9 Builds, then runs the program from BASIC, as a real CPC runs a binary
Run to cursor Ctrl+F10 Runs to the cursor's C line, past every breakpoint, and pauses there
Convert assets Runs every asset step of a CPCtelera project again
  • Build log shows the commands and what they printed. Errors go to the messages list, on their files' tabs.
  • The .h files that a .c file includes open in tabs after it.

CPCtelera projects

Open the project's src/main.c. The build follows the project's cfg/*.mk files:

  • Asset steps run first: images, Tiled maps, Arkos Tracker 3 music, packed data (zx0, zx1, zx7b) and .bin files. F9 runs only the steps whose outputs are older than their inputs. Convert assets runs all of them again.
  • The project's disc and tape images (DSK, CDT, FILE2SECTOR) are made as iDSK, cpc2cdt and RASM make them, and an SNA snapshot too.
  • All 58 example projects of CPCtelera's "next" branch build and run.

Debugging C

  • Step a C line: F10 (over), F11 (into), Shift+F11 (out), or the Line, Over and Out buttons.
  • When the machine stops on a C line, its file opens in a tab and the line is marked.
  • Click a line number in the gutter to set or remove a breakpoint on that line's first instruction.
  • Mouse-over a variable or function: its address and value (a byte, a word, a long, or the bytes, from the build's listings).
  • The disassembly in the Debugger window shows the C lines.

Command line

--cbuild <main.c> builds a C project and runs it, with no window (for scripts). Add --cpctelera <folder>, --sdcc <folder>, --codeloc <address>, --force-assets, --z88dk <folder> or --sccz80 as needed. Use it with --shot (refer to Command line).

Clone this wiki locally