1 |
/* |
2 |
* main_x.h - Main program, Unix specific stuff |
3 |
* |
4 |
* Frodo (C) 1994-1997,2002-2005 Christian Bauer |
5 |
* |
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 |
#ifdef HAVE_GLADE |
24 |
#include <gnome.h> |
25 |
#endif |
26 |
|
27 |
// Qtopia Windowing System |
28 |
#ifdef QTOPIA |
29 |
extern "C" int main(int argc, char *argv[]); |
30 |
#include <SDL.h> |
31 |
#endif |
32 |
|
33 |
extern int init_graphics(void); |
34 |
|
35 |
|
36 |
// Global variables |
37 |
char Frodo::prefs_path[256] = ""; |
38 |
|
39 |
|
40 |
/* |
41 |
* Create application object and start it |
42 |
*/ |
43 |
|
44 |
int main(int argc, char **argv) |
45 |
{ |
46 |
#ifdef HAVE_GLADE |
47 |
gnome_program_init(PACKAGE_NAME, PACKAGE_VERSION, LIBGNOMEUI_MODULE, argc, argv, |
48 |
GNOME_PARAM_APP_DATADIR, DATADIR, NULL); |
49 |
#endif |
50 |
|
51 |
timeval tv; |
52 |
gettimeofday(&tv, NULL); |
53 |
srand(tv.tv_usec); |
54 |
|
55 |
#ifndef HAVE_GLADE |
56 |
printf( |
57 |
"%s Copyright (C) 1994-1997,2002-2005 Christian Bauer\n" |
58 |
"This is free software with ABSOLUTELY NO WARRANTY.\n" |
59 |
, VERSION_STRING |
60 |
); |
61 |
#endif |
62 |
if (!init_graphics()) |
63 |
return 1; |
64 |
fflush(stdout); |
65 |
|
66 |
Frodo *the_app = new Frodo(); |
67 |
the_app->ArgvReceived(argc, argv); |
68 |
the_app->ReadyToRun(); |
69 |
delete the_app; |
70 |
|
71 |
return 0; |
72 |
} |
73 |
|
74 |
|
75 |
/* |
76 |
* Constructor: Initialize member variables |
77 |
*/ |
78 |
|
79 |
Frodo::Frodo() |
80 |
{ |
81 |
TheC64 = NULL; |
82 |
} |
83 |
|
84 |
|
85 |
/* |
86 |
* Process command line arguments |
87 |
*/ |
88 |
|
89 |
void Frodo::ArgvReceived(int argc, char **argv) |
90 |
{ |
91 |
if (argc == 2) |
92 |
strncpy(prefs_path, argv[1], 255); |
93 |
} |
94 |
|
95 |
|
96 |
/* |
97 |
* Arguments processed, run emulation |
98 |
*/ |
99 |
|
100 |
void Frodo::ReadyToRun(void) |
101 |
{ |
102 |
getcwd(AppDirPath, 256); |
103 |
|
104 |
// Load preferences |
105 |
if (!prefs_path[0]) { |
106 |
char *home = getenv("HOME"); |
107 |
if (home != NULL && strlen(home) < 240) { |
108 |
strncpy(prefs_path, home, 200); |
109 |
strcat(prefs_path, "/"); |
110 |
} |
111 |
strcat(prefs_path, ".frodorc"); |
112 |
} |
113 |
ThePrefs.Load(prefs_path); |
114 |
|
115 |
// Show preferences editor |
116 |
#ifdef HAVE_GLADE |
117 |
if (!ThePrefs.ShowEditor(true, prefs_path)) |
118 |
return; |
119 |
#endif |
120 |
|
121 |
// Create and start C64 |
122 |
TheC64 = new C64; |
123 |
load_rom_files(); |
124 |
TheC64->Run(); |
125 |
delete TheC64; |
126 |
} |
127 |
|
128 |
|
129 |
Prefs *Frodo::reload_prefs(void) |
130 |
{ |
131 |
static Prefs newprefs; |
132 |
newprefs.Load(prefs_path); |
133 |
return &newprefs; |
134 |
} |
135 |
|
136 |
|
137 |
/* |
138 |
* Determine whether path name refers to a directory |
139 |
*/ |
140 |
|
141 |
bool IsDirectory(const char *path) |
142 |
{ |
143 |
struct stat st; |
144 |
return stat(path, &st) == 0 && S_ISDIR(st.st_mode); |
145 |
} |