Path: utzoo!attcan!uunet!lll-winken!ncis.llnl.gov!helios.ee.lbl.gov!pasteur!ucbvax!bloom-beacon!apple!lsr From: lsr@Apple.COM (Larry Rosenstein) Newsgroups: comp.sys.mac.programmer Subject: Re: Help With VBL Tasks Keywords: VBL task; post itself; BOMB Message-ID: <468@internal.Apple.COM> Date: 23 Jan 89 20:49:24 GMT References: <8343@orstcs.CS.ORST.EDU> <445@internal.Apple.COM> <8383@orstcs.CS.ORST.EDU> Organization: Advanced Technology Group, Apple Computer Lines: 119 In article <8383@orstcs.CS.ORST.EDU> borcelf@jacobs.CS.ORST.EDU.UUCP (Fernando Borcel) writes: > >OK, I'm using LSPascal. How do I get A0, and what is the TYPE of what it's >pointed by it? Here is a simple LSP 2.0 program that shows how to use VBLs. It sets up a VBL task that runs every 2 seconds. That task increments a global variable. The main program loops checking the variable and printing it when it changes. When you click the mouse the program stops. I don't know if the GetA0 technique is absolutely safe. It depends on the compiler not using A0 for anything before the start of the vbl task. It seemed to work in this case. A safer technique is to write a short assembler routine that gets A0 and passes it as a parameter to your Pascal routine. But this requires some other development system that can generate assembler code. (Eg, MPW or LSC.) *********** program VBLTest; var myRecord: record mya5: LONGINT; vblBlock: VBLTask; end; state: INTEGER; { INLINES to manipulate A5 } function GetA5: LONGINT; inline $2E8D; {MOVE.L A5,(A7)} function LoadA5 (newA5: LONGINT): LONGINT; inline $2F4D, $0004, $2A5F; { INLINE to get A0 in the task } function GetA0: LONGINT; inline $2e88; { Can't do debugging at interrupt level } { don't want to use $A+ because it uses CurrentA5 } {$D-} procedure VBL; var err: OSErr; curA5: LONGINT; p: ^LONGINT; begin { Get the pointer to myA5 } p := Pointer(GetA0 - 4); { Set A5 } curA5 := LoadA5(p^); { Here's where you do something. } state := state + 1; { Reset the VBL counter } myRecord.vblBlock.vblCount := 120; { Restore A5 } curA5 := LoadA5(curA5); end; {$D+} var err: OSErr; old: integer; ev: EventRecord; begin { Initialize A5 } myRecord.mya5 := GetA5; state := 0; old := 0; showtext; with myRecord.vblBlock do begin qType := Ord(vType); vblAddr := @VBL; vblCount := 120; vblPhase := 0; end; err := VInstall(@myRecord.vblBlock); writeln('err=', err); while true do begin if old <> state then begin old := state; writeln(old); end; if GetNextEvent(-1, ev) then begin if ev.what = mouseDown then leave; end; end; err := VRemove(@myRecord.vblBlock); writeln('err=', err); end.-- Larry Rosenstein, Object Specialist Apple Computer, Inc. 20525 Mariani Ave, MS 46-B Cupertino, CA 95014 AppleLink:Rosenstein1 domain:lsr@Apple.COM UUCP:{sun,voder,nsc,decwrl}!apple!lsr