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"
35 #include "aica/audio.h"
36 #include "gdrom/gdrom.h"
37 #include "maple/maple.h"
39 #include "aica/armdasm.h"
40 #include "vmu/vmulist.h"
45 char *option_list = "a:A:bc:e:dfg:G:hHl:m:npt:T:uvV:x?";
46 struct option longopts[] = {
47 { "aica", required_argument, NULL, 'a' },
48 { "audio", required_argument, NULL, 'A' },
49 { "biosless", no_argument, NULL, 'b' },
50 { "config", required_argument, NULL, 'c' },
51 { "debugger", no_argument, NULL, 'd' },
52 { "execute", required_argument, NULL, 'e' },
53 { "fullscreen", no_argument, NULL, 'f' },
54 { "gdb-sh4", required_argument, NULL, 'g' },
55 { "gdb-arm", required_argument, NULL, 'G' },
56 { "help", no_argument, NULL, 'h' },
57 { "headless", no_argument, NULL, 'H' },
58 { "log", required_argument, NULL,'l' },
59 { "multiplier", required_argument, NULL, 'm' },
60 { "run-time", required_argument, NULL, 't' },
61 { "trace", required_argument, NULL, 'T' },
62 { "unsafe", no_argument, NULL, 'u' },
63 { "video", no_argument, NULL, 'V' },
64 { "version", no_argument, NULL, 'v' },
66 char *aica_program = NULL;
67 char *display_driver_name = NULL;
68 char *audio_driver_name = NULL;
69 char *trace_regions = NULL;
70 char *sh4_gdb_port = NULL;
71 char *arm_gdb_port = NULL;
72 gboolean start_immediately = FALSE;
73 gboolean no_start = FALSE;
74 gboolean headless = FALSE;
75 gboolean use_xlat = TRUE;
76 gboolean show_debugger = FALSE;
77 gboolean show_fullscreen = FALSE;
78 gboolean use_bootrom = TRUE;
79 extern uint32_t sh4_cpu_multiplier;
81 static void print_version()
83 printf( "lxdream %s\n", lxdream_full_version );
86 static void print_usage()
89 printf( "Usage: lxdream %s [options] [disc-file] [save-state]\n\n", lxdream_full_version );
91 printf( "Options:\n" );
92 printf( " -a, --aica=PROGFILE %s\n", _("Run the AICA SPU only, with the supplied program") );
93 printf( " -A, --audio=DRIVER %s\n", _("Use the specified audio driver (? to list)") );
94 printf( " -b, --biosless %s\n", _("Run without the BIOS boot rom even if available") );
95 printf( " -c, --config=CONFFILE %s\n", _("Load configuration from CONFFILE") );
96 printf( " -e, --execute=PROGRAM %s\n", _("Load and execute the given SH4 program") );
97 printf( " -d, --debugger %s\n", _("Start in debugger mode") );
98 printf( " -f, --fullscreen %s\n", _("Start in fullscreen mode") );
99 printf( " -g, --gdb-sh4=PORT %s\n", _("Start GDB remote server on PORT for SH4") );
100 printf( " -G, --gdb-arm=PORT %s\n", _("Start GDB remote server on PORT for ARM") );
101 printf( " -h, --help %s\n", _("Display this usage information") );
102 printf( " -H, --headless %s\n", _("Run in headless (no video) mode") );
103 printf( " -l, --log=LEVEL %s\n", _("Set the output log level") );
104 printf( " -m, --multiplier=SCALE %s\n", _("Set the SH4 multiplier (1.0 = fullspeed)") );
105 printf( " -n %s\n", _("Don't start running immediately") );
106 printf( " -p %s\n", _("Start running immediately on startup") );
107 printf( " -t, --run-time=SECONDS %s\n", _("Run for the specified number of seconds") );
108 printf( " -T, --trace=REGIONS %s\n", _("Output trace information for the named regions") );
109 printf( " -u, --unsafe %s\n", _("Allow unsafe dcload syscalls") );
110 printf( " -v, --version %s\n", _("Print the lxdream version string") );
111 printf( " -V, --video=DRIVER %s\n", _("Use the specified video driver (? to list)") );
112 printf( " -x %s\n", _("Disable the SH4 translator") );
115 static void bind_gettext_domain()
118 bindtextdomain( PACKAGE, get_locale_path() );
123 int main (int argc, char *argv[])
127 gboolean display_ok, have_disc = FALSE, have_save = FALSE, have_exec = FALSE;
128 uint32_t time_secs, time_nanos;
129 const char *exec_name = NULL;
131 install_crash_handler();
132 bind_gettext_domain();
133 display_ok = gui_parse_cmdline(&argc, &argv);
135 while( (opt = getopt_long( argc, argv, option_list, longopts, NULL )) != -1 ) {
137 case 'a': /* AICA only mode - argument is an AICA program */
138 aica_program = optarg;
140 case 'A': /* Audio driver */
141 audio_driver_name = optarg;
143 case 'b': /* No Boot rom */
145 case 'c': /* Config file */
146 lxdream_set_config_filename(optarg);
148 case 'd': /* Launch w/ debugger */
149 show_debugger = TRUE;
155 show_fullscreen = TRUE;
158 sh4_gdb_port = optarg;
161 arm_gdb_port = optarg;
168 case 'H': /* Headless - shorthand for -V null */
169 display_driver_name = "null";
171 case 'l': /* Log verbosity */
172 if( !set_global_log_level(optarg) ) {
173 ERROR( "Unrecognized log level '%s'", optarg );
176 case 'm': /* Set SH4 CPU clock multiplier (default 0.5) */
177 t = strtod(optarg, NULL);
178 sh4_cpu_multiplier = (int)(1000.0/t);
180 case 'n': /* Don't start immediately */
182 start_immediately = FALSE;
184 case 'p': /* Start immediately */
185 start_immediately = TRUE;
188 case 't': /* Time limit + auto quit */
189 t = strtod(optarg, NULL);
190 time_secs = (uint32_t)t;
191 time_nanos = (int)((t - time_secs) * 1000000000);
192 dreamcast_set_run_time( time_secs, time_nanos );
193 dreamcast_set_exit_on_stop( TRUE );
195 case 'T': /* trace regions */
196 trace_regions = optarg;
197 set_global_log_level("trace");
199 case 'u': /* Allow unsafe dcload syscalls */
200 dcload_set_allow_unsafe(TRUE);
206 case 'V': /* Video driver */
207 display_driver_name = optarg;
209 case 'x': /* Disable translator */
219 lxdream_make_config_dir( );
220 lxdream_load_config( );
222 if( audio_driver_name != NULL && strcmp(audio_driver_name, "?") == 0 ) {
224 print_audio_drivers(stdout);
228 if( display_driver_name != NULL && strcmp(display_driver_name,"?") == 0 ) {
230 print_display_drivers(stdout);
238 if( aica_program == NULL ) {
239 dreamcast_init(use_bootrom);
241 dreamcast_configure_aica_only();
242 mem_load_block( aica_program, 0x00800000, 2048*1024 );
244 mem_set_trace( trace_regions, TRUE );
246 audio_init_driver( audio_driver_name );
248 headless = display_driver_name != NULL && strcasecmp( display_driver_name, "null" ) == 0;
250 display_set_driver( &display_null_driver );
252 gui_init(show_debugger, show_fullscreen);
254 display_driver_t display_driver = get_display_driver_by_name(display_driver_name);
255 if( display_driver == NULL ) {
256 ERROR( "Video driver '%s' not found, aborting.", display_driver_name );
258 } else if( display_set_driver( display_driver ) == FALSE ) {
259 ERROR( "Video driver '%s' failed to initialize (could not connect to display?)",
260 display_driver->name );
268 maple_reattach_all();
269 INFO( "%s! ready...", APP_NAME );
271 for( ; optind < argc; optind++ ) {
273 lxdream_file_type_t type = file_identify(argv[optind], -1, &err);
274 if( type == FILE_SAVE_STATE ) {
276 ERROR( "Multiple save states given on command-line, ignoring %s", argv[optind] );
278 have_save = dreamcast_load_state(argv[optind]);
284 ERROR( "Multiple GD-ROM discs given on command-line, ignoring %s", argv[optind] );
286 have_disc = gdrom_mount_image(argv[optind], &err);
295 if( exec_name != NULL ) {
298 ERROR( "Both a save state and an executable were specified, ignoring %s", exec_name );
300 have_exec = file_load_exec( exec_name, &err );
308 if( !no_start && (have_exec || have_disc || have_save) ) {
309 start_immediately = TRUE;
312 if( gdrom_get_current_disc() == NULL ) {
314 gchar *disc_file = lxdream_get_global_config_path_value( CONFIG_GDROM );
315 if( disc_file != NULL ) {
316 gboolean ok = gdrom_mount_image( disc_file, &err );
324 sh4_translate_set_enabled( use_xlat );
326 /* If requested, start the gdb server immediately before we go into the main
329 if( sh4_gdb_port != NULL ) {
330 gdb_init_server( NULL, strtol(sh4_gdb_port,NULL,0), &sh4_cpu_desc, TRUE );
332 if( arm_gdb_port != NULL ) {
333 gdb_init_server( NULL, strtol(arm_gdb_port,NULL,0), &arm_cpu_desc, TRUE );
339 gui_main_loop( start_immediately && dreamcast_can_run() );
341 dreamcast_shutdown();
.