Search
lxdream.org :: lxdream/src/main.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/main.c
changeset 392:39e596b3b6dd
prev379:7e1c33a184d8
next402:85fd4a4582be
author nkeynes
date Tue Sep 18 10:48:57 2007 +0000 (14 years ago)
permissions -rw-r--r--
last change Remove debugger from default startup - now only shown if started with -D
file annotate diff log raw
nkeynes@30
     1
/**
nkeynes@392
     2
 * $Id: main.c,v 1.24 2007-09-18 10:48:57 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@392
    38
char *option_list = "a:s:A:V:puhbd:c:t:xD";
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@379
    49
gboolean use_xlat = FALSE;
nkeynes@392
    50
gboolean show_debugger = FALSE;
nkeynes@372
    51
uint32_t time_secs = 0;
nkeynes@372
    52
uint32_t time_nanos = 0;
nkeynes@68
    53
nkeynes@106
    54
audio_driver_t audio_driver_list[] = { &audio_null_driver,
nkeynes@106
    55
				       &audio_esd_driver,
nkeynes@106
    56
				       NULL };
nkeynes@106
    57
nkeynes@144
    58
display_driver_t display_driver_list[] = { &display_null_driver,
nkeynes@144
    59
					   &display_gtk_driver,
nkeynes@144
    60
					   NULL };
nkeynes@106
    61
nkeynes@30
    62
int main (int argc, char *argv[])
nkeynes@1
    63
{
nkeynes@106
    64
    int opt, i;
nkeynes@372
    65
    double t;
nkeynes@1
    66
#ifdef ENABLE_NLS
nkeynes@68
    67
    bindtextdomain (PACKAGE, PACKAGE_LOCALE_DIR);
nkeynes@68
    68
    textdomain (PACKAGE);
nkeynes@1
    69
#endif
nkeynes@68
    70
  
nkeynes@94
    71
    while( (opt = getopt_long( argc, argv, option_list, longopts, NULL )) != -1 ) {
nkeynes@68
    72
	switch( opt ) {
nkeynes@68
    73
	case 'a': /* AICA only mode - argument is an AICA program */
nkeynes@68
    74
	    aica_program = optarg;
nkeynes@68
    75
	    break;
nkeynes@144
    76
	case 'c': /* Config file */
nkeynes@144
    77
	    config_file = optarg;
nkeynes@144
    78
	    break;
nkeynes@144
    79
	case 'd': /* Mount disc */
nkeynes@144
    80
	    disc_file = optarg;
nkeynes@144
    81
	    break;
nkeynes@392
    82
	case 'D': /* Launch w/ debugger */
nkeynes@392
    83
	    show_debugger = TRUE;
nkeynes@392
    84
	    break;
nkeynes@77
    85
	case 's': /* AICA-only w/ S3M player */
nkeynes@77
    86
	    aica_program = S3M_PLAYER;
nkeynes@77
    87
	    s3m_file = optarg;
nkeynes@77
    88
	    break;
nkeynes@68
    89
	case 'A': /* Audio driver */
nkeynes@106
    90
	    audio_driver_name = optarg;
nkeynes@68
    91
	    break;
nkeynes@68
    92
	case 'V': /* Video driver */
nkeynes@144
    93
	    display_driver_name = optarg;
nkeynes@68
    94
	    break;
nkeynes@68
    95
	case 'p': /* Start immediately */
nkeynes@68
    96
	    start_immediately = TRUE;
nkeynes@77
    97
    	    break;
nkeynes@209
    98
	case 'u': /* Allow unsafe dcload syscalls */
nkeynes@209
    99
	    dcload_set_allow_unsafe(TRUE);
nkeynes@182
   100
	    break;
nkeynes@87
   101
    	case 'b': /* No BIOS */
nkeynes@87
   102
    	    without_bios = TRUE;
nkeynes@87
   103
    	    break;
nkeynes@77
   104
        case 'h': /* Headless */
nkeynes@77
   105
            headless = TRUE;
nkeynes@77
   106
            break;
nkeynes@372
   107
	case 't': /* Time limit */
nkeynes@372
   108
	    t = strtod(optarg, NULL);
nkeynes@372
   109
	    time_secs = (uint32_t)t;
nkeynes@372
   110
	    time_nanos = (int)((t - time_secs) * 1000000000);
nkeynes@379
   111
	    break;
nkeynes@379
   112
	case 'x': /* Use experimental translator */
nkeynes@379
   113
	    use_xlat = TRUE;
nkeynes@379
   114
	    break;
nkeynes@68
   115
	}
nkeynes@68
   116
    }
nkeynes@30
   117
nkeynes@144
   118
    dreamcast_load_config( config_file );
nkeynes@144
   119
