Search
lxdream.org :: lxdream/src/main.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/main.c
changeset 144:7f0714e89aaa
prev111:230243c2b520
next180:e6dcf9b65658
author nkeynes
date Mon May 15 08:28:52 2006 +0000 (14 years ago)
permissions -rw-r--r--
last change Rename video_driver to display_driver
Add input source to display
Implement configuration file support
Hook controllers up to configuration
file annotate diff log raw
nkeynes@30
     1
/**
nkeynes@144
     2
 * $Id: main.c,v 1.17 2006-05-15 08:28:48 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@144
    38
char *option_list = "a:s:A:V:phbd: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@87
    90
    	case 'b': /* No BIOS */
nkeynes@87
    91
    	    without_bios = TRUE;
nkeynes@87
    92
    	    break;
nkeynes@77
    93
        case 'h': /* Headless */
nkeynes@77
    94
            headless = TRUE;
nkeynes@77
    95
            break;
nkeynes@68
    96
	}
nkeynes@68
    97
    }
nkeynes@30
    98
nkeynes@144
    99
    dreamcast_load_config( config_file );
nkeynes@144
   100
nkeynes@68
   101
    if( aica_program == NULL ) {
nkeynes@77
   102
	if( !headless ) {
nkeynes@77
   103
	    gnome_init ("dreamon", VERSION, argc, argv);
nkeynes@94
   104
	    dreamcast_init();
nkeynes@77
   105
	    dreamcast_register_module( &gtk_gui_module );
nkeynes@94
   106
	} else {
nkeynes@94
   107
	    dreamcast_init();
nkeynes@77
   108
	}
nkeynes@105
   109
nkeynes@68
   110
    } else {
nkeynes@68
   111
	dreamcast_configure_aica_only();
nkeynes@68
   112
	mem_load_block( aica_program, 0x00800000, 2048*1024 );
nkeynes@77
   113
	if( s3m_file != NULL ) {
nkeynes@77
   114
	    mem_load_block( s3m_file, 0x00810000, 2048*1024 - 0x10000 );
nkeynes@77
   115
	}
nkeynes@77
   116
	if( !headless ) {
nkeynes@77
   117
	    gnome_init ("dreamon", VERSION, argc, argv);
nkeynes@77
   118
	    dreamcast_register_module( &gtk_gui_module );
nkeynes@77
   119
	    set_disassembly_cpu( main_debug, "ARM7" );
nkeynes@77
   120
	}
nkeynes@68
   121
    }
nkeynes@1
   122
nkeynes@87
   123
    if( without_bios ) {
nkeynes@87
   124
    	bios_install();
nkeynes@105
   125
	dcload_install();
nkeynes@87
   126
    }
nkeynes@106
   127
nkeynes@106
   128
    for( i=0; audio_driver_list[i] != NULL; i++ ) {
nkeynes@106
   129
	if( strcasecmp( audio_driver_list[i]->name, audio_driver_name ) == 0 ) {
nkeynes@111
   130
	    if( audio_set_driver( audio_driver_list[i], 44100, AUDIO_FMT_16ST ) == FALSE ) {
nkeynes@111
   131
		audio_set_driver( &audio_null_driver, 44100, AUDIO_FMT_16ST );
nkeynes@111
   132
	    }
nkeynes@106
   133
	    break;
nkeynes@106
   134
	}
nkeynes@106
   135
nkeynes@106
   136
    }
nkeynes@106
   137
    if( audio_driver_list[i] == NULL ) {
nkeynes@106
   138
	ERROR( "Audio driver '%s' not found, using null driver", audio_driver_name );
nkeynes@106
   139
	audio_set_driver( &audio_null_driver, 44100, AUDIO_FMT_16ST );
nkeynes@106
   140
    }
nkeynes@106
   141
nkeynes@106
   142
    if( headless ) {
nkeynes@144
   143
	display_set_driver( &display_null_driver );
nkeynes@106
   144
    } else {
nkeynes@144
   145
	for( i=0; display_driver_list[i] != NULL; i++ ) {
nkeynes@144
   146
	    if( strcasecmp( display_driver_list[i]->name, display_driver_name ) == 0 ) {
nkeynes@144
   147
		display_set_driver( display_driver_list[i] );
nkeynes@106
   148
		break;
nkeynes@106
   149
	    }
nkeynes@106
   150
	}
nkeynes@144
   151
	if( display_driver_list[i] == NULL ) {
nkeynes@144
   152
	    ERROR( "Video driver '%s' not found, using null driver", display_driver_name );
nkeynes@144
   153
	    display_set_driver( &display_null_driver );
nkeynes@106
   154
	}
nkeynes@106
   155
    }
nkeynes@106
   156
nkeynes@144
   157
    maple_reattach_all();
nkeynes@68
   158
    INFO( "DreamOn! ready..." );
nkeynes@94
   159
    if( optind < argc ) {
nkeynes@94
   160
	file_load_magic( argv[optind] );
nkeynes@94
   161
    }
nkeynes@94
   162
nkeynes@144
   163
    if( disc_file != NULL ) {
nkeynes@144
   164
	gdrom_mount_image( disc_file );
nkeynes@144
   165
    }
nkeynes@144
   166
nkeynes@68
   167
    if( start_immediately )
nkeynes@68
   168
	dreamcast_run();
nkeynes@77
   169
    if( !headless ) {
nkeynes@77
   170
        gtk_main ();
nkeynes@77
   171
    }
nkeynes@68
   172
    return 0;
nkeynes@1
   173
}
nkeynes@1
   174
.