-
Notifications
You must be signed in to change notification settings - Fork 78
/
c64disasm_ms.txt
7582 lines (7374 loc) · 474 KB
/
c64disasm_ms.txt
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
- Fully Commented Commodore 64 BASIC ROM Disassembly (English, "MS")
-
- The comments have been taken from
- Microsoft's original BASIC for M6502 source
- http://www.pagetable.com/?p=774
-
- The comments here are basically a complete copy of Microsoft's BASIC
- for 6502 source code, lined up with the version in the C64 ROM.
- This way, even all variable names are intact. The C64 ROM contains
- several fixes and extensions, so the comments do not always line
- up perfectly, so make sure the machine code matches the assembly
- code in the respective lines your looking at.
-
- The range $E0F9-$E261 was taken from
- The original C64 BASIC source by Commodore
- https://github.com/mist64/cbmsrc
-
- Converted and formatted by Michael Steil <[email protected]>
-
- Corrections (formatting, lining up) welcome at:
- https://github.com/mist64/c64ref
-
------------------------------------------------------------
-
# This plain text file is formatted so that it can be automatically
# parsed in order to create cross-references etc.
# * Lines starting with "-" is top-level information. The first line
# is the title. Lines starting with "--" are separators.
# * Lines starting with "#" are internal comments.
# * Lines starting with ".," indicate code to be disassembled.
# * Lines starting with ".:" indicate bytes to be dumped.
# * Comments start at the 33rd column.
# * 32 leading spaces and "SUBTTL" indicate a heading.
# * Otherwise, 32 leading spaces indicate an overflow comment.
# The encoding is UTF-8.
TITLE BASIC M6502 8K VER 1.1 BY MICRO-SOFT
SEARCH M6502
SALL
RADIX 10 ;THROUGHOUT ALL BUT MATH-PAK.
$Z:: ;STARTING POINT FOR M6502 SIMULATOR
ORG 0 ;START OFF AT LOCATION ZERO.
SUBTTL SWITCHES,MACROS.
REALIO=4 ;5=STM
;4=APPLE.
;3=COMMODORE.
;2=OSI
;1=MOS TECH,KIM
;0=PDP-10 SIMULATING 6502
INTPRC==1 ;INTEGER ARRAYS.
ADDPRC==1 ;FOR ADDITIONAL PRECISION.
LNGERR==0 ;LONG ERROR MESSAGES.
TIME== 0 ;CAPABILITY TO SET AND READ A CLK.
EXTIO== 0 ;EXTERNAL I/O.
DISKO== 0 ;SAVE AND LOAD COMMANDS
NULCMD==1 ;FOR THE "NULL" COMMAND
GETCMD==1
RORSW==1
ROMSW==1 ;TELLS IF THIS IS ON ROM.
CLMWID==14
LONGI==1 ;LONG INITIALIZATION SWITCH.
STKEND=511
BUFPAG==0
LINLEN==72 ;TERMINAL LINE LENGTH.
BUFLEN==72 ;INPUT BUFFER SIZE.
ROMLOC= ^O20000 ;ADDRESS OF START OF PURE SEGMENT.
KIMROM=1
IFE ROMSW,<KIMROM==0>
IFN REALIO-1,<KIMROM==0>
IFN ROMSW,<
RAMLOC= ^O40000 ;USED ONLY IF ROMSW=1
IFE REALIO,<ROMLOC= ^O20000 ;START AT 8K.
RAMLOC=^O1400>>
IFE REALIO-3,<
DISKO==1
RAMLOC==^O2000
ROMLOC=^O140000
NULCMD==0
GETCMD==1
linlen==40
BUFLEN==81
CQOPEN=^O177700
CQCLOS=^O177703
CQOIN= ^O177706 ;OPEN CHANNEL FOR INPUT
CQOOUT=^O177711 ;FILL FOR COMMO.
CQCCHN=^O177714
CQINCH=^O177717 ;INCHR'S CALL TO GET A CHARACTER
OUTCH= ^O177722
CQLOAD=^O177725
CQSAVE=^O177730
CQVERF=^O177733
CQSYS= ^O177736
ISCNTC=^O177741
CZGETL=^O177744 ;CALL POINT FOR "GET"
CQCALL=^O177747 ;CLOSE ALL CHANNELS
CQTIMR=^O215
BUFPAG==2
BUF==256*BUFPAG
STKEND==507
CQSTAT=^O226
CQHTIM=^O164104
EXTIO==1
TIME==1
GETCMD==1
CLMWID==10
PI=255 ;VALUE OF PI CHARACTER FOR COMMODORE.
ROMSW==1
RORSW==1
TRMPOS=^O306>
IFE REALIO-1,<GETCMD==1
DISKO==1
OUTCH=^O17240 ;1EA0
ROMLOC==^O20000
RORSW==0
CZGETL=^O17132>
IFE REALIO-2,<
RORSW==0
RAMLOC==^O1000
IFN ROMSW,<
RORSW==0
RAMLOC==^O100000>
OUTCH==^O177013>
IFE REALIO-4,<
RORSW==1
NULCMD==0
GETCMD==1
CQINLN==^O176547
CQPRMP==^O63
CQINCH==^O176414
CQCOUT==^O177315
CQCSIN==^O177375
BUFPAG==2
BUF=BUFPAG*256
ROMLOC=^O4000
RAMLOC=^O25000 ;PAGE 2A
OUTCH=^O176755
CZGETL=^O176414
LINLEN==40
BUFLEN==240
RORSW==1
STKEND=507>
IFE RORSW,<
DEFINE ROR (WD),<
LDAI 0
BCC .+4
LDAI ^O200
LSR WD
ORA WD
STA WD>>
DEFINE ACRLF,<
13
10>
DEFINE SYNCHK (Q),<
LDAI <Q>
JSR SYNCHR>
DEFINE DT(Q),<
IRPC Q,<IFDIF <Q><">,<EXP "Q">>>
DEFINE LDWD (WD),<
LDA WD
LDY <WD>+1>
DEFINE LDWDI (WD),<
LDAI <<WD>&^O377>
LDYI <<WD>/^O400>>
DEFINE LDWX (WD),<
LDA WD
LDX <WD>+1>
DEFINE LDWXI (WD),<
LDAI <<WD>&^O377>
LDXI <<WD>/^O400>>
DEFINE LDXY (WD),<
LDX WD
LDY <WD>+1>
DEFINE LDXYI (WD),<
LDXI <<WD>&^O377>
LDYI <<WD>/^O400>>
DEFINE STWD (WD),<
STA WD
STY <WD>+1>
DEFINE STWX (WD),<
STA WD
STX <WD>+1>
DEFINE STXY (WD),<
STX WD
STY <WD>+1>
DEFINE CLR (WD),<
LDAI 0
STA WD>
DEFINE COM (WD),<
LDA WD
EORI ^O377
STA WD>
DEFINE PULWD (WD),<
PLA
STA WD
PLA
STA <WD>+1>
DEFINE PSHWD (WD),<
LDA <WD>+1
PHA
LDA WD
PHA>
DEFINE JEQ (WD),<
BNE .+5
JMP WD>
DEFINE JNE (WD),<
BEQ .+5
JMP WD>
DEFINE BCCA(Q),< BCC Q> ;BRANCHES THAT ALWAYS BRANCH
DEFINE BCSA(Q),< BCS Q> ;THESE ARE USED ON THE 6502 BECAUSE
DEFINE BEQA(Q),< BEQ Q> ;THERE IS NO UNCONDITIONAL BRANCH
DEFINE BNEA(Q),< BNE Q>
DEFINE BMIA(Q),< BMI Q>
DEFINE BPLA(Q),< BPL Q>
DEFINE BVCA(Q),< BVC Q>
DEFINE BVSA(Q),< BVS Q>
DEFINE INCW(R),<
INC R
BNE %Q
INC R+1
%Q:>
DEFINE SKIP1, <XWD ^O1000,^O044> ;BIT ZERO PAGE TRICK.
DEFINE SKIP2, <XWD ^O1000,^O054> ;BIT ABS TRICK.
IF1,<
IFE REALIO,<PRINTX/SIMULATE/>
IFE REALIO-1,<PRINTX KIM>
IFE REALIO-2,<PRINTX OSI>
IFE REALIO-3,<PRINTX COMMODORE>
IFE REALIO-4,<PRINTX APPLE>
IFE REALIO-5,<PRINTX STM>
IFN ADDPRC,<PRINTX ADDITIONAL PRECISION>
IFN INTPRC,<PRINTX INTEGER ARRAYS>
IFN LNGERR,<PRINTX LONG ERRORS>
IFN DISKO,<PRINTX SAVE AND LOAD>
IFE ROMSW,<PRINTX RAM>
IFN ROMSW,<PRINTX ROM>
IFE RORSW,<PRINTX NO ROR>
IFN RORSW,<PRINTX ROR ASSUMED>>
PAGE
SUBTTL INTRODUCTION AND COMPILATION PARAMETERS.
COMMENT *
--------- ---- -- ---------
COPYRIGHT 1976 BY MICROSOFT
--------- ---- -- ---------
7/27/78 FIXED BUG WHERE FOR VARIABLE AT BYTE FF MATCHED RETURN SEARCHING
FOR GOSUB ENTRY ON STACK IN FNDFOR CALL BY CHANGING STA FORPNT
TO STA FORPNT+1. THIS IS A SERIOUS BUG IN ALL VERSIONS.
7/27/78 FIXED BUG AT NEWSTT UNDER IFN BUFPAG WHEN CHECK OF CURLIN
WAS DONE BEFORE CURLIN SET UP SO INPUT RETRIES OF FIRST STATEMENT
WAS GIVING SYNTAX ERROR INSTEAD OF REDO FROM START (CODE WAS 12/1/77 FIX)
7/1/78 SAVED A FEW BYTES IN INIT FOR COMMODORE (14)
7/1/78 FIXED BUG WHERE REPLACING A LINE OVERFLOWING MEMORY LEFT LINKS
IN A BAD STATE. (CODE AT NODEL AND FINI) BUG#4
7/1/78 FIXED BUG WHERE GARBAGE COLLECTION NEVER(!) COLLECTS TEMPS
(STY GRBPNT AT FNDVAR, LDA GRBPNT ORA GRBPNT+1 AT GRBPAS)
THIS WAS COMMODORE BUG #2
7/1/78 FIXED BUG WHERE DELETE/INSERT OF LINE COULD CAUSE A GARBAGE COLLECTION WITH BAD VARTAB IF OUT OF MEMORY
(LDWD MEMSIZ STWD FRETOP=JSR RUNC CLC ALSO AT NODEL)
3/9/78 EDIT TO FIX COMMO TRMPOS AND CHANGE LEFT$ AND RIGHT$ TO ALLOW A SECOND ARGUMENT OF 0 AND RETURN A NULL STRING
2/25/78 FIXED BUG THAT INPFLG WAS SET WRONG WHEN BUFPAG.NE.0
INCREASED NUMLEV FROM 19 TO 23
2/11/78 DISALLOWED SPACES IN RESERVED WORDS. PUT IN SPECIAL CHECK FOR "GO TO"
2/11/78 FIXED BUG WHERE ROUNDING OF THE FAC BEFORE PUSHING COULD CAUSE A STRING POINTER
IN THE FAC TO BE INCREMENTED
1/24/78 fixed problem where user defined function undefined check fix was smashing error number in [x]
12/1/77 FIXED PROBLEM WHERE PEEK WAS SMASHING (POKER) CAUSING POKE OF PEEK TO FAIL
12/1/77 FIXED PROBLEM WHERE PROBLEM WITH VARTXT=LINNUM=BUF-2 CAUSING BUF-1 COMMA TO DISAPPEAR
12/1/77 FIXED BUFPAG.NE.0 PROBLEM AT NEWSTT AND STOP : CODE WAS STILL
ASSUMING TXTPTR+1.EQ.0 IFF STATEMENT WAS DIRECT
*
NUMLEV==23 ;NUMBER OF STACK LEVELS RESERVED
;BY AN EXPLICIT CALL TO "GETSTK".
STRSIZ==3 ;# OF LOCS PER STRING DESCRIPTOR.
NUMTMP==3 ;NUMBER OF STRING TEMPORARIES.
CONTW==15 ;CHARACTER TO SUPPRESS OUTPUT.
PAGE
SUBTTL SOME EXPLANATION.
COMMENT *
M6502 BASIC CONFIGURES BASIC AS FOLLOWS
LOW LOCATIONS
PAGE ZERO
STARTUP:
INITIALLY A JMP TO INITIALIZATION CODE BUT
CHANGED TO A JMP TO "READY".
RESTARTING THE MACHINE AT LOC 0 DURING PROGRAM
EXECUTION CAN LEAVE THINGS MESSED UP.
LOC OF FAC TO INTEGER AND INTEGER TO FAC
ROUTINES.
"DIRECT" MEMORY:
THESE ARE THE MOST COMMONLY USED LOCATIONS.
THEY HOLD BOOKKEEPING INFO AND ALL OTHER
FREQUENTLY USED INFORMATION.
ALL TEMPORARIES, FLAGS, POINTERS, THE BUFFER AREA,
THE FLOATING ACCUMULATOR, AND ANYTHING ELSE THAT
IS USED TO STORE A CHANGING VALUE SHOULD BE LOCATED
IN THIS AREA. CARE MUST BE MADE IN MOVING LOCATIONS
IN THIS AREA SINCE THE JUXTAPOSITION OF TWO LOCATIONS
IS OFTEN DEPENDED UPON.
STILL IN RAM WE HAVE THE BEGINNING OF THE "CHRGET"
SUBROUTINE. IT IS HERE SO [TXTPTR] CAN BE THE
EXTENDED ADDRESS OF A LOAD INSTRUCTION.
THIS SAVES HAVING TO BOTHER ANY REGISTERS.
PAGE ONE
THE STACK.
STORAGE PAGE TWO AND ON
IN RAM VERSIONS THESE DATA STRUCTURES COME AT THE
END OF BASIC. IN ROM VERSON THEY ARE AT RAMLOC WHICH
CAN EITHER BE ABOVE OR BELOW ROMLOC, WHICH IS WHERE
BASIC ITSELF RESIDES.
A ZERO.
[TXTTAB] POINTER TO NEXT LINE'S POINTER.
LINE # OF THIS LINE (2 BYTES).
CHARACTERS ON THIS LINE.
ZERO.
POINTER AT NEXT LINE'S POINTER
(POINTED TO BY THE ABOVE POINTER).
... REPEATS ...
LAST LINE: POINTER AT ZERO POINTER.
LINE # OF THIS LINE.
CHARACTERS ON THIS LINE.
ZERO.
DOUBLE ZERO (POINTED TO BY THE ABOVE POINTER).
[VARTAB] SIMPLE VARIABLES. 6 BYTES PER VALUE.
2 BYTES GIVE THE NAME, 4 BYTES THE VALUE.
... REPEATS ...
[ARYTAB] ARRAY VARIABLES. 2 BYTES NAME, 2 BYTE
LENGTH, NUMBER OF DIMENSIONS , EXTENT OF
EACH DIMENSION (2BYTES/), VALUES
... REPEATS ...
[STREND] FREE SPACE.
... REPEATS ...
[FRETOP] STRING SPACE IN USE.
... REPEATS ...
[MEMSIZ] HIGHEST MACHINE LOCATION.
UNUSED EXCEPT BY THE VAL FUNCTION.
ROM -- CONSTANTS AND CODE.
FUNCTION DISPATCH ADDRESSES (AT ROMLOC)
"FUNDSP" CONTAINS THE ADDRESSES OF THE
FUNCTION ROUTINES IN THE ORDER OF THE
FUNCTION NAMES IN THE CRUNCH LIST.
THE FUNCTIONS THAT TAKE MORE THAN ONE ARGUMENT
ARE AT THE END. SEE THE EXPLANATION AT "ISFUN".
THE OPERATOR LIST
THE "OPTAB" LIST CONTAINS AN OPERATOR'S PRECEDENCE
FOLLOWED BY THE ADDRESS OF THE ROUTINE TO PERFORM
THE OPERATION. THE INDEX INTO THE
OPERATOR LIST IS MADE BY SUBTRACTING OFF THE CRUNCH VALUE
OF THE LOWEST NUMBERED OPERATOR. THE ORDER
OF OPERATORS IN THE CRUNCH LIST AND IN "OPTAB" IS IDENTICAL.
THE PRECEDENCES ARE ARBITRARY EXCEPT FOR THEIR
COMPARATIVE SIZES. NOTE THAT THE PRECEDENCE FOR
UNARY OPERATORS SUCH AS "NOT" AND NEGATION ARE
SETUP SPECIALLY WITHOUT USING THE LIST.
THE RESERVED WORD OR CRUNCH LIST
WHEN A COMMAND OR PROGRAM LINE IS TYPED IN
IT IS STORED IN "BUF". AS SOON AS THE WHOLE LINE
HAS BEEN TYPED IN ("INLIN" RETURNS) "CRUNCH" IS
CALLED TO CONVERT ALL RESERVED WORDS TO THEIR
CRUNCHED VALUES. THIS REDUCES THE SIZE OF THE
PROGRAM AND SPEEDS UP EXECUTION BY ALLOWING
LIST DISPATCHES TO PERFORM FUNCTIONS, STATEMENTS,
AND OPERATIONS. THIS IS BECAUSE ALL THE STATEMENT
NAMES ARE STORED CONSECUTIVELY IN THE CRUNCH LIST.
WHEN A MATCH IS FOUND BETWEEN A STRING
OF CHARACTERS AND A WORD IN THE CRUNCH LIST
THE ENTIRE TEXT OF THE MATCHED WORD IS TAKEN OUT OF
THE INPUT LINE AND A RESERVED WORD TOKEN IS PUT
IN ITS PLACE. A RESERVED WORD TOKEN IS ALWAYS EQUAL
TO OCTAL 200 PLUS THE POSITION OF THE MATCHED WORD
IN THE CRUNCH LIST.
STATEMENT DISPATCH ADDRESSES
WHEN A STATEMENT IS TO BE EXECUTED, THE FIRST
CHARACTER OF THE STATEMENT IS EXAMINED
TO SEE IF IT IS LESS THAN THE RESERVED
WORD TOKEN FOR THE LOWEST NUMBERED STATEMENT NAME.
IF SO, THE "LET" CODE IS CALLED TO
TREAT THE STATEMENT AS AN ASSIGNMENT STATEMENT.
OTHERWISE A CHECK IS MADE TO MAKE SURE THE
RESERVED WORD NUMBER IS NOT TOO LARGE TO BE A
STATEMENT TYPE NUMBER. IF NOT THE ADDRESS
TO DISPATCH TO IS FETCHED FROM "STMDSP" (THE STATEMENT
DISPATCH LIST) USING THE RESERVED WORD
NUMBER FOR THE STATEMENT TO CALCULATE AN INDEX INTO
THE LIST.
ERROR MESSAGES
WHEN AN ERROR CONDITION IS DETECTED,
[ACCX] MUST BE SET UP TO INDICATE WHICH ERROR
MESSAGE IS APPROPRIATE AND A BRANCH MUST BE MADE
TO "ERROR". THE STACK WILL BE RESET AND ALL
PROGRAM CONTEXT WILL BE LOST. VARIABLES
VALUES AND THE ACTUAL PROGRAM REMAIN INTACT.
ONLY THE VALUE OF [ACCX] IS IMPORTANT WHEN
THE BRANCH IS MADE TO ERROR. [ACCX] IS USED AS AN
INDEX INTO "ERRTAB" WHICH GIVES THE TWO
CHARACTER ERROR MESSAGE THAT WILL BE PRINTED ON THE
USER'S TERMINAL.
TEXTUAL MESSAGES
CONSTANT MESSAGES ARE STORED HERE. UNLESS
THE CODE TO CHECK IF A STRING MUST BE COPIED
IS CHANGED THESE STRINGS MUST BE STORED ABOVE
PAGE ZERO, OR ELSE THEY WILL BE COPIED BEFORE
THEY ARE PRINTED.
FNDFOR
MOST SMALL ROUTINES ARE FAIRLY SIMPLE
AND ARE DOCUMENTED IN PLACE. "FNDFOR" IS
USED FOR FINDING "FOR" ENTRIES ON
THE STACK. WHENEVER A "FOR" IS EXECUTED, A
16-BYTE ENTRY IS PUSHED ONTO THE STACK.
BEFORE THIS IS DONE, HOWEVER, A CHECK
MUST BE MADE TO SEE IF THERE
ARE ANY "FOR" ENTRIES ALREADY ON THE STACK
FOR THE SAME LOOP VARIABLE. IF SO, THAT "FOR" ENTRY
AND ALL OTHER "FOR" ENTRIES THAT WERE MADE AFTER IT
ARE ELIMINATED FROM THE STACK. THIS IS SO A
PROGRAM THAT JUMPS OUT OF THE MIDDLE
OF A "FOR" LOOP AND THEN RESTARTS THE LOOP AGAIN
AND AGAIN WON'T USE UP 18 BYTES OF STACK
SPACE EVERY TIME. THE "NEXT" CODE ALSO
CALLS "FNDFOR" TO SEARCH FOR A "FOR" ENTRY WITH
THE LOOP VARIABLE IN
THE "NEXT". AT WHATEVER POINT A MATCH IS FOUND
THE STACK IS RESET. IF NO MATCH IS FOUND A
"NEXT WITHOUT FOR" ERROR OCCURS. GOSUB EXECUTION
ALSO PUTS A 5-BYTE ENTRY ON STACK.
WHEN A RETURN IS EXECUTED "FNDFOR" IS
CALLED WITH A VARIABLE POINTER THAT CAN'T
BE MATCHED. WHEN "FNDFOR" HAS RUN
THROUGH ALL THE "FOR" ENTRIES ON THE STACK
IT RETURNS AND THE RETURN CODE MAKES
SURE THE ENTRY THAT WAS STOPPED
ON IS A GOSUB ENTRY. THIS ASSURES THAT
IF YOU GOSUB TO A SECTION OF CODE
IN WHICH A FOR LOOP IS ENTERED BUT NEVER
EXITED THE RETURN WILL STILL BE
ABLE TO FIND THE MOST RECENT
GOSUB ENTRY. THE "RETURN" CODE ELIMINATES THE
"GOSUB" ENTRY AND ALL "FOR" ENTRIES MADE AFTER
THE GOSUB ENTRY.
NON-RUNTIME STUFF
THE CODE TO INPUT A LINE, CRUNCH IT, GIVE ERRORS,
FIND A SPECIFIC LINE IN THE PROGRAM,
PERFORM A "NEW", "CLEAR", AND "LIST" ARE
ALL IN THIS AREA. GIVEN THE EXPLANATION OF
PROGRAM STORAGE SET FORTH ABOVE, THESE ARE
ALL STRAIGHTFORWARD.
NEWSTT
WHENEVER A STATEMENT FINISHES EXECUTION IT
DOES A "RTS" WHICH TAKES
EXECUTION BACK TO "NEWSTT". STATEMENTS THAT
CREATE OR LOOK AT SEMI-PERMANENT STACK ENTRIES
MUST GET RID OF THE RETURN ADDRESS OF "NEWSTT" AND
JMP TO "NEWSTT" WHEN DONE. "NEWSTT" ALWAYS
CHRGETS THE FIRST CHARACTER AFTER THE STATEMENT
NAME BEFORE DISPATCHING. WHEN RETURNING
BACK TO "NEWSTT" THE ONLY THING THAT
MUST BE SET UP IS THE TEXT POINTER IN
"TXTPTR". "NEWSTT" WILL CHECK TO MAKE SURE
"TXTPTR" IS POINTING TO A STATEMENT TERMINATOR.
IF A STATEMENT SHOULDN'T BE PERFORMED UNLESS
IT IS PROPERLY FORMATTED (I.E. "NEW") IT CAN
SIMPLY DO A RETURN AFTER READING ALL OF
ITS ARGUMENTS. SINCE THE ZERO FLAG
BEING OFF INDICATES THERE IS NOT
A STATEMENT TERMINATOR "NEWSTT" WILL
DO THE JMP TO THE "SYNTAX ERROR"
ROUTINE. IF A STATEMENT SHOULD BE STARTED
OVER IT CAN DO LDWD OLDTXT, STWD TXTPTR RTS SINCE THE TEXT PNTR
AT "NEWSTT" IS ALWAYS STORED IN "OLDTXT".
THE ^C CODE STORES [CURLIN] (THE
CURRENT LINE NUMBER) IN "OLDLIN" SINCE THE ^C CHECK
IS MADE BEFORE THE STATEMENT POINTED TO IS
EXECUTED. "STOP" AND "END" STORE THE TEXT POINTER
FROM "TXTPTR", WHICH POINTS AT THEIR TERMINATING
CHARACTER, IN "OLDTXT".
STATEMENT CODE
THE INDIVIDUAL STATEMENT CODE COMES
NEXT. THE APPROACH USED IN EXECUTING EACH
STATEMENT IS DOCUMENTED IN THE STATEMENT CODE
ITSELF.
FRMEVL, THE FORMULA EVALUATOR
GIVEN A TEXT POINTER POINTING TO THE STARTING
CHARACTER OF A FORMULA, "FRMEVL"
EVALUATES THE FORMULA AND LEAVES
THE VALUE IN THE FLOATING ACCUMULATOR (FAC).
"TXTPTR" IS RETURNED POINTING TO THE FIRST CHARACTER
THAT COULD NOT BE INTERPRETED AS PART OF THE
FORMULA. THE ALGORITHM USES THE STACK
TO STORE TEMPORARY RESULTS:
0. PUT A DUMMY PRECEDENCE OF ZERO ON
THE STACK.
1. READ LEXEME (CONSTANT,FUNCTION,
VARIABLE,FORMULA IN PARENS)
AND TAKE THE LAST PRECEDENCE VALUE
OFF THE STACK.
2. SEE IF THE NEXT CHARACTER IS AN OPERATOR.
IF NOT, CHECK PREVIOUS ONE. THIS MAY CAUSE
OPERATOR APPLICATION OR AN ACTUAL
RETURN FROM "FRMEVL".
3. IF IT IS, SEE WHAT PRECEDENCE IT HAS
AND COMPARE IT TO THE PRECEDENCE
OF THE LAST OPERATOR ON THE STACK.
4. IF = OR LESS REMEMBER THE OPERATOR
POINTER OF THIS OPERATOR
AND BRANCH TO "QCHNUM" TO CAUSE
APPLICATION OF THE LAST OPERATOR.
EVENTUALLY RETURN TO STEP 2
BY RETURNING TO JUST AFTER "DOPREC".
5. IF GREATER PUT THE LAST PRECEDENCE
BACK ON, SAVE THE OPERATOR ADDRESS,
CURRENT TEMPORARY RESULT,
AND PRECEDENCE AND RETURN TO STEP 1.
RELATIONAL OPERATORS ARE ALL HANDLED THROUGH
A COMMON ROUTINE. SPECIAL
CARE IS TAKEN TO DETECT TYPE MISMATCHES SUCH AS 3+"F".
EVAL -- THE ROUTINE TO READ A LEXEME
"EVAL" CHECKS FOR THE DIFFERENT TYPES OF
ENTITIES IT IS SUPPOSED TO DETECT.
LEADING PLUSES ARE IGNORED,
DIGITS AND "." CAUSE "FIN" (FLOATING INPUT)
TO BE CALLED. FUNCTION NAMES CAUSE THE
FORMULA INSIDE THE PARENTHESES TO BE EVALUATED
AND THE FUNCTION ROUTINE TO BE CALLED. VARIABLE
NAMES CAUSE "PTRGET" TO BE CALLED TO GET A POINTER
TO THE VALUE, AND THEN THE VALUE IS PUT INTO
THE FAC. AN OPEN PARENTHESIS CAUSES "FRMEVL"
TO BE CALLED (RECURSIVELY), AND THE ")" TO
BE CHECKED FOR. UNARY OPERATORS (NOT AND
NEGATION) PUT THEIR PRECEDENCE ON THE STACK
AND ENTER FORMULA EVALUATION AT STEP 1, SO
THAT EVERYTHING UP TO AN OPERATOR GREATER THAN
THEIR PRECEDENCE OR THE END OF THE FORMULA
WILL BE EVALUATED.
DIMENSION AND VARIABLE SEARCHING
SPACE IS ALLOCATED FOR VARIABLES AS THEY ARE
ENCOUNTERED. THUS "DIM" STATEMENTS MUST BE
EXECUTED TO HAVE EFFECT. 6 BYTES ARE ALLOCATED
FOR EACH SIMPLE VARIABLE, WHETHER IT IS A STRING,
NUMBER OR USER DEFINED FUNCTION. THE FIRST TWO
BYTES GIVE THE NAME OF THE VARIABLE AND THE LAST FOUR
GIVE ITS VALUE. [VARTAB] GIVES THE FIRST LOCATION
WHERE A SIMPLE VARIABLE NAME IS FOUND AND [ARYTAB]
GIVES THE LOCATION TO STOP SEARCHING FOR SIMPLE
VARIABLES. A "FOR" ENTRY HAS A TEXT POINTER
AND A POINTER TO A VARIABLE VALUE SO NEITHER
THE PROGRAM OR THE SIMPLE VARIABLES CAN BE
MOVED WHILE THERE ARE ACTIVE "FOR" ENTRIES ON THE STACK.
USER DEFINED FUNCTION VALUES ALSO CONTAIN
POINTERS INTO SIMPLE VARIABLE SPACE SO NO USER-DEFINED
FUNCTION VALUES CAN BE RETAINED IF SIMPLE VARIABLES
ARE MOVED. ADDING A SIMPLE VARIABLE IS JUST
ADDING SIX TO [ARYTAB] AND [STREND], BLOCK TRANSFERING
THE ARRAY VARIABLES UP BY SIX AND MAKING SURE THE
NEW [STREND] IS NOT TOO CLOSE TO THE STRINGS.
THIS MOVEMENT OF ARRAY VARIABLES MEANS
THAT NO POINTER TO AN ARRAY WILL STAY VALID WHEN
NEW SIMPLE VARIABLES CAN BE ENCOUNTERED. THIS IS
WHY ARRAY VARIABLES ARE NOT ALLOWED FOR "FOR"
LOOP VARIABLES. SETTING UP A NEW ARRAY VARIABLE
MERELY INVOLVES BUILDING THE DESCRIPTOR,
UPDATING [STREND], AND MAKING SURE THERE IS
STILL ENOUGH ROOM BETWEEN [STREND] AND STRING SPACE.
"PTRGET", THE ROUTINE WHICH RETURNS A POINTER
TO A VARIABLE VALUE, HAS TWO IMPORTANT FLAGS. ONE IS
"DIMFLG" WHICH INDICATES WHETHER "DIM" CALLED "PTRGET"
OR NOT. IF SO, NO PRIOR ENTRY FOR THE VARIABLE IN
QUESTION SHOULD BE FOUND, AND THE INDEX INDICATES
HOW MUCH SPACE TO SET ASIDE. SIMPLE VARIABLES CAN
BE "DIMENSIONED", BUT THE ONLY EFFECT WILL BE TO
SET ASIDE SPACE FOR THE VARIABLE IF IT HASN'T BEEN
ENCOUNTERED YET. THE OTHER IMPORTANT FLAG IS "SUBFLG"
WHICH INDICATES WHETHER A SUBSCRIPTED VARIABLE SHOULD BE
ALLOWED IN THE CURRENT CONTEXT. IF [SUBFLG] IS NON-ZERO
THE OPEN PARENTHESIS FOR A SUBSCRIPTED VARIABLE
WILL NOT BE SCANNED BY "PTRGET", AND "PTRGET" WILL RETURN
WITH A TEXT POINTER POINTING TO THE "(", IF
THERE WAS ONE.
STRINGS
IN THE VARIABLE TABLES STRINGS ARE STORED JUST LIKE
NUMERIC VARIABLES. SIMPLE STRINGS HAVE THREE VALUE
BYTES WHICH ARE INITIALIZED TO ALL ZEROS (WHICH
REPRESENTS THE NULL STRING). THE ONLY DIFFERENCE
IN HANDLING IS THAT WHEN "PTRGET" SEES A "$" AFTER THE
NAME OF A VARIABLE, "PTRGET" SETS [VALTYP]
TO NEGATIVE ONE AND TURNS
ON THE MSB (MOST-SIGNIFIGANT-BIT) OF THE VALUE OF
THE FIRST CHARACTER OF THE VARIABLE NAME.
HAVING THIS BIT ON IN THE NAME OF THE VARIABLE ENSURES
THAT THE SEARCH ROUTINE WILL NOT MATCH
'A' WITH 'A$' OR 'A$' WITH 'A'. THE MEANING OF
THE THREE VALUE BYTES ARE:
LOW
LENGTH OF THE STRING
LOW 8 BITS
HIGH 8 BITS OF THE ADDRESS
OF THE CHARACTERS IN THE
STRING IF LENGTH.NE.0.
MEANINGLESS OTHERWISE.
HIGH
THE VALUE OF A STRING VARIABLE (THESE 3 BYTES)
IS CALLED THE STRING DESCRIPTOR TO DISTINGUISH
IT FROM THE ACTUAL STRING DATA. WHENEVER A
STRING CONSTANT IS ENCOUNTERED IN A FORMULA OR AS
PART OF AN INPUT STRING, OR AS PART OF DATA, "STRLIT"
IS CALLED, CAUSING A DESCRIPTOR TO BE BUILT FOR
THE STRING. WHEN ASSIGNMENT IS MADE TO A STRING POINTING INTO
"BUF" THE VALUE IS COPIED INTO STRING SPACE SINCE [BUF]
IS ALWAYS CHANGING.
STRING FUNCTIONS AND THE ONE STRING OPERATOR "+"
ALWAYS RETURN THEIR VALUES IN STRING SPACE.
ASSIGNING A STRING A CONSTANT VALUE IN A PROGRAM
THROUGH A "READ" OR ASSIGNMENT STATEMENT
WILL NOT USE ANY STRING SPACE SINCE
THE STRING DESCRIPTOR WILL POINT INTO THE
PROGRAM ITSELF. IN GENERAL, COPYING IS DONE
WHEN A STRING VALUE IS IN "BUF", OR IT IS IN STRING
SPACE AND THERE IS AN ACTIVE POINTER TO IT.
THUS F$=G$ WILL CAUSE COPYING IF G$ HAS ITS
STRING DATA IN STRING SPACE. F$=CHR$(7)
WILL USE ONE BYTE OF STRING SPACE TO STORE THE
NEW ONE CHARACTER STRING CREATED BY "CHR$", BUT
THE ASSIGNMENT ITSELF WILL CAUSE NO COPYING SINCE
THE ONLY POINTER AT THE NEW STRING IS A
TEMPORARY DESCRIPTOR CREATED BY "FRMEVL" WHICH WILL
GO AWAY AS SOON AS THE ASSIGNMENT IS DONE.
IT IS THE NATURE OF GARBAGE COLLECTION THAT
DISALLOWS HAVING TWO STRING DESCRIPTORS POINT TO THE SAME
AREA IN STRING SPACE. STRING FUNCTIONS AND OPERATORS
MUST PROCEED AS FOLLOWS:
1) FIGURE OUT THE LENGTH OF THEIR RESULT.
2) CALL "GETSPA" TO FIND SPACE FOR THEIR
RESULT. THE ARGUMENTS TO THE FUNCTION
OR OPERATOR MAY CHANGE SINCE GARBAGE COLLECTION
MAY BE INVOKED. THE ONLY THING THAT CAN
BE SAVED DURING THE CALL TO "GETSPA" IS A POINTER
TO THE DESCRIPTORS OF THE ARGUMENTS.
3) CONSTRUCT THE RESULT DESCRIPTOR IN "DSCTMP".
"GETSPA" RETURNS THE LOCATION OF THE AVAILABLE
SPACE.
4) CREATE THE NEW VALUE BY COPYING PARTS
OF THE ARGUMENTS OR WHATEVER.
5) FREE UP THE ARGUMENTS BY CALLING "FRETMP".
6) JUMP TO "PUTNEW" TO GET THE DESCRIPTOR IN
"DSCTMP" TRANSFERRED INTO A NEW STRING TEMPORARY.
THE REASON FOR STRING TEMPORARIES IS THAT GARBAGE
COLLECTION HAS TO KNOW ABOUT ALL ACTIVE STRING DESCRIPTORS
SO IT KNOWS WHAT IS AND ISN'T IN USE. STRING TEMPORARIES ARE
USED TO STORE THE DESCRIPTORS OF STRING EXPRESSIONS.
INSTEAD OF HAVING AN ACTUAL VALUE STORED IN THE
FAC, AND HAVING THE VALUE OF A TEMPORARY RESULT
BEING SAVED ON THE STACK, AS HAPPENS WITH NUMERIC
VARIABLES, STRINGS HAVE THE POINTER TO A STRING DESCRIPTOR
STORED IN THE FAC, AND IT IS THIS POINTER
THAT GETS SAVED ON THE STACK BY FORMULA EVALUATION.
STRING FUNCTIONS CANNOT FREE THEIR ARGUMENTS UP RIGHT
AWAY SINCE "GETSPA" MAY FORCE
GARBAGE COLLECTION AND THE ARGUMENT STRINGS
MAY BE OVER-WRITTEN SINCE GARBAGE COLLECTION
WILL NOT BE ABLE TO FIND AN ACTIVE POINTER TO
THEM. FUNCTION AND OPERATOR RESULTS ARE BUILT IN
"DSCTMP" SINCE STRING TEMPORARIES ARE ALLOCATED
(PUTNEW) AND DEALLOCATED (FRETMP) IN A FIFO ORDERING
(I.E. A STACK) SO THE NEW TEMPORARY CANNOT
BE SET UP UNTIL THE OLD ONE(S) ARE FREED. TRYING
TO BUILD A RESULT IN A TEMPORARY AFTER
FREEING UP THE ARGUMENT TEMPORARIES COULD RESULT
IN ONE OF THE ARGUMENT TEMPORARIES BEING OVERWRITTEN
TOO SOON BY THE NEW RESULT.
STRING SPACE IS ALLOCATED AT THE VERY TOP
OF MEMORY. "MEMSIZ" POINTS BEYOND THE LAST LOCATION OF
STRING SPACE. STRINGS ARE STORED IN HIGH LOCATIONS
FIRST. WHENEVER STRING SPACE IS ALLOCATED (GETSPA).
[FRETOP], WHICH IS INITIALIZED TO [MEMSIZ], IS UPDATED
TO GIVE THE HIGHEST LOCATION IN STRING SPACE
THAT IS NOT IN USE. THE RESULT IS THAT
[FRETOP] GETS SMALLER AND SMALLER, UNTIL SOME
ALLOCATION WOULD MAKE [FRETOP] LESS THAN OR EQUAL TO
[STREND]. THIS MEANS STRING SPACE HAS RUN INTO THE
THE ARRAYS AND THAT GARBAGE COLLECTION MUST BE CALLED.
GARBAGE COLLECTION:
0. [MINPTR]=[STREND] [FRETOP]=[MEMSIZ]
1. [REMMIN]=0
2. FOR EACH STRING DESCRIPTOR
(TEMPORARIES, SIMPLE STRINGS, STRING ARRAYS)
IF THE STRING IS NOT NULL AND ITS POINTER IS
.GT.MINPTR AND .LT.FRETOP,
[MINPTR]=THIS STRING DESCRIPTOR'S POINTER,
[REMMIN]=POINTER AT THIS STRING DESCRIPTOR.
END.
3. IF REMMIN.NE.0 (WE FOUND AN UNCOLLECTED STRING),
BLOCK TRANSFER THE STRING DATA POINTED
TO IN THE STRING DESCRIPTOR POINTED TO BY "REMMIN"
SO THAT THE LAST BYTE OF STRING DATA IS AT
[FRETOP]. UPDATE [FRETOP] SO THAT IT
POINTS TO THE LOCATION JUST BELOW THE ONE
THE STRING DATA WAS MOVED INTO. UPDATE
THE POINTER IN THE DESCRIPTOR SO IT POINTS
TO THE NEW LOCATION OF THE STRING DATA.
GO TO STEP 1.
AFTER CALLING GARBAGE COLLECTION "GETSPA" AGAIN CHECKS
TO SEE IF [ACCA] CHARACTERS ARE AVAILABLE BETWEEN
[STREND] AND [FRETOP]; IF NOT, AN "OUT OF STRING"
ERROR IS INVOKED.
MATH PACKAGE
THE MATH PACKAGE CONTAINS FLOATING INPUT (FIN),
FLOATING OUTPUT (FOUT), FLOATING COMPARE (FCOMP)
... AND ALL THE NUMERIC OPERATORS AND FUNCTIONS.
THE FORMATS, CONVENTIONS AND ENTRY POINTS ARE ALL
DESCRIBED IN THE MATH PACKAGE ITSELF.
INIT -- THE INITIALIZATION ROUTINE
THE AMOUNT OF MEMORY,
TERMINAL WIDTH, AND WHICH FUNCTIONS TO BE RETAINED
ARE ASCERTAINED FROM THE USER. A ZERO IS PUT DOWN
AT THE FIRST LOCATION NOT USED BY THE MATH-PACKAGE
AND [TXTTAB] IS SET UP TO POINT AT THE NEXT LOCATION.
THIS DETERMINES WHERE PROGRAM STORAGE WILL START.
SPECIAL CHECKS ARE MADE TO MAKE SURE
ALL QUESTIONS IN "INIT" ARE ANSWERED REASONABLY, SINCE
ONCE "INIT" FINISHES, THE LOCATIONS IT USES ARE
USED FOR PROGRAM STORAGE. THE LAST THING "INIT" DOES IS
CHANGE LOCATION ZERO TO BE A JUMP TO "READY" INSTEAD
OF "INIT". ONCE THIS IS DONE THERE IS NO WAY TO RESTART
"INIT".
HIGH LOCATIONS
*
PAGE
SUBTTL PAGE ZERO.
IFN REALIO-3,<
START: JMP INIT ;INITIALIZE - SETUP CERTAIN LOCATIONS
;AND DELETE FUNCTIONS IF NOT NEEDED,
;AND CHANGE THIS TO "JMP READY"
;IN CASE USER RESTARTS AT LOC ZERO.
RDYJSR: JMP INIT ;CHANGED TO "JMP STROUT" BY "INIT"
;TO HANDLE ERRORS.
ADRAYI: ADR(AYINT) ;STORE HERE THE ADDR OF THE
;ROUTINE TO TURN THE FAC INTO A
;TWO BYTE SIGNED INTEGER IN [Y,A]
ADRGAY: ADR(GIVAYF)> ;STORE HERE THE ADDR OF THE
;ROUTINE TO CONVERT [Y,A] TO A FLOATING
;POINT NUMBER IN THE FAC.
IFN ROMSW,<
USRPOK: JMP FCERR> ;SET UP ORIG BY INIT.
;
; THIS IS THE "VOLATILE" STORAGE AREA AND NONE OF IT
; CAN BE KEPT IN ROM. ANY CONSTANTS IN THIS AREA CANNOT
; BE KEPT IN A ROM, BUT MUST BE LOADED IN BY THE
; PROGRAM INSTRUCTIONS IN ROM.
;
; --- GENERAL RAM ---:
CHARAC: BLOCK 1 ;A DELIMITING CHARACTER.
INTEGR= CHARAC ;A ONE-BYTE INTEGER FROM "QINT".
ENDCHR: BLOCK 1 ;THE OTHER DELIMITING CHARACTER.
COUNT: BLOCK 1 ;A GENERAL COUNTER.
; --- FLAGS ---:
DIMFLG: BLOCK 1 ;IN GETTING A POINTER TO A VARIABLE
;IT IS IMPORTANT TO REMEMBER WHETHER IT
;IS BEING DONE FOR "DIM" OR NOT.
;DIMFLG AND VALTYP MUST BE
;CONSECUTIVE LOCATIONS.
KIMY= DIMFLG ;PLACE TO PRESERVE Y DURING OUT.
VALTYP: BLOCK 1 ;THE TYPE INDICATOR.
;0=NUMERIC 1=STRING.
IFN INTPRC,<
INTFLG: BLOCK 1> ;TELLS IF INTEGER.
DORES: BLOCK 1 ;WHETHER CAN OR CAN'T CRUNCH RES'D WORDS.
;TURNED ON WHEN "DATA"
;BEING SCANNED BY CRUNCH SO UNQUOTED
;STRINGS WON'T BE CRUNCHED.
GARBFL= DORES ;WHETHER TO DO GARBAGE COLLECTION.
SUBFLG: BLOCK 1 ;FLAG WHETHER SUB'D VARIABLE ALLOWED.
;"FOR" AND USER-DEFINED FUNCTION
;POINTER FETCHING TURN
;THIS ON BEFORE CALLING "PTRGET"
;SO ARRAYS WON'T BE DETECTED.
;"STKINI" AND "PTRGET" CLEAR IT.
;ALSO DISALLOWS INTEGERS THERE.
INPFLG: BLOCK 1 ;FLAGS WHETHER WE ARE DOING "INPUT"
;OR "READ".
TANSGN: BLOCK 1 ;USED IN DETERMINING SIGN OF TANGENT.
IFN REALIO,<
CNTWFL: BLOCK 1> ;SUPPRESS OUTPUT FLAG.
;NON-ZERO MEANS SUPPRESS.
;RESET BY "INPUT", READY AND ERRORS.
;COMPLEMENTED BY INPUT OF ^O.
IFE REALIO-4,<ORG 80> ;ROOM FOR APPLE PAGE 0 STUFF.
; --- RAM DEALING WITH TERMINAL HANDLING ---:
IFN EXTIO,<
CHANNL: BLOCK 1> ;HOLDS CHANNEL NUMBER.
IFN NULCMD,<
NULCNT: 0> ;NUMBER OF NULLS TO PRINT.
IFN REALIO-3,<
TRMPOS: BLOCK 1> ;POSITION OF TERMINAL CARRIAGE.
LINWID: LINLEN ;LENGTH OF LINE (WIDTH).
NCMWID: NCMPOS ;POSITION BEYOND WHICH THERE ARE
;NO MORE FIELDS.
LINNUM: 0 ;LOCATION TO STORE LINE NUMBER BEFORE BUF
;SO THAT "BLTUC" CAN STORE IT ALL AWAY AT ONCE.
44 ;A COMMA (PRELOAD OR FROM ROM)
;USED BY INPUT STATEMENT SINCE THE
;DATA POINTER ALWAYS STARTS ON A
;COMMA OR TERMINATOR.
IFE BUFPAG,<
BUF: BLOCK BUFLEN> ;TYPE IN STORED HERE.
;DIRECT STATEMENTS EXECUTE OUT OF
;HERE. REMEMBER "INPUT" SMASHES BUF.
;MUST BE ON PAGE ZERO
;OR ASSIGNMENT OF STRING
;VALUES IN DIRECT STATEMENTS WON'T COPY
;INTO STRING SPACE -- WHICH IT MUST.
;N.B. TWO NONZERO BYTES MUST PRECEDE "BUFLNM".
; --- STORAGE FOR TEMPORARY THINGS ---:
TEMPPT: BLOCK 1 ;POINTER AT FIRST FREE TEMP DESCRIPTOR.
;INITIALIZED TO POINT TO TEMPST.
LASTPT: BLOCK 2 ;POINTER TO LAST-USED STRING TEMPORARY.
TEMPST: BLOCK STRSIZ*NUMTMP ;STORAGE FOR NUMTMP TEMP DESCRIPTORS.
INDEX1: BLOCK 2 ;INDEXES.
INDEX= INDEX1
INDEX2: BLOCK 2
RESHO: BLOCK 1 ;RESULT OF MULTIPLIER AND DIVIDER.
IFN ADDPRC,<
RESMOH: BLOCK 1> ;ONE MORE BYTE.
RESMO: BLOCK 1
RESLO: BLOCK 1
ADDEND= RESMO ;TEMPORARY USED BY "UMULT".
0 ;OVERFLOW FOR RES.
; --- POINTERS INTO DYNAMIC DATA STRUCTURES ---;
TXTTAB: BLOCK 2 ;POINTER TO BEGINNING OF TEXT.
;DOESN'T CHANGE AFTER BEING
;SETUP BY "INIT".
VARTAB: BLOCK 2 ;POINTER TO START OF SIMPLE
;VARIABLE SPACE.
;UPDATED WHENEVER THE SIZE OF THE
;PROGRAM CHANGES, SET TO [TXTTAB]
;BY "SCRATCH" ("NEW").
ARYTAB: BLOCK 2 ;POINTER TO BEGINNING OF ARRAY
;TABLE.
;INCREMENTED BY 6 WHENEVER
;A NEW SIMPLE VARIABLE IS FOUND, AND
;SET TO [VARTAB] BY "CLEARC".
STREND: BLOCK 2 ;END OF STORAGE IN USE.
;INCREASED WHENEVER A NEW ARRAY
;OR SIMPLE VARIABLE IS ENCOUNTERED.
;SET TO [VARTAB] BY "CLEARC".
FRETOP: BLOCK 2 ;TOP OF STRING FREE SPACE.
FRESPC: BLOCK 2 ;POINTER TO NEW STRING.
MEMSIZ: BLOCK 2 ;HIGHEST LOCATION IN MEMORY.
; --- LINE NUMBERS AND TEXTUAL POINTERS ---:
CURLIN: BLOCK 2 ;CURRENT LINE #.
;SET TO 0,255 FOR DIRECT STATEMENTS.
OLDLIN: BLOCK 2 ;OLD LINE NUMBER (SETUP BY ^C,"STOP"
;OR "END" IN A PROGRAM).
POKER= LINNUM ;SET UP LOCATION USED BY POKE.
;TEMPORARY FOR INPUT AND READ CODE
OLDTXT: BLOCK 2 ;OLD TEXT POINTER.
;POINTS AT STATEMENT TO BE EXEC'D NEXT.
DATLIN: BLOCK 2 ;DATA LINE # -- REMEMBER FOR ERRORS.
DATPTR: BLOCK 2 ;POINTER TO DATA. INITIALIZED TO POINT
;AT THE ZERO IN FRONT OF [TXTTAB]
;BY "RESTORE" WHICH IS CALLED BY "CLEARC".
;UPDATED BY EXECUTION OF A "READ".
INPPTR: BLOCK 2 ;THIS REMEMBERS WHERE INPUT IS COMING FROM.
; --- STUFF USED IN EVALUATIONS ---:
VARNAM: BLOCK 2 ;VARIABLE'S NAME IS STORED HERE.
VARPNT: BLOCK 2 ;POINTER TO VARIABLE IN MEMORY.
FDECPT= VARPNT ;POINTER INTO POWER OF TENS OF "FOUT".
FORPNT: BLOCK 2 ;A VARIABLE'S POINTER FOR "FOR" LOOPS
;AND "LET" STATEMENTS.
LSTPNT= FORPNT ;PNTR TO LIST STRING.
ANDMSK= FORPNT ;THE MASK USED BY WAIT FOR ANDING.
EORMSK= FORPNT+1 ;THE MASK FOR EORING IN WAIT.
OPPTR: BLOCK 2 ;POINTER TO CURRENT OP'S ENTRY IN "OPTAB".
VARTXT= OPPTR ;POINTER INTO LIST OF VARIABLES.
OPMASK: BLOCK 1 ;MASK CREATED BY CURRENT OPERATOR.
DOMASK=TANSGN ;MASK IN USE BY RELATION OPERATIONS.
DEFPNT: BLOCK 2 ;POINTER USED IN FUNCTION DEFINITION.
GRBPNT= DEFPNT ;ANOTHER USED IN GARBAGE COLLECTION.
DSCPNT: BLOCK 2 ;POINTER TO A STRING DESCRIPTOR.
IFN ADDPRC,<BLOCK 1> ;FOR TEMPF3.
FOUR6: EXP STRSIZ ;VARIABLE CONSTANT USED BY GARB COLLECT.
; --- ET CETERA ---:
JMPER: JMP 60000
SIZE= JMPER+1
OLDOV= JMPER+2 ;THE OLD OVERFLOW.
TEMPF3= DEFPNT ;A THIRD FAC TEMPORARY (4 BYTES).
TEMPF1:
IFN ADDPRC,<0> ;FOR TEMPF1S EXTRA BYTE.
HIGHDS: BLOCK 2 ;DESINATION OF HIGHEST ELEMENT IN BLT.
HIGHTR: BLOCK 2 ;SOURCE OF HIGHEST ELEMENT TO MOVE.
TEMPF2:
IFN ADDPRC,<0> ;FOR TEMPF2S EXTRA BYTE.
LOWDS: BLOCK 2 ;LOCATION OF LAST BYTE TRANSFERRED INTO.
LOWTR: BLOCK 2 ;LAST THING TO MOVE IN BLT.
ARYPNT= HIGHDS ;A POINTER USED IN ARRAY BUILDING.
GRBTOP= LOWTR ;A POINTER USED IN GARBAGE COLLECTION.
DECCNT= LOWDS ;NUMBER OF PLACES BEFORE DECIMAL POINT.
TENEXP= LOWDS+1 ;HAS A DPT BEEN INPUT?
DPTFLG= LOWTR ;BASE TEN EXPONENT.
EXPSGN= LOWTR+1 ;SIGN OF BASE TEN EXPONENT.
; --- THE FLOATING ACCUMULATOR ---:
FAC:
FACEXP: 0
FACHO: 0 ;MOST SIGNIFICANT BYTE OF MANTISSA.
IFN ADDPRC,<
FACMOH: 0> ;ONE MORE.
FACMO: 0 ;MIDDLE ORDER OF MANTISSA.
FACLO: 0 ;LEAST SIG BYTE OF MANTISSA.
FACSGN: 0 ;SIGN OF FAC (0 OR -1) WHEN UNPACKED.
SGNFLG: 0 ;SIGN OF FAC IS PRESERVED BERE BY "FIN".
DEGREE= SGNFLG ;A COUNT USED BY POLYNOMIALS.
DSCTMP= FAC ;THIS IS WHERE TEMP DESCS ARE BUILT.
INDICE= FACMO ;INDICE IS SET UP HERE BY "QINT".
BITS: 0 ;SOMETHING FOR "SHIFTR" TO USE.
; --- THE FLOATING ARGUMENT (UNPACKED) ---:
ARGEXP: 0
ARGHO: 0
IFN ADDPRC,<ARGMOH: 0>
ARGMO: 0
ARGLO: 0
ARGSGN: 0
ARISGN: 0 ;A SIGN REFLECTING THE RESULT.
FACOV: 0 ;OVERFLOW BYTE OF THE FAC.
STRNG1= ARISGN ;POINTER TO A STRING OR DESCRIPTOR.
FBUFPT: BLOCK 2 ;POINTER INTO FBUFFR USED BY FOUT.
BUFPTR= FBUFPT ;POINTER TO BUF USED BY "CRUNCH".
STRNG2= FBUFPT ;POINTER TO STRING OR DESC.
POLYPT= FBUFPT ;POINTER INTO POLYNOMIAL COEFFICIENTS.
CURTOL= FBUFPT ;ABSOLUTE LINEAR INDEX IS FORMED HERE.
PAGE
SUBTTL RAM CODE.
; THIS CODE GETS CHANGED THROUGHOUT EXECUTION.
; IT IS MADE TO BE FAST THIS WAY.
; ALSO, [X] AND [Y] ARE NOT DISTURBED
;
; "CHRGET" USING [TXTPTR] AS THE CURRENT TEXT PNTR
; FETCHES A NEW CHARACTER INTO ACCA AFTER INCREMENTING [TXTPTR]
; AND SETS CONDITION CODES ACCORDING TO WHAT'S IN ACCA.
; NOT C= NUMERIC ("0" THRU "9")
; Z= ":" OR END-OF-LINE (A NULL)
;
; [ACCA] = NEW CHAR.
; [TXTPTR]=[TXTPTR]+1
;
; THE FOLLOWING EXISTS IN ROM IF ROM EXISTS AND IS LOADED
; DOWN HERE BY INIT. OTHERWISE IT IS JUST LOADED INTO THIS
; RAM LIKE ALL THE REST OF RAM IS LOADED.
;
CHRGET: INC CHRGET+7 ;INCREMENT THE WHOLE TXTPTR.
BNE CHRGOT
INC CHRGET+8
CHRGOT: LDA 60000 ;A LOAD WITH AN EXT ADDR.