-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathroutines.asc
124 lines (114 loc) · 1.98 KB
/
routines.asc
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
; MSX Block Puzzle game, released as entry for the MSXDev'20
; Created by David Heremans, aka turbor on mrc
;
; a simple task scheduler in the game to allow all the animations etc
; to work as if running in parallel
; you add the routines to be called on a custom stack and remove them when no longer needed
; calling the execroutine will then sequentially call al routines on the stack
;
addroutine: ; in DE routine address
; each routine can be on stack only once!
; {{{
ld hl,routinestack-1
addroutine1:
inc hl
ld a,(hl)
ld c,a
inc hl
ld b,(hl)
ld a,e
cp c
jr nz,addroutine3
ld a,d
cp b
ret z ; routine already in stack!
addroutine3:
ld a,c
or b
jr nz,addroutine1
ld (hl),d
dec hl
ld (hl),e
ret ; assuming next two bytes are still zero!!
; }}}
isonroutinestack: ; in DE routine addres
; returns Z if on stack, NZ if not on stack
; {{{
ld hl,routinestack-1
isonroutinestack1:
inc hl
ld a,(hl)
ld c,a
inc hl
ld b,(hl)
or b
jr z,isonroutinestack5 ; end of stack reached
ld a,e
cp c
jr nz,isonroutinestack1
ld a,d
cp b
ret z ; routine on stack!
jr isonroutinestack1
isonroutinestack5:
xor a
inc a
ret
; }}}
delroutine: ; in DE routine to remove
; {{{
ld hl,routinestack
delroutine1:
ld a,e
cp (hl)
jr nz,delroutine2
inc hl
ld a,d
cp (hl)
jr nz,delroutine3
dec hl
ld e,l
ld d,h
inc hl
inc hl
delroutine4:
ld bc,2
ldir
;if we did not just copy two zero then move again two bytes
push de
push hl
dec de
ld a,(de)
ld l,a
dec de
ld a,(de)
or l
pop hl
pop de
jr nz,delroutine4
ret
delroutine2: inc hl
delroutine3: inc hl
jr delroutine1
; }}}
execroutine:
; {{{
ld hl,routinestack
execroutine1:
ld e,(hl)
inc hl
ld d,(hl)
inc hl
ld a,d
or e
ret z
;else de is a routine to call
push hl
ld hl,execroutine3
push hl
ex de,hl
jp (hl)
execroutine3: pop hl
jr execroutine1
; }}}
; vim:foldmethod=marker:ft=z8a:ts=16