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 fbedce2..318e666 100644 Binary files a/RaspberryPi/driveimage/AT28C64B.bin and b/RaspberryPi/driveimage/AT28C64B.bin differ diff --git a/RaspberryPi/driveimage/Shell.bin b/RaspberryPi/driveimage/Shell.bin index b9ff2ec..de2e0bc 100644 Binary files a/RaspberryPi/driveimage/Shell.bin and b/RaspberryPi/driveimage/Shell.bin differ 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})