Search
lxdream.org :: lxdream/src/main.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/main.c
changeset 370:3131ba1440fc
prev209:ff67a7b9aa17
next372:86aa060ddcec
author nkeynes
date Sat Sep 08 04:05:35 2007 +0000 (13 years ago)
permissions -rw-r--r--
last change Handle video driver init failure cleanly (fallback to headless)
Hookup shutdown for the GTK driver
view annotate diff log raw
     1 /**
     2  * $Id: main.c,v 1.21 2007-09-08 04:05:35 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:";
    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;
    50 audio_driver_t audio_driver_list[] = { &audio_null_driver,
    51 				       &audio_esd_driver,
    52 				       NULL };
    54 display_driver_t display_driver_list[] = { &display_null_driver,
    55 					   &display_gtk_driver,
    56 					   NULL };
    58 int main (int argc, char *argv[])
    59 {
    60     int opt, i;
    61 #ifdef ENABLE_NLS
    62     bindtextdomain (PACKAGE, PACKAGE_LOCALE_DIR);
    63     textdomain (PACKAGE);
    64 #endif
    66     while( (opt = getopt_long( argc, argv, option_list, longopts, NULL )) != -1 ) {
    67 	switch( opt ) {
    68 	case 'a': /* AICA only mode - argument is an AICA program */
    69 	    aica_program = optarg;
    70 	    break;
    71 	case 'c': /* Config file */
    72 	    config_file = optarg;
    73 	    break;
    74 	case 'd': /* Mount disc */
    75 	    disc_file = optarg;
    76 	    break;
    77 	case 's': /* AICA-only w/ S3M player */
    78 	    aica_program = S3M_PLAYER;
    79 	    s3m_file = optarg;
    80 	    break;
    81 	case 'A': /* Audio driver */
    82 	    audio_driver_name = optarg;
    83 	    break;
    84 	case 'V': /* Video driver */
    85 	    display_driver_name = optarg;
    86 	    break;
    87 	case 'p': /* Start immediately */
    88 	    start_immediately = TRUE;
    89     	    break;
    90 	case 'u': /* Allow unsafe dcload syscalls */
    91 	    dcload_set_allow_unsafe(TRUE);
    92 	    break;
    93     	case 'b': /* No BIOS */
    94     	    without_bios = TRUE;
    95     	    break;
    96         case 'h': /* Headless */
    97             headless = TRUE;
    98             break;
    99 	}
   100     }
   102     dreamcast_load_config( config_file );
   104     if( aica_program == NULL ) {
   105 	if( !headless ) {
   106 	    gnome_init ("lxdream", VERSION, argc, argv);
   107 	    dreamcast_init();
   108 	    dreamcast_register_module( &gtk_gui_module );
   109 	} else {
   110 	    dreamcast_init();
   111 	}
   113     } else {
   114 	dreamcast_configure_aica_only();
   115 	mem_load_block( aica_program, 0x00800000, 2048*1024 );
   116 	if( s3m_file != NULL ) {
   117 	    mem_load_block( s3m_file, 0x00810000, 2048*1024 - 0x10000 );
   118 	}
   119 	if( !headless ) {
   120 	    gnome_init ("lxdream", VERSION, argc, argv);
   121 	    dreamcast_register_module( &gtk_gui_module );
   122 	    set_disassembly_cpu( main_debug, "ARM7" );
   123 	}
   124     }
   126     if( without_bios ) {
   127     	bios_install();
   128 	dcload_install();
   129     }
   131     for( i=0; audio_driver_list[i] != NULL; i++ ) {
   132 	if( strcasecmp( audio_driver_list[i]->name, audio_driver_name ) == 0 ) {
   133 	    if( audio_set_driver( audio_driver_list[i], 44100, AUDIO_FMT_16ST ) == FALSE ) {
   134 		audio_set_driver( &audio_null_driver, 44100, AUDIO_FMT_16ST );
   135 	    }
   136 	    break;
   137 	}
   139     }
   140     if( audio_driver_list[i] == NULL ) {
   141 	ERROR( "Audio driver '%s' not found, using null driver", audio_driver_name );
   142 	audio_set_driver( &audio_null_driver, 44100, AUDIO_FMT_16ST );
   143     }
   145     if( headless ) {
   146 	display_set_driver( &display_null_driver );
   147     } else {
   148 	gboolean initialized = FALSE;
   149 	for( i=0; display_driver_list[i] != NULL; i++ ) {
   150 	    if( strcasecmp( display_driver_list[i]->name, display_driver_name ) == 0 ) {
   151 		initialized = display_set_driver( display_driver_list[i] );
   152 		break;
   153 	    }
   154 	}
   155 	if( !initialized ) {
   156 	    if( display_driver_list[i] == NULL ) {
   157 		ERROR( "Video driver '%s' not found, using null driver", display_driver_name );
   158 	    } else {
   159 		ERROR( "Video driver '%s' failed to initialize, falling back to null driver", display_driver_name );
   160 	    }
   161 	    display_set_driver( &display_null_driver );
   162 	}
   163     }
   165     maple_reattach_all();
   166     INFO( "%s! ready...", APP_NAME );
   167     if( optind < argc ) {
   168 	file_load_magic( argv[optind] );
   169     }
   171     if( disc_file != NULL ) {
   172 	gdrom_mount_image( disc_file );
   173     }
   175     if( start_immediately )
   176 	dreamcast_run();
   177     if( !headless ) {
   178         gtk_main ();
   179     }
   180     return 0;
   181 }
.