1 |
nigel |
1.1 |
/* |
2 |
nigel |
1.8 |
* $Id: prefs_macosx.cpp,v 1.7 2004/01/27 11:31:01 nigel Exp $ |
3 |
nigel |
1.1 |
* |
4 |
nigel |
1.8 |
* prefs_macosx.cpp - Preferences handling, Mac OS X specific. |
5 |
nigel |
1.1 |
* Based on prefs_unix.cpp |
6 |
|
|
* |
7 |
cebix |
1.5 |
* Basilisk II (C) 1997-2004 Christian Bauer |
8 |
nigel |
1.1 |
* |
9 |
|
|
* This program is free software; you can redistribute it and/or modify |
10 |
|
|
* it under the terms of the GNU General Public License as published by |
11 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
12 |
|
|
* (at your option) any later version. |
13 |
|
|
* |
14 |
|
|
* This program is distributed in the hope that it will be useful, |
15 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 |
|
|
* GNU General Public License for more details. |
18 |
|
|
* |
19 |
|
|
* You should have received a copy of the GNU General Public License |
20 |
|
|
* along with this program; if not, write to the Free Software |
21 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
22 |
|
|
*/ |
23 |
|
|
|
24 |
|
|
#include "sysdeps.h" |
25 |
|
|
|
26 |
|
|
#include <stdio.h> |
27 |
|
|
#include <stdlib.h> |
28 |
|
|
|
29 |
nigel |
1.3 |
#include <string> |
30 |
|
|
using std::string; |
31 |
|
|
|
32 |
nigel |
1.1 |
#include "prefs.h" |
33 |
|
|
|
34 |
|
|
|
35 |
|
|
// Platform-specific preferences items |
36 |
|
|
prefs_desc platform_prefs_items[] = { |
37 |
nigel |
1.3 |
#ifdef HAVE_SIGSEGV_SKIP_INSTRUCTION |
38 |
|
|
{"ignoresegv", TYPE_BOOLEAN, false, "ignore illegal memory accesses"}, |
39 |
|
|
#endif |
40 |
nigel |
1.1 |
{NULL, TYPE_END, false, NULL} // End of list |
41 |
|
|
}; |
42 |
|
|
|
43 |
|
|
|
44 |
|
|
// Prefs file name and path |
45 |
|
|
const char PREFS_FILE_NAME[] = ".basilisk_ii_prefs"; |
46 |
nigel |
1.3 |
string UserPrefsPath; |
47 |
|
|
static string prefs_path; |
48 |
nigel |
1.1 |
|
49 |
|
|
|
50 |
|
|
/* |
51 |
|
|
* Load preferences from settings file |
52 |
|
|
*/ |
53 |
|
|
|
54 |
|
|
void LoadPrefs(void) |
55 |
|
|
{ |
56 |
|
|
// Construct prefs path |
57 |
nigel |
1.3 |
if (UserPrefsPath.empty()) { |
58 |
|
|
char *home = getenv("HOME"); |
59 |
|
|
if (home) |
60 |
|
|
prefs_path = string(home) + '/'; |
61 |
|
|
prefs_path += PREFS_FILE_NAME; |
62 |
|
|
UserPrefsPath = prefs_path; |
63 |
|
|
} else |
64 |
|
|
prefs_path = UserPrefsPath; |
65 |
nigel |
1.1 |
|
66 |
|
|
// Read preferences from settings file |
67 |
nigel |
1.3 |
FILE *f = fopen(prefs_path.c_str(), "r"); |
68 |
nigel |
1.1 |
if (f != NULL) { |
69 |
|
|
|
70 |
|
|
// Prefs file found, load settings |
71 |
|
|
LoadPrefsFromStream(f); |
72 |
|
|
fclose(f); |
73 |
|
|
|
74 |
|
|
} else { |
75 |
|
|
|
76 |
|
|
// No prefs file, save defaults |
77 |
|
|
SavePrefs(); |
78 |
nigel |
1.6 |
} |
79 |
|
|
|
80 |
nigel |
1.8 |
// Remove Nigel's bad old serial prefs |
81 |
nigel |
1.6 |
|
82 |
|
|
const char *str; |
83 |
|
|
int tmp = 0; |
84 |
|
|
|
85 |
|
|
if ( (str = PrefsFindString("seriala") ) != NULL |
86 |
|
|
&& strcmp(str, "/dev/ttys0") == 0 ) |
87 |
|
|
{ |
88 |
|
|
puts("Deleting invalid prefs item 'seriala /dev/ttys0'"); |
89 |
nigel |
1.7 |
PrefsRemoveItem("seriala", 1); |
90 |
nigel |
1.6 |
} |
91 |
|
|
|
92 |
|
|
if ( (str = PrefsFindString("serialb") ) != NULL |
93 |
|
|
&& strcmp(str, "/dev/ttys1") == 0 ) |
94 |
|
|
{ |
95 |
|
|
puts("Deleting invalid prefs item 'serialb /dev/ttys1'"); |
96 |
nigel |
1.7 |
PrefsRemoveItem("serialb", 1); |
97 |
nigel |
1.1 |
} |
98 |
nigel |
1.8 |
|
99 |
|
|
// Floppy & cdrom prefs are always removed - |
100 |
|
|
// we search for them each time the emulator is started |
101 |
|
|
|
102 |
|
|
while ( (str = PrefsFindString("floppy", tmp) ) != NULL ) |
103 |
|
|
PrefsRemoveItem("floppy", tmp); |
104 |
|
|
|
105 |
|
|
while ( (str = PrefsFindString("cdrom", tmp) ) != NULL ) |
106 |
|
|
PrefsRemoveItem("cdrom", tmp); |
107 |
nigel |
1.1 |
} |
108 |
|
|
|
109 |
|
|
|
110 |
|
|
/* |
111 |
|
|
* Save preferences to settings file |
112 |
|
|
*/ |
113 |
|
|
|
114 |
|
|
void SavePrefs(void) |
115 |
|
|
{ |
116 |
|
|
FILE *f; |
117 |
nigel |
1.3 |
if ((f = fopen(prefs_path.c_str(), "w")) != NULL) { |
118 |
nigel |
1.1 |
SavePrefsToStream(f); |
119 |
|
|
fclose(f); |
120 |
|
|
} |
121 |
|
|
} |
122 |
|
|
|
123 |
|
|
|
124 |
|
|
/* |
125 |
|
|
* Add defaults of platform-specific prefs items |
126 |
|
|
* You may also override the defaults set in PrefsInit() |
127 |
|
|
*/ |
128 |
|
|
|
129 |
|
|
void AddPlatformPrefsDefaults(void) |
130 |
|
|
{ |
131 |
nigel |
1.4 |
PrefsReplaceString("extfs", getenv("HOME")); |
132 |
nigel |
1.2 |
PrefsReplaceString("screen", "win/512/384/16"); |
133 |
nigel |
1.3 |
#ifdef HAVE_SIGSEGV_SKIP_INSTRUCTION |
134 |
|
|
PrefsAddBool("ignoresegv", false); |
135 |
|
|
#endif |
136 |
nigel |
1.1 |
} |