Пример #1
0
int core_fgetc(core_file *file)
{
	int result;

	/* refresh buffer, if necessary */
	if (file->back_char_head == file->back_char_tail)
	{
		utf16_char utf16_buffer[UTF16_CHAR_MAX];
		char utf8_buffer[UTF8_CHAR_MAX];
		char default_buffer[16];
		unicode_char uchar = (unicode_char) ~0;
		int readlen, charlen;

		/* do we need to check the byte order marks? */
		if (file->offset == 0)
		{
			UINT8 bom[4];
			int pos = 0;

			if (core_fread(file, bom, 4) == 4)
			{
				if (bom[0] == 0xef && bom[1] == 0xbb && bom[2] == 0xbf)
				{
					file->text_type = TFT_UTF8;
					pos = 3;
				}
				else if (bom[0] == 0x00 && bom[1] == 0x00 && bom[2] == 0xfe && bom[3] == 0xff)
				{
					file->text_type = TFT_UTF32BE;
					pos = 4;
				}
				else if (bom[0] == 0xff && bom[1] == 0xfe && bom[2] == 0x00 && bom[3] == 0x00)
				{
					file->text_type = TFT_UTF32LE;
					pos = 4;
				}
				else if (bom[0] == 0xfe && bom[1] == 0xff)
				{
					file->text_type = TFT_UTF16BE;
					pos = 2;
				}
				else if (bom[0] == 0xff && bom[1] == 0xfe)
				{
					file->text_type = TFT_UTF16LE;
					pos = 2;
				}
				else
				{
					file->text_type = TFT_OSD;
					pos = 0;
				}
			}
			core_fseek(file, pos, SEEK_SET);
		}

		/* fetch the next character */
		switch (file->text_type)
		{
			default:
			case TFT_OSD:
				readlen = core_fread(file, default_buffer, sizeof(default_buffer));
				if (readlen > 0)
				{
					charlen = osd_uchar_from_osdchar(&uchar, default_buffer, readlen / sizeof(default_buffer[0]));
					core_fseek(file, (INT64) (charlen * sizeof(default_buffer[0])) - readlen, SEEK_CUR);
				}
				break;

			case TFT_UTF8:
				readlen = core_fread(file, utf8_buffer, sizeof(utf8_buffer));
				if (readlen > 0)
				{
					charlen = uchar_from_utf8(&uchar, utf8_buffer, readlen / sizeof(utf8_buffer[0]));
					core_fseek(file, (INT64) (charlen * sizeof(utf8_buffer[0])) - readlen, SEEK_CUR);
				}
				break;

			case TFT_UTF16BE:
				readlen = core_fread(file, utf16_buffer, sizeof(utf16_buffer));
				if (readlen > 0)
				{
					charlen = uchar_from_utf16be(&uchar, utf16_buffer, readlen / sizeof(utf16_buffer[0]));
					core_fseek(file, (INT64) (charlen * sizeof(utf16_buffer[0])) - readlen, SEEK_CUR);
				}
				break;

			case TFT_UTF16LE:
				readlen = core_fread(file, utf16_buffer, sizeof(utf16_buffer));
				if (readlen > 0)
				{
					charlen = uchar_from_utf16le(&uchar, utf16_buffer, readlen / sizeof(utf16_buffer[0]));
					core_fseek(file, (INT64) (charlen * sizeof(utf16_buffer[0])) - readlen, SEEK_CUR);
				}
				break;

			case TFT_UTF32BE:
				if (core_fread(file, &uchar, sizeof(uchar)) == sizeof(uchar))
					uchar = BIG_ENDIANIZE_INT32(uchar);
				break;

			case TFT_UTF32LE:
				if (core_fread(file, &uchar, sizeof(uchar)) == sizeof(uchar))
					uchar = LITTLE_ENDIANIZE_INT32(uchar);
				break;
		}

		if (uchar != ~0)
		{
			/* place the new character in the ring buffer */
			file->back_char_head = 0;
			file->back_char_tail = utf8_from_uchar(file->back_chars, ARRAY_LENGTH(file->back_chars), uchar);
/*          assert(file->back_char_tail != -1);*/
		}
	}

	/* now read from the ring buffer */
	if (file->back_char_head != file->back_char_tail)
	{
		result = file->back_chars[file->back_char_head++];
		file->back_char_head %= ARRAY_LENGTH(file->back_chars);
	}
	else
		result = EOF;

	return result;
}
Пример #2
0
static int vmsx_tap_image_read_data (TAP_IMAGE *image, char *chunk, unsigned char **pcas, int *psize)
	{
	unsigned int caspos, pos = 0, found = 0, offset, size, tappos;
	UINT32 tapblock;
	unsigned char *p, *pmem;

	size = image->size;
	pmem = image->data;

    while ( (pos + 8) < size)
		{
		offset = *((UINT32*)(pmem + pos + 4));
		offset = LITTLE_ENDIANIZE_INT32 (offset);
		if (memcmp (pmem + pos, "LIST", 4) )
			{
			if (offset & 1) offset++;
			pos += offset + 8;
			continue;
			}

		if (memcmp (pmem + pos + 8, "TAPE", 4) )
			return IMGTOOLERR_CORRUPTIMAGE;

		pos += 12;
		offset -= 8;
		if ( (pos + offset) > size)
			return IMGTOOLERR_CORRUPTIMAGE;

		pmem += pos;
		size = offset;
		found = 1;
		break;
		}

    if (!found)
		return IMGTOOLERR_CORRUPTIMAGE;

	/* OK we've got the right data chunk. Now we can start looking for
		the blocks */
	pos = 0; 
	while ( (pos + 8) < size)
		{
		offset = *((UINT32*)(pmem + pos + 4));
		offset = LITTLE_ENDIANIZE_INT32 (offset);
		if (memcmp (pmem + pos, chunk, 4) )
			{
			if (offset & 1) offset++;
			pos += offset + 8;
			continue;
			}

		pos += 8;
		caspos = tappos = 0;
		p = malloc (offset * 2);
		if (!p) return IMGTOOLERR_OUTOFMEMORY;

		while ( (tappos + 4) <= offset)
			{
			tapblock = *((UINT32*)(pmem + pos + tappos));
			tappos += 4;
			tapblock = LITTLE_ENDIANIZE_INT32 (tapblock);
			if (tapblock == 0xffffffff) break;
			memcpy (p + caspos, CasHeader, 8); 
			caspos += 8;
			memcpy (p + caspos, pmem + pos + tappos, tapblock); 
			caspos += tapblock;
			tappos += tapblock;
			}


		*psize = caspos;
		*pcas = p;
	
		return 0;
		}

	return IMGTOOLERR_CORRUPTIMAGE;
	}
