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

SuperFX 3D — auto-rotating wireframe cube (2-axis rotation). More...

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

Functions

void buildEdges (void)
 Build edge buffer from projected vertices.
int main (void)
void rotateVertex (u16 idx)
 Rotate one vertex, store projected screen coords (clamped).
void vtimer_irq (void)
void writeEdgesToSRAM (void)

Variables

static const u8 ce []
static const u16 cube_pal []
static const s16 cvx [] = {-25, 25, 25,-25,-25, 25, 25,-25}
static const s16 cvy [] = {-25,-25, 25, 25,-25,-25, 25, 25}
static const s16 cvz [] = {-25,-25,-25,-25, 25, 25, 25, 25}
u8 edge_buffer [48]
s16 g_cax
s16 g_cay
u8 g_px [8]
u8 g_py [8]
s16 g_sax
s16 g_say
const u8 gsu_program []
u16 irq_ticks
static const s8 sin_tab [256]

Detailed Description

SuperFX 3D — auto-rotating wireframe cube (2-axis rotation).

Demonstrates GSU (SuperFX) coprocessor execution. The 65816 sets up a Mode 1 bitmap framebuffer in VRAM, then hands control to a small GSU program (compiled separately by wla-superfx) that rotates a cube's 8 vertices via the GSU's hardware sine LUT and writes the edge bytes into SRAM. The 65816 streams those edge bytes back to VRAM each frame via DMA. The result: a smoothly rotating 3D wireframe entirely driven by the GSU.

SNES Concepts
  • GSU launch via gsuLaunch() (gsuRun + cache prefetch)
  • GSU ↔ 65816 communication via SRAM as shared scratch
  • DMA full-frame transfer from SRAM to VRAM each frame
  • HDMA-driven force-blank during transfer (gsuSetupHdmaBlanking)
What to Observe
  • A wireframe cube rotates continuously on two axes (X and Y).
  • No input — the rotation is autonomous; reset to restart from the initial angle.
  • GSU presence is detected via the ROM header bits; luna (the SDK's emulator) and bsnes run it (snes9x's GSU detection is unreliable on our header layout).
  • A V-timer IRQ stays armed through GSU jobs (vtimer_irq, irq_ticks).
Modules Used
console, sprite, dma, background, input, superfx
See also
superfx.h, dma.h, background.h

Function Documentation

◆ buildEdges()

void buildEdges ( void )

Build edge buffer from projected vertices.

◆ main()

int main ( void )

◆ rotateVertex()

void rotateVertex ( u16 idx)

Rotate one vertex, store projected screen coords (clamped).

◆ vtimer_irq()

void vtimer_irq ( void )
extern

◆ writeEdgesToSRAM()

void writeEdgesToSRAM ( void )
extern

Variable Documentation

◆ ce

const u8 ce[]
static
Initial value:
= {
0,1, 1,2, 2,3, 3,0, 4,5, 5,6, 6,7, 7,4, 0,4, 1,5, 2,6, 3,7,
}

◆ cube_pal

const u16 cube_pal[]
static
Initial value:
= {
RGB(0,0,4), RGB(0,0,10), RGB(0,0,16), RGB(0,0,24),
RGB(0,10,31), RGB(0,20,31), RGB(0,31,31), RGB(0,31,16),
RGB(16,31,0), RGB(31,31,0), RGB(31,16,0), RGB(31,0,0),
RGB(31,0,16), RGB(31,0,31), RGB(20,20,20), RGB(31,31,31),
}
#define RGB(r, g, b)
Create RGB color value.
Definition video.h:88

◆ cvx

const s16 cvx[] = {-25, 25, 25,-25,-25, 25, 25,-25}
static

◆ cvy

const s16 cvy[] = {-25,-25, 25, 25,-25,-25, 25, 25}
static

◆ cvz

const s16 cvz[] = {-25,-25,-25,-25, 25, 25, 25, 25}
static

◆ edge_buffer

u8 edge_buffer[48]
extern

◆ g_cax

s16 g_cax

◆ g_cay

s16 g_cay

◆ g_px

u8 g_px[8]

◆ g_py

u8 g_py[8]

◆ g_sax

s16 g_sax

◆ g_say

s16 g_say

◆ gsu_program

const u8 gsu_program[]
extern

◆ irq_ticks

u16 irq_ticks
extern

◆ sin_tab

const s8 sin_tab[256]
static
Initial value:
= {
0, 3, 6, 9, 12, 16, 19, 22, 25, 28, 31, 34, 37, 40, 43, 46,
49, 51, 54, 57, 60, 63, 65, 68, 71, 73, 76, 78, 81, 83, 85, 88,
90, 92, 94, 96, 98, 100, 102, 104, 106, 107, 109, 111, 112, 113, 115, 116,
117, 118, 120, 121, 122, 122, 123, 124, 125, 125, 126, 126, 126, 127, 127, 127,
127, 127, 127, 127, 126, 126, 126, 125, 125, 124, 123, 122, 122, 121, 120, 118,
117, 116, 115, 113, 112, 111, 109, 107, 106, 104, 102, 100, 98, 96, 94, 92,
90, 88, 85, 83, 81, 78, 76, 73, 71, 68, 65, 63, 60, 57, 54, 51,
49, 46, 43, 40, 37, 34, 31, 28, 25, 22, 19, 16, 12, 9, 6, 3,
0, -3, -6, -9, -12, -16, -19, -22, -25, -28, -31, -34, -37, -40, -43, -46,
-49, -51, -54, -57, -60, -63, -65, -68, -71, -73, -76, -78, -81, -83, -85, -88,
-90, -92, -94, -96, -98,-100,-102,-104,-106,-107,-109,-111,-112,-113,-115,-116,
-117,-118,-120,-121,-122,-122,-123,-124,-125,-125,-126,-126,-126,-127,-127,-127,
-127,-127,-127,-127,-126,-126,-126,-125,-125,-124,-123,-122,-122,-121,-120,-118,
-117,-116,-115,-113,-112,-111,-109,-107,-106,-104,-102,-100, -98, -96, -94, -92,
-90, -88, -85, -83, -81, -78, -76, -73, -71, -68, -65, -63, -60, -57, -54, -51,
-49, -46, -43, -40, -37, -34, -31, -28, -25, -22, -19, -16, -12, -9, -6, -3,
}