1 /*
2  * Copyright (c) 1980 Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
6  * provided that this notice is preserved and that due credit is given
7  * to the University of California at Berkeley. The name of the University
8  * may not be used to endorse or promote products derived from this
9  * software without specific prior written permission. This software
10  * is provided ``as is'' without express or implied warranty.
11  */
12 
13 #ifndef lint
14 static char sccsid[] = "@(#)board.c	5.2 (Berkeley) 02/16/88";
15 #endif /* not lint */
16 
17 #include "back.h"
18 
19 static int	i, j, k;
20 static char	ln[60];
21 
22 wrboard ()  {
23 	register int	l;
24 	static char	bl[] =
25 		"|                       |   |                       |\n";
26 	static char	sv[] =
27 		"|                       |   |                       |    \n";
28 
29 	fixtty (noech);
30 	clear();
31 
32 	if (tflag)  {
33 		fboard();
34 		goto lastline;
35 	}
36 
37 	writel ("_____________________________________________________\n");
38 	writel (bl);
39 	strcpy (ln,bl);
40 	for (j = 1; j < 50; j += 4) {
41 		k = j/4+(j > 24? 12: 13);
42 		ln[j+1] = k%10+'0';
43 		ln[j] = k/10+'0';
44 		if (j == 21)
45 			j += 4;
46 	}
47 	writel (ln);
48 	for (i = 0; i < 5; i++) {
49 		strcpy (ln,sv);
50 		for (j = 1; j < 50; j += 4) {
51 			k = j/4+(j > 24? 12: 13);
52 			wrbsub ();
53 			if (j == 21)
54 				j += 4;
55 		}
56 		if (-board[25] > i)
57 			ln[26] = 'w';
58 		if (-board[25] > i+5)
59 			ln[25] = 'w';
60 		if (-board[25] > i+10)
61 			ln[27] = 'w';
62 		l = 53;
63 		if (off[1] > i || (off[1] < 0 && off[1]+15 > i))  {
64 			ln[54] = 'r';
65 			l = 55;
66 		}
67 		if (off[1] > i+5 || (off[1] < 0 && off[1]+15 > i+5))  {
68 			ln[55] = 'r';
69 			l = 56;
70 		}
71 		if (off[1] > i+10 || (off[1] < 0 && off[1]+15 > i+10))  {
72 			ln[56] = 'r';
73 			l = 57;
74 		}
75 		ln[l++] = '\n';
76 		ln[l] = '\0';
77 		writel (ln);
78 	}
79 	strcpy (ln,bl);
80 	ln[25] = 'B';
81 	ln[26] = 'A';
82 	ln[27] = 'R';
83 	writel (ln);
84 	strcpy (ln,sv);
85 	for (i = 4; i > -1; i--) {
86 		for (j = 1; j < 50; j += 4) {
87 			k = ((j > 24? 53: 49)-j)/4;
88 			wrbsub();
89 			if (j == 21)
90 				j += 4;
91 		}
92 		if (board[0] > i)
93 			ln[26] = 'r';
94 		if (board[0] > i+5)
95 			ln[25] = 'r';
96 		if (board[0] > i+10)
97 			ln[27] = 'r';
98 		l = 53;
99 		if (off[0] > i || (off[0] < 0 && off[0]+15 > i))  {
100 			ln[54] = 'w';
101 			l = 55;
102 		}
103 		if (off[0] > i+5 || (off[0] < 0 && off[0]+15 > i+5))  {
104 			ln[55] = 'w';
105 			l = 56;
106 		}
107 		if (off[0] > i+10 || (off[0] < 0 && off[0]+15 > i+10))  {
108 			ln[56] = 'w';
109 			l = 57;
110 		}
111 		ln[l++] = '\n';
112 		ln[l] = '\0';
113 		writel (ln);
114 	}
115 	strcpy (ln,bl);
116 	for (j = 1; j < 50; j += 4) {
117 		k = ((j > 24? 53: 49)-j)/4;
118 		ln[j+1] = k%10+'0';
119 		if (k > 9)
120 			ln[j] = k/10+'0';
121 		if (j == 21)
122 			j += 4;
123 	}
124 	writel (ln);
125 	writel ("|_______________________|___|_______________________|\n");
126 
127 lastline:
128 	gwrite ();
129 	if (tflag)
130 		curmove (18,0);
131 	else  {
132 		writec ('\n');
133 		writec ('\n');
134 	}
135 	fixtty(raw);
136 }
137 
138 wrbsub () {
139 	register int	m;
140 	register char	d;
141 
142 	if (board[k] > 0)  {
143 		m = board[k];
144 		d = 'r';
145 	} else {
146 		m = -board[k];
147 		d = 'w';
148 	}
149 	if (m>i)
150 		ln[j+1] = d;
151 	if (m>i+5)
152 		ln[j] = d;
153 	if (m>i+10)
154 		ln[j+2] = d;
155 }
156