diff --git a/Apple2/AT28C64B.bin b/Apple2/AT28C64B.bin index 6b17c96..41aaea0 100644 Binary files a/Apple2/AT28C64B.bin and b/Apple2/AT28C64B.bin differ diff --git a/Apple2/MenuFirmware.asm b/Apple2/MenuFirmware.asm index c9fd19b..3ea237c 100644 --- a/Apple2/MenuFirmware.asm +++ b/Apple2/MenuFirmware.asm @@ -16,6 +16,7 @@ OutputByte = $c08d+SLOT*$10 InputFlags = $c08b+SLOT*$10 OutputFlags = $c087+SLOT*$10 +ResetCommand = $00 ReadBlockCommand = $01 WriteBlockCommand = $02 GetTimeCommand = $03 @@ -29,6 +30,11 @@ Wait = $fca8 PrintChar = $fded Home = $fc58 ReadChar = $fd0c +BasCalc = $fbc1 +htab = $24 +vtab = $25 +BasL = $28 +htab80 = $057b .org SLOT*$100 + $C000 ;ID bytes for booting and drive detection @@ -57,7 +63,10 @@ Start: sta $36 lda #$fd sta $37 - jsr Home ;clear screen and show menu options + ;jsr Home ;clear screen and show menu options + lda #$10 + sta vtab + jsr BasCalc ldy #$00 PrintString: lda Text,y @@ -70,36 +79,36 @@ PrintString: WaitForRPi: lda InputFlags rol - bcs OK + bcs Reset lda #$ff jsr Wait lda #'.'+$80 jsr PrintChar jmp WaitForRPi -OK: - jsr Home ;clear screen - - lda #MenuCommand ;request menu text from RPi - jsr SendByte - -DumpOutput: - jsr GetByte - cmp #$00 - beq GetChar +Reset: + lda #'_'|$80 jsr PrintChar - clc - bcc DumpOutput + lda #ResetCommand + jsr SendByte + lda #$88 + jsr PrintChar + lda #'.'|$80 + jsr PrintChar + jsr GetByte + beq Ok + jmp Reset -GetChar: - jsr ReadChar - sec ;subtract ascii "1" to get 0 - 3 from "1" to "4" - sbc #$b1 - asl ;put in top nibble as EPROM page - asl - asl - asl - ora #$0f ;set all flags high +Ok: + lda #$8D + jsr PrintChar + lda #'O'|$80 + jsr PrintChar + lda #'K'|$80 + jsr PrintChar + +Boot: + lda #$0f jmp PageJump SendByte: diff --git a/Apple2/MenuFirmware.lst b/Apple2/MenuFirmware.lst index db8acab..77276fa 100644 --- a/Apple2/MenuFirmware.lst +++ b/Apple2/MenuFirmware.lst @@ -20,6 +20,7 @@ Current file: MenuFirmware.asm 000000r 1 InputFlags = $c08b+SLOT*$10 000000r 1 OutputFlags = $c087+SLOT*$10 000000r 1 +000000r 1 ResetCommand = $00 000000r 1 ReadBlockCommand = $01 000000r 1 WriteBlockCommand = $02 000000r 1 GetTimeCommand = $03 @@ -33,6 +34,11 @@ Current file: MenuFirmware.asm 000000r 1 PrintChar = $fded 000000r 1 Home = $fc58 000000r 1 ReadChar = $fd0c +000000r 1 BasCalc = $fbc1 +000000r 1 htab = $24 +000000r 1 vtab = $25 +000000r 1 BasL = $28 +000000r 1 htab80 = $057b 000000r 1 000000r 1 .org SLOT*$100 + $C000 00C700 1 ;ID bytes for booting and drive detection @@ -61,95 +67,94 @@ Current file: MenuFirmware.asm 00C71B 1 85 36 sta $36 00C71D 1 A9 FD lda #$fd 00C71F 1 85 37 sta $37 -00C721 1 20 58 FC jsr Home ;clear screen and show menu options -00C724 1 A0 00 ldy #$00 -00C726 1 PrintString: -00C726 1 B9 BC C7 lda Text,y -00C729 1 F0 08 beq WaitForRPi -00C72B 1 09 80 ora #$80 -00C72D 1 20 ED FD jsr PrintChar -00C730 1 C8 iny -00C731 1 D0 F3 bne PrintString -00C733 1 -00C733 1 WaitForRPi: -00C733 1 AD FB C0 lda InputFlags -00C736 1 2A rol -00C737 1 B0 0D bcs OK -00C739 1 A9 FF lda #$ff -00C73B 1 20 A8 FC jsr Wait -00C73E 1 A9 AE lda #'.'+$80 -00C740 1 20 ED FD jsr PrintChar -00C743 1 4C 33 C7 jmp WaitForRPi -00C746 1 -00C746 1 OK: -00C746 1 20 58 FC jsr Home ;clear screen -00C749 1 -00C749 1 A9 08 lda #MenuCommand ;request menu text from RPi -00C74B 1 20 6A C7 jsr SendByte -00C74E 1 -00C74E 1 DumpOutput: -00C74E 1 20 88 C7 jsr GetByte -00C751 1 C9 00 cmp #$00 -00C753 1 F0 06 beq GetChar -00C755 1 20 ED FD jsr PrintChar -00C758 1 18 clc -00C759 1 90 F3 bcc DumpOutput -00C75B 1 -00C75B 1 GetChar: -00C75B 1 20 0C FD jsr ReadChar -00C75E 1 38 sec ;subtract ascii "1" to get 0 - 3 from "1" to "4" -00C75F 1 E9 B1 sbc #$b1 -00C761 1 0A asl ;put in top nibble as EPROM page -00C762 1 0A asl -00C763 1 0A asl -00C764 1 0A asl -00C765 1 09 0F ora #$0f ;set all flags high -00C767 1 4C 0E C7 jmp PageJump -00C76A 1 -00C76A 1 SendByte: -00C76A 1 48 pha -00C76B 1 waitWrite: -00C76B 1 AD FB C0 lda InputFlags -00C76E 1 2A rol -00C76F 1 2A rol -00C770 1 B0 F9 bcs waitWrite -00C772 1 68 pla -00C773 1 8D FD C0 sta OutputByte -00C776 1 A9 3E lda #$3e ; set bit 0 low to indicate write started -00C778 1 8D F7 C0 sta OutputFlags -00C77B 1 finishWrite: +00C721 1 ;jsr Home ;clear screen and show menu options +00C721 1 A9 10 lda #$10 +00C723 1 85 25 sta vtab +00C725 1 20 C1 FB jsr BasCalc +00C728 1 A0 00 ldy #$00 +00C72A 1 PrintString: +00C72A 1 B9 BC C7 lda Text,y +00C72D 1 F0 08 beq WaitForRPi +00C72F 1 09 80 ora #$80 +00C731 1 20 ED FD jsr PrintChar +00C734 1 C8 iny +00C735 1 D0 F3 bne PrintString +00C737 1 +00C737 1 WaitForRPi: +00C737 1 AD FB C0 lda InputFlags +00C73A 1 2A rol +00C73B 1 B0 0D bcs Reset +00C73D 1 A9 FF lda #$ff +00C73F 1 20 A8 FC jsr Wait +00C742 1 A9 AE lda #'.'+$80 +00C744 1 20 ED FD jsr PrintChar +00C747 1 4C 37 C7 jmp WaitForRPi +00C74A 1 +00C74A 1 Reset: +00C74A 1 A9 DF lda #'_'|$80 +00C74C 1 20 ED FD jsr PrintChar +00C74F 1 A9 00 lda #ResetCommand +00C751 1 20 7A C7 jsr SendByte +00C754 1 A9 88 lda #$88 +00C756 1 20 ED FD jsr PrintChar +00C759 1 A9 AE lda #'.'|$80 +00C75B 1 20 ED FD jsr PrintChar +00C75E 1 20 98 C7 jsr GetByte +00C761 1 F0 03 beq Ok +00C763 1 4C 4A C7 jmp Reset +00C766 1 +00C766 1 Ok: +00C766 1 A9 8D lda #$8D +00C768 1 20 ED FD jsr PrintChar +00C76B 1 A9 CF lda #'O'|$80 +00C76D 1 20 ED FD jsr PrintChar +00C770 1 A9 CB lda #'K'|$80 +00C772 1 20 ED FD jsr PrintChar +00C775 1 +00C775 1 Boot: +00C775 1 A9 0F lda #$0f +00C777 1 4C 0E C7 jmp PageJump +00C77A 1 +00C77A 1 SendByte: +00C77A 1 48 pha +00C77B 1 waitWrite: 00C77B 1 AD FB C0 lda InputFlags 00C77E 1 2A rol 00C77F 1 2A rol -00C780 1 90 F9 bcc finishWrite -00C782 1 A9 3F lda #$3f -00C784 1 8D F7 C0 sta OutputFlags -00C787 1 60 rts -00C788 1 -00C788 1 GetByte: -00C788 1 A9 3D lda #$3d ;set read flag low -00C78A 1 8D F7 C0 sta OutputFlags -00C78D 1 waitRead: -00C78D 1 AD FB C0 lda InputFlags -00C790 1 2A rol -00C791 1 B0 FA bcs waitRead -00C793 1 AD FE C0 lda InputByte -00C796 1 48 pha -00C797 1 A9 3F lda #$3f ;set all flags high -00C799 1 8D F7 C0 sta OutputFlags -00C79C 1 finishRead: -00C79C 1 AD FB C0 lda InputFlags -00C79F 1 2A rol -00C7A0 1 90 FA bcc finishRead -00C7A2 1 68 pla -00C7A3 1 end: -00C7A3 1 60 rts -00C7A4 1 -00C7A4 1 00 00 00 00 .repeat 187- 13 && b < 32 { + fmt.Printf("Control code: %02X\n", b) + return + } + if len(escapeSequence) == 0 { + fmt.Printf("%c", b) + } if len(escapeSequence) > 0 { escapeSequence += string(b) + if escapeSequence == "^[]" { + fmt.Printf("Start operating system sequence\n") + operatingSystemSequence = true + return + } + if operatingSystemSequence { + if b == 0x07 { + fmt.Printf("Operating system sequence: %s\n", escapeSequence) + operatingSystemSequence = false + escapeSequence = "" + } + return + } // save cursor if escapeSequence == "^[7" { savedHtab = htab savedVtab = vtab + fmt.Printf("Save Cursor (%d, %d): %s\n", htab, vtab, escapeSequence) escapeSequence = "" } // restore cursor @@ -38,21 +66,34 @@ func sendCharacter(comm A2Io, b byte) { comm.WriteByte(byte(htab)) comm.WriteByte('V') comm.WriteByte(byte(vtab)) + fmt.Printf("Restore Cursor (%d, %d): %s\n", htab, vtab, escapeSequence) escapeSequence = "" } if (b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z') { switch b { // Set cursor location case 'H', 'f': - var ignore string - fmt.Sscanf(escapeSequence, "^[[%d;%d%s", &vtab, &htab, &ignore) - htab-- - vtab-- - comm.WriteByte('H') - comm.WriteByte(byte(htab)) - comm.WriteByte('V') - comm.WriteByte(byte(vtab)) - escapeSequence = "" + if escapeSequence == "^[[H" || escapeSequence == "^[[;H" { + htab = 0 + vtab = 0 + comm.WriteByte(0x19) // ^Y moves to home position + fmt.Printf("Home: %s\n", escapeSequence) + escapeSequence = "" + } else { + var ignore string + fmt.Sscanf(escapeSequence, "^[[%d;%d%s", &vtab, &htab, &ignore) + htab-- + vtab-- + if htab < 0 { + htab = 0 + } + comm.WriteByte('H') + comm.WriteByte(byte(htab)) + comm.WriteByte('V') + comm.WriteByte(byte(vtab)) + fmt.Printf("Set Cursor (%d, %d): %s\n", htab, vtab, escapeSequence) + escapeSequence = "" + } case 'r': fmt.Sscanf(escapeSequence, "^[[%d;%dr", &windowTop, &windowBottom) windowTop-- @@ -61,13 +102,68 @@ func sendCharacter(comm A2Io, b byte) { comm.WriteByte(byte(windowTop)) comm.WriteByte('B') comm.WriteByte(byte(windowBottom)) + fmt.Printf("Set Window (%d, %d): %s\n", windowTop, windowBottom, escapeSequence) + escapeSequence = "" + case 'A': + if escapeSequence == "^[[A" || escapeSequence == "^[A" { + vtab-- + comm.WriteByte('U') + fmt.Printf("Up: %s\n", escapeSequence) + } else { + var up int + fmt.Sscanf(escapeSequence, "^[[%dA", &up) + vtab -= up + for i := 0; i < up; i++ { + comm.WriteByte('U') + } + fmt.Printf("Up (%d): %s\n", up, escapeSequence) + } + escapeSequence = "" + case 'B': + if escapeSequence == "^[(B" || escapeSequence == "^[)B" || escapeSequence == "^[B" { + escapeSequence = "" + } else if escapeSequence == "^[[B" { + vtab++ + comm.WriteByte(0x0a) + fmt.Printf("Down: %s\n", escapeSequence) + } else { + var down int + fmt.Sscanf(escapeSequence, "^[[%dB", &down) + vtab += down + for i := 0; i < down; i++ { + comm.WriteByte(0x0a) + } + fmt.Printf("Down (%d): %s\n", down, escapeSequence) + } escapeSequence = "" case 'C': - var right int - fmt.Sscanf(escapeSequence, "^[[%dC", &right) - htab -= right - for i := 0; i < right; i++ { + if escapeSequence == "^[[C" || escapeSequence == "^[C" { + htab++ + comm.WriteByte(0x1c) + fmt.Printf("Right: %s\n", escapeSequence) + } else { + var right int + fmt.Sscanf(escapeSequence, "^[[%dC", &right) + htab += right + for i := 0; i < right; i++ { + comm.WriteByte(0x1c) + } + fmt.Printf("Right (%d): %s\n", right, escapeSequence) + } + escapeSequence = "" + case 'D': + if escapeSequence == "^[[D" || escapeSequence == "^[D" { + htab-- comm.WriteByte(0x08) + fmt.Printf("Left: %s\n", escapeSequence) + } else { + var left int + fmt.Sscanf(escapeSequence, "^[[%dD", &left) + htab -= left + for i := 0; i < left; i++ { + comm.WriteByte(0x08) + } + fmt.Printf("Left (%d): %s\n", left, escapeSequence) } escapeSequence = "" } @@ -76,6 +172,7 @@ func sendCharacter(comm A2Io, b byte) { case "^[[?1h": applicationMode = true comm.WriteByte(0x0c) // ^L clears the screen + fmt.Printf("Start application mode: %s\n", escapeSequence) escapeSequence = "" case "^[[?1l": applicationMode = false @@ -84,54 +181,65 @@ func sendCharacter(comm A2Io, b byte) { comm.WriteByte('B') comm.WriteByte(0x18) comm.WriteByte(0x0c) // ^L clears the screen + fmt.Printf("End application mode: %s\n", escapeSequence) escapeSequence = "" // Tab to home position - case "^[[H", "^[[;H", "^[[f", "^[[;f": + case "^[[f", "^[[;f": htab = 0 vtab = 0 comm.WriteByte(0x19) // ^Y moves to home position + fmt.Printf("Home: %s\n", escapeSequence) escapeSequence = "" // Clear screen case "^[[2J", "^[[c": htab = 0 vtab = 0 comm.WriteByte(0x0c) // ^L clears the screen + fmt.Printf("Clear screen: %s\n", escapeSequence) escapeSequence = "" - // Move down one line case "^[E": comm.WriteByte(0x0A) // ^J moves cursor down + fmt.Printf("Move down: %s\n", escapeSequence) escapeSequence = "" case "^[D": comm.WriteByte(0x17) // ^W scrolls up + fmt.Printf("Scroll up: %s\n", escapeSequence) escapeSequence = "" - // Clear line to the right case "^[[K", "^[[0K": comm.WriteByte(0x1d) // ^] clears to end of line + fmt.Printf("Clear line right: %s\n", escapeSequence) + escapeSequence = "" + case "^[[2K": + comm.WriteByte(0x1a) // ^Z clears line + fmt.Printf("Clear line: %s\n", escapeSequence) escapeSequence = "" case "^[M": comm.WriteByte(0x16) // ^V scrolls down + fmt.Printf("Scroll down: %s\n", escapeSequence) escapeSequence = "" - // Clear screen below cursor case "^[[J": comm.WriteByte(0x0b) // ^K clears to end of screen + fmt.Printf("Clear below cursor: %s\n", escapeSequence) escapeSequence = "" case "^[[7m": comm.WriteByte(0x0f) // ^O inverse video + fmt.Printf("Inverse: %s\n", escapeSequence) escapeSequence = "" case "^[[m", "^[[0m": - comm.WriteByte(0x0e) // ^N normal video + //comm.WriteByte(0x0e) // ^N normal video + fmt.Printf("Normal: %s\n", escapeSequence) escapeSequence = "" } if len(escapeSequence) > 0 { - fmt.Printf("\nUnhandled escape sequence: %s\n", escapeSequence) + fmt.Printf("Unhandled escape sequence: %s\n", escapeSequence) } escapeSequence = "" return } return } - fmt.Print(string(b)) + //fmt.Print(string(b)) htabIncrement := 0 switch b { // convert LF to CR for Apple II compatiblity @@ -158,7 +266,7 @@ func sendCharacter(comm A2Io, b byte) { default: htabIncrement = 1 } - if !applicationMode || htab < 78 { + if !applicationMode || htab < 79 { updateTabs(comm) b |= 0x80 htab += htabIncrement @@ -171,6 +279,26 @@ func sendCharacter(comm A2Io, b byte) { } } +func readCharacter(comm A2Io) (string, error) { + b, err := comm.ReadByte() + var s = string(b) + if err == nil { + switch b { + case 0x0b: // up + s = "\033[A" + case 0x0a: // down + s = "\033[B" + case 0x15: // right + s = "\033[C" + case 0x08: // left + s = "\033[D" + case 0x0d: // return + s = string(byte(0x0a)) + } + } + return s, err +} + func updateTabs(comm A2Io) { if htab >= 80 { htab = 0 diff --git a/RaspberryPi/apple2driver/driver.go b/RaspberryPi/apple2driver/driver.go index f5b18af..e3011ff 100644 --- a/RaspberryPi/apple2driver/driver.go +++ b/RaspberryPi/apple2driver/driver.go @@ -18,6 +18,7 @@ import ( "github.com/tjboldt/Apple2-IO-RPi/RaspberryPi/apple2driver/handlers" ) +const resetCommand = 0 const readBlockCommand = 1 const writeBlockCommand = 2 const getTimeCommand = 3 @@ -40,11 +41,16 @@ func main() { lastCommandTime := time.Now() + // In case Apple II is waiting, send 0 byte to start + comm.WriteByte(0) + for { command, err := comm.ReadByte() if err == nil { lastCommandTime = time.Now() switch command { + case resetCommand: + handlers.ResetCommand() case readBlockCommand: handlers.ReadBlockCommand(drive1, drive2) case writeBlockCommand: diff --git a/RaspberryPi/apple2driver/handlers/exec.go b/RaspberryPi/apple2driver/handlers/exec.go index c9aa1ba..da8eb22 100644 --- a/RaspberryPi/apple2driver/handlers/exec.go +++ b/RaspberryPi/apple2driver/handlers/exec.go @@ -117,7 +117,6 @@ func execCommand(linuxCommand string, workingDirectory string) { return case <-userCancelled: userCancelled <- true - comm.WriteString("^C\r") cmd.Process.Kill() return case <-inputComplete: @@ -132,6 +131,7 @@ func getStdout(stdout io.ReadCloser, outputComplete chan bool, userCancelled cha for { select { case <-userCancelled: + fmt.Printf("User Cancelled stdout\n") stdout.Close() return default: @@ -158,22 +158,15 @@ func getStdin(stdin io.WriteCloser, done chan bool, inputComplete chan bool, use inputComplete <- true return default: - b, err := comm.ReadByte() + s, err := comm.ReadCharacter() if err == nil { - if b == 0x03 { + if s == string(byte(0x00)) { stdin.Close() userCancelled <- true + fmt.Printf("\nUser cancelled stdin\n") return } - if b == 0x0d { - b = 0x0a - } - if b == 0x0b { - b = 'k' - } - - fmt.Printf("%c", b) - io.WriteString(stdin, string(b)) + io.WriteString(stdin, string(s)) } } } diff --git a/RaspberryPi/apple2driver/handlers/reset.go b/RaspberryPi/apple2driver/handlers/reset.go new file mode 100755 index 0000000..dcfd190 --- /dev/null +++ b/RaspberryPi/apple2driver/handlers/reset.go @@ -0,0 +1,18 @@ +// Copyright Terence J. Boldt (c)2020-2021 +// Use of this source code is governed by an MIT +// license that can be found in the LICENSE file. + +// This file is contains the handler for displaying the menu of choices on +// the Apple II + +package handlers + +import ( + "fmt" +) + +// ResetCommand responds with zero +func ResetCommand() { + fmt.Printf("Reset request\n") + comm.WriteByte(0) +} diff --git a/RaspberryPi/apple2driver/handlers/shell.go b/RaspberryPi/apple2driver/handlers/shell.go index bc0f910..599b982 100755 --- a/RaspberryPi/apple2driver/handlers/shell.go +++ b/RaspberryPi/apple2driver/handlers/shell.go @@ -7,6 +7,7 @@ package handlers import ( + "fmt" "os" "os/exec" @@ -41,14 +42,14 @@ func ShellCommand() { for { select { case <-outputComplete: - outputComplete <- true - cmd.Wait() + ptmx.Close() comm.WriteByte(0) return case <-userCancelled: - userCancelled <- true - comm.WriteString("^C\r") + fmt.Printf("User cancelled, killing process\n") + ptmx.Close() cmd.Process.Kill() + comm.WriteByte(0) return case <-inputComplete: cmd.Wait()