
FMT40 ISZ REPCT     REPCT = O ? 
      JMP FMT37+4   NO
      CCA           YES,REINITIALIZE
      STA REPCT       REPCT 
      JMP FMT59 
FMT57 LDB DPFLG     FIXED POINT 
      SZB             SPECIFICATION ? 
      JMP FMT42     NO
      CPA .+56B     TOP OF STACK A DECIMAL POINT ?
      RSS           YES 
      JMP FMT42     NO
      ISZ FSP       INCREMENT STACK POINTER 
      LDB SNFLG 
      SSB           SNFLG = -1 ?
      JMP FM00      YES 
      ADB .-1       NO, = 1 ? 
      SZB 
      JMP FM01      NO
FM00  LDA SIGN      YES, OUTPUT 
      JSB OUTCR       SIGN
      LDA .+2       SET SNFLG 
      STA SNFLG       TO 2
FM01  LDA .+56B     OUTPUT
      JSB OUTCR       DECIMAL POINT 
      ISZ DPFLG     INCREMENT FLAG TO SHOW D.P. FOUND 
FMT59 LDA FSP       END OF
      CPA EST         STACK 
      JMP FMT90     YES 
      JMP FMT34     NO
FMT42 ISZ FSP       INCREMENT STACK POINTER 
      JSB OUTCR     OUTPUT AN E 
FMT76 LDA FSP       END OF
      CPA EST         STACK ? 
      JMP FMT78     YES 
      LDA FSP,I     NO,TOP OF 
      SSA,RSS         STACK A NUMBER ?
      JMP FM02      NO
      ISZ FSP       YES, INCREMENT STACK POINTER
      STA REPCT     STORE NUMBER
      LDA FSP,I     GET NEW TOP OF STACK
FM02  CPA .X        IS IT AN X ?
      RSS           YES 
      JSB FERRS+7,I NO, ERROR 
      JSB OUTBL 
      CCA           RESET 
      STA REPCT       REPCT 
      JMP FMT76 
FMT78 LDA .+55B     OUTPUT
      LDB EXPON 
      SSB             AN
      CMB,INB,RSS 
      LDA .+53B         EXPONENT
      STB EXPON 
      JSB OUTCR           SIGN
      LDA EXPON 
      CLB           COMPUTE 
      DIV .+12B 
      ADA .+60B       EXPONENT'S
      ADB .+60B 
      STB EXPON         10'S DIGIT
      JSB OUTCR     OUTPUT IT 
      LDA EXPON 
      JSB OUTCR     OUTPUT 1'S DIGIT
      JMP FMT90 
**                                **
***  PREPARE FIXED POINT NUMBER  ***
**                                **
FMT45 CLA           SET PRE-DECIMAL POINT 
      STA EXPON       DIGIT COUNTER 
      STA NAD         ZERO COUNTER
      CPA EXP       ZERO EXPONENT ? 
      JMP FMT61+3   YES 
      LDB EXP       NO
      SSB           EXPONENT NEGATIVE 
      JMP FMT61     YES 
      JSB DTL1
      STA EXPON     LOAD
      STA NBD         PRE-DECIMAL POINT 
FM03  JSB GETDG         DIGITS
      ADA .+60B 
      STA HBP,I           INTO
      ISZ HBP               HOLD
      ISZ EXPON               BUFFER
      JMP FM03
FMT50 LDB NUM2      ANY D'S AFTER 
      SZB,RSS         DECIMAL POINT ? 
      JMP FMT51     NO
      LDA IHB       END 
      ADA .+46        OF
      CPA HBP           BUFFER ?
      JMP FM04      YES 
      LDB NAD       LEADING 
      CLA             ZEROES
      SZB,RSS           AFTER 
      JMP *+4             DECIMAL 
      ADB .-1               POINT 
      STB NAD 
      RSS           YES 
      JSB GETDG 
      ADA .+60B     LOAD
      STA HBP,I       POST-DECIMAL POINT
      CCB             DIGITS
      ADB NUM2            INTO
      STB NUM2              HOLD
      ISZ HBP                 BUFFER
      JMP FMT50+1 
