Search
lxdream.org :: lxdream/src/main.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/main.c
changeset 379:7e1c33a184d8
prev372:86aa060ddcec
next392:39e596b3b6dd
author nkeynes
date Wed Sep 12 09:21:01 2007 +0000 (13 years ago)
permissions -rw-r--r--
last change Hook up the translator as a command line option
view annotate diff log raw
     1 /**
     2  * $Id: main.c,v 1.23 2007-09-12 09:21:01 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 <gnome.h>
    28 #include "gui/gui.h"
    29 #include "dream.h"
    30 #include "syscall.h"
    31 #include "dreamcast.h"
    32 #include "aica/audio.h"
    33 #include "display.h"
    34 #include "maple/maple.h"
    36 #define S3M_PLAYER "s3mplay.bin"
    38 char *option_list = "a:s:A:V:puhbd:c:t:x";
    39 struct option longopts[1] = { { NULL, 0, 0, 0 } };
    40 char *aica_program = NULL;
    41 char *s3m_file = NULL;
    42 char *disc_file = NULL;
    43 char *display_driver_name = "gtk";
    44 char *audio_driver_name = "esd";
    45 char *config_file = DEFAULT_CONFIG_FILENAME;
    46 gboolean start_immediately = FALSE;
    47 gboolean headless = FALSE;
    48 gboolean without_bios = FALSE;
    49 gboolean use_xlat = FALSE;
    50 uint32_t time_secs = 0;
    51 uint32_t time_nanos = 0;
    53 audio_driver_t audio_driver_list[] = { &audio_null_driver,
    54 				       &audio_esd_driver,
    55 				       NULL };
    57 display_driver_t display_driver_list[] = { &display_null_driver,
    58 					   &display_gtk_driver,
    59 					   NULL };
    61 int main (int argc, char *argv[])
    62 {
    63     int opt, i;
    64     double t;
    65 #ifdef ENABLE_NLS
    66     bindtextdomain (PACKAGE, PACKAGE_LOCALE_DIR);
    67     textdomain (PACKAGE);
    68 #endif
    70     while( (opt = getopt_long( argc, argv, option_list, longopts, NULL )) != -1 ) {
    71 	switch( opt ) {
    72 	case 'a': /* AICA only mode - argument is an AICA program */
    73 	    aica_program = optarg;
    74 	    break;
    75 	case 'c': /* Config file */
    76 	    config_file = optarg;
    77 	    break;
    78 	case 'd': /* Mount disc */
    79 	    disc_file = optarg;
    80 	    break;
    81 	case 's': /* AICA-only w/ S3M player */
    82 	    aica_program = S3M_PLAYER;
    83 	    s3m_file = optarg;
    84 	    break;
    85 	case 'A': /* Audio driver */
    86 	    audio_driver_name = optarg;
    87 	    break;
    88 	case 'V': /* Video driver */
    89 	    display_driver_name = optarg;
    90 	    break;
    91 	case 'p': /* Start immediately */
    92 	    start_immediately = TRUE;
    93     	    break;
    94 	case 'u': /* Allow unsafe dcload syscalls */
    95 	    dcload_set_allow_unsafe(TRUE);
    96 	    break;
    97     	case 'b': /* No BIOS */
    98     	    without_bios = TRUE;
    99     	    break;
   100         case 'h': /* Headless */
   101             headless = TRUE;
   102             break;
   103 	case 't': /* Time limit */
   104 	    t = strtod(optarg, NULL);
   105 	    time_secs = (uint32_t)t;
   106 	    time_nanos = (int)((t - time_secs) * 1000000000);
   107 	    break;
   108 	case 'x': /* Use experimental translator */
   109 	    use_xlat = TRUE;
   110 	    break;
   111 	}
   112     }
   114     dreamcast_load_config( config_file );
   116     if( aica_program == NULL ) {
   117 	if( !headless ) {
   118 	    gnome_init ("lxdream", VERSION, argc, argv);
   119 	    dreamcast_init();
   120 	    dreamcast_register_module( &gtk_gui_module );
   121 	} else {
   122 	    dreamcast_init();
   123 	}
   125     } else {
   126 	dreamcast_configure_aica_only();
   127 	mem_load_block( aica_program, 0x00800000, 2048*1024 );
   128 	if( s3m_file != NULL ) {
   129 	    mem_load_block( s3m_file, 0x00810000, 2048*1024 - 0x10000 );
   130 	}
   131 	if( !headless ) {
   132 	    gnome_init ("lxdream", VERSION, argc, argv);
   133 	    dreamcast_register_module( &gtk_gui_module );
   134 	    set_disassembly_cpu( main_debug, "ARM7" );
   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 	gboolean initialized = FALSE;
   161 	for( i=0; display_driver_list[i] != NULL; i++ ) {
   162 	    if( strcasecmp( display_driver_list[i]->name, display_driver_name ) == 0 ) {
   163 		initialized = display_set_driver( display_driver_list[i] );
   164 		break;
   165 	    }
   166 	}
   167 	if( !initialized ) {
   168 	    if( display_driver_list[i] == NULL ) {
   169 		ERROR( "Video driver '%s' not found, using null driver", display_driver_name );
   170 	    } else {
   171 		ERROR( "Video driver '%s' failed to initialize, falling back to null driver", display_driver_name );
   172 	    }
   173 	    display_set_driver( &display_null_driver );
   174 	}
   175     }
   177     maple_reattach_all();
   178     INFO( "%s! ready...", APP_NAME );
   179     if( optind < argc ) {
   180 	file_load_magic( argv[optind] );
   181     }
   183     if( disc_file != NULL ) {
   184 	gdrom_mount_image( disc_file );
   185     }
   187     sh4_set_use_xlat( use_xlat );
   189     if( start_immediately ) {
   190 	if( time_nanos != 0 || time_secs != 0 ) {
   191 	    dreamcast_run_for(time_secs, time_nanos);
   192 	    return 0;
   193 	} else {
   194 	    dreamcast_run();
   195 	}
   196     }
   197     if( !headless ) {
   198         gtk_main ();
   199     }
   200     return 0;
   201 }
.