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:npPt: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' },
70 { "sh4-profile-blocks", no_argument, NULL, 'P' },
72 char *aica_program = NULL;
73 char *display_driver_name = NULL;
74 char *audio_driver_name = NULL;
75 char *trace_regions = NULL;
76 char *sh4_gdb_port = NULL;
77 char *arm_gdb_port = NULL;
78 gboolean start_immediately = FALSE;
79 gboolean no_start = FALSE;
80 gboolean headless = FALSE;
81 sh4core_t sh4_core = SH4_TRANSLATE;
82 gboolean show_debugger = FALSE;
83 gboolean show_fullscreen = FALSE;
84 gboolean use_bootrom = TRUE;
85 extern uint32_t sh4_cpu_multiplier;
87 static void print_version()
89 printf( "lxdream %s\n", lxdream_full_version );
92 static void print_usage()
95 printf( "Usage: lxdream %s [options] [disc-file] [save-state]\n\n", lxdream_full_version );
97 printf( "Options:\n" );
98 printf( " -a, --aica=PROGFILE %s\n", _("Run the AICA SPU only, with the supplied program") );
99 printf( " -A, --audio=DRIVER %s\n", _("Use the specified audio driver (? to list)") );
100 printf( " -b, --biosless %s\n", _("Run without the BIOS boot rom even if available") );
101 printf( " -c, --config=CONFFILE %s\n", _("Load configuration from CONFFILE") );
102 printf( " -e, --execute=PROGRAM %s\n", _("Load and execute the given SH4 program") );
103 printf( " -d, --debugger %s\n", _("Start in debugger mode") );
104 printf( " -f, --fullscreen %s\n", _("Start in fullscreen mode") );
105 printf( " -g, --gdb-sh4=PORT %s\n", _("Start GDB remote server on PORT for SH4") );
106 printf( " -G, --gdb-arm=PORT %s\n", _("Start GDB remote server on PORT for ARM") );
107 printf( " -h, --help %s\n", _("Display this usage information") );
108 printf( " -H, --headless %s\n", _("Run in headless (no video) mode") );
109 printf( " -l, --log=LEVEL %s\n", _("Set the output log level") );
110 printf( " -m, --multiplier=SCALE %s\n", _("Set the SH4 multiplier (1.0 = fullspeed)") );
111 printf( " -n %s\n", _("Don't start running immediately") );
112 printf( " -p %s\n", _("Start running immediately on startup") );
113 printf( " -t, --run-time=SECONDS %s\n", _("Run for the specified number of seconds") );
114 printf( " -T, --trace=REGIONS %s\n", _("Output trace information for the named regions") );
115 printf( " -u, --unsafe %s\n", _("Allow unsafe dcload syscalls") );
116 printf( " -v, --version %s\n", _("Print the lxdream version string") );
117 printf( " -V, --video=DRIVER %s\n", _("Use the specified video driver (? to list)") );
118 printf( " -x %s\n", _("Disable the SH4 translator") );
119 printf( " -X %s\n", _("Run both SH4 interpreter and translator") );
122 static void bind_gettext_domain()
125 bindtextdomain( PACKAGE, get_locale_path() );
130 int main (int argc, char *argv[])
134 gboolean display_ok, have_disc = FALSE, have_save = FALSE, have_exec = FALSE;
135 gboolean print_glinfo = FALSE, sh4_profile_blocks = FALSE;
136 uint32_t time_secs, time_nanos;
137 const char *exec_name = NULL;
139 install_crash_handler();
140 bind_gettext_domain();
141 display_ok = gui_parse_cmdline(&argc, &argv);
143 while( (opt = getopt_long( argc, argv, option_list, longopts, NULL )) != -1 ) {
145 case 'a': /* AICA only mode - argument is an AICA program */
146 aica_program = optarg;
148 case 'A': /* Audio driver */
149 audio_driver_name = optarg;
151 case 'b': /* No Boot rom */
153 case 'c': /* Config file */
154 lxdream_set_config_filename(optarg);
156 case 'd': /* Launch w/ debugger */
157 show_debugger = TRUE;
163 show_fullscreen = TRUE;
166 sh4_gdb_port = optarg;
169 arm_gdb_port = optarg;
176 case 'H': /* Headless - shorthand for -V null */
177 display_driver_name = "null";
179 case 'l': /* Log verbosity */
180 if( !set_global_log_level(optarg) ) {
181 ERROR( "Unrecognized log level '%s'", optarg );
184 case 'm': /* Set SH4 CPU clock multiplier (default 0.5) */
185 t = strtod(optarg, NULL);
186 sh4_cpu_multiplier = (int)(1000.0/t);
188 case 'n': /* Don't start immediately */
190 start_immediately = FALSE;
192 case 'p': /* Start immediately */
193 start_immediately = TRUE;
197 sh4_profile_blocks = TRUE;
199 case 't': /* Time limit + auto quit */
200 t = strtod(optarg, NULL);
201 time_secs = (uint32_t)t;
202 time_nanos = (int)((t - time_secs) * 1000000000);
203 dreamcast_set_run_time( time_secs, time_nanos );
204 dreamcast_set_exit_on_stop( TRUE );
206 case 'T': /* trace regions */
207 trace_regions = optarg;
208 set_global_log_level("trace");
210 case 'u': /* Allow unsafe dcload syscalls */
211 dcload_set_allow_unsafe(TRUE);
217 case 'V': /* Video driver */
218 display_driver_name = optarg;
220 case 'x': /* Disable translator */
221 sh4_core = SH4_INTERPRET;
223 case 'X': /* Shadow translator */
224 sh4_core = SH4_SHADOW;
236 lxdream_make_config_dir( );
237 lxdream_load_config( );
239 if( audio_driver_name != NULL && strcmp(audio_driver_name, "?") == 0 ) {
241 print_audio_drivers(stdout);
245 if( display_driver_name != NULL && strcmp(display_driver_name,"?") == 0 ) {
247 print_display_drivers(stdout);
252 gui_init(FALSE, FALSE);
253 display_driver_t display_driver = get_display_driver_by_name(display_driver_name);
254 if( display_driver == NULL ) {
255 ERROR( "Video driver '%s' not found, aborting.", display_driver_name );
257 } else if( display_set_driver( display_driver ) == FALSE ) {
258 ERROR( "Video driver '%s' failed to initialize (could not connect to display?)",
259 display_driver->name );
261 } else if( display_driver->capabilities.has_gl == FALSE ) {
262 ERROR( "Video driver '%s' has no GL capabilities.", display_driver_name );
275 if( aica_program == NULL ) {
276 dreamcast_init(use_bootrom);
278 dreamcast_configure_aica_only();
279 mem_load_block( aica_program, 0x00800000, 2048*1024 );
281 mem_set_trace( trace_regions, TRUE );
283 audio_init_driver( audio_driver_name );
285 headless = display_driver_name != NULL && strcasecmp( display_driver_name, "null" ) == 0;
287 display_set_driver( &display_null_driver );
289 gui_init(show_debugger, show_fullscreen);
291 display_driver_t display_driver = get_display_driver_by_name(display_driver_name);
292 if( display_driver == NULL ) {
293 ERROR( "Video driver '%s' not found, aborting.", display_driver_name );
295 } else if( display_set_driver( display_driver ) == FALSE ) {
296 ERROR( "Video driver '%s' failed to initialize (could not connect to display?)",
297 display_driver->name );
305 maple_reattach_all();
306 INFO( "%s! ready...", APP_NAME );
308 for( ; optind < argc; optind++ ) {
310 lxdream_file_type_t type = file_identify(argv[optind], -1, &err);
311 if( type == FILE_SAVE_STATE ) {
313 ERROR( "Multiple save states given on command-line, ignoring %s", argv[optind] );
315 have_save = dreamcast_load_state(argv[optind]);
321 ERROR( "Multiple GD-ROM discs given on command-line, ignoring %s", argv[optind] );
323 have_disc = gdrom_mount_image(argv[optind], &err);
332 if( exec_name != NULL ) {
335 ERROR( "Both a save state and an executable were specified, ignoring %s", exec_name );
337 have_exec = file_load_exec( exec_name, &err );
345 if( !no_start && (have_exec || have_disc || have_save) ) {
346 start_immediately = TRUE;
349 if( gdrom_get_current_disc() == NULL ) {
351 gchar *disc_file = lxdream_get_global_config_path_value( CONFIG_GDROM );
352 if( disc_file != NULL ) {
353 gboolean ok = gdrom_mount_image( disc_file, &err );
361 sh4_set_core( sh4_core );
362 sh4_set_profile_blocks( sh4_profile_blocks );
364 /* If requested, start the gdb server immediately before we go into the main
367 if( sh4_gdb_port != NULL ) {
368 gdb_init_server( NULL, strtol(sh4_gdb_port,NULL,0), &sh4_cpu_desc, TRUE );
370 if( arm_gdb_port != NULL ) {
371 gdb_init_server( NULL, strtol(arm_gdb_port,NULL,0), &arm_cpu_desc, TRUE );
377 gui_main_loop( start_immediately && dreamcast_can_run() );
379 dreamcast_shutdown();
.