
      SKP 
* *                *
**  COMPUTE LOG(X)  * 
* *                *
ELOG  JSB .LOG
      JMP FRET,I
#LOG  SZA,RSS       NON-ZERO ARGUMENT?
      JMP .LOG1     NO
      SSA           YES, POSITIVE ARGUMENT? 
      JSB RERRS+27,I  NO
      STA XTEMP     YES,
      JSB .FLUN       SAVE MANTISSA 
      STB XTEMP+1       AND FLOATED 
      FLT                 EXPONENT               [B]
      DST YTEMP             SEPARATELY
      DLD XTEMP 
      JSB .FAD
      DEF R22 
      DST UTEMP     U = X+SQR(0.5)
      DLD XTEMP 
      JSB .FSB
      DEF R22 
      JSB .FDV
      DEF UTEMP 
      DST UTEMP     U = (X-SQR(0.5))/U
      JSB .FMP
      DEF UTEMP 
      JSB .FSB
      DEF CCC 
      DST XTEMP 
      DLD MB
      JSB .FDV
      DEF XTEMP 
      JSB .FAD
      DEF AAA 
      JSB .FMP
      DEF UTEMP 
      JSB .FSB
      DEF HALF
      JSB .FAD
      DEF YTEMP 
      JSB .FMP
      DEF LE2       ANS = LOG(2)* 
      JMP .LOG,I      (MANTISSA-0.5+U*(AAA+MB/X)) 
.LOG1 JSB WERRS+1,I 
      LDA MNEG
      LDB B776      ANS = NEGATIVE INFINITY 
      JMP .LOG,I
* 
B776  OCT 776 
R22   DEC .707106781     SQR(0.5) 
LE2   DEC .6931471806    LOG BASE E (2) 
AAA   DEC 1.2920070987
MB    DEC -2.6398577035 
CCC   DEC 1.6567626301
      HED UTILITY ROUTINE 
* 
*  ENTER WITH:
* 
*     (A)=1 IF PBFLG HAS TO BE SET. 
* 
*     (A)=2 IF PBFLG HAS TO BE CLEARED. 
* 
*     (A)=4 IF PBFLG AND CBFLG HAVE TO BE CLEARED.
* 
*     (B)= POINTER TO ?FLAG 
* 
*  EXIT WITH ORIGINAL CONTENTS IN B.
* 
#EDAB EQU * 
      CLF 0 
      SLA,RSS       BIT#0 SET?
      JMP *+4 
      LDA PBFLG     YES. SET PBFLG. 
      IOR B,I 
      JMP #EDB1 
      RAR,SLA       NO. BIT#1 SET?
      LDA PBFLG     YES. CLEAR PBFLG. 
      LDA B30M      NO. CLEAR PBFLG AND CBFLG.
      CMA 
      AND B,I 
#EDB1 EQU * 
      STA B,I       STORE ?FLAG WORD BACK.
      STF 0 
      JMP EDABR,I   EXIT. 
* 
* 
      HED LIBRARY FUNCTIONS 
      SKP 
      ORG 52000B
TENTH OCT 63146 
B63   OCT 63
B120  OCT 120       "P" 
D62   OCT -62 
M71B  OCT -71 
BB776 OCT 776 
F     OCT 106 
N     OCT 116 
* *                *
**  COMPUTE SQR(X)  * 
* *                *
ESQR  SZA,RSS       X= 0? 
      JMP FRET,I    YES, ANS = 0
      SSA           NO, X < 0?
      JSB RERRS+28,I  YES 
      STA XTEMP     NO
      JSB .FLUN 
      SLA,ARS       EXPONENT ODD? 
      JMP ESQR2     YES 
      ADA .-1       NO
      STA LBTMP     EXPONENT/2 -1 
      STB XTEMP+1   MANTISSA SAVED
      LDA XTEMP 
      JSB .FMP
      DEF SA2 
      JSB .FAD
      DEF SB2       Y = SB2+SA2*X 
