home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Overload
/
ShartewareOverload.cdr
/
games
/
fr386.zip
/
FR386.C
next >
Wrap
C/C++ Source or Header
|
1988-05-20
|
8KB
|
183 lines
/* fr386 -- 386-specific, fixed pt. mandelbrot generator for EGA or Herc */
/* graphics ... this is working but not very pretty version ... */
int switchpt, xhi, xlo, yhi, ylo, i, itermax, mcol, mrow, andit;
double xmin, xmax, ymin, ymax, newdy, newdx, dx, dy, fabs();
char key;
void (*gm)(),(*tm)(),(*pt)(); /* pointers to funtions that turn on */
/* graphics mode, turn on text mode, and plot a pt */
void egapt(), hplotpt(), tmode(), gmode(), egatext(), mode16();
int its_ega(), is_ega(), is_herc(), mandel();
main()
{
if(!is_386()) puts("SORRY! Need Intel 386!\n"), exit(0);
if(is_herc()){
mcol = 720, mrow = 348, andit = 1;
pt = hplotpt, gm = gmode, tm = tmode;
}
else if(is_ega() || its_ega()){
mcol = 640, mrow = 350, andit = 15;
pt = egapt, gm = mode16, tm = egatext;
}
else {
puts("Did not detect EGA/VGA. Do you wish to try EGA/VGA anyway?\n");
puts("(detection scheme is not foolproof)\n\ny = YES, try EGA/VGA\n\n");
if(scr_ci()=='y'){
mcol = 640, mrow = 350, andit = 15;
pt = egapt, gm = mode16, tm = egatext;
}
else puts("SORRY! Need EGA 16 color or Hercules Graphics!\n"), exit(0);
}
puts("Need instructions? (y=yes)\n"), key = scr_ci();
if(key=='y' || key=='Y'){
puts("80386 fixed pt Mandel zoom program.\n\n");
puts("Uses 386 32-bit instructions in real mode to simulate 1 megaflop\n");
puts("performance WITHOUT math coprocessor. To get 1st mandel screen, you\n");
puts("can use defaults or enter values from keyboard. After 1st screen is\n");
puts("drawn, hit a key to show box cursor. Hit 'q' to quit program. Move\n");
puts("box with cursor keys; shift with cursor keys moves box fast. Use PGUP,\n");
puts("PGDN, Home and End to alter box size and shape. Then hit <CR> (Enter)\n");
puts("to expand region in box to full screen. At low magnifications, a\n");
puts("switchpt of 30-40 removes some of the muddle in rapidly changing parts\n");
puts("of the image; for high magnifications use a switchpt > 70 to prevent\n");
puts("loss of detail. GOOD LUCK! H.W. Stockman...\n");
}
puts("Use defaults for first screen? (y=yes)\n"), key = scr_ci();
if(key=='y' || key=='Y'){
xmin=-2.0, xmax=0.5, ymin=-1.25, ymax=1.25;
itermax=200, switchpt=40; /* bug in DeSmet requires < 4 comma phrases */
puts("xmin= -2.0, xmax= 0.5\nymin= -1.25, ymax= 1.25\niter=200, switchpt=40\n");
puts("hit a key to draw 1st screen..."), scr_ci();
}
else do {
puts("ENTER xmin: "), scanf("%lf",&xmin);
puts("ENTER xmax: "), scanf("%lf",&xmax);
puts("ENTER ymin: "), scanf("%lf",&ymin);
puts("ENTER ymax: "), scanf("%lf",&ymax);
puts("ENTER switchpt (iteration to start log scale): "),
scanf("%d",&switchpt);
puts("ENTER # iterations: "), scanf("%d",&itermax);
if(itermax < 50) itermax = 50;
if(itermax > 1000) itermax = 1000;
puts("ALL OK ? \n"), key = scr_ci();
if(xmax-xmin < 0.00001) key = 'n', puts("xmax-xmin too small or < 0\n");
if(ymax-ymin < 0.00001) key = 'n', puts("ymax-ymin too small or < 0\n");
if(fabs(xmin)>4.0 || fabs(xmax)>4.0 || fabs(ymax)>4.0 || fabs(ymin)>4.0)
key = 'n', puts("absolute vals of x's and y's must be < 4.0\n");
} while(key != 'y' && key != 'Y');
(*gm)(); /* TURN ON GRAPHICS MODE */
if('q'==mandel(xmin,xmax,ymin,ymax,switchpt,itermax,mcol,mrow,pt,andit))
(*tm)(), exit(0);
/* INITIALIZE CO-ORDS OF BOX CURSOR CORNERS */
xlo = 90, xhi = 130, ylo = 90, yhi = 110;
/* DO-WHILE LOOP TO MOVE BOX CURSOR ABOUT SCREEN */
do {
key = scr_ci();
/* DRAW INITIAL XOR BOX */
for(i=xlo; i<=xhi; ++i) (*pt)(i,ylo,-1), (*pt)(i,yhi,-1);
for(i=ylo+1;i<yhi; ++i) (*pt)(xlo,i,-1), (*pt)(xhi,i,-1);
/* ALLOW BOX TO BE REPOSITIONED AND ALTERED IN SHAPE, SIZE */
do {
for(i=xlo; i<=xhi; ++i) (*pt)(i,ylo,-1), (*pt)(i,yhi,-1);
for(i=ylo+1; i<yhi; ++i) (*pt)(xlo,i,-1), (*pt)(xhi,i,-1);
if(key=='\034' && xhi<mcol-1) xhi++, xlo++; /* RIGHT AND LEFT */
else if(key=='\035' && xlo>0) xhi--, xlo--; /* CURSOR KEYS... */
else if(key=='\036' && ylo>0) yhi--, ylo--; /* UP AND DOWN */
else if(key=='\037' && yhi<mrow-1) yhi++, ylo++; /* CURSOR KEYS... */
else if(key=='8' && ylo>9) yhi-=10, ylo-=10; /* SHIFTED CURSOR */
else if(key=='2' && yhi<mrow-10) yhi+=10, ylo+=10; /* KEYS FOR FAST */
else if(key=='4' && xlo>9) xhi-=10, xlo-=10; /* BOX MOVES ... */
else if(key=='6' && xhi<mcol-10) xhi+=10, xlo+=10;
else if(key=='\312' && ylo>0) ylo--; /* PGUP | THESE KEYS */
else if(key=='\313' && ylo<yhi-1) ylo++; /* PGDN | CHANGE BOX */
else if(key=='\310' && xhi>xlo+1) xhi--; /* HOME | SIZE AND */
else if(key=='\311' && xhi<mcol-2) xhi++; /* END | SHAPE ..... */
for(i=xlo; i<=xhi; ++i) (*pt)(i,ylo,-1), (*pt)(i,yhi,-1);
for(i=ylo+1; i<yhi; ++i) (*pt)(xlo,i,-1), (*pt)(xhi,i,-1);
} while((key=scr_ci()) != 'q' && key != '\015');
/* IF RETURN KEY HIT, REDRAW REGION IN BOX */
if(key=='\015'){
dx = xmax-xmin, dy = ymax-ymin;
newdx = (xhi-xlo)*dx/(mcol-1);
newdy = (yhi-ylo)*dy/(mrow-1);
if(fabs(newdy) > 0.00001 && fabs(newdx) > 0.00001){
xmax = xmin + xhi*dx/(mcol-1); /* dx,dy SHOULD AUTO */
xmin += xlo*dx/(mcol-1); /* COERCE THESE TO */
ymax = ymin + yhi*dy/(mrow-1); /* DOUBLE... */
ymin += ylo*dy/(mrow-1);
(*gm)();
key = mandel(xmin,xmax,ymin,ymax,switchpt,itermax,mcol,mrow,pt,andit);
}
}
}while(key != 'q');
(*tm)(); /* TURN TEXT MODE BACK ON */
puts("LAST SCREEN:\n\n");
printf("x= %.5f to %.5f\ny= %.5f to %.5f\nswitchpt= %d, iter= %d",
xmin,xmax,ymin,ymax,switchpt,itermax);
}
/* mandel() IS ANALOGOUS TO L. FOGG'S VERSION IN DEC/JAN 87/88 MicroC ... */
/* ncol AND nrow ARE THE NUMBER OF COLUMNS AND ROWS THAT CAN BE DISPLAYED */
/* BY CHOSEN GRAPHICS ADAPTER/MODE; E.G., (ncol,nrow) = (720,348) FOR HERC, */
/* (640,350) FOR EGA; endcolor IS ONE LESS THAN MAXIMUM # COLORS GRAPHICS */
/* ADAPTER/MODE CAN DISPLAY; E.G., endcolor IS 1 FOR HERCULES, 15 FOR */
/* MOST EGA's; ptptr IS POINTER TO PIXEL PLOTTING FUNCTION... nmax IS THE */
/* MAXIMUM NUMBER OF ITERATIONS WE WILL ALLOW FOR MANDELBROT SERIES... */
/* DeSmet FUNCTION scr_csts() READS KEYBOARD BUFFER, BUT DOES NOT WAIT IF NO KEY */
/* WAS PRESSED ... SIMILAR TO Turbo C COMBINATION OF kbhit() AND getch()... */
mandel(Pmin, Pmax, Qmin, Qmax, switcher, maxiter, ncol, nrow, ptptr, endcolor)
double Pmin, Pmax, Qmin, Qmax;
int switcher,maxiter,ncol,nrow,endcolor;
void (*ptptr)();
{
int color,row,col,iter,mandwhile(),transform();
long P,Q,P0,Q0,dP,dQ;
long muldiv();
dP = (Pmax-Pmin)*16777216 + 0.5; /* 16777216 = 2 to the 24th */
dQ = (Qmax-Qmin)*16777216 + 0.5;
P0 = Pmin*16777216 + 0.5;
Q0 = Qmin*16777216 + 0.5;
for(col=0; col<ncol; ++col){
for(row=0; row<nrow; ++row){
P = P0 + muldiv(dP,col,ncol-1);
Q = Q0 + muldiv(dQ,row,nrow-1);
iter = mandwhile(P,Q,maxiter) + 1; /* "+1" DEPENDS ON HOW 1ST */
color = transform(iter,switchpt) & endcolor; /* ITERATION DEFINED ..... */
(*ptptr)(col,row,color);
}
if(scr_csts()=='q') return('q');
}
}
/* STUPID FUNCTION TO CHECK FOR EGA BY ROM STRING SEARCH */
its_ega()
{
int i;
char c[100];
_lmove(100,0,0xC000,c,_showds());
for(i=0; i<98; ++i)
if((c[i]=='I' && c[i+1]=='B' && c[i+2]=='M') || (c[i]=='E' && c[i+1]=='G' && c[i+2]=='A'))
return(1);
return(0);
}