mirror of
https://github.com/tjboldt/Apple2-IO-RPi.git
synced 2024-05-29 00:41:45 +00:00
Add new shell command (#34)
This commit is contained in:
parent
b37855dbfd
commit
5f365e01a6
205
Apple2/Shell.asm
Executable file
205
Apple2/Shell.asm
Executable file
|
@ -0,0 +1,205 @@
|
||||||
|
;ProDOS Zero Page
|
||||||
|
Command = $42 ;ProDOS Command
|
||||||
|
Unit = $43 ;ProDOS unit (SDDD0000)
|
||||||
|
BufferLo = $44
|
||||||
|
BufferHi = $45
|
||||||
|
BlockLo = $46
|
||||||
|
BlockHi = $47
|
||||||
|
|
||||||
|
; ProDOS Error Codes
|
||||||
|
IOError = $27
|
||||||
|
NoDevice = $28
|
||||||
|
WriteProtect = $2B
|
||||||
|
|
||||||
|
; hard code slot to 7 for now, will make it auto-detect later
|
||||||
|
SLOT = 7
|
||||||
|
|
||||||
|
InputByte = $c08e+SLOT*$10
|
||||||
|
OutputByte = $c08d+SLOT*$10
|
||||||
|
InputFlags = $c08b+SLOT*$10
|
||||||
|
OutputFlags = $c087+SLOT*$10
|
||||||
|
|
||||||
|
ReadBlockCommand = $01
|
||||||
|
WriteBlockCommand = $02
|
||||||
|
GetTimeCommand = $03
|
||||||
|
ChangeDriveCommand = $04
|
||||||
|
ExecCommand = $05
|
||||||
|
LoadFileCommand = $06
|
||||||
|
SaveFileCommand = $07
|
||||||
|
MenuCommand = $08
|
||||||
|
|
||||||
|
InputString = $fd6a
|
||||||
|
StringBuffer = $0200
|
||||||
|
PrintChar = $fded
|
||||||
|
Keyboard = $c000
|
||||||
|
ClearKeyboard = $c010
|
||||||
|
Wait = $fca8
|
||||||
|
PromptChar = $33
|
||||||
|
|
||||||
|
ESC = $9b
|
||||||
|
|
||||||
|
.org $2000
|
||||||
|
Start:
|
||||||
|
lda PromptChar
|
||||||
|
sta OldPromptChar
|
||||||
|
lda #'$'|$80
|
||||||
|
sta PromptChar
|
||||||
|
lda #ExecCommand
|
||||||
|
jsr SendByte
|
||||||
|
ldx #$00
|
||||||
|
sendHelpCommand:
|
||||||
|
lda HelpCommand,x
|
||||||
|
cmp #$00
|
||||||
|
beq sendHelpCommandEnd
|
||||||
|
jsr SendByte
|
||||||
|
inx
|
||||||
|
bpl sendHelpCommand
|
||||||
|
sendHelpCommandEnd:
|
||||||
|
lda #$00
|
||||||
|
jsr SendByte
|
||||||
|
bit ClearKeyboard
|
||||||
|
jsr DumpOutput
|
||||||
|
|
||||||
|
Prompt:
|
||||||
|
lda #ExecCommand
|
||||||
|
jsr SendByte
|
||||||
|
ldx #$00
|
||||||
|
sendPromptCommand:
|
||||||
|
lda PromptCommand,x
|
||||||
|
cmp #$00
|
||||||
|
beq sendPromptCommandEnd
|
||||||
|
jsr SendByte
|
||||||
|
inx
|
||||||
|
bpl sendPromptCommand
|
||||||
|
sendPromptCommandEnd:
|
||||||
|
lda #$00
|
||||||
|
jsr SendByte
|
||||||
|
bit ClearKeyboard
|
||||||
|
jsr DumpOutput
|
||||||
|
|
||||||
|
; get input
|
||||||
|
jsr InputString
|
||||||
|
; check for "exit"
|
||||||
|
lda StringBuffer
|
||||||
|
cmp #'e'|$80
|
||||||
|
bne Execute
|
||||||
|
lda StringBuffer+1
|
||||||
|
cmp #'x'|$80
|
||||||
|
bne Execute
|
||||||
|
lda StringBuffer+2
|
||||||
|
cmp #'i'|$80
|
||||||
|
bne Execute
|
||||||
|
lda StringBuffer+3
|
||||||
|
cmp #'t'|$80
|
||||||
|
bne Execute
|
||||||
|
lda OldPromptChar
|
||||||
|
sta PromptChar
|
||||||
|
rts
|
||||||
|
Execute:
|
||||||
|
bit ClearKeyboard
|
||||||
|
lda #ExecCommand
|
||||||
|
jsr SendByte
|
||||||
|
ldy #$00
|
||||||
|
sendInput:
|
||||||
|
lda $0200,y
|
||||||
|
cmp #$8d
|
||||||
|
beq sendNullTerminator
|
||||||
|
and #$7f
|
||||||
|
jsr SendByte
|
||||||
|
iny
|
||||||
|
bne sendInput
|
||||||
|
sendNullTerminator:
|
||||||
|
lda #$00
|
||||||
|
jsr SendByte
|
||||||
|
jsr DumpOutput
|
||||||
|
jmp Prompt
|
||||||
|
|
||||||
|
DumpOutput:
|
||||||
|
jsr GetByte
|
||||||
|
bcs skipOutput
|
||||||
|
cmp #$00
|
||||||
|
beq endOutput
|
||||||
|
cmp #ESC
|
||||||
|
beq escapeSequence
|
||||||
|
jsr PrintChar
|
||||||
|
skipOutput:
|
||||||
|
bit Keyboard ;check for keypress
|
||||||
|
bpl DumpOutput ;keep dumping output if no keypress
|
||||||
|
lda Keyboard ;send keypress to RPi
|
||||||
|
;jsr PrintChar
|
||||||
|
and #$7f
|
||||||
|
jsr SendByte
|
||||||
|
bit ClearKeyboard
|
||||||
|
clc
|
||||||
|
bcc DumpOutput
|
||||||
|
endOutput:
|
||||||
|
rts
|
||||||
|
escapeSequence:
|
||||||
|
jsr ParseEscape
|
||||||
|
clc
|
||||||
|
bcc DumpOutput
|
||||||
|
|
||||||
|
ParseEscape:
|
||||||
|
jsr GetByte ; expect first byte after ESC to be '['
|
||||||
|
cmp #'['|$80
|
||||||
|
beq endParse
|
||||||
|
checkLetter:
|
||||||
|
jsr GetByte ; loop until there is a letter
|
||||||
|
cmp #$C1
|
||||||
|
bcc checkLetter
|
||||||
|
endParse:
|
||||||
|
rts
|
||||||
|
|
||||||
|
SendByte:
|
||||||
|
pha
|
||||||
|
waitWrite:
|
||||||
|
lda InputFlags
|
||||||
|
rol
|
||||||
|
rol
|
||||||
|
bcs waitWrite
|
||||||
|
pla
|
||||||
|
sta OutputByte
|
||||||
|
lda #$1e ; set bit 0 low to indicate write started
|
||||||
|
sta OutputFlags
|
||||||
|
finishWrite:
|
||||||
|
lda InputFlags
|
||||||
|
rol
|
||||||
|
rol
|
||||||
|
bcc finishWrite
|
||||||
|
lda #$1f
|
||||||
|
sta OutputFlags
|
||||||
|
rts
|
||||||
|
|
||||||
|
GetByte:
|
||||||
|
lda #$1d ;set read flag low
|
||||||
|
sta OutputFlags
|
||||||
|
waitRead:
|
||||||
|
lda InputFlags
|
||||||
|
rol
|
||||||
|
bcc readByte
|
||||||
|
bit Keyboard ;keypress will abort waiting to read
|
||||||
|
bpl waitRead
|
||||||
|
lda #$1f ;set all flags high and exit
|
||||||
|
sta OutputFlags
|
||||||
|
sec ;failure
|
||||||
|
rts
|
||||||
|
readByte:
|
||||||
|
lda InputByte
|
||||||
|
pha
|
||||||
|
lda #$1f ;set all flags high
|
||||||
|
sta OutputFlags
|
||||||
|
finishRead:
|
||||||
|
lda InputFlags
|
||||||
|
rol
|
||||||
|
bcc finishRead
|
||||||
|
pla
|
||||||
|
clc ;success
|
||||||
|
end:
|
||||||
|
rts
|
||||||
|
|
||||||
|
HelpCommand:
|
||||||
|
.byte "a2help",$00
|
||||||
|
PromptCommand:
|
||||||
|
.byte "a2prompt",$00
|
||||||
|
OldPromptChar:
|
||||||
|
.byte "]"
|
BIN
Apple2/Shell.bin
Normal file
BIN
Apple2/Shell.bin
Normal file
Binary file not shown.
213
Apple2/Shell.lst
Normal file
213
Apple2/Shell.lst
Normal file
|
@ -0,0 +1,213 @@
|
||||||
|
ca65 V2.17 - Raspbian 2.17-1
|
||||||
|
Main file : Shell.asm
|
||||||
|
Current file: Shell.asm
|
||||||
|
|
||||||
|
000000r 1 ;ProDOS Zero Page
|
||||||
|
000000r 1 Command = $42 ;ProDOS Command
|
||||||
|
000000r 1 Unit = $43 ;ProDOS unit (SDDD0000)
|
||||||
|
000000r 1 BufferLo = $44
|
||||||
|
000000r 1 BufferHi = $45
|
||||||
|
000000r 1 BlockLo = $46
|
||||||
|
000000r 1 BlockHi = $47
|
||||||
|
000000r 1
|
||||||
|
000000r 1 ; ProDOS Error Codes
|
||||||
|
000000r 1 IOError = $27
|
||||||
|
000000r 1 NoDevice = $28
|
||||||
|
000000r 1 WriteProtect = $2B
|
||||||
|
000000r 1
|
||||||
|
000000r 1 ; hard code slot to 7 for now, will make it auto-detect later
|
||||||
|
000000r 1 SLOT = 7
|
||||||
|
000000r 1
|
||||||
|
000000r 1 InputByte = $c08e+SLOT*$10
|
||||||
|
000000r 1 OutputByte = $c08d+SLOT*$10
|
||||||
|
000000r 1 InputFlags = $c08b+SLOT*$10
|
||||||
|
000000r 1 OutputFlags = $c087+SLOT*$10
|
||||||
|
000000r 1
|
||||||
|
000000r 1 ReadBlockCommand = $01
|
||||||
|
000000r 1 WriteBlockCommand = $02
|
||||||
|
000000r 1 GetTimeCommand = $03
|
||||||
|
000000r 1 ChangeDriveCommand = $04
|
||||||
|
000000r 1 ExecCommand = $05
|
||||||
|
000000r 1 LoadFileCommand = $06
|
||||||
|
000000r 1 SaveFileCommand = $07
|
||||||
|
000000r 1 MenuCommand = $08
|
||||||
|
000000r 1
|
||||||
|
000000r 1 InputString = $fd6a
|
||||||
|
000000r 1 StringBuffer = $0200
|
||||||
|
000000r 1 PrintChar = $fded
|
||||||
|
000000r 1 Keyboard = $c000
|
||||||
|
000000r 1 ClearKeyboard = $c010
|
||||||
|
000000r 1 Wait = $fca8
|
||||||
|
000000r 1 PromptChar = $33
|
||||||
|
000000r 1
|
||||||
|
000000r 1 ESC = $9b
|
||||||
|
000000r 1
|
||||||
|
000000r 1 .org $2000
|
||||||
|
002000 1 Start:
|
||||||
|
002000 1 A5 33 lda PromptChar
|
||||||
|
002002 1 8D 20 21 sta OldPromptChar
|
||||||
|
002005 1 A9 A4 lda #'$'|$80
|
||||||
|
002007 1 85 33 sta PromptChar
|
||||||
|
002009 1 A9 05 lda #ExecCommand
|
||||||
|
00200B 1 20 C9 20 jsr SendByte
|
||||||
|
00200E 1 A2 00 ldx #$00
|
||||||
|
002010 1 sendHelpCommand:
|
||||||
|
002010 1 BD 10 21 lda HelpCommand,x
|
||||||
|
002013 1 C9 00 cmp #$00
|
||||||
|
002015 1 F0 06 beq sendHelpCommandEnd
|
||||||
|
002017 1 20 C9 20 jsr SendByte
|
||||||
|
00201A 1 E8 inx
|
||||||
|
00201B 1 10 F3 bpl sendHelpCommand
|
||||||
|
00201D 1 sendHelpCommandEnd:
|
||||||
|
00201D 1 A9 00 lda #$00
|
||||||
|
00201F 1 20 C9 20 jsr SendByte
|
||||||
|
002022 1 2C 10 C0 bit ClearKeyboard
|
||||||
|
002025 1 20 90 20 jsr DumpOutput
|
||||||
|
002028 1
|
||||||
|
002028 1 Prompt:
|
||||||
|
002028 1 A9 05 lda #ExecCommand
|
||||||
|
00202A 1 20 C9 20 jsr SendByte
|
||||||
|
00202D 1 A2 00 ldx #$00
|
||||||
|
00202F 1 sendPromptCommand:
|
||||||
|
00202F 1 BD 17 21 lda PromptCommand,x
|
||||||
|
002032 1 C9 00 cmp #$00
|
||||||
|
002034 1 F0 06 beq sendPromptCommandEnd
|
||||||
|
002036 1 20 C9 20 jsr SendByte
|
||||||
|
002039 1 E8 inx
|
||||||
|
00203A 1 10 F3 bpl sendPromptCommand
|
||||||
|
00203C 1 sendPromptCommandEnd:
|
||||||
|
00203C 1 A9 00 lda #$00
|
||||||
|
00203E 1 20 C9 20 jsr SendByte
|
||||||
|
002041 1 2C 10 C0 bit ClearKeyboard
|
||||||
|
002044 1 20 90 20 jsr DumpOutput
|
||||||
|
002047 1
|
||||||
|
002047 1 ; get input
|
||||||
|
002047 1 20 6A FD jsr InputString
|
||||||
|
00204A 1 ; check for "exit"
|
||||||
|
00204A 1 AD 00 02 lda StringBuffer
|
||||||
|
00204D 1 C9 E5 cmp #'e'|$80
|
||||||
|
00204F 1 D0 1B bne Execute
|
||||||
|
002051 1 AD 01 02 lda StringBuffer+1
|
||||||
|
002054 1 C9 F8 cmp #'x'|$80
|
||||||
|
002056 1 D0 14 bne Execute
|
||||||
|
002058 1 AD 02 02 lda StringBuffer+2
|
||||||
|
00205B 1 C9 E9 cmp #'i'|$80
|
||||||
|
00205D 1 D0 0D bne Execute
|
||||||
|
00205F 1 AD 03 02 lda StringBuffer+3
|
||||||
|
002062 1 C9 F4 cmp #'t'|$80
|
||||||
|
002064 1 D0 06 bne Execute
|
||||||
|
002066 1 AD 20 21 lda OldPromptChar
|
||||||
|
002069 1 85 33 sta PromptChar
|
||||||
|
00206B 1 60 rts
|
||||||
|
00206C 1 Execute:
|
||||||
|
00206C 1 2C 10 C0 bit ClearKeyboard
|
||||||
|
00206F 1 A9 05 lda #ExecCommand
|
||||||
|
002071 1 20 C9 20 jsr SendByte
|
||||||
|
002074 1 A0 00 ldy #$00
|
||||||
|
002076 1 sendInput:
|
||||||
|
002076 1 B9 00 02 lda $0200,y
|
||||||
|
002079 1 C9 8D cmp #$8d
|
||||||
|
00207B 1 F0 08 beq sendNullTerminator
|
||||||
|
00207D 1 29 7F and #$7f
|
||||||
|
00207F 1 20 C9 20 jsr SendByte
|
||||||
|
002082 1 C8 iny
|
||||||
|
002083 1 D0 F1 bne sendInput
|
||||||
|
002085 1 sendNullTerminator:
|
||||||
|
002085 1 A9 00 lda #$00
|
||||||
|
002087 1 20 C9 20 jsr SendByte
|
||||||
|
00208A 1 20 90 20 jsr DumpOutput
|
||||||
|
00208D 1 4C 28 20 jmp Prompt
|
||||||
|
002090 1
|
||||||
|
002090 1 DumpOutput:
|
||||||
|
002090 1 20 E7 20 jsr GetByte
|
||||||
|
002093 1 B0 0B bcs skipOutput
|
||||||
|
002095 1 C9 00 cmp #$00
|
||||||
|
002097 1 F0 1A beq endOutput
|
||||||
|
002099 1 C9 9B cmp #ESC
|
||||||
|
00209B 1 F0 17 beq escapeSequence
|
||||||
|
00209D 1 20 ED FD jsr PrintChar
|
||||||
|
0020A0 1 skipOutput:
|
||||||
|
0020A0 1 2C 00 C0 bit Keyboard ;check for keypress
|
||||||
|
0020A3 1 10 EB bpl DumpOutput ;keep dumping output if no keypress
|
||||||
|
0020A5 1 AD 00 C0 lda Keyboard ;send keypress to RPi
|
||||||
|
0020A8 1 ;jsr PrintChar
|
||||||
|
0020A8 1 29 7F and #$7f
|
||||||
|
0020AA 1 20 C9 20 jsr SendByte
|
||||||
|
0020AD 1 2C 10 C0 bit ClearKeyboard
|
||||||
|
0020B0 1 18 clc
|
||||||
|
0020B1 1 90 DD bcc DumpOutput
|
||||||
|
0020B3 1 endOutput:
|
||||||
|
0020B3 1 60 rts
|
||||||
|
0020B4 1 escapeSequence:
|
||||||
|
0020B4 1 20 BA 20 jsr ParseEscape
|
||||||
|
0020B7 1 18 clc
|
||||||
|
0020B8 1 90 D6 bcc DumpOutput
|
||||||
|
0020BA 1
|
||||||
|
0020BA 1 ParseEscape:
|
||||||
|
0020BA 1 20 E7 20 jsr GetByte ; expect first byte after ESC to be '['
|
||||||
|
0020BD 1 C9 DB cmp #'['|$80
|
||||||
|
0020BF 1 F0 07 beq endParse
|
||||||
|
0020C1 1 checkLetter:
|
||||||
|
0020C1 1 20 E7 20 jsr GetByte ; loop until there is a letter
|
||||||
|
0020C4 1 C9 C1 cmp #$C1
|
||||||
|
0020C6 1 90 F9 bcc checkLetter
|
||||||
|
0020C8 1 endParse:
|
||||||
|
0020C8 1 60 rts
|
||||||
|
0020C9 1
|
||||||
|
0020C9 1 SendByte:
|
||||||
|
0020C9 1 48 pha
|
||||||
|
0020CA 1 waitWrite:
|
||||||
|
0020CA 1 AD FB C0 lda InputFlags
|
||||||
|
0020CD 1 2A rol
|
||||||
|
0020CE 1 2A rol
|
||||||
|
0020CF 1 B0 F9 bcs waitWrite
|
||||||
|
0020D1 1 68 pla
|
||||||
|
0020D2 1 8D FD C0 sta OutputByte
|
||||||
|
0020D5 1 A9 1E lda #$1e ; set bit 0 low to indicate write started
|
||||||
|
0020D7 1 8D F7 C0 sta OutputFlags
|
||||||
|
0020DA 1 finishWrite:
|
||||||
|
0020DA 1 AD FB C0 lda InputFlags
|
||||||
|
0020DD 1 2A rol
|
||||||
|
0020DE 1 2A rol
|
||||||
|
0020DF 1 90 F9 bcc finishWrite
|
||||||
|
0020E1 1 A9 1F lda #$1f
|
||||||
|
0020E3 1 8D F7 C0 sta OutputFlags
|
||||||
|
0020E6 1 60 rts
|
||||||
|
0020E7 1
|
||||||
|
0020E7 1 GetByte:
|
||||||
|
0020E7 1 A9 1D lda #$1d ;set read flag low
|
||||||
|
0020E9 1 8D F7 C0 sta OutputFlags
|
||||||
|
0020EC 1 waitRead:
|
||||||
|
0020EC 1 AD FB C0 lda InputFlags
|
||||||
|
0020EF 1 2A rol
|
||||||
|
0020F0 1 90 0C bcc readByte
|
||||||
|
0020F2 1 2C 00 C0 bit Keyboard ;keypress will abort waiting to read
|
||||||
|
0020F5 1 10 F5 bpl waitRead
|
||||||
|
0020F7 1 A9 1F lda #$1f ;set all flags high and exit
|
||||||
|
0020F9 1 8D F7 C0 sta OutputFlags
|
||||||
|
0020FC 1 38 sec ;failure
|
||||||
|
0020FD 1 60 rts
|
||||||
|
0020FE 1 readByte:
|
||||||
|
0020FE 1 AD FE C0 lda InputByte
|
||||||
|
002101 1 48 pha
|
||||||
|
002102 1 A9 1F lda #$1f ;set all flags high
|
||||||
|
002104 1 8D F7 C0 sta OutputFlags
|
||||||
|
002107 1 finishRead:
|
||||||
|
002107 1 AD FB C0 lda InputFlags
|
||||||
|
00210A 1 2A rol
|
||||||
|
00210B 1 90 FA bcc finishRead
|
||||||
|
00210D 1 68 pla
|
||||||
|
00210E 1 18 clc ;success
|
||||||
|
00210F 1 end:
|
||||||
|
00210F 1 60 rts
|
||||||
|
002110 1
|
||||||
|
002110 1 HelpCommand:
|
||||||
|
002110 1 61 32 68 65 .byte "a2help",$00
|
||||||
|
002114 1 6C 70 00
|
||||||
|
002117 1 PromptCommand:
|
||||||
|
002117 1 61 32 70 72 .byte "a2prompt",$00
|
||||||
|
00211B 1 6F 6D 70 74
|
||||||
|
00211F 1 00
|
||||||
|
002120 1 OldPromptChar:
|
||||||
|
002120 1 5D .byte "]"
|
||||||
|
002121 1
|
|
@ -43,6 +43,9 @@ cat \
|
||||||
DriveFirmware.bin CommandFirmware.bin FileAccessFirmware.bin MenuFirmware.bin \
|
DriveFirmware.bin CommandFirmware.bin FileAccessFirmware.bin MenuFirmware.bin \
|
||||||
> AT28C64B.bin
|
> AT28C64B.bin
|
||||||
|
|
||||||
|
ca65 Shell.asm -o Shell.o --listing Shell.lst || exit 1
|
||||||
|
ld65 Shell.o -o Shell.bin -C ../.cicd/none.cfg || exit 1
|
||||||
|
|
||||||
rm ./*.o
|
rm ./*.o
|
||||||
rm DriveFirmware.bin
|
rm DriveFirmware.bin
|
||||||
rm MenuFirmware.bin
|
rm MenuFirmware.bin
|
||||||
|
@ -50,4 +53,5 @@ rm CommandFirmware.bin
|
||||||
rm FileAccessFirmware.bin
|
rm FileAccessFirmware.bin
|
||||||
|
|
||||||
ProDOS-Utilities -d ../RaspberryPi/Apple2-IO-RPi.hdv -c put -i AT28C64B.bin -p /APPLE2.IO.RPI/AT28C64B.BIN || exit 1
|
ProDOS-Utilities -d ../RaspberryPi/Apple2-IO-RPi.hdv -c put -i AT28C64B.bin -p /APPLE2.IO.RPI/AT28C64B.BIN || exit 1
|
||||||
|
ProDOS-Utilities -d ../RaspberryPi/Apple2-IO-RPi.hdv -c put -i Shell.bin -p /APPLE2.IO.RPI/SHELL || exit 1
|
||||||
ProDOS-Utilities -d ../RaspberryPi/Apple2-IO-RPi.hdv -c ls
|
ProDOS-Utilities -d ../RaspberryPi/Apple2-IO-RPi.hdv -c ls
|
||||||
|
|
Binary file not shown.
|
@ -54,6 +54,11 @@ func ExecCommand() {
|
||||||
a2wifi()
|
a2wifi()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if linuxCommand == "a2prompt" {
|
||||||
|
prompt := fmt.Sprintf("A2IO:%s ", workingDirectory)
|
||||||
|
comm.WriteString(prompt)
|
||||||
|
return
|
||||||
|
}
|
||||||
if linuxCommand == "a2wifi list" {
|
if linuxCommand == "a2wifi list" {
|
||||||
linuxCommand = a2wifiList()
|
linuxCommand = a2wifiList()
|
||||||
}
|
}
|
||||||
|
@ -66,17 +71,23 @@ func ExecCommand() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func execCommand(linuxCommand string, workingDirectory string) {
|
func execCommand(linuxCommand string, workingDirectory string) {
|
||||||
|
// force the command to combine stderr(2) into stdout(1)
|
||||||
|
linuxCommand += " 2>&1"
|
||||||
cmd := exec.Command("bash", "-c", linuxCommand)
|
cmd := exec.Command("bash", "-c", linuxCommand)
|
||||||
cmd.Dir = workingDirectory
|
cmd.Dir = workingDirectory
|
||||||
stdout, err := cmd.StdoutPipe()
|
stdout, err := cmd.StdoutPipe()
|
||||||
stdin, err := cmd.StdinPipe()
|
|
||||||
stderr, err := cmd.StderrPipe()
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Failed to set stdout\n")
|
fmt.Printf("Failed to set stdout\n")
|
||||||
comm.WriteString("Failed to set stdout\r")
|
comm.WriteString("Failed to set stdout\r")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
stdin, err := cmd.StdinPipe()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Failed to set stdin\n")
|
||||||
|
comm.WriteString("Failed to set stdin\r")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Printf("Command output:\n")
|
fmt.Printf("Command output:\n")
|
||||||
err = cmd.Start()
|
err = cmd.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -88,7 +99,6 @@ func execCommand(linuxCommand string, workingDirectory string) {
|
||||||
outputComplete := make(chan bool)
|
outputComplete := make(chan bool)
|
||||||
inputComplete := make(chan bool)
|
inputComplete := make(chan bool)
|
||||||
userCancelled := make(chan bool)
|
userCancelled := make(chan bool)
|
||||||
stderrComplete := make(chan bool)
|
|
||||||
|
|
||||||
if linuxCommand == "openssl" {
|
if linuxCommand == "openssl" {
|
||||||
fmt.Printf("\nSending help command...\n")
|
fmt.Printf("\nSending help command...\n")
|
||||||
|
@ -96,14 +106,17 @@ func execCommand(linuxCommand string, workingDirectory string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
go getStdin(stdin, outputComplete, inputComplete, userCancelled)
|
go getStdin(stdin, outputComplete, inputComplete, userCancelled)
|
||||||
go getStdout(stdout, outputComplete, userCancelled, stderrComplete)
|
go getStdout(stdout, outputComplete, userCancelled)
|
||||||
go getStderr(stderr, userCancelled, stderrComplete)
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-outputComplete:
|
case <-outputComplete:
|
||||||
outputComplete <- true
|
outputComplete <- true
|
||||||
|
cmd.Wait()
|
||||||
|
comm.WriteByte(0)
|
||||||
|
return
|
||||||
case <-userCancelled:
|
case <-userCancelled:
|
||||||
|
userCancelled <- true
|
||||||
comm.WriteString("^C\r")
|
comm.WriteString("^C\r")
|
||||||
cmd.Process.Kill()
|
cmd.Process.Kill()
|
||||||
return
|
return
|
||||||
|
@ -115,31 +128,19 @@ func execCommand(linuxCommand string, workingDirectory string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getStdout(stdout io.ReadCloser, outputComplete chan bool, userCancelled chan bool, stderrComplete chan bool) {
|
func getStdout(stdout io.ReadCloser, outputComplete chan bool, userCancelled chan bool) {
|
||||||
stderrDone := false
|
|
||||||
stdoutDone := false
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-userCancelled:
|
case <-userCancelled:
|
||||||
stdout.Close()
|
stdout.Close()
|
||||||
return
|
return
|
||||||
case <-stderrComplete:
|
|
||||||
stderrDone = true
|
|
||||||
if stdoutDone {
|
|
||||||
outputComplete <- true
|
|
||||||
return
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
bb := make([]byte, 1)
|
bb := make([]byte, 1)
|
||||||
n, err := stdout.Read(bb)
|
n, err := stdout.Read(bb)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
stdout.Close()
|
stdout.Close()
|
||||||
stdoutDone = true
|
outputComplete <- true
|
||||||
if stderrDone {
|
return
|
||||||
outputComplete <- true
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if n > 0 {
|
if n > 0 {
|
||||||
b := bb[0]
|
b := bb[0]
|
||||||
|
@ -149,27 +150,6 @@ func getStdout(stdout io.ReadCloser, outputComplete chan bool, userCancelled cha
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getStderr(stderr io.ReadCloser, userCancelled chan bool, stderrComplete chan bool) {
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <-userCancelled:
|
|
||||||
stderr.Close()
|
|
||||||
return
|
|
||||||
default:
|
|
||||||
bb := make([]byte, 1)
|
|
||||||
n, err := stderr.Read(bb)
|
|
||||||
if err != nil {
|
|
||||||
stderr.Close()
|
|
||||||
stderrComplete <- true
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if n > 0 {
|
|
||||||
sendCharacter(bb[0])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func getStdin(stdin io.WriteCloser, done chan bool, inputComplete chan bool, userCancelled chan bool) {
|
func getStdin(stdin io.WriteCloser, done chan bool, inputComplete chan bool, userCancelled chan bool) {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
@ -198,7 +178,8 @@ func getStdin(stdin io.WriteCloser, done chan bool, inputComplete chan bool, use
|
||||||
func a2help() {
|
func a2help() {
|
||||||
comm.WriteString("\r" +
|
comm.WriteString("\r" +
|
||||||
"This is a pseudo shell. Each command is executed as a process. The cd command\r" +
|
"This is a pseudo shell. Each command is executed as a process. The cd command\r" +
|
||||||
"is intercepted and sets the working directory for the next command.\r" +
|
"is intercepted and sets the working directory for the next command. The exit\r" +
|
||||||
|
"command will exit the shell when not running from firmware.\r" +
|
||||||
"\r" +
|
"\r" +
|
||||||
"Built-in commands:\r" +
|
"Built-in commands:\r" +
|
||||||
"a2help - display this message\r" +
|
"a2help - display this message\r" +
|
||||||
|
|
Loading…
Reference in New Issue
Block a user