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”

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”
Design a site like this with WordPress.com
Get started