S-C DocuMentor — Applesoft

               SAVE S.EC4A
               1010 *--------------------------------
               1020 *      CONVERT STRING TO FP VALUE IN FAC
               1030 *
               1040 *      STRING POINTED TO BY TXTPTR
               1050 *      FIRST CHAR ALREADY SCANNED BY CHRGET
               1060 *      (A) = FIRST CHAR, C=0 IF DIGIT.
               1070 *--------------------------------
EC4A- A0 00    1080 FIN    LDY #0       CLEAR WORKING AREA ($99...$A3)
EC4C- A2 0A    1090        LDX #10   TMPEXP, EXPON, DPFLG, EXPSGN, FAC, SERLEN
EC4E- 94 99    1100 .1     STY TMPEXP,X
EC50- CA       1110        DEX
EC51- 10 FB    1120        BPL .1
               1130 *--------------------------------
EC53- 90 0F    1140        BCC FIN.2    FIRST CHAR IS A DIGIT
EC55- C9 2D    1150        CMP #'-'     CHECK FOR LEADING SIGN
EC57- D0 04    1160        BNE .2       NOT MINUS
EC59- 86 A3    1170        STX SERLEN   MINUS, SET SERLEN = $FF FOR FLAG
EC5B- F0 04    1180        BEQ FIN.1    ...ALWAYS
EC5D- C9 2B    1190 .2     CMP #'+'     MIGHT BE PLUS
EC5F- D0 05    1200        BNE FIN.3    NOT PLUS EITHER, CHECK DECIMAL POINT
               1210 *--------------------------------
EC61- 20 B1 00 1220 FIN.1  JSR CHRGET   GET NEXT CHAR OF STRING
               1230 *--------------------------------
EC64- 90 5B    1240 FIN.2  BCC FIN.9    INSERT THIS DIGIT
               1250 *--------------------------------
EC66- C9 2E    1260 FIN.3  CMP #'.'     CHECK FOR DECIMAL POINT
EC68- F0 2E    1270        BEQ FIN.10   YES
EC6A- C9 45    1280        CMP #'E'     CHECK FOR EXPONENT PART
EC6C- D0 30    1290        BNE FIN.7    NO, END OF NUMBER
EC6E- 20 B1 00 1300        JSR CHRGET   YES, START CONVERTING EXPONENT
EC71- 90 17    1310        BCC FIN.5    EXPONENT DIGIT
EC73- C9 C9    1320        CMP #TOKEN.MINUS  NEGATIVE EXPONENT?
EC75- F0 0E    1330        BEQ .1            YES
EC77- C9 2D    1340        CMP #'-'          MIGHT NOT BE TOKENIZED YET
EC79- F0 0A    1350        BEQ .1            YES, IT IS NEGATIVE
EC7B- C9 C8    1360        CMP #TOKEN.PLUS   OPTIONAL "+"
EC7D- F0 08    1370        BEQ FIN.4         YES
EC7F- C9 2B    1380        CMP #'+'          MIGHT NOT BE TOKENIZED YET
EC81- F0 04    1390        BEQ FIN.4         YES, FOUND "+"
EC83- D0 07    1400        BNE FIN.6    ...ALWAYS, NUMBER COMPLETED
EC85- 66 9C    1410 .1     ROR EXPSGN   C=1, SET FLAG NEGATIVE
               1420 *--------------------------------
EC87- 20 B1 00 1430 FIN.4  JSR CHRGET   GET NEXT DIGIT OF EXPONENT
               1440 *--------------------------------
EC8A- 90 5C    1450 FIN.5  BCC GETEXP   CHAR IS A DIGIT OF EXPONENT
               1460 *--------------------------------
EC8C- 24 9C    1470 FIN.6  BIT EXPSGN   END OF NUMBER, CHECK EXP SIGN
EC8E- 10 0E    1480        BPL FIN.7    POSITIVE EXPONENT
EC90- A9 00    1490        LDA #0       NEGATIVE EXPONENT
EC92- 38       1500        SEC          MAKE 2'S COMPLEMENT OF EXPONENT
EC93- E5 9A    1510        SBC EXPON
EC95- 4C A0 EC 1520        JMP FIN.8
               1530 *--------------------------------
               1540 *      FOUND A DECIMAL POINT
               1550 *--------------------------------
EC98- 66 9B    1560 FIN.10 ROR DPFLG    C=1, SET DPFLG FOR DECIMAL POINT
EC9A- 24 9B    1570        BIT DPFLG    CHECK IF PREVIOUS DEC. PT.
EC9C- 50 C3    1580        BVC FIN.1    NO PREVIOUS DECIMAL POINT
               1590 *      A SECOND DECIMAL POINT IS TAKEN AS A TERMINATOR
               1600 *      TO THE NUMERIC STRING.
               1610 *      "A=11..22" WILL GIVE A SYNTAX ERROR, BECAUSE
               1620 *      IT IS TWO NUMBERS WITH NO OPERATOR BETWEEN.
               1630 *      "PRINT 11..22" GIVES NO ERROR, BECAUSE IT IS
               1640 *      JUST THE CONCATENATION OF TWO NUMBERS.
               1650 *--------------------------------
               1660 *      NUMBER TERMINATED, ADJUST EXPONENT NOW
               1670 *--------------------------------
