Controller detection

Topics related to the API, programming discussions & questions, coding tips, bugs, etc. should go here.
Post Reply
User avatar
kivan117
Posts: 72
Joined: Sat Mar 14, 2015 5:43 am

Controller detection

Post by kivan117 » Mon May 18, 2015 3:50 pm

I know that it is (was?) possible to set a makefile flag to switch from the default SNES controller input to NES input. Is there a method to detect them on the fly and swap input handling appropriately? Both of my current projects use few enough buttons that the NES controllers are a viable option for people that want to use them instead, but I'd like to keep a single release that handled both. I'm aware that very few people actually deviate from the normal SNES controller, I'd just like to have a reusable method to make my games as compatible as possible.

User avatar
D3thAdd3r
Posts: 2424
Joined: Wed Apr 29, 2009 10:00 am
Location: Minneapolis, United States

Re: Controller detection

Post by D3thAdd3r » Mon May 18, 2015 9:09 pm

Ghosty Ghost should work perfectly with an NES controller, as is, without specific recompilation for NES controllers. If you would like to test and have a standard Uzebox and a NES controller handy you can use some jumper wires to connect VCC/GND/LATCH/DATA of the NES controller into the corresponding port/holes of the female SNES plug on the console itself. A little better to make an adapter if you can sacrifice an NES controller extension for the female end and wire to the male end of an SNES extension. It works because the SNES controller is basically an NES controller(1 8bit shift register) with an extra shift register daisy chained for the 4 extra buttons, and 4 unused bits. If you push the '5' key while running Uzem you can cycle through different emulated controller setups and see that many games work well with either controller needing no special recompilation.

The only thing you should keep in mind, if compiled for SNES and configured as specified, pushing B on an NES controller will be a BTN_Y to your game, and pushing A will look like BTN_B(because thats how the bits line up between the 2). For games that require no more than 2 action buttons I would highly recommend using (BTN_Y|BTN_B) = action 1 (BTN_X|BTN_A) = action 2 so it automatically works. Take a look at "defines.h" in the kernel and you can see that BTN_Y and BTN_X(b8, b9) bits do not conflict with an NES controller, because every reads after the first 8 on an NES will simply return 0 since no button is pressed(since they don't exist and the shift register is out of data).

If someone had a game like Zombienator that actually puts 4 face buttons to use plus shoulders, you would of course have to use entirely different input logic and control scheme(and let's face it, it would be inferior "shoot only in direction I walke"). That would require knowing which one to use. I am not aware of any way to tell, unless the player pushes Y/X/SL/SR which indicate SNES. You could always let the player choose a setting, and if wrong, he can still navigate menus to go back and fix it. That said now I recall GG makes use of SNES extended buttons for the score stuff. D-Pad and select/start buttons directly line up between the 2 if that helps...not sure what to recommend on that piece.

User avatar
uze6666
Site Admin
Posts: 4487
Joined: Tue Aug 12, 2008 9:13 pm
Location: Montreal, Canada
Contact:

Re: Controller detection

Post by uze6666 » Mon May 18, 2015 9:54 pm

There's no way that I'm aware to detect dynamically a nes from a snes controller. Perhaps one or two person ever used the nes ports so i would not spend too much time on this. If you still really want, There's a flag reserved on the eeprom to specify which one is in use. You'd still need a custom button polling code.

User avatar
kivan117
Posts: 72
Joined: Sat Mar 14, 2015 5:43 am

Re: Controller detection

Post by kivan117 » Tue May 19, 2015 12:52 am

Awesome. The decision to have input use A and Y for the name entry was pretty arbitrary. I'll just have it be player selectable and be sure to use buttons that overlap on both for things like that. In cases where the shoulders are not available because the player selected NES, I'll use an alternate method of switching screens that should work fine (might even change the menu graphics to reflect proper button colors because why not). I knew they both used shift registers but wasn't really sure how it all played out comparing the two or if we had any way of knowing (aside from one of the non-NES buttons being pressed). Thanks guys.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests