S-C DocuMentor — Applesoft

               SAVE S.D52C
               1010 *--------------------------------
               1020 *      READ A LINE, AND STRIP OFF SIGN BITS
               1030 *--------------------------------
D52C- A2 80    1040 INLIN  LDX #$80     NULL PROMPT
D52E- 86 33    1050 INLIN2 STX MON.PROMPT
D530- 20 6A FD 1060        JSR MON.GETLN
D533- E0 EF    1070        CPX #239     MAXIMUM LINE LENGTH
D535- 90 02    1080        BCC .1
D537- A2 EF    1090        LDX #239     TRUNCATE AT 239 CHARS
D539- A9 00    1100 .1     LDA #0       MARK END OF LINE WITH $00 BYTE
D53B- 9D 00 02 1110        STA INPUT.BUFFER,X
D53E- 8A       1120        TXA
D53F- F0 0B    1130        BEQ .3       NULL INPUT LINE
D541- BD FF 01 1140 .2     LDA INPUT.BUFFER-1,X   DROP SIGN BITS
D544- 29 7F    1150        AND #$7F
D546- 9D FF 01 1160        STA INPUT.BUFFER-1,X
D549- CA       1170        DEX
D54A- D0 F5    1180        BNE .2
D54C- A9 00    1190 .3     LDA #0       (Y,X) POINTS AT BUFFER-1
D54E- A2 FF    1200        LDX #INPUT.BUFFER-1
D550- A0 01    1210        LDY /INPUT.BUFFER-1
D552- 60       1220        RTS
               1230 *--------------------------------
D553- 20 0C FD 1240 INCHR  JSR MON.RDKEY    *** OUGHT TO BE "BIT $C010" ***
D556- 29 7F    1250        AND #$7F
D558- 60       1260        RTS
               1270 *--------------------------------
               1280 *      TOKENIZE THE INPUT LINE
               1290 *--------------------------------
               1300 PARSE.INPUT.LINE
D559- A6 B8    1310        LDX TXTPTR   INDEX INTO UNPARSED LINE
D55B- CA       1320        DEX          PREPARE FOR INX AT "PARSE"
D55C- A0 04    1330        LDY #4       INDEX TO PARSED OUTPUT LINE
D55E- 84 13    1340        STY DATAFLG  CLEAR SIGN-BIT OF DATAFLG
D560- 24 D6    1350        BIT LOCK     IS THIS PROGRAM LOCKED?
D562- 10 08    1360        BPL PARSE    NO, GO AHEAD AND PARSE THE LINE
D564- 68       1370        PLA          YES, IGNORE INPUT AND "RUN"
D565- 68       1380        PLA             THE PROGRAM
D566- 20 65 D6 1390        JSR SETPTRS  CLEAR ALL VARIABLES
D569- 4C D2 D7 1400        JMP NEWSTT   START RUNNING
               1410 *--------------------------------
D56C- E8       1420 PARSE  INX          NEXT INPUT CHARACTER
D56D- BD 00 02 1430 .1     LDA INPUT.BUFFER,X
D570- 24 13    1440        BIT DATAFLG       IN A "DATA" STATEMENT?
D572- 70 04    1450        BVS .2            YES (DATAFLG = $49)
D574- C9 20    1460        CMP #' '     IGNORE BLANKS
D576- F0 F4    1470        BEQ PARSE
D578- 85 0E    1480 .2     STA ENDCHR
D57A- C9 22    1490        CMP #'"      START OF QUOTATION?
D57C- F0 74    1500        BEQ .13
D57E- 70 4D    1510        BVS .9       BRANCH IF IN "DATA" STATEMENT
D580- C9 3F    1520        CMP #'?      SHORTHAND FOR "PRINT"?
D582- D0 04    1530        BNE .3       NO
D584- A9 BA    1540        LDA #TOKEN.PRINT  YES, REPLACE WITH "PRINT" TOKEN
D586- D0 45    1550        BNE .9       ...ALWAYS
D588- C9 30    1560 .3     CMP #'0      IS IT A DIGIT, COLON, OR SEMI-COLON?
D58A- 90 04    1570        BCC .4       NO, PUNCTUATION !"#$%&'()*+,-./
D58C- C9 3C    1580        CMP #';'+1
D58E- 90 3D    1590        BCC .9       YES, NOT A TOKEN
               1600 *--------------------------------
               1610 *      SEARCH TOKEN NAME TABLE FOR MATCH STARTING
               1620 *      WITH CURRENT CHAR FROM INPUT LINE
               1630 *--------------------------------
