MiSTer-devel / Saturn_MiSTer

Sega Saturn for MiSTer
51 stars 13 forks source link

[FEATURE REQUEST] SNAC support #173

Open blue212 opened 3 months ago

blue212 commented 3 months ago

Hi I wrote code to add SNAC support to the saturn core. This would let people use an adapter with the USER port and use Saturn or Gensesis/MD(software must support them) controllers. It currently supports both control modes - SMPC and SH-2 direct modes. I did uncomment and use IOSEL and it does work correctly, it determines which control mode is used(SMPC or SH2).

SH2 mode is only used in a few homebrews and lightgun games when the Stunner is detected. This mode is similar to Gen/MD since the software controls the polling and reading of the controls.

SMPC mode seems to rely on that chip to poll and read controls and put the right values into OREG. All 3 modes are supported in SMPC mode(THTR, TH, 3 line). I used a counter to time setting the select signals(TH, TR) and reading the controls. This may not be how the original chip did it. I couldn't figure out where the select signals came from in this mode, in SH-2 direct mode it they would be PDR1O, PDR2O in the core.

Every frame I check if anything is connected and identify and read the controllers. All controllers are auto detected. Every peripheral will work except the multitaps. The Sega genesis segatap and the Saturn multitaps. They don't work with current code, they use 3 line mode and I had special checks for them to make them work but removed the code to simplify and minimize it. The digital pads, 3d pad, steering wheel, mouse, mission sticks etc have been tested and all work.

There's enough io for snac to act as one port. It is coded to be act as port 1 and usb controller 1 as port 2 when SNAC is turned on in OSD. I had a joyswap function where snac coould be switched to port 2 but commented out most of it. I removed the joyswap code in the OREG section to simplify and try to save space.

Feel free to use any of this code you like, it's ok if you want to rework, rename, optimize, or simplify any of it, just please don't change to pinout in saturn.sv because that would break existing adapters. I over commented the code in the hopes you could figure out what I was trying to do. If you want to use the code as is I can do a pull request.

I used the homebrew "Pseudo Saturn Kai" to view the OREG. it has a "smpc pad test". hit a L or R sholder button then press UDLR then z to unlock the "extra stuff" menu, then choose "smpc pad test".

If you do use it I would like you to look into how the lightgun sensor works if you get a chance. Currently with lightgun games the Stunner is detected and trigger and start button work but the sensor doesn't trigger the right thing in the core so aiming doesn't work. I think EXLE1 or 2 needs to be used so bit 6 - the sensor (TH) can be used to trigger stuff. When it goes low and EXLE(EXternal Latch Enable - it is in SMPC) is high I think that signal causes a pad interrupt (IRQL in SCU) and/or latches HV (EXLAT in VDP2). But I'm unsure how that works exactly.

Here is the code. https://github.com/blue212/Saturn_MiSTer/commit/23124284d39a24994ab0ed5cd8b6361d8a82a2aa

Great job on this and the other cores btw.

gleek12 commented 1 month ago

This sounds amazing! Would this also support the twin sticks for Virtual On?