Link SDK sd2snes+ 3.0 Specification draft 3

sd2snes+ Link SDK

A SNES homebrew carries a URL, asks for it, and gets the content: a few KB of text or JSON (news, a message of the day) or megabytes of extra levels, graphics or music. The sd2snes+ Link fetches it over Wi-Fi and hands it to the game through the cartridge. The player allows it once per game, the GamesDB checks every request, and the game keeps what it got in its own memory or in its own folder on the SD card.

The SDK comes with sd2snes+ 3.0 and the Link firmware that ships with it. It was checked on the sd2snes Mk.II and the FXPAK PRO (Mk.III) with the example games. The specification is draft 3.

1 · The short version

A minimal example

The library does the mailbox work. Call lk_detect once and lk_open for a session, then, every frame, lk_poll and lk_recv to take the answers. A download is an open, reads of pieces until the end (EOF), and a close. The blocks below are copied unchanged from the SDK's files; each label names the file and the lines.

C · lib/c, for pvsneslib or any 65816 C compiler · README.md:90-97
if (lk_detect() == LK_SDK_OPEN) lk_open();
lk_fetch_open(url, sizeof url - 1, 0, 0, 0, 0);
/* each frame */
while ((op = lk_recv())) {
  if (op == (LK_OP_FETCH_OPEN | LK_RSP) && !lk_rsp[3]) lk_fetch_read(LK_RSP_PAYLOAD[0], 0, 16384);
  else if (op == (LK_OP_FETCH_READ | LK_RSP) && !lk_rsp[3]) { /* lk_bulk_read(0, dst, len); read again unless EOF */ }
  else if (lk_rsp[3]) show(lk_errstr(lk_rsp[3]));
}

Each piece lands in the bulk area of the mailbox. Copy it out (lk_bulk_dma to WRAM, lk_bulk_vram to VRAM, lk_bulk_read with the CPU) before you ask for the next piece on the same range.

ca65 · examples/fetch/fetch.s:163-175 · detect, then open a session
        jsl lk_detect
        sta ex_detect
        php
        AT 3, 10, PAL_WHITE
        lda ex_detect
        jsr print_hex8
        plp
        bcc main
        jsl lk_open
        bcc main
        lda #ST_HELLO
        sta ex_step
        bra main
ca65 · examples/fetch/fetch.s:177-192 · every frame: take the answers
running:
        jsl lk_poll
@rx:    jsl lk_recv
        bcc main
        cmp #LK_OP_HELLO | LK_RSP
        bne :+
        jsr on_hello
        bra @rx
:       cmp #LK_OP_FETCH_OPEN | LK_RSP
        bne :+
        jsr on_open
        bra @rx
:       cmp #LK_OP_FETCH_READ | LK_RSP
        bne @rx
        jsr on_read
        bra @rx
ca65 · examples/fetch/fetch.s:206-222 · open a URL (a plain GET)
; open_url: X = the url's address (bank of the code), A = its length; a plain GET
open_url:
        .a8
        sta lk_len
        stx lk_ptr
        lda #^s_news
        sta lk_ptr+2
        stz lk_vlen                     ; no etag
        stz lk_vlen+1
        ldx #0
:       stz lk_arg,x                    ; GET, offset 0
        inx
        cpx #10
        bcc :-
        lda #0                          ; no flags
        jsl lk_fetch_open
        rts
ca65 · examples/fetch/fetch.s:277-289 · ask for the next piece
read_more:
        .a8
        ldx #0                          ; the text: one piece at the start of the bulk area
; read_at: X = the bulk offset of the next piece
read_at:
        .a8
        lda stream
        rep #$10
        ldy #PIECE
        jsl lk_fetch_read
        bcc :+                          ; the ring is full: cannot happen with these few requests
        inc inflight
:       rts

The same open and first read with the asar library, from its self-test ROM. At the first line A, X and Y are 16-bit (the routine before it in the file ends a KV write).

