 TITLE 'TELEFILE ASSEMBLY PROGRAM - APDGINT'
         PCC      0
         SPACE    6
*   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*   %%%%%     MODULE NAME:     APDGINT                 %%%%%
*   %%%%%     LAST UPDATED:    MAR 07, 1984            %%%%%
*   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
         SPACE    2
         SPACE    12
*        T E L E F I L E    P R O P R I E T A R Y    P R O D U C T
         SPACE    2
*        THIS DOCUMENT INCLUDES DATA AND INFORMATION WHICH IS CONSIDERED
*        PROPRIETARY TO TELEFILE COMPUTER PRODUCTS, INC. REPRODUCTION,
*        DUPLICATION, DISCLOSURE OR DISSEMINATION, IN WHOLE OR IN PART,
*        TO OTHERS THAN REPRESENTATIVES OF THE UNITED STATES GOVERNMENT
*        SHALL NOT BE MADE WITHOUT PRIOR WRITTEN AUTHORIZATION OF TELEFILE
*        COMPUTER PRODUCTS, INC. NOTWITHSTANDING THE FOREGOING, USE OF
*        THE DATA OR INFORMATION IN WHOLE OR IN PART FOR DESIGN,
*        PROCUREMENT OR MANUFACTURE IS STRICTLY FORBIDDEN.
         PAGE
         SPACE    12
*        T E L E F I L E    P R O P R I E T A R Y    P R O D U C T
         SPACE    2
*        THIS DOCUMENT INCLUDES DATA AND INFORMATION WHICH IS CONSIDERED
*        PROPRIETARY TO TELEFILE COMPUTER PRODUCTS, INC. REPRODUCTION,
*        DUPLICATION, DISCLOSURE OR DISSEMINATION, IN WHOLE OR IN PART,
*        TO OTHERS THAN REPRESENTATIVES OF THE UNITED STATES GOVERNMENT
*        SHALL NOT BE MADE WITHOUT PRIOR WRITTEN AUTHORIZATION OF TELEFILE
*        COMPUTER PRODUCTS, INC. NOTWITHSTANDING THE FOREGOING, USE OF
*        THE DATA OR INFORMATION IN WHOLE OR IN PART FOR DESIGN,
*        PROCUREMENT OR MANUFACTURE IS STRICTLY FORBIDDEN.
         PAGE
DGI      CSECT    1                 PROCEDURE
         DEF      DGI
         DEF      DGINIT
         DEF      ENDDEF
         DEF      ENDGEN
*
         REF      CLRLSTBF
         REF      DC%FLAG           CONCORDANCE CONTROL
         REF      ENDCORE
         REF      HWX1SIZE
         REF      HWX3SIZE
         REF      LO%FLAG
         REF      LOWCORE
         REF      MAJLINE,SUBLINE   ASSEMBLY LINE NUMBER
         REF      SEGMENT#          AP OVERLAY SEGMENT
         REF      NXSYMB
         REF      PGLINES
         REF      POSITIONX1
         REF      POSITIONX3
         REF      RD%STD
         REF      READX3
         REF      REWX1
         REF      REWX3
         REF      ROOTRTN
         REF      SD%FLAG
         REF      SYSLEVEL
         REF      VAL%S:IVAL
         REF      X1BUF
         REF      X3BUF
*
         REF      BEDIT
         REF      HILIMIT4          ABORT W/ SPACE OVERFLOW
*
         REF      BOUND4
         REF      DEFHEXLBL
         REF      DEFINE2
         REF      DELETEXP
         REF      EDITV
         REF      EERR
         REF      EXPEND
         REF      GENERATE1
         REF      GENERATE3
         REF      GETCSADD
         REF      LCLDLTE
         REF      LENGTH
         REF      LITSRCH
         REF      MAXLOC
         REF      NXTRECRD
         REF      OLDCSECT
         REF      PRINT
         REF      TYPE
*
         SYSTEM   AP%IL
         SYSTEM   AP%DG
*
SDEXTSYMCD  EQU   17                LOADER CODE FOR EXT. SYM. TYPE INFO.
         PAGE
         USECT    DGI
*
*   D E F G E N        * * *  I N I T I A L I Z A T I O N  * * *
*
         LOCAL    %10
*
DGINIT   RES      0
         STW,IORL ROOTRTN           SAVE RETURN ADDRESS TO ROOT
         MTW,+1   SEGMENT#          BUMP OVERLAY SEGMENT NUMBER
*
*   INITIALIZATION FOR THE DEFINITION PASS ONLY
*
*        IF THE 'SD' OPTION IS NOT SPECIFIED, THE FIXED PORTION OF THE
*        GLOBAL SYMBOL TABLE BEGINS AT THE BASE OF DYNAMIC STORAGE.  IF
*        'SD' IS SPECIFIED, HOLD OUT 'NXSYMB' BYTES FOR TYPE INFORMATION
*        AND START THE GLOBAL TABLE AFTER THAT.
*
         LW,XT    LOWCORE
         STW,XT   SDTT              SD TYPE-TABLE BASE
         STW,XT   SYMT              GLOBAL SYMBOL TABLE BASE
         LW,XT    SD%FLAG
         IF,NZ                 -20- DOIF SD SPECIFIED
         LW,XT    NXSYMB
         AI,XT    4
         SLS,XT   -2
         AWM,XT   SYMT              BUMP BASE BY (NXSYMB+1)//4
         LW,XT1   SYMT
         CW,XT1   ENDCORE
         BGE      HILIMIT4          NO ROOM TO EVEN GET STARTED
