home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / WINDOWS / PROGRAM / WINSRC20.ZIP / WINDOS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-10-23  |  26.6 KB  |  910 lines

  1. /*
  2.     Routines which simulate DOS functions in the existing
  3.     Fractint for DOS
  4. */
  5.  
  6. #include "windows.h"
  7. #include "fractint.h"
  8. #include "winfract.h"
  9. #include <time.h>
  10. #include <stdio.h>
  11.  
  12. int save_system;           /* tag identifying Fractint for Windows */
  13. int save_release;          /* tag identifying version number */
  14. int win_release = 200;     /* tag identifying version number */
  15. char win_comment[] =       /* "About..." comment */ 
  16.     {" "};                 /*  publicly-released version */
  17. /*  {"Test Version - Not for Release"};   interim test versions */
  18.  
  19. extern BOOL bTrack;                  /* TRUE if user is selecting a region */
  20. extern BOOL zoomflag;                /* TRUE is a zoom-box selected */
  21.  
  22. extern HWND hwnd;                    /* handle to main window */
  23.  
  24. extern int xdots, ydots, colors, maxiter;
  25. extern int xposition, yposition, win_xoffset, win_yoffset, xpagesize, ypagesize;
  26. extern int win_xdots, win_ydots;
  27.  
  28. extern int last_written_y;           /* last line written */
  29. extern int screen_to_be_cleared;     /* clear screen flag */
  30.  
  31. extern int time_to_act;              /* time to take some action? */
  32. extern int time_to_restart;          /* time to restart?  */
  33. extern int time_to_quit;             /* time to quit? */
  34. extern int time_to_reinit;           /* time to reinitialize? */
  35. extern int time_to_load;             /* time to load? (DECODE) */
  36. extern int time_to_save;             /* time to save? (ENCODE) */
  37. extern int time_to_print;            /* time to print? (PRINTER) */
  38. extern int time_to_cycle;            /* time to begin color-cycling? */
  39.  
  40. extern unsigned char dacbox[256][3];
  41.  
  42. extern BOOL win_systempaletteused;    /* flag system palette set */
  43.  
  44. extern unsigned char far temp_array[];   /* temporary spot for Encoder rtns */
  45.  
  46. extern HANDLE hpixels;            /* handle to the DIB pixels */
  47. extern unsigned char huge *pixels;   /* the device-independent bitmap pixels */
  48. int pixels_per_byte;                 /* pixels/byte in the pixmap */
  49. long pixels_per_bytem1;              /* pixels / byte - 1 (for ANDing) */
  50. int pixelshift_per_byte;             /* 0, 1, 2, or 3 */
  51. int bytes_per_pixelline;             /* pixels/line / pixels/byte */
  52.  
  53. extern int kbdcount;
  54.  
  55. extern int win_overlay3d;
  56. extern int win_display3d;
  57.  
  58. /****************************************************************************
  59.  
  60.     FUNCTION: keypressed(), getakey()
  61.  
  62.     PURPOSE:
  63.          keypressed()
  64.               Checks for, and processes, messages.
  65.               Returns -1 if it's time to wrap up and go home.
  66.               Returns 0 otherwise.
  67.         getakey()
  68.               same, but doesn't return until it's time to.
  69.  
  70.  
  71. ****************************************************************************/
  72.  
  73. BOOL dont_wait_for_a_key = TRUE;
  74.  
  75. int getakey()
  76. {
  77. int i;
  78.  
  79. dont_wait_for_a_key = FALSE;
  80. i = keypressed();
  81. dont_wait_for_a_key = TRUE;
  82. zoomflag = FALSE;
  83. return(i);
  84.  
  85. }
  86.  
  87. int keypressed()
  88. {
  89. MSG msg;
  90.  
  91. if (dont_wait_for_a_key)
  92.     if (PeekMessage(&msg, NULL, NULL, NULL, PM_NOREMOVE) == 0) {
  93.         time_to_act = time_to_reinit+time_to_restart+time_to_quit+
  94.             time_to_load+time_to_save+time_to_print+time_to_cycle;
  95.         /* bail out if nothing is happening */
  96.         return(time_to_act);
  97.         }
  98.  
  99. while (GetMessage(&msg, NULL, NULL, NULL)) {
  100.  
  101.     TranslateMessage(&msg);
  102.     DispatchMessage(&msg); 
  103.  
  104.     if (!bTrack) {                /* don't do this if mouse-button is down */
  105.         time_to_act = time_to_reinit+time_to_restart+time_to_quit+
  106.             time_to_load+time_to_save+time_to_print+time_to_cycle;
  107.         if (dont_wait_for_a_key || time_to_act)
  108.             return(time_to_act);
  109.         }
  110.  
  111.     }
  112.  
  113. if (!dont_wait_for_a_key)
  114.     time_to_quit = 1;
  115.         
  116.     /* bail out if nothing is happening */
  117.     time_to_act = time_to_reinit+time_to_restart+time_to_quit+
  118.         time_to_load+time_to_save+time_to_print+time_to_cycle;
  119.     return(time_to_act);
  120.  
  121. }
  122.  
  123. /****************************************************************************
  124.  
  125.     FUNCTION: putcolor(int x, int y, int color), getcolor(int x, int y)
  126.  
  127.     PURPOSE:
  128.         putcolor:
  129.            sets the "color" value of the pixel at location x,y
  130.            (actually, a palette value)
  131.         getcolor:
  132.            returns the "color" value of the pixel at location x,y
  133.            (actually, a palette value)
  134.  
  135. ****************************************************************************/
  136.  
  137. extern int debug_fastupdate;
  138.  
  139. time_t last_time;
  140. time_t update_time;
  141. long minimum_update;
  142. long pixelsout;
  143. int top_changed, bottom_changed;
  144.  
  145. static unsigned char win_andmask[8];
  146. static unsigned char win_notmask[8];
  147. static unsigned char win_bitshift[8];
  148.  
  149. void putcolor(int x, int y, int color)
  150. {
  151. RECT tempRect;                   /* temporary rectangle structure */
  152. long i;
  153. int j, tempcolor, temp_top_changed, temp_bottom_changed;
  154. time_t this_time;
  155.  
  156. kbdcount--;      /* partially adjust for the lower speed of Win graphics */
  157.  
  158. last_written_y = y;
  159. if (y < top_changed) top_changed = y;
  160. if (y > bottom_changed) bottom_changed = y;
  161.  
  162. i = win_ydots-1-y;
  163. i = (i * win_xdots) + x;
  164.  
  165. if (x >= 0 && x < xdots && y >= 0 && y < ydots) {
  166.     if (pixelshift_per_byte == 0) {
  167.           pixels[i] = color % colors;
  168.           }
  169.      else {
  170.           unsigned int j;
  171.           j = i & pixels_per_bytem1;
  172.           i = i >> pixelshift_per_byte;
  173.           pixels[i] = (pixels[i] & win_notmask[j]) +
  174.               (((unsigned char)(color % colors)) << win_bitshift[j]);
  175.           }
  176.  
  177.      /* check the time every nnn pixels */
  178.      if (debug_fastupdate || ++pixelsout > 100) {
  179.           pixelsout = 0;
  180.           this_time = time(NULL);
  181.           /* time to update the screen? */
  182.           if (debug_fastupdate || (this_time - last_time) > update_time ||
  183.               (minimum_update*(this_time-last_time)) > (bottom_changed-top_changed)) {
  184.               temp_top_changed = top_changed - win_yoffset;
  185.               temp_bottom_changed = bottom_changed - win_yoffset;
  186.               if (!(temp_top_changed >= ypagesize || temp_bottom_changed < 0)) {
  187.                   if (temp_top_changed < 0) temp_top_changed = 0;
  188.                   if (temp_bottom_changed < 0) temp_bottom_changed = 0;
  189.                   tempRect.top = temp_top_changed;
  190.                   tempRect.bottom = temp_bottom_changed+1;
  191.                   tempRect.left = 0;
  192.                   tempRect.right = xdots;
  193.                   InvalidateRect(hwnd, &tempRect, FALSE);
  194.                   keypressed();    /* force a look-see at the screen */
  195.                   }
  196.               last_time = this_time;
  197.               top_changed = win_ydots;
  198.               bottom_changed = 0;
  199.               }
  200.           }
  201.      }
  202.  
  203. }
  204.  
  205. int getcolor(int x, int y)
  206. {
  207. long i;
  208.  
  209. i = win_ydots-1-y;
  210. i = (i * win_xdots) + x;
  211.  
  212. if (x >= 0 && x < xdots && y >= 0 && y < ydots) {
  213.     if (pixelshift_per_byte == 0) {
  214.           return(pixels[i]);
  215.           }
  216.      else {
  217.           unsigned int j;
  218.           j = i & pixels_per_bytem1;
  219.           i = i >> pixelshift_per_byte;
  220.           return((int)((pixels[i] & win_andmask[j]) >> win_bitshift[j]));
  221.           }
  222.      }
  223. else
  224.      return(0);
  225. }
  226.  
  227. int put_line(int rownum, int leftpt, int rightpt, unsigned char *localvalues)
  228. {
  229. int i, len;
  230. long startloc;
  231.  
  232. len = rightpt - leftpt;
  233. if (rightpt >= xdots) len = xdots - 1 - leftpt;
  234. startloc = win_ydots-1-rownum;
  235. startloc = (startloc * win_xdots) + leftpt;
  236.  
  237. kbdcount -= (len>>2);      /* adjust for the lower speed of Win graphics */
  238.  
  239. if (rownum < 0 || rownum >= ydots || leftpt < 0) {
  240.     return(0);
  241.     }
  242.  
  243. if (pixelshift_per_byte == 0) {
  244.     for (i = 0; i <= len; i++)
  245.         pixels[startloc+i] = localvalues[i];
  246.     }
  247. else {
  248.     unsigned int j;
  249.     long k;
  250.     for (i = 0; i <= len; i++) {
  251.         k = startloc + i;
  252.         j = k & pixels_per_bytem1;
  253.         k = k >> pixelshift_per_byte;
  254.         pixels[k] = (pixels[k] & win_notmask[j]) +
  255.             (((unsigned char)(localvalues[i] % colors)) << win_bitshift[j]);
  256.         }
  257.     }
  258. pixelsout += len;
  259. putcolor(leftpt, rownum, localvalues[0]);
  260. }
  261.  
  262. int get_line(int rownum, int leftpt, int rightpt, unsigned char *localvalues)
  263. {
  264. int i, len;
  265. long startloc;
  266.  
  267. len = rightpt - leftpt;
  268. if (rightpt >= xdots) len = xdots - 1 - leftpt;
  269. startloc = win_ydots-1-rownum;
  270. startloc = (startloc * win_xdots) + leftpt;
  271.  
  272. if (rownum < 0 || rownum >= ydots || leftpt < 0 || rightpt >= xdots) {
  273.     for (i = 0; i <= len; i++)
  274.         localvalues[i] = 0;
  275.     return(0);
  276.     }
  277.  
  278. if (pixelshift_per_byte == 0) {
  279.     for (i = 0; i <= len; i++)
  280.         localvalues[i] = pixels[startloc+i];
  281.     }
  282. else {
  283.     unsigned int j;
  284.     long k;
  285.     for (i = 0; i <= len; i++) {
  286.         k = startloc + i;
  287.         j = k & pixels_per_bytem1;
  288.         k = k >> pixelshift_per_byte;
  289.         localvalues[i] = (pixels[k] & win_andmask[j]) >> win_bitshift[j];
  290.         }
  291.     }
  292. }
  293.  
  294. extern int rowcount;
  295.  
  296. int out_line(unsigned char *localvalues, int numberofdots)
  297. {
  298.     put_line(rowcount++, 0, numberofdots, localvalues);
  299. }
  300.  
  301. extern LPBITMAPINFO pDibInfo;        /* pointer to the DIB info */
  302.  
  303. int clear_screen(int forceclear)
  304. {
  305. long numdots;
  306. int i;
  307.  
  308. win_xdots = (xdots+3) & 0xfffc;
  309. win_ydots = ydots;
  310. pixelshift_per_byte = 0;
  311. pixels_per_byte   = 1;
  312. pixels_per_bytem1 = 0;
  313. if (colors == 16) {
  314.     win_xdots = (xdots+7) & 0xfff8;
  315.     pixelshift_per_byte = 1;
  316.     pixels_per_byte = 2;
  317.     pixels_per_bytem1 = 1;
  318.     win_andmask[0] = 0xf0;  win_notmask[0] = 0x0f; win_bitshift[0] = 4;
  319.     win_andmask[1] = 0x0f;  win_notmask[1] = 0xf0; win_bitshift[1] = 0;
  320.     }
  321. if (colors == 2) {
  322.     win_xdots = (xdots+31) & 0xffe0;
  323.     pixelshift_per_byte = 3;
  324.     pixels_per_byte = 8;
  325.     pixels_per_bytem1 = 7;
  326.     win_andmask[0] = 0x80;  win_notmask[0] = 0x7f; win_bitshift[0] = 7;
  327.     for (i = 1; i < 8; i++) {
  328.         win_andmask[i] = win_andmask[i-1] >> 1;
  329.         win_notmask[i] = (win_notmask[i-1] >> 1) + 0x80;
  330.         win_bitshift[i] = win_bitshift[i-1] - 1;
  331.         }
  332.     }
  333.  
  334. numdots = (long)win_xdots * (long) win_ydots;
  335. update_time = 2;
  336. if (numdots > 200000L) update_time = 4;
  337. if (numdots > 400000L) update_time = 8;
  338. last_time = time(NULL) - update_time + 1;
  339. minimum_update = 7500/xdots;    /* assume 75,000 dots/sec drawing speed */
  340.  
  341. last_written_y = -1;
  342. pixelsout = 0;
  343. top_changed = win_ydots;
  344. bottom_changed = 0;
  345.  
  346. bytes_per_pixelline = win_xdots >> pixelshift_per_byte;
  347.  
  348. /* Create the Device-independent Bitmap entries */
  349. pDibInfo->bmiHeader.biWidth  = win_xdots;
  350. pDibInfo->bmiHeader.biHeight = win_ydots;
  351. pDibInfo->bmiHeader.biSizeImage = (DWORD)bytes_per_pixelline * win_ydots;
  352. pDibInfo->bmiHeader.biBitCount = 8 / pixels_per_byte;
  353.  
  354. /* hard to believe, but this is the fast way to clear the pixel map */
  355. if (hpixels) {
  356.      GlobalUnlock(hpixels);
  357.      GlobalFree(hpixels);
  358.      }
  359.  
  360. if (!(hpixels = GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT,
  361.      (long)(numdots >> pixelshift_per_byte)+1L)))
  362.      return(0);
  363. if (!(pixels = (char huge *)GlobalLock(hpixels)))
  364.      return(0);
  365.  
  366. /* adjust the colors for B&W or default */
  367. if (colors == 2) {
  368.     dacbox[0][0] = dacbox[0][1] = dacbox[0][2] = 0;
  369.     dacbox[1][0] = dacbox[1][1] = dacbox[1][2] = 63;
  370.     spindac(0,1);
  371.     }
  372. else
  373.     restoredac();   /* color palette */
  374.  
  375. screen_to_be_cleared = 1;
  376. InvalidateRect(hwnd, NULL, TRUE);
  377.  
  378. if (forceclear)
  379.     keypressed();        /* force a look-see at the screen */
  380.  
  381. return(1);
  382. }
  383.  
  384. int flush_screen()
  385. {
  386.  
  387. last_written_y = 0;
  388.  
  389. InvalidateRect(hwnd, NULL, FALSE);
  390.  
  391. }
  392.  
  393. /****************************************************************************
  394.  
  395.     FUNCTION: buzzer(int buzzertype)
  396.  
  397.     PURPOSE:
  398.               make some sort of sound (hey, we do what we can)
  399.  
  400. ****************************************************************************/
  401.  
  402. void buzzer(int i)
  403. {
  404.  
  405. MessageBeep(0);
  406.  
  407. }
  408.  
  409. /****************************************************************************
  410.  
  411.     FUNCTION: unsigned char far * farmemalloc(long bytecount)
  412.               void farmemfree(unsigned char * bytepointer)
  413.     PURPOSE:
  414.               allocate and free memory in a manner consistent with
  415.               Fractint for DOS
  416.  
  417. ****************************************************************************/
  418.  
  419. #define MAXFARMEMALLOCS  20        /* max active farmemallocs */
  420. int   farmemallocinit = 0;              /* any memory been allocated yet?   */
  421. HANDLE farmemallochandles[MAXFARMEMALLOCS];            /* handles  */
  422. unsigned char far *farmemallocpointers[MAXFARMEMALLOCS];    /* pointers */
  423.  
  424. unsigned char far * farmemalloc(long bytecount)
  425. {
  426. int i;
  427. HANDLE temphandle;
  428. unsigned char far *temppointer;
  429.  
  430. if (!farmemallocinit) {        /* never been here yet - initialize */
  431.     farmemallocinit = 1;
  432.     for (i = 0; i < MAXFARMEMALLOCS; i++) {
  433.         farmemallochandles[i] = (HANDLE)0;
  434.         farmemallocpointers[i] = NULL;
  435.         }
  436.     }
  437.  
  438. for (i = 0; i < MAXFARMEMALLOCS; i++)  /* look for a free handle */
  439.     if (farmemallochandles[i] == (HANDLE)0) break;
  440.  
  441. if (i == MAXFARMEMALLOCS)       /* uh-oh - no more handles */
  442.    return(NULL);        /* can't get far memory this way */
  443.  
  444. if (!(temphandle = GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, bytecount)))
  445.      return(NULL);        /* can't allocate the memory */
  446. if (!(temppointer = (unsigned char far *)GlobalLock(temphandle))) {
  447.      GlobalFree(temphandle);
  448.      return(NULL);        /* ?? can't lock the memory ?? */
  449.      }
  450.  
  451. farmemallochandles[i] =  temphandle;
  452. farmemallocpointers[i] = temppointer;
  453. return(temppointer);
  454. }
  455.  
  456. void farmemfree(unsigned char far *bytepointer)
  457. {
  458. int i;
  459. HANDLE temphandle;
  460. unsigned char far *temppointer;
  461.  
  462. if (bytepointer == (unsigned char far *)NULL) return;
  463.  
  464. for (i = 0; i < MAXFARMEMALLOCS; i++)    /* search for a matching pointer */
  465.     if (farmemallocpointers[i] == bytepointer)
  466.          break;
  467. if (i < MAXFARMEMALLOCS) {        /* got one */
  468.     GlobalUnlock(farmemallochandles[i]);
  469.     GlobalFree(farmemallochandles[i]);
  470.     farmemallochandles[i] = (HANDLE)0;
  471.     }
  472.  
  473. }
  474.  
  475. debugmessage(char *msg1, char *msg2)
  476. {
  477. MessageBox (
  478.     GetFocus(),
  479.     msg2,
  480.     msg1,
  481.     MB_ICONASTERISK | MB_OK);
  482.  
  483. }
  484.  
  485. texttempmsg(char *msg1)
  486. {
  487. MessageBox (
  488.     GetFocus(),
  489.     msg1,
  490.     "Encoder",
  491.     MB_ICONASTERISK | MB_OK);
  492. }
  493.  
  494. stopmsg(int flags, char *msg1)
  495. {
  496. int result;
  497.  
  498. if (! (flags & 4)) MessageBeep(0);
  499.  
  500. result = IDOK;
  501.  
  502. if (!(flags & 2))
  503.     MessageBox (
  504.         GetFocus(),
  505.         msg1,
  506.         "Fractint for Windows",
  507.         MB_ICONASTERISK | MB_OK);
  508. else 
  509.     result = MessageBox (
  510.         GetFocus(),
  511.         msg1,
  512.         "Fractint for Windows",
  513.         MB_ICONQUESTION | MB_OKCANCEL);
  514.  
  515. if (result == 0 || result == IDOK || result == IDYES)
  516.     return(0);
  517. else
  518.     return(-1);
  519. }
  520.  
  521. extern char readname[];
  522. extern int fileydots, filexdots, filecolors;
  523. extern int     iNumColors;    /* Number of colors supported by device           */
  524.  
  525. win_load()
  526. {
  527. int i;
  528. char temp[80];
  529.  
  530. time_to_load = 0;
  531.  
  532.     start_wait();
  533.     if ((i = read_overlay()) >= 0 && (!win_display3d || 
  534.         xdots < filexdots || ydots < fileydots)) {
  535.         if (win_display3d) stopmsg(0,
  536.             "3D and Overlay3D file image sizes must be\nat least as large as the display image.\nAltering your display image to match the file.");
  537.         xdots = filexdots;
  538.         ydots = fileydots;
  539.         colors = filecolors;
  540.         if (colors > 16) colors = 256;
  541.         if (colors >  2 && colors < 16) colors = 16;
  542.         if (xdots < 50) xdots = 50;
  543.         if (xdots > 2048) xdots = 2048;
  544.         if (ydots < 50) ydots = 50;
  545.         if (ydots > 2048) ydots = 2048;
  546.         set_win_offset();
  547.         clear_screen(0);
  548.         }
  549.     end_wait();
  550.     return(i);
  551. }
  552.  
  553. win_save()
  554. {
  555.     start_wait();
  556.     time_to_save = 0;
  557.     save_system = 1;
  558.     save_release = win_release;
  559.     savetodisk(readname);
  560.     end_wait();
  561. }
  562.  
  563. extern HDC PASCAL GetPrinterDC(void);
  564.  
  565. win_print()
  566. {
  567. int Return;
  568. int display_xpixperinch, display_ypixperinch;
  569. int printer_xdots, printer_ydots, printer_colors;
  570. int printer_xpixperinch, printer_ypixperinch;
  571. int printer_xmill, printer_ymill;
  572. int printer_xacross, printer_yacross;
  573. int printer_bandable;
  574. long firstpixel;
  575. float daspect, paspect;
  576. HDC printerDC, displayDC;
  577. WORD printer_usage;
  578. RECT printerRect;
  579. int more;
  580.  
  581. time_to_print = 0;
  582.  
  583. displayDC = GetDC(NULL);
  584. display_xpixperinch  =  GetDeviceCaps(displayDC,LOGPIXELSX);
  585. display_ypixperinch  =  GetDeviceCaps(displayDC,LOGPIXELSY);
  586. ReleaseDC(NULL,displayDC);
  587. daspect = ((float)xdots / (float)display_xpixperinch) /
  588.     ((float)ydots / (float)display_ypixperinch);
  589.  
  590. if ((printerDC = GetPrinterDC())) {
  591.     start_wait();
  592.     printer_xpixperinch  =  GetDeviceCaps(printerDC,LOGPIXELSX);
  593.     printer_ypixperinch  =  GetDeviceCaps(printerDC,LOGPIXELSY);
  594.     printer_xmill  =  GetDeviceCaps(printerDC,HORZSIZE);
  595.     printer_ymill  =  GetDeviceCaps(printerDC,VERTSIZE);
  596.     printer_xdots  =  GetDeviceCaps(printerDC,HORZRES);
  597.     printer_ydots  =  GetDeviceCaps(printerDC,VERTRES);
  598.     printer_colors =  GetDeviceCaps(printerDC,NUMCOLORS);
  599.     printer_bandable =  GetDeviceCaps(printerDC,RASTERCAPS) & RC_BANDING;
  600.     printer_bandable = 0;
  601.     paspect = ((float)printer_xdots / (float) printer_xmill) /
  602.         ((float)printer_ydots / (float) printer_ymill);
  603.     printer_xacross = printer_xdots;
  604.     printer_yacross = (float)printer_xdots / daspect / paspect;
  605.     if (printer_yacross > printer_ydots) {
  606.         printer_xacross = (float)printer_xacross * (float) printer_ydots /
  607.             (float)printer_yacross;
  608.         if (printer_xacross > printer_xdots)
  609.             printer_xacross = printer_xdots;
  610.         printer_yacross = printer_ydots;
  611.         }
  612.     firstpixel = win_ydots - ydots;
  613.     firstpixel = firstpixel * bytes_per_pixelline;
  614.     printer_usage = DIB_PAL_COLORS;
  615.     if (printer_colors <= 2) {
  616.         mono_dib_palette();      /* B&W stripes for B&W printers */
  617.         printer_usage = DIB_RGB_COLORS;
  618.         }
  619.     Return = Escape (printerDC, STARTDOC, 17, (LPSTR)"Fractint Printout", NULL);
  620.     if (Return <= 0) goto oops;
  621.     if (printer_bandable)
  622.         Escape(printerDC, NEXTBAND, 0, NULL, (LPSTR) &printerRect);
  623.     more = 1;
  624.     while (more) {
  625.         if (printer_bandable)
  626.             DPtoLP(printerDC, (LPPOINT) &printerRect, 2);
  627.         Return = StretchDIBits(printerDC,
  628.             0, 0,
  629.             printer_xacross, printer_yacross,
  630.             0, 0,
  631.             xdots, ydots,
  632.             &pixels[firstpixel], (LPBITMAPINFO)pDibInfo,
  633.             printer_usage, SRCCOPY);
  634.         if (Return <= 0) goto oops;
  635.         more = 0;
  636.         if (printer_bandable) {
  637.             Escape(printerDC, NEXTBAND, 0, NULL, (LPSTR) &printerRect);
  638.             more = IsRectEmpty(&printerRect);
  639.             }
  640.         }
  641.     Return = Escape(printerDC, NEWFRAME, 0, NULL, NULL);
  642.     if (Return <= 0) goto oops;
  643. oops: Escape(printerDC, ENDDOC, 0, NULL, NULL);
  644.     DeleteDC(printerDC);
  645.     if (printer_colors <= 2) 
  646.         default_dib_palette();   /* replace the palette */
  647.     end_wait();
  648.     if (Return < 0) stopmsg(0,
  649.         "File Print failed\nYou probably ran out of memory\nSorry...");
  650.     }
  651. else
  652.     stopmsg(0,"?? Can't find the printer!! ???");
  653. }
  654.  
  655. extern int win_cycledir, win_cyclerand, win_cyclefreq;
  656.  
  657. extern HANDLE  hPal;       /* Palette Handle */
  658. extern LPLOGPALETTE pLogPal;  /* pointer to the application's logical palette */
  659. extern unsigned char far win_dacbox[256][3];
  660. #define PALETTESIZE 256               /* dull-normal VGA                    */
  661.  
  662. static int win_fsteps[] = {54, 24, 8};
  663.  
  664. int win_animate_flag = 0;
  665. int win_syscolorindex[21];
  666. DWORD win_syscolorold[21];
  667. DWORD win_syscolornew[21];
  668.  
  669. extern int debugflag;
  670.  
  671. win_cycle()
  672. {
  673. int istep, jstep, fstep, step, oldstep, last, next, maxreg;
  674. int incr, random, fromred, fromblue, fromgreen, tored, toblue, togreen;
  675. HDC hDC;                      /* handle to device context           */
  676.  
  677. fstep = 1;                              /* randomization frequency      */
  678. oldstep = 1;                /* single-step            */
  679. step = 256;                /* single-step            */
  680. incr = 999;                /* ready to randomize        */
  681. maxreg = 256;                /* maximum register to rotate   */
  682. last = maxreg-1;            /* last box that was filled    */
  683. next = 1;                /* next box to be filled    */
  684. if (win_cycledir < 0) {
  685.     last = 1;
  686.     next = maxreg;
  687.     }
  688. srand((unsigned)time(NULL));        /* randomize things        */
  689.  
  690. hDC = GetDC(GetFocus());
  691.  
  692. win_animate_flag = 1;
  693. SetPaletteEntries(hPal, 0, pLogPal->palNumEntries, pLogPal->palPalEntry);
  694. SelectPalette (hDC, hPal, 1);
  695.  
  696. if ((iNumColors <= 16 || debugflag == 1000) && !win_systempaletteused) {
  697.     int i;
  698.     DWORD white, black;
  699.     win_systempaletteused = TRUE;
  700.     white = 0xffffff00;
  701.     black = 0;
  702.     for (i = 0; i <= COLOR_ENDCOLORS; i++) {
  703.         win_syscolorindex[i] = i;
  704.         win_syscolorold[i] = GetSysColor(i);
  705.         win_syscolornew[i] = black;
  706.         }
  707.     win_syscolornew[COLOR_BTNTEXT] = white;
  708.     win_syscolornew[COLOR_CAPTIONTEXT] = white;
  709.     win_syscolornew[COLOR_GRAYTEXT] = white;
  710.     win_syscolornew[COLOR_HIGHLIGHTTEXT] = white;
  711.     win_syscolornew[COLOR_MENUTEXT] = white;
  712.     win_syscolornew[COLOR_WINDOWTEXT] = white;
  713.     win_syscolornew[COLOR_WINDOWFRAME] = white;
  714.     win_syscolornew[COLOR_INACTIVECAPTION] = white;
  715.     win_syscolornew[COLOR_INACTIVEBORDER] = white;
  716.     SetSysColors(COLOR_ENDCOLORS,win_syscolorindex,win_syscolornew);
  717.     SetSystemPaletteUse(hDC,SYSPAL_NOSTATIC);
  718.     UnrealizeObject(hPal);
  719.     }
  720.  
  721. while (time_to_cycle) {
  722.     if (win_cyclerand) {
  723.         for (istep = 0; istep < step; istep++) {
  724.             jstep = next + (istep * win_cycledir);
  725.             if (jstep <=      0) jstep += maxreg-1;
  726.             if (jstep >= maxreg) jstep -= maxreg-1;
  727.             if (++incr > fstep) {    /* time to randomize    */
  728.                 incr = 1;
  729.                 fstep = ((win_fsteps[win_cyclefreq]*
  730.                     (rand() >> 8)) >> 6) + 1;
  731.                 fromred   = dacbox[last][0];
  732.                 fromgreen = dacbox[last][1];
  733.                 fromblue  = dacbox[last][2];
  734.                 tored      = rand() >> 9;
  735.                 togreen   = rand() >> 9;
  736.                 toblue      = rand() >> 9;
  737.                 }
  738.             dacbox[jstep][0] = fromred   + (((tored   - fromred  )*incr)/fstep);
  739.             dacbox[jstep][1] = fromgreen + (((togreen - fromgreen)*incr)/fstep);
  740.             dacbox[jstep][2] = fromblue  + (((toblue  - fromblue )*incr)/fstep);
  741.             }
  742.         }
  743.         if (step >= 256) step = oldstep;
  744.  
  745.     spindac(win_cycledir,step);
  746.     AnimatePalette(hPal, 0, pLogPal->palNumEntries, pLogPal->palPalEntry);
  747.     RealizePalette(hDC); 
  748.     keypressed();
  749.     if (win_cyclerand == 2) {
  750.         win_cyclerand = 1;
  751.         step = 256;
  752.         }
  753.     }
  754.  
  755. win_animate_flag = 0;
  756. ReleaseDC(GetFocus(),hDC);
  757.  
  758. }
  759.  
  760. /* cursor routines */
  761.  
  762. HANDLE hSaveCursor = 0;             /* the original cursor value */
  763. HANDLE hHourGlass;                  /* the hourglass cursor value */
  764.  
  765. start_wait()
  766. {
  767. if (!hSaveCursor)
  768.     hHourGlass = LoadCursor(NULL, IDC_WAIT);
  769. hSaveCursor = SetCursor(hHourGlass);
  770. keypressed();   /* just to give messages, like cursor-changes, a chance */
  771. }
  772.  
  773. end_wait()
  774. {
  775. hSaveCursor = LoadCursor(NULL,IDC_ARROW);
  776. SetCursor(hSaveCursor);
  777. keypressed();   /* just to give messages, like cursor-changes, a chance */
  778. }
  779.  
  780. /* video-mode routines */
  781.  
  782. extern int    viewwindow;        /* 0 for full screen, 1 for window */
  783. extern float  viewreduction;        /* window auto-sizing */
  784. extern float  finalaspectratio;     /* for view shape and rotation */
  785. extern int    viewxdots,viewydots;    /* explicit view sizing */
  786. extern int    fileydots, filexdots, filecolors;
  787. extern float  fileaspectratio;
  788. extern int    skipxdots,skipydots;    /* for decoder, when reducing image */
  789.  
  790. int get_video_mode(struct fractal_info *info)
  791. {
  792.    viewwindow = viewxdots = viewydots = 0;
  793.    fileaspectratio = .75;
  794.    skipxdots = skipydots = 0;
  795.    return(0);
  796. }
  797.  
  798.  
  799. void spindac(int direction, int step)
  800. {
  801. int i, j, k;
  802.  
  803. for (k = 0; k < step; k++) {
  804.     if (direction > 0) {
  805.         for (j = 0; j < 3; j++) {
  806.             for (i = 255; i >= 1; i--)
  807.                 dacbox[i+1][j] = dacbox[i][j];
  808.             dacbox[1][j] = dacbox[256][j];
  809.             }
  810.         }
  811.     if (direction < 0) {
  812.         for (j = 0; j < 3; j++) {
  813.             dacbox[256][j] = dacbox[1][j];
  814.             for (i = 1; i < 256; i++)
  815.                 dacbox[i][j] = dacbox[i+1][j];
  816.             }
  817.         }
  818.     }
  819.  
  820.     /* fill in intensities for all palette entry colors */
  821.     for (i = 0; i < 256; i++) {
  822.         pLogPal->palPalEntry[i].peRed   = ((BYTE)dacbox[i][0]) << 2;
  823.         pLogPal->palPalEntry[i].peGreen = ((BYTE)dacbox[i][1]) << 2;
  824.         pLogPal->palPalEntry[i].peBlue  = ((BYTE)dacbox[i][2]) << 2;
  825.         pLogPal->palPalEntry[i].peFlags = PC_RESERVED;
  826.         }
  827.  
  828.     if (!win_animate_flag) {
  829.         HDC hDC;
  830.         hDC = GetDC(GetFocus());
  831.         SetPaletteEntries(hPal, 0, pLogPal->palNumEntries, pLogPal->palPalEntry);
  832.         SelectPalette (hDC, hPal, 1);
  833.         RealizePalette(hDC); 
  834.         ReleaseDC(GetFocus(),hDC);
  835.         }
  836. }
  837.  
  838. restoredac()
  839. {
  840. int iLoop;
  841. int j;
  842.  
  843.     /* fill in intensities for all palette entry colors */
  844.     for (iLoop = 0; iLoop < PALETTESIZE; iLoop++) 
  845.         for (j = 0; j < 3; j++)
  846.             dacbox[iLoop][j] = win_dacbox[iLoop][j];
  847.     spindac(0,1);
  848. }
  849.  
  850. int ValidateLuts( char * fn )
  851. {
  852. FILE * f;
  853. unsigned    r, g, b, index;
  854. unsigned char    line[101];
  855. unsigned char    temp[81];
  856.     strcpy (temp,fn);
  857.     if (strchr(temp,'.') == NULL) /* Did name have an extension? */
  858.         strcat(temp,".map");  /* No? Then add .map */
  859.     findpath( temp, line);          /* search the dos path */
  860.     f = fopen( line, "r" );
  861.     if (f == NULL)
  862.         return 1;
  863.     for( index = 0; index < 256; index++ ) {
  864.         if (fgets(line,100,f) == NULL)
  865.             break;
  866.         sscanf( line, "%d %d %d", &r, &g, &b );
  867.         /** load global dac values **/
  868.         dacbox[index][0] = r >> 2;    /* maps default to 8 bits */
  869.         dacbox[index][1] = g >> 2;    /* DAC wants 6 bits */
  870.         dacbox[index][2] = b >> 2;
  871.     }
  872.     fclose( f );
  873.     return 0;
  874. }
  875.  
  876. /* fake/not-yet-implemented subroutines */
  877.  
  878. int kbhit() { return(keypressed()); }
  879. int getch() {return(13);}
  880.  
  881. void farmessage(unsigned char far *foo) {}
  882. int calctime() {}
  883. void setvideomode(int foo1, int foo2, int foo3, int foo4) {}
  884. int fromvideotable() {}
  885. int setforgraphics() {}
  886. int setfortext() {}
  887. int movecursor() {}
  888. int home() {}
  889. int _FAR_ _cdecl printf() {}
  890. int help_overlay() {}
  891. int prompts_overlay() {}
  892. int rotate_overlay() {}
  893. int printer_overlay() {}
  894. int miscovl_overlay() {}
  895. int pot_startdisk() {}
  896. int SetTgaColors() {}
  897. int startdisk() {}
  898. int enddisk() {}
  899. int readdisk() {}
  900. int writedisk() {}
  901. int nosnd(){}
  902. int snd(){}
  903. int targa_startdisk(){}
  904. int targa_writedisk(){}
  905. int SetColorPaletteName() {}
  906. int get_3d_params() { return(0);}
  907. int findfont() {return(0);}
  908. int readticker(){return(0);}
  909. int EndTGA(){}
  910.