nand2mario / nestang

NESTang is an FPGA Nintendo Entertainment System implemented with Sipeed Tang Primer 25K, Nano 20K and Primer 20K boards
https://nand2mario.github.io/nestang
GNU General Public License v3.0
346 stars 38 forks source link

Master System controller support #36

Closed RyanMac84 closed 2 months ago

RyanMac84 commented 11 months ago

I’m no coder, more of a copy & paste warrior and have no experience of FPGA, but rather then trying to implement USB would it be possible using the GPIO of the Tango nano 20k to read the digital inputs from a Sega Master System controller? From a nostalgia perspective it’s very similar to the NES controller (rectangular pad with 2 buttons) but I think easier to read as it doesn’t use Data/Latch etc but instead each pinout is a direct connection to each button, therefore, no input lag either, unlike USB or what the BlueRetro would introduce.

I hope that makes sense and is a plausible solution 🤷🏻‍♂️

fjpolo commented 10 months ago

I don't know the SMS joystick and the electrical properties of the signals, but I believe it should be possible. Bear in mind that it probably works with 5V and NESTang works with 3V3 signals, so you'd probably need a logic shifter for high frequency sampling or you'd probably do with resistor voltage dividers for sampling @60-120Hz.

My approach would be to create a new module with a clock divider from 27MHz to 60-120Hz, and just sample every pin at posedge of this clock divider, and just output that register. I think that should be enough.

I don't know how the light sensor works, so I'd just keep that disconnected

fjpolo commented 10 months ago

I think this branch should do it: fjpolo/TangNano20k_SMSGamepap

Bitstream: nes.zip

You'll get something like this if you place a scope: Verilator_GTKWave_20231201

And this would be the pinout: Pinout

EVK: tang_nano_20k_pinlabel

Can't test it myself since I don't own a SMS gamepad.

⚠Don't forget to convert your 5V logic to 3V3 logic!

fjpolo commented 10 months ago

BTW @RyanMac84, NESTang parses controller as [Right Left Down Up Start Select B A] and this SMSGamepad module parses it as [0 0 Right Left Down Up B A]. Here's a new version that parses it as [Right Left Down Up 0 0 B A]:

NESTang_Nano20k_0v8_SMSGamepad_20231206.zip

I personally don't think it's gonna work that good, many NES games depend on Start and Select buttons, so idk how you'll gonna find a workaround for it

fjpolo commented 2 months ago

@nand2mario can we close this one?