Thanks, but I looked at T2 and Body Count (they both use the same code) to see what was going on. The pdf has WHAT you need to do right, but no timing, which is CRITICAL on the Menacer. It's a persnickety piece of junk.
Getting the position is no problem, but to get the buttons, in the vertical blank you have to first do a mandatory wait... why? Because when the gun is at the bottom of the screen, you're so close to the vblank that the gun needs more time as a gap between the position IR signal and the button IR signals. Then you disable reset, wait a small time, enable the long reset and wait just long enough for the Menacer to reset, then disable reset and almost immediately enable long reset again. Then wait about 1.5 msec (yes MILLISECONDS) for the buttons to be read and read them. Then disable reset and almost immediately enable short reset to clear the beam position counter.
Notes: The buttons seem to have troubles at the edges of the screen... all of them. They are only stable on screen, and well offscreen. At the edges, you get glitchy buttons. Also, when START is pressed, you ALWAYS get another button (A or B 99% of the time) at the same time, and no other buttons respond (you cannot press START + C, for example). A, B, and C are no problem and can be pressed in any combination. When START is pressed, I guess you're supposed to just ignore all the other buttons. My current code returns the codes just as reported, which means START + B or START + A.
The Justifier is a MUCH better lightgun, having none of these issues. The Menacer needs to be treated with kid gloves.
Here's the current code and the sample app. There are three binaries: "trackball2.bin" sets port 2 to trackball mode (which works great - just like a mouse), "blue2.bin" only sets blue gun support on port 2 if a justifier is there (you have both guns in port 1), and "both.bin" which uses both guns on either port for the justifier.
Supported and tested on real hardware (in either port):
3 button pad
6 button pad
megamouse
team player (up to eight controllers)
menacer
justifier (one or two guns)
trackball
There's also code for the EA 4-Way-Play, but I can't really test it as I don't have one.
Emulator notes: Neither Gens/GS nor Fusion 3.63 report a correct ID for the TeamPlayer - they both report ID 0, which is a Menacer. So neither emulator works with TeamPlayer with this code. The ID code is standard and works on real hardware, so it's clearly a bug in both emulators. The Menacer and Justifier support in Fusion works with this code just fine. Pads and mice also work fine. So it's only multitap that's currently an issue in the emulators.
http://www.mediafire.com/?7zekr7duerwb09i
Stef: I can commit the code to the repo if you want... it's just joy.c and joy.h that changed. I worked from the latest rev (58 ). I noticed while compiling the library that timer.c reports an implicit declaration of SYS_isInVIntCallback(). It still compiles, but you might want to add the include file to avoid the warning.
Further notes: The trackball cannot be IDed - the first time you run the standard ID, it reports 0x0F (unknown), and every time after that until you power off, it reports 0x00 (Menacer). I had to put special conditions into the menacer support to distinguish between enabling the Menacer support and enabling the trackball support. So if you want to use a trackball in port 2, you just do JOY_setSupport(PORT_2, JOY_SUPPORT_TRACKBALL); and hope the user plugged a trackball into port 2. But it does work nice!
EDIT: Actually, Gens/GS's EA 4-Way Play support DOES work with this code, but a slight booboo makes it think there's two Menacers in place. In JOY_init(), you find
Code: Select all
/* EA 4-Way Play detected */
portSupport[PORT_1] = JOY_SUPPORT_EA4WAYPLAY;
portSupport[PORT_2] = JOY_SUPPORT_OFF;
needs to be
Code: Select all
/* EA 4-Way Play detected */
portType[PORT_1] = PORT_TYPE_EA4WAYPLAY;
portType[PORT_2] = PORT_TYPE_EA4WAYPLAY;
portSupport[PORT_1] = JOY_SUPPORT_EA4WAYPLAY;
portSupport[PORT_2] = JOY_SUPPORT_OFF;
You can see I forgot to set the portType when I discovered the EA 4-Way Play.
Note: Gens/GS always acts like there's an EA 4-Way when you turn on TeamPlayer/EA 4-Way support on port 1. There's no choosing one or the other. It also doesn't ID TeampPlayer correctly. Looking at the io code in Gens/GS for TP, it doesn't check if the direction register is 0x40 (which means it's doing the ID) or 0x60 9which means it's doing a transfer); it just assumes it's doing a transfer and so returns the wrong values for the ID code.
EDIT 2: Checking in Fusion, it has the same issue with EA 4-Way Play - it DOES work, but thinks there's two menacers. The fix above should fix Fusion as well as Gens/GS.
EDIT 3: Again in Fusion, TeamPlayer is now working... not sure why. Maybe I just goofed setting the settings the first time I tested it. So TeamPlayer IS working in Fusion. Sorry about any confusion.