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

46 lines
819 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"
)
func LoadFileCommand() {
fileName, _ := a2io.ReadString()
file, err := os.OpenFile(fileName, os.O_RDWR, 0755)
if err != nil {
fmt.Printf("ERROR: %s\n", err.Error())
a2io.WriteByte(0)
a2io.WriteByte(0)
return
}
fileInfo, _ := file.Stat()
fileSize := int(fileInfo.Size())
fmt.Printf("FileSize: %d\n", fileSize)
fileSizeHigh := byte(fileSize >> 8)
fileSizeLow := byte(fileSize & 255)
2021-06-01 23:08:21 +00:00
err = a2io.WriteByte(fileSizeLow)
if err != nil {
return
}
err = a2io.WriteByte(fileSizeHigh)
if err != nil {
return
}
2021-05-30 11:18:39 +00:00
buffer := make([]byte, fileSize)
fmt.Printf("Read file %s SizeHigh: %d SizeLow: %d\n", fileName, fileSizeHigh, fileSizeLow)
file.Read(buffer)
a2io.WriteBuffer(buffer)
}