-
Notifications
You must be signed in to change notification settings - Fork 1
/
BasTo6809.1.Tokenizer.bas
3206 lines (3100 loc) · 150 KB
/
BasTo6809.1.Tokenizer.bas
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
$ScreenHide
$Console
_Dest _Console
Verbose = 0
Dim Array(270000) As _Unsigned _Byte
Dim INArray(270000) As _Unsigned _Byte
Dim LabelName$(100000)
Dim NumericVariable$(100000)
Dim NumericVariableCount As Integer
Dim FloatVariable$(100000)
Dim FloatVariableCount As Integer
Dim StringVariable$(100000)
Dim StringVariableCounter As Integer
Dim NumericArrayVariables$(100000), NumericArrayDimensions(100000) As Integer, NumericArrayDimensionsVal$(100000)
Dim StringArrayVariables$(100000), StringArrayDimensions(100000) As Integer, StringArrayDimensionsVal$(100000)
Dim GeneralCommands$(2000)
Dim GeneralCommandsCount As Integer
Dim NumericCommands$(2000)
Dim NumericCommandsCount As Integer
Dim StringCommands$(2000)
Dim StringCommandsCount As Integer
Dim OperatorCommands$(2000)
Dim OperatorCommandsCount As Integer
Dim GeneralCommandsFound$(2000)
Dim GeneralCommandsFoundCount As Integer
Dim NumericCommandsFound$(2000)
Dim NumericCommandsFoundCount As Integer
Dim StringCommandsFound$(2000)
Dim StringCommandsFoundCount As Integer
Dim IncludeList$(10000)
Dim DefLabel$(10000)
Dim DefVar(1000) As Integer
DefLabelCount = 0
DefVarCount = 0
Dim Signed16bit As Integer
Open "Basic_Commands/BasTo6809_CommandsGeneral.dat" For Input As #1
GeneralCommandsCount = 0
While EOF(1) = 0
Line Input #1, i$
GeneralCommandsCount = GeneralCommandsCount + 1
GeneralCommands$(GeneralCommandsCount) = i$
Wend
Close #1
Open "Basic_Commands/BasTo6809_CommandsNumeric.dat" For Input As #1
NumericCommandsCount = 0
While EOF(1) = 0
Line Input #1, i$
NumericCommandsCount = NumericCommandsCount + 1
NumericCommands$(NumericCommandsCount) = i$
Wend
Close #1
Open "Basic_Commands/BasTo6809_CommandsString.dat" For Input As #1
StringCommandsCount = 0
While EOF(1) = 0
Line Input #1, i$
StringCommandsCount = StringCommandsCount + 1
StringCommands$(StringCommandsCount) = i$
Wend
Close #1
Open "Basic_Commands/BasTo6809_CommandsOperators.dat" For Input As #1
OperatorCommandsCount = 0
While EOF(1) = 0
Line Input #1, i$
i$ = Right$(i$, Len(i$) - 1)
i$ = Left$(i$, InStr(i$, ",") - 2)
OperatorCommandsCount = OperatorCommandsCount + 1
OperatorCommands$(OperatorCommandsCount) = i$
Wend
Close #1
Check$ = "IF": GoSub FindGenCommandNumber ' Gets the General Command number of Check$, returns with number in ii, Found=1 if found and Found=0 if not found
C_IF = ii
Check$ = "THEN": GoSub FindGenCommandNumber ' Gets the General Command number of Check$, returns with number in ii, Found=1 if found and Found=0 if not found
C_THEN = ii
Check$ = "ELSE": GoSub FindGenCommandNumber ' Gets the General Command number of Check$, returns with number in ii, Found=1 if found and Found=0 if not found
C_ELSE = ii
Check$ = "GOTO": GoSub FindGenCommandNumber ' Gets the General Command number of Check$, returns with number in ii, Found=1 if found and Found=0 if not found
C_GOTO = ii
Check$ = "END": GoSub FindGenCommandNumber ' Gets the General Command number of Check$, returns with number in ii, Found=1 if found and Found=0 if not found
C_END = ii
Check$ = "DIM": GoSub FindGenCommandNumber ' Gets the General Command number of Check$, returns with number in ii, Found=1 if found and Found=0 if not found
C_DIM = ii
Check$ = "DATA": GoSub FindGenCommandNumber ' Gets the General Command number of Check$, returns with number in ii, Found=1 if found and Found=0 if not found
C_DATA = ii
Check$ = "REM": GoSub FindGenCommandNumber ' Gets the General Command number of Check$, returns with number in ii, Found=1 if found and Found=0 if not found
C_REM = ii
Check$ = "'": GoSub FindGenCommandNumber ' Gets the General Command number of Check$, returns with number in ii, Found=1 if found and Found=0 if not found
C_REMApostrophe = ii
Check$ = "PRINT": GoSub FindGenCommandNumber ' Gets the General Command number of Check$, returns with number in ii, Found=1 if found and Found=0 if not found
C_PRINT = ii
Check$ = "PSET": GoSub FindGenCommandNumber ' Gets the General Command number of Check$, returns with number in ii, Found=1 if found and Found=0 if not found
C_PSET = ii
Check$ = "PRESET": GoSub FindGenCommandNumber ' Gets the General Command number of Check$, returns with number in ii, Found=1 if found and Found=0 if not found
C_PRESET = ii
Check$ = "GET": GoSub FindGenCommandNumber ' Gets the General Command number of Check$, returns with number in ii, Found=1 if found and Found=0 if not found
C_GET = ii
Check$ = "PUT": GoSub FindGenCommandNumber ' Gets the General Command number of Check$, returns with number in ii, Found=1 if found and Found=0 if not found
C_PUT = ii
' Handle command line options
FI = 0
count = _CommandCount
If count = 0 Then
Print "Compiler has no options given to it"
System
End If
nt = 0: newp = 0: endp = 0: BranchCheck = 0: StringArraySize = 255: AutoStart = 0
Optimize = 2 ' Default to optimize level 2
For check = 1 To count
N$ = Command$(check)
If LCase$(Left$(N$, 2)) = "-c" Then BASICMode = Val(Right$(N$, Len(N$) - 2)): GoTo CheckNextCMDOption
If LCase$(Left$(N$, 2)) = "-s" Then StringArraySize = Val(Right$(N$, Len(N$) - 2)): GoTo CheckNextCMDOption
If LCase$(Left$(N$, 2)) = "-o" Then Optimize = Val(Right$(N$, Len(N$) - 2)): GoTo CheckNextCMDOption
If LCase$(Left$(N$, 2)) = "-b" Then BranchCheck = Val(Right$(N$, Len(N$) - 2)): GoTo CheckNextCMDOption
If LCase$(Left$(N$, 2)) = "-v" Then Verbose = Val(Right$(N$, Len(N$) - 2)): GoTo CheckNextCMDOption
If LCase$(Left$(N$, 2)) = "-p" Then ProgramStart$ = Right$(N$, Len(N$) - 2): GoTo CheckNextCMDOption
If LCase$(Left$(N$, 2)) = "-f" Then Font$ = Right$(N$, Len(N$) - 2): GoTo CheckNextCMDOption
If LCase$(Left$(N$, 2)) = "-a" Then AutoStart = 1: GoTo CheckNextCMDOption
' check if we got a file name yet if so then the next filename will be output
OutName$ = N$
CheckNextCMDOption:
Next check
' Fill the Array() with the preformatted BASIC text file
Fname$ = "BASIC_Text.bas"
Open Fname$ For Append As #1
length = LOF(1)
Close #1
If length < 1 Then Print "Error file: "; Fname$; " is 0 bytes. Or doesn't exist.": Kill Fname$: End
If Verbose > 0 Then Print "Length of Input file in bytes:"; length
Open Fname$ For Binary As #1
Get #1, , Array()
Close #1
Array(length) = &H0D: length = length + 1 ' add one last EOL
' Get the line Labels first so we can recognize them if there is a forward reference to a Label we haven't come across yet
NumericVariableCount = 0 ' Numeric variable name count
NumericVariable$(NumericVariableCount) = "Timer" ' Make the first variable the TIMER
NumericVariableCount = NumericVariableCount + 1 ' Numeric variable name count
x = 0
INx = 0
lc = 0
LineCount = 0
FloatVariableCount = 0 ' Floating Point variable name count
StringVariableCounter = 0 ' String variable name count
CommandsUsedCounter = 0 ' Counter for unique commmands used
NumArrayVarsUsedCounter = 0 ' Counter for number of NumericArrays used
StringArrayVarsUsedCounter = 0 ' Counter for number of String Array Variables used
Check$ = "REM": GoSub FindGenCommandNumber ' Gets the General Command number of Check$, returns with number in ii, Found=1 if found and Found=0 if not found
C_REM = ii
While x < length - 1 ' Loop until we've processed the entire BASIC program
' Start of new line
' Searching for Inline assembly - read a full line
y = x
v = 0
Temp$ = ""
Do Until x >= length Or v = &H0D
v = Array(x): x = x + 1
Temp$ = Temp$ + Chr$(v)
Loop
p = InStr(Temp$, "ADDASSEM")
If p > 0 Then
' We found the start of some inline assembly
' Ignore any labels found here...
'copy lines unaltered until we get a ENDASSEM
REM_AddCodeAlpha0:
Temp$ = ""
v = 0
Do Until x >= length Or v = &H0D
v = Array(x): x = x + 1
Temp$ = Temp$ + Chr$(v)
Loop
' Check if this line is the last
If InStr(Temp$, "ENDASSEM") = 0 Then GoTo REM_AddCodeAlpha0
Else
x = y
End If
CheckLineSpaces0:
v = Array(x): x = x + 1
If v = &H20 Then GoTo CheckLineSpaces0 ' Skip spaces at the beginning of a line
If v = &H0D Or v = &H0A Then GoTo GotLabel ' Skip to the bottom if we get a line feed or carriage return, this is an empty line
Tokenized$ = ""
CurrentLine$ = ""
'Figure out if we have a line number or a label:
If v >= Asc("0") And v <= Asc("9") Then ' Check if line starts with a number
'Does start with a number
LineCount = LineCount + 1
While v >= Asc("0") And v <= Asc("9") ' is it a number?
LabelName$(LineCount) = LabelName$(LineCount) + Chr$(v)
v = Array(x): x = x + 1
Wend
If Verbose > 0 Then Print "Scanning line "; LabelName$(LineCount)
CurrentLine$ = LabelName$(LineCount)
If IsNumber(LabelName$(LineCount)) = 0 Then Print "Error: There's something wrong with the Line number or Label "; LabelName$(LineCount): System
If v = &H0D Then
' this is a number line only
GoTo GotLabel ' Skip to the bottom if we get a line feed or carriage return, this is an empty line
End If
Else
'Not a line number, figure out if this line starts with a BASIC command
T = Asc(UCase$(Chr$(v)))
If T >= Asc("A") And T <= Asc("Z") Then
'Maybe found a label
Check$ = ""
y = x - 1
While v <> Asc(":") And v <> &H0D And v <> &H0A And v <> Asc(" ")
Check$ = Check$ + Chr$(v)
v = Array(x): x = x + 1
Wend
CheckLC$ = Check$
If v = Asc(":") And Array(x) = &H0D Then
'Could be a label or a general command with a colon after it
' Check for a General command
Found = 0
For c = 1 To GeneralCommandsCount
Temp$ = UCase$(GeneralCommands$(c))
Check$ = UCase$(Check$)
If Temp$ = Check$ Then
'Found a General Command
Found = 1: Exit For
End If
Next c
If Found = 0 Then
' It is a label
LineCount = LineCount + 1
LabelName$(LineCount) = CheckLC$
CurrentLine$ = LabelName$(LineCount)
If Verbose > 0 Then Print "Scanning line "; LabelName$(LineCount); ":"
Tokenized$ = ""
GoTo GotLabel
End If
End If
x = y
End If
End If
v = Array(x): x = x + 1
While v <> &H0D
v = Array(x): x = x + 1
Wend
GotLabel:
Wend
' Get commands and variables used in program
' Tokenize the text version of the BASIC program to make it easier to handle parsing expressions
If Verbose > 0 Then Print "Doing Pass 1 - Finding commands and variables used"
x = 0
INx = 0
lc = 0
LineCountB = 0
If Verbose > 1 Then Print "Done scanning for labels"; LineCount
While x < length - 1 ' Loop until we've processed the entire BASIC program
' Start of new line
' Searching for Inline assembly - read a full line
y = x
v = 0
Temp$ = ""
Do Until x >= length Or v = &H0D
v = Array(x): x = x + 1
Temp$ = Temp$ + Chr$(v)
Loop
p = InStr(Temp$, "ADDASSEM")
If p > 0 Then
' We found the start of some inline assembly
' Copy the line number or label
' Tokenized$ = Chr$(Len(CurrentLine$)) + CurrentLine$ + Tokenized$ + Chr$(&HF5) + Chr$(&H0D) ' Line ends with $F50D
CurrentLine$ = ""
If Asc(Left$(Temp$, 1)) >= &H30 And Asc(Left$(Temp$, 1)) <= &H39 Then
For ii = 1 To Len(Temp$)
If Mid$(Temp$, ii, 1) = Chr$(&H20) Then Exit For
CurrentLine$ = CurrentLine$ + Mid$(Temp$, ii, 1)
Next ii
End If
Num = C_REM: GoSub NumToMSBLSBString ' Convert number in num to 16 bit value in MSB$ & LSB$ and MSB & LSB
' INArray(INx) = MSB: INx = INx + 1: INArray(INx) = LSB: INx = INx + 1 ' write command to ouput array
Temp$ = Chr$(Len(CurrentLine$)) + CurrentLine$ + Chr$(&HFF) + Chr$(MSB) + Chr$(LSB) + " ADDASSEM:" + Chr$(&HF5) + Chr$(&H0D)
For ii = 1 To Len(Temp$)
INArray(INx) = Asc(Mid$(Temp$, ii, 1)): INx = INx + 1
Next ii
' Copy lines unaltered until we get a ENDASSEM
REM_AddCode0:
v = 0
Temp$ = ""
Do Until x >= length Or v = &H0D
v = Array(x): x = x + 1
Temp$ = Temp$ + Chr$(v)
Loop
' Check if this line is the last
p = InStr(Temp$, "ENDASSEM")
If p = 0 Then
For ii = 1 To Len(Temp$)
INArray(INx) = Asc(Mid$(Temp$, ii, 1)): INx = INx + 1
Next ii
GoTo REM_AddCode0
End If
Num = C_REM: GoSub NumToMSBLSBString ' Convert number in num to 16 bit value in MSB$ & LSB$ and MSB & LSB
' INArray(INx) = MSB: INx = INx + 1: INArray(INx) = LSB: INx = INx + 1 ' write command to ouput array
Temp$ = Chr$(0) + Chr$(&HFF) + Chr$(MSB) + Chr$(LSB) + " ENDASSEM:" + Chr$(&HF5) + Chr$(&H0D)
For ii = 1 To Len(Temp$)
INArray(INx) = Asc(Mid$(Temp$, ii, 1)): INx = INx + 1
Next ii
GoTo ScanNextLine ' Skip to the bottom
Else
x = y
End If
v = Array(x): x = x + 1
If v = &H20 Then GoTo ScanNextLine ' Skip spaces at the beginning of a line
If v = &H0D Then GoTo ScanNextLine ' Skip to the bottom if we get a line feed or carriage return, this is an empty line
Tokenized$ = ""
CurrentLine$ = ""
'Figure out if we have a line number or a label:
If v >= Asc("0") And v <= Asc("9") Then ' Check if line starts with a number
'Does start with a number
LineCountB = LineCountB + 1
While v >= Asc("0") And v <= Asc("9") ' is it a number?
' LabelName$(LineCountB) = LabelName$(LineCountB) + Chr$(v)
v = Array(x): x = x + 1
Wend
If Verbose > 0 Then Print "Scanning line "; LabelName$(LineCount)
CurrentLine$ = LabelName$(LineCountB)
If IsNumber(LabelName$(LineCountB)) = 0 Then
Print "There's something wrong with the Line number or Label "; LabelName$(LineCountB): System
End If
If v = &H0D Then
' this is a number line only
GoTo ScanNextLine ' Skip to the bottom if we get a line feed or carriage return, this is an empty line
End If
Else
'Not a line number, figure out if this line starts with a BASIC command
T = Asc(UCase$(Chr$(v)))
If T >= Asc("A") And T <= Asc("Z") Then
'Maybe found a label
Check$ = ""
Start = x - 1
While v <> Asc(":") And v <> &H0D And v <> Asc(" ")
Check$ = Check$ + Chr$(v)
v = Array(x): x = x + 1
Wend
If v = Asc(":") And Array(x) = &H0D Then
'Could be a label or a general command with a colon after it
' Check for a General command
Found = 0
For c = 1 To GeneralCommandsCount
Temp$ = UCase$(GeneralCommands$(c))
Check$ = UCase$(Check$)
If Temp$ = Check$ Then
'Found a General Command
Found = 1
End If
Next c
If Found = 0 Then
' It is a label
LineCountB = LineCountB + 1
CurrentLine$ = LabelName$(LineCountB)
If Verbose > 0 Then Print "Scanning line "; LabelName$(LineCountB); ":"
Tokenized$ = ""
GoTo LabelOnlyLine
End If
End If
x = Start
v = Array(x): x = x + 1
End If
End If
' Get the first argument/command
' No line number or label
GetFirstArg:
Expression$ = ""
ColonCount = 0
If v = &H20 Then v = Array(x): x = x + 1 ' skip past the first space on the line
'Get the rest of this line as it is
While v <> &H0D And x < length
If v = &H22 Then ' is it a quote"
Expression$ = Expression$ + Chr$(v)
v = Array(x): x = x + 1
' Yes deal with text in quotes, copy all until we get an end quote or RETURN
While v <> &H22 And v <> &H0D
Expression$ = Expression$ + Chr$(v)
v = Array(x): x = x + 1
Wend
If v = &H0D Then
' we got the end of the line without an end quote, let's add one
Expression$ = Expression$ + Chr$(&H22)
GoTo DoneGetFirstArg
End If
If v = &H22 Then ' did we get the end quote?
'Yes got the end quote
Expression$ = Expression$ + Chr$(v)
GoTo GetMoreArgs
End If
Else
' Not inside a quote
If v = Asc(":") Then
Expression$ = Expression$ + Chr$(&HF5) ' flag colons as special characters $F53A
While Array(x) = Asc(" ")
x = x + 1 ' skip the spaces after a ":"
Wend
End If
If v = Asc("?") Then ' Change ? to a PRINT command
Expression$ = Expression$ + "PRINT "
Else
Expression$ = Expression$ + Chr$(v)
End If
End If
GetMoreArgs:
v = Array(x): x = x + 1
Wend
DoneGetFirstArg:
If InStr(0, Expression$, "THEN " + Chr$(&HF5) + ":") > 0 Then
' Fix THEN :ELSE to be THEN ELSE
While InStr(0, Expression$, "THEN " + Chr$(&HF5) + ":") > 0
Expression$ = Left$(Expression$, InStr(0, Expression$, "THEN " + Chr$(&HF5) + ":") + 4) + Right$(Expression$, Len(Expression$) - InStr(0, Expression$, "THEN " + Chr$(&HF5) + ":") - 6)
Wend
End If
GoSub TokenizeExpression ' Go tokenize Expression$
LabelOnlyLine:
Tokenized$ = Chr$(Len(CurrentLine$)) + CurrentLine$ + Tokenized$ + Chr$(&HF5) + Chr$(&H0D) ' Line ends with $F50D
For ii = 1 To Len(Tokenized$)
INArray(INx) = Asc(Mid$(Tokenized$, ii, 1)): INx = INx + 1
Next ii
ScanNextLine:
Wend
If Verbose > 0 Then
' Print the commands used and variables used by this BASIC program
Print "General Commands Used:"
For ii = 0 To GeneralCommandsFoundCount - 1
Print GeneralCommandsFound$(ii)
Next ii
Print "Numeric Commands Used:"
For ii = 0 To NumericCommandsFoundCount - 1
Print NumericCommandsFound$(ii)
Next ii
Print "String Commands Used:"
For ii = 0 To StringCommandsFoundCount - 1
Print StringCommandsFound$(ii)
Next ii
Print "Floating Point Variables Used:"
For ii = 0 To FloatVariableCount - 1
Print FloatVariable$(ii)
Next ii
Print "Numeric Variables Used:"
For ii = 0 To NumericVariableCount - 1
Print NumericVariable$(ii)
Next ii
Print "String Variables Used:"
For ii = 0 To StringVariableCounter - 1
Print StringVariable$(ii)
Next ii
Print "Numeric Arrays Used:"
For ii = 0 To NumArrayVarsUsedCounter - 1
Print NumericArrayVariables$(ii); " which has"; NumericArrayDimensions(ii); "Dimensions"
Next ii
Print "String Arrays Used:"
For ii = 0 To StringArrayVarsUsedCounter - 1
Print StringArrayVariables$(ii); " which has"; StringArrayDimensions(ii); "Dimensions"
Next ii
End If
' Write tokenized data to file
' Copy array to output file first byte of the array is 0
' Example: array(0),array(1),array(2),...,array(length)
filesize = INx - 1
c = 0
For OP = 0 To filesize
Array(c) = INArray(OP): c = c + 1
Next OP
ReDim LastOutArray(filesize) As _Unsigned _Byte
c = 0
For OP = 0 To filesize
LastOutArray(c) = Array(OP): c = c + 1
Next OP
If _FileExists("BasicTokenizedB4Pass2.bin") Then Kill "BasicTokenizedB4Pass2.bin"
If Verbose > 0 Then Print "Writing to file "; "BasicTokenizedB4Pass2.bin"
Open "BasicTokenizedB4Pass2.bin" For Binary As #1
Put #1, , LastOutArray()
Close #1
' Re-format IF statements that are only one line and don't end with an ENDIF just an EOL to end with and ENDIF (so all IF's can be handled the same)
If Verbose > 0 Then Print "Doing Pass 2 - Changing single line IF commands to IF/THEN/ELSE/END IF, multiple lines"
c = 0
x = 0
While x <= filesize
v = Array(x): x = x + 1 ' get a byte
INArray(c) = v: c = c + 1 'write byte to ouput array
If v = &HFF And Array(x) * 256 + Array(x + 1) = C_IF Then
'It is an IF command
v = Array(x): x = x + 1 ' get the command to do
INArray(c) = v: c = c + 1 ' write byte to ouput array
v = Array(x): x = x + 1 ' get the command to do
INArray(c) = v: c = c + 1 ' write byte to ouput array
'Make sure it wasn't part of an END IF
'END IF = FF xx xx FF xx xx F5 0D
If x > 6 Then
' check for an END IF
If Array(x - 6) = &HFF And Array(x - 5) * 256 + Array(x - 4) = C_END Then
'It is part of an END IF
GoTo PartOfENDIF
End If
End If
'Otherwise it is a regular IF
' Find the THEN command for this IF
Do Until v = &HFF And (Array(x) * 256 + Array(x + 1) = C_THEN Or Array(x) * 256 + Array(x + 1) = C_GOTO) ' If we come across a GOTO instead of a THEN, make it a THEN
v = Array(x): x = x + 1 ' get a byte
INArray(c) = v: c = c + 1 ' write byte to ouput array
Loop 'loop until we find a THEN or GOTO command
' Just in case we found a GOTO instead of a THEN, change it to a THEN
' Make it a THEN even if it was a GOTO
Num = C_THEN: GoSub NumToMSBLSBString ' Convert number in num to 16 bit value in MSB$ & LSB$ and MSB & LSB
INArray(c) = MSB: c = c + 1: INArray(c) = LSB: c = c + 1 ' write command to ouput array
x = x + 2 ' skip forward past command number
' Print "Checking for stuff after the THEN"
v = Array(x) ' get a byte
If Array(x) = &HF5 And Array(x + 1) = &H3A Then
While Array(x) = &HF5 And Array(x + 1) = &H3A: x = x + 2: Wend ' consume any colons directly after the THEN
v = Array(x): x = x + 1
Else
x = x + 1
End If
If v = (&HF5 And Array(x) = &H0D) Or (v = &HFF And Array(x) * 256 + Array(x + 1) = C_REM) Or (v = &HFF And Array(x) * 256 + Array(x + 1) = C_REMApostrophe) Then ' After THEN do we have an EOL, or REMarks?
' if so this is already an IF/THEN/ELSE/ELSEIF/ENDIF so don't need to change it to be a multi line IF
INArray(c) = v: c = c + 1 ' write byte to ouput array
If v = &HF5 And Array(x) = &H0D Then INArray(c) = &H0D: c = c + 1: x = x + 1
Else
' Print "not a multi line IF"
' This is a one line IF/THEN/ELSE command that ends with a $F5 $0D
' Make it a multi line IF THEN ELSE
' We've copied everything upto and including the THEN
' Make the byte after the THEN an EOL
IfCounter = 1
INArray(c) = &HF5: c = c + 1 ' Add EOL
INArray(c) = &H0D: c = c + 1 ' Add EOL
INArray(c) = 0: c = c + 1 ' start of next line - line label length of zero
'Check for a number could be IF THEN 50
FoundLineNumber:
If v >= Asc("0") And v <= Asc("9") Then
' Found a line number, change it to a new line with GOTO linenumber
INArray(c) = &HFF: c = c + 1 ' General command
Num = C_GOTO: GoSub NumToMSBLSBString ' Convert number in num to 16 bit value in MSB$ & LSB$ and MSB & LSB
INArray(c) = MSB: c = c + 1: INArray(c) = LSB: c = c + 1 ' write command to ouput array
While v >= Asc("0") And v <= Asc("9")
INArray(c) = v: c = c + 1 ' write line number
v = Array(x): x = x + 1 ' copy the line number
Wend
x = x - 1
While Array(x) = &HF5 And Array(x + 1) = &H3A: v = Array(x): x = x + 2: Wend ' consume any colons
v = Array(x): x = x + 1
If v = &HF5 And Array(x) = &H0D Then INArray(c) = &HF5: c = c + 1: GoTo FixedGoto ' The &H0D will be added below
End If
' Not a line number after the THEN
x = x - 1
Do Until v = &HF5 And Array(x) = &H0D
v = Array(x): x = x + 1 ' get a byte
INArray(c) = v: c = c + 1 ' write byte to ouput array
If v = &HFF Then
If Array(x) * 256 + Array(x + 1) = C_IF Then
' Found an IF
IfCounter = IfCounter + 1
c = c - 1 ' Don't keep the &HFF it just wrote
INArray(c) = &HF5: c = c + 1 ' add EOL instead of the IF Command
INArray(c) = &H0D: c = c + 1 ' add EOL
INArray(c) = &H00: c = c + 1 ' line label length of zero
INArray(c) = &HFF: c = c + 1 ' Add the command Token
v = Array(x): x = x + 1 ' Get the IF Command #MSB
INArray(c) = v: c = c + 1 ' Write the IF Command #MSB
v = Array(x): x = x + 1 ' Get the IF Command #LSB
INArray(c) = v: c = c + 1 ' Write the IF Command #LSB
End If
If Array(x) * 256 + Array(x + 1) = C_THEN Or Array(x) * 256 + Array(x + 1) = C_ELSE Then
' Found THEN or ELSE
c = c - 1 ' Don't keep the &HFF it just wrote
INArray(c) = &HF5: c = c + 1 ' add EOL
INArray(c) = &H0D: c = c + 1 ' add EOL
INArray(c) = 0: c = c + 1 ' line label length
INArray(c) = &HFF: c = c + 1 ' write &HFF command byte to ouput array
v = Array(x): x = x + 1 ' get the THEN or ELSE command # MSB
INArray(c) = v: c = c + 1 ' write byte to ouput array
v = Array(x): x = x + 1 ' get the THEN or ELSE command # LSB
INArray(c) = v: c = c + 1 ' write byte to ouput array
v = Array(x): x = x + 1 ' get the next byte
If v = &HF5 And Array(x) = &H3A Then
' We have a colon
x = x - 1
While Array(x) = &HF5 And Array(x + 1) = &H3A: x = x + 2: Wend ' consume any colons
v = Array(x): x = x + 1 ' get the next byte
End If
If v >= Asc("0") And v <= Asc("9") Then GoTo FoundLineNumber
x = x - 1
INArray(c) = &HF5: c = c + 1 ' Add EOL
INArray(c) = &H0D: c = c + 1 ' Add EOL
INArray(c) = 0: c = c + 1 ' line label length of zero
End If
End If
Loop
FixedGoto:
v = Array(x): x = x + 1 ' get a byte the $0D
INArray(c) = v: c = c + 1 ' write byte to ouput array
For I = 1 To IfCounter
'END IF = FF xx xx FF xx xx F5 0D
INArray(c) = 0: c = c + 1 ' line label length of zero
INArray(c) = &HFF: c = c + 1
Num = C_END: GoSub NumToMSBLSBString ' Convert number in num to 16 bit value in MSB$ & LSB$ and MSB & LSB
INArray(c) = MSB: c = c + 1: INArray(c) = LSB: c = c + 1 ' write command to ouput array
INArray(c) = &HFF: c = c + 1
Num = C_IF: GoSub NumToMSBLSBString ' Convert number in num to 16 bit value in MSB$ & LSB$ and MSB & LSB
INArray(c) = MSB: c = c + 1: INArray(c) = LSB: c = c + 1 ' write command to ouput array
INArray(c) = &HF5: c = c + 1 ' Add EOL
INArray(c) = &H0D: c = c + 1 ' EOL
Next I
End If
End If
PartOfENDIF:
Wend
' Tokens for variables type:
' &HF0 = Numeric Arrays (4 Bytes)
' &HF1 = String Arrays (3 Bytes)
' &HF2 = Regular Numeric Variable (3 Bytes)
' &HF3 = Regular String Variable (3 Bytes)
' &HF4 = Floating Point Variable
' &HF5 = Special characters like a EOL, colon, comma, semi colon, quote, brackets (2 Bytes)
' &HFB = DEF FN Function
' &HFC = Operator Command (2 Bytes)
' &HFD = String Command (3 Bytes)
' &HFE = Numeric Command (3 Bytes)
' &HFF = General Command (3 Bytes)
' Change Variable _Var_Timer = to command TIMER =
Check$ = "TIMER": GoSub FindGenCommandNumber ' Gets the General Command number of Check$, returns with number in ii, Found=1 if found and Found=0 if not found
C_TIMER = ii
CheckForTimer:
While OP <= filesize
v = INArray(OP): OP = OP + 1
If v < &HF0 Then GoTo CheckForTimer
'We have a Token
Select Case v
Case &HF0, &HF1: ' Found a Numeric or String array
OP = OP + 3
Case &HF2: ' Found a numeric variable
If INArray(OP) * 256 + INArray(OP + 1) = 0 Then
If INArray(OP + 2) = &HFC Then
If INArray(OP + 3) = &H3D Then ' Check for =
' Found "_Var_Timer =" as a variable
INArray(OP - 1) = &HFF ' Make it a General command
Num = C_TIMER: GoSub NumToMSBLSBString ' Convert number in num to 16 bit value in MSB$ & LSB$ and MSB & LSB
INArray(OP) = MSB: INArray(OP + 1) = LSB ' write command to ouput array
OP = OP + 2
End If
End If
End If
Case &HF3, &HF4: ' Found a string or fating point variable
OP = OP + 2
Case &HF5 ' Found a special character
OP = OP + 1
Case &HFB: ' Found a DEF FN Function
OP = OP + 2
Case &HFC: ' Found an Operator
OP = OP + 1
Case &HFD, &HFE, &HFF: 'Found String,Numeric or General command
OP = OP + 2
End Select
Wend
' Copy array INArray() to Array()
filesize = c - 1
c = 0
For OP = 0 To filesize
Array(c) = INArray(OP): c = c + 1
Next OP
ReDim LastOutArray(filesize) As _Unsigned _Byte
c = 0
For OP = 0 To filesize
LastOutArray(c) = Array(OP): c = c + 1
Next OP
If _FileExists("BasicTokenizedB4Pass3.bin") Then Kill "BasicTokenizedB4Pass3.bin"
If Verbose > 0 Then Print "Writing to file "; "BasicTokenizedB4Pass3.bin"
Open "BasicTokenizedB4Pass3.bin" For Binary As #1
Put #1, , LastOutArray()
Close #1
' Decided to not skip it just in case someone select the -coco option even though they truly are using -ascii
'If BASICMode = 1 Then GoTo SkipCheckingForElseIF ' CoCo BASIC won't have ELSEIF
' Change any ElseIf to ELSE/IF
c = 0
x = 0
AddENDIF = 0
ElseIfCheckPartOfENDIF:
While x <= filesize
v = Array(x): x = x + 1 ' get a byte
INArray(c) = v: c = c + 1 'write byte to ouput array
If v > &HEF Then
'We have a Token
Select Case v
Case &HF0, &HF1: ' Found a Numeric or String array
v = Array(x): x = x + 1 ' get a byte
INArray(c) = v: c = c + 1 'write byte to ouput array
v = Array(x): x = x + 1 ' get a byte
INArray(c) = v: c = c + 1 'write byte to ouput array
v = Array(x): x = x + 1 ' get a byte
INArray(c) = v: c = c + 1 'write byte to ouput array
Case &HF2, &HF3, &HF4: ' Found a numeric or string or Floating point variable
v = Array(x): x = x + 1 ' get a byte
INArray(c) = v: c = c + 1 'write byte to ouput array
v = Array(x): x = x + 1 ' get a byte
INArray(c) = v: c = c + 1 'write byte to ouput array
Case &HF5 ' Found a special character
v = Array(x): x = x + 1 ' get a byte
INArray(c) = v: c = c + 1 'write byte to ouput array
Case &HFB: ' Found a DEF FN Function
v = Array(x): x = x + 1 ' get a byte
INArray(c) = v: c = c + 1 'write byte to ouput array
v = Array(x): x = x + 1 ' get a byte
INArray(c) = v: c = c + 1 'write byte to ouput array
Case &HFC: ' Found an Operator
v = Array(x): x = x + 1 ' get a byte
INArray(c) = v: c = c + 1 'write byte to ouput array
Case &HFD, &HFE: 'Found String or Numeric command
v = Array(x): x = x + 1 ' get a byte
INArray(c) = v: c = c + 1 'write byte to ouput array
v = Array(x): x = x + 1 ' get a byte
INArray(c) = v: c = c + 1 'write byte to ouput array
Case &HFF: ' Found a General command
Temp1 = Array(x): x = x + 1 ' get a byte
INArray(c) = Temp1: c = c + 1 'write byte to ouput array
Temp2 = Array(x): x = x + 1 ' get a byte
INArray(c) = Temp2: c = c + 1 'write byte to ouput array
v = Temp1 * 256 + Temp2
If v = C_ELSE Then
' Found an Else, check for IF
If Array(x) = &HFF And Array(x + 1) * 256 + Array(x + 2) = C_IF Then
' We found an ELSE IF
' Change ELSEIF to ELSE - EOL
INArray(c) = &HF5: c = c + 1: INArray(c) = &H0D: c = c + 1 ' EOL
INArray(c) = 0: c = c + 1 ' line label length of zero
End If
End If
End Select
End If
Wend
filesize = c - 1
ReDim LastOutArray(filesize) As _Unsigned _Byte
c = 0
For OP = 0 To filesize
Array(c) = INArray(OP)
LastOutArray(c) = INArray(OP): c = c + 1
Next OP
If _FileExists("BasicTokenized.bin") Then Kill "BasicTokenized.bin"
If Verbose > 0 Then Print "Writing to file "; "BasicTokenized.bin"
Open "BasicTokenized.bin" For Binary As #1
Put #1, , LastOutArray()
Close #1
If Verbose > 0 Then Print "Doing Pass 3 - Figuring out Arrays sizes, within the DIM commands..."
x = 0
While x < filesize
v = Array(x): x = x + 1 ' get the command to do
If v = &HFF Then ' Found a command
v = Array(x) * 256 + Array(x + 1): x = x + 2
If v = C_DIM Then ' Is it the DIM command?
' Found a DIM command, go setup the array sizes
GoSub DoDim
End If
End If
Wend
If Verbose > 0 Then Print "Doing Pass 4 - Finding special cases that will need other files to be included..."
x = 0
While x < filesize
v = Array(x): x = x + 1 ' get the command to do
If v = &HFF Then ' Found a command
v = Array(x) * 256 + Array(x + 1): x = x + 2
If v = C_PRINT Then ' Is it the PRINT command?
' Found a PRINT command, see if we have a print #-3, which will print to the graphics screen
'#-3, = F5 23 FC 2D 33 F5 2C
If Array(x) = &HF5 And Array(x + 1) = &H23 And Array(x + 2) = &HFC And Array(x + 3) = &H2D And Array(x + 4) = &H33 And Array(x + 5) = &HF5 And Array(x + 6) = &H2C Then
x = x + 7
PrintGraphicsText = 1
End If
End If
End If
Wend
Open "NumericVariablesUsed.txt" For Output As #1
For I = 0 To NumericVariableCount - 1
Print #1, NumericVariable$(I)
Next I
Close #1
Open "FloatingPointVariablesUsed.txt" For Output As #1
For I = 0 To FloatVariableCount - 1
Print #1, FloatVariable$(I)
Next I
Close #1
Open "StringVariablesUsed.txt" For Output As #1
For I = 0 To StringVariableCounter - 1
Print #1, StringVariable$(I)
Next I
Close #1
Open "GeneralCommandsFound.txt" For Output As #1
For I = 0 To GeneralCommandsFoundCount - 1
Print #1, GeneralCommandsFound$(I)
Next I
Close #1
Open "StringCommandsFound.txt" For Output As #1
For I = 0 To StringCommandsFoundCount - 1
Print #1, StringCommandsFound$(I)
Next I
Close #1
Open "NumericCommandsFound.txt" For Output As #1
For I = 0 To NumericCommandsFoundCount - 1
Print #1, NumericCommandsFound$(I)
Next I
Close #1
Open "NumericArrayVarsUsed.txt" For Output As #1
For I = 0 To NumArrayVarsUsedCounter - 1
Print #1, NumericArrayVariables$(I)
Print #1, NumericArrayDimensions(I)
Next I
Close #1
Open "StringArrayVarsUsed.txt" For Output As #1
For I = 0 To StringArrayVarsUsedCounter - 1
Print #1, StringArrayVariables$(I)
Print #1, StringArrayDimensions(I)
Next I
Close #1
Open "DefFNUsed.txt" For Output As #1
For I = 0 To DefLabelCount - 1
Print #1, DefLabel$(I)
Next I
Close #1
Open "DefVarUsed.txt" For Output As #1
For I = 0 To DefVarCount - 1
Print #1, DefVar(I)
Next I
Close #1
'See if we should need to use Disk access and Background sound
For ii = 0 To GeneralCommandsFoundCount - 1
Temp$ = UCase$(GeneralCommandsFound$(ii))
If Temp$ = "LOADM" Then
Disk = 1 ' Flag that we use Disk access
End If
If Temp$ = "PLAY" Then
PlayCommand = 1 ' Flag that we use the Play Command
End If
If Temp$ = "LINE" Then
LineCommand = 1 ' Flag that we will use the LINE command
End If
If Temp$ = "SDC_PLAY" Or Temp$ = "SDC_PLAYORCL" Or Temp$ = "SDC_PLAYORCR" Or Temp$ = "SDC_PLAYORCS" Then
SDCPLAY = 1 ' Flag that we need extra SDCPlayback buffer space
End If
If Temp$ = "SDC_OPEN" Or Temp$ = "SDC_LOADM" Or Temp$ = "SDC_SAVEM" Then
SDCVersionCheck = 1 ' include code to make sure we have the correct SDC firmware
End If
Next ii
' Start writing to the .asm file
Open OutName$ For Output As #1
DirectPage$ = ProgramStart$
DirectPage = Val("&H" + DirectPage$)
DirectPage = DirectPage / 256
DirectPage$ = Hex$(DirectPage)
T1$ = " ": T2$ = T1$ + T1$
If BranchCheck > 0 Then
' User wants all branches checked for minimum size
A$ = "PRAGMA": B$ = "noforwardrefmax": C$ = "This option is necessary for auto branch size feature to work properly, makes lwasm REALLY slow, but code will be smaller and faster": GoSub AO
End If
A$ = "PRAGMA": B$ = "autobranchlength": C$ = "Tell LWASM to automatically use long branches if the short branch is too small, see compiler docs for option -b1 to make this work properly": GoSub AO
Print #1, "; Program reserves $100 bytes before the starting location below for stack space"
A$ = "ORG": B$ = "$" + ProgramStart$: C$ = "Program code starts here": GoSub AO
A$ = "SETDP": B$ = "$" + DirectPage$: C$ = "Direct page is setup here": GoSub AO
Print #1, "Seed1 RMB 1 ; Random number seed location"
Print #1, "Seed2 RMB 1 ; Random number seed location"
Print #1, "RNDC RMB 1 ; Used by Random number generator"
Print #1, "RNDX RMB 1 ; Used by Random number generator"
Print #1, "StartClearHere:" ' This is the start address of variables that will all be cleared to zero when the program starts
' Save space for 10 temporary 16 bit numbers
Print #1, "; Temporary Numbers:"
For Num = 0 To 10
GoSub NumAsString 'Convert number in Num to a string without spaces as Num$
If Num < 10 Then Num$ = "0" + Num$
Print #1, "_Var_PF"; Num$; T1$; "RMB "; T1$; "2"
Next Num
Print #1, "Temp1 RMB 1 ; Temporary byte used for many routines"
Print #1, "Temp2 RMB 1 ; Temporary byte used for many routines"
Print #1, "Temp3 RMB 1 ; Temporary byte used for many routines"
Print #1, "Temp4 RMB 1 ; Temporary byte used for many routines"
Print #1, "Denominator RMB 2 ; Denominator, used in division"
Print #1, "Numerator RMB 2 ; Numerator, used in division"
Print #1, "DATAPointer RMB 2 ; Variable that points to the current DATA location"
Print #1, "_NumVar_IFRight RMB 2 ; Temp bytes for IF Compares"
' Reserve space for Floating Point variables
Print #1, "; Floating Point Variables Used:"; FloatVariableCount
For ii = 0 To FloatVariableCount - 1
Print #1, "_FPVar_"; FloatVariable$(ii); T1$; "RMB "; T1$; "5"
Next ii
Print #1, "; Numeric Variables Used:"; NumericVariableCount
For ii = 0 To NumericVariableCount - 1
Print #1, "_Var_"; NumericVariable$(ii); T1$; "RMB "; T1$; "2"
Next ii
Print #1, "EveryCasePointer RMB 2 ; Pointer at the table to keep track of the CASE/EVERYCASE Flags"
Print #1, "EveryCaseStack RMB 10*2 ; Space Used for nested Cases"
Print #1, "SoundTone RMB 1 ; SOUND Tone value"
Print #1, "SoundDuration RMB 2 ; SOUND Command duration value"
Print #1, "CASFLG RMB 1 ; Case flag for keyboard output $FF=UPPER (normal), 0=LOWER"
Print #1, "OriginalIRQ RMB 3 ; We save the original branch and location of the IRQ here, restored before we exit"
' Add temp string space
For Num = 0 To 1
GoSub NumAsString 'Convert number in Num to a string without spaces as Num$
If Num < 10 Then Num$ = "0" + Num$
Print #1, "_StrVar_PF"; Num$; T1$; "RMB "; T1$; "256 ; Temp String Variable"
Next Num
' Add temp IF string space
Print #1, "_StrVar_IFRight"; T1$; "RMB "; T1$; "256 ; Temp String Variable for IF Compares"
If SDCPLAY = 1 Then
' We need extra SDCPlayback buffer space
Print #1, "SDCPLAY_Extra"; T1$; "RMB "; T1$; "256 ; Extra temp Space for SDCPLAY command"
End If
' Add the String Variables used
Print #1, "; String Variables Used:"; StringVariableCounter
For ii = 0 To StringVariableCounter - 1
Z$ = "_StrVar_" + StringVariable$(ii): GoSub AO
A$ = "RMB": B$ = "1": C$ = "String Variable " + StringVariable$(ii) + " length (0 to 255) initialized to 0": GoSub AO
A$ = "RMB": B$ = "255": C$ = "255 bytes available for string variable " + StringVariable$(ii): GoSub AO
Next ii
Print #1, "; Numeric Arrays Used:"; NumArrayVarsUsedCounter
If NumArrayVarsUsedCounter > 0 Then
For ii = 0 To NumArrayVarsUsedCounter - 1
Temp$ = "2*" 'Two bytes (16 bits) per element
For D1 = 0 To NumericArrayDimensions(ii) - 1
Num = Val("&H" + Mid$(NumericArrayDimensionsVal$(ii), 1 + D1 * 4, 4)) + 1 ' + 1 because it is zero based
GoSub NumAsString 'Convert number in Num to a string without spaces as Num$
Temp$ = Temp$ + Num$ + "*"
Next D1
Temp$ = Left$(Temp$, Len(Temp$) - 1) ' Remove the extra '*'
Print #1, "_ArrayNum_"; NumericArrayVariables$(ii)
Print #1, "; Reserve bytes per element size, set with the DIM command"
For D1 = 0 To NumericArrayDimensions(ii) - 1
Num = Val("&H" + Mid$(NumericArrayDimensionsVal$(ii), 1 + D1 * 4, 4)) + 1 ' + 1 because it is zero based
GoSub NumAsString 'Convert number in Num to a string without spaces as Num$
A$ = "FCB": B$ = Num$: C$ = "Default size of each array element is 12 (0 to 11), changed with the DIM command": GoSub AO
Next D1
A$ = "RMB": B$ = Temp$: C$ = "Two bytes (16 bits) per element": GoSub AO
Next ii
End If
Print #1, "; String Arrays Used:"; StringArrayVarsUsedCounter
If StringArrayVarsUsedCounter > 0 Then
For ii = 0 To StringArrayVarsUsedCounter - 1
StringArrayReserveSize = StringArraySize + 1 ' Need an extra byte for the actual string size value
Num = StringArrayReserveSize
GoSub NumAsString 'Convert number in Num to a string without spaces as Num$
'Temp$ = "256*" '256 bytes per element
Temp$ = Num$ + "*" '# of bytes per element
For D1 = 0 To StringArrayDimensions(ii) - 1
Num = Val("&H" + Mid$(StringArrayDimensionsVal$(ii), 1 + D1 * 4, 4)) + 1 ' + 1 because it is zero based
GoSub NumAsString 'Convert number in Num to a string without spaces as Num$
Temp$ = Temp$ + Num$ + "*"
Next D1
Temp$ = Left$(Temp$, Len(Temp$) - 1) ' Remove the extra '*'
Print #1, "_ArrayStr_"; StringArrayVariables$(ii)
Print #1, "; Reserve bytes per element size, set with the DIM command"
For D1 = 0 To StringArrayDimensions(ii) - 1
Num = Val("&H" + Mid$(StringArrayDimensionsVal$(ii), 1 + D1 * 4, 4)) + 1 ' + 1 because it is zero based
GoSub NumAsString 'Convert number in Num to a string without spaces as Num$
A$ = "FCB": B$ = Num$: C$ = "Default size of each array element is 11 (0 to 10), changed with the DIM command": GoSub AO
Next D1
A$ = "RMB": B$ = Temp$: C$ = "Reserve " + Temp$ + " bytes per element": GoSub AO
Next ii
End If
Print #1, "EndClearHere:" ' This is the end address of variables that will all be cleared to zero when the program starts
Print #1, "; General Commands Used:"; GeneralCommandsFoundCount
For ii = 0 To GeneralCommandsFoundCount - 1
Print #1, "; " + GeneralCommandsFound$(ii)
Next ii
Print #1, "; Numeric Commands Used:"; NumericCommandsFoundCount
For ii = 0 To NumericCommandsFoundCount - 1
Print #1, "; " + NumericCommandsFound$(ii)
Next ii