Very nicely done! I think it would be interesting to try the 16-bit "table of squares" algorithm on the same hardware. It might not be as slow as you imagine: the bottleneck on the 8088 is fetching the (instruction and data) bytes from memory, which it can do at a rate of about 1.13MHz. The 6502 has essentially the same bottleneck, but (in a BBC) can fetch bytes at 2MHz if I understand correctly. So what you lack in registers and 16-bit arithmetic you may be able to make up for with raw speed.

Here's the 8088 code I'm using for my version. Registers are:

si = x (real part of z)

bx = y (imaginary part of z)

sp = 0x1c00 (bailout radius). We set up SS so that interrupts can still occur and the stack functions as normal, but it's slightly faster to be able to use a register than an immediate constant.

ds:0 = points to the table of squares divided by 0x600 (32768 2-byte entries, all with the least significant bit 0).

cx = number of iterations remaining (the iteration loop is unrolled but we still need to know where we got to when we bail out).

es = a (real part of c)

dx = b (imaginary part of c)

Code:

mov di,[si] ; x*x
mov bp,[bx] ; y*y
lea ax,[di+bp] ; x*x+y*y
cmp ax,sp
jae escaped
dec cx
mov bx,[si+bx] ; (x+y)*(x+y)
sub bx,ax ; 2*x*y
add bx,dx ; 2*x*y+b -> new y
mov si,es
add si,di
sub si,bp ; x*x-y*y+a -> new x

So that's seven 16-bit additions/subtractions (including the comparison) and three 16-bit table lookups. This takes about 130.3 cycles per iteration on average. So if you can do it in 54 cycles or less on a 2MHz machine, you'll be beating the 8088 at 4.77MHz. Sound doable?

I'm still working on my subdivision code (getting there). And keeping track of iteration counts in a quadtree is starting to look more practical, not just for avoiding incorrect guessing but also for real-time zooming. I've also been thinking about doubling the precision (by using a table of squares that is 16384 entries of 4 bytes instead of 32768 entries of 2 bytes, and doing 12 lookups per iteration instead of 3) so that we can zoom in further.

## Bookmarks