D590- 84 AD    1640 .4     STY STRNG2   SAVE INDEX TO OUTPUT LINE
D592- A9 D0    1650        LDA #TOKEN.NAME.TABLE-$100
D594- 85 9D    1660        STA FAC      MAKE PNTR FOR SEARCH
D596- A9 CF    1670        LDA /TOKEN.NAME.TABLE-$100
D598- 85 9E    1680        STA FAC+1
D59A- A0 00    1690        LDY #0       USE Y-REG WITH (FAC) TO ADDRESS TABLE
D59C- 84 0F    1700        STY TKN.CNTR     HOLDS CURRENT TOKEN-$80
D59E- 88       1710        DEY          PREPARE FOR "INY" A FEW LINES DOWN
D59F- 86 B8    1720        STX TXTPTR   SAVE POSITION IN INPUT LINE
D5A1- CA       1730        DEX          PREPARE FOR "INX" A FEW LINES DOWN
D5A2- C8       1740 .5     INY          ADVANCE POINTER TO TOKEN TABLE
D5A3- D0 02    1750        BNE .6       Y=Y+1 IS ENOUGH
D5A5- E6 9E    1760        INC FAC+1    ALSO NEED TO BUMP THE PAGE
D5A7- E8       1770 .6     INX          ADVANCE POINTER TO INPUT LINE
D5A8- BD 00 02 1780 .7     LDA INPUT.BUFFER,X   NEXT CHAR FROM INPUT LINE
D5AB- C9 20    1790        CMP #' '     THIS CHAR A BLANK?
D5AD- F0 F8    1800        BEQ .6       YES, IGNORE ALL BLANKS
D5AF- 38       1810        SEC          NO, COMPARE TO CHAR IN TABLE
D5B0- F1 9D    1820        SBC (FAC),Y  SAME AS NEXT CHAR OF TOKEN NAME?
D5B2- F0 EE    1830        BEQ .5       YES, CONTINUE MATCHING
D5B4- C9 80    1840        CMP #$80     MAYBE; WAS IT SAME EXCEPT FOR BIT 7?
D5B6- D0 41    1850        BNE .14      NO, SKIP TO NEXT TOKEN
D5B8- 05 0F    1860        ORA TKN.CNTR     YES, END OF TOKEN; GET TOKEN #
D5BA- C9 C5    1870        CMP #TOKEN.AT  DID WE MATCH "AT"?
D5BC- D0 0D    1880        BNE .8       NO, SO NO AMBIGUITY
D5BE- BD 01 02 1890        LDA INPUT.BUFFER+1,X  "AT" COULD BE "ATN" OR "A TO"
D5C1- C9 4E    1900        CMP #'N      "ATN" HAS PRECEDENCE OVER "AT"
D5C3- F0 34    1910        BEQ .14      IT IS "ATN", FIND IT THE HARD WAY
D5C5- C9 4F    1920        CMP #'O      "TO" HAS PRECEDENCE OVER "AT"
D5C7- F0 30    1930        BEQ .14      IT IS "A TO", FIN IT THE HARD WAY
D5C9- A9 C5    1940        LDA #TOKEN.AT     NOT "ATN" OR "A TO", SO USE "AT"
               1950 *--------------------------------
               1960 *      STORE CHARACTER OR TOKEN IN OUTPUT LINE
               1970 *--------------------------------
