spectranext.h
spectranext.h (included in the SDK) exposes the Z80 interface to Spectranext services: controller status, Wi-Fi scan/connect/disconnect, DNS, and engine calls (e.g. JSONPath). Everything routes through the single SPECTRANEXT ($3EF0) jump-table entry, selected by register A on entry.
Functions declared here are not linked separately as are provided as part of libspectranet library.
Error convention (assembly): carry set = error; carry clear = success.
Functions
C calling convention: __z88dk_callee (callee cleans stack). spectranext_detect is __FASTCALL__.
spectranext_detect
Returns whether the cartridge is Spectranext (see Detection):
| Return | Meaning |
|---|---|
| 1 | Spectranext |
| 0 | Classic Spectranet |
| -1 | No compatible interface |
- C
- Assembly
int result = spectranext_detect();
if (result == 1) {
// Spectranext present
}
Detection is not a SPECTRANEXT operation — it probes CTRLREG ($033B) bit 7. See Detection for the full assembly sequence.
ld bc, CTRLREG ; $033B
in a, (c) ; read current value
ld d, a ; save original
and 0x7F ; clear bit 7
out (c), a ; write it
in a, (c) ; read back
bit 7, a ; on Spectranext, written 0 reads as 1
jr z, .not_spectranext
; Spectranext confirmed — restore register
ld a, d
out (c), a
spectranext_get_controller_status
int8_t spectranext_get_controller_status(int8_t *wifi_connection_out, uint32_t *ipv4_out)
Fills Wi-Fi connection state and IPv4 (host byte order).
| Return | Meaning |
|---|---|
| < 0 | ROM/port failure. |
| ≥ 0 | Controller status (compare with WIFI_CONTROLLER_STATUS_*). |
On success, *wifi_connection_out uses WIFI_CONNECT_*; *ipv4_out is the IPv4 address in host order.
- C
- Assembly
uint32_t ipv4;
int8_t wifi_state;
int8_t status = spectranext_get_controller_status(&wifi_state, &ipv4);
if (status >= 0) {
// wifi_state: WIFI_CONNECT_*
// ipv4: address in host order
}
Operation ID: 0 (SPECTRANEXT_CMD_GET_STATUS)
| Register | Direction | Role |
|---|---|---|
A | in | 0 — get controller status |
DE | in | pointer to 4-byte IPv4 output buffer |
B | out | controller status (WIFI_CONTROLLER_STATUS_*) |
C | out | Wi-Fi connection state (WIFI_CONNECT_*) |
(DE..DE+3) | out | IPv4 address, host byte order |
ld de, ipv4_buf ; 4-byte output buffer
ld a, 0 ; SPECTRANEXT_CMD_GET_STATUS (0)
ld ix, SPECTRANEXT ; $3EF0
call IXCALL ; $3FFD — self-paging on Spectranext
jr c, .error
; B = controller status
; C = Wi-Fi connection state
; (ipv4_buf) filled with IPv4 in host order
spectranext_wifi_scan_access_points
int8_t spectranext_wifi_scan_access_points(void)
| Return | Meaning |
|---|---|
| < 0 | Failure. |
| ≥ 0 | Number of networks found. |
- C
- Assembly
int8_t count = spectranext_wifi_scan_access_points();
if (count < 0) {
// error
} else {
// count networks available via spectranext_wifi_get_access_point()
}
Operation ID: 1 (SPECTRANEXT_CMD_WIFI_SCAN_ACCESS_POINTS)
| Register | Direction | Role |
|---|---|---|
A | in | 1 — scan access points |
A | out | number of networks found (carry clear) |
ld a, 1 ; SPECTRANEXT_CMD_WIFI_SCAN_ACCESS_POINTS (1)
ld ix, SPECTRANEXT ; $3EF0
call IXCALL ; $3FFD
jr c, .error
; A = number of networks found
spectranext_wifi_get_access_point
int8_t spectranext_wifi_get_access_point(uint8_t ap, char *result_name)
Copies the NUL-terminated SSID for index ap (0-based) into result_name (buffer must hold up to 64 bytes).
| Return | Meaning |
|---|---|
| 0 | Success. |
| -1 | Failure. |
- C
- Assembly
char ssid[64];
int8_t r = spectranext_wifi_get_access_point(0, ssid);
if (r == 0) {
// ssid[] contains NUL-terminated network name
}
Operation ID: 2 (SPECTRANEXT_CMD_WIFI_GET_ACCESS_POINT)
| Register | Direction | Role |
|---|---|---|
A | in | 2 — get access point name |
C | in | AP index (0-based) |
DE | in | pointer to output buffer (≥ 64 bytes) |
(DE) | out | NUL-terminated SSID string |
ld c, 0 ; AP index (0-based)
ld de, ssid_buf ; output buffer, at least 64 bytes
ld a, 2 ; SPECTRANEXT_CMD_WIFI_GET_ACCESS_POINT (2)
ld ix, SPECTRANEXT ; $3EF0
call IXCALL ; $3FFD
jr c, .error
; NUL-terminated SSID written at (ssid_buf)
spectranext_wifi_connect_access_point
int8_t spectranext_wifi_connect_access_point(const char *ssid, const char *password)
| Return | Meaning |
|---|---|
| 0 | Success. |
| -1 | Failure. |
- C
- Assembly
int8_t r = spectranext_wifi_connect_access_point("MyNetwork", "s3cr3t");
if (r < 0) {
// connection failed
}
Operation ID: 3 (SPECTRANEXT_CMD_WIFI_CONNECT)
| Register | Direction | Role |
|---|---|---|
A | in | 3 — connect |
HL | in | pointer to NUL-terminated SSID |
DE | in | pointer to NUL-terminated password |
ld hl, ssid_str ; NUL-terminated SSID
ld de, pass_str ; NUL-terminated password
ld a, 3 ; SPECTRANEXT_CMD_WIFI_CONNECT (3)
ld ix, SPECTRANEXT ; $3EF0
call IXCALL ; $3FFD
jr c, .error
spectranext_wifi_disconnect
int8_t spectranext_wifi_disconnect(void)
| Return | Meaning |
|---|---|
| 0 | Success. |
| -1 | Failure. |
- C
- Assembly
int8_t r = spectranext_wifi_disconnect();
Operation ID: 4 (SPECTRANEXT_CMD_WIFI_DISCONNECT)
| Register | Direction | Role |
|---|---|---|
A | in | 4 — disconnect |
ld a, 4 ; SPECTRANEXT_CMD_WIFI_DISCONNECT (4)
ld ix, SPECTRANEXT ; $3EF0
call IXCALL ; $3FFD
jr c, .error
spectranext_gethostbyname
int8_t spectranext_gethostbyname(const char *hostname, uint32_t *result_ipv4)
Resolves hostname to an IPv4 address; *result_ipv4 is host byte order.
| Return | Meaning |
|---|---|
| 0 | Success. |
| -1 | Failure (ROM/port or lookup error). |
- C
- Assembly
uint32_t ipv4;
int8_t r = spectranext_gethostbyname("example.com", &ipv4);
if (r == 0) {
// ipv4 contains resolved address in host byte order
}
Operation ID: 5 (SPECTRANEXT_CMD_DNS)
| Register | Direction | Role |
|---|---|---|
A | in | 5 — DNS lookup |
HL | in | pointer to NUL-terminated hostname |
DE | in | pointer to 4-byte IPv4 result buffer |
(DE..DE+3) | out | resolved IPv4, host byte order |
ld hl, hostname_str ; NUL-terminated hostname, e.g. "example.com"
ld de, ipv4_buf ; 4-byte output buffer
ld a, 5 ; SPECTRANEXT_CMD_DNS (5)
ld ix, SPECTRANEXT ; $3EF0
call IXCALL ; $3FFD
jr c, .error
; (ipv4_buf) = resolved IPv4 in host order
spectranext_enginecall
int8_t spectranext_enginecall(const char *input, const char *output, const char *operation)
Runs a named engine call with argv-style arguments in operation (space-separated; see below).
Used for heavier work such as JSONPath queries over a file.
Input file (input) — must include the mount index as a prefix: N:path where N is a single digit 0…3 selecting mount slot 0…3, and path is the path on that mount (e.g. 1:data/app.json).
Output file (output) — path on the RAM XFS volume only (no N: prefix); the result is written there.
Operation (operation) — first token is the engine name (e.g. jsonpath; the legacy name json is also accepted); further tokens are engine-specific. Example:
spectranext_enginecall("1:example.json", "example.bin", "jsonpath $[*].id $[*].name");
| Return | Meaning |
|---|---|
| 0 | Success. |
| < 0 | Failure: negative int8_t error code from the engine (e.g. -1 unknown engine, -2 I/O, -3 JSON parse, -4 JSONPath, -5 non-scalar match, -6 bad argv). |
- C
- Assembly
int8_t r = spectranext_enginecall("0:config.json", "out.bin", "jsonpath $.name");
Operation ID: 6 (SPECTRANEXT_CMD_ENGINECALL)
| Register | Direction | Role |
|---|---|---|
A | in | 6 — engine call |
HL | in | pointer to input path (N:…, NUL-terminated) |
DE | in | pointer to output path on RAM XFS (NUL-terminated) |
BC | in | pointer to operation string (NUL-terminated) |
ld hl, input_spec ; e.g. "1:file.json"
ld de, output_path ; e.g. "out.bin" on RAM
ld bc, op_str ; e.g. "json $[*].id"
ld a, 6 ; SPECTRANEXT_CMD_ENGINECALL
ld ix, SPECTRANEXT
call IXCALL
jr c, .error ; A = error code
Linking (libspectranet vs libspectranet_np)
- libspectranet.lib — Paged build: use when your program already follows the usual Spectranet paging model (see memory).
- libspectranet_np.lib — No-page stubs: often paired with an explicit
pagein()at startup when your code expects Spectranet ROM to be mapped before calling these helpers.
Exact link lines and pragma redirects match your other Spectranet projects (e.g. libterm, ndos). The SDK copies spectranext.h into sdk/include/.
See also
- Syscalls —
SPECTRANEXToperations,IXCALL, register I/O - I/O Ports —
$3400/$3401command/status - Detection —
spectranext_detect - Spectranext module — high-level module development notes