Well, I got Justifier support working... here's a few notes:
If you want continuous tracking of the gun coords, the average brightness of the screen needs to be BGR=88x or better. The sensor is apparently sensitive to light in the blue-green spectrum. Note that BGR=800 or 008 or 088 or 808 won't work; it needs to be 880 or better. Your value may vary by the brightness of your TV.
The gun lens has a focal length longer than a yard... any closer to the TV and you have to point directly at something white to activate the sensor. It seems to work about the same for greater than a yard (meter for you metric folk!).
There doesn't seem to be any way to auto-detect the second gun. I get the same inputs regardless of whether the second gun is attached or not. Because of this, I have a suggestion.
The way I currently handle Justifier support is to auto-detect the Justifier during JOY_init() with the pads and mouses and taps. That works well. However, the Justifier is a fairly resource heavy input device, needing you to setup an interrupt handler and all, so I don't enable the Justifier by default.
Instead, I added a new function: JOY_getPortType(). This allows you to see if one of the ports has a Justifier plugged in or not. If there is and if you wish to use it, THEN you enable the Justifier support.
Code: Select all
/* one or the other, not both */
value = JOY_getPortType(PORT_1);
if (value == PORT_TYPE_JUSTIFIER)
{
JOY_setSupport(PORT_1, JOY_SUPPORT_JUSTIFIER);
}
else
{
value = JOY_getPortType(PORT_2);
if (value == PORT_TYPE_JUSTIFIER)
JOY_setSupport(PORT_2, JOY_SUPPORT_JUSTIFIER);
}
The JOY_setSupport() function actually sets up all the junk needed to handle the Justifier at that point. From that point on, you merely do JOY_readJoypad()/JOY_readJoypadX()/JOY_readJoypadY() to get the Justifier input just like a mouse.
The X/Y values are -1 if the gun is not pointed at the screen. They are the raw HV counters if the gun IS pointed at the screen (and it's bright enough to pick up). I don't process the values in any way other than to separate them - JOY_readJoypadX() returns H and JOY_readJoypadY() returns V.
Currently, since I can't auto-detect the red gun, both guns show as JOY_1 and JOY_3 for port 1, or JOY_2 and JOY_6 for port 2. The buttons are read every vertical blank, with START mapped to BUTTON_START and TRIGGER mapped to BUTTON_A. The coords are read every other frame since you can only handle one light sensor input at a time.
While I support Justifiers in either port 1 or port 2, I don't yet support BOTH (four guns). I don't really see the need for that, but if someone thinks it worth it, I can add support for that.
Which brings up my suggestion: since I can't auto-detect the red gun, I was wondering if I should make two different Justifier support defines - one for just the blue gun, and one for both guns. That way if a game only supports one gun, they just enable support for one gun. If the game can handle both guns, then it can enable support for both guns. There's a MINOR speedup for just handling the blue gun (can't measure it), and the coords would update at 60 Hz instead of 30. With both guns enabled, there is a very minor slowdown associated with reading two guns instead of one, and you update the coords every other frame, i.e., 30 Hz.
Anywho, my current sample for reading the joypads now also shows both ports in addition to all eight pads. So I can see what the port type value is for different controllers: the Sega Sport Pad (trackball) has an ID of 0, the two button pad (SMS) has an ID of 15 (same as nothing), and the SMS light gun also has an ID of 15.