;
;  PROGRAM:  RECORD
;  AUTHOR:  RICHARD CONN
;  VERSION:  1.4
;  DATE:  6 Jan 83
;  PREVIOUS VERSIONS:  1.3 (5 Jan 83)
;  PREVIOUS VERSIONS:  1.0 (30 Dec 82), 1.1 (31 Dec 82), 1.2 (1 Jan 83)
;
VERS	EQU	14

;
;	This program is Copyright (c) 1982, 1983 by Richard Conn
;	All Rights Reserved
;
;	ZCPR2 and its utilities, including this one, are released
; to the public domain.  Anyone who wishes to USE them may do so with
; no strings attached.  The author assumes no responsibility or
; liability for the use of ZCPR2 and its utilities.
;
;	The author, Richard Conn, has sole rights to this program.
; ZCPR2 and its utilities may not be sold without the express,
; written permission of the author.
;


;
;	RECORD enables and disables the disk output redirectable I/O
; drivers for ZCPR2.  This command takes two forms:
;
;		RECORD ON	<-- Turn on console recording
;		RECORD OFF	<-- Turn off console recording
;		RECORD ON LST	<-- Turn on printer recording
;		RECORD OFF LST	<-- Turn off printer recording
;
	ext	print,fname,bbline

fcb	equ	5dh		;FCB Input
fcb2	equ	6dh		;FCB2 Input
cr	equ	0dh
lf	equ	0ah

;
;  Branch to Start of Program
;
	jmp	start

;
;******************************************************************
;
;  SINSFORM -- ZCPR2 Utility Standard General Purpose Initialization Format
;
;	This data block precisely defines the data format for
; initial features of a ZCPR2 system which are required for proper
; initialization of the ZCPR2-Specific Routines in SYSLIB.
;

;
;  EXTERNAL PATH DATA
;
EPAVAIL:
	DB	0FFH	; IS EXTERNAL PATH AVAILABLE? (0=NO, 0FFH=YES)
EPADR:
	DW	40H	; ADDRESS OF EXTERNAL PATH IF AVAILABLE

;
;  INTERNAL PATH DATA
;
INTPATH:
	DB	0,0	; DISK, USER FOR FIRST PATH ELEMENT
			; DISK = 1 FOR A, '$' FOR CURRENT
			; USER = NUMBER, '$' FOR CURRENT
	DB	0,0
	DB	0,0
	DB	0,0
	DB	0,0
	DB	0,0
	DB	0,0
	DB	0,0	; DISK, USER FOR 8TH PATH ELEMENT
	DB	0	; END OF PATH

;
;  MULTIPLE COMMAND LINE BUFFER DATA
;
MCAVAIL:
	DB	0FFH	; IS MULTIPLE COMMAND LINE BUFFER AVAILABLE?
MCADR:
	DW	0FF00H	; ADDRESS OF MULTIPLE COMMAND LINE BUFFER IF AVAILABLE

;
;  DISK/USER LIMITS
;
MDISK:
	DB	4	; MAXIMUM NUMBER OF DISKS
MUSER:
	DB	31	; MAXIMUM USER NUMBER

;
;  FLAGS TO PERMIT LOG IN FOR DIFFERENT USER AREA OR DISK
;
DOK:
	DB	0FFH	; ALLOW DISK CHANGE? (0=NO, 0FFH=YES)
UOK:
	DB	0FFH	; ALLOW USER CHANGE? (0=NO, 0FFH=YES)

;
;  PRIVILEGED USER DATA
;
PUSER:
	DB	10	; BEGINNING OF PRIVILEGED USER AREAS
PPASS:
	DB	'chdir',0	; PASSWORD FOR MOVING INTO PRIV USER AREAS
	DS	41-($-PPASS)	; 40 CHARS MAX IN BUFFER + 1 for ending NULL

;
;  CURRENT USER/DISK INDICATOR
;
CINDIC:
	DB	'$'	; USUAL VALUE (FOR PATH EXPRESSIONS)

;
;  DMA ADDRESS FOR DISK TRANSFERS
;
DMADR:
	DW	80H	; TBUFF AREA

;
;  NAMED DIRECTORY INFORMATION
;
NDRADR:
	DW	00000H	; ADDRESS OF MEMORY-RESIDENT NAMED DIRECTORY
NDNAMES:
	DB	64	; MAX NUMBER OF DIRECTORY NAMES
DNFILE:
	DB	'NAMES   '	; NAME OF DISK NAME FILE
	DB	'DIR'		; TYPE OF DISK NAME FILE

;
;  REQUIREMENTS FLAGS
;
EPREQD:
	DB	000H	; EXTERNAL PATH?
MCREQD:
	DB	000H	; MULTIPLE COMMAND LINE?
MXREQD:
	DB	000H	; MAX USER/DISK?
UDREQD:
	DB	000H	; ALLOW USER/DISK CHANGE?
PUREQD:
	DB	000H	; PRIVILEGED USER?
CDREQD:
	DB	000H	; CURRENT INDIC AND DMA?
NDREQD:
	DB	000H	; NAMED DIRECTORIES?
Z2CLASS:
	DB	1	; CLASS 1
	DB	'ZCPR2'
	DS	10	; RESERVED

