mirror of
https://github.com/tjboldt/Apple2-IO-RPi.git
synced 2025-01-21 15:30:09 +00:00
Fix boot of dynamic drive
This commit is contained in:
parent
f0e67ea5ff
commit
a13866a458
@ -57,7 +57,12 @@ func main() {
|
||||
case resetCommand:
|
||||
handlers.ResetCommand()
|
||||
case readBlockCommand:
|
||||
handlers.ReadBlockCommand(drive1, drive2)
|
||||
var block int
|
||||
block, err = handlers.ReadBlockCommand(drive1, drive2)
|
||||
if err == nil && block == 0 {
|
||||
resetCwd()
|
||||
drive1, _ = generateDriveFromCwd()
|
||||
}
|
||||
case writeBlockCommand:
|
||||
handlers.WriteBlockCommand(drive1, drive2)
|
||||
case getTimeCommand:
|
||||
@ -67,7 +72,7 @@ func main() {
|
||||
newCwd, _ := os.Getwd()
|
||||
if newCwd != cwd {
|
||||
cwd = newCwd
|
||||
drive1, err = generateDrive1FromCwd()
|
||||
drive1, _ = generateDriveFromCwd()
|
||||
}
|
||||
case loadFileCommand:
|
||||
handlers.LoadFileCommand()
|
||||
@ -105,16 +110,7 @@ func getDriveFiles() (prodos.ReaderWriterAt, prodos.ReaderWriterAt) {
|
||||
drive1, err = os.OpenFile(drive1Name, os.O_RDWR, 0755)
|
||||
logAndExitOnErr(err)
|
||||
} else {
|
||||
var exec string
|
||||
exec, err = os.Executable()
|
||||
if err != nil {
|
||||
fmt.Printf("ERROR: %s", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
cwd := filepath.Dir(exec)
|
||||
err = os.Chdir(filepath.Join(cwd, "../driveimage"))
|
||||
logAndExitOnErr(err)
|
||||
drive1, err = generateDrive1FromCwd()
|
||||
drive1, err = generateDriveFromCwd()
|
||||
logAndExitOnErr(err)
|
||||
}
|
||||
|
||||
@ -134,14 +130,25 @@ func logAndExitOnErr(err error) {
|
||||
}
|
||||
}
|
||||
|
||||
func generateDrive1FromCwd() (prodos.ReaderWriterAt, error) {
|
||||
func resetCwd() {
|
||||
exec, err := os.Executable()
|
||||
if err != nil {
|
||||
fmt.Printf("ERROR: %s", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
cwd := filepath.Dir(exec)
|
||||
err = os.Chdir(filepath.Join(cwd, "../driveimage"))
|
||||
logAndExitOnErr(err)
|
||||
}
|
||||
|
||||
func generateDriveFromCwd() (prodos.ReaderWriterAt, error) {
|
||||
cwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
drive1 := prodos.NewMemoryFile(0x2000000)
|
||||
fmt.Printf("Generating Drive 1 in memory from: %s\n", cwd)
|
||||
prodos.CreateVolume(drive1, "APPLE2.IO.RPI", 65535)
|
||||
err = prodos.AddFilesFromHostDirectory(drive1, cwd)
|
||||
return drive1, err
|
||||
drive := prodos.NewMemoryFile(0x2000000)
|
||||
fmt.Printf("Generating Drive in memory from: %s\n", cwd)
|
||||
prodos.CreateVolume(drive, "APPLE2.IO.RPI", 65535)
|
||||
err = prodos.AddFilesFromHostDirectory(drive, cwd)
|
||||
return drive, err
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ import (
|
||||
)
|
||||
|
||||
// ReadBlockCommand handles requests to read ProDOS blocks
|
||||
func ReadBlockCommand(drive1 prodos.ReaderWriterAt, drive2 prodos.ReaderWriterAt) {
|
||||
func ReadBlockCommand(drive1 prodos.ReaderWriterAt, drive2 prodos.ReaderWriterAt) (int, error) {
|
||||
blockLow, _ := comm.ReadByte()
|
||||
blockHigh, _ := comm.ReadByte()
|
||||
var driveUnit byte
|
||||
@ -23,7 +23,7 @@ func ReadBlockCommand(drive1 prodos.ReaderWriterAt, drive2 prodos.ReaderWriterAt
|
||||
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to read block")
|
||||
return
|
||||
return 0, err
|
||||
}
|
||||
|
||||
file := drive1
|
||||
@ -43,7 +43,7 @@ func ReadBlockCommand(drive1 prodos.ReaderWriterAt, drive2 prodos.ReaderWriterAt
|
||||
buffer, err := prodos.ReadBlock(file, block)
|
||||
if err != nil {
|
||||
fmt.Printf("failed %s\n", err)
|
||||
return
|
||||
return 0, err
|
||||
}
|
||||
|
||||
err = comm.WriteBlock(buffer)
|
||||
@ -52,10 +52,12 @@ func ReadBlockCommand(drive1 prodos.ReaderWriterAt, drive2 prodos.ReaderWriterAt
|
||||
} else {
|
||||
fmt.Printf("failed %s\n", err)
|
||||
}
|
||||
|
||||
return block, nil
|
||||
}
|
||||
|
||||
// WriteBlockCommand handles requests to write ProDOS blocks
|
||||
func WriteBlockCommand(drive1 prodos.ReaderWriterAt, drive2 prodos.ReaderWriterAt) {
|
||||
func WriteBlockCommand(drive1 prodos.ReaderWriterAt, drive2 prodos.ReaderWriterAt) error {
|
||||
blockLow, _ := comm.ReadByte()
|
||||
blockHigh, _ := comm.ReadByte()
|
||||
|
||||
@ -65,7 +67,7 @@ func WriteBlockCommand(drive1 prodos.ReaderWriterAt, drive2 prodos.ReaderWriterA
|
||||
driveUnit, err = comm.ReadByte()
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to write block")
|
||||
return
|
||||
return err
|
||||
}
|
||||
|
||||
file := drive1
|
||||
@ -87,7 +89,7 @@ func WriteBlockCommand(drive1 prodos.ReaderWriterAt, drive2 prodos.ReaderWriterA
|
||||
err = comm.ReadBlock(buffer)
|
||||
if err != nil {
|
||||
fmt.Printf("failed %s\n", err)
|
||||
return
|
||||
return err
|
||||
}
|
||||
fmt.Printf("...")
|
||||
|
||||
@ -97,4 +99,6 @@ func WriteBlockCommand(drive1 prodos.ReaderWriterAt, drive2 prodos.ReaderWriterA
|
||||
} else {
|
||||
fmt.Printf("failed\n")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user