[net.sources.games] vtrek termio.c patched

pkern@utcs.uucp (pkern) (09/16/85)

Here is a patched termio.c for the small visual trek game
posted a little while back. 
It originally would not work with a vt100 because vt100 termcap entries
were too long and because the padding information wasn't being decoded.
The "cl" and "cm" char arrays have been expanded to allow for
longer termcap entries and tputs() is now being called instead
of fputs() in the UNIX sections so as to allow the padding
information in termcap entries to be decoded.
It now works on 4.2BSD and Xenix 3.0
I guess this is for those who haven't bothered to mess about already.
(vtrek is made with -ltermcap OR -ltermlib depending on the system)
Hope this helps.
	Paul Kern
          ..!{decvax,ihnp4}!utcs!pkern
   ..!{allegra,linus}!utzoo!    "
..!{uw-beaver,floyd}!utcsri!	"

----------cut-------(vtrek's termio.c file follows)----------snip---------
/* terminal I/O */
#include "vtrek.h"

#ifdef AZTEC
/* These constants are at the beginning so they will be easy to find with */
/* DDT.  They will be a 0103 and 0107 if this file is loaded first. */
char cm[4] = "\033=";		/* cursor movement string */
char cl[4] = "\032";		/* clear screen string */
#else /* UNIX */
#include <sgtty.h>
static int saveflags;
static char cl[16], cm[32], bp[1024], name[20];
char PC, BC[5], UP[5];

#endif

/* initialize the termimal mode */
terminit()
{
#ifdef UNIX
	struct sgttyb tty;
	char *p, *getenv(), *tgetstr();
	if (p = getenv("TERM"))
	    strcpy(name, p);
	else {
	    fprintf(stderr, "TERM not set\n");
	    exit(1);
	}
	if (tgetent(bp, name) != 1) {
	    fprintf(stderr, "Can't get termcap entry\n");
	    exit(1);
	}
	p = cl;
	tgetstr("cl", &p);
	p = cm;
	tgetstr("cm", &p);
	p = UP;
	tgetstr("up", &p);
	p = BC;
	tgetstr("bc", &p);
	gtty(0, &tty);
	saveflags = tty.sg_flags;
	tty.sg_flags |= RAW;
	tty.sg_flags &= ~(ECHO | XTABS);
	stty(0, &tty);
#endif
}

/* reset the terminal mode */
termreset()
{
#ifdef UNIX
	struct sgttyb tty;
	gtty(0, &tty);
	tty.sg_flags = saveflags;
	stty(0, &tty);
#endif
}

/* get a character from the terminal */
getch()
{
#ifdef AZTEC
	int ch;
	while ((ch = CPM(6, 0xff)) == 0)
	    ;
	return ch;
#else /* UNIX */
	return getchar() & 0177;
#endif
}

/* write a character */
putch(ch)
int ch;
{
#ifdef AZTEC
	CPM(6, ch);
#else /* UNIX */
	putchar(ch);
#endif
}

#ifdef AZTEC
/* see if a character is ready to be read */
chready()
{
	return CPM(11, 0);
}
#endif

/* move cursor */
moveyx(ypos,xpos)
int ypos,xpos;
{
#ifdef AZTEC
	printf("%s%c%c", cm, ypos+31, xpos+31);
#else /* UNIX */
	tputs((char *)tgoto(cm, xpos - 1, ypos - 1),1,putch);
#endif
}

/* clear screen */
cls()
{
#ifdef AZTEC
	fputs(cl, stdout);
#else /* UNIX */
	tputs(cl,24,putch);
#endif
}