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

View File

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