home *** CD-ROM | disk | FTP | other *** search
/ Graphics Programming Black Book (Special Edition) / BlackBook.bin / disk1 / source / chapterg / lg-3.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-06-18  |  1.9 KB  |  52 lines

  1. /* Draws all pixels in the list of horizontal lines passed in, in Hicolor 
  2. (32K color) mode on an ET4000-based SuperVGA. Uses a slow pixel-by-pixel 
  3. approach. 
  4.   Tested with Borland C++ 4.02 in small model by Jim Mischel 12/16/94. */
  5.  
  6. #include <dos.h>
  7. #include "polygon.h"
  8. #define SCREEN_SEGMENT     0xA000
  9. #define GC_SEGMENT_SELECT  0x3CD
  10.  
  11. void DrawPixel(int, int, int);
  12. extern int BitmapWidthInBytes; /* # of pixels per line */
  13.  
  14. void DrawHCLineList(struct HLineList * HLineListPtr,
  15.       int Color)
  16. {
  17.    struct HLine *HLinePtr;
  18.    int Y, X;
  19.  
  20.    /* Point to XStart/XEnd descriptor for the first (top) horizontal line */
  21.    HLinePtr = HLineListPtr->HLinePtr;
  22.    /* Draw each horizontal line in turn, starting with the top one and
  23.       advancing one line each time */
  24.    for (Y = HLineListPtr->YStart; Y < (HLineListPtr->YStart +
  25.          HLineListPtr->Length); Y++, HLinePtr++) {
  26.       /* Draw each pixel in the current horizontal line in turn,
  27.          starting with the leftmost one */
  28.       for (X = HLinePtr->XStart; X <= HLinePtr->XEnd; X++)
  29.          DrawPixel(X, Y, Color);
  30.    }
  31. }
  32.  
  33. /* Draws the pixel at (X, Y) in color Color in Hicolor mode on an
  34.    ET4000-based SuperVGA */
  35. void DrawPixel(int X, int Y, int Color) {
  36.    unsigned int far *ScreenPtr, Bank;
  37.    unsigned long BitmapAddress;
  38.  
  39.    /* Full bitmap address of pixel, as measured from address 0 to
  40.       address 0xFFFFF. (X << 1) because pixels are 2 bytes in size */
  41.    BitmapAddress = (unsigned long) Y * BitmapWidthInBytes + (X << 1);
  42.    /* Map in the proper bank. Bank # is upper word of bitmap addr */
  43.    Bank = *(((unsigned int *)&BitmapAddress) + 1);
  44.    /* Upper nibble is read bank #, lower nibble is write bank # */
  45.    outp(GC_SEGMENT_SELECT, (Bank << 4) | Bank);
  46.    /* Draw into the bank */
  47.    FP_SEG(ScreenPtr) = SCREEN_SEGMENT;
  48.    FP_OFF(ScreenPtr) = *((unsigned int *)&BitmapAddress);
  49.    *ScreenPtr = (unsigned int)Color;
  50. }
  51.  
  52.