Difference between revisions of "680x0:Opening a library"

From Amiga Coding
Jump to: navigation, search
(changed so example gets syntax highlighting)
(fixed mistakes in comment, added more info and some todo's)
 
Line 15: Line 15:
 
jsr OpenLibrary(a6) ; Call the OpenLibrary function
 
jsr OpenLibrary(a6) ; Call the OpenLibrary function
  
; OldOpenLibrary looks if the library is in memory (or ROM)
+
; OpenLibrary looks if the library is in memory (or ROM)
 
; and loads it if nessesary.
 
; and loads it if nessesary.
; Then it returns the base of graphics.library in d0
+
; Then it returns the base of the requested library in d0
  
 
move.l d0,libbase ; Store the base
 
move.l d0,libbase ; Store the base
  
; Closelibrary needs the base of the library
 
; (the address given to you in D0 by OpenLibrary)
 
; to close the library
 
  
move.l libbase,a1 ; Get 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)
 
jsr CloseLibrary(a6)
  
Line 33: Line 38:
 
libbase: dc.l $00000000
 
libbase: dc.l $00000000
 
</code>
 
</code>
 +
 +
 +
Notes (important):
 +
* ...a6
 +
* ...scratch registers
 +
 +
 +
Notes on optimizing:
 +
** use 'move.l $4.w,a6' instead of 'move.l $4,a6'
 +
** use 'moveq' if the version you require is lower than 128
 +
** if you want to save on bytes you can reuse libname to store your libbase
 +
** There's also a function OldOpenLibrary doesn't have the library version check. If you are desperate you could use OldOpenLibrary and save a few bytes by not needing a moveq/move.l #version,d0. Commodore didn't want anyone to use this, it would be removed, but it never happened and removing it would probably break too many programs.
 +
 +
 +
==LVO's==
 +
TODO

Latest revision as of 02:50, 18 May 2008

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):

  • ...a6
  • ...scratch registers


Notes on optimizing:

    • use 'move.l $4.w,a6' instead of 'move.l $4,a6'
    • use 'moveq' if the version you require is lower than 128
    • if you want to save on bytes you can reuse libname to store your libbase
    • There's also a function OldOpenLibrary doesn't have the library version check. If you are desperate you could use OldOpenLibrary and save a few bytes by not needing a moveq/move.l #version,d0. Commodore didn't want anyone to use this, it would be removed, but it never happened and removing it would probably break too many programs.


LVO's

TODO