SNES Super Scope light gun detection, calibration, and firing. More...
Macros | |
| #define | STATE_CALIBRATE 1 |
| Asking player to shoot screen center for aim offset calibration. | |
| #define | STATE_DETECT 0 |
| Waiting for Super Scope to be connected to port 2. | |
| #define | STATE_READY 2 |
| Calibrated and tracking fire events; placing red dot markers. | |
Functions | |
| static void | clearBottom (void) |
| Clear the bottom 4 rows of the text overlay (rows 24-27). | |
| static void | hideDot (void) |
| Hide the red dot 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 red dot marker at the given screen coordinates. | |
Variables | |
| u8 | aim_target_map [] |
| Aim target tilemap (32x32 BG2 layout) from data.asm. | |
| u8 | aim_target_map_end [] |
| u8 | aim_target_pal [] |
| Aim target palette (BGR555) from data.asm. | |
| u8 | aim_target_pal_end [] |
| u8 | aim_target_tiles [] |
| Aim target background tile data (2bpp, crosshair pattern) from data.asm. | |
| u8 | aim_target_tiles_end [] |
| u8 | sprites_pal [] |
| Sprite palette (BGR555) from data.asm. | |
| u8 | sprites_pal_end [] |
| u8 | sprites_tiles [] |
| Sprite tile data (red dot marker, 4bpp) from data.asm. | |
| u8 | sprites_tiles_end [] |
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 a red dot sprite.
Video setup: Mode 0 with BG1 (text overlay) and BG2 (crosshair target background for calibration), plus OBJ sprites for the red dot marker.
| #define STATE_CALIBRATE 1 |
Asking player to shoot screen center for aim offset calibration.
| #define STATE_DETECT 0 |
Waiting for Super Scope to be connected to port 2.
| #define STATE_READY 2 |
Calibrated and tracking fire events; placing red dot 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 red dot 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.
Show the red dot marker at the given screen coordinates.
Updates sprite 0's X/Y in the OAM low table and signals the NMI handler to DMA the OAM buffer to the PPU next VBlank.
| x | Screen X coordinate (0-255) |
| y | Screen Y coordinate (0-223 for visible area) |
|
extern |
Aim target tilemap (32x32 BG2 layout) from data.asm.
| u8 aim_target_map_end[] |
|
extern |
Aim target palette (BGR555) from data.asm.
| u8 aim_target_pal_end[] |
|
extern |
Aim target background tile data (2bpp, crosshair pattern) from data.asm.
| u8 aim_target_tiles_end[] |
|
extern |
Sprite palette (BGR555) from data.asm.
| u8 sprites_pal_end[] |
|
extern |
Sprite tile data (red dot marker, 4bpp) from data.asm.
| u8 sprites_tiles_end[] |