libzx - ZX Spectrum game programming library (Z80 assembly language)
During the development of my ZX Spectrum game, Husband Chores, I kept the functionality and routines which were not game-specific separate from the game-specific code. As the weeks went by, I realized that I could package up all my re-usable work into a ZX Spectrum homebrew game development library.
Thus libzx was born. It is written from scratch in Z80 assembly language, and it is intended to help with the creation of simple-to-medium ZX Spectrum homebrew games. Generally speaking, it provides an abstraction layer above the ZX Spectrum hardware, in that it hides things like video memory layout, etc., from the programmer. It has routines for the following:
  • bitmap drawing routines (XOR, masked, etc.)
  • video buffer utilities (needed for masked sprites functionality, when used in conjunction with masked bitmap routines)
  • custom font and text output
  • screen attribute functions
  • keyboard routines
  • random number generation
  • music and sound playback (looped sounds, frame-by-frame playback, etc.)

Given that this was my first non-trivial ZX Spectrum project, the performance of the routines has room for improvement. However, it should suffice for simple games by programmers looking to make headway into the interesting ZX Spectrum, just like I did.

To use libzx successfully, it's recommended that you have, at least, seen assembly language before. The Z80 processor has a relatively restrictive set of opcodes and permitted register argument combinations compared to other CPUs, such as the x86 family.
I've included some ZX Spectrum and Z80-specific documentation in the docs directory. These should help with learning through experimentation, in case you're unfamiliar with the platform.

Read more on Husband Chores, my ZX Spectrum game written using libzx.

Downloads


libzx and examples source package - this archive includes libzx, as well as all the examples. Contains all tools necessary to build all examples. Download it to start coding your own ZX Spectrum game. Just download, unzip, and run make.bat. Tested in Windows 7 64bit and Windows XP 32bit.

Examples


I have created a suite of examples to demonstrate most of libzx's functionality. They are all included with libzx in the zip archive in the Downloads section above. They are also hosted in a JavaScript emulator, available to try out immediately, in your browser.

You can try out all libzx examples in your browser.


example 0 - text output and attributes

download the examples and libzx from the Downloads section above.

try out all libzx examples in your browser


example 1 - keyboard routines

download the examples and libzx from the Downloads section above.

try out all libzx examples in your browser


example 2 - XORed and masked sprites

download the examples and libzx from the Downloads section above.

try out all libzx examples in your browser


example 3 - random number generator

download the examples and libzx from the Downloads section above.

try out all libzx examples in your browser


example 4 - music and sound playback

download the examples and libzx from the Downloads section above.

try out all libzx examples in your browser


example 5 - colour cycling effect

download the examples and libzx from the Downloads section above.

try out all libzx examples in your browser


example 6 - loading a background image

download the examples and libzx from the Downloads section above.

try out all libzx examples in your browser


example 7 - comprehensive example (background, sprites, keyboard, sound)

download the examples and libzx from the Downloads section above.

try out all libzx examples in your browser