Add writeblock command

This commit is contained in:
Terence Boldt 2021-12-12 10:43:30 -05:00
parent 1cbb9fa0d9
commit 2e60d3c09c

16
main.go
View File

@ -106,7 +106,7 @@ func main() {
fmt.Printf("Failed to write file %s: %s", pathName, err) fmt.Printf("Failed to write file %s: %s", pathName, err)
} }
case "readblock": case "readblock":
fmt.Printf("Block 0x%04X (%d):\n\n", blockNumber, blockNumber) fmt.Printf("Reading block 0x%04X (%d):\n\n", blockNumber, blockNumber)
file, err := os.OpenFile(fileName, os.O_RDWR, 0755) file, err := os.OpenFile(fileName, os.O_RDWR, 0755)
if err != nil { if err != nil {
fmt.Printf("Failed to open drive image %s:\n %s", fileName, err) fmt.Printf("Failed to open drive image %s:\n %s", fileName, err)
@ -115,6 +115,20 @@ func main() {
defer file.Close() defer file.Close()
block := prodos.ReadBlock(file, blockNumber) block := prodos.ReadBlock(file, blockNumber)
prodos.DumpBlock(block) prodos.DumpBlock(block)
case "writeblock":
fmt.Printf("Writing block 0x%04X (%d):\n\n", blockNumber, blockNumber)
file, err := os.OpenFile(fileName, os.O_RDWR, 0755)
if err != nil {
fmt.Printf("Failed to open drive image %s:\n %s", fileName, err)
os.Exit(1)
}
defer file.Close()
inFile, err := os.ReadFile(inFileName)
if err != nil {
fmt.Printf("Failed to open input file %s: %s", inFileName, err)
os.Exit(1)
}
prodos.WriteBlock(file, blockNumber, inFile)
case "create": case "create":
file, err := os.Create(fileName) file, err := os.Create(fileName)
if err != nil { if err != nil {