A86: Functions and libraries


[Prev][Next][Index][Thread]

A86: Functions and libraries



I'm leaving out the quoting because otherwise, this would be ridiculously 
long.

Functions libraries should work like this.

The end of ALL asm programs using libraries should have the following 
line DIRECTLY before the .end directive:
Libspace:
     jp 0      ;The number of "jp 0"'s is equal to the number of 
functions in the table.
     jp 0
     jp 0

Let's say the first function in the table is "FindPixel", the second is 
"FastLine", and the third is "DrawMenu".  The definition for the table 
would look like this:

JumpTable:
#Define TableEntry(x,y)       .dw x\.db $C3\.dw 0 ;This, with the FN 
ID's, would go into an
                                                  ;Include file for 
library functions.
id_Findpixel   .equ    $A2     ;Just some hypothetical fnID's.
     TableEntry(id_FindPixel)  ;Shell looks up funcID in libs, moves fn,
id_FastLine    .equ    $13     ; and puts pointer in Jump table.
     TableEntry(id_FastLine)
id_DrawMenu    .equ    $8C
     TableEntry(id_DrawMenu)
.dw 0     ;Marks End of table.


Function calls for the libraries will be defined as follows:
Libraries can contain multiple functions, but only one function is 
exported at a time, by its unique ID. Libraries MUST contain ONLY 
relative jumps, unless they call out to ROM.
To call a fn, you'd use the Macro:
#Define libCall(x)  call 3*(x-1)+2*x+JumpTable     ;I don't know if TASM 
accepts this stuff
and use it like this:
FindPixel   .equ    1
FastLine    .equ    2
DrawMenu    .equ    3
libCall(FindPixel)      ;Jumps to JumpTable, which hops out to FN. Ret 
Brings it back here.

Please send any suggestions or revisions of this back to the list.

James Yopp
jyopp@pobox.com
"Time is the fire in which we burn."


Follow-Ups: