Handy Macros for usage in Z88dk or any C compiler

My list of Macros

This is a list of macros that I often use when programming with C using Z88dk.

Irrational numbers

Continue reading “Handy Macros for usage in Z88dk or any C compiler”

Converting Bresenham to Assembler (pass 3)

After optimizing my code in my last article, I was rather pleased with the performance, however, I started to notice something rather redundant about my code. I was performing several similar operations. Primarily, the program involves a lot of addition and subtraction of the same values to ensure smooth program flow. What if we combine some of those calculations?

To do this, I’m going to have to rearrange some of the program flow. Our current flow looks something like this:

Continue reading “Converting Bresenham to Assembler (pass 3)”

Converting Bresenham to Assembler (pass 2) Part 2

In my last article, I was working on optimizations on the setup portion of the Bresenham line in Z80. We were able to save some T-States and bytes with a few optimizations of each section. That part however is only run once per line. This article is going to delve into the iterative portion of this function and is going to give us our best time savings as it is run every time we plot a pixel to make our line complete.

Continue reading “Converting Bresenham to Assembler (pass 2) Part 2”

Converting Bresenham to Assembler (pass 2) Part 1

In my previous article, I presented a fairly straightforward method for converting my C code for Bresenham’s line algorithm to assembly language. It is certainly faster than the C equivalent, however, it is not optimized. In this article, we are going to improve this code and try to save some bytes and some T-States.

This article is going to be rather lengthy and will be split into 2 parts.

Before we start performing any optimizations, let’s remember the quote from Donald Knuth: “Premature optimization is the root of all evil”. To me, this means don’t optimize unless you know what the implications are going to be. So I’m not going to go too unorthodox in my optimizations and as always, test edge cases as well as general cases.

Continue reading “Converting Bresenham to Assembler (pass 2) Part 1”

Converting Bresenham to Assembler (pass 1)

It is often said that C is an assembler with long variable names and built-in functions. This is somewhat true, but not exactly. If you are trying to convert C to assembler, it is much easier to use a compiler, which is why compilers exist, but you can quite often produce faster code if you use assembler in the first place. It takes a bit of additional effort and careful planning, but it can be done just by following the original C code and knowing what that C code does in the first place. Being able to convert between the two can also allow you to be a better C programmer as well.

Continue reading “Converting Bresenham to Assembler (pass 1)”

Exploring the Bresenham Line routine

The Bresenham Line routine (https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm) was created by Jack Bresenham back in 1962. It has been described as one of the most important algorithms made for computer graphics. It allows you to use integer math to draw a line, and it’s fast.

We’re going to implement several different versions of this algorithm in C to improve its speed compared to the default algorithm listed on Wikipedia.

Continue reading “Exploring the Bresenham Line routine”

A fast pixel routine for the ZX Spectrum


In 2022 I was working on one of my silly projects and decided that I wanted to play around with some plot routines. As you may already know, plotting or placing a pixel on the screen on the ZX Spectrum is a bit tricky. This is due to the non linear nature of the ZX Spectrum display. Plotting in a controlled method requires a calculation or by using a look up table (LUT) of some sort.

Continue reading “A fast pixel routine for the ZX Spectrum”

128k Programming basics using Z88DK and the SCCZ80 compiler Lesson 13

Arkos 2 Tracker and Player

This is the thirteenth lesson of programming the 128k ZX Spectrum. Today, I’m going to write about adding music to your program. I’m not going to be writing about making the song itself but integrating the Arkos 2 player into Z88dk.

Continue reading “128k Programming basics using Z88DK and the SCCZ80 compiler Lesson 13”

128k Programming basics using Z88DK and the SCCZ80 compiler Lesson 12

Arkos 1 Tracker and Player

This is the twelfth lesson of programming the 128k ZX Spectrum. Today, I’m going to write about adding music to your program. I’m not going to be writing about making the song itself but integrating the Arkos 1 player into Z88dk.

If you missed out on lesson 11, it’s available at:

Continue reading “128k Programming basics using Z88DK and the SCCZ80 compiler Lesson 12”

128k Programming basics using Z88DK and the SCCZ80 compiler Lesson 11

Vortex Tracker and Player

This is the eleventh lesson of programming the 128k ZX Spectrum. Today, I’m going to write about adding music to your program. I’m not going to be writing about making the song itself but integrating the Vortex player into Z88dk.

Continue reading “128k Programming basics using Z88DK and the SCCZ80 compiler Lesson 11”
Design a site like this with WordPress.com
Get started