Next (KS2) joysticks

The Speccy's spritely young offspring. Discuss everything from FPGA to ZX
Post Reply
jamesh
Dizzy
Posts: 83
Joined: Thu Jul 06, 2023 6:36 pm

Next (KS2) joysticks

Post by jamesh »

Hello everyone,

Not that it's a very important question, but I was wondering what types of joysticks/gamepads are supported for KS2 model? FAQ for KS1 says "The Next supports any “Atari” standard joystick or gamepad, along with Master System and MegaDrive pads." but I am not able to get Kempston working, it forces "updater" mode when connected. config.ini has joystick1=1 (Kempston $1F) and joystick2=3 (Sinclair 1). I think I heard that the first port can act as a regular RS-232 port [on KS1 model at least]. Maybe my Kempston somehow triggers that mode? I am a bit reluctant to hot plug the joystick and I am not sure how to change the default configuration, if that's possible at all.

NMI -> Settings -> Joysticks menu shows different values (MD1 and MD2). And I am not even sure what that menu or config.ini actually controls. Does it change the way connected joystick is presented in the emulated hardware (basically, the port number) or does it physically reconfigure the joystick port?

Thanks.

P.S. my Mega Drive gamepad works just fine, so practically I am alright, but I am lost in all those settings available in several places.
SNG
Drutt
Posts: 13
Joined: Sat Dec 23, 2023 12:16 am

Re: Next (KS2) joysticks

Post by SNG »

Several places?

The startup menu, normally skipped, sets the defaults. These persist till you change them.

The NextZXOS menu lets you over-ride them temporarily during a session. It shows what you set as default, then lets you change that.

It seems sensible to have both.

The options exist because there is no standard, never was, and Next lets you pick from all those assumed in thousands of programs written over the years, and for new software it adds compatible support for a second button on Kempston ports (which works with CD32 pads etc) and up to eight buttons via the compatibility with Sega Megadrive controllers and clones of those, which are cheap and readily available now and can be used in some complicated new Next-specific titles.

NextZXOS 2.08 also allows keys to be mapped as alternatives to any controller direction or button, via a simple extension to the INPUT command.

And then there’s support out of the box for PS/2 mice, pads and trackballs each potentially with three buttons and a scroll wheel. Not only does that work with new software like Krystal Designs, and all Datel and Kempston mouse titles, dozens of classic games have also been patched for mouse control by velesoft.
jamesh
Dizzy
Posts: 83
Joined: Thu Jul 06, 2023 6:36 pm

Re: Next (KS2) joysticks

Post by jamesh »

Hmm, sorry, I totally agree with your explanation and I thought that was how it was supposed to work, but...
SNG wrote: Sat Dec 23, 2023 9:59 am The startup menu, normally skipped, sets the defaults. […] The NextZXOS menu […] shows what you set as default, then lets you change that.
That’s where my Next KS2 disagrees. NextZXOS menu is always set to MD1+MD2, even though Kempston+Sinclair is requested in config.ini. Hence, something overrides the config.ini settings always using Mega Drive protocol* on the hardware level and presenting joysticks as “MDx” to software. And booting with Kempston connected is just not possible.

Based on what I see, my Next works like this:
  • physical connection is always assumed to be Mega Drive, 6 buttons*. I have not found a way to change it. Connecting something that doesn’t “speak” Mega Drive protocol prevents booting at all.
  • config.ini is either ignored altogether or overridden by something else.
  • NMI -> Settings -> Joystick (NextZXOS menu) allows choosing how the connected Mega Drive pad is presented to the code running (MDX,KempstonX = Kempston + A -> ENTER, C -> M, XYZ to keys XYZ; Sinclair, Cursor, KeyJoy = as described, extra buttons are ignored). That’s confirmed with a simple keyboard/joystick test. Interesting fact: XYZ buttons are mapped to XYZ keys for both MD pads connected, at least that’s how it appears to the legacy software expecting regular Kempston input, maybe native Next software can read those separately for each controller.
Note: this was all about Next native personality.

For the non-native personalities, config.ini seems to be the place defining software behaviour. NMI button does not work, hence no way to change anything on the fly.

Long story short, FAQ statement "The Next supports any “Atari” standard joystick or gamepad, along with Master System and MegaDrive pads." is not true for KS2 and, probably, wasn't not true even for KS1 models (the "pinout" document is 3 years old).

*) port pinout doc actually says Mega Drive is the only physical protocol supported, am I reading it right?

