
      HED OUTPUT ROUTINES 
      ORG 50000B
HMASK OCT 174000
LCALL DEF LIS10-1 
NMBFA DEF NUMBF 
.74   DEC 74
.75   DEC 75
MM72  DEC -72 
MM74  DEC -74 
M1000 DEC -1000 
**                    **
***  PRINT A NUMBER  ***
**                    **
* 
*  ENTER WITH A FLOATING POINT NUMBER IN (A) AND (B).  PRINT THE
*  NUMBER AND APPEND BLANKS TO REACH THE PRINT POSITION SPECIFIED 
*  BY -EOPF ON RETURN FROM NUMOT. 
* 
#ENOT CCE           ENABLE SIGN 
      JSB NUMOT     OUTPUT NUMBER 
      JMP *+3 
      LDA .+40B     OUTPUT
      JSB OUTCR       A BLANK 
      LDB EOPF      FIELD 
      ADB CHRCT 
      SZB             FULL? 
      JMP *-5       NO
      JMP ENOUT,I   YES 
* 
MINFX DEC -0.099999959
MAXFX DEC -999999.5 
**                     ** 
***  OUTPUT A NUMBER  *** 
**                     ** 
* 
*  ENTER WITH A FLOATING POINT NUMBER IN (A) AND (B) AND (E) = 1
*  IF A SIGN IS WANTED.  DETERMINE THE FORM OF THE NUMBER AND 
*  SET EOPF ACCORDINGLY.  NON-INTEGERS ARE ROUNDED AFTER CONVERSION 
*  TO DECIMAL.  TRAILING ZEROS ARE SUPPRESSED ON NUMBERS WITHOUT
*  EXPONENTS (AND ON NUMBERS WITH EXPONENTS IF CALLED FROM 'LIST'). 
* 
#NMOT STA NUMBF     SAVE HIGH MANTISSA
      SEZ,RSS       SIGN? 
      JMP NUMO1     NO
      SSA,RSS       YES, NEGATIVE NUMBER? 
      JMP *+5       NO
      JSB ARINV     YES, NEGATE NUMBER
      STA NUMBF     SAVE HIGH MANTISSA
      LDA .+55B     LOAD '-'
      RSS 
      LDA .+40B     LOAD '+'
      STA SIGN      SAVE SIGN 
      LDA NUMBF     RETRIEVE HIGH MANTISSA
NUMO1 STB NUMBF+1   SAVE LOW MANTISSA 
      JSB IFIX      INTEGER?
      JMP NUMO2     NO
      SOC           YES, 16-BIT INTEGER?
      JMP NUMO2     NO
*                       * 
**  OUTPUT AN INTEGER  ** 
*                       * 
      STB NUMBF     SAVE INTEGER
      ADB M1000 
      LDA .+6 
      SSB,RSS       3 DIGIT INTEGER?
      ADA .+3       NO
      ADA CHRCT     COMPUTE END-OF-FIELD
      CMA,INA       SAVE
      STA EOPF        IT
      ADA .74       ENOUGH
      SSA             ROOM? 
      JSB OUTLN     NO
      LDA SIGN      YES 
      SZA           SIGN? 
      JSB OUTCR     YES, OUTPUT IT
      LDB NUMBF     NO
      JSB OUTIN     OUTPUT THE INTEGER
      JMP NUMOT,I 
*                                    *
**  OUTPUT A FLOATING POINT NUMBER  **
*                                    *
NUMO2 LDA .-2       SET 'FIXED' 
      STA FFLAG       FLAG FALSE
      DLD NUMBF     LOAD NUMBER 
      JSB .FAD      IS NUMBER 
      DEF MAXFX       LESS THAN 
      SSA,RSS           999999.5 ?
      JMP NUMO3     NO
      DLD NUMBF     YES, IS 
      JSB .FAD        NUMBER
      DEF MINFX         LESS THAN 
      SSA,RSS             0.09999995 ?
      ISZ FFLAG     NO, SET 'FIXED' FLAG TRUE 
NUMO3 DLD NUMBF     LOAD NUMBER 
      STA MANT1     UNPACK
      JSB .FLUN 
      STB MANT2       NUMBER
      STA EXP 
      CLA           INITIALIZE
      STA EXPON       DECIMAL EXPONENT
      CPA EXP       ZERO EXPONENT?
      JMP NUMO5     YES 