EC9E- A5 9A    1680 FIN.7  LDA EXPON    E-VALUE
ECA0- 38       1690 FIN.8  SEC          MODIFY WITH COUNT OF DIGITS
ECA1- E5 99    1700        SBC TMPEXP        AFTER THE DECIMAL POINT
ECA3- 85 9A    1710        STA EXPON    COMPLETE CURRENT EXPONENT
ECA5- F0 12    1720        BEQ .15      NO ADJUST NEEDED IF EXP=0
ECA7- 10 09    1730        BPL .14      EXP>0, MULTIPLY BY TEN
ECA9- 20 55 EA 1740 .13    JSR DIV10    EXP<0, DIVIDE BY TEN
ECAC- E6 9A    1750        INC EXPON    UNTIL EXP=0
ECAE- D0 F9    1760        BNE .13
ECB0- F0 07    1770        BEQ .15      ...ALWAYS, WE ARE FINISHED
ECB2- 20 39 EA 1780 .14    JSR MUL10    EXP>0, MULTIPLY BKY TEN
ECB5- C6 9A    1790        DEC EXPON    UNTIL EXP=0
ECB7- D0 F9    1800        BNE .14
ECB9- A5 A3    1810 .15    LDA SERLEN   IS WHOLE NUMBER NEGATIVE?
ECBB- 30 01    1820        BMI .16      YES
ECBD- 60       1830        RTS          NO, RETURN, WHOLE JOB DONE!
ECBE- 4C D0 EE 1840 .16    JMP NEGOP    NEGATIVE NUMBER, SO NEGATE FAC
               1850 *--------------------------------
               1860 *      ACCUMULATE A DIGIT INTO FAC
               1870 *--------------------------------
ECC1- 48       1880 FIN.9  PHA          SAVE DIGIT
ECC2- 24 9B    1890        BIT DPFLG    SEEN A DECIMAL POINT YET?
ECC4- 10 02    1900        BPL .1       NO, STILL IN INTEGER PART
ECC6- E6 99    1910        INC TMPEXP   YES, COUNT THE FRACTIONAL DIGIT
ECC8- 20 39 EA 1920 .1     JSR MUL10    FAC = FAC * 10
ECCB- 68       1930        PLA          CURRENT DIGIT
ECCC- 38       1940        SEC          <<<SHORTER HERE TO JUST "AND #$0F">>>
ECCD- E9 30    1950        SBC #'0'     <<<TO CONVERT ASCII TO BINARY FORM>>>
ECCF- 20 D5 EC 1960        JSR ADDACC   ADD THE DIGIT
ECD2- 4C 61 EC 1970        JMP FIN.1    GO BACK FOR MORE
               1980 *--------------------------------
               1990 *      ADD (A) TO FAC
               2000 *--------------------------------
ECD5- 48       2010 ADDACC PHA          SAVE ADDEND
ECD6- 20 63 EB 2020        JSR COPY.FAC.TO.ARG.ROUNDED
ECD9- 68       2030        PLA          GET ADDEND AGAIN
ECDA- 20 93 EB 2040        JSR FLOAT    CONVERT TO FP VALUE IN FAC
ECDD- A5 AA    2050        LDA ARG.SIGN
ECDF- 45 A2    2060        EOR FAC.SIGN
ECE1- 85 AB    2070        STA SGNCPR
ECE3- A6 9D    2080        LDX FAC      TO SIGNAL IF FAC=0
ECE5- 4C C1 E7 2090        JMP FADDT    PERFORM THE ADDITION
               2100 *--------------------------------
               2110 *      ACCUMULATE DIGIT OF EXPONENT
               2120 *--------------------------------
ECE8- A5 9A    2130 GETEXP LDA EXPON    CHECK CURRENT VALUE
ECEA- C9 0A    2140        CMP #10      FOR MORE THAN 2 DIGITS
ECEC- 90 09    2150        BCC .1       NO, THIS IS 1ST OR 2ND DIGIT
ECEE- A9 64    2160        LDA #100     EXPONENT TOO BIG
ECF0- 24 9C    2170        BIT EXPSGN   UNLESS IT IS NEGATIVE
ECF2- 30 11    2180        BMI .2       LARGE NEGATIVE EXPONENT MAKES FAC=0
ECF4- 4C D5 E8 2190        JMP OVERFLOW LARGE POSITIVE EXPONENT IS ERROR
ECF7- 0A       2200 .1     ASL          EXPONENT TIMES 10
ECF8- 0A       2210        ASL
ECF9- 18       2220        CLC
ECFA- 65 9A    2230        ADC EXPON
ECFC- 0A       2240        ASL
ECFD- 18       2250        CLC          <<< ASL ALREADY DID THIS! >>>
ECFE- A0 00    2260        LDY #0       ADD THE NEW DIGIT
ED00- 71 B8    2270        ADC (TXTPTR),Y    BUT THIS IS IN ASCII,
ED02- 38       2280        SEC               SO ADJUST BACK TO BINARY
ED03- E9 30    2290        SBC #'0'
ED05- 85 9A    2300 .2     STA EXPON    NEW VALUE
ED07- 4C 87 EC 2310        JMP FIN.4    BACK FOR MORE
               2320 *--------------------------------