Move magneto-optical types to a table.

This commit is contained in:
2020-03-29 05:01:31 +01:00
parent d9e2f8ab32
commit 0a1bc9e419
2 changed files with 34 additions and 41 deletions

View File

@@ -2476,6 +2476,7 @@ mo_load(mo_t *dev, const wchar_t *fn)
{
int read_only = dev->drv->ui_writeprot;
int size = 0;
unsigned int i, found = 0;
dev->drv->f = plat_fopen(fn, dev->drv->ui_writeprot ? L"rb" : L"rb+");
if (!dev->drv->ui_writeprot && !dev->drv->f) {
@@ -2486,36 +2487,26 @@ mo_load(mo_t *dev, const wchar_t *fn)
fseek(dev->drv->f, 0, SEEK_END);
size = ftell(dev->drv->f);
switch(size)
for(i = 0; i < sizeof(mo_types); i++)
{
case MO_SECTORS_ISO10090 * MO_BPS_ISO10090:
dev->drv->medium_size = MO_SECTORS_ISO10090;
dev->drv->sector_size = MO_BPS_ISO10090;
break;
case MO_SECTORS_ISO13963 * MO_BPS_ISO13963:
dev->drv->medium_size = MO_SECTORS_ISO13963;
dev->drv->sector_size = MO_BPS_ISO13963;
break;
case MO_SECTORS_ISO15498 * MO_BPS_ISO15498:
dev->drv->medium_size = MO_SECTORS_ISO15498;
dev->drv->sector_size = MO_BPS_ISO15498;
break;
case MO_SECTORS_GIGAMO * MO_BPS_GIGAMO:
dev->drv->medium_size = MO_SECTORS_GIGAMO;
dev->drv->sector_size = MO_BPS_GIGAMO;
break;
case MO_SECTORS_GIGAMO2 * MO_BPS_GIGAMO2:
dev->drv->medium_size = MO_SECTORS_GIGAMO2;
dev->drv->sector_size = MO_BPS_GIGAMO2;
break;
default:
DEBUG("File is incorrect size for a magneto-optical image\n");
fclose(dev->drv->f);
dev->drv->f = NULL;
dev->drv->medium_size = 0;
dev->drv->sector_size = 0;
ui_mo_eject(dev->id); /* Make sure the host OS knows we've rejected (and ejected) the image. */
return 0;
if(size == mo_types[i].disk_size)
{
found = 1;
dev->drv->medium_size = mo_types[i].sectors;
dev->drv->sector_size = mo_types[i].bytes_per_sector;
break;
}
}
if(!found)
{
DEBUG("File is incorrect size for a magneto-optical image\n");
fclose(dev->drv->f);
dev->drv->f = NULL;
dev->drv->medium_size = 0;
dev->drv->sector_size = 0;
ui_mo_eject(dev->id); /* Make sure the host OS knows we've rejected (and ejected) the image. */
return 0;
}
fseek(dev->drv->f, dev->drv->base, SEEK_SET);

View File

@@ -44,19 +44,21 @@
#define MO_TIME (5LL * 100LL * (1LL << TIMER_SHIFT))
// TODO: Create arrays with media-type, sectors, bps
// 3.5" standard M.O. disks
#define MO_SECTORS_ISO10090 (248826)
#define MO_SECTORS_ISO13963 (446325)
#define MO_SECTORS_ISO15498 (310352)
#define MO_SECTORS_GIGAMO (605846)
#define MO_SECTORS_GIGAMO2 (1063146)
typedef struct {
uint32_t sectors;
uint16_t bytes_per_sector;
int64_t disk_size;
char name[255];
} mo_type_t;
#define MO_BPS_ISO10090 (512)
#define MO_BPS_ISO13963 (512)
#define MO_BPS_ISO15498 (2048)
#define MO_BPS_GIGAMO (2048)
#define MO_BPS_GIGAMO2 (2048)
static const mo_type_t mo_types[5] = {
// 3.5" standard M.O. disks
{ 248826, 512, 127398912, "3.5\" 128Mb M.O. (ISO 10090)" },
{ 446325, 512, 228518400, "3.5\" 230Mb M.O. (ISO 13963)" },
{ 310352, 2048, 635600896, "3.5\" 640Mb M.O. (ISO 15498)" },
{ 605846, 2048, 1240772608, "3.5\" 1.3Gb M.O. (GigaMO)" },
{ 1063146, 2048, 2177323008, "3.5\" 2.3Gb M.O. (GigaMO 2)" }
};
enum {
MO_BUS_DISABLED = 0,