Skip to content

Commit

Permalink
fix prodos file delete bug
Browse files Browse the repository at this point in the history
  • Loading branch information
undefinedopcode committed Jun 27, 2018
1 parent 358c506 commit e38cb58
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions disk/diskimagepd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package disk

import (
"errors"
"fmt"
"regexp"
"strings"
"time"
Expand Down Expand Up @@ -193,9 +192,9 @@ func (fd *VDH) Publish(dsk *DSKWrapper) error {
for i, v := range fd.Data {
bd[fd.blockoffset+i] = v
}
fmt.Printf("Writing dir header at block %d\n", fd.blockid)
//fmt.Printf("Writing dir header at block %d\n", fd.blockid)

fmt.Printf("Data=%v\n", bd)
//fmt.Printf("Data=%v\n", bd)

return dsk.PRODOSWrite(fd.blockid, bd)
}
Expand Down Expand Up @@ -324,6 +323,9 @@ func (vb ProDOSVolumeBitmap) IsBlockFree(b int) bool {
}

func (vb ProDOSVolumeBitmap) SetBlockFree(b int, free bool) {

//log.Printf("Freeing block %d", b)

bidx := b / 8
bit := 7 - (b % 8)
setmask := byte(1 << uint(bit))
Expand Down Expand Up @@ -1390,10 +1392,16 @@ func (dsk *DSKWrapper) PRODOSDeleteFile(path string, name string) error {
return err
}

maxBlocks := 1600
if len(dsk.Data) == STD_DISK_BYTES {
maxBlocks = 280
}

i := 0
b := int(ib[2*i+0]) + 256*int(ib[2*i+1])
for i < 256 && b != 0 {
b = int(ib[2*i+0]) + 256*int(ib[2*i+1])
b := int(ib[i]) + 256*int(ib[256+i])
for i < 256 && b != 0 && b <= maxBlocks {
removeBlocks = append(removeBlocks, b)
b = int(ib[i]) + 256*int(ib[256+i])
i++
}
}
Expand Down

0 comments on commit e38cb58

Please sign in to comment.