filename | src/main.c |
changeset | 866:86cd01c2b2d3 |
prev | 772:c0b5928dd600 |
next | 968:6fb1481859a4 |
author | nkeynes |
date | Mon Oct 06 01:05:12 2008 +0000 (15 years ago) |
permissions | -rw-r--r-- |
last change | Move bundle/system paths into paths.c, install lxdreamrc into the bundle (Fix OSX bundle missing default configuration) |
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 "gettext.h"
25 #include "mem.h"
26 #include "dreamcast.h"
27 #include "dream.h"
28 #include "display.h"
29 #include "gui.h"
30 #include "gdlist.h"
31 #include "syscall.h"
32 #include "loader.h"
33 #include "aica/audio.h"
34 #include "gdrom/gdrom.h"
35 #include "maple/maple.h"
36 #include "sh4/sh4.h"
39 char *option_list = "a:A:c:dhHl:m:npt:T:uvV:x?";
40 struct option longopts[] = {
41 { "aica", required_argument, NULL, 'a' },
42 { "audio", required_argument, NULL, 'A' },
43 { "config", required_argument, NULL, 'c' },
44 { "debugger", no_argument, NULL, 'D' },
45 { "help", no_argument, NULL, 'h' },
46 { "headless", no_argument, NULL, 'H' },
47 { "log", required_argument, NULL,'l' },
48 { "multiplier", required_argument, NULL, 'm' },
49 { "run-time", required_argument, NULL, 't' },
50 { "trace", required_argument, NULL, 'T' },
51 { "unsafe", no_argument, NULL, 'u' },
52 { "video", no_argument, NULL, 'V' },
53 { "version", no_argument, NULL, 'v' },
54 { NULL, 0, 0, 0 } };
55 char *aica_program = NULL;
56 char *display_driver_name = NULL;
57 char *audio_driver_name = NULL;
58 char *trace_regions = NULL;
59 gboolean start_immediately = FALSE;
60 gboolean no_start = FALSE;
61 gboolean headless = FALSE;
62 gboolean use_xlat = TRUE;
63 gboolean show_debugger = FALSE;
64 extern uint32_t sh4_cpu_multiplier;
66 void print_version()
67 {
68 printf( "lxdream %s\n", lxdream_full_version );
69 }
71 void print_usage()
72 {
73 print_version();
74 printf( "Usage: lxdream %s [options] [disc-file] [program-file]\n\n", lxdream_full_version );
76 printf( "Options:\n" );
77 printf( " -a, --aica=PROGFILE %s\n", _("Run the AICA SPU only, with the supplied program") );
78 printf( " -A, --audio=DRIVER %s\n", _("Use the specified audio driver (? to list)") );
79 printf( " -c, --config=CONFFILE %s\n", _("Load configuration from CONFFILE") );
80 printf( " -d, --debugger %s\n", _("Start in debugger mode") );
81 printf( " -h, --help %s\n", _("Display this usage information") );
82 printf( " -H, --headless %s\n", _("Run in headless (no video) mode") );
83 printf( " -l, --log=LEVEL %s\n", _("Set the output log level") );
84 printf( " -m, --multiplier=SCALE %s\n", _("Set the SH4 multiplier (1.0 = fullspeed)") );
85 printf( " -n %s\n", _("Don't start running immediately") );
86 printf( " -p %s\n", _("Start running immediately on startup") );
87 printf( " -t, --run-time=SECONDS %s\n", _("Run for the specified number of seconds") );
88 printf( " -T, --trace=REGIONS %s\n", _("Output trace information for the named regions") );
89 printf( " -u, --unsafe %s\n", _("Allow unsafe dcload syscalls") );
90 printf( " -v, --version %s\n", _("Print the lxdream version string") );
91 printf( " -V, --video=DRIVER %s\n", _("Use the specified video driver (? to list)") );
92 printf( " -x %s\n", _("Disable the SH4 translator") );
93 }
95 void bind_gettext_domain()
96 {
97 #ifdef ENABLE_NLS
98 bindtextdomain( PACKAGE, get_locale_path() );
99 textdomain(PACKAGE);
100 #endif
101 }
103 int main (int argc, char *argv[])
104 {
105 int opt;
106 double t;
107 gboolean display_ok;
108 uint32_t time_secs, time_nanos;
110 install_crash_handler();
111 bind_gettext_domain();
112 display_ok = gui_parse_cmdline(&argc, &argv);
114 while( (opt = getopt_long( argc, argv, option_list, longopts, NULL )) != -1 ) {
115 switch( opt ) {
116 case 'a': /* AICA only mode - argument is an AICA program */
117 aica_program = optarg;
118 break;
119 case 'A': /* Audio driver */
120 audio_driver_name = optarg;
121 if( strcmp(audio_driver_name, "?") == 0 ) {
122 print_version();
123 print_audio_drivers(stdout);
124 exit(0);
125 }
126 break;
127 case 'c': /* Config file */
128 lxdream_set_config_filename(optarg);
129 break;
130 case 'd': /* Launch w/ debugger */
131 show_debugger = TRUE;
132 break;
133 case 'h': /* help */
134 case '?':
135 print_usage();
136 exit(0);
137 break;
138 case 'H': /* Headless - shorthand for -V null */
139 display_driver_name = "null";
140 break;
141 case 'l': /* Log verbosity */
142 if( !set_global_log_level(optarg) ) {
143 ERROR( "Unrecognized log level '%s'", optarg );
144 }
145 break;
146 case 'm': /* Set SH4 CPU clock multiplier (default 0.5) */
147 t = strtod(optarg, NULL);
148 sh4_cpu_multiplier = (int)(1000.0/t);
149 break;
150 case 'n': /* Don't start immediately */
151 no_start = TRUE;
152 start_immediately = FALSE;
153 break;
154 case 'p': /* Start immediately */
155 start_immediately = TRUE;
156 no_start = FALSE;
157 break;
158 case 't': /* Time limit + auto quit */
159 t = strtod(optarg, NULL);
160 time_secs = (uint32_t)t;
161 time_nanos = (int)((t - time_secs) * 1000000000);
162 dreamcast_set_run_time( time_secs, time_nanos );
163 dreamcast_set_exit_on_stop( TRUE );
164 break;
165 case 'T': /* trace regions */
166 trace_regions = optarg;
167 set_global_log_level("trace");
168 break;
169 case 'u': /* Allow unsafe dcload syscalls */
170 dcload_set_allow_unsafe(TRUE);
171 break;
172 case 'v':
173 print_version();
174 exit(0);
175 break;
176 case 'V': /* Video driver */
177 display_driver_name = optarg;
178 if( strcmp(display_driver_name,"?") == 0 ) {
179 print_version();
180 print_display_drivers(stdout);
181 exit(0);
182 }
183 break;
184 case 'x': /* Disable translator */
185 use_xlat = FALSE;
186 break;
187 }
188 }
190 lxdream_load_config( );
191 gdrom_list_init();
193 if( aica_program == NULL ) {
194 dreamcast_init();
195 } else {
196 dreamcast_configure_aica_only();
197 mem_load_block( aica_program, 0x00800000, 2048*1024 );
198 }
199 mem_set_trace( trace_regions, TRUE );
201 audio_init_driver( audio_driver_name );
203 headless = display_driver_name != NULL && strcasecmp( display_driver_name, "null" ) == 0;
204 if( headless ) {
205 display_set_driver( &display_null_driver );
206 } else {
207 gui_init(show_debugger);
209 display_driver_t display_driver = get_display_driver_by_name(display_driver_name);
210 if( display_driver == NULL ) {
211 ERROR( "Video driver '%s' not found, aborting.", display_driver_name );
212 exit(2);
213 } else if( display_set_driver( display_driver ) == FALSE ) {
214 ERROR( "Video driver '%s' failed to initialize (could not connect to display?)",
215 display_driver->name );
216 exit(2);
217 }
218 }
220 maple_reattach_all();
221 INFO( "%s! ready...", APP_NAME );
223 for( ; optind < argc; optind++ ) {
224 gboolean ok = gdrom_mount_image(argv[optind]);
225 if( !ok ) {
226 ok = file_load_magic( argv[optind] );
227 }
228 if( !ok ) {
229 ERROR( "Unrecognized file '%s'", argv[optind] );
230 }
231 if( !no_start ) {
232 start_immediately = ok;
233 }
234 }
236 if( gdrom_get_current_disc() == NULL ) {
237 const gchar *disc_file = lxdream_get_config_value( CONFIG_GDROM );
238 if( disc_file != NULL ) {
239 gdrom_mount_image( disc_file );
240 }
241 }
243 sh4_translate_set_enabled( use_xlat );
245 if( headless ) {
246 dreamcast_run();
247 } else {
248 gui_main_loop( start_immediately && dreamcast_can_run() );
249 }
250 dreamcast_shutdown();
251 return 0;
252 }
.