1 /*
2 * init.c - General initialization.
3 *
4 * Written by
5 * Andreas Boose <viceteam@t-online.de>
6 * Ettore Perazzoli <ettore@comm2000.it>
7 *
8 * This file is part of VICE, the Versatile Commodore Emulator.
9 * See README for copyright notice.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
24 * 02111-1307 USA.
25 *
26 */
27
28 #include "vice.h"
29
30 #include "archdep.h"
31 #include "attach.h"
32 #include "cmdline.h"
33 #include "console.h"
34 #include "debug.h"
35 #include "drive.h"
36 #include "initcmdline.h"
37 #include "keyboard.h"
38 #include "log.h"
39 #include "machine-bus.h"
40 #include "machine-video.h"
41 #include "machine.h"
42 #include "maincpu.h"
43 #include "monitor.h"
44 #ifdef HAVE_NETWORK
45 #include "monitor_binary.h"
46 #include "monitor_network.h"
47 #endif
48 #include "palette.h"
49 #include "ram.h"
50 #include "resources.h"
51 #include "romset.h"
52 #include "screenshot.h"
53 #include "signals.h"
54 #include "sysfile.h"
55 #include "uiapi.h"
56 #include "vdrive.h"
57 #include "video.h"
58 #include "vsync.h"
59
60 #include "init.h"
61
62 /* #define DBGINIT */
63
64 #ifdef DBGINIT
65 #define DBG(x) printf x
66 #else
67 #define DBG(x)
68 #endif
69
init_resource_fail(const char * module)70 void init_resource_fail(const char *module)
71 {
72 archdep_startup_log_error("Cannot initialize %s resources.\n",
73 module);
74 }
75
init_resources(void)76 int init_resources(void)
77 {
78 DBG(("init_resources\n"));
79 if (resources_init(machine_get_name())) {
80 archdep_startup_log_error("Cannot initialize resource handling.\n");
81 return -1;
82 }
83 if (log_resources_init() < 0) {
84 init_resource_fail("log");
85 return -1;
86 }
87 if (sysfile_resources_init() < 0) {
88 init_resource_fail("system file locator");
89 return -1;
90 }
91 if (romset_resources_init() < 0) {
92 init_resource_fail("romset");
93 return -1;
94 }
95 if (ui_resources_init() < 0) {
96 init_resource_fail("UI");
97 return -1;
98 }
99 if (machine_common_resources_init() < 0) {
100 init_resource_fail("machine common");
101 return -1;
102 }
103 if (vsync_resources_init() < 0) {
104 init_resource_fail("vsync");
105 return -1;
106 }
107 if (sound_resources_init() < 0) {
108 init_resource_fail("sound");
109 return -1;
110 }
111 if (keyboard_resources_init() < 0) {
112 init_resource_fail("keyboard");
113 return -1;
114 }
115 if (machine_video_resources_init() < 0) {
116 init_resource_fail("machine video");
117 return -1;
118 }
119 if (machine_resources_init() < 0) {
120 init_resource_fail("machine");
121 return -1;
122 }
123 if (ram_resources_init() < 0) {
124 init_resource_fail("RAM");
125 return -1;
126 }
127 if (monitor_resources_init() < 0) {
128 init_resource_fail("monitor");
129 return -1;
130 }
131 #ifdef HAVE_NETWORK
132 if (monitor_network_resources_init() < 0) {
133 init_resource_fail("MONITOR_NETWORK");
134 return -1;
135 }
136 if (monitor_binary_resources_init() < 0) {
137 init_resource_fail("MONITOR_BINARY");
138 return -1;
139 }
140 #endif
141 return 0;
142 }
143
init_cmdline_options_fail(const char * module)144 void init_cmdline_options_fail(const char *module)
145 {
146 archdep_startup_log_error("Cannot initialize %s command-line options.\n",
147 module);
148 }
149
init_cmdline_options(void)150 int init_cmdline_options(void)
151 {
152 if (cmdline_init()) {
153 archdep_startup_log_error("Cannot initialize command-line handling.\n");
154 return -1;
155 }
156 if (log_cmdline_options_init() < 0) {
157 init_cmdline_options_fail("log");
158 return -1;
159 }
160 if (initcmdline_init() < 0) {
161 init_cmdline_options_fail("main");
162 return -1;
163 }
164 if (sysfile_cmdline_options_init() < 0) {
165 init_cmdline_options_fail("system file locator");
166 return -1;
167 }
168 if (!video_disabled_mode && ui_cmdline_options_init() < 0) {
169 init_cmdline_options_fail("UI");
170 return -1;
171 }
172 if (machine_class != VICE_MACHINE_VSID) {
173 if (romset_cmdline_options_init() < 0) {
174 init_cmdline_options_fail("romset");
175 return -1;
176 }
177 }
178 if (monitor_cmdline_options_init() < 0) {
179 init_cmdline_options_fail("monitor");
180 return -1;
181 }
182 if (machine_common_cmdline_options_init() < 0) {
183 init_cmdline_options_fail("machine common");
184 return -1;
185 }
186 if (vsync_cmdline_options_init() < 0) {
187 init_cmdline_options_fail("vsync");
188 return -1;
189 }
190 if (sound_cmdline_options_init() < 0) {
191 init_cmdline_options_fail("sound");
192 return -1;
193 }
194 if (keyboard_cmdline_options_init() < 0) {
195 init_cmdline_options_fail("keyboard");
196 return -1;
197 }
198 if (video_cmdline_options_init() < 0) {
199 init_cmdline_options_fail("video");
200 return -1;
201 }
202 if (machine_cmdline_options_init() < 0) {
203 init_cmdline_options_fail("machine");
204 return -1;
205 }
206
207 if (machine_class != VICE_MACHINE_VSID) {
208 if (ram_cmdline_options_init() < 0) {
209 init_cmdline_options_fail("RAM");
210 return -1;
211 }
212 }
213 #ifdef HAVE_NETWORK
214 if (monitor_network_cmdline_options_init() < 0) {
215 init_cmdline_options_fail("MONITOR_NETWORK");
216 return -1;
217 }
218 if (monitor_binary_cmdline_options_init() < 0) {
219 init_cmdline_options_fail("MONITOR_BINARY");
220 return -1;
221 }
222 #endif
223 return 0;
224 }
225
init_main(void)226 int init_main(void)
227 {
228 #ifdef __IBMC__
229 signals_init(0);
230 #else
231 signals_init(debug.do_core_dumps);
232 #endif
233
234 romset_init();
235
236 if (!video_disabled_mode) {
237 palette_init();
238 }
239
240 if (machine_class != VICE_MACHINE_VSID) {
241 screenshot_init();
242
243 drive_cpu_early_init_all();
244 }
245
246 machine_bus_init();
247 machine_maincpu_init();
248
249 /* Machine-specific initialization. */
250 if (machine_init() < 0) {
251 log_error(LOG_DEFAULT, "Machine initialization failed.");
252 return -1;
253 }
254
255 /* FIXME: what's about uimon_init??? */
256 /* the monitor console MUST be available, because of for example cpujam,
257 or -initbreak from cmdline.
258 */
259 if (console_init() < 0) {
260 log_error(LOG_DEFAULT, "Console initialization failed.");
261 return -1;
262 }
263
264 keyboard_init();
265
266 if (machine_class != VICE_MACHINE_VSID) {
267 vdrive_init();
268 }
269
270 ui_init_finalize();
271
272 return 0;
273 }
274