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