hoglet67 / MMFS

Modern SD Card File System for Acorn 8-bit Machine (Master, Beeb, Electron)
68 stars 17 forks source link

First access used is always drive 0 regardless of filename/*DRIVE #14

Closed mincebert closed 5 years ago

mincebert commented 5 years ago

I'm running 1.41 - both the BBC Master version and the Electron SRAM version and they seem to exhibit the same bug: regardless of which drive is referenced in either a filename, or selected with *DRIVE, drive 0 is always used.

For example, if you CTRL+BREAK then type *.1, drive :0 is listed. Type the command again and drive 1 is listed. The same thing happens using (e.g.) *INFO :1.*.* - drive 0 is shown first type and then 1 thereafter. It also doesn't matter which other drive is being accessed.

This doesn't seem to occur in normal DFSs, so it's a bit odd. No biggy, but something is wrong! Thanks.

hoglet67 commented 5 years ago

I think I understand what's causing this now.

On control-break, the MMFS filesystem is initialized, but the initialization of the SD Card hardware, and the loading of the default drive mapping is delayed.

(This is so you never end up with a fatal Card? error on break)

Only when the first command is executed is the SD Card actually initialized, and it's at this point that the default mapping (drive 0 -> image 0; drive 1 -> image 1; drive 2 -> image 2; drive 3 -> image 3) is set up: https://github.com/hoglet67/MMFS/blob/master/MMC.asm#L655

The code that sets up that mapping makes use of CurrentDrv, and doesn't preseve the original value.

So if the first command is *CAT 1, then the drive number which is parsed into CurrentDrv is then clobbered.

I think thie fix will be to update MMC_LoadDisks to preserve CurrentDrv.

Note, the variable set by DRIVE is called DEFAULT_DRIVE, and the variable set by DIR is DEFAULT_DIR. CurrentDrv is distinct from these, and is really rather temporary in nature, i.e. it's scope I think is just the currently executing command.

hoglet67 commented 5 years ago

This seems to fix the issue, but costs 6 bytes.

 .MMC_LoadDisks
 {
+       LDA CurrentDrv
+       PHA
        LDA #0
        STA &B9
        LDX #3
 .loop  STX CurrentDrv
        STX &B8
        JSR LoadDrive
        DEX
        BPL loop
+       PLA
+       STA CurrentDrv
        RTS
 }
hoglet67 commented 5 years ago

This also seems to work, and only costs 2 bytes.

 .MMC_LoadDisks
 {
        LDA #0
        STA &B9
        LDX #3
-.loop  STX CurrentDrv
+.loop
        STX &B8
-       JSR LoadDrive
+       JSR LoadDriveX
        DEX
        BPL loop
        RTS
 }
...

 .LoadDrive
+       LDX CurrentDrv
+.LoadDriveX
 {
+       TXA
+       PHA
        LDA #&C0
        STA &B7
        JSR GetDiskStatus
@@ -6334,7 +6338,8 @@ ENDIF
        JSR CheckCRC7
        \ Make sure disk is not in another drive
        JSR UnloadDisk
-       LDX CurrentDrv
+       PLA
+       TAX
        LDA &B8
        STA DRIVE_INDEX0,X
mincebert commented 5 years ago

That fixes it for me, too. Thanks!

hoglet67 commented 5 years ago

I'll include the second version in the next release.

There is also one possible write timeout related issue that needs to be tracked down.