home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Libraries / VideoToolbox 94.11.17 / VideoToolboxSources / Identify.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-17  |  8.4 KB  |  275 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 and 68881 instructions, 
  7. and use 12-byte universal-format doubles."
  8.  
  9. IdentifyOwner:
  10. "Denis Pelli"
  11.  
  12. IdentifyModel:
  13. "PowerBook 170"
  14.  
  15. IdentifyMachine:
  16. "Denis Pelli’s PowerBook 170 with 68030 and 68882 running System 7.10, ROM 1024K
  17. version 124+6*256. Caching data & instructions."
  18.  
  19. IdentifyVideo(device):
  20. "PowerBook 170 “Macintosh D Built-In Video” (.Display_Video_Apple_TIM) in slot 0"
  21.  
  22. The computer model appears only if the slot==0, which indicates built-in video. The
  23. curly quotes embrace the card name, and the parentheses embrace the driver name.
  24. The driver's version number appears only if it's non-zero.
  25.  
  26. HISTORY:
  27. 1/29/92    dgp wrote IdentifyCompiler.
  28. 2/25/92    dgp    wrote IdentifyMachine.
  29. 8/26/92    dgp get owner and model name from the System file
  30. 2/20/93    dgp    added ROM version
  31. 2/27/93    dgp merged IdentifyCompiler.c and IdentifyMachine.c into the new Identify.c,
  32.             and added IdentifyVideo.
  33. 4/25/93    dgp    IdentifyMachine reports 24/32-bit addressing.
  34. 12/14/93 dgp If THINK C compiler version is "5" I report "5 or 6.0" since Symantec
  35.             forgot to increment the version number when they released 6.0. They
  36.             fixed this in version 6.01.
  37. 3/2/94    dgp    Extracted IdentifyOwner from within IdentifyMachine
  38. 7/28/94 dgp added support for Metrowerks CodeWarrior C compiler and PowerPC.
  39.             Eliminated use of "#s" printf format, since it's not supported by
  40.             Metrowerks CodeWarrior C.
  41. 9/5/94 dgp     removed assumption in printf's that int==short.
  42. 9/6/94    dgp    Enhanced IdentifyCompiler to specify the size of int.
  43. 9/6/94    dgp    Disable cache checks on PowerPC, because those traps are undefined.
  44. 10/5/94 dgp Removed all floating point code from IdentifyCompiler().
  45. 11/5/94 dgp Suppressed ROM info in Identify.
  46. 11/9/94 dgp added IdentifyApplication().
  47. */
  48. #include "VideoToolbox.h"
  49. #include <Traps.h>    // _HWPriv
  50. #include "mc68881.h"
  51. #if UNIVERSAL_HEADERS
  52.     #include <LowMem.h>
  53. #else
  54.     #define LMGetCurApName() ((StringPtr) 0x0910)
  55.     #define gestaltNativeCPUtype 'cput'
  56.     enum{
  57.         gestaltCPU601                = 0x101,
  58.         gestaltCPU603                = 0x103,
  59.         gestaltCPU604                = 0x104
  60.     };
  61. #endif
  62.  
  63. /*
  64. This table was complete in summer '92, but does not include the newer models.
  65. However, the table is used only as a backup, when the System lacks a machine name
  66. string, which is a feature of System 7. Since all new machines nominally require
  67. System 7, it is unlikely that it will ever be necessary to look them up in
  68. this table.
  69. */
  70. char machineName[][20]={
  71.     "Unknown Macintosh","Macintosh","Mac XL","Mac 512KE","Mac Plus","Mac SE","Mac II"
  72.     ,"Mac IIx","Mac IIcx","Mac SE/30","Mac Portable","Mac IIci","Unknown Macintosh"
  73.     ,"Mac IIfx","Unknown Macintosh","Unknown Macintosh","Unknown Macintosh"
  74.     ,"Mac Classic","Mac IIsi","Mac LC","Mac Quadra 900","PowerBook 170"
  75.     ,"Mac Quadra 700","Mac Classic II","PowerBook 100","PowerBook 140","Quadra 950"
  76.     ,"Unknown Macintosh"
  77. };
  78.  
  79. char fpuName[][32]={
  80.     "no floating point unit","68881","68882","built-in floating point"
  81.     ,"unknown floating point unit","Software FPU"
  82. };
  83.  
  84. char *IdentifyCompiler(void)
  85. {
  86.     static char string[200];
  87.     char *compiler,*longs,*floating,version[4],*universal;
  88.     int v=0;
  89.     
  90.     string[0]=0;
  91.     compiler="";
  92.     #if THINK_C
  93.         compiler="Symantec THINK C";
  94.         if(THINK_C==1)v=4;
  95.         else v=THINK_C;
  96.     #endif
  97.     #if THINK_CPLUS
  98.         compiler="Symantec C++";
  99.         v=THINK_CPLUS;
  100.     #endif
  101.     #if applec
  102.         compiler="MPW C";
  103.     #endif
  104.     #if __MWERKS__
  105.         compiler="Metrowerks CodeWarrior C";
  106.     #endif
  107.     if(v>0)sprintf(version,"%d ",v);
  108.     else sprintf(version,"");
  109.     if(mc68020)longs="68020";
  110.     else{
  111.         #if __powerc
  112.             longs="PowerPC";
  113.         #else
  114.             longs="68000";
  115.         #endif
  116.     }
  117.     if(mc68881)floating=" and 68881";
  118.     else floating="";
  119.     universal="";
  120.     if(sizeof(double)==12){
  121.         #if defined(THINK_C)
  122.             #if !__option(native_fp)
  123.                 universal="\"universal\"-format ";
  124.             #endif
  125.         #endif
  126.     }
  127.     sprintf(string,"Compiled by %s %sfor %s%s, using %ld-byte int and %s%ld-byte double."
  128.         ,compiler,version,longs,floating,sizeof(int),universal,sizeof(double));
  129.     return string;
  130. }
  131.  
  132. char *IdentifyModel(void)
  133. {
  134.     int error;
  135.     long machine;
  136.     int machines=sizeof(machineName)/sizeof(machineName[0]);
  137.     static char string[32];
  138.  
  139.     string[0]=0;
  140.     error=Gestalt(gestaltMachineType,&machine);
  141.     if(!error){
  142.         GetIndString((unsigned char *)string,kMachineNameStrID,machine);
  143.         p2cstr((unsigned char *)string);
  144.         if(strlen(string)==0){
  145.             if(machine<0 || machine>=machines)machine=0;
  146.             sprintf(string,"%s",machineName[machine]);
  147.         }
  148.     }
  149.     return string;
  150. }
  151.  
  152. char *IdentifyVideo(GDHandle device)
  153. // E.g. "PowerBook 170 “Macintosh D Built-In Video” (.Display_Video_Apple_TIM)"
  154. {
  155.     static char string[256];
  156.     long quickDraw;
  157.  
  158.     string[0]=0;
  159.     Gestalt(gestaltQuickdrawVersion,&quickDraw);
  160.     if(quickDraw<gestalt8BitQD){
  161.         sprintf(string,"%s ",IdentifyModel());
  162.         sprintf(string,"%s“%s”",string,"1-bit QuickDraw");
  163.     }else{
  164.         if(GetDeviceSlot(device)==0)sprintf(string,"%s ",IdentifyModel());
  165.         sprintf(string,"%s“%s”",string,GDCardName(device));
  166.         if(GDVersion(device)==0)sprintf(string,"%s (%s)",string,GDNameStr(device));
  167.         else sprintf(string,"%s (%s version %d)"
  168.             ,string,GDNameStr(device),(int)GDVersion(device));
  169.         sprintf(string,"%s slot %d",string,(int)GetDeviceSlot(device));
  170.     }
  171.     return string;
  172. }
  173.  
  174. char *IdentifyOwner(void)
  175. {
  176.     static char string[64];
  177.     unsigned char **owner;
  178.     
  179.     string[0]=0;
  180.     owner=GetString(-16096);    // Get owner's name from System file
  181.     if(owner!=NULL && *owner[0]>0){
  182.         memcpy(string,*owner,(*owner)[0]+1);
  183.         p2cstr((unsigned char *)string);
  184.     }
  185.     return string;
  186. }
  187.  
  188. char *IdentifyApplication(void)    // Returns name of application.
  189. {
  190.     static char string[32];
  191.  
  192.     memcpy(string,LMGetCurApName(),32);
  193.     p2cstr((unsigned char *)string);
  194.     return string;
  195. }
  196.  
  197. char *IdentifyMachine(void)
  198. {
  199.     int error;
  200.     long fpu,processor,system,value;
  201.     int fpus=sizeof(fpuName)/sizeof(fpuName[0]);
  202.     static char string[256];
  203.     Boolean cacheData=1,cacheInstructions=1;
  204.     long romSize,romVersion,qD;
  205.     char *processorName,*owner;
  206.     
  207.     string[0]=0;
  208.     error=Gestalt(gestaltSystemVersion,&system);
  209.     if(error)return string;                        /* Gestalt not available */
  210.     error=Gestalt(gestaltNativeCPUtype,&processor);
  211.     if(error)Gestalt(gestaltProcessorType,&processor);
  212.     Gestalt(gestaltFPUType,&fpu);
  213.     if(fpu<0 || fpu>=fpus)fpu=fpus-2;
  214.     if(fpu==1 && Gestalt('FPUE',&value)==0)fpu=fpus-1;    // Software FPU by John Neil & Assoc.
  215.     owner=IdentifyOwner();
  216.     if(strlen(owner)>0)sprintf(string,"%s’s ",owner);
  217.     sprintf(string,"%s%s",string,IdentifyModel());
  218.     switch(processor){
  219.         case 1: processorName="68000";break;
  220.         case 2: processorName="68010";break;
  221.         case 3: processorName="68020";break;
  222.         case 4: processorName="68030";break;
  223.         case 5: processorName="68040";break;
  224.         case gestaltCPU601: processorName="PPC601";break;
  225.         case gestaltCPU603: processorName="PPC603";break;
  226.         case gestaltCPU604: processorName="PPC604";break;
  227.         default: processorName="unknown processor";break;
  228.     }
  229.     sprintf(string,"%s with %s and %s running System %lx.%lx"
  230.         ,string,processorName,fpuName[fpu]
  231.         ,system/0x100,system%0x100/0x10);
  232.     system%=0x10;
  233.     if(system)sprintf(string,"%s.%lx",string,system);
  234.     sprintf(string,"%s.",string);
  235.     Gestalt(gestaltROMSize,&romSize);
  236.     Gestalt(gestaltROMVersion,&romVersion);
  237.     // I've never found any use for the ROM info, so I'm suppressing it.
  238.     if(0)sprintf(string,"%s, %ldK ROM version %ld+%ld*256."
  239.         ,string,romSize/1024,romVersion%256,romVersion/256);
  240.     if(TrapAvailable(_HWPriv)){
  241.         #if !__powerc    /* apparently these functions don't work on PowerPC */
  242.             cacheData=SwapDataCache(1);
  243.             SwapDataCache(cacheData);
  244.             cacheInstructions=SwapInstructionCache(1);
  245.             SwapInstructionCache(cacheInstructions);
  246.             if(cacheData || cacheInstructions)sprintf(string,"%s Caching",string);
  247.             else sprintf(string,"%s No caching",string);
  248.             if(cacheData)sprintf(string,"%s data",string);
  249.             if(cacheData && cacheInstructions)sprintf(string,"%s &",string);
  250.             if(cacheInstructions)sprintf(string,"%s instructions",string);
  251.             sprintf(string,"%s.",string);
  252.         #endif
  253.     }
  254.     value=0;
  255.     Gestalt(gestaltAddressingModeAttr,&value);
  256.     if(value&1<<gestalt32BitAddressing)sprintf(string,"%s 32-bit addressing.",string);
  257.     else sprintf(string,"%s 24-bit addressing.",string);
  258.     Gestalt(gestaltQuickdrawVersion,&qD);
  259.     switch(qD/0x100){
  260.         case 0:
  261.             sprintf(string,"%s 1-bit QuickDraw.",string);
  262.             break;
  263.         case 1:
  264.             sprintf(string,"%s 8-bit QuickDraw.",string);
  265.             break;
  266.         case 2:
  267.             sprintf(string,"%s 32-bit QuickDraw 1.%02lx.",string,qD%0x100);
  268.             break;
  269.         default:
  270.             sprintf(string,"%s QuickDraw 0x%lx.",string,qD);
  271.             break;
  272.     }
  273.     return string;
  274. }
  275.