Skip to content

Commit

Permalink
upd765: Fix Speedlock copy protection regression.
Browse files Browse the repository at this point in the history
  • Loading branch information
mizapf committed Mar 6, 2019
1 parent a31aad3 commit 9a5e311
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions src/devices/machine/upd765.cpp
Expand Up @@ -18,6 +18,7 @@
#define LOG_MATCH (1U << 10) // Sector matching
#define LOG_STATE (1U << 11) // State machine
#define LOG_LIVE (1U << 12) // Live states
#define LOG_DONE (1U << 13) // Command done

#define VERBOSE (LOG_GENERAL | LOG_WARN )

Expand All @@ -38,6 +39,7 @@
#define LOGMATCH(...) LOGMASKED(LOG_MATCH, __VA_ARGS__)
#define LOGSTATE(...) LOGMASKED(LOG_STATE, __VA_ARGS__)
#define LOGLIVE(...) LOGMASKED(LOG_LIVE, __VA_ARGS__)
#define LOGDONE(...) LOGMASKED(LOG_DONE, __VA_ARGS__)

DEFINE_DEVICE_TYPE(UPD765A, upd765a_device, "upd765a", "NEC uPD765A FDC")
DEFINE_DEVICE_TYPE(UPD765B, upd765b_device, "upd765b", "NEC uPD765B FDC")
Expand Down Expand Up @@ -1484,7 +1486,7 @@ void upd765_family_device::execute_command(int cmd)

void upd765_family_device::command_end(floppy_info &fi, bool data_completion)
{
LOGCOMMAND("command done (%s) - %s\n", data_completion ? "data" : "seek", results());
LOGDONE("command done (%s) - %s\n", data_completion ? "data" : "seek", results());
fi.main_state = fi.sub_state = IDLE;
if(data_completion)
data_irq = true;
Expand Down Expand Up @@ -1756,7 +1758,16 @@ void upd765_family_device::read_data_continue(floppy_info &fi)
fi.sub_state = COMMAND_DONE;
break;
}
// MZ: This st1 handling ensures that both HX5102 floppy and the
// Speedlock protection scheme are properly working.
// a) HX5102 requires that the ND flag not be set when no address
// marks could be found on the track at all (particularly due to
// wrong density)
// b) Speedlock requires the ND flag be set when there are valid
// sectors on the track, but the desired sector is missing, also
// when it has no valid address marks
st1 &= ~ST1_MA;
st1 |= ST1_ND;
if(!sector_matches()) {
if(cur_live.idbuf[0] != command[2]) {
if(cur_live.idbuf[0] == 0xff)
Expand All @@ -1768,6 +1779,7 @@ void upd765_family_device::read_data_continue(floppy_info &fi)
live_start(fi, SEARCH_ADDRESS_MARK_HEADER);
return;
}
st1 &= ~ST1_ND;
LOGRW("reading sector %02x %02x %02x %02x\n",
cur_live.idbuf[0],
cur_live.idbuf[1],
Expand All @@ -1786,11 +1798,6 @@ void upd765_family_device::read_data_continue(floppy_info &fi)
case SCAN_ID_FAILED:
LOGSTATE("SCAN_ID_FAILED\n");
fi.st0 |= ST0_FAIL;
// MZ: The HX5102 does not correctly detect a FM/MFM mismatch
// when the ND bit is set, because in the firmware the ND bit wins
// against MA, and thus concludes that the format is correct
// but the sector is missing.
// st1 |= ST1_ND;
fi.sub_state = COMMAND_DONE;
break;

Expand Down Expand Up @@ -1862,7 +1869,7 @@ void upd765_family_device::write_data_start(floppy_info &fi)
fi.main_state = WRITE_DATA;
fi.sub_state = HEAD_LOAD;
mfm = command[0] & 0x40;
LOGRW("command write%s data%s%s cmd=%02x sel=%x chrn=(%d, %d, %d, %d) eot=%02x gpl=%02x dtl=%02x rate=%d\n",
LOGCOMMAND("command write%s data%s%s cmd=%02x sel=%x chrn=(%d, %d, %d, %d) eot=%02x gpl=%02x dtl=%02x rate=%d\n",
command[0] & 0x08 ? " deleted" : "",
command[0] & 0x80 ? " mt" : "",
command[0] & 0x40 ? " mfm" : "",
Expand Down Expand Up @@ -1930,6 +1937,11 @@ void upd765_family_device::write_data_continue(floppy_info &fi)
break;
}
st1 &= ~ST1_MA;
LOGRW("writing sector %02x %02x %02x %02x\n",
cur_live.idbuf[0],
cur_live.idbuf[1],
cur_live.idbuf[2],
cur_live.idbuf[3]);
sector_size = calc_sector_size(cur_live.idbuf[3]);
fifo_expect(sector_size, true);
fi.sub_state = SECTOR_WRITTEN;
Expand Down Expand Up @@ -2002,7 +2014,7 @@ void upd765_family_device::read_track_start(floppy_info &fi)
mfm = command[0] & 0x40;
sectors_read = 0;

LOGRW("command read track%s cmd=%02x sel=%x chrn=(%d, %d, %d, %d) eot=%02x gpl=%02x dtl=%02x rate=%d\n",
LOGCOMMAND("command read track%s cmd=%02x sel=%x chrn=(%d, %d, %d, %d) eot=%02x gpl=%02x dtl=%02x rate=%d\n",
command[0] & 0x40 ? " mfm" : "",
command[0],
command[1],
Expand Down Expand Up @@ -2326,8 +2338,7 @@ void upd765_family_device::read_id_continue(floppy_info &fi)
case SCAN_ID_FAILED:
LOGSTATE("SCAN_ID_FAILED\n");
fi.st0 |= ST0_FAIL;
// st1 |= ST1_ND|ST1_MA;
st1 = ST1_MA;
st1 |= ST1_ND|ST1_MA;
fi.sub_state = COMMAND_DONE;
break;

Expand Down

6 comments on commit 9a5e311

@Tafoid
Copy link
Contributor

@Tafoid Tafoid commented on 9a5e311 Mar 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears to have caused a regression - showing error 301 (I think that is a keyboard error):
mk88 - pc.cpp
mk88-diff

@mizapf
Copy link
Member Author

@mizapf mizapf commented on 9a5e311 Mar 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A keyboard error from a change in a floppy controller? Where is mk88-pc? (I just found mk85)

@Tafoid
Copy link
Contributor

@Tafoid Tafoid commented on 9a5e311 Mar 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mk88 is a machine in MAME. The setname and romset should match up to that name "mk88.zip", clone of ibm5150. 301 code is only a guess -I've seen it attributed to keyboard/communication failure before - it might mean something different in this machine?

@Tafoid
Copy link
Contributor

@Tafoid Tafoid commented on 9a5e311 Mar 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry. This might also be one for mc6845 changes .. or even emumem changes eb1b8e5 which I cannot predict effects what. If I've flagged you incorrectly, I apologize. Both "Motorola MC6845 CRTC" and "NEC uPD765A FDC" triggered testing.

@mizapf
Copy link
Member Author

@mizapf mizapf commented on 9a5e311 Mar 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem; I'll wait until you find more evidence. It's really like Rubik's Cube - once you think one face is done, you messed up another one.

@AmatCoder
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is caused by commit c4f0852
I have created a pull request to fix it #4733 (without breaking previous improvements)

Please sign in to comment.