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.