Search
lxdream.org :: lxdream/src/main.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/main.c
changeset 470:e09a16196693
prev469:3e2a0fde5cd8
next480:d28c2992f5ee
author nkeynes
date Sun Oct 28 08:29:29 2007 +0000 (12 years ago)
permissions -rw-r--r--
last change Maintain current gdrom and recently-used list in config file
file annotate diff log raw
nkeynes@30
     1
/**
nkeynes@470
     2
 * $Id: main.c,v 1.33 2007-10-28 08:29:29 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@68
    22
#include <unistd.h>
nkeynes@94
    23
#include <getopt.h>
nkeynes@27
    24
#include "dream.h"
nkeynes@450
    25
#include "config.h"
nkeynes@105
    26
#include "syscall.h"
nkeynes@422
    27
#include "mem.h"
nkeynes@27
    28
#include "dreamcast.h"
nkeynes@422
    29
#include "display.h"
nkeynes@422
    30
#include "loader.h"
nkeynes@450
    31
#include "gui.h"
nkeynes@106
    32
#include "aica/audio.h"
nkeynes@422
    33
#include "gdrom/gdrom.h"
nkeynes@144
    34
#include "maple/maple.h"
nkeynes@422
    35
#include "sh4/sh4core.h"
nkeynes@11
    36
nkeynes@77
    37
#define S3M_PLAYER "s3mplay.bin"
nkeynes@77
    38
nkeynes@414
    39
char *option_list = "a:m:s:A:V:puhbd:c:t:xD";
nkeynes@94
    40
struct option longopts[1] = { { NULL, 0, 0, 0 } };
nkeynes@68
    41
char *aica_program = NULL;
nkeynes@77
    42
char *s3m_file = NULL;
nkeynes@144
    43
char *disc_file = NULL;
nkeynes@144
    44
char *display_driver_name = "gtk";
nkeynes@106
    45
char *audio_driver_name = "esd";
nkeynes@68
    46
gboolean start_immediately = FALSE;
nkeynes@77
    47
gboolean headless = FALSE;
nkeynes@87
    48
gboolean without_bios = FALSE;
nkeynes@402
    49
gboolean use_xlat = TRUE;
nkeynes@392
    50
gboolean show_debugger = FALSE;
nkeynes@372
    51
uint32_t time_secs = 0;
nkeynes@372
    52
uint32_t time_nanos = 0;
nkeynes@414
    53
extern uint32_t sh4_cpu_multiplier;
nkeynes@68
    54
nkeynes@106
    55
audio_driver_t audio_driver_list[] = { &audio_null_driver,
nkeynes@106
    56
				       &audio_esd_driver,
nkeynes@106
    57
				       NULL };
nkeynes@106
    58
nkeynes@144
    59
display_driver_t display_driver_list[] = { &display_null_driver,
nkeynes@144
    60
					   &display_gtk_driver,
nkeynes@144
    61
					   NULL };
nkeynes@106
    62
nkeynes@30
    63
int main (int argc, char *argv[])
nkeynes@1
    64
{
nkeynes@106
    65
    int opt, i;
nkeynes@372
    66
    double t;
nkeynes@1
    67
#ifdef ENABLE_NLS
nkeynes@68
    68
    bindtextdomain (PACKAGE, PACKAGE_LOCALE_DIR);
nkeynes@68
    69
    textdomain (PACKAGE);
nkeynes@1
    70
#endif
nkeynes@435
    71
    gboolean ui_initialized = gui_parse_cmdline(&argc, &argv);
nkeynes@464
    72
nkeynes@94
    73
    while( (opt = getopt_long( argc, argv, option_list, longopts, NULL )) != -1 ) {
nkeynes@68
    74
	switch( opt ) {
nkeynes@68
    75
	case 'a': /* AICA only mode - argument is an AICA program */
nkeynes@68
    76
	    aica_program = optarg;
nkeynes@68
    77
	    break;
nkeynes@144
    78
	case 'c': /* Config file */
nkeynes@450
    79
	    lxdream_set_config_filename(optarg);
nkeynes@144
    80
	    break;