FM04  LDA NUM2      OUTPUT BLANKS 
      CMA,INA         TO
      STA REPCT         FILL FIELD
      JSB OUTBL 
      CCA           REINITIALIZE
      STA REPCT       REPCT 
      ADA FSP       CORRECT 
      STA FSP         STACK POINTER 
FMT51 LDA NBD       COMPUT NUMBER 
      ADA NUM1        OF LEADING BLANKS 
      LDB SBD       ANY S'S 
      ADB SAD         FOUND ? 
      SZB 
      JMP FMT54     YES 
      LDB SIGN      NO, NUMBER
      CPB .+53B       POSITIVE ?
      JMP FMT54     YES 
      ADA .-1       NO, LEAVE ROOM FOR
      CLB,INB         SIGN TO BE PRINTED AND
      STB SNFLG         SET SNFLG TO 1
FMT54 SSA           NUMBER OF BLANKS NEGATIVE ? 
      JMP FMT80     YES 
      STA NBLK      NO, 
      CCB           NEXT DIGIT A
      ADB NAD         LEADING ZERO ?
      SSB 
      JSB ROUND     NO, ROUND NUMBER
      RSS 
      JMP FMT80     NO ROOM FOR CARRY FROM ROUND
      LDA IHB       RESET HOLD
      STA HBP         BUFFER POINTER
      JMP FMT34     GO OUTPUT THE NUMBER
FMT61 JSB MTG1
      LDA EXPON 
      STA NAD 
      LDB NUM1      ANY D'S FOUND 
      SZB,RSS         BEFORE THE DECIMAL POINT ?
      JMP FMT50     NO
      LDA NUM2      YES, ANY D'S FOUND
      SZA,RSS         AFTER THE DECIMAL POINT ? 
      JMP FMT55     NO
      CPB .+1       YES, ONLY ONE OF THEM ? 
      RSS 
      JMP FMT55     NO
      LDA SAD       YES, ANY S'S FOUND ?
      ADA SBD 
      SZA 
      JMP FMT55     YES 
      LDA SIGN      NO, NUMBER
      CPA .+55B       NEGATIVE ?
      JMP FMT50     YES 
FMT55 LDA .+60B     NO, LOAD PRE-DECIMAL POINT
      STA HBP,I       ZERO INTO BUFFER
      ISZ HBP 
      CCA           DECREASE NUMBER OF
      ADA NUM1        D'S AVAILABLE FOR SIGN
      STA NUM1          AND BLANKS BEFORE DECIMAL PT. 
      JMP FMT50 
**                                   ** 
***  PREPARE FLOATING POINT NUMBER  *** 
**                                   ** 
FMT62 CLA           INITIALIZE DECIMAL
      STA EXPON       EXPONENT
      CPA EXP       ZERO EXPONENT ? 
      JMP *+3       YES 
      JSB MTG1
      JSB DTL1
      CMA,INA       SAVE DECIMAL EXPONENT 
      STA EXPON 
      LDA NUM1      GET 
      ADA NUM2        TOTAL NUMBER
      STA TOTDG         OF DIGITS 
      LDA SBD 
      ADA SAD       ANY S'S FOUND ? 
      SZA 
      JMP FMT67     YES 
      LDA SIGN      NO, NUMBER
      CPA .+53B       POSITIVE ?
      JMP FMT67     YES 
      CCB           NO, LEAVE ROOM
      ADB NUM1        FOR SIGN
      SSB           NONE ?
      JMP FMT80     YES 
      STB NUM1      NO, DECREMENT 
      CCA             TOTAL NUMBER OF D'S 
      ADA TOTDG         AVAILABLE FOR SIGN
      STA TOTDG           AND BLANKS BEFORE DEC. PT.
      SZA,RSS 
      JMP FMT80 
      CLB,INB       SET SNFLG 
      STB SNFLG       TO 1
