/****************************************************************************
 *			MAND4.C - Information
 *		Mandelbrot Self-Squared Dragon Generator
 *			For the Commodore Amiga
 *			    Version 2.05
 *
 *		Copyright (C) 1986,    =Robert J. Mical=
 *		Copyright (C) 1986, >>Scott D. Ballantyne<<
 *		     Placed in the Public Domain
 *
 *	This program may be distributed free of charge as long as the above
 *	notice is retained.
 *
 ***************************************************************************/

/* === IMPORTANT NOTE: =================================================
 *	If you are going to design Information pages, make sure that all
 *	lines are a maximum of 59 characters long.  Also, make sure that
 *	there are 19 lines at most per page.  These two restrictions
 *	are to allow info pages to fit on low-res fat font screens.
 *	These two restrictions combined comprise the reason why the info 
 *	pages are (and should remain) terse.
 * ===================================================================== */

#include "mand.h"

extern SHORT	Color0, Color1, Color2;
extern SHORT	UserPalette[29];
extern FILE	*console;
extern FLOAT	start_r, end_r, start_i, end_i;	/* Block bounds for set */
extern int	max_x, max_y;
extern int	max_count, color_inc, color_offset;
extern int	color_set, color_mode, color_div;
extern int	color_inset, func_num;
extern UWORD	*color_table;
extern UWORD	Compressed;

