home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Black Box 4
/
BlackBox.cdr
/
progc
/
djlsr106.arj
/
GPPCONIO.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-03-29
|
7KB
|
327 lines
/**********************************************************************
*
* NAME: gppconio.c
*
* DESCRIPTION: simulate Borland text video funcs for GNU C++
*
* copyright (c) 1991 J. Alan Eldridge
*
* M O D I F I C A T I O N H I S T O R Y
*
* when who what
* -------------------------------------------------------------------
* 10/27/91 J. Alan Eldridge created
*
*********************************************************************/
#include <stdlib.h>
#include <stdarg.h>
#include <pc.h>
#include "gppconio.h"
#define DBGGTINFO 0
static struct text_info txinfo;
#define VIDADDR(r,c) (ScreenPrimary + r * txinfo.screenwidth + c)
int puttext(int c, int r, int c2, int r2, void *buf)
{
int c0;
short *pvch = (short *)buf;
r--, r2--, c--, c2--;
for (c0 = c; r <= r2; r++) {
for (c = c0; c <= c2; c++)
*VIDADDR(r,c) = *pvch++;
}
return 1;
}
int gettext(int c, int r, int c2, int r2, void *buf)
{
int c0;
short *pvch = (short *)buf;
r--, r2--, c--, c2--;
for (c0 = c; r <= r2; r++) {
for (c = c0; c <= c2; c++)
*pvch++ = *VIDADDR(r,c);
}
return 1;
}
void gotoxy(int col, int row)
{
ScreenSetCursor(row + txinfo.wintop - 2, col + txinfo.winleft - 2);
}
int wherex(void)
{
int row, col;
ScreenGetCursor(&row, &col);
return col - txinfo.winleft + 2;
}
int wherey(void)
{
int row, col;
ScreenGetCursor(&row, &col);
return row - txinfo.wintop + 2;
}
void textmode(int unused_mode)
{
}
void textattr(int attr)
{
ScreenAttrib = (unsigned char)attr;
}
void textcolor(int color)
{
ScreenAttrib &= 0xf0;
ScreenAttrib |= (color & 0x0f);
}
void textbackground(int color)
{
ScreenAttrib &= 0x0f;
ScreenAttrib |= ((color & 0x0f) << 4);
}
void highvideo(void)
{
ScreenAttrib |= 0x08;
}
void lowvideo(void)
{
ScreenAttrib &= 0x07;
}
void normvideo(void)
{
ScreenAttrib = txinfo.normattr;
}
void _setcursortype(int unused_type)
{
}
static void getwincursor(int *row, int *col)
{
ScreenGetCursor(row, col);
*col += txinfo.winleft - 1;
*row += txinfo.wintop - 1;
}
void clreol(void)
{
short image[ 256 ];
short val = ' ' | (ScreenAttrib << 8);
int c, row, col, ncols;
getwincursor(&row, &col);
ncols = txinfo.winright - col;
for (c = 0; c < ncols; c++)
image[ c ] = val;
puttext(col + 1, row + 1, txinfo.winright, row + 1, image);
}
static void fillrow(int row, int left, int right, int fill)
{
int col;
for (col = left; col <= right; col++)
*VIDADDR(row, col) = fill;
}
static void scrollwin(int t, int b, int l)
{
int top = txinfo.wintop + t - 1, left = txinfo.winleft - 1,
bot = txinfo.wintop + b - 1, right = txinfo.winright - 1;
int row, col, nbytes, fill, nlines;
if (!l)
return;
nbytes = (right - left + 1) * 2;
nlines = (bot - top + 1) - l;
fill = ' ' | (ScreenAttrib << 8);
if (l > 0) {
for (row = top; nlines > 0; row++, nlines--)
memcpy(VIDADDR(row, left), VIDADDR(row + l, left), nbytes);
for (; row <= bot; row++)
fillrow(row, left, right, fill);
} else {
for (row = bot; nlines > 0; row--, nlines--)
memcpy(VIDADDR(row, left), VIDADDR(row + l, left), nbytes);
for (; row >= top; row--)
fillrow(row, left, right, fill);
}
}
void clrscr(void)
{
scrollwin(0, txinfo.winbottom - txinfo.wintop, 32000);
}
int putch(int c)
{
int row, col;
getwincursor(&row, &col);
/* first, handle the character */
if (c == '\n')
row++;
else if (c == '\r')
col = txinfo.winleft - 1;
else {
short val = c | (ScreenAttrib << 8);
puttext(col + 1, row + 1, col + 1, row + 1, &val);
col++;
}
/* now, readjust the window */
if (col >= txinfo.winright) {
col = txinfo.winleft - 1;
row++;
}
if (row >= txinfo.winbottom) {
scrollwin(0, txinfo.winbottom - txinfo.wintop, 1);
row--;
}
ScreenSetCursor(row, col);
return c;
}
int getche(void)
{
int c = getch();
if (!c || c == 0xE0)
c = getch();
return putch(c);
}
void delline(void)
{
scrollwin(wherey() - 1, txinfo.winbottom - txinfo.wintop, 1);
}
void insline(void)
{
scrollwin(wherey() - 1, txinfo.winbottom - txinfo.wintop, -1);
}
void window(int left, int top, int right, int bottom)
{
if (top < 1 || left < 1 || right > txinfo.screenwidth ||
bottom > txinfo.screenheight)
return;
txinfo.wintop = top;
txinfo.winleft = left;
txinfo.winright = right;
txinfo.winbottom = bottom;
}
int cputs(const char *s)
{
int c = 0;
while (*s)
putch(c = *s++);
return c;
}
int cprintf(const char *fmt, ...)
{
int cnt;
char buf[ 2048 ];
va_list ap;
va_start(ap, fmt);
cnt = vsprintf(buf, fmt, ap);
va_end(ap);
cputs(buf);
return cnt;
}
int movetext(int left, int top, int right, int bottom, int dleft, int dtop)
{
char *buf = malloc((right - left + 1) * (bottom - top + 1) * 2);
if (!buf)
return 0;
gettext(left, top, right, bottom, buf);
puttext(dleft, dtop, dleft + right - left, dtop + bottom - top, buf);
free(buf);
return 1;
}
static void _gettextinfo(struct text_info *t)
{
int row, col;
t->winleft = t->wintop = 1;
t->winright = t->screenwidth = ScreenCols();
t->winbottom = t->screenheight = ScreenRows();
t->normattr = 0x07;
t->currmode = ScreenMode();
ScreenGetCursor(&row, &col);
t->curx = col;
t->cury = row;
#if DBGGTINFO
printf("left=%2d,right=%2d,top=%2d,bottom=%2d\n",t->winleft,
t->winright,t->wintop,t->winbottom);
printf("scrht=%2d,scrwid=%2d,norm=%2x,mode=%2d,x=%2d,y=%2d\n",
t->screenheight, t->screenwidth, t->normattr, t->currmode,
t->curx, t->cury);
#endif
}
void gettextinfo(struct text_info *t)
{
*t = txinfo;
#if DBGGTINFO
printf("left=%2d,right=%2d,top=%2d,bottom=%2d\n",t->winleft,
t->winright,t->wintop,t->winbottom);
printf("scrht=%2d,scrwid=%2d,norm=%2x,mode=%2d,x=%2d,y=%2d\n",
t->screenheight, t->screenwidth, t->normattr, t->currmode,
t->curx, t->cury);
#endif
}
extern int _gppconio_init;
void gppconio_init(void)
{
_gettextinfo(&txinfo);
_gppconio_init = 1;
}