SNES mouse input with cursor sprite, buttons, and sensitivity.
Demonstrates the SNES Mouse peripheral connected to controller port 1. The SNES mouse is a standard serial device that reports relative X/Y deltas and two buttons each frame via the auto-joypad read registers. This example accumulates the deltas into absolute screen coordinates and drives a 16x16 hardware sprite as a cursor.
The mouse supports three sensitivity levels (low, medium, high) that scale the delta values. Sensitivity is toggled by right-clicking. If no mouse is detected at startup, a diagnostic message is shown.
- SNES Concepts
- Mouse peripheral detection and initialization via auto-joypad
- Relative-to-absolute coordinate accumulation from mouse deltas
- Sensitivity control (hardware-level scaling of mouse movement)
- Sprite used as a cursor overlay on a text background
- What to Observe
- A 16x16 cursor sprite follows mouse movement on screen
- Left click changes the background color to blue
- Right click cycles sensitivity (LOW / MED / HIGH)
- Button states ("PRESSED") appear next to L-click / R-click labels
- Without a mouse connected, a "No mouse detected" message appears
- Modules Used
- console, input, sprite, dma, text, background
- See also
- input.h, sprite.h, dma.h, text.h
Main entry point – mouse detection, initialization, and input loop.
Sets up Mode 0 with a text background for status display and a 16x16 hardware sprite as a mouse cursor. The mouse is detected via mouseInit() on port 1. If absent, the program halts with a diagnostic message. Otherwise, the main loop reads relative mouse deltas each frame, accumulates them into absolute screen coordinates, and updates the cursor sprite position and button/sensitivity status on screen.
- Returns
- 0 (never reached – infinite game loop)