S-C DocuMentor — Applesoft

               SAVE S.ED0A
               1010 *--------------------------------
ED0A- 9B 3E BC
ED0D- 1F FD    1020 CON.99999999.9 .HS 9B3EBC1FFD  99,999,999.9
ED0F- 9E 6E 6B
ED12- 27 FD    1030 CON.999999999  .HS 9E6E6B27FD  999,999,999
ED14- 9E 6E 6B
ED17- 28 00    1040 CON.BILLION    .HS 9E6E6B2800  1,000,000,000
               1050 *--------------------------------
               1060 *      PRINT "IN <LINE #>"
               1070 *--------------------------------
ED19- A9 58    1080 INPRT  LDA #QT.IN    PRINT " IN "
ED1B- A0 D3    1090        LDY /QT.IN
ED1D- 20 31 ED 1100        JSR GO.STROUT
ED20- A5 76    1110        LDA CURLIN+1
ED22- A6 75    1120        LDX CURLIN
               1130 *--------------------------------
               1140 *      PRINT A,X AS DECIMAL INTEGER
               1150 *--------------------------------
ED24- 85 9E    1160 LINPRT STA FAC+1    PRINT A,X IN DECIMAL
ED26- 86 9F    1170        STX FAC+2
ED28- A2 90    1180        LDX #$90     EXPONENT = 2^16
ED2A- 38       1190        SEC          CONVERT UNSIGNED
ED2B- 20 A0 EB 1200        JSR FLOAT.2  CONVERT LINE # TO FP 
               1210 *--------------------------------
               1220 *      CONVERT (FAC) TO STRING, AND PRINT IT
               1230 *--------------------------------
               1240 PRINT.FAC
ED2E- 20 34 ED 1250        JSR FOUT     CONVERT (FAC) TO STRING AT STACK
               1260 *--------------------------------
               1270 *      PRINT STRING STARTING AT Y,A
               1280 *--------------------------------
               1290 GO.STROUT
ED31- 4C 3A DB 1300        JMP STROUT    PRINT STRING AT A,Y
               1310 *--------------------------------
               1320 *      CONVERT (FAC) TO STRING STARTING AT STACK
               1330 *      RETURN WITH (Y,A) POINTING AT STRING
               1340 *--------------------------------
ED34- A0 01    1350 FOUT   LDY #1       NORMAL ENTRY PUTS STRING AT STACK...
               1360 *--------------------------------
               1370 *      "STR$" FUNCTION ENTERS HERE, WITH (Y)=0
               1380 *      SO THAT RESULT STRING STARTS AT STACK-1
               1390 *      (THIS IS USED AS A FLAG)
               1400 *--------------------------------
ED36- A9 2D    1410 FOUT.1 LDA #'-'     IN CASE VALUE NEGATIVE
ED38- 88       1420        DEY          BACK UP PNTR
ED39- 24 A2    1430        BIT FAC.SIGN
ED3B- 10 04    1440        BPL .1       VALUE IS +
ED3D- C8       1450        INY          VALUE IS -
ED3E- 99 FF 00 1460        STA STACK-1,Y     EMIT "-"
ED41- 85 A2    1470 .1     STA FAC.SIGN MAKE FAC.SIGN POSITIVE ($2D)
ED43- 84 AD    1480        STY STRNG2   SAVE STRING PNTR
ED45- C8       1490        INY
ED46- A9 30    1500        LDA #'0'     IN CASE (FAC)=0
ED48- A6 9D    1510        LDX FAC      NUMBER=0?
ED4A- D0 03    1520        BNE .2       NO, (FAC) NOT ZERO
ED4C- 4C 57 EE 1530        JMP FOUT.4   YES, FINISHED
               1540 *--------------------------------
ED4F- A9 00    1550 .2     LDA #0       STARTING VALUE FOR TMPEXP
ED51- E0 80    1560        CPX #$80     ANY INTEGER PART?
ED53- F0 02    1570        BEQ .3       NO, BTWN .5 AND .999999999
ED55- B0 09    1580        BCS .4       YES
               1590 *--------------------------------
ED57- A9 14    1600 .3     LDA #CON.BILLION  MULTIPLY BY 1E9
ED59- A0 ED    1610        LDY /CON.BILLION  TO GIVE ADJUSTMENT A HEAD START
ED5B- 20 7F E9 1620        JSR FMULT
ED5E- A9 F7    1630        LDA #-9           EXPONENT ADJUSTMENT
ED60- 85 99    1640 .4     STA TMPEXP        0 OR -9
               1650 *--------------------------------
               1660 *      ADJUST UNTIL 1E8 <= (FAC) <1E9
               1670 *--------------------------------
