ZXBaremulator - GPIO "Cursor" Joystick Port

For experts to discuss very technical stuff and newbies to ask why the Spectrum they bought off ebay doesn't work.
Post Reply
User avatar
MonkZy
Manic Miner
Posts: 279
Joined: Thu Feb 08, 2018 1:01 pm

ZXBaremulator - GPIO "Cursor" Joystick Port

Post by MonkZy »

Pre-amble

I have been using the most excellent ZXBaremulator since it was first released. I feel it the very best emulated Spectrum, due to fact it is compiled to run directly on Raspberry Pi hardware without the need for an OS. Since it was updated to include support for GPIO keyboard connection I have been using an original +2 (original grey) keyboard. The result is a machine that feels just like a hardware Spectrum, awesome. Second only to an FPGA solution like ZX-Uno or TBBLue hardware. I have been experimenting with connecting joysticks to the GPIO, recreating the 'Sinclair' joystick format. 'Sinclair' joystick interfaces essentially just 'pressed' keys for each direction and fire. Each joystick port is attached to keys "0,9,8,7.6" and "5,4,3,2,1" so it is very simple to wire up to the GPIO. For the 'Sinclair' type joystick each port uses all 5 keys from two different rows on the keyboard matrix. This is OK for most games as the 'Sinclair' joystick is a very common option. Some old games (Atic Atac) only offer 'Cursor' joystick. The cursor joystick mimicked the cursor keys on the Spectrum and used "0" for fire. This creates a problem as it spreads the keys across two keyboard rows in the matrix. You can no longer attach a common ground to a GPIO for one row.

A Solution

I soldered up a solution using Opto-couplers. Maybe someone might find this useful.

Image

I am not an electrical engineer, so there may be a more elegant solution. This works perfectly, as evidenced by a three hour Atic Atac session..much fun (still only found 2 key sections - no POKE's used). Using ZXBaremulator and GPIO input there is zero noticeable lag at all.

I used LTV-847 4 x opto-couplers as they were in my box. On my rig I have two 9 pin d-sub's , one is wired for Sinclair joystick (port 1) the other is wired for Cursor joystick. I am a solo specchum. I could easily incorporate a switch to allow one port to swich between cursor and sinclair (port 2), maybe I will if I could encourage one of my sons to join me on Batty :D .
zx81
Microbot
Posts: 138
Joined: Sat Feb 17, 2018 9:33 pm

Re: ZXBaremulator - GPIO "Cursor" Joystick Port

Post by zx81 »

Hi MonkZy,

Thanks by your kind words about ZXBaremulator and by share your build with us. ;)

Can you share some images of your +2 and build?
User avatar
MonkZy
Manic Miner
Posts: 279
Joined: Thu Feb 08, 2018 1:01 pm

Re: ZXBaremulator - GPIO "Cursor" Joystick Port

Post by MonkZy »

zx81 wrote: Sat Apr 11, 2020 4:04 pm Can you share some images of your +2 and build?
I can, but it may upset some people. I bought two grey +2's from ebay. One was in very bad condition the other was OK. I made one working +2 which I have stored away. The messy +2 got chopped :shock:

I did not like the +2 when it came out, mainly because it was obviously a Sinclair creation in an Amstrad case. I was not fond of the 'all-in-one' case and thought the cassette drive should have been kept separate. I did like the keyboard. Black is my preferred colour. So with the help of a very thin saw, epoxy resin and some Isopon filler this frankenspectrum was born....

Image

Swapped the LED for a blue one...just because.

Image

Image

It is a work in progress, I have yet to print the cover for the unused ports.

Image

Image

The front joystick port is wired to be a 'cursor' joystick, the rear port is a "09876" 'sinclair' port. They are both wired for standard 'Atari' joysticks.

Image

All the parts are held together on a 3D printed frame that attaches to the original PCB screw mounts. I have drilled/cut this case up so I could have the SD card slot on the side and also I raised the opening for the edge-connector. I am currently re-designing the frame so it can be fitted with no cutting the original case. You will have to open the case to change the SD though, which is not great.

No, non-Amstrad, Sir Clive / Rick Dickinson cases were harmed in the creation of this project. Sorry Alan.
Firefox

Re: ZXBaremulator - GPIO "Cursor" Joystick Port

Post by Firefox »

Wow, I really like that!

I'd be tempted to paint the "Sinclair" and "128k" logos red, but that's just me. :)
zx81
Microbot
Posts: 138
Joined: Sat Feb 17, 2018 9:33 pm

Re: ZXBaremulator - GPIO "Cursor" Joystick Port

Post by zx81 »

Great project, MonkZy!. It's really good.
User avatar
Mort
Microbot
Posts: 190
Joined: Thu Jan 17, 2019 10:03 am
Location: Kent , England
Contact:

Re: ZXBaremulator - GPIO "Cursor" Joystick Port

Post by Mort »

I love Spectrum Bare Metal, during this time of quiet been out in the shed and hacked an old Keyboard, found A long disused pib+ from 2014, lots of Hot glue and hey presto , the cartridge on the back of the keyboard is the Pib+ :D
Image
Also hacked some old usb speakers for the sound output

Image

Slightly tidied effort

Image