Пример #3
0
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;
}
Пример #4
0
static UINT32 get_leuint32(const void *ptr)
{
	UINT32 value;
	memcpy(&value, ptr, sizeof(value));
	return LITTLE_ENDIANIZE_INT32(value);
}
Пример #5
0
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;
}
Пример #6
0
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;
}
Пример #7
0
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 *) malloc(sizeof(struct _wav_file));
	if (!wav)
		return NULL;

	/* create the file */
	wav->file = fopen(filename, "wb");
	if (!wav->file)
	{
		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
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;
}
Пример #9
0
/*-------------------------------------------------
    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;
	bits = LITTLE_ENDIANIZE_INT16(bits);
	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;
}
Пример #10
0
static void put_leuint32(void *ptr, UINT32 value)
{
	value = LITTLE_ENDIANIZE_INT32(value);
	memcpy(ptr, &value, sizeof(value));
}
Пример #11
0
bool fdd_format::load(io_generic *io, UINT32 form_factor, floppy_image *image)
{
	UINT8 hsec[0x0c];

	// sector map
	UINT8 num_secs[160];
	UINT8 tracks[160 * 26];
	UINT8 heads[160 * 26];
	UINT8 secs[160 * 26];
	UINT8 fill_vals[160 * 26];
	UINT32 sec_offs[160 * 26];
	UINT8 sec_sizes[160 * 26];

	int pos = 0xdc;

	for (int track = 0; track < 160; track++)
	{
		int curr_num_sec = 0, curr_track_size = 0;
		for (int sect = 0; sect < 26; sect++)
		{
			// read sector map for this sector
			io_generic_read(io, hsec, pos, 0x0c);
			pos += 0x0c;

			if (hsec[0] == 0xff)    // unformatted/unused sector
				continue;

			tracks[(track * 26) + sect] = hsec[0];
			heads[(track * 26) + sect] = hsec[1];
			secs[(track * 26) + sect] = hsec[2];
			sec_sizes[(track * 26) + sect] = hsec[3];
			fill_vals[(track * 26) + sect] = hsec[4];
			sec_offs[(track * 26) + sect] = LITTLE_ENDIANIZE_INT32(*(UINT32 *)(hsec + 0x08));

			curr_track_size += (128 << hsec[3]);
			curr_num_sec++;
		}
		num_secs[track] = curr_num_sec;
	}

	int cell_count = form_factor == floppy_image::FF_35 ? 200000 : 166666;
	desc_pc_sector sects[256];
	UINT8 sect_data[65536];
	int cur_sec_map = 0, sector_size;

	for (int track = 0; track < 160; track++)
	{
		int cur_pos = 0;
		for (int i = 0; i < num_secs[track]; i++)
		{
			cur_sec_map = track * 26 + i;
			sector_size = 128 << sec_sizes[cur_sec_map];

			if (sec_offs[cur_sec_map] == 0xffffffff)
				memset(sect_data + cur_pos, fill_vals[cur_sec_map], sector_size);
			else
				io_generic_read(io, sect_data + cur_pos, sec_offs[cur_sec_map], sector_size);

			sects[i].track       = tracks[cur_sec_map];
			sects[i].head        = heads[cur_sec_map];
			sects[i].sector      = secs[cur_sec_map];
			sects[i].size        = sec_sizes[cur_sec_map];
			sects[i].actual_size = sector_size;
			sects[i].deleted     = false;
			sects[i].bad_crc     = false;
			sects[i].data        = sect_data + cur_pos;
			cur_pos += sector_size;
		}

		build_pc_track_mfm(track / 2, track % 2, image, cell_count, num_secs[track], sects, calc_default_pc_gap3_size(form_factor, (128 << sec_sizes[track * 26])));
	}

	return true;
}