home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / packery / xpk_source / xpkmaster / libdata.a < prev    next >
Text File  |  1996-10-28  |  8KB  |  320 lines

  1. * Routinesheader
  2. *
  3. *    Name:        libdata.a
  4. *    Main:        xpkmaster
  5. *    Versionstring:    $VER: libdata.a 3.10 (28.10.96)
  6. *    Author:        SDI
  7. *    Distribution:    PD
  8. *    Description:    all the library startup data
  9. *
  10. * 3.10  28.10.96 : first real version
  11.  
  12.     NOLIST
  13.     INCLUDE    "AINCLUDE:IncDirs.i" *sets all includedirs, needed for my ASM
  14.     INCLUDE "exec/types.i"
  15.     INCLUDE "exec/initializers.i"
  16.     INCLUDE "exec/libraries.i"
  17.     INCLUDE "exec/lists.i"
  18.     INCLUDE "exec/alerts.i"
  19.     INCLUDE "exec/resident.i"
  20.     INCLUDE "dos/dos.i"
  21.     INCLUDE    "lvo.i"
  22.     LIST
  23.  
  24. *_SysBase    EQU    4
  25. *        XDEF    _SysBase
  26.  
  27. VERSION        EQU    3
  28. REVISION    EQU    10
  29. MINOSVERSION    EQU    0
  30.  
  31. STRINGANZ    EQU    12
  32. STRINGSTART    EQU    0
  33. ERRSTRINGANZ    EQU    33
  34. ERRSTRINGSTART    EQU    200
  35.  
  36. VSTRING    MACRO
  37.         DC.B    'xpkmaster 3.10 (28.10.96)',13,10,0
  38.     ENDM
  39.  
  40. ;    XDEF    InitTable
  41. ;    XDEF    Open
  42. ;    XDEF    Close
  43. ;    XDEF    Expunge
  44. ;    XDEF    Null
  45. ;    XDEF    LibName
  46.     XDEF    _DOSBase,_DosBase,_IntuitionBase,_UtilityBase
  47.     XDEF    _MainVersion
  48.  
  49.     XREF    _XpkExamine,_XpkPack
  50.     XREF    _XpkUnpack,_XpkOpen,_XpkRead,_XpkWrite
  51.     XREF    _XpkSeek,_XpkClose,_XpkQuery
  52.     XREF    _strings,_XpkErrs
  53.  
  54.     SECTION    "XPK_LibStart",Code
  55. Start    MOVEQ    #-1,d0    ; return an error in case someone
  56.     RTS        ; tried to run as a program
  57.  
  58. ; A romtag structure.  Both "exec" and "ramlib" look for this structure to
  59. ; discover magic constants about you (such as where to start running you
  60. ; from...).
  61.  
  62. RomTag        DC.W    RTC_MATCHWORD    ; UWORD rt_MatchWord
  63.         DC.L    RomTag        ; APTR  rt_MatchTag
  64.         DC.L    ENDCODE        ; APTR  rt_EndSkip
  65.         DC.B    RTF_AUTOINIT    ; UBYTE rt_Flags
  66. _MainVersion    DC.B    VERSION        ; UBYTE rt_Version
  67.         DC.B    NT_LIBRARY    ; UBYTE rt_type
  68.         DC.B    0        ; BYTE  rt_Pri
  69.         DC.L    LibName        ; APTR  rt_Name
  70.         DC.L    IDString    ; APTR  rt_IDString
  71.         DC.L    InitTable    ; APTR  rt_Init  table for InitResident()
  72.  
  73. LibName        DC.B    'xpkmaster.library',0
  74. DOSNAME        DC.B    'dos.library',0
  75. INTUITIONNAME    DC.B    'intuition.library',0
  76. UTILITYNAME    DC.B    'utility.library',0
  77. LOCALENAME    DC.B    'locale.library',0
  78. CATALOGNAME    DC.B    'xpkmaster.catalog',0
  79.         CNOP    0,2
  80. IDString    VSTRING
  81.           CNOP    0,2    ; word alignement
  82.  
  83. ; The romtag specified that we were "RTF_AUTOINIT". This means that the
  84. ; rt_Init structure member points to one of these tables below. If the
  85. ; AUTOINIT bit was not set then RT_INIT would point to a routine to run.
  86.  
  87. InitTable:
  88.     DC.L    LIB_SIZE        ; size of library base data space
  89.     DC.L    funcTable        ; pointer to function initializers
  90.     DC.L    dataTable        ; pointer to data initializers
  91.     DC.L    initRoutine        ; routine to run
  92.  
  93. funcTable:
  94. ;------ standard system routines
  95.     DC.L    Open
  96.     DC.L    Close
  97.     DC.L    Expunge
  98.     DC.L    Null
  99. ;------ my libraries definitions
  100.     DC.L    Null
  101.     DC.L    _XpkExamine
  102.     DC.L    _XpkPack
  103.     DC.L    _XpkUnpack
  104.     DC.L    _XpkOpen
  105.     DC.L    _XpkRead
  106.     DC.L    _XpkWrite
  107.     DC.L    _XpkSeek
  108.     DC.L    _XpkClose
  109.     DC.L    _XpkQuery
  110. ;------ function table end marker
  111.     DC.L    -1
  112.  
  113. ; The data table initializes static data structures. The format is specified
  114. ; in exec/InitStruct routine's manual pages. The INITBYTE/INITWORD/INITLONG
  115. ; routines are in the file "exec/initializers.i". The first argument is the
  116. ; offset from the library base for this byte/word/long. The second argument
  117. ; is the value to put in that cell. The table is null terminated.
  118.  
  119. dataTable:
  120.     INITBYTE    LN_TYPE,NT_LIBRARY
  121.     INITLONG    LN_NAME,LibName
  122.     INITBYTE    LIB_FLAGS,LIBF_SUMUSED!LIBF_CHANGED
  123.     INITWORD    LIB_VERSION,VERSION
  124.     INITWORD    LIB_REVISION,REVISION
  125.     INITLONG    LIB_IDSTRING,IDString
  126.     DC.L        0
  127.  
  128. ; This routine gets called after the library has been allocated. The library
  129. ; pointer is in D0. The segment list is in A0. If it returns non-zero then
  130. ; the library will be linked into the library list.
  131.  
  132. initRoutine:
  133. ;------ get the library pointer into a convenient A register
  134.     MOVEM.L    A2/D6/D7/A6/A5,-(A7)
  135.     MOVEA.L    D0,A5
  136. ;------ save a pointer to our loaded code
  137.     MOVE.L    A0,SegList
  138. ;
  139. ; specific openings here
  140. ;
  141.     MOVEA.L    4.W,A6
  142.     MOVEQ    #MINOSVERSION,D0
  143.     LEA    DOSNAME(PC),A1
  144.     JSR    _LVOOpenLibrary(A6)
  145.     MOVE.L    D0,_DOSBase
  146.     BEQ.B    .kill
  147.     MOVEQ    #MINOSVERSION,D0
  148.     LEA    INTUITIONNAME(PC),A1
  149.     JSR    _LVOOpenLibrary(A6)
  150.     MOVE.L    D0,_IntuitionBase
  151.     BEQ.B    .kill
  152.     MOVEQ    #MINOSVERSION,D0
  153.     LEA    UTILITYNAME(PC),A1
  154.     JSR    _LVOOpenLibrary(A6)
  155.     MOVE.L    D0,_UtilityBase
  156. *    BEQ.B    .kill            * remove mark out, when special
  157.                     * OS 2.0 version
  158.     MOVEQ    #38,D0
  159.     LEA    LOCALENAME(PC),A1
  160.     JSR    _LVOOpenLibrary(A6)
  161.     MOVE.L    D0,_LocaleBase
  162.     BEQ.B    .endok
  163.     MOVEA.L    D0,A6
  164.     SUBA.L    A0,A0
  165.     JSR    _LVOOpenLocale(A6)
  166.     MOVE.L    D0,_Locale
  167.     BEQ.B    .endok
  168.     MOVEA.L    D0,A0
  169.     LEA    CATALOGNAME(PC),A1
  170.     SUBA.L    A2,A2
  171.     JSR    _LVOOpenCatalogA(A6)
  172.     MOVE.L    D0,_Catalog
  173.     BEQ.B    .endok
  174.     MOVEQ    #STRINGANZ-1,D6
  175.     MOVEQ    #STRINGSTART,D7
  176.     LEA    _strings,A2
  177.     BSR.B    DoLocale
  178.     MOVEQ    #ERRSTRINGANZ-1,D6
  179.     MOVE.L    #ERRSTRINGSTART,D7
  180.     LEA    _XpkErrs,A2
  181.     BSR.B    DoLocale
  182.  
  183. .endok    MOVE.L    A5,D0
  184. .end    MOVEM.L    (A7)+,A2/D6/D7/A6/A5
  185.     RTS
  186. .kill    BSR.B    KillLibs
  187.     MOVEQ    #0,D0
  188.     BRA.B    .end
  189.  
  190. DoLocale    MOVE.L    _Catalog(PC),A0
  191.         MOVE.L    D7,D0
  192.         MOVEA.L    A2,A1
  193.         ADDQ.L    #1,D7
  194.         JSR    _LVOGetCatalogStr(A6)
  195.         MOVE.L    D0,(A2)+
  196.         DBRA.B    D6,DoLocale
  197.         RTS
  198.  
  199. ; here begins the system interface commands. When the user calls
  200. ; OpenLibrary/CloseLibrary/RemoveLibrary, this eventually gets translated
  201. ; into a call to the following routines (Open/Close/Expunge). Exec has
  202. ; already put our library pointer in A6 for us. Exec has turned off task
  203. ; switching while in these routines (via Forbid/Permit), so we should not
  204. ; take too long in them.
  205.  
  206. ; Open returns the library pointer in D0 if the open was successful. If the
  207. ; open failed then null is returned. It might fail if we allocated memory
  208. ; on each open, or if only one application could have the library open at
  209. ; a time...
  210.  
  211. Open:        ; (libptr:A6, version:D0)
  212. ;------ mark us as having another opener
  213.     ADDQ.W    #1,LIB_OPENCNT(A6)
  214.     BCLR    #LIBB_DELEXP,LIB_FLAGS(A6)
  215.     MOVE.L    A6,D0
  216.     RTS
  217.  
  218. ; There are two different things that might be returned from the Close
  219. ; routine. If the library is no longer open and there is a delayed expunge
  220. ; then Close should return the segment list (as given to Init). Otherwise
  221. ; close should return NULL.
  222.  
  223. Close:        ; (libptr:A6)
  224. ;------ set the return value
  225.     MOVEQ    #0,D0
  226. ;------ mark us as having one fewer openers
  227.     SUBQ.W   #1,LIB_OPENCNT(A6)
  228. ;------ see if there is anyone left with us open
  229.     BNE.B    .OneLeft
  230. ;------ do the expunge
  231.     BTST    #LIBB_DELEXP,LIB_FLAGS(a6)
  232.     BEQ.B    .OneLeft
  233.     BSR.B    Expunge
  234. .OneLeft
  235.     RTS
  236.  
  237. ; There are two different things that might be returned from the Expunge
  238. ; routine. If the library is no longer open then Expunge should return the
  239. ; segment list (as given to Init). Otherwise Expunge should set the delayed
  240. ; expunge flag and return NULL.
  241. ; One other important note: because Expunge is called from the memory
  242. ; allocator, it may NEVER Wait() or otherwise take long time to complete.
  243.  
  244. Expunge:    ; (libptr: A6)
  245.     MOVEM.L    D2/A5/A6,-(A7)
  246.     MOVEA.L    A6,A5
  247.     MOVEA.L    4.W,A6
  248. ;------ see if anyone has us open
  249.     TST.W    LIB_OPENCNT(A5)
  250.     BEQ.B    .DoIt
  251.     BSET    #LIBB_DELEXP,LIB_FLAGS(A6)
  252.     MOVEQ    #0,D0
  253.     BRA.B    .Expunge_End
  254. .DoIt
  255. ;------ go ahead and get rid of us.  Store our seglist in D2
  256.     MOVE.L    SegList(PC),D2
  257. ;------ unlink from library list
  258.     MOVEA.L    A5,A1
  259.     JSR    _LVORemove(A6)
  260. ;
  261. ; device specific closings here...
  262.     BSR.B    KillLibs
  263. ;
  264. ;------ free our memory
  265.     MOVEQ    #0,D0
  266.     MOVEA.L    A5,A1
  267.     MOVE.W    LIB_NEGSIZE(A5),D0
  268.     SUBA.L    D0,A1
  269.     ADD.W    LIB_POSSIZE(A5),D0
  270.     JSR    _LVOFreeMem(A6)
  271. ;------ set up our return value
  272.     MOVE.L    D2,D0
  273.  
  274. .Expunge_End
  275.     MOVEM.L    (A7)+,D2/A5/A6
  276.     RTS
  277.  
  278. KillLibs:    MOVEA.L    4.W,A6
  279.         MOVEA.L    _IntuitionBase(PC),A1
  280.         MOVE.L    A1,D0                ; for checking
  281.         BEQ.B    .utility
  282.         JSR    _LVOCloseLibrary(A6)
  283. .utility    MOVEA.L    _UtilityBase(PC),A1
  284.         MOVE.L    A1,D0
  285.         BEQ.B    .dos
  286.         JSR    _LVOCloseLibrary(A6)
  287. .dos        MOVEA.L    _DOSBase(PC),A1
  288.         MOVE.L    A1,D0
  289.         BEQ.B    .locale
  290.         JSR    _LVOCloseLibrary(A6)
  291. .locale        MOVEA.L    _LocaleBase(PC),A6
  292.         MOVE.L    A1,D0
  293.         BEQ.B    .endlibs
  294.         MOVEA.L    _Catalog(PC),A0
  295.         MOVE.L    A0,D0
  296.         BEQ.B    .closelocale
  297.         JSR    _LVOCloseCatalog(A6)
  298. .closelocale    MOVEA.L    _Locale(PC),A0
  299.         MOVE.L    A0,D0
  300.         BEQ.B    .closelibrary
  301.         JSR    _LVOCloseLocale(A6)
  302. .closelibrary    MOVEA.L    A6,A1
  303.         MOVEA.L    4.W,A6
  304.         JSR    _LVOCloseLibrary(A6)
  305. .endlibs    RTS
  306.  
  307. Null:    MOVEQ    #0,D0
  308.     RTS
  309.  
  310. SegList:    DC.L    0    * set by Init
  311. _Catalog:    DC.L    0
  312. _Locale:    DC.L    0
  313. _LocaleBase:    DC.L    0
  314. _DosBase:
  315. _DOSBase:    DC.L    0    * set by Init    these are library globals
  316. _UtilityBase:    DC.L    0    * set by Init    in C Code read only !!!
  317. ENDCODE:
  318. _IntuitionBase:    DC.L    0    * set by Init
  319.         END
  320.