forked from Apple-2-HW/Apple2-IO-RPi
Add support for two drives
This commit is contained in:
parent
88fef5db11
commit
068c907f45
@ -1,8 +1,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/tjboldt/Apple2-IO-RPi/RaspberryPi/apple2driver/a2io"
|
"github.com/tjboldt/Apple2-IO-RPi/RaspberryPi/apple2driver/a2io"
|
||||||
"github.com/tjboldt/Apple2-IO-RPi/RaspberryPi/apple2driver/handlers"
|
"github.com/tjboldt/Apple2-IO-RPi/RaspberryPi/apple2driver/handlers"
|
||||||
@ -18,26 +20,20 @@ const SaveFileCommand = 7
|
|||||||
const MenuCommand = 8
|
const MenuCommand = 8
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
a2io.InitGpio()
|
drive1, drive2 := getDriveFiles()
|
||||||
|
|
||||||
fmt.Printf("Starting Apple II RPi...\n")
|
fmt.Printf("Starting Apple II RPi...\n")
|
||||||
|
|
||||||
fileName := os.Args[1]
|
a2io.InitGpio()
|
||||||
|
|
||||||
file, err := os.OpenFile(fileName, os.O_RDWR, 0755)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("ERROR: %s", err.Error())
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
command, err := a2io.ReadByte()
|
command, err := a2io.ReadByte()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
switch command {
|
switch command {
|
||||||
case ReadBlockCommand:
|
case ReadBlockCommand:
|
||||||
handlers.ReadBlockCommand(file)
|
handlers.ReadBlockCommand(drive1, drive2)
|
||||||
case WriteBlockCommand:
|
case WriteBlockCommand:
|
||||||
handlers.WriteBlockCommand(file)
|
handlers.WriteBlockCommand(drive1, drive2)
|
||||||
case GetTimeCommand:
|
case GetTimeCommand:
|
||||||
handlers.GetTimeCommand()
|
handlers.GetTimeCommand()
|
||||||
case ExecCommand:
|
case ExecCommand:
|
||||||
@ -50,3 +46,56 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getDriveFiles() (*os.File, *os.File) {
|
||||||
|
var drive1Name string
|
||||||
|
var drive2Name string
|
||||||
|
|
||||||
|
execName, _ := os.Executable()
|
||||||
|
path := filepath.Dir(execName)
|
||||||
|
path = filepath.Join(path, "..")
|
||||||
|
path, _ = filepath.EvalSymlinks(path)
|
||||||
|
defaultFileName := filepath.Join(path, "Apple2-IO-RPi.hdv")
|
||||||
|
|
||||||
|
flag.StringVar(&drive1Name, "d1", "", "A ProDOS format drive image for drive 1")
|
||||||
|
flag.StringVar(&drive2Name, "d2", defaultFileName, "A ProDOS format drive image for drive 2 and will be used for drive 1 if drive 1 empty")
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
var drive1 *os.File = nil
|
||||||
|
var drive2 *os.File = nil
|
||||||
|
var err error
|
||||||
|
|
||||||
|
if len(drive1Name) > 0 {
|
||||||
|
fmt.Printf("Opening Drive 1 as: %s\n", drive1Name)
|
||||||
|
drive1, err = os.OpenFile(drive1Name, os.O_RDWR, 0755)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("ERROR: %s", err.Error())
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(drive2Name) > 0 {
|
||||||
|
if drive1 == nil {
|
||||||
|
fmt.Printf("Opening Drive 1 as: %s because Drive 1 was empty\n", drive2Name)
|
||||||
|
drive1, err = os.OpenFile(drive2Name, os.O_RDWR, 0755)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("ERROR: %s", err.Error())
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fmt.Printf("Opening Drive 2 as: %s\n", drive2Name)
|
||||||
|
drive2, err = os.OpenFile(drive2Name, os.O_RDWR, 0755)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("ERROR: %s", err.Error())
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if drive1 == nil {
|
||||||
|
flag.PrintDefaults()
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
return drive1, drive2
|
||||||
|
}
|
||||||
|
@ -7,9 +7,20 @@ import (
|
|||||||
"github.com/tjboldt/Apple2-IO-RPi/RaspberryPi/apple2driver/a2io"
|
"github.com/tjboldt/Apple2-IO-RPi/RaspberryPi/apple2driver/a2io"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ReadBlockCommand(file *os.File) {
|
func ReadBlockCommand(drive1 *os.File, drive2 *os.File) {
|
||||||
blockLow, _ := a2io.ReadByte()
|
blockLow, _ := a2io.ReadByte()
|
||||||
blockHigh, _ := a2io.ReadByte()
|
blockHigh, _ := a2io.ReadByte()
|
||||||
|
driveUnit, err := a2io.ReadByte()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Drive unit not sent, assuming older firmware")
|
||||||
|
}
|
||||||
|
|
||||||
|
file := drive1
|
||||||
|
|
||||||
|
if driveUnit >= 8 {
|
||||||
|
file = drive2
|
||||||
|
}
|
||||||
|
|
||||||
buffer := make([]byte, 512)
|
buffer := make([]byte, 512)
|
||||||
var block int64
|
var block int64
|
||||||
@ -19,7 +30,7 @@ func ReadBlockCommand(file *os.File) {
|
|||||||
|
|
||||||
file.ReadAt(buffer, int64(block)*512)
|
file.ReadAt(buffer, int64(block)*512)
|
||||||
|
|
||||||
err := a2io.WriteBlock(buffer)
|
err = a2io.WriteBlock(buffer)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
fmt.Printf("Read block completed\n")
|
fmt.Printf("Read block completed\n")
|
||||||
} else {
|
} else {
|
||||||
|
@ -7,9 +7,20 @@ import (
|
|||||||
"github.com/tjboldt/Apple2-IO-RPi/RaspberryPi/apple2driver/a2io"
|
"github.com/tjboldt/Apple2-IO-RPi/RaspberryPi/apple2driver/a2io"
|
||||||
)
|
)
|
||||||
|
|
||||||
func WriteBlockCommand(file *os.File) {
|
func WriteBlockCommand(drive1 *os.File, drive2 *os.File) {
|
||||||
blockLow, _ := a2io.ReadByte()
|
blockLow, _ := a2io.ReadByte()
|
||||||
blockHigh, _ := a2io.ReadByte()
|
blockHigh, _ := a2io.ReadByte()
|
||||||
|
driveUnit, err := a2io.ReadByte()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Drive unit not sent, assuming older firmware")
|
||||||
|
}
|
||||||
|
|
||||||
|
file := drive1
|
||||||
|
|
||||||
|
if driveUnit >= 8 {
|
||||||
|
file = drive2
|
||||||
|
}
|
||||||
|
|
||||||
buffer := make([]byte, 512)
|
buffer := make([]byte, 512)
|
||||||
var block int64
|
var block int64
|
||||||
|
Loading…
x
Reference in New Issue
Block a user