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

  1. /* ==================================================================
  2.     CVIDEO.C - C video modules.
  3. ================================================================== */
  4.  
  5. #include <dos.h>
  6.  
  7. struct VideoInfo {
  8.    unsigned char mode;
  9.    unsigned char rows;
  10.    unsigned char columns;
  11.    unsigned char ColorFlag;
  12.    unsigned char SyncFlag;
  13.    unsigned int BufferStart;
  14.    unsigned int SegAddr;
  15. };
  16.  
  17. void GetVideoParms(struct VideoInfo *);
  18. void ClrScr(char, struct VideoInfo *);
  19. void ClrRegion(char, char, char, char, char);
  20. void TextBox(char, char, char, char, char, struct VideoInfo *);
  21. void SaveRegion(char, char, char, char, int *, struct VideoInfo *);
  22. void RestRegion(char, char, char, char, int *, struct VideoInfo *);
  23.  
  24. extern int GetCharAttr(char, char, struct VideoInfo *);
  25. extern void DispCharAttr(char, char, char, char, struct VideoInfo *);
  26.  
  27. struct VideoInfo video;
  28. union REGS inregs, outregs;
  29.  
  30. /* ==================================================================
  31.    GetVideoParms() fills a video structure of type 
  32.    VideoInfo with data.
  33. =================================================================== */
  34. void GetVideoParms(struct VideoInfo *sptr)
  35. {
  36.    char far *CrtMode    = (char far *) 0x00400049;
  37.    char far *CrtCols    = (char far *) 0x0040004A;
  38.    int  far *CrtStart   = (int far *) 0x0040004E;
  39.    int  far *CrtAddr    = (int far *) 0x00400063;
  40.    char far *CrtRows    = (char far *) 0x00400084;
  41.    char far *CrtEgaInfo = (char far *) 0x00400087;
  42.  
  43.    /* --- Determine whether video writes must be synchronized --- */
  44.    inregs.h.ah = 0x12;
  45.    inregs.h.bl = 0x10;
  46.    int86(0x10, &inregs, &outregs);
  47.    if (outregs.h.bl == 0x10) {
  48.        if (*CrtAddr == 0x3D4)
  49.            sptr->SyncFlag = 1;
  50.        else
  51.            sptr->SyncFlag = 0;
  52.        sptr->rows = 25;
  53.    }
  54.    else {
  55.        if ((*CrtEgaInfo & 0x08) && (*CrtAddr == 0x3D4))
  56.            sptr->SyncFlag = 1;
  57.        else
  58.            sptr->SyncFlag = 0;
  59.        sptr->rows = *CrtRows + 1;
  60.    }
  61.  
  62.    /* ---- Determine whether video is color or monochrome ---- */
  63.    if (*CrtAddr == 0x3D4) {
  64.        sptr->ColorFlag = 1;
  65.        sptr->SegAddr = 0xB800;
  66.    }
  67.    else {
  68.        sptr->ColorFlag = 0;
  69.        sptr->SegAddr = 0xB000;
  70.    }
  71.  
  72.    /* ----- Copy remaining parameters from BIOS ----- */
  73.    sptr->mode = *CrtMode;
  74.    sptr->columns = *CrtCols;
  75.    sptr->BufferStart = *CrtStart;
  76. }
  77.  
  78. /* ==================================================================
  79.    ClrScr() clears the entire viewing area.
  80. ================================================================== */
  81. void ClrScr(char VideoAttr, struct VideoInfo *sptr)
  82. {
  83.    inregs.x.ax = 0x0600;
  84.    inregs.h.bh = VideoAttr;
  85.    inregs.x.cx = 0x0000;
  86.    inregs.h.dh = sptr->rows - 1;
  87.    inregs.h.dl = sptr->columns - 1;
  88.    int86(0x10, &inregs, &outregs);
  89. }
  90.  
  91. /* ==================================================================
  92.    ClrRegion() clears the specified screen region.
  93. ================================================================== */
  94. void ClrRegion(char row1, char col1, char row2, char col2, 
  95.                char VideoAttr)
  96. {
  97.    inregs.x.ax = 0x0600;
  98.    inregs.h.bh = VideoAttr;
  99.    inregs.h.ch = row1;
  100.    inregs.h.cl = col1;
  101.    inregs.h.dh = row2;
  102.    inregs.h.dl = col2;
  103.    int86(0x10, &inregs, &outregs);
  104. }
  105.  
  106. /* ==================================================================
  107.    TextBox() draws a box around the specified region.
  108. ================================================================== */
  109. void TextBox(char row1, char col1, char row2, char col2, 
  110.              char VideoAttr, struct VideoInfo *sptr)
  111. {
  112.    char i;
  113.  
  114.    DispCharAttr(0xDA, row1, col1, VideoAttr, sptr);
  115.    for (i=col1+1; i<col2; i++)
  116.        DispCharAttr(0xC4, row1, i, VideoAttr, sptr);
  117.    DispCharAttr(0xBF, row1, col2, VideoAttr, sptr);
  118.    for (i=row1+1; i<row2; i++)
  119.        DispCharAttr(0xB3, i, col2, VideoAttr, sptr);
  120.    DispCharAttr(0xD9, row2, col2, VideoAttr, sptr);
  121.    for (i=col2-1; i>col1; i--)
  122.        DispCharAttr(0xC4, row2, i, VideoAttr, sptr);
  123.    DispCharAttr(0xC0, row2, col1, VideoAttr, sptr);
  124.    for (i=row2-1; i>row1; i--)
  125.        DispCharAttr(0xB3, i, col1, VideoAttr, sptr);
  126. }
  127.  
  128. /* ==================================================================
  129.    SaveRegion() saves the contents of a specified screen region.
  130. ================================================================== */
  131. void SaveRegion(char row1, char col1, char row2, char col2,
  132.                 int *ScreenBuffer, struct VideoInfo *sptr)
  133. {
  134.    char i, j;
  135.  
  136.    for (i=row1; i<=row2; i++)
  137.        for (j=col1; j<=col2; j++)
  138.            *ScreenBuffer++ = GetCharAttr(i, j, sptr);
  139. }
  140.  
  141. /* ==================================================================
  142.    RestRegion() restores the contents of a specified screen region.
  143. ================================================================== */
  144. void RestRegion(char row1, char col1, char row2, char col2,
  145.                 int *ScreenBuffer, struct VideoInfo *sptr)
  146. {
  147.    char i, j;
  148.  
  149.    for (i=row1; i<=row2; i++)
  150.        for (j=col1; j<=col2; j++)
  151.            DispCharAttr((char) (*ScreenBuffer++ & 0x00FF), i, j,
  152.                         (char) (*ScreenBuffer >> 8), sptr);
  153. }
  154.