680x0:Opening a library

From Amiga Coding
Jump to: navigation, search

This is a example on how to open a library:
(with the Library Vector Offsets added so you won't need to use any includes yet)


OldOpenLibrary	= -408		; OldOpenLibrary(libName)(A1)
OpenLibrary = -552 ; OpenLibrary(libName,version)(A1,D0)
CloseLibrary = -414 ; CloseLibrary(library)(A1)
 
move.l $4.w,a6 ; Get the value at position $4 in memory
; This value is the base of exec.library
 
lea LibName(pc),a1 ; libName must be in A1
moveq #0,d0 ; version must be in D0
jsr OpenLibrary(a6) ; Call the OpenLibrary function
 
; OpenLibrary looks if the library is in memory (or ROM)
; and loads it if nessesary.
; Then it returns the base of the requested library in d0
 
move.l d0,libbase ; Store the base
 
 
; You can access function in a library with this base,
; like we called OpenLibrary() with exec.library's base.
; move.l d0,a6  ; move to a6, since d0 can't be used for addresses
; jsr SomeFunction(a6)
 
 
; Now close the library we opened
move.l $4.w,a6 ; Get exec.library's base again
move.l libbase,a1 ; Get the base of the library we want to close
jsr CloseLibrary(a6)
 
rts
 
libname: dc.b 'dos.library',0
libbase: dc.l $00000000


Notes (important):


Notes on optimizing:


LVO's

TODO

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox