ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/Frodo4/Src/main_x.h
Revision: 1.11
Committed: 2010-04-21T22:03:44Z (14 years, 7 months ago) by cebix
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.10: +22 -12 lines
Log Message:
adaptations for Gtk prefs editor

File Contents

# User Rev Content
1 cebix 1.1 /*
2     * main_x.h - Main program, Unix specific stuff
3     *
4 cebix 1.11 * Frodo Copyright (C) Christian Bauer
5 cebix 1.1 *
6     * This program is free software; you can redistribute it and/or modify
7     * it under the terms of the GNU General Public License as published by
8     * the Free Software Foundation; either version 2 of the License, or
9     * (at your option) any later version.
10     *
11     * This program is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with this program; if not, write to the Free Software
18     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19     */
20    
21     #include "Version.h"
22    
23 cebix 1.5 #ifdef HAVE_GLADE
24     #include <gnome.h>
25     #endif
26    
27 cebix 1.8 // Qtopia Windowing System
28 berlac 1.10 #ifdef QTOPIA
29 cebix 1.7 extern "C" int main(int argc, char *argv[]);
30     #include <SDL.h>
31     #endif
32 cebix 1.1
33     extern int init_graphics(void);
34    
35    
36     // Global variables
37 cebix 1.11 Frodo *TheApp = NULL;
38 cebix 1.1 char Frodo::prefs_path[256] = "";
39    
40    
41     /*
42     * Create application object and start it
43     */
44    
45     int main(int argc, char **argv)
46     {
47 cebix 1.5 #ifdef HAVE_GLADE
48     gnome_program_init(PACKAGE_NAME, PACKAGE_VERSION, LIBGNOMEUI_MODULE, argc, argv,
49     GNOME_PARAM_APP_DATADIR, DATADIR, NULL);
50     #endif
51 cebix 1.1
52     timeval tv;
53     gettimeofday(&tv, NULL);
54     srand(tv.tv_usec);
55    
56 cebix 1.8 #ifndef HAVE_GLADE
57     printf(
58 cebix 1.11 "%s Copyright (C) Christian Bauer\n"
59 cebix 1.8 "This is free software with ABSOLUTELY NO WARRANTY.\n"
60     , VERSION_STRING
61     );
62     #endif
63 cebix 1.1 if (!init_graphics())
64 cebix 1.5 return 1;
65 cebix 1.1 fflush(stdout);
66    
67 cebix 1.11 TheApp = new Frodo();
68     TheApp->ArgvReceived(argc, argv);
69     TheApp->ReadyToRun();
70     delete TheApp;
71 cebix 1.1
72     return 0;
73     }
74    
75    
76     /*
77     * Constructor: Initialize member variables
78     */
79    
80     Frodo::Frodo()
81     {
82     TheC64 = NULL;
83     }
84    
85    
86     /*
87     * Process command line arguments
88     */
89    
90     void Frodo::ArgvReceived(int argc, char **argv)
91     {
92     if (argc == 2)
93     strncpy(prefs_path, argv[1], 255);
94     }
95    
96    
97     /*
98     * Arguments processed, run emulation
99     */
100    
101 cebix 1.11 void Frodo::ReadyToRun()
102 cebix 1.1 {
103     getcwd(AppDirPath, 256);
104    
105     // Load preferences
106     if (!prefs_path[0]) {
107     char *home = getenv("HOME");
108     if (home != NULL && strlen(home) < 240) {
109     strncpy(prefs_path, home, 200);
110     strcat(prefs_path, "/");
111     }
112     strcat(prefs_path, ".frodorc");
113     }
114     ThePrefs.Load(prefs_path);
115    
116 cebix 1.5 // Show preferences editor
117 cebix 1.7 #ifdef HAVE_GLADE
118     if (!ThePrefs.ShowEditor(true, prefs_path))
119 cebix 1.11 return; // "Quit" clicked
120 cebix 1.7 #endif
121 cebix 1.5
122 cebix 1.7 // Create and start C64
123     TheC64 = new C64;
124     load_rom_files();
125     TheC64->Run();
126     delete TheC64;
127 cebix 1.1 }
128    
129    
130 cebix 1.11 /*
131     * Run preferences editor
132     */
133    
134     bool Frodo::RunPrefsEditor(void)
135 cebix 1.1 {
136 cebix 1.11 Prefs *prefs = new Prefs(ThePrefs);
137     bool result = prefs->ShowEditor(false, prefs_path);
138     if (result) {
139     TheC64->NewPrefs(prefs);
140     ThePrefs = *prefs;
141     }
142     delete prefs;
143     return result;
144 cebix 1.1 }
145 cebix 1.6
146    
147     /*
148     * Determine whether path name refers to a directory
149     */
150    
151     bool IsDirectory(const char *path)
152     {
153     struct stat st;
154     return stat(path, &st) == 0 && S_ISDIR(st.st_mode);
155     }