-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp-cntrl.asm
More file actions
148 lines (123 loc) · 2.1 KB
/
p-cntrl.asm
File metadata and controls
148 lines (123 loc) · 2.1 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
;;; -*- TI-Asm -*-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Control Structure Primitives
;;;
;; RUN:
;;
;; RUN instructionlist
;;
;; Evaluate the instructions in the input list.
p_RUN:
BUILTIN_PRIMITIVE 1, 1, 1, "l$"
call PopOPS
jp EvalTail
;; IF:
;;
;; IF condition instructionlist
;;
;; If :condition is true, run :instructionlist.
p_IF:
BUILTIN_PRIMITIVE 2, 2, 2, "Bl$"
call Pop2OPS
ld a,l
or a
jp z,ReturnVoid
ex de,hl
jp EvalTail
;; IFELSE:
;;
;; IFELSE condition instructionlist1 instructionlist2
;;
;; If :condition is true, run instructionlist1; if it is false, run
;; instructionlist2.
p_IFELSE:
BUILTIN_PRIMITIVE 3, 3, 3, "Bll$"
call Pop3OPS
ld a,l
ld h,b
ld l,c
or a
jr z,IFELSE_False
ex de,hl
IFELSE_False:
jp EvalTail
;; REPEAT:
;;
;; REPEAT number instructionlist
;;
;; Run :instructionlist repeatedly, :number times.
p_REPEAT:
BUILTIN_PRIMITIVE 2, 2, 2, "Il$"
call Pop2OPS ; HL = count, DE = list
ld a,h
or l
jp z,ReturnVoid
REPEAT_Loop:
dec hl
ld a,h
or l
jr z,REPEAT_Last
call PushOPS ; push count
ex de,hl
call PushOPS ; push list
call EvalRecursiveVoid
call Pop2OPS ; HL = count, DE = list
jr REPEAT_Loop
REPEAT_Last:
ex de,hl
jp EvalTailVoid
;; STOP:
;;
;; STOP
;;
;; End the current procedure immediately, without outputting anything.
p_STOP:
BUILTIN_PRIMITIVE 0, 0, 0, ""
ld hl,voidNode
jr OUTPUT_Value
;; OUTPUT:
;;
;; OUTPUT thing
;; OP thing
;;
;; End the current procedure immediately, and output :thing.
p_OUTPUT:
BUILTIN_PRIMITIVE 1, 1, 1, ""
call PopOPS
OUTPUT_Value:
ld sp,(mainSP)
push hl
ld hl,(evalProcTop)
ld a,h
or l
jr z,OUTPUT_Error
ld de,(OPBase)
add hl,de
ld (OPS),hl
pop hl
jp Eval_ExitProcedure
OUTPUT_Error:
ld hl,EMsg_OnlyInsideProcedure
ld de,(evalNextProc)
ld a,E_Invalid
call ThrowError
;; UNREACHABLE
;; BYE:
;;
;; BYE
;;
;; Exit Logo and return to the calculator homescreen.
p_BYE:
BUILTIN_PRIMITIVE 0, 0, 0, ""
BCALL _JForceCmdNoChar
;; UNREACHABLE
;; IGNORE:
;;
;; IGNORE thing
;;
;; Do nothing.
p_IGNORE:
BUILTIN_PRIMITIVE 1, 1, 1, ""
call PopOPS
jp ReturnVoid