Search
lxdream.org :: lxdream/src/main.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/main.c
changeset 372:86aa060ddcec
prev370:3131ba1440fc
next379:7e1c33a184d8
author nkeynes
date Sat Sep 08 04:38:38 2007 +0000 (13 years ago)
permissions -rw-r--r--
last change Add time-limited run option (for time trials)
view annotate diff log raw
     1 /**
     2  * $Id: main.c,v 1.22 2007-09-08 04:38:38 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:";
    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 uint32_t time_secs = 0;
    50 uint32_t time_nanos = 0;
    52 audio_driver_t audio_driver_list[] = { &audio_null_driver,
    53 				       &audio_esd_driver,
    54 				       NULL };
    56 display_driver_t display_driver_list[] = { &display_null_driver,
    57 					   &display_gtk_driver,
    58 					   NULL };
    60 int main (int argc, char *argv[])
    61 {
    62     int opt, i;
    63     double t;
    64 #ifdef ENABLE_NLS
    65     bindtextdomain (PACKAGE, PACKAGE_LOCALE_DIR);
    66     textdomain (PACKAGE);
    67 #endif
    69     while( (opt = getopt_long( argc, argv, option_list, longopts, NULL )) != -1 ) {
    70 	switch( opt ) {
    71 	case 'a': /* AICA only mode - argument is an AICA program */
    72 	    aica_program = optarg;
    73 	    break;
    74 	case 'c': /* Config file */
    75 	    config_file = optarg;
    76 	    break;
    77 	case 'd': /* Mount disc */
    78 	    disc_file = optarg;
    79 	    break;
    80 	case 's': /* AICA-only w/ S3M player */
    81 	    aica_program = S3M_PLAYER;
    82 	    s3m_file = optarg;
    83 	    break;
    84 	case 'A': /* Audio driver */
    85 	    audio_driver_name = optarg;
    86 	    break;
    87 	case 'V': /* Video driver */
    88 	    display_driver_name = optarg;
    89 	    break;
    90 	case 'p': /* Start immediately */
    91 	    start_immediately = TRUE;
    92     	    break;
    93 	case 'u': /* Allow unsafe dcload syscalls */
    94 	    dcload_set_allow_unsafe(TRUE);
    95 	    break;
    96     	case 'b': /* No BIOS */
    97     	    without_bios = TRUE;
    98     	    break;
    99         case 'h': /* Headless */
   100             headless = TRUE;
   101             break;
   102 	case 't': /* Time limit */
   103 	    t = strtod(optarg, NULL);
   104 	    time_secs = (uint32_t)t;
   105 	    time_nanos = (int)((t - time_secs) * 1000000000);
   106 	}
   107     }
   109     dreamcast_load_config( config_file );
   111     if( aica_program == NULL ) {
   112 	if( !headless ) {
   113 	    gnome_init ("lxdream", VERSION, argc, argv);
   114 	    dreamcast_init();
   115 	    dreamcast_register_module( &gtk_gui_module );
   116 	} else {
   117 	    dreamcast_init();
   118 	}
   120     } else {
   121 	dreamcast_configure_aica_only();
   122 	mem_load_block( aica_program, 0x00800000, 2048*1024 );
   123 	if( s3m_file != NULL ) {
   124 	    mem_load_block( s3m_file, 0x00810000, 2048*1024 - 0x10000 );
   125 	}
   126 	if( !headless ) {
   127 	    gnome_init ("lxdream", VERSION, argc, argv);
   128 	    dreamcast_register_module( &gtk_gui_module );
   129 	    set_disassembly_cpu( main_debug, "ARM7" );
   130 	}
   131     }
   133     if( without_bios ) {
   134     	bios_install();
   135 	dcload_install();
   136     }
   138     for( i=0; audio_driver_list[i] != NULL; i++ ) {
   139 	if( strcasecmp( audio_driver_list[i]->name, audio_driver_name ) == 0 ) {
   140 	    if( audio_set_driver( audio_driver_list[i], 44100, AUDIO_FMT_16ST ) == FALSE ) {
   141 		audio_set_driver( &audio_null_driver, 44100, AUDIO_FMT_16ST );
   142 	    }
   143 	    break;
   144 	}
   146     }
   147     if( audio_driver_list[i] == NULL ) {
   148 	ERROR( "Audio driver '%s' not found, using null driver", audio_driver_name );
   149 	audio_set_driver( &audio_null_driver, 44100, AUDIO_FMT_16ST );
   150     }
   152     if( headless ) {
   153 	display_set_driver( &display_null_driver );
   154     } else {
   155 	gboolean initialized = FALSE;
   156 	for( i=0; display_driver_list[i] != NULL; i++ ) {
   157 	    if( strcasecmp( display_driver_list[i]->name, display_driver_name ) == 0 ) {
   158 		initialized = display_set_driver( display_driver_list[i] );
   159 		break;
   160 	    }
   161 	}
   162 	if( !initialized ) {
   163 	    if( display_driver_list[i] == NULL ) {
   164 		ERROR( "Video driver '%s' not found, using null driver", display_driver_name );
   165 	    } else {
   166 		ERROR( "Video driver '%s' failed to initialize, falling back to null driver", display_driver_name );
   167 	    }
   168 	    display_set_driver( &display_null_driver );
   169 	}
   170     }
   172     maple_reattach_all();
   173     INFO( "%s! ready...", APP_NAME );
   174     if( optind < argc ) {
   175 	file_load_magic( argv[optind] );
   176     }
   178     if( disc_file != NULL ) {
   179 	gdrom_mount_image( disc_file );
   180     }
   182     if( start_immediately ) {
   183 	if( time_nanos != 0 || time_secs != 0 ) {
   184 	    dreamcast_run_for(time_secs, time_nanos);
   185 	    return 0;
   186 	} else {
   187 	    dreamcast_run();
   188 	}
   189     }
   190     if( !headless ) {
   191         gtk_main ();
   192     }
   193     return 0;
   194 }
.