home *** CD-ROM | disk | FTP | other *** search
/ Graphics Programming Black Book (Special Edition) / BlackBook.bin / disk1 / source / chapter42 / l42-5.c < prev    next >
C/C++ Source or Header  |  1997-06-18  |  1KB  |  41 lines

  1. /* Mode set and pixel-drawing functions for the 640x480 256-color mode of
  2.  * Tseng Labs ET4000-based SuperVGAs.
  3.  * Tested with Borland C++ 4.02 in small model by Jim Mischel 12/16/94.
  4.  */
  5. #include <dos.h>
  6.  
  7. /* Screen dimension globals, used in main program to scale */
  8. int ScreenWidthInPixels = 640;
  9. int ScreenHeightInPixels = 480;
  10.  
  11. /* ET4000 640x480 256-color draw pixel function. */
  12. void DrawPixel(int X, int Y, int Color)
  13. {
  14. #define SCREEN_SEGMENT        0xA000
  15. #define GC_SEGMENT_SELECT     0x3CD /* ET4000 segment (bank) select reg */
  16.    unsigned char far *ScreenPtr;
  17.    unsigned int Bank;
  18.    unsigned long BitmapAddress;
  19.  
  20.    /* Full bitmap address of pixel, as measured from address 0 to 0xFFFFF */
  21.    BitmapAddress = (unsigned long) Y * ScreenWidthInPixels + X;
  22.    /* Bank # is upper word of bitmap addr */
  23.    Bank = BitmapAddress >> 16;
  24.    /* Upper nibble is read bank #, lower nibble is write bank # */
  25.    outp(GC_SEGMENT_SELECT, (Bank << 4) | Bank);
  26.    /* Draw into the bank */
  27.    FP_SEG(ScreenPtr) = SCREEN_SEGMENT;
  28.    FP_OFF(ScreenPtr) = (unsigned int) BitmapAddress;
  29.    *ScreenPtr = Color;
  30. }
  31.  
  32. /* ET4000 640x480 256-color mode-set function. */
  33. void SetMode()
  34. {
  35.    union REGS regset;
  36.  
  37.    /* Set to 640x480 256-color graphics mode */
  38.    regset.x.ax = 0x002E;
  39.    int86(0x10, ®set, ®set);
  40. }
  41.