home *** CD-ROM | disk | FTP | other *** search
- /*
- Commodore 64 Emulator v0.4 Earle F. Philhower III
- Copyright (C) 1993-4 (st916w9r@dunx1.ocs.drexel.edu)
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
- #include "Processor.h"
- #include "Preferences.h"
- #include "Error.h"
- #include "Resources.h"
- #include "FileTypes.h"
- #include <Folders.h>
-
- Pref globalPref;
- DialogPtr prefDialog;
- FSSpec prefSpec;
-
- int PrefInitialize()
- {
- short vRefNum;
- long dirID;
- short fnum;
- int err;
- long size;
-
- /* Get the preferences dialog */
- prefDialog=GetNewDialog(kPrefDialog, nil, (WindowPtr)-1L);
- if (prefDialog==nil) return kMissingResource;
-
- /* Set up the default preferences */
- globalPref.byteAlign=0;
- globalPref.colorVIC=0;
- globalPref.doubleSize=0;
- globalPref.ramCheck=0;
- globalPref.useProcessor=0;
-
- /* File spec for the pref file. Only need to create once */
- FindFolder(0, kPreferencesFolderType, true, &vRefNum, &dirID);
- FSMakeFSSpec(vRefNum, dirID, "\pCommodore 64 Prefs", &prefSpec);
-
- /* Try to read in the prefs file */
- err=FSpOpenDF(&prefSpec, fsRdPerm, &fnum);
- if (err==noErr)
- {
- size=sizeof(Pref);
- FSRead(fnum, &size, &globalPref);
- FSClose(fnum);
- }
-
- return kNoError;
- }
-
- void UpdatePrefDialog(Pref pref)
- {
- short type;
- Rect rect;
- Handle ctl;
-
- GetDItem(prefDialog, 1, &type, &ctl, &rect);
- SetCtlValue( (ControlHandle)ctl, pref.byteAlign?1:0);
-
- GetDItem(prefDialog, 2, &type, &ctl, &rect);
- SetCtlValue( (ControlHandle)ctl, pref.colorVIC?0:1);
-
- GetDItem(prefDialog, 3, &type, &ctl, &rect);
- SetCtlValue( (ControlHandle)ctl, pref.colorVIC?1:0);
-
- GetDItem(prefDialog, 4, &type, &ctl, &rect);
- SetCtlValue( (ControlHandle)ctl, pref.doubleSize?1:0);
-
- GetDItem(prefDialog, 5, &type, &ctl, &rect);
- SetCtlValue( (ControlHandle)ctl, pref.ramCheck?0:1);
-
- GetDItem(prefDialog, 6, &type, &ctl, &rect);
- SetCtlValue( (ControlHandle)ctl, pref.useProcessor==asmProcessor?1:0);
-
- GetDItem(prefDialog, 7, &type, &ctl, &rect);
- SetCtlValue( (ControlHandle)ctl, pref.useProcessor==cProcessor?1:0);
-
- GetDItem(prefDialog, 8, &type, &ctl, &rect);
- SetCtlValue( (ControlHandle)ctl, pref.useProcessor==intCProcessor?1:0);
- }
-
- void DoPrefs()
- {
- short itemHit, done, err;
- Pref localPref;
- short fnum;
- long size;
-
- /* Make a local copy of the prefs in case the user "Cancels" */
- localPref=globalPref;
-
- /* Setup dialog window, bring it up */
- UpdatePrefDialog(localPref);
- SelectWindow(prefDialog);
- ShowWindow(prefDialog);
-
- /* Do the dialog event loop */
- done=0;
- while (done==0)
- {
- ModalDialog(nil, &itemHit);
- switch (itemHit)
- {
- case 1: /* Byte-align window */
- localPref.byteAlign=localPref.byteAlign?0:1;
- UpdatePrefDialog(localPref);
- break;
- case 2: /* Black-and-white VIC */
- localPref.colorVIC=0;
- UpdatePrefDialog(localPref);
- break;
- case 3: /* Color VIC */
- localPref.colorVIC=1;
- UpdatePrefDialog(localPref);
- break;
- case 4: /* Double size */
- localPref.doubleSize=localPref.doubleSize?0:1;
- UpdatePrefDialog(localPref);
- break;
- case 5: /* Ram test skip */
- localPref.ramCheck=localPref.ramCheck?0:1;
- UpdatePrefDialog(localPref);
- break;
- case 6: /* 68K processor */
- localPref.useProcessor=asmProcessor;
- UpdatePrefDialog(localPref);
- break;
- case 7: /* C processor */
- localPref.useProcessor=cProcessor;
- UpdatePrefDialog(localPref);
- break;
- case 8: /* Integrated C processor */
- localPref.useProcessor=intCProcessor;
- UpdatePrefDialog(localPref);
- break;
- case 9: /* Okay */
- /* Delete the old file and make a new one */
- FSpDelete(&prefSpec);
- FSpCreate(&prefSpec, (OSType)APPLTYPE, (OSType)PREFFTYPE, 0);
-
- /* Attempt to write the file */
- err=FSpOpenDF(&prefSpec, fsRdWrPerm, &fnum);
- if (err==noErr)
- {
- size=sizeof(Pref);
- FSWrite(fnum, &size, &localPref);
- FSClose(fnum);
- }
-
- /* Set up the global prefs */
- globalPref=localPref;
- done=1;
- ShowVICWindow();
- break;
-
- case 10: /* Cancel */
- /* Exit without copying over to global */
- done=1;
- break;
- }
- };
-
- /* Drop the window */
- HideWindow(prefDialog);
- }
-