	title	Module from library BASE_6 : INIREC
	name	('INIREC')
	maclib	baselib.lib

; Initialize file with variable record length

; Copyright (C)	Werner Cirsovius
;		Hohe Weide 44
;		D-20253 Hamburg
;		Tel.: +49-40-4223247

;		Version 1.0 December 1989

; ENTRY	Reg pair DE points to parameter block
;	Byte 0   Record length (1 .. 255)
;	Byte 1,2 Max record number (1 .. 65535)
;	Byte 3,4 FCB of file
;	Byte 5,6 Pointer to 128 byte buffer
;	Byte 7,8 Pointer to record data

; EXIT	Carry set on error, either disk or parameter error
;	File will be created if not on disk
;	File filled with contents of record data
;	if carry reset, file opened

; NOTE	Location INIREC-2 holds 1st record to be written into

	entry	inirec

	extrn	open,create,wrrecf,$rndpr,$rndrg

	dw	1		; Start record
inirec:
	call	$rndrg		; Get registers
	call	$rndpr		; Test parameter
	ret	c		; Error
	call	open		; Test file on disk
	call	c,create	; Else create it
	ret	c		; Cannot do so
	push	ix
	pop	de		; Get back PB
	ld	c,(ix+1)	; Get count
	ld	b,(ix+2)
	ld	hl,(inirec-2)	; Init start record
opn.loop:
	ld	(ix+1),l	; Set record
	ld	(ix+2),h
	push	hl
	push	bc
	push	de
	push	ix
	call	wrrecf		; Print record
	pop	ix
	pop	de
	pop	bc
	pop	hl
	inc	hl
	dec	bc
	ld	a,c
	or	b		; Test done
	jr	nz,opn.loop
	ret

	end