*
         LCW,XT   XT
         LI,XT1   0
%10      RES      0                 CLEAR SDTT
         STW,XT1  *SYMT,XT
         BIR,XT   %10
*
         FI                    -20-
         LI,XT    FREELIST          SELF-ADDRESS FREE LIST POINTER
         STW,XT   FREELIST
         LW,XT    ENDCORE
         AI,XT    -1                INITIALIZE START ADDRESS OF
         STW,XT   NXTLOCAL            LOCAL SYMBOL TABLE
         LV,XT    1**(31-DEFLOB)
         STW,XT   PASSDEF           INITIALIZE FOR DEFINITION PASS
*   INITIALIZE SYMBOL TABLE TO SPECIAL ADDRESS
*
         LW,XT    NXSYMB
         AW,XT    SYMT
         CW,XT    ENDCORE
         BGE      HILIMIT4          NO ROOM TO EVEN GET STARTED
*
         LW,XT    NXSYMB            NUMBER OF SYMBOL TABLE ENTRIES
         LV,RL    1**(31-SPALOB)    SPA BIT=1 , ALL OTHERS=0
         STW,RL   *SYMT,XT
         BDR,XT   %-1
         STW,RL   *SYMT
*   READ THE NAMES USED AS COMMANDS AND MARK THEIR SYMBOL TABLE ENTRIES
READCF1  RES      0
         LI,IOADD X3BUF
         BAL,IORL READX3            READ A RECORD OF CF1 SYMBOL #S
         LI,XW    0                 RESET INDEX
         LV,XT1   1**(31-CPTRLOB)   VALUE OF 1 FOR CPTR FIELD
MARKCF1  RES      0
         LH,XT    X3BUF,XW          LOAD NEXT SYMBOL NUMBER
         BL       MARKEND           DONE IF SYMBOL NUMBER IS NEGATIVE
         STW,XT1  *SYMT,XT            FIELD BY SETTING CPTR TO ONE
         AI,XW    1                 INCREMENT INDEX
         CI,XW    HWX3SIZE
         BL       MARKCF1           CONTINUE UNTIL END OF RECORD
         B        READCF1
MARKEND  RES      0
*   DETERMINE THE BEGINNING OF DYNAMIC TABLE STORAGE
         LW,XT    SYMT              ORIGIN OF SYMBOL TABLE PLUS NUMBER
         AW,XT    NXSYMB              OF SYMBOLS IS ADDRESS OF NEXT
         STW,XT   CS0LOC              AVAILABLE SYMBOL TABLE ENTRY
         LI,RL    0
         STW,RL   0,XT              INITIALIZE
         STW,RL   1,XT                CONTROL
         STW,RL   3,XT                SECTIONS
         STW,RL   4,XT                ZERO AND ONE
         AI,XT    16*CSTBLSIZE      ROOM FOR CONTROL SECTIONS 0-15
         STW,XT   NXTSYMT           START OF DYNAMIC TABLE STORAGE
         CW,XT    ENDCORE
         BGE      HILIMIT4          NO ROOM TO EVEN GET STARTED
*
         LI,XT    X'3CFF'           SET BOBUF BINARY FORMAT
         STH,XT   BOBUF               AND SEQ. NO. BYTES
         LI,XT    108
         STW,XT   BOMAX             MAX # ACTIVE BYTES / BINARY RECORD
         LI,XT    4
         STW,XT   BOCT              INITIALIZE BO COUNT FOR BEDIT
         STW,RL   BOBUF+25,XT       CLEAR LAST FOUR WORDS
         BDR,XT   %-1                 OF BINARY OUTPUT BUFFER
         LI,XT1   -NCLEARS          NUMBER OF VARIABLES TO CLEAR
         STW,XT1  1STDEF
DEFGEN1  RES      0
*   INITIALIZATION THAT IS COMMON TO BOTH PASSES
*   CLEAR VARIABLES
         LI,XT    0
         STW,XT   ENDORG,XT1
         BIR,XT1  %-1
         STW,XT   PGLINES           FORCE TOP OF PAGE
         STW,XT   SYSLEVEL          INITIALIZE TO SOURCE LEVEL
         STW,XT   MAJLINE           CLEAR LINE NUMBER
         STW,XT   SUBLINE
*
*   SET LISTING CONTROL
         MTW,0    LO%FLAG
         BNEZ     %+2               BRANCH IF 'LO' OUTPUT REQUESTED
         MTW,8    NOLIST            SUPPRESS LO OUTPUT
*   INITIALIZE VARIABLES
         MTW,-1   MAJERRLN
         MTW,1    PSTRIG            SET SYSTEM LISTING CONTROL OFF
         MTW,1    MAXCSECT          NEXT CONTROL SECTION IS # 1
         MTW,1    DLRCS             INITIALIZE CONTROL SECTION TO ONE
         MTW,1    DDLRCS              AND %% CONTROL SECTION TO ONE
         MTW,2    DLRRS             INITIALIZE LOCATION COUNTERS
         MTW,2    DDLRRS              TO WORD RESOLUTION
*   INITIALIZE CONTROL SECTION NUMBER ONE (DEFAULT CONTROL SECTION)
         BAL,RL   OLDCSECT          SAVE LOC COUNTER VAL AND RESOLUTION
         LV,XT    CSTYPE            INITIALIZE CONTROL SECTION
         STB,XT   *XT2                ONE TO CSECT TYPE
         LW,LVL   NXTSYMT
         AW,LVL   NXTLOCAL
         SLS,LVL  -1
         STW,LVL  KLINE             ORIGIN OF MISC DYNAMIC TABLES
