	TITLE  '(SB80CLI) - SB/80 Command Line Interpreter'

MEMSZ	EQU	64		!=;
BIOSSZ	EQU	01C00H		!=; tarbell bios sz = 3 1/2 k
VERS	EQU	0AH		!=;
;****************************************************************
;*								
;* module name = cli.asm
;* descriptive name = sb/80 o/s command line interpreter
;* copyright (c) = 1981, lifeboat associates, inc.
;* author = lee rautenberg, dma
;*	    mark l. rollins, lifeboat associates
;* date written =
;*
;* change activity =
;*   01/18/82 mlr ny:  finish sbst; reverse compatibility flag (0=cpm,1=sb80)
;*   12/16/81 mlr ny:  changes to match new dos ldpgm (cli ldtran)
;*   12/09/81 mlr ny:  write srchfg to disk on intrinsic;
;*			- finish auto load;
;*			- make dos fn # compatibile w/new dos
;*   11/27/81 mlr ny:  fix del *.* to remain on curdrv;
;*			- mov cmdbuf to front of cli, as in cp/m
;*			- put copyright in ram
;*   11/14/81 mlr ny:  add srchfg & intrinsics for dsk srch to
;*			to load pgm (default is srch logged drive
;*			only):
;*			- srcal:  srch drv a, then logged drv;
;*			  srcla:  srch both, logged 1st, then a;
;*			  srclo:  same as srcl
;*   11/09/81 mlr ny:  use full 1000h for cli;
;*			- put in vers # string
;*   08/14/81 mlr ny:  setup for Tarbell dd controller;
;*			- make so dir looks like cp/m dir
;*
;*   
;*   release = R0.A
;*   date = 18/jan/82
;*
;* environment =
;*   processor = mac (dig.rsrch)
;*
;****************************************************************
;
;
	PAGE
;****************************************************************
;*								*
;*		    SYSTEM DEFINITION EQUATES			*
;*								*
;****************************************************************
;
TOFMEM	EQU	MEMSZ*1024	!=;
BIOS	EQU	TOFMEM-BIOSSZ	!=;
DOSSZ	EQU	1400H		!=;
CLISZ	EQU	1000H		!=;
DOSST	EQU	BIOS-DOSSZ	!=;
CLIST	EQU	DOSST-CLISZ	!=; org cli

DVSTRNG	EQU	DOSST+11	!=; loc of dos vers string
;
;****************************************************************
;*								*
;*		    MISCELLAENOUS EQUATES			*
;*								*
;****************************************************************
;
;
FALSE	EQU	0000H
TRUE	EQU	NOT FALSE
PASSW	EQU	TRUE		; PASSWORD OPTION SWITCH
IOBYTE	EQU	3		; IOBYTE
NMDRIV	EQU	16		; MAXIMUM NUMBER OR DRIVES
DISKA	EQU	0004H		; DISK ADDRESS FOR CURRENT DISK
DOS	EQU	0005H		; PRIMARY DOS ENTRY POINT
WBOOT	EQU	0		; WARM BOOT ADDRESS
BUFF	EQU	0080H		; DEFAULT BUFFER
FCB	EQU	005CH		; DEFAULT FILE CONTROL BLOCK
CR	EQU	13		; CARRIAGE RETURN
LF	EQU	10		; LINE FEED
DLR	EQU	24H		; DOLLAR SIGN
EOFILE	EQU	1AH		; END OF FILE
;
MONITOR EQU	0F000H		; LOCATION OF TARBELL MONITOR
;
;
	PAGE
;
;****************************************************************
;*								*
;*		    BDOS FUNCTION EQUATES			*
;*								*
;****************************************************************


CNREAD	EQU	1		; READ CHARACTER FUNCTION
CNWRIT	EQU	2		; PRINT CHARACTER FUNCTION
CNBFWR	EQU	9		; PRINT BUFFER FUNCTION
CNBFRD	EQU	10		; READ BUFFER FUNCTION
CNBRK 	EQU	11		; BREAK KEY FUNCTION
DINIT	EQU	13		; INIT DOS FUNCTION
DSEL	EQU	14		; SELECT DISK FUNCTION
DOPEN	EQU	15		; OPEN FILE FUNCTION
DCLOS 	EQU	16		; CLOSE FILE FUNCTION
DSRCH	EQU	17		; SEARCH FOR FILE FUNCTION
DSRNX 	EQU	18		; SEARCH FOR NEXT FILE FUNCTION
DERAS	EQU	19		; DELETE FILE FUNCTION
DREAD 	EQU	20		; DISK READ FUNCTION
DWRIT 	EQU	21		; DISK WRITE FUNCTION
DCRAT	EQU	22		; FILE MAKE FUNCTION
DRENA	EQU	23		; RENAME FILE FUNCTION
DLOGV	EQU	24		; RETURN LOGIN VECTOR
DGDSK	EQU	25		; RETURN CURRENTLY SELECTED DRIVE NUMBER
DDMA	EQU	26		; SET DMA ADDRESS
ATRF	EQU	30		; SET ATTRIBUTE FN
STUSRF	EQU	32		; GET/SET USER NUMBER
GTUSRF	EQU	32	
QUEFIL	EQU	128		; FILE QUE FUNCTION
UNQFIL	EQU	129		; DEQUE A FILE
KILPRN	EQU	130		; KILL BACKGROUND PRINT
SUSPRN	EQU	131		; SUSPEND PRINT
RSTPRN	EQU	132		; RESTORE PRINT
BPSTAT	EQU	133		; BACKGROUND PRINT STATUS
SBPST	EQU	134		; SET BACKGROUND PRINT STATUS
QUVEC	EQU	135		; GET THE QUEUE VECTOR
BPINIT	EQU	136		; INITIALIZE BACKGROUND PRINT
LDCLI	EQU	137		; RESET DISK SYSTEM AND READ CLI
DGDMA	EQU	138		; GET DMA ADDRESS
DGCMPT	EQU	139		; GET/SET FCB COMPATIBILITY
DSCMPT	EQU	139
DSCLI	EQU	141		; SET USER CLI FILENAME
DSLDAD	EQU	142		; SET PGM LD ADDR
DSEXAD	EQU	143		; SET PGM EXECUTION ADDR
DLDPGM	EQU	144		; DOS FN TO LD A PGM


	PAGE
;****************************************************************
;*								*
;*		    BACKGROUND PRINT EQUATES			*
;*								*
;****************************************************************


PREADY	EQU	1		; BP READY STATUS
PSUSPN	EQU	2		; BP SUSPENDED STATUS
PFEROR	EQU	5		; BP FILE ERROR STATUS
PESUS	EQU	3		; BP PRINTER ERROR STATUS


;****************************************************************
;*								*
;*		    FILE ATTRIBUTE EQUATES			*
;*								*
;****************************************************************


BITWRP	EQU	80H		; MASK FOR WRITE PROTECT BIT
BITSYS	EQU	40H		; MASK FOR SYSTEM FILE BIT
BITINV	EQU	20H		; MASK FOR INVISIBLE FILE BIT

FAT	EQU	14		; OFFSET POS OF ATTR BYTE IN FCB
XORMSK	EQU	034H		; EXCLUSIVE OR MASK FOR PASSWORDS



	PAGE
;****************************************************************
;*								*
;*			START OF CLI				*
;*								*
;****************************************************************



TRAN	EQU	100H
TRANM	EQU	$

CLILOC	EQU	$
;
	JMP	CLISTA		; JUMP TO THE START OF THE CLI
	JMP	CLISTB		; ALT ENTRY FOR AUTO LOAD

	PAGE
;****************************************************************
;*								*
;*	(CLI) -		COMMAND BUFFER AREA			*
;*								*
;****************************************************************

CMDMAX:	DB	127		; MAXIMUM COMMAND LEN
CMDLEN:	DB	0		; LENGTH, FILLED IN BY DOS
CMDBUF:				; COMMAND BUFFER (128 BYTES)
	DB	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	DB	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	DB	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	DB	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	DB	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	DB	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	DB	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	DB	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0

CMDPTR:	DW	CMDBUF		; PTR TO NEXT CHAR IN CMDBUF TO SCAN

VRSTRNG:
	IF	(VERS/16) > 9
	DB	(VERS/16) + 37H
	ELSE
	DB	(VERS/16) + 30H
	ENDIF

	IF	(VERS MOD 16) > 9
	DB	(VERS MOD 16) + 37H
	ELSE
	DB	(VERS MOD 16) + 30H
	ENDIF

SRCHFG:	DB	0		; flag to determine srch process for pgm ld:
				;   0        = srch logged drv only
				;   1        = srch logged drv, then a:
				;   -1(0ffh) = srch a:, then logged drv

CPYRT:	DB	'(c) 1981, lifeboat associates'
	DB	CR,LF,'$'

	PAGE
;****************************************************************
;*								*
;*	CMDTBL	TABLE OF INTRINSIC COMMANDS.  ALL COMMANDS ARE	*
;*		5 CHARACTERS LONG.				*
;*		TABLE FORMAT:	DB	'COMMAND NAME'		*
;*				DW	 COMMAND ROUTINE ADRS	*
;*								*
;****************************************************************


CMDTBL:
	DB	'ATTR '		;
	DW	ATTRIB		; SET THE FILE ATTRIBUTES
	DB	'BPINI'		;
	DW	BPRINIT		; INITIALIZE BACKGROUND PRINT
	DB	'BPST '		;
	DW	BPSTATUS	; <==> BPS
	DB	'CON  '		;
	DW	BATCHIN		; BATCH CONIN FROM FILE
	DB	'CONT '		;
	DW	RESTPRINT	; RESTORE PRINT
	DB	'DEQ  '		;
	DW	DEQUEFILE	; DEQUEUE A FILE
	DB	'DIR  '		;
	DW	DIRECT		; DIRECTORY SEARCH
	DB	'DIRA '		;
	DW	DIRA		; DIRECTORY SEARCH WITH ATTRIBUTES
	DB	'DIRI '		;
	DW	DIRI		; DIRECTORY SEARCH WITH INVISIBLE
	DB	'DEL  '		;
	DW	DELQ		; FILE ERASE, W/QUERY
	DB	'DEL/N'		;
	DW	DELETE		; FILE ERASE, NO QUERY
	DB	'KILL '		;
	DW	KILLPRINT	; KILL PRINT
	DB	'MON  '		;
	DW	MONITOR		; TELETEK MONITOR
	DB	'QUE  '		;
	DW	QUEFILE		; QUE A FILE
	DB	'REN  '		;
	DW	RENAME		; FILE RENAME
	DB	'SAVE '		;
	DW	SAVE		; SAVE MEMORY IMAGE
	DB	'SBST '		;
	DW	SBSTAT		; DSPLY SB80 STAT (CLI INTRINS FLAG SETTINGS)
	DB	'SRCAL'		;
	DW	SRCHAL		; SRCH DRV A:, THEN LOGGED DRV FOR PGM LD
	DB	'SRCLA'		;
	DW	SRCHLA		; SRCH LOGGED DRV, THEN A: FOR PGM LD
	DB	'SRCLO'		;
	DW	SRCHLO		; SRCH LOGGED DRV ONLY FOR PGM LD
	DB	'STCLI'		;
	DW	SETCLI		; SET USER CLI <FILENAME.TYP>
	DB	'STCPM'		;
	DW	SETCPM		; SET CPM COMPATIBILITY
	DB	'STIO '		;
	DW	SETIOBYTE	; SET IOBYTE	
	DB	'STSB8'		;
	DW	SETSB80		; RESET CPM COMPATIBILITY
	DB	'SUSP '		;
	DW	SUSPRINT	; SUSPEND PRINT
	DB	'TROFF'		;
	DW	TROFF		; TURN OFF TRANSLATE
	DB	'TRON '		;
	DW	TRON		; TURN ON TRANSLATE(LOWER TO UPPER)
	DB	'TYPE '		;
	DW	TYPE		; LIST FILE
	DB	'USER '		;
	DW	NEWUSR		; LOG IN NEW USER

RESTLN	EQU	($-CMDTBL)/7	;NUMBER OF COMMANDS



	PAGE
;****************************************************************
;*								*
;*	CLISTA	MAIN ENTRY POINT FOR COMMAND LINE INTERPRETER	*
;*	CLISTB	ALT  ENTRY POINT FOR NO AUTO LOAD		*
;*								*
;****************************************************************



CLISTA:
	LXI	SP,STACK
	MOV	E,C		; DISK NUMBER IN E
	CALL	FNSEL		; PROPER DISK IS SELECTED
	LDA	CMDLEN
	ORA	A
	JZ	CLI
	XRA	A		; CLEAR SLDISK
	STA	SLDISK
	CALL	GETLOG		; & GET CURRENT DISK
	STA	CURDSK
	JMP	CLI1

CLISTB:
	LXI	SP,STACK
	MOV	E,C		; DISK NUMBER IN E
	CALL	FNSEL		; PROPER DISK IS SELECTED
	JMP	CLI

	PAGE
;****************************************************************
;*								*
;*	CLI	ENTRY POINT FOR NEXT COMMAND PROCESSING		*
;*								*
;****************************************************************


