Apple2-IO-RPi/Apple2/Shell.lst
2021-11-05 15:15:54 -04:00

214 lines
8.0 KiB
Plaintext

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