ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/xneko/xneko.c
Revision: 1
Committed: Tue Apr 28 20:35:01 2026 UTC (2 months, 3 weeks ago) by operz
Content type: text/plain
File size: 42293 byte(s)
Log Message:
Import data

File Contents

# Content
1 /*-
2 * Copyright (c) 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * %sccs.include.redist.c%
6 */
7
8 #ifndef lint
9 static char copyright[] =
10 "@(#) Copyright (c) 1991, 1993\n\
11 The Regents of the University of California. All rights reserved.\n";
12 #endif /* not lint */
13
14 #ifndef lint
15 static char sccsid[] = "@(#)xneko.c 8.1 (Berkeley) 05/31/93";
16 #endif /* not lint */
17
18 /*--------------------------------------------------------------
19 *
20 * xneko - X11 G-
21 *
22 * Original Writer: Masayuki Koba
23 * Programmed by Masayuki Koba, 1990
24 *
25 *--------------------------------------------------------------
26 *
27 *!!Introduction:
28 *
29 *!!!!K\@(#)xneko.c 8.1m%0%i%`$O Macintosh $N05/31/939%/%"%/%;%5%j!< "neko" $N
30 *!!F0:n$r X11 $G%^%M$?$b$N$G$9!#
31 *
32 *!!!!Macintosh "neko" $N=(0o$J05/31/936%$%s$K7I0U$rI=$7$D$D!"$3$N
33 *!!@(#)xneko.c 8.1m%0%i%`$r3'$5$s$KJ{$2$^$9!#
34 *
35 *--------------------------------------------------------------
36 *
37 *!!Special Thanks to
38 *
39 * toshi-w !D!!Macintosh neko $N>R2p<T
40 * shio-m !D!!!VX11 $N neko $,M_$7$$!*!W$H%?%@$r$3$M$??M
41 * disco !D!!X11 s.xneko.c/%K%+%k!&%"8.1P%$%6!<
42 *
43 * HOMY !D!!/usr/home/csrg/sccs/games/xneko/SCCS/s.xneko.c0;XE&<T
44 * BNS !D!!J#?t@(#)xneko.c 8.1l!<%sBP1~C%ADs6!<T
45 *
46 * "xneko" Presented by Masayuki Koba (masa-k).
47 *
48 *--------------------------------------------------------------
49 *
50 *!!Manifest:
51 *
52 *!!!!K\@(#)xneko.c 8.1m%0%i%`$O Public Domain Software $G$9!#E>:\!&2~NI$O
53 *!!<+M3$K9T$C$F2<$5$$!#
54 *
55 *!!!!$J$*!"86:n<T$O!"K\@(#)xneko.c 8.1m%0%i%`$r;HMQ$9$k$3$H$K$h$C$F@8$8$?
56 *!!>c32$dITMx1W$K$D$$$F$$$C$5$$@UG$$r;}$A$^$;$s!#
57 *
58 *--------------------------------------------------------------
59 *
60 *!!Bugs:
61 *
62 *!!!!!J#1!KX11 $N .Xdefaults $N@_Dj$r$^$k$C$-$jL5;k$7$F$$$^$9!#
63 *
64 *!!!!!J#2!KG-$NF0:n$,;~4V$HF14|$7$F$$$k$?$a!"%^%&%9$N0\F0>pJs
65 *!!!!!!!!$r%]!<%j%s%0$7$F$$$^$9!#=>$C$F!"%^%&%9$,A4$/F0:n$7$F
66 *!!!!!!!!$$$J$$;~$OL5BL$J%^%&%9:BI8FI$_<h$j$r9T$C$F$7$^$$$^$9!#
67 *
68 *!!!!!J#3!K%&%#%s8.1&$,%"%$%3%s2=$5$l$F$b!"$7$i$s$W$j$GIA2h$7
69 *!!!!!!!!$D$E$1$^$9!#$3$NItJ,$O!"8=:_$N%&%#%s8.1&$N>uBV$r@(#) xneko.c 8.1@(#)'
70 *!!!!!!!!70/$7$F!"%"%$%3%s2=$5$l$F$$$k;~$O40A4$K%$s%HBT$A
71 *!!!!!!!!$K$J$k$h$&$K=q$-JQ$($J$1$l$P$J$j$^$;$s!# ($=$s$J$3$H!"
72 *!!!!!!!!$G$-$k$N$+$J$!!#X10 $G$O$G$-$^$7$?$,!#)
73 *
74 *!!!!!J#4!K%j%5%$%:8e$N%&%#%s8.1&$,6KC<$K>.$5$/$J$C$?;~$NF0:n
75 *!!!!!!!!$OJ]>Z$G$-$^$;$s!#
76 *
77 *!!!!!J#5!KK\Mh$J$i$P3NJ]$7$?%&%#%s8.1&$d Pixmap $O@(#)xneko.c 8.1m%0%i%`
78 *!!!!!!!!=*N;;~$K2rJ|$9$kI,MW$,$"$j$^$9$,!"K\@(#)xneko.c 8.1m%0%i%`$O$=$N
79 *!!!!!!!!$X$s$r%5%\$C$F$*$j!"Hs>o$K$*9T57$,0-$/$J$C$F$$$^$9!#
80 *!!!!!!!!IaDL$O exit() ;~$K%7%9s.xneko.c`$,M>J,$J%j%=!<%9$r2rJ|$7$F
81 *!!!!!!!!$/$l$^$9$,!"#O#S$K/usr/home/csrg/sccs/games/xneko/SCCS/s.xneko.c0$,$"$k>l9g$O xneko $r2?EY$b5/
82 *!!!!!!!!F0$9$k$H!"$=$N$&$A%9%o82WNN0h$,ITB-$7$F$7$^$&$3$H$K
83 *!!!!!!!!$J$k$+$b$7$l$^$;$s!#
84 *
85 *!!!!!J#6!K;~4V$KF14|$7$FI,$:IA2h=hM}$r<B9T$9$k$?$a!"0BDj>uBV
86 *!!!!!!!!$G$b Idle 90 !A 95% $H$J$j!"%7%9s.xneko.c`#C#P#U$r 5 !A 10%
87 *!!!!!!!!Dx>CHq$7$^$9!#!Jxtachos $GD4$Y$^$7$?!#!K
88 *
89 *--------------------------------------------------------------
90 *
91 *!!System (Machine):
92 *
93 *!!!!K\@(#)xneko.c 8.1m%0%i%`$NF0:n$r3NG'$7$?%7%9s.xneko.c`9=@.$O0J2<$NDL$j!#
94 *
95 * !&NWS-1750!"NWS-1720 (NEWS)!"NWP-512D
96 * !!NEWS-OS 3.2a (UNIX 4.3BSD)!"X11 Release 2
97 *
98 * !&NWS-1750!"NWS-1720 (NEWS)!"NWP-512D
99 * !!NEWS-OS 3.3 (UNIX 4.3BSD)!"X11 Release 3
100 *
101 * !&Sun 3!"X11 Release 4
102 *
103 * !&LUNA!"X11 Release 3
104 *
105 * !&DECstation 3100!"ULTRIX!"X11
106 *
107 *--------------------------------------------------------------*/
108
109
110 #include <X11/Xlib.h>
111 #include <X11/Xutil.h>
112 #include <X11/keysym.h>
113
114 #include <stdio.h>
115
116 #include <stdlib.h>
117 #include <string.h>
118 #include <unistd.h>
119
120 #include <signal.h>
121 #include <math.h>
122 #include <sys/time.h>
123
124
125 #ifndef lint
126 static char
127 rcsid[] = "$Header: /afs/athena.mit.edu/user/j/jik/sipbsrc/src/xneko/RCS/xneko.c,v 1.2 90/09/01 23:40:01 jik Exp $";
128 static char WriterMessage[] = "xneko: Programmed by Masayuki Koba, 1990";
129 #endif
130
131
132 /*
133 * X11 G- 0C10/14/12^129W18:45:52!%$%k0lMw!'
134 *
135 * "icon.xbm" !D!!%"%$%3%s
136 * "cursor.xbm" !D!!%+!<%=%k
137 * "cursor_mask.xbm" !D!!%+!<%=%k!J%^%9%/!K
138 *
139 * "space.xbm" !D!!%9%Z!<%9
140 *
141 * "mati2.xbm" !D!!BT$A#2
142 * "jare2.xbm" !D!!$8$c$l#2
143 * "kaki1.xbm" !D!!A_$-#1
144 * "kaki2.xbm" !D!!A_$-#2
145 * "mati3.xbm" !D!!BT$A#3!J$"$/$S!K
146 * "sleep1.xbm" !D!!?2$k#1
147 * "sleep2.xbm" !D!!?2$k#2
148 *
149 * "awake.xbm" !D!!L\3P$a
150 *
151 * "up1.xbm" !D!!>e#1
152 * "up2.xbm" !D!!>e#2
153 * "down1.xbm" !D!!2<#1
154 * "down2.xbm" !D!!2<#2
155 * "left1.xbm" !D!!:8#1
156 * "left2.xbm" !D!!:8#2
157 * "right1.xbm" !D!!1&#1
158 * "right2.xbm" !D!!1&#2
159 * "upleft1.xbm" !D!!:8>e#1
160 * "upleft2.xbm" !D!!:8>e#2
161 * "upright1.xbm" !D!!1&>e#1
162 * "upright2.xbm" !D!!1&>e#2
163 * "dwleft1.xbm" !D!!:82<#1
164 * "dwleft2.xbm" !D!!:82<#2
165 * "dwright1.xbm" !D!!1&2<#1
166 * "dwright2.xbm" !D!!1&2<#2
167 *
168 * "utogi1.xbm" !D!!>eKa$.#1
169 * "utogi2.xbm" !D!!>eKa$.#2
170 * "dtogi1.xbm" !D!!2<Ka$.#1
171 * "dtogi2.xbm" !D!!2<Ka$.#2
172 * "ltogi1.xbm" !D!!:8Ka$.#1
173 * "ltogi2.xbm" !D!!:8Ka$.#2
174 * "rtogi1.xbm" !D!!1&Ka$.#1
175 * "rtogi2.xbm" !D!!1&Ka$.#2
176 *
177 * !!$3$l$i$N18:45:52!%$%k$O bitmap %3%^%s%I$GJT=82DG=$G$9!#
178 *
179 * (bitmap size "* 32x32 ... Macintosh ICON resource size.)
180 *
181 */
182
183
184 #include "bitmaps/icon.xbm"
185 #include "bitmaps/cursor.xbm"
186 #include "bitmaps/cursor_mask.xbm"
187
188 #include "bitmaps/space.xbm"
189
190 #include "bitmaps/mati2.xbm"
191 #include "bitmaps/jare2.xbm"
192 #include "bitmaps/kaki1.xbm"
193 #include "bitmaps/kaki2.xbm"
194 #include "bitmaps/mati3.xbm"
195 #include "bitmaps/sleep1.xbm"
196 #include "bitmaps/sleep2.xbm"
197
198 #include "bitmaps/awake.xbm"
199
200 #include "bitmaps/up1.xbm"
201 #include "bitmaps/up2.xbm"
202 #include "bitmaps/down1.xbm"
203 #include "bitmaps/down2.xbm"
204 #include "bitmaps/left1.xbm"
205 #include "bitmaps/left2.xbm"
206 #include "bitmaps/right1.xbm"
207 #include "bitmaps/right2.xbm"
208 #include "bitmaps/upright1.xbm"
209 #include "bitmaps/upright2.xbm"
210 #include "bitmaps/upleft1.xbm"
211 #include "bitmaps/upleft2.xbm"
212 #include "bitmaps/dwleft1.xbm"
213 #include "bitmaps/dwleft2.xbm"
214 #include "bitmaps/dwright1.xbm"
215 #include "bitmaps/dwright2.xbm"
216
217 #include "bitmaps/utogi1.xbm"
218 #include "bitmaps/utogi2.xbm"
219 #include "bitmaps/dtogi1.xbm"
220 #include "bitmaps/dtogi2.xbm"
221 #include "bitmaps/ltogi1.xbm"
222 #include "bitmaps/ltogi2.xbm"
223 #include "bitmaps/rtogi1.xbm"
224 #include "bitmaps/rtogi2.xbm"
225
226
227 /*
228 * Dj?tDj5A
229 */
230
231 #define BITMAP_WIDTH 32 /* #1%-%c%i%/%?$NI} (17:01:51/%;%k) */
232 #define BITMAP_HEIGHT 32 /* #1%-%c%i%/%?$N9b$5 (17:01:51/%;%k) */
233
234 #define WINDOW_WIDTH 320 /* %&%#%s8.1&$NI} (17:01:51/%;%k) */
235 #define WINDOW_HEIGHT 256 /* %&%#%s8.1&$N9b$5 (17:01:51/%;%k) */
236
237 #define DEFAULT_BORDER 2 /* %\!<%@!<%5%$%: */
238
239 #define DEFAULT_WIN_X 1 /* %&%#%s8.1&@8@.#X:BI8 */
240 #define DEFAULT_WIN_Y 1 /* %&%#%s8.1&@8@.#Y:BI8 */
241
242 #define AVAIL_KEYBUF 255
243
244 #define EVENT_MASK1 ( KeyPressMask | StructureNotifyMask )
245
246 #define EVENT_MASK2 ( KeyPressMask | \
247 ExposureMask | \
248 StructureNotifyMask )
249
250 #define MAX_TICK 9999 /* Odd Only! */
251
252 #define INTERVAL 125000L /* %$%s%?!</usr/home/csrg/sccs/games/xneko/SCCS/s.xneko.ck%?%$%` */
253
254 #define NEKO_SPEED 16
255
256 #define IDLE_SPACE 6
257
258 #define NORMAL_STATE 1
259 #define DEBUG_LIST 2
260 #define DEBUG_MOVE 3
261
262 /* G-$N>uBVDj?t */
263
264 #define NEKO_STOP 0 /* N)$A;_$^$C$? */
265 #define NEKO_JARE 1 /* 4i$r@v$C$F$$$k */
266 #define NEKO_KAKI 2 /* F,$rA_$$$F$$$k */
267 #define NEKO_AKUBI 3 /* $"$/$S$r$7$F$$$k */
268 #define NEKO_SLEEP 4 /* ?2$F$7$^$C$? */
269 #define NEKO_AWAKE 5 /* L\$,3P$a$? */
270 #define NEKO_U_MOVE 6 /* >e$K0\F0Cf */
271 #define NEKO_D_MOVE 7 /* 2<$K0\F0Cf */
272 #define NEKO_L_MOVE 8 /* :8$K0\F0Cf */
273 #define NEKO_R_MOVE 9 /* 1&$K0\F0Cf */
274 #define NEKO_UL_MOVE 10 /* :8>e$K0\F0Cf */
275 #define NEKO_UR_MOVE 11 /* 1&>e$K0\F0Cf */
276 #define NEKO_DL_MOVE 12 /* :82<$K0\F0Cf */
277 #define NEKO_DR_MOVE 13 /* 1&2<$K0\F0Cf */
278 #define NEKO_U_TOGI 14 /* >e$NJI$r0z$CA_$$$F$$$k */
279 #define NEKO_D_TOGI 15 /* 2<$NJI$r0z$CA_$$$F$$$k */
280 #define NEKO_L_TOGI 16 /* :8$NJI$r0z$CA_$$$F$$$k */
281 #define NEKO_R_TOGI 17 /* 1&$NJI$r0z$CA_$$$F$$$k */
282
283 /* G-$N%"%K%a!<%7%g%s7+$jJV$72s?t */
284
285 #define NEKO_STOP_TIME 4
286 #define NEKO_JARE_TIME 10
287 #define NEKO_KAKI_TIME 4
288 #define NEKO_AKUBI_TIME 3
289 #define NEKO_AWAKE_TIME 3
290 #define NEKO_TOGI_TIME 10
291
292 #define PI_PER8 ((double)3.1415926535/(double)8)
293
294 #define DIRNAMELEN 255
295
296
297 /*
298 * %0%m!</usr/home/csrg/sccs/games/xneko/SCCS/s.xneko.ckJQ?t
299 */
300
301 static char *ProgramName; /* %3%^%s%IL>>N */
302
303 Display *theDisplay;
304 int theScreen;
305 unsigned int theDepth;
306 unsigned long theBlackPixel;
307 unsigned long theWhitePixel;
308 Window theWindow;
309 Cursor theCursor;
310
311 static unsigned int WindowWidth;
312 static unsigned int WindowHeight;
313
314 static int WindowPointX;
315 static int WindowPointY;
316
317 static unsigned int BorderWidth = DEFAULT_BORDER;
318
319 long IntervalTime = INTERVAL;
320
321 int EventState; /* %$s%H=hM}MQ >uBVJQ?t */
322
323 int NekoTickCount; /* G-F0:n%+%&%s%? */
324 int NekoStateCount; /* G-F10l>uBV%+%&%s%? */
325 int NekoState; /* G-$N>uBV */
326
327 int MouseX; /* %^%&%9#X:BI8 */
328 int MouseY; /* %^%&%9#Y:BI8 */
329
330 int PrevMouseX = 0; /* D>A0$N%^%&%9#X:BI8 */
331 int PrevMouseY = 0; /* D>A0$N%^%&%9#Y:BI8 */
332
333 int NekoX; /* G-#X:BI8 */
334 int NekoY; /* G-#Y:BI8 */
335
336 int NekoMoveDx; /* G-0\F05wN%#X */
337 int NekoMoveDy; /* G-0\F05wN%#Y */
338
339 int NekoLastX; /* G-:G=*IA2h#X:BI8 */
340 int NekoLastY; /* G-:G=*IA2h#Y:BI8 */
341 GC NekoLastGC; /* G-:G=*IA2h GC */
342
343 double NekoSpeed = (double)NEKO_SPEED;
344
345 double SinPiPer8Times3; /* sin( #3&P!?#8 ) */
346 double SinPiPer8; /* sin( &P!?#8 ) */
347
348 Pixmap SpaceXbm;
349
350 Pixmap Mati2Xbm;
351 Pixmap Jare2Xbm;
352 Pixmap Kaki1Xbm;
353 Pixmap Kaki2Xbm;
354 Pixmap Mati3Xbm;
355 Pixmap Sleep1Xbm;
356 Pixmap Sleep2Xbm;
357
358 Pixmap AwakeXbm;
359
360 Pixmap Up1Xbm;
361 Pixmap Up2Xbm;
362 Pixmap Down1Xbm;
363 Pixmap Down2Xbm;
364 Pixmap Left1Xbm;
365 Pixmap Left2Xbm;
366 Pixmap Right1Xbm;
367 Pixmap Right2Xbm;
368 Pixmap UpLeft1Xbm;
369 Pixmap UpLeft2Xbm;
370 Pixmap UpRight1Xbm;
371 Pixmap UpRight2Xbm;
372 Pixmap DownLeft1Xbm;
373 Pixmap DownLeft2Xbm;
374 Pixmap DownRight1Xbm;
375 Pixmap DownRight2Xbm;
376
377 Pixmap UpTogi1Xbm;
378 Pixmap UpTogi2Xbm;
379 Pixmap DownTogi1Xbm;
380 Pixmap DownTogi2Xbm;
381 Pixmap LeftTogi1Xbm;
382 Pixmap LeftTogi2Xbm;
383 Pixmap RightTogi1Xbm;
384 Pixmap RightTogi2Xbm;
385
386 GC SpaceGC;
387
388 GC Mati2GC;
389 GC Jare2GC;
390 GC Kaki1GC;
391 GC Kaki2GC;
392 GC Mati3GC;
393 GC Sleep1GC;
394 GC Sleep2GC;
395
396 GC AwakeGC;
397
398 GC Up1GC;
399 GC Up2GC;
400 GC Down1GC;
401 GC Down2GC;
402 GC Left1GC;
403 GC Left2GC;
404 GC Right1GC;
405 GC Right2GC;
406 GC UpLeft1GC;
407 GC UpLeft2GC;
408 GC UpRight1GC;
409 GC UpRight2GC;
410 GC DownLeft1GC;
411 GC DownLeft2GC;
412 GC DownRight1GC;
413 GC DownRight2GC;
414
415 GC UpTogi1GC;
416 GC UpTogi2GC;
417 GC DownTogi1GC;
418 GC DownTogi2GC;
419 GC LeftTogi1GC;
420 GC LeftTogi2GC;
421 GC RightTogi1GC;
422 GC RightTogi2GC;
423
424 typedef struct {
425 GC *GCCreatePtr;
426 Pixmap *BitmapCreatePtr;
427 char *PixelPattern;
428 unsigned int PixelWidth;
429 unsigned int PixelHeight;
430 } BitmapGCData;
431
432 BitmapGCData BitmapGCDataTable[] =
433 {
434 { &SpaceGC, &SpaceXbm, space_bits, space_width, space_height },
435 { &Mati2GC, &Mati2Xbm, mati2_bits, mati2_width, mati2_height },
436 { &Jare2GC, &Jare2Xbm, jare2_bits, jare2_width, jare2_height },
437 { &Kaki1GC, &Kaki1Xbm, kaki1_bits, kaki1_width, kaki1_height },
438 { &Kaki2GC, &Kaki2Xbm, kaki2_bits, kaki2_width, kaki2_height },
439 { &Mati3GC, &Mati3Xbm, mati3_bits, mati3_width, mati3_height },
440 { &Sleep1GC, &Sleep1Xbm, sleep1_bits, sleep1_width, sleep1_height },
441 { &Sleep2GC, &Sleep2Xbm, sleep2_bits, sleep2_width, sleep2_height },
442 { &AwakeGC, &AwakeXbm, awake_bits, awake_width, awake_height },
443 { &Up1GC, &Up1Xbm, up1_bits, up1_width, up1_height },
444 { &Up2GC, &Up2Xbm, up2_bits, up2_width, up2_height },
445 { &Down1GC, &Down1Xbm, down1_bits, down1_width, down1_height },
446 { &Down2GC, &Down2Xbm, down2_bits, down2_width, down2_height },
447 { &Left1GC, &Left1Xbm, left1_bits, left1_width, left1_height },
448 { &Left2GC, &Left2Xbm, left2_bits, left2_width, left2_height },
449 { &Right1GC, &Right1Xbm, right1_bits, right1_width, right1_height },
450 { &Right2GC, &Right2Xbm, right2_bits, right2_width, right2_height },
451 { &UpLeft1GC, &UpLeft1Xbm, upleft1_bits, upleft1_width, upleft1_height },
452 { &UpLeft2GC, &UpLeft2Xbm, upleft2_bits, upleft2_width, upleft2_height },
453 { &UpRight1GC,
454 &UpRight1Xbm, upright1_bits, upright1_width, upright1_height },
455 { &UpRight2GC,
456 &UpRight2Xbm, upright2_bits, upright2_width, upright2_height },
457 { &DownLeft1GC,
458 &DownLeft1Xbm, dwleft1_bits, dwleft1_width, dwleft1_height },
459 { &DownLeft2GC,
460 &DownLeft2Xbm, dwleft2_bits, dwleft2_width, dwleft2_height },
461 { &DownRight1GC,
462 &DownRight1Xbm, dwright1_bits, dwright1_width, dwright1_height },
463 { &DownRight2GC,
464 &DownRight2Xbm, dwright2_bits, dwright2_width, dwright2_height },
465 { &UpTogi1GC, &UpTogi1Xbm, utogi1_bits, utogi1_width, utogi1_height },
466 { &UpTogi2GC, &UpTogi2Xbm, utogi2_bits, utogi2_width, utogi2_height },
467 { &DownTogi1GC, &DownTogi1Xbm, dtogi1_bits, dtogi1_width, dtogi1_height },
468 { &DownTogi2GC, &DownTogi2Xbm, dtogi2_bits, dtogi2_width, dtogi2_height },
469 { &LeftTogi1GC, &LeftTogi1Xbm, ltogi1_bits, ltogi1_width, ltogi1_height },
470 { &LeftTogi2GC, &LeftTogi2Xbm, ltogi2_bits, ltogi2_width, ltogi2_height },
471 { &RightTogi1GC,
472 &RightTogi1Xbm, rtogi1_bits, rtogi1_width, rtogi1_height },
473 { &RightTogi2GC,
474 &RightTogi2Xbm, rtogi2_bits, rtogi2_width, rtogi2_height },
475 { NULL, NULL, 0, 0, 0 }
476 };
477
478 typedef struct {
479 GC *TickEvenGCPtr;
480 GC *TickOddGCPtr;
481 } Animation;
482
483 Animation AnimationPattern[] =
484 {
485 { &Mati2GC, &Mati2GC }, /* NekoState == NEKO_STOP */
486 { &Jare2GC, &Mati2GC }, /* NekoState == NEKO_JARE */
487 { &Kaki1GC, &Kaki2GC }, /* NekoState == NEKO_KAKI */
488 { &Mati3GC, &Mati3GC }, /* NekoState == NEKO_AKUBI */
489 { &Sleep1GC, &Sleep2GC }, /* NekoState == NEKO_SLEEP */
490 { &AwakeGC, &AwakeGC }, /* NekoState == NEKO_AWAKE */
491 { &Up1GC, &Up2GC } , /* NekoState == NEKO_U_MOVE */
492 { &Down1GC, &Down2GC }, /* NekoState == NEKO_D_MOVE */
493 { &Left1GC, &Left2GC }, /* NekoState == NEKO_L_MOVE */
494 { &Right1GC, &Right2GC }, /* NekoState == NEKO_R_MOVE */
495 { &UpLeft1GC, &UpLeft2GC }, /* NekoState == NEKO_UL_MOVE */
496 { &UpRight1GC, &UpRight2GC }, /* NekoState == NEKO_UR_MOVE */
497 { &DownLeft1GC, &DownLeft2GC }, /* NekoState == NEKO_DL_MOVE */
498 { &DownRight1GC, &DownRight2GC }, /* NekoState == NEKO_DR_MOVE */
499 { &UpTogi1GC, &UpTogi2GC }, /* NekoState == NEKO_U_TOGI */
500 { &DownTogi1GC, &DownTogi2GC }, /* NekoState == NEKO_D_TOGI */
501 { &LeftTogi1GC, &LeftTogi2GC }, /* NekoState == NEKO_L_TOGI */
502 { &RightTogi1GC, &RightTogi2GC }, /* NekoState == NEKO_R_TOGI */
503 };
504
505
506 /*--------------------------------------------------------------
507 *
508 * 0C10/14/12^504W%G!<%?!&GC =i4|2=
509 *
510 *--------------------------------------------------------------*/
511
512 void
513 InitBitmapAndGCs()
514 {
515 BitmapGCData *BitmapGCDataTablePtr;
516 XGCValues theGCValues;
517
518 theGCValues.function = GXcopy;
519 theGCValues.foreground = BlackPixel( theDisplay, theScreen );
520 theGCValues.background = WhitePixel( theDisplay, theScreen );
521 theGCValues.fill_style = FillTiled;
522
523 for ( BitmapGCDataTablePtr = BitmapGCDataTable;
524 BitmapGCDataTablePtr->GCCreatePtr != NULL;
525 BitmapGCDataTablePtr++ ) {
526
527 *(BitmapGCDataTablePtr->BitmapCreatePtr)
528 = XCreatePixmapFromBitmapData(
529 theDisplay,
530 RootWindow( theDisplay, theScreen ),
531 BitmapGCDataTablePtr->PixelPattern,
532 BitmapGCDataTablePtr->PixelWidth,
533 BitmapGCDataTablePtr->PixelHeight,
534 BlackPixel( theDisplay, theScreen ),
535 WhitePixel( theDisplay, theScreen ),
536 DefaultDepth( theDisplay, theScreen ) );
537
538 theGCValues.tile = *(BitmapGCDataTablePtr->BitmapCreatePtr);
539
540 *(BitmapGCDataTablePtr->GCCreatePtr)
541 = XCreateGC( theDisplay, theWindow,
542 GCFunction | GCForeground | GCBackground |
543 GCTile | GCFillStyle,
544 &theGCValues );
545 }
546
547 XFlush( theDisplay );
548 }
549
550
551 /*--------------------------------------------------------------
552 *
553 * %9%/%j!<%s4D6-=i4|2=
554 *
555 *--------------------------------------------------------------*/
556
557 void
558 InitScreen( DisplayName, theGeometry, TitleName, iconicState )
559 char *DisplayName;
560 char *theGeometry;
561 char *TitleName;
562 Bool iconicState;
563 {
564 int GeometryStatus;
565 XSetWindowAttributes theWindowAttributes;
566 XSizeHints theSizeHints;
567 unsigned long theWindowMask;
568 Pixmap theIconPixmap;
569 Pixmap theCursorSource;
570 Pixmap theCursorMask;
571 XWMHints theWMHints;
572 Window theRoot;
573 Colormap theColormap;
574 XColor theWhiteColor, theBlackColor, theExactColor;
575
576 if ( ( theDisplay = XOpenDisplay( DisplayName ) ) == NULL ) {
577 fprintf( stderr, "%s: Can't open display", ProgramName );
578 if ( DisplayName != NULL ) {
579 fprintf( stderr, " %s.\n", DisplayName );
580 } else {
581 fprintf( stderr, ".\n" );
582 }
583 exit( 1 );
584 }
585
586 theScreen = DefaultScreen( theDisplay );
587 theDepth = DefaultDepth( theDisplay, theScreen );
588
589 theBlackPixel = BlackPixel( theDisplay, theScreen );
590 theWhitePixel = WhitePixel( theDisplay, theScreen );
591
592 GeometryStatus = XParseGeometry( theGeometry,
593 &WindowPointX, &WindowPointY,
594 &WindowWidth, &WindowHeight );
595
596 if ( !( GeometryStatus & XValue ) ) {
597 WindowPointX = DEFAULT_WIN_X;
598 }
599 if ( !( GeometryStatus & YValue ) ) {
600 WindowPointY = DEFAULT_WIN_Y;
601 }
602 if ( !( GeometryStatus & WidthValue ) ) {
603 WindowWidth = WINDOW_WIDTH;
604 }
605 if ( !( GeometryStatus & HeightValue ) ) {
606 WindowHeight = WINDOW_HEIGHT;
607 }
608
609 theCursorSource
610 = XCreateBitmapFromData( theDisplay,
611 RootWindow( theDisplay, theScreen ),
612 cursor_bits,
613 cursor_width,
614 cursor_height );
615
616 theCursorMask
617 = XCreateBitmapFromData( theDisplay,
618 RootWindow( theDisplay, theScreen ),
619 cursor_mask_bits,
620 cursor_mask_width,
621 cursor_mask_height );
622
623 theColormap = DefaultColormap( theDisplay, theScreen );
624
625 if ( !XAllocNamedColor( theDisplay, theColormap,
626 "white", &theWhiteColor, &theExactColor ) ) {
627 fprintf( stderr,
628 "%s: Can't XAllocNamedColor( \"white\" ).\n", ProgramName );
629 exit( 1 );
630 }
631
632 if ( !XAllocNamedColor( theDisplay, theColormap,
633 "black", &theBlackColor, &theExactColor ) ) {
634 fprintf( stderr,
635 "%s: Can't XAllocNamedColor( \"black\" ).\n", ProgramName );
636 exit( 1 );
637 }
638
639 theCursor = XCreatePixmapCursor( theDisplay,
640 theCursorSource, theCursorMask,
641 &theBlackColor, &theWhiteColor,
642 cursor_x_hot, cursor_y_hot );
643
644 theWindowAttributes.border_pixel = theBlackPixel;
645 theWindowAttributes.background_pixel = theWhitePixel;
646 theWindowAttributes.cursor = theCursor;
647 theWindowAttributes.override_redirect = False;
648
649 theWindowMask = CWBackPixel |
650 CWBorderPixel |
651 CWCursor |
652 CWOverrideRedirect;
653
654 theWindow = XCreateWindow( theDisplay,
655 RootWindow( theDisplay, theScreen ),
656 WindowPointX, WindowPointY,
657 WindowWidth, WindowHeight,
658 BorderWidth,
659 theDepth,
660 InputOutput,
661 CopyFromParent,
662 theWindowMask,
663 &theWindowAttributes );
664
665 theIconPixmap = XCreateBitmapFromData( theDisplay, theWindow,
666 icon_bits,
667 icon_width,
668 icon_height );
669
670 theWMHints.icon_pixmap = theIconPixmap;
671 if ( iconicState ) {
672 theWMHints.initial_state = IconicState;
673 } else {
674 theWMHints.initial_state = NormalState;
675 }
676 theWMHints.flags = IconPixmapHint | StateHint;
677
678 XSetWMHints( theDisplay, theWindow, &theWMHints );
679
680 theSizeHints.flags = PPosition | PSize;
681 theSizeHints.x = WindowPointX;
682 theSizeHints.y = WindowPointY;
683 theSizeHints.width = WindowWidth;
684 theSizeHints.height = WindowHeight;
685
686 XSetNormalHints( theDisplay, theWindow, &theSizeHints );
687
688 if ( strlen( TitleName ) >= 1 ) {
689 XStoreName( theDisplay, theWindow, TitleName );
690 XSetIconName( theDisplay, theWindow, TitleName );
691 } else {
692 XStoreName( theDisplay, theWindow, ProgramName );
693 XSetIconName( theDisplay, theWindow, ProgramName );
694 }
695
696 XMapWindow( theDisplay, theWindow );
697
698 XFlush( theDisplay );
699
700 XGetGeometry( theDisplay, theWindow,
701 &theRoot,
702 &WindowPointX, &WindowPointY,
703 &WindowWidth, &WindowHeight,
704 &BorderWidth, &theDepth );
705
706 InitBitmapAndGCs();
707
708 XSelectInput( theDisplay, theWindow, EVENT_MASK1 );
709
710 XFlush( theDisplay );
711 }
712
713
714 /*--------------------------------------------------------------
715 *
716 * %$%s%?!</usr/home/csrg/sccs/games/xneko/SCCS/s.xneko.ck
717 *
718 * !!$3$N4X?t$r8F$V$H!"$"$k0lDj$N;~4VJV$C$F$3$J$/$J$k!#G-
719 * $NF0:n%?%$%_%s%0D4@0$KMxMQ$9$k$3$H!#
720 *
721 *--------------------------------------------------------------*/
722
723 void
724 Interval()
725 {
726 pause();
727 }
728
729
730 /*--------------------------------------------------------------
731 *
732 * s.xneko.c#728/%+%&%s%H=hM}
733 *
734 *--------------------------------------------------------------*/
735
736 void
737 TickCount()
738 {
739 if ( ++NekoTickCount >= MAX_TICK ) {
740 NekoTickCount = 0;
741 }
742
743 if ( NekoTickCount % 2 == 0 ) {
744 if ( NekoStateCount < MAX_TICK ) {
745 NekoStateCount++;
746 }
747 }
748 }
749
750
751 /*--------------------------------------------------------------
752 *
753 * G->uBV@_Dj
754 *
755 *--------------------------------------------------------------*/
756
757 void
758 SetNekoState( SetValue )
759 int SetValue;
760 {
761 NekoTickCount = 0;
762 NekoStateCount = 0;
763
764 NekoState = SetValue;
765
766 #ifdef DEBUG
767 switch ( NekoState ) {
768 case NEKO_STOP:
769 case NEKO_JARE:
770 case NEKO_KAKI:
771 case NEKO_AKUBI:
772 case NEKO_SLEEP:
773 case NEKO_U_TOGI:
774 case NEKO_D_TOGI:
775 case NEKO_L_TOGI:
776 case NEKO_R_TOGI:
777 NekoMoveDx = NekoMoveDy = 0;
778 break;
779 default:
780 break;
781 }
782 #endif
783 }
784
785
786 /*--------------------------------------------------------------
787 *
788 * G-IA2h=hM}
789 *
790 *--------------------------------------------------------------*/
791
792 void
793 DrawNeko( x, y, DrawGC )
794 int x;
795 int y;
796 GC DrawGC;
797 {
798 if ( ( x != NekoLastX || y != NekoLastY )
799 && ( EventState != DEBUG_LIST ) ) {
800 XFillRectangle( theDisplay, theWindow, SpaceGC,
801 NekoLastX, NekoLastY,
802 BITMAP_WIDTH, BITMAP_HEIGHT );
803 }
804
805 XSetTSOrigin( theDisplay, DrawGC, x, y );
806
807 XFillRectangle( theDisplay, theWindow, DrawGC,
808 x, y, BITMAP_WIDTH, BITMAP_HEIGHT );
809
810 XFlush( theDisplay );
811
812 NekoLastX = x;
813 NekoLastY = y;
814
815 NekoLastGC = DrawGC;
816 }
817
818
819 /*--------------------------------------------------------------
820 *
821 * G-:FIA2h=hM}
822 *
823 *--------------------------------------------------------------*/
824
825 void
826 RedrawNeko()
827 {
828 XFillRectangle( theDisplay, theWindow, NekoLastGC,
829 NekoLastX, NekoLastY,
830 BITMAP_WIDTH, BITMAP_HEIGHT );
831
832 XFlush( theDisplay );
833 }
834
835
836 /*--------------------------------------------------------------
837 *
838 * G-0\F0J}K!7hDj
839 *
840 *--------------------------------------------------------------*/
841
842 void
843 NekoDirection()
844 {
845 int NewState;
846 double LargeX, LargeY;
847 double Length;
848 double SinTheta;
849
850 if ( NekoMoveDx == 0 && NekoMoveDy == 0 ) {
851 NewState = NEKO_STOP;
852 } else {
853 LargeX = (double)NekoMoveDx;
854 LargeY = (double)(-NekoMoveDy);
855 Length = sqrt( LargeX * LargeX + LargeY * LargeY );
856 SinTheta = LargeY / Length;
857
858 if ( NekoMoveDx > 0 ) {
859 if ( SinTheta > SinPiPer8Times3 ) {
860 NewState = NEKO_U_MOVE;
861 } else if ( ( SinTheta <= SinPiPer8Times3 )
862 && ( SinTheta > SinPiPer8 ) ) {
863 NewState = NEKO_UR_MOVE;
864 } else if ( ( SinTheta <= SinPiPer8 )
865 && ( SinTheta > -( SinPiPer8 ) ) ) {
866 NewState = NEKO_R_MOVE;
867 } else if ( ( SinTheta <= -( SinPiPer8 ) )
868 && ( SinTheta > -( SinPiPer8Times3 ) ) ) {
869 NewState = NEKO_DR_MOVE;
870 } else {
871 NewState = NEKO_D_MOVE;
872 }
873 } else {
874 if ( SinTheta > SinPiPer8Times3 ) {
875 NewState = NEKO_U_MOVE;
876 } else if ( ( SinTheta <= SinPiPer8Times3 )
877 && ( SinTheta > SinPiPer8 ) ) {
878 NewState = NEKO_UL_MOVE;
879 } else if ( ( SinTheta <= SinPiPer8 )
880 && ( SinTheta > -( SinPiPer8 ) ) ) {
881 NewState = NEKO_L_MOVE;
882 } else if ( ( SinTheta <= -( SinPiPer8 ) )
883 && ( SinTheta > -( SinPiPer8Times3 ) ) ) {
884 NewState = NEKO_DL_MOVE;
885 } else {
886 NewState = NEKO_D_MOVE;
887 }
888 }
889 }
890
891 if ( NekoState != NewState ) {
892 SetNekoState( NewState );
893 }
894 }
895
896
897 /*--------------------------------------------------------------
898 *
899 * G-JI$V$D$+$jH=Dj
900 *
901 *--------------------------------------------------------------*/
902
903 Bool
904 IsWindowOver()
905 {
906 Bool ReturnValue = False;
907
908 if ( NekoY <= 0 ) {
909 NekoY = 0;
910 ReturnValue = True;
911 } else if ( NekoY >= WindowHeight - BITMAP_HEIGHT ) {
912 NekoY = WindowHeight - BITMAP_HEIGHT;
913 ReturnValue = True;
914 }
915 if ( NekoX <= 0 ) {
916 NekoX = 0;
917 ReturnValue = True;
918 } else if ( NekoX >= WindowWidth - BITMAP_WIDTH ) {
919 NekoX = WindowWidth - BITMAP_WIDTH;
920 ReturnValue = True;
921 }
922
923 return( ReturnValue );
924 }
925
926
927 /*--------------------------------------------------------------
928 *
929 * G-0\F0>u67H=Dj
930 *
931 *--------------------------------------------------------------*/
932
933 Bool
934 IsNekoDontMove()
935 {
936 if ( NekoX == NekoLastX && NekoY == NekoLastY ) {
937 return( True );
938 } else {
939 return( False );
940 }
941 }
942
943
944 /*--------------------------------------------------------------
945 *
946 * G-0\F03+;OH=Dj
947 *
948 *--------------------------------------------------------------*/
949
950 Bool
951 IsNekoMoveStart()
952 {
953 #ifndef DEBUG
954 if ( ( PrevMouseX >= MouseX - IDLE_SPACE
955 && PrevMouseX <= MouseX + IDLE_SPACE ) &&
956 ( PrevMouseY >= MouseY - IDLE_SPACE
957 && PrevMouseY <= MouseY + IDLE_SPACE ) ) {
958 return( False );
959 } else {
960 return( True );
961 }
962 #else
963 if ( NekoMoveDx == 0 && NekoMoveDy == 0 ) {
964 return( False );
965 } else {
966 return( True );
967 }
968 #endif
969 }
970
971
972 /*--------------------------------------------------------------
973 *
974 * G-0\F0 dx, dy 7W;;
975 *
976 *--------------------------------------------------------------*/
977
978 void
979 CalcDxDy()
980 {
981 Window QueryRoot, QueryChild;
982 int AbsoluteX, AbsoluteY;
983 int RelativeX, RelativeY;
984 unsigned int ModKeyMask;
985 double LargeX, LargeY;
986 double DoubleLength, Length;
987
988 XQueryPointer( theDisplay, theWindow,
989 &QueryRoot, &QueryChild,
990 &AbsoluteX, &AbsoluteY,
991 &RelativeX, &RelativeY,
992 &ModKeyMask );
993
994 PrevMouseX = MouseX;
995 PrevMouseY = MouseY;
996
997 MouseX = RelativeX;
998 MouseY = RelativeY;
999
1000 LargeX = (double)( MouseX - NekoX - BITMAP_WIDTH / 2 );
1001 LargeY = (double)( MouseY - NekoY - BITMAP_HEIGHT );
1002
1003 DoubleLength = LargeX * LargeX + LargeY * LargeY;
1004
1005 if ( DoubleLength != (double)0 ) {
1006 Length = sqrt( DoubleLength );
1007 if ( Length <= NekoSpeed ) {
1008 NekoMoveDx = (int)LargeX;
1009 NekoMoveDy = (int)LargeY;
1010 } else {
1011 NekoMoveDx = (int)( ( NekoSpeed * LargeX ) / Length );
1012 NekoMoveDy = (int)( ( NekoSpeed * LargeY ) / Length );
1013 }
1014 } else {
1015 NekoMoveDx = NekoMoveDy = 0;
1016 }
1017 }
1018
1019
1020 /*--------------------------------------------------------------
1021 *
1022 * F0:n2r@OG-IA2h=hM}
1023 *
1024 *--------------------------------------------------------------*/
1025
1026 void
1027 NekoThinkDraw()
1028 {
1029 #ifndef DEBUG
1030 CalcDxDy();
1031 #endif
1032
1033 if ( NekoState != NEKO_SLEEP ) {
1034 DrawNeko( NekoX, NekoY,
1035 NekoTickCount % 2 == 0 ?
1036 *(AnimationPattern[ NekoState ].TickEvenGCPtr) :
1037 *(AnimationPattern[ NekoState ].TickOddGCPtr) );
1038 } else {
1039 DrawNeko( NekoX, NekoY,
1040 NekoTickCount % 8 <= 3 ?
1041 *(AnimationPattern[ NekoState ].TickEvenGCPtr) :
1042 *(AnimationPattern[ NekoState ].TickOddGCPtr) );
1043 }
1044
1045 TickCount();
1046
1047 switch ( NekoState ) {
1048 case NEKO_STOP:
1049 if ( IsNekoMoveStart() ) {
1050 SetNekoState( NEKO_AWAKE );
1051 break;
1052 }
1053 if ( NekoStateCount < NEKO_STOP_TIME ) {
1054 break;
1055 }
1056 if ( NekoMoveDx < 0 && NekoX <= 0 ) {
1057 SetNekoState( NEKO_L_TOGI );
1058 } else if ( NekoMoveDx > 0 && NekoX >= WindowWidth - BITMAP_WIDTH ) {
1059 SetNekoState( NEKO_R_TOGI );
1060 } else if ( NekoMoveDy < 0 && NekoY <= 0 ) {
1061 SetNekoState( NEKO_U_TOGI );
1062 } else if ( NekoMoveDy > 0 && NekoY >= WindowHeight - BITMAP_HEIGHT ) {
1063 SetNekoState( NEKO_D_TOGI );
1064 } else {
1065 SetNekoState( NEKO_JARE );
1066 }
1067 break;
1068 case NEKO_JARE:
1069 if ( IsNekoMoveStart() ) {
1070 SetNekoState( NEKO_AWAKE );
1071 break;
1072 }
1073 if ( NekoStateCount < NEKO_JARE_TIME ) {
1074 break;
1075 }
1076 SetNekoState( NEKO_KAKI );
1077 break;
1078 case NEKO_KAKI:
1079 if ( IsNekoMoveStart() ) {
1080 SetNekoState( NEKO_AWAKE );
1081 break;
1082 }
1083 if ( NekoStateCount < NEKO_KAKI_TIME ) {
1084 break;
1085 }
1086 SetNekoState( NEKO_AKUBI );
1087 break;
1088 case NEKO_AKUBI:
1089 if ( IsNekoMoveStart() ) {
1090 SetNekoState( NEKO_AWAKE );
1091 break;
1092 }
1093 if ( NekoStateCount < NEKO_AKUBI_TIME ) {
1094 break;
1095 }
1096 SetNekoState( NEKO_SLEEP );
1097 break;
1098 case NEKO_SLEEP:
1099 if ( IsNekoMoveStart() ) {
1100 SetNekoState( NEKO_AWAKE );
1101 break;
1102 }
1103 break;
1104 case NEKO_AWAKE:
1105 if ( NekoStateCount < NEKO_AWAKE_TIME ) {
1106 break;
1107 }
1108 NekoDirection(); /* G-$,F0$/8~$-$r5a$a$k */
1109 break;
1110 case NEKO_U_MOVE:
1111 case NEKO_D_MOVE:
1112 case NEKO_L_MOVE:
1113 case NEKO_R_MOVE:
1114 case NEKO_UL_MOVE:
1115 case NEKO_UR_MOVE:
1116 case NEKO_DL_MOVE:
1117 case NEKO_DR_MOVE:
1118 NekoX += NekoMoveDx;
1119 NekoY += NekoMoveDy;
1120 NekoDirection();
1121 if ( IsWindowOver() ) {
1122 if ( IsNekoDontMove() ) {
1123 SetNekoState( NEKO_STOP );
1124 }
1125 }
1126 break;
1127 case NEKO_U_TOGI:
1128 case NEKO_D_TOGI:
1129 case NEKO_L_TOGI:
1130 case NEKO_R_TOGI:
1131 if ( IsNekoMoveStart() ) {
1132 SetNekoState( NEKO_AWAKE );
1133 break;
1134 }
1135 if ( NekoStateCount < NEKO_TOGI_TIME ) {
1136 break;
1137 }
1138 SetNekoState( NEKO_KAKI );
1139 break;
1140 default:
1141 /* Internal Error */
1142 SetNekoState( NEKO_STOP );
1143 break;
1144 }
1145
1146 Interval();
1147 }
1148
1149
1150 #ifdef DEBUG
1151
1152 /*--------------------------------------------------------------
1153 *
1154 * %-%c%i%/%?!<0lMwI=<(!J05/31/93P11500MQ!K
1155 *
1156 *--------------------------------------------------------------*/
1157
1158 void
1159 DisplayCharacters()
1160 {
1161 int Index;
1162 int x, y;
1163
1164 for ( Index = 0, x = 0, y = 0;
1165 BitmapGCDataTable[ Index ].GCCreatePtr != NULL; Index++ ) {
1166
1167 DrawNeko( x, y, *(BitmapGCDataTable[ Index ].GCCreatePtr) );
1168 XFlush( theDisplay );
1169
1170 x += BITMAP_WIDTH;
1171
1172 if ( x > WindowWidth - BITMAP_WIDTH ) {
1173 x = 0;
1174 y += BITMAP_HEIGHT;
1175 if ( y > WindowHeight - BITMAP_HEIGHT) {
1176 break;
1177 }
1178 }
1179 }
1180 }
1181
1182 #endif /* DEBUG */
1183
1184
1185 /*--------------------------------------------------------------
1186 *
1187 * %-!<%$s%H=hM}
1188 *
1189 *--------------------------------------------------------------*/
1190
1191 Bool
1192 ProcessKeyPress( theKeyEvent )
1193 XKeyEvent *theKeyEvent;
1194 {
1195 int Length;
1196 int theKeyBufferMaxLen = AVAIL_KEYBUF;
1197 char theKeyBuffer[ AVAIL_KEYBUF + 1 ];
1198 KeySym theKeySym;
1199 XComposeStatus theComposeStatus;
1200 Bool ReturnState;
1201
1202 ReturnState = True;
1203
1204 Length = XLookupString( theKeyEvent,
1205 theKeyBuffer, theKeyBufferMaxLen,
1206 &theKeySym, &theComposeStatus );
1207
1208 if ( Length > 0 ) {
1209 switch ( theKeyBuffer[ 0 ] ) {
1210 case 'q':
1211 case 'Q':
1212 if ( theKeyEvent->state & Mod1Mask ) { /* META (Alt) %-!< */
1213 ReturnState = False;
1214 }
1215 break;
1216 default:
1217 break;
1218 }
1219 }
1220
1221 #ifdef DEBUG
1222 if ( EventState == DEBUG_MOVE ) {
1223 switch ( theKeySym ) {
1224 case XK_KP_1:
1225 NekoMoveDx = -(int)( NekoSpeed / sqrt( (double)2 ) );
1226 NekoMoveDy = -NekoMoveDx;
1227 break;
1228 case XK_KP_2:
1229 NekoMoveDx = 0;
1230 NekoMoveDy = (int)NekoSpeed;
1231 break;
1232 case XK_KP_3:
1233 NekoMoveDx = (int)( NekoSpeed / sqrt( (double)2 ) );
1234 NekoMoveDy = NekoMoveDx;
1235 break;
1236 case XK_KP_4:
1237 NekoMoveDx = -(int)NekoSpeed;
1238 NekoMoveDy = 0;
1239 break;
1240 case XK_KP_5:
1241 NekoMoveDx = 0;
1242 NekoMoveDy = 0;
1243 break;
1244 case XK_KP_6:
1245 NekoMoveDx = (int)NekoSpeed;
1246 NekoMoveDy = 0;
1247 break;
1248 case XK_KP_7:
1249 NekoMoveDx = -(int)( NekoSpeed / sqrt( (double)2 ) );
1250 NekoMoveDy = NekoMoveDx;
1251 break;
1252 case XK_KP_8:
1253 NekoMoveDx = 0;
1254 NekoMoveDy = -(int)NekoSpeed;
1255 break;
1256 case XK_KP_9:
1257 NekoMoveDx = (int)( NekoSpeed / sqrt( (double)2 ) );
1258 NekoMoveDy = -NekoMoveDx;
1259 break;
1260 }
1261 }
1262 #endif
1263
1264 return( ReturnState );
1265 }
1266
1267
1268 /*--------------------------------------------------------------
1269 *
1270 * G-0LCVD4@0
1271 *
1272 *--------------------------------------------------------------*/
1273
1274 void
1275 NekoAdjust()
1276 {
1277 if ( NekoX < 0 ) {
1278 NekoX = 0;
1279 } else if ( NekoX > WindowWidth - BITMAP_WIDTH ) {
1280 NekoX = WindowWidth - BITMAP_WIDTH;
1281 }
1282
1283 if ( NekoY < 0 ) {
1284 NekoY = 0;
1285 } else if ( NekoY > WindowHeight - BITMAP_HEIGHT ) {
1286 NekoY = WindowHeight - BITMAP_HEIGHT;
1287 }
1288 }
1289
1290
1291 /*--------------------------------------------------------------
1292 *
1293 * %$s%H=hM}
1294 *
1295 *--------------------------------------------------------------*/
1296
1297 Bool
1298 ProcessEvent()
1299 {
1300 XEvent theEvent;
1301 Bool ContinueState = True;
1302
1303 switch ( EventState ) {
1304 case NORMAL_STATE:
1305 while ( XCheckMaskEvent( theDisplay, EVENT_MASK1, &theEvent ) ) {
1306 switch ( theEvent.type ) {
1307 case ConfigureNotify:
1308 WindowWidth = theEvent.xconfigure.width;
1309 WindowHeight = theEvent.xconfigure.height;
1310 WindowPointX = theEvent.xconfigure.x;
1311 WindowPointY = theEvent.xconfigure.y;
1312 BorderWidth = theEvent.xconfigure.border_width;
1313 NekoAdjust();
1314 break;
1315 case Expose:
1316 if ( theEvent.xexpose.count == 0 ) {
1317 RedrawNeko();
1318 }
1319 break;
1320 case MapNotify:
1321 RedrawNeko();
1322 break;
1323 case KeyPress:
1324 ContinueState = ProcessKeyPress( &theEvent.xkey );
1325 if ( !ContinueState ) {
1326 return( ContinueState );
1327 }
1328 break;
1329 default:
1330 /* Unknown Event */
1331 break;
1332 }
1333 }
1334 break;
1335 #ifdef DEBUG
1336 case DEBUG_LIST:
1337 XNextEvent( theDisplay, &theEvent );
1338 switch ( theEvent.type ) {
1339 case ConfigureNotify:
1340 WindowWidth = theEvent.xconfigure.width;
1341 WindowHeight = theEvent.xconfigure.height;
1342 WindowPointX = theEvent.xconfigure.x;
1343 WindowPointY = theEvent.xconfigure.y;
1344 BorderWidth = theEvent.xconfigure.border_width;
1345 break;
1346 case Expose:
1347 if ( theEvent.xexpose.count == 0 ) {
1348 DisplayCharacters();
1349 }
1350 break;
1351 case MapNotify:
1352 DisplayCharacters();
1353 break;
1354 case KeyPress:
1355 ContinueState = ProcessKeyPress( &theEvent );
1356 break;
1357 default:
1358 /* Unknown Event */
1359 break;
1360 }
1361 break;
1362 case DEBUG_MOVE:
1363 while ( XCheckMaskEvent( theDisplay, EVENT_MASK1, &theEvent ) ) {
1364 switch ( theEvent.type ) {
1365 case ConfigureNotify:
1366 WindowWidth = theEvent.xconfigure.width;
1367 WindowHeight = theEvent.xconfigure.height;
1368 WindowPointX = theEvent.xconfigure.x;
1369 WindowPointY = theEvent.xconfigure.y;
1370 BorderWidth = theEvent.xconfigure.border_width;
1371 NekoAdjust();
1372 break;
1373 case Expose:
1374 if ( theEvent.xexpose.count == 0 ) {
1375 RedrawNeko();
1376 }
1377 break;
1378 case MapNotify:
1379 RedrawNeko();
1380 break;
1381 case KeyPress:
1382 ContinueState = ProcessKeyPress( &theEvent );
1383 if ( !ContinueState ) {
1384 return( ContinueState );
1385 }
1386 break;
1387 default:
1388 /* Unknown Event */
1389 break;
1390 }
1391 }
1392 break;
1393 #endif
1394 default:
1395 /* Internal Error */
1396 break;
1397 }
1398
1399 return( ContinueState );
1400 }
1401
1402
1403 /*--------------------------------------------------------------
1404 *
1405 * G-=hM}
1406 *
1407 *--------------------------------------------------------------*/
1408
1409 void
1410 ProcessNeko()
1411 {
1412 struct itimerval Value;
1413
1414 /* 4D6-$N=i4|2= */
1415
1416 EventState = NORMAL_STATE;
1417
1418 /* G-$N=i4|2= */
1419
1420 NekoX = ( WindowWidth - BITMAP_WIDTH / 2 ) / 2;
1421 NekoY = ( WindowHeight - BITMAP_HEIGHT / 2 ) / 2;
1422
1423 NekoLastX = NekoX;
1424 NekoLastY = NekoY;
1425
1426 SetNekoState( NEKO_STOP );
1427
1428 /* %?%$%^!<@_Dj */
1429
1430 timerclear( &Value.it_interval );
1431 timerclear( &Value.it_value );
1432
1433 Value.it_interval.tv_usec = IntervalTime;
1434 Value.it_value.tv_usec = IntervalTime;
1435
1436 setitimer( ITIMER_REAL, &Value, 0 );
1437
1438 /* %a%$%s=hM} */
1439
1440 do {
1441 NekoThinkDraw();
1442 } while ( ProcessEvent() );
1443 }
1444
1445
1446 #ifdef DEBUG
1447
1448 /*--------------------------------------------------------------
1449 *
1450 * G-0lMw!J05/31/93P14460MQ!K
1451 *
1452 *--------------------------------------------------------------*/
1453
1454 void
1455 NekoList()
1456 {
1457 EventState = DEBUG_LIST;
1458
1459 fprintf( stderr, "\n" );
1460 fprintf( stderr, "G-0lMw$rI=<($7$^$9!#(Quit !D Alt-Q)\n" );
1461 fprintf( stderr, "\n" );
1462
1463 XSelectInput( theDisplay, theWindow, EVENT_MASK2 );
1464
1465 while ( ProcessEvent() );
1466 }
1467
1468
1469 /*--------------------------------------------------------------
1470 *
1471 * G-0\F0s.xneko.c9%H!J05/31/93P14670MQ!K
1472 *
1473 *--------------------------------------------------------------*/
1474
1475 void
1476 NekoMoveTest()
1477 {
1478 struct itimerval Value;
1479
1480 /* 4D6-$N=i4|2= */
1481
1482 EventState = DEBUG_MOVE;
1483
1484 /* G-$N=i4|2= */
1485
1486 NekoX = ( WindowWidth - BITMAP_WIDTH / 2 ) / 2;
1487 NekoY = ( WindowHeight - BITMAP_HEIGHT / 2 ) / 2;
1488
1489 NekoLastX = NekoX;
1490 NekoLastY = NekoY;
1491
1492 SetNekoState( NEKO_STOP );
1493
1494 /* %?%$%^!<@_Dj */
1495
1496 timerclear( &Value.it_interval );
1497 timerclear( &Value.it_value );
1498
1499 Value.it_interval.tv_usec = IntervalTime;
1500 Value.it_value.tv_usec = IntervalTime;
1501
1502 setitimer( ITIMER_REAL, &Value, 0 );
1503
1504 /* %a%$%s=hM} */
1505
1506 fprintf( stderr, "\n" );
1507 fprintf( stderr, "G-$N0\F0s.xneko.c9%H$r9T$$$^$9!#(Quit !D Alt-Q)\n" );
1508 fprintf( stderr, "\n" );
1509 fprintf( stderr, "\t%-!<C%I>e$Ns.xneko.cs%-!<$GG-$r0\F0$5$;$F2<$5$$!#\n" );
1510 fprintf( stderr, "\t(M-8z$J%-!<$O#1!A#9$G$9!#)\n" );
1511 fprintf( stderr, "\n" );
1512
1513 do {
1514 NekoThinkDraw();
1515 } while ( ProcessEvent() );
1516 }
1517
1518
1519 /*--------------------------------------------------------------
1520 *
1521 * %a%K%e!<=hM}!J05/31/93P15170MQ!K
1522 *
1523 *--------------------------------------------------------------*/
1524
1525 void
1526 ProcessDebugMenu()
1527 {
1528 int UserSelectNo = 0;
1529 char UserAnswer[ BUFSIZ ];
1530
1531 fprintf( stderr, "\n" );
1532 fprintf( stderr, "!Zxneko 05/31/93P15280%a%K%e!<![\n" );
1533
1534 while ( !( UserSelectNo >= 1 && UserSelectNo <= 2 ) ) {
1535 fprintf( stderr, "\n" );
1536 fprintf( stderr, "\t1)!!G-%-%c%i%/%?!<0lMwI=<(\n" );
1537 fprintf( stderr, "\t2)!!G-0\F0s.xneko.c9%H\n" );
1538 fprintf( stderr, "\n" );
1539 fprintf( stderr, "Select: " );
1540
1541 fgets( UserAnswer, sizeof( UserAnswer ), stdin );
1542
1543 UserSelectNo = atoi( UserAnswer );
1544
1545 if ( !( UserSelectNo >= 1 && UserSelectNo <= 2 ) ) {
1546 fprintf( stderr, "\n" );
1547 fprintf( stderr, "@5$7$$HV9f$rA*Br$7$F2<$5$$!#\n" );
1548 }
1549 }
1550
1551 switch ( UserSelectNo ) {
1552 case 1:
1553 /* G-%-%c%i%/%?!<0lMwI=<( */
1554 NekoList();
1555 break;
1556 case 2:
1557 /* G-0\F0s.xneko.c9%H */
1558 NekoMoveTest();
1559 break;
1560 default:
1561 /* Internal Error */
1562 break;
1563 }
1564
1565 fprintf( stderr, "s.xneko.c9%H=*N;!#\n" );
1566 fprintf( stderr, "\n" );
1567 }
1568
1569 #endif /* DEBUG */
1570
1571
1572 /*--------------------------------------------------------------
1573 *
1574 * SIGALRM %7%0%J%k=hM}
1575 *
1576 *--------------------------------------------------------------*/
1577
1578 void
1579 NullFunction()
1580 {
1581 /* No Operation */
1582 }
1583
1584
1585 /*--------------------------------------------------------------
1586 *
1587 * Usage
1588 *
1589 *--------------------------------------------------------------*/
1590
1591 void
1592 Usage()
1593 {
1594 fprintf( stderr,
1595 "Usage: %s [-display <display>] [-geometry <geometry>] \\\n",
1596 ProgramName );
1597 fprintf( stderr, " [-title <title>] [-name <title>] [-iconic] \\\n" );
1598 fprintf( stderr, " [-speed <speed>] [-time <time>] [-help]\n" );
1599 }
1600
1601
1602 /*--------------------------------------------------------------
1603 *
1604 * #Xi%a!<%?I>2A
1605 *
1606 *--------------------------------------------------------------*/
1607
1608 Bool
1609 GetArguments( argc, argv, theDisplayName, theGeometry, theTitle,
1610 NekoSpeed, IntervalTime )
1611 int argc;
1612 char *argv[];
1613 char *theDisplayName;
1614 char *theGeometry;
1615 char *theTitle;
1616 double *NekoSpeed;
1617 long *IntervalTime;
1618 {
1619 int ArgCounter;
1620 Bool iconicState;
1621
1622 theDisplayName[ 0 ] = '\0';
1623 theGeometry[ 0 ] = '\0';
1624 theTitle[ 0 ] = '\0';
1625
1626 iconicState = False;
1627
1628 for ( ArgCounter = 0; ArgCounter < argc; ArgCounter++ ) {
1629
1630 if ( strncmp( argv[ ArgCounter ], "-h", 2 ) == 0 ) {
1631 Usage();
1632 exit( 0 );
1633 } else if ( strcmp( argv[ ArgCounter ], "-display" ) == 0 ) {
1634 ArgCounter++;
1635 if ( ArgCounter < argc ) {
1636 strcpy( theDisplayName, argv[ ArgCounter ] );
1637 } else {
1638 fprintf( stderr, "%s: -display option error.\n", ProgramName );
1639 exit( 1 );
1640 }
1641 } else if ( strncmp( argv[ ArgCounter ], "-geom", 5 ) == 0 ) {
1642 ArgCounter++;
1643 if ( ArgCounter < argc ) {
1644 strcpy( theGeometry, argv[ ArgCounter ] );
1645 } else {
1646 fprintf( stderr,
1647 "%s: -geometry option error.\n", ProgramName );
1648 exit( 1 );
1649 }
1650 } else if ( ( strcmp( argv[ ArgCounter ], "-title" ) == 0 )
1651 || ( strcmp( argv[ ArgCounter ], "-name" ) == 0 ) ) {
1652 ArgCounter++;
1653 if ( ArgCounter < argc ) {
1654 strcpy( theTitle, argv[ ArgCounter ] );
1655 } else {
1656 fprintf( stderr, "%s: -title option error.\n", ProgramName );
1657 exit( 1 );
1658 }
1659 } else if ( strcmp( argv[ ArgCounter ], "-iconic" ) == 0 ) {
1660 iconicState = True;
1661 } else if ( strcmp( argv[ ArgCounter ], "-speed" ) == 0 ) {
1662 ArgCounter++;
1663 if ( ArgCounter < argc ) {
1664 *NekoSpeed = atof( argv[ ArgCounter ] );
1665 } else {
1666 fprintf( stderr, "%s: -speed option error.\n", ProgramName );
1667 exit( 1 );
1668 }
1669 } else if ( strcmp( argv[ ArgCounter ], "-time" ) == 0 ) {
1670 ArgCounter++;
1671 if ( ArgCounter < argc ) {
1672 *IntervalTime = atol( argv[ ArgCounter ] );
1673 } else {
1674 fprintf( stderr, "%s: -time option error.\n", ProgramName );
1675 exit( 1 );
1676 }
1677 } else {
1678 fprintf( stderr,
1679 "%s: Unknown option \"%s\".\n", ProgramName,
1680 argv[ ArgCounter ] );
1681 Usage();
1682 exit( 1 );
1683 }
1684 }
1685
1686 if ( strlen( theDisplayName ) < 1 ) {
1687 theDisplayName = NULL;
1688 }
1689
1690 if ( strlen( theGeometry ) < 1 ) {
1691 theGeometry = NULL;
1692 }
1693
1694 return( iconicState );
1695 }
1696
1697
1698 /*--------------------------------------------------------------
1699 *
1700 * %a%$%s4X?t
1701 *
1702 *--------------------------------------------------------------*/
1703
1704 int
1705 main( argc, argv )
1706 int argc;
1707 char *argv[];
1708 {
1709 Bool iconicState;
1710 char theDisplayName[ DIRNAMELEN ];
1711 char theGeometry[ DIRNAMELEN ];
1712 char theTitle[ DIRNAMELEN ];
1713
1714 ProgramName = argv[ 0 ];
1715
1716 argc--;
1717 argv++;
1718
1719 iconicState = GetArguments( argc, argv,
1720 theDisplayName,
1721 theGeometry,
1722 theTitle,
1723 &NekoSpeed,
1724 &IntervalTime );
1725
1726 InitScreen( theDisplayName, theGeometry, theTitle, iconicState );
1727
1728 signal( SIGALRM, NullFunction );
1729
1730 SinPiPer8Times3 = sin( PI_PER8 * (double)3 );
1731 SinPiPer8 = sin( PI_PER8 );
1732
1733 #ifndef DEBUG
1734 ProcessNeko();
1735 #else
1736 ProcessDebugMenu();
1737 #endif
1738
1739 exit( 0 );
1740 }