dirkwhoffmann / virtualc64

VirtualC64 is a cycle-accurate C64 emulator for macOS
https://dirkwhoffmann.github.io/virtualc64
Other
351 stars 33 forks source link

"New disk" seems to create a disk with a faulty file system #705

Closed dirkwhoffmann closed 2 years ago

dirkwhoffmann commented 2 years ago

Reported to me by email:

There is an issue/pb regarding the 1541 on VirtualC64; maybe I am wrong.

When you save more than 8 file to a 1541.D64 (Drive 8 / New) that does not work.

try: save « yan01 »,8,1 to save « yan10 »,8,1 and you will see

Unknown

More infos provided by Jan:

Deep look, I found that the track 18 (hex12) , sector 0 Virtual C64 create is wrong

On the BAM you get: x48: 00 00 00 00

When formatted it became: x48: 11 FC FF 07

; $11: remaining free blocks ; FC FF 07: block free are bit’ed 1 ; 1111.1100 1111.1111 0000.0111

;To understand BAM allocation, we have to read backward ; Sector ; 1 2 ; 1234.5678 9012.3456 7890.1234 ; 0011.1111 1111.1111 1110.0000

So, here, reading BAM track18, sector 0; we see that sector 1 and 2 are not available (Sector 1: BAM , Sector 2: first entry; here not, but even.)

000

001

dirkwhoffmann commented 2 years ago

Bug will be fixed in the next release. The culprit is function FSBlock::writeBAM(PETName<16> &name):

Old code:

      if (k == 18) {

            p[0] = 0;    // No free blocks on the directory track
            p[1] = 0x00;
            p[2] = 0x00;
            p[3] = 0x00;

        } 

New code:

       if (k == 18) {

            p[0] = 17;      // 17 out of 19 blocks are free
            p[1] = 0xFC;    // Mark first two blocks as allocated
            p[2] = 0xFF;
            p[3] = 0x07;

        }
dirkwhoffmann commented 2 years ago

For reference: BAM of a disk that has been formatted via

OPEN 1,8,15,"N:TEST, ID": CLOSE 1
RealBAM
dirkwhoffmann commented 2 years ago

v4.5b1 is online.