-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtb8.pal
3191 lines (2798 loc) · 71.5 KB
/
tb8.pal
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
//
// TB8 - Tiny BASIC for PDP8
// Version 0.01
//
// Project repository at github.com/SmallRoomLabs/TB8
//
// Copyright (c) 2020 Mats Engstrom
// Licensed under the MIT license
//
/NL0000=CLA / 0
/NL0001=CLA IAC / 1
/NL0002=CLA CLL CML RTL / 2
/NL0003=CLA STL IAC RAL / 3
/NL0004=CLA CLL IAC RTL / 4
/NL0006=CLA STL IAC RTL / 6
/NL0100=CLA IAC BSW / 100 64(dec)
/NL2000=CLA CLL CML RTR / 2000 1024(dec)
/NL4000=CLA CLL CML RAR / 4000 2048(dec)
/NL3777=CLA CLL CMA RAR / 3777 2047(dec)
/NL5777=CLA CLL CMA RTR / 5777 3071(dec)
/NL6000=CLA STL IAC RTR / 6000 3072(dec)
/NL7775=CLA CLL CMA RTL / 7775 4093(dec)
/NL7776=CLA CLL CMA RAL / 7776 4094(dec)
NL7777=CLA CMA / 7777 4095(dec)
/NLM3=NL7775 / -3
/NLM2=NL7776 / -2
NLM1=NL7777 / -1
SkpZER=SZA / Skip if Zero Accumulator
SkpNOZ=SNA / Skip if Nonzero Accumulator
SkpNEG=SMA / Skip if Minus Accumulator
SkpPOS=SPA / Skip if Positive Accumulator
SkpNE0=SMA SZA / Skip if Less than or Equal to Zero
SkpGT0=SPA SNA / Skip if Greater than Zero
*0
// ___ ___ ___ ___
// / _ \ / _ \ / _ \ / _ \
// | | | | | | | | | | | | | | | |
// | |_| | | |_| | | |_| | | |_| |
// \___/ \___/ \___/ \___/
/[
IRQ, 0 / Placeholder for future IRQ handler
JMP I IRQ
// _ _ _
// __/\__ __ __ __ _ _ __ (_) __ _ | |__ | | ___ ___
// \ / \ \ / / / _` | | '__| | | / _` | | '_ \ | | / _ \ / __|
// /_ _\ \ V / | (_| | | | | | | (_| | | |_) | | | | __/ \__ \
// \/ \_/ \__,_| |_| |_| \__,_| |_.__/ |_| \___| |___/
//
Key, .-. / Last read key
KBufL, .-. / Current length of string in KBuf
tmp,;tmp1, .-. / Generic temporary variable
tmp2,;A,;tmpH, .-. / Generic temporary variable
tmp3,;B,;tmpL, .-. / Generic temporary variable
*10
PrintP, .-. / Pointer to string to be printed
KBufP, .-. / Pointer to the first free location in KBuf
iP1, .-. / Generic memory pointer
iP2, .-. / Generic memory pointer
iSP, .-. / Stack pointer for GOSUB / FOR
*20
cnt, .-. / Generic counter
cnt2, .-.
src, .-. / Generic source address
dst, .-. / Generic destination address
ADDRS, .-. /???
numH, .-.
numL, .-.
lineH, .-.
lineL, .-.
Arg1,;Arg1H, .-.
Arg1L, .-.
Arg2,;Arg2H, .-.
Arg2L, .-.
C,;ResH, .-.
D,;ResL, .-.
Ctype, .-.
// Variables for SDPRINT
SDLOOP, -7 /COUNT OF SEVEN DIGITS
SDTWO, 260 /BASIC CODE FOR DIGITS
SDPLUS, -15 /"SPACE". TO TYPE "+",REPLACE BY "-2"
SDMNS, -3 /"MINUS"
SDCNT, 0 /STORAGE LOCATIONS
SDHIGH, 0
SDLOW, 0
SDHSUB, 0
SDLSUB, 0
SDBOX, 0
SDTEML, 0
SDGET, 0
SDPTR, 0
// Variables for DMUL
SIGNSW, 0
REST, -2
MULTH, 0
MULTL, 0
MLTL, 0
MLTH, 0
MP3, 0
MP5, 0
// Variables for DIVIDE
DIVCNT, 0
DIVND1, 0
DIVND2, 0
DIVND3, 0
DIVND4, 0
HDIVSR, 0
LDIVSR, 0
M12, -14 / Constant -12(dec)
M13, -15 / Constant -13(dec)
M25, -31 / Constant -25(dec)
P127, 0177 / Constant
P3840, 7400 / Constant
DW1M, 364; 1100 / Double Word constant 1000 000(dec)
DW100K, 30; 3240 / Double Word constant 100 000(dec)
DW10K, 2; 3420 / Double Word constant 10 000(dec)
DW1K, 0; 1750 / Double Word constant 1000(dec)
DW100, 0; 144 / Double Word constant 100(dec)
DW10, 0; 12 / Double Word constant 10(dec)
DW1, 0; 1 / Double Word constant 1(dec)
SDCONL,
DWM1M, 7413; 6700 / Double Word constant -100 0000(dec)
DWM100K,7747; 4540 / Double Word constant -100 000(dec)
DWM10K, 7775; 4360 / Double Word constant -10 000(dec)
DWM1K, 7777; 6030 / Double Word constant -1 000(dec)
DWM100 7777; 7634 / Double Word constant -100(dec)
DWM10, 7777; 7766 / Double Word constant -10(dec)
DWM1, 7777; 7777 / Double Word constant -1(dec)
IntOut, IntOuX
Prompt, PrompX
/]
*200
// ___ ____ ___ ___
// / _ \ |___ \ / _ \ / _ \
// | | | | __) | | | | | | | | |
// | |_| | / __/ | |_| | | |_| |
// \___/ |_____| \___/ \___/
// _ _
// __/\__ ___ | |_ __ _ _ __ | |_
// \ / / __| | __| / _` | | '__| | __|
// /_ _\ \__ \ | |_ | (_| | | | | |_
// \/ |___/ \__| \__,_| |_| \__|
//
/[
KCC / Clear keyboard flag
JMS TxtOut; Greet / Print greeting/header
// ____ _
// | _ \ _ __ ___ _ __ ___ _ __ | |_
// | |_) | | '__| / _ \ | '_ ` _ \ | '_ \ | __|
// | __/ | | | (_) | | | | | | | | |_) | | |_
// |_| |_| \___/ |_| |_| |_| | .__/ \__|
// |_|
//
PrompX, CLA / Clear buffers
DCA lineH
DCA lineL
TAD [-10-120] // TODO Move this into ReadLi
DCA cnt
TAD [TokBuf-1]
DCA iP1
JMS ZeroM
JMS TxtOut; Prmpt / Print TB8 prompt
JMS ReadLi / Collect one line of text from the user.
/ ReadLi returns with the text in KBuf[]
/ and the length of text in KBufL
JMS Tokeni / Tokenize the string. It's hardcoded to
/ use KBuf[] and KBufL as the source and
/ TokBuf[] as destination
/
/ Check if this is a direct command or if it should be inserted
/ into the code buffer. A direct command lacks the line number
/ which then will have a zero value.
/
CLA
TAD (TokBuf-1) / Point to start of tokenized data
DCA iP1
TAD I iP1 / Is LineNo High zero?
SZA
JMP NotDir
TAD I iP1 / Is LineNo Low zero?
SZA
JMP NotDir
/
/ No line number given, so this is a direct command.
/ Currently only RUN, LIST, NEW and FREE are accepted as
/ direct commands
/
ISZ iP1 / Skip the length
TAD I iP1 / Retrieve the command
SkpNOZ / If just an empty line then
JMP I Prompt / go prompt again
/
/ Verify that the command is within the range of direct commands. If
/ outside the allowed range the CkRang will print error and abort
/
JMS CkRang; tkFREE; tkRUN
TAD [tkOFS1+JMPTB1] / Goto to the correct direct command using
DCA JMPVE1 / a jump vector table
TAD I JMPVE1
DCA JMPVE1
JMS TxtOut; CRLF / Do a newline before executing the command
JMP I JMPVE1
JMPVE1, NOP
JMPTB1, dcFREE / tkFREE = -50 7730
dcNEW / tkNEW = -47 7731
dcLIST / tkLIST = -46 7732
dcRUN / tkRUN = -45 7733
/
/ First search for the line in the code base and remove it if it's there
/ already. Then check if the new line is not empty and insert it into
/ the code base.
/
NotDir,
/
/ Start by deleting the specified line from code. This can only be
/ done if the lineNo is exactly matched.
/
CLA CLL
TAD I (TokBuf)
DCA NumH
TAD I (TokBuf+1)
DCA NumL
JMS FndLine / Locate line, return pointer in src
SZL / L is 0 if exact line not found, so skip deleting
JMS CodDel / Delete line pointed to by src
/
/ If the new line if empty (just the line number) then
/ we're done. The user just wanted to delete a line in
/ the source.
/
CLA CLL / Now check if new line is empty
TAD TokBuf+2 / I.E length is 2
TAD [-2]
SNA / Skip if length is not 2
JMP I Prompt
/
/ Make a hole in the code large enough to fit the new line
/
CLA CLL / Now make a hole in the code
TAD TokBuf+2 / Add 2 to the length to fit LineNo
TAD [2]
DCA cnt
TAD src / The destination is 'cnt' away
TAD cnt
DCA dst
TAD src; DCA srcHld
JMS FndEnd
TAD srcHld
CIA
TAD src
TAD cnt
DCA cnt
TAD srcHld; DCA src
JMS CodIns
/
/ Copy the new line into the hole just created
/
CLA CLL / Then copy the new tokens into the code
TAD TokBuf+2
DCA cnt
TAD src
DCA dst
TAD (TokBuf)
DCA src
JMS CodCpy
JMP I Prompt
/]
// _ _ ___ ____ _____
// __| | ___ | | |_ _| / ___| |_ _|
// / _` | / __| | | | | \___ \ | |
// | (_| | | (__ | |___ | | ___) | | |
// \__,_| \___| |_____| |___| |____/ |_|
//
// Direct Command LIST
/[
dcLIST, CLA CLL
JMS List
JMP I Prompt
/]
// _ _____ ____ _____ _____
// __| | ___ | ___| | _ \ | ____| | ____|
// / _` | / __| | |_ | |_) | | _| | _|
// | (_| | | (__ | _| | _ < | |___ | |___
// \__,_| \___| |_| |_| \_\ |_____| |_____|
//
// Direct Command FREE
//
/[
dcFREE, JMS FndEnd
TAD (-CODEND) / Calculate difference between end-of-code
TAD src / memory and the last used location
CIA
DCA tmpL
DCA tmpH
JMS I IntOut;tmpH / Print the calculated number
JMP I Prompt
/]
// _ _ _ _____ __ __
// __| | ___ | \ | | | ____| \ \ / /
// / _` | / __| | \| | | _| \ \ /\ / /
// | (_| | | (__ | |\ | | |___ \ V V /
// \__,_| \___| |_| \_| |_____| \_/\_/
//
//
// Direct Command NEW
//
/[
dcNEW, NL7777 / Set first byte of code buffer to
DCA I (Code) / end-of-code marker 7777
JMP I Prompt
/]
// ____ ___ _____ ___
// ___ / ___| / _ \ |_ _| / _ \
// / __| | | _ | | | | | | | | | |
// | (__ | |_| | | |_| | | | | |_| |
// \___| \____| \___/ |_| \___/
//
//
/[
cGOTO, CLA CLL
JMS Expr; NumH
JMS FndLin / Set src. L=1 if exact match
SZL / Skip if Zero Link
JMP RunNL
JMP Syntax
/]
*400
//
// ___ _ _ ___ ___
// / _ \ | || | / _ \ / _ \
// | | | | | || |_ | | | | | | | |
// | |_| | |__ _| | |_| | | |_| |
// \___/ |_| \___/ \___/
// _ ____ _ _ _ _
// __| | ___ | _ \ | | | | | \ | |
// / _` | / __| | |_) | | | | | | \| |
// | (_| | | (__ | _ < | |_| | | |\ |
// \__,_| \___| |_| \_\ \___/ |_| \_|
//
// Direct Command RUN
//
// The lines of BASIC code are stored in a tokenized format. Each line starts
// with 3 word header consisting of the high and low part of the LineNo and
// a length denoting the number of additional bytes that must be read to
// reach the start of the next line.
//
// If the lineNo is negative (the high word of the lineNo is 7777) then the
// end-of-code is reached and an implicit END command is executed.
//
// This is followed by token words that are just a straight translation of
// the keywords and numbers entered by the user.
//
// The end-of-line is denoted using a 0-token
//
//
/[
dcRUN, CLA CLL
TAD (Code) / Start execution at first line of code
DCA src
TAD (TokBuf-1)/ Initailzie Stack Pointer
DCA iSP / Set SP
DCA I iSP / Set first entry in SP as 0/empty
/
/ We're at the beginning of a new line of code, so save the
/ two first words as into the lineNo variables for later usage
/ and then skip over the length byte. (It's only used in the
/ FndLin function to quickly find a specific line)
/
RunNL, CLA CLL
TAD I src / Get the high part of the lineNo
ISZ src / Advance the source pointer
SPA / If it's not negative then it's a real lineNo
JMP I Prompt / if negative it's end-of-code, so goto Prompt
DCA lineH / Save the ight part of lineNo
TAD I src / get it and store it
ISZ src / Advance the source pointer
DCA lineL
ISZ src / Finally advance past the length byte
/
/ All commands will JMP to here when they have reached either
/ the end-of-line 0, or the tkCOLO (colon). If it's 0 then
/ goto RunNL to start processing of a new line. If it's tkCOLO
/ goto back here to process the next token on the line. The
/ tkCOLO is handled in the jump-vector table as any other
/ token.
/
Runnin, CLA CLL
KRS / Read keyboard static
TAD (-203) / Check if received ^C from keyboard
SkpNOZ
JMP I Prompt / If ^C then jump to prompt
CLA CLL / Get token
TAD I src
ISZ src / Advance the token pointer
SkpNOZ / Check if token is 0000 (end-of-line)
JMP RunNL / yes, then go process a new line from beginning
TAD (tkOFS2+JMPTB2)
DCA JMPVE2
TAD I JMPVE2
DCA JMPVE2
JMP I JMPVE2
JMPVE2, 0
JMPTB2,
PrompX / tkEND=-35 Jump to end prompt to end the execution
cRETURN / tkRETU=-34
cGOSUB / tkGOSU=-33
cGOTO / tkGOTO=-32
cNEXT / tkNEXT=-31
cFOR / tkFOR=-30
cIFF / tkIF= -27
cPRINT / tkPRIQ=-26
cPRINT / tkPRIN=-25
cGET / tkGET=-24
cINPUT / tkINPU=-23
cLET / tkLET=-22
Running / tkCOLO=-21 Just continue executing in the line
cREM / tkREM=-20
/]
/
/ Unimplemented commands
/
cGET,
JMP I Prompt
// ____ _ ____ _
// / ___| ___ __| | | _ \ ___ | |
// | | / _ \ / _` | | | | | / _ \ | |
// | |___ | (_) | | (_| | | |_| | | __/ | |
// \____| \___/ \__,_| |____/ \___| |_|
//
/[
CodDel, 0
CLA
TAD src / Get code line start
TAD [-1] / adjust for autoinc
DCA iP2 / iP2 is autoincrementing destination
TAD src
IAC / Get length of line to delete
IAC
DCA tmp
TAD I tmp
TAD src / Add the length to code line start
IAC / Adjust for LineNo and autoinc
DCA iP1 / iP1 is autoincrementing source
CodDe0, CLA
TAD I iP1 / Copy code data
DCA I iP2
TAD CODEND / Reached end of code?
CIA
TAD iP1
SZA
JMP CodDe0
JMP I CodDel
/]
// ____ _ ___
// / ___| ___ __| | |_ _| _ __ ___
// | | / _ \ / _` | | | | '_ \ / __|
// | |___ | (_) | | (_| | | | | | | | \__ \
// \____| \___/ \__,_| |___| |_| |_| |___/
//
// Backwards copy 'cnt' bytes from 'src' to 'dst'
//
// Inputs: src, dst, cnt
// Modifies: src, dst, cnt, memory
// Outputs:
/[
CodIns,0
CLA CLL
TAD cnt / Offset to last byte
TAD src
DCA src
TAD cnt / Offset to last byte
TAD dst
DCA dst
TAD cnt / Make cnt negative for ISZ
CIA
DCA cnt
CodIn0,
NLM1 / src--
TAD src
DCA src
NLM1 / dst--
TAD dst
DCA dst
TAD I src / Move [src] -> [dst]
DCA I dst
ISZ cnt / Loop until all 'cnt' bytes are moved
JMP CodIn0
JMP I CodIns
/]
// ____ _ ____
// / ___| ___ __| | / ___| _ __ _ _
// | | / _ \ / _` | | | | '_ \ | | | |
// | |___ | (_) | | (_| | | |___ | |_) | | |_| |
// \____| \___/ \__,_| \____| | .__/ \__, |
// |_| |___/
/[
CodCpy, 0
CLA
TAD cnt
IAC
CMA
DCA cnt
CodCp0,
TAD I src
DCA I dst
ISZ src
ISZ dst
ISZ cnt
JMP CodCp0
JMP I CodCpy
/]
// ____ _____ __ __
// ___ | _ \ | ____| | \/ |
// / __| | |_) | | _| | |\/| |
// | (__ | _ < | |___ | | | |
// \___| |_| \_\ |_____| |_| |_|
//
// Skip the rest of the line
//
/[
cREM, CLA IAC CLL / Take the current line number + 1
TAD LineL
DCA NumL
RAL
TAD LineH
DCA NumH
JMS FndLin / and then search for that line number.
JMP RunNL
/]
// ____ _
// / ___| _ _ _ __ | |_ __ _ __ __
// \___ \ | | | | | '_ \ | __| / _` | \ \/ /
// ___) | | |_| | | | | | | |_ | (_| | > <
// |____/ \__, | |_| |_| \__| \__,_| /_/\_\
// |___/
/[
Syntax, JMS TxtOut; SynErr
JMS I IntOut; lineH
JMS TxtOut; CRLF
JMP I Prompt
/]
*600
// ___ __ ___ ___
// / _ \ / /_ / _ \ / _ \
// | | | | | '_ \ | | | | | | | |
// | |_| | | (_) | | |_| | | |_| |
// \___/ \___/ \___/ \___/
// ____ ___ ____ _ _ ____
// ___ / ___| / _ \ / ___| | | | | | __ )
// / __| | | _ | | | | \___ \ | | | | | _ \
// | (__ | |_| | | |_| | ___) | | |_| | | |_) |
// \___| \____| \___/ |____/ \___/ |____/
//
/[
cGOSUB, CLA CLL
JMS Expr; NumH
JMS PushAd
JMS FndLin / Set src. L=1 if exact match
SZL / Skip if Zero Link
JMP RunNL
JMP Syntax
JMP Running
/]
// ____ _____ _____ _ _ ____ _ _
// ___ | _ \ | ____| |_ _| | | | | | _ \ | \ | |
// / __| | |_) | | _| | | | | | | | |_) | | \| |
// | (__ | _ < | |___ | | | |_| | | _ < | |\ |
// \___| |_| \_\ |_____| |_| \___/ |_| \_\ |_| \_|
//
/[
cRETURN,
JMS PopAd
JMP Running
/]
// ____ _ _ _
// | _ \ _ _ ___ | |__ / \ __| |
// | |_) | | | | | / __| | '_ \ / _ \ / _` |
// | __/ | |_| | \__ \ | | | | / ___ \ | (_| |
// |_| \__,_| |___/ |_| |_| /_/ \_\ \__,_|
//
// Pushes the current src onto the common stack for GOSUB. Each
// entry of the stack begins with the data followed by the length
// of the data. The lenght byte is only used when POP'ing from so
// it needs to be after the data block. The first word of the stack
// if set to 0 in cRUN and acts as a marker for an empty stack.
//
/[
PushAd, 0
CLA CLL
TAD src
DCA I iSP / Push the Address value
CLA IAC CLL / Load AC=1 L=0
DCA I iSP / Push 1 for Type
JMP I PushAd
/]
// ____ _ _____
// | _ \ _ _ ___ | |__ | ___| ___
// | |_) | | | | | / __| | '_ \ | |_ / _ \
// | __/ | |_| | \__ \ | | | | | _| | (_) |
// |_| \__,_| |___/ |_| |_| |_| \___/
//
//
// 1var, 2final, 1src
//
//
//
//[
/PushFo, 0
/ CLA CLL
/ TAD (-1)
/ DCA I iSP / Push the variable
/ TAD (-1)
/ DCA I iSP / Push the finalH
/ TAD (-1)
/ DCA I iSP / Push the finalL
/ TAD (-1)
/ DCA I iSP / Push the src
/ TAD (5) / Push 4 for Type
/ DCA I iSP
/ JMP I PushFo
//]
// ____ _ _
// | _ \ ___ _ __ / \ __| |
// | |_) | / _ \ | '_ \ / _ \ / _` |
// | __/ | (_) | | |_) | / ___ \ | (_| |
// |_| \___/ | .__/ /_/ \_\ \__,_|
// |_|
/[
PopAd, 0
PopAdL, CLA CLL
TAD iSP / Get the type for what SP is pointing to
DCA tmp
TAD I tmp
SkpNOZ
JMP Syntax / If type=0 then at end of stack, can't pop then
TAD (-1) / Check if type is 1
SkpNOZ
JMP PopAd1
/ If the type is not 0 or 1 it must be 4 (FOR)
CLA CLL
TAD iSP / Back the SP down five words so it points to
TAD [-5] / the previous entry
DCA iSP
JMP PopAdL
PopAd1, TAD (-1) / The pushed value is 1 before the current SP
TAD tmp
DCA tmp
TAD I tmp / Get the value and store it in src
DCA src
TAD iSP / Back the SP down two words so it points to
TAD [-2] / the previous entry
DCA iSP
JMP I PopAd
/]
// ____ _____
// | _ \ ___ _ __ | ___| ___
// | |_) | / _ \ | '_ \ | |_ / _ \
// | __/ | (_) | | |_) | | _| | (_) |
// |_| \___/ | .__/ |_| \___/
// |_|
//[
/PopFo, 0
/ CLA CLL
/ JMP I PopFo
//]
// _____ _ _____ _
// | ___| _ __ __| | | ____| _ __ __| |
// | |_ | '_ \ / _` | | _| | '_ \ / _` |
// | _| | | | | | (_| | | |___ | | | | | (_| |
// |_| |_| |_| \__,_| |_____| |_| |_| \__,_|
//
// Return the location of the end-of-code marker 7777.
//
// Destroys numH, numL
// Returns location in src
//
/[
FndEnd, 0
CLA CLL
TAD (3777) / Search for location of last line of code
DCA numH
TAD (7777)
DCA numL
JMS FndLin
CLA CLL
JMP I FndEnd
/]
// _____ _ _ _
// | ___| _ __ __| | | | (_) _ __
// | |_ | '_ \ / _` | | | | | | '_ \
// | _| | | | | | (_| | | |___ | | | | | |
// |_| |_| |_| \__,_| |_____| |_| |_| |_|
//
// Find the starting address of the specified (or the next higher) line
// number in the code area.
//
// Enter with desired line number in NumH/numL
// Returns with src pointing to the line.
// L=1 if exact match, L=0 if the next higher is found
//
// Destroys tmp, tmpH, tmpL
/[
FndLin, 0
CLA
TAD [CODE]
DCA src
FndLi0, CLA
TAD src
DCA tmp
TAD I tmp / Fetch Line No from code
SPA / If LineNoH is not negative we not at end
JMP FndLiL / Exit with src at end of code and L=0
DCA tmpH
ISZ tmp
TAD I tmp
DCA tmpL
TAD [tkGTEQ] / GREATER THAN OR EQUAL op for Compar
JMS Compar; TmpH; NumH
SZL / Skip if no match
JMP FndLiM
ISZ src / Skip LineNoH
ISZ src / Skip LineNoL
CLA
TAD src / Get length
TAD I src / and skip over the length as well
DCA src
JMP FndLi0
/
/ Found a line that is either equal or larger than the desired line no
/ so compare Tmp and Num to see if they're equal and then return L=1,
/ else return L=0
/
FndLiM,
CLA
TAD TmpH
CIA
TAD NumH
SZL
JMP FndLiL
CLA
TAD TmpL
CIA
TAD NumL
SZL
JMP FndLiE
FndLiL, CLL / Found larger, return with L=0
JMP I FndLin / Exit with src pointing to start of line
FndLiE, CLL CML / Found exact, return with L=1
JMP I FndLin / Exit with src pointing to start of line
/]
*1000
// _ ___ ___ ___
// / | / _ \ / _ \ / _ \
// | | | | | | | | | | | | | |
// | | | |_| | | |_| | | |_| |
// |_| \___/ \___/ \___/
// ___ _____
// ___ |_ _| | ___|
// / __| | | | |_
// | (__ | | | _|
// \___| |___| |_|
//
// IF <expr1> <cond> <expr2> THEN <code>
/[
cIFF, JMS Expr; left / Get expression #11
CLA CLL / Get the condition
TAD I src
JMS CkRang; tkLT; tkEQ / Verify valid comparison token
ISZ src
DCA IFcomp / Store it for later
JMS Expr; right / Get expression #2
CLA CLL / Get the THEN
TAD I src
JMS CkRang; tkTHEN; tkTHEN / Verify THEN token
ISZ src
CLA CLL / Compare the expressions using stored
TAD IFcomp / comparison mode
JMS Compar; Left; Right
SZL / Skip on L=0 (failed comparison)
JMP Running / If successful comparison continue parsing the line]
/
/ The comparison failed, so we need to find the start of the next line
/ and start running from there. This is just what the REM command is doing
/ so we can simply jump to the the REM command to do this.
/
JMP cREM
IFcomp, 0
left, 0;0
right, 0;0
/]
// _ _____ _____
// ___ | | | ____| |_ _|
// / __| | | | _| | |
// | (__ | |___ | |___ | |
// \___| |_____| |_____| |_|
//
// LET <var> = <expr>
//
// This command simply calls the doLet function. It is broken out as
// a separate function to be able to be utilized in the first part of
// the FOR command
/[
cLET, JMS doLet
JMP Running
/]
// _ _ _
// __| | ___ | | ___ | |_
// / _` | / _ \ | | / _ \ | __|
// | (_| | | (_) | | |___ | __/ | |_
// \__,_| \___/ |_____| \___| \__|
//
/[
doLET, 0
CLA CLL
TAD I src / Check if token is Variable
JMS CkRang; tkVAR; tkVAR / Check if token is Variable
ISZ src
CLA CLL
TAD I src / Get destination variable address
JMS UCase
TAD (-301) / Ucase sets parity, so subtract A plus parity
JMS CkRang; 0; 31 / Verify A-Z
CLL RAL
TAD (AZvars)
DCA cLetDst
ISZ src
CLA CLL
TAD I src
JMS CkRang; tkEQ; tkEQ / Check if token is "="
ISZ src
JMS Expr
cLetDst,0
JMP I doLet
/]
// ___ _ _ ____ _ _ _____
// ___ |_ _| | \ | | | _ \ | | | | |_ _|
// / __| | | | \| | | |_) | | | | | | |
// | (__ | | | |\ | | __/ | |_| | | |
// \___| |___| |_| \_| |_| \___/ |_|
//
/[
cINPUT, CLA CLL
TAD I src / Check if token is Variable
JMS CkRang; tkVAR; tkVAR / Check if token is Variable
ISZ src
CLA CLL
TAD I src / Get destination variable address
JMS UCase
TAD (-301) / Ucase sets parity, so subtract A plus parity
JMS CkRang; 0; 31 / Verify A-Z
CLL RAL
TAD (AZvars)
DCA cInpDst
ISZ src
TAD src / Save src as it's getting destroyed
DCA cINPhl / by ReadLi
JMS ReadLi / Collect one line of text from the user.
/ ReadLi returns with the text in KBuf[]
/ and the length of text in KBufL
CLA CLL
TAD [KBuf]
DCA src
JMS SkipSp / Skip spaces
JMS ATOL / Reads from src, stores in numH,numL
CLA
TAD numH / Get high part of line number
DCA I cInpDst
ISZ cInpDst
TAD numL / Get low part of line number
DCA I cInpDst