Repository navigation
superdevkit 0.10.0
This is still an alpha release. It works for me, that doesn't necessarily mean it works for you at the moment. Sorry 😔.
superdevkit is a development kit for SNES games written in C. You write a game once, and it builds as a ROM for the Super Nintendo, a program for Linux and Windows, and a page for the browser. It comes with dampf, its own C compiler for the SNES's 65816 CPU.
Play the example games in your browser · Read the book
Download
| Your system | File |
|---|---|
| Windows (x64) | superdevkit-0.10.0-windows-x64.zip |
| Linux or WSL (x64) | superdevkit-0.10.0-linux-x64.zip |
Each zip brings its own Java, so you don't need to install one.
Your first ROM
On Windows, in PowerShell, in the folder with the zip:
Expand-Archive superdevkit-0.10.0-windows-x64.zip .
$env:Path = "$PWD\superdevkit-0.10.0\bin;$env:Path"
superdevkit init mygame
cd mygame
superdevkit build snesOn Linux or WSL:
unzip superdevkit-0.10.0-linux-x64.zip
export PATH="$PWD/superdevkit-0.10.0/bin:$PATH"
superdevkit init mygame
cd mygame
superdevkit build snesThe ROM is build/snes/mygame.sfc. Getting started goes on from there.
What each target needs
| Target | Command | You need |
|---|---|---|
| SNES | superdevkit build snes |
nothing else (an emulator such as MesenCE to play the ROM) |
| Windows | superdevkit build win64 |
Visual Studio with "Desktop development with C++" |
| Linux | superdevkit build linux |
a C compiler and the OpenGL and X11 development libraries |
| Web | superdevkit build web |
the Emscripten SDK, with emcc on the PATH |
New in 0.10.0
This release concludes milestone M10. A game can now run C code in interrupts, dampf links
hand-written assembly into optimized code, and the console API is new. Games written for 0.9
need changes: see What a game written for 0.9 must change.
The console API
- The core,
sdevkit/snes.h, is the hardware at once. Every PPU register is written with
sdevkit_reg_writeandsdevkit_reg_write_twice, which dampf turns into one store each.
Copies into VRAM, CGRAM and OAM go by DMA (sdevkit_dma,sdevkit_vram_copy,
sdevkit_cgram_copy,sdevkit_oam_copyand others), and HDMA hassdevkit_hdma_setand
sdevkit_hdma_enable. Macros build the registers' values (SDEVKIT_BGSC,SDEVKIT_OBSEL,
SDEVKIT_OAM_ATTR, ...). - The kit writes nothing in the vertical blank by itself. The main loop no longer copies the
sprite table, so the whole vertical blank belongs togame_vblank. - Optional layers sit above the core, and a game pays only for the ones it calls:
sdevkit/shadow.h(the registers in memory),sdevkit/sprites.h(a sprite list),
sdevkit/queue.h(copies queued in the tick, with a budget),sdevkit/input.h(the buttons
pressed since the last tick), andsdevkit/easy.h, which brings all of them and one
sdevkit_commit()forgame_vblank. - dampf leaves out the functions a program never reaches, so the layers a game does not use cost
it nothing. The examples' code got 4 to 48 % smaller. - The desktop check fails on a PPU register or an HDMA channel written while the picture is
drawn, as it already did for bytes written to VRAM, CGRAM or OAM then. Switching the screen
off is allowed at any time.
The book's console API reference
lists every call with its cost in cycles.
Interrupts
- The game's IRQ (
sdevkit/irq.h). The game defines
DAMPF_INTERRUPT(irq) void game_irq(void)and callssdevkit_irq_line(row). The handler then
runs before that row of the picture, on the SNES and on the desktop and the web. It reads its
data, callssdevkit_irq_wait_hblank(), and has about 25 CPU cycles for its register writes,
enough for a scroll split. The desktop check fails on a write before the wait. The handler can
set the next row itself, for several splits a frame. - Data for interrupt code (
sdevkit/publish.h).SDEVKIT_PUBLISH(type, name, tick, vblank)
declares one struct the tick writes and definesgame_tickandgame_vblank, which call the
game's owntickandvblankand copy the struct after the tick. Interrupt code reads
it throughSDEVKIT_PUBLISHED(name)and always gets the data of the tick the picture on the
screen was made from, whole. The copy costs about 10.5 CPU cycles per byte and tick. - The kit's NMI. A game that publishes gets its
vblankfunction run in every vertical
blank by the kit's NMI, also while a tick takes longer than a frame. A game that does not
publish keepsgame_vblankin the loop, as before. - C in interrupt handlers.
DAMPF_INTERRUPT(irq)gives a handler frames and a direct page
of its own, so it never overwrites the locals of the code it interrupted; the kit's NMI is
built the same way. A function that both the main code and a handler call is compiled once for each.
Interrupt code multiplies in software, since the CPU's multiplier cannot be saved. The timing
report has a line for each handler.
dampf
- Hand-written assembly with the optimizing code generator:
DAMPF_ASM("file.s")after a C
function's parameter list links the assembly in place of the compiled body. dampf reads the
assembly for its cycles and its safety checks, and checks it against the C body in every
build.--replace fn=file.sdoes the same from the command line. Interrupt code cannot call
an assembly function yet. switchas a jump table where that costs fewer cycles than the compares: from 4 to 7
cases, depending on the range check.- A constant on an index goes into the address (
a[i + 1]issta a+1,x): the examples
do 0.7 % less work. - Warnings where gcc warns by default, starting with
-Woverflow: a constant that does not
fit the type it initialises or is assigned to (uint8_t w[] = { 420 }). Warnings do not stop
the build. --lib FILE-OR-FOLDERnames a library's sources. They are compiled into the program, but
the-Ddefines do not reach them.superdevkit build snespasses the kit'slib/snesthis
way.
What a game written for 0.9 must change
- The console API. The PVSnesLib-style calls are gone:
sdevkit_set_mode,
sdevkit_bg_set_scroll,sdevkit_oam_set,sdevkit_dma_copy_vramand the rest. Write the
registers withsdevkit_reg_write, copy with the core's copies (the destination comes first
now:sdevkit_vram_copy(address, source, bytes)), or move to the layers. A game that relied
on the loop copying its sprite table copies it ingame_vblank(sdevkit_oam_copy), or uses
sdevkit/sprites.h. The rename scripttools/sdevkit_rename.pyis gone, since its target
names are gone. The seven examples show both ways: Mode 7, Mandelbrot, Steinschlag and Er-Tüp
use the core, Hello, Schach and CatchMe the layers. - Plain
charis for text only. Acharcan be copied, tested for zero, compared with==
and!=against anothercharor a constant from 0 to 127, and converted to another 8-bit
type. Arithmetic, ordering, shifts and widening acharare errors now, since their result
depends on whethercharis signed. The message says what to write instead; usually that is
uint8_t, or a cast(uint8_t)cfirst ((uint8_t)c - '0'for a digit). - An enum object takes only values of its enum: its enumerators, or another value of the
same enum type.++,--and compound assignment on it are errors, and so is a cast to the
enum from anything else. In return dampf stores it in the smallest width that holds its
values, usually one byte. - Defines in
superdevkit.tomlno longer reach the kit's library on the SNES, as on the
desktop and the web. A game that set a define forlib/snescannot do that any more.
What the files dampf writes add
- Labels for the copies of a function per interrupt context, such as
__irq_clamp, in the
assembly, the timing report and Mesen's debug file. - The timing report's lines
dampf_irqanddampf_nmi, the entry code and the handler's cycles. - The desktop and web builds generate
game_interrupts.c, which tells Rachael whether the game
has an IRQ handler or the kit's NMI. - Functions a program never reaches are no longer in the ROM, the listing or the timing report.
Known limits
- Music plays on the desktop and the web, but not yet on the SNES. Sound effects and save RAM work there.
- The kit has been tested in emulators, not on a real SNES.
- The C subset, the command line and the files dampf writes may change before 1.0.
- The games on the website need a keyboard.
Licences
superdevkit is under the Apache License 2.0 with LLVM Exceptions. The zips include an unmodified OpenJDK runtime (Eclipse Temurin 25.0.5+8, GPL v2 with the Classpath Exception, source) and raylib 5.5 (zlib licence). NOTICE in each zip has the details.
superdevkit is an independent project, not affiliated with or endorsed by Nintendo.
Full changelog: v0.9.2...v0.10.0