Skip to Content

Project templates

When you create a project with File › New Project… or the newp command, you choose a machine and a template. A template is a small, working starting point: a build root file with a “Welcome to Klive IDE” program, and a build.ksx file that tells Klive how to build, run and export it. Press Run on a new project and it works.

Templates by machine

MachineMachine IDdefaultzx-basicsjasmpluspasta-80z88-dk
ZX Spectrum 48Ksp48✓✓✓✓✓
ZX Spectrum 128Ksp128✓✓✓✓✓
ZX Spectrum +2E/+3Espp3e✓✓✓✓
Timextimex✓✓✓✓✓
Scorpion ZS-256scorpion✓✓✓✓✓
ZX Spectrum Nextzxnext✓✓✓
ZX81zx81✓✓
ZX80zx80✓✓
Cambridge Z88z88✓✓
HT-1080Zht1080z✓

A machine’s models share its templates: the Pentagon 128 is a model of the ZX Spectrum 128K, and the +2A and +3 models are on the spp3e row. Machine types lists the models of each machine.

The templates

TemplateLanguageBuild rootNeeds
defaultKlive Z80 assemblycode/code.kz80.asm (on the Z88, code/code.z88.asm, not set as the build root)Nothing: the assembler is built in.
zx-basicZX BASICcode/program.zxbasBoriel BASIC (a beta), which comes with Klive; Boriel BASIC describes setting it up and the build options.
sjasmplussjasmplus assemblycode/code.asmsjasmplus, set up as sjasmplus describes.
pasta-80Pascalmain.pasThe PASTA/80 compiler, set up as PASTA/80 describes.
z88-dkCcode/main.cz88dk, set up as z88dk (C) describes.

A few details:

  • The default template’s code starts with a .model pragma for its machine (Spectrum48, Spectrum128, SpectrumP3, ZX80, ZX81, HT1080Z), so the assembler knows what it targets.
  • The ZX Spectrum Next’s default template is a Next program (.model next): Klive builds it into a .nex file, which Run and Debug have NextZXOS load. It switches the CPU to 28 MHz, prints with the Next’s pixel instructions (pixelad, pixeldn) and ends in a loop, because a .nex program has nothing to return to. ZX Spectrum Next development explains .model next and the .savenex pragma.
  • On the ZX81 and ZX80, the program runs as a BASIC program: Klive puts the code into a 1 REM line and calls it. See ZX80 and ZX81.
  • On the HT-1080Z, the default template prints a welcome in the middle of the screen through the ROM’s display routine, draws a block-graphics bar under it and goes back to BASIC. Run starts it from RAM at $7000; Export writes a .cmd file that loads with SYSTEM. See HT-1080Z Development.
  • The zx-basic templates print a welcome and start with a header for the build options. On the ZX Spectrum Next, Run and Debug load the .nex file that zxbc writes.
  • The Cambridge Z88’s default template has no program yet; it gives you the project structure to start from. Its z88-dk template is a complete card application: Run puts the card in slot 3, restarts the Z88 and starts the application.
  • The z88-dk templates call a small function in a loop and keep a global counter, so breakpoints, the call stack and the Variables panel have something to show. The Spectrum ones print with printf after clearing the screen and setting the border.
  • The ZX Spectrum Next’s z88-dk template prints with putchar instead of printf and never returns from main: a .nex program has no system to return to, and z88dk’s Next startup code may fail to start a program that uses printf. The ZX Spectrum Next explains both.
💡

You can change a project’s machine at any time while it is open, but the template’s code stays what it was: a program written for the 48K’s ROM does not run on a ZX81.

What a template creates

Every project has the same structure:

  • klive.project: the project’s settings (the machine, breakpoints, the build root). Klive maintains it; do not edit it by hand.
  • build.ksx: the build functions behind Compile, Inject, Run, Debug and Export. See The build system.
  • the source files of the template.

Creating a project explains the project file, the build root, and the build bar.

Applying a template to an existing folder

When you make a plain folder a Klive project, you choose a template too, and its files are copied into the folder next to yours: the build.ksx that Compile, Run and Debug need, and the sample program. A template file that already exists in the folder is replaced only when you tick it in the dialog, and the build root you choose there takes the place of the template’s own.

Last updated on