From ef88f0e530b898ebcb14f9e3dff1d58e83089ada Mon Sep 17 00:00:00 2001 From: user Date: Thu, 16 Jul 2026 00:49:58 +0200 Subject: C toolchain: run SDCC-compiled C programs as gbos processes - c/{gbos.h,crt0.s,libc.s,build.sh}: SDCC sm83 -> ROM-bank blob toolchain. libc syscall wrappers save/restore BC/DE/HL around rst $30 (trap clobbers them; SDCC expects them preserved). - build via SDCC native asxxxx path (sdasgb/sdldgb), crt0 linked first so _start is the $4000 entry; blob INCBIN'd into a ROM bank. - chello.c: prints a message + getpid() -> runs as 'chello' shell command. - Makefile: auto-build c/*.bin, track as a dep of programs.o; gitignore blobs. - README: document the C toolchain + the SDCC --asm=rgbds codegen bug that forced the native-toolchain approach. - verified: '$ chello' -> 'hello from C on gbos!' / 'my pid is 2'. --- Makefile | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 23551ad..ad14afd 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,13 @@ all: $(ROM) $(BUILD)/%.o: src/%.asm | $(BUILD) rgbasm $(ASFLAGS) -o $@ $< +# C programs: compiled with SDCC into ROM-bank blobs and INCBIN'd by programs.asm +CBLOBS := c/chello.bin +$(BUILD)/programs.o: $(CBLOBS) + +c/%.bin: c/%.c c/crt0.s c/libc.s c/build.sh + sh c/build.sh $< $@ + $(ROM): $(OBJS) rgblink -m $(BUILD)/gbos.map -n $(BUILD)/gbos.sym -o $@ $(OBJS) rgbfix $(FIXFLAGS) $@ -- cgit v1.3.1-sl0p