示例#1
0
bool mfi_format::save(io_generic *io, floppy_image *image)
{
	int tracks, heads;
	image->get_actual_geometry(tracks, heads);
	int max_track_size = 0;
	for(int track=0; track<tracks; track++)
		for(int head=0; head<heads; head++) {
			int tsize = image->get_track_size(track, head);
			if(tsize > max_track_size)
				 max_track_size = tsize;
		}

	header h;
	entry entries[84*2];
	memcpy(h.sign, sign, 16);
	h.cyl_count = tracks;
	h.head_count = heads;

	io_generic_write(io, &h, 0, sizeof(header));

	memset(entries, 0, sizeof(entries));

	int pos = sizeof(header) + tracks*heads*sizeof(entry);
	int epos = 0;
	UINT32 *precomp = global_alloc_array(UINT32, max_track_size);
	UINT8 *postcomp = global_alloc_array(UINT8, max_track_size*4 + 1000);

	for(int track=0; track<tracks; track++)
		for(int head=0; head<heads; head++) {
			int tsize = image->get_track_size(track, head);
			if(!tsize) {
				epos++;
				continue;
			}

			memcpy(precomp, image->get_buffer(track, head), tsize*4);
			for(int j=0; j<tsize-1; j++)
				precomp[j] = (precomp[j] & floppy_image::MG_MASK) |
					((precomp[j+1] & floppy_image::TIME_MASK) -
					 (precomp[j] & floppy_image::TIME_MASK));
			precomp[tsize-1] = (precomp[tsize-1] & floppy_image::MG_MASK) |
				(200000000 - (precomp[tsize-1] & floppy_image::TIME_MASK));

			uLongf csize = max_track_size*4 + 1000;
			if(compress(postcomp, &csize, (const Bytef *)precomp, tsize*4) != Z_OK)
				return false;

			entries[epos].offset = pos;
			entries[epos].uncompressed_size = tsize*4;
			entries[epos].compressed_size = csize;
			epos++;

			io_generic_write(io, postcomp, pos, csize);
			pos += csize;
		}

	io_generic_write(io, entries, sizeof(header), tracks*heads*sizeof(entry));
	return true;
}
示例#2
0
const char * sega8_cart_slot_device::get_default_card_software(const machine_config &config, emu_options &options)
{
	if (open_image_file(options))
	{
		const char *slot_string = "rom";
		UINT32 len = core_fsize(m_file), offset = 0;
		UINT8 *ROM = global_alloc_array(UINT8, len);
		int type;

		core_fread(m_file, ROM, len);

		if ((len % 0x4000) == 512)
			offset = 512;

		type = get_cart_type(ROM + offset, len - offset);
		slot_string = sega8_get_slot(type);

		//printf("type: %s\n", slot_string);
		global_free(ROM);
		clear();

		return slot_string;
	}

	return software_get_default_slot(config, options, this, "rom");
}
示例#3
0
file_error emu_file::load_zipped_file()
{
	assert(m_file == NULL);
	assert(m_zipdata == NULL);
	assert(m_zipfile != NULL);

	// allocate some memory
	m_zipdata = global_alloc_array(UINT8, m_ziplength);

	// read the data into our buffer and return
	zip_error ziperr = zip_file_decompress(m_zipfile, m_zipdata, m_ziplength);
	if (ziperr != ZIPERR_NONE)
	{
		global_free(m_zipdata);
		m_zipdata = NULL;
		return FILERR_FAILURE;
	}

	// convert to RAM file
	file_error filerr = core_fopen_ram(m_zipdata, m_ziplength, m_openflags, &m_file);
	if (filerr != FILERR_NONE)
	{
		global_free(m_zipdata);
		m_zipdata = NULL;
		return FILERR_FAILURE;
	}

	// close out the ZIP file
	zip_file_close(m_zipfile);
	m_zipfile = NULL;
	return FILERR_NONE;
}
示例#4
0
static LRESULT send_id_string(running_machine &machine, HWND hwnd, LPARAM id)
{
	copydata_id_string *temp;
	COPYDATASTRUCT copydata;
	const char *name;
	int datalen;

	// id 0 is the name of the game
	if (id == 0)
		name = machine.system().name;
	else
		name = output_id_to_name(id);

	// a NULL name is an empty string
	if (name == NULL)
		name = "";

	// allocate memory for the message
	datalen = sizeof(*temp) + strlen(name);
	temp = (copydata_id_string *)global_alloc_array(UINT8, datalen);
	temp->id = id;
	strcpy(temp->string, name);

	// reply by using SendMessage with WM_COPYDATA
	copydata.dwData = COPYDATA_MESSAGE_ID_STRING;
	copydata.cbData = datalen;
	copydata.lpData = temp;
	SendMessage(hwnd, WM_COPYDATA, (WPARAM)output_hwnd, (LPARAM)&copydata);

	// free the data
	global_free(temp);
	return 0;
}
示例#5
0
file_error emu_file::load__7zped_file()
{
	assert(m_file == NULL);
	assert(m__7zdata == NULL);
	assert(m__7zfile != NULL);

	// allocate some memory
	m__7zdata = global_alloc_array(UINT8, m__7zlength);

	// read the data into our buffer and return
	_7z_error _7zerr = _7z_file_decompress(m__7zfile, m__7zdata, m__7zlength);
	if (_7zerr != _7ZERR_NONE)
	{
		global_free(m__7zdata);
		m__7zdata = NULL;
		return FILERR_FAILURE;
	}

	// convert to RAM file
	file_error filerr = core_fopen_ram(m__7zdata, m__7zlength, m_openflags, &m_file);
	if (filerr != FILERR_NONE)
	{
		global_free(m__7zdata);
		m__7zdata = NULL;
		return FILERR_FAILURE;
	}

	// close out the _7Z file
	_7z_file_close(m__7zfile);
	m__7zfile = NULL;
	return FILERR_NONE;
}
示例#6
0
void dp8390_device::do_tx() {
	UINT8 *buf;
	int i;
	UINT32 high16 = (m_regs.dcr & 4)?m_regs.rsar<<16:0;
	if(m_reset) return;
	if(LOOPBACK) return;  // TODO: loopback
	m_regs.tsr = 0;
	if(m_regs.tbcr > 1518) logerror("dp8390: trying to send overlong frame\n");
	if(!m_regs.tbcr) { // ? Bochs says solaris actually does this
		m_regs.tsr = 1;
		m_regs.cr &= ~4;
		return;
	}

	buf = global_alloc_array(UINT8, m_regs.tbcr);
	for(i = 0; i < m_regs.tbcr; i++) buf[i] = mem_read(high16 + (m_regs.tpsr << 8) + i);

	if(send(buf, m_regs.tbcr)) {
		m_regs.tsr = 1;
		m_regs.isr |= 2;
	} else {
		m_regs.tsr = 8; // not quite right but there isn't a generic "tx failed"
		m_regs.isr |= 8;
	}
	m_regs.cr &= ~4;
	check_irq();
	global_free(buf);
}
示例#7
0
static void hiscore_save (running_machine &machine)
{
    file_error filerr;
	if (is_highscore_enabled(machine))
	{
		astring fname(machine.basename(), ".hi");
 		emu_file f = emu_file(machine.options().value(OPTION_HISCORE_DIRECTORY), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS);
		filerr = f.open(fname);
		LOG(("hiscore_save\n"));
		if (filerr == FILERR_NONE)
		{
			memory_range *mem_range = state.mem_range;
			LOG(("saving...\n"));
			while (mem_range)
			{
				UINT8 *data = global_alloc_array(UINT8, mem_range->num_bytes);
				if (data)
				{
					/*  this buffer will almost certainly be small
                        enough to be dynamically allocated, but let's
                        avoid memory trashing just in case */
					copy_from_memory (machine, mem_range->cpu, mem_range->addr, data, mem_range->num_bytes);
					f.write(data, mem_range->num_bytes);
					global_free (data);
				}
				mem_range = mem_range->next;
			}
			f.close();
		}
	}
}
示例#8
0
static void hiscore_save (running_machine &machine)
{
	file_error filerr;
  	emu_file f(machine.options().hiscore_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS);
  	filerr = f.open(machine.basename(), ".hi");

	if (filerr == FILERR_NONE)
	{
		memory_range *mem_range = state.mem_range;

		while (mem_range)
		{
			UINT8 *data = global_alloc_array(UINT8, mem_range->num_bytes);

			if (data)
			{
				/*  this buffer will almost certainly be small
                        enough to be dynamically allocated, but let's
                        avoid memory trashing just in case */
				copy_from_memory (machine, mem_range->cpu, mem_range->addr, data, mem_range->num_bytes);
				f.write(data, mem_range->num_bytes);
				global_free_array(data);
			}
			mem_range = mem_range->next;
		}
		f.close();
	}
}
bool mfm_format::load(io_generic *io, floppy_image *image)
{
	MFMIMG header;
	MFMTRACKIMG trackdesc;
	UINT8 *trackbuf = 0;
	int trackbuf_size = 0;

	// read header
	io_generic_read(io, &header, 0, sizeof(header));
	int counter = 0;
	for(int track=0; track < header.number_of_track; track++) {
		for(int side=0; side < header.number_of_side; side++) {
			// read location of
			io_generic_read(io, &trackdesc,(header.mfmtracklistoffset)+( counter *sizeof(trackdesc)),sizeof(trackdesc));

			if(trackdesc.mfmtracksize > trackbuf_size) {
				if(trackbuf)
					global_free(trackbuf);
				trackbuf_size = trackdesc.mfmtracksize;
				trackbuf = global_alloc_array(UINT8, trackbuf_size);
			}

			// actual data read
			io_generic_read(io, trackbuf, trackdesc.mfmtrackoffset, trackdesc.mfmtracksize);

			generate_track_from_bitstream(track, side, trackbuf, trackdesc.mfmtracksize*8, image);

			counter++;
		}
	}
	if(trackbuf)
		global_free(trackbuf);

	return true;
}
示例#10
0
text_buffer *text_buffer_alloc(UINT32 bytes, UINT32 lines)
{
	text_buffer *text;

	/* allocate memory for the text buffer object */
	text = (text_buffer *)global_alloc(text_buffer);
	if (!text)
		return NULL;

	/* allocate memory for the buffer itself */
	text->buffer = (char *)global_alloc_array(char, bytes);
	if (!text->buffer)
	{
		global_free(text);
		return NULL;
	}

	/* allocate memory for the lines array */
	text->lineoffs = (INT32 *)global_alloc_array(INT32, lines);
	if (!text->lineoffs)
	{
		global_free_array(text->buffer);
		global_free(text);
		return NULL;
	}

	/* initialize the buffer description */
	text->bufsize = bytes;
	text->linesize = lines;
	text_buffer_clear(text);

	return text;
}
示例#11
0
文件: intelfsh.c 项目: cdenix/psmame
void intelfsh_device::nvram_read(emu_file &file)
{
	UINT8 *buffer = global_alloc_array(UINT8, m_config.m_size);
	file.read(buffer, m_config.m_size);
	for (int byte = 0; byte < m_config.m_size; byte++)
		m_addrspace[0]->write_byte(byte, buffer[byte]);
	global_free(buffer);
}
示例#12
0
void intelfsh_device::nvram_write(emu_file &file)
{
	UINT8 *buffer = global_alloc_array(UINT8, m_size);
	for (int byte = 0; byte < m_size; byte++)
		buffer[byte] = m_addrspace[0]->read_byte(byte);
	file.write(buffer, m_size);
	global_free(buffer);
}
示例#13
0
static void romident(core_options *options, const char *filename, romident_status *status)
{
	osd_directory *directory;

	/* reset the status */
	memset(status, 0, sizeof(*status));

	/* first try to open as a directory */
	directory = osd_opendir(filename);
	if (directory != NULL)
	{
		const osd_directory_entry *entry;

		/* iterate over all files in the directory */
		while ((entry = osd_readdir(directory)) != NULL)
			if (entry->type == ENTTYPE_FILE)
			{
				astring curfile(filename, PATH_SEPARATOR, entry->name);
				identify_file(options, curfile, status);
			}
		osd_closedir(directory);
	}

	/* if that failed, and the filename ends with .zip, identify as a ZIP file */
	else if (core_filename_ends_with(filename, ".zip"))
	{
		/* first attempt to examine it as a valid ZIP file */
		zip_file *zip = NULL;
		zip_error ziperr = zip_file_open(filename, &zip);
		if (ziperr == ZIPERR_NONE && zip != NULL)
		{
			const zip_file_header *entry;

			/* loop over entries in the ZIP, skipping empty files and directories */
			for (entry = zip_file_first_file(zip); entry; entry = zip_file_next_file(zip))
				if (entry->uncompressed_length != 0)
				{
					UINT8 *data = global_alloc_array(UINT8, entry->uncompressed_length);
					if (data != NULL)
					{
						/* decompress data into RAM and identify it */
						ziperr = zip_file_decompress(zip, data, entry->uncompressed_length);
						if (ziperr == ZIPERR_NONE)
							identify_data(options, entry->filename, data, entry->uncompressed_length, status);
						global_free(data);
					}
				}

			/* close up */
			zip_file_close(zip);
		}
	}

	/* otherwise, identify as a raw file */
	else
		identify_file(options, filename, status);
}
示例#14
0
bool ipf_format::load(io_generic *io, floppy_image *image)
{
	UINT32 size = io_generic_size(io);
	UINT8 *data = global_alloc_array(UINT8, size);
	io_generic_read(io, data, 0, size);
	bool res = parse(data, size, image);
	global_free(data);
	return res;
}
示例#15
0
driver_enumerator::driver_enumerator(emu_options &options, const game_driver &driver)
	: m_current(-1),
	  m_filtered_count(0),
	  m_options(options),
	  m_included(global_alloc_array(UINT8, s_driver_count)),
	  m_config(global_alloc_array_clear(machine_config *, s_driver_count))
{
	filter(driver);
}
示例#16
0
static void identify_data(core_options *options, const char *name, const UINT8 *data, int length, romident_status *status)
{
	char hash[HASH_BUF_SIZE];
	UINT8 *tempjed = NULL;
	astring basename;
	int found = 0;
	jed_data jed;

	/* if this is a '.jed' file, process it into raw bits first */
	if (core_filename_ends_with(name, ".jed") && jed_parse(data, length, &jed) == JEDERR_NONE)
	{
		/* now determine the new data length and allocate temporary memory for it */
		length = jedbin_output(&jed, NULL, 0);
		tempjed = global_alloc_array(UINT8, length);
		if (tempjed == NULL)
			return;

		/* create a binary output of the JED data and use that instead */
		jedbin_output(&jed, tempjed, length);
		data = tempjed;
	}

	/* compute the hash of the data */
	hash_data_clear(hash);
	hash_compute(hash, data, length, HASH_SHA1 | HASH_CRC);

	/* output the name */
	status->total++;
	core_filename_extract_base(&basename, name, FALSE);
	mame_printf_info("%-20s", basename.cstr());

	/* see if we can find a match in the ROMs */
	match_roms(options, hash, length, &found);

	/* if we didn't find it, try to guess what it might be */
	if (found == 0)
	{
		/* if not a power of 2, assume it is a non-ROM file */
		if ((length & (length - 1)) != 0)
		{
			mame_printf_info("NOT A ROM\n");
			status->nonroms++;
		}

		/* otherwise, it's just not a match */
		else
			mame_printf_info("NO MATCH\n");
	}

	/* if we did find it, count it as a match */
	else
		status->matches++;

	/* free any temporary JED data */
	if (tempjed != NULL)
		global_free(tempjed);
}
示例#17
0
bool mfi_format::load(io_generic *io, UINT32 form_factor, floppy_image *image)
{
	header h;
	entry entries[84*2];
	io_generic_read(io, &h, 0, sizeof(header));
	io_generic_read(io, &entries, sizeof(header), h.cyl_count*h.head_count*sizeof(entry));

	image->set_variant(h.variant);

	UINT8 *compressed = 0;
	int compressed_size = 0;

	entry *ent = entries;
	for(unsigned int cyl=0; cyl != h.cyl_count; cyl++)
		for(unsigned int head=0; head != h.head_count; head++) {
			if(ent->uncompressed_size == 0) {
				// Unformatted track
				image->set_track_size(cyl, head, 0);
				ent++;
				continue;
			}

			if(ent->compressed_size > compressed_size) {
				if(compressed)
					global_free(compressed);
				compressed_size = ent->compressed_size;
				compressed = global_alloc_array(UINT8, compressed_size);
			}

			io_generic_read(io, compressed, ent->offset, ent->compressed_size);

			unsigned int cell_count = ent->uncompressed_size/4;
			image->set_track_size(cyl, head, cell_count);
			UINT32 *trackbuf = image->get_buffer(cyl, head);

			uLongf size = ent->uncompressed_size;
			if(uncompress((Bytef *)trackbuf, &size, compressed, ent->compressed_size) != Z_OK)
				return false;

			UINT32 cur_time = 0;
			for(unsigned int i=0; i != cell_count; i++) {
				UINT32 next_cur_time = cur_time + (trackbuf[i] & TIME_MASK);
				trackbuf[i] = (trackbuf[i] & MG_MASK) | cur_time;
				cur_time = next_cur_time;
			}
			if(cur_time != 200000000)
				return false;

			ent++;
		}

	if(compressed)
		global_free(compressed);

	return true;
}
示例#18
0
文件: g64_dsk.c 项目: tweakoz/vindigo
bool g64_format::save(io_generic *io, floppy_image *image)
{
	UINT8 header[] = { 'G', 'C', 'R', '-', '1', '5', '4', '1', 0x00, 0x54, TRACK_LENGTH & 0xff, TRACK_LENGTH >> 8 };

	io_generic_write(io, header, SIGNATURE, sizeof(header));
	
	int head = 0;
	int tracks_written = 0;

	for (int track = 0; track < 84; track++) {
		offs_t tpos = TRACK_OFFSET + track * 4;
		offs_t spos = SPEED_ZONE + track * 4;
		offs_t dpos = TRACK_DATA + tracks_written * TRACK_LENGTH;

		io_generic_write_filler(io, 0x00, tpos, 4);
		io_generic_write_filler(io, 0x00, spos, 4);

		if (image->get_track_size(track, head) <= 1)
			continue;

		UINT8 *trackbuf = global_alloc_array(UINT8, TRACK_LENGTH-2);
		int track_size;
		int speed_zone;

		// figure out the cell size and speed zone from the track data
		if ((speed_zone = generate_bitstream(track, head, 3, trackbuf, track_size, image)) == -1)
			if ((speed_zone = generate_bitstream(track, head, 2, trackbuf, track_size, image)) == -1)
				if ((speed_zone = generate_bitstream(track, head, 1, trackbuf, track_size, image)) == -1)
					if ((speed_zone = generate_bitstream(track, head, 0, trackbuf, track_size, image)) == -1)
						throw emu_fatalerror("g64_format: Cannot determine speed zone for track %u", track);

		LOG_FORMATS("track %u size %u cell %u\n", track, track_size, c1541_cell_size[speed_zone]);

		UINT8 track_offset[4];
		UINT8 speed_offset[4];
		UINT8 track_length[2];

		place_integer_le(track_offset, 0, 4, dpos);
		place_integer_le(speed_offset, 0, 4, speed_zone);
		place_integer_le(track_length, 0, 2, track_size/8);

		io_generic_write(io, track_offset, tpos, 4);
		io_generic_write(io, speed_offset, spos, 4);
		io_generic_write_filler(io, 0xff, dpos, TRACK_LENGTH);
		io_generic_write(io, track_length, dpos, 2);
		io_generic_write(io, trackbuf, dpos + 2, track_size);
		
		tracks_written++;

		global_free(trackbuf);
	}

	return true;
}
示例#19
0
/*-------------------------------------------------
    DEVICE_IMAGE_LOAD( rom )
-------------------------------------------------*/
bool rom_image_device::call_load()
{
	device_image_interface* image = this;
	UINT64 size = image->length();

	m_base = global_alloc_array(UINT8, 16384);
	if(size <= 16384)
	{
		image->fread(m_base,size);
	}
	else
	{
		image->fseek(size-16384,SEEK_SET);
		image->fread(m_base,16384);
	}

	return IMAGE_INIT_PASS;
}
示例#20
0
static int drawgdi_window_draw(win_window_info *window, HDC dc, int update)
{
	gdi_info *gdi = (gdi_info *)window->drawdata;
	int width, height, pitch;
	RECT bounds;

	// we don't have any special resize behaviors
	if (window->resize_state == RESIZE_STATE_PENDING)
		window->resize_state = RESIZE_STATE_NORMAL;

	// get the target bounds
	GetClientRect(window->hwnd, &bounds);

	// compute width/height/pitch of target
	width = rect_width(&bounds);
	height = rect_height(&bounds);
	pitch = (width + 3) & ~3;

	// make sure our temporary bitmap is big enough
	if (pitch * height * 4 > gdi->bmsize)
	{
		gdi->bmsize = pitch * height * 4 * 2;
		global_free(gdi->bmdata);
		gdi->bmdata = global_alloc_array(UINT8, gdi->bmsize);
	}

	// draw the primitives to the bitmap
	window->primlist->acquire_lock();
	software_renderer<UINT32, 0,0,0, 16,8,0>::draw_primitives(*window->primlist, gdi->bmdata, width, height, pitch);
	window->primlist->release_lock();

	// fill in bitmap-specific info
	gdi->bminfo.bmiHeader.biWidth = pitch;
	gdi->bminfo.bmiHeader.biHeight = -height;
	gdi->bminfo.bmiHeader.biBitCount = 32;

	// blit to the screen
	StretchDIBits(dc, 0, 0, width, height,
				0, 0, width, height,
				gdi->bmdata, &gdi->bminfo, DIB_RGB_COLORS, SRCCOPY);
	return 0;
}
示例#21
0
文件: g64_dsk.c 项目: tweakoz/vindigo
bool g64_format::load(io_generic *io, UINT32 form_factor, floppy_image *image)
{
	UINT64 size = io_generic_size(io);
	UINT8 *img = global_alloc_array(UINT8, size);
	io_generic_read(io, img, 0, size);

	if (img[VERSION]) {
		throw emu_fatalerror("g64_format: Unsupported version %u", img[VERSION]);
	}

	int track_count = img[TRACK_COUNT];
	int head = 0;

	for (int track = 0; track < track_count; track++)
	{
		offs_t track_offset = pick_integer_le(img, TRACK_OFFSET + (track * 4), 4);
		
		if (!track_offset)
			continue;

		if (track_offset > size)
			throw emu_fatalerror("g64_format: Track %u offset %06x out of bounds", track, track_offset);

		offs_t speed_zone = pick_integer_le(img, SPEED_ZONE + (track * 4), 4);

		if (speed_zone > 3)
			throw emu_fatalerror("g64_format: Unsupported variable speed zones on track %d", track);

		UINT16 track_bytes = pick_integer_le(img, track_offset, 2);
		int track_size = track_bytes * 8;
		
		LOG_FORMATS("track %u size %u cell %ld\n", track, track_size, 200000000L/track_size);

		generate_track_from_bitstream(track, head, &img[track_offset+2], track_size, image);
	}

	global_free(img);

	image->set_variant(floppy_image::SSSD);

	return true;
}
示例#22
0
driver_enumerator::driver_enumerator(emu_options &options)
	: m_current(-1),
	  m_filtered_count(0),
	  m_options(options),
	  m_included(global_alloc_array(UINT8, s_driver_count)),
	  m_config(global_alloc_array_clear(machine_config *, s_driver_count))
{
	include_all();
}


