Minimal ZX Spectrum 48K C project with Docker-based SDCC builds, using a custom crt0 and SDCC's default z80 libraries.
- Builds inside Docker (no local SDCC install required).
- Uses SDCC for compile + link (no generated linker script).
- Uses
--code-locto place code at a chosen load address. - Uses
--no-std-crt0and provides our own startup insrc/crt0.s. - Uses SDCC libc (
printf,puts,malloc, etc.) with platform hooks implemented incrt0.s.
make runs the build in Docker using image wischner/sdcc-z80-zx-spectrum:latest.
makeOutput artifacts:
build/<TARGET>/<TARGET>.ihxbuild/<TARGET>/<TARGET>.binbin/<TARGET>.tap
Default target name is zxspec48-app.
Change program name:
make TARGET=myappChange load address used for linking and TAP header:
make LOAD_ADDR_HEX=0x9000src/crt0.s is the runtime glue between ZX ROM and SDCC libc:
- Saves registers and sets a private stack.
- Opens Spectrum stream channel (
CHAN-OPEN) so console I/O goes to screen. - Runs SDCC GSINIT (global/static initialization) and calls
___sdcc_heap_init. - Calls
_main. - Restores registers and returns.
It also provides symbols required by SDCC library:
- Heap symbols:
___sdcc_heap(heap start, in_HEAP)___sdcc_heap_end = 0xffff(heap end)
- Stdio hooks:
_putchar(ROMRST 0x10)_getchar(ROM key input routine)
Because these hooks are present, standard C I/O from SDCC libc links and runs against Spectrum ROM services.
Makefile: host/Docker entrypoint.src/Makefile: compile/link pipeline (.c/.s -> .rel -> .ihx -> .bin -> .tap).src/crt0.s: startup + SDCC runtime hooks.src/main.c: sample C program using stdio.
A .vscode setup is included for emulator launch. If GUI access from Docker is needed, allow X access first:
xhost +SI:localuser:$(whoami)