summaryrefslogtreecommitdiff
path: root/reference/C/CONTRIB/SNIP/vidport.c
blob: a3b328624fa4ebe53701b63a82aab2c2eba65142 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
**  Portable PC screen functions
**  Public domain by Bob Stout
**  Uses SCROLL.C, also from SNIPPETS
*/
 
#include <stdio.h>
#include <dos.h>
#include "scrnmacs.h"         /* Also in SNIPPETS     */

void GotoXY(int col, int row)
{
      union REGS regs;

      setbuf(stdout, NULL);
      regs.h.dh = (unsigned)row;
      regs.h.dl = (unsigned)col;
      regs.h.bh = VIDPAGE;
      regs.h.ah = 2;
      int86(0x10, &regs, &regs);
}

void ClrScrn(int vattrib)
{
      scroll(SCROLL_UP, 0, vattrib, 0, 0, SCREENROWS, SCREENCOLS);
      GotoXY(0, 0);                     /* Home cursor  */
}

void GetCurPos(int *col, int *row)
{
      union REGS regs;

      regs.h.ah = 0x03;
      regs.h.bh = VIDPAGE;
      int86(0x10, &regs, &regs);
      *row = regs.h.dh;
      *col = regs.h.dl;
}

int GetCurAtr(void)
{
      int row, col;
      unsigned short chat;

      GetCurPos(&col, &row);
      chat = *((unsigned FAR *)MK_FP(SCREENSEG,
            (row * SCREENCOLS + col) << 1));
      return (chat >> 8);
}

void ClrEol(void)
{
      int row, col;

      GetCurPos(&col, &row);
      scroll(0, 0, GetCurAtr(), row, col, row, SCREENCOLS);
}

void ClrEop(void)
{
      int row, col;

      GetCurPos(&col, &row);
      ClrEol();
      if (++row < SCREENROWS)
            scroll(0, 0, GetCurAtr(), row, 0, SCREENROWS, SCREENCOLS);
}

void Repaint(int vattrib)
{
      unsigned short FAR *screen = SCRBUFF;
      int row, col;

      for (row = 0; row < SCREENROWS; ++row)
      {
            for (col = 0; col < SCREENCOLS; ++col, ++screen)
                  *screen = (*screen & 0xff) + (vattrib << 8);
      }
}

#ifdef TEST

#include <conio.h>

/*
**  Run this test with a screenful of misc. stuff
*/

main()
{
      int vatr = GetCurAtr();

      GotoXY(1, 1);
      fputs("Testing ClrEol()", stderr);
      ClrEol();
      fputs("\nHit any key to continue...\n", stderr);
      getch();
      fputs("Testing ClrEop()", stderr);
      ClrEop();
      fputs("\nHit any key to continue...\n", stderr);
      getch();
      ClrScrn(vatr);
      GotoXY(0, 0);
      fputs("ClrScrn() tested", stderr);
      fputs("\nHit any key to continue...\n", stderr);
      getch();
      Repaint(BG_(CYAN) | BLACK);
      fputs("Repaint() tested", stderr);
      fputs("\nHit any key to continue...\n", stderr);
      getch();
      Repaint(vatr);
}

#endif