*
* initialization stub for the toshiba printer driver
*

	INCLUDE "exec/types.i"
	INCLUDE "exec/nodes.i"
	INCLUDE "exec/lists.i"
	INCLUDE "exec/memory.i"
	INCLUDE "exec/ports.i"
	INCLUDE "exec/libraries.i"

	INCLUDE "macros.i"
	INCLUDE "devices/prtbase.i"

	XREF_EXE	CloseLibrary
	XREF_EXE	OldOpenLibrary
	XREF_EXE	OpenLibrary

	XREF		_AbsExecBase	;these are in the Aztec Library
	XREF		_SysBase	;and this

	XREF		_PEDData

	ifd		DEBUG
	XREF		_dbstart
	XREF		_dbuninit
	XREF		_dbprintf
	XREF		_PWait
	endc

	XDEF		_Init
	XDEF		_Expunge
	XDEF		_PrOpen
	XDEF		_PrClose
	XDEF		_PD
	XDEF		_PED
	XDEF		_DOSBase
	XDEF		_GfxBase
	XDEF		_IntuitionBase

*------------------------------------------------------
	section	printer,data
_PD		dc.l	0
_PED		dc.l	0
_DosBase	dc.l	0
_GfxBase	dc.l	0
_IntuitionBase	dc.l	0

*------------------------------------------------------
	section printer,code
_Init
		move.l	4(sp),_PD

		lea	_PEDData(pc),a0
		move.l	a0,_PED
		move.l	a6,-(a7)
		move.l	_AbsExecBase,a6
		move.l	a6,_SysBase

* open dos library

		lea	DLName,a1
		moveq	#1,d0
		callexe	OpenLibrary
		move.l	d0,_DOSBase
		beq	initDLErr

* open gfx libarary

		lea	GLName,a1
		moveq	#1,d0
		callexe	OpenLibrary
		move.l	d0,_GfxBase
		beq	initGLErr

* open intuition libarary

		lea	ILName,a1
		moveq	#1,d0
		callexe	OpenLibrary
		move.l	d0,_IntuitionBase
		beq	initILErr

		ifd	DEBUG
		jsr	_dbstart
		endc

		moveq	#0,d0
pdiRts:
		move.l	(a7)+,a6
		rts

initPAErr:
		move.l	_IntuitionBase,a1
		LINKEXE	CloseLibrary

initILErr:
		move.l	_GfxBase,a1
		LINKEXE	CloseLibrary

initGLErr:
		move.l	_DOSBase,a1
		LINKEXE	CloseLibrary

initDLErr:
		moveq	#-1,d0
		bra.s	pdiRts

ILName:		dc.b	"intuition.library",0
DLName:		dc.b	"dos.library",0
GLName:		dc.b	"graphics.library",0
DeathMsg:	dc.b	"I'm being rubbed out!",0
		ds.w	0



*------------------------------------------------------

_Expunge:
		move.l	a6,-(sp)

		ifd	DEBUG
		pea.l	DeathMsg
		jsr	_dbprintf
		addq.l	#4,sp
		pea	0
		pea	1
		jsr	_PWait
		addq.l	#8,sp
		jsr	_dbuninit
		endc

		move.l	_SysBase,a6

		move.l	_IntuitionBase,a1
		callexe	CloseLibrary

		move.l	_GfxBase,a1
		callexe	CloseLibrary

		move.l	_DOSBase,a1
		callexe	CloseLibrary

		move.l	(sp)+,a6
		moveq	#0,d0
		rts

*------------------------------------------------------
_PrOpen:
		moveq	#0,d0
		rts

*------------------------------------------------------
_PrClose:
		moveq	#0,d0
		rts
