aboutsummaryrefslogtreecommitdiffstats
path: root/src/tasks.asm
blob: 0b5276d9e48f408c05a7d6d1cde389e3c419bb8f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
; =============================================================================
; tasks.asm - the init task demonstrates fork() + exec().
;
; init forks; the parent exec()s PROG_PING (ROM bank 2), the child exec()s
; PROG_PONG (ROM bank 3). Both program images are ORG'd at $4000, so the output
; "1212..." proves each process runs from its own ROM bank via PROC_ROMB - not
; from shared ROM0.
; =============================================================================
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 b, PROG_PING
    ld c, SYS_EXEC
    rst $30                 ; never returns

.child
    ld b, PROG_PONG
    ld c, SYS_EXEC
    rst $30                 ; never returns