home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / cpm / bye5 / kmdrsx.lbr / KMDRSX.MQC / KMDRSX.MAC
Text File  |  1986-08-05  |  4KB  |  183 lines

  1. ; KMDRSX.MAC 07/22/86
  2. ;
  3. ; Copyright (c) 1986 Jim Lopushinsky
  4. ;
  5. ; This RSX was written to add 2 features to KMD for CP/M+ RCP/Ms.
  6. ; It will attach to any version of KMD running under BYE509 or
  7. ; newer.  See the DOC file for details.
  8.  
  9.     .z80
  10.  
  11. NO    EQU    0
  12. YES    EQU    NOT NO
  13.  
  14.  
  15. TOUCH    EQU    YES        ; Yes, to write first record back
  16.                 ;   during a KMD S or L option to force
  17.                 ;   an update time-stamp.
  18. maxdrv    equ    'C'        ; Max drive for 'Touching' for KMD S
  19.  
  20. bdos    equ    5
  21. fcb    equ    5ch
  22. wheel    equ    3eh        ; ZCPR wheel
  23. maxusr    equ    3fh        ; ZCPR max user
  24.  
  25. ;
  26. ; RSX header
  27. ;
  28.     dw    0,0,0
  29. entry:    jp    ftest
  30. next:    jp    0
  31. prev:    dw    0
  32. remove:    db    0ffh
  33.     db    0
  34.     db    'KMDRSX  '
  35.     db    0,0,0
  36.  
  37. ftest:
  38.     pop    hl        ; Get return address
  39.     push    hl
  40.     ld    a,(next-1)    ; Get our page
  41.     cp    h        ; Are we called from above?
  42.     jp    c,next        ; Ignore calls from higher RSX's
  43.     ld    a,(fcb+1)    ; Get option
  44.     cp    'R'        ; Is it receive?
  45.     jp    z,dor
  46.  
  47.      IF    TOUCH
  48.     cp    'S'        ; Is it send?
  49.     jp    z,dos
  50.     cp    'L'        ; Is it library send?
  51.     jp    z,dos
  52.      ENDIF            ; TOUCH
  53.  
  54. delus:                ; Here to delete this RSX.  We will no
  55.                 ;   longer intercept anything
  56.     call    remrsx        ; Delete this RSX
  57.     jp    bdos        ; Have to do this, because our vectors
  58.                 ;   will no longer be in place
  59.  
  60. dor:                ; Process Receive file
  61.     push    de
  62.     push    bc
  63.     ld    de,delrsx
  64.     ld    c,60
  65.     call    next        ; BYE will delete all RSX's (including
  66.                 ;   this one)
  67.     pop    bc
  68.     pop    de
  69.     jp    bdos        ; Onward.  We will no longer intercept
  70.  
  71.      IF    TOUCH
  72. dos:                ; Process Send file
  73.     ld    (sflag),a    ; Set send file flag
  74.     ld    a,(wheel)    ; Get wheel byte
  75.     or    a        ; Is it set?
  76.     jp    nz,delus    ; Go delete this RSX if set.
  77.     push    de
  78.     push    bc
  79.     ld    de,scbpb
  80.     ld    c,49
  81.     call    next        ; Return address of SCB for later calls
  82.     ld    (scbbase),hl    ; Save SCB
  83.     pop    bc
  84.     pop    de
  85.     ld    hl,stest    ; entry for subsequent intercepts
  86.     ld    (entry+1),hl    ; Modify JP FTEST to JP STEST
  87.  
  88. stest:                ; Here to test function during send
  89.     ld    a,c        ; Get function
  90.     cp    33        ; Random read?
  91.     jp    z,isread    ; Jump if read
  92.     cp    20        ; Read file?
  93.     jp    nz,next        ; Ignore if not
  94.     ld    a,(sflag)    ; Get option
  95.     cp    'S'        ; Is it send?
  96.     jp    nz,next        ; Ignore if not
  97.     ld    a,c
  98. isread:
  99.     ld    (function),a    ; Save read function
  100.     ld    hl,(scbbase)    ; Get SCB address
  101.     ld    l,0e0h        ; Point to user number
  102.     ld    a,(hl)        ; Get it
  103.     ld    hl,(maxusr)    ; Point to ZCPR max user
  104.     cp    (hl)        ; Out of range?
  105.     jp    nc,delus    ; Ignore if user > max user
  106.     ld    a,(de)        ; Get drive code
  107.     dec    a        ; Default?
  108.     jp    p,isdrive
  109.     ld    hl,(scbbase)
  110.     ld    l,0dah        ; Point to current drive
  111.     ld    a,(hl)        ; Get it
  112. isdrive:
  113.     cp    maxdrv-40h    ; Out of range?
  114.     jp    nc,delus    ; Go delete this RSX and continue
  115.     push    de        ; Save FCB addr
  116.     ld    hl,ourfcb
  117.     ld    b,36
  118.     call    move        ; Move a copy of FCB for us
  119.     pop    de        ; Restore FCB addr
  120.     call    next        ; Attempt read file
  121.     or    a        ; Any errors?
  122.     jp    z,noerror    ; Jump if no errors
  123.     push    hl        ; Save error code
  124.     call    remrsx        ; Remove this RSX
  125.     pop    hl        ; Restore error code
  126.     ld    a,l
  127.     ld    b,h
  128.     ret
  129. noerror:
  130.     ld    hl,(scbbase)
  131.     ld    l,0e7h        ; Point to error mode
  132.     push    hl        ; Save addr for later
  133.     ld    (hl),0ffh    ; Set error mode to return so that we don't
  134.                 ;   abort in case of read-only file.
  135.     ld    de,ourfcb    ; Point to our FCB
  136.     ld    a,(function)    ; Get read function
  137.     inc    a        ; Convert to write function
  138.     ld    c,a
  139.     call    next        ; Write first record back to cause an
  140.                 ;   update time stamp.
  141.     pop    hl        ; Get addr of error mode
  142.     ld    (hl),0        ; Reset error mode
  143.     call    remrsx        ; Remove this RSX (no longer needed)
  144.     ld    hl,0        ; Restore read return codes
  145.     ld    a,h
  146.     ld    b,a
  147.     ret            ; Back to KMD
  148.      ENDIF            ; TOUCH
  149.  
  150. remrsx:
  151.     push    de
  152.     push    bc
  153.     ld    de,0
  154.     ld    c,59
  155.     call    next        ; Loader will delete this RSX
  156.     pop    bc
  157.     pop    de
  158.     ret
  159.  
  160.      IF    TOUCH
  161. move:
  162.     ld    a,(de)
  163.     ld    (hl),a
  164.     inc    de
  165.     inc    hl
  166.     dec    b
  167.     jp    nz,move
  168.     ret
  169.      ENDIF            ; TOUCH
  170.  
  171. delrsx:        db    11        ; Delete RSX's function for BYE
  172.  
  173.      IF    TOUCH
  174. sflag:        db    0        ; Send option flag
  175. scbbase:    ds    2        ; Address of SCB
  176. scbpb:        db    3ah        ; To return SCB address
  177.         db    0        ; Get op
  178. ourfcb:        ds    36        ; Our FCB
  179. function:    ds    1        ; Read function
  180.      ENDIF            ; TOUCH
  181.  
  182.     end
  183.