[comp.sys.mac.programmer] Help for VBL

meynard@anodin.iro.umontreal.ca (Meynard Yves) (11/04/88)

   I've been fruitlessly trying to install a VBL task in the Vertical
Retrace queue.  I haven't got the faintest idea what I can be doing
wrong.
   I define a task, fill in all the fields with appropriate values, as
per IM2, then tell the machine to "VInstall(thePtr)" and... crash.  A
bad one that corrupts memory all over, at that. 
   I'm using a Mac Plus with TML Pascal 2.5, a coupla' INITs as well.  Does it
matter? 
   Could anyone point me to a source code example for doing this?
Many thanks.

tim@hoptoad.uucp (Tim Maroney) (11/06/88)

In article <737@mannix.iros1.UUCP> meynard@iros1.iro.umontreal.ca writes:
>   I've been fruitlessly trying to install a VBL task in the Vertical
>Retrace queue.  I haven't got the faintest idea what I can be doing
>wrong.
>   I define a task, fill in all the fields with appropriate values, as
>per IM2, then tell the machine to "VInstall(thePtr)" and... crash.  A
>bad one that corrupts memory all over, at that. 

Here's an easy way to find out why this is happening.  Put a debugger
opcode ($a9ff) at the very beginning of your retrace routine using
inline assembler (the same way toolbox traps are declared -- I don't
know the syntax in TML Pascal).  Then use MacsBug or TMON to watch what
happens the first time it goes off.

If you get the crash but the Mac doesn't break into the debugger, then
your routine is not getting called at all -- you've set up the vertical
retrace queue entry data structure incorrectly.  (The most likely cause
in Pascal would be passing a nested function pointer; only top-level
functions can be used as function pointers.)

If you break into the debugger before the crash, simply step through
your retrace code using the trace instruction in MacsBug (or the
equivalent in TMON) and that should show you where things start to go
out of control.  From this information, you should be able to deduce
your problem.

And remember -- if you access globals from inside your retrace routine,
save A5 on entry, set A5 to the value of CurrentA5, run your routine,
and restore the saved A5 on exit.  This isn't the bug at hand -- it
generally takes some time for failure to do this to cause a problem,
and yours is happening at once -- but you need to be aware of it.
-- 
Tim Maroney, Consultant, Eclectic Software, sun!hoptoad!tim
"Don't talk to me about disclaimers!  I invented disclaimers!"
    - The Censored Hacker