コード例 #1
0
ファイル: cbm.c プロジェクト: broftkd/historic-mess
static int general_cbm_loadsnap(mess_image *image, const char *file_type, int snapshot_size,
	offs_t offset, void (*cbm_sethiaddress)(UINT16 hiaddress))
{
	char buffer[7];
	UINT8 *data = NULL;
	UINT32 bytesread;
	UINT16 address = 0;
	int i;

	if (!file_type)
		goto error;

	if (!mame_stricmp(file_type, "prg"))
	{
		/* prg files */
	}
	else if (!mame_stricmp(file_type, "p00"))
	{
		/* p00 files */
		if (image_fread(image, buffer, sizeof(buffer)) != sizeof(buffer))
			goto error;
		if (memcmp(buffer, "C64File", sizeof(buffer)))
			goto error;
		image_fseek(image, 26, SEEK_SET);
		snapshot_size -= 26;
	}
	else
	{
		goto error;
	}

	image_fread(image, &address, 2);
	address = LITTLE_ENDIANIZE_INT16(address);
	snapshot_size -= 2;

	data = malloc(snapshot_size);
	if (!data)
		goto error;

	bytesread = image_fread(image, data, snapshot_size);
	if (bytesread != snapshot_size)
		goto error;

	for (i = 0; i < snapshot_size; i++)
		program_write_byte(address + i + offset, data[i]);

	cbm_sethiaddress(address + snapshot_size);
	free(data);
	return INIT_PASS;

error:
	if (data)
		free(data);
	return INIT_FAIL;
}
コード例 #2
0
ファイル: mekd2.c プロジェクト: dinkc64/mame
QUICKLOAD_LOAD_MEMBER( mekd2_state, mekd2_quik )
{
	static const char magic[] = "MEK6800D2";
	char buff[9];
	UINT16 addr, size;
	UINT8 ident, *RAM = memregion("maincpu")->base();

	image.fread(buff, sizeof (buff));
	if (memcmp(buff, magic, sizeof (buff)))
	{
		logerror("mekd2 rom load: magic '%s' not found\n", magic);
		return IMAGE_INIT_FAIL;
	}
	image.fread(&addr, 2);
	addr = LITTLE_ENDIANIZE_INT16(addr);
	image.fread(&size, 2);
	size = LITTLE_ENDIANIZE_INT16(size);
	image.fread(&ident, 1);
	logerror("mekd2 rom load: $%04X $%04X $%02X\n", addr, size, ident);
	while (size-- > 0)
		image.fread(&RAM[addr++], 1);

	return IMAGE_INIT_PASS;
}
コード例 #3
0
ファイル: homelab.c プロジェクト: kleopatra999/mess-svn
static QUICKLOAD_LOAD(homelab)
{
	address_space *space = image.device().machine().device("maincpu")->memory().space(AS_PROGRAM);
	int i=0;
	UINT8 ch;
	UINT16 quick_addr;
	UINT16 quick_length;
	UINT16 quick_end;
	UINT8 *quick_data;
	char pgmname[256];
	UINT16 args[2];
	int read_;

	quick_length = image.length();
	quick_data = (UINT8*)malloc(quick_length);
	if (!quick_data)
	{
		image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot open file");
		image.message(" Cannot open file");
		return IMAGE_INIT_FAIL;
	}

	read_ = image.fread( quick_data, quick_length);
	if (read_ != quick_length)
	{
		image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Cannot read the file");
		image.message(" Cannot read the file");
		return IMAGE_INIT_FAIL;
	}

	image.fseek(0x100, SEEK_SET);
	ch = image.fgetc();
	if (ch != 0xA5)
	{
		image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Invalid header");
		image.message(" Invalid header");
		return IMAGE_INIT_FAIL;
	}

	while((ch = image.fgetc()))
	{
		if (i >= (ARRAY_LENGTH(pgmname) - 1))
		{
			image.seterror(IMAGE_ERROR_INVALIDIMAGE, "File name too long");
			image.message(" File name too long");
			return IMAGE_INIT_FAIL;
		}

		pgmname[i] = ch;	/* build program name */
		i++;
	}

	pgmname[i] = '\0';	/* terminate string with a null */

	if (image.fread(args, sizeof(args)) != sizeof(args))
	{
		image.seterror(IMAGE_ERROR_INVALIDIMAGE, "Unexpected EOF while getting file size");
		image.message(" Unexpected EOF while getting file size");
		return IMAGE_INIT_FAIL;
	}

	quick_addr = LITTLE_ENDIANIZE_INT16(args[0]);
	quick_length = LITTLE_ENDIANIZE_INT16(args[1]);
	quick_end = quick_addr+quick_length-1;

	if (quick_end > 0x7fff)
	{
		image.seterror(IMAGE_ERROR_INVALIDIMAGE, "File too large");
		image.message(" File too large");
		return IMAGE_INIT_FAIL;
	}

	/* display a message about the loaded quickload */
	image.message(" %s\nsize=%04X : start=%04X : end=%04X",pgmname,quick_length,quick_addr,quick_end);

	for (i = 0; i < quick_length; i++)
	{
		int j = (quick_addr + i);
		if (image.fread(&ch, 1) != 1)
		{
			char message[256];
			snprintf(message, ARRAY_LENGTH(message), "%s: Unexpected EOF while writing byte to %04X", pgmname, (unsigned) j);
			image.seterror(IMAGE_ERROR_INVALIDIMAGE, message);
			image.message("%s: Unexpected EOF while writing byte to %04X", pgmname, (unsigned) j);
			return IMAGE_INIT_FAIL;
		}
		space->write_byte(j, ch);
	}

	return IMAGE_INIT_PASS;
}
コード例 #4
0
ファイル: samples.c プロジェクト: Paulodx/sdl-mame-wii
static int read_wav_sample(running_machine *machine, mame_file *f, loaded_sample *sample)
{
	unsigned long offset = 0;
	UINT32 length, rate, filesize;
	UINT16 bits, temp16;
	char buf[32];
	UINT32 sindex;

	/* read the core header and make sure it's a WAVE file */
	offset += mame_fread(f, buf, 4);
	if (offset < 4)
		return 0;
	if (memcmp(&buf[0], "RIFF", 4) != 0)
		return 0;

	/* get the total size */
	offset += mame_fread(f, &filesize, 4);
	if (offset < 8)
		return 0;
	filesize = LITTLE_ENDIANIZE_INT32(filesize);

	/* read the RIFF file type and make sure it's a WAVE file */
	offset += mame_fread(f, buf, 4);
	if (offset < 12)
		return 0;
	if (memcmp(&buf[0], "WAVE", 4) != 0)
		return 0;

	/* seek until we find a format tag */
	while (1)
	{
		offset += mame_fread(f, buf, 4);
		offset += mame_fread(f, &length, 4);
		length = LITTLE_ENDIANIZE_INT32(length);
		if (memcmp(&buf[0], "fmt ", 4) == 0)
			break;

		/* seek to the next block */
		mame_fseek(f, length, SEEK_CUR);
		offset += length;
		if (offset >= filesize)
			return 0;
	}

	/* read the format -- make sure it is PCM */
	offset += mame_fread(f, &temp16, 2);
	temp16 = LITTLE_ENDIANIZE_INT16(temp16);
	if (temp16 != 1)
		return 0;

	/* number of channels -- only mono is supported */
	offset += mame_fread(f, &temp16, 2);
	temp16 = LITTLE_ENDIANIZE_INT16(temp16);
	if (temp16 != 1)
		return 0;

	/* sample rate */
	offset += mame_fread(f, &rate, 4);
	rate = LITTLE_ENDIANIZE_INT32(rate);

	/* bytes/second and block alignment are ignored */
	offset += mame_fread(f, buf, 6);

	/* bits/sample */
	offset += mame_fread(f, &bits, 2);
	bits = LITTLE_ENDIANIZE_INT16(bits);
	if (bits != 8 && bits != 16)
		return 0;

	/* seek past any extra data */
	mame_fseek(f, length - 16, SEEK_CUR);
	offset += length - 16;

	/* seek until we find a data tag */
	while (1)
	{
		offset += mame_fread(f, buf, 4);
		offset += mame_fread(f, &length, 4);
		length = LITTLE_ENDIANIZE_INT32(length);
		if (memcmp(&buf[0], "data", 4) == 0)
			break;

		/* seek to the next block */
		mame_fseek(f, length, SEEK_CUR);
		offset += length;
		if (offset >= filesize)
			return 0;
	}

	/* if there was a 0 length data block, we're done */
	if (length == 0)
		return 0;

	/* fill in the sample data */
	sample->length = length;
	sample->frequency = rate;

	/* read the data in */
	if (bits == 8)
	{
		unsigned char *tempptr;
		int sindex;

		sample->data = auto_alloc_array(machine, INT16, length);
		mame_fread(f, sample->data, length);

		/* convert 8-bit data to signed samples */
		tempptr = (unsigned char *)sample->data;
		for (sindex = length - 1; sindex >= 0; sindex--)
			sample->data[sindex] = (INT8)(tempptr[sindex] ^ 0x80) * 256;
	}
	else
	{
		/* 16-bit data is fine as-is */
		sample->data = auto_alloc_array(machine, INT16, length/2);
		mame_fread(f, sample->data, length);
		sample->length /= 2;
		if (ENDIANNESS_NATIVE != ENDIANNESS_LITTLE)
			for (sindex = 0; sindex < sample->length; sindex++)
				sample->data[sindex] = LITTLE_ENDIANIZE_INT16(sample->data[sindex]);
	}
	return 1;
}
コード例 #5
0
ファイル: wavfile.c プロジェクト: Fulg/mame
static void put_leuint16(void *ptr, UINT16 value)
{
	value = LITTLE_ENDIANIZE_INT16(value);
	memcpy(ptr, &value, sizeof(value));
}
コード例 #6
0
ファイル: wavfile.c プロジェクト: Fulg/mame
static UINT16 get_leuint16(const void *ptr)
{
	UINT16 value;
	memcpy(&value, ptr, sizeof(value));
	return LITTLE_ENDIANIZE_INT16(value);
}
コード例 #7
0
ファイル: wavwrite.c プロジェクト: AltimorTASDK/shmupmametgm
wav_file *wav_open(const char *filename, int sample_rate, int channels)
{
	wav_file *wav;
	UINT32 bps, temp32;
	UINT16 align, temp16;

	/* allocate memory for the wav struct */
	wav = (wav_file *) osd_malloc(sizeof(struct _wav_file));
	if (!wav)
		return NULL;

	/* create the file */
	wav->file = fopen(filename, "wb");
	if (!wav->file)
	{
		osd_free(wav);
		return NULL;
	}

	/* write the 'RIFF' header */
	fwrite("RIFF", 1, 4, wav->file);

	/* write the total size */
	temp32 = 0;
	wav->total_offs = ftell(wav->file);
	fwrite(&temp32, 1, 4, wav->file);

	/* write the 'WAVE' type */
	fwrite("WAVE", 1, 4, wav->file);

	/* write the 'fmt ' tag */
	fwrite("fmt ", 1, 4, wav->file);

	/* write the format length */
	temp32 = LITTLE_ENDIANIZE_INT32(16);
	fwrite(&temp32, 1, 4, wav->file);

	/* write the format (PCM) */
	temp16 = LITTLE_ENDIANIZE_INT16(1);
	fwrite(&temp16, 1, 2, wav->file);

	/* write the channels */
	temp16 = LITTLE_ENDIANIZE_INT16(channels);
	fwrite(&temp16, 1, 2, wav->file);

	/* write the sample rate */
	temp32 = LITTLE_ENDIANIZE_INT32(sample_rate);
	fwrite(&temp32, 1, 4, wav->file);

	/* write the bytes/second */
	bps = sample_rate * 2 * channels;
	temp32 = LITTLE_ENDIANIZE_INT32(bps);
	fwrite(&temp32, 1, 4, wav->file);

	/* write the block align */
	align = 2 * channels;
	temp16 = LITTLE_ENDIANIZE_INT16(align);
	fwrite(&temp16, 1, 2, wav->file);

	/* write the bits/sample */
	temp16 = LITTLE_ENDIANIZE_INT16(16);
	fwrite(&temp16, 1, 2, wav->file);

	/* write the 'data' tag */
	fwrite("data", 1, 4, wav->file);

	/* write the data length */
	temp32 = 0;
	wav->data_offs = ftell(wav->file);
	fwrite(&temp32, 1, 4, wav->file);

	return wav;
}
コード例 #8
0
ファイル: d88_dsk.c プロジェクト: AreaScout/mame-libretro
bool d88_format::load(io_generic *io, UINT32 form_factor, floppy_image *image)
{
	UINT8 h[32];

	io_generic_read(io, h, 0, 32);

	int cell_count = 0;
	int track_count = 0;
	int head_count = 0;
	switch(h[0x1b]) {
	case 0x00:
		cell_count = 100000;
		track_count = 42;
		head_count = 2;
		image->set_variant(floppy_image::DSDD);
		break;

	case 0x10:
		cell_count = 100000;
		track_count = 82;
		head_count = 2;
		image->set_variant(floppy_image::DSQD);
		break;

	case 0x20:
		cell_count = form_factor == floppy_image::FF_35 ? 200000 : 166666;
		track_count = 82;
		head_count = 2;
		image->set_variant(floppy_image::DSHD);
		break;

	case 0x30:
		cell_count = 100000;
		track_count = 42;
		head_count = 1;
		image->set_variant(floppy_image::SSDD);
		break;

	case 0x40:
		cell_count = 100000;
		track_count = 82;
		head_count = 1;
		image->set_variant(floppy_image::SSQD);
		break;
	}

	if(!head_count)
		return false;

	UINT32 track_pos[164];
	io_generic_read(io, track_pos, 32, 164*4);

	for(int track=0; track < track_count; track++)
		for(int head=0; head < head_count; head++) {
			int pos = LITTLE_ENDIANIZE_INT32(track_pos[track * head_count + head]);
			if(!pos)
				continue;

			desc_pc_sector sects[256];
			UINT8 sect_data[65536];
			int sdatapos = 0;
			int sector_count = 1;
			for(int i=0; i<sector_count; i++) {
				UINT8 hs[16];
				io_generic_read(io, hs, pos, 16);
				pos += 16;

				UINT16 size = LITTLE_ENDIANIZE_INT16(*(UINT16 *)(hs+14));
				if(i == 0)
					sector_count = LITTLE_ENDIANIZE_INT16(*(UINT16 *)(hs+4));

				sects[i].track       = hs[0];
				sects[i].head        = hs[1];
				sects[i].sector      = hs[2];
				sects[i].size        = hs[3];
				sects[i].actual_size = size;
				sects[i].deleted     = hs[7] != 0;
				sects[i].bad_crc     = false;

				if(size) {
					sects[i].data    = sect_data + sdatapos;
					io_generic_read(io, sects[i].data, pos, size);
					pos += size;
					sdatapos += size;

				} else
					sects[i].data    = NULL;
			}

			build_pc_track_mfm(track, head, image, cell_count, sector_count, sects, calc_default_pc_gap3_size(form_factor, sects[0].actual_size));
		}

	return true;
}
コード例 #9
0
ファイル: svi_cas.c プロジェクト: BirchJD/xmame-0.103-RPi
static int svi_cas_image_readfile(imgtool_image *img, const char *fname, imgtool_stream *destf)
	{
	CAS_IMAGE *image=(CAS_IMAGE*)img;
	INT16 *wavdata;
	UINT16	temp16;
	UINT32	temp32;
	int wavlen, offset;

	if (mame_stricmp (fname, image->file_name) )
		return IMGTOOLERR_MODULENOTFOUND;

	wavdata = image->wavdata;
	wavlen = image->count;
    /* write the core header for a WAVE file */
	offset = stream_write(destf, "RIFF", 4);
    if( offset < 4 )
		return IMGTOOLERR_WRITEERROR;

	temp32 = LITTLE_ENDIANIZE_INT32(image->count * 2 + 0x24);
	offset += stream_write(destf, &temp32, 4);
    if( offset < 8 )
		return IMGTOOLERR_WRITEERROR;

	/* read the RIFF file type and make sure it's a WAVE file */
	offset += stream_write(destf, "WAVEfmt ", 8);
	if( offset < 16 )
		return IMGTOOLERR_WRITEERROR;

    /* size of the following 'fmt ' fields */
    offset += stream_write(destf, "\x10\x00\x00\x00", 4);
	if( offset < 20 )
		return IMGTOOLERR_WRITEERROR;

	/* format: PCM */
	temp16 = LITTLE_ENDIANIZE_INT16 (1);
	offset += stream_write(destf, &temp16, 2);
	if( offset < 22 )
		return IMGTOOLERR_WRITEERROR;

	/* channels: 1 (mono) */
	temp16 = LITTLE_ENDIANIZE_INT16 (1);
	offset += stream_write(destf, &temp16, 2);
	if( offset < 24 )
		return IMGTOOLERR_WRITEERROR;

	/* sample rate */
	temp32 = LITTLE_ENDIANIZE_INT32(22050);
	offset += stream_write(destf, &temp32, 4);
	if( offset < 24 )
		return IMGTOOLERR_WRITEERROR;

	/* byte rate */
	temp32 = LITTLE_ENDIANIZE_INT32(22050 * 2);
	offset += stream_write(destf, &temp32, 4);
	if( offset < 28 )
		return IMGTOOLERR_WRITEERROR;

	/* block align (size of one `sample') */
	temp16 = LITTLE_ENDIANIZE_INT16 (2);
	offset += stream_write(destf, &temp16, 2);
	if( offset < 30 )
		return IMGTOOLERR_WRITEERROR;

	/* block align */
	temp16 = LITTLE_ENDIANIZE_INT16 (16);
	offset += stream_write(destf, &temp16, 2);
	if( offset < 32 )
		return IMGTOOLERR_WRITEERROR;

	/* 'data' tag */
	offset += stream_write(destf, "data", 4);
	if( offset < 36 )
		return IMGTOOLERR_WRITEERROR;

	/* data size */
	temp32 = LITTLE_ENDIANIZE_INT32(image->count * 2);
	offset += stream_write(destf, &temp32, 4);
	if( offset < 40 )
		return IMGTOOLERR_WRITEERROR;

	if (stream_write(destf, wavdata, (image->count*2))!=(image->count*2))
		return IMGTOOLERR_WRITEERROR;

	return 0;
	}