nkeynes@144
    81
	case 'd': /* Mount disc */
nkeynes@144
    82
	    disc_file = optarg;
nkeynes@144
    83
	    break;
nkeynes@392
    84
	case 'D': /* Launch w/ debugger */
nkeynes@392
    85
	    show_debugger = TRUE;
nkeynes@392
    86
	    break;
nkeynes@414
    87
	case 'm': /* Set SH4 CPU clock multiplier (default 0.5) */
nkeynes@414
    88
	    t = strtod(optarg, NULL);
nkeynes@414
    89
	    sh4_cpu_multiplier = (int)(1000.0/t);
nkeynes@414
    90
	    break;
nkeynes@77
    91
	case 's': /* AICA-only w/ S3M player */
nkeynes@77
    92
	    aica_program = S3M_PLAYER;
nkeynes@77
    93
	    s3m_file = optarg;
nkeynes@77
    94
	    break;
nkeynes@68
    95
	case 'A': /* Audio driver */
nkeynes@106
    96
	    audio_driver_name = optarg;
nkeynes@68
    97
	    break;
nkeynes@68
    98
	case 'V': /* Video driver */
nkeynes@144
    99
	    display_driver_name = optarg;
nkeynes@68
   100
	    break;
nkeynes@68
   101
	case 'p': /* Start immediately */
nkeynes@68
   102
	    start_immediately = TRUE;
nkeynes@77
   103
    	    break;
nkeynes@209
   104
	case 'u': /* Allow unsafe dcload syscalls */
nkeynes@209
   105
	    dcload_set_allow_unsafe(TRUE);
nkeynes@182
   106
	    break;
nkeynes@87
   107
    	case 'b': /* No BIOS */
nkeynes@87
   108
    	    without_bios = TRUE;
nkeynes@87
   109
    	    break;
nkeynes@77
   110
        case 'h': /* Headless */
nkeynes@77
   111
            headless = TRUE;
nkeynes@77
   112
            break;
nkeynes@372
   113
	case 't': /* Time limit */
nkeynes@372
   114
	    t = strtod(optarg, NULL);
nkeynes@372
   115
	    time_secs = (uint32_t)t;
nkeynes@372
   116
	    time_nanos = (int)((t - time_secs) * 1000000000);
nkeynes@379
   117
	    break;
nkeynes@402
   118
	case 'x': /* Disable translator */
nkeynes@402
   119
	    use_xlat = FALSE;
nkeynes@379
   120
	    break;
nkeynes@68
   121
	}
nkeynes@68
   122
    }
nkeynes@30
   123
nkeynes@450
   124
    lxdream_load_config( );
nkeynes@144
   125
nkeynes@68
   126
    if( aica_program == NULL ) {
nkeynes@435
   127
	dreamcast_init();
nkeynes@68
   128
    } else {
nkeynes@68
   129
	dreamcast_configure_aica_only();
nkeynes@68
   130
	mem_load_block( aica_program, 0x00800000, 2048*1024 );
nkeynes@77
   131
	if( s3m_file != NULL ) {
nkeynes@77
   132
	    mem_load_block( s3m_file, 0x00810000, 2048*1024 - 0x10000 );
nkeynes@77
   133
	}
nkeynes@68
   134
    }
nkeynes@1
   135
nkeynes@87
   136
    if( without_bios ) {
nkeynes@87
   137
    	bios_install();
nkeynes@105
   138
	dcload_install();
nkeynes@87
   139
    }
nkeynes@106
   140
nkeynes@106
   141
    for( i=0; audio_driver_list[i] != NULL; i++ ) {
nkeynes@106
   142
	if( strcasecmp( audio_driver_list[i]->name, audio_driver_name ) == 0 ) {
nkeynes@111
   143
	    if( audio_set_driver( audio_driver_list[i], 44100, AUDIO_FMT_16ST ) == FALSE ) {
nkeynes@111
   144
		audio_set_driver( &audio_null_driver, 44100, AUDIO_FMT_16ST );
nkeynes@111
   145
	    }
nkeynes@106
   146
	    break;
nkeynes@106
   147
	}
nkeynes@106
   148
nkeynes@106
   149
    }