FMT67 LDA NUM2      NUM2
      CMA,INA         > 7 ? 
      LDB .+6 
      ADB 0 
      SSB 
      JMP FMT70     YES 
      LDA TOTDG     YES, TOTAL NUMBER OF D'S
      ADA .-10B       > 7 ? 
      SSA 
      JMP FMT68     NO
      LDB .-7       PREPARE TO GET
      STB DCTR        SEVEN DIGITS
      INA           NUMBER OF BLANKS
      STA NBLK        BECOMES TOTDG - 7 
      JMP FMT72 
FMT68 LDA TOTDG     PREPARE TO GET
      CMA,INA 
      STA DCTR        TOTDG DIGITS
      CLB           SET NUMBER OF BLANKS
      STB NBLK        TO ZERO 
      JMP FMT72 
FMT70 LDB NUM1      ANY D'S BEFORE
      SZB             DECIMAL POINT ? 
      ADA .-1       YES, INCREMENT NUMBER OF DIGITS 
      STA DCTR      PREPARE TO GET NUM2 DIGITS
      SZB           SET 
      ADB .-1         BLANK 
      STB NBLK          COUNT 
      LDA DCTR      MORE THAN 
      ADA .+46        FOURTY-SIX
      SSA,RSS           DIGITS NEEDED ? 
      JMP FMT72     NO
      STA REPCT     YES, OUTPUT NECESSARY BLANKS
      JSB OUTBL 
      ADA FSP       CORRECT 
      STA FSP         STACK POINTER 
      LDA M46       SET DCTR
      STA DCTR        TO 46 
FMT72 EQU * 
      CCA           REINITIALIZE
      STA REPCT       REPCT 
      JSB GETDG 
      ADA .+60B     CONVERT TO ASCII
      STA HBP,I     STORE IN HOLD BUFFER
      ISZ HBP       INCREMENT BUFFER POINTER
      ISZ DCTR      ALL DIGITS GOT ?
      JMP FMT72     NO
      JSB ROUND     YES, ROUND THE NUMBER IN BUFFER 
      RSS 
      JMP FMT80     NO ROOM FOR CARRY FROM ROUND
      LDA IHB       RESET 
      STA HBP         BUFFER POINTER
      JMP FMT34 
**                                 ** 
***  HANDLE END OF SPECIFICATION  *** 
**                                 ** 
FMT90 CLA 
      STA SFLG        STRING FLAG 
      LDA CC        ENF OF
      CPA NCH         FORMAT STRING ? 
      RSS           YES 
      JMP FMT92     NO
FMT09 LDA CC1       YES, PARENTHESIS
      SZA             BALANCED ?
      JSB FERRS+10,I NO, ERROR
FMT91 LDB EC        ANY EXPRESSIONS 
      SZB,RSS         USED ?
      JMP FMEND     NO
      LDB EDSTA     END OF
      SZB,RSS         STATEMENT ? 
      JMP FMEND     YES 
      CLA 
      STA EC        YES, CLEAR EC 
      STA CC
      LDA IFSTR     RESET 
      STA DP          DELIMITER POINTER 
      JMP FMT2
FMT92 LDA DP        GET THE 
      CLO             DELIMITING CHARACTER
      JSB MCHAR         NOT IGNORING BLANKS 
      CPA .+51B     IS IT A RIGHT PARENTHESIS 
      JMP FMT97     YES 
      STA LCH       NO, SAVE THE CHARACTER
      CPA .+54B     IS IT A COMMA ? 
      JMP FMT93+1   YES 
      CPA .+57B     IS IT A SLASH ? 
      RSS           YES 
      JSB FERRS+1,I NO, ERROR EXIT
FMT93 JSB OUTCL 
      ISZ CC        INCREMENT CHARACTER COUNTER 
      LDA CC        ALL CHARACTERS
      CPA NCH         USED ?
      JMP FMT94     YES 
      ISZ DP        INCREMENT DELIMITER POINTER 
      JSB DSRCH     FIND NEXT DELIMITER 
      STO           IGNORE BLANKS 
      LDA FST 
      JSB MCHAR       NEXT CHARACTER
      CPA DP        IS IT A DELIMITER 
      RSS           YES 
      JMP FM11      NO
      LDA CC        ALL CHARACTERS
      CPA NCH         USED ?
      JMP FMT94     YES 
      LDA DP        NO, GET DELIMITING
      CLO             CHARACTER 
      JSB MCHAR         IGNORING BLANKS 
