;
;  PROGRAM:  SYSTEST6
;  AUTHOR:  Richard Conn
;  PURPOSE:  To illustrate the ZCPR2-specific routines in SYSLIB
;

;
;  Externals
;
	EXT	ZCPRSET		; Set DMA, et al
	EXT	ZINIEXT		; Set External Path Address
	EXT	ZPFIND		; Find File Along Path
	EXT	ZFSTAT		; Return Status of File
	EXT	ZFNAME		; Extended File Name Parser

	EXT	RETUD		; Return Current User/Disk
	EXT	CRLF		; New Line
	EXT	BBLINE		; Input Line Editor
	EXT	PRINT		; Print String
	EXT	PSTR		; Another Print String
	EXT	CIN		; Char in
	EXT	COUT		; Char out
	EXT	CAPS		; Capitalize char
	EXT	PADC		; Print A as decimal
	EXT	BDOS		; BDOS Call
	EXT	PHL4HC		; Print HL as 4 Hex chars
	EXT	CODEND		; End of code/beginning of buffer

;
;  Constants
;
CR	EQU	0DH
LF	EQU	0AH

;
;  THIS INITIALIZATION MUST BE DONE WHENEVER THE ZCPR-ORIENTED ROUTINES
;	ARE TO BE USED WITH THE USER'S EXTERNAL PATH
;
	LXI	H,40H		; BASE OF EXTERNAL PATHS
	CALL	ZINIEXT		; SET BASE ADDRESS

;
;  THIS INITIALIZATION NEED NOT ALWAYS BE DONE, ESPECIALLY WHEN THE
;	DEFAULTS ARE USED, BUT I'M DOING IT HERE FOR PURPOSE OF EXAMPLE
;
	MVI	A,'$'	; CURRENT INDICATOR
	LXI	H,80H	; DMA ADDRESS
	CALL	ZCPRSET	; SET THESE VALUES FOR ZCPR ROUTINES

;
;  SINCE I AM PLAYING WITH DISKS AND USER AREAS, GET THE CURRENT DISK/USER
;
	CALL	RETUD	; GET CURRENT USER AND DISK
	MOV	A,B	; SAVE DISK
	STA	CDISK
	MOV	A,C	; SAVE USER
	STA	CUSER

;
;  TEST LOOP
;
LOOP:
	CALL	PRINT
	DB	CR,LF,'Current Disk is ',0
	LDA	CDISK	; GET DISK
	PUSH	PSW	; SAVE IF
	ADI	'A'	; CONVERT TO ASCII
	CALL	COUT
	POP	PSW	; GET DISK
	MOV	E,A
	MVI	C,14	; SELECT DISK
	CALL	BDOS
	CALL	PRINT
	DB	', and Current User is ',0
	LDA	CUSER	; GET USER
	CALL	PADC	; PRINT AS DECIMAL
	MOV	E,A	; SELECT USER
	MVI	C,32
	CALL	BDOS
	CALL	PRINT
	DB	CR,LF,'Name of File to Search For (<CR>=Done)? ',0
	XRA	A	; NO CAP
	CALL	BBLINE	; GET LINE FROM USER
	ORA	A	; ANY INPUT?
	RZ
	CALL	PRINT
	DB	CR,LF,'File Name: ',0
	PUSH	H	; SAVE HL, SINCE MODIFIED BY PSTR
	CALL	PSTR
	CALL	CODEND	; GET ADDRESS OF SCRATCH AREA FOR ZFNAME
	MOV	B,H	; ... IN BC
	MOV	C,L
	POP	H
	LXI	D,FCB	; PT TO FCB
	CALL	ZFNAME	; CONVERT TO FCB FORM
	JZ	UDERR	; USER OR DISK ERROR?
	CALL	PRINT
	DB	CR,LF,'Selected Disk is ',0
	MOV	A,B	; GET DISK NUMBER
	CPI	0FFH	; CURRENT?
	JNZ	DN1
	CALL	PRINT
	DB	'Current',0
	JMP	DN2
