Wireless SNES controllers

Topics regarding the Uzebox hardware/AVCore/BaseBoard (i.e: PCB, resistors, connectors, part list, schematics, hardware issues, etc.) should go here.
User avatar
nicksen782
Posts: 714
Joined: Wed Feb 01, 2012 8:23 pm
Location: Detroit, United States
Contact:

Re: Wireless SNES controllers

Post by nicksen782 »

@Jubatian:

I can confirm that FoAD works with my wireless controller. It is an 8BITDO SNES30.

Your changes work.

Of course, to work with the game loader you would need a wired controller and then to replace it with the wireless one once you start the game.

What changes did you make to make it work?
User avatar
Jubatian
Posts: 1561
Joined: Thu Oct 01, 2015 9:44 pm
Location: Hungary
Contact:

Re: Wireless SNES controllers

Post by Jubatian »

Thanks!

I moved the controller reading into the video frame logic of the kernel to be performed during VBlank, realizing a state machine which reads a bit in each scanline. This apparently gives sufficient time for the controller to properly detect edges, and apart from the 2 extra RAM bytes per controller, it doesn't really take any extra resource. It neither introduces more delay than the current kernel since it normally calls the ReadButtons() in VSync, at a time which is usually past the processing of the game logic (you could use CONTROLLERS_VSYNC_READ to disable it though).

There are enough blank scanlines at the 224 line tall screen on top after VSync to perform this task (so it is possible to adapt it to the regular kernel, the concept doesn't need FoaD's modifications). The delay is ~ 14ms (~20 scanlines reading plus the visible part of the video frame), you can't get anything better unless you did the controller read within the inline mixer where applicable.
User avatar
nicksen782
Posts: 714
Joined: Wed Feb 01, 2012 8:23 pm
Location: Detroit, United States
Contact:

Re: Wireless SNES controllers

Post by nicksen782 »

Sounds like a great fix! I have the entire library of Uzebox games (minus Tornado 2000). They would all need to be recompiled with this fix.

I still like the idea of the dongle. It may allow more devices to connect to the Uzebox and make it easier to use keyboards with Uzenet. Perhaps even a gamepad port memory card or something since timing could be controlled tightly external to the Uzebox.

What do you think?
User avatar
nicksen782
Posts: 714
Joined: Wed Feb 01, 2012 8:23 pm
Location: Detroit, United States
Contact:

Re: Wireless SNES controllers

Post by nicksen782 »

I have a test circuit ready. I can read any button from the wireless SNES controller. That was not too difficult.

So, with two 8-bit PI/SO shift registers I have 16 bits to set for the Uzebox to read. I only actually need 12 bits though so I tie the remaining 4 bits high.

However, the Uzebox didn't respond like I thought it would. I created a really quick demo program that would have 16 tiles lined up and change tiles based on which buttons were pressed. I double confirmed my wiring and that the micro I am using actually was outputting 0 or 1 based on button presses. Everything is correct.

So, I studied the datasheet for the 74165 shift register and I also looked at technical data for the shift registers found in the SNES controller. It is a different shift register. It uses 4021 shift register. The SH/PL pin works backwards. I'm using the wrong shift registers.

I ordered new 4021 shift registers. I'll need to re-wire of course but I am certain that this will work.

I also do not expect a delay since what the Uzebox reads will be determined by another chip. If anything the delay would be ~17 ms. Also, I found that 16.67 ms isn't a set in stone value. I was able to poll it at 8 ms as well as 100. If there is a delay I can minimize it.

This dongle will allow us to use wireless controllers (and likely any normal SNES gamepad) with the Uzebox in any game and also in the bootloader. Once this is done I think it would be smart to see if we could expand the dongle to also have PS/2 ports for keyboards/mice instead of chopping cords.
uzebuffer_demo1.png
uzebuffer_demo1.png (266.37 KiB) Viewed 14485 times
User avatar
D3thAdd3r
Posts: 3221
Joined: Wed Apr 29, 2009 10:00 am
Location: Minneapolis, United States

Re: Wireless SNES controllers