ESQR1 DST YTEMP 
      DLD XTEMP 
      JSB .FDV
      DEF YTEMP 
      JSB .FAD
      DEF YTEMP 
      JSB .PWR2 
      DEF .-1 
      DST YTEMP     Y = (Y+X/Y)/2 
      DLD XTEMP 
      JSB .FDV
      DEF YTEMP 
      JSB .FAD
      DEF YTEMP 
      JSB .PWR2 
      DEF LBTMP 
      JMP FRET,I    ANS = (P+F/P)*2^ESQ0
ESQR2 STA LBTMP     EXPONENT/2
      ADB B377
      STB XTEMP+1   MANTISSA/2 SAVED
      LDA XTEMP 
      JSB .FMP
      DEF SA1 
      JSB .FAD
      DEF SB1 
      JMP ESQR1     Y = SB1+SA1*X 
* 
SA1   DEC .875
SA2   DEC .578125 
SB1   DEC .27863
SB2   DEC .421875 
* *              *
** COMPUTE BRK(X) * 
* *              *
* 
*  ENTER WITH ARGUMENT IN A AND B.
*  IF X=0, DISABLE ABORT CAPABILITY.
*  IF X>0, ENABLE ABORT CAPABILITY. 
*  IF X<0, DO NOT DISABLE OR ENABLE BUT JUST
*  RETURN A VALUE.
* 
*  RETURN WITH: 
* 
*  1.  0 IF ABORT CAPABILITY WAS DISABLED PREVIOUS
*      TO EVALUATION. 
* 
*  2.  +1 IF ABORT CAPABILITY WAS ENABLED PREVIOUS
*      TO EVALUATION. 
* 
EBRK  STA XTEMP     STORE HIGH PART OF ARGUMENT.
      LDA MAIN,I    A= ?FLAG
      AND PBFLG 
      CLB 
      SZA,RSS       PBFLG BIT SET?
      LDB .+2       NO. SET (B)=EXPONENT OF +1. 
      LDA FLGBT     YES. SET (A)=100000B. 
      SZB,RSS       WAS PBFLG SET?
      CLA           YES. SET RETURN VALUE TO 0. 
      RAR           NO. SET RETURN VALUE TO +1. 
      DST YTEMP     SAVE. 
* 
      LDB MAIN      (B)=> ? FLAG
      LDA XTEMP     RETRIEVE HIGH PART OF ARGUMENT. 
      SZA           ARGUMENT=0? 
      JMP EBRK1 
      CLA,INA       YES. SET PBFLG TO 1(=DISABLE
      JSB EDABR        ABORT).
      CLF 0 
      ADB .+?STAT   B=> ?STAT 
      LDB B,I       B= ?STAT
      CCA 
      CPA B 
      JMP SUSPN,I   QUIT IF ABORT REQUEST.
      STF 0 
      JMP EBRK2 
EBRK1 EQU * 
      SSA           NO. ARGUMENT >0 OR <0?
      JMP EBRK2     <0. DO NOTHING. 
      LDA .+2       <0 SET PBFLG TO 0(=ENABLE 
      JSB EDABR        ABORT).
EBRK2 EQU * 
      DLD YTEMP     RETURN WITH VALUE OF CONDITION
      JMP FRET,I      PREVIOUS TO EVALUATION. 
* 
* 
SUSPN DEF SUSP
* 
* 
      HED LIST ROUTINES 
* **********************
****                  *** 
***  LIST THE PROGRAM  ***
****                  *** 
* **********************
* 
* 
* 
*  'LIST' CONVERTS THE CURRENT USER PROGRAM TO A STANDARD ASCII 
*  FORMAT AND PRINTS IT ON THE TELETYPE ONE LINE PER PROGRAM
*  STATEMENT.  'PUNCH' ADDS A LEADER AND TRAILER TO THE ASCII 
*  PROGRAM DUMP.  LISTING BEGINS WITH THE FIRST PROGRAM STATEMENT 
*  UNLESS DIRECTED OTHERWISE BY THE 'LIST' OR 'PUNCH' COMMAND.
*  LT1 IS THE PROGRAM POSITION POINTER.  LT2 IS THE STATEMENT 
*  LENGTH COUNTER.
* 
XPNCH CLA,INA       SET TO 'XPUNCH' MODE
      JMP LIST+1