NUMO0 JSB MBY10     NO
      LDA EXP       MULTIPLY
      CMA,SSA,INA,SZA   NUMBER BY 10
      JMP *+3             UNTIL IT IS 
      ISZ EXPON             GREATER 
      JMP NUMO0               THAN 1
      JSB DBY10     DIVIDE BY 10
      LDA EXPON 
NUMO4 LDB EXP       DIVIDE
      CMB,INB         NUMBER
      SSB,RSS           BY 10 
      JMP NUMO5           UNTIL 
      STA EXPON             IT IS 
      JSB DBY10               LESS
      CCA                       THAN
      ADA EXPON                   1 
      JMP NUMO4 
NUMO5 CMA           SET EXPONENT
      STA EXPON       TO TRUE VALUE-1 
      LDB .-6       SET DIGIT 
      STB DIGCT       COUNTER 
      LDB NMBFA     SET BUFFER
      STB NMPTR       POINTER 
*                               * 
**  CONVERT MANTISSA TO ASCII  ** 
*                               * 
NUMO6 JSB GETDG     STORE A 
      ADA .+60B       DECIMAL 
      STA NMPTR,I       DIGIT 
      ISZ NMPTR 
      ISZ DIGCT     SIXTH DIGIT?
      JMP NUMO6     NO
      JSB GETDG     YES,
      ADA .-5         NEXT DIGIT
      SSA               >= 5 ?
      JMP NUMO9+1   NO
*                          *
**  ROUND ASCII MANTISSA  **
*                          *
      LDB NMPTR 
NUMO7 ADB .-1       LOAD LAST 
      LDA 1,I         DIGIT 
      INA           INCREMENT IT
      CPA .58       WAS IT A 9? 
      RSS           YES 
      JMP NUMO9     NO
      CPB NMBFA     LEADING DIGIT?
      JMP NUMO8     YES 
      LDA .+60B     NO, OVERLAY 
      STA 1,I         A 0 
      JMP NUMO7 
NUMO8 ISZ EXPON     BUMP DECIMAL
      NOP             EXPONENT AND
      LDA .+61B         OVERLAY A 1 
NUMO9 STA 1,I 
      LDA EXPON     IS NUMBER 
      SSA,RSS         LESS THAN 1 ? 
      JMP NMO11     NO
      STA NMTMP     YES 
      LDA .+60B 
      LDB NMPTR 
NMO10 ISZ NMTMP     COUNT ZEROS 
      NOP             PLUS 1
      ADB .-1       LAST
      CPA 1,I         DIGIT 0?
      JMP NMO10     YES 
      LDA NMTMP     NO, ALL SIGNIFICANCE
      SSA             IN SIX DIGITS?
      JMP NMO11     NO
      CCA           YES, SET
      STA FFLAG       'FIXED' FLAG TRUE 
NMO11 LDB .+12      COMPUTE 
      ISZ FFLAG       FIELD 
      ADB .+3           WIDTH 
      ADB CHRCT     SAVE
      CMB,INB         END-OF-FIELD
      STB EOPF          MARKER
      ADB .75       ENOUGH
      SSB             ROOM? 
      JSB OUTLN     NO
      LDA SIGN      YES 
      SZA           SIGN? 
      JSB OUTCR     YES, OUTPUT IT
      LDB .-7       SET OUTPUT
      STB DIGCT       DIGIT COUNTER 
      LDB NMPTR 
      CCA           FIXED 
      CPA FFLAG       FORMAT? 
      JMP *+5       NO
      LDA EXPON     YES, SET
      CMA             INDICATOR TO
      STA NMTMP         DECIMAL POINT 
      JMP NMO16 
      STA NMTMP     SET INDICATOR FOR DECIMAL POINT 
      LDA LCALL     CALLED
      CPA NUMOT       FROM 'LIST' ? 
      JMP NMO16     YES 
      JMP NMO14     NO
*                           * 
**  DELETE TRAILING ZEROS  ** 
*                           * 
NMO12 LDA DIGCT     AT RIGHT OF 
      INA             DECIMAL 
      CPA NMTMP         POINT?
      JMP *+6       NO
      STA DIGCT     YES, DELETE ZERO