Information(page)
SHORT page;
{
	REGISTER FILE	*c;

	c = console;
	switch (page) {
case 0:
case 1:
fprintf(c, "Mandelbrot Self-Squared Dragon Generator Version %s\n", VERSION);
fputs("Copyright (C) 1985 - Robert S. French\n",c);
fputs("Vastly Enhanced (with Intuition!) by  =RJ Mical=  1985/86\n",c);
fputs("Copyright (C) 1986 - =Robert J. Mical= -\n",c);
fputs("Further enhancements and additions by S. Ballantyne\n", c);
fputs("Copyright (C) 1986, Scott Ballantyne\n", c);
fputs("Placed in the public domain ... Please read and learn!\n",c);
fputs("\n",c);
fputs("Inspired by Scientific American, August/1985\n",c);
fputs("Corrections and improvements suggested by\n",c);
fputs("\"The Fractal Geometry of Nature\"\n",c);
fputs("By Benoit Mandelbrot, W.H. Freeman and Company, 1983\n",c);
fputs("\n",c);
fputs("Robert S. French may be contacted at:\n",c);
fputs("   USPS:   2740 Frankfort Avenue\n",c);
fputs("           Louisville, Ky  40206\n",c);
fputs("   Phone: (502) 897-5096   ARPA: French#Robert%d@LLL-MFE\n",c);
fputs("=RJ Mical= may be contacted at:\n",c);
fputs("         Commodore-Amiga, Inc.\n",c);
fputs("         983 University Avenue\n",c);
fputs("         Los Gatos, CA  95030\n",c);
break;

case 2:
fputs("The four basic commands of this program are:\n",c);
fputs("G  - Generate picture\n",c);
fputs("   When this command is entered the Mandelbrot set is drawn\n",c);
fputs("   according to the current settings.  When you first run\n",c);
fputs("   this program, you can say \"G\" immediately and see \n",c);
fputs("   the entire Mandelbrot set.\n",c);
fputs("\n",c);
fputs("SH   - Show current settings\n",c);
fputs("   When you enter the command \"SH\", the current settings of\n",c);
fputs("   all of the important variables are shown.  To reproduce\n",c);
fputs("   a picture, you should copy these values down so you or\n",c);
fputs("   anyone else can re-enter the values and re-generate\n",c);
fputs("   the picture.\n",c);
fputs("\n",c);
fputs("I n  - Information pages\n",c);
fputs("   Shows page n of the information pages.\n",c);
fputs("\n",c);
fputs("Q  - Quit\n",c);
fputs("   Lets you exit back to the CLI.\n",c);
break;

case 3:
fputs("The Mandelbrot set consists of pairs of numbers, one number\n",c);
fputs("real and the other complex.  This set can be graphed using\n",c);
fputs("one axis for the real numbers and the other for the complex\n",c);
fputs("numbers.  The Mandelbrot set is located on a graph roughly\n",c);
fputs("centered over the origin (0,0).  The default settings of\n",c);
fputs("this program create a display that shows the entire set.\n",c);
fputs("All of the black display pixels represent Mandelbrot pairs.\n",c);
fputs("The shaded pixels show the pairs that are *almost* in the\n",c);
fputs("set.  The pairs nearest the set on the display just miss\n",c);
fputs("making it into the set numerically; these are white.  The\n",c);
fputs("more grey a position, the further the pair is from the set.\n",c);
fputs("    This program lets you explore the Mandelbrot set by\n",c);
fputs("panning across and zooming in to look at details of the set.\n",c);
fputs("You can also change colors and display mode.  For instance:\n",c);
fputs(" : CS 1      ; Use the fancy arrangements of color set 1\n",c);
fputs(" : CO 29     ; Set the initial color offset\n",c);
fputs(" : CI 4      ; Set the color increment\n",c);
fputs(" : MC 29     ; Set the maximum tests count\n",c);
fputs(" : G         ; Generate the picture\n",c);
break;

case 4:
fputs("The MC command lets you specify how many times each position\n",c);
fputs("is tested to see whether or not it's in the Mandelbrot set.\n",c);
fputs("A low MC value means that very few tests will be done on\n",c);
fputs("position, which will cause the display to be created more\n",c);
fputs("quickly, but which will also have a cruder approximation of\n",c);
fputs("the Mandelbrot set and, consequently, fewer colors.\n",c);
fputs("\n",c);
fputs("The MX and MY commands set the size of the display window.\n",c);
fputs("The larger your window, the longer it takes for the picture\n",c);
fputs("to be resolved.  While you're experimenting with the\n",c);
fputs("program, you should create a smaller window with a lower\n",c);
fputs("count value until you get approximately the picture that you\n",c);
fputs("want to see.  Then when you've gotten a picture you want to\n",c);
fputs("see in large scale, increase the size and count resolution\n",c);
fputs("to see the detailed version of your picture.  For instance:\n",c);
fputs(" : MC 8        ; Each position will be tested only 8 times\n",c);
fputs(" : MX 80       ; The width is 25% of full width\n",c);
fputs(" : MY 50       ; The height is 25% of full height\n",c);
fputs(" : G           ; Generate the picture\n",c);
break;

case 5:
fputs(" : CS 1        ; Color set 1 (special ranges of colors)\n",c);
fputs(" : CI 1        ; Color increment of 1 (smallest increment)\n",c);
fputs(" : MC 29       ; Count position and number of colors\n",c);
fputs("Then, by setting the initial color offset into color set 1 \n",c);
fputs("using the command CO, you can select from these ranges:\n",c);
fputs("      ======    ===========================================\n",c);
fputs("        1-15    unit steps of blue\n",c);
fputs("       16-30    unit steps of green\n",c);
fputs("       31-45    unit steps of red\n",c);
fputs("       46-60    unit steps of sky sky blue (blue and green)\n",c);
fputs("       61-75    unit steps of purple (blue and red)\n",c);
fputs("       76-90    unit steps of yellow (red and green)\n",c);
fputs("       91-115   unit steps of white (all colors)\n",c);
fputs("CM is the command to set the display mode.  Add up these:\n",c);
fputs("    o  add 1 to get NO HOLD-AND-MODIFY\n",c);
fputs("    o  add 2 to get INTERLACE\n",c);
fputs("    o  add 4 to get HIRES (640 columns; low-res is 320)\n",c);
fputs("For instance, for HIRES and NO HOLD-AND-MODIFY, add 1 + 4:\n",c);
fputs(" : CM 5\n",c);
break;

case 6:
fputs("The starting (left) and ending (right) edge values for the\n",c);
fputs("axis of the real numbers (the horizontal axis) can be set\n",c);
fputs("using the commands SR (Start Real) and ER (End Real).  For\n",c);
fputs("the complex numbers axis (vertical) the start (bottom) and\n",c);
fputs("end (top) edge values are set using SI and EI.  Got it?\n",c);
fputs("    The graph that you get with this program's default\n",c);
fputs("values has the real numbers along the horizontal axis.  The\n",c);
fputs("leftmost position represents the real number -2.85.  The\n",c);
fputs("rightmost position represents 2.85.  The complex numbers\n",c);
fputs("are charted along the vertical axis, starting at the bottom\n",c);
fputs("with a value of -2.05 and ranging up to 2.05 at the top.\n",c);
fputs("    You control the range of these axes using the text\n",c);
fputs("commands SR, ER, SI and EI.  The commands ZR and ZI let you\n",c);
fputs("zoom in or out on the real and imaginary axes respectively.\n",c);
fputs("ZB lets you zoom on both proportionally.\n",c);
fputs("    Once the display is built, there are ZOOM menu commands\n",c);
fputs("which allow you to zoom in and out automatically.  These\n",c);
fputs("are more convenient than using the text commands.  On the\n",c);
fputs("other hand, the text commands lend precision.\n",c);
break;

case 7:
fputs("OK!  Now there's plenty of new features, especially being\n", c);
fputs("able to change the colors and save pictures to the disk.\n", c);
fputs("I hope you find this newest version more useable.  -=RJM=-\n", c);
fputs("\n", c);
fputs("There's lots more to this program than what's described on\n",c);
fputs("these info pages.  You should read the available text on\n",c);
fputs("Mandelbrot sets (see info page 1).  This program has more \n",c);
fputs("features than what's described here.  If you can get your\n",c);
fputs("hands on the source, you're welcome to expand these pages.\n",c);
fputs("In fact, this program is still far from complete.  Care to\n",c);
fputs("have a bash at it?  We need the greater-precision \n",c);
fputs("floating point.  Also, we seriously need to be able to\n",c);
fputs("save some or all of the image to a disk file in IFF format.\n",c);
fputs("\n",c);
fputs("Good luck.  Have fun!  Send mail (on USENET at least!) if\n",c);
fputs("you find spectacular scenes.\n",c);
break;

case 8:
fputs("(This page describes the additions made by SDB.)\n",c);
fputs("The calculations and pixel writes are now in 68000 Assembler\n",c);
fputs("It now runs as fast as it is going to without a 68881.\n",c);
fputs("Read Picture (L) and Print Picture features have been added.\n",c);
fputs("\n", c);
fputs("A Resume feature has been implemented - this means that you\n", c);
fputs("may now stop a graph in the middle, save it, and complete it\n", c);
fputs("at a later date. Simply \"L\" filename, and select resume\n", c);
fputs("from the display menu.\n", c);
fputs("The ZOOM features will also work on saved files - either\n", c);
fputs("complete or incomplete.  These are perhaps the handiest\n", c);
fputs("features in this new version. It is now much more practical\n", c);
fputs("to investigate graphs at higher resolutions and max counts.\n",c);
fputs("It also makes it easier to continue a line of investigation\n", c);
fputs("since you don't need to regenerate the earlier graph.\n", c);
fputs("(continued on next information page)\n", c);
break;
case 9:
fputs("(continuation of preceeding info page)\n", c);
fputs("Bugs in the previous versions IFF writer are fixed (I hope).\n", c);
fputs("Also - IFF compression has been added. This saves a *lot* of\n", c);
fputs("disk space.  If you don't want compressed files, for some\n", c);
fputs("reason, you can use the CP command to change the default:\n", c);
fputs(" CP 1   ; Write compressed files (this is the default).\n",c);
fputs(" CP 0   ; Don't compress the files.\n", c);
fputs("One word of warning: Only files produced by this version of\n",c);
fputs("the program can take advantage of the new Resume features.\n", c);
fputs("\n", c);
fputs("This version may be run from Workbench - clicking on a graphs\n",c);
fputs("Icon will now cause Workbench to load this program, and\n",c);
fputs("and the program will then bring up the picture.\n", c);
fputs("Earlier versions of this program would load GraphiCraft.\n", c);
fputs("\n",c);
fputs("(continued on next page)\n", c);
break;
case 10:
fputs("(continued from preceeding info page)\n",c);
fputs("Another color setting has been added to this program.\n", c);
fputs("This is known as EXTRA_HALFBRITE mode. This mode allows\n", c);
fputs("64 colors on a lowres screen at one time - 32 of these\n", c);
fputs("are \"half intensity\" settings of the lower 32 colors.\n", c);
fputs("\n", c);
fputs("You specify this mode as follows:\n", c);
fputs(" CM 9 ; set half-brite mode\n", c);
fputs("Please note: Not all Amiga's currently in production have\n", c);
fputs("this mode. You will not damage your Amiga by selecting CM 9\n", c);
fputs("but you won't get 64 colors, either.\n", c);
fputs("\n", c);
fputs("Enjoy and Good Luck! - If you find any bugs in any of these\n", c);
fputs("new additions, please contact me (SDB) via Email:\n", c);
fputs(" CIS:    70066,603\n",c);
fputs(" BIX:    SDB\n", c);
fputs(" SOURCE: BDE712\n", c);
break;

default:
fputs("SORRY:  there's not that many pages of info available!\n",c);
AvailableCommands();
break;
	}
}

