6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Fri Nov 22, 2024 9:44 pm

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Wed Aug 01, 2012 2:00 am 
Offline
User avatar

Joined: Thu Mar 11, 2004 7:42 am
Posts: 362
In Yet Another Side Project, I have been monkeying with Bob Bishop's Mandelbrot routines and have recoded them for the 65C816 with 16-bit accumulator/memory and index register. I also recoded the BASIC program in (16-bit) assembly, so it should be relatively straightforward to port it to the 65org16. MASK (which is $FF to clear high bytes) probably won't be necessary on the 65org16. In fact, the reason I changed the zero page save/restore routines to use a RAM buffer instead of the stack is because JSR pushes one 16-bit quantity on the 65C816, but two 16-bit quantities on on the 65org16 (I encountered this while porting eForth). I have also included the system-specific routines (e.g. I/O, plotting) I used on the Apple IIgs, for anyone who wishes to run it on a IIgs (or an emulator), but those routines can be simply discarded for the 65org16, of course. (Incidentally, there isn't any of Bob's original code left. I've gone into a bit more detail about the differences in the documentation.)

With 16-bit math, it took just under four minutes (on an Apple IIgs in fast (2.8 MHz) mode) to generate Figure 2 (the lo-res picture from Bob's article), as compared to seven and a half minutes for the original program (I measured it at 7 minutes 17 seconds, which matches Bob's seven and a half minutes from the article). (Actually, since measuring the new routines, I've since refactored the code a bit, but it's mostly things like input and parsing, which only happen at the very beginning and aren't inside loops, so it should still be somewhere near four minutes.)

Anyway, as the subject hints at, I have written some fixed-point routines to replace some of the floating point calculations from the original BASIC program. It's not much of a library so far (I only wrote the operations needed to replace BASIC program, so you get arithmetic, but no transcendental (e.g. trig) functions), but the fixed-point are completely independent of the rest of Mandelbrot program (and are grouped together in the source code, for easy cut-and-paste).

And since it's a Mandelbrot program here are a few pictures for your viewing pleasure/annoyance. First up is a recreation of Figure 2 from the article, using the new routines. I used this for testing and comparison since it doesn't take very long to run, compared to the other pictures from the article. An explanation of why this isn't exactly the same as the picture from the magazine is in the documentation, so I won't repeat that here.

Attachment:
figure2.png
figure2.png [ 3.54 KiB | Viewed 1945 times ]


Next up are two higher resolution pictures (each 200 x 150 pixels and more colors), which use the same X and Y coordinates and magnification as the lo-res picture. (The aspect ratio is 1.)

In this picture, the timeout value was 256 (the "distance" returned by MANDEL ranging from 0 to 256 was used as a color), and the 8-bit (per color) RGB values are:

Attachment:
figure2h.png
figure2h.png [ 18.21 KiB | Viewed 1945 times ]


color 0: R = 0, G = 0, B = 0
color c+0*51+1: R = 255, G = 5*c, B = 0
color c+1*51+1: R = 255-5*c, G = 255, B = 0
color c+2*51+1: R = 0, G = 255, B = 5*c
color c+3*51+1: R = 0, G = 255-5*c, B = 255
color c+4*51+1: R = 5*c, G = 0, B = 255
color 256: R = 255, G = 0, B = 255
where c = 0 to 50

In this picture, the timeout value was 258 (the color is likewise from 0 to 258), and the 8-bit (per color) RGB values are:

Attachment:
figure2c.png
figure2c.png [ 22.84 KiB | Viewed 1945 times ]


color 0: R = 0, G = 0, B = 0
color 3*c+1: R = 255, G = 0, B = 3*c
color 3*c+2: R = 3*c, G = 255, B = 0
color 3*c+3: R = 0, G = 3*c, B = 255
where c = 0 to 85

As usual, available here:

http://www.lowkey.comuf.com/


Top
 Profile  
Reply with quote  
PostPosted: Wed Aug 01, 2012 9:32 am 
Offline

Joined: Mon Mar 02, 2009 7:27 pm
Posts: 3258
Location: NC, USA
Awesome work Bruce! I'm checking this out...

_________________
65Org16:https://github.com/ElEctric-EyE/verilog-6502


Top
 Profile  
Reply with quote  
PostPosted: Thu Aug 02, 2012 4:35 am 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8507
Location: Midwestern USA
dclxvi wrote:
In Yet Another Side Project, I have been monkeying with Bob Bishop's Mandelbrot routines and have recoded them for the 65C816 with 16-bit accumulator/memory and index register. I also recoded the BASIC program in (16-bit) assembly...With 16-bit math, it took just under four minutes (on an Apple IIgs in fast (2.8 MHz) mode) to generate Figure 2 (the lo-res picture from Bob's article), as compared to seven and a half minutes for the original program (I measured it at 7 minutes 17 seconds, which matches Bob's seven and a half minutes from the article).

That's a pretty impressive improvement. If you consider that the '816's performance scales directly with the Ø2 clock, imagine how your code would run if you could crank that IIgs up to 20 MHz. You'd have your picture in under a minute. Good job!

Quote:
Anyway, as the subject hints at, I have written some fixed-point routines to replace some of the floating point calculations from the original BASIC program. It's not much of a library so far (I only wrote the operations needed to replace BASIC program, so you get arithmetic, but no transcendental (e.g. trig) functions), but the fixed-point are completely independent of the rest of Mandelbrot program (and are grouped together in the source code, for easy cut-and-paste).

These routines could be quite useful in non-graphics situations. The code substantially resembles the 32 bit native mode integer math functions I have written to support the S51K-like filesystem I am designing for my POC unit. The use of the 65C81's 16 bit registers in arithmetic and logical operations greatly speeds up the process, as Bruce's code has demonstrated.

Quote:
And since it's a Mandelbrot program here are a few pictures for your viewing pleasure/annoyance.

Some of those pics remind me of my hospital stay last winter, when the doctors were using hydrocodone and morphine to try to keep me out of permanent darkness, and I was having narco-induced hallucinations. That bloke that was living in the wall clock in my room was real, y'know! :lol:

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
PostPosted: Tue Jul 09, 2013 12:02 am 
Offline
User avatar

Joined: Thu Mar 11, 2004 7:42 am
Posts: 362
Even as far back as the original program, something I always wanted to try, but never got around to, was using a table-driven multiplication. Well, I've finally gotten around to it (with my all-assembly Mandelbrot program) and it's quite a speed up. I started by re-measuring my all-assembly program. "Just under 4 minutes" is actually 3 minutes 45 seconds; with the table-driven multiplication it only takes 1 minute 10 seconds -- 3 times faster! (And 6 times faster than the original program.) Multiplication tables are FAST, kids.

It takes 5 seconds to generate the 1.25 megabytes of tables. There is a table of squares, and tables for the 4AB = (A+B)^2 - (A-B)^2 technique. However, the tables only need to be calculated once; it's not necessary to re-calculate any tables if you loop back to where you enter different values for X, Y, magnification, and timeout and generate a new Mandelbrot image.

The multiplication tables are only used in MANDEL1 routine, not the fixed-point routines (they still shift and loop) used for the preparatory (DX, DY, CREAL, CIMAG) calculations (which finish instantly, even in the original BASIC program).

Incidentally, porting the table-driven multiplication to the 65org16 is going to be less straightforward. Possible, of course, but it'll be more than just a couple of minor tweaks.

(Note: I haven't added any new source code at the link above.)


Top
 Profile  
Reply with quote  
PostPosted: Tue Jul 09, 2013 1:03 am 
Offline

Joined: Mon Mar 02, 2009 7:27 pm
Posts: 3258
Location: NC, USA
Thanks for continuing your work and posting, it is very interesting. I had had a misunderstanding, in my time limited research, that that has now been cleared up thanks to your post!
I had managed to make a piece of hardware to draw lines in Verilog, no tables needed there...
But now I desire to make another piece of hardware to draw circles in Verilog. Creating the A^2+B^2=C^2 tables would be the first step on power-up.

_________________
65Org16:https://github.com/ElEctric-EyE/verilog-6502


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 43 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: