Home | History | Annotate | Line # | Download | only in huntd
terminal.c revision 1.3
      1 /*	$NetBSD: terminal.c,v 1.3 2002/05/26 00:12:13 wiz Exp $	*/
      2 /*
      3  *  Hunt
      4  *  Copyright (c) 1985 Conrad C. Huang, Gregory S. Couch, Kenneth C.R.C. Arnold
      5  *  San Francisco, California
      6  */
      7 
      8 #include <sys/cdefs.h>
      9 #ifndef lint
     10 __RCSID("$NetBSD: terminal.c,v 1.3 2002/05/26 00:12:13 wiz Exp $");
     11 #endif /* not lint */
     12 
     13 #include <stdarg.h>
     14 #include "hunt.h"
     15 #define	TERM_WIDTH	80	/* Assume terminals are 80-char wide */
     16 
     17 /*
     18  * cgoto:
     19  *	Move the cursor to the given position on the given player's
     20  *	terminal.
     21  */
     22 void
     23 cgoto(pp, y, x)
     24 	PLAYER	*pp;
     25 	int	y, x;
     26 {
     27 	if (x == pp->p_curx && y == pp->p_cury)
     28 		return;
     29 	sendcom(pp, MOVE, y, x);
     30 	pp->p_cury = y;
     31 	pp->p_curx = x;
     32 }
     33 
     34 /*
     35  * outch:
     36  *	Put out a single character.
     37  */
     38 void
     39 outch(pp, ch)
     40 	PLAYER	*pp;
     41 	char	ch;
     42 {
     43 	if (++pp->p_curx >= TERM_WIDTH) {
     44 		pp->p_curx = 0;
     45 		pp->p_cury++;
     46 	}
     47 	(void) putc(ch, pp->p_output);
     48 }
     49 
     50 /*
     51  * outstr:
     52  *	Put out a string of the given length.
     53  */
     54 void
     55 outstr(pp, str, len)
     56 	PLAYER	*pp;
     57 	char	*str;
     58 	int	len;
     59 {
     60 	pp->p_curx += len;
     61 	pp->p_cury += (pp->p_curx / TERM_WIDTH);
     62 	pp->p_curx %= TERM_WIDTH;
     63 	while (len--)
     64 		(void) putc(*str++, pp->p_output);
     65 }
     66 
     67 /*
     68  * clrscr:
     69  *	Clear the screen, and reset the current position on the screen.
     70  */
     71 void
     72 clrscr(pp)
     73 	PLAYER	*pp;
     74 {
     75 	sendcom(pp, CLEAR);
     76 	pp->p_cury = 0;
     77 	pp->p_curx = 0;
     78 }
     79 
     80 /*
     81  * ce:
     82  *	Clear to the end of the line
     83  */
     84 void
     85 ce(pp)
     86 	PLAYER	*pp;
     87 {
     88 	sendcom(pp, CLRTOEOL);
     89 }
     90 
     91 #if 0		/* XXX lukem*/
     92 /*
     93  * ref;
     94  *	Refresh the screen
     95  */
     96 void
     97 ref(pp)
     98 	PLAYER	*pp;
     99 {
    100 	sendcom(pp, REFRESH);
    101 }
    102 #endif
    103 
    104 /*
    105  * sendcom:
    106  *	Send a command to the given user
    107  */
    108 void
    109 sendcom(PLAYER *pp, int command, ...)
    110 {
    111 	va_list	ap;
    112 	int	arg1, arg2;
    113 
    114 	va_start(ap, command);
    115 	(void) putc(command, pp->p_output);
    116 	switch (command & 0377) {
    117 	case MOVE:
    118 		arg1 = va_arg(ap, int);
    119 		arg2 = va_arg(ap, int);
    120 		(void) putc(arg1, pp->p_output);
    121 		(void) putc(arg2, pp->p_output);
    122 		break;
    123 	case ADDCH:
    124 	case READY:
    125 		arg1 = va_arg(ap, int);
    126 		(void) putc(arg1, pp->p_output);
    127 		break;
    128 	}
    129 
    130 	va_end(ap);		/* No return needed for void functions. */
    131 }
    132