*
*    TABLE GENERATION DIRECTIVES
*
:DOT     COM,8,8,8,8       BA(AF(1))-BA(DOT),AF(2),AF(3),AF(4)
:CLST    COM,8             DA(AF(1))-DA(DOT)
:CDW     COM,8,24,8,8,8,8  AF(1),AF(2),AF(3),0,AF(4),AF(5)
 TITLE '** REMOTE ASSIST STATION (RAS) RESIDENT HANDLER **'
MONPROC  SET      1
UTSPROC  SET      1
S69PROC  SET      1
         SYSTEM   UTS
*
*        REGISTER ASSIGNMENTS
*
R0       EQU      0
R1       EQU      1
R2       EQU      2
R3       EQU      3
R4       EQU      4
R5       EQU      5
R6       EQU      6
R7       EQU      7
R8,SR1   EQU      8
R9,SR2   EQU      9
R10,SR3  EQU      10
R11,SR4  EQU      11
R12,D1   EQU      12
R13,D2   EQU      13
R14,D3   EQU      14
R15,D4   EQU      15
*
*        INTERNAL REFERECNES
*
         REF      IOQ15             USER'S NUMBER
         REF      CIT1
         REF      RAS:DOL
         REF      DCT5              DEVICE FLAGS (BUSY,XFER,ETC..)
         REF      Y2
         REF      IOSERCK,M21,IOQ6
         REF      COMLIST
         REF      IOQ13
         REF      E:CEC             CONTROL-Y EVENT
         REF      M:UC
         REF      J:JIT
         REF      UX:JIT
         REF      RAS:CBP           CURRENT BUFFER POINTER
         REF      E:CBK             BREAK RECEIVED
         REF      S:CUN,Y15
         REF      M16,DCT13,M24
         REF      DCT3,DCT7
         REF      IOQ8
         REF      SH:RNM
         REF      T:DLR1            IN SCHED
         REF      IOQ9
         REF      IOSCU
         REF      T:RUE
         REF      IOQ5
         REF      E:ABRT
         REF      DOUBLEONE
         REF      UH:FLG
*
*        EXTERNAL DEFINITIONS
*
         DEF      RAS               PRE-PROCESSOR
         DEF      T:RESCNCT
         DEF      RASCU             POST PROCESSOR
*
*0       8         15        23        31
*****************************************
*X'F4'   *        7*         DCT INDEX  *   RAS:DOL
*****************************************
*BRK CNT *   T:RESCNCT WA              *
****************************************
*                  * RAS RESOUCE INDEX *
****************************************
*USR #   *         *                   *    RAS:CBP
****************************************
         PAGE
*
*        RAS DEVICE PRE-PROCESSOR
*
*
************************************************************************
*    COMMAND LIST OFFSETS FOR MAINTENANCE CONSOLE                      *
************************************************************************
*
*
RAS      EQU      %
         BAL,R9   RAS:PRE           PRE-PROCESS THE BUFFER
         BAL,R10  COMLIST           ESTABLISH DOT TABLE ADDRESS
DOTTY    EQU      %
DOT      SET      %
         :DOT     TYRE,90,0,3       0(READ) RETRY=READ / FOLLOW=NEWLINE
         :DOT     TYWD,15,1,2       1(WRIT) RETRY=WRIT / FOLLOW=NEWLINE
         :DOT     TYNL,2,2,0        2(NL)   RETRY=NL   / FOLLOW=NULL
*
*
TYRE     :CLST    RDTYE
TYWD     :CLST    WRBNC
TYNL     :CLST    TNL
         PAGE
************************************************************************
*    COMMAND DOUBLE WORDS FOR COMMAND LISTS                            *
************************************************************************
         BOUND    8
*
FNC      EQU      X'1E'             ICE,HTE,IUE,SIL (NO COMMAND CHAIN)
FC       EQU      X'2E'             ICE,HTE,IUE,SIL (COMMAND CHAIN)
*
WRBNC    :CDW     5,0,FNC,2         WRITE BINARY
*
RDTYE    :CDW     134,0,FNC,2       READ TYPEWRITER WITH CONTROL
*
TYB      :CDW     20,0,FNC,0        SET BREAK WATCH
*
TNL      :CDW     5,BA(Y15),FNC,0,1 WRITE NEW LINE
MCVT     COM,8    AF(1)-RAS
*
MCVTB    EQU      %
         MCVT     RASCU0            CLEANUP FROM READ OP
         MCVT     RASCU0            CLEANUP FROM WRIT OP
         MCVT     RASCU3            EXIT TO IOQ FROM N/L FOLLOW ON
         BOUND    4
         PAGE
