*
*        SDEVICE  ROUTINE
*
         SYSTEM   BPM
         SYSTEM   SIG7FDP
*
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
*
*        REFS AND DEFS
*
         REF      SYNTAX,MODGEN,COREALLOC,WRITELM
         REF      READSTRG,SYMBPTR,SYMBDEV,SYMBTYPE,SYMBCOUNT
         REF      GETPGPTR,#PAGES,DCT16TEMP,DCTSIZE,ENDUSED
         REF      #MXSTRM,#RBTS,DCT4TEMP,GETPGS,NOROOM
         REF      TBFLGSPTR
         REF      PASS2ABRT
         REF      SYMBACT,SYMBVAL
         REF      FAUTPTR
         DEF      SDEVICE
         PAGE
*
*        KEYWORDS
*
KWD      COM,32,8,24 AF(1),AF(2),AF(3)
FOP      COM,1,7,8 AF(1),AF(2),AF(3)
KWDTBLO  EQU      %
         DATA     KWDTBL-KWDTBLO
         FOP      0,0,3             0 FIND LEFT'('
         FOP      1,0,9             1 KWD
         FOP      1,0,10            2 PROCKWD
         FOP      1,0,8             3 INTEROPT
         FOP      0,1,1             4 GOTO 1
         FOP      1,3,20            5 GETSTRG (IN)
         FOP      0,1,19            6 DWTBLPTR AT 1,R5
         FOP      0,3,1             7 GOTO 3
         FOP      1,3,20            8 GETSTRG (OUT)
         FOP      0,3,19            9 DWTBLPTR AT 3,R5
         FOP      0,14,6            10 LOOK FOR,  IF NONE GO TO 14
         FOP      1,0,9             11 LOOK FOR KWD ('KEEP'/'OPCON')
         FOP      1,0,10            12 PROCKWD
         FOP      0,10,1            13 GO TO 10
         FOP      1,3,4             14 LOOK FOR )
         FOP      0,6,21            15 INCREMENT ADDRESS @ 6,R5
         FOP      1,0,7             16 LOOK FOR , OR END OF COMMAND
         FOP      0,0,1             17 GO TO 0
         FOP      1,3,20            18 GETSTRG (NCTL)
         FOP      0,5,19            19 DWTBLPTR AT 5,R5
         FOP      0,3,1             10 GO TO 3
         DATA,2   0
KWDTBL   EQU      %
         KWD      'MXST',1,MXSLOC
         KWD      'IN  ',8,5        KEYWORD GO TO 5
         KWD      'OUT ',8,8        KEYWORD GO TO 8
         KWD      'NCTL',8,18       KEYWORD GO TO 18
         TEXT     'KEEP'
         GEN,8,8,16 X'70',X'10',06  STORE BYTE '10' INTO 6,R5
         TEXT     'OPCON'
         GEN,8,8,16 X'70',X'80',06  STORE BYTE '80' INTO 6,R5
LKWDTBL  EQU      %
         DATA     0                 NO DEFAULTS
KWDPTR   GEN,15,17 LKWDTBL-KWDTBL,KWDTBLO
         PAGE
*
*        SKELETON TEMPSTACK
*
DYNAM    EQU      %
INPTR    EQU      %-DYNAM
         DATA     0                 HIGHEST LOC FOR GOTTEN PAGE
         DATA     0                 STARTING LOC FOR IN
OUTPTR   EQU      %-DYNAM
         DATA     0                 HIGHEST LOC FOR OUT
         DATA     0                 STARTING LOC FOR OUT
NCTLPTR  EQU      %-DYNAM
        DATA      0                 HIGHEST LOC FOR NCTL
         DATA     0                 STARTING LOC FOR NCTL
KEEPOPTR EQU      %-DYNAM
         DATA     0                 STARTING LOC FOR KEEP/OPCON IN BYTES
MXSLOC   EQU      %-DYNAM
         GEN,1,15,16 1,0,0
#DYNAM   EQU      %-DYNAM
         PZE      WRITERROR
         PAGE
