Search
lxdream.org :: lxdream/src/main.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/main.c
changeset 446:def93c34c84c
prev435:7a5d71e8560b
next450:207461e79f21
author nkeynes
date Tue Oct 16 12:28:42 2007 +0000 (14 years ago)
permissions -rw-r--r--
last change Change command line handling to not require -d
view annotate diff log raw
     1 /**
     2  * $Id: main.c,v 1.29 2007-10-16 12:28:42 nkeynes Exp $
     3  *
     4  * Main program, initializes dreamcast and gui, then passes control off to
     5  * the gtk main loop (currently). 
     6  *
     7  * FIXME: Remove explicit GTK/Gnome references from this file
     8  *
     9  * Copyright (c) 2005 Nathan Keynes.
    10  *
    11  * This program is free software; you can redistribute it and/or modify
    12  * it under the terms of the GNU General Public License as published by
    13  * the Free Software Foundation; either version 2 of the License, or
    14  * (at your option) any later version.
    15  *
    16  * This program is distributed in the hope that it will be useful,
    17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    19  * GNU General Public License for more details.
    20  */
    22 #ifdef HAVE_CONFIG_H
    23 #  include <config.h>
    24 #endif
    25 #include <unistd.h>
    26 #include <getopt.h>
    27 #include "gui.h"
    28 #include "dream.h"
    29 #include "syscall.h"
    30 #include "mem.h"
    31 #include "dreamcast.h"
    32 #include "display.h"
    33 #include "loader.h"
    34 #include "aica/audio.h"
    35 #include "gdrom/gdrom.h"
    36 #include "maple/maple.h"
    37 #include "sh4/sh4core.h"
    39 #define S3M_PLAYER "s3mplay.bin"
    41 char *option_list = "a:m:s:A:V:puhbd:c:t:xD";
    42 struct option longopts[1] = { { NULL, 0, 0, 0 } };
    43 char *aica_program = NULL;
    44 char *s3m_file = NULL;
    45 char *disc_file = NULL;
    46 char *display_driver_name = "gtk";
    47 char *audio_driver_name = "esd";
    48 char *config_file = DEFAULT_CONFIG_FILENAME;
    49 gboolean start_immediately = FALSE;
    50 gboolean headless = FALSE;
    51 gboolean without_bios = FALSE;
    52 gboolean use_xlat = TRUE;
    53 gboolean show_debugger = FALSE;
    54 uint32_t time_secs = 0;
    55 uint32_t time_nanos = 0;
    56 extern uint32_t sh4_cpu_multiplier;
    58 audio_driver_t audio_driver_list[] = { &audio_null_driver,
    59 				       &audio_esd_driver,
    60 				       NULL };
    62 display_driver_t display_driver_list[] = { &display_null_driver,
    63 					   &display_gtk_driver,
    64 					   NULL };
    66 int main (int argc, char *argv[])
    67 {
    68     int opt, i;
    69     double t;
    70 #ifdef ENABLE_NLS
    71     bindtextdomain (PACKAGE, PACKAGE_LOCALE_DIR);
    72     textdomain (PACKAGE);
    73 #endif
    74     gboolean ui_initialized = gui_parse_cmdline(&argc, &argv);
    76     while( (opt = getopt_long( argc, argv, option_list, longopts, NULL )) != -1 ) {
    77 	switch( opt ) {
    78 	case 'a': /* AICA only mode - argument is an AICA program */
    79 	    aica_program = optarg;
    80 	    break;
    81 	case 'c': /* Config file */
    82 	    config_file = optarg;
    83 	    break;
    84 	case 'd': /* Mount disc */
    85 	    disc_file = optarg;
    86 	    break;
    87 	case 'D': /* Launch w/ debugger */
    88 	    show_debugger = TRUE;
    89 	    break;
    90 	case 'm': /* Set SH4 CPU clock multiplier (default 0.5) */
    91 	    t = strtod(optarg, NULL);
    92 	    sh4_cpu_multiplier = (int)(1000.0/t);
    93 	    break;
    94 	case 's': /* AICA-only w/ S3M player */
    95 	    aica_program = S3M_PLAYER;
    96 	    s3m_file = optarg;
    97 	    break;
    98 	case 'A': /* Audio driver */
    99 	    audio_driver_name = optarg;
   100 	    break;
   101 	case 'V': /* Video driver */
   102 	    display_driver_name = optarg;
   103 	    break;
   104 	case 'p': /* Start immediately */
   105 	    start_immediately = TRUE;
   106     	    break;
   107 	case 'u': /* Allow unsafe dcload syscalls */
   108 	    dcload_set_allow_unsafe(TRUE);
   109 	    break;
   110     	case 'b': /* No BIOS */
   111     	    without_bios = TRUE;
   112     	    break;
   113         case 'h': /* Headless */
   114             headless = TRUE;
   115             break;
   116 	case 't': /* Time limit */
   117 	    t = strtod(optarg, NULL);
   118 	    time_secs = (uint32_t)t;
   119 	    time_nanos = (int)((t - time_secs) * 1000000000);
   120 	    break;
   121 	case 'x': /* Disable translator */
   122 	    use_xlat = FALSE;
   123 	    break;
   124 	}
   125     }
   127     dreamcast_load_config( config_file );
   129     if( aica_program == NULL ) {
   130 	dreamcast_init();
   131     } else {
   132 	dreamcast_configure_aica_only();
   133 	mem_load_block( aica_program, 0x00800000, 2048*1024 );
   134 	if( s3m_file != NULL ) {
   135 	    mem_load_block( s3m_file, 0x00810000, 2048*1024 - 0x10000 );
   136 	}
   137     }
   139     if( without_bios ) {
   140     	bios_install();
   141 	dcload_install();
   142     }
   144     for( i=0; audio_driver_list[i] != NULL; i++ ) {
   145 	if( strcasecmp( audio_driver_list[i]->name, audio_driver_name ) == 0 ) {
   146 	    if( audio_set_driver( audio_driver_list[i], 44100, AUDIO_FMT_16ST ) == FALSE ) {
   147 		audio_set_driver( &audio_null_driver, 44100, AUDIO_FMT_16ST );
   148 	    }
   149 	    break;
   150 	}
   152     }
   153     if( audio_driver_list[i] == NULL ) {
   154 	ERROR( "Audio driver '%s' not found, using null driver", audio_driver_name );
   155 	audio_set_driver( &audio_null_driver, 44100, AUDIO_FMT_16ST );
   156     }
   158     if( headless ) {
   159 	display_set_driver( &display_null_driver );
   160     } else {
   161 	gui_init(show_debugger);
   163 	gboolean initialized = FALSE;
   164 	for( i=0; display_driver_list[i] != NULL; i++ ) {
   165 	    if( strcasecmp( display_driver_list[i]->name, display_driver_name ) == 0 ) {
   166 		initialized = display_set_driver( display_driver_list[i] );
   167 		break;
   168 	    }
   169 	}
   170 	if( !initialized ) {
   171 	    if( display_driver_list[i] == NULL ) {
   172 		ERROR( "Video driver '%s' not found, using null driver", display_driver_name );
   173 	    } else {
   174 		ERROR( "Video driver '%s' failed to initialize, falling back to null driver", display_driver_name );
   175 	    }
   176 	    display_set_driver( &display_null_driver );
   177 	}
   178     }
   180     maple_reattach_all();
   181     INFO( "%s! ready...", APP_NAME );
   183     for( ; optind < argc; optind++ ) {
   184 	gboolean ok = gdrom_mount_image(argv[optind]);
   185 	if( !ok ) {
   186 	    ok = file_load_magic( argv[optind] );
   187 	}
   188 	if( !ok ) {
   189 	    ERROR( "Unrecognized file '%s'", argv[optind] );
   190 	}
   191 	start_immediately = ok;
   192     }
   194     if( disc_file != NULL ) {
   195 	gdrom_mount_image( disc_file );
   196     }
   198     sh4_set_use_xlat( use_xlat );
   200     if( start_immediately ) {
   201 	if( time_nanos != 0 || time_secs != 0 ) {
   202 	    dreamcast_run_for(time_secs, time_nanos);
   203 	    return 0;
   204 	} else {
   205 	    dreamcast_run();
   206 	}
   207     }
   208     if( !headless ) {
   209 	gui_main_loop();
   210     }
   211     return 0;
   212 }
.