2 * $Id: main.c,v 1.24 2007-09-18 10:48:57 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: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 = FALSE;
50 gboolean show_debugger = FALSE;
51 uint32_t time_secs = 0;
52 uint32_t time_nanos = 0;
54 audio_driver_t audio_driver_list[] = { &audio_null_driver,
58 display_driver_t display_driver_list[] = { &display_null_driver,
62 int main (int argc, char *argv[])
67 bindtextdomain (PACKAGE, PACKAGE_LOCALE_DIR);
71 while( (opt = getopt_long( argc, argv, option_list, longopts, NULL )) != -1 ) {
73 case 'a': /* AICA only mode - argument is an AICA program */
74 aica_program = optarg;
76 case 'c': /* Config file */
79 case 'd': /* Mount disc */
82 case 'D': /* Launch w/ debugger */
85 case 's': /* AICA-only w/ S3M player */
86 aica_program = S3M_PLAYER;
89 case 'A': /* Audio driver */
90 audio_driver_name = optarg;
92 case 'V': /* Video driver */
93 display_driver_name = optarg;
95 case 'p': /* Start immediately */
96 start_immediately = TRUE;
98 case 'u': /* Allow unsafe dcload syscalls */
99 dcload_set_allow_unsafe(TRUE);
101 case 'b': /* No BIOS */
104 case 'h': /* Headless */
107 case 't': /* Time limit */
108 t = strtod(optarg, NULL);
109 time_secs = (uint32_t)t;
110 time_nanos = (int)((t - time_secs) * 1000000000);
112 case 'x': /* Use experimental translator */
118 dreamcast_load_config( config_file );
120 if( aica_program == NULL ) {
122 gnome_init ("lxdream", VERSION, argc, argv);
124 dreamcast_register_module( >k_gui_module );
125 if( show_debugger ) {
126 gtk_gui_show_debugger();
133 dreamcast_configure_aica_only();
134 mem_load_block( aica_program, 0x00800000, 2048*1024 );
135 if( s3m_file != NULL ) {
136 mem_load_block( s3m_file, 0x00810000, 2048*1024 - 0x10000 );
139 gnome_init ("lxdream", VERSION, argc, argv);
140 dreamcast_register_module( >k_gui_module );
141 set_disassembly_cpu( main_debug, "ARM7" );
150 for( i=0; audio_driver_list[i] != NULL; i++ ) {
151 if( strcasecmp( audio_driver_list[i]->name, audio_driver_name ) == 0 ) {
152 if( audio_set_driver( audio_driver_list[i], 44100, AUDIO_FMT_16ST ) == FALSE ) {
153 audio_set_driver( &audio_null_driver, 44100, AUDIO_FMT_16ST );
159 if( audio_driver_list[i] == NULL ) {
160 ERROR( "Audio driver '%s' not found, using null driver", audio_driver_name );
161 audio_set_driver( &audio_null_driver, 44100, AUDIO_FMT_16ST );
165 display_set_driver( &display_null_driver );
167 gboolean initialized = FALSE;
168 for( i=0; display_driver_list[i] != NULL; i++ ) {
169 if( strcasecmp( display_driver_list[i]->name, display_driver_name ) == 0 ) {
170 initialized = display_set_driver( display_driver_list[i] );
175 if( display_driver_list[i] == NULL ) {
176 ERROR( "Video driver '%s' not found, using null driver", display_driver_name );
178 ERROR( "Video driver '%s' failed to initialize, falling back to null driver", display_driver_name );
180 display_set_driver( &display_null_driver );
184 maple_reattach_all();
185 INFO( "%s! ready...", APP_NAME );
186 if( optind < argc ) {
187 file_load_magic( argv[optind] );
190 if( disc_file != NULL ) {
191 gdrom_mount_image( disc_file );
194 sh4_set_use_xlat( use_xlat );
196 if( start_immediately ) {
197 if( time_nanos != 0 || time_secs != 0 ) {
198 dreamcast_run_for(time_secs, time_nanos);
.