From 04193fb1996363f2c18b2fe5e3acc1ea684a63dc Mon Sep 17 00:00:00 2001 From: OBattler Date: Mon, 23 Mar 2020 09:02:32 +0100 Subject: [PATCH] Floppy changes. --- src/floppy/fdc.c | 47 +++++++++++++++++++++++++------------------- src/floppy/fdc.h | 2 +- src/floppy/fdd_86f.c | 2 +- 3 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/floppy/fdc.c b/src/floppy/fdc.c index 81274199c..d4eebc796 100644 --- a/src/floppy/fdc.c +++ b/src/floppy/fdc.c @@ -702,10 +702,6 @@ fdc_write(uint16_t addr, uint8_t val, void *priv) fdc->stat = 0x00; fdc->pnum = fdc->ptot = 0; } - if (val&4) { - fdc->stat = 0x80; - fdc->pnum = fdc->ptot = 0; - } if ((val&4) && !(fdc->dor&4)) { timer_set_delay_u64(&fdc->timer, 8 * TIMER_USEC); fdc->interrupt = -1; @@ -775,7 +771,16 @@ fdc_write(uint16_t addr, uint8_t val, void *priv) fdc->stat |= 0x10; fdc_log("Starting FDC command %02X\n",fdc->command); - switch (fdc->command & 0x1f) { + if (((fdc->command & 0x1f) == 0x02) || ((fdc->command & 0x1f) == 0x05) || + ((fdc->command & 0x1f) == 0x06) || ((fdc->command & 0x1f) == 0x0a) || + ((fdc->command & 0x1f) == 0x0c) || ((fdc->command & 0x1f) == 0x0d) || + ((fdc->command & 0x1f) == 0x11) || ((fdc->command & 0x1f) == 0x16) || + ((fdc->command & 0x1f) == 0x19) || ((fdc->command & 0x1f) == 0x1d)) + fdc->processed_cmd = fdc->command & 0x1f; + else + fdc->processed_cmd = fdc->command; + + switch (fdc->processed_cmd) { case 0x01: /*Mode*/ if (fdc->flags & FDC_FLAG_NSC) { fdc->pnum = 0; @@ -921,7 +926,7 @@ fdc_write(uint16_t addr, uint8_t val, void *priv) } if (fdc->pnum == fdc->ptot) { fdc_log("Got all params %02X\n", fdc->command); - fdc->interrupt = fdc->command & 0x1F; + fdc->interrupt = fdc->processed_cmd; fdc->reset_stat = 0; /* Disable timer if enabled. */ timer_disable(&fdc->timer); @@ -950,7 +955,7 @@ fdc_write(uint16_t addr, uint8_t val, void *priv) break; } /* Process the firt phase of the command. */ - switch (fdc->interrupt & 0x1F) { + switch (fdc->processed_cmd) { case 0x02: /* Read a track */ fdc_io_command_phase1(fdc, 0); fdc->read_track_sector.id.c = fdc->params[1]; @@ -1072,7 +1077,8 @@ fdc_write(uint16_t addr, uint8_t val, void *priv) fdc->stat = (1 << fdc->drive); if (!(fdc->flags & FDC_FLAG_PCJR)) fdc->stat |= 0x80; - fdc->head = (fdc->params[0] & 4) ? 1 : 0; + /* fdc->head = (fdc->params[0] & 4) ? 1 : 0; */ + fdc->head = 0; /* TODO: See if this is correct. */ fdc->st0 = fdc->params[0] & 0x03; fdc->st0 |= (fdc->params[0] & 4); fdc->st0 |= 0x80; @@ -1210,21 +1216,22 @@ fdc_read(uint16_t addr, void *priv) } } else { if (is486 || !fdc->enable_3f1) - return 0xff; + ret = 0xff; + else { + ret = 0x70; - ret = 0x70; + drive = real_drive(fdc, fdc->dor & 3); - drive = real_drive(fdc, fdc->dor & 3); + if (drive) + ret &= ~0x40; + else + ret &= ~0x20; - if (drive) - ret &= ~0x40; - else - ret &= ~0x20; - - if (fdc->dor & 0x10) - ret |= 1; - if (fdc->dor & 0x20) - ret |= 2; + if (fdc->dor & 0x10) + ret |= 1; + if (fdc->dor & 0x20) + ret |= 2; + } } break; case 2: diff --git a/src/floppy/fdc.h b/src/floppy/fdc.h index 786d1bfe5..4fae14c62 100644 --- a/src/floppy/fdc.h +++ b/src/floppy/fdc.h @@ -36,7 +36,7 @@ typedef struct { - uint8_t dor, stat, command, dat, st0, swap; + uint8_t dor, stat, command, processed_cmd, dat, st0, swap; uint8_t swwp, disable_write; uint8_t params[256], res[256]; uint8_t specify[256], format_dat[256]; diff --git a/src/floppy/fdd_86f.c b/src/floppy/fdd_86f.c index d55f86734..8eb4d0f42 100644 --- a/src/floppy/fdd_86f.c +++ b/src/floppy/fdd_86f.c @@ -826,7 +826,7 @@ d86f_byteperiod(int drive) int d86f_is_mfm(int drive) { - return (d86f_track_flags(drive) & 8) ? 1 : 0; + return ((d86f_track_flags(drive) & 0x18) == 0x08) ? 1 : 0; }