Source for "tetrix" game (reposted)

Mark H. Weber mhw at lock60.UUCP
Mon Jan 8 16:48:21 AEST 1990


Here's the re-posted source for the "tetrix" (tetris) game. It's
a shell archive, use your editor to chop off everything up to the
!/bin/sh line, then feed it into sh. The version of "shar" that I 
used is not very sophisticated and will allow overwriting of existing
files, so make sure you have the file in the proper directory before you
do the extraction. For those of you who alredy have this, sorry for 
using the bandwidth, but a lot of people never saw this. Have fun!


#!/bin/sh
# shar:	Shell Archiver  (v1.22)
#
#	Run the following text with /bin/sh to create:
#	  AdvanceP.c
#	  Makefile
#	  MoveL.c
#	  MoveR.c
#	  NewP.c
#	  README
#	  Rotate.c
#	  tet.c
#	  tet.h
#	  window.c
#
sed 's/^X//' << 'SHAR_EOF' > AdvanceP.c &&
X
X#include <tam.h>
X#include <termio.h>
X#include "tet.h"
X/*********************************************************************/
X/* Switch on type of piece, find out if I can move down */
X/* If so, then do it and return 1 else return 0 */
X/*********************************************************************/
XAdvancePiece()
X{
Xswitch (Type) {
X	/*  WHITE PIECES  */
X	case W_TYPE	: 
X		    if (IS_FREE(Column-1,Row+1) && 
X			IS_FREE(Column,Row+2) &&
X			IS_FREE(Column+1,Row+1)) 
X				{
X				PUTCH(Column-1,Row,NO_CHAR);
X				PUTCH(Column,Row,NO_CHAR);
X				PUTCH(Column+1,Row,NO_CHAR);
X				PUTCH(Column-1,Row+1,W_CHAR);
X				PUTCH(Column,Row+2,W_CHAR);
X				PUTCH(Column+1,Row+1,W_CHAR);
X				Row +=1;
X				goto out;
X				}
X			else goto badout;
X
X	case W_TYPE-1 :
X		    if (IS_FREE(Column,Row+2) && 
X			IS_FREE(Column+1,Row+1))
X				{
X				PUTCH(Column,Row-1,NO_CHAR);
X				PUTCH(Column+1,Row,NO_CHAR);
X				PUTCH(Column,Row+2,W_CHAR);
X				PUTCH(Column+1,Row+1,W_CHAR);
X				Row +=1;
X				goto out;
X				}
X			else goto badout;
X
X	case W_TYPE-2 :  
X		    if (IS_FREE(Column-1,Row+1) && 	
X			IS_FREE(Column,Row+1) && 
X			IS_FREE(Column+1,Row+1))
X				{
X				PUTCH(Column-1,Row,NO_CHAR);
X				PUTCH(Column,Row-1,NO_CHAR);
X				PUTCH(Column+1,Row,NO_CHAR);
X				PUTCH(Column-1,Row+1,W_CHAR);
X				PUTCH(Column,Row+1,W_CHAR);
X				PUTCH(Column+1,Row+1,W_CHAR);
X				Row +=1;
X				goto out;
X				}
X			else goto badout;
X
X	case W_TYPE-3 :  
X		    if (IS_FREE(Column-1,Row+1) && 	
X			IS_FREE(Column,Row+2))
X				{
X				PUTCH(Column-1,Row,NO_CHAR);
X				PUTCH(Column,Row-1,NO_CHAR);
X				PUTCH(Column-1,Row+1,W_CHAR);
X				PUTCH(Column,Row+2,W_CHAR);
X				Row +=1;
X				goto out;
X				}
X			else goto badout;
X
X
X	/*  RED PIECES  */
X	case R_TYPE   : 
X		    if (IS_FREE(Column-1,Row+2) && 
X			IS_FREE(Column,Row+1) &&
X			IS_FREE(Column+1,Row+1))
X				{
X				PUTCH(Column-1,Row,NO_CHAR);
X				PUTCH(Column,Row,NO_CHAR);
X				PUTCH(Column+1,Row,NO_CHAR);
X				PUTCH(Column-1,Row+2,R_CHAR);
X				PUTCH(Column,Row+1,R_CHAR);
X				PUTCH(Column+1,Row+1,R_CHAR);
X				Row +=1;
X				goto out;
X				}
X			else goto badout;
X
X	case R_TYPE-1 : 
X		    if (IS_FREE(Column,Row+2) && 
X			IS_FREE(Column+1,Row+2))
X				{
X				PUTCH(Column,Row-1,NO_CHAR);
X				PUTCH(Column+1,Row+1,NO_CHAR);
X				PUTCH(Column,Row+2,R_CHAR);
X				PUTCH(Column+1,Row+2,R_CHAR);
X				Row +=1;
X				goto out;
X				}
X			else goto badout;
X
X	case R_TYPE-2 : 
X		    if (IS_FREE(Column-1,Row+1) && 
X			IS_FREE(Column,Row+1) &&
X			IS_FREE(Column+1,Row+1))
X				{
X				PUTCH(Column-1,Row,NO_CHAR);
X				PUTCH(Column,Row,NO_CHAR);
X				PUTCH(Column+1,Row-1,NO_CHAR);
X				PUTCH(Column-1,Row+1,R_CHAR);
X				PUTCH(Column,Row+1,R_CHAR);
X				PUTCH(Column+1,Row+1,R_CHAR);
X				Row +=1;
X				goto out;
X				}
X			else goto badout;
X
X	case R_TYPE-3 : 
X		    if (IS_FREE(Column-1,Row) && 
X			IS_FREE(Column,Row+2))
X				{
X				PUTCH(Column-1,Row-1,NO_CHAR);
X				PUTCH(Column,Row-1,NO_CHAR);
X				PUTCH(Column-1,Row,R_CHAR);
X				PUTCH(Column,Row+2,R_CHAR);
X				Row +=1;
X				goto out;
X				}
X			else goto badout;
X
X
X	/*  TAN PIECES  */
X	case T_TYPE   :
X	case T_TYPE-1 :
X	case T_TYPE-2 :
X	case T_TYPE-3 :
X		    if (IS_FREE(Column,Row+2) && 
X			IS_FREE(Column+1,Row+2))
X				{
X				PUTCH(Column,Row,NO_CHAR);
X				PUTCH(Column+1,Row,NO_CHAR);
X				PUTCH(Column,Row+2,T_CHAR);
X				PUTCH(Column+1,Row+2,T_CHAR);
X				Row +=1;
X				goto out;
X				}
X			else goto badout;
X
X
X	/*  YELLOW PIECES  */
X	case Y_TYPE   :
X	case Y_TYPE-2 :  
X		    if (IS_FREE(Column-1,Row+2) && 
X			IS_FREE(Column,Row+2) &&
X			IS_FREE(Column+1,Row+1))
X				{
X				PUTCH(Column-1,Row+1,NO_CHAR);
X				PUTCH(Column,Row,NO_CHAR);
X				PUTCH(Column+1,Row,NO_CHAR);
X				PUTCH(Column-1,Row+2,Y_CHAR);
X				PUTCH(Column,Row+2,Y_CHAR);
X				PUTCH(Column+1,Row+1,Y_CHAR);
X				Row +=1;
X				goto out;
X				}
X			else goto badout;
X
X	case Y_TYPE-1 :
X	case Y_TYPE-3 : 
X		    if (IS_FREE(Column,Row+1) && 
X			IS_FREE(Column+1,Row+2))
X				{
X				PUTCH(Column,Row-1,NO_CHAR);
X				PUTCH(Column+1,Row,NO_CHAR);
X				PUTCH(Column,Row+1,Y_CHAR);
X				PUTCH(Column+1,Row+2,Y_CHAR);
X				Row +=1;
X				goto out;
X				}
X			else goto badout;
X
X
X	/*  GREEN PIECES  */
X	case G_TYPE   :
X	case G_TYPE-2 : 
X		    if (IS_FREE(Column-1,Row+1) && 
X			IS_FREE(Column,Row+2) &&
X			IS_FREE(Column+1,Row+2))
X				{
X				PUTCH(Column-1,Row,NO_CHAR);
X				PUTCH(Column,Row,NO_CHAR);
X				PUTCH(Column+1,Row+1,NO_CHAR);
X				PUTCH(Column-1,Row+1,G_CHAR);
X				PUTCH(Column,Row+2,G_CHAR);
X				PUTCH(Column+1,Row+2,G_CHAR);
X				Row +=1;
X				goto out;
X				}
X			else goto badout;
X
X	case G_TYPE-1 :
X	case G_TYPE-3 : 
X		    if (IS_FREE(Column-1,Row+2) && 
X			IS_FREE(Column,Row+1))
X				{
X				PUTCH(Column,Row-1,NO_CHAR);
X				PUTCH(Column-1,Row,NO_CHAR);
X				PUTCH(Column,Row+1,G_CHAR);
X				PUTCH(Column-1,Row+2,G_CHAR);
X				Row +=1;
X				goto out;
X				}
X			else goto badout;
X
X
X	/*  BLUE PIECES  */
X	case B_TYPE   : 
X		    if (IS_FREE(Column-1,Row+1) && 
X			IS_FREE(Column,Row+1) &&
X			IS_FREE(Column+1,Row+2))
X				{
X				PUTCH(Column-1,Row,NO_CHAR);
X				PUTCH(Column,Row,NO_CHAR);
X				PUTCH(Column+1,Row,NO_CHAR);
X				PUTCH(Column-1,Row+1,B_CHAR);
X				PUTCH(Column,Row+1,B_CHAR);
X				PUTCH(Column+1,Row+2,B_CHAR);
X				Row +=1;
X				goto out;
X				}
X			else goto badout;
X
X	case B_TYPE-1 : 
X		    if (IS_FREE(Column,Row+2) && 
X			IS_FREE(Column+1,Row))
X				{
X				PUTCH(Column,Row-1,NO_CHAR);
X				PUTCH(Column+1,Row-1,NO_CHAR);
X				PUTCH(Column,Row+2,B_CHAR);
X				PUTCH(Column+1,Row,B_CHAR);
X				Row +=1;
X				goto out;
X				}
X			else goto badout;
X
X	case B_TYPE-2 : 
X		    if (IS_FREE(Column-1,Row+1) && 
X			IS_FREE(Column,Row+1) &&
X			IS_FREE(Column+1,Row+1))
X				{
X				PUTCH(Column-1,Row-1,NO_CHAR);
X				PUTCH(Column,Row,NO_CHAR);
X				PUTCH(Column+1,Row,NO_CHAR);
X				PUTCH(Column-1,Row+1,B_CHAR);
X				PUTCH(Column,Row+1,B_CHAR);
X				PUTCH(Column+1,Row+1,B_CHAR);
X				Row +=1;
X				goto out;
X				}
X			else goto badout;
X
X	case B_TYPE-3 : 
X		    if (IS_FREE(Column-1,Row+2) && 
X			IS_FREE(Column,Row+2))
X				{
X				PUTCH(Column-1,Row+1,NO_CHAR);
X				PUTCH(Column,Row-1,NO_CHAR);
X				PUTCH(Column-1,Row+2,B_CHAR);
X				PUTCH(Column,Row+2,B_CHAR);
X				Row +=1;
X				goto out;
X				}
X			else goto badout;
X
X
X	/*  VIOLET PIECES  */
X	case V_TYPE   :
X	case V_TYPE-2 : 
X		    if (IS_FREE(Column-1,Row+1) && 
X			IS_FREE(Column,Row+1) && 
X			IS_FREE(Column+1,Row+1) && 
X			IS_FREE(Column+2,Row+1))
X				{
X				PUTCH(Column-1,Row,NO_CHAR);
X				PUTCH(Column,Row,NO_CHAR);
X				PUTCH(Column+1,Row,NO_CHAR);
X				PUTCH(Column+2,Row,NO_CHAR);
X				PUTCH(Column-1,Row+1,V_CHAR);
X				PUTCH(Column,Row+1,V_CHAR);
X				PUTCH(Column+1,Row+1,V_CHAR);
X				PUTCH(Column+2,Row+1,V_CHAR);
X				Row +=1;
X				goto out;
X				}
X			else goto badout;
X
X	case V_TYPE-1 :
X	case V_TYPE-3 : 
X		    if (IS_FREE(Column,Row+3)) 
X				{
X				PUTCH(Column,Row-1,NO_CHAR);
X				PUTCH(Column,Row+3,V_CHAR);
X				Row +=1;
X				goto out;
X				}
X			else goto badout;
X
X	default : 
X		printf("Advance Piece: illegal piece Type=%d!!\n",Type); 
X		exit();
X	}
Xbadout:
X	return(0);
Xout:
X	refresh();
X	return(1);
X}
SHAR_EOF
chmod 0644 AdvanceP.c || echo "restore of AdvanceP.c fails"
sed 's/^X//' << 'SHAR_EOF' > Makefile &&
X#  - un'cpio' this in /usr/src or /usr/local/src or something - doesn't matter.
X#  - do a 'make install' in the tetrix directory
X#  - tetrix gets installed in /usr/local/bin
X#  - this will create a high score file in /usr/tmp, so doing it again
X#    later on will erase high scores for the machine.
X
X
XOBJS= MoveR.o MoveL.o NewP.o AdvanceP.o Rotate.o tet.o window.o
XINCS= tet.h
X
Xtetrix: $(OBJS) $(INCS)
X	$(CC) -O -s $(OBJS) -o tetrix -ltam -ltermlib
X
XMoveR.o: MoveR.c
X
Xwindow.o: window.c
X
XMoveL.o: MoveL.c
X
XNewP.o: NewP.c
X
XAdvanceP.o: AdvanceP.c
X
XRotate.o: Rotate.c
X
Xtet.o: tet.c
X
Xinstall: tetrix
X	chmod 755 tetrix
X	/bin/mv -f tetrix /usr/local/bin
X
Xclean:
X	/bin/rm -rf tetrix core *.o
SHAR_EOF
chmod 0644 Makefile || echo "restore of Makefile fails"
sed 's/^X//' << 'SHAR_EOF' > MoveL.c &&
X
X#include <tam.h>
X#include <termio.h>
X#include "tet.h"
X/*********************************************************************/
X/* Switch on type of piece, find out if I can move left */
X/* If so, then do it */
X/*********************************************************************/
XMoveLeft()
X{
Xswitch (Type) {
X	/*  WHITE PIECES  */
X	case W_TYPE   :  /* checked */
X		if (IS_FREE(Column-2,Row) && IS_FREE(Column-1,Row+1)) {
X			PUTCH(Column+1,Row,NO_CHAR);
X			PUTCH(Column,Row+1,NO_CHAR);
X			PUTCH(Column-2,Row,W_CHAR);
X			PUTCH(Column-1,Row+1,W_CHAR);
X			Column -=1;
X			}
X		else goto beepout;
X		goto out;
X	case W_TYPE-1 :  /* checked */
X		if (IS_FREE(Column-1,Row-1) && IS_FREE(Column-1,Row) && 
X		    IS_FREE(Column-1,Row+1)) {
X			PUTCH(Column,Row-1,NO_CHAR);
X			PUTCH(Column+1,Row,NO_CHAR);
X			PUTCH(Column,Row+1,NO_CHAR);
X			PUTCH(Column-1,Row-1,W_CHAR);
X			PUTCH(Column-1,Row,W_CHAR);
X			PUTCH(Column-1,Row+1,W_CHAR);
X			Column -=1;
X			}
X		else goto beepout;
X		goto out;
X	case W_TYPE-2 :  /* checked */
X		if (IS_FREE(Column-2,Row) && IS_FREE(Column-1,Row-1)) {
X			PUTCH(Column+1,Row,NO_CHAR);
X			PUTCH(Column,Row-1,NO_CHAR);
X			PUTCH(Column-2,Row,W_CHAR);
X			PUTCH(Column-1,Row-1,W_CHAR);
X			Column -=1;
X			}
X		else goto beepout;
X		goto out;
X	case W_TYPE-3 :  /* checked */
X		if (IS_FREE(Column-1,Row-1) && IS_FREE(Column-2,Row) && 
X		    IS_FREE(Column-1,Row+1)) {
X			PUTCH(Column,Row-1,NO_CHAR);
X			PUTCH(Column,Row,NO_CHAR);
X			PUTCH(Column,Row+1,NO_CHAR);
X			PUTCH(Column-1,Row-1,W_CHAR);
X			PUTCH(Column-2,Row,W_CHAR);
X			PUTCH(Column-1,Row+1,W_CHAR);
X			Column -=1;
X			}
X		else goto beepout;
X		goto out;
X
X	/*  RED PIECES  */
X	case R_TYPE   : /* checked */
X		if (IS_FREE(Column-2,Row) && IS_FREE(Column-2,Row+1)) {
X			PUTCH(Column+1,Row,NO_CHAR);
X			PUTCH(Column-1,Row+1,NO_CHAR);
X			PUTCH(Column-2,Row,R_CHAR);
X			PUTCH(Column-2,Row+1,R_CHAR);
X			Column -=1;
X			}
X		else goto beepout;
X		goto out;
X	case R_TYPE-1 : /* checked */
X		if (IS_FREE(Column-1,Row-1) && IS_FREE(Column-1,Row) && 
X		    IS_FREE(Column-1,Row+1)) {
X			PUTCH(Column,Row-1,NO_CHAR);
X			PUTCH(Column,Row,NO_CHAR);
X			PUTCH(Column+1,Row+1,NO_CHAR);
X			PUTCH(Column-1,Row-1,R_CHAR);
X			PUTCH(Column-1,Row,R_CHAR);
X			PUTCH(Column-1,Row+1,R_CHAR);
X			Column -=1;
X			}
X		else goto beepout;
X		goto out;
X	case R_TYPE-2 : /* checked  */
X		if (IS_FREE(Column-2,Row) && IS_FREE(Column,Row-1)) {
X			PUTCH(Column+1,Row-1,NO_CHAR);
X			PUTCH(Column+1,Row,NO_CHAR);
X			PUTCH(Column-2,Row,R_CHAR);
X			PUTCH(Column,Row-1,R_CHAR);
X			Column -=1;
X			}
X		else goto beepout;
X		goto out;
X	case R_TYPE-3 : /* checked */
X		if (IS_FREE(Column-2,Row-1) && IS_FREE(Column-1,Row) && 
X		    IS_FREE(Column-1,Row+1)) {
X			PUTCH(Column,Row-1,NO_CHAR);
X			PUTCH(Column,Row,NO_CHAR);
X			PUTCH(Column,Row+1,NO_CHAR);
X			PUTCH(Column-2,Row-1,R_CHAR);
X			PUTCH(Column-1,Row,R_CHAR);
X			PUTCH(Column-1,Row+1,R_CHAR);
X			Column -=1;
X			}
X		else goto beepout;
X		goto out;
X
X	/*  TAN PIECES  */
X	case T_TYPE   :
X	case T_TYPE-1 :
X	case T_TYPE-2 :
X	case T_TYPE-3 : /* checked */
X		if (IS_FREE(Column-1,Row) && IS_FREE(Column-1,Row+1)) {
X			PUTCH(Column+1,Row,NO_CHAR);
X			PUTCH(Column+1,Row+1,NO_CHAR);
X			PUTCH(Column-1,Row,T_CHAR);
X			PUTCH(Column-1,Row+1,T_CHAR);
X			Column -=1;
X			}
X		else goto beepout;
X		goto out;
X
X	/*  YELLOW PIECES  */
X	case Y_TYPE   :
X	case Y_TYPE-2 :  /* checked */
X		if (IS_FREE(Column-1,Row) && IS_FREE(Column-2,Row+1)) {
X			PUTCH(Column+1,Row,NO_CHAR);
X			PUTCH(Column,Row+1,NO_CHAR);
X			PUTCH(Column-1,Row,Y_CHAR);
X			PUTCH(Column-2,Row+1,Y_CHAR);
X			Column -=1;
X			}
X		else goto beepout;
X		goto out;
X	case Y_TYPE-1 :
X	case Y_TYPE-3 : /* checked */
X		if (IS_FREE(Column-1,Row-1) && IS_FREE(Column-1,Row) && 
X		    IS_FREE(Column,Row+1)) {
X			PUTCH(Column,Row-1,NO_CHAR);
X			PUTCH(Column+1,Row,NO_CHAR);
X			PUTCH(Column+1,Row+1,NO_CHAR);
X			PUTCH(Column-1,Row-1,Y_CHAR);
X			PUTCH(Column-1,Row,Y_CHAR);
X			PUTCH(Column,Row+1,Y_CHAR);
X			Column -=1;
X			}
X		else goto beepout;
X		goto out;
X
X	/*  GREEN PIECES  */
X	case G_TYPE   :
X	case G_TYPE-2 : /* checked */
X		if (IS_FREE(Column-2,Row) && IS_FREE(Column-1,Row+1)) {
X			PUTCH(Column,Row,NO_CHAR);
X			PUTCH(Column+1,Row+1,NO_CHAR);
X			PUTCH(Column-2,Row,G_CHAR);
X			PUTCH(Column-1,Row+1,G_CHAR);
X			Column -=1;
X			}
X		else goto beepout;
X		goto out;
X	case G_TYPE-1 :
X	case G_TYPE-3 : /* checked */
X		if (IS_FREE(Column-1,Row-1) && IS_FREE(Column-2,Row) && 
X		    IS_FREE(Column-2,Row+1)) {
X			PUTCH(Column,Row-1,NO_CHAR);
X			PUTCH(Column,Row,NO_CHAR);
X			PUTCH(Column-1,Row+1,NO_CHAR);
X			PUTCH(Column-1,Row-1,G_CHAR);
X			PUTCH(Column-2,Row,G_CHAR);
X			PUTCH(Column-2,Row+1,G_CHAR);
X			Column -=1;
X			}
X		else goto beepout;
X		goto out;
X
X	/*  BLUE PIECES  */
X	case B_TYPE   : /* checked */
X		if (IS_FREE(Column-2,Row) && IS_FREE(Column,Row+1)) {
X			PUTCH(Column+1,Row,NO_CHAR);
X			PUTCH(Column+1,Row+1,NO_CHAR);
X			PUTCH(Column-2,Row,B_CHAR);
X			PUTCH(Column,Row+1,B_CHAR);
X			Column -=1;
X			}
X		else goto beepout;
X		goto out;
X	case B_TYPE-1 : /* checked */
X		if (IS_FREE(Column-1,Row-1) && IS_FREE(Column-1,Row) && 
X		    IS_FREE(Column-1,Row+1)) {
X			PUTCH(Column+1,Row-1,NO_CHAR);
X			PUTCH(Column,Row,NO_CHAR);
X			PUTCH(Column,Row+1,NO_CHAR);
X			PUTCH(Column-1,Row-1,B_CHAR);
X			PUTCH(Column-1,Row,B_CHAR);
X			PUTCH(Column-1,Row+1,B_CHAR);
X			Column -=1;
X			}
X		else goto beepout;
X		goto out;
X	case B_TYPE-2 : /* checked */
X		if (IS_FREE(Column-2,Row-1) && IS_FREE(Column-2,Row)) {
X			PUTCH(Column-1,Row-1,NO_CHAR);
X			PUTCH(Column+1,Row,NO_CHAR);
X			PUTCH(Column-2,Row-1,B_CHAR);
X			PUTCH(Column-2,Row,B_CHAR);
X			Column -=1;
X			}
X		else goto beepout;
X		goto out;
X	case B_TYPE-3 : /* checked */
X		if (IS_FREE(Column-1,Row-1) && IS_FREE(Column-1,Row) && 
X		    IS_FREE(Column-2,Row+1)) {
X			PUTCH(Column,Row-1,NO_CHAR);
X			PUTCH(Column,Row,NO_CHAR);
X			PUTCH(Column,Row+1,NO_CHAR);
X			PUTCH(Column-1,Row-1,B_CHAR);
X			PUTCH(Column-1,Row,B_CHAR);
X			PUTCH(Column-2,Row+1,B_CHAR);
X			Column -=1;
X			}
X		else goto beepout;
X		goto out;
X
X	/*  VIOLET PIECES  */
X	case V_TYPE   :
X	case V_TYPE-2 : /* checked */
X		if (IS_FREE(Column-2,Row)) {
X			PUTCH(Column+2,Row,NO_CHAR);
X			PUTCH(Column-2,Row,V_CHAR);
X			Column -=1;
X			}
X		else goto beepout;
X		goto out;
X	case V_TYPE-1 :
X	case V_TYPE-3 : /* checked */
X		if (IS_FREE(Column-1,Row-1) && IS_FREE(Column-1,Row) && 
X		    IS_FREE(Column-1,Row+1) && IS_FREE(Column-1,Row+2)) {
X			PUTCH(Column,Row-1,NO_CHAR);
X			PUTCH(Column,Row,NO_CHAR);
X			PUTCH(Column,Row+1,NO_CHAR);
X			PUTCH(Column,Row+2,NO_CHAR);
X			PUTCH(Column-1,Row-1,V_CHAR);
X			PUTCH(Column-1,Row,V_CHAR);
X			PUTCH(Column-1,Row+1,V_CHAR);
X			PUTCH(Column-1,Row+2,V_CHAR);
X			Column -=1;
X			}
X		else goto beepout;
X		goto out;
X	default : 
X		printf("illegal piece Type=%d!!\n",Type); 
X		exit();
X	}
Xbeepout:
X	if (Beep) beep();
Xout:
X	refresh();
X}
X
SHAR_EOF
chmod 0644 MoveL.c || echo "restore of MoveL.c fails"
sed 's/^X//' << 'SHAR_EOF' > MoveR.c &&
X
X#include <tam.h>
X#include <termio.h>
X#include "tet.h"
X/*********************************************************************/
X/* Switch on type of piece, find out if I can move right */
X/* If so, then do it */
X/*********************************************************************/
XMoveRight()
X{
Xswitch (Type) {
X
X	/*  WHITE PIECES  */
X	case W_TYPE   : /*  */
X		if (IS_FREE(Column+2,Row) && IS_FREE(Column+1,Row+1)) {
X			PUTCH(Column-1,Row,NO_CHAR);
X			PUTCH(Column,Row+1,NO_CHAR);
X			PUTCH(Column+2,Row,W_CHAR);
X			PUTCH(Column+1,Row+1,W_CHAR);
X			Column +=1;
X			}
X		else goto beepout;
X		goto out;
X	case W_TYPE-1 :  /*  */
X		if (IS_FREE(Column+1,Row-1) && IS_FREE(Column+2,Row) && 
X		    IS_FREE(Column+1,Row+1)) {
X			PUTCH(Column,Row-1,NO_CHAR);
X			PUTCH(Column,Row,NO_CHAR);
X			PUTCH(Column,Row+1,NO_CHAR);
X			PUTCH(Column+1,Row-1,W_CHAR);
X			PUTCH(Column+2,Row,W_CHAR);
X			PUTCH(Column+1,Row+1,W_CHAR);
X			Column +=1;
X			}
X		else goto beepout;
X		goto out;
X	case W_TYPE-2 :  /*  */
X		if (IS_FREE(Column+2,Row) && IS_FREE(Column+1,Row-1)) {
X			PUTCH(Column-1,Row,NO_CHAR);
X			PUTCH(Column,Row-1,NO_CHAR);
X			PUTCH(Column+2,Row,W_CHAR);
X			PUTCH(Column+1,Row-1,W_CHAR);
X			Column +=1;
X			}
X		else goto beepout;
X		goto out;
X	case W_TYPE-3 :  /*  */
X		if (IS_FREE(Column+1,Row-1) && IS_FREE(Column+1,Row) && 
X		    IS_FREE(Column+1,Row+1)) {
X			PUTCH(Column,Row-1,NO_CHAR);
X			PUTCH(Column-1,Row,NO_CHAR);
X			PUTCH(Column,Row+1,NO_CHAR);
X			PUTCH(Column+1,Row-1,W_CHAR);
X			PUTCH(Column+1,Row,W_CHAR);
X			PUTCH(Column+1,Row+1,W_CHAR);
X			Column +=1;
X			}
X		else goto beepout;
X		goto out;
X
X	/*  RED PIECES  */
X	case R_TYPE   : /*  */
X		if (IS_FREE(Column,Row+1) && IS_FREE(Column+2,Row)) {
X			PUTCH(Column-1,Row,NO_CHAR);
X			PUTCH(Column-1,Row+1,NO_CHAR);
X			PUTCH(Column+2,Row,R_CHAR);
X			PUTCH(Column,Row+1,R_CHAR);
X			Column +=1;
X			}
X		else goto beepout;
X		goto out;
X	case R_TYPE-1 : /*  */
X		if (IS_FREE(Column+1,Row-1) && IS_FREE(Column+1,Row) && 
X		    IS_FREE(Column+2,Row+1)) {
X			PUTCH(Column,Row-1,NO_CHAR);
X			PUTCH(Column,Row,NO_CHAR);
X			PUTCH(Column,Row+1,NO_CHAR);
X			PUTCH(Column+1,Row-1,R_CHAR);
X			PUTCH(Column+1,Row,R_CHAR);
X			PUTCH(Column+2,Row+1,R_CHAR);
X			Column +=1;
X			}
X		else goto beepout;
X		goto out;
X	case R_TYPE-2 : /*  */
X		if (IS_FREE(Column+2,Row-1) && IS_FREE(Column+2,Row)) {
X			PUTCH(Column-1,Row,NO_CHAR);
X			PUTCH(Column+1,Row-1,NO_CHAR);
X			PUTCH(Column+2,Row,R_CHAR);
X			PUTCH(Column+2,Row-1,R_CHAR);
X			Column +=1;
X			}
X		else goto beepout;
X		goto out;
X	case R_TYPE-3 : /*  */
X		if (IS_FREE(Column+1,Row-1) && IS_FREE(Column+1,Row) && 
X		    IS_FREE(Column+1,Row+1)) {
X			PUTCH(Column-1,Row-1,NO_CHAR);
X			PUTCH(Column,Row,NO_CHAR);
X			PUTCH(Column,Row+1,NO_CHAR);
X			PUTCH(Column+1,Row-1,R_CHAR);
X			PUTCH(Column+1,Row,R_CHAR);
X			PUTCH(Column+1,Row+1,R_CHAR);
X			Column +=1;
X			}
X		else goto beepout;
X		goto out;
X
X	/*  TAN PIECES  */
X	case T_TYPE   :
X	case T_TYPE-1 :
X	case T_TYPE-2 :
X	case T_TYPE-3 : /*  */
X		if (IS_FREE(Column+2,Row) && IS_FREE(Column+2,Row+1)) {
X			PUTCH(Column,Row,NO_CHAR);
X			PUTCH(Column,Row+1,NO_CHAR);
X			PUTCH(Column+2,Row,T_CHAR);
X			PUTCH(Column+2,Row+1,T_CHAR);
X			Column +=1;
X			}
X		else goto beepout;
X		goto out;
X
X	/*  YELLOW PIECES  */
X	case Y_TYPE   :
X	case Y_TYPE-2 : /* checked */
X		if (IS_FREE(Column+2,Row) && IS_FREE(Column+1,Row+1)) {
X			PUTCH(Column,Row,NO_CHAR);
X			PUTCH(Column-1,Row+1,NO_CHAR);
X			PUTCH(Column+2,Row,Y_CHAR);
X			PUTCH(Column+1,Row+1,Y_CHAR);
X			Column +=1;
X			}
X		else goto beepout;
X		goto out;
X	case Y_TYPE-1 :
X	case Y_TYPE-3 : /*  */
X		if (IS_FREE(Column+1,Row-1) && IS_FREE(Column+2,Row) && 
X		    IS_FREE(Column+2,Row+1)) {
X			PUTCH(Column,Row-1,NO_CHAR);
X			PUTCH(Column,Row,NO_CHAR);
X			PUTCH(Column+1,Row+1,NO_CHAR);
X			PUTCH(Column+1,Row-1,Y_CHAR);
X			PUTCH(Column+2,Row,Y_CHAR);
X			PUTCH(Column+2,Row+1,Y_CHAR);
X			Column +=1;
X			}
X		else goto beepout;
X		goto out;
X
X	/*  GREEN PIECES  */
X	case G_TYPE   :
X	case G_TYPE-2 : /* checked */
X		if (IS_FREE(Column+1,Row) && IS_FREE(Column+2,Row+1)) {
X			PUTCH(Column-1,Row,NO_CHAR);
X			PUTCH(Column,Row+1,NO_CHAR);
X			PUTCH(Column+1,Row,G_CHAR);
X			PUTCH(Column+2,Row+1,G_CHAR);
X			Column +=1;
X			}
X		else goto beepout;
X		goto out;
X	case G_TYPE-1 :
X	case G_TYPE-3 : /*  */
X		if (IS_FREE(Column+1,Row-1) && IS_FREE(Column+1,Row) && 
X		    IS_FREE(Column,Row+1)) {
X			PUTCH(Column,Row-1,NO_CHAR);
X			PUTCH(Column-1,Row,NO_CHAR);
X			PUTCH(Column-1,Row+1,NO_CHAR);
X			PUTCH(Column+1,Row-1,G_CHAR);
X			PUTCH(Column+1,Row,G_CHAR);
X			PUTCH(Column,Row+1,G_CHAR);
X			Column +=1;
X			}
X		else goto beepout;
X		goto out;
X
X	/*  BLUE PIECES  */
X	case B_TYPE   : /* checked */
X		if (IS_FREE(Column+2,Row) && IS_FREE(Column+2,Row+1)) {
X			PUTCH(Column-1,Row,NO_CHAR);
X			PUTCH(Column+1,Row+1,NO_CHAR);
X			PUTCH(Column+2,Row,B_CHAR);
X			PUTCH(Column+2,Row+1,B_CHAR);
X			Column +=1;
X			}
X		else goto beepout;
X		goto out;
X	case B_TYPE-1 : /* checked */
X		if (IS_FREE(Column+2,Row-1) && IS_FREE(Column+1,Row) && 
X		    IS_FREE(Column+1,Row+1)) {
X			PUTCH(Column,Row-1,NO_CHAR);
X			PUTCH(Column,Row,NO_CHAR);
X			PUTCH(Column,Row+1,NO_CHAR);
X			PUTCH(Column+2,Row-1,B_CHAR);
X			PUTCH(Column+1,Row,B_CHAR);
X			PUTCH(Column+1,Row+1,B_CHAR);
X			Column +=1;
X			}
X		else goto beepout;
X		goto out;
X	case B_TYPE-2 : /* checked */
X		if (IS_FREE(Column,Row-1) && IS_FREE(Column+2,Row)) {
X			PUTCH(Column-1,Row-1,NO_CHAR);
X			PUTCH(Column-1,Row,NO_CHAR);
X			PUTCH(Column,Row-1,B_CHAR);
X			PUTCH(Column+2,Row,B_CHAR);
X			Column +=1;
X			}
X		else goto beepout;
X		goto out;
X	case B_TYPE-3 : /* checked */
X		if (IS_FREE(Column+1,Row-1) && IS_FREE(Column+1,Row) && 
X		    IS_FREE(Column+1,Row+1)) {
X			PUTCH(Column,Row-1,NO_CHAR);
X			PUTCH(Column,Row,NO_CHAR);
X			PUTCH(Column-1,Row+1,NO_CHAR);
X			PUTCH(Column+1,Row-1,B_CHAR);
X			PUTCH(Column+1,Row,B_CHAR);
X			PUTCH(Column+1,Row+1,B_CHAR);
X			Column +=1;
X			}
X		else goto beepout;
X		goto out;
X
X	/*  VIOLET PIECES  */
X	case V_TYPE   :
X	case V_TYPE-2 : /* checked */
X		if (IS_FREE(Column+3,Row)) {
X			PUTCH(Column-1,Row,NO_CHAR);
X			PUTCH(Column+3,Row,V_CHAR);
X			Column +=1;
X			}
X		else goto beepout;
X		goto out;
X	case V_TYPE-1 :
X	case V_TYPE-3 : /* checked */
X		if (IS_FREE(Column+1,Row-1) && IS_FREE(Column+1,Row) && 
X		    IS_FREE(Column+1,Row+1) && IS_FREE(Column+1,Row+2)) {
X			PUTCH(Column,Row-1,NO_CHAR);
X			PUTCH(Column,Row,NO_CHAR);
X			PUTCH(Column,Row+1,NO_CHAR);
X			PUTCH(Column,Row+2,NO_CHAR);
X			PUTCH(Column+1,Row-1,V_CHAR);
X			PUTCH(Column+1,Row,V_CHAR);
X			PUTCH(Column+1,Row+1,V_CHAR);
X			PUTCH(Column+1,Row+2,V_CHAR);
X			Column +=1;
X			}
X		else goto beepout;
X		goto out;
X	default : 
X		printf("illegal piece Type=%d!!\n",Type);
X		exit();
X	}
Xbeepout:
X	if (Beep) beep();
Xout:
X	refresh();
X}
X
SHAR_EOF
chmod 0644 MoveR.c || echo "restore of MoveR.c fails"
sed 's/^X//' << 'SHAR_EOF' > NewP.c &&
X
X#include <tam.h>
X#include <termio.h>
X#include "tet.h"
X/*********************************************************************/
X/* A new piece is created on the game board if possible */
X/* returns 0 if unable to do it */
X/*********************************************************************/
XNewPiece()
X{	
XFallingDown = 0;			/* true when fall key is pressed */
XType = ((int)(mrand48() % 4) + 4) * 4;	/* random number 4 8 16 20 24 or 28 */
X/* printf("DEBUG:NewPiece Type = %d\n",Type); */
X
Xswitch (Type) {
X	case W_TYPE : /* checked  */
X	    if (IS_FREE(STARTCOL-1,STARTROW) && IS_FREE(STARTCOL,STARTROW) &&
X		IS_FREE(STARTCOL+1,STARTROW) && IS_FREE(STARTCOL,STARTROW+1)) {
X		PUTCH(STARTCOL-1,STARTROW,W_CHAR);
X		PUTCH(STARTCOL,STARTROW,W_CHAR);
X		PUTCH(STARTCOL+1,STARTROW,W_CHAR);
X		PUTCH(STARTCOL,STARTROW+1,W_CHAR);
X		}
X	    else {
X	return(0);
X	}
X	break;
X	case R_TYPE : /* checked */
X	    if (IS_FREE(STARTCOL-1,STARTROW) && IS_FREE(STARTCOL,STARTROW) &&
X	       IS_FREE(STARTCOL+1,STARTROW) && IS_FREE(STARTCOL-1,STARTROW+1)) {
X		PUTCH(STARTCOL-1,STARTROW,R_CHAR);
X		PUTCH(STARTCOL,STARTROW,R_CHAR);
X		PUTCH(STARTCOL+1,STARTROW,R_CHAR);
X		PUTCH(STARTCOL-1,STARTROW+1,R_CHAR);
X		}
X	    else return(0);
X	break;
X	case T_TYPE : /* checked */
X	    if (IS_FREE(STARTCOL,STARTROW) && IS_FREE(STARTCOL,STARTROW+1) &&
X	       IS_FREE(STARTCOL+1,STARTROW) && IS_FREE(STARTCOL+1,STARTROW+1)) {
X		PUTCH(STARTCOL,STARTROW,T_CHAR);
X		PUTCH(STARTCOL,STARTROW+1,T_CHAR);
X		PUTCH(STARTCOL+1,STARTROW,T_CHAR);
X		PUTCH(STARTCOL+1,STARTROW+1,T_CHAR);
X		}
X	    else return(0);
X	break;
X	case Y_TYPE : /* checked */
X	   if (IS_FREE(STARTCOL-1,STARTROW+1) && IS_FREE(STARTCOL,STARTROW+1) &&
X		IS_FREE(STARTCOL,STARTROW) && IS_FREE(STARTCOL+1,STARTROW)) {
X		PUTCH(STARTCOL-1,STARTROW+1,Y_CHAR);
X		PUTCH(STARTCOL,STARTROW+1,Y_CHAR);
X		PUTCH(STARTCOL,STARTROW,Y_CHAR);
X		PUTCH(STARTCOL+1,STARTROW,Y_CHAR);
X		}
X	    else return(0);
X	break;
X	case G_TYPE : { /* checked */
X	    if (IS_FREE(STARTCOL-1,STARTROW) && IS_FREE(STARTCOL,STARTROW) &&
X	       IS_FREE(STARTCOL,STARTROW+1) && IS_FREE(STARTCOL+1,STARTROW+1)) {
X		PUTCH(STARTCOL-1,STARTROW,G_CHAR);
X		PUTCH(STARTCOL,STARTROW,G_CHAR);
X		PUTCH(STARTCOL,STARTROW+1,G_CHAR);
X		PUTCH(STARTCOL+1,STARTROW+1,G_CHAR);
X		}
X	    else return(0);
X	break; }
X	case B_TYPE : /* checked */
X	    if (IS_FREE(STARTCOL-1,STARTROW) && IS_FREE(STARTCOL,STARTROW) &&
X	       IS_FREE(STARTCOL+1,STARTROW) && IS_FREE(STARTCOL+1,STARTROW+1)) {
X		PUTCH(STARTCOL-1,STARTROW,B_CHAR);
X		PUTCH(STARTCOL,STARTROW,B_CHAR);
X		PUTCH(STARTCOL+1,STARTROW,B_CHAR);
X		PUTCH(STARTCOL+1,STARTROW+1,B_CHAR);
X		}
X	    else return(0);
X	break;
X	case V_TYPE : /* checked */
X	    if (IS_FREE(STARTCOL-1,STARTROW) && IS_FREE(STARTCOL,STARTROW) &&
X		IS_FREE(STARTCOL+1,STARTROW) && IS_FREE(STARTCOL+2,STARTROW)) {
X		PUTCH(STARTCOL-1,STARTROW,V_CHAR);
X		PUTCH(STARTCOL,STARTROW,V_CHAR);
X		PUTCH(STARTCOL+1,STARTROW,V_CHAR);
X		PUTCH(STARTCOL+2,STARTROW,V_CHAR);
X		}
X	    else return(0);
X	break;
X	default : printf("illegal piece Type=%d!!\n",Type); exit();
X	}
Xrefresh();
XRow=STARTROW; Column=STARTCOL;	/* all pieces start at same point */
X}
SHAR_EOF
chmod 0644 NewP.c || echo "restore of NewP.c fails"
sed 's/^X//' << 'SHAR_EOF' > README &&
XThis program has been through so many ports and rewrites that the
Xlineage is completely lost. To my knowledge it does not contain
Xany copyrighted code. The last identifiable author is Quentin Neill
Xbut unfortunately he has not included his email address in any of
Xthe documentation. I have hacked in some UNIXpc specific stuff but
Xthe majority of the code is Quentin's. 
X
XHans Jespersen           ..!uunet!attcan!hjespers
X
X--------------------Original README-----------------------------------
X
X        This is a Unix SysV implementation of a game that appeared on
Xcomp.binaries.amiga a while ago. The author, Quentin Neill,
Xsaw it on an amiga here at work, and ported it to curses 
X(on his own time, of course ;-)  ).
X	I'm not too sure about the history of tetrix.  Someone 
Xsaid that the game originated in Russia, and that it is quite old.
XWe became enthralled with the game on an Amiga, almost to the point
Xof addiction.  That version had some documentation, but I never had
Xthe chance to read it - I only played.  I considered writing a version
Xin machine language for my Franklin junker at home, but settled on a
XC implementation for unix machines.
X	The object of the game is to keep the board clear for as long as
Xpossible.  Pieces consisting of four blocks (hence the name TETRix) in the
Xseven possible arrangements are sent down one at a time.  The player's
Xjob is to find the best fit for the piece in the pile of blocks that have
Xalready fallen.  He can rotate each piece and move it from side to side.  
XIf the piece just played causes a complete row of blocks, that row is 
Xerased and all blocks above it move down one row.  Points are awarded for
Xcompleted rows - more for rows higher up on the board.  A piece may
Xbe dropped from a height for additional points when the player feels it 
Xis oriented correctly.  The game is over when no more pieces can be formed
Xat the top of the board.
X	There is one variable INIT_PAUSE in tet.c that compensates for
Xdifferent machine speeds.  Set this higher if tetrix screams, and the 
Xtime between each piece's movement will lengthen.  Set it lower if
Xit crawls along too slowly.  On a Tower 32/800 with about 45 users on a
Xbusy day, we do well with the value set at about 300.  On a Tower 32/200
Xwith one user, the value was set at 1500.
X
X	Good luck!					Quentin Neill
X
SHAR_EOF
chmod 0644 README || echo "restore of README fails"
sed 's/^X//' << 'SHAR_EOF' > Rotate.c &&
X
X#include <tam.h>
X#include <termio.h>
X#include "tet.h"
X/*********************************************************************/
X/* Switch on type of piece, find out if I can rotate */
X/* If so, then do it */
X/*********************************************************************/
XRotate()
X{
Xswitch (Type) {
X	/*  WHITE PIECES  */
X	case W_TYPE   :  /* checked */
X		if (IS_FREE(Column,Row-1)) {
X			PUTCH(Column-1,Row,NO_CHAR);
X			PUTCH(Column,Row-1,W_CHAR);
X			Type--;
X			}
X		else goto beepout;
X		goto out;
X	case W_TYPE-1 :  /* checked */
X		if (IS_FREE(Column-1,Row)) {
X			PUTCH(Column,Row+1,NO_CHAR);
X			PUTCH(Column-1,Row,W_CHAR);
X			Type--;
X			}
X		else goto beepout;
X		goto out;
X	case W_TYPE-2 :  /* checked */
X		if (IS_FREE(Column,Row+1)) {
X			PUTCH(Column+1,Row,NO_CHAR);
X			PUTCH(Column,Row+1,W_CHAR);
X			Type--;
X			}
X		else goto beepout;
X		goto out;
X	case W_TYPE-3 :  /* checked */
X		if (IS_FREE(Column+1,Row)) {
X			PUTCH(Column,Row-1,NO_CHAR);
X			PUTCH(Column+1,Row,W_CHAR);
X			Type = W_TYPE;
X			}
X		else goto beepout;
X		goto out;
X
X	/*  RED PIECES  */
X	case R_TYPE   : /* checked */
X		if (IS_FREE(Column,Row-1) && IS_FREE(Column,Row+1) && 
X		    IS_FREE(Column+1,Row+1)) {
X			PUTCH(Column-1,Row,NO_CHAR);
X			PUTCH(Column-1,Row+1,NO_CHAR);
X			PUTCH(Column+1,Row,NO_CHAR);
X			PUTCH(Column,Row-1,R_CHAR);
X			PUTCH(Column,Row+1,R_CHAR);
X			PUTCH(Column+1,Row+1,R_CHAR);
X			Type--;
X			}
X		else goto beepout;
X		goto out;
X	case R_TYPE-1 : /* checked */
X		if (IS_FREE(Column-1,Row) && IS_FREE(Column+1,Row-1) && 
X		    IS_FREE(Column+1,Row)) {
X			PUTCH(Column,Row-1,NO_CHAR);
X			PUTCH(Column,Row+1,NO_CHAR);
X			PUTCH(Column+1,Row+1,NO_CHAR);
X			PUTCH(Column-1,Row,R_CHAR);
X			PUTCH(Column+1,Row-1,R_CHAR);
X			PUTCH(Column+1,Row,R_CHAR);
X			Type--;
X			}
X		else goto beepout;
X		goto out;
X	case R_TYPE-2 : /* checked  */
X		if (IS_FREE(Column-1,Row-1) && IS_FREE(Column,Row-1) && 
X		    IS_FREE(Column,Row+1)) {
X			PUTCH(Column-1,Row,NO_CHAR);
X			PUTCH(Column+1,Row-1,NO_CHAR);
X			PUTCH(Column+1,Row,NO_CHAR);
X			PUTCH(Column-1,Row-1,R_CHAR);
X			PUTCH(Column,Row-1,R_CHAR);
X			PUTCH(Column,Row+1,R_CHAR);
X			Type--;
X			}
X		else goto beepout;
X		goto out;
X	case R_TYPE-3 : /* checked */
X		if (IS_FREE(Column-1,Row) && IS_FREE(Column-1,Row+1) && 
X		    IS_FREE(Column+1,Row)) {
X			PUTCH(Column-1,Row-1,NO_CHAR);
X			PUTCH(Column,Row-1,NO_CHAR);
X			PUTCH(Column,Row+1,NO_CHAR);
X			PUTCH(Column-1,Row,R_CHAR);
X			PUTCH(Column-1,Row+1,R_CHAR);
X			PUTCH(Column+1,Row,R_CHAR);
X			Type = R_TYPE;
X			}
X		else goto beepout;
X		goto out;
X
X	/*  TAN PIECES  */
X	case T_TYPE   :
X	case T_TYPE-1 :
X	case T_TYPE-2 :
X	case T_TYPE-3 : goto out;
X
X	/*  YELLOW PIECES  */
X	case Y_TYPE   :
X	case Y_TYPE-2 :  /* checked */
X		if (IS_FREE(Column,Row-1) && IS_FREE(Column+1,Row+1)) {
X			PUTCH(Column-1,Row+1,NO_CHAR);
X			PUTCH(Column,Row+1,NO_CHAR);
X			PUTCH(Column,Row-1,Y_CHAR);
X			PUTCH(Column+1,Row+1,Y_CHAR);
X			Type--;
X			}
X		else goto beepout;
X		goto out;
X	case Y_TYPE-1 :
X	case Y_TYPE-3 : /* checked */
X		if (IS_FREE(Column-1,Row+1) && IS_FREE(Column,Row+1)) {
X			PUTCH(Column,Row-1,NO_CHAR);
X			PUTCH(Column+1,Row+1,NO_CHAR);
X			PUTCH(Column-1,Row+1,Y_CHAR);
X			PUTCH(Column,Row+1,Y_CHAR);
X			Type = Y_TYPE;
X			}
X		else goto beepout;
X		goto out;
X
X	/*  GREEN PIECES  */
X	case G_TYPE   :
X	case G_TYPE-2 : /* checked */
X		if (IS_FREE(Column-1,Row+1) && IS_FREE(Column,Row-1)) {
X			PUTCH(Column,Row+1,NO_CHAR);
X			PUTCH(Column+1,Row+1,NO_CHAR);
X			PUTCH(Column-1,Row+1,G_CHAR);
X			PUTCH(Column,Row-1,G_CHAR);
X			Type--;
X			}
X		else goto beepout;
X		goto out;
X	case G_TYPE-1 :
X	case G_TYPE-3 : /* checked */
X		if (IS_FREE(Column,Row+1) && IS_FREE(Column+1,Row+1)) {
X			PUTCH(Column-1,Row+1,NO_CHAR);
X			PUTCH(Column,Row-1,NO_CHAR);
X			PUTCH(Column,Row+1,G_CHAR);
X			PUTCH(Column+1,Row+1,G_CHAR);
X			Type = G_TYPE;
X			}
X		else goto beepout;
X		goto out;
X
X
X	/*  BLUE PIECES  */
X	case B_TYPE   : /* checked */
X		if (IS_FREE(Column,Row-1) && IS_FREE(Column,Row+1) && 
X		    IS_FREE(Column+1,Row-1)) {
X			PUTCH(Column-1,Row,NO_CHAR);
X			PUTCH(Column+1,Row,NO_CHAR);
X			PUTCH(Column+1,Row+1,NO_CHAR);
X			PUTCH(Column,Row-1,B_CHAR);
X			PUTCH(Column,Row+1,B_CHAR);
X			PUTCH(Column+1,Row-1,B_CHAR);
X			Type--;
X			}
X		else goto beepout;
X		goto out;
X	case B_TYPE-1 : /* checked */
X		if (IS_FREE(Column-1,Row-1) && IS_FREE(Column-1,Row) && 
X		    IS_FREE(Column+1,Row)) {
X			PUTCH(Column,Row-1,NO_CHAR);
X			PUTCH(Column,Row+1,NO_CHAR);
X			PUTCH(Column+1,Row-1,NO_CHAR);
X			PUTCH(Column-1,Row-1,B_CHAR);
X			PUTCH(Column-1,Row,B_CHAR);
X			PUTCH(Column+1,Row,B_CHAR);
X			Type--;
X			}
X		else goto beepout;
X		goto out;
X	case B_TYPE-2 : /* checked  */
X		if (IS_FREE(Column-1,Row+1) && IS_FREE(Column,Row-1) && 
X		    IS_FREE(Column,Row+1)) {
X			PUTCH(Column-1,Row-1,NO_CHAR);
X			PUTCH(Column-1,Row,NO_CHAR);
X			PUTCH(Column+1,Row,NO_CHAR);
X			PUTCH(Column-1,Row+1,B_CHAR);
X			PUTCH(Column,Row-1,B_CHAR);
X			PUTCH(Column,Row+1,B_CHAR);
X			Type--;
X			}
X		else goto beepout;
X		goto out;
X	case B_TYPE-3 : /* checked */
X		if (IS_FREE(Column-1,Row) && IS_FREE(Column+1,Row) && 
X		    IS_FREE(Column+1,Row+1)) {
X			PUTCH(Column-1,Row+1,NO_CHAR);
X			PUTCH(Column,Row-1,NO_CHAR);
X			PUTCH(Column,Row+1,NO_CHAR);
X			PUTCH(Column-1,Row,B_CHAR);
X			PUTCH(Column+1,Row,B_CHAR);
X			PUTCH(Column+1,Row+1,B_CHAR);
X			Type = B_TYPE;
X			}
X		else goto beepout;
X		goto out;
X
X	/*  VIOLET PIECES  */
X	case V_TYPE   :
X	case V_TYPE-2 : /* checked */
X		if (IS_FREE(Column,Row-1) && IS_FREE(Column,Row+1) && 
X		    IS_FREE(Column,Row+2)) {
X			PUTCH(Column-1,Row,NO_CHAR);
X			PUTCH(Column+1,Row,NO_CHAR);
X			PUTCH(Column+2,Row,NO_CHAR);
X			PUTCH(Column,Row-1,V_CHAR);
X			PUTCH(Column,Row+1,V_CHAR);
X			PUTCH(Column,Row+2,V_CHAR);
X			Type--;
X			}
X		else goto beepout;
X		goto out;
X	case V_TYPE-1 :
X	case V_TYPE-3 : /* checked */
X		if (IS_FREE(Column-1,Row) && IS_FREE(Column+1,Row) && 
X		    IS_FREE(Column+2,Row)) {
X			PUTCH(Column,Row-1,NO_CHAR);
X			PUTCH(Column,Row+1,NO_CHAR);
X			PUTCH(Column,Row+2,NO_CHAR);
X			PUTCH(Column-1,Row,V_CHAR);
X			PUTCH(Column,Row,V_CHAR);
X			PUTCH(Column+1,Row,V_CHAR);
X			PUTCH(Column+2,Row,V_CHAR);
X			Type = V_TYPE;
X			}
X		else goto beepout;
X		goto out;
X	default : 
X		printf("illegal piece Type=%d!!\n",Type); 
X		exit();
X	}
Xbeepout:
X	if (Beep) beep();
Xout:
X	refresh();
X}
X
SHAR_EOF
chmod 0644 Rotate.c || echo "restore of Rotate.c fails"
sed 's/^X//' << 'SHAR_EOF' > tet.c &&
X/* Tetrix by quentin */
X/* UNIXpc hacks by Hans Jespersen */
X
X#include <signal.h>
X#include <sys/ioctl.h>
X#include <fcntl.h>
X#include <stdio.h>
X#include <tam.h>
X#include <sys/termio.h>
X#include "tet.h"
X
X
X
X
X/* Definitions related to the operation of the program */
X
X#define	DFLT_PAUSE	200
X
X
X
X
X/********** Some global variable declarations ************/
Xint Type;		/* type specifies rotation, shape and color of blocks */
Xint Row;		/* Row of pivot point of block */
Xint Column;		/* Column of pivot point of block */
Xint Pause;		/* Time between movements this block */
Xint CurrentPause;	/* Time between movements per level */
Xint FallingDown;	/* True when space bar is pressed */
Xint Beep;
Xchar Key;		/* holds last key polled */
X
X#define SCORE_FILE	"/usr/tmp/.TetScores"
Xchar ScoreString[10];
Xstruct ScoreStruct {
X	char Name[10];
X	int Score;
X} High[10];
Xint ThisScore,HighsChanged;
X		
Xchar *ttyname();
Xchar combuf[2];
Xstruct termio origtty, tty;
Xchar Board[BOARD_WIDE][BOARD_HIGH];
Xchar Temp[BOARD_WIDE][BOARD_HIGH];	/* temp storage for TestRows */
X
X/* debug flash to screen */
X#define FLASHMSG(x)
X/*
X#define FLASHMSG(x)	      { mvaddstr(23,0,"                "); \
X				mvaddstr(23,0,x); \
X				refresh(); }
X*/
X#define UPSCORE(x)    { ThisScore += x; \
X			sprintf((char *)ScoreString,"%-d",ThisScore); \
X			mvaddstr(1,46,ScoreString); }
X
X#define NULL_KEY	'\0'
X#define FALL_KEY	' '
X#define RIGHT_KEY	'l'
X#define LEFT_KEY	'j'
X#define ROTATE_KEY	'k'
X#define L_RIGHT_KEY	'f'		/* for south paws */
X#define L_LEFT_KEY	's'
X#define L_ROTATE_KEY	'd'
X#define QUIT_KEY	'q'
X#define BEEP_KEY	'b'
X#define BOSS_KEY	'\033'
X#define PLAY_KEY	'p'
X#define SCORE_KEY	'h'
X#define MENU_KEY	'm'
X
X/**************************************************MAIN*****/
Xmain()
X{
X	Init();
X	for ( ; ; ) {
X		NewGame();
X		Play();
X		ScoreIt();
X		DrawScore();
X		}
X}
X
X/*************************************************************/
X
XInit()
X{
X	register char *ttnam, *p;
X	register int x,y,i,fd;
X	int timein;
X
X	time(&timein);		/* get start time */
X	srand48(timein);	/* start rand randomly */
X
X	ttnam = ttyname (0); 
X	close (0); 
X	open (ttnam, O_NDELAY);
X	/*
X	 * setup raw mode, no echo
X	 */
X	ioctl (0, TCGETA, &origtty);
X	ioctl (0, TCGETA, &tty);
X	tty.c_iflag &= 077;
X	tty.c_oflag &= 077700;
X	tty.c_lflag = 0201;
X	tty.c_cc[4] =  1;
X	ioctl (1, TCSETAW, &tty);
X	signal(SIGINT, SIG_IGN);
X	
X	Beep=0;
X	HighsChanged = 0;
X	ScoreIt();
X	initscr();
X	clear();
X	refresh();
X	/* initilialize board to spaces */
X	for (x=0; x<BOARD_WIDE; x++) 
X		for (y=0; y<BOARD_HIGH; y++) 
X			PUTCH(x,y,NO_CHAR);
X	erase();
X	DrawMenu();
X	refresh();
X}
X
X/**************************************************************/
XNewGame()
X{
X	register int x,y;
X
X	CurrentPause=0;
X
X	while (!CurrentPause) {
X		GetKey();
X		switch (Key) {
X			case BEEP_KEY   : Beep = !Beep ;
X					  if (Beep) beep(); 
X					  break;
X			case SCORE_KEY  : DrawScore(); break;
X			case MENU_KEY	: DrawMenu(); break;
X			case BOSS_KEY	: Boss(); break;
X			case PLAY_KEY	: CurrentPause=DFLT_PAUSE; break;
X			case QUIT_KEY   : Leave();
X			}
X	}
X	/* initilialize board to spaces */
X	for (x=0; x<BOARD_WIDE; x++) 
X		for (y=0; y<BOARD_HIGH; y++) 
X			PUTCH(x,y,NO_CHAR);
X	ThisScore=0;
X	mvaddstr(1,42,"|  ......  |");
X	UPSCORE(0);
X
X}
X
X/******************************************************************/
XDrawMenu()
X{
X	register int y;
X	erase(); 
X
X	/* draw score border */
X	mvaddstr(0,42,".----------.");
X	mvaddstr(1,42,"|  ......  |");
X	mvaddstr(2,42,"`----------'");
X	UPSCORE(0);
X
X	/* draw menu */
X	mvaddstr( 4,35,".---------------------------.");
X	mvaddstr( 5,35,"|                           |");
X	mvaddstr( 6,35,"|      ..   Menu   ..       |");
X	mvaddstr( 7,35,"|                           |");
X	mvaddstr( 8,35,"|   h     .... high scores  |");
X	mvaddstr( 9,35,"|   b     .... toggle beep  |");
X	mvaddstr(10,35,"|   p     .... play         |");
X	mvaddstr(11,35,"|   q     .... quit         |");
X	mvaddstr(12,35,"|                           |");
X	mvaddstr(13,35,"| s or j  .... move left    |");
X	mvaddstr(14,35,"| d or k  .... rotate piece |");
X	mvaddstr(15,35,"| f or l  .... move right   |");
X	mvaddstr(16,35,"|  spc    .... fall piece   |");
X	mvaddstr(17,35,"|  esc    .... pause        |");
X	mvaddstr(18,35,"|                           |");
X	mvaddstr(19,35,"| LATEST: allow concurrent  |");
X	mvaddstr(20,35,"|    high score setting     |");
X	mvaddstr(21,35,"`---------------------------'");
X
X	/* draw game border */
X	mvaddstr(4,10, ".----------------------.");
X	mvaddstr(21,10,"`----------------------'");
X	for (y=5; y<21; y++)
X		mvaddstr(y,10,"|                      |");
X
X	/* display the title */
X	mvaddstr(3,20,"TETRIX");
X	refresh();
X}
X
X/**************************************************************/
XPlay()
X{
Xwhile ((Key != QUIT_KEY) && NewPiece()) {
X	FallingDown = 0;
X	do {	/* do until we can't Advance the piece */
X		if (FallingDown) 
X			Pause = 0;
X		else 
X			Pause = CurrentPause;
X		while (Pause) {		/* do this until pause runs out */
X			Pause--;
X			switch (Key) {
X				case BOSS_KEY     : Boss(); break;
X				case QUIT_KEY     : CurrentPause = 0;
X				case FALL_KEY     : FallingDown = 1;
X						    UPSCORE(20-Row);
X						    Pause = 0; break;
X				case RIGHT_KEY    :
X				case L_RIGHT_KEY  : MoveRight(); break;
X				case LEFT_KEY     :
X				case L_LEFT_KEY   : MoveLeft(); break;
X				case ROTATE_KEY   :
X				case L_ROTATE_KEY : Rotate(); break;
X				case NULL_KEY     : break;
X				default           : if (Beep) beep();
X				}
X			GetKey();
X			}
X		} while (AdvancePiece());
X	UPSCORE(5);
X	TestRows();
X	}
X}
X
X/*********************************************************************/
XScoreIt()
X{
X	register int  oldmask,fd,i,j;
X
X	oldmask = umask(0);
X	if ((fd=open(SCORE_FILE,O_CREAT|O_RDONLY,0666)) != -1) {
X		read(fd,High,sizeof(High));
X		close(fd);
X	}
X	else {
X	for(i=0; i<10; i++)
X		High[i].Score = 0;
X	for(i=0; i<10; i++)
X		strncpy("         ",High[i].Name,10);
X	}
X	umask(oldmask);
X
X	for (i=0; i<10; i++)		/* place this guy */
X		if (High[i].Score <= ThisScore) break;
X
X	if (i < 10 )			/* insert this score */
X	{
X		HighsChanged = 1;
X		for (j=9; j>i; j--)		/* move down others */
X			if (High[j-1].Score)
X			{
X				High[j].Score = High[j-1].Score;
X				strncpy(High[j].Name,High[j-1].Name,10);
X			}
X		cuserid((char *) High[i].Name);
X		High[i].Score = ThisScore;
X	}
X
X	if (HighsChanged)
X	{
X		if ((fd=open(SCORE_FILE,O_RDWR)) != -1) {
X			write(fd,High,sizeof(High));
X			close(fd);
X		}
X		else mvaddstr(22,0,"Couldn't open high score file.");
X	}
X	
X}
X
X/***********************************************************************/
XDrawScore()
X{
X	register int j;
X
X	mvaddstr( 5,35,"|     Hit 'm' for menu      |");
X	mvaddstr( 6,35,"|                           |");
X	mvaddstr( 7,35,"|        HIGH SCORES        |");
X	mvaddstr( 8,35,"| 1.                        |");
X	mvaddstr( 9,35,"| 2.                        |");
X	mvaddstr(10,35,"| 3.                        |");
X	mvaddstr(11,35,"| 4.                        |");
X	mvaddstr(12,35,"| 5.                        |");
X	mvaddstr(13,35,"| 6.                        |");
X	mvaddstr(14,35,"| 7.                        |");
X	mvaddstr(15,35,"| 8.                        |");
X	mvaddstr(16,35,"| 9.                        |");
X	mvaddstr(17,35,"|10.                        |");
X	mvaddstr(18,35,"|                           |");
X	mvaddstr(19,35,"|                           |");
X	mvaddstr(20,35,"|                           |");
X	
X	for (j=0; j<10; j++)
X	   if (High[j].Score)
X	   {
X	      move(j+8,41);
X	      printw("%-s",(char *)High[j].Name);
X	      move(j+8,54);
X	      printw("%d",High[j].Score);
X	   }
X	refresh();
X
X}
X
X/*********************************************************************/
XBoss()
X{	register int x,y;
X
X	clear();
X	refresh();
X	ioctl (0, TCSETA, &origtty);
X	system("sh </dev/tty >/dev/tty");
X	ioctl (1, TCSETAW, &tty);
X	clear();
X	DrawMenu();
X	/* restore board */
X	for (x=0; x<BOARD_WIDE; x++) 
X		for (y=0; y<BOARD_HIGH; y++) 
X			PUTCH(x,y,Board[x][y]);
X	refresh();
X
X}
X
X/*********************************************************************/
XGetKey()
X{
X/*	fflush(stdout); */
X	Key = NULL_KEY;
X	top:
X	if (read (0, combuf, 1) == 0) 
X		return;
X	else Key = (*combuf&0177); 
X	goto top;
X}
X
X/************************************************************************/
X/* Could be a macro for speed but cpp runs out of tree space in CanMove */
XIS_FREE(x,y)
Xint x,y;
X{
X	if ((y < 0) || (y >= BOARD_HIGH) || (x < 0) || (x >= BOARD_WIDE))
X		return(0);
X	if (Board[x][y] != NO_CHAR)
X		return(0);
X	else return(1);
X}
X
X/*********************************************************************/
XTestRows()
X{	register int x,y,tempy,fullrow;
X	int marked[BOARD_HIGH];
X
Xfor (y=0; y<BOARD_HIGH; y++) {
X	marked[y] = 0;
X	for (x=0; x<BOARD_WIDE; x++)
X		Temp[x][y] = NO_CHAR;
X	}
X
X/* main loop to traverse Board, looking for fullrows */
X/* as it looks, it copies non full ones over to Temp */
Xtempy=BOARD_HIGH-1;
Xfor (y=BOARD_HIGH-1; y>=0; y--) {
X	fullrow = 1;
X	for (x=0; x<BOARD_WIDE; x++)		/* check for any holes at all */
X		if (IS_FREE(x,y)) { fullrow = 0; break; }
X	if (fullrow) {
X		marked[y]++;
X		CurrentPause--;			/* speed up the game */
X	}
X	else    {
X		for (x=0; x<BOARD_WIDE; x++)
X			Temp[x][tempy] = Board[x][y];
X		tempy--;
X		}
X	}
X
X/* flash the rows that will die */
Xfor (tempy=1; tempy<5; tempy++)
X	for (y=BOARD_HIGH-1; y>=0; y--) 
X		if (marked[y]) {	
X			UPSCORE(30-y);
X			for (x=0; x<BOARD_WIDE; x++)	
X				PUTCH(x,y,BRITE_CHAR);
X			refresh();
X			for (x=0; x<BOARD_WIDE; x++)	
X				PUTCH(x,y,NO_CHAR);
X			refresh();
X			}
X
X/* Move temp back to Board */
Xfor (y=BOARD_HIGH-1; y>=0; y--) {
X	for (x=0; x<BOARD_WIDE; x++)
X		PUTCH(x,y,Temp[x][y]);
X	refresh();
X	}
X}
X
X/***********************************************************/
XLeave()
X{
X	erase();
X	mvaddstr(22,48,"Tetrix says Bye\n");
X	mvaddstr(23,0,"");
X	refresh();
X	endwin();
X	sleep(1);
X	ioctl (0, TCSETA, &origtty);
X	exit(0);
X}
SHAR_EOF
chmod 0644 tet.c || echo "restore of tet.c fails"
sed 's/^X//' << 'SHAR_EOF' > tet.h &&
X#define NO_TYPE	0
X#define NO_CHAR	' '
X#define BRITE_CHAR '$'
X
X/* type numbers 1-3, 4-7, 9-11 etc represent the white, red, blue etc */
X/* pieces at different rotations */
X#define G_TYPE	4		/* Green pieces */
X#define G_CHAR	'G'
X#define R_TYPE	8		/* Red pieces */
X#define R_CHAR	'R'
X#define T_TYPE  12		/* Tan pieces */
X#define T_CHAR	'O'
X#define W_TYPE	16		/* White pieces */
X#define W_CHAR	'W'
X#define V_TYPE	20		/* Violet pieces */
X#define V_CHAR	'V'
X#define B_TYPE	24		/* Blue pieces */
X#define B_CHAR	'B'
X#define Y_TYPE	28		/* Yellow pieces */
X#define Y_CHAR	'Y'
X
X#define MINX 15		/* defines corner screen position */
X#define MINY 1
X
X#define BOARD_WIDE 10
X#define BOARD_HIGH 20
X
X#define MAXX BOARD_WIDE+MINX
X#define MAXY BOARD_HIGH+MINY
X
X#define STARTROW 1		/* defines starting position of pieces */
X#define STARTCOL 5
X
Xextern int Type, Row, Column, Pause, CurrentSpeed, FallingDown, Beep;
Xextern char Board[BOARD_WIDE][BOARD_HIGH];
X
Xextern void PUTCH();
X
X/* Macros */
X/* test whether a square is empty and legal */
X/*
X#define IS_FREE(x,y)  (((y >= 0) && (y < BOARD_HIGH) && \
X			(x >= 0) && (x < BOARD_WIDE)) && \
X			(Board[x][y] == NO_CHAR))
X*/
XIS_FREE();
SHAR_EOF
chmod 0644 tet.h || echo "restore of tet.h fails"
sed 's/^X//' << 'SHAR_EOF' > window.c &&
X/**********************************************************\
X* Bugs : a bit-mapped arcade game for the AT&T UNIX PC.    *
X*                                                          *
X* By : Hans Jespersen                                      *
X*                                                          *
X* Copyright 1989, Hans Jespersen                           *
X*                                                          *
X\**********************************************************/
X
X#include <sys/window.h>
X#include <stdio.h>
X#include <termio.h>
X#include <tam.h>
X#include <fcntl.h>
X#include "tet.h"
X
Xextern unsigned short patwhite[];
Xextern unsigned short patblack[];
Xextern unsigned short patgray[];
Xunsigned short pathex[16] = {
X	0x8888, 0x5555, 0x2222, 0x5555,
X	0x8888, 0x5555, 0x2222, 0x5555,
X	0x8888, 0x5555, 0x2222, 0x5555,
X	0x8888, 0x5555, 0x2222, 0x5555,
X};
Xint wn;
X
Xvoid PUTCH( x, y, z)
Xint x, y, z;
X{
X	Board[x][y] = z;
X	if( z == NO_CHAR )
X	   wrastop(0,0,0,0,0,0,0,100+x*20,56+y*10,19,9,SRCPAT,DSTSRC,patblack);
X	else if( z == G_CHAR || z == R_CHAR || z == T_CHAR )
X	   wrastop(0,0,0,0,0,0,0,100+x*20,56+y*10,19,9,SRCPAT,DSTSRC,patwhite);
X	else if( z == W_CHAR || z == V_CHAR )
X	   wrastop(0,0,0,0,0,0,0,100+x*20,56+y*10,19,9,SRCPAT,DSTSRC,patgray);
X	else
X	   wrastop(0,0,0,0,0,0,0,100+x*20,56+y*10,19,9,SRCPAT,DSTSRC,pathex);
X}
SHAR_EOF
chmod 0644 window.c || echo "restore of window.c fails"
exit 0



More information about the Unix-pc.sources mailing list