libzx - ZX Spectrum game programming library (Z80 assembly language)
Last updated on December 16, 2016, 19:12 by Sebastian Mihai
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



If you use the materials on this page, or any other page on this web site, you do so at your own risk. They are provided "as is". No warranty is provided or implied. I neither guarantee that the materials will work, nor that they will not be harmful in any way.

Intellivision development - Hotel Bunny

Coverage of my projects

Interviewed in the Retro Gamer magazine

My homebrew cartridges

ZX Spectrum development - Husband Chores (in Z80 assembly language)

No Snakes! - a multiplayer game over serial port

Sega Dreamcast development - Overbearing Burgers

Snowdrop OS - my operating system from scratch, in assembly language

libzx - ZX Spectrum game programming library (Z80 assembly language)

Compact Pong - game in C# for the Pocket PC (Windows Mobile 2003)

TOTP (time-based one-time password) authenticator in C# (.Net)

aSMtris - Tetris in assembly language (x86, 16-bit)

Balanced Diet (GBA) limited edition

Gameboy Advance development - Balanced Diet

Atari 7800 development - Poetiru

Arcade ROM hacking - Knights of the Round translation

PocketStation development - Pocket Worm

Sega Game Gear development - Burgers of Hanoi GG

Pokemon Mini development - Mini Cookie

Magnavox Odyssey2 development - Red Green

Sega Dreamcast VMU development - Raining Squares

Nintendo GameCube development - Mama Bear Puzzle

Nintendo Wii development - Groundhog Puzzle

Sega Saturn development - Saturnade

Atari Jaguar development - Jagmatch

Sega CD development - Blackjack CD

Nintendo 64 development - Don't Be Square

Commodore 64 development - Tube64

Sega 32x development - Eight Queens

WonderSwan (Mono) development - Swan Driving BW

WonderSwan Color development - Swan Driving

Animal Keeper - a JavaScript and HTML5 Canvas game

3DO development - Space Invaders Invaders

Sony PlayStation development - The 11th Power

Sony PSP development - Newton Voyage

Nintendo DS development - Geoincursion

Gold of the Kingdoms - an XNA/C# homebrew game

Blue Elf 2 309-in-1 JAMMA PCB - troubleshoot controls not working

Fractals in JavaScript and HTML5 Canvas

Angry Video Game Nerd (AVGN) theme song on the Gameboy Advance

Novice calligraphy - Gothic hand, with letter guide

Video compilation of my classic console homebrew games

Seven segment display circuit with the 4511 decoder and the 4029 counter

A simple Atari 2600 joystick tester circuit

555 timer and 4017 decade counter - traffic lights circuit

Catch That LED! - an electronic game circuit

Capacitor study circuit

BlackBerry PlayBook development - Sheepish Bearings (Native SDK, OpenGL)

Neo Geo Pocket Color development - NGCollector

Neo Geo development - Neo Thunder

Atari 5200 development - Shooting Gallery

ZX Spectrum development - simple input/graphics example

Vectrex development - Scalar Ownage

Nintendo Virtual Boy development - Real Danger

Gameboy Color development - Burly Bear vs. The Mean Foxes (GBC version)

Sega Master System development - Burgers of Hanoi

Colecovision development - Mowleco

TurboGrafx-16/PC Engine development - Alddee

Atari Lynx development - Catkanoid

Nintendo NES development - Invaders must die!

Atari 2600 development - Snappy (batari basic)

Super Nintendo development - Bucket

Gameboy Advance development - smgbalib library

Airplane Vegas slot machine

Sega Genesis development - Gen Poker

(2004) Project One - first university game programming club project

Gameboy development - Burly Bear vs. The Mean Foxes

(2006) RGB Overdose - university programming contest entry