Add error handling

This commit is contained in:
Terence Boldt 2022-03-04 18:24:59 -05:00
parent 74702e2cb5
commit da04931665
10 changed files with 134 additions and 67 deletions

View File

@ -94,12 +94,12 @@ PrintString:
iny iny
bne PrintString bne PrintString
copyDriver: copyDriver:
ldx #$00 ldy #$00
copyDriverByte: copyDriverByte:
lda $2100,x lda $2100,y
sta $0300,x sta $0300,y
inx iny
cpx #$e6 cpy #$e6
bne copyDriverByte bne copyDriverByte
; ;
; FIRST SAVE THE EXTERNAL COMMAND ADDRESS SO YOU WON'T ; FIRST SAVE THE EXTERNAL COMMAND ADDRESS SO YOU WON'T
@ -114,14 +114,36 @@ copyDriverByte:
STA EXTRNCMD+1 ; command handler in the STA EXTRNCMD+1 ; command handler in the
LDA #>RPI ; external command JMP LDA #>RPI ; external command JMP
STA EXTRNCMD+2 ; vector. STA EXTRNCMD+2 ; vector.
RTS
; lda #ExecCommand
jsr SendByte
ldy #$00
nextCommandByte:
lda a2help, y
beq finishCommand
jsr SendByte
iny
jmp nextCommandByte
finishCommand:
lda #$00
jsr SendByte
showVersion:
jsr GetByte
cmp #$00
beq FinishDriver
jsr PrintChar
jmp showVersion
FinishDriver:
rts
a2help:
.byte "a2help", $00
Text: Text:
aschi "RPI command v000D" aschi "RPI command version: 000E"
.byte $8d .byte $8d
end: end:
.byte $00 .byte $00
.repeat 255-<end .repeat 255-<end
.byte 0 .byte 0

Binary file not shown.

View File