Post by D3thAdd3r »

Awesome man, good progress so far :ugeek:

Like Cunning and yourself said, really the extra delay can be brought to basically 0 which is great. Input latency bothers me to no end. Did you notice any delay on the wireless controllers you have? Also if you ended up with some stand alone no extra features style(that could work with a small MCU like the ATtiny85 PS/2 solution), it sure seems like you could fit a clean solution right in that plug just like this:
ImageImage

I often think feature requests are pointless as it takes 1/1000000 the work to think up an idea as it does to create the solution solution...so much higher supplies of ideas than development efforts. But I would particularly be interested if this could somehow expand to support a 4 player multitap. I have a cool SNES one(the Bomberman head style), but it uses extra pins in the controller port that Uzebox does not have connected. Just a random thought, that for cheap perhaps it could have a case(with ports), and read it using the required extra pins, and translate that data to Uzebox. I found it is impossible currently to use any existing SNES multitap without a translation or hacking the PCB and using a non-standard pin wired onto the port.
User avatar
nicksen782
Posts: 714
Joined: Wed Feb 01, 2012 8:23 pm
Location: Detroit, United States
Contact:

Re: Wireless SNES controllers

Post by nicksen782 »

Sorry for the delay. Life happens!

I got this working. I am using two daisy-chained CD4021BE shift registers and one ATMEGA328P-PU.

I put together a controller tester program to test both controller ports. It displays buttons pressed graphically and also indicates the bit value each bit of the button data for both controllers. (Yes I know a controller test program already exists. I wanted my own, plus it is part of another project. :) ) Although the SNES gamepad has 12 buttons the number of bits sent is 16. The other 4 bits are not used for gamepads. However, I wanted my test program to display those bits anyway.

The ATMEGA polls the wireless receiver of the wireless controller. When the ATMEGA reads the controllers it sends HIGH/LOW to the 12 bits on the shift registers. That is literally it.

The CD4021BE shift registers are read from the Uzebox as normal with no modification to the kernel. As far as the Uzebox is concerned there should be no difference. These shift registers are latched so it really doesn't much matter when the Uzebox reads since there is technically no interruption occurring.

Latency was a concern of mine. It turns out that I can poll the wireless receiver WITHOUT a delay in the main loop. I tried a delay of 0 (no delay at all), delay of 1, and a delay of 16. You can just barely perceive some latency at 16. The button press seems to stay active for longer but only slightly. I have read that the poll delay is supposed to be 16.67 but it does not seem to matter much. I set it to 8ms.

bridge_20180414_145922.jpg
bridge_20180414_145922.jpg (293.43 KiB) Viewed 14060 times
My wireless controller has worked in every game I have tested it with. As a bonus the circuit works without external power.

What about those other 4 bits? Are they used for anything? COULD they be used for something? I have them tied HIGH with pull-up resistors but no connection to them from the ATMEGA. I could connect them though.

D3thAdd3r, you posted pictures of your PS/2 mouse to Uzebox SNES connector. I don't see any circuitry, none is needed, right? I think it would be a GREAT idea to include a PS/2 port for keyboard and mouse into my project. Clean data due to the ATMEGA and multi-port goodness. This would likely help the adoption of Uzenet a bit since it could be made very easy to add a keyboard/mouse and of course, play games with whatever controller you want like my wireless one.

I now need to consider shrinking the circuit to fit into something more manageable. I like what you did with your pictures. Perhaps I could fit something together that isn't much bigger.
User avatar
D3thAdd3r
Posts: 3221
Joined: Wed Apr 29, 2009 10:00 am
Location: Minneapolis, United States

Re: Wireless SNES controllers

Post by D3thAdd3r »

