Search
lxdream.org :: lxdream/src/main.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/main.c
changeset 180:e6dcf9b65658
prev144:7f0714e89aaa
next182:e3b513538548
author nkeynes
date Sun Jul 02 04:59:00 2006 +0000 (15 years ago)
permissions -rw-r--r--
last change Merge changes made on the MILESTONE1 branch back into head (mostly
release touchups)
view annotate diff log raw
     1 /**
     2  * $Id: main.c,v 1.18 2006-07-02 04:59:00 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:phbd: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 'b': /* No BIOS */
    91     	    without_bios = TRUE;
    92     	    break;
    93         case 'h': /* Headless */
    94             headless = TRUE;
    95             break;
    96 	}
    97     }
    99     dreamcast_load_config( config_file );
   101     if( aica_program == NULL ) {
   102 	if( !headless ) {
   103 	    gnome_init ("lxdream", VERSION, argc, argv);
   104 	    dreamcast_init();
   105 	    dreamcast_register_module( &gtk_gui_module );
   106 	} else {
   107 	    dreamcast_init();
   108 	}
   110     } else {
   111 	dreamcast_configure_aica_only();
   112 	mem_load_block( aica_program, 0x00800000, 2048*1024 );
   113 	if( s3m_file != NULL ) {
   114 	    mem_load_block( s3m_file, 0x00810000, 2048*1024 - 0x10000 );
   115 	}
   116 	if( !headless ) {
   117 	    gnome_init ("lxdream", VERSION, argc, argv);
   118 	    dreamcast_register_module( &gtk_gui_module );
   119 	    set_disassembly_cpu( main_debug, "ARM7" );
   120 	}
   121     }
   123     if( without_bios ) {
   124     	bios_install();
   125 	dcload_install();
   126     }
   128     for( i=0; audio_driver_list[i] != NULL; i++ ) {
   129 	if( strcasecmp( audio_driver_list[i]->name, audio_driver_name ) == 0 ) {
   130 	    if( audio_set_driver( audio_driver_list[i], 44100, AUDIO_FMT_16ST ) == FALSE ) {
   131 		audio_set_driver( &audio_null_driver, 44100, AUDIO_FMT_16ST );
   132 	    }
   133 	    break;
   134 	}
   136     }
   137     if( audio_driver_list[i] == NULL ) {
   138 	ERROR( "Audio driver '%s' not found, using null driver", audio_driver_name );
   139 	audio_set_driver( &audio_null_driver, 44100, AUDIO_FMT_16ST );
   140     }
   142     if( headless ) {
   143 	display_set_driver( &display_null_driver );
   144     } else {
   145 	for( i=0; display_driver_list[i] != NULL; i++ ) {
   146 	    if( strcasecmp( display_driver_list[i]->name, display_driver_name ) == 0 ) {
   147 		display_set_driver( display_driver_list[i] );
   148 		break;
   149 	    }
   150 	}
   151 	if( display_driver_list[i] == NULL ) {
   152 	    ERROR( "Video driver '%s' not found, using null driver", display_driver_name );
   153 	    display_set_driver( &display_null_driver );
   154 	}
   155     }
   157     maple_reattach_all();
   158     INFO( "%s! ready...", APP_NAME );
   159     if( optind < argc ) {
   160 	file_load_magic( argv[optind] );
   161     }
   163     if( disc_file != NULL ) {
   164 	gdrom_mount_image( disc_file );
   165     }
   167     if( start_immediately )
   168 	dreamcast_run();
   169     if( !headless ) {
   170         gtk_main ();
   171     }
   172     return 0;
   173 }
.