SDEVICE  EQU      %
         LW,R1    DCTSIZE,R3        GET # DCTS TO  INDICATE # DEVICES
         SLS,R1   -1                DIVIDE IN HALF FOR SPACE FOR SYMBTYPE TABLE
         LW,SR2   ENDUSED,R3
         AI,SR2   1
         STW,SR2  SYMBPTR,R3        START OF SYMB TEXT DEVICE TYPE TABLE
         AW,SR2   R1
         SLS,R1   -1                CUT IN 1/4 FOR BYTE TABLE
         STW,SR2  SYMBTYPE,R3       TYPEMNEMONIC INDEX FOR DEVICE TYPE
         AW,SR2   R1
         AI,SR2   1
         SLS,SR2  -1
         SLS,SR2  1
         STW,SR2  SYMBACT,R3        ROOM FOR ACTUAL DEVICES
         AW,SR2   DCTSIZE,R3        SHOULD BE ENOUGH FOR DW
         CW,SR2   GETPGPTR,R3
         BL       %+3
         LI,R2    GETPGPTR+1
         BAL,R1   GETPGS
         STW,SR2  ENDUSED,R3
         LW,R1    =X'08000001'      GET ONE PAGE
         CAL1,8   R1
         BCS,8    NOROOM
         LI,R1    510               SR2= START OF GOTTEN PAGE
         LI,R2    0
         STW,R2   *SR2,R1           ZERO OUT
         BDR,R1   %-1
         STW,SR2  DYNAM+1
         STW,SR2  INSTART
         AI,SR2   83                42 AVAILABLE ENTRIES
         STW,SR2  DYNAM
         AI,SR2   1
         STW,SR2  DYNAM+3
         STW,SR2  OUTSTART
         AI,SR2   83
         STW,SR2  DYNAM+2
         AI,SR2   1
         STW,SR2  DYNAM+5
         STW,SR2  NCTLSTRT
         AI,SR2   83
         STW,SR2  DYNAM+4
         AI,SR2   1
         STW,SR2  KEEPOPCON         START OF KEEP/OPCON FLAG BYTES
         SLS,SR2  2                 CHANGE TO BYTE ADDRESS
         STW,SR2  DYNAM+6           STORE INTO STARTING ADDRESS
         AI,SR2   168               ADD 42 WORDS TO START
         SLS,SR2  -2
         AI,SR2   1
         STW,SR2  WORKSTART         BEG AVAILABLE SPACE
         AI,SR2   250               END OF AREA
         STW,SR2  WORKEND
*        GO TO SYNTAX TO READ COMMAND
         LI,R1    #DYNAM            SIZE OF TEMP STACK
         LI,R2    DYNAM             START OF TEMP STACK
         LW,R4    KWDPTR            KEYWORD PTR
         BAL,SR4  SYNTAX
*        R5=ADDRESS OF GENERATED TABLE
         LW,D2    INPTR+1,R5
         STW,D2   INEND
         LW,D2    OUTPTR+1,R5
         STW,D2   INEND+1
         LW,D2    NCTLPTR+1,R5
         STW,D2   INEND+2
         LW,D2    #RBTS,R3          GET #RBTS DEFINED
         MI,D2    3                 FOR 3 X#RBTS OF 0 DEFAULT FOR MXSTRM
         LW,SR1   MXSLOC,R5         GET MXSTRM VALUE
         BGZ      %+3
         STW,D2   #MXSTRM,R3        NOT SPECIFIED
         B        CHKENT
         CW,SR1   D2                MUST BE > = 3 X#RBTS
         BL       ERR1              ERROR DEFAULT TO 3X#RBTS
         CI,SR1   128               MUST BE < = 128
         BG       ERR2              NO ERROR SET TO 128
         STW,SR1  #MXSTRM,R3
CHKENT   EQU      %
         LI,R7    0
         LI,R1    1                 INDEX FOR LOOP THRU 3 TYPES OF TABLES
         LW,D3    DCT16TEMP,R3      GET ADDRESS OF DCT16 TABLE
         LW,D4    DCT4TEMP,R3       GET ADDRESS OF DCT4 TABLE
         LW,R6    SYMBCOUNT,R3      #SYMBDEVICES CTR.
TABLOOP  LW,SR3   INSTART-1,R1
         CW,SR3   INEND-1,R1
         BGE      DNTBL
ONELOOP  LD,SR1   *SR3              GET ENTRY
         BEZ      DNTBL
         LW,SR4   =X'FFFFD9C2'
         CH,SR4   SR1               IS IT RB
         BE       IGENT             YES
         AND,SR2  =X'FF000000'
         LW,R2    DCTSIZE,R3        GET #DCTS
         AI,R2    -1
         LD,D1    *D3,R2            GET DCT16 ENTRY
         SLD,D1   24
         CD,SR1   D1                IS IT THIS DCT
         BE       %+3               YES
         BDR,R2   %-4               NO SEE IF ANOTHER
         B        ERR3              NOT DEFINED IN DCT TABLES
         LB,SR4   *D4,R2            R2=DCT INDEX R4=DEVTYPE INDEX
         CI,R1    3                 IS IT NCTL
         BE       SKPNCTL
         LI,R4    0
         CI,R1    2                 IF AN OUTPUT SYMBIONT NEED
         BNE      CONTINU           TO MERGE KEEP/OPCON FLAGS
         LB,R4    *KEEPOPCON,R7
         OR,R1    R4
         AI,7     1
