1997-10-10 20:32:15 +04:00
|
|
|
/* $NetBSD: terminal.c,v 1.2 1997/10/10 16:34:05 lukem Exp $ */
|
1997-10-04 13:00:13 +04:00
|
|
|
/*
|
|
|
|
* Hunt
|
|
|
|
* Copyright (c) 1985 Conrad C. Huang, Gregory S. Couch, Kenneth C.R.C. Arnold
|
|
|
|
* San Francisco, California
|
|
|
|
*/
|
|
|
|
|
1997-10-10 20:32:15 +04:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
#ifndef lint
|
|
|
|
__RCSID("$NetBSD: terminal.c,v 1.2 1997/10/10 16:34:05 lukem Exp $");
|
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#if __STDC__
|
|
|
|
#include <stdarg.h>
|
|
|
|
#else
|
|
|
|
#include <varargs.h>
|
|
|
|
#endif
|
1997-10-04 13:00:13 +04:00
|
|
|
# include "hunt.h"
|
|
|
|
# define TERM_WIDTH 80 /* Assume terminals are 80-char wide */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* cgoto:
|
|
|
|
* Move the cursor to the given position on the given player's
|
|
|
|
* terminal.
|
|
|
|
*/
|
1997-10-10 20:32:15 +04:00
|
|
|
void
|
1997-10-04 13:00:13 +04:00
|
|
|
cgoto(pp, y, x)
|
1997-10-10 20:32:15 +04:00
|
|
|
PLAYER *pp;
|
|
|
|
int y, x;
|
1997-10-04 13:00:13 +04:00
|
|
|
{
|
|
|
|
if (x == pp->p_curx && y == pp->p_cury)
|
|
|
|
return;
|
|
|
|
sendcom(pp, MOVE, y, x);
|
|
|
|
pp->p_cury = y;
|
|
|
|
pp->p_curx = x;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* outch:
|
|
|
|
* Put out a single character.
|
|
|
|
*/
|
1997-10-10 20:32:15 +04:00
|
|
|
void
|
1997-10-04 13:00:13 +04:00
|
|
|
outch(pp, ch)
|
1997-10-10 20:32:15 +04:00
|
|
|
PLAYER *pp;
|
|
|
|
char ch;
|
1997-10-04 13:00:13 +04:00
|
|
|
{
|
|
|
|
if (++pp->p_curx >= TERM_WIDTH) {
|
|
|
|
pp->p_curx = 0;
|
|
|
|
pp->p_cury++;
|
|
|
|
}
|
|
|
|
(void) putc(ch, pp->p_output);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* outstr:
|
|
|
|
* Put out a string of the given length.
|
|
|
|
*/
|
1997-10-10 20:32:15 +04:00
|
|
|
void
|
1997-10-04 13:00:13 +04:00
|
|
|
outstr(pp, str, len)
|
1997-10-10 20:32:15 +04:00
|
|
|
PLAYER *pp;
|
|
|
|
char *str;
|
|
|
|
int len;
|
1997-10-04 13:00:13 +04:00
|
|
|
{
|
|
|
|
pp->p_curx += len;
|
|
|
|
pp->p_cury += (pp->p_curx / TERM_WIDTH);
|
|
|
|
pp->p_curx %= TERM_WIDTH;
|
|
|
|
while (len--)
|
|
|
|
(void) putc(*str++, pp->p_output);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* clrscr:
|
|
|
|
* Clear the screen, and reset the current position on the screen.
|
|
|
|
*/
|
1997-10-10 20:32:15 +04:00
|
|
|
void
|
1997-10-04 13:00:13 +04:00
|
|
|
clrscr(pp)
|
1997-10-10 20:32:15 +04:00
|
|
|
PLAYER *pp;
|
1997-10-04 13:00:13 +04:00
|
|
|
{
|
|
|
|
sendcom(pp, CLEAR);
|
|
|
|
pp->p_cury = 0;
|
|
|
|
pp->p_curx = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ce:
|
|
|
|
* Clear to the end of the line
|
|
|
|
*/
|
1997-10-10 20:32:15 +04:00
|
|
|
void
|
1997-10-04 13:00:13 +04:00
|
|
|
ce(pp)
|
1997-10-10 20:32:15 +04:00
|
|
|
PLAYER *pp;
|
1997-10-04 13:00:13 +04:00
|
|
|
{
|
|
|
|
sendcom(pp, CLRTOEOL);
|
|
|
|
}
|
|
|
|
|
1997-10-10 20:32:15 +04:00
|
|
|
#if 0 /* XXX lukem*/
|
1997-10-04 13:00:13 +04:00
|
|
|
/*
|
|
|
|
* ref;
|
|
|
|
* Refresh the screen
|
|
|
|
*/
|
1997-10-10 20:32:15 +04:00
|
|
|
void
|
1997-10-04 13:00:13 +04:00
|
|
|
ref(pp)
|
1997-10-10 20:32:15 +04:00
|
|
|
PLAYER *pp;
|
1997-10-04 13:00:13 +04:00
|
|
|
{
|
|
|
|
sendcom(pp, REFRESH);
|
|
|
|
}
|
1997-10-10 20:32:15 +04:00
|
|
|
#endif
|
1997-10-04 13:00:13 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* sendcom:
|
|
|
|
* Send a command to the given user
|
|
|
|
*/
|
1997-10-10 20:32:15 +04:00
|
|
|
void
|
|
|
|
#if __STDC__
|
|
|
|
sendcom(PLAYER *pp, int command, ...)
|
|
|
|
#else
|
|
|
|
sendcom(pp, command, va_alist)
|
|
|
|
PLAYER *pp;
|
|
|
|
int command;
|
|
|
|
va_dcl
|
|
|
|
#endif
|
1997-10-04 13:00:13 +04:00
|
|
|
{
|
1997-10-10 20:32:15 +04:00
|
|
|
va_list ap;
|
|
|
|
int arg1, arg2;
|
|
|
|
#if __STDC__
|
|
|
|
va_start(ap, command);
|
|
|
|
#else
|
|
|
|
va_start(ap);
|
|
|
|
#endif
|
1997-10-04 13:00:13 +04:00
|
|
|
(void) putc(command, pp->p_output);
|
|
|
|
switch (command & 0377) {
|
1997-10-10 20:32:15 +04:00
|
|
|
case MOVE:
|
|
|
|
arg1 = va_arg(ap, int);
|
|
|
|
arg2 = va_arg(ap, int);
|
1997-10-04 13:00:13 +04:00
|
|
|
(void) putc(arg1, pp->p_output);
|
|
|
|
(void) putc(arg2, pp->p_output);
|
|
|
|
break;
|
1997-10-10 20:32:15 +04:00
|
|
|
case ADDCH:
|
|
|
|
case READY:
|
|
|
|
arg1 = va_arg(ap, int);
|
1997-10-04 13:00:13 +04:00
|
|
|
(void) putc(arg1, pp->p_output);
|
|
|
|
break;
|
|
|
|
}
|
1997-10-10 20:32:15 +04:00
|
|
|
|
|
|
|
va_end(ap); /* No return needed for void functions. */
|
1997-10-04 13:00:13 +04:00
|
|
|
}
|