filename | src/main.c |
changeset | 1100:50e702af9373 |
prev | 1081:ef31ae97bb8b |
next | 1107:7b279d10f46f |
author | nkeynes |
date | Mon Feb 15 17:27:14 2010 +1000 (14 years ago) |
permissions | -rw-r--r-- |
last change | Hook up the fake bios boot Use fakebios if invoked with -b, or if there's no boot rom loaded |
view | annotate | diff | log | raw |
1 /**
2 * $Id$
3 *
4 * Main program, initializes dreamcast and gui, then passes control off to
5 * the main loop.
6 *
7 * Copyright (c) 2005 Nathan Keynes.
8 *
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 */
20 #include <stdlib.h>
21 #include <unistd.h>
22 #include <getopt.h>
23 #include "lxdream.h"
24 #include "lxpaths.h"
25 #include "gettext.h"
26 #include "mem.h"
27 #include "dreamcast.h"
28 #include "dream.h"
29 #include "display.h"
30 #include "gui.h"
31 #include "gdlist.h"
32 #include "syscall.h"
33 #include "loader.h"
34 #include "aica/audio.h"
35 #include "gdrom/gdrom.h"
36 #include "maple/maple.h"
37 #include "sh4/sh4.h"
38 #include "aica/armdasm.h"
39 #include "vmu/vmulist.h"
40 #include "serial.h"
41 #include "hotkeys.h"
42 #include "plugin.h"
44 char *option_list = "a:A:bc:dfg:G:hHl:m:npt:T:uvV:x?";
45 struct option longopts[] = {
46 { "aica", required_argument, NULL, 'a' },
47 { "audio", required_argument, NULL, 'A' },
48 { "biosless", no_argument, NULL, 'b' },
49 { "config", required_argument, NULL, 'c' },
50 { "debugger", no_argument, NULL, 'D' },
51 { "fullscreen", no_argument, NULL, 'f' },
52 { "gdb-sh4", required_argument, NULL, 'g' },
53 { "gdb-arm", required_argument, NULL, 'G' },
54 { "help", no_argument, NULL, 'h' },
55 { "headless", no_argument, NULL, 'H' },
56 { "log", required_argument, NULL,'l' },
57 { "multiplier", required_argument, NULL, 'm' },
58 { "run-time", required_argument, NULL, 't' },
59 { "trace", required_argument, NULL, 'T' },
60 { "unsafe", no_argument, NULL, 'u' },
61 { "video", no_argument, NULL, 'V' },
62 { "version", no_argument, NULL, 'v' },
63 { NULL, 0, 0, 0 } };
64 char *aica_program = NULL;
65 char *display_driver_name = NULL;
66 char *audio_driver_name = NULL;
67 char *trace_regions = NULL;
68 char *sh4_gdb_port = NULL;
69 char *arm_gdb_port = NULL;
70 gboolean start_immediately = FALSE;
71 gboolean no_start = FALSE;
72 gboolean headless = FALSE;
73 gboolean use_xlat = TRUE;
74 gboolean show_debugger = FALSE;
75 gboolean show_fullscreen = FALSE;
76 gboolean use_bootrom = TRUE;
77 extern uint32_t sh4_cpu_multiplier;
79 static void print_version()
80 {
81 printf( "lxdream %s\n", lxdream_full_version );
82 }
84 static void print_usage()
85 {
86 print_version();
87 printf( "Usage: lxdream %s [options] [disc-file] [program-file]\n\n", lxdream_full_version );
89 printf( "Options:\n" );
90 printf( " -a, --aica=PROGFILE %s\n", _("Run the AICA SPU only, with the supplied program") );
91 printf( " -A, --audio=DRIVER %s\n", _("Use the specified audio driver (? to list)") );
92 printf( " -b, --biosless %s\n", _("Run without the BIOS boot rom even if available") );
93 printf( " -c, --config=CONFFILE %s\n", _("Load configuration from CONFFILE") );
94 printf( " -d, --debugger %s\n", _("Start in debugger mode") );
95 printf( " -f, --fullscreen %s\n", _("Start in fullscreen mode") );
96 printf( " -g, --gdb-sh4=PORT %s\n", _("Start GDB remote server on PORT for SH4") );
97 printf( " -G, --gdb-arm=PORT %s\n", _("Start GDB remote server on PORT for ARM") );
98 printf( " -h, --help %s\n", _("Display this usage information") );
99 printf( " -H, --headless %s\n", _("Run in headless (no video) mode") );
100 printf( " -l, --log=LEVEL %s\n", _("Set the output log level") );
101 printf( " -m, --multiplier=SCALE %s\n", _("Set the SH4 multiplier (1.0 = fullspeed)") );
102 printf( " -n %s\n", _("Don't start running immediately") );
103 printf( " -p %s\n", _("Start running immediately on startup") );
104 printf( " -t, --run-time=SECONDS %s\n", _("Run for the specified number of seconds") );
105 printf( " -T, --trace=REGIONS %s\n", _("Output trace information for the named regions") );
106 printf( " -u, --unsafe %s\n", _("Allow unsafe dcload syscalls") );
107 printf( " -v, --version %s\n", _("Print the lxdream version string") );
108 printf( " -V, --video=DRIVER %s\n", _("Use the specified video driver (? to list)") );
109 printf( " -x %s\n", _("Disable the SH4 translator") );
110 }
112 static void bind_gettext_domain()
113 {
114 #ifdef ENABLE_NLS
115 bindtextdomain( PACKAGE, get_locale_path() );
116 textdomain(PACKAGE);
117 #endif
118 }
120 int main (int argc, char *argv[])
121 {
122 int opt;
123 double t;
124 gboolean display_ok;
125 uint32_t time_secs, time_nanos;
127 install_crash_handler();
128 bind_gettext_domain();
129 display_ok = gui_parse_cmdline(&argc, &argv);
131 while( (opt = getopt_long( argc, argv, option_list, longopts, NULL )) != -1 ) {
132 switch( opt ) {
133 case 'a': /* AICA only mode - argument is an AICA program */
134 aica_program = optarg;
135 break;
136 case 'A': /* Audio driver */
137 audio_driver_name = optarg;
138 break;
139 case 'b': /* No Boot rom */
140 use_bootrom = FALSE;
141 case 'c': /* Config file */
142 lxdream_set_config_filename(optarg);
143 break;
144 case 'd': /* Launch w/ debugger */
145 show_debugger = TRUE;
146 break;
147 case 'f':
148 show_fullscreen = TRUE;
149 break;
150 case 'g':
151 sh4_gdb_port = optarg;
152 break;
153 case 'G':
154 arm_gdb_port = optarg;
155 break;
156 case 'h': /* help */
157 case '?':
158 print_usage();
159 exit(0);
160 break;
161 case 'H': /* Headless - shorthand for -V null */
162 display_driver_name = "null";
163 break;
164 case 'l': /* Log verbosity */
165 if( !set_global_log_level(optarg) ) {
166 ERROR( "Unrecognized log level '%s'", optarg );
167 }
168 break;
169 case 'm': /* Set SH4 CPU clock multiplier (default 0.5) */
170 t = strtod(optarg, NULL);
171 sh4_cpu_multiplier = (int)(1000.0/t);
172 break;
173 case 'n': /* Don't start immediately */
174 no_start = TRUE;
175 start_immediately = FALSE;
176 break;
177 case 'p': /* Start immediately */
178 start_immediately = TRUE;
179 no_start = FALSE;
180 break;
181 case 't': /* Time limit + auto quit */
182 t = strtod(optarg, NULL);
183 time_secs = (uint32_t)t;
184 time_nanos = (int)((t - time_secs) * 1000000000);
185 dreamcast_set_run_time( time_secs, time_nanos );
186 dreamcast_set_exit_on_stop( TRUE );
187 break;
188 case 'T': /* trace regions */
189 trace_regions = optarg;
190 set_global_log_level("trace");
191 break;
192 case 'u': /* Allow unsafe dcload syscalls */
193 dcload_set_allow_unsafe(TRUE);
194 break;
195 case 'v':
196 print_version();
197 exit(0);
198 break;
199 case 'V': /* Video driver */
200 display_driver_name = optarg;
201 break;
202 case 'x': /* Disable translator */
203 use_xlat = FALSE;
204 break;
205 }
206 }
208 #ifdef ENABLE_SHARED
209 plugin_init();
210 #endif
212 lxdream_make_config_dir( );
213 lxdream_load_config( );
215 if( audio_driver_name != NULL && strcmp(audio_driver_name, "?") == 0 ) {
216 print_version();
217 print_audio_drivers(stdout);
218 exit(0);
219 }
221 if( display_driver_name != NULL && strcmp(display_driver_name,"?") == 0 ) {
222 print_version();
223 print_display_drivers(stdout);
224 exit(0);
225 }
227 gdrom_list_init();
228 vmulist_init();
230 if( aica_program == NULL ) {
231 dreamcast_init(use_bootrom);
232 } else {
233 dreamcast_configure_aica_only();
234 mem_load_block( aica_program, 0x00800000, 2048*1024 );
235 }
236 mem_set_trace( trace_regions, TRUE );
238 audio_init_driver( audio_driver_name );
240 headless = display_driver_name != NULL && strcasecmp( display_driver_name, "null" ) == 0;
241 if( headless ) {
242 display_set_driver( &display_null_driver );
243 } else {
244 gui_init(show_debugger, show_fullscreen);
246 display_driver_t display_driver = get_display_driver_by_name(display_driver_name);
247 if( display_driver == NULL ) {
248 ERROR( "Video driver '%s' not found, aborting.", display_driver_name );
249 exit(2);
250 } else if( display_set_driver( display_driver ) == FALSE ) {
251 ERROR( "Video driver '%s' failed to initialize (could not connect to display?)",
252 display_driver->name );
253 exit(2);
254 }
255 }
257 hotkeys_init();
258 serial_init();
260 maple_reattach_all();
261 INFO( "%s! ready...", APP_NAME );
263 for( ; optind < argc; optind++ ) {
264 gboolean ok = gdrom_mount_image(argv[optind]);
265 if( !ok ) {
266 ok = file_load_magic( argv[optind] );
267 }
268 if( !ok ) {
269 ERROR( "Unrecognized file '%s'", argv[optind] );
270 }
271 if( !no_start ) {
272 start_immediately = ok;
273 }
274 }
276 if( gdrom_get_current_disc() == NULL ) {
277 gchar *disc_file = lxdream_get_global_config_path_value( CONFIG_GDROM );
278 if( disc_file != NULL ) {
279 gdrom_mount_image( disc_file );
280 g_free(disc_file);
281 }
282 }
284 sh4_translate_set_enabled( use_xlat );
286 /* If requested, start the gdb server immediately before we go into the main
287 * loop.
288 */
289 if( sh4_gdb_port != NULL ) {
290 gdb_init_server( NULL, strtol(sh4_gdb_port,NULL,0), &sh4_cpu_desc, TRUE );
291 }
292 if( arm_gdb_port != NULL ) {
293 gdb_init_server( NULL, strtol(arm_gdb_port,NULL,0), &arm_cpu_desc, TRUE );
294 }
296 if( headless ) {
297 dreamcast_run();
298 } else {
299 gui_main_loop( start_immediately && dreamcast_can_run() );
300 }
301 dreamcast_shutdown();
302 return 0;
303 }
.