blob: a05cb9dc327455a370ae092906ad3288da3d9726 (
plain)
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
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
|
.org $1000
tok:
.byte "dab"
msg:
.byte "oof, you divided a, and b on me.\n"
.org $2000
buffer:
.org $4000
cmd_buf:
.org $200
bitmask:
.byte $0
bitabl:
.qword $0
.word $0
bits:
.byte $0
.org $0
scr_row:
.byte $0
scr_col:
.byte $0
scr_lnst:
.word $0
scr_lncnt:
.word $0
scr_rowst:
.byte $0
a:
.byte $0
b:
.byte $0
c:
.byte $0
d:
.byte $0
e:
.byte $0
string:
.byte "Please, type something.\n"
string2:
.byte "You typed, "
end:
.byte $0
ptr:
.qword buffer
cptr:
.qword cmd_buf
tptr:
.qword tok
mptr:
.qword msg
bmptr:
.qword bitmask
btptr:
.qword bitabl
.org $8000
reset:
cps
ldx.w
txs
ldy
lda
jsl clr_buf
jmp start
clr_buf:
lda
cpy.w
beq clr_buf_end
sta (ptr), y
iny
jmp clr_buf
clr_buf_end:
ldy.w
rtl
start:
lda
tax
sta $C000
phy
ldy.w
jsl clr_cbuf
ply
lda
sta $C000
jmp print
clr_cbuf:
cpy.w
beq clr_cbuf_end
sta (cptr), y
iny
jmp clr_cbuf
clr_cbuf_end:
rtl
pull_y:
ply
rset_a:
lda
sta $C000
inc
read:
lda $C000
beq rset_a
jsl getchar
beq parse
jmp rset_a
sleep:
lda end
bne spin
print:
phy
txy
lda string, y
beq pull_y
ply
inx
jsl print_char
jmp print
getbit:
phy
ldx scr_row
getbt1:
jsl bitpos
txy
ldb (btptr), y
ply
aba
cmp
jmp bitout
bitpos:
stx bitmask
txa
and
tax
lda bits, x
pha
lda bitmask
lsr
tax
pla
rtl
bitout:
ldx bitmask
rtl
getchar:
lda $C002
pha
phy
cmp
beq cmd_cpy
getchar_pnt:
ply
pla
jsl print_char
lda a
cmp
beq getchar_line
jmp getchar_char
cmd_cpy:
lda scr_row
mul
tay
ldx.w
cmd_cpy_strt:
lda (ptr), y
beq getchar_pnt
phy
txy
sta (cptr), y
inx
ply
iny
jmp cmd_cpy_strt
getchar_line:
lda
sta scr_lncnt
jmp getchar_end
getchar_char:
lda
getchar_end:
rtl
parse:
lda
tax
jsl dabbed
beq start
lda
tax
jmp result
print_char:
sta a
cmp
beq esc
cmp
beq nl
cmp
beq clr_scr
cmp
beq bs
cmp
beq bs
sta a
ldb scr_col
cpb
beq linewrap
jmp printc
linewrap:
ldb
stb scr_col
lda
sta c
jsl isdown
ldb scr_row
cpb
beq printc_end
printc:
lda a
inc scr_col
inc scr_lncnt
sta (ptr), y
iny
sta $C001
printc_end:
rtl
nl:
lda
sta (ptr), y
sta scr_col
lda scr_row
cmp
bne nl_inc
lda
sta a
jmp printc_end
nl_inc:
lda
sta c
jsl isdown
sty.w scr_lnst
lda
sta a
jmp printc_end
clr_scr:
lda
sta.w scr_lnst
sta scr_rowst
tay
jsl clr_buf
sta scr_col
sta scr_row
jsl update_pos
lda
sta $C001
jmp printc_end
back:
lda
sta $C001
dey
lda
sta (ptr), y
lda
dec scr_col
dec scr_lncnt
jsl update_pos
jmp printc_end
bs:
lda scr_col
beq printc_end
jmp back
esc:
lda $C000
lda $C000
beq printc_end
lda $C002
sta c
lda
sta d
jsl isup
lda e
bne esc_lnst
lda d
bne esc_end
jsl isdown
lda e
bne esc_lnst
lda d
bne esc_end
lda
jsl isleft
lda d
bne esc_end
jsl isright
jmp esc_end
esc_lnst:
lda scr_row
sta scr_rowst
mul
sta.w scr_lnst
esc_end:
lda
sta d
jmp printc_end
isup:
lda scr_row
beq isup_done
lda c
cmp
beq up
isup_done:
rtl
isdown:
lda scr_row
cmp
beq isdown_done
lda c
cmp
beq down
jmp isdown_done
isdown_scrl:
lda
sta $C001
lda
sta $C001
lda
sta $C001
isdown_done:
rtl
isright:
lda scr_col
cmp
beq isright_end
lda c
cmp
beq right
isright_end:
rtl
isleft:
lda scr_col
beq isleft_done
lda c
cmp
beq left
isleft_done:
rtl
up:
dec scr_row
jsl update_pos
lda
sta d
jmp isup_done
down:
inc scr_row
jsl update_pos
lda
sta d
jmp isdown_done
right:
inc scr_col
jsl update_pos
jmp isright_end
left:
dec scr_col
jsl update_pos
lda
sta d
jmp isleft_done
update_pos:
lda scr_row
mul
adc scr_col
tay
lda
sta $C001
lda
sta $C001
jsl getrow
jsl getcol
lda
sta $C001
rtl
getrow:
lda scr_row
div
adc
sta $C001
tba
adc
sta $C001
rtl
getcol:
lda
sta $C001
lda scr_col
div
adc
sta $C001
tba
adc
sta $C001
rtl
result:
phy
txy
lda string2, y
beq rset_y
ply
jsl print_char
inx
jmp result
rset_y:
ply
lda
tax
jmp print_buf
dabbed:
phy
txy
lda (cptr), y
beq dab_pend
cmp (tptr), y
bcs dab_pend
beq chk_str
bcc dab_pend
chk_str:
ply
inx
cpx
bne dabbed
ldx
pnt_msg:
phy
txy
lda (mptr), y
beq dab_peqnd
ply
jsl print_char
inx
jmp pnt_msg
dab_pend:
ply
lda
jmp dab_end
dab_peqnd:
ply
lda
jmp dab_end
dab_end:
rtl
print_buf:
phy
txy
lda (cptr), y
beq cmd_clr
ply
jsl print_char
inx
jmp print_buf
cmd_clr:
ply
lda
jsl print_char
jmp start
.org $FFC0
.qword reset
.org $FF50
.qword spin
.qword spin
.qword spin
.qword spin
.qword spin
.qword spin
.qword spin
.org $FF50
done
|