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
bne PrintString
copyDriver:
ldx #$00
ldy #$00
copyDriverByte:
lda $2100,x
sta $0300,x
inx
cpx #$e6
lda $2100,y
sta $0300,y
iny
cpy #$e6
bne copyDriverByte
;
; FIRST SAVE THE EXTERNAL COMMAND ADDRESS SO YOU WON'T
@ -114,14 +114,36 @@ copyDriverByte:
STA EXTRNCMD+1 ; command handler in the
LDA #>RPI ; external command JMP
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:
aschi "RPI command v000D"
.byte $8d
aschi "RPI command version: 000E"
.byte $8d
end:
.byte $00
.byte $00
.repeat 255-<end
.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
002034 1 A0 00 ldy #$00
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
00203B 1 09 80 ora #$80
00203D 1 20 ED FD jsr PrintChar
002040 1 C8 iny
002041 1 D0 F3 bne PrintString
002043 1 copyDriver:
002043 1 A2 00 ldx #$00
002043 1 A0 00 ldy #$00
002045 1 copyDriverByte:
002045 1 BD 00 21 lda $2100,x
002048 1 9D 00 03 sta $0300,x
00204B 1 E8 inx
00204C 1 E0 E6 cpx #$e6
002045 1 B9 00 21 lda $2100,y
002048 1 99 00 03 sta $0300,y
00204B 1 C8 iny
00204C 1 C0 E6 cpy #$e6
00204E 1 D0 F5 bne copyDriverByte
002050 1 ;
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
002061 1 A9 03 LDA #>RPI ; external command JMP
002063 1 8D 08 BE STA EXTRNCMD+2 ; vector.
002066 1 60 RTS
002067 1 ;
002067 1
002067 1 Text:
002067 1 D2 D0 C9 A0 aschi "RPI command v000D"
00206B 1 E3 EF ED ED
00206F 1 E1 EE E4 A0
002078 1 8D .byte $8d
002079 1 end:
002079 1 00 .byte $00
00207A 1
00207A 1 00 00 00 00 .repeat 255-<end
00207E 1 00 00 00 00
002082 1 00 00 00 00
002066 1
002066 1 A9 05 lda #ExecCommand
002068 1 20 6F 03 jsr SendByte
00206B 1 A0 00 ldy #$00
00206D 1 nextCommandByte:
00206D 1 B9 8C 20 lda a2help, y
002070 1 F0 07 beq finishCommand
002072 1 20 6F 03 jsr SendByte
002075 1 C8 iny
002076 1 4C 6D 20 jmp nextCommandByte
002079 1 finishCommand:
002079 1 A9 00 lda #$00
00207B 1 20 6F 03 jsr SendByte
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 .endrepeat
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 (
github.com/creack/pty v1.1.17
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/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/tjboldt/ProDOS-Utilities v0.0.0-20210607001541-fa0e76cf84c0 h1:iH6+15jJQsUMv9yeC5m26qh8VdJeRmZiYGM1ZG4aLVI=
github.com/tjboldt/ProDOS-Utilities v0.0.0-20210607001541-fa0e76cf84c0/go.mod h1:eBQRf0U+goRbBOxzFCwRW+FZmALC8dfYaqCwcqwzi74=
github.com/tjboldt/ProDOS-Utilities v0.3.0 h1:nlBvrGtvAV7KBfxiSkXHdosmDLEYAXMq955P8NL0qiE=
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"
)
var oldFirmware = false
// ReadBlockCommand handles requests to read ProDOS blocks
func ReadBlockCommand(drive1 *os.File, drive2 *os.File) {
blockLow, _ := comm.ReadByte()
@ -22,33 +20,38 @@ func ReadBlockCommand(drive1 *os.File, drive2 *os.File) {
var driveUnit byte
var err error
if !oldFirmware {
driveUnit, err = comm.ReadByte()
fmt.Printf("Drive unit: %0X\n", driveUnit)
driveUnit, err = comm.ReadByte()
if err != nil {
fmt.Printf("Drive unit not sent, assuming older firmware")
oldFirmware = true
}
if err != nil {
fmt.Printf("Failed to read block")
return
}
file := drive1
driveNumber := 1
if driveUnit >= 128 {
file = drive2
driveNumber = 2
}
slotNumber := driveUnit &0x7F >> 4
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)
if err == nil {
fmt.Printf("Read block completed\n")
fmt.Printf("succeeded\n")
} 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 err error
if !oldFirmware {
driveUnit, err = comm.ReadByte()
if err != nil {
fmt.Printf("Drive unit not sent, assuming older firmware")
oldFirmware = true
}
driveUnit, err = comm.ReadByte()
if err != nil {
fmt.Printf("Failed to write block")
return
}
file := drive1
driveNumber := 1
if driveUnit >= 128 {
file = drive2
driveNumber = 2
}
buffer := make([]byte, 512)
block := int(blockHigh)*256 + int(blockLow)
fmt.Printf("Write block %d\n", block)
slotNumber := driveUnit &0x7F >> 4
comm.ReadBlock(buffer)
prodos.WriteBlock(file, block, buffer)
fmt.Printf("Write block completed\n")
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)
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() {
comm.WriteString("\rVersion: " + info.Version + "\r")
comm.WriteString("\rDriver version: " + info.Version + "\r")
}
func a2help() {
comm.WriteString("\r" +
"Built-in commands:\r" +
"------------------\r" +
comm.WriteString("\rDriver version: " + info.Version + "\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" +
"a2version - display version number\r" +
"a2version - display driver version\r" +
"a2wifi - set up wifi\r" +
"a2timeout - seconds to timeout commands\r" +
"A2LOWER - force lowercase for II+\r" +
"a2lower - disable force lowercase for II+\r" +
"a2lower - disable force lowercase\r" +
"\r")
}
@ -161,14 +168,14 @@ func a2timeout(linuxCommand string) {
switch len(params) {
case 1:
comm.WriteString("\rCommand timeout: " + strconv.FormatInt(int64(execTimeoutSeconds),10) + "\r")
comm.WriteString("\rCommand timeout: " + strconv.FormatInt(int64(execTimeoutSeconds), 10) + "\r")
case 2:
timeoutSeconds, err := strconv.ParseInt(params[1], 10, 32)
if err != nil {
comm.WriteString("\rFailed to parse timeout\r")
} else {
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:
comm.WriteString("\rToo many parameters\n")

View File

@ -16,12 +16,12 @@ import (
// GetTimeCommand handles the request to get ProDOS time bytes
func GetTimeCommand() {
fmt.Printf("Sending date/time...\n")
fmt.Printf("Sending date/time...")
prodosTime := prodos.DateTimeToProDOS(time.Now())
for i := 0; i < len(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
// should be incremented with each driver update
const Version = "0025"
const Version = "0026"