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

16.16 fixed-point orbit demo (B5 capstone) More...

#include <snes.h>
#include <snes/fixed32.h>

Functions

int main (void)

Variables

fixed32 g_angle
u8 g_angle8
fixed32 g_omega
fixed32 g_radius
s16 g_sx
s16 g_sy
static const u8 orbiter_pal [4]
static const u8 orbiter_tile [32]

Detailed Description

16.16 fixed-point orbit demo (B5 capstone)

A single 8x8 sprite orbits the screen centre. The orbit is driven entirely by the lib's <snes/fixed32.h> API — fix32Sin, fix32Cos, fix32Mul, plus straight Kl arithmetic on fixed32 accumulators.

What this example demonstrates

  • fixed32 (s32 16.16) for an angle accumulator that stays smooth across many frames without 8.8 rounding drift.
  • fix32Sin / fix32Cos lifted from the 8.8 LUT to 16.16 (8 bits of fractional precision, ~25 cycles each — adequate for sub-pixel animation).
  • fix32Mul(radius, fix32Cos(angle)) as the canonical pattern for trig-driven motion: a radius * sin/cos term used in every 2D game that needs aim/orbit/parallax-around-a-point.

Inputs / interaction

None — the sprite orbits autonomously. The example is structured as the simplest possible fixed32 fixture; later examples (likemario, aim_target, breakout) compose the same primitives into game logic.

Modules Used
console, sprite, dma, background, fixed32, math

Function Documentation

◆ main()

int main ( void )

Variable Documentation

◆ g_angle

fixed32 g_angle

◆ g_angle8

u8 g_angle8

◆ g_omega

fixed32 g_omega

◆ g_radius

fixed32 g_radius

◆ g_sx

s16 g_sx

◆ g_sy

s16 g_sy

◆ orbiter_pal

const u8 orbiter_pal[4]
static
Initial value:
= {
0x00, 0x00,
0xFF, 0x7F,
}

◆ orbiter_tile

const u8 orbiter_tile[32]
static
Initial value:
= {
0xFF, 0, 0xFF, 0, 0xFF, 0, 0xFF, 0,
0xFF, 0, 0xFF, 0, 0xFF, 0, 0xFF, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
}