*   INITIALIZE THE PROCEDURE LEVEL TABLE
         LW,XT    NXTLOCAL          INITIALIZE LOCALCT TO ZERO, AND
         SW,XT    SYMT                LOCALORG TO THE ORIGIN OF THE
         STW,XT   LOCALORG,LVL        LOCAL SYMBOL TABLE
         LI,XT    0
         STW,XT   DOCT,LVL          ZERO BOTH
         STW,XT   DO1CT,LVL           DO COUNTS
         STW,XT   SYSLVL,LVL        CLEAR NUMBER SYSTEMS AT THIS LEVEL
         LI,XT    -1                INITIALIZE OFFSET TO EXPRESSION
         STW,XT   ECTORG,LVL        CONTROL TABLE ORIGIN
         BAL,RL   DELETEXP          INITIALIZE ECT,LVL AND EVT,LVL
*   INITIALIZE INTRINSIC SYMBOLS
         LW,XT    VAL%S:IVAL        VALUE TO ASSIGN TO S:IVAL
         AV,XT    SPAFLD+SPINTFLD
         AW,XT    PASSDEF
         STW,XT   TEMP              MAKE IT A SPECIAL INTEGER
         LI,XT    TEMP
         STW,XT   ARG               POINTER TO VALUE TO ASSIGN
         LV,XT    S:IVAL#           SYMBOL NUMBER FOR S:IVAL
         BAL,RL   DEFINE2           DEFINE S:IVAL
*   SET THE LISTING BUFFER TO BLANKS
         BAL,RL   CLRLSTBF          CLEAR LIST BUFFER
         STW,XT2  ERRTRIG
*   POSITION FILES
         BAL,IORL REWX1             REWIND ENCODED TEXT
         BAL,IORL REWX3             REWIND INTERMEDIATE SYMBOLIC
         LB,IOSIZE   DC%FLAG
         IF,NZ                      SKIP PAST CN CONTROL INFO
         BAL,IORL POSITIONX3
         FI
*   INITIALIZE INPUT FLAG (0,INPUT FROM X1 FILE ; 1,INPUT FROM STD FILE)
         LW,XT    RD%STD            LOAD PRE-ENCODED SYSTEM FLAG
         STH,XT   RD%STD            STORE AS INPUT FILE FLAG
         BEZ      DEFGEN2           NO PRE-ENCODED SYSTEM
         MTW,4    NOLIST        DONT LIST DURING PRE-ENCODED PROCESSING
         B        *ROOTRTN          LEAVE SF ZERO FOR STD FILE PROCESSING
DEFGEN2  RES      0
*   INITIALIZE SOURCE FLAG TO ONE FOR X1 FILE PROCESSING
         MTW,1    SF
         B        *ROOTRTN          RETURN TO THE ROOT
*
*   E N D  O F  D E F I N I T I O N  P A S S
*
ENDDEF   RES      0
         STW,IORL ROOTRTN           SAVE RETURN ADDRESS TO ROOT
         LI,XT    0
         STW,XT   NOWORDS           INITIALIZE NUMBER OF DEFS TO ZERO
         XW,XT    DECLRNUM          NUMBER OF REF AND SREFS
         AW,XT    NXTSYMT
         STW,XT   TEMPO             BASE ADDRESS FOR DEF NUMBERS
         LW,XT     TEXTCT
         STW,XT    LABELLOC            SAVE ENCODED TEXT RECORD NUMBER
         MTW,0    SOCW%FLG
         BNEZ     END15
*
END%1    RES       0
         BAL,RL   NXTRECRD          READ 1ST RECORD OF EBCDIC NAMES
END2     RES      0
         BAL,RL   NEXTITEM          GET SYMBOL NUMBER OF NEXT NAME
         CI,XT    0
         BL       END9              END OF EBCDIC NAMES
         AND,XT   =VFLD
         STW,XT   NCDITEM
         LI,XT1    X'FFFF'
         CS,XT     1STDEF              BRANCH IF THIS SYMBOL OCCURRED
         BE        END%4                 AS THE FIRST DEF
         MTH,0     1STDEF              SKIP THIS SYMBOL IF
         BEZ       END3                  LOOKING FOR FIRST DEF
END%3    RES       0
         AW,XT    SYMT              SYMBOL TABLE ADDRESS OF NAME
         LW,XT1   0,XT
         BFNZ,XT1 SPAFLD,END4       ONE WORD ENTRY
         AND,XT1  =LPTRFLD
         BEZ      END3              ITEM USED AS A COMMAND NAME ONLY
         AW,XT1   SYMT              ADDRESS OF SYMBOL
         LW,XT    XT1
         LW,XT1   0,XT
         BFNZ,XT1 SPAFLD,END4       ONE WORD ENTRY
         BFNZ,XT1 EXTFLD,END5       ITEM MUST BE AN EXTERNAL DEFINITION
