TweetFollow Us on Twitter

Rotten Apple
Volume Number:8
Issue Number:1
Column Tag:Fun hacks

Related Info: Color Quickdraw

Rotten Apple INIT for April Fool's

"PacMan just ate my Apple menu!"

By Mike Scanlin, MacTutor Regular Contributing Author

Note: Source code files accompanying article are located on MacTech CD-ROM or source code disks.

Picture This

(Scene: Someone working on a Macintosh in an office.

The Apple menu is clicked on.)

“Oh! Look at that!”

(A short animation sequence finishes before someone comes over.)

“Look at what?”

“A little tank just came out and blew up my Apple menu.”

“Uh huh. Looks normal to me. Do it again.”

(Click, click, option-click, ...)

“Well, now it’s not doing it.”

“Gee, I’ve never heard of anything like that before.”

“Well it did!”

“Sure. Bye.”

(Many more clicks on the Apple menu to no avail. No tank. Nothing out of the ordinary. Ten minutes elapse. The Apple menu is clicked on again.)

“Ah ha! Look! PacMan just ate my Apple menu!”

(and so on...)

A Rotten Apple

RottenApple is an INIT that causes one of three animation sequences to happen when you click on the Apple menu’s apple icon: (1) a little tank rolls out and blows it away, (2) PacMan comes out and eats it, or (3) it is replaced with a bomb that explodes. In all three cases a little crane brings back a fresh apple so that you still have the Apple menu when the animation is finished. The sequence that is shown is random but is guaranteed not to be the one that was just shown. In addition, you won’t get an animation every time you click on the Apple menu, only once every so often (which you can set in the source code, the default is not more than once every 10 minutes). It can be fun if the person whose machine you put it on doesn’t know what’s going on (you might want to rename the INIT something innocuous like “Easy Access” or some other little-used file that lives in the System Folder).

How does this work?

The first part of the INIT code creates space for the animation code in the system heap (about 5800 bytes) and moves a copy of the code there. Then it puts a tail patch on GetNextEvent so that it can intercept mouseDowns on the Apple menu at a later time. The patch also intercepts the cmd-shift-opt-Tab keyDown event, which will disable the animation from happening until you restart the Mac (you will hear a beep when the patch disables itself).

Once the special mouseDown event is detected, the patch checks to see if enough time has elapsed since the last animation. If not, it passes the mouseDown through unmodified (and without any animation). However, if enough time has elapsed (or if you hold down the Option and Command keys while clicking on the Apple menu) then one of three animation sequences is run. The patch remembers which sequence was last shown and chooses one of the other two (based on the low bit of Ticks for randomness). After the animation has finished the patch sets the minimum time for the next animation, modifies the event to be a null event and exits.

Note that this INIT could cause problems for some types of script-like or journaling software that simulate clicks on the Apple menu to do their job (things like QuicKeys, Virtual User, etc ) because in the case where an animation is done the click event is ignored.

The Animations

This INIT was written to be expandable. You can add your own animations to the three given here if you want. Since all of the bookkeeping and details of INIT-installation and trap patching have been taken care of, you can concentrate on writing cool animations. All you have to do is add your function and modify the animation dispatcher (the little bit of assembly that decides which animation routine to call) and you’re set. You need to remember a few things, though. You don’t have your own QuickDraw globals, you’re using the ones that CurrentA5 points to. Therefore, be a good citizen and leave things as you found them. (It is possible, albeit unlikely, that GNE will be called when the QuickDraw globals are not initialized. This will probably cause a crash. I have never had this happen.) Secondly, you are executing as a tail patch to GetNextEvent. It is not a good idea to implement a five minute animation because there may be a background task going on that will time out (a print job, a modem connection, etc ). Keep it short and sweet.

For simplicity and reduced memory requirements, I use black and white BitMaps in my animations. Also for simplicity, the animations don’t run if the screen with the menu bar on it has a pixel depth of greater than 1 (i.e., you have to be in black and white mode for anything to happen). The reason why I check for this condition within each animation rather than once at a higher level is because someone may write an animation that runs perfectly well at any bit depth.

If for whatever reason your animation can’t run (not enough memory, wrong pixel depth, etc ) it should return a function result of 1. This tells the GNE tail patch not to modify the event. If the animation returns 0 (meaning that it completed successfully) then the patch changes the event to be a null event (from the user’s point of view, the click is lost).

The three animations here have some common elements (which you can use in your animations, too). All three use the crane at one point and two of the three use the explosion sequence.

The Crane

The crane is useful for removing an object (like the apple) or bringing in an object (like a bomb or a replacement apple). There are three BitMaps for its mouth: craneOpen (all the way open), craneClosing (in the middle of opening or closing) and craneClosed (closed on an object). The neck (the straight horizontal two pixel line) is not part of a BitMap, it’s just a line that’s drawn in the offscreen BitMap.

The Explosion

The explosion has six BitMaps but requires eight frames to execute (plus some delay frames) because the second explosion frame is repeated after the third before the fourth (this looks nicer than not doing it and it saves a little memory to reuse one of the BitMaps rather than making an additional bitmap) and the last frame is blank. This is a general purpose explosion sequence and can be used for anything that is about the size of the apple (like the bomb, for instance).

The Tank

The tank only has one BitMap in the code, although it has three representations on screen. I modify the BitMap in place when I need to have it look different. Every time it moves forward or backward by a pixel the little dots inside the tread are moved to give the illusion of a rotating tread (instead of a tank that slides). The turret rising is just a matter of moving the two end pixels of it up by one pixel. When the tank fires there is no projectile (because it’s so close to the apple) but it does recoil back one pixel (and then forward again as the explosion starts) to add a little realism. After the tank backs away from the exploded apple the crane brings a new apple on the screen.

PacMan

Not much originality here. It’s fun to watch, though. This takes quite a bit of memory for the pixels of the eight little PacMan BitMaps (68*8 = 544 bytes). I could have cut the memory requirements by more than half (saved 288 bytes) if I had made the PacMan 1 pixel less in diameter because then he would have fit within a 16x16 BitMap instead of a 32x17 BitMap (remember, rowBytes has to be even) but, I tried that and it didn’t look nearly as good so I thought the extra memory was worth it. It’s something to think about, though, when designing your BitMaps. Try to make them multiples of 16 pixels wide.

Bomb Disposal

Uh oh! The crane found a little bomb inside your Mac. It has decided to explode it somewhere safe (like on the screen) so that it doesn’t blow up your program.

This is the longest of the animations. First the crane removes the apple, then it brings on the bomb. As the crane is moving away from the bomb the fuse is getting smaller and smaller. Just as the crane gets to the edge of the screen the bomb explodes. When the explosion is complete the crane brings back the apple (or one just like it; they’re difficult to tell apart).

How is a frame drawn?

There is a very simple loop at the center of these animations. The offscreen BitMap is initialized at the beginning of each frame with the background BitMap (which is set to be a copy of what’s in that corner of the screen when the mouseDown occurs during the initialization part of the animation). After that, potentially several BitMaps are srcOr’ed on to the offscreen BitMap (like the apple, the crane, the tank, PacMan, etc ).

Once the offscreen BitMap has been built there is a delay loop that makes sure we wait TicksBetweenFrames ticks before using CopyBits to update the screen. Once the appropriate amount of time has elapsed we CopyBits the offscreen BitMap to the WMgrPort to update the screen. You can change the speed of the animation increasing or decreasing TicksBetweenFrames. Setting it to something like 30 (the default is 3) is useful when debugging the animation sequences because it’s nice and slow.

After the frame has been drawn on the screen we update all of our animation variables. The way I have implemented this is as one switch statement that cases off of the current state we’re in. The current state is defined by a state table sequence at the beginning of each animation. For instance, the first part of the tank state table is:

/* 1 */

#define TComeOnScreen0
#define TTankStop(TComeOnScreen + AppleLeft)
#define TRaiseTurret (TTankStop + 10)
#define TAim(TRaiseTurret + 10)
#define TFire    (TAim + 3)
#define TRecoil  (TFire + 1)
#define TExp2    (TRecoil + 2)
#define TExp3    (TExp2 + 3)

We read this as follows: Frame 0 is when things start. In our case, that’s when the tank begins to roll out. At frame TTankStop we stop the tank. After waiting for 10 frames (until TRaiseTurret) we raise the turret. We then wait for 10 more frames until TAim which gives us a nice delay after raising the turret to build a little suspense (and make people think the tank is loading or whatever). To simulate firing we move the tank back one pixel at the same time that we change the apple to the first frame of the explosion. Three frames later, at TRecoil, we move the tank back to its original position. We then begin the eight step process of working through the states of the explosion (the tank doesn’t move in this case, although it could if we wanted it to).

The corresponding code that does all of what was just described is:

/* 2 */

