home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Science⁄Math / VideoToolbox / VideoToolboxSources / Identify.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-16  |  6.7 KB  |  211 lines  |  [TEXT/KAHL]

  1. /* Identify.c
  2. Each routine returns an informative C string. Here are samples. (I suggest you
  3. use BreakLines() to printf the longer ones.)
  4.  
  5. IdentifyCompiler:
  6. "THINK C 6 compiled to generate 68020 instructions,
  7. generate 68881 instructions, and use 12-byte universal-format doubles."
  8.  
  9. IdentifyMachine:
  10. "Denis Pelli’s PowerBook 170 with 68030 and 68882 running System 7.10, ROM 1024K
  11. version 124+6*256. Caching data & instructions."
  12.  
  13. IdentifyModel:
  14. "PowerBook 170"
  15.  
  16. IdentifyVideo(device):
  17. "PowerBook 170 “Macintosh D Built-In Video” (.Display_Video_Apple_TIM) in slot 0"
  18.  
  19. The computer model appears only if the slot==0, which indicates built-in video. The
  20. curly quotes embrace the card name, and the parentheses embrace the driver name.
  21. The driver's version number appears only if it's non-zero.
  22.  
  23. HISTORY:
  24. 1/29/92    dgp wrote IdentifyCompiler.
  25. 2/25/92    dgp    wrote IdentifyMachine.
  26. 8/26/92    dgp get owner and model name from the System file
  27. 2/20/93    dgp    added ROM version
  28. 2/27/93    dgp merged IdentifyCompiler.c and IdentifyMachine.c into the new Identify.c,
  29.             and added IdentifyVideo.
  30. 4/25/93    dgp    IdentifyMachine reports 24/32-bit addressing.
  31. 12/14/93 dgp If THINK C compiler version is "5" I report "5 or 6.0" since Symantec
  32.             forgot to increment the version number when they released 6.0. They
  33.             fixed this in version 6.01.
  34. */
  35. #include "VideoToolbox.h"
  36. #include <Traps.h>    // _HWPriv
  37. #include "mc68881.h"
  38.  
  39. /*
  40. This table was complete in summer '92, but does not include the newer models.
  41. However, the table is used only as a backup, when the System lacks a machine name
  42. string, which is a feature of System 7. Since all new machines nominally require
  43. System 7, it is unlikely that it will ever be necessary to look them up in
  44. this table.
  45. */
  46. char machineName[][20]={
  47.     "Unknown Macintosh","Macintosh","Mac XL","Mac 512KE","Mac Plus","Mac SE","Mac II"
  48.     ,"Mac IIx","Mac IIcx","Mac SE/30","Mac Portable","Mac IIci","Unknown Macintosh"
  49.     ,"Mac IIfx","Unknown Macintosh","Unknown Macintosh","Unknown Macintosh"
  50.     ,"Mac Classic","Mac IIsi","Mac LC","Mac Quadra 900","PowerBook 170"
  51.     ,"Mac Quadra 700","Mac Classic II","PowerBook 100","PowerBook 140","Quadra 950"
  52.     ,"Unknown Macintosh"
  53. };
  54.  
  55. char processorName[][20]={
  56.     "unknown processor","68000","68010","68020","68030","68040","unknown processor"
  57. };
  58.  
  59. char fpuName[][32]={
  60.     "no floating point unit","68881","68882","built-in floating point"
  61.     ,"unknown floating point unit"
  62. };
  63.  
  64. char *IdentifyCompiler(void)
  65. {
  66.     static char string[200];
  67.     char *compiler,*longs,*floating,version[4],*format;
  68.     double v;
  69.     
  70.     string[0]=0;
  71.     compiler="";
  72.     #if THINK_C
  73.         compiler="THINK ";
  74.     #endif
  75.     #if applec
  76.         compiler="MPW ";
  77.     #endif
  78.     v=0;
  79.     #if THINK_C==1
  80.         v=4;
  81.     #endif
  82.     #if THINK_C>1
  83.         v=THINK_C;
  84.     #endif
  85.     if(v>0.0){
  86.         if(v==5.0)sprintf(version,"5 or 6.0 "); /* Symantec forgot to update version # */
  87.         else sprintf(version,"%1.0f ",v);
  88.     }else sprintf(version,"");
  89.     if(mc68020)longs="generate 68020 instructions";
  90.     else longs="not generate 68020 instructions";
  91.     if(mc68881)floating="generate 68881 instructions";
  92.     else floating="do all float arithmetic through SANE";
  93.     if(sizeof(double)==12){
  94.         format="native-format doubles";
  95.         #if THINK_C>1 
  96.             #if !__option(native_fp)
  97.                 format="universal-format doubles";
  98.             #endif
  99.         #endif
  100.     }else format="doubles";
  101.     sprintf(string,"%sC %scompiled to %s, \n%s, and use %ld-byte %s."
  102.         ,compiler,version,longs,floating,sizeof(double),format);
  103.     return string;
  104. }
  105.  
  106. char *IdentifyModel(void)
  107. {
  108.     OSErr error;
  109.     long machine;
  110.     int machines=sizeof(machineName)/sizeof(machineName[0]);
  111.     static char string[32];
  112.  
  113.     string[0]=0;
  114.     error=Gestalt(gestaltMachineType,&machine);
  115.     if(!error){
  116.         GetIndString((unsigned char *)string,kMachineNameStrID,machine);
  117.         p2cstr((unsigned char *)string);
  118.         if(strlen(string)==0){
  119.             if(machine<0 || machine>=machines)machine=0;
  120.             sprintf(string,"%#s",machineName[machine]);
  121.         }
  122.     }
  123.     return string;
  124. }
  125.  
  126. char *IdentifyVideo(GDHandle device)
  127. // E.g. "PowerBook 170 “Macintosh D Built-In Video” (.Display_Video_Apple_TIM)"
  128. {
  129.     static char string[256];
  130.     long quickDraw;
  131.  
  132.     string[0]=0;
  133.     Gestalt(gestaltQuickdrawVersion,&quickDraw);
  134.     if(quickDraw<gestalt8BitQD){
  135.         sprintf(string,"%s ",IdentifyModel());
  136.         sprintf(string,"%s“%s”",string,"1-bit QuickDraw");
  137.     }else{
  138.         if(GetDeviceSlot(device)==0)sprintf(string,"%s ",IdentifyModel());
  139.         sprintf(string,"%s“%s”",string,GDCardName(device));
  140.         if(GDVersion(device)==0)sprintf(string,"%s (%#s)",string,GDName(device));
  141.         else sprintf(string,"%s (%#s version %d)"
  142.             ,string,GDName(device),GDVersion(device));
  143.         sprintf(string,"%s slot %d",string,GetDeviceSlot(device));
  144.     }
  145.     return string;
  146. }
  147.  
  148. char *IdentifyMachine(void)
  149. {
  150.     OSErr error;
  151.     long fpu,processor,system,value;
  152.     int processors=sizeof(processorName)/sizeof(processorName[0]);
  153.     int fpus=sizeof(fpuName)/sizeof(fpuName[0]);
  154.     static char string[256];
  155.     unsigned char **owner;
  156.     Boolean cacheData=1,cacheInstructions=1;
  157.     long romSize,romVersion,qD;
  158.     
  159.     string[0]=0;
  160.     owner=GetString(-16096);    // Get owner's name from System file
  161.     error=Gestalt(gestaltSystemVersion,&system);
  162.     if(error)return string;                        /* Gestalt not available */
  163.     Gestalt(gestaltProcessorType,&processor);
  164.     if(processor<0 || processor>=processors)processor=processors-1;
  165.     Gestalt(gestaltFPUType,&fpu);
  166.     if(fpu<0 || fpu>=fpus)fpu=fpus-1;
  167.     if(owner!=NULL && *owner[0]>0)sprintf(string,"%#s’s ",*owner);
  168.     sprintf(string,"%s%s",string,IdentifyModel());
  169.     sprintf(string,"%s with %s and %s running System %lx.%lx"
  170.         ,string,processorName[processor],fpuName[fpu]
  171.         ,system/0x100,system%0x100/0x10);
  172.     system%=0x10;
  173.     if(system)sprintf(string,"%s.%lx",string,system);
  174.     Gestalt(gestaltROMSize,&romSize);
  175.     Gestalt(gestaltROMVersion,&romVersion);
  176.     sprintf(string,"%s, %ldK ROM version %ld+%ld*256."
  177.         ,string,romSize/1024,romVersion%256,romVersion/256);
  178.     if(TrapAvailable(_HWPriv)){
  179.         cacheData=SwapDataCache(1);
  180.         SwapDataCache(cacheData);
  181.         cacheInstructions=SwapInstructionCache(1);
  182.         SwapInstructionCache(cacheInstructions);
  183.         if(cacheData || cacheInstructions)sprintf(string,"%s Caching",string);
  184.         else sprintf(string,"%s No caching",string);
  185.         if(cacheData)sprintf(string,"%s data",string);
  186.         if(cacheData && cacheInstructions)sprintf(string,"%s &",string);
  187.         if(cacheInstructions)sprintf(string,"%s instructions",string);
  188.         sprintf(string,"%s.",string);
  189.     }
  190.     value=0;
  191.     Gestalt(gestaltAddressingModeAttr,&value);
  192.     if(value&1<<gestalt32BitAddressing)sprintf(string,"%s 32-bit addressing.",string);
  193.     else sprintf(string,"%s 24-bit addressing.",string);
  194.     Gestalt(gestaltQuickdrawVersion,&qD);
  195.     switch(qD/0x100){
  196.         case 0:
  197.             sprintf(string,"%s 1-bit QuickDraw.",string);
  198.             break;
  199.         case 1:
  200.             sprintf(string,"%s 8-bit QuickDraw.",string);
  201.             break;
  202.         case 2:
  203.             sprintf(string,"%s 32-bit QuickDraw 1.%02lx.",string,qD%0x100);
  204.             break;
  205.         default:
  206.             sprintf(string,"%s QuickDraw 0x%lx.",string,qD);
  207.             break;
  208.     }
  209.     return string;
  210. }
  211.