 
*  ED:/DSLNK   40 col   Feb / 08 / 92
 
 
*  TWDSLK - no following data - modify offset on fly
*---------------------------------------------------
*  DSRDIR - direct re-entry without search
*         - use only on same invocation of L/S module
 
*  Status Block Definition
 
SCLEN  EQU   >8354
CRULST EQU   >83D0
STADDR EQU   >83D2
 
*** DSR Opcodes
 
* DSROPN EQU   0
* DSRCLS EQU   1
* DSREAD EQU   2
* DSRITE EQU   3
* DSRLOD EQU   5
* DSRSAV EQU   6
 
*** PAB IMAGE IN RAM
 
PAB    EQU   $              PAB image
OPCODE EQU   PAB
FLAGS  EQU   PAB+1
BUFF   EQU   PAB+2
LRL    EQU   PAB+4
CHCNT  EQU   PAB+5
RECNUM EQU   PAB+6
SCROFF EQU   PAB+8
NAMLEN EQU   PAB+9
FILDSC EQU   PAB+10
 
 
*  BLWP Entry Vectors
*--------------------
 
TWDSLK DATA DSRWS,LNKDSR
DSRDIR DATA DSRWS,LNKDIR
 
*  Data stored at OPEN
*---------------------------
*  Use only on same L/S call
 
DSRDAT EQU  $
SAVVER DATA 0
SAVCRU DATA 0
SAVENT DATA 0
SAVSCN DATA 0
SAVNPT DATA 0
 
 
*  Full DSRLNK code
*------------------
 
LNKDSR EQU   $
       LWPI  GPLWS            Use GPL workspace
       LI    R1,SCNAME        Byte saver
       MOV   *R1,R9           Get name length pointer
       BL    @SETRDA          Set VDP read at device name in PAB
       MOVB  @VDPRD,R7        Save total length & advance
       SRL   R7,8             As a word
       SETO  R6               Initialize counter
       LI    R2,FAC           Use FAC as buffer
LNK$LP INC   R6               Next byte and count in R6
       C     R6,R7            Last character ?
       JEQ   LNK$LN           Yes, escape loop
 
       MOVB  @VDPRD,*R2       Copy name to buffer
       CB    *R2+,@PERIOD     Is it the separator ?
       JNE   LNK$LP           Not yet
 
*  Name found to first delimiter
 
LNK$LN MOV   R6,R6            How long was it ?
       JEQ   LNKERR           Null must be error
 
       CI    R6,8             Name too long ?
       JGT   LNKERR           Yes
 
       INC   *R1              Advance to next part of name
       A     R6,*R1           After first part in SCNAME
       MOV   R6,@SCLEN        Set device name length
 
*  Search for DSR - multiple RS232 included
 
       CLR   R1               Initialize multiple card search
       LI    R12,>0F00        Initialize DSR search
CRUSTT EQU   $-2
NOROM  SBZ   0                Current ROM off
       CLR   @CRULST
       AI    R12,>0100        Next ROM
CRUINC EQU   $-2
CRUEND EQU   $+2
       CI    R12,>2000        All done ?
       JEQ   NODSR            Not found then
 
       MOV   R12,@CRULST      Save CRU base
       SBO   0                ROM on
       LI    R2,>4000         DSR ROM address
       CB    *R2,@HAA         Ident byte of DSR
       JNE   NOROM            Not a valid DSR header
 
       AI    R2,8             Gets pointer for DSR name chain
DSRTYP EQU   $-2
       JMP   SGO2             And compares device
 
*  Do not use R6 in SGO loop - multiple RS232
 
SGO    MOV   @STADDR,R2       Looking for name
       SBO   0                Reset DSR on for error path  ?????
 
*  Look for device name in this DSR ROM
 
SGO2   MOV   *R2,R2           Last name in this ROM ?
       JEQ   NOROM            Try next then
 
       MOV   R2,@STADDR       Save pointer ro next name
       INCT  R2               Advance to entry pointer
       MOV   *R2+,R9          Save it & advance to length byte
 
*  Check device name
 
       MOV  @SCLEN,R5         Fetch device name length as word
       CB   @SCLEN+1,*R2+     Check length in DSR - LSB only needed
       JNE  SGO               Bail out now
 
       LI    R3,FAC           Device name buffer
NAME1  CB    *R3+,*R2+        Check against name in buffer
       JNE   SGO              Not the one
 
       DEC   R5               Count down
       JNE   NAME1            More to do
 
       INC   R1               Next card
 
*  Save DSR entry values
 
       LI    R11,DSRDAT       Point to data list
       MOV   R1,*R11+         SAVVER
       MOV   R12,*R11+        SAVCRU
       MOV   R9,*R11+         SAVENT
       MOV   @SCNAME,*R11+    SAVSCN
       MOV   @SCLEN,*R11      SAVNPT
 
*  Execute DSR
 
EXEDSR BL    *R9              Execute DSR
       JMP   SGO              Special error return for 2 x RS232
       SBZ   0                ROM off
 
*  Good exit
 
       LWPI  DSRWS            Normal return
       SZCB  R12,R15          Clear error indicator
       RTWP
 
*  Error exit
 
LNKERR EQU   $
NODSR  LWPI  DSRWS            Restore workspace
       SOCB  R12,R15          Flag error
       RTWP
 
*  Data and WSp
 
DSRWS  EQU   $-24
       BYTE  >20              EQU bit mask as R12 MSByte
HAA    BYTE  >AA              In R12  LSByte
       DATA  >0,>0,>0         R13 - R15
 
 
*  DSR direct entry for record R/W
*---------------------------------
 
LNKDIR EQU  $
       LWPI GPLWS             As for internals of DSRLNK
 
*  Restore values at DSR entry
 
       LI   R11,DSRDAT
       MOV  *R11+,R1         SAVVER
       MOV  *R11+,R12        SAVCRU
       MOV  *R11+,R9         SAVENT
       MOV  *R11+,@SCNAME    SAVSCN
       MOV  *R11,@SCLEN      SAVNPT
 
*  Engage DSR ROM and execute
 
       SBO   0                Turn on ROM
       JMP   EXEDSR           Execute DSR
 
 
