home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / drdobbs / 1991 / 08 / dflat5 / video.c < prev    next >
Text File  |  1991-06-25  |  4KB  |  149 lines

  1. /* --------------------- video.c -------------------- */
  2. #include <stdio.h>
  3. #include <dos.h>
  4. #include <string.h>
  5. #include <conio.h>
  6. #include "dflat.h"
  7.  
  8. static unsigned video_address;
  9. /* -- read a rectangle of video memory into a save buffer -- */
  10. void getvideo(RECT rc, void far *bf)
  11. {
  12.     int ht = RectBottom(rc)-RectTop(rc)+1;
  13.     int bytes_row = (RectRight(rc)-RectLeft(rc)+1) * 2;
  14.     unsigned vadr = vad(RectLeft(rc), RectTop(rc));
  15.     hide_mousecursor();
  16.     while (ht--)    {
  17.         movedata(video_address, vadr, FP_SEG(bf),
  18.                 FP_OFF(bf), bytes_row);
  19.         vadr += 160;
  20.         bf = (char far *)bf + bytes_row;
  21.     }
  22.     show_mousecursor();
  23. }
  24.  
  25. /* -- write a rectangle of video memory from a save buffer -- */
  26. void storevideo(RECT rc, void far *bf)
  27. {
  28.     int ht = RectBottom(rc)-RectTop(rc)+1;
  29.     int bytes_row = (RectRight(rc)-RectLeft(rc)+1) * 2;
  30.     unsigned vadr = vad(RectLeft(rc), RectTop(rc));
  31.     hide_mousecursor();
  32.     while (ht--)    {
  33.         movedata(FP_SEG(bf), FP_OFF(bf), video_address,
  34.                 vadr, bytes_row);
  35.         vadr += 160;
  36.         bf = (char far *)bf + bytes_row;
  37.     }
  38.     show_mousecursor();
  39. }
  40.  
  41. /* -------- read a character of video memory ------- */
  42. int GetVideoChar(int x, int y)
  43. {
  44.     int c;
  45.     hide_mousecursor();
  46.     c = peek(video_address, vad(x,y));
  47.     show_mousecursor();
  48.     return c;
  49. }
  50.  
  51. /* -------- write a character of video memory ------- */
  52. void PutVideoChar(int x, int y, int c)
  53. {
  54.     if (x < SCREENWIDTH && y < SCREENHEIGHT)    {
  55.         hide_mousecursor();
  56.         poke(video_address, vad(x,y), c);
  57.         show_mousecursor();
  58.     }
  59. }
  60.  
  61. /* -------- write a character to a window ------- */
  62. void wputch(WINDOW wnd, int c, int x, int y)
  63. {
  64.     int x1 = GetLeft(wnd)+x;
  65.     int y1 = GetTop(wnd)+y;
  66.     if (x1 < SCREENWIDTH && y1 < SCREENHEIGHT)    {
  67.         hide_mousecursor();
  68.         poke(video_address,
  69.             vad(x1,y1),(c & 255) |
  70.                 (clr(foreground, background) << 8));
  71.         show_mousecursor();
  72.     }
  73. }
  74.  
  75. /* ------- write a string to a window ---------- */
  76. void wputs(WINDOW wnd, void *s, int x, int y)
  77. {
  78.     int x1 = GetLeft(wnd)+x;
  79.     int y1 = GetTop(wnd)+y;
  80.     if (x1 < SCREENWIDTH && y1 < SCREENHEIGHT)    {
  81.         int fg = foreground;
  82.         int bg = background;
  83.         unsigned char *str = s;
  84.         char ss[200];
  85.         int ln[SCREENWIDTH];
  86.         int *cp1 = ln;
  87.         int len;
  88.         strncpy(ss, s, 199);
  89.         ss[199] = '\0';
  90.         clipline(wnd, x, ss);
  91.         str = (unsigned char *) ss;
  92.         hide_mousecursor();
  93.         while (*str)    {
  94.             if (*str == CHANGECOLOR)    {
  95.                 str++;
  96.                 foreground = (*str++) & 0x7f;
  97.                 background = (*str++) & 0x7f;
  98.                 continue;
  99.             }
  100.             if (*str == RESETCOLOR)    {
  101.                 foreground = fg & 0x7f;
  102.                 background = bg & 0x7f;
  103.                 str++;
  104.                 continue;
  105.             }
  106.             *cp1++ = (*str & 255) |
  107.                 (clr(foreground, background) << 8);
  108.             str++;
  109.         }
  110.         foreground = fg;
  111.         background = bg;
  112.         len = (int)(cp1-ln);
  113.         if (x1+len > SCREENWIDTH)
  114.             len = SCREENWIDTH-x1;
  115.         movedata(FP_SEG(ln), FP_OFF(ln), video_address, vad(x1,y1), len*2);
  116.         show_mousecursor();
  117.     }
  118. }
  119.  
  120. /* --------- get the current video mode -------- */
  121. void get_videomode(void)
  122. {
  123.     videomode();
  124.     /* ---- Monochrome Display Adaptor or text mode ---- */
  125.     if (ismono())
  126.         video_address = 0xb000;
  127.     else
  128.         /* ------ Text mode -------- */
  129.         video_address = 0xb800 + video_page;
  130. }
  131.  
  132. /* --------- scroll the window. d: 1 = up, 0 = dn ---------- */
  133. void scroll_window(WINDOW wnd, RECT rc, int d)
  134. {
  135.     union REGS regs;
  136.     hide_mousecursor();
  137.     regs.h.cl = RectLeft(rc);
  138.     regs.h.ch = RectTop(rc);
  139.     regs.h.dl = RectRight(rc);
  140.     regs.h.dh = RectBottom(rc);
  141.     regs.h.bh = clr(WndForeground(wnd),WndBackground(wnd));
  142.     regs.h.ah = 7 - d;
  143.     regs.h.al = 1;
  144.     int86(VIDEO, ®s, ®s);
  145.     show_mousecursor();
  146. }
  147.  
  148.  
  149.