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