*
*        RAS DEVICE POST PROCESSING
*
RASCU    EQU      %
         BAL,R9   IOSERCK           EXAMINE STATUS FOR AN ERROR
         B        RAS:ERR           ANALYZE FAULT
         CW,R5    Y2                IS THIS A BREAK EVENT
         BANZ     RASBRK            YEP
         LB,R6    IOQ5,R3           GET CURRENT FUNCTION STEP
         LB,R7    MCVTB,R6          GET ROUTINE ADDRESS
         B        RAS,R7            DISPATCH TO PROPER ROUTINE
RASCU0   EQU      %
         LB,R6    IOQ15,R3          GET USER'S NUMBER
         STB,R6   RAS:CBP           ****TEMP - REMEMBER USER # ****
         LOAD,R8  UX:JIT,R6         GET USER'S PHYSICAL PAGE OF JIT
         SLS,R8   9                 INTO A PAGE WA
         AI,R8    M:UC-J:JIT
         LW,R9    M21               DCB MASK
         CS,R8    IOQ6,R3           IS THIS DCB=M:UC
         BE       RASCU5            YES - NO LINE EDITING - NO N/L
         LI,R13   0                 RESET N/L DETECTED CELL
         LH,R4    IOQ9,R3           BYTE CNT OR # COMMANDS USED
         LW,R5    IOQ8,R3           BA OF BUFFER OR FIRST CDW
         BGZ      RASCU4            NO DATA CHAIN
         AND,R5   M16
         SLS,R5   1                 INTO A WA
RASCU1   EQU      %
         LW,R6    M24               BA MASK
         AND,R6   0,R5              EXTRACT BA OF BUFFER
         LI,R12   X'FFF'
         AND,R12  1,R5              MASK TO EXTRACT BYTE COUNT
         BAL,R9   RAS:EDIT          EDIT THE LINE
         LW,R9    1,R5              GET FLAGS
         BGZ      RASCU2            AT END OF DATA CHAIN LIST
         AI,R5    2                 BUMP WA POINTER TO CDW'S
         BDR,R4   RASCU1
RASCU2   EQU      %
         LI,R12   X'6000'           ASSUME NO N/L FOUND
         AI,R13   0                 TRUE
         BEZ      IOSCU             YEP
RASCU3   LI,R12   1                 NORMAL COMPLETION - NO FOLLOW ON
         LI,R13   0                 NO MESSAGE TO GO OUT
         STB,R13  RAS:DOL+1         RESET BREAK COUNTER
         STB,R13  CIT1,R2           FREE CHANNEL ON NORMAL COMPLETE
         B        IOSCU
RASCU4   EQU      %
         LW,R12   R4                MOVE BYTE COUNT
         LW,R6    R5                MOVE BA OF BUFFER
         LI,R9    RASCU2            RETURN POINT
         B        RAS:EDIT          GO EDIT BUFFER
         PAGE
*
*        IF DELTA IN CONTROL - DECREMENT RETURNING BYTE COUNT
*
*        OTHERWISE EXIT TO IOSCU
*
RASCU5   EQU      %
         MTB,0    IOQ5,R3           ARE READING
         BNEZ     RASCU3            NO - DONT BOTHER
         LH,R6    UH:FLG,R6         GET USER'S FLAGS
         CI,R6    DIC               IS DELTA IN CONTROL
         BAZ      RASCU3            NOPE
         MTW,0    IOQ8,R3           DID WE DATA CHAIN
         BLZ      RASCU3            CANT HELP YOU DELTA
         MTH,-1   IOQ9,R3           DROP COUNT BY ONE
         B        RASCU3            AND EXIT TO IOSCU
         PAGE
*
*        CONNECT MC USER TO RAS DEVICE
*
T:RESCNCT EQU     %
         LW,R6    RAS:DOL+2         GET INDEX TO RESOURCE TABLES
         LH,R6    SH:RNM,R6         GET NAME
         LI,R1    1
         STH,R1   R6                SET UP
         STW,R6   M:UC,R1           FOR OPENDEV TO FIND THIS
         B        T:DLR1            AND EXIT TO SCHED
         PAGE
*
*        BREAK SIGNAL RECEIVED FROM THE RAS
*
RASBRK   EQU      %
         LC       DCT5,R1           WERE WE DOING I/O
         BCR,1    RASCU3            WERENT DOING I/O
         LB,R6    RAS:DOL+1         GET BRK COUNTER
         AI,R6    1                 INCREMENT BY ONE
         STB,R6   RAS:DOL+1
         CI,R6    4                 AT MAX
         BL       RASBRK1           NO
         LI,R9    0
         STB,R9   RAS:DOL+1         ERASE COUNTER
         LI,R6    E:CEC             CONTROL-Y EVENT
         B        %+2
RASBRK1  EQU      %
         LI,R6    E:CBK             BREAK EVENT
         BAL,R9   RAS:REPORT        GO REPORT IT
         LI,R12   X'6000'           FOLLOW ON
         LI,R13   0                 NO MSG
         B        IOSCU             RETRUN TO I/O CLEANUP
         PAGE
