home *** CD-ROM | disk | FTP | other *** search
/ Mega A/V / mega_av.zip / mega_av / GRAPHUTL / FRPOR172.ZIP / PRINTER.C < prev    next >
C/C++ Source or Header  |  1992-03-14  |  36KB  |  1,127 lines

  1. /*  Printer.c
  2.  *    This module is linked as an overlay, use ENTER_OVLY and EXIT_OVLY.
  3.  *    Simple screen printing functions for FRACTINT
  4.  *    By Matt Saucier CIS: [72371,3101]      7/2/89
  5.  *    "True-to-the-spirit" of FRACTINT, this code makes few checks that you
  6.  *    have specified a valid resolution for the printer (just in case yours
  7.  *    has more dots/line than the Standard HP and IBM/EPSON,
  8.  *    (eg, Wide Carriage, etc.))
  9.  *
  10.  *    PostScript support by Scott Taylor [72401,410] / (DGWM18A)   10/8/90
  11.  *    For PostScript, use 'printer=PostScript/resolution' where resolution
  12.  *    is ANY NUMBER between 10 and 600. Common values: 300,150,100,75.
  13.  *    Default resolution for PostScript is 150 pixels/inch.
  14.  *    At 200 DPI, a fractal that is 640x480 prints as a 3.2"x2.4" picture.
  15.  *    PostScript printer names:
  16.  *
  17.  *    PostScript/PS            = Portrait printing
  18.  *    PostScriptH/PostScriptL/PSH/PSL = Landscape printing
  19.  *
  20.  *    This code supports printers attached to a LPTx (1-3) parallel port.
  21.  *    It also now supports serial printers AFTER THEY ARE CONFIGURED AND
  22.  *    WORKING WITH THE DOS MODE COMMAND, eg. MODE COM1:9600,n,8,1 (for HP)
  23.  *    (NOW you can also configure the serial port with the comport= command)
  24.  *    Printing calls are made directly to the BIOS for DOS can't handle fast
  25.  *    transfer of data to the HP.  (Or maybe visa-versa, HP can't handle the
  26.  *    slow transfer of data from DOS)
  27.  *
  28.  *    I just added direct port access for COM1 and COM2 **ONLY**. This method
  29.  *    does a little more testing than BIOS, and may work (especially on
  30.  *    serial printer sharing devices) where the old method doesn't. I noticed
  31.  *    maybe a 5% speed increase at 9600 baud. These are selected in the
  32.  *    printer=.../.../31 for COM1 or 32 for COM2.
  33.  *
  34.  *    I also added direct parallel port access for LPT1 and LPT2 **ONLY**.
  35.  *    This toggles the "INIT" line of the parallel port to reset the printer
  36.  *    for each print session. It will also WAIT for a error / out of paper /
  37.  *    not selected condition instead of quitting with an error.
  38.  *
  39.  *    Supported Printers:    Tested Ok:
  40.  *     HP LaserJet
  41.  *        LJ+,LJII         MDS
  42.  *     Toshiba PageLaser     MDS (Set FRACTINT to use HP)
  43.  *     IBM Graphics         MDS
  44.  *     EPSON
  45.  *        Models?         Untested.
  46.  *     IBM LaserPrinter
  47.  *        with PostScript     SWT
  48.  *     HP Plotter         SWT
  49.  *
  50.  *    Future support to include OKI 20 (color) printer, and just about
  51.  *    any printer you request.
  52.  *
  53.  *    Future modifications to include a more flexible, standard interface
  54.  *    with the surrounding program, for easier portability to other
  55.  *    programs.
  56.  *
  57.  * PostScript Styles:
  58.  *  0  Dot
  59.  *  1  Dot*           [Smoother]
  60.  *  2  Inverted Dot
  61.  *  3  Ring
  62.  *  4  Inverted Ring
  63.  *  5  Triangle        [45-45-90]
  64.  *  6  Triangle*       [30-75-75]
  65.  *  7  Grid
  66.  *  8  Diamond
  67.  *  9  Line
  68.  * 10  Microwaves
  69.  * 11  Ellipse
  70.  * 12  RoundBox
  71.  * 13  Custom
  72.  * 14  Star
  73.  * 15  Random
  74.  * 16  Line*           [Not much different]
  75.  *
  76.  *  *  Alternate style
  77.  */
  78.  
  79. #include <stdlib.h>
  80.  
  81. #ifndef XFRACT
  82. #include <bios.h>
  83. #include <dos.h>
  84. #include <io.h>
  85. #endif
  86.  
  87. #include <fcntl.h>
  88. #include <sys/types.h>
  89. #include <errno.h>
  90. #include <stdio.h>    /*** for vsprintf prototype ***/
  91.  
  92. #ifndef XFRACT
  93. #include <conio.h>
  94. #include <stdarg.h>
  95. #else
  96. #include <varargs.h>
  97. #endif
  98.  
  99. #include <string.h>
  100. #include <float.h>    /* for pow() */
  101. #include <math.h>    /*  "    "   */
  102. #include "fractint.h"
  103. #include "fractype.h"
  104.  
  105. /********      PROTOTYPES     ********/
  106.  
  107.        void printer_overlay(void);
  108.        void Print_Screen(void);
  109. #ifndef XFRACT
  110. static void Printer_printf(char *fmt,...);
  111. #else
  112. static void Printer_printf();
  113. #endif
  114. static int  _fastcall printer(int c);
  115. static void _fastcall print_title(int,int,char *);
  116. static void printer_reset();
  117.  
  118. extern int keypressed (void);
  119. extern void updatesavename (char *);
  120. extern void showtrig (char *);
  121.  
  122. /********  EXTRN GLOBAL VARS  ********/
  123.  
  124. extern int xdots,ydots,            /* size of screen           */
  125.        extraseg,               /* used for buffering           */
  126.        fractype;               /* used for title block           */
  127. extern BYTE dacbox[256][3];   /* for PostScript printing       */
  128. extern BYTE dstack[2][3][400];
  129. extern char FormName[];            /* for Title block info           */
  130. extern char LName[];               /* for Title block info           */
  131. extern char IFSName[];               /* for Title block info           */
  132. extern char PrintName[];           /* Filename for print-to-file       */
  133. extern float finalaspectratio;
  134. extern double xxmin,xxmax,xx3rd,
  135.           yymin,yymax,yy3rd,param[4]; /* for Title block info       */
  136. extern int colors;
  137. extern int dotmode;
  138. extern unsigned int debugflag;
  139.  
  140. extern unsigned int  far pj_patterns[];
  141. extern BYTE far pj_reds[];
  142. extern BYTE far pj_blues[];
  143. extern BYTE far pj_greens[];
  144.  
  145. extern int thinking(int,char *);
  146.  
  147. /********    GLOBALS       ********/
  148.  
  149. int Printer_Resolution,        /* 75,100,150,300 for HP;           */
  150.                    /* 60,120,240 for IBM;               */
  151.                    /* 90 or 180 for the PaintJet;           */
  152.                    /* 10-600 for PS                */
  153.                    /* 1-20 for Plotter               */
  154.     LPTNumber,               /* ==1,2,3 LPTx; or 11,12,13,14 for COM1-4  */
  155.                    /* 21,22 for direct port access for LPT1-2  */
  156.                    /* 31,32 for direct port access for COM1-2  */
  157.     Printer_Type,               /* ==1 HP,
  158.                       ==2 IBM/EPSON,
  159.                       ==3 Epson color,
  160.                       ==4 HP PaintJet,
  161.                       ==5,6 PostScript,
  162.                       ==7 HP Plotter           */
  163.     Printer_Titleblock,       /* Print info about the fractal?           */
  164.     Printer_ColorXlat,          /* PostScript only - invert colors       */
  165.     Printer_SetScreen,          /* PostScript only - reprogram halftone ?    */
  166.     Printer_SFrequency,       /* PostScript only - Halftone Frequency K    */
  167.     Printer_SAngle,           /* PostScript only - Halftone angle     K    */
  168.     Printer_SStyle,           /* PostScript only - Halftone style     K    */
  169.     Printer_RFrequency,       /* PostScript only - Halftone Frequency R    */
  170.     Printer_RAngle,           /* PostScript only - Halftone angle     R    */
  171.     Printer_RStyle,           /* PostScript only - Halftone style     R    */
  172.     Printer_GFrequency,       /* PostScript only - Halftone Frequency G    */
  173.     Printer_GAngle,           /* PostScript only - Halftone angle     G    */
  174.     Printer_GStyle,           /* PostScript only - Halftone style     G    */
  175.     Printer_BFrequency,       /* PostScript only - Halftone Frequency B    */
  176.     Printer_BAngle,           /* PostScript only - Halftone angle     B    */
  177.     Printer_BStyle,           /* PostScript only - Halftone style     B    */
  178.     Print_To_File,          /* Print to file toggle               */
  179.     EPSFileType,          /* EPSFileType -
  180.                            1 = well-behaved,
  181.                            2 = much less behaved,
  182.                            3 = not well behaved       */
  183.     Printer_CRLF,             /* (0) CRLF (1) CR (2) LF                    */
  184.     ColorPS;                  /* (0) B&W  (1) Color                        */
  185.  
  186. static int LPTn;           /* printer number we're gonna use */
  187.  
  188. static FILE *PRFILE;
  189.  
  190. #define TONES 17           /* Number of PostScript halftone styles */
  191.  
  192. static char *HalfTone[TONES]=  {
  193.              "dup mul exch dup mul add 1 exch sub",
  194.              "abs exch abs 2 copy add 1 gt {1 sub dup mul exch 1 sub dup mul add 1 sub} {dup mul exch dup mul add 1 exch sub} ifelse",
  195.              "dup mul exch dup mul add 1 sub",
  196.              "dup mul exch dup mul add 0.6 exch sub abs -0.5 mul",
  197.              "dup mul exch dup mul add 0.6 exch sub abs 0.5 mul",
  198.              "add 2 div",
  199.              "2 exch sub exch abs 2 mul sub 3 div",
  200.              "2 copy abs exch abs gt {exch} if pop 2 mul 1 exch sub 3.5 div",
  201.              "abs exch abs add 1 exch sub",
  202.              "pop",
  203.              "/wy exch def 180 mul cos 2 div wy dup dup dup mul mul sub mul wy add 180 mul cos",
  204.              "dup 5 mul 8 div mul exch dup mul exch add sqrt 1 exch sub",
  205.              "dup mul dup mul exch dup mul dup mul add 1 exch sub",
  206.              "dup mul exch dup mul add sqrt 1 exch sub",
  207.              "abs exch abs 2 copy gt {exch} if 1 sub dup 0 eq {0.01 add} if atan 360 div",
  208.              "pop pop rand 1 add 10240 mod 5120 div 1 exch sub",
  209.              "pop abs 2 mul 1 exch sub"
  210.             };
  211.  
  212. void printer_overlay() { }    /* for restore_active_ovly */
  213.  
  214. #ifdef __BORLANDC__
  215. #if(__BORLANDC__ > 2)
  216.    #pragma warn -eff
  217. #endif
  218. #endif
  219.  
  220. void Print_Screen()
  221. {
  222.     int y,j;
  223.     char buff[192];        /* buffer for 192 sets of pixels  */
  224.                 /* This is very large so that we can*/
  225.                 /* get reasonable times printing  */
  226.                 /* from modes like 2048x2048 disk-*/
  227.                 /* video.  When this was 24, a 2048*/
  228.                 /* by 2048 pic took over 2 hours to*/
  229.                 /* print.  It takes about 15 min now*/
  230.     int BuffSiz;        /* how much of buff[] we'll use   */
  231.     char far *es;        /* pointer to extraseg for buffer */
  232.     int i,x,k,            /* more indices           */
  233.     imax,            /* maximum i value (ydots/8)      */
  234.     res,            /* resolution we're gonna' use    */
  235.     high,            /* if LPTn>10 COM == com port to use*/
  236.     low,            /* misc               */
  237.                 /************************************/
  238.     ptrid;            /* Printer Id code.          */
  239.                 /* Currently, the following are   */
  240.                 /* assigned:              */
  241.                 /*          1. HPLJ (all)      */
  242.                 /*         Toshiba PageLaser*/
  243.                 /*          2. IBM Graphics      */
  244.                 /*          3. Color Printer      */
  245.                 /*          4. HP PaintJet      */
  246.                 /*          5. PostScript      */
  247.                 /************************************/
  248.     double ci,ck;
  249.     int pj_width;
  250.     int pj_color_ptr[256];    /* Paintjet color translation */
  251.     char EndOfLine[3];
  252.  
  253.     ENTER_OVLY(OVLY_PRINTER);
  254.                 /********   SETUP VARIABLES  ********/
  255.     memset(buff,0,192);
  256.  
  257.     EndOfLine[0]=(((Printer_CRLF==1) || (Printer_CRLF==0)) ? 0x0D : 0x0A);
  258.     EndOfLine[1]=((Printer_CRLF==0) ? 0x0A : 0x00);
  259.     EndOfLine[2]=0x00;
  260.  
  261.     if (Print_To_File>0)
  262.       {
  263.       while ((PRFILE = fopen(PrintName,"r"))) {
  264.      j = fgetc(PRFILE);
  265.      fclose(PRFILE);
  266.      if (j == EOF) break;
  267.      updatesavename((char *)PrintName);
  268.      }
  269.       if ((PRFILE = fopen(PrintName,"wb"))==NULL) Print_To_File = 0;
  270.       }
  271.  
  272.     es=MK_FP(extraseg,0);
  273.  
  274.     LPTn=LPTNumber-1;
  275.     if (((LPTn>2)&&(LPTn<10))||
  276.     ((LPTn>13)&&(LPTn<20))||
  277.     ((LPTn>21)&&(LPTn<30))||
  278.     (LPTn<0)||(LPTn>31)) LPTn=0;   /* default of LPT1 (==0)      */
  279.     ptrid=Printer_Type;
  280.     if ((ptrid<1)||(ptrid>7)) ptrid=2; /* default of IBM/EPSON         */
  281.     res=Printer_Resolution;
  282. #ifndef XFRACT
  283.     if ((LPTn==20)||(LPTn==21))
  284.     {
  285.     k = (inp((LPTn==20) ? 0x37A : 0x27A)) & 0xF7;
  286.     outp((LPTn==20) ? 0x37A : 0x27A,k);
  287.     k = k & 0xFB;
  288.     outp((LPTn==20) ? 0x37A : 0x27A,k);
  289.     k = k | 0x0C;
  290.     outp((LPTn==20) ? 0x37A : 0x27A,k);
  291.     }
  292.     if ((LPTn==30)||(LPTn==31))
  293.     {
  294.     outp((LPTn==30) ? 0x3F9 : 0x2F9,0x00);
  295.     outp((LPTn==30) ? 0x3FC : 0x2FC,0x00);
  296.     outp((LPTn==30) ? 0x3FC : 0x2FC,0x03);
  297.     }
  298. #endif
  299.  
  300.     switch (ptrid) {
  301.  
  302.     case 1:
  303.         if (res<75) res=75;
  304.         if ( (res<= 75)&&(ydots> 600)) res=100;
  305.         if ( (res<=100)&&(ydots> 800)) res=150;
  306.         if (((res<=150)&&(ydots>1200))||(res>300)) res=300;
  307.         break;
  308.  
  309.     case 2:
  310.     case 3:
  311.         if (res<60) res=60;
  312.         if ((res<=60)&&(ydots>480)) res=120;
  313.         if (((res<=120)&&(ydots>960))||(res>240)) res=240;
  314.         break;
  315.  
  316.     case 4: /****** PaintJet  *****/
  317.         {
  318. #ifndef XFRACT
  319.         /* Pieter Branderhorst:
  320.            My apologies if the numbers and approach here seem to be
  321.            picked out of a hat.  They were.  They happen to result in
  322.            a tolerable mapping of screen colors to printer colors on
  323.            my machine.  There are two sources of error in getting colors
  324.            to come out right.
  325.            1) Must match some dacbox values to the 330 PaintJet dithered
  326.           colors so that they look the same.  For this we use HP's
  327.           color values in printera.asm and modify by gamma separately
  328.           for each of red/green/blue.  This mapping is ok if the
  329.           preview shown on screen is a fairly close match to what
  330.           gets printed. The defaults are what work for me.
  331.            2) Must find nearest color in HP palette to each color in
  332.           current image. For this we use Lee Crocker's least sum of
  333.           differences squared approach, modified to spread the
  334.           values using gamma 1.7.  This mods was arrived at by
  335.           trial and error, just because it improves the mapping.
  336.            */
  337.         long ldist;
  338.         int r,g,b;
  339.         double gamma,gammadiv;
  340.         BYTE convert[256];
  341.         BYTE scale[64];
  342.  
  343.         BYTE far *table_ptr;
  344.         res = (res < 150) ? 90 : 180;   /* 90 or 180 dpi */
  345.         if (Printer_SetScreen == 0) {
  346.         Printer_SFrequency = 21;  /* default red gamma */
  347.         Printer_SAngle       = 19;  /*       green gamma */
  348.         Printer_SStyle       = 16;  /*        blue gamma */
  349.         }
  350.         /* Convert the values in printera.asm.  We might do this just   */
  351.         /* once per run, but we'd need separate memory for that - can't */
  352.         /* just convert table in-place cause it could be in an overlay, */
  353.         /* might be paged out and then back in in original form.  Also, */
  354.         /* user might change gammas with a .par file entry mid-run.     */
  355.         for (j = 0; j < 3; ++j) {
  356.         switch (j) {
  357.             case 0: table_ptr = pj_reds;
  358.                 i = Printer_SFrequency;
  359.                 break;
  360.             case 1: table_ptr = pj_greens;
  361.                 i = Printer_SAngle;
  362.                 break;
  363.             case 2: table_ptr = pj_blues;
  364.                 i = Printer_SStyle;
  365.             }
  366.         gamma = 10.0 / i;
  367.         gammadiv = pow(255,gamma) / 255;
  368.         for (i = 0; i < 256; ++i) { /* build gamma conversion table */
  369.             if ((i & 15) == 15)
  370.             thinking(1,"Calculating color translation");
  371.             convert[i] = (int)((pow((double)i,gamma) / gammadiv) + 0.5);
  372.             }
  373.         for (i = 0; i < 330; ++i) {
  374.             k = convert[table_ptr[i]];
  375.             if (k > 252) k = 252;
  376.             dstack[0][j][i] = (k + 2) >> 2;
  377.         }
  378.         }
  379.         /* build comparison lookup table */
  380.         gamma = 1.7;
  381.         gammadiv = pow(63,gamma) / 63;
  382.         for (i = 0; i < 64; ++i) {
  383.            if ((j = (int)((pow((double)i,gamma) / gammadiv) * 4 + 0.5)) < i)
  384.           j = i;
  385.            scale[i] = j;
  386.         }
  387.         for (i = 0; i < 3; ++i) /* convert values via lookup */
  388.         for (j = 0; j < 330; ++j)
  389.             dstack[1][i][j] = scale[dstack[0][i][j]];
  390.         /* Following code and the later code which writes to Paintjet    */
  391.         /* using pj_patterns was adapted from Lee Crocker's PGIF program */
  392.         for (i = 0; i < colors; ++i) { /* find nearest match colors */
  393.         r = scale[dacbox[i][0]];
  394.         g = scale[dacbox[i][1]];
  395.         b = scale[dacbox[i][2]];
  396.         ldist = 9999999;
  397.         /* check variance vs each PaintJet color */
  398.         /* if high-res 8 color mode, consider only 1st 8 colors */
  399.         j = (res == 90) ? 330 : 8;
  400.         while (--j >= 0) {
  401.             long dist;
  402.             dist  = (unsigned)(r-dstack[1][0][j]) * (r-dstack[1][0][j]);
  403.             dist += (unsigned)(g-dstack[1][1][j]) * (g-dstack[1][1][j]);
  404.             dist += (unsigned)(b-dstack[1][2][j]) * (b-dstack[1][2][j]);
  405.             if (dist < ldist) {
  406.             ldist = dist;
  407.             k = j;
  408.             }
  409.         }
  410.         pj_color_ptr[i] = k; /* remember best fit */
  411.         }
  412.         thinking(0,NULL);
  413.     /*  if (debugflag == 900 || debugflag == 902) {
  414.         color_test();
  415.         EXIT_OVLY;
  416.         return;
  417.         }  */
  418.         if (dotmode != 11) { /* preview */
  419.         memcpy(dstack[1],dacbox,768);
  420.         for (i = 0; i < colors; ++i)
  421.             for (j = 0; j < 3; ++j)
  422.             dacbox[i][j] = dstack[0][j][pj_color_ptr[i]];
  423.         spindac(0,1);
  424.         texttempmsg("Preview. Enter=go, Esc=cancel, k=keep");
  425.         i = getakeynohelp();
  426.         if (i == 'K' || i == 'k') {
  427.             EXIT_OVLY;
  428.             return;
  429.         }
  430.         memcpy(dacbox,dstack[1],768);
  431.         spindac(0,1);
  432.         if (i == 0x1B) {
  433.             EXIT_OVLY;
  434.             return;
  435.         }
  436.         }
  437.         break;
  438. #endif
  439.         }
  440.  
  441.     case 5:
  442.     case 6: /***** PostScript *****/
  443.         if ( res < 10 && res != 0 ) res = 10; /* PostScript scales... */
  444.         if ( res > 600 ) res = 600; /* it can handle any range! */
  445.         if ((Printer_SStyle < 0) || (Printer_SStyle >= TONES))
  446.         Printer_SStyle = 0;
  447.         break;
  448.     }
  449.  
  450.     /*****  Set up buffer size for immediate user gratification *****/
  451.     /*****    AKA, if we don't have to, don't buffer the data   *****/
  452.     BuffSiz=8;
  453.     if (xdots>1024) BuffSiz=192;
  454.  
  455.     /*****   Initialize printer  *****/
  456.     if (Print_To_File < 1) {
  457.     printer_reset();
  458.     /* wait a bit, some printers need time after reset */
  459.     delay((ptrid == 4) ? 2000 : 500);
  460.     }
  461.  
  462.     /******  INITIALIZE GRAPHICS MODES    ******/
  463.     switch (ptrid) {
  464.  
  465.     case 1:
  466.         print_title(ptrid,res,EndOfLine);
  467.         Printer_printf("\033*t%iR\033*r0A",res);/* HP           */
  468.         break;
  469.  
  470.     case 2:
  471.     case 3:
  472.         print_title(ptrid,res,EndOfLine);
  473.         Printer_printf("\033\063\030");/* IBM                   */
  474.         break;
  475.  
  476.     case 4: /****** PaintJet *****/
  477.         print_title(ptrid,res,EndOfLine);
  478.         pj_width = ydots;
  479.         if (res == 90) pj_width <<= 1;
  480.         Printer_printf("\033*r0B\033*t180R\033*r3U\033*r%dS\033*b0M\033*r0A",
  481.         pj_width);
  482.         pj_width >>= 3;
  483.         break;
  484.  
  485.     case 5:   /***** PostScript *****/
  486.     case 6:   /***** PostScript Landscape *****/
  487.         if (!((EPSFileType > 0) && (ptrid==5)))
  488.         Printer_printf("%%!PS-Adobe%s",EndOfLine);
  489.         if ((EPSFileType > 0) &&     /* Only needed if saving to .EPS */
  490.         (ptrid == 5))
  491.         {
  492.         Printer_printf("%%!PS-Adobe-1.0 EPSF-2.0%s",EndOfLine);
  493.  
  494.         if (EPSFileType==1)
  495.             i=xdots+78;
  496.         else
  497.             i=(int)((double)xdots * (72.0 / (double)res))+78;
  498.  
  499.         if (Printer_Titleblock==0)
  500.             {
  501.             if (EPSFileType==1) { j = ydots + 78; }
  502.             else { j = (int)(((double)ydots * (72.0 / (double)res) / (double)finalaspectratio)+78); }
  503.             }
  504.         else
  505.             {
  506.             if (EPSFileType==1) { j = ydots + 123; }
  507.             else { j = (int)(((double)ydots * (72.0 / (double)res))+123); }
  508.             }
  509.         Printer_printf("%%%%TemplateBox: 12 12 %d %d%s",i,j,EndOfLine);
  510.         Printer_printf("%%%%BoundingBox: 12 12 %d %d%s",i,j,EndOfLine);
  511.         Printer_printf("%%%%PrinterRect: 12 12 %d %d%s",i,j,EndOfLine);
  512.         Printer_printf("%%%%Creator: Fractint PostScript%s",EndOfLine);
  513.         Printer_printf("%%%%Title: A %s fractal - %s - Fractint EPSF Type %d%s",
  514.                        curfractalspecific->name[0]=='*' ?
  515.                        &curfractalspecific->name[1] :
  516.                        curfractalspecific->name,
  517.                        PrintName,
  518.                        EPSFileType,
  519.                        EndOfLine);
  520.         if (Printer_Titleblock==1)
  521.             Printer_printf("%%%%DocumentFonts: Helvetica%s",EndOfLine);
  522.         Printer_printf("%%%%EndComments%s",EndOfLine);
  523.         Printer_printf("/EPSFsave save def%s",EndOfLine);
  524.         Printer_printf("0 setgray 0 setlinecap 1 setlinewidth 0 setlinejoin%s",EndOfLine);
  525.         Printer_printf("10 setmiterlimit [] 0 setdash newpath%s",EndOfLine);
  526.         }
  527.  
  528.         /* Common code for all PostScript */
  529.         Printer_printf("/dopic { gsave %d %d 8 [%d 0 0 %d 0 %d]%s",
  530.                      xdots, ydots, xdots, -ydots, ydots,
  531.                      EndOfLine);
  532.         if (ColorPS)
  533.         Printer_printf("{ currentfile %d string readhexstring pop } false 3 colorimage grestore } def%s", xdots*3, EndOfLine);
  534.         else
  535.         Printer_printf("{ currentfile %d string readhexstring pop } image grestore } def%s", xdots, EndOfLine);
  536.  
  537.         if (Printer_Titleblock==1)
  538.         {
  539.         Printer_printf("/Helvetica findfont 12 scalefont setfont%s",EndOfLine);
  540.         if (ptrid==5) Printer_printf("30 60 moveto ");
  541.         else          Printer_printf("552 30 moveto 90 rotate ");
  542.         print_title(ptrid,res,EndOfLine);
  543.         }
  544.  
  545.         if (EPSFileType != 1) /* Do not use on a WELL BEHAVED .EPS */
  546.           {
  547.           if ((ptrid == 5)&&(EPSFileType==2)&&
  548.           ((Printer_ColorXlat!=0)||(Printer_SetScreen!=0)))
  549.             Printer_printf("%%%%BeginFeature%s",EndOfLine);
  550.           if (ColorPS)
  551.         {
  552.         if (Printer_ColorXlat==1)
  553.             Printer_printf("{1 exch sub} dup dup dup setcolortransfer%s",EndOfLine);
  554.         if (Printer_ColorXlat>1)
  555.             Printer_printf("{%d mul round %d div} dup dup dup setcolortransfer%s",
  556.                        Printer_ColorXlat,Printer_ColorXlat,EndOfLine);
  557.         if (Printer_ColorXlat<-1)
  558.             Printer_printf("{%d mul round %d div 1 exch sub} dup dup dup setcolortransfer",
  559.                        Printer_ColorXlat,Printer_ColorXlat,EndOfLine);
  560.  
  561.         if (Printer_SetScreen==1)
  562.             {
  563.             Printer_printf("%d %d {%s}%s",
  564.                        Printer_RFrequency,
  565.                        Printer_RAngle,
  566.                        HalfTone[Printer_RStyle],
  567.                        EndOfLine);
  568.             Printer_printf("%d %d {%s}%s",
  569.                        Printer_GFrequency,
  570.                        Printer_GAngle,
  571.                        HalfTone[Printer_GStyle],
  572.                        EndOfLine);
  573.             Printer_printf("%d %d {%s}%s",
  574.                        Printer_BFrequency,
  575.                        Printer_BAngle,
  576.                        HalfTone[Printer_BStyle],
  577.                        EndOfLine);
  578.             Printer_printf("%d %d {%s}%s",
  579.                        Printer_SFrequency,
  580.                        Printer_SAngle,
  581.                        HalfTone[Printer_SStyle],
  582.                        EndOfLine);
  583.             Printer_printf("setcolorscreen%s", EndOfLine);
  584.             }
  585.         }
  586.           else
  587.         {
  588.         if (Printer_ColorXlat==1)
  589.             Printer_printf("{1 exch sub} settransfer%s",EndOfLine);
  590.         if (Printer_ColorXlat>1)
  591.             Printer_printf("{%d mul round %d div} settransfer%s",
  592.                        Printer_ColorXlat,Printer_ColorXlat,EndOfLine);
  593.         if (Printer_ColorXlat<-1)
  594.             Printer_printf("{%d mul round %d div 1 exch sub} settransfer",
  595.                        Printer_ColorXlat,Printer_ColorXlat,EndOfLine);
  596.  
  597.         if (Printer_SetScreen==1)
  598.             Printer_printf("%d %d {%s} setscreen%s",
  599.                        Printer_SFrequency,
  600.                        Printer_SAngle,
  601.                        HalfTone[Printer_SStyle],
  602.                        EndOfLine);
  603.         }
  604.  
  605.           if (ptrid == 5)
  606.             {
  607.             if ((EPSFileType==2)&&((Printer_ColorXlat!=0)||(Printer_SetScreen!=0)))
  608.             Printer_printf("%%%%EndFeature%s",EndOfLine);
  609.             if (res == 0)
  610.             Printer_printf("30 191.5 translate 552 %4.1f",
  611.                     (552.0*(double)finalaspectratio));
  612.             else
  613.             Printer_printf("30 %d translate %f %f",
  614.                      75 - ((Printer_Titleblock==1) ? 0 : 45),
  615.                      ((double)xdots*(72.0/(double)res)),
  616.                      ((double)ydots*(72.0/(double)res)/(double)finalaspectratio));
  617.             }
  618.         else                 /* For Horizontal PostScript */
  619.             if (res == 0)
  620.             Printer_printf("582 30 translate 90 rotate 732 552");
  621.             else
  622.             Printer_printf("%d 30 translate 90 rotate %f %f",
  623.                      537 + ((Printer_Titleblock==1) ? 0 : 45),
  624.                      ((double)xdots*(72.0/(double)res)),
  625.                      ((double)ydots*(72.0/(double)res)/(double)finalaspectratio));
  626.         Printer_printf(" scale%s",EndOfLine);
  627.           }
  628.  
  629.         else if (ptrid == 5)       /* To be used on WELL-BEHAVED .EPS */
  630.         Printer_printf("30 %d translate %d %d scale%s",
  631.                     75 - ((Printer_Titleblock==1) ? 0 : 45),
  632.                     xdots,ydots,EndOfLine);
  633.  
  634.         Printer_printf("dopic%s",EndOfLine);
  635.         break;
  636.  
  637.     case 7: /* HP Plotter */
  638.         if (res<1) res=1;
  639.         if (res>10) res=10;
  640.         ci = (((double)xdots*((double)res-1.0))/2.0);
  641.         ck = (((double)ydots*((double)res-1.0))/2.0);
  642.         Printer_printf(";IN;SP0;SC%d,%d,%d,%d;%s\0",
  643.         (int)(-ci),(int)((double)xdots+ci),
  644.         (int)((double)ydots+ck),(int)(-ck),EndOfLine);
  645.         break;
  646.     }
  647.  
  648.     if (keypressed()) {     /* one last chance before we start...*/
  649.     EXIT_OVLY;
  650.     return;
  651.     }
  652.  
  653.     memset(buff,0,192);
  654.  
  655.                 /*****    Get And Print Screen **** */
  656.     switch (ptrid) {
  657.  
  658.     case 1:                /* HP LaserJet (et al)         */
  659.         imax=(ydots/8)-1;
  660.         for (x=0;((x<xdots)&&(!keypressed()));x+=BuffSiz) {
  661.         for (i=imax;((i>=0)&&(!keypressed()));i--) {
  662.             for (y=7;((y>=0)&&(!keypressed()));y--) {
  663.             for (j=0;j<BuffSiz;j++) {
  664.                 if ((x+j)<xdots) {
  665.                 buff[j]<<=1;
  666.                 buff[j]+=(getcolor(x+j,i*8+y)&1);
  667.                 }
  668.                 }
  669.             }
  670.             for (j=0;j<BuffSiz;j++) {
  671.             *(es+j+BuffSiz*i)=buff[j];
  672.             buff[j]=0;
  673.             }
  674.             }
  675.         for (j=0;((j<BuffSiz)&&(!keypressed()));j++) {
  676.             if ((x+j)<xdots) {
  677.             Printer_printf("\033*b%iW",imax+1);
  678.             for (i=imax;((i>=0)&&(!keypressed()));i--) {
  679.                 printer(*(es+j+BuffSiz*i));
  680.                 }
  681.             }
  682.             }
  683.         }
  684.         if (!keypressed()) Printer_printf("\033*rB\014");
  685.         break;
  686.  
  687.     case 2:                /* IBM Graphics/Epson         */
  688.         for (x=0;((x<xdots)&&(!keypressed()));x+=8) {
  689.         switch (res) {
  690.             case 60:  Printer_printf("\033K"); break;
  691.             case 120: Printer_printf("\033L"); break;
  692.             case 240: Printer_printf("\033Z"); break;
  693.             }
  694.         high=ydots/256;
  695.         low=ydots-(high*256);
  696.         printer(low);
  697.         printer(high);
  698.         for (y=ydots-1;(y>=0);y--) {
  699.             buff[0]=0;
  700.             for (i=0;i<8;i++) {
  701.             buff[0]<<=1;
  702.             buff[0]+=(getcolor(x+i,y)&1);
  703.             }
  704.             printer(buff[0]);
  705.             }
  706.         if (keypressed()) break;
  707.         Printer_printf(EndOfLine);
  708.         }
  709.         if (!keypressed()) printer(12);
  710.         break;
  711.  
  712.     case 3:                /* IBM Graphics/Epson Color    */
  713.         high=ydots/256;
  714.         low=ydots%256;
  715.         for (x=0;((x<xdots)&&(!keypressed()));x+=8)
  716.         {
  717.         for (k=0; k<8; k++)  /* colors */
  718.             {
  719.             Printer_printf("\033r%d",k); /* set printer color */
  720.             switch (res)
  721.             {
  722.             case 60:  Printer_printf("\033K"); break;
  723.             case 120: Printer_printf("\033L"); break;
  724.             case 240: Printer_printf("\033Z"); break;
  725.             }
  726.             printer(low);
  727.             printer(high);
  728.             for (y=ydots-1;y>=0;y--)
  729.             {
  730.             buff[0]=0;
  731.             for (i=0;i<8;i++)
  732.                 {
  733.                 buff[0]<<=1;
  734.                 if ((getcolor(x+i,y)%8)==k)
  735.                 buff[0]++;
  736.                 }
  737.             printer(buff[0]);
  738.             }
  739.             if (Printer_CRLF<2) printer(13);
  740.             }
  741.         if ((Printer_CRLF==0) || (Printer_CRLF==2)) printer(10);
  742.         }
  743.         printer(12);
  744.         printer(12);
  745.         printer_reset();
  746.         break;
  747.  
  748.     case 4:               /* HP PaintJet       */
  749. #ifndef XFRACT /* PaintJet needs pj_patterns, which is in assembly */
  750.         {
  751.         unsigned int fetchrows,fetched;
  752.         BYTE far *pixels, far *nextpixel;
  753.         /* for reasonable speed when using disk video, try to fetch
  754.            and store the info for 8 columns at a time instead of
  755.            doing getcolor calls down each column in separate passes */
  756.         fetchrows = 16;
  757.         while (1) {
  758.         if ((pixels = farmemalloc((long)(fetchrows)*ydots))) break;
  759.         if ((fetchrows >>= 1) == 0) {
  760.             static char far msg[]={"insufficient memory"};
  761.             stopmsg(0,msg);
  762.             break;
  763.         }
  764.         }
  765.         if (!pixels) break;
  766.         fetched = 0;
  767.         for (x = 0; (x < xdots && !keypressed()); ++x) {
  768.         if (fetched == 0) {
  769.             if ((fetched = xdots-x) > fetchrows)
  770.             fetched = fetchrows;
  771.             for (y = ydots-1; y >= 0; --y) {
  772.             if (debugflag == 602) /* flip image */
  773.                 nextpixel = pixels + y;
  774.             else              /* reverse order for unflipped */
  775.                 nextpixel = pixels + ydots-1 - y;
  776.             for (i = 0; i < fetched; ++i) {
  777.                 *nextpixel = getcolor(x+i,y);
  778.                 nextpixel += ydots;
  779.             }
  780.             }
  781.             nextpixel = pixels;
  782.         }
  783.         --fetched;
  784.         if (res == 180) { /* high-res 8 color mode */
  785.             int offset;
  786.             BYTE bitmask;
  787.             offset = -1;
  788.             bitmask = 0;
  789.             for (y = ydots - 1; y >= 0; --y) {
  790.             BYTE color;
  791.             if ((bitmask >>= 1) == 0) {
  792.                 ++offset;
  793.                 dstack[0][0][offset] = dstack[0][1][offset]
  794.                          = dstack[0][2][offset] = 0;
  795.                 bitmask = 0x80;
  796.             }
  797.             /* translate 01234567 to 70123456 */
  798.             color = pj_color_ptr[*(nextpixel++)] - 1;
  799.             if ((color & 1)) dstack[0][0][offset] += bitmask;
  800.             if ((color & 2)) dstack[0][1][offset] += bitmask;
  801.             if ((color & 4)) dstack[0][2][offset] += bitmask;
  802.             }
  803.         }
  804.         else { /* 90 dpi, build 2 lines, 2 dots per pixel */
  805.             int bitct,offset;
  806.             bitct = offset = 0;
  807.             for (y = ydots - 1; y >= 0; --y) {
  808.             unsigned int color;
  809.             color = pj_patterns[pj_color_ptr[*(nextpixel++)]];
  810.             for (i = 0; i < 3; ++i) {
  811.                 BYTE *bufptr;
  812.                 bufptr = &dstack[0][i][offset];
  813.                 *bufptr <<= 2;
  814.                 if ((color & 0x1000)) *bufptr += 2;
  815.                 if ((color & 0x0100)) ++*bufptr;
  816.                 bufptr = &dstack[1][i][offset];
  817.                 *bufptr <<= 2;
  818.                 if ((color & 0x0010)) *bufptr += 2;
  819.                 if ((color & 0x0001)) ++*bufptr;
  820.                 color >>= 1;
  821.             }
  822.             if (++bitct == 4) {
  823.                 bitct = 0;
  824.                 ++offset;
  825.             }
  826.             }
  827.         }
  828.         for (i = 0; i < ((res == 90) ? 2 : 1); ++i) {
  829.             for (j = 0; j < 3; ++j) {
  830.             BYTE *bufptr,*bufend;
  831.             Printer_printf((j < 2) ? "\033*b%dV" : "\033*b%dW",
  832.                        pj_width);
  833.             bufend = pj_width + (bufptr = dstack[i][j]);
  834.             do {
  835.                 while (printer(*bufptr)) { }
  836.             } while (++bufptr < bufend);
  837.             }
  838.         }
  839.         }
  840.         Printer_printf("\033*r0B"); /* end raster graphics */
  841.         if (!keypressed())
  842.            if (debugflag != 600)
  843.           printer(12); /* form feed */
  844.            else
  845.           Printer_printf("\n\n");
  846.         farmemfree(pixels);
  847.         break;
  848.         }
  849. #endif
  850.  
  851.     case 5:
  852.     case 6:     /***** PostScript Portrait & Landscape *****/
  853.         {
  854.         char convert[513];
  855.         if (!ColorPS)
  856.           for (i=0; i<256; ++i)
  857.         sprintf(&convert[2*i], "%02X",
  858.                   (int)((1.20 * (double)dacbox[i][0])+
  859.                     (2.36 * (double)dacbox[i][1])+
  860.                     (0.44 * (double)dacbox[i][2])));
  861.         i=0;
  862.         j=0;
  863.         for (y=0;((y<ydots)&&(!keypressed()));y++)
  864.         {
  865.         for (x=0;x<xdots;x++)
  866.         {
  867.             k=getcolor(x,y);
  868.             if (ColorPS)
  869.               {
  870.               sprintf(&buff[i], "%02X%02X%02X", dacbox[k][0]<<2,
  871.                             dacbox[k][1]<<2,
  872.                             dacbox[k][2]<<2);
  873.               i+=6;
  874.               }
  875.             else
  876.               {
  877.               k*=2;
  878.               buff[i++]=convert[k];
  879.               buff[i++]=convert[k+1];
  880.               }
  881.             if (i>=64)
  882.             {
  883.             strcpy(&buff[i],"  ");
  884.             Printer_printf("%s%s",buff,EndOfLine);
  885.             i=0;
  886.             j++;
  887.             if (j>9)
  888.             {
  889.                 j=0;
  890.                 Printer_printf(EndOfLine);
  891.             }
  892.             }
  893.         }
  894.         }
  895.         if ( (EPSFileType > 0) && (EPSFileType <3) )
  896.         Printer_printf("%s%%%%Trailer%sEPSFsave restore%s",EndOfLine,EndOfLine,EndOfLine);
  897.         else
  898.         Printer_printf("%sshowpage%s%c",EndOfLine,EndOfLine,4);
  899.         break;
  900.         }
  901.  
  902.     case 7: /* HP Plotter */
  903.         {
  904.         double parm1,parm2;
  905.         for (i=0;i<3;i++)
  906.         {
  907.           Printer_printf("%sSP %d;%s\0",EndOfLine,(i+1),EndOfLine);
  908.           for (y=0;(y<ydots)&&(!keypressed());y++)
  909.           {
  910.         for (x=0;x<xdots;x++)
  911.         {
  912.           j=dacbox[getcolor(x,y)][i];
  913.           if (j>0)
  914.           {
  915.             switch(Printer_SStyle)
  916.             {
  917.               case 0:
  918.             ci=0.004582144*(double)j;
  919.             ck=-.007936057*(double)j;
  920.             parm1 = (double)x+.5+ci+(((double)i-1.0)/3);
  921.             parm2 = (double)y+.5+ck;
  922.             break;
  923.               case 1:
  924.             ci=-.004582144*(double)j+(((double)i+1.0)/8.0);
  925.             ck=-.007936057*(double)j;
  926.             parm1 = (double)x+.5+ci;
  927.             parm2 = (double)y+.5+ck;
  928.             break;
  929.               case 2:
  930.             ci=-.0078125*(double)j+(((double)i+1.0)*.003906250);
  931.             ck=-.0078125*(double)j;
  932.             parm1 = (double)x+.5+ci;
  933.             parm2 = (double)y+.5+ck;
  934.             break;
  935.             }
  936.             Printer_printf("PA %f,%f;PD;PR %f,%f;PU;\0",
  937.             parm1,parm2, ci*((double)-2), ck*((double)-2));
  938.           }
  939.         }
  940.           }
  941.         }
  942.         Printer_printf("%s;SC;PA 0,0;SP0;%s\0",EndOfLine,EndOfLine);
  943.         Printer_printf(";;SP 0;%s\0",EndOfLine);
  944.         break;
  945.         }
  946.     }
  947.  
  948.     if (Print_To_File > 0) fclose(PRFILE);
  949. #ifndef XFRACT
  950.     if ((LPTn==30)||(LPTn==31))
  951.     {
  952.     for (x=0;x<2000;x++);
  953.     outp((LPTn==30) ? 0x3FC : 0x2FC,0x00);
  954.     outp((LPTn==30) ? 0x3F9 : 0x2F9,0x00);
  955.     }
  956. #endif
  957.     EXIT_OVLY;
  958. }
  959.  
  960. static void _fastcall print_title(int ptrid,int res,char *EndOfLine)
  961. {
  962.     char buff[80];
  963.     int postscript;
  964.     if (Printer_Titleblock == 0)
  965.     return;
  966.     postscript = (ptrid == 5 || ptrid ==6);
  967.     if (!postscript)
  968.     Printer_printf(EndOfLine);
  969.     else
  970.     Printer_printf("(");
  971.     Printer_printf((curfractalspecific->name[0]=='*')
  972.              ? &curfractalspecific->name[1]
  973.              : curfractalspecific->name);
  974.     if (fractype == FORMULA || fractype == FFORMULA)
  975.     Printer_printf(" %s",FormName);
  976.     if (fractype == LSYSTEM)
  977.     Printer_printf(" %s",LName);
  978.     if (fractype == IFS || fractype == IFS3D)
  979.     Printer_printf(" %s",IFSName);
  980.     Printer_printf(" - %dx%d - %d DPI", xdots, ydots, res);
  981.     if (!postscript)
  982.     Printer_printf(EndOfLine);
  983.     else {
  984.     Printer_printf(") show%s",EndOfLine);
  985.     if (ptrid==5) Printer_printf("30 45 moveto (");
  986.     else          Printer_printf("-90 rotate 567 30 moveto 90 rotate (");
  987.     }
  988.     Printer_printf("Corners: Top-Left=%4.4f/%4.4f Bottom-Right=%4.4f/%4.4f",
  989.            xxmin,yymax,xxmax,yymin);
  990.     if (xx3rd != xxmin || yy3rd != yymin) {
  991.     if (!postscript)
  992.         Printer_printf("%s        ",EndOfLine);
  993.     Printer_printf(" Bottom-Left=%4.4f/%4.4f",xx3rd,yy3rd);
  994.     }
  995.     if (!postscript)
  996.     Printer_printf(EndOfLine);
  997.     else {
  998.     Printer_printf(") show%s",EndOfLine);
  999.     if (ptrid==5) Printer_printf("30 30 moveto (");
  1000.     else          Printer_printf("-90 rotate 582 30 moveto 90 rotate (");
  1001.     }
  1002.     showtrig(buff);
  1003.     Printer_printf("Parameters: %4.4f/%4.4f/%4.4f/%4.4f %s",
  1004.            param[0],param[1],param[2],param[3],buff);
  1005.     if (!postscript)
  1006.     Printer_printf(EndOfLine);
  1007.     else
  1008.     Printer_printf(") show%s",EndOfLine);
  1009. }
  1010.  
  1011. /* This function prints a string to the the printer with BIOS calls. */
  1012.  
  1013. #ifndef XFRACT
  1014. static void Printer_printf(char *fmt,...)
  1015. #else
  1016. static void Printer_printf(va_alist)
  1017. va_dcl
  1018. #endif
  1019. {
  1020. char s[500];
  1021. int x=0;
  1022. va_list arg;
  1023.  
  1024. #ifndef XFRACT
  1025. va_start(arg,fmt);
  1026. #else
  1027. char *fmt;
  1028. va_start(arg);
  1029. fmt = va_arg(arg,char *);
  1030. #endif
  1031. vsprintf(s,fmt,arg);
  1032.  
  1033. if (Print_To_File>0)    /* This is for printing to file */
  1034.     fprintf(PRFILE,"%s",s);
  1035. else            /* And this is for printing to printer */
  1036.     while (s[x])
  1037.     if (printer(s[x++])!=0)
  1038.         while (!keypressed()) { if (printer(s[x-1])==0) break; }
  1039. }
  1040.  
  1041. /* This function standardizes both _bios_printer and _bios_serialcom
  1042.  * in one function.  It takes its arguments and rearranges them and calls
  1043.  * the appropriate bios call.  If it then returns result !=0, there is a
  1044.  * problem with the printer.
  1045.  */
  1046. static int _fastcall printer(int c)
  1047. {
  1048.     if (Print_To_File>0) return ((fprintf(PRFILE,"%c",c))<1);
  1049. #ifndef XFRACT
  1050.     if (LPTn<9)  return (((_bios_printer(0,LPTn,c))+0x0010)&0x0010);
  1051.     if (LPTn<19) return ((_bios_serialcom(1,(LPTn-10),c))&0x9E00);
  1052.     if ((LPTn==20)||(LPTn==21))
  1053.     {
  1054.     int PS=0;
  1055.     while ((PS & 0xF8) != 0xD8)
  1056.         { PS = inp((LPTn==20) ? 0x379 : 0x279);
  1057.           if (keypressed()) return(1); }
  1058.     outp((LPTn==20) ? 0x37C : 0x27C,c);
  1059.     PS = inp((LPTn==20) ? 0x37A : 0x27A);
  1060.     outp((LPTn==20) ? 0x37A : 0x27A,(PS | 0x01));
  1061.     outp((LPTn==20) ? 0x37A : 0x27A,PS);
  1062.     return(0);
  1063.     }
  1064.     if ((LPTn==30)||(LPTn==31))
  1065.     {
  1066.     while (((inp((LPTn==30) ? 0x3FE : 0x2FE)&0x30)!=0x30) ||
  1067.            ((inp((LPTn==30) ? 0x3FD : 0x2FD)&0x60)!=0x60))
  1068.         { if (keypressed()) return (1); }
  1069.     outp((LPTn==30) ? 0x3F8 : 0x2F8,c);
  1070.     return(0);
  1071.     }
  1072. #endif
  1073.  
  1074.     /* MCP 7-7-91, If we made it down to here, we may as well error out. */
  1075.     return(-1);
  1076. }
  1077.  
  1078. #ifdef __BORLANDC__
  1079. #if(__BORLANDC__ > 2)
  1080.    #pragma warn +eff
  1081. #endif
  1082. #endif
  1083.  
  1084. static void printer_reset()
  1085. {
  1086. #ifndef XFRACT
  1087.     if (Print_To_File < 1)
  1088.     if (LPTn<9)      _bios_printer(1,LPTn,0);
  1089.     else if (LPTn<19) _bios_serialcom(3,(LPTn-10),0);
  1090. #endif
  1091. }
  1092.  
  1093.  
  1094. /** debug code for pj_ color table checkout
  1095. color_test()
  1096. {
  1097.    int x,y,color,i,j,xx,yy;
  1098.    int bw,cw,bh,ch;
  1099.    setvideomode(videoentry.videomodeax,
  1100.         videoentry.videomodebx,
  1101.         videoentry.videomodecx,
  1102.         videoentry.videomodedx);
  1103.    bw = xdots/25; cw = bw * 2 / 3;
  1104.    bh = ydots/10; ch = bh * 2 / 3;
  1105.    dacbox[0][0] = dacbox[0][1] = dacbox[0][2] = 60;
  1106.    if (debugflag == 902)
  1107.       dacbox[0][0] = dacbox[0][1] = dacbox[0][2] = 0;
  1108.    for (x = 0; x < 25; ++x)
  1109.       for (y = 0; y < 10; ++y) {
  1110.      if (x < 11) i = (32 - x) * 10 + y;
  1111.          else    i = (24 - x) * 10 + y;
  1112.      color = x * 10 + y + 1;
  1113.      dacbox[color][0] = dstack[0][0][i];
  1114.      dacbox[color][1] = dstack[0][1][i];
  1115.      dacbox[color][2] = dstack[0][2][i];
  1116.      for (i = 0; i < cw; ++i) {
  1117.         xx = x * bw + bw / 6 + i;
  1118.         yy = y * bh + bh / 6;
  1119.         for (j = 0; j < ch; ++j)
  1120.            putcolor(xx,yy++,color);
  1121.         }
  1122.      }
  1123.    spindac(0,1);
  1124.    getakey();
  1125. }
  1126. **/
  1127.