SNES mouse input with cursor sprite, buttons, and sensitivity. More...
#include <snes.h>#include <snes/input.h>#include <snes/text.h>#include <snes/dma.h>#include "res/cursor.inc"Functions | |
| int | main (void) |
| Main entry point – mouse detection, initialization, and input loop. | |
Variables | |
| static s16 | pos_x |
| Cursor sprite tile data (16x16, 4bpp) defined in data.asm. | |
| static s16 | pos_y |
| Absolute cursor Y position on screen. | |
| static const char | sens_hi [] = "HIGH" |
| Sensitivity label: high speed (largest deltas per physical movement). | |
| static const char | sens_low [] = "LOW " |
| Sensitivity label: low speed (smallest deltas per physical movement). | |
| static const char | sens_med [] = "MED " |
| Sensitivity label: medium speed. | |
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.
| int main | ( | void | ) |
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.
|
static |
Cursor sprite tile data (16x16, 4bpp) defined in data.asm.
Cursor sprite palette (SNES BGR555 format) defined in data.asm
Absolute cursor X position on screen.
Accumulated from relative mouse X deltas each frame. The SNES mouse reports displacement, not position, so we must integrate the deltas ourselves and clamp to the visible screen range (0-255).
|
static |
Absolute cursor Y position on screen.
Same accumulation strategy as pos_x, clamped to 0-223 (NTSC visible).
|
static |
Sensitivity label: high speed (largest deltas per physical movement).
|
static |
Sensitivity label: low speed (smallest deltas per physical movement).
|
static |
Sensitivity label: medium speed.