ED62- A9 0F    1680 .5     LDA #CON.999999999
ED64- A0 ED    1690        LDY /CON.999999999
ED66- 20 B2 EB 1700        JSR FCOMP    COMPARE TO 1E9-1
ED69- F0 1E    1710        BEQ .10      (FAC) = 1E9-1
ED6B- 10 12    1720        BPL .8       TOO LARGE, DIVIDE BY TEN
ED6D- A9 0A    1730 .6     LDA #CON.99999999.9   COMPARE TO 1E8-.1
ED6F- A0 ED    1740        LDY /CON.99999999.9
ED71- 20 B2 EB 1750        JSR FCOMP    COMPARE TO 1E8-.1
ED74- F0 02    1760        BEQ .7       (FAC) = 1E8-.1
ED76- 10 0E    1770        BPL .9       IN RANGE, ADJUSTMENT FINISHED
ED78- 20 39 EA 1780 .7     JSR MUL10    TOO SMALL, MULTIPLY BY TEN
ED7B- C6 99    1790        DEC TMPEXP   KEEP TRACK OF MULTIPLIES
ED7D- D0 EE    1800        BNE .6       ...ALWAYS
ED7F- 20 55 EA 1810 .8     JSR DIV10    TOO LARGE, DIVIDE BY TEN
ED82- E6 99    1820        INC TMPEXP   KEEP TRACK OF DIVISIONS
ED84- D0 DC    1830        BNE .5       ...ALWAYS
               1840 *--------------------------------
ED86- 20 A0 E7 1850 .9     JSR FADDH    ROUND ADJUSTED RESULT
ED89- 20 F2 EB 1860 .10    JSR QINT   CONVERT ADJUSTED VALUE TO 32-BIT INTEGER
               1870 *--------------------------------
               1880 *      FAC+1...FAC+4 IS NOW IN INTEGER FORM
               1890 *      WITH POWER OF TEN ADJUSTMENT IN TMPEXP
               1900 *
               1910 *      IF -10 < TMPEXP > 1, PRINT IN DECIMAL FORM
               1920 *      OTHERWISE, PRINT IN EXPONENTIAL FORM
               1930 *--------------------------------
ED8C- A2 01    1940 FOUT.2 LDX #1       ASSUME 1 DIGIT BEFORE "."
ED8E- A5 99    1950        LDA TMPEXP   CHECK RANGE
ED90- 18       1960        CLC
ED91- 69 0A    1970        ADC #10
ED93- 30 09    1980        BMI .1       < .01, USE EXPONENTIAL FORM
ED95- C9 0B    1990        CMP #11
ED97- B0 06    2000        BCS .2       >= 1E10, USE EXPONENTIAL FORM
ED99- 69 FF    2010        ADC #$FF     LESS 1 GIVES INDEX FOR "."
ED9B- AA       2020        TAX
ED9C- A9 02    2030        LDA #2       SET REMAINING EXPONENT = 0
ED9E- 38       2040 .1     SEC          COMPUTE REMAINING EXPONENT
ED9F- E9 02    2050 .2     SBC #2
EDA1- 85 9A    2060        STA EXPON    VALUE FOR "E+XX" OR "E-XX"
EDA3- 86 99    2070        STX TMPEXP   INDEX FOR DECIMAL POINT
EDA5- 8A       2080        TXA          SEE IF "." COMES FIRST
EDA6- F0 02    2090        BEQ .3       YES
EDA8- 10 13    2100        BPL .5       NO, LATER
EDAA- A4 AD    2110 .3     LDY STRNG2   GET INDEX INTO STRING BEING BUILT
EDAC- A9 2E    2120        LDA #'.'     STORE A DECIMAL POINT
EDAE- C8       2130        INY
EDAF- 99 FF 00 2140        STA STACK-1,Y
EDB2- 8A       2150        TXA          SEE IF NEED ".0"
EDB3- F0 06    2160        BEQ .4       NO
EDB5- A9 30    2170        LDA #'0'     YES, STORE "0"
EDB7- C8       2180        INY
EDB8- 99 FF 00 2190        STA STACK-1,Y
EDBB- 84 AD    2200 .4     STY STRNG2   SAVE OUTPUT INDEX AGAIN
               2210 *--------------------------------
               2220 *     NOW DIVIDE BY POWERS OF TEN TO GET SUCCESSIVE DIGITS
               2230 *--------------------------------
