home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / w / winsr173.zip / MAINFRAC.C < prev    next >
C/C++ Source or Header  |  1992-07-20  |  17KB  |  660 lines

  1. /*
  2.    non-windows main driver of Fractint for Windows -
  3. */
  4.  
  5.  
  6. #define PUTTHEMHERE 1        /* stuff common external arrays here */
  7.  
  8. void win_cmdfiles();
  9.  
  10. /* from MSC's <dos.h> */
  11. #define FP_SEG(fp) (*((unsigned _far *)&(fp)+1))
  12. #define FP_OFF(fp) (*((unsigned _far *)&(fp)))
  13.  
  14. #include "fractint.h"
  15. #include "fractype.h"
  16. #include <windows.h>
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <search.h>
  20. #include <string.h>
  21. #include <float.h>
  22. #include <ctype.h>
  23. #include <time.h>
  24.  
  25. int cmp_line(), pot_line();
  26.  
  27. LPSTR win_lpCmdLine;
  28.  
  29. extern int time_to_act;
  30. extern int time_to_restart;
  31. extern int time_to_reinit;
  32. extern int time_to_resume;
  33. extern int time_to_quit;
  34. extern int time_to_load;
  35. extern int time_to_save;
  36. extern int time_to_print;
  37. extern int time_to_cycle;
  38. extern int time_to_starfield;
  39. extern int time_to_orbit;
  40.  
  41. extern char FileName[];
  42. char string004[2];
  43.  
  44. unsigned char textcolor[27];
  45.  
  46. extern int xdots, ydots, colors, maxiter;
  47. extern int ytop, ybottom, xleft, xright;
  48.  
  49. int fractype;
  50. extern int invert;
  51.  
  52. double ftemp, xxmin, xxmax, yymin, yymax;
  53. long fudge;
  54. double xfudge;
  55.  
  56. long xvalue, yvalue;
  57. extern long lm, linitx, linity;
  58. int maxit, bitshift;
  59. extern int color, row, col;
  60. extern    int colorstate,colorpreloaded;    /* comments in cmdfiles */
  61.  
  62. int calc_status; /* -1 no fractal            */
  63.          /*  0 parms changed, recalc reqd   */
  64.          /*  1 actively calculating        */
  65.          /*  2 interrupted, resumable        */
  66.          /*  3 interrupted, not resumable   */
  67.          /*  4 completed            */
  68.  
  69. extern int reset_periodicity;
  70. extern int cpu;
  71. extern int kbdcount;
  72. extern int max_kbdcount;
  73. extern int show_orbit;
  74. extern int orbit_ptr;
  75. extern int periodicitycheck;
  76. extern int debugflag;
  77. int integerfractal;
  78. extern int distest;
  79. int oktoprint = 0;
  80. extern int bitshiftless1;
  81. char usr_stdcalcmode, stdcalcmode;
  82. int  usr_distest;
  83. int usr_floatflag, usr_periodicitycheck;
  84.  
  85. long creal, cimag;
  86. long delx, dely, delx2, dely2, delmin;
  87. long xmin, xmax, ymin, ymax, x3rd, y3rd;
  88. double  dxsize, dysize;        /* xdots-1, ydots-1        */
  89. double delxx, delyy, delxx2, delyy2, ddelmin, xx3rd, yy3rd;
  90. double param[4];
  91. double potparam[3];
  92. int diskvideo, savedac;
  93. long calctime;
  94. int mode7text, textsafe;
  95.  
  96. #define MAXLINE  2048
  97.  
  98. long   far *lx0, far *ly0, far *lx1, far *ly1;
  99. double far *dx0, far *dy0, far *dx1, far *dy1;
  100. extern double far *temp_array;
  101.  
  102. extern unsigned char trigndx[4];
  103.  
  104. unsigned char dacbox[257][3];
  105. extern unsigned char olddacbox[257][3];
  106. double plotmx1, plotmx2, plotmy1, plotmy2;
  107. extern int MPOverflow;
  108. int dotmode;
  109. extern int pot16bit;
  110. int andcolor, resave_flag;
  111. extern int timer_interval;
  112. extern int active_ovly;
  113.  
  114. int extraseg;
  115. int timedsave = 0;
  116. int disk16bit = 0;
  117. extern int initbatch;
  118. float far initifs3d[32][13];
  119. float far initifs[32][7];
  120. extern unsigned char readname[];
  121. int rowcount;
  122. int adapter;
  123. extern int showfile;
  124. extern int initmode;
  125. extern int overlay3d;
  126. extern int display3d;
  127. extern int filetype;
  128. int comparegif = 0;
  129. int diskisactive = 0;
  130. extern int initsavetime;
  131. int saveticks = 0;
  132. int savebase = 0;
  133. int zwidth = 0;
  134. extern int (*outln)();
  135. extern int out_line();
  136. extern int outlin16();
  137. static int call_line3d();
  138. extern int line3d();
  139. extern int gifview();
  140. extern int tgaview();
  141. int hasconfig = 0;
  142. FILE *dacfile;
  143. int reallyega = 0;
  144. int loadPalette = 0;
  145. int compiled_by_turboc = 0;
  146.  
  147. int     sxdots,sydots;
  148. int     sxoffs=0,syoffs=0;
  149. int     viewwindow=0;
  150. float   viewreduction=1;
  151. int     viewcrop=1;
  152. float   finalaspectratio;
  153. int     viewxdots=0,viewydots=0;
  154. extern int filexdots, fileydots, filecolors;
  155. int frommandel;
  156.  
  157. int onthelist[100];        /* list of available fractal types */
  158. int CountFractalList;           /* how many are on the list? */
  159. extern int CurrentFractal;        /* which one is current? */
  160.  
  161. int Printer_Resolution, Printer_Titleblock, Printer_SFrequency;
  162. int Printer_SetScreen, Printer_SStyle, Printer_Type;
  163. int Printer_ColorXlat, Printer_SAngle, LPTnumber;
  164. int EPSFileType, Print_To_File, Printer_CRLF;
  165. int ColorPS;
  166. int Printer_BFrequency, Printer_BStyle, Printer_BAngle;
  167. int Printer_GFrequency, Printer_GStyle, Printer_GAngle;
  168. int Printer_RFrequency, Printer_RStyle, Printer_RAngle;
  169.  
  170. int tabmode, video_type, no_color_text;
  171.  
  172. long    l_at_rad;        /* finite attractor radius  */
  173. double    f_at_rad;        /* finite attractor radius  */
  174.  
  175.  
  176. int active_system = WINFRAC;    /* running under windows */
  177. extern int win_display3d, win_overlay3d;
  178.  
  179. int iit = 0;
  180. int vesa_detect;
  181. int far videotable[2];
  182. int release;
  183. extern int win_release;
  184. char busy;
  185. int started_resaves = 0;
  186. int gotrealdac = 1;
  187. void    (*outln_cleanup)();
  188. extern int fpu;
  189. int svga_type = 0;
  190. int TranspSymmetry;
  191.  
  192. int made_dsktemp = 0;
  193.  
  194. compare_fractalnames( const void *element1, const void *element2)
  195. {
  196. int i, j, k;
  197.     j = *(int*)element1;
  198.     k = *(int*)element2;
  199. for (i = 0; i < 100; i++) {
  200.     if (fractalspecific[j].name[i] < fractalspecific[k].name[i])
  201.         return(-1);
  202.     if (fractalspecific[j].name[i] > fractalspecific[k].name[i])
  203.         return(1);
  204.     if (fractalspecific[j].name[i] == 0)
  205.         return(0);
  206.     }
  207. return(0);
  208. }
  209.  
  210. fractint_main()
  211. {
  212. int i, k;
  213. double temp1, temp2;
  214. double dtemp;
  215.  
  216. outln_cleanup = NULL;        /* outln routine can set this */
  217.  
  218. CountFractalList = 0;
  219. for (k = 0; fractalspecific[k].name != NULL; k++)
  220.    if (fractalspecific[k].name[0] != '*' &&
  221.        (fractalspecific[k].flags & WINFRAC) != 0 &&
  222.        CountFractalList < 100) 
  223.             onthelist[CountFractalList++] = k;
  224. qsort(onthelist,CountFractalList,2,compare_fractalnames);
  225. CurrentFractal = fractype;
  226.  
  227. lx0 = (long far *)&temp_array[0];
  228. ly0 = (long far *)&lx0[MAXLINE];
  229. lx1 = (long far *)&ly0[MAXLINE];
  230. ly1 = (long far *)&ly0[MAXLINE];
  231. dx0 = (double far *)&temp_array[0];
  232. dy0 = (double far *)&dx0[MAXLINE];
  233. dx1 = (double far *)&dy0[MAXLINE];
  234. dy1 = (double far *)&dy0[MAXLINE];
  235.  
  236. extraseg = FP_SEG(dx0);
  237.  
  238. restoredac();        /* ensure that the palette has been initialized */
  239.  
  240. win_cmdfiles();                /* SSTOOLS.INI processing */
  241.  
  242. initmode = 1;                           /* override SSTOOLS.INI */
  243.  
  244. release = win_release;
  245.  
  246. dotmode = 1;
  247. diskvideo = 0;
  248. usr_distest = 0;
  249.  
  250. max_kbdcount=(cpu==386) ? 80 : 30; /* check the keyboard less often */
  251.  
  252. /* ----- */
  253.  
  254. calc_status = -1;
  255. resave_flag = 1;
  256. strcpy(FileName,"Fract001");
  257. if (showfile != 0) {
  258.     strcpy(readname, FileName);
  259.     }
  260. else {
  261.     if (strchr(readname,'.') == NULL)
  262.      strcat(readname,".gif");
  263.     strcpy(FileName,readname);
  264.     time_to_load = 1;
  265.     }
  266.  
  267. if (debugflag == 17500) {   /* force the release number for screen-shots */
  268.     extern int win_release;
  269.     win_release = 1750;
  270.     win_set_title_text();
  271.     }
  272.  
  273. if (debugflag == 10000) {   /* check for free memory */
  274.    char temp[50];
  275.    char *tempptr;
  276.    unsigned i,i2;
  277.    long j,j2;
  278.  
  279.    sprintf(temp," %d bytes of free stack space",stackavail());
  280.    stopmsg(0,temp);
  281.  
  282.    i = j = 0;
  283.    i2 = 0x8000;
  284.    while ((i2 >>= 1) != 0)
  285.       if ((tempptr = malloc(i+i2)) != NULL) {
  286.      free(tempptr);
  287.      i += i2;
  288.      }
  289.    sprintf(temp," %d NEAR bytes free", i);
  290.    stopmsg(0,temp);
  291.    }
  292.  
  293. if (debugflag == 70) fpu = 0;
  294.  
  295. init_help();
  296.  
  297. /* ----- */
  298.  
  299. time_to_quit = 0;
  300. if (debugflag == 23232) /* give the Windows stuff control first */
  301.     getakey(); 
  302. if (time_to_quit) {
  303.     end_help();
  304.     return(0);
  305.     }
  306.  
  307. reinit:
  308.     time_to_reinit = 0;
  309.  
  310.     savedac = 0;             /* don't save the VGA DAC */
  311.  
  312.     for (i = 0; i < 4; i++) {
  313.         if(param[i] == FLT_MAX)
  314.             param[i] = fractalspecific[fractype].paramvalue[i];
  315. /*
  316.         else
  317.             fractalspecific[fractype].paramvalue[i] = param[i];
  318. */
  319.         }
  320.  
  321. /*  Not used, MCP 8-6-91
  322.     ccreal = param[0]; ccimag = param[1]; */ /* default C-values */
  323.     frommandel = 0;
  324.  
  325.     if (xxmin > xxmax) {
  326.        dtemp = xxmin; xxmin = xxmax; xxmax = dtemp;} 
  327.     if (yymin > yymax) {
  328.        dtemp = yymin; yymin = yymax; yymax = dtemp;} 
  329.  
  330.     ytop    = 0;
  331.     ybottom = ydots-1;
  332.     xleft   = 0;
  333.     xright  = xdots-1;
  334.     filexdots = xdots;
  335.     fileydots = ydots;
  336.     filecolors = colors;
  337.  
  338. restart:
  339.     time_to_restart = 0;
  340.     time_to_resume = 0;
  341.     time_to_orbit = 0;
  342.  
  343.     win_title_text(1);
  344.  
  345.     if (calc_status == -99)
  346.         calc_status = 2;            /* force a recalc */
  347.     else
  348.         calc_status = 0;            /* force a restart */
  349.  
  350.     maxit = maxiter;
  351.  
  352.     if (colors == 2 && (fractype == PLASMA || usr_stdcalcmode == 'b'))
  353.         colors = 16;         /* 2-color mode just doesn't work on these */
  354.  
  355.     andcolor = colors-1;
  356.  
  357.     /* compute the (new) screen co-ordinates */
  358.     /* correct a possibly munged-up zoom-box outside the image range */
  359.     if (ytop    >= ydots) ytop    = ydots-1;
  360.     if (ybottom >= ydots) ybottom = ydots-1;
  361.     if (xleft   >= xdots) xleft   = xdots-1;
  362.     if (xright  >= xdots) xright  = xdots-1;
  363.     if (xleft == xright || ytop == ybottom) {
  364.         }
  365.     if (xleft > xright)
  366.         { i = xleft; xleft = xright; xright = i;}
  367.     if (ytop > ybottom)
  368.         { i = ybottom; ybottom = ytop; ytop = i;}
  369.     temp1 = xxmin;
  370.     temp2 = xxmax - xxmin;
  371.     xxmin = temp1 + (temp2 * xleft )/(xdots-1);
  372.     xxmax = temp1 + (temp2 * xright)/(xdots-1);
  373.     temp1 = yymin;
  374.     temp2 = yymax - yymin;
  375.     yymin = temp1 + (temp2 * (ydots - 1 - ybottom)/(ydots-1));
  376.     yymax = temp1 + (temp2 * (ydots - 1 - ytop   )/(ydots-1));
  377.     xx3rd = xxmin;
  378.     yy3rd = yymin;
  379.     xleft   = 0;
  380.     xright  = xdots-1;
  381.     ytop    = 0;
  382.     ybottom = ydots-1;
  383.  
  384. /*
  385.     delxx = (xxmax - xxmin) / (xdots-1);
  386.     delyy = (yymax - yymin) / (ydots-1);
  387.     delxx2 = delyy2 = 0.0;
  388.     ddelmin = fabs(delxx);
  389.     if (fabs(delyy) < ddelmin)
  390.         ddelmin = fabs(delyy);
  391. */
  392.  
  393.     dxsize = xdots - 1;  dysize = ydots - 1;
  394.  
  395.     if (calc_status != 2 && !overlay3d)
  396.         if (!clear_screen(1)) {
  397.             stopmsg(0,"Can't free and re-allocate the image");
  398.             return(0);
  399.             }
  400.  
  401.     if (savedac || colorpreloaded) {
  402.         memcpy(dacbox,olddacbox,256*3); /* restore the DAC */
  403.         spindac(0,1);
  404.         colorpreloaded = 0;
  405.         }
  406.  
  407.     dxsize = xdots - 1;  dysize = ydots - 1;
  408.     sxdots = xdots;  sydots = ydots;
  409.     finalaspectratio = ((float)ydots)/xdots;
  410.  
  411.     calcfracinit();
  412.  
  413.     bitshiftless1 = bitshift - 1;
  414.  
  415.     if (time_to_load)
  416.         goto wait_loop;
  417.  
  418.       if(showfile == 0) {        /* loading an image */
  419.      if (display3d)         /* set up 3D decoding */
  420.         outln = call_line3d;
  421.      else if(filetype >= 1)     /* old .tga format input file */
  422.         outln = outlin16;
  423.      else if(comparegif)        /* debug 50 */
  424.         outln = cmp_line;
  425.      else if(pot16bit) {        /* .pot format input file */
  426.         pot_startdisk();
  427.         outln = pot_line;
  428.         }
  429.      else                /* regular gif/fra input file */
  430.         outln = out_line;
  431.      if(filetype == 0)
  432.         i = funny_glasses_call(gifview);
  433.      else
  434.         i = funny_glasses_call(tgaview);
  435.      if(i == 0)
  436.         buzzer(0);
  437.      else {
  438.         calc_status = -1;
  439.         }
  440.      }
  441.  
  442.       if(showfile == 0) {        /* image has been loaded */
  443.      showfile = 1;
  444.      if (initbatch == 1 && calc_status == 2)
  445.         initbatch = -1; /* flag to finish calc before save */
  446.      if (calc_status == 2) goto try_to_resume;
  447.      }
  448.       else {                /* draw an image */
  449.  
  450. try_to_resume:
  451.  
  452.      diskisactive = 1;        /* flag for disk-video routines */
  453.      if (initsavetime != 0        /* autosave and resumable? */
  454.        && (fractalspecific[fractype].flags&NORESUME) == 0) {
  455.         savebase = readticker(); /* calc's start time */
  456.         saveticks = (long)initsavetime * 1092; /* bios ticks/minute */
  457.         if ((saveticks & 65535) == 0)
  458.            ++saveticks; /* make low word nonzero */
  459.         }
  460.          kbdcount = 30;                 /* ensure that we check the keyboard */
  461.      if ((i = calcfract()) == 0)    /* draw the fractal using "C" */
  462.         buzzer(0); /* finished!! */
  463.          saveticks = 0;         /* turn off autosave timer */
  464.          diskisactive = 0;        /* flag for disk-video routines */
  465.      }
  466.  
  467.     overlay3d = 0;      /* turn off overlay3d */
  468.     display3d = 0;      /* turn off display3d */
  469.  
  470.     zwidth = 0;
  471.  
  472.     if (!keypressed()) {
  473.         flush_screen();
  474.         buzzer(3);
  475.         win_title_text(0);
  476.         getakey();
  477.         }
  478.  
  479. wait_loop:
  480.  
  481.     win_title_text(0);
  482.  
  483. for (;;) {
  484.     if (time_to_act) {
  485.          /* we bailed out of the main loop to take some secondary action */
  486.          time_to_act = 0;
  487.          SecondaryWndProc();
  488.          if (! keypressed())
  489.              time_to_resume = 1;
  490.          }
  491.     if (time_to_quit) {
  492.          end_help();
  493.          return(0);
  494.          }
  495.     if (time_to_starfield) {
  496.          time_to_starfield = 0;
  497.          win_title_text(4);
  498.          starfield();
  499.          win_title_text(0);
  500.          flush_screen();
  501.          }
  502.     if (time_to_load) {
  503.         strcpy(readname, FileName);
  504.         showfile = 1;
  505.         time_to_load = 0;
  506.         time_to_restart = 0;
  507.         overlay3d = win_overlay3d;
  508.         display3d = win_display3d;
  509.         if (win_load() >= 0) {
  510.             showfile = 0;
  511.             rowcount = 0;
  512.             ytop    = 0;        /* reset the zoom-box */
  513.             ybottom = ydots-1;
  514.             xleft   = 0;
  515.             xright  = xdots-1;
  516.             maxiter = maxit;
  517.             time_to_load = 0;
  518.             time_to_restart = 1;
  519.             if (calc_status == 2) {
  520.                 calc_status = -99;      /* special klooge for restart */
  521.                 }
  522.             }
  523.         win_overlay3d = 0;
  524.         win_display3d = 0;
  525.         }
  526.     if (time_to_save) {
  527.         strcpy(readname, FileName);
  528.         if (readname[0] != 0)
  529.             win_save();
  530.         time_to_save = 0;
  531.         if (calc_status == 2) {
  532.             calc_status = -99;
  533.             time_to_restart = 1;
  534.             }
  535.         }
  536.     if (time_to_print) {
  537.         win_print();
  538.         time_to_print = 0;
  539.         }
  540.     if (time_to_cycle) {
  541.        win_cycle();
  542.        }
  543.     if (time_to_reinit == 2) {
  544.        win_cmdfiles();
  545.        maxiter = maxit;
  546.        }
  547.     if (time_to_reinit)
  548.          goto reinit;
  549.     if(time_to_restart)
  550.          goto restart;
  551.     if(time_to_resume)
  552.         if (calc_status == 2) {
  553.             calc_status = -99;
  554.             time_to_restart = 1;
  555.             goto restart;
  556.             }
  557.     getakey();
  558.     }
  559.  
  560. }
  561.  
  562. /* displays differences between current image file and new image */
  563. /* Bert - suggest add this to video.asm */
  564. int cmp_line(unsigned char *pixels, int linelen)
  565. {
  566.    static errcount;
  567.    static FILE *fp = NULL;
  568.    extern int rowcount;
  569.    int row,col;
  570.    int oldcolor;
  571.    char *timestring;
  572.    time_t ltime;
  573.    if(fp == NULL)
  574.       fp = fopen("cmperr",(initbatch)?"a":"w");
  575.    if((row = rowcount++) == 0)
  576.       errcount = 0;
  577.    if(pot16bit) { /* 16 bit info, ignore odd numbered rows */
  578.       if((row & 1) != 0) return(0);
  579.       row >>= 1;
  580.       }
  581.    for(col=0;col<linelen;col++) {
  582.       oldcolor=getcolor(col,row);
  583.       if(oldcolor==pixels[col])
  584.      putcolor(col,row,0);
  585.       else {
  586.      if(oldcolor==0)
  587.         putcolor(col,row,1);
  588.      ++errcount;
  589.      if(initbatch == 0)
  590.         fprintf(fp,"#%5d col %3d row %3d old %3d new %3d\n",
  591.            errcount,col,row,oldcolor,pixels[col]);
  592.      }
  593.       }
  594.    if(row+1 == ydots && initbatch) {
  595.       time(<ime);
  596.       timestring = ctime(<ime);
  597.       timestring[24] = 0; /*clobber newline in time string */
  598.       fprintf(fp,"%s compare to %s has %5d errs\n",timestring,readname,errcount);
  599.       }
  600.    return(0);
  601. }
  602.  
  603. int pot_line(unsigned char *pixels, int linelen)
  604. {
  605.    extern int rowcount;
  606.    int row,col,saverowcount;
  607.    if (rowcount == 0)
  608.       pot_startdisk();
  609.    saverowcount = rowcount;
  610.    row = (rowcount >>= 1);
  611.    if ((saverowcount & 1) != 0) /* odd line */
  612.       row += ydots;
  613.    else             /* even line */
  614.       if (dotmode != 11) /* display the line too */
  615.      out_line(pixels,linelen);
  616.    for (col = 0; col < xdots; ++col)
  617.       writedisk(col+sxoffs,row+syoffs,*(pixels+col));
  618.    rowcount = saverowcount + 1;
  619.    return(0);
  620. }
  621.  
  622. static int call_line3d(unsigned char *pixels, int linelen)
  623. {
  624.    /* this routine exists because line3d might be in an overlay */
  625.    return(line3d(pixels,linelen));
  626. }
  627.  
  628. void win_cmdfiles()   /* convert lpCmdLine into argc, argv */
  629. {
  630. int i, k;
  631. int argc;
  632. char *argv[10];
  633. unsigned char arg[501];   /* max 10 args, 450 chars total */
  634.  
  635. arg[0] = 0;
  636. for (i = 0; i < 10; i++)
  637.    argv[i] = &arg[0];
  638. argc = 1;
  639. strcpy(&arg[1],"winfract.exe");
  640. argv[argc-1] = &arg[1];
  641.  
  642. for (i = 0; i < 460 && win_lpCmdLine[i] != 0; i++)
  643.    arg[20+i] = win_lpCmdLine[i];
  644. arg[20+i] = 0;
  645. arg[21+i] = 0;
  646.  
  647. for (k = 20; arg[k] != 0; k++) {
  648.     while(arg[k] <= ' ' && arg[k] != 0) k++;
  649.     if (arg[k] == 0) break;
  650.     if (argc >= 10) break;
  651.     argc++;
  652.     argv[argc-1] = &arg[k];
  653.     while(arg[k] > ' ')k++;
  654.     arg[k] = 0;
  655.     }
  656.  
  657. cmdfiles(argc,argv);
  658.  
  659. }
  660.