CLI:
	LXI	SP,STACK
	XRA	A		; CLEAR
	STA	INVFLG		; DIR COMMAND MODE FLAG
	STA	ATTFLG		; DIR COMMAND ATTR FLAG
	STA	RENFLG		; RENAME FLAG
	STA	SWPFLG		; SWAP FLAG
	INR	A		; INIT DIR CR,LF FLAG TO DSPLY DRV
	STA	CRFLG		; DIR CR,LF FLAG FOR 4 WIDE DISPLAY
	CALL	CRLF		; PRINT PROMPT
	CALL	GETLOG		; GET CURRENT DISK NUMBER
	STA	CURDSK		; SAVE CURRENT DISK NUMBER
	ADI	'A'		; CONVERT TO ASCII
	CALL	PCHAR		; PRINT IT
	MVI	A,'>'		; AND PRINT REST OF PROMPT
	CALL	PCHAR		; 
	CALL	GETCOM		; GET A COMMAND LINE
	JZ	CLI		; JUMP IF SO TO IGNORE INPUT LINE
CLI1:				; ENTRY PT FOR AUTO LOAD
	LXI	D,BUFF		; 
	CALL	SETDMA		; DEFAULT DMA ADDRESS AT BUFF
	CALL	MAKDFB		; CREATE AN FCB FROM COMMAND BUFFER
	CALL	AMBIG		; CHECK IF AMBIGUOUS REFERENCE
	JNZ	COMERR		; JUMP IF ERROR-CANT BE AN AMBIGUOUS REFERENCE
	LDA	SLDISK		; GET DISK SELECTED BY COMMAND
	ORA	A
	JNZ	LDTRAN		; JUMP IF DISK SPECIFIED-CAN'T BE INTRINSIC
	LXI	H,CMDTBL	; GET TABLE OF RESIDENT COMMANDS
	MVI	C,0		; C COUNTS INTRINSICS AS SCANNED
INTRIN0:
	MOV	A,C
	CPI	RESTLN		; DONE WITH SCAN?
	JNC	LDTRAN		; YES, TRY TO LOAD TRANSIENT PGM
;
; MORE TO SCAN
;
	LXI	D,COMFCB+1	; BEGINNING OF NAME
	MVI	B,5		; LENGTH OF MATCH IS IN B
INTRIN1:
	LDAX	D
	CMP	M		; MATCH?
	JNZ	INTRIN2		; SKIP IF NO MATCH
	INX	D
	INX	H
	DCR	B
	JNZ	INTRIN1		; LOOP WHILE MATCHING
;
;COMPLETE MATCH ON NAME, CHECK FOR BLANK IN REST OF COMFCB
;
	MVI	B,6		; NUMBER OF BLANKS THAT MUST BE IN FCB
INTRN11:
	LDAX	D
	CPI	' '
	JNZ	LDTRAN 		; JUMP IF NOT BLANK, CAN'T INTRINSIC
	INX	D		; BUMP PTR
	DCR	B		; DOWN COUNT
	JNZ	INTRN11		; JUMP IF MORE TO TEST
	MOV	A,M
	INX	H
	MOV	H,M		; DO INDIRECT JUMP TO RESIDENT
	MOV	L,A
	PCHL
;
INTRIN2:			; MISMATCH, MOVE TO END OF INTRINSIC
	INX	H
	DCR	B
	JNZ	INTRIN2
;
INTRIN3:			; TRY NEXT INTRINSIC
	INX	H		; PAST THE ADDRESS
	INX	H
	INR	C		; TO NEXT INTRINSIC NUMBER
	JMP	INTRIN0		; FOR ANOTHER ROUND

	PAGE
;****************************************************************
;*								*
;*	LDTRAN		LOAD TRANSIENT PROGRAM			*
;*								*
;****************************************************************


LDTRAN:				; LOAD USER PROGRAM, AND SET UP FOR EXECUTION
	LDA	COMFCB+1
	CPI	' '
	JNZ	LDTRN1		; JUMP TO LOAD IF FILE NAME SPECIFIED
	LDA	SLDISK		; ELSE, NO FILE NAME, BUT MAY BE DRV CHANGE
	ORA	A
	JZ	CLI   		; IF 0, NO DRV SPECIFIED EITHER
	DCR	A
	CPI	NMDRIV		; MUST BE LESS THAN SYSTEM # DRVS (16)
	JNC	CLI   		; JUMP IF NOT
	PUSH	PSW		; SAVE DRIVE TO BE MADE CURRENT IF SELECT OK
	CALL	SELECT		; SELECT THE DRIVE
	POP	PSW		; RESTORE DRIVE TO BE MADE CURRENT
	STA	CURDSK		; SET AS CURRENT DISK
	STA	DISKA		; SET UP USER'S CURRENT DISK LOCATION
	JMP	CLI
;
;  FILENAME IS PRESENT, COMPLETE THE SETUP, & CALL DOS TO LD THE PGM
;
LDTRN1:
	LXI	D,COMFCB+9	; TEST FOR BLANK <' '> IN TYPE FLD
	LDAX	D
	CPI	' '
	JNZ	COMERR		; ERROR IF TYPE NOT <' '>
	LXI	H,COMTYPE	; PT <HL> TO 'COM' STRING,
	CALL	MOVENAME	;   & SET FILE TYPE TO .COM
;
	CALL	COMSETD		; PREPARE TO SRCH FOR .COM FILE
