mirror of
https://github.com/mamedev/mame.git
synced 2024-11-18 10:06:19 +01:00
Merge pull request #1978 from npwoods/fix_coco_dmk_image_creation
[CoCo] Fixed a recently introduced bug in DMK image creation
This commit is contained in:
commit
4d8258dbcb
1 changed files with 15 additions and 23 deletions
|
@ -723,7 +723,6 @@ static floperr_t coco_dmk_format_track(floppy_image_legacy *floppy, int head, in
|
||||||
uint8_t *track_data;
|
uint8_t *track_data;
|
||||||
void *track_data_v;
|
void *track_data_v;
|
||||||
uint32_t max_track_size;
|
uint32_t max_track_size;
|
||||||
std::vector<int> sector_map;
|
|
||||||
|
|
||||||
sectors = params->lookup_int(PARAM_SECTORS);
|
sectors = params->lookup_int(PARAM_SECTORS);
|
||||||
sector_length = params->lookup_int(PARAM_SECTOR_LENGTH);
|
sector_length = params->lookup_int(PARAM_SECTOR_LENGTH);
|
||||||
|
@ -733,24 +732,18 @@ static floperr_t coco_dmk_format_track(floppy_image_legacy *floppy, int head, in
|
||||||
max_track_size = get_dmk_tag(floppy)->track_size;
|
max_track_size = get_dmk_tag(floppy)->track_size;
|
||||||
|
|
||||||
if (sectors > DMK_TOC_LEN)
|
if (sectors > DMK_TOC_LEN)
|
||||||
{
|
return FLOPPY_ERROR_INTERNAL;
|
||||||
err = FLOPPY_ERROR_INTERNAL;
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (max_track_size < coco_dmk_min_track_size(sectors, sector_length))
|
if (max_track_size < coco_dmk_min_track_size(sectors, sector_length))
|
||||||
{
|
return FLOPPY_ERROR_NOSPACE;
|
||||||
err = FLOPPY_ERROR_NOSPACE;
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
err = floppy_load_track(floppy, head, track, true, &track_data_v, NULL);
|
err = floppy_load_track(floppy, head, track, true, &track_data_v, NULL);
|
||||||
if (err)
|
if (err)
|
||||||
goto done;
|
return err;
|
||||||
track_data = (uint8_t *) track_data_v;
|
track_data = (uint8_t *) track_data_v;
|
||||||
|
|
||||||
/* set up sector map */
|
// set up sector map
|
||||||
memset(§or_map[0], 0xff, sectors*sizeof(int));
|
std::vector<int> sector_map(sectors, -1);
|
||||||
|
|
||||||
physical_sector = 0;
|
physical_sector = 0;
|
||||||
for (logical_sector = 0; logical_sector < sectors; logical_sector++)
|
for (logical_sector = 0; logical_sector < sectors; logical_sector++)
|
||||||
|
@ -766,22 +759,22 @@ static floperr_t coco_dmk_format_track(floppy_image_legacy *floppy, int head, in
|
||||||
physical_sector %= sectors;
|
physical_sector %= sectors;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* set up track table of contents */
|
// set up track table of contents
|
||||||
physical_sector = 0;
|
physical_sector = 0;
|
||||||
track_position = DMK_TOC_LEN * 2 + DMK_LEAD_IN;
|
track_position = DMK_TOC_LEN * 2 + DMK_LEAD_IN;
|
||||||
while(physical_sector < DMK_TOC_LEN)
|
while(physical_sector < DMK_TOC_LEN)
|
||||||
{
|
{
|
||||||
if (physical_sector >= sectors)
|
if (physical_sector >= sectors)
|
||||||
{
|
{
|
||||||
/* no more sectors */
|
// no more sectors
|
||||||
idam_offset = 0;
|
idam_offset = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* this is a sector */
|
// this is a sector
|
||||||
logical_sector = sector_map[physical_sector];
|
logical_sector = sector_map[physical_sector];
|
||||||
|
|
||||||
/* write the sector */
|
// write the sector
|
||||||
memset(&track_data[track_position], 0x00, 8);
|
memset(&track_data[track_position], 0x00, 8);
|
||||||
track_position += 8;
|
track_position += 8;
|
||||||
|
|
||||||
|
@ -807,7 +800,7 @@ static floperr_t coco_dmk_format_track(floppy_image_legacy *floppy, int head, in
|
||||||
memset(&track_data[track_position], 0xA1, 3);
|
memset(&track_data[track_position], 0xA1, 3);
|
||||||
track_position += 3;
|
track_position += 3;
|
||||||
|
|
||||||
/* write sector body */
|
// write sector body
|
||||||
track_data[track_position] = 0xFB;
|
track_data[track_position] = 0xFB;
|
||||||
memset(&track_data[track_position + 1], floppy_get_filler(floppy), sector_length);
|
memset(&track_data[track_position + 1], floppy_get_filler(floppy), sector_length);
|
||||||
crc = ccitt_crc16(0xcdb4, &track_data[track_position], sector_length + 1);
|
crc = ccitt_crc16(0xcdb4, &track_data[track_position], sector_length + 1);
|
||||||
|
@ -815,27 +808,26 @@ static floperr_t coco_dmk_format_track(floppy_image_legacy *floppy, int head, in
|
||||||
track_data[track_position + sector_length + 2] = (uint8_t) (crc >> 0);
|
track_data[track_position + sector_length + 2] = (uint8_t) (crc >> 0);
|
||||||
track_position += sector_length + 3;
|
track_position += sector_length + 3;
|
||||||
|
|
||||||
/* write sector footer */
|
// write sector footer
|
||||||
memset(&track_data[track_position], 0x4E, 24);
|
memset(&track_data[track_position], 0x4E, 24);
|
||||||
track_position += 24;
|
track_position += 24;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* write the TOC entry */
|
// write the TOC entry
|
||||||
track_data[physical_sector * 2 + 0] = (uint8_t) (idam_offset >> 0);
|
track_data[physical_sector * 2 + 0] = (uint8_t) (idam_offset >> 0);
|
||||||
track_data[physical_sector * 2 + 1] = (uint8_t) (idam_offset >> 8);
|
track_data[physical_sector * 2 + 1] = (uint8_t) (idam_offset >> 8);
|
||||||
|
|
||||||
physical_sector++;
|
physical_sector++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* write track lead in */
|
// write track lead in
|
||||||
memset(&track_data[physical_sector * 2], 0x4e, DMK_LEAD_IN);
|
memset(&track_data[physical_sector * 2], 0x4e, DMK_LEAD_IN);
|
||||||
|
|
||||||
/* write track footer */
|
// write track footer
|
||||||
assert(max_track_size >= (uint32_t)track_position);
|
assert(max_track_size >= (uint32_t)track_position);
|
||||||
memset(&track_data[track_position], 0x4e, max_track_size - track_position);
|
memset(&track_data[track_position], 0x4e, max_track_size - track_position);
|
||||||
|
|
||||||
done:
|
return FLOPPY_ERROR_SUCCESS;
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue