/
snippets.asm
250 lines (231 loc) · 4.71 KB
/
snippets.asm
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
### Stack frame
```
arg0 -- 0th arg
arg1
:
argn -- nth arg
loc0 -- 0th local
loc1
:
locn -- last local
IP -- IP (saved interpreter ptr, return)
arg_list* -- arg_list*
first_arg* -- first_arg*
BP -- BP (saved base ptr) <-- iy
res0 -- 0th result
res1
:
resn -- last result. <-- sp
```
### Control codes
```
^@ 0 NUL
^A 1 SOH
^B 2 STX
^C 3 ETX
^D 4 EOT
^E 5 ENQ
^F 6 ACK
^G 7 BEL
^H 8 BS
^I 9 TAB
^J 10 LF
^K 11 VT
^L 12 FF
^M 13 CR
^N 14 SO
^O 15 SI
^P 16 DLE
^Q 17 DC1
^R 18 DC2
^S 19 DC3
^T 20 DC4
^U 21 NAK
^V 22 SYN
^W 23 ETB
^X 24 CAN
^Y 25 EM
^Z 26 SUB
^[ 27 ESC
^\ 28 FS
^] 29 GS
^^ 30 RS
^_ 31 US
```
; str -- num
hash:
pop hl
push bc
ld bc,hl
call hashStr
pop bc
push hl
jp (ix)
sqrt1:
pop hl
push bc
call squareRoot
ld (vRemain),bc
pop bc
push de
jp (ix)
; hash C-string
; BC = str
; HL = hash
hashStr:
ld (vHashStr),bc ; store source string
ld hl,0
hashStr1:
ld a,(bc) ; load next char
inc bc
cp 0 ; NUL?
ret z
hashStr2:
ld d,0
ld e,a
add hl,de
ld de,hl ; hl *= 193 (11000001)
add hl,hl ; shift left
add hl,de ; add
add hl,hl ; shift left
add hl,hl ; shift left
add hl,hl ; shift left
add hl,hl ; shift left
add hl,hl ; shift left
add hl,hl ; shift left
add hl,de ; add
jr hashStr1
; squareroot
; Input: HL = value
; Result: DE = square root BC = remainder
squareRoot:
ld bc,0800h
ld e,c
xor a
squareRoot1:
add hl,hl
rl c
adc hl,hl
rl c
jr nc,$+4
set 0,l
ld a,e
add a,a
ld e,a
add a,a
bit 0,l
jr nz,$+5
sub c
jr nc,squareRoot4
ld a,c
sub e
inc e
sub e
ld c,a
squareRoot4:
djnz squareRoot1
bit 0,l
jr z,squareRoot5
inc b
squareRoot5:
ld d,0
ret
; /pk print stack
; --
printStack:
ld (vTemp1),bc
call printStr
.cstr "=> "
ld hl,STACK
sbc hl,sp
srl h
rr l
ld bc,hl
ld hl,STACK
jr printStack2
printStack1:
dec bc
dec hl
ld d,(hl)
dec hl
ld e,(hl)
ex de,hl
call prthex
ex de,hl
ld a," "
call putchar
printStack2:
ld a,c
or b
jr nz,printStack1
call prompt
ld bc,(vTemp1)
jp (ix)
; /pb printBuffer
; --
; prints chars in buffer from /vB to /vb. Resets /vb to /vB
FUNC printBuffer, 0, "a"
.cstr "{/vB /vb/vB- /pc /vB/vb=}" ; block
FUNC f3, 0, ""
db "{"
db ":kt{"
db ":dt{" ; return talkback to receive data
db "0 2 %k^"
db "}; 0 %k^" ; init sink
db "};"
db "}"
db 0
FUNC f4, 1, "spT"
db "{"
db ":dt{" ; *** return talkback to receive data ; $56AA
db "0%t==/br" ; break if type = 2
db "0 0 %d^" ; 0 or 1: get next src data item
db "}; 0 %s^"
db "}"
db 0
; _ func
; -- func*
underscore:
colon:
lambda:
push ix
ld ix,lambda1
jp arglist
lambda1:
inc bc
ld ix,lambda2
jp blockStart
lambda2:
ld ix,lambda3
jp createFunc
lambda3:
pop hl
pop ix
push hl
jp (ix)
; breakout the machine code from inside lambda
; accesses first arg
f1:
call go
dw NUL
dw f1x
dw $+2
db 0
.pstr "a"
f1x:
db "{`h`"
db 0
ld e,(iy+2) ; de = first_arg*
ld d,(iy+3)
ex de,hl
dec hl
ld d,(hl)
dec hl
ld e,(hl)
ld a,e
call putchar
ld bc,f1y-1
jp (ix)
f1y:
db "`y`}"
db 0