Both controllers on a terminal's test screen: buttons lit, the edges, a frame counter. More...
#include <snes.h>#include <snes/text.h>#include <snes/gameloop.h>#include "res/screen.inc"#include "res/cast.inc"Classes | |
| struct | Lamp |
| A lamp: the button it shows, its place on a pad's drawing, its tile. More... | |
Macros | |
| #define | LAMPS 14 |
| Number of lamps on a pad: one per button, two per shoulder. | |
| #define | PAD_Y 32 |
| Both pads' top edge (the shoulders). | |
VRAM (word addresses): textModeInit() keeps $0000-$0FFF (font) and $3800 (its map) | |
| #define | OBJ_VRAM 0x4000 |
| #define | SCREEN_MAP 0x3C00 |
| #define | SCREEN_TILES 0x1000 |
The sheet's tiles (res/cast.png, 128 px wide: one row of the sheet is one row of OBJ tiles) | |
| #define | TILE_AVATAR 64 |
| #define | TILE_LAMP 128 |
The bay the avatars walk in: their 32x32 sprites stay inside its outline | |
| #define | BAY_X_MAX 206 |
| #define | BAY_X_MIN 18 |
| #define | BAY_Y_MAX 174 |
| #define | BAY_Y_MIN 154 |
Enumerations | |
| enum | { SOUTH , NORTH , EAST , WEST } |
| Facings, in the sheet's order. More... | |
Functions | |
| static const char * | first_name (u16 mask) |
| The name of the first button set in a mask, for the edges. | |
| int | main (void) |
| Entry point — the game loop runs on_init once, then on_update each frame. | |
| static void | on_init (void) |
| Once, in force blank: the screen, the sheet, the labels. | |
| static void | on_update (void) |
| Every frame: the lamps, the edges, the counter, the avatars. | |
| static void | show_pad (u8 pad) |
| Light pad n's lamps for the buttons held, and print its bitmask. | |
| static void | walk (u8 pad) |
| Walk pad n's avatar with its D-pad, inside the bay. | |
Variables | |
| u16 | avatar_x [2] |
| Probe oracle: each avatar's top-left, x (pad 1, pad 2). | |
| u16 | avatar_y [2] |
| Probe oracle: each avatar's top-left, y (pad 1, pad 2). | |
| static u8 | facing [2] |
| Each avatar's facing (SOUTH, NORTH, EAST, WEST). | |
| static const u16 | key_bit [12] |
| The 12 buttons in the order the pad sends them, for the edges. | |
| static const char *const | key_name [12] |
| Their names, padded to one width so a shorter one covers a longer. | |
| static const Lamp | lamps [14] |
| The lamps of one pad; the drawing has a button under each. | |
| static const u8 | pad_x [2] = { 16, 136 } |
| Each pad's top-left on screen. | |
Both controllers on a terminal's test screen: buttons lit, the edges, a frame counter.
The pad test of a city terminal. The two controllers are drawn on screen, and each button held lights up on its pad's drawing, several at once; under each pad, the bitmask padHeld() returns, in hex. Under them, the last button pressed and the last button released on pad 1, and the number of VBlanks since boot. In the test bay at the bottom, each pad's D-pad walks its avatar: Kit for pad 1, the raccoon for pad 2. This is the starting point for understanding how SNES games read player input, and the screen the console check uses.
The SNES joypad has 12 buttons: 4 face buttons (A, B, X, Y), 2 shoulder buttons (L, R), a D-pad (4 directions), START, and SELECT. The NMI handler reads both joypads automatically every VBlank. Your code just calls padHeld(pad) for the buttons down, padPressed(pad) for the ones that went down on this frame, and padReleased(pad) for the ones that came up.
Ported from PVSnesLib "controller" example by alekmaul; the second pad was the two_players example, the counter the timer example, both merged here.
| #define BAY_X_MAX 206 |
| #define BAY_X_MIN 18 |
| #define BAY_Y_MAX 174 |
| #define BAY_Y_MIN 154 |
| #define LAMPS 14 |
Number of lamps on a pad: one per button, two per shoulder.
| #define OBJ_VRAM 0x4000 |
| #define PAD_Y 32 |
Both pads' top edge (the shoulders).
| #define SCREEN_MAP 0x3C00 |
| #define SCREEN_TILES 0x1000 |
| #define TILE_AVATAR 64 |
pad p's avatar starts at tile 64 p; + 4 per facing
| #define TILE_LAMP 128 |
the four 8x8 lamps: disc, square, pill, half a shoulder
|
static |
The name of the first button set in a mask, for the edges.
| int main | ( | void | ) |
Entry point — the game loop runs on_init once, then on_update each frame.
|
static |
Once, in force blank: the screen, the sheet, the labels.
|
static |
Every frame: the lamps, the edges, the counter, the avatars.
|
static |
Light pad n's lamps for the buttons held, and print its bitmask.
< the four 8x8 lamps: disc, square, pill, half a shoulder
|
static |
Walk pad n's avatar with its D-pad, inside the bay.
< pad p's avatar starts at tile 64 p; + 4 per facing
| u16 avatar_x[2] |
Probe oracle: each avatar's top-left, x (pad 1, pad 2).
| u16 avatar_y[2] |
Probe oracle: each avatar's top-left, y (pad 1, pad 2).
|
static |
Each avatar's facing (SOUTH, NORTH, EAST, WEST).
|
static |
The 12 buttons in the order the pad sends them, for the edges.
|
static |
Their names, padded to one width so a shorter one covers a longer.
|
static |
The lamps of one pad; the drawing has a button under each.
|
static |
Each pad's top-left on screen.