2 * $Id: main.c,v 1.27 2007-10-06 09:00:10 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.
32 #include "dreamcast.h"
35 #include "aica/audio.h"
36 #include "gdrom/gdrom.h"
37 #include "maple/maple.h"
38 #include "sh4/sh4core.h"
40 #define S3M_PLAYER "s3mplay.bin"
42 char *option_list = "a:m:s:A:V:puhbd:c:t:xD";
43 struct option longopts[1] = { { NULL, 0, 0, 0 } };
44 char *aica_program = NULL;
45 char *s3m_file = NULL;
46 char *disc_file = NULL;
47 char *display_driver_name = "gtk";
48 char *audio_driver_name = "esd";
49 char *config_file = DEFAULT_CONFIG_FILENAME;
50 gboolean start_immediately = FALSE;
51 gboolean headless = FALSE;
52 gboolean without_bios = FALSE;
53 gboolean use_xlat = TRUE;
54 gboolean show_debugger = FALSE;
55 uint32_t time_secs = 0;
56 uint32_t time_nanos = 0;
57 extern uint32_t sh4_cpu_multiplier;
59 audio_driver_t audio_driver_list[] = { &audio_null_driver,
63 display_driver_t display_driver_list[] = { &display_null_driver,
67 int main (int argc, char *argv[])
72 bindtextdomain (PACKAGE, PACKAGE_LOCALE_DIR);
76 while( (opt = getopt_long( argc, argv, option_list, longopts, NULL )) != -1 ) {
78 case 'a': /* AICA only mode - argument is an AICA program */
79 aica_program = optarg;
81 case 'c': /* Config file */
84 case 'd': /* Mount disc */
87 case 'D': /* Launch w/ debugger */
90 case 'm': /* Set SH4 CPU clock multiplier (default 0.5) */
91 t = strtod(optarg, NULL);
92 sh4_cpu_multiplier = (int)(1000.0/t);
94 case 's': /* AICA-only w/ S3M player */
95 aica_program = S3M_PLAYER;
98 case 'A': /* Audio driver */
99 audio_driver_name = optarg;
101 case 'V': /* Video driver */
102 display_driver_name = optarg;
104 case 'p': /* Start immediately */
105 start_immediately = TRUE;
107 case 'u': /* Allow unsafe dcload syscalls */
108 dcload_set_allow_unsafe(TRUE);
110 case 'b': /* No BIOS */
113 case 'h': /* Headless */
116 case 't': /* Time limit */
117 t = strtod(optarg, NULL);
118 time_secs = (uint32_t)t;
119 time_nanos = (int)((t - time_secs) * 1000000000);
121 case 'x': /* Disable translator */
127 dreamcast_load_config( config_file );
129 if( aica_program == NULL ) {
131 gnome_init ("lxdream", VERSION, argc, argv);
133 dreamcast_register_module( >k_gui_module );
134 if( show_debugger ) {
135 gtk_gui_show_debugger();
142 dreamcast_configure_aica_only();
143 mem_load_block( aica_program, 0x00800000, 2048*1024 );
144 if( s3m_file != NULL ) {
145 mem_load_block( s3m_file, 0x00810000, 2048*1024 - 0x10000 );
148 gnome_init ("lxdream", VERSION, argc, argv);
149 dreamcast_register_module( >k_gui_module );
150 set_disassembly_cpu( main_debug, "ARM7" );
159 for( i=0; audio_driver_list[i] != NULL; i++ ) {
160 if( strcasecmp( audio_driver_list[i]->name, audio_driver_name ) == 0 ) {
161 if( audio_set_driver( audio_driver_list[i], 44100, AUDIO_FMT_16ST ) == FALSE ) {
162 audio_set_driver( &audio_null_driver, 44100, AUDIO_FMT_16ST );
168 if( audio_driver_list[i] == NULL ) {
169 ERROR( "Audio driver '%s' not found, using null driver", audio_driver_name );
170 audio_set_driver( &audio_null_driver, 44100, AUDIO_FMT_16ST );
174 display_set_driver( &display_null_driver );
176 gboolean initialized = FALSE;
177 for( i=0; display_driver_list[i] != NULL; i++ ) {
178 if( strcasecmp( display_driver_list[i]->name, display_driver_name ) == 0 ) {
179 initialized = display_set_driver( display_driver_list[i] );
184 if( display_driver_list[i] == NULL ) {
185 ERROR( "Video driver '%s' not found, using null driver", display_driver_name );
187 ERROR( "Video driver '%s' failed to initialize, falling back to null driver", display_driver_name );
189 display_set_driver( &display_null_driver );
193 maple_reattach_all();
194 INFO( "%s! ready...", APP_NAME );
195 if( optind < argc ) {
196 file_load_magic( argv[optind] );
199 if( disc_file != NULL ) {
200 gdrom_mount_image( disc_file );
203 sh4_set_use_xlat( use_xlat );
205 if( start_immediately ) {
206 if( time_nanos != 0 || time_secs != 0 ) {
207 dreamcast_run_for(time_secs, time_nanos);
.