|
| static void | build_border (u8 top, u8 bottom, u8 left, u8 right) |
| | Build one 9-slice border tile: border on the named edges, fill else.
|
| static void | build_heart (u8 filled) |
| | Build a heart icon on the box-fill background (filled or outline).
|
| static void | build_scene (void) |
| | A colourful BG1 scene so the HUD clearly floats over content.
|
| static void | build_sheet (void) |
| | Build the whole BG2 sheet: blank, 9-slice, two heart icons.
|
| static void | draw_hearts (void) |
| | Redraw the heart row inside the HUD from hero_hp.
|
| static void | encode_4bpp (void) |
| | Pack px[] (8x8 palette indices) into a 4bpp planar tile.
|
| static void | flush_hud_row (void) |
| | Push ONLY the HUD's heart row to VRAM — a small VBlank-safe DMA.
|
| int | main (void) |
| static void | put_tile (u16 tile) |
| | Upload the just-encoded tile to a tile slot in BG2's char space.
|
Game math & UI, rung — panel HUD: a status box that survives a dialog.
Every game needs furniture: a status bar with hearts and a coin count, a dialog box that opens over the world and closes again. Both are the same primitive — a 9-slice panel, a bordered box stamped from a 3x3 tile sheet (four corners, four edges, one fill) onto a background layer. The panel module does the stamping; you own the tilemap.
Its whole point is on show here: the HUD and the dialog live in ONE tilemap on ONE layer. Opening the dialog (panelDraw + panelFlush) and closing it (panelClear + panelFlush) never disturbs the HUD.
panelFlush() uploads the whole 2 KB map under FORCED BLANK, which briefly blanks the screen — fine for a structural change like a dialog box, but far too heavy to run every time a heart changes. So the hearts, which change often, upload only their own 64-byte tilemap row with an ordinary VBlank DMA (flush_hud_row) — no forced blank, no flicker. The rule: panelFlush for structure, a small VBlank DMA for frequent HUD tweaks.
The border and heart icons are generated in C — zero assets. Tile 0 is left transparent (that is what panelInit() stamps everywhere), so the colourful BG1 shows through wherever no panel has been drawn.
ROM mode: LoROM (project default).
- Controls
- B: lose a heart · A: gain one (small VBlank DMA of the heart row)
- START: toggle the dialog box (panelFlush; the HUD stays put)
- SNES Concepts
- 9-slice stamping: panelDraw() picks corner/edge/fill from the sheet by position; panelPut() drops a single sheet tile (an icon) into the box
- Several panels, one layer, one upload — the module's reason to exist
- panelFlush() uploads under real forced blank (INIDISP bit 7): safe for 2 KB but it blanks briefly, so use it for structural changes; push a frequently-updated HUD row with a small ordinary VBlank DMA instead
- What to Observe
- A HUD box with hearts sits over a colourful background. A/B change the hearts; START opens/closes a dialog box lower down without touching the HUD. hero_hp and dialog_shown are the probe oracles.
- Modules Used
- console, dma, background, panel, input
- See also
- lib/include/snes/panel.h — panelInit/Draw/Put/Clear/Flush