rs4u#@ANDREW.CMU.EDU (Richard Siegel) (05/06/87)
Following is a short Lightspeed Pascal program that does a vertical retrace
task.
The program should be commented well enough, but if you've any comments,
send 'em to rs4u@andrew.cmu.edu or {ucbvax, decvax, seismo}!andrew.cmu.edu!rs4u
--Rich
PROGRAM Retrace;
{Puts up a vertical retrace task that inverts the menu bar and beeps twice per
second.}
{This is a really quick and dirty program; the task itself calls SetUpA5 so that
the system}
{doesn't risk a crash. This is because we modify "mytask" (an application
global) directly}
{to keep the task running. Recall that a task has to reset its own VBLCount
field}
{in order to keep running. This is the simplest (but not the best) way to do
that}
{Richard Siegel. May 6, 1987}
{Comments to rs4u@andrew.cmu.edu}
VAR
myTask : VBLTask;
PROCEDURE TheTask;
VAR
task : VBLTask;
BEGIN
{Do our thing}
SysBeep(2); {beep for 2 ticks}
FlashMenuBar(0); {invert the menu bar}
SetUpA5; {get application globals boundary so we get the right pointer to
"myTask"}
mytask.vblCount := 30; {we need to reset this so the task will keep executing}
RestoreA5; {restore A5 to what it was before}
END;
PROCEDURE InstallTask;
VAR
err : OSErr;
BEGIN
WITH myTask DO
BEGIN
qType := Ord(vType); {A vertical retrace task!}
vblAddr := @TheTask; {our task procedure}
vblCount := 30; {30 ticks between invocations}
vblPhase := 0; {no timing shift}
END;
err := VInstall(@myTask); {Install it}
END;
PROCEDURE RemoveTask;
VAR
err : OSErr;
BEGIN
err := VRemove(@MyTask); {fields are already set up; remove the task}
END;
BEGIN
InstallTask;
WHILE NOT Button DO {wait for mouse click}
;
RemoveTask; {if we don't remove it the system's likely to crash when we exit}
END.