;
;  END OF SINSFORM -- STANDARD DEFAULT PARAMETER DATA
;
;******************************************************************
;
iobase:
	dw	0	; I/O Driver Base Address

;
;  Start of Program
;
start:
	call	print
	db	'RECORD, Version '
	db	(vers/10)+'0','.',(vers mod 10)+'0',0

	lhld	iobase		;Check for I/O Driver Defn
	mov	a,h
	ora	l
	jnz	start0
	call	print
	db	cr,lf,'Abort -- I/O Driver Address NOT Defined',0
	ret

start0:
	call	status		;Call Status Routine
	jz	nodriver	;No Driver Available?
	cpi	80H		;MUST have Disk Driver Module (> 80H) Loaded
	jnc	start1
	call	print
	db	cr,lf,'Abort -- Disk Driver Module NOT Loaded',0
	ret
nodriver:
	call	print
	db	cr,lf,'Abort -- No I/O Driver Module Loaded',0
	ret

start1:
	lda	fcb		;Get first char
	cpi	'O'		;Must be O
	jnz	help
	lda	fcb+1		;Get 2nd char
	cpi	'N'		;ON?
	jnz	off
on:
	call	getfile	;Get File Name
	lda	fcb2	;Printer?
	cpi	'P'
	jnz	on1
	call	lopen	;TTY (HL pts to File FCB)
	call	print
	db	cr,lf,'++ TTY Recording ON ++',0
	ret
on1:
	call	copen	;CRT (HL pts to File FCB)
	call	print
	db	cr,lf,'++ CRT Recording ON ++',0
	ret
off:
	lda	fcb2	;Printer?
	cpi	'P'
	jnz	off1
	call	print
	db	cr,lf,'++ TTY Recording OFF ++',cr,lf,0
	call	lclose	;Close Disk File
	ret
off1:
	call	print
	db	cr,lf,'++ CRT Recording OFF ++',cr,lf,0
	call	cclose	;Close Disk File
	ret
;
;  Print Help Message
;
help:
	call	print
	db	cr,lf
	db	cr,lf,'RECORD turns on and off recording of screen displays'
	db	cr,lf,'on disk under ZCPR2 with the SYSIO Redirectable I/O '
	db	'Drivers'
	db	cr,lf,'engaged.'
	db	cr,lf
	db	cr,lf,'It is invoked by two forms:'
	db	cr,lf
	db	cr,lf,'	RECORD ON  or RECORD ON PRINTER'
	db	cr,lf,'	RECORD OFF or RECORD OFF PRINTER'
	db	cr,lf
	db	cr,lf,'Minimum Required Option Forms are ON, OF, and P:'
	db	cr,lf,'	RECORD ON P = RECORD ON PRINTER'
	db	cr,lf,'If the P option is given, then TTY output is '
	db	'recorded,'
	db	cr,lf,'else CRT output is recorded.'
	db	cr,lf,0
	ret
;
;  Obtain Name of Output File and Return Pointer to its FCB in HL
;
getfile:
	call	print
	db	cr,lf,'Output File Name (<CR> for DISKOUT)? ',0
	mvi	a,0ffh	;Caps
	call	bbline	;Get user Input
	call	sblank	;Skip to Non-Blank
	ora	a	;EOL?
	jz	defexit	;Done if Default
	lxi	d,confcb	;Pt to FCB
	push	d	;Save ptr for return
	call	fname	;Extract Name
	jz	uderr	;No UD Allowed
	mov	a,c	;Check for any UD
	cpi	0ffh
	jnz	uderr
	mov	a,b
	cpi	0ffh
	jz	getf1
uderr:
	call	print
	db	cr,lf,'Override -- File is Placed in your Current Directory'
	db	cr,lf,0
getf1:
	pop	h	;Get ptr to FCB
	ret
defexit:
	lxi	h,confcb	;Default FCB
	lda	fcb2	;Check for Printer
	cpi	'P'
	rnz
	lxi	h,prtfcb	;Printer FCB
	ret
;
;  Skip to Non-Blank
;
sblank:
	mov	a,m	;Get char
	inx	h	;Pt to next
	cpi	' '	;Loop if Space
	jz	sblank
	dcx	h	;Pt to Non-Blank Char
	ret

;
;  I/O Driver Interface Routines
;
status:
	push	h		;Save HL
	push	d		;Save DE
	lxi	d,0		;No Offset for Status
runio:
	lhld	iobase		;Get I/O Base Address
	dad	d		;Pt to Routine
	pop	d		;Restore DE
	xthl			;Restore HL and Place Address on Stack
	ret			;"Run" Routine
copen:
	push	h		;Save Regs
	push	d
	lxi	d,36		;Offset for Console Open Routine
	jmp	runio		;Run Routine
cclose:
	push	h		;Save Regs
	push	d
	lxi	d,39		;Offset for Console Close Routine
	jmp	runio
lopen:
	push	h		;Save Regs
	push	d
	lxi	d,42		;Offset for Printer Open Routine
	jmp	runio
lclose:
	push	h		;Save Regs
	push	d
	lxi	d,45		;Offset for Printer Close Routine
	jmp	runio

;
;  FCBs
;
confcb:
	db	0
	db	'DISKOUT '
	db	'CON'
	ds	24
prtfcb:
	db	0
	db	'DISKOUT '
	db	'PRT'
	ds	24

	end