home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / packery / xpk_develop / include / asm / xpklibheader.i < prev   
Text File  |  1996-10-19  |  5KB  |  187 lines

  1.     NOLIST
  2.     INCLUDE "exec/types.i"
  3.     INCLUDE "exec/initializers.i"
  4.     INCLUDE "exec/libraries.i"
  5.     INCLUDE "exec/lists.i"
  6.     INCLUDE "exec/alerts.i"
  7.     INCLUDE "exec/resident.i"
  8.     INCLUDE "dos/dos.i"
  9.     INCLUDE    "lvo.i"
  10.     LIST
  11.  
  12. ;    XDEF    InitTable
  13. ;    XDEF    Open
  14. ;    XDEF    Close
  15. ;    XDEF    Expunge
  16. ;    XDEF    Null
  17. ;    XDEF    LibName
  18.  
  19.     SECTION    "0", Code
  20. Start    MOVEQ    #-1,d0    ; return an error in case someone
  21.     RTS        ; tried to run as a program
  22.  
  23. ; A romtag structure.  Both "exec" and "ramlib" look for this structure to
  24. ; discover magic constants about you (such as where to start running you
  25. ; from...).
  26.  
  27. RomTag        DC.W    RTC_MATCHWORD    ; UWORD rt_MatchWord
  28.         DC.L    RomTag        ; APTR  rt_MatchTag
  29.         DC.L    EndCode        ; APTR  rt_EndSkip
  30.         DC.B    RTF_AUTOINIT    ; UBYTE rt_Flags
  31.         DC.B    VERSION        ; UBYTE rt_Version
  32.         DC.B    NT_LIBRARY    ; UBYTE rt_type
  33.         DC.B    0        ; BYTE  rt_Pri
  34.         DC.L    LibName        ; APTR  rt_Name
  35.         DC.L    IDString    ; APTR  rt_IDString
  36.         DC.L    InitTable    ; APTR  rt_Init  table for InitResident()
  37.  
  38. ; The romtag specified that we were "RTF_AUTOINIT". This means that the
  39. ; rt_Init structure member points to one of these tables below. If the
  40. ; AUTOINIT bit was not set then RT_INIT would point to a routine to run.
  41.  
  42. InitTable:
  43.     DC.L    LIB_SIZE        ; size of library base data space
  44.     DC.L    funcTable        ; pointer to function initializers
  45.     DC.L    dataTable        ; pointer to data initializers
  46.     DC.L    initRoutine        ; routine to run
  47.  
  48. funcTable:
  49. ;------ standard system routines
  50.     DC.L    Open
  51.     DC.L    Close
  52.     DC.L    Expunge
  53.     DC.L    Null
  54. ;------ the library definitions
  55.     DC.L    _XpksPackerInfo
  56.     DC.L    _XpksPackChunk
  57.     DC.L    _XpksPackFree
  58.     DC.L    _XpksPackReset
  59.     DC.L    _XpksUnpackChunk
  60.     DC.L    _XpksUnpackFree
  61. ;------ function table end marker
  62.     DC.L    -1
  63.  
  64. ; The data table initializes static data structures. The format is specified
  65. ; in exec/InitStruct routine's manual pages. The INITBYTE/INITWORD/INITLONG
  66. ; routines are in the file "exec/initializers.i". The first argument is the
  67. ; offset from the library base for this byte/word/long. The second argument
  68. ; is the value to put in that cell. The table is null terminated.
  69.  
  70. dataTable:
  71.     INITBYTE    LN_TYPE,NT_LIBRARY
  72.     INITLONG    LN_NAME,LibName
  73.     INITBYTE    LIB_FLAGS,LIBF_SUMUSED!LIBF_CHANGED
  74.     INITWORD    LIB_VERSION,VERSION
  75.     INITWORD    LIB_REVISION,REVISION
  76.     INITLONG    LIB_IDSTRING,IDString
  77.     DC.L        0
  78.  
  79. ; This routine gets called after the library has been allocated. The library
  80. ; pointer is in D0. The segment list is in A0. If it returns non-zero then
  81. ; the library will be linked into the library list.
  82.  
  83. SegList        DC.L    0
  84. initRoutine:
  85. ;------ get the library pointer into a convenient A register
  86.     MOVEM.L    A5,-(A7)
  87.     MOVEA.L    D0,A5
  88. ;------ save a pointer to our loaded code
  89.     MOVE.L    A0,SegList
  90. ;
  91. ; specific openings here
  92. ;
  93.     JSR    _InitCode
  94.     TST.L    D0
  95.     BNE.B    .kill
  96.     MOVEA.L    A5,D0
  97. .end    MOVEM.L    (A7)+,A5
  98.     RTS
  99. .kill    JSR    _ExitCode
  100.     MOVEQ    #0,D0
  101.     BRA.B    .end
  102.  
  103. ; here begins the system interface commands. When the user calls
  104. ; OpenLibrary/CloseLibrary/RemoveLibrary, this eventually gets translated
  105. ; into a call to the following routines (Open/Close/Expunge). Exec has
  106. ; already put our library pointer in A6 for us. Exec has turned off task
  107. ; switching while in these routines (via Forbid/Permit), so we should not
  108. ; take too long in them.
  109.  
  110. ; Open returns the library pointer in D0 if the open was successful. If the
  111. ; open failed then null is returned. It might fail if we allocated memory
  112. ; on each open, or if only one application could have the library open at
  113. ; a time...
  114.  
  115. Open:        ; (libptr:A6, version:D0)
  116. ;------ mark us as having another opener
  117.     ADDQ.W    #1,LIB_OPENCNT(A6)
  118.     BCLR    #LIBB_DELEXP,LIB_FLAGS(A6)
  119.     MOVE.L    A6,D0
  120.     RTS
  121.  
  122. ; There are two different things that might be returned from the Close
  123. ; routine. If the library is no longer open and there is a delayed expunge
  124. ; then Close should return the segment list (as given to Init). Otherwise
  125. ; close should return NULL.
  126.  
  127. Close:        ; (libptr:A6)
  128. ;------ set the return value
  129.     MOVEQ    #0,D0
  130. ;------ mark us as having one fewer openers
  131.     SUBQ.W   #1,LIB_OPENCNT(A6)
  132. ;------ see if there is anyone left with us open
  133.     BNE.B    OneLeft
  134. ;------ do the expunge
  135.     BTST    #LIBB_DELEXP,LIB_FLAGS(a6)
  136.     BEQ.B    DelExp
  137.     BSR.B    Expunge
  138. OneLeft
  139. DelExp    RTS
  140.  
  141. ; There are two different things that might be returned from the Expunge
  142. ; routine. If the library is no longer open then Expunge should return the
  143. ; segment list (as given to Init). Otherwise Expunge should set the delayed
  144. ; expunge flag and return NULL.
  145. ; One other important note: because Expunge is called from the memory
  146. ; allocator, it may NEVER Wait() or otherwise take long time to complete.
  147.  
  148. Expunge:    ; (libptr: A6)
  149.     MOVEM.L    D2/A5/A6,-(A7)
  150.     MOVEA.L    A6,A5
  151.     MOVEA.L    4.W,A6
  152. ;------ see if anyone has us open
  153.     TST.W    LIB_OPENCNT(A5)
  154.     BEQ.B    DoIt
  155.     BSET    #LIBB_DELEXP,LIB_FLAGS(A6)
  156.     MOVEQ    #0,D0
  157.     BRA.B    Expunge_End
  158. DoIt
  159. ;------ go ahead and get rid of us.  Store our seglist in D2
  160.     MOVE.L    SegList(PC),D2
  161. ;------ unlink from library list
  162.     MOVEA.L    A5,A1
  163.     JSR    _LVORemove(A6)
  164. ;
  165. ; device specific closings here...
  166.     JSR    _ExitCode
  167. ;
  168. ;------ free our memory
  169.     MOVEQ    #0,D0
  170.     MOVEA.L    A5,A1
  171.     MOVE.W    LIB_NEGSIZE(A5),D0
  172.     SUBA.L    D0,A1
  173.     ADD.W    LIB_POSSIZE(A5),D0
  174.     JSR    _LVOFreeMem(A6)
  175. ;------ set up our return value
  176.     MOVE.L    D2,D0
  177.  
  178. Expunge_End:
  179.     MOVEM.L    (A7)+,D2/A5/A6
  180.     RTS
  181.  
  182. Null:    MOVEQ    #0,D0
  183. EndCode    RTS
  184.  
  185.         END
  186.  
  187.