asar · lib/asar/selftest.asm:245-270
    lda.w #url
    sta.w !lk_ptr
    stz.w !lk_vlen
    stz.w !lk_arg+0
    stz.w !lk_arg+2
    stz.w !lk_arg+4
    stz.w !lk_arg+6
    stz.w !lk_arg+8
    sep #$20
    lda.b #url>>16
    sta.w !lk_ptr+2
    lda.b #url_end-url
    sta.w !lk_len
    lda.b #0
    jsl lk_fetch_open
    rts

on_fopen:                       ; the stream: read up to 1 KB of it
    lda.w !lk_rsp+!LKS_STATUS
    sta.w !EX+50
    bne +
    lda.w !lk_rsp+!LKS_PAYLOAD+0
    ldx.w #0
    ldy.w #1024
    jsl lk_fetch_read
+   rts
asar · lib/asar/selftest.asm:287-289 · the URL the ROM carries
url:
    db "https://example.com/sdk/news.txt"
url_end:

The examples carry example.com URLs: put your own. The ROM also needs the two marks of its header (section 3) and, for the network, a registration in the GamesDB (section 8).

2 · Before you start

Requirements

  • Firmware: sd2snes+ 3.0 on the cartridge, and an sd2snes+ Link with the Link firmware that ships with 3.0. With an older cartridge firmware, another cartridge or an emulator, the detection says no and the game plays offline.
  • Boards: sd2snes Mk.II, FXPAK PRO (Mk.III) and FXPAK PRO STM32.
  • Games: a SNES game without an enhancement chip (LoROM or HiROM), or with DSP-n / ST-0010, ST-0011 or ST-0018: the cores that have the mailbox window. Only a LoROM game without a chip has been checked on hardware.
  • Not in this version: ExHiROM games; SA-1, Super FX, Cx4, S-DD1, SPC7110 and OBC1 games; Game Boy games; Satellaview games with a memory pack and Sufami Turbo games (they map their own memory where the mailbox goes); a game started in Link Play mode.
  • ROM size: while the SDK is open, banks $E0-$EF are the mailbox's window, not ROM. Otherwise they hold the ROM offsets $300000-$37FFFF in LoROM and $200000-$2FFFFF in HiROM, so a LoROM game of up to 3 MB and a HiROM game of up to 2 MB have nothing there. A LoROM or HiROM game of up to 4 MB finds the same bytes in banks $60-$6F and may use the SDK only if it reads that part of its ROM there, never through $E0-$EF. ExHiROM is out: the lower halves of its offsets $200000-$2FFFFF exist only in $E0-$EF.
  • RAM for the library: about 560 bytes of WRAM inside $0000-$1FFF, used as direct page while a routine runs (ca65: the LKRAM segment; asar: !LK_RAM). The C library uses two 256-byte arrays and a few bytes.
  • Battery SRAM is not a mailbox: keep the SDK's state in the mailbox and in WRAM. The firmware autosaves SRAM to the card, and with the Link it is backed up to the cloud. A download may go to SRAM, knowing that.
  • Savestates do not include the mailbox: after loading one, the game opens a new session (lk_open). The in-game hook (menu, savestates) stays.
4 · At run time

Detection and states

The player's permission

The first time the game is started from the cartridge's menu, the menu asks, before the game runs: Internet access. <title> wants to use the internet through the sd2snes+ Link. It can download content for this game. Your answer is remembered: revoke it on the Link's web page. The answers are Allow and Don't allow; B goes back to the menu. The answer is kept per game in /sd2snes/sdk/consent.txt, so the question comes once. A game started without the menu (a usb2snes Boot, autoboot) is never asked: the stored answer decides, and without one the mailbox stays closed.

What lk_detect reads

The firmware writes the 8-byte identification register at $2BC0-$2BC7 at every game load (layout on the developer tools page). In firmware 3.0 it is version 3: capability bit $10 at $2BC3 = the mailbox is open, $2BC5 = the SDK status, $2BC6 = the mailbox's bank ($EF). lk_detect returns the status, or $FF when there is no identification register at all.

