	title	Module from library BASE_2 : REC3
	name	('REC3')
	maclib	baselib.lib

; Utilities for handling with variable length records

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

;		Version 1.0 December 1989

	entry	$bufsw,$bufrs,$dmabf,$rndrg

	extrn	setdma,curdma

;
; Save and restore DMA address
;
; ENTRY	Accu        holds record length (1 .. 255)
;	Reg pair BC holds max record number (1 .. 65535)
;	Reg pair DE holds FCB of file
;	Reg pair HL holds pointer to record data
;	Reg      IY holds pointer to 128 byte buffer
; 	Reg      IX points to parameter block
; EXIT	Buffer swapped from old to new one or old one restored
;
$bufsw:
	push	af
	push	ix
	push	iy
	push	de
	push	hl
	call	curdma		; Get old buffer
	ld	($dmabf),hl	; .. save it
	pop	hl
	push	iy
	pop	de		; Get new buffer
	jr	buff..
$bufrs:
	push	af
	push	ix
	push	iy
	push	de
	ld	de,($dmabf)
buff..:
	call	setdma		; Set old buffer
	pop	de
	pop	iy
	pop	ix
	pop	af
	ret
;
; Load registers from parameter block
;
; 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	Accu        holds record length (1 .. 255)
;	Reg pair BC holds max record number (1 .. 65535)
;	Reg pair DE holds FCB of file
;	Reg pair HL holds pointer to record data
;	Reg      IY holds pointer to 128 byte buffer
; 	Reg      IX points to parameter block
;
$rndrg:
	push	de
	pop	ix		; Get parameter block
	ld	l,(ix+5)
	ld	h,(ix+6)
	push	hl
	ld	a,(ix+0)	; Load regs
	ld	c,(ix+1)
	ld	b,(ix+2)
	ld	e,(ix+3)
	ld	d,(ix+4)
	ld	l,(ix+7)
	ld	h,(ix+8)
	pop	iy
	ret

	dseg

$dmabf:
	ds	2		; DMA buffer

	end

