home *** CD-ROM | disk | FTP | other *** search
- /*************************************************************/
- /* Copyright (C) 1989, California Institute of Technology */
- /* U. S. Government Sponsorship under NASA Contract */
- /* NAS7-918 is acknowledged. */
- /*************************************************************/
-
- /*** IMDISP module DISPIO.C
-
- DISPIO contains the device dependent display routines for the
- Color Graphics Adapter (CGA), the Enhanced Graphics Adapter (EGA),
- the Professional Graphics Adapter (PGA) and the Video Graphics Array
- (VGA). The global variables that define the device are allocated
- and initialized here.
-
- ***/
-
- /* * * * INCLUDE files * * * */
-
- #include <conio.h>
- #include <dos.h>
- #include <graph.h>
- #include <malloc.h>
- #include <math.h>
- #include <memory.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include "imdef.h"
- #include "imdisp.h"
- #include "disputil.h"
- #include "evgaio.h"
- #include "refresh.h"
- #include "ativga.h"
- #include "dispsub.h"
- #include "paradise.h"
-
- /* * * * Defined Constants * * * */
- #define CGA 0
- #define EGA350 1
- #define PGA 2
- #define VGA480 3
- #define VGA200 4
- #define BIOS 5
- #define ORCHID480 6
- #define ORCHID600 7
- #define EVGA640 8
- #define EVGA512 9
- #define EVGA800 10
- #define EGA480 11
- #define ATI640 12
- #define ATI800 13
- #define ATI1024 14
- #define PARADISE 15
- #define ORCHID768 16
-
- /* * * * External functions * * * */
-
- /* * * * Function declarations * * * */
-
- int DisplayOn (void);
- int DisplayOff (void);
- int ReadPalette (struct Color *);
- int WritePalette (struct Color *);
- int WritePixel (int, int, int);
- int ReadPixel (int, int, int *);
- int DisplayLine (unsigned char *,int ,int ,int );
- int FormatLine (unsigned char *, int, int, int, int, char *);
- int ClearDisplay (int );
- int PGAreceive (unsigned char *, int *);
-
- /* * * * Global Variables * * * */
-
- int atibank;
-
- /*
- DisplayDevice indicates the type of display (CGA=0, EGA=1, PGA=2, etc).
- dispnl is the number of lines in the display.
- dispns is the number of samples in the display.
- numDN is the number of unique pixel values (e.g. 4 bits ->
- numDN=16).
- numshades is the number of shades each of red, green, and blue
- (e.g. numshades=16 gives 16**3 = 4096 possible colors).
- OneScreen is true if there is only one screen, i.e. there is not
- image screen and a text screen.
- */
-
- int DisplayDevice, dispnl, dispns, numDN, numshades, OneScreen;
-
- struct Color
- /*
- This is the structure for the color palette.
- The current palette is stored in PaletteTable.
- */
- {
- unsigned char r, g, b;
- } DefaultPalette[256], PaletteTable[256];
-
-
- int DisplayOn(void)
-
- /***
- DisplayOn figures out which display device is on the system and then
- initializes for that device. The device is turned on. The global
- variables that define the display characteristics and the default
- color palette are initialized. The refresh buffer is zeroed.
- ***/
-
- {
- int i;
- unsigned char cmd[7], EVGApalette[17];
- union REGS inreg, outreg;
- struct SREGS segregs;
- struct Color DP[16];
-
- /* Test for Enhanced Graphics Adapter (EGA) */
- if (DisplayDevice == CGA)
- {
- inreg.x.ax = 0x1200;
- inreg.x.bx = 0x0FF10;
- inreg.x.cx = 0x000F;
- int86 (0x10, &inreg, &outreg);
- if ( (outreg.h.cl < 0x0C) && (outreg.h.bh <= 1) && (outreg.h.bl <= 3) )
- DisplayDevice = EGA350;
- }
-
- /* moved from before ega test to avoid conflicts with memory boards*/
- /* mdm 2-19-88 */
-
- /* Test for Professional Graphics Adapter (PGA) */
- /* if (DisplayDevice == CGA && devname == NULL) */
- if (DisplayDevice == CGA)
- {
- putmem (0x0C000, 0x63DB, 0x0AD);
- if (getmem (0x0C000, 0x63DB) == 0x0AD)
- DisplayDevice = PGA;
- }
-
- /* Initialize for the appropriate device */
- switch (DisplayDevice)
- {
- case CGA : /* for standard cga display */
-
- dispnl = 200;
- dispns = 640;
- numDN = 2;
- numshades = 2;
- OneScreen = 1;
- _setvideomode( _HRESBW );
- DefaultPalette[0].r = 0; DefaultPalette[1].r = 255;
- DefaultPalette[0].g = 0; DefaultPalette[1].g = 255;
- DefaultPalette[0].b = 0; DefaultPalette[1].b = 255;
- break;
-
- case EGA350 : /* for standard ega displays */
-
- dispnl = 350;
- dispns = 640;
- numDN = 16;
- numshades = 4;
- OneScreen = 1;
- _setvideomode( _ERESCOLOR );
-
- DP[0].r = 32; DP[0].g = 32; DP[0].b = 32;
- DP[1].r = 96; DP[1].g = 32; DP[1].b = 32;
- DP[2].r = 160; DP[2].g = 32; DP[2].b = 32;
- DP[3].r = 224; DP[3].g = 32; DP[3].b = 32;
- DP[4].r = 224; DP[4].g = 96; DP[4].b = 32;
- DP[5].r = 224; DP[5].g = 160; DP[5].b = 32;
- DP[6].r = 224; DP[6].g = 224; DP[6].b = 32;
- DP[7].r = 160; DP[7].g = 224; DP[7].b = 32;
- DP[8].r = 32; DP[8].g = 224; DP[8].b = 32;
- DP[9].r = 32; DP[9].g = 224; DP[9].b = 160;
- DP[10].r = 32; DP[10].g = 160; DP[10].b = 160;
- DP[11].r = 32; DP[11].g = 160; DP[11].b = 224;
- DP[12].r = 32; DP[12].g = 32; DP[12].b = 224;
- DP[13].r = 160; DP[13].g = 32; DP[13].b = 224;
- DP[14].r = 224; DP[14].g = 32; DP[14].b = 224;
- DP[15].r = 224; DP[15].g = 224; DP[15].b = 224;
- for (i = 0; i <= 15; i++)
- {
- DefaultPalette[i].r = DP[i].r;
- DefaultPalette[i].g = DP[i].g;
- DefaultPalette[i].b = DP[i].b;
- }
-
- break;
-
- case EGA480 : /* for extended ega displays */
-
- /* if environment variable EGA480 is not null, then
- initialize for 480 line mode. Requires crystal
- upgrade on EGA board and multisync monitor. */
-
- dispnl = 480;
- dispns = 640;
- numDN = 16;
- numshades = 4;
- OneScreen = 1;
- egainit(); /* special init routines in dispsub.asm */
-
- DP[0].r = 32; DP[0].g = 32; DP[0].b = 32;
- DP[1].r = 96; DP[1].g = 32; DP[1].b = 32;
- DP[2].r = 160; DP[2].g = 32; DP[2].b = 32;
- DP[3].r = 224; DP[3].g = 32; DP[3].b = 32;
- DP[4].r = 224; DP[4].g = 96; DP[4].b = 32;
- DP[5].r = 224; DP[5].g = 160; DP[5].b = 32;
- DP[6].r = 224; DP[6].g = 224; DP[6].b = 32;
- DP[7].r = 160; DP[7].g = 224; DP[7].b = 32;
- DP[8].r = 32; DP[8].g = 224; DP[8].b = 32;
- DP[9].r = 32; DP[9].g = 224; DP[9].b = 160;
- DP[10].r = 32; DP[10].g = 160; DP[10].b = 160;
- DP[11].r = 32; DP[11].g = 160; DP[11].b = 224;
- DP[12].r = 32; DP[12].g = 32; DP[12].b = 224;
- DP[13].r = 160; DP[13].g = 32; DP[13].b = 224;
- DP[14].r = 224; DP[14].g = 32; DP[14].b = 224;
- DP[15].r = 224; DP[15].g = 224; DP[15].b = 224;
- for (i = 0; i <= 15; i++)
- {
- DefaultPalette[i].r = DP[i].r;
- DefaultPalette[i].g = DP[i].g;
- DefaultPalette[i].b = DP[i].b;
- }
-
- break;
-
- case EVGA800 : /* for Everex EV-673 hi-res ega mode */
-
- dispns = 800;
- dispnl = 600;
- numDN = 16;
- numshades = 4;
- OneScreen = 1;
- inreg.x.ax = 0x0070; /* turn on EVGA MODE */
- inreg.x.bx = 0x0002; /* at 800x600 res */
- int86 (0x10, &inreg, &outreg);
-
- DP[0].r = 32; DP[0].g = 32; DP[0].b = 32;
- DP[1].r = 96; DP[1].g = 32; DP[1].b = 32;
- DP[2].r = 160; DP[2].g = 32; DP[2].b = 32;
- DP[3].r = 224; DP[3].g = 32; DP[3].b = 32;
- DP[4].r = 224; DP[4].g = 96; DP[4].b = 32;
- DP[5].r = 224; DP[5].g = 160; DP[5].b = 32;
- DP[6].r = 224; DP[6].g = 224; DP[6].b = 32;
- DP[7].r = 160; DP[7].g = 224; DP[7].b = 32;
- DP[8].r = 32; DP[8].g = 224; DP[8].b = 32;
- DP[9].r = 32; DP[9].g = 224; DP[9].b = 160;
- DP[10].r = 32; DP[10].g = 160; DP[10].b = 160;
- DP[11].r = 32; DP[11].g = 160; DP[11].b = 224;
- DP[12].r = 32; DP[12].g = 32; DP[12].b = 224;
- DP[13].r = 160; DP[13].g = 32; DP[13].b = 224;
- DP[14].r = 224; DP[14].g = 32; DP[14].b = 224;
- DP[15].r = 224; DP[15].g = 224; DP[15].b = 224;
- for (i = 0; i <= 15; i++)
- {
- DefaultPalette[i].r = DP[i].r;
- DefaultPalette[i].g = DP[i].g;
- DefaultPalette[i].b = DP[i].b;
- }
-
- break;
-
- case VGA480 : /* for standard vga displays */
- case BIOS : /* for standard vga displays */
-
- dispnl = 480;
- dispns = 640;
- numDN = 16;
- numshades = 64;
- OneScreen = 1;
- _setvideomode( _VRES16COLOR );
-
- /* load default gray level palette with 17 dn increments */
- for (i = 0; i <= 15; i++)
- {
- DefaultPalette[i].r = i*16+i;
- DefaultPalette[i].g = i*16+i;
- DefaultPalette[i].b = i*16+i;
- }
- break;
-
- case PGA: /* for standard pga display */
-
- dispnl = 480;
- dispns = 640;
- numDN = 256;
- numshades = 16;
- OneScreen = 1;
-
- cmd[0] = 0x43; cmd[1] = 0x58; cmd[2] = 0x20;
- cmd[3] = 0x0D0; cmd[4] = 0x00;
- cmd[5] = 0x0F; cmd[6] = 0x00;
- PGAsend (cmd, 7); /* 'CA DISPLA 0 CLEARS 0 ' */
-
- for (i = 0; i <= 255; i++)
- {
- DefaultPalette[i].r = i;
- DefaultPalette[i].g = i;
- DefaultPalette[i].b = i;
- }
- break;
-
- case ORCHID480 : /* for Orchid ProDesigner enhanced VGA mode */
-
- dispnl = 480;
- dispns = 640;
- numDN = 256;
- numshades = 64;
- OneScreen = 1;
- inreg.x.ax = 0x002E; /* set 256 color 640 x480 mode */
- int86 (0x10, &inreg, &outreg);
- inreg.x.ax = 0x0500; /* select page */
- int86 (0x10, &inreg, &outreg);
-
- for (i = 0; i <= 255; i++)
- {
- DefaultPalette[i].r = i;
- DefaultPalette[i].g = i;
- DefaultPalette[i].b = i;
- }
- break;
-
- case ORCHID600 : /* for Orchid ProDesigner+ with 512K */
-
- dispnl = 600;
- dispns = 800;
- numDN = 256;
- numshades = 64;
- OneScreen = 1;
- inreg.x.ax = 0x0030; /* set 256 color 800 x 600 mode */
- int86 (0x10, &inreg, &outreg);
- inreg.x.ax = 0x0500; /* select page */
- int86 (0x10, &inreg, &outreg);
-
- for (i = 0; i <= 255; i++)
- {
- DefaultPalette[i].r = i;
- DefaultPalette[i].g = i;
- DefaultPalette[i].b = i;
- }
- break;
-
- case ORCHID768 : /* for Orchid ProDesigner+ with 1024K */
-
- dispnl = 768;
- dispns = 1024;
- numDN = 256;
- numshades = 64;
- OneScreen = 1;
- inreg.x.ax = 0x0038; /* set 256 color 1024 x 768 mode */
- int86 (0x10, &inreg, &outreg);
- inreg.x.ax = 0x0500; /* select page */
- int86 (0x10, &inreg, &outreg);
-
- for (i = 0; i <= 255; i++)
- {
- DefaultPalette[i].r = i;
- DefaultPalette[i].g = i;
- DefaultPalette[i].b = i;
- }
- break;
-
- case VGA200 : /* for standard VGA displays */
-
- dispnl = 200;
- dispns = 320;
- numDN = 256;
- numshades = 64;
- OneScreen = 1;
- _setvideomode( _MRES256COLOR );
- for (i = 0; i <= 255; i++)
- {
- DefaultPalette[i].r = i;
- DefaultPalette[i].g = i;
- DefaultPalette[i].b = i;
- }
- break;
-
- case EVGA640 : /* for Everex EV-673 enhanced vga mode */
-
- dispns = 640;
- dispnl = 400;
- numDN = 256;
- numshades = 64;
- OneScreen = 1;
- inreg.x.ax = 0x0070;
- inreg.x.bx = 0x0014;
- int86 (0x10, &inreg, &outreg);
- for (i = 0; i <= 255; i++)
- {
- DefaultPalette[i].r = i;
- DefaultPalette[i].g = i;
- DefaultPalette[i].b = i;
- }
- EVGASetPage(0);
- break;
-
- case EVGA512 : /* for Everex EV-673 almost image proc mode */
-
- dispns = 512;
- dispnl = 480;
- numDN = 256;
- numshades = 64;
- OneScreen = 1;
- inreg.x.ax = 0x0070;
- inreg.x.bx = 0x0015;
- int86 (0x10, &inreg, &outreg);
- for (i = 0; i <= 255; i++)
- {
- DefaultPalette[i].r = i;
- DefaultPalette[i].g = i;
- DefaultPalette[i].b = i;
- }
- EVGASetPage(0);
- break;
-
- case ATI640: /* for ATI VGA Wonder */
-
- dispns = 640;
- dispnl = 480;
- numDN = 256;
- numshades = 16;
- OneScreen = 1;
-
- ATI_Init();
-
- for (i = 0; i <= 255; i++)
- {
- DefaultPalette[i].r = i;
- DefaultPalette[i].g = i;
- DefaultPalette[i].b = i;
- }
- break;
-
- case ATI800: /* for ATI VGA Wonder */
-
- dispns = 800;
- dispnl = 600;
- numDN = 256;
- numshades = 16;
- OneScreen = 1;
-
- ATI_Init();
-
- for (i = 0; i <= 255; i++)
- {
- DefaultPalette[i].r = i;
- DefaultPalette[i].g = i;
- DefaultPalette[i].b = i;
- }
- break;
-
- case ATI1024: /* for ATI VGA Wonder */
-
- dispns = 1024;
- dispnl = 768;
- numDN = 16;
- numshades = 4;
- OneScreen = 1;
-
- ATI_Init();
-
- /* load default gray level palette */
- for (i = 0; i <= 255; i++)
- {
- DefaultPalette[i].r = i;
- DefaultPalette[i].g = i;
- DefaultPalette[i].b = i;
- }
- break;
-
- case PARADISE : /* for SUPER VGA board */
-
- dispnl = 480;
- dispns = 640;
- numDN = 256;
- numshades = 64;
- OneScreen = 1;
- inreg.x.ax=0x007F; /*BIOS check on board memory */
- inreg.x.bx=0x0200;
- int86 (0x10, &inreg, &outreg);
- if(outreg.h.ch >= 5) /*return number of 64k units */
- {
- inreg.x.ax = 0x005F; /*we have at least 309k for this mode */
- int86 (0x10, &inreg, &outreg); /*set 256 color 640 x480 mode */
- }
- else
- {
- inreg.x.ax = 0x005E; /*board has only 256k of memory */
- int86 (0x10, &inreg, &outreg); /*set 256 color 640 x400 mode */
- dispnl=400;
- }
- for (i = 0; i <= 255; i++)
- {
- DefaultPalette[i].r = i;
- DefaultPalette[i].g = i;
- DefaultPalette[i].b = i;
- }
- break;
-
-
- }
- /*
- i = 0;
-
- while ( ((RefreshBuf[i] = (unsigned char *) calloc( dispns, sizeof(char)) ) != NULL)
- && (i < dispnl) ) i++;
- if (i == dispnl)
- RefreshLines = i + 1;
- else
- RefreshLines = i;
- */
- RefreshLines = AllocRefresh();
-
- if (dispnl >= 768)
- {
- TextHeight = 15;
- BigChars = 20;
- SmallChars = 12;
- }
- else if (dispnl >= 600)
- {
- TextHeight = 12;
- BigChars = 15;
- SmallChars = 10;
- }
- else if (dispnl >= 480)
- {
- TextHeight = 9;
- BigChars = 12;
- SmallChars = 6;
- }
- else if (dispnl >= 400)
- {
- TextHeight = 8;
- BigChars = 12;
- SmallChars = 6;
- }
- else if (dispnl >= 350)
- {
- TextHeight = 8;
- BigChars = 10;
- SmallChars = 6;
- }
- else
- {
- TextHeight = 6;
- BigChars = 8;
- SmallChars = 5;
- }
-
- }
-
-
- int DisplayOff(void)
-
- /***
- DisplayOff turns off the display device returning the screen
- to text mode.
- ***/
-
- {
- unsigned char cmd[2];
- union REGS inreg, outreg;
- int i;
-
- switch (DisplayDevice)
- {
- case BIOS : /* for plain vga display */
- case CGA : /* for cga display */
- case EGA350 : /* for ega and vga displays */
- case VGA480 : /* for ega and vga displays */
- case VGA200 : /* for ega and vga displays */
- case EGA480 : /* for enhanced ega */
- case EVGA640 : /* for Everex EVGA */
- case EVGA512 : /* for Everex EVGA */
- case EVGA800 : /* for Everex EVGA */
- case ATI640 : /* For ATI VGA Wonder */
- case ATI800 : /* For ATI VGA Wonder */
- case ATI1024 : /* For ATI VGA Wonder */
- case PARADISE : /* for Paradise Super VGA */
-
- _setvideomode( _DEFAULTMODE );
- break;
-
- case ORCHID480 : /* for orchid designer */
- case ORCHID600 : /* for orchid designer */
- case ORCHID768 : /* for orchid designer */
-
- ClearDisplay( 0 ); /* Keep Seiko monitor from */
- /* shutting off */
- inreg.x.ax = 0x0003;
- int86 (0x10, &inreg, &outreg);
- break;
-
-
- case PGA: /* for pga display */
-
- cmd[0] = 0x0D0; cmd[1] = 1;
- PGAsend (cmd, 2); /* 'DISPLA 1' */
- break;
-
- }
- OneScreen = 0;
-
- /* clear out the refreshbuffer */
- for (i = 0; i < RefreshLines; i++)
- free (RefreshBuf[i]);
- RefreshLines = 0;
- }
-
- int ReadPalette (struct Color * coltab)
-
- /*** ReadPalette returns the current color palette in coltab.
- coltab is of type Color.
- ***/
-
- {
- int i;
-
- for (i = 0; i < numDN; i++)
- {
- coltab[i].r = PaletteTable[i].r;
- coltab[i].g = PaletteTable[i].g;
- coltab[i].b = PaletteTable[i].b;
- }
- }
-
- int WritePalette (struct Color * coltab)
-
- /***
- WritePalette updates the display device palette with the
- palette passed in coltab. coltab must be of type Color.
- ***/
-
- {
- int i;
- unsigned char cmd[5], red, green, blue;
- long pal_color;
- union REGS inreg, outreg;
- struct SREGS segregs;
- struct Color DP[256];
- unsigned int x,y;
- unsigned char *colors, palbuf[256][3];
-
- for (i = 0; i < numDN; i++)
- {
- PaletteTable[i].r = coltab[i].r;
- PaletteTable[i].g = coltab[i].g;
- PaletteTable[i].b = coltab[i].b;
- }
-
- switch (DisplayDevice)
- {
- case EGA350 : /* for ega displays */
- case EGA480 : /* for ega displays */
- case EVGA800 : /* for Everex EVGA */
-
- for (i = 0; i <= 15; i++)
- {
- /* Old ega palette routine. Changed to DISPLAY.LIB routine to see
- it fixes problems with original IBM EGA.
- inreg.x.ax = 0x1010;
- inreg.x.bx = i;
- inreg.h.dh = coltab[i].r/4;
- inreg.h.ch = coltab[i].g/4;
- inreg.h.cl = coltab[i].b/4;
- int86 (0x10, &inreg, &outreg);
- */
- red = (coltab[i].r >> 2) & 0x3f;
- green = (coltab[i].g >> 2) & 0x3f;
- blue = (coltab[i].b >> 2) & 0x3f;
- pal_color = ( ((long)blue) << 16)
- | ( ((long)green) << 8)
- | ((long)red) ;
- _remappalette( i, pal_color) ;
- }
- return;
-
- case VGA480 : /* for vga displays */
-
- for (i = 0; i <= 15; i++)
- {
- palbuf[i][0] = (coltab[i].r >> 2) & 0xff;
- palbuf[i][1] = (coltab[i].g >> 2) & 0xff;
- palbuf[i][2] = (coltab[i].b >> 2) & 0xff;
- }
- colors = &palbuf[0][0];
- segregs.es = FP_SEG( colors );
- inreg.x.dx = FP_OFF( colors );
- inreg.x.ax = 0x1012;
- inreg.x.bx = 0x0;
- inreg.x.cx = 16;
- int86x(0x10, &inreg, &outreg, &segregs);
- return;
-
- case BIOS : /* for vga displays */
-
- for (i = 0; i <= 15; i++)
- {
- red = (coltab[i].r >> 2) & 0x3f;
- green = (coltab[i].g >> 2) & 0x3f;
- blue = (coltab[i].b >> 2) & 0x3f;
- pal_color = ( ((long)blue) << 16)
- | ( ((long)green) << 8)
- | ((long)red) ;
- _remappalette( i, pal_color) ;
- }
- return;
-
- case VGA200 : /* for vga displays */
- case ORCHID480 : /* for orchid designer */
- case ORCHID600 : /* for orchid designer */
- case ORCHID768 : /* for orchid designer */
- case EVGA640 : /* for Everex EVGA */
- case EVGA512 : /* for Everex EVGA */
- case PARADISE :
-
- for (i = 0; i <= 255; i++)
- {
-
- palbuf[i][0] = (coltab[i].r >> 2) & 0xff;
- palbuf[i][1] = (coltab[i].g >> 2) & 0xff;
- palbuf[i][2] = (coltab[i].b >> 2) & 0xff;
- }
- colors = &palbuf[0][0];
- segregs.es = FP_SEG( colors );
- inreg.x.dx = FP_OFF( colors );
- inreg.x.ax = 0x1012;
- inreg.x.bx = 0x0;
- inreg.x.cx = 256;
- int86x(0x10, &inreg, &outreg, &segregs);
- return;
-
- case PGA : /* for pga display */
- for (i = 0; i <= 255; i++)
- {
- cmd[0] = 0x0EE;
- cmd[1] = i;
- cmd[2] = coltab[i].r >> 4;
- cmd[3] = coltab[i].g >> 4;
- cmd[4] = coltab[i].b >> 4;
- PGAsend (cmd, 5); /* 'LUT numcol red green blue' */
- }
- return;
-
- case ATI640 : /* for ATI VGA Wonder */
- case ATI800 : /* for ATI VGA Wonder */
- case ATI1024: /* for ATI VGA Wonder */
-
- for(i=0;i<256;i++)
- {
- palbuf[i][0] = (coltab[i].r >> 2) & 0xff;
- palbuf[i][1] = (coltab[i].g >> 2) & 0xff;
- palbuf[i][2] = (coltab[i].b >> 2) & 0xff;
- }
- ATI_WritePalette(palbuf,0,256);
- return ;
-
- }
- }
-
- int WritePixel (int line, int sample, int DN)
-
- /*** WritePixel writes a pixel on the display screen.
- Parameter type description
- line integer The line coordinate of the pixel
- sample integer The sample coordinate of the pixel
- DN integer The DN value of the pixel
- ***/
-
- {
- unsigned int x, y;
- unsigned int segment;
- unsigned long laddress;
- int address, bit, mask, useBIOS;
- unsigned char cmd[9];
- unsigned char far *faraddr;
- unsigned int color;
-
- switch (DisplayDevice)
- {
-
- case CGA : /* for cga display */
-
- line--;
- sample--;
- bit = 7 - (sample & 7);
- DN = (DN & 1) << bit;
- mask = ~(1 << bit);
-
- if ((line & 1) == 0)
- address = 0x8000 + 40*line + (sample >> 3);
- else
- address = 0x0A000 + 40*(line-1) + (sample >> 3);
- putmem (0x0B000, address, (getmem(0xB000,address) & mask) | DN);
- return;
-
- case EGA350 : /* for ega and vga displays */
- case EGA480 : /* for ega and vga displays */
- case VGA480 : /* for ega and vga displays */
- case BIOS : /* for ega and vga displays */
-
- WritePixelEGA (line, sample, DN);
- return;
-
- case PGA : /* for pga display */
-
- x = sample - 1;
- y = 480 - line;
- cmd[0] = 0x0D9;
- cmd[1] = y; cmd[2] = y >> 8;
- cmd[3] = x; cmd[4] = x >> 8;
- cmd[5] = x; cmd[6] = x >> 8;
- cmd[7] = 0; cmd[8] = DN;
- PGAsend (cmd, 9); /* 'IMAGEW y x x ' */
- return;
-
- case VGA200 : /* for ega and vga displays */
- case ORCHID480 : /* for orchid designer */
- case ORCHID600 : /* for orchid designer */
- case ORCHID768 : /* for orchid designer */
-
- laddress = ((long)dispns*(long)(line-1))+(long)(sample-1);
- segment = laddress >> 16;
- laddress = laddress & 0x0FFFF;
- faraddr = (unsigned char far *) (0x0a0000000L + laddress);
- outp(0x3cd,0x40 | segment);
- *(faraddr) = (unsigned char)DN;
- return;
-
- case EVGA640 : /* for Everex EVGA */
- case EVGA512 : /* for Everex EVGA */
-
- EVGAWritePixel256(sample, line, DN);
- /*
- laddress = ((long)dispns*(long)(line-1))+(long)(sample-1);
- segment = laddress >> 0x10;
- laddress = laddress & 0xFFFF;
- EVGASetPage(segment);
- faraddr = (unsigned char far *) (0xA0000000 + laddress);
- *(faraddr) = (unsigned char)DN;
- */
- return ;
-
- case EVGA800 : /* for Everex EVGA */
-
- useBIOS = 0;
- EVGAWritePixelEGA (sample, line, DN, useBIOS);
- return ;
-
- case ATI640 : /* for ATI VGA Wonder */
- case ATI800 : /* for ATI VGA Wonder */
- case ATI1024: /* for ATI VGA Wonder */
-
- x = (unsigned int) sample;
- y = (unsigned int) line;
- color = (unsigned int) DN;
-
- ATI_WritePixel(x,y,color);
- return ;
-
- case PARADISE : /* for Super VGA */
-
- WritePixelPAR (line-1, sample-1, DN);
- outp( 0x3ce, 0x0000f); /* added - mwm */
- return;
-
- }
- }
-
- int ReadPixel (int line, int sample, int * p_DN)
-
- /*** ReadPixel read a pixel value from the display screen.
- Parameter type description
- line integer The line coordinate of the pixel
- sample integer The sample coordinate of the pixel
- p_DN int ptr The DN value of the pixel is returned
- **/
-
- {
- int address, y, x, mask, bit;
- int len;
- unsigned int segment;
- unsigned long laddress;
- unsigned char cmd[256];
- unsigned char far *faraddr;
-
- switch (DisplayDevice)
- {
- case CGA : /* for cga display */
-
- line--;
- sample--;
- bit = 7 - (sample & 7);
-
- if ((line & 1) == 0)
- address = 0x8000 + 40*line + (sample >> 3);
- else
- address = 0x0A000 + 40*(line-1) + (sample >> 3);
-
- *p_DN = (getmem(0x0B000,address) & (1 << bit)) >> bit;
- return;
-
- case EGA350 : /* for ega and vga displays */
- case EGA480 : /* for ega and vga displays */
- case VGA480 : /* for ega and vga displays */
- case BIOS : /* for ega and vga displays */
- case EVGA640 : /* for Everex EVGA */
- case EVGA512 : /* for Everex EVGA */
- case EVGA800 : /* for Everex EVGA */
-
- y = line - 1;
- x = sample - 1;
- address = (y << 6) + (y << 4) + (x >> 3);
- mask = 0x80 >> (x & 7);
- *p_DN = 0;
- for (bit = 3; bit >= 0; bit--)
- {
- outp (0x3CE, 4);
- outp (0x3CF, bit);
- if ( (getmem (0x0A000,address) & mask) > 0 )
- *p_DN = (*p_DN << 1) | 1;
- else
- *p_DN = *p_DN << 1;
- }
- return;
-
- case ATI640 : /* for ATI VGA Wonder */
- case ATI800 : /* for ATI VGA Wonder */
- case ATI1024: /* for ATI VGA Wonder */
-
- *p_DN = ATI_ReadPixel(sample,line);
- return;
-
- case PGA : /* for pga display */
-
- x = sample - 1; y = 480 - line;
- cmd[0] = 0x0D8;
- cmd[1] = y; cmd[2] = y >> 8;
- cmd[3] = x; cmd[4] = x >> 8;
- cmd[5] = x; cmd[6] = x >> 8;
- PGAsend (cmd, 7); /* 'IMAGER y x x ' */
- for (x = 0; x < 1000; x++) ; /* delay loop */
- PGAreceive (cmd, &len);
- *p_DN = cmd[8];
- return;
-
- case VGA200 : /* for ega and vga displays */
- case ORCHID480 : /* for orchid designer */
- case ORCHID600 : /* for orchid designer */
- case ORCHID768 : /* for orchid designer */
-
- laddress = ((long)dispns*(long)(line-1))+(long)(sample-1);
- segment = laddress >> 16;
- laddress = laddress & 0x0FFFF;
- faraddr = (unsigned char far *) (0x0a0000000L + laddress);
- outp(0x3cd,0x40 | segment << 3);
- *p_DN = *(faraddr);
- return;
-
- case PARADISE : /* for Super VGA */
-
- ReadPixelPAR(line-1,sample-1,p_DN);
- *p_DN &= 0xFF; /* Remove garbage - mwm */
- return;
-
- }
- }
-
- int DisplayLine (unsigned char * buffer, int line, int sample, int ns)
-
- /*** DisplayLine writes a line of pixels on the display screen.
- Parameter type description
- buffer char ptr The array of pixel values
- line integer The line coordinate of the first pixel
- sample integer The sample coordinate of the first pixel
- ns integer The number of pixels to display
- ***/
-
- {
- unsigned char cmd[7];
- unsigned int x,y, x1, x2, len, s;
- int i, address, mask, bit;
- unsigned int segment;
- unsigned long laddress;
- unsigned char far *faraddr;
- unsigned int color;
-
- switch (DisplayDevice)
- {
- case CGA : /* for cga display */
-
- line--;
- sample--;
- if ((line & 1) == 0)
- address = 0x8000 + 40*line + (sample >> 3);
- else
- address = 0x0A000 + 40*(line-1) + (sample >> 3);
- bit = 7 - (sample & 7);
- mask = getmem(0x0B000,address) & ~((1 << (bit+1)) - 1);
- for (i = 0; i < ns; i++)
- {
- mask |= (buffer[i] & 1) << bit;
- bit--;
- if (bit < 0)
- {
- putmem(0x0B000,address, mask);
- address++;
- bit = 7;
- mask = 0;
- }
- }
- putmem(0x0B000,address,
- mask | (getmem(0x0B000,address) & ((1 << (bit+1)) - 1)) );
- return;
-
- case EGA350 : /* for ega and vga displays */
- case EGA480 : /* for ega and vga displays */
- case VGA480 : /* for ega and vga displays */
- case BIOS : /* for ega and vga displays */
- case EVGA800 : /* for Everex EVGA */
-
- DisplayLineEGA (FP_SEG(buffer),FP_OFF(buffer), line, sample, ns);
- return;
-
- case ATI640 :
- case ATI800 :
- case ATI1024:
-
- y = line;
- for (i=0; i<ns; i++)
- {
- x = sample + i;
- color = (unsigned int)(buffer[i]);
- ATI_WritePixel(x,y,color);
- }
- return;
-
- case PGA : /* for pga display */
- y = 480 - line; x1 = sample - 1; x2 = x1 + ns - 1;
- cmd[0] = 0x0D9;
- cmd[1] = y; cmd[2] = y >> 8;
- cmd[3] = x1; cmd[4] = x1 >> 8;
- cmd[5] = x2; cmd[6] = x2 >> 8;
- PGAsend (cmd, 7); /* 'IMAGEW y x1 x2 ' */
- s = 0;
- while (s < ns)
- {
- len = ns - s; if (len > 128) len = 128;
- cmd[0] = 127 + len;
- PGAsend (cmd, 1);
- PGAsend (&buffer[s], len);
- s += 128;
- }
- return;
-
- case VGA200 : /* for ega and vga displays */
- case ORCHID480 : /* for orchid designer */
- case ORCHID600 : /* for orchid designer */
- case ORCHID768 : /* for orchid designer */
-
- laddress = ((long)dispns*(long)(line-1))+(long)(sample-1);
- segment = laddress >> 16;
- laddress = laddress & 0x0FFFF;
- if ((laddress + (long)ns) > 65535L)
- /* this line will overlap a segment so write it pixel by pixel */
- for (i = 0; i < ns; i++) WritePixel(line,sample+i,(int)buffer[i]);
- else
- {
- faraddr = (unsigned char far *) (0x0a0000000L + laddress);
- outp(0x3cd,0x40 | segment);
- memcpy (faraddr,buffer,ns);
- }
- return;
-
- case EVGA640 : /* for Everex EVGA */
- case EVGA512 : /* for Everex EVGA */
-
- laddress = ((long)dispns*(long)(line))+(long)(sample-1);
- segment = laddress >> 16;
- laddress = laddress & 0x0FFFF;
- if ((laddress + (long)ns) > 65535L)
- /* this line will overlap a segment so write it pixel by pixel */
- for (i = 0; i < ns; i++) EVGAWritePixel256(sample+i,line,(int)buffer[i]);
- else
- {
- faraddr = (unsigned char far *) (0x0a0000000L + laddress);
- EVGASetPage(segment);
- memcpy (faraddr,buffer,ns);
- }
- return;
-
- case PARADISE : /* for Super VGA */
-
- WriteLinePAR (sample-1,ns,line-1,buffer);
- outp( 0x3ce, 0x0000f); /* added - mwm */
- return;
- }
- }
-
- int FormatLine (unsigned char * buffer, int nsdd, int nsd, int bitshift,
- int NoScale, char * status)
-
- /* FormatLine converts the line of pixels in the buffer into
- byte format for display. It also performs subsampling
- or zooming if needed.
- */
-
- {
- int samp, j, k, DN, scale, absbitshift;
- int mult;
- float fscale;
- unsigned char tmpbuf[2048];
- union {
- unsigned char *b;
- int *i;
- } buf;
- buf.b = buffer;
-
-
- status[0] = 0;
- TurnCursorOff = 0; /* always reinitialize the cursor fn to be on */
-
- /* For 16 bit images */
- /* scaling is done by dividing by a scale factor if the dn range specified
- is greater than the display range and by multiplying if the range
- specified is less than the display range
- */
- if (bitsperpix == 16 || bitsperpix ==32)
- {
- fscale = ((float)(DNhigh - DNlow) / (float)numDN);
- if (fscale < 1)
- {
- mult = 1;
- scale = 1.0/fscale;
- }
- else
- {
- mult = 0;
- scale = fscale + 1;
- }
-
- if (zoom == 1 )
- {
- samp = 0;
- for (j = 0; j < nsdd; j++)
- {
- DN = buf.i[samp];
- if (DN >= DNhigh)
- DN = DNhigh - 1;
- else
- if (DN <= DNlow)
- DN = DNlow;
-
- if (mult)
- buf.b[j] = ((long)DN-DNlow) * scale;
- else
- buf.b[j] = ((long)DN-DNlow) / scale;
- samp += subsample;
- }
- }
- else
- {
- j = nsd*zoom-1;
- for (samp = nsd-1; samp >= 0; samp--)
- {
- DN = buf.i[samp];
- if (DN >= DNhigh)
- DN = DNhigh - 1;
- else
- if (DN <= DNlow)
- DN = DNlow;
- if (mult)
- DN = ((long)DN-DNlow) * scale;
- else
- DN = ((long)DN-DNlow) / scale;
-
- for (k = 1; k <= zoom; k++)
- buf.b[j--] = DN;
- }
- }
-
- }
-
- /* For byte images (no offset) */
-
- else if ( (bitsperpix == 8) && NoScale )
- {
- if ( (subsample == 1) && (zoom == 1) )
- {
- if (bitshift > 0)
- for (j = 0; j < nsdd; j++)
- buf.b[j] >>= bitshift;
- }
- else if (zoom == 1)
- {
- samp = 0;
- for (j = 0; j < nsdd; j++)
- {
- buf.b[j] = buf.b[samp] >> bitshift;
- samp += subsample;
- }
- }
- else
- {
- j = nsd*zoom - 1;
- for (samp = nsd-1; samp >= 0; samp--)
- {
- DN = buf.b[samp] >> bitshift;
- for (k = 1; k <= zoom; k++)
- buf.b[j--] = DN;
- }
- }
- }
-
-
- /* For byte images (with offset) */
-
- /* scaling is done by dividing by a scale factor if the dn range specified
- is greater than the display range and by multiplying if the range
- specified is less than the display range
- */
- else if ( (bitsperpix == 8) && !NoScale )
- {
- fscale = ((float)(DNhigh - DNlow) / (float)numDN);
- if (fscale < 1)
- {
- mult = 1;
- scale = 1.0/fscale;
- }
- else
- {
- mult = 0;
- scale = fscale + 1;
- }
- if (zoom == 1)
- {
- samp = 0;
- for (j = 0; j < nsdd; j++)
- {
- DN = buf.b[samp];
- if (DN >= DNhigh)
- DN = DNhigh - 1;
- else
- if (DN <= DNlow)
- DN = DNlow;
- if (mult)
- buf.b[j] = (DN-DNlow) * scale;
- else
- buf.b[j] = (DN-DNlow) / scale;
- samp += subsample;
- }
- }
- else
- {
- j = nsd*zoom - 1;
- for (samp = nsd-1; samp >= 0; samp--)
- {
- DN = buf.b[samp];
- if (DN >= DNhigh)
- DN = DNhigh - 1;
- else
- if (DN <= DNlow)
- DN = DNlow;
- if (mult)
- buf.b[j] = (DN-DNlow) * scale;
- else
- DN = (DN-DNlow) / scale;
- for (k = 1; k <= zoom; k++)
- { /* 256 color bug fix - Ron Baalke - 07/15/90 */
- if ((numDN == 256) && ((DNlow >0) || (DNhigh < 255)))
- buf.b[j--] = (DN - DNlow) * scale;
- else
- buf.b[j--] = DN;
- }
- }
- }
-
- }
-
-
- /* For 4 bit and 1 bit images */
- else
- {
- absbitshift = abs(bitshift);
- ConvertLine (buf.b, tmpbuf, bitsperpix, 8, nsd, status);
- if (zoom == 1)
- {
- samp = 0;
- for (j = 0; j < nsdd; j++)
- {
- if (DisplayDevice == 0)
- {
- buf.b[j] = tmpbuf[samp];
- }
- else
- {
- buf.b[j] = tmpbuf[samp] << absbitshift;
- }
- samp += subsample;
- }
- }
- else
- {
- j = nsd*zoom - 1;
- for (samp = nsd-1; samp >= 0; samp--)
- {
- if (DisplayDevice == 0)
- {
- DN = tmpbuf[samp];
- }
- else
- {
- DN = tmpbuf[samp] << absbitshift;
- }
- for (k = 1; k <= zoom; k++)
- buf.b[j--] = DN;
- }
- }
- }
- }
-
-
- int ClearDisplay (int DN)
-
- /*** ClearDisplay sets the whole display to a particular value.
- Parameter type description
- DN integer The DN value to set (usually 0)
- ***/
-
- {
- int address, junk;
- unsigned char cmd[2];
- unsigned int i,j,segment;
- unsigned char far *faraddr;
-
- switch (DisplayDevice)
- {
-
- case CGA : /* for cga display */
- junk = 0x0FF*(DN & 1);
- for (address = 0; address < 8000; address++)
- {
- putmem(0x0B800,address, junk);
- putmem(0x0BA00,address, junk);
- }
- return;
-
- case EGA350 : /* for ega and vga displays */
- case EGA480 : /* for ega and vga displays */
- case VGA480 : /* for ega and vga displays */
- case BIOS : /* for ega and vga displays */
-
- ClearDisplayEGA (DN,dispnl);
- return;
-
- case ATI640 :
- case ATI800 :
- case ATI1024:
-
- faraddr = (unsigned char far *) 0x0a0000000L ;
- for (i=0; i < 8; i++)
- {
- atibank = i;
- ATI_Bank();
- memset(faraddr,DN,32768);
- memset(faraddr+32768L,DN,32768);
- }
- return;
-
- case PGA :
-
- cmd[0] = 0x0F; cmd[1] = DN;
- PGAsend (cmd, 2);
- return;
-
- case VGA200 : /* for ega and vga displays */
- case ORCHID480 : /* for orchid designer */
- case ORCHID600 : /* for orchid designer */
- case ORCHID768 : /* for orchid designer */
-
- faraddr = (unsigned char far *) 0x0a0000000L ;
- for (i = 0; i < 5; i++)
- {
- outp(0x3cd,0x40 | i);
- memset(faraddr,'\0',32768);
- memset(faraddr+32768L,'\0',32768);
- }
- if (dispnl > 480)
- for (i = 5; i < 8; i++)
- {
- outp(0x3cd,0x40 | i);
- memset(faraddr,'\0',32768);
- memset(faraddr+32768L,'\0',32768);
- }
-
- return;
-
- case EVGA640 : /* for ega and vga displays */
- case EVGA512 : /* for ega and vga displays */
- case EVGA800 : /* for ega and vga displays */
-
- EVGAClearDisplay(DN);
- return;
-
- case PARADISE:
-
- ClearDisplayPAR(DN);
- return;
- }
- }
-
-
- int PGAreceive (unsigned char * answer, int * p_len)
- /*
- This routine receives data from the PGA device.
- Only used by ReadPixel routine.
- */
-
- {
- unsigned char i, InWritePtr, InReadPtr, numbytes;
-
- do
- {
- InReadPtr = getmem (0x0C600,0x0303);
- InWritePtr = getmem (0x0C600,0x0302);
- numbytes = InWritePtr - InReadPtr;
- } while (numbytes == 0);
-
- for (i = 0; i < numbytes; i++)
- answer[i] = getmem (0x0C610,InReadPtr++);
-
- putmem (0x0C600, 0x0303, InReadPtr);
- *p_len = numbytes;
- }
-