2021-06-06 03:22:30 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2021-06-07 00:15:41 +00:00
|
|
|
"flag"
|
2021-06-06 03:22:30 +00:00
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/tjboldt/ProDOS-Utilities/prodos"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2021-06-07 00:15:41 +00:00
|
|
|
var fileName string
|
|
|
|
var pathName string
|
|
|
|
var command string
|
|
|
|
var outFileName string
|
2021-06-09 12:23:18 +00:00
|
|
|
var blockNumber int
|
|
|
|
var volumeSize int
|
|
|
|
var volumeName string
|
2021-06-07 00:15:41 +00:00
|
|
|
flag.StringVar(&fileName, "driveimage", "", "A ProDOS format drive image")
|
|
|
|
flag.StringVar(&pathName, "path", "", "Path name in ProDOS drive image")
|
2021-06-12 02:43:35 +00:00
|
|
|
flag.StringVar(&command, "command", "ls", "Command to execute: ls, get, put, volumebitmap, readblock, writeblock, createvolume, delete")
|
2021-06-07 00:15:41 +00:00
|
|
|
flag.StringVar(&outFileName, "outfile", "export.bin", "Name of file to write")
|
2021-06-09 12:23:18 +00:00
|
|
|
flag.IntVar(&volumeSize, "volumesize", 65535, "Number of blocks to create the volume with")
|
|
|
|
flag.StringVar(&volumeName, "volumename", "NO.NAME", "Specifiy a name for the volume from 1 to 15 characters")
|
|
|
|
flag.IntVar(&blockNumber, "block", 0, "A block number to read/write from 0 to 65535")
|
2021-06-07 00:15:41 +00:00
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
if len(fileName) == 0 {
|
|
|
|
fmt.Printf("Missing driveimage. Run with --help for more info.\n")
|
2021-06-06 12:00:20 +00:00
|
|
|
os.Exit(1)
|
2021-06-06 03:22:30 +00:00
|
|
|
}
|
2021-06-06 12:00:20 +00:00
|
|
|
|
2021-06-07 00:15:41 +00:00
|
|
|
switch command {
|
|
|
|
case "ls":
|
2021-06-09 12:23:18 +00:00
|
|
|
file, err := os.OpenFile(fileName, os.O_RDWR, 0755)
|
|
|
|
if err != nil {
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
2021-06-07 00:15:41 +00:00
|
|
|
volumeHeader, fileEntries := prodos.ReadDirectory(file, pathName)
|
|
|
|
prodos.DumpDirectory(volumeHeader, fileEntries)
|
|
|
|
case "volumebitmap":
|
2021-06-09 12:23:18 +00:00
|
|
|
file, err := os.OpenFile(fileName, os.O_RDWR, 0755)
|
|
|
|
if err != nil {
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
2021-06-07 00:15:41 +00:00
|
|
|
volumeBitmap := prodos.ReadVolumeBitmap(file)
|
|
|
|
prodos.DumpBlock(volumeBitmap)
|
|
|
|
case "get":
|
2021-06-09 12:23:18 +00:00
|
|
|
file, err := os.OpenFile(fileName, os.O_RDWR, 0755)
|
|
|
|
if err != nil {
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
2021-06-07 00:15:41 +00:00
|
|
|
if len(pathName) == 0 {
|
|
|
|
fmt.Println("Missing pathname")
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
getFile := prodos.LoadFile(file, pathName)
|
2021-06-09 12:23:18 +00:00
|
|
|
outFile, err := os.Create(outFileName)
|
|
|
|
if err != nil {
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
outFile.Write(getFile)
|
|
|
|
case "readblock":
|
|
|
|
file, err := os.OpenFile(fileName, os.O_RDWR, 0755)
|
|
|
|
if err != nil {
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
block := prodos.ReadBlock(file, blockNumber)
|
|
|
|
outFile, err := os.Create(outFileName)
|
|
|
|
if err != nil {
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
outFile.Write(block)
|
2021-06-12 02:43:35 +00:00
|
|
|
case "createvolume":
|
2021-06-09 12:23:18 +00:00
|
|
|
prodos.CreateVolume(fileName, volumeName, volumeSize)
|
2021-06-12 02:43:35 +00:00
|
|
|
case "delete":
|
|
|
|
file, err := os.OpenFile(fileName, os.O_RDWR, 0755)
|
|
|
|
if err != nil {
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
prodos.DeleteFile(file, pathName)
|
2021-06-07 00:15:41 +00:00
|
|
|
default:
|
2021-06-09 12:23:18 +00:00
|
|
|
fmt.Printf("Command %s not handle\n", command)
|
2021-06-07 00:15:41 +00:00
|
|
|
os.Exit(1)
|
2021-06-06 03:22:30 +00:00
|
|
|
}
|
|
|
|
}
|