コード例 #10
0
ファイル: chdcd.c プロジェクト: Ilgrim/MAMEHub
/*-------------------------------------------------
    parse_wav_sample - takes a .WAV file, verifies
    that the file is 16 bits, and returns the
    length in bytes of the data and the offset in
    bytes to where the data starts in the file.
-------------------------------------------------*/
static UINT32 parse_wav_sample(const char *filename, UINT32 *dataoffs)
{
	unsigned long offset = 0;
	UINT32 length, rate, filesize;
	UINT16 bits, temp16;
	char buf[32];
	osd_file *file;
	file_error filerr;
	UINT64 fsize = 0;
	UINT32 actual;

	filerr = osd_open(filename, OPEN_FLAG_READ, &file, &fsize);
	if (filerr != FILERR_NONE)
	{
		printf("ERROR: could not open (%s)\n", filename);
		return 0;
	}

	/* read the core header and make sure it's a WAVE file */
	osd_read(file, buf, 0, 4, &actual);
	offset += actual;
	if (offset < 4)
	{
		osd_close(file);
		printf("ERROR: unexpected RIFF offset %lu (%s)\n", offset, filename);
		return 0;
	}
	if (memcmp(&buf[0], "RIFF", 4) != 0)
	{
		osd_close(file);
		printf("ERROR: could not find RIFF header (%s)\n", filename);
		return 0;
	}

	/* get the total size */
	osd_read(file, &filesize, offset, 4, &actual);
	offset += actual;
	if (offset < 8)
	{
		osd_close(file);
		printf("ERROR: unexpected size offset %lu (%s)\n", offset, filename);
		return 0;
	}
	filesize = LITTLE_ENDIANIZE_INT32(filesize);

	/* read the RIFF file type and make sure it's a WAVE file */
	osd_read(file, buf, offset, 4, &actual);
	offset += actual;
	if (offset < 12)
	{
		osd_close(file);
		printf("ERROR: unexpected WAVE offset %lu (%s)\n", offset, filename);
		return 0;
	}
	if (memcmp(&buf[0], "WAVE", 4) != 0)
	{
		osd_close(file);
		printf("ERROR: could not find WAVE header (%s)\n", filename);
		return 0;
	}

	/* seek until we find a format tag */
	while (1)
	{
		osd_read(file, buf, offset, 4, &actual);
		offset += actual;
		osd_read(file, &length, offset, 4, &actual);
		offset += actual;
		length = LITTLE_ENDIANIZE_INT32(length);
		if (memcmp(&buf[0], "fmt ", 4) == 0)
			break;

		/* seek to the next block */
		offset += length;
		if (offset >= filesize)
		{
			osd_close(file);
			printf("ERROR: could not find fmt tag (%s)\n", filename);
			return 0;
		}
	}

	/* read the format -- make sure it is PCM */
	osd_read(file, &temp16, offset, 2, &actual);
	offset += actual;
	temp16 = LITTLE_ENDIANIZE_INT16(temp16);
	if (temp16 != 1)
	{
		osd_close(file);
		printf("ERROR: unsupported format %u - only PCM is supported (%s)\n", temp16, filename);
		return 0;
	}

	/* number of channels -- only stereo is supported */
	osd_read(file, &temp16, offset, 2, &actual);
	offset += actual;
	temp16 = LITTLE_ENDIANIZE_INT16(temp16);
	if (temp16 != 2)
	{
		osd_close(file);
		printf("ERROR: unsupported number of channels %u - only stereo is supported (%s)\n", temp16, filename);
		return 0;
	}

	/* sample rate */
	osd_read(file, &rate, offset, 4, &actual);
	offset += actual;
	rate = LITTLE_ENDIANIZE_INT32(rate);
	if (rate != 44100)
	{
		osd_close(file);
		printf("ERROR: unsupported samplerate %u - only 44100 is supported (%s)\n", rate, filename);
		return 0;
	}

	/* bytes/second and block alignment are ignored */
	osd_read(file, buf, offset, 6, &actual);
	offset += actual;

	/* bits/sample */
	osd_read(file, &bits, offset, 2, &actual);
	offset += actual;
	if (bits != 16)
	{
		osd_close(file);
		printf("ERROR: unsupported bits/sample %u - only 16 is supported (%s)\n", bits, filename);
		return 0;
	}

	/* seek past any extra data */
	offset += length - 16;

	/* seek until we find a data tag */
	while (1)
	{
		osd_read(file, buf, offset, 4, &actual);
		offset += actual;
		osd_read(file, &length, offset, 4, &actual);
		offset += actual;
		length = LITTLE_ENDIANIZE_INT32(length);
		if (memcmp(&buf[0], "data", 4) == 0)
			break;

		/* seek to the next block */
		offset += length;
		if (offset >= filesize)
		{
			osd_close(file);
			printf("ERROR: could not find data tag (%s)\n", filename);
			return 0;
		}
	}

	osd_close(file);

	/* if there was a 0 length data block, we're done */
	if (length == 0)
	{
		printf("ERROR: empty data block (%s)\n", filename);
		return 0;
	}

	*dataoffs = offset;

	return length;
}
コード例 #11
0
ファイル: cbm.c プロジェクト: broftkd/historic-mess
static DEVICE_LOAD(cbm_rom)
{
	int i;
	int size, j, read_;
	const char *filetype;
	int adr = 0;
	const struct IODevice *dev;

	for (i=0; (i<sizeof(cbm_rom) / sizeof(cbm_rom[0])) && (cbm_rom[i].size!=0); i++)
		;
	if (i >= sizeof(cbm_rom) / sizeof(cbm_rom[0]))
		return INIT_FAIL;

	dev = cbm_rom_find_device();

	size = image_length(image);

	filetype = image_filetype(image);
	if (filetype && !mame_stricmp(filetype, "prg"))
	{
		unsigned short in;

		image_fread (image, &in, 2);
		in = LITTLE_ENDIANIZE_INT16(in);
		logerror("rom prg %.4x\n", in);
		size -= 2;

		logerror("loading rom %s at %.4x size:%.4x\n", image_filename(image), in, size);

		cbm_rom[i].chip = (UINT8 *) image_malloc(image, size);
		if (!cbm_rom[i].chip)
			return INIT_FAIL;

		cbm_rom[i].addr=in;
		cbm_rom[i].size=size;
		read_ = image_fread (image, cbm_rom[i].chip, size);
		if (read_ != size)
			return INIT_FAIL;
	}
	else if (filetype && !mame_stricmp (filetype, "crt"))
	{
		unsigned short in;
		image_fseek(image, 0x18, SEEK_SET);
		image_fread(image, &cbm_c64_exrom, 1);
		image_fread(image, &cbm_c64_game, 1);
		image_fseek(image, 64, SEEK_SET);
		j = 64;

		logerror("loading rom %s size:%.4x\n", image_filename(image), size);

		while (j < size)
		{
			unsigned short segsize;
			unsigned char buffer[10], number;

			image_fread(image, buffer, 6);
			image_fread(image, &segsize, 2);
			segsize = BIG_ENDIANIZE_INT16(segsize);
			image_fread(image, buffer + 6, 3);
			image_fread(image, &number, 1);
			image_fread(image, &adr, 2);
			adr = BIG_ENDIANIZE_INT16(adr);
			image_fread(image, &in, 2);
			in = BIG_ENDIANIZE_INT16(in);
			logerror("%.4s %.2x %.2x %.4x %.2x %.2x %.2x %.2x %.4x:%.4x\n",
				buffer, buffer[4], buffer[5], segsize,
				buffer[6], buffer[7], buffer[8], number,
				adr, in);
			logerror("loading chip at %.4x size:%.4x\n", adr, in);

			cbm_rom[i].chip = (UINT8*) image_malloc(image, size);
			if (!cbm_rom[i].chip)
				return INIT_FAIL;

			cbm_rom[i].addr=adr;
			cbm_rom[i].size=in;
			read_ = image_fread(image, cbm_rom[i].chip, in);
			i++;
			if (read_ != in)
				return INIT_FAIL;

			j += 16 + in;
		}
	}
	else if (filetype)
	{
		if (mame_stricmp(filetype, "lo") == 0)
			adr = CBM_ROM_ADDR_LO;
		else if (mame_stricmp (filetype, "hi") == 0)
			adr = CBM_ROM_ADDR_HI;
		else if (mame_stricmp (filetype, "10") == 0)
			adr = 0x1000;
		else if (mame_stricmp (filetype, "20") == 0)
			adr = 0x2000;
		else if (mame_stricmp (filetype, "30") == 0)
			adr = 0x3000;
		else if (mame_stricmp (filetype, "40") == 0)
			adr = 0x4000;
		else if (mame_stricmp (filetype, "50") == 0)
			adr = 0x5000;
		else if (mame_stricmp (filetype, "60") == 0)
			adr = 0x6000;
		else if (mame_stricmp (filetype, "70") == 0)
			adr = 0x7000;
		else if (mame_stricmp (filetype, "80") == 0)
			adr = 0x8000;
		else if (mame_stricmp (filetype, "90") == 0)
			adr = 0x9000;
		else if (mame_stricmp (filetype, "a0") == 0)
			adr = 0xa000;
		else if (mame_stricmp (filetype, "b0") == 0)
			adr = 0xb000;
		else if (mame_stricmp (filetype, "e0") == 0)
			adr = 0xe000;
		else if (mame_stricmp (filetype, "f0") == 0)
			adr = 0xf000;
		else
			adr = CBM_ROM_ADDR_UNKNOWN;

		logerror("loading %s rom at %.4x size:%.4x\n",
				image_filename(image), adr, size);

		cbm_rom[i].chip = (UINT8*) image_malloc(image, size);
		if (!cbm_rom[i].chip)
			return INIT_FAIL;

		cbm_rom[i].addr=adr;
		cbm_rom[i].size=size;
		read_ = image_fread(image, cbm_rom[i].chip, size);

		if (read_ != size)
			return INIT_FAIL;
	}
	return INIT_PASS;
}
コード例 #12
0
ファイル: d88_dsk.c プロジェクト: pinchyCZN/mameppk
bool d88_format::load(io_generic *io, UINT32 form_factor, floppy_image *image)
{
	UINT8 h[32];

	io_generic_read(io, h, 0, 32);

	int cell_count = 0;
	int track_count = 0;
	int head_count = 0;
	switch(h[0x1b]) {
	case 0x00:
		cell_count = 100000;
		track_count = 42;
		head_count = 2;
		image->set_variant(floppy_image::DSDD);
		break;

	case 0x10:
		cell_count = 100000;
		track_count = 82;
		head_count = 2;
		image->set_variant(floppy_image::DSQD);
		break;

	case 0x20:
		cell_count = form_factor == floppy_image::FF_35 ? 200000 : 166666;
		track_count = 82;
		head_count = 2;
		image->set_variant(floppy_image::DSHD);
		break;

	case 0x30:
		cell_count = 100000;
		track_count = 42;
		head_count = 1;
		image->set_variant(floppy_image::SSDD);
		break;

	case 0x40:
		cell_count = 100000;
		track_count = 82;
		head_count = 1;
		image->set_variant(floppy_image::SSQD);
		break;
	}

	if(!head_count)
		return false;

	UINT32 track_pos[164];
	io_generic_read(io, track_pos, 32, 164*4);

	for(int track=0; track < track_count; track++)
		for(int head=0; head < head_count; head++) {
			int pos = LITTLE_ENDIANIZE_INT32(track_pos[track * head_count + head]);
			if(!pos)
				continue;

			UINT32 track_data[210000];
			UINT8 sect_data[65536];
			int tpos = 0;

			// gap 4a , IAM and gap 1
			for(int i=0; i<80; i++) mfm_w(track_data, tpos, 8, 0x4e);
			for(int i=0; i<12; i++) mfm_w(track_data, tpos, 8, 0x00);
			for(int i=0; i< 3; i++) raw_w(track_data, tpos, 16, 0x5224);
			mfm_w(track_data, tpos, 8, 0xfc);
			for(int i=0; i<50; i++) mfm_w(track_data, tpos, 8, 0x4e);

			// Updated after reading the first header
			int sector_count = 1;
			int gap3 = 84;
			for(int i=0; i<sector_count; i++) {
				UINT8 hs[16];
				io_generic_read(io, hs, pos, 16);
				UINT16 size = LITTLE_ENDIANIZE_INT16(*(UINT16 *)(hs+14));
				io_generic_read(io, sect_data, pos+16, size);
				pos += 16+size;

				if(i == 0) {
					sector_count = LITTLE_ENDIANIZE_INT16(*(UINT16 *)(hs+4));
					if(size < 512)
						gap3 = form_factor == floppy_image::FF_35 ? 54 : 50;
					else
						gap3 = form_factor == floppy_image::FF_35 ? 84 : 80;
				}

				int cpos;
				UINT16 crc;
				// sync and IDAM and gap 2
				for(int j=0; j<12; j++) mfm_w(track_data, tpos, 8, 0x00);
				cpos = tpos;
				for(int j=0; j< 3; j++) raw_w(track_data, tpos, 16, 0x4489);
				mfm_w(track_data, tpos, 8, 0xfe);
				mfm_w(track_data, tpos, 8, hs[0]);
				mfm_w(track_data, tpos, 8, hs[1]);
				mfm_w(track_data, tpos, 8, hs[2]);
				mfm_w(track_data, tpos, 8, hs[3]);
				crc = calc_crc_ccitt(track_data, cpos, tpos);
				mfm_w(track_data, tpos, 16, crc);
				for(int j=0; j<22; j++) mfm_w(track_data, tpos, 8, 0x4e);

				// sync, DAM, data and gap 3
				for(int j=0; j<12; j++) mfm_w(track_data, tpos, 8, 0x00);
				cpos = tpos;
				for(int j=0; j< 3; j++) raw_w(track_data, tpos, 16, 0x4489);
				mfm_w(track_data, tpos, 8, 0xfb);
				for(int j=0; j<size; j++) mfm_w(track_data, tpos, 8, sect_data[j]);
				crc = calc_crc_ccitt(track_data, cpos, tpos);
				mfm_w(track_data, tpos, 16, crc);
				for(int j=0; j<gap3; j++) mfm_w(track_data, tpos, 8, 0x4e);
			}

			// Gap 4b

			if(tpos > cell_count)
				throw emu_fatalerror("d88_format: Incorrect layout on track %d head %d, expected_size=%d, current_size=%d", track, head, cell_count, tpos);
			while(tpos < cell_count-15) mfm_w(track_data, tpos, 8, 0x4e);
			raw_w(track_data, tpos, cell_count-tpos, 0x9254 >> (16+tpos-cell_count));

			generate_track_from_levels(track, head, track_data, cell_count, 0, image);
		}

	return true;
}
コード例 #13
0
ファイル: imgwave.c プロジェクト: kkalmaz/psmame
int imgwave_init(const imgtool_module *mod, imgtool_stream *f, imgtool_image **outimg)
{
	int err;
	waveimage *wimg;
	struct WaveExtra *extra;
	char buf[4];
	UINT16 format, channels, resolution;
	UINT32 filelen, blocklen, frequency;
	int offset = 0;

	offset += stream_read(f, buf, sizeof(buf));
	if (offset < 4)
		goto initalt;
	if (memcmp(buf, "RIFF", 4))
		goto initalt;

	offset += stream_read(f, &filelen, sizeof(filelen));
	if (offset < 8)
		goto initalt;
	filelen = LITTLE_ENDIANIZE_INT32(filelen);

	offset += stream_read(f, buf, sizeof(buf));
	if (offset < 12)
		goto initalt;
	if (memcmp(buf, "WAVE", 4))
		goto initalt;

	err = find_wavtag(f, filelen, "fmt ", &offset, &blocklen);
	if (err)
		return err;

	offset += stream_read(f, &format, sizeof(format));
	format = LITTLE_ENDIANIZE_INT16(format);
	if (format != 1)
		return IMGTOOLERR_CORRUPTIMAGE;

	offset += stream_read(f, &channels, sizeof(channels));
	channels = LITTLE_ENDIANIZE_INT16(channels);
	if (channels != 1 && channels != 2)
		return IMGTOOLERR_CORRUPTIMAGE;

	offset += stream_read(f, &frequency, sizeof(frequency));
	frequency = LITTLE_ENDIANIZE_INT32(frequency);

	stream_seek(f, 6, SEEK_CUR);

	offset += stream_read(f, &resolution, sizeof(resolution));
	resolution = LITTLE_ENDIANIZE_INT16(resolution);
	if ((resolution != 8) && (resolution != 16))
		return IMGTOOLERR_CORRUPTIMAGE;

	stream_seek(f, blocklen - 16, SEEK_CUR);

	err = find_wavtag(f, filelen, "data", &offset, &blocklen);
	if (err)
		return err;

	wimg = malloc(sizeof(waveimage));
	if (!wimg)
		return IMGTOOLERR_OUTOFMEMORY;

	wimg->base.module = mod;
	wimg->f = f;
	wimg->basepos = wimg->curpos = offset;
	wimg->length = blocklen;
	wimg->channels = channels;
	wimg->frequency = frequency;
	wimg->resolution = resolution;
	wimg->lastsample = 0;
	*outimg = &wimg->base;
	return 0;

initalt:
	extra = (struct WaveExtra *) mod->extra;
	if (!extra->initalt)
		return IMGTOOLERR_CORRUPTIMAGE;

	stream_seek(f, 0, SEEK_SET);

	wimg = malloc(sizeof(waveimage));
	if (!wimg)
		return IMGTOOLERR_OUTOFMEMORY;


	err = extra->initalt(f, &wimg->f, &wimg->basepos, &wimg->length,
		&wimg->channels, &wimg->frequency, &wimg->resolution);
	if (err) {
		free(wimg);
		return err;
	}

	wimg->base.module = mod;
	wimg->curpos = wimg->basepos;
	wimg->lastsample = 0;
	stream_seek(wimg->f, wimg->basepos, SEEK_SET);
	*outimg = &wimg->base;

	if (wimg->f != f)
		stream_close(f);

	return 0;
}