Wow love the setup, very cool! Especially that you report the latency is very low, I am interested to have this wireless option.
nicksen782 wrote: Sat Apr 14, 2018 8:39 pm What about those other 4 bits? Are they used for anything? COULD they be used for something? I have them tied HIGH with pull-up resistors but no connection to them from the ATMEGA. I would connect them though.
Yes they are used for the SNES Mouse(and the Super Scope, though no one ever showed a lightgun game yet). Bit 15 will be 1 if the mouse is present, and that is how a game(Whack-a-Mole and Solitaire, currently) detects if the SNES mouse is present. Otherwise it assumes it is a normal controller. I don't see an issue with using the other bits for something else, as currently no code I have seen uses them(now I forget how Alec signaled for his PS/2 adapter though..). Try out WAM or Solitaire, I think with those tied high it will detect a mouse is present? If so, then the kernel reads an additional 16 bits from each port for the extended data the mouse would normally output. So I would expect the "mouse" moves on it's own with the current setup.
nicksen782 wrote: Sat Apr 14, 2018 8:39 pm D3thAdd3r, you posted pictures of your PS/2 mouse to Uzebox SNES connector. I don't see any circuitry, none is needed, right? I think it would be a GREAT idea to include a PS/2 port for keyboard and mouse into my project. Clean data due to the ATMEGA and multi-port goodness. This would likely help the adoption of Uzenet a bit since it could be made very easy to add a keyboard/mouse and of course, play games with whatever controller you want like my wireless one.
No circuitry for the PS/2 solution...well the existing one. Alec and I discussed some extensions(by discussed, I mean he has done all the work), to support PS/2 Mouse and Keyboard simultaneously. It gets a bit crazy, I don't know what the final idea is there. In my mind, Keyboard in P1 mouse in P2, each with it's own ATtiny85, but there was talks of making some "expansion bus controller" that could do any number of things. Realistically the PS/2 keyboard is very good, and if someone modified that for a finalized version for a mouse(just a bit different data format), it will just be the standard I guess. I experimented with a similar concept to use a N64 controller, but I never perfected the firmware. Similarly there was talks about spinner controls. I like the idea of each peripheral presenting things in the same format, even if it requires a micro for each device...anyway sorry getting off track there.

With a PCB and SMT you could probably fit all that into a pretty small space. If you are interested in PS/2 stuff then I am game since I have the hardware/etc. and it would really benefit Uzenet/Uzebox128 to have a standard done. My thing there was, I would like to have an arbitrary number of controllers on the bus(like 4), with the keyboard and mouse as well, and also be totally backwards compatible with existing games(that don't know about these micros on the controller input bus). This was where it starts to get insane, and ideas like throwing '644s in front of tiny85s get brought up. What are you thinking on this direction? There really is no determined path yet but I am interested.
User avatar
Jubatian
Posts: 1561
Joined: Thu Oct 01, 2015 9:44 pm
Location: Hungary
Contact:

Re: Wireless SNES controllers

Post by Jubatian »

By the way the new bootloader should be capable to work with the wireless controllers as-is (at least by reports I received on FoaD). Just mentioning! Maybe later the kernel could be modified similarly, so native support could spread.
User avatar
nicksen782
Posts: 714
Joined: Wed Feb 01, 2012 8:23 pm
Location: Detroit, United States
Contact:

Re: Wireless SNES controllers

Post by nicksen782 »

Yes, I remember that test and it is true that the new bootloader supports wireless controllers. I don't remember what the fix was but if it isn't harmful to the kernel/games in any way I would say go ahead and include it.

But, in addition to a cleaner polling of the gamepad (which supports wireless ones) the device should be able to support keyboards/mice.

The Uzebox reads 4021 shift registers just as it would in a controller. They apparently can accept the rapid polling. I'm not sure if all controllers use the same shift registers in them or in the case of wireless controllers if shift registers are used at all (meaning all in the micro.) At least with this any snes gamepad should work with Uzebox plus you would have the connector for keyboard/mouse.

I'm going to design a PCB for this.
User avatar
D3thAdd3r
Posts: 3221
Joined: Wed Apr 29, 2009 10:00 am
Location: Minneapolis, United States

Re: Wireless SNES controllers

Post by D3thAdd3r »

Are you meaning you would like this device to read from a standard PS/2 keyboard/mouse combo that does not have the ATtiny85 addition?
Post Reply