D5CB- A4 AD    1980 .8     LDY STRNG2   GET INDEX TO OUTPUT LINE IN Y-REG
D5CD- E8       1990 .9     INX          ADVANCE INPUT INDEX
D5CE- C8       2000        INY          ADVANCE OUTPUT INDEX
D5CF- 99 FB 01 2010        STA INPUT.BUFFER-5,Y   STORE CHAR OR TOKEN
D5D2- B9 FB 01 2020        LDA INPUT.BUFFER-5,Y   TEST FOR EOL OR EOS
D5D5- F0 39    2030        BEQ .17      END OF LINE
D5D7- 38       2040        SEC
D5D8- E9 3A    2050        SBC #':      END OF STATEMENT?
D5DA- F0 04    2060        BEQ .10      YES, CLEAR DATAFLG
D5DC- C9 49    2070        CMP #TOKEN.DATA-':'   "DATA" TOKEN?
D5DE- D0 02    2080        BNE .11      NO, LEAVE DATAFLG ALONE
D5E0- 85 13    2090 .10    STA DATAFLG  DATAFLG = 0 OR $83-$3A = $49
D5E2- 38       2100 .11    SEC          IS IT A "REM" TOKEN?
D5E3- E9 78    2110        SBC #TOKEN.REM-':'
D5E5- D0 86    2120        BNE .1       NO, CONTINUE PARSING LINE
D5E7- 85 0E    2130        STA ENDCHR   YES, CLEAR LITERAL FLAG
               2140 *--------------------------------
               2150 *      HANDLE LITERAL (BETWEEN QUOTES) OR REMARK,
               2160 *      BY COPYING CHARS UP TO ENDCHR.
               2170 *--------------------------------
D5E9- BD 00 02 2180 .12    LDA INPUT.BUFFER,X
D5EC- F0 DF    2190        BEQ .9       END OF LINE
D5EE- C5 0E    2200        CMP ENDCHR
D5F0- F0 DB    2210        BEQ .9       FOUND ENDCHR
D5F2- C8       2220 .13    INY          NEXT OUTPUT CHAR
D5F3- 99 FB 01 2230        STA INPUT.BUFFER-5,Y
D5F6- E8       2240        INX          NEXT INPUT CHAR
D5F7- D0 F0    2250        BNE .12      ...ALWAYS
               2260 *--------------------------------
               2270 *      ADVANCE POINTER TO NEXT TOKEN NAME
               2280 *--------------------------------
