home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / snip9707.zip / VIDPORT.C < prev    next >
C/C++ Source or Header  |  1997-07-05  |  3KB  |  120 lines

  1. /* +++Date last modified: 05-Jul-1997 */
  2.  
  3. /*
  4. **  Portable PC screen functions
  5. **  Public domain by Bob Stout
  6. **  Uses SCROLL.C, also from SNIPPETS
  7. */
  8.  
  9. #include <stdio.h>
  10. #include <dos.h>
  11. #include "scrnmacs.h"         /* Also in SNIPPETS     */
  12. #include "mk_fp.h"
  13.  
  14. void GotoXY(int col, int row)
  15. {
  16.       union REGS regs;
  17.  
  18.       setbuf(stdout, NULL);
  19.       regs.h.dh = (unsigned char)row;
  20.       regs.h.dl = (unsigned char)col;
  21.       regs.h.bh = VIDPAGE;
  22.       regs.h.ah = 2;
  23.       int86(0x10, ®s, ®s);
  24. }
  25.  
  26. void ClrScrn(int vattrib)
  27. {
  28.       scroll(SCROLL_UP, 0, vattrib, 0, 0, SCREENROWS, SCREENCOLS);
  29.       GotoXY(0, 0);                     /* Home cursor  */
  30. }
  31.  
  32. void GetCurPos(int *col, int *row)
  33. {
  34.       union REGS regs;
  35.  
  36.       regs.h.ah = 0x03;
  37.       regs.h.bh = VIDPAGE;
  38.       int86(0x10, ®s, ®s);
  39.       *row = regs.h.dh;
  40.       *col = regs.h.dl;
  41. }
  42.  
  43. int GetCurAtr(void)
  44. {
  45.       int row, col;
  46.       unsigned short chat;
  47.  
  48.       GetCurPos(&col, &row);
  49.       chat = *((unsigned short FAR *)MK_FP(SCREENSEG,
  50.             (row * SCREENCOLS + col) << 1));
  51.       return (chat >> 8);
  52. }
  53.  
  54. void ClrEol(void)
  55. {
  56.       int row, col;
  57.  
  58.       GetCurPos(&col, &row);
  59.       scroll(0, 0, GetCurAtr(), row, col, row, SCREENCOLS);
  60. }
  61.  
  62. void ClrEop(void)
  63. {
  64.       int row, col;
  65.  
  66.       GetCurPos(&col, &row);
  67.       ClrEol();
  68.       if (++row < SCREENROWS)
  69.             scroll(0, 0, GetCurAtr(), row, 0, SCREENROWS, SCREENCOLS);
  70. }
  71.  
  72. void Repaint(int vattrib)
  73. {
  74.       unsigned short FAR *screen = (unsigned short FAR *)SCRBUFF;
  75.       int row, col;
  76.  
  77.       for (row = 0; row < SCREENROWS; ++row)
  78.       {
  79.             for (col = 0; col < SCREENCOLS; ++col, ++screen)
  80.                   *screen = (*screen & 0xff) + (vattrib << 8);
  81.       }
  82. }
  83.  
  84.  
  85. #ifdef TEST
  86.  
  87. #include <conio.h>
  88.  
  89. /*
  90. **  Run this test with a screenful of misc. stuff
  91. */
  92.  
  93. main()
  94. {
  95.       int vatr = GetCurAtr();
  96.  
  97.       GotoXY(1, 1);
  98.       fputs("Testing ClrEol()", stderr);
  99.       ClrEol();
  100.       fputs("\nHit any key to continue...\n", stderr);
  101.       getch();
  102.       fputs("Testing ClrEop()", stderr);
  103.       ClrEop();
  104.       fputs("\nHit any key to continue...\n", stderr);
  105.       getch();
  106.       ClrScrn(vatr);
  107.       GotoXY(0, 0);
  108.       fputs("ClrScrn() tested", stderr);
  109.       fputs("\nHit any key to continue...\n", stderr);
  110.       getch();
  111.       Repaint(BG_(CYAN_) | BLACK_);
  112.       fputs("Repaint() tested", stderr);
  113.       fputs("\nHit any key to continue...\n", stderr);
  114.       getch();
  115.       Repaint(vatr);
  116.       return 0;
  117. }
  118.  
  119. #endif /* TEST */
  120.