
 1000  *SAVE S.DP18 FIN
 1010  *--------------------------------
 1020  *   DP18 INPUT CONVERSION
 1030  *--------------------------------
 1040  FIN    LDA #0       CLEAR WORK AREA
 1050         LDX #WRKSZ-1      (DAC, SGNEXP, EXP,
 1060  .1     STA WORK,X         DGTCNT, & DECFLG)
 1070         DEX
 1080         BPL .1       LEAVE X=$FF WHEN FINISHED
 1090         LDA #$40
 1100         STA DAC.EXPONENT
 1110  *---HANDLE LEADING SIGN----------
 1120         JSR AS.CHRGOT
 1130         BCC .2       IF DIGIT 0-9
 1140         JSR FIN.SIGN ...SEE IF + OR - SIGN
 1150         BNE .4       ...NEITHER + NOR -
 1160         BCC .3       ...+
 1170         STX DAC.SIGN ...-, SET TO $FF
 1180         BCS .3       ...ALWAYS
 1190  *---GET DIGITS TILL NON-DIGIT----
 1200  .2     JSR ACCUMULATE.DIGIT
 1210  .3     JSR AS.CHRGET   GET NEXT CHARACTER
 1220         BCC .2       ...DIGIT
 1230  *---".", "E", OR END-------------
 1240  .4     CMP #'.      DECIMAL POINT?
 1250         BEQ .9       YES
 1260         CMP #'E      LETTER E
 1270         BNE .10      END OF NUMBER
 1280  *---HANDLE EXPONENT FIELD--------
 1290         JSR AS.CHRGET
 1300         BCC .6       ...DIGIT, ASSUME POSITIVE
 1310         JSR FIN.SIGN ...SEE IF + OR - SIGN
 1320         BNE .8       ...NEITHER + NOR -
 1330         BCC .5       ...+
 1340         ROR SGNEXP   ...-, SO SET SGNEXP NEGATIVE
 1350  .5     JSR AS.CHRGET   GET FIRST DIGIT OF EXP
 1360         BCS .8          ...NO DIGITS!
 1370  .6     AND #$0F        ...ISOLATE EXP 1ST DIGIT
 1380         STA EXP
 1390         JSR AS.CHRGET   GET 2ND DIGIT OF EXP, IF ANY
 1400         BCS .8          ...NO MORE DIGITS
 1410         AND #$0F        ISOLATE 2ND DIGIT
 1420         PHA             SAVE ON STACK
 1430         LDA EXP         MULTIPLY 1ST DIGIT BY 10
 1440         ASL
 1450         ASL         (CLEARS CARRY TOO)
 1460         ADC EXP      *5
 1470         ASL          *10  (CARRY STILL CLEAR)
 1480         STA EXP      ADD 2ND DIGIT
 1490         PLA
 1500         ADC EXP
 1510         STA EXP      2 DIGIT EXP
 1520         CMP #64+18   ALLOW .00000000000000001E+82
 1530         BCS .7       OR 999999999999999999E-82
 1540         JSR AS.CHRGET   GET NEXT CHAR
 1550         BCS .8       NO MORE DIGITS
 1560  .7     JMP AS.OVRFLW   OVERFLOW ERROR
 1570  .8     ASL SGNEXP   CHECK SIGN OF EXP
 1580         BCC .10      ...POSITIVE
 1590         LDA #0       ...NEGATIVE, SO COMPLEMENT EXP
 1600         SBC EXP
 1610         JMP .11      ...ALWAYS
 1620  *---FOUND DECIMAL POINT----------
 1630  .9     ROR DECFLG   SET DECIMAL POINT FLAG
 1640         BIT DECFLG   CHECK FOR TWO DECIMAL POINTS
 1650         BVC .3       NO
 1660  *---COMPUTE FINAL EXPONENT-------
 1670  .10    LDA EXP      GET EXPLICIT EXPONENT
 1680  .11    CLC
 1690         ADC DAC.EXPONENT
 1700         LDX DGTCNT   SEE IF ANY SIGNIFICANT DIGITS
 1710         BNE .12      ...YES
 1720         TXA          ...NO, MAKE EXPONENT ZERO
 1730  .12    STA DAC.EXPONENT
 1740         TAX          TEST RANGE OF EXPONENT
 1750         BMI .13      ...NOT IN RANGE 0...7F
 1760         RTS
 1770  *---EITHER UNDER- OR OVER-FLOW---
 1780  .13    ASL          UNDER, OR OVER?
 1790         BCC .7       ...OVERFLOW
 1800         LDA #0
 1810         STA DAC.SIGN
 1820         BEQ .12      ...ALWAYS
 1830  *--------------------------------
 1840  ACCUMULATE.DIGIT
 1850         AND #$0F     ISOLATE DIGIT
 1860         BEQ .4       ZERO DIGIT
 1870         TAX          SAVE DIGIT IN X-REG
 1880         LDA DGTCNT   NO MORE THAN 20 SIGNIFICANT DIGITS
 1890         CMP #20
 1900         BCS .2       DISCARD EXTRA DIGITS
 1910  *---STORE THE DIGIT IN DAC-------
 1920         LSR          ODD/EVEN TO CARRY
 1930         TAY          INDEX TO Y-REG
 1940         TXA          GET DIGIT FROM X-REG
 1950         BCS .1       ODD DIGIT ON RIGHT SIDE
 1960         ASL          EVEN DIGIT MUST BE SHIFTED
 1970         ASL
 1980         ASL
 1990         ASL
 2000  .1     ORA DAC.HI,Y MERGE
 2010         STA DAC.HI,Y
 2020  *---COUNT THE DIGIT--------------
 2030  .2     INC DGTCNT   COUNT SIGNIFICANT DIGIT
 2040         LDA DECFLG   SEE IF IN FRACTION
 2050         BMI .3       YES
 2060         INC DAC.EXPONENT  NO
 2070  .3     RTS
 2080  *---DIGIT = 0--------------------
 2090  .4     LDA DGTCNT   SEE IF LEADING ZERO
 2100         BNE .2       NO
 2110         LDA DECFLG   SEE IF PART OF FRACTION
 2120         BPL .5       NO, COMPLETELY IGNORE IT
 2130         DEC DAC.EXPONENT
 2140  .5     RTS
 2150  *--------------------------------
 2160  *   SCAN + OR - SIGN
 2170  *   -------------------
 2180  *      +     .EQ., .CC.
 2190  *      -     .EQ., .CS.
 2200  *    OTHER   .NE.
 2210  *--------------------------------
 2220  FIN.SIGN
 2230         CMP #'-'
 2240         BEQ .2
 2250         CMP #TKN.MINUS
 2260         BEQ .2
 2270         CMP #'+'
 2280         BEQ .1
 2290         CMP #TKN.PLUS
 2300  .1     CLC
 2310  .2     RTS