DN1:
	DCR	A	; CONVERT TO 0-15
	ADI	'A'	; CONVERT TO LETTER
	CALL	COUT
	SUI	'A'	; CONVERT BACK
	MOV	E,A	; IN E
	PUSH	B	; SAVE BC
	MVI	C,14	; SELECT DISK
	CALL	BDOS
	POP	B	; GET BC
DN2:
	CALL	PRINT
	DB	', and Selected User is ',0
	MOV	A,C	; GET USER
	CPI	0FFH	; CURRENT?
	JNZ	DN3
	CALL	PRINT
	DB	'Current',0
	JMP	DN4
DN3:
	CALL	PADC	; PRINT AS DECIMAL
	MOV	E,A	; USER IN E
	MVI	C,32	; SELECT USER
	CALL	BDOS
DN4:
	CALL	PRINT
	DB	CR,LF,'Selected User and Disk Now Logged In'
	DB	CR,LF,'File Name from FCB: ',0
	LXI	H,FCB+1
	MVI	C,8	; PRINT 8 CHARS
	CALL	PCH
	MVI	A,'.'
	CALL	COUT
	MVI	C,3	; PRINT 3 MORE CHARS
	CALL	PCH
	CALL	CRLF
	LXI	D,FCB	; PT TO FCB
	MVI	B,0	; DON'T SEARCH CURRENT
	CALL	ZPFIND	; SEARCH FOR FILE ALONG PATH (DE PTS TO FCB)
	JZ	FNF	; FILE NOT FOUND IF A=0 AND ZERO FLAG SET
	CALL	PRINT
	DB	CR,LF,'File Found on Disk ',0
	MOV	A,B	; GET DISK NUMBER
	ADI	'A'	; CONVERT TO LETTER
	CALL	COUT
	CALL	PRINT
	DB	' in User ',0
	MOV	A,C	; GET USER NUMBER
	CALL	PADC	; PRINT AS DECIMAL
	PUSH	D	; SAVE FCB PTR
	PUSH	B	; SAVE USER/DISK
	MOV	E,B	; SELECT DISK
	MVI	C,14	; BDOS FCT
	CALL	BDOS	; SELECT USER
	POP	B	; GET USER
	MOV	E,C
	MVI	C,32	; BDOS FCT
	CALL	BDOS	; SELECT USER
	POP	D	; GET FCB PTR
	CALL	ZFSTAT	; GET STATUS OF FILE
	JNZ	FNF1	; FILE NOT FOUND?  SHOULD NOT HAPPEN
	CALL	PRINT
	DB	CR,LF,'File is ',0
	MOV	A,C	; GET R/O FLAG
	ORA	A	; 0=NOT R/O
	JNZ	LOOP1
	CALL	PRINT
	DB	'NOT ',0
LOOP1:
	CALL	PRINT
	DB	'Read/Only, and File is ',0
	MOV	A,B	; GET SYSTEM FLAG
	ORA	A	; 0=NOT SYSTEM
	JNZ	LOOP2
	CALL	PRINT
	DB	'Non-',0
LOOP2:
	CALL	PRINT
	DB	'System',0
	JMP	LOOP
FNF1:
	CALL	PRINT
	DB	CR,LF,'This should not happen',0
FNF:
	CALL	PRINT
	DB	CR,LF,'File Not Found',0
	JMP	LOOP
UDERR:
	CALL	PRINT
	DB	CR,LF,'Error in User or Disk Numbers',0
	JMP	LOOP
PCH:
	MOV	A,M	; GET CHAR
	CALL	COUT	; PRINT CHAR
	INX	H	; PT TO NEXT
	DCR	C	; COUNT DOWN
	JNZ	PCH
	RET

CDISK:
	DS	1	; CURRENT DISK
CUSER:
	DS	1	; CURRENT USER
FCB:
	DS	36

	END
