1 #ifndef tetris_h
2 #define tetris_h
3 
4 #include "int32t.h"
5 
6 #define TETR_I  0xF00	/* |    | #  | */
7 #define TETR_I2 0x2222	/* |    | #  | */
8 			/* |####| #  |
9 			   |    | #  | */
10 
11 #define TETR_J  0x470	/* |    | #  |#   | ## | */
12 #define TETR_J2 0x322	/* |#x# | x  |#x# | x  | */
13 #define TETR_J3 0x71	/* |  # |##  |    | #  | */
14 #define TETR_J4 0x226
15 
16 #define TETR_L  0x170	/* |    |##  |  # | #  | */
17 #define TETR_L2 0x223	/* |#x# | x  |#x# | x  | */
18 #define TETR_L3 0x74	/* |#   | #  |    | ## | */
19 #define TETR_L4 0x622
20 
21 #define TETR_O  0x66	/* | ## | */
22 			/* | ## | */
23 
24 #define TETR_S  0x360	/* |    |#   | */
25 #define TETR_S2 0x231	/* | x# |#x  | */
26 			/* |##  | #  | */
27 
28 #define TETR_T  0x270	/* |    | #  | #  | #  | */
29 #define TETR_T2 0x232	/* |#x# |#x  |#x# | x# | */
30 #define TETR_T3 0x72	/* | #  | #  |    | #  | */
31 #define TETR_T4 0x262
32 
33 #define TETR_Z  0x630	/* |    | #  | */
34 #define TETR_Z2 0x132	/* |#x  |#x  | */
35 			/* | ## |#   | */
36 
37 #define SPAWN_DELAY 166
38 #define LOCK_DELAY 166
39 #define CLEAR_DELAY 332
40 
41 struct tetr {
42 	short blocks;
43 	signed char x, y;
44 	char color;
45 };
46 
47 /* rotation sys flags */
48 #define ROT_CLOCKWISE 1
49 #define ROT_LEFTHAND 2
50 
51 struct player {
52 	char startlevel;
53 	char height;
54 	char lineslimit;
55 	char rotationsys;
56 	struct tetr piece;
57 	uint_least32_t board[20];
58 	int_least32_t score;
59 	signed char level;
60 	short falltime;
61 	short lines;
62 	short mvleft_tm;
63 	short mvright_tm;
64 };
65 
66 /* game modes */
67 #define MODE_1PLAYER 1
68 #define MODE_2PLAYER 2
69 #define MODE_BTYPE 4
70 #define MODE_NETWORK 8
71 
72 /* game states */
73 #define GAME_RUNNING 1
74 #define GAME_PAUSED 2
75 #define GAME_OVER 4
76 
77 #define GAME_members(n) 	\
78 	char mode;		\
79 	char state;		\
80 	struct tetr *next;	\
81 	struct player player[n]	\
82 
83 extern struct game {
84 	GAME_members(1);
85 } *game;
86 
87 struct game_1p {
88 	GAME_members(1);
89 	unsigned char data[8];
90 };
91 
92 struct game_2p {
93 	GAME_members(2);
94 };
95 
96 #define game_running  (game->state & GAME_RUNNING)
97 #define game_paused   (game->state & GAME_PAUSED)
98 #define game_over     (game->state & GAME_OVER)
99 
100 #define player1  game->player[0]
101 #define player2  game->player[1]
102 
103 #define tetr_stats	((struct game_1p *) game)->data
104 #define softdrop_speed	((struct game_1p *) game)->data[7]
105 
106 extern char clearedlines[4];
107 
108 int randnum(int n);
109 void gettetrom(struct tetr *t, int i);
110 
111 int hitbtm(struct tetr *piece, struct player *p);
112 void lockpiece(struct player *p);
113 void moveright(struct player *p);
114 void moveleft(struct player *p);
115 int movedown(struct player *p, int drop);
116 void rotate(struct player *p, int clockwise);
117 int harddrop(struct player *p, int safe);
118 int softdrop(int n, int safe);
119 
120 void setupplayer(struct player *p);
121 int startgame_1p();
122 int startgame_wait(int flags);
123 int pausegame();
124 
125 #ifdef TWOPLAYER
126 #define TWOPLAYER_MODE (game->mode & MODE_2PLAYER)
127 #define isplayer2(p) ((p) > game->player)
128 #else
129 #define TWOPLAYER_MODE 0
130 #define isplayer2(p) 0
131 #endif
132 
133 #endif /* !tetris_h */
134