home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C++ / Frameworks / GameShell / Sourcery / Compat.c < prev    next >
Encoding:
Text File  |  1994-07-06  |  2.3 KB  |  99 lines  |  [TEXT/CWIE]

  1. // Compat.c++
  2.  
  3. #include <Traps.h>
  4. #include <OSUtils.h>
  5.  
  6.  
  7. #include "Compat.h"
  8.  
  9. MacEnviron gEnviron;
  10.  
  11.  
  12. #define TrapMask 0x0800
  13.  
  14.  
  15. short NumToolboxTraps();
  16. TrapType GetTrapType(short theTrap);
  17. Boolean TrapAvailable(short theTrap);
  18.  
  19.  
  20. short NumToolboxTraps() {
  21.     if (NGetTrapAddress(_InitGraf, ToolTrap) ==
  22.             NGetTrapAddress(0xAA6E, ToolTrap))
  23.         return(0x0200);
  24.     else
  25.         return(0x0400);
  26. } // END NumToolboxTraps
  27.  
  28. TrapType GetTrapType(short theTrap) {
  29.     if ((theTrap & TrapMask) > 0)
  30.         return(ToolTrap);
  31.     else
  32.         return(OSTrap);
  33.  
  34. } // END GetTrapType
  35.  
  36. Boolean TrapAvailable(short theTrap) {
  37.     TrapType    tType;
  38.  
  39.     tType = GetTrapType(theTrap);
  40.     if (tType == ToolTrap)
  41.     theTrap = theTrap & 0x07FF;
  42.     if (theTrap >= NumToolboxTraps())
  43.         theTrap = _Unimplemented;
  44.  
  45.     return (NGetTrapAddress(theTrap, tType) !=
  46.             NGetTrapAddress(_Unimplemented, ToolTrap));
  47. } // END TrapAvailable
  48.  
  49. // ***************************************************************************
  50.  
  51. void CheckEnviron() {
  52.     long gestaltInfo;
  53.     SysEnvRec myEnv;
  54.     
  55.     // Get GESTALT availability
  56.     gEnviron.gestaltAvail = TrapAvailable(_Gestalt);
  57.     // Get WAITNEXTEVENT availability
  58.     gEnviron.WNEAvail     = TrapAvailable(_WaitNextEvent);
  59.     
  60.     if (gEnviron.gestaltAvail) {
  61.         // Get PROCESSOR type
  62.         Gestalt(gestaltProcessorType, &gestaltInfo);
  63.         gEnviron.cpu = gestaltInfo;
  64.         
  65.         // Get FPU availability
  66.         Gestalt(gestaltFPUType, &gestaltInfo);
  67.         gEnviron.fpu = gestaltInfo;
  68.         
  69.         // Get SYSTEM VERSION
  70.         Gestalt(gestaltSystemVersion, &gestaltInfo);
  71.         gEnviron.sysVersion = gestaltInfo;
  72.         
  73.         // Get whether COLOR QUICKDRAW is present or not
  74.         SysEnvirons(curSysEnvVers, &myEnv);
  75.         gEnviron.hasColor = gEnviron.hasCQD = myEnv.hasColorQD;
  76.         if (gEnviron.hasColor)
  77.             gEnviron.pixDepth = (**((**GetMainDevice()).gdPMap)).pixelSize;
  78.             // Equivalent to GetMainDevice^^.gdPMap^^.pixelSize in Pascal!!
  79.         else
  80.             gEnviron.pixDepth = 1;
  81.             
  82.         if (gEnviron.pixDepth < 2)
  83.             gEnviron.hasColor = FALSE;
  84.  
  85.         // Determine if we have TEMPORARY MEMORY support
  86.         Gestalt(gestaltOSAttr, &gestaltInfo);
  87.         if (BitTst(&gestaltInfo, 31-gestaltTempMemSupport))
  88.             gEnviron.hasTempMem = TRUE;
  89.         else
  90.             gEnviron.hasTempMem = FALSE;
  91.             
  92.         // Do we have an APPLE SOUND CHIP installed?
  93.         Gestalt(gestaltHardwareAttr, &gestaltInfo);
  94.         if (BitTst(&gestaltInfo, 31-gestaltHasASC))
  95.             gEnviron.hasSoundChip = TRUE;
  96.         else
  97.             gEnviron.hasSoundChip = FALSE;
  98.     }
  99. } // END CheckEnviron