SDK Setup and Usage
The Spectranext SDK provides everything you need to develop programs for the Spectranext cartridge (and for original Spectranet). It includes the z88dk toolchain, CMake integration, and SPX tools for file transfer.
Installation
Clone and install the SDK:
git clone https://github.com/spectranext/spectranext-sdk
cd spectranext-sdk
./install.sh
This will:
- Download and install z88dk toolchain
- Create a Python virtual environment
- Install required Python dependencies
Setup
Source the SDK environment in your shell:
source spectranext-sdk/source.sh
Or add it to your shell configuration file (~/.zshrc or ~/.bashrc):
source /path/to/spectranext-sdk/source.sh
Note: The SDK environment is automatically activated when you source source.sh. No need to manually activate Python virtual environments.
Setting Up a CMake Project
Create a CMakeLists.txt file in your project directory:
cmake_minimum_required(VERSION 3.16)
# Import Spectranext SDK - MUST be before project()
include($ENV{SPECTRANEXT_SDK_PATH}/cmake/spectranext_sdk_import.cmake)
spectranext_sdk_init()
project(idetest C)
add_executable(idetest main.c)
target_compile_options(idetest PUBLIC -debug)
target_link_libraries(idetest PUBLIC -lndos -llibspectranet.lib -llibsocket.lib)
target_link_options(idetest PUBLIC -debug -create-app)
# Set boot basic program (optional)
# This creates a boot.zx file that will be uploaded before your program
spectranext_set_boot("
10 %tapein \"idetest.tap\"
20 LOAD \"\"
")
# Add convenience targets (upload_bin, upload_tap, etc.)
spectranext_add_extra_outputs(idetest)
If source.sh is not sourced then SPECTRANEXT_SDK_PATH must be explicitly provided.
Important Notes
spectranext_sdk_init()must be called beforeproject()- This is required because the SDK sets up the CMake toolchain, which must be configured before the project is defined.
Boot BASIC Program
The spectranext_set_boot() function allows you to create a boot BASIC program that will be automatically uploaded before your main program. This is useful for creating loader programs or initialization code.
Usage:
spectranext_set_boot("
10 PRINT \"Booting...\"
20 CLEAR 32767
30 %aload \"myprogram.bin\" CODE 32768
40 RANDOMIZE USR 32768
")
The function:
- Creates
boot.basin the CMake binary directory - Compiles it to
boot.zxusingzmakebas(starting at line 10) - Creates an
upload_boottarget that builds and uploadsboot.zx - When
spectranext_add_extra_outputs()is called,upload_binandupload_taptargets will automatically depend onupload_bootif it exists
Example boot program:
spectranext_set_boot("
10 REM Boot loader
20 %tapein \"myprogram.tap\"
30 LOAD \"\"
40 REM Program will auto-run after loading
")
The boot program is compiled with zmakebas -o boot.zx -a 10 boot.bas, which means it starts at line 10. Make sure your BASIC code includes line numbers or uses labels if you're using zmakebas label mode.
Available Targets
If spectranext_set_boot() was called, the following additional target is available:
upload_boot- Build and uploadboot.zxfile for your BASIC loader program.
After calling spectranext_add_extra_outputs(project_name), the following targets are available:
project_name_upload_bin- Build and upload.binfileproject_name_upload_tap- Build and upload.tapfileproject_name_bin_autoboot- Build, upload.bin, and configure autobootproject_name_tap_autoboot- Build, upload.tap, and configure autoboot
Building and Uploading
# Configure CMake (if not already done)
cmake -B build
# Build and upload .bin file
cmake --build build --target idetest_upload_bin
# Build and upload .tap file
cmake --build build --target idetest_upload_tap
# Build, upload, and configure autoboot
cmake --build build --target idetest_bin_autoboot
SDK Components
- z88dk - Z80 cross-compiler toolchain
- SPX Tools - Command-line tools for interacting with Spectranext (
spx-ls,spx-get,spx-put, etc.) - CMake Integration - Automatic toolchain setup and convenience targets
- Headers - Spectranext API headers in
include/ - Libraries - Pre-built libraries in
clibs/
SPX Tools
The SDK provides command-line tools for interacting with Spectranext:
Spectranext filesystem tools
You can read more about XFS tools here: Syncing with Computer
spx-ls [path]- List contents of RAMFS on Spectranext cartridgespx-get <remote> <local>- Download file from devicespx-put <local> <remote>- Upload file to devicespx-mv <old> <new>- Move/rename filespx-rm <path>- Delete filespx-mkdir <path>- Create directoryspx-rmdir <path>- Remove directoryspx-reboot- Trigger ZX Spectrum rebootspx-autoboot- Configure autoboot from xfs://ram/ and rebootspx-terminal- Launch minicom terminal on console port
Run spx-help for a list of available commands.
Environment Variables
The SDK sets the following environment variables:
SPECTRANEXT_SDK_PATH- Path to the SDK root directorySPECTRANEXT_TOOLCHAIN- Path to the CMake toolchain fileSPECTRANEXT_INCLUDE_DIR- Path to SDK include directoryZCCTARGET- z88dk target (default:zx)SPX_SDK_DIR- SDK directory for SPX toolsZCCCFG- z88dk configuration pathPATH- Includesz88dk/bin
Development Workflow
Typical Workflow
- Source SDK:
source spectranext-sdk/source.sh - Create CMake Project: Set up
CMakeLists.txtwith SDK integration - Develop: Write your code
- Build: Use CMake to build your project
- Upload: Use convenience targets to upload to device
- Test: Test on Spectrum hardware
Example Project Structure
my-project/
├── CMakeLists.txt
├── main.c
└── build/ # CMake build directory
Complete Example
CMakeLists.txt:
cmake_minimum_required(VERSION 3.16)
include($ENV{SPECTRANEXT_SDK_PATH}/cmake/spectranext_sdk_import.cmake)
spectranext_sdk_init()
project(hello C)
add_executable(hello main.c)
target_compile_options(hello PUBLIC -debug)
target_link_libraries(hello PUBLIC -lndos -llibspectranet.lib)
target_link_options(hello PUBLIC -debug -create-app)
# Optional: Set boot BASIC program
spectranext_set_boot("
10 PRINT \"Loading hello...\"
20 %tapein \"hello.tap\"
30 LOAD \"\"
")
spectranext_add_extra_outputs(hello)
main.c:
#include <stdio.h>
#include <spectranet.h>
int main() {
printf("Hello from Spectranext!\n");
return 0;
}
Build and upload:
cmake -B build
cmake --build build --target hello_upload_bin
Next Steps
- Syncing with Computer - Learn about file transfer tools
- XFS Filesystem - Access files from Spectrum programs
- Memory Architecture - Understand memory mapping