libterm API Reference
libterm is a small z88dk static library (libterm.lib) available on Spectranext SDK. It redirects standard output from C programs to a dedicated I/O port that Spectranext decodes; the firmware captures that and forwards it over USB CDC when a host is connected (see Logging and terminal stdout).
Unlike other libraries, libterm does not require separation as implementation does not depend on paging. Even when unpaged, libterm can produces output by means of a port output.
I/O port
Characters are sent with:
OUT (C), A with BC = $043B
Spectranext treats writes whose bus address satisfies (address & $043B) == $043B as terminal stdout bytes. Using BC = $043B in Z80 OUT (c), a matches that decode.
Provided symbols
The library includes assembly objects such as:
spectranext_fputc_cons/_spectranext_fputc_cons— console character output used by the z88dk console/fputcpath for the Spectrum target.
Exact object files are listed in spectranet-firmware/z88dk/libterm/libterm.lst at build time.
Linkage (z88dk / CMake)
Link libterm together with libspectranet (and your usual Spectranext SDK flags). You must also link either the minimal C runtime libndos or the SPDOS filesystem library libspdos:
| Scenario | Typical libraries |
|---|---|
No VFS/filesystem in C, only printf / stdout | libndos, libterm, libspectranet |
Using open / read / write via SPDOS | libspdos (instead of libndos), libterm, libspectranet |
Classic z88dk stdio expects a writebyte implementation for file-descriptor stdout. That comes from libndos or libspdos. If you link libterm without either, you will get an undefined symbol: writebyte link error.
Either libndos or libspdos must be linked whenever you use libterm.
You must also pass -pragma-redirect:fputc_cons=spectranext_fputc_cons to the linker (see your SDK / example CMake project).
CMake example (Spectranext SDK)
target_link_options(myprogram PUBLIC
-pragma-redirect:fputc_cons=spectranext_fputc_cons
)
target_link_libraries(myprogram PUBLIC
-lndos
-llibterm
-llibspectranet.lib
)
With SPDOS instead of ndos (same fputc_cons redirect):
target_link_options(myprogram PUBLIC
-pragma-redirect:fputc_cons=spectranext_fputc_cons
)
target_link_libraries(myprogram PUBLIC
-llibspdos.lib
-llibterm.lib
-llibspectranet.lib
)
Keep libterm after the runtime library you choose so that the intended stdout/console behaviour is resolved consistently (follow your SDK’s usual link order if documented).
Building and installing
libterm is part of Spectranext SDK.
See also
- Logging and terminal stdout — end-to-end capture and examples in C, assembly, and BASIC
- libspdos — when using libspdos for filesystem I/O
- SDK setup —
SPECTRANEXT_SDK_PATHand CMake import