Using ZX BASIC
The ZX Spectrum was famous for its BASIC interpreter, which was significantly faster than other home computers’ BASIC variants in 1982. However, the compiled variants that emerged later were much faster. BASIC became a viable alternative to writing games and applications in assembly language.
With the ZX BASIC extensions, including graphics utilities, user-defined functions, and a powerful array handling facility, developers could create useful programs, including animation and sound effects.
However, BASIC still ran as an interpreted language, which means the computer had to process the source code line by line, which limited the execution speed of BASIC programs. This issue, and the emergence of BASIC compilers, including HiSoft BASIC, gave birth to new possibilities.
Boriel’s ZX BASIC (you can find it here) is a BASIC dialect similar to the original Sinclair BASIC. It fixes many issues found in the original language, such as proper subroutine handling and local variables. It compiles BASIC source code to Z80 binary code, which runs much faster than interpreted BASIC.
Klive supports Boriel’s ZX BASIC with an extension that allows you to write BASIC source code and create ZX Spectrum executables.
ZX BASIC Files
Files with the .bas
extension are automatically recognized as ZX BASIC files. You can open a Klive project and create a new ZX BASIC source file:
Using ZX BASIC
When you create a ZX BASIC file, you can write your source code using ZX BASIC syntax. When you open a .bas
file, you can see four build-related icons in the document tab bar:
Click the rightmost icon (with the “play” sign) to compile and run the code:
You can also try keyboard shortcuts to trigger these actions: F7
to compile, Ctrl+F7
to inject code into memory, Shift+F7
to run the code, and Ctrl+Shift+F7
to run it in debug mode.
Handling Errors
When you run the code, the compiler checks the syntax. If there are any errors, the IDE displays them in a list in the Output panel. You can click an error to navigate to its location in the source code.
Debugging
You can run your code in debug mode by clicking the last icon in the document tab bar or pressing Ctrl+Shift+F7
. In debug mode, the IDE will stop at any breakpoints you set in your code.