[futurebasic] How do you access globals in an INIT? (2nd try)

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : April 1998 : Group Archive : Group : All Groups

From: Mark Goodes <wave@...>
Date: Mon, 27 Apr 1998 23:55:08 -0400
This is a somewhat lengthy and technical message, but I really could use
some help here.  I've asked this question before but now have a better
understanding that will help to refine the question:

I'm writing an INIT that uses the INIT shell that came with FB II.  This
shell patches GetNextEvent and the patch has access to all globals and
local functions.  The patch also has an entry point someplace near the
beginning of the whole code segment, which is determined by the value of a4
when the startup routine is running (after which all the relevant code is
copied into a pointer block).

Now I've taken the shell and attempted to add to it.  First step:  create
and install another patch.  It's no problem to write the patch, but it
can't have the same entry point because then I wouldn't know which trap was
calling my code.  So instead I stick the patch somewhere in the middle of
the code segment and put in a GOTO statement to jump over it and write a
few test statements in assembler.  I install the patch using traditional
methods.

The problem is:  when my new patch is called, I have almost no access to
globals.  Nor can I call local fns.  All of these produce address or bus
errors.  (Interestingly, the following will work:
  myRecord.field1%=myVar%
but this won't:
  myRecAddr&=@myRecord)
So to avoid clunking around using low-level addressing techniques all the
time, I need to find a way to access the globals.

I tried what seemed to be a rather clever technique:  when the code entered
my patch, I set a value (which was stored inside the code space itself) to
identify which patch had been called, then jsr'd to the start of the whole
code segment, then entered a second routine which was supposed to continue
the patch code.  But the second routine kept crashing with address or bus
errors in spite of my best attempts to fix the problem.

So what I'm hoping is that there's another way to access the globals.
Walking through Macsbug shows that FB uses a6 or a4 addressing to find the
globals.  Is there a value in a6 that I can store at startup, or a pointer
value somewhere, which will give the base address for the globals?  And is
there a way to tell FB where the globals are so that I don't have to
calculate my own offsets into the global space?

Any help will save me from a number of evenings crashing my machine and
poking around by trial and error.  TIA.


____________
wave (Toronto, Canada)
Much better at "OOPS!" programming than OOP programming.