-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
251 lines (215 loc) · 7.39 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
/*
* main.c - VICE main startup entry.
*
* Written by
* Ettore Perazzoli <ettore@comm2000.it>
* Teemu Rantanen <tvr@cs.hut.fi>
* Vesa-Matti Puro <vmp@lut.fi>
* Jarkko Sonninen <sonninen@lut.fi>
* Jouko Valta <jopi@stekt.oulu.fi>
* André Fachat <a.fachat@physik.tu-chemnitz.de>
* Andreas Boose <viceteam@t-online.de>
*
* This file is part of VICE, the Versatile Commodore Emulator.
* See README for copyright notice.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA.
*
*/
#include "vice.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef ENABLE_NLS
#include <locale.h>
#endif
#include "archdep.h"
#include "cmdline.h"
#include "console.h"
#include "debug.h"
#include "drive.h"
#include "fullscreen.h"
#include "gfxoutput.h"
#include "init.h"
#include "initcmdline.h"
#ifdef HAS_TRANSLATION
#include "intl.h"
#endif
#include "lib.h"
#include "log.h"
#include "machine.h"
#include "maincpu.h"
#include "main.h"
#include "resources.h"
#include "sysfile.h"
#ifdef HAS_TRANSLATION
#include "translate.h"
#endif
#include "types.h"
#include "uiapi.h"
#include "version.h"
#include "video.h"
int vsid_mode = 0;
#ifdef __OS2__
const
#endif
int console_mode = 0;
int video_disabled_mode = 0;
static int init_done;
/* ------------------------------------------------------------------------- */
/* This is the main program entry point. Call this from `main()'. */
int main_program(int argc, char **argv)
{
int i;
char *program_name;
/* Check for -config, -console and -vsid before initializing the user interface.
-config => use specified configuration file
-console => no user interface
-vsid => user interface in separate process */
for (i = 0; i < argc; i++) {
#ifndef __OS2__
if (strcmp(argv[i], "-console") == 0) {
console_mode = 1;
video_disabled_mode = 1;
} else
#endif
if (strcmp(argv[i], "-vsid") == 0) {
vsid_mode = 1;
#ifndef USE_SDLUI
video_disabled_mode = 1;
#endif
} else if (strcmp(argv[i], "-config") == 0) {
if ((i+1) < argc) {
vice_config_file = lib_stralloc(argv[++i]);
}
} else if (strcmp(argv[i], "-model") == 0 &&
(machine_class == VICE_MACHINE_CBM5x0 ||
machine_class == VICE_MACHINE_CBM6x0)) {
if ((i+1) < argc) {
machine_class = (atoi(argv[++i]) == 510) ? VICE_MACHINE_CBM5x0 : VICE_MACHINE_CBM6x0;
}
} else if (strcmp(argv[i], "-modelline") == 0 &&
(machine_class == VICE_MACHINE_CBM5x0 ||
machine_class == VICE_MACHINE_CBM6x0)) {
if ((i+1) < argc) {
machine_class = (atoi(argv[++i]) == 2) ? VICE_MACHINE_CBM5x0 : VICE_MACHINE_CBM6x0;
}
}
}
#ifdef ENABLE_NLS
/* gettext stuff, not needed in Gnome, but here I can
overrule the default locale path */
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, NLS_LOCALEDIR);
textdomain(PACKAGE);
#endif
archdep_init(&argc, argv);
#ifndef __riscos
if (atexit(main_exit) < 0) {
archdep_startup_log_error("atexit");
return -1;
}
#endif
maincpu_early_init();
machine_setup_context();
drive_setup_context();
machine_early_init();
/* Initialize system file locator. */
sysfile_init(machine_name);
gfxoutput_early_init();
if (init_resources() < 0 || init_cmdline_options() < 0)
return -1;
/* Set factory defaults. */
if (resources_set_defaults() < 0) {
archdep_startup_log_error("Cannot set defaults.\n");
return -1;
}
/* Initialize the user interface. `ui_init()' might need to handle the
command line somehow, so we call it before parsing the options.
(e.g. under X11, the `-display' option is handled independently). */
if (!console_mode && ui_init(&argc, argv) < 0) {
archdep_startup_log_error("Cannot initialize the UI.\n");
return -1;
}
#ifdef HAS_TRANSLATION
/* set the default arch language */
translate_arch_language_init();
#endif
/* Load the user's default configuration file. */
if (vsid_mode) {
resources_set_int("Drive8Type", 0);
resources_set_int("Sound", 1);
#ifdef HAVE_RESID
/* FIXME: Use `SID_ENGINE_RESID'. */
resources_set_int("SidEngine", 1);
#endif
resources_set_int("SidModel", 0);
resources_set_int("SidFilters", 1);
resources_set_int("SoundSampleRate", 44100);
resources_set_int("SoundSpeedAdjustment", 2);
resources_set_int("SoundBufferSize", 1000);
resources_set_int("SoundSuspendTime", 0);
} else {
int retval;
retval = resources_load(NULL);
if (retval < 0) {
/* The resource file might contain errors, and thus certain
resources might have been initialized anyway. */
if (resources_set_defaults() < 0) {
archdep_startup_log_error("Cannot set defaults.\n");
return -1;
}
}
}
if (log_init() < 0)
archdep_startup_log_error("Cannot startup logging system.\n");
if (initcmdline_check_args(argc, argv) < 0)
return -1;
program_name = archdep_program_name();
/* VICE boot sequence. */
log_message(LOG_DEFAULT, "*** VICE Version %s ***", VERSION);
log_message(LOG_DEFAULT, " ");
log_message(LOG_DEFAULT, "Welcome to %s, the free portable %s Emulator.",
program_name, machine_name);
log_message(LOG_DEFAULT, " ");
log_message(LOG_DEFAULT, "Current VICE team members:");
log_message(LOG_DEFAULT, "A. Boose, D. Lem, T. Biczo, A. Dehmel, T. Bretz, A. Matthies,");
log_message(LOG_DEFAULT, "M. Pottendorfer, M. Brenner, S. Trikaliotis, M. van den Heuvel,");
log_message(LOG_DEFAULT, "C. Vogelgsang, F. Gennari, M. Kiesel, H. Nuotio, D. Kahlin,");
log_message(LOG_DEFAULT, "A. Lankila.");
log_message(LOG_DEFAULT, " ");
log_message(LOG_DEFAULT, "This is free software with ABSOLUTELY NO WARRANTY.");
log_message(LOG_DEFAULT, "See the \"About VICE\" command for more info.");
log_message(LOG_DEFAULT, " ");
lib_free(program_name);
/* Complete the GUI initialization (after loading the resources and
parsing the command-line) if necessary. */
if (!console_mode && ui_init_finish() < 0)
return -1;
if (!console_mode && video_init() < 0)
return -1;
if (initcmdline_check_psid() < 0)
return -1;
if (init_main() < 0)
return -1;
initcmdline_check_attach();
init_done = 1;
/* Let's go... */
log_message(LOG_DEFAULT, "Main CPU: starting at ($FFFC).");
maincpu_mainloop();
log_error(LOG_DEFAULT, "perkele!");
return 0;
}