home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / Libraries / VideoToolbox 95.04.18 / Utilities / GrabDrivers / GrabSlotDrivers.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-18  |  4.4 KB  |  137 lines  |  [TEXT/MMCC]

  1. /* GrabSlotDrivers.c
  2. Repeatedly calls the Slot Manager to get every slot driver and puts each in its
  3. own file. These files can then be perused with the ResEdit CODE viewer. 
  4.  
  5. The ResEdit CODE viewer is a public domain file, for use with ResEdit, distributed by:
  6. Ira L. Ruben
  7. Apple Computer, Inc.
  8. 20525 Mariani Ave., MS: 37-A
  9. Cupertino, Ca. 95014
  10. Ira@Apple.Com
  11. ftp://ftp.apple.com/dts/mac/tools/resedit/
  12.  
  13. Note that GrabSlotDrivers gets the driver directly from the card's configuration
  14. ROM, whereas it is possible that your run-time System is actually superceding
  15. that by a later version of the driver loaded from the System file or by an INIT.
  16. If you want the active version of the driver it would be best to get it from the
  17. device manager, which is what GrabVideoDrivers.c does, though it skips non-video
  18. devices.
  19.  
  20. HISTORY:
  21. 2/89 dgp Wrote it as "video hacker II" using THINK C 3.
  22. 1/3/93 dgp updated it to THINK C 5 and renamed it GrabSlotDrivers.c
  23. 5/11/93    dgp    added check for Slot Manager, in response to bug report by Jonathan Brecher.
  24. 7/29/94 dgp Eliminated use of "#s" printf format, since it's not supported by
  25.             Metrowerks CodeWarrior C.
  26. 9/5/94 dgp removed assumption in printf's that int==short.
  27. */
  28. #include "VideoToolbox.h"
  29. #include <Errors.h>
  30. #include <Resources.h>
  31. #include <Traps.h>
  32. #include <ROMDefs.h>
  33. #include <Video.h>
  34. typedef struct {
  35.     short flags;
  36.     short blanks[3];
  37.     short open;
  38.     short prime;
  39.     short control;
  40.     short status;
  41.     short close;
  42.     Str255 name;
  43. } VideoDriver;
  44. void AddResourceToFile(unsigned char *filename,unsigned char *name,ResType type,int id
  45.     ,Handle handle);
  46. void GrabSlotDrivers(void);
  47.  
  48. void main(void)
  49. {
  50.     Require(0);
  51.     if(!TrapAvailable(_SlotManager))
  52.         PrintfExit("Sorry, no Slot Manager.\n");
  53.     MaximizeConsoleHeight();
  54.     printf(BreakLines("Welcome to GrabSlotDrivers.\n"
  55.     "This programs copies all drivers from your slot devices. "
  56.     "Note that this gets the driver from the card's configuration ROM, whereas "
  57.     "it is possible that at run-time your System replaces "
  58.     "that by a later version of the driver loaded from the System file or INIT.\n\n",78));
  59.     GrabSlotDrivers();
  60. }
  61.  
  62. void GrabSlotDrivers(void)
  63. {
  64.     SpBlock spBlock;
  65.     SEBlock sEBlock;
  66.     unsigned char name[256],filename[32];
  67.     int error,version;
  68.     Ptr *handle;
  69.     VideoDriver *videoDriverPtr;
  70.     unsigned char *bytePtr;
  71.     Boolean newSlotMgr;    // SGetTypeSRsrc requires system 7 slot manager
  72.  
  73.     newSlotMgr=(SVersion(&spBlock)==noErr);
  74.     spBlock.spsExecPBlk = (Ptr) &sEBlock;
  75.     spBlock.spSlot = 0;
  76.     spBlock.spID = 0;
  77.     spBlock.spExtDev = 0;
  78. /*
  79.     spBlock.spCategory=catDisplay;
  80.     spBlock.spCType=0;
  81.     spBlock.spDrvrSW=0;
  82.     spBlock.spDrvrHW=0;
  83.     spBlock.spTBMask=3;    // ignore DrvrHW and DrvrSW
  84. */
  85.     while(1){
  86.         spBlock.spParamData=5;    // next resource, whether enabled & disabled
  87.         if(newSlotMgr)error=SGetSRsrc(&spBlock);
  88.         else error=SNextSRsrc(&spBlock);
  89.         if(error==smNoMoresRsrcs) break;
  90.         if(error){
  91.             printf("SNextSRsrc/SGetSRsrc error %d\n",error);
  92.             break;
  93.         }
  94.         spBlock.spResult = (unsigned long) &name;
  95.         error = SReadDrvrName(&spBlock);
  96.         p2cstr(name);
  97.         printf("SReadDrvrName=%s\n",name);
  98.         c2pstr((char *)name);
  99.         printf("spSlot=%d,spID=%u,spExtDev=%d"
  100.             ,(int)spBlock.spSlot,(unsigned int)spBlock.spID,(int)spBlock.spExtDev);
  101.         printf(",spCategory=%d,spCType=%d,spDrvrSW=%d,spDrvrHW=%d,spRefNum=%d\n"
  102.             ,(int)spBlock.spCategory,(int)spBlock.spCType,(int)spBlock.spDrvrSW
  103.             ,(int)spBlock.spDrvrHW,(int)spBlock.spRefNum);
  104.         memcpy(filename,name,32);
  105.         /* filename must be truncated to 31 characters */
  106.         if(filename[0] > 31) filename[0]=31;
  107.         // Replace leading "." by "-" since the Mac filing system 
  108.         // is confused by filenames beginning with ".".
  109.         if(filename[1]=='.')filename[1]='-';
  110.         
  111.         /* get handle to desired driver resource */
  112.         error = SGetDriver(&spBlock);
  113.         if(!error) {
  114.             handle = (Ptr *) spBlock.spResult;
  115.     
  116.             // Is this a video driver?
  117.             videoDriverPtr=*(VideoDriver **)handle;
  118.             if(EqualString(name,videoDriverPtr->name,1,1)){
  119.                 // Probably is a video driver. The version number of a video driver 
  120.                 // is the first word-aligned word after the name string.
  121.                 bytePtr= videoDriverPtr->name;
  122.                 bytePtr += 1+bytePtr[0];    /* go to end of Pascal string */
  123.                 bytePtr = (unsigned char *)((long)(bytePtr+1) & ~1);    // round up to word boundary
  124.                 version = *(short *)bytePtr;
  125.             } else version=rand();
  126.         
  127.             AddResourceToFile(filename,name,'DRVR',version,handle);
  128.             printf("Driver copied to file “%s”, with resource id %d\n"
  129.                 ,p2cstr(filename),(int)version);
  130.             DisposHandle(handle);
  131.         }
  132.         else printf("No driver.\n");
  133.         printf("\n");
  134.     }
  135. }
  136.  
  137.