Search
lxdream.org :: lxdream/src/main.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/main.c
changeset 422:61a0598e07ff
prev414:fd8e96bc513e
next435:7a5d71e8560b
author nkeynes
date Sun Oct 07 06:27:12 2007 +0000 (16 years ago)
permissions -rw-r--r--
last change Fix compilation warnings
view annotate diff log raw
     1 /**
     2  * $Id: main.c,v 1.27 2007-10-06 09:00:10 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 "mem.h"
    32 #include "dreamcast.h"
    33 #include "display.h"
    34 #include "loader.h"
    35 #include "aica/audio.h"
    36 #include "gdrom/gdrom.h"
    37 #include "maple/maple.h"
    38 #include "sh4/sh4core.h"
    40 #define S3M_PLAYER "s3mplay.bin"
    42 char *option_list = "a:m:s:A:V:puhbd:c:t:xD";
    43 struct option longopts[1] = { { NULL, 0, 0, 0 } };
    44 char *aica_program = NULL;
    45 char *s3m_file = NULL;
    46 char *disc_file = NULL;
    47 char *display_driver_name = "gtk";
    48 char *audio_driver_name = "esd";
    49 char *config_file = DEFAULT_CONFIG_FILENAME;
    50 gboolean start_immediately = FALSE;
    51 gboolean headless = FALSE;
    52 gboolean without_bios = FALSE;
    53 gboolean use_xlat = TRUE;
    54 gboolean show_debugger = FALSE;
    55 uint32_t time_secs = 0;
    56 uint32_t time_nanos = 0;
    57 extern uint32_t sh4_cpu_multiplier;
    59 audio_driver_t audio_driver_list[] = { &audio_null_driver,
    60 				       &audio_esd_driver,
    61 				       NULL };
    63 display_driver_t display_driver_list[] = { &display_null_driver,
    64 					   &display_gtk_driver,
    65 					   NULL };
    67 int main (int argc, char *argv[])
    68 {
    69     int opt, i;
    70     double t;
    71 #ifdef ENABLE_NLS
    72     bindtextdomain (PACKAGE, PACKAGE_LOCALE_DIR);
    73     textdomain (PACKAGE);
    74 #endif
    76     while( (opt = getopt_long( argc, argv, option_list, longopts, NULL )) != -1 ) {
    77 	switch( opt ) {
    78 	case 'a': /* AICA only mode - argument is an AICA program */
    79 	    aica_program = optarg;
    80 	    break;
    81 	case 'c': /* Config file */
    82 	    config_file = optarg;
    83 	    break;
    84 	case 'd': /* Mount disc */
    85 	    disc_file = optarg;
    86 	    break;
    87 	case 'D': /* Launch w/ debugger */
    88 	    show_debugger = TRUE;
    89 	    break;
    90 	case 'm': /* Set SH4 CPU clock multiplier (default 0.5) */
    91 	    t = strtod(optarg, NULL);
    92 	    sh4_cpu_multiplier = (int)(1000.0/t);
    93 	    break;
    94 	case 's': /* AICA-only w/ S3M player */
    95 	    aica_program = S3M_PLAYER;
    96 	    s3m_file = optarg;
    97 	    break;
    98 	case 'A': /* Audio driver */
    99 	    audio_driver_name = optarg;
   100 	    break;
   101 	case 'V': /* Video driver */
   102 	    display_driver_name = optarg;
   103 	    break;
   104 	case 'p': /* Start immediately */
   105 	    start_immediately = TRUE;
   106     	    break;
   107 	case 'u': /* Allow unsafe dcload syscalls */
   108 	    dcload_set_allow_unsafe(TRUE);
   109 	    break;
   110     	case 'b': /* No BIOS */
   111     	    without_bios = TRUE;
   112     	    break;
   113         case 'h': /* Headless */
   114             headless = TRUE;
   115             break;
   116 	case 't': /* Time limit */
   117 	    t = strtod(optarg, NULL);
   118 	    time_secs = (uint32_t)t;
   119 	    time_nanos = (int)((t - time_secs) * 1000000000);
   120 	    break;
   121 	case 'x': /* Disable translator */
   122 	    use_xlat = FALSE;
   123 	    break;
   124 	}
   125     }
   127     dreamcast_load_config( config_file );
   129     if( aica_program == NULL ) {
   130 	if( !headless ) {
   131 	    gnome_init ("lxdream", VERSION, argc, argv);
   132 	    dreamcast_init();
   133 	    dreamcast_register_module( &gtk_gui_module );
   134 	    if( show_debugger ) {
   135 		gtk_gui_show_debugger();
   136 	    }
   137 	} else {
   138 	    dreamcast_init();
   139 	}
   141     } else {
   142 	dreamcast_configure_aica_only();
   143 	mem_load_block( aica_program, 0x00800000, 2048*1024 );
   144 	if( s3m_file != NULL ) {
   145 	    mem_load_block( s3m_file, 0x00810000, 2048*1024 - 0x10000 );
   146 	}
   147 	if( !headless ) {
   148 	    gnome_init ("lxdream", VERSION, argc, argv);
   149 	    dreamcast_register_module( &gtk_gui_module );
   150 	    set_disassembly_cpu( main_debug, "ARM7" );
   151 	}
   152     }
   154     if( without_bios ) {
   155     	bios_install();
   156 	dcload_install();
   157     }
   159     for( i=0; audio_driver_list[i] != NULL; i++ ) {
   160 	if( strcasecmp( audio_driver_list[i]->name, audio_driver_name ) == 0 ) {
   161 	    if( audio_set_driver( audio_driver_list[i], 44100, AUDIO_FMT_16ST ) == FALSE ) {
   162 		audio_set_driver( &audio_null_driver, 44100, AUDIO_FMT_16ST );
   163 	    }
   164 	    break;
   165 	}
   167     }
   168     if( audio_driver_list[i] == NULL ) {
   169 	ERROR( "Audio driver '%s' not found, using null driver", audio_driver_name );
   170 	audio_set_driver( &audio_null_driver, 44100, AUDIO_FMT_16ST );
   171     }
   173     if( headless ) {
   174 	display_set_driver( &display_null_driver );
   175     } else {
   176 	gboolean initialized = FALSE;
   177 	for( i=0; display_driver_list[i] != NULL; i++ ) {
   178 	    if( strcasecmp( display_driver_list[i]->name, display_driver_name ) == 0 ) {
   179 		initialized = display_set_driver( display_driver_list[i] );
   180 		break;
   181 	    }
   182 	}
   183 	if( !initialized ) {
   184 	    if( display_driver_list[i] == NULL ) {
   185 		ERROR( "Video driver '%s' not found, using null driver", display_driver_name );
   186 	    } else {
   187 		ERROR( "Video driver '%s' failed to initialize, falling back to null driver", display_driver_name );
   188 	    }
   189 	    display_set_driver( &display_null_driver );
   190 	}
   191     }
   193     maple_reattach_all();
   194     INFO( "%s! ready...", APP_NAME );
   195     if( optind < argc ) {
   196 	file_load_magic( argv[optind] );
   197     }
   199     if( disc_file != NULL ) {
   200 	gdrom_mount_image( disc_file );
   201     }
   203     sh4_set_use_xlat( use_xlat );
   205     if( start_immediately ) {
   206 	if( time_nanos != 0 || time_secs != 0 ) {
   207 	    dreamcast_run_for(time_secs, time_nanos);
   208 	    return 0;
   209 	} else {
   210 	    dreamcast_run();
   211 	}
   212     }
   213     if( !headless ) {
   214         gtk_main ();
   215     }
   216     return 0;
   217 }
.