home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Extras / BOOPSI / led_ic / classinit.asm < prev    next >
Encoding:
Assembly Source File  |  1994-03-31  |  6.4 KB  |  266 lines

  1.  
  2. ;---------------------------------------------------------------------------
  3.  
  4.         NOLIST
  5.  
  6.         INCLUDE "exec/types.i"
  7.         INCLUDE "exec/libraries.i"
  8.         INCLUDE "exec/lists.i"
  9.         INCLUDE "exec/alerts.i"
  10.         INCLUDE "exec/initializers.i"
  11.         INCLUDE "exec/resident.i"
  12.         INCLUDE "libraries/dos.i"
  13.         INCLUDE "utility/hooks.i"
  14.  
  15.         INCLUDE "led_rev.i"
  16.         INCLUDE "classbase.i"
  17.  
  18.         LIST
  19.  
  20. ;---------------------------------------------------------------------------
  21.  
  22.     XREF    _CreateClass
  23.     XREF    _DestroyClass
  24.  
  25.     XREF    _LVOSMult32
  26.     XREF    _LVOUMult32
  27.     XREF    _LVOSDivMod32
  28.     XREF    _LVOUDivMod32
  29.  
  30.         XREF    ENDCODE
  31.  
  32. ;---------------------------------------------------------------------------
  33.  
  34.     SECTION CODE
  35.  
  36.         XDEF    LibInit
  37.         XDEF    LibOpen
  38.         XDEF    LibClose
  39.         XDEF    LibExpunge
  40.         XDEF    LibReserved
  41.         XDEF    @CallCHook
  42.  
  43. ;---------------------------------------------------------------------------
  44.  
  45. ; First executable location, must return an error to the caller
  46. Start:
  47.         moveq   #-1,d0
  48.         rts
  49.  
  50. ;-----------------------------------------------------------------------
  51.  
  52. ROMTAG:
  53.         DC.W    RTC_MATCHWORD           ; UWORD RT_MATCHWORD
  54.         DC.L    ROMTAG                  ; APTR  RT_MATCHTAG
  55.         DC.L    ENDCODE                 ; APTR  RT_ENDSKIP
  56.         DC.B    RTF_AUTOINIT            ; UBYTE RT_FLAGS
  57.         DC.B    VERSION                 ; UBYTE RT_VERSION
  58.         DC.B    NT_LIBRARY              ; UBYTE RT_TYPE
  59.         DC.B    0                       ; BYTE  RT_PRI
  60.         DC.L    LibName                 ; APTR  RT_NAME
  61.         DC.L    LibId                   ; APTR  RT_IDSTRING
  62.         DC.L    LibInitTable            ; APTR  RT_INIT
  63.  
  64. LibName DC.B 'led.image',0
  65. LibId   VSTRING
  66.  
  67.         CNOP    0,4
  68.  
  69. LibInitTable:
  70.         DC.L    ClassLib_SIZEOF
  71.         DC.L    LibFuncTable
  72.         DC.L    0
  73.         DC.L    LibInit
  74.  
  75. V_DEF    MACRO
  76.     DC.W    \1+(*-LibFuncTable)
  77.     ENDM
  78.  
  79. LibFuncTable:
  80.     DC.W    -1
  81.         V_DEF    LibOpen
  82.         V_DEF    LibClose
  83.         V_DEF    LibExpunge
  84.         V_DEF    LibReserved
  85.         DC.W   -1
  86.  
  87. ;-----------------------------------------------------------------------
  88.  
  89. ; Library Init entry point called when library is first loaded in memory
  90. ; On entry, D0 points to library base, A0 has lib seglist, A6 has SysBase
  91. ; Returns 0 for failure or the library base for success.
  92. LibInit:
  93.         movem.l a0/a5/d7,-(sp)
  94.         move.l  d0,a5
  95.         move.l  a6,cb_SysBase(a5)
  96.         move.l  a0,cb_SegList(a5)
  97.  
  98.         move.w    #REVISION,LIB_REVISION(a5)
  99.  
  100.         move.l  #AO_GraphicsLib,d7
  101.         lea     GfxName(pc),a1
  102.         bsr.s    OpenLib
  103.         move.l  d0,cb_GfxBase(a5)
  104.  
  105.         move.l  #AO_Intuition,d7
  106.         lea     IntuitionName(pc),a1
  107.         bsr.s    OpenLib
  108.         move.l  d0,cb_IntuitionBase(a5)
  109.  
  110.         move.l  #AO_UtilityLib,d7
  111.         lea     UtilityName(pc),a1
  112.         bsr.s    OpenLib
  113.         move.l  d0,cb_UtilityBase(a5)
  114.  
  115.         move.l  a5,d0
  116.         movem.l (sp)+,a0/a5/d7
  117.         rts
  118.  
  119. OpenLib:
  120.         moveq   #LIBVERSION,d0
  121.         CALL    OpenLibrary
  122.         move.l    (sp)+,a0    ; pop return address
  123.         tst.l   d0        ; did lib open?
  124.         beq.s   FailInit    ; nope, so exit
  125.         jmp    (a0)        ; yes, so return
  126.  
  127. FailInit:
  128.         bsr     CloseLibs
  129.         or.l    #AG_OpenLib,d7
  130.         CALL    Alert
  131.         movem.l (sp)+,a0/a5/d7
  132.         moveq   #0,d0
  133.         rts
  134.  
  135. LIBVERSION    EQU  37
  136. GfxName       DC.B "graphics.library",0
  137. IntuitionName DC.B "intuition.library",0
  138. UtilityName   DC.B "utility.library",0
  139.  
  140.         CNOP    0,2
  141.  
  142. ;-----------------------------------------------------------------------
  143.  
  144. ; Library open entry point called every OpenLibrary()
  145. ; On entry, A6 has ClassBase, task switching is disabled
  146. ; Returns 0 for failure, or ClassBase for success.
  147. LibOpen:
  148.     tst.w    LIB_OPENCNT(a6)
  149.     bne.s    1$
  150.  
  151.     bsr    _CreateClass
  152.     tst.w    d0
  153.     bne.s    1$
  154.  
  155.     moveq    #0,d0
  156.     rts
  157.  
  158. 1$:
  159.         addq.w  #1,LIB_OPENCNT(a6)
  160.         bclr    #LIBB_DELEXP,LIB_FLAGS(a6)
  161.         move.l  a6,d0
  162.         rts
  163.  
  164. ;-----------------------------------------------------------------------
  165.  
  166. ; Library close entry point called every CloseLibrary()
  167. ; On entry, A6 has ClassBase, task switching is disabled
  168. ; Returns 0 normally, or the library seglist when lib should be expunged
  169. ;   due to delayed expunge bit being set
  170. LibClose:
  171.     subq.w    #1,LIB_OPENCNT(a6)
  172.     bne.s    1$            ; if openers, don't remove class
  173.  
  174.     bsr    _DestroyClass        ; zero openers, so try to remove class
  175.  
  176. 1$:
  177.     ; if delayed expunge bit set, then try to get rid of the library
  178.     btst    #LIBB_DELEXP,LIB_FLAGS(a6)
  179.     bne.s    CloseExpunge
  180.  
  181.     ; delayed expunge not set, so stick around
  182.     moveq    #0,d0
  183.     rts
  184.  
  185. CloseExpunge:
  186.     ; if no library users, then just remove the library
  187.     tst.w    LIB_OPENCNT(a6)
  188.     beq.s    DoExpunge
  189.  
  190.     ; still some library users, so forget about flushing
  191.     bclr    #LIBB_DELEXP,LIB_FLAGS(a6)
  192.     moveq    #0,d0
  193.     rts
  194.  
  195. ;-----------------------------------------------------------------------
  196.  
  197. ; Library expunge entry point called whenever system memory is lacking
  198. ; On entry, A6 has ClassBase, task switching is disabled
  199. ; Returns the library seglist if the library open count is 0, returns 0
  200. ; otherwise and sets the delayed expunge bit.
  201. LibExpunge:
  202.         tst.w   LIB_OPENCNT(a6)
  203.         beq.s   DoExpunge
  204.  
  205.         tst.l   cl_Class(a6)
  206.         beq.s   DoExpunge
  207.  
  208.         bset    #LIBB_DELEXP,LIB_FLAGS(a6)
  209.         moveq   #0,d0
  210.         rts
  211.  
  212. DoExpunge:
  213.         movem.l d2/a5/a6,-(sp)
  214.         move.l  a6,a5
  215.         move.l  cb_SegList(a5),d2
  216.  
  217.         move.l  a5,a1
  218.         REMOVE
  219.  
  220.         move.l  cb_SysBase(a5),a6
  221.         bsr.s   CloseLibs
  222.  
  223.         move.l  a5,a1
  224.         moveq   #0,d0
  225.         move.w  LIB_NEGSIZE(a5),d0
  226.         sub.l   d0,a1
  227.         add.w   LIB_POSSIZE(a5),d0
  228.         CALL    FreeMem
  229.  
  230.         move.l  d2,d0
  231.         movem.l (sp)+,d2/a5/a6
  232.         rts
  233.  
  234. ;-----------------------------------------------------------------------
  235.  
  236. LibReserved:
  237.         moveq   #0,d0
  238.         rts
  239.  
  240. ;-----------------------------------------------------------------------
  241.  
  242. CloseLibs:
  243.         move.l  cb_GfxBase(a5),a1
  244.         CALL    CloseLibrary
  245.  
  246.         move.l  cb_IntuitionBase(a5),a1
  247.         CALL    CloseLibrary
  248.  
  249.         move.l  cb_UtilityBase(a5),a1
  250.         GO    CloseLibrary
  251.  
  252. ;-----------------------------------------------------------------------
  253.  
  254.  
  255. ; Restores context and calls high-level language hook
  256. @CallCHook:
  257.     movem.l    a5/a6,-(sp)
  258.     movem.l    h_SubEntry(a0),a5/a6    ; h_SubEntry into A5, h_Data into A6
  259.     jsr    (a5)            ; call HLL
  260.     movem.l    (sp)+,a5/a6
  261.     rts
  262.  
  263. ;-----------------------------------------------------------------------
  264.  
  265.         END
  266.