CONTINU  EQU      %
         SLS,R1   8                 SHIFT FOR TEMP STORE
         OR,R2    R1                OR WITH DCT INDEX
         SLS,R1   -8                SHIFT BACK FOR INDEX
         EOR,R1   R4                RESTORE R1
SKPNCTL  EQU      %
         MTW,1    SYMBVAL,R3
         LW,R4    SYMBVAL,R3        SAVE YYNDD
         LW,D1    SYMBACT,R3        FOR LATER OPLABEL CHECK
         STD,SR1  *D1,R4
         SAS,SR1  -16               GET ONLY YY
         LW,D1    SYMBPTR,R3        GET START OF SYMB DEVICE TYPE TABLE
         LW,D2    SYMBTYPE,R3       TYPE INDEX FOR SYMB DEVICE TABLE
         LW,R4    SYMBDEV,R3        GET # SYMB DEVICE TYPE
         BEZ      %+4               1ST TIME THROUGH
         CH,SR1   *D1,R4
         BE       ENTHERE
         BDR,R4   %-2
         MTW,1    SYMBDEV,R3        INCREMENT SYMBCOUNT
         LW,R4    SYMBDEV,R3
         STH,SR1  *D1,R4            STORE YY IN DEVICE TYPE TBL
         STB,SR4  *D2,R4            STORE DEVICE TYPE BYTE
ENTHERE  STB,R4   R2                R2=INDEX INTO TYPE,0,IN,OUT,NCTL,DCT INDEX
         CI,R1    3
         BNE      %+2
         OR,R2    =X'00000500'      BIT 4 AND BIT 7 (5) NCTL
         STW,R2   *WORKSTART,R6
         MTW,1    SYMBCOUNT,R3      INCRE # SYMB DEVICES
IGENT    LW,R6    SYMBCOUNT,R3      GET # SYMB DEVICES
         AI,SR3   2
         CW,SR3   INEND-1,R1        ONE TABLE DONE
         BL       ONELOOP           NO
DNTBL    AI,R1    1
         CI,R1    3                 ALL DONE ALL TABLES
         BLE      TABLOOP           NO
*                                   YES
         LW,R6    SYMBCOUNT,R3
         BEZ      ERR4              ERROR NO SYMBIONTS
         AI,R6    3
         AW,R6    #MXSTRM,R3        ADD #MXSTRM
         STW,R6   WTBSIZE
         AI,R6    1
         SLS,R6   -1                WORDS FOR HW TABLES
         STW,R6   HTBSIZE
         AI,R6    1
         SLS,R6   -1                WORDS FOR BYTE TABLES
         STW,R6   BTBSIZE
         B        %+2
         PZE      WRITERROR         ERROR RETURN FOR COREALLOC MODGEN
         LI,D1    200               REFDEF SIZE FOR M:SDEV
         LI,D2    -1                SECT0 SIZE
         BAL,SR4  COREALLOC         ALLOCATE CORE