FM11  CPA .+54      IS IT A COMMA 
      JSB FERRS,I   YES, ERROR
      CPA .+57B     NO, A SLASH 
      JMP FMT94     YES 
      CPA .+51B     NO, A RIGHT PARENTHESIS ? 
      JMP FMT97     YES 
      JMP FMT3
FMT94 LDA LCH       LAST CHARACTER
      CPA .+54B       A COMMA ? 
      JSB FERRS,I 
      LDA CC        NO, ALL CHARACTERS
      CPA NCH         USED ?
      JMP FMT09     YES 
      JMP FMT93     NO
**                                     ** 
***  HANDLE GROUPS OF SPECIFICATIONS  *** 
**                                     ** 
FMT95 CCA           SECOND
      ADA FSP         CHARACTER 
      CPA IFSS          IN STACK ?
      RSS 
      JSB FERRS+11,I NO, ERROR
      LDA CC1       YES, FIRST LEVEL
      SZA             OF PARENTHESIS ?
      JMP FMT96     NO
      ISZ FST       INCREMENT STRING POINTER
      CCA           FIND CHARACTER COUNT
      ADA IFSTR           UP TO AND INCLUDING 
      CMA                     LEFT
      ADA FST                   PARENTHESIS 
      STA CC1 
      LDB REPCT     STORE REPETITION
      STB PC1         COUNT 
      JMP FMT3      PROCESS STRING
FMT96 LDA CC2       SECOND LEVEL
      SZA             OF PARENTHESIS
      JSB FERRS+12,I NO, ERROR
      ISZ FST 
      CCA           FIND CHARACTER COUNT
      ADA IFSTR           UP TO AND 
      CMA                     INCLUDING 
      ADA FST                   LEFT
      STA CC2                     PARENTHESIS 
      LDB REPCT     STORE REPETITION
      STB PC2             COUNT 
      JMP FMT3
FMT97 LDA PC2       SECOND LEVEL OF 
      SZA,RSS         PARENTHESIS ? 
      JMP FMT98     NO
      ADA .-1       YES, REPEAT IT
      STA PC2 
      SZA,RSS 
      JMP FMT99 
      LDB CC2       RESET 
      STB CC          CHARACTER COUNTER 
      ADB IFSTR 
      STB DP          AND STRING POINTER
      JSB DSRCH 
      JMP FMT3      REPROCESS PARENTHESIZED STRING
FMT99 CLA           CLEAR SECOND
      STA CC2         LEVEL POINTER 
      STA SFLG        AND STRING FLAG 
      ISZ CC        INCREMENT CHARACTER COUNTER 
      LDA CC        ALL CHARACTERS
      CPA NCH         USED ?
      JSB FERRS+1,I YES, ERROR
      ISZ DP        NO, POINT TO DELIMITER
      JSB DSRCH     FIND NEXT DELIMITER 
      STO           GET NEXT
      LDA FST         NON-BLANK 
      JSB MCHAR         CHARACTER 
      CPA DP        IS IT A DELIMITER ? 
      RSS           YES 
      JMP FMT92+3   MAYBE 
      LDB CC        ALL 
      CPB NCH         CHARACTERS USED ? 
      JSB FERRS+10,I  YES, ERROR
      JMP FMT92     NO, INVESTIGATE THE CHARACTER 
FMT98 LDA PC1       FIRST LEVEL 
      SZA,RSS         OF PARENTHESIS ?
      JSB FERRS+13,I NO, ERROR
      ADA .-1       YES, REPEAT IT
      STA PC1 
      SZA,RSS 
      JMP FMT00 
      LDB CC1       RESET 
      STB CC          CHARACTER COUNTER 
      ADB IFSTR 
      STB DP
      JSB DSRCH 
      JMP FMT3      REPROCESS PARENTHESIZED STRING
