4 * Main program, initializes dreamcast and gui, then passes control off to
7 * Copyright (c) 2005 Nathan Keynes.
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.
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.
28 #include "dreamcast.h"
38 #include "aica/audio.h"
39 #include "aica/armdasm.h"
40 #include "gdrom/gdrom.h"
41 #include "maple/maple.h"
42 #include "pvr2/glutil.h"
44 #include "vmu/vmulist.h"
48 char *option_list = "a:A:bc:e:dfg:G:hHl:m:npt:T:uvV:xX?";
49 struct option longopts[] = {
50 { "aica", required_argument, NULL, 'a' },
51 { "audio", required_argument, NULL, 'A' },
52 { "biosless", no_argument, NULL, 'b' },
53 { "config", required_argument, NULL, 'c' },
54 { "debugger", no_argument, NULL, 'd' },
55 { "execute", required_argument, NULL, 'e' },
56 { "fullscreen", no_argument, NULL, 'f' },
57 { "gdb-sh4", required_argument, NULL, 'g' },
58 { "gdb-arm", required_argument, NULL, 'G' },
59 { "gl-info", no_argument, NULL, GL_INFO_OPT },
60 { "help", no_argument, NULL, 'h' },
61 { "headless", no_argument, NULL, 'H' },
62 { "log", required_argument, NULL,'l' },
63 { "multiplier", required_argument, NULL, 'm' },
64 { "run-time", required_argument, NULL, 't' },
65 { "shadow", no_argument, NULL, 'X' },
66 { "trace", required_argument, NULL, 'T' },
67 { "unsafe", no_argument, NULL, 'u' },
68 { "video", no_argument, NULL, 'V' },
69 { "version", no_argument, NULL, 'v' },
71 char *aica_program = NULL;
72 char *display_driver_name = NULL;
73 char *audio_driver_name = NULL;
74 char *trace_regions = NULL;
75 char *sh4_gdb_port = NULL;
76 char *arm_gdb_port = NULL;
77 gboolean start_immediately = FALSE;
78 gboolean no_start = FALSE;
79 gboolean headless = FALSE;
80 sh4core_t sh4_core = SH4_TRANSLATE;
81 gboolean show_debugger = FALSE;
82 gboolean show_fullscreen = FALSE;
83 gboolean use_bootrom = TRUE;
84 extern uint32_t sh4_cpu_multiplier;
86 static void print_version()
88 printf( "lxdream %s\n", lxdream_full_version );
91 static void print_usage()
94 printf( "Usage: lxdream %s [options] [disc-file] [save-state]\n\n", lxdream_full_version );
96 printf( "Options:\n" );
97 printf( " -a, --aica=PROGFILE %s\n", _("Run the AICA SPU only, with the supplied program") );
98 printf( " -A, --audio=DRIVER %s\n", _("Use the specified audio driver (? to list)") );
99 printf( " -b, --biosless %s\n", _("Run without the BIOS boot rom even if available") );
100 printf( " -c, --config=CONFFILE %s\n", _("Load configuration from CONFFILE") );
101 printf( " -e, --execute=PROGRAM %s\n", _("Load and execute the given SH4 program") );
102 printf( " -d, --debugger %s\n", _("Start in debugger mode") );
103 printf( " -f, --fullscreen %s\n", _("Start in fullscreen mode") );
104 printf( " -g, --gdb-sh4=PORT %s\n", _("Start GDB remote server on PORT for SH4") );
105 printf( " -G, --gdb-arm=PORT %s\n", _("Start GDB remote server on PORT for ARM") );
106 printf( " -h, --help %s\n", _("Display this usage information") );
107 printf( " -H, --headless %s\n", _("Run in headless (no video) mode") );
108 printf( " -l, --log=LEVEL %s\n", _("Set the output log level") );
109 printf( " -m, --multiplier=SCALE %s\n", _("Set the SH4 multiplier (1.0 = fullspeed)") );
110 printf( " -n %s\n", _("Don't start running immediately") );
111 printf( " -p %s\n", _("Start running immediately on startup") );
112 printf( " -t, --run-time=SECONDS %s\n", _("Run for the specified number of seconds") );
113 printf( " -T, --trace=REGIONS %s\n", _("Output trace information for the named regions") );
114 printf( " -u, --unsafe %s\n", _("Allow unsafe dcload syscalls") );
115 printf( " -v, --version %s\n", _("Print the lxdream version string") );
116 printf( " -V, --video=DRIVER %s\n", _("Use the specified video driver (? to list)") );
117 printf( " -x %s\n", _("Disable the SH4 translator") );
118 printf( " -X %s\n", _("Run both SH4 interpreter and translator") );
121 static void bind_gettext_domain()
124 bindtextdomain( PACKAGE, get_locale_path() );
129 int main (int argc, char *argv[])
133 gboolean display_ok, have_disc = FALSE, have_save = FALSE, have_exec = FALSE;
134 gboolean print_glinfo = FALSE;
135 uint32_t time_secs, time_nanos;
136 const char *exec_name = NULL;
138 install_crash_handler();
139 bind_gettext_domain();
140 display_ok = gui_parse_cmdline(&argc, &argv);
142 while( (opt = getopt_long( argc, argv, option_list, longopts, NULL )) != -1 ) {
144 case 'a': /* AICA only mode - argument is an AICA program */
145 aica_program = optarg;
147 case 'A': /* Audio driver */
148 audio_driver_name = optarg;
150 case 'b': /* No Boot rom */
152 case 'c': /* Config file */
153 lxdream_set_config_filename(optarg);
155 case 'd': /* Launch w/ debugger */
156 show_debugger = TRUE;
162 show_fullscreen = TRUE;
165 sh4_gdb_port = optarg;
168 arm_gdb_port = optarg;
175 case 'H': /* Headless - shorthand for -V null */
176 display_driver_name = "null";
178 case 'l': /* Log verbosity */
179 if( !set_global_log_level(optarg) ) {
180 ERROR( "Unrecognized log level '%s'", optarg );
183 case 'm': /* Set SH4 CPU clock multiplier (default 0.5) */
184 t = strtod(optarg, NULL);
185 sh4_cpu_multiplier = (int)(1000.0/t);
187 case 'n': /* Don't start immediately */
189 start_immediately = FALSE;
191 case 'p': /* Start immediately */
192 start_immediately = TRUE;
195 case 't': /* Time limit + auto quit */
196 t = strtod(optarg, NULL);
197 time_secs = (uint32_t)t;
198 time_nanos = (int)((t - time_secs) * 1000000000);
199 dreamcast_set_run_time( time_secs, time_nanos );
200 dreamcast_set_exit_on_stop( TRUE );
202 case 'T': /* trace regions */
203 trace_regions = optarg;
204 set_global_log_level("trace");
206 case 'u': /* Allow unsafe dcload syscalls */
207 dcload_set_allow_unsafe(TRUE);
213 case 'V': /* Video driver */
214 display_driver_name = optarg;
216 case 'x': /* Disable translator */
217 sh4_core = SH4_INTERPRET;
219 case 'X': /* Shadow translator */
220 sh4_core = SH4_SHADOW;
232 lxdream_make_config_dir( );
233 lxdream_load_config( );
235 if( audio_driver_name != NULL && strcmp(audio_driver_name, "?") == 0 ) {
237 print_audio_drivers(stdout);
241 if( display_driver_name != NULL && strcmp(display_driver_name,"?") == 0 ) {
243 print_display_drivers(stdout);
248 gui_init(FALSE, FALSE);
249 display_driver_t display_driver = get_display_driver_by_name(display_driver_name);
250 if( display_driver == NULL ) {
251 ERROR( "Video driver '%s' not found, aborting.", display_driver_name );
253 } else if( display_set_driver( display_driver ) == FALSE ) {
254 ERROR( "Video driver '%s' failed to initialize (could not connect to display?)",
255 display_driver->name );
257 } else if( display_driver->capabilities.has_gl == FALSE ) {
258 ERROR( "Video driver '%s' has no GL capabilities.", display_driver_name );
271 if( aica_program == NULL ) {
272 dreamcast_init(use_bootrom);
274 dreamcast_configure_aica_only();
275 mem_load_block( aica_program, 0x00800000, 2048*1024 );
277 mem_set_trace( trace_regions, TRUE );
279 audio_init_driver( audio_driver_name );
281 headless = display_driver_name != NULL && strcasecmp( display_driver_name, "null" ) == 0;
283 display_set_driver( &display_null_driver );
285 gui_init(show_debugger, show_fullscreen);
287 display_driver_t display_driver = get_display_driver_by_name(display_driver_name);
288 if( display_driver == NULL ) {
289 ERROR( "Video driver '%s' not found, aborting.", display_driver_name );
291 } else if( display_set_driver( display_driver ) == FALSE ) {
292 ERROR( "Video driver '%s' failed to initialize (could not connect to display?)",
293 display_driver->name );
301 maple_reattach_all();
302 INFO( "%s! ready...", APP_NAME );
304 for( ; optind < argc; optind++ ) {
306 lxdream_file_type_t type = file_identify(argv[optind], -1, &err);
307 if( type == FILE_SAVE_STATE ) {
309 ERROR( "Multiple save states given on command-line, ignoring %s", argv[optind] );
311 have_save = dreamcast_load_state(argv[optind]);
317 ERROR( "Multiple GD-ROM discs given on command-line, ignoring %s", argv[optind] );
319 have_disc = gdrom_mount_image(argv[optind], &err);
328 if( exec_name != NULL ) {
331 ERROR( "Both a save state and an executable were specified, ignoring %s", exec_name );
333 have_exec = file_load_exec( exec_name, &err );
341 if( !no_start && (have_exec || have_disc || have_save) ) {
342 start_immediately = TRUE;
345 if( gdrom_get_current_disc() == NULL ) {
347 gchar *disc_file = lxdream_get_global_config_path_value( CONFIG_GDROM );
348 if( disc_file != NULL ) {
349 gboolean ok = gdrom_mount_image( disc_file, &err );
357 sh4_set_core( sh4_core );
359 /* If requested, start the gdb server immediately before we go into the main
362 if( sh4_gdb_port != NULL ) {
363 gdb_init_server( NULL, strtol(sh4_gdb_port,NULL,0), &sh4_cpu_desc, TRUE );
365 if( arm_gdb_port != NULL ) {
366 gdb_init_server( NULL, strtol(arm_gdb_port,NULL,0), &arm_cpu_desc, TRUE );
372 gui_main_loop( start_immediately && dreamcast_can_run() );
374 dreamcast_shutdown();
.