*
*        REPORT EVENT ON RAS USER
*
RAS:REPORT EQU    %
         PUSH     16,R0
         LB,R5    RAS:CBP           ALWAYS NEED USER NUMBER
         BAL,R11  T:RUE             ISSUE EVENT
         PULL     16,R0
         B        *R9               RETURN TO CALLER
         PAGE
*
*        RECEIVED AN ERROR FROM THE RAS TERMINAL
*
RAS:ERR  EQU      %
         LB,R9    DCT3,R1           GET DEVICE ERROR FLAGS
         CI,R9    X'18'             DID SIO FAIL / TIMEOUT
         BAZ      RASRTRY           NO - JUST RETRY OPERATION
         LI,R6    E:ABRT            YES - NEED TO DUMP USER OFF
         BAL,R9   RAS:REPORT        GO DO IT
RAS:ERR1 EQU      %
         LI,R12   X'C008'
         LI,R13   RASERRMSG
         B        IOSCU
*
*
RASERRMSG TEXTC  'MC DEVICE NOT RESPONDING'
*
*
         PAGE
*
*        EDIT OUTGOING BUFFER
*
RAS:PRE  EQU      %
         BAL,R8    RAS:SET
         LB,R8    IOQ5,R3           CURRENT FUNCTION STEP
         CI,R8    1                 ARE WE WRITING
         BNE      *R9               NO - RETURN
         LH,R4    IOQ9,R3           BYTE CNT OR # OF CDWS
         LW,R6    IOQ8,R3           BA OF BUFFER OR FIRST CDW
         BLZ      *R9               DATA CHAIN - FORGET IT
         LW,R7    R6                COPY BA OF BUFFER TO R7
         AW,R7    R4                ADD BYTE COUNT
         AI,R7    -1
         LI,R5    0                 BLANK COUNTER
RAS:PRE1 LB,R8    0,R7              GET A BYTE
         CI,R8    ' '               IS BLANK
         BNE      PRE:STOP          NO
         AI,R5    1                 BUMP COUNTER
         AI,R7    -1                KEEP BACKING UP
         CW,R7    R6                DONT PASS END OF BUFFER
         BG       RAS:PRE1          KEEP GOING
PRE:STOP EQU      %
         SW,R4    R5                SUBTRACT TRAILING BLANK COUNT
         BGZ      %+2               COUNT IS OKAY
         LI,R4    1                 WELL - SEND AT LEAST ONE OF EM
         STH,R4   IOQ9,R3           REPLACE THE COUNT
         B        *R9               AND RETURN
         PAGE
*
*        SET UP BREAK CONTROL TO THE RAS DEVICE
*
RAS:SET  EQU       %
         MTB,0     RAS:DOL+2           DID WE SEND IT YET
         BGZ      *R8               YEP
         LI,R0    DA(TYB)
         SIO,R0   11                SEND IT
         MTB,7    RAS:DOL+2         POST FLAG
         B        *R8               AND EXIT
         PAGE
*
*        EDIT THE INCOMING BUFFER TO REMOVE DELETED CHARACTERS, HONOR
*        LINE DELETION..ETC...
*
RAS:EDIT EQU      %                 BASE BUFFER BA POINT
         LW,R8    R6                BASE PAGE BA REMEMBERED
         LW,R7    R6                COPY DEST BA TO R7
RAS:EDIT1 LB,R8   0,R7              GET A BYTE
         CI,R8    '@'               IS A DELETED CHAR
         BE       RAS:EDIT3         YES - DONT MOVE IT
         STB,R8   0,R6              OKAY - MOVE IT
         AD,R6    DOUBLEONE         BUMP BOTH POINTERS ON A MOVE
RAS:EDIT2 CI,R8   8                 WAS AN EOM
         BE       RASRTRY           YES - RETRY ENTIRE LINE
         CI,R8    X'15'             IS N/L CHAR
         BNE      %+2               NO
         AI,R13   1                 YES - FLAG IT
         BDR,R12  RAS:EDIT1         FINISH UP
         B        *R9               ALL DONE
RAS:EDIT3 EQU     %
         AI,R6    -1                RETREAT THE BUFFER OUTPUT POINTR
         CW,R6    R8                DID WE GO TOO FAR
         BGE      %+2               NOPE
         LW,R6    R8                YES - HOLD AT BUFFER START
         AI,R7    1                 ADVANCE INPUT STRING POINTER
         B        RAS:EDIT1         AND KEEP EDITING
         PAGE
*
*        HIT AN EOM
*
RASRTRY  EQU      %
         LI,R12   X'C008'           RETRY AND TYC
         B        IOSCU             GO ENTER I/O CLEANUP
         END

