From 6c84387ec005e0b77644aaa8ca9a2b9e3e371582 Mon Sep 17 00:00:00 2001 From: Peter Schorn Date: Tue, 18 Feb 2020 11:55:29 +0100 Subject: [PATCH] AltairZ80: Fix error handling of bad IMD disks and sector size computation --- AltairZ80/altairz80_hdsk.c | 4 +++- sim_imd.c | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/AltairZ80/altairz80_hdsk.c b/AltairZ80/altairz80_hdsk.c index fd96c543..9a2f449b 100644 --- a/AltairZ80/altairz80_hdsk.c +++ b/AltairZ80/altairz80_hdsk.c @@ -449,8 +449,10 @@ static t_stat hdsk_attach(UNIT *uptr, CONST char *cptr) { hdsk_imd[thisUnitIndex] = diskOpenEx(uptr -> fileref, sim_deb && (hdsk_dev.dctrl & VERBOSE_MSG), &hdsk_dev, VERBOSE_MSG, VERBOSE_MSG); - if (hdsk_imd[thisUnitIndex] == NULL) + if (hdsk_imd[thisUnitIndex] == NULL) { + detach_unit(uptr); return SCPE_IOERR; + } verifyDiskInfo(hdsk_imd[thisUnitIndex], '0' + thisUnitIndex); uptr -> HDSK_NUMBER_OF_TRACKS = hdsk_imd[thisUnitIndex] -> ntracks; uptr -> HDSK_SECTORS_PER_TRACK = hdsk_imd[thisUnitIndex] -> track[1][0].nsects; diff --git a/sim_imd.c b/sim_imd.c index b1d09499..fab8f6af 100644 --- a/sim_imd.c +++ b/sim_imd.c @@ -164,7 +164,7 @@ static t_stat diskParse(DISK_INFO *myDisk, uint32 isVerbose) sim_fread(&imd, 1, 5, myDisk->file); if (feof(myDisk->file)) break; - sectorSize = 128 << imd.sectsize; + sectorSize = 128 << (imd.sectsize & 0x1f); sectorHeadwithFlags = imd.head; /*AGN save the head and flags */ imd.head &= 1 ; /*AGN mask out flag bits to head 0 or 1 */