Total cost was around a fiver and a good use of spare time and social distancing :-)
Scanner extraordinaire, 1000`s of magazines and Software from the 8 and 16 bit era now up on internet archive in lovely 600dpi.
Donations are welcome of items to scan that are no longer needed ;)
nenebien
Drutt
Posts: 2
Joined: Mon Oct 25, 2021 9:47 pm

Re: ZXBaremulator - GPIO "Cursor" Joystick Port

Post by nenebien »

hello! it's a great project, thanks for sharing it.
maybe is a silly question but I need to ask you, what should I change in the diagram to make it work as sinclair instead of cursor.
thanks!

Post edited by admin to remove quoting.
User avatar
MonkZy
Manic Miner
Posts: 279
Joined: Thu Feb 08, 2018 1:01 pm

Re: ZXBaremulator - GPIO "Cursor" Joystick Port

Post by MonkZy »

Hi [mention]nenebien[/mention]

I am assuming you have read the magPI 67 article. I refer to KB1 and KB2 which is used in the article for the two keyboard connectors. KB1 is 5 lines, no diodes. KB2 is 8 lines with diodes.

For a sinclair 'left' port:
Connect the common to KB2, line 1, which is GPIO 25. This must be connected before the diode, the same side of the diode as the keyboard connector.
LEFT to KB1, line 1 (GPIO 26)
RIGHT to KB1, line 2 (GPIO 19)
DOWN to KB1, line 3 (GPIO 13)
UP to KB1, line 4 (GPIO 6)
FIRE to KB1, line 5 (GPIO 5)

For a sinclair 'right' port:
Connect the common to KB2, line 4, which is GPIO 22. This also must be connected before the diode.
LEFT to KB1, line 5 (GPIO 5)
RIGHT to KB1, line 4 (GPIO 6)
DOWN to KB1, line 3 (GPIO 13)
UP to KB1, line 2 (GPIO 19)
FIRE to KB1, line 1 (GPIO 26)

Have fun! This is a great joystick setup for the ZXBaremulator.
nenebien
Drutt
Posts: 2
Joined: Mon Oct 25, 2021 9:47 pm

Re: ZXBaremulator - GPIO "Cursor" Joystick Port

Post by nenebien »

[mention]MonkZy[/mention]

Thanks a lot for your reply, a very clear explanation.
I just discover this emulator and it's a shame to find the project is dead. :cry:
anyway, I'm glad I'm gonna mount this in a Spectrum case and be able to play Dynamite Dan II with my old atari joystick. :D
Thanks again for taking your time to answer

Regards!

Edited by Admin
Czarnikjak
Dizzy
Posts: 67
Joined: Wed Feb 02, 2022 10:53 am

Re: ZXBaremulator - GPIO "Cursor" Joystick Port

Post by Czarnikjak »

[mention]MonkZy[/mention]

What are these usb devices plugged into your Pi?
I was under the impression that ZXBaremulator doesn’t support any usb devices.

Thanks
User avatar
MonkZy
Manic Miner
Posts: 279
Joined: Thu Feb 08, 2018 1:01 pm

Re: ZXBaremulator - GPIO "Cursor" Joystick Port

Post by MonkZy »

I missed this, so late reply. The two USB dongles are for when I use retropie on the same box. I have abandoned this setup now, because the GPIO/ZX keyboard is hopeless outside of ZXBaremulator.
User avatar
Joefish
Rick Dangerous
Posts: 2059
Joined: Tue Nov 14, 2017 10:26 am

Re: ZXBaremulator - GPIO "Cursor" Joystick Port

Post by Joefish »

Is it true that ZXBaremulator only supports very specific joypads? Will I be out of luck trying to plug in a generic joystick using a ZeroDelay encoder? I was thinking of giving it a go as I still have a Mk1 Pi, the price of even Mk3s is shooting up, and there seems to be sod all around that will still run on a Mk1.
(I note the idea of connecting a regular microswitched joystick as if it were just the top-left row of keys to the GPIO pins as a fallback).
User avatar
MonkZy
Manic Miner
Posts: 279
Joined: Thu Feb 08, 2018 1:01 pm

Re: ZXBaremulator - GPIO "Cursor" Joystick Port

Post by MonkZy »

I have always used a PS3 controller with a USB lead. I think you have to stick to the controllers listed on the ZXB website, there is a reasonably long list but they are all from consoles. Anything off list will be 'suck it and see'.

https://zxmini.speccy.org/en/index.html
User avatar
Joefish
Rick Dangerous
Posts: 2059
Joined: Tue Nov 14, 2017 10:26 am

Re: ZXBaremulator - GPIO "Cursor" Joystick Port

Post by Joefish »

I was hoping to be able to set it up in a sort of 'console mode' for a show, without too many options available to the user to b*gger it up. It'd be a shame to go to all the effort of supporting all those gaming controllers with their various pads and sticks and not support a basic N x buttons USB joypad.

Also experimenting with a mini macro-keyboard with just the essential controls on it. I found an 8-button one fairly cheap, although I haven't braved installing the shonky Chinese config software for it yet! Once programmed, it should work without drivers. Not sure if that's going to be recognised though.

There's always the Pi Pico as an option; apparently that can pretend to be a USB keyboard, then feed in whatever keypresses you like in response to any number of wired-up buttons and switches. You could set one button to type out LOAD " " ENTER, for example. Just takes a bit of programming... :roll:
User avatar
MonkZy
Manic Miner
Posts: 279
Joined: Thu Feb 08, 2018 1:01 pm

Re: ZXBaremulator - GPIO "Cursor" Joystick Port

Post by MonkZy »

If you are making the console yourself, the Pi Pico option sounds good if you can master it. For a console you would need a macro for the J shift-P shift-P, a simple 'start game' button.

https://learn.adafruit.com/diy-pico-mec ... o-keyboard : Adafruit blog about a pico keyboard project, looks interesting.

Sounds like a fun project.
Post Reply