home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fish 'n' More 2
/
fishmore-publicdomainlibraryvol.ii1991xetec.iso
/
dirs
/
libtool_463.lzh
/
LibTool
/
LibTool.lzh
/
AsmComplex
/
Complex.DOC
< prev
next >
Wrap
Text File
|
1990-06-27
|
4KB
|
81 lines
This describes how to make the "complex.library" assembly example. If you
have not made the "simple.library" assembly example, do so first.
The primary difference between the complex and simple example is that the
complex example introduces the Init, Expunge, Open, and Close vectors, and a
scheme for avoiding global data.
When a library is first loaded, an initialization routine is called. This is
the routine that opens the intuition, graphics, DOS, and exec libraries on
behalf of your lib functions. There are some other things that you might want
to do (once only) when the lib is first loaded. For example, you might want
to set up a port, or start a separate task. These are things that you only
wish to do once at the beginning. If you need to do something like this, you
should write a function, and place it with your lib functions. Now, add a
##init line to your fd file followed by the name of your function. For example,
if your function is myInit().
##init myInit
You'll probably want to free that port, or remove that task when you're lib
finally gets removed from memory. You do this by writing a function to free/
close anything that you allocate/open in your Init function. Assume that we
wrote a function called myFree(). Add this line to the fd file
##expu myFree
On the other hand, there are things that you might need to do once for each
task that uses the lib. For example, you may want to allocate some memory for
each task to be used as a "work buffer". Each task needs its own memblock to
be allocated once when the task opens the lib. Write a function to do this, and
set it up as the Open vector. Here is an example of an Open vector, OpenIt().
##open OpenIt
Now, you'll want to free each task's memory when the task closes the lib. You
do this by writing a function and setting it up as the Close vector. For
example, you might add this line to the fd file for some CloseIt() function.
##clos CloseIt
You can set up one or all four of the above vectors. Just remember that the
Init function only gets executed once when the lib is loaded. The Open routine
gets executed everytime that an application opens the library. You should free/
close anything that you allocate/open in the Init function, with a corresponding
Expunge function. Likewise, a Close function complements an Open function.
The Close and Expunge vectors return nothing. The Init and Open vectors should
return d0 = 1 if everything went well, or d0=0 for an error. If an error,
this will force the application's OpenLibrary to fail. Your Init and Open
routines are responsible for cleaning up their partially allocated resources.
The complex.library sets up an Open and complimentary Close vectors for the
above purpose. Each task gets a work buffer which we use for making a newWindow
structure. This work buffer gets linked into a master list so that we can keep
track of all of them. We use the address of each task to tag its work buffer.
Note these 2 functions, OpenUp() and CloseUp() in the file "Complex.asm".
Also, note how I set them up in the fd file "Complex.fd".
This library also has 3 functions:
MakeWindow - opens a window
PrintMsg - prints a msg and waits for a CLOSEWINDOW
RemWindow - closes the window
Note that we have changed the name and id of the library. Also note how I
use the ##ret to declare the return values of the lib functions.
To make the library, assemble "Complex.asm" as "Complex.o". Invoke LibTool
on "Complex.fd" to make our asm INCLUDE file and libstart code.
LibTool -am Complex.fd
You should see "Complex.i" and "Complex.src". Assemble "Complex.src" as
"LibStart.o".
Link the library as follows
blink LibStart.o Complex.o small.lib NODEBUG TO Libs:complex.library
To make a test application, assemble "ComplexApp.asm". Link with a standard
startup code:
blink startup.o complexapp.o NODEBUG TO ram:TestProgram
Now run ram:TestProgram.