home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Science / Science.zip / imdisp79.zip / DISPIO.C < prev    next >
C/C++ Source or Header  |  1993-08-03  |  53KB  |  1,806 lines

  1. /***  IMDISP module DISPIO.C
  2.  
  3.         DISPIO contains the device dependent display routines for the
  4.     Color Graphics Adapter (CGA), the Enhanced Graphics Adapter (EGA),
  5.     the Professional Graphics Adapter (PGA) and the Video Graphics Array
  6.     (VGA).  The global variables that define the device are allocated
  7.     and initialized here.
  8.  
  9. ***/
  10.  
  11. #define __MSC
  12.  
  13. /* * * * INCLUDE files * * * */
  14.  
  15. #include <conio.h>
  16. #include <dos.h>
  17.  
  18. #ifdef __TURBOC__
  19. #include <graphics.h>
  20. #else
  21. #include <graph.h>
  22. #endif
  23.  
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <string.h>
  27. #include <malloc.h>
  28. #include "mshell.h"
  29. #include "imdef.h"
  30. #include "imdisp.h"
  31. #include "imdutil.h"
  32. #include "imageio.h"
  33. #include "evgaio.h"
  34. #include "ativga.h"
  35. #include "dispsub.h"
  36. #include "paradise.h"
  37. #include "textutil.h"
  38. #include "keywutil.h"
  39. #include "trident.h"
  40. #include "refresh.h"
  41. #include "buffer.h"
  42. #include "vesa.h"
  43. #include "mem.h"
  44.  
  45. #include "ev629.h"
  46.  
  47. /* * * *  Defined Constants * * * */
  48.  
  49. /* * * * External functions * * * */
  50.  
  51. /* * * * Function declarations * * * */
  52.  
  53. int DisplayOn (void);
  54. int DisplayOff (void);
  55. int WritePixel (int, int, int);
  56. int ReadPixel (int, int, int *);
  57. int DisplayLine (unsigned char *,int ,int ,int );
  58. int GetLine (unsigned char *,int ,int ,int );
  59. int FormatLine (unsigned char *, int, int, int, int, char *);
  60. int ClearDisplay (int );
  61. int PGAreceive (unsigned char *, int *);
  62. int Which_Tseng(void);
  63.  
  64. /* * * * Global Variables * * * */
  65.  
  66. int            atibank;
  67. unsigned int   LastPage;
  68. int            tseng;
  69.  
  70. /*
  71.    DisplayDevice indicates the type of display (CGA=0, EGA=1, PGA=2, etc).
  72.    dispnl        is the number of lines in the display.
  73.    dispns        is the number of samples in the display.
  74.    numDN         is the number of unique pixel values (e.g. 4 bits ->
  75.                  numDN=16).
  76.    numshades     is the number of shades each of red, green, and blue
  77.                  (e.g.  numshades=16 gives 16**3 = 4096 possible colors).
  78.    OneScreen     is true if there is only one screen, i.e. there is not
  79.                  image screen and a text screen.
  80. */
  81.  
  82. int      dispnl, dispns, numDN, numshades, OneScreen;
  83.  
  84. Color  DefaultPalette[256], PaletteTable[256];
  85.  
  86. enum Display
  87.              { DISPLAY_MIN = -1, CGA200, EGA350, PGA, VGA480, VGA200, BIOS,
  88.                ORCHID480, ORCHID600, EVGA640, EVGA512, EVGA800, EGA480,
  89.                ATI640, ATI800, ATI1024, PARADISE, ORCHID768, TRIDENT, VESA,
  90.                VESA800, VESA640, EV629, TEST, DISPLAY_MAX };
  91.  
  92. enum Display DisplayDevice;
  93.  
  94. int DisplayOn(void)
  95.  
  96. /***
  97.     DisplayOn figures out which display device is on the system and then
  98.     initializes for that device.  The device is turned on. The global
  99.     variables that define the display characteristics and the default
  100.     color palette are initialized.
  101. ***/
  102.  
  103. {
  104.     int             i, VESA_mode;
  105.     unsigned char   cmd[7], EVGApalette[17];
  106.     union  REGS     inreg, outreg, regs;
  107.     struct SREGS    segregs;
  108.     Color           DP[16];
  109.  
  110.     /* Test for Enhanced Graphics Adapter (EGA) */
  111.     if (DisplayDevice == CGA200)
  112.     {
  113.         inreg.x.ax = 0x1200;
  114.         inreg.x.bx = 0x0FF10;
  115.         inreg.x.cx = 0x000F;
  116.         int86 (0x10, &inreg, &outreg);
  117.         if ( (outreg.h.cl < 0x0C) && (outreg.h.bh <= 1) && (outreg.h.bl <= 3) )
  118.             DisplayDevice = EGA350;
  119.     }
  120.  
  121. /* moved from before ega test to avoid conflicts with memory boards*/
  122. /* mdm 2-19-88 */
  123.  
  124. /* Test for Professional Graphics Adapter (PGA) */
  125. /*    if (DisplayDevice == CGA200 && devname == NULL) */
  126.     if (DisplayDevice == CGA200)
  127.     {
  128.         putmem (0x0C000, 0x63DB, 0x0AD);
  129.         if (getmem (0x0C000, 0x63DB) == 0x0AD)
  130.             DisplayDevice = PGA;
  131.     }
  132.  
  133.           /* Initialize for the appropriate device */
  134.     switch (DisplayDevice)
  135.     {
  136.     case CGA200 :    /* for standard cga display */
  137.  
  138.           dispnl     = 200;
  139.           dispns     = 640;
  140.           numDN      = 2;
  141.           numshades  = 2;
  142.           OneScreen  = 1;
  143.           _setvideomode( _HRESBW );
  144.           DefaultPalette[0].r = 0;    DefaultPalette[1].r = 255;
  145.           DefaultPalette[0].g = 0;    DefaultPalette[1].g = 255;
  146.           DefaultPalette[0].b = 0;    DefaultPalette[1].b = 255;
  147.           break;
  148.  
  149.     case EGA350 :     /* for standard ega displays */
  150.  
  151.           dispnl     = 350;
  152.           dispns     = 640;
  153.           numDN      = 16;
  154.           numshades  = 4;
  155.           OneScreen  = 1;
  156.           _setvideomode( _ERESCOLOR );
  157.  
  158.           DP[0].r  = 32;   DP[0].g  = 32;    DP[0].b  = 32;
  159.           DP[1].r  = 96;   DP[1].g  = 32;    DP[1].b  = 32;
  160.           DP[2].r  = 160;  DP[2].g  = 32;    DP[2].b  = 32;
  161.           DP[3].r  = 224;  DP[3].g  = 32;    DP[3].b  = 32;
  162.           DP[4].r  = 224;  DP[4].g  = 96;    DP[4].b  = 32;
  163.           DP[5].r  = 224;  DP[5].g  = 160;   DP[5].b  = 32;
  164.           DP[6].r  = 224;  DP[6].g  = 224;   DP[6].b  = 32;
  165.           DP[7].r  = 160;  DP[7].g  = 224;   DP[7].b  = 32;
  166.           DP[8].r  = 32;   DP[8].g  = 224;   DP[8].b  = 32;
  167.           DP[9].r  = 32;   DP[9].g  = 224;   DP[9].b  = 160;
  168.           DP[10].r = 32;   DP[10].g = 160;   DP[10].b = 160;
  169.           DP[11].r = 32;   DP[11].g = 160;   DP[11].b = 224;
  170.           DP[12].r = 32;   DP[12].g = 32;    DP[12].b = 224;
  171.           DP[13].r = 160;  DP[13].g = 32;    DP[13].b = 224;
  172.           DP[14].r = 224;  DP[14].g = 32;    DP[14].b = 224;
  173.           DP[15].r = 224;  DP[15].g = 224;   DP[15].b = 224;
  174.           for (i = 0; i <= 15; i++)
  175.             {
  176.              DefaultPalette[i].r = DP[i].r;
  177.              DefaultPalette[i].g = DP[i].g;
  178.              DefaultPalette[i].b = DP[i].b;
  179.             }
  180.  
  181.           break;
  182.  
  183.     case EGA480 :     /* for extended ega displays */
  184.  
  185.           /* if environment variable EGA480 is not null, then
  186.              initialize for 480 line mode.  Requires crystal
  187.              upgrade on EGA board and multisync monitor.      */
  188.  
  189.           dispnl     = 480;
  190.           dispns     = 640;
  191.           numDN      = 16;
  192.           numshades  = 4;
  193.           OneScreen  = 1;
  194.           egainit(); /* special init routines in dispsub.asm */
  195.  
  196.           DP[0].r  = 32;   DP[0].g  = 32;    DP[0].b  = 32;
  197.           DP[1].r  = 96;   DP[1].g  = 32;    DP[1].b  = 32;
  198.           DP[2].r  = 160;  DP[2].g  = 32;    DP[2].b  = 32;
  199.           DP[3].r  = 224;  DP[3].g  = 32;    DP[3].b  = 32;
  200.           DP[4].r  = 224;  DP[4].g  = 96;    DP[4].b  = 32;
  201.           DP[5].r  = 224;  DP[5].g  = 160;   DP[5].b  = 32;
  202.           DP[6].r  = 224;  DP[6].g  = 224;   DP[6].b  = 32;
  203.           DP[7].r  = 160;  DP[7].g  = 224;   DP[7].b  = 32;
  204.           DP[8].r  = 32;   DP[8].g  = 224;   DP[8].b  = 32;
  205.           DP[9].r  = 32;   DP[9].g  = 224;   DP[9].b  = 160;
  206.           DP[10].r = 32;   DP[10].g = 160;   DP[10].b = 160;
  207.           DP[11].r = 32;   DP[11].g = 160;   DP[11].b = 224;
  208.           DP[12].r = 32;   DP[12].g = 32;    DP[12].b = 224;
  209.           DP[13].r = 160;  DP[13].g = 32;    DP[13].b = 224;
  210.           DP[14].r = 224;  DP[14].g = 32;    DP[14].b = 224;
  211.           DP[15].r = 224;  DP[15].g = 224;   DP[15].b = 224;
  212.           for (i = 0; i <= 15; i++)
  213.             {
  214.              DefaultPalette[i].r = DP[i].r;
  215.              DefaultPalette[i].g = DP[i].g;
  216.              DefaultPalette[i].b = DP[i].b;
  217.             }
  218.  
  219.           break;
  220.  
  221.     case EVGA800 :     /* for Everex EV-673 hi-res ega mode */
  222.  
  223.           dispns = 800;
  224.           dispnl = 600;
  225.           numDN      = 16;
  226.           numshades  = 4;
  227.           OneScreen  = 1;
  228.           inreg.x.ax = 0x0070;  /* turn on EVGA MODE */
  229.           inreg.x.bx = 0x0002;  /* at 800x600 res */
  230.           int86 (0x10, &inreg, &outreg);
  231.  
  232.           DP[0].r  = 32;   DP[0].g  = 32;    DP[0].b  = 32;
  233.           DP[1].r  = 96;   DP[1].g  = 32;    DP[1].b  = 32;
  234.           DP[2].r  = 160;  DP[2].g  = 32;    DP[2].b  = 32;
  235.           DP[3].r  = 224;  DP[3].g  = 32;    DP[3].b  = 32;
  236.           DP[4].r  = 224;  DP[4].g  = 96;    DP[4].b  = 32;
  237.           DP[5].r  = 224;  DP[5].g  = 160;   DP[5].b  = 32;
  238.           DP[6].r  = 224;  DP[6].g  = 224;   DP[6].b  = 32;
  239.           DP[7].r  = 160;  DP[7].g  = 224;   DP[7].b  = 32;
  240.           DP[8].r  = 32;   DP[8].g  = 224;   DP[8].b  = 32;
  241.           DP[9].r  = 32;   DP[9].g  = 224;   DP[9].b  = 160;
  242.           DP[10].r = 32;   DP[10].g = 160;   DP[10].b = 160;
  243.           DP[11].r = 32;   DP[11].g = 160;   DP[11].b = 224;
  244.           DP[12].r = 32;   DP[12].g = 32;    DP[12].b = 224;
  245.           DP[13].r = 160;  DP[13].g = 32;    DP[13].b = 224;
  246.           DP[14].r = 224;  DP[14].g = 32;    DP[14].b = 224;
  247.           DP[15].r = 224;  DP[15].g = 224;   DP[15].b = 224;
  248.           for (i = 0; i <= 15; i++)
  249.             {
  250.              DefaultPalette[i].r = DP[i].r;
  251.              DefaultPalette[i].g = DP[i].g;
  252.              DefaultPalette[i].b = DP[i].b;
  253.             }
  254.  
  255.           break;
  256.  
  257.     case VGA480 :     /* for standard vga displays */
  258. #ifndef __TURBOC__
  259.     case BIOS :       /* for standard vga displays */
  260. #endif
  261.           dispnl     = 480;
  262.           dispns     = 640;
  263.           numDN      = 16;
  264.           numshades  = 64;
  265.           OneScreen  = 1;
  266.           _setvideomode( _VRES16COLOR );
  267.  
  268.           /* load default gray level palette with 17 dn increments */
  269.           for (i = 0; i <= 15; i++)
  270.             {
  271.                 DefaultPalette[i].r = i*16+i;
  272.                 DefaultPalette[i].g = i*16+i;
  273.                 DefaultPalette[i].b = i*16+i;
  274.             }
  275.           break;
  276.  
  277.     case PGA:     /* for standard pga display */
  278.  
  279.           dispnl = 480;
  280.           dispns = 640;
  281.           numDN = 256;
  282.           numshades = 16;
  283.           OneScreen = 1;
  284.  
  285.           cmd[0] = 0x43; cmd[1] = 0x58; cmd[2] = 0x20;
  286.           cmd[3] = 0x0D0; cmd[4] = 0x00;
  287.           cmd[5] = 0x0F; cmd[6] = 0x00;
  288.           PGAsend (cmd, 7);      /* 'CA DISPLA 0  CLEARS 0 '  */
  289.  
  290.           for (i = 0; i <= 255; i++)
  291.             {
  292.              DefaultPalette[i].r = i;
  293.              DefaultPalette[i].g = i;
  294.              DefaultPalette[i].b = i;
  295.             }
  296.           break;
  297.  
  298.     case ORCHID480 :   /* for Orchid ProDesigner enhanced VGA mode */
  299.  
  300.           dispnl = 480;
  301.           dispns = 640;
  302.           numDN = 256;
  303.           numshades = 64;
  304.           OneScreen = 1;
  305.           inreg.x.ax = 0x002E;  /* set 256 color 640 x480 mode */
  306.           int86 (0x10, &inreg, &outreg);
  307.           inreg.x.ax = 0x0500;  /* select page */
  308.           int86 (0x10, &inreg, &outreg);
  309.  
  310.           for (i = 0; i <= 255; i++)
  311.             {
  312.              DefaultPalette[i].r = i;
  313.              DefaultPalette[i].g = i;
  314.              DefaultPalette[i].b = i;
  315.             }
  316.  
  317.           tseng = Which_Tseng();     /* Ron Baalke - 04/22/91 */
  318.           break;
  319.  
  320.     case ORCHID600 :   /* for Orchid ProDesigner+ with 512K */
  321.  
  322.           dispnl = 600;
  323.           dispns = 800;
  324.           numDN = 256;
  325.           numshades = 64;
  326.           OneScreen = 1;
  327.           inreg.x.ax = 0x0030;  /* set 256 color 800 x 600 mode */
  328.           int86 (0x10, &inreg, &outreg);
  329.           inreg.x.ax = 0x0500;  /* select page */
  330.           int86 (0x10, &inreg, &outreg);
  331.  
  332.           for (i = 0; i <= 255; i++)
  333.             {
  334.              DefaultPalette[i].r = i;
  335.              DefaultPalette[i].g = i;
  336.              DefaultPalette[i].b = i;
  337.             }
  338.           tseng = Which_Tseng();     /* Ron Baalke - 04/22/91 */
  339.           break;
  340.  
  341.     case ORCHID768 :   /* for Orchid ProDesigner+ with 1024K */
  342.  
  343.           dispnl = 768;
  344.           dispns = 1024;
  345.           numDN = 256;
  346.           numshades = 64;
  347.           OneScreen = 1;
  348.           inreg.x.ax = 0x0038;  /* set 256 color 1024 x 768 mode */
  349.           int86 (0x10, &inreg, &outreg);
  350.           inreg.x.ax = 0x0500;  /* select page */
  351.           int86 (0x10, &inreg, &outreg);
  352.  
  353.           for (i = 0; i <= 255; i++)
  354.             {
  355.              DefaultPalette[i].r = i;
  356.              DefaultPalette[i].g = i;
  357.              DefaultPalette[i].b = i;
  358.             }
  359.           tseng = Which_Tseng();     /* Ron Baalke - 04/22/91 */
  360.           break;
  361.  
  362.     case VGA200 :   /* for standard VGA displays */
  363.  
  364.           dispnl = 200;
  365.           dispns = 320;
  366.           numDN = 256;
  367.           numshades = 64;
  368.           OneScreen = 1;
  369.           _setvideomode( _MRES256COLOR );
  370.           for (i = 0; i <= 255; i++)
  371.             {
  372.              DefaultPalette[i].r = i;
  373.              DefaultPalette[i].g = i;
  374.              DefaultPalette[i].b = i;
  375.             }
  376.           break;
  377.  
  378.     case EVGA640 :  /* for Everex EV-673 enhanced vga mode */
  379.  
  380.           dispns = 640;
  381.           dispnl = 400;
  382.           numDN = 256;
  383.           numshades = 64;
  384.           OneScreen = 1;
  385.           inreg.x.ax = 0x0070;
  386.           inreg.x.bx = 0x0014;
  387.           int86 (0x10, &inreg, &outreg);
  388.           for (i = 0; i <= 255; i++)
  389.             {
  390.               DefaultPalette[i].r = i;
  391.               DefaultPalette[i].g = i;
  392.               DefaultPalette[i].b = i;
  393.             }
  394.           EVGASetPage(0);
  395.           break;
  396.  
  397.     case EVGA512 :  /* for Everex EV-673 almost image proc mode */
  398.  
  399.           dispns = 512;
  400.           dispnl = 480;
  401.           numDN = 256;
  402.           numshades = 64;
  403.           OneScreen = 1;
  404.           inreg.x.ax = 0x0070;
  405.           inreg.x.bx = 0x0015;
  406.           int86 (0x10, &inreg, &outreg);
  407.           for (i = 0; i <= 255; i++)
  408.             {
  409.               DefaultPalette[i].r = i;
  410.               DefaultPalette[i].g = i;
  411.               DefaultPalette[i].b = i;
  412.             }
  413.           EVGASetPage(0);
  414.           break;
  415.  
  416.     case ATI640:     /* for ATI VGA Wonder */
  417.  
  418.           dispns = 640;
  419.           dispnl = 480;
  420.           numDN = 256;
  421.           numshades = 16;
  422.           OneScreen = 1;
  423.  
  424.           ATI_Init();
  425.  
  426.           for (i = 0; i <= 255; i++)
  427.             {
  428.              DefaultPalette[i].r = i;
  429.              DefaultPalette[i].g = i;
  430.              DefaultPalette[i].b = i;
  431.             }
  432.           break;
  433.  
  434.     case ATI800:     /* for ATI VGA Wonder */
  435.  
  436.           dispns = 800;
  437.           dispnl = 600;
  438.           numDN = 256;
  439.           numshades = 16;
  440.           OneScreen = 1;
  441.  
  442.           ATI_Init();
  443.  
  444.           for (i = 0; i <= 255; i++)
  445.             {
  446.              DefaultPalette[i].r = i;
  447.              DefaultPalette[i].g = i;
  448.              DefaultPalette[i].b = i;
  449.             }
  450.           break;
  451.  
  452.     case ATI1024:     /* for ATI VGA Wonder */
  453.  
  454.           dispns     = 1024;
  455.           dispnl     = 768;
  456.           numDN      = 16;
  457.           numshades  = 4;
  458.           OneScreen  = 1;
  459.  
  460.           ATI_Init();
  461.  
  462.           /* load default gray level palette */
  463.           for (i = 0; i <= 255; i++)
  464.             {
  465.                 DefaultPalette[i].r = i;
  466.                 DefaultPalette[i].g = i;
  467.                 DefaultPalette[i].b = i;
  468.             }
  469.           break;
  470.  
  471.     case PARADISE : /* for SUPER VGA board */
  472.     
  473.           dispnl = 480;
  474.           dispns = 640;
  475.           numDN = 256;
  476.           numshades = 64;
  477.           OneScreen = 1;
  478.           inreg.x.ax=0x007F;                   /*BIOS check on board memory */
  479.           inreg.x.bx=0x0200;
  480.           int86 (0x10, &inreg, &outreg);
  481.           if(outreg.h.ch >= 5)                /*return number of 64k units */
  482.           {
  483.                inreg.x.ax = 0x005F;           /*we have at least 309k for this mode */
  484.                int86 (0x10, &inreg, &outreg); /*set 256 color 640 x480 mode */
  485.           }
  486.           else
  487.           {
  488.                inreg.x.ax = 0x005E;           /*board has only 256k of memory */
  489.                int86 (0x10, &inreg, &outreg); /*set 256 color 640 x400 mode */
  490.                dispnl=400;
  491.           }
  492.           for (i = 0; i <= 255; i++)
  493.           {
  494.                DefaultPalette[i].r = i;
  495.                DefaultPalette[i].g = i;
  496.                DefaultPalette[i].b = i;
  497.           }
  498.           break;
  499.  
  500.     case TRIDENT:     /* for Trident boards */
  501.  
  502.           dispns = 640;
  503.           dispnl = 480;
  504.           numDN = 256;
  505.           numshades = 16;
  506.           OneScreen = 1;
  507.  
  508.           InitTRI();
  509.  
  510.           for (i = 0; i <= 255; i++)
  511.             {
  512.              DefaultPalette[i].r = i;
  513.              DefaultPalette[i].g = i;
  514.              DefaultPalette[i].b = i;
  515.             }
  516.           break;
  517.  
  518.     case VESA :       /* VESA SVGA Driver  */
  519.  
  520.           dispns = 1024;
  521.           dispnl = 768;
  522.           numDN = 256;
  523.           numshades = 64;
  524.           OneScreen = 1;
  525.           inreg.x.ax = 0x4F02;  /* SVGA set video mode */
  526.           inreg.x.bx = 0x0105;  /* 1024x768 mode, clear memory */
  527.           int86 (0x10, &inreg, &outreg);
  528.           for (i = 0; i <= 255; i++)
  529.           {
  530.               DefaultPalette[i].r = i;
  531.               DefaultPalette[i].g = i;
  532.               DefaultPalette[i].b = i;
  533.           }
  534.  
  535.           break;
  536.  
  537.     case VESA800 :       /* VESA SVGA Driver  */
  538.  
  539.           dispns = 800;
  540.           dispnl = 600;
  541.           numDN = 256;
  542.           numshades = 64;
  543.           OneScreen = 1;
  544.           inreg.x.ax = 0x4F02;  /* SVGA set video mode */
  545.           inreg.x.bx = 0x0103;  /* 800x600 mode, clear memory */
  546.           int86 (0x10, &inreg, &outreg);
  547.           for (i = 0; i <= 255; i++)
  548.           {
  549.               DefaultPalette[i].r = i;
  550.               DefaultPalette[i].g = i;
  551.               DefaultPalette[i].b = i;
  552.           }
  553.  
  554.           break;
  555.  
  556.     case VESA640 :       /* VESA SVGA Driver  */
  557.  
  558.           dispns = 640;
  559.           dispnl = 480;
  560.           numDN = 256;
  561.           numshades = 64;
  562.           OneScreen = 1;
  563.           inreg.x.ax = 0x4F02;  /* SVGA set video mode */
  564.           inreg.x.bx = 0x0101;  /* 640x480 mode, clear memory */
  565.           int86 (0x10, &inreg, &outreg);
  566.           for (i = 0; i <= 255; i++)
  567.           {
  568.               DefaultPalette[i].r = i;
  569.               DefaultPalette[i].g = i;
  570.               DefaultPalette[i].b = i;
  571.           }
  572.  
  573.           break;
  574.  
  575.     case EV629 :       /* for Everex EV-629 24-bit board  */
  576.  
  577.           dispns = 640;
  578.           dispnl = 480;
  579.           numDN = 256;
  580.           numshades = 256;
  581.           OneScreen = 1;
  582.  
  583.           setbits(24);
  584.           setwide(640);
  585.  
  586.           init629();
  587.           ClearDisplay( 0 );
  588.  
  589.           for (i = 0; i <= numDN; i++)
  590.           {
  591.              DefaultPalette[i].r = i;
  592.              DefaultPalette[i].g = i;
  593.              DefaultPalette[i].b = i;
  594.           }
  595.  
  596.           break;
  597.  
  598.     }
  599.  
  600.     if (dispnl >= 768)
  601.     {
  602.         TextHeight = 15;
  603.         BigChars   = 20;
  604.         SmallChars = 12;
  605.     }
  606.     else if (dispnl >= 600)
  607.     {
  608.         TextHeight = 12;
  609.         BigChars   = 15;
  610.         SmallChars = 10;
  611.     }
  612.     else if (dispnl >= 480)
  613.     {
  614.         TextHeight =  9;
  615.         BigChars   = 12;
  616.         SmallChars =  6;
  617.     }
  618.     else if (dispnl >= 400)
  619.     {
  620.         TextHeight =  8;
  621.         BigChars   = 12;
  622.         SmallChars =  6;
  623.     }
  624.     else if (dispnl >= 350)
  625.     {
  626.         TextHeight =  8;
  627.         BigChars   = 10;
  628.         SmallChars =  6;
  629.     }
  630.     else
  631.     {
  632.         TextHeight = 6;
  633.         BigChars   = 8;
  634.         SmallChars = 5;
  635.     }
  636.  
  637. }
  638.  
  639.  
  640. int DisplayOff(void)
  641.  
  642. /***
  643.     DisplayOff turns off the display device returning the screen
  644.     to text mode.
  645. ***/
  646.  
  647. {
  648.     unsigned   char    cmd[2];
  649.     union      REGS    inreg, outreg;
  650.     int        i;
  651.  
  652.     switch (DisplayDevice)
  653.     {
  654. #ifndef __TURBOC__
  655.     case BIOS    :    /* for plain vga display */
  656. #endif
  657.     case CGA200  :    /* for cga display */
  658.     case EGA350  :    /* for ega and vga displays */
  659.     case VGA480  :    /* for ega and vga displays */
  660.     case VGA200  :    /* for ega and vga displays */
  661.     case EGA480  :    /* for enhanced ega */
  662.     case EVGA640 :    /* for Everex EVGA */
  663.     case EVGA512 :    /* for Everex EVGA */
  664.     case EVGA800 :    /* for Everex EVGA */
  665.     case ATI640  :    /* For ATI VGA Wonder */
  666.     case ATI800  :    /* For ATI VGA Wonder */
  667.     case ATI1024 :    /* For ATI VGA Wonder */
  668.     case PARADISE :   /* for Paradise Super VGA */
  669.     case TRIDENT :    /* for Trident Super VGA */
  670.     case VESA :       /* VESA SVGA Driver  */
  671.     case VESA800 :    /* VESA SVGA Driver  */
  672.     case VESA640 :    /* VESA SVGA Driver  */
  673.  
  674.           _setvideomode( _DEFAULTMODE );
  675.           break;
  676.  
  677.     case ORCHID480 :    /* for orchid designer */
  678.     case ORCHID600 :    /* for orchid designer */
  679.     case ORCHID768 :    /* for orchid designer */
  680.  
  681.           ClearDisplay( 0 );              /* Keep Seiko monitor from */
  682.                                           /* shutting off */
  683.           inreg.x.ax = 0x0003;
  684.           int86 (0x10, &inreg, &outreg);
  685.           break;
  686.  
  687.  
  688.     case PGA:     /* for pga display */
  689.  
  690.           cmd[0] = 0x0D0;   cmd[1] = 1;
  691.           PGAsend (cmd, 2);  /* 'DISPLA 1' */
  692.           break;
  693.  
  694.     case EV629 :       /* for Everex EV-629 24-bit board  */
  695.  
  696.           done629();
  697.           break;
  698.  
  699.     }
  700.     OneScreen = 0;
  701.  
  702. }
  703.  
  704.  
  705. int WritePixel (int line, int sample, int DN)
  706.  
  707. /***  WritePixel writes a pixel on the display screen.
  708.       Parameter   type       description
  709.         line     integer     The line coordinate of the pixel
  710.         sample   integer     The sample coordinate of the pixel
  711.         DN       integer     The DN value of the pixel
  712. ***/
  713.  
  714. {
  715.     unsigned int  x, y;
  716.     unsigned int  segment;
  717.     unsigned long laddress;
  718.     int           address, bit, mask, useBIOS;
  719.     unsigned char cmd[9];
  720.     unsigned char far *faraddr;
  721.     unsigned int  color;
  722.  
  723.     long *pix_adr;
  724.     long color24;
  725.     unsigned int  red_pixel, green_pixel, blue_pixel;
  726.  
  727.     switch (DisplayDevice)
  728.     {
  729.  
  730.     case CGA200 :     /* for cga display */
  731.  
  732.           line--;
  733.           sample--;
  734.           bit = 7 - (sample & 7);
  735.           DN = (DN & 1) << bit;
  736.           mask = ~(1 << bit);
  737.  
  738.           if ((line & 1) == 0)
  739.               address = 0x8000 + 40*line + (sample >> 3);
  740.           else
  741.               address = 0x0A000 + 40*(line-1) + (sample >> 3);
  742.           putmem (0x0B000, address, (getmem(0xB000,address) & mask) | DN);
  743.           return(0);
  744.  
  745.     case EGA350 :   /* for ega and vga displays */
  746.     case EGA480 :   /* for ega and vga displays */
  747.     case VGA480 :   /* for ega and vga displays */
  748.  
  749.             WritePixelEGA (line, sample, DN);
  750.             return(0);
  751.  
  752. #ifndef __TURBOC__
  753.     case BIOS :   /* for ega and vga displays */
  754.  
  755.             _setcolor( DN );
  756.             _setpixel( sample, line );
  757.             return(0);
  758. #endif
  759.  
  760.     case PGA :    /* for pga display */
  761.  
  762.           x = sample - 1;
  763.           y = 480 - line;
  764.           cmd[0] = 0x0D9;
  765.             cmd[1] = y;  cmd[2] = y >> 8;
  766.             cmd[3] = x;  cmd[4] = x >> 8;
  767.             cmd[5] = x;  cmd[6] = x >> 8;
  768.             cmd[7] = 0;       cmd[8] = DN;
  769.           PGAsend (cmd, 9);       /* 'IMAGEW y x x ' */
  770.           return(0);
  771.  
  772.     case VGA200 :   /* for ega and vga displays */
  773.     case ORCHID480 :    /* for orchid designer */
  774.     case ORCHID600 :    /* for orchid designer */
  775.     case ORCHID768 :    /* for orchid designer */
  776.  
  777.           laddress = ((long)dispns*(long)(line-1))+(long)(sample-1);
  778.           segment  = laddress >> 16;
  779.           laddress = laddress & 0x0FFFF;
  780.           faraddr  = (unsigned char far *) (0x0a0000000L + laddress);
  781.           outp(0x3cd,0x40 | segment);
  782.           *(faraddr) = (unsigned char)DN;
  783.           return(0);
  784.  
  785.     case EVGA640 :    /* for Everex EVGA */
  786.     case EVGA512 :    /* for Everex EVGA */
  787.  
  788.           EVGAWritePixel256(sample, line, DN);
  789.           return(0);
  790.  
  791.     case EVGA800 :    /* for Everex EVGA */
  792.  
  793.           useBIOS = 0;
  794.           EVGAWritePixelEGA (sample, line, (unsigned char) DN, useBIOS);
  795.           return(0);
  796.  
  797.     case ATI640 :    /* for ATI VGA Wonder */
  798.     case ATI800 :    /* for ATI VGA Wonder */
  799.     case ATI1024:    /* for ATI VGA Wonder */
  800.  
  801.           x = (unsigned int) sample;
  802.           y = (unsigned int) line;
  803.           color = (unsigned int) DN;
  804.  
  805.           ATI_WritePixel(x,y,color);
  806.           return(0);
  807.  
  808.     case PARADISE :   /* for Super VGA */
  809.  
  810.             WritePixelPAR (line-1, sample-1, DN);
  811.             outp( 0x3ce, 0x0000f);                 /* added - mwm */
  812.             return(0);
  813.  
  814.     case TRIDENT:    /* for Trident SVGA */
  815.  
  816.           x = (unsigned int) sample;
  817.           y = (unsigned int) line;
  818.           color = (unsigned int) DN;
  819.  
  820.           WritePixelTRI (y-1, x-1, color);
  821.           return(0);
  822.  
  823.     case VESA :       /* VESA SVGA Driver  */
  824.     case VESA800 :       /* VESA SVGA Driver  */
  825.     case VESA640 :       /* VESA SVGA Driver  */
  826.  
  827.            laddress = ( (long) dispns * (long) (line-1)) + (long) (sample-1);
  828.            segment  = laddress >> 16;       /* find page number */
  829.            laddress = laddress & 0x0FFFF;   /* find offset */
  830.            faraddr  = (unsigned char far *) (0x0a0000000L + laddress);
  831.  
  832.            if (segment != LastPage)
  833.                LastPage = VESA_Set_Page( segment );
  834.  
  835.            *(faraddr) = (unsigned char)DN;
  836.            return(0);
  837.  
  838.  
  839.     case EV629 :       /* for Everex EV-629 24-bit board  */
  840.  
  841.            pix_adr = pixaddr( sample-1, line-1) ;
  842.            red_pixel = (unsigned) DN;
  843.            green_pixel = 0;
  844.            blue_pixel = 0;
  845.            color24 = buildcolor( red_pixel, green_pixel, blue_pixel);
  846.            memcpy( pix_adr, &color24, colorbytes);
  847.            return(0);
  848.  
  849.     }
  850. }
  851.  
  852. int ReadPixel (int line, int sample, int * p_DN)
  853.  
  854. /***  ReadPixel read a pixel value from the display screen.
  855.       Parameter   type       description
  856.         line     integer     The line coordinate of the pixel
  857.         sample   integer     The sample coordinate of the pixel
  858.         p_DN     int ptr     The DN value of the pixel is returned
  859. **/
  860.  
  861. {
  862.     int   address, y, x, mask, bit;
  863.     int   len;
  864.     unsigned int  segment;
  865.     unsigned long laddress;
  866.     unsigned char   cmd[256];
  867.     unsigned char far *faraddr;
  868.  
  869.     long *pix_adr, color24;
  870.     unsigned int red_pixel, green_pixel, blue_pixel;
  871.  
  872.     switch (DisplayDevice)
  873.     {
  874.     case CGA200 :     /* for cga display */
  875.  
  876.           line--;
  877.           sample--;
  878.           bit = 7 - (sample & 7);
  879.  
  880.           if ((line & 1) == 0)
  881.               address = 0x8000 + 40*line + (sample >> 3);
  882.           else
  883.               address = 0x0A000 + 40*(line-1) + (sample >> 3);
  884.  
  885.           *p_DN = (getmem(0x0B000,address) & (1 << bit)) >> bit;
  886.           return(0);
  887.  
  888.     case EGA350 :   /* for ega and vga displays */
  889.     case EGA480 :   /* for ega and vga displays */
  890.     case VGA480 :   /* for ega and vga displays */
  891.     case EVGA640 :    /* for Everex EVGA */
  892.     case EVGA512 :    /* for Everex EVGA */
  893.     case EVGA800 :    /* for Everex EVGA */
  894.  
  895.           y = line - 1;
  896.           x = sample - 1;
  897.           address = (y << 6) + (y << 4) + (x >> 3);
  898.           mask = 0x80 >> (x & 7);
  899.           *p_DN = 0;
  900.           for (bit = 3;  bit >= 0;  bit--)
  901.           {
  902.               outp (0x3CE, 4);
  903.               outp (0x3CF, bit);
  904.               if ( (getmem (0x0A000,address) & mask) > 0 )
  905.                   *p_DN = (*p_DN << 1) | 1;
  906.               else
  907.                   *p_DN = *p_DN << 1;
  908.           }
  909.           return(0);
  910.  
  911. #ifndef __TURBOC__
  912.     case BIOS :   /* for ega and vga displays */
  913.  
  914.           *p_DN = _getpixel(sample, line);
  915.           return(0);
  916. #endif
  917.  
  918.     case ATI640 :   /* for ATI VGA Wonder */
  919.     case ATI800 :   /* for ATI VGA Wonder */
  920.     case ATI1024:   /* for ATI VGA Wonder */
  921.  
  922.           *p_DN = ATI_ReadPixel(sample,line);
  923.           return(0);
  924.  
  925.     case PGA :     /* for pga display */
  926.  
  927.           x = sample - 1;     y = 480 - line;
  928.           cmd[0] = 0x0D8;
  929.             cmd[1] = y;  cmd[2] = y >> 8;
  930.             cmd[3] = x;  cmd[4] = x >> 8;
  931.             cmd[5] = x;  cmd[6] = x >> 8;
  932.           PGAsend (cmd, 7);          /* 'IMAGER y x x ' */
  933.           for (x = 0; x < 1000; x++) ;    /* delay loop */
  934.           PGAreceive (cmd, &len);
  935.           *p_DN = cmd[8];
  936.           return(0);
  937.  
  938.     case VGA200 :   /* for ega and vga displays */
  939.     case ORCHID480 :     /* for orchid designer */
  940.     case ORCHID600 :     /* for orchid designer */
  941.     case ORCHID768 :     /* for orchid designer */
  942.  
  943.           laddress = ((long)dispns*(long)(line-1))+(long)(sample-1);
  944.           segment  = laddress >> 16;
  945.           laddress = laddress & 0x0FFFF;
  946.           faraddr  = (unsigned char far *) (0x0a0000000L + laddress);
  947.           if (tseng == 4000)        /* Added 04/22/91 - Ron Baalke */
  948.              outp(0x3cd,(0x40 | segment) << 4);
  949.           else
  950.              outp(0x3cd,0x40 | segment << 3);
  951.           *p_DN = *(faraddr);
  952.           return(0);
  953.  
  954.     case PARADISE : /* for Super VGA */
  955.  
  956.          ReadPixelPAR( line-1, sample-1, p_DN);
  957.          *p_DN &= 0xFF;                         /* Remove garbage - mwm */
  958.          return(0);
  959.  
  960.     case TRIDENT : /* for Super VGA */
  961.  
  962.          ReadPixelTRI( line-1, sample-1, p_DN);
  963.          *p_DN &= 0xFF;                         /* Remove garbage - mwm */
  964.          return(0);
  965.  
  966.     case VESA :       /* VESA SVGA Driver */
  967.     case VESA800 :       /* VESA SVGA Driver */
  968.     case VESA640 :       /* VESA SVGA Driver */
  969.  
  970.            laddress = ( (long) dispns * (long) (line-1)) + (long) (sample-1);
  971.            segment  = laddress >> 16;
  972.            laddress = laddress & 0x0FFFF;
  973.            faraddr  = (unsigned char far *) (0x0a0000000L + laddress);
  974.  
  975.            if (segment != LastPage)
  976.                LastPage = VESA_Set_Page( segment );
  977.  
  978.            *p_DN = *(faraddr);
  979.            return(0);
  980.  
  981.     case EV629 :       /* for Everex EV-629 24-bit board  */
  982.  
  983.            pix_adr = pixaddr( sample-1, line-1) ;
  984.            memcpy( &color24, pix_adr, colorbytes);
  985.            unbuildcolor( color24, &red_pixel, &green_pixel, &blue_pixel);
  986.            *p_DN = red_pixel;
  987.            return(0);
  988.  
  989.     }
  990. }
  991.  
  992. int DisplayLine (unsigned char * buffer, int line, int sample, int ns)
  993.  
  994. /***  DisplayLine writes a line of pixels on the display screen.
  995.       Parameter   type       description
  996.         buffer   char ptr    The array of pixel values
  997.         line     integer     The line coordinate of the first pixel
  998.         sample   integer     The sample coordinate of the first pixel
  999.         ns       integer     The number of pixels to display
  1000. ***/
  1001.  
  1002. {
  1003.     unsigned char   cmd[7];
  1004.     unsigned int   x,y, x1, x2, len, s;
  1005.     int            i, address, mask, bit;
  1006.     unsigned int  segment;
  1007.     unsigned long laddress;
  1008.     unsigned char far *faraddr;
  1009.     unsigned int  color;
  1010.     long *pix_adr;
  1011.  
  1012.     switch (DisplayDevice)
  1013.     {
  1014.     case CGA200 :     /* for cga display */
  1015.  
  1016.           line--;
  1017.           sample--;
  1018.           if ((line & 1) == 0)
  1019.               address = 0x8000 + 40*line + (sample >> 3);
  1020.           else
  1021.               address = 0x0A000 + 40*(line-1) + (sample >> 3);
  1022.           bit = 7 - (sample & 7);
  1023.           mask = getmem(0x0B000,address) & ~((1 << (bit+1)) - 1);
  1024.           for (i = 0;  i < ns;  i++)
  1025.           {
  1026.               mask |= (buffer[i] & 1) << bit;
  1027.               bit--;
  1028.               if (bit < 0)
  1029.               {
  1030.                   putmem(0x0B000,address, mask);
  1031.                   address++;
  1032.                   bit = 7;
  1033.                   mask = 0;
  1034.               }
  1035.           }
  1036.           putmem(0x0B000,address,
  1037.                   mask | (getmem(0x0B000,address) & ((1 << (bit+1)) - 1)) );
  1038.           return(0);
  1039.  
  1040.     case EGA350 :   /* for ega and vga displays */
  1041.     case EGA480 :   /* for ega and vga displays */
  1042.     case VGA480 :   /* for ega and vga displays */
  1043.     case EVGA800 :    /* for Everex EVGA */
  1044.  
  1045.           DisplayLineEGA (FP_SEG(buffer),FP_OFF(buffer), line, sample, ns);
  1046.           return(0);
  1047.  
  1048. #ifndef __TURBOC__
  1049.     case BIOS :   /* for ega and vga displays */
  1050.  
  1051.  
  1052.           y = line;
  1053.           for (i=0; i<ns; i++)
  1054.           {
  1055.              x = sample + i;
  1056.              color = (unsigned int)(buffer[i]);
  1057.              WritePixel( y, x, color);
  1058.           }
  1059.           return(0);
  1060. #endif
  1061.  
  1062.     case ATI640 :
  1063.     case ATI800 :
  1064.     case ATI1024:
  1065.  
  1066.           y = line;
  1067.           for (i=0; i<ns; i++)
  1068.           {
  1069.              x = sample + i;
  1070.              color = (unsigned int)(buffer[i]);
  1071.              ATI_WritePixel(x,y,color);
  1072.           }
  1073.           return(0);
  1074.  
  1075.     case PGA :     /* for pga display */
  1076.           y = 480 - line;  x1 = sample - 1;  x2 = x1 + ns - 1;
  1077.           cmd[0] = 0x0D9;
  1078.            cmd[1] = y;   cmd[2] = y >> 8;
  1079.            cmd[3] = x1;  cmd[4] = x1 >> 8;
  1080.            cmd[5] = x2;  cmd[6] = x2 >> 8;
  1081.           PGAsend (cmd, 7);       /* 'IMAGEW y x1 x2 ' */
  1082.           s = 0;
  1083.           while (s < ns)
  1084.           {
  1085.               len = ns - s;   if (len > 128)  len = 128;
  1086.               cmd[0] = 127 + len;
  1087.               PGAsend (cmd, 1);
  1088.               PGAsend (&buffer[s], len);
  1089.               s += 128;
  1090.           }
  1091.           return(0);
  1092.  
  1093.     case VGA200 :   /* for ega and vga displays */
  1094.     case ORCHID480 :     /* for orchid designer */
  1095.     case ORCHID600 :     /* for orchid designer */
  1096.     case ORCHID768 :     /* for orchid designer */
  1097.  
  1098.           laddress = ((long)dispns*(long)(line-1))+(long)(sample-1);
  1099.           segment  = laddress >> 16;
  1100.           laddress = laddress & 0x0FFFF;
  1101.           if ((laddress + (long)ns) > 65535L)
  1102.           /* this line will overlap a segment so write it pixel by pixel */
  1103.             for (i = 0; i < ns; i++) WritePixel(line,sample+i,(int)buffer[i]);
  1104.           else
  1105.             {
  1106.              faraddr  = (unsigned char far *) (0x0a0000000L + laddress);
  1107.              outp(0x3cd,0x40 | segment);
  1108.              memcpy (faraddr,buffer,ns);
  1109.             }
  1110.           return(0);
  1111.  
  1112.     case EVGA640 :    /* for Everex EVGA */
  1113.     case EVGA512 :    /* for Everex EVGA */
  1114.  
  1115.           laddress = ( (long) dispns * (long) line ) + (long) (sample-1);
  1116.           segment  = laddress >> 16;
  1117.           laddress = laddress & 0x0FFFF;
  1118.           if ((laddress + (long)ns) > 65535L)
  1119.           /* this line will overlap a segment so write it pixel by pixel */
  1120.               for (i = 0; i < ns; i++)
  1121.                   EVGAWritePixel256(sample+i,line,(int)buffer[i]);
  1122.           else
  1123.           {
  1124.              faraddr  = (unsigned char far *) (0x0a0000000L + laddress);
  1125.              if (segment != LastPage)
  1126.              {
  1127.                  EVGASetPage( (unsigned char)segment);
  1128.                  LastPage = segment;
  1129.              }
  1130.              memcpy (faraddr,buffer,ns);
  1131.           }
  1132.           return(0);
  1133.  
  1134.     case PARADISE : /* for Super VGA */
  1135.  
  1136.           WriteLinePAR (sample-1, ns, line-1, buffer);
  1137.           outp( 0x3ce, 0x0000f);                 /* added - mwm */
  1138.           return(0);
  1139.  
  1140.     case TRIDENT : /* for Super VGA */
  1141.  
  1142.           WriteLineTRI (sample-1, ns, line-1, buffer);
  1143.           return(0);
  1144.  
  1145.     case VESA :       /* VESA SVGA Driver  */
  1146.     case VESA800 :       /* VESA SVGA Driver  */
  1147.     case VESA640 :       /* VESA SVGA Driver  */
  1148.  
  1149.            laddress = ( (long) dispns * (long) (line-1)) + (long) (sample-1);
  1150.            segment  = laddress >> 16;
  1151.            laddress = laddress & 0x0FFFF;
  1152.  
  1153.            if ((laddress + (long)ns) > 65535L)
  1154.            /* this line will overlap a segment so write it pixel by pixel */
  1155.                for (i = 0; i < ns; i++)
  1156. /*                   WritePixel (sample+i, line, (int)buffer[i]); */
  1157.                    WritePixel (line, sample+i, (int)buffer[i]);
  1158.            else
  1159.            {
  1160.                faraddr  = (unsigned char far *) (0x0a0000000L + laddress);
  1161.  
  1162.                if (segment != LastPage)
  1163.                    LastPage = VESA_Set_Page( segment );
  1164.  
  1165.                memcpy (faraddr,buffer,ns);
  1166.            }
  1167.            return(0);
  1168.  
  1169.     case EV629 :       /* for Everex EV-629 24-bit board  */
  1170.  
  1171.           y = line;
  1172.           for (i=0; i<ns; i++)
  1173.           {
  1174.              x = sample + i;
  1175.              color = (unsigned int)(buffer[i]);
  1176.              WritePixel( y, x, color);
  1177.           }
  1178.           return(0);
  1179.  
  1180.     }
  1181. }
  1182.  
  1183. int GetLine (unsigned char * buffer, int line, int sample, int ns)
  1184.  
  1185. /***  GetLine reads a line of pixels from the display screen.  Will
  1186.       attempt to retrieve the line from the refresh buffer first if
  1187.       the refresh buffer is in extended memory.
  1188.  
  1189.       Written by Ron Baalke - 05/91.
  1190.  
  1191.       Parameter   type       description
  1192.         buffer   char ptr    The array of pixel values
  1193.         line     integer     The line coordinate of the first pixel
  1194.         sample   integer     The sample coordinate of the first pixel
  1195.         ns       integer     The number of pixels to be read
  1196. ***/
  1197. {
  1198.    int i;
  1199.    long offset;
  1200.    int DN;
  1201.    unsigned int  segment;
  1202.    unsigned long laddress;
  1203.    unsigned char far *faraddr;
  1204.     long *pix_adr;
  1205.  
  1206.    if ((RefreshLines > 0) && (RefreshLocation != VIRTUAL_FILE))
  1207.    {
  1208.       GetRefresh(buffer,line,sample,ns);
  1209.       return(0);
  1210.    }
  1211.  
  1212.    switch (DisplayDevice)
  1213.    {
  1214.     case VGA200 :        /* for ega and vga displays */
  1215.     case ORCHID480 :     /* for orchid designer */
  1216.     case ORCHID600 :     /* for orchid designer */
  1217.     case ORCHID768 :     /* for orchid designer */
  1218.  
  1219.           laddress = ((long)dispns*(long)(line-1))+(long)(sample-1);
  1220.           segment  = laddress >> 16;
  1221.           laddress = laddress & 0x0FFFF;
  1222.           faraddr  = (unsigned char far *) (0x0a0000000L + laddress);
  1223.           if ((laddress + (long)ns) > 65535L)
  1224.           {
  1225.           /* this line will overlap a segment so read it pixel by pixel */
  1226.              for (i = 0; i < ns; i++)
  1227.              {
  1228.                 ReadPixel(line,i+sample,&DN);
  1229.                 buffer[i] = DN;
  1230.              }
  1231.           }
  1232.           else
  1233.             {
  1234.              faraddr  = (unsigned char far *) (0x0a0000000L + laddress);
  1235.              if (tseng == 4000)
  1236.                 outp(0x3cd,(0x40 | segment) << 4);
  1237.              else
  1238.                 outp(0x3cd,0x40 | segment << 3);
  1239.              memcpy (buffer,faraddr,ns);
  1240.             }
  1241.           return(0);
  1242.  
  1243.     case EV629 :       /* for Everex EV-629 24-bit board  */
  1244.  
  1245.            pix_adr = pixaddr( sample-1, line-1) ;
  1246.            memcpy( buffer, pix_adr, colorbytes*ns);
  1247.            return(0);
  1248.  
  1249.  
  1250.     default :             /* everything else */
  1251.           for (i=0; i<ns; i++)
  1252.           {
  1253.              ReadPixel(line,i+sample,&DN);
  1254.              buffer[i] = DN;
  1255.           }
  1256.           return(0);
  1257.    }
  1258. }
  1259.  
  1260. int FormatLine (unsigned char * buffer, int nsdd, int nsd, int bitshift,
  1261.                 int NoScale, char * status)
  1262.  
  1263. /*  FormatLine converts the line of pixels in the buffer into
  1264.     byte format for display.  It also performs subsampling
  1265.     or zooming if needed.
  1266. */
  1267.  
  1268. {
  1269.     int   samp, j, k, DN, scale, absbitshift;
  1270.     int   mult;
  1271.     float fscale;
  1272.     unsigned char *tmpbuf;
  1273.     union {
  1274.                unsigned char   *b;
  1275.                int             *i;
  1276.                long            *l;
  1277.           }  buf;
  1278.     buf.b = buffer;
  1279.  
  1280.     if ((tmpbuf = malloc(2048)) == NULL)
  1281.     {
  1282.         FatalError( "Not enough memory for pixel buffer.\n");
  1283.     }
  1284.  
  1285.     status[0] = 0;
  1286.     TurnCursorOff = 0; /* always reinitialize the cursor fn to be on */
  1287.  
  1288. /* For 16 bit images */
  1289. /* scaling is done by dividing by a scale factor if the dn range specified
  1290.    is greater than the display range and by multiplying if the range
  1291.    specified is less than the display range
  1292. */
  1293.     if (bitsperpix == 16)
  1294.     {
  1295.        fscale = ((float)(DNhigh - DNlow) / (float)numDN);
  1296.        if (fscale < 1)
  1297.        {
  1298.           mult = 1;
  1299.           scale = 1.0/fscale;
  1300.        }
  1301.        else
  1302.        {
  1303.           mult = 0;
  1304.           scale = fscale + 1;
  1305.        }
  1306.  
  1307.        if (zoom == 1 )
  1308.        {
  1309.            samp = 0;
  1310.            for (j = 0;  j < nsdd;  j++)
  1311.            {
  1312.                DN = buf.i[samp];
  1313.                if (DN >= DNhigh)
  1314.                    DN = DNhigh - 1;
  1315.                else
  1316.                    if (DN <= DNlow)
  1317.                        DN = DNlow;
  1318.  
  1319.                if (mult)
  1320.                    buf.b[j] = ((long)DN-DNlow) *  scale;
  1321.                else
  1322.                    buf.b[j] = ((long)DN-DNlow) /  scale;
  1323.                samp += subsample;
  1324.            }
  1325.        }
  1326.        else
  1327.        {
  1328.            j = nsd*zoom-1;
  1329.            for (samp = nsd-1;  samp >= 0;  samp--)
  1330.            {
  1331.                DN = buf.i[samp];
  1332.                if (DN >= DNhigh)
  1333.                    DN = DNhigh - 1;
  1334.                else
  1335.                    if (DN <= DNlow)
  1336.                        DN = DNlow;
  1337.                if (mult)
  1338.                    DN = ((long)DN-DNlow) *  scale;
  1339.                else
  1340.                    DN = ((long)DN-DNlow) /  scale;
  1341.  
  1342.                for (k = 1;  k <= zoom;  k++)
  1343.                   buf.b[j--] = DN;
  1344.            }
  1345.        }
  1346.  
  1347.     }
  1348.  
  1349. /* For 32 bit images */
  1350. /* scaling is done by dividing by a scale factor if the dn range specified
  1351.    is greater than the display range and by multiplying if the range
  1352.    specified is less than the display range
  1353. */
  1354.     else if (bitsperpix ==32)
  1355.     {
  1356.        fscale = ((float)(DNhigh - DNlow) / (float)numDN);
  1357.        if (fscale < 1)
  1358.        {
  1359.           mult = 1;
  1360.           scale = 1.0/fscale;
  1361.        }
  1362.        else
  1363.        {
  1364.           mult = 0;
  1365.           scale = fscale + 1;
  1366.        }
  1367.  
  1368.        if (zoom == 1 )
  1369.        {
  1370.            samp = 0;
  1371.            for (j = 0;  j < nsdd;  j++)
  1372.            {
  1373.                DN = buf.l[samp];
  1374.                if (DN >= DNhigh)
  1375.                    DN = DNhigh - 1;
  1376.                else
  1377.                    if (DN <= DNlow)
  1378.                        DN = DNlow;
  1379.  
  1380.                if (mult)
  1381.                    buf.b[j] = ((long)DN-DNlow) *  scale;
  1382.                else
  1383.                    buf.b[j] = ((long)DN-DNlow) /  scale;
  1384.                samp += subsample;
  1385.            }
  1386.        }
  1387.        else
  1388.        {
  1389.            j = nsd*zoom-1;
  1390.            for (samp = nsd-1;  samp >= 0;  samp--)
  1391.            {
  1392.                DN = buf.l[samp];
  1393.                if (DN >= DNhigh)
  1394.                    DN = DNhigh - 1;
  1395.                else
  1396.                    if (DN <= DNlow)
  1397.                        DN = DNlow;
  1398.                if (mult)
  1399.                    DN = ((long)DN-DNlow) *  scale;
  1400.                else
  1401.                    DN = ((long)DN-DNlow) /  scale;
  1402.  
  1403.                for (k = 1;  k <= zoom;  k++)
  1404.                   buf.b[j--] = DN;
  1405.            }
  1406.        }
  1407.  
  1408.     }
  1409.  
  1410. /* For byte images (no offset) */
  1411.  
  1412.     else if ( (bitsperpix == 8) && NoScale )
  1413.     {
  1414.         if ( (subsample == 1) && (zoom == 1) )
  1415.         {
  1416.             if (bitshift > 0)
  1417.                 for (j = 0;  j < nsdd;  j++)
  1418.                     buf.b[j] >>= bitshift;
  1419.         }
  1420.         else if (zoom == 1)
  1421.         {
  1422.             samp = 0;
  1423.             for (j = 0;  j < nsdd;  j++)
  1424.             {
  1425.                 buf.b[j] = buf.b[samp] >> bitshift;
  1426.                 samp += subsample;
  1427.             }
  1428.         }
  1429.         else
  1430.         {
  1431.             j = nsd*zoom - 1;
  1432.             for (samp = nsd-1;  samp >= 0;  samp--)
  1433.             {
  1434.                 DN = buf.b[samp] >> bitshift;
  1435.                 for (k = 1;  k <= zoom;  k++)
  1436.                     buf.b[j--] = DN;
  1437.             }
  1438.         }
  1439.     }
  1440.  
  1441.  
  1442. /* For byte images (with offset) */
  1443.  
  1444. /* scaling is done by dividing by a scale factor if the dn range specified
  1445.    is greater than the display range and by multiplying if the range
  1446.    specified is less than the display range
  1447. */
  1448.     else if ( (bitsperpix == 8) && !NoScale )
  1449.     {
  1450.        fscale = ((float)(DNhigh - DNlow) / (float)numDN);
  1451.        if (fscale < 1)
  1452.        {
  1453.            mult = 1;
  1454.            scale = 1.0/fscale;
  1455.        }
  1456.        else
  1457.        {
  1458.            mult = 0;
  1459.            scale = fscale + 1;
  1460.        }
  1461.        if (zoom == 1)
  1462.        {
  1463.            samp = 0;
  1464.            for (j = 0;  j < nsdd;  j++)
  1465.            {
  1466.                DN = buf.b[samp];
  1467.                if (DN >= DNhigh)
  1468.                    DN = DNhigh - 1;
  1469.                else
  1470.                    if (DN <= DNlow)
  1471.                        DN = DNlow;
  1472.                if (mult)
  1473.                    buf.b[j] = (DN-DNlow) *  scale;
  1474.                else
  1475.                    buf.b[j] = (DN-DNlow) /  scale;
  1476.                samp += subsample;
  1477.            }
  1478.        }
  1479.        else
  1480.        {
  1481.            j = nsd*zoom - 1;
  1482.            for (samp = nsd-1;  samp >= 0;  samp--)
  1483.            {
  1484.                DN = buf.b[samp];
  1485.                if (DN >= DNhigh)
  1486.                    DN = DNhigh - 1;
  1487.                else
  1488.                    if (DN <= DNlow)
  1489.                        DN = DNlow;
  1490.                if (mult)
  1491.                    buf.b[j] = (DN-DNlow) * scale;
  1492.                else
  1493.                    DN = (DN-DNlow) / scale;
  1494.                for (k = 1;  k <= zoom;  k++)
  1495.                {     /* 256 color bug fix - Ron Baalke - 07/15/90  */
  1496.                    if ((numDN == 256) && ((DNlow >0) || (DNhigh < 255)))
  1497.                        buf.b[j--] = (DN - DNlow) * scale;
  1498.                    else
  1499.                        buf.b[j--] = DN;
  1500.                }
  1501.            }
  1502.        }
  1503.  
  1504.     }
  1505.  
  1506.  
  1507. /*  For 4 bit and 1 bit images */
  1508.     else
  1509.     {
  1510.        absbitshift = abs(bitshift);
  1511.        ConvertLine (buf.b, tmpbuf, bitsperpix, 8, nsd, status);
  1512.        if (zoom == 1)
  1513.        {
  1514.            samp = 0;
  1515.            for (j = 0;  j < nsdd;  j++)
  1516.            {
  1517.                if (DisplayDevice == 0)
  1518.                {
  1519.                    buf.b[j] = tmpbuf[samp];
  1520.                }
  1521.                else
  1522.                {
  1523.                    buf.b[j] = tmpbuf[samp] << absbitshift;
  1524.                }
  1525.                samp += subsample;
  1526.            }
  1527.        }
  1528.        else
  1529.        {
  1530.            j = nsd*zoom - 1;
  1531.            for (samp = nsd-1;  samp >= 0;  samp--)
  1532.            {
  1533.                if (DisplayDevice == 0)
  1534.                {
  1535.                    DN = tmpbuf[samp];
  1536.                }
  1537.                else
  1538.                {
  1539.                    DN = tmpbuf[samp] << absbitshift;
  1540.                }
  1541.                for (k = 1;  k <= zoom;  k++)
  1542.                    buf.b[j--] = DN;
  1543.            }
  1544.        }
  1545.     }
  1546.     free(tmpbuf);
  1547. }
  1548.  
  1549.  
  1550. int ClearDisplay (int DN)
  1551.  
  1552. /***  ClearDisplay sets the whole display to a particular value.
  1553.       Parameter   type       description
  1554.         DN       integer     The DN value to set (usually 0)
  1555. ***/
  1556.  
  1557. {
  1558.     int      address, junk;
  1559.     unsigned char   cmd[2];
  1560.     unsigned int  i,j,segment;
  1561.     unsigned char far *faraddr;
  1562.     char     dummy[80];
  1563.     int      refresh_flag;
  1564.     int      index;
  1565.     union  REGS     inreg, outreg;
  1566.  
  1567.     /* Erase refresh buffer - Ron Baalke - 05/91 */
  1568.     GetKeywordString (CommandString, "REF", "",dummy, &refresh_flag);
  1569.     if (refresh_flag != -1)
  1570.     {
  1571.        if (RefreshLines > 0)
  1572.           EraseRefresh();
  1573.        return(0);
  1574.     }
  1575.  
  1576.     /* Erase buffers - Ron Baalke - 06/16/91 */
  1577.     strcat(CommandString," ");     /* kludge */
  1578.     GetKeywordString (CommandString, "ERA", " ",dummy, &refresh_flag);
  1579.     if ((refresh_flag)       &&
  1580.         (strlen(dummy) == 1) &&
  1581.         (dummy[0] >= 'A')    &&
  1582.         (dummy[0] <= 'Z'))
  1583.     {
  1584.        index = dummy[0] - 'A';
  1585.        DeallocBuffer(index);
  1586.        return(0);
  1587.     }
  1588.  
  1589.  
  1590.     switch (DisplayDevice)
  1591.     {
  1592.  
  1593.     case CGA200 :    /* for cga display */
  1594.           junk = 0x0FF*(DN & 1);
  1595.           for (address = 0; address < 8000;  address++)
  1596.           {
  1597.               putmem(0x0B800,address, junk);
  1598.               putmem(0x0BA00,address, junk);
  1599.           }
  1600.           return(0);
  1601.  
  1602.     case EGA350 :   /* for ega and vga displays */
  1603.     case EGA480 :   /* for ega and vga displays */
  1604.     case VGA480 :   /* for ega and vga displays */
  1605.  
  1606. #ifndef __TURBOC__
  1607.     case BIOS :     /* for ega and vga displays */
  1608. #endif
  1609.  
  1610.           ClearDisplayEGA (DN,dispnl);
  1611.           return(0);
  1612.  
  1613.     case ATI640 :
  1614.     case ATI800 :
  1615.     case ATI1024:
  1616.  
  1617.            if (DisplayDevice == ATI640)
  1618.                j = 5;
  1619.            else
  1620.                j = 8;
  1621.  
  1622.            faraddr  = (unsigned char far *) 0x0a0000000L ;
  1623.            for (i=0; i < j; i++)
  1624.            {
  1625.                atibank = i;
  1626.                ATI_Bank();
  1627.                memset(faraddr,DN,(size_t)32768);
  1628.                memset(faraddr+32768L,DN,(size_t)32768);
  1629.            }
  1630.            return(0);
  1631.  
  1632.     case PGA :
  1633.  
  1634.           cmd[0] = 0x0F;  cmd[1] = DN;
  1635.           PGAsend (cmd, 2);
  1636.           return(0);
  1637.  
  1638.     case VGA200 :   /* for ega and vga displays */
  1639.     case ORCHID480 :      /* for orchid designer */
  1640.     case ORCHID600 :      /* for orchid designer */
  1641.     case ORCHID768 :      /* for orchid designer */
  1642.  
  1643.           faraddr  = (unsigned char far *) 0x0a0000000L ;
  1644.           for (i = 0; i < 5; i++)
  1645.           {
  1646.              outp(0x3cd,0x40 | i);
  1647.              memset(faraddr,'\0',(size_t)32768);
  1648.              memset(faraddr+32768L,'\0',(size_t)32768);
  1649.           }
  1650.  
  1651.           if (dispnl > 480)
  1652.             for (i = 5; i < 8; i++)
  1653.             {
  1654.                outp(0x3cd,0x40 | i);
  1655.                memset(faraddr,'\0',(size_t)32768);
  1656.                memset(faraddr+32768L,'\0',(size_t)32768);
  1657.             }
  1658.  
  1659. /* Added for Orchid with 1MB,  March 1991, Ron Baalke */
  1660.           if (dispnl >= 768)
  1661.             for (i = 8; i < 12; i++)
  1662.             {
  1663.                outp(0x3cd,0x40 | i);
  1664.                memset(faraddr,'\0',(size_t)32768);
  1665.                memset(faraddr+32768L,'\0',(size_t)32768);
  1666.             }
  1667.  
  1668.           return(0);
  1669.  
  1670.     case EVGA640 :    /* for ega and vga displays */
  1671.     case EVGA512 :    /* for ega and vga displays */
  1672.     case EVGA800 :    /* for ega and vga displays */
  1673.  
  1674.           EVGAClearDisplay(DN);
  1675.           return(0);
  1676.  
  1677.     case PARADISE:
  1678.  
  1679.           ClearDisplayPAR(DN);
  1680.           return(0);
  1681.  
  1682.    case TRIDENT :
  1683.  
  1684.           ClearDisplayTRI(DN);
  1685.           return(0);
  1686.  
  1687.     case VESA :       /* VESA SVGA Driver  */
  1688.  
  1689.            faraddr  = (unsigned char far *) 0x0a0000000L ;
  1690.            for (i = 0; i < 12; i++)
  1691.            {
  1692.  
  1693.                VESA_Set_Page (i);
  1694.  
  1695.                memset(faraddr,'\0',(size_t)32768);
  1696.                memset(faraddr+32768L,'\0',(size_t)32768);
  1697.            }
  1698.            return(0);
  1699.  
  1700.     case VESA800 :       /* VESA SVGA Driver  */
  1701.  
  1702.            faraddr  = (unsigned char far *) 0x0a0000000L ;
  1703.            for (i = 0; i < 8; i++)
  1704.            {
  1705.  
  1706.                VESA_Set_Page (i);
  1707.  
  1708.                memset(faraddr,'\0',(size_t)32768);
  1709.                memset(faraddr+32768L,'\0',(size_t)32768);
  1710.            }
  1711.            return(0);
  1712.  
  1713.  
  1714.     case VESA640 :       /* VESA SVGA Driver  */
  1715.  
  1716.            faraddr  = (unsigned char far *) 0x0a0000000L ;
  1717.            for (i = 0; i < 5; i++)
  1718.            {
  1719.  
  1720.                VESA_Set_Page (i);
  1721.  
  1722.                memset(faraddr,'\0',(size_t)32768);
  1723.                memset(faraddr+32768L,'\0',(size_t)32768);
  1724.            }
  1725.            return(0);
  1726.  
  1727.     case EV629 :       /* for Everex EV-629 24-bit board  */
  1728.  
  1729.            faraddr  = (unsigned char far *) 0x0a0000000L ;
  1730.            for (i = 0; i < 12; i++)
  1731.            {
  1732.  
  1733.                VESA_Set_Page (i);
  1734.  
  1735.                memset(faraddr,'\0',(size_t)32768);
  1736.                memset(faraddr+32768L,'\0',(size_t)32768);
  1737.            }
  1738.            return(0);
  1739.     }
  1740. }
  1741.  
  1742.  
  1743. int PGAreceive (unsigned char * answer, int * p_len)
  1744. /*
  1745.     This routine receives data from the PGA device.
  1746.     Only used by ReadPixel routine.
  1747. */
  1748.  
  1749. {
  1750.     unsigned char   i, InWritePtr, InReadPtr, numbytes;
  1751.  
  1752.     do
  1753.     {
  1754.         InReadPtr  = getmem (0x0C600,0x0303);
  1755.         InWritePtr = getmem (0x0C600,0x0302);
  1756.         numbytes   = InWritePtr - InReadPtr;
  1757.     } while (numbytes == 0);
  1758.  
  1759.     for (i = 0; i < numbytes; i++)
  1760.        answer[i] = getmem (0x0C610,InReadPtr++);
  1761.  
  1762.     putmem (0x0C600, 0x0303, InReadPtr);
  1763.     *p_len = numbytes;
  1764. }
  1765.  
  1766. /*
  1767. Function:
  1768.          Determining the Tseng chip
  1769.  
  1770. Output parameters:
  1771.         identity    integer containing the chip code
  1772.                                                      3000 = ET3000
  1773.                                                      4000 = ET4000
  1774.  
  1775. Calling Protocol:
  1776.         identity = Which_Tseng() */
  1777.  
  1778.  
  1779. int Which_Tseng()
  1780. {
  1781.    int base;
  1782.    unsigned    char    new_value, old_value, value;
  1783.  
  1784.    if ( (inp(0x3CC) & 0x01) == 1)
  1785.        base = 0x3D0;
  1786.    else
  1787.        base = 0x3B0;
  1788.  
  1789. /* get old value */
  1790.    outp(base+4, 0x33);
  1791.    old_value = inp(base+5);
  1792.  
  1793. /* change value */
  1794.    value = old_value ^ 0x0f;
  1795.    outp(base+5, value);
  1796.    new_value = inp(base+5);
  1797.  
  1798. /* restore old value */
  1799.    outp(base+5, old_value);
  1800.  
  1801.    if (new_value == value)
  1802.        return(4000);
  1803.    else
  1804.        return(3000);
  1805. }
  1806.