NMO16 ADB .-1       LAST
      LDA 1,I         DIGIT 
      CPA .+60B         0?
      JMP NMO12     YES 
      CCA           NO, FIXED 
      CPA FFLAG       FORMAT? 
      JMP NMO14     NO
      LDA EXPON     YES, LEADING
      SSA,RSS         DECIMAL POINT?
      JMP NMO14     NO
      STA NMTMP     YES, SET LEADING ZEROS COUNTER
*                     * 
**  OUTPUT MANTISSA  ** 
*                     * 
      LDA .+56B     OUTPUT A
      RSS             DECIMAL POINT 
NMO13 LDA .+60B     OUTPUT
      JSB OUTCR       A ZERO
      ISZ NMTMP     MORE LEADING ZEROS? 
      JMP NMO13     YES 
      ISZ DIGCT     NO, COUNT DECIMAL POINT 
NMO14 LDB NMBFA     SET 
      STB NMPTR       DIGIT POINTER 
      JMP *+5 
NMO15 ISZ NMTMP     DECIMAL POINT NEXT? 
      JMP *+3       NO
      LDA .+56B     YES, LOAD IT
      JMP *+3 
      LDA NMPTR,I   LOAD NEXT 
      ISZ NMPTR       DIGIT 
      JSB OUTCR     OUTPUT CHARACTER
      ISZ DIGCT     MORE DIGITS?
      JMP NMO15     YES 
      ISZ FFLAG     NO, EXPONENT? 
      JMP NUMOT,I   NO
*                         * 
**  OUTPUT THE EXPONENT  ** 
*                         * 
      LDA E 
      JSB OUTCR     OUTPUT AN 'E' 
      LDA .+55B     OUTPUT
      LDB EXPON 
      SSB             AN
      CMB,INB,RSS 
      LDA .+53B         EXPONENT
      STB EXPON 
      JSB OUTCR           SIGN
      LDA EXPON 
      CLB           COMPUTE 
      DIV .+10
      ADA .+60B       EXPONENT'S
      ADB .+60B 
      STB EXPON         10'S DIGIT
      JSB OUTCR     OUTPUT IT 
      LDA EXPON     OUTPUT
      JSB OUTCR       1'S DIGIT 
      JMP NUMOT,I 
**                         ** 
***  GET DIGIT TO OUTPUT  *** 
**                         ** 
* 
*  COMPUTE NEXT DECIMAL DIGIT AND RETURN WITH IT IN (A).
*  SUBTRACT IT OUT OF THE NUMBER. 
* 
#GTDG JSB MBY10     MULTIPLY BY 10
      LDB EXP       GET EXPONENT IN (B) 
      CMB,INB         AS NEGATIVE 
      AND HMASK     RETAIN HIGH 5 BITS
      RAL           NORMALIZE TO BIT 15 
      SSB,INB       ROTATE INTEGER
      JMP *-2         INTO (A)
      AND B377      EXTRACT 
      STA FD0         DIGIT 
      LDB EXP       ROTATE
      CMB,INB 
      RAR             BACK
      SSB,INB 
      JMP *-2 
      XOR MANT1     REMOVE
      LDB MANT2       DIGIT 
      JSB NORML     NORMALIZE REMAINDER 
      LDA FD0       LOAD (A) WITH DIGIT 
      JMP GETDG,I 
      SKP 
**                       ** 
***  OUTPUT AN INTEGER  *** 
**                       ** 
* 
*  ENTER WITH A POSITIVE INTEGER IN (B).  OUTPUT IT WITHOUT 
*  LEADING ZEROS. 
* 
#OTIN LDA .-4       SET DIGIT 
      STA DGCNT       COUNTER 
      LDA LDVSR     SET DIVISOR 
      STA OT1         ADDRESS 
      CLA           SUPPRESS
      STA OUTCR       ZEROS 
OUTI1 LSR 16        DIVIDE INTEGER BY 
      DIV OT1,I       CURRENT DIVISOR 
      STB OT3       SAVE THE REMAINDER
      CPA OUTCR     LEADING ZERO? 
      JMP OUTI2     YES 
      ADA .+60B     NO, TURN OFF ZERO SUPPRESS
      JSB OUTCR     OUTPUT DIGIT
