Wolf3D-Mac/Burger.c

1 line
22 KiB
C
Raw Normal View History

/********************************** Burger library for the Macintosh. Use Think.c or Code Warrior to compile. Use SMART linking to link in just what you need **********************************/ #include "WolfDef.h" /* Get the prototypes */ #include <string.h> #include <sound.h> #include <stdio.h> #include <palettes.h> #include "SoundMusicSystem.h" #include "PickAMonitor.h" /********************************** Variables used by my global library **********************************/ Word DoEvent(EventRecord *event); void DoMacEvents(void); void BlastScreen(void); static Word FreeStage(Word Stage,LongWord Size); extern Boolean MouseHit; /* True if a mouse down event occured */ Word NoSystemMem; unsigned char *VideoPointer; /* Pointer to video memory */ extern Word QuitFlag; /* Did the application quit? */ Word VideoWidth; /* Width to each video scan line */ Word SystemState=3; /* Sound on/off flags */ Word KilledSong; /* Song that's currently playing */ Word KeyModifiers; /* Keyboard modifier flags */ LongWord LastTick; /* Last system tick (60hz) */ Word FontX; /* X Coord of font */ Word FontY; /* Y Coord of font */ unsigned char *FontPtr; /* Pointer to font image data */ unsigned char *FontWidths; /* Pointer to font width table */ Word FontHeight; /* Point size of current font */ Word FontLast; /* Number of font entries */ Word FontFirst; /* ASCII value of first char */ Word FontLoaded; /* Rez number of loaded font (0 if none) */ Word FontInvisible; /* Allow masking? */ unsigned char FontOrMask[16]; /* Colors for font */ LongWord YTable[480]; /* Offsets to the screen */ SndChannelPtr myPaddleSndChan; /* Sound channel */ Word ScanCode; CWindowPtr GameWindow; CGrafPtr GameGWorld; extern GDHandle gMainGDH; extern CTabHandle MainColorHandle; extern Boolean DoQuickDraw; /********************************** Wait a single system tick **********************************/ static Word QuickTicker; void DoMacEvents(void) { EventRecord MyEvent; if (!DoQuickDraw) { if ((ReadTick() - QuickTicker) < 30) { return; } QuickTicker = ReadTick(); } PurgeAllSounds(85000); /* Try to keep some memory free */ if (WaitNextEvent2(updateMask|diskMask|driverMask|networkMask|activMask|app4Mask,&MyEvent,0,0)) { DoEvent(&MyEvent); } } /********************************** Wait a single system tick **********************************/ void WaitTick(void) { do { DoMacEvents(); /* Allow backgrounding */ } while (ReadTick()==LastTick); /* Tick changed? */ LastTick=ReadTick(); /* Save it */ } /********************************** Wait a specific number of system ticks from a time mark before you get control **********************************/ void WaitTicks(Word Count) { LongWord TickMark; /* Temp tick mark */ do { DoMacEvents(); /* Allow other tasks to execute */ TickMark = ReadTick(); /* Get the mark */ } while ((TickMark-LastTick)<=Count); /* Time up? */ LastTick = TickMark; /* Save the new time mark */ } /********************************** Get the current system tick **********************************/ LongWord ReadTick(void) { return(TickCount()); /* Just get it from the Mac OS */ } /********************************** Wait for a mouse/keyboard event **********************************/ Word WaitEvent(void) { Word Temp; do { Temp = WaitTicksEvent(6000); /* Wait 10 minutes */ } while (!Temp); /* No event? */ return Temp; /* Return the event code */ } /********************************** Wait for an event or a timeout **********************************/ Word WaitTicksEvent(Word Time) { LongWord TickMark; LongWord NewMark; Word RetVal; MouseHit = FALSE; TickMark = ReadTick(); /* Get the initial time mark */ for (;;) { DoMacEvents(); /* Allow other tasks a shot! */ NewMark = ReadTick(); /* Get the new time mark */ if (Time) { if ((NewMark-TickMark)>=Time) { /* Time up? */ RetVal = 0; /* Return timeout */ break; } } RetVal = GetAKey(); if (RetVal) { break; } if (MouseHit) { RetVal = 1;