home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 581a.lha / MemMan_v2.0 / MemManLib.asm < prev    next >
Assembly Source File  |  1991-12-04  |  4KB  |  158 lines

  1. * Lib.asm - Runtime library interface for Guido - © 1991 Bryan Ford *
  2.  
  3.         include "exec/types.i"
  4.         include "exec/initializers.i"
  5.         include "exec/libraries.i"
  6.         include "exec/lists.i"
  7.         include "exec/alerts.i"
  8.         include "exec/resident.i"
  9.         include "exec/semaphores.i"
  10.         include "exec/funcdef.i"
  11.         include "exec/exec_lib.i"
  12.         include "bry/macros.i"
  13.  
  14. VERSION equ     1               ; Don't forget to change the idstring
  15. REVISION equ    0
  16.  
  17.  STRUCTURE      MemManLibrary,0
  18.         STRUCT  lib_Node,LIB_SIZE
  19.         UBYTE   lib_Flags               ; Defined below
  20.         BYTE    lib_pad
  21.         LONG    lib_SegList             ; Library SegList
  22.         APTR    lib_SysBase             ; A bunch of library pointers
  23.         APTR    lib_DOSBase
  24.         APTR    lib_GfxBase
  25.         APTR    lib_IntuitionBase
  26.         APTR    lib_GadToolsBase        ; From here on are optional libraries
  27.         APTR    lib_AslBase
  28.         APTR    lib_ArpBase
  29.         LABEL   lib_Size
  30.  
  31.         code    text
  32.  
  33.         xref    MMInit,MMFinish
  34.  
  35. dosentry:
  36.         moveq   #-1,d0
  37.         rts
  38.  
  39. idstring:
  40.         dc.b    "memman.library 1.0 (4-Dec-91) Copyright 1991 Bryan Ford"
  41.         ds.w    0
  42.  
  43. initdescrip:
  44.         DC.W    RTC_MATCHWORD   ; UWORD RT_MATCHWORD
  45.         DC.L    initdescrip     ; APTR  RT_MATCHTAG
  46.         DC.L    endcode         ; APTR  RT_ENDSKIP
  47.         DC.B    RTF_AUTOINIT    ; UBYTE RT_FLAGS
  48.         DC.B    VERSION         ; UBYTE RT_VERSION
  49.         DC.B    NT_LIBRARY      ; UBYTE RT_TYPE
  50.         DC.B    0               ; BYTE  RT_PRI
  51.         DC.L    libname         ; APTR  RT_NAME
  52.         DC.L    idstring        ; APTR  RT_IDSTRING
  53.         DC.L    init            ; APTR  RT_INIT
  54.  
  55. init:
  56.         DC.L    lib_Size        ; size of library base data space
  57.         DC.L    functable       ; pointer to function initializers
  58.         DC.L    datatable       ; pointer to data initializers
  59.         DC.L    initroutine     ; routine to run
  60.  
  61. functable:
  62.         ;------ standard system routines
  63.         dc.l    Open
  64.         dc.l    Close
  65.         dc.l    Expunge
  66.         dc.l    Null
  67.  
  68.         ;------ my libraries definitions
  69.         dcx.l   MMAddNode
  70.         dcx.l   MMRemNode
  71.  
  72.         ;------ function table end marker
  73.         dc.l    -1
  74.  
  75. datatable:
  76.         INITBYTE        LN_TYPE,NT_LIBRARY
  77.         INITLONG        LN_NAME,libname
  78.         INITBYTE        LIB_FLAGS,LIBF_SUMUSED!LIBF_CHANGED
  79.         INITWORD        LIB_VERSION,VERSION
  80.         INITWORD        LIB_REVISION,REVISION
  81.         INITLONG        LIB_IDSTRING,idstring
  82.         dc.l   0
  83.  
  84. initroutine:
  85.         push    a5
  86.         move.l  d0,a5
  87.         move.l  a6,lib_SysBase(a5)
  88.         move.l  a0,lib_SegList(a5)
  89.  
  90.         bsr     MMInit
  91.         tst.l   d0
  92.         bz.s    \err
  93.  
  94.         move.l  a5,d0
  95. \err
  96.         pop     a5
  97.         rts
  98.  
  99. Open:      ; ( libptr:a6, version:d0 )
  100.         addq.w  #1,LIB_OPENCNT(a6)
  101.         bclr    #LIBB_DELEXP,lib_Flags(a6)
  102.         move.l  a6,d0
  103.         rts
  104.  
  105. Close:      ; ( libptr:a6 )
  106.         cq      d0
  107.         subq.w  #1,LIB_OPENCNT(a6)
  108.         bnz.s   \noexp
  109.         btst    #LIBB_DELEXP,lib_Flags(a6)
  110.         bnz.s   Expunge
  111. \noexp
  112.         rts
  113.  
  114. Expunge:   ; ( libptr: a6 )
  115.         apush
  116.         move.l  a6,a5
  117.         move.l  lib_SysBase(a5),a6
  118.  
  119.         ;------ see if anyone has us open
  120.         tst.w   LIB_OPENCNT(a5)
  121.         bz.s   1$
  122.  
  123.         ;------ it is still open.  set the delayed expunge flag
  124.         bset    #LIBB_DELEXP,lib_Flags(a5)
  125.         cq      d0
  126.         b.s     9$
  127. 1$
  128.         bsr     MMFinish
  129.  
  130.         move.l  lib_SegList(a5),d2
  131.  
  132.         ;------ unlink from library list
  133.         move.l  a5,a1
  134.         jsr     _LVORemove(a6)
  135.  
  136.         ;------ free our memory
  137.         moveq   #0,d0
  138.         move.l  a5,a1
  139.         move.w  LIB_NEGSIZE(a5),d0
  140.         sub.l   d0,a1
  141.         add.w   LIB_POSSIZE(a5),d0
  142.         jsr     _LVOFreeMem(a6)
  143.  
  144.         move.l  d2,d0
  145. 9$
  146.         apop
  147.         rts
  148.  
  149. Null:
  150.         moveq   #0,d0
  151.         rts
  152.  
  153. libname         dc.b    "memman.library",0
  154.  
  155. endcode:
  156.  
  157.         end
  158.