;
	CALL	SEARCHCOM	; (INR's RETCODE (<A>) BEFORE RETURNING)
	LXI	H,DSKCHG	; POINT TO DSK CHANGE FLAG (INDICATES 2ND SRCH)
	MOV	A,M		; GET IT
	MVI	M,0		; AND CLEAR IT
	JNZ	LDTRN2		;  JUMP IF OPEN WENT OK
	ORA	A		;  ELSE, TEST DSKCHG FLAG FOR 0
	JZ	NOFILE		;   JMP IF 0 ==> PGM FILE N.F. & NO 2ND SRCH
	STA	COMFCB		;   ELSE, DSKCHG CONTAINS DRV FOR 2ND SRCH,
	STA	SLDISK		;    SET .COM FCB & AS SELECTED DRV,
	CALL	SEARCHCOM	;     THEN, TRY AGAIN (INR's <A> BEFORE RET)
	JZ	NOFILE		;      JMP IF OPEN NG
;
;  SETUP THE DEFAULT FCB's & BUF IN PAGE 0
;
LDTRN2:
	CALL	STPPG0		; SETUP DEFAULT FCB's & BUF IN PG 0
;
	CALL	CRLF		; FINAL PREP FOR LOAD
	LDA	CURDSK
	STA	DISKA		; CURRENT DISK AT DISKA
	LXI	D,COMFCB
;
;  FINALLY, GO TO THE LOADED PROGRAM
;
	CALL	LDPGM		; LET DOS LOAD THE PGM & EXECUTE IT
;
	LDA	COMRETCD	; GET RETCODE (PUT IN R0 BYTE BY DOS)
	ORA	A
	JNZ	LOADERR
TRANEND:
	LXI	SP,STACK	;MAY COME BACK HERE
	LDA	CURDSK
 	STA	DISKA		;SET CURRENT DISK
	CALL	SELECT
	JMP	CLI

;
LOADERR:			; CANNOT LOAD THE PROGRAM
	LXI	D,LOADMSG
	CALL	FNBFWR
	JMP	CLI

	PAGE
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;****************************************************************
;*								*
;*		SUPPORT SUBROUTINES FOR PGM LD			*
;*								*
;****************************************************************
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

;****************************************************************
;*								*
;*	STPPG0		SETUP DEFAULT (PG 0) FCB & BUF		*
;*								*
;****************************************************************

STPPG0:
	LXI	H,FCB		; BUILD DEF FCB FROM CUR (CMDPTR)
	CALL	MAKFCB
	LXI	H,FCB+16	; START POINT FOR NEXT FCB
	CALL	MAKFCB		; MOVE ENTIRE FCB TO MEMORY
	XRA	A
	STA	FCB+32		; ZERO NXT BYTE PAST 2ND FCB
;
;  MOVE COMMAND LINE TO DEF BUF
;
	LXI	H,CMDBUF	; PT <HL> (SRC REG) TO CMDBUF
BMOVE0:
	MOV	A,M
	ORA	A
	JZ	BMOVE1		; SCAN FOR A <0> OR A <' '>
	CPI	' '
	JZ	BMOVE1
	INX	H
	JMP	BMOVE0		; LOOP UNTIL <0> OR <' '> FND

BMOVE1:				; FIRST BLANK POSITION FOUND
	MVI	B,0		; CLEAR CHAR COUNT
	LXI	D,BUFF+1	; READY FOR THE MOVE, PT <DE> (DEST REG)
BMOVE2:				;   TO DEF BUF + 1
	MOV	A,M
	STAX	D
	ORA	A
	JZ	BMOVE3
				; MORE TO MOVE
	INR	B
	INX	H
	INX	D
	JMP	BMOVE2
BMOVE3:
	MOV	A,B		; PUT CHAR COUNT IN <B> TO <A>,
	STA	BUFF		;   & STORE IN BUFFER
	RET

	PAGE
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;****************************************************************
;*								*
;*		SUPPORT SUBROUTINES FOR PGM LD			*
;*								*
;****************************************************************
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

;****************************************************************
;*								*
;*	COMSETD	  This subrout sets up the drive(s) to srch for	*
;*		  pgm ld;  if sldisk is non-zero, then user	*
;*		  specified a drv, and we can just return;	*
;*		  otherwise, drv(s) to setup depend on srchfg:	*
;*		    0        = srch logged drv only;		*
;*		    1        = srch logged drv, then drv a:;	*
;*		   -1(0ffh)  = srch drv a:, then logged drv;	*
;*	entry:	  dskchg flag is assumed to be 0;		*
;*		  sldisk is non-zero if user specified a drv;	*
;*	exit:	  dskchg flag = 0 for no 2nd srch, else set to	*
;*				the drv for the 2nd srch;	*
;*		  comfcb & sldisk set to drv for 1st srch;	*
;*		  if logged drv is a:, dskchg flag is set to 0.	*
;*								*
;****************************************************************

COMSETD:
	LDA	SLDISK		; GET SELECTED DISK
	ORA	A		; TEST FOR NZ, MEANING USER SPEC'D DRV
	RNZ			;  RET IF DRV SPECIFIED (DSKCHG STILL 0)
	LDA	CURDSK		;  ELSE, GET LOGGED DRV
	ORA	A		;   TEST FOR Z, MEANING LOGGED DRV IS A:
	RZ			;    RET IF A: (DSKCHG STILL 0)
	LDA	SRCHFG		;    ELSE, GET SRCHFG
	ORA	A		;     TEST FOR Z, MEANING SRCH LOG'D ONLY
	RZ			;      RET IF LOGGED ONLY (DSKCHG STILL 0)
	STA	DSKCHG		;      ELSE, STORE IN PREP FOR SRCHFG = 1
	CPI	1		;	TEST SRCHFG FOR 1 (SRCH LOG DRV 1ST)
	RZ			;	 RET IF 1 (COMFCB,SLDISK=0, AUTO LD)
	MVI	A,1		;	 ELSE, SETUP 1ST SRCH FOR A:
	STA	COMFCB		;	  PUT IN FCB,
	STA	SLDISK		;	   & AS SELECTED DRV,
	LDA	CURDSK		;	   GET CUR DRV,
	INR	A		;	    (MAKE FCB FORMAT),
	STA	DSKCHG		;	    & PUT IN DSKCHG FOR 2ND SRCH
	RET			;	     (THIS ALSO CORRECTS PUTTING 1
				;	      IN DSKCHG ABOVE)

;................................................................
;
;		END OF SUPPORT SUBROUTINES FOR PGM LD

	PAGE
;****************************************************************
;*								*
;*	SRCHAL	  set srchfg to srch drv a:, then logged drv	*
;*		  for pgm ld (set to -1(0ffh))			*
;*								*
;****************************************************************

SRCHAL:
	MVI	A,0ffh
	STA	SRCHFG
	JMP	WRTCLI



;****************************************************************
;*								*
;*	SRCHLA	  set srchfg to srch logged drv, then drv a:	*
;*		  for pgm ld (set to 1)				*
;*								*
;****************************************************************

SRCHLA:
	MVI	A,1
	STA	SRCHFG
	JMP	WRTCLI



;****************************************************************
;*								*
;*	SRCHLO	  set srchfg to srch logged drv only for pgm ld	*
;*		  (set to 0)					*
;*								*
;****************************************************************

SRCHLO:
	XRA	A
	STA	SRCHFG
	JMP	WRTCLI


;****************************************************************
;*								*
;*	WRTCLI	write srchfg back to the cli			*
;*								*
;****************************************************************

WRTCLI:
	CALL	CLRCFCB
	CALL	STPCLIFNM
	CALL	FNOPENC
	JZ	NOFILE
				; now, get sctr cntning srchfg
	MVI	B,0		; stp <b> as cntr (will become comrec)
	LXI	D,CLIST		; use <de> as cur cli ptr
	PUSH	D
WRCLILP:
	LXI	H,80H		; sz of one logical sctr
	DAD	D
	XCHG			; put cur cli ptr in <de>
	LXI	H,SRCHFG	; put addr(srchfg) in <hl>
	CALL	CMPHLDE		;   & cmpare (hl-de)
	JC	WRCLILX
	INR	B
	POP	H		; take old cur cli ptr off stack
	PUSH	D		;   & put new cur cli ptr on
	JMP	WRCLILP
WRCLILX:
	MOV	A,B		; <b> cnts sctr to write
	STA	COMREC
	POP	D		; get back 'last' cur cli ptr,
	CALL	SETDMA		;   & setup as dma addr
	LXI	H,CMDBUF	; reset cmdptr
	SHLD	CMDPTR
	LXI	D,COMFCB
	PUSH	D
	CALL	FNWRIT		; write file sctr
	POP	D
	CALL	FNCLOS
	JMP	CLI		; (resets dma addr to BUFF)

	PAGE
;****************************************************************
;*								*
;*	DIRI	PRINT DIRECTORY INCLUDING INVISIBLE FILES	*
;*								*
;****************************************************************


DIRI:	MVI	A,TRUE		; SET THE INVISIBLE DISPLAY FLAG TRUE
	STA	INVFLG		; 
				; FALL THROUGH TO SET DSPLY OF ATTR
				;
;****************************************************************
;*								*
;*	DIRA	PRINT DIRECTORY WITH FILE ATTRIBUTES		*
;*								*
;****************************************************************


DIRA:	MVI	A,TRUE		; SET THE ATTRIBUTE DISPLAY FLAG TRUE
	STA	ATTFLG		; 
	JMP	DIRECT


;****************************************************************
;*								*
;*	DIRECT	PRINT DIRECTORY 				*
;*								*
;****************************************************************


DIRECT:
	CALL	MAKDFB		; CREATE AN FCB
	CALL	GETDSK		; SET ACC TO DISK SELECTED
	STA	SLDISK		; SAVE IT THERE
	LXI	H,COMFCB+1	; POINT TO FIRST CHAR IN ARGUMENT
	MOV	A,M		; MAY BE EMPTY REQUEST
	CPI	' '		; IF BLANK
	JNZ	DIR1		; SKIP FILL OF ??? IF NOT BLANK
				; SET COMFCB TO ALL ??? FOR CURRENT DISK
	MVI	B,11		; LENGTH OF FILL ????????.???
DIR0:	MVI	M,'?'		; MOVE IN A QUESTION MARK
	INX	H		; BUMP 
	DCR	B		; AND COUNT DOWN
	JNZ	DIR0		; LOOP TIL DONE
				; NOT A BLANK REQUEST, MUST BE IN COMFCB
DIR1:
	CALL	SEARCHCOM   	; FIRST ONE HAS BEEN FOUND
	JZ	NOFILE		; NO SUCH FILE MESSAGE
	LDA	ATTFLG
	ORA	A
	JZ	DIR2
	  CALL	DSPHDG		; GET HEADING IF ANY FILES (*** OUT)
DIR2:
	LDA	INVFLG
	ORA	A
	JNZ	DIR2A		; DISPLAY, EVEN IF INVISIBLE
	CALL	GETATTR		; ELSE TST FOR INVISIBLE, GET ATTR
	ANI	BITINV		; IS THE FILE INVISIBLE?
	JNZ	DIR5		; YES, DON'T DSPLY
DIR2A:
	LDA	CRFLG		; CK IF 2/4 WIDE TIME YET
	DCR	A
	STA	CRFLG
	LXI	D,SPMSG 	; SPACE MESSAGE
	JNZ	DIR2D		; NOT TIME FOR CRLF, SPACE OUT INSTEAD
	  CALL	CRLF
	  LDA	SLDISK
	  ADI	'A'-1		; MAKE ASCII
	  CALL	PCHAR
	  LDA	ATTFLG
	  ORA	A
	  JZ	DIR2B
	    MVI	A,2		; DSPLYING ATT'S, MAKE 2 WIDE
	    JMP	DIR2C
DIR2B:	  MVI	A,4		; ELSE MAKE 4 WIDE
DIR2C:
	  STA	CRFLG
	  LXI	D,SPMSG+1	; DON'T DSPLY 1ST SPACE
DIR2D:
	CALL	FNBFWR
	MVI	A,' '		; CHARACTER TO PRINT BETWEEN HALVES OF NAME
	CALL	PRDIR		; PRINT DIRECTORY ENTRY AT DIRNUM IN BUFFER
	LDA	ATTFLG
	ORA	A
	JZ	DIR5		; JUMP IF NOT DSPLYING ATTRIBUTES
DIR4D:
	MVI	A,' '
	CALL	PBC
	CALL	GETATTR		;GET THE ATTRIBUTE BYTE
	MOV	B,A
	ANI	BITWRP		;WRITE PROTECT TEST
	MVI	A,' '
	JZ	DIR4A
	MVI	A,'W'
DIR4A:
	CALL	PBC		;PRINT 'W' OR ' '
	MOV	A,B		;GET THE ATTRIBUTE BYTE AGAIN
	ANI	BITSYS		;public (used to be system) file test
	MVI	A,' '
	JZ	DIR4B
	MVI	A,'P'
DIR4B:
	CALL	PBC		;PRINT 'S' OR ' '
	MOV	A,B		;GET THE ATTRIBUTE BYTE AGAIN
	ANI	BITINV		;system (invisible) file test
	MVI	A,' '
	JZ	DIR4C
	MVI	A,'S'
DIR4C:
	CALL	PBC		;PRINT 'I' OR ' '
	MVI	A,' '   	;SPACE FOR THE USER NUMBER
	CALL 	PCHAR
	LHLD	BUFF		;GET BASE OF FCB BFR PTR
	MOV	B,H		;SAVE IN BC
	MOV	C,L
	MOV	B,C		;PREPARE FOR GETATTR
	INR	L		;BUMP BY ONE FOR NEXT BYTE
	MOV	L,C		;SET HL TO BASE OF DIRECTORY QUEUE
	MOV	B,E		;TEMPORARY SAVE FOR ATTR CHARACTER
	CALL	GETATTR		;GET THE ATTRIBUTE BYTE
	ANI	0FH		;GET USER NUMBER
	CALL	DSPUSR		;  & DSPLY IT
;
;	END OF CURRENT ENTRY
;
DIR5:
	CALL	CHKBRK   	;CHECK FOR INTERRUPT AT KEYBOARD
	JNZ	CLI		;ABORT DIRECTORY SEARCH
	CALL	FNSRNX
	JZ	CLI
	JMP	DIR2		;FOR ANOTHER ENTRY


;****************************************************************
;*								*
;*	DSPHDG		DSPLY HEADING FOR DIR W/ATTRIBUTES	*
;*								*
;****************************************************************

DSPHDG:
	LXI	D,HDGMSG
	CALL	FNBFWR
	RET


;****************************************************************
;*								*
;*	DSPUSR		DSPLY USER NUMBER (ENTRY W/USR IN <A>)	*
;*								*
;****************************************************************

DSPUSR:
	PUSH	PSW		; SAVE BINARY VALUE OF USR
	MVI	B,' '		;IF NO TENS DIGIT
	CPI	10
	JC	DSPUS1		;NO TENS
	MVI	B,'1'		;IS GT 10
	SUI	10		;GET THE UNITS DIGIT
;
DSPUS1:
	ORI	'0'		;MAKE IT ASCII
	MOV	C,A
	MOV	A,B		;GET THE FIRST CHAR
	CALL	PBC		;PRINT IT
	MOV	A,C		;GET UNITS CHAR
	CALL	PBC		;PRINT IT
	MVI	A,' '		;AND A SPACE
	CALL	PBC
	POP	PSW		; RESTORE BINARY VALUE OF USR
	RET

	PAGE
;****************************************************************
;*								*
;*	SBSTAT	DSPLY SB80 STATUS (CLI INTRINSIC FLAG SETTINGS)	*
;*								*
;****************************************************************

SBSTAT:
	LXI	D,TFGMSG
	CALL	FNBFWR
	LDA	TRFLAG
	ORA	A
	JZ	SBST1
	LXI	D,FONMSG
	JMP	SBST2
SBST1:
	LXI	D,FOFFMSG
SBST2:
	CALL	FNBFWR
;
	LXI	D,CMPTMSG
	CALL	FNBFWR
	MVI	E,0FFH		; PARM TO GET COMPATIBILITY FLAG
	MVI	C,DGCMPT
	CALL	DOS
	ORA	A
	JZ	SBST3
	LXI	D,SB80MSG
	JMP	SBST4
SBST3:
	LXI	D,CPMMSG
SBST4:
	CALL	FNBFWR
;
	LXI	D,SRCHMSG
	CALL	FNBFWR
	LDA	SRCHFG
	INR	A		; TEST FOR -1 (SRCAL)
	JNZ	SBST5
	LXI	D,SRCALMSG
	JMP	SBST7
SBST5:
	DCR	A		; ELSE, TEST FOR 0 (SRCLO)
	JNZ	SBST6
	LXI	D,SRCLOMSG
	JMP	SBST7
SBST6:
	LXI	D,SRCLAMSG	; ELSE, MUST BE (SRCLA)
SBST7:
	CALL	FNBFWR
;
	LXI	D,CUSRMSG
	CALL	FNBFWR
	MVI	E,0FFH		; PARM TO GET USR
	MVI	C,GTUSRF
	CALL	DOS
	CALL	DSPUSR
;
	LXI	D,SBVERMSG
	CALL	FNBFWR
	LDA	VRSTRNG
	CALL	PCHAR
	LDA	VRSTRNG+1
	CALL	PCHAR
	MVI	A,'/'
	CALL	PCHAR
	LDA	DVSTRNG
	CALL	PCHAR
	LDA	DVSTRNG+1
	CALL	PCHAR
	JMP	CLI

	PAGE
;****************************************************************
;*								*
;*	NEWUSR	SETUP NEW USER NUMBER				*
;*								*
;****************************************************************


NEWUSR:	CALL	MAKNUM		; GET A NUMBER
	CPI	16		; SEE IF A LEGAL NUMBER
	JNC	COMERR		; ILLEGAL USER NUMBER
	MOV	E,A		; USER NUMBER TO [E]
	CALL	SETUSR		; SETUP NEW USER
	JMP	CLI		; AND RETURN TO CLI



;****************************************************************
;*								*
;*	GETATTR	GET ATTRIBUTE OF FILE				*
;*								*
;****************************************************************



GETATTR:
	LDA	DIRNUM		; GET THE CURRENT ENTRY
	ANI	3		; MASK LO ORDER 2 BITS
	RRC
	RRC
	RRC
	MVI	C,FAT		; ATTRIBUTE OFFSET
	JMP	ADDHCF

	PAGE
;****************************************************************
;*								*
;*	ATTRIB	SET FILE ATTRIBUTES				*
;*								*
;****************************************************************


ATTRIB:
	CALL	MAKDFB		; make default fcb from cmd line
	LDA	COMFCB+1	; get 1st char of filename,
	CPI	' '		;   & test for filename entered
	JZ	COMERR		; error if filename not entered
;
	XRA	A		; zero out <b>, which will
	MOV	B,A		;   accumulate attribute bits
;
	LHLD	CMDPTR		; get base of cmd string left to scan
	XCHG			;   & put in <de>
	CALL	SKPBLK		; skip leading blanks,
	CPI	'/'		;   & test for switch char (</>)
	JNZ	COMERR		; error if not </>
ATTR0:
	INX	D		; bump to next char
	CALL	SKPBLK		; skip leading blanks
	JZ	ATTR3		; if end, jmp to complete the operation
	STA	ATTFLG		; else, save last non-0 char,
				;   & test for legal switches
	CPI	'X'		; clear all attributes?
	JZ	CLRATTR
	CPI	'W'		; write protect ?
	JZ	STWRP
	CPI	'P'		; public (used to be system) ?
	JZ	STSYS
	CPI	'S'		; system (invisible) ?
	JNZ	COMERR		; error if not one of the above
	MVI	A,BITINV	; public (used to be system) bit
ATTR2:
	ORA	B		; or-in accumulated bits
	MOV	B,A
	JMP	ATTR0
STWRP:
	MVI	A,BITWRP	; write protect bit
	JMP	ATTR2
STSYS:
	MVI	A,BITSYS	; public (used to be system) bit
	JMP	ATTR2
CLRATTR:
	XRA	A
	MOV	B,A
	JMP	ATTR0
ATTR3:
	LDA	ATTFLG		; get attr flag,
	ORA	A		;   & make sure at least one attr entered
	JZ	COMERR
				;
	LXI	H,FAT		; get displacement to attr byte
	LXI	D,COMFCB	; pt <de> to fcb for dos call & disp add
	DAD	D		; <hl> now pts to attr byte
	MOV	M,B		; put new attributes in fcb,
	MVI	C,ATRF		;   & call dos attr fn
	CALL	DOS
	INR	A		; RETCODE = -1 ON ERROR
	JZ	NOFILE
	JMP	CLI

	PAGE
;****************************************************************
;*								*
;*	DELETE	ERASE FILE(S) FROM DIRECTORY			*
;*								*
;****************************************************************


DELETE:
	CALL	MAKDFB		; CANNOT BE ALL ???'S
	CALL	AMBIG		; GET NUMBER OF <?>'s entered
	CPI	11		; TEST FOR ENTIRE <filenm.typ>
	JNZ	DELFIL		; IF NOT ENTIRE NAME, DO NORMAL DELETE
	LXI	D,RUSURE	; ELSE, USER WANTS TO ERASE ALL...
	CALL	FNBFWR		;   PROMPT 'Are you sure?'
	LXI	D,CMDMAX	; POINT TO BUFFER TO GET RESPONSE
	CALL	FNBFRD
	LXI	H,CMDLEN	; POINT TO RESPONDED # OF CHARACTERS
	DCR	M
	JNZ	CLI		; BAD INPUT
	INX	H
	MOV	A,M
	ORI	20H		; FOLD TO LOWER CASE
	CPI	'y'
	JNZ	CLI
				; OK, ERASE THE ENTIRE DISKETTE
;
DELFIL:
	LXI	D,COMFCB
	CALL	FNERAS
	INR	A		; ERROR RETCODE IS -1, SET TO 0
	JZ	DSPFNF		;   DSPLY FIL NOT FND & EXIT
	JMP	CLI		;   ELSE, ALL DONE

;
DSPFNF:
	POP	PSW		; CLEANUP STACK
	JMP	NOFILE



	PAGE
;****************************************************************
;*								*
;*	DELETE	ERASE FILE(S) FROM DIRECTORY			*
;*		PROMPT USER AT EACH FILE			*
;*								*
;****************************************************************


DELQ:
	CALL	MAKDFB		; MAKE IT AN FCB
	CALL	SEARCHCOM	; SEARCH FOR FILE
	JZ	NOFILE		; JUMP IF NO FILE OF THIS TYPE
	LDA	SLDISK		; SEE IF SPECIAL DISK SELECTED
	ORA	A		; NONE ?
	JNZ	DELQ0		; JUMP IF ONE WAS SELECTED
	LDA	CURDSK		; GET CURRENT DISK
	INR	A		; BUMP BY ONE TO SET BET 1 AND N
DELQ0:	ADI	'A'-1		; MAKE IT A LETTER
	STA	SLDISK		; SAVE THERE IN PREP FOR DRIVE: BEF EA FILE
	LXI	D,DQMSG		; INITIALIZING MESSAGE
	CALL	FNBFWR		; SEND IT
	JMP	DELQ2		; SKIP AROUND NEXT STEP
DELQ1:	LXI	D,COMFCB	; GET ADDRESS OF FCB TO SEARCH
	CALL	FNSRNX		; SEARCH FOR NEXT
	JZ	CLI		; JUMP IF NO MORE
DELQ2:	CALL	CRLF		; SEND CRLF
	LDA	SLDISK		; GET DRIVE OF FILE
	CALL	PCHAR		; PRINT IT
	MVI	A,':'		; GET COLON
	CALL	PCHAR		; PRINT IT TOO
	MVI	A,'.'		; CHARACTER BETWEEN HALVES OF FILE NAME
	CALL	PRDIR		; PRINT DIRECTORY ENTRY
	LXI	D,SPQSP		; PRINT ?
	CALL	FNBFWR
	CALL	GETCOM		; GET RESPONSE, ONLY SINGLE Y ACCEPTED
	LXI	H,CMDLEN	; POINT TO LENGTH ENTERED
	MOV	A,M		; GET LENGTH
	DCR	A		; SET ZERO FLAG IF EXACTLY ONE CHAR
	JNZ	DELQ1		; TRY AGAIN IF NOT Y
	INX	H		; POINT TO FIRST CHARACTER
	MOV	A,M		; GET IT
	CPI	'Y'		; YES ?
	JNZ	DELQ1		; JUMP IF NOT
	CALL	GTDPOS		; GET DIRECTORY POSITION POINTER
	XCHG			; INTO DE
	LXI	H,FCB		; DEFAULT FCB AREA
	PUSH	H		; SAVE FOR LATER
	MVI	C,16		; BYTES TO MOVE
	CALL	MOVE
	LDA	COMFCB		; GET DRIVE AS SPECIFIED BY OPERATOR
	STA	FCB		; AND SAVE IN DEFAULT FCB
	POP	D
	CALL	FNERAS		; ERASE FILE
	JMP	DELQ1



	PAGE
;****************************************************************
;*								*
;*	BATCHIN		CONSOLE BATCH PROCESSOR			*
;*								*
;****************************************************************


BATCHIN:
	CALL	MAKDFB		; GET FCB OF BATCH FILE
	CALL	AMBIG		; CHECK FOR ?
	JNZ	COMERR		; NO ? IN FILE NAME
	LDA	COMFCB		; GET DISK SPECIFIED
	ORA	A		; LOGGED DISK ?
	JNZ	BATCH0		; JUMP IF NOT
	LDA	CURDSK		; GET CURRENT DISK
	INR	A		; MAKE IT 1-N
	STA	COMFCB		; SET SO DRIVE IS NEVER LOGGED DRIVE
BATCH0:	CALL	FNOPENC		; AND ATTEMPT TO OPEN IT
	JZ	NOFILE		; JUMP IF NO GO
	LDA	CURDSK		; GET CURRENT DISK
	STA	LOGDSK		; AND SAVE FOR LATER
	LDA	BTFLAG		; GET BATCH IN PROGRESS FLAG
	ORA	A
	JNZ	BATCHIN0	; JUMP IF ALREADY IN PROGRESS
	LHLD	DOS+1		; GET ADDRESS OF DOS BOTTOM
	INX	H
	SHLD	DOSJMP		; SAVE ADDRESS OF EVENTUAL JUMP TO DISKMON
	MOV	E,M		; GET ADDRESS POINTED TO
	INX	H
	MOV	D,M
	XCHG
	SHLD	DOSSV		; SAVE ACTUAL ENTRY TO DISKMON ROUTINE
	LXI	H,CLIST-3
	PUSH	H
	MVI	A,0C3H		; JUMP INSTR
	MOV	M,A		; BEGIN FAKEOUT OF LATER DOS CALLS
	LXI	D,FAKEOUT	; ADDRESS IN CCP WHERE DOS CALLS GO FIRST
	INX	H
	MOV	M,E		; STORE THIS ADDRESS  BELOW CCP
	INX	H
	MOV	M,D
	POP	H		; GET NEW BOTTOM OF DOS(HA HA)
	SHLD	DOS+1		; SAVE IN LOCATION 5
	XCHG			; INTO D-E
	LHLD	DOSJMP		; GET THIS BACK
	MOV	M,E		; AND PUT FAKEOUT THERE ALSO
	INX	H
	MOV	M,D
	LHLD	WBOOT+1		; ADDRESS OF JUMP TO WARM BOOT IN UIOI
	LXI	D,7		; DISP TO ADDRESS OF CONIN
	DAD	D
	SHLD	CONINJMP	; SAVE ADDRESS OF PLACE WHERE CONIN JUMP WAS
	MOV	E,M		; GET ADDRESS OF REAL CONIN
	INX	H
	MOV	D,M
	XCHG			;  INTO HL
	SHLD	CONINSV		; SAVE ACTUAL CONIN LOC
	LXI	H,SNEAKY	; ADD OF BATCH CONSOLE INPT
	XCHG			;  INTO DE
	MOV	M,D		; MODIFY UIOI JUMP TABLE (OUCH)
	DCX	H
	MOV	M,E
	DCX	H
	DCX	H		; PTS TO CONST ACTUAL ADDRESS
	MOV	D,M		; GET REAL CONSOLE STATUS ROUTINE
	DCX	H
	MOV	E,M
	XCHG
	SHLD	CONSTSV		; SAVE IT
	XCHG
	LXI	D,SNKSTAT	; FAKEOUT CONSOLE STATUS
	MOV	M,E		; STORE OUR FUNNY ONE HERE
	INX	H
	MOV	M,D
	LHLD	WBOOT+1
	INX	H		; ADDRESS OF WARM BOOT ROUTINE
	MOV	E,M
	INX	H
	MOV	D,M		; SAVE REAL WARM BOOT ADDRESS
	XCHG
	SHLD	OLDBOOT		; SAVE FOR LATER
	XCHG
	LXI	D,NEWBOOT	; WARM BOOT FAKEOUT
	MOV	M,D
	DCX	H
	MOV	M,E		; NOW IN TABLE IN UIOI
	MVI	A,1
	STA	BTFLAG		; SET FLAG TO SAY BATCH IN PROGRESS
BATCHIN0:
	LXI	H,BATFCB	; INTERNAL COPY OF BATCH FILE FCB
	LXI	D,COMFCB	; WHERE FCB IS NOW
	MVI	C,32		; BYTES TO MOVE
	CALL	MOVE		; MOVE BYTES
	XRA	A
	STA	COUNT		; CLEAR COUNT IN BATCH BUFFER
	STA	BATNXR		; SET NEXT RECORD TO ZERO
	JMP	CLI
;
;	DOS ENTRY POINT
;
FAKEOUT:
	PUSH	H
	PUSH	D
	PUSH	B
	CALL	BCONSTAT	; GET REAL CONSOLE STATUS
	ORA	A		; CHECK FOR 0FFH
	JZ	FAKEOUT1	; JUMP IF NO CHAR AVAILABLE
	CALL	BCONGET		; GET CONSOLE CHARACTER
	CPI	03H		; CTL-C ?
	JZ	BATCHEND	; JUMP IF SO
	CPI	0BH		; CTL-K ?
	JNZ	FAKEOUT1	; JUMP IF NOT
	CALL	BRESET		; KILL BATCHIN--LEAVE PROGRAM ALONE
	POP	B
	POP	D
	POP	H
	JMP	DOS
FAKEOUT1:
	POP	B
	POP	D
	POP	H
	MOV	A,C		; GET FUNCTION CODE
	CPI	CNBRK 		; CONSOLE STATUS ?
	JZ	BCONSTA		; JUMP IF SO
	LXI	H,0
	DAD	SP		; GET USERS STACK POINTER
	SHLD	USRSTK		; AND SAVE IT
	LXI	SP,DOSSTK	; STACK FOR FAKEOUT
	LXI	H,RETBATCH	; ADDRESS TO RETURN TO AFTER CALL
	PUSH	H		; PUT ON STACK
	LXI	H,CLIST-3
	SHLD	DOS+1		; FIX THIS AGAIN IN CASE NECESSARYY
	CPI	CNREAD		; READ CONSOLE ?
	JZ	BREADCH		; JUMP IF SO
	CPI	CNBFRD		; BUFFERED READ
	JZ	BREADBF		; JUMP IF SO
	LHLD	DOSSV		; ADDRESS OF DISKMON-NOT A TRAPPED FUNCTION
	PCHL			; BYE BYE
;
;	RETURN POINT AFTER DOS FAKEOUT CALL
;
RETBATCH:
	XCHG			; PUT RETURN PARAMETER FROM DOS IN DE
	LHLD	USRSTK		; GET HIS STACK
	SPHL
	XCHG			; GET BACK RETURN PARAMETER FOR HL
	RET			; FINAL RETURN
;
;	CONSOLE STATUS IF SNUCK IN
;
SNKSTAT:
	MVI	C,CNBRK
	JMP	FAKEOUT			; PRETEND DOS CALL MADE
;
;	CONSOLE STATUS ROUTINE
;
BCONSTA:
	XRA	A
	RET			; SORRY, NO CHARACTER READY
;
;	GET REAL CONSOLE STATUS
;
BCONSTAT:
	LHLD	CONSTSV		; GET ADDRESS OF READ CONSOLE STATUS ROUTINE
	PCHL
;
;	GET REAL CONSOLE CHARACTER
;
BCONGET:
	LHLD	CONINSV
	PCHL			; GO THERE
;
;	SPECIAL ENTRY POINT IF TPA SNOOK INTO UIOI
;
SNEAKY:
	MVI	A,1
	STA	SNEAKFLAG	; TURN ON SNEAK FLAG
	MVI	C,CNREAD
	JMP	FAKEOUT		; PRETEND DOS CALL MADE
;
;	READ CHARACTER FROM CONSOLE FILE
;
BREADCH:
	PUSH	H
	PUSH	D
	PUSH	B
	LXI	H,COUNT		; GET COUNT LEFT
	DCR	M
	CM	BREADBAT	; READ NEXT SECTOR IF NONE AROUND
	LHLD	POINTER		; GET PTR TO NEXT CHAR
	MOV	A,M		; GET CHAR
	INX	H		; BUMP PTR
	SHLD	POINTER
	CPI	1AH		; CTL-Z ?
	JZ	BATCHEND	; JUMP IF SO
	PUSH	PSW		; SAVE CHAR
	CALL	BCONOUTP	; OUTPUT CHAR
	POP	PSW
	POP	B
	POP	D
	POP	H
	RET
;
;	BUFFERED READ, D-E PTS TO PROGRAM SPECIFIED BUFFER
;
BREADBF:
	MVI	C,0		; COUNT OF CHAR IN BUFFER
	INX	D
	PUSH	D		; SAVE ADDRESS TO PUT FINAL TALLY
BREADBF1:
	INX	D		; POINT TO NEXT BUFFER POS
BREADBF2:
	CALL	BREADCH		; GET A CHARACTER
	CPI	CR		; END OF LINE ???
	JZ	BEREADBF	; JUMP IF SO
	CPI	3		; CTL-C ?
	JNZ	BREADBF3	; JUMP IF NOT
	MOV	A,C		; GET COUNT SO FAR
	ORA	A		; IS IT 0
	JZ	TRANEND		; JUMP IF SO
	MVI	A,3		; PUT BACK CTL-C
BREADBF3:
	CPI	LF		; LINE FEED ?
	JZ	BREADBF2	; IGNORE
	INR	C		; BUMP COUNT
	STAX	D		; SAVE CHAR
	JMP	BREADBF1	; GET NEXT ONE
BEREADBF:
	XRA	A
	STAX	D		; FILL LAST BYTE WITH A NULL
	POP	H		; RETRIEVE ADDRESS OF LENGTH OF READ BYTE
	MOV	M,C		; SAVE COUNT THERE
	RET			; ALL DONE
;
;	READ SECTOR FROM BATCH FILE
;
BREADBAT:
	CALL	BGDMA		; GET CURRENT DMA ADDRESS
	PUSH	H		; SAVE IT
	LXI	H,BUFFER
	SHLD	POINTER		; SAVE BUFFER START AS BUFFER POINTER
	XCHG
	CALL	BSETDMA		; SET DMA
	LXI	D,BATFCB	; BATCH FILE FCB
	CALL	BREADF		; READ FILE
	POP	D		; GET BACK OLD DMA ADDRESS
	PUSH	PSW		; SAVE STATUS OF READ
	CALL	BSETDMA		; RESET OLD DMA ADDRESS
	POP	PSW		; RETRIEVE FLAGS FROM ACTUAL READ
	ORA	A		; CHECK FOR ERROR
	JNZ	BATCHEND	; JUMP IF SO
	MVI	A,127		; COUNT LEFT IN BUFFER
	STA	COUNT
	RET
;
;	OUTPUT CONSOLE CHAR
;
BCONOUT:
	LXI	H,SNEAKFLAG
	MOV	A,M		; GET SNEAK FLAG
	MVI	M,0		;  AND CLEAR IT
	ORA	A
	RNZ			; NO PRINT IF ON
	MVI	C,CNWRIT	; PRINT CHAR FUNC
	LHLD	DOSSV
	PCHL			; GO AND PRINT IT
;
;	OUTPUT CHAR TO CONSOLE BUT WATCH FOR CONTROLS
;
BCONOUTP:
	MOV	E,A		; INTO E FOR REAL CONOUT
	CPI	CR		; CR ?
	JZ	BCONOUT		; JUMP IF SO
	CPI	LF		; LF ?
	RZ			; IGNORE IF SO
	CPI	' '		; CHECK FOR OTHER CTL
	JNC	BCONOUT		; JUMP IF NOT
	PUSH	PSW		; SAVE REAL CHAR
	LDA	SNEAKFLAG
	PUSH	PSW		; SAVE THIS ALSO
	MVI	E,'^'		; UPARROW FIRST
	CALL	BCONOUT		; DISPLAY IT
	POP	PSW		; GET SNEAKFLAG
	STA	SNEAKFLAG	; RESAVE IT
	POP	PSW		; GET REAL CHAR
	ORI	40H		; MAKE A CAPITAL LETTER
	MOV	E,A		; INTO E
	JMP	BCONOUT		; AND DISPLAY IT
;
;	SET DMA FAKEOUT
;
BSETDMA:
	MVI	C,DDMA
	LHLD	DOSSV
	PCHL
;
;	GET DMA FAKEOUT
;
BGDMA:
	MVI	C,DGDMA
	LHLD	DOSSV
	PCHL
;
;	FAKEOUT READ FILE
;
BREADF:
	MVI	C,DREAD
	LHLD	DOSSV
	PCHL
;
;	END OF BATCHIN FILE
;
BATCHEND:
	CALL	BRESET
	LDA	LOGDSK		; ORIGINAL LOGGED DISK
	MOV	E,A		; INTO E
	CALL	FNSEL		; SELECT DISK FUNC
	LXI	D,CLOSEMSG
	CALL	FNBFWR		; PRINT IT
	JMP	WBOOT
;
;	WARM BOOT FAKEOUT MUST RESET DISK SYSTEM THEN EXIT TO NORMAL TP END
;
NEWBOOT:
	LXI	SP,STACK	;MAKE SURE OF NO STACK CLOBBERING
	LXI	H,TRANEND	;WHERE WE WANT TO END UP AFTER DISK SYS INIT
	PUSH	H		;PUSH ONTO STACK
	MVI	C,DINIT		;INIT SYSTEM FUNCTION NUMBER
	LHLD	DOSSV		;ACTUAL DOS ADDRESS
	PCHL			;GO TO DOS THEN TRANEND
;
;	RESET ALL FAKEOUTS PLEASE
;
BRESET:
	LHLD	DOSSV
	SHLD	CLIST-2		; IF A PROG SAVES DOS-FOOL HIM TOO
	XCHG
	LHLD	DOSJMP		; PUT DOSSV BACK AT DOSJMP
	MOV	M,E
	INX	H
	MOV	M,D
	MVI	A,0C3H		; JUMP INSTRUCTION
	STA	SNEAKY		; BEGIN COUP DE GRAS
	STA	SNKSTAT
	LHLD	CONINSV		; DITTO WITH CONIN
	SHLD	SNEAKY+1	; NO WAY TO SCREW UP NOW
	XCHG
	LHLD	CONINJMP
	MOV	M,E
	INX	H
	MOV	M,D
	DCX	H
	DCX	H
	DCX	H		; PTS TO PLACE FOR ADDR OF REAL CONS STAT
	XCHG
	LHLD	CONSTSV		; GET THIS ADDR
	SHLD	SNKSTAT+1
	XCHG
	MOV	M,D		; AND RESET IT
	DCX	H
	MOV	M,E
	LHLD	OLDBOOT		; GET OLD WARM BOOT ADDRESS
	XCHG
	LHLD	WBOOT+1		; WHERE IT GOES
	INX	H		; IS HERE
	MOV	M,E
	INX	H
	MOV	M,D
	RET



	PAGE
;****************************************************************
;*								*
;*	TYPE 	TYPE A FILE ON CONSOLE				*
;*								*
;****************************************************************


TYPE:	CALL	MAKDFB
	CALL	AMBIG		; CHECK FOR ?
	JNZ	COMERR		; DON'T ALLOW ?'S IN FILE NAME
	CALL	FNOPENC		; OPEN THE FILE
	JZ	NOFILE		; ZERO FLAG INDICATES NOT FOUND
	CALL	CRLF
	LXI	H,BPTR
	MVI	M,255		; READ FIRST BUFFER
TYPE0:				; LOOP ON BPTR
	LXI	H,BPTR
	MOV	A,M
	CPI	128		; END BUFFER
	JC	TYPE1
	PUSH	H		; CARRY IF 0,1,...,127
	LXI	D,COMFCB	; READ ANOTHER BUFFER FULL
	CALL	FNRDNX
	POP	H		; RECOVER ADDRESS OF BPTR
	JNZ	CLI		; HARD END OF FILE
	XRA	A
	MOV	M,A		; BPTR = 0
TYPE1:				; READ CHARACTER AT BPTR AND PRINT
	INR	M		; BPTR = BPTR + 1
	LXI	H,BUFF
	CALL	ADDAHL		; H,L ADDRESSES CHAR
	MOV	A,M
	CPI	EOFILE
	JZ	CLI
	CALL	PCHAR
	CALL	CHKBRK
	JNZ	CLI		; ABORT IF BREAK
	JMP	TYPE0		; FOR ANOTHER CHARACTER



	PAGE
;****************************************************************
;*								*
;*	SAVE	SAVE ARG1 PAGES IN ARG2 FILENAME		*
;*								*
;****************************************************************


SAVE:	CALL	MAKNUM		; RESULTING VALUE IN REGISTER A
	PUSH	PSW		; SAVE IT FOR LATER
;
;	SHOULD BE FOLLOWED BY A FILE TO SAVE THE MEMORY IMAGE
;
	CALL	MAKDFB
	CALL	AMBIG		; CHECK IF AMBIGUOUS REFERENCE
	JNZ	COMERR		; CANNOT BE AMBIGUOUS
	LXI	D,COMFCB
	PUSH	D
	CALL	FNERAS		; EXISTING FILE REMOVED
	POP	D
	CALL	FNCRAT		; CREATE A NEW FILE ON DISK
	JZ	SAVERR		; NO DIRECTORY SPACE
	CALL	FNOPENC		; OPEN THE FILE
	POP	PSW		; #PAGES TO WRITE IS IN A, CHANGE TO #SECTORS
	MOV	L,A
	MVI	H,0
	DAD	H
	
	LXI	D,TRAN		; H,L IS SECTOR COUNT, D,E IS LOAD ADDRESS
SAVE0:				; CHECK FOR SECTOR COUNT ZERO
	MOV	A,H
	ORA	L
	JZ	SAVE1		; MAY BE COMPLETED
	DCX	H		; SECTOR COUNT = SECTOR COUNT - 1
	PUSH	H		; SAVE IT FOR NEXT TIME AROUND
	LXI	H,128
	DAD	D
	PUSH	H		; NEXT DMA ADDRESS SAVED
	CALL	SETDMA		; CURRENT DMA ADDRESS SET
	LXI	D,COMFCB
	CALL	FNWRIT
	POP	D
	POP	H		; DMA ADDRESS, SECTOR COUNT
	JNZ	SAVERR		; MAY BE DISK FULL CASE
	JMP	SAVE0		; FOR ANOTHER SECTOR


SAVERR:				; MUST BE FULL DISK
	LXI	D,FULLMSG
	CALL	FNBFWR
SAVE1:				; END OF DUMP, CLOSE THE FILE
	LXI	D,COMFCB
	CALL	FNCLOS
	JNZ	CLI		; OTHERWISE CANNOT CLOSE FILE
	LXI	D,CLOSMSG
	CALL	FNBFWR
SAVE2:	JMP	CLI



	PAGE
;****************************************************************
;*								*
;*	RENAME	RENAME FILE					*
;*								*
;****************************************************************


RENAME:
	MVI	A,1
	STA	RENFLG
	CALL	MAKDFB		; TRY TO CREATE AN FCB AT COMFCB
	LDA	COMFCB+1	; GET FIRST BYTE OF FILE NAME
	CPI	'='		; EQUAL SIGN ?
	JZ	COMERR		;   YES, COMMAND ERROR
	CPI	' '		; BLANK ?
	JNZ	REN2		;    JUMP IF NOT
REN1:
	LXI	D,FRMMSG	; PROMPT OPERATOR FOR FROM FILE
	CALL	FNBFWR		; OUTPUT MESSAGE
	CALL	GETCOM		; GET A COMMAND LINE
	JZ	CLI		; GIVE UP IF JUST PLAIN CR ENTERED
	JMP	RENAME		; CONTINUE AND TRY AGAIN
;
;	1ST FILE FCB IN COMFCB
;
REN2:
	CALL	GETDSK		; GET SELECTED DISK FOR 1ST FILE
	PUSH	PSW		;   & SAVE IT
	LHLD	CMDPTR		; NOW PTING AT DELIMITER
	XCHG			; PUT IN <DE> FOR SKPBLK
	CALL	SKPBLK
	XCHG			; LOOKING AT 1ST NON-BLK
	MVI	A,'='		; TEST FOR '=' SIGN
	CMP	M
	JNZ	REN3
	STA	SWPFLG		; IF DELIM IS '=', SET SWAP FLAG
	INX	H		;   & BUMP COMPTR PAST '='
	SHLD	CMDPTR
REN3:
	LXI	H,COMFCB+16	; PLACE FOR 2ND FILE
	CALL	MAKFCB		; CREATE AN FCB THERE
	LDA	COMFCB+17	; GET FIRST CHARACTER OF FILE NAME
	CPI	' '		; BLANK ?
	JNZ	REN5		; JUMP IF NOT
REN4:
	LDA	SWPFLG
	ORA	A		; IF SWAP FLAG IS SET,
	JZ	REN4A
	LXI	D,FRMMSG	;   PROMPT FOR 'FROM' FILE,
	JMP	REN4B
REN4A:
	LXI	D,TOMSG		;   ELSE, PROMPT FOR 'TO' FILE
REN4B:
	CALL	FNBFWR		; SEND IT
	CALL	GETCOM		; GET A COMMAND LINE
	JZ	CLI		; GIVE UP IF LONE CR HIT
	JMP	REN3		; TRY AGAIN
;
;	2ND FILE ENTERED
;
REN5:
	POP	B		; RESTORE 1ST FILE'S DISK TO REG B
	CALL	GETDSK		; GET SELECTED DISK FOR 2ND FILE
	CMP	B		; THEY MUST BE THE SAME
	JNZ	COMERR		; JUMP IF NOT, COMMAND ERROR
;
	LDA	SWPFLG		; NOW SWAP POSITIONS IF NECESSARY,
	ORA	A
	CNZ	SWAPFCB
;
	CALL	EDITFCB		;   & EDIT FOR IMPROPER AMBIGUOUS
				;   REFERENCE(S)
;
	XRA	A
	STA	COMFCB+16	; CLEAR DRIVE BYTE OF NEW NAME
	LXI	D,COMFCB	; POINT TO FCB
	CALL	FNRENA		; DO DOS RENAME FUNCTION
	INR	A		; SET TO -1 IF 1ST FILE NOT FOUND
	JZ	NOFILE
	JMP	CLI		; GET NEXT COMMAND
;
;
SWAPFCB:
	MVI	C,16		; use <c> as counter
	LXI	D,COMFCB
	LXI	H,COMFCB+16
SWAP:
	MOV	B,M		; 2nd-file char to <b>
	LDAX	D		; get 1st-file char
	MOV	M,A		;  & put to wnd-file position
	MOV	A,B
	STAX	D		; now put 2nd-file char to 1st-file position
	INX	D
	INX	H
	DCR	C
	JNZ	SWAP
	RET

EDITFCB:
	LXI	H,COMFCB	; pt to name-1 (scnq bumps <hl>
	LXI	B,8		;   before testing)
	CALL	SCNQ		; look for <?>'s in <filenm> flds
	JNZ	COMERR		;   none allowed
	LXI	H,COMFCB+16	; pt to name-1
	LXI	B,8
	CALL	SCNQ
	JNZ	COMERR
;
	LXI	H,COMFCB+8	; pt to typ-1
	LXI	B,3
	CALL	SCNQ
	PUSH	B		; save result
	LXI	H,COMFCB+24	; pt to typ-1
	LXI	B,3
	CALL	SCNQ
	MOV	A,B		; put 2nd result in <A>
	POP	B		; get 1st result back
	CMP	B
	JNZ	COMERR		; if they're either different,
	ORA	A
	RZ
	CPI	3		;   or (~0 & ~3),
	RZ
	JMP	COMERR		;   it's an error

	PAGE
;****************************************************************
;*								*
;*	SETIOBYTE	SET IO BYTE IN HEX			*
;*								*
;****************************************************************


SETIOBYTE:
	LHLD	CMDPTR
	XCHG	
	CALL	SKPBLK		;  BYPASS BLANKS
	JZ	COMERR		;  NO CHARACTERS
	CPI	3AH		;  CHECK IF NON-DIGIT
	JC	STIOBYT1	;  JUMP IF DIGIT
	SUI	7		;  ASSUME A-F AND REDUCE BY 7
STIOBYT1:
	ANI	0FH		;  MASK OF ZONE
	RLC
	RLC	
	RLC	
	RLC			;  ROTATE TO APPROPRIATE SPOT
	MOV	B,A		;  AND SAVE
	INX	D		;  POINT TO NEXT BYTE
	LDAX	D		;  AND GET IT
	CPI	3AH		; CHECK FOR DIGIT
	JC	STIOBYT2	; JUMP IF DIGIT
	SUI	7		; DITTO AS ABOVE
STIOBYT2:
	ANI	0FH		; MASK OFF ZONE
	ORA	B		; OR IN HIGH BITS
	STA	IOBYTE		; SAVE NEW IOBYTE
	JMP	CLI		; ALL DONE



	PAGE
;****************************************************************
;*								*
;*	BPSTATUS	BACKGROUND PRINT STATUS CHECK		*
;*								*
;****************************************************************


BPSTATUS:
	CALL	BPST
	JMP	CLI




;****************************************************************
;*								*
;*	BPRINIT	INITIALIZE BACKGROUND PRINT			*
;*								*
;****************************************************************


BPRINIT:
	MVI	C,BPINIT	;INITIALIZE BPRINT FUNCTION NUMBER
	CALL	DOS		;DO IT
	JMP	CLI



;****************************************************************
;*								*
;*	BPST	DISPLAY BACKGROUND PRINT STATUS			*
;*								*
;****************************************************************


BPST:
	CALL	CRLF		; SEND CRLF
	MVI	C,BPSTAT
	CALL	DOS
	LXI	H,BPMSGS	; BASE ADDR OF MSG TABLE
	INR	A		; BUMP BY ONE TO MAKE 0FFH=0
	ADD	A		; DOUBLE STAT
	CALL	ADDAHL		; ADD TO BASE OF TABLE
	MOV	E,M		; GET MSG ADDRESS
	INX	H
	MOV	D,M
	CALL	FNBFWR		; PRINT MSG
	JMP 	CRLF		; DO CRLF



	PAGE
;****************************************************************
;*								*
;*	BPMSGS	BACKGROUND PRINT MESSAGES			*
;*								*
;****************************************************************


BPMSGS:
	DW	OMSG		; STAT=0FFH=OFF
	DW	DMSG		; STAT=0
	DW	RMSG		;      1
	DW	SMSG		;      2
	DW	PMSG		;      3
	DW	UMSG		;      4
	DW	FMSG		;      5
;



;****************************************************************
;*								*
;*	SUSPRINT	SUSPEND BACKGROUND PRINT		*
;*								*
;****************************************************************


SUSPRINT:
	MVI	C,SUSPRN
	CALL	DOS
	JMP	CLI



;****************************************************************
;*								*
;*	RESTPRINT	RESTART BACKGROUND PRINT		*
;*								*
;****************************************************************


RESTPRINT:
	MVI	C,RSTPRN
	CALL	DOS
	JMP	CLI



	PAGE
;****************************************************************
;*								*
;*	QUEFILE	QUE A FILE TO PRINT				*
;*								*
;****************************************************************



QUEFILE:
	MVI	A,QUEFIL	;GET AND SAVE QUEUE FILE FUNCTION
BPTASK:
	STA	QCOM		;DEQUEUE ENTERS HERE
	CALL	MAKDFB
	CALL	AMBIG
	JNZ	COMERR		;NOT A VALID FILE NAME
	LDA	COMFCB		;MUST SEE IF DRIVE 0-CHANGE TO LOG DISK #
	ORA	A
	JNZ	BPTSK1		;JUMP IF OK
	CALL	GETLOG		;GET LOGGED DRIVE
	INR	A		;SET TO 1-N
	STA	COMFCB		;SAVE IN FCB
BPTSK1:
	CALL	FNOPENC
	JZ	NOFILE		;IF FILE OPENS, ITS THERE!!
	LXI	D,COMFCB
	LDA	QCOM
	MOV	C,A		;PREPARE FOR DOS CALL
	CALL	DOS		;QUEUE OR DEQUEUE
	ORA	A		;SUCCESSFULL?
	JZ	CLI
	LXI	D,QUEFULL	;NO
	CALL	FNBFWR
	JMP	CLI



	PAGE
;****************************************************************
;*								*
;*	DEQUEFILE	DE-QUEUE A FILE				*
;*								*
;****************************************************************


DEQUEFILE:
	MVI	A,UNQFIL
	JMP	BPTASK
;




;****************************************************************
;*								*
;*	KILLPRINT	KILL BACKGROUND PRINT TASK		*
;*								*
;****************************************************************


KILLPRINT:
	LXI	D,KPMSG		;INITIAL MESSAGE FOR OLD STATUS
	CALL	FNBFWR
	CALL	BPST		;PRINT OLD STATUS
	MVI	C,KILPRN
	CALL	DOS
	JMP	WBOOT		;RESTORE OLD DOS




	PAGE
;****************************************************************
;*								*
;*	SETCLI		SET USER CLI <DRV:FILENAME.TYP>		*
;*								*
;****************************************************************

SETCLI:
	CALL	MAKDFB		; MAKE DEFAULT FCB FROM CMD LINE
	LDA	COMFCB+1	; GET 1ST CHAR OF FILENAME,
	CPI	' '		;   & TEST FOR FILENAME ENTERED
	JNZ	STCLI1		; JUMP IF FILENAME ENTERED
	LXI	D,CLIDRV	; ELSE, USE DEFAULT ('1,SYSTEM  CLI')
	JMP	STCLI2
STCLI1:
	LXI	D,COMFCB
STCLI2:
	MVI	C,DSCLI		; DOS FN TO SET USER CLI
	CALL	DOS
	JMP	CLI



;****************************************************************
;*								*
;*	TRON/TROFF	CASE TRANSLATION SWITCH			*
;*								*
;****************************************************************


TRON:
	MVI	A,1
	JMP	TROF1
TROFF:
	XRA	A
TROF1:
	STA	TRFLAG
	JMP	CLI



	PAGE
;*****************************************************************
;*****************************************************************
;**								**
;**		     CLI SUPPORT ROUTINES			**
;**								**
;*****************************************************************
;*****************************************************************





;****************************************************************
;*								*
;*	GETCOM	GET CONSOLE COMMAND, STUFF END DELIMETER, AND 	*
;*		OPTIONALLY XLATE TO UPPER CASE.			*
;*								*
;****************************************************************


GETCOM:
	LXI	D,CMDMAX	; POINT TO BUFFERED READ BUFFER
	CALL	FNBFRD		; DO READ
	LXI	H,CMDBUF	; POINT TO FIRST INPUT CHAR
	SHLD	CMDPTR		; SET BUFFER PTR THERE
	DCX	H		; BACK UP TO COUNT
	MOV	A,M		; GET COUNT
	ORA	A		; TEST IT
	RZ			; RETURN IF EMPTY
	PUSH	PSW		; SAVE FLAG
	MOV	D,A		; GET COUNT TO D
	LDA	TRFLAG		; GET TRANSLATE FLAG
	ORA	A		; TEST IT
	JNZ	GETC0		; JUMP IF TRANSLATION
	MOV	A,D		; GET COUNT BACK TO A
	INX	H		; PUT HL BACK TO FIRST BYTE OF STRING
	CALL	ADDAHL		; COMPUTE PTR TO ONE BYTE PAST END
	JMP	GETC2		; CONTINUE THERE


GETC0:	INX	H		; POINT TO FIRST CHARACTER
GETC1:	MOV	A,M		; GET CMD CHARACTER
	CALL	TRCASE		; TRANSLATE CASE IF NECESSARY
	MOV	M,A		; SAVE THE TRANSLATED CHARACTER
	INX	H		; BUMP TO NEXT CHARACTER
	DCR	D		; COUNT DOWN
	JNZ	GETC1		; JUMP IF MORE TO GO
GETC2:	MVI	M,0		; PUT NULL THERE AT STRING END
	POP	PSW		; RESTORE/RESET ZERO FLAG
	RET




	PAGE
;****************************************************************
;*								*
;*	MAKFCB	CONSTRUCT FCB					*
;*		ENTRY	[DE] POINTS TO COMMAND LINE		*
;*			[HL] POINTS TO FCB BUFFER		*
;*								*
;****************************************************************


MAKDFB:	LXI	H,COMFCB	; POINT TO DEFAULT FCB
MAKFCB:	PUSH	H		; FCB RESCANNED AT END
	XRA	A
	STA	SLDISK		; CLEAR SELECTED DISK (IN CASE A:...)
	LHLD	CMDPTR
	XCHG			; COMMAND ADDRESS IN D,E
	CALL	SKPBLK		; TO FIRST NON-BLANK CHARACTER
	POP	H		; D,E HAS COMMAND, H,L HAS FCB ADDRESS
				; LOOK FOR PRECEDING FILE NAME A: B: ...
	LDAX	D
	ORA	A
	JZ	SETCUR0		; USE CURRENT DISK IF EMPTY COMMAND
	SBI	'A'-1
	MOV	B,A		; DISK NAME HELD IN B IF : FOLLOWS
	INX	D
	LDAX	D
	CPI	':'
	JZ	SETDSK		; SET DISK NAME IF :

SETCUR:				; SET CURRENT DISK
	DCX	D		; BACK TO FIRST CHARACTER OF COMMAND
SETCUR0:MVI	M,0		; PUT ZERO AS DRIVE
	JMP	SETNAME
SETDSK:	MOV	A,B		; PUT NEW SELECTED DISK IN A
	STA	SLDISK		; MARK AS DISK SELECTED
	MOV	M,A
	INX	D		; PAST THE :
SETNAME:			; SET THE FILE NAME FIELD
	MVI	B,8		; FILE NAME LENGTH (MAX)
SETNAM0:	
	CALL	DELIM		; TEST FOR DELIMITER
	JZ	PADNAME		;   YES, PAD REMAINDER OF NAME FLD
	INX	H		;   NO, TEST FOR AMBIG
	CPI	'*'
	JNZ	SETNAM1		;     NOT AMBIG, CONTINUE
	MVI	M,'?'		;     AMBIG, MUST BE <?>'s,
	JMP	SETNAM2		;       JMP TO DEC COUNT
	;
SETNAM1:
	MOV	M,A		; STORE CHARACTER TO FCB
	INX	D
SETNAM2:
	DCR	B		; COUNT DOWN LENGTH
	JNZ	SETNAM0
				; END OF NAME, TRUNCATE REMAINDER
TRNAME:	CALL	DELIM
	JZ	SETTY		; SET TYPE FIELD IF DELIMITER
	INX	D
	JMP	TRNAME
PADNAME:
	CALL	PAD
SETTY:	MVI	B,3			; SET THE TYPE FIELD
	CPI	'.'			; TEST FOR .
	JNZ	PADTY			; SKIP THE TYPE FIELD IF NO .
	INX	D			; PAST THE ., TO THE FILE TYPE FIELD
SETTY0:					; SET THE FIELD FROM THE COMMAND BUFFER
	CALL	DELIM
	JZ	PADTY
	INX	H
	CPI	'*'
	JNZ	SETTY1
	MVI	M,'?'			;SINCE * SPECIFIED
	JMP	SETTY2
SETTY1:					;NOT A *, SO COPY TO TYPE FIELD
	MOV	M,A
	INX	D
SETTY2:					;DECREMENT COUNT AND GO AGAIN
	DCR	B
	JNZ	SETTY0
					;END OF TYPE FIELD, TRUNCATE
TRTYP:
	CALL	DELIM
	JZ	EFILL
	INX	D
	JMP	TRTYP
PADTY:	CALL	PAD			; PAD 
EFILL:					;END OF THE FILENAME/FILETYPE FILL
					;SAVE COMMAND ADDRESS
					;FILL THE REMAINING FIELDS FOR THE FCB
	MVI	B,3
EFILL0: INX	H
	MVI	M,0
	DCR	B
	JNZ	EFILL0
	XCHG
	SHLD	CMDPTR			;SET NEW STARTING POINT
	RET



	PAGE
;****************************************************************
;*								*
;*	PAD	PAD WITH BLANKS					*
;*		ENTRY	[B] IS NUMBER OF BLANKS TO INSERT	*
;*			[HL] POINTS TO BUFFER			*
;*								*
;****************************************************************


PAD:	
	INX	H
	MVI	M,' '
	DCR	B
	JNZ	PAD
	RET




;****************************************************************
;*								*
;*	AMBIG	COUNT QUESTION MARKS IN COMFCB			*
;*								*
;****************************************************************


AMBIG:
	LXI	H,COMFCB
	LXI	B,11			;B=0, C=8+3
SCNQ:	INX	H
	MOV	A,M
	CPI	'?'
	JNZ	SCNQ0
	INR	B
SCNQ0:	DCR	C
	JNZ	SCNQ
	MOV	A,B
	ORA	A
	RET



	PAGE
;****************************************************************
;*								*
;*	GETDSK	RETURN DRIVE TO USE IN [A]			*
;*		USE DEFAULT DRIVE IF NONE SPECIFIED		*
;*								*
;****************************************************************


GETDSK:
	LDA	SLDISK		; GET SELECTED DISK
	ORA	A		; TEST IF NOT ZERO
	RNZ			; RETURN IF A DRIVE WAS INDICATED
	LDA	CURDSK		; GET CURRENT DISK
	INR	A		; BUMP BY ONE SO IS 1 TO N
	RET			; ALL DONE



;****************************************************************
;*								*
;*	NOFILE							*
;*								*
;****************************************************************


NOFILE:
	LXI	D,EMSG
	CALL	FNBFWR
	JMP	CLI		; GET NEXT COMMAND



;****************************************************************
;*								*
;*	COMERR		ERROR IN COMMAND LINE			*
;*								*
;****************************************************************


COMERR:
	LXI	D,CMEMSG	; GET MESSAGE
	CALL	FNBFWR		; SEND ID
	JMP	CLI		; BACK TO CLI



	PAGE
;****************************************************************
;*								*
;*	PRDIR	PRINT A DIRECTORY ENTRY AT DIRNUM		*
;*								*
;****************************************************************


PRDIR:
	PUSH	PSW		; SAVE IN BETWEEN CHARACTER
	CALL	GTDPOS		; GET POINTER TO DIRECTORY ENTRY
	INX	H		; MOVE PASSED TYPE BYTE
	MVI	B,8		; NUMBER OF CHAR IN NAME
	CALL	PRDIRL		; PRINT CHARACTERS
	POP	PSW		; GET IN BETWEENER
	PUSH	H		; SAVE BUFFER PTR
	CALL	PCHAR		; PRINT A CHARACTER
	POP	H		; GET BACK BUFF PT
	MVI	B,3		; NUMBER OF CHAR IN EXT
PRDIRL:
	PUSH	H
	MOV	A,M		; GET A CHAR
	CALL	PBC		; PRINT AND SAVE BC
	POP	H		; GET BACK PTR
	INX	H		; BUMP PTR
	DCR	B		; DOWN COUNT
	JNZ	PRDIRL		; JUMP IF MORE
	RET			; DONE



;****************************************************************
;*								*
;*	GTDPOS	SET [HL] TO POSITION IN DIRBUF OF ENTRY		*
;*		MULT DIRNUM BY 32				*
;*								*
;****************************************************************


GTDPOS:
	LDA	DIRNUM		; GET DIRECTORY NUMBER
	RRC			; ROTATE LOWW TWO BITS INTO POSITION
	RRC
	RRC
	ANI	60H		; MASK OFF UNNEEDED BITS
	LXI	H,BUFF		; BASE OF BUFFER
	JMP	ADDAHL		; ADD A TO HL AND DONE



	PAGE
;
;****************************************************************
;*								*
;*	MAKNUM	 CONVERT CONTENTS OF FILBUF INTO A NUMBER	*
;*								*
;****************************************************************
;
;
MAKNUM:	CALL	MAKDFB			; GET COMMAND
	LDA	SLDISK			; SEE IF DISK SPECIFIED
	ORA	A			; IF SO,
	JNZ	COMERR			; THEN BAD COMMAND
	LXI	H,COMFCB+1		; [HL] POINTS TO ASCII NUMBER
	LXI	B,11			; 0 TO [C], 11 TO [B]
MAKNM1:	MOV	A,M			; GET CHARACTER
	CPI	' '			; IS IT A SPACE
	JZ	MAKNM2			; YES, THEN NUMBER FINISHED
	INX	H			; BUMP POINTER
	SUI	'0'			; STRIP ASCII BIAS
	CPI	10			; CHECK FOR LEGAL NUMBER
	JNC	COMERR			; NOT LEGAL, THEN BAD NUMBER
	MOV	D,A			; NUMBER TO [D]
	MOV	A,B			; COUNT TO [A]
	ANI	0E0H			; CHECK FOR TOO MANY DIGITS
	JNZ	COMERR			; BAD IF SO
	MOV	A,B			; GET COUNT
	RLC				; * 2
	RLC				; * 4
	RLC				; * 8
	ADD	B			; * 9
	JC	COMERR			; BAD IF CARRY
	ADD	B			; * 10
	JC	COMERR			; BAD IF CARRY
	ADD	D			; ADD LEAST SIGNIFICANT DIGIT
	JC	COMERR			; BAD IF CARRY
	MOV	B,A			; NEW TOTAL TO [B]
	DCR	C			; COUNT DOWN
	JNZ	MAKNM1			; LOOP TILL DONE	
	RET
;
MAKNM2:	MOV	A,M			; GET NEXT CHARACTER
	CPI	' '			; TEST FOR SPACE
	JNZ	COMERR			; BAD ENTRY IF NOT SPACE
	INX	H			; BUMP POINTER
	DCR	C			; COUNT DOWN
	JNZ	MAKNM2			; TILL BUFFER EXHAUSTED
	MOV	A,B			; NUMBER TO [A]
	RET				; AND DONE
;
;
;
	PAGE
;****************************************************************
;*								*
;*	MOVENAME	MOVE 3 CHARS FROM [HL] TO [DE]		*
;*								*
;****************************************************************


MOVENAME:
	MVI	B,3


;****************************************************************
;*								*
;*	MOVE0	MOVE [B] BYTES FROM [HL] TO [DE]		*
;*								*
;****************************************************************


MOVE0:	MOV	A,M
	STAX	D
	INX	H
	INX	D
	DCR	B
	JNZ	MOVE0
	RET



	PAGE
;*****************************************************************
;*****************************************************************
;**								**
;**			UTILITY ROUTINES			**
;**								**
;*****************************************************************
;*****************************************************************




;****************************************************************
;*								*
;*	SKPBLK		SKIP LEADING BLANKS			*
;*								*
;****************************************************************


SKPBLK:	LDAX	D
	ORA	A
	RZ				;TREAT END OF LINE AS BLANK
	CPI	' '
	RNZ
	INX	D
	JMP	SKPBLK





;****************************************************************
;*								*
;*	TRCASE	XLATE TO UPPER CASE				*
;*								*
;****************************************************************


TRCASE:	CPI	'a'		; CHECK FOR RANGE
	RC			; RETURN IF SMALLER THAN SMALL A
	CPI	'z'+1		
	RNC			; RETURN IF BIGGER THAN SMALL Z
	ANI	0DFH		; TURN OFF CASE BIT
	RET			; DONE



;****************************************************************
;*								*
;*	ADDHCF	BUFF + [A] + [C]				*
;*		RESULT IN [HL]					*
;*								*
;****************************************************************


ADDHCF:				;BUFF + A + C TO H,L FOLLOWED BY FETCH
	LXI	H,BUFF
	ADD	C
	CALL	ADDAHL
	MOV	A,M
	RET


;****************************************************************
;*								*
;*	ADDAHL	ADD [A] TO [HL]					*
;*								*
;****************************************************************


ADDAHL:	ADD	L
	MOV	L,A
	RNC
	INR	H
	RET


;****************************************************************
;*								*
;*	CMPHLDE		COMPARE <HL> & <DE>  (<HL> - <DE>)	*
;*		RETURNS	CARRY SET IF <DE> > <HL>		*
;*		NEITHER REGISTER PR ALTERED			*
;*								*
;****************************************************************

CMPHLDE:
	MOV	A,L
	SUB	E
	MOV	A,H
	SBB	D
	RET

	PAGE
;****************************************************************
;*								*
;*	DELIM 	SEARCH FOR DELIMITER				*
;*								*
;*	   RETURNS:	Z SET IF DELIMITER FOUND		*
;*								*
;****************************************************************


DELIM:	LDAX	D
	ORA	A		; TEST FOR LAST CHARACTER
	RZ			;   YES (THE FINAL DELIMITER)
	CPI	' '		;   NO, TEST FOR OTHER DELIMITERS
	JC	COMERR		; NON GRAPHIC IS AN ERROR
	RZ			; DELIMITERS ARE:  BLANK,
	CPI	'.'
	RZ			;   PERIOD,
	CPI	':'
	RZ			;   & COLON
;
	LDA	RENFLG		; TEST FOR RENAME IN PROGRESS
	ORA	A
	LDAX	D		;   (GET CHAR BACK INTO <A>)
	JNZ	DELIM1		; RENAME IN PROGRESS, JMP
	ORA	A		; ELSE, RESTORE NZ FLAG,
	RET			;   NO DELIMITER FOUND
DELIM1:
	CPI	'='		; FOR RENAME, EQUAL SIGN ALSO A DELIMITER
	RET			; IF NZ, NO DELIMITER FOUND

	PAGE
;*****************************************************************
;*****************************************************************
;**								**
;**		     	DOS CALLS				**
;**								**
;*****************************************************************
;*****************************************************************




;****************************************************************
;*								*
;*	CRLF		PRINT CARRIAGE RET/ LINE FEED		*
;*								*
;****************************************************************


CRLF:	MVI	A,CR		; GET A CARRIAGE RETURN
	CALL	PCHAR		; PRINT IT
	MVI	A,LF		; GET A LINE FEED
				; AND FALL THRU TO PCHAR



;****************************************************************
;*								*
;*	PRCHAR		SEND CHAR IN [A] TO CONSOLE		*
;*								*
;****************************************************************


PCHAR:	MOV	E,A
	MVI	C,CNWRIT
	JMP	DOS



;****************************************************************
;*								*
;*	PBC	SEND CHAR IN [A] TO CONSOLE, SAVE [BC] PAIR	*
;*								*
;****************************************************************


PBC:	PUSH	B		;PRINT CHARACTER, BUT SAVE B,C REGISTERS
	CALL	PCHAR
	POP	B
	RET



	PAGE
;****************************************************************
;*								*
;*	FNBFRD	DO BUFFERED INPUT FROM CONSOLE			*
;*								*
;****************************************************************


FNBFRD:
	MVI	C,CNBFRD
	JMP	DOS



;****************************************************************
;*								*
;*	FNBFWR	DO BUFFERED WRITE TO CONSOLE			*
;*								*
;****************************************************************


FNBFWR:
	MVI	C,CNBFWR
	JMP	DOS



	PAGE
;****************************************************************
;*								*
;*	SELECT	SELECT DRIVE					*
;*		ENTRY	DRIVE NUMBER IN [A]			*
;*								*
;****************************************************************


SELECT:	MOV	E,A
FNSEL:
	MVI	C,DSEL
	JMP	DOS



;****************************************************************
;*								*
;*	FNINIT	INITIALIZE DISK SYSTEM				*
;*								*
;****************************************************************


FNINIT:
	MVI	C,DINIT
	JMP	DOS



;****************************************************************
;*								*
;*	COMOPN	OPEN FILE AT COMFCB				*
;*								*
;****************************************************************


COMOPN:
	LXI	D,COMFCB
	XRA	A
	STA	COMREC		;ZERO OUT NEXT R/W RECORD
				; FALL THRU TO OPEN FILE



	PAGE
;****************************************************************
;*								*
;*	FNOPENC		OPEN FILE FUNCTION			*
;*								*
;****************************************************************


FNOPENC:
	LXI	D,COMFCB
	XRA	A
	STA	COMREC		; CLEAR OUT NEXT R/W POINTER
FNOPEN:
	MVI	C,DOPEN
FNOPN1:
	CALL	DOS
	STA	DIRNUM		;GET DIRECTORY NUMBER RETURNED FROM CALL
	INR	A		;WILL BE SET TO ZERO IF END OF DIR
	RET



;****************************************************************
;*								*
;*	FNCLOS	CLOSE FILE FUNCTION				*
;*								*
;****************************************************************


FNCLOS:	MVI	C,DCLOS
	JMP	FNOPN1



	PAGE
;****************************************************************
;*								*
;*	SEARCHCOM	SEARCH FOR FILE IN COMFCB		*
;*								*
;****************************************************************


SEARCHCOM:
	LXI	D,COMFCB



;****************************************************************
;*								*
;*	FNSRCH	SEARCH FOR FILE FUNCTION			*
;*								*
;****************************************************************


FNSRCH:
	MVI	C,DSRCH
	JMP	FNOPN1



;****************************************************************
;*								*
;*	LDPGM	LOAD A PROGRAM AND EXECUTE			*
;*								*
;****************************************************************


LDPGM:
	MVI	C,DLDPGM
	CALL	DOS
	RET


	PAGE
;****************************************************************
;*								*
;*	FNSRNX	SEARCH FOR NEXT OCCURANCE OF A FILE		*
;*								*
;****************************************************************


FNSRNX:	MVI	C,DSRNX
	JMP	FNOPN1



;****************************************************************
;*								*
;*	FNERAS	DELETE FILE FUNCTION				*
;*								*
;****************************************************************


FNERAS:				
	MVI	C,DERAS
	JMP	DOS



;****************************************************************
;*								*
;*	DISKREADC	READ FILE AT COMFCB			*
;*								*
;****************************************************************


DISKREADC:
	LXI	D,COMFCB


	PAGE
;****************************************************************
;*								*
;*	FNRDNX	READ FILE FUNCTION				*
;*								*
;****************************************************************


FNRDNX:
	MVI	C,DREAD
	CALL	DOS
	ORA	A
	RET




;****************************************************************
;*								*
;*	FNWRIT	WRITE BUFFER TO DISK FILE			*
;*								*
;****************************************************************


FNWRIT:
	MVI	C,DWRIT
	CALL	DOS
	ORA	A
	RET




;****************************************************************
;*								*
;*	FNCRAT	CREATE FILE FUNCTION				*
;*								*
;****************************************************************


FNCRAT:
	MVI	C,DCRAT
	JMP	FNOPN1



	PAGE
;****************************************************************
;*								*
;*	FNRENA	RENAME A FILE FUNCTION				*
;*								*
;****************************************************************


FNRENA:
	MVI	C,DRENA
	JMP	DOS



;****************************************************************
;*								*
;*	CHKBRK	CHECK IF CONSOLE CHARACTER WAITING		*
;*								*
;****************************************************************



CHKBRK:
	MVI	C,CNBRK
	CALL	DOS
	ORA	A
	RZ
	MVI	C,CNREAD
	CALL	DOS		;CHARACTER CLEARED
	ORA	A
	RET




;****************************************************************
;*								*
;*	GETLOG		RETURN CURRENTLY LOGGED IN DRIVE	*
;*								*
;****************************************************************


GETLOG:
	MVI	C,DGDSK
	JMP	DOS



	PAGE
;****************************************************************
;*								*
;*	MOVE	MOVE <C> BYTES FROM <DE> TO <HL>		*
;*								*
;****************************************************************


MOVE:	LDAX	D
	MOV	M,A
	INX	D
	INX	H
	DCR	C
	JNZ	MOVE
	RET


;****************************************************************
;*								*
;*	STPCLIFNM	MOVE CLI DRV/FNM INTO COMFCB		*
;*								*
;****************************************************************

STPCLIFNM:
	LXI	D,CLIDRV
	LXI	H,COMFCB
	MVI	C,12
	CALL	MOVE
	RET


;****************************************************************
;*								*
;*	CLRCFCB		ZERO OUT COMFCB				*
;*	CLEAR		ZERO OUT <C> BYTES AT <HL>		*
;*								*
;****************************************************************

CLRCFCB:
	LXI	H,COMFCB
	MVI	C,32
CLEAR:
	XRA	A	; PREP FOR DAY WHEN CTR IS IN <BC>
	MOV	M,A
	INX	H
	DCR	C
	JNZ	CLEAR
	RET

;****************************************************************
;*								*
;*	SETDMA	SET DMA ADDRESS					*
;*								*
;****************************************************************


SETDMA:
	MVI	C,DDMA
	JMP	DOS


;****************************************************************
;*								*
;*	GETUSR		RETURN CURRENT USER IN [A]		*
;*								*
;****************************************************************


GETUSR:
	MVI	E,0FFH
	MVI	C,GTUSRF
	JMP	DOS


;****************************************************************
;*								*
;*	SETUSER		SET USER NUMBER				*
;*		ENTRY	USER NUMBER IN [E]			*
;*								*
;****************************************************************


SETUSR:
	MVI	C,STUSRF
	JMP	DOS


	PAGE
;****************************************************************
;*								*
;*	SELDSK	SELECT DISK					*
;*		ENTRY	DRIVE NUMBER IN [A]			*
;*								*
;****************************************************************


SELDISK:
	MOV	C,A		;DRIVE TO C
	LXI	D,24
	JMP	SPGODOS



;****************************************************************
;*								*
;*	RDCHAR	READ 1 CHARACTER FROM CONSOLE, NO ECHO		*
;*								*
;****************************************************************


RDCHAR:	LXI	D,6
SPGODOS:
	LHLD	WBOOT+1
	DAD	D			; OFFSET TO ADDRESS OF JUMP TO ROUTINE
	PCHL				; GO TO CALLED ROUTINE



;****************************************************************
;*								*
;*	SETCPM/SETSB80	SET CPM/SB80 COMPATIBILITY		*
;*								*
;****************************************************************


SETCPM:
	MVI	E,0
	JMP	SETCMPT

SETSB80:
	MVI	E,1
SETCMPT:
	MVI	C,DSCMPT
	CALL	DOS
	JMP	CLI



	PAGE
;*****************************************************************
;*****************************************************************
;**								**
;**		     	DATA AREA				**
;**								**
;*****************************************************************
;*****************************************************************




CLIDRV:		DB	1,'SYSTEM  CLI'
OLDBOOT:	DW	0	; WARM BOOT ADDRESS IN UIOI JMP TABLE
LOGDSK:		DB	0	; LOGGED IN DISK DRIVE NUMBER
SNEAKFLAG:	DB	0	; FOR SNEAKY TRANSIENT PROGRAMS
DOSJMP: 	DW	0	; ADDRESS OF JUMP TO DISKMON
DOSSV:		DW	0	; ADDRESS OF DISKMON
CONINSV:	DW	0	; ADDRESS OF OLD CONIN ROUTINE
CONINJMP:	DW	0	; ADDRESS OF WHERE CONIN JUMP IS
CONSTSV: 	DW	0	; ADDRESS OF OLD CONSOLE STATUS ROUTINE
COUNT:		DB	0	; COUNT OF CHARACTERS IN BATCH BUFFER
POINTER: 	DW	BUFFER	; ADDRESS OF PTR TO BATCH BUFFER
BUFFER:		DS	128	; BATCH BUFFER
BATFCB:		DS	32	; BATCH FILE FCB
BATNXR:		DB	0	;    "   "   RC
USRSTK:		DW	0	; PLACE TO STORE USER STACK PTR ON DOS CALL

		DS	20
DOSSTK		EQU	$



	PAGE
;****************************************************************
;*								*
;*	(CLI) -	[MSGBUF:]	MESSAGES			*
;*								*
;****************************************************************

MSGBUF		EQU	$		; MSGBUF:

CLOSEMSG:
		DB	CR,LF,'End Batch',CR,LF,DLR

LOADMSG:
		DB	'Load error',DLR
COMTYPE: 	DB	'COM'		; FOR COM FILES
QUEFULL:	DB	CR,LF,'Q error ',CR,LF,DLR
KPMSG:		DB	CR,LF,'Status was : ',DLR
RMSG:		DB	'Ready',DLR
SMSG:		DB	'Suspended',DLR
FMSG:		DB	'File error',DLR
PMSG:		DB	'Print fault',DLR
UMSG:		DB	'? error',DLR
DMSG:		DB	'Dormant',DLR
OMSG:		DB	'Off',DLR
;
HDGMSG:
		DB	CR,LF
		DB	'D: FILENAME.EXT WPS Usr'
		DB	'   FILENAME.EXT WPS Usr'
		DB	CR,LF,'$'
;
SPMSG:		DB	' : $'		;SPC BETW FILES (TO MATCH CP/M)
EMSG:
		DB	CR,LF,'File not found',CR,LF,DLR
SGNMSG:
		DB	CR,LF,'User ? $'
RUSURE:
		DB	CR,LF,'Are you sure ? $'
FULLMSG:
		DB	CR,LF,'No Space',CR,LF,DLR
CLOSMSG:
		DB	CR,LF,'Cannot Close'
CRLFMS:		DB	CR,LF,DLR
FRMMSG:
		DB	CR,LF,'From ? $'
TOMSG:
		DB	CR,LF,'To ? $'
CMEMSG:
		DB	CR,LF,'Command error',CR,LF,DLR
DQMSG:
		DB	CR,LF,LF,'Files deleted:$'
SPQSP:		DB	' ? $'

	PAGE
TFGMSG:
		DB	CR,LF
		DB	'   '
		DB	'Translate     = ',DLR
CMPTMSG:
		DB	CR,LF
		DB	'   '
		DB	'Compatibility = ',DLR
SRCHMSG:
		DB	CR,LF
		DB	'   '
		DB	'Search        = ',DLR
CUSRMSG:
		DB	CR,LF
		DB	'   '
		DB	'Current user  = ',DLR
SBVERMSG:
		DB	CR,LF
		DB	'   '
		DB	'Cli/Dos vers  = ',DLR
FONMSG:		DB	'on',DLR
FOFFMSG:	DB	'off',DLR
SB80MSG:	DB	'SB/80',DLR
CPMMSG:		DB	'CP/M',DLR
SRCALMSG:	DB	'AL',DLR
SRCLOMSG:	DB	'LO',DLR
SRCLAMSG:	DB	'LA',DLR

	PAGE
;****************************************************************
;*								*
;*			STACK AREA				*
;*								*
;****************************************************************


	DS	32		; 16 LEVEL STACK
STACK	EQU	$		; 



;****************************************************************
;*								*
;*			DATA AREA II				*
;*								*
;****************************************************************



COMFCB:	DS	32		; COMMAND FILE CONTROL BLOCK
COMREC:	DS	1		; CURRENT RECORD TO READ/WRITE
COMRETCD: DS	1		; LDPGM RETCODE (STORED BY DOS)
DIRNUM:	DS	1		; DISK DIRECTORY COUNT (USED FOR ERROR CODES)
CURDSK:	DB	0		; CURRENT DISK
SLDISK:	DB	0		; SELECTED DISK FOR CURRENT OPERATION
				; =0 IF NONE, 1 IF A, 2 IF B,.....
BTFLAG:	DB	0		; FLAG TO SAY BATCH IN PROGRESS
TRFLAG:	DB	1		; FLAG TO SAY CASE TRANSLATE IF NON-ZERO
ATTFLG:	DB	0		; ON = DSPLY FILE ATTRIBUTES IN DIR CMD
INVFLG:	DB	0		; INVISIBLE FILE FLAG FOR DIR CMD
CRFLG:	DB	0		; CR,LF FLAG FOR 2 WIDE DIR
DSKCHG:	DB	0		; FLAG INDICATING DRIVE A .COM SEARCH FIRST
RENFLG:	DB	0		; RENAME IN PROGRESS FLAG
SWPFLG:	DB	0		; SWAP FLAG FOR RENAME
BPTR:	DS	1		; BUFFER POINTER
QCOM:	DB	QUEFIL		; TEMPORARY STORAGE FOR QUEUE COMMAND


LSTBYT	EQU	$		  !=;
ACTSIZ	EQU	$-CLIST		  !=;

CLIFILL	EQU	CLIST+(CLISZ-1)-$ !=; FOR RELOCATION
	DS	CLIFILL
CLIND	EQU	$		  !=;
	DB	0		; MAKE SURE WE GENERATE A HEX FILE BYTE HERE

	END	CLILOC
