Page 1 of 2

Light Zapper

Posted: Thu Jun 01, 2006 5:42 pm
by zgh4000
Who is the Light Zapper research? You can write a simple demonstration of the procedure for me?

Posted: Thu Jun 01, 2006 7:51 pm
by tokumaru
I think all the zapper does is detect the presence of white... So, to check if it hit anything on the screen, you have to paint it all black (when the trigger is pressed), and have a white square in the area that you are checking for a hit. If the gun detects white, the target was hit.

Objects you can hit must be checked one at a time, so that you know wich one was hit.

You may want to avoid cheating, when someone points the gun to a white light and pulls the trigger, meaning he'll alway get a hit. To avoid that, you first make the screen all black before checking for the individual hits. If you get a hit with a black screen, the person is cheating, and you can ignore that shot.

I don't have any code though, sorry.

Posted: Thu Jun 01, 2006 9:07 pm
by tepples
tokumaru wrote:I think all the zapper does is detect the presence of white
It may be sensitive to other colors, but nobody has studied this in depth.
Objects you can hit must be checked one at a time, so that you know wich one was hit.
Almost. If you light up a group of objects at once, then you know that the object that is hit is either inside the group (if the gun registers light) or outside the group (if the gun registers dark).

Posted: Thu Jun 01, 2006 9:14 pm
by tokumaru
tepples wrote:Almost. If you light up a group of objects at once, then you know that the object that is hit is either inside the group (if the gun registers light) or outside the group (if the gun registers dark).
Yeah, like a binary search you say? You narrow down until you reach the one object that was hit... That would be good for a big number of objects. But do you think the number of objects the NES can display at once would justify a binary search? I don't know...

Posted: Fri Jun 02, 2006 9:53 am
by Dwedit
Binary search means less frames of a dark screen.

Posted: Fri Jun 02, 2006 12:57 pm
by Quietust
Dwedit wrote:Binary search means less frames of a dark screen.
It is also only useful if you have 4 or more targets on the screen at once. There's also the fact that even with 6 targets, the overall delay (1/10th of a second) when doing one at a time is still very short.

Posted: Fri Jun 02, 2006 1:09 pm
by Memblers
I have a zapper demo here:

http://www.parodius.com/~memblers/nes/zappa.zip

It's really simple though, it doesn't check the trigger and it displays an all-white screen. It changes the pitch of the sound depending on where on the screen it's pointed.

To read the zapper, you have to poll it constantly. Like every scanline (114 cpu cycles or so), reading it only during vblank like a controller won't work. The good part of that is that you can narrow down the target by counting the scanlines, but the bad part is that it keeps the CPU busy for most of the frame.

Posted: Fri Jun 09, 2006 9:35 pm
by zgh4000
I understand the basic principles, but I have never made a successful demonstration of the procedure.
I write the nes have not appeared in the simulator gun sights.
Zappa.nes I have read, it is not a complete zapper demonstration procedures.

Posted: Sun Jun 18, 2006 8:26 am
by zgh4000

Posted: Sun Jun 18, 2006 8:52 am
by Quietust
zgh4000 wrote:a zapper demo :
http://zgh3000.ik8.com/fc/zapper.zip
I'm not quite sure what it's supposed do, but I don't think it's working properly. When it starts up on my CopyNES, it displays a bunch of junk on the screen (probably due to writing to VRAM while rendering is turned on), then displays a blue semicircle moving diagonally across the screen. When I fire at it, it flashes white for 1 frame but does nothing else, whether I hit it or not.

It might aid in the debugging process if you included the ASM sources with the demo.

Posted: Sun Jun 18, 2006 3:44 pm
by zgh4000
It might aid in the debugging process if you included the ASM sources with the demo.
OK.
http://zgh3000.ik8.com/fc/zapperdemo.rar

Image

Posted: Sun Jun 18, 2006 4:46 pm
by Quietust
Taking a look, I can now see why it was getting graphical glitches on powerup - you must do the...

Code: Select all

	lda #%10000000		
	sta $2000
	lda #%00011110
	sta $2001
...after the "jsr load_palette". Also, you should really be doing...

Code: Select all

	lda #0
	sta $2000
	sta $2001
...immediately after the SEI/CLD at the top of your reset routine.

The reason it doesn't actually detect anything properly is because the Zapper only detects white as it is rendered - in other words, you need to constantly poll $4017 for the entire duration of the frame (and give up if another NMI comes along) and wait if it ever senses white. Evidently, NNNesterJ does not emulate the Zapper with correct timing - the latest build of my emulator (over at http://nintendulator.sourceforge.net/) has reasonably correct behavior (verified against actual hardware) if you want to perform additional testing.

Posted: Sun Jun 18, 2006 5:11 pm
by tepples
Quietust wrote:the Zapper only detects white as it is rendered - in other words, you need to constantly poll $4017 for the entire duration of the frame (and give up if another NMI comes along) and wait if it ever senses white.
Constantly meaning that it fades after how many cycles? Is polling once a scanline enough, or should I unroll the loop to poll once every 6 CPU clocks for a scanline at a time? And does "only detects white" mean that it will return false for lighter colors such as $10 and $31-$3C?

Posted: Sun Jun 18, 2006 5:23 pm
by Quietust
1. Once a scanline should be enough, since that's approximately how often the Zapper updates the read signal.
2. Light colors will also trigger it, but for a shorter period of time (normally, if you aim the zapper at a solid white screen, it will register a hit for about 25 scanlines or so).

Posted: Sat Jul 15, 2006 4:19 am
by zgh4000
No wrong-ray gun demonstration

http://zgh3000.ik8.com/fc/new_zapper.zip

Nintendulator
Nestopia