-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcore-stack.a65
462 lines (427 loc) · 6.08 KB
/
core-stack.a65
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
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
; core-stack.a65
#echo . core-stack.a65 Stack
An untested rewrite of the inner interpreter stack jazz
```
pdo
;ldy #2
jsr locals2
ldy #3
pdo01
lda zi,y
pha
lda tos,y
sta zi,y
dey
bpl pdo01
dex
; fall through
twodrop
inx ; fall through
bne drop ; bra
i
ldy zi+1
lda zi
; pass YA = value to push/put on stack
pushya
dex
pha
tya
pushsa
sta stackh,x
pushs
pla
sta stackl,x
drop
ldy stackh,x
lda stackl,x
inx
put
sty tos+1
sta tos
jmp next
push0a
ldy #0
beq pushya
cfetch
clc
.byt $29
fetch
sec
ldy #0
lda (tos),y
bcc put
pha
iny
lda (tos),y
;bcs pushsa ; is [2] shorter
tay
pla
bcs put
```
clit
lda #0
pha
clc
.byt $29
plit
sec
ldy #2
lda (ip),y
pha
bcc gotit
iny
lda (ip),y
pha
gotit
dex
lda tos
sta stackl,x
lda tos+1
sta stackh,x
pla
sta tos
pla
sta tos+1
;--------------------------------------------------------------
#if 0
name=CLIT
stack=( -- b )
tags=nosymbol
#endif
clit
clc
lda #0
beq lit01 ; bra
;
plit
sec
ldy #3
lda (ip),y
lit01
tay
jsr slip
sty tos+1
ldy #2
lda (ip),y
sta tos
bump01
lda #3 ; ip+3 or ip+4 depending on Carry
pad
adc ip ; pass A = offset added to IP
bcs branch02 ; check for page boundary crossing
cmp #$ff
bne branch03 ; check for xxFF at end of page
page
lda #0
beq branch02 ; bra
;
pqleave
lda tos
ora tos+1
php
jsr slide
plp
bne pleave
beq bump
qbranch
lda tos
ora tos+1 ; check the flag
ldy stackl,x
sty tos
ldy stackh,x
sty tos+1
inx ; drop
tay ; to set the Z flag
beq branch
bump
;lda #3 ; bump01 does this for us
clc
bcc bump01 ; bra
;
pqdo
inc ip ; skip past branch byte
jsr subeq
bne pdo
pqdo02
inx
jsr slide
dec ip ; we need the branch byte
branch
ldy #2 ; [2]
lda (ip),y ; [5] get the offset
bpl branch01 ; [2|3]
dec ip+1 ; [5]
branch01
sec ; [2]
adc ip ; [3]
bcc branch03 ; [2|3]
branch02
inc ip+1 ; [5]
branch03
sta ip ; [3]
jmp nexto ; [3]
ploop
inc zi
bne ploop01
inc zi+1
ploop01
lda zi
eor zlim
bne branch
lda zi+1
eor zlim+1
bne branch
beq ploop02
;
pploop
sec
lda zi
sbc zlim
sta n
lda zi+1
sbc zlim+1
eor #$80
tay
clc
lda n
adc tos
tya
adc tos+1
php
clc
lda tos
adc zi
sta zi
lda tos+1
adc zi+1
sta zi+1
jsr slide
plp
bvc branch
ploop02
sec
.byt $29 ; AND #
pleave
clc
pla
sta zi
pla
sta zi+1
pla
sta zi+2
pla
sta zi+3
bcs bump
bcc branch
pdo
;ldy #2
jsr locals2
ldy #3
pdo01
lda zi,y
pha
lda tos,y
sta zi,y
dey
bpl pdo01
bne drop ; bra
fourdrop
inx ; fall through
threedrop
inx
twodrop
inx ; fall through
;
;
;
drop
lda stackh,x
pha
lda stackl,x
inx
put
sta tos
pla
sta tos+1
jmp next
;
;
;
spfetch
txa
push0a
ldy #0
beq pushya
cstore
clc
.byt $29 ; AND #
store
sec
ldy #0 ; [2]
lda stackl,x ; [4]
sta (tos),y ; [6]
bcc twodrop
lda stackh,x ; [4]
iny ; [2] ; clear Z flag
sta (tos),y ; [6] ; MSB is stored last, this is important to EVENTS
bne twodrop ; [3] ; bra
i
ldy zi+1
lda zi
pushya
dex
pha
lda #>(put-1)
pha
lda #<(put-1)
pha
lda tos+1
sta stackh,x
lda tos
sta stackl,x
pla
jmp put
qdup
lda tos
ora tos+1
beq qdup01
dup
lda #>(next-1)
pha
lda #<(next-1)
pha
bne slip
slip
dex ; slip something onto the stack
lda tos+1
sta stackh,x
lda tos
sta stackl,x
rts
doconst
sec
.byt $29 ; AND # to skip the CLC
docconst
clc
jsr slip
pla
sta tos
pla
sta tos+1
ldy #1
lda (tos),y
bcc push0a
bcs fetchya ; bra
cfetch
clc
.byt $29 ; AND #
fetch
sec
fetch0a
ldy #0
lda (tos),y
bcc put
fetchya
pha
iny
lda (tos),y
tay
pla
bcs put
rts
;--------------------------------------------------------------
roll
txa
clc
adc tos
tax
lda stackh,x
pha
lda stackl,x
pha
roll01
inx
dec tos
bmi rput
dex
lda stackh-1,x
sta stackh,x
lda stackl-1,x
sta stackl,x
dex
bne roll01 ; bra
rfrom
jsr slip
rput
pla
sta tos
pla
sta tos+1
qdup01
jmp next
;--------------------------------------------------------------
;--------------------------------------------------------------
slide
ldy stackh,x ; slide something off of the stack
lda stackl,x
inx
sty tos+1
sta tos
rts
cstoreplus
lda tos
pha
jsr slide
ldy #0
pla
sta (tos),y
oneplus
lda #>(next-1)
pha
lda #<(next-1)
pha
inctos
inc tos
bne inctos01
inc tos+1
inctos01
rts
;--------------------------------------------------------------
twofetch
ldy #3
twofetch01
lda (tos),y
pha
dey
bpl twofetch01
jsr slide
tworfrom
jsr slip
dex
pla
sta tos
pla
sta tos+1
pla
sta stackl,x
pla
sta stackh,x
jmp next
;--------------------------------------------------------------
tworfetch
jsr slip
dex
stx xsave
tsx
txa
tay
ldx xsave
lda $0104,y
sta stackh,x
lda $0103,y
sta stackl,x
lda $0102,y
sta n
lda $0101,y
ldy n
jmp put