-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyield.asm
77 lines (68 loc) · 1.64 KB
/
yield.asm
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
; process control macros
;
#define YIELD call $+3 \ pop de \ jp yield
#define DIE jp dodie
#define DIEZ jp z,dodie
#define DIENZ jp nz,dodie
#define DIEC jp c,dodie
#define DIENC jp nc,dodie
dodie:
push iy
pop hl
call unlinkobject
jp resumenext
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;
; yield: the core of the co-operative multitasking 'os' at the
; heart of the game. allows game entities to be written in a
; 'linear' fashion, without having to worry about state. yield
; simply stores the return address in the object's struct, and
; resumes execution at the next object's saved execution address.
; neat and effective. called from the YIELD macro, which does the
; relevant return-address pickling.
;
; [in] iy: points at the object's storage
; [out]: nothing
; preserves: nothing
;
yield:
; on entry de points to the 'pop de' instruction in the YIELD macro
; adjust it so that it points to the instruction after the jump: in other
; words, the resume address for the function.
;
inc de
inc de
inc de
inc de
; store 'return' address held in de in o->OPC
;
ld (IY+OPC),e
ld (IY+OPC+1),d
resumenext:
; get next object from o = o->ONEXT in hl
;
ld l,(IY+ONEXT)
ld h,(IY+ONEXT+1)
push hl
pop iy
; make a courtesy pointer to the object's OUSER (private store) area
;
ld bc,OUSER
add hl,bc
ld (PSTORE),hl
; keep count of the number of objects which have YIELDed,
; and the maximum encountered so far
;
ld hl,ocount
inc (hl)
ld a,(hl)
inc hl
cp (hl)
jr c,{+}
ld (hl),a
+:
; now resume executing at the object's saved address
;
ld l,(IY+OPC)
ld h,(IY+OPC+1)
jp (hl)