Mandelbrot for the Minimal 64 Computer #13
Replies: 3 comments 3 replies
-
Its awesome to see software being developed for the Minimal 64 :-) The BespokeASM is definitely on my list and this Mandelbrot set demo looks fantastic! Haven't tried to write this on the Minimal 64 but a while ago I put a lot of work into a simple 64-bit math library (just add, sub, compare, multiply, divide) and even wrote a 32-bit IEEE floating point lib just for the learning experience. So given your constraints (use math functions and 32-bit integer with 255 iterations) I might try my hand at this problem, too ;-) Btw, I can confirm that the emulator runs at exactly the speed you'd get on real hardware, i. e. 6MHz. |
Beta Was this translation helpful? Give feedback.
-
I'll try to complement Michael's very readable and well-generalized Mandelbrot demo by a more dirty and speed-oriented version ;-) So far I was only able to spit out pseudo-code in Processing (see below). The next week I'll be on vacation at the seaside ;-) void setup()
{
size(400, 240);
background(255);
}
void draw()
{
loadPixels();
int cb = -976;
for(int y=0; y<height; y++)
{
int ca = -2248;
for(int x=0; x<width; x++)
{
int za = ca; // start of iteration
int zb = cb;
int n;
for(n=0; n<256; n++)
{
int za_sq = (za * za)>>10;
int zb_sq = (zb * zb)>>10;
if(za_sq + zb_sq > 4<<10) break;
zb = ((za * zb)>>9) + cb;
za = za_sq - zb_sq + ca;
}
if (n == 256) pixels[x+y*width] = 0xff000000;
ca += 8;
}
cb += 8;
}
updatePixels();
} |
Beta Was this translation helpful? Give feedback.
-
Here is my version of the 'Mandelbrot' benchmark. I've deliberately used an approach complementary to Michael's. I've optimized the hell out of the code just for the fun of it and to demonstrate the 'Minimal 64's potential for multi-byte number crunching ;-). https://github.com/slu4coder/The-Minimal-64-Home-Computer/blob/main/Programs/asm/mandel.asm With a maximum of 256 iterations this code now takes ~73min in comparison to ~1380min of the generalized version - a speed improvement of almost a factor of 19. So generalization does come at a cost on the Minimal 64 ;-) When using only 16 iterations for a first impression, the whole Mandelbrot set can be rendered in 8min 20sec: :108000005530B03B8B811DFE288F811D20288E812D
:108010004A89811DFB288D811D9C288C812789819F
:1080200057278A8157278B81575536B0278C81284F
:108030009081278D81289181278E81289281278F99
:10804000812893817410279081289881289A81270C
:108050009181289981289B81552481279F8114270C
:108060009E811C289581279D811C289481279281BF
:10807000289881289A81279381289981289B815566
:108080002481279F8114279E811C289781279D8109
:108090001C2896812794812996812795812B978189
:1080A00022085E0081279081289881279181289954
:1080B00081279281289A81279381289B8155248149
:1080C000279D81289281279E81298F81289381274E
:1080D0008E814F92812794812890812795812891C4
:1080E00081279781419181279681509081278C81AA
:1080F0004F9081278D81409181785E46805539B0BF
:108100005858581D044F8C814D89815C1D802789EA
:108110008122905D1D801D044F8E813E8B8122F057
:108120005D10807F3BA08127998122005F35813CD3
:10813000A0814C9881279B8122005F43813CA081D4
:108140004C9A8166104A9C814A9E81265481539C98
:1081500081549E815398815D7081279A814F9C81C3
:108160001D00519E81279B81409D811D00519E8154
:108170006A5B4E8129A0815F88814B9C814B9E81E7
:098180004D9C811D00519E8156A9
:00000001FF
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
The thing I liked about the Minimal 64 is it integrated VGA out. It's not a flashy, multicolor display, but it's something and that made it interesting to me. The first thing I thought was that I could implement a Mandelbrot app for the computer, and so I did (link below).
Before I get to deep into what I did, a little context is warranted. I have also developed customizable assembler called BespokeASM. I did this a few years ago for my own custom CPU projects. This assembler allows you to define a custom instruction set in a YAML configuration file, and then it provides a full tool chain for that custom instruction set, including syntax highlighting in text editors like Sublime Text and VSCode. So I have created the needed configuration file that allows BespokeASM to be used for developing software for the Minimal 64.
The reason while this is relevant for the Mandelbrot software is that I wrote the Mandelbrot algorithm using 32-bit signed integer math. Dealing with 4-byte values can be tedious in the low-level Minimal 64 instruction set, and one of the features that BespokeASM supports is the definition of instruction macros. So my Mandelbrot software makes heavy use of macros designed for 4-byte value manipulation.
As indicated, the Mandelbrot software I wrote does its computation with signed 32-bit integers. There was another design consideration was that I did want to have some generality in the software I wrote. Specifically, the 32-bit math routines such as multiplications, arithmetic right shifting, and even comparison, were implemented as functions I could re-use in other projects. The downside is that generality does come at a speed cost as the values being operated on need to be moved around more than they would if I wrote the operations inline with the Mandelbrot program. While I didn't want the program to be super slow, it wasn't my goal to make it super fast either. Nonetheless, I did make one design trade off for speed: I made the Mandelbrot algorithm max out at 255 iterations (modern computers frequently use 1000 iterations). This does improve the speed of the algorithm, but does create some "fuzziness" around the edges of the Mandelbrot set. It's not bad, but if you look close you will notice it.
So the speed of the of generating a 400x240 pixel Mandelbrot image is slow. It took about a day on the Processing emulator. I don't have the Minimal 64 hardware yet ... still waiting on delivery of those out-of-production 74HC4078 chips ... so I cannot confirm if the speed is similar on real hardware.
If you would like to try out the Mandelbrot software, you can get it here:
The file
mandelbrot.min64
is what you'd assemble to produce the Intel Hex output that can then be entered into the Minimal 64 using thereceive
command followed by arun 8000
command in the Minimal 64 OS. The code is written in a such a way that you can experiment some with the image generation, such as changing the value range over which the Mandelbrot is generated or even the image size.If you are too impatient for assembling the software yourself, here is the Intel Hex you can use directly:
Beta Was this translation helpful? Give feedback.
All reactions