*                                   SR1 IS START OF DATA AREA
         BAL,10   MODGEN
         STW,SR1  MODBEGIN
         TEXTC    'M:SDEV1'
         TEXTC    'SSTAT1'
         AW,SR1   BTBSIZE
         TEXTC    'SRET1'
         AW,SR1   WTBSIZE
         TEXTC    'SNDDX1'
         STW,SR1  TABSTARTS
         AW,SR1   BTBSIZE
         TEXTC    'SSIG1'
         AW,SR1   BTBSIZE
         TEXTC    'SCNTXT1'
         AW,SR1   HTBSIZE
         TEXTC    'SQHD1'
         AI,SR1   1
         TEXTC    'SQTL1'
         AI,SR1   1
         TEXTC    'SQUE1'
         AW,SR1   BTBSIZE
         TEXTC    'SYMX1'
         STW,SR1  TABSTARTS+1
         AW,SR1   BTBSIZE
         TEXTC    'STB:TYP1'
         STW,SR1  TABSTARTS+2
         LW,D1    SYMBCOUNT,R3
         AW,D1    #MXSTRM,R3
         AI,D1    2+3               ONLY 2 ADDED
         SLS,D1   -2
         AW,SR1   D1
         STW,SR1  MODEND
         B        %+1               OUT OF MODGEN
         LW,D1    #MXSTRM,R3
         BEZ      ABSDEF
         LW,D2    #MXSTRM,R3
         AI,D2    1+1
         SLS,D2   -1                HALFWORD SIZE
         BAL,10   MODGEN
         TEXTC    'STH:FLG1'
         AW,SR1   D2
         TEXTC    'STH:SUS1'
         AW,SR1   D2
         TEXTC    'STB:Q1'
         AI,D2    1
         SLS,D2   -1
         AW,SR1   D2                BYTE SIZE
         TEXTC    'STB:LNK1'
         STW,SR1  TABSTARTS+3
         AW,SR1   D2
         STW,SR1  MODEND
         TEXTC    'E2'              INSURE ADEQUATE SPACE
         B        %+1               OUT OF MODGEN FOR LINK TABLE
         LI,R4    0
         LI,R6    1
         STB,R6   *TABSTARTS+3,R4
         AI,R4    1
         AI,R6    1
         CW,R4    D1
         BL       %-4
