1 |
nigel |
1.1 |
/* |
2 |
nigel |
1.12 |
* $Id: prefs_macosx.cpp,v 1.11 2008/01/01 09:40:32 gbeauche 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 |
gbeauche |
1.11 |
* Basilisk II (C) 1997-2008 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 |
gbeauche |
1.10 |
{"idlewait", TYPE_BOOLEAN, false, "sleep when idle"}, |
41 |
nigel |
1.1 |
{NULL, TYPE_END, false, NULL} // End of list |
42 |
|
|
}; |
43 |
|
|
|
44 |
|
|
|
45 |
|
|
// Prefs file name and path |
46 |
|
|
const char PREFS_FILE_NAME[] = ".basilisk_ii_prefs"; |
47 |
nigel |
1.3 |
string UserPrefsPath; |
48 |
|
|
static string prefs_path; |
49 |
nigel |
1.1 |
|
50 |
|
|
|
51 |
|
|
/* |
52 |
|
|
* Load preferences from settings file |
53 |
|
|
*/ |
54 |
|
|
|
55 |
nigel |
1.12 |
void LoadPrefs(const char *vmdir) |
56 |
nigel |
1.1 |
{ |
57 |
nigel |
1.12 |
if (vmdir) { |
58 |
|
|
prefs_path = string(vmdir) + '/' + string("prefs"); |
59 |
|
|
FILE *prefs = fopen(prefs_path.c_str(), "r"); |
60 |
|
|
if (!prefs) { |
61 |
|
|
printf("No file at %s found.\n", prefs_path.c_str()); |
62 |
|
|
exit(1); |
63 |
|
|
} |
64 |
|
|
LoadPrefsFromStream(prefs); |
65 |
|
|
fclose(prefs); |
66 |
|
|
return; |
67 |
|
|
} |
68 |
|
|
|
69 |
nigel |
1.1 |
// Construct prefs path |
70 |
nigel |
1.3 |
if (UserPrefsPath.empty()) { |
71 |
|
|
char *home = getenv("HOME"); |
72 |
|
|
if (home) |
73 |
|
|
prefs_path = string(home) + '/'; |
74 |
|
|
prefs_path += PREFS_FILE_NAME; |
75 |
|
|
UserPrefsPath = prefs_path; |
76 |
|
|
} else |
77 |
|
|
prefs_path = UserPrefsPath; |
78 |
nigel |
1.1 |
|
79 |
|
|
// Read preferences from settings file |
80 |
nigel |
1.3 |
FILE *f = fopen(prefs_path.c_str(), "r"); |
81 |
nigel |
1.1 |
if (f != NULL) { |
82 |
|
|
|
83 |
|
|
// Prefs file found, load settings |
84 |
|
|
LoadPrefsFromStream(f); |
85 |
|
|
fclose(f); |
86 |
|
|
|
87 |
|
|
} else { |
88 |
|
|
|
89 |
|
|
// No prefs file, save defaults |
90 |
|
|
SavePrefs(); |
91 |
nigel |
1.6 |
} |
92 |
|
|
|
93 |
nigel |
1.8 |
// Remove Nigel's bad old serial prefs |
94 |
nigel |
1.6 |
|
95 |
|
|
const char *str; |
96 |
|
|
int tmp = 0; |
97 |
|
|
|
98 |
|
|
if ( (str = PrefsFindString("seriala") ) != NULL |
99 |
|
|
&& strcmp(str, "/dev/ttys0") == 0 ) |
100 |
|
|
{ |
101 |
|
|
puts("Deleting invalid prefs item 'seriala /dev/ttys0'"); |
102 |
nigel |
1.7 |
PrefsRemoveItem("seriala", 1); |
103 |
nigel |
1.6 |
} |
104 |
|
|
|
105 |
|
|
if ( (str = PrefsFindString("serialb") ) != NULL |
106 |
|
|
&& strcmp(str, "/dev/ttys1") == 0 ) |
107 |
|
|
{ |
108 |
|
|
puts("Deleting invalid prefs item 'serialb /dev/ttys1'"); |
109 |
nigel |
1.7 |
PrefsRemoveItem("serialb", 1); |
110 |
nigel |
1.1 |
} |
111 |
nigel |
1.8 |
|
112 |
|
|
// Floppy & cdrom prefs are always removed - |
113 |
|
|
// we search for them each time the emulator is started |
114 |
|
|
|
115 |
|
|
while ( (str = PrefsFindString("floppy", tmp) ) != NULL ) |
116 |
|
|
PrefsRemoveItem("floppy", tmp); |
117 |
|
|
|
118 |
|
|
while ( (str = PrefsFindString("cdrom", tmp) ) != NULL ) |
119 |
|
|
PrefsRemoveItem("cdrom", tmp); |
120 |
nigel |
1.1 |
} |
121 |
|
|
|
122 |
|
|
|
123 |
|
|
/* |
124 |
|
|
* Save preferences to settings file |
125 |
|
|
*/ |
126 |
|
|
|
127 |
|
|
void SavePrefs(void) |
128 |
|
|
{ |
129 |
|
|
FILE *f; |
130 |
nigel |
1.3 |
if ((f = fopen(prefs_path.c_str(), "w")) != NULL) { |
131 |
nigel |
1.1 |
SavePrefsToStream(f); |
132 |
|
|
fclose(f); |
133 |
|
|
} |
134 |
|
|
} |
135 |
|
|
|
136 |
|
|
|
137 |
|
|
/* |
138 |
|
|
* Add defaults of platform-specific prefs items |
139 |
|
|
* You may also override the defaults set in PrefsInit() |
140 |
|
|
*/ |
141 |
|
|
|
142 |
|
|
void AddPlatformPrefsDefaults(void) |
143 |
|
|
{ |
144 |
nigel |
1.4 |
PrefsReplaceString("extfs", getenv("HOME")); |
145 |
nigel |
1.2 |
PrefsReplaceString("screen", "win/512/384/16"); |
146 |
nigel |
1.3 |
#ifdef HAVE_SIGSEGV_SKIP_INSTRUCTION |
147 |
|
|
PrefsAddBool("ignoresegv", false); |
148 |
|
|
#endif |
149 |
gbeauche |
1.10 |
PrefsAddBool("idlewait", true); |
150 |
nigel |
1.1 |
} |