P.P.S. Quickstart guide mentions that both joystick ports may be used for serial communications. Is it described anywhere?
SNG
Drutt
Posts: 13
Joined: Sat Dec 23, 2023 12:16 am

Re: Next (KS2) joysticks

Post by SNG »

By ‘startup’ I was referring to the menu in the anti-brick scheme, before NextZXOS (or Acorn or other cores) is loaded. Press space immediately after powering up to see that one and adjust the defaults. Let us know if it helps.

You can always change the joystick configurations with NextREG 5. Mask out bits other than the relevant three for each port.

REG 11 lets you select and bitbang pin 7 output on both ports at once, or route a clock or UART data stream there. All easy to experiment with from NextBASIC. I’ve only tried this from KS1 hardware, so far.
jamesh
Dizzy
Posts: 83
Joined: Thu Jul 06, 2023 6:36 pm

Re: Next (KS2) joysticks

Post by jamesh »

SNG wrote: Sat Dec 23, 2023 3:41 pm By ‘startup’ I was referring to the menu in the anti-brick scheme, before NextZXOS (or Acorn or other cores) is loaded. Press space immediately after powering up to see that one and adjust the defaults. Let us know if it helps.
That's the UI for config.ini, unless I am missing something, right? Anyway, that screen (SPACE from initial boot splash following SPACE on the screen with personalities list) shows the same as config.ini -- Kempston1 + Sinclair1. Tried changing those, too. Yet, NextZXOS menu (NMI -> Settings -> Joysticks) always starts with MD1+MD2.
User avatar
Seven.FFF
Manic Miner
Posts: 744
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: Next (KS2) joysticks

Post by Seven.FFF »

The boot options settings (which are indeed a UI for config.ini) are now split into two sections. One section that applies everywhere, and the other section that only applies in non-Next boot personalities. (I say now - several years ago it was different, but not everybody wants to update, so the older ways can still be relevant even now.)

NextZXOS with the Next personality has equivalent options to that other half, which are selectable and remembered individually for each legacy game in the tape/snapshot loader options.

For non-legacy Next-specific games (NEX files, NextBASIC BAS files), the expectation is that the dev will drive the joystick options directly from inside the game. The options are only there, after all, because legacy Spectrums had a bunch of different hardware, and users usually own one of them.

The settings can also be changed on the fly in NextZXOS at anytime, including during a game, by pressing the yellow NMI button to invoke the multiface.

For users that aren’t picking joysticks options on the tape screen for whatever reason, or are running Next-only games where the dev didn’t get the memo, the effect is indeed going to be that those games default to MD1 and MD2. Those were chosen to be the sensible defaults as they offer the most extra buttons, and also Kempston interoperability.

If you’re hitting a problem with this setup, please explain exactly what you’re trying to do. The solution will be different, depending.
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins
jamesh
Dizzy
Posts: 83
Joined: Thu Jul 06, 2023 6:36 pm

Re: Next (KS2) joysticks

Post by jamesh »

Thank you very much, it's good to have official confirmation. Looks like I've correctly deduced most of the moving parts there.
Seven.FFF wrote: Mon Dec 25, 2023 5:58 pm If you’re hitting a problem with this setup, please explain exactly what you’re trying to do. The solution will be different, depending.
No, it actually works fine with the MD pad, and that's all I need to enjoy my Next. I'm just that kind of guy who loves to have all the answers, even though they may not be useful right now :)

I have one (not critical) question, though. What is the physical "protocol"? Only MD 6 button or something else is supported? I see other people mention Atari/Kempston working, but my Kempston adapter did not work. Surely, it's not a real Kempston, it's a passive adapter for the MD pad, but it does work with DivMMC units, Protek and a programmable joystick interface (the latter two being the original hardware from the 80s).
User avatar
1024MAK
Bugaboo
Posts: 3123
Joined: Wed Nov 15, 2017 2:52 pm
Location: Sunny Somerset in the U.K. in Europe

Re: Next (KS2) joysticks

Post by 1024MAK »

Do you mean the pin-out of the port?

And what do you mean by "Kempston adapter"?

For Sinclair ZX Spectrum 16K/48K/+/128 machines, there were no built-in joystick ports. The term "Kempston" when used to describe a protocol, refers to the Z80 input/output port address and if the logic of the inputs was positive or inverted ("negative"). Both the Sinclair Interface 2 and all known third partly joystick interfaces used a subset of the Atari joystick port pin-out on a 9 pin D-connector.

