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
file annotate diff log raw
nkeynes@30
     1
/**
nkeynes@370
     2
 * $Id: main.c,v 1.21 2007-09-08 04:05:35 nkeynes Exp $
nkeynes@30
     3
 *
nkeynes@30
     4
 * Main program, initializes dreamcast and gui, then passes control off to
nkeynes@30
     5
 * the gtk main loop (currently). 
nkeynes@30
     6
 *
nkeynes@30
     7
 * FIXME: Remove explicit GTK/Gnome references from this file
nkeynes@30
     8
 *
nkeynes@30
     9
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@30
    10
 *
nkeynes@30
    11
 * This program is free software; you can redistribute it and/or modify
nkeynes@30
    12
 * it under the terms of the GNU General Public License as published by
nkeynes@30
    13
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@30
    14
 * (at your option) any later version.
nkeynes@30
    15
 *
nkeynes@30
    16
 * This program is distributed in the hope that it will be useful,
nkeynes@30
    17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@30
    18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@30
    19
 * GNU General Public License for more details.
nkeynes@1
    20
 */
nkeynes@1
    21
nkeynes@1
    22
#ifdef HAVE_CONFIG_H
nkeynes@1
    23
#  include <config.h>
nkeynes@1
    24
#endif
nkeynes@68
    25
#include <unistd.h>
nkeynes@94
    26
#include <getopt.h>
nkeynes@1
    27
#include <gnome.h>
nkeynes@25
    28
#include "gui/gui.h"
nkeynes@27
    29
#include "dream.h"
nkeynes@105
    30
#include "syscall.h"
nkeynes@27
    31
#include "dreamcast.h"
nkeynes@106
    32
#include "aica/audio.h"
nkeynes@144
    33
#include "display.h"
nkeynes@144
    34
#include "maple/maple.h"
nkeynes@11
    35
nkeynes@77
    36
#define S3M_PLAYER "s3mplay.bin"
nkeynes@77
    37
nkeynes@209
    38
char *option_list = "a:s:A:V:puhbd:c:";
nkeynes@94
    39
struct option longopts[1] = { { NULL, 0, 0, 0 } };
nkeynes@68
    40
char *aica_program = NULL;
nkeynes@77
    41
char *s3m_file = NULL;
nkeynes@144
    42
char *disc_file = NULL;
nkeynes@144
    43
char *display_driver_name = "gtk";
nkeynes@106
    44
char *audio_driver_name = "esd";
nkeynes@144
    45
char *config_file = DEFAULT_CONFIG_FILENAME;
nkeynes@68
    46
gboolean start_immediately = FALSE;
nkeynes@77
    47
gboolean headless = FALSE;
nkeynes@87
    48
gboolean without_bios = FALSE;
nkeynes@68
    49
nkeynes@106
    50
audio_driver_t audio_driver_list[] = { &audio_null_driver,
nkeynes@106
    51
				       &audio_esd_driver,
nkeynes@106
    52
				       NULL };
nkeynes@106
    53
nkeynes@144
    54
display_driver_t display_driver_list[] = { &display_null_driver,
nkeynes@144
    55
					   &display_gtk_driver,
nkeynes@144
    56
					   NULL };
nkeynes@106
    57
nkeynes@30
    58
