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).
Below is the same idea the library uses: talk to the control register at port $033B, try writing bit 7 off and on, and check that reads come back inverted for that bit. On success, HL = 1. This fragment only shows the Spectranext probe; restoring the original byte and falling back to a classic Spectranet check is what the full library routine does for you.
CTRLREG equ $033B
; --- Spectranext-style probe (result: HL = 1 if matched) ---
ld bc, CTRLREG
in a, (c)
ld d, a ; keep original value to restore later
; Write bit 7 = 0, expect to read bit 7 = 1 on Spectranext
and $7F
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 $7F
or $80
out (c), a
in a, (c)
bit 7, a
jr nz, not_spectranext
; Restore original control register
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.