Apple2-IO-RPi/Apple2/CommandFirmware.lst

196 lines
7.7 KiB
Plaintext
Raw Normal View History

2024-01-03 03:51:33 +00:00
ca65 V2.18 - Debian 2.19-1
Main file : CommandFirmware.asm
Current file: CommandFirmware.asm
2024-01-03 03:51:33 +00:00
000000r 1 ; Copyright Terence J. Boldt (c)2020-2024
000000r 1 ; Use of this source code is governed by an MIT
000000r 1 ; license that can be found in the LICENSE file.
000000r 1
000000r 1 ; This file contains the source for the firmware
000000r 1 ; that was formerly used to act as a pseudo-shell
000000r 1
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 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
2021-07-17 14:17:52 +00:00
000000r 1 MenuCommand = $08
000000r 1
2021-07-02 02:34:09 +00:00
000000r 1 InputString = $fd67
000000r 1 PrintChar = $fded
2021-10-23 20:39:02 +00:00
000000r 1 Keyboard = $c000
000000r 1 ClearKeyboard = $c010
000000r 1 Wait = $fca8
2021-07-02 02:34:09 +00:00
000000r 1
000000r 1 .org SLOT*$100 + $C000
2021-04-01 12:43:04 +00:00
00C700 1 ;ID bytes for booting and drive detection
00C700 1 E0 20 cpx #$20 ;ID bytes for ProDOS and the
00C702 1 E0 00 cpx #$00 ; Apple Autostart ROM
00C704 1 E0 03 cpx #$03 ;
00C706 1
00C706 1 A2 70 ldx #SLOT*$10
00C708 1 86 2B stx $2b
00C70A 1 86 43 stx Unit
00C70C 1
00C70C 1 ;force EPROM to second page on boot
00C70C 1 A9 3F lda #$3f ;set all flags high and page 3 of EPROM for menu
00C70E 1 PageJump:
00C70E 1 8D F7 C0 sta OutputFlags
00C711 1 4C 19 C7 jmp Start ;this jump is only called if coming in from PageJump with A=$2f
00C714 1
00C714 1 ;entry points for ProDOS
00C714 1 DriverEntry:
00C714 1 A9 0F lda #$0f ;set all flags high and page 0 of EPROM
00C716 1 8D F7 C0 sta OutputFlags
00C719 1
00C719 1 Start:
00C719 1 20 00 C3 jsr $c300 ;enable 80 columns
2021-05-11 04:23:30 +00:00
00C71C 1 A9 05 lda #$05 ;execute command
2021-10-27 03:13:06 +00:00
00C71E 1 20 95 C7 jsr SendByte
2021-05-11 04:23:30 +00:00
00C721 1 A0 00 ldy #$00
00C723 1 sendHelp:
2021-10-27 03:13:06 +00:00
00C723 1 B9 8E C7 lda HelpCommand,y
2021-05-11 04:23:30 +00:00
00C726 1 F0 06 beq endSendHelp
2021-10-27 03:13:06 +00:00
00C728 1 20 95 C7 jsr SendByte
2021-05-11 04:23:30 +00:00
00C72B 1 C8 iny
00C72C 1 D0 F5 bne sendHelp
00C72E 1 endSendHelp:
00C72E 1 A9 00 lda #$00
2021-10-27 03:13:06 +00:00
00C730 1 20 95 C7 jsr SendByte
2021-10-23 20:39:02 +00:00
00C733 1 20 6B C7 jsr DumpOutput
2021-05-11 04:23:30 +00:00
00C736 1
00C736 1 A5 33 lda $33
00C738 1 48 pha
00C739 1 A9 A4 lda #$a4
00C73B 1 85 33 sta $33
00C73D 1 GetCommand:
2021-07-02 02:34:09 +00:00
00C73D 1 20 67 FD jsr InputString
2021-05-11 04:23:30 +00:00
00C740 1 AD 00 02 lda $0200
00C743 1 C9 8D cmp #$8d ;skip when return found
00C745 1 F0 F6 beq GetCommand
00C747 1 20 4D C7 jsr SendCommand
00C74A 1 18 clc
00C74B 1 90 F0 bcc GetCommand
00C74D 1
00C74D 1 SendCommand:
2021-10-23 20:39:02 +00:00
00C74D 1 2C 10 C0 bit ClearKeyboard
00C750 1 A9 05 lda #$05 ;send command 5 = exec
2021-10-27 03:13:06 +00:00
00C752 1 20 95 C7 jsr SendByte
2021-10-23 20:39:02 +00:00
00C755 1 A0 00 ldy #$00
00C757 1 getInput:
00C757 1 B9 00 02 lda $0200,y
00C75A 1 C9 8D cmp #$8d
00C75C 1 F0 08 beq sendNullTerminator
00C75E 1 29 7F and #$7f
2021-10-27 03:13:06 +00:00
00C760 1 20 95 C7 jsr SendByte
2021-10-23 20:39:02 +00:00
00C763 1 C8 iny
00C764 1 D0 F1 bne getInput
00C766 1 sendNullTerminator:
00C766 1 A9 00 lda #$00
2021-10-27 03:13:06 +00:00
00C768 1 20 95 C7 jsr SendByte
2021-10-23 20:39:02 +00:00
00C76B 1 DumpOutput:
Initial Pico hardware support * Added assemble.cmd for Windows. In the long run, some (c)make-based cross-plafrom solution seems preferable. * Fill up the menu page just like the other pages. * Allow to assemble for different hardware types. The first script parameter is used to set the ca65 symbol HW_TYPE. Without parameter, HW_TYPE is set to 0. * Avoid unwanted i/o access. Depending on the 6502, LDA addr,X and/or STA addr,X produce additional phantom reads. In order to avoid those phantom reads to do i/o access, I used the "classic" approach of moving those reads from page $C0 to page $BF. * Made use of BIT instruction to access InputFlags from firmware. Doing the same for access from disk-based software would require selfmodifying code as there's not bit <addr>,x instruction. * Removed push/pop from GetByte. After the replacing the rol instructions with bit instructions with a recent chnage, the only reason left to save a to the stack was setting the OutputFlags. But that can be done using x. * Added InputFlags check for consistency. * Added support for an alternative hardware type. The new hardware type has simple UART-type interface. Beside the two data registers, there are only the two bits to indicate readability and writability of the data registers. * Added another comminucation interface implementation. Use ACM CDC (or another proprietary) USB serial device for communication. Currently VID / PID of a Raspberry Pi Pico SDK CDC UART are hardcoded - see https://github.com/raspberrypi/usb-pid * Revert "Avoid unwanted i/o access." Neither the original hardware type nor the alternative hardware type have any read and write i/o port share addresses. Therefore phantom reads aren't an issue with those hardware types. This reverts commit ae5cb754fb9540794bdb5465a77e1263ca257539. * Adapt to the different error signatures on Linux. So far the code was only tested on Windows. * Added implementation of the alternative hardware type. The implemenation is based on a Raspberry Pi Pico - see https://github.com/a2retrosystems/A2retroNET The new hardware type has a simple UART-type interface. Beside the two data registers, there are only the two bits to indicate readability and writability of the data registers. * Modify the HD image for the alternative hardware type. It is likely desirable to have two HD images for the two hardware types. And likely the apple2driver program should default to the right one based on its protocol setting. BUt given that the HD image(s) shouldn't be part of the actual Git repo anyhow, I don't do anything about this here and now. * Fixed shell startup (?) At least on the alternative hardware, this "blindly sending" a reset command causes the shell to be terminated right away: The driver acknowldges the reset command with a zero byte - and that byte ends up being read by DumpOutput causing it to branch to endOutput. Maybe that sending a reset command is beneficial on the original hardware. Then another .if is required. Or DumpOutput shouldn't quit on reading a zero byte - the shell handler doesn't seem to send it on purpose(?) * Upate HD image with recent shell change. * Fix shell shutdown (?) At least on the alternative hardware, things happen this way: 1. The shell 'exit' command has ptyOut signal outputComplete and terminate. At this point, ptyIn is still blocked up to one second in ReadCharacter - and can therefore not react on outputComplete. 2. The outputComplete handler in ShellCommand sends a zero byte. This makes on the A2 DumpOutput return and the caller send a zero byte. ShellCommand must not return here as ptyIn is still blocked. 3. The zero byte from the A2 has ptyIn return from ReadCharacter, signal userCancelled and terminate. 4. ShellCommand can now return, but it must not send a zero byte, as the A2 is not expecting it - and will therefore later misinterpret it. Maybe the original hardware needs another handling, then differentiation of behavior in shell.go becomes necessary. * Moved boot text out of IIgs copyright message area. Having the boot text start at the left border of the third line makes it look nice on the cold boot screen of all Apple II's - and there's where the user sees it for some time while waiting for the RPi to come up. * Several adjustements: - Get latest Go version as of now. - Nowadays (?) GitHub 'git clone' seems to only work with a GitHub account. Therefore the zip download workaround. The becomes hopefully unnecessary soon with Go module magic. - Use 'go mod tidy' to update .sum file for now. - Error handling for an empty drive 2 is currently not exactly great, so download Total Replay for drive 2. Unfortunately there's no stable URL as of now. - Use $USER and $HOME instead of hardcoded values. - Removed deprecated syslog output directives. * Added brief fork description. * Added ProDOS-Utilities reference. * Reverted back to using 'git clone'. I've no idea why git acted up the other day :-( Now, everything is back to normal... * Ignore Pico build directory. * Updated from https://github.com/a2retrosystems/A2retroNET * Updated from https://github.com/a2retrosystems/A2retroNET At this point, nothing at all is done on an A2 reset. This can likely be improved. However, Apple2-IO-RPi doesn't seem to handle A2 reset exactly gracefully anyhow. In general, it seems desirable to introduce some simple framing protocol - like SLIP - that allows to recover from an A2 reset in the middle of an Apple2-IO-RPi command execution. Such a framing protocol would allow to introduce different frame types. One frame type could then be an A2 reset frame sent by the A2retroNET firmware. * Make use of brand new stable Total Replay download URL. Thanks to 4am :-) * Fixed typos. * Clone upstream ProDOS-Utilities. My ProDOS-Utilities pull request was merged. * Added support for boards without LED. * Updated link. * Adjusted to the current A2retroNET hardware. * Removed support for the Pico W. * Updated URL. * Updated URL. * Make use A2Pico library. * Added link to A2Pico. * Remove intermediates from repo. * Build intermediates from Pico build. * Have LED reflect status of logic ACM connection. * Update upstream repo references. * Adjust build instructions. * Update README.md * Fix build and update dependencies * Fix binary comparison * Fix firware bug on classic hardware --------- Co-authored-by: Oliver Schmidt <ol.sc@web.de>
2024-02-06 03:49:09 +00:00
00C76B 1 20 AD C7 jsr GetByte
2021-10-27 01:29:40 +00:00
00C76E 1 B0 07 bcs skipOutput
00C770 1 C9 00 cmp #$00
2021-10-27 03:13:06 +00:00
00C772 1 F0 19 beq endOutput
2021-10-27 01:29:40 +00:00
00C774 1 20 ED FD jsr PrintChar
00C777 1 skipOutput:
00C777 1 2C 00 C0 bit Keyboard ;check for keypress
00C77A 1 10 EF bpl DumpOutput ;keep dumping output if no keypress
00C77C 1 AD 00 C0 lda Keyboard ;send keypress to RPi
2021-10-27 03:13:06 +00:00
00C77F 1 20 ED FD jsr PrintChar
00C782 1 29 7F and #$7f
00C784 1 20 95 C7 jsr SendByte
00C787 1 2C 10 C0 bit ClearKeyboard
00C78A 1 18 clc
00C78B 1 90 DE bcc DumpOutput
00C78D 1 endOutput:
00C78D 1 60 rts
00C78E 1
00C78E 1 HelpCommand:
00C78E 1 61 32 68 65 .byte "a2help",$00
00C792 1 6C 70 00
00C795 1
00C795 1 SendByte:
Initial Pico hardware support * Added assemble.cmd for Windows. In the long run, some (c)make-based cross-plafrom solution seems preferable. * Fill up the menu page just like the other pages. * Allow to assemble for different hardware types. The first script parameter is used to set the ca65 symbol HW_TYPE. Without parameter, HW_TYPE is set to 0. * Avoid unwanted i/o access. Depending on the 6502, LDA addr,X and/or STA addr,X produce additional phantom reads. In order to avoid those phantom reads to do i/o access, I used the "classic" approach of moving those reads from page $C0 to page $BF. * Made use of BIT instruction to access InputFlags from firmware. Doing the same for access from disk-based software would require selfmodifying code as there's not bit <addr>,x instruction. * Removed push/pop from GetByte. After the replacing the rol instructions with bit instructions with a recent chnage, the only reason left to save a to the stack was setting the OutputFlags. But that can be done using x. * Added InputFlags check for consistency. * Added support for an alternative hardware type. The new hardware type has simple UART-type interface. Beside the two data registers, there are only the two bits to indicate readability and writability of the data registers. * Added another comminucation interface implementation. Use ACM CDC (or another proprietary) USB serial device for communication. Currently VID / PID of a Raspberry Pi Pico SDK CDC UART are hardcoded - see https://github.com/raspberrypi/usb-pid * Revert "Avoid unwanted i/o access." Neither the original hardware type nor the alternative hardware type have any read and write i/o port share addresses. Therefore phantom reads aren't an issue with those hardware types. This reverts commit ae5cb754fb9540794bdb5465a77e1263ca257539. * Adapt to the different error signatures on Linux. So far the code was only tested on Windows. * Added implementation of the alternative hardware type. The implemenation is based on a Raspberry Pi Pico - see https://github.com/a2retrosystems/A2retroNET The new hardware type has a simple UART-type interface. Beside the two data registers, there are only the two bits to indicate readability and writability of the data registers. * Modify the HD image for the alternative hardware type. It is likely desirable to have two HD images for the two hardware types. And likely the apple2driver program should default to the right one based on its protocol setting. BUt given that the HD image(s) shouldn't be part of the actual Git repo anyhow, I don't do anything about this here and now. * Fixed shell startup (?) At least on the alternative hardware, this "blindly sending" a reset command causes the shell to be terminated right away: The driver acknowldges the reset command with a zero byte - and that byte ends up being read by DumpOutput causing it to branch to endOutput. Maybe that sending a reset command is beneficial on the original hardware. Then another .if is required. Or DumpOutput shouldn't quit on reading a zero byte - the shell handler doesn't seem to send it on purpose(?) * Upate HD image with recent shell change. * Fix shell shutdown (?) At least on the alternative hardware, things happen this way: 1. The shell 'exit' command has ptyOut signal outputComplete and terminate. At this point, ptyIn is still blocked up to one second in ReadCharacter - and can therefore not react on outputComplete. 2. The outputComplete handler in ShellCommand sends a zero byte. This makes on the A2 DumpOutput return and the caller send a zero byte. ShellCommand must not return here as ptyIn is still blocked. 3. The zero byte from the A2 has ptyIn return from ReadCharacter, signal userCancelled and terminate. 4. ShellCommand can now return, but it must not send a zero byte, as the A2 is not expecting it - and will therefore later misinterpret it. Maybe the original hardware needs another handling, then differentiation of behavior in shell.go becomes necessary. * Moved boot text out of IIgs copyright message area. Having the boot text start at the left border of the third line makes it look nice on the cold boot screen of all Apple II's - and there's where the user sees it for some time while waiting for the RPi to come up. * Several adjustements: - Get latest Go version as of now. - Nowadays (?) GitHub 'git clone' seems to only work with a GitHub account. Therefore the zip download workaround. The becomes hopefully unnecessary soon with Go module magic. - Use 'go mod tidy' to update .sum file for now. - Error handling for an empty drive 2 is currently not exactly great, so download Total Replay for drive 2. Unfortunately there's no stable URL as of now. - Use $USER and $HOME instead of hardcoded values. - Removed deprecated syslog output directives. * Added brief fork description. * Added ProDOS-Utilities reference. * Reverted back to using 'git clone'. I've no idea why git acted up the other day :-( Now, everything is back to normal... * Ignore Pico build directory. * Updated from https://github.com/a2retrosystems/A2retroNET * Updated from https://github.com/a2retrosystems/A2retroNET At this point, nothing at all is done on an A2 reset. This can likely be improved. However, Apple2-IO-RPi doesn't seem to handle A2 reset exactly gracefully anyhow. In general, it seems desirable to introduce some simple framing protocol - like SLIP - that allows to recover from an A2 reset in the middle of an Apple2-IO-RPi command execution. Such a framing protocol would allow to introduce different frame types. One frame type could then be an A2 reset frame sent by the A2retroNET firmware. * Make use of brand new stable Total Replay download URL. Thanks to 4am :-) * Fixed typos. * Clone upstream ProDOS-Utilities. My ProDOS-Utilities pull request was merged. * Added support for boards without LED. * Updated link. * Adjusted to the current A2retroNET hardware. * Removed support for the Pico W. * Updated URL. * Updated URL. * Make use A2Pico library. * Added link to A2Pico. * Remove intermediates from repo. * Build intermediates from Pico build. * Have LED reflect status of logic ACM connection. * Update upstream repo references. * Adjust build instructions. * Update README.md * Fix build and update dependencies * Fix binary comparison * Fix firware bug on classic hardware --------- Co-authored-by: Oliver Schmidt <ol.sc@web.de>
2024-02-06 03:49:09 +00:00
00C795 1 2C FB C0 bit InputFlags
00C798 1 70 FB bvs SendByte
00C79A 1 8D FD C0 sta OutputByte
00C79D 1 .if HW_TYPE = 0
00C79D 1 A9 1E lda #$1e ; set bit 0 low to indicate write started
00C79F 1 8D F7 C0 sta OutputFlags
00C7A2 1 finishWrite:
00C7A2 1 2C FB C0 bit InputFlags
00C7A5 1 50 FB bvc finishWrite
00C7A7 1 A9 1F lda #$1f
00C7A9 1 8D F7 C0 sta OutputFlags
00C7AC 1 .endif
00C7AC 1 60 rts
00C7AD 1
00C7AD 1 GetByte:
00C7AD 1 .if HW_TYPE = 0
00C7AD 1 A2 1D ldx #$1d ;set read flag low
00C7AF 1 8E F7 C0 stx OutputFlags
00C7B2 1 .endif
00C7B2 1 waitRead:
00C7B2 1 2C FB C0 bit InputFlags
00C7B5 1 10 0C bpl readByte
00C7B7 1 2C 00 C0 bit Keyboard ;keypress will abort waiting to read
00C7BA 1 10 F6 bpl waitRead
00C7BC 1 .if HW_TYPE = 0
00C7BC 1 A9 1F lda #$1f ;set all flags high and exit
00C7BE 1 8D F7 C0 sta OutputFlags
00C7C1 1 .endif
00C7C1 1 38 sec ;failure
00C7C2 1 60 rts
00C7C3 1 readByte:
00C7C3 1 AD FE C0 lda InputByte
00C7C6 1 .if HW_TYPE = 0
00C7C6 1 A2 1F ldx #$1f ;set all flags high
00C7C8 1 8E F7 C0 stx OutputFlags
00C7CB 1 finishRead:
00C7CB 1 2C FB C0 bit InputFlags
00C7CE 1 10 FB bpl finishRead
00C7D0 1 .endif
00C7D0 1 18 clc ;success
00C7D1 1 end:
00C7D1 1 60 rts
00C7D2 1
00C7D2 1 00 00 00 00 .repeat 251-<end
00C7D6 1 00 00 00 00
00C7DA 1 00 00 00 00
00C7DE 1 00 00 00 00
00C7E2 1 00 00 00 00
00C7E6 1 00 00 00 00
00C7EA 1 00 00 00 00
00C7EE 1 00 00 00 00
00C7F2 1 00 00 00 00
00C7F6 1 00 00 00 00
00C7FA 1 00 00
2021-10-06 23:30:20 +00:00
00C7FC 1 .byte 0
00C7FC 1 .endrepeat
00C7FC 1
2021-04-01 12:43:04 +00:00
00C7FC 1 00 00 .byte 0,0 ;0000 blocks = check status
00C7FE 1 07 .byte 7 ;bit set(0=status 1=read 2=write) unset(3=format, 4/5=number of volumes, 6=interruptable, 7=removable)
00C7FF 1 14 .byte DriverEntry&$00FF ;low byte of entry
00C7FF 1