OpenSNES
Modern Open-Source SNES Development SDK
Loading...
Searching...
No Matches
screen.c File Reference

The screen layer (see screen.h). More...

#include <snes.h>
#include <snes/input.h>
#include <snes/vramqueue.h>
#include "screen.h"

Macros

#define FADE_SPEED   1
 Frames between two brightness steps: 16 steps, so 16 images a fade.

Functions

static void fade (u8 direction)
 Run a fade a step per image. Never the blocking fadeIn()/fadeOut(): the pump must not freeze during a transition.
static void primePads (void)
 Take the pads as they are now as "already held": a key held over a screen change does not count.
static void pump (void)
 Run the pump. A rule of the layer: nothing waits without calling it.
static void readPads (void)
 Read both pads; the old words become the "before".
void screenClose (void)
 Non-blocking fade-out, display off, then the close hook.
void screenFadeSkip (u16 on)
 1: skip the fades; 0: play them for real.
void screenFrame (void)
 One image of a lit screen: VBlank, queue flush, pump, pads.
void screenLoad (const u8 *src, u16 addr, u16 size, u16 step)
 Upload a block to VRAM through the queue, in pieces that keep to SCREEN_VBLANK_BUDGET.
u16 screenPressed (u16 keys, u16 both)
 Keys newly pressed this image, among keys; both also reads pad 2.
void screenSetClose (void(*fn)(void))
 Hook run by screenClose(): undoes what the screen set up. One shot.
void screenSetPump (void(*fn)(void))
 Function run on EVERY image: fades, waits, loads and frames. No state is passed.
void screenShow (void)
 Display on, non-blocking fade-in; a key already held does not count.
u16 screenWait (u16 frames)
 Wait frames images or START; 1 if START cut it short.

Variables

static void(* close_fn )(void)
 The hook of the screen on display, or 0.
static u16 held0
 Pad words of this image and of the one before (the edges come from the pair).
static u16 held1
static u16 prev0
static u16 prev1
static void(* pump_fn )(void)
 The function run on every image, or 0.
u16 screen_fade_frames
 Images the last fade took (16 at speed 1), for the tests.
u16 screen_fade_skip
 1: the fades are skipped (long tests). 0 by default. A test may poke it.

Detailed Description

The screen layer (see screen.h).

Macro Definition Documentation

◆ FADE_SPEED

#define FADE_SPEED   1

Frames between two brightness steps: 16 steps, so 16 images a fade.

Function Documentation

◆ fade()

void fade ( u8 direction)
static

Run a fade a step per image. Never the blocking fadeIn()/fadeOut(): the pump must not freeze during a transition.

◆ primePads()

void primePads ( void )
static

Take the pads as they are now as "already held": a key held over a screen change does not count.

◆ pump()

void pump ( void )
static

Run the pump. A rule of the layer: nothing waits without calling it.

◆ readPads()

void readPads ( void )
static

Read both pads; the old words become the "before".

◆ screenClose()

void screenClose ( void )

Non-blocking fade-out, display off, then the close hook.

◆ screenFadeSkip()

void screenFadeSkip ( u16 on)

1: skip the fades; 0: play them for real.

◆ screenFrame()

void screenFrame ( void )

One image of a lit screen: VBlank, queue flush, pump, pads.

◆ screenLoad()

void screenLoad ( const u8 * src,
u16 addr,
u16 size,
u16 step )

Upload a block to VRAM through the queue, in pieces that keep to SCREEN_VBLANK_BUDGET.

◆ screenPressed()

u16 screenPressed ( u16 keys,
u16 both )

Keys newly pressed this image, among keys; both also reads pad 2.

◆ screenSetClose()

void screenSetClose ( void(* fn )(void))

Hook run by screenClose(): undoes what the screen set up. One shot.

◆ screenSetPump()

void screenSetPump ( void(* fn )(void))

Function run on EVERY image: fades, waits, loads and frames. No state is passed.

◆ screenShow()

void screenShow ( void )

Display on, non-blocking fade-in; a key already held does not count.

◆ screenWait()

u16 screenWait ( u16 frames)

Wait frames images or START; 1 if START cut it short.

Variable Documentation

◆ close_fn

void(* close_fn) (void) ( void )
static

The hook of the screen on display, or 0.

◆ held0

u16 held0
static

Pad words of this image and of the one before (the edges come from the pair).

◆ held1

u16 held1
static

◆ prev0

u16 prev0
static

◆ prev1

u16 prev1
static

◆ pump_fn

void(* pump_fn) (void) ( void )
static

The function run on every image, or 0.

◆ screen_fade_frames

u16 screen_fade_frames

Images the last fade took (16 at speed 1), for the tests.

◆ screen_fade_skip

u16 screen_fade_skip

1: the fades are skipped (long tests). 0 by default. A test may poke it.