Search
lxdream.org :: lxdream/src/main.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/main.c
changeset 495:4db4702b0778
prev480:d28c2992f5ee
next531:f0fee3ba71d1
author nkeynes
date Thu Nov 15 08:17:44 2007 +0000 (16 years ago)
permissions -rw-r--r--
last change Ensure gendec and genglsl aren't installed
view annotate diff log raw
     1 /**
     2  * $Id: main.c,v 1.35 2007-11-07 11:45:53 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 #include <unistd.h>
    23 #include <getopt.h>
    24 #include "dream.h"
    25 #include "config.h"
    26 #include "syscall.h"
    27 #include "mem.h"
    28 #include "dreamcast.h"
    29 #include "display.h"
    30 #include "loader.h"
    31 #include "gui.h"
    32 #include "aica/audio.h"
    33 #include "gdrom/gdrom.h"
    34 #include "maple/maple.h"
    35 #include "sh4/sh4core.h"
    37 #define S3M_PLAYER "s3mplay.bin"
    39 char *option_list = "a:m:s:A:V:puhbd:c:t:xD";
    40 struct option longopts[1] = { { NULL, 0, 0, 0 } };
    41 char *aica_program = NULL;
    42 char *s3m_file = NULL;
    43 const char *disc_file = NULL;
    44 char *display_driver_name = "gtk";
    45 char *audio_driver_name = "esd";
    46 gboolean start_immediately = FALSE;
    47 gboolean headless = FALSE;
    48 gboolean without_bios = FALSE;
    49 gboolean use_xlat = TRUE;
    50 gboolean show_debugger = FALSE;
    51 uint32_t time_secs = 0;
    52 uint32_t time_nanos = 0;
    53 extern uint32_t sh4_cpu_multiplier;
    55 audio_driver_t audio_driver_list[] = { &audio_null_driver,
    56 				       &audio_esd_driver,
    57 				       NULL };
    59 display_driver_t display_driver_list[] = { &display_null_driver,
    60 					   &display_gtk_driver,
    61 					   NULL };
    63 int main (int argc, char *argv[])
    64 {
    65     int opt, i;
    66     double t;
    68     install_crash_handler();
    69 #ifdef ENABLE_NLS
    70     bindtextdomain (PACKAGE, PACKAGE_LOCALE_DIR);
    71     textdomain (PACKAGE);
    72 #endif
    73     gui_parse_cmdline(&argc, &argv);
    75     while( (opt = getopt_long( argc, argv, option_list, longopts, NULL )) != -1 ) {
    76 	switch( opt ) {
    77 	case 'a': /* AICA only mode - argument is an AICA program */
    78 	    aica_program = optarg;
    79 	    break;
    80 	case 'c': /* Config file */
    81 	    lxdream_set_config_filename(optarg);
    82 	    break;
    83 	case 'd': /* Mount disc */
    84 	    disc_file = optarg;
    85 	    break;
    86 	case 'D': /* Launch w/ debugger */
    87 	    show_debugger = TRUE;
    88 	    break;
    89 	case 'm': /* Set SH4 CPU clock multiplier (default 0.5) */
    90 	    t = strtod(optarg, NULL);
    91 	    sh4_cpu_multiplier = (int)(1000.0/t);
    92 	    break;
    93 	case 's': /* AICA-only w/ S3M player */
    94 	    aica_program = S3M_PLAYER;
    95 	    s3m_file = optarg;
    96 	    break;
    97 	case 'A': /* Audio driver */
    98 	    audio_driver_name = optarg;
    99 	    break;
   100 	case 'V': /* Video driver */
   101 	    display_driver_name = optarg;
   102 	    break;
   103 	case 'p': /* Start immediately */
   104 	    start_immediately = TRUE;
   105     	    break;
   106 	case 'u': /* Allow unsafe dcload syscalls */
   107 	    dcload_set_allow_unsafe(TRUE);
   108 	    break;
   109     	case 'b': /* No BIOS */
   110     	    without_bios = TRUE;
   111     	    break;
   112         case 'h': /* Headless */
   113             headless = TRUE;
   114             break;
   115 	case 't': /* Time limit */
   116 	    t = strtod(optarg, NULL);
   117 	    time_secs = (uint32_t)t;
   118 	    time_nanos = (int)((t - time_secs) * 1000000000);
   119 	    break;
   120 	case 'x': /* Disable translator */
   121 	    use_xlat = FALSE;
   122 	    break;
   123 	}
   124     }
   126     lxdream_load_config( );
   128     if( aica_program == NULL ) {
   129 	dreamcast_init();
   130     } else {
   131 	dreamcast_configure_aica_only();
   132 	mem_load_block( aica_program, 0x00800000, 2048*1024 );
   133 	if( s3m_file != NULL ) {
   134 	    mem_load_block( s3m_file, 0x00810000, 2048*1024 - 0x10000 );
   135 	}
   136     }
   138     if( without_bios ) {
   139     	bios_install();
   140 	dcload_install();
   141     }
   143     for( i=0; audio_driver_list[i] != NULL; i++ ) {
   144 	if( strcasecmp( audio_driver_list[i]->name, audio_driver_name ) == 0 ) {
   145 	    if( audio_set_driver( audio_driver_list[i], 44100, AUDIO_FMT_16ST ) == FALSE ) {
   146 		audio_set_driver( &audio_null_driver, 44100, AUDIO_FMT_16ST );
   147 	    }
   148 	    break;
   149 	}
   151     }
   152     if( audio_driver_list[i] == NULL ) {
   153 	ERROR( "Audio driver '%s' not found, using null driver", audio_driver_name );
   154 	audio_set_driver( &audio_null_driver, 44100, AUDIO_FMT_16ST );
   155     }
   157     if( headless ) {
   158 	display_set_driver( &display_null_driver );
   159     } else {
   160 	gui_init(show_debugger);
   162 	gboolean initialized = FALSE;
   163 	for( i=0; display_driver_list[i] != NULL; i++ ) {
   164 	    if( strcasecmp( display_driver_list[i]->name, display_driver_name ) == 0 ) {
   165 		initialized = display_set_driver( display_driver_list[i] );
   166 		break;
   167 	    }
   168 	}
   169 	if( !initialized ) {
   170 	    if( display_driver_list[i] == NULL ) {
   171 		ERROR( "Video driver '%s' not found, using null driver", display_driver_name );
   172 	    } else {
   173 		ERROR( "Video driver '%s' failed to initialize, falling back to null driver", display_driver_name );
   174 	    }
   175 	    display_set_driver( &display_null_driver );
   176 	}
   177     }
   179     maple_reattach_all();
   180     INFO( "%s! ready...", APP_NAME );
   182     for( ; optind < argc; optind++ ) {
   183 	gboolean ok = gdrom_menu_open_file(argv[optind]);
   184 	if( !ok ) {
   185 	    ok = file_load_magic( argv[optind] );
   186 	}
   187 	if( !ok ) {
   188 	    ERROR( "Unrecognized file '%s'", argv[optind] );
   189 	}
   190 	start_immediately = ok;
   191     }
   193     if( disc_file != NULL ) {
   194 	gdrom_menu_open_file( disc_file );
   195     }
   197     if( gdrom_get_current_disc() == NULL ) {
   198 	disc_file = lxdream_get_config_value( CONFIG_GDROM );
   199 	if( disc_file != NULL ) {
   200 	    gdrom_menu_open_file( disc_file );
   201 	}
   202     }
   204     sh4_set_use_xlat( use_xlat );
   206     if( start_immediately ) {
   207 	if( time_nanos != 0 || time_secs != 0 ) {
   208 	    dreamcast_run_for(time_secs, time_nanos);
   209 	    return 0;
   210 	} else {
   211 	    dreamcast_run();
   212 	}
   213     }
   214     if( !headless ) {
   215 	gui_main_loop();
   216     }
   217     return 0;
   218 }
.