home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-04-28 | 3.0 KB | 142 lines | [TEXT/PJMM] |
- (************************************************************************)
- (* put up an interrupt driven cursor *)
- (* from inside Macintosh "Processes" *)
- (* Daniel W. Rickey *)
- (* drickey@irus.rri.uwo.ca *)
- (* London, Ontario *)
- (* CANADA *)
- (* last modified 1994-04-28 *)
- (************************************************************************)
-
- Program SpinCursor;
-
- Uses
- Retrace;
-
- Const
- InterruptDelay = 4;
- MaxNumberCursors = 16; {maximum number of cursors in animation}
-
- Type
- CursorsList = Array[1..MaxNumberCursors] Of CursHandle;
- CursorTask = Record
- myVBLTask: VBLTask;
- myCursors: CursorsList;
- myFrame: Integer;
- NumberOfCursors: Integer;
- End;
-
- CursorTaskPTR = ^CursorTask;
-
- Var
- gmyCursorTask: CursorTask;
-
- (**** returns address of a VBL task record, from within a VBL task ****)
- Function GetVBLRec: LongInt;
- Inline
- $2E88;
-
- (**** this is the task that is executed during a VBL ****)
- {$PUSH}
- {$D- V- R-}
- {can not have debug information in an interrupt routine!}
- Procedure ChangeCursor;
-
- Var
- RecPTR: CursorTaskPtr;
-
- Begin
- (* get cursor information *)
- RecPtr := CursorTaskPtr(GetVBLRec);
-
- With RecPtr^ Do
- Begin
- (* display the next cursor *)
- SetCursor(myCursors[myFrame]^^);
-
- (* advance to the next cursor frame *)
- myFrame := myFrame + 1;
-
- (* wrap around to the first cursor *)
- If myFrame > NumberOfCursors Then
- Begin
- myFrame := 1;
- End;
- End;
-
- (* set task to run again *)
- RecPtr^.myVBLTask.vblCount := InterruptDelay;
- End; {ChangeCursor}
- {$POP}
-
-
- (**** call this procedure to start a moving cursor ****)
- Procedure StartSpinning (NumOfCursors, InitialResID: Integer);
-
- Const
- InitialDelay = 10;
-
- Var
- myError: OSerr;
- Count: Integer;
-
- Begin
-
- (*initialise cursor information*)
- gMyCursorTask.NumberOfCursors := NumOfCursors;
-
- For Count := 1 To NumOfCursors Do
- Begin
- (* load cursor into memory*)
- gMyCursorTask.MyCursors[Count] := GetCursor(InitialResID + Count - 1);
-
- (*lock cursor so that we can call SetCursor at Interrupt time*)
- HLockHi(Handle(gMyCursorTask.MyCursors[Count]));
- End;
-
- gMyCursorTask.MyFrame := 1;
-
- (* initialise the VBL task record *)
- With gMyCursorTask.MyVBLTask Do
- Begin
- qType := ORD(vType); (* set queue type *)
- vblAddr := @ChangeCursor; (* get address of VBL task *)
- vblCount := InitialDelay; (* set task frequency/delay *)
- vblPhase := 0; (* no phase *)
- End;
-
- (* install the interrupt *)
- myError := VInstall(@gMyCursorTask.MyVBLTask);
- End; {StartSpinning}
-
-
- (**** call this to stop the moving/spinning cursor ****)
- Procedure StopSpinning;
-
- Var
- myError: OSErr;
- Count: Integer;
-
- Begin
- (*remove the task record from its queue*)
- MyError := VRemove(@gMyCursorTask.MyVBLTask);
-
- (*free memory occupied by the cursors *)
- For Count := 1 To gMyCursorTask.NumberOfCursors Do
- Begin
- ReleaseResource(Handle(gMyCursorTask.MyCursors[Count]));
- End;
-
- End; {StopSpinning}
-
- Begin
-
- StartSpinning(7, 128);
-
- Repeat
- Until Button;
-
- StopSpinning;
-
-
- End.