home *** CD-ROM | disk | FTP | other *** search
/ Mac Expert 1995 Winter / Mac Expert - Winter 95.iso / Les fichiers / Utilitaires divers / Divers / C64-Emulator 0.4 ƒ / SOURCE / Preferences.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-06  |  4.6 KB  |  181 lines  |  [TEXT/KAHL]

  1. /*
  2.     Commodore 64 Emulator v0.4      Earle F. Philhower III
  3.     Copyright (C) 1993-4            (st916w9r@dunx1.ocs.drexel.edu)
  4.  
  5.     This program is free software; you can redistribute it and/or modify
  6.     it under the terms of the GNU General Public License as published by
  7.     the Free Software Foundation; either version 2 of the License, or
  8.     (at your option) any later version.
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19.  
  20. #include "Processor.h"
  21. #include "Preferences.h"
  22. #include "Error.h"
  23. #include "Resources.h"
  24. #include "FileTypes.h"
  25. #include <Folders.h>
  26.  
  27. Pref globalPref;
  28. DialogPtr prefDialog;
  29. FSSpec prefSpec;
  30.  
  31. int PrefInitialize()
  32. {
  33.     short vRefNum;
  34.     long dirID;
  35.     short fnum;
  36.     int err;
  37.     long size;
  38.     
  39.     /* Get the preferences dialog */
  40.     prefDialog=GetNewDialog(kPrefDialog, nil, (WindowPtr)-1L);
  41.     if (prefDialog==nil) return kMissingResource;
  42.  
  43.     /* Set up the default preferences */
  44.     globalPref.byteAlign=0;
  45.     globalPref.colorVIC=0;
  46.     globalPref.doubleSize=0;
  47.     globalPref.ramCheck=0;
  48.     globalPref.useProcessor=0;
  49.  
  50.     /* File spec for the pref file.  Only need to create once */
  51.     FindFolder(0, kPreferencesFolderType, true, &vRefNum, &dirID);
  52.     FSMakeFSSpec(vRefNum, dirID, "\pCommodore 64 Prefs", &prefSpec);
  53.  
  54.     /* Try to read in the prefs file */
  55.     err=FSpOpenDF(&prefSpec, fsRdPerm, &fnum);
  56.     if (err==noErr)
  57.     {
  58.         size=sizeof(Pref);
  59.         FSRead(fnum, &size, &globalPref);
  60.         FSClose(fnum);
  61.     }
  62.     
  63.     return kNoError;
  64. }
  65.  
  66. void UpdatePrefDialog(Pref pref)
  67. {
  68.     short type;
  69.     Rect rect;
  70.     Handle ctl;
  71.     
  72.     GetDItem(prefDialog, 1, &type, &ctl, &rect);
  73.     SetCtlValue( (ControlHandle)ctl, pref.byteAlign?1:0);
  74.  
  75.     GetDItem(prefDialog, 2, &type, &ctl, &rect);
  76.     SetCtlValue( (ControlHandle)ctl, pref.colorVIC?0:1);
  77.  
  78.     GetDItem(prefDialog, 3, &type, &ctl, &rect);
  79.     SetCtlValue( (ControlHandle)ctl, pref.colorVIC?1:0);
  80.  
  81.     GetDItem(prefDialog, 4, &type, &ctl, &rect);
  82.     SetCtlValue( (ControlHandle)ctl, pref.doubleSize?1:0);
  83.  
  84.     GetDItem(prefDialog, 5, &type, &ctl, &rect);
  85.     SetCtlValue( (ControlHandle)ctl, pref.ramCheck?0:1);
  86.  
  87.     GetDItem(prefDialog, 6, &type, &ctl, &rect);
  88.     SetCtlValue( (ControlHandle)ctl, pref.useProcessor==asmProcessor?1:0);
  89.  
  90.     GetDItem(prefDialog, 7, &type, &ctl, &rect);
  91.     SetCtlValue( (ControlHandle)ctl, pref.useProcessor==cProcessor?1:0);
  92.  
  93.     GetDItem(prefDialog, 8, &type, &ctl, &rect);
  94.     SetCtlValue( (ControlHandle)ctl, pref.useProcessor==intCProcessor?1:0);
  95. }
  96.  
  97. void DoPrefs()
  98. {
  99.     short itemHit, done, err;
  100.     Pref localPref;
  101.     short fnum;
  102.     long size;
  103.  
  104.     /* Make a local copy of the prefs in case the user "Cancels" */
  105.     localPref=globalPref;
  106.     
  107.     /* Setup dialog window, bring it up */
  108.     UpdatePrefDialog(localPref);
  109.     SelectWindow(prefDialog);
  110.     ShowWindow(prefDialog);
  111.  
  112.     /* Do the dialog event loop */
  113.     done=0;
  114.     while (done==0)
  115.     {
  116.         ModalDialog(nil, &itemHit);
  117.         switch (itemHit)
  118.         {
  119.         case 1:    /* Byte-align window */
  120.             localPref.byteAlign=localPref.byteAlign?0:1;
  121.             UpdatePrefDialog(localPref);
  122.             break;
  123.         case 2:    /* Black-and-white VIC */
  124.             localPref.colorVIC=0;
  125.             UpdatePrefDialog(localPref);
  126.             break;
  127.         case 3:    /* Color VIC */
  128.             localPref.colorVIC=1;
  129.             UpdatePrefDialog(localPref);
  130.             break;
  131.         case 4:    /* Double size */
  132.             localPref.doubleSize=localPref.doubleSize?0:1;
  133.             UpdatePrefDialog(localPref);
  134.             break;
  135.         case 5:    /* Ram test skip */
  136.             localPref.ramCheck=localPref.ramCheck?0:1;
  137.             UpdatePrefDialog(localPref);
  138.             break;
  139.         case 6:    /* 68K processor */
  140.             localPref.useProcessor=asmProcessor;
  141.             UpdatePrefDialog(localPref);
  142.             break;
  143.         case 7:    /* C processor */
  144.             localPref.useProcessor=cProcessor;
  145.             UpdatePrefDialog(localPref);
  146.             break;
  147.         case 8:    /* Integrated C processor */
  148.             localPref.useProcessor=intCProcessor;
  149.             UpdatePrefDialog(localPref);
  150.             break;
  151.         case 9:    /* Okay */
  152.             /* Delete the old file and make a new one */
  153.             FSpDelete(&prefSpec);
  154.             FSpCreate(&prefSpec, (OSType)APPLTYPE, (OSType)PREFFTYPE, 0);
  155.  
  156.             /* Attempt to write the file */
  157.             err=FSpOpenDF(&prefSpec, fsRdWrPerm, &fnum);
  158.             if (err==noErr)
  159.             {
  160.                 size=sizeof(Pref);
  161.                 FSWrite(fnum, &size, &localPref);
  162.                 FSClose(fnum);
  163.             }
  164.             
  165.             /* Set up the global prefs */
  166.             globalPref=localPref;
  167.             done=1;
  168.             ShowVICWindow();
  169.             break;
  170.             
  171.         case 10:    /* Cancel */
  172.             /* Exit without copying over to global */
  173.             done=1;
  174.             break;
  175.         }
  176.     };
  177.     
  178.     /* Drop the window */
  179.     HideWindow(prefDialog);
  180. }
  181.