filename | src/main.c |
changeset | 772:c0b5928dd600 |
prev | 759:f16975739abc |
next | 866:86cd01c2b2d3 |
author | nkeynes |
date | Mon Sep 08 11:23:32 2008 +0000 (15 years ago) |
permissions | -rw-r--r-- |
last change | As long as we've broken save-state compatibility anyway, remove the two FIXME padding words, and bump the version number |
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"
38 #ifdef APPLE_BUILD
39 #include <AppKit/AppKit.h>
40 #endif
42 char *option_list = "a:A:c:dhHl:m:npt:T:uvV:x?";
43 struct option longopts[] = {
44 { "aica", required_argument, NULL, 'a' },
45 { "audio", required_argument, NULL, 'A' },
46 { "config", required_argument, NULL, 'c' },
47 { "debugger", no_argument, NULL, 'D' },
48 { "help", no_argument, NULL, 'h' },
49 { "headless", no_argument, NULL, 'H' },
50 { "log", required_argument, NULL,'l' },
51 { "multiplier", required_argument, NULL, 'm' },
52 { "run-time", required_argument, NULL, 't' },
53 { "trace", required_argument, NULL, 'T' },
54 { "unsafe", no_argument, NULL, 'u' },
55 { "video", no_argument, NULL, 'V' },
56 { "version", no_argument, NULL, 'v' },
57 { NULL, 0, 0, 0 } };
58 char *aica_program = NULL;
59 char *display_driver_name = NULL;
60 char *audio_driver_name = NULL;
61 char *trace_regions = NULL;
62 gboolean start_immediately = FALSE;
63 gboolean no_start = FALSE;
64 gboolean headless = FALSE;
65 gboolean use_xlat = TRUE;
66 gboolean show_debugger = FALSE;
67 extern uint32_t sh4_cpu_multiplier;
69 void print_version()
70 {
71 printf( "lxdream %s\n", lxdream_full_version );
72 }
74 void print_usage()
75 {
76 print_version();
77 printf( "Usage: lxdream %s [options] [disc-file] [program-file]\n\n", lxdream_full_version );
79 printf( "Options:\n" );
80 printf( " -a, --aica=PROGFILE %s\n", _("Run the AICA SPU only, with the supplied program") );
81 printf( " -A, --audio=DRIVER %s\n", _("Use the specified audio driver (? to list)") );
82 printf( " -c, --config=CONFFILE %s\n", _("Load configuration from CONFFILE") );
83 printf( " -d, --debugger %s\n", _("Start in debugger mode") );
84 printf( " -h, --help %s\n", _("Display this usage information") );
85 printf( " -H, --headless %s\n", _("Run in headless (no video) mode") );
86 printf( " -l, --log=LEVEL %s\n", _("Set the output log level") );
87 printf( " -m, --multiplier=SCALE %s\n", _("Set the SH4 multiplier (1.0 = fullspeed)") );
88 printf( " -n %s\n", _("Don't start running immediately") );
89 printf( " -p %s\n", _("Start running immediately on startup") );
90 printf( " -t, --run-time=SECONDS %s\n", _("Run for the specified number of seconds") );
91 printf( " -T, --trace=REGIONS %s\n", _("Output trace information for the named regions") );
92 printf( " -u, --unsafe %s\n", _("Allow unsafe dcload syscalls") );
93 printf( " -v, --version %s\n", _("Print the lxdream version string") );
94 printf( " -V, --video=DRIVER %s\n", _("Use the specified video driver (? to list)") );
95 printf( " -x %s\n", _("Disable the SH4 translator") );
96 }
98 void bind_gettext_domain()
99 {
100 #ifdef ENABLE_NLS
101 #ifdef APPLE_BUILD
102 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
103 NSString *resourcePath = [[NSBundle mainBundle] resourcePath];
104 bindtextdomain( PACKAGE, [resourcePath UTF8String] );
105 #ifdef HAVE_BIND_TEXTDOMAIN_CODESET
106 bind_textdomain_codeset( PACKAGE, "UTF-8" );
107 #endif
108 [pool release];
109 #else
110 bindtextdomain (PACKAGE, PACKAGE_LOCALE_DIR);
111 #endif
112 textdomain(PACKAGE);
114 #endif
115 }
117 int main (int argc, char *argv[])
118 {
119 int opt;
120 double t;
121 gboolean display_ok;
122 uint32_t time_secs, time_nanos;
124 install_crash_handler();
125 bind_gettext_domain();
126 display_ok = gui_parse_cmdline(&argc, &argv);
128 while( (opt = getopt_long( argc, argv, option_list, longopts, NULL )) != -1 ) {
129 switch( opt ) {
130 case 'a': /* AICA only mode - argument is an AICA program */
131 aica_program = optarg;
132 break;
133 case 'A': /* Audio driver */
134 audio_driver_name = optarg;
135 if( strcmp(audio_driver_name, "?") == 0 ) {
136 print_version();
137 print_audio_drivers(stdout);
138 exit(0);
139 }
140 break;
141 case 'c': /* Config file */
142 lxdream_set_config_filename(optarg);
143 break;
144 case 'd': /* Launch w/ debugger */
145 show_debugger = TRUE;
146 break;
147 case 'h': /* help */
148 case '?':
149 print_usage();
150 exit(0);
151 break;
152 case 'H': /* Headless - shorthand for -V null */
153 display_driver_name = "null";
154 break;
155 case 'l': /* Log verbosity */
156 if( !set_global_log_level(optarg) ) {
157 ERROR( "Unrecognized log level '%s'", optarg );
158 }
159 break;
160 case 'm': /* Set SH4 CPU clock multiplier (default 0.5) */
161 t = strtod(optarg, NULL);
162 sh4_cpu_multiplier = (int)(1000.0/t);
163 break;
164 case 'n': /* Don't start immediately */
165 no_start = TRUE;
166 start_immediately = FALSE;
167 break;
168 case 'p': /* Start immediately */
169 start_immediately = TRUE;
170 no_start = FALSE;
171 break;
172 case 't': /* Time limit + auto quit */
173 t = strtod(optarg, NULL);
174 time_secs = (uint32_t)t;
175 time_nanos = (int)((t - time_secs) * 1000000000);
176 dreamcast_set_run_time( time_secs, time_nanos );
177 dreamcast_set_exit_on_stop( TRUE );
178 break;
179 case 'T': /* trace regions */
180 trace_regions = optarg;
181 set_global_log_level("trace");
182 break;
183 case 'u': /* Allow unsafe dcload syscalls */
184 dcload_set_allow_unsafe(TRUE);
185 break;
186 case 'v':
187 print_version();
188 exit(0);
189 break;
190 case 'V': /* Video driver */
191 display_driver_name = optarg;
192 if( strcmp(display_driver_name,"?") == 0 ) {
193 print_version();
194 print_display_drivers(stdout);
195 exit(0);
196 }
197 break;
198 case 'x': /* Disable translator */
199 use_xlat = FALSE;
200 break;
201 }
202 }
204 lxdream_load_config( );
205 gdrom_list_init();
207 if( aica_program == NULL ) {
208 dreamcast_init();
209 } else {
210 dreamcast_configure_aica_only();
211 mem_load_block( aica_program, 0x00800000, 2048*1024 );
212 }
213 mem_set_trace( trace_regions, TRUE );
215 audio_init_driver( audio_driver_name );
217 headless = display_driver_name != NULL && strcasecmp( display_driver_name, "null" ) == 0;
218 if( headless ) {
219 display_set_driver( &display_null_driver );
220 } else {
221 gui_init(show_debugger);
223 display_driver_t display_driver = get_display_driver_by_name(display_driver_name);
224 if( display_driver == NULL ) {
225 ERROR( "Video driver '%s' not found, aborting.", display_driver_name );
226 exit(2);
227 } else if( display_set_driver( display_driver ) == FALSE ) {
228 ERROR( "Video driver '%s' failed to initialize (could not connect to display?)",
229 display_driver->name );
230 exit(2);
231 }
232 }
234 maple_reattach_all();
235 INFO( "%s! ready...", APP_NAME );
237 for( ; optind < argc; optind++ ) {
238 gboolean ok = gdrom_mount_image(argv[optind]);
239 if( !ok ) {
240 ok = file_load_magic( argv[optind] );
241 }
242 if( !ok ) {
243 ERROR( "Unrecognized file '%s'", argv[optind] );
244 }
245 if( !no_start ) {
246 start_immediately = ok;
247 }
248 }
250 if( gdrom_get_current_disc() == NULL ) {
251 const gchar *disc_file = lxdream_get_config_value( CONFIG_GDROM );
252 if( disc_file != NULL ) {
253 gdrom_mount_image( disc_file );
254 }
255 }
257 sh4_translate_set_enabled( use_xlat );
259 if( headless ) {
260 dreamcast_run();
261 } else {
262 gui_main_loop( start_immediately && dreamcast_can_run() );
263 }
264 dreamcast_shutdown();
265 return 0;
266 }
.