ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/MacOSX/prefs_macosx.cpp
Revision: 1.10
Committed: 2007-06-13T16:11:31Z (17 years, 4 months ago) by gbeauche
Branch: MAIN
Changes since 1.9: +3 -1 lines
Log Message:
Handle "idlewait" option.

File Contents

# User Rev Content
1 nigel 1.1 /*
2 gbeauche 1.10 * $Id: prefs_macosx.cpp,v 1.9 2005/01/30 21:42:13 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.9 * Basilisk II (C) 1997-2005 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     void LoadPrefs(void)
56     {
57     // Construct prefs path
58 nigel 1.3 if (UserPrefsPath.empty()) {
59     char *home = getenv("HOME");
60     if (home)
61     prefs_path = string(home) + '/';
62     prefs_path += PREFS_FILE_NAME;
63     UserPrefsPath = prefs_path;
64     } else
65     prefs_path = UserPrefsPath;
66 nigel 1.1
67     // Read preferences from settings file
68 nigel 1.3 FILE *f = fopen(prefs_path.c_str(), "r");
69 nigel 1.1 if (f != NULL) {
70    
71     // Prefs file found, load settings
72     LoadPrefsFromStream(f);
73     fclose(f);
74    
75     } else {
76    
77     // No prefs file, save defaults
78     SavePrefs();
79 nigel 1.6 }
80    
81 nigel 1.8 // Remove Nigel's bad old serial prefs
82 nigel 1.6
83     const char *str;
84     int tmp = 0;
85    
86     if ( (str = PrefsFindString("seriala") ) != NULL
87     && strcmp(str, "/dev/ttys0") == 0 )
88     {
89     puts("Deleting invalid prefs item 'seriala /dev/ttys0'");
90 nigel 1.7 PrefsRemoveItem("seriala", 1);
91 nigel 1.6 }
92    
93     if ( (str = PrefsFindString("serialb") ) != NULL
94     && strcmp(str, "/dev/ttys1") == 0 )
95     {
96     puts("Deleting invalid prefs item 'serialb /dev/ttys1'");
97 nigel 1.7 PrefsRemoveItem("serialb", 1);
98 nigel 1.1 }
99 nigel 1.8
100     // Floppy & cdrom prefs are always removed -
101     // we search for them each time the emulator is started
102    
103     while ( (str = PrefsFindString("floppy", tmp) ) != NULL )
104     PrefsRemoveItem("floppy", tmp);
105    
106     while ( (str = PrefsFindString("cdrom", tmp) ) != NULL )
107     PrefsRemoveItem("cdrom", tmp);
108 nigel 1.1 }
109    
110    
111     /*
112     * Save preferences to settings file
113     */
114    
115     void SavePrefs(void)
116     {
117     FILE *f;
118 nigel 1.3 if ((f = fopen(prefs_path.c_str(), "w")) != NULL) {
119 nigel 1.1 SavePrefsToStream(f);
120     fclose(f);
121     }
122     }
123    
124    
125     /*
126     * Add defaults of platform-specific prefs items
127     * You may also override the defaults set in PrefsInit()
128     */
129    
130     void AddPlatformPrefsDefaults(void)
131     {
132 nigel 1.4 PrefsReplaceString("extfs", getenv("HOME"));
133 nigel 1.2 PrefsReplaceString("screen", "win/512/384/16");
134 nigel 1.3 #ifdef HAVE_SIGSEGV_SKIP_INSTRUCTION
135     PrefsAddBool("ignoresegv", false);
136     #endif
137 gbeauche 1.10 PrefsAddBool("idlewait", true);
138 nigel 1.1 }