StatusMeaning
1 OPENThe mailbox is open at $EF:0000: go on with lk_open.
0 NONENo valid descriptor, or a firmware without the SDK (register version 2).
2 DECLINEDThe player answered "Don't allow" at this load.
3 NO_MAPThis core cannot open the mailbox (a chip outside the list above).
4 DENIEDThe stored answer for this game is "Don't allow", or the descriptor asks for something this firmware refuses.
5 NO_ASKThe question was needed but could not be asked (usb2snes boot, autoboot).
6 BUSYThe game was started in Link Play mode.
$FFLibrary only: not an sd2snes+ (another cartridge, an emulator, an older firmware).

The Link's side: host states

Once the mailbox is open, lk_open starts a session and lk_poll (once per frame) returns the host state, which the Link writes in the mailbox. The Link also beats a heartbeat at least once a second; lk_poll returns the carry clear when it did not move for 180 frames (3 s). A Link that comes back (a Wi-Fi drop, a restart) needs a new lk_open.

StateWhenWhat the game gets
0 ABSENTNo Link, a Link without the SDK, or a Link still startingNothing answers and lk_poll returns the carry clear. Give up after your own timeout and play offline.
1 READYServingDownloads, if the Link is online and the game registered (or in developer mode). Offline: E_OFFLINE on a download, but the game's files on the card still work.
2 POLICY_OFFThe project switched the SDK off, for everyone or for this gameHELLO and STATUS only; the rest is E_DENIED.
3 BUSYA Link Play or Game Boy link cable session runs on the LinkE_BUSY
4 USER_OFFThe player switched off "Games may use the Link" on the Link's pageHELLO and STATUS only; the rest is E_DENIED.