@ -91,19 +91,19 @@ Current file: RPi.Command.asm
002031 1 8E 31 21 stx slotx + $1e01 ;set the slot for the driver 002031 1 8E 31 21 stx slotx + $1e01 ;set the slot for the driver
002034 1 A0 00 ldy #$00 002034 1 A0 00 ldy #$00
002036 1 PrintString: 002036 1 PrintString:
002036 1 B9 67 20 lda Text,y 002036 1 B9 93 20 lda Text,y
002039 1 F0 08 beq copyDriver 002039 1 F0 08 beq copyDriver
00203B 1 09 80 ora #$80 00203B 1 09 80 ora #$80
00203D 1 20 ED FD jsr PrintChar 00203D 1 20 ED FD jsr PrintChar
002040 1 C8 iny 002040 1 C8 iny
002041 1 D0 F3 bne PrintString 002041 1 D0 F3 bne PrintString
002043 1 copyDriver: 002043 1 copyDriver:
002043 1 A2 00 ldx #$00 002043 1 A0 00 ldy #$00
002045 1 copyDriverByte: 002045 1 copyDriverByte:
002045 1 BD 00 21 lda $2100,x 002045 1 B9 00 21 lda $2100,y
002048 1 9D 00 03 sta $0300,x 002048 1 99 00 03 sta $0300,y
00204B 1 E8 inx 00204B 1 C8 iny
00204C 1 E0 E6 cpx #$e6 00204C 1 C0 E6 cpy #$e6
00204E 1 D0 F5 bne copyDriverByte 00204E 1 D0 F5 bne copyDriverByte
002050 1 ; 002050 1 ;
002050 1 ; FIRST SAVE THE EXTERNAL COMMAND ADDRESS SO YOU WON'T 002050 1 ; FIRST SAVE THE EXTERNAL COMMAND ADDRESS SO YOU WON'T
@ -118,20 +118,43 @@ Current file: RPi.Command.asm
00205E 1 8D 07 BE STA EXTRNCMD+1 ; command handler in the 00205E 1 8D 07 BE STA EXTRNCMD+1 ; command handler in the
002061 1 A9 03 LDA #>RPI ; external command JMP 002061 1 A9 03 LDA #>RPI ; external command JMP
002063 1 8D 08 BE STA EXTRNCMD+2 ; vector. 002063 1 8D 08 BE STA EXTRNCMD+2 ; vector.
002066 1 60 RTS 002066 1
002067 1 ; 002066 1 A9 05 lda #ExecCommand
002067 1 002068 1 20 6F 03 jsr SendByte
002067 1 Text: 00206B 1 A0 00 ldy #$00
002067 1 D2 D0 C9 A0 aschi "RPI command v000D" 00206D 1 nextCommandByte:
00206B 1 E3 EF ED ED 00206D 1 B9 8C 20 lda a2help, y
00206F 1 E1 EE E4 A0 002070 1 F0 07 beq finishCommand
002078 1 8D .byte $8d 002072 1 20 6F 03 jsr SendByte
002079 1 end: 002075 1 C8 iny
002079 1 00 .byte $00 002076 1 4C 6D 20 jmp nextCommandByte
00207A 1 002079 1 finishCommand:
00207A 1 00 00 00 00 .repeat 255-<end 002079 1 A9 00 lda #$00
00207E 1 00 00 00 00 00207B 1 20 6F 03 jsr SendByte
002082 1 00 00 00 00 00207E 1 showVersion:
00207E 1 20 8D 03 jsr GetByte
002081 1 C9 00 cmp #$00
002083 1 F0 06 beq FinishDriver
002085 1 20 ED FD jsr PrintChar
002088 1 4C 7E 20 jmp showVersion
00208B 1 FinishDriver:
00208B 1 60 rts
00208C 1
00208C 1 a2help:
00208C 1 61 32 68 65 .byte "a2help", $00
002090 1 6C 70 00
002093 1
002093 1 Text:
002093 1 D2 D0 C9 A0 aschi "RPI command version: 000E"
002097 1 E3 EF ED ED
00209B 1 E1 EE E4 A0
0020AC 1 8D .byte $8d
0020AD 1 end:
0020AD 1 00 .byte $00
0020AE 1
0020AE 1 00 00 00 00 .repeat 255-<end
0020B2 1 00 00 00 00
0020B6 1 00 00 00 00
002100 1 .byte 0 002100 1 .byte 0
002100 1 .endrepeat 002100 1 .endrepeat
002100 1 002100 1

BIN
RaspberryPi/Apple2-IO-RPi.hdv Executable file → Normal file

Binary file not shown.

View File

@ -5,5 +5,5 @@ go 1.16
require ( require (
github.com/creack/pty v1.1.17 github.com/creack/pty v1.1.17
github.com/stianeikeland/go-rpio/v4 v4.6.0 github.com/stianeikeland/go-rpio/v4 v4.6.0
github.com/tjboldt/ProDOS-Utilities v0.0.0-20210607001541-fa0e76cf84c0 github.com/tjboldt/ProDOS-Utilities v0.3.0
) )

View File

@ -2,5 +2,5 @@ github.com/creack/pty v1.1.17 h1:QeVUsEDNrLBW4tMgZHvxy18sKtr6VI492kBhUfhDJNI=
github.com/creack/pty v1.1.17/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4= github.com/creack/pty v1.1.17/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
github.com/stianeikeland/go-rpio/v4 v4.6.0 h1:eAJgtw3jTtvn/CqwbC82ntcS+dtzUTgo5qlZKe677EY= github.com/stianeikeland/go-rpio/v4 v4.6.0 h1:eAJgtw3jTtvn/CqwbC82ntcS+dtzUTgo5qlZKe677EY=
github.com/stianeikeland/go-rpio/v4 v4.6.0/go.mod h1:A3GvHxC1Om5zaId+HqB3HKqx4K/AqeckxB7qRjxMK7o= github.com/stianeikeland/go-rpio/v4 v4.6.0/go.mod h1:A3GvHxC1Om5zaId+HqB3HKqx4K/AqeckxB7qRjxMK7o=
github.com/tjboldt/ProDOS-Utilities v0.0.0-20210607001541-fa0e76cf84c0 h1:iH6+15jJQsUMv9yeC5m26qh8VdJeRmZiYGM1ZG4aLVI= github.com/tjboldt/ProDOS-Utilities v0.3.0 h1:nlBvrGtvAV7KBfxiSkXHdosmDLEYAXMq955P8NL0qiE=
github.com/tjboldt/ProDOS-Utilities v0.0.0-20210607001541-fa0e76cf84c0/go.mod h1:eBQRf0U+goRbBOxzFCwRW+FZmALC8dfYaqCwcqwzi74= github.com/tjboldt/ProDOS-Utilities v0.3.0/go.mod h1:eBQRf0U+goRbBOxzFCwRW+FZmALC8dfYaqCwcqwzi74=

