
  **  Here's an annotated copy of the source for Tetrx 1K (TETRX.83P).
  **  Feel free to modify this code, but do not put your name (or anyone
  **  else's) on it.  Read TETRX.TXT for more information.
  **  My comments are set off by **s.
  **
  **  Arthur O'Dwyer

\start83\
\comment=Program file dated 11/14/00, 19:39
\name=TETRX
\file=C:\TI\ARCHIVE\MINE\GAMES\TETRX\ANNOTATE.TXT

  ** We start off with the sprite-display subroutines.
  ** They are activated by setting Ans to a multiple of pi (for
  ** draw) or e (for erase).
  ** Label E is the erase-sprite routine.
  ** Label A is the beginning of the main program.

If not(fPart(Ans/\e\:Goto E
Ans/\pi\\->\L
If fPart(Ans:Goto A

  ** Draw the sprite encoded for by LTETRX(P).
  ** These are binary, 3x3 grid sprites, listed in prgmZTETRX.
  ** Here, L holds the type of pixel to plot (dot, box, or cross).

\L\TETRX(P\->\J
For(I,0,8
3int(I/3
If .5\<=\fPart(J/2^(I+1
Pt-On(A+Ans-3,3I-B-3Ans-3,L
End
Return
End

Lbl E
Ans/\e\\->\L
\L\TETRX(P\->\J
For(I,0,8
3int(I/3
If .5\<=\fPart(J/2^(I+1
Pt-Off(A+Ans-3,3I-B-3Ans-3,L
End
Return
End

  ** Here's the main part of the program.  We end up here
  ** if Ans doesn't contain a multiple of e or pi - i.e.,
  ** most of the time it's run from the PRGM menu.
  ** Here, we set up a convenient window and read in the
  ** piece bitmap-sprites from prgmZTETRX.

Lbl A
0\->\Xmin
\(-)\62\->\Ymin
94\->\Xmax
0\->\Ymax
prgmZTETRX
Ans\->\\L\TETRX
AxesOff:ClrDraw

  ** Display a nice playfield and score counter.

Text(5,70,"TETRX
Line(69,\(-)\12,89,\(-)\12
Line(69,\(-)\20,89,\(-)\20
Line(69,\(-)\20,69,\(-)\12
Line(89,\(-)\20,89,\(-)\12
Text(13,71,0
Line(19,0,19,\(-)\57
Line(67,0,67,\(-)\57
Line(19,\(-)\57,67,\(-)\57

  ** A holds the x-coord of the piece, B holds the
  ** y-coord (from top to bottom).
  ** P holds the current piece.  Get a random piece to begin.

43\->\A:6\->\B
randInt(1,dim(\L\TETRX\->\P
DelVar SDelVar TDelVar \theta\

  ** Done initializing; here's the main loop.  Repeat until
  ** the user hits <Clear>.

Repeat K=45
getKey\->\K
T+1\->\T
If K=34:5

  ** T holds a timer-counter.  It counts to 5, then moves
  ** the piece down.  If you press <down>, the piece moves
  ** down anyway, and T is reset (at the end of this block).

If Ans=5:Then

  ** Move the piece down.

0
For(I,B-2,B+4,3
For(J,A-3,A+3,3
If pxl-Test(I,J+1)pxl-Test(I+2,J:1
End:End

  ** If a piece-bit (a single square of the current piece)
  ** exists with a dead piece-bit (a square of a solid
  ** piece) right under it, then stop the piece and kill it.
  ** If B<=9 (y-coord near top of screen), make player lose.

If Ans:Then
If B\<=\9:Goto L

  ** Kill the piece: change its bits to dead piece-bits.

\pi\:prgmTETRX
A+1\->\A:B+1\->\B
\e\:prgmTETRX

  ** Do we have a completed row?  Check around the dead piece.

For(I,B-4,min(54,B+2),3
1\->\L
For(J,22,64,3
If not(pxl-Test(I,J:DelVar L
End
If L:Then

  ** Yes, we do.  Move all rows down one, until there's no
  ** more to shift (a completely blank row).

\(-)\I\->\T
Repeat T>\(-)\9 or not(A
DelVar A
For(J,\(-)\1,1
Line(21,T+J,65,T+J,0
End
For(J,22,64,3
If pxl-Test(\(-)\T-3,J:Then
Pt-On(J,T,2
Pt-On(J,T
Pt-Off(J+1,T+1
1\->\A:End
End

** Move up to the next row, check it... and so on.

3+T\->\T
End

  ** Here's the end of the "yes, row completed" block.

S+10\->\S
End
End

  ** Here's the end of the "yes, piece killed" block.
  ** Get a new piece; reset A and B; display new score.

S+1\->\S
randInt(1,dim(\L\TETRX\->\P
43\->\A:6\->\B
Text(13,71,S
End

  ** T is back to representing the timer-counter.
  ** Clear it (wait another 5 ticks).

DelVar T
End

  ** If T=0 or K has a keystroke, then:
  ** Erase the old piece-bits.

If not(Tnot(K:Then
2\e\:prgmTETRX
B+3not(T\->\B

  ** If T is 0 (i.e., we've just done the big routine
  ** right above us), increment the y-coord.
  ** Increment or decrement the x-coord according to K.
  ** If K is 25 (<up>), flip the piece to its next
  ** configuration (mod 4).

A+3(K=26)-3(K=24\->\A
If K=25:P+1-4not(fPart(P/4\->\P

  ** Move the x-coord back inside the bounds of the box,
  ** being careful to allow, e.g., the 3x1 rectangle to
  ** fit flush against either side (the extra tests there).

If K:Then
A+3(A<25-3(not(fPart(8\^-1\\L\TETRX(P\->\A
A-3(A>61+3(64>\L\TETRX(P\->\A
End

  ** And draw the new bitmap.

2\pi\:prgmTETRX
End

  ** And go back and do it all over again.

End

  ** When the user hits <Clear>, come here.
  ** Go to credits.
  ** If the user loses, display the message,
  ** pause, and then go to credits.

Goto Q
Lbl L
Text(20,29,"YOU LOSE!
Text(26,28,"TRY AGAIN
Pause
Lbl Q
ClrDraw:ClrHome:Disp "   TETRX v1.2","  Cln(up) crew

 ** Clear the screen and exit the program.

Output(1,1,"

\stop83\

