This page follows Super FX: a First Job and assumes a program that builds, launches and returns a result, and covers what changes once the game has to keep running while the GSU works.
When SCMR has RON=1, the GSU owns the ROM bus. The SNES CPU cannot read ROM – not even its own code or its own interrupt vectors. The hardware plans for it: while the GSU owns the ROM, a vector fetch returns a dummy vector — $0108 for NMI, $010C for IRQ, $0104 COP, $0100 BRK/ABORT (Nintendo dev manual Book II §5.4.1) — and a Super FX cartridge keeps a jump at each of those WRAM addresses. The SDK does this for you in every USE_SUPERFX=1 build:
The WRAM handlers and gsuLaunch's wait loop live in the RAM code window (below): a Super FX build reserves 768 bytes of it for the SDK on top of your own RAM_CODE_SIZE. crt0 installs the four stubs before it enables the NMI.
The NMI is not disabled during a job, so no VBlank is lost while the GSU runs, and an H/V-timer IRQ the game has armed stays armed.
gsuLaunch() waits in WRAM for the whole job, because a GSU running its program from ROM owns the ROM. A program that fits in the GSU's 512-byte code cache does not need the ROM: loaded there by the CPU and started from the cache, the GSU keeps running with RON = 0, and the CPU carries on with its own code in ROM (Nintendo dev manual Book II §6.1.2: a program in the cache "will not stop" when RON is 0, "it becomes possible to access the game pak ROM or RAM from the Super NES CPU"; §6.8.4 for loading the cache from the CPU).
gsuCacheLoad() stops the GSU (which empties the cache), copies the code to $3100 and pads the last 16-byte line with NOP, as krom's cache-injection test does. gsuStartCached() writes your gsu_cfgr / gsu_scbr / gsu_scmr, with RON forced to 0, then R15, which starts the GSU.
What such a program may not do:
If gsu_scmr grants the Game Pak RAM to the GSU (RAN, needed for PLOT and STW), the CPU must not touch $70:xxxx, nor its $6000-$7FFF mirror, until gsuWait(). testing/fixtures/libtests_gsu runs a job of about seven frames this way; its manifest checks that the game loop counted seven frames during the job and that the CPU never read the ROM the GSU owned (luna's gsu.bus_violations stays 0, against 149 340 when RON is left at 1).
Instead of asking gsuBusy(), the game can let the GSU tell it. With CFGR bit 7 clear, STOP raises an IRQ on the SNES CPU; bit 15 of the GSU status register (SFR) says the GSU was its source, and reading that byte resets it (Nintendo dev manual Book II §5.4.2, which describes the IRQ as the way to "continue its own processing without having to periodically monitor the GSU"; fullsnes, CFGR: "0=Trigger IRQ on STOP opcode, 1=Disable IRQ").
The Super FX IRQ entry in crt0 does that test first. A GSU IRQ is acknowledged and counted in gsu_stop_irqs, and never reaches your irqSet() handler, which stays the H/V timer's. When the timer fired too, its IRQ comes straight back after the GSU's, for your handler.
The CPU takes no IRQ at all while its I flag is set, which is how crt0 boots: the count moves only once something has cleared it (irqEnable() does). Keep CFGR_IRQ_MASK set when you poll: whether SFR bit 15 is also set by a STOP whose IRQ is masked is an open question in fullsnes ("also set if IRQ masked?"); ares and bsnes set it only when the IRQ is unmasked (instructionSTOP: if(regs.cfgr.irq == 0) { regs.sfr.irq = 1; … }), an emulator's choice rather than a measurement. If a console did set it, the next timer IRQ would count that old STOP. testing/fixtures/libtests_gsu runs its job a second time this way (the count moves by exactly one, seven game frames during the job).
A program too big for the cache, or one that reads ROM data, runs with RON = 1, and then the CPU cannot fetch a single instruction from the ROM (Nintendo dev manual Book II §5.3). gsuLaunch() waits from the RAM code window, which a Super FX build always has (768 bytes for the SDK). For your own code, ask the build for more room and write the loop as ordinary assembly:
The window is stored in the top RAM_CODE_SIZE bytes of ROM bank 1 and linked at the same 16-bit address in bank $7E, so jumps, calls and labels inside it are the RAM ones; crt0 copies it at boot. C calls it like any function (ramRunRomJob(); is a jsl to $7E:xxxx). While the GSU owns the ROM, code in the window must not call or read the ROM: no lib function, no C code, no const data. The NMI keeps counting frames (gsu_owns_cart, see above). testing/fixtures/libtests_gsu runs its job a third time this way: 33 frames of a ROM-resident job with the CPU polling from RAM and no bus violation; the same loop in a plain ROM section loses the CPU at once.
The loop can be C. RAM_CODE on a function puts it in the same window:
What the compiler does not check is the same as in assembly: while the GSU owns the ROM, nothing in such a function may reach the ROM. In C that excludes more than it looks: any call that is not itself RAM_CODE (library functions, and inline ones the compiler chose not to inline), the runtime helpers a multiplication, a division or a 32-bit shift calls, switch tables and const data. Register writes, bank-0 variables and FAR variables are fine. luna's gsu.bus_violations tells you at once when one slipped through: the fixture's fourth job asserts 0, and the same function without RAM_CODE counts 49 585.
The build links every .sfx of GSUSRC into a binary and writes a header next to it: one #define per global label, its offset in the binary. gsu_job.sfx with the labels gsu_start and mul_job gives gsu_job.sfx.h:
Labels starting with _ or @ are local and left out. Pass an entry point to gsuCall() (from ROM, like gsuLaunch(), which is entry 0) or to gsuStartCached() (from the cache), and the arguments in the GSU registers before the start:
testing/fixtures/libtests_gsu runs mul_job both ways. The offsets are relative to the binary. By default the program is assembled at 0 and placed by the linker where it fits, so only position-independent code is right: relative branches, LOOP through MOVE R13, R15.
A program that jumps to an absolute address or reads a table of its own needs its labels to be the addresses the GSU sees. One line in the Makefile does it:
The .sfx is then assembled at $8000 and GSU_SECTION forces the binary to the start of ROM bank 1, which the GSU reads at the same address (it sees banks $00-$3F as LoROM, ROM at $8000-$FFFF). GSU_BANK is also defined inside the .sfx:
The generated .sfx.h still holds offsets, so gsuCall() and gsuStartCached() are called the same way. One .sfx per ROM in this mode (.include the others from it); bank 1's top is the RAM code window, so a program longer than what is left below it fails at link rather than at run. testing/fixtures/libtests_gsu is built this way: its rom_job returns the two table bytes, and returns 0 when the same binary is placed elsewhere.
gsuDmaFullFrame() makes every frame a sequence: the job, then a wait for bottom band, then a 16 KB DMA that halts the CPU. The GSU is idle while the frame moves, and the CPU can do nothing but wait. gsuPresent() overlaps the three instead:
examples/chips/superfx_game_skeleton is that loop: a sight follows the D-pad at 60 frames per second while a hologram of 34 lines is rendered and presented at 30. With a blocking gsuLaunch() the loop is simpler (gsuLaunch(); gsuPresent();) and the transfer still overlaps the next job, but the game waits for each job.
How fast frames land. The NMI reads the V counter and moves what the rest of the blank window allows, at most 152 bytes per line (DMA is 8 master cycles a byte, 1324 usable per line: snesdev-wiki, Timing). The window is the VBlank, extended into the top band of gsuSetupHdmaBlanking when the bottom band is at least one line (it keeps force blank across line 0). The bottom band gives the NMI nothing: the NMI starts at line
| Letterbox (top / bottom) | Most bytes moved in one VBlank | Frames presented per second |
|---|---|---|
| none | 4 712 | 15 |
| 40 / 40 | 10 640 | 30 |
| 76 / 4 | 16 112 | 30 |
| 84 / 4 | 16 384, the whole frame | 31: the job is now the limit |
Past that point the job decides: while the previous frame moves, the job waits for Game Pak RAM, and the skeleton's (clear 16 KB, then draw 34 lines) presents 31 frames a second with the whole frame moved in one VBlank, against 30 at 40 / 40.
What it costs. The DMA halts the CPU and the GSU waits for Game Pak RAM for as long as a piece takes; a RAM-heavy job (clearing a buffer, PLOT) loses most of that time. The single-buffer path reaches the same 30 frames per second on this scene (superfx_3d, which also uses the bottom band), but its CPU does nothing else: it waits for the job, then for the band, then for the DMA.
Rules.
testing/vram_dma_blank.py checks, with luna's DMA trace, that every presented byte lands in blank or force blank, in whole frames into alternating blocks, and that no swap shows a block before its frame is complete.
A Super FX cartridge has no separate save chip: when it has a battery, the battery keeps the GSU's Game Pak RAM. USE_SRAM := 1 beside USE_SUPERFX := 1 declares it (cartridge type $15), and the sram module then reads and writes that RAM:
Two things differ from an ordinary cartridge:
testing/fixtures/libtests_gsu saves while a job runs, and two luna manifests (f_gsu_save_write.toml, g_gsu_save_read.toml) power the cartridge off and on between the save and the read.
| Example | What it demonstrates |
|---|---|
| superfx_3d | Single-buffer presentation in the letterbox bands |
| superfx_game_skeleton | A game loop at 60 fps while the GSU renders from its cache; double-buffered presentation |