-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patha1basic.asm
More file actions
2018 lines (1875 loc) · 48.5 KB
/
Copy patha1basic.asm
File metadata and controls
2018 lines (1875 loc) · 48.5 KB
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
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
; Apple 1 BASIC
;
; Modifications to build with CC65 by Jeff Tranter <tranter@pobox.com>
;
; Apple 1 BASIC was written by Steve Wozniak
; Uses disassembly copyright 2003 Eric Smith <eric@brouhaha.com>
; http://www.brouhaha.com/~eric/retrocomputing/apple/apple1/basic/
Z1d = $1D
ch = $24 ; horizontal cursor location
var = $48
lomem = $4A ; lower limit of memory used by BASIC (2 bytes)
himem = $4C ; upper limit of memory used by BASIC (2 bytes)
rnd = $4E ; random number (2 bytes)
; The noun stack and syntax stack appear to overlap, which is OK since
; they apparently are not used simultaneously.
; The noun stack size appears to be 32 entries, based on LDX #$20
; instruction at e67f. However, there seems to be enough room for
; another 8 entries. The noun stack builds down from noun_stk_<part>+$1f
; to noun_stk_<part>+$00, indexed by the X register.
; Noun stack usage appears to be:
; integer:
; (noun_stk_h_int,noun_stk_l) = value
; noun_stk_h_str = 0
; string:
; (noun_stk_h_str,noun_stk_l) = pointer to string
; noun_stk_h_int = any
; Since noun_stk_h_str determines whether stack entry is integer or string,
; strings can't start in zero page.
noun_stk_l = $50
syn_stk_h = $58 ; through $77
noun_stk_h_str = $78
syn_stk_l = $80 ; through $9F
noun_stk_h_int = $A0
txtndxstk = $A8 ; through $C7
text_index = $C8 ; index into text being tokenized (in buffer at $0200)
leadbl = $C9 ; leading blanks
pp = $CA ; pointer to end of program (2 bytes)
pv = $CC ; pointer to end of variable storage (2 bytes)
acc = $CE ; (2 bytes)
srch = $D0
tokndxstk = $D1
srch2 = $D2
if_flag = $D4
cr_flag = $D5
current_verb = $D6
precedence = $D7
x_save = $D8
run_flag = $D9
aux = $DA
pline = $DC ; pointer to current program line (2 bytes)
pverb = $E0 ; pointer to current verb (2 bytes)
p1 = $E2
p2 = $E4
p3 = $E6
token_index = $F1 ; pointer used to write tokens into buffer 2 bytes)
pcon = $F2 ; temp used in decimal output (2 bytes)
auto_inc = $F4
auto_ln = $F6
auto_flag = $F8
char = $F9
leadzr = $FA
for_nest_count = $FB ; count of active (nested) FOR loops
gosub_nest_count = $FC ; count of active (nested) subroutines calls (GOSUB)
synstkdx = $FD
synpag = $FE
; GOSUB stack, max eight entries
; note that the Apple II version has sixteen entries
gstk_pverbl = $0100 ; saved pverb
gstk_pverbh = $0108
gstk_plinel = $0110 ; saved pline
gstk_plineh = $0118
; FOR stack, max eight entries
; note that the Apple II version has sixteen entries
fstk_varl = $0120 ; pointer to index variable
fstk_varh = $0128
fstk_stepl = $0130 ; step value
fstk_steph = $0138
fstk_plinel = $0140 ; saved pline
fstk_plineh = $0148
fstk_pverbl = $0150 ; saved pverb
fstk_pverbh = $0158
fstk_tol = $0160 ; "to" (limit) value
fstk_toh = $0168
buffer = $0200
KBD = $D010
KBDCR = $D011
DSP = $D012
; The program can be relocated to a different address but should be a
; multiple of $2000.
.org $E000
.export START
START: JMP cold ; BASIC cold start entry point
; Get character for keyboard, return in A.
rdkey: LDA KBDCR ; Read control register
BPL rdkey ; Loop if no key pressed
LDA KBD ; Read key data
RTS ; and return
Se00c: TXA
AND #$20
BEQ Le034
Se011: LDA #$A0
STA p2
JMP cout
Se018: LDA #$20
Se01a: CMP ch
BCS nextbyte
LDA #$8D
LDY #$07
Le022: JSR cout
LDA #$A0
DEY
BNE Le022
nextbyte: LDY #$00
LDA (p1),Y
INC p1
BNE Le034
INC p1+1
Le034: RTS
; token $75 - "," in LIST command
list_comman: JSR get16bit
JSR find_line2
Le03b: LDA p1
CMP p3
LDA p1+1
SBC p3+1
BCS Le034
JSR list_line
JMP Le03b
; token $76 - LIST command w/ no args
list_all: LDA pp
STA p1
LDA pp+1
STA p1+1
LDA himem
STA p3
LDA himem+1
STA p3+1
BNE Le03b
; token $74 - LIST command w/ line number(s)
list_cmd: JSR get16bit
JSR find_line
LDA p2
STA p1
LDA p2+1
STA p1+1
BCS Le034
; list one program line
list_line: STX x_save
LDA #$A0
STA leadzr
JSR nextbyte
TYA
; list an integer (line number or literal)
list_int: STA p2
JSR nextbyte
TAX
JSR nextbyte
JSR prdec
Le083: JSR Se018
STY leadzr
TAX
BPL list_token
ASL
BPL list_int
LDA p2
BNE Le095
JSR Se011
Le095: TXA
Le096: JSR cout
Le099: LDA #$25
JSR Se01a
TAX
BMI Le096
STA p2
; list a single token
list_token: CMP #$01
BNE Le0ac
LDX x_save
JMP crout
Le0ac: PHA
STY acc
LDX #>syntabl2
STX acc+1
CMP #$51
BCC Le0bb
DEC acc+1
SBC #$50
Le0bb: PHA
LDA (acc),Y
Le0be: TAX
DEY
LDA (acc),Y
BPL Le0be
CPX #$C0
BCS Le0cc
CPX #$00
BMI Le0be
Le0cc: TAX
PLA
SBC #$01
BNE Le0bb
BIT p2
BMI Le0d9
JSR Seff8
Le0d9: LDA (acc),Y
BPL Le0ed
TAX
AND #$3F
STA p2
CLC
ADC #$A0
JSR cout
DEY
CPX #$C0
BCC Le0d9
Le0ed: JSR Se00c
PLA
CMP #$5D
BEQ Le099
CMP #$28
BNE Le083
BEQ Le099
; token $2A - left paren for substring like A$(3,5)
paren_substr: JSR Se118
STA noun_stk_l,X
CMP noun_stk_h_str,X
Le102: BCC Le115
string_err: LDY #$2B
go_errmess_1: JMP print_err_msg
; token $2B - comma for substring like A$(3,5)
comma_substr: JSR getbyte
CMP noun_stk_l,X
BCC string_err
JSR Sefe4
STA noun_stk_h_str,X
Le115: JMP left_paren
Se118: JSR getbyte
BEQ string_err
SEC
SBC #$01
RTS
; token $42 - left paren for string array as dest
; A$(1)="FOO"
str_arr_dest: JSR Se118
STA noun_stk_l,X
CLC
SBC noun_stk_h_str,X
JMP Le102
Le12c: LDY #$14
BNE go_errmess_1
; token $43 - comma, next var in DIM statement is string
; token $4E - "DIM", next var in DIM is string
dim_str: JSR Se118
INX
Le134: LDA noun_stk_l,X
STA aux
ADC acc
PHA
TAY
LDA noun_stk_h_str,X
STA aux+1
ADC acc+1
PHA
CPY pp
SBC pp+1
BCS Le12c
LDA aux
ADC #$FE
STA aux
LDA #$FF
TAY
ADC aux+1
STA aux+1
Le156: INY
LDA (aux),Y
CMP 100
BNE Le16d
TYA
BEQ Le156
Le161: PLA
STA (aux),Y
STA 100
DEY
BPL Le161
INX
RTS
NOP
Le16d: LDY #$80
Le16f: BNE go_errmess_1
; token ???
input_str: LDA #$00
JSR push_a_noun_stk
LDY #$02
STY noun_stk_h_str,X
JSR push_a_noun_stk
LDA #$BF ; '?'
JSR cout
LDY #$00
JSR read_line
STY noun_stk_h_str,X
NOP
NOP
NOP
; token $70 - string literal
string_lit: LDA noun_stk_l+1,X
STA acc
LDA noun_stk_h_str+1,X
STA acc+1
INX
INX
JSR Se1bc
Le199: LDA rnd,X
CMP syn_stk_h+30,X
BCS Le1b4
INC rnd,X
TAY
LDA (acc),Y
LDY noun_stk_l,X
CPY p2
BCC Le1ae
LDY #$83
BNE Le16f
Le1ae: STA (aux),Y
INC noun_stk_l,X
BCC Le199
Le1b4: LDY noun_stk_l,X
TXA
STA (aux),Y
INX
INX
RTS
Se1bc: LDA noun_stk_l+1,X
STA aux
SEC
SBC #$02
STA p2
LDA noun_stk_h_str+1,X
STA aux+1
SBC #$00
STA p2+1
LDY #$00
LDA (p2),Y
CLC
SBC aux
STA p2
RTS
; token $39 - "=" for string equality operator
string_eq: LDA noun_stk_l+3,X
STA acc
LDA noun_stk_h_str+3,X
STA acc+1
LDA noun_stk_l+1,X
STA aux
LDA noun_stk_h_str+1,X
STA aux+1
INX
INX
INX
LDY #$00
STY noun_stk_h_str,X
STY noun_stk_h_int,X
INY
STY noun_stk_l,X
Le1f3: LDA himem+1,X
CMP syn_stk_h+29,X
PHP
PHA
LDA rnd+1,X
CMP syn_stk_h+31,X
BCC Le206
PLA
PLP
BCS Le205
Le203: LSR noun_stk_l,X
Le205: RTS
Le206: TAY
LDA (acc),Y
STA p2
PLA
TAY
PLP
BCS Le203
LDA (aux),Y
CMP p2
BNE Le203
INC rnd+1,X
INC himem+1,X
BCS Le1f3
; token $3A - "#" for string inequality operator
string_neq: JSR string_eq
JMP not_op
; token $14 - "*" for numeric multiplication
mult_op: JSR Se254
Le225: ASL acc
ROL acc+1
BCC Le238
CLC
LDA p3
ADC aux
STA p3
LDA p3+1
ADC aux+1
STA p3+1
Le238: DEY
BEQ Le244
ASL p3
ROL p3+1
BPL Le225
JMP Le77e
Le244: LDA p3
JSR push_ya_noun_stk
LDA p3+1
STA noun_stk_h_int,X
ASL p2+1
BCC Le279
JMP negate
Se254: LDA #$55
STA p2+1
JSR Se25b
Se25b: LDA acc
STA aux
LDA acc+1
STA aux+1
JSR get16bit
STY p3
STY p3+1
LDA acc+1
BPL Le277
DEX
ASL p2+1
JSR negate
JSR get16bit
Le277: LDY #$10
Le279: RTS
; token $1f - "MOD"
mod_op: JSR See6c
BEQ Le244
.byte $FF
Le280: CMP #$84
BNE Le286
LSR auto_flag
Le286: CMP #$DF
BEQ Le29b
CMP #$9B
BEQ Le294
STA buffer,Y
INY
BPL read_line
Le294: LDY #$8B
JSR Se3c4
Se299: LDY #$01
Le29b: DEY
BMI Le294
; read a line from keyboard (using rdkey) into buffer
read_line: JSR rdkey
NOP
NOP
JSR cout
CMP #$8D
BNE Le280
LDA #$DF
STA buffer,Y
RTS
cold: JSR mem_init_4k
.export warm
warm: JSR crout ; BASIC warm start entry point
Le2b6: LSR run_flag
LDA #'>'+$80 ; Prompt character (high bit set)
JSR cout
LDY #$00
STY leadzr
BIT auto_flag
BPL Le2d1
LDX auto_ln
LDA auto_ln+1
JSR prdec
LDA #$A0
JSR cout
Le2d1: LDX #$FF
TXS
JSR read_line
STY token_index
TXA
STA text_index
LDX #$20
JSR Se491
LDA text_index
ADC #$00
STA pverb
LDA #$00
TAX
ADC #$02
STA pverb+1
LDA (pverb,X)
AND #$F0
CMP #$B0
BEQ Le2f9
JMP Le883
Le2f9: LDY #$02
Le2fb: LDA (pverb),Y
STA 100
DEY
BNE Le2fb
JSR Se38a
LDA token_index
SBC text_index
CMP #$04
BEQ Le2b6
STA (pverb),Y
LDA pp
SBC (pverb),Y
STA p2
LDA pp+1
SBC #$00
STA p2+1
LDA p2
CMP pv
LDA p2+1
SBC pv+1
BCC Le36b
Le326: LDA pp
SBC (pverb),Y
STA p3
LDA pp+1
SBC #$00
STA p3+1
LDA (pp),Y
STA (p3),Y
INC pp
BNE Le33c
INC pp+1
Le33c: LDA p1
CMP pp
LDA p1+1
SBC pp+1
BCS Le326
Le346: LDA p2,X
STA pp,X
DEX
BPL Le346
LDA (pverb),Y
TAY
Le350: DEY
LDA (pverb),Y
STA (p3),Y
TYA
BNE Le350
BIT auto_flag
BPL Le365
Le35c: LDA auto_ln+1,X
ADC auto_inc+1,X
STA auto_ln+1,X
INX
BEQ Le35c
Le365: BPL Le3e5
.byte $00,$00,$00,$00
Le36b: LDY #$14
BNE print_err_msg
; token $0a - "," in DEL command
del_comma: JSR get16bit
LDA p1
STA p3
LDA p1+1
STA p3+1
JSR find_line1
LDA p1
STA p2
LDA p1+1
STA p2+1
BNE Le395
; token $09 - "DEL"
del_cmd: JSR get16bit
Se38a: JSR find_line
LDA p3
STA p1
LDA p3+1
STA p1+1
Le395: LDY #$00
Le397: LDA pp
CMP p2
LDA pp+1
SBC p2+1
BCS Le3b7
LDA p2
BNE Le3a7
DEC p2+1
Le3a7: DEC p2
LDA p3
BNE Le3af
DEC p3+1
Le3af: DEC p3
LDA (p2),Y
STA (p3),Y
BCC Le397
Le3b7: LDA p3
STA pp
LDA p3+1
STA pp+1
RTS
Le3c0: JSR cout
INY
Se3c4: LDA error_msg_tbl,Y
BMI Le3c0
cout: CMP #$8D
BNE Le3d3
crout: LDA #$00 ; character output
STA ch
LDA #$8D
Le3d3: INC ch
; Send character to display. Char is in A.
Le3d5: BIT DSP ; See if display ready
BMI Le3d5 ; Loop if not
STA DSP ; Write display data
RTS ; and return
too_long_err: LDY #$06
print_err_msg: JSR print_err_msg1 ; print error message specified in Y
BIT run_flag
Le3e5: BMI Le3ea
JMP Le2b6
Le3ea: JMP Leb9a
Le3ed: ROL
ADC #$A0
CMP buffer,X
BNE Le448
LDA (synpag),Y
ASL
BMI Le400
DEY
LDA (synpag),Y
BMI Le428
INY
Le400: STX text_index
TYA
PHA
LDX #$00
LDA (synpag,X)
TAX
Le409: LSR
EOR #$48
ORA (synpag),Y
CMP #$C0
BCC Le413
INX
Le413: INY
BNE Le409
PLA
TAY
TXA
JMP Le4c0
; write a token to the buffer
; buffer [++tokndx] = A
put_token: INC token_index
LDX token_index
BEQ too_long_err
STA buffer,X
Le425: RTS
Le426: LDX text_index
Le428: LDA #$A0
Le42a: INX
CMP buffer,X
BCS Le42a
LDA (synpag),Y
AND #$3F
LSR
BNE Le3ed
LDA buffer,X
BCS Le442
ADC #$3F
CMP #$1A
BCC Le4b1
Le442: ADC #$4F
CMP #$0A
BCC Le4b1
Le448: LDX synstkdx
Le44a: INY
LDA (synpag),Y
AND #$E0
CMP #$20
BEQ Le4cd
LDA txtndxstk,X
STA text_index
LDA tokndxstk,X
STA token_index
Le45b: DEY
LDA (synpag),Y
ASL
BPL Le45b
DEY
BCS Le49c
ASL
BMI Le49c
LDY syn_stk_h,X
STY synpag+1
LDY syn_stk_l,X
INX
BPL Le44a
Le470: BEQ Le425
CMP #$7E
BCS Le498
DEX
BPL Le47d
LDY #$06
BPL go_errmess_2
Le47d: STY syn_stk_l,X
LDY synpag+1
STY syn_stk_h,X
LDY text_index
STY txtndxstk,X
LDY token_index
STY tokndxstk,X
AND #$1F
TAY
LDA syntabl_index,Y
Se491: ASL
TAY
LDA #(>syntabl_index)>>1
ROL
STA synpag+1
Le498: BNE Le49b
INY
Le49b: INY
Le49c: STX synstkdx
LDA (synpag),Y
BMI Le426
BNE Le4a9
LDY #$0E
go_errmess_2: JMP print_err_msg
Le4a9: CMP #$03
BCS Le470
LSR
LDX text_index
INX
Le4b1: LDA buffer,X
BCC Le4ba
CMP #$A2
BEQ Le4c4
Le4ba: CMP #$DF
BEQ Le4c4
STX text_index
Le4c0: JSR put_token
INY
Le4c4: DEY
LDX synstkdx
Le4c7: LDA (synpag),Y
DEY
ASL
BPL Le49c
Le4cd: LDY syn_stk_h,X
STY synpag+1
LDY syn_stk_l,X
INX
LDA (synpag),Y
AND #$9F
BNE Le4c7
STA pcon
STA pcon+1
TYA
PHA
STX synstkdx
LDY srch,X
STY leadbl
CLC
Le4e7: LDA #$0A
STA char
LDX #$00
INY
LDA buffer,Y
AND #$0F
Le4f3: ADC pcon
PHA
TXA
ADC pcon+1
BMI Le517
TAX
PLA
DEC char
BNE Le4f3
STA pcon
STX pcon+1
CPY token_index
BNE Le4e7
LDY leadbl
INY
STY token_index
JSR put_token
PLA
TAY
LDA pcon+1
BCS Le4c0
Le517: LDY #$00
BPL go_errmess_2
prdec: STA pcon+1 ; output A:X in decimal
STX pcon
LDX #$04
STX leadbl
Le523: LDA #$B0
STA char
Le527: LDA pcon
CMP dectabl,X
LDA pcon+1
SBC dectabh,X
BCC Le540
STA pcon+1
LDA pcon
SBC dectabl,X
STA pcon
INC char
BNE Le527
Le540: LDA char
INX
DEX
BEQ Le554
CMP #$B0
BEQ Le54c
STA leadbl
Le54c: BIT leadbl
BMI Le554
LDA leadzr
BEQ Le55f
Le554: JSR cout
BIT auto_flag
BPL Le55f
STA buffer,Y
INY
Le55f: DEX
BPL Le523
RTS
; powers of 10 table, low byte
dectabl: .byte $01,$0A,$64,$E8,$10
; powers of 10 table, high byte
dectabh: .byte $00,$00,$00,$03,$27
find_line: LDA pp
STA p3
LDA pp+1
STA p3+1
find_line1: INX
find_line2: LDA p3+1
STA p2+1
LDA p3
STA p2
CMP himem
LDA p2+1
SBC himem+1
BCS Le5ac
LDY #$01
LDA (p2),Y
SBC acc
INY
LDA (p2),Y
SBC acc+1
BCS Le5ac
LDY #$00
LDA p3
ADC (p2),Y
STA p3
BCC Le5a0
INC p3+1
CLC
Le5a0: INY
LDA acc
SBC (p2),Y
INY
LDA acc+1
SBC (p2),Y
BCS find_line2
Le5ac: RTS
; token $0B - "NEW"
new_cmd: LSR auto_flag
LDA himem
STA pp
LDA himem+1
STA pp+1
; token $0C - "CLR"
clr: LDA lomem
STA pv
LDA lomem+1
STA pv+1
LDA #$00
STA for_nest_count
STA gosub_nest_count
STA synpag
LDA #$00
STA Z1d
RTS
Le5cc: LDA srch
ADC #$05
STA srch2
LDA tokndxstk
ADC #$00
STA srch2+1
LDA srch2
CMP pp
LDA srch2+1
SBC pp+1
BCC Le5e5
JMP Le36b
Le5e5: LDA acc
STA (srch),Y
LDA acc+1
INY
STA (srch),Y
LDA srch2
INY
STA (srch),Y
LDA srch2+1
INY
STA (srch),Y
LDA #$00
INY
STA (srch),Y
INY
STA (srch),Y
LDA srch2
STA pv
LDA srch2+1
STA pv+1
LDA srch
BCC Le64f
execute_var: STA acc
STY acc+1
JSR get_next_prog_byte
BMI Le623
CMP #$40
BEQ Le623
JMP Le628
.byte $06,$C9,$49,$D0,$07,$A9,$49
Le623: STA acc+1
JSR get_next_prog_byte
Le628: LDA lomem+1
STA tokndxstk
LDA lomem
Le62e: STA srch
CMP pv
LDA tokndxstk
SBC pv+1
BCS Le5cc
LDA (srch),Y
INY
CMP acc
BNE Le645
LDA (srch),Y
CMP acc+1
BEQ Le653
Le645: INY
LDA (srch),Y