home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / wps / graphic / fractint / sources / pmfrcalc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-03-30  |  24.6 KB  |  990 lines

  1. /*--------------------------------------------------
  2.    PMFRCALC.C -- FRACTINT for PM
  3.  
  4.       Fractal Calculation Engine Interface Module
  5.  
  6.    03/15/91     Code by Donald P. Egen (with help)
  7.  
  8.    This module's first function (CalcDriverInit)
  9.    does calculation-engine specific initialization,
  10.    primarily calling the FRACTINT command line and init
  11.    file processing routines, then copying the results
  12.    back where the user interface can find them.
  13.  
  14.    This module's second function (CalcDriver) is the
  15.    Fractal Calculation Engine interface function.
  16.    Much of its code was extracted from module FRACTINT.C,
  17.    the base module and user interface module of the FRACTINT
  18.    DOS-based fractal calculation program.
  19.    As such, it looks very much like a hack-up job.
  20.    It gets and then updates the background bitmap
  21.    (and memory Device Context and Presentation Space).
  22.  
  23.    Functions putcolor and getcolor serve as the glue
  24.    modules back from the fractal calculation engine
  25.    to the PM display environment.  putcolor sets
  26.    pixels, getcolor reads pixels.  Each puts or gets
  27.    the background bitmap.
  28.  
  29.    Other functions tie up loose ends in the fractal
  30.    calculation engine.  They return control to the
  31.    main CalcThread routine and terminate the current
  32.    calculation with an error post to the main thread,
  33.    which will result in an error box.
  34.  ---------------------------------------------------*/
  35.  
  36. #define PUTTHEMHERE 1        /* stuff common external arrays here */
  37.  
  38. /* from MSC's <dos.h> */
  39. #define FP_SEG(fp) (*((unsigned _far *)&(fp)+1))
  40. #define FP_OFF(fp) (*((unsigned _far *)&(fp)))
  41.  
  42. #define INCL_WIN
  43. #define INCL_GPI
  44. #define INCL_DOS
  45. #include <os2.h>
  46. #include <process.h>
  47. #include <stdlib.h>
  48. #include <stdio.h>
  49. #include <setjmp.h>
  50. #include <float.h>
  51. #include <malloc.h>
  52. #include <search.h>
  53. #include <string.h>
  54. #include <ctype.h>
  55. #include <time.h>
  56.  
  57. #include <smplhelp.h>
  58.  
  59. #include "pmfract.h"
  60. #include "fractint.h"
  61. #include "fractype.h"
  62.  
  63. jmp_buf  longjmpbuf;       /* unwind from stubbed-out subroutine */
  64. extern HAB    habThread;
  65.  
  66. extern    int cputype(void);     /* in PMGENERL.ASM */
  67. extern  int fputype(void);
  68. extern    int fpu, cpu;
  69.  
  70. int save_system;       /* tag identifying Fractint for Windows */
  71. int save_release;          /* tag identifying version number */
  72. int win_release = 200;       /* tag identifying version number */
  73.  
  74. int cmp_line(), pot_line();
  75.  
  76. char FileName[128];
  77. char string004[2];
  78.  
  79. int xdots, ydots, colors, maxiter;
  80. int ytop, ybottom, xleft, xright;
  81.  
  82. int fractype;
  83. int invert;
  84.  
  85. double ftemp, xxmin, xxmax, yymin, yymax;
  86. long fudge;
  87.  
  88. long lm, linitx, linity;
  89. int maxit, bitshift, color, row, col;
  90.  
  91. int calc_status; /* -1 no fractal            */
  92.          /*  0 parms changed, recalc reqd   */
  93.          /*  1 actively calculating        */
  94.          /*  2 interrupted, resumable        */
  95.          /*  3 interrupted, not resumable   */
  96.          /*  4 completed            */
  97.  
  98. int reset_periodicity = 1;
  99. extern int kbdcount;
  100. int show_orbit = 0;
  101. int orbit_ptr = 0;
  102. int periodicitycheck;
  103. extern int debugflag;
  104. int integerfractal;
  105. extern int distest;
  106. extern int bitshiftless1;
  107. char usr_stdcalcmode, stdcalcmode;
  108. int  usr_distest, usr_floatflag, usr_periodicitycheck;
  109. long calctime;
  110.  
  111. long creal, cimag;
  112. long delx, dely, delx2, dely2, delmin;
  113. long xmin, xmax, ymin, ymax, x3rd, y3rd;
  114. double  dxsize, dysize;        /* xdots-1, ydots-1        */
  115. double delxx, delyy, delxx2, delyy2, ddelmin, xx3rd, yy3rd;
  116. double param[4];
  117. double potparam[3];
  118. int diskvideo;
  119.  
  120. /*    #define MAXLINE  2048  */
  121. #define MAXLINE 4096
  122.  
  123. long   far *lx0, far *ly0, far *lx1, far *ly1;
  124. double far *dx0, far *dy0, far *dx1, far *dy1;
  125.    /*  extern double far temp_array[8001];  */
  126. double far *temp_array;
  127. double far *temp_array2;
  128.  
  129. extern unsigned char trigndx[4];
  130. extern void set_trig_pointers(int which);
  131.  
  132. unsigned char dacbox[257][3];
  133. double plotmx1, plotmx2, plotmy1, plotmy2;
  134. int MPOverflow;
  135. int dotmode;
  136. extern int pot16bit;
  137. int andcolor, resave_flag, timer_interval;
  138. int active_ovly;
  139.  
  140.     /*    int extraseg;  */
  141.  
  142. extern int extraseg;
  143.  
  144. int timedsave = 0;
  145. int disk16bit = 0;
  146. extern int initbatch;
  147. float far initifs3d[32][13];
  148. float far initifs[32][7];
  149. extern unsigned char readname[];
  150. unsigned char MAP_name[40] = "";
  151. int rowcount;
  152. int adapter;
  153. extern int showfile;
  154. extern int initmode;
  155. extern int overlay3d;
  156. extern int display3d;
  157. extern int filetype;
  158. int comparegif = 0;
  159. int diskisactive = 0;
  160. extern int initsavetime;
  161. int saveticks = 0;
  162. int savebase = 0;
  163. int zwidth = 0;
  164. extern int (*outln)();
  165. extern int out_line();
  166. extern int outlin16();
  167. static int call_line3d();
  168. extern int line3d();
  169. extern int gifview();
  170. extern int tgaview();
  171. int mapset = 0;
  172. int reallyega = 0;
  173. int loadPalette = 0;
  174. int compiled_by_turboc = 0;
  175.  
  176. /* Fractint Release 15.1 engine */
  177.  
  178. int mode7text, Slope, textsafe, Distribution, Offset;
  179. long con;
  180. int Print_To_File, EPSFileType;
  181.  
  182. /* **** **** **** **** **** **** */
  183.  
  184. extern char ifsfilename[];
  185. extern char ifs3dfilename[];
  186. extern char FormFileName[];
  187. extern char FormName[];
  188. extern char LFileName[];
  189. extern char LName[];
  190. extern char PrintName[];
  191.  
  192. int     sxdots,sydots;
  193. int     sxoffs=0,syoffs=0;
  194. int     viewwindow=0;
  195. float   viewreduction=1;
  196. int     viewcrop=1;
  197. float   finalaspectratio;
  198. int     viewxdots=0,viewydots=0;
  199. extern int filexdots, fileydots, filecolors;
  200. int frommandel;
  201. extern int decomp[2];
  202. extern int biomorph, inside, outside;
  203.  
  204. int debug_fastupdate;        /* debugging - update every pixel if set */
  205.  
  206. int Printer_Resolution, Printer_Titleblock, Printer_SFrequency;
  207. int Printer_SetScreen, Printer_SStyle, Printer_Type;
  208. int Printer_ColorXlat, Printer_SAngle, LPTNumber;
  209. int video_type;
  210.  
  211. int active_system = WINFRAC;    /* running under windows/PM */
  212. extern int win_display3d, win_overlay3d;
  213.  
  214. #pragma optimize("elg",off)
  215.  
  216.  /* Local initialization */
  217.  
  218. void FAR CalcDriverInit(void)
  219.     {
  220.  
  221.       BYTE    b80287;
  222.  
  223. int i;
  224. double temp1, temp2;
  225. double dtemp, ccreal, ccimag;
  226.  
  227. SEL selExtraSeg, selExtraSeg2;
  228.  
  229.      /* init one time only vars */
  230.      cpu = cputype();
  231.  
  232.      /* must ask OS/2 if we have a coprocessor before
  233.         asking the coprocessor what kind he is! */
  234. #define DEVINFO_COPROCESSOR 0x0003
  235.      DosDevConfig (&b80287, DEVINFO_COPROCESSOR, 0);
  236.      if (b80287)
  237.          fpu = fputype();
  238.      else
  239.      fpu = 0;
  240.  
  241.   /* go for 2*64K memory from OS/2 */
  242.   DosAllocSeg(0, &selExtraSeg, SEG_NONSHARED);
  243.   DosAllocSeg(0, &selExtraSeg2, SEG_NONSHARED);
  244.  
  245.   extraseg = (int) selExtraSeg;
  246.   temp_array = MAKEP(selExtraSeg, 0);
  247.   temp_array2 = MAKEP(selExtraSeg2, 0);
  248.  
  249. lx0 = (long far *)&temp_array[0*MAXLINE];
  250. ly0 = (long far *)&temp_array[1*MAXLINE];
  251. lx1 = (long far *)&temp_array2[0*MAXLINE];
  252. ly1 = (long far *)&temp_array2[1*MAXLINE];
  253. dx0 = (double far *)&temp_array[0*MAXLINE];
  254. dy0 = (double far *)&temp_array[1*MAXLINE];
  255. dx1 = (double far *)&temp_array2[0*MAXLINE];
  256. dy1 = (double far *)&temp_array2[1*MAXLINE];
  257.    /*     extraseg = FP_SEG(dx0);    */
  258.  
  259. restoredac();        /* ensure that the palette has been initialized */
  260.  
  261. cmdfiles(MainArgc, MainArgv);        /* SSTOOLS.INI processing */
  262.  
  263. initmode = 1;                           /* override SSTOOLS.INI */
  264.  
  265. dotmode = 1;
  266. diskvideo = 0;
  267. usr_distest = 0;
  268.  
  269. /* ----- */
  270.  
  271. debug_fastupdate = 0;
  272. calc_status = -1;
  273. resave_flag = 1;
  274. strcpy(FileName,"Fract001");
  275. if (showfile != 0) {
  276.     strcpy(readname, FileName);
  277.     /* we don't have a file name passed to us to load.
  278.        Therefore we begin calculating. */
  279.     DosSemClear((HSEM) &cp.ulSemTrigger);
  280.     cp.sSubAction = SUB_ACT_CALC;
  281.     cp.sSubFunction = 0;
  282.     }
  283. else {
  284.     if (strchr(readname,'.') == NULL)
  285.      strcat(readname,".gif");
  286.     strcpy(FileName,readname);
  287.     // time_to_load = 1;
  288.     DosSemClear((HSEM) &cp.ulSemTrigger);
  289.     cp.sSubAction = SUB_ACT_LOAD;
  290.     cp.sSubFunction = SUB_LOADSAVE_GIF;
  291.     }
  292.  
  293. /*
  294.    sprintf(strlocn," %d bytes",stackavail());
  295.    stopmsg(0,"Available Stack",strlocn);
  296. */
  297.     save_system = 1;
  298.     save_release = win_release;
  299.  
  300.    /* default to a window-size picture */
  301.    cp.cx = cxClient;
  302.    cp.cy = cyClient;
  303.  
  304.    /* initialize based on the physical colors the screen can support */
  305.    if (lScreenColors <16)
  306.       {
  307.       cp.colors = 2;
  308.       cp.cBitCount = 1;
  309.       cp.maxiter = 150;
  310.       }
  311.    else if (lScreenColors < 256)
  312.       {
  313.       cp.colors = 16;
  314.       cp.cBitCount = 4;
  315.       cp.maxiter = 150;
  316.       }
  317.    else
  318.       {
  319.       cp.colors = 256;
  320.       cp.cBitCount = 8;
  321.       cp.maxiter = 250;
  322.       }
  323.  
  324.    /* collect the calc data set by engine init - CMDFILES mostly */
  325.    cp.iFractType = fractype;
  326.    cp.cFloatflag = usr_floatflag;
  327.    cp.XL = xxmin;
  328.    cp.XR = xxmax;
  329.    cp.YT = yymax;
  330.    cp.YB = yymin;
  331.    cp.param[0] = param[0];
  332.    cp.param[1] = param[1];
  333.    cp.param[2] = param[2];
  334.    cp.param[3] = param[3];
  335.    cp.trigndx[0] = trigndx[0];
  336.    cp.trigndx[1] = trigndx[1];
  337.    cp.trigndx[2] = trigndx[2];
  338.    cp.trigndx[3] = trigndx[3];
  339.    _fstrcpy(cp.szFileName, FileName);
  340.    _fstrcpy(cp.szIfsFileName, ifsfilename);
  341.    _fstrcpy(cp.szIfs3dFileName, ifs3dfilename);
  342.    _fstrcpy(cp.szFormFileName, FormFileName);
  343.    _fstrcpy(cp.szFormName, FormName);
  344.    _fstrcpy(cp.szLSysFileName, LFileName);
  345.    _fstrcpy(cp.szLSysName, LName);
  346.    _fstrcpy(cp.szPrintName, PrintName);
  347.    cp.stdCalcMode = usr_stdcalcmode;
  348.    cp.distest = usr_distest;
  349.    cp.periodicitycheck = usr_periodicitycheck;
  350.    cp.biomorph = biomorph;
  351.    cp.decomp[0] = decomp[0]; cp.decomp[1] = decomp[1];
  352.    cp.inside = inside;
  353.    cp.outside = outside;
  354.  
  355.      }
  356.  
  357.  /* Now, the real driver */
  358. int  FAR CalcDriver (VOID)
  359.      {
  360. int i;
  361. double temp1, temp2;
  362. double dtemp, ccreal, ccimag;
  363.  
  364.      int jmp_rc;
  365.      double ftemp;
  366.  
  367.       /* resize the memory bitmap for the current calc */
  368.       /* fall on sword if can't get memory */
  369.       if (GetMemoryBitmap(habThread))
  370.          return(SUB_STAT_FATAL);
  371.  
  372.           WinPostMsg (cp.hwnd, WM_THRD_POST,
  373.                   MPFROM2SHORT(SUB_STAT_START_TIMER,0), MPFROMP(NULL) ) ;
  374.  
  375.           /* we are directed by the main task to calculate a fractal */
  376.           /* prepare the variable mass for the calculation engine */
  377.  
  378.       usr_floatflag = cp.cFloatflag;
  379.       fractype = cp.iFractType;            /* specify the fractal */
  380.       _fstrcpy(FileName,cp.szFileName);
  381.       _fstrcpy(ifsfilename, cp.szIfsFileName);
  382.       _fstrcpy(ifs3dfilename, cp.szIfs3dFileName);
  383.       _fstrcpy(FormFileName, cp.szFormFileName);
  384.       _fstrcpy(FormName, cp.szFormName);
  385.       _fstrcpy(LFileName, cp.szLSysFileName);
  386.       _fstrcpy(LName, cp.szLSysName);
  387.       xxmin = cp.XL;
  388.       xxmax = cp.XR;
  389.       yymin = cp.YB;
  390.       yymax = cp.YT;
  391.       xdots = cp.cx;
  392.       ydots = cp.cy;
  393.       param[0] = cp.param[0];
  394.       param[1] = cp.param[1];
  395.       param[2] = cp.param[2];
  396.       param[3] = cp.param[3];
  397.       trigndx[0] = cp.trigndx[0];
  398.       trigndx[1] = cp.trigndx[1];
  399.       trigndx[2] = cp.trigndx[2];
  400.       trigndx[3] = cp.trigndx[3];
  401.       set_trig_pointers(-1);
  402.       colors = cp.colors;
  403.       maxiter = cp.maxiter;
  404.       usr_distest = cp.distest;
  405.       usr_stdcalcmode = cp.stdCalcMode;
  406.       usr_periodicitycheck = cp.periodicitycheck;
  407.       biomorph = cp.biomorph;
  408.       decomp[0] = cp.decomp[0]; decomp[1] = cp.decomp[1];
  409.       inside = cp.inside;
  410.       outside = cp.outside;
  411.  
  412.       /* a little (in)sanity check before we crank up */
  413.  
  414.       if ((xdots < 2) || (ydots < 2) )
  415.           return(33);
  416.  
  417.       /* If we are about to calculate an IFS or IFS3D fractal,
  418.          we need to load the data from the file.
  419.          This is a proper job for the subthread.
  420.       */
  421.  
  422.       if (fractype == IFS)
  423.            ifsgetfile();
  424.  
  425.       if (fractype == IFS3D)
  426.            ifs3dgetfile();
  427.  
  428. reinit:
  429.  
  430.     for (i = 0; i < 4; i++) {
  431.         if(param[i] != FLT_MAX)
  432.             fractalspecific[fractype].paramvalue[i] = param[i];
  433.         else
  434.             param[i] = fractalspecific[fractype].paramvalue[i];
  435.         }
  436.     ccreal = param[0]; ccimag = param[1]; /* default C-values */
  437.     frommandel = 0;
  438.  
  439.     if (xxmin > xxmax) {
  440.        dtemp = xxmin; xxmin = xxmax; xxmax = dtemp;} 
  441.     if (yymin > yymax) {
  442.        dtemp = yymin; yymin = yymax; yymax = dtemp;} 
  443.  
  444.     ytop    = 0;
  445.     ybottom = ydots-1;
  446.     xleft   = 0;
  447.     xright  = xdots-1;
  448.     filexdots = xdots;
  449.     fileydots = ydots;
  450.     filecolors = colors;
  451.  
  452. restart:
  453.  
  454.     if (calc_status == -99)
  455.         calc_status = 2;            /* force a recalc */
  456.     else
  457.         calc_status = 0;            /* force a restart */
  458.  
  459.     maxit = maxiter;
  460.  
  461.     if (colors == 2 && (fractype == PLASMA || usr_stdcalcmode == 'b'))
  462.         colors = 16;         /* 2-color mode just doesn't work on these */
  463.  
  464.     andcolor = colors-1;
  465.  
  466.     debug_fastupdate = 0;    /* turn off debug-mode screen updates */
  467.     if (debugflag == 6666)
  468.         debug_fastupdate = 1;
  469.  
  470.     /* compute the (new) screen co-ordinates */
  471.     /* correct a possibly munged-up zoom-box outside the image range */
  472.     if (ytop    >= ydots) ytop    = ydots-1;
  473.     if (ybottom >= ydots) ybottom = ydots-1;
  474.     if (xleft   >= xdots) xleft   = xdots-1;
  475.     if (xright  >= xdots) xright  = xdots-1;
  476.     if (xleft == xright || ytop == ybottom) {
  477.         }
  478.     if (xleft > xright)
  479.         { i = xleft; xleft = xright; xright = i;}
  480.     if (ytop > ybottom)
  481.         { i = ybottom; ybottom = ytop; ytop = i;}
  482.     temp1 = xxmin;
  483.     temp2 = xxmax - xxmin;
  484.     xxmin = temp1 + (temp2 * xleft )/(xdots-1);
  485.     xxmax = temp1 + (temp2 * xright)/(xdots-1);
  486.     temp1 = yymin;
  487.     temp2 = yymax - yymin;
  488.     yymin = temp1 + (temp2 * (ydots - 1 - ybottom)/(ydots-1));
  489.     yymax = temp1 + (temp2 * (ydots - 1 - ytop   )/(ydots-1));
  490.     xx3rd = xxmin;
  491.     yy3rd = yymin;
  492.     xleft   = 0;
  493.     xright  = xdots-1;
  494.     ytop    = 0;
  495.     ybottom = ydots-1;
  496.  
  497. /*
  498.     delxx = (xxmax - xxmin) / (xdots-1);
  499.     delyy = (yymax - yymin) / (ydots-1);
  500.     delxx2 = delyy2 = 0.0;
  501.     ddelmin = fabs(delxx);
  502.     if (fabs(delyy) < ddelmin)
  503.         ddelmin = fabs(delyy);
  504. */
  505.  
  506.     dxsize = xdots - 1;  dysize = ydots - 1;
  507.  
  508.     if (calc_status != 2 && !overlay3d)
  509.         if (!clear_screen(1)) {
  510.             stopmsg(0,"Screen-Clearing Function","Can't free and re-allocate the image");
  511.             return(0);
  512.             }
  513.  
  514.     dxsize = xdots - 1;  dysize = ydots - 1;
  515.     sxdots = xdots;  sydots = ydots;
  516.     finalaspectratio = ((float)ydots)/xdots;
  517.  
  518.     calcfracinit();
  519.  
  520.     bitshiftless1 = bitshift - 1;
  521.  
  522.     /* delete the following file read processing */
  523. #if 0
  524.       if(showfile == 0) {        /* loading an image */
  525.      if (display3d)         /* set up 3D decoding */
  526.         outln = call_line3d;
  527.      else if(filetype >= 1)     /* old .tga format input file */
  528.         outln = outlin16;
  529.      else if(comparegif)        /* debug 50 */
  530.         outln = cmp_line;
  531.      else if(pot16bit) {        /* .pot format input file */
  532.         pot_startdisk();
  533.         outln = pot_line;
  534.         }
  535.      else                /* regular gif/fra input file */
  536.         outln = out_line;
  537.      if(filetype == 0)
  538.         i = funny_glasses_call(gifview);
  539.      else
  540.         i = funny_glasses_call(tgaview);
  541.      if(i == 0)
  542.         buzzer(0);
  543.      else {
  544.         calc_status = -1;
  545.         }
  546.      }
  547. #endif
  548.  
  549.       if(showfile == 0) {        /* image has been loaded */
  550.      showfile = 1;
  551.      if (initbatch == 1 && calc_status == 2)
  552.         initbatch = -1; /* flag to finish calc before save */
  553.      if (calc_status == 2) goto try_to_resume;
  554.      }
  555.       else {                /* draw an image */
  556.  
  557. try_to_resume:
  558.  
  559.      diskisactive = 1;        /* flag for disk-video routines */
  560.      if (initsavetime != 0        /* autosave and resumable? */
  561.        && (fractalspecific[fractype].flags&NORESUME) == 0) {
  562.         savebase = readticker(); /* calc's start time */
  563.         saveticks = (long)initsavetime * 1092; /* bios ticks/minute */
  564.         if ((saveticks & 65535) == 0)
  565.            ++saveticks; /* make low word nonzero */
  566.         }
  567.      kbdcount = 30;         /* ensure that we check the keyboard */
  568.  
  569.      }
  570.  
  571.       /* set up to catch a longjmp from a subroutine loose end */
  572.           jmp_rc = setjmp(longjmpbuf);
  573.  
  574.           if (0 == jmp_rc)
  575.              {  /* ready for a calculation */
  576.              jmp_rc = calcfract();
  577.              /* jmp_rc == 0 for done, 1 for interrupted */
  578.          saveticks = 0;     /* turn off autosave timer */
  579.          diskisactive = 0;     /* flag for disk-video routines */
  580.          overlay3d = 0;     /* turn off overlay3d */
  581.          display3d = 0;     /* turn off display3d */
  582.  
  583.          zwidth = 0;
  584.  
  585.          }
  586.           /* else jmp_rc is a locator code from a loose end */
  587.  
  588.       /* translate Aborted from Fractint-eze to PMfract-eze */
  589.       if (jmp_rc==1) jmp_rc = SUB_STAT_ABORT;
  590.           /* in any case, pass it back to the main task */
  591.  
  592.           /* return our final status back to the subtask driver */
  593.           return (jmp_rc);
  594.      }
  595.  
  596. /* displays differences between current image file and new image */
  597. /* Bert - suggest add this to video.asm */
  598. int cmp_line(unsigned char *pixels, int linelen)
  599. {
  600.    static errcount;
  601.    static FILE *fp = NULL;
  602.    extern int rowcount;
  603.    int row,col;
  604.    int oldcolor;
  605.    char *timestring;
  606.    time_t ltime;
  607.    if(fp == NULL)
  608.       fp = fopen("cmperr",(initbatch)?"a":"w");
  609.    if((row = rowcount++) == 0)
  610.       errcount = 0;
  611.    if(pot16bit) { /* 16 bit info, ignore odd numbered rows */
  612.       if((row & 1) != 0) return(0);
  613.       row >>= 1;
  614.       }
  615.    for(col=0;col<linelen;col++) {
  616.       oldcolor=getcolor(col,row);
  617.       if(oldcolor==pixels[col])
  618.      putcolor(col,row,0);
  619.       else {
  620.      if(oldcolor==0)
  621.         putcolor(col,row,1);
  622.      ++errcount;
  623.      if(initbatch == 0)
  624.         fprintf(fp,"#%5d col %3d row %3d old %3d new %3d\n",
  625.            errcount,col,row,oldcolor,pixels[col]);
  626.      }
  627.       }
  628.    if(row+1 == ydots && initbatch) {
  629.       time(<ime);
  630.       timestring = ctime(<ime);
  631.       timestring[24] = 0; /*clobber newline in time string */
  632.       fprintf(fp,"%s compare to %s has %5d errs\n",timestring,readname,errcount);
  633.       }
  634.    return(0);
  635. }
  636.  
  637. int pot_line(unsigned char *pixels, int linelen)
  638. {
  639.    extern int rowcount;
  640.    int row,col,saverowcount;
  641.    if (rowcount == 0)
  642.       pot_startdisk();
  643.    saverowcount = rowcount;
  644.    row = (rowcount >>= 1);
  645.    if ((saverowcount & 1) != 0) /* odd line */
  646.       row += ydots;
  647.    else             /* even line */
  648.       if (dotmode != 11) /* display the line too */
  649.      out_line(pixels,linelen);
  650.    for (col = 0; col < xdots; ++col)
  651.       writedisk(col+sxoffs,row+syoffs,*(pixels+col));
  652.    rowcount = saverowcount + 1;
  653.    return(0);
  654. }
  655.  
  656. static int call_line3d(unsigned char *pixels, int linelen)
  657. {
  658.    /* this routine exists because line3d might be in an overlay */
  659.    return(line3d(pixels,linelen));
  660. }
  661.  
  662. /* This function draws on the bitmap for the calculation engine */
  663.  
  664. void putcolor (int xdot, int ydot, int color)
  665. {
  666.     ULONG pm_y, offset;
  667.  
  668.     /* some calculation routines run [0..xdots] and/or [0..ydots],
  669.        rather than [0..xdots-1] and [0..ydots-1] for a total of
  670.        xdots by ydots.    We clip coordinates that will blow the
  671.        pixel array quietly here.                  */
  672.     if ( ! ((xdot >= xleft) && (xdot <= xright) &&
  673.         (ydot >= ytop)  && (ydot <= ybottom)) )
  674.        return;
  675.  
  676.     pm_y = (ULONG) (cp.cy - ydot - 1);
  677.     offset = ((ULONG) cp.pm_xdots * pm_y) + (ULONG) xdot;
  678.  
  679.     if (cp.pixelshift_per_byte == 0)
  680.     {
  681.     cp.pixels[offset] = (unsigned char) (color % cp.colors) ;
  682.     }
  683.      else
  684.     {
  685.     USHORT j;
  686.     j = offset & cp.pixels_per_bytem1;
  687.     offset = offset >> cp.pixelshift_per_byte;
  688.     cp.pixels[offset] = (cp.pixels[offset] & cp.pm_notmask[j]) +
  689.         (((unsigned char)(color % cp.colors)) << cp.pm_bitshift[j]);
  690.     }
  691. }
  692.  
  693. int getcolor (int xdot, int ydot)
  694. {
  695.      ULONG pm_y, offset;
  696.  
  697.     if ( ! ((xdot >= xleft) && (xdot <= xright) &&
  698.         (ydot >= ytop)  && (ydot <= ybottom)) )
  699.        return 0;    /* arbitrary value */
  700.  
  701.      pm_y = (ULONG) (cp.cy - ydot - 1);
  702.      offset = ((ULONG) cp.pm_xdots * pm_y) + (ULONG) xdot;
  703.  
  704.      if (cp.pixelshift_per_byte == 0)
  705.        {
  706.       return(cp.pixels[offset]);
  707.        }
  708.      else
  709.        {
  710.     USHORT j;
  711.     j = offset & cp.pixels_per_bytem1;
  712.     offset = offset >> cp.pixelshift_per_byte;
  713.     return((int)((cp.pixels[offset] & cp.pm_andmask[j]) >> cp.pm_bitshift[j]));
  714.        }
  715. }
  716.  
  717. int keypressed (void)
  718. {
  719.     return (! cp.fContinueCalc) ;
  720. }
  721.  
  722. /* Fractint-for-DOS memory get/free.
  723.    Let's go directly to OS/2 */
  724. unsigned char far *farmemalloc(long howmuch)
  725.   {
  726.   USHORT usSize;     /* howmuch as an unsigned short */
  727.   SEL selGot;
  728.   char far *pGot;
  729.  
  730.   if (howmuch > 65535L)  /* if asking for too much ... */
  731.     return (char far *) NULL;  /* sorry */
  732.  
  733.   usSize = (USHORT) howmuch;
  734.   if (DosAllocSeg(usSize, &selGot, SEG_NONSHARED) )
  735.     return (char far *) NULL;    /* sorry, OS/2 don't have it */
  736.   pGot = MAKEP(selGot,0);      /* cvt to pointer */
  737.   return pGot;               /* and go back */
  738.   }
  739.  
  740. void   farmemfree(unsigned char far * it)
  741.   {
  742.   /* we assume what is farmemfree'd has been farmemalloc'd */
  743.   SEL selIt;        /* selector to free */
  744.  
  745.   selIt = SELECTOROF(it);
  746.   DosFreeSeg(selIt);     /* bye bye */
  747.  
  748.   return;         /* and go back */
  749.   }
  750.  
  751. int put_line(int rownum, int leftpt, int rightpt, unsigned char *localvalues)
  752. {
  753. int i;
  754.   for (i = leftpt; i <= rightpt; i++)
  755.        putcolor(i, rownum, localvalues[i-leftpt]);
  756.   return 0;
  757. }
  758.  
  759. int get_line(int rownum, int leftpt, int rightpt, unsigned char *localvalues)
  760. {
  761. int i;
  762.  
  763.    for (i = leftpt; i <= rightpt; i++)
  764.       localvalues[i-leftpt] = (unsigned char) getcolor(i, rownum);
  765.    return 0;
  766. }
  767.  
  768. extern int rowcount;
  769.  
  770. int out_line(unsigned char *localvalues, int numberofdots)
  771. {
  772.     put_line(rowcount++, 0, numberofdots, localvalues);
  773.     return 0;
  774. }
  775.  
  776. int clear_screen(int forceclear)
  777. {
  778.   GpiErase(cp.hpsMemory);
  779.   return(1);
  780. }
  781.  
  782. /****************************************************************************
  783.  
  784.     FUNCTION: buzzer(int buzzertype)
  785.              0 = normal completion of task
  786.              1 = interrupted task
  787.              2 = error
  788.  
  789.     PURPOSE:  make some noise depending on the situation
  790.  
  791. ****************************************************************************/
  792.  
  793. void buzzer(int i)
  794. {
  795.  
  796.    switch(i)
  797.      {
  798.      case 1:
  799.            DosBeep(1047, 100);
  800.            DosBeep(1109, 100);
  801.            DosBeep(1175, 100);
  802.            break;
  803.  
  804.      case 2:
  805.            DosBeep(2093, 100);
  806.            DosBeep(1976, 100);
  807.            DosBeep(1857, 100);
  808.            break;
  809.  
  810.      case 3:
  811.            DosBeep(40, 500);
  812.            break;
  813.  
  814.      default:
  815.            DosBeep(1000, 250);
  816.            break;
  817.      }
  818.  
  819. }
  820.  
  821. texttempmsg(char *msg1)
  822. {
  823.  
  824.     PMfrSyncMsg(0, (PSZ) msg1);
  825.  
  826. }
  827.  
  828. stopmsg(int flags, char *msg1)
  829. {
  830.  
  831.    return PMfrSyncMsg(flags, (PSZ) msg1);
  832.  
  833. }
  834.  
  835. int get_video_mode(struct fractal_info *info)
  836. {
  837.    viewwindow = viewxdots = viewydots = 0;
  838. // fileaspectratio = .75;
  839. // skipxdots = skipydots = 0;
  840.    return(0);
  841. }
  842.  
  843. restoredac()
  844. {
  845.  
  846. }
  847.  
  848. /* The following procs tie up loose calc ends.    They are all dummy */
  849.  
  850. int getakey(void)
  851. {
  852.      longjmp (longjmpbuf, 5);
  853.      return(999);
  854. }
  855.  
  856. void helpmessage(unsigned char far *q)
  857. {
  858.      longjmp (longjmpbuf, 8);
  859. }
  860.  
  861. void t16_flush(void)
  862. {
  863.      longjmp (longjmpbuf, 9);
  864. }
  865.  
  866. void spindac(int a, int b)
  867. {
  868.   // longjmp (longjmpbuf, 10);
  869. }
  870.  
  871. void ValidateLuts(void)
  872. {
  873.      longjmp (longjmpbuf, 13);
  874. }
  875.  
  876. void t16_putline(void)
  877. {
  878.      longjmp (longjmpbuf, 17);
  879. }
  880.  
  881. void t16_create(void)
  882. {
  883.      longjmp (longjmpbuf, 19);
  884. }
  885.  
  886. void CustomLut(void)
  887. {
  888.      longjmp (longjmpbuf, 20);
  889. }
  890.  
  891. void fullscreen_prompt(void)
  892. {
  893.      longjmp (longjmpbuf, 25);
  894. }
  895.  
  896. /* Fractint Release 15.1 engine */
  897.  
  898. void setattr(void)
  899. {
  900.      longjmp (longjmpbuf, 26);
  901. }
  902.  
  903. void _bios_serialcom(void)
  904. {
  905.  
  906. }
  907.  
  908. void dvid_status(void)
  909. {
  910.      longjmp (longjmpbuf, 27);
  911. }
  912.  
  913. void stackscreen(void)
  914. {
  915.      longjmp (longjmpbuf, 28);
  916. }
  917.  
  918. void unstackscreen(void)
  919. {
  920.      longjmp (longjmpbuf, 29);
  921. }
  922.  
  923. int thinking(int a, char * b)
  924. {
  925. return (keypressed());
  926. }
  927.  
  928. int    putstringcenter(int a,int b,int c,int d,char far * e)
  929. {
  930.  
  931. }
  932.  
  933. int helptitle()
  934. {
  935.  
  936. }
  937. /* **** **** **** **** **** **** */
  938.  
  939. #pragma optimize("",on)
  940.  
  941. /* other loose-end routines (from WINFRACT) */
  942.  
  943. goodbye()
  944. {
  945. /* naah - let's stick around */
  946. }
  947. void   putstring(int a,int b,int c,unsigned char far * d)
  948. {
  949. /* CMDFILES calls this in case of an error */
  950. }
  951. tovideotable()
  952. {
  953. /* CMDFILES calls this */
  954. }
  955.  
  956. /* fake/not-yet-implemented subroutines */
  957.  
  958. int kbhit() { return(keypressed()); }
  959. int getch() {return(13);}
  960.  
  961. void farmessage(unsigned char far *foo) {}
  962. void setvideomode(int foo1, int foo2, int foo3, int foo4) {}
  963. int fromvideotable() {}
  964. int setforgraphics() {}
  965. int setfortext() {}
  966. int movecursor() {}
  967. int home() {}
  968. int _FAR_ _cdecl printf() {longjmp (longjmpbuf, 21);}
  969. int help_overlay() {}
  970. int prompts_overlay() {}
  971. int rotate_overlay() {}
  972. int printer_overlay() {}
  973. int miscovl_overlay() {}
  974. int pot_startdisk() {}
  975. int SetTgaColors() {}
  976. int startdisk() {}
  977. int enddisk() {}
  978. int readdisk() {}
  979. int writedisk() {}
  980. int nosnd(){}
  981. int snd(){}
  982. int targa_startdisk(){}
  983. int targa_writedisk(){}
  984. int SetColorPaletteName() {}
  985. int get_3d_params() { return(0);}
  986. int findfont() {return(0);}
  987. int readticker(){return(0);}
  988. int EndTGA(){}
  989. 
  990.