From: mhall@occs.cs.oberlin.edu (Matthew Hall)
Subject: Slot VBL Tasks - How do I find slots and globals
Organization: Oberlin College Computer Science
Distribution: comp.sys.mac.programmer
Date: Sun, 27 Sep 1992 19:42:30 GMT
X-Posted-From: occs.cs.oberlin.edu
NNTP-Posting-Host: sol.ctr.columbia.edu

Hello-
I have been commissioned to write a psych experiment, where a small
square on a green background flickers from red to the backgrounds
color at about 15 Hz.  The user must be able to control the intensity
of the red.
I chose to implement this by installing a SlotVTask that performs
every couple of retraces.  This way I could use a scroll bar to change
the red's brightness. (if I had put it in a loop, it might be hard to
keep it flickering at a constant rate).  I also wanted to synch it to
the vertical retrace so that I wouldn't get squares drawn half
red,half green.

Now, a few questions.
How do I find the slot for the current gDevice?  For my computer, I
just looked at the 'scrn' 0 resource and hard coded it in, but I want
my code a little more portable than that.  I can't find a slot field
in the GDevice.

Also, right now I am using self modifying code to find the globals
within my VBLTask.  Basically, I wrote the code like this:

procedure MyVBLTask;
var CurA5 : LONGINT;
...
begin
   CurA5 :=$12345678;
   OldA5:=SetA5(CurA5)
   ...
   OldA5:=SetA5(OldA5);
end;

{Installing the vbltask}
Type LongPtr : ^LONGINT;
var Illegal : Longptr;
begin
Illegal:=LongPtr(@MyVBLTask); {Find it's entry in Jump table}
Illegal:=LongPtr(ORD(Illegal)+2); {Find VBLTasks entry from jump
table}
Illegal:=LongPtr(ORD(Illegal^)+$0A) {Set Illegal to the place in my
VBLTask where I assign $12345678 to CurA5.  Specifically to the
constant $12345678.  I found the $A offset from MacsBug}
Illegal^:=SetCurrentA5;

Now obviously this is horrid, but SetupA5, RestoreA5 will not work(I
tried it).  This doesn't need to port to A/UX, nor does this program
need to survive for more than a year, so my question is Is This Method
Too Awful for even a hack?  If it is, how do I find globals from a
VBLTask?

And last, from within my task I am calling AnimateEntry to change the
color of the square.  IMV says this is okay.  IMVI says this is bad,
and so would be pmforecolor, drawrect combinations.  It works on my LC
System 6.0.7.  I tried using SetEntries to change the color but it was
so slow that my machine was barely able to update the scroll bar.
(IMVI doesn't say you can't use Setentries from a VBLTask, but it
doesn't say you can, either.)  My question is, am I all right as long
as I am in system 6.0.x with animate entry? In System 7?  If not, is
there any feasible way to animate a color table entry?

Thanks
-matt hall
--
-------------------------------------------------------------------------------
Matt Hall.    mhall@occs.oberlin.edu  OR  SMH9666@OBERLIN.BITNET
              (216)-775-5805 (That's a Cleveland Area code. Lucky Me)

" When Fate arrives, a Physician becomes a Fool" - moon over morocco
    -particularly appropriate to my day last tuesday,
    -also appropriate to Oedipus Rex.

DISCLAIMER: My day last tuesday had no relation to Oedipus Rex, except
            that Fate intervened in both (though more extremely for Oed)
Newsgroups: comp.sys.mac.programmer