int main (int argc, char *argv[])
nkeynes@1
    59
{
nkeynes@106
    60
    int opt, i;
nkeynes@1
    61
#ifdef ENABLE_NLS
nkeynes@68
    62
    bindtextdomain (PACKAGE, PACKAGE_LOCALE_DIR);
nkeynes@68
    63
    textdomain (PACKAGE);
nkeynes@1
    64
#endif
nkeynes@68
    65
  
nkeynes@94
    66
    while( (opt = getopt_long( argc, argv, option_list, longopts, NULL )) != -1 ) {
nkeynes@68
    67
	switch( opt ) {
nkeynes@68
    68
	case 'a': /* AICA only mode - argument is an AICA program */
nkeynes@68
    69
	    aica_program = optarg;
nkeynes@68
    70
	    break;
nkeynes@144
    71
	case 'c': /* Config file */
nkeynes@144
    72
	    config_file = optarg;
nkeynes@144
    73
	    break;
nkeynes@144
    74
	case 'd': /* Mount disc */
nkeynes@144
    75
	    disc_file = optarg;
nkeynes@144
    76
	    break;
nkeynes@77
    77
	case 's': /* AICA-only w/ S3M player */
nkeynes@77
    78
	    aica_program = S3M_PLAYER;
nkeynes@77
    79
	    s3m_file = optarg;
nkeynes@77
    80
	    break;
nkeynes@68
    81
	case 'A': /* Audio driver */
nkeynes@106
    82
	    audio_driver_name = optarg;
nkeynes@68
    83
	    break;
nkeynes@68
    84
	case 'V': /* Video driver */
nkeynes@144
    85
	    display_driver_name = optarg;
nkeynes@68
    86
	    break;
nkeynes@68
    87
	case 'p': /* Start immediately */
nkeynes@68
    88
	    start_immediately = TRUE;
nkeynes@77
    89
    	    break;
nkeynes@209
    90
	case 'u': /* Allow unsafe dcload syscalls */
nkeynes@209
    91
	    dcload_set_allow_unsafe(TRUE);
nkeynes@182
    92
	    break;
nkeynes@87
    93
    	case 'b': /* No BIOS */
nkeynes@87
    94
    	    without_bios = TRUE;
nkeynes@87
    95
    	    break;
nkeynes@77
    96
        case 'h': /* Headless */
nkeynes@77
    97
            headless = TRUE;
nkeynes@77
    98
            break;
nkeynes@68
    99
	}
nkeynes@68
   100
    }
nkeynes@30
   101
nkeynes@144
   102
    dreamcast_load_config( config_file );
nkeynes@144
   103
nkeynes@68
   104
    if( aica_program == NULL ) {
nkeynes@77
   105
	if( !headless ) {
nkeynes@180
   106
	    gnome_init ("lxdream", VERSION, argc, argv);
nkeynes@94
   107
	    dreamcast_init();
nkeynes@77
   108
	    dreamcast_register_module( &gtk_gui_module );
nkeynes@94
   109
	} else {
nkeynes@94
   110
	    dreamcast_init();
nkeynes@77
   111
	}
nkeynes@105
   112
nkeynes@68
   113
    } else {
nkeynes@68
   114
	dreamcast_configure_aica_only();
nkeynes@68
   115
	mem_load_block( aica_program, 0x00800000, 2048*1024 );
nkeynes@77
   116
	if( s3m_file != NULL ) {
nkeynes@77
   117
	    mem_load_block( s3m_file, 0x00810000, 2048*1024 - 0x10000 );
nkeynes@77
   118
	}
nkeynes@77
   119
	if( !headless ) {
nkeynes@180
   120
	    gnome_init ("lxdream", VERSION, argc, argv);
nkeynes@77
   121
	    dreamcast_register_module( &gtk_gui_module );
nkeynes@77
   122
	    set_disassembly_cpu( main_debug, "ARM7" );
nkeynes@77
   123
	}
nkeynes@68
   124
    }
nkeynes@1
   125
nkeynes@87
   126
    if( without_bios ) {
nkeynes@87
   127
    	bios_install();
nkeynes@105
   128
	dcload_install();
nkeynes@87
   129
    }
nkeynes@106
   130
nkeynes@106
   131
    for( i=0; audio_driver_list[i] != NULL; i++ ) {
nkeynes@106
   132
	if( strcasecmp( audio_driver_list[i]->name, audio_driver_name ) == 0 ) {
nkeynes@111
   133
	    if( audio_set_driver( audio_driver_list[i], 44100, AUDIO_FMT_16ST ) == FALSE ) {
nkeynes@111
   134
		audio_set_driver( &audio_null_driver, 44100, AUDIO_FMT_16ST );
nkeynes@111
   135
	    }
nkeynes@106
   136
	    break;
nkeynes@106
   137
	}
nkeynes@106
   138
nkeynes@106
   139
    }
nkeynes@106
   140
    if( audio_driver_list[i] == NULL ) {
nkeynes@106
   141
	ERROR( "Audio driver '%s' not found, using null driver", audio_driver_name );
nkeynes@106
   142
	audio_set_driver( &audio_null_driver, 44100, AUDIO_FMT_16ST );
nkeynes@106
   143
    }
nkeynes@106
   144
nkeynes@106
   145
    if( headless ) {
nkeynes@144
   146
	display_set_driver( &display_null_driver );
nkeynes@106
   147
    } else {
nkeynes@370
   148
	gboolean initialized = FALSE;
nkeynes@144
   149
	for( i=0; display_driver_list[i] != NULL; i++ ) {
nkeynes@144
   150
	    if( strcasecmp( display_driver_list[i]->name, display_driver_name ) == 0 ) {
nkeynes@370
   151
		initialized = display_set_driver( display_driver_list[i] );
nkeynes@106
   152
		break;
nkeynes@106
   153
	    }
nkeynes@106
   154
	}
nkeynes@370
   155
	if( !initialized ) {
nkeynes@370
   156
	    if( display_driver_list[i] == NULL ) {
nkeynes@370
   157
		ERROR( "Video driver '%s' not found, using null driver", display_driver_name );
nkeynes@370
   158
	    } else {
nkeynes@370
   159
		ERROR( "Video driver '%s' failed to initialize, falling back to null driver", display_driver_name );
nkeynes@370
   160
	    }
nkeynes@144
   161
	    display_set_driver( &display_null_driver );
nkeynes@106
   162
	}
nkeynes@106
   163
    }
nkeynes@106
   164
nkeynes@144
   165
    maple_reattach_all();
nkeynes@180
   166
    INFO( "%s! ready...", APP_NAME );
nkeynes@94
   167
    if( optind < argc ) {
nkeynes@94
   168
	file_load_magic( argv[optind] );
nkeynes@94
   169
    }
nkeynes@94
   170
nkeynes@144
   171
    if( disc_file != NULL ) {
nkeynes@144
   172
	gdrom_mount_image( disc_file );
nkeynes@144
   173
    }
nkeynes@144
   174
nkeynes@68
   175
    if( start_immediately )
nkeynes@68
   176
	dreamcast_run();
nkeynes@77
   177
    if( !headless ) {
nkeynes@77
   178
        gtk_main ();
nkeynes@77
   179
    }
nkeynes@68
   180
    return 0;
nkeynes@1
   181
}
nkeynes@1
   182
.