This commit is contained in:
Terence Boldt 2020-12-10 23:13:20 -05:00
commit 6fee77f587

View File

@ -28,17 +28,17 @@ var in_bit0 gpio.PinIO
func readNibble() byte {
// let the Apple II know we are ready to read
fmt.Printf("let the Apple II know we are ready to read\n")
//fmt.Printf("let the Apple II know we are ready to read\n")
out_read.Out(gpio.Low)
// wait for the Apple II to write
fmt.Printf("wait for the Apple II to write\n")
//fmt.Printf("wait for the Apple II to write\n")
for in_write.Read() == gpio.High {
in_write.WaitForEdge(-1)
}
// get a nibble of data
fmt.Printf("get a nibble of data\n")
//fmt.Printf("get a nibble of data\n")
var nibble byte
nibble = 0
bit3 := in_bit3.Read()
@ -60,11 +60,11 @@ func readNibble() byte {
}
// let the Apple II know we are done reading
fmt.Printf("let the Apple II know we are done reading\n")
//fmt.Printf("let the Apple II know we are done reading\n")
out_read.Out(gpio.High)
// wait for the Apple II to finish writing
fmt.Printf("wait for the Apple II to finish writing\n")
//fmt.Printf("wait for the Apple II to finish writing\n")
for in_write.Read() == gpio.Low {
in_write.WaitForEdge(-1)
}
@ -81,7 +81,7 @@ func readByte() byte {
func writeNibble(data byte) {
// wait for the Apple II to be ready to read
fmt.Printf("wait for the Apple II to be ready to read\n")
//fmt.Printf("wait for the Apple II to be ready to read\n")
for in_read.Read() == gpio.High {
in_read.WaitForEdge(-1)
}
@ -111,19 +111,19 @@ func writeNibble(data byte) {
out_bit0.Out(bit0)
// let Apple II know we're writing
fmt.Printf("let Apple II know we're writing\n")
//fmt.Printf("let Apple II know we're writing\n")
out_write.Out(gpio.Low)
// wait for the Apple II to finsih reading
fmt.Printf("wait for the Apple II to finsih reading\n")
//fmt.Printf("wait for the Apple II to finsih reading\n")
for in_read.Read() == gpio.Low {
in_write.WaitForEdge(-1)
in_read.WaitForEdge(-1)
}
// let the Apple II know we are done writing
fmt.Printf("let the Apple II know we are done writing\n")
out_read.Out(gpio.High)
//fmt.Printf("let the Apple II know we are done writing\n")
out_write.Out(gpio.High)
}
func writeByte(data byte) {
@ -137,7 +137,16 @@ func readBlock(buffer []byte) {
}
}
func writeBlock() {
func dumpBlock(buffer []byte) {
for i := 0; i < 512; i++ {
fmt.Printf("%02X ", buffer[i])
}
}
func writeBlock(buffer []byte) {
for i := 0; i < 512; i++ {
buffer[i] = readByte()
}
}
func main() {
@ -161,7 +170,7 @@ func main() {
in_bit0 = gpioreg.ByName("GPIO6")
fmt.Printf("Starting Apple II RPi...\n")
fileName := "Total Replay v4.0-beta.1.hdv"
fileName := "Total Replay v4.0-rc.1.hdv"
file, err := os.OpenFile(fileName, os.O_RDWR, 0755)
if err != nil {
//log.Fatal(err)
@ -170,9 +179,12 @@ func main() {
//log.Fatal(err)
//}
for in_write.Read() == gpio.Low {
in_write.WaitForEdge(-1)
}
//for in_write.Read() == gpio.Low {
// in_write.WaitForEdge(-1)
//}
buffer := make([]byte, 512)
//file.ReadAt(buffer, int64(0) * 512)
//dumpBlock(buffer)
for {
command := readByte();
@ -186,11 +198,24 @@ func main() {
fmt.Printf("Read block %d\n", block)
buffer := make([]byte, 512)
file.ReadAt(buffer, int64(block) * 512)
//dumpBlock(buffer)
readBlock(buffer)
}
if (command == 2) {
blockLow := readByte();
blockHigh := readByte();
var block int64
block = int64(blockHigh) * 256 + int64(blockLow)
fmt.Printf("Write block %d\n", block)
writeBlock(buffer)
file.WriteAt(buffer, int64(block) * 512)
}
}
}