MEGA65 / mega65-rom-public

MEGA65 ROM public issue reporting
4 stars 0 forks source link

920403: Internal floppy drive head is not reset after a read of bad disk/missing disk #143

Closed dansanderson closed 3 days ago

dansanderson commented 3 days ago

920403 re-introduces D64 support, which previously was noticed to cause some unusual issues with disk driver state involving the internal physical floppy drive. The previous issues could be reproduced in v0.95 core + 920381 and have been cleared up in v0.96 core + 920403. But we've found a new reproduceable issue that's worth investigating, and might be related.

  1. Cold boot.
  2. Open Freezer. Mount a D81 disk image to unit 8. Resume.
  3. DIR: successfully lists directory on D81 disk image.
  4. Ensure that physical floppy drive is empty.
  5. MOUNT
  6. DIR: after a pause, successfully notices there is no disk, reports 27,READ ERROR,09,37
  7. Insert a known-working floppy disk.
  8. DIR

With v0.96 core + 920402, step 8 correctly retries the physical floppy disk and prints a directory listing. With v0.96 core + 920403, step 8 reports 27,READ ERROR,09,37 again, and subsequent attempts to access the disk continue to report the error.

The Freezer step may or may not significant. Skipping steps 2 and 3 may not reproduce the issue: 920403 has a successful result on step 8. I've seen it both ways.

dansanderson commented 3 days ago

Unmounting and mounting the floppy drive doesn't clear the persistent Read Error.

Warm boot doesn't clear the persistent Read Error.

Cold boot (power off, power on) doesn't always clear the persistent Read Error either. This is similar to issues we've seen in 920381. We don't have a working theory yet for why bad state would persist across a cold boot.

Previous 920402 uses different logic (try_d64) to determine the disk image type. I wonder if this logic has different effects on physical drives, e.g. resetting a head position or something.

dansanderson commented 3 days ago

I have been able to narrow this to the specific case where the internal floppy drive head is in an unexpected position after a bad disk read or an attempt to read an empty drive. This was functional in 920402 and other ROMs because they were performing an extra read of a specific track before attempting to read the directory. In the specific case of the internal floppy drive after a bad read, this extra track read was resetting the drive mechanism. With ROM 920403, this extra track read was removed, and so was not recovering this internal floppy condition.

I have a kludge fix that reinstates the extra read. A better fix would only do this when the internal drive is mounted and being accessed, may or may not use a more specific command to reset the drive head mechanism (vs. reading an arbitrary track), and may only do this if the last read was an error of the internal floppy drive (if this is possible to detect completely).

I bet this was the cause of issues seen wtih our previous attempt in 920381, where things like having the physical floppy drive auto-mount, or reading a particular kind of bad floppy disk, would put it in this bad state that wasn't getting reset. This also explains how this bad state could persist between cold boots, because it has to do with the position of the read head.

dansanderson commented 3 days ago

... It's possible my kludge fix is the best fix. Avoiding a spurious track read from a virtual disk image doesn't save much time or wear, and it's possible that the only way to reset the drive head is to just read a track anyway. If I can't find a local expert or some documentation on the matter, I might just go with the kludge fix for now.