D5F9- A6 B8    2290 .14    LDX TXTPTR   GET POINTER TO INPUT LINE IN X-REG
D5FB- E6 0F    2300        INC TKN.CNTR     BUMP (TOKEN # - $80)
D5FD- B1 9D    2310 .15    LDA (FAC),Y  SCAN THROUGH TABLE FOR BIT7 = 1
D5FF- C8       2320        INY          NEXT TOKEN ONE BEYOND THAT
D600- D0 02    2330        BNE .16      ...USUALLY ENOUGH TO BUMP Y-REG
D602- E6 9E    2340        INC FAC+1    NEXT SET OF 256 TOKEN CHARS
D604- 0A       2350 .16    ASL          SEE IF SIGN BIT SET ON CHAR
D605- 90 F6    2360        BCC .15      NO, MORE IN THIS NAME
D607- B1 9D    2370        LDA (FAC),Y  YES, AT NEXT NAME.  END OF TABLE?
D609- D0 9D    2380        BNE .7       NO, NOT END OF TABLE
D60B- BD 00 02 2390        LDA INPUT.BUFFER,X   YES, SO NOT A KEYWORD
D60E- 10 BB    2400        BPL .8       ...ALWAYS, COPY CHAR AS IS
               2410 *---END OF LINE------------------
D610- 99 FD 01 2420 .17    STA INPUT.BUFFER-3,Y   STORE ANOTHER 00 ON END
D613- C6 B9    2430        DEC TXTPTR+1      SET TXTPTR = INPUT.BUFFER-1
D615- A9 FF    2440        LDA #INPUT.BUFFER-1
D617- 85 B8    2450        STA TXTPTR
D619- 60       2460        RTS
               2470 *--------------------------------
               2480 *      SEARCH FOR LINE
               2490 *
               2500 *      (LINNUM) = LINE # TO FIND
               2510 *      IF NOT FOUND:  CARRY = 0
               2520 *                     LOWTR POINTS AT NEXT LINE
               2530 *      IF FOUND:      CARRY = 1
               2540 *                     LOWTR POINTS AT LINE
               2550 *--------------------------------
D61A- A5 67    2560 FNDLIN LDA TXTTAB   SEARCH FROM BEGINNING OF PROGRAM
D61C- A6 68    2570        LDX TXTTAB+1
D61E- A0 01    2580 FL1    LDY #1       SEARCH FROM (X,A)
D620- 85 9B    2590        STA LOWTR
D622- 86 9C    2600        STX LOWTR+1
D624- B1 9B    2610        LDA (LOWTR),Y
D626- F0 1F    2620        BEQ .3       END OF PROGRAM, AND NOT FOUND
D628- C8       2630        INY
D629- C8       2640        INY
D62A- A5 51    2650        LDA LINNUM+1
D62C- D1 9B    2660        CMP (LOWTR),Y
D62E- 90 18    2670        BCC RTS.1    IF NOT FOUND
D630- F0 03    2680        BEQ .1
D632- 88       2690        DEY
D633- D0 09    2700        BNE .2
D635- A5 50    2710 .1     LDA LINNUM
D637- 88       2720        DEY
D638- D1 9B    2730        CMP (LOWTR),Y
D63A- 90 0C    2740        BCC RTS.1    PAST LINE, NOT FOUND
D63C- F0 0A    2750        BEQ RTS.1    IF FOUND
D63E- 88       2760 .2     DEY
D63F- B1 9B    2770        LDA (LOWTR),Y
D641- AA       2780        TAX
D642- 88       2790        DEY
D643- B1 9B    2800        LDA (LOWTR),Y
D645- B0 D7    2810        BCS FL1      ALWAYS
D647- 18       2820 .3     CLC          RETURN CARRY = 0
D648- 60       2830 RTS.1  RTS
               2840 *--------------------------------
               2850 *      "NEW" STATEMENT
               2860 *--------------------------------
D649- D0 FD    2870 NEW    BNE RTS.1    IGNORE IF MORE TO THE STATEMENT
D64B- A9 00    2880 SCRTCH LDA #0
D64D- 85 D6    2890        STA LOCK
D64F- A8       2900        TAY
D650- 91 67    2910        STA (TXTTAB),Y
D652- C8       2920        INY
D653- 91 67    2930        STA (TXTTAB),Y
D655- A5 67    2940        LDA TXTTAB
D657- 69 02    2950        ADC #2      (CARRY WASN'T CLEARED, SO "NEW" USUALLY
D659- 85 69    2960        STA VARTAB    ADDS 3, WHEREAS "FP" ADDS 2.)
D65B- 85 AF    2970        STA PRGEND
D65D- A5 68    2980        LDA TXTTAB+1
D65F- 69 00    2990        ADC #0
D661- 85 6A    3000        STA VARTAB+1
D663- 85 B0    3010        STA PRGEND+1
               3020 *--------------------------------
               3030 SETPTRS
D665- 20 97 D6 3040        JSR STXTPT   SET TXTPTR TO TXTTAB - 1
D668- A9 00    3050        LDA #0       (THIS COULD HAVE BEEN ".HS 2C")
               3060 *--------------------------------
               3070 *      "CLEAR" STATEMENT
               3080 *--------------------------------
D66A- D0 2A    3090 CLEAR  BNE RTS.2    IGNORE IF NOT AT END OF STATEMENT
D66C- A5 73    3100 CLEARC LDA MEMSIZ   CLEAR STRING AREA
D66E- A4 74    3110        LDY MEMSIZ+1
D670- 85 6F    3120        STA FRETOP
D672- 84 70    3130        STY FRETOP+1
D674- A5 69    3140        LDA VARTAB   CLEAR ARRAY AREA
D676- A4 6A    3150        LDY VARTAB+1
D678- 85 6B    3160        STA ARYTAB
D67A- 84 6C    3170        STY ARYTAB+1
D67C- 85 6D    3180        STA STREND   LOW END OF FREE SPACE
D67E- 84 6E    3190        STY STREND+1
D680- 20 49 D8 3200        JSR RESTORE  SET "DATA" POINTER TO BEGINNING
               3210 *--------------------------------