The HELLO answer and the mailbox also carry host flags: ONLINE (internet reachable), PAIRED (the Link has an account), REGISTERED (the game's app_id is known and enabled), DEVMODE (developer mode) and RA.

5 · The main service

Downloading a URL into memory

The mailbox is 64 KB of the cartridge's memory at $EF:0000. Requests and answers go through two rings of 16 slots; the bulk area, $EF:4000-$EF:FFFF (48 KB), belongs to the game, which names a range of it for each read.

  1. Open (lk_fetch_open): an https:// URL of up to 235 bytes, port 443, no user name, ASCII only. The answer gives a stream id, the HTTP status, the total length (when the server says it), the ETag and the content type. An HTTP error (404, 500) is not an error of the request: the stream opens and the error body can be read.
  2. Read (lk_fetch_read): up to 32 KB per read into a range of the bulk area. Each answer says the offset of the bytes in the resource, how many were written, EOF, the total so far and the range it used. Fewer bytes than asked is normal; 0 bytes without EOF means "nothing yet, ask again".
  3. Close (lk_fetch_close). The Link also closes a stream idle for 30 s and every stream of a session that ended.

The Link writes into a range only as the answer to a read the game sent, so the game never gets more than it asked for and never has to keep up with the network.

The fast path: reads in flight and DMA

One read at a time waits a full round trip per piece. Keep 2 to 4 reads of the stream in flight, each on its own range (three reads of 16 KB fill the 48 KB: a triple buffer); the Link answers them in the order sent. Copy each piece out with one DMA and ask for the next piece on the same range. lk_bulk_dma copies to WRAM, lk_bulk_vram to VRAM (in vblank or forced blank); both use DMA channel 7 (LK_DMA_CH changes it). After EOF or an error, the reads still in flight answer the same way (0 bytes with EOF, or the same error): count the answers.

ca65 · examples/fetch/fetch.s:253-275 · three reads at once
        ; the binary: DEPTH reads at once, on ranges 0, PIECE, 2 * PIECE of the bulk area
        rep #$20
        .a16
        lda nmi_count
        sta t0
        sep #$20
        .a8
        stz ended
        stz inflight
        ldx #0
@more:  phx
        jsr read_at
        rep #$20
        .a16
        pla
        clc
        adc #PIECE
        tax
        sep #$20
        .a8
        cpx #DEPTH * PIECE
        bcc @more
        rts
ca65 · examples/fetch/fetch.s:373-400 · each piece: copy, then the same range again
@dlc:   ; a piece: copy it out (DMA) and sum it, then the same range again until the end
        rep #$20
        .a16
        lda lk_rsp+LKS_PAYLOAD+4
        clc
        adc ex_dgot
        sta ex_dgot
        lda ex_dgot+2
        adc #0
        sta ex_dgot+2
        sep #$20
        .a8
        jsr take_piece
        rep #$20
        .a16
        ldx #ex_dsum
        jsr add_sum
        sep #$20
        .a8
        dec inflight
        lda lk_rsp+LKS_PAYLOAD+6
        and #LK_FD_EOF
        beq :+
        sta ended
:       lda ended
        bne :+
        ldx lk_rsp+LKS_PAYLOAD+12       ; the range it came in: free again
        jsr read_at
ca65 · examples/fetch/common.inc:246-254 · inside take_piece: one DMA to $7E8000
:       lda #.loword(COPY)
        sta lk_arg+0
        sep #$20
        .a8
        lda #^COPY
        sta lk_arg+2
        ldx lk_rsp+LKS_PAYLOAD+12
        ldy tmp
        jsl lk_bulk_dma

Cache, resume and POST

  • Cache: keep the ETag of the open (and the content). Next time open with the LK_FO_COND flag and the ETag: an unchanged resource answers 304 with the flag NOT_MODIFIED and no body.
  • Resume: after a broken connection (a read answers E_REMOTE or E_TIMEOUT), open again with LK_FO_RESUME, the offset you already have and the ETag. A server that honours ranges answers 206 (flag PARTIAL) and the data goes on from there; one that does not answers 200 from offset 0.
  • POST: a body of up to 4 KB from the bulk area, as octet-stream, JSON, plain text or a form (lk_fetch_post in C; lk_arg fields in ca65 and asar).
  • At most 2 streams open per session; 10 s to the response headers; at most 3 redirects, each one only to an approved domain.

Errors the game can show

Every answer has a status. lk_errstr(status) in C and lk_errtext in ca65 and asar give the short text in the third column.

CodeNameTextTypical cause
$01E_UNSUPPORTEDNOT SUPPORTEDAn operation this Link does not have (see Status)
$02E_BADREQBAD REQUESTA bad length or field, a file name outside the rules
$03E_DENIEDNOT ALLOWEDReason byte: 1 not registered, 2 the project's policy, 3 the player's setting, 5 not in this state, 6 the game switched off in the registry
$04E_OFFLINENO INTERNETThe Link has no internet
$05E_BUSYBUSYToo many requests in flight, 2 streams open, a 5th read, a download to the card running, a Link Play session
$06E_RATETOO MANY, WAITMore than 20 opens in a minute; the answer says how many seconds to wait
$07E_QUOTAQUOTA USED UPA download without an announced length passed its byte limit
$08E_NOTFOUNDNOT FOUNDNo such stream or file
$09E_TOOBIGTOO BIGThe announced length is above the limit
$0AE_TIMEOUTTIMED OUT10 s without headers, 30 s without data
$0BE_REMOTENETWORK ERRORDetail: 1 DNS, 2 connect, 3 TLS, 4 a private address refused, 5 a redirect refused
$0CE_DOMAINURL NOT ALLOWEDNot https, a host not approved for this game, a port, a user name, non-ASCII
$0EE_RANGEBAD BUFFERA range outside the bulk area, a read of 0 or more than 32768 bytes
$0FE_INTERNALINTERNAL ERROR
ca65 · examples/fetch/fetch.s:452-475 · show the code and its text
; ---- an error: its code and its text, readable
fail:
        .a8
        sta ex_lasterr
        AT 20, 2, PAL_RED
        PRINT s_err
        lda ex_lasterr
        jsr print_hex8
        lda #' '
        jsr putc
        lda ex_lasterr
        jsl lk_errtext
        rep #$20
        .a16
        lda lk_ptr
        sta sptr
        sep #$20
        .a8
        lda lk_ptr+2
        sta sptr+2
        jsr print_str
        lda #ST_DONE
        sta ex_step
        rts

Speed and cost per frame

Measured on the bench, on an sd2snes Mk.II, with the example ROMs (SlowROM):

PathMeasured
URL → game's WRAM, 3 reads of 16 KB in flight, DMA≈300 KB/s (3 MB in 602 frames)
URL → file on the card, through the GamesDB proxy≈470 KB/s
URL → file on the card, fetched by the Link directly≈320 KB/s
File on the card → game's WRAM≈170 KB/s
For comparison: one read of 16 KB at a time, a CPU byte loop≈50 KB/s
  • Your server and the player's network decide the real figure. For a download into memory the ceiling is the cartridge taking the Link's writes while a game runs (~400 KB/s).
  • The game's cost: lk_poll and lk_recv once per frame. Copying a 16 KB piece with lk_bulk_dma stops the CPU for about 0.37 of a frame (8 master clocks a byte); a CPU byte loop in SlowROM takes about 16 frames for the same piece.
  • The Link's cost: one 8-byte read of the mailbox per video frame over the cartridge's USB; the slots only when the game wrote a request.
  • The window answers at the speed of its bank: FastROM with MEMSEL set, SlowROM otherwise. FastROM access has not been confirmed on hardware yet.
6 · DLC that stays

Files in the game's own folder

Every game has one folder on the SD card, /sd2snes/sdk/<app_id in 16 lowercase hex>/, and sees nothing else of the card. The Link writes the download itself, so the file can be larger than the game's memory, and the game reads it back in pieces whenever it wants.

CWhat it does
lk_file_fetchA URL straight into a file. The URL is checked as an open's and counts in the same 20 opens a minute. Progress events (LK_EV_FILE_PROGRESS) at most every 64 KB, then the answer with the HTTP status and the file's size. Only a 200 or 206 writes the card; a 304 or an HTTP error leaves the file as it was. One at a time per game.
lk_file_listThe files, in name order, with their sizes, a page at a time.
lk_file_readUp to 32 KB of a file from an offset into a bulk range. Several may be in flight, as with a download.
lk_file_deleteDeletes a file (and an unfinished download of that name).
lk_file_spaceThe bytes and files in the game's folder. The card's free space comes back as "not known" ($FFFFFFFF) with this Link.
  • Names: 1 to 32 characters of [A-Za-z0-9._-], not starting with a dot and not ending in .part; no paths. Names compare without case (FAT).
  • Downloads in progress are written as <name>.part and renamed when complete, replacing the old file. After an error, or when the session ends, the .part stays: fetch again with LK_FO_RESUME to continue it.
  • Size: no cap but the card's free space and a per-file limit in the registry (256 MB by default).
  • Offline: listing, reading, deleting and the folder's size use only the card. They work without internet and without a registration, as long as the player allowed the game. Only lk_file_fetch needs the internet and a registered game.
  • While a download runs the game keeps running: the Link writes the card in pieces of 64 KB and serves the mailbox between them. An MSU-1 track pauses about 0.2 s per piece, so show a "downloading" screen and keep the music on the SPC.
  • The folder is an ordinary folder: the player sees and deletes the files in the menu's file browser, and on the Link's page (Online › Games › Delete files).
C · README.md:115-120
lk_file_fetch("level9.bin", 10, url, sizeof url - 1, 0, 0, 0);
/* each frame */
while ((op = lk_recv())) {
  if (op == LK_EV_FILE_PROGRESS) show_progress(LK_RSP_PAYLOAD + 4);        /* u32 bytes, u32 total at +8 */
  else if (op == (LK_OP_FILE_FETCH | LK_RSP)) { if (lk_rsp[3]) show(lk_errstr(lk_rsp[3])); else /* on the card */; }
}
ca65 · examples/dlc/dlc.s:238-264 · once the session is open
        ldx #.loword(s_name)
        stx lk_ptr
        lda #^s_name
        sta lk_ptr+2
        rts

; ---- the session is open: the URL straight into the file
on_hello:
        .a8
        lda #1
        sta ex_hello
        AT 3, 13, PAL_GREEN
        PRINT s_ready
        AT 5, 2, PAL_WHITE
        PRINT s_dl_lbl
        lda #ST_FETCH
        sta ex_step
        lda #<(s_url_end - s_url)       ; the url, as for lk_fetch_open
        sta lk_len
        ldx #.loword(s_url)
        stx lk_ptr
        lda #^s_url
        sta lk_ptr+2
        stz lk_vlen                     ; no etag
        stz lk_vlen+1
        ldx #.loword(s_name)            ; the file's name: lk_arg+0..2 pointer, +3 length
        stx lk_arg+0
7 · Who decides what

Permissions and limits

Three yeses before a download

  1. The player, in the cartridge's menu, the first time the game starts (see section 4). Per game, remembered. The player can take it back on the Link's page: Online › Games › Revoke removes the answer and the menu asks again the next time. Revoking and deleting files work with the console in its menu. The same page has the switch Games may use the Link (on by default), which turns the SDK off for every game.
  2. The registration. Every game that downloads needs an entry in the GamesDB: its name, a contact and, for release builds, their CRC32s (section 8). There is no approval: the game gets its app_id at once. An unregistered game (app_id zero or unknown) gets no download; the files it already has in its folder still work.
  3. The domain. A registered game may fetch from the GamesDB's public list of approved domains without asking. A domain outside the list is asked for per game on the developer page and needs an admin's approval. Only https on port 443.

The GamesDB decides on every open: game registered and enabled, URL on an approved domain of that game, opens left this minute. The Link keeps no list of its own, so a game or a domain can be withdrawn at once.

Who fetches the URL

Domain approved asFetched byNotes
direct (the default)The Link, straight to the domainNo traffic through the project's server. The Link checks TLS against the URL's name with its own CA bundle, resolves the name once, refuses private, loopback, link-local, CGNAT and multicast addresses, and connects to the address it checked. Every redirect is checked the same way. A redirect to a domain approved as proxy is refused: point the game at the final URL.
proxyThe GamesDB, and the Link relays the bytesThe admin's choice per domain: a certificate the Link's bundle does not know, a server that must not see the player's IP, or content the project wants to cache (at most 10 minutes).
anything elseNobodyE_DOMAIN: the Link never contacts a host the GamesDB did not approve for that game.

What your server sees: User-Agent: sd2snes-link-sdk/1 (with (proxy) after it when the GamesDB fetches), X-SD2SNES-App: <app_id in hex>, Accept-Encoding: identity and the cache or range headers the game asked for. No cookies, nothing about the player.

Limits

WhatLimit
A download into memory8 MB
A file on the card256 MB by default (set per game in the registry), and the card's free space
Opens20 per minute per console per game, downloads into memory and into files together
Per dayno limit
Streams open / reads in flight / one read2 / 4 per stream / 32 KB
URL / ETag / POST body235 bytes / 64 bytes / 4 KB
Time10 s to the headers, 30 s without data, 30 s idle closes a stream
Redirects3, only to approved domains

What a game cannot do

  • Reach the local network: private, loopback and link-local addresses are refused, also after a redirect.
  • See the card outside its own folder, or another game's folder.
  • See the player's account: no name, e-mail or token, and not the Link's IP address or Wi-Fi data. A game whose mailbox is open cannot change the cartridge's configuration either: the firmware never opens that memory to it.
  • Run with RetroAchievements: a game with the mailbox open plays with RetroAchievements off (not only hardcore), as in Link Play.

The project can also switch the SDK off for every game (the Link's remote policy) or for one game (the registry), with no firmware update.

8 · The GamesDB

Registering a game and asking for a domain

Everything happens on the GamesDB's developer page (sd2snes.ludufre.com/gamesdb/developer), signed in with an sd2snes+ account.

  • Register a game: its name, a contact (an e-mail or a site) and the CRC32 of its release builds (8 hex digits each, at most 32). With CRCs, only those builds may use the network; leave the list empty while you develop and any build of the game may. The page shows the app_id at once: put it in the descriptor (section 3).
  • Public list: the domains every registered game may fetch from, without asking, are listed on the same page.
  • Ask for a domain: a host name (with or without its subdomains) and a note. It waits for an admin, who approves it or not and chooses whether the Link fetches it directly or through the project's server. Ask only for what the public list does not cover.
  • Each game shows its limits and the last 30 days of use (MB downloaded and opens). One account can register up to 20 games, each with up to 16 domains of its own.
9 · On your desk

Testing without hardware

The SDK comes with lkmock (in mock/, Python 3), which plays the Link and the cloud.

  • An emulator: build the game in emulator mode (-D LK_EMU=1 in ca65, -DLK_EMU=1 in asar, -DLK_EMU in C). The game then skips the detection and keeps a 32 KB mailbox in WRAM at $7F:0000 (16 KB of bulk area). Run python3 -m lkmock usb2snes against the usb2snes server of QUsb2Snes or SNI attached to the emulator, with the app_id of your ROM's descriptor; it writes the mailbox's header and serves it (needs pip install websockets). --card names a folder that stands for the card's /sd2snes/sdk/.
  • A real console, in developer mode: on the Link's page, Online › Games › Developer mode, with the Server URL of a computer on your network running python3 -m lkmock server --port 8790 (for example http://<computer>:8790). Every game's SDK requests then go to that server instead of the GamesDB, without a token; the registry is ignored (app_id zero works) and the game sees the DEVMODE flag. The player's question in the menu still applies. --site <folder> serves the files of a folder as https://sdk-test.example/<file>, fetched in proxy mode.
shell · README.md:147-152 · build and test
examples/fetch/build.sh; examples/hello/build.sh; examples/dlc/build.sh   # ca65/ld65
ASAR=/path/to/asar lib/asar/build.sh                   # asar 1.8+
cd mock && python3 -m unittest tests.test_host tests.test_fetch tests.test_files tests.test_clib tests.test_transports
python3 -m lkmock usb2snes --url ws://localhost:23074 --app-id 53444b4558414d50 --card /tmp/card
                                                       # an emulator through QUsb2Snes/SNI (LK_EMU builds)
python3 -m lkmock server --port 8790                   # the developer-mode server for a real Link
  • The ca65 examples need ca65/ld65 (cc65) and Python 3; each build.sh writes a cartridge ROM and an emulator-mode ROM (OUT=dir picks the folder). The asar build needs asar 1.8 or newer in ASAR.
  • tools/lksum.py FILE prints the checksum the fetch and dlc examples show for a download of that file.
  • examples/hello uses the extension services (time, a value kept in the cloud): it runs against the mock only. On a real Link use fetch and dlc.
10 · Download

Code and license

The library, the examples, the mock and the tools are under the MIT license, in the SDK's repository:

FolderWhat
lib/ca65/The library for ca65 (sd2link.s, sd2link.inc)
lib/asar/The same for asar 1.8+ (sd2link.asm; build.sh makes a self-test ROM)
lib/c/The same in C89, for pvsneslib or any 65816 C compiler (sd2link.h, sd2link.c)
examples/fetch/Downloads a text, then a file the fast way, with progress, a checksum and the frames it took
examples/dlc/Downloads a file to the card with progress, lists it, reads it back with a checksum, deletes it on A
examples/hello/Status, time and a value kept in the cloud (extension services, mock only)
mock/lkmock: the Link and the cloud in Python, and its tests
tools/The examples' font, the ROM header check and checksum, the constants generator, lksum.py
11 · Honest status

Status

Checked on hardware

On the sd2snes Mk.II and the FXPAK PRO (Mk.III), with the fetch and dlc examples:

  • The question in the menu at the first load, and no question at the next one.
  • A text and a file downloaded into the game's memory.
  • A file downloaded to the card through the proxy (3 MB, with the right checksum), and one fetched by the Link directly from a server with real TLS.
  • RetroAchievements off for the game; revoking on the Link's page brings the question back; the player's switch off gives "NOT ALLOWED".

In the specification, not in the Link yet

The SPEC also describes extension services: the Link's clock, the LED, a per-game player id, values kept in the cloud, leaderboards, Discord presence and rooms between two consoles. The mock serves them when it plays the Link; the Link that ships with 3.0 answers them E_UNSUPPORTED ("NOT SUPPORTED"), also in developer mode. Build on downloads and files.

Questions and requests: GitHub issues.