*   HERE IF NAME IS TO BE SKIPPED
END3     RES      0
         BAL,RL   NEXTITEM          GET BYTE COUNT FOR CURRENT NAME
         SLS,XT   -9                CONVERT BYTE COUNT TO HALFWORD COUNT
         CI,XT    0
         BEZ      END2              NO MORE TO SKIP
         LW,ER    XT                NUMBER OF HALFWORDS TO SKIP
         BAL,RL   NEXTITEM          GET NEXT HALFWORD
         BDR,ER   %-1               CONTINUE SKIPPING UNTIL ENTIRE
         B        END2                NAME HAS BEEN SKIPPED
END%4    RES       0
         MTH,0     1STDEF              OUTPUT THIS SYMBOL IF
         BEZ       END%3                 LOOKING FOR FIRST DEF
         B         END3                SKIP THE FIRST DEF SYMBOL
END4     RES      0
         AND,XT1  =EXTFLD
         CV,XT1   DEFEXT
         BL       END3              ENTRY IS NOT EXTERNAL, SKIP IT
         BE       END5              ENTRY IS AN EXTERNAL DEFINITION
*   HERE IF ENTRY IS AN EXTERNAL REFERENCE
         LW,XT3   0,XT              GET PREVIOUSLY ASSIGNED DECLR. NUM.
         MTW,1    DECLRNUM          INCREMENT DECLARATION NUMBER
         LW,XT2   DECLRNUM
         STW,XT2  *NXTSYMT,XT3      SAVE NEW ASSIGNMENT
         LV,XT3   ADDFLD
         STS,XT2  0,XT              REASSIGN DECLR. NUM. IN SEQUENCE
         SHIFT,XT1 EXTLOB,31
         B        END6
END5     RES      0
         LW,XT    NOWORDS           NUMBER OF DEFS
         LW,XT1   NCDITEM           STORE SYMBOL NUMBER OF DEF SYMBOL
         STH,XT1  *TEMPO,XT           IN LEFT HALF OF WORD
         AI,XT    1                 INCREMENT INDEX TO RIGHT HALF
         MTW,1    DECLRNUM          INCREMENT DECLARATION NUMBER
         LW,XT1   DECLRNUM
         STH,XT1  *TEMPO,XT         STORE DECLARATION NUMBER OF DEF
         MTW,2    NOWORDS           INCREMENT NUMBER OF DEFS
         LI,XT1   0
END6     RES      0
         AI,XT1   3                 FORM LOADER CODES OF 3, 5, OR 6
         STW,XT1  DD%TYPE             TO DECLARE EXTERNAL NAME
         LI,NBYTES 1                NUMBER OF BYTES TO OUTPUT
         LI,XT1   BA(DD%TYPE)+3     BYTE ADDRESS OF ITEM TO OUTPUT
         BAL,RL   BEDIT             OUTPUT LOADER CODE
         BAL,RL   NEXTITEM          GET BYTE COUNT FOR EXTERNAL NAME
*                                     AND FIRST EBCDIC CHARACTER
         SLS,XT   -8
         STW,XT   TEMP              SAVE CHARACTER COUNT
         AI,XW    -1                BACK UP XW TO RELOAD CT AND 1ST CHAR
END7     RES      0
         LI,NBYTES 2                NUMBER OF BYTES TO OUTPUT
END8     RES      0
         LI,XT1   BA(ACONVAL)+2     BYTE ADDRESS OF ITEMS TO OUTPUT
         BAL,RL   NEXTITEM          GET NEXT 2 BYTES TO OUTPUT
         STW,XT   ACONVAL
         BAL,RL   BEDIT             OUTPUT NEXT 2 BYTES OF EXT. NAME
         MTW,-2   TEMP              DECREASE CHARACTER COUNT BY 2
         BGZ      END7              MORE CHARACTERS TO OUTPUT
         BLZ       END%9               ALL CHARACTERS HAVE BEEN OUTPUT
*   HERE IF ONLY ONE CHARACTER REMAINS TO BE OUTPUT
         LI,NBYTES 1                NUMBER OF BYTES TO OUTPUT
         B        END8
END%9    RES       0
         MTH,0     1STDEF              CONTINUE WITH ALL EXTERNALS
         BNEZ      END2                  IF NOT LOOKING FOR FIRST DEF
END9     RES      0
         MTH,0     1STDEF              DONE PROCESSING ALL EXTERNALS
         BNEZ      END%10                IF NOT LOOKING FOR FIRST DEF
         MTH,1     1STDEF              FIRST DEF HAS BEEN OUTPUT
         LW,IOSIZE  LABELLOC
         SW,IOSIZE  TEXTCT
         AWM,IOSIZE  TEXTCT            POSITION X1 FILE BACK TO FIRST
         BAL,IORL  POSITIONX1            RECORD OF EBCDIC NAMES
         B        END%1             BACK TO PROCESS ALL EXTERNALS
END%10   RES      0
*   SEARCH THE DYNAMIC SYMBOL TABLE FOR ANY EXTERNAL REFERENCE ENTRIES
*     AND RE-ASSIGN THE EXTERNAL REFERENCE NUMBER
         LW,XT    NXSYMB            NUMBER OF SYMBOLS IN FIXED TABLE
         AW,XT    SYMT                PLUS BASE ADDRESS OF TABLE IS END
         STW,XT   TEMP                ADDRESS + 1
END10    RES      0
         MTW,-1   TEMP              POINTER TO NEXT CONTROL WORD
         LW,XT    *TEMP             LOAD ENTRY FROM FIXED SYMBOL TABLE
         BFNZ,XT  SPAFLD,END14      ONE WORD ENTRY
         AND,XT   =LPTRFLD
         BEZ      END14             ENTRY NOT USED AS A SYMBOL
         AW,XT    SYMT
         LW,XT1   0,XT              LOAD DYNAMIC SYMBOL TABLE ENTRY
         BFNZ,XT1 SPAFLD,END14      ONE WORD ENTRY