driver_enumerator::driver_enumerator(emu_options &options, const char *string)
	: m_current(-1),
	  m_filtered_count(0),
	  m_options(options),
	  m_included(global_alloc_array(UINT8, s_driver_count)),
	  m_config(global_alloc_array_clear(machine_config *, s_driver_count))
{
	filter(string);
}
示例#23
0
文件: drawgdi.cpp 项目: goofwear/mame
int renderer_gdi::draw(const int update)
{
	auto win = assert_window();

	// we don't have any special resize behaviors
	if (win->m_resize_state == RESIZE_STATE_PENDING)
		win->m_resize_state = RESIZE_STATE_NORMAL;

	// get the target bounds
	RECT bounds;
	GetClientRect(win->platform_window<HWND>(), &bounds);

	// compute width/height/pitch of target
	int width = rect_width(&bounds);
	int height = rect_height(&bounds);
	int pitch = (width + 3) & ~3;

	// make sure our temporary bitmap is big enough
	if (pitch * height * 4 > m_bmsize)
	{
		m_bmsize = pitch * height * 4 * 2;
		global_free_array(m_bmdata);
		m_bmdata = global_alloc_array(uint8_t, m_bmsize);
	}

	// draw the primitives to the bitmap
	win->m_primlist->acquire_lock();
	software_renderer<uint32_t, 0,0,0, 16,8,0>::draw_primitives(*win->m_primlist, m_bmdata, width, height, pitch);
	win->m_primlist->release_lock();

	// fill in bitmap-specific info
	m_bminfo.bmiHeader.biWidth = pitch;
	m_bminfo.bmiHeader.biHeight = -height;

	// blit to the screen
	StretchDIBits(win->m_dc, 0, 0, width, height,
				0, 0, width, height,
				m_bmdata, &m_bminfo, DIB_RGB_COLORS, SRCCOPY);
	return 0;
}
示例#24
0
const char * gba_cart_slot_device::get_default_card_software(const machine_config &config, emu_options &options)
{
	if (open_image_file(options))
	{
		const char *slot_string = "gba_rom";
		UINT32 len = core_fsize(m_file);
		UINT8 *ROM = global_alloc_array(UINT8, len);
		int type;

		core_fread(m_file, ROM, len);

		type = get_cart_type(ROM, len);
		slot_string = gba_get_slot(type);

		//printf("type: %s\n", slot_string);
		global_free(ROM);
		clear();

		return slot_string;
	}

	return software_get_default_slot(config, options, this, "gba_rom");
}
示例#25
0
static TCHAR *reg_query_string(HKEY key, const TCHAR *path)
{
	TCHAR *buffer;
	DWORD datalen;
	LONG result;

	// first query to get the length
	result = RegQueryValueEx(key, path, NULL, NULL, NULL, &datalen);
	if (result != ERROR_SUCCESS)
		return NULL;

	// allocate a buffer
	buffer = global_alloc_array(TCHAR, datalen + sizeof(*buffer));
	buffer[datalen / sizeof(*buffer)] = 0;

	// now get the actual data
	result = RegQueryValueEx(key, path, NULL, NULL, (LPBYTE)buffer, &datalen);
	if (result == ERROR_SUCCESS)
		return buffer;

	// otherwise return a NULL buffer
	global_free_array(buffer);
	return NULL;
}
示例#26
0
bool imd_format::load(io_generic *io, UINT32 form_factor, floppy_image *image)
{
	UINT64 size = io_generic_size(io);
	UINT8 *img = global_alloc_array(UINT8, size);
	io_generic_read(io, img, 0, size);

	UINT64 pos;
	for(pos=0; pos < size && img[pos] != 0x1a; pos++);
	pos++;

	if(pos >= size)
		return false;

	while(pos < size) {
		UINT8 mode = img[pos++];
		UINT8 track = img[pos++];
		UINT8 head = img[pos++];
		UINT8 sector_count = img[pos++];
		UINT8 ssize = img[pos++];

		if(ssize == 0xff)
			throw emu_fatalerror("imd_format: Unsupported variable sector size on track %d head %d", track, head);

		UINT32 actual_size = ssize < 7 ? 128 << ssize : 8192;

		static const int rates[3] = { 500000, 300000, 250000 };
		bool fm = mode < 3;
		int rate = rates[mode % 3];
		int rpm = form_factor == floppy_image::FF_8 || (form_factor == floppy_image::FF_525 && rate >= 300000) ? 360 : 300;
		int cell_count = (fm ? 1 : 2)*rate*60/rpm;

		const UINT8 *snum = img+pos;
		pos += sector_count;
		const UINT8 *tnum = head & 0x80 ? img+pos : NULL;
		if(tnum)
			pos += sector_count;
		const UINT8 *hnum = head & 0x40 ? img+pos : NULL;
		if(hnum)
			pos += sector_count;

		head &= 0x3f;

		int gap_3 = calc_default_pc_gap3_size(form_factor, actual_size);

		desc_pc_sector sects[256];

		for(int i=0; i<sector_count; i++) {
			UINT8 stype = img[pos++];
			sects[i].track       = tnum ? tnum[i] : track;
			sects[i].head        = hnum ? hnum[i] : head;
			sects[i].sector      = snum[i];
			sects[i].size        = ssize;
			sects[i].actual_size = actual_size;

			if(stype == 0 || stype > 8) {
				sects[i].data = NULL;

			} else {
				sects[i].deleted = stype == 3 || stype == 4 || stype == 7 || stype == 8;
				sects[i].bad_crc = stype == 5 || stype == 6 || stype == 7 || stype == 8;

				if(stype == 2 || stype == 4 || stype == 6 || stype == 8) {
					sects[i].data = global_alloc_array(UINT8, actual_size);
					memset(sects[i].data, img[pos++], actual_size);

				} else {
					sects[i].data = img + pos;
					pos += actual_size;
				}
			}
		}

		if(fm)
			build_pc_track_fm(track, head, image, cell_count, sector_count, sects, gap_3);
		else
			build_pc_track_mfm(track, head, image, cell_count, sector_count, sects, gap_3);

		for(int i=0; i<sector_count; i++)
			if(sects[i].data && (sects[i].data < img || sects[i].data >= img+size))
				global_free(sects[i].data);
	}

	global_free(img);
	return true;
}
示例#27
0
/* call hiscore_open once after loading a game */
void hiscore_init (running_machine &machine)
{
	memory_range *mem_range = state.mem_range;
	file_error filerr;
	const char *db_filename = machine.options().value(OPTION_HISCORE_FILE); /* high score definition file */
    const char *name = machine.system().name;
	state.hiscores_have_been_loaded = 0;

	while (mem_range)
	{

		if (strstr(machine.system().source_file,"cinemat.c") > 0)
		{
			machine.cpu[mem_range->cpu]->memory().space(AS_DATA)->write_byte(mem_range->addr, ~mem_range->start_value);
			machine.cpu[mem_range->cpu]->memory().space(AS_DATA)->write_byte(mem_range->addr + mem_range->num_bytes-1, ~mem_range->end_value);
			mem_range = mem_range->next;
		}
		else
		{
			machine.cpu[mem_range->cpu]->memory().space(AS_PROGRAM)->write_byte(mem_range->addr, ~mem_range->start_value);
			machine.cpu[mem_range->cpu]->memory().space(AS_PROGRAM)->write_byte(mem_range->addr + mem_range->num_bytes-1,~mem_range->end_value);
			mem_range = mem_range->next;
		}
	}

	state.mem_range = NULL;
	emu_file f = emu_file(OPEN_FLAG_READ);
	filerr = f.open(db_filename);
	if (filerr == FILERR_NONE)
	{
		char buffer[MAX_CONFIG_LINE_SIZE];
		enum { FIND_NAME, FIND_DATA, FETCH_DATA } mode;
		mode = FIND_NAME;

		while (f.gets (buffer, MAX_CONFIG_LINE_SIZE))
		{
			if (mode==FIND_NAME)
			{
				if (matching_game_name (buffer, name))
				{
					mode = FIND_DATA;
					LOG(("hs config found!\n"));
				}
			}
			else if (is_mem_range (buffer))
			{
				const char *pBuf = buffer;
				mem_range = global_alloc_array(memory_range, sizeof(memory_range));
				if (mem_range)
				{
					mem_range->cpu = hexstr2num (&pBuf);
					mem_range->addr = hexstr2num (&pBuf);
					mem_range->num_bytes = hexstr2num (&pBuf);
					mem_range->start_value = hexstr2num (&pBuf);
					mem_range->end_value = hexstr2num (&pBuf);

					mem_range->next = NULL;
					{
						memory_range *last = state.mem_range;
						while (last && last->next) last = last->next;
						if (last == NULL)
						{
							state.mem_range = mem_range;
						}
						else
						{
							last->next = mem_range;
						}
					}

					mode = FETCH_DATA;
				}
				else
				{
					hiscore_free();
					break;
				}
			}
			else
			{
				/* line is a game name */
				if (mode == FETCH_DATA) break;
			}
		}
		f.close ();
	}

	timer = machine.scheduler().timer_alloc(FUNC(hiscore_periodic), NULL);
	timer->adjust(machine.primary_screen->frame_period(), 0, machine.primary_screen->frame_period());

	machine.add_notifier(MACHINE_NOTIFY_EXIT, machine_notify_delegate(FUNC(hiscore_close), &machine));
}
示例#28
0
 /**************************************************************************
 *      index_datafile
 *      Create an index for the records in the currently open datafile.
 *
 *      Returns 0 on error, or the number of index entries created.
 **************************************************************************/
