mirror of
https://github.com/tjboldt/Apple2-IO-RPi.git
synced 2024-12-22 02:30:12 +00:00
Fix dynamic drive
This commit is contained in:
parent
91efe725b7
commit
f0e67ea5ff
@ -67,7 +67,7 @@ func main() {
|
||||
newCwd, _ := os.Getwd()
|
||||
if newCwd != cwd {
|
||||
cwd = newCwd
|
||||
generateDrive1FromCwd()
|
||||
drive1, err = generateDrive1FromCwd()
|
||||
}
|
||||
case loadFileCommand:
|
||||
handlers.LoadFileCommand()
|
||||
@ -83,7 +83,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func getDriveFiles() (*os.File, *os.File) {
|
||||
func getDriveFiles() (prodos.ReaderWriterAt, prodos.ReaderWriterAt) {
|
||||
var drive1Name string
|
||||
var drive2Name string
|
||||
|
||||
@ -96,8 +96,8 @@ func getDriveFiles() (*os.File, *os.File) {
|
||||
flag.StringVar(&drive2Name, "d2", "", "A ProDOS format drive image for drive 2 and will be used for drive 1 if drive 1 empty")
|
||||
flag.Parse()
|
||||
|
||||
var drive1 *os.File
|
||||
var drive2 *os.File
|
||||
var drive1 prodos.ReaderWriterAt
|
||||
var drive2 prodos.ReaderWriterAt
|
||||
var err error
|
||||
|
||||
if len(drive1Name) > 0 {
|
||||
@ -114,7 +114,7 @@ func getDriveFiles() (*os.File, *os.File) {
|
||||
cwd := filepath.Dir(exec)
|
||||
err = os.Chdir(filepath.Join(cwd, "../driveimage"))
|
||||
logAndExitOnErr(err)
|
||||
err = generateDrive1FromCwd()
|
||||
drive1, err = generateDrive1FromCwd()
|
||||
logAndExitOnErr(err)
|
||||
}
|
||||
|
||||
@ -134,14 +134,14 @@ func logAndExitOnErr(err error) {
|
||||
}
|
||||
}
|
||||
|
||||
func generateDrive1FromCwd() error {
|
||||
func generateDrive1FromCwd() (prodos.ReaderWriterAt, error) {
|
||||
cwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
drive1 := prodos.NewMemoryFile(0x2000000)
|
||||
fmt.Printf("Generating Drive 1 in memory from: %s\n", cwd)
|
||||
prodos.CreateVolume(drive1, "APPLE2.IO.RPI", 65535)
|
||||
err = prodos.AddFilesFromHostDirectory(drive1, cwd)
|
||||
return err
|
||||
return drive1, err
|
||||
}
|
||||
|
@ -8,13 +8,12 @@ package handlers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/tjboldt/ProDOS-Utilities/prodos"
|
||||
)
|
||||
|
||||
// ReadBlockCommand handles requests to read ProDOS blocks
|
||||
func ReadBlockCommand(drive1 *os.File, drive2 *os.File) {
|
||||
func ReadBlockCommand(drive1 prodos.ReaderWriterAt, drive2 prodos.ReaderWriterAt) {
|
||||
blockLow, _ := comm.ReadByte()
|
||||
blockHigh, _ := comm.ReadByte()
|
||||
var driveUnit byte
|
||||
@ -35,15 +34,15 @@ func ReadBlockCommand(drive1 *os.File, drive2 *os.File) {
|
||||
driveNumber = 2
|
||||
}
|
||||
|
||||
slotNumber := driveUnit &0x7F >> 4
|
||||
slotNumber := driveUnit & 0x7F >> 4
|
||||
|
||||
block := int(blockHigh)*256 + int(blockLow)
|
||||
|
||||
fmt.Printf("Read block %04X in slot %d, drive %d...", block, slotNumber, driveNumber)
|
||||
|
||||
buffer,err := prodos.ReadBlock(file, block)
|
||||
buffer, err := prodos.ReadBlock(file, block)
|
||||
if err != nil {
|
||||
fmt.Printf("failed %s\n",err)
|
||||
fmt.Printf("failed %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -51,12 +50,12 @@ func ReadBlockCommand(drive1 *os.File, drive2 *os.File) {
|
||||
if err == nil {
|
||||
fmt.Printf("succeeded\n")
|
||||
} else {
|
||||
fmt.Printf("failed %s\n",err)
|
||||
fmt.Printf("failed %s\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
// WriteBlockCommand handles requests to write ProDOS blocks
|
||||
func WriteBlockCommand(drive1 *os.File, drive2 *os.File) {
|
||||
func WriteBlockCommand(drive1 prodos.ReaderWriterAt, drive2 prodos.ReaderWriterAt) {
|
||||
blockLow, _ := comm.ReadByte()
|
||||
blockHigh, _ := comm.ReadByte()
|
||||
|
||||
@ -81,13 +80,13 @@ func WriteBlockCommand(drive1 *os.File, drive2 *os.File) {
|
||||
|
||||
block := int(blockHigh)*256 + int(blockLow)
|
||||
|
||||
slotNumber := driveUnit &0x7F >> 4
|
||||
slotNumber := driveUnit & 0x7F >> 4
|
||||
|
||||
fmt.Printf("Write block %04X in slot %d, drive %d...", block, slotNumber, driveNumber)
|
||||
|
||||
err = comm.ReadBlock(buffer)
|
||||
if err != nil {
|
||||
fmt.Printf("failed %s\n",err)
|
||||
fmt.Printf("failed %s\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Printf("...")
|
||||
|
14
RaspberryPi/driveimage/Startup.bas
Normal file
14
RaspberryPi/driveimage/Startup.bas
Normal file
@ -0,0 +1,14 @@
|
||||
10 HOME
|
||||
11 PRINT "Apple2-IO-RPi"
|
||||
12 PRINT "(c)2021-2023 Terence J. Boldt"
|
||||
13 PRINT
|
||||
14 PRINT "This drive is dynamically generated"
|
||||
15 PRINT "from the current working directory on"
|
||||
16 PRINT "the Raspberry Pi and is in RAM only."
|
||||
17 PRINT
|
||||
18 PRINT "To start a shell to the RPi, type:"
|
||||
19 PRINT "-shell"
|
||||
20 PRINT
|
||||
21 PRINT "To add RPI command to ProDOS, type:"
|
||||
22 PRINT "-rpi.command"
|
||||
23 PRINT
|
28
RaspberryPi/driveimage/Update.Firmware.bas
Normal file
28
RaspberryPi/driveimage/Update.Firmware.bas
Normal file
@ -0,0 +1,28 @@
|
||||
10 HOME
|
||||
100 PRINT CHR$ (4)"BLOAD AT28C64B,A$2000"
|
||||
200 PRINT "Program the firmare in slot #"
|
||||
300 INPUT SL
|
||||
400 FW = 8192 + 256 * SL: REM Firmware source
|
||||
500 PS = 49287 + SL * 16: REM Firmware page selection
|
||||
600 EP = 49152 + SL * 256: REM EPROM location
|
||||
900 HOME
|
||||
1000 FOR PG = 0 TO 3
|
||||
1004 PRINT : PRINT
|
||||
1005 PRINT "Writing page "PG" to slot "SL
|
||||
1006 PRINT "_______________________________________"
|
||||
1007 PRINT "_______________________________________";
|
||||
1008 HTAB 1
|
||||
1010 POKE PS,PG * 16 + 15: REM Set firmware page
|
||||
1020 FOR X = 0 TO 255
|
||||
1030 A = PEEK (FW + PG * 2048 + X)
|
||||
1035 B = PEEK (EP + X): REM Skip if unchanged
|
||||
1037 IF (A = B) THEN GOTO 1045
|
||||
1040 POKE EP + X,A
|
||||
1041 B = PEEK (EP + X)
|
||||
1042 IF (B < > A) THEN GOTO 1041: REM Wait for write
|
||||
1045 HTAB (X / 256) * 39 + 1
|
||||
1046 INVERSE : PRINT " ";: NORMAL
|
||||
1050 NEXT X
|
||||
1060 NEXT PG
|
||||
1900 PRINT
|
||||
2000 PRINT "Firmware Update Complete"
|
Loading…
Reference in New Issue
Block a user