Then Amstrad messed things up by including built-in joystick ports that to software looked like the Sinclair Interface 2 standard, but used a completely different pin-out. But still used a a 9 pin D-connector.

Mark
:!: Standby alert :!:
“There are four lights!”
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :dance
Looking forward to summer later in the year.
User avatar
Seven.FFF
Manic Miner
Posts: 744
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: Next (KS2) joysticks

Post by Seven.FFF »

Thanks Mark. I'll try to bring this back to how it relates to the Next.

Normally you wouldn't call the physical wiring between the stick and the DE-9 socket a protocol, just a wiring. But in the case of Sega MegaDrive/Genesis, it kinda is. In the regular Atari type wiring we're all used to, there's a GND ground pin and and a separate input pin for all the directions and buttons, and the "protocol" is for the direction/button switches to be normally open, but closed when activated, shorting the individual pin to GND. But in Sega, one of the pins is an output pin that has a clock signal on it. The stick is supposed to watch that clock signal and divide it up into a repeating pattern of two or eight cycles, and depending on which step of the repeating pattern it thinks it is on, short the pins that correspond to that step to GND. In that way, far more buttons and directions can be used than there are separate pins for. You could call this a state machine for multiplexing signals. There used to be a nice public page decscring how the eight steps worked, but it's disappeared off the web. This one has copied most of the info, but has some unrelated arduine stuff in too: https://jonthysell.com/2014/07/26/readi ... h-arduino/

So. The Next physical side always operates with a 6 button Sega wiring and protocol, whichever software protocol the CPU is using to read it. But not all the software protocols can read all six buttons, or ever could in classic Spectrums. I believe we have the Next set so that Kempston 1 and 2 can read buttons B (main fire) and C, and all the other ones except MD1 and MD2 can only read button B (main fire). MD1 and 2 are the same as Kempston 1 and 2, except that all eight bits of the port can be read for extra buttons. Because there are more Sega buttons than bits in an 8bit byte, the additional buttons (Mode, X, Y and Z) can be read with nextreg 178.

Reading the Sega protocol details, it is clear that Sega can also operate in 1 or 2 button mode, if the stick detects there is nothing going on with the clock signal on the Select output pin. And sticks that don't know about the the Select output pin ignore it. This effectively collapses it down to something very close to standard 1 button Atari wiring. The differences are that Atari machines usually had +5V on pin 7, and they had analogue paddles on pin 5 and 9. Sega has Select output pin on pin 7, +5V on pin 6, and second fire (C) on pin 9. So, for the subset of 1 button Atari joysticks that don't need power (no autofire etc), they work just fine in Sega machines and the Next. In fact this is the vast majority of 80s Spectrum sticks. apart from those ghastly nonstandard Amstrad Sinclair SJS-1 stick Mark mentions.

This is the Next (and Sega) physical wiring.

That pinout also has details of the UART mode. It came about like this. The Next has two internal fast UARTs (up to 2,000,000 baud), one to talk to the internal ESP-01 or ESP-12f wifi modem, and one to talk to the internal Raspberry Pi Zero accelerator. Devs and hardware hobbyists pretty soon found ways to use the UARTs with wired serial cables too, for dev tools like PDS, or for sending files or other data around. But as the connections are all internal, and using the ESP connector for wired serial stops you using it for the ESP, we added the ability to plug a serial cable into one of the joystick ports. That Select output pin on pin 7 is now very useful, as it can be used for serial TX. Any of the other input pins are suitable for RX so we chose pin 9. And the only other pin serial needs is GND on pin 8.

There is a physical multiplex chip on all Next boards, which means there is only one set of FPGA GPIO pins connected to the directions and buttons, with an additional GPIO pin that can switch the mux chip between left and right socket. Because the mux chip is hardsoldered, it means there is a hard limitation of a single output pin shared between both sockets, so you can't have two UARTs connected to joystick sockets at the same time, or one UART and one Sega stick. You can have two Sega sticks because the same Select clock signal can drive both sticks at the same time.

That limitation of not having two independent output pins led us to add something to the ks2 board, so that a wired serial and ESP can be connected internally at the same time. The ESP-12f is soldered in on ks2 boards, so the mechanism is to pull the ESP's EN pin low by connecting it to GND through a 1K resistor. This disables the ESP and allows the signals on the CN9 pin header to reach the FPGA, so a serial cable on CN9 can talk directly to the UART. Simply disconnecting the resistor and unplugging hte serial cable at the PC end allows the ESP back into the circuit. A similar arrangement can be done for ks1 boards, although it needs a piggyback adaptor board so that serial cable, resistor and ESP can all plug into the ks1 board's CN9.

