; TITLE "SLUDIR - Syslib 4.0" NAME ('LUDIR') ;================================================================= ; The Libraries, Version 4, (C) 1989 by Alpha Systems Corp. ;----------------------------------------------------------------- ; Author : Harold F. Bower ; Derived from SLUDIR.Z80 by Richard Conn ; Date : 17 Sep 89 ; Version : 1.2 ; Module : SLUDIR ; Abstract: This module contains the routine LUDIR which stores ; selected directory entries from a library in a memory ; buffer. It accepts an ambiguous file name reference and ; an LUD pointer (as provided by LUINIT), and it builds a ; listing of names in memory. This listing is structured as: ; DEFB 'FILENAME' ; DEFB 'TYP' ; DEFW START_INDEX ; DEFW LENGTH ; DEFW CRC ; ... ; repeated as necessary ; DEFB 0 ; indicates end of list ; Revision: ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ; Module Entry Points PUBLIC LUDIR ; From SYSLIB Get.. EXT F$OPEN, R$READ, SETDMA ; Definitions LENTSZ EQU 17 ; Size of dir entry ; 11 - fir FN.FT ; 2 - for Index ; 2 - for Length ; 2 - for CRC BDOSE EQU 5 ; Vector to CP/M, ZRDOS, P2DOS, etc TBUFF EQU 0080H ; Default buffer LUDFCB EQU 17 ; Offset from LUD starting address .Z80 CSEG ;=============================================================== ; NAME - LUDIR ; Entry: DE - Addresses a LUD ; HL - Addresses a filename and type ; BC - Points to a memory buffer ; Exit : A = 0, Zero Flag Set (Z) if Ok ; A = 0FFH, Zero Clear (NZ) if Memory Buffer overflow ; Uses : AF ; Special Requirements: NOTE that a side effect is that the ; DMA address is set to 0080H by this routine ;=============================================================== LUDIR: PUSH HL ; save HL LD HL,TBUFF CALL SETDMA ; Set default DMA address POP HL PUSH HL PUSH DE PUSH BC LD A,(BDOSE+2) ; get upper base page of system SUB 10 ; pt to below ZCPR3 LD (TPAEND),A ; set end ptr LD (FILE),HL ; save ptr to file name LD (BUFFER),BC ; save ptr to memory buffer LD HL,LUDFCB ; offset to FCB ADD HL,DE EX DE,HL ; DE = FCB LD C,(HL) ; get length of directory INC HL LD B,(HL) LD HL,0 ; read directory in (record 0) LOOP: CALL R$READ ; random read JR NZ,ERROR ; file not found if error PUSH HL ; save key regs PUSH DE PUSH BC CALL SCAN ; scan for file name match and build buffer POP BC ; restore key regs POP DE POP HL JR Z,ERROR ; TPA full INC HL ; pt to next record DEC BC ; count down length of dir LD A,B ; done? OR C JR NZ,LOOP LD HL,(BUFFER) ; point to next byte after last entry LD (HL),A ; Store A=0 from before the "jr nz,loop" DEFB 01H ; ..trash BC and fall thru leaving AF set ERROR: OR 0FFH ; Set 0FFH and flags (unless fall thru) POP BC ; restore regs POP DE POP HL RET ; Scan TBUFF for file names ; If memory overflow, A=0 and Zero Flag Set ; If OK, A=0FFH SCAN: LD HL,TBUFF ; pt to buffer LD C,4 ; 4 entries possible SCAN1: LD A,(HL) ; check for active entry OR A ; 0=yes JR NZ,SCANXT PUSH HL INC HL ; pt to name LD DE,(FILE) ; pt to file name LD B,11 ; 11 bytes SCANLP: LD A,(DE) ; get name AND 7FH ; mask msb CP '?' ; match wild JR Z,SCANLP1 CP (HL) ; compare to dir entry JR NZ,SCANLP2 SCANLP1: INC HL ; pt to next INC DE DJNZ SCANLP POP DE ; we have a match - pt to entry with DE LD HL,(BUFFER) ; get address of next buffer entry LD A,(TPAEND) ; check for overflow CP H JR C,SCANERR ; TPA overflow PUSH DE ; save ptr PUSH BC ; save count INC DE ; pt to file name EX DE,HL ; source in HL LD BC,LENTSZ ; entry Size LDIR LD (BUFFER),DE ; save ptr for next copy POP BC ; get count JR SCANLP2 ; continue SCANLP2: POP HL ; pt to current SCANXT: LD DE,32 ; pt to next ADD HL,DE DEC C ; count down JR NZ,SCAN1 DEFB 0F6H ; Set NO error with "OR 0AFH" SCANERR: XOR A ; Set Error RET ; Buffers DSEG ; Put these in the Data Segment FILE: DEFS 2 ; pointer to FN.FT BUFFER: DEFS 2 ; pointer to memory buffer TPAEND: DEFS 1 ; end page of TPA LUDENT: DEFS 2 ; pointer to LUD entry END