-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwords.tasm
424 lines (360 loc) · 7.07 KB
/
words.tasm
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
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
# words -- partial input code for a forth
# includes stack1pt
### words info:
# pushes chars to the stack as they're entered.
# perhaps it's a strange way to do it,
# but it saves writing yet another lot of pointer load/store nonsense.
# later, it will save messing about with allocating memory or having a
# fixed size buffer. (allocating is easy, freeing is not.)
### stack info:
# namespace:
# stack* push pop
# bstack* bpush bpop
# push and pop reg1 only. use regswap etc. for reg2.
# interrupts should probably be disabled while using any of these routines.
# risking it this time!
# it can go wrong! press 2 chars together and you may get only one.
# whether there's any leakage when that happens, i don't know.
# the push routines (main and b) save reg1 out of necessity,
# so if you need to preserve it you can omit the save, and
# restore it from stackreg1bak.
# this version (with pt*) preserves reg2 in push and pop,
# but trashes mempoint.
gotodata;>start
# test data
null;+0+0+0+0+;reg1pat1
null;0+0+0+0+0;reg2pat1
null;-0-0-0-0-;reg1pat2
null;0-0-0-0-0;reg2pat2
# stack pointer etc
null;+++++++++;stackbase
null;;stacktop
null;;stackreg1bak
null;+++------;bstackbase
null;;bstacktop
# some bstackbase values with space for
# the 2 stacks and remaining memory:
# +++------ 728 18955
# ++------- 2186 17497
# +-------- 6560 13123
############################
### initialization
null;;start
romread1;>stackbase;stackinit
setdata;>stacktop
# if not using bstack omit remainder
romread1;>bstackbase
setdata;>bstacktop
# underflow marker for bstack, may help in debugging;
# 2 lines doubly optional:
setreg1;-+-+-+-+-
gotodata;>bpush
# <sed 's/(.+)(.)/setkeyint;:\2\nkeyint;>key_\2/; /z/q' ../textdocs/SBTCVM-6-trit-Text-encoding.txt
#[
setkeyint;:a
keyint;>key_a
setkeyint;:b
keyint;>key_b
setkeyint;:c
keyint;>key_c
setkeyint;:d
keyint;>key_d
setkeyint;:e
keyint;>key_e
setkeyint;:f
keyint;>key_f
setkeyint;:g
keyint;>key_g
setkeyint;:h
keyint;>key_h
setkeyint;:i
keyint;>key_i
setkeyint;:j
keyint;>key_j
setkeyint;:k
keyint;>key_k
setkeyint;:l
keyint;>key_l
setkeyint;:m
keyint;>key_m
setkeyint;:n
keyint;>key_n
setkeyint;:o
keyint;>key_o
setkeyint;:p
keyint;>key_p
setkeyint;:q
keyint;>key_q
setkeyint;:r
keyint;>key_r
setkeyint;:s
keyint;>key_s
setkeyint;:t
keyint;>key_t
setkeyint;:u
keyint;>key_u
setkeyint;:v
keyint;>key_v
setkeyint;:w
keyint;>key_w
setkeyint;:x
keyint;>key_x
setkeyint;:y
keyint;>key_y
setkeyint;:z
keyint;>key_z
#]
setkeyint;:space
keyint;>proc_word
setkeyint;:enter
keyint;>clear
#######################
### words main code
# read a word and compress.
# on space, dump the length and compressed form.
# enter cancels the word.
# data:
# input mode:
# chars get pushed to the stack.
# mempoint holds the count of chars.
# processing:
# space beyond the end of the program is used to compose the word
# see "allocbase" below.
textstart
Parser test.
Enter words of alphabetic characters only.
Special keys:
Space: process word
Enter: cancel; clear word
textstop
# clear0 - [re]init for next word - used by clear and proc_word
setreg1;000000000;clear0
setdata;>charcount
null;;spinloop
gotodata;>spinloop
### words data
null;;charcount
null
null;;compacted
null
null;;compactcount
# proc_word - dump length and compressed form
# got:
# chars on the stack, last on top
# charcount
# allocbase as the start of memory to put the chars in order
# done:
# compose the chars in order
# print the length
# print them to show they're in order
romread1;>charcount;proc_word
setreg2;>allocbase
add
setdata;>ptrtmp
setreg2;00000000+;cploop
subtract
setdata;>ptrtmp
gotodata;>pop
setdata;000000000;ptrtmp
romread1;>ptrtmp
setreg2;>allocbase
gotoifgreater;>cploop
# now chars are from allocbase to allocbase+charcount
romread1;>charcount
dumpreg1
TTYwrite;:
TTYwrite;:c
TTYwrite;:h
TTYwrite;:a
TTYwrite;:r
TTYwrite;:s
TTYwrite;:,
TTYwrite;:
setreg1;>allocbase
gotodata;>push
romread1;>charcount
gotodata;>push
setreg1;>ret1
gotodata;>bpush
gotodata;>ttystring
TTYwrite;:enter;ret1
gotodata;>clear0
# clear - replacement for delete word
TTYwrite;:-;clear
TTYwrite;:-
TTYwrite;:c
TTYwrite;:l
TTYwrite;:e
TTYwrite;:a
TTYwrite;:r
TTYwrite;:e
TTYwrite;:d
TTYwrite;:-
TTYwrite;:-
TTYwrite;:enter
gotodata;>clear0
# inkey - a word-char key was pressed
gotodata;>push;inkey
romread1;>charcount
setreg2;00000000+
add
setdata;>charcount
gotodata;>spinloop
############################
### print string subroutine
# my first stack-based subroutine!
# params on the main stack: address; length.
# return address on the b stack
gotodata;>pop;ttystring
setreg2;00000000+
subtract
copy1to2
gotodata;>pop
# now length in r2, startaddr in r1
ptset
regswap
add
regswap
# now endaddr in r2
ptread;;ttystring_loop
setdata;>ttystring_write
TTYwrite;;ttystring_write
ptinc
ptget
gotoifgreater;>ttystring_done
gotodata;>ttystring_loop
gotodata;>bpop;ttystring_done
gotoreg1
############################
### interrupt routines
# <sed 's/(.+)(.)/TTYwrite;:\2;key_\2\nsetreg1;---\1\ngotodata;>inkey/; /z/q' ../textdocs/SBTCVM-6-trit-Text-encoding.txt
#[
TTYwrite;:a;key_a
setreg1;---------
gotodata;>inkey
TTYwrite;:b;key_b
setreg1;--------0
gotodata;>inkey
TTYwrite;:c;key_c
setreg1;--------+
gotodata;>inkey
TTYwrite;:d;key_d
setreg1;-------0-
gotodata;>inkey
TTYwrite;:e;key_e
setreg1;-------00
gotodata;>inkey
TTYwrite;:f;key_f
setreg1;-------0+
gotodata;>inkey
TTYwrite;:g;key_g
setreg1;-------+-
gotodata;>inkey
TTYwrite;:h;key_h
setreg1;-------+0
gotodata;>inkey
TTYwrite;:i;key_i
setreg1;-------++
gotodata;>inkey
TTYwrite;:j;key_j
setreg1;------0--
gotodata;>inkey
TTYwrite;:k;key_k
setreg1;------0-0
gotodata;>inkey
TTYwrite;:l;key_l
setreg1;------0-+
gotodata;>inkey
TTYwrite;:m;key_m
setreg1;------00-
gotodata;>inkey
TTYwrite;:n;key_n
setreg1;------000
gotodata;>inkey
TTYwrite;:o;key_o
setreg1;------00+
gotodata;>inkey
TTYwrite;:p;key_p
setreg1;------0+-
gotodata;>inkey
TTYwrite;:q;key_q
setreg1;------0+0
gotodata;>inkey
TTYwrite;:r;key_r
setreg1;------0++
gotodata;>inkey
TTYwrite;:s;key_s
setreg1;------+--
gotodata;>inkey
TTYwrite;:t;key_t
setreg1;------+-0
gotodata;>inkey
TTYwrite;:u;key_u
setreg1;------+-+
gotodata;>inkey
TTYwrite;:v;key_v
setreg1;------+0-
gotodata;>inkey
TTYwrite;:w;key_w
setreg1;------+00
gotodata;>inkey
TTYwrite;:x;key_x
setreg1;------+0+
gotodata;>inkey
TTYwrite;:y;key_y
setreg1;------++-
gotodata;>inkey
TTYwrite;:z;key_z
setreg1;------++0
gotodata;>inkey
#]
############################
### main stack routines
## push
# pushes reg1 to the stack
# trashes reg1, mempoint
setdata;>stackreg1bak;push
romread1;>stacktop
ptset
romread1;>stackreg1bak
ptwri
ptdec
ptget
setdata;>stacktop
continue
## pop
# pops top of stack into reg1
# trashes mempoint
romread1;>stacktop;pop
ptset
ptinc
ptget
setdata;>stacktop
ptread
continue
##########################
### b stack routines
# optional
## push
# pushes reg1 to b stack
# trashes reg1, mempoint
setdata;>stackreg1bak;bpush
romread1;>bstacktop
ptset
romread1;>stackreg1bak
ptwri
ptinc
ptget
setdata;>bstacktop
continue
## pop
# pops top of b stack into reg1
# trashes mempoint
romread1;>bstacktop;bpop
ptset
ptdec
ptget
setdata;>bstacktop
ptread
continue
stop;;allocbase