mirror of
https://github.com/paleotronic/diskm8.git
synced 2024-12-06 12:51:36 +00:00
file reading and writing fixes
This commit is contained in:
parent
4479f21f0b
commit
0a4cc590d8
@ -205,8 +205,10 @@ func (fd *FileDescriptor) TotalSectors() int {
|
||||
}
|
||||
|
||||
func (fd *FileDescriptor) SetTotalSectors(v int) {
|
||||
fmt.Printf("Call to set sector count to %d\n", v)
|
||||
fd.Data[0x21] = byte(v & 0xff)
|
||||
fd.Data[0x22] = byte(v / 0x100)
|
||||
fmt.Printf("Sector count bytes are %d, %d\n", fd.Data[0x21], fd.Data[0x22])
|
||||
}
|
||||
|
||||
func (fd *FileDescriptor) SetTrackSectorListStart(t, s int) {
|
||||
@ -901,6 +903,15 @@ func (dsk *DSKWrapper) AppleDOSWriteFile(name string, kind FileType, data []byte
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("Writing file with type %s\n", kind.Ext())
|
||||
|
||||
if kind == FileTypeBIN {
|
||||
l := len(data)
|
||||
fmt.Printf("Length is %d\n", l)
|
||||
header := []byte{byte(l % 256), byte(l / 256)}
|
||||
data = append(header, data...)
|
||||
}
|
||||
|
||||
if kind != FileTypeTXT {
|
||||
header := []byte{byte(loadAddr % 256), byte(loadAddr / 256)}
|
||||
data = append(header, data...)
|
||||
@ -932,6 +943,7 @@ func (dsk *DSKWrapper) AppleDOSWriteFile(name string, kind FileType, data []byte
|
||||
}
|
||||
|
||||
// 2nd: check we can get a free catalog entry
|
||||
sectorCount := len(dataBlocks)
|
||||
|
||||
// 3rd: Write the datablocks
|
||||
var block int = 0
|
||||
@ -1010,7 +1022,8 @@ func (dsk *DSKWrapper) AppleDOSWriteFile(name string, kind FileType, data []byte
|
||||
fd.SetName(name)
|
||||
fd.SetTrackSectorListStart(tsBlocks[0][0], tsBlocks[0][1])
|
||||
fd.SetType(kind)
|
||||
fd.SetTotalSectors(len(dataBlocks))
|
||||
fd.SetTotalSectors(sectorCount)
|
||||
fd.Publish(dsk)
|
||||
|
||||
return nil
|
||||
|
||||
|
@ -102,11 +102,11 @@ func analyzeDOS13(id int, dsk *disk.DSKWrapper, info *Disk) {
|
||||
Modified: time.Now(),
|
||||
}
|
||||
|
||||
_, _, data, err := dsk.AppleDOSReadFileRaw(fd)
|
||||
size, addr, data, err := dsk.AppleDOSReadFileRaw(fd)
|
||||
if err == nil {
|
||||
sum := sha256.Sum256(data)
|
||||
file.SHA256 = hex.EncodeToString(sum[:])
|
||||
file.Size = len(data)
|
||||
file.Size = size
|
||||
if *ingestMode&1 == 1 {
|
||||
if fd.Type() == disk.FileTypeAPP {
|
||||
file.Text = disk.ApplesoftDetoks(data)
|
||||
@ -124,8 +124,8 @@ func analyzeDOS13(id int, dsk *disk.DSKWrapper, info *Disk) {
|
||||
file.TypeCode = TypeMask_AppleDOS | TypeCode(fd.Type())
|
||||
file.LoadAddress = 0x0000
|
||||
} else if fd.Type() == disk.FileTypeBIN && len(data) >= 2 {
|
||||
file.LoadAddress = int(data[0]) + 256*int(data[1])
|
||||
file.Data = data[2:]
|
||||
file.LoadAddress = addr
|
||||
file.Data = data
|
||||
file.TypeCode = TypeMask_AppleDOS | TypeCode(fd.Type())
|
||||
} else {
|
||||
file.LoadAddress = 0x0000
|
||||
|
@ -136,11 +136,11 @@ func analyzeDOS16(id int, dsk *disk.DSKWrapper, info *Disk) {
|
||||
}
|
||||
|
||||
//l.Log("start read")
|
||||
_, _, data, err := dsk.AppleDOSReadFileRaw(fd)
|
||||
size, addr, data, err := dsk.AppleDOSReadFileRaw(fd)
|
||||
if err == nil {
|
||||
sum := sha256.Sum256(data)
|
||||
file.SHA256 = hex.EncodeToString(sum[:])
|
||||
file.Size = len(data)
|
||||
file.Size = size
|
||||
if *ingestMode&1 == 1 {
|
||||
if fd.Type() == disk.FileTypeAPP {
|
||||
file.Text = disk.ApplesoftDetoks(data)
|
||||
@ -158,8 +158,8 @@ func analyzeDOS16(id int, dsk *disk.DSKWrapper, info *Disk) {
|
||||
file.TypeCode = TypeMask_AppleDOS | TypeCode(fd.Type())
|
||||
file.LoadAddress = 0x0000
|
||||
} else if fd.Type() == disk.FileTypeBIN && len(data) >= 2 {
|
||||
file.LoadAddress = int(data[0]) + 256*int(data[1])
|
||||
file.Data = data[2:]
|
||||
file.LoadAddress = addr
|
||||
file.Data = data
|
||||
file.TypeCode = TypeMask_AppleDOS | TypeCode(fd.Type())
|
||||
} else {
|
||||
file.LoadAddress = 0x0000
|
||||
|
36
shell.go
36
shell.go
@ -1060,15 +1060,42 @@ func shellPut(args []string) int {
|
||||
return 1
|
||||
}
|
||||
|
||||
data, err := ioutil.ReadFile(args[0])
|
||||
parts := strings.Split(args[0], ",")
|
||||
|
||||
data, err := ioutil.ReadFile(parts[0])
|
||||
if err != nil {
|
||||
return -1
|
||||
}
|
||||
|
||||
addr := int64(0x0801)
|
||||
name := filepath.Base(args[0])
|
||||
reTrailAddr := regexp.MustCompile("(?i)^([^,]+)([,]A(([$]|0x)[0-9a-f]+))?([,]L(([$]|0x)[0-9a-f]+))?$")
|
||||
if reTrailAddr.MatchString(name) {
|
||||
m := reTrailAddr.FindAllStringSubmatch(name, -1)
|
||||
name = m[0][1]
|
||||
saddr := m[0][3]
|
||||
slen := m[0][6]
|
||||
if saddr != "" {
|
||||
if strings.HasPrefix(saddr, "$") {
|
||||
saddr = "0x" + saddr[1:]
|
||||
}
|
||||
addr, _ = strconv.ParseInt(saddr, 0, 32)
|
||||
}
|
||||
if slen != "" {
|
||||
if strings.HasPrefix(slen, "$") {
|
||||
slen = "0x" + slen[1:]
|
||||
}
|
||||
nlen, _ := strconv.ParseInt(slen, 0, 32)
|
||||
if int(nlen) < len(data) {
|
||||
data = data[:int(nlen)]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if formatIn(commandVolumes[commandTarget].Format.ID, []disk.DiskFormatID{disk.DF_DOS_SECTORS_13, disk.DF_DOS_SECTORS_16}) {
|
||||
addr := int64(0x0801)
|
||||
name := filepath.Base(args[0])
|
||||
|
||||
kind := disk.FileTypeAPP
|
||||
|
||||
reSpecial := regexp.MustCompile("(?i)^(.+)[#](0x[a-fA-F0-9]+)[.]([A-Za-z]+)$")
|
||||
ext := strings.Trim(filepath.Ext(name), ".")
|
||||
if reSpecial.MatchString(name) {
|
||||
@ -1106,8 +1133,7 @@ func shellPut(args []string) int {
|
||||
saveDisk(commandVolumes[commandTarget], fullpath)
|
||||
|
||||
} else if formatIn(commandVolumes[commandTarget].Format.ID, []disk.DiskFormatID{disk.DF_PRODOS, disk.DF_PRODOS_800KB, disk.DF_PRODOS_400KB, disk.DF_PRODOS_CUSTOM}) {
|
||||
addr := int64(0x0801)
|
||||
name := filepath.Base(args[0])
|
||||
|
||||
ext := strings.Trim(filepath.Ext(name), ".")
|
||||
reSpecial := regexp.MustCompile("(?i)^(.+)[#](0x[a-fA-F0-9]+)[.]([A-Za-z]+)$")
|
||||
if reSpecial.MatchString(name) {
|
||||
|
Loading…
Reference in New Issue
Block a user