Zapper: Difference between revisions

From NESdev Wiki
Jump to navigationJump to search
(Quicker to check for light during vblank than to turn off the whole screen. Zap Ruder does this, for example.)
m (thinko)
Line 14: Line 14:
The proper way to implement Zapper support in a game is as follows:
The proper way to implement Zapper support in a game is as follows:
# Each frame, check if the player has pulled the trigger. Remain in this step until the trigger is pulled.
# Each frame, check if the player has pulled the trigger. Remain in this step until the trigger is pulled.
# During vertical blanking, verify that the light gun is ''not'' detecting light, to ensure that the player is actually pointing the gun at the screen. If bit 3 is set during vblank, a [[standard controller]] is probably plugged in.
# During vertical blanking, verify that the light gun is ''not'' detecting light, to ensure that the player is actually pointing the gun at the screen. If bit 3 is false during vblank, a [[standard controller]] is probably plugged in.
# Optional: Turn the entire screen white or display white boxes on all targets, and use timed code to wait for the Zapper to start detecting light in order to see how far down the screen the Zapper is pointed. This can reduce the number of targets that must be checked in the next step.
# Optional: Turn the entire screen white or display white boxes on all targets, and use timed code to wait for the Zapper to start detecting light in order to see how far down the screen the Zapper is pointed. This can reduce the number of targets that must be checked in the next step.
# For each target the player may hit, display a black screen with a single white box at the target's location. Wait the entire frame to check if white is ever detected - if it is, register a 'hit' within the game; if not, move on to the next target or, if there are no additional targets, register a 'miss' within the game.
# For each target the player may hit, display a black screen with a single white box at the target's location. Wait the entire frame to check if white is ever detected - if it is, register a 'hit' within the game; if not, move on to the next target or, if there are no additional targets, register a 'miss' within the game.

Revision as of 21:05, 3 October 2011

The Zapper is a light gun, often associated with the game "Duck Hunt". It reads light from a CRT SDTV and sends the brightness of the area where it is pointed on the controller port.

The Zapper can be used in either controller port, though most games will only allow you to use it in controller port #2, leaving port #1 for a standard controller used for navigating through options.

Output ($4016/$4017 read)

7  bit  0
---- ----
xxxT Wxxx
   | |
   | +---- Light sense (0: detected; 1: not detected)
   +------ Trigger (0: released; 1: pulled)

The proper way to implement Zapper support in a game is as follows:

  1. Each frame, check if the player has pulled the trigger. Remain in this step until the trigger is pulled.
  2. During vertical blanking, verify that the light gun is not detecting light, to ensure that the player is actually pointing the gun at the screen. If bit 3 is false during vblank, a standard controller is probably plugged in.
  3. Optional: Turn the entire screen white or display white boxes on all targets, and use timed code to wait for the Zapper to start detecting light in order to see how far down the screen the Zapper is pointed. This can reduce the number of targets that must be checked in the next step.
  4. For each target the player may hit, display a black screen with a single white box at the target's location. Wait the entire frame to check if white is ever detected - if it is, register a 'hit' within the game; if not, move on to the next target or, if there are no additional targets, register a 'miss' within the game.
  5. Restore the screen to its original state.