Search
lxdream.org :: lxdream/src/main.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/main.c
changeset 700:4650d0c7f6f9
prev698:6d9fd7f54609
next708:0b8b5eaa3b52
author nkeynes
date Sun Jun 22 06:49:00 2008 +0000 (13 years ago)
permissions -rw-r--r--
last change Big cleanup of the command-line options
Add an actual manpage (*gasp*)
file annotate diff log raw
1.1 --- a/src/main.c Sun Jun 22 04:30:38 2008 +0000
1.2 +++ b/src/main.c Sun Jun 22 06:49:00 2008 +0000
1.3 @@ -33,24 +33,62 @@
1.4 #include "maple/maple.h"
1.5 #include "sh4/sh4.h"
1.6
1.7 -#define S3M_PLAYER "s3mplay.bin"
1.8 -
1.9 -char *option_list = "a:m:s:A:V:v:puhbd:c:t:T:xDn";
1.10 -struct option longopts[1] = { { NULL, 0, 0, 0 } };
1.11 +char *option_list = "a:A:c:dhHl:m:npt:T:uvV:x?";
1.12 +struct option longopts[] = {
1.13 + { "aica", required_argument, NULL, 'a' },
1.14 + { "audio", required_argument, NULL, 'A' },
1.15 + { "config", required_argument, NULL, 'c' },
1.16 + { "debugger", no_argument, NULL, 'D' },
1.17 + { "help", no_argument, NULL, 'h' },
1.18 + { "headless", no_argument, NULL, 'H' },
1.19 + { "log", required_argument, NULL,'l' },
1.20 + { "multiplier", required_argument, NULL, 'm' },
1.21 + { "run-time", required_argument, NULL, 't' },
1.22 + { "trace", required_argument, NULL, 'T' },
1.23 + { "unsafe", no_argument, NULL, 'u' },
1.24 + { "video", no_argument, NULL, 'V' },
1.25 + { "version", no_argument, NULL, 'v' },
1.26 + { NULL, 0, 0, 0 } };
1.27 char *aica_program = NULL;
1.28 -char *s3m_file = NULL;
1.29 -const char *disc_file = NULL;
1.30 char *display_driver_name = NULL;
1.31 char *audio_driver_name = NULL;
1.32 char *trace_regions = NULL;
1.33 gboolean start_immediately = FALSE;
1.34 gboolean no_start = FALSE;
1.35 gboolean headless = FALSE;
1.36 -gboolean without_bios = FALSE;
1.37 gboolean use_xlat = TRUE;
1.38 gboolean show_debugger = FALSE;
1.39 extern uint32_t sh4_cpu_multiplier;
1.40
1.41 +void print_version()
1.42 +{
1.43 + printf( "lxdream " APP_VERSION "\n" );
1.44 +}
1.45 +
1.46 +void print_usage()
1.47 +{
1.48 + print_version();
1.49 + printf( "Usage: lxdream [options] [disc-file] [program-file]\n\n" );
1.50 +
1.51 + printf( "Options:\n" );
1.52 + printf( " -a, --aica=PROGFILE %s\n", _("Run the AICA SPU only, with the supplied program") );
1.53 + printf( " -A, --audio=DRIVER %s\n", _("Use the specified audio driver (? to list)") );
1.54 + printf( " -c, --config=CONFFILE %s\n", _("Load configuration from CONFFILE") );
1.55 + printf( " -d, --debugger %s\n", _("Start in debugger mode") );
1.56 + printf( " -h, --help %s\n", _("Display this usage information") );
1.57 + printf( " -H, --headless %s\n", _("Run in headless (no video) mode") );
1.58 + printf( " -l, --log=LEVEL %s\n", _("Set the output log level") );
1.59 + printf( " -m, --multiplier=SCALE %s\n", _("Set the SH4 multiplier (1.0 = fullspeed)") );
1.60 + printf( " -n %s\n", _("Don't start running immediately") );
1.61 + printf( " -p %s\n", _("Start running immediately on startup") );
1.62 + printf( " -t, --run-time=SECONDS %s\n", _("Run for the specified number of seconds") );
1.63 + printf( " -T, --trace=REGIONS %s\n", _("Output trace information for the named regions") );
1.64 + printf( " -u, --unsafe %s\n", _("Allow unsafe dcload syscalls") );
1.65 + printf( " -v, --version %s\n", _("Print the lxdream version string") );
1.66 + printf( " -V, --video=DRIVER %s\n", _("Use the specified video driver (? to list)") );
1.67 + printf( " -x %s\n", _("Disable the SH4 translator") );
1.68 +}
1.69 +
1.70 int main (int argc, char *argv[])
1.71 {
1.72 int opt;
1.73 @@ -71,15 +109,33 @@
1.74 case 'a': /* AICA only mode - argument is an AICA program */
1.75 aica_program = optarg;
1.76 break;
1.77 + case 'A': /* Audio driver */
1.78 + audio_driver_name = optarg;
1.79 + if( strcmp(audio_driver_name, "?") == 0 ) {
1.80 + print_version();
1.81 + print_audio_drivers(stdout);
1.82 + exit(0);
1.83 + }
1.84 + break;
1.85 case 'c': /* Config file */
1.86 lxdream_set_config_filename(optarg);
1.87 break;
1.88 - case 'd': /* Mount disc */
1.89 - disc_file = optarg;
1.90 - break;
1.91 - case 'D': /* Launch w/ debugger */
1.92 + case 'd': /* Launch w/ debugger */
1.93 show_debugger = TRUE;
1.94 break;
1.95 + case 'h': /* help */
1.96 + case '?':
1.97 + print_usage();
1.98 + exit(0);
1.99 + break;
1.100 + case 'H': /* Headless - shorthand for -V null */
1.101 + display_driver_name = "null";
1.102 + break;
1.103 + case 'l': /* Log verbosity */
1.104 + if( !set_global_log_level(optarg) ) {
1.105 + ERROR( "Unrecognized log level '%s'", optarg );
1.106 + }
1.107 + break;
1.108 case 'm': /* Set SH4 CPU clock multiplier (default 0.5) */
1.109 t = strtod(optarg, NULL);
1.110 sh4_cpu_multiplier = (int)(1000.0/t);
1.111 @@ -88,29 +144,10 @@
1.112 no_start = TRUE;
1.113 start_immediately = FALSE;
1.114 break;
1.115 - case 's': /* AICA-only w/ S3M player */
1.116 - aica_program = S3M_PLAYER;
1.117 - s3m_file = optarg;
1.118 - break;
1.119 - case 'A': /* Audio driver */
1.120 - audio_driver_name = optarg;
1.121 - break;
1.122 - case 'V': /* Video driver */
1.123 - display_driver_name = optarg;
1.124 - break;
1.125 case 'p': /* Start immediately */
1.126 start_immediately = TRUE;
1.127 no_start = FALSE;
1.128 - break;
1.129 - case 'u': /* Allow unsafe dcload syscalls */
1.130 - dcload_set_allow_unsafe(TRUE);
1.131 break;
1.132 - case 'b': /* No BIOS */
1.133 - without_bios = TRUE;
1.134 - break;
1.135 - case 'h': /* Headless */
1.136 - headless = TRUE;
1.137 - break;
1.138 case 't': /* Time limit + auto quit */
1.139 t = strtod(optarg, NULL);
1.140 time_secs = (uint32_t)t;
1.141 @@ -122,11 +159,21 @@
1.142 trace_regions = optarg;
1.143 set_global_log_level("trace");
1.144 break;
1.145 - case 'v': /* Log verbosity */
1.146 - if( !set_global_log_level(optarg) ) {
1.147 - ERROR( "Unrecognized log level '%s'", optarg );
1.148 - }
1.149 + case 'u': /* Allow unsafe dcload syscalls */
1.150 + dcload_set_allow_unsafe(TRUE);
1.151 + break;
1.152 + case 'v':
1.153 + print_version();
1.154 + exit(0);
1.155 break;
1.156 + case 'V': /* Video driver */
1.157 + display_driver_name = optarg;
1.158 + if( strcmp(display_driver_name,"?") == 0 ) {
1.159 + print_version();
1.160 + print_display_drivers(stdout);
1.161 + exit(0);
1.162 + }
1.163 + break;
1.164 case 'x': /* Disable translator */
1.165 use_xlat = FALSE;
1.166 break;
1.167 @@ -137,61 +184,50 @@
1.168 gdrom_list_init();
1.169
1.170 if( aica_program == NULL ) {
1.171 - dreamcast_init();
1.172 + dreamcast_init();
1.173 } else {
1.174 - dreamcast_configure_aica_only();
1.175 - mem_load_block( aica_program, 0x00800000, 2048*1024 );
1.176 - if( s3m_file != NULL ) {
1.177 - mem_load_block( s3m_file, 0x00810000, 2048*1024 - 0x10000 );
1.178 - }
1.179 + dreamcast_configure_aica_only();
1.180 + mem_load_block( aica_program, 0x00800000, 2048*1024 );
1.181 }
1.182 mem_set_trace( trace_regions, TRUE );
1.183
1.184 - if( without_bios ) {
1.185 - bios_install();
1.186 - dcload_install();
1.187 - }
1.188 -
1.189 audio_init_driver( audio_driver_name, 44100, AUDIO_FMT_16ST );
1.190
1.191 + headless = display_driver_name != NULL && strcasecmp( display_driver_name, "null" ) == 0;
1.192 if( headless ) {
1.193 - display_set_driver( &display_null_driver );
1.194 + display_set_driver( &display_null_driver );
1.195 } else {
1.196 - gui_init(show_debugger);
1.197 + gui_init(show_debugger);
1.198
1.199 - display_driver_t display_driver = get_display_driver_by_name(display_driver_name);
1.200 - if( display_driver == NULL ) {
1.201 - ERROR( "Video driver '%s' not found, aborting.", display_driver_name );
1.202 - exit(2);
1.203 - } else if( display_set_driver( display_driver ) == FALSE ) {
1.204 - ERROR( "Video driver '%s' failed to initialize (could not connect to display?)",
1.205 - display_driver->name );
1.206 - exit(2);
1.207 - }
1.208 + display_driver_t display_driver = get_display_driver_by_name(display_driver_name);
1.209 + if( display_driver == NULL ) {
1.210 + ERROR( "Video driver '%s' not found, aborting.", display_driver_name );
1.211 + exit(2);
1.212 + } else if( display_set_driver( display_driver ) == FALSE ) {
1.213 + ERROR( "Video driver '%s' failed to initialize (could not connect to display?)",
1.214 + display_driver->name );
1.215 + exit(2);
1.216 + }
1.217 }
1.218
1.219 maple_reattach_all();
1.220 INFO( "%s! ready...", APP_NAME );
1.221
1.222 for( ; optind < argc; optind++ ) {
1.223 - gboolean ok = gdrom_mount_image(argv[optind]);
1.224 - if( !ok ) {
1.225 - ok = file_load_magic( argv[optind] );
1.226 - }
1.227 - if( !ok ) {
1.228 - ERROR( "Unrecognized file '%s'", argv[optind] );
1.229 - }
1.230 - if( !no_start ) {
1.231 - start_immediately = ok;
1.232 - }
1.233 - }
1.234 -
1.235 - if( disc_file != NULL ) {
1.236 - gdrom_mount_image( disc_file );
1.237 + gboolean ok = gdrom_mount_image(argv[optind]);
1.238 + if( !ok ) {
1.239 + ok = file_load_magic( argv[optind] );
1.240 + }
1.241 + if( !ok ) {
1.242 + ERROR( "Unrecognized file '%s'", argv[optind] );
1.243 + }
1.244 + if( !no_start ) {
1.245 + start_immediately = ok;
1.246 + }
1.247 }
1.248
1.249 if( gdrom_get_current_disc() == NULL ) {
1.250 - disc_file = lxdream_get_config_value( CONFIG_GDROM );
1.251 + const gchar *disc_file = lxdream_get_config_value( CONFIG_GDROM );
1.252 if( disc_file != NULL ) {
1.253 gdrom_mount_image( disc_file );
1.254 }
.