Search
lxdream.org :: lxdream/src/main.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/main.c
changeset 106:9048bac046c3
prev105:1faa0745f200
next111:230243c2b520
author nkeynes
date Tue Mar 14 12:45:53 2006 +0000 (15 years ago)
permissions -rw-r--r--
last change Move driver selection out to main at long last. Add video NULL driver for
headless operation
Make dcload exit() actually exit
file annotate diff log raw
nkeynes@30
     1
/**
nkeynes@106
     2
 * $Id: main.c,v 1.15 2006-03-14 12:45:50 nkeynes Exp $
nkeynes@30
     3
 *
nkeynes@30
     4
 * Main program, initializes dreamcast and gui, then passes control off to
nkeynes@30
     5
 * the gtk main loop (currently). 
nkeynes@30
     6
 *
nkeynes@30
     7
 * FIXME: Remove explicit GTK/Gnome references from this file
nkeynes@30
     8
 *
nkeynes@30
     9
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@30
    10
 *
nkeynes@30
    11
 * This program is free software; you can redistribute it and/or modify
nkeynes@30
    12
 * it under the terms of the GNU General Public License as published by
nkeynes@30
    13
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@30
    14
 * (at your option) any later version.
nkeynes@30
    15
 *
nkeynes@30
    16
 * This program is distributed in the hope that it will be useful,
nkeynes@30
    17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@30
    18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@30
    19
 * GNU General Public License for more details.
nkeynes@1
    20
 */
nkeynes@1
    21
nkeynes@1
    22
#ifdef HAVE_CONFIG_H
nkeynes@1
    23
#  include <config.h>
nkeynes@1
    24
#endif
nkeynes@68
    25
#include <unistd.h>
nkeynes@94
    26
#include <getopt.h>
nkeynes@1
    27
#include <gnome.h>
nkeynes@25
    28
#include "gui/gui.h"
nkeynes@27
    29
#include "dream.h"
nkeynes@105
    30
#include "syscall.h"
nkeynes@27
    31
#include "dreamcast.h"
nkeynes@106
    32
#include "aica/audio.h"
nkeynes@106
    33
#include "video.h"
nkeynes@11
    34
nkeynes@77
    35
#define S3M_PLAYER "s3mplay.bin"
nkeynes@77
    36
nkeynes@87
    37
char *option_list = "a:s:A:V:phb";
nkeynes@94
    38
struct option longopts[1] = { { NULL, 0, 0, 0 } };
nkeynes@68
    39
char *aica_program = NULL;
nkeynes@77
    40
char *s3m_file = NULL;
nkeynes@106
    41
char *video_driver_name = "gtk";
nkeynes@106
    42
char *audio_driver_name = "esd";
nkeynes@68
    43
gboolean start_immediately = FALSE;
nkeynes@77
    44
gboolean headless = FALSE;
nkeynes@87
    45
gboolean without_bios = FALSE;
nkeynes@68
    46
nkeynes@106
    47
audio_driver_t audio_driver_list[] = { &audio_null_driver,
nkeynes@106
    48
				       &audio_esd_driver,
nkeynes@106
    49
				       NULL };
nkeynes@106
    50
nkeynes@106
    51
video_driver_t video_driver_list[] = { &video_null_driver,
nkeynes@106
    52
				       &video_gtk_driver,
nkeynes@106
    53
				       NULL };
nkeynes@106
    54
nkeynes@30
    55
