Apple2-IO-RPi/RaspberryPi/apple2driver/handlers/writeBlock.go

42 lines
752 B
Go
Raw Normal View History

2021-05-30 11:18:39 +00:00
package handlers
import (
"fmt"
"os"
"github.com/tjboldt/Apple2-IO-RPi/RaspberryPi/apple2driver/a2io"
)
2021-10-06 12:34:18 +00:00
func WriteBlockCommand(drive1 *os.File, drive2 *os.File) {
2021-05-30 11:18:39 +00:00
blockLow, _ := a2io.ReadByte()
blockHigh, _ := a2io.ReadByte()
2021-10-06 12:34:18 +00:00
2021-10-06 23:30:20 +00:00
var driveUnit byte = 0
var err error
if !oldFirmware {
driveUnit, err = a2io.ReadByte()
if err != nil {
fmt.Printf("Drive unit not sent, assuming older firmware")
oldFirmware = true
}
2021-10-06 12:34:18 +00:00
}
file := drive1
if driveUnit >= 128 {
2021-10-06 12:34:18 +00:00
file = drive2
}
2021-05-30 11:18:39 +00:00
buffer := make([]byte, 512)
var block int64
block = int64(blockHigh)*256 + int64(blockLow)
fmt.Printf("Write block %d\n", block)
a2io.ReadBlock(buffer)
file.WriteAt(buffer, int64(block)*512)
file.Sync()
fmt.Printf("Write block completed\n")
}