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