home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_C / SNIP9404.ZIP / VIDPORT.C < prev    next >
C/C++ Source or Header  |  1994-04-03  |  2KB  |  115 lines

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