int main (int argc, char *argv[])
nkeynes@1
    56
{
nkeynes@106
    57
    int opt, i;
nkeynes@1
    58
#ifdef ENABLE_NLS
nkeynes@68
    59
    bindtextdomain (PACKAGE, PACKAGE_LOCALE_DIR);
nkeynes@68
    60
    textdomain (PACKAGE);
nkeynes@1
    61
#endif
nkeynes@68
    62
  
nkeynes@94
    63
    while( (opt = getopt_long( argc, argv, option_list, longopts, NULL )) != -1 ) {
nkeynes@68
    64
	switch( opt ) {
nkeynes@68
    65
	case 'a': /* AICA only mode - argument is an AICA program */
nkeynes@68
    66
	    aica_program = optarg;
nkeynes@68
    67
	    break;
nkeynes@77
    68
	case 's': /* AICA-only w/ S3M player */
nkeynes@77
    69
	    aica_program = S3M_PLAYER;
nkeynes@77
    70
	    s3m_file = optarg;
nkeynes@77
    71
	    break;
nkeynes@68
    72
	case 'A': /* Audio driver */
nkeynes@106
    73
	    audio_driver_name = optarg;
nkeynes@68
    74
	    break;
nkeynes@68
    75
	case 'V': /* Video driver */
nkeynes@106
    76
	    video_driver_name = optarg;
nkeynes@68
    77
	    break;
nkeynes@68
    78
	case 'p': /* Start immediately */
nkeynes@68
    79
	    start_immediately = TRUE;
nkeynes@77
    80
    	    break;
nkeynes@87
    81
    	case 'b': /* No BIOS */
nkeynes@87
    82
    	    without_bios = TRUE;
nkeynes@87
    83
    	    break;
nkeynes@77
    84
        case 'h': /* Headless */
nkeynes@77
    85
            headless = TRUE;
nkeynes@77
    86
            break;
nkeynes@68
    87
	}
nkeynes@68
    88
    }
nkeynes@30
    89
nkeynes@68
    90
    if( aica_program == NULL ) {
nkeynes@77
    91
	if( !headless ) {
nkeynes@77
    92
	    gnome_init ("dreamon", VERSION, argc, argv);
nkeynes@94
    93
	    dreamcast_init();
nkeynes@77
    94
	    dreamcast_register_module( &gtk_gui_module );
nkeynes@94
    95
	} else {
nkeynes@94
    96
	    dreamcast_init();
nkeynes@77
    97
	}
nkeynes@105
    98
nkeynes@68
    99
    } else {
nkeynes@68
   100
	dreamcast_configure_aica_only();
nkeynes@68
   101
	mem_load_block( aica_program, 0x00800000, 2048*1024 );
nkeynes@77
   102
	if( s3m_file != NULL ) {
nkeynes@77
   103
	    mem_load_block( s3m_file, 0x00810000, 2048*1024 - 0x10000 );
nkeynes@77
   104
	}
nkeynes@77
   105
	if( !headless ) {
nkeynes@77
   106
	    gnome_init ("dreamon", VERSION, argc, argv);
nkeynes@77
   107
	    dreamcast_register_module( &gtk_gui_module );
nkeynes@77
   108
	    set_disassembly_cpu( main_debug, "ARM7" );
nkeynes@77
   109
	}
nkeynes@68
   110
    }
nkeynes@1
   111
nkeynes@87
   112
    if( without_bios ) {
nkeynes@87
   113
    	bios_install();
nkeynes@105
   114
	dcload_install();
nkeynes@87
   115
    }
nkeynes@106
   116
nkeynes@106
   117
    for( i=0; audio_driver_list[i] != NULL; i++ ) {
nkeynes@106
   118
	if( strcasecmp( audio_driver_list[i]->name, audio_driver_name ) == 0 ) {
nkeynes@106
   119
	    audio_set_driver( audio_driver_list[i], 44100, AUDIO_FMT_16ST );
nkeynes@106
   120
	    break;
nkeynes@106
   121
	}
nkeynes@106
   122
nkeynes@106
   123
    }
nkeynes@106
   124
    if( audio_driver_list[i] == NULL ) {
nkeynes@106
   125
	ERROR( "Audio driver '%s' not found, using null driver", audio_driver_name );
nkeynes@106
   126
	audio_set_driver( &audio_null_driver, 44100, AUDIO_FMT_16ST );
nkeynes@106
   127
    }
nkeynes@106
   128
nkeynes@106
   129
    if( headless ) {
nkeynes@106
   130
	video_set_driver( &video_null_driver );
nkeynes@106
   131
    } else {
nkeynes@106
   132
	for( i=0; video_driver_list[i] != NULL; i++ ) {
nkeynes@106
   133
	    if( strcasecmp( video_driver_list[i]->name, video_driver_name ) == 0 ) {
nkeynes@106
   134
		video_set_driver( video_driver_list[i] );
nkeynes@106
   135
		break;
nkeynes@106
   136
	    }
nkeynes@106
   137
	}
nkeynes@106
   138
	if( video_driver_list[i] == NULL ) {
nkeynes@106
   139
	    ERROR( "Video driver '%s' not found, using null driver", video_driver_name );
nkeynes@106
   140
	    video_set_driver( &video_null_driver );
nkeynes@106
   141
	}
nkeynes@106
   142
    }
nkeynes@106
   143
nkeynes@68
   144
    INFO( "DreamOn! ready..." );
nkeynes@94
   145
    if( optind < argc ) {
nkeynes@94
   146
	file_load_magic( argv[optind] );
nkeynes@94
   147
    }
nkeynes@94
   148
nkeynes@68
   149
    if( start_immediately )
nkeynes@68
   150
	dreamcast_run();
nkeynes@77
   151
    if( !headless ) {
nkeynes@77
   152
        gtk_main ();
nkeynes@77
   153
    }
nkeynes@68
   154
    return 0;
nkeynes@1
   155
}
nkeynes@1
   156
.