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
| Machine | Machine ID | default | zx-basic | sjasmplus | pasta-80 | z88-dk |
|---|---|---|---|---|---|---|
| ZX Spectrum 48K | sp48 | ✓ | ✓ | ✓ | ✓ | ✓ |
| ZX Spectrum 128K | sp128 | ✓ | ✓ | ✓ | ✓ | ✓ |
| ZX Spectrum +2E/+3E | spp3e | ✓ | ✓ | ✓ | ✓ | |
| Timex | timex | ✓ | ✓ | ✓ | ✓ | ✓ |
| Scorpion ZS-256 | scorpion | ✓ | ✓ | ✓ | ✓ | ✓ |
| ZX Spectrum Next | zxnext | ✓ | ✓ | ✓ | ||
| ZX81 | zx81 | ✓ | ✓ | |||
| ZX80 | zx80 | ✓ | ✓ | |||
| Cambridge Z88 | z88 | ✓ | ✓ | |||
| HT-1080Z | ht1080z | ✓ |
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
| Template | Language | Build root | Needs |
|---|---|---|---|
default | Klive Z80 assembly | code/code.kz80.asm (on the Z88, code/code.z88.asm, not set as the build root) | Nothing: the assembler is built in. |
zx-basic | ZX BASIC | code/program.zxbas | Boriel BASIC (a beta), which comes with Klive; Boriel BASIC describes setting it up and the build options. |
sjasmplus | sjasmplus assembly | code/code.asm | sjasmplus, set up as sjasmplus describes. |
pasta-80 | Pascal | main.pas | The PASTA/80 compiler, set up as PASTA/80 describes. |
z88-dk | C | code/main.c | z88dk, set up as z88dk (C) describes. |
A few details:
- The
defaulttemplate’s code starts with a.modelpragma for its machine (Spectrum48,Spectrum128,SpectrumP3,ZX80,ZX81,HT1080Z), so the assembler knows what it targets. - The ZX Spectrum Next’s
defaulttemplate is a Next program (.model next): Klive builds it into a.nexfile, 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.nexprogram has nothing to return to. ZX Spectrum Next development explains.model nextand the.savenexpragma. - On the ZX81 and ZX80, the program runs as a BASIC program: Klive puts the code into a
1 REMline and calls it. See ZX80 and ZX81. - On the HT-1080Z, the
defaulttemplate 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.cmdfile that loads withSYSTEM. See HT-1080Z Development. - The
zx-basictemplates print a welcome and start with a header for the build options. On the ZX Spectrum Next, Run and Debug load the.nexfile thatzxbcwrites. - The Cambridge Z88’s
defaulttemplate has no program yet; it gives you the project structure to start from. Itsz88-dktemplate is a complete card application: Run puts the card in slot 3, restarts the Z88 and starts the application. - The
z88-dktemplates 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 withprintfafter clearing the screen and setting the border. - The ZX Spectrum Next’s
z88-dktemplate prints withputcharinstead ofprintfand never returns frommain: a.nexprogram has no system to return to, and z88dk’s Next startup code may fail to start a program that usesprintf. 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.