home *** CD-ROM | disk | FTP | other *** search
- /*
- ***********************************************************************
- *
- * PRAM boss
- * Reading Parameter RAM (PRAM) and setting/resetting it
- *
- * The program is intended to save the contents of the parameter RAM and the
- * extended PRAM in a resource. The resource is used by an INIT PRAMset to
- * reset the PRAM and extended PRAM to their "original" values (at the moment
- * when the resource was created/updated). PRAM is a non-volatile RAM that stores
- * almost all system parameters that are controlled by "control panels",
- * say, the current date, the system font number and the speaker volume, beep 'snd '
- * resource id, etc. The resource to store the "standard" PRAM settings is a 'HEXA'
- * resource named "Standard PRAM".
- *
- ***********************************************************************
- */
-
- /* MacHeaders Included */
-
- #include "PRAM Resource.h"
- #include "myenv.h"
- #include <string.h>
-
- // This is
- // CLR.L D0
- // MOVE.W (A7)+,D0 size -> lo word of d0
- // SWAP D0 size -> hi word of d0
- // MOVEA.L (A7)+,A0 where -> A0
- // _ReadXPRam
- void read_extended_PRAM(char * where, const short size) =
- { 0x4280, 0x301F, 0x4840, 0x205F, 0xA051 };
-
- void main(void)
- {
- Initialize_MAC();
-
- const OSType res_type = 'HEXA';
- const unsigned char * res_name = "\pStandard PRAM";
- Boolean new_resource;
- PRAMSettings ** res_handle;
- // Try to get a resource from the file first
- if( (res_handle = (PRAMSettings**)Get1NamedResource(res_type,res_name)) == nil )
- {
- OSErr err = ResError();
- if( err != resNotFound && err != noErr )
- _error("Can't load the %#s resource because of error %d",res_name,err);
- // If the resource is not found, create it
- res_handle = (PRAMSettings **)NewHandle(sizeof(PRAMSettings));
- assert( res_handle != nil );
- new_resource = TRUE;
- }
- else
- { // Just to make sure we got what we needed
- assert( SizeResource((Handle)res_handle) == sizeof(PRAMSettings) );
- new_resource = FALSE;
- }
-
-
- (*res_handle)->PRAM = *(GetSysPPtr());
- assert( (unsigned char)((*res_handle)->PRAM).valid == 0xA8 );
-
- read_extended_PRAM((*res_handle)->extended_PRAM.body,
- sizeof((*res_handle)->extended_PRAM.body));
-
- // Save the resource
- if( new_resource )
- AddResource((Handle)res_handle,res_type,UniqueID(res_type),res_name);
- else
- ChangedResource((Handle)res_handle);
-
- do_well( ResError() );
- WriteResource((Handle)res_handle);
- do_well( ResError() );
-
- message("Resource '%#s' of type %4c was created with the current content of the PRAM(s)",
- res_name,res_type);
- }