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