*
         LI,NBYTES 1                SET # OF ENTRIES TO PROCESS TO 1
         B        END12
*
END11    RES      0
*
*   HERE FOR COMPLEX SUM OR LIST
*
         AI,XT    2                 POINT TO NEXT CONTROL WORD
         AI,NBYTES -2          REDUCE # OF ENTRIES TO PROCESS AND BRANCH
         BGZ      END12           IF NOT OUTER-MOST LIST OR SUM
*
         AND,XT1  =LENGTHFLD        GET LENGTH OF LIST OR SUM
         AI,XT1   -2                LENGTH LESS 2 (FOR CONTROL ITEMS)
         LW,NBYTES XT1                IS NUMBER OF ENTRIES TO PROCESS
END12    RES      0
         LW,XT1   0,XT              LOAD CONTROL WORD
         BAL,RL   TYPE              GET ITEM'S TYPE
         CV,XT2   LISTET
         BE       END11             BRANCH IF ITEM IS A LIST
*
         CV,XT2   SUMET
         BE       END11             ENTRY IS A SUM
*
         CV,XT2   EXTET             SKIP THIS ITEM IF IT IS NOT AN
         BNE      END13               EXTERNAL REFERENCE
*
         LV,XT3   LENGTHFLD
         LS,XT2   0,XT              GET DECLARATION NUMBER
         LW,XT2   *NXTSYMT,XT2
         STS,XT2  0,XT              RE-ASSIGN DECLARATION NUMBER
END13    RES      0
         CALL     LENGTH            SKIP THIS ITEM AND REDUCE
         AW,XT    XT1                 COUNT BY THE NUMBER OF WORDS
         SW,NBYTES XT1                SKIPPED
         BGZ      END12             CONTINUE UNTIL ALL ENTRIES PROCESSED
END14    RES      0
         LW,XT    TEMP              ADDRESS OF CURRENT TABLE ENTRY
         CW,XT    SYMT              BASE ADDRESS OF TABLE
         BG       END10             PROCESS ENTIRE SYMBOL TABLE
*
END15    RES      0
         LW,XT    DLRCS
         STW,XT   LITCS             CONTROL SECTION FOR LITERALS
         LW,XT    NLITS             DON'T ADVANCE THE LOCATION COUNTERS
         IF,NZ
         BAL,RL   BOUND4            LOCATION COUNTERS TO WORD BOUNDARY
         FI
         LW,XT    DLRVAL
         AND,XT   =MAXDDFLD        TRIM LOCATION COUNTER
         SLS,XT   -2                CONVERT FROM BYTE TO WORD
         STW,XT   LITORG            ORIGIN FOR LITERALS
         LW,XT    NLITS             INCREASE BOTH LOCATION
         SLS,XT   2                   COUNTERS BY THE NUMBER
         AWM,XT   DLRVAL              OF WORDS REQUIRED
         AWM,XT   DDLRVAL             FOR THE LITERALS
         LI,XT    LITTABLE          ADDRESS OF WORD CONTAINING INDEX
         STW,XT   TX1                 TO FIRST LITERAL TABLE ENTRY
END16    RES      0
*   HERE TO PROCEED TO NEXT LITERAL TABLE ENTRY
         LW,XT    TX1               SAVE ADDRESS OF WORD CONTAINING
         STW,XT   TX2                 OFFSET TO NEXT LITERAL ENTRY
         LW,XT2   0,XT              LOAD OFFSET TO NEXT LITERAL ENTRY
END17    RES      0
         BEZ      END25             END OF LITERAL TABLE
         AW,XT2   SYMT              ADDRESS OF NEXT LITERAL ENTRY
         STW,XT2  TX1
         LW,XT    1,XT2
         BFZ,XT   SPAFLD,END20      ENTRY IS NOT A ONE WORD ITEM
         BFNZ,XT  SPINTFLD,END16    ENTRY IS A SPECIAL INTEGER, SKIP IT
*   HERE IF ENTRY IS A SPECIAL ADDRESS
         CV,XT    REFORSREF
         BAZ      END19             ENTRY IS NOT A REF OR SREF
*   HERE IF ENTRY IS AN EXTERNAL REF OR SREF
END18    RES      0
         LV,XT1   LENGTHFLD
         AND,XT   XT1
         LW,XT    *NXTSYMT,XT       LOAD DECLARATION NUMBER
         STS,XT   1,XT2             REASSIGN EXTERNAL DECLARATION NUMBER
         B        END16
END19    RES      0
         BFNZ,XT  DEFFLD,END16      LITERAL IS DEFINED, SKIP IT
         AW,XT    SYMT
         STW,XT   ARG               STORE POINTER TO SYMBOL TABLE ENTRY
         LW,XT    0,XT
         BFNZ,XT  SPAFLD,END22      ENTRY IS A ONE WORD ITEM
         AND,XT   =LPTRFLD
         BEZ      END23             SYMBOL IS UNDEFINED, DELETE LITERAL
         AW,XT    SYMT
         STW,XT   ARG               POINTER TO SYMBOL TABLE ENTRY
         LW,XT    0,XT
