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