2002-03-16 04:01:09 +00:00
|
|
|
/*
|
|
|
|
* $Id$
|
|
|
|
*
|
2004-05-02 11:09:25 +00:00
|
|
|
* prefs_macosx.cpp - Preferences handling, Mac OS X specific.
|
2002-03-16 04:01:09 +00:00
|
|
|
* Based on prefs_unix.cpp
|
|
|
|
*
|
2008-01-01 09:40:36 +00:00
|
|
|
* Basilisk II (C) 1997-2008 Christian Bauer
|
2002-03-16 04:01:09 +00:00
|
|
|
*
|
|
|
|
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "sysdeps.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2003-04-02 02:15:52 +00:00
|
|
|
#include <string>
|
|
|
|
using std::string;
|
|
|
|
|
2002-03-16 04:01:09 +00:00
|
|
|
#include "prefs.h"
|
|
|
|
|
|
|
|
|
|
|
|
// Platform-specific preferences items
|
|
|
|
prefs_desc platform_prefs_items[] = {
|
2003-04-02 02:15:52 +00:00
|
|
|
#ifdef HAVE_SIGSEGV_SKIP_INSTRUCTION
|
|
|
|
{"ignoresegv", TYPE_BOOLEAN, false, "ignore illegal memory accesses"},
|
|
|
|
#endif
|
2007-06-13 16:11:31 +00:00
|
|
|
{"idlewait", TYPE_BOOLEAN, false, "sleep when idle"},
|
2002-03-16 04:01:09 +00:00
|
|
|
{NULL, TYPE_END, false, NULL} // End of list
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Prefs file name and path
|
|
|
|
const char PREFS_FILE_NAME[] = ".basilisk_ii_prefs";
|
2003-04-02 02:15:52 +00:00
|
|
|
string UserPrefsPath;
|
|
|
|
static string prefs_path;
|
2002-03-16 04:01:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Load preferences from settings file
|
|
|
|
*/
|
|
|
|
|
2009-11-06 21:33:03 +00:00
|
|
|
void LoadPrefs(const char *vmdir)
|
2002-03-16 04:01:09 +00:00
|
|
|
{
|
2009-11-06 21:33:03 +00:00
|
|
|
if (vmdir) {
|
|
|
|
prefs_path = string(vmdir) + '/' + string("prefs");
|
|
|
|
FILE *prefs = fopen(prefs_path.c_str(), "r");
|
|
|
|
if (!prefs) {
|
|
|
|
printf("No file at %s found.\n", prefs_path.c_str());
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
LoadPrefsFromStream(prefs);
|
|
|
|
fclose(prefs);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-03-16 04:01:09 +00:00
|
|
|
// Construct prefs path
|
2003-04-02 02:15:52 +00:00
|
|
|
if (UserPrefsPath.empty()) {
|
|
|
|
char *home = getenv("HOME");
|
|
|
|
if (home)
|
|
|
|
prefs_path = string(home) + '/';
|
|
|
|
prefs_path += PREFS_FILE_NAME;
|
|
|
|
UserPrefsPath = prefs_path;
|
|
|
|
} else
|
|
|
|
prefs_path = UserPrefsPath;
|
2002-03-16 04:01:09 +00:00
|
|
|
|
|
|
|
// Read preferences from settings file
|
2003-04-02 02:15:52 +00:00
|
|
|
FILE *f = fopen(prefs_path.c_str(), "r");
|
2002-03-16 04:01:09 +00:00
|
|
|
if (f != NULL) {
|
|
|
|
|
|
|
|
// Prefs file found, load settings
|
|
|
|
LoadPrefsFromStream(f);
|
|
|
|
fclose(f);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// No prefs file, save defaults
|
|
|
|
SavePrefs();
|
|
|
|
}
|
2004-01-26 11:12:46 +00:00
|
|
|
|
2004-05-02 11:09:25 +00:00
|
|
|
// Remove Nigel's bad old serial prefs
|
2004-01-26 11:12:46 +00:00
|
|
|
|
|
|
|
const char *str;
|
|
|
|
int tmp = 0;
|
|
|
|
|
|
|
|
if ( (str = PrefsFindString("seriala") ) != NULL
|
|
|
|
&& strcmp(str, "/dev/ttys0") == 0 )
|
|
|
|
{
|
|
|
|
puts("Deleting invalid prefs item 'seriala /dev/ttys0'");
|
2004-01-27 11:31:01 +00:00
|
|
|
PrefsRemoveItem("seriala", 1);
|
2004-01-26 11:12:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( (str = PrefsFindString("serialb") ) != NULL
|
|
|
|
&& strcmp(str, "/dev/ttys1") == 0 )
|
|
|
|
{
|
|
|
|
puts("Deleting invalid prefs item 'serialb /dev/ttys1'");
|
2004-01-27 11:31:01 +00:00
|
|
|
PrefsRemoveItem("serialb", 1);
|
2004-01-26 11:12:46 +00:00
|
|
|
}
|
2004-05-02 11:09:25 +00:00
|
|
|
|
|
|
|
// Floppy & cdrom prefs are always removed -
|
|
|
|
// we search for them each time the emulator is started
|
|
|
|
|
|
|
|
while ( (str = PrefsFindString("floppy", tmp) ) != NULL )
|
|
|
|
PrefsRemoveItem("floppy", tmp);
|
|
|
|
|
|
|
|
while ( (str = PrefsFindString("cdrom", tmp) ) != NULL )
|
|
|
|
PrefsRemoveItem("cdrom", tmp);
|
2002-03-16 04:01:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Save preferences to settings file
|
|
|
|
*/
|
|
|
|
|
|
|
|
void SavePrefs(void)
|
|
|
|
{
|
|
|
|
FILE *f;
|
2003-04-02 02:15:52 +00:00
|
|
|
if ((f = fopen(prefs_path.c_str(), "w")) != NULL) {
|
2002-03-16 04:01:09 +00:00
|
|
|
SavePrefsToStream(f);
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add defaults of platform-specific prefs items
|
|
|
|
* You may also override the defaults set in PrefsInit()
|
|
|
|
*/
|
|
|
|
|
|
|
|
void AddPlatformPrefsDefaults(void)
|
|
|
|
{
|
2003-08-02 10:43:06 +00:00
|
|
|
PrefsReplaceString("extfs", getenv("HOME"));
|
2003-03-26 00:18:05 +00:00
|
|
|
PrefsReplaceString("screen", "win/512/384/16");
|
2003-04-02 02:15:52 +00:00
|
|
|
#ifdef HAVE_SIGSEGV_SKIP_INSTRUCTION
|
|
|
|
PrefsAddBool("ignoresegv", false);
|
|
|
|
#endif
|
2007-06-13 16:11:31 +00:00
|
|
|
PrefsAddBool("idlewait", true);
|
2002-03-16 04:01:09 +00:00
|
|
|
}
|