EDBD- A0 00    2240 .5     LDY #0       INDEX TO TABLE OF POWERS OF TEN
EDBF- A2 80    2250        LDX #$80    STARTING VALUE FOR DIGIT WITH DIRECTION
EDC1- A5 A1    2260 .6     LDA FAC+4    START BY ADDING -100000000 UNTIL
EDC3- 18       2270        CLC          OVERSHOOT.  THEN ADD +10000000,
EDC4- 79 6C EE 2280        ADC DECTBL+3,Y    THEN ADD -1000000, THEN ADD
EDC7- 85 A1    2290        STA FAC+4         +100000, AND SO ON.
EDC9- A5 A0    2300        LDA FAC+3    THE # OF TIMES EACH POWER IS ADDED
EDCB- 79 6B EE 2310        ADC DECTBL+2,Y   IS 1 MORE THAN CORRESPONDING DIGIT
EDCE- 85 A0    2320        STA FAC+3
EDD0- A5 9F    2330        LDA FAC+2
EDD2- 79 6A EE 2340        ADC DECTBL+1,Y
EDD5- 85 9F    2350        STA FAC+2
EDD7- A5 9E    2360        LDA FAC+1
EDD9- 79 69 EE 2370        ADC DECTBL,Y
EDDC- 85 9E    2380        STA FAC+1
EDDE- E8       2390        INX          COUNT THE ADD
EDDF- B0 04    2400        BCS .7       IF C=1 AND X NEGATIVE, KEEP ADDING
EDE1- 10 DE    2410        BPL .6       IF C=0 AND X POSITIVE, KEEP ADDING
EDE3- 30 02    2420        BMI .8       IF C=0 AND X NEGATIVE, WE OVERSHOT
EDE5- 30 DA    2430 .7     BMI .6       IF C=1 AND X POSITIVE, WE OVERSHOT
EDE7- 8A       2440 .8     TXA          OVERSHOT, SO MAKE X INTO A DIGIT
EDE8- 90 04    2450        BCC .9       HOW DEPENDS ON DIRECTION WE WERE GOING
EDEA- 49 FF    2460        EOR #$FF     DIGIT = 9-X
EDEC- 69 0A    2470        ADC #10
EDEE- 69 2F    2480 .9     ADC #'0'-1   MAKE DIGIT INTO ASCII
EDF0- C8       2490        INY          ADVANCE TO NEXT SMALLER POWER OF TEN
EDF1- C8       2500        INY
EDF2- C8       2510        INY
EDF3- C8       2520        INY
EDF4- 84 83    2530        STY VARPNT   SAVE PNTR TO POWERS
EDF6- A4 AD    2540        LDY STRNG2   GET OUTPUT PNTR
EDF8- C8       2550        INY          STORE THE DIGIT
EDF9- AA       2560        TAX          SAVE DIGIT, HI-BIT IS DIRECTION
EDFA- 29 7F    2570        AND #$7F     MAKE SURE $30...$39 FOR STRING
EDFC- 99 FF 00 2580        STA STACK-1,Y
EDFF- C6 99    2590        DEC TMPEXP   COUNT THE DIGIT
EE01- D0 06    2600        BNE .10      NOT TIME FOR "." YET
EE03- A9 2E    2610        LDA #'.'     TIME, SO STORE THE DECIMAL POINT
EE05- C8       2620        INY
EE06- 99 FF 00 2630        STA STACK-1,Y
EE09- 84 AD    2640 .10    STY STRNG2   SAVE OUTPUT PNTR AGAIN
EE0B- A4 83    2650        LDY VARPNT   GET PNTR TO POWERS
EE0D- 8A       2660        TXA          GET DIGIT WITH HI-BIT = DIRECTION
EE0E- 49 FF    2670        EOR #$FF     CHANGE DIRECTION
EE10- 29 80    2680        AND #$80     $00 IF ADDING, $80 IF SUBTRACTING
EE12- AA       2690        TAX
EE13- C0 24    2700        CPY #DECTBL.END-DECTBL
EE15- D0 AA    2710        BNE .6       NOT FINISHED YET
               2720 *--------------------------------
               2730 *      NINE DIGITS HAVE BEEN STORED IN STRING.  NOW LOOK
               2740 *      BACK AND LOP OFF TRAILING ZEROES AND A TRAILING
               2750 *      DECIMAL POINT.
               2760 *--------------------------------
