Search
lxdream.org :: lxdream/src/main.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/main.c
changeset 209:ff67a7b9aa17
prev182:e3b513538548
next370:3131ba1440fc
author nkeynes
date Mon Jan 15 08:30:50 2007 +0000 (17 years ago)
permissions -rw-r--r--
last change Commit testyuv WIP
view annotate diff log raw
     1 /**
     2  * $Id: main.c,v 1.20 2006-08-07 13:18:16 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 	for( i=0; display_driver_list[i] != NULL; i++ ) {
   149 	    if( strcasecmp( display_driver_list[i]->name, display_driver_name ) == 0 ) {
   150 		display_set_driver( display_driver_list[i] );
   151 		break;
   152 	    }
   153 	}
   154 	if( display_driver_list[i] == NULL ) {
   155 	    ERROR( "Video driver '%s' not found, using null driver", display_driver_name );
   156 	    display_set_driver( &display_null_driver );
   157 	}
   158     }
   160     maple_reattach_all();
   161     INFO( "%s! ready...", APP_NAME );
   162     if( optind < argc ) {
   163 	file_load_magic( argv[optind] );
   164     }
   166     if( disc_file != NULL ) {
   167 	gdrom_mount_image( disc_file );
   168     }
   170     if( start_immediately )
   171 	dreamcast_run();
   172     if( !headless ) {
   173         gtk_main ();
   174     }
   175     return 0;
   176 }
.