		incdir	_include:
		include	exec/exec.i
		include	libraries/dos_lib.i
		include	libraries/exec_lib.i
		include	libraries/dosextens.i
		include	include:libraries/xpk.i

start:		move.l	4.w,a6
		lea	xpkname(pc),a1
		jsr	_LVOOldOpenLibrary(a6)
		move.l	d0,xpkbase		; Store XPK Library base!
		beq.b	cleanup			; ERROR -> Exit

		move.l	d0,a6			; XPKBase to A6
		lea	tags(pc),a0
		jsr	_LVOXpkUnpack(a6)
		tst.l	d0
		beq.w	noerror

		suba.l	a0,a0
		bra.s	yoyo

noerror		move.l	fileptr(pc),a0
		move.l	a0,0.w

yo		btst	#6,$bfe001
		bne.s	yo

yoyo		

cleanup		move.l	fileptr(pc),d0
		beq.b	s1
		move.l	d0,a1
		move.l	fileptrlen(pc),d0
		move.l	4.w,a6
		jsr	_LVOFreeMem(a6)		; Free XPK output buffer

s1		move.l	xpkbase(pc),d0
		beq.b	exit			; Library not open
		move.l	d0,a1
		jsr	_LVOCloseLibrary(a6)	; Close XPK library

exit		moveq	#0,d0			; No error code!
		rts


xpkbase:	dc.l	1

tags:		dc.l	XPK_InName,filename		; The file name to be read
		dc.l	XPK_GetError,errbuf		; A pointer to the error message buffer
		dc.l	XPK_GetOutBuf,fileptr		; Sets a pointer to the output buffer
		dc.l	XPK_GetOutLen,filesize		; Sets the number of bytes written
		dc.l	XPK_GetOutBufLen,fileptrlen	; Sets the length of the output buffer
		dc.l	XPK_PassThru,-1			; Will pass through uncompressed data
		dc.l	TAG_DONE

fileptr:	ds.l	1
filesize:	ds.l	1
fileptrlen:	ds.l	1
errbuf:		ds.b	82
		even
dosname:	dc.b	'dos.library',0
xpkname:	dc.b	'xpkmaster.library',0
filename:	dc.b	'work:vars3.c',0
		even
		end
