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