home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / games / volume15 / gtetrs2 / part01 < prev    next >
Encoding:
Internet Message Format  |  1993-01-26  |  55.4 KB

  1. Path: uunet!ogicse!zephyr.ens.tek.com!master!saab!billr
  2. From: billr@saab.CNA.TEK.COM (Bill Randle)
  3. Newsgroups: comp.sources.games
  4. Subject: v15i005:  gtetris2 -  Generic Tetris for X11, V1.8, Part01/02
  5. Message-ID: <3733@master.CNA.TEK.COM>
  6. Date: 9 Oct 92 00:49:47 GMT
  7. Article-I.D.: master.3733
  8. Sender: news@master.CNA.TEK.COM
  9. Lines: 1804
  10. Approved: billr@saab.CNA.TEK.COM
  11.  
  12. Submitted-by: "Qiang Alex Zhao" <azhao@cs.arizona.edu>
  13. Posting-number: Volume 15, Issue 5
  14. Archive-name: gtetris2/Part01
  15. Supersedes: gtetris: Volume 15, Issue 1-2
  16. Environment: X11R4/5, Xlib
  17.  
  18.     [This is an updated version of gtetris. Some files were changed
  19.      and added so this is a complete repost, rather than just diffs. -br]
  20.  
  21. #! /bin/sh
  22. # This is a shell archive.  Remove anything before this line, then unpack
  23. # it by saving it into a file and typing "sh file".  To overwrite existing
  24. # files, type "sh file -c".  You can also feed this as standard input via
  25. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  26. # will see the following message at the end:
  27. #        "End of archive 1 (of 2)."
  28. # Contents:  README MANIFEST data.h tetris.h utils.c
  29. # Wrapped by billr@saab on Thu Oct  8 17:46:30 1992
  30. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  31. if test -f 'README' -a "${1}" != "-c" ; then 
  32.   echo shar: Will not clobber existing file \"'README'\"
  33. else
  34. echo shar: Extracting \"'README'\" \(3942 characters\)
  35. sed "s/^X//" >'README' <<'END_OF_FILE'
  36. X    GENERIC TETRIS
  37. X    ==============    Yet Another Tetris Game on X, V1.8
  38. X
  39. X
  40. XWHY ANOTHER?
  41. X
  42. X    Because this one is simple, easy to build, and portable -- actually
  43. X    the blocks are bigger, more comfortable for your eyes. It only uses
  44. X    Xlib -- no "toolkit" kind of thing. People have tested it on the
  45. X    following platforms:
  46. X
  47. X    DEC 5000        Ultrix 4.2A    X11R4
  48. X    HP 9000            HP-UX 7.0    Motif
  49. X    IBM RS6000        AIX 3.1        Motif
  50. X    Iris 4D            IRIX 4.0.1    Motif
  51. X    Sun4, SPARC-2        SunOS 4.1.1    X11R4, X11R5
  52. X    Sequent S81        DYNIX 3.2.0    X11R5
  53. X
  54. X    If your's is not in this list, please let me know -- thanks. The
  55. X    most updated source could be found on export.lcs.mit.edu under
  56. X    /contrib.
  57. X
  58. X    A System V port (Sequent Dynix/ptx) has been added by
  59. X    "Hans-Wolfgang Loidl" (hwloidl@risc.uni-linz.ac.at). The source can
  60. X    be retrieved by anonymous FTP to:
  61. X    Host:    melmac.risc.uni-linz.ac.at
  62. X    File:    /pub/misc/gtetris.tar.Z
  63. X
  64. X
  65. XHOW TO BUILD?
  66. X
  67. X    If you want to put the score-file at a different location (I bet
  68. X    you would), edit the Makefile correspondingly with the make mathod
  69. X    you choose from the following:
  70. X
  71. X    If you you have xmkmf:
  72. X    xmkmf
  73. X    make
  74. X
  75. X    Or use the standard Makefile:
  76. X    make -f Makefile.std
  77. X
  78. X    Also check "local settings" -- if your system is listed there,
  79. X    change "LOCAL_DEFS", "LOCAL_LIBS" and "LINK_LIBS" accordingly.
  80. X
  81. X    "Tetris" is the game. It only lists the top 15 players at the end,
  82. X    each player may has at most three scores.  "Tscores" will list all
  83. X    the players/scores for you.
  84. X
  85. X
  86. XANYTHING SPECIAL IN PLAYING?
  87. X
  88. X    Use "j" to move left; "l" to move right; "k" to rotate. Left-handed
  89. X    people may want to use "s", "d", "f" respectively. Use the space
  90. X    bar to drop a block quickly.
  91. X
  92. X    Use CTRL-L key combination to redraw -- in case it mess somthing up.
  93. X
  94. X    As usual, "+" and "-" will speed up or lower down the speed. Note
  95. X    that you don't need to press the SHIFT key -- "=" and "_" also
  96. X    work. The "b" key can be used to toggle "beep".
  97. X
  98. X    If you press CTRL-S or "p", the game will be paused, and the window
  99. X    will be iconified -- just in case your boss suddenly appears at
  100. X    your door. ;o)
  101. X
  102. X
  103. XFOUND A BUG?
  104. X
  105. X    Send bugs (or their reports, or fixes) to the author:
  106. X
  107. X    Qiang Alex Zhao,    azhao@cs.arizona.edu
  108. X    Computer Science Department
  109. X    University of Arizona
  110. X    Tucson, AZ 85721
  111. X
  112. X    Refter to the "COPYRIGHT" notice in the "COPYRIGHT" file (yeah, as
  113. X    its name implies). And note: my first name is *NOT* spelled as
  114. X    "Quiang".
  115. X
  116. X
  117. XHISTORY -- Oh no, not again: I failed in my history course!
  118. XWell ... ACKNOWLEDGEMENTS
  119. X
  120. X    I studied an old tetris game for X10, wrote by Wayne Christopher
  121. X    <faustus@cs.berkeley.edu> in 1988; then I adopted the ideas in
  122. X    representing those "blocks" and rotating them, and added X11
  123. X    stuff. Also I learned a lot from Nathan Sidwell's great game
  124. X    "xmris", e.g. the "iconifying pause".
  125. X
  126. X    Thanks go to people who helped me in improving the program (see
  127. X    CHANGES).
  128. X
  129. X
  130. XCHANGES
  131. X
  132. X  [Oct 04, 92]  V1.8: Corrected some typos, <herbison@erlang.enet.dec.com>.
  133. X        Added man-page.  Gregg Townsend <gmt@cs.arizona.edu>
  134. X        provided hints for some problems on HP-UX. Imakefile.
  135. X
  136. X  [Sep 27, 92]  V1.6: Changed speed coefficients. Improved window
  137. X        manager hints. Several rows at once worth more points.
  138. X
  139. X  [Sep 25, 92]  V1.5: HP-UX fixes by "Richard van Denzel"
  140. X        <raet-sh!richard@relay.nluug.nl>. Added 'b' to toggle
  141. X        "beep". Rewrote window creation/initialization to fix
  142. X        the "losing input focus" problem.
  143. X
  144. X  [Sep 24, 92]  V1.4: Added <sys/select.h> and -lbsd for AIX (by "Daryl
  145. X        Green" <darylg@amex-trs.com>).
  146. X
  147. X  [Sep 23, 92]  V1.3: Scoring -- a line in a higher level worth more
  148. X        points; "tscores" program. Submitted to
  149. X        comp.sources.games (volumn 15, issues 1-2; it has
  150. X        nothing to do with GNU, but it was called "gtetris",
  151. X        pronounced as "Gee, tetris", by the newsgroup
  152. X        moderator).
  153. X
  154. X  [Sep ??, 92]  First set of versions, 1.0 through 1.2. Put on
  155. X        export.lcs.mit.edu.
  156. X
  157. END_OF_FILE
  158. if test 3942 -ne `wc -c <'README'`; then
  159.     echo shar: \"'README'\" unpacked with wrong size!
  160. fi
  161. # end of 'README'
  162. fi
  163. if test -f 'MANIFEST' -a "${1}" != "-c" ; then 
  164.   echo shar: Will not clobber existing file \"'MANIFEST'\"
  165. else
  166. echo shar: Extracting \"'MANIFEST'\" \(455 characters\)
  167. sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
  168. X   File Name        Archive #    Description
  169. X-----------------------------------------------------------
  170. X COPYRIGHT                  2    
  171. X Imakefile                  2    
  172. X MANIFEST                   1    This shipping list
  173. X Makefile.std               2    
  174. X README                     1    
  175. X data.h                     1    
  176. X die.c                      2    
  177. X tetris.c                   2    
  178. X tetris.h                   1    
  179. X tetris.man                 2    
  180. X utils.c                    1    
  181. END_OF_FILE
  182. if test 455 -ne `wc -c <'MANIFEST'`; then
  183.     echo shar: \"'MANIFEST'\" unpacked with wrong size!
  184. fi
  185. # end of 'MANIFEST'
  186. fi
  187. if test -f 'data.h' -a "${1}" != "-c" ; then 
  188.   echo shar: Will not clobber existing file \"'data.h'\"
  189. else
  190. echo shar: Extracting \"'data.h'\" \(21038 characters\)
  191. sed "s/^X//" >'data.h' <<'END_OF_FILE'
  192. X/*
  193. X# GENERIC X-WINDOW-BASED TETRIS
  194. X#
  195. X#    data.h
  196. X#
  197. X###
  198. X#
  199. X#  Copyright (C) 1992    Qiang Alex Zhao
  200. X#            Computer Science Dept, University of Arizona
  201. X#            azhao@cs.arizona.edu
  202. X#
  203. X#            All Rights Reserved
  204. X#
  205. X#  Permission to use, copy, modify, and distribute this software and
  206. X#  its documentation for any purpose and without fee is hereby granted,
  207. X#  provided that the above copyright notice appear in all copies and
  208. X#  that both that copyright notice and this permission notice appear in
  209. X#  supporting documentation, and that the name of the author not be
  210. X#  used in advertising or publicity pertaining to distribution of the
  211. X#  software without specific, written prior permission.
  212. X#
  213. X#  This program is distributed in the hope that it will be "playable",
  214. X#  but WITHOUT ANY WARRANTY; without even the implied warranty of
  215. X#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  216. X#
  217. X*/
  218. X
  219. X#define rot00_width 30
  220. X#define rot00_height 30
  221. Xstatic char rot00_bits[] = {
  222. X   0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0xff, 0x03, 0xf8, 0xff, 0xff, 0x07,
  223. X   0x5c, 0x55, 0x55, 0x0f, 0xae, 0xaa, 0xaa, 0x1e, 0x56, 0x55, 0x55, 0x1d,
  224. X   0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d, 0xae, 0xaa, 0xaa, 0x1a,
  225. X   0x56, 0x55, 0x55, 0x1d, 0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d,
  226. X   0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d, 0xae, 0x6a, 0xaa, 0x1a,
  227. X   0x56, 0x95, 0x55, 0x1d, 0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d,
  228. X   0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d, 0xae, 0xaa, 0xaa, 0x1a,
  229. X   0x56, 0x55, 0x55, 0x1d, 0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d,
  230. X   0xae, 0xaa, 0xaa, 0x1a, 0x5e, 0x55, 0x55, 0x1d, 0xbc, 0xaa, 0xaa, 0x0e,
  231. X   0xf8, 0xff, 0xff, 0x07, 0xf0, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00};
  232. X
  233. X#define rot01_width 30
  234. X#define rot01_height 30
  235. Xstatic char rot01_bits[] = {
  236. X   0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x03, 0xff, 0xff, 0xff, 0x07,
  237. X   0x55, 0x55, 0x55, 0x0f, 0xaa, 0xaa, 0xaa, 0x1e, 0x55, 0x55, 0x55, 0x1d,
  238. X   0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d, 0xaa, 0xaa, 0xaa, 0x1a,
  239. X   0x55, 0x55, 0x55, 0x1d, 0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d,
  240. X   0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d, 0xaa, 0x6a, 0xaa, 0x1a,
  241. X   0x55, 0x95, 0x55, 0x1d, 0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d,
  242. X   0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d, 0xaa, 0xaa, 0xaa, 0x1a,
  243. X   0x55, 0x55, 0x55, 0x1d, 0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d,
  244. X   0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d, 0xaa, 0xaa, 0xaa, 0x0e,
  245. X   0xff, 0xff, 0xff, 0x07, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00};
  246. X
  247. X#define rot02_width 30
  248. X#define rot02_height 30
  249. Xstatic char rot02_bits[] = {
  250. X   0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0xff, 0x03, 0xf8, 0xff, 0xff, 0x07,
  251. X   0x5c, 0x55, 0x55, 0x0f, 0xae, 0xaa, 0xaa, 0x1e, 0x56, 0x55, 0x55, 0x1d,
  252. X   0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d, 0xae, 0xaa, 0xaa, 0x1a,
  253. X   0x56, 0x55, 0x55, 0x1d, 0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d,
  254. X   0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d, 0xae, 0x6a, 0xaa, 0x1a,
  255. X   0x56, 0x95, 0x55, 0x1d, 0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d,
  256. X   0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d, 0xae, 0xaa, 0xaa, 0x1a,
  257. X   0x56, 0x55, 0x55, 0x1d, 0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d,
  258. X   0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d, 0xae, 0xaa, 0xaa, 0x1a,
  259. X   0x56, 0x55, 0x55, 0x1d, 0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d};
  260. X
  261. X#define rot03_width 30
  262. X#define rot03_height 30
  263. Xstatic char rot03_bits[] = {
  264. X   0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x03, 0xff, 0xff, 0xff, 0x07,
  265. X   0x55, 0x55, 0x55, 0x0f, 0xaa, 0xaa, 0xaa, 0x1e, 0x55, 0x55, 0x55, 0x1d,
  266. X   0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d, 0xaa, 0xaa, 0xaa, 0x1a,
  267. X   0x55, 0x55, 0x55, 0x1d, 0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d,
  268. X   0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d, 0xaa, 0x6a, 0xaa, 0x1a,
  269. X   0x55, 0x95, 0x55, 0x1d, 0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d,
  270. X   0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d, 0xaa, 0xaa, 0xaa, 0x1a,
  271. X   0x55, 0x55, 0x55, 0x1d, 0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d,
  272. X   0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d, 0xaa, 0xaa, 0xaa, 0x1a,
  273. X   0x57, 0x55, 0x55, 0x1d, 0xaf, 0xaa, 0xaa, 0x1a, 0x57, 0x55, 0x55, 0x1d};
  274. X
  275. X#define rot04_width 30
  276. X#define rot04_height 30
  277. Xstatic char rot04_bits[] = {
  278. X   0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0xff, 0x3f, 0xf8, 0xff, 0xff, 0x3f,
  279. X   0x5c, 0x55, 0x55, 0x15, 0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15,
  280. X   0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15, 0xae, 0xaa, 0xaa, 0x2a,
  281. X   0x56, 0x55, 0x55, 0x15, 0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15,
  282. X   0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15, 0xae, 0x6a, 0xaa, 0x2a,
  283. X   0x56, 0x95, 0x55, 0x15, 0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15,
  284. X   0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15, 0xae, 0xaa, 0xaa, 0x2a,
  285. X   0x56, 0x55, 0x55, 0x15, 0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15,
  286. X   0xae, 0xaa, 0xaa, 0x2a, 0x5e, 0x55, 0x55, 0x15, 0xbc, 0xaa, 0xaa, 0x2a,
  287. X   0xf8, 0xff, 0xff, 0x3f, 0xf0, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00};
  288. X
  289. X#define rot05_width 30
  290. X#define rot05_height 30
  291. Xstatic char rot05_bits[] = {
  292. X   0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 0x3f,
  293. X   0x55, 0x55, 0x55, 0x15, 0xaa, 0xaa, 0xaa, 0x2a, 0x55, 0x55, 0x55, 0x15,
  294. X   0xaa, 0xaa, 0xaa, 0x2a, 0x55, 0x55, 0x55, 0x15, 0xaa, 0xaa, 0xaa, 0x2a,
  295. X   0x55, 0x55, 0x55, 0x15, 0xaa, 0xaa, 0xaa, 0x2a, 0x55, 0x55, 0x55, 0x15,
  296. X   0xaa, 0xaa, 0xaa, 0x2a, 0x55, 0x55, 0x55, 0x15, 0xaa, 0x6a, 0xaa, 0x2a,
  297. X   0x55, 0x95, 0x55, 0x15, 0xaa, 0xaa, 0xaa, 0x2a, 0x55, 0x55, 0x55, 0x15,
  298. X   0xaa, 0xaa, 0xaa, 0x2a, 0x55, 0x55, 0x55, 0x15, 0xaa, 0xaa, 0xaa, 0x2a,
  299. X   0x55, 0x55, 0x55, 0x15, 0xaa, 0xaa, 0xaa, 0x2a, 0x55, 0x55, 0x55, 0x15,
  300. X   0xaa, 0xaa, 0xaa, 0x2a, 0x55, 0x55, 0x55, 0x15, 0xaa, 0xaa, 0xaa, 0x2a,
  301. X   0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00};
  302. X
  303. X#define rot06_width 30
  304. X#define rot06_height 30
  305. Xstatic char rot06_bits[] = {
  306. X   0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0xff, 0x3f, 0xf8, 0xff, 0xff, 0x3f,
  307. X   0x5c, 0x55, 0x55, 0x15, 0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15,
  308. X   0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15, 0xae, 0xaa, 0xaa, 0x2a,
  309. X   0x56, 0x55, 0x55, 0x15, 0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15,
  310. X   0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15, 0xae, 0x6a, 0xaa, 0x2a,
  311. X   0x56, 0x95, 0x55, 0x15, 0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15,
  312. X   0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15, 0xae, 0xaa, 0xaa, 0x2a,
  313. X   0x56, 0x55, 0x55, 0x15, 0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15,
  314. X   0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15, 0xae, 0xaa, 0xaa, 0x2a,
  315. X   0x56, 0x55, 0x55, 0x3d, 0xae, 0xaa, 0xaa, 0x3a, 0x56, 0x55, 0x55, 0x3d};
  316. X
  317. X#define rot07_width 30
  318. X#define rot07_height 30
  319. Xstatic char rot07_bits[] = {
  320. X   0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 0x3f,
  321. X   0x55, 0x55, 0x55, 0x15, 0xaa, 0xaa, 0xaa, 0x2a, 0x55, 0x55, 0x55, 0x15,
  322. X   0xaa, 0xaa, 0xaa, 0x2a, 0x55, 0x55, 0x55, 0x15, 0xaa, 0xaa, 0xaa, 0x2a,
  323. X   0x55, 0x55, 0x55, 0x15, 0xaa, 0xaa, 0xaa, 0x2a, 0x55, 0x55, 0x55, 0x15,
  324. X   0xaa, 0xaa, 0xaa, 0x2a, 0x55, 0x55, 0x55, 0x15, 0xaa, 0x6a, 0xaa, 0x2a,
  325. X   0x55, 0x95, 0x55, 0x15, 0xaa, 0xaa, 0xaa, 0x2a, 0x55, 0x55, 0x55, 0x15,
  326. X   0xaa, 0xaa, 0xaa, 0x2a, 0x55, 0x55, 0x55, 0x15, 0xaa, 0xaa, 0xaa, 0x2a,
  327. X   0x55, 0x55, 0x55, 0x15, 0xaa, 0xaa, 0xaa, 0x2a, 0x55, 0x55, 0x55, 0x15,
  328. X   0xaa, 0xaa, 0xaa, 0x2a, 0x55, 0x55, 0x55, 0x15, 0xaa, 0xaa, 0xaa, 0x2a,
  329. X   0x57, 0x55, 0x55, 0x3d, 0xaf, 0xaa, 0xaa, 0x3a, 0x57, 0x55, 0x55, 0x3d};
  330. X
  331. X#define rot08_width 30
  332. X#define rot08_height 30
  333. Xstatic char rot08_bits[] = {
  334. X   0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d, 0xae, 0xaa, 0xaa, 0x1a,
  335. X   0x56, 0x55, 0x55, 0x1d, 0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d,
  336. X   0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d, 0xae, 0xaa, 0xaa, 0x1a,
  337. X   0x56, 0x55, 0x55, 0x1d, 0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d,
  338. X   0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d, 0xae, 0x6a, 0xaa, 0x1a,
  339. X   0x56, 0x95, 0x55, 0x1d, 0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d,
  340. X   0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d, 0xae, 0xaa, 0xaa, 0x1a,
  341. X   0x56, 0x55, 0x55, 0x1d, 0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d,
  342. X   0xae, 0xaa, 0xaa, 0x1a, 0x5e, 0x55, 0x55, 0x1d, 0xbc, 0xaa, 0xaa, 0x0e,
  343. X   0xf8, 0xff, 0xff, 0x07, 0xf0, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00};
  344. X
  345. X#define rot09_width 30
  346. X#define rot09_height 30
  347. Xstatic char rot09_bits[] = {
  348. X   0xaf, 0xaa, 0xaa, 0x1a, 0x57, 0x55, 0x55, 0x1d, 0xaf, 0xaa, 0xaa, 0x1a,
  349. X   0x55, 0x55, 0x55, 0x1d, 0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d,
  350. X   0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d, 0xaa, 0xaa, 0xaa, 0x1a,
  351. X   0x55, 0x55, 0x55, 0x1d, 0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d,
  352. X   0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d, 0xaa, 0x6a, 0xaa, 0x1a,
  353. X   0x55, 0x95, 0x55, 0x1d, 0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d,
  354. X   0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d, 0xaa, 0xaa, 0xaa, 0x1a,
  355. X   0x55, 0x55, 0x55, 0x1d, 0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d,
  356. X   0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d, 0xaa, 0xaa, 0xaa, 0x0e,
  357. X   0xff, 0xff, 0xff, 0x07, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00};
  358. X
  359. X#define rot10_width 30
  360. X#define rot10_height 30
  361. Xstatic char rot10_bits[] = {
  362. X   0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d, 0xae, 0xaa, 0xaa, 0x1a,
  363. X   0x56, 0x55, 0x55, 0x1d, 0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d,
  364. X   0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d, 0xae, 0xaa, 0xaa, 0x1a,
  365. X   0x56, 0x55, 0x55, 0x1d, 0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d,
  366. X   0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d, 0xae, 0x6a, 0xaa, 0x1a,
  367. X   0x56, 0x95, 0x55, 0x1d, 0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d,
  368. X   0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d, 0xae, 0xaa, 0xaa, 0x1a,
  369. X   0x56, 0x55, 0x55, 0x1d, 0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d,
  370. X   0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d, 0xae, 0xaa, 0xaa, 0x1a,
  371. X   0x56, 0x55, 0x55, 0x1d, 0xae, 0xaa, 0xaa, 0x1a, 0x56, 0x55, 0x55, 0x1d};
  372. X
  373. X#define rot11_width 30
  374. X#define rot11_height 30
  375. Xstatic char rot11_bits[] = {
  376. X   0xaf, 0xaa, 0xaa, 0x1a, 0x57, 0x55, 0x55, 0x1d, 0xaf, 0xaa, 0xaa, 0x1a,
  377. X   0x55, 0x55, 0x55, 0x1d, 0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d,
  378. X   0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d, 0xaa, 0xaa, 0xaa, 0x1a,
  379. X   0x55, 0x55, 0x55, 0x1d, 0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d,
  380. X   0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d, 0xaa, 0x6a, 0xaa, 0x1a,
  381. X   0x55, 0x95, 0x55, 0x1d, 0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d,
  382. X   0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d, 0xaa, 0xaa, 0xaa, 0x1a,
  383. X   0x55, 0x55, 0x55, 0x1d, 0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d,
  384. X   0xaa, 0xaa, 0xaa, 0x1a, 0x55, 0x55, 0x55, 0x1d, 0xaa, 0xaa, 0xaa, 0x1a,
  385. X   0x57, 0x55, 0x55, 0x1d, 0xaf, 0xaa, 0xaa, 0x1a, 0x57, 0x55, 0x55, 0x1d};
  386. X
  387. X#define rot12_width 30
  388. X#define rot12_height 30
  389. Xstatic char rot12_bits[] = {
  390. X   0xae, 0xaa, 0xaa, 0x3a, 0x56, 0x55, 0x55, 0x3d, 0xae, 0xaa, 0xaa, 0x3a,
  391. X   0x56, 0x55, 0x55, 0x15, 0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15,
  392. X   0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15, 0xae, 0xaa, 0xaa, 0x2a,
  393. X   0x56, 0x55, 0x55, 0x15, 0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15,
  394. X   0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15, 0xae, 0x6a, 0xaa, 0x2a,
  395. X   0x56, 0x95, 0x55, 0x15, 0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15,
  396. X   0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15, 0xae, 0xaa, 0xaa, 0x2a,
  397. X   0x56, 0x55, 0x55, 0x15, 0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15,
  398. X   0xae, 0xaa, 0xaa, 0x2a, 0x5e, 0x55, 0x55, 0x15, 0xbc, 0xaa, 0xaa, 0x2a,
  399. X   0xf8, 0xff, 0xff, 0x3f, 0xf0, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00};
  400. X
  401. X#define rot13_width 30
  402. X#define rot13_height 30
  403. Xstatic char rot13_bits[] = {
  404. X   0xaf, 0xaa, 0xaa, 0x3a, 0x57, 0x55, 0x55, 0x3d, 0xaf, 0xaa, 0xaa, 0x3a,
  405. X   0x55, 0x55, 0x55, 0x15, 0xaa, 0xaa, 0xaa, 0x2a, 0x55, 0x55, 0x55, 0x15,
  406. X   0xaa, 0xaa, 0xaa, 0x2a, 0x55, 0x55, 0x55, 0x15, 0xaa, 0xaa, 0xaa, 0x2a,
  407. X   0x55, 0x55, 0x55, 0x15, 0xaa, 0xaa, 0xaa, 0x2a, 0x55, 0x55, 0x55, 0x15,
  408. X   0xaa, 0xaa, 0xaa, 0x2a, 0x55, 0x55, 0x55, 0x15, 0xaa, 0x6a, 0xaa, 0x2a,
  409. X   0x55, 0x95, 0x55, 0x15, 0xaa, 0xaa, 0xaa, 0x2a, 0x55, 0x55, 0x55, 0x15,
  410. X   0xaa, 0xaa, 0xaa, 0x2a, 0x55, 0x55, 0x55, 0x15, 0xaa, 0xaa, 0xaa, 0x2a,
  411. X   0x55, 0x55, 0x55, 0x15, 0xaa, 0xaa, 0xaa, 0x2a, 0x55, 0x55, 0x55, 0x15,
  412. X   0xaa, 0xaa, 0xaa, 0x2a, 0x55, 0x55, 0x55, 0x15, 0xaa, 0xaa, 0xaa, 0x2a,
  413. X   0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0x00};
  414. X
  415. X#define rot14_width 30
  416. X#define rot14_height 30
  417. Xstatic char rot14_bits[] = {
  418. X   0xae, 0xaa, 0xaa, 0x3a, 0x56, 0x55, 0x55, 0x3d, 0xae, 0xaa, 0xaa, 0x3a,
  419. X   0x56, 0x55, 0x55, 0x15, 0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15,
  420. X   0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15, 0xae, 0xaa, 0xaa, 0x2a,
  421. X   0x56, 0x55, 0x55, 0x15, 0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15,
  422. X   0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15, 0xae, 0x6a, 0xaa, 0x2a,
  423. X   0x56, 0x95, 0x55, 0x15, 0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15,
  424. X   0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15, 0xae, 0xaa, 0xaa, 0x2a,
  425. X   0x56, 0x55, 0x55, 0x15, 0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15,
  426. X   0xae, 0xaa, 0xaa, 0x2a, 0x56, 0x55, 0x55, 0x15, 0xae, 0xaa, 0xaa, 0x2a,
  427. X   0x56, 0x55, 0x55, 0x3d, 0xae, 0xaa, 0xaa, 0x3a, 0x56, 0x55, 0x55, 0x3d};
  428. X
  429. Xbitmap_t        bitmap_data[] = {
  430. X    {
  431. X    rot00_bits, rot00_height, rot00_width
  432. X    },
  433. X    {
  434. X    rot01_bits, rot01_height, rot01_width
  435. X    },
  436. X    {
  437. X    rot02_bits, rot02_height, rot02_width
  438. X    },
  439. X    {
  440. X    rot03_bits, rot03_height, rot03_width
  441. X    },
  442. X    {
  443. X    rot04_bits, rot04_height, rot04_width
  444. X    },
  445. X    {
  446. X    rot05_bits, rot05_height, rot05_width
  447. X    },
  448. X    {
  449. X    rot06_bits, rot06_height, rot06_width
  450. X    },
  451. X    {
  452. X    rot07_bits, rot07_height, rot07_width
  453. X    },
  454. X    {
  455. X    rot08_bits, rot08_height, rot08_width
  456. X    },
  457. X    {
  458. X    rot09_bits, rot09_height, rot09_width
  459. X    },
  460. X    {
  461. X    rot10_bits, rot10_height, rot10_width
  462. X    },
  463. X    {
  464. X    rot11_bits, rot11_height, rot11_width
  465. X    },
  466. X    {
  467. X    rot12_bits, rot12_height, rot12_width
  468. X    },
  469. X    {
  470. X    rot13_bits, rot13_height, rot13_width
  471. X    },
  472. X    {
  473. X    rot14_bits, rot14_height, rot14_width
  474. X    }
  475. X};
  476. X
  477. Xpattern_t       patterns[] = {
  478. X    {0, "magenta", "white", DUMC, DUMC, DUMP},
  479. X    {1, "magenta", "white", DUMC, DUMC, DUMP},
  480. X    {2, "magenta", "white", DUMC, DUMC, DUMP},
  481. X    {3, "magenta", "white", DUMC, DUMC, DUMP},
  482. X    {4, "magenta", "white", DUMC, DUMC, DUMP},
  483. X    {5, "magenta", "white", DUMC, DUMC, DUMP},
  484. X    {6, "magenta", "white", DUMC, DUMC, DUMP},
  485. X    {7, "magenta", "white", DUMC, DUMC, DUMP},
  486. X    {8, "magenta", "white", DUMC, DUMC, DUMP},
  487. X    {9, "magenta", "white", DUMC, DUMC, DUMP},
  488. X    {10, "magenta", "white", DUMC, DUMC, DUMP},
  489. X    {11, "magenta", "white", DUMC, DUMC, DUMP},
  490. X    {12, "magenta", "white", DUMC, DUMC, DUMP},
  491. X    {13, "magenta", "white", DUMC, DUMC, DUMP},
  492. X    {14, "magenta", "white", DUMC, DUMC, DUMP},
  493. X    {0, "magenta", "white", DUMC, DUMC, DUMP},
  494. X    {0, "forest green", "white", DUMC, DUMC, DUMP},
  495. X    {1, "forest green", "white", DUMC, DUMC, DUMP},
  496. X    {2, "forest green", "white", DUMC, DUMC, DUMP},
  497. X    {3, "forest green", "white", DUMC, DUMC, DUMP},
  498. X    {4, "forest green", "white", DUMC, DUMC, DUMP},
  499. X    {5, "forest green", "white", DUMC, DUMC, DUMP},
  500. X    {6, "forest green", "white", DUMC, DUMC, DUMP},
  501. X    {7, "forest green", "white", DUMC, DUMC, DUMP},
  502. X    {8, "forest green", "white", DUMC, DUMC, DUMP},
  503. X    {9, "forest green", "white", DUMC, DUMC, DUMP},
  504. X    {10, "forest green", "white", DUMC, DUMC, DUMP},
  505. X    {11, "forest green", "white", DUMC, DUMC, DUMP},
  506. X    {12, "forest green", "white", DUMC, DUMC, DUMP},
  507. X    {13, "forest green", "white", DUMC, DUMC, DUMP},
  508. X    {14, "forest green", "white", DUMC, DUMC, DUMP},
  509. X    {0, "forest green", "white", DUMC, DUMC, DUMP},
  510. X    {0, "blue", "white", DUMC, DUMC, DUMP},
  511. X    {1, "blue", "white", DUMC, DUMC, DUMP},
  512. X    {2, "blue", "white", DUMC, DUMC, DUMP},
  513. X    {3, "blue", "white", DUMC, DUMC, DUMP},
  514. X    {4, "blue", "white", DUMC, DUMC, DUMP},
  515. X    {5, "blue", "white", DUMC, DUMC, DUMP},
  516. X    {6, "blue", "white", DUMC, DUMC, DUMP},
  517. X    {7, "blue", "white", DUMC, DUMC, DUMP},
  518. X    {8, "blue", "white", DUMC, DUMC, DUMP},
  519. X    {9, "blue", "white", DUMC, DUMC, DUMP},
  520. X    {10, "blue", "white", DUMC, DUMC, DUMP},
  521. X    {11, "blue", "white", DUMC, DUMC, DUMP},
  522. X    {12, "blue", "white", DUMC, DUMC, DUMP},
  523. X    {13, "blue", "white", DUMC, DUMC, DUMP},
  524. X    {14, "blue", "white", DUMC, DUMC, DUMP},
  525. X    {0, "blue", "white", DUMC, DUMC, DUMP},
  526. X    {0, "red", "white", DUMC, DUMC, DUMP},
  527. X    {1, "red", "white", DUMC, DUMC, DUMP},
  528. X    {2, "red", "white", DUMC, DUMC, DUMP},
  529. X    {3, "red", "white", DUMC, DUMC, DUMP},
  530. X    {4, "red", "white", DUMC, DUMC, DUMP},
  531. X    {5, "red", "white", DUMC, DUMC, DUMP},
  532. X    {6, "red", "white", DUMC, DUMC, DUMP},
  533. X    {7, "red", "white", DUMC, DUMC, DUMP},
  534. X    {8, "red", "white", DUMC, DUMC, DUMP},
  535. X    {9, "red", "white", DUMC, DUMC, DUMP},
  536. X    {10, "red", "white", DUMC, DUMC, DUMP},
  537. X    {11, "red", "white", DUMC, DUMC, DUMP},
  538. X    {12, "red", "white", DUMC, DUMC, DUMP},
  539. X    {13, "red", "white", DUMC, DUMC, DUMP},
  540. X    {14, "red", "white", DUMC, DUMC, DUMP},
  541. X    {0, "red", "white", DUMC, DUMC, DUMP},
  542. X    {0, "dark turquoise", "white", DUMC, DUMC, DUMP},
  543. X    {1, "dark turquoise", "white", DUMC, DUMC, DUMP},
  544. X    {2, "dark turquoise", "white", DUMC, DUMC, DUMP},
  545. X    {3, "dark turquoise", "white", DUMC, DUMC, DUMP},
  546. X    {4, "dark turquoise", "white", DUMC, DUMC, DUMP},
  547. X    {5, "dark turquoise", "white", DUMC, DUMC, DUMP},
  548. X    {6, "dark turquoise", "white", DUMC, DUMC, DUMP},
  549. X    {7, "dark turquoise", "white", DUMC, DUMC, DUMP},
  550. X    {8, "dark turquoise", "white", DUMC, DUMC, DUMP},
  551. X    {9, "dark turquoise", "white", DUMC, DUMC, DUMP},
  552. X    {10, "dark turquoise", "white", DUMC, DUMC, DUMP},
  553. X    {11, "dark turquoise", "white", DUMC, DUMC, DUMP},
  554. X    {12, "dark turquoise", "white", DUMC, DUMC, DUMP},
  555. X    {13, "dark turquoise", "white", DUMC, DUMC, DUMP},
  556. X    {14, "dark turquoise", "white", DUMC, DUMC, DUMP},
  557. X    {0, "dark turquoise", "white", DUMC, DUMC, DUMP},
  558. X    {0, "black", "white", DUMC, DUMC, DUMP},
  559. X    {1, "black", "white", DUMC, DUMC, DUMP},
  560. X    {2, "black", "white", DUMC, DUMC, DUMP},
  561. X    {3, "black", "white", DUMC, DUMC, DUMP},
  562. X    {4, "black", "white", DUMC, DUMC, DUMP},
  563. X    {5, "black", "white", DUMC, DUMC, DUMP},
  564. X    {6, "black", "white", DUMC, DUMC, DUMP},
  565. X    {7, "black", "white", DUMC, DUMC, DUMP},
  566. X    {8, "black", "white", DUMC, DUMC, DUMP},
  567. X    {9, "black", "white", DUMC, DUMC, DUMP},
  568. X    {10, "black", "white", DUMC, DUMC, DUMP},
  569. X    {11, "black", "white", DUMC, DUMC, DUMP},
  570. X    {12, "black", "white", DUMC, DUMC, DUMP},
  571. X    {13, "black", "white", DUMC, DUMC, DUMP},
  572. X    {14, "black", "white", DUMC, DUMC, DUMP},
  573. X    {0, "brown", "white", DUMC, DUMC, DUMP},
  574. X    {0, "brown", "white", DUMC, DUMC, DUMP},
  575. X    {1, "brown", "white", DUMC, DUMC, DUMP},
  576. X    {2, "brown", "white", DUMC, DUMC, DUMP},
  577. X    {3, "brown", "white", DUMC, DUMC, DUMP},
  578. X    {4, "brown", "white", DUMC, DUMC, DUMP},
  579. X    {5, "brown", "white", DUMC, DUMC, DUMP},
  580. X    {6, "brown", "white", DUMC, DUMC, DUMP},
  581. X    {7, "brown", "white", DUMC, DUMC, DUMP},
  582. X    {8, "brown", "white", DUMC, DUMC, DUMP},
  583. X    {9, "brown", "white", DUMC, DUMC, DUMP},
  584. X    {10, "brown", "white", DUMC, DUMC, DUMP},
  585. X    {11, "brown", "white", DUMC, DUMC, DUMP},
  586. X    {12, "brown", "white", DUMC, DUMC, DUMP},
  587. X    {13, "brown", "white", DUMC, DUMC, DUMP},
  588. X    {14, "brown", "white", DUMC, DUMC, DUMP},
  589. X    {0, "brown", "white", DUMC, DUMC, DUMP}
  590. X};
  591. X
  592. X#define NUM_PATTERNS    (sizeof (patterns) / sizeof (patterns[0]))
  593. X
  594. Xint             num_patterns = NUM_PATTERNS;
  595. X
  596. Xthing_t         possible[] = {
  597. X
  598. X    {{{0, 0, 0, 0},
  599. X    {1, 1, 1, 1},
  600. X    {0, 0, 0, 0},
  601. X    {0, 0, 0, 0}}, 0, 0, 4, 1},
  602. X
  603. X    {{{0, 1, 0, 0},
  604. X    {0, 1, 0, 0},
  605. X    {1, 1, 0, 0},
  606. X    {0, 0, 0, 0}}, 0, 0, 3, 1},
  607. X
  608. X    {{{1, 0, 0, 0},
  609. X    {1, 0, 0, 0},
  610. X    {1, 1, 0, 0},
  611. X    {0, 0, 0, 0}}, 0, 0, 3, 1},
  612. X
  613. X    {{{0, 1, 0, 0},
  614. X    {1, 1, 0, 0},
  615. X    {1, 0, 0, 0},
  616. X    {0, 0, 0, 0}}, 0, 0, 3, 1},
  617. X
  618. X    {{{1, 0, 0, 0},
  619. X    {1, 1, 0, 0},
  620. X    {0, 1, 0, 0},
  621. X    {0, 0, 0, 0}}, 0, 0, 3, 1},
  622. X
  623. X    {{{1, 1, 0, 0},
  624. X    {1, 1, 0, 0},
  625. X    {0, 0, 0, 0},
  626. X    {0, 0, 0, 0}}, 0, 0, 2, 1},
  627. X
  628. X    {{{0, 1, 0, 0},
  629. X    {1, 1, 1, 0},
  630. X    {0, 0, 0, 0},
  631. X    {0, 0, 0, 0}}, 0, 0, 3, 2},
  632. X};
  633. X
  634. X#define NUM_POSSIBLE    (sizeof (possible) / sizeof (possible[0]))
  635. X
  636. Xint             speeds[NUM_LEVELS] =
  637. X    {100, 92, 84, 76, 68, 60, 52, 43, 37, 31, 25, 19, 13, 7, 5, 3, 0};
  638. X
  639. Xint             thresh[NUM_LEVELS] =
  640. X    {10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, INF};
  641. X
  642. X/* variables used in tetris.c */
  643. X
  644. XXColor          bgcolor, bdcolor, titlecolor, textcolor;
  645. XColormap        cmap;
  646. X
  647. XDisplay        *disp;
  648. XGC              gc_t;
  649. XGC              gc_w;
  650. XGC              gc_w2;
  651. XGC              gc_ttx;
  652. XGC              gc_wtx;
  653. XGC              gc_pat[NUM_PATTERNS];
  654. XXGCValues       gcv;
  655. XXGCValues       color;
  656. XXGCValues       text;
  657. X
  658. XBool            beep = False;
  659. Xchar           *winName = "GENERIC TETRIS";
  660. Xchar           *iconName = "TETRIS";
  661. X
  662. Xint             rootScreen;
  663. Xint             rootDepth;
  664. X
  665. END_OF_FILE
  666. if test 21038 -ne `wc -c <'data.h'`; then
  667.     echo shar: \"'data.h'\" unpacked with wrong size!
  668. fi
  669. # end of 'data.h'
  670. fi
  671. if test -f 'tetris.h' -a "${1}" != "-c" ; then 
  672.   echo shar: Will not clobber existing file \"'tetris.h'\"
  673. else
  674. echo shar: Extracting \"'tetris.h'\" \(5752 characters\)
  675. sed "s/^X//" >'tetris.h' <<'END_OF_FILE'
  676. X/*
  677. X# GENERIC X-WINDOW-BASED TETRIS
  678. X#
  679. X#    tetris.h
  680. X#
  681. X###
  682. X#
  683. X#  Copyright (C) 1992    Qiang Alex Zhao
  684. X#            Computer Science Dept, University of Arizona
  685. X#            azhao@cs.arizona.edu
  686. X#
  687. X#            All Rights Reserved
  688. X#
  689. X#  Permission to use, copy, modify, and distribute this software and
  690. X#  its documentation for any purpose and without fee is hereby granted,
  691. X#  provided that the above copyright notice appear in all copies and
  692. X#  that both that copyright notice and this permission notice appear in
  693. X#  supporting documentation, and that the name of the author not be
  694. X#  used in advertising or publicity pertaining to distribution of the
  695. X#  software without specific, written prior permission.
  696. X#
  697. X#  This program is distributed in the hope that it will be "playable",
  698. X#  but WITHOUT ANY WARRANTY; without even the implied warranty of
  699. X#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  700. X#
  701. X*/
  702. X
  703. X/*
  704. X * Common defs
  705. X */
  706. X
  707. X#include    <stdio.h>
  708. X#include    <sys/types.h>
  709. X#include    <sys/errno.h>
  710. X#include    <sys/file.h>
  711. X#include    <pwd.h>
  712. X
  713. X#ifdef    SYSV    /* for Imake */
  714. X#include    <string.h>
  715. X#else
  716. X#include    <strings.h>
  717. X#endif
  718. X
  719. X#ifdef    HPUX
  720. X#include    <unistd.h>
  721. X#include    <time.h>
  722. X#define    random()    lrand48()
  723. X#define    srandom(x)    srand48(x)
  724. X#define    LOCK(X)        lockf((X), F_LOCK, 0)
  725. X#define    ULOCK(X)    lockf((X), F_ULOCK, 0)
  726. X#else
  727. X#include    <sys/time.h>
  728. X#define    LOCK(X)        flock((X), LOCK_EX)
  729. X#define    ULOCK(X)    flock((X), LOCK_UN)
  730. X#endif
  731. X
  732. X#ifdef    AIX
  733. X#include    <sys/select.h>
  734. X#endif
  735. X
  736. X/*
  737. X * X related
  738. X */
  739. X
  740. X#include    <X11/Xlib.h>
  741. X#include    <X11/Xutil.h>
  742. X#include    <X11/cursorfont.h>
  743. X#include    <X11/keysym.h>
  744. X
  745. X/*
  746. X * Assertion
  747. X */
  748. X
  749. X#define    assert(E, X)    if ((E)==0) \
  750. X            { fprintf(stderr, \
  751. X             "Assertion failed, line %d, fill %s: %s\n", \
  752. X             __LINE__, __FILE__, (X)); \
  753. X             exit(-1); }
  754. X
  755. X/*
  756. X * Tetris defs
  757. X */
  758. X
  759. X/* score file */
  760. X#ifndef    SCOREFILE
  761. X#define SCOREFILE    "/usr/games/.tetris.scores"
  762. X#endif
  763. X
  764. X/* Maximum # of scores allowed per person */
  765. X#ifndef    MAXSCORES
  766. X#define MAXSCORES 3
  767. X#endif
  768. X
  769. X/* number of scores shown */
  770. X#ifndef    SHOWNSCORES
  771. X#define    SHOWNSCORES    15
  772. X#endif
  773. X
  774. X/* fonts */
  775. X#define TITLE_FONT      "-*-new century schoolbook-bold-r-*-*-24-*-*-*-*-*-*-*"
  776. X#define SCORE_FONT      "-*-times-bold-r-*-*-12-*-*-*-*-*-*-*"
  777. X
  778. X/* if the above fonts cannot be allocated, try the following */
  779. X#define    TITLE_FONT2    "-*-*-bold-r-*-*-24-*-*-*-*-*-*-*"
  780. X#define SCORE_FONT2    "-*-*-bold-r-*-*-12-*-*-*-*-*-*-*"
  781. X
  782. X/****************************/
  783. X
  784. X#define    NAMELEN        12
  785. X
  786. X#define NUM_BITMAPS    (sizeof (bitmap_data) / sizeof (bitmap_data[0]))
  787. X
  788. X#define DEF_WIDTH    10
  789. X#define DEF_HEIGHT    20
  790. X
  791. X#define BOX_HEIGHT    30
  792. X#define BOX_WIDTH    30
  793. X
  794. X#define BOX_SPACE    1
  795. X
  796. X#define X_MARGIN    1
  797. X#define Y_MARGIN    1
  798. X
  799. X#define THING_SIZE    4
  800. X
  801. X#define BASE_XPOS    100
  802. X#define BASE_YPOS    100
  803. X
  804. X#define BORDER_WIDTH    3
  805. X
  806. X#define TITLE_HEIGHT    40
  807. X
  808. X#define NUM_FLASHES    15
  809. X
  810. X#define SCORE_XPOS1    150
  811. X#define SCORE_XPOS2    230
  812. X#define SCORE_YPOS1    18
  813. X#define SCORE_YPOS2    32
  814. X
  815. X#define BG_COLOR    "lightyellow"
  816. X#define BD_COLOR    "darkgreen"
  817. X#define TITLE_COLOR    "blue"
  818. X#define TEXT_COLOR    "red"
  819. X
  820. Xtypedef struct score_s {
  821. X    char            myname[NAMELEN], myhost[NAMELEN], mytime[27];
  822. X    char            score[10];
  823. X    char            level[4];
  824. X    char            lines[5];
  825. X}               score_t;
  826. X#define SCORELEN    sizeof(score_t)
  827. X
  828. X#define    DUMC    {0, 0, 0, 0, '\0', '\0'}
  829. X#define    DUMP    ((Pixmap) 0)
  830. Xtypedef struct pattern_s {
  831. X    int             whichbitmap;
  832. X    char           *fgname, *bgname;
  833. X    XColor          fg, bg;
  834. X    Pixmap          pixmap;
  835. X}               pattern_t;
  836. X
  837. Xtypedef enum {
  838. X    NONE, LEFT, RIGHT, ROTATE, DROP
  839. X}               command_t;
  840. X
  841. Xtypedef struct field_s {
  842. X    Window          frame;
  843. X    Window          title;
  844. X    Window          win;
  845. X    Atom            delw;
  846. X    XFontStruct    *tfont;
  847. X    XFontStruct    *sfont;
  848. X    int           **full;
  849. X    int             height, width;
  850. X    int             winheight, winwidth;
  851. X    long int        score;
  852. X    int             level;
  853. X    int             lines;
  854. X}               field_t;
  855. X
  856. Xtypedef struct thing_s {
  857. X    int             map[THING_SIZE][THING_SIZE];
  858. X    int             xpos, ypos;
  859. X    int             size;
  860. X    int             probability;
  861. X}               thing_t;
  862. X
  863. Xtypedef struct bitmap_datum {
  864. X    char           *data;
  865. X    int             height, width;
  866. X}               bitmap_t;
  867. X
  868. X#define    DIE_MESG    "GAME OVER"
  869. X#define    PAUSED_MESG    "PAUSED"
  870. X
  871. X#define ytr(y)        (field->winheight - (y))
  872. X
  873. X#define NUM_LEVELS    17
  874. X
  875. X#define INF        10000000
  876. X
  877. X#define MILLION        1000000
  878. X
  879. Xextern XColor   bgcolor, bdcolor, titlecolor, textcolor;
  880. X
  881. Xextern Bool     atBottom();
  882. Xextern Bool     overlapping();
  883. Xextern Bool     tryMove();
  884. Xextern field_t *initField();
  885. Xextern int      checkLine();
  886. Xextern int      putBoxes();
  887. Xextern thing_t *makeNewThing();
  888. Xextern void    Usage();
  889. Xextern void     addHighScore();
  890. Xextern void     banner();
  891. Xextern void     die();
  892. Xextern void     doBox();
  893. Xextern void     drawField();
  894. Xextern void     drawThing();
  895. Xextern void     drawThingDiff();
  896. Xextern void     fallDown();
  897. Xextern void     handleEvents();
  898. Xextern void     initPixmaps();
  899. Xextern void     moveOne();
  900. Xextern void     normTimeVal();
  901. Xextern void     rotateThing();
  902. Xextern void     showHighScores();
  903. Xextern void     updateScore();
  904. X
  905. Xextern Display *disp;
  906. Xextern Window   win;
  907. Xextern GC       gc_t;
  908. Xextern GC       gc_w;
  909. Xextern GC       gc_w2;
  910. Xextern GC       gc_wtx;
  911. Xextern GC       gc_ttx;
  912. Xextern GC       gc_pat[];
  913. Xextern XGCValues gcv;
  914. Xextern XGCValues text;
  915. Xextern XGCValues color;
  916. X
  917. Xextern pattern_t patterns[];
  918. Xextern bitmap_t bitmap_data[];
  919. Xextern int      num_patterns;
  920. Xextern thing_t  possible[];
  921. Xextern int      speeds[];
  922. Xextern int      thresh[];
  923. Xextern XColor   bgcolor, bdcolor, titlecolor, textcolor;
  924. Xextern Colormap cmap;
  925. Xextern int      rootDepth;
  926. Xextern int      rootScreen;
  927. X
  928. Xextern Bool     beep;
  929. Xextern char    *winName;
  930. Xextern char    *iconName;
  931. X
  932. END_OF_FILE
  933. if test 5752 -ne `wc -c <'tetris.h'`; then
  934.     echo shar: \"'tetris.h'\" unpacked with wrong size!
  935. fi
  936. # end of 'tetris.h'
  937. fi
  938. if test -f 'utils.c' -a "${1}" != "-c" ; then 
  939.   echo shar: Will not clobber existing file \"'utils.c'\"
  940. else
  941. echo shar: Extracting \"'utils.c'\" \(20459 characters\)
  942. sed "s/^X//" >'utils.c' <<'END_OF_FILE'
  943. X/*
  944. X# GENERIC X-WINDOW-BASED TETRIS
  945. X#
  946. X#    tetris.c
  947. X#
  948. X###
  949. X#
  950. X#  Copyright (C) 1992    Qiang Alex Zhao
  951. X#            Computer Science Dept, University of Arizona
  952. X#            azhao@cs.arizona.edu
  953. X#
  954. X#            All Rights Reserved
  955. X#
  956. X#  Permission to use, copy, modify, and distribute this software and
  957. X#  its documentation for any purpose and without fee is hereby granted,
  958. X#  provided that the above copyright notice appear in all copies and
  959. X#  that both that copyright notice and this permission notice appear in
  960. X#  supporting documentation, and that the name of the author not be
  961. X#  used in advertising or publicity pertaining to distribution of the
  962. X#  software without specific, written prior permission.
  963. X#
  964. X#  This program is distributed in the hope that it will be "playable",
  965. X#  but WITHOUT ANY WARRANTY; without even the implied warranty of
  966. X#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  967. X#
  968. X*/
  969. X
  970. X#include "tetris.h"
  971. X#include "data.h"
  972. X
  973. Xvoid
  974. XnormTimeVal(tv)
  975. X    struct timeval *tv;
  976. X{
  977. X    while (tv->tv_usec < 0) {
  978. X    tv->tv_sec--;
  979. X    tv->tv_usec += MILLION;
  980. X    }
  981. X    while (tv->tv_usec >= MILLION) {
  982. X    tv->tv_sec++;
  983. X    tv->tv_usec -= MILLION;
  984. X    }
  985. X    return;
  986. X}
  987. X
  988. Xvoid
  989. XfallDown(field, thingp, eat)
  990. X    field_t        *field;
  991. X    thing_t       **thingp;
  992. X    Bool            eat;
  993. X{
  994. X    int             lines;
  995. X    XEvent          event;
  996. X
  997. X    putBoxes(field, *thingp);
  998. X
  999. X    lines = checkLine(field);
  1000. X    field->score += 5 + 4 * field->level * field->level * lines * lines;
  1001. X    field->lines += lines;
  1002. X    if (field->lines >= thresh[field->level])
  1003. X        field->level++;
  1004. X    updateScore(field);
  1005. X
  1006. X    free((char *) *thingp);
  1007. X    if (eat) {
  1008. X    *thingp = NULL;
  1009. X    while (XPending(disp)) XNextEvent(disp, &event);
  1010. X    }
  1011. X    *thingp = makeNewThing(field);
  1012. X    if (overlapping(field, *thingp)) die(field);
  1013. X    drawThing(field, *thingp);
  1014. X}
  1015. X
  1016. Xvoid
  1017. XhandleEvents(field, thingp, fall_down)
  1018. X    field_t        *field;
  1019. X    thing_t       **thingp;
  1020. X    Bool            fall_down;
  1021. X{
  1022. X    static Bool     frozen = False;
  1023. X    XEvent          event;
  1024. X    char            s[4];
  1025. X
  1026. X    if (frozen) fall_down = False;
  1027. X
  1028. X    if (!*thingp) {
  1029. X    *thingp = makeNewThing(field);
  1030. X    if (overlapping(field, *thingp)) die(field);
  1031. X    drawThing(field, *thingp);
  1032. X    XSync(disp, 0);
  1033. X    }
  1034. X    if (fall_down && atBottom(field, *thingp)) {
  1035. X    fallDown(field, thingp, False);
  1036. X    fall_down = False;
  1037. X    }
  1038. X    if (!XPending(disp) && !frozen)
  1039. X    moveOne(field, *thingp, NONE, fall_down);
  1040. X
  1041. X    while (XPending(disp)) {
  1042. X    if (overlapping(field, *thingp)) die(field);
  1043. X
  1044. X    XNextEvent(disp, &event);
  1045. X    switch (event.type) {
  1046. X    case KeyPress:
  1047. X        if (!XLookupString((XKeyEvent *) &event, s, 4, NULL, NULL)) break;
  1048. X        switch (*s) {
  1049. X        case 'j':        /* Move left. */
  1050. X        case 'J':
  1051. X        case 's':
  1052. X        case 'S':
  1053. X        if (!frozen)
  1054. X            moveOne(field, *thingp, LEFT, fall_down);
  1055. X        break;
  1056. X
  1057. X        case 'k':        /* Rotate. */
  1058. X        case 'K':
  1059. X        case 'd':
  1060. X        case 'D':
  1061. X        if (!frozen)
  1062. X            moveOne(field, *thingp, ROTATE, fall_down);
  1063. X        break;
  1064. X
  1065. X        case 'l':        /* Move right. */
  1066. X        case 'L':
  1067. X        case 'f':
  1068. X        case 'F':
  1069. X        if (!frozen)
  1070. X            moveOne(field, *thingp, RIGHT, fall_down);
  1071. X        break;
  1072. X
  1073. X        case ' ':        /* Drop. */
  1074. X        case '\n':
  1075. X        if (!frozen) {
  1076. X            moveOne(field, *thingp, DROP, fall_down);
  1077. X            fallDown(field, thingp, True);
  1078. X        }
  1079. X        return;
  1080. X        break;
  1081. X
  1082. X        case 'q':        /* Quit. */
  1083. X        case 'Q':
  1084. X        die(field);
  1085. X        break;
  1086. X
  1087. X        case '+':        /* Speed up. */
  1088. X        case '=':
  1089. X        if (field->level < NUM_LEVELS - 1) {
  1090. X            field->level++;
  1091. X            updateScore(field);
  1092. X        }
  1093. X        break;
  1094. X
  1095. X        case '-':        /* Slow down. */
  1096. X        case '_':
  1097. X        if (field->level > 0) {
  1098. X            field->level--;
  1099. X            updateScore(field);
  1100. X        }
  1101. X        break;
  1102. X
  1103. X        case 'b':
  1104. X        case 'B':
  1105. X        beep = !beep;
  1106. X        if (beep) XBell(disp, -90);
  1107. X        break;
  1108. X
  1109. X        case '\023':    /* Freeze / continue. */
  1110. X        case 'p':
  1111. X        case 'P':
  1112. X        if (beep) XBell(disp, -90);
  1113. X        frozen = (frozen ? False : True);
  1114. X        if (frozen) {
  1115. X        /* "... Hi Boss, I'm working hard as usual ..." */
  1116. X            XIconifyWindow(disp, field->frame, rootScreen);
  1117. X        } else {
  1118. X            XClearWindow(disp, field->win);
  1119. X            drawField(field);
  1120. X            if (*thingp) drawThing(field, *thingp);
  1121. X        }
  1122. X        XFlush(disp);
  1123. X        break;
  1124. X
  1125. X        case '\014':        /* Redraw. */
  1126. X        XClearWindow(disp, field->win);
  1127. X        drawField(field);
  1128. X        if (*thingp)
  1129. X            drawThing(field, *thingp);
  1130. X        /* flow to next */
  1131. X
  1132. X        default:
  1133. X        XBell(disp, -90);
  1134. X        XFlush(disp);
  1135. X        break;
  1136. X        }
  1137. X        break;        /* processing key press */
  1138. X
  1139. X    case UnmapNotify:
  1140. X        frozen = True;
  1141. X        break;
  1142. X
  1143. X    case Expose:
  1144. X        if (event.xexpose.count == 0) {
  1145. X            drawField(field);
  1146. X            if (*thingp) drawThing(field, *thingp);
  1147. X            if (frozen) banner(field, PAUSED_MESG);
  1148. X        }
  1149. X        XFlush(disp);
  1150. X        break;
  1151. X
  1152. X    case ClientMessage:
  1153. X        if ((Atom) event.xclient.data.l[0] == field->delw)
  1154. X        die(field);
  1155. X        break;
  1156. X
  1157. X    case DestroyNotify:
  1158. X        die(field);
  1159. X        break;
  1160. X
  1161. X    }
  1162. X
  1163. X    fall_down = False;
  1164. X    }
  1165. X
  1166. X    return;
  1167. X}
  1168. X
  1169. Xvoid
  1170. XmoveOne(field, thing, what, fall_down)
  1171. X    field_t        *field;
  1172. X    thing_t        *thing;
  1173. X    command_t       what;
  1174. X    Bool            fall_down;
  1175. X{
  1176. X    thing_t         old;
  1177. X
  1178. X    old = *thing;
  1179. X
  1180. X    if (tryMove(field, thing, what, fall_down))
  1181. X    drawThingDiff(field, thing, &old);
  1182. X
  1183. X    XSync(disp, 0);
  1184. X    return;
  1185. X}
  1186. X
  1187. XBool
  1188. XtryMove(field, thing, what, fall_down)
  1189. X    field_t        *field;
  1190. X    thing_t        *thing;
  1191. X    command_t       what;
  1192. X    Bool            fall_down;
  1193. X{
  1194. X    int             x, y;
  1195. X    thing_t         temp;
  1196. X    Bool            ok = True;
  1197. X
  1198. X    temp = *thing;
  1199. X
  1200. X    if (fall_down) temp.ypos--;
  1201. X
  1202. X    switch (what) {
  1203. X    case LEFT:
  1204. X    temp.xpos--;
  1205. X    break;
  1206. X
  1207. X    case RIGHT:
  1208. X    temp.xpos++;
  1209. X    break;
  1210. X
  1211. X    case ROTATE:
  1212. X    rotateThing(&temp);
  1213. X    break;
  1214. X
  1215. X    case DROP:
  1216. X    while (!overlapping(field, &temp)) {
  1217. X        field->score += field->level;
  1218. X        temp.ypos--;
  1219. X    }
  1220. X    temp.ypos++;
  1221. X    break;
  1222. X
  1223. X    case NONE:
  1224. X    break;
  1225. X    }
  1226. X
  1227. X    for (x = 0; (x < temp.size) && ok; x++)
  1228. X    for (y = 0; (y < temp.size) && ok; y++) {
  1229. X        if (temp.map[x][y]) {
  1230. X        if ((temp.xpos + x < 0) ||
  1231. X            (temp.xpos + x >= field->width) ||
  1232. X            (temp.ypos + y < 0) ||
  1233. X            (temp.ypos + y >= field->height) ||
  1234. X            (field->full[temp.xpos + x]
  1235. X             [temp.ypos + y]))
  1236. X            ok = False;
  1237. X        }
  1238. X    }
  1239. X
  1240. X    if (ok) *thing = temp;
  1241. X
  1242. X    if (overlapping(field, thing)) {
  1243. X    return False;
  1244. X    } else {
  1245. X    return True;
  1246. X    }
  1247. X}
  1248. X
  1249. XBool
  1250. XatBottom(field, thing)
  1251. X    field_t        *field;
  1252. X    thing_t        *thing;
  1253. X{
  1254. X    int             x, y;
  1255. X
  1256. X    for (x = 0; x < thing->size; x++)
  1257. X    for (y = 0; y < thing->size; y++)
  1258. X        if (thing->map[x][y]) {
  1259. X        if (thing->ypos + y <= 0)
  1260. X            return True;
  1261. X        if (field->full[thing->xpos + x]
  1262. X            [thing->ypos + y - 1])
  1263. X            return True;
  1264. X        }
  1265. X    return False;
  1266. X}
  1267. X
  1268. Xvoid
  1269. XdrawThing(field, thing)
  1270. X    field_t        *field;
  1271. X    thing_t        *thing;
  1272. X{
  1273. X    int             x, y;
  1274. X
  1275. X    for (x = 0; x < thing->size; x++)
  1276. X    for (y = 0; y < thing->size; y++)
  1277. X        if (thing->map[x][y])
  1278. X        doBox(field, thing->xpos + x, thing->ypos + y,
  1279. X              thing->map[x][y]);
  1280. X    return;
  1281. X}
  1282. X
  1283. Xvoid
  1284. XdrawThingDiff(field, thing, oldthing)
  1285. X    field_t        *field;
  1286. X    thing_t        *thing, *oldthing;
  1287. X{
  1288. X    int             x, y;
  1289. X    int             ox, oy;
  1290. X
  1291. X    for (x = 0; x < thing->size; x++)
  1292. X    for (y = 0; y < thing->size; y++) {
  1293. X        ox = x - oldthing->xpos + thing->xpos;
  1294. X        oy = y - oldthing->ypos + thing->ypos;
  1295. X        if (thing->map[x][y])
  1296. X        doBox(field, thing->xpos + x, thing->ypos + y,
  1297. X              thing->map[x][y]);
  1298. X    }
  1299. X    for (x = 0; x < thing->size; x++)
  1300. X    for (y = 0; y < thing->size; y++) {
  1301. X        ox = x - thing->xpos + oldthing->xpos;
  1302. X        oy = y - thing->ypos + oldthing->ypos;
  1303. X        if (oldthing->map[x][y] &&
  1304. X            ((ox < 0) || (ox >= thing->size) ||
  1305. X             (oy < 0) || (oy >= thing->size) ||
  1306. X             !thing->map[ox][oy]))
  1307. X        doBox(field, oldthing->xpos + x,
  1308. X              oldthing->ypos + y,
  1309. X              0);
  1310. X    }
  1311. X    return;
  1312. X}
  1313. X
  1314. Xvoid
  1315. XdoBox(field, x, y, pat)
  1316. X    field_t        *field;
  1317. X    int             x, y;
  1318. X    int             pat;
  1319. X{
  1320. X    if ((x < 0) || (x >= field->width) || (y < 0) || (y >= field->height))
  1321. X    abort();
  1322. X    if (pat == 0)
  1323. X    XFillRectangle(disp, field->win, gc_w2,
  1324. X               x * BOX_WIDTH + X_MARGIN,
  1325. X               ytr((y + 1) * BOX_HEIGHT + Y_MARGIN) - 1,
  1326. X               BOX_WIDTH + 1, BOX_HEIGHT + 1);
  1327. X    else {
  1328. X    if (rootDepth == 1) {
  1329. X        pat = pat % 16 - 1;
  1330. X        XCopyPlane(disp, patterns[pat].pixmap, field->win, gc_w,
  1331. X               0, 0,
  1332. X               BOX_WIDTH, BOX_HEIGHT,
  1333. X               x * BOX_WIDTH + X_MARGIN,
  1334. X               ytr((y + 1) * BOX_HEIGHT + Y_MARGIN), 1);
  1335. X    } else {
  1336. X        pat -= 1;
  1337. X        XCopyPlane(disp, patterns[pat].pixmap, field->win,
  1338. X               gc_pat[pat],
  1339. X               0, 0,
  1340. X               BOX_WIDTH, BOX_HEIGHT,
  1341. X               x * BOX_WIDTH + X_MARGIN,
  1342. X               ytr((y + 1) * BOX_HEIGHT + Y_MARGIN), 1);
  1343. X    }
  1344. X    }
  1345. X    return;
  1346. X}
  1347. X
  1348. XBool
  1349. Xoverlapping(field, thing)
  1350. X    field_t        *field;
  1351. X    thing_t        *thing;
  1352. X{
  1353. X    int             x, y;
  1354. X
  1355. X    for (x = 0; x < thing->size; x++)
  1356. X    for (y = 0; y < thing->size; y++) {
  1357. X        if (thing->map[x][y] && (thing->ypos + y < 0))
  1358. X        return True;
  1359. X        if (thing->map[x][y] && field->full[thing->xpos + x]
  1360. X            [thing->ypos + y])
  1361. X        return True;
  1362. X    }
  1363. X    return False;
  1364. X}
  1365. X
  1366. Xint
  1367. XputBoxes(field, thing)
  1368. X    field_t        *field;
  1369. X    thing_t        *thing;
  1370. X{
  1371. X    int             x, y;
  1372. X    int             highest = 0;
  1373. X
  1374. X    for (x = 0; x < thing->size; x++)
  1375. X    for (y = 0; y < thing->size; y++)
  1376. X        if (thing->map[x][y]) {
  1377. X        if ((thing->xpos + x < 0) ||
  1378. X            (thing->xpos + x >= field->width) ||
  1379. X            (thing->ypos + y < 0) ||
  1380. X            (thing->ypos + y >= field->height))
  1381. X            abort();
  1382. X        field->full[thing->xpos + x][thing->ypos + y]
  1383. X            = thing->map[x][y];
  1384. X        if (thing->ypos + y > highest)
  1385. X            highest = thing->ypos + y;
  1386. X        }
  1387. X    return highest;
  1388. X}
  1389. X
  1390. Xfield_t        *
  1391. XinitField(width, height, lines_full, argc, argv)
  1392. X    int             width, height, lines_full, argc;
  1393. X    char           *argv[];
  1394. X{
  1395. X    XTextProperty   wName, iName;
  1396. X    XWMHints        wmhints;
  1397. X    XClassHint      classhints;
  1398. X    unsigned int    attvm;
  1399. X    XSetWindowAttributes att;
  1400. X    Cursor          cursor;
  1401. X    XSizeHints      sh;
  1402. X    field_t        *field = (field_t *) malloc(sizeof(field_t));
  1403. X    int             x, y, w, h;;
  1404. X
  1405. X    w = width * BOX_WIDTH + 2 * X_MARGIN;
  1406. X    h = height * BOX_HEIGHT + 2 * Y_MARGIN + TITLE_HEIGHT;
  1407. X
  1408. X    field->width = width;
  1409. X    field->height = height;
  1410. X    field->score = 0;
  1411. X    field->level = 1;
  1412. X    field->lines = 0;
  1413. X
  1414. X    cursor = XCreateFontCursor(disp, XC_exchange);
  1415. X
  1416. X    /* create window */
  1417. X    attvm = CWBackPixel | CWBorderPixel | CWEventMask | 
  1418. X    CWDontPropagate | CWCursor;
  1419. X    att.background_pixel = bgcolor.pixel;
  1420. X    att.border_pixel = bdcolor.pixel;
  1421. X    att.event_mask = ExposureMask | StructureNotifyMask;
  1422. X    att.do_not_propagate_mask = KeyPressMask | KeyReleaseMask |
  1423. X    ButtonPressMask | ButtonReleaseMask | PointerMotionMask |
  1424. X    ButtonMotionMask | Button1MotionMask | Button2MotionMask |
  1425. X    Button3MotionMask | Button4MotionMask | Button5MotionMask ;
  1426. X    att.cursor = cursor;
  1427. X
  1428. X    field->frame = XCreateWindow(disp, DefaultRootWindow(disp),
  1429. X    BASE_XPOS, BASE_YPOS, w, h, BORDER_WIDTH, CopyFromParent,
  1430. X    InputOutput, CopyFromParent, attvm, &att);
  1431. X
  1432. X    /* title */
  1433. X    assert(XStringListToTextProperty(&winName, 1, &wName), "Window Name");
  1434. X    assert(XStringListToTextProperty(&iconName, 1, &iName), "Icon Name");
  1435. X
  1436. X    /* size hints */
  1437. X    sh.flags = PSize | PMinSize | PMaxSize;
  1438. X    sh.width = (sh.min_width = (sh.max_width = w));
  1439. X    sh.height = (sh.min_height = (sh.max_height = h));
  1440. X
  1441. X    /* wm hints */
  1442. X    wmhints.initial_state = NormalState;
  1443. X    wmhints.input = True;
  1444. X    wmhints.icon_pixmap = None;
  1445. X    wmhints.flags = StateHint | InputHint | IconPixmapHint;
  1446. X    classhints.res_name = argv[0];
  1447. X    classhints.res_class = "GTetris";
  1448. X
  1449. X    /* set wm properties */
  1450. X    XSetWMProperties(disp, field->frame, &wName, &iName,
  1451. X    argv, argc, &sh, &wmhints, &classhints);
  1452. X
  1453. X    /* get ready to receive WM_DELETE_WINDOW */
  1454. X    field->delw = XInternAtom(disp, "WM_DELETE_WINDOW", False);
  1455. X    XSetWMProtocols(disp, field->frame, &(field->delw), 1);
  1456. X
  1457. X    /* "title" sub-window */
  1458. X    field->title = XCreateSimpleWindow(disp, field->frame,
  1459. X    -BORDER_WIDTH, -BORDER_WIDTH, w, TITLE_HEIGHT, BORDER_WIDTH,
  1460. X    bdcolor.pixel, bgcolor.pixel);
  1461. X    XSelectInput(disp, field->title, KeyPressMask | ExposureMask);
  1462. X
  1463. X    /* "ground" sub-window */
  1464. X    field->win = XCreateSimpleWindow(disp, field->frame,
  1465. X    -BORDER_WIDTH, TITLE_HEIGHT - BORDER_WIDTH, w, h - TITLE_HEIGHT,
  1466. X    BORDER_WIDTH, bdcolor.pixel, bgcolor.pixel);
  1467. X    XSelectInput(disp, field->win, KeyPressMask | ExposureMask);
  1468. X
  1469. X    if (rootDepth == 1)
  1470. X    num_patterns = NUM_BITMAPS;
  1471. X
  1472. X    field->full = (int **) malloc(sizeof(int *) * width);
  1473. X    for (x = 0; x < width; x++) {
  1474. X    field->full[x] = (int *) malloc(sizeof(int) * height);
  1475. X    for (y = 0; y < height; y++)
  1476. X        if ((y < lines_full) && nrandom(2))
  1477. X        field->full[x][y] = nrandom(num_patterns);
  1478. X        else
  1479. X        field->full[x][y] = 0;
  1480. X    }
  1481. X
  1482. X    /* loading fonts */
  1483. X    field->tfont = XLoadQueryFont(disp, TITLE_FONT);
  1484. X    field->sfont = XLoadQueryFont(disp, SCORE_FONT);
  1485. X    if (field->tfont == NULL) {
  1486. X    field->tfont = XLoadQueryFont(disp, TITLE_FONT2);
  1487. X    assert(field->tfont, "Title Font");
  1488. X    }
  1489. X    if (field->sfont == NULL) {
  1490. X    field->sfont = XLoadQueryFont(disp, SCORE_FONT2);
  1491. X    assert(field->sfont, "Banner Font");
  1492. X    }
  1493. X
  1494. X    field->winheight = field->height * BOX_HEIGHT + 2 * Y_MARGIN;
  1495. X    field->winwidth = field->width * BOX_WIDTH + 2 * X_MARGIN;
  1496. X
  1497. X    /* map windows */
  1498. X    XMapWindow(disp, field->title);
  1499. X    XMapWindow(disp, field->win);
  1500. X    XMapRaised(disp, field->frame);
  1501. X
  1502. X    gcv.function = GXcopy;
  1503. X    gcv.foreground = bdcolor.pixel;
  1504. X    gcv.background = bgcolor.pixel;
  1505. X
  1506. X    gc_t = XCreateGC(disp, field->title,
  1507. X    (GCForeground | GCBackground | GCFunction), &gcv);
  1508. X    gc_w = XCreateGC(disp, field->win,
  1509. X    (GCForeground | GCBackground | GCFunction), &gcv);
  1510. X
  1511. X    gcv.background = bdcolor.pixel;
  1512. X    gcv.foreground = bgcolor.pixel;
  1513. X
  1514. X    gc_w2 = XCreateGC(disp, field->win, (GCForeground | GCBackground |
  1515. X                     GCFunction), &gcv);
  1516. X
  1517. X    text.function = GXcopy;
  1518. X    text.font = field->tfont->fid;
  1519. X    text.foreground = bdcolor.pixel;
  1520. X    text.background = bgcolor.pixel;
  1521. X    gc_ttx = XCreateGC(disp, field->title, (GCFunction | GCFont |
  1522. X                       GCForeground | GCBackground), &text);
  1523. X    text.font = field->sfont->fid;
  1524. X    gc_wtx = XCreateGC(disp, field->title, (GCFunction | GCFont |
  1525. X                       GCForeground | GCBackground), &text);
  1526. X
  1527. X    XFlush(disp);
  1528. X    return (field);
  1529. X}
  1530. X
  1531. Xvoid
  1532. XdrawField(field)
  1533. X    field_t        *field;
  1534. X{
  1535. X    int             x, y;
  1536. X
  1537. X    for (x = 0; x < field->width; x++)
  1538. X    for (y = 0; y < field->height; y++)
  1539. X        doBox(field, x, y, field->full[x][y]);
  1540. X
  1541. X    XDrawImageString(disp, field->title, gc_ttx, 5, 30, "TETRIS", 6);
  1542. X
  1543. X    updateScore(field);
  1544. X
  1545. X    XFlush(disp);
  1546. X    return;
  1547. X}
  1548. X
  1549. Xvoid
  1550. XupdateScore(field)
  1551. X    field_t        *field;
  1552. X{
  1553. X    char            buf[100];
  1554. X
  1555. X    (void) sprintf(buf, "Score: %-7d", field->score);
  1556. X    XDrawImageString(disp, field->title, gc_wtx,
  1557. X             SCORE_XPOS1, SCORE_YPOS1, buf, strlen(buf));
  1558. X
  1559. X    (void) sprintf(buf, "Level: %-7d", field->level);
  1560. X    XDrawImageString(disp, field->title, gc_wtx,
  1561. X             SCORE_XPOS1, SCORE_YPOS2, buf, strlen(buf));
  1562. X
  1563. X    (void) sprintf(buf, "Lines: %-7d", field->lines);
  1564. X    XDrawImageString(disp, field->title, gc_wtx,
  1565. X             SCORE_XPOS2, SCORE_YPOS2, buf, strlen(buf));
  1566. X
  1567. X    XFlush(disp);
  1568. X    return;
  1569. X}
  1570. X
  1571. Xthing_t        *
  1572. XmakeNewThing(field)
  1573. X    field_t        *field;
  1574. X{
  1575. X    int             i, j, k;
  1576. X    int             pat;
  1577. X    int             whichone;
  1578. X    thing_t        *thing = (thing_t *) malloc(sizeof(thing_t));
  1579. X
  1580. X    i = 0;
  1581. X    for (j = 0; j < NUM_POSSIBLE; j++)
  1582. X    i += possible[j].probability;
  1583. X
  1584. X    k = nrandom(i);
  1585. X
  1586. X    for (j = 0; j < NUM_POSSIBLE; j++) {
  1587. X    k -= possible[j].probability;
  1588. X    if (k < 0)
  1589. X        break;
  1590. X    }
  1591. X
  1592. X    *thing = possible[j];
  1593. X    whichone = j;
  1594. X    for (i = 0; i < thing->size; i++)
  1595. X    for (j = 0; j < thing->size; j++)
  1596. X        if (thing->map[i][j]) {
  1597. X        pat = 1;
  1598. X        if (i != 0 && thing->map[i - 1][j])
  1599. X            pat += 1;
  1600. X        if (j != 0 && thing->map[i][j - 1])
  1601. X            pat += 2;
  1602. X        if (i < thing->size - 1 && thing->map[i + 1][j])
  1603. X            pat += 4;
  1604. X        if (j < thing->size - 1 && thing->map[i][j + 1])
  1605. X            pat += 8;
  1606. X        thing->map[i][j] = pat + whichone * 16;
  1607. X        }
  1608. X    for (i = nrandom(4); i > 0; i--)
  1609. X    rotateThing(thing);
  1610. X
  1611. X    thing->ypos = field->height - thing->size;
  1612. X    thing->xpos = nrandom((field->width - 2 * thing->size) + thing->size);
  1613. X
  1614. X    return (thing);
  1615. X}
  1616. X
  1617. Xvoid
  1618. XrotateThing(thing)
  1619. X    thing_t        *thing;
  1620. X{
  1621. X    thing_t         temp;
  1622. X    int             lpoint = thing->size;
  1623. X    int             nlpoint = thing->size;
  1624. X    int             x, y;
  1625. X    int             pattype;
  1626. X
  1627. X    temp = *thing;
  1628. X    for (x = 0; x < thing->size; x++)
  1629. X    for (y = 0; y < thing->size; y++)
  1630. X        if (thing->map[x][y] && (lpoint < y))
  1631. X        lpoint = y;
  1632. X
  1633. X    for (x = 0; x < thing->size; x++)
  1634. X    for (y = 0; y < thing->size; y++) {
  1635. X        pattype = (temp.map[y][thing->size - x - 1] - 1) / 16;
  1636. X        thing->map[x][y] =
  1637. X        ((((temp.map[y][thing->size - x - 1] & 15) - 1) * 2) % 15 + 1)
  1638. X        + pattype * 16;
  1639. X        if (thing->map[x][y] < 0)
  1640. X        thing->map[x][y] = 0;
  1641. X    }
  1642. X
  1643. X    for (x = 0; x < thing->size; x++)
  1644. X    for (y = 0; y < thing->size; y++)
  1645. X        if (thing->map[x][y] && (nlpoint < y))
  1646. X        nlpoint = y;
  1647. X
  1648. X    thing->ypos += lpoint - nlpoint;
  1649. X
  1650. X    return;
  1651. X}
  1652. X
  1653. Xint
  1654. XcheckLine(field)
  1655. X    field_t        *field;
  1656. X{
  1657. X    int            *set = (int *) malloc(sizeof(int) * field->height);
  1658. X    int             i, x, y, nset = 0, h;
  1659. X
  1660. X    for (y = 0; y < field->height; y++) {
  1661. X    for (x = 0; x < field->width; x++)
  1662. X        if (!field->full[x][y])
  1663. X        break;
  1664. X    if (x == field->width) {
  1665. X        set[y] = 1;
  1666. X        nset++;
  1667. X    } else
  1668. X        set[y] = 0;
  1669. X    }
  1670. X
  1671. X    if (nset) {
  1672. X    for (i = 0; i < NUM_FLASHES / nset; i++) {
  1673. X        for (y = 0; y < field->height; y++)
  1674. X        if (set[y]) {
  1675. X            XFillRectangle(disp, field->win, gc_w,
  1676. X                   X_MARGIN,
  1677. X                   ytr((y + 1) * BOX_HEIGHT +
  1678. X                       Y_MARGIN),
  1679. X                   field->width * BOX_WIDTH,
  1680. X                   BOX_HEIGHT);
  1681. X            XFlush(disp);
  1682. X        }
  1683. X    }
  1684. X    for (y = 0; y < field->height; y++)
  1685. X        if (set[y]) {
  1686. X        for (i = y; i < field->height - 1; i++)
  1687. X            for (x = 0; x < field->width; x++)
  1688. X            field->full[x][i] =
  1689. X                field->full[x][i + 1];
  1690. X        for (x = 0; x < field->width; x++)
  1691. X            field->full[x][field->height - 1] = 0;
  1692. X
  1693. X        h = (field->height - y - 1) * BOX_HEIGHT;
  1694. X        if (h > field->winheight - BOX_HEIGHT -
  1695. X            Y_MARGIN)
  1696. X            h = field->winheight - BOX_HEIGHT -
  1697. X            Y_MARGIN;
  1698. X        XCopyArea(disp, field->win, field->win, gc_w,
  1699. X              X_MARGIN, Y_MARGIN,
  1700. X              field->winwidth, h,
  1701. X              X_MARGIN, BOX_HEIGHT + Y_MARGIN);
  1702. X
  1703. X        for (i = y; i < field->height - 1; i++)
  1704. X            set[i] = set[i + 1];
  1705. X        set[field->height - 1] = 0;
  1706. X        y--;
  1707. X        }
  1708. X    if (beep) XBell(disp, -90);
  1709. X    XSync(disp, 0);
  1710. X    }
  1711. X    free((char *) set);
  1712. X
  1713. X    return nset;
  1714. X}
  1715. X
  1716. Xvoid
  1717. XinitPixmaps(field)
  1718. X    field_t        *field;
  1719. X{
  1720. X    Pixmap          bms[NUM_BITMAPS];
  1721. X    int             i, j;
  1722. X    char           *lastFg = "", *lastBg = "";
  1723. X    XColor          lastFgC, lastBgC;
  1724. X
  1725. X    for (i = 0; i < NUM_BITMAPS; i++) {
  1726. X    bms[i] = XCreateBitmapFromData(disp, field->win,
  1727. X                       bitmap_data[i].data,
  1728. X                       bitmap_data[i].width,
  1729. X                       bitmap_data[i].height);
  1730. X    assert(bms[i], "Bitmap");
  1731. X    }
  1732. X    if (rootDepth == 1) {
  1733. X    for (i = 0; i < NUM_BITMAPS; i++) {
  1734. X        patterns[i].pixmap = bms[i];
  1735. X    }
  1736. X    return;
  1737. X    }
  1738. X    for (i = 0; i < NUM_PATTERNS; i++) {
  1739. X    j = 0;
  1740. X    if (strcmp(patterns[i].fgname, lastFg) != 0) {
  1741. X        assert(XParseColor(disp, cmap,
  1742. X        patterns[i].fgname, &patterns[i].fg), "Parse Color");
  1743. X        assert(XAllocColor(disp, cmap, &patterns[i].fg), "Allocate Color");
  1744. X        lastFg = patterns[i].fgname;
  1745. X        lastFgC = patterns[i].fg;
  1746. X        j = 1;
  1747. X    } else {
  1748. X        patterns[i].fg = lastFgC;
  1749. X    }
  1750. X    if (strcmp(patterns[i].bgname, lastBg) != 0) {
  1751. X        assert(XParseColor(disp, cmap,
  1752. X        patterns[i].bgname, &patterns[i].bg), "Parse Color");
  1753. X        assert(XAllocColor(disp, cmap, &patterns[i].bg), "Allocate Color");
  1754. X        lastBg = patterns[i].bgname;
  1755. X        lastBgC = patterns[i].bg;
  1756. X        j = 1;
  1757. X    } else {
  1758. X        patterns[i].bg = lastBgC;
  1759. X    }
  1760. X
  1761. X    if (j) {
  1762. X        color.function = GXcopy;
  1763. X        color.foreground = patterns[i].fg.pixel;
  1764. X        color.background = patterns[i].bg.pixel;
  1765. X
  1766. X        gc_pat[i] = XCreateGC(disp, field->win, (GCForeground |
  1767. X                    GCBackground | GCFunction), &color);
  1768. X    } else
  1769. X        gc_pat[i] = gc_pat[i - 1];
  1770. X
  1771. X    patterns[i].pixmap = bms[patterns[i].whichbitmap];
  1772. X    assert(patterns[i].pixmap, "Pixmap");
  1773. X    }
  1774. X    return;
  1775. X}
  1776. X
  1777. Xint
  1778. Xnrandom(n)
  1779. X    int             n;
  1780. X{
  1781. X    return ((((double) random()) / ((double) 0x7fffffff)) * n);
  1782. X}
  1783. X
  1784. Xvoid
  1785. XUsage(argv)
  1786. X    char          **argv;
  1787. X{
  1788. X    fprintf(stderr, "Usage:  %s [ starting_level [ rows_pre-filled ] ]\n\n",
  1789. X    argv[0]);
  1790. X    exit(255);
  1791. X}
  1792. X
  1793. END_OF_FILE
  1794. if test 20459 -ne `wc -c <'utils.c'`; then
  1795.     echo shar: \"'utils.c'\" unpacked with wrong size!
  1796. fi
  1797. # end of 'utils.c'
  1798. fi
  1799. echo shar: End of archive 1 \(of 2\).
  1800. cp /dev/null ark1isdone
  1801. MISSING=""
  1802. for I in 1 2 ; do
  1803.     if test ! -f ark${I}isdone ; then
  1804.     MISSING="${MISSING} ${I}"
  1805.     fi
  1806. done
  1807. if test "${MISSING}" = "" ; then
  1808.     echo You have unpacked both archives.
  1809.     rm -f ark[1-9]isdone
  1810. else
  1811.     echo You still need to unpack the following archives:
  1812.     echo "        " ${MISSING}
  1813. fi
  1814. ##  End of shell archive.
  1815. exit 0
  1816.