home *** CD-ROM | disk | FTP | other *** search
- ;
- ; Z3LIB Module Name: Z3PFIND
- ; Author: Richard Conn
- ; Z3LIB Version Number: 1.3
- ; Module Version Number: 1.1
- ;
- public pfind
-
- EXT GETPATH
-
- ;
- ; EQUATES
- ;
- BDOS EQU 5
-
- ;
- ; INTERNAL BUFFERS
- ;
- CURELT:
- DS 1 ; LOW-ORDER PTR TO CURRENT PATH ELEMENT
- SEARCUR:
- DS 1 ; 0=DON'T SEARCH CURRENT DIR
- CDISK:
- DS 1 ; CURRENT DISK NUMBER
- CUSER:
- DS 1 ; CURRENT USER NUMBER
- TDISK:
- DS 1 ; TEMP DISK NUMBER
- TUSER:
- DS 1 ; TEMP USER NUMBER
-
- ;
- ; PFIND -- LOOK FOR FILE WHOSE FCB IS PTED TO BY DE ALONG PATH
- ; IF FILE FOUND, RETURN DISK NUMBER IN B, USER NUMBER IN C, AND
- ; ZERO FLAG CLEAR (NZ) WITH A=0FFH; IF NOT FOUND, RETURN WITH ZERO FLAG
- ; SET (Z) AND A=0; IF ERROR, RETURN WITH ERROR CODE (1,2,3) AND NZ
- ;
- ; INPUTS: DE PTS TO FCB, A IS FLAG: A=0 IF NO CURRENT SEARCH ALSO,
- ; <>0 IF CURRENT SEARCH
- ; OUTPUTS: B=DISK, C=USER IF FOUND
- ; ZERO FLAG SET (Z) IF NOT FOUND
- ; ZERO FLAG CLEAR (NZ) IF FOUND
- ;
- PFIND:
- PUSH HL ; SAVE REGS
- PUSH DE
- LD (SEARCUR),A ; SET FLAG TO SEARCH CURRENT
- XOR A ; SET DISK NUMBER TO CURRENT
- LD (DE),A ; CHANGE FCB
- PUSH DE ; SAVE FCB PTR
- LD C,25 ; GET CURRENT DISK
- CALL BDOSH
- LD (CDISK),A ; SAVE CURRENT DISK
- LD (TDISK),A ; SET TEMP DISK
- LD C,32 ; GET CURRENT USER
- LD E,0FFH
- CALL BDOSH
- LD (CUSER),A ; SAVE CURRENT USER
- LD (TUSER),A ; SAVE TEMP USER
- POP DE ; GET FCB PTR
- CALL GETPATH ; GET ADDRESS OF EXTERNAL PATH IN HL
- LD A,(SEARCUR) ; SEARCH CURRENT?
- OR A ; 0=NO
- JP Z,PF1
- ;
- ; LOOK FOR FILE WHOSE FCB IS PTED TO BY DE
- ;
- PF0:
- LD C,17 ; SEARCH FOR FIRST
- CALL BDOSH
- INC A ; FILE FOUND?
- JP NZ,PFFND
- ;
- ; ADVANCE TO NEXT ELEMENT IN PATH
- ;
- PF1:
- LD A,(HL) ; GET DRIVE NUMBER FROM PATH
- OR A ; 0=DONE=FILE NOT FOUND
- JP Z,PFNFND
- CALL GETDU ; GET DU IN BC
- CALL CKDUP ; CHECK FOR DUPLICATION OF PATH ENTRY
- INC HL ; PT TO NEXT PATH ENTRY
- INC HL
- JP Z,PF1 ; CONTINUE IF DUPLICATION OF PATH ENTRY
- PUSH DE ; SAVE FCB PTR
- PUSH BC ; SAVE BC
- LD A,B ; SET DISK
- LD (TDISK),A
- LD E,A
- LD C,14 ; SELECT DISK
- CALL BDOSH
- POP BC ; GET BC
- LD A,C ; SET USER
- LD (TUSER),A
- LD E,A
- LD C,32 ; SELECT USER
- CALL BDOSH
- POP DE ; GET FCB PTR
- JP PF0 ; CONTINUE SEARCH
- ;
- ; FILE FOUND FLAG SETTING
- ;
- PFFND:
- XOR A ; FOUND RETURN CODE
- DEC A ; SET NZ
- JP FNDEXIT
- ;
- ; FILE NOT FOUND ERROR
- ;
- PFNFND:
- XOR A ; FILE NOT FOUND
- FNDEXIT:
- PUSH AF ; SAVE RETURN CODE
- LD A,(CDISK) ; RESTORE CURRENT DISK
- LD E,A ; SAVE IN E
- LD C,14 ; SELECT DISK IN E
- CALL BDOS
- LD A,(CUSER) ; RESTORE CURRENT USER
- LD E,A ; SAVE IN E
- LD C,32 ; SELECT USER IN E
- CALL BDOS
- LD A,(TDISK) ; SET FOUND DISK
- LD B,A
- LD A,(TUSER) ; SET FOUND USER
- LD C,A
- POP AF ; GET RETURN CODE
- POP DE ; RESTORE REGS
- POP HL
- RET
-
- ;
- ; CHECK ALONG PATH FOR DUPLICATION OF ENTRY
- ; RETURN WITH Z IF SO
- ;
- CKDUP:
- PUSH HL ; SAVE PTRS
- PUSH DE ; SAVE FCB
- PUSH BC ; SAVE DU
- LD A,L ; SAVE LOW-ORDER ADDRESS
- LD (CURELT),A
- CALL GETPATH ; PT TO FIRST ELEMENT OF PATH
- CKDUP1:
- LD A,(CURELT) ; GET CURRENT ELEMENT
- CP L ; ARE WE THERE?
- JP Z,NODUP
- CALL GETDU ; GET ELEMENT IN BC
- INC HL ; PT TO NEXT PATH ELEMENT
- INC HL
- POP DE ; GET CURRENT DU IN DE
- PUSH DE ; SAVE IT AGAIN
- LD A,B ; COMPARE AGAINST PATH ELEMENT
- CP D
- JP NZ,CKDUP1
- LD A,C
- CP E
- JP NZ,CKDUP1 ; NO MATCH, SO CONTINUE
- ;
- ; WE HAVE A DUPLICATE - RETURN Z
- ;
- POP BC ; RESTORE REGS
- POP DE
- POP HL
- XOR A ; SET Z
- RET
- ;
- ; NO DUPLICATES - RETURN NZ
- ;
- NODUP:
- POP BC ; RESTORE REGS
- POP DE
- POP HL
- XOR A ; SET NZ
- DEC A
- RET
-
- ;
- ; RETURN DU IN BC FOR CURRENT PATH ELEMENT PTED TO BY HL
- ;
- GETDU:
- LD A,(HL) ; GET DISK
- CP '$' ; CURRENT?
- JP NZ,GETDU1
- LD A,(CDISK) ; SELECT CURRENT DISK
- INC A ; ADJUST
- GETDU1:
- DEC A ; SET DISK FOR A=0
- LD B,A ; DISK IN B
- INC HL ; PT TO USER
- LD A,(HL) ; GET USER
- DEC HL ; PT BACK TO DISK
- CP '$' ; CURRENT?
- JP NZ,GETDU2
- LD A,(CUSER) ; GET CURRENT USER
- GETDU2:
- LD C,A ; USER IN C
- RET
-
- ;
- ; CALL BDOS AND NOT CHANGE HL
- ;
- BDOSH:
- PUSH HL ; CALL BDOS, BUT SAVE HL
- PUSH DE
- CALL BDOS
- POP DE
- POP HL
- RET
-
- END