D683- A2 55    3220 STKINI LDX #TEMPST
D685- 86 52    3230        STX TEMPPT
D687- 68       3240        PLA          SAVE RETURN ADDRESS
D688- A8       3250        TAY
D689- 68       3260        PLA
D68A- A2 F8    3270        LDX #$F8     START STACK AT $F8,
D68C- 9A       3280        TXS            LEAVING ROOM FOR PARSING LINES
D68D- 48       3290        PHA          RESTORE RETURN ADDRESS
D68E- 98       3300        TYA
D68F- 48       3310        PHA
D690- A9 00    3320        LDA #0
D692- 85 7A    3330        STA OLDTEXT+1
D694- 85 14    3340        STA SUBFLG
D696- 60       3350 RTS.2  RTS
               3360 *--------------------------------
               3370 *      SET TXTPTR TO BEGINNING OF PROGRAM
               3380 *--------------------------------
D697- 18       3390 STXTPT CLC          TXTPTR = TXTTAB - 1
D698- A5 67    3400        LDA TXTTAB
D69A- 69 FF    3410        ADC #$FF
D69C- 85 B8    3420        STA TXTPTR
D69E- A5 68    3430        LDA TXTTAB+1
D6A0- 69 FF    3440        ADC #$FF
D6A2- 85 B9    3450        STA TXTPTR+1
D6A4- 60       3460        RTS
               3470 *--------------------------------
               3480 *      "LIST" STATEMENT
               3490 *--------------------------------
D6A5- 90 0A    3500 LIST   BCC .1       NO  LINE # SPECIFIED
D6A7- F0 08    3510        BEQ .1       ---DITTO---
D6A9- C9 C9    3520        CMP #TOKEN.MINUS  IF DASH OR COMMA, START AT LINE 0
D6AB- F0 04    3530        BEQ .1            IS IS A DASH
D6AD- C9 2C    3540        CMP #',           COMMA?
D6AF- D0 E5    3550        BNE RTS.2         NO, ERROR
D6B1- 20 0C DA 3560 .1     JSR LINGET   CONVERT LINE NUMBER IF ANY
D6B4- 20 1A D6 3570        JSR FNDLIN   POINT LOWTR TO 1ST LINE
D6B7- 20 B7 00 3580        JSR CHRGOT   RANGE SPECIFIED?
D6BA- F0 10    3590        BEQ .3       NO
D6BC- C9 C9    3600        CMP #TOKEN.MINUS
D6BE- F0 04    3610        BEQ .2
D6C0- C9 2C    3620        CMP #',
D6C2- D0 84    3630        BNE RTS.1
D6C4- 20 B1 00 3640 .2     JSR CHRGET   GET NEXT CHAR
D6C7- 20 0C DA 3650        JSR LINGET   CONVERT SECOND LINE #
D6CA- D0 CA    3660        BNE RTS.2    BRANCH IF SYNTAX ERR
D6CC- 68       3670 .3     PLA          POP RETURN ADRESS
D6CD- 68       3680        PLA          (GET BACK BY "JMP NEWSTT")
D6CE- A5 50    3690        LDA LINNUM   IF NO SECOND NUMBER, USE $FFFF
D6D0- 05 51    3700        ORA LINNUM+1
D6D2- D0 06    3710        BNE LIST.0       THERE WAS A SECOND NUMBER
D6D4- A9 FF    3720        LDA #$FF     MAX END RANGE
D6D6- 85 50    3730        STA LINNUM
D6D8- 85 51    3740        STA LINNUM+1
D6DA- A0 01    3750 LIST.0 LDY #1
D6DC- B1 9B    3760        LDA (LOWTR),Y  HIGH BYTE OF LINK
D6DE- F0 44    3770        BEQ LIST.3   END OF PROGRAM
D6E0- 20 58 D8 3780        JSR ISCNTC   CHECK IF CONTROL-C HAS BEEN TYPED
D6E3- 20 FB DA 3790        JSR CRDO     NO, PRINT <RETURN>
D6E6- C8       3800        INY
D6E7- B1 9B    3810        LDA (LOWTR),Y  GET LINE #, COMPARE WITH END RANGE
D6E9- AA       3820        TAX
D6EA- C8       3830        INY
D6EB- B1 9B    3840        LDA (LOWTR),Y
D6ED- C5 51    3850        CMP LINNUM+1
D6EF- D0 04    3860        BNE .5
D6F1- E4 50    3870        CPX LINNUM
D6F3- F0 02    3880        BEQ .6       ON LAST LINE OF RANGE
D6F5- B0 2D    3890 .5     BCS LIST.3   FINISHED THE RANGE
               3900 *---LIST ONE LINE----------------
