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
Unix/Linux/macOS
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
Windows
Clone and install the SDK:
PowerShell:
git clone https://github.com/spectranext/spectranext-sdk
cd spectranext-sdk
.\install.bat
(or double-click install.bat)
Command Prompt:
git clone https://github.com/spectranext/spectranext-sdk
cd spectranext-sdk
install.bat
This will:
- Download and install z88dk toolchain
- Create a Python virtual environment
- Install required Python dependencies
Setup
Unix/Linux/macOS
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
You can also select this file as your environment file, or example in CLion you can select it as an environment file for your toolchain.
Windows
Use source.ps1 to set up environment in your projects.
For example, in CLion you can select source.ps1 as an environment file for your toolchain.
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
- CMake Integration - Automatic toolchain setup and convenience targets
- Headers - Spectranext API headers in
include/ - Libraries - Pre-built libraries in
clibs/
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
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