2024-01-02 22:51:33 -05:00
|
|
|
// Copyright Terence J. Boldt (c)2020-2024
|
2021-10-30 09:50:00 -04:00
|
|
|
// Use of this source code is governed by an MIT
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2022-01-10 23:00:58 -05:00
|
|
|
// This file contains the handler for loading files directly from the
|
2021-10-30 09:50:00 -04:00
|
|
|
// Raspberry Pi onto the Apple II
|
2021-11-03 05:33:09 -04:00
|
|
|
|
2021-05-30 07:18:39 -04:00
|
|
|
package handlers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
2021-11-03 05:33:09 -04:00
|
|
|
// LoadFileCommand handles requests to direct read files from Linux to the Apple II
|
2021-05-30 07:18:39 -04:00
|
|
|
func LoadFileCommand() {
|
2021-10-30 07:03:18 -04:00
|
|
|
fileName, _ := comm.ReadString()
|
2021-05-30 07:18:39 -04:00
|
|
|
|
|
|
|
file, err := os.OpenFile(fileName, os.O_RDWR, 0755)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("ERROR: %s\n", err.Error())
|
2021-10-30 07:03:18 -04:00
|
|
|
comm.WriteByte(0)
|
|
|
|
comm.WriteByte(0)
|
2021-05-30 07:18:39 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
fileInfo, _ := file.Stat()
|
|
|
|
fileSize := int(fileInfo.Size())
|
|
|
|
|
|
|
|
fmt.Printf("FileSize: %d\n", fileSize)
|
|
|
|
|
|
|
|
fileSizeHigh := byte(fileSize >> 8)
|
|
|
|
fileSizeLow := byte(fileSize & 255)
|
|
|
|
|
2021-10-30 07:03:18 -04:00
|
|
|
err = comm.WriteByte(fileSizeLow)
|
2021-06-02 00:08:21 +01:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2021-10-30 07:03:18 -04:00
|
|
|
err = comm.WriteByte(fileSizeHigh)
|
2021-06-02 00:08:21 +01:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2021-05-30 07:18:39 -04:00
|
|
|
|
|
|
|
buffer := make([]byte, fileSize)
|
|
|
|
|
|
|
|
fmt.Printf("Read file %s SizeHigh: %d SizeLow: %d\n", fileName, fileSizeHigh, fileSizeLow)
|
|
|
|
|
|
|
|
file.Read(buffer)
|
|
|
|
|
2021-10-30 07:03:18 -04:00
|
|
|
comm.WriteBuffer(buffer)
|
2021-05-30 07:18:39 -04:00
|
|
|
}
|