home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / qc_prog / chap14 / ch2001.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-04-07  |  1.2 KB  |  36 lines

  1. /* ch2001.c -- fill screen with 2000 characters        */
  2. /*    This program demonstrates direct memory access   */
  3. /*    of video memory.  It uses the current video mode */
  4. /*    value to select the proper video RAM address.    */
  5. /*    Press a key to fill; press Esc to quit.          */
  6. /* Program list: ch2001.c, scrfun.lib                  */
  7. /* Note: activate Screen Swapping On in Debug menu     */
  8.  
  9. #include <conio.h>
  10. #include "scrn.h"
  11. typedef unsigned short (far * VIDMEM);
  12. #define MONMEM ((VIDMEM) (0xB000L << 16)) /* monochrome */
  13. #define CGAMEM ((VIDMEM) (0xB800L << 16)) /* cga, ega */
  14. #define ESC '\033'
  15. #define CHARS 2000
  16. #define AMASK 0xFF
  17. main()
  18. {
  19.      unsigned ch, mode;
  20.      unsigned attrib = 7;
  21.      VIDMEM screen;         /* pointer to video RAM */
  22.      int offset;
  23.  
  24.      if ((mode = Getvmode()) == TEXTMONO)
  25.           screen = MONMEM;
  26.      else if (mode == TEXTC80 || mode == TEXTBW80)
  27.           screen = CGAMEM;
  28.      else
  29.           exit(1);
  30.      while ((ch = getch()) != ESC)
  31.           {
  32.           for (offset = 0; offset < CHARS; offset++)
  33.               *(screen + offset) = ((attrib++ & AMASK) << 8) | ch;
  34.           }
  35. }
  36.