Image

Either left or right sockets can be switched into UART mode by writing a 111 values to nextreg 5. ESP and Pi UARTs can be operated with ports 0x153B, 0x163B 0x133B and 0x143B, whether in joystick mode or not.

So that's how the Next physical side works. The software protocol side being switchable is best understood by visualizing a classic Spectrum with a Kempston interface, SInclair interface 2, Cursor interface and Sega interface (they didn't exist for Spectrums back in the 80s) all plugged into the back in a big chain. All of them with two sockets, and with two rotary A/B/C/D selector switches deciding which interface is turned on for the left side and the right side. Such a thing would have been unworkable in the 80s, and people would have just unplugged everything when they wanted to switch interfaces. In fact most people only owned one interface, which is why the games were mostly written to support all the interfaces, switchable on the main menu. The Next has no such trouble having all the hardware inside the FPGA and case at once, and using aconceptual A/B/C/D selector switches in nextreg 5.

Kempston 2 is not really a thing outside of modern hobby hardware btw. JoeFish invented it, I think, by rewiring a Kempston interface so that it responded to I/O port $1F instead of port $3F. That way he was able to set up some four player joystick gaming sessions. Fast forward a few years, and the Next team was looking for a way to have twin joystick games that still used the full keyboard (Sinclair and Cursor protocols both fake numeric keypresses). We looked at Protek (interfaces are quite rare out in the wild) but the port it uses conflicted with something else already built into the Next. So we adapted Jason's port $1F thing. It's pretty much only used for Next-specific games, but there are a small handful of classic games like Bomb Munchies that support it too.

The remaining confusion is terminology. Kempston is a company, who made Competition Pro joysticks, and joystick addons with the IN $31 software protocol, and is often used to mean a subset of the Atari wiring protocol. Atari is a company, a family of consoles (not all of which were wired the same as the 2600), a defacto wiring standard (with caveats for which pin power is on and what might be on the analogue paddle pins instead). Interface can mean hardware addon, or a common communication method between two different things. I like to call joystick interfaces addons instead of interfaces, and think of them as two back-to-back interfaces with a controller in between translating from one interface to the other. One interface speaks the Atari wiring standard, and the other interface puts data on the Z80 address bus for various addresses when the /IORQ and /RD pins are asserted low. Even controller is an ambiguous term, as it can mean a device like a CPU or logic circuit controlling things, or a joystick on a console.
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins
jamesh
Dizzy
Posts: 83
Joined: Thu Jul 06, 2023 6:36 pm

Re: Next (KS2) joysticks

Post by jamesh »

Thank you, Robin. That's all the details I was looking for, appreciate it.

And apologies for the confusion, "Kempston adapter" vs "Atari adapter" is my own slang. When I got my first Spectrum I first used a proper Atari 7800 adapter for MD pad (something I had after building a batch of those for a friend, active thingy, emulating both paddles). However, I quickly found that while those work fine with original hardware (where pins 2 and 9 are not connected at all) they confuse modern DivMMC units trying to read extra buttons from those pins (where pins appear to be shorted to the ground). So I built my own totally passive adapter basically connecting pin 5 on the Speccy's side with pin 7 on the MD pad side (SEL on pin 5 just left floating). Nothing new, schematics is all over the Internetz.

And when my Next arrived, I just pulled that thing I call "Kempston adapter" with MD pad from my Speccy's DivMMC and plugged it into the Next. And... Nothing works, Next is stuck on "update" screen. And then I started checking the docs, asking on the forums and here we are.
User avatar
1024MAK
Bugaboo
Posts: 3123
Joined: Wed Nov 15, 2017 2:52 pm
Location: Sunny Somerset in the U.K. in Europe

Re: Next (KS2) joysticks

Post by 1024MAK »

Yes, Sega MegaDrive/Genesis "pads"/"controllers" have active circuitry inside, including (depending on which "pad"/"controller" it is, a multiplex chip or equivalent or an even more complex system). Hence a controller port on a console or computer has to have the ability for some pins to be able to be configured as outputs as well as inputs (which is easy on certain rival computers to the Sinclair machines).

And the +5V power pin is different to that on Atari joystick ports which is the most annoying thing.

Anyway, as you were... :mrgreen:

Mark
:!: Standby alert :!:
“There are four lights!”
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :dance
Looking forward to summer later in the year.
Post Reply