EE17- A4 AD    2770 FOUT.3 LDY STRNG2   POINTS AT LAST STORED CHAR
EE19- B9 FF 00 2780 .1     LDA STACK-1,Y     SEE IF LOPPABLE
EE1C- 88       2790        DEY
EE1D- C9 30    2800        CMP #'0'     SUPPRESS TRAILING ZEROES
EE1F- F0 F8    2810        BEQ .1       YES, KEEP LOOPING
EE21- C9 2E    2820        CMP #'.'     SUPPRESS TRAILING DECIMAL POINT
EE23- F0 01    2830        BEQ .2       ".", SO WRITE OVER IT
EE25- C8       2840        INY          NOT ".", SO INCLUDE IN STRING AGAIN
EE26- A9 2B    2850 .2     LDA #'+'     PREPARE FOR POSITIVE EXPONENT "E+XX"
EE28- A6 9A    2860        LDX EXPON    SEE IF ANY E-VALUE
EE2A- F0 2E    2870        BEQ FOUT.5   NO, JUST MARK END OF STRING
EE2C- 10 08    2880        BPL .3       YES, AND IT IS POSITIVE
EE2E- A9 00    2890        LDA #0       YES, AND IT IS NEGATIVE
EE30- 38       2900        SEC          COMPLEMENT THE VALUE
EE31- E5 9A    2910        SBC EXPON
EE33- AA       2920        TAX          GET MAGNITUDE IN X
EE34- A9 2D    2930        LDA #'-'     E SIGN
EE36- 99 01 01 2940 .3     STA STACK+1,Y     STORE SIGN IN STRING
EE39- A9 45    2950        LDA #'E'          STORE "E" IN STRING BEFORE SIGN
EE3B- 99 00 01 2960        STA STACK,Y
EE3E- 8A       2970        TXA          EXPONENT MAGNITUDE IN A-REG
EE3F- A2 2F    2980        LDX #'0'-1   SEED FOR EXPONENT DIGIT
EE41- 38       2990        SEC          CONVERT TO DECIMAL
EE42- E8       3000 .4     INX          COUNT THE SUBTRACTION
EE43- E9 0A    3010        SBC #10      TEN'S DIGIT
EE45- B0 FB    3020        BCS .4       MORE TENS TO SUBTRACT
EE47- 69 3A    3030        ADC #'0'+10  CONVERT REMAINDER TO ONE'S DIGIT
EE49- 99 03 01 3040        STA STACK+3,Y     STORE ONE'S DIGIT
EE4C- 8A       3050        TXA
EE4D- 99 02 01 3060        STA STACK+2,Y     STORE TEN'S DIGIT
EE50- A9 00    3070        LDA #0       MARK END OF STRING WITH $00
EE52- 99 04 01 3080        STA STACK+4,Y
EE55- F0 08    3090        BEQ FOUT.6   ...ALWAYS
EE57- 99 FF 00 3100 FOUT.4 STA STACK-1,Y     STORE "0" IN ASCII
EE5A- A9 00    3110 FOUT.5 LDA #0       STORE $00 ON END OF STRING
EE5C- 99 00 01 3120        STA STACK,Y
EE5F- A9 00    3130 FOUT.6 LDA #STACK   POINT Y,A AT BEGINNING OF STRING
EE61- A0 01    3140        LDY /STACK   (STR$ STARTED STRING AT STACK-1, BUT
EE63- 60       3150        RTS          STR$ DOESN'T USE Y,A ANYWAY.)
               3160 *--------------------------------
EE64- 80 00 00
EE67- 00 00    3170 CON.HALF   .HS 8000000000  FP CONSTANT 0.5
               3180 *--------------------------------
               3190 *      POWERS OF 10 FROM 1E8 DOWN TO 1,
               3200 *      AS 32-BIT INTEGERS, WITH ALTERNATING SIGNS
               3210 *--------------------------------
EE69- FA 0A 1F
EE6C- 00       3220 DECTBL .HS FA0A1F00  -100000000
EE6D- 00 98 96
EE70- 80       3230        .HS 00989680  10000000
EE71- FF F0 BD
EE74- C0       3240        .HS FFF0BDC0  -1000000
EE75- 00 01 86
EE78- A0       3250        .HS 000186A0  100000
EE79- FF FF D8
EE7C- F0       3260        .HS FFFFD8F0  -10000
EE7D- 00 00 03
EE80- E8       3270        .HS 000003E8  1000
EE81- FF FF FF
EE84- 9C       3280        .HS FFFFFF9C  -100
EE85- 00 00 00
EE88- 0A       3290        .HS 0000000A  10
EE89- FF FF FF
EE8C- FF       3300        .HS FFFFFFFF  -1
               3310 DECTBL.END
               3320 *--------------------------------