home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / BEEHIVE / ZSUS / ZSUS002.LBR / LBREXT29.LBR / SLUOPEN.ZZ0 / SLUOPEN.Z80
Text File  |  1989-10-13  |  3KB  |  152 lines

  1. ;
  2. ; LULIB Module: LUOPEN
  3. ; Author: Richard Conn
  4. ; Date: 8 August 85
  5. ; LULIB Version: 1.0
  6. ; LULIB Module Version: 1.0
  7. ;
  8.     public    luopen,ludate,lumdate
  9. ;
  10. ;    LUOPEN opens a file within a library for reading.  It locates
  11. ; the file and loads the appropriate buffers in the LUD for following
  12. ; reads.
  13. ;    On input, DE = ptr to LUD and HL = ptr to FN.FT
  14. ;    On output, A is return code:
  15. ;        0     OK
  16. ;        0FFH  File Not Found
  17. ;
  18. ;    Side Effect: DMA Address is set to TBUFF
  19. ;
  20. ; OCTOBER 14, 1989.  Added anothe 2-byte buffer, LUMDATE, to store the
  21. ; modify date from the LBR member.  The create date is still stored in
  22. ; LUDATE.  Howard Goldstein
  23. ;
  24. ; March 25, 1988, special version for obtaining date information,
  25. ; now resembles SYSLIB4's SLUOPEN except that the DRI-format date
  26. ; is extracted and stored in the public 2-byte buffer LUDATE.
  27. ; Because of the new "@afncm" external, SYSLIB4 is required for
  28. ; linkage completion.
  29.  
  30. ;                        Bruce Morgen
  31. ;
  32. ;    Externals
  33. ;
  34.     extrn    f$open,r$read,setdma,@afncmp
  35.  
  36. bdose    equ    5
  37.  
  38.     include    luddef.lib
  39.  
  40. luopen:
  41.     push    hl        ; save regs
  42.     push    de
  43.     push    bc
  44.     ld    (file),hl    ; save ptr to file name
  45.     ld    hl,tbuff
  46.     call    setdma
  47.     ld    hl,ludfcb    ; offset to FCB
  48.     add    hl,de
  49.     ex    de,hl        ; DE = FCB
  50.     push    hl        ; save ptr to LUD
  51.     ld    c,(hl)        ; get length of directory
  52.     inc    hl
  53.     ld    b,(hl)
  54.     ld    hl,0        ; read directory in (record 0)
  55. loop:
  56.     call    r$read        ; random read
  57.     jr    nz,error    ; file not found if error
  58.     push    de        ; save key regs
  59.     push    bc
  60.     call    scan        ; scan for file name match
  61.     pop    bc        ; restore key regs
  62.     pop    de
  63.     jr    z,match
  64.     inc    hl        ; pt to next record
  65.     dec    bc        ; count down length of dir
  66.     ld    a,b        ; done?
  67.     or    c
  68.     jr    nz,loop
  69. error:
  70.     pop    hl        ; restore LUD ptr
  71.     or    0ffh        ; set 0FFH
  72. done:
  73.     pop    bc        ; restore regs
  74.     pop    de
  75.     pop    hl
  76.     or    a        ; set flags
  77.     ret
  78. ;
  79. ;  Match - HL pts to entry
  80. ;    Copy index and length into LUD
  81. ;
  82. match:
  83.     ld    (ludent),hl    ; save ptr to LUD entry
  84.     ld    de,luidx    ; offset to index
  85.     add    hl,de        ; HL pts to index
  86.     pop    de        ; DE pts to LUD
  87.     inc    de        ; DE pts to index in LUD
  88.     inc    de
  89.     ld    bc,4        ; copy index and length into LUD
  90.     ldir            ; copy
  91.     inc    hl
  92.     inc    hl
  93.     push    de
  94.     ld    de,ludate
  95.     ld    c,4
  96.     ldir
  97.     pop    de
  98.     ld    hl,(ludent)    ; get ptr to LUD entry
  99.     inc    hl        ; pt to file name
  100.     ld    c,11        ; 11 bytes to copy
  101.     ldir            ; copy
  102.     xor    a        ; A=0
  103.     jr    done
  104. ;
  105. ;  Scan TBUFF for file name
  106. ;  If found, A=0 and HL pts to entry
  107. ;  If not found, A=0FFH
  108. ;
  109. scan:
  110.     push    hl        ; save regs
  111.     ld    hl,tbuff    ; pt to buffer
  112.     ld    c,4        ; 4 entries possible
  113. scan1:
  114.     ld    a,(hl)        ; check for active entry
  115.     or    a        ; 0=yes
  116.     jr    nz,scanxt
  117.     push    hl
  118.     inc    hl        ; pt to name
  119.     ld    de,(file)    ; pt to file name
  120.     ld    b,11        ; 11 bytes
  121.     push    bc
  122.     ex    de,hl
  123.     call    @afncmp
  124.     pop    bc
  125.     jr    nz,scanlp2
  126.     pop    hl        ; we have a match - pt to entry with HL
  127.     pop    af        ; flush old HL
  128.     xor    a        ; return with zero for match
  129.     ret
  130. scanlp2:
  131.     pop    hl        ; pt to current
  132. scanxt:
  133.     ld    de,32        ; pt to next
  134.     add    hl,de
  135.     dec    c        ; count down
  136.     jr    nz,scan1
  137.     pop    hl        ; restore HL
  138.     or    0ffh        ; set no match
  139.     ret
  140. ;
  141.     dseg
  142.  
  143. ;  Buffers
  144. ;
  145. file:    ds    2        ; pointer to FN.FT
  146. ludent:    ds    2        ; pointer to LUD entry
  147. ludate:    ds    2        ; DRI-format create date
  148. lumdate:
  149.     ds    2        ; DRI-format modify date
  150.  
  151.     end
  152.