ikjordan / picozx81

ZX81 emulator for Raspberry Pi Pico
GNU General Public License v2.0
35 stars 2 forks source link

Running on a "bare" Raspberry Pi Pico #7

Closed stevexyz closed 5 months ago

stevexyz commented 1 year ago

Since the ZX80 and ZX81 have just black&white video output all the circuitry of VGA (mainly resitors to mix the colors) might be omitted using just one of the analog pins (analog just to generate proper front and back porch). Probably a simpler output in any sense might be the composite one with just two wires. Also the same for the audio. See for example the wespi ZX81 addon, just the bare ESP32 and some little components. Maybe one or two resistors should be attached to the cables, but there should be no need of an external board... Not sure how to program the 2040 "coprocessor" but should not be difficult for the expert to adapt. What do you think? PS: I've found also a working instance to take inspiration from https://areed.me/posts/2021-07-14_implementing_composite_video_output_using_the_pi_picos_pio/

ikjordan commented 1 year ago

That is an interesting link to the composite video output. It looks like it would need two pins for video (sync and data), both requiring resistors. There would also be two pins for the stero audio (1 if mono was used), also requiring resistors. Then 4 GPIO pins for the SD Card (plus 3.3V and ground), so 7 or 8 GPIO overall.

At that point I think some form of carrier board would probably still be useful? I can see why the wespi could be "bare", as I think it is connected to the ZX81 pcb via wires, but I would be concerned that a "bare" Pico with keyboard, video and audio connections might be very fragile?

However, with only 7 or 8 GPIO lines used there would be enough GPIOs free to connect a ZX81 matrix keyboard, so I can see that a custom carrier board to support composite video + audio + SD Card + keyboard matrix connection may be an interesting solution. Perhaps something like the Cytron Maker Pi Pico board could be used as the basis of a prototype board for that? Alternatively there are hardware solutions for the ZX Spectrum Pico emulator that support VGA, audio, SD Card and keyboard matrix, so using that hardware design may be possible.

stevexyz commented 1 year ago

"Bare" solution could be an option (and I would go for it). Also SD card might be avoided since input can be taken from cassette (or tapeduino/wespi alike). So few resistors attached directly to wires/connectors and that's it.

If a "carrier" has to be setup then probably putting also the 40 keys for the keyboard on it would be nice (adding something like https://github.com/swetland/zx81-keyboard, maybe usable also with a real zx81, or as a PC keyboard, as a "triple function" with one board), but I would still prefer the bare version!

ikjordan commented 1 year ago

I am trying to understand what the reason behind the request for a "bare" solution is. Is it:

  1. Video As described above, black and white composite output can be achieve with 2 GPIOs and 2 resistors. However, a new composite library would need to be written to interface to the existing code. If Black and White composite is used, then there is no way to display the ZX80 and ZX81 keyboard images on screen, which is a useful feature, especially if both ZX80 and ZX81 programs are regularly used. Also the composite standard vary between countries. It is not possible to have 1 GPIO pin drive the R, G and B inputs to VGA, as the current draw from the 3 VGA RGB pins is too high for 1 Pico GPIO to safely supply. The simplest “safe” solution is probably RGB111 (which would require 5 pins; 3RGB and 2 sync). It would be simple to reconfigure scanvideo to support RGB111, the repo already includes an example for RGB332. In theory the 2 syncs could be combined, but that requires changes to scanvideo. RGB111 has the advantage that the keyboard image can still be displayed.
  2. Keyboard There is already a solution that allows the use of a ZX81 keyboard, on both the emulator and on a PC at https://github.com/ikjordan/ZX81_USB_KBD. That solution should work with the keyboard mentioned above. That project does use a separate bare Pico to implement the USB interface.
  3. Board A simple solution requires some way to generate video, some way to interface to a keyboard, some way to load and save programs and configuration data and, optionally, some way to generate sound output. The video and the audio out is discussed above. Programs and configuration data currently requires an SD Card. The suggestion to use audio in (tape, TZXDUINO etc.) requires an circuit to detect audio signals. A circuit to achieve that requires many discrete components. It does not appear possible to create that circuit without a board. https://github.com/fruit-bat/pico-zxspectrum/issues/46 has a discussion on this and example circuits. It also requires software development to decode the audio signal. Another option may be to follow the ZX-Wespi route and use a Pico W to transfer data over WiFi and then store in the Pico Flash using LittleFS.

My thoughts…

  1. For a more integrated “single board” solution I’m keen to look at using the Circle RTOS (https://github.com/rsta2/circle) with a Pi 0 or a Pi 3A+. That offers the possibility of HDMI, audio out, SD Card and enough GPIO to interface a keyboard and possibly a DB9 joystick. The Pi Zero has a lot more CPU power than a Pico, so emulation of Chroma 81 should be possible.
  2. Implementing composite video appears a fun project. By using 3 pins a solution could be developed that allowed Black, white and 2 grey levels so the grey scale images could still be displayed. However, it will queued behind other projects I have and there are already other working display solutions (VGA, HDMI).
  3. Transferring data over WiFi is interesting. There are issues to address, such as creating directories, copying config files etc. There is already a working solution using an SD Card.
  4. Of course, all of the code is available here, so I’d be keen to receive pull requests if people want to work on these areas.
stevexyz commented 1 year ago

The idea was exactly "to achieve a simpler and more cost effective solution".

  1. B/W composite video only, seems requiring "only" two resistors before the connector (without keyboard impression on the video, if needed done with a simple printed sheet of paper)
  2. Audio input from cassette hopefully detectable from an analog pin in the simplest possible way (even if distorted the ZX81 read just 1 or 0 on the port), if not directly connected hopefully with very minimal components on it
  3. USB keyboard connected to Pico USB port, or "the real 40 keys thing" attached to digital pins (and in this case - as a nice to have - USB could be used as HID output for a PC) Audio output (for recording) as a bonus just if possible in some minimalistic way. All aligned to the original Clive Sinclair philosophy!...
ikjordan commented 5 months ago

I have now added support for LCD, VGA and HDMI. I have also added code for the colour Chroma card. I have received no more requests for composite output, and no pull requests offering code to support it, therefore I am closing this issue.