From aa5910cee8a6d8c24cda6334b1781617d1883a3d Mon Sep 17 00:00:00 2001 From: Terence Boldt Date: Mon, 5 Feb 2024 22:49:09 -0500 Subject: [PATCH] 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 ,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 --- .github/ISSUE_TEMPLATE/bug_report.yml | 18 +- .gitignore | 1 + Apple2/CommandFirmware.asm | 43 ++- Apple2/CommandFirmware.lst | 110 +++--- Apple2/DriveFirmware.asm | 31 +- Apple2/DriveFirmware.lst | 79 +++-- Apple2/FileAccessFirmware.asm | 41 +-- Apple2/FileAccessFirmware.lst | 121 ++++--- Apple2/MenuFirmware.asm | 96 ++++-- Apple2/MenuFirmware.lst | 248 ++++++++------ Apple2/RPi.Command.asm | 6 + Apple2/RPi.Command.lst | 6 + Apple2/Shell.asm | 22 +- Apple2/Shell.lst | 372 +++++++++++---------- Apple2/assemble.cmd | 105 ++++++ Apple2/assemble.sh | 70 ++-- Apple2/compare.sh | 70 ++-- README.md | 14 +- RaspberryPi/apple2driver/a2io/cdcio.go | 151 +++++++++ RaspberryPi/apple2driver/driver.go | 25 +- RaspberryPi/apple2driver/go.mod | 5 +- RaspberryPi/apple2driver/go.sum | 27 +- RaspberryPi/apple2driver/handlers/shell.go | 5 +- RaspberryPi/apple2driver/info/version.go | 2 +- RaspberryPi/driveimage/AT28C64B.bin | Bin 8192 -> 8192 bytes RaspberryPi/driveimage/Shell.bin | Bin 434 -> 436 bytes RaspberryPi/setup.sh | 10 +- RaspberryPiPico/CMakeLists.txt | 39 +++ RaspberryPiPico/LICENSE | 21 ++ RaspberryPiPico/board.c | 78 +++++ RaspberryPiPico/board.h | 32 ++ RaspberryPiPico/incbin.S | 6 + RaspberryPiPico/main.c | 92 +++++ RaspberryPiPico/pico_sdk_import.cmake | 73 ++++ 34 files changed, 1385 insertions(+), 634 deletions(-) create mode 100644 Apple2/assemble.cmd create mode 100644 RaspberryPi/apple2driver/a2io/cdcio.go create mode 100644 RaspberryPiPico/CMakeLists.txt create mode 100644 RaspberryPiPico/LICENSE create mode 100644 RaspberryPiPico/board.c create mode 100644 RaspberryPiPico/board.h create mode 100644 RaspberryPiPico/incbin.S create mode 100644 RaspberryPiPico/main.c create mode 100644 RaspberryPiPico/pico_sdk_import.cmake diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 2228e07..6ab5174 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -22,15 +22,10 @@ body: label: Hardware Version description: What version of the hardware are you running? options: - - Sixth Prototype (Purchased from Terence) - - Sixth Prototype (Self-assembled) - - Sixth Prototype (Purchased from third party) - - Fifth Prototype (Purchased from Terence) - - Fifth Prototype (Self-assembled) - - Fifth Prototype (Purchased from third party) - - Fourth Prototype (Purchased from Terence) - - Fourth Prototype (Self-assembled) - - Fourth Prototype (Purchased from third party) + - RPi Pico + - Sixth Prototype (lastest classic hardware) + - Fifth Prototype (classic hardware without jumper) + - Fourth Prototype (classic hardware with EPROM) validations: required: true - type: dropdown @@ -39,6 +34,8 @@ body: label: Firmware Version description: What version of the firmware are you running? (shown on boot screen) options: + - 8010 (initial RPi Pico hardware) + - 0010 (classic hardware) - 000F - Older (not shown on boot, pre-2022-Feb-07) validations: @@ -49,6 +46,7 @@ body: label: Driver Version description: What version of the driver are you running? Check with `RPI a2version` options: + - 002D (add support for RPi Pico hardware) - 002C (fix nano editor) - 002B (fix keyboard delay) - 002A (reduce CPU usage) @@ -69,6 +67,8 @@ body: label: Shell Version description: What version of the shell are you running?` options: + - 800F (initial RPi Pico support) + - 000F (classic hardware support) - 000E (fix hang on exit) - 000D (added version info) - Older (pre-2022-Mar-01) diff --git a/.gitignore b/.gitignore index 3a16924..390a0a0 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ *.DS_Store RaspberryPi/apple2driver/apple2driver RaspberryPi/Apple2-IO-RPi.log +RaspberryPiPico/build/ Hardware/Apple2IORPi-backups/ diff --git a/Apple2/CommandFirmware.asm b/Apple2/CommandFirmware.asm index ca80723..3ec96b2 100644 --- a/Apple2/CommandFirmware.asm +++ b/Apple2/CommandFirmware.asm @@ -127,48 +127,45 @@ HelpCommand: .byte "a2help",$00 SendByte: - pha -waitWrite: - lda InputFlags - rol - rol - bcs waitWrite - pla + bit InputFlags + bvs SendByte sta OutputByte +.if HW_TYPE = 0 lda #$1e ; set bit 0 low to indicate write started sta OutputFlags finishWrite: - lda InputFlags - rol - rol - bcc finishWrite + bit InputFlags + bvc finishWrite lda #$1f sta OutputFlags +.endif rts GetByte: - lda #$1d ;set read flag low - sta OutputFlags +.if HW_TYPE = 0 + ldx #$1d ;set read flag low + stx OutputFlags +.endif waitRead: - lda InputFlags - rol - bcc readByte + bit InputFlags + bpl readByte bit Keyboard ;keypress will abort waiting to read bpl waitRead +.if HW_TYPE = 0 lda #$1f ;set all flags high and exit sta OutputFlags +.endif sec ;failure rts readByte: lda InputByte - pha - lda #$1f ;set all flags high - sta OutputFlags +.if HW_TYPE = 0 + ldx #$1f ;set all flags high + stx OutputFlags finishRead: - lda InputFlags - rol - bcc finishRead - pla + bit InputFlags + bpl finishRead +.endif clc ;success end: rts diff --git a/Apple2/CommandFirmware.lst b/Apple2/CommandFirmware.lst index 8989605..4c3767f 100644 --- a/Apple2/CommandFirmware.lst +++ b/Apple2/CommandFirmware.lst @@ -109,7 +109,7 @@ Current file: CommandFirmware.asm 00C766 1 A9 00 lda #$00 00C768 1 20 95 C7 jsr SendByte 00C76B 1 DumpOutput: -00C76B 1 20 B3 C7 jsr GetByte +00C76B 1 20 AD C7 jsr GetByte 00C76E 1 B0 07 bcs skipOutput 00C770 1 C9 00 cmp #$00 00C772 1 F0 19 beq endOutput @@ -132,60 +132,60 @@ Current file: CommandFirmware.asm 00C792 1 6C 70 00 00C795 1 00C795 1 SendByte: -00C795 1 48 pha -00C796 1 waitWrite: -00C796 1 AD FB C0 lda InputFlags -00C799 1 2A rol -00C79A 1 2A rol -00C79B 1 B0 F9 bcs waitWrite -00C79D 1 68 pla -00C79E 1 8D FD C0 sta OutputByte -00C7A1 1 A9 1E lda #$1e ; set bit 0 low to indicate write started -00C7A3 1 8D F7 C0 sta OutputFlags -00C7A6 1 finishWrite: -00C7A6 1 AD FB C0 lda InputFlags -00C7A9 1 2A rol -00C7AA 1 2A rol -00C7AB 1 90 F9 bcc finishWrite -00C7AD 1 A9 1F lda #$1f -00C7AF 1 8D F7 C0 sta OutputFlags -00C7B2 1 60 rts -00C7B3 1 -00C7B3 1 GetByte: -00C7B3 1 A9 1D lda #$1d ;set read flag low -00C7B5 1 8D F7 C0 sta OutputFlags -00C7B8 1 waitRead: -00C7B8 1 AD FB C0 lda InputFlags -00C7BB 1 2A rol -00C7BC 1 90 0C bcc readByte -00C7BE 1 2C 00 C0 bit Keyboard ;keypress will abort waiting to read -00C7C1 1 10 F5 bpl waitRead -00C7C3 1 A9 1F lda #$1f ;set all flags high and exit -00C7C5 1 8D F7 C0 sta OutputFlags -00C7C8 1 38 sec ;failure -00C7C9 1 60 rts -00C7CA 1 readByte: -00C7CA 1 AD FE C0 lda InputByte -00C7CD 1 48 pha -00C7CE 1 A9 1F lda #$1f ;set all flags high -00C7D0 1 8D F7 C0 sta OutputFlags -00C7D3 1 finishRead: -00C7D3 1 AD FB C0 lda InputFlags -00C7D6 1 2A rol -00C7D7 1 90 FA bcc finishRead -00C7D9 1 68 pla -00C7DA 1 18 clc ;success -00C7DB 1 end: -00C7DB 1 60 rts -00C7DC 1 -00C7DC 1 00 00 00 00 .repeat 251- ../RaspberryPi/driveimage/AT28C64B.bin -ca65 Shell.asm -o Shell.o --listing Shell.lst || exit 1 +ca65 Shell.asm -D HW_TYPE=$HW_TYPE -o Shell.o --listing Shell.lst || exit 1 ld65 Shell.o -o ../RaspberryPi/driveimage/Shell.bin -C ../.cicd/none.cfg || exit 1 -ca65 RPi.Command.asm -o RPi.Command.o --listing RPi.Command.lst || exit 1 +ca65 RPi.Command.asm -D HW_TYPE=$HW_TYPE -o RPi.Command.o --listing RPi.Command.lst || exit 1 ld65 RPi.Command.o -o ../RaspberryPi/driveimage/RPi.Command.bin -C ../.cicd/none.cfg || exit 1 rm ./*.o diff --git a/Apple2/compare.sh b/Apple2/compare.sh index 9bf7b6c..a15ba06 100755 --- a/Apple2/compare.sh +++ b/Apple2/compare.sh @@ -1,52 +1,54 @@ #!/bin/sh -ca65 DriveFirmware.asm -D SLOT=0 -o DriveSlot0.o || exit 1 -ca65 DriveFirmware.asm -D SLOT=1 -o DriveSlot1.o || exit 1 -ca65 DriveFirmware.asm -D SLOT=2 -o DriveSlot2.o || exit 1 -ca65 DriveFirmware.asm -D SLOT=3 -o DriveSlot3.o || exit 1 -ca65 DriveFirmware.asm -D SLOT=4 -o DriveSlot4.o || exit 1 -ca65 DriveFirmware.asm -D SLOT=5 -o DriveSlot5.o || exit 1 -ca65 DriveFirmware.asm -D SLOT=6 -o DriveSlot6.o || exit 1 -ca65 DriveFirmware.asm -D SLOT=7 -o DriveSlot7.o --listing DriveFirmware.lst.new --list-bytes 255 || exit 1 +HW_TYPE=${1-0} + +ca65 DriveFirmware.asm -D HW_TYPE=$HW_TYPE -D SLOT=0 -o DriveSlot0.o || exit 1 +ca65 DriveFirmware.asm -D HW_TYPE=$HW_TYPE -D SLOT=1 -o DriveSlot1.o || exit 1 +ca65 DriveFirmware.asm -D HW_TYPE=$HW_TYPE -D SLOT=2 -o DriveSlot2.o || exit 1 +ca65 DriveFirmware.asm -D HW_TYPE=$HW_TYPE -D SLOT=3 -o DriveSlot3.o || exit 1 +ca65 DriveFirmware.asm -D HW_TYPE=$HW_TYPE -D SLOT=4 -o DriveSlot4.o || exit 1 +ca65 DriveFirmware.asm -D HW_TYPE=$HW_TYPE -D SLOT=5 -o DriveSlot5.o || exit 1 +ca65 DriveFirmware.asm -D HW_TYPE=$HW_TYPE -D SLOT=6 -o DriveSlot6.o || exit 1 +ca65 DriveFirmware.asm -D HW_TYPE=$HW_TYPE -D SLOT=7 -o DriveSlot7.o --listing DriveFirmware.lst.new --list-bytes 255 || exit 1 ld65 DriveSlot0.o DriveSlot1.o DriveSlot2.o DriveSlot3.o DriveSlot4.o DriveSlot5.o DriveSlot6.o DriveSlot7.o -o DriveFirmware.bin.new -C ../.cicd/none.cfg || exit 1 -ca65 MenuFirmware.asm -D SLOT=0 -o MenuSlot0.o || exit 1 -ca65 MenuFirmware.asm -D SLOT=1 -o MenuSlot1.o || exit 1 -ca65 MenuFirmware.asm -D SLOT=2 -o MenuSlot2.o || exit 1 -ca65 MenuFirmware.asm -D SLOT=3 -o MenuSlot3.o || exit 1 -ca65 MenuFirmware.asm -D SLOT=4 -o MenuSlot4.o || exit 1 -ca65 MenuFirmware.asm -D SLOT=5 -o MenuSlot5.o || exit 1 -ca65 MenuFirmware.asm -D SLOT=6 -o MenuSlot6.o || exit 1 -ca65 MenuFirmware.asm -D SLOT=7 -o MenuSlot7.o --listing MenuFirmware.lst.new --list-bytes 255 || exit 1 +ca65 MenuFirmware.asm -D HW_TYPE=$HW_TYPE -D SLOT=0 -o MenuSlot0.o || exit 1 +ca65 MenuFirmware.asm -D HW_TYPE=$HW_TYPE -D SLOT=1 -o MenuSlot1.o || exit 1 +ca65 MenuFirmware.asm -D HW_TYPE=$HW_TYPE -D SLOT=2 -o MenuSlot2.o || exit 1 +ca65 MenuFirmware.asm -D HW_TYPE=$HW_TYPE -D SLOT=3 -o MenuSlot3.o || exit 1 +ca65 MenuFirmware.asm -D HW_TYPE=$HW_TYPE -D SLOT=4 -o MenuSlot4.o || exit 1 +ca65 MenuFirmware.asm -D HW_TYPE=$HW_TYPE -D SLOT=5 -o MenuSlot5.o || exit 1 +ca65 MenuFirmware.asm -D HW_TYPE=$HW_TYPE -D SLOT=6 -o MenuSlot6.o || exit 1 +ca65 MenuFirmware.asm -D HW_TYPE=$HW_TYPE -D SLOT=7 -o MenuSlot7.o --listing MenuFirmware.lst.new --list-bytes 255 || exit 1 ld65 MenuSlot0.o MenuSlot1.o MenuSlot2.o MenuSlot3.o MenuSlot4.o MenuSlot5.o MenuSlot6.o MenuSlot7.o -o MenuFirmware.bin.new -C ../.cicd/none.cfg || exit 1 -ca65 CommandFirmware.asm -D SLOT=0 -o CommandSlot0.o || exit 1 -ca65 CommandFirmware.asm -D SLOT=1 -o CommandSlot1.o || exit 1 -ca65 CommandFirmware.asm -D SLOT=2 -o CommandSlot2.o || exit 1 -ca65 CommandFirmware.asm -D SLOT=3 -o CommandSlot3.o || exit 1 -ca65 CommandFirmware.asm -D SLOT=4 -o CommandSlot4.o || exit 1 -ca65 CommandFirmware.asm -D SLOT=5 -o CommandSlot5.o || exit 1 -ca65 CommandFirmware.asm -D SLOT=6 -o CommandSlot6.o || exit 1 -ca65 CommandFirmware.asm -D SLOT=7 -o CommandSlot7.o --listing CommandFirmware.lst.new --list-bytes 255 || exit 1 +ca65 CommandFirmware.asm -D HW_TYPE=$HW_TYPE -D SLOT=0 -o CommandSlot0.o || exit 1 +ca65 CommandFirmware.asm -D HW_TYPE=$HW_TYPE -D SLOT=1 -o CommandSlot1.o || exit 1 +ca65 CommandFirmware.asm -D HW_TYPE=$HW_TYPE -D SLOT=2 -o CommandSlot2.o || exit 1 +ca65 CommandFirmware.asm -D HW_TYPE=$HW_TYPE -D SLOT=3 -o CommandSlot3.o || exit 1 +ca65 CommandFirmware.asm -D HW_TYPE=$HW_TYPE -D SLOT=4 -o CommandSlot4.o || exit 1 +ca65 CommandFirmware.asm -D HW_TYPE=$HW_TYPE -D SLOT=5 -o CommandSlot5.o || exit 1 +ca65 CommandFirmware.asm -D HW_TYPE=$HW_TYPE -D SLOT=6 -o CommandSlot6.o || exit 1 +ca65 CommandFirmware.asm -D HW_TYPE=$HW_TYPE -D SLOT=7 -o CommandSlot7.o --listing CommandFirmware.lst.new --list-bytes 255 || exit 1 ld65 CommandSlot0.o CommandSlot1.o CommandSlot2.o CommandSlot3.o CommandSlot4.o CommandSlot5.o CommandSlot6.o CommandSlot7.o -o CommandFirmware.bin.new -C ../.cicd/none.cfg || exit 1 -ca65 FileAccessFirmware.asm -D SLOT=0 -o FileAccessSlot0.o || exit 1 -ca65 FileAccessFirmware.asm -D SLOT=1 -o FileAccessSlot1.o || exit 1 -ca65 FileAccessFirmware.asm -D SLOT=2 -o FileAccessSlot2.o || exit 1 -ca65 FileAccessFirmware.asm -D SLOT=3 -o FileAccessSlot3.o || exit 1 -ca65 FileAccessFirmware.asm -D SLOT=4 -o FileAccessSlot4.o || exit 1 -ca65 FileAccessFirmware.asm -D SLOT=5 -o FileAccessSlot5.o || exit 1 -ca65 FileAccessFirmware.asm -D SLOT=6 -o FileAccessSlot6.o || exit 1 -ca65 FileAccessFirmware.asm -D SLOT=7 -o FileAccessSlot7.o --listing FileAccessFirmware.lst.new --list-bytes 255 || exit 1 +ca65 FileAccessFirmware.asm -D HW_TYPE=$HW_TYPE -D SLOT=0 -o FileAccessSlot0.o || exit 1 +ca65 FileAccessFirmware.asm -D HW_TYPE=$HW_TYPE -D SLOT=1 -o FileAccessSlot1.o || exit 1 +ca65 FileAccessFirmware.asm -D HW_TYPE=$HW_TYPE -D SLOT=2 -o FileAccessSlot2.o || exit 1 +ca65 FileAccessFirmware.asm -D HW_TYPE=$HW_TYPE -D SLOT=3 -o FileAccessSlot3.o || exit 1 +ca65 FileAccessFirmware.asm -D HW_TYPE=$HW_TYPE -D SLOT=4 -o FileAccessSlot4.o || exit 1 +ca65 FileAccessFirmware.asm -D HW_TYPE=$HW_TYPE -D SLOT=5 -o FileAccessSlot5.o || exit 1 +ca65 FileAccessFirmware.asm -D HW_TYPE=$HW_TYPE -D SLOT=6 -o FileAccessSlot6.o || exit 1 +ca65 FileAccessFirmware.asm -D HW_TYPE=$HW_TYPE -D SLOT=7 -o FileAccessSlot7.o --listing FileAccessFirmware.lst.new --list-bytes 255 || exit 1 ld65 FileAccessSlot0.o FileAccessSlot1.o FileAccessSlot2.o FileAccessSlot3.o FileAccessSlot4.o FileAccessSlot5.o FileAccessSlot6.o FileAccessSlot7.o -o FileAccessFirmware.bin.new -C ../.cicd/none.cfg || exit 1 cat \ DriveFirmware.bin.new CommandFirmware.bin.new FileAccessFirmware.bin.new MenuFirmware.bin.new \ > AT28C64B.bin.new -ca65 Shell.asm -o Shell.o --listing Shell.lst.new || exit 1 +ca65 Shell.asm -D HW_TYPE=$HW_TYPE -o Shell.o --listing Shell.lst.new || exit 1 ld65 Shell.o -o Shell.bin.new -C ../.cicd/none.cfg || exit 1 -ca65 RPi.Command.asm -o RPi.Command.o --listing RPi.Command.lst.new || exit 1 +ca65 RPi.Command.asm -D HW_TYPE=$HW_TYPE -o RPi.Command.o --listing RPi.Command.lst.new || exit 1 ld65 RPi.Command.o -o RPi.Command.bin.new -C ../.cicd/none.cfg || exit 1 rm ./*.o diff --git a/README.md b/README.md index c441e14..c4b3bbb 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Apple II expansion card using a Raspberry Pi for I/O ![Image of Board](/Hardware/Apple2IORPi.jpg) ## Purpose -The purpose of this project is to provide I/O for an Apple II series 8 bit computer via a Raspberry Pi Zero W which is powered by the Apple II expansion bus. This includes using the attached RPi Zero W for it's storage, network and processor to provide new functionality for the Apple II. +The purpose of this project is to provide I/O for an Apple II series 8 bit computer via a Raspberry Pi Zero 2 W which is powered by the Apple II expansion bus. This includes using the attached RPi Zero 2 W for it's storage, network and processor to provide new functionality for the Apple II. ## Features 1. Boot message which waits for RPi to be ready @@ -16,22 +16,30 @@ The purpose of this project is to provide I/O for an Apple II series 8 bit compu 7. Supports "RPI" command from BASIC to execute Linux commands from the command prompt or inside BASIC programs: `10 PRINT CHR$(4);"RPI ls -al /"` ## Project Status + +### Classic Hardware So far, this is still a project and not a finished product. The current prototype is on the sixth revision. I have sold about 60 boards including previous prototypes. There are more than 100 in the wild between self made and ones purchased in places like eBay that were made by others. The sixth prototype is functionally equivalent to the fifth, other than a new jumper to select internal/external power. The card enables the Apple II to boot from and write to virtual hard drive images stored on the RPi in any slot (except slot 3), execute Linux commands from Applesoft BASIC and run a bash shell with VT100 emulation. The code has very few tests and is incomplete. Note that currently the firmware assumes an 80 column card is in slot 3 and than you have lowercase support. Most development has been done with an enhanced Apple //e with the card in slot 7. If you have other drive controllers earlier in the boot cycle, you can still boot from the Apple2-IO-RPi. For example, if the card was in slot 4, you could type `PR#4` from the BASIC prompt to boot the card. Note that the Raspberry Pi Zero W (and W 2) consume 170 - 250 mA and there is only 500 mA available to all expansion slots according to Apple. It is not recommended to have a lot of other cards in the system at the same time. With the sixth revision of the prototype, it is possible to remove the power jumper and run the RPi on an external USB power source. If configured for external power, note that the card's firmware will hang on boot without USB power on as the latch chips are powered by the 3.3V output of the RPi. If you have a problem or idea for enhancement, log an issue [here](https://github.com/tjboldt/Apple2-IO-RPi/issues) or start a [discussion](https://github.com/tjboldt/Apple2-IO-RPi/discussions/categories/general). I recommend starring/watching the project for updates on GitHub. You are welcome to fork the project and submit pull requests which I will review. The latest version has an in-memory virtual drive representing current working directory in Linux for ease of copying files between Linux and ProDOS when the drive 1 is not specified as a file. +### Pico Hardware +Ralle Palaveev has a version of the hardware that uses a RPi Pico to handle firmware and communications to the host over USB. This uses Oliver Schmidt's PIO code. + ## Roadmap See [List of issues tagged roadmap](https://github.com/tjboldt/Apple2-IO-RPi/issues?q=is%3Aissue+is%3Aopen+label%3Aroadmap+author%3Atjboldt) -## Setup +## Setup on classic hardware [Setup card from scratch](https://github.com/tjboldt/Apple2-IO-RPi/discussions/63) [Setup if you received a complete board from me](https://github.com/tjboldt/Apple2-IO-RPi/discussions/64) [Update to latest](https://github.com/tjboldt/Apple2-IO-RPi/discussions/65) +## Setup on Pico based hardware +[Setup card with Pico hardware](https://github.com/tjboldt/Apple2-IO-RPi/discussions/162) + ## Contributions/Thanks - Hans Hübner ([@hanshuebner](https://github.com/hanshuebner)) for help cleaning up schematics - Scott ([@figital](https://github.com/figital)) for assembling early prototypes and recommending the AT28C64B chip @@ -41,6 +49,8 @@ See [List of issues tagged roadmap](https://github.com/tjboldt/Apple2-IO-RPi/iss - ([@Abysmal](https://github.com/Abysmal)) for shell and rpi.command testing - ([@bfranske](https://github.com/bfranske)) for suggesting adding the 5V jumper - Tim Boldt ([@timboldt](https://github.com/timboldt)) for recommending removing sysfs based GPIO code +- Oliver Schmidt ([@oliverschmidt](https://github.com/oliverschmidt/apple2-io-rpi/)) for writing the Pico PIO and firmware +- Ralle Palaveev ([@rallepalaveev](https://github.com/rallepalaveev/a2pico)) for Pico hardware design ## Similar Project If you prefer having Apple II peripherals control a Raspberry Pi rather than simply using the Raspberry Pi to provide storage, network access and processing to the Apple II, have a look at David Schmenk's excellent [Apple2Pi](https://github.com/dschmenk/apple2pi) project. I am often asked about differences between these two projects. They are similar in some ways but essentially opposite. The Apple2Pi is meant for the primary machine to be the RPi, using the Apple II for it's peripherals. The Apple2-IO-RPi is meant to have the Apple II as the primary machine and just use the RPi for its processing, storage and network. diff --git a/RaspberryPi/apple2driver/a2io/cdcio.go b/RaspberryPi/apple2driver/a2io/cdcio.go new file mode 100644 index 0000000..bd0b86d --- /dev/null +++ b/RaspberryPi/apple2driver/a2io/cdcio.go @@ -0,0 +1,151 @@ +// Copyright Terence J. Boldt (c)2020-2022 +// Use of this source code is governed by an MIT +// license that can be found in the LICENSE file. + +// This file is used for communicating with the Apple II data bus via the +// GPIO ports on the Raspberry Pi + +package a2io + +import ( + "bytes" + "errors" + "fmt" + "strings" + "time" + + "go.bug.st/serial" + "go.bug.st/serial/enumerator" +) + +var port serial.Port + +// CDCio is a live implementation of A2Io interface +type CDCio struct { +} + +// Init initializes the CDC driver on the Raspberry Pi +func (a2 CDCio) Init() { + name := "" + for { + portInfos, err := enumerator.GetDetailedPortsList() + if err == nil { + for _, portInfo := range portInfos { + if portInfo.IsUSB && + strings.ToUpper(portInfo.VID) == "2E8A" && + strings.ToUpper(portInfo.PID) == "000A" { + name = portInfo.Name + fmt.Printf("Found CDC port %s\n", name) + break + } + } + if name != "" { + break + } + } + time.Sleep(time.Millisecond) + } + + for { + var err error + port, err = serial.Open(name, &serial.Mode{}) + if err == nil { + break + } + var portErr *serial.PortError + if !errors.As(err, &portErr) || + portErr.Code() != serial.PortNotFound && + portErr.Code() != serial.PermissionDenied { + panic(err) + } + time.Sleep(time.Millisecond) + } + + err := port.SetReadTimeout(time.Second) + if err != nil { + panic(err) + } +} + +// ReadByte reads a byte from the Apple II via Raspberry Pi's CDC driver +func (a2 CDCio) ReadByte(noDelay ...bool) (byte, error) { + var data [1]byte + n, err := port.Read(data[:]) + if err != nil { + return 0, err + } + if n == 0 { + return 0, errors.New("timed out reading byte") + } + return data[0], nil +} + +// WriteByte writes a byte to the Apple II via Raspberry Pi's CDC driver +func (a2 CDCio) WriteByte(data byte) error { + _, err := port.Write([]byte{data}) + return err +} + +// ReadString reads a string from the Apple II via Raspberry Pi's CDC driver +func (a2 CDCio) ReadString() (string, error) { + var inBytes bytes.Buffer + for { + inByte, err := a2.ReadByte() + if err != nil { + return "", err + } + if inByte == 0 { + break + } + inBytes.WriteByte(inByte) + } + return inBytes.String(), nil +} + +// WriteString writes a string to the Apple II via Raspberry Pi's CDC driver +func (a2 CDCio) WriteString(outString string) error { + for _, character := range outString { + err := a2.WriteByte(byte(character) | 128) + if err != nil { + fmt.Printf("Failed to write string\n") + return err + } + } + a2.WriteByte(0) + return nil +} + +// WriteBlock writes 512 bytes to the Apple II via Raspberry Pi's CDC driver +func (a2 CDCio) WriteBlock(buffer []byte) error { + _, err := port.Write(buffer) + return err +} + +// ReadBlock reads 512 bytes from the Apple II via Raspberry Pi's CDC driver +func (a2 CDCio) ReadBlock(buffer []byte) error { + var err error + for i := 0; i < 512; i++ { + buffer[i], err = a2.ReadByte() + if err != nil { + return err + } + } + + return nil +} + +// WriteBuffer writes a buffer of bytes to the Apple II via Raspberry Pi's CDC driver +func (a2 CDCio) WriteBuffer(buffer []byte) error { + _, err := port.Write(buffer) + return err +} + +// SendCharacter is a pass-through to vt100 implementation +func (a2 CDCio) SendCharacter(character byte) { + sendCharacter(a2, character) +} + +// ReadCharacter is a pass-through to vt100 implementation +func (a2 CDCio) ReadCharacter() (string, error) { + return readCharacter(a2) +} diff --git a/RaspberryPi/apple2driver/driver.go b/RaspberryPi/apple2driver/driver.go index a610109..8111376 100644 --- a/RaspberryPi/apple2driver/driver.go +++ b/RaspberryPi/apple2driver/driver.go @@ -9,12 +9,15 @@ package main import ( + "errors" "flag" "fmt" "os" "path/filepath" "time" + "go.bug.st/serial" + "github.com/tjboldt/Apple2-IO-RPi/RaspberryPi/apple2driver/a2io" "github.com/tjboldt/Apple2-IO-RPi/RaspberryPi/apple2driver/drive" "github.com/tjboldt/Apple2-IO-RPi/RaspberryPi/apple2driver/handlers" @@ -34,7 +37,7 @@ const menuCommand = 8 const shellCommand = 9 func main() { - drive1Name, drive2Name := getFlags() + drive1Name, drive2Name, cdc := getFlags() drive1, drive2 := getDriveFiles(drive1Name, drive2Name) driveImageDir, err := drive.GetDriveImageDirectory() @@ -44,7 +47,12 @@ func main() { fmt.Printf("Starting Apple II RPi v%s...\n", info.Version) - comm := a2io.A2Gpio{} + var comm a2io.A2Io + if cdc { + comm = a2io.CDCio{} + } else { + comm = a2io.A2Gpio{} + } handlers.SetCommunication(comm) comm.Init() @@ -73,6 +81,13 @@ func main() { case shellCommand: handlers.ShellCommand() } + // the A2Io interface should be extended in one way or another + // to encapsulate this, e.g. by a ReadByte variant / parameter + } else if cdc { + var portErr *serial.PortError + if errors.As(err, &portErr) && portErr.Code() == serial.PortClosed { + comm.Init() + } // temporary workaround for busy wait loop heating up the RPi } else { time.Sleep(time.Millisecond * 200) @@ -80,9 +95,10 @@ func main() { } } -func getFlags() (string, string) { +func getFlags() (string, string, bool) { var drive1Name string var drive2Name string + var cdc bool execName, _ := os.Executable() path := filepath.Dir(execName) @@ -91,9 +107,10 @@ func getFlags() (string, string) { flag.StringVar(&drive1Name, "d1", "", "A ProDOS format drive image for drive 1") flag.StringVar(&drive2Name, "d2", "", "A ProDOS format drive image for drive 2 and will be used for drive 1 if drive 1 empty") + flag.BoolVar(&cdc, "cdc", false, "Use ACM CDC serial device") flag.Parse() - return drive1Name, drive2Name + return drive1Name, drive2Name, cdc } func getDriveFiles(drive1Name string, drive2Name string) (prodos.ReaderWriterAt, prodos.ReaderWriterAt) { diff --git a/RaspberryPi/apple2driver/go.mod b/RaspberryPi/apple2driver/go.mod index 1767e1c..8231dc8 100644 --- a/RaspberryPi/apple2driver/go.mod +++ b/RaspberryPi/apple2driver/go.mod @@ -5,6 +5,7 @@ go 1.16 require ( github.com/creack/pty v1.1.21 github.com/stianeikeland/go-rpio/v4 v4.6.0 - github.com/tjboldt/ProDOS-Utilities v0.4.8 - golang.org/x/image v0.14.0 // indirect + github.com/tjboldt/ProDOS-Utilities v0.4.9 + go.bug.st/serial v1.6.1 + golang.org/x/sys v0.16.0 // indirect ) diff --git a/RaspberryPi/apple2driver/go.sum b/RaspberryPi/apple2driver/go.sum index aa982fe..57ebd52 100644 --- a/RaspberryPi/apple2driver/go.sum +++ b/RaspberryPi/apple2driver/go.sum @@ -1,15 +1,25 @@ +github.com/creack/goselect v0.1.2 h1:2DNy14+JPjRBgPzAd1thbQp4BSIihxcBf0IXhQXDRa0= +github.com/creack/goselect v0.1.2/go.mod h1:a/NhLweNvqIYMuxcMOuWY516Cimucms3DglDzQP3hKY= github.com/creack/pty v1.1.21 h1:1/QdRyBaHHJP61QkWMXlOIBfsgdDeeKfK8SYVUWJKf0= github.com/creack/pty v1.1.21/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4= +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 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.4.8 h1:hW4gHliqTjKCep6jXX4Z59pkVhB+OyVJPWM5X3N+ybs= -github.com/tjboldt/ProDOS-Utilities v0.4.8/go.mod h1:tk5Cd5WSoogNF+XRMjEPuWeU1vVuqdJexn23s5ev/fU= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/tjboldt/ProDOS-Utilities v0.4.9 h1:TkrXrm6EMcB9GDHoBtfpr0/h5G6xUQf4NVX6d1YLYvg= +github.com/tjboldt/ProDOS-Utilities v0.4.9/go.mod h1:TS0/NXtEofuAaDOhRzlrHrbGAzrJXlk9IltkLswShsc= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +go.bug.st/serial v1.6.1 h1:VSSWmUxlj1T/YlRo2J104Zv3wJFrjHIl/T3NeruWAHY= +go.bug.st/serial v1.6.1/go.mod h1:UABfsluHAiaNI+La2iESysd9Vetq7VRdpxvjx7CmmOE= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/image v0.13.0/go.mod h1:6mmbMOeV28HuMTgA6OSRkdXKYw/t5W9Uwn2Yv1r3Yxk= -golang.org/x/image v0.14.0 h1:tNgSxAFe3jC4uYqvZdTr84SZoM1KfwdC9SKIFrLjFn4= -golang.org/x/image v0.14.0/go.mod h1:HUYqC05R2ZcZ3ejNQsIHQDQiwWM4JBqmm6MKANTp4LE= +golang.org/x/image v0.15.0 h1:kOELfmgrmJlw4Cdb7g/QGuB3CvDrXbqEIww/pNtNBm8= +golang.org/x/image v0.15.0/go.mod h1:HUYqC05R2ZcZ3ejNQsIHQDQiwWM4JBqmm6MKANTp4LE= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= @@ -24,7 +34,10 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220829200755-d48e67d00261/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= +golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= @@ -32,10 +45,12 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/RaspberryPi/apple2driver/handlers/shell.go b/RaspberryPi/apple2driver/handlers/shell.go index 89a74f9..7139c9c 100755 --- a/RaspberryPi/apple2driver/handlers/shell.go +++ b/RaspberryPi/apple2driver/handlers/shell.go @@ -49,12 +49,13 @@ func ShellCommand() { ptmx.Close() cmd.Wait() comm.WriteByte(0) - return +// return + break case <-userCancelled: fmt.Printf("User cancelled, killing process\n") ptmx.Close() cmd.Process.Kill() - comm.WriteByte(0) +// comm.WriteByte(0) return case <-inputComplete: fmt.Printf("Shell input complete\n") diff --git a/RaspberryPi/apple2driver/info/version.go b/RaspberryPi/apple2driver/info/version.go index 3bcded3..6b8aa97 100644 --- a/RaspberryPi/apple2driver/info/version.go +++ b/RaspberryPi/apple2driver/info/version.go @@ -8,4 +8,4 @@ package info // Version is the hexadecimal version number that // should be incremented with each driver update -const Version = "002C" +const Version = "002D" diff --git a/RaspberryPi/driveimage/AT28C64B.bin b/RaspberryPi/driveimage/AT28C64B.bin index fbedce203b63ca49de00c4800c9a2c20d39c5d84..318e6668b24b29beb38643fdaf9e0fdbe9012920 100644 GIT binary patch literal 8192 zcmciHZD?dy9mnz6thOs`+aLuK(9C(EU~wMeRJ01o=ysD-jkwf8@!gb~wo8^al>5#X z`od|&PKFhcAd6)Q#&}s~(N~vYvEJvqVX@7-1QyqQ)x6lYj)~`Vy$@Ri(UwQ3GyT1CmyZCw6egxN=YoBPIu?x-l=0fwV zeX2RfYVP8RQ-6GN<4o`L)`{Nu)>!YEC+r_J*6&}wZx<#S8w=YL8}nOZ+n>E$uun4A zWxMY0F8=Mh`>E~!+9zndF^``G`uP?8ce%jcaNnJypLh<-Y4)$rUf=$(VUJQBfYlAo@% zFz*i!fdB9CCvNG6@F(2Q$K-#T z`}t_3|6J2BNYJwSKYsp18?vSoMU@u%!RG#_U#-s=>`wpM$0*$>=_i@nmgE7$PH zrylzmU-xgZuH*js!L34XlD&VgRB*@t)hW1i%jeL_iHo-y&(&U9y0B7EQJ+##FVbCO z{R{2a5&7}cSbx{X!zUUP`1NA?qCYXvcP;hC+XoH(pA`L1{Z#30+k>BS%l#f(_6&Y6 z^J7isr*+)#v5q&&?+y87)TdO`i*yJ78X}+h*WiB>e(~b4ey#tLqW`I%D&1}S@KbKN z-)GCd!S82&tjYYej{AMq@kjanA-|0Jl!|(h?%>}<DA@5Pr%n_lImbH2A~Jk2RT})^UHxI^igPIOLa6pHfjT(jEK>BA@va_}_+K zyg001>;I(af9j`7ciR#Clw0nP*m7j>N0}dMGC!^3{)ly=QT}MiFQY!CqF$ss_;(Qb z%)bNwE%?QY!}_)UPm2DheyVi09m7w#<^Gs0#|D3#`LQPR(>m^tStlOlkB9s+>QgG} zMY@B350TIOd+>h%zj$$2zt;ar(f`y>mF~6^_$jyCpRnb`;7>9?)?|KK$NdTGB%}Pv zkY7f9N=3a$cku5c@|k}h{*U1oFAnR^_do4Bo&V3;tT|^tz%1+ql*^+109=;KT5fY5 zKMNZRy>Z&rw8T07-MM&S`@N0%-f8(PoZr67etci$y+Zw_0iD^abk|rfi;B~pg_2&C zNpBd_{eOA*3H>+t2fA*hUAH{e^5FL}zc|Ma`teNqW!@_)?^T}nvZy%uDd|<2^yBd7 z`)}|Mblpn3ZuzX`!|!K)agHDK9~QGU>P{JMRw`3-xl`6cG{FBg9C#qJficj_}gr!)KY?f+1>rysKKvp;=gU!^CD-*oMN z($y}opSt!hafiq3H*W9b;`d#96;Iy5&kg)MviLB{PoFO6)BP;PUu*;L4-k#@8GRd2 zSKEN^tgKvEs+GU{!}8PT&aZy?`NwM0wdpebe2qP`^y<>f&o8m>RoIzVF8st=U48bs z^Va#7Ut}-5@+zb0Z2sAAO;3Myx>BhWv_GHJf0N(S{FjFOp7MLT--F*X_&qwvlb=4_ z&#G-eoo@qX^ld<0Z3B+dZ|J|t?`!@mLw;ZReckWF?;HF+9puSRpYCVXHlWV80WNz>K~PsH<(jQTh%2H~AyYe{;wmDSxE< zBlshOKca&?`RUXBtl9?D`8Hri-v-pxHsC1zhW?xUvF5)s3&vi1L}MmFeAz@wgGi9pl!fW`VIXz`4i3GAMz*4pXmMs{>0!<=pavi`gA|5wgGj% Q4Vcll0d=(vI1>N=0N3Y6Gynhq literal 8192 zcmcK9Uua}k9S88cyV|a>ZG#AAK$G(#*xH$dsn{YU(d{M~OT?mu(zhvX>@Hc_rQ9c9 z^ku48GQ+BgCBh{v>bd_nENb5Juyov~=Ao{RNE_RAU4P$mesk}+xpxW! zPGIl7=eNJJ>?aBN{?5&9aof6m>MiSyFTL@!v#|a{x$-&bJc4^&Iwx9Z9jmp}T5g?l zPPZ0CU9Oxs{p+W<&i2pjo#;>Oo$NpNl=GeDTlcTrcdW_g*7E-3*3#a|{ZC)9oKr$d z(UU*l_~Q-viT(GT6SUr1!eyB*Kc+udEb*p%cabjfBDPcaPtM)g|98_liMHdtE_z+= z{p~qwL2sk`rhM$NYagCpUzg6q^#4}tjSrQf={&@hYaeynvZ0D-*!bvt)1r^he&)9J zPq2TJ{2sN@z3vtL-bj8=^gPq=!Q{d3k>7*ggWntYz06%v;7?>1YvoUrUsuTgXXV$+ zg8y0eACNyHKi%t5(I1WEk3=sr{So{T{1N#h_#^nEfj`Rp#a|(9_2g6e~JA^RBWaDLT#LcDUXYn|L%?|&e^DJM7jk59@AciTSv6t~Ln zi#5N*?`MAO$^5iW`F*kD5A*xS{a4vfp+04V`ZPVmzpY|E^KZkCfJXx+fKmNM{#SJV zv!7CWw;jMwajX1+SPM%0LFUJv%uoB2KM*^?Fn@5|f1Ujl>QhFjPt!B}u8R50@4}CO zM*}8+QT;~#S9JcfpHh0a9l}p>tNfu@3rqZA=Et7QPy3WV6g%NCe|X$~ll>IxQ%0yy z(=+^uiuuf+z>k1O115k`{YL&*bpEqHf$6_ZQ=8up2-(x?8`jips)AS7gp^Ev;e+WMU9u1fPM)e!{U(xx`eoE=xb^?FG z{zR-LCH^GyV^8L%eafGRon)9lIqtv9ehT#|Bh;tq8U7;`^O^q$egr%kFaeC}FXlhz zJDvZ}Iij`bJRoe$0;$WUc>pe3ijHh8;j+B7+@GMSrlZgC?=Hs6`+wV7>Yo|Z!lnHW z#0&Rx@m}M^#>_H9&rPSw6`EPvL_*O#vky=6(f{US^1sBN%XOP`-S$MsgWt>i`W&D4 zqn7$F^Ou+6y=KJwjEeUvSICb@N0B4FIlA!UcclJe{+IZ3xo&f=+rH@d@cWrxpX2j> z)KdRd_EWsqjCh|>@m}Q$`4QRq9Yv1x@%fASU*gZ@y3M(6hoTe0A7*}ij?ep1OZ}A4>YW|Md(DXV z85QqUu8<#*jv`0;`25BEFY!mYpMRX|b|g9x{88rD=lHxIwbXx${S@ytBi?6JyjQtG zendKo9O>ip7xTZwpUZWdbKQvkeK3H(Xs*XQ`WAGOp^39Y{WDc);Fyw9k3uX2U_h;$S=(#Pj7$^U-q zE6%;vlg>oz3&Oig-}=9k{nMZN0iD=y?EedaeC;9UzWB|5oVTg8@}zYBN_WQ+-;>Ud z@PxAXne3lhc}69c_1U<&y9rArrA z>(y_3tNQI{FRXv@rAO(9SYiQj9eH}&|< z1x*3-#uTuirhvKp6oBGj3K)aGB>#(k-|$m{=ly=__f5YKzhC0_8|qCx{4@p38&kl7 zngZtXQviyCDPRo#lKe0F1H(@Vp7#f-KQR3P{6UF7Xs9>!@Y579Z%hFTY6_UkPXQW@u-41ZkWj~nVuJ^Xjz*CDTe{^O88m!AR_j45CY{*wGJ`V+%X37+>SsXsCO3H(Wk eKWV5p_3+aaFmFr&3u+3O%TEC)4yJ(rr~iL?tON4^ diff --git a/RaspberryPi/driveimage/Shell.bin b/RaspberryPi/driveimage/Shell.bin index b9ff2ec115853d24b7a814cc84cd61b88b850348..de2e0bccd05967bf8b2a8cd16ecb0eb81b09492d 100644 GIT binary patch delta 165 zcmdnQyoGs!rAD#h2M*2#g|~lCT==|{%|l1vz)DVq;|dDl3K^|z2?|dYPBMH@^H7MJ zm?r10tLPK1kf0FpM*++NO17%>RK>C>KQn=*A)0({6It&K{ ozV7Wlpry6p=fq#KjISn3Fq*SPC~C_4L`)84v}SahJdsfm06sK1!~g&Q delta 163 zcmdnOyoq^&rEa0(2M*2#g|~lCT==|{%|l1vz)A*%GYTs?frLVgLPjfFg2F3>lMEl! zJQQLkCd#>MEBeGJBq&7uQ2?`mlC3Je)vO4fs=~qF2%Zv9HAsyzkUplm6fQaOm?oQw k4#NR~uM_{sGQOWI#c0kJrl=|J6E-=V(VEe9@?=Iu0J3X0p#T5? diff --git a/RaspberryPi/setup.sh b/RaspberryPi/setup.sh index b05ef7e..83247ae 100644 --- a/RaspberryPi/setup.sh +++ b/RaspberryPi/setup.sh @@ -21,16 +21,18 @@ if [ ! -d "ProDOS-Utilities" ]; then git clone https://github.com/tjboldt/ProDOS-Utilities.git fi cd ProDOS-Utilities || exit +go mod tidy go build cd ~ || exit if [ -L "/usr/bin/ProDOS-Utilities" ]; then sudo rm /usr/bin/ProDOS-Utilities fi -sudo ln -s /home/pi/ProDOS-Utilities/ProDOS-Utilities /usr/bin/ProDOS-Utilities +sudo ln -s $HOME/ProDOS-Utilities/ProDOS-Utilities /usr/bin/ProDOS-Utilities if [ ! -d "Apple2-IO-RPi" ]; then git clone https://github.com/tjboldt/Apple2-IO-RPi.git fi cd Apple2-IO-RPi/RaspberryPi/apple2driver || exit +go mod tidy go build sudo apt install cc65 vim -y cd ~ || exit @@ -41,18 +43,18 @@ dtoverlay=disable-bt boot_delay=0 EOF' sudo bash -c 'echo " quiet" >> /boot/cmdline.txt' -bash -c 'cat > apple2driver.service << EOF +sudo --preserve-env=HOME --preserve-env=USER bash -c 'cat > apple2driver.service << EOF [Unit] Description=Apple2-IO-RPi Driver [Service] -ExecStart=/home/$USER/Apple2-IO-RPi/RaspberryPi/apple2driver/apple2driver +ExecStart=$HOME/Apple2-IO-RPi/RaspberryPi/apple2driver/apple2driver StandardOutput=syslog StandardError=syslog SyslogIdentifier=apple2driver User=$USER Group=$USER -WorkingDirectory=/home/$USER/Apple2-IO-RPi/RaspberryPi/apple2driver +WorkingDirectory=$HOME/Apple2-IO-RPi/RaspberryPi/apple2driver [Install] WantedBy=basic.target diff --git a/RaspberryPiPico/CMakeLists.txt b/RaspberryPiPico/CMakeLists.txt new file mode 100644 index 0000000..6ab7780 --- /dev/null +++ b/RaspberryPiPico/CMakeLists.txt @@ -0,0 +1,39 @@ +set(PROJECT_NAME Apple2-IO-RPi) + +cmake_minimum_required(VERSION 3.12) +include(pico_sdk_import.cmake) +project(${PROJECT_NAME} C CXX ASM) +pico_sdk_init() + +add_executable(${PROJECT_NAME}) +pico_add_extra_outputs(${PROJECT_NAME}) + +pico_enable_stdio_uart(${PROJECT_NAME} 0) +pico_enable_stdio_usb(${PROJECT_NAME} 1) + +include(FetchContent) +FetchContent_Declare(a2pico + GIT_REPOSITORY https://github.com/oliverschmidt/a2pico.git + GIT_TAG main + ) +FetchContent_MakeAvailable(a2pico) + +set_source_files_properties(incbin.S OBJECT_DEPENDS ../../Apple2/AT28C64B.bin) +add_custom_command( + WORKING_DIRECTORY ../../Apple2 + COMMAND ./assemble.sh 1 + OUTPUT ../../Apple2/AT28C64B.bin + VERBATIM + ) + +target_sources(${PROJECT_NAME} PRIVATE + main.c + board.c + incbin.S + ) + +target_link_libraries(${PROJECT_NAME} PRIVATE + pico_stdlib + pico_multicore + a2pico + ) diff --git a/RaspberryPiPico/LICENSE b/RaspberryPiPico/LICENSE new file mode 100644 index 0000000..8617998 --- /dev/null +++ b/RaspberryPiPico/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Oliver Schmidt (https://a2retro.de/) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/RaspberryPiPico/board.c b/RaspberryPiPico/board.c new file mode 100644 index 0000000..d6e440f --- /dev/null +++ b/RaspberryPiPico/board.c @@ -0,0 +1,78 @@ +/* + +MIT License + +Copyright (c) 2022 Oliver Schmidt (https://a2retro.de/) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +*/ + +#include + +#include + +#include "board.h" + +extern const __attribute__((aligned(4))) uint8_t firmware[]; + +static uint32_t page; + +void __time_critical_func(board)(void) { + + a2pico_init(pio0); + + while (true) { + uint32_t pico = a2pico_getaddr(pio0); + uint32_t addr = pico & 0x0FFF; + uint32_t io = pico & 0x0F00; // IOSTRB or IOSEL + uint32_t strb = pico & 0x0800; // IOSTRB + uint32_t read = pico & 0x1000; // R/W + + if (read) { + if (!io) { // DEVSEL + switch (addr & 0x7) { + case 0x3: + a2pico_putdata(pio0, !multicore_fifo_rvalid() << 7 | + !multicore_fifo_wready() << 6); + break; + case 0x6: + a2pico_putdata(pio0, sio_hw->fifo_rd); + break; + } + } else { + if (!strb) { + a2pico_putdata(pio0, firmware[page | addr]); + } + } + } else { + uint32_t data = a2pico_getdata(pio0); + if (!io) { // DEVSEL + switch (addr & 0x7) { + case 0x5: + sio_hw->fifo_wr = data; + break; + case 0x7: + page = (data & 0x30) << 7; + break; + } + } + } + } +} diff --git a/RaspberryPiPico/board.h b/RaspberryPiPico/board.h new file mode 100644 index 0000000..b1ac9c5 --- /dev/null +++ b/RaspberryPiPico/board.h @@ -0,0 +1,32 @@ +/* + +MIT License + +Copyright (c) 2022 Oliver Schmidt (https://a2retro.de/) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +*/ + +#ifndef _BOARD_H +#define _BOARD_H + +void board(void); + +#endif diff --git a/RaspberryPiPico/incbin.S b/RaspberryPiPico/incbin.S new file mode 100644 index 0000000..c43f6fb --- /dev/null +++ b/RaspberryPiPico/incbin.S @@ -0,0 +1,6 @@ +.section .time_critical.firmware +.global firmware +.type firmware, %object +.balign 4 +firmware: +.incbin "../../Apple2/AT28C64B.bin" diff --git a/RaspberryPiPico/main.c b/RaspberryPiPico/main.c new file mode 100644 index 0000000..c07f177 --- /dev/null +++ b/RaspberryPiPico/main.c @@ -0,0 +1,92 @@ +/* + +MIT License + +Copyright (c) 2022 Oliver Schmidt (https://a2retro.de/) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +*/ + +#include +#include +#include +#include + +#include "board.h" + +#ifdef TRACE +void uart_printf(uart_inst_t *uart, const char *format, ...) { + static char buffer[0x100]; + + va_list va; + va_start(va, format); + vsnprintf(buffer, sizeof(buffer), format, va); + va_end(va); + + buffer[0xFF] = '\0'; + uart_puts(uart, buffer); +} +#endif + +void main(void) { + multicore_launch_core1(board); + + stdio_init_all(); + stdio_set_translate_crlf(&stdio_usb, false); + +#ifdef PICO_DEFAULT_LED_PIN + gpio_init(PICO_DEFAULT_LED_PIN); + gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT); +#endif + +#ifdef TRACE + uart_init(uart0, 115200); + uart_set_translate_crlf(uart0, true); + gpio_set_function(PICO_DEFAULT_UART_TX_PIN, GPIO_FUNC_UART); + gpio_set_function(PICO_DEFAULT_UART_RX_PIN, GPIO_FUNC_UART); +#endif + + while (true) { + bool conn = stdio_usb_connected(); + if (conn) { + if (multicore_fifo_rvalid()) { + uint32_t data = multicore_fifo_pop_blocking(); + putchar(data); +#ifdef TRACE + uart_printf(uart0, "> %02X\n", data); +#endif + } + } + + if (multicore_fifo_wready()) { + int data = getchar_timeout_us(0); + if (data != PICO_ERROR_TIMEOUT) { + multicore_fifo_push_blocking(data); +#ifdef TRACE + uart_printf(uart0, "< %02X\n", data); +#endif + } + } + +#ifdef PICO_DEFAULT_LED_PIN + gpio_put(PICO_DEFAULT_LED_PIN, conn); +#endif + } +} diff --git a/RaspberryPiPico/pico_sdk_import.cmake b/RaspberryPiPico/pico_sdk_import.cmake new file mode 100644 index 0000000..65f8a6f --- /dev/null +++ b/RaspberryPiPico/pico_sdk_import.cmake @@ -0,0 +1,73 @@ +# This is a copy of /external/pico_sdk_import.cmake + +# This can be dropped into an external project to help locate this SDK +# It should be include()ed prior to project() + +if (DEFINED ENV{PICO_SDK_PATH} AND (NOT PICO_SDK_PATH)) + set(PICO_SDK_PATH $ENV{PICO_SDK_PATH}) + message("Using PICO_SDK_PATH from environment ('${PICO_SDK_PATH}')") +endif () + +if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT} AND (NOT PICO_SDK_FETCH_FROM_GIT)) + set(PICO_SDK_FETCH_FROM_GIT $ENV{PICO_SDK_FETCH_FROM_GIT}) + message("Using PICO_SDK_FETCH_FROM_GIT from environment ('${PICO_SDK_FETCH_FROM_GIT}')") +endif () + +if (DEFINED ENV{PICO_SDK_FETCH_FROM_GIT_PATH} AND (NOT PICO_SDK_FETCH_FROM_GIT_PATH)) + set(PICO_SDK_FETCH_FROM_GIT_PATH $ENV{PICO_SDK_FETCH_FROM_GIT_PATH}) + message("Using PICO_SDK_FETCH_FROM_GIT_PATH from environment ('${PICO_SDK_FETCH_FROM_GIT_PATH}')") +endif () + +set(PICO_SDK_PATH "${PICO_SDK_PATH}" CACHE PATH "Path to the Raspberry Pi Pico SDK") +set(PICO_SDK_FETCH_FROM_GIT "${PICO_SDK_FETCH_FROM_GIT}" CACHE BOOL "Set to ON to fetch copy of SDK from git if not otherwise locatable") +set(PICO_SDK_FETCH_FROM_GIT_PATH "${PICO_SDK_FETCH_FROM_GIT_PATH}" CACHE FILEPATH "location to download SDK") + +if (NOT PICO_SDK_PATH) + if (PICO_SDK_FETCH_FROM_GIT) + include(FetchContent) + set(FETCHCONTENT_BASE_DIR_SAVE ${FETCHCONTENT_BASE_DIR}) + if (PICO_SDK_FETCH_FROM_GIT_PATH) + get_filename_component(FETCHCONTENT_BASE_DIR "${PICO_SDK_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}") + endif () + # GIT_SUBMODULES_RECURSE was added in 3.17 + if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.17.0") + FetchContent_Declare( + pico_sdk + GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk + GIT_TAG master + GIT_SUBMODULES_RECURSE FALSE + ) + else () + FetchContent_Declare( + pico_sdk + GIT_REPOSITORY https://github.com/raspberrypi/pico-sdk + GIT_TAG master + ) + endif () + + if (NOT pico_sdk) + message("Downloading Raspberry Pi Pico SDK") + FetchContent_Populate(pico_sdk) + set(PICO_SDK_PATH ${pico_sdk_SOURCE_DIR}) + endif () + set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE}) + else () + message(FATAL_ERROR + "SDK location was not specified. Please set PICO_SDK_PATH or set PICO_SDK_FETCH_FROM_GIT to on to fetch from git." + ) + endif () +endif () + +get_filename_component(PICO_SDK_PATH "${PICO_SDK_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}") +if (NOT EXISTS ${PICO_SDK_PATH}) + message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' not found") +endif () + +set(PICO_SDK_INIT_CMAKE_FILE ${PICO_SDK_PATH}/pico_sdk_init.cmake) +if (NOT EXISTS ${PICO_SDK_INIT_CMAKE_FILE}) + message(FATAL_ERROR "Directory '${PICO_SDK_PATH}' does not appear to contain the Raspberry Pi Pico SDK") +endif () + +set(PICO_SDK_PATH ${PICO_SDK_PATH} CACHE PATH "Path to the Raspberry Pi Pico SDK" FORCE) + +include(${PICO_SDK_INIT_CMAKE_FILE})