PUNCH CCA,RSS       SET TO 'PUNCH' MODE 
LIST  CLA           SET TO 'LIST' MODE
      STA LT0       SAVE MODE 
      CLA           SET FOR 
      STA LT8         NO PAGINATION 
      LDB PBUFF     NULL
      CPB PBPTR       PROGRAM?
      JMP LIS16     YES 
      CLB,INB       NO, SET FIRST STATEMENT NUMBER
      STB LT3 
      JSB SINIT     PREPARE PROGRAM FOR LISTING 
      LDB PBPTR 
      CLF 0 
      LDA CFLAG     SAVE
      AND MAIN,I      PROGRAM 
      STA LT5           MODE
      STF 0 
*                                            *
**  DETERMINE FIRST STATEMENT TO BE LISTED  **
*                                            *
      SZA           SAVE POINTER TO 
      LDB SYMTB       LAST WORD +1
      STB LT6           OF PROGRAM
      LDB BIT15    GET LARGE SEQUENCE NUMBER
      STB LT7      SET ENDING SEQUENCE NUMBER 
      JSB GETCR     STARTING LINE NUMBER? 
      JMP LISCQ      NO 
      CLB 
      CPA .+54B    CHECK FOR COMMA
      JMP LISCM    FIRST STATEMENT NUMBER OMITTED.
      CPA B120      PAGINATION? 
      JMP LISCP       YES 
      JSB BCKSP     BACK UP FOR FIRST STATEMENT NUMBER
      JSB BLDIN     FETCH INTEGER 
      CPA .+15B    CHECK FOR CARRIAGE RETURN
      JMP LISCR    YES, END OF COMMAND
      CPA .+54B     COMMA FOLLOWS?
      RSS           YES 
      JSB RERRS+12,I
LISCM EQU * 
      STB LT3      SAVE STARTING SEQUENCE NUMBER
      JSB GETCR     GET THE NEXT CHARACTER
      JSB RERRS+12,I
      CPA B120      CHECK FOR P 
      JMP LISCP     PAGINATION
      JSB BCKSP     BACK UP FOR SECOND STATEMENT #
      JSB BLDIN    GET INTEGER
      CMB 
      STB LT7       SAVE ENDING SEQUENCE NUMBER 
      CPA .+15B     END OF RECORD?
      JMP LISCQ     YES 
      JSB GETCR     NO, GET NEXT CHARACTER
      JSB RERRS+12,I
      CPA B120      PAGINATION? 
      RSS           YES 
      JSB RERRS+12,I  NO
LISCP EQU * 
      LDA M71B      SET LINE COUNTER
      STA LT8 
      JSB GETCR     TEST FOR END OF LINE
      RSS 
      JSB RERRS+12,I
LISCQ EQU * 
      LDB LT3      GET BACK STARTING SEQUENCE NUMBER
LISCR EQU * 
      LDA LT6       SEEK
      JSB FNDPS       STATEMENT 
      JMP LIS16     ALL LINE NUMBERS < GIVEN INTEGER
      NOP           SAVE DESIRED
      STB LT3         STARTING POINT
      LDA .+12B     OUTPUT A
      JSB OUTCR       LINE FEED 
*                         * 
**  OUTPUT PROGRAM NAME  ** 
*                         * 
      LDA LNAME 
      STA LT1 
      ADA .+?NAME-?ID 
      LDA A,I       REMOVE RUN-ONLY 
      AND INF         BIT AND CHECK FOR 
      SZA,RSS           NULL PROGRAM NAME 
      JMP LISCU     YES 
      CLB           NO
      STB LT2       OUTPUT
      LDA .-3         PROGRAM 
      JSB OUTST         NAME
      LDA .+15B     OUTPUT
      JSB OUTCR       CARRIAGE RETURN 
