2 * $Id: main.c,v 1.35 2007-11-07 11:45:53 nkeynes Exp $
4 * Main program, initializes dreamcast and gui, then passes control off to
5 * the gtk main loop (currently).
7 * FIXME: Remove explicit GTK/Gnome references from this file
9 * Copyright (c) 2005 Nathan Keynes.
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
28 #include "dreamcast.h"
32 #include "aica/audio.h"
33 #include "gdrom/gdrom.h"
34 #include "maple/maple.h"
35 #include "sh4/sh4core.h"
37 #define S3M_PLAYER "s3mplay.bin"
39 char *option_list = "a:m:s:A:V:puhbd:c:t:xD";
40 struct option longopts[1] = { { NULL, 0, 0, 0 } };
41 char *aica_program = NULL;
42 char *s3m_file = NULL;
43 const char *disc_file = NULL;
44 char *display_driver_name = "gtk";
45 char *audio_driver_name = "esd";
46 gboolean start_immediately = FALSE;
47 gboolean headless = FALSE;
48 gboolean without_bios = FALSE;
49 gboolean use_xlat = TRUE;
50 gboolean show_debugger = FALSE;
51 uint32_t time_secs = 0;
52 uint32_t time_nanos = 0;
53 extern uint32_t sh4_cpu_multiplier;
55 audio_driver_t audio_driver_list[] = { &audio_null_driver,
59 display_driver_t display_driver_list[] = { &display_null_driver,
63 int main (int argc, char *argv[])
68 install_crash_handler();
70 bindtextdomain (PACKAGE, PACKAGE_LOCALE_DIR);
73 gui_parse_cmdline(&argc, &argv);
75 while( (opt = getopt_long( argc, argv, option_list, longopts, NULL )) != -1 ) {
77 case 'a': /* AICA only mode - argument is an AICA program */
78 aica_program = optarg;
80 case 'c': /* Config file */
81 lxdream_set_config_filename(optarg);
83 case 'd': /* Mount disc */
86 case 'D': /* Launch w/ debugger */
89 case 'm': /* Set SH4 CPU clock multiplier (default 0.5) */
90 t = strtod(optarg, NULL);
91 sh4_cpu_multiplier = (int)(1000.0/t);
93 case 's': /* AICA-only w/ S3M player */
94 aica_program = S3M_PLAYER;
97 case 'A': /* Audio driver */
98 audio_driver_name = optarg;
100 case 'V': /* Video driver */
101 display_driver_name = optarg;
103 case 'p': /* Start immediately */
104 start_immediately = TRUE;
106 case 'u': /* Allow unsafe dcload syscalls */
107 dcload_set_allow_unsafe(TRUE);
109 case 'b': /* No BIOS */
112 case 'h': /* Headless */
115 case 't': /* Time limit */
116 t = strtod(optarg, NULL);
117 time_secs = (uint32_t)t;
118 time_nanos = (int)((t - time_secs) * 1000000000);
120 case 'x': /* Disable translator */
126 lxdream_load_config( );
128 if( aica_program == NULL ) {
131 dreamcast_configure_aica_only();
132 mem_load_block( aica_program, 0x00800000, 2048*1024 );
133 if( s3m_file != NULL ) {
134 mem_load_block( s3m_file, 0x00810000, 2048*1024 - 0x10000 );
143 for( i=0; audio_driver_list[i] != NULL; i++ ) {
144 if( strcasecmp( audio_driver_list[i]->name, audio_driver_name ) == 0 ) {
145 if( audio_set_driver( audio_driver_list[i], 44100, AUDIO_FMT_16ST ) == FALSE ) {
146 audio_set_driver( &audio_null_driver, 44100, AUDIO_FMT_16ST );
152 if( audio_driver_list[i] == NULL ) {
153 ERROR( "Audio driver '%s' not found, using null driver", audio_driver_name );
154 audio_set_driver( &audio_null_driver, 44100, AUDIO_FMT_16ST );
158 display_set_driver( &display_null_driver );
160 gui_init(show_debugger);
162 gboolean initialized = FALSE;
163 for( i=0; display_driver_list[i] != NULL; i++ ) {
164 if( strcasecmp( display_driver_list[i]->name, display_driver_name ) == 0 ) {
165 initialized = display_set_driver( display_driver_list[i] );
170 if( display_driver_list[i] == NULL ) {
171 ERROR( "Video driver '%s' not found, using null driver", display_driver_name );
173 ERROR( "Video driver '%s' failed to initialize, falling back to null driver", display_driver_name );
175 display_set_driver( &display_null_driver );
179 maple_reattach_all();
180 INFO( "%s! ready...", APP_NAME );
182 for( ; optind < argc; optind++ ) {
183 gboolean ok = gdrom_menu_open_file(argv[optind]);
185 ok = file_load_magic( argv[optind] );
188 ERROR( "Unrecognized file '%s'", argv[optind] );
190 start_immediately = ok;
193 if( disc_file != NULL ) {
194 gdrom_menu_open_file( disc_file );
197 if( gdrom_get_current_disc() == NULL ) {
198 disc_file = lxdream_get_config_value( CONFIG_GDROM );
199 if( disc_file != NULL ) {
200 gdrom_menu_open_file( disc_file );
204 sh4_set_use_xlat( use_xlat );
206 if( start_immediately ) {
207 if( time_nanos != 0 || time_secs != 0 ) {
208 dreamcast_run_for(time_secs, time_nanos);
.