filename | src/main.c |
changeset | 537:d924be49e192 |
prev | 531:f0fee3ba71d1 |
next | 543:361ec0a70cf2 |
author | nkeynes |
date | Tue Nov 20 10:27:58 2007 +0000 (16 years ago) |
permissions | -rw-r--r-- |
last change | Move gtk UI into gtkui subdir (prep for non-gtk builds), and protect with an automake conditional |
view | annotate | diff | log | raw |
1 /**
2 * $Id: main.c,v 1.35 2007-11-07 11:45:53 nkeynes Exp $
3 *
4 * Main program, initializes dreamcast and gui, then passes control off to
5 * the main loop.
6 *
7 * Copyright (c) 2005 Nathan Keynes.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 */
20 #include <unistd.h>
21 #include <getopt.h>
22 #include "dream.h"
23 #include "config.h"
24 #include "syscall.h"
25 #include "mem.h"
26 #include "dreamcast.h"
27 #include "display.h"
28 #include "loader.h"
29 #include "gui.h"
30 #include "aica/audio.h"
31 #include "gdrom/gdrom.h"
32 #include "maple/maple.h"
33 #include "sh4/sh4core.h"
35 #define S3M_PLAYER "s3mplay.bin"
37 char *option_list = "a:m:s:A:V:puhbd:c:t:xD";
38 struct option longopts[1] = { { NULL, 0, 0, 0 } };
39 char *aica_program = NULL;
40 char *s3m_file = NULL;
41 const char *disc_file = NULL;
42 char *display_driver_name = NULL;
43 char *audio_driver_name = NULL;
44 gboolean start_immediately = FALSE;
45 gboolean headless = FALSE;
46 gboolean without_bios = FALSE;
47 gboolean use_xlat = TRUE;
48 gboolean show_debugger = FALSE;
49 uint32_t time_secs = 0;
50 uint32_t time_nanos = 0;
51 extern uint32_t sh4_cpu_multiplier;
53 int main (int argc, char *argv[])
54 {
55 int opt, i;
56 double t;
57 gboolean display_ok;
59 install_crash_handler();
60 #ifdef ENABLE_NLS
61 bindtextdomain (PACKAGE, PACKAGE_LOCALE_DIR);
62 textdomain (PACKAGE);
63 #endif
64 display_ok = gui_parse_cmdline(&argc, &argv);
66 while( (opt = getopt_long( argc, argv, option_list, longopts, NULL )) != -1 ) {
67 switch( opt ) {
68 case 'a': /* AICA only mode - argument is an AICA program */
69 aica_program = optarg;
70 break;
71 case 'c': /* Config file */
72 lxdream_set_config_filename(optarg);
73 break;
74 case 'd': /* Mount disc */
75 disc_file = optarg;
76 break;
77 case 'D': /* Launch w/ debugger */
78 show_debugger = TRUE;
79 break;
80 case 'm': /* Set SH4 CPU clock multiplier (default 0.5) */
81 t = strtod(optarg, NULL);
82 sh4_cpu_multiplier = (int)(1000.0/t);
83 break;
84 case 's': /* AICA-only w/ S3M player */
85 aica_program = S3M_PLAYER;
86 s3m_file = optarg;
87 break;
88 case 'A': /* Audio driver */
89 audio_driver_name = optarg;
90 break;
91 case 'V': /* Video driver */
92 display_driver_name = optarg;
93 break;
94 case 'p': /* Start immediately */
95 start_immediately = TRUE;
96 break;
97 case 'u': /* Allow unsafe dcload syscalls */
98 dcload_set_allow_unsafe(TRUE);
99 break;
100 case 'b': /* No BIOS */
101 without_bios = TRUE;
102 break;
103 case 'h': /* Headless */
104 headless = TRUE;
105 break;
106 case 't': /* Time limit */
107 t = strtod(optarg, NULL);
108 time_secs = (uint32_t)t;
109 time_nanos = (int)((t - time_secs) * 1000000000);
110 break;
111 case 'x': /* Disable translator */
112 use_xlat = FALSE;
113 break;
114 }
115 }
117 lxdream_load_config( );
119 if( aica_program == NULL ) {
120 dreamcast_init();
121 } else {
122 dreamcast_configure_aica_only();
123 mem_load_block( aica_program, 0x00800000, 2048*1024 );
124 if( s3m_file != NULL ) {
125 mem_load_block( s3m_file, 0x00810000, 2048*1024 - 0x10000 );
126 }
127 }
129 if( without_bios ) {
130 bios_install();
131 dcload_install();
132 }
134 audio_driver_t audio_driver = get_audio_driver_by_name(audio_driver_name);
135 if( audio_driver == NULL ) {
136 ERROR( "Audio driver '%s' not found, aborting.", audio_driver_name );
137 exit(2);
138 } else if( audio_set_driver( audio_driver, 44100, AUDIO_FMT_16ST ) == FALSE ) {
139 ERROR( "Failed to initialize audio driver '%s', using null driver",
140 audio_driver->name );
141 audio_set_driver( &audio_null_driver, 44100, AUDIO_FMT_16ST );
142 }
144 if( headless ) {
145 display_set_driver( &display_null_driver );
146 } else {
147 gui_init(show_debugger);
149 display_driver_t display_driver = get_display_driver_by_name(display_driver_name);
150 if( display_driver == NULL ) {
151 ERROR( "Video driver '%s' not found, aborting.", display_driver_name );
152 exit(2);
153 } else if( display_set_driver( display_driver ) == FALSE ) {
154 ERROR( "Video driver '%s' failed to initialize (could not connect to display?)",
155 display_driver->name );
156 exit(2);
157 }
158 }
160 maple_reattach_all();
161 INFO( "%s! ready...", APP_NAME );
163 for( ; optind < argc; optind++ ) {
164 gboolean ok = gdrom_menu_open_file(argv[optind]);
165 if( !ok ) {
166 ok = file_load_magic( argv[optind] );
167 }
168 if( !ok ) {
169 ERROR( "Unrecognized file '%s'", argv[optind] );
170 }
171 start_immediately = ok;
172 }
174 if( disc_file != NULL ) {
175 gdrom_menu_open_file( disc_file );
176 }
178 if( gdrom_get_current_disc() == NULL ) {
179 disc_file = lxdream_get_config_value( CONFIG_GDROM );
180 if( disc_file != NULL ) {
181 gdrom_menu_open_file( disc_file );
182 }
183 }
185 sh4_set_use_xlat( use_xlat );
187 if( start_immediately ) {
188 if( time_nanos != 0 || time_secs != 0 ) {
189 dreamcast_run_for(time_secs, time_nanos);
190 return 0;
191 } else {
192 dreamcast_run();
193 }
194 }
195 if( !headless ) {
196 gui_main_loop();
197 }
198 return 0;
199 }
.