        opt l-,o+

VERSION  equ    1
REVISION equ    1

LIBNAME	macro
        dc.b    "Paint",0
        endm
VSTRING macro
        dc.b    "$VER Paint 1.1 (17/11/94)",0
        dc.b    "Copyright © Paul Nolan & Almathera 1994. All Rights Reserved",0
        endm

        SECTION	code

        machine mc68020

        incdir  "include:"
        include "exec/funcdef.i"
        include "exec/types.i"
        INCLUDE "exec/initializers.i"
        INCLUDE "exec/libraries.i"
        INCLUDE "exec/lists.i"
        include "exec/memory.i"
        INCLUDE "exec/alerts.i"
        INCLUDE "exec/resident.i"
        INCLUDE "libraries/dos.i"
        include "exec/exec_lib.i"
        include "/photogenics.i"
        include "paintbase.i"
        include "paintmode.i"

        XDEF    InitTable
        XDEF    Open
        XDEF    Close
        XDEF    Expunge
        XDEF    Null
        XDEF    LibName
        XDEF    _main

        XREF    _PaintInfo
        XREF    _PaintAddr
        XREF    _PaintOptions

_main:
Start:
        moveq   #-1,d0
        rts

MYPRI   EQU   0

RomTag:
             ;STRUCTURE RT,0
     DC.W    RTC_MATCHWORD      ; UWORD RT_MATCHWORD
     DC.L    RomTag             ; APTR  RT_MATCHTAG
     DC.L    EndCode            ; APTR  RT_ENDSKIP
     DC.B    RTF_AUTOINIT       ; UBYTE RT_FLAGS
     DC.B    VERSION            ; UBYTE RT_VERSION
     DC.B    NT_LIBRARY         ; UBYTE RT_TYPE
     DC.B    MYPRI              ; BYTE  RT_PRI
     DC.L    LibName            ; APTR  RT_NAME
     DC.L    IDString           ; APTR  RT_IDSTRING
     DC.L    InitTable          ; APTR  RT_INIT  table for InitResident()

LibName:   LIBNAME
IDString:  VSTRING
        cnop    0,4

InitTable:
   DC.L   PaintBase_SIZEOF
   DC.L   funcTable
   DC.L   dataTable
   DC.L   init


funcTable:
   dc.l   Open
   dc.l   Close
   dc.l   Expunge
   dc.l   Null
   dc.l   _PaintInfo
   dc.l   _PaintAddr
   dc.l   _PaintOptions
   dc.l   -1

dataTable:
        INITBYTE        LN_TYPE,NT_LIBRARY
        INITLONG        LN_NAME,LibName
        INITBYTE        LIB_FLAGS,LIBF_SUMUSED!LIBF_CHANGED
        INITWORD        LIB_VERSION,VERSION
        INITWORD        LIB_REVISION,REVISION
        INITLONG        LIB_IDSTRING,IDString
        dc.l            0

init:   move.l   a5,-(sp)
        move.l   d0,a5
        move.l   a6,paintb_SysLib(a5)
        move.l   a0,paintb_SegList(a5)
        move.l   a5,d0
        move.l   (sp)+,a5
        rts

Open:   addq.w  #1,LIB_OPENCNT(a6)
        bclr    #LIBB_DELEXP,paintb_Flags(a6)
        move.l  a6,d0
        rts

Close:  moveq   #0,d0
        subq.w  #1,LIB_OPENCNT(a6)
        bne.s   1$
        btst    #LIBB_DELEXP,paintb_Flags(a6)
        beq.s   1$
        bsr.s   Expunge
1$:     rts

Expunge:
        movem.l d2/a5/a6,-(sp)
        move.l  a6,a5
        move.l  paintb_SysLib(a5),a6
        tst.w   LIB_OPENCNT(a5)
        beq.s   1$
        bset    #LIBB_DELEXP,paintb_Flags(a5)
        moveq   #0,d0
        bra.s   Expunge_End
1$:     move.l   paintb_SegList(a5),d2
        move.l   a5,a1
        jsr     _LVORemove(a6)
        moveq   #0,d0
        move.l  a5,a1
        move.w  LIB_NEGSIZE(a5),d0
        sub.l   d0,a1
        add.w   LIB_POSSIZE(a5),d0
        jsr     _LVOFreeMem(a6)
        move.l  d2,d0
Expunge_End:
        movem.l (sp)+,d2/a5/a6
        rts

Null:   moveq   #0,d0
        rts

EndCode:

*******************************************************************
*******************************************************************
*******************************************************************
***                                                             ***
*** Main code functions for library follow here...              ***
***                                                             ***
*******************************************************************
*******************************************************************
*******************************************************************


_PaintInfo
        move.l  #PAINT_ID+PAINT_COLOUR+PAINT_NOOPTIONS,d0
        rts

_PaintAddr
        move.l  #_code,d0
        rts

_code
; this code called with PhotoInfo in A5. Same rules as previous..
        move.l  PHI_red(a5),d4
        move.l  PHI_green(a5),d5
        move.l  PHI_blue(a5),d6
        rts

_PaintOptions
        moveq   #0,d0
        rts
