;------
TRGINS:
;------
;Installs a 6 OR LESS character name as a ROM trigger file on the
;Model 100 directory.
;Entry: HL points to 6 OR LESS null TERMINATED
;	character string to use for the name.
;Exit:  None

;==============================================================
;Model 100 addresses and routines used.

;Retrieve next directory entry of an active file
;Entry:	HL should point to one directory entry less than the
;	point at which to begin the search. The search routine
;	starts by incrementing to the next entry
;Exit:	Z set = no more entries
;		else
;	HL points to the next directory entry with an
;		active file.
NXTDIR: 	EQU      020D5H
;------

;Locate an empty directory slot.
;Entry:	none
;Exit:	HL points to a free slot
FREDIR: EQU      020ECH
;------

;Beginning of the User Directory Area
USRDIR:		EQU	0F9BAH
;------



;1.	Test if a Trigger file exists

	PUSH	H		;Save New File name.
	CALL	FOTRG		;Find an old trigger file
	POP	D		;File Name

;2.	If so then install over it

	JNZ	TRGINS1		;If found install over it.

;3.	Otherwise locate a free directory

	PUSH	D		;else
	RST	6		;Call Std ROM to
	DW	FREDIR		;Find an empty Slot.
	POP	D		;and install

;4.	Copy in 0F0H file type and 0FFFFH start

TRGINS1:
	MVI	M,0F0H		;Trigger File type
	INX	H		;Step past start
	MVI	M,0FFH		;Set start to 0FFFFH
	INX	H
	MVI	M,0FFH
	INX	H

;5.	Copy the name to the first null and then
;	nulls to the rest of the name.
	MVI	C,8		;and copy in the name

TRGINS2:
	LDAX	D
	MOV	M,A
	INX	H		;Fill the rest of the
	ORA	A		;name with nulls when we
	JZ	TRGINS3		;hit the null terminator
	INX	D
TRGINS3:
	DCR	C		;directory name with nulls
	JNZ	TRGINS2
	RET

;------
FOTRG:
;------
;Searches the directory for an already existing trigger
;file and returns a pointer to it in HL if found.
;Entry:	None
;Exit:	Z set if none found
;		else
;	HL points to the directory entry


;1.	Starting behind the free directory
	LXI	H,USRDIR-11	;Free dir - 1 entry

;2.	Get the next in use File

FOTRG1:
	RST	6		;Call Std ROM to
	DW	NXTDIR		;get Next Live File
	RZ			;no file found

;3.	Return Pointing to it if it is a ROM
;	trigger file.

	MOV	A,M		;is it a ROM Trigger
	CPI	0F0H		;Type
	JNZ	FOTRG1		;No - Go again
	ANA	A		;Clear Z flag
	RET

	END
