-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.asm
More file actions
171 lines (156 loc) · 1.98 KB
/
Copy pathstack.asm
File metadata and controls
171 lines (156 loc) · 1.98 KB
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
;;; -*- TI-Asm -*-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Stack Management
;;;
;; PushOPS:
;;
;; Push a value on the Operator Stack.
;;
;; Input:
;; - HL = value
;;
;; Destroys:
;; - F
PushOPS:
push de
push hl
PushOPS_TryAgain:
ld hl,(FPS)
ld de,(OPS)
dec de
or a
sbc hl,de
jr nc,PushOPS_OutOfMem
PushOPS_AllIsWell:
ifdef STACK_DEBUG
ld hl,(minOPS)
or a
sbc hl,de
jr c,PushOPS_NoSetMin
ld (minOPS),de
PushOPS_NoSetMin:
endif
ex de,hl
pop de
ld (hl),d
dec hl
ld (hl),e
ld (OPS),hl
ex de,hl
pop de
ret
PushOPS_OutOfMem:
push bc
push af
call GCRun
pop bc
ld a,b
pop bc
jr c,PushOPS_TryAgain
ld hl,(FPS)
ld de,(OPS)
dec de
or a
sbc hl,de
jr c,PushOPS_AllIsWell
BCALL _ErrMemory
;; UNREACHABLE
;; PopOPS:
;;
;; Pop a value off the Operator Stack.
;;
;; Output:
;; - HL = value
;;
;; Destroys:
;; - F
PopOPS:
push de
ld hl,(OPS)
inc hl
ld de,(OPBase)
or a
sbc hl,de
pop de
jp nc,StackAssertionFailed
PopOPS_nc:
push de
ld hl,(OPS)
ld e,(hl)
inc hl
ld d,(hl)
inc hl
ld (OPS),hl
ex de,hl
pop de
ret
;; Pop2OPS:
;;
;; Pop two values off the Operator Stack.
;;
;; Output:
;; - DE = first value popped
;; - HL = second value popped
;;
;; Destroys:
;; - AF
Pop2OPS:
ld hl,(OPS)
inc hl
inc hl
inc hl
ld de,(OPBase)
or a
sbc hl,de
jp nc,StackAssertionFailed
Pop2OPS_nc:
ld hl,(OPS)
ld e,(hl)
inc hl
ld d,(hl)
inc hl
ld a,(hl)
inc hl
inc hl
ld (OPS),hl
dec hl
ld h,(hl)
ld l,a
ret
;; Pop3OPS:
;;
;; Pop three values off the Operator Stack.
;;
;; Output:
;; - BC = first value popped
;; - DE = second value popped
;; - HL = third value popped
;;
;; Destroys:
;; - AF
Pop3OPS:
ld hl,(OPS)
ld de,5
add hl,de
ld de,(OPBase)
sbc hl,de
jp nc,StackAssertionFailed
Pop3OPS_nc:
ld hl,(OPS)
ld c,(hl)
inc hl
ld b,(hl)
inc hl
ld e,(hl)
inc hl
ld d,(hl)
inc hl
ld a,(hl)
inc hl
inc hl
ld (OPS),hl
dec hl
ld h,(hl)
ld l,a
ret