SNES Super Scope light gun detection, calibration, and firing. More...
#include <snes.h>#include <snes/input.h>#include <snes/text.h>#include <snes/dma.h>#include "res/aim_adjust_target.inc"#include "res/marker.inc"Macros | |
| #define | STATE_CALIBRATE 1 |
| Asking player to shoot screen center for aim offset calibration. | |
| #define | STATE_DETECT 0 |
| Aim target background tile data (2bpp, crosshair pattern), converted by the build from res/. | |
| #define | STATE_READY 2 |
| Calibrated and tracking fire events; placing impact markers. | |
Functions | |
| static void | clearBottom (void) |
| Clear the bottom 4 rows of the text overlay (rows 24-27). | |
| static void | hideDot (void) |
| Hide the impact marker sprite by moving it off-screen. | |
| int | main (void) |
| Main entry point – Super Scope detection, calibration, and fire tracking. | |
| static void | showDot (u16 x, u16 y) |
| Show the impact marker at the given screen coordinates. | |
SNES Super Scope light gun detection, calibration, and firing.
Demonstrates the SNES Super Scope (light gun) peripheral connected to controller port 2. The Super Scope works by detecting the CRT beam position when the trigger is pulled, returning X/Y screen coordinates via the auto-joypad registers. Because the sensor relies on CRT timing, a calibration step is needed to correct for aiming offset.
The example uses a three-state machine: DETECT waits for the Super Scope to be connected, CALIBRATE asks the player to shoot the screen center so the library can compute the aim offset, and READY tracks fire events and marks the hit position with an impact marker sprite.
Video setup: Mode 0 with BG1 (text overlay) and BG2 (the calibration target of the security range), plus an OBJ sprite for the impact marker.
| #define STATE_CALIBRATE 1 |
Asking player to shoot screen center for aim offset calibration.
| #define STATE_DETECT 0 |
Aim target background tile data (2bpp, crosshair pattern), converted by the build from res/.
Aim target tilemap (32x32 BG2 layout), converted by the build from res/
Aim target palette (BGR555), converted by the build from res/
Sprite tile data (impact marker, 4bpp), converted by the build from res/
Sprite palette (BGR555), converted by the build from res/
Waiting for Super Scope to be connected to port 2
| #define STATE_READY 2 |
Calibrated and tracking fire events; placing impact markers.
|
static |
Clear the bottom 4 rows of the text overlay (rows 24-27).
Used to erase status messages when transitioning between states (detect, calibrate, ready).
|
static |
Hide the impact marker sprite by moving it off-screen.
Y coordinate OAM_Y_OFFSCREEN (224) is below the NTSC visible area, so the SNES PPU will not render this sprite. This is cheaper than disabling the sprite via the OAM high table.
| int main | ( | void | ) |
Main entry point – Super Scope detection, calibration, and fire tracking.
Implements a three-state machine:
The fire_armed flag prevents stale FIRE events from the previous state from triggering immediately on state entry.