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