1 /*	$NetBSD: board.c,v 1.6 1999/02/10 12:29:47 hubertf Exp $	*/
2 
3 /*
4  * Copyright (c) 1980, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *	This product includes software developed by the University of
18  *	California, Berkeley and its contributors.
19  * 4. Neither the name of the University nor the names of its contributors
20  *    may be used to endorse or promote products derived from this software
21  *    without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  */
35 
36 #include <sys/cdefs.h>
37 #ifndef lint
38 #if 0
39 static char sccsid[] = "@(#)board.c	8.1 (Berkeley) 5/31/93";
40 #else
41 __RCSID("$NetBSD: board.c,v 1.6 1999/02/10 12:29:47 hubertf Exp $");
42 #endif
43 #endif /* not lint */
44 
45 #include "back.h"
46 
47 static int i, j, k;
48 static char ln[60];
49 
50 void
51 wrboard()
52 {
53 	int     l;
54 	static const char bl[] =
55 	"|                       |   |                       |\n";
56 	static const char sv[] =
57 	"|                       |   |                       |    \n";
58 
59 	fixtty(&noech);
60 	clear();
61 
62 	if (tflag) {
63 		fboard();
64 		goto lastline;
65 	}
66 	writel("_____________________________________________________\n");
67 	writel(bl);
68 	strcpy(ln, bl);
69 	for (j = 1; j < 50; j += 4) {
70 		k = j / 4 + (j > 24 ? 12 : 13);
71 		ln[j + 1] = k % 10 + '0';
72 		ln[j] = k / 10 + '0';
73 		if (j == 21)
74 			j += 4;
75 	}
76 	writel(ln);
77 	for (i = 0; i < 5; i++) {
78 		strcpy(ln, sv);
79 		for (j = 1; j < 50; j += 4) {
80 			k = j / 4 + (j > 24 ? 12 : 13);
81 			wrbsub();
82 			if (j == 21)
83 				j += 4;
84 		}
85 		if (-board[25] > i)
86 			ln[26] = 'w';
87 		if (-board[25] > i + 5)
88 			ln[25] = 'w';
89 		if (-board[25] > i + 10)
90 			ln[27] = 'w';
91 		l = 53;
92 		if (off[1] > i || (off[1] < 0 && off[1] + 15 > i)) {
93 			ln[54] = 'r';
94 			l = 55;
95 		}
96 		if (off[1] > i + 5 || (off[1] < 0 && off[1] + 15 > i + 5)) {
97 			ln[55] = 'r';
98 			l = 56;
99 		}
100 		if (off[1] > i + 10 || (off[1] < 0 && off[1] + 15 > i + 10)) {
101 			ln[56] = 'r';
102 			l = 57;
103 		}
104 		ln[l++] = '\n';
105 		ln[l] = '\0';
106 		writel(ln);
107 	}
108 	strcpy(ln, bl);
109 	ln[25] = 'B';
110 	ln[26] = 'A';
111 	ln[27] = 'R';
112 	writel(ln);
113 	strcpy(ln, sv);
114 	for (i = 4; i > -1; i--) {
115 		for (j = 1; j < 50; j += 4) {
116 			k = ((j > 24 ? 53 : 49) - j) / 4;
117 			wrbsub();
118 			if (j == 21)
119 				j += 4;
120 		}
121 		if (board[0] > i)
122 			ln[26] = 'r';
123 		if (board[0] > i + 5)
124 			ln[25] = 'r';
125 		if (board[0] > i + 10)
126 			ln[27] = 'r';
127 		l = 53;
128 		if (off[0] > i || (off[0] < 0 && off[0] + 15 > i)) {
129 			ln[54] = 'w';
130 			l = 55;
131 		}
132 		if (off[0] > i + 5 || (off[0] < 0 && off[0] + 15 > i + 5)) {
133 			ln[55] = 'w';
134 			l = 56;
135 		}
136 		if (off[0] > i + 10 || (off[0] < 0 && off[0] + 15 > i + 10)) {
137 			ln[56] = 'w';
138 			l = 57;
139 		}
140 		ln[l++] = '\n';
141 		ln[l] = '\0';
142 		writel(ln);
143 	}
144 	strcpy(ln, bl);
145 	for (j = 1; j < 50; j += 4) {
146 		k = ((j > 24 ? 53 : 49) - j) / 4;
147 		ln[j + 1] = k % 10 + '0';
148 		if (k > 9)
149 			ln[j] = k / 10 + '0';
150 		if (j == 21)
151 			j += 4;
152 	}
153 	writel(ln);
154 	writel("|_______________________|___|_______________________|\n");
155 
156 lastline:
157 	gwrite();
158 	if (tflag)
159 		curmove(18, 0);
160 	else {
161 		writec('\n');
162 		writec('\n');
163 	}
164 	fixtty(&raw);
165 }
166 
167 void
168 wrbsub()
169 {
170 	int     m;
171 	char    d;
172 
173 	if (board[k] > 0) {
174 		m = board[k];
175 		d = 'r';
176 	} else {
177 		m = -board[k];
178 		d = 'w';
179 	}
180 	if (m > i)
181 		ln[j + 1] = d;
182 	if (m > i + 5)
183 		ln[j] = d;
184 	if (m > i + 10)
185 		ln[j + 2] = d;
186 }
187