Ever wanted to reset a SNES with the controller?

Discussion of hardware and software development for Super NES and Super Famicom. See the SNESdev wiki for more information.

Moderator: Moderators

Forum rules
  • For making cartridges of your Super NES games, see Reproduction.
poorstudenthobbyist
Posts: 252
Joined: Fri Jun 24, 2016 4:20 pm

Re: Ever wanted to reset a SNES with the controller?

Post by poorstudenthobbyist »

Oh you probably meant the clock pulse into the shift registers. Duh. I'm tired lol, I'll check in the morning.
lidnariq
Posts: 11432
Joined: Sun Apr 13, 2008 11:12 am

Re: Ever wanted to reset a SNES with the controller?

Post by lidnariq »

Alignment of clock pulse on the controllers relative to latch pin.
poorstudenthobbyist
Posts: 252
Joined: Fri Jun 24, 2016 4:20 pm

Re: Ever wanted to reset a SNES with the controller?

Post by poorstudenthobbyist »

Ch1 (yellow) - Data
Ch2 (blue) - Latch
Ch3 (purple) - Strobe

The zoomed out capture is of DKC running while pressing L+R+START+SELECT.
The closer capture is zoomed in while pressing Y button so I can capture the button press and the latch signal at the same time.
The closest capture with the latch signal removed is zoomed in really close to a button press (yellow) and the strobe (purple).

I'd attach the ones for Zelda, but they're literally the exact same haha

I'm thinking that maybe the clock rising edge and the data rising edge are too close together. Maybe? For the zoomed in pictures, I'm pressing the Y button, and the second rising clock edge should detect the Y button being pressed. It'd be better if the data changed in the middle of the clock pulse, but it still seems like it should capture it correctly, I think. So maybe that's something I can try fiddling with.

I don't know why DKC and Zelda respond differently, it's literally night and day. Zelda is always perfect, never glitches, and DKC will shift back and forth every so often (holding down the buttons and watching the LEDs confirm this). But the scope traces are identical, I can lay them on top of each other and they'll be perfectly lined up.
Attachments
DS1Z_QuickPrint23.png
DS1Z_QuickPrint20.png
DS1Z_QuickPrint19.png
lidnariq
Posts: 11432
Joined: Sun Apr 13, 2008 11:12 am

Re: Ever wanted to reset a SNES with the controller?

Post by lidnariq »

Oh, yeah! The output changes on rising edges, and the latches latch on rising edges. That's definitely a bad combination.

Make your 74'595s latch on falling edges.
poorstudenthobbyist
Posts: 252
Joined: Fri Jun 24, 2016 4:20 pm

Re: Ever wanted to reset a SNES with the controller?

Post by poorstudenthobbyist »

NOPE
I inverted the strobe signal going into the shift registers and it still does the same thing. Even checked on a scope, the rising edge is smack in the middle of each button press, and it STILL shifts the output. Really strange....

I would love to blame the '595, but I mean, it's directly tied to the game! I have absolutely no idea what's going on.

I thought I could catch the problem by being clever - I held down the Y button, and triggered the scope off the (supposed) Y button output (which is usually actually tied to the Select button playing DKC). So when playing DKC, I could catch the glitch in process. I had to hold it down for anywhere between 5 seconds and a minute to get a capture, but I got it.

Then I put in Zelda and triggered off the Y button (immediately triggers when I press the button as expected). Then I compared the two.


......they're exactly the same.

*pulls out hair*

I even went back and triggered the scope again during DKC by pressing the Select button during the "normal" operation, and yeah, the data shows the pulse in the Select button position, but the Y position is being output! (this is QuickPrint26, the first test is 24; both channel 4's are the Y button outputs on the '595 to trigger from)
Attachments
DS1Z_QuickPrint24.png
DS1Z_QuickPrint26.png
lidnariq
Posts: 11432
Joined: Sun Apr 13, 2008 11:12 am

Re: Ever wanted to reset a SNES with the controller?

Post by lidnariq »

