2 * $Id: main.c,v 1.26 2007-10-03 08:22:27 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.
31 #include "dreamcast.h"
32 #include "aica/audio.h"
34 #include "maple/maple.h"
36 #define S3M_PLAYER "s3mplay.bin"
38 char *option_list = "a:m:s:A:V:puhbd:c:t:xD";
39 struct option longopts[1] = { { NULL, 0, 0, 0 } };
40 char *aica_program = NULL;
41 char *s3m_file = NULL;
42 char *disc_file = NULL;
43 char *display_driver_name = "gtk";
44 char *audio_driver_name = "esd";
45 char *config_file = DEFAULT_CONFIG_FILENAME;
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 bindtextdomain (PACKAGE, PACKAGE_LOCALE_DIR);
72 while( (opt = getopt_long( argc, argv, option_list, longopts, NULL )) != -1 ) {
74 case 'a': /* AICA only mode - argument is an AICA program */
75 aica_program = optarg;
77 case 'c': /* Config file */
80 case 'd': /* Mount disc */
83 case 'D': /* Launch w/ debugger */
86 case 'm': /* Set SH4 CPU clock multiplier (default 0.5) */
87 t = strtod(optarg, NULL);
88 sh4_cpu_multiplier = (int)(1000.0/t);
90 case 's': /* AICA-only w/ S3M player */
91 aica_program = S3M_PLAYER;
94 case 'A': /* Audio driver */
95 audio_driver_name = optarg;
97 case 'V': /* Video driver */
98 display_driver_name = optarg;
100 case 'p': /* Start immediately */
101 start_immediately = TRUE;
103 case 'u': /* Allow unsafe dcload syscalls */
104 dcload_set_allow_unsafe(TRUE);
106 case 'b': /* No BIOS */
109 case 'h': /* Headless */
112 case 't': /* Time limit */
113 t = strtod(optarg, NULL);
114 time_secs = (uint32_t)t;
115 time_nanos = (int)((t - time_secs) * 1000000000);
117 case 'x': /* Disable translator */
123 dreamcast_load_config( config_file );
125 if( aica_program == NULL ) {
127 gnome_init ("lxdream", VERSION, argc, argv);
129 dreamcast_register_module( >k_gui_module );
130 if( show_debugger ) {
131 gtk_gui_show_debugger();
138 dreamcast_configure_aica_only();
139 mem_load_block( aica_program, 0x00800000, 2048*1024 );
140 if( s3m_file != NULL ) {
141 mem_load_block( s3m_file, 0x00810000, 2048*1024 - 0x10000 );
144 gnome_init ("lxdream", VERSION, argc, argv);
145 dreamcast_register_module( >k_gui_module );
146 set_disassembly_cpu( main_debug, "ARM7" );
155 for( i=0; audio_driver_list[i] != NULL; i++ ) {
156 if( strcasecmp( audio_driver_list[i]->name, audio_driver_name ) == 0 ) {
157 if( audio_set_driver( audio_driver_list[i], 44100, AUDIO_FMT_16ST ) == FALSE ) {
158 audio_set_driver( &audio_null_driver, 44100, AUDIO_FMT_16ST );
164 if( audio_driver_list[i] == NULL ) {
165 ERROR( "Audio driver '%s' not found, using null driver", audio_driver_name );
166 audio_set_driver( &audio_null_driver, 44100, AUDIO_FMT_16ST );
170 display_set_driver( &display_null_driver );
172 gboolean initialized = FALSE;
173 for( i=0; display_driver_list[i] != NULL; i++ ) {
174 if( strcasecmp( display_driver_list[i]->name, display_driver_name ) == 0 ) {
175 initialized = display_set_driver( display_driver_list[i] );
180 if( display_driver_list[i] == NULL ) {
181 ERROR( "Video driver '%s' not found, using null driver", display_driver_name );
183 ERROR( "Video driver '%s' failed to initialize, falling back to null driver", display_driver_name );
185 display_set_driver( &display_null_driver );
189 maple_reattach_all();
190 INFO( "%s! ready...", APP_NAME );
191 if( optind < argc ) {
192 file_load_magic( argv[optind] );
195 if( disc_file != NULL ) {
196 gdrom_mount_image( disc_file );
199 sh4_set_use_xlat( use_xlat );
201 if( start_immediately ) {
202 if( time_nanos != 0 || time_secs != 0 ) {
203 dreamcast_run_for(time_secs, time_nanos);
.