On Mon, Mar 04, 2002 at 10:39:32AM +1100, Harry Ohlsen wrote:
> I'm using prc-tools on Linux, so can anyone point me at some sample source 
> code that implements a hack using that environment?

I don't have any samples lying around, but actually the process is
simple enough to be described reasonably concisely.  (It ought to be
even simpler and will be if I ever get around to adding specific
standalone code resource / hack support to build-prc's .def file.)

To build a standalone code resource in prc-tools (and for the compiler, a
hack is just a special case of a standalone code resource), you need to:

1. Compile your code normally.  Make sure that the function which you want
   to be the entry point for your code resource or hack is named "start".

        m68k-palmos-gcc -c -o foo.o foo.c

2. Link it.  The important thing about standalone code is it doesn't
   want any startup code; it is its own startup code.  Use -nostartfiles
   when linking to avoid pulling in the normal application startup code.

        m68k-palmos-gcc -nostartfiles -o foo foo.o

3. Rip the .text section out of the linker output and turn it into a
   code resource.  (This is where it gets a bit painful and more support
   in build-prc would be nice.)

   The best way to do this is to run build-prc to make a (temporary)
   .prc file with just your linker output's resources in it, and then
   pull the code resource out again using a tool like par or a suitably
   recent version of pilot-file.

        build-prc -o foo.ro foo
        [ignore build-prc's warnings about names and creator ids -- they
        don't matter for a temporary file]
        par x foo.ro -f TRAP03e8.bin code 1

Now you have your standalone code resource in a binary file TRAP03e8.bin
that will add a TRAP #1000 resource when you use it in the final
build-prc command that builds your hack .prc.

Instead of step 3 you could just use m68k-palmos-objcopy to rip the
.text section out of the linker output directly.  The advantage of doing
it via build-prc is that if the start() function is not at offset 0,
build-prc will insert a jump to it at the beginning of the resource.
Thus you don't need to worry about whether other functions or string
constants or anything else might get placed in the code section in front
of the function you need to be the first thing in the resulting code
resource.  (The name "start" is just the default; if you prefer to use
something more meaningful for your hack, look at the linker's -e option.)

You need to do these three steps separately for each standalone code
resource in your final .prc.

Together with the information at http://www.daggerware.com/hackapi.htm
this ought to be everything you need to know to make a well-built hack.

    John

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to