FMT00 CLA           CLEAR FIRST 
      STA CC1         LEVEL POINTER 
      STA SFLG        AND STRING FLAG 
      ISZ CC        INCREMENT CHARACTER COUNTER 
      ISZ DP        POINT TO DELIMITER
      LDA CC        ALL 
      CPA NCH         CHARACTERS USED ? 
      JMP FMT91     YES 
      JSB DSRCH     NO, FIND NEXT DELIMITER 
      STO           GET NEXT
      LDA FST         NON-BLANK 
      JSB MCHAR         CHARACTER 
      CPA DP        IS IT A DELIMITER ? 
      RSS           YES 
      JMP FMT92+3   NO
      LDB CC        ALL 
      CPB NCH         CHARACTERS USED ? 
      JMP FMT91     YES 
      JMP FMT92     NO, INVESTIGATE THE FOUND CHARACTER 
**                                     ** 
***  OUTPUT NUMBER IN DEFAULT FORMAT  *** 
**                                     ** 
FMT80 LDA NUMW1 
      STA MANT1     LOAD
      LDB NUMW2 
      STB MANT2       SAVED 
      LDA EXPW
      STA EXP           NUMBER
      CLA           CLEAR 
      STA EXPON       DECIMAL EXPONENT
      STA EFLAG     SET FLOATING POINT FLAG 
      CPA EXP       ZERO EXPONENT ? 
      JMP *+3       YES 
      JSB MTG1
      JSB DTL1
      CMA 
      STA EXPON 
      JSB OUTCL 
      LDA IHB       RESET HOLD
      STA HBP         BUFFER POINTER
      LDA .-6       PREPARE TO GET
      STA TOTDG       SIX DIGITS
      JSB GETDG     GET 
      ADA .+60B 
      STA HBP,I       SIX 
      ISZ HBP 
      ISZ TOTDG         DIGITS
      JMP *-5 
      LDA .+2       SET NBLK TO 
      STA NBLK        WHERE IT WONT CAUSE TROUBLE 
      JSB ROUND     ROUND NUMBER IN HOLD BUFFER 
      NOP 
      LDA SIGN      OUTPUT
      JSB OUTCR       SIGN
      LDA IHB       INITIALIZE
      STA HBP       HOLD BUFFER POINTER 
      LDA HBP,I     OUTPUT
      JSB OUTCR       DIGIT 
      ISZ HBP         INCREMENT HOLD BUFFER POINTER 
      LDA .+56B     OUTPUT
      JSB OUTCR       DECIMAL POINT 
      LDA .-5       PREPARE TO OUTPUT 
      STA TOTDG       FIVE DIGITS 
      LDA HBP,I     OUTPUT
      JSB OUTCR       FIVE
      ISZ HBP           DIGITS
      ISZ TOTDG 
      JMP *-4 
      LDA E         OUTPUT
      JSB OUTCR       AN E
      LDA .+55B 
      LDB EXPON     OUTPUT
      SSB 
      CMB,INB,RSS     EXPONENT
      LDA .+53B 
      STB EXPON         SIGN
      JSB OUTCR 
      LDA EXPON 
      CLB           GET BOTH EXPONENT DIGITS
      DIV .+12B 
      ADA .+60B     CONVERT BOTH
      ADB .+60B       TO ASCII
      STB EXPON 
      JSB OUTCR     OUTPUT 10'S DIGIT 
      LDA EXPON 
      JSB OUTCR     OUTPUT 1'S DIGIT
      JSB OUTCL 
      JMP FMT90 
FMEND LDA CONTR     YES, CONTROL
      SZA           CHARACTER FOUND ? 
      JMP *+3       YES 
      JSB OUTCL     NO
      JMP XEC1A,I 
      CPA .+53B     IS CARRIAGE 
      RSS                CONTROL A +
      JMP FM10      NO
      LDA .+23B     YES 
      JSB OUTCR     OUTPUT AN X-OFF 
      LDA .+15B      AND A
      JSB OUTCR       CARRIAGE RETURN 
      CLA 
      STA CHRCT 
      JMP XEC1A,I 
FM10  CPA .+55B     IS IT A MINUS ? 
      RSS           YES 
      JMP XEC1A,I 
      LDA .+12B     OUTPUT A
      JSB OUTCR       LINEFEED
      JMP XEC1A,I 