END22    RES      0
         BFZ,XT   DEFFLD,END23      SYMBOL IS UNDEFINED, DELETE LITERAL
         BAL,RL   LITSRCH           SEARCH FOR MATCH OF DEFINED VALUE
         CI,XT    0
         BEZ      END23             NO MATCH FOUND
         MTW,-4   DLRVAL            ENTRY EXISTS, DECREMENT NUMBER OF
         MTW,-4   DDLRVAL             WORDS REQUIRED FOR LITERALS
END23    RES      0
         MTW,-1   NLITS             DECREMENT NUMBER OF LITERALS
         LW,XT2   *TX1              REMOVE THE CURRENT UNDEFINED ENTRY
         STW,XT2  *TX2                FROM THE LITERAL TABLE
         B        END17
END20    RES      0
         LV,XT1   TYPEFLD+STYPEFLD  MASK FOR TYPE AND STYPE FIELDS
         CS,XT    =SYMBOL+EXTREF
         BE       END18             ENTRY IS A SINGLE EXTERNAL REFERENCE
         CS,XT    =SYMBOL+CMPLXSUM
         BNE      END16             ENTRY IS NOT A COMPLEX SUM, SKIP IT
*   HERE IF LITERAL IS A COMPLEX SUM
         AND,XT   =LENGTHFLD
         AI,XT    -2
         STW,XT   ARG               NUMBER OF ITEMS IN COMPLEX SUM
END21    RES      0
         AI,XT2   1
         MTW,-1   ARG               DECREMENT ITEM COUNT
         BLZ      END16             DONE WITH COMPLEX SUM
         LW,XT    2,XT2             LOAD NEXT SYMBOL ITEM
         LV,XT1   STYPEFLD
         CS,XT    =EXTREF
         BNE      END21             ITEM IS NOT AN EXTERNAL REFERENCE
         LV,XT1   LENGTHFLD         REASSIGN EXTERNAL DECLARATION NUMBER
         AND,XT   XT1
         LW,XT    *NXTSYMT,XT       LOAD DECLARATION NUMBER
         STS,XT   2,XT2             REASSIGN EXTERNAL DECLARATION NUMBER
         B        END21
END25    RES      0
         LW,XT    DECLRNUM          DECLARATION NUMBER CONTROL
         STW,XT   CSBASE              SECTION BASE (CONTROL SECTION 0)
         LW,IOSIZE  LABELLOC
         SW,IOSIZE  TEXTCT
         AI,IOSIZE  -1              BACKSPACE THE X1 FILE TO THE RECORD
         BAL,IORL POSITIONX1          CONTAINING THE END STATEMENT
         BAL,RL   NXTRECRD          RE-READ RECORD CONTAINING END LINE
         CALL     DEFHEXLBL         DEFINE LABEL ON END STATEMENT
         LW,XT    DLRVAL            SAVE ADDRESS ASSIGNED
         STW,XT   ENDADDR             TO END LABEL
         BAL,RL   LCLDLTE           DELETE LOCAL SYMBOL TABLE
         BAL,RL   MAXLOC
         LI,XT2   1                 START WITH CONTROL SECTION NUMBER 1
END26    RES      0
         STW,XT2  CS
         BAL,RL   GETCSADD          GET ADDRESS OF CONT SECT TABLE ENTRY
         LW,XT    MAXDD,XT2
         AND,XT   =MAXDDFLD         GET MAX VALUE OF LOAD LOC COUNTER
         STW,XT   MAXDD+1,XT2       SAVE MAX %% VALUE FOR PASS 1
         MTW,0    SOCW%FLG
         BNEZ     END40
*
         LV,XT1   CSTFLD+PTFLD
         LS,XT    CST,XT2           MERGE IN CST AND PT
         STW,XT   TEMP1
         LB,XT    TEMP1
         CI,XT    DSTYPE
         BE       END27             CONTROL SECTION IS A DSECT
*   HERE IF CONTROL SECTION IS A CSECT OR PSECT
         LI,XT1   BA(TEMP1)         BYTE ADDRESS OF 1ST ITEM TO OUTPUT
         LI,NBYTES 4                NUMBER OF BYTES TO OUTPUT
         B        END31
END27    RES      0
         LI,XT1   BA(TEMP)+3        BYTE ADDRESS OF 1ST ITEM TO OUTPUT
         LI,NBYTES 5                NUMBER OF BYTES TO OUTPUT
         LW,RL    DSNUM,XT2
         SLS,RL   DSNUMLOB-31
         LW,XT2   NOWORDS           NUMBER OF DEFS
END28    RES      0
         AI,XT2   -2
         CH,RL    *TEMPO,XT2        FIND DSECT SYMBOL NUMBER IN
         BNE      END28               THE TABLE OF DEF NUMBERS
         AI,XT2   1
         LH,RL    *TEMPO,XT2        LOAD DECLARATION NUMBER OF DEF
         STB,RL   TEMP1             DECLARATION NUMBER OF DSECT
         LI,ER    0                 CLEAR DECLARATION NUMBER SO THAT
         STH,ER   *TEMPO,XT2        NO 'DEFINE EXT. DEF.' IS OUTPUT
         LW,XT2   DECLRNUM
         CI,XT2   256
         BL       END30             DECLARATION NUMBER IS ONE BYTE
         SLS,RL   -8                STORE SECOND BYTE (HIGH ORDER PART)
         STW,RL   TEMP                OF DECLARATION NUMBER
         LI,XT1   BA(TEMP)+2        BYTE ADDRESS OF 1ST ITEM TO OUTPUT
         LI,NBYTES 6                NUMBER OF BYTES TO OUTPUT