OUTI2 LDB OT3       RETRIEVE REMAINDER
      ISZ OT1       SET FOR NEXT DIVISOR
      ISZ DGCNT     ALL DIVISORS USED?
      JMP OUTI1     NO
      LDA 1         YES 
      ADA .+60B     OUTPUT
      JSB OUTCR       LAST DIGIT
      JMP OUTIN,I 
**                       ** 
***  SPACE FOR A COMMA  *** 
**                       ** 
* 
*  MOVE TO THE NEXT FIELD OF 15 ON THE PRINT LINE OR TO THE 
*  NEXT LINE IF THE CURRENT ONE IS EXHAUSTED. 
* 
#EDLM LDB CHRCT     LOAD CURRENT CHARACTER COUNT
      SZB,RSS       ZERO? 
      JMP EDELM,I   YES, AT START OF ZONE 
      ADB .-15      NO, SUBTRACT ZONE WIDTH 
      SSB,RSS       NON-NEGATIVE RESULT?
      JMP #EDLM+1   YES 
      STB EOL       NO, SAVE COUNT
      LDA .+40B     OUTPUT
      JSB OUTCR       A BLANK 
      ISZ EOL       ZONE FULL?
      JMP *-3       NO
      LDB CHRCT     YES,
      ADB MM74        PAST THE
      SSB,RSS           END OF LINE?
      JSB OUTLN     YES 
      JMP EDELM,I   NO
      SKP 
**                           ** 
***  OUTPUT AN END-OF-LINE  *** 
**                           ** 
#OTLN LDB EOPF      RESET 
      ADB CHRCT       END-OF-FIELD
      STB EOPF          MARKER
      LDA .+23B     OUTPUT
      JSB OUTCR       AN X-OFF
      LDA .+15B     OUTPUT A
      JSB OUTCR       CARRIAGE RETURN 
      LDA .+12B         AND A 
      JSB OUTCR           LINE FEED 
      JMP OUTLN,I 
**                        **
***  OUTPUT A CHARACTER  ***
**                        **
* 
*  OUTPUT THE CHARACTER IN (A).  NON-PRINTING CHARACTERS DO NOT 
*  COUNT AGAINST THE 72 CHARACTERS PER LINE.  A CARRIAGE RETURN 
*  ('CONTROL O' IN A STRING OR AN END-OF-LINE, FOR EXAMPLE) 
*  RESETS THE PRINT POSITION TO 0.
* 
#OTCR STA OCTMP     SAVE CHARACTER
      CPA B177      CHECK FOR 
      JMP OTCRA       RUBOUT
      AND .140      NON-PRINTING
      SZA             CHARACTER?
      ISZ CHRCT     NO, COUNT IT
OTCRA EQU * 
      CLB 
      LDA OCTMP     RETRIEVE CHARACTER
      CPA .+15B     CARRIAGE RETURN?
      STB CHRCT     YES, ZERO CHARACTER COUNT 
      LDB MLINK+1 
      ADB .-?LINK 
      JSB OUTCH,I 
      JMP OUTCR,I 
**                         ** 
***  BACKSPACE IN BUFFER  *** 
**                         ** 
* 
* BACKSPACE IN BUFFER 
* 
#BKSP LDA MAIN      TELL 2114 
      INA 
      LDA 0,I         TO BACKSPACE
      IOR BKS 
      JSB S14LP,I       IN BUFFER 
      JMP BCKSP,I 
      SKP 
