filename | src/main.c |
changeset | 1027:4e527bc96109 |
prev | 1024:c67f2d61ab97 |
next | 1034:7044e01148f0 |
author | nkeynes |
date | Sat Jun 13 07:12:51 2009 +0000 (14 years ago) |
permissions | -rw-r--r-- |
last change | Load plugins from the directory containing the executable first if they're there - simplifies development testing. Add dummy plugin for easy identification of the plugin directory |
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"
37 #include "aica/armdasm.h"
38 #include "hotkeys.h"
39 #include "plugin.h"
41 char *option_list = "a:A:c:dfg:G:hHl:m:npt:T:uvV:x?";
42 struct option longopts[] = {
43 { "aica", required_argument, NULL, 'a' },
44 { "audio", required_argument, NULL, 'A' },
45 { "config", required_argument, NULL, 'c' },
46 { "debugger", no_argument, NULL, 'D' },
47 { "fullscreen", no_argument, NULL, 'f' },
48 { "gdb-sh4", required_argument, NULL, 'g' },
49 { "gdb-arm", required_argument, NULL, 'G' },
50 { "help", no_argument, NULL, 'h' },
51 { "headless", no_argument, NULL, 'H' },
52 { "log", required_argument, NULL,'l' },
53 { "multiplier", required_argument, NULL, 'm' },
54 { "run-time", required_argument, NULL, 't' },
55 { "trace", required_argument, NULL, 'T' },
56 { "unsafe", no_argument, NULL, 'u' },
57 { "video", no_argument, NULL, 'V' },
58 { "version", no_argument, NULL, 'v' },
59 { NULL, 0, 0, 0 } };
60 char *aica_program = NULL;
61 char *display_driver_name = NULL;
62 char *audio_driver_name = NULL;
63 char *trace_regions = NULL;
64 char *sh4_gdb_port = NULL;
65 char *arm_gdb_port = NULL;
66 gboolean start_immediately = FALSE;
67 gboolean no_start = FALSE;
68 gboolean headless = FALSE;
69 gboolean use_xlat = TRUE;
70 gboolean show_debugger = FALSE;
71 gboolean show_fullscreen = FALSE;
72 extern uint32_t sh4_cpu_multiplier;
74 static void print_version()
75 {
76 printf( "lxdream %s\n", lxdream_full_version );
77 }
79 static void print_usage()
80 {
81 print_version();
82 printf( "Usage: lxdream %s [options] [disc-file] [program-file]\n\n", lxdream_full_version );
84 printf( "Options:\n" );
85 printf( " -a, --aica=PROGFILE %s\n", _("Run the AICA SPU only, with the supplied program") );
86 printf( " -A, --audio=DRIVER %s\n", _("Use the specified audio driver (? to list)") );
87 printf( " -c, --config=CONFFILE %s\n", _("Load configuration from CONFFILE") );
88 printf( " -d, --debugger %s\n", _("Start in debugger mode") );
89 printf( " -f, --fullscreen %s\n", _("Start in fullscreen mode") );
90 printf( " -g, --gdb-sh4=PORT %s\n", _("Start GDB remote server on PORT for SH4") );
91 printf( " -G, --gdb-arm=PORT %s\n", _("Start GDB remote server on PORT for ARM") );
92 printf( " -h, --help %s\n", _("Display this usage information") );
93 printf( " -H, --headless %s\n", _("Run in headless (no video) mode") );
94 printf( " -l, --log=LEVEL %s\n", _("Set the output log level") );
95 printf( " -m, --multiplier=SCALE %s\n", _("Set the SH4 multiplier (1.0 = fullspeed)") );
96 printf( " -n %s\n", _("Don't start running immediately") );
97 printf( " -p %s\n", _("Start running immediately on startup") );
98 printf( " -t, --run-time=SECONDS %s\n", _("Run for the specified number of seconds") );
99 printf( " -T, --trace=REGIONS %s\n", _("Output trace information for the named regions") );
100 printf( " -u, --unsafe %s\n", _("Allow unsafe dcload syscalls") );
101 printf( " -v, --version %s\n", _("Print the lxdream version string") );
102 printf( " -V, --video=DRIVER %s\n", _("Use the specified video driver (? to list)") );
103 printf( " -x %s\n", _("Disable the SH4 translator") );
104 }
106 static void bind_gettext_domain()
107 {
108 #ifdef ENABLE_NLS
109 bindtextdomain( PACKAGE, get_locale_path() );
110 textdomain(PACKAGE);
111 #endif
112 }
114 int main (int argc, char *argv[])
115 {
116 int opt;
117 double t;
118 gboolean display_ok;
119 uint32_t time_secs, time_nanos;
121 install_crash_handler();
122 bind_gettext_domain();
123 display_ok = gui_parse_cmdline(&argc, &argv);
125 while( (opt = getopt_long( argc, argv, option_list, longopts, NULL )) != -1 ) {
126 switch( opt ) {
127 case 'a': /* AICA only mode - argument is an AICA program */
128 aica_program = optarg;
129 break;
130 case 'A': /* Audio driver */
131 audio_driver_name = optarg;
132 break;
133 case 'c': /* Config file */
134 lxdream_set_config_filename(optarg);
135 break;
136 case 'd': /* Launch w/ debugger */
137 show_debugger = TRUE;
138 break;
139 case 'f':
140 show_fullscreen = TRUE;
141 break;
142 case 'g':
143 sh4_gdb_port = optarg;
144 break;
145 case 'G':
146 arm_gdb_port = optarg;
147 break;
148 case 'h': /* help */
149 case '?':
150 print_usage();
151 exit(0);
152 break;
153 case 'H': /* Headless - shorthand for -V null */
154 display_driver_name = "null";
155 break;
156 case 'l': /* Log verbosity */
157 if( !set_global_log_level(optarg) ) {
158 ERROR( "Unrecognized log level '%s'", optarg );
159 }
160 break;
161 case 'm': /* Set SH4 CPU clock multiplier (default 0.5) */
162 t = strtod(optarg, NULL);
163 sh4_cpu_multiplier = (int)(1000.0/t);
164 break;
165 case 'n': /* Don't start immediately */
166 no_start = TRUE;
167 start_immediately = FALSE;
168 break;
169 case 'p': /* Start immediately */
170 start_immediately = TRUE;
171 no_start = FALSE;
172 break;
173 case 't': /* Time limit + auto quit */
174 t = strtod(optarg, NULL);
175 time_secs = (uint32_t)t;
176 time_nanos = (int)((t - time_secs) * 1000000000);
177 dreamcast_set_run_time( time_secs, time_nanos );
178 dreamcast_set_exit_on_stop( TRUE );
179 break;
180 case 'T': /* trace regions */
181 trace_regions = optarg;
182 set_global_log_level("trace");
183 break;
184 case 'u': /* Allow unsafe dcload syscalls */
185 dcload_set_allow_unsafe(TRUE);
186 break;
187 case 'v':
188 print_version();
189 exit(0);
190 break;
191 case 'V': /* Video driver */
192 display_driver_name = optarg;
193 break;
194 case 'x': /* Disable translator */
195 use_xlat = FALSE;
196 break;
197 }
198 }
200 #ifdef ENABLE_SHARED
201 plugin_init();
202 #endif
204 lxdream_load_config( );
206 if( audio_driver_name != NULL && strcmp(audio_driver_name, "?") == 0 ) {
207 print_version();
208 print_audio_drivers(stdout);
209 exit(0);
210 }
212 if( display_driver_name != NULL && strcmp(display_driver_name,"?") == 0 ) {
213 print_version();
214 print_display_drivers(stdout);
215 exit(0);
216 }
218 gdrom_list_init();
220 if( aica_program == NULL ) {
221 dreamcast_init();
222 } else {
223 dreamcast_configure_aica_only();
224 mem_load_block( aica_program, 0x00800000, 2048*1024 );
225 }
226 mem_set_trace( trace_regions, TRUE );
228 audio_init_driver( audio_driver_name );
230 headless = display_driver_name != NULL && strcasecmp( display_driver_name, "null" ) == 0;
231 if( headless ) {
232 display_set_driver( &display_null_driver );
233 } else {
234 gui_init(show_debugger, show_fullscreen);
236 display_driver_t display_driver = get_display_driver_by_name(display_driver_name);
237 if( display_driver == NULL ) {
238 ERROR( "Video driver '%s' not found, aborting.", display_driver_name );
239 exit(2);
240 } else if( display_set_driver( display_driver ) == FALSE ) {
241 ERROR( "Video driver '%s' failed to initialize (could not connect to display?)",
242 display_driver->name );
243 exit(2);
244 }
245 }
247 hotkeys_init();
249 maple_reattach_all();
250 INFO( "%s! ready...", APP_NAME );
252 for( ; optind < argc; optind++ ) {
253 gboolean ok = gdrom_mount_image(argv[optind]);
254 if( !ok ) {
255 ok = file_load_magic( argv[optind] );
256 }
257 if( !ok ) {
258 ERROR( "Unrecognized file '%s'", argv[optind] );
259 }
260 if( !no_start ) {
261 start_immediately = ok;
262 }
263 }
265 if( gdrom_get_current_disc() == NULL ) {
266 const gchar *disc_file = lxdream_get_config_value( CONFIG_GDROM );
267 if( disc_file != NULL ) {
268 gdrom_mount_image( disc_file );
269 }
270 }
272 sh4_translate_set_enabled( use_xlat );
274 /* If requested, start the gdb server immediately before we go into the main
275 * loop.
276 */
277 if( sh4_gdb_port != NULL ) {
278 gdb_init_server( NULL, strtol(sh4_gdb_port,NULL,0), &sh4_cpu_desc, TRUE );
279 }
280 if( arm_gdb_port != NULL ) {
281 gdb_init_server( NULL, strtol(arm_gdb_port,NULL,0), &arm_cpu_desc, TRUE );
282 }
284 if( headless ) {
285 dreamcast_run();
286 } else {
287 gui_main_loop( start_immediately && dreamcast_can_run() );
288 }
289 dreamcast_shutdown();
290 return 0;
291 }
.