clang-format in src/floppy/
This commit is contained in:
3116
src/floppy/fdc.c
3116
src/floppy/fdc.c
File diff suppressed because it is too large
Load Diff
@@ -31,20 +31,20 @@
|
||||
#include <86box/fdc.h>
|
||||
#include <86box/fdc_ext.h>
|
||||
|
||||
#define ROM_B215 "roms/floppy/magitronic/Magitronic B215 - BIOS ROM.bin"
|
||||
#define ROM_ADDR (uint32_t)(device_get_config_hex20("bios_addr") & 0x000fffff)
|
||||
#define ROM_B215 "roms/floppy/magitronic/Magitronic B215 - BIOS ROM.bin"
|
||||
#define ROM_ADDR (uint32_t)(device_get_config_hex20("bios_addr") & 0x000fffff)
|
||||
|
||||
#define DRIVE_SELECT (int)(real_drive(dev->fdc_controller, i))
|
||||
#define DRIVE_SELECT (int) (real_drive(dev->fdc_controller, i))
|
||||
typedef struct
|
||||
{
|
||||
fdc_t *fdc_controller;
|
||||
rom_t rom;
|
||||
rom_t rom;
|
||||
} b215_t;
|
||||
|
||||
static uint8_t
|
||||
b215_read(uint16_t addr, void *priv)
|
||||
{
|
||||
b215_t *dev = (b215_t *)priv;
|
||||
b215_t *dev = (b215_t *) priv;
|
||||
|
||||
/*
|
||||
Register 3F0h
|
||||
@@ -59,19 +59,15 @@ b215_read(uint16_t addr, void *priv)
|
||||
*/
|
||||
int drive_spec[2];
|
||||
|
||||
for (int i = 0; i <= 1; i++)
|
||||
{
|
||||
if (fdd_is_525(DRIVE_SELECT))
|
||||
{
|
||||
for (int i = 0; i <= 1; i++) {
|
||||
if (fdd_is_525(DRIVE_SELECT)) {
|
||||
if (!fdd_is_dd(DRIVE_SELECT))
|
||||
drive_spec[i] = 1;
|
||||
else if (fdd_doublestep_40(DRIVE_SELECT))
|
||||
drive_spec[i] = 2;
|
||||
else
|
||||
drive_spec[i] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
if (fdd_is_dd(DRIVE_SELECT) && !fdd_is_double_sided(DRIVE_SELECT))
|
||||
drive_spec[i] = 0;
|
||||
else if (fdd_is_dd(DRIVE_SELECT) && fdd_is_double_sided(DRIVE_SELECT))
|
||||
@@ -87,7 +83,7 @@ b215_read(uint16_t addr, void *priv)
|
||||
static void
|
||||
b215_close(void *priv)
|
||||
{
|
||||
b215_t *dev = (b215_t *)priv;
|
||||
b215_t *dev = (b215_t *) priv;
|
||||
|
||||
free(dev);
|
||||
}
|
||||
@@ -95,7 +91,7 @@ b215_close(void *priv)
|
||||
static void *
|
||||
b215_init(const device_t *info)
|
||||
{
|
||||
b215_t *dev = (b215_t *)malloc(sizeof(b215_t));
|
||||
b215_t *dev = (b215_t *) malloc(sizeof(b215_t));
|
||||
memset(dev, 0, sizeof(b215_t));
|
||||
|
||||
rom_init(&dev->rom, ROM_B215, ROM_ADDR, 0x2000, 0x1fff, 0, MEM_MAPPING_EXTERNAL);
|
||||
@@ -106,13 +102,14 @@ b215_init(const device_t *info)
|
||||
return dev;
|
||||
}
|
||||
|
||||
static int b215_available(void)
|
||||
static int
|
||||
b215_available(void)
|
||||
{
|
||||
return rom_present(ROM_B215);
|
||||
}
|
||||
|
||||
static const device_config_t b215_config[] = {
|
||||
// clang-format off
|
||||
// clang-format off
|
||||
{
|
||||
.name = "bios_addr",
|
||||
.description = "BIOS Address:",
|
||||
@@ -132,15 +129,15 @@ static const device_config_t b215_config[] = {
|
||||
};
|
||||
|
||||
const device_t fdc_b215_device = {
|
||||
.name = "Magitronic B215",
|
||||
.name = "Magitronic B215",
|
||||
.internal_name = "b215",
|
||||
.flags = DEVICE_ISA,
|
||||
.local = 0,
|
||||
.init = b215_init,
|
||||
.close = b215_close,
|
||||
.reset = NULL,
|
||||
.flags = DEVICE_ISA,
|
||||
.local = 0,
|
||||
.init = b215_init,
|
||||
.close = b215_close,
|
||||
.reset = NULL,
|
||||
{ .available = b215_available },
|
||||
.speed_changed = NULL,
|
||||
.force_redraw = NULL,
|
||||
.config = b215_config
|
||||
.force_redraw = NULL,
|
||||
.config = b215_config
|
||||
};
|
||||
|
@@ -76,9 +76,9 @@ MiniMicro 4 also won't work with the XT FDC which the Zilog claims to be.
|
||||
#include <86box/fdc.h>
|
||||
#include <86box/fdc_ext.h>
|
||||
|
||||
#define DTK_VARIANT ((info->local == 158) ? ROM_PII_158B : ROM_PII_151B)
|
||||
#define DTK_CHIP ((info->local == 158) ? &fdc_xt_device : &fdc_dp8473_device)
|
||||
#define BIOS_ADDR (uint32_t)(device_get_config_hex20("bios_addr") & 0x000fffff)
|
||||
#define DTK_VARIANT ((info->local == 158) ? ROM_PII_158B : ROM_PII_151B)
|
||||
#define DTK_CHIP ((info->local == 158) ? &fdc_xt_device : &fdc_dp8473_device)
|
||||
#define BIOS_ADDR (uint32_t)(device_get_config_hex20("bios_addr") & 0x000fffff)
|
||||
#define ROM_PII_151B "roms/floppy/dtk/pii-151b.rom"
|
||||
#define ROM_PII_158B "roms/floppy/dtk/pii-158b.rom"
|
||||
|
||||
@@ -90,7 +90,7 @@ typedef struct
|
||||
static void
|
||||
pii_close(void *priv)
|
||||
{
|
||||
pii_t *dev = (pii_t *)priv;
|
||||
pii_t *dev = (pii_t *) priv;
|
||||
|
||||
free(dev);
|
||||
}
|
||||
@@ -100,7 +100,7 @@ pii_init(const device_t *info)
|
||||
{
|
||||
pii_t *dev;
|
||||
|
||||
dev = (pii_t *)malloc(sizeof(pii_t));
|
||||
dev = (pii_t *) malloc(sizeof(pii_t));
|
||||
memset(dev, 0, sizeof(pii_t));
|
||||
|
||||
if (BIOS_ADDR != 0)
|
||||
@@ -111,18 +111,20 @@ pii_init(const device_t *info)
|
||||
return dev;
|
||||
}
|
||||
|
||||
static int pii_151b_available(void)
|
||||
static int
|
||||
pii_151b_available(void)
|
||||
{
|
||||
return rom_present(ROM_PII_151B);
|
||||
}
|
||||
|
||||
static int pii_158_available(void)
|
||||
static int
|
||||
pii_158_available(void)
|
||||
{
|
||||
return rom_present(ROM_PII_158B);
|
||||
}
|
||||
|
||||
static const device_config_t pii_config[] = {
|
||||
// clang-format off
|
||||
// clang-format off
|
||||
{
|
||||
.name = "bios_addr",
|
||||
.description = "BIOS Address:",
|
||||
@@ -144,29 +146,29 @@ static const device_config_t pii_config[] = {
|
||||
};
|
||||
|
||||
const device_t fdc_pii151b_device = {
|
||||
.name = "DTK PII-151B (MiniMicro) Floppy Drive Controller",
|
||||
.name = "DTK PII-151B (MiniMicro) Floppy Drive Controller",
|
||||
.internal_name = "dtk_pii151b",
|
||||
.flags = DEVICE_ISA,
|
||||
.local = 151,
|
||||
.init = pii_init,
|
||||
.close = pii_close,
|
||||
.reset = NULL,
|
||||
.flags = DEVICE_ISA,
|
||||
.local = 151,
|
||||
.init = pii_init,
|
||||
.close = pii_close,
|
||||
.reset = NULL,
|
||||
{ .available = pii_151b_available },
|
||||
.speed_changed = NULL,
|
||||
.force_redraw = NULL,
|
||||
.config = pii_config
|
||||
.force_redraw = NULL,
|
||||
.config = pii_config
|
||||
};
|
||||
|
||||
const device_t fdc_pii158b_device = {
|
||||
.name = "DTK PII-158B (MiniMicro4) Floppy Drive Controller",
|
||||
.name = "DTK PII-158B (MiniMicro4) Floppy Drive Controller",
|
||||
.internal_name = "dtk_pii158b",
|
||||
.flags = DEVICE_ISA,
|
||||
.local = 158,
|
||||
.init = pii_init,
|
||||
.close = pii_close,
|
||||
.reset = NULL,
|
||||
.flags = DEVICE_ISA,
|
||||
.local = 158,
|
||||
.init = pii_init,
|
||||
.close = pii_close,
|
||||
.reset = NULL,
|
||||
{ .available = pii_158_available },
|
||||
.speed_changed = NULL,
|
||||
.force_redraw = NULL,
|
||||
.config = pii_config
|
||||
.force_redraw = NULL,
|
||||
.config = pii_config
|
||||
};
|
||||
|
397
src/floppy/fdd.c
397
src/floppy/fdd.c
@@ -39,7 +39,6 @@
|
||||
#include <86box/fdd_td0.h>
|
||||
#include <86box/fdc.h>
|
||||
|
||||
|
||||
/* Flags:
|
||||
Bit 0: 300 rpm supported;
|
||||
Bit 1: 360 rpm supported;
|
||||
@@ -53,18 +52,17 @@
|
||||
Bit 9: ignore DENSEL;
|
||||
Bit 10: drive is a PS/2 drive;
|
||||
*/
|
||||
#define FLAG_RPM_300 1
|
||||
#define FLAG_RPM_360 2
|
||||
#define FLAG_525 4
|
||||
#define FLAG_DS 8
|
||||
#define FLAG_HOLE0 16
|
||||
#define FLAG_HOLE1 32
|
||||
#define FLAG_HOLE2 64
|
||||
#define FLAG_DOUBLE_STEP 128
|
||||
#define FLAG_INVERT_DENSEL 256
|
||||
#define FLAG_IGNORE_DENSEL 512
|
||||
#define FLAG_PS2 1024
|
||||
|
||||
#define FLAG_RPM_300 1
|
||||
#define FLAG_RPM_360 2
|
||||
#define FLAG_525 4
|
||||
#define FLAG_DS 8
|
||||
#define FLAG_HOLE0 16
|
||||
#define FLAG_HOLE1 32
|
||||
#define FLAG_HOLE2 64
|
||||
#define FLAG_DOUBLE_STEP 128
|
||||
#define FLAG_INVERT_DENSEL 256
|
||||
#define FLAG_IGNORE_DENSEL 512
|
||||
#define FLAG_PS2 1024
|
||||
|
||||
typedef struct {
|
||||
int type;
|
||||
@@ -75,28 +73,26 @@ typedef struct {
|
||||
int check_bpb;
|
||||
} fdd_t;
|
||||
|
||||
fdd_t fdd[FDD_NUM];
|
||||
|
||||
fdd_t fdd[FDD_NUM];
|
||||
char floppyfns[FDD_NUM][512];
|
||||
|
||||
char floppyfns[FDD_NUM][512];
|
||||
pc_timer_t fdd_poll_time[FDD_NUM];
|
||||
|
||||
pc_timer_t fdd_poll_time[FDD_NUM];
|
||||
static int fdd_notfound = 0,
|
||||
driveloaders[FDD_NUM];
|
||||
|
||||
static int fdd_notfound = 0,
|
||||
driveloaders[FDD_NUM];
|
||||
int writeprot[FDD_NUM], fwriteprot[FDD_NUM],
|
||||
fdd_changed[FDD_NUM], ui_writeprot[FDD_NUM] = { 0, 0, 0, 0 },
|
||||
drive_empty[FDD_NUM] = { 1, 1, 1, 1 };
|
||||
|
||||
int writeprot[FDD_NUM], fwriteprot[FDD_NUM],
|
||||
fdd_changed[FDD_NUM], ui_writeprot[FDD_NUM] = {0, 0, 0, 0},
|
||||
drive_empty[FDD_NUM] = {1, 1, 1, 1};
|
||||
DRIVE drives[FDD_NUM];
|
||||
|
||||
DRIVE drives[FDD_NUM];
|
||||
uint64_t motoron[FDD_NUM];
|
||||
|
||||
uint64_t motoron[FDD_NUM];
|
||||
|
||||
fdc_t *fdd_fdc;
|
||||
|
||||
d86f_handler_t d86f_handler[FDD_NUM];
|
||||
fdc_t *fdd_fdc;
|
||||
|
||||
d86f_handler_t d86f_handler[FDD_NUM];
|
||||
|
||||
static const struct
|
||||
{
|
||||
@@ -104,48 +100,46 @@ static const struct
|
||||
void (*load)(int drive, char *fn);
|
||||
void (*close)(int drive);
|
||||
int size;
|
||||
} loaders[]=
|
||||
{
|
||||
{"001", img_load, img_close, -1},
|
||||
{"002", img_load, img_close, -1},
|
||||
{"003", img_load, img_close, -1},
|
||||
{"004", img_load, img_close, -1},
|
||||
{"005", img_load, img_close, -1},
|
||||
{"006", img_load, img_close, -1},
|
||||
{"007", img_load, img_close, -1},
|
||||
{"008", img_load, img_close, -1},
|
||||
{"009", img_load, img_close, -1},
|
||||
{"010", img_load, img_close, -1},
|
||||
{"12", img_load, img_close, -1},
|
||||
{"144", img_load, img_close, -1},
|
||||
{"360", img_load, img_close, -1},
|
||||
{"720", img_load, img_close, -1},
|
||||
{"86F", d86f_load, d86f_close, -1},
|
||||
{"BIN", img_load, img_close, -1},
|
||||
{"CQ", img_load, img_close, -1},
|
||||
{"CQM", img_load, img_close, -1},
|
||||
{"DDI", img_load, img_close, -1},
|
||||
{"DSK", img_load, img_close, -1},
|
||||
{"FDI", fdi_load, fdi_close, -1},
|
||||
{"FDF", img_load, img_close, -1},
|
||||
{"FLP", img_load, img_close, -1},
|
||||
{"HDM", img_load, img_close, -1},
|
||||
{"IMA", img_load, img_close, -1},
|
||||
{"IMD", imd_load, imd_close, -1},
|
||||
{"IMG", img_load, img_close, -1},
|
||||
{"JSON", json_load, json_close, -1},
|
||||
{"MFM", mfm_load, mfm_close, -1},
|
||||
{"TD0", td0_load, td0_close, -1},
|
||||
{"VFD", img_load, img_close, -1},
|
||||
{"XDF", img_load, img_close, -1},
|
||||
{0, 0, 0, 0}
|
||||
} loaders[] = {
|
||||
{"001", img_load, img_close, -1},
|
||||
{ "002", img_load, img_close, -1},
|
||||
{ "003", img_load, img_close, -1},
|
||||
{ "004", img_load, img_close, -1},
|
||||
{ "005", img_load, img_close, -1},
|
||||
{ "006", img_load, img_close, -1},
|
||||
{ "007", img_load, img_close, -1},
|
||||
{ "008", img_load, img_close, -1},
|
||||
{ "009", img_load, img_close, -1},
|
||||
{ "010", img_load, img_close, -1},
|
||||
{ "12", img_load, img_close, -1},
|
||||
{ "144", img_load, img_close, -1},
|
||||
{ "360", img_load, img_close, -1},
|
||||
{ "720", img_load, img_close, -1},
|
||||
{ "86F", d86f_load, d86f_close, -1},
|
||||
{ "BIN", img_load, img_close, -1},
|
||||
{ "CQ", img_load, img_close, -1},
|
||||
{ "CQM", img_load, img_close, -1},
|
||||
{ "DDI", img_load, img_close, -1},
|
||||
{ "DSK", img_load, img_close, -1},
|
||||
{ "FDI", fdi_load, fdi_close, -1},
|
||||
{ "FDF", img_load, img_close, -1},
|
||||
{ "FLP", img_load, img_close, -1},
|
||||
{ "HDM", img_load, img_close, -1},
|
||||
{ "IMA", img_load, img_close, -1},
|
||||
{ "IMD", imd_load, imd_close, -1},
|
||||
{ "IMG", img_load, img_close, -1},
|
||||
{ "JSON", json_load, json_close, -1},
|
||||
{ "MFM", mfm_load, mfm_close, -1},
|
||||
{ "TD0", td0_load, td0_close, -1},
|
||||
{ "VFD", img_load, img_close, -1},
|
||||
{ "XDF", img_load, img_close, -1},
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
|
||||
static const struct
|
||||
{
|
||||
int max_track;
|
||||
int flags;
|
||||
int max_track;
|
||||
int flags;
|
||||
const char *name;
|
||||
const char *internal_name;
|
||||
} drive_types[] =
|
||||
@@ -197,161 +191,148 @@ static const struct
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#ifdef ENABLE_FDD_LOG
|
||||
int fdd_do_log = ENABLE_FDD_LOG;
|
||||
|
||||
|
||||
static void
|
||||
fdd_log(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_list ap;
|
||||
|
||||
if (fdd_do_log)
|
||||
{
|
||||
va_start(ap, fmt);
|
||||
pclog_ex(fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
if (fdd_do_log) {
|
||||
va_start(ap, fmt);
|
||||
pclog_ex(fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
}
|
||||
#else
|
||||
#define fdd_log(fmt, ...)
|
||||
# define fdd_log(fmt, ...)
|
||||
#endif
|
||||
|
||||
|
||||
char *
|
||||
fdd_getname(int type)
|
||||
{
|
||||
return (char *)drive_types[type].name;
|
||||
return (char *) drive_types[type].name;
|
||||
}
|
||||
|
||||
|
||||
char *
|
||||
fdd_get_internal_name(int type)
|
||||
{
|
||||
return (char *)drive_types[type].internal_name;
|
||||
return (char *) drive_types[type].internal_name;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
fdd_get_from_internal_name(char *s)
|
||||
{
|
||||
int c = 0;
|
||||
|
||||
while (strlen(drive_types[c].internal_name)) {
|
||||
if (!strcmp((char *)drive_types[c].internal_name, s))
|
||||
return c;
|
||||
c++;
|
||||
if (!strcmp((char *) drive_types[c].internal_name, s))
|
||||
return c;
|
||||
c++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* This is needed for the dump as 86F feature. */
|
||||
void
|
||||
fdd_do_seek(int drive, int track)
|
||||
{
|
||||
if (drives[drive].seek)
|
||||
drives[drive].seek(drive, track);
|
||||
drives[drive].seek(drive, track);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
fdd_forced_seek(int drive, int track_diff)
|
||||
{
|
||||
fdd[drive].track += track_diff;
|
||||
|
||||
if (fdd[drive].track < 0)
|
||||
fdd[drive].track = 0;
|
||||
fdd[drive].track = 0;
|
||||
|
||||
if (fdd[drive].track > drive_types[fdd[drive].type].max_track)
|
||||
fdd[drive].track = drive_types[fdd[drive].type].max_track;
|
||||
fdd[drive].track = drive_types[fdd[drive].type].max_track;
|
||||
|
||||
fdd_do_seek(drive, fdd[drive].track);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
fdd_seek(int drive, int track_diff)
|
||||
{
|
||||
if (!track_diff)
|
||||
return;
|
||||
return;
|
||||
|
||||
fdd[drive].track += track_diff;
|
||||
|
||||
if (fdd[drive].track < 0)
|
||||
fdd[drive].track = 0;
|
||||
fdd[drive].track = 0;
|
||||
|
||||
if (fdd[drive].track > drive_types[fdd[drive].type].max_track)
|
||||
fdd[drive].track = drive_types[fdd[drive].type].max_track;
|
||||
fdd[drive].track = drive_types[fdd[drive].type].max_track;
|
||||
|
||||
fdd_changed[drive] = 0;
|
||||
|
||||
fdd_do_seek(drive, fdd[drive].track);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
fdd_track0(int drive)
|
||||
{
|
||||
/* If drive is disabled, TRK0 never gets set. */
|
||||
if (!drive_types[fdd[drive].type].max_track) return 0;
|
||||
if (!drive_types[fdd[drive].type].max_track)
|
||||
return 0;
|
||||
|
||||
return !fdd[drive].track;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
fdd_current_track(int drive)
|
||||
{
|
||||
return fdd[drive].track;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
fdd_set_densel(int densel)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
for (i = 0; i < FDD_NUM; i++) {
|
||||
if (drive_types[fdd[i].type].flags & FLAG_INVERT_DENSEL)
|
||||
fdd[i].densel = densel ^ 1;
|
||||
else
|
||||
fdd[i].densel = densel;
|
||||
if (drive_types[fdd[i].type].flags & FLAG_INVERT_DENSEL)
|
||||
fdd[i].densel = densel ^ 1;
|
||||
else
|
||||
fdd[i].densel = densel;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
fdd_getrpm(int drive)
|
||||
{
|
||||
int densel = 0;
|
||||
int hole;
|
||||
|
||||
hole = fdd_hole(drive);
|
||||
hole = fdd_hole(drive);
|
||||
densel = fdd[drive].densel;
|
||||
|
||||
if (drive_types[fdd[drive].type].flags & FLAG_INVERT_DENSEL)
|
||||
densel ^= 1;
|
||||
densel ^= 1;
|
||||
|
||||
if (!(drive_types[fdd[drive].type].flags & FLAG_RPM_360))
|
||||
return 300;
|
||||
return 300;
|
||||
if (!(drive_types[fdd[drive].type].flags & FLAG_RPM_300))
|
||||
return 360;
|
||||
return 360;
|
||||
|
||||
if (drive_types[fdd[drive].type].flags & FLAG_525)
|
||||
return densel ? 360 : 300;
|
||||
return densel ? 360 : 300;
|
||||
else {
|
||||
/* fdd_hole(drive) returns 0 for double density media, 1 for high density, and 2 for extended density. */
|
||||
if (hole == 1)
|
||||
return densel ? 300 : 360;
|
||||
else
|
||||
return 300;
|
||||
/* fdd_hole(drive) returns 0 for double density media, 1 for high density, and 2 for extended density. */
|
||||
if (hole == 1)
|
||||
return densel ? 300 : 360;
|
||||
else
|
||||
return 300;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
fdd_can_read_medium(int drive)
|
||||
{
|
||||
@@ -362,351 +343,322 @@ fdd_can_read_medium(int drive)
|
||||
return !!(drive_types[fdd[drive].type].flags & hole);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
fdd_doublestep_40(int drive)
|
||||
{
|
||||
return !!(drive_types[fdd[drive].type].flags & FLAG_DOUBLE_STEP);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
fdd_set_type(int drive, int type)
|
||||
{
|
||||
int old_type = fdd[drive].type;
|
||||
int old_type = fdd[drive].type;
|
||||
fdd[drive].type = type;
|
||||
if ((drive_types[old_type].flags ^ drive_types[type].flags) & FLAG_INVERT_DENSEL)
|
||||
fdd[drive].densel ^= 1;
|
||||
fdd[drive].densel ^= 1;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
fdd_get_type(int drive)
|
||||
{
|
||||
return fdd[drive].type;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
fdd_get_flags(int drive)
|
||||
{
|
||||
return drive_types[fdd[drive].type].flags;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
fdd_is_525(int drive)
|
||||
{
|
||||
return drive_types[fdd[drive].type].flags & FLAG_525;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
fdd_is_dd(int drive)
|
||||
{
|
||||
return (drive_types[fdd[drive].type].flags & 0x70) == 0x10;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
fdd_is_ed(int drive)
|
||||
{
|
||||
return drive_types[fdd[drive].type].flags & FLAG_HOLE2;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
fdd_is_double_sided(int drive)
|
||||
{
|
||||
return drive_types[fdd[drive].type].flags & FLAG_DS;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
fdd_set_head(int drive, int head)
|
||||
{
|
||||
if (head && !fdd_is_double_sided(drive))
|
||||
fdd[drive].head = 0;
|
||||
fdd[drive].head = 0;
|
||||
else
|
||||
fdd[drive].head = head;
|
||||
fdd[drive].head = head;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
fdd_get_head(int drive)
|
||||
{
|
||||
if (!fdd_is_double_sided(drive))
|
||||
return 0;
|
||||
return 0;
|
||||
return fdd[drive].head;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
fdd_set_turbo(int drive, int turbo)
|
||||
{
|
||||
fdd[drive].turbo = turbo;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
fdd_get_turbo(int drive)
|
||||
{
|
||||
return fdd[drive].turbo;
|
||||
}
|
||||
|
||||
|
||||
void fdd_set_check_bpb(int drive, int check_bpb)
|
||||
void
|
||||
fdd_set_check_bpb(int drive, int check_bpb)
|
||||
{
|
||||
fdd[drive].check_bpb = check_bpb;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
fdd_get_check_bpb(int drive)
|
||||
{
|
||||
return fdd[drive].check_bpb;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
fdd_get_densel(int drive)
|
||||
{
|
||||
return fdd[drive].densel;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
fdd_load(int drive, char *fn)
|
||||
{
|
||||
int c = 0, size;
|
||||
int c = 0, size;
|
||||
char *p;
|
||||
FILE *f;
|
||||
|
||||
fdd_log("FDD: loading drive %d with '%s'\n", drive, fn);
|
||||
|
||||
if (!fn)
|
||||
return;
|
||||
return;
|
||||
p = path_get_extension(fn);
|
||||
if (!p)
|
||||
return;
|
||||
return;
|
||||
f = plat_fopen(fn, "rb");
|
||||
if (f) {
|
||||
if (fseek(f, -1, SEEK_END) == -1)
|
||||
fatal("fdd_load(): Error seeking to the end of the file\n");
|
||||
size = ftell(f) + 1;
|
||||
fclose(f);
|
||||
while (loaders[c].ext) {
|
||||
if (!strcasecmp(p, (char *) loaders[c].ext) && (size == loaders[c].size || loaders[c].size == -1)) {
|
||||
driveloaders[drive] = c;
|
||||
if (floppyfns[drive] != fn) strcpy(floppyfns[drive], fn);
|
||||
d86f_setup(drive);
|
||||
loaders[c].load(drive, floppyfns[drive]);
|
||||
drive_empty[drive] = 0;
|
||||
fdd_forced_seek(drive, 0);
|
||||
fdd_changed[drive] = 1;
|
||||
return;
|
||||
}
|
||||
c++;
|
||||
}
|
||||
if (fseek(f, -1, SEEK_END) == -1)
|
||||
fatal("fdd_load(): Error seeking to the end of the file\n");
|
||||
size = ftell(f) + 1;
|
||||
fclose(f);
|
||||
while (loaders[c].ext) {
|
||||
if (!strcasecmp(p, (char *) loaders[c].ext) && (size == loaders[c].size || loaders[c].size == -1)) {
|
||||
driveloaders[drive] = c;
|
||||
if (floppyfns[drive] != fn)
|
||||
strcpy(floppyfns[drive], fn);
|
||||
d86f_setup(drive);
|
||||
loaders[c].load(drive, floppyfns[drive]);
|
||||
drive_empty[drive] = 0;
|
||||
fdd_forced_seek(drive, 0);
|
||||
fdd_changed[drive] = 1;
|
||||
return;
|
||||
}
|
||||
c++;
|
||||
}
|
||||
}
|
||||
fdd_log("FDD: could not load '%s' %s\n",fn,p);
|
||||
fdd_log("FDD: could not load '%s' %s\n", fn, p);
|
||||
drive_empty[drive] = 1;
|
||||
fdd_set_head(drive, 0);
|
||||
memset(floppyfns[drive], 0, sizeof(floppyfns[drive]));
|
||||
ui_sb_update_icon_state(SB_FLOPPY | drive, 1);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
fdd_close(int drive)
|
||||
{
|
||||
fdd_log("FDD: closing drive %d\n", drive);
|
||||
|
||||
d86f_stop(drive); /* Call this first of all to make sure the 86F poll is back to idle state. */
|
||||
d86f_stop(drive); /* Call this first of all to make sure the 86F poll is back to idle state. */
|
||||
if (loaders[driveloaders[drive]].close)
|
||||
loaders[driveloaders[drive]].close(drive);
|
||||
loaders[driveloaders[drive]].close(drive);
|
||||
drive_empty[drive] = 1;
|
||||
fdd_set_head(drive, 0);
|
||||
floppyfns[drive][0] = 0;
|
||||
drives[drive].hole = NULL;
|
||||
drives[drive].poll = NULL;
|
||||
drives[drive].seek = NULL;
|
||||
drives[drive].readsector = NULL;
|
||||
drives[drive].writesector = NULL;
|
||||
floppyfns[drive][0] = 0;
|
||||
drives[drive].hole = NULL;
|
||||
drives[drive].poll = NULL;
|
||||
drives[drive].seek = NULL;
|
||||
drives[drive].readsector = NULL;
|
||||
drives[drive].writesector = NULL;
|
||||
drives[drive].comparesector = NULL;
|
||||
drives[drive].readaddress = NULL;
|
||||
drives[drive].format = NULL;
|
||||
drives[drive].byteperiod = NULL;
|
||||
drives[drive].stop = NULL;
|
||||
drives[drive].readaddress = NULL;
|
||||
drives[drive].format = NULL;
|
||||
drives[drive].byteperiod = NULL;
|
||||
drives[drive].stop = NULL;
|
||||
d86f_destroy(drive);
|
||||
ui_sb_update_icon_state(SB_FLOPPY | drive, 1);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
fdd_hole(int drive)
|
||||
{
|
||||
if (drives[drive].hole)
|
||||
return drives[drive].hole(drive);
|
||||
return drives[drive].hole(drive);
|
||||
else
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static __inline uint64_t
|
||||
fdd_byteperiod(int drive)
|
||||
{
|
||||
if (!fdd_get_turbo(drive) && drives[drive].byteperiod)
|
||||
return drives[drive].byteperiod(drive);
|
||||
return drives[drive].byteperiod(drive);
|
||||
else
|
||||
return 32ULL * TIMER_USEC;
|
||||
return 32ULL * TIMER_USEC;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
fdd_set_motor_enable(int drive, int motor_enable)
|
||||
{
|
||||
/* I think here is where spin-up and spin-down should be implemented. */
|
||||
if (motor_enable && !motoron[drive])
|
||||
timer_set_delay_u64(&fdd_poll_time[drive], fdd_byteperiod(drive));
|
||||
timer_set_delay_u64(&fdd_poll_time[drive], fdd_byteperiod(drive));
|
||||
else if (!motor_enable)
|
||||
timer_disable(&fdd_poll_time[drive]);
|
||||
timer_disable(&fdd_poll_time[drive]);
|
||||
motoron[drive] = motor_enable;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
fdd_poll(void *priv)
|
||||
{
|
||||
int drive;
|
||||
int drive;
|
||||
DRIVE *drv = (DRIVE *) priv;
|
||||
|
||||
drive = drv->id;
|
||||
|
||||
if (drive >= FDD_NUM)
|
||||
fatal("Attempting to poll floppy drive %i that is not supposed to be there\n", drive);
|
||||
fatal("Attempting to poll floppy drive %i that is not supposed to be there\n", drive);
|
||||
|
||||
timer_advance_u64(&fdd_poll_time[drive], fdd_byteperiod(drive));
|
||||
|
||||
if (drv->poll)
|
||||
drv->poll(drive);
|
||||
drv->poll(drive);
|
||||
|
||||
if (fdd_notfound) {
|
||||
fdd_notfound--;
|
||||
if (!fdd_notfound)
|
||||
fdc_noidam(fdd_fdc);
|
||||
fdd_notfound--;
|
||||
if (!fdd_notfound)
|
||||
fdc_noidam(fdd_fdc);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
fdd_get_bitcell_period(int rate)
|
||||
{
|
||||
int bit_rate = 250;
|
||||
|
||||
switch (rate) {
|
||||
case 0: /*High density*/
|
||||
bit_rate = 500;
|
||||
break;
|
||||
case 1: /*Double density (360 rpm)*/
|
||||
bit_rate = 300;
|
||||
break;
|
||||
case 2: /*Double density*/
|
||||
bit_rate = 250;
|
||||
break;
|
||||
case 3: /*Extended density*/
|
||||
bit_rate = 1000;
|
||||
break;
|
||||
case 0: /*High density*/
|
||||
bit_rate = 500;
|
||||
break;
|
||||
case 1: /*Double density (360 rpm)*/
|
||||
bit_rate = 300;
|
||||
break;
|
||||
case 2: /*Double density*/
|
||||
bit_rate = 250;
|
||||
break;
|
||||
case 3: /*Extended density*/
|
||||
bit_rate = 1000;
|
||||
break;
|
||||
}
|
||||
|
||||
return 1000000 / bit_rate*2; /*Bitcell period in ns*/
|
||||
return 1000000 / bit_rate * 2; /*Bitcell period in ns*/
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
fdd_reset(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < FDD_NUM; i++) {
|
||||
drives[i].id = i;
|
||||
timer_add(&(fdd_poll_time[i]), fdd_poll, &drives[i], 0);
|
||||
drives[i].id = i;
|
||||
timer_add(&(fdd_poll_time[i]), fdd_poll, &drives[i], 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
fdd_readsector(int drive, int sector, int track, int side, int density, int sector_size)
|
||||
{
|
||||
if (drives[drive].readsector)
|
||||
drives[drive].readsector(drive, sector, track, side, density, sector_size);
|
||||
drives[drive].readsector(drive, sector, track, side, density, sector_size);
|
||||
else
|
||||
fdd_notfound = 1000;
|
||||
fdd_notfound = 1000;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
fdd_writesector(int drive, int sector, int track, int side, int density, int sector_size)
|
||||
{
|
||||
if (drives[drive].writesector)
|
||||
drives[drive].writesector(drive, sector, track, side, density, sector_size);
|
||||
drives[drive].writesector(drive, sector, track, side, density, sector_size);
|
||||
else
|
||||
fdd_notfound = 1000;
|
||||
fdd_notfound = 1000;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
fdd_comparesector(int drive, int sector, int track, int side, int density, int sector_size)
|
||||
{
|
||||
if (drives[drive].comparesector)
|
||||
drives[drive].comparesector(drive, sector, track, side, density, sector_size);
|
||||
drives[drive].comparesector(drive, sector, track, side, density, sector_size);
|
||||
else
|
||||
fdd_notfound = 1000;
|
||||
fdd_notfound = 1000;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
fdd_readaddress(int drive, int side, int density)
|
||||
{
|
||||
if (drives[drive].readaddress)
|
||||
drives[drive].readaddress(drive, side, density);
|
||||
drives[drive].readaddress(drive, side, density);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
fdd_format(int drive, int side, int density, uint8_t fill)
|
||||
{
|
||||
if (drives[drive].format)
|
||||
drives[drive].format(drive, side, density, fill);
|
||||
drives[drive].format(drive, side, density, fill);
|
||||
else
|
||||
fdd_notfound = 1000;
|
||||
fdd_notfound = 1000;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
fdd_stop(int drive)
|
||||
{
|
||||
if (drives[drive].stop)
|
||||
drives[drive].stop(drive);
|
||||
drives[drive].stop(drive);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
fdd_set_fdc(void *fdc)
|
||||
{
|
||||
fdd_fdc = (fdc_t *) fdc;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
fdd_init(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < FDD_NUM; i++) {
|
||||
drives[i].poll = 0;
|
||||
drives[i].seek = 0;
|
||||
drives[i].readsector = 0;
|
||||
drives[i].poll = 0;
|
||||
drives[i].seek = 0;
|
||||
drives[i].readsector = 0;
|
||||
}
|
||||
|
||||
img_init();
|
||||
@@ -720,7 +672,6 @@ fdd_init(void)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
fdd_do_writeback(int drive)
|
||||
{
|
||||
|
4047
src/floppy/fdd_86f.c
4047
src/floppy/fdd_86f.c
File diff suppressed because it is too large
Load Diff
@@ -24,7 +24,6 @@
|
||||
#include <86box/fdd.h>
|
||||
#include <86box/fdd_common.h>
|
||||
|
||||
|
||||
const uint8_t fdd_holes[6] = { 0, 0, 0, 1, 1, 2 };
|
||||
|
||||
const uint8_t fdd_rates[6] = { 2, 2, 1, 4, 0, 3 };
|
||||
@@ -59,11 +58,10 @@ const uint8_t fdd_max_sectors[8][6] = {
|
||||
{ 0, 0, 0, 0, 0, 1 } /* 16384 */
|
||||
};
|
||||
|
||||
const uint8_t fdd_dmf_r[21] = {
|
||||
12,2,13,3,14,4,15,5,16,6,17,7,18,8,19,9,20,10,21,11,1
|
||||
const uint8_t fdd_dmf_r[21] = {
|
||||
12, 2, 13, 3, 14, 4, 15, 5, 16, 6, 17, 7, 18, 8, 19, 9, 20, 10, 21, 11, 1
|
||||
};
|
||||
|
||||
|
||||
static const uint8_t fdd_gap3_sizes[5][8][48] = {
|
||||
{ { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* [0][0] */
|
||||
@@ -347,95 +345,90 @@ static const uint8_t fdd_gap3_sizes[5][8][48] = {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
int
|
||||
fdd_get_gap3_size(int rate, int size, int sector)
|
||||
{
|
||||
return(fdd_gap3_sizes[rate][size][sector]);
|
||||
return (fdd_gap3_sizes[rate][size][sector]);
|
||||
}
|
||||
|
||||
|
||||
uint8_t
|
||||
fdd_sector_size_code(int size)
|
||||
{
|
||||
int ret = 2;
|
||||
|
||||
switch(size) {
|
||||
case 128:
|
||||
ret = 0;
|
||||
break;
|
||||
switch (size) {
|
||||
case 128:
|
||||
ret = 0;
|
||||
break;
|
||||
|
||||
case 256:
|
||||
ret = 1;
|
||||
break;
|
||||
case 256:
|
||||
ret = 1;
|
||||
break;
|
||||
|
||||
case 512:
|
||||
ret = 2;
|
||||
break;
|
||||
case 512:
|
||||
ret = 2;
|
||||
break;
|
||||
|
||||
case 1024:
|
||||
ret = 3;
|
||||
break;
|
||||
case 1024:
|
||||
ret = 3;
|
||||
break;
|
||||
|
||||
case 2048:
|
||||
ret = 4;
|
||||
break;
|
||||
case 2048:
|
||||
ret = 4;
|
||||
break;
|
||||
|
||||
case 4096:
|
||||
ret = 5;
|
||||
break;
|
||||
case 4096:
|
||||
ret = 5;
|
||||
break;
|
||||
|
||||
case 8192:
|
||||
ret = 6;
|
||||
break;
|
||||
case 8192:
|
||||
ret = 6;
|
||||
break;
|
||||
|
||||
case 16384:
|
||||
ret = 7;
|
||||
break;
|
||||
case 16384:
|
||||
ret = 7;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return(ret);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
fdd_sector_code_size(uint8_t code)
|
||||
{
|
||||
return(128 << code);
|
||||
return (128 << code);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
fdd_bps_valid(uint16_t bps)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0; i<=8; i++) {
|
||||
if (bps == (128 << i)) {
|
||||
return 1;
|
||||
}
|
||||
for (i = 0; i <= 8; i++) {
|
||||
if (bps == (128 << i)) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return(0);
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
fdd_interleave(int sector, int skew, int spt)
|
||||
{
|
||||
uint32_t add = (spt & 1);
|
||||
uint32_t add = (spt & 1);
|
||||
uint32_t adjust = (spt >> 1);
|
||||
uint32_t adjusted_r;
|
||||
uint32_t skewed_i;
|
||||
|
||||
skewed_i = (sector + skew) % spt;
|
||||
skewed_i = (sector + skew) % spt;
|
||||
adjusted_r = (skewed_i >> 1) + 1;
|
||||
if (skewed_i & 1) {
|
||||
adjusted_r += (adjust + add);
|
||||
adjusted_r += (adjust + add);
|
||||
}
|
||||
|
||||
return(adjusted_r);
|
||||
return (adjusted_r);
|
||||
}
|
||||
|
@@ -36,73 +36,67 @@
|
||||
#include <86box/fdc.h>
|
||||
#include <fdi2raw.h>
|
||||
|
||||
|
||||
typedef struct {
|
||||
FILE *f;
|
||||
FDI *h;
|
||||
FILE *f;
|
||||
FDI *h;
|
||||
|
||||
int lasttrack;
|
||||
int sides;
|
||||
int track;
|
||||
int tracklen[2][4];
|
||||
int trackindex[2][4];
|
||||
int lasttrack;
|
||||
int sides;
|
||||
int track;
|
||||
int tracklen[2][4];
|
||||
int trackindex[2][4];
|
||||
|
||||
uint8_t track_data[2][4][256*1024];
|
||||
uint8_t track_timing[2][4][256*1024];
|
||||
uint8_t track_data[2][4][256 * 1024];
|
||||
uint8_t track_timing[2][4][256 * 1024];
|
||||
} fdi_t;
|
||||
|
||||
|
||||
static fdi_t *fdi[FDD_NUM];
|
||||
static fdc_t *fdi_fdc;
|
||||
|
||||
static fdi_t *fdi[FDD_NUM];
|
||||
static fdc_t *fdi_fdc;
|
||||
|
||||
#ifdef ENABLE_FDI_LOG
|
||||
int fdi_do_log = ENABLE_FDI_LOG;
|
||||
|
||||
|
||||
static void
|
||||
fdi_log(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_list ap;
|
||||
|
||||
if (fdi_do_log)
|
||||
{
|
||||
va_start(ap, fmt);
|
||||
pclog_ex(fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
if (fdi_do_log) {
|
||||
va_start(ap, fmt);
|
||||
pclog_ex(fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
}
|
||||
#else
|
||||
#define fdi_log(fmt, ...)
|
||||
# define fdi_log(fmt, ...)
|
||||
#endif
|
||||
|
||||
|
||||
static uint16_t
|
||||
disk_flags(int drive)
|
||||
{
|
||||
fdi_t *dev = fdi[drive];
|
||||
uint16_t temp_disk_flags = 0x80; /* We ALWAYS claim to have extra bit cells, even if the actual amount is 0. */
|
||||
fdi_t *dev = fdi[drive];
|
||||
uint16_t temp_disk_flags = 0x80; /* We ALWAYS claim to have extra bit cells, even if the actual amount is 0. */
|
||||
|
||||
switch (fdi2raw_get_bit_rate(dev->h)) {
|
||||
case 500:
|
||||
temp_disk_flags |= 2;
|
||||
break;
|
||||
case 500:
|
||||
temp_disk_flags |= 2;
|
||||
break;
|
||||
|
||||
case 300:
|
||||
case 250:
|
||||
temp_disk_flags |= 0;
|
||||
break;
|
||||
case 300:
|
||||
case 250:
|
||||
temp_disk_flags |= 0;
|
||||
break;
|
||||
|
||||
case 1000:
|
||||
temp_disk_flags |= 4;
|
||||
break;
|
||||
case 1000:
|
||||
temp_disk_flags |= 4;
|
||||
break;
|
||||
|
||||
default:
|
||||
temp_disk_flags |= 0;
|
||||
default:
|
||||
temp_disk_flags |= 0;
|
||||
}
|
||||
|
||||
if (dev->sides == 2)
|
||||
temp_disk_flags |= 8;
|
||||
temp_disk_flags |= 8;
|
||||
|
||||
/*
|
||||
* Tell the 86F handler that we will handle our
|
||||
@@ -110,39 +104,38 @@ disk_flags(int drive)
|
||||
*/
|
||||
temp_disk_flags |= 0x800;
|
||||
|
||||
return(temp_disk_flags);
|
||||
return (temp_disk_flags);
|
||||
}
|
||||
|
||||
|
||||
static uint16_t
|
||||
side_flags(int drive)
|
||||
{
|
||||
fdi_t *dev = fdi[drive];
|
||||
fdi_t *dev = fdi[drive];
|
||||
uint16_t temp_side_flags = 0;
|
||||
|
||||
switch (fdi2raw_get_bit_rate(dev->h)) {
|
||||
case 500:
|
||||
temp_side_flags = 0;
|
||||
break;
|
||||
case 500:
|
||||
temp_side_flags = 0;
|
||||
break;
|
||||
|
||||
case 300:
|
||||
temp_side_flags = 1;
|
||||
break;
|
||||
case 300:
|
||||
temp_side_flags = 1;
|
||||
break;
|
||||
|
||||
case 250:
|
||||
temp_side_flags = 2;
|
||||
break;
|
||||
case 250:
|
||||
temp_side_flags = 2;
|
||||
break;
|
||||
|
||||
case 1000:
|
||||
temp_side_flags = 3;
|
||||
break;
|
||||
case 1000:
|
||||
temp_side_flags = 3;
|
||||
break;
|
||||
|
||||
default:
|
||||
temp_side_flags = 2;
|
||||
default:
|
||||
temp_side_flags = 2;
|
||||
}
|
||||
|
||||
if (fdi2raw_get_rotation(dev->h) == 360)
|
||||
temp_side_flags |= 0x20;
|
||||
temp_side_flags |= 0x20;
|
||||
|
||||
/*
|
||||
* Set the encoding value to match that provided by the FDC.
|
||||
@@ -150,163 +143,158 @@ side_flags(int drive)
|
||||
*/
|
||||
temp_side_flags |= 0x08;
|
||||
|
||||
return(temp_side_flags);
|
||||
return (temp_side_flags);
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
fdi_density(void)
|
||||
{
|
||||
if (! fdc_is_mfm(fdi_fdc)) return(0);
|
||||
if (!fdc_is_mfm(fdi_fdc))
|
||||
return (0);
|
||||
|
||||
switch (fdc_get_bit_rate(fdi_fdc)) {
|
||||
case 0:
|
||||
return(2);
|
||||
case 0:
|
||||
return (2);
|
||||
|
||||
case 1:
|
||||
return(1);
|
||||
case 1:
|
||||
return (1);
|
||||
|
||||
case 2:
|
||||
return(1);
|
||||
case 2:
|
||||
return (1);
|
||||
|
||||
case 3:
|
||||
case 5:
|
||||
return(3);
|
||||
case 3:
|
||||
case 5:
|
||||
return (3);
|
||||
|
||||
default:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
|
||||
static int32_t
|
||||
extra_bit_cells(int drive, int side)
|
||||
{
|
||||
fdi_t *dev = fdi[drive];
|
||||
int density = 0;
|
||||
int raw_size = 0;
|
||||
int is_300_rpm = 0;
|
||||
fdi_t *dev = fdi[drive];
|
||||
int density = 0;
|
||||
int raw_size = 0;
|
||||
int is_300_rpm = 0;
|
||||
|
||||
density = fdi_density();
|
||||
|
||||
is_300_rpm = (fdd_getrpm(drive) == 300);
|
||||
|
||||
switch (fdc_get_bit_rate(fdi_fdc)) {
|
||||
case 0:
|
||||
raw_size = is_300_rpm ? 200000 : 166666;
|
||||
break;
|
||||
case 0:
|
||||
raw_size = is_300_rpm ? 200000 : 166666;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
raw_size = is_300_rpm ? 120000 : 100000;
|
||||
break;
|
||||
case 1:
|
||||
raw_size = is_300_rpm ? 120000 : 100000;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
raw_size = is_300_rpm ? 100000 : 83333;
|
||||
break;
|
||||
case 2:
|
||||
raw_size = is_300_rpm ? 100000 : 83333;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
case 5:
|
||||
raw_size = is_300_rpm ? 400000 : 333333;
|
||||
break;
|
||||
case 3:
|
||||
case 5:
|
||||
raw_size = is_300_rpm ? 400000 : 333333;
|
||||
break;
|
||||
|
||||
default:
|
||||
raw_size = is_300_rpm ? 100000 : 83333;
|
||||
default:
|
||||
raw_size = is_300_rpm ? 100000 : 83333;
|
||||
}
|
||||
|
||||
return((dev->tracklen[side][density] - raw_size));
|
||||
return ((dev->tracklen[side][density] - raw_size));
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
read_revolution(int drive)
|
||||
{
|
||||
fdi_t *dev = fdi[drive];
|
||||
int c, den, side;
|
||||
int track = dev->track;
|
||||
int c, den, side;
|
||||
int track = dev->track;
|
||||
|
||||
if (track > dev->lasttrack) {
|
||||
for (den = 0; den < 4; den++) {
|
||||
memset(dev->track_data[0][den], 0, 106096);
|
||||
memset(dev->track_data[1][den], 0, 106096);
|
||||
dev->tracklen[0][den] = dev->tracklen[1][den] = 100000;
|
||||
}
|
||||
return;
|
||||
for (den = 0; den < 4; den++) {
|
||||
memset(dev->track_data[0][den], 0, 106096);
|
||||
memset(dev->track_data[1][den], 0, 106096);
|
||||
dev->tracklen[0][den] = dev->tracklen[1][den] = 100000;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
for (den = 0; den < 4; den++) {
|
||||
for (side = 0; side < dev->sides; side++) {
|
||||
c = fdi2raw_loadtrack(dev->h,
|
||||
(uint16_t *)dev->track_data[side][den],
|
||||
(uint16_t *)dev->track_timing[side][den],
|
||||
(track * dev->sides) + side,
|
||||
&dev->tracklen[side][den],
|
||||
&dev->trackindex[side][den], NULL, den);
|
||||
if (! c)
|
||||
memset(dev->track_data[side][den], 0, dev->tracklen[side][den]);
|
||||
}
|
||||
for (side = 0; side < dev->sides; side++) {
|
||||
c = fdi2raw_loadtrack(dev->h,
|
||||
(uint16_t *) dev->track_data[side][den],
|
||||
(uint16_t *) dev->track_timing[side][den],
|
||||
(track * dev->sides) + side,
|
||||
&dev->tracklen[side][den],
|
||||
&dev->trackindex[side][den], NULL, den);
|
||||
if (!c)
|
||||
memset(dev->track_data[side][den], 0, dev->tracklen[side][den]);
|
||||
}
|
||||
|
||||
if (dev->sides == 1) {
|
||||
memset(dev->track_data[1][den], 0, 106096);
|
||||
dev->tracklen[1][den] = 100000;
|
||||
}
|
||||
if (dev->sides == 1) {
|
||||
memset(dev->track_data[1][den], 0, 106096);
|
||||
dev->tracklen[1][den] = 100000;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static uint32_t
|
||||
index_hole_pos(int drive, int side)
|
||||
{
|
||||
fdi_t *dev = fdi[drive];
|
||||
int density;
|
||||
int density;
|
||||
|
||||
density = fdi_density();
|
||||
|
||||
return(dev->trackindex[side][density]);
|
||||
return (dev->trackindex[side][density]);
|
||||
}
|
||||
|
||||
|
||||
static uint32_t
|
||||
get_raw_size(int drive, int side)
|
||||
{
|
||||
fdi_t *dev = fdi[drive];
|
||||
int density;
|
||||
int density;
|
||||
|
||||
density = fdi_density();
|
||||
|
||||
return(dev->tracklen[side][density]);
|
||||
return (dev->tracklen[side][density]);
|
||||
}
|
||||
|
||||
|
||||
static uint16_t *
|
||||
encoded_data(int drive, int side)
|
||||
{
|
||||
fdi_t *dev = fdi[drive];
|
||||
int density = 0;
|
||||
fdi_t *dev = fdi[drive];
|
||||
int density = 0;
|
||||
|
||||
density = fdi_density();
|
||||
|
||||
return((uint16_t *)dev->track_data[side][density]);
|
||||
return ((uint16_t *) dev->track_data[side][density]);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
fdi_seek(int drive, int track)
|
||||
{
|
||||
fdi_t *dev = fdi[drive];
|
||||
|
||||
if (fdd_doublestep_40(drive)) {
|
||||
if (fdi2raw_get_tpi(dev->h) < 2)
|
||||
track /= 2;
|
||||
if (fdi2raw_get_tpi(dev->h) < 2)
|
||||
track /= 2;
|
||||
}
|
||||
|
||||
d86f_set_cur_track(drive, track);
|
||||
|
||||
if (dev->f == NULL) return;
|
||||
if (dev->f == NULL)
|
||||
return;
|
||||
|
||||
if (track < 0)
|
||||
track = 0;
|
||||
track = 0;
|
||||
|
||||
#if 0
|
||||
if (track > dev->lasttrack)
|
||||
@@ -318,21 +306,20 @@ fdi_seek(int drive, int track)
|
||||
read_revolution(drive);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
fdi_load(int drive, char *fn)
|
||||
{
|
||||
char header[26];
|
||||
char header[26];
|
||||
fdi_t *dev;
|
||||
|
||||
writeprot[drive] = fwriteprot[drive] = 1;
|
||||
|
||||
/* Allocate a drive block. */
|
||||
dev = (fdi_t *)malloc(sizeof(fdi_t));
|
||||
dev = (fdi_t *) malloc(sizeof(fdi_t));
|
||||
|
||||
if (dev == NULL) {
|
||||
memset(floppyfns[drive], 0, sizeof(floppyfns[drive]));
|
||||
return;
|
||||
memset(floppyfns[drive], 0, sizeof(floppyfns[drive]));
|
||||
return;
|
||||
}
|
||||
|
||||
memset(dev, 0x00, sizeof(fdi_t));
|
||||
@@ -341,39 +328,39 @@ fdi_load(int drive, char *fn)
|
||||
|
||||
dev->f = plat_fopen(fn, "rb");
|
||||
if (fread(header, 1, 25, dev->f) != 25)
|
||||
fatal("fdi_load(): Error reading header\n");
|
||||
fatal("fdi_load(): Error reading header\n");
|
||||
if (fseek(dev->f, 0, SEEK_SET) == -1)
|
||||
fatal("fdi_load(): Error seeking to the beginning of the file\n");
|
||||
fatal("fdi_load(): Error seeking to the beginning of the file\n");
|
||||
header[25] = 0;
|
||||
if (strcmp(header, "Formatted Disk Image file") != 0) {
|
||||
/* This is a Japanese FDI file. */
|
||||
fdi_log("fdi_load(): Japanese FDI file detected, redirecting to IMG loader\n");
|
||||
fclose(dev->f);
|
||||
free(dev);
|
||||
img_load(drive, fn);
|
||||
return;
|
||||
/* This is a Japanese FDI file. */
|
||||
fdi_log("fdi_load(): Japanese FDI file detected, redirecting to IMG loader\n");
|
||||
fclose(dev->f);
|
||||
free(dev);
|
||||
img_load(drive, fn);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Set up the drive unit. */
|
||||
fdi[drive] = dev;
|
||||
|
||||
dev->h = fdi2raw_header(dev->f);
|
||||
dev->h = fdi2raw_header(dev->f);
|
||||
dev->lasttrack = fdi2raw_get_last_track(dev->h);
|
||||
dev->sides = fdi2raw_get_last_head(dev->h) + 1;
|
||||
dev->sides = fdi2raw_get_last_head(dev->h) + 1;
|
||||
|
||||
/* Attach this format to the D86F engine. */
|
||||
d86f_handler[drive].disk_flags = disk_flags;
|
||||
d86f_handler[drive].side_flags = side_flags;
|
||||
d86f_handler[drive].writeback = null_writeback;
|
||||
d86f_handler[drive].set_sector = null_set_sector;
|
||||
d86f_handler[drive].write_data = null_write_data;
|
||||
d86f_handler[drive].disk_flags = disk_flags;
|
||||
d86f_handler[drive].side_flags = side_flags;
|
||||
d86f_handler[drive].writeback = null_writeback;
|
||||
d86f_handler[drive].set_sector = null_set_sector;
|
||||
d86f_handler[drive].write_data = null_write_data;
|
||||
d86f_handler[drive].format_conditions = null_format_conditions;
|
||||
d86f_handler[drive].extra_bit_cells = extra_bit_cells;
|
||||
d86f_handler[drive].encoded_data = encoded_data;
|
||||
d86f_handler[drive].read_revolution = read_revolution;
|
||||
d86f_handler[drive].index_hole_pos = index_hole_pos;
|
||||
d86f_handler[drive].get_raw_size = get_raw_size;
|
||||
d86f_handler[drive].check_crc = 1;
|
||||
d86f_handler[drive].extra_bit_cells = extra_bit_cells;
|
||||
d86f_handler[drive].encoded_data = encoded_data;
|
||||
d86f_handler[drive].read_revolution = read_revolution;
|
||||
d86f_handler[drive].index_hole_pos = index_hole_pos;
|
||||
d86f_handler[drive].get_raw_size = get_raw_size;
|
||||
d86f_handler[drive].check_crc = 1;
|
||||
d86f_set_version(drive, D86FVER);
|
||||
|
||||
d86f_common_handlers(drive);
|
||||
@@ -383,32 +370,31 @@ fdi_load(int drive, char *fn)
|
||||
fdi_log("Loaded as FDI\n");
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
fdi_close(int drive)
|
||||
{
|
||||
fdi_t *dev = fdi[drive];
|
||||
|
||||
if (dev == NULL) return;
|
||||
if (dev == NULL)
|
||||
return;
|
||||
|
||||
d86f_unregister(drive);
|
||||
|
||||
drives[drive].seek = NULL;
|
||||
|
||||
if (dev->h)
|
||||
fdi2raw_header_free(dev->h);
|
||||
fdi2raw_header_free(dev->h);
|
||||
|
||||
if (dev->f)
|
||||
fclose(dev->f);
|
||||
fclose(dev->f);
|
||||
|
||||
/* Release the memory. */
|
||||
free(dev);
|
||||
fdi[drive] = NULL;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
fdi_set_fdc(void *fdc)
|
||||
{
|
||||
fdi_fdc = (fdc_t *)fdc;
|
||||
fdi_fdc = (fdc_t *) fdc;
|
||||
}
|
||||
|
1145
src/floppy/fdd_imd.c
1145
src/floppy/fdd_imd.c
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -31,177 +31,165 @@
|
||||
#include <86box/fdd_mfm.h>
|
||||
#include <86box/fdc.h>
|
||||
|
||||
|
||||
#pragma pack(push,1)
|
||||
#pragma pack(push, 1)
|
||||
typedef struct {
|
||||
uint8_t hdr_name[7];
|
||||
uint8_t hdr_name[7];
|
||||
|
||||
uint16_t tracks_no;
|
||||
uint8_t sides_no;
|
||||
uint16_t tracks_no;
|
||||
uint8_t sides_no;
|
||||
|
||||
uint16_t rpm;
|
||||
uint16_t bit_rate;
|
||||
uint8_t if_type;
|
||||
uint16_t rpm;
|
||||
uint16_t bit_rate;
|
||||
uint8_t if_type;
|
||||
|
||||
uint32_t track_list_offset;
|
||||
uint32_t track_list_offset;
|
||||
} mfm_header_t;
|
||||
|
||||
typedef struct {
|
||||
uint16_t track_no;
|
||||
uint8_t side_no;
|
||||
uint32_t track_size;
|
||||
uint32_t track_offset;
|
||||
uint16_t track_no;
|
||||
uint8_t side_no;
|
||||
uint32_t track_size;
|
||||
uint32_t track_offset;
|
||||
} mfm_track_t;
|
||||
|
||||
typedef struct {
|
||||
uint16_t track_no;
|
||||
uint8_t side_no;
|
||||
uint16_t rpm;
|
||||
uint16_t bit_rate;
|
||||
uint32_t track_size;
|
||||
uint32_t track_offset;
|
||||
uint16_t track_no;
|
||||
uint8_t side_no;
|
||||
uint16_t rpm;
|
||||
uint16_t bit_rate;
|
||||
uint32_t track_size;
|
||||
uint32_t track_offset;
|
||||
} mfm_adv_track_t;
|
||||
#pragma pack(pop)
|
||||
|
||||
typedef struct {
|
||||
FILE *f;
|
||||
FILE *f;
|
||||
|
||||
mfm_header_t hdr;
|
||||
mfm_track_t *tracks;
|
||||
mfm_adv_track_t *adv_tracks;
|
||||
mfm_header_t hdr;
|
||||
mfm_track_t *tracks;
|
||||
mfm_adv_track_t *adv_tracks;
|
||||
|
||||
uint16_t disk_flags, pad;
|
||||
uint16_t side_flags[2];
|
||||
uint16_t disk_flags, pad;
|
||||
uint16_t side_flags[2];
|
||||
|
||||
int br_rounded, rpm_rounded,
|
||||
total_tracks, cur_track;
|
||||
int br_rounded, rpm_rounded,
|
||||
total_tracks, cur_track;
|
||||
|
||||
uint8_t track_data[2][256*1024];
|
||||
uint8_t track_data[2][256 * 1024];
|
||||
} mfm_t;
|
||||
|
||||
|
||||
static mfm_t *mfm[FDD_NUM];
|
||||
static fdc_t *mfm_fdc;
|
||||
|
||||
static mfm_t *mfm[FDD_NUM];
|
||||
static fdc_t *mfm_fdc;
|
||||
|
||||
#ifdef ENABLE_MFM_LOG
|
||||
int mfm_do_log = ENABLE_MFM_LOG;
|
||||
|
||||
|
||||
static void
|
||||
mfm_log(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_list ap;
|
||||
|
||||
if (mfm_do_log)
|
||||
{
|
||||
va_start(ap, fmt);
|
||||
pclog_ex(fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
if (mfm_do_log) {
|
||||
va_start(ap, fmt);
|
||||
pclog_ex(fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
}
|
||||
#else
|
||||
#define mfm_log(fmt, ...)
|
||||
# define mfm_log(fmt, ...)
|
||||
#endif
|
||||
|
||||
|
||||
static int
|
||||
get_track_index(int drive, int side, int track)
|
||||
{
|
||||
mfm_t *dev = mfm[drive];
|
||||
int i, ret = -1;
|
||||
int i, ret = -1;
|
||||
|
||||
for (i = 0; i < dev->total_tracks; i++) {
|
||||
if ((dev->tracks[i].track_no == track) &&
|
||||
(dev->tracks[i].side_no == side)) {
|
||||
ret = i;
|
||||
break;
|
||||
}
|
||||
if ((dev->tracks[i].track_no == track) && (dev->tracks[i].side_no == side)) {
|
||||
ret = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
get_adv_track_index(int drive, int side, int track)
|
||||
{
|
||||
mfm_t *dev = mfm[drive];
|
||||
int i, ret = -1;
|
||||
int i, ret = -1;
|
||||
|
||||
for (i = 0; i < dev->total_tracks; i++) {
|
||||
if ((dev->adv_tracks[i].track_no == track) &&
|
||||
(dev->adv_tracks[i].side_no == side)) {
|
||||
ret = i;
|
||||
break;
|
||||
}
|
||||
if ((dev->adv_tracks[i].track_no == track) && (dev->adv_tracks[i].side_no == side)) {
|
||||
ret = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
get_adv_track_bitrate(int drive, int side, int track, int *br, int *rpm)
|
||||
{
|
||||
mfm_t *dev = mfm[drive];
|
||||
int track_index;
|
||||
int track_index;
|
||||
double dbr;
|
||||
|
||||
track_index = get_adv_track_index(drive, side, track);
|
||||
|
||||
if (track_index == -1) {
|
||||
*br = 250;
|
||||
*rpm = 300;
|
||||
*br = 250;
|
||||
*rpm = 300;
|
||||
} else {
|
||||
dbr = round(((double) dev->adv_tracks[track_index].bit_rate) / 50.0) * 50.0;
|
||||
*br = ((int) dbr);
|
||||
dbr = round(((double) dev->adv_tracks[track_index].rpm) / 60.0) * 60.0;
|
||||
*rpm = ((int) dbr);
|
||||
dbr = round(((double) dev->adv_tracks[track_index].bit_rate) / 50.0) * 50.0;
|
||||
*br = ((int) dbr);
|
||||
dbr = round(((double) dev->adv_tracks[track_index].rpm) / 60.0) * 60.0;
|
||||
*rpm = ((int) dbr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
set_disk_flags(int drive)
|
||||
{
|
||||
int br = 250, rpm = 300;
|
||||
mfm_t *dev = mfm[drive];
|
||||
uint16_t temp_disk_flags = 0x1080; /* We ALWAYS claim to have extra bit cells, even if the actual amount is 0;
|
||||
Bit 12 = 1, bits 6, 5 = 0 - extra bit cells field specifies the entire
|
||||
amount of bit cells per track. */
|
||||
int br = 250, rpm = 300;
|
||||
mfm_t *dev = mfm[drive];
|
||||
uint16_t temp_disk_flags = 0x1080; /* We ALWAYS claim to have extra bit cells, even if the actual amount is 0;
|
||||
Bit 12 = 1, bits 6, 5 = 0 - extra bit cells field specifies the entire
|
||||
amount of bit cells per track. */
|
||||
|
||||
/* If this is the modified MFM format, get bit rate (and RPM) from track 0 instead. */
|
||||
if (dev->hdr.if_type & 0x80)
|
||||
get_adv_track_bitrate(drive, 0, 0, &br, &rpm);
|
||||
get_adv_track_bitrate(drive, 0, 0, &br, &rpm);
|
||||
else {
|
||||
br = dev->br_rounded;
|
||||
rpm = dev->rpm_rounded;
|
||||
br = dev->br_rounded;
|
||||
rpm = dev->rpm_rounded;
|
||||
}
|
||||
|
||||
switch (br) {
|
||||
case 500:
|
||||
temp_disk_flags |= 2;
|
||||
break;
|
||||
case 500:
|
||||
temp_disk_flags |= 2;
|
||||
break;
|
||||
|
||||
case 300:
|
||||
case 250:
|
||||
default:
|
||||
temp_disk_flags |= 0;
|
||||
break;
|
||||
case 300:
|
||||
case 250:
|
||||
default:
|
||||
temp_disk_flags |= 0;
|
||||
break;
|
||||
|
||||
case 1000:
|
||||
temp_disk_flags |= 4;
|
||||
break;
|
||||
case 1000:
|
||||
temp_disk_flags |= 4;
|
||||
break;
|
||||
}
|
||||
|
||||
if (dev->hdr.sides_no == 2)
|
||||
temp_disk_flags |= 8;
|
||||
temp_disk_flags |= 8;
|
||||
|
||||
dev->disk_flags = temp_disk_flags;
|
||||
}
|
||||
|
||||
|
||||
static uint16_t
|
||||
disk_flags(int drive)
|
||||
{
|
||||
@@ -210,48 +198,47 @@ disk_flags(int drive)
|
||||
return dev->disk_flags;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
set_side_flags(int drive, int side)
|
||||
{
|
||||
mfm_t *dev = mfm[drive];
|
||||
mfm_t *dev = mfm[drive];
|
||||
uint16_t temp_side_flags = 0;
|
||||
int br = 250, rpm = 300;
|
||||
int br = 250, rpm = 300;
|
||||
|
||||
if (dev->hdr.if_type & 0x80)
|
||||
get_adv_track_bitrate(drive, side, dev->cur_track, &br, &rpm);
|
||||
get_adv_track_bitrate(drive, side, dev->cur_track, &br, &rpm);
|
||||
else {
|
||||
br = dev->br_rounded;
|
||||
rpm = dev->rpm_rounded;
|
||||
br = dev->br_rounded;
|
||||
rpm = dev->rpm_rounded;
|
||||
}
|
||||
|
||||
/* 300 kbps @ 360 rpm = 250 kbps @ 200 rpm */
|
||||
if ((br == 300) && (rpm == 360)) {
|
||||
br = 250;
|
||||
rpm = 300;
|
||||
br = 250;
|
||||
rpm = 300;
|
||||
}
|
||||
|
||||
switch (br) {
|
||||
case 500:
|
||||
temp_side_flags = 0;
|
||||
break;
|
||||
case 500:
|
||||
temp_side_flags = 0;
|
||||
break;
|
||||
|
||||
case 300:
|
||||
temp_side_flags = 1;
|
||||
break;
|
||||
case 300:
|
||||
temp_side_flags = 1;
|
||||
break;
|
||||
|
||||
case 250:
|
||||
default:
|
||||
temp_side_flags = 2;
|
||||
break;
|
||||
case 250:
|
||||
default:
|
||||
temp_side_flags = 2;
|
||||
break;
|
||||
|
||||
case 1000:
|
||||
temp_side_flags = 3;
|
||||
break;
|
||||
case 1000:
|
||||
temp_side_flags = 3;
|
||||
break;
|
||||
}
|
||||
|
||||
if (rpm == 360)
|
||||
temp_side_flags |= 0x20;
|
||||
temp_side_flags |= 0x20;
|
||||
|
||||
/*
|
||||
* Set the encoding value to match that provided by the FDC.
|
||||
@@ -262,112 +249,106 @@ set_side_flags(int drive, int side)
|
||||
dev->side_flags[side] = temp_side_flags;
|
||||
}
|
||||
|
||||
|
||||
static uint16_t
|
||||
side_flags(int drive)
|
||||
{
|
||||
mfm_t *dev = mfm[drive];
|
||||
int side;
|
||||
int side;
|
||||
|
||||
side = fdd_get_head(drive);
|
||||
|
||||
return dev->side_flags[side];
|
||||
}
|
||||
|
||||
|
||||
static uint32_t
|
||||
get_raw_size(int drive, int side)
|
||||
{
|
||||
mfm_t *dev = mfm[drive];
|
||||
int track_index, is_300_rpm;
|
||||
int br = 250, rpm = 300;
|
||||
int track_index, is_300_rpm;
|
||||
int br = 250, rpm = 300;
|
||||
|
||||
if (dev->hdr.if_type & 0x80) {
|
||||
track_index = get_adv_track_index(drive, side, dev->cur_track);
|
||||
get_adv_track_bitrate(drive, 0, 0, &br, &rpm);
|
||||
track_index = get_adv_track_index(drive, side, dev->cur_track);
|
||||
get_adv_track_bitrate(drive, 0, 0, &br, &rpm);
|
||||
} else {
|
||||
track_index = get_track_index(drive, side, dev->cur_track);
|
||||
br = dev->br_rounded;
|
||||
rpm = dev->rpm_rounded;
|
||||
track_index = get_track_index(drive, side, dev->cur_track);
|
||||
br = dev->br_rounded;
|
||||
rpm = dev->rpm_rounded;
|
||||
}
|
||||
|
||||
is_300_rpm = (rpm == 300);
|
||||
|
||||
if (track_index == -1) {
|
||||
mfm_log("MFM: Unable to find track (%i, %i)\n", dev->cur_track, side);
|
||||
switch (br) {
|
||||
case 250:
|
||||
default:
|
||||
return is_300_rpm ? 100000 : 83333;
|
||||
case 300:
|
||||
return is_300_rpm ? 120000 : 100000;
|
||||
case 500:
|
||||
return is_300_rpm ? 200000 : 166666;
|
||||
case 1000:
|
||||
return is_300_rpm ? 400000 : 333333;
|
||||
}
|
||||
mfm_log("MFM: Unable to find track (%i, %i)\n", dev->cur_track, side);
|
||||
switch (br) {
|
||||
case 250:
|
||||
default:
|
||||
return is_300_rpm ? 100000 : 83333;
|
||||
case 300:
|
||||
return is_300_rpm ? 120000 : 100000;
|
||||
case 500:
|
||||
return is_300_rpm ? 200000 : 166666;
|
||||
case 1000:
|
||||
return is_300_rpm ? 400000 : 333333;
|
||||
}
|
||||
}
|
||||
|
||||
/* Bit 7 on - my extension of the HxC MFM format to output exact bitcell counts
|
||||
for each track instead of rounded byte counts. */
|
||||
if (dev->hdr.if_type & 0x80)
|
||||
return dev->adv_tracks[track_index].track_size;
|
||||
return dev->adv_tracks[track_index].track_size;
|
||||
else
|
||||
return dev->tracks[track_index].track_size * 8;
|
||||
return dev->tracks[track_index].track_size * 8;
|
||||
}
|
||||
|
||||
|
||||
static int32_t
|
||||
extra_bit_cells(int drive, int side)
|
||||
{
|
||||
return (int32_t) get_raw_size(drive, side);
|
||||
}
|
||||
|
||||
|
||||
static uint16_t *
|
||||
encoded_data(int drive, int side)
|
||||
{
|
||||
mfm_t *dev = mfm[drive];
|
||||
|
||||
return((uint16_t *)dev->track_data[side]);
|
||||
return ((uint16_t *) dev->track_data[side]);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
mfm_read_side(int drive, int side)
|
||||
{
|
||||
mfm_t *dev = mfm[drive];
|
||||
int track_index, track_size;
|
||||
int track_bytes, ret;
|
||||
int track_index, track_size;
|
||||
int track_bytes, ret;
|
||||
|
||||
if (dev->hdr.if_type & 0x80)
|
||||
track_index = get_adv_track_index(drive, side, dev->cur_track);
|
||||
track_index = get_adv_track_index(drive, side, dev->cur_track);
|
||||
else
|
||||
track_index = get_track_index(drive, side, dev->cur_track);
|
||||
track_index = get_track_index(drive, side, dev->cur_track);
|
||||
|
||||
track_size = get_raw_size(drive, side);
|
||||
track_size = get_raw_size(drive, side);
|
||||
track_bytes = track_size >> 3;
|
||||
if (track_size & 0x07)
|
||||
track_bytes++;
|
||||
track_bytes++;
|
||||
|
||||
if (track_index == -1)
|
||||
memset(dev->track_data[side], 0x00, track_bytes);
|
||||
memset(dev->track_data[side], 0x00, track_bytes);
|
||||
else {
|
||||
if (dev->hdr.if_type & 0x80)
|
||||
ret = fseek(dev->f, dev->adv_tracks[track_index].track_offset, SEEK_SET);
|
||||
else
|
||||
ret = fseek(dev->f, dev->tracks[track_index].track_offset, SEEK_SET);
|
||||
if (ret == -1)
|
||||
fatal("mfm_read_side(): Error seeking to the beginning of the file\n");
|
||||
if (fread(dev->track_data[side], 1, track_bytes, dev->f) != track_bytes)
|
||||
fatal("mfm_read_side(): Error reading track bytes\n");
|
||||
if (dev->hdr.if_type & 0x80)
|
||||
ret = fseek(dev->f, dev->adv_tracks[track_index].track_offset, SEEK_SET);
|
||||
else
|
||||
ret = fseek(dev->f, dev->tracks[track_index].track_offset, SEEK_SET);
|
||||
if (ret == -1)
|
||||
fatal("mfm_read_side(): Error seeking to the beginning of the file\n");
|
||||
if (fread(dev->track_data[side], 1, track_bytes, dev->f) != track_bytes)
|
||||
fatal("mfm_read_side(): Error reading track bytes\n");
|
||||
}
|
||||
|
||||
mfm_log("drive = %i, side = %i, dev->cur_track = %i, track_index = %i, track_size = %i\n",
|
||||
drive, side, dev->cur_track, track_index, track_size);
|
||||
drive, side, dev->cur_track, track_index, track_size);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
mfm_seek(int drive, int track)
|
||||
{
|
||||
@@ -376,18 +357,18 @@ mfm_seek(int drive, int track)
|
||||
mfm_log("mfm_seek(%i, %i)\n", drive, track);
|
||||
|
||||
if (fdd_doublestep_40(drive)) {
|
||||
if (dev->hdr.tracks_no <= 43)
|
||||
track /= 2;
|
||||
if (dev->hdr.tracks_no <= 43)
|
||||
track /= 2;
|
||||
}
|
||||
|
||||
dev->cur_track = track;
|
||||
d86f_set_cur_track(drive, track);
|
||||
|
||||
if (dev->f == NULL)
|
||||
return;
|
||||
return;
|
||||
|
||||
if (track < 0)
|
||||
track = 0;
|
||||
track = 0;
|
||||
|
||||
mfm_read_side(drive, 0);
|
||||
mfm_read_side(drive, 1);
|
||||
@@ -396,25 +377,24 @@ mfm_seek(int drive, int track)
|
||||
set_side_flags(drive, 1);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
mfm_load(int drive, char *fn)
|
||||
{
|
||||
mfm_t *dev;
|
||||
double dbr;
|
||||
int i, size;
|
||||
int i, size;
|
||||
|
||||
writeprot[drive] = fwriteprot[drive] = 1;
|
||||
|
||||
/* Allocate a drive block. */
|
||||
dev = (mfm_t *)malloc(sizeof(mfm_t));
|
||||
dev = (mfm_t *) malloc(sizeof(mfm_t));
|
||||
memset(dev, 0x00, sizeof(mfm_t));
|
||||
|
||||
dev->f = plat_fopen(fn, "rb");
|
||||
if (dev->f == NULL) {
|
||||
free(dev);
|
||||
memset(floppyfns[drive], 0, sizeof(floppyfns[drive]));
|
||||
return;
|
||||
free(dev);
|
||||
memset(floppyfns[drive], 0, sizeof(floppyfns[drive]));
|
||||
return;
|
||||
}
|
||||
|
||||
d86f_unregister(drive);
|
||||
@@ -422,20 +402,20 @@ mfm_load(int drive, char *fn)
|
||||
/* Read the header. */
|
||||
size = sizeof(mfm_header_t);
|
||||
if (fread(&dev->hdr, 1, size, dev->f) != size)
|
||||
fatal("mfm_load(): Error reading header\n");
|
||||
fatal("mfm_load(): Error reading header\n");
|
||||
|
||||
/* Calculate tracks * sides, allocate the tracks array, and read it. */
|
||||
dev->total_tracks = dev->hdr.tracks_no * dev->hdr.sides_no;
|
||||
if (dev->hdr.if_type & 0x80) {
|
||||
dev->adv_tracks = (mfm_adv_track_t *) malloc(dev->total_tracks * sizeof(mfm_adv_track_t));
|
||||
size = dev->total_tracks * sizeof(mfm_adv_track_t);
|
||||
if (fread(dev->adv_tracks, 1, size, dev->f) != size)
|
||||
fatal("mfm_load(): Error reading advanced tracks\n");
|
||||
dev->adv_tracks = (mfm_adv_track_t *) malloc(dev->total_tracks * sizeof(mfm_adv_track_t));
|
||||
size = dev->total_tracks * sizeof(mfm_adv_track_t);
|
||||
if (fread(dev->adv_tracks, 1, size, dev->f) != size)
|
||||
fatal("mfm_load(): Error reading advanced tracks\n");
|
||||
} else {
|
||||
dev->tracks = (mfm_track_t *) malloc(dev->total_tracks * sizeof(mfm_track_t));
|
||||
size = dev->total_tracks * sizeof(mfm_track_t);
|
||||
if (fread(dev->tracks, 1, size, dev->f) != size)
|
||||
fatal("mfm_load(): Error reading tracks\n");
|
||||
dev->tracks = (mfm_track_t *) malloc(dev->total_tracks * sizeof(mfm_track_t));
|
||||
size = dev->total_tracks * sizeof(mfm_track_t);
|
||||
if (fread(dev->tracks, 1, size, dev->f) != size)
|
||||
fatal("mfm_load(): Error reading tracks\n");
|
||||
}
|
||||
|
||||
/* The chances of finding a HxC MFM image of a single-sided thin track
|
||||
@@ -444,30 +424,30 @@ mfm_load(int drive, char *fn)
|
||||
side and 80+ tracks instead of 2 sides and <= 43 tracks, so if we
|
||||
have detected such an image, convert the track numbers. */
|
||||
if ((dev->hdr.tracks_no > 43) && (dev->hdr.sides_no == 1)) {
|
||||
dev->hdr.tracks_no >>= 1;
|
||||
dev->hdr.sides_no <<= 1;
|
||||
dev->hdr.tracks_no >>= 1;
|
||||
dev->hdr.sides_no <<= 1;
|
||||
|
||||
for (i = 0; i < dev->total_tracks; i++) {
|
||||
if (dev->hdr.if_type & 0x80) {
|
||||
dev->adv_tracks[i].side_no <<= 1;
|
||||
dev->adv_tracks[i].side_no |= (dev->adv_tracks[i].track_no & 1);
|
||||
dev->adv_tracks[i].track_no >>= 1;
|
||||
} else {
|
||||
dev->tracks[i].side_no <<= 1;
|
||||
dev->tracks[i].side_no |= (dev->tracks[i].track_no & 1);
|
||||
dev->tracks[i].track_no >>= 1;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < dev->total_tracks; i++) {
|
||||
if (dev->hdr.if_type & 0x80) {
|
||||
dev->adv_tracks[i].side_no <<= 1;
|
||||
dev->adv_tracks[i].side_no |= (dev->adv_tracks[i].track_no & 1);
|
||||
dev->adv_tracks[i].track_no >>= 1;
|
||||
} else {
|
||||
dev->tracks[i].side_no <<= 1;
|
||||
dev->tracks[i].side_no |= (dev->tracks[i].track_no & 1);
|
||||
dev->tracks[i].track_no >>= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!(dev->hdr.if_type & 0x80)) {
|
||||
dbr = round(((double) dev->hdr.bit_rate) / 50.0) * 50.0;
|
||||
dev->br_rounded = (int) dbr;
|
||||
mfm_log("Rounded bit rate: %i kbps\n", dev->br_rounded);
|
||||
dbr = round(((double) dev->hdr.bit_rate) / 50.0) * 50.0;
|
||||
dev->br_rounded = (int) dbr;
|
||||
mfm_log("Rounded bit rate: %i kbps\n", dev->br_rounded);
|
||||
|
||||
dbr = round(((double) dev->hdr.rpm) / 60.0) * 60.0;
|
||||
dev->rpm_rounded = (int) dbr;
|
||||
mfm_log("Rounded RPM: %i kbps\n", dev->rpm_rounded);
|
||||
dbr = round(((double) dev->hdr.rpm) / 60.0) * 60.0;
|
||||
dev->rpm_rounded = (int) dbr;
|
||||
mfm_log("Rounded RPM: %i kbps\n", dev->rpm_rounded);
|
||||
}
|
||||
|
||||
/* Set up the drive unit. */
|
||||
@@ -476,18 +456,18 @@ mfm_load(int drive, char *fn)
|
||||
set_disk_flags(drive);
|
||||
|
||||
/* Attach this format to the D86F engine. */
|
||||
d86f_handler[drive].disk_flags = disk_flags;
|
||||
d86f_handler[drive].side_flags = side_flags;
|
||||
d86f_handler[drive].writeback = null_writeback;
|
||||
d86f_handler[drive].set_sector = null_set_sector;
|
||||
d86f_handler[drive].write_data = null_write_data;
|
||||
d86f_handler[drive].disk_flags = disk_flags;
|
||||
d86f_handler[drive].side_flags = side_flags;
|
||||
d86f_handler[drive].writeback = null_writeback;
|
||||
d86f_handler[drive].set_sector = null_set_sector;
|
||||
d86f_handler[drive].write_data = null_write_data;
|
||||
d86f_handler[drive].format_conditions = null_format_conditions;
|
||||
d86f_handler[drive].extra_bit_cells = extra_bit_cells;
|
||||
d86f_handler[drive].encoded_data = encoded_data;
|
||||
d86f_handler[drive].read_revolution = common_read_revolution;
|
||||
d86f_handler[drive].index_hole_pos = null_index_hole_pos;
|
||||
d86f_handler[drive].get_raw_size = get_raw_size;
|
||||
d86f_handler[drive].check_crc = 1;
|
||||
d86f_handler[drive].extra_bit_cells = extra_bit_cells;
|
||||
d86f_handler[drive].encoded_data = encoded_data;
|
||||
d86f_handler[drive].read_revolution = common_read_revolution;
|
||||
d86f_handler[drive].index_hole_pos = null_index_hole_pos;
|
||||
d86f_handler[drive].get_raw_size = get_raw_size;
|
||||
d86f_handler[drive].check_crc = 1;
|
||||
d86f_set_version(drive, D86FVER);
|
||||
|
||||
d86f_common_handlers(drive);
|
||||
@@ -497,35 +477,34 @@ mfm_load(int drive, char *fn)
|
||||
mfm_log("Loaded as MFM\n");
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
mfm_close(int drive)
|
||||
{
|
||||
mfm_t *dev = mfm[drive];
|
||||
|
||||
if (dev == NULL) return;
|
||||
if (dev == NULL)
|
||||
return;
|
||||
|
||||
d86f_unregister(drive);
|
||||
|
||||
drives[drive].seek = NULL;
|
||||
|
||||
if (dev->tracks)
|
||||
free(dev->tracks);
|
||||
free(dev->tracks);
|
||||
|
||||
if (dev->adv_tracks)
|
||||
free(dev->adv_tracks);
|
||||
free(dev->adv_tracks);
|
||||
|
||||
if (dev->f)
|
||||
fclose(dev->f);
|
||||
fclose(dev->f);
|
||||
|
||||
/* Release the memory. */
|
||||
free(dev);
|
||||
mfm[drive] = NULL;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
mfm_set_fdc(void *fdc)
|
||||
{
|
||||
mfm_fdc = (fdc_t *)fdc;
|
||||
mfm_fdc = (fdc_t *) fdc;
|
||||
}
|
||||
|
2978
src/floppy/fdi2raw.c
2978
src/floppy/fdi2raw.c
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user