; ============================================================================= ; programs.asm - userland program images (text-in-ROM model). ; ; Programs are linked to run from the ROMX window ($4000-$7FFF) and live in ; their own ROM banks. exec() maps the bank and jumps to the entry. Programs ; only talk to the kernel via `rst $30` (the trap + kernel live in ROM0, always ; mapped), so they never reference kernel labels. ; ============================================================================= INCLUDE "include/gbos.inc" ; ----------------------------------------------------------------------------- ; PROG_WORKER: announce with 'w', then exit() with a status equal to our pid. ; Exercises exec (runs from a ROM bank) + the exit/wait lifecycle. ; ----------------------------------------------------------------------------- SECTION "prog_worker", ROMX[$4000], BANK[2] ProgWorker: ld de, .msg ld b, 1 ld c, SYS_WRITE rst $30 ld c, SYS_GETPID rst $30 ld b, a ; exit status = pid (so reaped codes are distinct) ld c, SYS_EXIT rst $30 ; never returns .msg db "w" ; ----------------------------------------------------------------------------- ; Program table (ROM0). Indexed by exec()'s program id. ; Entry: bank (2 bytes, MBC5 16-bit) then entry address (2 bytes). ; ----------------------------------------------------------------------------- SECTION "progtab", ROM0 ProgramTable:: db LOW(BANK(ProgWorker)), HIGH(BANK(ProgWorker)) dw ProgWorker