sd2snes+ developer tools
Tools for people who develop and debug homebrew and romhacks on the sd2snes+: detect the cartridge from a game, read and write the game's memory over the network, log and watch variables, use the Game Boy link cable over the network, and make a game cooperate with Link Play. For content from the internet inside a game, see the Link SDK.
Needs sd2snes+ firmware 3.0 and the sd2snes+ Link (the ESP32-S3 dongle on the cartridge's USB port) that ships with it.
Detect the sd2snes+ and the Link
With firmware 3.0, a game can ask the cartridge for an 8-byte
identification register at $2BC0-$2BC7, in banks
$00-$3F and $80-$BF. It is read-only for the game. The firmware
writes it while the console is still in reset, so it is valid from the game's first
instruction and does not change while the game runs.
Checked on hardware on the sd2snes Mk.II and the FXPAK PRO.
Ask for it in the header
Put the ASCII text SD2SNES (7 bytes, no terminator) in the 7 reserved bytes of
the extended header, just below the title: $00:FFB6-$00:FFBC. File offsets
without a copier header: LoROM $007FB6, HiROM $00FFB6, ExHiROM
$40FFB6 (add $200 with a 512-byte copier header). The firmware does
not require $FFDA = $33 and does not look at $FFB0-$FFB5.
Recompute the header checksum after writing the bytes.
org $00FFB6 ; LoROM and HiROM alike: $00:FFB6-$00:FFBC
db "SD2SNES" ; 7 bytes, no terminator; then let asar fix the checksum
A game without the mark sees exactly what it always saw. On a plain cartridge, an emulator or another firmware the 7 bytes are harmless: they are reserved bytes. The mark has to be in the ROM file itself: an IPS/BPS patch that only adds it is not seen, unless the patch also changes the cartridge type.
Layout
| Address | Content |
|---|---|
$2BC0 | $53 ('S') |
$2BC1 | $AC, the complement of $2BC0 |
$2BC2 | Interface version, never 0: 3 in firmware 3.0 |
$2BC3 | Capabilities (below) |
$2BC4 | Board, low nibble: 0 = sd2snes Mk.II, 1 = FXPAK PRO (Mk.III), 2 = FXPAK PRO STM32. High nibble reserved (0) |
$2BC5 | Version 3: the Link SDK's status for this game (0 = the game did not ask for the SDK, 1 = its mailbox is open, 2-6 = why not) |
$2BC6 | Version 3: the bank of the SDK's mailbox, $EF when it is open, else $00 |
$2BC7 | Reserved, $00 |
| Bit of $2BC3 | Meaning when set |
|---|---|
| 0 · hook | The sd2snes+ in-game NMI hook is armed for this game (in-game menu, savestates, button gestures). 0 with the hook off in the options, during Link Play, and whenever the window was opened by the unlock path (bit 3 = 0). |
| 1 · MSU-1 | MSU-1 is on for this game (there is an .msu file for it): $2000-$2007 answer. |
| 2 · Link | An sd2snes+ Link wrote its area in the cartridge since power-on. It means "a Link talked to the cartridge this boot", not "a Link is there now": a game loaded right after power-on, before the Link found the cartridge, sees 0; a Link unplugged while a game runs can still show 1 on the next load for a while. |
| 3 · read-only | 1 = the register was opened read-only, with the hook and cheats intact. 0 = it was opened by the unlock path (see below). |
| 4 · SDK | Version 3: the Link SDK's mailbox is open for this game ($2BC5 = 1). |
| 5-7 | Reserved, 0. |
Version rule: fields are only ever added, never moved. Accept any version greater than or equal
to the one you know, and read a field only when the version has it ($2BC5 and
$2BC6 from version 3 on).
Detect it safely
Read $2BC0 and $2BC1 with absolute addressing
(lda $2BC0) with the data bank in $00-$3F or $80-$BF.
Where nothing answers, the read is open bus: normally the last byte on the bus, which is the high byte
of the operand, $2B, for both reads (on hardware a rare read brings another value, so
never test for $2B itself). With long addressing
(lda $002BC0) open bus gives the bank byte, $00. Neither matches
$53 followed by $AC, and whatever single value an emulator returns
for an unmapped address cannot be both. Then check that the version is not 0. Don't use
indirect addressing for these reads and don't read them while HDMA runs: open bus is no longer
predictable then.
; Sd2snesDetect: carry = 1 when the sd2snes+ identification register answers,
; with A (low byte) = its version; carry = 0 on anything else (open bus).
; Needs DB in $00-$3F or $80-$BF: with absolute reads, open bus gives $2B.
; Keeps X, Y and the register widths (php/plp).
Sd2snesDetect:
php
sep #$20
lda $2BC0
cmp #$53 ; 'S'
bne .no
lda $2BC1
cmp #$AC ; its complement
bne .no
lda $2BC2 ; version, never 0
beq .no
plp ; plp leaves A alone; the carry is set after it
sec
rts
.no: plp
clc
rts
; Sd2snesCaps / Sd2snesBoard: call with 8-bit A, after Sd2snesDetect said yes.
; Version 1 (firmware 3.0b33-b35 only) kept them one byte later.
Sd2snesCaps:
lda $2BC2
cmp #$02 ; carry = version >= 2; lda leaves it alone
lda $2BC3
bcs +
lda $2BC4
+ rts
Sd2snesBoard:
lda $2BC2
cmp #$02
lda $2BC4
bcs +
lda $2BC5
+ and #$0F ; 0 = Mk.II, 1 = Mk.III, 2 = FXPAK PRO STM32
rts
asar · use
sep #$20
lda #$80
pha
plb ; DB = $80: any bank of $00-$3F/$80-$BF works
jsr Sd2snesDetect
bcc NoSd2snes ; a plain cart, an emulator, an older firmware
sep #$20
jsr Sd2snesCaps
and #$04 ; bit 2: an sd2snes+ Link talked to the cart this boot
beq NoLink
ca65
.p816
.smart - ; the routine sets the widths itself
.export Sd2snesDetect, Sd2snesCaps, Sd2snesBoard
.segment "CODE"
; Sd2snesDetect: carry = 1 when the sd2snes+ identification register answers,
; with A (low byte) = its version; carry = 0 on anything else (open bus).
; Needs DB in $00-$3F or $80-$BF: with absolute reads, open bus gives $2B.
.proc Sd2snesDetect
php
sep #$20
.a8
lda a:$2BC0
cmp #$53 ; 'S'
bne no
lda a:$2BC1
cmp #$AC ; its complement
bne no
lda a:$2BC2 ; version, never 0
beq no
plp ; plp leaves A alone; the carry is set after it
sec
rts
no: plp
clc
rts
.endproc
; Call with 8-bit A, after Sd2snesDetect said yes.
.a8
.proc Sd2snesCaps
lda a:$2BC2
cmp #$02 ; carry = version >= 2; lda leaves it alone
lda a:$2BC3
bcs done
lda a:$2BC4 ; version 1 (3.0b33-b35): one byte later
done: rts
.endproc
.proc Sd2snesBoard
lda a:$2BC2
cmp #$02
lda a:$2BC4
bcs done
lda a:$2BC5
done: and #$0F ; 0 = Mk.II, 1 = Mk.III, 2 = FXPAK PRO STM32
rts
.endproc
; The mark: a segment the linker places at $00:FFB6 (file offset $7FB6 in a
; LoROM image, $FFB6 in HiROM), right below the title at $FFC0.
.segment "SD2SNES_MARK"
.byte "SD2SNES" ; 7 bytes, no terminator
asar 1.91 and ca65 2.19 produce the same bytes for these routines. They were run in a small
65816 model against open bus, constant $00 and $FF, a lone
$53, version 0, and version 1 and 2 blocks, starting with 8- and 16-bit
registers.
Once you ask: leave $2A00-$2DFF alone
- Never write to
$2A00-$2DFF. On the unlock path the window is writable:$2A00is the command register of the cartridge's microcontroller (a write there is a command, such as "back to the menu"), and the rest is the hook's code and data. - Don't count on open bus anywhere in
$2A00-$2DFF($2A00-$2FFFin DSP, ST011 and ST018 games) once you ask: the whole window then returns the cartridge's block RAM, not only the 8 bytes.
Which path a game gets
| Path | Games | What it means |
|---|---|---|
| Read-only (bit 3 = 1) |
No enhancement chip (LoROM, HiROM, ExHiROM, also S-RTC, BS-X and Sufami Turbo), DSP-1 to 4 and ST010, ST011, ST018, on both boards. Super FX on the FXPAK PRO (Mk.III and STM32). | The block RAM window opens for reading only. In-game menu, savestates and cheats keep working. |
| Unlock (bit 3 = 0) |
SA-1, Cx4, S-DD1, SPC7110 and OBC1 on both boards. Super FX on the sd2snes Mk.II. | The cartridge stops delivering its in-game hook to the game: no in-game menu, savestates or cheats for a game that asks for the register, and the window is writable. |
Game Boy, NES, Master System and Atari 2600 games run on the cartridge's players, whose header is the player's, so they never ask. During a Link Play session the session owns the register that opens the read-only path and can close it: the identification register may stop answering while a session runs (the block stays in place).
Read and write game memory over the network
The Link serves the usb2snes WebSocket protocol, the one QUsb2Snes and SNI speak to trackers, randomizer clients and file tools. A tool on your network connects to the console as it would to QUsb2Snes on the PC the cartridge is plugged into, with no PC at the console.
No authentication, local network only. The server has no password and does not check the Origin of a browser connection: any device on your network, and any web page that a browser on your network opens, can read and write the console's memory and the SD card through it. Use it on a network you trust, and never forward ports 8080 or 23074 from the internet.
Connecting
ws://sd2snes.local:8080(the Link announces itself over mDNS, also as_usb2snes._tcp), or the Link's IP address from the cartridge's menu. Port23074serves the same.- Up to 4 connections at once, counted over the two ports. Requests run one at a time, and each takes the cartridge's USB for itself only, so RetroAchievements, the Link's own web page and the other clients get the cartridge between two requests. A long request (a GetFile of megabytes) holds the others until it ends.
- Each request is a TEXT frame holding JSON:
{"Opcode": "…", "Space": "SNES", "Operands": ["…"]}. Numbers inOperandsare hexadecimal strings. Replies are a TEXT frame{"Results": […]}or, for data, BINARY frames of up to 4 KB each. - There is no error reply. As with QUsb2Snes, anything that goes wrong closes
the connection, with the reason in the close frame: a memory request before
Attach, bad operands, an unsupported opcode (PutIPS,Stream…), the cartridge busy for more than 20 s. - From a browser: a page served over
https://can open aws://connection to the Link only in Chrome or Edge 147 and newer, which ask once for access to the local network; Firefox and Safari block it. A page onhttp://localhostis not blocked.
| Opcode | Reply |
|---|---|
DeviceList | ["SD2SNES …"], or [] with no cartridge |
Attach [device] | None. Any name is taken: there is one cartridge |
Name [name] | None. Shown in the Link's log |
Info | [firmware version, "SD2SNES", running ROM, flags…] |
GetAddress [a, n, …] | BINARY: the n bytes at each address a, in order. Space SNES, CMD or MSU |
PutAddress [a, n, …] | None. Send the bytes as BINARY frames right after. Space SNES or CMD |
AppVersion | ["sd2snes-link <version>"] |
The file opcodes (List, ExtendedList, GetFile,
PutFile, Rename, Remove, MakeDir) and
Boot, Menu, Reset and Close are there too.
Addresses
| Space SNES | What |
|---|---|
$000000+ | The ROM |
$E00000+ | Save RAM. LoROM $70:0000 = $E00000. The game sees a write at once |
$F50000+ | A copy of the console's WRAM: $7E:0000 = $F50000, $7F:0000 = $F60000. It is the copy the FPGA keeps of every write the console makes, so it is for reading: writing there does not change the console's WRAM, and a byte nothing wrote since power-on shows what the cartridge's memory held |
The WRAM copy exists for games with no enhancement chip and for DSP games. Super FX, Cx4, S-DD1, SPC7110 and OBC1 games don't have it, and don't rely on it with SA-1 games.
What is safe while a game runs
- Reading anything is safe. It shares the cartridge's USB with everything else (see the rate below).
- Writing save RAM works and the game sees it at once, but it sets off the autosave: see the trap below.
- Writing WRAM is not possible through
$F50000. QUsb2Snes-style WRAM writes run a few bytes of 65816 code from the NMI hook, put in the cartridge's block RAM at$2C00(spaceCMD). That works only in games with no chip and DSP games, never during a Link Play session (the session puts its own code there), and the code has to clear$2C00and leave throughJMP ($FFEA). The Variables panel of /live/usb.html does it for you. - RetroAchievements hardcore: while a hardcore game runs, every
PutAddressis refused (spaces SNES and CMD); reading stays open. - Link Play: during a session
Boot,MenuandResetare refused. After any of them the cartridge answers nothing for a few seconds, and the next request waits for it. - Files: avoid them with a game running. Every file goes through the game's loop on the cartridge (an MSU-1 track pauses for each file), and a save written under a running game is overwritten when the game saves. File transfers are refused while the Game Boy link cable is in use, and writes while a save is being restored from the cloud.
Rate
The server has no rate limit of its own. The cartridge's USB is the limit, and it is shared.
Through the Link a 4 KB GetAddress takes about 28 ms (the whole 128 KB of WRAM in
about 0.9 s), and /live/usb.html reads up to about 20 times a
second. Ranges of up to 255 bytes in one GetAddress go to the cartridge together,
up to 8 in one USB transaction, so ask for everything you need in one request rather than in
many. Stay at 10 reads a second or fewer unless you need more: RetroAchievements reads the
console every frame over the same USB, and during Link Play an outside client was measured to
raise the frames held from 0.34% to 1.23%.
The autosave trap
Don't use save RAM as a mailbox. While a game runs, the firmware's autosave (on
by default) watches its save RAM: when it changes and then stays the same for a moment, the firmware writes the
.srm to the SD card, and when it keeps changing, the firmware writes it every so
often anyway. Each write is announced to the Link, and a player with cloud backup gets the save
uploaded. A mailbox in save RAM means a steady stream of SD card writes and uploads.
Put what the game publishes in WRAM and read it from the
$F50000 copy. Keep writes into save RAM rare and small.
Example: watch a block the game keeps in WRAM
The game keeps 10 bytes at $7E:1F00: "DBG!", a 16-bit counter it
bumps on every update, then x and y. A read is not atomic with the
game's writes, so a block can mix old and new values: for a debug view that is fine; when it
is not, read twice and keep a block only when both reads match.
# watch.py: read a status block the game keeps in WRAM, through the Link's usb2snes server.
# pip install websocket-client
import json, struct, time
from websocket import create_connection
URL = "ws://sd2snes.local:8080" # or the IP the menu shows
ws = create_connection(URL)
def send(op, *operands, space="SNES"):
ws.send(json.dumps({"Opcode": op, "Space": space, "Operands": list(operands)}))
def results(op, *operands):
send(op, *operands)
return json.loads(ws.recv())["Results"]
def read(addr, size): # GetAddress: BINARY frames of up to 4 KB each
send("GetAddress", f"{addr:X}", f"{size:X}")
data = b""
while len(data) < size:
data += ws.recv()
return data
def write(addr, payload): # PutAddress: no reply, the bytes follow
send("PutAddress", f"{addr:X}", f"{len(payload):X}")
ws.send_binary(payload)
device = results("DeviceList")[0] # [] = no cart: the [0] fails, as it should
send("Attach", device)
send("Name", "watch.py")
print(results("Info"))
WRAM = 0xF50000 # $7E:0000 of the console
last = None
for _ in range(50): # 5 seconds at 10 reads a second
block = read(WRAM + 0x1F00, 10) # $7E:1F00: "DBG!", seq, x, y
if block[:4] == b"DBG!":
seq, x, y = struct.unpack_from("<HHH", block, 4)
if seq != last:
print(f"seq {seq}: x={x} y={y}")
last = seq
time.sleep(0.1)
write(0xE00010, b"\x01") # one byte of save RAM: see "the autosave trap"
ws.close()
JavaScript · a web page, or Node 22+
function usb2snes(url) {
const ws = new WebSocket(url);
ws.binaryType = "arraybuffer";
const queue = [], waiting = [];
let closed = null;
ws.onmessage = (e) => (waiting.length ? waiting.shift().ok(e.data) : queue.push(e.data));
ws.onclose = (e) => { // every error closes the connection, with the reason
closed = new Error(e.reason || "connection closed");
while (waiting.length) waiting.shift().fail(closed);
};
const next = () =>
queue.length ? Promise.resolve(queue.shift())
: closed ? Promise.reject(closed)
: new Promise((ok, fail) => waiting.push({ ok, fail }));
const send = (op, operands = [], space = "SNES") =>
ws.send(JSON.stringify({ Opcode: op, Space: space, Operands: operands }));
const hex = (n) => n.toString(16).toUpperCase();
return {
opened: new Promise((ok, fail) => { ws.onopen = ok; ws.onerror = () => fail(new Error("no connection")); }),
send,
async results(op, operands = []) {
send(op, operands);
return JSON.parse(await next()).Results;
},
async read(addr, size) { // BINARY frames of up to 4 KB each
send("GetAddress", [hex(addr), hex(size)]);
const out = new Uint8Array(size);
for (let got = 0; got < size; ) {
const part = new Uint8Array(await next());
out.set(part, got);
got += part.length;
}
return out;
},
write(addr, bytes) { // no reply: the bytes follow the request
send("PutAddress", [hex(addr), hex(bytes.length)]);
ws.send(bytes);
},
close: () => ws.close(),
};
}
const url = "ws://sd2snes.local:8080"; // or the IP the menu shows
const link = usb2snes(url);
await link.opened;
const [device] = await link.results("DeviceList");
link.send("Attach", [device]);
link.send("Name", ["my-page"]);
console.log(await link.results("Info"));
const WRAM = 0xF50000; // $7E:0000 of the console
let last = null;
for (let i = 0; i < 50; i++) { // 10 reads a second
const b = await link.read(WRAM + 0x1F00, 10);
const v = new DataView(b.buffer);
if (String.fromCharCode(...b.subarray(0, 4)) === "DBG!" && v.getUint16(4, true) !== last) {
last = v.getUint16(4, true);
console.log(`seq ${last}: x=${v.getUint16(6, true)} y=${v.getUint16(8, true)}`);
}
await new Promise((r) => setTimeout(r, 100));
}
link.write(0xE00010, new Uint8Array([1])); // one byte of save RAM: see the autosave trap
link.close();
Both were run against a mock of the server written from the Link's description of the protocol (including the close-on-error behaviour and replies split into 4 KB frames), not against a Link.
Debug log and variables
/live/usb.html connects to a real sd2snes over USB (Web Serial) or through the Link's usb2snes server and shows the memory, a live game log, named variables and the graphics. The game log works like Mesen's logging breakpoints, on the console.
The log buffer
The program writes text into a ring buffer in its save RAM. The page reads it at
$E00000 plus the offset you type in its SRAM +$ field. It works
for any game or homebrew that declares save RAM in its header.
| Offset | Content (little endian) |
|---|---|
+0 | "SLOG" |
+4 | Ring size (u16): a power of two, 16 to 32768 |
+6 | Head (u16): total bytes written, wraps at 65536 |
+8 | Head again (u16): the page trusts the header only when both match |
+10 | 6 bytes reserved |
+16 | The ring: byte n goes to ring[n & (size-1)] |
To print a character, store it at ring[head & (size-1)], then store
head+1 at +6 and at +8. $0A ends a line.
The page marks the bytes it lost when the program wrote more than the ring holds between two
reads, and marks a restart of the log. The two routines to copy:
!LOG = $700000 ; LoROM save RAM ($70:0000); HiROM: $30:6000
!LOGSIZE = $1000 ; a power of two, 16..32768
LogInit: ; once, at boot; the magic goes last
php
rep #$20
lda.w #!LOGSIZE
sta.l !LOG+4
lda.w #$0000
sta.l !LOG+6 ; head
sta.l !LOG+8 ; head again
lda.w #$4C53 ; "SL"
sta.l !LOG+0
lda.w #$474F ; "OG"
sta.l !LOG+2
plp
rtl
LogPutc: ; JSL with A = one character ($0A ends a line);
php ; keeps A, X, Y and the flags, any M/X, any DB
rep #$30
pha
phx
lda.l !LOG+6
and.w #!LOGSIZE-1
tax
sep #$20
lda 3,s ; the character
sta.l !LOG+16,x
rep #$20
lda.l !LOG+6
inc a
sta.l !LOG+6 ; head, after the text
sta.l !LOG+8 ; and its copy
plx
pla
plp
rtl
Binary records are cheaper on the 65816: in the middle of the text, the byte
$01, the 24-bit address of a 0-terminated printf-style format in the ROM (low byte
first), then the arguments, little endian. The page reads the format from the ROM and builds the
line. %u %d %x %X %b are 16-bit (%d signed), hh makes
them 8-bit (%hhu), l 24-bit (%lx), %c is one
byte, %% a percent sign; width and zero padding work (%04X).
rep #$20
lda.w #$0001 ; starts a binary record
jsl LogPutc
lda.w #FmtHp
jsl LogPutc ; the format's address: low byte,
xba
jsl LogPutc ; high byte,
lda.w #FmtHp>>16
jsl LogPutc ; bank
lda.w Hp ; your 16-bit variable
jsl LogPutc ; %u: 16 bits, low byte first
xba
jsl LogPutc
FmtHp: db "hp %u", $0A, 0 ; in the ROM: the page reads it from there
The log lives in save RAM, so the autosave applies. While the game logs, its
.srm is rewritten (and uploaded, for a player with cloud backup). That is fine
while you develop: leave logging out of release builds. On an emulator the buffer is just save
RAM and does no harm.
Variables
Load your assembler's symbol file into the page's Variables panel: asar
(--symbols=wla) and WLA-DX, ca65 (-Ln), no$sns (nocash), Mesen
(.mlb), or plain lines such as name = $7E0010. The page maps each
symbol to the WRAM copy or to save RAM, shows it with a type, draws a graph and fires alerts that
mark the game log and can freeze the page. Clicking a value writes it: save RAM directly, WRAM
through the $2C00 hook in games with no chip and DSP games.
The Game Boy link cable, over the network
A Game Boy or Game Boy Color program running on the cartridge can talk over the link cable
through the Link. Your code uses the serial port exactly as on a real cable (SB at
$FF01, SC at $FF02, the serial interrupt), and the Link
is the other end of the cable. There is nothing to add to the ROM.
The cartridge's Game Boy core has a virtual link port that the Link reads over USB about once a
millisecond. When your program starts a transfer as master, the cartridge holds it, the Link
sends the byte to the other side and writes the answer back. When the other side starts one,
the Link hands the byte to your program if it is waiting for one. The FXPAK PRO has the full
port; the sd2snes Mk.II, whose Super Game Boy core had room only for a minimal one, has no
timeout of its own in the cartridge, so there the Link always ends a held transfer itself, with
$FF. What goes over the network is the same on both.
Two ways to connect
- A room: two consoles anywhere, each with a Link paired to an account. One
creates a room and gets a 6-character code, the other joins with it. On the console:
Y on a
.gb/.gbcROM › Link cable…. - Local, against the BGB emulator on a computer (the BGB 1.4 link protocol over TCP), handy while you develop: your build on the console, the other side in BGB.
# The gblink module is on by default; this turns it on if someone turned it off
curl -X POST -H 'X-Link: 1' -H 'Content-Type: application/json' \
-d '{"name":"gblink","enabled":true}' http://sd2snes.local/link/modules
# The Link listens on port 8765 ...
curl -X POST -H 'X-Link: 1' -H 'Content-Type: application/json' \
-d '{"mode":"listen","port":8765}' http://sd2snes.local/link/gblink
# ... and BGB connects to it
bgb -rom yourgame.gb -connect <the Link's IP>:8765
# Mode, state, the peer and statistics
curl http://sd2snes.local/link/gblink
Timing
- Every transfer your program starts as master is a network round trip. Measured: a whole Dr. Mario match between an sd2snes Mk.II and an FXPAK PRO in a room, 1,806 of 1,807 transfers answered, 11.7 ms of round trip on average.
- No answer in time and your program receives
$FF. The deadline is 250 ms by default in the local modes (20 to 480 ms) and 1 s in rooms (100 ms to 5 s; on the FXPAK PRO the port itself holds a transfer for 0.5 to 1 s at most, depending on the core). After a late answer, your next transfers get$FFat once, without being sent, until it arrives or 1 s goes by. - A byte from the other side that finds your program not waiting (or in a transfer of its own) is tried again for up to 250 ms before the other side hears "not waiting".
- Protocols where the master changes on every byte suffer the most, since each byte waits on the network. Tetris DX and Tetris Attack needed a special transport with a description of each game, which other games don't get.
So: design for tens of milliseconds per byte, let one side be master for a whole message, treat
$FF as "no answer", and check what arrives. Tested on consoles so far: Dr. Mario,
Pokémon Yellow (trades), Tetris, Tetris Attack and Tetris DX. While a link is up, the save
backup and file transfers wait for it to end.
Two-player SNES games: Link Play "class 1"
Link Play runs two-player SNES games over the internet, each player on their own console. For most games the Link patches the game and runs both consoles in lockstep, frame by frame: that takes a description of every controller read and a game that behaves the same on both sides, weeks of work per game. A game you write or modify can cooperate instead. That is "class 1", and the online Doom works that way.
In class 1 the game itself:
- writes its own sample for each tick (2, 4 or 6 bytes: the player's input, or whatever the game needs to stay in step) to an outbox, then waits until its inbox holds both players' samples for that tick;
- is responsible for its own determinism: the same samples in the same order have to give the same game on both consoles;
- writes an end cell when the match is over (or on an error of its own), and stops when the Link raises its abort cell.
The outbox, the inbox and the cells live in a window of the cartridge's memory that the firmware opens to the game only during a session.
How a game gets into Link Play
- Every game on the list has an image (the session's patches and layout) registered by the project in the GamesDB, by the ROM's CRC32. The Link downloads it when a room opens, so a game is added or fixed without a new firmware or Link.
- An unmodified game gets in through a descriptor the project writes for it (its controller reads, the tick, what must stay the same on both consoles), from which the image is built.
- A game that cooperates (class 1, like the online Doom) does the exchange itself, as above; it still gets its image in the GamesDB.
- The list has 30 ROMs today; the games are on the sd2snes+ Link page. To get your game in, open an issue on GitHub.
Compatibility and limits
- Boards: sd2snes Mk.II, FXPAK PRO (Mk.III) and FXPAK PRO STM32, with the sd2snes+ 3.0 firmware. The Link is an ESP32-S3 board on the cartridge's USB port: while it is there, a computer can't use that port at the same time.
| Game | ID register | WRAM copy | WRAM writes |
|---|---|---|---|
| No chip | read-only | yes | yes, $2C00 hook |
| DSP-1 to 4 | read-only | yes | yes, $2C00 hook |
| Super FX | read-only on FXPAK PRO, unlock on Mk.II | no | no |
| SA-1 | unlock | don't rely on it | no |
| Cx4, S-DD1, SPC7110, OBC1 | unlock | no | no |
- RetroAchievements: in a hardcore game no one from outside writes into the
game (
PutAddressis refused); reading stays open. The Link doesn't offer hardcore yet: it waits for RetroAchievements to approve it. - Link Play sessions: the identification register may stop answering,
Boot/Menu/Resetare refused, and the$2C00WRAM writes must not be used. - Security: the usb2snes server has no authentication. Local network only.
Testing without the hardware
- The identification register: on any emulator the detection takes its "not found" branch. Test that branch there, and the "found" branch on a cartridge.
- usb2snes tools: QUsb2Snes and SNI serve the same protocol for emulators, which is how one tracker works with both. Check their documentation for which emulators and memory areas each supports.
- The sd2snes in the browser (/live/) has no usb2snes connection, so it can't stand in for the Link. /live/usb.html is the page for a real cartridge.
Link SDK
A homebrew fetches a URL it carries, into its own memory or into its own folder on the SD card, with the player's permission and every request checked by the Link and the GamesDB. The Link SDK page has the library (ca65, asar and C), the examples and the specification.
Questions and requests: GitHub issues.