|
|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T c
Length: 6768 (0x1a70)
Types: TextFile
Names: »csr.c«
└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987
└─⟦this⟧ »EUUGD18/General/Tetris/csr.c«
/*
* multi-trek: csr.c 1/5/86 Written by Chuck Peterson,
* U.C. Santa Cruz There are two char arrays representing the screen.
* Window0 is the array which has what is currently on the terminal, and the
* future screen window1[] is the array which all updates are done to with
* the routines mvaddch(), mvaddstr(), move(), printc(), and clear().
* Csr_draw() is passed coordinates bounding the box region of the future
* screen which is to be transfered to the terminal.
*
* BUGS: tabs, newlines, and control characters on the window arrays will screw
* everything up.
*
* init_csr() -- initialize the whole thing
* resetty() -- reset term modes to like before init_csr()
* mvaddch(y,x,ch) -- add char to future screen
* mvaddstr(y,x,ch) -- add string to future screen
* csr_draw(y1,x1,y2,x2) -- make current screen look like future screen in
* the square bounded by the two coords
* move(y,x) -- move to current location in future window
* printc(fmt, args) -- printf into future screen @ current location
* clear(y1,x1,y2,x2) -- clear a box in the future screen
*
* For raw cursor movement and clear screen: csr(y,x) cls()
*/
#include <stdio.h>
#include <signal.h>
#include "csr.h"
#define reg register
#define MASK(sig) (1 << ((sig) - 1))
#define SIGHOLD(signo) (sigblock(MASK(signo)))
#define SIGRELSE(signo) (sigsetmask(sigblock(0) &~ MASK(signo)))
char obuf[BUFSIZ];
char nowrapping;
/* VARARGS */
extern ioctl();
init_csr()
{
static char bp[1024];
static char buffer[200];
char *area = buffer;
char *getenv();
char *tgetstr();
char *name;
tospaces((char *) window0, MAX_Y * MAX_X);
tospaces((char *) window1, MAX_Y * MAX_X);
_csrx = 9000;
_csry = 9000;
_rx = 9000;
_ry = 9000;
/*
* turn off echo and crmod; turn on cbreak mode
*/
gtty(0, &tty);
orig_tty = tty; /* structure assignment */
ospeed = tty.sg_ospeed;
tty.sg_flags &= ~ECHO;
tty.sg_flags &= ~CRMOD;
tty.sg_flags |= CBREAK;
stty(0, &tty);
ioctl(0, TIOCGLTC, <c);
orig_ltc = ltc; /* structure assignment */
ltc.t_flushc = -1; /* ignore whatever ctrl-o does */
ltc.t_suspc = -1; /* ctrl-z */
ltc.t_dsuspc = -1; /* ctrl-y */
ioctl(0, TIOCSLTC, <c);
/*
* ignore control-s and ctrl-c
*/
ioctl(0, TIOCGETC, &tc);
orig_tc = tc; /* structure assignment */
tc.t_stopc = -1;
tc.t_intrc = -1;
ioctl(0, TIOCSETC, &tc);
switch (tgetent(bp, name = getenv("TERM")))
{
case -1:
resetty();
printf("can't open termcap file.\n");
return 0;
break;
case 0:
resetty();
printf("No termcap entry for %s.\n", name);
return 0;
break;
}
tc_ce = tgetstr("ce", &area); /* not used yet */
tc_cm = tgetstr("cm", &area);
tc_cl = tgetstr("cl", &area);
tc_up = tgetstr("up", &area);
tc_do = tgetstr("do", &area);
if (!(tc_cm && tc_cl && tc_up && tc_do))
{
resetty();
puts("Your terminal must have cursor movement capabilities.");
return 0;
}
return 1;
}
putch(ch)
char ch;
{
putchar(ch);
}
resetty()
{
stty(0, &orig_tty);
ioctl(0, TIOCSETC, &orig_tc);
ioctl(0, TIOCSLTC, &orig_ltc);
}
csr_draw(y1, x1, y2, x2)
int y1, x1;
reg y2, x2;
{
reg i, j;
for (i = y1; i <= y2; ++i)
{
for (j = x1; j <= x2; ++j)
{
if (window0[i][j] != window1[i][j])
{
if (i == _ry)
{
if (_rx == j);
else
if (j == 0)
{
putchar('\r');
} else
if (j < _rx && j > _rx - 3)
{
while (_rx-- > j)
putchar('\b');
} else
if (j > _rx && j < _rx + 3)
{
while (_rx < j)
putchar(window0[i][_rx++]);
} else
csr(i, j);
} else
if (i == _ry - 1)
{
if (j == _rx)
tputs(tc_up, 0, putch);
else
if (j < _rx && j > _rx - 3)
{
tputs(tc_up, 0, putch);
while (_rx-- > j)
putchar('\b');
} else
if (j > _rx && j < _rx + 3)
{
tputs(tc_up, 0, putch);
while (_rx < j)
putchar(window0[i][_rx++]);
} else
csr(i, j);
} else
if (i == _ry + 1)
{
if (j == _rx)
tputs(tc_do, 0, putch);
else
if (j < _rx && j > _rx - 3)
{
tputs(tc_do, 0, putch);
while (_rx-- > j)
putchar('\b');
} else
if (j > _rx && j < _rx + 3)
{
tputs(tc_do, 0, putch);
while (_rx < j)
putchar(window0[i][_rx++]);
} else
csr(i, j);
} else
csr(i, j);
putchar(window1[i][j]);
window0[i][j] = window1[i][j];
_ry = i;
if (j + 1 == MAX_X)
{
if (nowrapping)
_rx = 100;
else
{
_rx = 0;
++_ry;
}
} else
_rx = j + 1;
}
}
}
fflush(stdout);
}
/* VARARGS 0 */
printc(fmt, args)
char *fmt, **args;
{
FILE jnk;
jnk._flag = _IOWRT + _IOSTRG;
jnk._ptr = &window1[_csry][_csrx];
jnk._cnt = 32014;
_doprnt(fmt, &args, &jnk);
_csrx += jnk._ptr - &window1[_csry][_csrx];
}
mvaddstr(y, x, s)
int y, x;
reg char *s;
{
reg char *w = &window1[y][x];
while (*s)
*w++ = *s++;
_csry = y;
_csrx = x + w - &window1[y][x];
}
clear(y1, x1, y2, x2)
{
reg int l;
reg int d = x2 - x1 + 1;
for (l = y1; l <= y2; ++l)
tospaces(&window1[l][x1], d);
}
clear0(y1, x1, y2, x2)
{
reg int l;
reg int d = x2 - x1 + 1;
for (l = y1; l <= y2; ++l)
tospaces(&window0[l][x1], d);
}
tospaces(p, n)
char *p;
int n;
{
while (n--)
*p++ = ' ';
}
/*
* This would be faster, but this isn't allowed. .text .globl _tospaces
*
* _tospaces: .word 0x0 movc5 $0,0,$32,8(ap),*4(ap) ret
*/
/* Refresh the whole screen */
int refreshing;
refresh()
{
refreshing = 1;
nowrapping = 1;
csr_draw(0, 0, MAX_Y - 1, MAX_X - 1);
fflush(stdout);
refreshing = 0;
}
/* added by jon luini, niteowl@ssyx */
save_screen(y1, x1, y2, x2)
int y1, /* the x, y co-ordinates of the area to be saved */
x1,
y2,
x2;
{
reg int i,
j;
for (i = y1; i <= y2; i++)
for (j = x1; j <= x2; j++)
window2[i][j] = window1[i][j];
}
restore_screen(y1, x1, y2, x2)
int y1, /* the x, y co-ordinates of the area to be restored */
x1,
y2,
x2;
{
reg int i,
j;
for (i = y1; i <= y2; i++)
for (j = x1; j <= x2; j++)
window1[i][j] = window2[i][j];
}