ProDOS-Utilities/main.go

110 lines
3.0 KiB
Go
Raw Normal View History

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-26 01:15:20 +00:00
var inFileName string
2021-06-09 12:23:18 +00:00
var blockNumber int
var volumeSize int
var volumeName string
2021-06-27 11:53:50 +00:00
var fileType int
var auxType int
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-26 01:15:20 +00:00
flag.StringVar(&outFileName, "outfile", "", "Name of file to write")
flag.StringVar(&inFileName, "infile", "", "Name of file to read")
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-27 11:53:50 +00:00
flag.IntVar(&fileType, "type", 6, "ProDOS FileType: 4=txt, 6=bin, 252=bas, 255=sys etc.")
flag.IntVar(&auxType, "aux", 0x2000, "ProDOS AuxType from 0 to 65535 (usually load address)")
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-26 01:15:20 +00:00
volumeHeader, _, fileEntries := prodos.ReadDirectory(file, pathName)
2021-06-07 00:15:41 +00:00
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-26 01:15:20 +00:00
if len(outFileName) == 0 {
_, outFileName = prodos.GetDirectoryAndFileNameFromPath(pathName)
}
2021-06-09 12:23:18 +00:00
outFile, err := os.Create(outFileName)
if err != nil {
os.Exit(1)
}
outFile.Write(getFile)
2021-06-26 01:15:20 +00:00
case "put":
file, err := os.OpenFile(fileName, os.O_RDWR, 0755)
if err != nil {
os.Exit(1)
}
if len(pathName) == 0 {
fmt.Println("Missing pathname")
os.Exit(1)
}
inFile, err := os.ReadFile(inFileName)
if err != nil {
os.Exit(1)
}
2021-06-27 11:53:50 +00:00
prodos.WriteFile(file, pathName, fileType, auxType, inFile)
2021-06-09 12:23:18 +00:00
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
}
}