;**************************************************************************
;           This routine is stock standard from RKM
;                         B.R.M 1/2/88
;
;**************************************************************************
        section printer

;       included files

        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"

;       imported functions

        XREF_EXE        CloseLibrary
        XREF_EXE        OpenLibrary
        XREF            _AbsExecBase

        XREF            _PEDData

;       exported globals

        XDEF    _Init
        XDEF    _Expunge
        XDEF    _Open
        XDEF    _Close
        XDEF    _PD
        XDEF    _PED
        XDEF    _SysBase
        XDEF    _DOSBase
        XDEF    _GfxBase
        XDEF    _IntuitionBase

;***********************************************
        section printer,data
_PD             DC.L    0
_PED            DC.L    0
_SysBase        DC.L    0
_DOSBase        DC.L    0
_GfxBase        DC.L    0
_IntuitionBase  DC.L    0
;***********************************************
        section printer,code
_Init:
        move.l  4(a7),_PD
        lea     _PEDData(pc),a0
        move.l  a0,_PED
        move.l  a6,-(a7)
        move.l  _AbsExecBase,a6
        move.l  a6,_SysBase

;       open the dos library
        lea     DLName(pc),a1
        moveq   #0,d0
        CALLEXE OpenLibrary
        move.l  d0,_DOSBase
        beq.l   initDLErr

;       open the graphics library
        lea     GLName(pc),a1
        moveq   #0,d0
        CALLEXE OpenLibrary
        move.l  d0,_GfxBase
        beq.l   initGLErr

;       open the intuition library
        lea     ILName(pc),a1
        moveq   #0,d0
        CALLEXE OpenLibrary
        move.l  d0,_IntuitionBase
        beq.l   initILErr

        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'
        dc.b    0
DLName:
        dc.b    'dos.library'
        dc.b    0
GLName:
        dc.b    'graphics.library'
        dc.b    0
        ds.w    0


_Expunge:
        move.l  _IntuitionBase,a1
        LINKEXE CloseLibrary

        move.l  _GfxBase,a1
        LINKEXE CloseLibrary

        move.l  _DOSBase,a1
        LINKEXE CloseLibrary

_Open:
        moveq   #0,d0
        rts

_Close:
        moveq   #0,d0
        rts

        end
