diff options
| author | user <user@clank> | 2026-07-18 00:38:38 +0200 |
|---|---|---|
| committer | user <user@clank> | 2026-07-18 00:38:38 +0200 |
| commit | ba2d7ae1d7b319645b10aaa31a7f664f9f80c25c (patch) | |
| tree | e01e6c7c710a661defe2515ff9657f08cddcb283 /README.md | |
| parent | tools: gbtype prints hub errors to stderr and exits 1 (diff) | |
| download | gbos-ba2d7ae1d7b319645b10aaa31a7f664f9f80c25c.tar.gz gbos-ba2d7ae1d7b319645b10aaa31a7f664f9f80c25c.tar.xz gbos-ba2d7ae1d7b319645b10aaa31a7f664f9f80c25c.zip | |
refactor: c/ -> usr/, compiled program blobs out of the source tree
Userland sources live in usr/ (fits the Unix theme better than 'c').
SDCC output .bin blobs land in build/usr/ with the other build artifacts
instead of littering the source dir; programs.asm INCBINs them from there.
Byte-identical ROM.
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 20 |
1 files changed, 10 insertions, 10 deletions
@@ -58,7 +58,7 @@ across a syscall (`push hl` / `pop hl`). Libc syscall stubs handle this for C. | 2 | read | ✅ blocking console input (1 byte) via external-clock serial | | 4,5,9,10 | open/close/kill/brk | ⛔ `ENOSYS` | -### The shell (`c/sh.c`) +### The shell (`usr/sh.c`) init `exec`s the shell (written in C). It reads a line, tokenizes it, and runs commands with **I/O redirection and pipes**: @@ -183,15 +183,15 @@ A real gbos would render to VRAM; serial is the zero-VRAM debug channel. ## Writing programs in C gbos programs can be written in **C**, compiled with **SDCC** (the `sm83` port). -This makes porting tiny Unix CLI tools realistic. The toolchain (`c/`): +This makes porting tiny Unix CLI tools realistic. The toolchain (`usr/`): -- `c/gbos.h` — the userland API (`writes`, `readc`, `nl`, `getpid`, `sexit`). -- `c/libc.s` — syscall wrappers (asxxxx asm). Each saves +- `usr/gbos.h` — the userland API (`writes`, `readc`, `nl`, `getpid`, `sexit`). +- `usr/libc.s` — syscall wrappers (asxxxx asm). Each saves `BC/DE/HL` around `rst $30`, since the trap clobbers them but SDCC expects them preserved. -- `c/crt0.s` — entry: `call main`; then `exit(0)`. Linked first so `_start` is +- `usr/crt0.s` — entry: `call main`; then `exit(0)`. Linked first so `_start` is the `$4000` entry. -- `c/build.sh` — compiles a `.c` with SDCC's **native** toolchain +- `usr/build.sh` — compiles a `.c` with SDCC's **native** toolchain (`sdasgb` + `sdldgb`), links code at `$4000`, and extracts the ROM-bank blob. The Makefile INCBINs it and registers it as a program. @@ -206,9 +206,9 @@ void main(void) { ### libc -Syscall wrappers (`c/libc.s`): `writes`, `putc`, `puts`, `nl`, `strlen`, `readc` +Syscall wrappers (`usr/libc.s`): `writes`, `putc`, `puts`, `nl`, `strlen`, `readc` (returns `EOF`=4 at end of input), `getargs` (this program's argument string), -`getpid`, `sexit`. C helpers (`c/libc.c`, linked into every program): `putu` +`getpid`, `sexit`. C helpers (`usr/libc.c`, linked into every program): `putu` (print decimal), `atou` (parse decimal), `argv_parse` (tokenize into argc/argv). Arguments: the shell splits the command line at the first space and leaves @@ -220,7 +220,7 @@ char *argv[8]; unsigned char argc = argv_parse(argv, 8); /* args one two -> argc=3 */ ``` -### CLI tools (in `c/`) +### CLI tools (in `usr/`) | tool | what it does | |------|--------------| @@ -254,7 +254,7 @@ alpha beta ``` -Each tool is a separate `c/<name>.c`, built to a ROM-bank blob, INCBIN'd, and +Each tool is a separate `usr/<name>.c`, built to a ROM-bank blob, INCBIN'd, and registered in the program table + shell command table (`src/programs.asm`). **Toolchain gotchas found the hard way:** SDCC's `--asm=rgbds` mode mis-orders |