ABSDEF   BAL,10   MODGEN
         TEXTC    'MXSTRM0'
         LW,D1    WTBSIZE           GET#SYMB+3+MXSTR
         AI,D1    -1                -1 (#SYM+2+MXST)
         TEXTC    'SNDDXSIZ0'
         STW,D1   R2
         B        %+1               OUT OF MODGEN
*        ROUTINE FOR STORING VALUES IN SNDDX,SYMX,STB:TYP PROCESSING OF INTERMED
         LW,SR2   TABSTARTS         SNDDX START
         LW,SR3   TABSTARTS+1       SYMX START
         LW,SR4   TABSTARTS+2       STB:TYP START
         LW,D1    SYMBTYPE,R3       SYMB DEVICE TYPE INDEX TABLE
         STB,R2   *SR2              0 ENTRY OF SNDDX=COUNT
         LW,R6    #MXSTRM,R3        GET #MXSTRM FOR DISPLACEMENTINTO TABLES
         AI,R6    1
         LI,R1    0                 PROCESSING # SYMB DEVICES
NXTENT   LW,R2    *WORKSTART,R1     GET ENTRY
         STB,R2   *SR2,R6           STORE DCT INDEX INTO SNDDX
         SLS,R2   -8
         STB,R2   *SR3,R6           STORE IN/OUT/NCTL IN SYMX
         SLS,R2   -16               GET INDEX INTO INTER DEVICE TYPE TABLES
         LB,R4    *D1,R2            GET DEVICE TYPE TYPEMNEMONIC INDEX
         STB,R4   *SR4,R6           STORE IN STB:TYP TABLE
         AI,R4    1
         LW,D2    TBFLGSPTR,R3      GET FLAG FOR DEVICE
         LB,D2    *D2,R4
         SLS,D2   -6                CHECK BITS 0 AND 1 ONLY. IF BIT 0
         CI,D2    1                 IS RESET AND BIT 1 IS SET IT'S A
*                                   LISTING DEVICE
         BNE      NXTENT1C          BRANCH IF NOT
         LB,D2    *SR3,R6           GET CURRENT SYMX SETTING
         CI,R4    X'10'             IS THIS AN XP (OCP) DEVICE
*                                   NOTE: THIS IS HARD-CODED USE OF
*                                   DEVICE TYPE INDEX
         BNE      NXTENT1A          BRANCH IF SOME OTHER LISTING DEVICE
         OR,D2    X30
         B        NXTENT1B
NXTENT1A OR,D2    X40
NXTENT1B STB,D2   *SR3,R6           STORE BACK IN SYMX
NXTENT1C EQU      %
         AI,R6    1
         AI,R1    1
         CW,R1    SYMBCOUNT,R3      ALL DONE ENTRIES
         BL       NXTENT
         LI,R4    3
         STB,R4   *SR3,R6           STORE IN NEXT TO LAST SYMX ENTRY
         AI,R6    1
         LI,R4    2
         STB,R4   *SR3,R6           STORE IN LAST SYMX ENTRY
         LW,SR1   MODEND
         LW,D1    MODEND
         AI,D1    1
         SLS,D1   -1
         SLS,D1   1
         SW,D1    MODBEGIN
         BAL,10   MODGEN
         TEXTC    'M:SDEVSZ0'
         B        %+1
         LI,D3    MSDEV
         BAL,SR4  WRITELM           WRITE M:SDEV
         B        %+2
*        ALLOCATE CORE AND WRITE SG:PNT MODULE
         PZE      WRITERROR
         LI,D1    25
         LI,D2    -1
         BAL,SR4  COREALLOC
         LW,D1    SYMBDEV,R3        GET # SYMB DEVICE TYPES
         BAL,10   MODGEN
         TEXTC    'SV:TYM0'
         TEXTC    'SH:SYMT1'
         LW,R2    FAUTPTR,R3
         AW,D1    *R2
         TEXTC    'SV:FTYM0'
         STW,SR1  SR2
         AI,D1    1+1               0TH ENTRY +1 FOR HW
         SLS,D1   -1
         AW,SR1   D1
         TEXTC    'E2'              INSURE ADEQUATE SPACE
         B        %+1               OUT OF MODGEN
         LW,R1    SYMBDEV,R3
         LW,D2    SYMBPTR,R3
         LH,D1    *D2,R1
         STH,D1   *SR2,R1
         BDR,R1   %-2
         LW,R1    SYMBDEV,R3
         AW,R1    *R2               PLUS # OF FAUTHS
         LW,R2    *R2
         CI,R2    0
         BE       WRITERROR-1
         LW,D2    FAUTPTR,R3        GET POINTER
         LW,D1    *D2,R2            GET CHARACTERS
         SLS,D1   -16               JUSTIFY IT
         STH,D1   *SR2,R1           STOREIT
         AI,R1    -1
         BDR,R2   %-4
         LI,D3    SGPNT
WRITERROR BAL,SR4 WRITELM
         LI,R1    -#DYNAM
         MSP,R1   *R0
         LW,R1    =X'09000002'      FREE BOTH THIS PAGE AND FAUTH PAGE
         CAL1,8   R1
         B        READSTRG
         PAGE
ERR1     EQU      %                 #MXSTRM < 3X#RBTS ON SYSTEM
         STW,D2   #MXSTRM,R3
         M:PRINT  (MESS,ERR1M)
         B        CHKENT
ERR1M    TEXTC    '*** MXSTRM TOO SMALL - SET TO 3*#RBTS'
ERR2     EQU      %                 #MXSTRM > 128
         LI,SR1   128
         STW,SR1  #MXSTRM,R3
         M:PRINT  (MESS,ERR2M)
         B        CHKENT
ERR2M    TEXTC    '*** MXSTRM TOO LARGE - SET TO 128'
ERR3     EQU      %                 YYNDD UNKNOWN
         OR,SR2   =X'00404040'
         STW,SR1  ERR3M+1
         STW,SR2  ERR3M+2
         M:PRINT  (MESS,ERR3M)
         B        IGENT
ERR3M    TEXTC    '***XXXXXXXX UNKNOWN-OPTION IGNORED'
ERR4     M:PRINT  (MESS,ERR4M)
         M:PRINT  (MESS,ERR4M2)
         B        PASS2ABRT         ERROR ABORT
ERR4M    TEXTC    '*** NO SYMBIONT DEVICES DEFINED'
ERR4M2   TEXTC    '*** PASS2 UNABLE TO CONTINUE'
         PAGE
*        DATA AREA
KEEPOPCON DATA    0
WORKSTART DATA    0                 WORKING AREA AVAILABLE
WORKEND  DATA     0                 END OF WORKING AREA
INSTART  DATA     0                 START OF INTABLE
OUTSTART DATA     0                 START OF OUTTABLE
TABSTARTS EQU     %
NCTLSTRT DATA     0                 START OF NCTL
INEND    DATA     0,0,0             LAST USED ADDRESS OF ABOVE TABLES
*                                   DURING MODGEN FROM TABSTARTS ARE ADD OF
*                                   SNDDX,SYMX,STB:TYP,STB:LNK
WTBSIZE  DATA     0                 WORDS NEED FOR #SYMB+3+MXSTRM IN WDS
HTBSIZE  DATA     0                 IN HALFWORDS
BTBSIZE  DATA     0                 IN BYTES
MODEND   DATA     0                 END OF MODULE
MODBEGIN DATA     0
MSDEV    TEXTC    'M:SDEV'
SGPNT    TEXTC    'SG:PNT'
X30      DATA     X'30'
X40      DATA     X'40'
         END