D6F7- 84 85    3910 .6     STY FORPNT
D6F9- 20 24 ED 3920        JSR LINPRT   PRINT LINE # FROM X,A
D6FC- A9 20    3930        LDA #' '     PRINT SPACE AFTER LINE #
D6FE- A4 85    3940 LIST.1 LDY FORPNT
D700- 29 7F    3950        AND #$7F
D702- 20 5C DB 3960 LIST.2 JSR OUTDO
D705- A5 24    3970        LDA MON.CH   IF PAST COLUMN 33, START A NEW LINE
D707- C9 21    3980        CMP #33
D709- 90 07    3990        BCC .1       < 33
D70B- 20 FB DA 4000        JSR CRDO     PRINT <RETURN>
D70E- A9 05    4010        LDA #5        AND TAB OVER 5
D710- 85 24    4020        STA MON.CH
D712- C8       4030 .1     INY
D713- B1 9B    4040        LDA (LOWTR),Y
D715- D0 1D    4050        BNE LIST.4   NOT END OF LINE YET
D717- A8       4060        TAY          END OF LINE
D718- B1 9B    4070        LDA (LOWTR),Y     GET LINK TO NEXT LINE
D71A- AA       4080        TAX
D71B- C8       4090        INY
D71C- B1 9B    4100        LDA (LOWTR),Y
D71E- 86 9B    4110        STX LOWTR    POINT TO NEXT LINE
D720- 85 9C    4120        STA LOWTR+1
D722- D0 B6    4130        BNE LIST.0       BRANCH IF NOT END OF PROGRAM
D724- A9 0D    4140 LIST.3 LDA #$0D     PRINT <RETURN>
D726- 20 5C DB 4150        JSR OUTDO
D729- 4C D2 D7 4160        JMP NEWSTT   TO NEXT STATEMENT
               4170 *--------------------------------
D72C- C8       4180 GETCHR INY          PICK UP CHAR FROM TABLE
D72D- D0 02    4190        BNE .1
D72F- E6 9E    4200        INC FAC+1
D731- B1 9D    4210 .1     LDA (FAC),Y
D733- 60       4220        RTS
               4230 *--------------------------------
D734- 10 CC    4240 LIST.4 BPL LIST.2   BRANCH IF NOT A TOKEN
D736- 38       4250        SEC
D737- E9 7F    4260        SBC #$7F     CONVERT TOKEN TO INDEX
D739- AA       4270        TAX
D73A- 84 85    4280        STY FORPNT   SAVE LINE POINTER
D73C- A0 D0    4290        LDY #TOKEN.NAME.TABLE-$100
D73E- 84 9D    4300        STY FAC      POINT FAC TO TABLE
D740- A0 CF    4310        LDY /TOKEN.NAME.TABLE-$100
D742- 84 9E    4320        STY FAC+1
D744- A0 FF    4330        LDY #-1
D746- CA       4340 .1     DEX          SKIP KEYWORDS UNTIL REACH THIS ONE
D747- F0 07    4350        BEQ .3
D749- 20 2C D7 4360 .2     JSR GETCHR   BUMP Y, GET CHAR FROM TABLE
D74C- 10 FB    4370        BPL .2       NOT AT END OF KEYWORD YET
D74E- 30 F6    4380        BMI .1       END OF KEYWORD, ALWAYS BRANCHES
D750- A9 20    4390 .3     LDA #' '     FOUND THE RIGHT KEYWORD
D752- 20 5C DB 4400        JSR OUTDO    PRINT LEADING SPACE
D755- 20 2C D7 4410 .4     JSR GETCHR   PRINT THE KEYWORD
D758- 30 05    4420        BMI .5       LAST CHAR OF KEYWORD
D75A- 20 5C DB 4430        JSR OUTDO
D75D- D0 F6    4440        BNE .4       ...ALWAYS
D75F- 20 5C DB 4450 .5     JSR OUTDO    PRINT LAST CHAR OF KEYWORD
D762- A9 20    4460        LDA #' '     PRINT TRAILING SPACE
D764- D0 98    4470        BNE LIST.1   ...ALWAYS, BACK TO ACTUAL LINE