Ejemplo 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;
	}
}
Ejemplo n.º 2
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);
}
Ejemplo n.º 3
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;
}
Ejemplo n.º 4
0
osd_file* osd_fopen(int pathtype, int pathindex, const char* filename, const char* mode, osd_file_error *error)
{
	struct fileio_item* i;
	char path_buffer[FILE_MAXPATH];
	adv_fz* h;
	char* split;
	struct advance_fileio_context* context = &CONTEXT.fileio;

	log_std(("osd: osd_fopen(pathtype:%d,pathindex:%d,filename:%s,mode:%s)\n", pathtype, pathindex, filename, mode));

	/* set a default error */
	*error = FILEERR_FAILURE;

	i = fileio_find(pathtype);
	if (!i) {
		log_std(("WARNING:fileio: file type %d unknown\n", pathtype));
		return 0;
	}

	/* HACK: for .CHD file MAME adds an initial slash */
	/* remove it assuming always relative paths */
	if (filename[0] == file_dir_slash())
		++filename;

	sncpy(path_buffer, sizeof(path_buffer), file_abs(i->dir_map[pathindex], filename));

	split = strchr(path_buffer, '=');
	if (split != 0) {
		char zip_file_buffer[FILE_MAXPATH];
		char file_buffer[FILE_MAXPATH];
		adv_zip* zip;
		adv_zipent* ent;

		*split = 0;
		snprintf(zip_file_buffer, sizeof(zip_file_buffer), "%s.zip", path_buffer);
		sncpy(file_buffer, sizeof(file_buffer), split + 1);

		log_std(("osd: osd_fopen() try %s %s\n", zip_file_buffer, file_buffer));

		if (access(zip_file_buffer, R_OK)!=0) {
			osd_errno_to_filerr(error);
			log_std(("osd: osd_fopen() -> failed, zip %s not readable\n", zip_file_buffer));
			return 0;
		}

		zip = zip_open(zip_file_buffer);
		if (!zip) {
			osd_errno_to_filerr(error);
			log_std(("osd: osd_fopen() -> failed, zip %s not openable\n", zip_file_buffer));
			return 0;
		}

		h = 0;
		while ((ent = zip_read(zip))!=0) {
			if (partialequal(ent->name, file_buffer)) {
				if (ent->compression_method == 0) {
					h = fzopenzipuncompressed(zip_file_buffer, ent->offset_lcl_hdr_frm_frst_disk, ent->uncompressed_size);
					if (h == 0)
						osd_errno_to_filerr(error);
				} else if (ent->compression_method == 8) {
					h = fzopenzipcompressed(zip_file_buffer, ent->offset_lcl_hdr_frm_frst_disk, ent->compressed_size, ent->uncompressed_size);
					if (h == 0)
						osd_errno_to_filerr(error);
				}
				break;
			}
		}

		zip_close(zip);
	} else {
		log_std(("osd: osd_fopen() try file %s\n", path_buffer));

		/* for the diff file support the write in memory mode */
		if (i->type == FILETYPE_IMAGE_DIFF) {
			/* if the file is already open reuse it */
			if (context->state.diff_handle && strcmp(path_buffer, context->state.diff_file_buffer)==0) {
				h = context->state.diff_handle;
			} else {
				/* try a normal open */
				h = fzopen(path_buffer, mode);
				if (h == 0) {
					osd_errno_to_filerr(error);
					log_std(("osd: fzopen() failed, %s\n", strerror(errno)));
					if (errno == EACCES || errno == EROFS) {
						log_std(("osd: retry with readonly\n"));
						/* reopen in memory */
						h = fzopennullwrite(path_buffer, mode);
						if (h == 0) {
							osd_errno_to_filerr(error);
							log_std(("osd: fzopenullwrite() failed, %s\n", strerror(errno)));
						} else {
							if (context->state.diff_handle == 0) {
								/* save the handle if not already saved */
								context->state.diff_handle = h;
								sncpy(context->state.diff_file_buffer, sizeof(context->state.diff_file_buffer), path_buffer);
							}
						}
					}
				}
			}
		} else {
			/* open a regular file */
			h = fzopen(path_buffer, mode);
			if (h == 0) {
				osd_errno_to_filerr(error);
				log_std(("osd: fzopen() failed, %s\n", strerror(errno)));
			}
		}
	}

	log_std(("osd: osd_fopen() -> return %p\n", h));

	/* clear the error if success */
	if (h != 0)
		*error = FILEERR_SUCCESS;

	return (osd_file*)h;
}