Пример #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;
	}
}
Пример #2
0
static void mixer_channel_free(unsigned channel)
{
	switch (mixer_map[channel].type) {
		case mixer_raw_file :
			fzclose(mixer_map[channel].file);
			break;
		case mixer_mp3_file :
			fzclose(mixer_map[channel].file);
			mp3_done(&mixer_map[channel].mp3);
			break;
		default:
			break;
	}

	mixer_map[channel].type = mixer_none;

	/* clear any stored data */
	memset(mixer_buffer[channel], 0, sizeof(mixer_buffer[channel]));
}
Пример #3
0
void advance_fileio_done(struct advance_fileio_context* context)
{
	struct fileio_item* i;
	for(i=FILEIO_CONFIG;i->type != FILETYPE_end;++i) {
		path_free(i->dir_map, i->dir_mac);
	}
	if (context->state.diff_handle) {
		fzclose(context->state.diff_handle);
	}
}
Пример #4
0
void osd_fclose(osd_file* file)
{
	adv_fz* h = (adv_fz*)file;
	struct advance_fileio_context* context = &CONTEXT.fileio;

	log_std(("osd: osd_fclose(%p)\n", file));

	if (h == context->state.diff_handle) {
		/* don't close the diff memory handler */

		/* reset the position */
		if (fzseek(h, 0, SEEK_SET) != 0) {
			fzclose(h);
			context->state.diff_handle = 0;
		}
	} else {
		fzclose(h);
	}
}
Пример #5
0
void advance_ui_changefont(struct advance_ui_context* context, unsigned screen_width, unsigned screen_height, unsigned aspect_x, unsigned aspect_y)
{
	unsigned sizex;
	unsigned sizey;

	adv_font_free(context->state.ui_font);
	adv_font_free(context->state.ui_font_oriented);

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

	log_std(("emu:ui: font computation: screen %dx%d, aspect %dx%d\n", screen_width, screen_height, aspect_x, aspect_y));

	if (context->config.ui_font_sizey >= 5 && context->config.ui_font_sizey <= 100) {
		sizey = screen_height / context->config.ui_font_sizey;
	} else {
		sizey = screen_height / 30;
	}

	if (context->config.ui_font_sizex >= 5 && context->config.ui_font_sizex <= 200) {
		sizex = screen_width / context->config.ui_font_sizex;
	} else {
		sizex = sizey * (screen_width * aspect_y) / (screen_height * aspect_x);
	}

	log_std(("emu:ui: font pixel size %dx%d\n", sizex, sizey));

	if (strcmp(context->config.ui_font_buffer, "auto") != 0) {
		adv_fz* f;
		const char* file = file_config_file_home(context->config.ui_font_buffer);

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

		f = fzopen(file, "rb");
		if (f) { /* ignore error */
			context->state.ui_font = adv_font_load(f, sizex, sizey);
			/* ignore error */

			fzclose(f);
		}
	}

	/* use default font otherwise */
	if (!context->state.ui_font)
		context->state.ui_font = adv_font_default(sizex, sizey, 0);

	if (!context->state.ui_font_oriented)
		context->state.ui_font_oriented = adv_font_default(13, 13, 1);

	adv_font_orientation(context->state.ui_font_oriented, context->config.ui_font_orientation);
}
Пример #6
0
/**
 * Play a WAV memory file.
 * If the channel is playing, it's before stopped.
 * \param channel Channel to use.
 * \param begin, end Memory range to use.
 * \param loop If loop the playing.
 */
adv_error mixer_play_memory_wav(unsigned channel, const unsigned char* begin, const unsigned char* end, adv_bool loop)
{
	adv_fz* f;

	f = fzopenmemory(begin, end - begin);
	if (!f)
		return -1;

	if (mixer_play_file_wav(channel, f, loop) != 0) {
		fzclose(f);
		return -1;
	}

	return 0;
}
Пример #7
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;
}