Пример #1
0
static floperr_t put_bml3_dirent(imgtool_image *f, int index_loc, const struct bml3_dirent *ent)
{
	floperr_t err;
	UINT8 head, track, sector, offset;
	UINT8 buf[32];
	bml3_diskinfo *info = bml3_get_diskinfo(f);
	if (index_loc >= max_dirents(f))
		return (floperr_t)IMGTOOLERR_FILENOTFOUND;
	dirent_location(f, index_loc, &head, &track, &sector, &offset);
	memset(buf, 0, sizeof(buf));
	switch (info->variant) {
	case 0:
		memcpy(&buf[0], &ent->fname, 8);
		buf[11] = ent->ftype;
		buf[12] = ent->asciiflag;
		buf[14] = ent->first_granule;
		break;
	case 1:
		memcpy(&buf[0], &ent->fname, 8);
		memcpy(&buf[8], &ent->fext, 3);
		buf[11] = ent->ftype;
		buf[12] = ent->asciiflag;
		buf[13] = ent->first_granule;
		buf[14] = ent->lastsectorbytes >> 8;
		buf[15] = ent->lastsectorbytes & 0xff;
		break;
	default:
		return FLOPPY_ERROR_INVALIDIMAGE;
	}
	err = floppy_write_sector(imgtool_floppy(f), head, track, sector, offset, (void *) buf, sizeof(buf), 0); /* TODO: pass ddam argument from imgtool */
	return err;
}
Пример #2
0
static imgtoolerr_t imgtool_floppy_transfer_sector_tofrom_stream(imgtool_image *img, int head, int track, int sector, int offset, size_t length, imgtool_stream *f, int direction)
{
	floperr_t err;
	floppy_image_legacy *floppy;
	dynamic_buffer buffer;

	floppy = imgtool_floppy(img);

	buffer.resize(length);

	if (direction)
	{
		err = floppy_read_sector(floppy, head, track, sector, offset, buffer, length);
		if (err)
			goto done;
		stream_write(f, buffer, length);
	}
	else
	{
		stream_read(f, buffer, length);
		err = floppy_write_sector(floppy, head, track, sector, offset, buffer, length, 0);  /* TODO: pass ddam argument from imgtool */
		if (err)
			goto done;
	}

	err = FLOPPY_ERROR_SUCCESS;

done:
	return imgtool_floppy_error(err);
}
Пример #3
0
floperr_t floppy_clear_sector(floppy_image *floppy, int head, int track, int sector, UINT8 data)
{
    floperr_t err;
    UINT32 length;
    UINT8 *buffer = NULL;

    err = floppy_get_sector_length(floppy, head, track, sector, &length);
    if (err)
        goto done;

    buffer = malloc(length);
    if (err)
    {
        err = FLOPPY_ERROR_OUTOFMEMORY;
        goto done;
    }

    memset(buffer, data, length);

    err = floppy_write_sector(floppy, head, track, sector, 0, buffer, length);
    if (err)
        goto done;

done:
    if (buffer)
        free(buffer);
    return err;
}
Пример #4
0
void floppy_write(uint8_t * buf, size_t count, int offset) {
	int offset_sector = offset / FLOPPY_SECTOR_SIZE;
	int offset_in_sector = offset % FLOPPY_SECTOR_SIZE;
	uint32_t cylinder;
	uint32_t head;
	uint32_t sector;
	size_t c;
	char buffer[FLOPPY_SECTOR_SIZE];

	while (count) {

		cylinder = offset_sector / (FLOPPY_SECTORS_PER_TRACK * FLOPPY_NB_HEADS);
		head    = (offset_sector % (FLOPPY_SECTORS_PER_TRACK * FLOPPY_NB_HEADS)) / (FLOPPY_SECTORS_PER_TRACK);
		sector  = (offset_sector % (FLOPPY_SECTORS_PER_TRACK * FLOPPY_NB_HEADS)) % (FLOPPY_SECTORS_PER_TRACK);

		floppy_read_sector(cylinder, head, sector, buffer);
		c = FLOPPY_SECTOR_SIZE - offset_in_sector;
		if (count <= c) {
			memcpy(buffer + offset_in_sector, buf, count);
			count = 0;
		} else {
			memcpy(buffer + offset_in_sector, buf, c);
			count -= c;
			buf += c;
			offset_in_sector = 0;
			offset_sector++;
		}
		floppy_write_sector(cylinder, head, sector, buffer);
	}
}
Пример #5
0
static imgtoolerr_t imgtool_floppy_write_sector(imgtool_image *image, UINT32 track, UINT32 head, UINT32 sector, const void *buffer, size_t len, int ddam)
{
	floperr_t ferr;

	ferr = floppy_write_sector(imgtool_floppy(image), head, track, sector, 0, buffer, len, ddam);
	if (ferr)
		return imgtool_floppy_error(ferr);

	return IMGTOOLERR_SUCCESS;
}
Пример #6
0
static imgtoolerr_t os9_write_lsn(imgtool_image *img, UINT32 lsn, int offset, const void *buffer, size_t buffer_len)
{
	imgtoolerr_t err;
	floperr_t ferr;
	UINT32 head, track, sector;

	err = os9_locate_lsn(img, lsn, &head, &track, &sector);
	if (err)
		return err;

	ferr = floppy_write_sector(imgtool_floppy(img), head, track, sector, offset, buffer, buffer_len, 0);    /* TODO: pass ddam argument from imgtool */
	if (ferr)
		return imgtool_floppy_error(ferr);

	return IMGTOOLERR_SUCCESS;
}
Пример #7
0
/* write data to sector */
static imgtoolerr_t vzdos_write_sector_data(imgtool_image *img, int track, int sector, UINT8 *data)
{
	int ret, data_start;
	UINT8 buffer[DATA_SIZE + 4]; /* data + checksum */

	ret = vzdos_get_data_start(img, track, sector, &data_start);
	if (ret) return (imgtoolerr_t)ret;

	memcpy(buffer, data, DATA_SIZE + 2);
	place_integer_le(buffer, DATA_SIZE + 2, 2, chksum16(data, DATA_SIZE + 2));

	ret = floppy_write_sector(imgtool_floppy(img), 0, track, sector_order[sector], data_start, buffer, sizeof(buffer), 0);	/* TODO: pass ddam argument from imgtool */
	if (ret) return (imgtoolerr_t)ret;

	return IMGTOOLERR_SUCCESS;
}
Пример #8
0
static imgtoolerr_t vzdos_write_formatted_sector(imgtool_image *img, int track, int sector)
{
	int ret;
	UINT8 sector_data[DATA_SIZE + 4 + 24];

	static const UINT8 sector_header[24] = {
		0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0xFE, 0xE7,
		0x18, 0xC3, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80,
		0x80, 0x80, 0x80, 0x00, 0xC3, 0x18, 0xE7, 0xFE
	};

	memset(sector_data, 0x00, sizeof(sector_data));
	memcpy(sector_data, sector_header, sizeof(sector_header));

	sector_data[10] = (UINT8) track;			/* current track */
	sector_data[11] = (UINT8) sector;			/* current sector */
	sector_data[12] = (UINT8) track + sector;	/* checksum-8 */

	ret = floppy_write_sector(imgtool_floppy(img), 0, track, sector_order[sector], 0, sector_data, sizeof(sector_data), 0);	/* TODO: pass ddam argument from imgtool */
	if (ret) return (imgtoolerr_t)ret;

	return IMGTOOLERR_SUCCESS;
}
Пример #9
0
static imgtoolerr_t imgtool_floppy_transfer_sector_tofrom_stream(imgtool_image *img, int head, int track, int sector, int offset, size_t length, imgtool_stream *f, int direction)
{
	floperr_t err;
	floppy_image_legacy *floppy;
	void *buffer = NULL;

	floppy = imgtool_floppy(img);

	buffer = malloc(length);
	if (!buffer)
	{
		err = FLOPPY_ERROR_OUTOFMEMORY;
		goto done;
	}

	if (direction)
	{
		err = floppy_read_sector(floppy, head, track, sector, offset, buffer, length);
		if (err)
			goto done;
		stream_write(f, buffer, length);
	}
	else
	{
		stream_read(f, buffer, length);
		err = floppy_write_sector(floppy, head, track, sector, offset, buffer, length, 0);	/* TODO: pass ddam argument from imgtool */
		if (err)
			goto done;
	}

	err = FLOPPY_ERROR_SUCCESS;

done:
	if (buffer)
		free(buffer);
	return imgtool_floppy_error(err);
}
Пример #10
0
static floperr_t put_rsdos_dirent(imgtool::image &f, int index_loc, const rsdos_dirent &ent)
{
	if (index_loc >= MAX_DIRENTS)
		return (floperr_t)IMGTOOLERR_FILENOTFOUND;
	return floppy_write_sector(imgtool_floppy(f), 0, 17, 3, index_loc * 32, (void *) &ent, sizeof(ent), 0); /* TODO: pass ddam argument from imgtool */
}
Пример #11
0
static floperr_t put_granule_map(imgtool::image &img, const uint8_t *granule_map, uint8_t granule_count)
{
	return floppy_write_sector(imgtool_floppy(img), 0, 17, 2, 0, granule_map, granule_count, 0);    /* TODO: pass ddam argument from imgtool */
}
Пример #12
0
static imgtoolerr_t os9_diskimage_create(imgtool_image *img, imgtool_stream *stream, option_resolution *opts)
{
	imgtoolerr_t err;
	dynamic_buffer header;
	UINT32 heads, tracks, sectors, sector_bytes, first_sector_id;
	UINT32 cluster_size, owner_id;
	UINT32 allocation_bitmap_bits, allocation_bitmap_lsns;
	UINT32 attributes, format_flags, disk_id;
	UINT32 i;
	INT32 total_allocated_sectors;
	const char *title;
	time_t t;
	struct tm *ltime;

	time(&t);
	ltime = localtime(&t);

	heads = option_resolution_lookup_int(opts, 'H');
	tracks = option_resolution_lookup_int(opts, 'T');
	sectors = option_resolution_lookup_int(opts, 'S');
	sector_bytes = option_resolution_lookup_int(opts, 'L');
	first_sector_id = option_resolution_lookup_int(opts, 'F');
	title = "";

	header.resize(sector_bytes);

	if (sector_bytes > 256)
		sector_bytes = 256;
	cluster_size = 1;
	owner_id = 1;
	disk_id = 1;
	attributes = 0;
	allocation_bitmap_bits = heads * tracks * sectors / cluster_size;
	allocation_bitmap_lsns = (allocation_bitmap_bits / 8 + sector_bytes - 1) / sector_bytes;
	format_flags = ((heads > 1) ? 0x01 : 0x00) | ((tracks > 40) ? 0x02 : 0x00);

	memset(&header[0], 0, sector_bytes);
	place_integer_be(&header[0],   0,  3, heads * tracks * sectors);
	place_integer_be(&header[0],   3,  1, sectors);
	place_integer_be(&header[0],   4,  2, (allocation_bitmap_bits + 7) / 8);
	place_integer_be(&header[0],   6,  2, cluster_size);
	place_integer_be(&header[0],   8,  3, 1 + allocation_bitmap_lsns);
	place_integer_be(&header[0],  11,  2, owner_id);
	place_integer_be(&header[0],  13,  1, attributes);
	place_integer_be(&header[0],  14,  2, disk_id);
	place_integer_be(&header[0],  16,  1, format_flags);
	place_integer_be(&header[0],  17,  2, sectors);
	place_string(&header[0],   31, 32, title);
	place_integer_be(&header[0], 103, 2, sector_bytes / 256);

	/* path descriptor options */
	place_integer_be(&header[0], 0x3f+0x00, 1, 1); /* device class */
	place_integer_be(&header[0], 0x3f+0x01, 1, 1); /* drive number */
	place_integer_be(&header[0], 0x3f+0x03, 1, 0x20); /* device type */
	place_integer_be(&header[0], 0x3f+0x04, 1, 1); /* density capability */
	place_integer_be(&header[0], 0x3f+0x05, 2, tracks); /* number of tracks */
	place_integer_be(&header[0], 0x3f+0x07, 1, heads); /* number of sides */
	place_integer_be(&header[0], 0x3f+0x09, 2, sectors); /* sectors per track */
	place_integer_be(&header[0], 0x3f+0x0b, 2, sectors); /* sectors on track zero */
	place_integer_be(&header[0], 0x3f+0x0d, 1, 3); /* sector interleave factor */
	place_integer_be(&header[0], 0x3f+0x0e, 1, 8); /* default sectors per allocation */

	err = (imgtoolerr_t)floppy_write_sector(imgtool_floppy(img), 0, 0, first_sector_id, 0, &header[0], sector_bytes, 0);    /* TODO: pass ddam argument from imgtool */
	if (err)
		goto done;

	total_allocated_sectors = 1 + allocation_bitmap_lsns + 1 + 7;

	for (i = 0; i < allocation_bitmap_lsns; i++)
	{
		memset(&header[0], 0x00, sector_bytes);

		if (total_allocated_sectors > (8 * 256))
		{
			memset(&header[0], 0xff, sector_bytes);
			total_allocated_sectors -= (8 * 256);
		}
		else if (total_allocated_sectors > 1 )
		{
			int offset;
			UINT8 mask;

			while( total_allocated_sectors >= 0 )
			{
				offset = total_allocated_sectors / 8;
				mask = 1 << (7 - ( total_allocated_sectors % 8 ) );

				header[offset] |= mask;
				total_allocated_sectors--;
			}
		}

		err = (imgtoolerr_t)floppy_write_sector(imgtool_floppy(img), 0, 0, first_sector_id + 1 + i, 0, &header[0], sector_bytes, 0);    /* TODO: pass ddam argument from imgtool */
		if (err)
			goto done;
	}

	memset(&header[0], 0, sector_bytes);
	header[0x00] = 0xBF;
	header[0x01] = 0x00;
	header[0x02] = 0x00;
	header[0x03] = (UINT8) ltime->tm_year;
	header[0x04] = (UINT8) ltime->tm_mon + 1;
	header[0x05] = (UINT8) ltime->tm_mday;
	header[0x06] = (UINT8) ltime->tm_hour;
	header[0x07] = (UINT8) ltime->tm_min;
	header[0x08] = 0x02;
	header[0x09] = 0x00;
	header[0x0A] = 0x00;
	header[0x0B] = 0x00;
	header[0x0C] = 0x40;
	header[0x0D] = (UINT8) (ltime->tm_year % 100);
	header[0x0E] = (UINT8) ltime->tm_mon;
	header[0x0F] = (UINT8) ltime->tm_mday;
	place_integer_be(&header[0], 0x10, 3, 1 + allocation_bitmap_lsns + 1);
	place_integer_be(&header[0], 0x13, 2, 8);

	err = (imgtoolerr_t)floppy_write_sector(imgtool_floppy(img), 0, 0, first_sector_id + 1 + allocation_bitmap_lsns, 0, &header[0], sector_bytes, 0);   /* TODO: pass ddam argument from imgtool */
	if (err)
		goto done;

	memset(&header[0], 0, sector_bytes);
	header[0x00] = 0x2E;
	header[0x01] = 0xAE;
	header[0x1F] = 1 + allocation_bitmap_lsns;
	header[0x20] = 0xAE;
	header[0x3F] = 1 + allocation_bitmap_lsns;
	err = (imgtoolerr_t)floppy_write_sector(imgtool_floppy(img), 0, 0, first_sector_id + 2 + allocation_bitmap_lsns, 0, &header[0], sector_bytes, 0);   /* TOOD: pass ddam argument from imgtool */
	if (err)
		goto done;

done:
	return err;
}
Пример #13
0
static floperr_t put_granule_map(imgtool_image *img, const UINT8 *granule_map, UINT8 granule_count)
{
    return floppy_write_sector(imgtool_floppy(img), 0, 17, 2, 0, granule_map, granule_count, 0);    /* TODO: pass ddam argument from imgtool */
}
Пример #14
0
static floperr_t write_granule(imgtool_image *img, UINT8 granule, int offset, int length, const UINT8 *buf)
{
	UINT8 head, track, sector;
	granule_location(img, granule, &head, &track, &sector);
	return floppy_write_sector(imgtool_floppy(img), head, track, sector, offset, buf, length, 0); /* TODO: pass ddam argument from imgtool */
}
Пример #15
-1
static floperr_t put_granule_map(imgtool_image *img, const UINT8 *granule_map, UINT8 granule_count)
{
	bml3_diskinfo *info = bml3_get_diskinfo(img);
	return floppy_write_sector(imgtool_floppy(img), 0, 20, info->fat_start_sector, info->fat_start_offset, granule_map, granule_count, 0);    /* TODO: pass ddam argument from imgtool */
}