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