nkeynes@68
   120
    if( aica_program == NULL ) {
nkeynes@77
   121
	if( !headless ) {
nkeynes@180
   122
	    gnome_init ("lxdream", VERSION, argc, argv);
nkeynes@94
   123
	    dreamcast_init();
nkeynes@77
   124
	    dreamcast_register_module( &gtk_gui_module );
nkeynes@392
   125
	    if( show_debugger ) {
nkeynes@392
   126
		gtk_gui_show_debugger();
nkeynes@392
   127
	    }
nkeynes@94
   128
	} else {
nkeynes@94
   129
	    dreamcast_init();
nkeynes@77
   130
	}
nkeynes@105
   131
nkeynes@68
   132
    } else {
nkeynes@68
   133
	dreamcast_configure_aica_only();
nkeynes@68
   134
	mem_load_block( aica_program, 0x00800000, 2048*1024 );
nkeynes@77
   135
	if( s3m_file != NULL ) {
nkeynes@77
   136
	    mem_load_block( s3m_file, 0x00810000, 2048*1024 - 0x10000 );
nkeynes@77
   137
	}
nkeynes@77
   138
	if( !headless ) {
nkeynes@180
   139
	    gnome_init ("lxdream", VERSION, argc, argv);
nkeynes@77
   140
	    dreamcast_register_module( &gtk_gui_module );
nkeynes@77
   141
	    set_disassembly_cpu( main_debug, "ARM7" );
nkeynes@77
   142
	}
nkeynes@68
   143
    }
nkeynes@1
   144
nkeynes@87
   145
    if( without_bios ) {
nkeynes@87
   146
    	bios_install();
nkeynes@105
   147
	dcload_install();
nkeynes@87
   148
    }
nkeynes@106
   149
nkeynes@106
   150
    for( i=0; audio_driver_list[i] != NULL; i++ ) {
nkeynes@106
   151
	if( strcasecmp( audio_driver_list[i]->name, audio_driver_name ) == 0 ) {
nkeynes@111
   152
	    if( audio_set_driver( audio_driver_list[i], 44100, AUDIO_FMT_16ST ) == FALSE ) {
nkeynes@111
   153
		audio_set_driver( &audio_null_driver, 44100, AUDIO_FMT_16ST );
nkeynes@111
   154
	    }
nkeynes@106
   155
	    break;
nkeynes@106
   156
	}
nkeynes@106
   157
nkeynes@106
   158
    }
nkeynes@106
   159
    if( audio_driver_list[i] == NULL ) {
nkeynes@106
   160
	ERROR( "Audio driver '%s' not found, using null driver", audio_driver_name );
nkeynes@106
   161
	audio_set_driver( &audio_null_driver, 44100, AUDIO_FMT_16ST );
nkeynes@106
   162
    }
nkeynes@106
   163
nkeynes@106
   164
    if( headless ) {
nkeynes@144
   165
	display_set_driver( &display_null_driver );
nkeynes@106
   166
    } else {
nkeynes@370
   167
	gboolean initialized = FALSE;
nkeynes@144
   168
	for( i=0; display_driver_list[i] != NULL; i++ ) {
nkeynes@144
   169
	    if( strcasecmp( display_driver_list[i]->name, display_driver_name ) == 0 ) {
nkeynes@370
   170
		initialized = display_set_driver( display_driver_list[i] );
nkeynes@106
   171
		break;
nkeynes@106
   172
	    }
nkeynes@106
   173
	}
nkeynes@370
   174
	if( !initialized ) {
nkeynes@370
   175
	    if( display_driver_list[i] == NULL ) {
nkeynes@370
   176
		ERROR( "Video driver '%s' not found, using null driver", display_driver_name );
nkeynes@370
   177
	    } else {
nkeynes@370
   178
		ERROR( "Video driver '%s' failed to initialize, falling back to null driver", display_driver_name );
nkeynes@370
   179
	    }
nkeynes@144
   180
	    display_set_driver( &display_null_driver );
nkeynes@106
   181
	}
nkeynes@106
   182
    }
nkeynes@106
   183
nkeynes@144
   184
    maple_reattach_all();
nkeynes@180
   185
    INFO( "%s! ready...", APP_NAME );
nkeynes@94
   186
    if( optind < argc ) {
nkeynes@94
   187
	file_load_magic( argv[optind] );
nkeynes@94
   188
    }
nkeynes@94
   189
nkeynes@144
   190
    if( disc_file != NULL ) {
nkeynes@144
   191
	gdrom_mount_image( disc_file );
nkeynes@144
   192
    }
nkeynes@144
   193
nkeynes@379
   194
    sh4_set_use_xlat( use_xlat );
nkeynes@379
   195
nkeynes@372
   196
    if( start_immediately ) {
nkeynes@372
   197
	if( time_nanos != 0 || time_secs != 0 ) {
nkeynes@372
   198
	    dreamcast_run_for(time_secs, time_nanos);
nkeynes@372
   199
	    return 0;
nkeynes@372
   200
	} else {
nkeynes@372
   201
	    dreamcast_run();
nkeynes@372
   202
	}
nkeynes@372
   203
    }
nkeynes@77
   204
    if( !headless ) {
nkeynes@77
   205
        gtk_main ();
nkeynes@77
   206
    }
nkeynes@68
   207
    return 0;
nkeynes@1
   208
}
nkeynes@1
   209
.