If you try with an "eyes" test signal like 0x5550, such as by pressing b+select+up+left+a+L, do you see any glitchy moments, i.e. a bit deletion?
poorstudenthobbyist
Posts: 252
Joined: Fri Jun 24, 2016 4:20 pm

Re: Ever wanted to reset a SNES with the controller?

Post by poorstudenthobbyist »

I redid the breadboard so it's not a monstrosity, and only have LEDs on start, select, L, R, and now Y. But if I hold them all down during DKC, when the output glitches itself to the correct positions, sometimes it'll stick there for a few seconds, sometimes it'll just flash for a split second (is that what you mean by an "eyes" test? lol). The B button data is probably getting deleted. It's like, skipping a clock pulse, either the first one or the last one I imagine, so it's not loading it in all the way.

I can probably do this easier with a microcontroller, but I'd rather do it all discrete.
lidnariq
Posts: 11432
Joined: Sun Apr 13, 2008 11:12 am

Re: Ever wanted to reset a SNES with the controller?

Post by lidnariq »

I ask about the "eyes" pattern just because if the clock signal is somehow dirty, maybe you'll see a momentary spike on the oscilloscope from the deleted bit. Just hoping, really.
poorstudenthobbyist
Posts: 252
Joined: Fri Jun 24, 2016 4:20 pm

Re: Ever wanted to reset a SNES with the controller?

Post by poorstudenthobbyist »

Oh, I get what you're saying now, alternating the bits.

