      HED LIST ROUTINES 
* **********************
****                  *** 
***  LIST THE PROGRAM  ***
****                  *** 
* **********************
* qq
* 
* 
*  '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.
* qq
XPNCH CLA,INA       SET FLAG TO XPUNCH
      JMP LIST+1
PUNCH CCA,RSS       SET TO 'PUNCH' MODE 
LIST  CLA           SET TO 'LIST' MODE
      STA LT0       SAVE MODE 
      LDB PBUFF     NULL
      CPB PBPTR       PROGRAM?
      JMP LIS16     YES 
      LDB SPROG     NO
      STB LT3 
      JSB SINIT     PREPARE PROGRAM FOR LISTING 
      LDB PBPTR 
      LDA CFLAG     SAVE
      AND LMSK        PROGRAM                      [X]
      STA LT5           MODE
*                                            *
**  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 LIST1     NO
      CLB 
      CPA .+54B     CHECK FOR COMMA 
      JMP LISCM    FIRST STATEMENT NUMBER OMITTED.
      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? 
      JMP LISCM     YES 
      JSB RERRS+12,I    NOPE
LISCM EQU * 
      STB LT3      SAVE STARTING SEQUENCE NUMBER
      JSB BLDIN    GET INTEGER
      CPA .+15B     END OF RECORD?
      CMB,RSS       YES 
      JSB RERRS+12,I  NO
      STB LT7      SAVE ENDING SEQUENCE NUMBER
      LDB LT3      GET BACK STARTING SEQUENCE NUMBER
LISCR EQU * FF
      LDA LT6       SEEK
      JSB FNDPS       STATEMENT 
      JMP LIS16     ALL LINE NUMBERS < GIVEN INTEGER
      NOP           SAVE DESIRED
      STB LT3         STARTING POINT
LIST1 LDA .+12B     OUTPUT A
      JSB OUTCR       LINE FEED 
*                         * 
**  OUTPUT PROGRAM NAME  ** 
*                         * 
      LDA LNAME 
      STA LT1 
      ADA .+?NAME-?ID 
      LDA 0,I 
      AND INF 
      SZA,RSS         NAME? 
      JMP *+7       YES 
      CLB           NO
      STB LT2       OUTPUT
      LDA .-3         PROGRAM 
      JSB OUTST         NAME
      LDA .+15B     OUTPUT
      JSB OUTCR       CARRIAGE RETURN 
      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
      LDB LT1,I     NO, OUTPUT
      JSB OUTIN       LINE NUMBER 
      LDA .+40B     OUTPUT
      JSB OUTCR       BLANK 
      ISZ LT1       CHECK STATEMENT LENGTH        (D) 
      LDA LT1,I                                   (D) 
      JSB STLCK                                   (D) 
      LDA LT1,I     SET LENGTH                  (D) 
      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    IS IT XPUNCH?
      CPA LT0 
      RSS         YES 
      JMP *+3 
      LDA .+23B   OUPUT X-OFF CHARACTER 
      JSB OUTCR kk
      LDA .+15B     NO, 
      JSB OUTCR       OUTPUT A
      LDA .+12B         CARRIAGE RETURN 
      JSB OUTCR           AND LINE FEED 
      JMP LIST2 2A
*                       * 
**  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     " ? ?k
      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 3X
      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       LISTING A 
      CPA DIMOP       <DIM STATEMENT> ? 
      JMP LIST3-2   YES 
      CPA COMOP     NO, 'COM'?
      JMP LIST3-2   YES 
LIS18 EQU *                                      B] 
      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 .+54B     EMIT
      JSB OUTCR       A COMMA 
      JMP LIS18                                  B] 
*                                  *
**  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 CHNOP     NO, 'CHAIN'?
      JMP LIS13-1   YES 
      JSB OUTCR     NO, OUTPUT A BLANK
      JMP LIST5 
      JSB OUTCR     OUTPUT A BLANK
LIS13 LDA LT2       OUTPUT
      CCB             THE 
      JSB OUTST         REMARK
      JMP LIST3 
*                               * 
**  OUTPUT TRAILER IF 'PUNCH'  ** 
*                               * 
LIS15 CLA       LISTSK
      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     OUTPUT
      JSB OUTCR       CLOSING " 
      JMP LIST3 
**                          **
***  WRITE BUFFER TO DISC  ***
**                          **
* qq
*  THE BUFFER OF THAT FILE CURRENTLY REFERENCED BY FBASE IS 
*  WRITTEN TO ITS PLACE ON THE DISC, UNLESS NOTHING HAS BEEN
*  WRITTEN INTO THE BUFFER. 
* *q
#WRBU LDB FBASE     LOAD FIRST
      ADB .-2         WORD FROM 
      LDA 1,I           FILE TABLE
      RAL,ELA             ENTRY 
      SEZ,CLE,RSS   HAS BIT14 BEEN SET? 
      JMP WRBUF,I   NO
      ERA,RAR       YES--CLEAR IT 
      STA 1,I 
      LDA FBASE,I   LOAD ACTIVE RECORD ADDRESS
      CPA .-1       NULL RECORD?
      JMP WRBUF,I   YES 
      LDB M128     NO                            X] 
      CLF 0         WRITE 
      STB WORD
      LDB RQ3 
      JSB DISC,I      RECORD
      LDA ENDSK 
      SZA 
      JMP *-2           TO DISK 
      JMP WRBUF,I I6
**                       ** 
***  TRANSFER A STRING  *** 
**                       ** 
* qq
*  THE NUMBER OF CHARACTERS SPECIFIED BY TNULL (IN 1'S
*  COMPLEMENT) IS TRANSFERRED FROM THE SOURCE STRING TO 
*  A DESTINATION STRING BEGINNING WITH THE CHARACTER
*  ADDRESSED BY TEMP5.
* *q
#TRST STA TRFCH     SAVE SUBROUTINE CALL
      ISZ TNULL     MORE TRANSFER STRING? 
      RSS           YES 
      JMP TRSTR,I   NO
      JSB TRFCH,I   FETCH A SOURCE CHARACTER
      LDA .+40B     NONE LEFT, LOAD A BLANK 
      STA TRS0      SAVE IT 
      LDB TEMP5     LOAD
      CLE,ERB         DESTINATION 
      LDA 1,I           WORD
      SEZ,RSS       SAVE
      ALF,ALF         OTHER 
      AND M256          CHARACTER 
      IOR TRS0      COMBINE WITH
      SEZ,RSS         NEW CHARACTER 
      ALF,ALF           AND STORE 
      STA 1,I             WORD
      ISZ TEMP5     INCREMENT DESTINATION ADDRESS 
      JMP #TRST+1 
**                                  **
***  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  *** *K
**                   ** 
* 
*  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.
* qq
#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
      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. 
      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 
      SKP Pl
**                     ** 
***  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 M74         PAST THE
      SSB,RSS           END OF LINE?
      JSB OUTLN     YES 
      JMP EDELM,I   NO
**                           ** 
***  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
      AND .140      NON-
      SZA             PRINTING
      CPA .140          CHARACTER?
      RSS           YES 
      ISZ CHRCT     NO, COUNT IT
      CLB 
      LDA OCTMP     RETRIEVE CHARACTER
      CPA .+15B     CARRIAGE RETURN?
      STB CHRCT     YES, ZERO CHARACTER COUNT 
      LDB MLINK+1 
      ADB .-?LINK 
      JSB POCR,I,l
      JMP OUTCR,I 