static int index_datafile(struct tDatafileIndex **_index, int source)
{
	struct tDatafileIndex *idx;
	int count = 0;
	char readbuf[512];
	char name[40];
	int num_games = driver_list::total();

	/* rewind file */
	if (ParseSeek (0L, SEEK_SET))
		return 0;

	/* allocate index */
	idx = *_index = global_alloc_array(tDatafileIndex, (num_games + 1) * sizeof (struct tDatafileIndex));

	if (!idx)
		return 0;

	while (fgets(readbuf, 512, fp))
	{
		/* DATAFILE_TAG_KEY identifies the driver */
		if (!core_strnicmp(DATAFILE_TAG_KEY, readbuf, strlen(DATAFILE_TAG_KEY)))
		{
			int game_index = 0;
			char *curpoint = &readbuf[strlen(DATAFILE_TAG_KEY) + 1];
			char *pch = NULL;
			char *ends = &readbuf[strlen(readbuf) - 1];

			while (curpoint < ends)
			{
				// search for comma
				pch = strpbrk(curpoint, ",");

				// found it
				if (pch)
				{
					// copy data and validate driver
					int len = pch - curpoint;
					strncpy(name, curpoint, len);
					name[len] = '\0';

					if (!source)
						game_index = GetGameNameIndex(name);
					else
						game_index = GetSrcDriverIndex(name);

					if (game_index >= 0)
					{
						idx->driver = &driver_list::driver(game_index);
						idx->offset = ftell(fp);
						idx++;
						count++;
					}

					// update current point
					curpoint = pch + 1;
				}
				// if comma not found, copy data while until reach the end of string
				else if (!pch && curpoint < ends)
				{
					int len = ends - curpoint;
					strncpy(name, curpoint, len);
					name[len] = '\0';

					if (!source)
						game_index = GetGameNameIndex(name);
					else
						game_index = GetSrcDriverIndex(name);

					if (game_index >= 0)
					{
						idx->driver = &driver_list::driver(game_index);
						idx->offset = ftell(fp);
						idx++;
						count++;
					}

					// update current point
					curpoint = ends;
				}
			}
		}
	}

	/* mark end of index */
	idx->offset = 0L;
	idx->driver = 0;
	return count;
}
示例#29
0
bool g64_format::load(io_generic *io, UINT32 form_factor, floppy_image *image)
{
    UINT64 size = io_generic_size(io);
    UINT8 *img = global_alloc_array(UINT8, size);
    io_generic_read(io, img, 0, size);

    int version = img[0x08];
    if (version)
        throw emu_fatalerror("g64_format: Unsupported version %u", version);

    int track_count = img[0x09];

    int pos = 0x0c;
    int track_offset[84*2];
    for(int track = 0; track < track_count; track++) {
        track_offset[track] = pick_integer_le(img, pos, 4);
        pos += 4;
    }

    int speed_zone_offset[84*2];
    for(int track = 0; track < track_count; track++) {
        speed_zone_offset[track] = pick_integer_le(img, pos, 4);
        pos += 4;
    }

    for(int track = 0; track < track_count; track++) {
        int track_size = 0;
        pos = track_offset[track];
        if (pos > 0) {
            track_size = pick_integer_le(img, pos, 2);
            pos +=2;

            if (speed_zone_offset[track] > 3)
                throw emu_fatalerror("g64_format: Unsupported variable speed zones on track %d", track);

            UINT32 cell_size = c1541_cell_size[speed_zone_offset[track]];
            int total_size = 200000000/cell_size;
            UINT32 *buffer = global_alloc_array_clear(UINT32, total_size);
            int offset = 0;

            for (int i=0; i<track_size; i++, pos++) {
                for (int bit=7; bit>=0; bit--) {
                    bit_w(buffer, offset++, BIT(img[pos], bit), cell_size);
                    if (offset == total_size) break;
                }
            }

            if (offset < total_size) {
                // pad the remainder of the track with sync
                int count = (total_size-offset);
                for (int i=0; i<count; i++) {
                    bit_w(buffer, offset++, 1, cell_size);
                }
            }

            int physical_track = track >= 84 ? track - 84 : track;
            int head = track >= 84;

            generate_track_from_levels(physical_track, head, buffer, total_size, 0, image);
            global_free(buffer);
        }
    }

    image->set_variant(floppy_image::SSSD);

    return true;
}
示例#30
0
static TCHAR *rawinput_device_improve_name(TCHAR *name)
{
	static const TCHAR usbbasepath[] = TEXT("SYSTEM\\CurrentControlSet\\Enum\\USB");
	static const TCHAR basepath[] = TEXT("SYSTEM\\CurrentControlSet\\Enum\\");
	TCHAR *regstring = NULL;
	TCHAR *parentid = NULL;
	TCHAR *regpath = NULL;
	const TCHAR *chsrc;
	HKEY regkey = NULL;
	int usbindex;
	TCHAR *chdst;
	LONG result;

	// The RAW name received is formatted as:
	//   \??\type-id#hardware-id#instance-id#{DeviceClasses-id}
	// XP starts with "\??\"
	// Vista64 starts with "\\?\"

	// ensure the name is something we can handle
	if (_tcsncmp(name, TEXT("\\\\?\\"), 4) != 0 && _tcsncmp(name, TEXT("\\??\\"), 4) != 0)
		return name;

	// allocate a temporary string and concatenate the base path plus the name
	regpath = global_alloc_array(TCHAR, _tcslen(basepath) + 1 + _tcslen(name));
	_tcscpy(regpath, basepath);
	chdst = regpath + _tcslen(regpath);

	// convert all # to \ in the name
	for (chsrc = name + 4; *chsrc != 0; chsrc++)
		*chdst++ = (*chsrc == '#') ? '\\' : *chsrc;
	*chdst = 0;

	// remove the final chunk
	chdst = _tcsrchr(regpath, '\\');
	if (chdst == NULL)
		goto exit;
	*chdst = 0;

	// now try to open the registry key
	result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, regpath, 0, KEY_READ, &regkey);
	if (result != ERROR_SUCCESS)
		goto exit;

	// fetch the device description; if it exists, we are finished
	regstring = reg_query_string(regkey, TEXT("DeviceDesc"));
	if (regstring != NULL)
		goto convert;

	// close this key
	RegCloseKey(regkey);
	regkey = NULL;

	// if the key name does not contain "HID", it's not going to be in the USB tree; give up
	if (_tcsstr(regpath, TEXT("HID")) == NULL)
		goto exit;

	// extract the expected parent ID from the regpath
	parentid = _tcsrchr(regpath, '\\');
	if (parentid == NULL)
		goto exit;
	parentid++;

	// open the USB key
	result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, usbbasepath, 0, KEY_READ, &regkey);
	if (result != ERROR_SUCCESS)
		goto exit;

	// enumerate the USB key
	for (usbindex = 0; result == ERROR_SUCCESS && regstring == NULL; usbindex++)
	{
		TCHAR keyname[MAX_PATH];
		DWORD namelen;

		// get the next enumerated subkey and scan it
		namelen = ARRAY_LENGTH(keyname) - 1;
		result = RegEnumKeyEx(regkey, usbindex, keyname, &namelen, NULL, NULL, NULL, NULL);
		if (result == ERROR_SUCCESS)
		{
			LONG subresult;
			int subindex;
			HKEY subkey;

			// open the subkey
			subresult = RegOpenKeyEx(regkey, keyname, 0, KEY_READ, &subkey);
			if (subresult != ERROR_SUCCESS)
				continue;

			// enumerate the subkey
			for (subindex = 0; subresult == ERROR_SUCCESS && regstring == NULL; subindex++)
			{
				// get the next enumerated subkey and scan it
				namelen = ARRAY_LENGTH(keyname) - 1;
				subresult = RegEnumKeyEx(subkey, subindex, keyname, &namelen, NULL, NULL, NULL, NULL);
				if (subresult == ERROR_SUCCESS)
				{
					TCHAR *endparentid;
					LONG endresult;
					HKEY endkey;

					// open this final key
					endresult = RegOpenKeyEx(subkey, keyname, 0, KEY_READ, &endkey);
					if (endresult != ERROR_SUCCESS)
						continue;

					// do we have a match?
					endparentid = reg_query_string(endkey, TEXT("ParentIdPrefix"));
					if (endparentid != NULL && _tcsncmp(parentid, endparentid, _tcslen(endparentid)) == 0)
						regstring = reg_query_string(endkey, TEXT("DeviceDesc"));

					// free memory and close the key
					if (endparentid != NULL)
						global_free_array(endparentid);
					RegCloseKey(endkey);
				}
			}

			// close the subkey
			RegCloseKey(subkey);
		}
	}

	// if we didn't find anything, go to the exit
	if (regstring == NULL)
		goto exit;

convert:
	// replace the name with the nicer one
	global_free_array(name);

	// remove anything prior to the final semicolon
	chsrc = _tcsrchr(regstring, ';');
	if (chsrc != NULL)
		chsrc++;
	else
		chsrc = regstring;
	name = global_alloc_array(TCHAR, _tcslen(chsrc) + 1);
	_tcscpy(name, chsrc);

exit:
	if (regstring != NULL)
		global_free_array(regstring);
	if (regpath != NULL)
		global_free_array(regpath);
	if (regkey != NULL)
		RegCloseKey(regkey);

	return name;
}