Search
lxdream.org :: lxdream/src/main.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/main.c
changeset 402:85fd4a4582be
prev392:39e596b3b6dd
next414:fd8e96bc513e
author nkeynes
date Fri Sep 28 07:24:14 2007 +0000 (16 years ago)
permissions -rw-r--r--
last change Add GLSL loader framework
view annotate diff log raw
     1 /**
     2  * $Id: main.c,v 1.25 2007-09-20 08:42:40 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:xD";
    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 = TRUE;
    50 gboolean show_debugger = FALSE;
    51 uint32_t time_secs = 0;
    52 uint32_t time_nanos = 0;
    54 audio_driver_t audio_driver_list[] = { &audio_null_driver,
    55 				       &audio_esd_driver,
    56 				       NULL };
    58 display_driver_t display_driver_list[] = { &display_null_driver,
    59 					   &display_gtk_driver,
    60 					   NULL };
    62 int main (int argc, char *argv[])
    63 {
    64     int opt, i;
    65     double t;
    66 #ifdef ENABLE_NLS
    67     bindtextdomain (PACKAGE, PACKAGE_LOCALE_DIR);
    68     textdomain (PACKAGE);
    69 #endif
    71     while( (opt = getopt_long( argc, argv, option_list, longopts, NULL )) != -1 ) {
    72 	switch( opt ) {
    73 	case 'a': /* AICA only mode - argument is an AICA program */
    74 	    aica_program = optarg;
    75 	    break;
    76 	case 'c': /* Config file */
    77 	    config_file = optarg;
    78 	    break;
    79 	case 'd': /* Mount disc */
    80 	    disc_file = optarg;
    81 	    break;
    82 	case 'D': /* Launch w/ debugger */
    83 	    show_debugger = TRUE;
    84 	    break;
    85 	case 's': /* AICA-only w/ S3M player */
    86 	    aica_program = S3M_PLAYER;
    87 	    s3m_file = optarg;
    88 	    break;
    89 	case 'A': /* Audio driver */
    90 	    audio_driver_name = optarg;
    91 	    break;
    92 	case 'V': /* Video driver */
    93 	    display_driver_name = optarg;
    94 	    break;
    95 	case 'p': /* Start immediately */
    96 	    start_immediately = TRUE;
    97     	    break;
    98 	case 'u': /* Allow unsafe dcload syscalls */
    99 	    dcload_set_allow_unsafe(TRUE);
   100 	    break;
   101     	case 'b': /* No BIOS */
   102     	    without_bios = TRUE;
   103     	    break;
   104         case 'h': /* Headless */
   105             headless = TRUE;
   106             break;
   107 	case 't': /* Time limit */
   108 	    t = strtod(optarg, NULL);
   109 	    time_secs = (uint32_t)t;
   110 	    time_nanos = (int)((t - time_secs) * 1000000000);
   111 	    break;
   112 	case 'x': /* Disable translator */
   113 	    use_xlat = FALSE;
   114 	    break;
   115 	}
   116     }
   118     dreamcast_load_config( config_file );
   120     if( aica_program == NULL ) {
   121 	if( !headless ) {
   122 	    gnome_init ("lxdream", VERSION, argc, argv);
   123 	    dreamcast_init();
   124 	    dreamcast_register_module( &gtk_gui_module );
   125 	    if( show_debugger ) {
   126 		gtk_gui_show_debugger();
   127 	    }
   128 	} else {
   129 	    dreamcast_init();
   130 	}
   132     } else {
   133 	dreamcast_configure_aica_only();
   134 	mem_load_block( aica_program, 0x00800000, 2048*1024 );
   135 	if( s3m_file != NULL ) {
   136 	    mem_load_block( s3m_file, 0x00810000, 2048*1024 - 0x10000 );
   137 	}
   138 	if( !headless ) {
   139 	    gnome_init ("lxdream", VERSION, argc, argv);
   140 	    dreamcast_register_module( &gtk_gui_module );
   141 	    set_disassembly_cpu( main_debug, "ARM7" );
   142 	}
   143     }
   145     if( without_bios ) {
   146     	bios_install();
   147 	dcload_install();
   148     }
   150     for( i=0; audio_driver_list[i] != NULL; i++ ) {
   151 	if( strcasecmp( audio_driver_list[i]->name, audio_driver_name ) == 0 ) {
   152 	    if( audio_set_driver( audio_driver_list[i], 44100, AUDIO_FMT_16ST ) == FALSE ) {
   153 		audio_set_driver( &audio_null_driver, 44100, AUDIO_FMT_16ST );
   154 	    }
   155 	    break;
   156 	}
   158     }
   159     if( audio_driver_list[i] == NULL ) {
   160 	ERROR( "Audio driver '%s' not found, using null driver", audio_driver_name );
   161 	audio_set_driver( &audio_null_driver, 44100, AUDIO_FMT_16ST );
   162     }
   164     if( headless ) {
   165 	display_set_driver( &display_null_driver );
   166     } else {
   167 	gboolean initialized = FALSE;
   168 	for( i=0; display_driver_list[i] != NULL; i++ ) {
   169 	    if( strcasecmp( display_driver_list[i]->name, display_driver_name ) == 0 ) {
   170 		initialized = display_set_driver( display_driver_list[i] );
   171 		break;
   172 	    }
   173 	}
   174 	if( !initialized ) {
   175 	    if( display_driver_list[i] == NULL ) {
   176 		ERROR( "Video driver '%s' not found, using null driver", display_driver_name );
   177 	    } else {
   178 		ERROR( "Video driver '%s' failed to initialize, falling back to null driver", display_driver_name );
   179 	    }
   180 	    display_set_driver( &display_null_driver );
   181 	}
   182     }
   184     maple_reattach_all();
   185     INFO( "%s! ready...", APP_NAME );
   186     if( optind < argc ) {
   187 	file_load_magic( argv[optind] );
   188     }
   190     if( disc_file != NULL ) {
   191 	gdrom_mount_image( disc_file );
   192     }
   194     sh4_set_use_xlat( use_xlat );
   196     if( start_immediately ) {
   197 	if( time_nanos != 0 || time_secs != 0 ) {
   198 	    dreamcast_run_for(time_secs, time_nanos);
   199 	    return 0;
   200 	} else {
   201 	    dreamcast_run();
   202 	}
   203     }
   204     if( !headless ) {
   205         gtk_main ();
   206     }
   207     return 0;
   208 }
.