From 7e0f021a9aec35fd8e6725e87e3313b101d26f5e Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Sun, 27 Jan 2008 11:37:44 +0100 Subject: Initial import (2.0.2-6) --- reference/C/CONTRIB/SNIP/vidport.c | 114 +++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100755 reference/C/CONTRIB/SNIP/vidport.c (limited to 'reference/C/CONTRIB/SNIP/vidport.c') diff --git a/reference/C/CONTRIB/SNIP/vidport.c b/reference/C/CONTRIB/SNIP/vidport.c new file mode 100755 index 0000000..a3b3286 --- /dev/null +++ b/reference/C/CONTRIB/SNIP/vidport.c @@ -0,0 +1,114 @@ +/* +** Portable PC screen functions +** Public domain by Bob Stout +** Uses SCROLL.C, also from SNIPPETS +*/ + +#include +#include +#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, ®s, ®s); +} + +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, ®s, ®s); + *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 + +/* +** 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 -- cgit v1.2.3-54-g00ecf