trd_dsk.cpp add more formats, improve image type detection

This commit is contained in:
MetalliC 2020-07-14 19:26:42 +03:00
parent fd8088de83
commit 06b98bd357
2 changed files with 57 additions and 1 deletions

View File

@ -31,12 +31,67 @@ const char *trd_format::extensions() const
return "trd";
}
int trd_format::find_size(io_generic *io, uint32_t form_factor)
{
int index = -1;
uint64_t size = io_generic_size(io);
for (int i = 0; formats[i].form_factor; i++)
{
const format &f = formats[i];
if (form_factor != floppy_image::FF_UNKNOWN && form_factor != f.form_factor)
continue;
uint64_t format_size = f.track_count * f.head_count * compute_track_size(f);
if (size == format_size)
{
index = i; // at least size match, save it for the case if there will be no exact matches
uint8_t sectdata[0x100];
if (f.encoding == floppy_image::MFM)
io_generic_read(io, sectdata, 0x800, 0x100);
else
{
io_generic_read(io, sectdata, 0x100, 0x100);
for (int i = 0; i < 0x100; i++)
sectdata[i] ^= 0xff;
}
uint8_t disktype = sectdata[0xe3]; // 16 - DS80, 17 - DS40, 18 - SS80, 19 - SS40
if (disktype < 0x16 || disktype > 0x19)
continue;
uint8_t heads = ((disktype == 0x16) || disktype == 0x17) ? 2 : 1;
uint8_t tracks = ((disktype == 0x16) || disktype == 0x18) ? 80 : 40;
if (f.sector_count != sectdata[0xe7] || f.head_count != heads || f.track_count != tracks)
continue;
return i;
}
}
return index;
}
const trd_format::format trd_format::formats[] = {
// GAP4A should be 0 bytes
{ // 5"25 640K 80 track double sided double density
floppy_image::FF_525, floppy_image::DSQD, floppy_image::MFM,
// GAP4A - 0(!!!) bytes, GAP1 - 10 bytes, GAP2 - 22 bytes, GAP3 - 60 bytes, GAP4B - upto track end
2000, 16, 80, 2, 256, {}, -1, { 1,9,2,10,3,11,4,12,5,13,6,14,7,15,8,16 }, 10, 22, 60
},
{ // 5"25 320K 80 track single sided double density
floppy_image::FF_525, floppy_image::SSQD, floppy_image::MFM,
2000, 16, 80, 1, 256, {}, -1, { 1,9,2,10,3,11,4,12,5,13,6,14,7,15,8,16 }, 10, 22, 60
},
{ // 5"25 320K 40 track double sided double density
floppy_image::FF_525, floppy_image::DSSD, floppy_image::MFM,
2000, 16, 40, 2, 256, {}, -1, { 1,9,2,10,3,11,4,12,5,13,6,14,7,15,8,16 }, 10, 22, 60
},
{ // 5"25 160K 40 track single sided double density
floppy_image::FF_525, floppy_image::SSSD, floppy_image::MFM,
2000, 16, 40, 1, 256, {}, -1, { 1,9,2,10,3,11,4,12,5,13,6,14,7,15,8,16 }, 10, 22, 60
},
{ // 5"25 400K 80 track double sided single density
floppy_image::FF_525, floppy_image::DSQD, floppy_image::FM,
// GAPs and interleave probably not correct

View File

@ -24,6 +24,7 @@ public:
private:
static const format formats[];
virtual int find_size(io_generic *io, uint32_t form_factor) override;
};
extern const floppy_format_type FLOPPY_TRD_FORMAT;