LISCU EQU * 
      LDA .+12B         AND 
      JSB OUTCR           DOUBLE
      LDA .+12B             LINE
      JSB OUTCR               FEED
*                              *
**  OUTPUT LEADER IF 'PUNCH'  **
*                              *
      CLA           'LIST'
      CPA LT0         MODE? 
      JMP LIST2-2   YES 
      LDA M72B      NO, 
      STA DIGCT       OUTPUT
      CLA               FEED
      JSB OUTCR           FRAMES
      ISZ DIGCT             FOR 
      JMP *-3                 LEADER
      LDB LT3       SET POINTER TO
      STB LT1         STARTING POINT
*                    *
**  MAIN LIST LOOP  **
*                    *
LIST2 LDB LT1       PROGRAM 
      CPB LT6         EXHAUSTED?
      JMP LIS15     YES 
      LDB LT1,I    GET LINE NUMBER
      ADB LT7      CHECK FOR END OF LISTING 
      SSB,RSS      SKIP IF NOT DONE YET 
      JMP LIS15    STOP LISTING HERE
* 
      ISZ LT8       CHECK FOR NEW PAGE
      JMP LISPM     NOT YET 
      LDA .-8 
      STA LT8 
LISPF EQU * 
      LDA .+12B     OUTPUT A
      JSB OUTCR       BUNCH OF
      ISZ LT8           LINE FEEDS
      JMP LISPF 
      LDA M72B      RESET LINE COUNTER
      STA LT8 
LISPM EQU * 
* 
      LDB LT1,I     NO, OUTPUT
      JSB OUTIN       LINE NUMBER 
      LDA .+40B     OUTPUT
      JSB OUTCR       BLANK 
      ISZ LT1       CHECK 
      LDA LT1,I       STATEMENT 
      JSB STLCK         LENGTH
      LDA LT1,I       LENGTH
      CMA,INA           COUNTER 
      INA                 FOR 
      STA LT2               STATEMENT 
      JMP LIST3 
      LDB LT1,I    OUTPUT 
      JSB OUTIN       BOUND 
LIST3 ISZ LT1       MORE OF 
      ISZ LT2         STATEMENT?
      JMP LIST4     YES 
      CLA,INA 
      CPA LT0       XPUNCH? 
      RSS           YES 
      JMP *+3       NO
      LDA .+23B     OUTPUT
      JSB OUTCR       X-OFF 
      LDA .+15B     NO, 
      JSB OUTCR       OUTPUT A
      LDA .+12B         CARRIAGE RETURN 
      JSB OUTCR           AND LINE FEED 
      JMP LIST2 
*                       * 
**  IDENTIFY OPERATOR  ** 
*                       * 
LIST4 LDA LT1,I     EXTRACT 
      AND OPMSK       OPERATOR
      SZA,RSS       NULL OPERATOR?
      JMP LIST5     YES 
      CPA LETOP     NO, 'IMPLIED' LET?
      JMP LIST5-2   YES, OUTPUT A BLANK 
      ALF,ALF       NO, 
      ADA D62         SINGLE-CHARACTER
      SSA,RSS           OPERATOR? 
      JMP LIS12     NO
      ADA B63       YES,
      ADA FOPBS       EXTRACT 
      LDA 0,I           ASCII 
      ALF,ALF             CODE
      AND B177
      CPA .+42B     " ? 
      JMP LIS14     YES 
      RSS           NO
      LDA .+40B     LOAD A BLANK
      JSB OUTCR 
*                      *
**  IDENTIFY OPERAND  **
*                      *
LIST5 LDA LT1,I     EXTRACT 
      AND OPDMK       OPERAND 
      STA LT3 
      SSA           FLAG BIT SET? 
      JMP LIST9     YES 
      CLB           NO, NULL
      CPB LT3         OPERAND?
      JMP LIST3     YES 
      CPB LT5       NO, 'COMPILED' ?
      JMP LIST0     NO
      ADA .-1       YES 
      ALS           LOAD
      ADA SYMTB       ACTUAL
      LDA 0,I           SYMBOL
      STA LT3       SAVE SYMBOL 
