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