1
0
mirror of https://github.com/fruit-bat/pico-zxspectrum.git synced 2025-04-19 00:04:01 +03:00
2022-05-26 21:27:16 +01:00
osm
2022-01-20 18:20:11 +00:00
2022-05-26 21:27:16 +01:00
2022-05-26 21:27:16 +01:00
2021-12-08 22:15:03 +00:00
2022-05-21 21:59:18 +01:00
2022-04-23 15:03:30 +01:00

pico-zxspectrum

48k/128k ZX Spectrum for Raspberry Pico Pi RP2040

This is a basic 48k/128k ZX Spectrum emulation on the RP2040 with DVI output.

Uses Wren's Amazing PicoDVI and CarlK's Super no OS FAT FS for Pico libraries.

Features

  • DVI over HDMI output
  • USB Keyboard & Joysticks
  • PWM sound for ear, mic and AY-3-8912
  • 12 quick save slots
  • Load from .z80 snapshot files
  • Read from .tap tape files
  • On screen menu system (work in progress)
  • Kempston and Sinclair joystick emulation

Screen shots

Wiring

SPI0 GPIO Pin SPI MicroSD 0 HDMI/DVI Description
MISO RX 4 6 DO DO Master In, Slave Out
CS0 CSn 5 7 SS or CS CS Slave (or Chip) Select
SCK SCK 2 4 SCLK CLK SPI clock
MOSI TX 3 5 DI DI Master Out, Slave In
CD 22 29 CD Card Detect
GND 3 GND Ground
3v3 36 3v3 3.3 volt power
GND 18,23 GND Ground
GP16 16 21 TX2+ Data channel 2+
GP17 17 22 TX2- Data channel 2-
GP18 18 24 TX1+ Data channel 1+
GP19 19 25 TX1- Data channel 1-
GP12 12 16 TX0+ Data channel 0+
GP13 13 17 TX0- Data channel 0-
GP14 14 19 TXC+ Clock +
GP15 15 20 TXC- Clock -
GP20 20 26 PWM audio out

image

Prototype

Audio filter

It's a good idea to filter out high frequencies from the PWM audio output. The following components were chosen as I found them in a draw... but it sounds ok.

image

Components

Issues

The Z80 is interrupted at the end of each frame at 60hz. The original Spectrum wrote frames at 50hz, so some code runs more frequently than it used to; there is a 4Mhz CPU setting that kind of balances this up.

There is now preliminary support for Kempston & Sinclair joysticks.

A USB hub can be connected to the RP2040 allowing a keyboard and joysticks to be used with the Spectrum. The code is a bit new and I don't know how many different joysticks will be supported; if you are having trouble raise an issue and attach a HID report descriptor from your device and I will have a look at it.

To get this to work I have done some hacking and slashing in TinyUSB (sorry Ha Thach):

https://github.com/fruit-bat/tinyusb/tree/hid_micro_parser

update

Updates suggested by Ryzee119 are getting harder to merge into the latest code:

https://github.com/Ryzee119/tinyusb/tree/multi-hub

The combined efforts were here, but are now out of date:

https://github.com/fruit-bat/tinyusb/tree/hid_micro_parser_and_hub

Try it

A pre-built binary can be copied directly to a Pico Pi. Connect your Pico Pi with a USB cable, while holding down the program button, then:

cp ZxSpectrum.uf2 /media/pi/RPI-RP2/

Build

The version of TinyUSB in the Pico SDK will need to be replaced with a version containing a HID report parser and USB hub support.

Using git protocol:

cd $PICO_SDK_PATH/lib/
mv tinyusb tinyusb.orig
git clone git@github.com:fruit-bat/tinyusb.git
cd tinyusb
git checkout hid_micro_parser

...or using https protocol:

cd $PICO_SDK_PATH/lib/
mv tinyusb tinyusb.orig
git clone https://github.com/fruit-bat/tinyusb.git
cd tinyusb
git checkout hid_micro_parser

The following code needs to be cloned into the 'apps' folder of the PicoDVI library.

Using git protocol:

