2 * $Id: main.c,v 1.23 2007-09-12 09:21:01 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:s:A:V:puhbd:c:t:x";
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 = FALSE;
50 uint32_t time_secs = 0;
51 uint32_t time_nanos = 0;
53 audio_driver_t audio_driver_list[] = { &audio_null_driver,
57 display_driver_t display_driver_list[] = { &display_null_driver,
61 int main (int argc, char *argv[])
66 bindtextdomain (PACKAGE, PACKAGE_LOCALE_DIR);
70 while( (opt = getopt_long( argc, argv, option_list, longopts, NULL )) != -1 ) {
72 case 'a': /* AICA only mode - argument is an AICA program */
73 aica_program = optarg;
75 case 'c': /* Config file */
78 case 'd': /* Mount disc */
81 case 's': /* AICA-only w/ S3M player */
82 aica_program = S3M_PLAYER;
85 case 'A': /* Audio driver */
86 audio_driver_name = optarg;
88 case 'V': /* Video driver */
89 display_driver_name = optarg;
91 case 'p': /* Start immediately */
92 start_immediately = TRUE;
94 case 'u': /* Allow unsafe dcload syscalls */
95 dcload_set_allow_unsafe(TRUE);
97 case 'b': /* No BIOS */
100 case 'h': /* Headless */
103 case 't': /* Time limit */
104 t = strtod(optarg, NULL);
105 time_secs = (uint32_t)t;
106 time_nanos = (int)((t - time_secs) * 1000000000);
108 case 'x': /* Use experimental translator */
114 dreamcast_load_config( config_file );
116 if( aica_program == NULL ) {
118 gnome_init ("lxdream", VERSION, argc, argv);
120 dreamcast_register_module( >k_gui_module );
126 dreamcast_configure_aica_only();
127 mem_load_block( aica_program, 0x00800000, 2048*1024 );
128 if( s3m_file != NULL ) {
129 mem_load_block( s3m_file, 0x00810000, 2048*1024 - 0x10000 );
132 gnome_init ("lxdream", VERSION, argc, argv);
133 dreamcast_register_module( >k_gui_module );
134 set_disassembly_cpu( main_debug, "ARM7" );
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 gboolean initialized = FALSE;
161 for( i=0; display_driver_list[i] != NULL; i++ ) {
162 if( strcasecmp( display_driver_list[i]->name, display_driver_name ) == 0 ) {
163 initialized = display_set_driver( display_driver_list[i] );
168 if( display_driver_list[i] == NULL ) {
169 ERROR( "Video driver '%s' not found, using null driver", display_driver_name );
171 ERROR( "Video driver '%s' failed to initialize, falling back to null driver", display_driver_name );
173 display_set_driver( &display_null_driver );
177 maple_reattach_all();
178 INFO( "%s! ready...", APP_NAME );
179 if( optind < argc ) {
180 file_load_magic( argv[optind] );
183 if( disc_file != NULL ) {
184 gdrom_mount_image( disc_file );
187 sh4_set_use_xlat( use_xlat );
189 if( start_immediately ) {
190 if( time_nanos != 0 || time_secs != 0 ) {
191 dreamcast_run_for(time_secs, time_nanos);
.