*                           * 
**  LIST SYMBOLIC OPERAND  ** 
*                           * 
LIST0 AND PDFFL     ISOLATE TYPE PART 
      CPA .+17B     FUNCTION? 
      JMP LIST8     YES 
LIST6 LDA LT3       NO, 
      RRR 4           COMPUTE 
      AND .+37B         ASCII FOR 
      ADA B100            LETTER
      JSB OUTCR     OUTPUT LETTER 
      LDA LT3 
      AND .+17B 
      CPA .+17B     FUNCTION? 
      JMP LIST3     YES 
      SZA,RSS       NO, STRING VARIABLE?
      JMP LIST7     YES 
      ADA .-5       NO
      SSA           DIGIT?
      JMP LIST3     NO
      ADA .+60B     YES,
      JSB OUTCR       OUTPUT IT 
      JMP LIST3 
LIST7 LDA .+44B     LOAD ASCII '$'
      JMP *-3 
LIST8 LDA F         OUTPUT
      JSB OUTCR 
      LDA N           'FN'
      JSB OUTCR 
      JMP LIST6 
*                                        *
**  LIST CONSTANT OPERAND OR PARAMETER  **
*                                        *
LIST9 ELA,CLE,ERA   CLEAR FLAG BIT
      SZA           CONSTANT? 
      JMP LIS10     NO
      STA CHRCT     YES, SET
      STA SIGN        FOR NO SIGN 
      ISZ LT1       LOAD
      ISZ LT2 
      DLD LT1,I       CONSTANT
      ISZ LT1 
      ISZ LT2 
      CLE,SSA       NEGATIVE NUMBER?
      CCE           YES, ENABLE SIGN
      JSB NUMOT     OUTPUT THE CONSTANT 
      JMP LIST3 
LIS10 AND .+17B     ISOLATE TYPE PART 
      CPA .+3       PROGRAM INTEGER?
      JMP LIS11     YES 
      CPA .+17B     NO, PRE-DEFINED FUNCTION? 
      RSS           YES 
      JMP LIST6     NO, MUST BE A PARAMETER SYMBOL
      LDA LT3       OUTPUT
      ALF,RAL 
      LDB ATAB        FUNCTION
      JSB MCOUT 
      JMP LIST3         SYMBOL
LIS11 ISZ LT1 
      ISZ LT2 
      LDA LT4       RESTORE OPERATOR
      CPA DIMOP       <DIM STATEMENT> ? 
      JMP LIST3-2   YES 
      CPA COMOP     NO, 'COM'?
      JMP LIST3-2   YES 
      LDA LT5       NO
      LDB LT1,I     LOAD PROSPECTIVE INTEGER
      SZA           PROGRAM 'COMPILED' ?
      LDB 1,I       YES 
      JSB OUTIN     OUTPUT INTEGER
      ISZ LT1       MORE
      ISZ LT2         STATEMENT?
      RSS           YES 
      JMP LIST3+3   NO
      LDA LT4       LISTING 
      CPA USEOP       'USING' ? 
      JMP LIST4     YES 
      LDA .+54B     EMIT
      JSB OUTCR       A COMMA 
      JMP LIS11+7 
*                                  *
**  LIST MULTICHARACTER OPERATOR  **
*                                  *
LIS12 LDA .+40B     OUTPUT
      JSB OUTCR       A BLANK 
      LDA LT1,I     OUTPUT
      LDB MCBOP       MULTICHARACTER
      JSB MCOUT         OPERATOR
      LDA .+40B 
      LDB LT4       WAS IT
      CPB REMOP       A 'REM' ? 
      JMP LIS13     YES 
      CPB FILOP     NO, 'FILES' ? 
      JMP LIS13-1   YES 
      CPB IMGOP     NO, 'IMAGE'?
      JMP LIS18     YES 
      JSB OUTCR     NO, OUTPUT A BLANK
      JMP LIST5 
LIS18 CLB 
      LDA LT2 
      INA,SZA 
      JSB OUTST     OUTPUT IMAGE STRING 
      JMP LIST3 
      JSB OUTCR     OUTPUT A BLANK
