diff options
Diffstat (limited to 'gnu/games/chess/Xchess')
62 files changed, 12199 insertions, 0 deletions
diff --git a/gnu/games/chess/Xchess/COPYING b/gnu/games/chess/Xchess/COPYING new file mode 100644 index 000000000000..5905c3292de1 --- /dev/null +++ b/gnu/games/chess/Xchess/COPYING @@ -0,0 +1,124 @@ + + GNU X-CHESS GENERAL PUBLIC LICENSE + + Copyright (C) 1986 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license, but changing it is not allowed. + + The license agreements of most software companies keep you at the +mercy of those companies. By contrast, our general public license is +intended to give everyone the right to share GNU X-Chess. To make +sure that you get the rights we want you to have, we need to make +restrictions that forbid anyone to deny you these rights or to ask you +to surrender the rights. Hence this license agreement. + + Specifically, we want to make sure that you have the right to give +away copies of GNU X-Chess, that you receive source code or else can get it +if you want it, that you can change GNU X-Chess or use pieces of it in new +free programs, and that you know you can do these things. + + To make sure that everyone has such rights, we have to forbid you to +deprive anyone else of these rights. For example, if you distribute +copies of GNU X-Chess, you must give the recipients all the rights that you +have. You must make sure that they, too, receive or can get the +source code. And you must tell them their rights. + + Also, for our own protection, we must make certain that everyone +finds out that there is no warranty for GNU X-Chess. If GNU X-Chess is +modified by someone else and passed on, we want its recipients to know +that what they have is not what we distributed, so that any problems +introduced by others will not reflect on our reputation. + + Therefore the Free Software Foundation, Inc. makes the following +terms which say what you must do to be allowed to distribute or change +GNU X-Chess. + + COPYING POLICIES + + 1. You may copy and distribute verbatim copies of GNU X-Chess source +code as you receive it, in any medium, provided that you conspicuously +and appropriately publish on each file a valid copyright notice +"Copyright (C) 1986 Free Software Foundation, Inc.", containing the +year of last change for the file in question; keep intact the notices +on all files that refer to this License Agreement and to the absence +of any warranty; and give any other recipients of the GNU X-Chess +program a copy of this License Agreement along with the program. + + 2. You may modify your copy or copies of GNU X-Chess source code or +any portion of it, and copy and distribute such modifications under +the terms of Paragraph 1 above, provided that you also do the following: + + a) cause the modified files to carry prominent notices stating + who last changed such files and the date of any change; and + + b) cause the whole of any work that you distribute or publish, + that in whole or in part contains or is a derivative of GNU X-Chess + or any part thereof, to be freely distributed + and licensed to all third parties on terms identical to those + contained in this License Agreement (except that you may choose + to grant more extensive warranty protection to third parties, + at your option). + + c) if the modified program serves as a text editor, cause it + when started running in the simplest and usual way, to print + an announcement including a valid copyright notice ("Copyright + (C)", the year of authorship, and all copyright owners' names), + saying that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of + this License Agreement. + + 3. You may copy and distribute GNU X-Chess or any portion of it in +compiled, executable or object code form under the terms of Paragraphs +1 and 2 above provided that you do the following: + + a) cause each such copy of GNU X-Chess to be accompanied by the + corresponding machine-readable source code; or + + b) cause each such copy of GNU X-Chess to be accompanied by a + written offer, with no time limit, to give any third party + free (except for a nominal shipping charge) machine readable + copy of the corresponding source code; or + + c) in the case of a recipient of GNU X-Chess in compiled, executable + or object code form (without the corresponding source code) you + shall cause copies you distribute to be accompanied by a copy + of the written offer of source code which you received along + with the copy of GNU X-Chess. + + 4. You may not copy, sublicense, distribute or transfer GNU X-Chess +except as expressly provided under this License Agreement. Any attempt +otherwise to copy, sublicense, distribute or transfer GNU X-Chess is void and +your rights to use GNU X-Chess under this License agreement shall be +automatically terminated. However, parties who have received computer +software programs from you with this License Agreement will not have +their licenses terminated so long as such parties remain in full compliance. + +Your comments and suggestions about our licensing policies and our +software are welcome! Please contact the Free Software Foundation, Inc., +1000 Mass Ave, Cambridge, MA 02138, or call (617) 876-3296. + + NO WARRANTY + + BECAUSE GNU X-CHESS IS LICENSED FREE OF CHARGE, WE PROVIDE ABSOLUTELY +NO WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW. EXCEPT +WHEN OTHERWISE STATED IN WRITING, FREE SOFTWARE FOUNDATION, INC, +AND/OR OTHER PARTIES PROVIDE GNU X-CHESS "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +PROGRAM IS WITH YOU. SHOULD THE GNU X-CHESS PROGRAM PROVE DEFECTIVE, +YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL FREE SOFTWARE +FOUNDATION, INC., AND/OR ANY OTHER PARTY WHO MAY MODIFY AND +REDISTRIBUTE GNU X-CHESS AS PERMITTED ABOVE, BE LIABLE TO YOU FOR +DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR OTHER SPECIAL, +INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR +INABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA +BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR A +FAILURE OF THE PROGRAM TO OPERATE WITH PROGRAMS NOT DISTRIBUTED BY +FREE SOFTWARE FOUNDATION, INC.) THE PROGRAM, EVEN IF YOU HAVE BEEN +ADVISED OF THE POSSIBILITY OF SUCH DAMAGES, OR FOR ANY CLAIM BY ANY +OTHER PARTY. +====================================================================== diff --git a/gnu/games/chess/Xchess/Makefile b/gnu/games/chess/Xchess/Makefile new file mode 100644 index 000000000000..5645953f4fd5 --- /dev/null +++ b/gnu/games/chess/Xchess/Makefile @@ -0,0 +1,136 @@ +# RCS Info: $Revision: 1.2 $ on $Date: 1994/01/07 11:10:39 $ +# $Source: /home/cvs/386BSD/src/gnu/games/chess/Xchess/Makefile,v $ +# Copyright (c) 1985 Wayne A. Christopher, U. C. Berkeley CAD Group +# +# Makefile for xchess. + +#CC = cc -O -m68010 -L/pub.MC68010/lib -L/usr.MC68010/lib +CC = cc -O + +CFILES =\ + board.c\ + button.c\ + clock.c\ + control.c\ + jail.c\ + message.c\ + parse.c\ + popup.c\ + program.c\ + record.c\ + std.c\ + valid.c\ + window.c\ + XCircle.c + +COBJS =\ + board.o\ + button.o\ + clock.o\ + control.o\ + jail.o\ + message.o\ + parse.o\ + popup.o\ + program.o\ + record.o\ + std.o\ + valid.o\ + window.o\ + XCircle.o + +HFILES =\ + std.h\ + xchess.h + +SOURCE = $(CFILES) + +ALLFILES = $(SOURCE) $(HFILES) + +INCLUDE = -I. -I/usr/X386/include + +DEFINES = -DDEF_PROGRAM=\"/usr/bin/chess\" + +CFLAGS = $(DEFINES) $(INCLUDE) +LINTFLAGS = -u -z -lc -DLINT $(DEFINES) $(INCLUDE) +LINTLIB = ../lib/llib-lX.ln +#LDFLAGS = -L/usr2/X/lib -z -lX -lm +LDFLAGS = -L/usr/X386/lib -loldX -lX11 -z -lm +GPLDFLAGS = -z -loldX -lX11 -lXMenu_p -lX -lm_p -g -pg + +.c.o: $*.c + $(CC) $(CFLAGS) -c $*.c +.s.o: $*.s + $(CC) $(CFLAGS) -c $*.s + +all: xchess scrollText.o + @echo "All done." + +everything: all tags depend lint wc + @echo "All done." + +xchess: xchess.o $(COBJS) scrollText.o + $(CC) -o xchess xchess.o $(COBJS) scrollText.o \ + $(LDFLAGS) + +scrollText.o: scrollText.h scrollText.c + +gpxchess: xchess.o $(COBJS) + $(CC) -o gpxchess xchess.o $(COBJS) scrollText/libScroll.a \ + $(GPLDFLAGS) + +lint: $(SOURCE) + lint $(LINTFLAGS) $(SOURCE) $(LINTLIB) | \ + grep -v "multiply declared" + +qgrind: $(ALLFILES) + qgrind -lc $(ALLFILES) + +vgrind: $(ALLFILES) + vgrind -lc $(ALLFILES) + +opt: all + +reopt: all + +install: all + +source: $(SOURCE) + +tags: $(ALLFILES) + ctags -w -t *.c *.h > /dev/null 2>&1 + +wc: $(ALLFILES) + @wc $(ALLFILES) + +print: $(ALLFILES) + @pr $(ALLFILES) + +clean: + rm -f *.o *.a *.out xchess tags foo tmp + +tar: + tar -cf xchess.tar Makefile *.h *.c *.bitmap *.icon *.cur *.1\ + scrollText/Makefile scrollText/*.h scrollText/*.c scrollText/*.1\ + scrollText/*.3 + +$(ALLFILES): + co $@ + +depend: $(SOURCE) + cc -M $(CFLAGS) $(CFILES) > makedep + echo '/^# DO NOT DELETE THIS LINE/+2,$$d' >eddep + echo '$$r makedep' >>eddep + echo 'w' >>eddep + ed - Makefile < eddep + rm eddep makedep + echo '# DEPENDENCIES MUST END AT END OF FILE' >> Makefile + echo '# IF YOU PUT STUFF HERE IT WILL GO AWAY' >> Makefile + echo '# see make depend above' >> Makefile + +#----------------------------------------------------------------- +# DO NOT DELETE THIS LINE -- make depend uses it +# DEPENDENCIES MUST END AT END OF FILE + +xchess.o $(COBJS): $(HFILES) + diff --git a/gnu/games/chess/Xchess/ScrollText b/gnu/games/chess/Xchess/ScrollText new file mode 100644 index 000000000000..782a54f48548 --- /dev/null +++ b/gnu/games/chess/Xchess/ScrollText @@ -0,0 +1,34 @@ +Subject: File: scrollText.h + +/* + * Scrollable Text Window Header File + * + * David Harrison + * University of California, Berkeley + * 1986 + * + * This file contains definitions for a scrollable text window + * with scroll bar support. + */ + +int TxtGrab(); + /* Take hold of a previously created window */ + +#define TXT_NO_COLOR -1 + +int TxtAddFont(); + /* Loads a new font for use later */ +int TxtWinP(); + /* Returns non-zero value if the window is text window */ +int TxtClear(); + /* Clears text window and resets text buffer */ + +int TxtWriteStr(); + /* Writes a string to window with immediate update */ +int TxtJamStr(); + /* Write a string without causing update to screen */ + +int TxtRepaint(); + /* Repaints entire scrollable text window */ +int TxtFilter(); + /* Handles events related to text window */ diff --git a/gnu/games/chess/Xchess/XCircle.c b/gnu/games/chess/Xchess/XCircle.c new file mode 100644 index 000000000000..33e3b1c909b3 --- /dev/null +++ b/gnu/games/chess/Xchess/XCircle.c @@ -0,0 +1,162 @@ + +/* This file contains code for X-CHESS. + Copyright (C) 1986 Free Software Foundation, Inc. + +This file is part of X-CHESS. + +X-CHESS is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY. No author or distributor +accepts responsibility to anyone for the consequences of using it +or for whether it serves any particular purpose or works at all, +unless he says so in writing. Refer to the X-CHESS General Public +License for full details. + +Everyone is granted permission to copy, modify and redistribute +X-CHESS, but only under the conditions described in the +X-CHESS General Public License. A copy of this license is +supposed to have been given to you along with X-CHESS so you +can know your rights and responsibilities. It should be in a +file named COPYING. Among other things, the copyright notice +and this notice must be preserved on all copies. */ + + +/* RCS Info: $Revision: 1.1.1.1 $ on $Date: 1993/06/12 14:41:12 $ + * $Source: /home/cvs/386BSD/src/gnu/games/chess/Xchess/XCircle.c,v $ + * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group + * Permission is granted to do anything with this code except sell it + * or remove this message. + * + */ + +#include <stdio.h> +#include <X11/Xlib.h> +#include <X11/X10.h> +#include <math.h> + +#define PI 3.1415926535897932384 + +#define MAXVERTS 1000 + +void +XCircle(win, x, y, rad, start, end, width, height, pixel, func, planes) + Window win; + int x, y, rad; + double start, end; + int pixel; + int width, height; + int func, planes; +{ + Vertex verts[MAXVERTS]; + double xp, yp, ang; + int lx, ly, xpt, ypt, i; + double gradincr = 2 / (double) rad; + int bk = 0; + + while (end >= PI * 2) + end -= PI * 2; + while (start >= PI * 2) + start -= PI * 2; + while (end < 0) + end += PI * 2; + while (start < 0) + start += PI * 2; + if (end == start) { + if (end < gradincr) + end = end + PI * 2 - gradincr / 2; + else + end -= gradincr / 2; + } + for (ang = start, i = 0; i < MAXVERTS; ) { + + xp = x + rad * cos(ang); + yp = y + rad * sin(ang); + + xpt = xp; + ypt = yp; + + if (!i || (lx != xpt) || (ly != ypt)) { + verts[i].x = xpt; + verts[i].y = ypt; + verts[i].flags = 0; + i++; + } + lx = xpt; + ly = ypt; + if (bk) + break; + if (((ang < end) && (ang + gradincr > end)) || ((end < start) + && (ang + gradincr > 2 * PI) + && (ang + gradincr - 2 * PI > end))) { + ang = end; + bk = 1; + } else if (ang == end) { + break; + } else { + ang += gradincr; + } + if (ang >= PI * 2) + ang -= PI * 2; + } + + /* Now draw the thing.. */ + XDraw(win, verts, i, width, height, pixel, func, planes); + + return; +} + +#ifdef notdef VertexCurved is screwed up + +void +XCircle(win, x, y, rad, start, end, width, height, pixel, func, planes) + Window win; + int x, y, rad; + double start, end; + int pixel; + int width, height; + int func, planes; +{ + Vertex verts[7]; + int i, j, sv, ev; + int dp = 0; + + for (i = j = 0 ; i < 4; i++) { + verts[j].x = x + rad * cos((double) (PI * i / 2)); + verts[j].y = y + rad * sin((double) (PI * i / 2)); + verts[j].flags = VertexCurved; + if ((start >= PI * i / 2) && (start < PI * (i + 1) / 2) && + (start != end)) { + j++; + verts[j].x = x + rad * cos(start); + verts[j].y = y + rad * sin(start); + verts[j].flags = VertexCurved; + sv = j; + } else if ((end >= PI * i / 2) && (end < PI * (i + 1) / 2) + && (start != end)) { + j++; + verts[j].x = x + rad * cos(end); + verts[j].y = y + rad * sin(end); + verts[j].flags = VertexCurved; + ev = j; + } + j++; + } + verts[0].flags |= VertexStartClosed; + verts[j].x = verts[0].x; + verts[j].y = verts[0].y; + verts[j].flags = (verts[0].flags & ~VertexStartClosed) | + VertexEndClosed; + for (i = 0; i < 15; i++) { + if (dp) + verts[i % 7].flags |= VertexDontDraw; + if (i % 7 == ev) + dp = 1; + else if (i % 7 == sv) + dp = 0; + } + XDraw(win, verts, j + 1, width, height, pixel, func, planes); + + return; +} + +#endif notdef + diff --git a/gnu/games/chess/Xchess/bishop.bitmap b/gnu/games/chess/Xchess/bishop.bitmap new file mode 100644 index 000000000000..dc068ddf1cfa --- /dev/null +++ b/gnu/games/chess/Xchess/bishop.bitmap @@ -0,0 +1,71 @@ + +#define bishop_width 80 +#define bishop_height 80 +static char bishop_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x07, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x8f, + 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x8f, 0x0f, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x8f, 0x0f, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x80, 0x0f, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x9f, + 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x7f, 0x10, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x7f, 0x10, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xf8, 0xff, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xfc, 0xff, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, + 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0x23, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xf8, 0x67, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xff, 0xf8, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x80, 0xff, 0xf8, 0x4f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, + 0x1f, 0xc0, 0x4f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x1f, 0xc0, + 0x5f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x1f, 0xc0, 0x5f, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xf8, 0x7f, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xe0, 0xff, 0xf8, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xe0, 0xff, 0xf8, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, + 0xff, 0xf8, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0xf8, + 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0xf8, 0x7f, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0xf8, 0xff, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xf8, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, + 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, + 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, 0xff, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xf0, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xf0, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, + 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, + 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0x3f, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0x1f, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x80, 0xff, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, + 0xff, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, + 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x07, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xfe, 0xfd, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfa, 0xf8, + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x72, 0x70, 0x02, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x72, 0x70, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xfa, 0xf8, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xfe, 0xfd, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x04, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0x0f, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xc0, 0xff, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x80, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x0f, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x1f, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x3f, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xf0, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xf8, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x1f, + 0xfc, 0xfd, 0xc1, 0xff, 0x01, 0x00, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xfd, + 0xff, 0xff, 0x07, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, + 0x3f, 0x00, 0x00, 0xf0, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0x00, + 0x00, 0xc0, 0xff, 0xff, 0x3f, 0xf0, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x80, + 0x0f, 0xf0, 0x0f, 0xc0, 0x7f, 0x00, 0x1f, 0x00, 0x00, 0xc0, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; diff --git a/gnu/games/chess/Xchess/bishop_mask.bitmap b/gnu/games/chess/Xchess/bishop_mask.bitmap new file mode 100644 index 000000000000..ca17bb3dae0d --- /dev/null +++ b/gnu/games/chess/Xchess/bishop_mask.bitmap @@ -0,0 +1,71 @@ + +#define bishop_mask_width 80 +#define bishop_mask_height 80 +static char bishop_mask_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x80, 0x8f, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xc0, 0xdf, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xdf, + 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xdf, 0x1f, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xdf, 0x1f, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xc0, 0xdf, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x80, 0x8f, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xc0, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, + 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0x3f, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0x3f, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xfe, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, + 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xc0, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, + 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, + 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0xff, 0xff, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xf0, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xf0, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, + 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, + 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, 0xff, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xfc, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xfc, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, + 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0xff, + 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0xff, 0xff, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xf8, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, + 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, + 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0xff, 0x7f, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xe0, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, + 0xff, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, + 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0x1f, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0x0f, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x80, 0xff, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, + 0xff, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, + 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x07, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x80, 0xff, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, + 0xff, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, + 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0x1f, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0x1f, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xe0, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, + 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x3f, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x7f, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xfc, 0x3f, 0xfc, 0xff, 0xe3, 0xff, 0x03, 0x00, 0x00, 0x00, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0x0f, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0x7f, 0x00, 0x00, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0x01, 0x00, 0xf8, 0xff, 0xff, 0xff, 0xfd, 0xff, 0xff, 0xff, 0x01, + 0x00, 0xf8, 0xff, 0xff, 0xff, 0xfd, 0xff, 0xff, 0xff, 0x01, 0x00, 0xe0, + 0xff, 0xff, 0x7f, 0xf8, 0xff, 0xff, 0x7f, 0x00, 0x00, 0xf0, 0x1f, 0xf8, + 0x1f, 0xe0, 0xff, 0x80, 0xff, 0x00, 0x00, 0xf0, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xf8, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; diff --git a/gnu/games/chess/Xchess/bishop_outline.bitmap b/gnu/games/chess/Xchess/bishop_outline.bitmap new file mode 100644 index 000000000000..9772328c2984 --- /dev/null +++ b/gnu/games/chess/Xchess/bishop_outline.bitmap @@ -0,0 +1,71 @@ + +#define bishop_outline_width 80 +#define bishop_outline_height 80 +static char bishop_outline_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x07, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x8d, + 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x88, 0x08, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x8d, 0x0d, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x80, 0x0f, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x98, + 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x70, 0x10, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x40, 0x10, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x18, 0xc0, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x08, 0x80, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x0c, 0x80, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x80, + 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x22, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x07, 0x66, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x05, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x80, 0x01, 0x05, 0x4c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, + 0xe0, 0x3d, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x20, 0x20, + 0x58, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0xe0, 0x3d, 0x50, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x05, 0x70, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x20, 0x00, 0x05, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x20, 0x00, 0x05, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, + 0x00, 0x05, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x05, + 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x05, 0x40, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x07, 0xc0, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x08, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, + 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, + 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0xc0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x10, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, + 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x30, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x80, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, + 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x07, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x07, + 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8e, 0x8d, 0x03, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8e, 0x8d, 0x03, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x06, 0x07, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x02, 0x02, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x04, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x0c, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xc0, 0xff, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x80, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x08, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x18, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x30, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x30, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x18, 0xc7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x1f, + 0x0c, 0x85, 0xc1, 0xff, 0x01, 0x00, 0x00, 0x00, 0x0e, 0xf0, 0x87, 0x0d, + 0x7f, 0x00, 0x07, 0x00, 0x00, 0xc0, 0x03, 0x00, 0xc0, 0x08, 0x00, 0x00, + 0x3c, 0x00, 0x00, 0x70, 0x00, 0x00, 0xe0, 0x18, 0x00, 0x00, 0xe0, 0x00, + 0x00, 0xc0, 0xf8, 0x1f, 0x38, 0x70, 0xc0, 0xff, 0x31, 0x00, 0x00, 0x80, + 0x0f, 0xf0, 0x0f, 0xc0, 0x7f, 0x00, 0x1f, 0x00, 0x00, 0xc0, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; diff --git a/gnu/games/chess/Xchess/bishop_small.bitmap b/gnu/games/chess/Xchess/bishop_small.bitmap new file mode 100644 index 000000000000..5525ecd03c2d --- /dev/null +++ b/gnu/games/chess/Xchess/bishop_small.bitmap @@ -0,0 +1,15 @@ + +#define bishop_small_width 32 +#define bishop_small_height 32 +static char bishop_small_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x1c, 0x00, 0x00, 0x70, 0x1c, 0x00, + 0x00, 0x70, 0x1c, 0x00, 0x00, 0x20, 0x08, 0x00, 0x00, 0x60, 0x16, 0x00, + 0x00, 0x60, 0x22, 0x00, 0x00, 0xf0, 0x23, 0x00, 0x00, 0xf0, 0x21, 0x00, + 0x00, 0xf8, 0x21, 0x00, 0x00, 0xf8, 0x23, 0x00, 0x00, 0xf8, 0x23, 0x00, + 0x00, 0xf8, 0x27, 0x00, 0x00, 0x38, 0x27, 0x00, 0x00, 0x3c, 0x2f, 0x00, + 0x00, 0x0c, 0x2c, 0x00, 0x00, 0x0e, 0x3c, 0x00, 0x00, 0x3e, 0x3f, 0x00, + 0x00, 0x3e, 0x3f, 0x00, 0x00, 0x3e, 0x3f, 0x00, 0x00, 0x3e, 0x3f, 0x00, + 0x00, 0xfe, 0x7f, 0x00, 0x00, 0xfe, 0x7f, 0x00, 0x00, 0xfe, 0x7f, 0x00, + 0x00, 0xfe, 0x7f, 0x00, 0x00, 0xfe, 0x7f, 0x00, 0x00, 0xfe, 0x7f, 0x00, + 0x00, 0xfe, 0x7f, 0x00, 0x00, 0xfe, 0x7f, 0x00, 0xe0, 0xff, 0xff, 0x07, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; diff --git a/gnu/games/chess/Xchess/bishop_small_outline.bitmap b/gnu/games/chess/Xchess/bishop_small_outline.bitmap new file mode 100644 index 000000000000..8d29a812e29e --- /dev/null +++ b/gnu/games/chess/Xchess/bishop_small_outline.bitmap @@ -0,0 +1,15 @@ + +#define bishop_small_outline_width 32 +#define bishop_small_outline_height 32 +static char bishop_small_outline_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x1c, 0x00, 0x00, 0x50, 0x14, 0x00, + 0x00, 0x70, 0x1c, 0x00, 0x00, 0x20, 0x08, 0x00, 0x00, 0x60, 0x16, 0x00, + 0x00, 0x60, 0x22, 0x00, 0x00, 0xf0, 0x23, 0x00, 0x00, 0x10, 0x21, 0x00, + 0x00, 0x18, 0x21, 0x00, 0x00, 0x08, 0x23, 0x00, 0x00, 0x08, 0x22, 0x00, + 0x00, 0x08, 0x26, 0x00, 0x00, 0x08, 0x24, 0x00, 0x00, 0xcc, 0x2c, 0x00, + 0x00, 0xc4, 0x28, 0x00, 0x00, 0xf6, 0x3b, 0x00, 0x00, 0xf2, 0x23, 0x00, + 0x00, 0xc2, 0x20, 0x00, 0x00, 0xc2, 0x20, 0x00, 0x00, 0xc2, 0x20, 0x00, + 0x00, 0xc2, 0x60, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02, 0x40, 0x00, + 0x00, 0x02, 0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x02, 0x40, 0x00, + 0x00, 0x02, 0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0xe0, 0xff, 0xff, 0x07, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; diff --git a/gnu/games/chess/Xchess/board.c b/gnu/games/chess/Xchess/board.c new file mode 100644 index 000000000000..9ca2bacf657f --- /dev/null +++ b/gnu/games/chess/Xchess/board.c @@ -0,0 +1,179 @@ + +/* This file contains code for X-CHESS. + Copyright (C) 1986 Free Software Foundation, Inc. + +This file is part of X-CHESS. + +X-CHESS is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY. No author or distributor +accepts responsibility to anyone for the consequences of using it +or for whether it serves any particular purpose or works at all, +unless he says so in writing. Refer to the X-CHESS General Public +License for full details. + +Everyone is granted permission to copy, modify and redistribute +X-CHESS, but only under the conditions described in the +X-CHESS General Public License. A copy of this license is +supposed to have been given to you along with X-CHESS so you +can know your rights and responsibilities. It should be in a +file named COPYING. Among other things, the copyright notice +and this notice must be preserved on all copies. */ + + +/* RCS Info: $Revision: 1.1.1.1 $ on $Date: 1993/06/12 14:41:08 $ + * $Source: /home/cvs/386BSD/src/gnu/games/chess/Xchess/board.c,v $ + * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group + * Permission is granted to do anything with this code except sell it + * or remove this message. + * + * Stuff to deal with the board. + */ + +#include "xchess.h" + +board *chessboard; + +void +board_setup() +{ + chessboard = alloc(board); + board_init(chessboard); + return; +} + +void +board_init(b) + board *b; +{ + int i, j; + + for (i = 0; i < 2; i++) + for (j = 0; j < SIZE; j++) + b->square[i][j].color = BLACK; + for (i = 2; i < 6; i++) + for (j = 0; j < SIZE; j++) + b->square[i][j].color = NONE; + for (i = 6; i < 8; i++) + for (j = 0; j < SIZE; j++) + b->square[i][j].color = WHITE; + for (i = 0; i < SIZE; i++) + b->square[1][i].type = b->square[6][i].type = + PAWN; + b->square[0][0].type = b->square[7][0].type = ROOK; + b->square[0][1].type = b->square[7][1].type = KNIGHT; + b->square[0][2].type = b->square[7][2].type = BISHOP; + b->square[0][3].type = b->square[7][3].type = QUEEN; + b->square[0][4].type = b->square[7][4].type = KING; + b->square[0][5].type = b->square[7][5].type = BISHOP; + b->square[0][6].type = b->square[7][6].type = KNIGHT; + b->square[0][7].type = b->square[7][7].type = ROOK; + b->black_cant_castle_k = false; + b->black_cant_castle_q = false; + b->white_cant_castle_k = false; + b->white_cant_castle_q = false; + + return; +} + +void +board_drawall() +{ + int i, j; + + for (i = 0; i < SIZE; i++) + for (j = 0; j < SIZE; j++) + if (chessboard->square[i][j].color != NONE) { + win_drawpiece(&chessboard->square[i][j], i, + j, WHITE); + if (!oneboard) + win_drawpiece(&chessboard->square[i][j], + i, j, BLACK); + } + return; +} + +void +board_move(b, m) + board *b; + move *m; +{ + switch (m->type) { + + case MOVE: + case CAPTURE: + b->square[m->fromy][m->fromx].color = NONE; + b->square[m->toy][m->tox].color = m->piece.color; + b->square[m->toy][m->tox].type = m->piece.type; + if ((m->piece.type == PAWN) && (((m->piece.color == BLACK) && + (m->toy == 7)) || ((m->piece.color == WHITE) && + (m->toy == 0)))) + b->square[m->toy][m->tox].type = QUEEN; + if (m->enpassant) + b->square[m->toy + ((m->piece.color == WHITE) ? 1 : + -1)][m->tox].color = NONE; + break; + + case KCASTLE: + if (m->piece.color == WHITE) { + b->square[7][5].color = m->piece.color; + b->square[7][5].type = ROOK; + b->square[7][6].color = m->piece.color; + b->square[7][6].type = KING; + b->square[7][4].color = NONE; + b->square[7][7].color = NONE; + } else { + b->square[0][5].color = m->piece.color; + b->square[0][5].type = ROOK; + b->square[0][6].color = m->piece.color; + b->square[0][6].type = KING; + b->square[0][4].color = NONE; + b->square[0][7].color = NONE; + } + break; + + case QCASTLE: + if (m->piece.color == WHITE) { + b->square[7][3].color = m->piece.color; + b->square[7][3].type = ROOK; + b->square[7][2].color = m->piece.color; + b->square[7][2].type = KING; + b->square[7][4].color = NONE; + b->square[7][0].color = NONE; + } else { + b->square[0][3].color = m->piece.color; + b->square[0][3].type = ROOK; + b->square[0][2].color = m->piece.color; + b->square[0][2].type = KING; + b->square[0][4].color = NONE; + b->square[0][0].color = NONE; + } + break; + + default: + fprintf(stderr, "Bad move type %d\n", m->type); + } + + if (m->piece.type == KING) { + if (m->piece.color == WHITE) + b->white_cant_castle_q = + b->white_cant_castle_k= true; + else + b->black_cant_castle_q = + b->black_cant_castle_k= true; + } else if (m->piece.type == ROOK) { + if (m->piece.color == WHITE) { + if (m->fromx == 0) + b->white_cant_castle_q = true; + else if (m->fromx == 7) + b->white_cant_castle_k = true; + } else { + if (m->fromx == 0) + b->black_cant_castle_q = true; + else if (m->fromx == 7) + b->black_cant_castle_k = true; + } + } + + return; +} + diff --git a/gnu/games/chess/Xchess/button.c b/gnu/games/chess/Xchess/button.c new file mode 100644 index 000000000000..a080d1465db1 --- /dev/null +++ b/gnu/games/chess/Xchess/button.c @@ -0,0 +1,337 @@ + +/* This file contains code for X-CHESS. + Copyright (C) 1986 Free Software Foundation, Inc. + +This file is part of X-CHESS. + +X-CHESS is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY. No author or distributor +accepts responsibility to anyone for the consequences of using it +or for whether it serves any particular purpose or works at all, +unless he says so in writing. Refer to the X-CHESS General Public +License for full details. + +Everyone is granted permission to copy, modify and redistribute +X-CHESS, but only under the conditions described in the +X-CHESS General Public License. A copy of this license is +supposed to have been given to you along with X-CHESS so you +can know your rights and responsibilities. It should be in a +file named COPYING. Among other things, the copyright notice +and this notice must be preserved on all copies. */ + + +/* RCS Info: $Revision: 1.1.1.1 $ on $Date: 1993/06/12 14:41:15 $ + * $Source: /home/cvs/386BSD/src/gnu/games/chess/Xchess/button.c,v $ + * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group + * Permission is granted to do anything with this code except sell it + * or remove this message. + * + * Do stuff with the buttons. + * The configuration we're using is: Draw Back Pause + * Resign Fwd Flip + * Reset Save Easy (Switch) + */ + +#include "xchess.h" + +typedef enum choice { NOCHOICE, DRAW, RESIGN, REPLAY, SWITCH, FORE, SAVE, + STOP, FLIP, RESTART, EASY } choice; + +static struct but { + char *label; + int x, y; + int width, height; + choice which; +} buts[] = { + { "Draw", 0, 20, 108, 29, DRAW } , + { "Back", 109, 20, 108, 29, REPLAY } , + { "Pause", 219, 20, 108, 29, STOP } , + { "Resign", 0, 50, 108, 29, RESIGN } , + { "Fwd", 109, 50, 108, 29, FORE } , + { "Flip", 219, 50, 108, 29, FLIP } , + { "Reset", 0, 80, 108, 29, RESTART } , + { "Save", 109, 80, 108, 29, SAVE } , +#define EASY_OFFSET 8 + { "Switch", 219, 80, 108, 29, SWITCH } +/* { "NoEasy", 219, 80, 108, 29, EASY }*/ +} ; +static int easy = 1; + +void +button_draw(win) + windata *win; +{ + int i, x, numbuts = sizeof (buts) / sizeof (struct but); + + XSetState(win->display, DefaultGC(win->display, 0), + win->border.pixel, WhitePixel(win->display, 0), + GXcopy, AllPlanes); + XSetLineAttributes(win->display, DefaultGC(win->display, 0), + BORDER_WIDTH, LineSolid, CapButt, + JoinMiter); + + XDrawLine(win->display, win->buttonwin, + DefaultGC(win->display, 0), + 0, 29, BUTTON_WIDTH, 29); + XDrawLine(win->display, win->buttonwin, + DefaultGC(win->display, 0), + 0, 60, BUTTON_WIDTH, 60); + XDrawLine(win->display, win->buttonwin, + DefaultGC(win->display, 0), + 108, 0, 108, BUTTON_HEIGHT); + XDrawLine(win->display, win->buttonwin, + DefaultGC(win->display, 0), + 219, 0, 219, BUTTON_HEIGHT); + + XSetFont(win->display, DefaultGC(win->display, 0), win->large->fid); + XSetForeground(win->display, DefaultGC(win->display, 0), + win->textcolor.pixel); + XSetBackground(win->display, DefaultGC(win->display, 0), + win->textback.pixel); + + for (i = 0; i < numbuts; i++) { + x = (buts[i].width - + XTextWidth(win->large, buts[i].label, + strlen(buts[i].label))) / 2; + + XDrawImageString(win->display, win->buttonwin, + DefaultGC(win->display, 0), + buts[i].x + x, buts[i].y, buts[i].label, + strlen(buts[i].label)); + } + return; +} + +void +button_service(win, event) + windata *win; + XEvent *event; +{ + XKeyEvent *ev = &event->xkey; + choice c; + int i, numbuts = sizeof (buts) / sizeof (struct but); + char *s; + + ev->y += 15; + for (i = 0; i < numbuts; i++) + if ((ev->x >= buts[i].x) && (ev->x <= buts[i].x + + buts[i].width) && (ev->y >= buts[i].y) && + (ev->y <= buts[i].y + buts[i].height)) { + c = buts[i].which; + break; + } + if ((i == numbuts) || (c == NOCHOICE)) { + message_add(win, "Bad choice.\n", true); + return; + } + + if (loading_flag && (c != STOP)) { + message_add(win, "You can only use PAUSE now\n", true); + return; + } + + switch (c) { + case DRAW: + if (!oneboard) { + message_add(win, "Just a sec...\n", false); + if (!pop_question(((win == win1) ? win2 : win1), +"The other player wants\nto call the game a draw.\nDo you agree?\n")) { + message_add(win, + "The other player declines the draw\n", false); + return; + } + } + message_add(win1, "Draw agreed.\n", false); + if (!oneboard) + message_add(win2, "Draw agreed.\n", false); + cleanup("Draw agreed."); + break; + + case RESIGN: + if (!pop_question(win, "Are you sure\nyou want to resign?")) + return; + if ((oneboard && !progflag) || (nexttomove == win->color)) { + if (nexttomove == WHITE) + s = "White resigns."; + else + s = "Black resigns."; + if (oneboard) { + message_add(win, s, false); + message_add(win, "\n", false); + } else { + message_add(win1, s, false); + message_add(win, "\n", false); + message_add(win2, s, false); + message_add(win, "\n", false); + } + sleep(5); + cleanup(s); + } else { + message_add(win, "It's not your turn.\n", true); + } + break; + + case REPLAY: + if (!oneboard) { + message_add(win, "Just a sec...\n", false); + if (!pop_question(((win == win1) ? win2 : win1), +"The other player wants\nto take back his last move.\nDo you let him?\n")) { + message_add(win, + "The other player refuses...\n", false); + return; + } + } + if (!moves) { + message_add(win, "Can't back up...\n", true); + break; + } + message_add(win1, "Replaying...\n", false); + if (!oneboard) + message_add(win2, "Replaying...\n", false); + replay(); + if (progflag) + replay(); + break; + + case FORE: + if (!oneboard) { + message_add(win, "Just a sec...\n", false); + if (!pop_question(((win == win1) ? win2 : win1), +"The other player wants\nto do a 'fore'.\nIs that ok with you?\n")) { + message_add(win, + "The other player refuses...\n", false); + return; + } + } + if (!foremoves) { + message_add(win, "Can't go forward...\n", true); + break; + } + message_add(win1, "Moving forward...\n", false); + if (!oneboard) + message_add(win2, "Moving forward...\n", false); + forward(); + break; + + case SWITCH: + message_add(win, "You can't switch yet.\n", false); + break; + + case SAVE: + if (saveflag) { + message_add(win, + "Game is already being logged in file '", true); + message_add(win, record_file, true); + message_add(win, "'.\n", true); + } else { + message_add(win, "Saving game to file '", false); + message_add(win, record_file, false); + message_add(win, "'.\n", false); + record_save(); + } + break; + + case STOP: + if (loading_flag) { + loading_paused = (loading_paused ? false : true); + message_add(win, loading_paused ? + "Stopped.\nHit 'Pause' again to restart.\n" : + "Restarted.\n", false); + } else if (clock_started) { + if (!oneboard) { + message_add(win, "Just a sec...\n", false); + if (!pop_question(((win == win1) ? win2 : win1), +"The other player wants\nto stop the clock.\nDo you let him?\n")) { + message_add(win, + "The other player refuses to pause.\n", + false); + return; + } + } + message_add(win1, + "Clock stopped.\nHit 'Pause' again to restart.\n", + false); + if (!oneboard) + message_add(win2, + "Clock stopped.\nHit 'Pause' again to restart.\n", + false); + clock_started = false; + } else { + if (!oneboard) { + message_add(win, "Just a sec...\n", false); + if (!pop_question(((win == win1) ? win2 : win1), +"The other player wants\nto start the clock again.\nIs that ok?\n")) { + message_add(win, + "The other player refuses to resume.\n", + false); + return; + } + } + message_add(win1, "Clock restarted.\n", false); + if (!oneboard) + message_add(win2, "Clock restarted.\n", false); + clock_started = true; + } + break; + + case FLIP: + message_add(win, "Flipping window...\n", false); + win->flipped = win->flipped ? false : true; + win_redraw(win, (XEvent *) NULL); + break; + + case RESTART: + if (!oneboard) { + message_add(win, "Just a sec...\n", false); + if (!pop_question(((win == win1) ? win2 : win1), +"The other player wants\nto restart the game.\nDo you agree?\n")) { + message_add(win, + "The other player refuses to reset\n", false); + return; + } + } + message_add(win, "Restarting game.\n", false); + restart(); + break; + case EASY: + if (oneboard) { + int x; + if (easy) + easy = 0; + else + easy = 1; + + if (easy) + buts[EASY_OFFSET].label = " Easy "; + else + buts[EASY_OFFSET].label = "NoEasy"; + + program_easy(easy); + + x = (buts[EASY_OFFSET].width - + XTextWidth(win->large, + buts[EASY_OFFSET].label, + strlen(buts[EASY_OFFSET].label))) / 2; + + XSetFont(win->display, DefaultGC(win->display, + 0), win->large->fid); + XSetForeground(win->display, + DefaultGC(win->display, 0), + win->textcolor.pixel); + XSetBackground(win->display, + DefaultGC(win->display, 0), + win->textback.pixel); + + XDrawImageString(win->display, + win->buttonwin, + DefaultGC(win->display, 0), + buts[EASY_OFFSET].x + x, + buts[EASY_OFFSET].y, + buts[EASY_OFFSET].label, + strlen(buts[EASY_OFFSET].label)); + } + break; + } + return; +} + diff --git a/gnu/games/chess/Xchess/clock.c b/gnu/games/chess/Xchess/clock.c new file mode 100644 index 000000000000..c3877151f3bf --- /dev/null +++ b/gnu/games/chess/Xchess/clock.c @@ -0,0 +1,291 @@ + +/* This file contains code for X-CHESS. + Copyright (C) 1986 Free Software Foundation, Inc. + +This file is part of X-CHESS. + +X-CHESS is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY. No author or distributor +accepts responsibility to anyone for the consequences of using it +or for whether it serves any particular purpose or works at all, +unless he says so in writing. Refer to the X-CHESS General Public +License for full details. + +Everyone is granted permission to copy, modify and redistribute +X-CHESS, but only under the conditions described in the +X-CHESS General Public License. A copy of this license is +supposed to have been given to you along with X-CHESS so you +can know your rights and responsibilities. It should be in a +file named COPYING. Among other things, the copyright notice +and this notice must be preserved on all copies. */ + + +/* RCS Info: $Revision: 1.1.1.1 $ on $Date: 1993/06/12 14:41:08 $ + * $Source: /home/cvs/386BSD/src/gnu/games/chess/Xchess/clock.c,v $ + * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group + * Permission is granted to do anything with this code except sell it + * or remove this message. + * + * Do stuff with the clocks. The way things work is as follows. We call + * clock_init to draw the clocks initially, but they don't actually start + * running until we call clock_switch for the first time. + */ + +#include "xchess.h" + +int movesperunit = 0; +int timeunit = 0; +bool clock_started = false; +int whiteseconds, blackseconds; + +static bool white_running = true; +static long lastwhite, lastblack; +static bool firstmove = true; + +extern void dohands(), hilight(); + +#define PI 3.1415926535897932384 + +void +clock_draw(win, col) + windata *win; + color col; +{ + int i; + char buf[BSIZE]; + int x = CLOCK_WIDTH / 2, y = CLOCK_WIDTH / 2; + int xp, yp; + int rad = CLOCK_WIDTH / 2 - 10; + Window w = ((col == WHITE) ? win->wclockwin : win->bclockwin); + + /* Draw a clock face and the hands. */ + XCircle(w, x, y, rad, 0.0, 0.0, 1, 1, win->textcolor.pixel, GXcopy, + AllPlanes); + rad -= 8; + + XSetFont(win->display, DefaultGC(win->display, 0), + win->small->fid); + XSetForeground(win->display, DefaultGC(win->display, 0), + win->textcolor.pixel); + XSetBackground(win->display, DefaultGC(win->display, 0), + win->textback.pixel); + for (i = 1; i <= 12; i++) { + xp = x + rad * cos(PI * 3 / 2 + i * PI / 6) - 4; + yp = y + rad * sin(PI * 3 / 2 + i * PI / 6) - 5; + sprintf(buf, "%d", i); + XDrawString(win->display, w, DefaultGC(win->display, 0), + xp, yp, buf, strlen(buf)); + } + + dohands(win, col); + + if (white_running) { + hilight(win, WHITE, true); + hilight(win, BLACK, false); + } else { + hilight(win, WHITE, false); + hilight(win, BLACK, true); + } + return; +} + +void +clock_init(win, col) + windata *win; + color col; +{ + whiteseconds = blackseconds = 0; + clock_started = false; + firstmove = true; + clock_draw(win, col); + + return; +} + +void +clock_update() +{ + int now = time((long *) NULL); + int i; + + if (!clock_started) { + lastwhite = lastblack = now; + return; + } + + if (white_running) { + whiteseconds += now - lastwhite; + lastwhite = now; + dohands(win1, WHITE); + if (!oneboard) + dohands(win2, WHITE); + if (timeunit) { + i = whiteseconds / timeunit; + if ((i > 0) && (whiteseconds > i * timeunit) && + (whiteseconds < i * timeunit + 10) && + (movesperunit * i > movenum)) { + message_add(win1, + "White has exceeded his time limit\n", + true); + if (!oneboard) { + message_add(win2, + "White has exceeded his time limit\n", + true); + } + timeunit = 0; + } + } + } else { + blackseconds += now - lastblack; + lastblack = now; + dohands(win1, BLACK); + if (!oneboard) + dohands(win2, BLACK); + if (timeunit) { + i = blackseconds / timeunit; + if ((i > 0) && (blackseconds > i * timeunit) && + (blackseconds < i * timeunit + 10) && + (movesperunit * i > movenum)) { + message_add(win1, + "Black has exceeded his time limit\n", + true); + if (!oneboard) { + message_add(win2, + "Black has exceeded his time limit\n", + true); + } + timeunit = 0; + } + } + } + return; +} + +void +clock_switch() +{ + if (firstmove) { + clock_started = true; + firstmove = false; + lastwhite = lastblack = time((long *) NULL); + } + if (white_running) { + white_running = false; + lastblack = time((long *) NULL); + hilight(win1, WHITE, false); + hilight(win1, BLACK, true); + if (!oneboard) { + hilight(win2, WHITE, false); + hilight(win2, BLACK, true); + } + } else { + white_running = true; + lastwhite = time((long *) NULL); + hilight(win1, WHITE, true); + hilight(win1, BLACK, false); + if (!oneboard) { + hilight(win2, WHITE, true); + hilight(win2, BLACK, false); + } + } + return; +} + +static void +dohands(win, col) + windata *win; + color col; +{ + int cx = CLOCK_WIDTH / 2, cy = CLOCK_WIDTH / 2; + double *h = (col == WHITE) ? win->whitehands : win->blackhands; + Window w = (col == WHITE) ? win->wclockwin : win->bclockwin; + long secs = (col == WHITE) ? whiteseconds : blackseconds; + int rad, x, y, i; + + /* First erase the old hands. */ + XSetState(win->display, DefaultGC(win->display, 0), + win->textback.pixel, win->textback.pixel, + GXcopy, AllPlanes); + + rad = CLOCK_WIDTH / 2 - 30; + for (i = 0; i < 3; i++) { + x = cx + rad * sin(PI - h[i]); + y = cy + rad * cos(PI - h[i]); + XSetLineAttributes(win->display, + DefaultGC(win->display, 0), + i, LineSolid, 0, 0); + XDrawLine(win->display, w, DefaultGC(win->display, 0), + cx, cy, x, y); + rad -= 8; + } + + h[0] = (secs % 60) * 2 * PI / 60; + h[1] = ((secs / 60) % 60) * 2 * PI / 60; + h[2] = ((secs / 3600) % 12) * 2 * PI / 12; + + /* Now draw the new ones. */ + + XSetState(win->display, DefaultGC(win->display, 0), + win->textcolor.pixel, win->textback.pixel, + GXcopy, AllPlanes); + + rad = CLOCK_WIDTH / 2 - 30; + for (i = 0; i < 3; i++) { + x = cx + rad * sin(PI - h[i]); + y = cy + rad * cos(PI - h[i]); + XSetLineAttributes(win->display, + DefaultGC(win->display, 0), + i, LineSolid, 0, 0); + XDrawLine(win->display, w, DefaultGC(win->display, 0), + cx, cy, x, y); + rad -= 8; + } + XFlush(win->display); + return; +} + +static void +hilight(win, col, on) + windata *win; + color col; + bool on; +{ + Window w = (col == WHITE) ? win->wclockwin : win->bclockwin; + char *s = (col == WHITE) ? " WHITE " : " BLACK "; + int x; + + + x = XTextWidth(win->large, s, strlen(s)); + if (on) + XSetState(win->display, DefaultGC(win->display, 0), + win->textback.pixel, + win->textcolor.pixel, + GXcopy, + AllPlanes); + else + XSetState(win->display, DefaultGC(win->display, 0), + win->textcolor.pixel, + win->textback.pixel, + GXcopy, AllPlanes); + + XSetLineAttributes(win->display, DefaultGC(win->display, 0), + BORDER_WIDTH, LineSolid, CapButt, JoinMiter); + XSetFont(win->display, DefaultGC(win->display, 0), + win->large->fid); + + XDrawLine(win->display, w, DefaultGC(win->display, 0), + 0, CLOCK_HEIGHT - 26, + CLOCK_WIDTH, CLOCK_HEIGHT - 26); + + XDrawImageString(win->display, w, DefaultGC(win->display, 0), + (CLOCK_WIDTH - x) / 2, CLOCK_HEIGHT, + s, strlen(s)); + + if (on) + XSetState(win->display, DefaultGC(win->display, 0), + win->textcolor.pixel, + win->textback.pixel, + GXcopy, AllPlanes); + return; +} + diff --git a/gnu/games/chess/Xchess/control.c b/gnu/games/chess/Xchess/control.c new file mode 100644 index 000000000000..8591bd7176da --- /dev/null +++ b/gnu/games/chess/Xchess/control.c @@ -0,0 +1,515 @@ +/* This file contains code for X-CHESS. + Copyright (C) 1986 Free Software Foundation, Inc. + +This file is part of X-CHESS. + +X-CHESS is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY. No author or distributor +accepts responsibility to anyone for the consequences of using it +or for whether it serves any particular purpose or works at all, +unless he says so in writing. Refer to the X-CHESS General Public +License for full details. + +Everyone is granted permission to copy, modify and redistribute +X-CHESS, but only under the conditions described in the +X-CHESS General Public License. A copy of this license is +supposed to have been given to you along with X-CHESS so you +can know your rights and responsibilities. It should be in a +file named COPYING. Among other things, the copyright notice +and this notice must be preserved on all copies. */ + + +/* RCS Info: $Revision: 1.1.1.1 $ on $Date: 1993/06/12 14:41:11 $ + * $Source: /home/cvs/386BSD/src/gnu/games/chess/Xchess/control.c,v $ + * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group + * Permission is granted to do anything with this code except sell it + * or remove this message. + * + * Deal with input from the user. + */ + +#include "xchess.h" + +move *moves; +move *foremoves; +color nexttomove = WHITE; +bool noisyflag = false; + +move *lastmove; +static move *thismove; + +static void screen_move(); + +void +button_pressed(event, win) + XEvent *event; + windata *win; +{ + int x, y; + XKeyEvent *ev = (XKeyEvent *) event; + + if (!oneboard && (win->color != nexttomove)) { + message_add(win, "Wrong player!\n", true); + return; + } + if (progflag && (nexttomove == (blackflag ? WHITE : BLACK))) { + message_add(win, "Wait for the computer...\n", true); + return; + } + if (loading_flag) { + message_add(win, "You'd better not do that now...\n", true); + return; + } + + /* Figure out what piece he is pointing at. */ + x = ev->x / (SQUARE_WIDTH + BORDER_WIDTH); + y = ev->y / (SQUARE_HEIGHT + BORDER_WIDTH); + + if (win->flipped) { + y = SIZE - y - 1; + x = SIZE - x - 1; + } + + if ((x < 0) || (x >= SIZE) || (y < 0) || (y >= SIZE)) { + fprintf(stderr, "Bad coords (%d, %d)\n", x, y); + return; + } + + if (oneboard && (chessboard->square[y][x].color != nexttomove)) { + message_add(win, "Wrong player!\n", true); + return; + } else if (!oneboard && (chessboard->square[y][x].color != + win->color)) { + message_add(win, "Can't move that\n", true); + return; + } + + thismove = alloc(move); + thismove->fromx = x; + thismove->fromy = y; + thismove->piece.color = chessboard->square[y][x].color; + thismove->piece.type = chessboard->square[y][x].type; + + if (debug) + fprintf(stderr, "%s selected his %s at (%d, %d)...\n", + colornames[(int) thismove->piece.color], + piecenames[(int) thismove->piece.type], + thismove->fromy, thismove->fromx); + return; +} + +void +button_released(event, win) + XEvent *event; + windata *win; +{ + int x, y; + XKeyEvent *ev = (XKeyEvent *) event; + + if (!thismove) { + /* fprintf(stderr, "Error: button hasn't been pressed\n"); */ + return; + } + if (loading_flag) + return; + + /* Figure out what piece he is pointing at. */ + x = ev->x / (SQUARE_WIDTH + BORDER_WIDTH); + y = ev->y / (SQUARE_HEIGHT + BORDER_WIDTH); + + if (win->flipped) { + y = SIZE - y - 1; + x = SIZE - x - 1; + } + + if ((x < 0) || (x >= SIZE) || (y < 0) || (y >= SIZE)) { + fprintf(stderr, "Bad coords (%d, %d)\n", x, y); + return; + } + + if ((thismove->fromx == x) && (thismove->fromy == y)) { + message_add(win, "Hey, you touch it, you move it, buddy.\n", + true); + return; + } + if (chessboard->square[y][x].color == thismove->piece.color) { + message_add(win, "Can't put one piece on top of another\n", + true); + return; + } + + thismove->tox = x; + thismove->toy = y; + thismove->taken.color = chessboard->square[y][x].color; + thismove->taken.type = chessboard->square[y][x].type; + if (thismove->taken.color != NONE) + thismove->type = CAPTURE; + else if ((thismove->piece.type == KING) && (thismove->fromx == 4) && + (thismove->tox == 6) && + (thismove->toy == thismove->fromy)) + thismove->type = KCASTLE; + else if ((thismove->piece.type == KING) && (thismove->tox == 2) && + (thismove->fromx == 4) && + (thismove->toy == thismove->fromy)) + thismove->type = QCASTLE; + else + thismove->type = MOVE; + + /* Now check the en-passant case... */ + if ((thismove->type == MOVE) && ((thismove->tox == thismove->fromx + 1) + || (thismove->tox == thismove->fromx - 1)) && + (thismove->piece.type == PAWN) && lastmove && + (lastmove->tox == lastmove->fromx) && (lastmove->fromx + == thismove->tox) && ((lastmove->fromy + lastmove->toy) + / 2 == thismove->toy)) { + thismove->type = CAPTURE; + thismove->enpassant = true; + thismove->taken = lastmove->piece; + } + + if (!valid_move(thismove, chessboard)) { + message_add(win, "Invalid move.\n", true); + return; + } + + if (debug) + fprintf(stderr, "\t... and moved it to (%d, %d), type %s\n", + thismove->toy, thismove->tox, + movetypenames[(int) thismove->type]); + move_piece(thismove); + + if (thismove->check) { + message_add(win1, "Check.\n", true); + if (!oneboard) { + message_add(win2, "Check.\n", true); + } + } + + if (!moves) + moves = lastmove = thismove; + else + lastmove = lastmove->next = thismove; + + if (progflag) + program_send(thismove); + + thismove = NULL; + nexttomove = ((nexttomove == WHITE) ? BLACK : WHITE); + clock_switch(); + + return; +} + +void +prog_move(m) + move *m; +{ + if (debug) + fprintf(stderr, "program moves from (%d, %d) to (%d, %d)\n", + m->fromy, m->fromx, m->toy, m->tox); + move_piece(m); + + if (!moves) + moves = lastmove = m; + else + lastmove = lastmove->next = m; + + nexttomove = ((nexttomove == WHITE) ? BLACK : WHITE); + clock_switch(); + + return; +} + +void +move_piece(m) + move *m; +{ + /* Update the screen... */ + screen_move(m); + + /* Move the piece on the board... */ + board_move(chessboard, m); + + /* And record it... */ + record_move(m); + + if (noisyflag) { + XBell(win1->display, 50); + XBell(win2->display, 50); + } + return; +} + +static void +screen_move(m) + move *m; +{ + piece pp; + + switch (m->type) { + case CAPTURE: + jail_add(&m->taken); + /* FALLTHRU */ + + case MOVE: + win_erasepiece(m->fromy, m->fromx, WHITE); + if (win_flashmove) + win_flash(m, WHITE); + win_drawpiece(&m->piece, m->toy, m->tox, WHITE); + if (m->enpassant) + win_erasepiece(m->toy + ((m->piece.color == WHITE) ? + 1 : -1), m->tox, WHITE); + if (!oneboard) { + win_erasepiece(m->fromy, m->fromx, BLACK); + if (win_flashmove) + win_flash(m, BLACK); + win_drawpiece(&m->piece, m->toy, m->tox, BLACK); + if (m->enpassant) + win_erasepiece(m->toy + ((m->piece.color == + WHITE) ? 1 : -1), m->tox, WHITE); + } + if ((m->piece.type == PAWN) && (((m->piece.color == BLACK) && + (m->toy == 7)) || ((m->piece.color == WHITE) && + (m->toy == 0)))) { + pp.color = m->piece.color; + pp.type = QUEEN; + win_drawpiece(&pp, m->toy, m->tox, WHITE); + if (!oneboard) + win_drawpiece(&m->piece, m->toy, m->tox, BLACK); + } + break; + + case KCASTLE: + if (m->piece.color == WHITE) { + win_erasepiece(7, 4, WHITE); + win_erasepiece(7, 7, WHITE); + if (win_flashmove) + win_flash(m, WHITE); + win_drawpiece(&m->piece, 7, 6, WHITE); + win_drawpiece(&chessboard->square[7][7], 7, 5, WHITE); + if (!oneboard) { + win_erasepiece(7, 4, BLACK); + win_erasepiece(7, 7, BLACK); + if (win_flashmove) + win_flash(m, BLACK); + win_drawpiece(&m->piece, 7, 6, BLACK); + win_drawpiece(&chessboard->square[7][7], 7, 5, + BLACK); + } + } else { + win_erasepiece(0, 4, WHITE); + win_erasepiece(0, 7, WHITE); + if (win_flashmove) + win_flash(m, WHITE); + win_drawpiece(&m->piece, 0, 6, WHITE); + win_drawpiece(&chessboard->square[0][7], 0, 5, WHITE); + if (!oneboard) { + win_erasepiece(0, 4, BLACK); + win_erasepiece(0, 7, BLACK); + if (win_flashmove) + win_flash(m, BLACK); + win_drawpiece(&m->piece, 0, 6, BLACK); + win_drawpiece(&chessboard->square[0][7], 0, 5, + BLACK); + } + } + break; + + case QCASTLE: + if (m->piece.color == WHITE) { + win_erasepiece(7, 4, WHITE); + win_erasepiece(7, 0, WHITE); + if (win_flashmove) + win_flash(m, WHITE); + win_drawpiece(&m->piece, 7, 2, WHITE); + win_drawpiece(&chessboard->square[7][0], 7, 3, WHITE); + if (!oneboard) { + win_erasepiece(7, 4, BLACK); + win_erasepiece(7, 0, BLACK); + if (win_flashmove) + win_flash(m, BLACK); + win_drawpiece(&m->piece, 7, 2, BLACK); + win_drawpiece(&chessboard->square[7][7], 7, 3, + BLACK); + } + } else { + win_erasepiece(0, 4, WHITE); + win_erasepiece(0, 0, WHITE); + if (win_flashmove) + win_flash(m, WHITE); + win_drawpiece(&m->piece, 0, 2, WHITE); + win_drawpiece(&chessboard->square[0][0], 0, 3, WHITE); + if (!oneboard) { + win_erasepiece(0, 4, BLACK); + win_erasepiece(0, 0, BLACK); + if (win_flashmove) + win_flash(m, BLACK); + win_drawpiece(&m->piece, 0, 2, BLACK); + win_drawpiece(&chessboard->square[0][7], 0, 3, + BLACK); + } + } + break; + + default: + fprintf(stderr, "Bad move type %d\n", m->type); + } + return; +} + +/* Retract the last move made... */ + +void +replay() +{ + move *m = lastmove, bm; + + memset(&bm, 0, sizeof(bm)); + switch (m->type) { + case MOVE: + bm.type = MOVE; + bm.piece = m->piece; + bm.fromx = m->tox; + bm.fromy = m->toy; + bm.tox = m->fromx; + bm.toy = m->fromy; + board_move(chessboard, &bm); + screen_move(&bm); + break; + + case CAPTURE: + bm.type = MOVE; + bm.piece = m->piece; + bm.fromx = m->tox; + bm.fromy = m->toy; + bm.tox = m->fromx; + bm.toy = m->fromy; + board_move(chessboard, &bm); + screen_move(&bm); + chessboard->square[m->toy][m->tox] = m->taken; + bm.piece = m->taken; + bm.fromx = bm.tox = m->tox; + bm.fromy = bm.toy = m->toy; + screen_move(&bm); + jail_remove(&m->taken); + break; + + case KCASTLE: + bm.type = MOVE; + bm.piece.type = KING; + bm.piece.color = m->piece.color; + bm.fromx = 6; + bm.tox = 4; + bm.fromy = bm.toy = (m->piece.color == WHITE) ? 7 : 0; + board_move(chessboard, &bm); + screen_move(&bm); + bm.type = MOVE; + bm.piece.type = ROOK; + bm.piece.color = m->piece.color; + bm.fromx = 5; + bm.tox = 7; + bm.fromy = bm.toy = (m->piece.color == WHITE) ? 7 : 0; + board_move(chessboard, &bm); + screen_move(&bm); + if (m->piece.color == WHITE) + chessboard->white_cant_castle_k = false; + else + chessboard->black_cant_castle_k = false; + break; + + case QCASTLE: + bm.type = MOVE; + bm.piece.type = KING; + bm.piece.color = m->piece.color; + bm.fromx = 2; + bm.tox = 4; + bm.fromy = bm.toy = (m->piece.color == WHITE) ? 7 : 0; + board_move(chessboard, &bm); + screen_move(&bm); + bm.type = MOVE; + bm.piece.type = ROOK; + bm.piece.color = m->piece.color; + bm.fromx = 3; + bm.tox = 0; + bm.fromy = bm.toy = (m->piece.color == WHITE) ? 7 : 0; + board_move(chessboard, &bm); + screen_move(&bm); + if (m->piece.color == WHITE) + chessboard->white_cant_castle_q = false; + else + chessboard->black_cant_castle_q = false; + break; + } + record_back(); + + nexttomove = ((nexttomove == WHITE) ? BLACK : WHITE); + clock_switch(); + + if (!moves->next) { + moves->next = foremoves; + foremoves = moves; + moves = lastmove = NULL; + } else { + for (m = moves; m->next; m = m->next) + lastmove = m; + lastmove->next->next = foremoves; + foremoves = lastmove->next; + lastmove->next = NULL; + } + + if (progflag) + program_undo(); + + return; +} + +/* Put back the last move undone. */ + +void +forward() +{ + prog_move(foremoves); + foremoves = foremoves->next; + return; +} + +/* End the game. */ + +void +cleanup(s) + char *s; +{ + if (progflag) + program_end(); + record_end(s); + XSync(win1->display, 0); + if (!oneboard) { + XSync(win2->display, 0); + } + exit(0); +} + +void +restart() +{ + moves = lastmove = thismove = NULL; + nexttomove = WHITE; + + clock_init(win1, WHITE); + clock_init(win1, BLACK); + jail_init(win1); + if (!oneboard) { + clock_init(win2, WHITE); + clock_init(win2, BLACK); + jail_init(win2); + } + board_init(chessboard); + win_restart(); + record_reset(); + if (progflag) { + program_end(); + program_init(progname); + } + return; +} + diff --git a/gnu/games/chess/Xchess/jail.c b/gnu/games/chess/Xchess/jail.c new file mode 100644 index 000000000000..7ca901301120 --- /dev/null +++ b/gnu/games/chess/Xchess/jail.c @@ -0,0 +1,327 @@ + +/* This file contains code for X-CHESS. + Copyright (C) 1986 Free Software Foundation, Inc. + +This file is part of X-CHESS. + +X-CHESS is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY. No author or distributor +accepts responsibility to anyone for the consequences of using it +or for whether it serves any particular purpose or works at all, +unless he says so in writing. Refer to the X-CHESS General Public +License for full details. + +Everyone is granted permission to copy, modify and redistribute +X-CHESS, but only under the conditions described in the +X-CHESS General Public License. A copy of this license is +supposed to have been given to you along with X-CHESS so you +can know your rights and responsibilities. It should be in a +file named COPYING. Among other things, the copyright notice +and this notice must be preserved on all copies. */ + + +/* RCS Info: $Revision: 1.1.1.1 $ on $Date: 1993/06/12 14:41:12 $ + * $Source: /home/cvs/386BSD/src/gnu/games/chess/Xchess/jail.c,v $ + * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group + * Permission is granted to do anything with this code except sell it + * or remove this message. + * + */ + +#include "xchess.h" + +#include "pawn_small.bitmap" +#include "rook_small.bitmap" +#include "knight_small.bitmap" +#include "bishop_small.bitmap" +#include "queen_small.bitmap" +#include "king_small.bitmap" + +#include "pawn_small_outline.bitmap" +#include "rook_small_outline.bitmap" +#include "knight_small_outline.bitmap" +#include "bishop_small_outline.bitmap" +#include "queen_small_outline.bitmap" +#include "king_small_outline.bitmap" + +static bool pos[32]; + +static piecetype pcs[] = { KING, QUEEN, ROOK, ROOK, BISHOP, BISHOP, KNIGHT, + KNIGHT, PAWN, PAWN, PAWN, PAWN, PAWN, PAWN, PAWN, PAWN } ; + +extern int piecepos(); +extern char *bitsget(); + +void +jail_init(win) + windata *win; +{ + int i; + + for (i = 0; i < 32; i++) + pos[i] = false; + jail_draw(win); + return; +} + +#define JAIL_HEADER "Captured Pieces" + +void +jail_draw(win) + windata *win; +{ + int i; + char *bits; + Pixmap tmpPM; + piece p; + + i = XTextWidth(win->large, JAIL_HEADER, strlen(JAIL_HEADER)); + XSetFont(win->display, DefaultGC(win->display, 0), + win->large->fid); + XSetForeground(win->display, DefaultGC(win->display, 0), + win->textcolor.pixel); + XSetBackground(win->display, DefaultGC(win->display, 0), + win->textback.pixel); + + XDrawImageString(win->display, win->jailwin, + DefaultGC(win->display, 0), + (JAIL_WIDTH - i) / 2, 20, JAIL_HEADER, + strlen(JAIL_HEADER)); + + XSetForeground(win->display, DefaultGC(win->display, 0), + win->blackpiece.pixel); + XSetBackground(win->display, DefaultGC(win->display, 0), + win->textback.pixel); + XSetFillStyle(win->display, DefaultGC(win->display, 0), + FillSolid); + XSetFunction(win->display, DefaultGC(win->display, 0), + GXcopy); + + for (i = 0; i < 16; i++) + if (pos[i]) { + p.color = WHITE; + p.type = pcs[i]; + bits = bitsget(&p); + tmpPM = XCreateBitmapFromData(win->display, + win->jailwin, bits, + 32, 32); + + XCopyPlane(win->display, tmpPM, win->jailwin, + DefaultGC(win->display, 0), + 0, 0, 32, 32, + 5 + (i % 8) * 32, 25 + (i / 8) * 32, + 1); + XFreePixmap(win->display, tmpPM); + } else { + XFillRectangle(win->display, win->jailwin, + DefaultGC(win->display, 0), + 5 + (i % 8) * 32, + 25 + (i / 8) * 32, + 32, 32); + } + for (i = 0; i < 16; i++) + if (pos[i + 16]) { + p.color = BLACK; + p.type = pcs[i]; + bits = bitsget(&p); + tmpPM = XCreateBitmapFromData(win->display, + win->jailwin, bits, + 32, 32); + + XCopyPlane(win->display, tmpPM, win->jailwin, + DefaultGC(win->display, 0), + 0, 0, 32, 32, + 5 + (i % 8) * 32, 94 + (i / 8) * 32, + 1); + XFreePixmap(win->display, tmpPM); + } else { + XFillRectangle(win->display, win->jailwin, + DefaultGC(win->display, 0), + 5 + (i % 8) * 32, 94 + (i / 8) * 32, + 32, 32); + } + + return; +} + +void +jail_add(p) + piece *p; +{ + int i = piecepos(p, false); + char *bits; + Pixmap tmpPM; + + pos[i] = true; + + bits = bitsget(p); + + XSetState(win1->display, DefaultGC(win1->display, 0), + win1->blackpiece.pixel, + win1->textback.pixel, + GXcopy, + AllPlanes); + + tmpPM = XCreateBitmapFromData(win1->display, + win1->jailwin, bits, + 32, 32); + + XCopyPlane(win1->display, tmpPM, win1->jailwin, + DefaultGC(win1->display, 0), + 0, 0, 32, 32, + 5 + (i % 8) * 32, ((i >= 16) ? 30 : 25) + (i / 8) * 32, + 1); + XFreePixmap(win1->display, tmpPM); + + if (!oneboard) { + XSetState(win2->display, DefaultGC(win2->display, 0), + win2->blackpiece.pixel, + win2->textback.pixel, + GXcopy, + AllPlanes); + + + tmpPM = XCreateBitmapFromData(win2->display, + win2->jailwin, bits, + 32, 32); + + XCopyPlane(win2->display, tmpPM, win2->jailwin, + DefaultGC(win2->display, 0), + 0, 0, 32, 32, + 5 + (i % 8) * 32, ((i >= 16) ? 30 : 25) + (i / 8) * 32, + 1); + XFreePixmap(win2->display, tmpPM); + } + + return; +} + +void +jail_remove(p) + piece *p; +{ + int i = piecepos(p, true); + + pos[i] = false; + + + XSetForeground(win1->display, + DefaultGC(win1->display, 0), + win1->blackpiece.pixel); + XSetBackground(win1->display, + DefaultGC(win1->display, 0), + win1->textback.pixel); + XSetFillStyle(win1->display, + DefaultGC(win1->display, 0), + FillSolid); + + XFillRectangle(win1->display, win1->jailwin, + DefaultGC(win1->display, 0), + 5 + (i % 8) * 32, + ((i >= 16) ? 30 : 25) + (i / 8) * 32, + 32, 32); + + if (!oneboard) { + XSetForeground(win2->display, + DefaultGC(win2->display, 0), + win2->blackpiece.pixel); + XSetBackground(win2->display, + DefaultGC(win2->display, 0), + win2->textback.pixel); + XSetFillStyle(win2->display, + DefaultGC(win2->display, 0), + FillSolid); + + XFillRectangle(win2->display, win2->jailwin, + DefaultGC(win2->display, 0), + 5 + (i % 8) * 32, + ((i >= 16) ? 30 : 25) + (i / 8) * 32, + 32, 32); + } + + return; +} + +static char *bitsget(p) + piece *p; +{ + char *bits; + + switch (p->type) { + case PAWN: + bits = (p->color == WHITE) ? pawn_small_outline_bits : + pawn_small_bits; + break; + + case ROOK: + bits = (p->color == WHITE) ? rook_small_outline_bits : + rook_small_bits; + break; + + case KNIGHT: + bits = (p->color == WHITE) ? knight_small_outline_bits : + knight_small_bits; + break; + + case BISHOP: + bits = (p->color == WHITE) ? bishop_small_outline_bits : + bishop_small_bits; + break; + + case QUEEN: + bits = (p->color == WHITE) ? queen_small_outline_bits : + queen_small_bits; + break; + + case KING: + bits = (p->color == WHITE) ? king_small_outline_bits : + king_small_bits; + break; + } + return (bits); +} + +static int +piecepos(p, there) + piece *p; + bool there; +{ + int i, base = (p->color == WHITE) ? 0 : 16; + + switch (p->type) { + case PAWN: + for (i = base + 8; (i < base + 15) && pos[i]; i++) + ; + if (there && !pos[i]) + i--; + break; + + case KING: + /* Hmm... */ + i = base; + break; + + case QUEEN: + i = base + 1; + break; + + case ROOK: + i = base + 2; + if ((there && pos[i + 1]) || (!there && pos[i])) + i++; + break; + + case BISHOP: + i = base + 4; + if ((there && pos[i + 1]) || (!there && pos[i])) + i++; + break; + + case KNIGHT: + i = base + 6; + if ((there && pos[i + 1]) || (!there && pos[i])) + i++; + break; + } + return (i); +} diff --git a/gnu/games/chess/Xchess/king.bitmap b/gnu/games/chess/Xchess/king.bitmap new file mode 100644 index 000000000000..dd9178a2ed9e --- /dev/null +++ b/gnu/games/chess/Xchess/king.bitmap @@ -0,0 +1,71 @@ + +#define king_width 80 +#define king_height 80 +static char king_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x80, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x03, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x0f, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x0f, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x80, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x80, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xe0, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x1f, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x1f, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xf8, 0x1f, 0x00, 0x30, 0x18, 0x00, 0xfc, 0x1f, 0x00, + 0x00, 0xfe, 0x7f, 0x00, 0xb8, 0x3b, 0x00, 0xff, 0x7f, 0x00, 0x00, 0xff, + 0xff, 0x00, 0xb8, 0x3b, 0x80, 0xff, 0xff, 0x00, 0x80, 0xff, 0xff, 0x03, + 0xb8, 0x3b, 0xe0, 0xff, 0xff, 0x01, 0xc0, 0xff, 0xff, 0x0f, 0xb8, 0x3b, + 0xf0, 0xff, 0xff, 0x03, 0xe0, 0xff, 0xff, 0x1f, 0xb8, 0x3b, 0xf8, 0xff, + 0xf8, 0x07, 0xe0, 0x1f, 0xc0, 0x3f, 0xb8, 0x3b, 0xfc, 0x07, 0xe2, 0x07, + 0xf0, 0xcf, 0x9f, 0x7f, 0x30, 0x18, 0xfe, 0xf3, 0xcf, 0x0f, 0xf0, 0xe7, + 0x3f, 0xfe, 0xf0, 0x1f, 0x7e, 0xfc, 0xdf, 0x0f, 0xf0, 0xf3, 0xff, 0xfc, + 0xf1, 0x1f, 0x3f, 0xff, 0x9f, 0x0f, 0xf8, 0xfb, 0xff, 0xfd, 0xf3, 0x9f, + 0xbf, 0xff, 0xbf, 0x1f, 0xf8, 0xf9, 0xff, 0xf9, 0xe3, 0x8f, 0xdf, 0xff, + 0x3f, 0x1f, 0xf8, 0xfd, 0xff, 0xf3, 0xef, 0xcf, 0xcf, 0xff, 0x7f, 0x1f, + 0xf8, 0xfd, 0xff, 0xe7, 0xef, 0xef, 0xef, 0xff, 0x7f, 0x1f, 0xfc, 0xfd, + 0xff, 0xcf, 0xff, 0xff, 0xe7, 0x3f, 0x7c, 0x3f, 0xfc, 0x3c, 0xfc, 0xdf, + 0xff, 0xfe, 0xf3, 0x3d, 0x7c, 0x3f, 0xfc, 0x3e, 0xfc, 0x9e, 0x7f, 0xfc, + 0xf9, 0x39, 0x7c, 0x3f, 0xfc, 0x3e, 0x7c, 0xbe, 0x3f, 0xf8, 0xf9, 0x3b, + 0x7c, 0x3f, 0xfc, 0x3e, 0x78, 0x3f, 0x7f, 0xfc, 0xfc, 0x3b, 0x7f, 0x3f, + 0xfc, 0xfe, 0x7b, 0x7f, 0xff, 0xfe, 0xfe, 0x9b, 0x7f, 0x3f, 0xf8, 0xfe, + 0xbb, 0x7f, 0xfe, 0x7f, 0xfe, 0xdb, 0x79, 0x1f, 0xf8, 0xfe, 0xb3, 0xff, + 0xfe, 0x7f, 0xff, 0xcb, 0x7c, 0x1f, 0xf8, 0x9e, 0xb7, 0xff, 0xfe, 0x7f, + 0xff, 0x2b, 0x3e, 0x1f, 0xf8, 0x3e, 0xa6, 0xff, 0xfc, 0x7f, 0xff, 0xa3, + 0xbf, 0x1f, 0xf8, 0xfe, 0xa8, 0xff, 0xfd, 0x3e, 0xff, 0xd3, 0xbf, 0x1f, + 0xf8, 0xfd, 0x83, 0xff, 0x7d, 0xbc, 0xff, 0xc3, 0xbf, 0x1f, 0xf0, 0xfd, + 0x8f, 0xff, 0x39, 0xb8, 0xff, 0xe3, 0xbf, 0x1f, 0xf0, 0xfd, 0x9f, 0xff, + 0x7b, 0xbc, 0xff, 0xf1, 0x9f, 0x0f, 0xf0, 0xf9, 0xbf, 0xff, 0xfb, 0xbe, + 0xff, 0xfd, 0xdf, 0x0f, 0xf0, 0xfb, 0x3f, 0xff, 0xf3, 0x9f, 0xff, 0xfd, + 0xdf, 0x0f, 0xf0, 0xf3, 0x7f, 0xff, 0xf7, 0xdf, 0xff, 0xfc, 0xdf, 0x0f, + 0xe0, 0xf7, 0x7f, 0xfe, 0xf7, 0xdf, 0xff, 0xfe, 0xdf, 0x07, 0xe0, 0xf7, + 0xff, 0xfe, 0xf7, 0xdf, 0x7f, 0xfe, 0xcf, 0x07, 0xe0, 0xe7, 0xff, 0xfe, + 0xf7, 0xdf, 0x7f, 0xff, 0xef, 0x07, 0xc0, 0xef, 0xff, 0xfc, 0xef, 0xee, + 0x7f, 0xff, 0xe7, 0x03, 0xc0, 0xcf, 0xff, 0xfd, 0x6f, 0xec, 0x3f, 0xff, + 0xf7, 0x03, 0x80, 0xdf, 0xff, 0xf9, 0xef, 0xee, 0xbf, 0xff, 0xf3, 0x01, + 0x80, 0x9f, 0xff, 0xfb, 0xef, 0xef, 0x9f, 0xff, 0xfb, 0x01, 0x00, 0xbf, + 0xff, 0xfb, 0xef, 0xef, 0xdf, 0xff, 0xf9, 0x00, 0x00, 0x7e, 0xff, 0xf3, + 0xef, 0xef, 0xdf, 0xff, 0x7e, 0x00, 0x00, 0x7e, 0xfe, 0xff, 0xef, 0xef, + 0xff, 0x7f, 0x7e, 0x00, 0x00, 0xfc, 0xfc, 0xff, 0xef, 0xef, 0xff, 0x7f, + 0x3f, 0x00, 0x00, 0xfc, 0xf9, 0xff, 0xef, 0xef, 0xff, 0x3f, 0x1f, 0x00, + 0x00, 0xf8, 0xfb, 0x03, 0xe0, 0x0f, 0x00, 0x9f, 0x1f, 0x00, 0x00, 0xf0, + 0x03, 0xf8, 0xff, 0xff, 0x7f, 0xc0, 0x0f, 0x00, 0x00, 0xe0, 0xff, 0xbf, + 0xf7, 0xde, 0xfb, 0xff, 0x07, 0x00, 0x00, 0xc0, 0xff, 0x1d, 0x63, 0x8c, + 0x71, 0xff, 0x03, 0x00, 0x00, 0x80, 0xef, 0xb8, 0xf7, 0xde, 0x3b, 0xee, + 0x01, 0x00, 0x00, 0x00, 0xc7, 0xfd, 0xff, 0xff, 0x7f, 0xc7, 0x00, 0x00, + 0x00, 0x00, 0xee, 0xff, 0x00, 0x00, 0xfc, 0x6f, 0x00, 0x00, 0x00, 0x00, + 0xfe, 0x03, 0xfe, 0xff, 0x01, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x06, 0xf8, + 0x7f, 0xfc, 0x7f, 0x60, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0x1f, 0xf0, + 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xff, 0x07, 0xc0, 0xff, 0x63, + 0x00, 0x00, 0x00, 0x00, 0x06, 0xff, 0x1f, 0xf0, 0xff, 0x60, 0x00, 0x00, + 0x00, 0x00, 0x06, 0xfc, 0x7f, 0xfc, 0x3f, 0x60, 0x00, 0x00, 0x00, 0x00, + 0x06, 0xff, 0xff, 0xff, 0xff, 0x60, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xff, + 0x00, 0x00, 0xfc, 0x63, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x03, 0xfe, 0xff, + 0x01, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x06, 0xf8, 0xff, 0xff, 0x7f, 0x60, + 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, + 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; diff --git a/gnu/games/chess/Xchess/king_mask.bitmap b/gnu/games/chess/Xchess/king_mask.bitmap new file mode 100644 index 000000000000..e1bb523cad10 --- /dev/null +++ b/gnu/games/chess/Xchess/king_mask.bitmap @@ -0,0 +1,71 @@ + +#define king_mask_width 80 +#define king_mask_height 80 +static char king_mask_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xc0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xc0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x1f, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x1f, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x1f, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xf0, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xf0, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xf8, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x3f, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x3f, 0x00, 0xf8, 0x3f, 0x00, 0xfe, + 0x3f, 0x00, 0x00, 0xff, 0xff, 0x00, 0xfc, 0x3f, 0x80, 0xff, 0x7f, 0x00, + 0x80, 0xff, 0xff, 0x01, 0xfc, 0x7f, 0xc0, 0xff, 0xff, 0x00, 0xc0, 0xff, + 0xff, 0x07, 0xfc, 0x7f, 0xe0, 0xff, 0xff, 0x01, 0xe0, 0xff, 0xff, 0x1f, + 0xfc, 0x7f, 0xf8, 0xff, 0xff, 0x07, 0xe0, 0xff, 0xff, 0x3f, 0xfc, 0x7f, + 0xfc, 0xff, 0xff, 0x0f, 0xf0, 0xff, 0xff, 0x7f, 0xfc, 0x7f, 0xfe, 0xff, + 0xff, 0x0f, 0xf8, 0xff, 0xff, 0xff, 0xfc, 0x7f, 0xff, 0xff, 0xff, 0x1f, + 0xf8, 0xff, 0xff, 0xff, 0xfd, 0xff, 0xff, 0xff, 0xff, 0x1f, 0xf8, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xfc, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0x7f, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0x7f, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, + 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0xfe, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0xfe, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0x7f, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0x7f, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, + 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0xfe, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0xfe, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0x3f, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0x3f, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, + 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xfc, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xf8, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0x1f, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0x1f, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, + 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0xf0, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xf0, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0x0f, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0x07, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, + 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0xc0, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x80, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x7f, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, + 0x00, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0xfc, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x00, 0xf8, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0x0f, 0x00, 0x00, 0xf0, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0x07, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x03, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, + 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, + 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, + 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; diff --git a/gnu/games/chess/Xchess/king_outline.bitmap b/gnu/games/chess/Xchess/king_outline.bitmap new file mode 100644 index 000000000000..173651c28efa --- /dev/null +++ b/gnu/games/chess/Xchess/king_outline.bitmap @@ -0,0 +1,71 @@ + +#define king_outline_width 80 +#define king_outline_height 80 +static char king_outline_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xc0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x40, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x1c, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x70, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x40, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x40, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x3c, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x20, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xf8, 0x1f, 0x00, 0x0c, 0x60, 0x00, 0xfc, 0x1f, 0x00, + 0x00, 0x0e, 0x70, 0x00, 0x84, 0x43, 0x00, 0x07, 0x70, 0x00, 0x00, 0x03, + 0xc0, 0x00, 0xc4, 0x46, 0x80, 0x01, 0xc0, 0x00, 0x80, 0x01, 0x80, 0x03, + 0x44, 0x44, 0xe0, 0x00, 0x80, 0x01, 0xc0, 0x00, 0x00, 0x0e, 0x44, 0x44, + 0x30, 0x00, 0x00, 0x03, 0x60, 0x00, 0x00, 0x18, 0x44, 0x44, 0x18, 0x00, + 0x07, 0x06, 0x20, 0xe0, 0x3f, 0x30, 0xc4, 0x46, 0x0c, 0xf8, 0x1d, 0x04, + 0x30, 0x30, 0x60, 0x60, 0x8c, 0x63, 0x06, 0x0c, 0x30, 0x0c, 0x10, 0x18, + 0xc0, 0xc1, 0x08, 0x20, 0x82, 0x03, 0x20, 0x0c, 0x10, 0x0c, 0x00, 0x83, + 0x09, 0x20, 0xc3, 0x00, 0x60, 0x08, 0x18, 0x04, 0x00, 0x02, 0x8b, 0xa3, + 0x41, 0x00, 0x40, 0x18, 0x08, 0x06, 0x00, 0x06, 0x7a, 0xb6, 0x20, 0x00, + 0xc0, 0x10, 0x08, 0x02, 0x00, 0x0c, 0x3e, 0x7c, 0x30, 0x00, 0x80, 0x10, + 0x08, 0x02, 0x00, 0x18, 0x18, 0x18, 0x10, 0x00, 0x80, 0x10, 0x0c, 0x02, + 0x00, 0x30, 0x00, 0x00, 0x18, 0xc0, 0x83, 0x30, 0x04, 0xc3, 0x03, 0x20, + 0x00, 0x01, 0x0c, 0xc2, 0x83, 0x20, 0x04, 0xc1, 0x03, 0x61, 0x80, 0x03, + 0x06, 0xc6, 0x83, 0x20, 0x04, 0xc1, 0x83, 0x41, 0xc0, 0x07, 0x06, 0xc4, + 0x83, 0x20, 0x04, 0xc1, 0x87, 0xc0, 0x80, 0x03, 0x03, 0xc4, 0x80, 0x20, + 0x0c, 0x01, 0x84, 0x80, 0x00, 0x01, 0x01, 0x64, 0x80, 0x30, 0x08, 0x01, + 0x44, 0x80, 0x01, 0x80, 0x01, 0x24, 0x86, 0x10, 0x08, 0x01, 0x4c, 0x00, + 0x01, 0x80, 0x00, 0x34, 0x83, 0x10, 0x08, 0x61, 0x48, 0x00, 0x01, 0x80, + 0x00, 0xd4, 0xc1, 0x10, 0x08, 0xc1, 0x59, 0x00, 0x03, 0x80, 0x00, 0x5c, + 0x40, 0x10, 0x08, 0x01, 0x57, 0x00, 0x02, 0xc1, 0x00, 0x2c, 0x40, 0x10, + 0x18, 0x02, 0x7c, 0x00, 0x82, 0x43, 0x00, 0x3c, 0x40, 0x18, 0x10, 0x02, + 0x70, 0x00, 0xc6, 0x47, 0x00, 0x1c, 0x40, 0x18, 0x10, 0x02, 0x60, 0x00, + 0x84, 0x43, 0x00, 0x0e, 0x60, 0x08, 0x10, 0x06, 0x40, 0x00, 0x04, 0x41, + 0x00, 0x02, 0x20, 0x08, 0x10, 0x04, 0xc0, 0x00, 0x0c, 0x60, 0x00, 0x02, + 0x20, 0x0c, 0x30, 0x0c, 0x80, 0x00, 0x08, 0x20, 0x00, 0x03, 0x20, 0x0c, + 0x20, 0x08, 0x80, 0x01, 0x08, 0x20, 0x00, 0x01, 0x20, 0x04, 0x20, 0x08, + 0x00, 0x01, 0x08, 0x20, 0x80, 0x01, 0x30, 0x04, 0x60, 0x18, 0x00, 0x01, + 0x08, 0x20, 0x80, 0x00, 0x10, 0x06, 0x40, 0x10, 0x00, 0x03, 0x10, 0x11, + 0x80, 0x00, 0x18, 0x02, 0xc0, 0x30, 0x00, 0x02, 0x90, 0x13, 0xc0, 0x00, + 0x08, 0x03, 0x80, 0x20, 0x00, 0x06, 0x10, 0x11, 0x40, 0x00, 0x04, 0x01, + 0x80, 0x61, 0x00, 0x04, 0x10, 0x10, 0x60, 0x00, 0x84, 0x01, 0x00, 0x41, + 0x00, 0x04, 0x10, 0x10, 0x20, 0x00, 0xc6, 0x00, 0x00, 0x83, 0x00, 0x0c, + 0x10, 0x10, 0x20, 0x00, 0x41, 0x00, 0x00, 0x82, 0x01, 0x00, 0x10, 0x10, + 0x00, 0x80, 0x61, 0x00, 0x00, 0x06, 0x01, 0x00, 0x10, 0x10, 0x00, 0x80, + 0x30, 0x00, 0x00, 0x0c, 0x01, 0x00, 0x10, 0x10, 0x00, 0xc0, 0x10, 0x00, + 0x00, 0x18, 0x02, 0xff, 0x1f, 0xf0, 0xff, 0x60, 0x18, 0x00, 0x00, 0x30, + 0xfe, 0x01, 0x00, 0x00, 0x80, 0x3f, 0x0c, 0x00, 0x00, 0x20, 0x00, 0x40, + 0x08, 0x21, 0x04, 0x00, 0x06, 0x00, 0x00, 0xc0, 0x00, 0xe2, 0x9c, 0x73, + 0x8e, 0x00, 0x03, 0x00, 0x00, 0x80, 0x11, 0x47, 0x08, 0x21, 0xc4, 0x11, + 0x01, 0x00, 0x00, 0x00, 0x3b, 0x02, 0x00, 0x00, 0x80, 0xb8, 0x00, 0x00, + 0x00, 0x00, 0x12, 0x00, 0xff, 0xff, 0x03, 0x90, 0x00, 0x00, 0x00, 0x00, + 0x02, 0xfc, 0x01, 0x00, 0xfe, 0xc0, 0x00, 0x00, 0x00, 0x00, 0xfa, 0x07, + 0x80, 0x03, 0x80, 0x5f, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0xe0, 0x0f, + 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x3a, 0x00, 0xf8, 0x3f, 0x00, 0x5c, + 0x00, 0x00, 0x00, 0x00, 0xfa, 0x00, 0xe0, 0x0f, 0x00, 0x5f, 0x00, 0x00, + 0x00, 0x00, 0xfa, 0x03, 0x80, 0x03, 0xc0, 0x5f, 0x00, 0x00, 0x00, 0x00, + 0xfa, 0x00, 0x00, 0x00, 0x00, 0x5f, 0x00, 0x00, 0x00, 0x00, 0x3a, 0x00, + 0xff, 0xff, 0x03, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x02, 0xfc, 0x01, 0x00, + 0xfe, 0x40, 0x00, 0x00, 0x00, 0x00, 0xfa, 0x07, 0x00, 0x00, 0x80, 0x5f, + 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, + 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; diff --git a/gnu/games/chess/Xchess/king_small.bitmap b/gnu/games/chess/Xchess/king_small.bitmap new file mode 100644 index 000000000000..38bb2b7e88b8 --- /dev/null +++ b/gnu/games/chess/Xchess/king_small.bitmap @@ -0,0 +1,15 @@ + +#define king_small_width 32 +#define king_small_height 32 +static char king_small_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xe0, 0x00, 0x00, 0x80, 0x9f, 0x00, 0x00, 0x70, 0x20, 0x00, + 0x00, 0x0c, 0x40, 0x00, 0x00, 0x02, 0x80, 0x01, 0x80, 0x01, 0x00, 0x03, + 0x40, 0x00, 0x00, 0x06, 0x40, 0x60, 0x30, 0x08, 0x20, 0x60, 0x30, 0x10, + 0x20, 0x00, 0x00, 0x60, 0x20, 0x00, 0x00, 0x40, 0x10, 0x00, 0x00, 0x80, + 0x10, 0x00, 0x02, 0x80, 0x10, 0x00, 0x01, 0x80, 0x10, 0x01, 0x01, 0x80, + 0x10, 0x03, 0x1f, 0x84, 0x10, 0x02, 0x00, 0x84, 0x10, 0x06, 0x00, 0x86, + 0x20, 0x1c, 0x00, 0x42, 0x20, 0xf0, 0xff, 0x43, 0x20, 0x00, 0x00, 0x40, + 0x40, 0x00, 0x00, 0x20, 0x40, 0x00, 0x00, 0x20, 0x80, 0x01, 0x00, 0x18, + 0x00, 0xff, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; diff --git a/gnu/games/chess/Xchess/king_small_outline.bitmap b/gnu/games/chess/Xchess/king_small_outline.bitmap new file mode 100644 index 000000000000..18d569e9d7b9 --- /dev/null +++ b/gnu/games/chess/Xchess/king_small_outline.bitmap @@ -0,0 +1,15 @@ + +#define king_small_outline_width 32 +#define king_small_outline_height 32 +static char king_small_outline_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x90, 0x00, 0x06, 0x10, 0xb1, 0x00, + 0x22, 0x12, 0xe1, 0x00, 0x24, 0x92, 0x9f, 0x00, 0x40, 0x72, 0xa0, 0x50, + 0x04, 0x0e, 0x40, 0x50, 0x40, 0x02, 0x80, 0x71, 0xc8, 0x01, 0x00, 0x73, + 0xd8, 0x00, 0x00, 0x46, 0xd8, 0x60, 0x30, 0x08, 0xa0, 0x60, 0x30, 0x10, + 0x20, 0x00, 0x00, 0x60, 0x20, 0x00, 0x00, 0x40, 0x10, 0x00, 0x00, 0x80, + 0x10, 0x00, 0x02, 0x80, 0x10, 0x00, 0x01, 0x80, 0x10, 0x01, 0x01, 0x80, + 0x10, 0x03, 0x1f, 0x84, 0x10, 0x02, 0x00, 0x84, 0x10, 0x06, 0x00, 0x86, + 0x20, 0x1c, 0x00, 0x42, 0x20, 0xf0, 0xff, 0x43, 0x20, 0x00, 0x00, 0x40, + 0x40, 0x00, 0x00, 0x20, 0x40, 0x00, 0x00, 0x20, 0x80, 0x01, 0x00, 0x18, + 0x00, 0xff, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; diff --git a/gnu/games/chess/Xchess/knight.bitmap b/gnu/games/chess/Xchess/knight.bitmap new file mode 100644 index 000000000000..c5b1de1997f4 --- /dev/null +++ b/gnu/games/chess/Xchess/knight.bitmap @@ -0,0 +1,71 @@ + +#define knight_width 80 +#define knight_height 80 +static char knight_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x18, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x38, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, + 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x1f, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xe0, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xe0, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, + 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xbf, 0xff, + 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x7f, 0xfe, 0x0f, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xf8, 0xff, 0x01, 0x00, 0x00, + 0x00, 0x00, 0xe0, 0x0f, 0xfc, 0xe3, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xf0, 0xe1, 0xf3, 0xcf, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xfd, + 0xff, 0x1f, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x3f, 0xfe, 0x7f, + 0xfe, 0x1f, 0x00, 0x00, 0x00, 0x00, 0xff, 0x1f, 0xfe, 0xff, 0xfc, 0x07, + 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xf1, 0x7f, 0x00, 0x00, + 0x00, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xe7, 0x1f, 0x00, 0x00, 0x00, 0xe0, + 0xff, 0xff, 0xff, 0xff, 0xcf, 0xff, 0x03, 0x00, 0x00, 0xf0, 0xff, 0xff, + 0xff, 0xff, 0x9f, 0x3f, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, 0xff, 0xff, + 0x3f, 0xff, 0x07, 0x00, 0x00, 0xfc, 0xff, 0xff, 0xff, 0xff, 0x7f, 0xfe, + 0x00, 0x00, 0x00, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xfc, 0x07, 0x00, + 0x00, 0xfe, 0xff, 0xff, 0xff, 0x7f, 0xfe, 0xfd, 0x01, 0x00, 0x00, 0xff, + 0xff, 0xff, 0xff, 0x3f, 0xff, 0xfb, 0x1f, 0x00, 0x00, 0xff, 0xff, 0xff, + 0xff, 0xbf, 0xff, 0xf3, 0x03, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0x9f, + 0xff, 0xf7, 0x3f, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xcf, 0xff, 0xef, + 0x07, 0x00, 0xc0, 0xff, 0xff, 0xff, 0x7f, 0xf3, 0xff, 0xcf, 0x7f, 0x00, + 0xe0, 0xff, 0xff, 0xff, 0x1f, 0xfd, 0xff, 0xdf, 0x07, 0x00, 0xe0, 0xff, + 0xff, 0xff, 0x83, 0xff, 0xf3, 0x9f, 0xff, 0x00, 0xf0, 0xff, 0xff, 0x7f, + 0x80, 0xff, 0xf9, 0xbf, 0x0f, 0x00, 0xf0, 0xff, 0xff, 0x00, 0x80, 0x7f, + 0xfc, 0x7f, 0xff, 0x01, 0xf8, 0x3f, 0x7f, 0x00, 0x80, 0x81, 0xff, 0x7f, + 0x1e, 0x00, 0x18, 0x9f, 0x3f, 0x00, 0xc0, 0xff, 0xff, 0x7f, 0xfe, 0x07, + 0x98, 0x8f, 0x1f, 0x00, 0xc0, 0xff, 0xcf, 0x7f, 0x3e, 0x00, 0xf8, 0x87, + 0x0f, 0x00, 0xe0, 0xff, 0xe3, 0xff, 0xfe, 0x07, 0xf0, 0xc3, 0x07, 0x00, + 0xf0, 0x1f, 0xfc, 0xff, 0x3c, 0x00, 0xf0, 0xe1, 0x03, 0x00, 0xf0, 0xc0, + 0xff, 0xff, 0xfc, 0x0f, 0x60, 0xe0, 0x01, 0x00, 0xf8, 0xff, 0xff, 0xff, + 0x7c, 0x00, 0x00, 0xf0, 0x00, 0x00, 0xfc, 0xff, 0xff, 0xff, 0xfc, 0x0f, + 0x00, 0x70, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0x7c, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xf9, 0x0f, 0x00, 0x00, 0x00, 0x00, + 0xff, 0xff, 0xff, 0xff, 0xf9, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, + 0xff, 0xff, 0xf9, 0x0f, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, + 0xf9, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xf9, 0x1f, + 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xf1, 0x01, 0x00, 0x00, + 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xf1, 0x3f, 0x00, 0x00, 0x00, 0xf0, + 0xff, 0xff, 0xff, 0xff, 0xf3, 0x01, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, + 0xff, 0xff, 0xf3, 0x3f, 0x00, 0x00, 0x00, 0xfc, 0xff, 0xff, 0xff, 0xff, + 0xf3, 0x01, 0x00, 0x00, 0x00, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xf3, 0x3f, + 0x00, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xf3, 0x01, 0x00, 0x00, + 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf3, 0x3f, 0x00, 0x00, 0x00, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xf3, 0x01, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xf3, 0x3f, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xf3, 0x01, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf3, 0x3f, + 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf3, 0x01, 0x00, 0x00, + 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf3, 0x3f, 0x00, 0x00, 0xe0, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xf3, 0x01, 0x00, 0x00, 0xf0, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xf3, 0x3f, 0x00, 0x00, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xf3, 0x01, 0x00, 0x00, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf3, 0x3f, + 0x00, 0x00, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf3, 0x01, 0x00, 0x00, + 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf3, 0x3f, 0x00, 0x00, 0xfc, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xf3, 0x01, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xf3, 0x3f, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xf3, 0x01, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf3, 0x3f, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; diff --git a/gnu/games/chess/Xchess/knight_mask.bitmap b/gnu/games/chess/Xchess/knight_mask.bitmap new file mode 100644 index 000000000000..97d288c60554 --- /dev/null +++ b/gnu/games/chess/Xchess/knight_mask.bitmap @@ -0,0 +1,71 @@ + +#define knight_mask_width 80 +#define knight_mask_height 80 +static char knight_mask_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9c, 0x0f, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xbe, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xfe, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xfc, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, + 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0x7f, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xf0, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xf0, 0xff, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, + 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, + 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff, 0xff, 0x03, + 0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, + 0x00, 0x00, 0xf8, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, + 0xfc, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, + 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, + 0x00, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0xf8, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0xfc, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0x0f, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x0f, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, + 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x80, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0xc0, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0x7f, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x7f, 0x00, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, + 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0xf8, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0xf8, 0xff, 0xff, 0xff, + 0xc7, 0xff, 0xff, 0xff, 0xff, 0x01, 0xfc, 0xff, 0xff, 0xff, 0xc1, 0xff, + 0xff, 0xff, 0xff, 0x03, 0xfc, 0xff, 0xff, 0x01, 0xc0, 0xff, 0xff, 0xff, + 0xff, 0x0f, 0xfc, 0xff, 0xff, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x0f, + 0xfc, 0xff, 0x7f, 0x00, 0xf0, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xfc, 0xdf, + 0x3f, 0x00, 0xf8, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xfc, 0xef, 0x1f, 0x00, + 0xf8, 0xff, 0xff, 0xff, 0xff, 0x1f, 0xf8, 0xf7, 0x0f, 0x00, 0xfc, 0xff, + 0xff, 0xff, 0xff, 0x1f, 0xf8, 0xfb, 0x07, 0x00, 0xfc, 0xff, 0xff, 0xff, + 0xff, 0x1f, 0xf0, 0xf9, 0x03, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0x1f, + 0x00, 0xf8, 0x01, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0xf8, + 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x80, + 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, + 0xff, 0xff, 0xff, 0x1f, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, + 0xff, 0x1f, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, + 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, + 0x00, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0xfc, + 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0xfe, 0xff, 0xff, + 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0x7f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, + 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, + 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0xc0, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0x7f, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, + 0x00, 0x00, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, + 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0xf8, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0xf8, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0x7f, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, + 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0x7f, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, + 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; diff --git a/gnu/games/chess/Xchess/knight_outline.bitmap b/gnu/games/chess/Xchess/knight_outline.bitmap new file mode 100644 index 000000000000..a1ab938b773f --- /dev/null +++ b/gnu/games/chess/Xchess/knight_outline.bitmap @@ -0,0 +1,71 @@ + +#define knight_outline_width 80 +#define knight_outline_height 80 +static char knight_outline_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x18, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x38, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, + 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xf9, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x0f, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0xf8, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x20, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x20, 0x00, 0xe0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, + 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x80, + 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x08, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0xf8, 0x01, 0x00, 0x00, + 0x00, 0x00, 0xe0, 0xf0, 0x01, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x30, 0x58, 0x07, 0x00, 0xc0, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x18, 0x4c, + 0x04, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x78, 0x07, 0x00, + 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x23, 0xe0, 0x01, 0x00, 0x00, 0x04, + 0x00, 0x00, 0x00, 0x80, 0x11, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x00, 0x00, + 0x00, 0xc0, 0x08, 0x00, 0x00, 0x40, 0x00, 0x10, 0x00, 0x00, 0x00, 0x60, + 0x04, 0x00, 0x00, 0x40, 0x00, 0xf0, 0x03, 0x00, 0x00, 0x30, 0x02, 0x00, + 0x00, 0x60, 0x00, 0x20, 0x00, 0x00, 0x00, 0x18, 0x01, 0x00, 0x00, 0x20, + 0x00, 0xe0, 0x07, 0x00, 0x00, 0x8c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x80, + 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x20, 0x00, 0x80, 0x07, 0x00, + 0x00, 0x26, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x01, 0x00, 0x00, 0x13, + 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x1f, 0x00, 0x00, 0x09, 0x40, 0x00, + 0x00, 0x18, 0x08, 0x00, 0x02, 0x00, 0x80, 0x05, 0xc0, 0x00, 0x00, 0x0c, + 0x0c, 0x00, 0x3e, 0x00, 0x80, 0x00, 0x80, 0x00, 0xc0, 0x03, 0x06, 0x00, + 0x04, 0x00, 0xc0, 0x00, 0x80, 0x01, 0x70, 0x01, 0xc3, 0x00, 0x7c, 0x00, + 0x60, 0x00, 0x00, 0x03, 0x1e, 0x81, 0x41, 0x00, 0x04, 0x00, 0x20, 0x00, + 0x00, 0xce, 0x83, 0x61, 0x60, 0x00, 0xfc, 0x00, 0x30, 0x00, 0x80, 0x7f, + 0x80, 0x1c, 0x30, 0x00, 0x08, 0x00, 0x10, 0xe0, 0xc1, 0x00, 0x80, 0x07, + 0x10, 0x00, 0xf8, 0x01, 0x18, 0x30, 0x61, 0x00, 0x80, 0x00, 0x08, 0x00, + 0x10, 0x00, 0x08, 0x98, 0x31, 0x00, 0xc0, 0x00, 0x0c, 0x00, 0xf0, 0x07, + 0x08, 0x8c, 0x18, 0x00, 0x40, 0x00, 0x03, 0x00, 0x20, 0x00, 0x18, 0x86, + 0x0c, 0x00, 0x60, 0xc0, 0x01, 0x00, 0xe0, 0x07, 0x10, 0xc3, 0x06, 0x00, + 0x30, 0x30, 0x00, 0x00, 0x20, 0x00, 0xf0, 0x61, 0x02, 0x00, 0x10, 0x1e, + 0x00, 0x00, 0xe0, 0x0f, 0x60, 0x30, 0x02, 0x00, 0x98, 0x03, 0x00, 0x00, + 0x40, 0x00, 0x00, 0x10, 0x02, 0x00, 0x0c, 0x00, 0x00, 0x00, 0xc0, 0x0f, + 0x00, 0xb0, 0x03, 0x00, 0x06, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0xc0, + 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0xc0, 0x0f, 0x00, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, + 0x00, 0x00, 0x80, 0x0f, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, + 0x80, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x80, 0x1f, + 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, + 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x30, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, + 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, + 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x01, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, + 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, + 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x20, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x01, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, + 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, + 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x04, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x01, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; diff --git a/gnu/games/chess/Xchess/knight_small.bitmap b/gnu/games/chess/Xchess/knight_small.bitmap new file mode 100644 index 000000000000..77c74517f0f6 --- /dev/null +++ b/gnu/games/chess/Xchess/knight_small.bitmap @@ -0,0 +1,15 @@ + +#define knight_small_width 32 +#define knight_small_height 32 +static char knight_small_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x80, 0x00, 0x00, 0xee, 0x7f, 0x02, + 0x00, 0xfe, 0x7f, 0x01, 0x00, 0xff, 0xff, 0x04, 0x00, 0xff, 0xff, 0x02, + 0x80, 0xff, 0xff, 0x09, 0xc0, 0xfc, 0xff, 0x07, 0xe0, 0xfc, 0xff, 0x11, + 0xe0, 0xff, 0xff, 0x0d, 0xe0, 0xff, 0xff, 0x03, 0xf0, 0xff, 0xff, 0x3f, + 0xf0, 0xff, 0xff, 0x03, 0xf0, 0xff, 0xff, 0x7f, 0xf8, 0xff, 0xff, 0x07, + 0xfc, 0xc7, 0xff, 0x7f, 0xfe, 0xc1, 0xff, 0x07, 0xfa, 0xc1, 0xff, 0x7f, + 0xce, 0xc0, 0xff, 0x07, 0x6c, 0xc0, 0xff, 0x7f, 0x28, 0xe0, 0xff, 0x07, + 0x00, 0xe0, 0xff, 0x7f, 0x00, 0xe0, 0xff, 0x0f, 0x00, 0xf0, 0xff, 0x7f, + 0x00, 0xf0, 0xff, 0x0f, 0x00, 0xf0, 0xff, 0x7f, 0x00, 0xf8, 0xff, 0x0f, + 0x00, 0xf8, 0xff, 0x7f, 0x00, 0xfc, 0xff, 0x0f, 0x00, 0xff, 0xff, 0x7f, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; diff --git a/gnu/games/chess/Xchess/knight_small_outline.bitmap b/gnu/games/chess/Xchess/knight_small_outline.bitmap new file mode 100644 index 000000000000..c0e738c6db4c --- /dev/null +++ b/gnu/games/chess/Xchess/knight_small_outline.bitmap @@ -0,0 +1,15 @@ + +#define knight_small_outline_width 32 +#define knight_small_outline_height 32 +static char knight_small_outline_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x80, 0x00, 0x00, 0xee, 0x7f, 0x02, + 0x00, 0x3a, 0x40, 0x01, 0x00, 0x03, 0xc0, 0x04, 0x00, 0x01, 0x80, 0x02, + 0x80, 0x01, 0x80, 0x09, 0xc0, 0x0c, 0x00, 0x07, 0x60, 0x0c, 0x00, 0x11, + 0x20, 0x00, 0x00, 0x0d, 0x20, 0x00, 0x00, 0x03, 0x30, 0x00, 0x00, 0x3e, + 0x10, 0x00, 0x00, 0x02, 0x10, 0x00, 0x00, 0x7e, 0x18, 0x7c, 0x00, 0x04, + 0x0c, 0x47, 0x00, 0x7c, 0x06, 0x41, 0x00, 0x04, 0xf2, 0x41, 0x00, 0x7c, + 0xde, 0x40, 0x00, 0x04, 0x6c, 0x40, 0x00, 0x7c, 0x28, 0x60, 0x00, 0x04, + 0x00, 0x20, 0x00, 0x7c, 0x00, 0x20, 0x00, 0x08, 0x00, 0x30, 0x00, 0x78, + 0x00, 0x10, 0x00, 0x08, 0x00, 0x10, 0x00, 0x78, 0x00, 0x18, 0x00, 0x08, + 0x00, 0x08, 0x00, 0x78, 0x00, 0x0c, 0x00, 0x08, 0x00, 0xff, 0xff, 0x7f, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; diff --git a/gnu/games/chess/Xchess/message.c b/gnu/games/chess/Xchess/message.c new file mode 100644 index 000000000000..7060192dbdee --- /dev/null +++ b/gnu/games/chess/Xchess/message.c @@ -0,0 +1,101 @@ + +/* This file contains code for X-CHESS. + Copyright (C) 1986 Free Software Foundation, Inc. + +This file is part of X-CHESS. + +X-CHESS is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY. No author or distributor +accepts responsibility to anyone for the consequences of using it +or for whether it serves any particular purpose or works at all, +unless he says so in writing. Refer to the X-CHESS General Public +License for full details. + +Everyone is granted permission to copy, modify and redistribute +X-CHESS, but only under the conditions described in the +X-CHESS General Public License. A copy of this license is +supposed to have been given to you along with X-CHESS so you +can know your rights and responsibilities. It should be in a +file named COPYING. Among other things, the copyright notice +and this notice must be preserved on all copies. */ + + +/* RCS Info: $Revision: 1.1.1.1 $ on $Date: 1993/06/12 14:41:14 $ + * $Source: /home/cvs/386BSD/src/gnu/games/chess/Xchess/message.c,v $ + * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group + * Permission is granted to do anything with this code except sell it + * or remove this message. + * + * Do stuff with the message window. Font 0 is the normal font, font 1 + * is large, and font 2 is normal red. + */ + +#include "xchess.h" + +#define MESSAGE_HEADER "\n1 XChess Messages0\n" + +void +message_init(win) + windata *win; +{ + TxtGrab(win->display, win->messagewin, "xchess", win->medium, + win->textback.pixel, win->textcolor.pixel, + win->cursorcolor.pixel); + TxtAddFont(win->display, win->messagewin, 1, win->large, win->textcolor.pixel); + TxtAddFont(win->display, win->messagewin, 2, win->medium, win->errortext.pixel); + TxtAddFont(win->display, win->messagewin, 3, win->medium, win->playertext.pixel); + + TxtWriteStr(win->display, win->messagewin, MESSAGE_HEADER); + return; +} + +void +message_add(win, string, err) + windata *win; + char *string; + bool err; +{ + if (err) { + TxtWriteStr(win->display, win->messagewin, "2"); + TxtWriteStr(win->display, win->messagewin, string); + TxtWriteStr(win->display, win->messagewin, "0"); + XBell(win->display, 50); + } else + TxtWriteStr(win->display, win->messagewin, string); + + XSync(win->display, 0); + return; +} + +void +message_send(win, event) + windata *win; + XEvent *event; +{ + XKeyEvent *ev = &event->xkey; + KeySym keysym; + windata *ow = (win == win1) ? win2 : win1; + char buf[BSIZE], *s; + int i; + + i = XLookupString(ev, buf, sizeof(buf) - 1, &keysym, &s); + buf[i] = '\0'; + for (s = buf; *s; s++) + if (*s == '\r') + *s = '\n'; + else if (*s == '\177') + *s = ''; + + TxtWriteStr(win->display, win->messagewin, "3"); + TxtWriteStr(win->display, win->messagewin, buf); + TxtWriteStr(win->display, win->messagewin, "0"); + XSync(win->display, 0); + if (ow) { + TxtWriteStr(ow->display, ow->messagewin, "3"); + TxtWriteStr(ow->display, ow->messagewin, buf); + TxtWriteStr(ow->display, ow->messagewin, "0"); + XSync(ow->display, 0); + } + return; +} + diff --git a/gnu/games/chess/Xchess/parse.c b/gnu/games/chess/Xchess/parse.c new file mode 100644 index 000000000000..19f473952e6c --- /dev/null +++ b/gnu/games/chess/Xchess/parse.c @@ -0,0 +1,386 @@ +/* This file contains code for X-CHESS. + Copyright (C) 1986 Free Software Foundation, Inc. + +This file is part of X-CHESS. + +X-CHESS is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY. No author or distributor +accepts responsibility to anyone for the consequences of using it +or for whether it serves any particular purpose or works at all, +unless he says so in writing. Refer to the X-CHESS General Public +License for full details. + +Everyone is granted permission to copy, modify and redistribute +X-CHESS, but only under the conditions described in the +X-CHESS General Public License. A copy of this license is +supposed to have been given to you along with X-CHESS so you +can know your rights and responsibilities. It should be in a +file named COPYING. Among other things, the copyright notice +and this notice must be preserved on all copies. */ + + +/* RCS Info: $Revision: 1.1.1.1 $ on $Date: 1993/06/12 14:41:06 $ + * $Source: /home/cvs/386BSD/src/gnu/games/chess/Xchess/parse.c,v $ + * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group + * Permission is granted to do anything with this code except sell it + * or remove this message. + * + * Parse a sequence of chess moves... + */ + +#include "xchess.h" + +bool loading_flag = false; +bool loading_paused = false; + +static char *line; + +/* Load a record file in. This returns a number of things -- the board, the + * list of moves, and whose turn it is. + */ + +void +load_game(file) + char *file; +{ + FILE *fp; + char buf[BSIZE]; + bool eflag; + move *m; + board *tmpboard = alloc(board); + + if (eq(file, "xchess.game") && saveflag) { + message_add(win1, + "Oops, I just overwrote the\nfile xchess.game...\n", + true); + message_add(win1, "I hope you had another copy.\n", true); + return; + } + if (!(fp = fopen(file, "r"))) { + perror(file); + return; + } + + /* Get a few lines... */ + fgets(buf, BSIZE, fp); + message_add(win1, buf, false); + if (!oneboard) + message_add(win2, buf, false); + + fgets(buf, BSIZE, fp); + message_add(win1, buf, false); + if (!oneboard) + message_add(win2, buf, false); + + fgets(buf, BSIZE, fp); + if (eq(buf, "\tenglish\n")) + eflag = true; + else if (eq(buf, "\talgebraic\n")) + eflag = false; + else { + fprintf(stderr, "Can't decide whether this is english...\n"); + return; + } + + board_init(tmpboard); + line = NULL; + m = parse_file(fp, tmpboard, eflag); + tfree(tmpboard); + + /* Now apply these moves to the board we were given... */ + loading_flag = true; + while (m) { + if (!quickflag) + XSync(win1->display, 0); + win_process(true); + if (!quickflag) + sleep(1); + if (!loading_paused) { + prog_move(m); + m = m->next; + } + } + loading_flag = false; + if (line) + message_add(win1, line, false); + + while (fgets(buf, BSIZE, fp)) + message_add(win1, buf, false); + + fclose(fp); + + return; +} + +/* Given a starting position (usually the beginning board configuration), + * read in a file of moves. + */ + +move * +parse_file(fp, b, english) + FILE *fp; + board *b; + bool english; +{ + move *mvs = NULL, *end = NULL; + char buf[BSIZE], *s, *t; + + while (fgets(buf, BSIZE, fp)) { + if (*buf == '#') + continue; + s = buf; + + /* The move number... */ + if (!(t = gettok(&s))) + break; + if (!isdigit(*t)) { + line = copy(buf); + break; + } + + if (!(t = gettok(&s))) + break; + if (end) + end = end->next = (english ? parse_move(b, t, WHITE) : + parse_imove(b, t, WHITE)); + else + mvs = end = (english ? parse_move(b, t, WHITE) : + parse_imove(b, t, WHITE)); + if (!end) { + fprintf(stderr, "Can't parse %s\n", buf); + return (NULL); + } + board_move(b, end); + + if (!(t = gettok(&s))) + break; + if (end) + end = end->next = (english ? parse_move(b, t, BLACK) : + parse_imove(b, t, BLACK)); + else + mvs = end = (english ? parse_move(b, t, BLACK) : + parse_imove(b, t, BLACK)); + if (!end) { + fprintf(stderr, "Can't parse %s\n", buf); + return (NULL); + } + board_move(b, end); + } + + return (mvs); +} + +/* Parse a move. The move format accepted is as follows - + * move: spec-spec + * capture: specxspec + * kcastle: 2 o's + * qcastle: 3 o's + * A spec is either piece/pos, piece, or just pos. A pos consists of a column + * name followed by a row number. If the column name is kr, kn, kb, k, q, + * qb, qn, or qr, then the row number is according to the english system, + * or if it is a-h then it is according to the international system. + * + *** As of now the spec must include the position. + */ + +move * +parse_move(b, str, w) + board *b; + char *str; + color w; +{ + move *m = alloc(move); + char *s; + char spec1[16], spec2[16]; + int i, j; + +if (debug) fprintf(stderr, "parsing %s\n", str); + + /* Check for castles. */ + for (s = str, i = 0; *s; s++) + if ((*s == 'o') || (*s == 'O')) + i++; + if (i == 2) { + m->type = KCASTLE; + m->piece.type = KING; + m->piece.color = w; + return (m); + } else if (i == 3) { + m->type = QCASTLE; + m->piece.type = KING; + m->piece.color = w; + return (m); + } + if (index(str, '-')) + m->type = MOVE; + else if (index(str, 'x')) + m->type = CAPTURE; + else + return (NULL); + for (i = 0; str[i]; i++) + if ((str[i] == 'x') || (str[i] == '-')) + break; + else + spec1[i] = str[i]; + spec1[i] = '\0'; + for (i++, j = 0; str[i]; i++, j++) + if ((str[i] == 'x') || (str[i] == '-')) + break; + else + spec2[j] = str[i]; + spec2[j] = '\0'; + + /* Now decode the specifications. */ + s = spec1; + switch (*s) { + case 'p': case 'P': + m->piece.type = PAWN; break; + case 'r': case 'R': + m->piece.type = ROOK; break; + case 'n': case 'N': + m->piece.type = KNIGHT; break; + case 'b': case 'B': + m->piece.type = BISHOP; break; + case 'q': case 'Q': + m->piece.type = QUEEN; break; + case 'k': case 'K': + m->piece.type = KING; break; + default: + return (NULL); + } + m->piece.color = w; + s += 2; + + /* Now get the {q,k}{,b,n,r}n string... */ + if ((s[0] == 'q') && (s[1] == 'r')) + m->fromx = 0, s += 2; + else if ((s[0] == 'q') && (s[1] == 'n')) + m->fromx = 1, s += 2; + else if ((s[0] == 'q') && (s[1] == 'b')) + m->fromx = 2, s += 2; + else if ((s[0] == 'q') && isdigit(s[1])) + m->fromx = 3, s += 1; + else if ((s[0] == 'k') && isdigit(s[1])) + m->fromx = 4, s += 1; + else if ((s[0] == 'k') && (s[1] == 'b')) + m->fromx = 5, s += 2; + else if ((s[0] == 'k') && (s[1] == 'n')) + m->fromx = 6, s += 2; + else if ((s[0] == 'k') && (s[1] == 'r')) + m->fromx = 7, s += 2; + m->fromy = ((w == WHITE) ? (SIZE - atoi(s)) : (atoi(s) - 1)); + + if ((b->square[m->fromy][m->fromx].color != w) || + (b->square[m->fromy][m->fromx].type != m->piece.type)) { + fprintf(stderr, "Error: bad stuff\n"); + return (NULL); + } + + s = spec2; + if (m->type == CAPTURE) { + switch (*s) { + case 'p': case 'P': + m->taken.type = PAWN; break; + case 'r': case 'R': + m->taken.type = ROOK; break; + case 'n': case 'N': + m->taken.type = KNIGHT; break; + case 'b': case 'B': + m->taken.type = BISHOP; break; + case 'q': case 'Q': + m->taken.type = QUEEN; break; + case 'k': case 'K': + m->taken.type = KING; break; + default: + return (NULL); + } + m->taken.color = ((w == WHITE) ? BLACK : WHITE); + s += 2; + } + + /* Now get the {q,k}{,b,n,r}n string... */ + if ((s[0] == 'q') && (s[1] == 'r')) + m->tox = 0, s += 2; + else if ((s[0] == 'q') && (s[1] == 'n')) + m->tox = 1, s += 2; + else if ((s[0] == 'q') && (s[1] == 'b')) + m->tox = 2, s += 2; + else if ((s[0] == 'q') && isdigit(s[1])) + m->tox = 3, s += 1; + else if ((s[0] == 'k') && isdigit(s[1])) + m->tox = 4, s += 1; + else if ((s[0] == 'k') && (s[1] == 'b')) + m->tox = 5, s += 2; + else if ((s[0] == 'k') && (s[1] == 'n')) + m->tox = 6, s += 2; + else if ((s[0] == 'k') && (s[1] == 'r')) + m->tox = 7, s += 2; + m->toy = ((w == WHITE) ? (SIZE - atoi(s)) : (atoi(s) - 1)); + + if ((m->type == CAPTURE) && ((b->square[m->toy][m->tox].color != + m->taken.color) || (b->square[m->toy][m->tox].type != + m->taken.type))) { + fprintf(stderr, "Error: bad stuff\n"); + return (NULL); + } + + return (m); +} + +/* Parse an algebraic notation move. This is a lot easier... */ + +move * +parse_imove(b, buf, w) + board *b; + char *buf; + color w; +{ + char *s; + move *m = alloc(move); + int n; + +if (debug) fprintf(stderr, "(alg) parsing %s\n", buf); + + for (s = buf, n = 0; *s; s++) + if ((*s == 'o') || (*s == 'O')) + n++; + s = buf; + + if (n == 2) + m->type = KCASTLE; + else if (n == 3) + m->type = QCASTLE; + else { + m->fromx = *s++ - 'a'; + m->fromy = SIZE - (*s++ - '0'); + m->tox = *s++ - 'a'; + m->toy = SIZE - (*s++ - '0'); + m->piece = b->square[m->fromy][m->fromx]; + m->taken = b->square[m->toy][m->tox]; + if (m->taken.color == NONE) + m->type = MOVE; + else + m->type = CAPTURE; + /* for pawns we must account for en passant */ + if (m->piece.type == PAWN) { + if (m->type == MOVE && m->fromx != m->tox) { + m->enpassant = 1; + m->type = CAPTURE; + } + } + } + + if (m->piece.color != w) { + fprintf(stderr, "Error: parse_imove: piece of wrong color!\n"); + return (NULL); + } + if ((m->piece.type == KING) && (m->fromy == m->toy) && (m->fromx == 4) + && (m->tox == 6)) + m->type = KCASTLE; + else if ((m->piece.type == KING) && (m->fromy == m->toy) && + (m->fromx == 4) && (m->tox == 2)) + m->type = QCASTLE; + + return (m); +} + diff --git a/gnu/games/chess/Xchess/pawn.bitmap b/gnu/games/chess/Xchess/pawn.bitmap new file mode 100644 index 000000000000..5c3ff76dbf68 --- /dev/null +++ b/gnu/games/chess/Xchess/pawn.bitmap @@ -0,0 +1,71 @@ + +#define pawn_width 80 +#define pawn_height 80 +static char pawn_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x80, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x7f, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xf8, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xf8, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0x01, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xe0, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xc0, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0x03, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0x0f, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xe0, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, + 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0x01, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xf8, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xf8, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, + 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0x07, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0x07, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xfe, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xff, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, + 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0x3f, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xe0, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, + 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0xff, + 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0xff, 0xff, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xf8, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, + 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, + 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, 0xff, 0x03, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xf0, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, + 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0xff, + 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xc0, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, + 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, + 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0x3f, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x1f, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xfe, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xfc, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, + 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, + 0x80, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, + 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0xff, 0xff, + 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x03, 0x00, 0x00, 0x00, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0x00, + 0x00, 0x00, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, + 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x00, 0x00, 0x00, 0xfe, 0xff, + 0xff, 0xff, 0xff, 0xff, 0x0f, 0x00, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, + 0xff, 0xff, 0x0f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x1f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; diff --git a/gnu/games/chess/Xchess/pawn_mask.bitmap b/gnu/games/chess/Xchess/pawn_mask.bitmap new file mode 100644 index 000000000000..724875c59972 --- /dev/null +++ b/gnu/games/chess/Xchess/pawn_mask.bitmap @@ -0,0 +1,71 @@ + +#define pawn_mask_width 80 +#define pawn_mask_height 80 +static char pawn_mask_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xc0, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xf0, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0x01, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0x03, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xfc, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xfc, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, + 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0x03, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0x03, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xfc, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xfc, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, + 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0x07, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xf0, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xfc, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, + 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0xff, + 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0x03, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0x07, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xfc, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xfe, 0xff, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, + 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0x0f, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x1f, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x80, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, + 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, + 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xf0, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xf0, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, + 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, + 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0xff, 0xff, 0x07, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xfc, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xfc, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, + 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0xff, + 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0xff, 0xff, 0x07, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xfc, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xfc, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, + 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, + 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, 0xff, 0x03, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xf0, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xf0, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, + 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, + 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0x7f, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xff, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xff, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0xff, + 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0x0f, + 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, + 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, + 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0xf0, 0xff, + 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0xfc, 0xff, 0xff, 0xff, + 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x0f, 0x00, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x00, + 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x00, 0x00, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x00, 0x80, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0x3f, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x3f, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, + 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; diff --git a/gnu/games/chess/Xchess/pawn_outline.bitmap b/gnu/games/chess/Xchess/pawn_outline.bitmap new file mode 100644 index 000000000000..0c4a3a13229a --- /dev/null +++ b/gnu/games/chess/Xchess/pawn_outline.bitmap @@ -0,0 +1,71 @@ + +#define pawn_outline_width 80 +#define pawn_outline_height 80 +static char pawn_outline_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x80, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x70, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0xc0, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x80, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x18, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x08, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x80, 0x01, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x80, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x30, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xe0, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xc0, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x03, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x0e, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x80, 0x03, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xe0, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, + 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x01, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x08, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x08, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x04, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x02, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, + 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x20, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x20, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, + 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, + 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x08, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, + 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, + 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x02, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, + 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, + 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x80, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x40, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, + 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, + 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x30, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x18, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x06, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x1f, 0x00, 0xff, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x78, 0xc0, 0x81, 0x07, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x07, 0xc0, 0x7f, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, + 0x80, 0x01, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, + 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, + 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, + 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x02, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x18, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; diff --git a/gnu/games/chess/Xchess/pawn_small.bitmap b/gnu/games/chess/Xchess/pawn_small.bitmap new file mode 100644 index 000000000000..88ff7bbcd16f --- /dev/null +++ b/gnu/games/chess/Xchess/pawn_small.bitmap @@ -0,0 +1,15 @@ + +#define pawn_small_width 32 +#define pawn_small_height 32 +static char pawn_small_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xf0, 0x0f, 0x00, + 0x00, 0xf8, 0x1f, 0x00, 0x00, 0xf8, 0x1f, 0x00, 0x00, 0xf8, 0x1f, 0x00, + 0x00, 0xf8, 0x1f, 0x00, 0x00, 0xf8, 0x1f, 0x00, 0x00, 0xf0, 0x0f, 0x00, + 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x80, 0xff, 0xff, 0x01, + 0x80, 0xff, 0xff, 0x01, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, + 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, + 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, + 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, + 0x00, 0xf0, 0x0f, 0x00, 0x00, 0xf8, 0x1f, 0x00, 0x00, 0xfc, 0x3f, 0x00, + 0x00, 0xff, 0xff, 0x00, 0xe0, 0xff, 0xff, 0x07, 0xf0, 0xff, 0xff, 0x0f, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; diff --git a/gnu/games/chess/Xchess/pawn_small_outline.bitmap b/gnu/games/chess/Xchess/pawn_small_outline.bitmap new file mode 100644 index 000000000000..e860f43f3d50 --- /dev/null +++ b/gnu/games/chess/Xchess/pawn_small_outline.bitmap @@ -0,0 +1,15 @@ + +#define pawn_small_outline_width 32 +#define pawn_small_outline_height 32 +static char pawn_small_outline_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0x30, 0x0c, 0x00, + 0x00, 0x18, 0x18, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x08, 0x10, 0x00, + 0x00, 0x08, 0x10, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x30, 0x0c, 0x00, + 0x00, 0x20, 0x04, 0x00, 0x00, 0x20, 0x04, 0x00, 0x80, 0x3f, 0xfc, 0x01, + 0x80, 0x3f, 0xfc, 0x01, 0x00, 0x20, 0x04, 0x00, 0x00, 0x20, 0x04, 0x00, + 0x00, 0x20, 0x04, 0x00, 0x00, 0x20, 0x04, 0x00, 0x00, 0x20, 0x04, 0x00, + 0x00, 0x20, 0x04, 0x00, 0x00, 0x20, 0x04, 0x00, 0x00, 0x20, 0x04, 0x00, + 0x00, 0x20, 0x04, 0x00, 0x00, 0x20, 0x04, 0x00, 0x00, 0x20, 0x04, 0x00, + 0x00, 0xf0, 0x0f, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x0c, 0x30, 0x00, + 0x00, 0x07, 0xe0, 0x00, 0xe0, 0x01, 0x80, 0x07, 0xf0, 0xff, 0xff, 0x0f, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; diff --git a/gnu/games/chess/Xchess/popup.c b/gnu/games/chess/Xchess/popup.c new file mode 100644 index 000000000000..1a53f706e49b --- /dev/null +++ b/gnu/games/chess/Xchess/popup.c @@ -0,0 +1,112 @@ + +/* This file contains code for X-CHESS. + Copyright (C) 1986 Free Software Foundation, Inc. + +This file is part of X-CHESS. + +X-CHESS is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY. No author or distributor +accepts responsibility to anyone for the consequences of using it +or for whether it serves any particular purpose or works at all, +unless he says so in writing. Refer to the X-CHESS General Public +License for full details. + +Everyone is granted permission to copy, modify and redistribute +X-CHESS, but only under the conditions described in the +X-CHESS General Public License. A copy of this license is +supposed to have been given to you along with X-CHESS so you +can know your rights and responsibilities. It should be in a +file named COPYING. Among other things, the copyright notice +and this notice must be preserved on all copies. */ + + +/* RCS Info: $Revision: 1.1.1.1 $ on $Date: 1993/06/12 14:41:13 $ + * $Source: /home/cvs/386BSD/src/gnu/games/chess/Xchess/popup.c,v $ + * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group + * faustus@cad.berkeley.edu, ucbvax!faustus + * Permission is granted to modify and re-distribute this code in any manner + * as long as this notice is preserved. All standard disclaimers apply. + * + * A simple pop-up menu system. + */ + +#include "xchess.h" + +/* Open a small window with some text in it and two buttons -- yes and no. + * Use black and white pixel, and the medium font. + */ + +bool +pop_question(win, text) + windata *win; + char *text; +{ + char *s, *t; + int nlines = 1, ncols = 0, i = 0, j; + int x, y; + Window w; + bool ch; + XEvent ev; + + for (s = text; *s; s++) { + if ((*s == '\n') && s[1]) + nlines++; + if ((*s == '\n') || !s[1]) { + if (i > ncols) + ncols = i; + i = 0; + } else + i++; + } + + if (ncols < 12) + ncols = 12; + nlines += 4; + ncols += 4; + + x = (BASE_WIDTH - ncols * win->medium->max_bounds.width) / 2; + y = (BASE_HEIGHT - nlines * win->medium->max_bounds.ascent) / 2; + + w = XCreateSimpleWindow(win->display, win->basewin, + x, y, ncols * win->medium->max_bounds.width, + nlines * win->medium->ascent, + BORDER_WIDTH, win->border.pixel, + win->textback.pixel); + XMapRaised(win->display, w); + XSetFont(win->display, DefaultGC(win->display, 0), + win->medium->fid); + + for (i = 0, s = text; i < nlines - 4; i++) { + for (t = s, j = 0; *t && (*t != '\n'); t++, j++) + ; + XDrawString(win->display, w, DefaultGC(win->display, 0), + (ncols - j) / 2 * win->medium->max_bounds.width, + (i + 1) * win->medium->ascent, + s, j); + s = t + 1; + } + XDrawString(win->display, w, DefaultGC(win->display, 0), + (ncols - 8) * win->medium->max_bounds.width / 4, + (nlines - 2) * win->medium->ascent, + "YES", 3); + XDrawString(win->display, w, DefaultGC(win->display, 0), + (ncols - 4) * win->medium->max_bounds.width * 3 / 4, + (nlines - 2) * win->medium->ascent, + "NO", 2); + + XSync(win->display, 0); + XSelectInput(win->display, w, ButtonPressMask); + XWindowEvent(win->display, w, ButtonPressMask, &ev); + x = ev.xkey.x; + y = ev.xkey.y; + + if (x > ncols * win->medium->max_bounds.width / 2) + ch = false; + else + ch = true; + + XDestroyWindow(win->display, w); + XSync(win->display, 0); + return (ch); +} + diff --git a/gnu/games/chess/Xchess/program.c b/gnu/games/chess/Xchess/program.c new file mode 100644 index 000000000000..161f4d2343e6 --- /dev/null +++ b/gnu/games/chess/Xchess/program.c @@ -0,0 +1,204 @@ + +/* This file contains code for X-CHESS. + Copyright (C) 1986 Free Software Foundation, Inc. + +This file is part of X-CHESS. + +X-CHESS is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY. No author or distributor +accepts responsibility to anyone for the consequences of using it +or for whether it serves any particular purpose or works at all, +unless he says so in writing. Refer to the X-CHESS General Public +License for full details. + +Everyone is granted permission to copy, modify and redistribute +X-CHESS, but only under the conditions described in the +X-CHESS General Public License. A copy of this license is +supposed to have been given to you along with X-CHESS so you +can know your rights and responsibilities. It should be in a +file named COPYING. Among other things, the copyright notice +and this notice must be preserved on all copies. */ + + +/* RCS Info: $Revision: 1.2 $ on $Date: 1994/01/07 11:10:40 $ + * $Source: /home/cvs/386BSD/src/gnu/games/chess/Xchess/program.c,v $ + * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group + * Permission is granted to do anything with this code except sell it + * or remove this message. + * + * The interface to whichever chess playing program we are using... + */ + +#include "xchess.h" +#include <signal.h> +#include <sys/time.h> + +static int pid; +static FILE *from; +static FILE *to; +static bool easy = 1; + +bool +program_init(name) + char *name; +{ + int toprog[2], fromprog[2]; + char buf[BSIZE]; + char time[10]; + char moves[10]; + + pipe(toprog); + pipe(fromprog); + + if (!(pid = fork())) { + /* Start up the program. */ + dup2(toprog[0], 0); + dup2(fromprog[1], 1); + close(toprog[0]); + close(toprog[1]); + close(fromprog[0]); + close(fromprog[1]); + sprintf (time, "%d", timeunit/60); + sprintf (moves, "%d", movesperunit); + if (proghost) + execl("/usr/ucb/rsh", "rsh", proghost, name, + moves, time, + (char *) NULL); + else + execl(name, name, moves, time, (char *) NULL); + perror(name); + exit(1); + } + + close(toprog[0]); + close(fromprog[1]); + + from = fdopen(fromprog[0], "r"); + setbuf(from, NULL); + to = fdopen(toprog[1], "w"); + setbuf(to, NULL); + + /* Get the first line... */ + fgets(buf, BSIZE, from); + if (debug) + fprintf(stderr, "program says %s", buf); + if (blackflag) { + fputs("switch\n", to); + fflush(to); + fgets(buf, BSIZE, from); + if (debug) + fprintf(stderr, "program says %s", buf); + message_add(win1, "GNU Chess playing white\n", false); + } else + message_add(win1, "GNU Chess playing black\n", false); + + return (true); +} + +void +program_end() +{ + fclose(from); + fclose(to); + kill(pid, SIGTERM); + return; +} + +void +program_send(m) + move *m; +{ + char buf[BSIZE]; + + if ((m->type == MOVE) || (m->type == CAPTURE)) + sprintf(buf, "%c%d%c%d\n", 'a' + m->fromx, SIZE - m->fromy, + 'a' + m->tox, SIZE - m->toy); + else if (m->type == KCASTLE) + strcpy(buf, (m->piece.color == WHITE) ? "e1g1\n" : "e8g8\n"); + else if (m->type == QCASTLE) + strcpy(buf, (m->piece.color == WHITE) ? "e1c1\n" : "e8c8\n"); + + if (debug) + fprintf(stderr, "sending program %s", buf); + if (!easy) + kill (pid, SIGINT); + + fputs(buf, to); + fflush(to); + + /* One junk line... */ + fgets(buf, BSIZE, from); + if (debug) + fprintf(stderr, "program says %s", buf); + return; +} + +move * +program_get() +{ + int rfd = (1 << fileno(from)), wfd = 0, xfd = 0; + static struct timeval notime = { 0, 0 }; + char buf[BSIZE], *s; + move *m; + int i; + + /* Do a poll... */ + +#ifdef __386BSD__ + if (!(i = select(32, &rfd, &wfd, &xfd, ¬ime))) { +#else + if (!(i = select(32, &rfd, &wfd, &xfd, ¬ime)) && + !from->_cnt) { /* Bad stuff... */ +#endif + if (debug) + fprintf(stderr, "poll: nothing\n"); + return (NULL); + } + if (i == -1) { + perror("select"); + return (NULL); + } + + fgets(buf, BSIZE, from); + if (*buf == '\n' || *buf == '\0') { + message_add(win1, "program died", false); + return (NULL); + } + + if (debug) + fprintf(stderr, "got from program %s", buf); + + for (s = buf; !isalpha(*s); s++) + ; + m = parse_imove(chessboard, s, nexttomove); + if (m == NULL) + return (NULL); + + if (!valid_move(m, chessboard)) { + fprintf(stderr, "Error: move %s is invalid!!\n", buf); + return (NULL); + } + + /* + fgets(buf, BSIZE, from); + if (debug) + fprintf(stderr, "program says %s", buf); + */ + message_add(win1, buf, false); + return (m); +} + +void +program_undo() +{ + fputs("undo\n", to); + return; +} +void +program_easy (mode) + bool mode; + +{ + fputs("easy\n", to); + easy = mode; +} diff --git a/gnu/games/chess/Xchess/queen.bitmap b/gnu/games/chess/Xchess/queen.bitmap new file mode 100644 index 000000000000..ab3817a123a9 --- /dev/null +++ b/gnu/games/chess/Xchess/queen.bitmap @@ -0,0 +1,71 @@ + +#define queen_width 80 +#define queen_height 80 +static char queen_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x03, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x03, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xe0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x80, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x01, 0x80, 0x01, 0x00, 0x07, + 0x00, 0x00, 0x00, 0x00, 0xf0, 0x01, 0x80, 0x01, 0x80, 0x0f, 0x00, 0x00, + 0x00, 0x00, 0xf0, 0x01, 0xc0, 0x03, 0x80, 0x0f, 0x00, 0x00, 0x00, 0x00, + 0xe0, 0x00, 0xc0, 0x03, 0x80, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, + 0xc0, 0x03, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0xc0, 0x03, + 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0xc0, 0x03, 0x00, 0x03, + 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0xc0, 0x03, 0x00, 0x03, 0x00, 0x00, + 0x00, 0x00, 0xc0, 0x01, 0xc0, 0x03, 0x80, 0x03, 0x00, 0x00, 0x00, 0x00, + 0xc0, 0x01, 0xc0, 0x03, 0x80, 0x03, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x01, + 0xe0, 0x07, 0x80, 0x03, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x03, 0xe0, 0x07, + 0xc0, 0x03, 0x00, 0x00, 0x1c, 0x00, 0xc0, 0x03, 0xe0, 0x07, 0xc0, 0x03, + 0x00, 0x00, 0x3e, 0x00, 0xc0, 0x03, 0xe0, 0x07, 0xc0, 0x03, 0x00, 0x0e, + 0x3e, 0x00, 0xc0, 0x07, 0xe0, 0x07, 0xe0, 0x03, 0x00, 0x1f, 0x3e, 0x00, + 0xc0, 0x07, 0xe0, 0x07, 0xe0, 0x03, 0x00, 0x1f, 0x3c, 0x00, 0xc0, 0x07, + 0xe0, 0x07, 0xe0, 0x03, 0x00, 0x1f, 0x70, 0x00, 0xc0, 0x0f, 0xe0, 0x07, + 0xf0, 0x03, 0x00, 0x0e, 0x60, 0x00, 0xc0, 0x0f, 0xe0, 0x07, 0xf0, 0x03, + 0x00, 0x03, 0xe0, 0x00, 0xc0, 0x0f, 0xf0, 0x0f, 0xf0, 0x03, 0x80, 0x03, + 0xc0, 0x01, 0xc0, 0x1f, 0xf0, 0x0f, 0xf8, 0x03, 0x80, 0x01, 0xc0, 0x01, + 0xc0, 0x1f, 0xf0, 0x0f, 0xf8, 0x03, 0xc0, 0x01, 0xc0, 0x03, 0xc0, 0x1f, + 0xf0, 0x0f, 0xf8, 0x03, 0xe0, 0x01, 0xc0, 0x07, 0xc0, 0x1f, 0xf0, 0x0f, + 0xf8, 0x03, 0xe0, 0x01, 0xc0, 0x07, 0xc0, 0x3f, 0xf0, 0x0f, 0xfc, 0x03, + 0xf0, 0x01, 0xc0, 0x0f, 0xc0, 0x3f, 0xf0, 0x0f, 0xfc, 0x03, 0xf8, 0x01, + 0x80, 0x1f, 0xc0, 0x3f, 0xf0, 0x0f, 0xfc, 0x03, 0xf8, 0x01, 0x80, 0x1f, + 0xc0, 0x7f, 0xf0, 0x0f, 0xfe, 0x03, 0xfc, 0x01, 0x80, 0x3f, 0xc0, 0x7f, + 0xf8, 0x1f, 0xfe, 0x03, 0xfc, 0x00, 0x80, 0x3f, 0xc0, 0x7f, 0xf8, 0x1f, + 0xfe, 0x03, 0xfe, 0x00, 0x80, 0x7f, 0xc0, 0xff, 0xf8, 0x1f, 0xff, 0x03, + 0xff, 0x00, 0x80, 0xff, 0xc0, 0xff, 0xf8, 0x1f, 0xff, 0x03, 0xff, 0x00, + 0x00, 0xff, 0xc0, 0xff, 0xf8, 0x1f, 0xff, 0x83, 0xff, 0x00, 0x00, 0xff, + 0xc1, 0xff, 0xf9, 0x9f, 0xff, 0x83, 0xff, 0x00, 0x00, 0xff, 0xc3, 0xff, + 0xf9, 0x9f, 0xff, 0xc3, 0xff, 0x00, 0x00, 0xff, 0xc3, 0xff, 0xf9, 0x9f, + 0xff, 0xe3, 0x7f, 0x00, 0x00, 0xff, 0xc7, 0xff, 0xff, 0xff, 0xff, 0xe3, + 0x7f, 0x00, 0x00, 0xff, 0xcf, 0xff, 0xff, 0xff, 0xff, 0xf3, 0x7f, 0x00, + 0x00, 0xfe, 0xcf, 0xff, 0xff, 0xff, 0xff, 0xfb, 0x7f, 0x00, 0x00, 0xfe, + 0xdf, 0xff, 0xff, 0xff, 0xff, 0xfb, 0x7f, 0x00, 0x00, 0xfe, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0x7f, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x7f, 0x00, 0x00, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, + 0x00, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0xfc, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0xfc, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0xfc, 0xff, 0xff, 0x01, 0x80, + 0xff, 0xff, 0x3f, 0x00, 0x00, 0xf8, 0xff, 0x03, 0xfc, 0x3f, 0xc0, 0xff, + 0x1f, 0x00, 0x00, 0xf0, 0x01, 0xf8, 0x7f, 0xfe, 0x1f, 0x80, 0x1f, 0x00, + 0x00, 0x30, 0xfc, 0xff, 0x1f, 0xf8, 0xff, 0x3f, 0x0c, 0x00, 0x00, 0xe0, + 0xe7, 0xff, 0x07, 0xe0, 0xff, 0xe7, 0x07, 0x00, 0x00, 0xc0, 0x81, 0xff, + 0x1f, 0xf8, 0xff, 0x81, 0x03, 0x00, 0x00, 0x80, 0x00, 0xfe, 0x7f, 0xfe, + 0x7f, 0x00, 0x03, 0x00, 0x00, 0x80, 0x81, 0xff, 0xff, 0xff, 0xff, 0x81, + 0x01, 0x00, 0x00, 0x00, 0xe7, 0xff, 0x01, 0x80, 0xff, 0xe7, 0x00, 0x00, + 0x00, 0x00, 0xff, 0x03, 0xfc, 0x3f, 0xc0, 0xff, 0x00, 0x00, 0x00, 0x80, + 0x01, 0xf8, 0xff, 0xff, 0x1f, 0x80, 0x01, 0x00, 0x00, 0x80, 0xfc, 0xff, + 0xff, 0xff, 0xff, 0x3f, 0x01, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0x01, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x03, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, + 0x00, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0xe0, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0xe0, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; diff --git a/gnu/games/chess/Xchess/queen_mask.bitmap b/gnu/games/chess/Xchess/queen_mask.bitmap new file mode 100644 index 000000000000..76a5904e8340 --- /dev/null +++ b/gnu/games/chess/Xchess/queen_mask.bitmap @@ -0,0 +1,71 @@ + +#define queen_mask_width 80 +#define queen_mask_height 80 +static char queen_mask_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xe0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x07, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x07, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x07, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xf0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x60, 0x00, 0xf0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x01, + 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x03, 0xc0, 0x03, + 0xc0, 0x1f, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x03, 0xc0, 0x03, 0xc0, 0x1f, + 0x00, 0x00, 0x00, 0x00, 0xf8, 0x03, 0xe0, 0x07, 0xc0, 0x1f, 0x00, 0x00, + 0x00, 0x00, 0xf8, 0x03, 0xe0, 0x07, 0xc0, 0x1f, 0x00, 0x00, 0x00, 0x00, + 0xf8, 0x01, 0xe0, 0x07, 0xc0, 0x1f, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x01, + 0xe0, 0x07, 0xc0, 0x1f, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x01, 0xe0, 0x07, + 0x80, 0x07, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x01, 0xe0, 0x07, 0x80, 0x07, + 0x00, 0x00, 0x00, 0x00, 0xe0, 0x03, 0xe0, 0x07, 0x80, 0x07, 0x00, 0x00, + 0x00, 0x00, 0xe0, 0x03, 0xf0, 0x0f, 0xc0, 0x07, 0x00, 0x00, 0x00, 0x00, + 0xe0, 0x07, 0xf0, 0x0f, 0xc0, 0x07, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x07, + 0xf0, 0x0f, 0xc0, 0x07, 0x00, 0x00, 0x7e, 0x00, 0xe0, 0x07, 0xf0, 0x0f, + 0xe0, 0x07, 0x00, 0x00, 0x7f, 0x00, 0xe0, 0x0f, 0xf0, 0x0f, 0xe0, 0x07, + 0x00, 0x1f, 0x7f, 0x00, 0xe0, 0x0f, 0xf0, 0x0f, 0xe0, 0x07, 0x80, 0x3f, + 0x7f, 0x00, 0xe0, 0x0f, 0xf0, 0x0f, 0xf0, 0x07, 0x80, 0x3f, 0x7f, 0x00, + 0xe0, 0x0f, 0xf0, 0x0f, 0xf0, 0x07, 0x80, 0x3f, 0xff, 0x00, 0xe0, 0x1f, + 0xf0, 0x0f, 0xf0, 0x07, 0x80, 0x3f, 0xfe, 0x00, 0xe0, 0x1f, 0xf0, 0x0f, + 0xf8, 0x07, 0x80, 0x1f, 0xfc, 0x01, 0xe0, 0x1f, 0xf8, 0x1f, 0xf8, 0x07, + 0x80, 0x1f, 0xf0, 0x03, 0xe0, 0x3f, 0xf8, 0x1f, 0xf8, 0x07, 0xc0, 0x0f, + 0xf0, 0x07, 0xe0, 0x3f, 0xf8, 0x1f, 0xfc, 0x07, 0xe0, 0x03, 0xe0, 0x07, + 0xe0, 0x3f, 0xf8, 0x1f, 0xfc, 0x07, 0xf0, 0x03, 0xe0, 0x0f, 0xe0, 0x7f, + 0xf8, 0x1f, 0xfc, 0x07, 0xf0, 0x03, 0xe0, 0x1f, 0xe0, 0x7f, 0xf8, 0x1f, + 0xfc, 0x07, 0xf8, 0x03, 0xe0, 0x1f, 0xe0, 0x7f, 0xf8, 0x1f, 0xfe, 0x07, + 0xf8, 0x03, 0xe0, 0x3f, 0xe0, 0x7f, 0xf8, 0x1f, 0xfe, 0x07, 0xfc, 0x03, + 0xe0, 0x3f, 0xe0, 0xff, 0xf8, 0x1f, 0xfe, 0x07, 0xfe, 0x03, 0xc0, 0x7f, + 0xe0, 0xff, 0xfc, 0x3f, 0xff, 0x07, 0xfe, 0x03, 0xc0, 0xff, 0xe0, 0xff, + 0xfd, 0x3f, 0xff, 0x07, 0xff, 0x03, 0xc0, 0xff, 0xe1, 0xff, 0xfd, 0xff, + 0xff, 0x87, 0xff, 0x03, 0xc0, 0xff, 0xe3, 0xff, 0xff, 0xff, 0xff, 0x87, + 0xff, 0x01, 0xc0, 0xff, 0xe7, 0xff, 0xff, 0xff, 0xff, 0xc7, 0xff, 0x01, + 0xc0, 0xff, 0xe7, 0xff, 0xff, 0xff, 0xff, 0xc7, 0xff, 0x01, 0x80, 0xff, + 0xef, 0xff, 0xff, 0xff, 0xff, 0xe7, 0xff, 0x01, 0x80, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xe7, 0xff, 0x01, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xf7, 0xff, 0x01, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, + 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, + 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0xfe, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0xfe, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0x7f, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x7f, 0x00, 0x00, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, + 0x00, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0xf8, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x00, 0xf0, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0x0f, 0x00, 0x00, 0xf0, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0x07, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x07, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, + 0x00, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0xc0, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0xc0, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0x03, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x07, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0x00, + 0x00, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x00, 0x00, 0xf0, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x00, 0x00, 0xf0, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x00, 0xf0, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; diff --git a/gnu/games/chess/Xchess/queen_outline.bitmap b/gnu/games/chess/Xchess/queen_outline.bitmap new file mode 100644 index 000000000000..2527216b3966 --- /dev/null +++ b/gnu/games/chess/Xchess/queen_outline.bitmap @@ -0,0 +1,71 @@ + +#define queen_outline_width 80 +#define queen_outline_height 80 +static char queen_outline_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x03, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x02, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x60, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x80, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb0, 0x01, 0x80, 0x01, 0x00, 0x07, + 0x00, 0x00, 0x00, 0x00, 0x10, 0x01, 0x80, 0x01, 0x80, 0x0d, 0x00, 0x00, + 0x00, 0x00, 0xb0, 0x01, 0xc0, 0x03, 0x80, 0x08, 0x00, 0x00, 0x00, 0x00, + 0xe0, 0x00, 0x40, 0x02, 0x80, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, + 0x40, 0x02, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x40, 0x02, + 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x40, 0x02, 0x00, 0x03, + 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x40, 0x02, 0x00, 0x03, 0x00, 0x00, + 0x00, 0x00, 0xc0, 0x01, 0x40, 0x02, 0x80, 0x03, 0x00, 0x00, 0x00, 0x00, + 0x40, 0x01, 0x40, 0x02, 0x80, 0x02, 0x00, 0x00, 0x00, 0x00, 0x40, 0x01, + 0x60, 0x06, 0x80, 0x02, 0x00, 0x00, 0x00, 0x00, 0x40, 0x03, 0x20, 0x04, + 0xc0, 0x02, 0x00, 0x00, 0x1c, 0x00, 0x40, 0x02, 0x20, 0x04, 0x40, 0x02, + 0x00, 0x00, 0x36, 0x00, 0x40, 0x02, 0x20, 0x04, 0x40, 0x02, 0x00, 0x0e, + 0x22, 0x00, 0x40, 0x06, 0x20, 0x04, 0x60, 0x02, 0x00, 0x1b, 0x36, 0x00, + 0x40, 0x04, 0x20, 0x04, 0x20, 0x02, 0x00, 0x11, 0x3c, 0x00, 0x40, 0x04, + 0x20, 0x04, 0x20, 0x02, 0x00, 0x1b, 0x70, 0x00, 0x40, 0x0c, 0x20, 0x04, + 0x30, 0x02, 0x00, 0x0e, 0x60, 0x00, 0x40, 0x08, 0x20, 0x04, 0x10, 0x02, + 0x00, 0x03, 0xe0, 0x00, 0x40, 0x08, 0x30, 0x0c, 0x10, 0x02, 0x80, 0x03, + 0xc0, 0x01, 0x40, 0x18, 0x10, 0x08, 0x18, 0x02, 0x80, 0x01, 0x40, 0x01, + 0x40, 0x10, 0x10, 0x08, 0x08, 0x02, 0xc0, 0x01, 0x40, 0x03, 0x40, 0x10, + 0x10, 0x08, 0x08, 0x02, 0x60, 0x01, 0x40, 0x06, 0x40, 0x10, 0x10, 0x08, + 0x08, 0x02, 0x20, 0x01, 0x40, 0x04, 0x40, 0x30, 0x10, 0x08, 0x0c, 0x02, + 0x30, 0x01, 0xc0, 0x0c, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x18, 0x01, + 0x80, 0x18, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x08, 0x01, 0x80, 0x10, + 0x40, 0x60, 0x10, 0x08, 0x06, 0x02, 0x8c, 0x01, 0x80, 0x30, 0x40, 0x40, + 0x18, 0x18, 0x02, 0x02, 0x84, 0x00, 0x80, 0x20, 0x40, 0x40, 0x08, 0x10, + 0x02, 0x02, 0x86, 0x00, 0x80, 0x60, 0x40, 0xc0, 0x08, 0x10, 0x03, 0x02, + 0x83, 0x00, 0x80, 0xc1, 0x40, 0x80, 0x08, 0x10, 0x01, 0x02, 0x81, 0x00, + 0x00, 0x81, 0x40, 0x80, 0x08, 0x10, 0x01, 0x82, 0x81, 0x00, 0x00, 0x81, + 0x41, 0x80, 0x09, 0x90, 0x01, 0x82, 0x80, 0x00, 0x00, 0x01, 0x43, 0x00, + 0x09, 0x90, 0x00, 0xc2, 0xc0, 0x00, 0x00, 0x01, 0x42, 0x00, 0x09, 0x90, + 0x00, 0x62, 0x40, 0x00, 0x00, 0x01, 0x46, 0x00, 0x0f, 0xf0, 0x00, 0x22, + 0x40, 0x00, 0x00, 0x03, 0x4c, 0x00, 0x00, 0x00, 0x00, 0x32, 0x40, 0x00, + 0x00, 0x02, 0x48, 0x00, 0x00, 0x00, 0x00, 0x1a, 0x40, 0x00, 0x00, 0x02, + 0x58, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x40, 0x00, 0x00, 0x02, 0x70, 0x00, + 0x00, 0x00, 0x00, 0x0e, 0x40, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x40, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x60, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, + 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x04, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x04, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x0c, 0x00, 0x00, 0xfe, 0x7f, + 0x00, 0x00, 0x30, 0x00, 0x00, 0x18, 0x00, 0xfc, 0x03, 0xc0, 0x3f, 0x00, + 0x10, 0x00, 0x00, 0x10, 0xfe, 0x07, 0x80, 0x01, 0xe0, 0x7f, 0x18, 0x00, + 0x00, 0x30, 0x03, 0x00, 0xe0, 0x07, 0x00, 0xc0, 0x0c, 0x00, 0x00, 0x60, + 0x18, 0x00, 0xf8, 0x1f, 0x00, 0x18, 0x06, 0x00, 0x00, 0x40, 0x7e, 0x00, + 0xe0, 0x07, 0x00, 0x7e, 0x02, 0x00, 0x00, 0x40, 0xff, 0x01, 0x80, 0x01, + 0x80, 0xff, 0x02, 0x00, 0x00, 0x40, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x7e, + 0x02, 0x00, 0x00, 0xc0, 0x18, 0x00, 0xfe, 0x7f, 0x00, 0x18, 0x03, 0x00, + 0x00, 0x80, 0x00, 0xfc, 0x03, 0xc0, 0x3f, 0x00, 0x01, 0x00, 0x00, 0x80, + 0xfe, 0x07, 0x00, 0x00, 0xe0, 0x7f, 0x01, 0x00, 0x00, 0x80, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x01, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, + 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x60, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0xe0, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; diff --git a/gnu/games/chess/Xchess/queen_small.bitmap b/gnu/games/chess/Xchess/queen_small.bitmap new file mode 100644 index 000000000000..d7ee50e9b820 --- /dev/null +++ b/gnu/games/chess/Xchess/queen_small.bitmap @@ -0,0 +1,15 @@ + +#define queen_small_width 32 +#define queen_small_height 32 +static char queen_small_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, + 0x00, 0x80, 0x00, 0x00, 0x80, 0x80, 0x80, 0x00, 0x80, 0x80, 0x80, 0x00, + 0x80, 0x81, 0xc0, 0x00, 0x80, 0x81, 0xc0, 0x00, 0x00, 0xc1, 0x41, 0x00, + 0x00, 0xc1, 0x41, 0x00, 0x02, 0xc3, 0x61, 0x20, 0x06, 0xc3, 0x61, 0x30, + 0x04, 0xc3, 0x61, 0x10, 0x0c, 0xc3, 0x61, 0x18, 0x08, 0xc7, 0x71, 0x08, + 0x18, 0xc6, 0x31, 0x0c, 0x38, 0xc6, 0x31, 0x0e, 0x30, 0xce, 0x39, 0x06, + 0x70, 0xce, 0x39, 0x07, 0x60, 0xee, 0x3b, 0x03, 0xe0, 0xee, 0xbb, 0x03, + 0xe0, 0xff, 0xff, 0x03, 0xc0, 0xff, 0xff, 0x01, 0xc0, 0xff, 0xff, 0x01, + 0x80, 0xff, 0xff, 0x00, 0x80, 0xff, 0xff, 0x00, 0x00, 0xff, 0x7f, 0x00, + 0x80, 0xff, 0xff, 0x00, 0xf0, 0xff, 0xff, 0x07, 0xf0, 0xff, 0xff, 0x07, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; diff --git a/gnu/games/chess/Xchess/queen_small_outline.bitmap b/gnu/games/chess/Xchess/queen_small_outline.bitmap new file mode 100644 index 000000000000..0b624b9587bc --- /dev/null +++ b/gnu/games/chess/Xchess/queen_small_outline.bitmap @@ -0,0 +1,15 @@ + +#define queen_small_outline_width 32 +#define queen_small_outline_height 32 +static char queen_small_outline_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, + 0x00, 0x80, 0x00, 0x00, 0x80, 0x80, 0x80, 0x00, 0x80, 0x80, 0x80, 0x00, + 0x80, 0x81, 0xc0, 0x00, 0x80, 0x81, 0xc0, 0x00, 0x00, 0xc1, 0x41, 0x00, + 0x00, 0x41, 0x41, 0x00, 0x02, 0x43, 0x61, 0x20, 0x06, 0x43, 0x61, 0x30, + 0x04, 0x43, 0x61, 0x10, 0x0c, 0x43, 0x61, 0x18, 0x08, 0x47, 0x71, 0x08, + 0x18, 0x46, 0x31, 0x0c, 0x38, 0x46, 0x31, 0x0e, 0x30, 0x4e, 0x39, 0x06, + 0x70, 0x4e, 0x29, 0x07, 0x60, 0x6a, 0x2b, 0x03, 0xe0, 0x2a, 0xab, 0x03, + 0xe0, 0x3b, 0xee, 0x03, 0x40, 0x00, 0x00, 0x01, 0xc0, 0x00, 0x80, 0x01, + 0x80, 0xfc, 0x9f, 0x00, 0x80, 0x01, 0xc0, 0x00, 0x00, 0x01, 0x40, 0x00, + 0x80, 0xfd, 0xdf, 0x00, 0xf0, 0x00, 0x80, 0x07, 0xf0, 0xff, 0xff, 0x07, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; diff --git a/gnu/games/chess/Xchess/record.c b/gnu/games/chess/Xchess/record.c new file mode 100644 index 000000000000..067cccbf1a1f --- /dev/null +++ b/gnu/games/chess/Xchess/record.c @@ -0,0 +1,315 @@ + +/* This file contains code for X-CHESS. + Copyright (C) 1986 Free Software Foundation, Inc. + +This file is part of X-CHESS. + +X-CHESS is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY. No author or distributor +accepts responsibility to anyone for the consequences of using it +or for whether it serves any particular purpose or works at all, +unless he says so in writing. Refer to the X-CHESS General Public +License for full details. + +Everyone is granted permission to copy, modify and redistribute +X-CHESS, but only under the conditions described in the +X-CHESS General Public License. A copy of this license is +supposed to have been given to you along with X-CHESS so you +can know your rights and responsibilities. It should be in a +file named COPYING. Among other things, the copyright notice +and this notice must be preserved on all copies. */ + + +/* RCS Info: $Revision: 1.1.1.1 $ on $Date: 1993/06/12 14:41:09 $ + * $Source: /home/cvs/386BSD/src/gnu/games/chess/Xchess/record.c,v $ + * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group + * Permission is granted to do anything with this code except sell it + * or remove this message. + * + * Deal with recording moves. + */ + +#include "xchess.h" + +#undef smartass + +bool record_english = true; +char *record_file = DEF_RECORD_FILE; +int movenum = 0; +bool saveflag = false; + +static char *colnames[] = { "qr", "qn", "qb", "q", "k", "kb", "kn", "kr" } ; +static char *pcnames[] = { "P", "R", "N", "B", "Q", "K" } ; + +static char *movestring(); +static char *tstring(); +static FILE *backup; + +#define RECORD_HEADER "\n1 XChess Game Record0\n" + +void +record_init(win) + windata *win; +{ + int i; + + i = XTextWidth(win->medium, RECORD_HEADER, + sizeof(RECORD_HEADER) - 1); + i = (40 * win->small->max_bounds.width - i * + win->medium->max_bounds.width) / + win->medium->max_bounds.width / 2; + TxtGrab(win->display, win->recwin, "xchess", win->small, win->textback.pixel, + win->textcolor.pixel, win->cursorcolor.pixel); + TxtAddFont(win->display, win->recwin, 1, win->medium, win->textcolor.pixel); + for (; i > 0; i++) + TxtWriteStr(win->display, win->recwin, " "); + TxtWriteStr(win->display, win->recwin, RECORD_HEADER); + + if (saveflag) { + if (!(backup = fopen(record_file, "w"))) { + perror(record_file); + saveflag = false; + } else { + fprintf(backup, "X Chess -- %s\n", datestring()); + if (dispname2) + fprintf(backup, "\tWhite on %s, black on %s\n", + dispname1, dispname2); + else + fprintf(backup, "\tGame played on %s\n", + dispname1); + fprintf(backup, "\t%s\n", record_english ? "english" : + "algebraic"); + fflush(backup); + } + } + + movenum = 0; + return; +} + +void +record_reset() +{ + TxtWriteStr(win1->display, win1->recwin, "\n\n1 New Game0\n\n"); + if (!oneboard) { + TxtWriteStr(win2->display, win2->recwin, "\n\n1 New Game0\n\n"); + } + movenum = 0; + if (saveflag) { + fprintf(backup, "\n\nNew Game\n\n"); + fflush(backup); + } + return; +} + +void +record_end(s) + char *s; +{ + char buf[BSIZE]; + + sprintf(buf, "\n%s\n", s); + TxtWriteStr(win1->display, win1->recwin, s); + if (!oneboard) { + TxtWriteStr(win2->display, win2->recwin, s); + } + if (saveflag) { + fprintf(backup, "\n%s\n", s); + fprintf(backup, "Time: white: %s, ", tstring(whiteseconds)); + fprintf(backup, "black: %s\n", tstring(blackseconds)); + fclose(backup); + } + return; +} + +void +record_save() +{ + move *m; + FILE *fp; + int i; + char *s; + + if (!(fp = fopen(record_file, "w"))) { + perror(record_file); + return; + } + fprintf(fp, "X Chess -- %s\n", datestring()); + if (dispname2) + fprintf(fp, "\tWhite on %s, black on %s\n", + dispname1, dispname2); + else + fprintf(fp, "\tGame played on %s\n", dispname1); + fprintf(fp, "\t%s\n", record_english ? "english" : "algebraic"); + + for (m = moves, i = 1; m; i++) { + s = movestring(m); + fprintf(fp, "%2d. %-16s ", i, s); + m = m->next; + if (m) + s = movestring(m); + else + s = ""; + fprintf(fp, "%s\n", s); + if (m) + m = m->next; + } + fclose(fp); + return; +} + +void +record_move(m) + move *m; +{ + char *s, buf[BSIZE]; + + s = movestring(m); + + if (m->piece.color == WHITE) { + movenum++; + sprintf(buf, "%2d. %-16s ", movenum, s); + } else { + sprintf(buf, "%s\n", s); + } + TxtWriteStr(win1->display, win1->recwin, buf); + if (!oneboard) { + TxtWriteStr(win2->display, win2->recwin, buf); + } + if (saveflag) { + fprintf(backup, "%s", buf); + fflush(backup); + } + + return; +} + +void +record_back() +{ + extern move *lastmove; + move *m = lastmove; + char *s = movestring(m); + char buf[BSIZE]; + long i; + + if (m->piece.color == WHITE) { + sprintf(buf, "%2d. %-16s ", movenum, s); + } else { + sprintf(buf, "%s\n", s); + } + s = buf; + for (i = 0; *s != '\0'; i++) + *s++ = ''; /* control H, backspace */ + + TxtWriteStr(win1->display, win1->recwin, buf); + if (!oneboard) { + TxtWriteStr(win2->display, win2->recwin, buf); + } + + if (nexttomove == BLACK) + movenum--; + if (saveflag) { + fseek(backup, -i, 1); + fflush(backup); + } + + return; +} + +static char * +movestring(m) + move *m; +{ + int fy, ty; + static char buf[BSIZE]; + + if (!record_english || (m->piece.color == WHITE)) { + fy = SIZE - m->fromy; + ty = SIZE - m->toy; + } else { + fy = m->fromy + 1; + ty = m->toy + 1; + } + + switch (m->type) { + case MOVE: + if (record_english) + sprintf(buf, "%s/%s%d-%s%d%s", pcnames[(int) m->piece. + type], colnames[m->fromx], fy, + colnames[m->tox], ty, m->check ? "+" : + ""); + else + sprintf(buf, "%c%d%c%d", 'a' + m->fromx, fy, 'a' + + m->tox, ty); + break; + case CAPTURE: + if (record_english) + sprintf(buf, "%s/%s%dx%s/%s%d%s%s", + pcnames[(int) m->piece.type], + colnames[m->fromx], fy, + pcnames[(int) m->taken.type], + colnames[m->tox], ty, + m->enpassant ? "e.p." : "", + m->check ? "+" : ""); + else + sprintf(buf, "%c%d%c%d", 'a' + m->fromx, fy, 'a' + + m->tox, ty); + break; + + case KCASTLE: + if (record_english) + sprintf(buf, "O-O%s", m->check ? "ch" : ""); + else if (m->piece.color == WHITE) + strcpy(buf, "e1g1"); + else + strcpy(buf, "e8g8"); + break; + + case QCASTLE: + if (record_english) + sprintf(buf, "O-O-O%s", m->check ? "ch" : ""); + else if (m->piece.color == WHITE) + strcpy(buf, "e1c1"); + else + strcpy(buf, "e8c8"); + break; + + default: + sprintf(buf, "something strange"); + break; + } + if ((m->piece.type == PAWN) && (((m->piece.color == BLACK) && + (m->toy == 7)) || ((m->piece.color == WHITE) && + (m->toy == 0)))) + strcat(buf, "(Q)"); + +#ifdef smartass + if (!(random() % 50)) + strcat(buf, "?"); + else if (!(random() % 50)) + strcat(buf, "!"); + else if (!(random() % 500)) + strcat(buf, "???"); + else if (!(random() % 500)) + strcat(buf, "!!!"); +#endif smartass + + return (buf); +} + +static char * +tstring(s) + int s; +{ + static char buf[64]; + + if (s > 3600) + sprintf(buf, "%dh %dm %ds", s / 3600, (s % 3600) / 60, s % 60); + else if (s > 60) + sprintf(buf, "%dm %ds", (s % 3600) / 60, s % 60); + else + sprintf(buf, "%ds", s); + return (buf); +} + diff --git a/gnu/games/chess/Xchess/rook.bitmap b/gnu/games/chess/Xchess/rook.bitmap new file mode 100644 index 000000000000..f274614eb9cb --- /dev/null +++ b/gnu/games/chess/Xchess/rook.bitmap @@ -0,0 +1,71 @@ + +#define rook_width 80 +#define rook_height 80 +static char rook_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xf8, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x01, 0xf8, 0xff, 0x00, 0x3c, + 0x00, 0x00, 0x00, 0x80, 0xff, 0x01, 0xf8, 0xff, 0x00, 0xfc, 0x0f, 0x00, + 0x00, 0xc0, 0xff, 0x01, 0xf8, 0xff, 0x00, 0xfc, 0x1f, 0x00, 0x00, 0xc0, + 0xff, 0x01, 0xf8, 0xff, 0x00, 0xfc, 0x1f, 0x00, 0x00, 0xc0, 0xff, 0x01, + 0xf8, 0xff, 0x00, 0xfc, 0x1f, 0x00, 0x00, 0xc0, 0xff, 0x01, 0xff, 0xff, + 0x07, 0xfc, 0x1f, 0x00, 0x00, 0xc0, 0xff, 0xfd, 0x01, 0x00, 0xfc, 0xfd, + 0x1f, 0x00, 0x00, 0xc0, 0xff, 0x07, 0xfc, 0xff, 0x01, 0xff, 0x1f, 0x00, + 0x00, 0xc0, 0x1f, 0xf0, 0xff, 0xff, 0x7f, 0xc0, 0x1f, 0x00, 0x00, 0x40, + 0xc0, 0xff, 0x07, 0x00, 0xff, 0x1f, 0x10, 0x00, 0x00, 0xc0, 0xff, 0x1f, + 0xf0, 0x7f, 0xc0, 0xff, 0x1f, 0x00, 0x00, 0xc0, 0x7f, 0xc0, 0xfd, 0xff, + 0x1d, 0xf0, 0x1f, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xfd, 0xff, 0xfd, 0x1f, + 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xfd, 0xff, 0xfd, 0x1f, 0x00, 0x00, + 0x00, 0x00, 0xc0, 0xff, 0xfd, 0xff, 0xfd, 0x1f, 0x00, 0x00, 0x00, 0x00, + 0xc0, 0xff, 0xfd, 0xff, 0xfd, 0x1f, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, + 0xfd, 0xff, 0xfd, 0x1f, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xfd, 0xff, + 0xfd, 0x1f, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xfd, 0xff, 0xfd, 0x1f, + 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xfd, 0xff, 0xfd, 0x1f, 0x00, 0x00, + 0x00, 0x00, 0xc0, 0xff, 0xfd, 0xff, 0xfd, 0x1f, 0x00, 0x00, 0x00, 0x00, + 0xc0, 0x7f, 0x00, 0x00, 0xf0, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, + 0xff, 0xfe, 0x07, 0x10, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xfe, + 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xfe, 0xff, 0x1f, + 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xfe, 0xff, 0x1f, 0x00, 0x00, + 0x00, 0x00, 0xc0, 0xff, 0xff, 0xfe, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, + 0xc0, 0xff, 0xff, 0xfe, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, + 0xff, 0xfe, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xfe, + 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xfe, 0xff, 0x1f, + 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xfe, 0xff, 0x1f, 0x00, 0x00, + 0x00, 0x00, 0xc0, 0xff, 0xff, 0xfe, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, + 0xc0, 0xff, 0xff, 0xfe, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, + 0x0f, 0x80, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0xe0, 0x3f, + 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xfd, 0xff, 0xfd, 0x1f, + 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xfd, 0xff, 0xfd, 0x1f, 0x00, 0x00, + 0x00, 0x00, 0xc0, 0xff, 0xfd, 0xff, 0xfd, 0x1f, 0x00, 0x00, 0x00, 0x00, + 0xc0, 0xff, 0xfd, 0xff, 0xfd, 0x1f, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, + 0xfd, 0xff, 0xfd, 0x1f, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xfd, 0xff, + 0xfd, 0x1f, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xfd, 0xff, 0xfd, 0x1f, + 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xfd, 0xff, 0xfd, 0x1f, 0x00, 0x00, + 0x00, 0x00, 0xc0, 0xff, 0xfd, 0xff, 0xfd, 0x1f, 0x00, 0x00, 0x00, 0x00, + 0xc0, 0xff, 0xfd, 0xff, 0xfd, 0x1f, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, + 0xfd, 0xff, 0xfd, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, + 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xfd, 0xff, 0x1f, + 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xfd, 0xff, 0x1f, 0x00, 0x00, + 0x00, 0x00, 0xc0, 0xff, 0xff, 0xfd, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, + 0xc0, 0xff, 0xff, 0xfd, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, + 0xff, 0xfd, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xfd, + 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xfd, 0xff, 0x1f, + 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xfd, 0xff, 0x1f, 0x00, 0x00, + 0x00, 0x00, 0xc0, 0xff, 0xff, 0xfd, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, + 0xc0, 0xff, 0xff, 0xfd, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, + 0xff, 0xfd, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xfd, + 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x10, + 0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, + 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x07, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, + 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x60, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x20, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x20, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x3f, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; diff --git a/gnu/games/chess/Xchess/rook_mask.bitmap b/gnu/games/chess/Xchess/rook_mask.bitmap new file mode 100644 index 000000000000..c04441655879 --- /dev/null +++ b/gnu/games/chess/Xchess/rook_mask.bitmap @@ -0,0 +1,71 @@ + +#define rook_mask_width 80 +#define rook_mask_height 80 +static char rook_mask_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xfc, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xfc, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x03, 0xfc, 0xff, + 0x01, 0x7e, 0x00, 0x00, 0x00, 0xc0, 0xff, 0x03, 0xfc, 0xff, 0x01, 0xfe, + 0x1f, 0x00, 0x00, 0xe0, 0xff, 0x03, 0xfc, 0xff, 0x01, 0xfe, 0x3f, 0x00, + 0x00, 0xe0, 0xff, 0x03, 0xfc, 0xff, 0x01, 0xfe, 0x3f, 0x00, 0x00, 0xe0, + 0xff, 0x03, 0xfc, 0xff, 0x1f, 0xfe, 0x3f, 0x00, 0x00, 0xe0, 0xff, 0x83, + 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0x3f, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x3f, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, + 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0xe0, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0xe0, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0x3f, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x3f, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, + 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, + 0xe0, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, + 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, + 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x3f, + 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, + 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, + 0xe0, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, + 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, + 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x3f, + 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, + 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, + 0xe0, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, + 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, + 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x3f, + 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, + 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, + 0xe0, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, + 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, + 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x3f, + 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, + 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, + 0xe0, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, + 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, + 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x3f, + 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, + 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, + 0xe0, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, + 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, + 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x3f, + 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, + 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, + 0xe0, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, + 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, + 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x3f, + 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, + 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, + 0xe0, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, + 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, + 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x01, 0x00, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, + 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0x0f, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x1f, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, + 0x00, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0xf0, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0xf0, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0xf0, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0x7f, 0x00, 0x00, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x7f, 0x00, 0x00, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, + 0x00, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; diff --git a/gnu/games/chess/Xchess/rook_outline.bitmap b/gnu/games/chess/Xchess/rook_outline.bitmap new file mode 100644 index 000000000000..f30107a3f277 --- /dev/null +++ b/gnu/games/chess/Xchess/rook_outline.bitmap @@ -0,0 +1,71 @@ + +#define rook_outline_width 80 +#define rook_outline_height 80 +static char rook_outline_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xf8, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x80, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x01, 0x08, 0x80, 0x00, 0x3c, + 0x00, 0x00, 0x00, 0x80, 0x3f, 0x01, 0x08, 0x80, 0x00, 0xe4, 0x0f, 0x00, + 0x00, 0xc0, 0x00, 0x01, 0x08, 0x80, 0x00, 0x04, 0x18, 0x00, 0x00, 0x40, + 0x00, 0x01, 0x08, 0x80, 0x00, 0x04, 0x10, 0x00, 0x00, 0x40, 0x00, 0x01, + 0x08, 0x80, 0x00, 0x04, 0x10, 0x00, 0x00, 0x40, 0x00, 0x01, 0x0f, 0x80, + 0x07, 0x04, 0x10, 0x00, 0x00, 0x40, 0x00, 0xfd, 0x01, 0x00, 0xfc, 0x05, + 0x10, 0x00, 0x00, 0x40, 0x00, 0x07, 0x00, 0x00, 0x00, 0x07, 0x10, 0x00, + 0x00, 0x40, 0x00, 0x00, 0xfc, 0xff, 0x01, 0x00, 0x10, 0x00, 0x00, 0x40, + 0x00, 0xf0, 0x07, 0x00, 0x7f, 0x00, 0x10, 0x00, 0x00, 0x40, 0xc0, 0x1f, + 0x00, 0x00, 0xc0, 0x1f, 0x10, 0x00, 0x00, 0xc0, 0x7f, 0x00, 0x02, 0x00, + 0x02, 0xf0, 0x1f, 0x00, 0x00, 0x00, 0x40, 0x00, 0x02, 0x00, 0x02, 0x10, + 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x02, 0x00, 0x02, 0x10, 0x00, 0x00, + 0x00, 0x00, 0x40, 0x00, 0x02, 0x00, 0x02, 0x10, 0x00, 0x00, 0x00, 0x00, + 0x40, 0x00, 0x02, 0x00, 0x02, 0x10, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, + 0x02, 0x00, 0x02, 0x10, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x02, 0x00, + 0x02, 0x10, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x02, 0x00, 0x02, 0x10, + 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x02, 0x00, 0x02, 0x10, 0x00, 0x00, + 0x00, 0x00, 0x40, 0x00, 0x02, 0x00, 0x02, 0x10, 0x00, 0x00, 0x00, 0x00, + 0x40, 0x80, 0xff, 0xff, 0x0f, 0x10, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, + 0x00, 0x01, 0xf8, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x01, + 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x01, 0x00, 0x10, + 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x01, 0x00, 0x10, 0x00, 0x00, + 0x00, 0x00, 0x40, 0x00, 0x00, 0x01, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, + 0x40, 0x00, 0x00, 0x01, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, + 0x00, 0x01, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x01, + 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x01, 0x00, 0x10, + 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x01, 0x00, 0x10, 0x00, 0x00, + 0x00, 0x00, 0x40, 0x00, 0x00, 0x01, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, + 0x40, 0x00, 0x00, 0x01, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, + 0xf0, 0x7f, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0x1f, 0xc0, + 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x02, 0x00, 0x02, 0x10, + 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x02, 0x00, 0x02, 0x10, 0x00, 0x00, + 0x00, 0x00, 0x40, 0x00, 0x02, 0x00, 0x02, 0x10, 0x00, 0x00, 0x00, 0x00, + 0x40, 0x00, 0x02, 0x00, 0x02, 0x10, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, + 0x02, 0x00, 0x02, 0x10, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x02, 0x00, + 0x02, 0x10, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x02, 0x00, 0x02, 0x10, + 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x02, 0x00, 0x02, 0x10, 0x00, 0x00, + 0x00, 0x00, 0x40, 0x00, 0x02, 0x00, 0x02, 0x10, 0x00, 0x00, 0x00, 0x00, + 0x40, 0x00, 0x02, 0x00, 0x02, 0x10, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, + 0x02, 0x00, 0x02, 0x10, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff, + 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x02, 0x00, 0x10, + 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x02, 0x00, 0x10, 0x00, 0x00, + 0x00, 0x00, 0x40, 0x00, 0x00, 0x02, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, + 0x40, 0x00, 0x00, 0x02, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, + 0x00, 0x02, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x02, + 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x02, 0x00, 0x10, + 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x02, 0x00, 0x10, 0x00, 0x00, + 0x00, 0x00, 0x40, 0x00, 0x00, 0x02, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, + 0x40, 0x00, 0x00, 0x02, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, + 0x00, 0x02, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x02, + 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff, 0xff, 0x1f, + 0x00, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x00, + 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x07, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, + 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x60, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x20, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x20, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x3f, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; diff --git a/gnu/games/chess/Xchess/rook_small.bitmap b/gnu/games/chess/Xchess/rook_small.bitmap new file mode 100644 index 000000000000..ddee75660d4b --- /dev/null +++ b/gnu/games/chess/Xchess/rook_small.bitmap @@ -0,0 +1,15 @@ + +#define rook_small_width 32 +#define rook_small_height 32 +static char rook_small_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xc0, 0x73, 0xce, 0x03, 0xc0, 0x73, 0xce, 0x03, 0xc0, 0x73, 0xce, 0x03, + 0xc0, 0x73, 0xce, 0x03, 0xc0, 0xff, 0xff, 0x03, 0x00, 0xff, 0xff, 0x00, + 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, + 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, + 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, + 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, + 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, + 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0x00, + 0xe0, 0xff, 0xff, 0x07, 0xe0, 0xff, 0xff, 0x07, 0xe0, 0xff, 0xff, 0x07, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; diff --git a/gnu/games/chess/Xchess/rook_small_outline.bitmap b/gnu/games/chess/Xchess/rook_small_outline.bitmap new file mode 100644 index 000000000000..523521b963b7 --- /dev/null +++ b/gnu/games/chess/Xchess/rook_small_outline.bitmap @@ -0,0 +1,15 @@ + +#define rook_small_outline_width 32 +#define rook_small_outline_height 32 +static char rook_small_outline_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xc0, 0x73, 0xce, 0x03, 0x40, 0x52, 0x4a, 0x02, 0x40, 0x52, 0x4a, 0x02, + 0x40, 0x52, 0x4a, 0x02, 0xc0, 0xff, 0xff, 0x03, 0x00, 0x01, 0x80, 0x00, + 0x00, 0x01, 0x80, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x01, 0x80, 0x00, + 0x00, 0x01, 0x80, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x01, 0x80, 0x00, + 0x00, 0x01, 0x80, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x01, 0x80, 0x00, + 0x00, 0x01, 0x80, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x01, 0x80, 0x00, + 0x00, 0x01, 0x80, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x01, 0x80, 0x00, + 0x00, 0x01, 0x80, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x01, 0x80, 0x00, + 0xe0, 0xff, 0xff, 0x07, 0x20, 0x00, 0x00, 0x04, 0xe0, 0xff, 0xff, 0x07, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; diff --git a/gnu/games/chess/Xchess/scrollText.c b/gnu/games/chess/Xchess/scrollText.c new file mode 100644 index 000000000000..847b41c622af --- /dev/null +++ b/gnu/games/chess/Xchess/scrollText.c @@ -0,0 +1,1877 @@ +/* + * A Scrollable Text Output Window + * + * David Harrison + * University of California, Berkeley + * 1986 + * + * The following is an implementation for a scrollable text output + * system. It handles exposure events only (other interactions are + * under user control). For scrolling, a always present scroll bar + * is implemented. It detects size changes and compensates accordingly. + */ + +#include <X11/X.h> +#include <X11/Xlib.h> +#include <X11/X10.h> +#include <sys/types.h> +#include "scrollText.h" + +extern char *malloc(); +extern char *realloc(); +#define alloc(type) (type *) malloc(sizeof(type)) +#define numalloc(type, num) (type *) malloc((unsigned) (num * sizeof(type))) +#define MAXINT 2147483647 + +extern XAssocTable *XCreateAssocTable(); +extern caddr_t XLookUpAssoc(); + +static XAssocTable *textWindows = (XAssocTable *) 0; + +#define NOOPTION -1 /* Option hasn't been set yet */ +#define NORMSCROLL 0 /* Smooth scroll on LineToTop and TopToHere */ +#define JUMPSCROLL 1 /* Jump scrolling on LineToTop and TopToHere */ + +static int ScrollOption = NOOPTION; + +typedef char *Generic; + +#define DEFAULT_GC textInfo->fontGC[textInfo->curFont] + +#define BARSIZE 15 +#define BARBORDER 1 +#define MAXFONTS 8 +#define INITBUFSIZE 1024 +#define INITLINES 50 +#define INITEXPARY 50 +#define XPADDING 2 +#define YPADDING 2 +#define INTERLINE 5 +#define INTERSPACE 1 +#define CURSORWIDTH 2 +#define EXPANDPERCENT 40 +#define BUFSIZE 1024 +#define CUROFFSET 1 +#define MAXFOREIGN 250 +#define NOINDEX -1 + +/* The wrap line indicator */ +#define WRAPINDSIZE 7 +#define STEMOFFSET 5 +#define arrow_width 7 +#define arrow_height 5 +static char arrow_bits[] = { + 0x24, 0x26, 0x3f, 0x06, 0x04}; + +#define NEWLINE '\n' +#define BACKSPACE '\010' +#define NEWFONT '\006' +#define LOWCHAR '\040' +#define HIGHCHAR '\176' + +#define CHARMASK 0x00ff /* Character mask */ +#define FONTMASK 0x0700 /* Character font */ +#define FONTSHIFT 8 /* Shift amount */ + +#define WRAPFLAG 0x01 /* Line wrap flag */ + +/* + * Lines are represented by a pointer into the overall array of + * 16-bit characters. The lower eight bits is used to indicate the character + * (in ASCII), and the next two bits are used to indicate the font + * the character should be drawn in. + */ + +typedef struct txtLine { + int lineLength; /* Current line length */ + int lineHeight; /* Full height of line in pixels */ + int lineBaseLine; /* Current baseline of the line */ + int lineWidth; /* Drawing position at end of line */ + int lineText; /* Offset into master buffer */ + int lineFlags; /* Line wrap flag is here */ +}; + + +/* + * For ExposeCopy events, we queue up the redraw requests collapsing + * them into line redraw requests until the CopyExpose event arrives. + * The queue is represented as a dynamic array of the following + * structure: + */ + +typedef struct expEvent { + int lineIndex; /* Index of line to redraw */ + int ypos; /* Drawing position of line */ +}; + + +/* + * The text buffer is represented using a dynamic counted array + * of 16-bit quantities. This array expands as needed. + * For the screen representation, a dynamic counted array + * of line structures is used. This array points into the + * text buffer to denote the start of each line and its parameters. + * The windows are configured as one overall window which contains + * the scroll bar as a sub-window along its right edge. Thus, + * the text drawing space is actually w-BARSIZE. + */ + +#define NOTATBOTTOM 0x01 /* Need to scroll to bottom before appending */ +#define FONTNUMWAIT 0x02 /* Waiting for font number */ +#define COPYEXPOSE 0x04 /* Need to process a copy expose event */ +#define SCREENWRONG 0x08 /* TxtJamStr has invalidated screen contents */ + +typedef struct txtWin { + /* Basic text buffer */ + int bufAlloc; /* Allocated size of buffer */ + int bufSpot; /* Current writing position in buffer */ + short *mainBuffer; /* Main buffer of text */ + + /* Line information */ + int numLines; /* Number of display lines in buffer */ + int allocLines; /* Number of lines allocated */ + struct txtLine **txtBuffer; /* Dynamic array of lines */ + + /* Current Window display information */ + Window mainWindow; /* Text display window */ + Window scrollBar; /* Subwindow for scroll bar */ + Pixmap arrowMap; /* line wrap indicator */ + int bgPix, fgPix; /* Background and cursor */ + GC CursorGC; /* gc for the cursor */ + GC bgGC; /* gc for erasing things */ + GC fontGC[MAXFONTS]; /* gc for doing fonts */ + XFontStruct theFonts[MAXFONTS];/* Display fonts */ + int theColors[MAXFONTS]; /* foregrounds of the fonts */ + int curFont; /* current font for tracking */ + int w, h; /* Current size */ + int startLine; /* Top line in display */ + int endLine; /* Bottom line in display */ + int bottomSpace; /* Space at bottom of screen */ + int flagWord; /* If non-zero, not at end */ + + /* For handling ExposeCopy events */ + int exposeSize; /* Current size of array */ + int exposeAlloc; /* Allocated size */ + struct expEvent **exposeAry;/* Array of line indices */ + + /* Drawing position information */ + int curLine; /* Current line in buffer */ + int curX; /* Current horizontal positi */ + int curY; /* Current vertical drawing */ +}; + +/* Flags for the various basic character handling functions */ + +#define DODISP 0x01 /* Update the display */ +#define NONEWLINE 0x02 /* Dont append newline */ + + + +static int InitLine(newLine) +struct txtLine *newLine; /* Newly created line structure */ +/* + * This routine initializes a newly created line structure. + */ +{ + newLine->lineLength = 0; + newLine->lineHeight = 0; + newLine->lineBaseLine = 0; + newLine->lineWidth = XPADDING; + newLine->lineText = NOINDEX; + newLine->lineFlags = 0; + return 1; +} + + + + +int TxtGrab(display, txtWin, program, mainFont, bg, fg, cur) +Display *display; /* display window is on */ +Window txtWin; /* Window to take over as scrollable text */ +char *program; /* Program name for Xdefaults */ +XFontStruct *mainFont; /* Primary text font */ +int bg, fg, cur; /* Background, foreground, and cursor colors */ +/* + * This routine takes control of 'txtWin' and makes it into a scrollable + * text output window. It will create a sub-window for the scroll bar + * with a background of 'bg' and an bar with color 'fg'. Both fixed width + * and variable width fonts are supported. Additional fonts can be loaded + * using 'TxtAddFont'. Returns 0 if there were problems, non-zero if + * everything went ok. + */ +{ + struct txtWin *newWin; /* Text package specific information */ + XWindowAttributes winInfo; /* Window information */ + int index; + XGCValues gc_val; + + if (textWindows == (XAssocTable *) 0) { + textWindows = XCreateAssocTable(32); + if (textWindows == (XAssocTable *) 0) return(0); + } + if (XGetWindowAttributes(display, txtWin, &winInfo) == 0) return 0; + + if (ScrollOption == NOOPTION) { + /* Read to see if the user wants jump scrolling or not */ + if (XGetDefault(display, program, "JumpScroll")) { + ScrollOption = JUMPSCROLL; + } else { + ScrollOption = NORMSCROLL; + } + } + + /* Initialize local structure */ + newWin = alloc(struct txtWin); + + /* Initialize arrow pixmap */ + newWin->arrowMap = XCreatePixmapFromBitmapData(display, txtWin, + arrow_bits, + arrow_width, arrow_height, + cur, bg, + DisplayPlanes(display, 0)); + + newWin->bufAlloc = INITBUFSIZE; + newWin->bufSpot = 0; + newWin->mainBuffer = numalloc(short, INITBUFSIZE); + + newWin->numLines = 1; + newWin->allocLines = INITLINES; + newWin->txtBuffer = numalloc(struct txtLine *, INITLINES); + for (index = 0; index < INITLINES; index++) { + newWin->txtBuffer[index] = alloc(struct txtLine); + InitLine(newWin->txtBuffer[index]); + } + + /* Window display information */ + newWin->mainWindow = txtWin; + newWin->w = winInfo.width; + newWin->h = winInfo.height; + newWin->startLine = 0; + newWin->endLine = 0; + newWin->bottomSpace = winInfo.height + - YPADDING - mainFont->ascent - mainFont->descent - INTERLINE; + newWin->flagWord = 0; + newWin->bgPix = bg; + newWin->fgPix = fg; + + /* Scroll Bar Creation */ + newWin->scrollBar = XCreateSimpleWindow(display, txtWin, + winInfo.width - BARSIZE, + 0, BARSIZE - (2*BARBORDER), + winInfo.height - (2*BARBORDER), + BARBORDER, + fg, bg); + XSelectInput(display, newWin->scrollBar, ExposureMask|ButtonReleaseMask); + XMapRaised(display, newWin->scrollBar); + + /* Font and Color Initialization */ + newWin->theFonts[0] = *mainFont; + newWin->theColors[0] = fg; + gc_val.function = GXcopy; + gc_val.plane_mask = AllPlanes; + gc_val.foreground = fg; + gc_val.background = bg; + gc_val.graphics_exposures = 1; + gc_val.font = mainFont->fid; + gc_val.line_width = 1; + gc_val.line_style = LineSolid; + + newWin->fontGC[0] = XCreateGC(display, txtWin, + GCFunction | GCPlaneMask | + GCForeground | GCBackground | + GCGraphicsExposures | GCFont, + &gc_val); + + gc_val.foreground = cur; + newWin->CursorGC = XCreateGC(display, txtWin, + GCFunction | GCPlaneMask | + GCForeground | GCBackground | + GCLineStyle | GCLineWidth, + &gc_val); + + gc_val.foreground = bg; + newWin->bgGC = XCreateGC(display, txtWin, + GCFunction | GCPlaneMask | + GCForeground | GCBackground | + GCGraphicsExposures | GCFont, + &gc_val); + + + for (index = 1; index < MAXFONTS; index++) { + newWin->theFonts[index].fid = 0; + newWin->fontGC[index] = 0; + } + + + /* Initialize size of first line */ + newWin->txtBuffer[0]->lineHeight = newWin->theFonts[0].ascent + + newWin->theFonts[0].descent; + newWin->txtBuffer[0]->lineText = 0; + + /* ExposeCopy array initialization */ + newWin->exposeSize = 0; + newWin->exposeAlloc = INITEXPARY; + newWin->exposeAry = numalloc(struct expEvent *, INITEXPARY); + for (index = 0; index < newWin->exposeAlloc; index++) + newWin->exposeAry[index] = alloc(struct expEvent); + /* Put plus infinity in last slot for sorting purposes */ + newWin->exposeAry[0]->lineIndex = MAXINT; + + /* Drawing Position Information */ + newWin->curLine = 0; + newWin->curX = 0; + newWin->curY = YPADDING + mainFont->ascent + mainFont->descent; + + /* Attach it to both windows */ + XMakeAssoc(display, textWindows, (XID) txtWin, (caddr_t) newWin); + XMakeAssoc(display, textWindows, (XID) newWin->scrollBar, (caddr_t) newWin); + return 1; +} + + +int TxtRelease(display, w) +Display *display; +Window w; /* Window to release */ +/* + * This routine releases all resources associated with the + * specified window which are consumed by the text + * window package. This includes the entire text buffer, line start + * array, and the scroll bar window. However, the window + * itself is NOT destroyed. The routine will return zero if + * the window is not owned by the text window package. + */ +{ + struct txtWin *textInfo; + int index; + + if ((textInfo = (struct txtWin *) XLookUpAssoc(display, + textWindows, (XID) w)) == 0) + return 0; + + for (index = 0; index < MAXFONTS; index++) + if (textInfo->fontGC[index] != 0) + XFreeGC(display, textInfo->fontGC[index]); + + free((Generic) textInfo->mainBuffer); + for (index = 0; index < textInfo->numLines; index++) { + free((Generic) textInfo->txtBuffer[index]); + } + free((Generic) textInfo->txtBuffer); + XDestroyWindow(display, textInfo->scrollBar); + for (index = 0; index < textInfo->exposeSize; index++) { + free((Generic) textInfo->exposeAry[index]); + } + free((Generic) textInfo->exposeAry); + XDeleteAssoc(display, textWindows, (XID) w); + free((Generic) textInfo); + return 1; +} + + + +static int RecompBuffer(textInfo) +struct txtWin *textInfo; /* Text window information */ +/* + * This routine recomputes all line breaks in a buffer after + * a change in window size or font. This is done by throwing + * away the old line start array and recomputing it. Although + * a lot of this work is also done elsewhere, it has been included + * inline here for efficiency. + */ +{ + int startPos, endSize, linenum; + register int index, chsize, curfont; + register short *bufptr; + register XFontStruct *fontptr; + register struct txtLine *lineptr; + char theChar; + + /* Record the old position so we can come back to it */ + for (startPos = textInfo->txtBuffer[textInfo->startLine]->lineText; + (startPos > 0) && (textInfo->mainBuffer[startPos] != '\n'); + startPos--) + /* null loop body */; + + /* Clear out the old line start array */ + for (index = 0; index < textInfo->numLines; index++) { + InitLine(textInfo->txtBuffer[index]); + } + + /* Initialize first line */ + textInfo->txtBuffer[0]->lineHeight = + textInfo->theFonts[0].ascent + textInfo->theFonts[0].descent; + textInfo->txtBuffer[0]->lineText = 0; + + /* Process the text back into lines */ + endSize = textInfo->w - BARSIZE - WRAPINDSIZE; + bufptr = textInfo->mainBuffer; + lineptr = textInfo->txtBuffer[0]; + linenum = 0; + fontptr = &(textInfo->theFonts[0]); + curfont = 0; + for (index = 0; index < textInfo->bufSpot; index++) { + theChar = bufptr[index] & CHARMASK; + + if ((bufptr[index] & FONTMASK) != curfont) { + int newFontNum, heightDiff; + + /* Switch fonts */ + newFontNum = (bufptr[index] & FONTMASK) >> FONTSHIFT; + if (textInfo->theFonts[newFontNum].fid != 0) { + /* Valid font */ + curfont = bufptr[index] & FONTMASK; + fontptr = &(textInfo->theFonts[newFontNum]); + heightDiff = (fontptr->ascent + fontptr->descent) - + lineptr->lineHeight; + if (heightDiff < 0) heightDiff = 0; + lineptr->lineHeight += heightDiff; + } + } + if (theChar == '\n') { + /* Handle new line */ + if (linenum >= textInfo->allocLines-1) + /* Expand number of lines */ + ExpandLines(textInfo); + linenum++; + lineptr = textInfo->txtBuffer[linenum]; + /* Initialize next line */ + lineptr->lineHeight = fontptr->ascent + fontptr->descent; + lineptr->lineText = index+1; + /* Check to see if its the starting line */ + if (index == startPos) textInfo->startLine = linenum; + } else { + /* Handle normal character */ + chsize = CharSize(textInfo, linenum, index); + if (lineptr->lineWidth + chsize > endSize) { + /* Handle line wrap */ + lineptr->lineFlags |= WRAPFLAG; + if (linenum >= textInfo->allocLines-1) + /* Expand number of lines */ + ExpandLines(textInfo); + linenum++; + lineptr = textInfo->txtBuffer[linenum]; + /* Initialize next line */ + lineptr->lineHeight = fontptr->ascent + fontptr->descent; + lineptr->lineText = index; + lineptr->lineLength = 1; + lineptr->lineWidth += chsize; + } else { + /* Handle normal addition of character */ + lineptr->lineLength += 1; + lineptr->lineWidth += chsize; + } + } + } + /* We now have a valid line array. Let's clean up some other fields. */ + textInfo->numLines = linenum+1; + if (startPos == 0) { + textInfo->startLine = 0; + } + textInfo->endLine = FindEndLine(textInfo, &(textInfo->bottomSpace)); + textInfo->curLine = linenum; + /* Check to see if we are at the bottom */ + if (textInfo->endLine >= textInfo->numLines-1) { + textInfo->curY = textInfo->h - textInfo->bottomSpace - + lineptr->lineHeight; + textInfo->flagWord &= (~NOTATBOTTOM); + } else { + textInfo->flagWord |= NOTATBOTTOM; + } + return 1; +} + + + + +int TxtAddFont(display, textWin, fontNumber, newFont, newColor) +Display *display; +Window textWin; /* Scrollable text window */ +int fontNumber; /* Place to add font (0-7) */ +XFontStruct *newFont; /* Font to add */ +int newColor; /* Color of font */ +/* + * This routine loads a new font so that it can be used in a previously + * created text window. There are eight font slots numbered 0 through 7. + * If there is already a font in the specified slot, it will be replaced + * and an automatic redraw of the window will take place. See TxtWriteStr + * for details on using alternate fonts. The color specifies the foreground + * color of the text. The default foreground color is used if this + * parameter is TXT_NO_COLOR. Returns a non-zero value if + * everything went well. + */ +{ + struct txtWin *textInfo; + int redrawFlag; + XGCValues gc_val; + + if ((fontNumber < 0) || (fontNumber >= MAXFONTS)) return 0; + if ((textInfo = (struct txtWin *) + XLookUpAssoc(display, textWindows, (XID) textWin)) == 0) + return 0; + if (newColor == TXT_NO_COLOR) { + newColor = textInfo->fgPix; + } + + gc_val.font = newFont->fid; + gc_val.foreground = newColor; + gc_val.background = textInfo->bgPix; + gc_val.plane_mask = AllPlanes; + gc_val.graphics_exposures = 1; + gc_val.function = GXcopy; + + if (textInfo->fontGC[fontNumber] != 0) + { + XChangeGC(display, textInfo->fontGC[fontNumber], + GCFont | GCForeground, &gc_val); + } + else + textInfo->fontGC[fontNumber] = XCreateGC(display, textWin, + GCFont | + GCForeground | + GCBackground | + GCFunction | + GCPlaneMask | + GCGraphicsExposures, + &gc_val); + + + redrawFlag = (textInfo->theFonts[fontNumber].fid != 0) && + (((newFont) && (newFont->fid != textInfo->theFonts[fontNumber].fid)) || + (newColor != textInfo->theColors[fontNumber])); + if (newFont) { + textInfo->theFonts[fontNumber] = *newFont; + } + textInfo->theColors[fontNumber] = newColor; + + if (redrawFlag) { + RecompBuffer(textInfo); + XClearWindow(display, textWin); + TxtRepaint(display, textWin); + } + return 1; +} + + + +int TxtWinP(display, w) +Display *display; +Window w; +/* + * Returns a non-zero value if the window has been previously grabbed + * using TxtGrab and 0 if it has not. + */ +{ + if (XLookUpAssoc(display, textWindows, (XID) w)) + return(1); + else return(0); +} + + + +static int FindEndLine(textInfo, botSpace) +struct txtWin *textInfo; +int *botSpace; +/* + * Given the starting line in 'textInfo->startLine', this routine + * determines the index of the last line that can be drawn given the + * current size of the screen. If there are not enough lines to + * fill the screen, the index of the last line will be returned. + * The amount of empty bottom space is returned in 'botSpace'. + */ +{ + int index, height, lineHeight; + + height = YPADDING; + index = textInfo->startLine; + while (index < textInfo->numLines) { + lineHeight = textInfo->txtBuffer[index]->lineHeight + INTERLINE; + if (height + lineHeight > textInfo->h) break; + height += lineHeight; + index++; + } + if (botSpace) { + *botSpace = textInfo->h - height; + } + return index - 1; +} + + + +static int UpdateScroll(display, textInfo) +Display *display; +struct txtWin *textInfo; /* Text window information */ +/* + * This routine computes the current extent of the scroll bar + * indicator and repaints the bar with the correct information. + */ +{ + int top, bottom; + + if (textInfo->numLines > 1) { + top = textInfo->startLine * (textInfo->h - 2*BARBORDER) / + (textInfo->numLines - 1); + bottom = textInfo->endLine * (textInfo->h - 2*BARBORDER) / + (textInfo->numLines - 1); + } else { + top = 0; + bottom = textInfo->h - (2*BARBORDER); + } + + /* Draw it - make sure there is a little padding */ + if (top == 0) top++; + if (bottom == textInfo->h-(2*BARBORDER)) bottom--; + + XFillRectangle(display, textInfo->scrollBar, + textInfo->bgGC, + 0, 0, BARSIZE, top-1); +#ifdef __386BSD__ + XFillRectangle(display, textInfo->scrollBar, + DEFAULT_GC, top, BARSIZE - (2*BARBORDER) - 2, + BARSIZE, bottom - top); +#else + XFillRectangle(display, textInfo->scrollBar, + DEFAULT_GC, top, BARSIZE - (2*BARBORDER) - 2, + bottom - top); +#endif + XFillRectangle(display, textInfo->scrollBar, DEFAULT_GC, + 0, bottom+1, BARSIZE, + textInfo->h - (2 * BARBORDER) - bottom); + + return 1; +} + + + + +int TxtClear(display, w) +Display *display; +Window w; +/* + * This routine clears a scrollable text window. It resets the current + * writing position to the upper left hand corner of the screen. + * NOTE: THIS ALSO CLEARS THE CONTENTS OF THE TEXT WINDOW BUFFER AND + * RESETS THE SCROLL BAR. Returns 0 if the window is not a text window. + * This should be used *instead* of XClear. + */ +{ + struct txtWin *textInfo; + int index; + + if ((textInfo = (struct txtWin *) XLookUpAssoc(display, textWindows, (XID) w)) == 0) + return 0; + + /* Zero out the arrays */ + textInfo->bufSpot = 0; + for (index = 0; index < textInfo->numLines; index++) { + InitLine(textInfo->txtBuffer[index]); + } + textInfo->txtBuffer[0]->lineHeight = + textInfo->theFonts[textInfo->curFont].ascent + + textInfo->theFonts[textInfo->curFont].descent; + + textInfo->numLines = 1; + textInfo->startLine = 0; + textInfo->endLine = 0; + textInfo->curLine = 0; + textInfo->curX = 0; + textInfo->curY = YPADDING + textInfo->theFonts[textInfo->curFont].ascent + + textInfo->theFonts[textInfo->curFont].descent; + + textInfo->bottomSpace = textInfo->h - YPADDING - + textInfo->theFonts[textInfo->curFont].ascent - INTERLINE - + textInfo->theFonts[textInfo->curFont].descent; + /* Actually clear the window */ + XClearWindow(display, w); + + /* Draw the current cursor */ + XFillRectangle(display, w, textInfo->CursorGC, + XPADDING + CUROFFSET, textInfo->curY, + CURSORWIDTH, + textInfo->theFonts[textInfo->curFont].ascent + + textInfo->theFonts[textInfo->curFont].descent); + + /* Update the scroll bar */ + UpdateScroll(display, textInfo); + return 1; +} + + +static int WarpToBottom(display, textInfo) +Display *display; +struct txtWin *textInfo; /* Text Information */ +/* + * This routine causes the specified text window to display its + * last screen of information. It updates the scroll bar + * to the appropriate spot. The implementation scans backward + * through the buffer to find an appropriate starting spot for + * the window. + */ +{ + int index, height, lineHeight; + + index = textInfo->numLines-1; + height = 0; + while (index >= 0) { + lineHeight = textInfo->txtBuffer[index]->lineHeight + INTERLINE; + if (height + lineHeight > textInfo->h) break; + height += lineHeight; + index--; + } + textInfo->startLine = index + 1; + textInfo->endLine = FindEndLine(textInfo, &(textInfo->bottomSpace)); + textInfo->curY = textInfo->h - textInfo->bottomSpace - + textInfo->txtBuffer[textInfo->endLine]->lineHeight; + XClearWindow(display, textInfo->mainWindow); + TxtRepaint(display, textInfo->mainWindow); + return 1; +} + + + +static int UpdateExposures(display, textInfo) +Display *display; +struct txtWin *textInfo; /* Text window information */ +/* + * Before a new scrolling action occurs, the text window package + * must handle all COPYEXPOSE events generated by the last scrolling + * action. This routine is called to do this. Foreign events (those + * not handled by TxtFilter) are queued up and replaced on the queue + * after the processing of the exposure events is complete. + */ +{ +#if 0 + XEvent foreignQueue[MAXFOREIGN]; + int index, lastItem = 0; + + while (textInfo->flagWord & COPYEXPOSE) { + XNextEvent(display, &(foreignQueue[lastItem])); + if (!TxtFilter(display, &(foreignQueue[lastItem]))) + lastItem++; + if (lastItem >= MAXFOREIGN) { + printf("Too many foreign events to queue!\n"); + textInfo->flagWord &= (~COPYEXPOSE); + } + } + for (index = 0; index < lastItem; index++) { + XPutBackEvent(display, &(foreignQueue[index])); + } +#endif + return 1; +} + + +static int ScrollDown(display,textInfo) +Display *display; +struct txtWin *textInfo; /* Text window information */ +/* + * This routine scrolls the indicated text window down by one + * line. The line below the current line must exist. The window + * is scrolled so that the line below the last line is fully + * displayed. This may cause many lines to scroll off the top. + * Scrolling is done using XCopyArea. The exposure events should + * be caught using ExposeCopy. + */ +{ + int lineSum, index, targetSpace, freeSpace, updateFlag; + + lineSum = 0; + if (textInfo->endLine + 1 >= textInfo->numLines) return 0; + targetSpace = textInfo->txtBuffer[textInfo->endLine+1]->lineHeight + + INTERLINE; + if (textInfo->bottomSpace < targetSpace) { + index = textInfo->startLine; + while (index < textInfo->endLine) { + lineSum += (textInfo->txtBuffer[index]->lineHeight + INTERLINE); + if (textInfo->bottomSpace + lineSum >= targetSpace) break; + index++; + } + + /* Must move upward by 'lineSum' pixels */ + XCopyArea(display, textInfo->mainWindow, textInfo->mainWindow, + DEFAULT_GC, 0, lineSum, + textInfo->w - BARSIZE, textInfo->h, + 0, 0); + + textInfo->flagWord |= COPYEXPOSE; + /* Repair the damage to the structures */ + textInfo->startLine = index + 1; + updateFlag = 1; + } else { + updateFlag = 0; + } + /* More lines might be able to fit. Let's check. */ + freeSpace = textInfo->bottomSpace + lineSum - targetSpace; + index = textInfo->endLine + 1; + while (index < textInfo->numLines-1) { + if (freeSpace - textInfo->txtBuffer[index+1]->lineHeight - INTERLINE < 0) + break; + freeSpace -= (textInfo->txtBuffer[index+1]->lineHeight + INTERLINE); + index++; + } + textInfo->endLine = index; + textInfo->bottomSpace = freeSpace; + if (updateFlag) { + UpdateExposures(display, textInfo); + } + UpdateScroll(display, textInfo); + return 1; +} + + + + +static int ExpandLines(textInfo) +struct txtWin *textInfo; /* Text Information */ +/* + * This routine allocates and initializes additional space in + * the line start array (txtBuffer). The new space + * is allocated using realloc. The expansion factor is a percentage + * given by EXPANDPERCENT. + */ +{ + int newSize, index; + + newSize = textInfo->allocLines; + newSize += (newSize * EXPANDPERCENT) / 100; + + textInfo->txtBuffer = (struct txtLine **) + realloc((char *) textInfo->txtBuffer, + (unsigned) (newSize * sizeof(struct txtLine *))); + for (index = textInfo->allocLines; index < newSize; index++) { + textInfo->txtBuffer[index] = alloc(struct txtLine); + InitLine(textInfo->txtBuffer[index]); + } + textInfo->allocLines = newSize; + return 1; +} + +static int ExpandBuffer(textInfo) +struct txtWin *textInfo; /* Text information */ +/* + * Expands the basic character buffer using realloc. The expansion + * factor is a percentage given by EXPANDPERCENT. + */ +{ + int newSize; + + newSize = textInfo->bufAlloc + (textInfo->bufAlloc * EXPANDPERCENT) / 100; + textInfo->mainBuffer = (short *) + realloc((char *) textInfo->mainBuffer, (unsigned) newSize * sizeof(short)); + textInfo->bufAlloc = newSize; + return 1; +} + + + +static int HandleNewLine(display, textInfo, flagWord) +Display *display; +struct txtWin *textInfo; /* Text Information */ +int flagWord; /* DODISP or NONEWLINE or both */ +/* + * This routine initializes the next line for drawing by setting + * its height to the current font height, scrolls the screen down + * one line, and updates the current drawing position to the + * left edge of the newly cleared line. If DODISP is specified, + * the screen will be updated (otherwise not). If NONEWLINE is + * specified, no newline character will be added to the text buffer + * (this is for line wrap). + */ +{ + struct txtLine *curLine, *nextLine; + + /* Check to see if a new line must be allocated */ + if (textInfo->curLine >= textInfo->allocLines-1) + /* Expand the number of lines */ + ExpandLines(textInfo); + textInfo->numLines += 1; + + /* Then we initialize the next line */ + nextLine = textInfo->txtBuffer[textInfo->numLines-1]; + nextLine->lineHeight = + textInfo->theFonts[textInfo->curFont].ascent + + textInfo->theFonts[textInfo->curFont].descent; + + curLine = textInfo->txtBuffer[textInfo->curLine]; + if (flagWord & DODISP) { + /* Scroll down a line if required */ + if ((textInfo->curY + curLine->lineHeight + + nextLine->lineHeight + (INTERLINE * 2)) > textInfo->h) + { + ScrollDown(display, textInfo); + } + else + { + /* Update the bottom space appropriately */ + textInfo->bottomSpace -= (nextLine->lineHeight + INTERLINE); + textInfo->endLine += 1; + } + /* Update drawing position */ + textInfo->curY = textInfo->h - + (textInfo->bottomSpace + nextLine->lineHeight); + } + + /* Move down a line */ + textInfo->curLine += 1; + if (!(flagWord & NONEWLINE)) { + /* Append end-of-line to text buffer */ + if (textInfo->bufSpot >= textInfo->bufAlloc) { + /* Allocate more space in main text buffer */ + ExpandBuffer(textInfo); + } + textInfo->mainBuffer[(textInfo->bufSpot)++] = + (textInfo->curFont << FONTSHIFT) | '\n'; + } + nextLine->lineText = textInfo->bufSpot; + textInfo->curX = 0; + return 1; +} + + + +static int CharSize(textInfo, lineNum, charNum) +struct txtWin *textInfo; /* Current Text Information */ +int lineNum; /* Line in buffer */ +int charNum; /* Character in line */ +/* + * This routine determines the size of the specified character. + * It takes in account the font of the character and whether its + * fixed or variable. The size includes INTERSPACE spacing between + * the characters. + */ +{ + register XFontStruct *charFont; + register short *theLine; + register short theChar; + + theLine = &(textInfo->mainBuffer[textInfo->txtBuffer[lineNum]->lineText]); + theChar = theLine[charNum] & CHARMASK; + charFont = &(textInfo->theFonts[(theChar & FONTMASK) >> FONTSHIFT]); + if (theChar <= charFont->min_char_or_byte2 || + theChar >= charFont->max_char_or_byte2 || + charFont->per_char == 0) + return charFont->max_bounds.width + 1; + else + return charFont->per_char[theChar].width + 1; +} + + + + + +static int HandleBackspace(display, textInfo, flagWord) +Display *display; +struct txtWin *textInfo; /* Text Information */ +int flagWord; /* DODISP or nothing */ +/* + * This routine handles a backspace found in the input stream. The + * character before the current writing position will be erased and + * the drawing position will move back one character. If the writing + * position is at the left margin, the drawing position will move + * up to the previous line. If it is a line that has been wrapped, + * the character at the end of the previous line will be erased. + */ +{ + struct txtLine *thisLine, *prevLine; + int chSize; + + thisLine = textInfo->txtBuffer[textInfo->curLine]; + /* First, determine whether we need to go back a line */ + if (thisLine->lineLength == 0) { + /* Bleep if at top of buffer */ + if (textInfo->curLine == 0) { + XBell(display, 50); + return 0; + } + + /* See if we have to scroll in the other direction */ + if ((flagWord & DODISP) && (textInfo->curY <= YPADDING)) { + /* This will display the last lines of the buffer */ + WarpToBottom(display, textInfo); + } + + /* Set drawing position at end of previous line */ + textInfo->curLine -= 1; + prevLine = textInfo->txtBuffer[textInfo->curLine]; + textInfo->numLines -= 1; + if (flagWord & DODISP) { + textInfo->curY -= (prevLine->lineHeight + INTERLINE); + textInfo->bottomSpace += (thisLine->lineHeight + INTERLINE); + textInfo->endLine -= 1; + } + + /* We are unlinewrapping if the previous line has flag set */ + if (prevLine->lineFlags & WRAPFLAG) { + /* Get rid of line wrap indicator */ + if (flagWord & DODISP) { + XFillRectangle(display, textInfo->mainWindow, + textInfo->bgGC, + textInfo->w - BARSIZE - WRAPINDSIZE, + textInfo->curY, WRAPINDSIZE, + prevLine->lineHeight); + } + prevLine->lineFlags &= (~WRAPFLAG); + /* Call recursively to wipe out the ending character */ + HandleBackspace(display, textInfo, flagWord); + } else { + /* Delete the end-of-line in the primary buffer */ + textInfo->bufSpot -= 1; + } + } else { + /* Normal deletion of character */ + chSize = + CharSize(textInfo, textInfo->curLine, + textInfo->txtBuffer[textInfo->curLine]->lineLength - 1); + /* Move back appropriate amount and wipe it out */ + thisLine->lineWidth -= chSize; + if (flagWord & DODISP) { + XFillRectangle(display, textInfo->mainWindow, + textInfo->bgGC, + thisLine->lineWidth, textInfo->curY, + chSize, thisLine->lineHeight); + } + /* Delete from buffer */ + textInfo->txtBuffer[textInfo->curLine]->lineLength -= 1; + textInfo->bufSpot -= 1; + } + return 1; +} + + + +static int DrawLineWrap(display, win, x, y, h, col) +Display *display; +Window win; /* What window to draw it in */ +int x, y; /* Position of upper left corner */ +int h; /* Height of indicator */ +int col; /* Color of indicator */ +/* + * This routine draws a line wrap indicator at the end of a line. + * Visually, it is an arrow of the specified height directly against + * the scroll bar border. The bitmap used for the arrow is stored + * in 'arrowMap' with size 'arrow_width' and 'arrow_height'. + */ +{ + struct txtWin *textInfo; + + textInfo = (struct txtWin *)XLookUpAssoc(display, textWindows, + (XID) win); + + /* First, draw the arrow */ +#ifdef __386BSD__ + XCopyArea(display, textInfo->arrowMap, textInfo->mainWindow, + textInfo->CursorGC, + 0, 0, arrow_width, arrow_height, + x, y + h - arrow_height); +#else + XCopyArea(display, textInfo->arrowMap, textInfo->mainWindow, + textInfo->CursorGC, + 0, 0, arrow_width, arrow_height, + x, y + h - arrow_height, 1); +#endif + + /* Then draw the stem */ + XDrawLine(display, textInfo->mainWindow, textInfo->CursorGC, + x + STEMOFFSET, y, + x + STEMOFFSET, y + h - arrow_height); + return 1; +} + + + + +static int DrawLine(display, textInfo, lineIndex, ypos) +Display *display; +struct txtWin *textInfo; /* Text window information */ +int lineIndex; /* Index of line to draw */ +int ypos; /* Y position for line */ +/* + * This routine destructively draws the indicated line in the + * indicated window at the indicated position. It does not + * clear to end of line however. It draws a line wrap indicator + * if needed but does not draw a cursor. + */ +{ + int index, startPos, curFont, theColor, curX, saveX, fontIndex; + struct txtLine *someLine; + char lineBuffer[BUFSIZE], *glyph; + short *linePointer; + XFontStruct *theFont; + XGCValues gc; + + /* First, we draw the text */ + index = 0; + curX = XPADDING; + someLine = textInfo->txtBuffer[lineIndex]; + linePointer = &(textInfo->mainBuffer[someLine->lineText]); + while (index < someLine->lineLength) { + startPos = index; + saveX = curX; + curFont = linePointer[index] & FONTMASK; + fontIndex = curFont >> FONTSHIFT; + theFont = &(textInfo->theFonts[fontIndex]); + theColor = textInfo->theColors[fontIndex]; + glyph = &(lineBuffer[0]); + while ((index < someLine->lineLength) && + ((linePointer[index] & FONTMASK) == curFont)) + { + *glyph = linePointer[index] & CHARMASK; + index++; + curX += CharSize(textInfo, lineIndex, index); + glyph++; + } + + /* Flush out the glyphs */ + XFillRectangle(display, textInfo->mainWindow, + textInfo->bgGC, + saveX, ypos, + textInfo->w - BARSIZE, + someLine->lineHeight + YPADDING + INTERLINE); + + XDrawString(display, textInfo->mainWindow, + textInfo->fontGC[fontIndex], + saveX, ypos, + lineBuffer, someLine->lineLength); + } + /* Then the line wrap indicator (if needed) */ + if (someLine->lineFlags & WRAPFLAG) { + DrawLineWrap(display, textInfo->mainWindow, + textInfo->w - BARSIZE - WRAPINDSIZE, + ypos, someLine->lineHeight, + textInfo->fgPix); + } + return 1; +} + + + + +static int HandleNewFont(display, fontNum, textInfo, flagWord) +Display *display; +int fontNum; /* Font number */ +struct txtWin *textInfo; /* Text information */ +int flagWord; /* DODISP or nothing */ +/* + * This routine handles a new font request. These requests take + * the form "^F<digit>". The parsing is done in TxtWriteStr. + * This routine is called only if the form is valid. It may return + * a failure (0 status) if the requested font is not loaded. + * If the new font is larger than any of the current + * fonts on the line, it will change the line height and redisplay + * the line. + */ +{ + struct txtLine *thisLine; + int heightDiff, baseDiff, redrawFlag; + + if (textInfo->theFonts[fontNum].fid == 0) { + return 0; + } else { + thisLine = textInfo->txtBuffer[textInfo->curLine]; + textInfo->curFont = fontNum; + redrawFlag = 0; + heightDiff = textInfo->theFonts[fontNum].ascent + + textInfo->theFonts[fontNum].descent - + thisLine->lineHeight; + + if (heightDiff > 0) { + redrawFlag = 1; + } else { + heightDiff = 0; + } + + if (redrawFlag) { + if (flagWord & DODISP) { + /* Clear current line */ + XFillRectangle(display, textInfo->mainWindow, + textInfo->bgGC, + 0, textInfo->curY, textInfo->w, + thisLine->lineHeight); + + /* Check to see if it requires scrolling */ + if ((textInfo->curY + thisLine->lineHeight + heightDiff + + INTERLINE) > textInfo->h) + { + /* + * General approach: "unscroll" the last line up + * and then call ScrollDown to do the right thing. + */ + textInfo->endLine -= 1; + textInfo->bottomSpace += thisLine->lineHeight + + INTERLINE; + + XFillRectangle(display, textInfo->mainWindow, + textInfo->bgGC, + 0, textInfo->h - textInfo->bottomSpace, + textInfo->w, textInfo->bottomSpace); + + thisLine->lineHeight += heightDiff; + ScrollDown(display, textInfo); + textInfo->curY = textInfo->h - + (textInfo->bottomSpace + INTERLINE + + thisLine->lineHeight); + } + else + { + /* Just update bottom space */ + textInfo->bottomSpace -= heightDiff; + thisLine->lineHeight += heightDiff; + } + /* Redraw the current line */ + DrawLine(display, textInfo, textInfo->curLine, textInfo->curY); + } else { + /* Just update line height */ + thisLine->lineHeight += heightDiff; + } + } + return 1; + } +} + + + +int TxtWriteStr(display, w, str) +Display *display; +Window w; /* Text window */ +register char *str; /* 0 terminated string */ +/* + * This routine writes a string to the specified text window. + * The following notes apply: + * - Text is always appended to the end of the text buffer. + * - If the scroll bar is positioned such that the end of the + * text is not visible, an automatic scroll to the bottom + * will be done before the appending of text. + * - Non-printable ASCII characters are not displayed. + * - The '\n' character causes the current text position to + * advance one line and start at the left. + * - Tabs are not supported. + * - Lines too long for the screen will be wrapped and a line wrap + * indication will be drawn. + * - Backspace clears the previous character. It will do the right + * thing if asked to backspace past a wrapped line. + * - A new font can be chosen using the sequence '^F<digit>' where + * <digit> is 0-7. The directive will be ignored if + * there is no font in the specified slot. + * Returns 0 if something went wrong. + */ +{ + register int fontIndex; + register struct txtWin *textInfo; + register struct txtLine *thisLine; + + if ((textInfo = (struct txtWin *) XLookUpAssoc(display, textWindows, (XID) w)) == 0) + return 0; + + /* See if screen needs to be updated */ + if (textInfo->flagWord & SCREENWRONG) { + TxtRepaint(display, textInfo->mainWindow); + } + + /* See if we have to scroll down to the bottom */ + if (textInfo->flagWord & NOTATBOTTOM) { + WarpToBottom(display, textInfo); + textInfo->flagWord &= (~NOTATBOTTOM); + } + + /* Undraw the current cursor */ + thisLine = textInfo->txtBuffer[textInfo->curLine]; + + XFillRectangle(display, w, textInfo->bgGC, + thisLine->lineWidth + CUROFFSET, + textInfo->curY, + CURSORWIDTH, + thisLine->lineHeight); + + for ( /* str is ok */ ; (*str != 0) ; str++) { + /* Check to see if we are waiting on a font */ + if (textInfo->flagWord & FONTNUMWAIT) { + textInfo->flagWord &= (~FONTNUMWAIT); + fontIndex = *str - '0'; + if ((fontIndex >= 0) && (fontIndex < MAXFONTS)) { + /* Handle font -- go get next character */ + if (HandleNewFont(display, fontIndex, textInfo, DODISP)) + continue; + } + } + + /* Inline code for handling normal character case */ + if ((*str >= LOWCHAR) && (*str <= HIGHCHAR)) { + register XFontStruct *thisFont; + register struct txtLine *thisLine; + register int charWidth; + int thisColor; + + /* Determine size of character */ + thisFont = &(textInfo->theFonts[textInfo->curFont]); + thisColor = textInfo->theColors[textInfo->curFont]; + if (*str <= thisFont->min_char_or_byte2 || + *str >= thisFont->max_char_or_byte2 || + thisFont->per_char == 0) + charWidth = thisFont->max_bounds.width + 1; + else + charWidth = thisFont->per_char[*str].width + 1; + + /* Check to see if line wrap is required */ + thisLine = textInfo->txtBuffer[textInfo->curLine]; + if (thisLine->lineWidth + charWidth > + (textInfo->w-BARSIZE-WRAPINDSIZE)) + { + DrawLineWrap(display, textInfo->mainWindow, + textInfo->w-BARSIZE-WRAPINDSIZE, + textInfo->curY, thisLine->lineHeight, + textInfo->fgPix); + thisLine->lineFlags |= WRAPFLAG; + /* Handle the spacing problem the same way as a newline */ + HandleNewLine(display, textInfo, DODISP | NONEWLINE); + thisLine = textInfo->txtBuffer[textInfo->curLine]; + } + + /* Ready to draw character */ + XDrawString(display, textInfo->mainWindow, + DEFAULT_GC, + textInfo->curX += charWidth, + textInfo->curY + thisLine->lineHeight, + str, 1); + + /* Append character onto main buffer */ + if (textInfo->bufSpot >= textInfo->bufAlloc) + /* Make room for more characters */ + ExpandBuffer(textInfo); + textInfo->mainBuffer[(textInfo->bufSpot)++] = + (textInfo->curFont << FONTSHIFT) | (*str); + + /* Update the line start array */ + thisLine->lineLength += 1; + thisLine->lineWidth += charWidth; + } else if (*str == NEWLINE) { + HandleNewLine(display, textInfo, DODISP); + } else if (*str == NEWFONT) { + /* Go into waiting for font number mode */ + textInfo->flagWord |= FONTNUMWAIT; + } else if (*str == BACKSPACE) { + HandleBackspace(display, textInfo, DODISP); + } else { + /* Ignore all others */ + } + } + /* Draw the cursor in its new position */ + thisLine = textInfo->txtBuffer[textInfo->curLine]; + + XFillRectangle(display, w, textInfo->CursorGC, + thisLine->lineWidth + CUROFFSET, + textInfo->curY /* + thisLine->lineHeight */, + CURSORWIDTH, thisLine->lineHeight); + + return 1; +} + + + +int TxtJamStr(display, w, str) +Display *display; +Window w; /* Text window */ +register char *str; /* NULL terminated string */ +/* + * This is the same as TxtWriteStr except the screen is NOT updated. + * After a call to this routine, TxtRepaint should be called to + * update the screen. This routine is meant to be used to load + * a text buffer with information and then allow the user to + * scroll through it at will. + */ +{ + register int fontIndex; + register struct txtWin *textInfo; + + if ((textInfo = (struct txtWin *) XLookUpAssoc(display, textWindows, (XID) w) + ) == 0) + return 0; + + for ( /* str is ok */ ; (*str != 0) ; str++) { + /* Check to see if we are waiting on a font */ + if (textInfo->flagWord & FONTNUMWAIT) { + textInfo->flagWord &= (~FONTNUMWAIT); + fontIndex = *str - '0'; + if ((fontIndex >= 0) && (fontIndex < MAXFONTS)) { + if (HandleNewFont(display, fontIndex, textInfo, 0)) { + /* Handled font -- go get next character */ + continue; + } + } + } + /* Inline code for handling normal character case */ + if ((*str >= LOWCHAR) && (*str <= HIGHCHAR)) { + register XFontStruct *thisFont; + register struct txtLine *thisLine; + register int charWidth; + + /* Determine size of character */ + thisFont = &(textInfo->theFonts[textInfo->curFont]); + + if (*str <= thisFont->min_char_or_byte2 || + *str >= thisFont->max_char_or_byte2 || + thisFont->per_char == 0) + charWidth = thisFont->max_bounds.width + 1; + else + charWidth = thisFont->per_char[*str].width + 1; + + /* Check to see if line wrap is required */ + thisLine = textInfo->txtBuffer[textInfo->curLine]; + if (thisLine->lineWidth + charWidth > + (textInfo->w-BARSIZE-WRAPINDSIZE)) + { + thisLine->lineFlags |= WRAPFLAG; + /* Handle the spacing problem the same way as a newline */ + HandleNewLine(display, textInfo, NONEWLINE); + thisLine = textInfo->txtBuffer[textInfo->curLine]; + } + /* Append character onto main buffer */ + if (textInfo->bufSpot >= textInfo->bufAlloc) + /* Make room for more characters */ + ExpandBuffer(textInfo); + textInfo->mainBuffer[(textInfo->bufSpot)++] = + (textInfo->curFont << FONTSHIFT) | (*str); + + /* Update the line start array */ + thisLine->lineLength += 1; + thisLine->lineWidth += charWidth; + } else if (*str == NEWLINE) { + HandleNewLine(display, textInfo, 0); + } else if (*str == NEWFONT) { + /* Go into waiting for font number mode */ + textInfo->flagWord |= FONTNUMWAIT; + } else if (*str == BACKSPACE) { + HandleBackspace(display, textInfo, 0); + } else { + /* Ignore all others */ + } + } + textInfo->flagWord |= SCREENWRONG; + return 1; +} + + + +int TxtRepaint(display,w) +Display *display; +Window w; +/* + * Repaints the given scrollable text window. The routine repaints + * the entire window. For handling exposure events, the TxtFilter + * routine should be used. + */ +{ + struct txtWin *textInfo; + int index, ypos; + + if ((textInfo = (struct txtWin *) XLookUpAssoc(display, textWindows, (XID) w) + ) == 0) + return 0; + + /* Check to see if the screen is up to date */ + if (textInfo->flagWord & SCREENWRONG) { + textInfo->endLine = FindEndLine(textInfo, &(textInfo->bottomSpace)); + textInfo->flagWord &= (~SCREENWRONG); + } + + ypos = YPADDING; + index = textInfo->startLine; + for (;;) { + DrawLine(display, textInfo, index, ypos); + if (index >= textInfo->endLine) break; + ypos += (textInfo->txtBuffer[index]->lineHeight + INTERLINE); + index++; + } + /* Draw the cursor (if on screen) */ + if (textInfo->endLine == textInfo->curLine) { + XFillRectangle(display, w, textInfo->CursorGC, + textInfo->txtBuffer[index]->lineWidth + CUROFFSET, + ypos /* + textInfo->txtBuffer[index]->lineHeight */, + CURSORWIDTH, textInfo->txtBuffer[index]->lineHeight); + + } + /* Update the scroll bar */ + UpdateScroll(display, textInfo); + return 1; +} + + + +static int InsertIndex(textInfo, thisIndex, ypos) +struct txtWin *textInfo; /* Text Window Information */ +int thisIndex; /* Line index of exposed line */ +int ypos; /* Drawing position of line */ +/* + * This routine inserts the supplied line index into the copy + * exposure array for 'textInfo'. The array is kept sorted + * from lowest to highest using insertion sort. The array + * is dynamically expanded if needed. + */ +{ + struct expEvent *newItem; + int newSize, index, downIndex; + + /* Check to see if we need to expand it */ + if ((textInfo->exposeSize + 3) >= textInfo->exposeAlloc) { + newSize = textInfo->exposeAlloc + + (textInfo->exposeAlloc * EXPANDPERCENT / 100); + textInfo->exposeAry = (struct expEvent **) + realloc((char *) textInfo->exposeAry, + (unsigned) (newSize * sizeof(struct expEvent *))); + for (index = textInfo->exposeAlloc; index < newSize; index++) + textInfo->exposeAry[index] = alloc(struct expEvent); + textInfo->exposeAlloc = newSize; + } + /* Find spot for insertion. NOTE: last spot has big number */ + for (index = 0; index <= textInfo->exposeSize; index++) { + if (textInfo->exposeAry[index]->lineIndex >= thisIndex) { + if (textInfo->exposeAry[index]->lineIndex > thisIndex) { + /* Insert before this entry */ + newItem = textInfo->exposeAry[textInfo->exposeSize+1]; + for (downIndex = textInfo->exposeSize; + downIndex >= index; + downIndex--) + { + textInfo->exposeAry[downIndex+1] = + textInfo->exposeAry[downIndex]; + } + /* Put a free structure at this spot */ + textInfo->exposeAry[index] = newItem; + /* Fill it in */ + textInfo->exposeAry[index]->lineIndex = thisIndex; + textInfo->exposeAry[index]->ypos = ypos; + /* Break out of loop */ + textInfo->exposeSize += 1; + } + break; + } + } + return 1; +} + + + +static int ScrollUp(display, textInfo) +Display *display; +struct txtWin *textInfo; /* Text window information */ +/* + * This routine scrolls the indicated text window up by one + * line. The line above the current line must exist. The + * window is scrolled so that the line above the start line + * is displayed at the top of the screen. This may cause + * many lines to scroll off the bottom. The scrolling is + * done using XCopyArea. The exposure events should be caught + * by ExposeCopy. + */ +{ + int targetSpace; + + /* Make sure all exposures have been handled by now */ + if (textInfo->startLine == 0) return 0; + targetSpace = textInfo->txtBuffer[textInfo->startLine-1]->lineHeight + + INTERLINE; + /* Move the area downward by the target amount */ + XCopyArea(display, textInfo->mainWindow, textInfo->mainWindow, + DEFAULT_GC, + 0, YPADDING, textInfo->w - BARSIZE, + textInfo->h, 0, targetSpace); + + textInfo->flagWord |= COPYEXPOSE; + /* Update the text window parameters */ + textInfo->startLine -= 1; + textInfo->endLine = FindEndLine(textInfo, &(textInfo->bottomSpace)); + + /* Clear out bottom space region */ +#ifdef __386BSD__ + XClearArea(display, textInfo->mainWindow, + 0, textInfo->h - textInfo->bottomSpace, + textInfo->w, textInfo->bottomSpace, 1); +#else + XClearArea(display, textInfo->mainWindow, + 0, textInfo->h - textInfo->bottomSpace, + textInfo->w, textInfo->bottomSpace); +#endif + + UpdateExposures(display, textInfo); + UpdateScroll(display, textInfo); + + return 1; +} + + +static int ScrollToSpot(display, textInfo, ySpot) +Display *display; +struct txtWin *textInfo; /* Text window information */ +int ySpot; /* Button position in scroll window */ +/* + * This routine scrolls the specified text window relative to the + * position of the mouse in the scroll bar. The center of the screen + * will be positioned to correspond to the mouse position. + */ +{ + int targetLine, aboveLines; + + targetLine = textInfo->numLines * ySpot / textInfo->h; + textInfo->startLine = targetLine; + textInfo->endLine = FindEndLine(textInfo, &(textInfo->bottomSpace)); + aboveLines = 0; + /* Make the target line the *center* of the window */ + while ((textInfo->startLine > 0) && + (aboveLines < textInfo->endLine - targetLine)) + { + textInfo->startLine -= 1; + textInfo->endLine = FindEndLine(textInfo, &(textInfo->bottomSpace)); + aboveLines++; + } + if (textInfo->endLine == textInfo->numLines-1) { + WarpToBottom(display, textInfo); + } else { + XClearWindow(display, textInfo->mainWindow); + TxtRepaint(display, textInfo->mainWindow); + } + return 1; +} + + + +static int LineToTop(display, textInfo, pos) +Display *display; +struct txtWin *textInfo; /* Text window information */ +int pos; /* Y position of mouse */ +/* + * This routine scrolls the screen down until the line at the + * mouse position is at the top of the screen. It stops + * if it can't scroll the buffer down that far. If the + * global 'ScrollOption' is NORMSCROLL, a smooth scroll + * is used. Otherwise, it jumps to the right position + * and repaints the screen. + */ +{ + int index, sum; + + /* First, we find the current line */ + sum = 0; + for (index = textInfo->startLine; index <= textInfo->endLine; index++) { + if (sum + textInfo->txtBuffer[index]->lineHeight + INTERLINE> pos) break; + sum += textInfo->txtBuffer[index]->lineHeight + INTERLINE; + } + /* We always want to scroll down at least one line */ + if (index == textInfo->startLine) index++; + if (ScrollOption == NORMSCROLL) { + /* Scroll down until 'index' is the starting line */ + while ((textInfo->startLine < index) && ScrollDown(display, textInfo)) + { + /* Empty Loop Body */ + } + } else { + /* Immediately jump to correct spot */ + textInfo->startLine = index; + textInfo->endLine = FindEndLine(textInfo, &(textInfo->bottomSpace)); + if (textInfo->endLine == textInfo->numLines-1) { + WarpToBottom(display, textInfo); + } else { + XClearWindow(display, textInfo->mainWindow); + TxtRepaint(display, textInfo->mainWindow); + } + } + /* Check to see if at end of buffer */ + if (textInfo->endLine >= textInfo->numLines-1) { + textInfo->flagWord &= (~NOTATBOTTOM); + } + return 1; +} + + + +static int TopToHere(display, textInfo, pos) +Display *display; +struct txtWin *textInfo; /* Text window information */ +int pos; /* Y position of mouse */ +/* + * This routine scrolls the screen up until the top line of + * the screen is at the current Y position of the mouse. Again, + * it will stop if it can't scroll that far. If the global + * 'ScrollOption' is NORMSCROLL, a smooth scroll is used. + * If it's not, it will simply redraw the screen at the + * correct spot. + */ +{ + int sum, target, linesup, index; + + target = pos - textInfo->txtBuffer[textInfo->startLine]->lineHeight; + /* We always want to scroll up at least one line */ + if (target <= 0) target = 1; + sum = 0; + linesup = 0; + /* Check to see if we are at the top anyway */ + if (textInfo->startLine == 0) return 0; + if (ScrollOption == NORMSCROLL) { + /* Scroll up until sum of new top lines greater than target */ + while ((sum < target) && ScrollUp(display, textInfo)) { + sum += textInfo->txtBuffer[textInfo->startLine]->lineHeight; + linesup++; + } + } else { + /* Search backward to find index */ + index = textInfo->startLine - 1; + while ((index > 0) && (sum < target)) { + sum += textInfo->txtBuffer[index]->lineHeight; + linesup++; + index--; + } + /* Go directly to the index */ + textInfo->startLine = index; + textInfo->endLine = FindEndLine(textInfo, &(textInfo->bottomSpace)); + XClearWindow(display, textInfo->mainWindow); + TxtRepaint(display, textInfo->mainWindow); + } + /* If we scrolled, assert we are not at bottom of buffer */ + if (linesup > 0) { + textInfo->flagWord |= NOTATBOTTOM; + } + return 1; +} + + + +int TxtFilter(display, evt) +Display *display; +XEvent *evt; +/* + * This routine handles events associated with scrollable text windows. + * It will handle all exposure events and any button released events + * in the scroll bar of a text window. It does NOT handle any other + * events. If it cannot handle the event, it will return 0. + */ +{ + XExposeEvent *expose = &evt->xexpose; + XButtonEvent *btEvt = &evt->xbutton; + XGraphicsExposeEvent *gexpose = &evt->xgraphicsexpose; + XNoExposeEvent *noexpose = &evt->xnoexpose; + struct txtWin *textInfo; + int index, ypos; + Window w, sw; + + if (textWindows == (XAssocTable *) 0) { + textWindows = XCreateAssocTable(32); + if (textWindows == (XAssocTable *) 0) return(0); + } + if (evt->type == Expose) { + w = expose->window; + sw = 0; + } + else if (evt->type == GraphicsExpose) { + w = gexpose->drawable; + sw = 0; + } + else if (evt->type == NoExpose) { + w = noexpose->drawable; + sw = 0; + } + else if (evt->type == ButtonRelease) { + w = btEvt->window; + sw = btEvt->subwindow; + } + else + return 0; + + if ((textInfo = (struct txtWin *) + XLookUpAssoc(display, textWindows, (XID) w)) == 0) + return 0; + + /* Determine whether it's main window or not */ + if ((w == textInfo->mainWindow) && (sw == 0)) { + /* Main Window - handle exposures */ + switch (evt->type) { + case Expose: + ypos = 0 /*YPADDING*/; + for (index = textInfo->startLine; + index <= textInfo->endLine; + index++) + { + int lh = textInfo->txtBuffer[index]->lineHeight; + + if (((ypos + lh) >= expose->y) && + (ypos <= (expose->y + expose->height))) + { + /* Intersection region */ + /* Draw line immediately */ + DrawLine(display, textInfo, index, ypos); + /* And possibly draw cursor */ + if (textInfo->curLine == index) { + XFillRectangle(display, w, textInfo->CursorGC, + textInfo->txtBuffer[index]->lineWidth + + CUROFFSET, + ypos, + CURSORWIDTH, + lh); + } + } + ypos += lh + INTERLINE; + } + break; + case GraphicsExpose: + ypos = 0 /*YPADDING*/; + for (index = textInfo->startLine; + index <= textInfo->endLine; + index++) + { + int lh = textInfo->txtBuffer[index]->lineHeight; + + if (((ypos + lh) >= gexpose->y) && + (ypos <= (gexpose->y + gexpose->height))) + { + /* Intersection region */ + /* Draw line immediately */ + DrawLine(display, textInfo, index, ypos); + /* And possibly draw cursor */ + if (textInfo->curLine == index) { + XFillRectangle(display, w, textInfo->CursorGC, + textInfo->txtBuffer[index]->lineWidth + + CUROFFSET, + ypos, + CURSORWIDTH, + lh); + } + } + ypos += lh + INTERLINE; + } + break; + case NoExpose: + break; + default: + /* Not one of our events */ + return 0; + } + } else { + switch (evt->type) { + case Expose: + UpdateScroll(display, textInfo); + break; + case ButtonRelease: + /* Find out which button */ + switch (btEvt->button) { + case Button1: + /* Scroll up until top line is at mouse position */ + TopToHere(display, textInfo, btEvt->y); + break; + case Button2: + /* Scroll to spot relative to position */ + ScrollToSpot(display, textInfo, btEvt->y); + if (textInfo->endLine >= textInfo->numLines-1) { + textInfo->flagWord &= (~NOTATBOTTOM); + } else { + textInfo->flagWord |= NOTATBOTTOM; + } + break; + case Button3: + /* Scroll down until pointed line is at top */ + LineToTop(display, textInfo, btEvt->y); + break; + } + break; + default: + /* Not one of our events */ + return 0; + } + } + return 1; +} diff --git a/gnu/games/chess/Xchess/scrollText.h b/gnu/games/chess/Xchess/scrollText.h new file mode 100644 index 000000000000..d9d05b08dc0b --- /dev/null +++ b/gnu/games/chess/Xchess/scrollText.h @@ -0,0 +1,32 @@ +/* + * Scrollable Text Window Header File + * + * David Harrison + * University of California, Berkeley + * 1986 + * + * This file contains definitions for a scrollable text window + * with scroll bar support. + */ + +int TxtGrab(); + /* Take hold of a previously created window */ + +#define TXT_NO_COLOR -1 + +int TxtAddFont(); + /* Loads a new font for use later */ +int TxtWinP(); + /* Returns non-zero value if the window is text window */ +int TxtClear(); + /* Clears text window and resets text buffer */ + +int TxtWriteStr(); + /* Writes a string to window with immediate update */ +int TxtJamStr(); + /* Write a string without causing update to screen */ + +int TxtRepaint(); + /* Repaints entire scrollable text window */ +int TxtFilter(); + /* Handles events related to text window */ diff --git a/gnu/games/chess/Xchess/scrollText/scrollText.c b/gnu/games/chess/Xchess/scrollText/scrollText.c new file mode 100644 index 000000000000..432071086d15 --- /dev/null +++ b/gnu/games/chess/Xchess/scrollText/scrollText.c @@ -0,0 +1,1858 @@ +/* + * A Scrollable Text Output Window + * + * David Harrison + * University of California, Berkeley + * 1986 + * + * The following is an implementation for a scrollable text output + * system. It handles exposure events only (other interactions are + * under user control). For scrolling, a always present scroll bar + * is implemented. It detects size changes and compensates accordingly. + */ + +#include <X11/X.h> +#include <X11/Xlib.h> +#include <X11/X10.h> +#include <sys/types.h> +#include "scrollText.h" + +extern char *malloc(); +extern char *realloc(); +#define alloc(type) (type *) malloc(sizeof(type)) +#define numalloc(type, num) (type *) malloc((unsigned) (num * sizeof(type))) +#define MAXINT 2147483647 + +extern XAssocTable *XCreateAssocTable(); +extern caddr_t XLookUpAssoc(); + +static XAssocTable *textWindows = (XAssocTable *) 0; + +#define NOOPTION -1 /* Option hasn't been set yet */ +#define NORMSCROLL 0 /* Smooth scroll on LineToTop and TopToHere */ +#define JUMPSCROLL 1 /* Jump scrolling on LineToTop and TopToHere */ + +static int ScrollOption = NOOPTION; + +typedef char *Generic; + +#define DEFAULT_GC textInfo->fontGC[textInfo->curFont] + +#define BARSIZE 15 +#define BARBORDER 1 +#define MAXFONTS 8 +#define INITBUFSIZE 1024 +#define INITLINES 50 +#define INITEXPARY 50 +#define XPADDING 2 +#define YPADDING 2 +#define INTERLINE 5 +#define INTERSPACE 1 +#define CURSORWIDTH 2 +#define EXPANDPERCENT 40 +#define BUFSIZE 1024 +#define CUROFFSET 1 +#define MAXFOREIGN 250 +#define NOINDEX -1 + +/* The wrap line indicator */ +#define WRAPINDSIZE 7 +#define STEMOFFSET 5 +#define arrow_width 7 +#define arrow_height 5 +static char arrow_bits[] = { + 0x24, 0x26, 0x3f, 0x06, 0x04}; + +#define NEWLINE '\n' +#define BACKSPACE '\010' +#define NEWFONT '\006' +#define LOWCHAR '\040' +#define HIGHCHAR '\176' + +#define CHARMASK 0x00ff /* Character mask */ +#define FONTMASK 0x0700 /* Character font */ +#define FONTSHIFT 8 /* Shift amount */ + +#define WRAPFLAG 0x01 /* Line wrap flag */ + +/* + * Lines are represented by a pointer into the overall array of + * 16-bit characters. The lower eight bits is used to indicate the character + * (in ASCII), and the next two bits are used to indicate the font + * the character should be drawn in. + */ + +typedef struct txtLine { + int lineLength; /* Current line length */ + int lineHeight; /* Full height of line in pixels */ + int lineBaseLine; /* Current baseline of the line */ + int lineWidth; /* Drawing position at end of line */ + int lineText; /* Offset into master buffer */ + int lineFlags; /* Line wrap flag is here */ +}; + + +/* + * For ExposeCopy events, we queue up the redraw requests collapsing + * them into line redraw requests until the CopyExpose event arrives. + * The queue is represented as a dynamic array of the following + * structure: + */ + +typedef struct expEvent { + int lineIndex; /* Index of line to redraw */ + int ypos; /* Drawing position of line */ +}; + + +/* + * The text buffer is represented using a dynamic counted array + * of 16-bit quantities. This array expands as needed. + * For the screen representation, a dynamic counted array + * of line structures is used. This array points into the + * text buffer to denote the start of each line and its parameters. + * The windows are configured as one overall window which contains + * the scroll bar as a sub-window along its right edge. Thus, + * the text drawing space is actually w-BARSIZE. + */ + +#define NOTATBOTTOM 0x01 /* Need to scroll to bottom before appending */ +#define FONTNUMWAIT 0x02 /* Waiting for font number */ +#define COPYEXPOSE 0x04 /* Need to process a copy expose event */ +#define SCREENWRONG 0x08 /* TxtJamStr has invalidated screen contents */ + +typedef struct txtWin { + /* Basic text buffer */ + int bufAlloc; /* Allocated size of buffer */ + int bufSpot; /* Current writing position in buffer */ + short *mainBuffer; /* Main buffer of text */ + + /* Line information */ + int numLines; /* Number of display lines in buffer */ + int allocLines; /* Number of lines allocated */ + struct txtLine **txtBuffer; /* Dynamic array of lines */ + + /* Current Window display information */ + Window mainWindow; /* Text display window */ + Window scrollBar; /* Subwindow for scroll bar */ + Pixmap arrowMap; /* line wrap indicator */ + int bgPix, fgPix; /* Background and cursor */ + GC CursorGC; /* gc for the cursor */ + GC bgGC; /* gc for erasing things */ + GC fontGC[MAXFONTS]; /* gc for doing fonts */ + XFontStruct theFonts[MAXFONTS];/* Display fonts */ + int theColors[MAXFONTS]; /* foregrounds of the fonts */ + int curFont; /* current font for tracking */ + int w, h; /* Current size */ + int startLine; /* Top line in display */ + int endLine; /* Bottom line in display */ + int bottomSpace; /* Space at bottom of screen */ + int flagWord; /* If non-zero, not at end */ + + /* For handling ExposeCopy events */ + int exposeSize; /* Current size of array */ + int exposeAlloc; /* Allocated size */ + struct expEvent **exposeAry;/* Array of line indices */ + + /* Drawing position information */ + int curLine; /* Current line in buffer */ + int curX; /* Current horizontal positi */ + int curY; /* Current vertical drawing */ +}; + +/* Flags for the various basic character handling functions */ + +#define DODISP 0x01 /* Update the display */ +#define NONEWLINE 0x02 /* Dont append newline */ + + + +static int InitLine(newLine) +struct txtLine *newLine; /* Newly created line structure */ +/* + * This routine initializes a newly created line structure. + */ +{ + newLine->lineLength = 0; + newLine->lineHeight = 0; + newLine->lineBaseLine = 0; + newLine->lineWidth = XPADDING; + newLine->lineText = NOINDEX; + newLine->lineFlags = 0; + return 1; +} + + + + +int TxtGrab(display, txtWin, program, mainFont, bg, fg, cur) +Display *display; /* display window is on */ +Window txtWin; /* Window to take over as scrollable text */ +char *program; /* Program name for Xdefaults */ +XFontStruct *mainFont; /* Primary text font */ +int bg, fg, cur; /* Background, foreground, and cursor colors */ +/* + * This routine takes control of 'txtWin' and makes it into a scrollable + * text output window. It will create a sub-window for the scroll bar + * with a background of 'bg' and an bar with color 'fg'. Both fixed width + * and variable width fonts are supported. Additional fonts can be loaded + * using 'TxtAddFont'. Returns 0 if there were problems, non-zero if + * everything went ok. + */ +{ + struct txtWin *newWin; /* Text package specific information */ + XWindowAttributes winInfo; /* Window information */ + int index; + XGCValues gc_val; + + if (textWindows == (XAssocTable *) 0) { + textWindows = XCreateAssocTable(32); + if (textWindows == (XAssocTable *) 0) return(0); + } + if (XGetWindowAttributes(display, txtWin, &winInfo) == 0) return 0; + + if (ScrollOption == NOOPTION) { + /* Read to see if the user wants jump scrolling or not */ + if (XGetDefault(display, program, "JumpScroll")) { + ScrollOption = JUMPSCROLL; + } else { + ScrollOption = NORMSCROLL; + } + } + + /* Initialize local structure */ + newWin = alloc(struct txtWin); + + /* Initialize arrow pixmap */ + newWin->arrowMap = XCreatePixmapFromBitmapData(display, txtWin, + arrow_bits, + arrow_width, arrow_height, + cur, bg, + DisplayPlanes(display, 0)); + + newWin->bufAlloc = INITBUFSIZE; + newWin->bufSpot = 0; + newWin->mainBuffer = numalloc(short, INITBUFSIZE); + + newWin->numLines = 1; + newWin->allocLines = INITLINES; + newWin->txtBuffer = numalloc(struct txtLine *, INITLINES); + for (index = 0; index < INITLINES; index++) { + newWin->txtBuffer[index] = alloc(struct txtLine); + InitLine(newWin->txtBuffer[index]); + } + + /* Window display information */ + newWin->mainWindow = txtWin; + newWin->w = winInfo.width; + newWin->h = winInfo.height; + newWin->startLine = 0; + newWin->endLine = 0; + newWin->bottomSpace = winInfo.height + - YPADDING - mainFont->ascent - mainFont->descent - INTERLINE; + newWin->flagWord = 0; + newWin->bgPix = bg; + newWin->fgPix = fg; + + /* Scroll Bar Creation */ + newWin->scrollBar = XCreateSimpleWindow(display, txtWin, + winInfo.width - BARSIZE, + 0, BARSIZE - (2*BARBORDER), + winInfo.height - (2*BARBORDER), + BARBORDER, + fg, bg); + XSelectInput(display, newWin->scrollBar, ExposureMask|ButtonReleaseMask); + XMapRaised(display, newWin->scrollBar); + + /* Font and Color Initialization */ + newWin->theFonts[0] = *mainFont; + newWin->theColors[0] = fg; + gc_val.function = GXcopy; + gc_val.plane_mask = AllPlanes; + gc_val.foreground = fg; + gc_val.background = bg; + gc_val.graphics_exposures = 1; + gc_val.font = mainFont->fid; + gc_val.line_width = 1; + gc_val.line_style = LineSolid; + + newWin->fontGC[0] = XCreateGC(display, txtWin, + GCFunction | GCPlaneMask | + GCForeground | GCBackground | + GCGraphicsExposures | GCFont, + &gc_val); + + gc_val.foreground = cur; + newWin->CursorGC = XCreateGC(display, txtWin, + GCFunction | GCPlaneMask | + GCForeground | GCBackground | + GCLineStyle | GCLineWidth, + &gc_val); + + gc_val.foreground = bg; + newWin->bgGC = XCreateGC(display, txtWin, + GCFunction | GCPlaneMask | + GCForeground | GCBackground | + GCGraphicsExposures | GCFont, + &gc_val); + + + for (index = 1; index < MAXFONTS; index++) { + newWin->theFonts[index].fid = 0; + newWin->fontGC[index] = 0; + } + + + /* Initialize size of first line */ + newWin->txtBuffer[0]->lineHeight = newWin->theFonts[0].ascent + + newWin->theFonts[0].descent; + newWin->txtBuffer[0]->lineText = 0; + + /* ExposeCopy array initialization */ + newWin->exposeSize = 0; + newWin->exposeAlloc = INITEXPARY; + newWin->exposeAry = numalloc(struct expEvent *, INITEXPARY); + for (index = 0; index < newWin->exposeAlloc; index++) + newWin->exposeAry[index] = alloc(struct expEvent); + /* Put plus infinity in last slot for sorting purposes */ + newWin->exposeAry[0]->lineIndex = MAXINT; + + /* Drawing Position Information */ + newWin->curLine = 0; + newWin->curX = 0; + newWin->curY = YPADDING + mainFont->ascent + mainFont->descent; + + /* Attach it to both windows */ + XMakeAssoc(display, textWindows, (XID) txtWin, (caddr_t) newWin); + XMakeAssoc(display, textWindows, (XID) newWin->scrollBar, (caddr_t) newWin); + return 1; +} + + +int TxtRelease(display, w) +Display *display; +Window w; /* Window to release */ +/* + * This routine releases all resources associated with the + * specified window which are consumed by the text + * window package. This includes the entire text buffer, line start + * array, and the scroll bar window. However, the window + * itself is NOT destroyed. The routine will return zero if + * the window is not owned by the text window package. + */ +{ + struct txtWin *textInfo; + int index; + + if ((textInfo = (struct txtWin *) XLookUpAssoc(display, + textWindows, (XID) w)) == 0) + return 0; + + for (index = 0; index < MAXFONTS; index++) + if (textInfo->fontGC[index] != 0) + XFreeGC(display, textInfo->fontGC[index]); + + free((Generic) textInfo->mainBuffer); + for (index = 0; index < textInfo->numLines; index++) { + free((Generic) textInfo->txtBuffer[index]); + } + free((Generic) textInfo->txtBuffer); + XDestroyWindow(display, textInfo->scrollBar); + for (index = 0; index < textInfo->exposeSize; index++) { + free((Generic) textInfo->exposeAry[index]); + } + free((Generic) textInfo->exposeAry); + XDeleteAssoc(display, textWindows, (XID) w); + free((Generic) textInfo); + return 1; +} + + + +static int RecompBuffer(textInfo) +struct txtWin *textInfo; /* Text window information */ +/* + * This routine recomputes all line breaks in a buffer after + * a change in window size or font. This is done by throwing + * away the old line start array and recomputing it. Although + * a lot of this work is also done elsewhere, it has been included + * inline here for efficiency. + */ +{ + int startPos, endSize, linenum; + register int index, chsize, curfont; + register short *bufptr; + register XFontStruct *fontptr; + register struct txtLine *lineptr; + char theChar; + + /* Record the old position so we can come back to it */ + for (startPos = textInfo->txtBuffer[textInfo->startLine]->lineText; + (startPos > 0) && (textInfo->mainBuffer[startPos] != '\n'); + startPos--) + /* null loop body */; + + /* Clear out the old line start array */ + for (index = 0; index < textInfo->numLines; index++) { + InitLine(textInfo->txtBuffer[index]); + } + + /* Initialize first line */ + textInfo->txtBuffer[0]->lineHeight = + textInfo->theFonts[0].ascent + textInfo->theFonts[0].descent; + textInfo->txtBuffer[0]->lineText = 0; + + /* Process the text back into lines */ + endSize = textInfo->w - BARSIZE - WRAPINDSIZE; + bufptr = textInfo->mainBuffer; + lineptr = textInfo->txtBuffer[0]; + linenum = 0; + fontptr = &(textInfo->theFonts[0]); + curfont = 0; + for (index = 0; index < textInfo->bufSpot; index++) { + theChar = bufptr[index] & CHARMASK; + + if ((bufptr[index] & FONTMASK) != curfont) { + int newFontNum, heightDiff; + + /* Switch fonts */ + newFontNum = (bufptr[index] & FONTMASK) >> FONTSHIFT; + if (textInfo->theFonts[newFontNum].fid != 0) { + /* Valid font */ + curfont = bufptr[index] & FONTMASK; + fontptr = &(textInfo->theFonts[newFontNum]); + heightDiff = (fontptr->ascent + fontptr->descent) - + lineptr->lineHeight; + if (heightDiff < 0) heightDiff = 0; + lineptr->lineHeight += heightDiff; + } + } + if (theChar == '\n') { + /* Handle new line */ + if (linenum >= textInfo->allocLines-1) + /* Expand number of lines */ + ExpandLines(textInfo); + linenum++; + lineptr = textInfo->txtBuffer[linenum]; + /* Initialize next line */ + lineptr->lineHeight = fontptr->ascent + fontptr->descent; + lineptr->lineText = index+1; + /* Check to see if its the starting line */ + if (index == startPos) textInfo->startLine = linenum; + } else { + /* Handle normal character */ + chsize = CharSize(textInfo, linenum, index); + if (lineptr->lineWidth + chsize > endSize) { + /* Handle line wrap */ + lineptr->lineFlags |= WRAPFLAG; + if (linenum >= textInfo->allocLines-1) + /* Expand number of lines */ + ExpandLines(textInfo); + linenum++; + lineptr = textInfo->txtBuffer[linenum]; + /* Initialize next line */ + lineptr->lineHeight = fontptr->ascent + fontptr->descent; + lineptr->lineText = index; + lineptr->lineLength = 1; + lineptr->lineWidth += chsize; + } else { + /* Handle normal addition of character */ + lineptr->lineLength += 1; + lineptr->lineWidth += chsize; + } + } + } + /* We now have a valid line array. Let's clean up some other fields. */ + textInfo->numLines = linenum+1; + if (startPos == 0) { + textInfo->startLine = 0; + } + textInfo->endLine = FindEndLine(textInfo, &(textInfo->bottomSpace)); + textInfo->curLine = linenum; + /* Check to see if we are at the bottom */ + if (textInfo->endLine >= textInfo->numLines-1) { + textInfo->curY = textInfo->h - textInfo->bottomSpace - + lineptr->lineHeight; + textInfo->flagWord &= (~NOTATBOTTOM); + } else { + textInfo->flagWord |= NOTATBOTTOM; + } + return 1; +} + + + + +int TxtAddFont(display, textWin, fontNumber, newFont, newColor) +Display *display; +Window textWin; /* Scrollable text window */ +int fontNumber; /* Place to add font (0-7) */ +XFontStruct *newFont; /* Font to add */ +int newColor; /* Color of font */ +/* + * This routine loads a new font so that it can be used in a previously + * created text window. There are eight font slots numbered 0 through 7. + * If there is already a font in the specified slot, it will be replaced + * and an automatic redraw of the window will take place. See TxtWriteStr + * for details on using alternate fonts. The color specifies the foreground + * color of the text. The default foreground color is used if this + * parameter is TXT_NO_COLOR. Returns a non-zero value if + * everything went well. + */ +{ + struct txtWin *textInfo; + int redrawFlag; + XGCValues gc_val; + + if ((fontNumber < 0) || (fontNumber >= MAXFONTS)) return 0; + if ((textInfo = (struct txtWin *) + XLookUpAssoc(display, textWindows, (XID) textWin)) == 0) + return 0; + if (newColor == TXT_NO_COLOR) { + newColor = textInfo->fgPix; + } + + gc_val.font = newFont->fid; + gc_val.foreground = newColor; + gc_val.background = textInfo->bgPix; + gc_val.plane_mask = AllPlanes; + gc_val.graphics_exposures = 1; + gc_val.function = GXcopy; + + if (textInfo->fontGC[fontNumber] != 0) + { + XChangeGC(display, textInfo->fontGC[fontNumber], + GCFont | GCForeground, &gc_val); + } + else + textInfo->fontGC[fontNumber] = XCreateGC(display, textWin, + GCFont | + GCForeground | + GCBackground | + GCFunction | + GCPlaneMask | + GCGraphicsExposures, + &gc_val); + + + redrawFlag = (textInfo->theFonts[fontNumber].fid != 0) && + (((newFont) && (newFont->fid != textInfo->theFonts[fontNumber].fid)) || + (newColor != textInfo->theColors[fontNumber])); + if (newFont) { + textInfo->theFonts[fontNumber] = *newFont; + } + textInfo->theColors[fontNumber] = newColor; + + if (redrawFlag) { + RecompBuffer(textInfo); + XClearWindow(display, textWin); + TxtRepaint(display, textWin); + } + return 1; +} + + + +int TxtWinP(display, w) +Display *display; +Window w; +/* + * Returns a non-zero value if the window has been previously grabbed + * using TxtGrab and 0 if it has not. + */ +{ + if (XLookUpAssoc(display, textWindows, (XID) w)) + return(1); + else return(0); +} + + + +static int FindEndLine(textInfo, botSpace) +struct txtWin *textInfo; +int *botSpace; +/* + * Given the starting line in 'textInfo->startLine', this routine + * determines the index of the last line that can be drawn given the + * current size of the screen. If there are not enough lines to + * fill the screen, the index of the last line will be returned. + * The amount of empty bottom space is returned in 'botSpace'. + */ +{ + int index, height, lineHeight; + + height = YPADDING; + index = textInfo->startLine; + while (index < textInfo->numLines) { + lineHeight = textInfo->txtBuffer[index]->lineHeight + INTERLINE; + if (height + lineHeight > textInfo->h) break; + height += lineHeight; + index++; + } + if (botSpace) { + *botSpace = textInfo->h - height; + } + return index - 1; +} + + + +static int UpdateScroll(display, textInfo) +Display *display; +struct txtWin *textInfo; /* Text window information */ +/* + * This routine computes the current extent of the scroll bar + * indicator and repaints the bar with the correct information. + */ +{ + int top, bottom; + + if (textInfo->numLines > 1) { + top = textInfo->startLine * (textInfo->h - 2*BARBORDER) / + (textInfo->numLines - 1); + bottom = textInfo->endLine * (textInfo->h - 2*BARBORDER) / + (textInfo->numLines - 1); + } else { + top = 0; + bottom = textInfo->h - (2*BARBORDER); + } + + /* Draw it - make sure there is a little padding */ + if (top == 0) top++; + if (bottom == textInfo->h-(2*BARBORDER)) bottom--; + + XFillRectangle(display, textInfo->scrollBar, + textInfo->bgGC, + 0, 0, BARSIZE, top-1); + XFillRectangle(display, textInfo->scrollBar, + DEFAULT_GC, top, BARSIZE - (2*BARBORDER) - 2, + bottom - top); + XFillRectangle(display, textInfo->scrollBar, DEFAULT_GC, + 0, bottom+1, BARSIZE, + textInfo->h - (2 * BARBORDER) - bottom); + + return 1; +} + + + + +int TxtClear(display, w) +Display *display; +Window w; +/* + * This routine clears a scrollable text window. It resets the current + * writing position to the upper left hand corner of the screen. + * NOTE: THIS ALSO CLEARS THE CONTENTS OF THE TEXT WINDOW BUFFER AND + * RESETS THE SCROLL BAR. Returns 0 if the window is not a text window. + * This should be used *instead* of XClear. + */ +{ + struct txtWin *textInfo; + int index; + + if ((textInfo = (struct txtWin *) XLookUpAssoc(display, textWindows, (XID) w)) == 0) + return 0; + + /* Zero out the arrays */ + textInfo->bufSpot = 0; + for (index = 0; index < textInfo->numLines; index++) { + InitLine(textInfo->txtBuffer[index]); + } + textInfo->txtBuffer[0]->lineHeight = + textInfo->theFonts[textInfo->curFont].ascent + + textInfo->theFonts[textInfo->curFont].descent; + + textInfo->numLines = 1; + textInfo->startLine = 0; + textInfo->endLine = 0; + textInfo->curLine = 0; + textInfo->curX = 0; + textInfo->curY = YPADDING + textInfo->theFonts[textInfo->curFont].ascent + + textInfo->theFonts[textInfo->curFont].descent; + + textInfo->bottomSpace = textInfo->h - YPADDING - + textInfo->theFonts[textInfo->curFont].ascent - INTERLINE - + textInfo->theFonts[textInfo->curFont].descent; + /* Actually clear the window */ + XClearWindow(display, w); + + /* Draw the current cursor */ + XFillRectangle(display, w, textInfo->CursorGC, + XPADDING + CUROFFSET, textInfo->curY, + CURSORWIDTH, + textInfo->theFonts[textInfo->curFont].ascent + + textInfo->theFonts[textInfo->curFont].descent); + + /* Update the scroll bar */ + UpdateScroll(display, textInfo); + return 1; +} + + +static int WarpToBottom(display, textInfo) +Display *display; +struct txtWin *textInfo; /* Text Information */ +/* + * This routine causes the specified text window to display its + * last screen of information. It updates the scroll bar + * to the appropriate spot. The implementation scans backward + * through the buffer to find an appropriate starting spot for + * the window. + */ +{ + int index, height, lineHeight; + + index = textInfo->numLines-1; + height = 0; + while (index >= 0) { + lineHeight = textInfo->txtBuffer[index]->lineHeight + INTERLINE; + if (height + lineHeight > textInfo->h) break; + height += lineHeight; + index--; + } + textInfo->startLine = index + 1; + textInfo->endLine = FindEndLine(textInfo, &(textInfo->bottomSpace)); + textInfo->curY = textInfo->h - textInfo->bottomSpace - + textInfo->txtBuffer[textInfo->endLine]->lineHeight; + XClearWindow(display, textInfo->mainWindow); + TxtRepaint(display, textInfo->mainWindow); + return 1; +} + + + +static int UpdateExposures(display, textInfo) +Display *display; +struct txtWin *textInfo; /* Text window information */ +/* + * Before a new scrolling action occurs, the text window package + * must handle all COPYEXPOSE events generated by the last scrolling + * action. This routine is called to do this. Foreign events (those + * not handled by TxtFilter) are queued up and replaced on the queue + * after the processing of the exposure events is complete. + */ +{ +#if 0 + XEvent foreignQueue[MAXFOREIGN]; + int index, lastItem = 0; + + while (textInfo->flagWord & COPYEXPOSE) { + XNextEvent(display, &(foreignQueue[lastItem])); + if (!TxtFilter(display, &(foreignQueue[lastItem]))) + lastItem++; + if (lastItem >= MAXFOREIGN) { + printf("Too many foreign events to queue!\n"); + textInfo->flagWord &= (~COPYEXPOSE); + } + } + for (index = 0; index < lastItem; index++) { + XPutBackEvent(display, &(foreignQueue[index])); + } +#endif + return 1; +} + + +static int ScrollDown(display,textInfo) +Display *display; +struct txtWin *textInfo; /* Text window information */ +/* + * This routine scrolls the indicated text window down by one + * line. The line below the current line must exist. The window + * is scrolled so that the line below the last line is fully + * displayed. This may cause many lines to scroll off the top. + * Scrolling is done using XCopyArea. The exposure events should + * be caught using ExposeCopy. + */ +{ + int lineSum, index, targetSpace, freeSpace, updateFlag; + + lineSum = 0; + if (textInfo->endLine + 1 >= textInfo->numLines) return 0; + targetSpace = textInfo->txtBuffer[textInfo->endLine+1]->lineHeight + + INTERLINE; + if (textInfo->bottomSpace < targetSpace) { + index = textInfo->startLine; + while (index < textInfo->endLine) { + lineSum += (textInfo->txtBuffer[index]->lineHeight + INTERLINE); + if (textInfo->bottomSpace + lineSum >= targetSpace) break; + index++; + } + + /* Must move upward by 'lineSum' pixels */ + XCopyArea(display, textInfo->mainWindow, textInfo->mainWindow, + DEFAULT_GC, 0, lineSum, + textInfo->w - BARSIZE, textInfo->h, + 0, 0); + + textInfo->flagWord |= COPYEXPOSE; + /* Repair the damage to the structures */ + textInfo->startLine = index + 1; + updateFlag = 1; + } else { + updateFlag = 0; + } + /* More lines might be able to fit. Let's check. */ + freeSpace = textInfo->bottomSpace + lineSum - targetSpace; + index = textInfo->endLine + 1; + while (index < textInfo->numLines-1) { + if (freeSpace - textInfo->txtBuffer[index+1]->lineHeight - INTERLINE < 0) + break; + freeSpace -= (textInfo->txtBuffer[index+1]->lineHeight + INTERLINE); + index++; + } + textInfo->endLine = index; + textInfo->bottomSpace = freeSpace; + if (updateFlag) { + UpdateExposures(display, textInfo); + } + UpdateScroll(display, textInfo); + return 1; +} + + + + +static int ExpandLines(textInfo) +struct txtWin *textInfo; /* Text Information */ +/* + * This routine allocates and initializes additional space in + * the line start array (txtBuffer). The new space + * is allocated using realloc. The expansion factor is a percentage + * given by EXPANDPERCENT. + */ +{ + int newSize, index; + + newSize = textInfo->allocLines; + newSize += (newSize * EXPANDPERCENT) / 100; + + textInfo->txtBuffer = (struct txtLine **) + realloc((char *) textInfo->txtBuffer, + (unsigned) (newSize * sizeof(struct txtLine *))); + for (index = textInfo->allocLines; index < newSize; index++) { + textInfo->txtBuffer[index] = alloc(struct txtLine); + InitLine(textInfo->txtBuffer[index]); + } + textInfo->allocLines = newSize; + return 1; +} + +static int ExpandBuffer(textInfo) +struct txtWin *textInfo; /* Text information */ +/* + * Expands the basic character buffer using realloc. The expansion + * factor is a percentage given by EXPANDPERCENT. + */ +{ + int newSize; + + newSize = textInfo->bufAlloc + (textInfo->bufAlloc * EXPANDPERCENT) / 100; + textInfo->mainBuffer = (short *) + realloc((char *) textInfo->mainBuffer, (unsigned) newSize * sizeof(short)); + textInfo->bufAlloc = newSize; + return 1; +} + + + +static int HandleNewLine(display, textInfo, flagWord) +Display *display; +struct txtWin *textInfo; /* Text Information */ +int flagWord; /* DODISP or NONEWLINE or both */ +/* + * This routine initializes the next line for drawing by setting + * its height to the current font height, scrolls the screen down + * one line, and updates the current drawing position to the + * left edge of the newly cleared line. If DODISP is specified, + * the screen will be updated (otherwise not). If NONEWLINE is + * specified, no newline character will be added to the text buffer + * (this is for line wrap). + */ +{ + struct txtLine *curLine, *nextLine; + + /* Check to see if a new line must be allocated */ + if (textInfo->curLine >= textInfo->allocLines-1) + /* Expand the number of lines */ + ExpandLines(textInfo); + textInfo->numLines += 1; + + /* Then we initialize the next line */ + nextLine = textInfo->txtBuffer[textInfo->numLines-1]; + nextLine->lineHeight = + textInfo->theFonts[textInfo->curFont].ascent + + textInfo->theFonts[textInfo->curFont].descent; + + curLine = textInfo->txtBuffer[textInfo->curLine]; + if (flagWord & DODISP) { + /* Scroll down a line if required */ + if ((textInfo->curY + curLine->lineHeight + + nextLine->lineHeight + (INTERLINE * 2)) > textInfo->h) + { + ScrollDown(display, textInfo); + } + else + { + /* Update the bottom space appropriately */ + textInfo->bottomSpace -= (nextLine->lineHeight + INTERLINE); + textInfo->endLine += 1; + } + /* Update drawing position */ + textInfo->curY = textInfo->h - + (textInfo->bottomSpace + nextLine->lineHeight); + } + + /* Move down a line */ + textInfo->curLine += 1; + if (!(flagWord & NONEWLINE)) { + /* Append end-of-line to text buffer */ + if (textInfo->bufSpot >= textInfo->bufAlloc) { + /* Allocate more space in main text buffer */ + ExpandBuffer(textInfo); + } + textInfo->mainBuffer[(textInfo->bufSpot)++] = + (textInfo->curFont << FONTSHIFT) | '\n'; + } + nextLine->lineText = textInfo->bufSpot; + textInfo->curX = 0; + return 1; +} + + + +static int CharSize(textInfo, lineNum, charNum) +struct txtWin *textInfo; /* Current Text Information */ +int lineNum; /* Line in buffer */ +int charNum; /* Character in line */ +/* + * This routine determines the size of the specified character. + * It takes in account the font of the character and whether its + * fixed or variable. The size includes INTERSPACE spacing between + * the characters. + */ +{ + register XFontStruct *charFont; + register short *theLine; + register short theChar; + + theLine = &(textInfo->mainBuffer[textInfo->txtBuffer[lineNum]->lineText]); + theChar = theLine[charNum] & CHARMASK; + charFont = &(textInfo->theFonts[(theChar & FONTMASK) >> FONTSHIFT]); + if (theChar <= charFont->min_char_or_byte2 || + theChar >= charFont->max_char_or_byte2 || + charFont->per_char == 0) + return charFont->max_bounds.width + 1; + else + return charFont->per_char[theChar].width + 1; +} + + + + + +static int HandleBackspace(display, textInfo, flagWord) +Display *display; +struct txtWin *textInfo; /* Text Information */ +int flagWord; /* DODISP or nothing */ +/* + * This routine handles a backspace found in the input stream. The + * character before the current writing position will be erased and + * the drawing position will move back one character. If the writing + * position is at the left margin, the drawing position will move + * up to the previous line. If it is a line that has been wrapped, + * the character at the end of the previous line will be erased. + */ +{ + struct txtLine *thisLine, *prevLine; + int chSize; + + thisLine = textInfo->txtBuffer[textInfo->curLine]; + /* First, determine whether we need to go back a line */ + if (thisLine->lineLength == 0) { + /* Bleep if at top of buffer */ + if (textInfo->curLine == 0) { + XBell(display, 50); + return 0; + } + + /* See if we have to scroll in the other direction */ + if ((flagWord & DODISP) && (textInfo->curY <= YPADDING)) { + /* This will display the last lines of the buffer */ + WarpToBottom(display, textInfo); + } + + /* Set drawing position at end of previous line */ + textInfo->curLine -= 1; + prevLine = textInfo->txtBuffer[textInfo->curLine]; + textInfo->numLines -= 1; + if (flagWord & DODISP) { + textInfo->curY -= (prevLine->lineHeight + INTERLINE); + textInfo->bottomSpace += (thisLine->lineHeight + INTERLINE); + textInfo->endLine -= 1; + } + + /* We are unlinewrapping if the previous line has flag set */ + if (prevLine->lineFlags & WRAPFLAG) { + /* Get rid of line wrap indicator */ + if (flagWord & DODISP) { + XFillRectangle(display, textInfo->mainWindow, + textInfo->bgGC, + textInfo->w - BARSIZE - WRAPINDSIZE, + textInfo->curY, WRAPINDSIZE, + prevLine->lineHeight); + } + prevLine->lineFlags &= (~WRAPFLAG); + /* Call recursively to wipe out the ending character */ + HandleBackspace(display, textInfo, flagWord); + } else { + /* Delete the end-of-line in the primary buffer */ + textInfo->bufSpot -= 1; + } + } else { + /* Normal deletion of character */ + chSize = + CharSize(textInfo, textInfo->curLine, + textInfo->txtBuffer[textInfo->curLine]->lineLength - 1); + /* Move back appropriate amount and wipe it out */ + thisLine->lineWidth -= chSize; + if (flagWord & DODISP) { + XFillRectangle(display, textInfo->mainWindow, + textInfo->bgGC, + thisLine->lineWidth, textInfo->curY, + chSize, thisLine->lineHeight); + } + /* Delete from buffer */ + textInfo->txtBuffer[textInfo->curLine]->lineLength -= 1; + textInfo->bufSpot -= 1; + } + return 1; +} + + + +static int DrawLineWrap(display, win, x, y, h, col) +Display *display; +Window win; /* What window to draw it in */ +int x, y; /* Position of upper left corner */ +int h; /* Height of indicator */ +int col; /* Color of indicator */ +/* + * This routine draws a line wrap indicator at the end of a line. + * Visually, it is an arrow of the specified height directly against + * the scroll bar border. The bitmap used for the arrow is stored + * in 'arrowMap' with size 'arrow_width' and 'arrow_height'. + */ +{ + struct txtWin *textInfo; + + textInfo = (struct txtWin *)XLookUpAssoc(display, textWindows, + (XID) win); + + /* First, draw the arrow */ + XCopyArea(display, textInfo->arrowMap, textInfo->mainWindow, + textInfo->CursorGC, + 0, 0, arrow_width, arrow_height, + x, y + h - arrow_height, 1); + + /* Then draw the stem */ + XDrawLine(display, textInfo->mainWindow, textInfo->CursorGC, + x + STEMOFFSET, y, + x + STEMOFFSET, y + h - arrow_height); + return 1; +} + + + + +static int DrawLine(display, textInfo, lineIndex, ypos) +Display *display; +struct txtWin *textInfo; /* Text window information */ +int lineIndex; /* Index of line to draw */ +int ypos; /* Y position for line */ +/* + * This routine destructively draws the indicated line in the + * indicated window at the indicated position. It does not + * clear to end of line however. It draws a line wrap indicator + * if needed but does not draw a cursor. + */ +{ + int index, startPos, curFont, theColor, curX, saveX, fontIndex; + struct txtLine *someLine; + char lineBuffer[BUFSIZE], *glyph; + short *linePointer; + XFontStruct *theFont; + XGCValues gc; + + /* First, we draw the text */ + index = 0; + curX = XPADDING; + someLine = textInfo->txtBuffer[lineIndex]; + linePointer = &(textInfo->mainBuffer[someLine->lineText]); + while (index < someLine->lineLength) { + startPos = index; + saveX = curX; + curFont = linePointer[index] & FONTMASK; + fontIndex = curFont >> FONTSHIFT; + theFont = &(textInfo->theFonts[fontIndex]); + theColor = textInfo->theColors[fontIndex]; + glyph = &(lineBuffer[0]); + while ((index < someLine->lineLength) && + ((linePointer[index] & FONTMASK) == curFont)) + { + *glyph = linePointer[index] & CHARMASK; + index++; + curX += CharSize(textInfo, lineIndex, index); + glyph++; + } + + /* Flush out the glyphs */ + XFillRectangle(display, textInfo->mainWindow, + textInfo->bgGC, + saveX, ypos, + textInfo->w - BARSIZE, + someLine->lineHeight + YPADDING + INTERLINE); + + XDrawString(display, textInfo->mainWindow, + textInfo->fontGC[fontIndex], + saveX, ypos, + lineBuffer, someLine->lineLength); + } + /* Then the line wrap indicator (if needed) */ + if (someLine->lineFlags & WRAPFLAG) { + DrawLineWrap(display, textInfo->mainWindow, + textInfo->w - BARSIZE - WRAPINDSIZE, + ypos, someLine->lineHeight, + textInfo->fgPix); + } + return 1; +} + + + + +static int HandleNewFont(display, fontNum, textInfo, flagWord) +Display *display; +int fontNum; /* Font number */ +struct txtWin *textInfo; /* Text information */ +int flagWord; /* DODISP or nothing */ +/* + * This routine handles a new font request. These requests take + * the form "^F<digit>". The parsing is done in TxtWriteStr. + * This routine is called only if the form is valid. It may return + * a failure (0 status) if the requested font is not loaded. + * If the new font is larger than any of the current + * fonts on the line, it will change the line height and redisplay + * the line. + */ +{ + struct txtLine *thisLine; + int heightDiff, baseDiff, redrawFlag; + + if (textInfo->theFonts[fontNum].fid == 0) { + return 0; + } else { + thisLine = textInfo->txtBuffer[textInfo->curLine]; + textInfo->curFont = fontNum; + redrawFlag = 0; + heightDiff = textInfo->theFonts[fontNum].ascent + + textInfo->theFonts[fontNum].descent - + thisLine->lineHeight; + + if (heightDiff > 0) { + redrawFlag = 1; + } else { + heightDiff = 0; + } + + if (redrawFlag) { + if (flagWord & DODISP) { + /* Clear current line */ + XFillRectangle(display, textInfo->mainWindow, + textInfo->bgGC, + 0, textInfo->curY, textInfo->w, + thisLine->lineHeight); + + /* Check to see if it requires scrolling */ + if ((textInfo->curY + thisLine->lineHeight + heightDiff + + INTERLINE) > textInfo->h) + { + /* + * General approach: "unscroll" the last line up + * and then call ScrollDown to do the right thing. + */ + textInfo->endLine -= 1; + textInfo->bottomSpace += thisLine->lineHeight + + INTERLINE; + + XFillRectangle(display, textInfo->mainWindow, + textInfo->bgGC, + 0, textInfo->h - textInfo->bottomSpace, + textInfo->w, textInfo->bottomSpace); + + thisLine->lineHeight += heightDiff; + ScrollDown(display, textInfo); + textInfo->curY = textInfo->h - + (textInfo->bottomSpace + INTERLINE + + thisLine->lineHeight); + } + else + { + /* Just update bottom space */ + textInfo->bottomSpace -= heightDiff; + thisLine->lineHeight += heightDiff; + } + /* Redraw the current line */ + DrawLine(display, textInfo, textInfo->curLine, textInfo->curY); + } else { + /* Just update line height */ + thisLine->lineHeight += heightDiff; + } + } + return 1; + } +} + + + +int TxtWriteStr(display, w, str) +Display *display; +Window w; /* Text window */ +register char *str; /* 0 terminated string */ +/* + * This routine writes a string to the specified text window. + * The following notes apply: + * - Text is always appended to the end of the text buffer. + * - If the scroll bar is positioned such that the end of the + * text is not visible, an automatic scroll to the bottom + * will be done before the appending of text. + * - Non-printable ASCII characters are not displayed. + * - The '\n' character causes the current text position to + * advance one line and start at the left. + * - Tabs are not supported. + * - Lines too long for the screen will be wrapped and a line wrap + * indication will be drawn. + * - Backspace clears the previous character. It will do the right + * thing if asked to backspace past a wrapped line. + * - A new font can be chosen using the sequence '^F<digit>' where + * <digit> is 0-7. The directive will be ignored if + * there is no font in the specified slot. + * Returns 0 if something went wrong. + */ +{ + register int fontIndex; + register struct txtWin *textInfo; + register struct txtLine *thisLine; + + if ((textInfo = (struct txtWin *) XLookUpAssoc(display, textWindows, (XID) w)) == 0) + return 0; + + /* See if screen needs to be updated */ + if (textInfo->flagWord & SCREENWRONG) { + TxtRepaint(display, textInfo->mainWindow); + } + + /* See if we have to scroll down to the bottom */ + if (textInfo->flagWord & NOTATBOTTOM) { + WarpToBottom(display, textInfo); + textInfo->flagWord &= (~NOTATBOTTOM); + } + + /* Undraw the current cursor */ + thisLine = textInfo->txtBuffer[textInfo->curLine]; + + XFillRectangle(display, w, textInfo->bgGC, + thisLine->lineWidth + CUROFFSET, + textInfo->curY, + CURSORWIDTH, + thisLine->lineHeight); + + for ( /* str is ok */ ; (*str != 0) ; str++) { + /* Check to see if we are waiting on a font */ + if (textInfo->flagWord & FONTNUMWAIT) { + textInfo->flagWord &= (~FONTNUMWAIT); + fontIndex = *str - '0'; + if ((fontIndex >= 0) && (fontIndex < MAXFONTS)) { + /* Handle font -- go get next character */ + if (HandleNewFont(display, fontIndex, textInfo, DODISP)) + continue; + } + } + + /* Inline code for handling normal character case */ + if ((*str >= LOWCHAR) && (*str <= HIGHCHAR)) { + register XFontStruct *thisFont; + register struct txtLine *thisLine; + register int charWidth; + int thisColor; + + /* Determine size of character */ + thisFont = &(textInfo->theFonts[textInfo->curFont]); + thisColor = textInfo->theColors[textInfo->curFont]; + if (*str <= thisFont->min_char_or_byte2 || + *str >= thisFont->max_char_or_byte2 || + thisFont->per_char == 0) + charWidth = thisFont->max_bounds.width + 1; + else + charWidth = thisFont->per_char[*str].width + 1; + + /* Check to see if line wrap is required */ + thisLine = textInfo->txtBuffer[textInfo->curLine]; + if (thisLine->lineWidth + charWidth > + (textInfo->w-BARSIZE-WRAPINDSIZE)) + { + DrawLineWrap(display, textInfo->mainWindow, + textInfo->w-BARSIZE-WRAPINDSIZE, + textInfo->curY, thisLine->lineHeight, + textInfo->fgPix); + thisLine->lineFlags |= WRAPFLAG; + /* Handle the spacing problem the same way as a newline */ + HandleNewLine(display, textInfo, DODISP | NONEWLINE); + thisLine = textInfo->txtBuffer[textInfo->curLine]; + } + + /* Ready to draw character */ + XDrawString(display, textInfo->mainWindow, + DEFAULT_GC, + textInfo->curX += charWidth, + textInfo->curY + thisLine->lineHeight, + str, 1); + + /* Append character onto main buffer */ + if (textInfo->bufSpot >= textInfo->bufAlloc) + /* Make room for more characters */ + ExpandBuffer(textInfo); + textInfo->mainBuffer[(textInfo->bufSpot)++] = + (textInfo->curFont << FONTSHIFT) | (*str); + + /* Update the line start array */ + thisLine->lineLength += 1; + thisLine->lineWidth += charWidth; + } else if (*str == NEWLINE) { + HandleNewLine(display, textInfo, DODISP); + } else if (*str == NEWFONT) { + /* Go into waiting for font number mode */ + textInfo->flagWord |= FONTNUMWAIT; + } else if (*str == BACKSPACE) { + HandleBackspace(display, textInfo, DODISP); + } else { + /* Ignore all others */ + } + } + /* Draw the cursor in its new position */ + thisLine = textInfo->txtBuffer[textInfo->curLine]; + + XFillRectangle(display, w, textInfo->CursorGC, + thisLine->lineWidth + CUROFFSET, + textInfo->curY /* + thisLine->lineHeight */, + CURSORWIDTH, thisLine->lineHeight); + + return 1; +} + + + +int TxtJamStr(display, w, str) +Display *display; +Window w; /* Text window */ +register char *str; /* NULL terminated string */ +/* + * This is the same as TxtWriteStr except the screen is NOT updated. + * After a call to this routine, TxtRepaint should be called to + * update the screen. This routine is meant to be used to load + * a text buffer with information and then allow the user to + * scroll through it at will. + */ +{ + register int fontIndex; + register struct txtWin *textInfo; + + if ((textInfo = (struct txtWin *) XLookUpAssoc(display, textWindows, (XID) w) + ) == 0) + return 0; + + for ( /* str is ok */ ; (*str != 0) ; str++) { + /* Check to see if we are waiting on a font */ + if (textInfo->flagWord & FONTNUMWAIT) { + textInfo->flagWord &= (~FONTNUMWAIT); + fontIndex = *str - '0'; + if ((fontIndex >= 0) && (fontIndex < MAXFONTS)) { + if (HandleNewFont(display, fontIndex, textInfo, 0)) { + /* Handled font -- go get next character */ + continue; + } + } + } + /* Inline code for handling normal character case */ + if ((*str >= LOWCHAR) && (*str <= HIGHCHAR)) { + register XFontStruct *thisFont; + register struct txtLine *thisLine; + register int charWidth; + + /* Determine size of character */ + thisFont = &(textInfo->theFonts[textInfo->curFont]); + + if (*str <= thisFont->min_char_or_byte2 || + *str >= thisFont->max_char_or_byte2 || + thisFont->per_char == 0) + charWidth = thisFont->max_bounds.width + 1; + else + charWidth = thisFont->per_char[*str].width + 1; + + /* Check to see if line wrap is required */ + thisLine = textInfo->txtBuffer[textInfo->curLine]; + if (thisLine->lineWidth + charWidth > + (textInfo->w-BARSIZE-WRAPINDSIZE)) + { + thisLine->lineFlags |= WRAPFLAG; + /* Handle the spacing problem the same way as a newline */ + HandleNewLine(display, textInfo, NONEWLINE); + thisLine = textInfo->txtBuffer[textInfo->curLine]; + } + /* Append character onto main buffer */ + if (textInfo->bufSpot >= textInfo->bufAlloc) + /* Make room for more characters */ + ExpandBuffer(textInfo); + textInfo->mainBuffer[(textInfo->bufSpot)++] = + (textInfo->curFont << FONTSHIFT) | (*str); + + /* Update the line start array */ + thisLine->lineLength += 1; + thisLine->lineWidth += charWidth; + } else if (*str == NEWLINE) { + HandleNewLine(display, textInfo, 0); + } else if (*str == NEWFONT) { + /* Go into waiting for font number mode */ + textInfo->flagWord |= FONTNUMWAIT; + } else if (*str == BACKSPACE) { + HandleBackspace(display, textInfo, 0); + } else { + /* Ignore all others */ + } + } + textInfo->flagWord |= SCREENWRONG; + return 1; +} + + + +int TxtRepaint(display,w) +Display *display; +Window w; +/* + * Repaints the given scrollable text window. The routine repaints + * the entire window. For handling exposure events, the TxtFilter + * routine should be used. + */ +{ + struct txtWin *textInfo; + int index, ypos; + + if ((textInfo = (struct txtWin *) XLookUpAssoc(display, textWindows, (XID) w) + ) == 0) + return 0; + + /* Check to see if the screen is up to date */ + if (textInfo->flagWord & SCREENWRONG) { + textInfo->endLine = FindEndLine(textInfo, &(textInfo->bottomSpace)); + textInfo->flagWord &= (~SCREENWRONG); + } + + ypos = YPADDING; + index = textInfo->startLine; + for (;;) { + DrawLine(display, textInfo, index, ypos); + if (index >= textInfo->endLine) break; + ypos += (textInfo->txtBuffer[index]->lineHeight + INTERLINE); + index++; + } + /* Draw the cursor (if on screen) */ + if (textInfo->endLine == textInfo->curLine) { + XFillRectangle(display, w, textInfo->CursorGC, + textInfo->txtBuffer[index]->lineWidth + CUROFFSET, + ypos /* + textInfo->txtBuffer[index]->lineHeight */, + CURSORWIDTH, textInfo->txtBuffer[index]->lineHeight); + + } + /* Update the scroll bar */ + UpdateScroll(display, textInfo); + return 1; +} + + + +static int InsertIndex(textInfo, thisIndex, ypos) +struct txtWin *textInfo; /* Text Window Information */ +int thisIndex; /* Line index of exposed line */ +int ypos; /* Drawing position of line */ +/* + * This routine inserts the supplied line index into the copy + * exposure array for 'textInfo'. The array is kept sorted + * from lowest to highest using insertion sort. The array + * is dynamically expanded if needed. + */ +{ + struct expEvent *newItem; + int newSize, index, downIndex; + + /* Check to see if we need to expand it */ + if ((textInfo->exposeSize + 3) >= textInfo->exposeAlloc) { + newSize = textInfo->exposeAlloc + + (textInfo->exposeAlloc * EXPANDPERCENT / 100); + textInfo->exposeAry = (struct expEvent **) + realloc((char *) textInfo->exposeAry, + (unsigned) (newSize * sizeof(struct expEvent *))); + for (index = textInfo->exposeAlloc; index < newSize; index++) + textInfo->exposeAry[index] = alloc(struct expEvent); + textInfo->exposeAlloc = newSize; + } + /* Find spot for insertion. NOTE: last spot has big number */ + for (index = 0; index <= textInfo->exposeSize; index++) { + if (textInfo->exposeAry[index]->lineIndex >= thisIndex) { + if (textInfo->exposeAry[index]->lineIndex > thisIndex) { + /* Insert before this entry */ + newItem = textInfo->exposeAry[textInfo->exposeSize+1]; + for (downIndex = textInfo->exposeSize; + downIndex >= index; + downIndex--) + { + textInfo->exposeAry[downIndex+1] = + textInfo->exposeAry[downIndex]; + } + /* Put a free structure at this spot */ + textInfo->exposeAry[index] = newItem; + /* Fill it in */ + textInfo->exposeAry[index]->lineIndex = thisIndex; + textInfo->exposeAry[index]->ypos = ypos; + /* Break out of loop */ + textInfo->exposeSize += 1; + } + break; + } + } + return 1; +} + + + +static int ScrollUp(display, textInfo) +Display *display; +struct txtWin *textInfo; /* Text window information */ +/* + * This routine scrolls the indicated text window up by one + * line. The line above the current line must exist. The + * window is scrolled so that the line above the start line + * is displayed at the top of the screen. This may cause + * many lines to scroll off the bottom. The scrolling is + * done using XCopyArea. The exposure events should be caught + * by ExposeCopy. + */ +{ + int targetSpace; + + /* Make sure all exposures have been handled by now */ + if (textInfo->startLine == 0) return 0; + targetSpace = textInfo->txtBuffer[textInfo->startLine-1]->lineHeight + + INTERLINE; + /* Move the area downward by the target amount */ + XCopyArea(display, textInfo->mainWindow, textInfo->mainWindow, + DEFAULT_GC, + 0, YPADDING, textInfo->w - BARSIZE, + textInfo->h, 0, targetSpace); + + textInfo->flagWord |= COPYEXPOSE; + /* Update the text window parameters */ + textInfo->startLine -= 1; + textInfo->endLine = FindEndLine(textInfo, &(textInfo->bottomSpace)); + + /* Clear out bottom space region */ + XClearArea(display, textInfo->mainWindow, + 0, textInfo->h - textInfo->bottomSpace, + textInfo->w, textInfo->bottomSpace); + + UpdateExposures(display, textInfo); + UpdateScroll(display, textInfo); + + return 1; +} + + +static int ScrollToSpot(display, textInfo, ySpot) +Display *display; +struct txtWin *textInfo; /* Text window information */ +int ySpot; /* Button position in scroll window */ +/* + * This routine scrolls the specified text window relative to the + * position of the mouse in the scroll bar. The center of the screen + * will be positioned to correspond to the mouse position. + */ +{ + int targetLine, aboveLines; + + targetLine = textInfo->numLines * ySpot / textInfo->h; + textInfo->startLine = targetLine; + textInfo->endLine = FindEndLine(textInfo, &(textInfo->bottomSpace)); + aboveLines = 0; + /* Make the target line the *center* of the window */ + while ((textInfo->startLine > 0) && + (aboveLines < textInfo->endLine - targetLine)) + { + textInfo->startLine -= 1; + textInfo->endLine = FindEndLine(textInfo, &(textInfo->bottomSpace)); + aboveLines++; + } + if (textInfo->endLine == textInfo->numLines-1) { + WarpToBottom(display, textInfo); + } else { + XClearWindow(display, textInfo->mainWindow); + TxtRepaint(display, textInfo->mainWindow); + } + return 1; +} + + + +static int LineToTop(display, textInfo, pos) +Display *display; +struct txtWin *textInfo; /* Text window information */ +int pos; /* Y position of mouse */ +/* + * This routine scrolls the screen down until the line at the + * mouse position is at the top of the screen. It stops + * if it can't scroll the buffer down that far. If the + * global 'ScrollOption' is NORMSCROLL, a smooth scroll + * is used. Otherwise, it jumps to the right position + * and repaints the screen. + */ +{ + int index, sum; + + /* First, we find the current line */ + sum = 0; + for (index = textInfo->startLine; index <= textInfo->endLine; index++) { + if (sum + textInfo->txtBuffer[index]->lineHeight + INTERLINE> pos) break; + sum += textInfo->txtBuffer[index]->lineHeight + INTERLINE; + } + /* We always want to scroll down at least one line */ + if (index == textInfo->startLine) index++; + if (ScrollOption == NORMSCROLL) { + /* Scroll down until 'index' is the starting line */ + while ((textInfo->startLine < index) && ScrollDown(display, textInfo)) + { + /* Empty Loop Body */ + } + } else { + /* Immediately jump to correct spot */ + textInfo->startLine = index; + textInfo->endLine = FindEndLine(textInfo, &(textInfo->bottomSpace)); + if (textInfo->endLine == textInfo->numLines-1) { + WarpToBottom(display, textInfo); + } else { + XClearWindow(display, textInfo->mainWindow); + TxtRepaint(display, textInfo->mainWindow); + } + } + /* Check to see if at end of buffer */ + if (textInfo->endLine >= textInfo->numLines-1) { + textInfo->flagWord &= (~NOTATBOTTOM); + } + return 1; +} + + + +static int TopToHere(display, textInfo, pos) +Display *display; +struct txtWin *textInfo; /* Text window information */ +int pos; /* Y position of mouse */ +/* + * This routine scrolls the screen up until the top line of + * the screen is at the current Y position of the mouse. Again, + * it will stop if it can't scroll that far. If the global + * 'ScrollOption' is NORMSCROLL, a smooth scroll is used. + * If it's not, it will simply redraw the screen at the + * correct spot. + */ +{ + int sum, target, linesup, index; + + target = pos - textInfo->txtBuffer[textInfo->startLine]->lineHeight; + /* We always want to scroll up at least one line */ + if (target <= 0) target = 1; + sum = 0; + linesup = 0; + /* Check to see if we are at the top anyway */ + if (textInfo->startLine == 0) return 0; + if (ScrollOption == NORMSCROLL) { + /* Scroll up until sum of new top lines greater than target */ + while ((sum < target) && ScrollUp(display, textInfo)) { + sum += textInfo->txtBuffer[textInfo->startLine]->lineHeight; + linesup++; + } + } else { + /* Search backward to find index */ + index = textInfo->startLine - 1; + while ((index > 0) && (sum < target)) { + sum += textInfo->txtBuffer[index]->lineHeight; + linesup++; + index--; + } + /* Go directly to the index */ + textInfo->startLine = index; + textInfo->endLine = FindEndLine(textInfo, &(textInfo->bottomSpace)); + XClearWindow(display, textInfo->mainWindow); + TxtRepaint(display, textInfo->mainWindow); + } + /* If we scrolled, assert we are not at bottom of buffer */ + if (linesup > 0) { + textInfo->flagWord |= NOTATBOTTOM; + } + return 1; +} + + + +int TxtFilter(display, evt) +Display *display; +XEvent *evt; +/* + * This routine handles events associated with scrollable text windows. + * It will handle all exposure events and any button released events + * in the scroll bar of a text window. It does NOT handle any other + * events. If it cannot handle the event, it will return 0. + */ +{ + XExposeEvent *expose = &evt->xexpose; + XButtonEvent *btEvt = &evt->xbutton; + XGraphicsExposeEvent *gexpose = &evt->xgraphicsexpose; + XNoExposeEvent *noexpose = &evt->xnoexpose; + struct txtWin *textInfo; + int index, ypos; + Window w, sw; + + if (textWindows == (XAssocTable *) 0) { + textWindows = XCreateAssocTable(32); + if (textWindows == (XAssocTable *) 0) return(0); + } + if (evt->type == Expose) { + w = expose->window; + sw = 0; + } + else if (evt->type == GraphicsExpose) { + w = gexpose->drawable; + sw = 0; + } + else if (evt->type == NoExpose) { + w = noexpose->drawable; + sw = 0; + } + else if (evt->type == ButtonRelease) { + w = btEvt->window; + sw = btEvt->subwindow; + } + else + return 0; + + if ((textInfo = (struct txtWin *) + XLookUpAssoc(display, textWindows, (XID) w)) == 0) + return 0; + + /* Determine whether it's main window or not */ + if ((w == textInfo->mainWindow) && (sw == 0)) { + /* Main Window - handle exposures */ + switch (evt->type) { + case Expose: + ypos = 0 /*YPADDING*/; + for (index = textInfo->startLine; + index <= textInfo->endLine; + index++) + { + int lh = textInfo->txtBuffer[index]->lineHeight; + + if (((ypos + lh) >= expose->y) && + (ypos <= (expose->y + expose->height))) + { + /* Intersection region */ + /* Draw line immediately */ + DrawLine(display, textInfo, index, ypos); + /* And possibly draw cursor */ + if (textInfo->curLine == index) { + XFillRectangle(display, w, textInfo->CursorGC, + textInfo->txtBuffer[index]->lineWidth + + CUROFFSET, + ypos, + CURSORWIDTH, + lh); + } + } + ypos += lh + INTERLINE; + } + break; + case GraphicsExpose: + ypos = 0 /*YPADDING*/; + for (index = textInfo->startLine; + index <= textInfo->endLine; + index++) + { + int lh = textInfo->txtBuffer[index]->lineHeight; + + if (((ypos + lh) >= gexpose->y) && + (ypos <= (gexpose->y + gexpose->height))) + { + /* Intersection region */ + /* Draw line immediately */ + DrawLine(display, textInfo, index, ypos); + /* And possibly draw cursor */ + if (textInfo->curLine == index) { + XFillRectangle(display, w, textInfo->CursorGC, + textInfo->txtBuffer[index]->lineWidth + + CUROFFSET, + ypos, + CURSORWIDTH, + lh); + } + } + ypos += lh + INTERLINE; + } + break; + case NoExpose: + break; + default: + /* Not one of our events */ + return 0; + } + } else { + switch (evt->type) { + case Expose: + UpdateScroll(display, textInfo); + break; + case ButtonRelease: + /* Find out which button */ + switch (btEvt->button) { + case Button1: + /* Scroll up until top line is at mouse position */ + TopToHere(display, textInfo, btEvt->y); + break; + case Button2: + /* Scroll to spot relative to position */ + ScrollToSpot(display, textInfo, btEvt->y); + if (textInfo->endLine >= textInfo->numLines-1) { + textInfo->flagWord &= (~NOTATBOTTOM); + } else { + textInfo->flagWord |= NOTATBOTTOM; + } + break; + case Button3: + /* Scroll down until pointed line is at top */ + LineToTop(display, textInfo, btEvt->y); + break; + } + break; + default: + /* Not one of our events */ + return 0; + } + } + return 1; +} diff --git a/gnu/games/chess/Xchess/scrollText/scrollText.h b/gnu/games/chess/Xchess/scrollText/scrollText.h new file mode 100644 index 000000000000..d9d05b08dc0b --- /dev/null +++ b/gnu/games/chess/Xchess/scrollText/scrollText.h @@ -0,0 +1,32 @@ +/* + * Scrollable Text Window Header File + * + * David Harrison + * University of California, Berkeley + * 1986 + * + * This file contains definitions for a scrollable text window + * with scroll bar support. + */ + +int TxtGrab(); + /* Take hold of a previously created window */ + +#define TXT_NO_COLOR -1 + +int TxtAddFont(); + /* Loads a new font for use later */ +int TxtWinP(); + /* Returns non-zero value if the window is text window */ +int TxtClear(); + /* Clears text window and resets text buffer */ + +int TxtWriteStr(); + /* Writes a string to window with immediate update */ +int TxtJamStr(); + /* Write a string without causing update to screen */ + +int TxtRepaint(); + /* Repaints entire scrollable text window */ +int TxtFilter(); + /* Handles events related to text window */ diff --git a/gnu/games/chess/Xchess/shade.bitmap b/gnu/games/chess/Xchess/shade.bitmap new file mode 100644 index 000000000000..a32ac80611ce --- /dev/null +++ b/gnu/games/chess/Xchess/shade.bitmap @@ -0,0 +1,71 @@ + +#define shade_width 80 +#define shade_height 80 +static char shade_bits[] = { + 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x22, 0x22, + 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x11, 0x11, 0x11, 0x11, + 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, + 0x88, 0x88, 0x88, 0x88, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, + 0x44, 0x44, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, + 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x88, 0x88, + 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x44, 0x44, 0x44, 0x44, + 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, + 0x22, 0x22, 0x22, 0x22, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, + 0x11, 0x11, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, + 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x22, 0x22, + 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x11, 0x11, 0x11, 0x11, + 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, + 0x88, 0x88, 0x88, 0x88, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, + 0x44, 0x44, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, + 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x88, 0x88, + 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x44, 0x44, 0x44, 0x44, + 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, + 0x22, 0x22, 0x22, 0x22, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, + 0x11, 0x11, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, + 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x22, 0x22, + 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x11, 0x11, 0x11, 0x11, + 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, + 0x88, 0x88, 0x88, 0x88, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, + 0x44, 0x44, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, + 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x88, 0x88, + 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x44, 0x44, 0x44, 0x44, + 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, + 0x22, 0x22, 0x22, 0x22, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, + 0x11, 0x11, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, + 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x22, 0x22, + 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x11, 0x11, 0x11, 0x11, + 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, + 0x88, 0x88, 0x88, 0x88, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, + 0x44, 0x44, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, + 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x88, 0x88, + 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x44, 0x44, 0x44, 0x44, + 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, + 0x22, 0x22, 0x22, 0x22, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, + 0x11, 0x11, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, + 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x22, 0x22, + 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x11, 0x11, 0x11, 0x11, + 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, + 0x88, 0x88, 0x88, 0x88, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, + 0x44, 0x44, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, + 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x88, 0x88, + 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x44, 0x44, 0x44, 0x44, + 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, + 0x22, 0x22, 0x22, 0x22, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, + 0x11, 0x11, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, + 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x22, 0x22, + 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x11, 0x11, 0x11, 0x11, + 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, + 0x88, 0x88, 0x88, 0x88, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, + 0x44, 0x44, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, + 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x88, 0x88, + 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x44, 0x44, 0x44, 0x44, + 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, + 0x22, 0x22, 0x22, 0x22, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, + 0x11, 0x11, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, + 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x22, 0x22, + 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x11, 0x11, 0x11, 0x11, + 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, + 0x88, 0x88, 0x88, 0x88, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, + 0x44, 0x44, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, + 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x88, 0x88, + 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88}; diff --git a/gnu/games/chess/Xchess/std.c b/gnu/games/chess/Xchess/std.c new file mode 100644 index 000000000000..8f3865bac3fd --- /dev/null +++ b/gnu/games/chess/Xchess/std.c @@ -0,0 +1,427 @@ + +/* This file contains code for X-CHESS. + Copyright (C) 1986 Free Software Foundation, Inc. + +This file is part of X-CHESS. + +X-CHESS is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY. No author or distributor +accepts responsibility to anyone for the consequences of using it +or for whether it serves any particular purpose or works at all, +unless he says so in writing. Refer to the X-CHESS General Public +License for full details. + +Everyone is granted permission to copy, modify and redistribute +X-CHESS, but only under the conditions described in the +X-CHESS General Public License. A copy of this license is +supposed to have been given to you along with X-CHESS so you +can know your rights and responsibilities. It should be in a +file named COPYING. Among other things, the copyright notice +and this notice must be preserved on all copies. */ + + +/* RCS Info: $Revision: 1.2 $ on $Date: 1994/01/07 11:10:42 $ + * $Source: /home/cvs/386BSD/src/gnu/games/chess/Xchess/std.c,v $ + * Copyright (c) 1985 Wayne A. Christopher, U. C. Berkeley CAD Group + * + * Utility routines. + */ + +#include "std.h" + +#ifndef IBMPC +#include <sys/types.h> +#endif not IBMPC +#ifdef UNIX +#include <signal.h> +#include <pwd.h> +#endif UNIX +#ifdef BSD +#include <sys/time.h> +#include <sys/resource.h> +#endif BSD + +extern char **environ; + +bool +prefix(p, s) + register char *p, *s; +{ + while (*p && (*p == *s)) + p++, s++; + if (!*p) + return (true); + else + return (false); +} + +/* Create a copy of a string. */ + +char * +copy(str) + char *str; +{ + char *p, *tmalloc(); + + p = tmalloc(strlen(str) + 1); + strcpy(p, str); + return(p); +} + +/* Determine whether sub is a substring of str. */ + +bool +substring(sub, str) + register char *str, *sub; +{ + register char *s; + + while(*str) { + if(*str == *sub) { + for(s = sub; *s; s++) + if(*s != *str++) + break; + if(*s == '\0') + return (true); + } + str++; + } + return (false); +} + +/* Malloc num bytes and initialize to zero. Fatal error if the space can't + * be malloc'd. + */ + +char * +tmalloc(num) + register int num; +{ + register char *s; + char *malloc(); + + s = malloc((unsigned) num); + if (!s) { + fatal("malloc: can't allocate %d bytes", num); + } + bzero(s, num); + return(s); +} + +char * +trealloc(ptr, num) + char *ptr; + int num; +{ + register char *s; + char *realloc(); + + s = realloc(ptr, (unsigned) num); + if (!s) { + fatal("realloc: can't allocate %d bytes", num); + } + /* Well, this won't be zeroed... Too bad... */ + return(s); +} + +/* Append one character to a string. Don't check for overflow. */ + +void +appendc(s, c) + char *s, c; +{ + while (*s) + s++; + *s++ = c; + *s = '\0'; + return; +} + +int +scannum(str) + char *str; +{ + int i = 0; + + while(isdigit(*str)) + i = i * 10 + *(str++) - '0'; + return(i); +} + +/* Case insensitive prefix. */ + +bool +ciprefix(p, s) + register char *p, *s; +{ + while (*p) { + if ((isupper(*p) ? tolower(*p) : *p) != + (isupper(*s) ? tolower(*s) : *s)) + return(false); + p++; + s++; + } + return (true); +} + +/* Case insensitive strcmp... */ + +bool +cieq(p, s) + register char *p, *s; +{ + while (*p) { + if ((isupper(*p) ? tolower(*p) : *p) != + (isupper(*s) ? tolower(*s) : *s)) + return(false); + p++; + s++; + } + return (!*s); +} + +#ifdef BSD + +/* Return the date. Return value is static data. */ + +char * +datestring() +{ + register char *tzn; + struct tm *tp; + static char tbuf[40]; + char *ap; + struct timeval tv; + struct timezone tz; + char *timezone(), *asctime(); + int i; + struct tm *localtime(); + + (void) gettimeofday(&tv, &tz); + tp = localtime((time_t *) &tv.tv_sec); + ap = asctime(tp); + tzn = timezone(tz.tz_minuteswest, tp->tm_isdst); + sprintf(tbuf, "%.20s", ap); + if (tzn) + strcat(tbuf, tzn); + strcat(tbuf, ap + 19); + i = strlen(tbuf); + tbuf[i - 1] = '\0'; + return (tbuf); +} + +#else BSD + +/* Give it a try... */ + +char * +datestring() +{ + long i; + static char buf[64]; + + i = time(0); + strcpy(buf, ctime(&i)); + buf[strlen(buf) - 1] = '\0'; /* Kill the nl. */ + return (buf); +} + +#endif + +/* How many seconds have elapsed in running time. */ + +int +seconds() +{ +#ifdef BSD + struct rusage ruse; + + getrusage(RUSAGE_SELF, &ruse); + return (ruse.ru_utime.tv_sec); +#else BSD +#endif BSD +} + +/* A few things that may not exist on non-unix systems. */ + +#ifndef BSD + +#ifndef index + +char * +index(s, c) + register char *s; + register char c; +{ + while ((*s != c) && (*s != '\0')) + s++; + if (*s == '\0') + return ((char *) 0); + else + return (s); +} + +#endif not index + +#ifndef rindex + +char * +rindex(s, c) + register char *s; + register char c; +{ + register char *t; + + for (t = s; *t != '\0'; t++); + while ((*t != c) && (t != s)) + t--; + if (t == s) + return ((char *) 0); + else + return (t); +} + +#endif not rindex + +#ifndef bcopy + +void +bcopy(from, to, num) + register char *from, *to; + register int num; +{ + while (num-- > 0) + *to++ = *from++; + return; +} + +#endif not bcopy + +#ifndef bzero + +void +bzero(ptr, num) + register char *ptr; + register int num; +{ + while (num-- > 0) + *ptr++ = '\0'; + return; +} + +#endif not bzero + +/* This might not be around... If not then forget about sorting... */ + +void qsort() {} + +#endif BSD + +char * +gettok(s) + char **s; +{ + char buf[BSIZE]; + int i = 0; + + while (isspace(**s)) + (*s)++; + if (!**s) + return (NULL); + while (**s && !isspace(**s)) + buf[i++] = *(*s)++; + buf[i] = '\0'; + while (isspace(**s)) + (*s)++; + return (copy(buf)); +} + +/* Die horribly. */ + +/* VARARGS1 */ +void +fatal(s, args) + char *s; +{ + fputs("Internal Error: ", stderr); +#ifndef __386BSD__ + _doprnt(s, &args, stderr); +#endif + putc('\n', stderr); + + kill(getpid(), SIGIOT); + /* NOTREACHED */ +} + +void +setenv(name, value) + char *name, *value; +{ + int i; + char **xx, *s; + + s = tmalloc(strlen(name) + 2); + sprintf(s, "%s=", name); + + /* Copy the old environment... */ + for (i = 0; environ[i]; i++) + if (prefix(s, environ[i])) + break; + if (!environ[i]) { + xx = (char **) tmalloc((i + 2) * sizeof (char *)); + for (i = 0; environ[i]; i++) + xx[i] = environ[i]; + xx[i + 1] = NULL; + environ = xx; + } else + xx = environ; + + xx[i] = tmalloc(strlen(name) + strlen(value) + 2); + sprintf(xx[i], "%s=%s", name, value); + return; +} + +char * +getusername() +{ + int i = getuid(); + struct passwd *pw = getpwuid(i); + + return (pw ? pw->pw_name : NULL); +} + +char * +gethome() +{ + int i = getuid(); + struct passwd *pw = getpwuid(i); + + return (pw ? pw->pw_dir : "/strange"); +} + +char * +tildexpand(s) + char *s; +{ + struct passwd *pw; + char *n, buf[64]; + int i; + + if (*s != '~') + return (copy(s)); + + for (s++, i = 0; *s != '/'; s++, i++) + buf[i] = *s; + buf[i] = '\0'; + if (!i) + pw = getpwuid(getuid()); + else + pw = getpwnam(buf); + if (!pw) + return (s); + n = tmalloc(strlen(s) + strlen(pw->pw_dir) + 1); + strcpy(n, pw->pw_dir); + strcat(n, s); + return (n); +} + diff --git a/gnu/games/chess/Xchess/std.h b/gnu/games/chess/Xchess/std.h new file mode 100644 index 000000000000..ec70e3a43c5b --- /dev/null +++ b/gnu/games/chess/Xchess/std.h @@ -0,0 +1,105 @@ + +/* This file contains code for X-CHESS. + Copyright (C) 1986 Free Software Foundation, Inc. + +This file is part of X-CHESS. + +X-CHESS is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY. No author or distributor +accepts responsibility to anyone for the consequences of using it +or for whether it serves any particular purpose or works at all, +unless he says so in writing. Refer to the X-CHESS General Public +License for full details. + +Everyone is granted permission to copy, modify and redistribute +X-CHESS, but only under the conditions described in the +X-CHESS General Public License. A copy of this license is +supposed to have been given to you along with X-CHESS so you +can know your rights and responsibilities. It should be in a +file named COPYING. Among other things, the copyright notice +and this notice must be preserved on all copies. */ + + +/* RCS Info: $Revision: 1.1.1.1 $ on $Date: 1993/06/12 14:41:06 $ + * $Source: /home/cvs/386BSD/src/gnu/games/chess/Xchess/std.h,v $ + * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group + * + * Standard definitions. + */ + +#define UNIX +#define BSD + +#ifndef FILE +#include <stdio.h> +#endif +#ifndef isalpha +#include <ctype.h> +#endif +#ifndef HUGE +#include <math.h> +#endif +#include <strings.h> + +typedef int bool; + +#define false 0 +#define true 1 + +/* Externs defined in std.c */ + +extern char *tmalloc(); +extern char *trealloc(); +extern char *copy(); +extern char *datestring(); +extern char *getusername(); +extern char *gethome(); +extern char *gettok(); +extern char *tildexpand(); +extern void fatal(); +extern void setenv(); +extern void appendc(); +extern int scannum(); +extern int seconds(); +extern bool prefix(); +extern bool ciprefix(); +extern bool cieq(); +extern bool substring(); + +/* Externs from libc */ + +extern char *getenv(); +extern int errno; +extern char *sys_errlist[]; + +/* Should use BSIZE instead of BUFSIZ... */ + +#define BSIZE 512 + +/* Some standard macros. */ + +#define eq(a,b) (!strcmp((a), (b))) +#define isalphanum(c) (isalpha(c) || isdigit(c)) +#define alloc(strname) ((struct strname *) tmalloc(sizeof(struct strname))) +#define tfree(ptr) { if (ptr) free((char *) ptr); ptr = 0; } +#define hexnum(c) ((((c) >= '0') && ((c) <= '9')) ? ((c) - '0') : ((((c) >= \ + 'a') && ((c) <= 'f')) ? ((c) - 'a' + 10) : ((((c) >= 'A') && \ + ((c) <= 'F')) ? ((c) - 'A' + 10) : 0))) + +#ifndef BSD +#define random rand +#define srandom srand +#endif BSD + +#ifdef VMS + +#define EXIT_NORMAL 1 +#define EXIT_BAD 0 + +#else VMS + +#define EXIT_NORMAL 0 +#define EXIT_BAD 1 + +#endif VMS + diff --git a/gnu/games/chess/Xchess/valid.c b/gnu/games/chess/Xchess/valid.c new file mode 100644 index 000000000000..30ca40fb193e --- /dev/null +++ b/gnu/games/chess/Xchess/valid.c @@ -0,0 +1,264 @@ + +/* This file contains code for X-CHESS. + Copyright (C) 1986 Free Software Foundation, Inc. + +This file is part of X-CHESS. + +X-CHESS is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY. No author or distributor +accepts responsibility to anyone for the consequences of using it +or for whether it serves any particular purpose or works at all, +unless he says so in writing. Refer to the X-CHESS General Public +License for full details. + +Everyone is granted permission to copy, modify and redistribute +X-CHESS, but only under the conditions described in the +X-CHESS General Public License. A copy of this license is +supposed to have been given to you along with X-CHESS so you +can know your rights and responsibilities. It should be in a +file named COPYING. Among other things, the copyright notice +and this notice must be preserved on all copies. */ + + +/* RCS Info: $Revision: 1.1.1.1 $ on $Date: 1993/06/12 14:41:08 $ + * $Source: /home/cvs/386BSD/src/gnu/games/chess/Xchess/valid.c,v $ + * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group + * Permission is granted to do anything with this code except sell it + * or remove this message. + * + * Validate a move. + */ + +#include "xchess.h" + +extern bool ischeck(), couldmove(); + +bool +valid_move(m, b) + move *m; + board *b; +{ + board tb; + + /* First check that the piece can make the move at all... */ + if (!couldmove(m, b)) + return (false); + + /* Now see if the king is in check now. */ + bcopy((char *) b, (char *) &tb, sizeof (board)); + board_move(&tb, m); + if (ischeck(&tb, m->piece.color)) + return (false); + + if (ischeck(&tb, ((m->piece.color == WHITE) ? BLACK : WHITE))) + m->check = true; + + return (true); +} + +static bool +couldmove(m, b) + move *m; + board *b; +{ + int x, y; + + switch (m->type) { + case KCASTLE: + if ((m->piece.color == WHITE) && (b->white_cant_castle_k) || + (m->piece.color == BLACK) && + (b->black_cant_castle_k)) + return (false); + if ((b->square[m->fromy][5].color != NONE) || + (b->square[m->fromy][6].color != NONE)) + return (false); + if (ischeck(b, m->piece.color)) + return (false); + break; + + case QCASTLE: + if ((m->piece.color == WHITE) && (b->white_cant_castle_q) || + (m->piece.color == BLACK) && + (b->black_cant_castle_q)) + return (false); + if ((b->square[m->fromy][1].color != NONE) || + (b->square[m->fromy][2].color != NONE) || + (b->square[m->fromy][3].color != NONE)) + return (false); + if (ischeck(b, m->piece.color)) + return (false); + break; + + case MOVE: + case CAPTURE: + /* There is one special case here, that of taking a pawn + * en passant. In this case we change the move field to + * CAPTURE if it's ok. + */ + switch (m->piece.type) { + case PAWN: + if ((m->type == MOVE) && (m->fromx == m->tox)) { + /* A normal move. */ + if ((m->piece.color == WHITE) && (m->fromy == + m->toy + 1)) + break; + if ((m->piece.color == WHITE) && (m->fromy == + 6) && (m->toy == 4) && + (b->square[5][m->fromx].color + == NONE)) + break; + if ((m->piece.color == BLACK) && (m->fromy == + m->toy - 1)) + break; + if ((m->piece.color == BLACK) && (m->fromy == + 1) && (m->toy == 3) && + (b->square[2][m->fromx].color + == NONE)) + break; + return (false); + } else if (m->type == CAPTURE) { + if ((((m->piece.color == WHITE) && (m->fromy == + m->toy + 1)) || ((m->piece.color == + BLACK) && (m->fromy == m->toy - + 1))) && ((m->fromx == m->tox + 1) || + (m->fromx == m->tox - 1))) + break; + /* Now maybe it's enpassant... We've already + * checked for some of these things in the + * calling routine. + */ + if (m->enpassant) { + if (b->square[(m->piece.color == WHITE) + ? 3 : 4][m->tox].color == + ((m->piece.color == WHITE) ? + BLACK : WHITE)) + break; + } + return (false); + } + return (false); + + case ROOK: + if (m->fromx == m->tox) { + for (y = m->fromy + ((m->fromy > m->toy) ? -1 : + 1); y != m->toy; y += ((m->fromy + > m->toy) ? -1 : 1)) + if (b->square[y][m->tox].color != NONE) + return (false); + break; + } + if (m->fromy == m->toy) { + for (x = m->fromx + ((m->fromx > m->tox) ? -1 : + 1); x != m->tox; x += ((m->fromx + > m->tox) ? -1 : 1)) + if (b->square[m->toy][x].color != NONE) + return (false); + break; + } + return (false); + + case KNIGHT: + x = m->fromx - m->tox; + y = m->fromy - m->toy; + if ((((x == 2) || (x == -2)) && + ((y == 1) || (y == -1))) || + (((x == 1) || (x == -1)) && + ((y == 2) || (y == -2)))) + break; + return (false); + + case BISHOP: + x = m->fromx - m->tox; + y = m->fromy - m->toy; + if ((x != y) && (x != - y)) + return (false); + for (x = m->fromx + ((m->fromx > m->tox) ? -1 : 1), y = + m->fromy + ((m->fromy > m->toy) ? -1 : + 1); x != m->tox; + x += ((m->fromx > m->tox) ? -1 : 1), + y += ((m->fromy > m->toy) ? -1 : 1)) + if (b->square[y][x].color != NONE) + return (false); + break; + + case QUEEN: + if (m->fromx == m->tox) { + for (y = m->fromy + ((m->fromy > m->toy) ? -1 : + 1); y != m->toy; y += ((m->fromy + > m->toy) ? -1 : 1)) + if (b->square[y][m->tox].color != NONE) + return (false); + break; + } + if (m->fromy == m->toy) { + for (x = m->fromx + ((m->fromx > m->tox) ? -1 : + 1); x != m->tox; x += ((m->fromx + > m->tox) ? -1 : 1)) + if (b->square[m->toy][x].color != NONE) + return (false); + break; + } + x = m->fromx - m->tox; + y = m->fromy - m->toy; + if ((x != y) && (x != - y)) + return (false); + for (x = m->fromx + ((m->fromx > m->tox) ? -1 : 1), y = + m->fromy + ((m->fromy > m->toy) ? -1 : + 1); x != m->tox; + x += ((m->fromx > m->tox) ? -1 : 1), + y += ((m->fromy > m->toy) ? -1 : 1)) + if (b->square[y][x].color != NONE) + return (false); + break; + + case KING: + x = m->fromx - m->tox; + y = m->fromy - m->toy; + if ((x >= -1) && (x <= 1) && (y >= -1) && (y <= 1)) + break; + return (false); + } + break; + } + return (true); +} + +/* Say whether either king is in check... If move is non-NULL, say whether he + * in in check after the move takes place. We do this in a rather stupid way. + */ + +static bool +ischeck(b, col) + board *b; + color col; +{ + int x, y, kx, ky; + move ch; + + for (x = 0; x < SIZE; x++) + for (y = 0; y < SIZE; y++) + if ((b->square[y][x].color == col) && + (b->square[y][x].type == KING)) { + kx = x; + ky = y; + } + + for (x = 0; x < SIZE; x++) + for (y = 0; y < SIZE; y++) + if (b->square[y][x].color == ((col == WHITE) ? + BLACK : WHITE)) { + ch.type = CAPTURE; + ch.piece.color = b->square[y][x].color; + ch.piece.type = b->square[y][x].type; + ch.fromx = x; + ch.fromy = y; + ch.tox = kx; + ch.toy = ky; + ch.enpassant = false; + if (couldmove(&ch, b)) + return (true); + } + + return (false); +} + diff --git a/gnu/games/chess/Xchess/window.c b/gnu/games/chess/Xchess/window.c new file mode 100644 index 000000000000..70e9491ca04e --- /dev/null +++ b/gnu/games/chess/Xchess/window.c @@ -0,0 +1,952 @@ +/* This file contains code for X-CHESS. + Copyright (C) 1986 Free Software Foundation, Inc. + +This file is part of X-CHESS. + +X-CHESS is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY. No author or distributor +accepts responsibility to anyone for the consequences of using it +or for whether it serves any particular purpose or works at all, +unless he says so in writing. Refer to the X-CHESS General Public +License for full details. + +Everyone is granted permission to copy, modify and redistribute +X-CHESS, but only under the conditions described in the +X-CHESS General Public License. A copy of this license is +supposed to have been given to you along with X-CHESS so you +can know your rights and responsibilities. It should be in a +file named COPYING. Among other things, the copyright notice +and this notice must be preserved on all copies. */ + + +/* RCS Info: $Revision: 1.1.1.1 $ on $Date: 1993/06/12 14:41:08 $ + * $Source: /home/cvs/386BSD/src/gnu/games/chess/Xchess/window.c,v $ + * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group + * Permission is granted to do anything with this code except sell it + * or remove this message. + * + * Deal with the two (or one) windows. + */ + +#include "xchess.h" +#include <X11/Xutil.h> +#include <sys/time.h> + +#include "pawn.bitmap" +#include "rook.bitmap" +#include "knight.bitmap" +#include "bishop.bitmap" +#include "queen.bitmap" +#include "king.bitmap" + +#include "pawn_outline.bitmap" +#include "rook_outline.bitmap" +#include "knight_outline.bitmap" +#include "bishop_outline.bitmap" +#include "queen_outline.bitmap" +#include "king_outline.bitmap" + +#include "pawn_mask.bitmap" +#include "rook_mask.bitmap" +#include "knight_mask.bitmap" +#include "bishop_mask.bitmap" +#include "queen_mask.bitmap" +#include "king_mask.bitmap" + +#include "shade.bitmap" + +#include "xchess.cur" +#include "xchess_mask.cur" + +#include "xchess.icon" + +windata *win1, *win2; +bool win_flashmove = false; + +extern bool setup(); +extern void service(), drawgrid(), icon_refresh(); + +bool +win_setup(disp1, disp2) + char *disp1, *disp2; +{ + win1 = alloc(windata); + if (!oneboard) + win2 = alloc(windata); + + if (!setup(disp1, win1) || (!oneboard && !setup(disp2, win2))) + return (false); + + if (blackflag) { + win1->color = BLACK; + win1->flipped = true; + } else + win1->color = WHITE; + win_drawboard(win1); + + if (!oneboard) { + win2->color = BLACK; + win2->flipped = true; + win_drawboard(win2); + } + + return(true); +} + +/* Draw the chess board... */ + +void +win_drawboard(win) + windata *win; +{ + int i, j; + + drawgrid(win); + + /* Now toss on the squares... */ + for (i = 0; i < SIZE; i++) + for (j = 0; j < SIZE; j++) + win_erasepiece(j, i, win->color); + + return; +} + +/* Draw one piece. */ + +void +win_drawpiece(p, y, x, wnum) + piece *p; + int y, x; + color wnum; +{ + char *bits, *maskbits, *outline; + windata *win; + char buf[BSIZE]; + XImage *tmpImage; + Pixmap tmpPM, maskPM; + XGCValues gc; + + if (oneboard || (wnum == win1->color)) + win = win1; + else + win = win2; + + if (win->flipped) { + y = SIZE - y - 1; + x = SIZE - x - 1; + } + + /* + if (debug) + fprintf(stderr, "draw a %s at (%d, %d) on board %d\n", + piecenames[(int) p->type], y, x, wnum); + */ + + if ((x < 0) || (x > 7) || (y < 0) || (y > 7)) exit(1); + + switch (p->type) { + case PAWN: + bits = pawn_bits; + maskbits = pawn_mask_bits; + outline = pawn_outline_bits; + break; + + case ROOK: + bits = rook_bits; + maskbits = rook_mask_bits; + outline = rook_outline_bits; + break; + + case KNIGHT: + bits = knight_bits; + maskbits = knight_mask_bits; + outline = knight_outline_bits; + break; + + case BISHOP: + bits = bishop_bits; + maskbits = bishop_mask_bits; + outline = bishop_outline_bits; + break; + + case QUEEN: + bits = queen_bits; + maskbits = queen_mask_bits; + outline = queen_outline_bits; + break; + + case KING: + bits = king_bits; + maskbits = king_mask_bits; + outline = king_outline_bits; + break; + + default: + fprintf(stderr, + "Internal Error: win_drawpiece: bad piece type %d\n", + p->type); + } + + /* There are two things we can do... If this is a black and white + * display, we have to shade the square and use an outline if the piece + * is white. We also have to use a mask... Since we don't want + * to use up too many bitmaps, create the mask bitmap, put the bits, + * and then destroy it. + */ + if (win->bnw && (p->color == WHITE)) + bits = outline; + if (win->bnw && !iswhite(win, x, y)) { + XSetState(win->display, DefaultGC(win->display, 0), + BlackPixel(win->display, 0), + WhitePixel(win->display, 0), GXcopy, AllPlanes); + + tmpPM = XCreateBitmapFromData(win->display, win->boardwin, + shade_bits, SQUARE_WIDTH, SQUARE_HEIGHT); + + XCopyPlane(win->display, tmpPM, win->boardwin, DefaultGC(win->display, 0), + 0, 0, SQUARE_WIDTH, SQUARE_HEIGHT, + x * (SQUARE_WIDTH + BORDER_WIDTH), + y * (SQUARE_HEIGHT + BORDER_WIDTH), 1); + + XFreePixmap(win->display, tmpPM); + + XSetFunction(win->display, DefaultGC(win->display, 0), + GXandInverted); + maskPM = XCreateBitmapFromData(win->display, win->boardwin, + maskbits, SQUARE_WIDTH, SQUARE_HEIGHT); + XCopyPlane(win->display, maskPM, win->boardwin, DefaultGC(win->display, 0), + 0, 0, SQUARE_WIDTH, SQUARE_HEIGHT, + x * (SQUARE_WIDTH + BORDER_WIDTH), + y * (SQUARE_HEIGHT + BORDER_WIDTH), 1); + XFreePixmap(win->display, maskPM); + + XSetFunction(win->display, DefaultGC(win->display, 0), + GXor); + tmpPM = XCreateBitmapFromData(win->display, win->boardwin, + bits, SQUARE_WIDTH, SQUARE_HEIGHT); + XCopyPlane(win->display, tmpPM, win->boardwin, DefaultGC(win->display, 0), + 0, 0, SQUARE_WIDTH, SQUARE_HEIGHT, + x * (SQUARE_WIDTH + BORDER_WIDTH), + y * (SQUARE_HEIGHT + BORDER_WIDTH), 1); + XFreePixmap(win->display, tmpPM); + + XSetFunction(win->display, DefaultGC(win->display, 0), GXcopy); + + } else if (win->bnw){ + XSetState(win->display, DefaultGC(win->display, 0), + BlackPixel(win->display, 0), + WhitePixel(win->display, 0), GXcopy, AllPlanes); + + tmpPM = XCreateBitmapFromData(win->display, win->boardwin, + bits, SQUARE_WIDTH, SQUARE_HEIGHT); + XCopyPlane(win->display, tmpPM, win->boardwin, DefaultGC(win->display, 0), + 0, 0, SQUARE_WIDTH, SQUARE_HEIGHT, + x * (SQUARE_WIDTH + BORDER_WIDTH), + y * (SQUARE_HEIGHT + BORDER_WIDTH), 1); + XFreePixmap(win->display, tmpPM); + } else { + XSetState(win->display, DefaultGC(win->display, 0), + ((p->color == WHITE) ? win->whitepiece.pixel : + win->blackpiece.pixel), + (iswhite(win, x, y) ? win->whitesquare.pixel : + win->blacksquare.pixel), + GXcopy, AllPlanes); + tmpPM = XCreateBitmapFromData(win->display, win->boardwin, + bits, SQUARE_WIDTH, SQUARE_HEIGHT); + XCopyPlane(win->display, tmpPM, win->boardwin, DefaultGC(win->display, 0), + 0, 0, SQUARE_WIDTH, SQUARE_HEIGHT, + x * (SQUARE_WIDTH + BORDER_WIDTH), + y * (SQUARE_HEIGHT + BORDER_WIDTH), 1); + XFreePixmap(win->display, tmpPM); + } + + if (!record_english) { + gc.foreground = win->textcolor.pixel; + if (iswhite(win, x, y) || win->bnw) + gc.background = win->whitesquare.pixel; + else + gc.background = win->blacksquare.pixel; + + gc.font = win->small->fid; + + XChangeGC(win->display, DefaultGC(win->display, 0), + GCForeground | GCBackground | GCFont, &gc); + + if (!x) { + sprintf(buf, " %d", SIZE - y); + XDrawImageString(win->display, win->boardwin, + DefaultGC(win->display, 0), + 1, (y + 1) * (SQUARE_HEIGHT + + BORDER_WIDTH) - BORDER_WIDTH + + win->small->max_bounds.ascent - 1, buf, 2); + } + if (y == SIZE - 1) { + sprintf(buf, "%c", 'A' + x); + XDrawImageString(win->display, win->boardwin, + DefaultGC(win->display, 0), + x * (SQUARE_WIDTH + BORDER_WIDTH) + 1, + SIZE * (SQUARE_HEIGHT + BORDER_WIDTH) - BORDER_WIDTH + + win->small->max_bounds.ascent - 1, buf, 1); + } + } + return; +} + +void +win_erasepiece(y, x, wnum) + int y, x; + color wnum; +{ + windata *win; + char buf[BSIZE]; + XGCValues gc; + Pixmap tmpPM; + + if (oneboard || (wnum == win1->color)) + win = win1; + else + win = win2; + + if (win->flipped) { + y = SIZE - y - 1; + x = SIZE - x - 1; + } + + /* + if (debug) + fprintf(stderr, "erase square (%d, %d) on board %d\n", y, x, + wnum); + */ + + if ((x < 0) || (x > 7) || (y < 0) || (y > 7)) exit(1); + + if (win->bnw && !iswhite(win, x, y)) { + XSetState(win->display, DefaultGC(win->display, 0), + BlackPixel(win->display, 0), + WhitePixel(win->display, 0), GXcopy, AllPlanes); + tmpPM = XCreateBitmapFromData(win->display, win->boardwin, + shade_bits, SQUARE_WIDTH, SQUARE_HEIGHT); + + XCopyPlane(win->display, tmpPM, win->boardwin, DefaultGC(win->display, 0), + 0, 0, SQUARE_WIDTH, SQUARE_HEIGHT, + x * (SQUARE_WIDTH + BORDER_WIDTH), + y * (SQUARE_HEIGHT + BORDER_WIDTH), 1); + + XFreePixmap(win->display, tmpPM); + } else { + XSetFillStyle(win->display, DefaultGC(win->display, 0), + FillSolid); + XSetForeground(win->display, DefaultGC(win->display, 0), + iswhite(win, x, y) ? win->whitesquare.pixel : + win->blacksquare.pixel); + XFillRectangle(win->display, win->boardwin, + DefaultGC(win->display, 0), + x * (SQUARE_WIDTH + BORDER_WIDTH), + y * (SQUARE_HEIGHT + BORDER_WIDTH), + SQUARE_WIDTH, SQUARE_HEIGHT); + } + + if (!record_english) { + gc.foreground = win->textcolor.pixel; + if (iswhite(win, x, y) || win->bnw) + gc.background = win->whitesquare.pixel; + else + gc.background = win->blacksquare.pixel; + + gc.font = win->small->fid; + + XChangeGC(win->display, DefaultGC(win->display, 0), + GCForeground | GCBackground | GCFont, &gc); + + if (!x) { + sprintf(buf, " %d", SIZE - y); + XDrawImageString(win->display, win->boardwin, + DefaultGC(win->display, 0), + 1, (y + 1) * (SQUARE_HEIGHT + + BORDER_WIDTH) - BORDER_WIDTH + + win->small->max_bounds.ascent - 1, buf, 2); + } + if (y == SIZE - 1) { + sprintf(buf, "%c", 'A' + x); + XDrawImageString(win->display, win->boardwin, + DefaultGC(win->display, 0), + x * (SQUARE_WIDTH + BORDER_WIDTH) + 1, + SIZE * (SQUARE_HEIGHT + BORDER_WIDTH) - BORDER_WIDTH + + win->small->max_bounds.ascent - 1, buf, 1); + } + } + + + return; +} + +void +win_flash(m, wnum) + move *m; + color wnum; +{ + windata *win; + int sx, sy, ex, ey, i; + + if (oneboard || (wnum == win1->color)) + win = win1; + else + win = win2; + + if (win->flipped) { + sx = SIZE - m->fromx - 1; + sy = SIZE - m->fromy - 1; + ex = SIZE - m->tox - 1; + ey = SIZE - m->toy - 1; + } else { + sx = m->fromx; + sy = m->fromy; + ex = m->tox; + ey = m->toy; + } + sx = sx * (SQUARE_WIDTH + BORDER_WIDTH) + SQUARE_WIDTH / 2; + sy = sy * (SQUARE_HEIGHT + BORDER_WIDTH) + SQUARE_HEIGHT / 2; + ex = ex * (SQUARE_WIDTH + BORDER_WIDTH) + SQUARE_WIDTH / 2; + ey = ey * (SQUARE_HEIGHT + BORDER_WIDTH) + SQUARE_HEIGHT / 2; + + XSetFunction(win->display, DefaultGC(win->display, 0), GXinvert); + XSetLineAttributes(win->display, DefaultGC(win->display, 0), + 0, LineSolid, 0, 0); + for (i = 0; i < num_flashes * 2; i++) { + XDrawLine(win->display,win->boardwin, + DefaultGC(win->display, 0), + sx, sy, ex, ey); + } + + XSetFunction(win->display, DefaultGC(win->display, 0), GXcopy); + return; +} + +/* Handle input from the players. */ + +void +win_process(quick) + bool quick; +{ + int i, rfd = 0, wfd = 0, xfd = 0; + struct timeval timeout; + + timeout.tv_sec = 0; + timeout.tv_usec = (quick ? 0 : 500000); + + if (XPending(win1->display)) + service(win1); + if (!oneboard) { + if (XPending(win1->display)) + service(win2); + } + + if (oneboard) + rfd = 1 << win1->display->fd; + else + rfd = (1 << win1->display->fd) | (1 << win2->display->fd); + if (!(i = select(32, &rfd, &wfd, &xfd, &timeout))) + return; + if (i == -1) { + perror("select"); + exit(1); + } + if (rfd & (1 << win1->display->fd)) + service(win1); + if (!oneboard && (rfd & (1 << win2->display->fd))) + service(win2); + + return; +} + +static void +service(win) + windata *win; +{ + XEvent ev; + + while(XPending(win->display)) { + XNextEvent(win->display, &ev); + if (TxtFilter(win->display, &ev)) + continue; + + if (ev.xany.window == win->boardwin) { + switch (ev.type) { + case ButtonPress: + button_pressed(&ev, win); + break; + + case ButtonRelease: + button_released(&ev, win); + break; + + case Expose: + /* Redraw... */ + win_redraw(win, &ev); + break; + + case 0: + case NoExpose: + break; + default: + fprintf(stderr, "Bad event type %d\n", ev.type); + exit(1); + } + } else if (ev.xany.window == win->wclockwin) { + switch (ev.type) { + case Expose: + clock_draw(win, WHITE); + break; + + case 0: + case NoExpose: + break; + default: + fprintf(stderr, "Bad event type %d\n", ev.type); + exit(1); + } + } else if (ev.xany.window == win->bclockwin) { + switch (ev.type) { + case Expose: + clock_draw(win, BLACK); + break; + + case 0: + case NoExpose: + break; + default: + fprintf(stderr, "Bad event type %d\n", ev.type); + exit(1); + } + } else if (ev.xany.window == win->jailwin) { + switch (ev.type) { + case Expose: + jail_draw(win); + break; + + case 0: + case NoExpose: + break; + default: + fprintf(stderr, "Bad event type %d\n", ev.type); + exit(1); + } + } else if (ev.xany.window == win->buttonwin) { + switch (ev.type) { + case ButtonPress: + button_service(win, &ev); + break; + + case Expose: + button_draw(win); + break; + + case 0: + case NoExpose: + break; + default: + fprintf(stderr, "Bad event type %d\n", ev.type); + exit(1); + } + } else if (ev.xany.window == win->icon) { + icon_refresh(win); + } else if (ev.xany.window == win->basewin) { + message_send(win, &ev); + } else { + fprintf(stderr, "Internal Error: service: bad win\n"); + fprintf(stderr, "window = %d, event = %d\n", ev.xany.window, + ev.type); + } + } + return; +} + +void +win_redraw(win, event) + windata *win; + XEvent *event; +{ + XExposeEvent *ev = &event->xexpose; + int x1, y1, x2, y2, i, j; + + drawgrid(win); + if (ev) { + x1 = ev->x / (SQUARE_WIDTH + BORDER_WIDTH); + y1 = ev->y / (SQUARE_HEIGHT + BORDER_WIDTH); + x2 = (ev->x + ev->width) / (SQUARE_WIDTH + BORDER_WIDTH); + y2 = (ev->y + ev->height) / (SQUARE_HEIGHT + BORDER_WIDTH); + } else { + x1 = 0; + y1 = 0; + x2 = SIZE - 1; + y2 = SIZE - 1; + } + + if (x1 < 0) x1 = 0; + if (y1 < 0) y1 = 0; + if (x2 < 0) x2 = 0; + if (y2 < 0) y2 = 0; + if (x1 > SIZE - 1) x1 = SIZE - 1; + if (y1 > SIZE - 1) y1 = SIZE - 1; + if (x2 > SIZE - 1) x2 = SIZE - 1; + if (y2 > SIZE - 1) y2 = SIZE - 1; + + if (win->flipped) { + y1 = SIZE - y2 - 1; + y2 = SIZE - y1 - 1; + x1 = SIZE - x2 - 1; + x2 = SIZE - x1 - 1; + } + + for (i = x1; i <= x2; i++) + for (j = y1; j <= y2; j++) { + if (chessboard->square[j][i].color == NONE) + win_erasepiece(j, i, WHITE); + else + win_drawpiece(&chessboard->square[j][i], j, i, + WHITE); + if (!oneboard) { + if (chessboard->square[j][i].color == NONE) + win_erasepiece(j, i, BLACK); + else + win_drawpiece(&chessboard->square[j][i], + j, i, BLACK); + } + } + + return; +} + +static bool +setup(dispname, win) + char *dispname; + windata *win; +{ + char buf[BSIZE], *s; + Pixmap bm, bmask; + Cursor cur; + extern char *program, *recfile; + XSizeHints xsizes; + + + if (!(win->display = XOpenDisplay(dispname))) + return (false); + + + /* Now get boolean defaults... */ + if ((s = XGetDefault(win->display, program, "noisy")) && eq(s, "on")) + noisyflag = true; + if ((s = XGetDefault(win->display, program, "savemoves")) && eq(s, "on")) + saveflag = true; + if ((s = XGetDefault(win->display, program, "algebraic")) && eq(s, "on")) + record_english = false; + if ((s = XGetDefault(win->display, program, "blackandwhite")) && eq(s, "on")) + bnwflag = true; + if ((s = XGetDefault(win->display, program, "quickrestore")) && eq(s, "on")) + quickflag = true; + if ((s = XGetDefault(win->display, program, "flash")) && eq(s, "on")) + win_flashmove = true; + + /* ... numeric variables ... */ + if (s = XGetDefault(win->display, program, "numflashes")) + num_flashes = atoi(s); + if (s = XGetDefault(win->display, program, "flashsize")) + flash_size = atoi(s); + + /* ... and strings. */ + if (s = XGetDefault(win->display, program, "progname")) + progname = s; + if (s = XGetDefault(win->display, program, "proghost")) + proghost = s; + if (s = XGetDefault(win->display, program, "recordfile")) + recfile = s; + if (s = XGetDefault(win->display, program, "blackpiece")) + black_piece_color = s; + if (s = XGetDefault(win->display, program, "whitepiece")) + white_piece_color = s; + if (s = XGetDefault(win->display, program, "blacksquare")) + black_square_color = s; + if (s = XGetDefault(win->display, program, "whitesquare")) + white_square_color = s; + if (s = XGetDefault(win->display, program, "bordercolor")) + border_color = s; + if (s = XGetDefault(win->display, program, "textcolor")) + text_color = s; + if (s = XGetDefault(win->display, program, "textback")) + text_back = s; + if (s = XGetDefault(win->display, program, "errortext")) + error_text = s; + if (s = XGetDefault(win->display, program, "playertext")) + player_text = s; + if (s = XGetDefault(win->display, program, "cursorcolor")) + cursor_color = s; + + if ((DisplayPlanes(win->display, 0) == 1) || bnwflag) + win->bnw = true; + + /* Allocate colors... */ + if (win->bnw) { + win->blackpiece.pixel = BlackPixel (win->display, 0); + win->whitepiece.pixel = WhitePixel (win->display, 0); + win->blacksquare.pixel = BlackPixel (win->display, 0); + win->whitesquare.pixel = WhitePixel (win->display, 0); + win->border.pixel = BlackPixel (win->display, 0); + win->textcolor.pixel = BlackPixel (win->display, 0); + win->textback.pixel = WhitePixel (win->display, 0); + win->playertext.pixel = BlackPixel (win->display, 0); + win->errortext.pixel = BlackPixel (win->display, 0); + win->cursorcolor.pixel = BlackPixel (win->display, 0) ; + } else { + if (!XParseColor(win->display, + DefaultColormap(win->display, 0), + black_piece_color, &win->blackpiece) || + !XParseColor(win->display, + DefaultColormap(win->display, 0), + white_piece_color, &win->whitepiece) || + !XParseColor(win->display, + DefaultColormap(win->display, 0), + black_square_color, &win->blacksquare) || + !XParseColor(win->display, + DefaultColormap(win->display, 0), + white_square_color, &win->whitesquare) || + !XParseColor(win->display, + DefaultColormap(win->display, 0), + border_color, &win->border) || + !XParseColor(win->display, + DefaultColormap(win->display, 0), + text_color, &win->textcolor) || + !XParseColor(win->display, + DefaultColormap(win->display, 0), + text_back, &win->textback) || + !XParseColor(win->display, + DefaultColormap(win->display, 0), + error_text, &win->errortext) || + !XParseColor(win->display, + DefaultColormap(win->display, 0), + player_text, &win->playertext) || + !XParseColor(win->display, + DefaultColormap(win->display, 0), + cursor_color, &win->cursorcolor) || + !XAllocColor(win->display, + DefaultColormap(win->display, 0), + &win->blackpiece) || + !XAllocColor(win->display, + DefaultColormap(win->display, 0), + &win->whitepiece) || + !XAllocColor(win->display, + DefaultColormap(win->display, 0), + &win->blacksquare) || + !XAllocColor(win->display, + DefaultColormap(win->display, 0), + &win->whitesquare) || + !XAllocColor(win->display, + DefaultColormap(win->display, 0), + &win->border) || + !XAllocColor(win->display, + DefaultColormap(win->display, 0), + &win->textcolor) || + !XAllocColor(win->display, + DefaultColormap(win->display, 0), + &win->textback) || + !XAllocColor(win->display, + DefaultColormap(win->display, 0), + &win->errortext) || + !XAllocColor(win->display, + DefaultColormap(win->display, 0), + &win->playertext) || + !XAllocColor(win->display, + DefaultColormap(win->display, 0), + &win->cursorcolor)) + fprintf(stderr, "Can't get colors...\n"); + } + + /* Get fonts... */ + if ((win->small = XLoadQueryFont(win->display,SMALL_FONT)) == + NULL) + fprintf(stderr, "Can't get small font...\n"); + + if ((win->medium = XLoadQueryFont(win->display,MEDIUM_FONT)) + == NULL) + fprintf(stderr, "Can't get medium font...\n"); + + if ((win->large = XLoadQueryFont(win->display,LARGE_FONT)) == + NULL) + fprintf(stderr, "Can't get large font...\n"); + + + /* Create the windows... */ + + win->basewin = + XCreateSimpleWindow(win->display,DefaultRootWindow(win->display), + BASE_XPOS, BASE_YPOS, + BASE_WIDTH, BASE_HEIGHT, 0, + BlackPixel(win->display, 0), + WhitePixel(win->display, 0)); + win->boardwin = XCreateSimpleWindow(win->display,win->basewin, + BOARD_XPOS, BOARD_YPOS, + BOARD_WIDTH, BOARD_HEIGHT, + BORDER_WIDTH, + win->border.pixel, + WhitePixel(win->display, 0)); + win->recwin = XCreateSimpleWindow(win->display,win->basewin, + RECORD_XPOS, RECORD_YPOS, + RECORD_WIDTH, RECORD_HEIGHT, + BORDER_WIDTH, win->border.pixel, + win->textback.pixel); + win->jailwin = XCreateSimpleWindow(win->display,win->basewin, + JAIL_XPOS, JAIL_YPOS, + JAIL_WIDTH, JAIL_HEIGHT, + BORDER_WIDTH, + win->border.pixel, + win->textback.pixel); + win->wclockwin = XCreateSimpleWindow(win->display,win->basewin, + WCLOCK_XPOS, WCLOCK_YPOS, + CLOCK_WIDTH, CLOCK_HEIGHT, + BORDER_WIDTH, win->border.pixel, + win->textback.pixel); + win->bclockwin = XCreateSimpleWindow(win->display,win->basewin, + BCLOCK_XPOS, BCLOCK_YPOS, + CLOCK_WIDTH, CLOCK_HEIGHT, + BORDER_WIDTH, win->border.pixel, + win->textback.pixel); + win->messagewin = XCreateSimpleWindow(win->display,win->basewin, + MESS_XPOS, MESS_YPOS, + MESS_WIDTH, MESS_HEIGHT, + BORDER_WIDTH, win->border.pixel, + win->textback.pixel); + win->buttonwin = XCreateSimpleWindow(win->display,win->basewin, + BUTTON_XPOS, BUTTON_YPOS, + BUTTON_WIDTH, BUTTON_HEIGHT, + BORDER_WIDTH, win->border.pixel, + win->textback.pixel); + + /* Let's define an icon... */ + win->iconpixmap = XCreatePixmapFromBitmapData(win->display, + win->basewin, icon_bits, + icon_width, icon_height, + win->blacksquare.pixel, + win->whitesquare.pixel, + 1); + xsizes.flags = PSize | PMinSize | PPosition; + xsizes.min_width = BASE_WIDTH; + xsizes.min_height = BASE_HEIGHT; + xsizes.x = BASE_XPOS; + xsizes.y = BASE_YPOS; + XSetStandardProperties(win->display, win->basewin, + program, program, win->iconpixmap, + 0, NULL, &xsizes); + + bm = XCreateBitmapFromData(win->display, + win->basewin, xchess_bits, + xchess_width, xchess_height); + bmask = XCreateBitmapFromData(win->display, + win->basewin, xchess_mask_bits, + xchess_width, xchess_height); + cur = XCreatePixmapCursor(win->display, bm, bmask, + &win->cursorcolor, + &WhitePixel(win->display, 0), + xchess_x_hot, xchess_y_hot); + XFreePixmap(win->display, bm); + XFreePixmap(win->display, bmask); + + XDefineCursor(win->display,win->basewin, cur); + + XMapSubwindows(win->display,win->basewin); + XMapRaised(win->display,win->basewin); + + XSelectInput(win->display,win->basewin, KeyPressMask); + XSelectInput(win->display,win->boardwin, + ButtonPressMask | ButtonReleaseMask | ExposureMask); + XSelectInput(win->display,win->recwin, + ButtonReleaseMask | ExposureMask); + XSelectInput(win->display,win->jailwin, ExposureMask); + XSelectInput(win->display,win->wclockwin, ExposureMask); + XSelectInput(win->display,win->bclockwin, ExposureMask); + XSelectInput(win->display,win->messagewin, + ButtonReleaseMask | ExposureMask); + XSelectInput(win->display,win->buttonwin, + ButtonPressMask | ExposureMask); + + message_init(win); + record_init(win); + button_draw(win); + jail_init(win); + clock_init(win, WHITE); + clock_init(win, BLACK); + if (timeunit) { + if (timeunit > 1800) + sprintf(buf, "%d moves every %.2lg hours.\n", + movesperunit, ((double) timeunit) / 3600); + else if (timeunit > 30) + sprintf(buf, "%d moves every %.2lg minutes.\n", + movesperunit, ((double) timeunit) / 60); + else + sprintf(buf, "%d moves every %d seconds.\n", + movesperunit, timeunit); + message_add(win, buf, false); + } + return (true); +} + +static void +drawgrid(win) + windata *win; +{ + int i; + XGCValues gc; + + gc.function = GXcopy; + gc.plane_mask = AllPlanes; + gc.foreground = win->border.pixel; + gc.line_width = 0; + gc.line_style = LineSolid; + + XChangeGC(win->display, + DefaultGC(win->display, 0), + GCFunction | GCPlaneMask | GCForeground | + GCLineWidth | GCLineStyle, &gc); + + /* Draw the lines... horizontal, */ + for (i = 1; i < SIZE; i++) + XDrawLine(win->display, win->boardwin, + DefaultGC(win->display, 0), 0, + i * (SQUARE_WIDTH + BORDER_WIDTH) - + BORDER_WIDTH / 2, + SIZE * (SQUARE_WIDTH + BORDER_WIDTH), + i * (SQUARE_WIDTH + BORDER_WIDTH) - + BORDER_WIDTH / 2); + + /* and vertical... */ + for (i = 1; i < SIZE; i++) + XDrawLine(win->display, win->boardwin, + DefaultGC(win->display, 0), + i * (SQUARE_WIDTH + BORDER_WIDTH) - + BORDER_WIDTH / 2, 0, + i * (SQUARE_WIDTH + BORDER_WIDTH) - + BORDER_WIDTH / 2, + SIZE * (SQUARE_WIDTH + BORDER_WIDTH)); + return; +} + +void +win_restart() +{ + win1->flipped = false; + win_redraw(win1, (XEvent *) NULL); + if (!oneboard) { + win2->flipped = true; + win_redraw(win2, (XEvent *) NULL); + } + return; +} + +static void +icon_refresh(win) + windata *win; +{ + XCopyArea(win->display, win->iconpixmap, win->icon, + DefaultGC(win->display, 0), + 0, 0, icon_width, icon_height, 0, 0); + return; +} + diff --git a/gnu/games/chess/Xchess/window.c.bm b/gnu/games/chess/Xchess/window.c.bm new file mode 100644 index 000000000000..efcfc0aaa897 --- /dev/null +++ b/gnu/games/chess/Xchess/window.c.bm @@ -0,0 +1,928 @@ +/* This file contains code for X-CHESS. + Copyright (C) 1986 Free Software Foundation, Inc. + +This file is part of X-CHESS. + +X-CHESS is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY. No author or distributor +accepts responsibility to anyone for the consequences of using it +or for whether it serves any particular purpose or works at all, +unless he says so in writing. Refer to the X-CHESS General Public +License for full details. + +Everyone is granted permission to copy, modify and redistribute +X-CHESS, but only under the conditions described in the +X-CHESS General Public License. A copy of this license is +supposed to have been given to you along with X-CHESS so you +can know your rights and responsibilities. It should be in a +file named COPYING. Among other things, the copyright notice +and this notice must be preserved on all copies. */ + + +/* RCS Info: $Revision: 1.1.1.1 $ on $Date: 1993/06/12 14:41:07 $ + * $Source: /home/cvs/386BSD/src/gnu/games/chess/Xchess/window.c.bm,v $ + * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group + * Permission is granted to do anything with this code except sell it + * or remove this message. + * + * Deal with the two (or one) windows. + */ + +#include "xchess.h" +#include <sys/time.h> + +#include "pawn.bitmap" +#include "rook.bitmap" +#include "knight.bitmap" +#include "bishop.bitmap" +#include "queen.bitmap" +#include "king.bitmap" + +#include "pawn_outline.bitmap" +#include "rook_outline.bitmap" +#include "knight_outline.bitmap" +#include "bishop_outline.bitmap" +#include "queen_outline.bitmap" +#include "king_outline.bitmap" + +#include "pawn_mask.bitmap" +#include "rook_mask.bitmap" +#include "knight_mask.bitmap" +#include "bishop_mask.bitmap" +#include "queen_mask.bitmap" +#include "king_mask.bitmap" + +#include "shade.bitmap" + +#include "xchess.cur" +#include "xchess_mask.cur" + +#include "xchess.icon" + +windata *win1, *win2; +bool win_flashmove = false; + +extern bool setup(); +extern void service(), drawgrid(), icon_refresh(); + +bool +win_setup(disp1, disp2) + char *disp1, *disp2; +{ + win1 = alloc(windata); + if (!oneboard) + win2 = alloc(windata); + + if (!setup(disp1, win1) || (!oneboard && !setup(disp2, win2))) + return (false); + + if (blackflag) { + win1->color = BLACK; + win1->flipped = true; + } else + win1->color = WHITE; + win_drawboard(win1); + + if (!oneboard) { + win2->color = BLACK; + win2->flipped = true; + win_drawboard(win2); + } + + return(true); +} + +/* Draw the chess board... */ + +void +win_drawboard(win) + windata *win; +{ + int i, j; + + drawgrid(win); + + /* Now toss on the squares... */ + for (i = 0; i < SIZE; i++) + for (j = 0; j < SIZE; j++) + win_erasepiece(j, i, win->color); + + return; +} + +/* Draw one piece. */ + +void +win_drawpiece(p, y, x, wnum) + piece *p; + int y, x; + color wnum; +{ + char *bits, *maskbits, *outline; + windata *win; + char buf[BSIZE]; + XImage *tmpImage; + Pixmap tmpPM, maskPM; + XGCValues gc; + + if (oneboard || (wnum == win1->color)) + win = win1; + else + win = win2; + + if (win->flipped) { + y = SIZE - y - 1; + x = SIZE - x - 1; + } + + /* + if (debug) + fprintf(stderr, "draw a %s at (%d, %d) on board %d\n", + piecenames[(int) p->type], y, x, wnum); + */ + + if ((x < 0) || (x > 7) || (y < 0) || (y > 7)) exit(1); + + switch (p->type) { + case PAWN: + bits = pawn_bits; + maskbits = pawn_mask_bits; + outline = pawn_outline_bits; + break; + + case ROOK: + bits = rook_bits; + maskbits = rook_mask_bits; + outline = rook_outline_bits; + break; + + case KNIGHT: + bits = knight_bits; + maskbits = knight_mask_bits; + outline = knight_outline_bits; + break; + + case BISHOP: + bits = bishop_bits; + maskbits = bishop_mask_bits; + outline = bishop_outline_bits; + break; + + case QUEEN: + bits = queen_bits; + maskbits = queen_mask_bits; + outline = queen_outline_bits; + break; + + case KING: + bits = king_bits; + maskbits = king_mask_bits; + outline = king_outline_bits; + break; + + default: + fprintf(stderr, + "Internal Error: win_drawpiece: bad piece type %d\n", + p->type); + } + + /* There are two things we can do... If this is a black and white + * display, we have to shade the square and use an outline if the piece + * is white. We also have to use a mask... Since we don't want + * to use up too many bitmaps, create the mask bitmap, put the bits, + * and then destroy it. + */ + if (win->bnw && (p->color == WHITE)) + bits = outline; + if (win->bnw && !iswhite(win, x, y)) { + XSetState(win->display, DefaultGC(win->display, 0), + BlackPixel(win->display, 0), + WhitePixel(win->display, 0), GXcopy, AllPlanes); + + tmpPM = XCreateBitmapFromData(win->display, win->boardwin, + shade_bits, SQUARE_WIDTH, SQUARE_HEIGHT); + + XCopyPlane(win->display, tmpPM, win->boardwin, DefaultGC(win->display, 0), + 0, 0, SQUARE_WIDTH, SQUARE_HEIGHT, + x * (SQUARE_WIDTH + BORDER_WIDTH), + y * (SQUARE_HEIGHT + BORDER_WIDTH), 1); + + XFreePixmap(win->display, tmpPM); + + XSetFunction(win->display, DefaultGC(win->display, 0), + GXandInverted); + maskPM = XCreateBitmapFromData(win->display, win->boardwin, + maskbits, SQUARE_WIDTH, SQUARE_HEIGHT); + XCopyPlane(win->display, maskPM, win->boardwin, DefaultGC(win->display, 0), + 0, 0, SQUARE_WIDTH, SQUARE_HEIGHT, + x * (SQUARE_WIDTH + BORDER_WIDTH), + y * (SQUARE_HEIGHT + BORDER_WIDTH), 1); + XFreePixmap(win->display, maskPM); + + XSetFunction(win->display, DefaultGC(win->display, 0), + GXor); + tmpPM = XCreateBitmapFromData(win->display, win->boardwin, + bits, SQUARE_WIDTH, SQUARE_HEIGHT); + XCopyPlane(win->display, tmpPM, win->boardwin, DefaultGC(win->display, 0), + 0, 0, SQUARE_WIDTH, SQUARE_HEIGHT, + x * (SQUARE_WIDTH + BORDER_WIDTH), + y * (SQUARE_HEIGHT + BORDER_WIDTH), 1); + XFreePixmap(win->display, tmpPM); + + XSetFunction(win->display, DefaultGC(win->display, 0), GXcopy); + + } else if (win->bnw){ + XSetState(win->display, DefaultGC(win->display, 0), + BlackPixel(win->display, 0), + WhitePixel(win->display, 0), GXcopy, AllPlanes); + + tmpPM = XCreateBitmapFromData(win->display, win->boardwin, + bits, SQUARE_WIDTH, SQUARE_HEIGHT); + XCopyPlane(win->display, tmpPM, win->boardwin, DefaultGC(win->display, 0), + 0, 0, SQUARE_WIDTH, SQUARE_HEIGHT, + x * (SQUARE_WIDTH + BORDER_WIDTH), + y * (SQUARE_HEIGHT + BORDER_WIDTH), 1); + XFreePixmap(win->display, tmpPM); + } else { + XSetState(win->display, DefaultGC(win->display, 0), + ((p->color == WHITE) ? win->whitepiece.pixel : + win->blackpiece.pixel), + (iswhite(win, x, y) ? win->whitesquare.pixel : + win->blacksquare.pixel), + GXcopy, AllPlanes); + tmpPM = XCreateBitmapFromData(win->display, win->boardwin, + bits, SQUARE_WIDTH, SQUARE_HEIGHT); + XCopyPlane(win->display, tmpPM, win->boardwin, DefaultGC(win->display, 0), + 0, 0, SQUARE_WIDTH, SQUARE_HEIGHT, + x * (SQUARE_WIDTH + BORDER_WIDTH), + y * (SQUARE_HEIGHT + BORDER_WIDTH), 1); + XFreePixmap(win->display, tmpPM); + } + + if (!record_english) { + gc.foreground = win->textcolor.pixel; + if (iswhite(win, x, y) || win->bnw) + gc.background = win->whitesquare.pixel; + else + gc.background = win->blacksquare.pixel; + + gc.font = win->small->fid; + + XChangeGC(win->display, DefaultGC(win->display, 0), + GCForeground | GCBackground | GCFont, &gc); + + if (!x) { + sprintf(buf, " %d", SIZE - y); + XDrawImageString(win->display, win->boardwin, + DefaultGC(win->display, 0), + 1, (y + 1) * (SQUARE_HEIGHT + + BORDER_WIDTH) - BORDER_WIDTH + + win->small->max_bounds.ascent - 1, buf, 2); + } + if (y == SIZE - 1) { + sprintf(buf, "%c", 'A' + x); + XDrawImageString(win->display, win->boardwin, + DefaultGC(win->display, 0), + x * (SQUARE_WIDTH + BORDER_WIDTH) + 1, + SIZE * (SQUARE_HEIGHT + BORDER_WIDTH) - BORDER_WIDTH + + win->small->max_bounds.ascent - 1, buf, 1); + } + } + return; +} + +void +win_erasepiece(y, x, wnum) + int y, x; + color wnum; +{ + windata *win; + char buf[BSIZE]; + XGCValues gc; + Pixmap tmpPM; + + if (oneboard || (wnum == win1->color)) + win = win1; + else + win = win2; + + if (win->flipped) { + y = SIZE - y - 1; + x = SIZE - x - 1; + } + + /* + if (debug) + fprintf(stderr, "erase square (%d, %d) on board %d\n", y, x, + wnum); + */ + + if ((x < 0) || (x > 7) || (y < 0) || (y > 7)) exit(1); + + if (win->bnw && !iswhite(win, x, y)) { + XSetState(win->display, DefaultGC(win->display, 0), + BlackPixel(win->display, 0), + WhitePixel(win->display, 0), GXcopy, AllPlanes); + tmpPM = XCreateBitmapFromData(win->display, win->boardwin, + shade_bits, SQUARE_WIDTH, SQUARE_HEIGHT); + + XCopyPlane(win->display, tmpPM, win->boardwin, DefaultGC(win->display, 0), + 0, 0, SQUARE_WIDTH, SQUARE_HEIGHT, + x * (SQUARE_WIDTH + BORDER_WIDTH), + y * (SQUARE_HEIGHT + BORDER_WIDTH), 1); + + XFreePixmap(win->display, tmpPM); + } else { + XSetFillStyle(win->display, DefaultGC(win->display, 0), + FillSolid); + XSetForeground(win->display, DefaultGC(win->display, 0), + iswhite(win, x, y) ? win->whitesquare.pixel : + win->blacksquare.pixel); + XFillRectangle(win->display, win->boardwin, + DefaultGC(win->display, 0), + x * (SQUARE_WIDTH + BORDER_WIDTH), + y * (SQUARE_HEIGHT + BORDER_WIDTH), + SQUARE_WIDTH, SQUARE_HEIGHT); + } + + if (!record_english) { + gc.foreground = win->textcolor.pixel; + if (iswhite(win, x, y) || win->bnw) + gc.background = win->whitesquare.pixel; + else + gc.background = win->blacksquare.pixel; + + gc.font = win->small->fid; + + XChangeGC(win->display, DefaultGC(win->display, 0), + GCForeground | GCBackground | GCFont, &gc); + + if (!x) { + sprintf(buf, " %d", SIZE - y); + XDrawImageString(win->display, win->boardwin, + DefaultGC(win->display, 0), + 1, (y + 1) * (SQUARE_HEIGHT + + BORDER_WIDTH) - BORDER_WIDTH + + win->small->max_bounds.ascent - 1, buf, 2); + } + if (y == SIZE - 1) { + sprintf(buf, "%c", 'A' + x); + XDrawImageString(win->display, win->boardwin, + DefaultGC(win->display, 0), + x * (SQUARE_WIDTH + BORDER_WIDTH) + 1, + SIZE * (SQUARE_HEIGHT + BORDER_WIDTH) - BORDER_WIDTH + + win->small->max_bounds.ascent - 1, buf, 1); + } + } + + + return; +} + +void +win_flash(m, wnum) + move *m; + color wnum; +{ + windata *win; + int sx, sy, ex, ey, i; + + if (oneboard || (wnum == win1->color)) + win = win1; + else + win = win2; + + if (win->flipped) { + sx = SIZE - m->fromx - 1; + sy = SIZE - m->fromy - 1; + ex = SIZE - m->tox - 1; + ey = SIZE - m->toy - 1; + } else { + sx = m->fromx; + sy = m->fromy; + ex = m->tox; + ey = m->toy; + } + sx = sx * (SQUARE_WIDTH + BORDER_WIDTH) + SQUARE_WIDTH / 2; + sy = sy * (SQUARE_HEIGHT + BORDER_WIDTH) + SQUARE_HEIGHT / 2; + ex = ex * (SQUARE_WIDTH + BORDER_WIDTH) + SQUARE_WIDTH / 2; + ey = ey * (SQUARE_HEIGHT + BORDER_WIDTH) + SQUARE_HEIGHT / 2; + + for (i = 0; i < num_flashes * 2; i++) + XDrawLine(win->display,win->boardwin, + DefaultGC(win->display, 0), + sx, sy, ex, ey); + return; +} + +/* Handle input from the players. */ + +void +win_process(quick) + bool quick; +{ + int i, rfd = 0, wfd = 0, xfd = 0; + struct timeval timeout; + + timeout.tv_sec = 0; + timeout.tv_usec = (quick ? 0 : 500000); + + if (XPending(win1->display)) + service(win1); + if (!oneboard) { + if (XPending(win1->display)) + service(win2); + } + + if (oneboard) + rfd = 1 << win1->display->fd; + else + rfd = (1 << win1->display->fd) | (1 << win2->display->fd); + if (!(i = select(32, &rfd, &wfd, &xfd, &timeout))) + return; + if (i == -1) { + perror("select"); + exit(1); + } + if (rfd & (1 << win1->display->fd)) + service(win1); + if (!oneboard && (rfd & (1 << win2->display->fd))) + service(win2); + + return; +} + +static void +service(win) + windata *win; +{ + XEvent ev; + + while(XPending(win->display)) { + XNextEvent(win->display, &ev); + if (TxtFilter(win->display, &ev)) + continue; + + if (ev.xany.window == win->boardwin) { + switch (ev.type) { + case ButtonPress: + button_pressed(&ev, win); + break; + + case ButtonRelease: + button_released(&ev, win); + break; + + case Expose: + /* Redraw... */ + win_redraw(win, &ev); + break; + + case 0: + case NoExpose: + break; + default: + fprintf(stderr, "Bad event type %d\n", ev.type); + exit(1); + } + } else if (ev.xany.window == win->wclockwin) { + switch (ev.type) { + case Expose: + clock_draw(win, WHITE); + break; + + case 0: + case NoExpose: + break; + default: + fprintf(stderr, "Bad event type %d\n", ev.type); + exit(1); + } + } else if (ev.xany.window == win->bclockwin) { + switch (ev.type) { + case Expose: + clock_draw(win, BLACK); + break; + + case 0: + case NoExpose: + break; + default: + fprintf(stderr, "Bad event type %d\n", ev.type); + exit(1); + } + } else if (ev.xany.window == win->jailwin) { + switch (ev.type) { + case Expose: + jail_draw(win); + break; + + case 0: + case NoExpose: + break; + default: + fprintf(stderr, "Bad event type %d\n", ev.type); + exit(1); + } + } else if (ev.xany.window == win->buttonwin) { + switch (ev.type) { + case ButtonPress: + button_service(win, &ev); + break; + + case Expose: + button_draw(win); + break; + + case 0: + case NoExpose: + break; + default: + fprintf(stderr, "Bad event type %d\n", ev.type); + exit(1); + } + } else if (ev.xany.window == win->icon) { + icon_refresh(win); + } else if (ev.xany.window == win->basewin) { + message_send(win, &ev); + } else { + fprintf(stderr, "Internal Error: service: bad win\n"); + fprintf(stderr, "window = %d, event = %d\n", ev.xany.window, + ev.type); + } + } + return; +} + +void +win_redraw(win, event) + windata *win; + XEvent *event; +{ + XExposeEvent *ev = &event->xexpose; + int x1, y1, x2, y2, i, j; + + drawgrid(win); + if (ev) { + x1 = ev->x / (SQUARE_WIDTH + BORDER_WIDTH); + y1 = ev->y / (SQUARE_HEIGHT + BORDER_WIDTH); + x2 = (ev->x + ev->width) / (SQUARE_WIDTH + BORDER_WIDTH); + y2 = (ev->y + ev->height) / (SQUARE_HEIGHT + BORDER_WIDTH); + } else { + x1 = 0; + y1 = 0; + x2 = SIZE - 1; + y2 = SIZE - 1; + } + + if (x1 < 0) x1 = 0; + if (y1 < 0) y1 = 0; + if (x2 < 0) x2 = 0; + if (y2 < 0) y2 = 0; + if (x1 > SIZE - 1) x1 = SIZE - 1; + if (y1 > SIZE - 1) y1 = SIZE - 1; + if (x2 > SIZE - 1) x2 = SIZE - 1; + if (y2 > SIZE - 1) y2 = SIZE - 1; + + if (win->flipped) { + y1 = SIZE - y2 - 1; + y2 = SIZE - y1 - 1; + x1 = SIZE - x2 - 1; + x2 = SIZE - x1 - 1; + } + + for (i = x1; i <= x2; i++) + for (j = y1; j <= y2; j++) { + if (chessboard->square[j][i].color == NONE) + win_erasepiece(j, i, WHITE); + else + win_drawpiece(&chessboard->square[j][i], j, i, + WHITE); + if (!oneboard) { + if (chessboard->square[j][i].color == NONE) + win_erasepiece(j, i, BLACK); + else + win_drawpiece(&chessboard->square[j][i], + j, i, BLACK); + } + } + + return; +} + +static bool +setup(dispname, win) + char *dispname; + windata *win; +{ + char buf[BSIZE], *s; + Pixmap bm, bmask; + Cursor cur; + extern char *program, *recfile; + + + if (!(win->display = XOpenDisplay(dispname))) + return (false); + + + /* Now get boolean defaults... */ + if ((s = XGetDefault(win->display, program, "noisy")) && eq(s, "on")) + noisyflag = true; + if ((s = XGetDefault(win->display, program, "savemoves")) && eq(s, "on")) + saveflag = true; + if ((s = XGetDefault(win->display, program, "algebraic")) && eq(s, "on")) + record_english = false; + if ((s = XGetDefault(win->display, program, "blackandwhite")) && eq(s, "on")) + bnwflag = true; + if ((s = XGetDefault(win->display, program, "quickrestore")) && eq(s, "on")) + quickflag = true; + if ((s = XGetDefault(win->display, program, "flash")) && eq(s, "on")) + win_flashmove = true; + + /* ... numeric variables ... */ + if (s = XGetDefault(win->display, program, "numflashes")) + num_flashes = atoi(s); + if (s = XGetDefault(win->display, program, "flashsize")) + flash_size = atoi(s); + + /* ... and strings. */ + if (s = XGetDefault(win->display, program, "progname")) + progname = s; + if (s = XGetDefault(win->display, program, "proghost")) + proghost = s; + if (s = XGetDefault(win->display, program, "recordfile")) + recfile = s; + if (s = XGetDefault(win->display, program, "blackpiece")) + black_piece_color = s; + if (s = XGetDefault(win->display, program, "whitepiece")) + white_piece_color = s; + if (s = XGetDefault(win->display, program, "blacksquare")) + black_square_color = s; + if (s = XGetDefault(win->display, program, "whitesquare")) + white_square_color = s; + if (s = XGetDefault(win->display, program, "bordercolor")) + border_color = s; + if (s = XGetDefault(win->display, program, "textcolor")) + text_color = s; + if (s = XGetDefault(win->display, program, "textback")) + text_back = s; + if (s = XGetDefault(win->display, program, "errortext")) + error_text = s; + if (s = XGetDefault(win->display, program, "playertext")) + player_text = s; + if (s = XGetDefault(win->display, program, "cursorcolor")) + cursor_color = s; + + if ((DisplayPlanes(win->display, 0) == 1) || bnwflag) + win->bnw = true; + + /* Allocate colors... */ + if (win->bnw) { + win->blackpiece.pixel = BlackPixel (win->display, 0); + win->whitepiece.pixel = WhitePixel (win->display, 0); + win->blacksquare.pixel = BlackPixel (win->display, 0); + win->whitesquare.pixel = WhitePixel (win->display, 0); + win->border.pixel = BlackPixel (win->display, 0); + win->textcolor.pixel = BlackPixel (win->display, 0); + win->textback.pixel = WhitePixel (win->display, 0); + win->playertext.pixel = BlackPixel (win->display, 0); + win->errortext.pixel = BlackPixel (win->display, 0); + win->cursorcolor.pixel = BlackPixel (win->display, 0) ; + } else { + if (!XParseColor(win->display, + DefaultColormap(win->display, 0), + black_piece_color, &win->blackpiece) || + !XParseColor(win->display, + DefaultColormap(win->display, 0), + white_piece_color, &win->whitepiece) || + !XParseColor(win->display, + DefaultColormap(win->display, 0), + black_square_color, &win->blacksquare) || + !XParseColor(win->display, + DefaultColormap(win->display, 0), + white_square_color, &win->whitesquare) || + !XParseColor(win->display, + DefaultColormap(win->display, 0), + border_color, &win->border) || + !XParseColor(win->display, + DefaultColormap(win->display, 0), + text_color, &win->textcolor) || + !XParseColor(win->display, + DefaultColormap(win->display, 0), + text_back, &win->textback) || + !XParseColor(win->display, + DefaultColormap(win->display, 0), + error_text, &win->errortext) || + !XParseColor(win->display, + DefaultColormap(win->display, 0), + player_text, &win->playertext) || + !XParseColor(win->display, + DefaultColormap(win->display, 0), + cursor_color, &win->cursorcolor) || + !XAllocColor(win->display, + DefaultColormap(win->display, 0), + &win->blackpiece) || + !XAllocColor(win->display, + DefaultColormap(win->display, 0), + &win->whitepiece) || + !XAllocColor(win->display, + DefaultColormap(win->display, 0), + &win->blacksquare) || + !XAllocColor(win->display, + DefaultColormap(win->display, 0), + &win->whitesquare) || + !XAllocColor(win->display, + DefaultColormap(win->display, 0), + &win->border) || + !XAllocColor(win->display, + DefaultColormap(win->display, 0), + &win->textcolor) || + !XAllocColor(win->display, + DefaultColormap(win->display, 0), + &win->textback) || + !XAllocColor(win->display, + DefaultColormap(win->display, 0), + &win->errortext) || + !XAllocColor(win->display, + DefaultColormap(win->display, 0), + &win->playertext) || + !XAllocColor(win->display, + DefaultColormap(win->display, 0), + &win->cursorcolor)) + fprintf(stderr, "Can't get color...\n"); + } + + /* Get fonts... */ + win->small = XLoadQueryFont(win->display,SMALL_FONT); + win->medium = XLoadQueryFont(win->display,MEDIUM_FONT); + win->large = XLoadQueryFont(win->display,LARGE_FONT); + + /* Create the windows... */ + + win->basewin = + XCreateSimpleWindow(win->display,DefaultRootWindow(win->display), + BASE_XPOS, BASE_YPOS, + BASE_WIDTH, BASE_HEIGHT, 0, + BlackPixel(win->display, 0), + WhitePixel(win->display, 0)); + win->boardwin = XCreateSimpleWindow(win->display,win->basewin, + BOARD_XPOS, BOARD_YPOS, + BOARD_WIDTH, BOARD_HEIGHT, + BORDER_WIDTH, + win->border.pixel, + WhitePixel(win->display, 0)); + win->recwin = XCreateSimpleWindow(win->display,win->basewin, + RECORD_XPOS, RECORD_YPOS, + RECORD_WIDTH, RECORD_HEIGHT, + BORDER_WIDTH, win->border.pixel, + win->textback.pixel); + win->jailwin = XCreateSimpleWindow(win->display,win->basewin, + JAIL_XPOS, JAIL_YPOS, + JAIL_WIDTH, JAIL_HEIGHT, + BORDER_WIDTH, + win->border.pixel, + win->textback.pixel); + win->wclockwin = XCreateSimpleWindow(win->display,win->basewin, + WCLOCK_XPOS, WCLOCK_YPOS, + CLOCK_WIDTH, CLOCK_HEIGHT, + BORDER_WIDTH, win->border.pixel, + win->textback.pixel); + win->bclockwin = XCreateSimpleWindow(win->display,win->basewin, + BCLOCK_XPOS, BCLOCK_YPOS, + CLOCK_WIDTH, CLOCK_HEIGHT, + BORDER_WIDTH, win->border.pixel, + win->textback.pixel); + win->messagewin = XCreateSimpleWindow(win->display,win->basewin, + MESS_XPOS, MESS_YPOS, + MESS_WIDTH, MESS_HEIGHT, + BORDER_WIDTH, win->border.pixel, + win->textback.pixel); + win->buttonwin = XCreateSimpleWindow(win->display,win->basewin, + BUTTON_XPOS, BUTTON_YPOS, + BUTTON_WIDTH, BUTTON_HEIGHT, + BORDER_WIDTH, win->border.pixel, + win->textback.pixel); + + /* Let's define an icon... */ + win->iconpixmap = XCreatePixmapFromBitmapData(win->display, + win->basewin, icon_bits, + icon_width, icon_height, + win->blacksquare.pixel, + win->whitesquare.pixel, + 1); + + bm = XCreateBitmapFromData(win->display, + win->basewin, xchess_bits, + xchess_width, xchess_height); + bmask = XCreateBitmapFromData(win->display, + win->basewin, xchess_mask_bits, + xchess_width, xchess_height); + cur = XCreatePixmapCursor(win->display, bm, bmask, + &win->cursorcolor, + &WhitePixel(win->display, 0), + xchess_x_hot, xchess_y_hot); + XFreePixmap(win->display, bm); + XFreePixmap(win->display, bmask); + + XDefineCursor(win->display,win->basewin, cur); + + XMapSubwindows(win->display,win->basewin); + XMapRaised(win->display,win->basewin); + + XSelectInput(win->display,win->basewin, KeyPressMask); + XSelectInput(win->display,win->boardwin, + ButtonPressMask | ButtonReleaseMask | ExposureMask); + XSelectInput(win->display,win->recwin, + ButtonReleaseMask | ExposureMask); + XSelectInput(win->display,win->jailwin, ExposureMask); + XSelectInput(win->display,win->wclockwin, ExposureMask); + XSelectInput(win->display,win->bclockwin, ExposureMask); + XSelectInput(win->display,win->messagewin, + ButtonReleaseMask | ExposureMask); + XSelectInput(win->display,win->buttonwin, + ButtonPressMask | ExposureMask); + + message_init(win); + record_init(win); + button_draw(win); + jail_init(win); + clock_init(win, WHITE); + clock_init(win, BLACK); + if (timeunit) { + if (timeunit > 1800) + sprintf(buf, "%d moves every %.2lg hours.\n", + movesperunit, ((double) timeunit) / 3600); + else if (timeunit > 30) + sprintf(buf, "%d moves every %.2lg minutes.\n", + movesperunit, ((double) timeunit) / 60); + else + sprintf(buf, "%d moves every %d seconds.\n", + movesperunit, timeunit); + message_add(win, buf, false); + } + + return (true); +} + +static void +drawgrid(win) + windata *win; +{ + int i; + XGCValues gc; + + gc.function = GXcopy; + gc.plane_mask = AllPlanes; + gc.foreground = win->border.pixel; + gc.line_width = 0; + gc.line_style = LineSolid; + + XChangeGC(win->display, + DefaultGC(win->display, 0), + GCFunction | GCPlaneMask | GCForeground | + GCLineWidth | GCLineStyle, &gc); + + /* Draw the lines... horizontal, */ + for (i = 1; i < SIZE; i++) + XDrawLine(win->display, win->boardwin, + DefaultGC(win->display, 0), 0, + i * (SQUARE_WIDTH + BORDER_WIDTH) - + BORDER_WIDTH / 2, + SIZE * (SQUARE_WIDTH + BORDER_WIDTH), + i * (SQUARE_WIDTH + BORDER_WIDTH) - + BORDER_WIDTH / 2); + + /* and vertical... */ + for (i = 1; i < SIZE; i++) + XDrawLine(win->display, win->boardwin, + DefaultGC(win->display, 0), + i * (SQUARE_WIDTH + BORDER_WIDTH) - + BORDER_WIDTH / 2, 0, + i * (SQUARE_WIDTH + BORDER_WIDTH) - + BORDER_WIDTH / 2, + SIZE * (SQUARE_WIDTH + BORDER_WIDTH)); + return; +} + +void +win_restart() +{ + win1->flipped = false; + win_redraw(win1, (XEvent *) NULL); + if (!oneboard) { + win2->flipped = true; + win_redraw(win2, (XEvent *) NULL); + } + return; +} + +static void +icon_refresh(win) + windata *win; +{ + XCopyArea(win->display, win->iconpixmap, win->icon, + DefaultGC(win->display, 0), + 0, 0, icon_width, icon_height, 0, 0); + return; +} + diff --git a/gnu/games/chess/Xchess/xchess.1 b/gnu/games/chess/Xchess/xchess.1 new file mode 100644 index 000000000000..e6875136100c --- /dev/null +++ b/gnu/games/chess/Xchess/xchess.1 @@ -0,0 +1,217 @@ + +.TH XCHESS 1 "14 Nov 1986" "X Version 10" +.SH NAME +xchess \- X chess display +.SH SYNOPSIS +.B xchess +[ option ... ] [ white-display ] [ black-display ] +.SH DESCRIPTION +.PP +.B xchess +is a chess display program which allows players to play a game on either +one or two displays, or play a chess-playing program. It uses the +.B X +window system. If one or no display names are given, it will open up one +window and both black and white at the same board. If two displays are +given, +.B xchess +will accept moves from each player in his turn. Black's board will be drawn +with his pieces at the bottom. +.PP +.B xchess +will not allow a player to make an illegal move. It accepts all legal moves, +including castling and pawn capture \fIen passant\fR. +.SH OPTIONS +.TP 8 +.B -d +Turn on debugging. +.TP 8 +.B -f record-file +Use \fBrecord-file\fR for saving the game when the \fBSave\fR button is +selected, or if the \fB-s\fR flag is given. The default is "xchess.game". +.TP 8 +.B -r saved-game +Start with the position at the end of the saved game in the named file. +This file may be the result of the \fBSave\fR command, and may be in +either English or International format. When reading moves, one move +it made per second. +.TP 8 +.B -q +Don't pause for a second every time a move is made when a game is being +restored. +.TP 8 +.B -v +Whenever a piece is moved, outline the path with a "lightning bolt". +This option and the \fB-n\fR option are useful if you don't want to miss +an opponent's move when he makes it. +.TP 8 +.B -i +Use International format for recording moves (squares numbered 1-8, a-h) +as opposed to English (e.g, \fIp/k4xp/q5\fR). +.TP 8 +.B -t moves/timeunit +Allows \fBtimeunit\fR seconds for every \fBmoves\fR moves. If either player +exceeds this allowance both recieve a message saying informing them of +this fact. +.TP 8 +.B -c +Play the computer. +.B xchess +will start up a chess-playing program (currently the only one it knows +how to talk to is \fBGNU Chess\fR). +.TP 8 +.B -p program +The name of the program to use if the \fB-c\fR option is given. The +default is "/usr/public/gnuchess". Note that \fBgnuchess\fR must be +compiled with the \fIcompat\fR flag (in the file "main.c") set to 1. +.TP 8 +.B -b +If the \fB-c\fR flag was given, have the computer play white. +.TP 8 +.B -bnw +If the display has more than one display plane (i.e, is color), pretend +it's black and white. +.TP 8 +.B -s +Save the moves in the record file as they are made. This is useful if +you don't want your game to be lost when \fBxchess\fR core dumps. +.TP 8 +.B -n +Be noisy \- beep after every move is made. +.TP 8 +.B -h host +Run GNU Chess on the specified \fBhost\fR. +.TP 8 +.B -R +Randomly chose who plays white and who plays black, if two displays are +given. +.SH CONTROLS +.PP +The window is divided up into several sub-windows. The pieces are moved by +pushing down any mouse button on top of the piece, moving to the destination +square, and releasing it. Castling is done by moving the king to the +right square. If you push down on a piece and then let the button +up without moving it, you must move that piece. ("Touch it, move it.") +.PP +The progress of the game is listed in the "Game Record" window. Error +messages and such things are printed in the "Message" window. Both these +windows have scroll bars that you can use to move around. +There are also windows for clocks and for a record of the pieces captured. +.PP +If you type any keys in the window, the text will go into the message +window of both players. This provides a simple communication facility. +.PP +There are 9 buttons in the control window. They are as follows: +.TP 8 +.B Draw +Both players must push this button to agree on a draw (just one is ok +if only one display is being used). +.TP 8 +.B Resign +The player whose turn it is to move resigns. +.TP 8 +.B Reset +Start over from the beginning. +.TP 8 +.B Back +Retract a move. If two displays are being used the other player will be +asked to confirm this. +.TP 8 +.B Fwd +This will re-play the most recently retracted move. This button in conjunction +with \fBBack\fR is useful for "scrolling around" in a saved game. +.TP 8 +.B Save +Save the game in the record file. +.TP 8 +.B Flip +Rotate the board so that Black will have his pieces at the bottom. +.TP 8 +.B Switch +Change the mapping of boards to players. +.TP 8 +.B Pause +This button has two functions. When a game is being restored, pieces will +be moved once a second. Hitting \fBPause\fR will stop this process, and +hitting it again will restart it. During the time that it is stopped no +other action can be made except restarting it. While a game is being played, +\fBPause\fR will stop the clock and restart it. +.SH DEFAULTS +.PP +\fBxchess\fR uses the following \fI.Xdefaults\fR: +.TP 8 +.B Noisy +The -n flag. +.TP 8 +.B SaveMoves +The -s flag. +.TP 8 +.B Algebraic +The -i flag. +.TP 8 +.B BlackAndWhite +The -bnw flag. +.TP 8 +.B QuickRestore +The -q flag. +.TP 8 +.B Flash +The -v flag. +.TP 8 +.B NumFlashes +How many times to flash the move. The default is 5. +.TP 8 +.B FlashWidth +How big to make the lightning bolt. The default is 10 pixels. +.TP 8 +.B ProgName +The -p option. This may also be changed in the Makefile (-DDEF_PROG_NAME). +.TP 8 +.B ProgHost +The -h option. +.TP 8 +.B RecordFile +The -f option. +.TP 8 +.B BlackPiece +The color of the black pieces. +.TP 8 +.B WhitePiece +The color of the white pieces. +.TP 8 +.B BorderColor +The color of the borders. +.TP 8 +.B BlackSquare +The color of the black squares. +.TP 8 +.B WhiteSquare +The color of the white squares. +.TP 8 +.B TextColor +The color of routine messages and the move record text. +.TP 8 +.B ErrorText +The color of error messages. +.TP 8 +.B PlayerText +The color of player-entered text. +.TP 8 +.B TextBack +The background color for the two text windows. +.TP 8 +.B CursorColor +The color of the mouse and the text cursors. +.SH "SEE ALSO" +X(8), gnuchess(1), chess(5) +.SH AUTHOR +Wayne A. Christopher (faustus@ic.berkeley.edu) +.SH BUGS +.PP +Checkmate and stalemate are not detected, so the appropriate player must resign +or agree to a draw respectively. +.PP +\fBSwitch\fR doesn't work. +.PP +If you are playing \fBgnuchess\fR, and you select Undo a few times so that it +is \fBgnuchess\fR's turn to move, it won't do anything. diff --git a/gnu/games/chess/Xchess/xchess.c b/gnu/games/chess/Xchess/xchess.c new file mode 100644 index 000000000000..7a241502fd08 --- /dev/null +++ b/gnu/games/chess/Xchess/xchess.c @@ -0,0 +1,205 @@ + +/* This file contains code for X-CHESS. + Copyright (C) 1986 Free Software Foundation, Inc. + +This file is part of X-CHESS. + +X-CHESS is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY. No author or distributor +accepts responsibility to anyone for the consequences of using it +or for whether it serves any particular purpose or works at all, +unless he says so in writing. Refer to the X-CHESS General Public +License for full details. + +Everyone is granted permission to copy, modify and redistribute +X-CHESS, but only under the conditions described in the +X-CHESS General Public License. A copy of this license is +supposed to have been given to you along with X-CHESS so you +can know your rights and responsibilities. It should be in a +file named COPYING. Among other things, the copyright notice +and this notice must be preserved on all copies. */ + + +/* RCS Info: $Revision: 1.1.1.1 $ on $Date: 1993/06/12 14:41:09 $ + * $Source: /home/cvs/386BSD/src/gnu/games/chess/Xchess/xchess.c,v $ + * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group + * Permission is granted to do anything with this code except sell it + * or remove this message. + */ + +#define USAGE "xchess [ -d ] [ -f recordfile ] [ -r savedfile ] [ -i ]\n\ +\t[ -t moves/timeunit ] [ -c ] [ -p program ] [ -b ] [ -bnw ] [ -s ]\n\ +\t[ -n ] [ -h host ] [ -v ] [ -R ] [ whitedisplay ] [ blackdisplay ]" + +#include <signal.h> +#include "xchess.h" + +bool debug = false; +bool oneboard = false; +bool bnwflag = false; +bool progflag = false; +bool blackflag = false; +bool quickflag = false; + +char *progname = DEF_PROGRAM; +char *proghost = NULL; +char *piecenames[] = { "pawn", "rook", "knight", "bishop", "queen", "king" } ; +char *colornames[] = { "white", "black", "none" } ; +char *movetypenames[] = { "move", "qcastle", "kcastle", "capture" } ; +char *dispname1 = NULL, *dispname2 = NULL; + +char *black_piece_color = BLACK_PIECE_COLOR; +char *white_piece_color = WHITE_PIECE_COLOR; +char *black_square_color = BLACK_SQUARE_COLOR; +char *white_square_color = WHITE_SQUARE_COLOR; +char *border_color = BORDER_COLOR; +char *text_color = TEXT_COLOR; +char *text_back = TEXT_BACK; +char *error_text = ERROR_TEXT; +char *player_text = PLAYER_TEXT; +char *cursor_color = CURSOR_COLOR; + +int num_flashes = NUM_FLASHES; +int flash_size = FLASH_SIZE; +char *program; +char *recfile = NULL; + +#ifdef notdef +/* + * Serves no purpose. + */ +die () { +fprintf(stderr, "child proc changed status?!\n"); +} +#endif + +void +main(ac, av) + char **av; +{ + bool randflag = false; + move *m; + char *s; + + program = av[0]; + +#ifdef notdef + signal(SIGCHLD, die); +#endif + + /* Process args. */ + av++; ac--; + while (ac > 0 && **av == '-') { + if (eq(*av, "-d")) { + debug = true; + } else if (eq(*av, "-f")) { + av++; ac--; + if (*av) + record_file = *av; + else + goto usage; + } else if (eq(*av, "-r")) { + av++; ac--; + if (*av) + recfile = *av; + else + goto usage; + } else if (eq(*av, "-i")) { + record_english = false; + } else if (eq(*av, "-R")) { + randflag = true; + } else if (eq(*av, "-v")) { + win_flashmove = true; + } else if (eq(*av, "-q")) { + quickflag = true; + } else if (eq(*av, "-t")) { + av++; ac--; + if (*av) { + movesperunit = atoi(*av); + if (s = index(*av, '/')) + timeunit = atoi(s + 1) * 60; + else + timeunit = 60; + } else + goto usage; + } else if (eq(*av, "-p")) { + av++; ac--; + if (*av) + progname = *av; + else + goto usage; + } else if (eq(*av, "-h")) { + av++; ac--; + if (*av) + proghost = *av; + else + goto usage; + } else if (eq(*av, "-b")) { + blackflag = true; + } else if (eq(*av, "-c")) { + progflag = true; + } else if (eq(*av, "-bnw")) { + bnwflag = true; + } else if (eq(*av, "-s")) { + saveflag = true; + } else if (eq(*av, "-n")) { + noisyflag = true; + } else + goto usage; + av++; ac--; + } + if (ac > 0) + dispname1 = av[0]; + if (ac > 1) + dispname2 = av[1]; + if (ac > 2) + goto usage; + + if (!dispname2) + oneboard = true; + + srandom(getpid()); + + if (!oneboard && randflag && (random() % 2)) { + s = dispname1; + dispname1 = dispname2; + dispname2 = s; + } + + if (!dispname1) + dispname1 = getenv("DISPLAY"); + + /* Set up the board. */ + board_setup(); + + /* Create the windows. */ + win_setup(dispname1, dispname2); + + board_drawall(); + + /* Start the program if necessary. */ + if (progflag) + if (!program_init(progname)) + exit(1); + + if (recfile) + load_game(recfile); + + /* Go into a loop of prompting players alternately for moves, checking + * them, and updating things. + */ + for (;;) { + win_process(false); + clock_update(); + if (progflag && ((!blackflag && (nexttomove == BLACK)) || + (blackflag && (nexttomove == WHITE)))) { + m = program_get(); + if (m) + prog_move(m); + } + } + +usage: fprintf(stderr, "Usage: %s\n", USAGE); + exit(1); +} + diff --git a/gnu/games/chess/Xchess/xchess.c.150 b/gnu/games/chess/Xchess/xchess.c.150 new file mode 100644 index 000000000000..6a460c305c02 --- /dev/null +++ b/gnu/games/chess/Xchess/xchess.c.150 @@ -0,0 +1,197 @@ + +/* This file contains code for X-CHESS. + Copyright (C) 1986 Free Software Foundation, Inc. + +This file is part of X-CHESS. + +X-CHESS is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY. No author or distributor +accepts responsibility to anyone for the consequences of using it +or for whether it serves any particular purpose or works at all, +unless he says so in writing. Refer to the X-CHESS General Public +License for full details. + +Everyone is granted permission to copy, modify and redistribute +X-CHESS, but only under the conditions described in the +X-CHESS General Public License. A copy of this license is +supposed to have been given to you along with X-CHESS so you +can know your rights and responsibilities. It should be in a +file named COPYING. Among other things, the copyright notice +and this notice must be preserved on all copies. */ + + +/* RCS Info: $Revision: 1.1.1.1 $ on $Date: 1993/06/12 14:41:20 $ + * $Source: /home/cvs/386BSD/src/gnu/games/chess/Xchess/xchess.c.150,v $ + * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group + * Permission is granted to do anything with this code except sell it + * or remove this message. + */ + +#define USAGE "xchess [ -d ] [ -f recordfile ] [ -r savedfile ] [ -i ]\n\ +\t[ -t moves/timeunit ] [ -c ] [ -p program ] [ -b ] [ -bnw ] [ -s ]\n\ +\t[ -n ] [ -h host ] [ -v ] [ -R ] [ whitedisplay ] [ blackdisplay ]" + +#include <signal.h> +#include "xchess.h" + +bool debug = false; +bool oneboard = false; +bool bnwflag = false; +bool progflag = false; +bool blackflag = false; +bool quickflag = false; + +char *progname = DEF_PROGRAM; +char *proghost = NULL; +char *piecenames[] = { "pawn", "rook", "knight", "bishop", "queen", "king" } ; +char *colornames[] = { "white", "black", "none" } ; +char *movetypenames[] = { "move", "qcastle", "kcastle", "capture" } ; +char *dispname1 = NULL, *dispname2 = NULL; + +char *black_piece_color = BLACK_PIECE_COLOR; +char *white_piece_color = WHITE_PIECE_COLOR; +char *black_square_color = BLACK_SQUARE_COLOR; +char *white_square_color = WHITE_SQUARE_COLOR; +char *border_color = BORDER_COLOR; +char *text_color = TEXT_COLOR; +char *text_back = TEXT_BACK; +char *error_text = ERROR_TEXT; +char *player_text = PLAYER_TEXT; +char *cursor_color = CURSOR_COLOR; + +int num_flashes = NUM_FLASHES; +int flash_size = FLASH_SIZE; +char *program; +char *recfile = NULL; + +die () { +fprintf(stderr, "child proc changed status?!\n"); +} + +void +main(ac, av) + char **av; +{ + bool randflag = false; + move *m; + char *s; + + program = av[0]; + + signal(SIGCHLD, die); + /* Process args. */ + av++; ac--; + while (ac > 0 && **av == '-') { + if (eq(*av, "-d")) { + debug = true; + } else if (eq(*av, "-f")) { + av++; ac--; + if (*av) + record_file = *av; + else + goto usage; + } else if (eq(*av, "-r")) { + av++; ac--; + if (*av) + recfile = *av; + else + goto usage; + } else if (eq(*av, "-i")) { + record_english = false; + } else if (eq(*av, "-R")) { + randflag = true; + } else if (eq(*av, "-v")) { + win_flashmove = true; + } else if (eq(*av, "-q")) { + quickflag = true; + } else if (eq(*av, "-t")) { + av++; ac--; + if (*av) { + movesperunit = atoi(*av); + if (s = index(*av, '/')) + timeunit = atoi(s + 1) * 60; + else + timeunit = 60; + } else + goto usage; + } else if (eq(*av, "-p")) { + av++; ac--; + if (*av) + progname = *av; + else + goto usage; + } else if (eq(*av, "-h")) { + av++; ac--; + if (*av) + proghost = *av; + else + goto usage; + } else if (eq(*av, "-b")) { + blackflag = true; + } else if (eq(*av, "-c")) { + progflag = true; + } else if (eq(*av, "-bnw")) { + bnwflag = true; + } else if (eq(*av, "-s")) { + saveflag = true; + } else if (eq(*av, "-n")) { + noisyflag = true; + } else + goto usage; + av++; ac--; + } + if (ac > 0) + dispname1 = av[0]; + if (ac > 1) + dispname2 = av[1]; + if (ac > 2) + goto usage; + + if (!dispname2) + oneboard = true; + + srandom(getpid()); + + if (!oneboard && randflag && (random() % 2)) { + s = dispname1; + dispname1 = dispname2; + dispname2 = s; + } + + if (!dispname1) + dispname1 = getenv("DISPLAY"); + + /* Set up the board. */ + board_setup(); + + /* Create the windows. */ + win_setup(dispname1, dispname2); + + board_drawall(); + + /* Start the program if necessary. */ + if (progflag) + if (!program_init(progname)) + exit(1); + + if (recfile) + load_game(recfile); + + /* Go into a loop of prompting players alternately for moves, checking + * them, and updating things. + */ + for (;;) { + win_process(false); + clock_update(); + if (progflag && ((!blackflag && (nexttomove == BLACK)) || + (blackflag && (nexttomove == WHITE)))) { + m = program_get(); + if (m) + prog_move(m); + } + } + +usage: fprintf(stderr, "Usage: %s\n", USAGE); + exit(1); +} + diff --git a/gnu/games/chess/Xchess/xchess.cur b/gnu/games/chess/Xchess/xchess.cur new file mode 100644 index 000000000000..ef3750dbdd7f --- /dev/null +++ b/gnu/games/chess/Xchess/xchess.cur @@ -0,0 +1,9 @@ + +#define xchess_width 16 +#define xchess_height 16 +#define xchess_x_hot 9 +#define xchess_y_hot 8 +static char xchess_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0xf8, 0x00, 0xfe, 0x80, 0xff, + 0xc0, 0xff, 0x60, 0xff, 0xb0, 0xfd, 0xd8, 0x66, 0x6c, 0x3b, 0x76, 0x1d, + 0x98, 0x1d, 0xcc, 0x0c, 0x60, 0x00, 0x00, 0x00}; diff --git a/gnu/games/chess/Xchess/xchess.game b/gnu/games/chess/Xchess/xchess.game new file mode 100644 index 000000000000..2302334080c7 --- /dev/null +++ b/gnu/games/chess/Xchess/xchess.game @@ -0,0 +1,8 @@ + +X Chess -- Sun Sep 18 18:01:17 EDT 1988 + Game played on pitcairn:0 + english + 1. P/kb2-kb4 P/k2-k3 + 2. P/k2-k4 +Draw agreed. +Time: white: 6s, black: 43s diff --git a/gnu/games/chess/Xchess/xchess.h b/gnu/games/chess/Xchess/xchess.h new file mode 100644 index 000000000000..05b3acc63c3a --- /dev/null +++ b/gnu/games/chess/Xchess/xchess.h @@ -0,0 +1,301 @@ + +/* This file contains code for X-CHESS. + Copyright (C) 1986 Free Software Foundation, Inc. + +This file is part of X-CHESS. + +X-CHESS is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY. No author or distributor +accepts responsibility to anyone for the consequences of using it +or for whether it serves any particular purpose or works at all, +unless he says so in writing. Refer to the X-CHESS General Public +License for full details. + +Everyone is granted permission to copy, modify and redistribute +X-CHESS, but only under the conditions described in the +X-CHESS General Public License. A copy of this license is +supposed to have been given to you along with X-CHESS so you +can know your rights and responsibilities. It should be in a +file named COPYING. Among other things, the copyright notice +and this notice must be preserved on all copies. */ + + +/* RCS Info: $Revision: 1.1.1.1 $ on $Date: 1993/06/12 14:41:15 $ + * $Source: /home/cvs/386BSD/src/gnu/games/chess/Xchess/xchess.h,v $ + * Copyright (c) 1986 Wayne A. Christopher, U. C. Berkeley CAD Group + * Permission is granted to do anything with this code except sell it + * or remove this message. + * + * Definitions for the X chess program. + */ + +#include "std.h" +#include <X11/Xlib.h> +#include "scrollText/scrollText.h" + +#define SIZE 8 + +typedef enum piecetype { PAWN, ROOK, KNIGHT, BISHOP, QUEEN, KING } piecetype; +typedef enum movetype { MOVE, QCASTLE, KCASTLE, CAPTURE } movetype; +typedef enum color { WHITE, BLACK, NONE } color; + +typedef struct piece { + enum piecetype type; + enum color color; +} piece; + +/* The board has y=0 and black at the top... This probably isn't the best + * place to keep track of who can castle, but it's part of the game state... + */ + +typedef struct board { + piece square[SIZE][SIZE]; + bool white_cant_castle_k; + bool white_cant_castle_q; + bool black_cant_castle_k; + bool black_cant_castle_q; +} board; + +typedef struct move { + movetype type; + piece piece; + piece taken; + int fromx, fromy; + int tox, toy; + struct move *next; + bool enpassant; + bool check; +} move; + +#define iswhite(win, i, j) (!(((i) + (j)) % 2)) + +/* Stuff for the display. */ + +typedef struct windata { + Display *display; + Window basewin; + Window boardwin; + Window recwin; + Window wclockwin; + Window bclockwin; + Window messagewin; + Window buttonwin; + Window jailwin; + Window icon; + Pixmap iconpixmap; + XColor blackpiece; + XColor whitepiece; + XColor blacksquare; + XColor whitesquare; + XColor border; + XColor textcolor; + XColor textback; + XColor errortext; + XColor playertext; + XColor cursorcolor; + XFontStruct *small; + XFontStruct *medium; + XFontStruct *large; + bool bnw; + color color; + bool flipped; + double whitehands[3]; + double blackhands[3]; + char *txtassoc; +} windata; + +#define SMALL_FONT "6x10" +#define MEDIUM_FONT "8x13" +#define LARGE_FONT "9x15" +#define JAIL_FONT "6x10" + +#define SQUARE_WIDTH 80 +#define SQUARE_HEIGHT 80 + +#define BORDER_WIDTH 3 + +#define BOARD_WIDTH 8 * SQUARE_WIDTH + 7 * BORDER_WIDTH +#define BOARD_HEIGHT 8 * SQUARE_HEIGHT + 7 * BORDER_WIDTH +#define BOARD_XPOS 0 +#define BOARD_YPOS 0 + +#define RECORD_WIDTH 265 /* 40 chars * 6 pixels / character. */ +#define RECORD_HEIGHT 433 +#define RECORD_XPOS BOARD_WIDTH + BORDER_WIDTH +#define RECORD_YPOS 0 + +#define JAIL_WIDTH RECORD_WIDTH +#define JAIL_HEIGHT 163 +#define JAIL_XPOS RECORD_XPOS +#define JAIL_YPOS RECORD_YPOS + RECORD_HEIGHT + BORDER_WIDTH + +#define CLOCK_WIDTH 131 +#define CLOCK_HEIGHT 131 + BORDER_WIDTH + 20 +#define WCLOCK_XPOS RECORD_XPOS +#define WCLOCK_YPOS RECORD_HEIGHT + JAIL_HEIGHT + BORDER_WIDTH * 2 +#define BCLOCK_XPOS WCLOCK_XPOS + CLOCK_WIDTH + BORDER_WIDTH +#define BCLOCK_YPOS WCLOCK_YPOS + +#define MESS_WIDTH 329 +#define MESS_HEIGHT 92 +#define MESS_XPOS 0 +#define MESS_YPOS BOARD_HEIGHT + BORDER_WIDTH + +#define BUTTON_WIDTH MESS_WIDTH +#define BUTTON_HEIGHT MESS_HEIGHT +#define BUTTON_XPOS MESS_WIDTH + BORDER_WIDTH +#define BUTTON_YPOS MESS_YPOS + +#define BASE_WIDTH BOARD_WIDTH + RECORD_WIDTH + BORDER_WIDTH * 3 +#define BASE_HEIGHT BOARD_HEIGHT + MESS_HEIGHT + BORDER_WIDTH * 3 + +#define BASE_XPOS 50 +#define BASE_YPOS 50 + +#define BLACK_PIECE_COLOR "#202020" +#define WHITE_PIECE_COLOR "#FFFFCC" +#define BLACK_SQUARE_COLOR "#77A26D" +#define WHITE_SQUARE_COLOR "#C8C365" +#define BORDER_COLOR "#902E39" +#define TEXT_COLOR "#006D6D" +#define TEXT_BACK "#FFFFDD" +#define ERROR_TEXT "Red" +#define PLAYER_TEXT "Blue" +#define CURSOR_COLOR "#FF606F" + +#define DEF_RECORD_FILE "xchess.game" + +#define NUM_FLASHES 5 +#define FLASH_SIZE 10 + +/* xchess.c */ + +extern void main(); +extern bool debug; +extern char *progname; +extern char *proghost; +extern char *piecenames[]; +extern char *colornames[]; +extern char *movetypenames[]; +extern char *dispname1, *dispname2; +extern bool oneboard; +extern bool bnwflag; +extern bool progflag; +extern bool blackflag; +extern bool quickflag; +extern int num_flashes; +extern int flash_size; +extern char *black_piece_color; +extern char *white_piece_color; +extern char *black_square_color; +extern char *white_square_color; +extern char *border_color; +extern char *text_color; +extern char *text_back; +extern char *error_text; +extern char *player_text; +extern char *cursor_color; + +/* board.c */ + +extern void board_setup(); +extern void board_drawall(); +extern void board_move(); +extern board *chessboard; +extern void board_init(); + +/* window.c */ + +extern bool win_setup(); +extern void win_redraw(); +extern void win_restart(); +extern void win_drawboard(); +extern void win_drawpiece(); +extern void win_erasepiece(); +extern void win_process(); +extern void win_flash(); +extern windata *win1, *win2; +extern bool win_flashmove; + +/* control.c */ + +extern void button_pressed(); +extern void button_released(); +extern void move_piece(); +extern void prog_move(); +extern move *moves; +extern move *foremoves; +extern color nexttomove; +extern void replay(); +extern void forward(); +extern void cleanup(); +extern void restart(); +extern bool noisyflag; + +/* valid.c */ + +extern bool valid_move(); + +/* record.c */ + +extern void record_move(); +extern void record_reset(); +extern void record_save(); +extern void record_back(); +extern void record_init(); +extern void record_end(); +extern bool record_english; +extern char *record_file; +extern int movenum; +extern bool saveflag; + +/* message.c */ + +extern void message_init(); +extern void message_add(); +extern void message_send(); + +/* clock.c */ + +extern void clock_init(); +extern void clock_draw(); +extern void clock_update(); +extern void clock_switch(); +extern bool clock_started; +extern int movesperunit; +extern int timeunit; +extern int whiteseconds; +extern int blackseconds; + +/* button.c */ + +extern void button_draw(); +extern void button_service(); + +/* jail.c */ + +extern void jail_init(); +extern void jail_draw(); +extern void jail_add(); +extern void jail_remove(); + +/* program.c */ +extern bool program_init(); +extern void program_end(); +extern void program_send(); +extern void program_undo(); +extern move *program_get(); + +/* parse.c */ + +extern void load_game(); +extern move *parse_file(); +extern move *parse_move(); +extern move *parse_imove(); +extern bool loading_flag; +extern bool loading_paused; + +/* popup.c */ + +extern bool pop_question(); + diff --git a/gnu/games/chess/Xchess/xchess.icon b/gnu/games/chess/Xchess/xchess.icon new file mode 100644 index 000000000000..78c68f1ba46b --- /dev/null +++ b/gnu/games/chess/Xchess/xchess.icon @@ -0,0 +1,28 @@ + +#define icon_width 48 +#define icon_height 48 +static char icon_bits[] = { + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x80, + 0xc1, 0xff, 0xff, 0xff, 0xff, 0x83, 0x41, 0x00, 0x00, 0x00, 0x00, 0x82, + 0x41, 0xf0, 0xf0, 0xf0, 0xf0, 0x82, 0x41, 0xf0, 0xf0, 0xf0, 0xf0, 0x82, + 0x41, 0xf0, 0xf0, 0xf0, 0xf0, 0x82, 0x41, 0xf0, 0xf0, 0xf0, 0xf0, 0x82, + 0x41, 0x0f, 0x0f, 0x0f, 0x0f, 0x82, 0x41, 0x0f, 0x0f, 0x0f, 0x0f, 0x82, + 0x41, 0x0f, 0x0f, 0x0f, 0x0f, 0x82, 0x41, 0x0f, 0x0f, 0x0f, 0x0f, 0x82, + 0x41, 0xf0, 0xf0, 0xf0, 0xf0, 0x82, 0x41, 0xf0, 0xf0, 0xf0, 0xf0, 0x82, + 0x41, 0xf0, 0xf0, 0xf0, 0xf0, 0x82, 0x41, 0xf0, 0xf0, 0xf0, 0xf0, 0x82, + 0x41, 0x0f, 0x0f, 0x0f, 0x0f, 0x82, 0x41, 0x0f, 0x0f, 0x0f, 0x0f, 0x82, + 0x41, 0x0f, 0x0f, 0x0f, 0x0f, 0x82, 0x41, 0x0f, 0x0f, 0x0f, 0x0f, 0x82, + 0x41, 0xf0, 0xf0, 0xf0, 0xf0, 0x82, 0x41, 0xf0, 0xf0, 0xf0, 0xf0, 0x82, + 0x41, 0xf0, 0xf0, 0xf0, 0xf0, 0x82, 0x41, 0xf0, 0xf0, 0xf0, 0xf0, 0x82, + 0x41, 0x0f, 0x0f, 0x0f, 0x0f, 0x82, 0x41, 0x0f, 0x0f, 0x0f, 0x0f, 0x82, + 0x41, 0x0f, 0x0f, 0x0f, 0x0f, 0x82, 0x41, 0x0f, 0x0f, 0x0f, 0x0f, 0x82, + 0x41, 0xf0, 0xf0, 0xf0, 0xf0, 0x82, 0x41, 0xf0, 0xf0, 0xf0, 0xf0, 0x82, + 0x41, 0xf0, 0xf0, 0xf0, 0xf0, 0x82, 0x41, 0xf0, 0xf0, 0xf0, 0xf0, 0x82, + 0x41, 0x0f, 0x0f, 0x0f, 0x0f, 0x82, 0x41, 0x0f, 0x0f, 0x0f, 0x0f, 0x82, + 0x41, 0x0f, 0x0f, 0x0f, 0x0f, 0x82, 0x41, 0x0f, 0x0f, 0x0f, 0x0f, 0x82, + 0x41, 0x00, 0x00, 0x00, 0x00, 0x82, 0xc1, 0xff, 0xff, 0xff, 0xff, 0x83, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x80, 0x41, 0xc4, 0x89, 0x3c, 0xcf, 0x83, + 0x41, 0x24, 0x88, 0x04, 0x41, 0x80, 0x81, 0x22, 0x88, 0x04, 0x41, 0x80, + 0x01, 0x21, 0xf8, 0x1c, 0xcf, 0x83, 0x81, 0x22, 0x88, 0x04, 0x08, 0x82, + 0x41, 0x24, 0x88, 0x04, 0x08, 0x82, 0x41, 0xc4, 0x89, 0x3c, 0xcf, 0x83, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; diff --git a/gnu/games/chess/Xchess/xchess_mask.cur b/gnu/games/chess/Xchess/xchess_mask.cur new file mode 100644 index 000000000000..6408b7e0b915 --- /dev/null +++ b/gnu/games/chess/Xchess/xchess_mask.cur @@ -0,0 +1,7 @@ + +#define xchess_mask_width 16 +#define xchess_mask_height 16 +static char xchess_mask_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0xf8, 0x00, 0xfe, 0x80, 0xff, + 0xc0, 0xff, 0x60, 0xff, 0xb0, 0xfd, 0xd8, 0x66, 0x6c, 0x3b, 0x76, 0x1d, + 0x98, 0x1d, 0xcc, 0x0c, 0x60, 0x00, 0x00, 0x00}; |
