home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume38 / dmdtet / part01 < prev    next >
Encoding:
Text File  |  1993-07-13  |  36.2 KB  |  1,815 lines

  1. Newsgroups: comp.sources.misc
  2. From: fst@nimo.claircom.com (Fariborz Skip Tavakkolian)
  3. Subject: v38i053:  dmdtet - Tetris for the 630 MTG terminal, Part01/01
  4. Message-ID: <1993Jul14.135524.24508@sparky.sterling.com>
  5. X-Md4-Signature: 22d17bb70765938bbaacc2690b863d34
  6. Sender: kent@sparky.sterling.com (Kent Landfield)
  7. Organization: /home/nimo/fst/.organization
  8. Date: Wed, 14 Jul 1993 13:55:24 GMT
  9. Approved: kent@sparky.sterling.com
  10.  
  11. Submitted-by: fst@nimo.claircom.com (Fariborz Skip Tavakkolian)
  12. Posting-number: Volume 38, Issue 53
  13. Archive-name: dmdtet/part01
  14. Environment: AT&T 630 MTG
  15.  
  16. The following is the shell archive containing the sources to the
  17. ``dmdtet'' program.  This is a tetris like game for the AT&T 630 MTG
  18. terminals.  (The 630 is a descendant of the Blit and DMD5620
  19. terminals).  I have not had a chance to compile and test it for the
  20. 5620 yet.  The porting should be straight forward.  I used the
  21. ``xtetris'' score values for each piece and its orientation.  Anything
  22. else has either been guessed at, or made up.
  23.  
  24. You may do with the sources what you wish, as long as the copyright
  25. notice is kept, and authors are noted.
  26.  
  27. Enjoy
  28. Skip    (fst@claircom.com)
  29. --------------------------------8<-----------------------------------------
  30. #! /bin/sh
  31. # This is a shell archive.  Remove anything before this line, then feed it
  32. # into a shell via "sh file" or similar.  To overwrite existing files,
  33. # type "sh file -c".
  34. # Contents:  Makefile drawing.c motion.c tetris.c tetris.h
  35. # Wrapped by kent@sparky on Sun Jul 11 19:31:10 1993
  36. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin ; export PATH
  37. echo If this archive is complete, you will see the following message:
  38. echo '          "shar: End of archive 1 (of 1)."'
  39. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  40.   echo shar: Will not clobber existing file \"'Makefile'\"
  41. else
  42.   echo shar: Extracting \"'Makefile'\" \(795 characters\)
  43.   sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  44. X#
  45. X# Copyright (C) 1993 Fariborz ``Skip'' Tavakkolian
  46. X#
  47. X# $Id: Makefile,v 1.4 93/06/13 12:27:30 fst Exp $
  48. X#
  49. X# Description:
  50. X#
  51. X# $Log:    Makefile,v $
  52. X# Revision 1.4  93/06/13  12:27:30  fst
  53. X# Added the lint stuff
  54. X# 
  55. X# Revision 1.3  93/06/06  11:05:53  fst
  56. X# Changed CFLAGS to -g for debugging by dmdpi
  57. X# 
  58. X# Revision 1.2  93/06/05  22:10:42  fst
  59. X# Changed the RCS ``Header'' with ``Id''.
  60. X# 
  61. X# Revision 1.1  93/06/05  22:03:05  fst
  62. X# Initial revision
  63. X# 
  64. X
  65. XSOURCES = tetris.c drawing.c motion.c
  66. XOBJECTS = $(SOURCES:.c=.o)
  67. X
  68. XTARGET = tetris.m
  69. XTARGET_LINT = tetris.lint
  70. XCC=dmdcc
  71. XCFLAGS=-g
  72. X
  73. X$(TARGET_LINT):    $(SOURCES)
  74. X    lint -I$(DMD)/include $(SOURCES)
  75. X
  76. X$(TARGET):    $(OBJECTS)
  77. X    $(CC) -o $(TARGET) $(OBJECTS)
  78. X
  79. Xdmdtet.shar:
  80. X    shar Makefile $(SOURCES) tetris.h > dmdtet.shar
  81. X
  82. Xtetris.o:    tetris.h
  83. Xmotion.o:    tetris.h
  84. END_OF_FILE
  85.   if test 795 -ne `wc -c <'Makefile'`; then
  86.     echo shar: \"'Makefile'\" unpacked with wrong size!
  87.   fi
  88.   # end of 'Makefile'
  89. fi
  90. if test -f 'drawing.c' -a "${1}" != "-c" ; then 
  91.   echo shar: Will not clobber existing file \"'drawing.c'\"
  92. else
  93.   echo shar: Extracting \"'drawing.c'\" \(15443 characters\)
  94.   sed "s/^X//" >'drawing.c' <<'END_OF_FILE'
  95. X/**********************************************************/
  96. X/*                                                        */
  97. X/* Copyright (C) 1993 Fariborz ``Skip'' Tavakkoian        */
  98. X/*                                                        */
  99. X/**********************************************************/
  100. X
  101. Xstatic char *RCSid = "$Id: drawing.c,v 1.3 93/06/06 11:11:38 fst Exp $";
  102. X
  103. X/*
  104. X * Description:
  105. X *
  106. X * $Log:    drawing.c,v $
  107. X * Revision 1.3  93/06/06  11:11:38  fst
  108. X * Added the current game piece to argument list for Show_Full_Rows and
  109. X * Clear_Full_Rows.  The two functions were changed to check those rows
  110. X * which are effected by the last of move of the current game piece.
  111. X * 
  112. X * Revision 1.2  93/06/05  22:11:32  fst
  113. X * Changed the RCS ``Header'' with ``Id''.
  114. X * 
  115. X * Revision 1.1  93/06/05  22:05:24  fst
  116. X * Initial revision
  117. X * 
  118. X */
  119. X
  120. X#include    <dmd.h>
  121. X#include    <dmdio.h>
  122. X#include    "tetris.h"
  123. X
  124. XTexture16 *colors[] =
  125. X{
  126. X  &T_darkgrey,    
  127. X  (Texture16*) 0, /* black */
  128. X  (Texture16*) 0, /* grey */
  129. X  (Texture16*) 0, /* grey2 */
  130. X  (Texture16*) 0, /* checks */
  131. X  (Texture16*) 0, /* background */
  132. X  &T_lightgrey,
  133. X  (Texture16*) 0,
  134. X};
  135. X
  136. XTexture16 hashmark =
  137. X{
  138. X  0x318C, 0x6318, 0xC631, 0x8C63,
  139. X  0x18C6, 0x318C, 0x6318, 0xC631,
  140. X  0x8C63, 0x18C6, 0x318C, 0x6318,
  141. X  0xC631, 0x8C63, 0x18C6, 0x318C,
  142. X};
  143. X
  144. Xstatic Word brick_bits[] =
  145. X{
  146. X  0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE,
  147. X  0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE,
  148. X  0xFFFE, 0xFFFE, 0xFFFE, 0xFFFE,
  149. X  0xFFFE, 0xFFFE, 0xFFFE, 0x0000,
  150. X};
  151. X
  152. Xstatic Bitmap a_brick =
  153. X{
  154. X  (Word *) brick_bits,
  155. X  1,
  156. X  { {0, 0}, {16, 16} },
  157. X  (char *) 0,
  158. X};
  159. X
  160. Xstatic Word shadow_bits[64];
  161. Xstatic Bitmap shadow =
  162. X{
  163. X  (Word *) shadow_bits,
  164. X  1,                /* this changes at runtime    */
  165. X  { {0, 0}, {64, 16} },        /* so does corner.x        */
  166. X  (char *) 0,
  167. X};
  168. X
  169. Xstatic Word game_bits[BOARD_HEIGHT];
  170. Xstatic Bitmap game_bitmap =
  171. X{
  172. X  (Word *) game_bits,
  173. X  1,
  174. X  { {0, 0}, {BOARD_WIDTH+1, BOARD_HEIGHT+1} },
  175. X  (char *) 0,
  176. X};
  177. X
  178. XBoard game_board =
  179. X{
  180. X  { 0, 0, },
  181. X  &game_bitmap,
  182. X};
  183. X
  184. X/* ================= J - piece ================ */
  185. X
  186. X/* -------------------  North ----------------- */
  187. Xstatic Word xJ_n[] =
  188. X{
  189. X  0x4000,
  190. X  0x4000,
  191. X  0xC000,
  192. X};
  193. X
  194. Xstatic Bitmap xJ_north =
  195. X{
  196. X  (Word *) xJ_n,
  197. X  1,
  198. X  { {0, 0}, {2, 3} },
  199. X  (char *) 0,
  200. X};
  201. X
  202. Xstatic Word J_n[96];
  203. X
  204. Xstatic Bitmap J_north =
  205. X{
  206. X  (Word *) J_n,
  207. X  2,
  208. X  { {0, 0}, {32, 48} },
  209. X  (char *) 0,
  210. X};
  211. X
  212. X/* ------------------  East ----------------- */
  213. Xstatic Word xJ_e[] =
  214. X{
  215. X  0x8000,
  216. X  0xE000,
  217. X};
  218. X
  219. Xstatic Bitmap xJ_east =
  220. X{
  221. X  (Word *) xJ_e,
  222. X  1,
  223. X  { {0, 0}, {3, 2} },
  224. X  (char *) 0,
  225. X};
  226. X
  227. Xstatic Word J_e[96];
  228. X
  229. Xstatic Bitmap J_east =
  230. X{
  231. X  (Word*) J_e,
  232. X  3,
  233. X  { {0, 0}, {48, 32} },
  234. X  (char *) 0,
  235. X};
  236. X
  237. X/* ------------------- South ------------------ */
  238. Xstatic Word xJ_s[] =
  239. X{
  240. X  0xC000,
  241. X  0x8000,
  242. X  0x8000,
  243. X};
  244. X
  245. Xstatic Bitmap xJ_south =
  246. X{
  247. X  (Word *) xJ_s,
  248. X  1,
  249. X  { {0, 0}, {2, 3} },
  250. X  (char *) 0,
  251. X};
  252. X
  253. Xstatic Word J_s[96];
  254. X
  255. Xstatic Bitmap J_south =
  256. X{
  257. X  (Word*) J_s,
  258. X  2,
  259. X  { {0, 0}, {32, 48} },
  260. X  (char *) 0,
  261. X};
  262. X
  263. X
  264. X/* ---------------------- West ------------------ */
  265. Xstatic Word xJ_w[] =
  266. X{
  267. X  0xE000,
  268. X  0x2000,
  269. X};
  270. X
  271. Xstatic Bitmap xJ_west =
  272. X{
  273. X  (Word *) xJ_w,
  274. X  1,
  275. X  { {0, 0}, {3, 2} },
  276. X  (char *) 0,
  277. X};
  278. X
  279. Xstatic Word J_w[96];
  280. X
  281. Xstatic Bitmap J_west =
  282. X{
  283. X  (Word*) J_w,
  284. X  3,
  285. X  { {0, 0}, {48, 32} },
  286. X  (char *) 0,
  287. X};
  288. X
  289. X/* =================== L - piece ================== */
  290. X
  291. X/* ---------------------  North  ------------------ */
  292. Xstatic Word xL_n[] =
  293. X{
  294. X  0x8000,
  295. X  0x8000,
  296. X  0xC000,
  297. X};
  298. X
  299. Xstatic Bitmap xL_north =
  300. X{
  301. X  (Word *) xL_n,
  302. X  1,
  303. X  { {0, 0}, {2, 3} },
  304. X  (char *) 0,
  305. X};
  306. X
  307. Xstatic Word L_n[96];
  308. X
  309. Xstatic Bitmap L_north =
  310. X{
  311. X  (Word*) L_n,
  312. X  2,
  313. X  { {0, 0}, {32, 48} },
  314. X  (char *) 0,
  315. X};
  316. X
  317. X/* ---------------------  East  ------------------ */
  318. Xstatic Word xL_e[] =
  319. X{
  320. X  0xE000,
  321. X  0x8000,
  322. X};
  323. X
  324. Xstatic Bitmap xL_east =
  325. X{
  326. X  (Word *) xL_e,
  327. X  1,
  328. X  { {0, 0}, {3, 2} },
  329. X  (char *) 0,
  330. X};
  331. X
  332. Xstatic Word L_e[96];
  333. X
  334. Xstatic Bitmap L_east =
  335. X{
  336. X  (Word*) L_e,
  337. X  3,
  338. X  { {0, 0}, {48, 32} },
  339. X  (char *) 0,
  340. X};
  341. X
  342. X/* --------------------  South  ------------------ */
  343. Xstatic Word xL_s[] =
  344. X{
  345. X  0xC000,
  346. X  0x4000,
  347. X  0x4000,
  348. X};
  349. X
  350. Xstatic Bitmap xL_south =
  351. X{
  352. X  (Word *) xL_s,
  353. X  1,
  354. X  { {0, 0}, {2, 3} },
  355. X  (char *) 0,
  356. X};
  357. X
  358. Xstatic Word L_s[96];
  359. X
  360. Xstatic Bitmap L_south =
  361. X{
  362. X  (Word*) L_s,
  363. X  2,
  364. X  { {0, 0}, {32, 48} },
  365. X  (char *) 0,
  366. X};
  367. X
  368. X/* ---------------------  West  ------------------ */
  369. Xstatic Word xL_w[] =
  370. X{
  371. X  0x2000,
  372. X  0xE000,
  373. X};
  374. X
  375. Xstatic Bitmap xL_west =
  376. X{
  377. X  (Word *) xL_w,
  378. X  1,
  379. X  { {0, 0}, {3, 2} },
  380. X  (char *) 0,
  381. X};
  382. X
  383. Xstatic Word L_w[96];
  384. X
  385. Xstatic Bitmap L_west =
  386. X{
  387. X  (Word*) L_w,
  388. X  3,
  389. X  { {0, 0}, {48, 32} },
  390. X  (char *) 0,
  391. X};
  392. X
  393. X/* ================= S - peices ===================== */
  394. X
  395. X/* ------------------ North / South ----------------- */
  396. Xstatic Word xS_n[] =
  397. X{
  398. X  0x8000,
  399. X  0xC000,
  400. X  0x4000,
  401. X};
  402. X
  403. Xstatic Bitmap xS_north =
  404. X{
  405. X  (Word *) xS_n,
  406. X  1,
  407. X  { {0, 0}, {2, 3} },
  408. X  (char *) 0,
  409. X};
  410. X
  411. Xstatic Word S_n[96];
  412. X
  413. Xstatic Bitmap S_north =
  414. X{
  415. X  (Word *) S_n,
  416. X  2,
  417. X  { {0, 0}, {32, 48} },
  418. X  (char *) 0,
  419. X};
  420. X
  421. X/* ----------------- East / West ------------------ */
  422. Xstatic Word xS_e[] =
  423. X{
  424. X  0x6000,
  425. X  0xC000,
  426. X};
  427. X
  428. Xstatic Bitmap xS_east =
  429. X{
  430. X  (Word *) xS_e,
  431. X  1,
  432. X  { {0, 0}, {3, 2} },
  433. X  (char *) 0,
  434. X};
  435. X
  436. Xstatic Word S_e[96];
  437. X
  438. Xstatic Bitmap S_east = 
  439. X{
  440. X  (Word *) S_e,
  441. X  3,
  442. X  { {0, 0}, {48, 32} },
  443. X  (char *) 0,
  444. X};
  445. X
  446. X/* =========================== Z - piece ======================= */
  447. X
  448. X/* -------------------------- North/South ---------------------- */
  449. Xstatic Word xZ_n[] =
  450. X{
  451. X  0x4000,
  452. X  0xC000,
  453. X  0x8000,
  454. X};
  455. X
  456. Xstatic Bitmap xZ_north =
  457. X{
  458. X  (Word *) xZ_n,
  459. X  1,
  460. X  { {0, 0}, {2, 3} },
  461. X  (char *) 0,
  462. X};
  463. X
  464. Xstatic Word Z_n[96];
  465. Xstatic Bitmap Z_north =
  466. X{
  467. X  (Word *) Z_n,
  468. X  2,
  469. X  { {0, 0}, {32, 48} },
  470. X  (char *) 0,
  471. X};
  472. X
  473. X/* -------------------------- East/West ---------------------- */
  474. Xstatic Word xZ_e[] =
  475. X{
  476. X  0xC000,
  477. X  0x6000,
  478. X};
  479. X
  480. Xstatic Bitmap xZ_east =
  481. X{
  482. X  (Word *) xZ_e,
  483. X  1,
  484. X  { {0, 0}, {3, 2} },
  485. X  (char *) 0,
  486. X};
  487. X
  488. Xstatic Word Z_e[96];
  489. Xstatic Bitmap Z_east = 
  490. X{
  491. X  (Word *) Z_e,
  492. X  3,
  493. X  { {0, 0}, {48, 32} },
  494. X  (char *) 0,
  495. X};  
  496. X
  497. X/* ============================ T - piece ======================= */
  498. X/* ---------------- North -------------- */
  499. Xstatic Word xT_n[] =
  500. X{
  501. X  0x8000,
  502. X  0xC000,
  503. X  0x8000,
  504. X};
  505. X
  506. Xstatic Bitmap xT_north = 
  507. X{
  508. X  (Word *) xT_n,
  509. X  1,
  510. X  { {0, 0}, {2, 3} },
  511. X  (char *) 0,
  512. X};
  513. X
  514. Xstatic Word T_n[96];
  515. Xstatic Bitmap T_north = 
  516. X{
  517. X  (Word *) T_n,
  518. X  2,
  519. X  { {0, 0}, {32, 48} },
  520. X  (char *) 0,
  521. X};
  522. X
  523. X/* ------------------ East ----------------- */
  524. Xstatic Word xT_e[] =
  525. X{
  526. X  0xE000,
  527. X  0x4000,
  528. X};
  529. Xstatic Bitmap xT_east =
  530. X{
  531. X  (Word *) xT_e,
  532. X  1,
  533. X  { {0, 0}, {3, 2} },
  534. X  (char *) 0,
  535. X};
  536. X
  537. Xstatic Word T_e[96];
  538. Xstatic Bitmap T_east = 
  539. X{
  540. X  (Word *) T_e,
  541. X  3,
  542. X  { {0, 0}, {48, 32} },
  543. X  (char *) 0,
  544. X};
  545. X
  546. X/* ------------------ South ---------------- */
  547. Xstatic Word xT_s[] =
  548. X{
  549. X  0x4000,
  550. X  0xC000,
  551. X  0x4000,
  552. X};
  553. X
  554. Xstatic Bitmap xT_south = 
  555. X{
  556. X  (Word *) xT_s,
  557. X  1,
  558. X  { {0, 0}, {2, 3} },
  559. X  (char *) 0,
  560. X};
  561. X
  562. Xstatic Word T_s[96];
  563. Xstatic Bitmap T_south = 
  564. X{
  565. X  (Word *) T_s,
  566. X  2,
  567. X  { {0, 0}, {32, 48} },
  568. X  (char *) 0,
  569. X};
  570. X
  571. X/* -------------------- West ----------------- */  
  572. Xstatic Word xT_w[] =
  573. X{
  574. X  0x4000,
  575. X  0xE000,
  576. X};
  577. Xstatic Bitmap xT_west =
  578. X{
  579. X  (Word *) xT_w,
  580. X  1,
  581. X  { {0, 0}, {3, 2} },
  582. X  (char *) 0,
  583. X};
  584. X
  585. Xstatic Word T_w[96];
  586. Xstatic Bitmap T_west = 
  587. X{
  588. X  (Word *) T_w,
  589. X  3,
  590. X  { {0, 0}, {48, 32} },
  591. X  (char *) 0,
  592. X};
  593. X
  594. X/* ========================= I - piece ===================== */
  595. X
  596. X/* ------------------------- North / South ----------------- */
  597. Xstatic Word xI_n[] =
  598. X{
  599. X  0x8000,
  600. X  0x8000,
  601. X  0x8000,
  602. X  0x8000,
  603. X};
  604. Xstatic Bitmap xI_north = 
  605. X{
  606. X  (Word *) xI_n,
  607. X  1,
  608. X  { {0, 0}, {1, 4} },
  609. X  (char *) 0,
  610. X};
  611. X
  612. Xstatic Word I_n[96];
  613. Xstatic Bitmap I_north =
  614. X{
  615. X  (Word *) I_n,
  616. X  1,
  617. X  { {0, 0}, {16, 64} },
  618. X  (char *) 0,
  619. X};
  620. X
  621. X/* ------------------------- East / West ------------------- */
  622. Xstatic Word xI_e[] =
  623. X{
  624. X  0xF000,
  625. X};
  626. Xstatic Bitmap xI_east = 
  627. X{
  628. X  (Word *) xI_e,
  629. X  1,
  630. X  { {0, 0}, {4, 1} },
  631. X  (char *) 0,
  632. X};
  633. X
  634. Xstatic Word I_e[96];
  635. Xstatic Bitmap I_east =
  636. X{
  637. X  (Word *) I_e,
  638. X  4,
  639. X  { {0, 0}, {64, 16} },
  640. X};
  641. X
  642. X/* ======================== Square piece ====================== */
  643. X/* -------------------- North / South / East / West =========== */
  644. Xstatic Word xO_n[] =
  645. X{
  646. X  0xC000,
  647. X  0xC000,
  648. X};
  649. Xstatic Bitmap xO_north =
  650. X{
  651. X  (Word *) xO_n,
  652. X  1,
  653. X  { {0, 0}, {2, 2} },
  654. X  (char *) 0,
  655. X};
  656. X
  657. Xstatic Word O_n[96];
  658. Xstatic Bitmap O_north =
  659. X{
  660. X  (Word *) O_n,
  661. X  2,
  662. X  { {0, 0}, {32, 32} },
  663. X  (char *) 0,
  664. X};
  665. X    
  666. X
  667. X/* ============================================================ */
  668. X
  669. Xstatic GamePiece J_Piece =
  670. X{
  671. X  0, (Texture16 *) 0,
  672. X  { 7, 6, 7, 6, },
  673. X  { &xJ_north, &xJ_east, &xJ_south, &xJ_west,    },
  674. X  { &J_north, &J_east, &J_south, &J_west,    },
  675. X};
  676. X
  677. Xstatic GamePiece L_Piece =
  678. X{
  679. X  0, (Texture16 *) 0,
  680. X  { 7, 6, 7, 6, },
  681. X  { &xL_north, &xL_east, &xL_south, &xL_west,    },
  682. X  { &L_north, &L_east, &L_south, &L_west,    },
  683. X};
  684. X
  685. Xstatic GamePiece S_Piece =
  686. X{
  687. X  0, (Texture16 *) 0,
  688. X  { 7, 6, 7, 6, },
  689. X  { &xS_north, &xS_east, &xS_north, &xS_east,    },
  690. X  { &S_north, &S_east, &S_north, &S_east,    },
  691. X};
  692. X
  693. Xstatic GamePiece Z_Piece =
  694. X{
  695. X  0, (Texture16 *) 0,
  696. X  { 7, 6, 7, 6, },
  697. X  { &xZ_north, &xZ_east, &xZ_north, &xZ_east,    },
  698. X  { &Z_north, &Z_east, &Z_north, &Z_east,    },
  699. X};
  700. X
  701. Xstatic GamePiece T_Piece =
  702. X{
  703. X  0, (Texture16 *) 0,
  704. X  { 5, 6, 5, 5, },
  705. X  { &xT_north, &xT_east, &xT_south, &xT_west,    },
  706. X  { &T_north, &T_east, &T_south, &T_west,    },
  707. X};
  708. X
  709. Xstatic GamePiece I_Piece = 
  710. X{
  711. X  0, (Texture16 *) 0,
  712. X  { 8, 5, 8, 5, },
  713. X  { &xI_north, &xI_east, &xI_north, &xI_east,    },
  714. X  { &I_north, &I_east, &I_north, &I_east,    },
  715. X};
  716. X
  717. Xstatic GamePiece O_Piece =
  718. X{
  719. X  0, (Texture16 *) 0,
  720. X  { 6, 6, 6, 6, },
  721. X  { &xO_north, &xO_north, &xO_north, &xO_north,    },
  722. X  { &O_north, &O_north, &O_north, &O_north,    },
  723. X};
  724. X
  725. XGamePiece *Pieces[] =
  726. X{
  727. X  &O_Piece,
  728. X  &I_Piece,
  729. X  &J_Piece,
  730. X  &L_Piece,
  731. X  &S_Piece,
  732. X  &Z_Piece,
  733. X  &T_Piece,
  734. X};
  735. X
  736. X/*
  737. X * Pick a game piece. any piece...
  738. X */
  739. XGamePiece *Get_Next_Piece()
  740. X{
  741. X  return Pieces[rand() % 7];
  742. X}
  743. X
  744. X/*
  745. X * Set the color of a piece to a texture given.
  746. X */
  747. Xvoid Set_Color(smap, col)
  748. X     Bitmap *smap;
  749. X     Texture16 *col;
  750. X{
  751. X  texture(smap, smap->rect, col, F_OR);
  752. X  texture(smap, smap->rect, col, F_XOR);
  753. X}
  754. X
  755. Xint Show_Full_Rows(gp)
  756. X     GamePiece *gp;    /* the game piece that might have caused full rows */
  757. X{
  758. X  int y, xmax, ymax, ymin, rcount;
  759. X  Word *w;
  760. X  Bitmap *gbmap = game_board.map;
  761. X
  762. X  if (gp)
  763. X    {
  764. X      Bitmap *gpmap = gp->gmap_arr[gp->cur];
  765. X
  766. X      ymin = game_board.curpt.y;
  767. X      ymax = game_board.curpt.y + gpmap->rect.corner.y;
  768. X    }
  769. X  else
  770. X    {
  771. X      ymin = gbmap->rect.origin.y;
  772. X      ymax = gbmap->rect.corner.y;
  773. X    }
  774. X      
  775. X  xmax = gbmap->rect.corner.x - 1;
  776. X
  777. X  for (rcount = 0, y = ymin; y < ymax; y++)
  778. X    {
  779. X      w = addr(gbmap, Pt(0, y));
  780. X      if (*w == FULL_ROW_MASK)
  781. X    {
  782. X      Rectangle r;
  783. X
  784. X      rcount++;
  785. X      r.origin = add(add(Drect.origin, Grect.origin), mul(Pt(0, y), 16));
  786. X      r.corner = add(r.origin, mul(Pt(xmax, 1), 16));
  787. X      texture(&physical, r, &hashmark, F_STORE);
  788. X      sleep(30);
  789. X    }
  790. X    }
  791. X
  792. X  sleep(30);
  793. X  return rcount;
  794. X}
  795. X
  796. Xvoid Clear_Full_Rows(rcount, gp)
  797. X     int rcount;
  798. X     GamePiece *gp;
  799. X{
  800. X  int y, xmax, ymax, ymin;
  801. X  Word *w;
  802. X  Bitmap *gbmap = game_board.map;
  803. X
  804. X  if (gp)
  805. X    {
  806. X      Bitmap *gpmap = gp->gmap_arr[gp->cur];
  807. X
  808. X      ymin = game_board.curpt.y;
  809. X      ymax = game_board.curpt.y + gpmap->rect.corner.y;
  810. X    }
  811. X  else
  812. X    {
  813. X      ymin = gbmap->rect.origin.y;
  814. X      ymax = gbmap->rect.corner.y;
  815. X    }
  816. X
  817. X  xmax = gbmap->rect.corner.x - 1;
  818. X  while (rcount--)
  819. X    {
  820. X      for (y = ymax-1; y >= ymin; y--)
  821. X    {
  822. X      w = addr(gbmap, Pt(0,y));
  823. X      if (*w == FULL_ROW_MASK)
  824. X        {
  825. X          Point o;
  826. X          Rectangle r;
  827. X
  828. X          /* move game rows down by 1 row */
  829. X          bitblt(gbmap,Rpt(Pt(0,0), Pt(xmax, y)), gbmap, Pt(0,1), F_STORE);
  830. X          /* clear the top game row */
  831. X          rectf(gbmap, Rpt(Pt(0,0), Pt(xmax, 1)), F_CLR);
  832. X
  833. X          /* move displayed rows down by 1 row */
  834. X          r.origin = add(Drect.origin, Grect.origin);
  835. X          r.corner = add(r.origin, mul(Pt(xmax, y), 16));
  836. X          o = add(r.origin, mul(Pt(0, 1), 16));
  837. X          bitblt(&physical, r, &physical, o, F_STORE);
  838. X
  839. X          /* clear the top display row */
  840. X          r.origin = add(Drect.origin, Grect.origin);
  841. X          r.corner = add(r.origin, mul(Pt(xmax, 1), 16));
  842. X          rectf(&physical, r, F_CLR);
  843. X          break;
  844. X        }
  845. X    }
  846. X    }
  847. X}
  848. X
  849. X/*
  850. X * Using the game bitmap create the displayed piece shape.
  851. X */
  852. Xvoid Populate_Bitmap(gmap, smap)
  853. X     Bitmap *gmap, *smap;
  854. X{
  855. X  int x, y;
  856. X  int bit;
  857. X  Word *w;
  858. X
  859. X  if (! eqpt(gmap->rect.origin, Pt(0,0)))
  860. X    {
  861. X      /* fprintf(stderr, "Populate_Bitmap(): Internal error\n"); */
  862. X      sleep(2);
  863. X      exit();
  864. X    }
  865. X  if (gmap->rect.corner.x > 4 || gmap->rect.corner.y > 4)
  866. X    {
  867. X      /* fprintf(stderr, "Populate_Bitmap(): Internal error\n"); */
  868. X      sleep(2);
  869. X      exit();
  870. X    }
  871. X
  872. X  for (y = gmap->rect.origin.y; y < gmap->rect.corner.y; y++)
  873. X    for (x = gmap->rect.origin.x; x < gmap->rect.corner.x; x++)
  874. X    {
  875. X      w = addr(gmap, Pt(x,y));
  876. X
  877. X      bit = FIRSTBIT >> (x % WORDSIZE);
  878. X
  879. X      /*
  880. X       * If the bit is set fill the corresponding block
  881. X       * in game piece's shape bitmap
  882. X       */
  883. X      if ((*w & bit) == bit)
  884. X    bitblt(&a_brick, a_brick.rect, smap, Pt((x*16),(y*16)), F_STORE);
  885. X    }
  886. X}
  887. X
  888. Xvoid Clear_Shadow_Area()
  889. X{
  890. X  rectf(&physical, raddp(Mrect, Drect.origin), F_CLR);
  891. X}
  892. X  
  893. Xvoid Display_Shadow_XOR(gp)
  894. X     GamePiece *gp;
  895. X{
  896. X  Point origin;
  897. X  Bitmap *smap = gp->smap_arr[gp->cur];
  898. X
  899. X  /* Display the shadow */
  900. X
  901. X  origin = add(Drect.origin, Mrect.origin);
  902. X  origin = add(origin, Pt(game_board.curpt.x*16, 0));
  903. X
  904. X  shadow.rect.corner.x = smap->rect.corner.x;
  905. X  shadow.width = smap->width;
  906. X
  907. X  texture(&shadow, shadow.rect, (Texture16*) brick_bits, F_STORE);
  908. X  texture(&shadow, shadow.rect, gp->color, F_XOR);
  909. X  bitblt(&shadow, shadow.rect, &physical, origin, F_XOR);
  910. X}
  911. X
  912. Xvoid Bitblit_Piece_XOR(gp)
  913. X     GamePiece *gp;
  914. X{
  915. X  Point origin;
  916. X  Bitmap *smap = gp->smap_arr[gp->cur];
  917. X  Bitmap *gmap = gp->gmap_arr[gp->cur];
  918. X
  919. X  /* Game board bitmap */
  920. X  origin = game_board.curpt;
  921. X  bitblt(gmap, gmap->rect, game_board.map, origin, F_XOR);
  922. X  
  923. X  /* Display bitmap */
  924. X
  925. X  origin = fPt(add(add(Drect.origin, Grect.origin), mul(origin, 16)));
  926. X  bitblt(smap, smap->rect, &physical, origin, F_XOR);
  927. X  Display_Shadow_XOR(gp);
  928. X}
  929. X
  930. Xvoid Bitblit_Display_XOR(gp)
  931. X     GamePiece *gp;
  932. X{
  933. X  Point origin;
  934. X  Bitmap *smap = gp->smap_arr[gp->cur];
  935. X
  936. X  origin = fPt(add(add(Drect.origin, Grect.origin),mul(game_board.curpt, 16)));
  937. X
  938. X  bitblt(smap, smap->rect, &physical, origin, F_XOR);
  939. X  Display_Shadow_XOR(gp);
  940. X}
  941. X
  942. Xvoid Bitblit_Game_Board_XOR(gp)
  943. X     GamePiece *gp;
  944. X{
  945. X  Point origin;
  946. X  Bitmap *gmap = gp->gmap_arr[gp->cur];
  947. X
  948. X  /* Game board bitmap */
  949. X  origin = game_board.curpt;
  950. X  bitblt(gmap, gmap->rect, game_board.map, origin, F_XOR);
  951. X}
  952. X
  953. Xvoid Draw_Window()
  954. X{
  955. X  Rectangle r;
  956. X
  957. X  r.origin = sub(Srect.origin, Pt(1, 1));
  958. X  r.corner = add(Srect.corner, Pt(1, 1));
  959. X  r = raddp(r, Drect.origin);
  960. X  box(&display, r, F_STORE);
  961. X
  962. X  r.origin = sub(Grect.origin, Pt(1, 1));
  963. X  r.corner = add(Grect.corner, Pt(1, 1));
  964. X  r = raddp(r, Drect.origin);
  965. X  box(&display, r, F_STORE);
  966. X
  967. X  r.origin = sub(Mrect.origin, Pt(1, 1));
  968. X  r.corner = add(Mrect.corner, Pt(1, 1));
  969. X  r = raddp(r, Drect.origin);
  970. X  box(&display, r, F_STORE);
  971. X}
  972. X
  973. Xvoid Clear_Game_Board()
  974. X{
  975. X  extern Rectangle Grect;
  976. X  Rectangle r;
  977. X
  978. X  r.origin = add(Drect.origin, Grect.origin);
  979. X  r.corner = add(Drect.origin, Grect.corner);
  980. X
  981. X  /* rectf(&display, Drect, F_CLR); */
  982. X  rectf(&display, r, F_CLR);
  983. X  rectf(game_board.map, game_board.map->rect, F_CLR);
  984. X  /* sleep(2); */
  985. X}
  986. X
  987. Xvoid Show_Next_Piece(np)
  988. X     GamePiece *np;
  989. X{
  990. X  Bitmap *smap = np->smap_arr[np->cur];
  991. X  Rectangle r;
  992. X
  993. X  r.origin = add(Drect.origin, nploc);
  994. X  r.corner = add(r.origin, Pt(64, 64));
  995. X  rectf(&physical, r, F_CLR);
  996. X  bitblt(smap, smap->rect, &physical, r.origin, F_STORE);
  997. X}
  998. END_OF_FILE
  999.   if test 15443 -ne `wc -c <'drawing.c'`; then
  1000.     echo shar: \"'drawing.c'\" unpacked with wrong size!
  1001.   fi
  1002.   # end of 'drawing.c'
  1003. fi
  1004. if test -f 'motion.c' -a "${1}" != "-c" ; then 
  1005.   echo shar: Will not clobber existing file \"'motion.c'\"
  1006. else
  1007.   echo shar: Extracting \"'motion.c'\" \(6521 characters\)
  1008.   sed "s/^X//" >'motion.c' <<'END_OF_FILE'
  1009. X/**********************************************************/
  1010. X/*                                                        */
  1011. X/* Copyright (C) 1993 Fariborz ``Skip'' Tavakkolian       */
  1012. X/*                                                        */
  1013. X/**********************************************************/
  1014. X
  1015. Xstatic char *RCSid = "$Id: motion.c,v 1.2 93/06/05 22:11:28 fst Exp Locker: fst $";
  1016. X
  1017. X/*
  1018. X * Description:
  1019. X *
  1020. X * $Log:    motion.c,v $
  1021. X * Revision 1.2  93/06/05  22:11:28  fst
  1022. X * Changed the RCS ``Header'' with ``Id''.
  1023. X * 
  1024. X * Revision 1.1  93/06/05  22:06:11  fst
  1025. X * Initial revision
  1026. X * 
  1027. X */
  1028. X
  1029. X#include    <dmd.h>
  1030. X#include    <dmdio.h>
  1031. X#include    <font.h>
  1032. X#include    "tetris.h"
  1033. X
  1034. Xvoid Reshape_Window()
  1035. X{
  1036. X  lprintf("Please Reshape Window");
  1037. X
  1038. X  request(RESHAPED);
  1039. X  do
  1040. X    {
  1041. X      wait(RESHAPED);
  1042. X      if (P->state & MOVED)
  1043. X    {
  1044. X      P->state &= ~(MOVED|RESHAPED);
  1045. X    }
  1046. X      else if ((P->state & RESHAPED) && !(P->state & MOVED))
  1047. X    {
  1048. X      P->state &= ~RESHAPED;
  1049. X      P->state |= NO_RESHAPE;
  1050. X      break;
  1051. X    }
  1052. X    }
  1053. X  while (1);
  1054. X}
  1055. X
  1056. X/*
  1057. X * Initialize the game pieces.
  1058. X */
  1059. Xvoid Init_Pieces()
  1060. X{
  1061. X  int i, j;
  1062. X  extern Texture16 *colors[];
  1063. X
  1064. X  for (i = 0; i < PIECES_COUNT; i++)
  1065. X    for (j = 0; j < 4; j++)
  1066. X      {
  1067. X    Pieces[i]->color = colors[i];
  1068. X    Populate_Bitmap(Pieces[i]->gmap_arr[j], Pieces[i]->smap_arr[j]);
  1069. X    Set_Color(Pieces[i]->smap_arr[j], colors[i]);
  1070. X      }
  1071. X
  1072. X  srand((unsigned) realtime());    /* seed the random number generator */
  1073. X}
  1074. X
  1075. XRectangle Grect, Srect, Mrect;
  1076. X
  1077. X/*
  1078. X * Set default size for the window.
  1079. X */
  1080. XPoint default_size(x, y, p)
  1081. X     int x,y;
  1082. X     struct Proc *p;
  1083. X{
  1084. X  Point q;
  1085. X
  1086. X  Srect.origin = fPt(TET_INSET + BBW, TET_INSET + BBW);
  1087. X
  1088. X  Grect.origin = add(Srect.origin, Pt(TEXTWIDTH+2*BBW+TET_INSET, 0));
  1089. X  Grect.corner = add(Grect.origin, Pt(GBW, GBH));
  1090. X
  1091. X  Mrect.origin = add(Grect.origin, Pt(0, 2*BBW+GBH+TET_INSET));
  1092. X  Mrect.corner = add(Mrect.origin, Pt(GBW, 16));
  1093. X
  1094. X  Srect.corner = fPt(Srect.origin.x+TEXTWIDTH, Mrect.corner.y);
  1095. X
  1096. X  q.x = Grect.corner.x - Srect.origin.x + 2*TET_INSET + 2*BBW + 2*INSET;
  1097. X  q.y = Srect.corner.y - Srect.origin.y + 2*TET_INSET + 2*BBW + 2*INSET;
  1098. X
  1099. X  return q;
  1100. X}
  1101. X
  1102. X/*
  1103. X * Initialize the default size function, colors and pieces.
  1104. X */
  1105. Xvoid Initialize()
  1106. X{
  1107. X  colors[1] = &T_white;
  1108. X  colors[2] = &T_grey;
  1109. X  colors[3] = &T_grey2;
  1110. X  colors[4] = &T_checks;
  1111. X  colors[5] = &T_background;
  1112. X
  1113. X  Init_Pieces();
  1114. X
  1115. X  P->ctob = default_size;
  1116. X  P->state |= NOCURSEXPAND;
  1117. X}
  1118. X
  1119. Xint Check_Bounds(origin, corner)
  1120. X     Point origin, corner;
  1121. X{
  1122. X  /*
  1123. X  fprintf(stderr, "Check_Bounds origin(%d,%d), corner(%d,%d)\n",
  1124. X      origin.x, origin.y, corner.x, corner.y
  1125. X      );
  1126. X  */
  1127. X
  1128. X  if ((! ptinrect(origin, game_board.map->rect)) ||
  1129. X      (! ptinrect(corner, game_board.map->rect)))
  1130. X    return 0;
  1131. X
  1132. X  return 1;
  1133. X}
  1134. X
  1135. Xint Game_Board_Spot_Empty(gmap, pt)
  1136. X     Bitmap *gmap;    /* game piece bitmap */
  1137. X     Point pt;        /* origin of game piece in game board bitmap */
  1138. X{
  1139. X  Point gpt, ept;
  1140. X  int x, y, maxx, maxy, bit;
  1141. X  Word *w;
  1142. X  extern Word *addr();
  1143. X
  1144. X  ept = add(pt, sub(gmap->rect.corner, gmap->rect.origin));
  1145. X  if (! Check_Bounds(pt, ept))
  1146. X    {
  1147. X      /*fprintf(stderr, "Game_Board_Spot_Empty(): Check_Bounds() failed\n");*/
  1148. X      return 0;
  1149. X    }
  1150. X
  1151. X  maxy = gmap->rect.corner.y;
  1152. X  maxx = gmap->rect.corner.x;
  1153. X
  1154. X  /*
  1155. X    For every bit set in the game piece bitmap
  1156. X    if corresponding bit in the game board bitmap, then fail
  1157. X    if all bits in game board are free, succeed.
  1158. X    */
  1159. X    
  1160. X  for (y = gmap->rect.origin.y; y < maxy; y++)
  1161. X    for (x = gmap->rect.origin.x; x < maxx; x++)
  1162. X      {
  1163. X    w = addr(gmap, Pt(x, y));
  1164. X
  1165. X    bit = FIRSTBIT >> (x % WORDSIZE);
  1166. X
  1167. X    if ((*w & bit) == bit)
  1168. X      {
  1169. X        gpt = add(pt, Pt(x, y));
  1170. X
  1171. X        w = addr(game_board.map, gpt);
  1172. X        bit = FIRSTBIT >> (gpt.x % WORDSIZE);
  1173. X
  1174. X        if ((*w & bit) == bit)
  1175. X          {
  1176. X        /*
  1177. X        fprintf(stderr,
  1178. X            "Game_Board_Spot_Empty(): point(%d,%d) occupied\n",
  1179. X            gpt.x, gpt.y
  1180. X            );
  1181. X        */
  1182. X        return 0;
  1183. X          }
  1184. X      }
  1185. X      }
  1186. X
  1187. X  /*
  1188. X  fprintf(stderr,
  1189. X      "Game_Board_Spot_Empty(): rectangle([%d,%d],[%d,%d]) is open\n",
  1190. X      pt.x, pt.y, ept.x, ept.y
  1191. X      );
  1192. X  */
  1193. X  return 1;
  1194. X}
  1195. X
  1196. Xint Can_Move(gp, d, orgpt)
  1197. X     GamePiece *gp;
  1198. X     enum MoveDirection d;
  1199. X     Point *orgpt;
  1200. X{
  1201. X  switch ((int) d)
  1202. X    {
  1203. X    case Left:
  1204. X      *orgpt = sub(game_board.curpt, Pt(1, 0));
  1205. X      break;
  1206. X    case Right:
  1207. X      *orgpt = add(game_board.curpt, Pt(1, 0));
  1208. X      break;
  1209. X    case Down:
  1210. X      *orgpt = add(game_board.curpt, Pt(0, 1));
  1211. X      break;
  1212. X
  1213. X    default:
  1214. X      return 0;
  1215. X    }
  1216. X
  1217. X  return Game_Board_Spot_Empty(gp->gmap_arr[gp->cur], *orgpt);
  1218. X}
  1219. X
  1220. Xint Can_Rotate(gp, d, orgpt, orient)
  1221. X     GamePiece *gp;
  1222. X     enum MoveDirection d;
  1223. X     Point *orgpt;
  1224. X     int *orient;
  1225. X{
  1226. X  Point center;
  1227. X
  1228. X  switch ((int) d)
  1229. X    {
  1230. X    case Clockwise:
  1231. X      *orient = ((gp->cur + 1 > 3) ? 0 : gp->cur + 1);
  1232. X      break;
  1233. X    case CounterClockwise:
  1234. X      *orient = ((gp->cur - 1 < 0) ? 3 : gp->cur - 1);
  1235. X      break;
  1236. X    default:
  1237. X      return 0;
  1238. X    }
  1239. X
  1240. X
  1241. X  /* Center calculations */
  1242. X  center = add(game_board.curpt,
  1243. X           div(
  1244. X           sub(gp->gmap_arr[gp->cur]->rect.corner,
  1245. X               gp->gmap_arr[gp->cur]->rect.origin
  1246. X               ),
  1247. X           2)
  1248. X           );
  1249. X
  1250. X  /* New origin calculations */
  1251. X  *orgpt = sub(center,
  1252. X           div(
  1253. X           sub(gp->gmap_arr[*orient]->rect.corner,
  1254. X               gp->gmap_arr[*orient]->rect.origin
  1255. X               ),
  1256. X           2)
  1257. X           );
  1258. X
  1259. X  return Game_Board_Spot_Empty(gp->gmap_arr[*orient], *orgpt);
  1260. X}
  1261. X
  1262. Xint Move_Piece(gp, d)
  1263. X     GamePiece *gp;
  1264. X     enum MoveDirection d;
  1265. X{
  1266. X  int new_orientation;
  1267. X  Point new_origin;
  1268. X  int retval;
  1269. X
  1270. X  switch ((int) d)
  1271. X    {
  1272. X    case FirstMove:
  1273. X      if (! Game_Board_Spot_Empty(gp->gmap_arr[gp->cur], game_board.curpt))
  1274. X    return 0;
  1275. X
  1276. X      break;
  1277. X
  1278. X    case Left:
  1279. X    case Right:
  1280. X    case Down:
  1281. X      Bitblit_Game_Board_XOR(gp);    /* first free current location */
  1282. X      if (! Can_Move(gp, d, &new_origin))
  1283. X    {
  1284. X      Bitblit_Game_Board_XOR(gp);    /* put it back */
  1285. X      return ((d == Down) ? -1 : 0);
  1286. X    }
  1287. X
  1288. X      Bitblit_Display_XOR(gp);        /* erase old impression */
  1289. X      game_board.curpt = new_origin;
  1290. X      break;
  1291. X
  1292. X    case Clockwise:
  1293. X    case CounterClockwise:
  1294. X      Bitblit_Game_Board_XOR(gp);
  1295. X      if (! Can_Rotate(gp, d, &new_origin, &new_orientation))
  1296. X    {
  1297. X      Bitblit_Game_Board_XOR(gp);    /* put it back */
  1298. X      return 0;
  1299. X    }
  1300. X
  1301. X      Bitblit_Display_XOR(gp);
  1302. X      gp->cur = new_orientation;
  1303. X      game_board.curpt = new_origin;
  1304. X      break;
  1305. X
  1306. X    case Fall:
  1307. X      while ((retval = Move_Piece(gp, Down)) > 0)
  1308. X    /* sleep(2) */;
  1309. X
  1310. X      return retval;
  1311. X    }
  1312. X
  1313. X  /*
  1314. X  fprintf(stderr,
  1315. X      "Move_Piece(): drawing (0x%x) at game_board location (%d,%d)\n",
  1316. X      gp, game_board.curpt.x, game_board.curpt.y
  1317. X      );
  1318. X  */
  1319. X  Bitblit_Piece_XOR(gp);
  1320. X  return 1;
  1321. X}
  1322. X
  1323. X  
  1324. END_OF_FILE
  1325.   if test 6521 -ne `wc -c <'motion.c'`; then
  1326.     echo shar: \"'motion.c'\" unpacked with wrong size!
  1327.   fi
  1328.   # end of 'motion.c'
  1329. fi
  1330. if test -f 'tetris.c' -a "${1}" != "-c" ; then 
  1331.   echo shar: Will not clobber existing file \"'tetris.c'\"
  1332. else
  1333.   echo shar: Extracting \"'tetris.c'\" \(5731 characters\)
  1334.   sed "s/^X//" >'tetris.c' <<'END_OF_FILE'
  1335. X/**********************************************************/
  1336. X/*                                                        */
  1337. X/* Copyright (C) 1993 Fariborz ``Skip'' Tavakkolian       */
  1338. X/*                                                        */
  1339. X/**********************************************************/
  1340. X
  1341. Xstatic char *RCSid = "$Id: tetris.c,v 1.4 93/06/13 12:28:25 fst Exp $";
  1342. X
  1343. X/*
  1344. X * Description:
  1345. X *
  1346. X * $Log:    tetris.c,v $
  1347. X * Revision 1.4  93/06/13  12:28:25  fst
  1348. X * Added casts to satisfy link.
  1349. X * 
  1350. X * Revision 1.3  93/06/06  11:07:13  fst
  1351. X * Added the current game piece to the arguments passed to Collapse_Full_Rows
  1352. X * to allow for checking of only those rows which are effected by the last
  1353. X * move.
  1354. X * 
  1355. X * Revision 1.2  93/06/05  22:11:16  fst
  1356. X * Changed the RCS ``Header'' with ``Id''.
  1357. X * 
  1358. X * Revision 1.1  93/06/05  22:03:58  fst
  1359. X * Initial revision
  1360. X * 
  1361. X */
  1362. X
  1363. X#include <dmd.h>
  1364. X#include <dmdio.h>
  1365. X#include <object.h>
  1366. X#include <font.h>
  1367. X#include "tetris.h"
  1368. X
  1369. X/* Library Routines and associated manual page. */
  1370. Xvoid bitblt();
  1371. Xvoid lprintf();
  1372. Xvoid sleep();
  1373. XPoint sPtCurrent();
  1374. Xint wait();
  1375. X
  1376. X
  1377. X/* tetris functions */
  1378. Xextern char *Gen_Menu_Items();
  1379. X
  1380. X/* local variables */
  1381. Xstatic int running = 0;
  1382. Xstatic int new_piece = 1;
  1383. Xstatic int fall_speed = FALL_SPEED;
  1384. Xstatic int p_count = 0;
  1385. Xstatic int score = 0;
  1386. X
  1387. X#define    ADJUST_SPEED()                    \
  1388. X{                            \
  1389. X  if (score > 50)                    \
  1390. X    {                            \
  1391. X      fall_speed = FALL_SPEED - (score / 25);        \
  1392. X      fall_speed = (fall_speed <= 10) ? 10 : fall_speed;\
  1393. X    }                            \
  1394. X}
  1395. X
  1396. XMenu top_level_menu =
  1397. X{
  1398. X  0, 0, 0, Gen_Menu_Items,
  1399. X};
  1400. X  
  1401. Xchar *Gen_Menu_Items(i)
  1402. X     int i;
  1403. X{
  1404. X  switch (i)
  1405. X    {
  1406. X    case 0:
  1407. X      return "New Game";
  1408. X    case 1:
  1409. X      return ((running) ? "Stop" : "Start");
  1410. X    case 2:
  1411. X      return "Quit";
  1412. X    default:
  1413. X      return NULL;
  1414. X    }
  1415. X}
  1416. X  
  1417. X#define    WAIT_TIME    5
  1418. X
  1419. XGamePiece *cgp, *ngp;
  1420. X
  1421. X
  1422. XDo_First_Move()
  1423. X{
  1424. X  int middle_x;
  1425. X
  1426. X  if (! running)
  1427. X    return 0;
  1428. X
  1429. X  middle_x = BOARD_WIDTH/2 -
  1430. X    (cgp->gmap_arr[cgp->cur]->rect.corner.x -
  1431. X     cgp->gmap_arr[cgp->cur]->rect.origin.x)/2;
  1432. X      
  1433. X  game_board.curpt = fPt(middle_x, 0);
  1434. X  /*
  1435. X  fprintf(stderr, "Do_First_Move(): game_board.curpt is (%d,%d)\n",
  1436. X      game_board.curpt.x, game_board.curpt.y
  1437. X      );
  1438. X  */
  1439. X  if (! Move_Piece(cgp, FirstMove)) /* first move and wont fit */
  1440. X    {
  1441. X      return 0;
  1442. X    }
  1443. X
  1444. X  return 1;
  1445. X}
  1446. X
  1447. Xstatic Point scoreloc, countloc;
  1448. XPoint nploc;
  1449. X
  1450. Xvoid Show_Score()
  1451. X{
  1452. X  char buff[16];
  1453. X
  1454. X  /* itoa((long) score, buff); */
  1455. X  Sprintf(buff, "%4d", score);
  1456. X  string(&largefont, buff, &display, add(Drect.origin, scoreloc), F_STORE);
  1457. X
  1458. X  /* itoa((long) p_count, buff); */
  1459. X  Sprintf(buff, "%4d", p_count);
  1460. X  string(&largefont, buff, &display, add(Drect.origin, countloc), F_STORE);
  1461. X}
  1462. X
  1463. Xvoid New_Game()
  1464. X{
  1465. X  Point q;
  1466. X
  1467. X  Clear_Game_Board();
  1468. X  Draw_Window();
  1469. X  q = add(Drect.origin, Srect.origin);
  1470. X  scoreloc = string(&largefont, " SCORE   ", &display, q, F_STORE);
  1471. X  scoreloc = sub(scoreloc, Drect.origin);
  1472. X
  1473. X  q = add(q, Pt(0, FONTHEIGHT(largefont)));
  1474. X  countloc = string(&largefont, " PIECES  ", &display, q, F_STORE);
  1475. X  countloc = sub(countloc, Drect.origin);
  1476. X
  1477. X  q = add(q, Pt(0, FONTHEIGHT(largefont)));
  1478. X  nploc = string(&largefont, " NEXT PIECE ", &display, q, F_STORE);
  1479. X  nploc = sub(nploc, Drect.origin);
  1480. X
  1481. X  ngp = Get_Next_Piece();
  1482. X  new_piece = 1;
  1483. X  running = 0;
  1484. X  p_count = 0;
  1485. X  score = 0;
  1486. X  fall_speed = FALL_SPEED;
  1487. X
  1488. X  Show_Score();
  1489. X}
  1490. X
  1491. Xvoid Collapse_Full_Rows()
  1492. X{
  1493. X  int n;
  1494. X
  1495. X  if (n = Show_Full_Rows(cgp))
  1496. X    Clear_Full_Rows(n, cgp);
  1497. X}
  1498. X
  1499. Xmain()
  1500. X{
  1501. X  extern GamePiece *Get_Next_Piece();
  1502. X  int bonus;
  1503. X
  1504. X  Initialize();
  1505. X  /* cache((char *) 0, A_NO_BOOT & ~A_SHARED); */
  1506. X  Reshape_Window();
  1507. X
  1508. X  request(MOUSE);
  1509. X  New_Game();
  1510. X
  1511. X  while (1)
  1512. X    {
  1513. X      alarm(0);
  1514. X      request(MOUSE);
  1515. X
  1516. X      while (! running)
  1517. X    {
  1518. X      wait(MOUSE);
  1519. X      if ((own() & MOUSE) && button2())
  1520. X        {
  1521. X          int m = menuhit(&top_level_menu, 2);
  1522. X          switch (m)
  1523. X        {
  1524. X        default:
  1525. X          break;
  1526. X        case 0:
  1527. X          New_Game();
  1528. X          break;
  1529. X
  1530. X        case 1:
  1531. X          running = 1;
  1532. X          break;
  1533. X
  1534. X        case 2:
  1535. X          exit();
  1536. X        }
  1537. X        }
  1538. X    }
  1539. X
  1540. X
  1541. X      alarm(fall_speed);
  1542. X      request(MOUSE|KBD|ALARM);
  1543. X      
  1544. X      while (running)
  1545. X    {
  1546. X      Show_Score();
  1547. X      if (new_piece)
  1548. X        {
  1549. X          alarm(0);
  1550. X          Collapse_Full_Rows();
  1551. X          Clear_Shadow_Area();
  1552. X          cgp = ngp;
  1553. X          ngp = Get_Next_Piece();
  1554. X          cgp->cur = 0;
  1555. X          Show_Next_Piece(ngp);
  1556. X
  1557. X          if (! Do_First_Move())
  1558. X        {
  1559. X          running = 0;
  1560. X          new_piece = 1;
  1561. X          break;
  1562. X        }
  1563. X          p_count++;
  1564. X          new_piece = 0;
  1565. X          ADJUST_SPEED();
  1566. X          alarm(fall_speed);
  1567. X        }
  1568. X
  1569. X      wait(ALARM|MOUSE|KBD);
  1570. X      if ((own() & MOUSE) && button2())
  1571. X        {
  1572. X          int m = menuhit(&top_level_menu, 2);
  1573. X          switch (m)
  1574. X        {
  1575. X        default:
  1576. X          break;
  1577. X        case 0:
  1578. X          New_Game();
  1579. X          break;
  1580. X
  1581. X        case 1:
  1582. X          running = 0;
  1583. X          break;
  1584. X
  1585. X        case 2:
  1586. X          exit();
  1587. X        }
  1588. X
  1589. X          if (! running)
  1590. X        break;
  1591. X        }
  1592. X
  1593. X      if (own() & ALARM)
  1594. X        {
  1595. X          alarm(0);
  1596. X          if (Move_Piece(cgp, Down) < 0)    /* resting */
  1597. X        {
  1598. X          score += cgp->score[cgp->cur];
  1599. X          new_piece = 1;
  1600. X          continue;
  1601. X        }
  1602. X
  1603. X          alarm(fall_speed);
  1604. X        }
  1605. X
  1606. X      if (own() & KBD)
  1607. X        {
  1608. X          switch (kbdchar())
  1609. X        {
  1610. X        default:
  1611. X          break;
  1612. X
  1613. X        case 0xE2:    /* right arrow */
  1614. X        case 'l':
  1615. X          (void) Move_Piece(cgp, Right);
  1616. X          break;
  1617. X
  1618. X        case 0xE3:    /* left arrow */
  1619. X        case 'h':
  1620. X          (void) Move_Piece(cgp, Left);
  1621. X          break;
  1622. X
  1623. X        case 0xE4:    /* home key */
  1624. X        case 'j':
  1625. X          (void) Move_Piece(cgp, Clockwise);
  1626. X          break;
  1627. X
  1628. X        case 0xE0:    /* up arrow */
  1629. X        case 'k':
  1630. X          (void) Move_Piece(cgp, CounterClockwise);
  1631. X          break;
  1632. X
  1633. X        case 0xE1:    /* down arrow */
  1634. X        case ' ':
  1635. X          bonus = BOARD_HEIGHT - game_board.curpt.y;
  1636. X          (void) Move_Piece(cgp, Fall);
  1637. X          score += cgp->score[cgp->cur];
  1638. X          score += bonus/2;    /* give them half the fall distance */
  1639. X
  1640. X          /* after a fall, the piece is always resting */
  1641. X          new_piece = 1;
  1642. X          break;
  1643. X        }
  1644. X        }
  1645. X    }
  1646. X    }
  1647. X}
  1648. X
  1649. END_OF_FILE
  1650.   if test 5731 -ne `wc -c <'tetris.c'`; then
  1651.     echo shar: \"'tetris.c'\" unpacked with wrong size!
  1652.   fi
  1653.   # end of 'tetris.c'
  1654. fi
  1655. if test -f 'tetris.h' -a "${1}" != "-c" ; then 
  1656.   echo shar: Will not clobber existing file \"'tetris.h'\"
  1657. else
  1658.   echo shar: Extracting \"'tetris.h'\" \(2942 characters\)
  1659.   sed "s/^X//" >'tetris.h' <<'END_OF_FILE'
  1660. X/**********************************************************/
  1661. X/*                                                        */
  1662. X/* Copyright (C) 1993 Fariborz ``Skip'' Tavakkolian       */
  1663. X/* All rights reserved                                    */
  1664. X/*                                                        */
  1665. X/**********************************************************/
  1666. X
  1667. X#ident "$Id: tetris.h,v 1.3 93/06/13 12:29:25 fst Exp $"
  1668. X
  1669. X/*
  1670. X * Description:
  1671. X *
  1672. X * $Log:    tetris.h,v $
  1673. X * Revision 1.3  93/06/13  12:29:25  fst
  1674. X * Added forward declarations, and some external function declarations.
  1675. X * 
  1676. X * Revision 1.2  93/06/05  22:11:25  fst
  1677. X * Changed the RCS ``Header'' with ``Id''.
  1678. X * 
  1679. X * Revision 1.1  93/06/05  22:04:29  fst
  1680. X * Initial revision
  1681. X * 
  1682. X */
  1683. X
  1684. X#ifndef    _tetris_h
  1685. X#define    _tetris_h
  1686. X
  1687. X/* DMD Library Routines */
  1688. Xextern void bitblt();
  1689. Xextern void lprintf();
  1690. Xextern alarm();
  1691. Xextern int request();
  1692. Xextern int own();
  1693. Xextern int wait();
  1694. Xextern Point sPtCurrent();
  1695. X
  1696. X
  1697. X#define    DIM(x)    (sizeof(x)/sizeof((x)[0]))
  1698. X
  1699. X/* NOTE:
  1700. X   Do not set BOARD_WIDTH greater than 16
  1701. X   */
  1702. X#define    BOARD_WIDTH    10
  1703. X#define    BOARD_HEIGHT    30
  1704. X#define    PIECES_COUNT    7
  1705. X
  1706. X#define    TET_INSET    4
  1707. X#define    BBW        1
  1708. X#define    CHARCOUNT    18
  1709. X#define    TEXTWIDTH    (FONTWIDTH(largefont)*CHARCOUNT)
  1710. X#define    GBW    (BOARD_WIDTH * 16)
  1711. X#define    GBH    (BOARD_HEIGHT* 16)
  1712. X
  1713. X/* 1 tick = 1/60 of a second */
  1714. X#define    FALL_SPEED    30
  1715. X
  1716. X/*
  1717. X  FULL_ROW_MASK greater than FFFF wont work
  1718. X  (see drawing.c Collapse_Full_Rows)
  1719. X  */
  1720. X#define    FULL_ROW_MASK    0xFFC0
  1721. X
  1722. Xextern Texture16 hashmark;
  1723. X
  1724. Xenum MoveDirection
  1725. X{
  1726. X  FirstMove,
  1727. X  Fall,
  1728. X  Left,
  1729. X  Right,
  1730. X  Down,
  1731. X  Clockwise,
  1732. X  CounterClockwise,
  1733. X};
  1734. X
  1735. Xenum Boolean
  1736. X{
  1737. X  False = 0,
  1738. X  True,
  1739. X};
  1740. X
  1741. Xtypedef struct
  1742. X{
  1743. X  Point curpt;
  1744. X  Bitmap *map;
  1745. X} Board;
  1746. X
  1747. Xextern Board game_board;
  1748. X
  1749. Xtypedef struct
  1750. X{
  1751. X  int cur;
  1752. X  Texture16 *color;    /* color for this game piece */
  1753. X  int score[4];        /* points scored for each orientation of the piece */
  1754. X  Bitmap *gmap_arr[4];    /* the game bitmap (one bit per brick)           */
  1755. X  Bitmap *smap_arr[4];    /* shape bit map.  This is built from gmap       */
  1756. X} GamePiece;
  1757. X
  1758. Xextern GamePiece *Pieces[];
  1759. Xextern Texture16 *colors[];
  1760. Xextern Rectangle Srect, Grect, Mrect;
  1761. Xextern Point nploc;
  1762. X
  1763. X#ifdef    _STDC_
  1764. X# define    __(x)    x
  1765. X#else
  1766. X# define    __(x)    ()
  1767. X#endif
  1768. X
  1769. X/* dmdtetris functions */
  1770. Xextern GamePiece *Get_Next_Piece();
  1771. X
  1772. Xextern void Clear_Game_Board ();
  1773. Xextern void Draw_Window      ();
  1774. Xextern void Clear_Shadow_Area();
  1775. Xextern void Reshape_Window   ();
  1776. Xextern void Clear_Full_Rows  ();
  1777. Xextern void Init_Pieces      ();
  1778. Xextern void Initialize       ();
  1779. X
  1780. Xextern void Show_Next_Piece       __((GamePiece* ));
  1781. Xextern void Bitblit_Game_Board_XOR __((GamePiece* ));
  1782. Xextern void Bitblit_Display_XOR       __((GamePiece* ));
  1783. Xextern void Bitblit_Piece_XOR       __((GamePiece* ));
  1784. Xextern void Set_Color           __((Bitmap*, Texture16* ));
  1785. Xextern void Populate_Bitmap       __((Bitmap*, Bitmap* ));
  1786. X
  1787. Xextern int Show_Full_Rows();
  1788. X
  1789. Xextern Point default_size __((int x, int y, struct Proc* ));
  1790. X
  1791. X#endif    /* _tetris_h */
  1792. END_OF_FILE
  1793.   if test 2942 -ne `wc -c <'tetris.h'`; then
  1794.     echo shar: \"'tetris.h'\" unpacked with wrong size!
  1795.   fi
  1796.   # end of 'tetris.h'
  1797. fi
  1798. echo shar: End of archive 1 \(of 1\).
  1799. cp /dev/null ark1isdone
  1800. MISSING=""
  1801. for I in 1 ; do
  1802.     if test ! -f ark${I}isdone ; then
  1803.     MISSING="${MISSING} ${I}"
  1804.     fi
  1805. done
  1806. if test "${MISSING}" = "" ; then
  1807.     echo You have the archive.
  1808.     rm -f ark[1-9]isdone
  1809. else
  1810.     echo You still must unpack the following archives:
  1811.     echo "        " ${MISSING}
  1812. fi
  1813. exit 0
  1814. exit 0 # Just in case...
  1815.