View File

@ -13,8 +13,6 @@ import (
"github.com/tjboldt/ProDOS-Utilities/prodos" "github.com/tjboldt/ProDOS-Utilities/prodos"
) )
var oldFirmware = false
// ReadBlockCommand handles requests to read ProDOS blocks // ReadBlockCommand handles requests to read ProDOS blocks
func ReadBlockCommand(drive1 *os.File, drive2 *os.File) { func ReadBlockCommand(drive1 *os.File, drive2 *os.File) {
blockLow, _ := comm.ReadByte() blockLow, _ := comm.ReadByte()
@ -22,33 +20,38 @@ func ReadBlockCommand(drive1 *os.File, drive2 *os.File) {
var driveUnit byte var driveUnit byte
var err error var err error
if !oldFirmware { driveUnit, err = comm.ReadByte()
driveUnit, err = comm.ReadByte()
fmt.Printf("Drive unit: %0X\n", driveUnit)
if err != nil { if err != nil {
fmt.Printf("Drive unit not sent, assuming older firmware") fmt.Printf("Failed to read block")
oldFirmware = true return
}
} }
file := drive1 file := drive1
driveNumber := 1
if driveUnit >= 128 { if driveUnit >= 128 {
file = drive2 file = drive2
driveNumber = 2
} }
slotNumber := driveUnit &0x7F >> 4
block := int(blockHigh)*256 + int(blockLow) block := int(blockHigh)*256 + int(blockLow)
fmt.Printf("Read block %d\n", block) fmt.Printf("Read block %04X in slot %d, drive %d...", block, slotNumber, driveNumber)
buffer := prodos.ReadBlock(file, block) buffer,err := prodos.ReadBlock(file, block)
if err != nil {
fmt.Printf("failed %s\n",err)
return
}
err = comm.WriteBlock(buffer) err = comm.WriteBlock(buffer)
if err == nil { if err == nil {
fmt.Printf("Read block completed\n") fmt.Printf("succeeded\n")
} else { } else {
fmt.Printf("Failed to read block\n") fmt.Printf("failed %s\n",err)
} }
} }
@ -60,27 +63,39 @@ func WriteBlockCommand(drive1 *os.File, drive2 *os.File) {
var driveUnit byte var driveUnit byte
var err error var err error
if !oldFirmware { driveUnit, err = comm.ReadByte()
driveUnit, err = comm.ReadByte() if err != nil {
if err != nil { fmt.Printf("Failed to write block")
fmt.Printf("Drive unit not sent, assuming older firmware") return
oldFirmware = true
}
} }
file := drive1 file := drive1
driveNumber := 1
if driveUnit >= 128 { if driveUnit >= 128 {
file = drive2 file = drive2
driveNumber = 2
} }
buffer := make([]byte, 512) buffer := make([]byte, 512)
block := int(blockHigh)*256 + int(blockLow) block := int(blockHigh)*256 + int(blockLow)
fmt.Printf("Write block %d\n", block) slotNumber := driveUnit &0x7F >> 4
comm.ReadBlock(buffer) fmt.Printf("Write block %04X in slot %d, drive %d...", block, slotNumber, driveNumber)
prodos.WriteBlock(file, block, buffer)
fmt.Printf("Write block completed\n") err = comm.ReadBlock(buffer)
if err != nil {
fmt.Printf("failed %s\n",err)
return
}
fmt.Printf("...")
err = prodos.WriteBlock(file, block, buffer)
if err == nil {
fmt.Printf("succeeded\n")
} else {
fmt.Printf("failed\n")
}
} }

