         SYSTEM   SIG7
         SYSTEM   BPM
         DEF      DEFCM,PATCH
         REF      M:EI,M:EO
R0       EQU      0
R1       EQU      1
R2       EQU      2
R3       EQU      3
R4       EQU      4
R5       EQU      5
R6       EQU      6
R7       EQU      7
SR1      EQU      8
SR2      EQU      9
SR3      EQU      10
SR4      EQU      11
D1       EQU      12
D2       EQU      13
D3       EQU      14
D4       EQU      15
DEFCM    EQU      %
HEAD     RES      12
         DATA     0
TREE     RES      24
         RES      100
SEQNAME  DATA,16  0                 RFDFSTK KEY
DUMDEF   DATA     X'04100000'       TYPE
         DATA     0                 VALUE AT BYTE RESOLUTION
         DATA     X'01000000'       RESOLUTION
         TEXTC    ':PN'             NAME
RFDFBSZE DATA     0                 BYTES IN RFDFSTK
RFDFMAX  DATA     0                 UPPER LIMIT OF RFDFSTK
TX:PNDAT TEXTC    ':PNDATA'
TXHEAD   TEXTC    'HEAD'
TXTREE   TEXTC    'TREE'
XF0000   DATA     X'F0000'
X100000  DATA     X'100000'
DEFCOM   EQU      %
         M:OPEN   M:EO,(KEYED),(DIRECT),(KEYM,11)
         M:READ   M:EI,(BUF,HEAD),(SIZE,48),(WAIT),(KEY,TXHEAD)
         LI,R1    X'83'
         STB,R1   HEAD
         M:READ   M:EI,(BUF,TREE-1),(SIZE,48),(WAIT),(KEY,TXTREE)
         LI,R1    12                CHANGE SIZE OF TREE TO 12 WDS
         STW,R1   TREE-1
         LW,R1    TREE+6
         SLS,R1   -16
         M:GP     1
         LW,R7    SR2
         LW,R2    TX:PNDAT          GOING TO A :PNDATA CORE LIBRARY
         LW,R3    =X'FFFFFF00'
         CS,R2    M:EO+23
         BNE      DEFCOM3           NO
         LW,R2    TX:PNDAT+1
         CW,R2    M:EO+24
         BNE      DEFCOM3           NO
         LCI      4
         LM,R2    DUMDEF
         STM,R2   *R7               PUT :PN DEF ENTRY IN RFDFSTK
         LI,R3    3
         LB,R2    M:EO+23,R3        N FROM :PNDATA
         LI,R3    15
         STB,R2   *R7,R3            INTO DEF ENTRY
         LW,R2    TREE+5            DATA SIZE
         SLS,R2   -16
         SLS,R2   3                 IN BYTES
         STW,R2   1,R7              PUT DATA SIZE INTO :PN DEF
         AI,R1    4                 ADD SIZE OF :PN DEF ENTRY
         AI,R7    4                 MAKE ROOM FOR :PN DEF ENTRY
         LW,R2    HEAD+5
         SLS,R2   -16
         CW,R1    R2                MAX RFDF SIZE LARGER
         BLE      %+2               YES
         STH,R1   HEAD+5            INCREASE RFDF SIZE OF :PN
         STH,R1   TREE+6
DEFCOM3  STW,SR2  RFDFMAX           RFDFSTK ORG.
         AWM,R1   RFDFMAX           ESTABLISH RFDFSTK LIMITS
         SLS,R1   2                 BYTE SIZE OF REF/DEF STACK
         STW,R1   RFDFBSZE
         LB,R1    TREE
         STB,R1   SEQNAME
         LB,R2    TREE,R1
         STB,R2   SEQNAME,R1
         BDR,R1   %-2               COPY SEQ NAME TO MAKE RFDFSTK KEY
         MTB,1    SEQNAME
         LI,R4    0
         STH,R4   TREE+5            00 SIZE 0
         STH,R4   TREE+7            01 SIZE 0
         STH,R4   TREE+8            EXP SIZE 0
         STH,R4   TREE+9            10 SIZE 0
         LW,R1    RFDFMAX
         SW,R1    SR2
         SLS,R1   -9                COMPUT NO. OF ADDITIONAL PAGES NEED
         OR,R1    =X'08000000'      GET PAGE ORDER CODE
         LW,D1    SR2
         CAL1,8   R1                GET ADDITIONAL PAGES
         M:READ   M:EI,(BUF,*R7),(SIZE,*RFDFBSZE),(WAIT),(KEY,SEQNAME)
         LW,R1    D1                BASE OF RFDFSTK
         LI,R2    X'60000'          CONTROL SECTION CODE
         LW,R3    XF0000
         LI,R5    1
         LW,R7    X100000
         LW,SR1   DUMDEF+3          03:PN
         LW,SR2   =X'FFFFFF00'
DEFCOM2  CS,R2    *R1               IS THIS A CSECT
         BNE      DEFCOM1           NO
         STS,R7   *R1               YES-SET EVAL BIT
         STH,R4   *R1,R5            SET SIZE AT 0
DEFCOM1  CS,SR1   3,R1              03:PN ENTRY
         BNE      %+3               NO
         LW,R6    1,R1              YES-PUT CORE LIBRARY DATA SIZE
         STW,R6   HEAD+7                IN HEAD+7 (BYTE RESONTION)
         LB,R6    *R1               ADVANCE TO NEXT ENTRY
         AW,R1    R6                ADVANCE TO NEXT ENTRY
         CW,R1    RFDFMAX           LOOKED AT ALL ENTRYS
         BL       DEFCOM2           NO
         M:WRITE  M:EO,(BUF,HEAD),(SIZE,48),(WAIT),(ONEWKEY),;
                  (KEY,TXHEAD)
         LB,R1    M:EO+23
         STB,R1   SEQNAME
         STB,R1   TREE
         LB,R2    M:EO+23,R1
         STB,R2   SEQNAME,R1
         STB,R2   TREE,R1
         BDR,R1   %-3               COPY OUTPUT NAME TO TREE AND KEY
         MTB,1    SEQNAME
         LB,R2    SEQNAME
         STB,R1   SEQNAME,R2        ZERO TRAILING CHAR FOR RFDFSTK KEY
         M:WRITE  M:EO,(BUF,TREE-1),(SIZE,48),(WAIT),(ONEWKEY),;
                  (KEY,TXTREE)
         M:WRITE  M:EO,(BUF,*D1),(SIZE,*RFDFBSZE),(WAIT),(KEY,SEQNAME),;
                  (ONEWKEY)
         M:CLOSE  M:EI
         M:CLOSE  M:EO,(SAVE)
         CAL1,9   1
PATCH    RES      50                PATCH AREA
         END      DEFCOM

