home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / video / 10 / 10_15.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-11  |  2.2 KB  |  97 lines

  1. /* Listing 10-15 */
  2.  
  3. #define    Points        14    /* displayed scan lines per character */
  4. #define    StartCharCode    0x80    /* first character code in "window" */
  5. #define    CGenDefSize    32    /* (use 16 for Hercules) */
  6.  
  7. char far *CRT_MODE = 0x00400049;    /* BIOS video mode number */
  8. int  far *CRT_COLS = 0x0040004A;    /* characters per row */
  9.  
  10. char far *VideoBuffer;            /* pointer to video buffer */
  11. char far *CharDefTable = 0xA0000000;    /* pointer to char def RAM */
  12.                     /* (use 0xB0004000 for Hercules) */
  13. main()
  14. {
  15.     int    i;
  16.     int    CharCode;
  17.     int    CharOffset;
  18.     int    CharScanLine;
  19.     int    CharDefOffset;
  20.     int    Row,Column;
  21.  
  22.  
  23.     /* establish alphanumeric mode */
  24.  
  25.     if (*CRT_MODE == 7)        /* set video buffer pointer */
  26.       VideoBuffer = 0xB0000000;
  27.     else
  28.       VideoBuffer = 0xB8000000;
  29.  
  30.     AlphaModeSet( 8, Points, 8 );
  31.  
  32.  
  33.     /* establish a tiled graphics window in the upper left corner */
  34.  
  35.     CharCode = StartCharCode;
  36.  
  37.     for ( Row=0; Row<4; Row++ )
  38.       for ( Column=0; Column< 32; Column++ )
  39.       {
  40.         CharOffset = (Row*(*CRT_COLS) + Column) * 2;
  41.         VideoBuffer[CharOffset] = CharCode++;
  42.       }        
  43.  
  44.  
  45.     /* clear the window */
  46.  
  47.     CGenModeSet();        /* make character generator RAM addressable */
  48.  
  49.     for (CharCode=StartCharCode; CharCode<256; CharCode++ )
  50.       for ( CharScanLine=0; CharScanLine<Points; CharScanLine++ ) 
  51.       {
  52.         CharDefOffset = CharCode*CGenDefSize + CharScanLine;
  53.         CharDefTable[CharDefOffset] = 0;
  54.       }
  55.  
  56.  
  57.     /* draw a few lines */
  58.  
  59.     for ( i=0; i<256; i++ )        /* horizontal lines */
  60.     {
  61.       SetPixel( i, 0 );
  62.       SetPixel( i, 4*Points-1 );
  63.     }
  64.  
  65.     for ( i=0; i<4*Points-1; i++ )    /* vertical lines */
  66.     {
  67.       SetPixel( 0, i );
  68.       SetPixel( 255, i );
  69.     }
  70.  
  71.     for( i=0; i<Points*4; i++ )    /* diagonal lines */
  72.     {
  73.       SetPixel( i, i );
  74.       SetPixel( 255-i, i );
  75.     }
  76.  
  77.     CGenModeClear();        /* restore alphanumeric mode */
  78.  
  79. }
  80.  
  81. SetPixel( x, y )
  82. int    x,y;        /* pixel coordinates */
  83. {
  84.     int    CharCode;
  85.     int    CharScanLine;
  86.     int    BitMask;
  87.     int    CharDefOffset;
  88.  
  89.  
  90.     CharCode = StartCharCode + (y/Points)*32 + x/8;
  91.     CharScanLine = y % Points;        /* y MOD Points */
  92.     BitMask = 0x80 >> (x % 8);        /* 10000000b SHR (x MOD 8) */
  93.  
  94.     CharDefOffset = CharCode*CGenDefSize + CharScanLine;
  95.     CharDefTable[CharDefOffset] |= BitMask;    /* OR the pixel */
  96. }
  97.