What is the process for loading libload libs in eZ80 Assembly?
I haven't been able to find the resource to explain this as of yet, and I'm hoping to at least get pointed in the right direction.
Thanks
At the start of your program, call this code:


Code:
   call   load_libload_libraries
   jr   nz,failed_to_load_libs


And then put this somewhere in your program (it should only be called once)

Code:
; returns z if loaded, nz if not loaded
load_libload_libraries:
   jr   .tryfind
.inram:
   call   ti.Arc_Unarch
.tryfind:
   ld   hl,libload_name
   call   ti.Mov9ToOP1
   call   ti.ChkFindSym
   jr   c,.notfound
   call   ti.ChkInRam
   jr   z,.inram
   ld   hl,9 + 3 + libload_name.len
   add   hl,de
   ld   a,(hl)
   cp   a,$1f
   jr   c,.notfound
   dec   hl
   dec   hl
   ld   de,.relocations
   ld   bc,.notfound
   push   bc
   ld   bc,$aa55aa
   jp   (hl)
.notfound:
   xor   a,a
   inc   a
   ret

.relocations:
libload_libload:
   db   $c0, "LibLoad", $00, $1f


; -----------------------------------------------------
; put the libraries here
; see below code snippet for information
; -----------------------------------------------------

   xor   a,a      ; return z (loaded)
   pop   hl      ; pop error return
   ret

libload_name:
   db   ti.AppVarObj, "LibLoad", 0
.len := $ - .


In the section where it says to put the libraries, this is the format:

marker, library name, null terminator, minimum library version

This is then followed by a jump table starting at 0 and adding 3 for every function in this list for example.

You only need to include the functions that you use, but the offset needs to be correct.

For example, to support calling the gfx_Begin, gfx_End, and gfx_SetDefaultPalette from graphx, and the ti_CloseAll, ti_OpenVar, and ti_Write from fileioc, you would add the following code in that section:


Code:
   db   $c0, "GRAPHX", 0, 9

gfx_Begin:
   jp   0
gfx_End:
   jp   3
gfx_SetDefaultPalette:
   jp   9

; add more graphx functions as needed

   db   $c0, "FILEIOC", 0, 4

ti_CloseAll:
   jp   0
ti_OpenVar:
   jp   6
ti_Write:
   jp   12

; add more fileioc functions as needed


Once you have called load_libload_libraries successfully, you can just call the graphx and fileioc functions as normal from assembly.
Thank you very much for your detailed response Smile

Although:
Where is the ".inram:" label?

EDIT: I'm using the loader described in the toolchain
EDIT2: It works now
In what order would I pass arguments to a function?

P.S. the local label inram is undefined.
The first argument is the last push.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement