Page 1 of 1

Light gun input?

Posted: Fri Aug 29, 2008 9:31 am
by havok1919
Yeah, more random suggestions. ;)

If you have a spare counter that can be clocked at something close to the pixel clock (even a half or a quarter the pixel clock rate) we could connect a light gun (or two) to the hardwired external IRQ inputs. (INT0/1)

Start the counter at the beginning of each scan line. If an interrupt is detected (falling edge), the gun is pointing at the (CRT) screen and sensed a 'hit'. Stop the counter-- that's your 'X' position, the line count at the time is your 'Y' position. You then need to apply a calibration procedure (aim at the center of the screen, etc) to compensate for the (relatively) slow turn-on time for the photodiode in the gun and effects of the lense and stuff. It works though...

After the first interrupt I just mask off the interrupt until the start of VSYNC for the next frame (otherwise you can get multiple interrupts because of the focal distance of the gun). Not sure if that'd mess up your on the fly pixel shifting too much though! (might tear the line? could be OK in some applications depending on the background I suppose) I really need to read the kernal and see how you're generating sync. ;)

-Clay

Re: Light gun input?

Posted: Fri Aug 29, 2008 9:30 pm
by uze6666
Hi Clay, thats a neat idea.

Unless there's a hardware way to stop a timer on interrupt, its impossible to detect X position during rendering without screwing up the picture. That's mainly because 100% of cycles are used during rendering scanlines and the unpredictability of the interrupts latency. However, if I'm not mistaken, the Zapper would blank the screen for a single frame, overlaying white squares atop of targets for the sensor to pick up. IF interrupt only happens during that frame, that's not too bad. All timers are already taken, though timer0 could be used since it runs at 14.3Mhz to clock the AD725. Having NES connectors is a good thing since you can plug in all the stuff ever made for them. I'll add the idea to the incubator for others to tinker.

Sync code is all asm and pretty sensitive. I always wanted to go back and make it better, but there was always more interesting stuff to do. :mrgreen:

Cheers,

Uze

Re: Light gun input?

Posted: Fri Aug 29, 2008 10:27 pm
by havok1919
Coming from the "arcade" side of things I was thinking more of a Happ-style optical gun (about $50 on sale), but you're right, the Zapper would probably be a whole lot cheaper for most people. The upside on the Happ guns is that they're sensitive, so you don't have to do the "white screen flash" (or white-up on the targets) for a frame.

If timer0 if just free running I suppose the sync code could save off a copy of the timer at the start of the line, then when a (gun) interrupt occurs capture the current timer count... A-B = offset into scanline. But yeah, that's still require the IRQ to fire-mid scanline which would hose your video.

Maybe there's a way to do it using one of the input captures? I seem to recall that those can stop a counter on an edge?

OTOH, if you *did* just push white for one frame, only when the trigger on the gun is detected... You could just latch 0xff out to the video outputs and poll during the horizontal scanline paint time (since you don't need to fetch/render tiles). I bet that'd work! (That's the 'full screen flash' you see on older gun games like Lethal Enforcers, etc.)

-Clay

Re: Light gun input?

Posted: Mon Jan 14, 2013 11:29 am
by Janka
chubskee wrote:ahm... Light guns were most widely used with early console gaming systems such as the NES Zapper light gun, Using this gun the player could play games where they were required to point the gun at the screen and shoot targets, such as ducks in the popular Duck Hunt game.
^_^
The above discussed light guns won't work with TFT screens as they have not a single moving pixel but steady light coming from them. As CRTs are dying out a proposed uzebox lightgun should depend on motion sensors like a wiimote.