2021-05-30 11:18:39 +00:00
|
|
|
package handlers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/tjboldt/Apple2-IO-RPi/RaspberryPi/apple2driver/a2io"
|
2021-06-07 02:09:00 +00:00
|
|
|
"github.com/tjboldt/ProDOS-Utilities/prodos"
|
2021-05-30 11:18:39 +00:00
|
|
|
)
|
|
|
|
|
2021-10-06 23:30:20 +00:00
|
|
|
var oldFirmware = false
|
|
|
|
|
2021-10-06 12:34:18 +00:00
|
|
|
func ReadBlockCommand(drive1 *os.File, drive2 *os.File) {
|
2021-05-30 11:18:39 +00:00
|
|
|
blockLow, _ := a2io.ReadByte()
|
|
|
|
blockHigh, _ := a2io.ReadByte()
|
2021-10-06 23:30:20 +00:00
|
|
|
var driveUnit byte = 0
|
|
|
|
var err error
|
|
|
|
|
|
|
|
if !oldFirmware {
|
|
|
|
driveUnit, err = a2io.ReadByte()
|
2021-10-06 23:57:30 +00:00
|
|
|
fmt.Printf("Drive unit: %0X\n", driveUnit)
|
2021-10-06 12:34:18 +00:00
|
|
|
|
2021-10-06 23:30:20 +00:00
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("Drive unit not sent, assuming older firmware")
|
|
|
|
oldFirmware = true
|
|
|
|
}
|
2021-10-06 12:34:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
file := drive1
|
|
|
|
|
2021-10-06 23:57:30 +00:00
|
|
|
if driveUnit >= 128 {
|
2021-10-06 12:34:18 +00:00
|
|
|
file = drive2
|
|
|
|
}
|
2021-05-30 11:18:39 +00:00
|
|
|
|
2021-06-07 02:09:00 +00:00
|
|
|
var block int
|
|
|
|
block = int(blockHigh)*256 + int(blockLow)
|
2021-05-30 11:18:39 +00:00
|
|
|
|
|
|
|
fmt.Printf("Read block %d\n", block)
|
|
|
|
|
2021-06-07 02:09:00 +00:00
|
|
|
buffer := prodos.ReadBlock(file, block)
|
2021-05-30 11:18:39 +00:00
|
|
|
|
2021-10-06 12:34:18 +00:00
|
|
|
err = a2io.WriteBlock(buffer)
|
2021-05-30 11:18:39 +00:00
|
|
|
if err == nil {
|
|
|
|
fmt.Printf("Read block completed\n")
|
|
|
|
} else {
|
|
|
|
fmt.Printf("Failed to read block\n")
|
|
|
|
}
|
|
|
|
}
|