home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / WINDOWS / MISC / WINSR171.ZIP / WINDOS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-07  |  37.1 KB  |  1,356 lines

  1. /*
  2.     Routines which simulate DOS functions in the existing
  3.     Fractint for DOS
  4. */
  5.  
  6. #include "windows.h"
  7. #include "drivinit.h"
  8. #include "fractint.h"
  9. #include "winfract.h"
  10. #include <string.h>
  11. #include <time.h>
  12. #include <stdio.h>
  13.  
  14. extern unsigned char FullPathName[];
  15. extern int FileFormat;
  16.  
  17. int save_system;       /* tag identifying Fractint for Windows */
  18. int save_release;       /* tag identifying version number */
  19. int win_release = 1710;    /* tag identifying version number */
  20. char win_comment[] =       /* "About..." comment */
  21. /*   {" "};                /*  publicly-released version */
  22.      {"Test Version - Not for Release"};   /* interim test versions */
  23.  
  24. extern BOOL bTrack;             /* TRUE if user is selecting a region */
  25. extern BOOL zoomflag;             /* TRUE is a zoom-box selected */
  26.  
  27. extern HWND hwnd;             /* handle to main window */
  28. extern HANDLE hInst;
  29.  
  30. extern HANDLE hAccTable;             /* handle to accelerator table */
  31.  
  32. extern char szHelpFileName[];         /* Help file name*/
  33.  
  34. extern int xdots, ydots, colors, maxiter;
  35. extern int xposition, yposition, win_xoffset, win_yoffset, xpagesize, ypagesize;
  36. extern int win_xdots, win_ydots;
  37.  
  38. extern int last_written_y;         /* last line written */
  39. extern int screen_to_be_cleared;     /* clear screen flag */
  40.  
  41. extern int time_to_act;          /* time to take some action? */
  42. extern int time_to_restart;         /* time to restart?  */
  43. extern int time_to_quit;         /* time to quit? */
  44. extern int time_to_reinit;         /* time to reinitialize? */
  45. extern int time_to_load;         /* time to load? (DECODE) */
  46. extern int time_to_save;         /* time to save? (ENCODE) */
  47. extern int time_to_print;         /* time to print? (PRINTER) */
  48. extern int time_to_cycle;         /* time to begin color-cycling? */
  49.  
  50. extern unsigned char dacbox[256][3];
  51.  
  52. extern BOOL win_systempaletteused;    /* flag system palette set */
  53.  
  54. extern unsigned char far temp_array[];     /* temporary spot for Encoder rtns */
  55.  
  56. extern HANDLE hpixels;            /* handle to the DIB pixels */
  57. extern unsigned char huge *pixels;   /* the device-independent bitmap pixels */
  58. int pixels_per_byte;             /* pixels/byte in the pixmap */
  59. long pixels_per_bytem1;          /* pixels / byte - 1 (for ANDing) */
  60. int pixelshift_per_byte;         /* 0, 1, 2, or 3 */
  61. int bytes_per_pixelline;         /* pixels/line / pixels/byte */
  62. long win_bitmapsize;             /* bitmap size, in bytes */
  63.  
  64. extern int win_overlay3d;
  65. extern int win_display3d;
  66.  
  67. extern void center_window(HWND,int,int);
  68.  
  69. /****************************************************************************
  70.  
  71.     FUNCTION: keypressed(), getakey()
  72.  
  73.     PURPOSE:
  74.      keypressed()
  75.           Checks for, and processes, messages.
  76.           Returns -1 if it's time to wrap up and go home.
  77.           Returns 0 otherwise.
  78.     getakey()
  79.           same, but doesn't return until it's time to.
  80.  
  81.  
  82. ****************************************************************************/
  83.  
  84. BOOL dont_wait_for_a_key = TRUE;
  85.  
  86. #ifdef __BORLANDC__
  87.  
  88. /* Too many functions defaulting to a type 'int' return that should be
  89.    a type 'void'.  I'll just get rid of the warning message for this file
  90.    only.  MCP 8-6-91 */
  91.  
  92.    #pragma warn -rvl
  93.  
  94.    int LPTNumber;
  95.    int stackavail() { return(10240 + (signed int)_SP); }
  96. #else
  97.    int _FAR_ _cdecl printf() {}
  98.    int _bios_serialcom(){}
  99. #endif
  100.  
  101.  
  102.  
  103.  
  104. int getakey()
  105. {
  106. int i;
  107.  
  108. dont_wait_for_a_key = FALSE;
  109. i = keypressed();
  110. dont_wait_for_a_key = TRUE;
  111. zoomflag = FALSE;
  112. return(i);
  113.  
  114. }
  115.  
  116. int keypressed()
  117. {
  118. MSG msg;
  119.  
  120. if (dont_wait_for_a_key)
  121.     if (PeekMessage(&msg, NULL, NULL, NULL, PM_NOREMOVE) == 0) {
  122.     time_to_act = time_to_reinit+time_to_restart+time_to_quit+
  123.         time_to_load+time_to_save+time_to_print+time_to_cycle;
  124.     /* bail out if nothing is happening */
  125.     return(time_to_act);
  126.     }
  127.  
  128. while (GetMessage(&msg, NULL, NULL, NULL)) {
  129.  
  130.     if (!TranslateAccelerator(hwnd, hAccTable, &msg)) {
  131.         TranslateMessage(&msg);
  132.         DispatchMessage(&msg);
  133.         }
  134.  
  135.     CheckMathTools();
  136.     if (!bTrack) {          /* don't do this if mouse-button is down */
  137.     time_to_act = time_to_reinit+time_to_restart+time_to_quit+
  138.         time_to_load+time_to_save+time_to_print+time_to_cycle;
  139.     if (dont_wait_for_a_key || time_to_act)
  140.         return(time_to_act);
  141.     }
  142.  
  143.     }
  144.  
  145. if (!dont_wait_for_a_key)
  146.     time_to_quit = 1;
  147.  
  148.     /* bail out if nothing is happening */
  149.     time_to_act = time_to_reinit+time_to_restart+time_to_quit+
  150.     time_to_load+time_to_save+time_to_print+time_to_cycle;
  151.     return(time_to_act);
  152.  
  153. }
  154.  
  155. /****************************************************************************
  156.  
  157.     FUNCTION: putcolor(int x, int y, int color), getcolor(int x, int y)
  158.  
  159.     PURPOSE:
  160.     putcolor:
  161.        sets the "color" value of the pixel at location x,y
  162.        (actually, a palette value)
  163.     getcolor:
  164.        returns the "color" value of the pixel at location x,y
  165.        (actually, a palette value)
  166.  
  167. ****************************************************************************/
  168.  
  169. extern int debug_fastupdate;
  170.  
  171. time_t last_time;
  172. time_t update_time;
  173. long minimum_update;
  174. long pixelsout;
  175. int top_changed, bottom_changed;
  176.  
  177. /* Made global, MCP 6-16-91 */
  178. unsigned char win_andmask[8];
  179. unsigned char win_notmask[8];
  180. unsigned char win_bitshift[8];
  181.  
  182. void putcolor(int x, int y, int color)
  183. {
  184. RECT tempRect;             /* temporary rectangle structure */
  185. long i;
  186. int temp_top_changed, temp_bottom_changed;
  187. time_t this_time;
  188.  
  189. last_written_y = y;
  190. if (y < top_changed) top_changed = y;
  191. if (y > bottom_changed) bottom_changed = y;
  192.  
  193. i = win_ydots-1-y;
  194. i = (i * win_xdots) + x;
  195.  
  196. if (x >= 0 && x < xdots && y >= 0 && y < ydots) {
  197.     if (pixelshift_per_byte == 0) {
  198.       pixels[i] = color % colors;
  199.       }
  200.      else {
  201.       unsigned int j;
  202.       j = i & pixels_per_bytem1;
  203.       i = i >> pixelshift_per_byte;
  204.       pixels[i] = (pixels[i] & win_notmask[j]) +
  205.           (((unsigned char)(color % colors)) << win_bitshift[j]);
  206.       }
  207.  
  208.      /* check the time every nnn pixels */
  209.      if (debug_fastupdate || ++pixelsout > 100) {
  210.       pixelsout = 0;
  211.       this_time = time(NULL);
  212.       /* time to update the screen? */
  213.       if (debug_fastupdate || (this_time - last_time) > update_time ||
  214.           (minimum_update*(this_time-last_time)) > (bottom_changed-top_changed)) {
  215.           temp_top_changed = top_changed - win_yoffset;
  216.           temp_bottom_changed = bottom_changed - win_yoffset;
  217.           if (!(temp_top_changed >= ypagesize || temp_bottom_changed < 0)) {
  218.           if (temp_top_changed < 0) temp_top_changed = 0;
  219.           if (temp_bottom_changed < 0) temp_bottom_changed = 0;
  220.           tempRect.top = temp_top_changed;
  221.           tempRect.bottom = temp_bottom_changed+1;
  222.           tempRect.left = 0;
  223.           tempRect.right = xdots;
  224.           InvalidateRect(hwnd, &tempRect, FALSE);
  225.           keypressed();    /* force a look-see at the screen */
  226.           }
  227.           last_time = this_time;
  228.           top_changed = win_ydots;
  229.           bottom_changed = 0;
  230.           }
  231.       }
  232.      }
  233.  
  234. }
  235.  
  236. int getcolor(int x, int y)
  237. {
  238. long i;
  239.  
  240. i = win_ydots-1-y;
  241. i = (i * win_xdots) + x;
  242.  
  243. if (x >= 0 && x < xdots && y >= 0 && y < ydots) {
  244.     if (pixelshift_per_byte == 0) {
  245.       return(pixels[i]);
  246.       }
  247.      else {
  248.       unsigned int j;
  249.       j = i & pixels_per_bytem1;
  250.       i = i >> pixelshift_per_byte;
  251.       return((int)((pixels[i] & win_andmask[j]) >> win_bitshift[j]));
  252.       }
  253.      }
  254. else
  255.      return(0);
  256. }
  257.  
  258. int put_line(int rownum, int leftpt, int rightpt, unsigned char *localvalues)
  259. {
  260. int i, len;
  261. long startloc;
  262.  
  263. len = rightpt - leftpt;
  264. if (rightpt >= xdots) len = xdots - 1 - leftpt;
  265. startloc = win_ydots-1-rownum;
  266. startloc = (startloc * win_xdots) + leftpt;
  267.  
  268. if (rownum < 0 || rownum >= ydots || leftpt < 0) {
  269.     return(0);
  270.     }
  271.  
  272. if (pixelshift_per_byte == 0) {
  273.     for (i = 0; i <= len; i++)
  274.     pixels[startloc+i] = localvalues[i];
  275.     }
  276. else {
  277.     unsigned int j;
  278.     long k;
  279.     for (i = 0; i <= len; i++) {
  280.     k = startloc + i;
  281.     j = k & pixels_per_bytem1;
  282.     k = k >> pixelshift_per_byte;
  283.     pixels[k] = (pixels[k] & win_notmask[j]) +
  284.         (((unsigned char)(localvalues[i] % colors)) << win_bitshift[j]);
  285.     }
  286.     }
  287. pixelsout += len;
  288. putcolor(leftpt, rownum, localvalues[0]);
  289. }
  290.  
  291. int get_line(int rownum, int leftpt, int rightpt, unsigned char *localvalues)
  292. {
  293. int i, len;
  294. long startloc;
  295.  
  296. len = rightpt - leftpt;
  297. if (rightpt >= xdots) len = xdots - 1 - leftpt;
  298. startloc = win_ydots-1-rownum;
  299. startloc = (startloc * win_xdots) + leftpt;
  300.  
  301. if (rownum < 0 || rownum >= ydots || leftpt < 0 || rightpt >= xdots) {
  302.     for (i = 0; i <= len; i++)
  303.     localvalues[i] = 0;
  304.     return(0);
  305.     }
  306.  
  307. if (pixelshift_per_byte == 0) {
  308.     for (i = 0; i <= len; i++)
  309.     localvalues[i] = pixels[startloc+i];
  310.     }
  311. else {
  312.     unsigned int j;
  313.     long k;
  314.     for (i = 0; i <= len; i++) {
  315.     k = startloc + i;
  316.     j = k & pixels_per_bytem1;
  317.     k = k >> pixelshift_per_byte;
  318.     localvalues[i] = (pixels[k] & win_andmask[j]) >> win_bitshift[j];
  319.     }
  320.     }
  321. }
  322.  
  323. extern int rowcount;
  324.  
  325. int out_line(unsigned char *localvalues, int numberofdots)
  326. {
  327.     put_line(rowcount++, 0, numberofdots, localvalues);
  328. }
  329.  
  330. extern LPBITMAPINFO pDibInfo;        /* pointer to the DIB info */
  331.  
  332. int clear_screen(int forceclear)
  333. {
  334. long numdots;
  335. int i;
  336.  
  337. win_xdots = (xdots+3) & 0xfffc;
  338. win_ydots = ydots;
  339. pixelshift_per_byte = 0;
  340. pixels_per_byte   = 1;
  341. pixels_per_bytem1 = 0;
  342. if (colors == 16) {
  343.     win_xdots = (xdots+7) & 0xfff8;
  344.     pixelshift_per_byte = 1;
  345.     pixels_per_byte = 2;
  346.     pixels_per_bytem1 = 1;
  347.     win_andmask[0] = 0xf0;  win_notmask[0] = 0x0f; win_bitshift[0] = 4;
  348.     win_andmask[1] = 0x0f;  win_notmask[1] = 0xf0; win_bitshift[1] = 0;
  349.     }
  350. if (colors == 2) {
  351.     win_xdots = (xdots+31) & 0xffe0;
  352.     pixelshift_per_byte = 3;
  353.     pixels_per_byte = 8;
  354.     pixels_per_bytem1 = 7;
  355.     win_andmask[0] = 0x80;  win_notmask[0] = 0x7f; win_bitshift[0] = 7;
  356.     for (i = 1; i < 8; i++) {
  357.     win_andmask[i] = win_andmask[i-1] >> 1;
  358.     win_notmask[i] = (win_notmask[i-1] >> 1) + 0x80;
  359.     win_bitshift[i] = win_bitshift[i-1] - 1;
  360.     }
  361.     }
  362.  
  363. numdots = (long)win_xdots * (long) win_ydots;
  364. update_time = 2;
  365. if (numdots > 200000L) update_time = 4;
  366. if (numdots > 400000L) update_time = 8;
  367. last_time = time(NULL) - update_time + 1;
  368. minimum_update = 7500/xdots;    /* assume 75,000 dots/sec drawing speed */
  369.  
  370. last_written_y = -1;
  371. pixelsout = 0;
  372. top_changed = win_ydots;
  373. bottom_changed = 0;
  374.  
  375. bytes_per_pixelline = win_xdots >> pixelshift_per_byte;
  376.  
  377. /* Create the Device-independent Bitmap entries */
  378. pDibInfo->bmiHeader.biWidth  = win_xdots;
  379. pDibInfo->bmiHeader.biHeight = win_ydots;
  380. pDibInfo->bmiHeader.biSizeImage = (DWORD)bytes_per_pixelline * win_ydots;
  381. pDibInfo->bmiHeader.biBitCount = 8 / pixels_per_byte;
  382.  
  383. /* hard to believe, but this is the fast way to clear the pixel map */
  384. if (hpixels) {
  385.      GlobalUnlock(hpixels);
  386.      GlobalFree(hpixels);
  387.      }
  388.  
  389. win_bitmapsize = (numdots >> pixelshift_per_byte)+1;
  390.  
  391. if (!(hpixels = GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, win_bitmapsize)))
  392.      return(0);
  393. if (!(pixels = (char huge *)GlobalLock(hpixels))) {
  394.      GlobalFree(hpixels);
  395.      return(0);
  396.      }
  397.  
  398. /* adjust the colors for B&W or default */
  399. if (colors == 2) {
  400.     dacbox[0][0] = dacbox[0][1] = dacbox[0][2] = 0;
  401.     dacbox[1][0] = dacbox[1][1] = dacbox[1][2] = 63;
  402.     spindac(0,1);
  403.     }
  404. else
  405.     restoredac();   /* color palette */
  406.  
  407. screen_to_be_cleared = 1;
  408. InvalidateRect(hwnd, NULL, TRUE);
  409.  
  410. if (forceclear)
  411.     keypressed();        /* force a look-see at the screen */
  412.  
  413. return(1);
  414. }
  415.  
  416. int flush_screen()
  417. {
  418.  
  419. last_written_y = 0;
  420.  
  421. InvalidateRect(hwnd, NULL, FALSE);
  422.  
  423. }
  424.  
  425. /****************************************************************************
  426.  
  427.     FUNCTION: buzzer(int buzzertype)
  428.  
  429.     PURPOSE:
  430.           make some sort of sound (hey, we do what we can)
  431.  
  432. ****************************************************************************/
  433.  
  434. void buzzer(int i)
  435. {
  436.  
  437. MessageBeep(0);
  438.  
  439. }
  440.  
  441. /****************************************************************************
  442.  
  443.     FUNCTION: unsigned char far * farmemalloc(long bytecount)
  444.           void farmemfree(unsigned char * bytepointer)
  445.     PURPOSE:
  446.           allocate and free memory in a manner consistent with
  447.           Fractint for DOS
  448.  
  449. ****************************************************************************/
  450.  
  451. #define MAXFARMEMALLOCS  50        /* max active farmemallocs */
  452. int   farmemallocinit = 0;        /* any memory been allocated yet?   */
  453. HANDLE farmemallochandles[MAXFARMEMALLOCS];            /* handles  */
  454. void far *farmemallocpointers[MAXFARMEMALLOCS]; /* pointers */
  455.  
  456. void far * farmemalloc(long bytecount)
  457. {
  458. int i;
  459. HANDLE temphandle;
  460. unsigned char far *temppointer;
  461.  
  462. if (!farmemallocinit) {     /* never been here yet - initialize */
  463.     farmemallocinit = 1;
  464.     for (i = 0; i < MAXFARMEMALLOCS; i++) {
  465.     farmemallochandles[i] = (HANDLE)0;
  466.     farmemallocpointers[i] = NULL;
  467.     }
  468.     }
  469.  
  470. for (i = 0; i < MAXFARMEMALLOCS; i++)  /* look for a free handle */
  471.     if (farmemallochandles[i] == (HANDLE)0) break;
  472.  
  473. if (i == MAXFARMEMALLOCS)    /* uh-oh - no more handles */
  474.    return(NULL);        /* can't get far memory this way */
  475.  
  476. if (!(temphandle = GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, bytecount)))
  477.      return(NULL);        /* can't allocate the memory */
  478. if (!(temppointer = (unsigned char far *)GlobalLock(temphandle))) {
  479.      GlobalFree(temphandle);
  480.      return(NULL);        /* ?? can't lock the memory ?? */
  481.      }
  482.  
  483. farmemallochandles[i] =  temphandle;
  484. farmemallocpointers[i] = temppointer;
  485. return(temppointer);
  486. }
  487.  
  488. void farmemfree(void far *bytepointer)
  489. {
  490. int i;
  491.  
  492. if (bytepointer == (void far *)NULL) return;
  493.  
  494. for (i = 0; i < MAXFARMEMALLOCS; i++)    /* search for a matching pointer */
  495.     if (farmemallocpointers[i] == bytepointer)
  496.      break;
  497. if (i < MAXFARMEMALLOCS) {        /* got one */
  498.     GlobalUnlock(farmemallochandles[i]);
  499.     GlobalFree(farmemallochandles[i]);
  500.     farmemallochandles[i] = (HANDLE)0;
  501.     }
  502.  
  503. }
  504.  
  505. debugmessage(char *msg1, char *msg2)
  506. {
  507. MessageBox (
  508.     GetFocus(),
  509.     msg2,
  510.     msg1,
  511.     MB_ICONASTERISK | MB_OK);
  512.  
  513. }
  514.  
  515. texttempmsg(char *msg1)
  516. {
  517. MessageBox (
  518.     GetFocus(),
  519.     msg1,
  520.     "Encoder",
  521.     MB_ICONASTERISK | MB_OK);
  522. }
  523.  
  524. stopmsg(int flags, unsigned char far *msg1)
  525. {
  526. int result;
  527.  
  528. if (! (flags & 4)) MessageBeep(0);
  529.  
  530. result = IDOK;
  531.  
  532. if (!(flags & 2))
  533.     MessageBox (
  534.     NULL,
  535.     msg1,
  536.     "Fractint for Windows",
  537.     MB_TASKMODAL | MB_ICONASTERISK | MB_OK);
  538. else
  539.     result = MessageBox (
  540.     NULL,
  541.     msg1,
  542.     "Fractint for Windows",
  543.     MB_TASKMODAL | MB_ICONQUESTION | MB_OKCANCEL);
  544.  
  545. if (result == 0 || result == IDOK || result == IDYES)
  546.     return(0);
  547. else
  548.     return(-1);
  549. }
  550.  
  551. extern char readname[];
  552. extern int fileydots, filexdots, filecolors;
  553. extern int     iNumColors;    /* Number of colors supported by device           */
  554. extern int     iRasterCaps;   /* Raster capabilities                   */
  555.  
  556. win_load()
  557. {
  558. int i;
  559.  
  560. time_to_load = 0;
  561.  
  562.     start_wait();
  563.     if ((i = read_overlay()) >= 0 && (!win_display3d ||
  564.     xdots < filexdots || ydots < fileydots)) {
  565.     if (win_display3d) stopmsg(0,
  566.         "3D and Overlay3D file image sizes must be\nat least as large as the display image.\nAltering your display image to match the file.");
  567.     xdots = filexdots;
  568.     ydots = fileydots;
  569.     colors = filecolors;
  570.     if (colors > 16) colors = 256;
  571.     if (colors >  2 && colors < 16) colors = 16;
  572.     if (xdots < 50) xdots = 50;
  573.     if (xdots > 2048) xdots = 2048;
  574.     if (ydots < 50) ydots = 50;
  575.     if (ydots > 2048) ydots = 2048;
  576.     set_win_offset();
  577.     clear_screen(0);
  578.     }
  579.     end_wait();
  580.     return(i);
  581. }
  582.  
  583. win_save()
  584. {
  585.     time_to_save = 0;
  586.     save_system = 1;
  587.     save_release = win_release;
  588.  
  589.     /* MCP 10-27-91 */
  590.     if(FileFormat != ID_BMP)
  591.        savetodisk(readname);
  592.     else
  593.        SaveBitmapFile(hwnd, FullPathName);
  594.     CloseStatusBox();
  595. }
  596.  
  597.  
  598. /********************    Printer logic    *********************/
  599.  
  600. static struct PRINFO { /* dynamic alloc these to avoid eating static space */
  601.     HDC printerDC;        /* printer device context */
  602.     HANDLE hdm;         /* memory handle for next, NULL if none */
  603.     LPDEVMODE dm;        /* devmode block from printer */
  604.     BOOL b_print_abort;     /* abort flag from abort routine */
  605.     HWND h_pabort_dialog;    /* handle for abort window */
  606.     char drivername[41];
  607.     char devname[61];
  608.     char outname[41];
  609.     int cur_orient;        /* current options, saved if dialog ok'd */
  610.     int cur_maxflag;
  611.     float cur_width;
  612.     int width_ok;        /* FALSE if width currently in error */
  613.     float printer_xsize;    /* size of max print area in inches */
  614.     float printer_ysize;
  615.     int printer_xpix;        /* number of pixels across max print area */
  616.     int printer_ypix;
  617.     } far *pr;
  618.  
  619. static int pr_orient  = DMORIENT_LANDSCAPE; /* user selected orientation */
  620. static int pr_maxflag = 1;            /* user selected max size?     */
  621. static float pr_width = 0;            /* user selected width     */
  622.  
  623. static void create_printer_DC()
  624. {
  625.     HDC displayDC;
  626.     float daspect, paspect;
  627.     int printer_xdots, printer_ydots;
  628.     if (pr->printerDC) /* ditch the old one first if present */
  629.     DeleteDC(pr->printerDC);
  630.     if (!pr->dm) /* no DEVMODE, an old driver? */
  631.     pr->printerDC = CreateDC(pr->drivername, pr->devname, pr->outname, NULL);
  632.     else { /* got DEVMODE block so get fancy */
  633.     if ((pr->dm->dmFields & DM_ORIENTATION))
  634.         pr->dm->dmOrientation = pr->cur_orient;
  635.     if ((pr->dm->dmFields & DM_COLOR))
  636.         pr->dm->dmColor = DMCOLOR_COLOR;
  637.     pr->printerDC = CreateDC(pr->drivername, pr->devname, pr->outname, (LPSTR)pr->dm);
  638.     }
  639.     if (pr->printerDC) { /* calculate size of max area on printer */
  640.     displayDC = GetDC(NULL);
  641.     daspect = ((float)xdots / GetDeviceCaps(displayDC,LOGPIXELSX))
  642.         / ((float)ydots / GetDeviceCaps(displayDC,LOGPIXELSY));
  643.     ReleaseDC(NULL,displayDC);
  644.     printer_xdots = GetDeviceCaps(pr->printerDC,HORZRES);
  645.     printer_ydots = GetDeviceCaps(pr->printerDC,VERTRES);
  646.     paspect = ((float)printer_xdots / GetDeviceCaps(pr->printerDC,HORZSIZE))
  647.         / ((float)printer_ydots / GetDeviceCaps(pr->printerDC,VERTSIZE));
  648.     pr->printer_xpix = printer_xdots;
  649.     pr->printer_ypix = (float)printer_xdots / daspect / paspect;
  650.     if (pr->printer_ypix > printer_ydots) {
  651.         pr->printer_xpix = (float)pr->printer_xpix * (float) printer_ydots
  652.                  / (float)pr->printer_ypix;
  653.         if (pr->printer_xpix > printer_xdots)
  654.         pr->printer_xpix = printer_xdots;
  655.         pr->printer_ypix = printer_ydots;
  656.         }
  657.     pr->printer_xsize = (float)pr->printer_xpix
  658.               / GetDeviceCaps(pr->printerDC,LOGPIXELSX);
  659.     pr->printer_ysize = (float)pr->printer_ypix
  660.               / GetDeviceCaps(pr->printerDC,LOGPIXELSY);
  661.     }
  662. }
  663.  
  664. static void show_printsizes(HWND hDlg)
  665. {
  666.     HWND tmphwnd;
  667.     char buf[80];
  668.     sprintf(buf,"(%.2f x %.2f inches)",pr->printer_xsize,pr->printer_ysize);
  669.     SetDlgItemText(hDlg,ID_PRS_MAXSIZ,buf);
  670.     if (pr->cur_width == 0 || pr->cur_width > pr->printer_xsize)
  671.     pr->cur_width = pr->printer_xsize;
  672.     sprintf(buf,"%.2f",pr->cur_width);
  673.     SetDlgItemText(hDlg,ID_PRS_WIDTH,buf);
  674.     tmphwnd = GetDlgItem(hDlg,ID_PRS_WIDTH);
  675.     EnableWindow(tmphwnd,1 ^ pr->cur_maxflag); /* grey if max selected */
  676. }
  677.  
  678. BOOL FAR PASCAL PrintDlg(HWND hDlg, unsigned msg, WORD wParam, LONG lParam)
  679. {
  680.     int i;
  681.     HWND tmphwnd;
  682.     char buf[120];
  683.     float f;
  684.  
  685.     switch (msg) {
  686.  
  687.       case WM_INITDIALOG:
  688.     center_window(hDlg,0,0);
  689.     _fstrcpy((char far *)buf,pr->devname);
  690.     strcat(buf," on ");
  691.     _fstrcat((char far *)buf,pr->outname);
  692.     if (buf[i=strlen(buf)-1] == ':') buf[i] = 0;
  693.     SetDlgItemText(hDlg,ID_PR_DEVICE,buf);
  694.     if (!pr->dm || !(pr->dm->dmFields & DM_ORIENTATION)) {
  695.         i = 1; /* must use portrait */
  696.         tmphwnd = GetDlgItem(hDlg,ID_PRO_LANDS);
  697.         EnableWindow(tmphwnd,0);
  698.         }
  699.     else
  700.         i = (pr->cur_orient == DMORIENT_LANDSCAPE) ? 0 : 1;
  701.     CheckDlgButton(hDlg, ID_PRO_PORTR, i);
  702.     CheckDlgButton(hDlg, ID_PRO_LANDS, i ^ 1);
  703.     CheckDlgButton(hDlg, ID_PRS_MAX,  pr->cur_maxflag);
  704.     CheckDlgButton(hDlg, ID_PRS_CUST, pr->cur_maxflag ^ 1);
  705.     show_printsizes(hDlg); /* show the rest */
  706.     break;
  707.  
  708.       case WM_COMMAND:
  709.     switch (wParam) {
  710.       case IDOK:
  711.         if (pr->cur_maxflag == 0 && !pr->width_ok) {
  712.         MessageBeep(0);
  713.         SetFocus(GetDlgItem(hDlg, ID_PRS_WIDTH));
  714.         break;
  715.         }
  716.         EndDialog(hDlg, 1);
  717.         break;
  718.       case IDCANCEL:
  719.         EndDialog(hDlg, 0);
  720.         break;
  721.       case ID_PRO_PORTR:
  722.       case ID_PRO_LANDS:
  723.         pr->cur_orient = (wParam == ID_PRO_PORTR)
  724.                ? DMORIENT_PORTRAIT : DMORIENT_LANDSCAPE;
  725.         if (pr->cur_width == pr->printer_xsize)
  726.         pr->cur_width = 0; /* force reset to match new size */
  727.         create_printer_DC();   /* new device context for new orient */
  728.         show_printsizes(hDlg); /* display new orientation sizes */
  729.         break;
  730.       case ID_PRS_MAX:
  731.       case ID_PRS_CUST:
  732.         pr->cur_maxflag = (wParam == ID_PRS_MAX) ? 1 : 0;
  733.         show_printsizes(hDlg); /* to set width field grey status */
  734.         break;
  735.       case ID_PRS_WIDTH:
  736.         switch(HIWORD(lParam)) {
  737.           case EN_KILLFOCUS:
  738.         GetDlgItemText(hDlg, ID_PRS_WIDTH, buf, 20);
  739.         i = strlen(buf);
  740.         while (i > 0 && buf[i] == ' ') --i;
  741.         buf[i] = 0;
  742.         if (sscanf(buf,"%f%c",&f) == 1 /* got a float */
  743.           && f <= pr->printer_xsize) { /* not greater than max */
  744.             pr->cur_width = f;
  745.             pr->width_ok = TRUE;
  746.             show_printsizes(hDlg); /* redisplay, formatted */
  747.             }
  748.         else /* entry invalid */
  749.             pr->width_ok = FALSE;
  750.         break;
  751.           default:
  752.         return FALSE;
  753.           }
  754.         break;
  755.       default:
  756.         return FALSE;
  757.       }
  758.     break;
  759.  
  760.       case WM_KEYDOWN:
  761.     switch (wParam) {
  762.       case VK_F1:
  763.         /* F1, shifted F1 bring up the Help Index */
  764.         WinHelp(hwnd,szHelpFileName,HELP_INDEX,0L);
  765.         break;
  766.       default:
  767.         return FALSE;
  768.       }
  769.     break;
  770.  
  771.       default:
  772.     return FALSE;
  773.  
  774.       }
  775.     return TRUE;
  776. }
  777.  
  778. int FAR PASCAL PrintAbortDlg(HWND hWnd, unsigned msg, WORD wParam, LONG lParam)
  779. {
  780.     if (msg == WM_COMMAND) { /* Cancel button (Enter, Esc, Return, Space) */
  781.     pr->b_print_abort = TRUE;
  782.     DestroyWindow(hWnd);
  783.     return (TRUE);
  784.     }
  785.     if (msg == WM_INITDIALOG) {
  786.     center_window(hWnd,0,0);
  787.     SetFocus(hWnd);
  788.     return (TRUE);
  789.     }
  790.     return (FALSE);
  791. }
  792.  
  793. int FAR PASCAL PrintAbort(HDC hPr, int Code)
  794. {
  795.     MSG msg;
  796.     while (PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE))
  797.     if (!IsDialogMessage(pr->h_pabort_dialog, &msg)) {
  798.         TranslateMessage(&msg);
  799.         DispatchMessage(&msg);
  800.         }
  801.     return (!pr->b_print_abort); /* return FALSE iff aborted */
  802. }
  803.  
  804. void win_print()
  805. {
  806.     HANDLE hpr;
  807.     int Return;
  808.     int printer_bandable;
  809.     long firstpixel;
  810.     RECT printerRect;
  811.     int more;
  812.     FARPROC lpPrintDlg;
  813.     FARPROC p_print_abort;
  814.     FARPROC p_pabort_dialog;
  815.     int printer_xacross, printer_yacross;
  816.  
  817.     time_to_print = 0;
  818.     hpr = GlobalAlloc(GMEM_FIXED, sizeof(struct PRINFO));
  819.     pr    = (struct PRINFO FAR *)GlobalLock(hpr);
  820.     pr->printerDC = NULL;
  821.     pr->hdm = NULL;
  822.     pr->cur_orient  = pr_orient;
  823.     pr->cur_maxflag = pr_maxflag;
  824.     pr->cur_width   = pr_width;
  825.     pr->width_ok = TRUE;
  826.  
  827.     { /* find the default printer */
  828.     char szPrinter[80];
  829.     char *szDevice, *szDriver, *szOutput;
  830.     int dmsize;
  831.     dmsize = 0;
  832.     GetProfileString ("windows", "device", "", szPrinter, sizeof(szPrinter));
  833.     if ( (szDevice = strtok (szPrinter, "," ))
  834.       && (szDriver = strtok (NULL,    ", "))
  835.       && (szOutput = strtok (NULL,    ", "))) {
  836.     char drivname[40];
  837.     HANDLE hDriver;
  838.     int (FAR PASCAL *p_ExtDeviceMode)(HWND,HANDLE,DEVMODE FAR *,LPSTR,LPSTR,DEVMODE FAR *,LPSTR,WORD);
  839.     _fstrncpy(pr->drivername,(char far *)szDriver,40);
  840.     _fstrncpy(pr->devname,     (char far *)szDevice,60);
  841.     _fstrncpy(pr->outname,     (char far *)szOutput,40);
  842.     pr->drivername[40] = 0;
  843.     pr->devname   [60] = 0;
  844.     pr->outname   [40] = 0;
  845.     strcpy(drivname,szDriver); strcat(drivname,".drv");
  846.     if ((hDriver = LoadLibrary(drivname)) >= 32) { /* else driver not found */
  847.         if ((p_ExtDeviceMode = GetProcAddress(hDriver,"ExtDeviceMode"))
  848.           && (dmsize = (*p_ExtDeviceMode)(NULL,hDriver,NULL,szDevice,szOutput,NULL,NULL,0)) > 0) {
  849.         /* load DEVMODE block */
  850.         pr->hdm = GlobalAlloc(GMEM_FIXED, dmsize);
  851.         pr->dm    = (DEVMODE FAR *)GlobalLock(pr->hdm);
  852.         (*p_ExtDeviceMode)(NULL,hDriver,pr->dm,szDevice,szOutput,NULL,NULL,DM_COPY);
  853.         }
  854.         FreeLibrary(hDriver);
  855.         }
  856.     create_printer_DC();
  857.     }
  858.     if (!pr->printerDC) {
  859.     stopmsg(0,"Can't find the printer!");
  860.     goto win_print_exit;
  861.     }
  862.     }
  863.  
  864.     /* get user options */
  865.     lpPrintDlg = MakeProcInstance((FARPROC) PrintDlg, hInst);
  866.     Return = DialogBox(hInst, "Printoptions", hwnd, lpPrintDlg);
  867.     FreeProcInstance(lpPrintDlg);
  868.     if (Return == 0) /* cancelled */
  869.     goto win_print_exit;
  870.     pr_orient  = pr->cur_orient;    /* not cancelled, remember options */
  871.     pr_maxflag = pr->cur_maxflag;
  872.     pr_width   = pr->cur_width;
  873.  
  874.     start_wait();
  875.  
  876.     printer_bandable =    GetDeviceCaps(pr->printerDC,RASTERCAPS) & RC_BANDING;
  877. /*
  878.     printer_bandable = 0;
  879. */
  880.  
  881.     /* calc print position & size, set up colors */
  882.     firstpixel = win_ydots - ydots;
  883.     firstpixel = firstpixel * bytes_per_pixelline;
  884.     printer_xacross = pr->printer_xpix;
  885.     printer_yacross = pr->printer_ypix;
  886.     if (pr->cur_maxflag == 0 && pr->cur_width != pr->printer_xsize) {
  887.     float f;
  888.     f = pr->cur_width / pr->printer_xsize;
  889.     printer_xacross = f * printer_xacross;
  890.     printer_yacross = f * printer_yacross;
  891.     }
  892.     if (GetDeviceCaps(pr->printerDC,NUMCOLORS) <= 2)
  893.     mono_dib_palette();    /* B&W stripes for B&W printers */
  894.     else
  895.     rgb_dib_palette();
  896.  
  897.     /* set up abort logic */
  898.     pr->b_print_abort = FALSE;
  899.     p_print_abort  = MakeProcInstance(PrintAbort,    hInst);
  900.     p_pabort_dialog = MakeProcInstance(PrintAbortDlg, hInst);
  901.     pr->h_pabort_dialog = CreateDialog(hInst, "Printabort", hwnd, p_pabort_dialog);
  902.     ShowWindow(pr->h_pabort_dialog, SW_NORMAL);
  903.     UpdateWindow(pr->h_pabort_dialog);
  904.     EnableWindow(hwnd, FALSE);
  905.     Return = Escape (pr->printerDC, SETABORTPROC, 0, (LPSTR)p_print_abort, NULL);
  906.     if (Return <= 0 || pr->b_print_abort) goto oops;
  907.  
  908.     /* print */
  909.     Return = Escape (pr->printerDC, STARTDOC, 17, (LPSTR)"Fractint Printout", NULL);
  910.     if (Return <= 0 || pr->b_print_abort) goto oops;
  911.     if (printer_bandable) {
  912.     Return = Escape(pr->printerDC, NEXTBAND, 0, (LPSTR) NULL, (LPSTR) &printerRect);
  913.     if (Return <= 0 || pr->b_print_abort) goto oops;
  914.     }
  915.     more = 1;
  916.     while (more) {
  917.     if (printer_bandable)
  918.         DPtoLP(pr->printerDC, (LPPOINT) &printerRect, 2);
  919.     Return = StretchDIBits(pr->printerDC,
  920.         0, 0,
  921.         printer_xacross, printer_yacross,
  922.         0, 0,
  923.         xdots, ydots,
  924.         (LPSTR)&pixels[firstpixel], (LPBITMAPINFO)pDibInfo,
  925.         DIB_RGB_COLORS, SRCCOPY);
  926.     if (Return <= 0 || pr->b_print_abort) goto oops;
  927.     more = 0;
  928.     if (printer_bandable) {
  929.         Return = Escape(pr->printerDC, NEXTBAND, 0, (LPSTR) NULL, (LPSTR) &printerRect);
  930.         if (Return <= 0 || pr->b_print_abort) goto oops;
  931.         more = ! (IsRectEmpty(&printerRect));
  932.         }
  933.     }
  934.     Return = Escape(pr->printerDC, NEWFRAME, 0, NULL, NULL);
  935.     if (Return <= 0 || pr->b_print_abort) goto oops;
  936.     Return = Escape(pr->printerDC, ENDDOC, 0, NULL, NULL);
  937.  
  938. oops:
  939.     EnableWindow(hwnd, TRUE);
  940.     DestroyWindow(pr->h_pabort_dialog);
  941.     FreeProcInstance(p_print_abort);
  942.     FreeProcInstance(p_pabort_dialog);
  943.     default_dib_palette();   /* replace the palette */
  944.     end_wait();
  945.     if (!pr->b_print_abort) {
  946.     if (Return < 0 && (Return & SP_NOTREPORTED))
  947.         stopmsg(0,"Print failed\nYou probably ran out of memory\nSorry...");
  948.     if (Return == 0)
  949.         stopmsg(0,"Printer driver doesn't have a function we need\nSorry...");
  950.     }
  951.  
  952. win_print_exit: /* cleanup */
  953.     if (pr->printerDC)
  954.     DeleteDC(pr->printerDC);
  955.     if (pr->hdm) {
  956.     GlobalUnlock(pr->hdm); /* DEVMODE */
  957.     GlobalFree(pr->hdm);
  958.     }
  959.     GlobalUnlock(hpr); /* general vars */
  960.     GlobalFree(hpr);
  961.  
  962. }
  963.  
  964. /*
  965.     Delay code - still not so good for a multi-tasking environment, 
  966.     but what the hell...
  967. */
  968.  
  969. DWORD DelayCount;
  970.  
  971. DWORD DelayMillisecond(void)
  972. {
  973.    DWORD i;
  974.  
  975.    i = 0;
  976.    while(i != DelayCount)
  977.       i++;
  978.    return(i);
  979. }
  980.  
  981. void delay(DWORD milliseconds)
  982. {
  983.    DWORD n;
  984.  
  985.    for(n = 0; n < milliseconds; n++)
  986.       DelayMillisecond();
  987. }
  988.  
  989. void CalibrateDelay(void)
  990. {
  991.    DWORD Now, Time, Delta, TimeAdj;
  992.  
  993.    DelayCount = 128;
  994.  
  995.    /* Determine the Windows timer resolution.  It's usually 38ms in
  996.       version 3.0, but that may change latter. */
  997.    Now = Time = GetCurrentTime();
  998.    while(Time == Now)
  999.       Now = GetCurrentTime();
  1000.  
  1001.    /* Logrithmic Adjust */
  1002.    Delta = Now - Time;
  1003.    Time = Now;
  1004.    while(Time == Now)
  1005.    {
  1006.       delay(Delta);
  1007.       Now = GetCurrentTime();
  1008.       if(Time == Now)
  1009.       {
  1010.          /* Resynch */
  1011.          Time = Now = GetCurrentTime();
  1012.          while(Time == Now)
  1013.             Now = GetCurrentTime();
  1014.          Time = Now;
  1015.          DelayCount <<= 1;
  1016.       }
  1017.    }
  1018.  
  1019.    /* Linear Adjust */
  1020.    Time = Now;
  1021.    TimeAdj = (DelayCount - (DelayCount >> 1)) >> 1;
  1022.    DelayCount -= TimeAdj;
  1023.    while(TimeAdj > 16)
  1024.    {
  1025.       delay(Delta);
  1026.       TimeAdj >>= 1;
  1027.       if(GetCurrentTime() == Now)
  1028.          DelayCount += TimeAdj;
  1029.       else
  1030.          DelayCount -= TimeAdj;
  1031.  
  1032.       /* Resynch */
  1033.       Time = Now = GetCurrentTime();
  1034.       while(Time == Now)
  1035.          Now = GetCurrentTime();
  1036.       Time = Now;
  1037.    }
  1038. }
  1039.  
  1040. /*
  1041.     Color-cycling logic
  1042.     includes variable-delay capabilities
  1043. */
  1044.  
  1045. extern int win_cycledir, win_cyclerand, win_cyclefreq, win_cycledelay;
  1046.  
  1047. extern HANDLE  hPal;       /* Palette Handle */
  1048. extern LPLOGPALETTE pLogPal;  /* pointer to the application's logical palette */
  1049. extern unsigned char far win_dacbox[256][3];
  1050. #define PALETTESIZE 256           /* dull-normal VGA            */
  1051.  
  1052. static int win_fsteps[] = {54, 24, 8};
  1053.  
  1054. int win_animate_flag = 0;
  1055. int win_syscolorindex[21];
  1056. DWORD win_syscolorold[21];
  1057. DWORD win_syscolornew[21];
  1058.  
  1059. extern int debugflag;
  1060.  
  1061. win_cycle()
  1062. {
  1063. int istep, jstep, fstep, step, oldstep, last, next, maxreg;
  1064. int incr, fromred, fromblue, fromgreen, tored, toblue, togreen;
  1065. HDC hDC;              /* handle to device context        */
  1066.  
  1067. fstep = 1;                /* randomization frequency    */
  1068. oldstep = 1;                /* single-step            */
  1069. step = 256;                /* single-step            */
  1070. incr = 999;                /* ready to randomize        */
  1071. maxreg = 256;                /* maximum register to rotate    */
  1072. last = maxreg-1;            /* last box that was filled    */
  1073. next = 1;                /* next box to be filled    */
  1074. if (win_cycledir < 0) {
  1075.     last = 1;
  1076.     next = maxreg;
  1077.     }
  1078. srand((unsigned)time(NULL));        /* randomize things        */
  1079.  
  1080. hDC = GetDC(GetFocus());
  1081.  
  1082. win_animate_flag = 1;
  1083. SetPaletteEntries(hPal, 0, pLogPal->palNumEntries, pLogPal->palPalEntry);
  1084. SelectPalette (hDC, hPal, 1);
  1085.  
  1086. if ((iNumColors == 16 || debugflag == 1000) && !win_systempaletteused) {
  1087.     int i;
  1088.     DWORD white, black;
  1089.     win_systempaletteused = TRUE;
  1090.     white = 0xffffff00;
  1091.     black = 0;
  1092.     for (i = 0; i <= COLOR_ENDCOLORS; i++) {
  1093.     win_syscolorindex[i] = i;
  1094.     win_syscolorold[i] = GetSysColor(i);
  1095.     win_syscolornew[i] = black;
  1096.     }
  1097.     win_syscolornew[COLOR_BTNTEXT] = white;
  1098.     win_syscolornew[COLOR_CAPTIONTEXT] = white;
  1099.     win_syscolornew[COLOR_GRAYTEXT] = white;
  1100.     win_syscolornew[COLOR_HIGHLIGHTTEXT] = white;
  1101.     win_syscolornew[COLOR_MENUTEXT] = white;
  1102.     win_syscolornew[COLOR_WINDOWTEXT] = white;
  1103.     win_syscolornew[COLOR_WINDOWFRAME] = white;
  1104.     win_syscolornew[COLOR_INACTIVECAPTION] = white;
  1105.     win_syscolornew[COLOR_INACTIVEBORDER] = white;
  1106.     SetSysColors(COLOR_ENDCOLORS,(LPINT)win_syscolorindex,(LONG FAR *)win_syscolornew);
  1107.     SetSystemPaletteUse(hDC,SYSPAL_NOSTATIC);
  1108.     UnrealizeObject(hPal);
  1109.     }
  1110.  
  1111. while (time_to_cycle) {
  1112.     if (win_cyclerand) {
  1113.     for (istep = 0; istep < step; istep++) {
  1114.         jstep = next + (istep * win_cycledir);
  1115.         if (jstep <=      0) jstep += maxreg-1;
  1116.         if (jstep >= maxreg) jstep -= maxreg-1;
  1117.         if (++incr > fstep) {    /* time to randomize    */
  1118.         incr = 1;
  1119.         fstep = ((win_fsteps[win_cyclefreq]*
  1120.             (rand() >> 8)) >> 6) + 1;
  1121.         fromred   = dacbox[last][0];
  1122.         fromgreen = dacbox[last][1];
  1123.         fromblue  = dacbox[last][2];
  1124.         tored      = rand() >> 9;
  1125.         togreen   = rand() >> 9;
  1126.         toblue      = rand() >> 9;
  1127.         }
  1128.         dacbox[jstep][0] = fromred     + (((tored   - fromred  )*incr)/fstep);
  1129.         dacbox[jstep][1] = fromgreen + (((togreen - fromgreen)*incr)/fstep);
  1130.         dacbox[jstep][2] = fromblue  + (((toblue  - fromblue )*incr)/fstep);
  1131.         }
  1132.     }
  1133.     if (step >= 256) step = oldstep;
  1134.  
  1135.     spindac(win_cycledir,step);
  1136.     delay(win_cycledelay);
  1137.     AnimatePalette(hPal, 0, pLogPal->palNumEntries, pLogPal->palPalEntry);
  1138.     RealizePalette(hDC);
  1139.     keypressed();
  1140.     if (win_cyclerand == 2) {
  1141.     win_cyclerand = 1;
  1142.     step = 256;
  1143.     }
  1144.     }
  1145.  
  1146. win_animate_flag = 0;
  1147. ReleaseDC(GetFocus(),hDC);
  1148.  
  1149. }
  1150.  
  1151. /* cursor routines */
  1152.  
  1153. extern HANDLE hSaveCursor;           /* the original cursor value */
  1154. extern HANDLE hHourGlass;           /* the hourglass cursor value */
  1155.  
  1156. start_wait()
  1157. {
  1158.    hSaveCursor = SetClassWord(hwnd, GCW_HCURSOR, hHourGlass);
  1159. }
  1160.  
  1161. end_wait()
  1162. {
  1163.    SetClassWord(hwnd, GCW_HCURSOR, hSaveCursor);
  1164. }
  1165.  
  1166. /* video-mode routines */
  1167.  
  1168. extern int    viewwindow;        /* 0 for full screen, 1 for window */
  1169. extern float  viewreduction;        /* window auto-sizing */
  1170. extern float  finalaspectratio;     /* for view shape and rotation */
  1171. extern int    viewxdots,viewydots;    /* explicit view sizing */
  1172. extern int    fileydots, filexdots, filecolors;
  1173. extern float  fileaspectratio;
  1174. extern int    skipxdots,skipydots;    /* for decoder, when reducing image */
  1175.  
  1176. int get_video_mode(struct fractal_info *info)
  1177. {
  1178.    viewwindow = viewxdots = viewydots = 0;
  1179.    fileaspectratio = .75;
  1180.    skipxdots = skipydots = 0;
  1181.    return(0);
  1182. }
  1183.  
  1184.  
  1185. void spindac(int direction, int step)
  1186. {
  1187. int i, j, k;
  1188.  
  1189. for (k = 0; k < step; k++) {
  1190.     if (direction > 0) {
  1191.     for (j = 0; j < 3; j++) {
  1192.         for (i = 255; i >= 1; i--)
  1193.         dacbox[i+1][j] = dacbox[i][j];
  1194.         dacbox[1][j] = dacbox[256][j];
  1195.         }
  1196.     }
  1197.     if (direction < 0) {
  1198.     for (j = 0; j < 3; j++) {
  1199.         dacbox[256][j] = dacbox[1][j];
  1200.         for (i = 1; i < 256; i++)
  1201.         dacbox[i][j] = dacbox[i+1][j];
  1202.         }
  1203.     }
  1204.     }
  1205.  
  1206.     /* fill in intensities for all palette entry colors */
  1207.     for (i = 0; i < 256; i++) {
  1208.     pLogPal->palPalEntry[i].peRed    = ((BYTE)dacbox[i][0]) << 2;
  1209.     pLogPal->palPalEntry[i].peGreen = ((BYTE)dacbox[i][1]) << 2;
  1210.     pLogPal->palPalEntry[i].peBlue    = ((BYTE)dacbox[i][2]) << 2;
  1211.     pLogPal->palPalEntry[i].peFlags = PC_RESERVED;
  1212.     }
  1213.  
  1214.     if (!win_animate_flag) {
  1215.     HDC hDC;
  1216.     hDC = GetDC(GetFocus());
  1217.     SetPaletteEntries(hPal, 0, pLogPal->palNumEntries, pLogPal->palPalEntry);
  1218.     SelectPalette (hDC, hPal, 1);
  1219.     RealizePalette(hDC);
  1220.     ReleaseDC(GetFocus(),hDC);
  1221.         /* for non-palette-based adapters, redraw the image */
  1222.     if (!iRasterCaps)
  1223.             InvalidateRect(hwnd, NULL, FALSE);
  1224.     }
  1225. }
  1226.  
  1227. restoredac()
  1228. {
  1229. int iLoop;
  1230. int j;
  1231.  
  1232.     /* fill in intensities for all palette entry colors */
  1233.     for (iLoop = 0; iLoop < PALETTESIZE; iLoop++)
  1234.     for (j = 0; j < 3; j++)
  1235.         dacbox[iLoop][j] = win_dacbox[iLoop][j];
  1236.     spindac(0,1);
  1237. }
  1238.  
  1239. int ValidateLuts( char * fn )
  1240. {
  1241. FILE * f;
  1242. unsigned    r, g, b, index;
  1243. unsigned char    line[101];
  1244. unsigned char    temp[81];
  1245.     strcpy (temp,fn);
  1246.     if (strchr(temp,'.') == NULL) /* Did name have an extension? */
  1247.         strcat(temp,".map");  /* No? Then add .map */
  1248.     findpath( temp, line);          /* search the dos path */
  1249.     f = fopen( line, "r" );
  1250.     if (f == NULL)
  1251.         return 1;
  1252.     for( index = 0; index < 256; index++ ) {
  1253.         if (fgets(line,100,f) == NULL)
  1254.             break;
  1255.         sscanf( line, "%d %d %d", &r, &g, &b );
  1256.         /** load global dac values **/
  1257.         dacbox[index][0] = r >> 2;    /* maps default to 8 bits */
  1258.         dacbox[index][1] = g >> 2;    /* DAC wants 6 bits */
  1259.         dacbox[index][2] = b >> 2;
  1260.     }
  1261.     fclose( f );
  1262.     return 0;
  1263. }
  1264.  
  1265. int win_thinking = 0;
  1266.  
  1267. int thinking(int waiting, char *dummy)
  1268. {
  1269. if (waiting && ! win_thinking) {
  1270.     win_thinking = 1;
  1271.     start_wait();
  1272.     }
  1273. if (!waiting)
  1274.     end_wait();
  1275. return(keypressed());
  1276. }
  1277.  
  1278. int far_strlen(char far *string) {
  1279. int i;
  1280. for (i = 0; ; i++)
  1281.     if (string[i] == 0)
  1282.     return(i);
  1283. }
  1284.  
  1285. int far_strnicmp(char far *string1, char far *string2, int maxlen) {
  1286. int i;
  1287. unsigned char j, k;
  1288. for (i = 0;i < maxlen ; i++) {
  1289.     j = string1[i];
  1290.     k = string2[i];
  1291.     if (j >= 'a' && j <= 'z') j -= ('a' - 'A');
  1292.     if (k >= 'a' && k <= 'z') k -= ('a' - 'A');
  1293.     if (j-k != 0)
  1294.     return(j-k);
  1295.     }
  1296. return(0);
  1297. }
  1298.  
  1299. int far_memcpy(void far *string1, void far *string2, int maxlen) {
  1300. int i;
  1301. for (i = 0;i < maxlen ; i++)
  1302.     ((char far *)string1)[i] = ((char far *)string2)[i];
  1303. }
  1304.  
  1305. /* fake/not-yet-implemented subroutines */
  1306.  
  1307. int getakeynohelp() {return(getakey());}
  1308.  
  1309. void farmessage(unsigned char far *foo) {}
  1310. void setvideomode(int foo1, int foo2, int foo3, int foo4) {}
  1311. int fromvideotable() {}
  1312. int setforgraphics() {}
  1313. int setfortext() {}
  1314. int movecursor() {}
  1315. int home() {}
  1316.  
  1317. int intro_overlay() {}
  1318. int help_overlay() {}
  1319. int prompts_overlay() {}
  1320. int rotate_overlay() {}
  1321. int printer_overlay() {}
  1322. int miscovl_overlay() {}
  1323. int pot_startdisk() {}
  1324. int SetTgaColors() {}
  1325. int startdisk() {}
  1326. int enddisk() {}
  1327. int readdisk() {}
  1328. int writedisk() {}
  1329. int nosnd(){}
  1330. int snd(){}
  1331. int targa_startdisk(){}
  1332. int targa_writedisk(){}
  1333. int SetColorPaletteName() {}
  1334. int get_3d_params() { return(0);}
  1335. int findfont() {return(0);}
  1336. int readticker(){return(0);}
  1337. int EndTGA(){}
  1338.  
  1339. int setattr(){}
  1340. int helptitle(){}
  1341. int stackscreen(){}
  1342. int unstackscreen(){}
  1343. void putstring(int foo1, int foo2, int foo3, unsigned char far *foo4){}
  1344. int putstringcenter(int foo1, int foo2, int foo3, int foo4, char far *foo5){}
  1345. int dvid_status(){}
  1346. int goodbye(){}
  1347. int tovideotable(){}
  1348.  
  1349. void load_mat(){}
  1350. void mult_vec_iit(){}
  1351. int check_vidmode_keyname(){return(0);}
  1352. void print_document(){}
  1353. void makedoc_msg_func(){}
  1354.  
  1355. void TranspPerPixel(){}
  1356.