-
Notifications
You must be signed in to change notification settings - Fork 0
/
68KRPN.tcl
409 lines (401 loc) · 6.4 KB
/
68KRPN.tcl
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
# TI 68K RPN parser HexFiend template include
# Version 1.1
# (c) 2021-2024 LogicalJoe
# .hidden = true;
proc 68KRPN {size} {
proc Recursive_RPN {{expression ""} {start 0}} {
set 68KRPN_TAGS [dict create \
0x00 VAR_NAME \
0x01 _VAR_Q \
0x02 VAR_R \
0x03 VAR_S \
0x04 VAR_T \
0x05 VAR_U \
0x06 VAR_V \
0x07 VAR_W \
0x08 VAR_X \
0x09 VAR_Y \
0x0A VAR_Z \
0x0B VAR_A \
0x0C VAR_B \
0x0D VAR_C \
0x0E VAR_D \
0x0F VAR_E \
0x10 VAR_F \
0x11 VAR_G \
0x12 VAR_H \
0x13 VAR_I \
0x14 VAR_J \
0x15 VAR_K \
0x16 VAR_L \
0x17 VAR_M \
0x18 VAR_N \
0x19 VAR_O \
0x1A VAR_P \
0x1B VAR_Q \
0x1C EXT_SYSTEM \
0x1D ARB_REAL \
0x1E ARB_INT \
0x1F POSINT \
0x20 NEGINT \
0x21 POSFRAC \
0x22 NEGFRAC \
0x23 FLOAT \
0x24 PI \
0x25 EXP \
0x26 IM \
0x27 NEGINFINITY \
0x28 INFINITY \
0x29 PN_INFINITY \
0x2A UNDEF \
0x2B FALSE \
0x2C TRUE \
0x2D STR \
0x2E NOTHING \
0x2F ACOSH \
0x30 ASINH \
0x31 ATANH \
0x32 ASECH \
0x33 ACSCH \
0x34 ACOTH \
0x35 COSH \
0x36 SINH \
0x37 TANH \
0x38 SECH \
0x39 CSCH \
0x3A COTH \
0x3B ACOS \
0x3C ASIN \
0x3D ATAN \
0x3E ASEC \
0x3F ACSC \
0x40 ACOT \
0x41 RACOS \
0x42 RASIN \
0x43 RATAN \
0x44 COS \
0x45 SIN \
0x46 TAN \
0x47 SEC \
0x48 CSC \
0x49 COT \
0x4A ITAN \
0x4B ABS \
0x4C ANGLE \
0x4D CEILING \
0x4E FLOOR \
0x4F INT \
0x50 SIGN \
0x51 SQRT \
0x52 EXPF \
0x53 LN \
0x54 LOG \
0x55 FPART \
0x56 IPART \
0x57 CONJ \
0x58 IMAG \
0x59 REAL \
0x5A APPROX \
0x5B TEXPAND \
0x5C TCOLLECT \
0x5D GETDENOM \
0x5E GETNUM \
0x5F ERROR \
0x60 CUMSUM \
0x61 DET \
0x62 COLNORM \
0x63 ROWNORM \
0x64 NORM \
0x65 MEAN \
0x66 MEDIAN \
0x67 PRODUCT \
0x68 STDDEV \
0x69 SUM \
0x70 REF \
0x71 IDENTITY \
0x72 DIAG \
0x73 COLDIM \
0x74 ROWDIM \
0x75 TRANSPOSE \
0x76 FACTORIAL \
0x77 PERCENT \
0x78 RADIANS \
0x79 NOT \
0x7A MINUS \
0x7B VEC_POLAR \
0x7C VEC_CYLIND \
0x7D VEC_SPHERE \
0x7E START \
0x7F ISTORE \
0x80 STORE \
0x81 WITH \
0x82 XOR \
0x83 OR \
0x84 AND \
0x85 LT \
0x86 LE \
0x87 EQ \
0x88 GE \
0x89 GT \
0x8A NE \
0x8B ADD \
0x8C ADDELT \
0x8D SUB \
0x8E SUBELT \
0x8F MUL \
0x90 MULELT \
0x91 DIV \
0x92 DIVELT \
0x93 POW \
0x94 POWELT \
0x95 SINCOS \
0x96 SOLVE \
0x97 CSOLVE \
0x98 NSOLVE \
0x99 ZEROS \
0x9A CZEROS \
0x9B FMIN \
0x9C FMAX \
0x9D COMPLEX \
0x9E POLYEVEL \
0x9F RANDPOLY \
0xA0 CROSSP \
0xA1 DOTP \
0xA2 GCD \
0xA3 LCM \
0xA4 MOD \
0xA5 INTDIV \
0xA6 REMAIN \
0xA7 NCR \
0xA8 NPR \
0xA9 P2RX \
0xAA P2RY \
0xAB P2PTHETA \
0xAC P2PR \
0xAD AUGMENT \
0xAE NEWMAT \
0xAF RANDMAT \
0xB0 SIMULT \
0xB1 PART \
0xB2 EXP2LIST \
0xB3 RANDNORM \
0xB4 MROW \
0xB5 ROWADD \
0xB6 ROWSWAP \
0xB7 ARCLEN \
0xB8 NINT \
0xB9 PI_PRODUCT \
0xBA SIGMA_SUM \
0xBB MROWADD \
0xBC ANS \
0xBD ENTRY \
0xBE EXACT \
0xBF LOGB \
0xC0 COMDENOM \
0xC1 EXPAND \
0xC2 FACTOR \
0xC3 CFACTOR \
0xC4 INTEGRATE \
0xC5 DIFFERENTIATE \
0xC6 AVGRC \
0xC7 NDERIV \
0xC8 TAYLOR \
0xC9 LIMIT \
0xCA PROPFRAC \
0xCB WHEN \
0xCC ROUND \
0xCD DMS \
0xCE LEFT \
0xCF RIGHT \
0xD0 MID \
0xD1 SHIFT \
0xD2 SEQ \
0xD3 LIST2MAT \
0xD4 SUBMAT \
0xD5 SUBSCRIPT \
0xD6 RAND \
0xD7 MIN \
0xD8 MAX \
0xD9 LIST \
0xDA USERFUNC \
0xDB MATRIX \
0xDC FUNC \
0xDD DATA \
0xDE GDB \
0xDF PIC \
0xE0 TEXT \
0xE1 FIG \
0xE2 MAC \
0xE3 EXT \
0xE4 EXTR_INSTR \
0xE5 END \
0xE6 COMMENT \
0xE7 NEXTEXPR \
0xE8 NEWLINE \
0xE9 ENDSTACK \
0xEA PN1 \
0xEB PN2 \
0xEC ERROR_MSG \
0xED EIGVC \
0xEE EIGVL \
0xEF DASH \
0xF0 LOCALVAR \
0xF1 DESOLVE \
0xF2 FDASH \
0xF3 ASM \
0xF4 ISPRIME \
0xF8 OTH \
0xF9 ROTATE \
]
set tag_type [hex 1]
set tag_name [entryd TAG $tag_type 1 $68KRPN_TAGS]
move -2
switch $tag_name {
EXT_SYSTEM { #1C
hex 1 "Sys token"
move -2
}
ADD -
SUB -
MUL -
DIV -
POW {
# Two arguments
set expression $tag_name$expression
section $tag_name
set expression [Recursive_RPN $expression]
set expression [Recursive_RPN $expression]
endsection
}
COS -
SIN -
SQRT -
LOCALVAR -
MINUS {
# one argument
set expression $tag_name$expression
section $tag_name
set expression [Recursive_RPN $expression]
endsection
}
NEGINT -
POSINT {
# integer
section $tag_name
set num_bytes [hex 1 S_$tag_name]
move -$num_bytes
move -1
if {$num_bytes} {
set expression [hex $num_bytes $tag_name]$expression
move -$num_bytes
move -1
} else {
entry $tag_name 0
}
endsection
}
MAX -
MIN -
LIST {
# list ending with END
section $tag_name
while {[hex 1] != 0xE5} {
move -1
set expression [Recursive_RPN $expression]
}
move -1
set expression [Recursive_RPN $expression]
endsection
}
STR -
VAR_NAME {
# \0 name \0
section $tag_name
move -1
while {[int8]} {move -2}
set start [pos]
cstr ascii STR
goto $start
move -2
endsection
}
FLOAT {
move -8
hex 9 FLOAT
move -10
}
FUNC {
section $tag_name
hex 1 Flags
# 0x40 for tokenized, 0x08 for untokenized
# assume tokenized for now
move -3
hex 2 NULLs
move -3
# loop to ENDSTACK TAG
while {[hex 1] != 0xE9} {
move -1
set expression [Recursive_RPN $expression]
}
move -1
set expression [Recursive_RPN $expression]
# this is present in fargo programs
if {[pos] > $start} {
move 1
set t [expr [pos]-$start]
goto $start
bytes $t "Excess data"
}
endsection
}
STORE {
# variable then expression (could be "Two arguments")
section $tag_name {
section "variable" {
set expression [Recursive_RPN $expression]
}
section "expression" {
set expression [Recursive_RPN $expression]
}
}
}
EXTR_INSTR {
# BASIC ITAG
set ITAG [hex 1 "BASIC ITAG"]
move -2
if {$ITAG in {0x7B 0x7D}} {
section "ITAG $ITAG"
# loop to END TAG
while {[hex 1] != 0xE5} {
move -1
set expression [Recursive_RPN $expression]
}
move -1
set expression [Recursive_RPN $expression]
endsection
}
}
NEWLINE {
uint8 indentation
move -2
}
SIGMA_SUM {
section $tag_name
section Expr {Recursive_RPN $expression}
section Var {Recursive_RPN $expression}
section Start {Recursive_RPN $expression}
section End {Recursive_RPN $expression}
Recursive_RPN $expression ;# END_TAG
endsection
}
}
return $expression
}
set start [pos]
move $size
move -1
# while {[pos] >= $start} {
entry RPN: [Recursive_RPN "" $start]
# }
goto [expr $start+$size]
}