Ok, even though it wasn't too noisy, I put an RC filter on the (inverted) clock signal. I noticed that when I switched two of my probes input channels, the clock signal got a bit noisier. I had the original channel set to 20 MHz bandwidth. My oscilloscope has a full 50 MHz bandwidth if I don't limit the channel manually, and like, I don't think something that high of frequency would trigger a clock pulse (especially exactly one extra clock pulse every time almost?) and I don't know why it would changed based on the ROM of all things (I use the same 27C322 for Zelda and DKC, the board is the same except obviously Hi/Lorom modes, but that's why I tested Sim City 2000 as a HiROM game too)

but

this filter fixed it. It's still ever so slightly glitchy on DKC, but now it's the opposite problem - the buttons normally work, and glitch one datapoint off for a split second every so often.

The RC filter has a cutoff frequency of about 250 kHz, which does round off the clock pulse a bit, so this could easily be tweaked to make the signal better. But it works just fine for what I need it to do.

What a weird few days, haha. Thanks for helping out. I think I might make this into a little board, and add a few things - extra logic gates to prevent against false triggers (like adding the conditions that the other buttons CAN'T be pressed), selectable button configs (want to reset by pressing up and down at the same time?), and a large RC in-line with the 555 trigger to charge up so you have to hold the correct buttons down for a certain amount of time before the reset occurs.

Good ol' analog circuits. They don't let me down.
poorstudenthobbyist
Posts: 252
Joined: Fri Jun 24, 2016 4:20 pm

Re: Ever wanted to reset a SNES with the controller?

Post by poorstudenthobbyist »

I started looking at this again, I got PC boards made up a few months ago but only just got around to trying them out. I'm getting the same issue, where some games work and others don't. I haven't tried tweaking the RC filter yet. I imagine doing this on a breadboard introduced a lot of parasitics that might have been helping the function, and now that it's on a clean PCB, those parasitics aren't there to "fix" the issue anymore. So I'll have some fun tweaking.

I did start thinking about adding full configuration support. Using XOR gates, and two-way solder pads, I can set up the board to let the user decide the configuration of the buttons for the reset function (not including the D-pad to keep part count low). One input of the XOR gate would go to the shift register output for the L, R, Start, Select, X, A, Y, and B buttons, and the other input would go to the selector solder pad that would tie the input to VCC or GND. It's set up so that when the shift register output is the same as what the user selected (VCC = no press, GND = press) then the output is LOW. All of those get cascaded through 2-input OR gates, to a final OR gate that checks to make sure every output of the XOR gate is LOW. That then triggers the 555 timer circuit.

Here's a rough schematic that I thought up last night, if anyone is interested. Maybe there's mistakes and it's a bit messy - I was tired haha. Once I get something working (eventually) I'll update it.
resetmod2.PNG
I just realized I used XNOR gates here instead of XOR gates, but they should still work fine, it just flips the VCC and GND configurations on the solder pads.
User avatar
jeffythedragonslayer
Posts: 344
Joined: Thu Dec 09, 2021 12:29 pm

Re: Ever wanted to reset a SNES with the controller?

Post by jeffythedragonslayer »

poorstudenthobbyist wrote: Thu Dec 17, 2020 10:23 pm By strobe, do you mean what I label as "latch" in my schematic?
My oscilloscope shows the exact same traces when measuring the latch and data pins, triggering on latch, no matter what game it is. Unless you mean a different pin from the SNES console and not on the controller port.

Unless of course something is changing between latch pulses, and I'm missing it on the scope.
I think some people use "strobe" as a synonym for "latch," correct? But I don't think the snes controller actually uses data strobe encoding because there is a clock pin on the controller port (sending CLK would be redundant because it can be recovered by XORing data and strobe, when it is used in the d/s sense).

I think this kind of strobe just means "when strobe is high, data is valid, but when strobe is low, all bets are off.' Right?
User avatar
rainwarrior
Posts: 8734
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Ever wanted to reset a SNES with the controller?

Post by rainwarrior »

jeffythedragonslayer wrote: Tue Jan 17, 2023 11:18 pmI think some people use "strobe" as a synonym for "latch," correct? But I don't think the snes controller actually uses data strobe encoding because there is a clock pin on the controller port (sending CLK would be redundant because it can be recovered by XORing data and strobe, when it is used in the d/s sense).

I think this kind of strobe just means "when strobe is high, data is valid, but when strobe is low, all bets are off.' Right?
A strobe is a pulse, a flash, a signal that goes on then off.

In the controller reading context, it's the signal that causes the latch to gather data. When the strobe goes on, the latch opens and the button inputs will drive its contents. When the strobe turns off, the latch closes and will retain its contents to be read out. (This is controlled by writing $4016 bit 0, or using the auto-read.)

On a latch IC like the 74161 I think that pin is usually called "LOAD" or "LD"? The strobe is a signal that is "latch" in the verb sense, perhaps... but "latch" is also the noun for the register that remembers the data. The word "strobe" is more of a description of the signal used that goes high then low.

The latch (noun) is also a shift register, and the CLK (clock) causes the latch to discard a bit and shift everything else over to fill the void. That's how each bit from the latch gets read in series through the same output pin. (The clock pulse is sent once for each read to $4016/4017, or automatically 16 times by the auto-read.)

So, in this controller connector pinout, pin 3, labelled "latch" is sent a strobe to latch the data.

Though, I believe what poorstudenthobbyist has labelled "strobe" in one post above is the clock signal, used to shift a new data bit into place. I suppose a clock pulse is also a strobe, though I'm more used to using the word with the pulse that controls the latching. (I think poorstudenthobbyist is doing the reverse to capture the bits though, reading the input serially into a shift register, to be read out in parallel to potentially trigger a reset... so maybe the controller clock is also a latching strobe here? I dunno what the usual terminology is.)
User avatar
bouncingDVDlogo
Posts: 6
Joined: Fri Mar 11, 2022 10:46 pm

Re: Ever wanted to reset a SNES with the controller?

Post by bouncingDVDlogo »

DKC is clocking an extra bit from JOYA and then JOYB (i.e. generating a new clock pulse on each port), a few scanlines after auto-joypad-read, to check if either controller has been disconnected, and zero out the game logic's variables holding controller input if so. Relevant code starts at $80:C0FB. A connected controller would return a "1" bit for this extra clock, see "SNES Controllers Hardware ID Codes" in fullsnes.txt.

(Edited to add: the code will additionally check for controller ID's with any of the last 3 bits set, and clock in 16 extra bits per-controller without using them, before zeroing out the game-logic variables for that controller's input as above (for some reason???))
Post Reply