diff options
Diffstat (limited to 'src/tasks.asm')
| -rw-r--r-- | src/tasks.asm | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/src/tasks.asm b/src/tasks.asm index 1f84142..459ccb6 100644 --- a/src/tasks.asm +++ b/src/tasks.asm @@ -1,33 +1,39 @@ ; ============================================================================= -; tasks.asm - two demo userland tasks (text-in-ROM model). -; Each loops: write its letter to the console, then yield. This exercises the -; whole pipeline: syscall trap, console, and the HRAM context switch swapping -; RAM banks / SVBK between tasks. +; tasks.asm - the init task demonstrates fork(). +; init forks once; the parent loops printing 'P', the child loops printing 'C'. +; Both run the same ROM text, diverging on fork()'s return value (0 in child). +; Exercises: syscall trap, fork (8 KiB bank copy + child frame), scheduler, +; and the HRAM context switch swapping cart-RAM banks per task. ; ============================================================================= INCLUDE "include/gbos.inc" SECTION "tasks", ROM0 -TaskA:: -.loop - ld de, .msg - ld b, 1 ; len +TaskInit:: + ld c, SYS_FORK + rst $30 ; A = child pid (parent) or 0 (child) + or a + jr z, .child + +.parent + ld de, .pmsg + ld b, 1 ld c, SYS_WRITE rst $30 ld c, SYS_YIELD rst $30 - jr .loop -.msg - db "A" + jr .parent -TaskB:: -.loop - ld de, .msg +.child + ld de, .cmsg ld b, 1 ld c, SYS_WRITE rst $30 ld c, SYS_YIELD rst $30 - jr .loop -.msg - db "B" + jr .child + +.pmsg + db "P" +.cmsg + db "C" |