nkeynes@106
   150
    if( audio_driver_list[i] == NULL ) {
nkeynes@106
   151
	ERROR( "Audio driver '%s' not found, using null driver", audio_driver_name );
nkeynes@106
   152
	audio_set_driver( &audio_null_driver, 44100, AUDIO_FMT_16ST );
nkeynes@106
   153
    }
nkeynes@106
   154
nkeynes@106
   155
    if( headless ) {
nkeynes@144
   156
	display_set_driver( &display_null_driver );
nkeynes@106
   157
    } else {
nkeynes@435
   158
	gui_init(show_debugger);
nkeynes@435
   159
nkeynes@370
   160
	gboolean initialized = FALSE;
nkeynes@144
   161
	for( i=0; display_driver_list[i] != NULL; i++ ) {
nkeynes@144
   162
	    if( strcasecmp( display_driver_list[i]->name, display_driver_name ) == 0 ) {
nkeynes@370
   163
		initialized = display_set_driver( display_driver_list[i] );
nkeynes@106
   164
		break;
nkeynes@106
   165
	    }
nkeynes@106
   166
	}
nkeynes@370
   167
	if( !initialized ) {
nkeynes@370
   168
	    if( display_driver_list[i] == NULL ) {
nkeynes@370
   169
		ERROR( "Video driver '%s' not found, using null driver", display_driver_name );
nkeynes@370
   170
	    } else {
nkeynes@370
   171
		ERROR( "Video driver '%s' failed to initialize, falling back to null driver", display_driver_name );
nkeynes@370
   172
	    }
nkeynes@144
   173
	    display_set_driver( &display_null_driver );
nkeynes@106
   174
	}
nkeynes@106
   175
    }
nkeynes@106
   176
nkeynes@144
   177
    maple_reattach_all();
nkeynes@180
   178
    INFO( "%s! ready...", APP_NAME );
nkeynes@446
   179
nkeynes@446
   180
    for( ; optind < argc; optind++ ) {
nkeynes@469
   181
	gboolean ok = gdrom_menu_open_file(argv[optind]);
nkeynes@446
   182
	if( !ok ) {
nkeynes@446
   183
	    ok = file_load_magic( argv[optind] );
nkeynes@446
   184
	}
nkeynes@446
   185
	if( !ok ) {
nkeynes@446
   186
	    ERROR( "Unrecognized file '%s'", argv[optind] );
nkeynes@446
   187
	}
nkeynes@446
   188
	start_immediately = ok;
nkeynes@94
   189
    }
nkeynes@94
   190
nkeynes@144
   191
    if( disc_file != NULL ) {
nkeynes@470
   192
	gdrom_menu_open_file( disc_file );
nkeynes@144
   193
    }
nkeynes@144
   194
nkeynes@464
   195
    if( gdrom_get_current_disc() == NULL ) {
nkeynes@464
   196
	disc_file = lxdream_get_config_value( CONFIG_GDROM );
nkeynes@464
   197
	if( disc_file != NULL ) {
nkeynes@469
   198
	    gdrom_menu_open_file( disc_file );
nkeynes@464
   199
	}
nkeynes@464
   200
    }
nkeynes@464
   201
nkeynes@379
   202
    sh4_set_use_xlat( use_xlat );
nkeynes@379
   203
nkeynes@372
   204
    if( start_immediately ) {
nkeynes@372
   205
	if( time_nanos != 0 || time_secs != 0 ) {
nkeynes@372
   206
	    dreamcast_run_for(time_secs, time_nanos);
nkeynes@372
   207
	    return 0;
nkeynes@372
   208
	} else {
nkeynes@372
   209
	    dreamcast_run();
nkeynes@372
   210
	}
nkeynes@372
   211
    }
nkeynes@77
   212
    if( !headless ) {
nkeynes@435
   213
	gui_main_loop();
nkeynes@77
   214
    }
nkeynes@68
   215
    return 0;
nkeynes@1
   216
}
nkeynes@1
   217
.