END30    RES      0
         STB,XT   0,XT1             STORE CONTROL SECTION TYPE
END31    RES      0
         BAL,RL   BEDIT             OUTPUT CONTROL SECTION DECLARATION
         MTW,1    DECLRNUM          INCREMENT DECLARATION NUMBER
         LW,XT2   CS
         AI,XT2   1
         CW,XT2   MAXCSECT
         BLE      END26
*   OUTPUT EXTERNAL DEFINITION VALUES
         LW,XT    DECLRNUM
         CI,XT    256               BRANCH IF HIGHEST DECLARATION
         BL       END32               NUMBER FITS IN ONE BYTE
         MTW,1    NAMENUM           INDICATE 2 BYTE DECLARATION NUMBERS
END32    RES      0
*   HERE TO OUTPUT 'DEFINE EXTERNAL DEFINITION'
         MTW,-1   NOWORDS           DECREMENT NUMBER OF DEFS
         BLZ      END40               UNTIL ALL ARE OUTPUT
         LW,XT    NOWORDS           NUMBER OF DEFS
         MTW,-1   NOWORDS
         LH,RL    *TEMPO,XT         LOAD DECLARATION NUMBER OF DEF
         BEZ      END32             BRANCH IF A DSECT
         STW,RL   ACONVAL
         LI,NBYTES  2               NUMBER OF BYTES TO OUTPUT
         LI,XT1   BA(ACONVAL)+2     BYTE ADDRESS OF 1ST ITEM TO OUTPUT
         SW,XT1   NAMENUM           ADJUST ADDRESS FOR 2-BYTE DECLNUM
         AW,NBYTES NAMENUM          ADJUST BYTE COUNT ALSO
         LI,RL    DEFEXTCD          LOADER CODE FOR EXTERNAL DEFINITION
         STB,RL   0,XT1
         BAL,RL   BEDIT             OUTPUT THE DECLARATION NUMBER
         LW,XT    NOWORDS
         LH,XT    *TEMPO,XT         GET SYMBOL NUMBER OF DEF
         LW,XT1   *SYMT,XT          LOAD ENTRY FROM FIXED SYMBOL TABLE
         BFNZ,XT1 SPAFLD,END35      ONE WORD ENTRY
         AND,XT1  =LPTRFLD
         BNEZ     END34             OFFSET TO DYNAMIC SYMBOL TABLE
         BAL,RL   EXPEND            SYMBOL IS UNDEFINED, OUTPUT AN
         B        END32               'EXPRESSION END'
END34    RES      0
         LW,XT    XT1
END35    RES      0
         AW,XT    SYMT
         STW,XT   ARG               STORE POINTER TO SYMBOL TABLE ENTRY
         BAL,RL   GENERATE3         GENERATE AN EXTERNAL DEFINITION
*
*   IF 'SD' SPECIFIED, OUTPUT TYPE INFO. FOR DEF AT THIS POINT
*
         MTW,0    SD%FLAG
         BEZ      END32             BRIF NO SD.
*
*        THE FOLLOWING TEST FOR ADDRESSES IS HERE FOR META-SYMBOL
*           COMPATIBILITY - IT DOESN'T MAKE A GREAT DEAL OF SENSE
*           OTHERWISE.
*
         LW,XT1   *ARG              CONTROL WORD FROM SYMT
         CALL     TYPE
         CV,XT2   SPADDRET
         IF,NE                 -80- DOIF NOT SPECIAL ADDRESS
         CV,XT2   ADDRET
         BNE      END32             FALL THRU IF ADDRESS
*
         FI                    -80-
*
*        HAVE AN ADDRESS SYMBOL - NEED 'SD%TYPE' FOR SYMBOL, ITS
*           RESOLUTION, AND THE DECLARATION NUMBER ASSIGNED TO THE DEF.
*
         AND,XT1  L(ARFLD)
         SHIFT,XT1  ARLOB,31        AR RIGHT-ADJ. IN XT1
*
*        NEED THE SYMBOL NUMBER IN ORDER TO FETCH ASSOCIATED 'SD%TYPE'
*
         LW,XT2   NOWORDS
         LH,XT    *TEMPO,XT2        SYMBOL NO. IN XT
*
*        NOW SNEAK IN AND GET THE DECLARATION NUMBER - SET IT UP
*           IN 'ACONVAL'.
*
         AI,XT2   1
         LH,RL    *TEMPO,XT2
         LW,NBYTES  NAMENUM         (REMEMBER THIS ONE)
         IF,EZ                 -90- DOIF 1-BYTE DECL. NO.
         SLS,RL   8                 JOG IT LEFT
         FI                    -90-
         STW,RL   ACONVAL
*
*        BACK TO BUILDING THE TYPE CONTROL ---
*
         LB,XT    *SDTT,XT          SD%TYPE (POSITIONED)
         AW,XT    XT1                 + AR
         AV,XT    SDEXTSYMCD**8       + LOAD CONTROL
         STH,XT   ACONVAL             = FINISHED ITEM IN ACONVAL
*
*        DUMP TO BINARY, AND GO ON TO NEXT
*
         AI,NBYTES  3               (3 OR 4)
         LI,XT1   BA(ACONVAL)
         CALL     BEDIT
         B        END32
