Detection
Sometimes you only need to know which kind of network cartridge is in the machine. Spectranext builds on the same ideas as the classic Spectranet, but adds new features. Your program can ask the hardware a simple question before using Wi‑Fi, HTTPS, or other extras that exist only on Spectranext.
What you get back
A small helper (spectranext_detect) returns a number:
| Value | Meaning (plain language) |
|---|---|
| 1 | Spectranext is present. |
| 0 | Not Spectranext, but a classic Spectranet interface is there. |
| -1 | No compatible cartridge was found. |
So you can branch your program: use Spectranext‑only features when you see 1, fall back when you see 0, and show a friendly message when you see -1.
How it works
Spectranext exposes a control register on a fixed I/O port. When you write a bit and read it back, one particular bit appears “flipped” compared with what you wrote—only on Spectranext. The library uses that quirk to recognize the new hardware without disturbing the rest of the system when it isn’t Spectranext.
Examples
The behaviour is the same whether you call the helper from C or write the port yourself in assembly. Pick the tab that matches how you’re building your program.
- C (with header)
- Assembly
Include spectranext.h and call spectranext_detect. Link your project against the Spectranet library (for example libspectranet_np) so the routine is available—same family of libraries as other Spectranet networking code.
#include <spectranext.h>
int main(void)
{
int kind = spectranext_detect();
if (kind == 1) {
/* Spectranext: safe to rely on newer features */
} else if (kind == 0) {
/* Classic Spectranet only */
} else {
/* No cartridge (or not recognised) */
}
return 0;
}
The declaration lives in spectranext.h (return values are documented there next to the function).
The standalone probe below talks to the control register at $033B, writes bit 7 off and on, and checks that reads return the inverse. It returns HL = 1 for Spectranext, otherwise HL = 0; it does not perform the library's classic Spectranet fallback.
Run this fragment from host RAM with Spectranext paged out. Read bits 0–2 contain border colour; writing them back could page the cartridge in, force DivMMC mode and reboot, or latch Next compatibility. The probe writes only the trap-enable and signature bits, and reconstructs the original signature by inverting its readback. It clobbers AF, BC and DE.
CTRLREG equ $033B
; --- Spectranext-style probe (result: HL = 1 if matched) ---
ld bc, CTRLREG
in a, (c)
xor $80 ; reconstruct the original written signature
and $88 ; retain signature and trap enable only
ld d, a
; Write bit 7 = 0, expect to read bit 7 = 1 on Spectranext
and $08
out (c), a
in a, (c)
bit 7, a
jr z, not_spectranext
; Write bit 7 = 1, expect to read bit 7 = 0 on Spectranext
ld a, d
and $08
or $80
out (c), a
in a, (c)
bit 7, a
jr nz, not_spectranext
; Restore signature/trap bits without requesting page-in
ld a, d
out (c), a
ld hl, 1 ; yes: Spectranext
ret
not_spectranext:
ld a, d
out (c), a ; restore before other checks
ld hl, 0 ; not Spectranext (then test for Spectranet separately)
ret
From assembly you can CALL into the same spectranext_detect entry provided by the linked library if you prefer one routine that also handles the Spectranet fallback and -1 when nothing is present.
Summary
- Use
spectranext_detectwhen you want one call that distinguishes Spectranext, Spectranet, and no hardware, with return codes 1, 0, and -1. - From C, include
spectranext.hand link the Spectranet family libraries as usual. - From assembly, you can mirror the port handshake at
$033Bor call the library routine for the full behaviour.