home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 November / macformat-018.iso / Utility Spectacular / Developer / ParamRAM guard / PRAM save.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-13  |  2.6 KB  |  78 lines  |  [TEXT/KAHL]

  1. /*
  2.  ***********************************************************************
  3.  *
  4.  *                                    PRAM boss
  5.  *             Reading Parameter RAM (PRAM) and setting/resetting it
  6.  *
  7.  * The program is intended to save the contents of the parameter RAM and the
  8.  * extended PRAM in a resource. The resource is used by an INIT PRAMset to
  9.  * reset the PRAM and extended PRAM to their "original" values (at the moment
  10.  * when the resource was created/updated). PRAM is a non-volatile RAM that stores
  11.  * almost all system parameters that are controlled by "control panels",
  12.  * say, the current date, the system font number and the speaker volume, beep 'snd '
  13.  * resource id, etc. The resource to store the "standard" PRAM settings is a 'HEXA'
  14.  * resource named "Standard PRAM".
  15.  *
  16.  ***********************************************************************
  17.  */
  18.  
  19. /* MacHeaders Included */
  20.  
  21. #include "PRAM Resource.h"
  22. #include "myenv.h"
  23. #include <string.h>
  24.  
  25.                                 // This is
  26.                                 //        CLR.L      D0
  27.                                 //        MOVE.W    (A7)+,D0        size -> lo word of d0
  28.                                 //        SWAP      D0            size -> hi word of d0
  29.                                 //        MOVEA.L      (A7)+,A0        where -> A0
  30.                                 //        _ReadXPRam
  31. void read_extended_PRAM(char * where, const short size) =
  32. { 0x4280, 0x301F, 0x4840, 0x205F, 0xA051  };
  33.  
  34. void main(void)
  35. {
  36.     Initialize_MAC();
  37.         
  38.     const OSType res_type = 'HEXA';
  39.     const unsigned char * res_name = "\pStandard PRAM";
  40.     Boolean new_resource;
  41.     PRAMSettings ** res_handle;
  42.                                     // Try to get a resource from the file first
  43.     if( (res_handle = (PRAMSettings**)Get1NamedResource(res_type,res_name)) == nil )
  44.     {
  45.         OSErr err = ResError();
  46.         if( err != resNotFound && err != noErr )
  47.           _error("Can't load the %#s resource because of error %d",res_name,err);
  48.                                           // If the resource is not found, create it
  49.         res_handle = (PRAMSettings **)NewHandle(sizeof(PRAMSettings));
  50.         assert( res_handle != nil );
  51.         new_resource = TRUE;
  52.     }
  53.     else
  54.     {                                    // Just to make sure we got what we needed
  55.       assert( SizeResource((Handle)res_handle) == sizeof(PRAMSettings) );
  56.       new_resource = FALSE;
  57.     }
  58.                   
  59.  
  60.     (*res_handle)->PRAM = *(GetSysPPtr());
  61.     assert( (unsigned char)((*res_handle)->PRAM).valid == 0xA8 );
  62.  
  63.     read_extended_PRAM((*res_handle)->extended_PRAM.body,
  64.                         sizeof((*res_handle)->extended_PRAM.body));
  65.                         
  66.                                     // Save the resource
  67.     if( new_resource )
  68.         AddResource((Handle)res_handle,res_type,UniqueID(res_type),res_name);
  69.     else
  70.         ChangedResource((Handle)res_handle);
  71.  
  72.     do_well( ResError() );
  73.     WriteResource((Handle)res_handle);
  74.     do_well( ResError() );
  75.     
  76.     message("Resource '%#s' of type %4c was created with the current content of the PRAM(s)",
  77.             res_name,res_type);
  78. }