home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / Cruncher / XPK416SR.LHA / xpk_Source / xpkmaster / libdata.a < prev    next >
Encoding:
Text File  |  1997-09-06  |  9.4 KB  |  348 lines

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