Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!uwm.edu!rutgers!usenet!ogicse!qiclab!percy!tektronix!reed!chaffee From: chaffee@reed.UUCP (Alex Chaffee) Newsgroups: comp.sys.mac.programmer Subject: Re: Can the Mac actually do animation? Message-ID: <16310@reed.UUCP> Date: 9 Apr 91 22:36:49 GMT References: <6205@cactus.org> <2966@cod.NOSC.MIL> <314@crucible.UUCP> <552@humu.NOSC.Mil> <16301@reed.UUCP> Organization: Reed College, Portland OR Lines: 110 Okay, I've gotten enough requests -- here's a repost of Sync.c. Be careful - I haven't tested this on small Macs. It's likely that it only works if Color Quickdraw is installed. Alex Chaffee chaffee@reed.bitnet Reed College, Portland OR 97202 ____________________ /* Sync.h */ /* Exported Variables */ extern long vCounter; /* just like Ticks - incremented every refresh */ /* Macros/Prototypes */ void InstallSync(void); void RemoveSync(void); void WaitForSync (void); static long vblJunk; #define WaitForSync() vblJunk = vCounter; do {} while (vblJunk == vCounter); /* Sync.c Implements a VBL counter (like Ticks) on a Mac II Usage: #include "sync.h" InstallSync(); ... WaitForSync(); CopyBits(...); ... RemoveSync(); */ #include "Sync.h" /* Types */ typedef struct { long goodA5; VBLTask task; } MYVBLTASK; /* Globals */ long vCounter; static MYVBLTASK mytask; static DefVideoRec video; /* Prototypes */ static pascal void Task(void); /* Task */ static pascal void Task(void) { long oldA5; MYVBLTASK vbltask; asm { move.l A5,oldA5 ; save off the old value of A5 move.l -4(A0), A5 ; A0 points to our VBL task record, and earlier we ; saved CurrentA5 near it } vCounter++; mytask.task.vblCount = 1; /* we want to run again real soon */ asm { move.l oldA5,A5 } } /* InstallSync */ void InstallSync(void) { GetVideoDefault(&video); mytask.goodA5 = (long)CurrentA5; vCounter = 0; mytask.task.qType = vType; mytask.task.vblAddr = (ProcPtr) Task; mytask.task.vblCount = 1; mytask.task.vblPhase = 0; SlotVInstall(&mytask.task, video.sdSlot); } void RemoveSync(void) { SlotVRemove(&mytask.task, video.sdSlot); } /* If you don't want to use the macro, uncomment this function */ /* void WaitForSync (void) { long vJunk = vCounter; do {} while ( vCounter == vJunk ); } */ -- Alex Chaffee chaffee@reed.bitnet Reed College, Portland OR 97202 ____________________