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