TITLE "Z3WHRENV - Z3lib 4.0" ;================================================================= ; Copyright (C) 1989 by Harold F. Bower. Permission granted to ; Alpha Systems Corp. to distribute with The Libraries, Version 4 ;----------------------------------------------------------------- ; WHRENV - Find the ZCPR3 Environment Descriptor and return the ; address. If not found, then return error code. ;---------------------------------------------------------------- ; Author: Harold F. Bower ; Date : 26 Apr 87 ; Ver : 1.0 ; Revisions: ;---------------------------------------------------------------- ; This routine performs a step-wise check for a ZCPR3 ; Environment whose address (or a first cut) is passed in the HL ; register pair. The tests are: ; 1) If HL = 0, quit since no Environment exists. Return 0 in A ; and HL, and set the Zero flag (Z) ; 2) If HL points to a non-zero address, see if it is a valid ; environment. If so, return the address with HL unchanged, ; A <> 0 and the Zero Flag reset (NZ). ; 3) If HL points to an invalid Environment, start scanning for ; the string "Z3ENV" from the BDOS vector at location 5 to ; page FF00H of memory. If found, the pointer within the ; Environment is validated against the string to insure that ; the environment is indeed valid. If all checks are OK, ; the starting address of the Environment Descriptor is ; returned in the HL register pair, and the A register ; contains a Non-Zero value with the Zero Flag Reset (NZ). ; ;=============================================================== ; Grant access to these routines PUBLIC WHRENV ; Equates used in this module BDOS EQU 0005H ; Bdos entry vector .Z80 CSEG ;=======================================================; ; Routine - WHRENV ; ; ENTRY: HL - Points to candidate Environment ; ; EXIT : HL - Points to Environment if found, else 0 ; ; A <> 0, Zero Flag Reset (NZ) if found ; ; A = 0, Zero Flag Set (Z) if Not Found ; ; Uses All registers ; ;=======================================================; WHRENV: LD A,H ; If null value.. OR L RET Z ; ..Exit here since no Environment LD DE,3 ADD HL,DE ; Offset into proposed Environment LD A,'Z' ; Check first character.. CPI ; ..and check it JR NZ,WHREN0 ; Jump if Not, and scan memory PUSH HL ; Save Pointer around check CALL CHKENV ; Check validity of Env. POP HL JR Z,ENVXIT ; Exit if Good Environment ; Installed address is not valid. Scan memory from BDOS up WHREN0: LD HL,(BDOS+1) ; Get BDOS address to HL LD A,05H ; Find number of bytes to check SUB L ; ..only need to go to FF05 LD C,A LD A,0FFH SBC A,H LD B,A ; BC Now has # bytes to scan WHRLOP: LD A,'Z' ; Do quick scan for first char in string CPIR LD DE,0 ; Prepare for Error exit.. JP PO,ENVXIT ; ..and go Error if no 'Z' found PUSH BC ; Else save count and addr PUSH HL CALL CHKENV ; ..and check more POP HL POP BC JR NZ,WHRLOP ; No match? Loop if not ENVXIT: EX DE,HL ; Put Environment addr in HL LD A,H ; ..and set flags OR L RET ; Validate string pointed to by HL against 'ZCPR3', then check ; internal pointers to see if Environment is valid CHKENV: LD BC,4 ; Only 4 chars remain in string LD DE,Z3TAG ; Find this string in memory CHKLP: LD A,(DE) CPI RET NZ ; Return if no match INC DE ; ..bump source pointer JP PE,CHKLP ; Check more if not yet done LD DE,-8 ; String matched, check vector ADD HL,DE EX DE,HL ; Put possible Z3ENV addr in DE LD HL,27 ADD HL,DE ; Offset to check vector LD A,(HL) CP E ; Check low byte of pointer.. RET NZ ; ..no match is error INC HL ; Move to hi byte LD A,(HL) CP D ; ..and check it RET Z3TAG: DEFB '3ENV' ; String to match, less first char END