cd PicoDVI/software/apps
git clone git@github.com:fruit-bat/pico-zxspectrum.git zxspectrum
git clone git@github.com:fruit-bat/no-OS-FatFS-SD-SPI-RPi-Pico.git
git clone git@github.com:fruit-bat/pico-dvi-menu
git clone git@github.com:fruit-bat/pico-emu-utils

...or using https protocol:

cd PicoDVI/software/apps
git clone https://github.com/fruit-bat/pico-zxspectrum.git zxspectrum
git clone https://github.com/fruit-bat/no-OS-FatFS-SD-SPI-RPi-Pico.git
git clone https://github.com/fruit-bat/pico-dvi-menu
git clone https://github.com/fruit-bat/pico-emu-utils

In the 'apps' folder add the following lines to CMakeLists.txt

add_subdirectory(pico-dvi-menu)
add_subdirectory(pico-emu-utils)
add_subdirectory(zxspectrum)
add_subdirectory(no-OS-FatFS-SD-SPI-RPi-Pico/FatFs_SPI)

If your board does not include SD card detect add the following line in the file "zxspectrum/src/hw_config.c":

.use_card_detect = false,

after the line:

.card_detected_true = 1

In the build folder:

cmake -DPICO_COPY_TO_RAM=0 ..
make clean
make -j4 ZxSpectrum
cp apps/zxspectrum/ZxSpectrum.uf2 /media/pi/RPI-RP2/

Prepare an SD card

The following folders need to be created on the SD card:

Folder Contents
zxspectrum/snapshots Put your .z80 snapshot files in here.
zxspectrum/quicksaves Folder for quick saves.
zxspectrum/tapes Folder for .tap tape files.

Special keys

Key Action
AltGr Symbol
F1 Toggle on screen menu
F4 Toggle the Z80 moderator. Cycles through 3.5Mhz, 4.0Mhz and unmoderated
F5 play current tape
F6 play previous tape
F7 play next tape
F8 Reload current snap
F9 previous snap
F10 next snap
F11 Reset as 48k Spectrum
F12 Reset as 128k Spectrum
LCtrl + F1-F12 Quick save (LCtrl+F1 = save slot 1, LCtrl+F2 = save slot 2, etc)
LAlt + F1-F12 Quick load (LAlt+F1 = load slot 1, LAlt+F2 = load slot 2, etc)

Missing features

  • Audio input

Debug

Pico pin Pico GPIO Adapter wire
1 GP0 White
2 GP1 Green
3 GND Black
tio -m ODELBS /dev/ttyUSB0

Thanks to

CarlK for the super no OS FAT FS for Pico
Damien G for maintaining and publishing some wonderful 8-bit fonts
Wren for the amazing PicoDVI
hathach for the embeded USB library TinyUSB
Lin Ke-Fong for the Z80 emulator

References

Wren's Amazing PicoDVI
Z80 file format documentation
Fonts by DamienG
http://www.breakintoprogram.co.uk/computers/zx-spectrum/screen-memory-layout
http://www.breakintoprogram.co.uk/computers/zx-spectrum/keyboard
http://www.breakintoprogram.co.uk/computers/zx-spectrum/interrupts
http://mdfs.net/Software/Spectrum/Harston/
https://www.1000bit.it/support/manuali/sinclair/zxspectrum/sm/section1.html
https://k1.spdns.de/Vintage/Sinclair/82/Sinclair%20ZX%20Spectrum/ROMs/gw03%20'gosh%2C%20wonderful'%20(Geoff%20Wearmouth)/gw03%20info.htm
https://worldofspectrum.org/faq/reference/48kreference.htm
https://worldofspectrum.org/faq/reference/128kreference.htm
http://www.zxdesign.info/cassette.shtml
https://uelectronics.info/2015/03/21/zx-spectrum-and-loaders-part-one/
https://mdfs.net/Software/Spectrum/ROMImages/
https://worldofspectrum.org/ZXSpectrum128Manual/sp128p13.html
https://cpctech.cpc-live.com/docs/ay38912/psgspec.htm
http://www.armory.com/~rstevew/Public/SoundSynth/Novelty/AY3-8910/start.html
USB HID 1.1

Description
ZX Spectrum для Raspberry Pico Pi RP2040
Readme 114 MiB
Languages
C++ 45.3%
C 39.8%
CMake 10.1%
Assembly 4.8%