	title	Module SCB Parameter Save
	name	('SCBFILE')
	maclib	baselib.lib

; Save or restore parameters between file I/O while searching files

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

;		Version 1.0 July 1994

; ENTRY	SCBPUT:	Reg pair DE holds FCB mask
;		Reg pair HL fold FCB
;	SCBGET:	None

; EXIT	Reg pair DE holds FCB ready for work
;	SCBPUT:	Carry set on no file found
;	SCBGET:	Carry set on no more files

; NOTE	SCBPUT *MUST* be called always on 1st place

	entry	scbput,scbget

	extrn	srcfrs,srcnxt,scbpb,scbfun

_DIRSLT	equ	0e5h		; Absolute pointer
_SCBADR	equ	03ah		; Relative pointer

;
; This entry called after scbput and following calls
;
scbget:
	ld	de,(SCBADR)	; Get SCB address
	ld	hl,SCBSAV
	ld	bc,SCB1len
	ldir			; Unpack hash values
	ld	de,(DIRSLOT)	; Get SCB address
	ld	bc,SCB2len
	ldir			; Unpack file parameters
	ld	de,(SCBFCB)	; Fetch search FCB
	ld	hl,(FCBmask)
	or	a
	sbc	hl,de		; Test same FCB
	jr	z,restSCB	; Yeap
	add	hl,de		; Make address real
	ld	bc,DIRlen
	ldir			; Unpack
restSCB:
	call	srcnxt		; Search for next file
	jr	scbfnc
;
; This call must be executed first
;
scbput:
	ld	(FCBmask),de	; Save FCBs
	ld	(FCBwork),hl
	ld	a,(de)
	ld	(FCBdrv),a	; Save drive
	ld	a,_SCBADR	; Set request for SCB Address
	ld	(scbpb),a
	call	scbfun		; Get it
	ld	(SCBADR),hl	; Save address
	ld	l,_DIRSLT
	ld	(DIRSLOT),hl
	call	srcfrs		; Search for file
scbfnc:
	ret	c		; No file found
	push	hl		; Save file address
	ld	hl,(SCBADR)	; Get SCB address
	ld	de,SCBSAV
	ld	bc,SCB1len
	ldir			; Unpack hash values
	ld	hl,(DIRSLOT)	; Get SCB address
	ld	bc,SCB2len
	ldir			; Unpack file parameters
	pop	hl		; Get back FCB found
	ld	a,(FCBdrv)
	ld	(hl),a		; Set drive
	ld	de,(FCBwork)
	push	de
	ld	bc,.drv+.nam+.ext
	ldir			; Unpack file
	pop	de		; Get FCB
	or	a		; Set result
	ret			; And exit for file processing

	dseg

SCBADR:
	ds	2
DIRSLOT:
	ds	2
SCBSAV:
	dw	0,0,0
SCB1len	equ	$-SCBSAV
SCBSLOT:
	ds	2
SCBFCB:
	ds	2
SCBFUNO:
	ds	2
SCB2len	equ	$-SCBSLOT
FCBmask:
	ds	2
FCBwork:
	ds	2
FCBdrv:
	ds	1

	end

