Graphic routine in assembler (Z80) for drawing circles with ZX Spectrum.
This code was written in 2000, for pure fun and as just an exercise.
The source code is a .asm
text file that can be compiled with a Z80 assembler
like Pasmo, and run in a Spectrum emulator like the
Qaop/JS online emulator. You can use other assemblers, but with
Pasmo you can directly generate a .tap file,
ready to be loaded in the emulator. For Debian-based distributions we can install it by:
$ sudo apt-get install pasmo
Run the assembler with the --tap
or the --tapbas
:
$ pasmo -v --tapbas zxcircle.asm zxcircle.tap
Loading file: zxcircle.asm in 0
Finished loading file: zxcircle.asm in 235
Entering pass 1
Pass 1 finished
Entering pass 2
Pass 2 finished
Then we can load the .tap
in Qaop and run the example code:
RANDOMIZE USR 53000
In this video you can see a performance comparison of both the original and new algorithms.
10 FOR i=1 TO 20
20 CIRCLE 128, 80, i
30 NEXT i
40 RANDOMIZE USR 53000
You can try it online with Qaop/JS, just run the following command once inside:
RUN
The file zxcircle.asm contains two main functions: one for drawing pixels, labeled as plot
,
and another one for drawing circles, labeled circle
. Also, the file includes an
execution example placed at the address 53000, that draws a set of concentric
circles growing in size.
For drawing pixels, two lookup tables are used: tabpow2
, with powers of 2, and
tablinidx
, with the order of the 192 screen lines (remember that the ZX Spectrum
used an interlaced access).
You can invoke the routine by placing the point coordinates at the addresses 50998 and 50999, and jumping to the address 51000
POKE 50998, 128
POKE 50999, 88
RANDOMIZE USR 51000
To invoke the circle routine, you must place the center coordinates at 51997 and 51998, and the radius at 51999, and then jump to the address 52000.
POKE 51997, 128
POKE 51998, 88
POKE 51999, 80
RANDOMIZE USR 52000