; ============================================================================= ; 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 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 .parent .child ld de, .cmsg ld b, 1 ld c, SYS_WRITE rst $30 ld c, SYS_YIELD rst $30 jr .child .pmsg db "P" .cmsg db "C"