AvailableCommands()
{
	REGISTER FILE	*c;

	c = console;
/* === TRY TO KEEP THIS PAGE 18 LINES TALL AT MOST ======================== */
fputs("AVAILABLE COMMANDS:\n",c);
fputs("SH   - Show current settings        G  - Generate picture\n",c);
fputs("I n  - Information pages            Q  - Quit\n",c);
fputs("\n",c);
fputs("SR n / SI n / ER n / EI n - Starting and ending coords\n",c);
fputs("MX n / MY n - x/y display size      MC n - Max exam count\n",c);
fputs("XR n / XI n - Move to new coordinates\n",c);
fputs("ZR n / ZI n / ZB n - Zoom around the center point\n",c);
fputs("\n",c);
fputs("CM n - Graphics mode                F n - Dragon function\n",c);
fputs("CI n - Color increment              CD  - Color divisor\n",c);
fputs("CO n - Color offset                 CS  - Color set\n",c);
fputs("CT n - Color for points in set      P n - Start from Preset\n",c);
fputs("\n",c);
fputs("L name - Load picture               CP n - Compression type\n", c);
fputs("< filename - Redirect input         ; string - Comment\n",c);
}

CurrentSettings()
{
	REGISTER SHORT	i, d;
	FILE		*c;

	c = console;
	fprintf(c,"             Description  Command  Current Value\n");
	fprintf(c, "========================  =======  =============\n");
	fprintf(c, "       Start Real (Left)   SR n:   %f\n", start_r);
	fprintf(c, "        End Real (Right)   ER n:   %f\n", end_r);
	fprintf(c, "Start Imaginary (Bottom)   SI n:   %f\n", start_i);
	fprintf(c, "     End Imaginary (Top)   EI n:   %f\n", end_i);
	fputs("\n", c);
	fprintf(c, "          Function Number   F n:   %d\n", func_num);
	fprintf(c, "   Max Examination Count   MC n:   %d\n", max_count);
	fprintf(c, "               Color Set   CS n:   %d\n", color_set);
	fprintf(c, "             Compression   CP n:   %d\n", Compressed);
	if (color_set < 2) {
	  fprintf(c, "         Color Increment   CI n:   %d\n", color_inc);
	  fprintf(c, "            Color Offset   CO n:   %d\n", color_offset);
	}
	else
	for (i = 0; i < 32; i++) {
		if ((i % 6) == 0)
			fputs("Color ", c);
		switch (i) {
			case 0:
				d = Color0;
				break;
			case 1:
				d = Color1;
				break;
			case 2:
				d = Color2;
				break;
			default:
				d = UserPalette[i - 3];
				break;
		}
	fprintf(c,"%d=%d,%d,%d ", i, (d>>8) & 0xF, (d>>4) & 0xF, d & 0xF);
	if ((i % 6) == 5) fputs("\n", c);
	}
	fputs("\n", c);
	fprintf(c, "              Color Mode   CM n:   %d\n", color_mode);
	fprintf(c, "           Color Divisor   CD n:   %d\n", color_div);
	fprintf(c, "  Display Width/Height   MX/Y n:   %d %d\n", max_x, max_y);
	fflush(c);
}