View File

@ -140,19 +140,26 @@ func execCommand(linuxCommand string, workingDirectory string) {
} }
func a2version() { func a2version() {
comm.WriteString("\rVersion: " + info.Version + "\r") comm.WriteString("\rDriver version: " + info.Version + "\r")
} }
func a2help() { func a2help() {
comm.WriteString("\r" + comm.WriteString("\rDriver version: " + info.Version + "\r" +
"Built-in commands:\r" + "\r" +
"------------------\r" + "Example from ] prompt:\r" +
"]RPI ls /home/pi\r" +
"\r" +
"Example from Applesoft BASIC:\r" +
"]10 PRINT CHR$(4)\"RPI ping apple.com\"\r" +
"]RUN\r" +
"\r" +
"Driver commands called with RPI:\r" +
"a2help - display this message\r" + "a2help - display this message\r" +
"a2version - display version number\r" + "a2version - display driver version\r" +
"a2wifi - set up wifi\r" + "a2wifi - set up wifi\r" +
"a2timeout - seconds to timeout commands\r" + "a2timeout - seconds to timeout commands\r" +
"A2LOWER - force lowercase for II+\r" + "A2LOWER - force lowercase for II+\r" +
"a2lower - disable force lowercase for II+\r" + "a2lower - disable force lowercase\r" +
"\r") "\r")
} }
@ -161,14 +168,14 @@ func a2timeout(linuxCommand string) {
switch len(params) { switch len(params) {
case 1: case 1:
comm.WriteString("\rCommand timeout: " + strconv.FormatInt(int64(execTimeoutSeconds),10) + "\r") comm.WriteString("\rCommand timeout: " + strconv.FormatInt(int64(execTimeoutSeconds), 10) + "\r")
case 2: case 2:
timeoutSeconds, err := strconv.ParseInt(params[1], 10, 32) timeoutSeconds, err := strconv.ParseInt(params[1], 10, 32)
if err != nil { if err != nil {
comm.WriteString("\rFailed to parse timeout\r") comm.WriteString("\rFailed to parse timeout\r")
} else { } else {
execTimeoutSeconds = int(timeoutSeconds) execTimeoutSeconds = int(timeoutSeconds)
comm.WriteString("\rCommand timeout set to: " + strconv.FormatInt(int64(execTimeoutSeconds),10) + "\r") comm.WriteString("\rCommand timeout set to: " + strconv.FormatInt(int64(execTimeoutSeconds), 10) + "\r")
} }
default: default:
comm.WriteString("\rToo many parameters\n") comm.WriteString("\rToo many parameters\n")

View File

@ -16,12 +16,12 @@ import (
// GetTimeCommand handles the request to get ProDOS time bytes // GetTimeCommand handles the request to get ProDOS time bytes
func GetTimeCommand() { func GetTimeCommand() {
fmt.Printf("Sending date/time...\n") fmt.Printf("Sending date/time...")
prodosTime := prodos.DateTimeToProDOS(time.Now()) prodosTime := prodos.DateTimeToProDOS(time.Now())
for i := 0; i < len(prodosTime); i++ { for i := 0; i < len(prodosTime); i++ {
comm.WriteByte(prodosTime[i]) comm.WriteByte(prodosTime[i])
} }
fmt.Printf("Send time complete\n") fmt.Printf("%02X %02X %02X %02X\n", prodosTime[0], prodosTime[1], prodosTime[2], prodosTime[3])
} }

View File

@ -8,4 +8,4 @@ package info
// Version is the hexadecimal version number that // Version is the hexadecimal version number that
// should be incremented with each driver update // should be incremented with each driver update
const Version = "0025" const Version = "0026"