From 5476ca39d50872c36411628353f82eab453b7ae4 Mon Sep 17 00:00:00 2001 From: Phil Pemberton Date: Mon, 24 Jul 2023 15:22:02 +0100 Subject: [PATCH 1/2] Add support for HFE v3 OPCODE_RAND (fixes Sherston games with weak sector protection) --- src/disc_hfe.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/disc_hfe.c b/src/disc_hfe.c index 52c6b15..25a3bab 100644 --- a/src/disc_hfe.c +++ b/src/disc_hfe.c @@ -289,7 +289,8 @@ static void process_v3_track(mfm_t *mfm, int side) break; case HFE_V3_OPCODE_RAND: - /*Not currently implemented, just add a byte of zeroes*/ + /* Insert random byte - used for 'weak sector' protection on e.g. Sherston */ + mfm->track_data[side][wp >> 3] = rand() & 0xFF; wp += 8; break; From f51d93682b1e4ec7fb025e2898b2df754fba8b48 Mon Sep 17 00:00:00 2001 From: Philip Pemberton Date: Sat, 27 Jan 2024 10:06:10 +0000 Subject: [PATCH 2/2] Properly handle RAND data when output buffer isn't aligned --- src/disc_hfe.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/disc_hfe.c b/src/disc_hfe.c index 25a3bab..bf6a2ff 100644 --- a/src/disc_hfe.c +++ b/src/disc_hfe.c @@ -289,9 +289,18 @@ static void process_v3_track(mfm_t *mfm, int side) break; case HFE_V3_OPCODE_RAND: - /* Insert random byte - used for 'weak sector' protection on e.g. Sherston */ - mfm->track_data[side][wp >> 3] = rand() & 0xFF; - wp += 8; + { + uint8_t data = rand() & 0xFF; + int bit; + + /* Insert random byte - used for 'weak sector' protection on e.g. Sherston */ + for (bit = 0; bit < 8; bit++) { + if (data & 0x80) + mfm->track_data[side][wp >> 3] |= 0x80 >> (wp & 7); + data <<= 1; + wp++; + } + } break; default: