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.
23 #include <glib/gi18n.h>
27 #include "dreamcast.h"
31 #include "aica/audio.h"
32 #include "gdrom/gdrom.h"
33 #include "maple/maple.h"
37 #include <AppKit/AppKit.h>
40 char *option_list = "a:A:c:dhHl:m:npt:T:uvV:x?";
41 struct option longopts[] = {
42 { "aica", required_argument, NULL, 'a' },
43 { "audio", required_argument, NULL, 'A' },
44 { "config", required_argument, NULL, 'c' },
45 { "debugger", no_argument, NULL, 'D' },
46 { "help", no_argument, NULL, 'h' },
47 { "headless", no_argument, NULL, 'H' },
48 { "log", required_argument, NULL,'l' },
49 { "multiplier", required_argument, NULL, 'm' },
50 { "run-time", required_argument, NULL, 't' },
51 { "trace", required_argument, NULL, 'T' },
52 { "unsafe", no_argument, NULL, 'u' },
53 { "video", no_argument, NULL, 'V' },
54 { "version", no_argument, NULL, 'v' },
56 char *aica_program = NULL;
57 char *display_driver_name = NULL;
58 char *audio_driver_name = NULL;
59 char *trace_regions = NULL;
60 gboolean start_immediately = FALSE;
61 gboolean no_start = FALSE;
62 gboolean headless = FALSE;
63 gboolean use_xlat = TRUE;
64 gboolean show_debugger = FALSE;
65 extern uint32_t sh4_cpu_multiplier;
69 printf( "lxdream " APP_VERSION "\n" );
75 printf( "Usage: lxdream [options] [disc-file] [program-file]\n\n" );
77 printf( "Options:\n" );
78 printf( " -a, --aica=PROGFILE %s\n", _("Run the AICA SPU only, with the supplied program") );
79 printf( " -A, --audio=DRIVER %s\n", _("Use the specified audio driver (? to list)") );
80 printf( " -c, --config=CONFFILE %s\n", _("Load configuration from CONFFILE") );
81 printf( " -d, --debugger %s\n", _("Start in debugger mode") );
82 printf( " -h, --help %s\n", _("Display this usage information") );
83 printf( " -H, --headless %s\n", _("Run in headless (no video) mode") );
84 printf( " -l, --log=LEVEL %s\n", _("Set the output log level") );
85 printf( " -m, --multiplier=SCALE %s\n", _("Set the SH4 multiplier (1.0 = fullspeed)") );
86 printf( " -n %s\n", _("Don't start running immediately") );
87 printf( " -p %s\n", _("Start running immediately on startup") );
88 printf( " -t, --run-time=SECONDS %s\n", _("Run for the specified number of seconds") );
89 printf( " -T, --trace=REGIONS %s\n", _("Output trace information for the named regions") );
90 printf( " -u, --unsafe %s\n", _("Allow unsafe dcload syscalls") );
91 printf( " -v, --version %s\n", _("Print the lxdream version string") );
92 printf( " -V, --video=DRIVER %s\n", _("Use the specified video driver (? to list)") );
93 printf( " -x %s\n", _("Disable the SH4 translator") );
96 void bind_gettext_domain()
100 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
101 NSString *resourcePath = [[NSBundle mainBundle] resourcePath];
102 bindtextdomain( PACKAGE, [resourcePath UTF8String] );
103 #ifdef HAVE_BIND_TEXTDOMAIN_CODESET
104 bind_textdomain_codeset( PACKAGE, "UTF-8" );
108 bindtextdomain (PACKAGE, PACKAGE_LOCALE_DIR);
115 int main (int argc, char *argv[])
120 uint32_t time_secs, time_nanos;
122 install_crash_handler();
123 bind_gettext_domain();
124 display_ok = gui_parse_cmdline(&argc, &argv);
126 while( (opt = getopt_long( argc, argv, option_list, longopts, NULL )) != -1 ) {
128 case 'a': /* AICA only mode - argument is an AICA program */
129 aica_program = optarg;
131 case 'A': /* Audio driver */
132 audio_driver_name = optarg;
133 if( strcmp(audio_driver_name, "?") == 0 ) {
135 print_audio_drivers(stdout);
139 case 'c': /* Config file */
140 lxdream_set_config_filename(optarg);
142 case 'd': /* Launch w/ debugger */
143 show_debugger = TRUE;
150 case 'H': /* Headless - shorthand for -V null */
151 display_driver_name = "null";
153 case 'l': /* Log verbosity */
154 if( !set_global_log_level(optarg) ) {
155 ERROR( "Unrecognized log level '%s'", optarg );
158 case 'm': /* Set SH4 CPU clock multiplier (default 0.5) */
159 t = strtod(optarg, NULL);
160 sh4_cpu_multiplier = (int)(1000.0/t);
162 case 'n': /* Don't start immediately */
164 start_immediately = FALSE;
166 case 'p': /* Start immediately */
167 start_immediately = TRUE;
170 case 't': /* Time limit + auto quit */
171 t = strtod(optarg, NULL);
172 time_secs = (uint32_t)t;
173 time_nanos = (int)((t - time_secs) * 1000000000);
174 dreamcast_set_run_time( time_secs, time_nanos );
175 dreamcast_set_exit_on_stop( TRUE );
177 case 'T': /* trace regions */
178 trace_regions = optarg;
179 set_global_log_level("trace");
181 case 'u': /* Allow unsafe dcload syscalls */
182 dcload_set_allow_unsafe(TRUE);
188 case 'V': /* Video driver */
189 display_driver_name = optarg;
190 if( strcmp(display_driver_name,"?") == 0 ) {
192 print_display_drivers(stdout);
196 case 'x': /* Disable translator */
202 lxdream_load_config( );
205 if( aica_program == NULL ) {
208 dreamcast_configure_aica_only();
209 mem_load_block( aica_program, 0x00800000, 2048*1024 );
211 mem_set_trace( trace_regions, TRUE );
213 audio_init_driver( audio_driver_name, 44100, AUDIO_FMT_16ST );
215 headless = display_driver_name != NULL && strcasecmp( display_driver_name, "null" ) == 0;
217 display_set_driver( &display_null_driver );
219 gui_init(show_debugger);
221 display_driver_t display_driver = get_display_driver_by_name(display_driver_name);
222 if( display_driver == NULL ) {
223 ERROR( "Video driver '%s' not found, aborting.", display_driver_name );
225 } else if( display_set_driver( display_driver ) == FALSE ) {
226 ERROR( "Video driver '%s' failed to initialize (could not connect to display?)",
227 display_driver->name );
232 maple_reattach_all();
233 INFO( "%s! ready...", APP_NAME );
235 for( ; optind < argc; optind++ ) {
236 gboolean ok = gdrom_mount_image(argv[optind]);
238 ok = file_load_magic( argv[optind] );
241 ERROR( "Unrecognized file '%s'", argv[optind] );
244 start_immediately = ok;
248 if( gdrom_get_current_disc() == NULL ) {
249 const gchar *disc_file = lxdream_get_config_value( CONFIG_GDROM );
250 if( disc_file != NULL ) {
251 gdrom_mount_image( disc_file );
255 sh4_set_use_xlat( use_xlat );
260 gui_main_loop( start_immediately && dreamcast_can_run() );
262 dreamcast_shutdown();
.