switch (frameNo) {
case TTankStop:
 /* stop the tank from moving forward */
 tankDirection = 0;
 break;
case TRaiseTurret:
 /* change the BitMap to a raised turret */
 bitsPtr16 = (int *)tank->baseAddr;
 bitsPtr16[ 0] = 0x1C60;
 bitsPtr16[ 1] = 0x3780;
 break;
case TFire:
 /* move the tank left 1 pixel for
  * recoil */
 tank->bounds.left-;
 tank->bounds.right-;
 /* change the object from the apple to the
  * first frame of the explosion */
 theObject = exp1;
 break;
case TRecoil:
 /* move the tank back after the recoil */
 tank->bounds.left++;
 tank->bounds.right++;
 break;
case TExp2:
 theObject = exp2;
 break;
case TExp3:
 theObject = exp3;
 break;

As you can see, there’s not much too it. The hardest part is coming up with cool BitMaps and choreographing the whole thing.

I have chosen to use inline BitMaps that I set up manually one pixel row at a time in hex (0xhh or 0xhhhh) rather than a custom resource type because it seems easier to me to read magazine code when there aren’t 17 separate files that you have to piece together. The animation code and hex data is allocated in the system heap during INIT installation time but, the space for the BitMaps is not. They are allocated with NewPtr (in the system heap) each time the animation runs. Because of this, there is a chance that any one of them could fail for lack of memory. Tank needs 764 bytes of system heap (which is, of course, freed up when it’s done), PacMan needs 1074 bytes and Bomb Disposal needs 742 bytes. I have put in some rudimentary error checking for NIL returned by any of the NewPtr calls but no attempt is made to dispose of any Ptrs that were allocated before the call to NewPtr that failed. I think it is very unlikely that the system heap will have less than 1074 bytes in it at the time that this code executes so this potential memory leak shouldn’t be a problem in practice.

Some people have suggested that I add sound to the animations. I agree that they would be cooler if they made some noise but the idea of playing asynchronous sounds from a tail patch to GetNextEvent didn’t sound like a good idea to me. Also, substantial sound data is difficult to publish in printed form. [I’d like to see a color version first. - Ed.]

Because this is an INIT, the Think C Project Type should be “Code Resource” and the File Type should be “INIT”. You can use whatever you want for the Creator and ID (I used “Newt” with an ID of 55).

Have fun.

Code Listing

/**********************************************
 * RottenApple by Mike Scanlin. Dec 1991.
 *
 * An INIT that installs a tail patch on GNE so
 * that when the user clicks on the apple menu
 * the apple icon gets removed via one of
 * three animation sequences: BombDisposal,
 * PacMan or Tank.
 **********************************************/

/* AppleCore is the hit rect the user must
 * click in to activate the animation
 * (global coordinates) */
#define AppleCoreTop 5
#define AppleCoreLeft19
#define AppleCoreBottom (AppleCoreTop + 9)
#define AppleCoreRight  (AppleCoreLeft + 10)

/* minimum seconds between shows */
#define Frequency600

/* minimum time between frames (increase this
 * number to slow the animation down) */
#define TicksBetweenFrames3

/* used by the patch installation code */
#define GetNextEventTrap  0xA970
#define JmpInstruction    0x4EF9
#define TabKey   0x09
#define NumSavedRegs 5

/* used to detect bit depth */
#define GetMainDeviceTrap 0xAA2A
#define UnimplementedTrap 0xA89F

void main(void);
int MakeCommonBitMaps(BitMap **theApple,
 BitMap **theBackground, BitMap **theOffscreen,
 BitMap **theCraneOpen, BitMap **theCraneClosing,
 BitMap **theCraneClosed, BitMap *theOldBits,
 GrafPtr currentPort);
int MakeExplosionBitMaps(BitMap **theExp1,
 BitMap **theExp2, BitMap **theExp3,
 BitMap **theExp4, BitMap **theExp5,
 BitMap **theExp6);
int DoBombDisposal(void);
int DoPacMan(void);
int DoTank(void);
void EndProc(void);

/**********************************************
 * Install GNE patch
 *
 * This is run at startup time. It gets some
 * space in the system heap and sets up a
 * patch to GetNextEvent. The patch doesn’t
 * do anything until the user clicks in the
 * middle of the Apple menu title icon. In
 * that case they will see a little animation
 * sequence. The animation won’t be shown more
 * than once every ‘Frequency’ ticks. The patch
 * can be disabled at any time by typing
 * cmd-shift-opt-tab.
 **********************************************/

void
main(void) {

 asm {
 
   Move.L D3,-(SP)

/* get the old trap address */
 Move #GetNextEventTrap,D0
 _GetTrapAddress

/* set the address for the Jmp instruction 
 * that calls the original trap */
 Lea    @origTrap,A1
 Move.L A0,(A1)

/* get some space in the system heap */
 Lea    EndProc,A0
 Lea    @first,A1
 Suba.L A1,A0
/* D0 = length of patch */
 Move.L A0,D0
/* save for _BlockMove */
 Move.L D0,D3
 _NewPtrSYS
 Cmpi #memFullErr,D0
 Beq.S  @noPatch
 Lea    @saveLoc,A1
/* save for removePatch */
 Move.L A0,(A1)
/* save for _BlockMove */
 Move.L A0,-(SP)

/* set the trap address to the space we
 * just got in the system heap. */
 Move #GetNextEventTrap,D0
 _SetTrapAddress
 
/* now move our patch into place */
 Lea    @first,A0
 Move.L (SP)+,A1
 Move.L D3,D0
 _BlockMove

@noPatch
 Move.L (SP)+,D3

/* This is the end of the installation part,
 * but we can’t do an Rts here because Think C
 * needs to clean up. So we fall through
 * to the end. */
 Bra    @last

/**********************************************
 * GetNextEvent patch
 *
 * The patch calls the existing GNE and then
 * checks if a mouseDown or keyDown event is
 * being reported. If not, the event is passed
 * to the application unmodified. If we end up
 * using the event ourselves, a null event is
 * returned to the application.
 **********************************************/

@first
/* pop the original return address and save it */
 Lea    @exitAddress,A0
 Move.L (SP)+,(A0)
/* save ptr to event record so we can 
 * get at it later */
 Lea    @eventRecPtr,A0
 Move.L (SP),(A0)
/* set the return address to our patch */
 Pea    @tailPatch

/* the nops get filled with the address of 
 * the original GetNextEvent */
 DCJmpInstruction
@origTrap 
 Nop
 Nop

/* this is where it comes after the normal 
 * GetNextEvent processing */
@tailPatch
/* change NumSavedRegs if not 5 regs below */
 Movem.LA1/D0-D3,-(SP)

/* check if we’ve been disabled */
 Lea    @disabled,A0
 Tst    (A0)
 Bne    @patchExit

 Lea    @eventRecPtr,A0
 Move.L (A0),A0

/* check if it’s a keydown event that says
 * to remove ourself. This is the only keyDown 
 * that we intercept. */
 Move OFFSET(EventRecord,what)(A0),D0
 Cmpi #keyDown,D0
 Bne.S  @noKeyDown

/* the key to remove the patch is cmd-shift-opt-Tab */
 Move.L OFFSET(EventRecord,message)(A0),D0
 Cmpi.B #TabKey,D0
 Bne    @patchExit
 Move OFFSET(EventRecord,modifiers)(A0),D0
 Andi #optionKey+cmdKey+shiftKey+controlKey,D0
 Eori #optionKey+cmdKey+shiftKey,D0
 Beq    @removePatch
 
@noKeyDown
/* if it’s not a mousedown event, then ignore it */
 Cmpi #mouseDown,D0
 Bne    @patchExit

/* did they click in AppleCore? */
 Move.L OFFSET(EventRecord,where)(A0),D0
 Cmpi #AppleCoreLeft,D0
 Blt    @patchExit
 Cmpi #AppleCoreRight,D0
 Bge    @patchExit
 Swap D0
 Cmpi #AppleCoreTop,D0
 Blt.S  @patchExit
 Cmpi #AppleCoreBottom,D0
 Bgt.S  @patchExit

 Move.L Ticks,D0
/* if you hold down cmd-opt when you click in the
 * AppleCore rect then you can force the animation
 * to happen without the Frequency delay */
 Move OFFSET(EventRecord,modifiers)(A0),D1
 Andi #optionKey+cmdKey+shiftKey+controlKey,D1
 Eori #optionKey+cmdKey,D1
 Beq.s  @skipTimeCheck

/* don’t show the animation more than once every
 * Frequency ticks */
 Lea    @nextTime,A0
 Cmp.L  (A0),D0
 Blt.S  @patchExit
 
@skipTimeCheck
/* pick a show at random, but don’t show the one
 * that was most recently shown */
 Lea    @lastShow,A0
 Move (A0),D2
 Bne.S  @lastNotBomb
 Btst #0,D0
 Bne.S  @runPacMan
 Bra.S  @runTank
@lastNotBomb
 Subq #1,D2
 Bne.S  @lastNotPacMan
 Btst #0,D0
 Bne.S  @runBombDisposal
 Bra.S  @runTank
@lastNotPacMan
 Btst #0,D0
 Bne.S  @runPacMan
@runBombDisposal
 Clr    (A0)
 Bsr    DoBombDisposal
 Bra.S  @showFinished
@runPacMan
 Move #1,(A0)
 Bsr    DoPacMan
 Bra.S  @showFinished
@runTank
 Move #2,(A0)
 Bsr    DoTank
@showFinished
 Move.L #(long)60*Frequency,D1
 Add.L  Ticks,D1
 Lea    @nextTime,A0
 Move.L D1,(A0)

/* if no animation was run then don’t change
 * the event. */
 Tst    D0
 Bne.S  @patchExit
 
@returnNullEvent
/* set the event to null */
 Lea    @eventRecPtr,A0
 Move.L (A0),A0
 Clr    OFFSET(EventRecord,what)(A0)
/* change GNE’s return value to false. */
 Clr    (4*NumSavedRegs)(SP)

@patchExit
 Movem.L(SP)+,A1/D0-D3
/* JMP to the place that called GetNextEvent */
 DCJmpInstruction
@exitAddress
 Nop
 Nop


/**********************************************
 * RemovePatch
 *
 * Marks the GNE patch as disabled and then 
 * attempts to remove it. It won’t remove it
 * if someone else has patched GNE since we
 * patched it.
 **********************************************/
@removePatch
/* set the disabled flag */
 Lea    @disabled,A0
   St   (A0)
/* beep to let them know it has been disabled */
 Move #1,-(SP)
 _SysBeep
/* check if we are the most recent patch to GNE.
 * If we’re not, then don’t remove. */
   Move #GetNextEventTrap,D0
 _GetTrapAddress
 Lea    @first,A1
 Cmpa.L A1,A0
 Bne.S  @returnNullEvent
/* set the trap address back to the original trap */
 Lea    @origTrap,A0
 Move.L (A0),A0
 Move #GetNextEventTrap,D0
 _SetTrapAddress
/* free up the mem occupied by this patch */
 Lea    @saveLoc,A0
 Move.L (A0),A0
 _DisposPtr
 Bra.S  @returnNullEvent

/* disabled is non-zero if the patch is disabled */
@disabled dc0
/* eventRecPtr is a copy of the ptr passed to GNE */
@eventRecPtrdc.l 0
/* lastShow: 0=Bomb Disposal, 1=PacMan, 2=Tank */
@lastShow dc0
/* minimum value of Ticks before next show begins */
@nextTime dc.l 0
/* address of our patch in the system heap */
@saveLocdc.l0

@last
 }
}


/**********************************************
 * MakeCommonBitMaps
 *
 * Generates the bitMaps that are common to
 * all three animation sequences.
 **********************************************/

#define BgLeft   0
#define BgTop    0
#define BgRight  31
#define BgBottom 19
#define BgRowBytes (((BgRight-BgLeft+16) >> 3) & 0xFFFE)
#define BgPixelSize(BgRowBytes * (BgBottom-BgTop+1))
#define BgBitMapSize (sizeof(BitMap) + BgPixelSize)

#define AppleLeft(BgRight-15)
#define AppleRowBytes(((BgRight-AppleLeft+16) >> 3) & 0xFFFE)
#define ApplePixelSize  (AppleRowBytes * (BgBottom-BgTop+1))
#define AppleBitMapSize (sizeof(BitMap) + ApplePixelSize)

#define CraneLeft0
#define CraneTop 2
#define CraneRight 9
#define CraneBottom18
#define CraneRowBytes(((CraneRight-CraneLeft+16) >> 3) & 0xFFFE)
#define CranePixelSize  (CraneRowBytes * (CraneBottom-CraneTop+1))
#define CraneBitMapSize (sizeof(BitMap) + CranePixelSize)
#define CraneArmVLoc (((CraneBottom - CraneTop) >> 1) + CraneTop-1)

int
MakeCommonBitMaps(theApple, theBackground, theOffscreen,
 theCraneOpen, theCraneClosing, theCraneClosed, 
 theOldBits, currentPort)
BitMap  **theApple, **theBackground, **theOffscreen,
 **theCraneOpen, **theCraneClosing, 
 **theCraneClosed, *theOldBits;
GrafPtr currentPort;
{
 Ptr    bitsPtr;
 BitMap *p;

 p = (*theApple) = (BitMap *)NewPtrSys(AppleBitMapSize);
 if (!p) return(1);
 p->baseAddr = (Ptr)p + sizeof(BitMap);
 p->rowBytes = AppleRowBytes;
 SetRect(&p->bounds, AppleLeft, BgTop, BgRight, BgBottom);
 CopyBits(&currentPort->portBits, p, 
 &p->bounds, &p->bounds, srcCopy, 0L);
 
 p = (*theBackground) = (BitMap *)NewPtrSys(BgBitMapSize);
 if (!p) return(1);
 p->baseAddr = (Ptr)p + sizeof(BitMap);
 p->rowBytes = BgRowBytes;
 SetRect(&p->bounds, BgLeft, BgTop, BgRight, BgBottom);
 CopyBits(&currentPort->portBits, p, 
 &p->bounds, &p->bounds, srcCopy, 0L);
 
 *theOldBits = currentPort->portBits;
 SetPortBits(p);
 EraseRect(&(*theApple)->bounds);
 SetPortBits(theOldBits);

 p = (*theOffscreen) = (BitMap *)NewPtrSys(BgBitMapSize);
 if (!p) return(1);
 p->baseAddr = (Ptr)p + sizeof(BitMap);
 p->rowBytes = BgRowBytes;
 p->bounds = (*theBackground)->bounds;

 p = (*theCraneOpen) = (BitMap *)NewPtrSysClear(CraneBitMapSize);
 if (!p) return(1);
 p->baseAddr = (Ptr)p + sizeof(BitMap);
 p->rowBytes = CraneRowBytes;
 SetRect(&p->bounds, AppleLeft-CraneRight+6, 
 CraneTop, AppleLeft+6, CraneBottom);
 bitsPtr = p->baseAddr;
 bitsPtr[ 0] = 0x0C;
 bitsPtr[ 2] = 0x1E;
 bitsPtr[ 4] = 0x38;
 bitsPtr[ 6] = 0x30;
 bitsPtr[ 8] = 0x70;
 bitsPtr[10] = 0x60;
 bitsPtr[12] = 0xE0;
 bitsPtr[14] = 0xC0;
 bitsPtr[16] = 0xC0;
 bitsPtr[18] = 0xE0;
 bitsPtr[20] = 0x60;
 bitsPtr[22] = 0x70;
 bitsPtr[24] = 0x30;
 bitsPtr[26] = 0x38;
 bitsPtr[28] = 0x1E;
 bitsPtr[30] = 0x0C;
 
 p = (*theCraneClosing) = (BitMap *)NewPtrSysClear(CraneBitMapSize);
 if (!p) return(1);
 p->baseAddr = (Ptr)p + sizeof(BitMap);
 p->rowBytes = CraneRowBytes;
 SetRect(&p->bounds, AppleLeft-CraneRight+6,
 CraneTop, AppleLeft+6, CraneBottom);
 bitsPtr = p->baseAddr;
 bitsPtr[ 2] = 0x06;
 bitsPtr[ 4] = 0x0F;
 bitsPtr[ 6] = 0x1C;
 bitsPtr[ 8] = 0x38;
 bitsPtr[10] = 0x70;
 bitsPtr[12] = 0xE0;
 bitsPtr[14] = 0xC0;
 bitsPtr[16] = 0xC0;
 bitsPtr[18] = 0xE0;
 bitsPtr[20] = 0x70;
 bitsPtr[22] = 0x38;
 bitsPtr[24] = 0x1C;
 bitsPtr[26] = 0x0F;
 bitsPtr[28] = 0x06;
 
 p = (*theCraneClosed) = (BitMap *)NewPtrSysClear(CraneBitMapSize);
 if (!p) return(1);
 p->baseAddr = (Ptr)p + sizeof(BitMap);
 p->rowBytes = CraneRowBytes;
 SetRect(&p->bounds, -(CraneRight + 6), CraneTop,
 -6, CraneBottom);
 bitsPtr = p->baseAddr;
 bitsPtr[ 4] = 0x0F;
 bitsPtr[ 6] = 0x1F; bitsPtr[ 7] = 0x80;
 bitsPtr[ 8] = 0x38;
 bitsPtr[10] = 0x70;
 bitsPtr[12] = 0xE0;
 bitsPtr[14] = 0xC0;
 bitsPtr[16] = 0xC0;
 bitsPtr[18] = 0xE0;
 bitsPtr[20] = 0x70;
 bitsPtr[22] = 0x38;
 bitsPtr[24] = 0x1F; bitsPtr[25] = 0x80;
 bitsPtr[26] = 0x0F;
 
 return(0);
}


/**********************************************
 * MakeExplosionBitMaps
 *
 * Generates the explosion bitmaps that are
 * used in some of the animation sequences.
 **********************************************/

int
MakeExplosionBitMaps(theExp1, theExp2, theExp3,
 theExp4, theExp5, theExp6)
BitMap  **theExp1, **theExp2, **theExp3,
 **theExp4, **theExp5, **theExp6;
{
 Ptr    bitsPtr;
 int    *bitsPtr16;
 BitMap *p;
 
 p = (*theExp1) = (BitMap *)NewPtrSysClear(AppleBitMapSize);
 if (!p) return(1);
 p->baseAddr = (Ptr)p + sizeof(BitMap);
 p->rowBytes = AppleRowBytes;
 SetRect(&p->bounds, AppleLeft, BgTop, BgRight, BgBottom);
 bitsPtr16 = (int *)p->baseAddr;
 bitsPtr16[ 5] = 0x18C0;
 bitsPtr16[ 6] = 0x32E0;
 bitsPtr16[ 7] = 0x2670;
 bitsPtr16[ 8] = 0x2310;
 bitsPtr16[ 9] = 0x3760;
 bitsPtr16[10] = 0x07E0;
 bitsPtr16[11] = 0x70C0;
 bitsPtr16[12] = 0x7530;
 bitsPtr16[13] = 0x3DE0;
 bitsPtr16[14] = 0x01C0;

 p = (*theExp2) = (BitMap *)NewPtrSysClear(AppleBitMapSize);
 if (!p) return(1);
 p->baseAddr = (Ptr)p + sizeof(BitMap);
 p->rowBytes = AppleRowBytes;
 SetRect(&p->bounds, AppleLeft, BgTop, BgRight, BgBottom);
 bitsPtr16 = (int *)p->baseAddr;
 bitsPtr16[ 4] = 0x00C0;
 bitsPtr16[ 5] = 0x1D20;
 bitsPtr16[ 6] = 0x2220;
 bitsPtr16[ 7] = 0x2590;
 bitsPtr16[ 8] = 0x4448;
 bitsPtr16[ 9] = 0x5650;
 bitsPtr16[10] = 0x2890;
 bitsPtr16[11] = 0x4428;
 bitsPtr16[12] = 0x4148;
 bitsPtr16[13] = 0x2610;
 bitsPtr16[14] = 0x19E0;

 p = (*theExp3) = (BitMap *)NewPtrSysClear(AppleBitMapSize);
 if (!p) return(1);
 p->baseAddr = (Ptr)p + sizeof(BitMap);
 p->rowBytes = AppleRowBytes;
 SetRect(&p->bounds, AppleLeft, BgTop, BgRight, BgBottom);
 bitsPtr16 = (int *)p->baseAddr;
 bitsPtr16[ 4] = 0x3600;
 bitsPtr16[ 5] = 0x49B0;
 bitsPtr16[ 6] = 0x4448;
 bitsPtr16[ 7] = 0x3288;
 bitsPtr16[ 8] = 0x4448;
 bitsPtr16[ 9] = 0x5250;
 bitsPtr16[10] = 0x2820;
 bitsPtr16[11] = 0x2450;
 bitsPtr16[12] = 0x2390;
 bitsPtr16[13] = 0x1C60;

 p = (*theExp4) = (BitMap *)NewPtrSysClear(AppleBitMapSize);
 if (!p) return(1);
 p->baseAddr = (Ptr)p + sizeof(BitMap);
 p->rowBytes = AppleRowBytes;
 SetRect(&p->bounds, AppleLeft, BgTop, BgRight, BgBottom);
 bitsPtr16 = (int *)p->baseAddr;
 bitsPtr16[ 5] = 0x0660;
 bitsPtr16[ 6] = 0x0990;
 bitsPtr16[ 7] = 0x1450;
 bitsPtr16[ 8] = 0x2320;
 bitsPtr16[ 9] = 0x1450;
 bitsPtr16[10] = 0x1390;
 bitsPtr16[11] = 0x2220;
 bitsPtr16[12] = 0x1990;
 bitsPtr16[13] = 0x0660;

 p = (*theExp5) = (BitMap *)NewPtrSysClear(AppleBitMapSize);
 if (!p) return(1);
 p->baseAddr = (Ptr)p + sizeof(BitMap);
 p->rowBytes = AppleRowBytes;
 SetRect(&p->bounds, AppleLeft, BgTop, BgRight, BgBottom);
 bitsPtr16 = (int *)p->baseAddr;
 bitsPtr16[ 6] = 0x0700;
 bitsPtr16[ 7] = 0x08C0;
 bitsPtr16[ 8] = 0x0920;
 bitsPtr16[ 9] = 0x14C0;
 bitsPtr16[10] = 0x1120;
 bitsPtr16[11] = 0x08A0;
 bitsPtr16[12] = 0x0740;

 p = (*theExp6) = (BitMap *)NewPtrSysClear(AppleBitMapSize);
 if (!p) return(1);
 p->baseAddr = (Ptr)p + sizeof(BitMap);
 p->rowBytes = AppleRowBytes;
 SetRect(&p->bounds, AppleLeft, BgTop, BgRight, BgBottom);
 bitsPtr = p->baseAddr;
 bitsPtr[14] = 0x04;
 bitsPtr[16] = 0x01;
 bitsPtr[18] = 0x10;
 bitsPtr[20] = 0x0A; bitsPtr[21] = 0x40;
 bitsPtr[24] = 0x04;
 
 return(0);
}


/**********************************************
 * DoBombDisposal
 *
 * Replace the apple menu with a bomb, explode
 * the bomb and then bring on a new apple.
 **********************************************/

/* states for BombDisposal sequence */
#define BComeOnScreen0
#define BStartClosing(BComeOnScreen + AppleLeft + 4)
#define BFinishClosing  (BStartClosing + 1)
#define BRemoveApple (BFinishClosing + 1)
#define BBringOnBomb (BRemoveApple + BgRight + 1)
#define BStartOpening(BBringOnBomb + BgRight + 1)
#define BFinishOpening  (BStartOpening + 1)
#define BLeaveScreen (BFinishOpening + 1)
#define BBurn1   (BLeaveScreen + 3)
#define BBurn2   (BBurn1 + 3)
#define BBurn3   (BBurn2 + 3)
#define BBurn4   (BBurn3 + 3)
#define BBurn5   (BBurn4 + 3)
#define BBurn6   (BBurn5 + 3)
#define BBurn7   (BBurn6 + 3)
#define BExp1    (BBurn7 + 3)
#define BExp2    (BExp1 + 3)
#define BExp3    (BExp2 + 3)
#define BExp4    (BExp3 + 3)
#define BExp5    (BExp4 + 3)
#define BExp6    (BExp5 + 3)
#define BExp7    (BExp6 + 3)
#define BExp8    (BExp7 + 3)
#define BBringBackApple (BExp8 + 10)
#define BStartOpening2  (BBringBackApple + BgRight + 1)
#define BFinishOpening2 (BStartOpening2 + 1)
#define BLeaveScreen2(BFinishOpening2 + 1)
#define BAllDone (BLeaveScreen2 + AppleLeft + 5)

int
DoBombDisposal(void) {
 int    frameNo, craneDirection, objectDirection, 
 *bitsPtr16, err;
 long   nextFrame = 0;
 Ptr    bitsPtr;
 GrafPtroldPort, currentPort;
 GDHandle theDevice;
 BitMap *background, *offscreen, oldPortBits,
 *apple, *bomb, *theObject, *theCrane,
 *craneOpen, *craneClosing, *craneClosed, 
 *exp1, *exp2, *exp3, *exp4, *exp5, *exp6;
 
 if (GetToolTrapAddress(GetMainDeviceTrap) != 
   GetToolTrapAddress(UnimplementedTrap)) {
 theDevice = GetMainDevice();
 if (((**(**theDevice).gdPMap).pixelSize) != 1)
 return(1);
 }
 
 oldPort = **(GrafPtr **)CurrentA5;
 currentPort = WMgrPort;
 SetPort(currentPort);
 
 err = MakeCommonBitMaps(&apple, &background,
 &offscreen, &craneOpen, &craneClosing,
 &craneClosed, &oldPortBits, currentPort);
 if (err) return(err);
 err = MakeExplosionBitMaps(&exp1, &exp2, &exp3, 
 &exp4, &exp5, &exp6); 
 if (err) return(err);
 
 craneOpen->bounds.left = -CraneRight;
 craneOpen->bounds.right = 0;
 craneClosed->bounds.left = AppleLeft-CraneRight+6;
 craneClosed->bounds.right = AppleLeft+6;
 
 bomb = (BitMap *)NewPtrSysClear(AppleBitMapSize);
 if (!bomb) return(1);
 bomb->baseAddr = (Ptr)bomb + sizeof(BitMap);
 bomb->rowBytes = AppleRowBytes;
 SetRect(&bomb->bounds, AppleLeft-BgRight, 
 BgTop, 0, BgBottom);
 bitsPtr16 = (int *)bomb->baseAddr;
 bitsPtr16[ 2] = 0x3000;
 bitsPtr16[ 3] = 0x0C00;
 bitsPtr16[ 4] = 0x0200;
 bitsPtr16[ 5] = 0x0200;
 bitsPtr16[ 6] = 0x0F80;
 bitsPtr16[ 7] = 0x1FC0;
 bitsPtr16[ 8] = 0x3E60;
 bitsPtr16[ 9] = 0x3F60;
 bitsPtr16[10] = 0x3FE0;
 bitsPtr16[11] = 0x3FE0;
 bitsPtr16[12] = 0x1FC0;
 bitsPtr16[13] = 0x0F80;

 theCrane = craneOpen;
 craneDirection = 1;
 theObject = apple;
 objectDirection = 0;
 
 for (frameNo=BComeOnScreen; frameNo<BAllDone; frameNo++) {    
 
 CopyBits(background, offscreen, 
 &background->bounds, &background->bounds,
 srcCopy, 0L);

 theObject->bounds.left += objectDirection;
 theObject->bounds.right += objectDirection;
 CopyBits(theObject, offscreen, 
 &theObject->bounds, &theObject->bounds, srcOr, 0L);
 
 theCrane->bounds.left += craneDirection;
 theCrane->bounds.right += craneDirection;
 if (theCrane->bounds.left > 0) {
 SetPortBits(offscreen);
 PenSize(2,2);
 MoveTo(0, CraneArmVLoc);
 LineTo(theCrane->bounds.left, CraneArmVLoc);
 PenSize(1,1);
 SetPortBits(&oldPortBits);
 }
 CopyBits(theCrane, offscreen, 
 &theCrane->bounds, &theCrane->bounds, srcOr, 0L);

 while (TickCount() < nextFrame) ;
 nextFrame = TickCount() + TicksBetweenFrames;
 CopyBits(offscreen, &currentPort->portBits,
 &offscreen->bounds, &offscreen->bounds, srcCopy, 0L);
 
 switch (frameNo) {
 case BStartClosing:
 /* stop the crane from moving and
  * start it closing on the apple */
 craneDirection = 0;
 theCrane = craneClosing;
 break;
 case BFinishClosing:
 /* close it on the apple */
 theCrane = craneClosed;
 break;
 case BRemoveApple:
 /* start the apple and the crane 
  * moving backwards */
 craneDirection = -1;
 objectDirection = -1;
 break;
 case BBringOnBomb:
 /* start the crane moving forward */
 craneDirection = 1;
 /* change the object to the bomb and
  * start it moving forward */
 theObject = bomb;
 objectDirection = 1;
 break;
 case BStartOpening:
 case BStartOpening2:
 /* stop the crane from moving */
 craneDirection = 0;
 /* start to open the crane */
 theCrane = craneClosing;
 /* stop the object from moving */
 objectDirection = 0;
 break;
 case BFinishOpening:
 case BFinishOpening2:
 /* open the crane */
 theCrane = craneOpen;
 theCrane->bounds = craneClosing->bounds;
 break;
 case BLeaveScreen:
 case BLeaveScreen2:
 /* start the crane moving backwards */
 craneDirection = -1;
 break;
 case BBurn1:
 /* change the look of the fuse */
 bitsPtr = bomb->baseAddr;
 bitsPtr[ 0] = 0x40;
 bitsPtr[ 4] = 0x90;
 break;
 case BBurn2:
 /* change the look of the fuse */
 bitsPtr = bomb->baseAddr;
 bitsPtr[ 0] = 0x00;
 bitsPtr[ 2] = 0x14;
 bitsPtr[ 4] = 0x00;
 bitsPtr[ 6] = 0x2C;
 break;
 case BBurn3:
 /* change the look of the fuse */
 bitsPtr = bomb->baseAddr;
 bitsPtr[ 2] = 0x00;
 bitsPtr[ 4] = 0x11;
 bitsPtr[ 6] = 0x04;
 bitsPtr[ 8] = 0x12;
 break;
 case BBurn4:
 /* change the look of the fuse */
 bitsPtr = bomb->baseAddr;
 bitsPtr[ 4] = 0x02;
 bitsPtr[ 6] = 0x08; bitsPtr[ 7] = 0x80;
 bitsPtr[ 8] = 0x02;
 break;
 case BBurn5:
 /* change the look of the fuse */
 bitsPtr = bomb->baseAddr;
 bitsPtr[ 4] = 0x00;
 bitsPtr[ 6] = 0x04; bitsPtr[ 7] = 0x00;
 bitsPtr[ 8] = 0x01;
 break;
 case BBurn6:
 /* change the look of the fuse */
 bitsPtr = bomb->baseAddr;
 bitsPtr[ 6] = 0x00;
 bitsPtr[ 8] = 0x02;
 bitsPtr[10] = 0x00;
 break;
 case BBurn7:
 /* change the look of the fuse */
 bomb->baseAddr[ 8] = 0x00;
 break;
 case BExp1:
 /* start the explosion sequence */
 theObject = exp1;
 break;
 case BExp2:
 theObject = exp2;
 break;
 case BExp3:
 theObject = exp3;
 /* now that the crane is off the
  * screen, stop it from moving */
 craneDirection = 0;
 /* change it to the closed crane in
  * preparation of brining an apple on */
 theCrane = craneClosed;
 theCrane->bounds.left = craneOpen->bounds.left-2;
 theCrane->bounds.right = craneOpen->bounds.right-2;
 break;
 case BExp4:
 theObject = exp2;
 break;
 case BExp5:
 theObject = exp4;
 break;
 case BExp6:
 theObject = exp5;
 break;
 case BExp7:
 theObject = exp6;
 break;
 case BExp8:
 /* change the last explosion to all white space */
 bitsPtr = exp6->baseAddr;
 bitsPtr[14] = 0x00;
 bitsPtr[16] = 0x00;
 bitsPtr[18] = 0x00;
 bitsPtr[20] = 0x00; bitsPtr[21] = 0x00;
 bitsPtr[24] = 0x00;
 break;
 case BBringBackApple:
 /* start the crane and apple moving forward */
 theObject = apple;
 objectDirection = 1;
 craneDirection = 1;
 default:
 break;
 }
 }

 SetPort(oldPort);
 
 DisposePtr(background);
 DisposePtr(offscreen);
 DisposePtr(apple);
 DisposePtr(bomb);
 DisposePtr(craneOpen);
 DisposePtr(craneClosing);
 DisposePtr(craneClosed);
 DisposePtr(exp1);
 DisposePtr(exp2);
 DisposePtr(exp3);
 DisposePtr(exp4);
 DisposePtr(exp5);
 DisposePtr(exp6);
 
 return(0);
}


/**********************************************
 * DoPacMan
 *
 * A PacMan-like thing eats the apple and
 * then a new apple is brought out.
 **********************************************/

#define PacManLeft 0
#define PacManTop1
#define PacManRight17
#define PacManBottom 18
#define PacManRowBytes  (((PacManRight-PacManLeft+16) >> 3) & 0xFFFE)
#define PacManPixelSize (PacManRowBytes * (PacManBottom-PacManTop+1))
#define PacManBitMapSize (sizeof(BitMap) + PacManPixelSize)

/* states for PacMan sequence */
#define PComeOnScreen0
#define PAppleDisappear (PComeOnScreen + AppleLeft + PacManRight - 6)
#define PPMTurnAround(PAppleDisappear + 4)
#define PBringOnApple(PPMTurnAround + AppleLeft + PacManRight)
#define PStartOpening(PBringOnApple + BgRight - 3)
#define PFinishOpening  (PStartOpening + 1)
#define PLeaveScreen (PFinishOpening + 1)
#define PAllDone (PLeaveScreen + AppleLeft + 5)

int
DoPacMan(void) {
 int    i, frameNo, craneDirection, objectDirection,
 *bitsPtr16, pacManDirection, pmIndex, err,
 pmOldIndex, mouthState, pacManGone;
 long   nextFrame = 0;
 Ptr    bitsPtr;
 GrafPtroldPort, currentPort;
 GDHandle theDevice;
 BitMap *background, *offscreen, oldPortBits,
 *apple, *theObject, *theCrane,
 *craneOpen, *craneClosing, *craneClosed,
 *pacMan[8];
 
 if (GetToolTrapAddress(GetMainDeviceTrap) != 
   GetToolTrapAddress(UnimplementedTrap)) {
 theDevice = GetMainDevice();
 if (((**(**theDevice).gdPMap).pixelSize) != 1)
 return(1);
 }
 
 oldPort = **(GrafPtr **)CurrentA5;
 currentPort = WMgrPort;
 SetPort(currentPort);
 
 err = MakeCommonBitMaps(&apple, &background,
 &offscreen, &craneOpen, &craneClosing, 
 &craneClosed, &oldPortBits, currentPort);
 if (err) return(err);
 
 pacMan[0] = (BitMap *)NewPtrSysClear(PacManBitMapSize);
 if (!pacMan[0]) return(1);
 pacMan[0]->baseAddr = (Ptr)pacMan[0] + sizeof(BitMap);
 pacMan[0]->rowBytes = PacManRowBytes;
 SetRect(&pacMan[0]->bounds, -PacManRight,
 PacManTop, 0, PacManBottom);
 bitsPtr16 = (int *)pacMan[0]->baseAddr;
 bitsPtr16[ 0] = 0x03E0;
 bitsPtr16[ 2] = 0x0FF8;
 bitsPtr16[ 4] = 0x3FFE;
 bitsPtr16[ 6] = 0x3FBE;
 bitsPtr16[ 8] = 0x7FFF;
 bitsPtr16[10] = 0x7FFF;
 bitsPtr16[12] = 0xFFFF;  bitsPtr16[13] = 0x8000;
 bitsPtr16[14] = 0xFFFF;  bitsPtr16[15] = 0x8000;
 bitsPtr16[16] = 0xFFFF;  bitsPtr16[17] = 0x8000;
 bitsPtr16[18] = 0xFFFF;  bitsPtr16[19] = 0x8000;
 bitsPtr16[20] = 0xFFFF;  bitsPtr16[21] = 0x8000;
 bitsPtr16[22] = 0x7FFF;
 bitsPtr16[24] = 0x7FFF;
 bitsPtr16[26] = 0x3FFE;
 bitsPtr16[28] = 0x3FFE;
 bitsPtr16[30] = 0x0FF8;
 bitsPtr16[32] = 0x03E0;

 pacMan[1] = (BitMap *)NewPtrSys(PacManBitMapSize);
 if (!pacMan[1]) return(1);
 BlockMove(pacMan[0], pacMan[1], PacManBitMapSize);
 pacMan[1]->baseAddr = (Ptr)pacMan[1] + sizeof(BitMap);
 bitsPtr = pacMan[1]->baseAddr;
 bitsPtr[21] = 0xFE;
 bitsPtr[25] = 0xF8; bitsPtr[26] = 0x00;
 bitsPtr[29] = 0xE0; bitsPtr[30] = 0x00;
 bitsPtr[33] = 0x80; bitsPtr[34] = 0x00;
 bitsPtr[37] = 0xE0; bitsPtr[38] = 0x00;
 bitsPtr[41] = 0xF8; bitsPtr[42] = 0x00;
 bitsPtr[45] = 0xFE;

 /* since PacMans 2 and 3 are similar to 1, we
  * calculate them as differences from 1 (saves code) */
 for (i = 2; i < 4; i++) {
 pacMan[i] = (BitMap *)NewPtrSys(PacManBitMapSize);
 if (!pacMan[i]) return(1);
 BlockMove(pacMan[1], pacMan[i], PacManBitMapSize);
 pacMan[i]->baseAddr = (Ptr)pacMan[i] + sizeof(BitMap);
 }

 bitsPtr = pacMan[2]->baseAddr;
 bitsPtr[ 9] = 0xFC;
 bitsPtr[13] = 0xBC;
 bitsPtr[17] = 0xF8;
 bitsPtr[21] = 0xF0;
 bitsPtr[25] = 0xE0;
 bitsPtr[29] = 0xC0;
 bitsPtr[37] = 0xC0;
 bitsPtr[41] = 0xE0;
 bitsPtr[45] = 0xF0;
 bitsPtr[49] = 0xF8;
 bitsPtr[53] = 0xFC;
 bitsPtr[57] = 0xFC;

 bitsPtr = pacMan[3]->baseAddr;
 bitsPtr[ 9] = 0xF8;
 bitsPtr[13] = 0xB0;
 bitsPtr[17] = 0xE0;
 bitsPtr[21] = 0xE0;
 bitsPtr[25] = 0xC0;
 bitsPtr[29] = 0xC0;
 bitsPtr[37] = 0xC0;
 bitsPtr[41] = 0xC0;
 bitsPtr[45] = 0xE0;
 bitsPtr[49] = 0xE0;
 bitsPtr[53] = 0xF0;
 bitsPtr[57] = 0xF8;

 pacMan[4] = (BitMap *)NewPtrSys(PacManBitMapSize);
 if (!pacMan[4]) return(1);
 BlockMove(pacMan[0], pacMan[4], PacManBitMapSize);
 pacMan[4]->baseAddr = (Ptr)pacMan[4] + sizeof(BitMap);
 bitsPtr16 = (int *)pacMan[4]->baseAddr;
 bitsPtr16[ 6] = 0x3EFE;

 /* since PacMans 5, 6 and 7 are similar to 4, we
  * calculate them as differences from 4 (saves code) */
 for (i = 5; i < 8; i++) {
 pacMan[i] = (BitMap *)NewPtrSys(PacManBitMapSize);
 if (!pacMan[i]) return(1);
 BlockMove(pacMan[4], pacMan[i], PacManBitMapSize);
 pacMan[i]->baseAddr = (Ptr)pacMan[i] + sizeof(BitMap);
 }

 bitsPtr = pacMan[5]->baseAddr;
 bitsPtr[20] = 0x3F;
 bitsPtr[24] = 0x0F;
 bitsPtr[28] = 0x03;
 bitsPtr[32] = 0x00;
 bitsPtr[36] = 0x03;
 bitsPtr[40] = 0x0F;
 bitsPtr[44] = 0x3F;

 bitsPtr = pacMan[6]->baseAddr;
 bitsPtr[ 8] = 0x1F;
 bitsPtr[12] = 0x1E;
 bitsPtr[16] = 0x0F;
 bitsPtr[20] = 0x07;
 bitsPtr[24] = 0x03;
 bitsPtr[28] = 0x01;
 bitsPtr[32] = 0x00;
 bitsPtr[36] = 0x01;
 bitsPtr[40] = 0x03;
 bitsPtr[44] = 0x07;
 bitsPtr[48] = 0x0F;
 bitsPtr[52] = 0x1F;
 bitsPtr[56] = 0x1F;

 bitsPtr = pacMan[7]->baseAddr;
 bitsPtr[ 8] = 0x0F;
 bitsPtr[12] = 0x06;
 bitsPtr[16] = 0x03;
 bitsPtr[20] = 0x03;
 bitsPtr[24] = 0x01;
 bitsPtr[28] = 0x01;
 bitsPtr[32] = 0x00;
 bitsPtr[36] = 0x01;
 bitsPtr[40] = 0x01;
 bitsPtr[44] = 0x03;
 bitsPtr[48] = 0x03;
 bitsPtr[52] = 0x07;
 bitsPtr[56] = 0x0F;

 /* initially, there is no crane */
 theCrane = 0;
 /* the object is the apple and it’s not moving */
 theObject = apple;
 objectDirection = 0;
 /* PacMan starting state so that when he gets
  * to the apple his mouth is just beginning to close */
 pmIndex = 2;
 mouthState = 1;
 pacManDirection = 1;
 pacManGone = 0;
 
 for (frameNo=PComeOnScreen; frameNo<PAllDone; frameNo++) {    
 
 CopyBits(background, offscreen, 
 &background->bounds, &background->bounds,
 srcCopy, 0L);

 theObject->bounds.left += objectDirection;
 theObject->bounds.right += objectDirection;
 CopyBits(theObject, offscreen, 
 &theObject->bounds, &theObject->bounds, srcOr, 0L);
 
 if (theCrane) {
 theCrane->bounds.left += craneDirection;
 theCrane->bounds.right += craneDirection;
 if (theCrane->bounds.left > 0) {
 SetPortBits(offscreen);
 PenSize(2,2);
 MoveTo(0, CraneArmVLoc);
 LineTo(theCrane->bounds.left, CraneArmVLoc);
 PenSize(1,1);
 SetPortBits(&oldPortBits);
 }
 CopyBits(theCrane, offscreen, 
 &theCrane->bounds, &theCrane->bounds, srcOr, 0L);
 }

 if (!pacManGone) {
 pacMan[pmIndex]->bounds.left += pacManDirection;
 pacMan[pmIndex]->bounds.right += pacManDirection;
 CopyBits(pacMan[pmIndex], offscreen, 
 &pacMan[pmIndex]->bounds,
 &pacMan[pmIndex]->bounds, srcOr, 0L);
 /* The indexes of the mouth follow this
  * pattern: 0,1,2,3,2,1,0,1,2,... when
  * moving to the right and this pattern:
  * 4,5,6,7,6,5,4,5,6... when moving to
  * the right. The new few lines deal with
  * this. */
 pmOldIndex = pmIndex;
 if (pacManDirection < 0)
 pmIndex -= 4;
 pmIndex += mouthState;
 if (pmIndex > 3) {
 pmIndex = 2;
 mouthState = -1;
 }
 else if (pmIndex < 0) {
 pmIndex = 1;
 mouthState = 1;
 }
 if (pacManDirection < 0)
 pmIndex += 4;
 pacMan[pmIndex]->bounds =
 pacMan[pmOldIndex]->bounds;
 }

 while (TickCount() < nextFrame) ;
 nextFrame = TickCount() + TicksBetweenFrames;
 CopyBits(offscreen, &currentPort->portBits,
 &offscreen->bounds, &offscreen->bounds, srcCopy, 0L);

 switch (frameNo) {
 case PAppleDisappear:
 /* when the PacMan gets on top of the apple
  * reposition it to be offscreen (where the
  * crane will need it to bring it back on) */
 theObject->bounds.left -= (BgRight - 3);
 theObject->bounds.right -= (BgRight - 3);
 break;
 case PPMTurnAround:
 /* make PacMan move to the left */
 pacManDirection = -1;
 /* we’re dealing with the second set
  * of four PacMan BitMaps now */
 pmIndex += 4;
 pacMan[pmIndex]->bounds =
 pacMan[pmIndex-4]->bounds;
 break;
 case PBringOnApple:
 /* now that PacMan is gone, we’re finished
  * with him */
 pacManGone = 1;
 /* start the closed crane moving to the
  * right */
 theCrane = craneClosed;
 craneDirection = 1;
 /* start the apple moving to the right */
 objectDirection = 1;
 break;
 case PStartOpening:
 /* stop the crane and start it opening */
 craneDirection = 0;
 theCrane = craneClosing;
 /* stop the apple */
 objectDirection = 0;
 break;
 case PFinishOpening:
 /* open the crane */
 theCrane = craneOpen;
 break;
 case PLeaveScreen:
 /* start the crane moving to the left */
 craneDirection = -1;
 break;
 default:
 break;
 }
 }

 SetPort(oldPort);
 
 DisposePtr(background);
 DisposePtr(offscreen);
 DisposePtr(apple);
 DisposePtr(craneOpen);
 DisposePtr(craneClosing);
 DisposePtr(craneClosed);
 for (i = 0; i < 8; i++)
 DisposePtr(pacMan[i]);
 
 return(0);
}


/**********************************************
 * DoTank
 *
 * A little tank comes out and blows up the
 * apple. The tank goes away and a new apple
 * is brought out.
 **********************************************/

#define TankLeft 0
#define TankTop  10
#define TankRight11
#define TankBottom 18
#define TankRowBytes (((TankRight-TankLeft+16) >> 3) & 0xFFFE)
#define TankPixelSize(TankRowBytes * (TankBottom-TankTop+1))
#define TankBitMapSize  (sizeof(BitMap) + TankPixelSize)

/* states for Tank sequence */
#define TComeOnScreen0
#define TTankStop(TComeOnScreen + AppleLeft)
#define TRaiseTurret (TTankStop + 10)
#define TAim(TRaiseTurret + 10)
#define TFire    (TAim + 3)
#define TRecoil  (TFire + 1)
#define TExp2    (TRecoil + 2)
#define TExp3    (TExp2 + 3)
#define TExp4    (TExp3 + 3)
#define TExp5    (TExp4 + 3)
#define TExp6    (TExp5 + 3)
#define TExp7    (TExp6 + 3)
#define TExp8    (TExp7 + 3)
#define TLowerTurret (TExp8 + 10)
#define TTankLeave (TLowerTurret + 10)
#define TBringOnApple(TTankLeave + AppleLeft + 3)
#define TStartOpening(TBringOnApple + BgRight - 3)
#define TFinishOpening  (TStartOpening + 1)
#define TLeaveScreen (TFinishOpening + 1)
#define TAllDone (TLeaveScreen + AppleLeft + 5)

int
DoTank(void) {
 int    i, frameNo, *bitsPtr16, evenTread, tankDone, err,
 craneDirection, objectDirection, tankDirection;
 long   nextFrame = 0;
 Ptr    bitsPtr;
 GrafPtroldPort, currentPort;
 GDHandle theDevice;
 BitMap *background, *offscreen, oldPortBits,
 *apple, *theObject, *tank, *theCrane,
 *craneOpen, *craneClosing, *craneClosed,
 *exp1, *exp2, *exp3, *exp4, *exp5, *exp6;
 
 if (GetToolTrapAddress(GetMainDeviceTrap) != 
   GetToolTrapAddress(UnimplementedTrap)) {
 theDevice = GetMainDevice();
 if (((**(**theDevice).gdPMap).pixelSize) != 1)
 return(1);
 }
 
 oldPort = **(GrafPtr **)CurrentA5;
 currentPort = WMgrPort;
 SetPort(currentPort);
 
 err = MakeCommonBitMaps(&apple, &background, 
 &offscreen, &craneOpen, &craneClosing, 
 &craneClosed, &oldPortBits, currentPort);
 if (err) return(err);
 err = MakeExplosionBitMaps(&exp1, &exp2, &exp3, 
 &exp4, &exp5, &exp6); 
 if (err) return(err);

 tank = (BitMap *)NewPtrSysClear(TankBitMapSize);
 if (!tank) return(1);
 tank->baseAddr = (Ptr)tank + sizeof(BitMap);
 tank->rowBytes = TankRowBytes;
 SetRect(&tank->bounds, -TankRight,
 TankTop, 0, TankBottom);
 bitsPtr16 = (int *)tank->baseAddr;
 bitsPtr16[ 0] = 0x1C00;
 bitsPtr16[ 1] = 0x37E0;
 bitsPtr16[ 2] = 0x2200;
 bitsPtr16[ 3] = 0x7F80;
 bitsPtr16[ 4] = 0xD540;
 bitsPtr16[ 5] = 0x80C0;
 bitsPtr16[ 6] = 0xD540;
 bitsPtr16[ 7] = 0x7F80;

 /* initially, there is no crane, the apple
  * is stationary and the tank is moving
  * forward */
 theCrane = 0;
 theObject = apple;
 objectDirection = 0;
 tankDirection = 1;
 evenTread = 0;
 tankDone = 0;
 
 for (frameNo=TComeOnScreen; frameNo<TAllDone; frameNo++) {    
 
 CopyBits(background, offscreen, 
 &background->bounds, &background->bounds,
 srcCopy, 0L);

 theObject->bounds.left += objectDirection;
 theObject->bounds.right += objectDirection;
 CopyBits(theObject, offscreen, 
 &theObject->bounds, &theObject->bounds, srcOr, 0L);
 
 if (!tankDone) {
 tank->bounds.left += tankDirection;
 tank->bounds.right += tankDirection;
 if (tankDirection) {
 /* since the tank is moving, change
  * its treads’ appearance */
 bitsPtr16 = (int *)tank->baseAddr;
 if (evenTread) {
 bitsPtr16[ 4] = 0xD540;
 bitsPtr16[ 5] = 0x80C0;
 bitsPtr16[ 6] = 0xD540;
 }
 else {
 bitsPtr16[ 4] = 0xAAC0;
 bitsPtr16[ 5] = 0xC040;
 bitsPtr16[ 6] = 0xAAC0;
 }
 evenTread = ~evenTread;
 }
 CopyBits(tank, offscreen, 
 &tank->bounds, &tank->bounds, srcOr, 0L);
 }

 if (theCrane) {
 theCrane->bounds.left += craneDirection;
 theCrane->bounds.right += craneDirection;
 if (theCrane->bounds.left > 0) {
 SetPortBits(offscreen);
 PenSize(2,2);
 MoveTo(0, CraneArmVLoc);
 LineTo(theCrane->bounds.left, CraneArmVLoc);
 PenSize(1,1);
 SetPortBits(&oldPortBits);
 }
 CopyBits(theCrane, offscreen, 
 &theCrane->bounds, &theCrane->bounds, srcOr, 0L);
 }

 while (TickCount() < nextFrame) ;
 nextFrame = TickCount() + TicksBetweenFrames;
 CopyBits(offscreen, &currentPort->portBits,
 &offscreen->bounds, &offscreen->bounds,
 srcCopy, 0L);

 switch (frameNo) {
 case TTankStop:
 /* stop the tank from moving forward */
 tankDirection = 0;
 break;
 case TRaiseTurret:
 /* change the BitMap to a raised turret */
 bitsPtr16 = (int *)tank->baseAddr;
 bitsPtr16[ 0] = 0x1C60;
 bitsPtr16[ 1] = 0x3780;
 break;
 case TFire:
 /* move the tank left 1 pixel for recoil */
 tank->bounds.left-;
 tank->bounds.right-;
 /* change the object from the apple to the
  * first frame of the explosion */
 theObject = exp1;
 break;
 case TRecoil:
 /* move the tank back after the recoil */
 tank->bounds.left++;
 tank->bounds.right++;
 break;
 case TExp2:
 theObject = exp2;
 break;
 case TExp3:
 theObject = exp3;
 break;
 case TExp4:
 theObject = exp2;
 break;
 case TExp5:
 theObject = exp4;
 break;
 case TExp6:
 theObject = exp5;
 break;
 case TExp7:
 theObject = exp6;
 break;
 case TExp8:
 /* change the last explosion to all white space */
 bitsPtr = exp6->baseAddr;
 bitsPtr[14] = 0x00;
 bitsPtr[16] = 0x00;
 bitsPtr[18] = 0x00;
 bitsPtr[20] = 0x00; bitsPtr[21] = 0x00;
 bitsPtr[24] = 0x00;
 break;
 case TLowerTurret:
 /* change the BitMap to a lowered turret */
 bitsPtr16 = (int *)tank->baseAddr;
 bitsPtr16[ 0] = 0x1C00;
 bitsPtr16[ 1] = 0x37E0;
 break;
 case TTankLeave:
 /* start the tank moving backwards */
 tankDirection = -1;
 break;
 case TBringOnApple:
 /* tank is off the screen now */
 tankDone = 1;
 /* start the closed crane moving foward */
 theCrane = craneClosed;
 craneDirection = 1;
 /* position the apple to be in the crane */
 theObject = apple;
 theObject->bounds.left -= (BgRight - 3);
 theObject->bounds.right -= (BgRight - 3);
 objectDirection = 1;
 break;
 case TStartOpening:
 /* stop the crane from moving */
 craneDirection = 0;
 /* let go of the apple */
 theCrane = craneClosing;
 /* stop the apple from moving */
 objectDirection = 0;
 break;
 case TFinishOpening:
 /* open the crane some more */
 theCrane = craneOpen;
 break;
 case TLeaveScreen:
 /* start the crane moving backwards */
 craneDirection = -1;
 break;
 default:
 break;
 }
 }
 
 SetPort(oldPort);
 
 DisposePtr(background);
 DisposePtr(offscreen);
 DisposePtr(apple);
 DisposePtr(craneOpen);
 DisposePtr(craneClosing);
 DisposePtr(craneClosed);
 DisposePtr(exp1);
 DisposePtr(exp2);
 DisposePtr(exp3);
 DisposePtr(exp4);
 DisposePtr(exp5);
 DisposePtr(exp6);
 DisposePtr(tank);
 
 return(0);
}

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

Go from lowly lizard to wicked Wyvern in...
Do you like questing, and do you like dragons? If not then boy is this not the announcement for you, as Loongcheer Game has unveiled Quest Dragon: Idle Mobile Game. Yes, it is amazing Square Enix hasn’t sued them for copyright infringement, but... | Read more »
Aether Gazer unveils Chapter 16 of its m...
After a bit of maintenance, Aether Gazer has released Chapter 16 of its main storyline, titled Night Parade of the Beasts. This big update brings a new character, a special outfit, some special limited-time events, and, of course, an engaging... | Read more »
Challenge those pesky wyverns to a dance...
After recently having you do battle against your foes by wildly flailing Hello Kitty and friends at them, GungHo Online has whipped out another surprising collaboration for Puzzle & Dragons. It is now time to beat your opponents by cha-cha... | Read more »
Pack a magnifying glass and practice you...
Somehow it has already been a year since Torchlight: Infinite launched, and XD Games is celebrating by blending in what sounds like a truly fantastic new update. Fans of Cthulhu rejoice, as Whispering Mist brings some horror elements, and tests... | Read more »
Summon your guild and prepare for war in...
Netmarble is making some pretty big moves with their latest update for Seven Knights Idle Adventure, with a bunch of interesting additions. Two new heroes enter the battle, there are events and bosses abound, and perhaps most interesting, a huge... | Read more »
Make the passage of time your plaything...
While some of us are still waiting for a chance to get our hands on Ash Prime - yes, don’t remind me I could currently buy him this month I’m barely hanging on - Digital Extremes has announced its next anticipated Prime Form for Warframe. Starting... | Read more »
If you can find it and fit through the d...
The holy trinity of amazing company names have come together, to release their equally amazing and adorable mobile game, Hamster Inn. Published by HyperBeard Games, and co-developed by Mum Not Proud and Little Sasquatch Studios, it's time to... | Read more »
Amikin Survival opens for pre-orders on...
Join me on the wonderful trip down the inspiration rabbit hole; much as Palworld seemingly “borrowed” many aspects from the hit Pokemon franchise, it is time for the heavily armed animal survival to also spawn some illegitimate children as Helio... | Read more »
PUBG Mobile teams up with global phenome...
Since launching in 2019, SpyxFamily has exploded to damn near catastrophic popularity, so it was only a matter of time before a mobile game snapped up a collaboration. Enter PUBG Mobile. Until May 12th, players will be able to collect a host of... | Read more »
Embark into the frozen tundra of certain...
Chucklefish, developers of hit action-adventure sandbox game Starbound and owner of one of the cutest logos in gaming, has released their roguelike deck-builder Wildfrost. Created alongside developers Gaziter and Deadpan Games, Wildfrost will... | Read more »

Price Scanner via MacPrices.net

Limited-time sale: 13-inch M3 MacBook Airs fo...
Amazon has the base 13″ M3 MacBook Air (8GB/256GB) in stock and on sale for a limited time for $989 shipped. That’s $110 off MSRP, and it’s the lowest price we’ve seen so far for an M3-powered... Read more
13-inch M2 MacBook Airs in stock today at App...
Apple has 13″ M2 MacBook Airs available for only $849 today in their Certified Refurbished store. These are the cheapest M2-powered MacBooks for sale at Apple. Apple’s one-year warranty is included,... Read more
New today at Apple: Series 9 Watches availabl...
Apple is now offering Certified Refurbished Apple Watch Series 9 models on their online store for up to $80 off MSRP, starting at $339. Each Watch includes Apple’s standard one-year warranty, a new... Read more
The latest Apple iPhone deals from wireless c...
We’ve updated our iPhone Price Tracker with the latest carrier deals on Apple’s iPhone 15 family of smartphones as well as previous models including the iPhone 14, 13, 12, 11, and SE. Use our price... Read more
Boost Mobile will sell you an iPhone 11 for $...
Boost Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering an iPhone 11 for $149.99 when purchased with their $40 Unlimited service plan (12GB of premium data). No trade-in is required... Read more
Free iPhone 15 plus Unlimited service for $60...
Boost Infinite, part of MVNO Boost Mobile using AT&T and T-Mobile’s networks, is offering a free 128GB iPhone 15 for $60 per month including their Unlimited service plan (30GB of premium data).... Read more
$300 off any new iPhone with service at Red P...
Red Pocket Mobile has new Apple iPhones on sale for $300 off MSRP when you switch and open up a new line of service. Red Pocket Mobile is a nationwide MVNO using all the major wireless carrier... Read more
Clearance 13-inch M1 MacBook Airs available a...
Apple has clearance 13″ M1 MacBook Airs, Certified Refurbished, available for $759 for 8-Core CPU/7-Core GPU/256GB models and $929 for 8-Core CPU/8-Core GPU/512GB models. Apple’s one-year warranty is... Read more
Updated Apple MacBook Price Trackers
Our Apple award-winning MacBook Price Trackers are continually updated with the latest information on prices, bundles, and availability for 16″ and 14″ MacBook Pros along with 13″ and 15″ MacBook... Read more
Every model of Apple’s 13-inch M3 MacBook Air...
Best Buy has Apple 13″ MacBook Airs with M3 CPUs in stock and on sale today for $100 off MSRP. Prices start at $999. Their prices are the lowest currently available for new 13″ M3 MacBook Airs among... Read more

Jobs Board

Solutions Engineer - *Apple* - SHI (United...
**Job Summary** An Apple Solution Engineer's primary role is tosupport SHI customers in their efforts to select, deploy, and manage Apple operating systems and Read more
DMR Technician - *Apple* /iOS Systems - Haml...
…relevant point-of-need technology self-help aids are available as appropriate. ** Apple Systems Administration** **:** Develops solutions for supporting, deploying, Read more
Omnichannel Associate - *Apple* Blossom Mal...
Omnichannel Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Operations Associate - *Apple* Blossom Mall...
Operations Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Cashier - *Apple* Blossom Mall - JCPenney (...
Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Mall Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.