LIS13 CCB           OUTPUT
      LDA LT2         THE 
      JSB OUTST         REMARK
      JMP LIST3 
*                               * 
**  OUTPUT TRAILER IF 'PUNCH'  ** 
*                               * 
LIS15 EQU * 
      CLA           'LIST'
      CPA LT0         MODE? 
      JMP SCHEN,I   YES 
      LDA M72B      NO, 
      STA DIGCT       OUTPUT
      CLA               FEED
      JSB OUTCR           FRAMES
      ISZ DIGCT             FOR 
      JMP *-3                 TRAILER 
      JMP SCHEN,I 
* 
LIS16 LDA .+12B     ECHO
      JSB OUTCR       LINE
      JMP SCHEN,I       FEED
*                            *
**  LIST A STRING CONSTANT  **
*                            *
LIS14 JSB OUTCR     OUTPUT "
      LDA LT1,I     COMPUTE 
      AND B377        WORDS 
      SZA,RSS 
      JMP LIS17 
      CMA,INA           OF
      ARS                 STRING
      CLB           OUTPUT
      JSB OUTST       STRING
LIS17 LDA .+42B 
      JSB OUTCR     YES, OUTPUT IT
      JMP LIST3 
**                                  **
***  LIST A MULTICHARACTER SYMBOL  ***
**                                  **
* 
*  UPON ENTRY (A) HOLDS A WORD CONTAINING A SYMBOL CODE AND (B) 
*  HOLDS A POINTER TO THE PRINT NAME TABLE.  THE SYMBOL IS FOUND
*  IN THE TABLE AND ITS ASCII FORM OUTPUT.
* 
#MCOT AND OPMSK     SAVE
      STA LT4         SYMBOL
MCOT1 LDA 1,I       DESIRED 
      AND OPMSK       TABLE 
      CPA LT4           ENTRY?
      JMP MCOT2     YES 
      LDA 1,I       NO, 
      AND .+7         COMPUTE 
      ADA .+3           ADDRESS 
      ARS                 OF NEXT 
      ADB 0                 ENTRY 
      JMP MCOT1 
MCOT2 LDA 1,I       COMPUTE 
      AND .+7         COUNT 
      CMA,INA           OF
      ARS                 ASCII 
      STA LT3               WORDS 
      STB OUTST     SAVE ASCII SYMBOL ADDRESS 
MCOT3 ISZ OUTST     MOVE TO NEXT WORD OF SYMBOL 
      LDA OUTST,I   OUTPUT
      ALF,ALF         HIGH
      JSB OUTCR 
      LDA OUTST,I   OUTPUT
      AND B377        LOW CHARACTER 
      SZA               IF NOT
      JSB OUTCR           NULL
      ISZ LT3       MORE SYMBOL?
      JMP MCOT3     YES 
      JMP MCOUT,I   NO
**                   ** 
***  LIST A STRING  *** 
**                   ** 
* 
*  UPON ENTRY (A) HOLDS A NEGATIVE WORD COUNT OF THE STRING.  IF
*  (B) # 0 THE STRING BEGINS WITH THE LOW HALF OF (LT1),I ; IF
*  (B) = 0 IT BEGINS WITH THE HIGH HALF OF THE WORD FOLLOWING 
*  (LT1),I .  A TRAILING NULL CHARACTER WILL NOT BE PRINTED.
* 
#OTST STA LT4       SAVE STRING WORD COUNT
      SZB           'REM' ? 
      JMP OTST2     YES 
OTST1 ISZ LT1       NO, MOVE TO 
      ISZ LT2         NEXT PROGRAM WORD 
      LDA LT1,I     OUTPUT
      ALF,ALF         HIGH
      JSB OUTCR 
OTST2 LDA LT1,I     OUTPUT
      AND B377        LOW CHARACTER 
      SZA               IF NOT
      JSB OUTCR           NULL
      ISZ LT4       MORE STRING?
      JMP OTST1     YES 
      JMP OUTST,I   NO
