filename | src/main.c |
changeset | 464:8e099fad42a6 |
prev | 450:207461e79f21 |
next | 469:3e2a0fde5cd8 |
author | nkeynes |
date | Sun Oct 28 07:23:46 2007 +0000 (16 years ago) |
permissions | -rw-r--r-- |
last change | Fix CDI with multiple tracks/session Fix file being closed too early |
view | annotate | diff | log | raw |
1 /**
2 * $Id: main.c,v 1.31 2007-10-27 05:44:54 nkeynes Exp $
3 *
4 * Main program, initializes dreamcast and gui, then passes control off to
5 * the gtk main loop (currently).
6 *
7 * FIXME: Remove explicit GTK/Gnome references from this file
8 *
9 * Copyright (c) 2005 Nathan Keynes.
10 *
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.
15 *
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.
20 */
22 #include <unistd.h>
23 #include <getopt.h>
24 #include "dream.h"
25 #include "config.h"
26 #include "syscall.h"
27 #include "mem.h"
28 #include "dreamcast.h"
29 #include "display.h"
30 #include "loader.h"
31 #include "gui.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 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,
56 &audio_esd_driver,
57 NULL };
59 display_driver_t display_driver_list[] = { &display_null_driver,
60 &display_gtk_driver,
61 NULL };
63 int main (int argc, char *argv[])
64 {
65 int opt, i;
66 double t;
67 #ifdef ENABLE_NLS
68 bindtextdomain (PACKAGE, PACKAGE_LOCALE_DIR);
69 textdomain (PACKAGE);
70 #endif
71 gboolean ui_initialized = gui_parse_cmdline(&argc, &argv);
73 while( (opt = getopt_long( argc, argv, option_list, longopts, NULL )) != -1 ) {
74 switch( opt ) {
75 case 'a': /* AICA only mode - argument is an AICA program */
76 aica_program = optarg;
77 break;
78 case 'c': /* Config file */
79 lxdream_set_config_filename(optarg);
80 break;
81 case 'd': /* Mount disc */
82 disc_file = optarg;
83 break;
84 case 'D': /* Launch w/ debugger */
85 show_debugger = TRUE;
86 break;
87 case 'm': /* Set SH4 CPU clock multiplier (default 0.5) */
88 t = strtod(optarg, NULL);
89 sh4_cpu_multiplier = (int)(1000.0/t);
90 break;
91 case 's': /* AICA-only w/ S3M player */
92 aica_program = S3M_PLAYER;
93 s3m_file = optarg;
94 break;
95 case 'A': /* Audio driver */
96 audio_driver_name = optarg;
97 break;
98 case 'V': /* Video driver */
99 display_driver_name = optarg;
100 break;
101 case 'p': /* Start immediately */
102 start_immediately = TRUE;
103 break;
104 case 'u': /* Allow unsafe dcload syscalls */
105 dcload_set_allow_unsafe(TRUE);
106 break;
107 case 'b': /* No BIOS */
108 without_bios = TRUE;
109 break;
110 case 'h': /* Headless */
111 headless = TRUE;
112 break;
113 case 't': /* Time limit */
114 t = strtod(optarg, NULL);
115 time_secs = (uint32_t)t;
116 time_nanos = (int)((t - time_secs) * 1000000000);
117 break;
118 case 'x': /* Disable translator */
119 use_xlat = FALSE;
120 break;
121 }
122 }
124 lxdream_load_config( );
126 if( aica_program == NULL ) {
127 dreamcast_init();
128 } else {
129 dreamcast_configure_aica_only();
130 mem_load_block( aica_program, 0x00800000, 2048*1024 );
131 if( s3m_file != NULL ) {
132 mem_load_block( s3m_file, 0x00810000, 2048*1024 - 0x10000 );
133 }
134 }
136 if( without_bios ) {
137 bios_install();
138 dcload_install();
139 }
141 for( i=0; audio_driver_list[i] != NULL; i++ ) {
142 if( strcasecmp( audio_driver_list[i]->name, audio_driver_name ) == 0 ) {
143 if( audio_set_driver( audio_driver_list[i], 44100, AUDIO_FMT_16ST ) == FALSE ) {
144 audio_set_driver( &audio_null_driver, 44100, AUDIO_FMT_16ST );
145 }
146 break;
147 }
149 }
150 if( audio_driver_list[i] == NULL ) {
151 ERROR( "Audio driver '%s' not found, using null driver", audio_driver_name );
152 audio_set_driver( &audio_null_driver, 44100, AUDIO_FMT_16ST );
153 }
155 if( headless ) {
156 display_set_driver( &display_null_driver );
157 } else {
158 gui_init(show_debugger);
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] );
164 break;
165 }
166 }
167 if( !initialized ) {
168 if( display_driver_list[i] == NULL ) {
169 ERROR( "Video driver '%s' not found, using null driver", display_driver_name );
170 } else {
171 ERROR( "Video driver '%s' failed to initialize, falling back to null driver", display_driver_name );
172 }
173 display_set_driver( &display_null_driver );
174 }
175 }
177 maple_reattach_all();
178 INFO( "%s! ready...", APP_NAME );
180 for( ; optind < argc; optind++ ) {
181 gboolean ok = gdrom_mount_image(argv[optind]);
182 if( !ok ) {
183 ok = file_load_magic( argv[optind] );
184 }
185 if( !ok ) {
186 ERROR( "Unrecognized file '%s'", argv[optind] );
187 }
188 start_immediately = ok;
189 }
191 if( disc_file != NULL ) {
192 gdrom_mount_image( disc_file );
193 }
195 if( gdrom_get_current_disc() == NULL ) {
196 disc_file = lxdream_get_config_value( CONFIG_GDROM );
197 if( disc_file != NULL ) {
198 gdrom_mount_image( disc_file );
199 }
200 } else {
201 lxdream_set_global_config_value( CONFIG_GDROM, gdrom_get_current_disc()->name );
202 }
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);
209 return 0;
210 } else {
211 dreamcast_run();
212 }
213 }
214 if( !headless ) {
215 gui_main_loop();
216 }
217 return 0;
218 }
.