; TITLE "SLUINIT - Syslib 4.0" NAME ('LUINIT') ;================================================================= ; The Libraries, Version 4, (C) 1989 by Alpha Systems Corp. ;----------------------------------------------------------------- ; Author : Harold F. Bower ; Derived from SLUINIT.Z80 Ver 1.0 by Richard Conn ; Date : 17 Sep 89 ; Version : 1.1 ; Module : SLUINIT ; Abstract: This module contains the routine LUINIT which is ; used to initialize a library file for later access. ; Revision: ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ; Module Entry Points PUBLIC LUINIT ; From SYSLIB Get.. EXT F$OPEN, F$READ, INITFCB, SETDMA ; Definitions BDOSE EQU 5 ; CP/M, ZRDOS, P2DOS entry point TBUFF EQU 0080H ; Default buffer LUIDX EQU 12 ; Offset to Index in LU directory LUDIDX EQU 2 ; Offset to LUD current index LUDFCB EQU 17 ; Offset to LUD FCB .Z80 CSEG ;=============================================================== ; NAME - LUINIT ; Entry: DE - Points to an LUD which contains FCB and other info ; Exit : A = 0, Zero Flag Set (Z) if No Error ; A = Error code, Zero Clear (NZ) if ERROR as: ; 1 = File not found ; 2 = File empty ; 3 = Library File Format error ; Uses : AF ; NOTE: The DMA address is set to TBUFF by this routine ;=============================================================== LUINIT: PUSH HL ; save regs PUSH DE ; ..points to LUD ptr PUSH BC LD HL,TBUFF CALL SETDMA ; Set default DMA address LD HL,LUDIDX ; fill LUD index and count with zeroes ADD HL,DE ; pt to LUD index LD B,4 ; 4 bytes FILL: LD (HL),0 ; store zeroes INC HL DJNZ FILL LD HL,LUDFCB ; offset to LUD FCB ADD HL,DE EX DE,HL ; HL = LUD, DE = FCB CALL INITFCB CALL F$OPEN ; Try to open LU file LD A,1 ; ..preset error code in case JR NZ,DONE ; Jump to Return Error if file not found CALL F$READ ; Read directory block LD A,2 ; ..preset error code in case JR NZ,DONE ; Jump to Return Error if no first block EX DE,HL ; Put Ptr to LUD in DE LD HL,TBUFF ; Point to Sector buffer LD A,(HL) ; Check status of first byte (must be 0) OR A JR NZ,ERRFMT ; ..jump error if not 0 INC HL ; Point to first char of name LD A,' ' ; ..which must be spaces LD B,11 ; ...in Name and type CHECK: CP (HL) JR NZ,ERRFMT ; Jump error if not space INC HL ; ..else go to next DJNZ CHECK ; Loop til done LD A,(HL) ; Check both index bytes for 0 INC HL OR (HL) INC HL ERRFMT: LD A,3 ; ..prepare for error in case JR NZ,DONE ; Jump error if bad LDI ; Set LUD length LDI XOR A ; Show no error DONE: POP BC ; Return with proper regs POP DE POP HL OR A ; Set return flag RET END