mrehkopf / sd2snes

SD card based multi-purpose cartridge for the SNES
http://sd2snes.de
GNU General Public License v2.0
579 stars 114 forks source link

Fix for SGB controller multitap on SD2SNES mk2 (classic) #168

Closed redacted173 closed 1 year ago

redacted173 commented 2 years ago

https://github.com/redacted173/sd2snes/issues/29

Not sure why, but the Xilinx compiler appears to use the last? condition as the implicit default. I was expecting it to not do anything for the 2/3 case like Altera. This bug reset controller state 2 and 3 every cycle on SD2SNES mk2 which caused those controllers not to work for Wario Blast and Bomberman GB.

It may be easiest to manually merge the change in your local changes and close this pull request.

redacted173 commented 1 year ago

The SGB serial link code was rewritten so it works over the 3-wire P* debug bus available on mk3 when enabled in config.vh. It also still functions when it's disabled so games don't break. There is a commented out DIR and OE signal to drive a level shifter for SC, but one wasn't needed for testing with an original SGB2. Not sure if the weak pull-up resistors are necessary in main.qsf. I couldn't figure out a simple way to guard them with the define.

These changes may not be that useful, but they offer people who want to modify their device a way to use the link port. Feel free to make changes or not merge it if you don't think it's useful.

PM6_out (inout) - SC, weak pull-up PN6_out - SO PT5_in - SI, weak pull-up

mrehkopf commented 1 year ago

Out of curiosity: the Gameboy Schematics https://gamesx.com/wiki/lib/exe/fetch.php?media=schematics:gameboy_schematics_-_cpu.gif suggest that a CPU GPIO (P14) is also connected to the link port. AFAIK the same signal is also required to query the button matrix, and is fixed as an output, so its use for the link port seems limited, and it is never mentioned elsewhere in documentation of the link port. Do you have any idea what its purpose might have been and if any games use it at all?

redacted173 commented 1 year ago

I never even noticed that extra pin since the link port SGB changes were based on the link cable pinout which leaves it disconnected. LP4 does seem limited to something like a control/sync output for a peripheral. Not sure why P14 was used - perhaps the value of P14 can change the meaning of bits sent over SO? It's a mystery to me.

As an aside, the sd2snes link port will mostly work when connected to an original SGB and arduboy w/ MGB without a level shifter. However, and probably not too surprising, a level shifter is required for it to work with an Analogue Pocket. The DIR/OE pins weren't needed.

redacted173 commented 1 year ago

Do you think you'll have time to merge all these fixes from my develop branch into a future release?

The only file you may want to skip is the weak pull-up on the 2 debug pins in main.qsf. Let me know if there is anything I can do to make it easier for you. For example, submitting a branch with the changes based on a different revision.

mrehkopf commented 1 year ago

Definitely but I think I already cherry-picked a bunch of stuff from the earlier commits (before the link port stuff). I'll probably go over it in a couple of days; currently committing all the v1.11.0 stuff, then going to do bugfixes and make a v1.11.1. I think the merge would fit well in there :)