This program generates Mandelbrot and Julia set fractal images using 32-bitinteger arithmetic specific to the 386 microprocessor. It will politelyrefuse to execute if it finds itself on any earlier Intel processors suchas the 8086, 80186 or 80286. The program will work with CGA, EGA, MCGA,VGA, "tweaked" VGA, and many popular super-rez adapters, and can switchdisplay modes on-the-fly for those adapters capable of multiple emulation.For instance, I can run this program in any of the IBM CGA/EGA/MCGA/VGAmodes on my PS/2 model 80. The program does not perform any floating pointarithmetic in its image generation routines, and does not require an FPU.

To start the program, simply type its name (FRACT386) without any parameters.When the program fires up, it displays a startup screen explaining how itworks, and then waits for you to hit a Function Key (F1, F2, etc) to selectan initial video mode (see the table below for a partial list of supportedadapters and video modes). You can also hit the ENTER (Return) key to seea complete list of the video adapters and video modes currently supportedby the program and the function keys you can hit to activate them. As soonas you select a video mode, the program begins drawing an initial displayof the full Mandelbrot set. From this point on, and AT ANY TIME, you canhit any of the following keys to select a function:

PageUp Display and Shrink the Zoom Box ("Zoom In") PageDown Display and Expand the Zoom Box ("Zoom Out") Cursor Keys Display and Move the Zoom Box Left, Right, Up, or Down ("Pan") Ctrl-Cursor-Keys Pan like the normal Cursor-Keys, but (five times) faster (NOTE: Fast-Panning works only with an Enhanced Keyboard BIOS) End or Enter Redraw the area inside the Zoom Box as a full-screen image (If there is no Zoom Box, just re-draw the current screen) F1,F2,F3,F4... Select a new Video Mode and THEN perform a Screen Redraw Currently supported video modes include: F1 = 320x200 16-color EGA/VGA F2 = 640x350 16-color EGA/VGA F3 = 320x200 256-color MCGA/VGA F4 = 640x480 16-color VGA F5 = 320x200 4-color CGA F6 = 640x200 B&W CGA F7 = 640x350 B&W EGA/VGA F8 = 640x480 B&W VGA F9 = 640x200 16-color EGA/VGA ..etc...etc.. (For a complete list, hit the ENTER key at the Startup Screen) Home Redraw the Previous Screen (the program tracks 100 screens) (this gives you the ability to "back out" screen-by-screen) Tab Display the Current Screen or Zoom-Box coordinates (this gives you the ability to track where you are and re-start the program at your current position later on) Spacebar Toggles between Mandelbrot images and their corresponding Julia set images (read the Julia set notes below before trying this option if you want to see anything interesting) < or > Lower or Raise the maximum iteration count by 50 (the default value is 150, the allowable range is 50 - 1000) ((Note: the unshifted equivalents (comma, period) also work)) = Display the current maximum iteration count (in case you've forgotten what it was) 1 or 2 Select single-pass (the default) or dual-pass mode. Dual-pass mode generates a "coarse" screen first using (2x2) pixel boxes, and then generates the rest of the dots with a second pass. (same net speed and final display, but with a quick-preview) + or - (For VGA adapters) Rotate the Video DAC up or down one color. Hold down a key for exploding fractals! Whee! (sorry) s or S Save the screen contents to disk (default = FRACT001.GIF) To display its progress, the program colors the left-most and right-most dots as it saves the screen, top to bottom. The saved files are readable by GIF viewers (I use PICEM). Insert Restart the Program all over again at the Startup Screen (in case you forgot the instructions or need to see the Video Mode list again) Delete or Esc Stop the Program and Return to MSDOS

============================================================================= Mouse Support

If you have a mouse, FRACT386 now supports it, thanks to the contributionsof Michael Kaufman. He added mouse encoding to FRACT386 (which I thenhacked up beyond all recall, so any bugs in the code are probably mine - Bert)The mouse encoding is as follows:

Left Button: Brings up and sizes the Zoom Box. While holding down the left button, push the mouse forward to shrink the Zoom Box, and pull it back to expand it. Then let go of the button and move the mouse around to "pan" the Zoom Box (with no buttons held down, you are in "fast-pan" mode).

Right Button: When the right button is held down, the "panning" operation switches from "fast-pan" to "slow-pan" mode, giving you better control over the location of the Zoom Box.

Both Buttons: (or the middle button, if you have three of them) Redraws the area inside the Zoom Box over your full screen.

Zoom and Pan using the mouse typically consists of pushing in the leftbutton, sizing the zoom box, letting go of the button, fast-panning tothe general area, pushing in the right button and slow-panning to theexact area you want, and then (still holding down the right button) tappingthe left button to perform the Zoom.

Remember, you do NOT have to wait for the program to finish generating thefull screen display (a process that can take from 30 seconds in "Low-Rez" EGAor MCGA mode to several minutes in full VGA mode) before hitting one of theabove keys. If you hit a keyboard key while the program is generating ascreen image, it will simply stop and process the key (it will NOT finishthe display, though). If, say, you see an interesting spot you want to zoomin on, don't wait -- do it! If the program finishes a display before youhit any keys, it will simply beep and wait for you to hit one.

Hints: The most interesting areas are the border areas where the colors arechanging rapidly. Zoom in on them for the best results. The areas closerto the outside of the fractal "egg" tend to involve fewer iterations anddisplay more quickly than those closer to the inside. The solid blueinterior is the slowest region of all to display -- in fact, it's wherethe program has hit its iteration maximum (150) and given up.

Another hint: The time it takes to generate a fractal image is directlyproportional to the resolution of the selected video mode (more dots = morecalculations). I always select a low-resolution mode (I use F3 for MCGA)on the startup screen, and at some later point hit a function key insteadof the END key to switch to a higher resolution mode (I use F4 for VGA)when things get interesting. That gets me into the interesting stuff indetailed resolution quickly -- I've seen that first screen too often toget excited about it. Actually, with its 256 colors (the program is"only" using the first 150), MCGA mode can give you some pretty spectaculareffects on its own.

A final hint: Try using the '2' key to get dual-pass mode. Dual-passmode makes an initial sweep of the screen calculating every fourth pixeland using it to display a 2x2 pixel box, and then calculates the other threepixels in a second, "clean-up" sweep. The total time it takes to generatea full screen is the same as in single-pass mode, and the final display isidentical, but you get a quick scan early for zooming purposes.

****** Optional Command Line Arguments ******

FRACT386 accepts optional arguments that allow you to better controlsuch things a video modes, iteration limits, and startup display areas.NOTE that the current argument list is (a lot better, much more exapandable,but) totally incompatable with the argument lists of FRACT386 versions priorto version 5.1. The full FRACT386 command line is:

FRACT386 [argument] [argument] ...

where the individual arguments are separated by one or more spaces (anindividual argument can NOT include spaces), can be in any order or(upper/lower) case, and can be any of the following:

Argument Example Description

inside=nnn inside=0 Set the color of the Mandelbrot Interior (in this example, to black)maxiter=nnn maxiter=500 Set the starting iteration maximum (between 50 and 1000, please)iterincr=nnn iterincr=32 Set the interation increment (what happens when you hit '')video=xxxxx video=f4 Set the initial video mode (and bypass the startup screen)savefile=xxxxxx savefile=myfile Set the filename (myfile.gif, here) to use when you press the 's' key.julia=creal/cimag julia=-0.480/0.626 Begin with a Julia set with this (real and imaginary) starting valuecorners=xmin/xmax/ymin/ymax Begin with these Coordinates corners=-0.739/-0.736/0.288/0.291 instead of the default values

The 'julia=' and 'corner=' arguments let you re-create images that you orothers have generated in previous sessions of FRACT386 or other fractalgeneration programs. The julia set and corner values can be displayedat any time in FRACT386 by hitting the TAB key.

A warning about the 'video=' option: EVERY version of FRACT386 (includingthis one) has been introduced with a bigger, better, and generally shuffledaround Video Table. BE CAUTIOUS about using this argument and thendownloading future versions of FRACT386, particularly if you are usingthe "Super-VGA" modes near the end of the video table.

***** Toggling between Mandelbrot and Julia Sets *****

FRACT386 can be toggled between Mandelbrot images and their correspondingJulia sets. What is a Julia set? I don't really know either, but I candescribe how the program generates them. Let's start with a diversionarytactic and describe how the program generates the Mandelbrot set. TheMandelbrot set is generated by assuming that each pixel on the screenrepresents a point on the complex-number "C plane", (X + i*Y), and calculatingthe following function until the "size" of Z(n) is greater than 2 :

Julia sets use a slightly different tactic, picking out a specific pointon the "C plane" and assuming that each pixel on the screen representsan initial point on the "Z plane". Once everything has been started up,however, the calculations are the same:

In either case, the pixel's color is arbitrarily determined by thenumber of iterations it took the program to get Z "large" enough tobail out of the loop.

Generating Julia sets are different from generating Mandelbrot sets inseveral important ways:

(1) There is only one Mandelbrot set but, given that there are an infinitenumber of values available for the complex-number C, there are an infinitenumber of Julia sets.

(2) Although there are an infinite number of Julia sets, a lot of themare pretty boring. Only certain ranges of C result in interestingJulia set displays - values too "small" generate a simple circular display,and values that are too "big" generate something that looks like scattereddust.

(3) It turns out, however, that the coordinates of the most interestingportions of the Mandelbrot image, where the colors are changing rapidly,are the VERY SAME values that generate the most interesting Julia sets.(There is a very sound mathematical reason for this. I haven't the vaguest idea what it is, though.)

What FRACT386 does is begin with the full Mandelbrot set, give you the capability to zoom and pan around generating interesting Mandelbrot images,and then AT ANY POINT hit the spacebar toggle to "flip" to a full Julia setwith startup constant C set to the coordinates at the center of the Mandelbrotimage that you last generated. From that point, you are zooming andpanning around in a Julia set "Z plane" (you can always hit the spacebartoggle again to get your Mandelbrot set back). You can think of it this way:all those fantastic Mandelbrot images you have been generating are justa way to select an initial value for Julia sets you can play with!Holy infinity, Batman!

FRACT386 uses a Video Adapter Table in the "C" program to referenceeverything it needs to know about any particular adapter/mode combination.This table can contain information for up to 76 adapter/mode combinations,and is automatically tied to seventy-six Function Keys (F1-F10, their Control/Shift/Alt variants, and many Alt-x keypad combos) when the program is running.The table entries, and the function keys they are tied to, are displayedon your screen if you hit the ENTER key at FRACT386's startup screen.This table makes adding support for various third-party video cards andtheir high-rez modes much easier, at least for the ones that pretend to bea standard adapter with more dots and/or colors.

The assembler object code (FRASM386.OBJ) is included in the ARC files tomake it easier for those of you that have a fancy video adapter and want tomodify FRACT386 to support it. You will at a minimum need a "C" compilerthat supports "Medium" model object code (Microsoft or Borland will work)and enough information about your adapter to throw it into one of its uniquemodes via INT 10.

[Chris Green didn't have a "C" compiler handy, so he modified theprogram's video adapter table using DEBUG when he was testing the Paradiseadapter entries -- it was an act of desperation, but it worked. And the.EXE file isn't run through EXEPACK anymore, so it's easier now.]

The table as currently distributed begins with nine standard and severalnon-standard ("tweaked") IBM video modes that have been exercised successfullywith a PS/2 model 80. These entries, coupled with the descriptive commentsin the table definition and the knowledge you have about throwing your adapterinto its unique modes, should be all you need to see to be able to add yourown entries.

SPECIAL NOTE ON "TWEAKED" VGA MODES: The IBM VGA adapter is a highlyprogrammable device, and can be set up to display many video-mode combinationsbeyond those "officially" supported by the IBM BIOS. The assembler programin FRACT386 contains code that sets up the IBM VGA adapter (or any trulyregister-compatable clone) for several extended modes - such as 704x528,736x552, 768x576, and 800x600. The program accomplishes this by programmingthe VGA controller to use the fastest dot-clock on the IBM adapter (28.322Mhz),throwing more pixels on the screen, and reducing the refresh-rate to make upfor it. Note that these modes push many monitors beyond their rated specs,both in terms of higher pixel resolution and lower refresh-rate. Signs thatyour monitor is having problems with a particular "tweak" include: vertical orhorizontal overscan (displaying dots beyond the edges of your visible CRTarea), annoying "flicker" (caused by a too-slow refresh-rate), and "rolling"or total garbage on the screen (your monitor simply can't keep up, or isattempting to "force" the image into a pre-set mode that doesn't fit).I have successfully tested the modes up to 768x576 on an IBM PS/2 model 80connected to IBM 8513, IBM 8514, NEC Multisync II, and Zenith 1490 monitors(all of which exhibit some overscan and flicker at the highest rates), andhave tested 800x600 mode on the NEC Multisync II (although I had to fiddlewith the vertical size knob some to get it to display correctly).

UNTESTED (note the emphasis) support for a number of popular high-rezvideo adapters has been added to the table from an information sheet thatshows up sporadically on USENET (and later adjusted based on alternate listsand user feedback). Because the information on the sheet is somewhat sparse,I was forced to use the BIOS method for reading/writing dots for each of theseadapters. Specs for the Everex EVGA board are courtesy of Tom Moran (tmoranon BIX). Specs for the Video-7 board are courtesy of Ira Emus (irae on BIX).Other specs came from a list compiled by GRAFX and supplied by Juan Orlandini(juan on BIX). (Specs for the VEGA VGA board have "?" added to them becauseI now have two lists with CONFLICTING specs on that particular board.Nobody has complained yet about the old listing, but another claims that itis programmed the same way as a Video-7 VRAM VGA. Confusion reigns.) Notethat many "competitive" Super-VGA boards actually use identical chip sets,(Paradise, COMPAQ, Dell) and are programmed in an identical manner!I tried calling up each of the "major" video board manufacturers (defined asthose paying for full-page ads in magazines like BYTE and PC) several timesto get the specs for their boards, but never got through to any technicalsupport people - unless they were the ones playing the MUSAK while I was onhold. And boy, was I on hold.

If you have a favorite adapter that you would like added to the standardreleases of FRACT386, just give me the table entry that you added to getit working. You will be credited in the comments which display with theinitial list of adapters ("Courtesy of John Smith"). If you have a favoriteadapter that you would like added, but don't have the equipment to add ityourself, just provide me with the following information:

The name of the Adapter/Video mode combination The resolution (pixels across, pixels down, number of colors) How you get it into its special mode (hopefully it's a variant of BIOS interrupt 10H, with AX/BX/CX/DX = some specific values) How the assembler routine should access it in its write-a-dot and read-a-dot routines. Current options are: 1) use the BIOS (INT 10H, AH=12/13, AL=color) ((SLOW)) 2) pretend it's a super-res EGA/VGA 3) pretend it's a super-res MCGA (If you're not sure, have me use the BIOS or get me a programmer's manual. Note that using the BIOS to read/write dots can make it tough to keep up with the keyboard during zoom/pan box operations)

I will add the adapter to my list, with a status of "UNTESTED: may not work",and will change the status to "Tested OK by John Smith" on future releases ofFRACT386 after getting confirmation from you or someone else that it works.Which brings up another point: If you can confirm that a particular videoadapter/mode works (or that it doesn't), and the program says it is UNTESTED,please get that information to me. Thanks.

***** Limitations and Uglies *****

This program uses 32-bit integer math to generate fractals quickly (I do nothave an FPU, and "normal" fractal packages take hours to draw on my machine).The advantage of this option is speed: quite simply, this is by far thefastest fractal package that I have ever seen on a 386-class machine. Thedisadvantage, aside from the fact that it cannot run on 80286-and-belowprocessors, is accuracy. To keep as much accuracy as possible, the programrepresents numbers like 1.00 as 32-bit integers of the form [1.00 * (2**29)](approximately 500,000,000). This yields over 8 significant digits ofaccuracy, and works just great -- until the initial values of the fractalcalculations on consecutive pixels differ only in the ninth decimal place.At that point, the program does the best it can do -- it switches to itsminimal drawing mode, with consecutive pixels in both directions havinginitial values differing by 1 (really 0.000000002) and disables zoomingand panning. This happens more often than you might think, only becauseit's so easy (and fascinating) to zoom in on a tiny piece of the previousscreen -- and you can force this situation with your seventh consecutive"maximum zoom", each of which zooms in on about 1% of the previous screen.If it's any consolation, remember that this situation occurs when you areattempting to draw an area over your full screen that is approximately1/(10**13)th [~0.0000000000001] of the area of the full Mandelbrot set ***-- and you can always hit the "Home" key to get the previous screen(s) back.

*** Or, you can think of it this way: First, draw the full Mandelbrot set in full VGA mode. Then zoom in on an area represented by a SINGLE PIXEL (which you can't do with the current program) and re-draw it as a full-screen image. Then zoom in on an area represented by a single pixel of THAT screen and re-draw IT as a full-screen image. Your screen is now displaying an area representing ((1/(640*480))**2)th [~0.00000000001] of the area of the area of the full Mandelbrot set - not yet in minimal drawing mode. Try it a THIRD time, though, and you'll reach it - but not if you can contain yourself and zoom in on an area no smaller than 1/100th of the third screen.

Also, this being a public domain program and being true to that spirit, theprogram makes no attempt to verify that your video adapter can run in themode you specify, or even that it's really there, before writing to it.It also assumes that every EGA adapter has a full 256K of memory (and cantherefore display sixteen simultaneous colors in 640x350 resolution), butdoes nothing in particular to verify that fact before throwing pixels at it.

*** Background ***

This program started out as a modification of the Mandelbrot set programdistributed (on BIX) by Doug Klein as DKMANDEL.ARC. I have also downloadedand read the excellent description on Fractal calculations that is part ofTron Hvaring's FRACT12.ARC program (also on BIX). I kept adding this andreplacing that to Doug's code, until one day I looked around and couldn'tfind any of his code lying around anymore, so I guess it's now an originalprogram...

I have a PS/2 model 80 without an FPU, and all the Mandelbrot programsI could find on BIX ran slow as molasses using FPU emulation, so Ideveloped code to use 386-specific arithmetic along with a few othertricks to speed things up. If I say so myself, I think this version setsnew speed records. Clock the basic mandelbrot set using 150 iterations(that's the first screen the program draws) in MCGA mode on a 16MHZ PS/2model 80 without an FPU in 26 seconds, or in full VGA mode in 125 seconds!

I would like to be able to claim that re-writing what is traditionallyFloating Point arithmetic as scaled 32-bit integer arithmetic was my idea,but the truth is that I first saw it done by Dave Warker of HDS about a year ago when he wrote a Mandelbrot generator for a TI34010-based videodisplay that HDS was going to throw into a graphics terminal. When Igot the idea to do the same thing on a PS/2 model 80, I first called Dave tofind out how he accomplished it. I may not be very creative, but I knowgood code when I steal--uh--see it.

(No, Dave doesn't mind -- in fact, he was one of the guys responsiblefor getting me the Scientific American articles on Julia sets and then eggingme on to adding them to FRACT386. The TAB key display was also addedat his request so that, in his words, "someone could compare screens with,say, something on his MAC II". Dave uses a MAC-II as his "home" computer.)

After I got it running real fast and started showing it around toeverybody (see that! that's mine! WOW, that's fast!) I discovered thatnobody was particularly interested in playing with it, primarily becausethe original user interface was less than spectacular (re-read the argumentsthat use four floating-point numbers to start FRACT386 on a particularpiece of the fractal plane -- then picture that as the ONLY way to select anarea to draw). That's when I added the zoom-and-pan interface. It has passeda pretty robust ease-of-use test -- my seven year old likes to play with it.

This code was compiled using Microsoft C (version 5.1) and MicrosoftAssembler (also version 5.1) using the "Medium" model. Note that theassembler code uses the "C" model option added to version 5.1 (just becauseI thought it was neat), and must be assembled with the /MX switch to linkwith the "C" code. The "C" code is pretty simple (and simple-minded).The assembler code, however, is tweaked to the hilt for performance reasons.

This is public domain software. There is no warranty or acceptanceof liability either expressed or implied with it. Use it, modify it,distribute it as you wish. Your uploading it to other bulletin boards andthe like is specifically encouraged.