Ejemplo n.º 1
0
void bitbanger_output(mess_image *img, int value)
{
	int id = image_index_in_device(img);
	struct bitbanger_info *bi = bitbangers[id];
	double current_time;
	double pulse_width;

	/* normalize input */
	value = value ? 1 : 0;

	/* only meaningful if we change */
	if (bi->value != value)
	{
		current_time = timer_get_time();
		pulse_width = current_time - bi->last_pulse_time;

		assert(pulse_width >= 0);

		if (!bi->over_threshhold && ((bi->recorded_pulses > 0) || (bi->value == bi->config->initial_value)))
			bitbanger_addpulse(id, bi, pulse_width);

		/* update state */
		bi->value = value;
		bi->last_pulse_time = current_time;
		bi->over_threshhold = 0;

		/* update timeout timer */
		timer_reset(bi->timeout_timer, bi->config->pulse_threshhold);
	}
}
Ejemplo n.º 2
0
static basicdsk *get_basicdsk(mess_image *img)
{
	int drive = image_index_in_device(img);
	assert(drive >= 0);
	assert(drive < (sizeof(basicdsk_drives) / sizeof(basicdsk_drives[0])));
	return &basicdsk_drives[drive];
}
Ejemplo n.º 3
0
static void determine_open_plan(mess_image *image, int is_create, UINT32 *open_plan)
{
	unsigned int readable, writeable, creatable;
	int i = 0;

	if (image->dev->getdispositions)
	{
		image->dev->getdispositions(image->dev, image_index_in_device(image),
			&readable, &writeable, &creatable);
	}
	else
	{
		readable = image->dev->readable;
		writeable = image->dev->writeable;
		creatable = image->dev->creatable;
	}

	/* emit flags */
	if (!is_create && readable && writeable)
		open_plan[i++] = OPEN_FLAG_READ | OPEN_FLAG_WRITE;
	if (!is_create && !readable && writeable)
		open_plan[i++] = OPEN_FLAG_WRITE;
	if (!is_create && readable)
		open_plan[i++] = OPEN_FLAG_READ;
	if (writeable && creatable)
		open_plan[i++] = OPEN_FLAG_READ | OPEN_FLAG_WRITE | OPEN_FLAG_CREATE;
	open_plan[i] = 0;
}
Ejemplo n.º 4
0
static int bitbanger_init(mess_image *img)
{
	int id = image_index_in_device(img);
	struct bitbanger_info *bi;
	const struct bitbanger_config *config;

	config = (const struct bitbanger_config *) device_find(Machine->devices, IO_BITBANGER)->user1;

	bi = (struct bitbanger_info *) auto_malloc(sizeof(struct bitbanger_info));
	if (!bi)
		return INIT_FAIL;

	bi->pulses = (double *) auto_malloc(config->maximum_pulses * sizeof(double));
	if (!bi->pulses)
		return INIT_FAIL;

	bi->factored_pulses = (int *) auto_malloc(config->maximum_pulses * sizeof(int));
	if (!bi->factored_pulses)
		return INIT_FAIL;

	bi->config = config;
	bi->last_pulse_time = 0.0;
	bi->recorded_pulses = 0;
	bi->value = config->initial_value;
	bi->timeout_timer = timer_alloc(bitbanger_overthreshhold);
	bi->over_threshhold = 1;

	bitbangers[id] = bi;
	return INIT_PASS;
}
Ejemplo n.º 5
0
static int internal_load_mess_cd(mess_image *image, const char *metadata)
{
	chd_error err = 0;
	struct mess_cd *cd;
	chd_file *chd;
	int id = image_index_in_device(image);

	cd = get_drive(image);

	/* open the CHD file */
	err = chdcd_open_ref(image, CHD_OPEN_READ, NULL, &chd);	/* CDs are never writable */
	if (err)
		goto error;

	/* open the CD-ROM file */
	cd->cdrom_handle = cdrom_open(chd);
	if (!cd->cdrom_handle)
		goto error;

	drive_handles[id] = cd->cdrom_handle;
	return INIT_PASS;

error:
	if (chd)
		chd_close(chd);
	if (err)
		image_seterror(image, IMAGE_ERROR_UNSPECIFIED, chd_get_error_string(err));
	return INIT_FAIL;
}
Ejemplo n.º 6
0
static int process_cartridge(mess_image *image, mame_file *file)
{
	const rom_entry *romrgn, *roment;
	int position, result;

	romrgn = rom_first_region(Machine->gamedrv);
	while(romrgn)
	{
		roment = romrgn + 1;
		while(!ROMENTRY_ISREGIONEND(roment))
		{
			if (is_cart_roment(roment))
			{
				parse_rom_name(roment, &position, NULL);
				if (position == image_index_in_device(image))
				{
					result = load_cartridge(romrgn, roment, file);
					if (!result)
						return result;
				}
			}
			roment++;
		}
		romrgn = rom_next_region(romrgn);
	}
	return INIT_PASS;
}
Ejemplo n.º 7
0
static DEVICE_INIT(cbm_drive)
{
	int id = image_index_in_device(image);
	if (id == 0)
		cbm_drive_open();	/* boy these C64 drivers are butt ugly */
	return INIT_PASS;
}
Ejemplo n.º 8
0
void device_unload_mess_hd(mess_image *image)
{
	struct mess_hd *hd = get_drive(image);
	assert(hd->hard_disk_handle);
	hard_disk_close(hd->hard_disk_handle);
	hd->hard_disk_handle = NULL;
	drive_handles[image_index_in_device(image)] = NULL;
}
Ejemplo n.º 9
0
static int internal_load_mess_hd(mess_image *image, const char *metadata)
{
	int err = 0;
	struct mess_hd *hd;
	chd_file *chd;
	int is_writeable;
	int id = image_index_in_device(image);

	hd = get_drive(image);

	/* open the CHD file */
	do
	{
		is_writeable = image_is_writable(image);
		chd = chd_open_ref(image, is_writeable, NULL);

		if (!chd)
		{
			err = chd_get_last_error();

			/* special case; if we get CHDERR_FILE_NOT_WRITEABLE, make the
			 * image read only and repeat */
			if (err == CHDERR_FILE_NOT_WRITEABLE)
				image_make_readonly(image);
		}
	}
	while(!chd && is_writeable && (err == CHDERR_FILE_NOT_WRITEABLE));
	if (!chd)
		goto error;

	/* if we created the image and hence, have metadata to set, set the metadata */
	if (metadata)
	{
		err = chd_set_metadata(chd, HARD_DISK_STANDARD_METADATA, 0, metadata, strlen(metadata) + 1);
		if (err != CHDERR_NONE)
			goto error;
	}

	/* open the hard disk file */
	hd->hard_disk_handle = hard_disk_open(chd);
	if (!hd->hard_disk_handle)
		goto error;

	drive_handles[id] = hd->hard_disk_handle;

	return INIT_PASS;

error:
	if (chd)
		chd_close(chd);

	err = chd_get_last_error();
	if (err)
		image_seterror(image, IMAGE_ERROR_UNSPECIFIED, chd_get_error_string(err));
	return INIT_FAIL;
}
Ejemplo n.º 10
0
static DEVICE_INIT(cbm_rom)
{
	int id = image_index_in_device(image);
	if (id == 0)
	{
		cbm_c64_game = -1;
		cbm_c64_exrom = -1;
	}
	return INIT_PASS;
}
Ejemplo n.º 11
0
const char *image_typename_id(mess_image *image)
{
	const struct IODevice *dev;
	int id;
	static char buf[64];

	dev = image_device(image);
	id = image_index_in_device(image);
	return dev->name(dev, id, buf, sizeof(buf) / sizeof(buf[0]));
}
Ejemplo n.º 12
0
/* open an d64 image */
static DEVICE_LOAD(cbm_drive)
{
	int size;
	int id = image_index_in_device(image);

	cbm_drive[id].drive = 0;
	cbm_drive[id].image = NULL;

	size = mame_fsize(file);

	cbm_drive[id].image = (UINT8*) image_malloc(image, size);
	if (!cbm_drive[id].image)
		return INIT_FAIL;

	if (size != mame_fread (file, cbm_drive[id].image, size))
		return INIT_FAIL;

	cbm_drive[id].drive = D64_IMAGE;
	return 0;
}
Ejemplo n.º 13
0
/*
	display a small tape icon, with the current position in the tape image
*/
static void device_display_cassette(mess_image *image)
{
	char buf[65];
	float x, y;
	int n;
	double position, length;
	cassette_state uistate;

	/* abort if we should not be showing the image */
	if (!image_exists(image))
		return;
	if (!cassette_is_motor_on(image))
		return;

	/* figure out where we are in the cassette */
	position = cassette_get_position(image);
	length = cassette_get_length(image);
	uistate = cassette_get_state(image) & CASSETTE_MASK_UISTATE;

	/* choose a location on the screen */
	x = 0.0f;
	y = image_index_in_device(image) * ui_get_line_height();

	/* choose which frame of the animation we are at */
	n = ((int) position / ANIMATION_FPS) % ANIMATION_FRAMES;

	/* character pairs 2-3, 4-5, 6-7, 8-9 form little tape cassette images */
	snprintf(buf, sizeof(buf) / sizeof(buf[0]), "%c%c %c %02d:%02d (%04d) [%02d:%02d (%04d)]",
		n * 2 + 2,								/* cassette icon left */
		n * 2 + 3,								/* cassette icon right */
		(uistate == CASSETTE_PLAY) ? 16 : 14,	/* play or record icon */
		((int) position / 60),
		((int) position % 60),
		(int) position,
		((int) length / 60),
		((int) length % 60),
		(int) length);

	/* draw the cassette */
	ui_draw_text_box(buf, JUSTIFY_LEFT, x, y, UI_FILLCOLOR);
}
Ejemplo n.º 14
0
static int image_load_internal(mess_image *img, const char *name, int is_create, int create_format, option_resolution *create_args)
{
	const struct IODevice *dev;
	const char *s;
	char *newname;
	int err = INIT_PASS;
	mame_file *file = NULL;
	UINT8 *buffer = NULL;
	UINT64 size;
	unsigned int readable, writeable, creatable;

	/* unload if we are loaded */
	if (img->status & IMAGE_STATUS_ISLOADED)
		image_unload(img);

	/* clear out the error */
	image_clear_error(img);
	
	/* if we are attempting to "load" NULL, then exit at this point */
	if (!name)
		return INIT_PASS;

	dev = image_device(img);
	assert(dev);

	img->status |= IMAGE_STATUS_ISLOADING;

	if (name && *name)
	{
		newname = image_strdup(img, name);
		if (!newname)
		{
			err = IMAGE_ERROR_OUTOFMEMORY;
			goto error;
		}
	}
	else
		newname = NULL;

	img->name = newname;
	img->dir = NULL;

	osd_image_load_status_changed(img, 0);

	/* do we need to reset the CPU? */
	if ((timer_get_time() > 0) && dev->reset_on_load)
		machine_reset();

	/* prepare to open the file */
	img->created = 0;
	img->writeable = 0;
	file = NULL;
	if (dev->getdispositions)
	{
		dev->getdispositions(dev, image_index_in_device(img), &readable, &writeable, &creatable);
	}
	else
	{
		readable = dev->readable;
		writeable = dev->writeable;
		creatable = dev->creatable;
	}

	/* is this a ZIP file? */
	s = strrchr(img->name, '.');
	if (s && !mame_stricmp(s, ".ZIP"))
	{
		/* ZIP files are writeable */
		writeable = 0;
		creatable = 0;
	}

	if (readable && !writeable)
	{
		file = image_fopen_custom(img, FILETYPE_IMAGE, OSD_FOPEN_READ);
	}
	else if (!readable && writeable)
	{
		file = image_fopen_custom(img, FILETYPE_IMAGE, OSD_FOPEN_WRITE);
		img->writeable = file ? 1 : 0;
	}
	else if (readable && writeable)
	{
		file = image_fopen_custom(img, FILETYPE_IMAGE, OSD_FOPEN_RW);
		img->writeable = file ? 1 : 0;

		if (!file)
		{
			file = image_fopen_custom(img, FILETYPE_IMAGE, OSD_FOPEN_READ);
			if (!file && creatable)
			{
				file = image_fopen_custom(img, FILETYPE_IMAGE, OSD_FOPEN_RW_CREATE);
				img->writeable = file ? 1 : 0;
				img->created = file ? 1 : 0;
			}
		}
	}

	/* did this attempt succeed? */
	if (!file)
	{
		img->err = IMAGE_ERROR_FILENOTFOUND;
		goto error;
	}

	/* if applicable, call device verify */
	if (dev->imgverify && !image_has_been_created(img))
	{
		size = mame_fsize(file);
		buffer = malloc(size);
		if (!buffer)
		{
			img->err = IMAGE_ERROR_OUTOFMEMORY;
			goto error;
		}

		if (mame_fread(file, buffer, (UINT32) size) != size)
		{
			img->err = IMAGE_ERROR_INVALIDIMAGE;
			goto error;
		}

		err = dev->imgverify(buffer, size);
		if (err)
		{
			img->err = IMAGE_ERROR_INVALIDIMAGE;
			goto error;
		}

		mame_fseek(file, 0, SEEK_SET);

		free(buffer);
		buffer = NULL;
	}

	/* call device load or create */
	if (image_has_been_created(img) && dev->create)
	{
		err = dev->create(img, file, create_format, create_args);
		if (err)
		{
			if (!img->err)
				img->err = IMAGE_ERROR_UNSPECIFIED;
			goto error;
		}
	}
	else if (dev->load)
	{
		/* using device load */
		err = dev->load(img, file);
		if (err)
		{
			if (!img->err)
				img->err = IMAGE_ERROR_UNSPECIFIED;
			goto error;
		}
	}

	img->status &= ~IMAGE_STATUS_ISLOADING;
	img->status |= IMAGE_STATUS_ISLOADED;
	return INIT_PASS;

error:
	if (file)
		mame_fclose(file);
	if (buffer)
		free(buffer);
	if (img)
	{
		img->fp = NULL;
		img->name = NULL;
		img->status &= ~IMAGE_STATUS_ISLOADING|IMAGE_STATUS_ISLOADED;
	}

	osd_image_load_status_changed(img, 0);

	return INIT_FAIL;
}
Ejemplo n.º 15
0
static d88image *get_d88image(mess_image *img)
{
	return &d88image_drives[image_index_in_device(img)];
}
Ejemplo n.º 16
0
static DEVICE_EXIT(cbm_drive)
{
	int id = image_index_in_device(image);
	if (id == 0)
		cbm_drive_close();	/* boy these C64 drivers are butt ugly */
}
Ejemplo n.º 17
0
static DEVICE_UNLOAD(cbm_rom)
{
	int id = image_index_in_device(image);
	cbm_rom[id].size = 0;
	cbm_rom[id].chip = 0;
}
Ejemplo n.º 18
0
static struct mfm_disk_info *get_disk(mess_image *image)
{
	int disk = image_index_in_device(image);
	return &mfm_disks[disk];
}
Ejemplo n.º 19
0
int image_slotexists(mess_image *img)
{
	return image_index_in_device(img) < image_device(img)->count;
}