**                                 ** 
***  FETCH NEXT BUFFER CHARACTER  *** 
**                                 ** 
* 
*  THE NEXT CHARACTER FROM THE INPUT BUFFER IS FETCHED. NORMAL
*  EXIT IS TO (P+2) WITH THE CHARACTER IN (A). BLANKS ARE SKIPPED 
* IF 'BLANK' = 40 OCTAL. A 'CARRIAGE RETURN' EXITS TO (P+1) 
#GTCR LDA GTC       LOAD OPCODE 
      LDB MAIN        FOR GET CHARACTER 
      INB           => TTY #
      IOR 1,I       TTY # IN BITS 12-8
      CLB           BLOCK 
      STB DCLC1,I     CLOCK 
      JSB S14SC,I   CALL 2114 DRIVER
      SFS CH2       WAIT FOR
      JMP *-1         RESPONSE
      LIA CH2       LOAD CHARACTER
      LDB DCLC2,I   UNBLOCK 
      STB DCLC1,I     CLOCK 
      CPA BLANK     BLANK?
      JMP #GTCR     YES--IGNORE IT
      CPA .+15B     NO, CARRIAGE RETURN?
      JMP GETCR,I   YES 
      LDB 0         COPY CHAR TO B
      ADA M96 
      SSA,RSS       LOWER CASE
      ADA M32       MAKE INTO UPPER CASE
      ADA .140
      ISZ GETCR     NO--EXIT
      JMP GETCR,I     TO (P+2)
      HED           LIBRARY FUNCTIONS 
* *                *
**  EXECUTE TAB(X)  * 
* *                *
ETAB  JSB .IENT     INTEGERIZE ARGUMENT 
      LDA INF       ARG > 32767 
      CLB           SET FLAG TO 
      STB EOL         'TAB OCCURRED'
      LDB FFLG      GET FORMAT FLAG 
      SZB           IN FORMATTER ?
      JMP ETAB2     YES 
      LDB MM72
      ADB A 
      SSB,RSS 
      JMP ETAB4-1   YES, GO TO NEXT LINE
ETAB2 CMA,INA       NO
      ADA CHRCT     ANY BLANKS
      SSA,RSS         REQUIRED? 
      JMP ETAB4     NO
      STA LBTMP     YES 
ETAB1 LDA .+40B     OUTPUT
      JSB OUTCR       A BLANK 
      ISZ LBTMP     DONE? 
      JMP ETAB1     NO
      RSS           YES 
      JSB OUTLN 
ETAB4 LDA BIT15     SO OPCHK DOESN'T BARF 
      JMP FRET,I
*                  *
**  EXECUTE SPA(X)  * 
ESPA  JSB .IENT     INTEGERIZE ARGUMENT 
      LDA INF       ARG > 32767 
      CLB           SET FUNCTION FLAG 
      STB EOL         TO EXECUTED 
      SZA,RSS       IS IT ZERO ?
      JMP ESPA4     YES 
      SSA           NO, NEGATIVE? 
      JMP ESPA4     YES 
      CMA,INA       NO
      STA REPCT     OUTPUT
      LDB FFLG
      SZB 
      JMP ESPA1     NO
      ADA .72 
      LDB CHRCT     SPACING PAST
      CMB,INB         END OF LINE ? 
      ADA 1 
      SSA 
      JMP ESPA4-1 
ESPA1 LDA BLANK 
      JSB OUTCR 
      ISZ REPCT 
      JMP ESPA1 
      CCA           RESET 
      STA REPCT       REPCT 
      RSS 
      JSB OUTLN 
ESPA4 LDA BIT15     SO OPCHK DOESN'T BARF 
      JMP FRET,I
*                  *
*                  *
**  EXECUTE LIN(X)  * 
*                  *
ELIN  JSB .IENT     INTEGERIZE ARGUMENT 
      LDA B400
      CLB           SET FUNCTION FLAG 
      STB EOL         TO EXECUTED 
      SSA,RSS       NO, NEGATIVE ?
      JMP ELIN1     NO
      ADA B400
      SSA 
      CLA 
      ADA M256
      STA REPCT 
      LDA .+12B 
      JSB OUTCR       REPCT LINEFEEDS 
      ISZ REPCT 
      JMP *-3 
      CCA 
      STA REPCT     REINITIALIZE REPCT
      JMP ELIN2     YES 
ELIN1 ADA M256
      SSA,RSS       ARGUMENT > 2 56 ? 
      CLA 
      ADA B400
      SZA 
      JMP ELIN3 
      LDA .+15B 
      JSB OUTCR 
      CLA 
      STA CHRCT 
      JMP ELIN2     YES 
ELIN3 CMA,INA 
      STA REPCT       OUTPUT
      JSB OUTCL         CR-LF'S 
      ISZ REPCT 
      JMP *-2 
      CCA           RESET 
      STA REPCT       REPCT 
ELIN2 LDA BIT15     SO OPCHK DOESN'T BARF 
      JMP FRET,I