DEFEXTCD EQU      10                LOADER CODE FOR EXTERNAL DEFINITION
*
*   INITIALIZATION FOR THE GENERATION PASS ONLY
*   INITIALIZE VARIABLES
*
END40    RES      0
         LV,XT    3**(31-DEFLOB)
         STW,XT   PASSDEF           INITIALIZE FOR GENERATION PASS
         MTW,1    PASS
         MTW,+1   SEGMENT#          BUMP OVERLAY SEGMENT NUMBER
         LI,XT1   -NCLEARS1         NUMBER OF VARIABLES TO CLEAR
         B        DEFGEN1           BEGIN GENERATION PASS
*
*   E N D   O F   G E N E R A T I O N   P A S S
*
ENDGEN   RES      0
         STW,IORL ROOTRTN           SAVE RETURN ADDRESS TO ROOT
         LW,XT    NLITS             BOUND4 IF THERE ARE LITERALS
         BEZ      END54
         BAL,RL   BOUND4
END54    RES      0
         LW,XT    DLRVAL
         AND,XT   =MAXDDFLD         TEST LITERAL C.S. FOR SAME
         SLS,XT   -2                  SIZE AS IN
         CW,XT    LITORG              DEF PASS
         BE       END55             SAME
         LI,XT    0                 SET NLITS SO THAT A CONTROL SECT.
         STW,XT   NLITS               ERROR WILL BE REPORTED
END55    RES      0
         MTW,-1   LSTCT
         BLZ      END53             BRANCH IF OPERAND FIELD WAS BLANK
         BEZ      END52             BRANCH IF SINGLE OPERAND
         BAL,ER   EERR              REPORT OPERAND ERROR
END52    RES      0
         BAL,RL   EDITV             EDIT THE 'END' OPERAND VALUE
         MTW,0    SOCW%FLG
         IF,EZ                      DON'T BOTHER W/ START IF SOCW
         LI,NBYTES  1               NUMBER OF BYTES TO OUTPUT
         LI,XT1   BA(STARTCD)       ADDRESS OF BYTE TO OUTPUT
         BAL,RL   BEDIT             OUTPUT A 'DEFINE START' LOAD ITEM
         BAL,RL   GENERATE3         OUTPUT THE START ADDRESS
         FI
END53    RES      0
         BAL,RL   LCLDLTE           DELETE LOCAL SYMBOL TABLE
         BAL,RL   PRINT             PRINT THE END LINE
END51    RES      0
         LW,XT    LITTABLE          GET LINK TO NEXT LITERAL
         BEZ      END60             NO MORE LITERALS
         LW,RL    *SYMT,XT
         STW,RL   LITTABLE          SAVE NEXT LINK
         AW,XT    SYMT
         AI,XT    1
         LW,XT1   0,XT              GET CONTROL WORD OF VALUE
         BAL,RL   TYPE              GET LITERAL'S TYPE
         SW,XT    KLINE             OFFSET FROM KLINE
         LV,XT1   ~LOCFLD           MASK FOR ALL BUT LOC FIELD
         LS,XT    DD%TYPE           MERGE IN ITEM'S TYPE
         STW,XT   TEMPO             PSEUDO ECT ENTRY
         LI,XT    TEMPO
         STW,XT   VALPTR            POINTER TO PSEUDO ECT ENTRY
         LI,XT    1
         STW,XT   VALCNT            NUMBER OF VALUE ENTRIES
         STW,XT   FLDCNT            NUMBER OF FIELD ENTRIES
         LI,XT    LITFS
         STW,XT   FLDPTR            POINTER TO LITERAL FIELD SIZE
         BAL,RL   GENERATE1         GENERATE A LITERAL
         B        END51
*
LITFS    SPIECT   LITSIZE           ADDRESS OF LITERAL FIELD SIZE
LITSIZE  SPECINT  32                LITERAL'S FIELD SIZE
STARTCD  DATA,1   13                CONTROL BYTE FOR START ADDRESS
         BOUND    4
*
END60    RES      0
         BAL,RL   MAXLOC
         B        *ROOTRTN          RETURN TO ROOT FOR DGEND OVERLAY
         PAGE
*
*   N E X T I T E M
*        THIS SUBROUTINE OBTAINS THE NEXT ITEM (HALFWORD) FROM THE
*          RECORD(S) CONSISTING OF EBCDIC SYMBOL NAMES. THIS ROUTINE
*          IS USED BY THE END PROCESSOR ONLY.
*
*        INPUT:   XW CONTAINS AN INDEX TO THE HALFWORD TO BE LOADED
*                 INBUF CONTAINS THE EBCDIC RECORD
*
*        OUTPUT:  XT CONTAINS A HALFWORD ITEM TO PROCESS
*                 XW CONTAINS AN INDEX TO THE HALFWORD FOLLOWING THE
*                   ONE LOADED INTO XT
*
*        CALL:    BAL,RL  NEXTITEM
*
*        USES REGISTERS
*                 XT
*                 XW
*
NEXTITEM RES      0
         STW,RL   LAST
         CI,XW    HWX1SIZE
         BL       NXTITEM1          INDEX IS WITHIN RECORD
         LW,XT    NBYTES
         BAL,RL   NXTRECRD          READ NEXT RECORD OF EBCDIC NAMES
         LW,NBYTES  XT
NXTITEM1 RES      0
         LH,XT    X1BUF,XW          GET HALFWORD FROM INPUT BUFFER
         AI,XW    1                 INCREMENT INDEX TO NEXT HALFWORD
         B        *LAST             RETURN
         END

