Esempio n. 1
0
void run(unsigned channel, const char* file)
{
	adv_fz* f;
	const char* ext;

	ext = strrchr(file, '.');
	if (!ext) {
		target_err("Missing file extension\n");
		done = 1;
		return;
	}

	f = fzopen(file, "rb");
	if (!f) {
		target_err("Error opening the file %s\n", file);
		done = 1;
		return;
	}

	if (strcmp(ext, ".wav")==0) {
		mixer_play_file_wav(channel, f, 0);
	} else if (strcmp(ext, ".mp3")==0) {
		mixer_play_file_mp3(channel, f, 0);
	} else {
		target_err("Unknown file extension %s\n", ext);
		fzclose(f);
		done = 1;
		return;
	}
}
Esempio n. 2
0
static void error_callback(void* context, enum conf_callback_error error, const char* file, const char* tag, const char* valid, const char* desc, ...)
{
	va_list arg;
	va_start(arg, desc);
	target_err_va(desc, arg);
	target_err("\n");
	if (valid)
		target_err("%s\n", valid);
	va_end(arg);
}
Esempio n. 3
0
static int ui_color_load(struct advance_ui_context* context, adv_conf* cfg_context, int f, int b, const char* tag)
{
	const char* fs;
	const char* bs;
	const char* s;
	int p;
	char c;
	char* d;

	s = conf_string_get_default(cfg_context, tag);

	d = strdup(s);

	p = 0;

	fs = stoken(&c, &p, d, " ", "");
	if (c != ' ') {
		target_err("Error in option %s\n", tag);
		return -1;
	}
	sskip(&p, d, " ");
	bs = stoken(&c, &p, d, " ", "");
	if (c != 0) {
		target_err("Error in option %s\n", tag);
		return -1;
	}

	if (f >= 0) {
		if (ui_color_hex(&context->config.ui_color[f], fs) != 0) {
			target_err("Error in option %s\n", tag);
			return -1;
		}
	}

	if (b >= 0) {
		if (ui_color_hex(&context->config.ui_color[b], bs) != 0) {
			target_err("Error in option %s\n", tag);
			return -1;
		}
	}

	free(d);

	return 0;
}
Esempio n. 4
0
void troubleshotting(void)
{
	target_err("\n\r");
	target_err("Ensure to use the 'device_video_output auto' option.\n\r");
#ifdef USE_VIDEO_SVGAWIN
	target_err("Ensure to have installed the svgawin.sys driver with the svgawin.exe utility.\n\r");
#endif
#if defined(USE_VIDEO_FB) || defined(USE_VIDEO_SVGALIB)
	{
		char* term;
		if (getenv("DISPLAY") != 0) {
			target_err("Try to run this program in console mode and not in X.\n\r");
		} else {
#if defined(USE_VIDEO_FB)
			target_err("Ensure to have a Frame Buffer driver (other than VESA) in your Linux kernel.\n\r");
#endif
#if defined(USE_VIDEO_SVGALIB)
			target_err("Ensure to have a correctly installed and recent SVGALIB library.\n\r");
#endif
		}
		term = getenv("TERM");
		if (!term || strcmp(term, "linux")!=0)
			target_err("Try to run this program in a TERM=linux terminal.\n\r");
	}
#endif
}
Esempio n. 5
0
void device_error(const char* option, const char* arg, const adv_driver** driver_map, unsigned driver_mac)
{
	unsigned i, j;

	log_std(("adv_device: device_error %s %s\n", option, arg));

	target_err("Invalid argument '%s' for option '%s'\n", arg, option);
	target_err("Valid values are:\n");
	target_err("%16s %s\n", "auto", "Automatic detection");

	for(i=0;i<driver_mac;++i) {
		for(j=0;driver_map[i]->device_map[j].name;++j) {
			char buffer[DEVICE_NAME_MAX];
			if (strcmp(driver_map[i]->device_map[j].name, "auto")==0) {
				snprintf(buffer, sizeof(buffer), "%s", driver_map[i]->name);
			} else {
				snprintf(buffer, sizeof(buffer), "%s/%s", driver_map[i]->name, driver_map[i]->device_map[j].name);
			}
			target_err("%16s %s\n", buffer, driver_map[i]->device_map[j].desc);
		}
	}
}
Esempio n. 6
0
adv_error advance_ui_inner_init(struct advance_ui_context* context, adv_conf* cfg_context)
{
	adv_conf_iterator k;
	adv_color_def def;

	context->state.ui_font = 0;
	context->state.ui_font_oriented = 0;

	if (strcmp(context->config.ui_font_buffer, "auto") != 0) {
		/* try reading the font, the real font is loaded later */
		adv_font* font;
		adv_fz* f;

		const char* file = file_config_file_home(context->config.ui_font_buffer);

		log_std(("emu:ui: font '%s'\n", file));

		f = fzopen(file, "rb");
		if (!f) {
			target_err("Error opening the font %s\n", file);
			return -1;
		}

		font = adv_font_load(f, 16, 16);
		if (!font) {
			target_err("Error reading the font %s\n%s\n", file, error_get());
			return -1;
		}

		adv_font_free(font);

		fzclose(f);
	}

	def = color_def_make_rgb_from_sizelenpos(3, 8, 0, 8, 8, 8, 16);

	if (strcmp(context->config.help_image_buffer, "auto") == 0) {
		adv_fz* f;
		unsigned i;

		log_std(("emu:ui: helpimage auto\n"));

		f = fzopenmemory(HELPIMAGE, HELPIMAGE_SIZE);

		context->state.help_image = adv_bitmap_load_png_rgb(f, def);
		if (!context->state.help_image) {
			target_err("Error reading the internal help image\n");
			return -1;
		}

		fzclose(f);

		log_std(("emu:ui: helptag auto\n"));
		i = 0;
		while (HELPTAG[i]) {
			char* d = strdup(HELPTAG[i]);

			log_std(("emu:ui: helptag '%s'\n", d));

			if (advance_ui_parse_help(context, d) != 0) {
				free(d);
				target_err("Invalid 'ui_helptag' option.\n%s\n", error_get());
				return -1;
			}

			free(d);

			++i;
		}
	} else {
		if (strcmp(context->config.help_image_buffer, "none") != 0) {
			adv_fz* f;
			const char* file = file_config_file_home(context->config.help_image_buffer);

			log_std(("emu:ui: helpimage '%s'\n", file));

			f = fzopen(file, "rb");
			if (!f) {
				target_err("Error opening the help image %s\n", file);
				return -1;
			}

			context->state.help_image = adv_bitmap_load_png_rgb(f, def);
			if (!context->state.help_image) {
				target_err("Error reading the help image %s\n%s\n", file, error_get());
				return -1;
			}

			fzclose(f);
		} else {
			context->state.help_image = 0;
		}

		log_std(("emu:ui: helptag start\n"));
		for (conf_iterator_begin(&k, cfg_context, "ui_helptag"); !conf_iterator_is_end(&k); conf_iterator_next(&k)) {
			char* d = strdup(conf_iterator_string_get(&k));

			log_std(("emu:ui: helptag '%s'\n", d));

			if (advance_ui_parse_help(context, d) != 0) {
				free(d);
				target_err("Invalid 'ui_helptag' option.\n%s\n", error_get());
				return -1;
			}

			free(d);
		}
	}

	return 0;
}
Esempio n. 7
0
int os_inner_init(const char* title)
{
	const char* display;
	struct utsname uts;
	struct sigaction term_action;
	struct sigaction quit_action;
	struct sigaction hup_action;
	struct sigaction pipe_action;
#ifdef USE_SDL
	SDL_version compiled;
#endif
	unsigned char endian[4] = { 0x1, 0x2, 0x3, 0x4 };
	uint32 endian_little = 0x04030201;
	uint32 endian_big = 0x01020304;

	log_std(("os: os_inner_init\n"));

	if (uname(&uts) != 0) {
		log_std(("ERROR:os: uname failed\n"));
	} else {
		log_std(("os: sys %s\n", uts.sysname));
		log_std(("os: release %s\n", uts.release));
		log_std(("os: version %s\n", uts.version));
		log_std(("os: machine %s\n", uts.machine));
	}

#if HAVE_SYSCONF
#ifdef _SC_CLK_TCK
	log_std(("os: sysconf(_SC_CLK_TCK) %ld\n", sysconf(_SC_CLK_TCK)));
#endif
#ifdef _SC_NPROCESSORS_CONF
	log_std(("os: sysconf(_SC_NPROCESSORS_CONF) %ld\n", sysconf(_SC_NPROCESSORS_CONF)));
#endif
#ifdef _SC_NPROCESSORS_ONLN
	log_std(("os: sysconf(_SC_NPROCESSORS_ONLN) %ld\n", sysconf(_SC_NPROCESSORS_ONLN)));
#endif
#ifdef _SC_PHYS_PAGES
	log_std(("os: sysconf(_SC_PHYS_PAGES) %ld\n", sysconf(_SC_PHYS_PAGES)));
#endif
#ifdef _SC_AVPHYS_PAGES
	log_std(("os: sysconf(_SC_AVPHYS_PAGES) %ld\n", sysconf(_SC_AVPHYS_PAGES)));
#endif
#ifdef _SC_CHAR_BIT
	log_std(("os: sysconf(_SC_CHAR_BIT) %ld\n", sysconf(_SC_CHAR_BIT)));
#endif
#ifdef _SC_LONG_BIT
	log_std(("os: sysconf(_SC_LONG_BIT) %ld\n", sysconf(_SC_LONG_BIT)));
#endif
#ifdef _SC_WORD_BIT
	log_std(("os: sysconf(_SC_WORD_BIT) %ld\n", sysconf(_SC_WORD_BIT)));
#endif
#endif

#ifdef _POSIX_PRIORITY_SCHEDULING /* OSDEF Check for POSIX scheduling */
	log_std(("os: scheduling available\n"));
#else
	log_std(("os: scheduling NOT available\n"));
#endif

	/* print the compiler version */
#if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) /* OSDEF Detect compiler version */
#define COMPILER_RESOLVE(a) #a
#define COMPILER(a, b, c) COMPILER_RESOLVE(a) "." COMPILER_RESOLVE(b) "." COMPILER_RESOLVE(c)
	log_std(("os: compiler GNU %s\n", COMPILER(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__)));
#else
	log_std(("os: compiler unknown\n"));
#endif

	/* check for int size */
	if (sizeof(uint8) != 1) {
		target_err("The program is compiled with invalid uint8 type.\n");
		return -1;
	}
	if (sizeof(uint16) != 2) {
		target_err("The program is compiled with invalid uint16 type.\n");
		return -1;
	}
	if (sizeof(uint32) != 4) {
		target_err("The program is compiled with invalid uint32 type.\n");
		return -1;
	}
	if (sizeof(uint64) != 8) {
		target_err("The program is compiled with invalid uint64 type.\n");
		return -1;
	}

	/* check for the endianess */
#ifdef USE_MSB
	log_std(("os: compiled big endian system\n"));
	if (memcmp(endian, &endian_big, 4) != 0) {
		target_err("The program is compiled as bigendian but system doesn't appear to be bigendian.\n");
		return -1;
	}
#endif
#ifdef USE_LSB
	log_std(("os: compiled little endian system\n"));
	if (memcmp(endian, &endian_little, 4) != 0) {
		target_err("The program is compiled as littleendian but system doesn't appear to be littleendian.\n");
		return -1;
	}
#endif

#ifdef USE_SMP
	/* check the thread support */
	if (os_thread() != 0) {
		target_err("Error on the threading support.\n");
		return -1;
	}
#endif

	/* get DISPLAY environment variable */
	display = getenv("DISPLAY");
	if (display)
		log_std(("os: DISPLAY=%s\n", display));
	else
		log_std(("os: DISPLAY undef\n"));

	/* probe the delay system */
	os_delay();

	if (!os_internal_wm_active()) {
		log_std(("os: save term\n"));
		if (tcgetattr(fileno(stdin), &OS.term) != 0) {
			log_std(("ERROR:os: error getting the tty state.\n"));
			OS.term_active = 0;
		} else {
			OS.term_active = 1;
		}
	}

#if defined(USE_X)
	OS.x_active = 0;
	{
		int event_base, error_base;
		int major_version, minor_version;

		log_std(("os: XOpenDisplay()\n"));
		OS.dga_display = XOpenDisplay(0);
		if (OS.dga_display) {
			OS.x_active = 1;
		} else {
			log_std(("WARNING:os: XOpenDisplay() failed. All the X drivers will be disabled.\n"));
		}
	}
#endif
#if defined(USE_SVGALIB)
	OS.svgalib_active = 0;
	if (!os_internal_wm_active()) {
		int h;
		log_std(("os: open /dev/svga\n"));

		/* try opening the device, otherwise vga_init() will abort the program. */
		h = open("/dev/svga", O_RDWR);
		if (h >= 0) {
			int res;
			close(h);

			vga_disabledriverreport();

			/* check the version of the SVGALIB */
			res = vga_setmode(-1);
			if (res < 0 || res < 0x1911) { /* 1.9.11 */
				log_std(("WARNING:os: invalid SVGALIB version %x. All the SVGALIB drivers will be disabled.\n", (int)res));
				/* don't print the message. It may be a normal condition. */
				/* target_nfo("Invalid SVGALIB version, you need SVGALIB version 1.9.x or 2.0.x.\nPlease upgrade or recompile without SVGALIB support.\n"); */
			} else {
				log_std(("os: vga_init()\n"));
				if (vga_init() != 0) {
					log_std(("os: vga_init() failed\n"));
					target_err("Error initializing the SVGALIB video support.\n");
					return -1;
				}
				OS.svgalib_active = 1;
			}
		} else {
			log_std(("WARNING:os: open /dev/svga failed. All the SVGALIB drivers will be disabled.\n"));
			/* don't print the message. It may be a normal condition. */
			/* target_nfo("Error opening the SVGALIB device /dev/svga.\n"); */
		}
	} else {
		log_std(("WARNING:os: vga_init() skipped because X is active. All the SVGALIB drivers will be disabled.\n"));
		/* don't print the message. It may be a normal condition. */
		/* target_nfo("SVGALIB not initialized because it's unusable in X.\n"); */
	}
#endif
#if defined(USE_SDL)
	log_std(("os: SDL_Init(SDL_INIT_NOPARACHUTE)\n"));
	if (SDL_Init(SDL_INIT_NOPARACHUTE) != 0) {
		log_std(("os: SDL_Init() failed, %s\n", SDL_GetError()));
		target_err("Error initializing the SDL video support.\n");
		return -1;
	} 
	OS.sdl_active = 1;
	SDL_VERSION(&compiled);

	log_std(("os: compiled with sdl %d.%d.%d\n", compiled.major, compiled.minor, compiled.patch));
	log_std(("os: linked with sdl %d.%d.%d\n", SDL_Linked_Version()->major, SDL_Linked_Version()->minor, SDL_Linked_Version()->patch));
#ifdef USE_MSB
	if (SDL_BYTEORDER != SDL_BIG_ENDIAN) {
		target_err("Invalid SDL endianess.\n");
		return -1;
	}
#endif
#ifdef USE_LSB
	if (SDL_BYTEORDER != SDL_LIL_ENDIAN) {
		target_err("Invalid SDL endianess.\n");
		return -1;
	}
#endif
#endif
#if defined(USE_SLANG)
	OS.slang_active = 0;
	if (!os_internal_wm_active()) {
		log_std(("os: SLtt_get_terminfo()\n"));
		SLtt_get_terminfo();
		log_std(("os: SLsmg_init_smg()\n"));
		SLsmg_init_smg();
		OS.slang_active = 1;
	} else {
		log_std(("WARNING:os: SLang_init_tty() skipped because X is active. All the SLang drivers will be disabled.\n"));
	}
#endif
#if defined(USE_CURSES)
	OS.curses_active = 0;
	if (!os_internal_wm_active()) {
		log_std(("os: initscr()\n"));
		initscr();
		start_color();
		cbreak();
		noecho();
		nonl();
		OS.curses_active = 1;
	} else {
		log_std(("WARNING:os: curses initscr() skipped because X is active. All the curses drivers will be disabled.\n"));
	}
#endif

	/* set the titlebar */
	sncpy(OS.title_buffer, sizeof(OS.title_buffer), title);

	/* set some signal handlers */

	/* STANDARD signals */
	term_action.sa_handler = (void (*)(int))os_signal;
	/* block external generated signals in the signal handler */
	sigemptyset(&term_action.sa_mask);
	sigaddset(&term_action.sa_mask, SIGALRM);
	sigaddset(&term_action.sa_mask, SIGINT);
	sigaddset(&term_action.sa_mask, SIGTERM);
	sigaddset(&term_action.sa_mask, SIGHUP);
	sigaddset(&term_action.sa_mask, SIGQUIT);
	term_action.sa_flags = SA_RESTART | SA_SIGINFO;
	/* external generated */
	sigaction(SIGALRM, &term_action, 0);
	sigaction(SIGINT, &term_action, 0);
	sigaction(SIGTERM, &term_action, 0);
	/* internal generated */
	sigaction(SIGABRT, &term_action, 0);
	sigaction(SIGFPE, &term_action, 0);
	sigaction(SIGILL, &term_action, 0);
	sigaction(SIGSEGV, &term_action, 0);
	sigaction(SIGBUS, &term_action, 0);

	/* HUP signal */
	hup_action.sa_handler = os_hup_signal;
	sigemptyset(&hup_action.sa_mask);
	hup_action.sa_flags = SA_RESTART;
	sigaction(SIGHUP, &hup_action, 0);

	/* QUIT signal */
	quit_action.sa_handler = os_quit_signal;
	sigemptyset(&quit_action.sa_mask);
	quit_action.sa_flags = SA_RESTART;
	sigaction(SIGQUIT, &quit_action, 0);

	/* PIPE signal, ignoring it force some functions to */
	/* return with error. It happen for example on the LCD sockets. */
	pipe_action.sa_handler = SIG_IGN;
	sigemptyset(&pipe_action.sa_mask);
	pipe_action.sa_flags = SA_RESTART;
	sigaction(SIGPIPE, &pipe_action, 0);

	return 0;
}
Esempio n. 8
0
int os_main(int argc, char* argv[])
{
	int keyboard_id;
	adv_conf* context;
	const char* s;
        char* section_map[1];
	const char** file_map;
	unsigned file_mac;
	int i;
	double latency_time;
	double buffer_time;
	double volume;
	unsigned rate;
	int attenuation;
	adv_bool opt_log;
	adv_bool opt_logsync;

	opt_log = 0;
	opt_logsync = 0;
	file_map = 0;
	file_mac = 0;

	context = conf_init();

	if (os_init(context) != 0)
		goto err_conf;

	mixer_reg(context);

	conf_int_register_limit_default(context, "sound_volume", -32, 0, 0);
	conf_int_register_limit_default(context, "sound_samplerate", 5000, 96000, 44100);
	conf_float_register_limit_default(context, "sound_latency", 0.01, 2.0, 0.1);
	conf_float_register_limit_default(context, "sound_buffer", 0.05, 2.0, 0.1);

	if (conf_input_args_load(context, 0, "", &argc, argv, error_callback, 0) != 0)
		goto err_os;

	file_map = malloc(argc * sizeof(const char*));

	for(i=1;i<argc;++i) {
		if (target_option_compare(argv[i], "log")) {
			opt_log = 1;
		} else if (target_option_compare(argv[i], "logsync")) {
			opt_logsync = 1;
		} else if (target_option_extract(argv[i]) == 0) {
			file_map[file_mac++] = argv[i];
		} else {
			target_err("Unknown command line option '%s'.\n", argv[i]);
			goto err_os;
		}
	}

	if (argc <= 1 || file_mac == 0) {
		target_err("Syntax: advs FILES...\n");
		goto err_os;
	}

	if (opt_log || opt_logsync) {
		const char* log = "advs.log";
		remove(log);
		log_init(log, opt_logsync);
        }

	section_map[0] = "";
	conf_section_set(context, section_map, 1);

	if (mixer_load(context) != 0) {
		goto err_os;
	}

	attenuation = conf_int_get_default(context, "sound_volume");
	latency_time = conf_float_get_default(context, "sound_latency");
	buffer_time = conf_float_get_default(context, "sound_buffer");
	rate = conf_int_get_default(context, "sound_samplerate");
	volume = 1.0;
	while (attenuation++ < 0)
		volume /= 1.122018454; /* = (10 ^ (1/20)) = 1dB */

	if (os_inner_init("AdvanceSOUND") != 0)
		goto err_os;

	if (file_mac > MIXER_CHANNEL_MAX) {
		target_err("Too many files\n");
		goto err_os_inner;
	}

	if (mixer_init(rate, file_mac, 1, buffer_time + latency_time, latency_time) != 0) {
		target_err("%s\n", error_get());
		goto err_os_inner;
	}

	mixer_volume(volume);

	for(i=0;i<file_mac;++i)
		run(i, file_map[i]);

	free(file_map);

	signal(SIGINT, sigint);

	while (!done) {
		for(i=0;i<file_mac;++i)
			if (mixer_is_playing(i))
				break;
		if (i==file_mac)
			break;

		mixer_poll();
		target_idle();
	}

	log_std(("s: shutdown\n"));

	mixer_done();

	os_inner_done();

	log_std(("s: the end\n"));

	if (opt_log || opt_logsync) {
		log_done();
	}

	os_done();
	conf_done(context);

	return EXIT_SUCCESS;

err_os_inner:
	os_inner_done();
	log_done();
err_os:
	os_done();
err_conf:
	conf_done(context);
err:
	return EXIT_FAILURE;

}
Esempio n. 9
0
int os_main(int argc, char* argv[])
{
	adv_crtc_container selected;
	adv_crtc_container_iterator i;
	const char* opt_rc;
	adv_bool opt_log;
	adv_bool opt_logsync;
	int j;
	adv_error res;
	char* section_map[1];
	char buffer[1024];

	opt_rc = 0;
	opt_log = 0;
	opt_logsync = 0;
	the_advance = advance_mame;
	the_sound_flag = 1;

	the_config = conf_init();

	if (os_init(the_config)!=0) {
		target_err("Error initializing the OS support.\n");
		goto err_conf;
	}

	video_reg(the_config, 1);
	monitor_register(the_config);
	crtc_container_register(the_config);
	generate_interpolate_register(the_config);
	gtf_register(the_config);
	inputb_reg(the_config, 1);
	inputb_reg_driver_all(the_config);
	
	/* MSDOS requires a special driver sub set */
#ifndef __MSDOS__
	video_reg_driver_all(the_config);
#endif

	if (conf_input_args_load(the_config, 1, "", &argc, argv, error_callback, 0) != 0)
		goto err_os;

	for(j=1;j<argc;++j) {
		if (target_option_compare(argv[j], "rc") && j+1<argc) {
			opt_rc = argv[++j];
		} else if (target_option_compare(argv[j], "log")) {
			opt_log = 1;
		} else if (target_option_compare(argv[j], "logsync")) {
			opt_logsync = 1;
		} else if (target_option_compare(argv[j], "nosound")) {
			the_sound_flag = 0;
		} else if (target_option_compare(argv[j], "advmamev")) {
			the_advance = advance_mame;
		} else if (target_option_compare(argv[j], "advmessv")) {
			the_advance = advance_mess;
		} else if (target_option_compare(argv[j], "advpacv")) {
			the_advance = advance_pac;
		} else if (target_option_compare(argv[j], "advmenuv")) {
			the_advance = advance_menu;
#ifdef __MSDOS__
		} else if (target_option_compare(argv[j], "vgav")) {
			the_advance = advance_vga;
		} else if (target_option_compare(argv[j], "vbev")) {
			the_advance = advance_vbe;
#endif
#ifdef __WIN32__
		} else if (target_option_compare(argv[j], "videowv")) {
			the_advance = advance_videow;
#endif
		} else {
			target_err("Unknown option %s\n", argv[j]);
			goto err;
		}
	}

#ifdef __MSDOS__
	/* WARNING the MSDOS drivers are registered after the command line management. */
	/* It implyes that you cannot specify any driver options on the command line */
	msdos_rut();

	if (the_advance == advance_vga) {
		if (the_advance_vga_active) {
			target_err("The AdvanceVGA utility is active. Disable it before running vgav.\n");
			goto err;
		}
		video_reg_driver(the_config, &video_vgaline_driver);
	} else if (the_advance == advance_vbe) {
		if (the_advance_vbe_active) {
			target_err("The AdvanceVBE utility is active. Disable it before running vbev.\n");
			goto err;
		}
		video_reg_driver(the_config, &video_vbeline_driver);
		video_reg_driver(the_config, &video_vgaline_driver); /* for the text modes */
	} else {
		video_reg_driver_all(the_config);
	}
#endif

	if (!opt_rc) {
		switch (the_advance) {
			case advance_vbe : opt_rc = "vbe.rc"; break;
			case advance_vga : opt_rc = "vga.rc"; break;
			case advance_menu : opt_rc = file_config_file_home("advmenu.rc"); break;
			case advance_mame : opt_rc = file_config_file_home("advmame.rc"); break;
			case advance_mess : opt_rc = file_config_file_home("advmess.rc"); break;
			case advance_pac : opt_rc = file_config_file_home("advpac.rc"); break;
			case advance_videow : opt_rc = file_config_file_home("videow.rc"); break;
			default : opt_rc = "advv.rc"; break;
		}
	}

	if (access(opt_rc, R_OK)!=0) {
		target_err("Configuration file %s not found.\n", opt_rc);
		goto err_os;
	}

	if (conf_input_file_load_adv(the_config, 0, opt_rc, opt_rc, 1, 1, STANDARD, sizeof(STANDARD)/sizeof(STANDARD[0]), error_callback, 0) != 0)
		goto err_os;

	if (opt_log || opt_logsync) {
		const char* log = "advv.log";
		remove(log);
		log_init(log, opt_logsync);
        }

	log_std(("v: %s %s\n", __DATE__, __TIME__));

	section_map[0] = "";
	conf_section_set(the_config, section_map, 1);

	if (video_load(the_config, "") != 0) {
		target_err("Error loading the video options from the configuration file %s.\n", opt_rc);
		target_err("%s\n", error_get());
		goto err_os;
	}

	if (inputb_load(the_config) != 0) {
		target_err("%s\n", error_get());
		goto err_os;
	}

	/* NOTE: After this command all the target_err() string must */
	/* have \n\r at the end to ensure correct newline in graphics mode. */

	if (os_inner_init("AdvanceVIDEO") != 0) {
		goto err_os;
	}

	if (adv_video_init() != 0) {
		target_err("%s\n\r", error_get());
		troubleshotting();
		goto err_os_inner;
	}

	if (video_blit_init() != 0) {
		target_err("%s\n\r", error_get());
		goto err_video;
	}

	if (the_advance != advance_vbe && the_advance != advance_vga) {
		if ((video_mode_generate_driver_flags(VIDEO_DRIVER_FLAGS_MODE_GRAPH_MASK, 0) & VIDEO_DRIVER_FLAGS_PROGRAMMABLE_CLOCK) == 0) {
			target_err("No active video driver is able to program your video board.\n\r");
			troubleshotting();
			goto err_blit;
		}
	}

	if (inputb_init() != 0) {
		target_err("%s\n\r", error_get());
		goto err_blit;
	}

	if (monitor_load(the_config, &the_monitor) != 0) {
		target_err("Error loading the clock options from the configuration file %s.\n\r", opt_rc);
		target_err("%s\n\r", error_get());
		goto err_input;
	}

	monitor_print(buffer, sizeof(buffer), &the_monitor);
	log_std(("v: clock %s\n", buffer));

	/* load generate_linear config */
	res = generate_interpolate_load(the_config, &the_interpolate);
	if (res<0) {
		target_err("Error loading the format options from the configuration file %s.\n\r", opt_rc);
		target_err("%s\n\r", error_get());
		goto err_input;
	}
	if (res>0) {
		generate_default_vga(&the_interpolate.map[0].gen);
		the_interpolate.map[0].hclock = 31500;
		the_interpolate.mac = 1;
	}

	/* load generate_linear config */
	res = gtf_load(the_config, &the_gtf);
	if (res<0) {
		target_err("Error loading the gtf options from the configuration file %s.\n\r", opt_rc);
		target_err("%s\n\r", error_get());
		goto err_input;
	}
	if (res>0) {
		gtf_default_vga(&the_gtf);
	}

	/* all mode */
	crtc_container_init(&selected);

	/* insert modes */
	crtc_container_insert_default_all(&selected);

	/* sort */
	crtc_container_init(&the_modes);
	for(crtc_container_iterator_begin(&i, &selected);!crtc_container_iterator_is_end(&i);crtc_container_iterator_next(&i)) {
		adv_crtc* crtc = crtc_container_iterator_get(&i);
		crtc_container_insert_sort(&the_modes, crtc, crtc_compare);
	}
	crtc_container_done(&selected);

	/* load selected */
	crtc_container_init(&selected);

	if (crtc_container_load(the_config, &selected) != 0) {
		target_err("%s\n\r", error_get());
		goto err_input;
	}

	/* union set */
	for(crtc_container_iterator_begin(&i, &selected);!crtc_container_iterator_is_end(&i);crtc_container_iterator_next(&i)) {
		adv_crtc* crtc = crtc_container_iterator_get(&i);
		adv_bool has = crtc_container_has(&the_modes, crtc, crtc_compare) != 0;
		if (has)
			crtc_container_remove(&the_modes, crtc_select_by_compare, crtc);
		crtc->user_flags |= MODE_FLAGS_USER_BIT0;
		crtc_container_insert_sort(&the_modes, crtc, crtc_compare);
	}
	crtc_container_done(&selected);

	the_modes_modified = 0;

	if (text_init(&the_modes, &the_monitor) != 0) {
		goto err_input;
	}

	if (inputb_enable(0) != 0) {
		goto err_text;
	}

	sound_signal();

	menu_run();

	log_std(("v: shutdown\n"));

	inputb_disable();

	text_done();

	crtc_container_done(&the_modes);

	inputb_done();

	video_blit_done();

	adv_video_done();

	os_inner_done();

	log_std(("v: the end\n"));

	if (opt_log || opt_logsync) {
		log_done();
	}

	os_done();

	conf_save(the_config, 0, 0, error_callback, 0);

	conf_done(the_config);

	return EXIT_SUCCESS;

err_text:
	text_done();
err_input:
	inputb_done();
err_blit:
	video_blit_done();
err_video:
	adv_video_done();
err_os_inner:
	os_inner_done();
err_os:
	if (opt_log || opt_logsync) {
		log_done();
	}
	os_done();
err_conf:
	conf_done(the_config);
err:
	return EXIT_FAILURE;
}
Esempio n. 10
0
int os_main(int argc, char* argv[])
{
	int i;
	adv_conf* context;
	const char* section_map[1];
	adv_bool opt_log;
	adv_bool opt_logsync;

	opt_log = 0;
	opt_logsync = 0;

	context = conf_init();

	if (os_init(context) != 0)
		goto err_conf;

	joystickb_reg(context, 1);
	joystickb_reg_driver_all(context);

	if (conf_input_args_load(context, 0, "", &argc, argv, error_callback, 0) != 0)
		goto err_os;

	for (i = 1; i < argc; ++i) {
		if (target_option_compare(argv[i], "log")) {
			opt_log = 1;
		} else if (target_option_compare(argv[i], "logsync")) {
			opt_logsync = 1;
		} else {
			fprintf(stderr, "Unknown argument '%s'\n", argv[1]);
			goto err_os;
		}
	}

	if (opt_log || opt_logsync) {
		const char* log = "advj.log";
		remove(log);
		log_init(log, opt_logsync);
	}

	log_std(("j: %s %s %s %s\n", "AdvanceJOYSTICK", ADV_VERSION, __DATE__, __TIME__));

	section_map[0] = "";
	conf_section_set(context, section_map, 1);

	if (joystickb_load(context) != 0)
		goto err_os;

	if (os_inner_init("AdvanceJOYSTICK") != 0)
		goto err_os;

	if (joystickb_init() != 0) {
		target_err("%s\n", error_get());
		goto err_os_inner;
	}

	probe();
	calibrate();
	run();

	joystickb_done();
	os_inner_done();

	log_std(("j: the end\n"));

	if (opt_log || opt_logsync) {
		log_done();
	}

	os_done();
	conf_done(context);

	return EXIT_SUCCESS;

err_os_inner:
	os_inner_done();
	log_done();
err_os:
	os_done();
err_conf:
	conf_done(context);
	return EXIT_FAILURE;
}