Loading...
Searching...
No Matches
main.c File Reference

Scene stack demo — title → counter → pause overlay. More...

#include <snes.h>
#include <snes/text.h>
#include <snes/scene.h>

Functions

static void counter_init (void)
 
static void counter_update (void)
 
int main (void)
 Hand control to the scene framework. Never returns.
 
static void pause_init (void)
 
static void pause_update (void)
 
static void title_init (void)
 
static void title_update (void)
 

Variables

static const Scene counter_scene
 Counter screen — increments a number every frame.
 
static u16 counter_value
 Counter value, lives across pause/resume because counter's init runs once on push, not on every resume.
 
static const Scene pause_scene
 Pause overlay — freezes the counter, waits for Select to resume.
 
static const Scene title_scene
 Title screen — waits for Start to begin, no game state.
 

Detailed Description

Scene stack demo — title → counter → pause overlay.

Demonstrates the opt-in scene framework: the running game is split into three Scene structs that push and pop without a hand-rolled state machine. The demo is deliberately minimal — three text screens that swap when buttons are pressed — so you can read the dispatch shape without graphics noise getting in the way.

Flow:

  1. title scene: shows "PRESS START". Start pushes counter.
  2. counter scene: increments a number every frame. Select pushes pause (counter is suspended; numbers stop). Start pops back to title.
  3. pause scene: shows "PAUSED". Select pops back to counter (numbers resume from where they stopped, no init replay).
SNES Concepts
  • Scene stack: push/pop without enum + switch boilerplate
  • init runs once on first push; resume after pop does not re-init
  • Suspended scenes get no callbacks (pause overlay = counter frozen)
  • Text rendering through the auto-flush NMI hook
What to Observe
  • Start on title: enters counter, numbers increment from 0
  • Select while counting: PAUSED appears, numbers freeze
  • Select in pause: counter resumes, numbers continue from where they stopped (no reset — init was not re-called)
  • Start while counting: pops back to title (counter discarded; pressing Start again restarts from 0 because counter's init re-runs on the next push)
Modules Used
console, sprite, dma, background, text, input, scene
See also
scene.h, gameloop.h

Function Documentation

◆ counter_init()

static void counter_init ( void  )
static

◆ counter_update()

static void counter_update ( void  )
static

◆ main()

int main ( void  )

Hand control to the scene framework. Never returns.

◆ pause_init()

static void pause_init ( void  )
static

◆ pause_update()

static void pause_update ( void  )
static

◆ title_init()

static void title_init ( void  )
static

◆ title_update()

static void title_update ( void  )
static

Variable Documentation

◆ counter_scene

const Scene counter_scene
static
Initial value:
= {
.init = counter_init,
.update = counter_update,
}
static void counter_init(void)
Definition main.c:96
static void counter_update(void)
Definition main.c:104

Counter screen — increments a number every frame.

◆ counter_value

u16 counter_value
static

Counter value, lives across pause/resume because counter's init runs once on push, not on every resume.

◆ pause_scene

const Scene pause_scene
static
Initial value:
= {
.init = pause_init,
.update = pause_update,
}
static void pause_init(void)
Definition main.c:123
static void pause_update(void)
Definition main.c:127

Pause overlay — freezes the counter, waits for Select to resume.

◆ title_scene

const Scene title_scene
static
Initial value:
= {
.init = title_init,
.update = title_update,
}
static void title_init(void)
Definition main.c:79
static void title_update(void)
Definition main.c:87

Title screen — waits for Start to begin, no game state.