8 #include <sys/select.h>
16 static const char *termfile = "/dev/tty";
17 static struct termios saved_term;
18 static struct timeval tv0;
20 int main(int argc, char **argv)
34 gettimeofday(&tv0, 0);
36 tv.tv_sec = tick_interval / 1000;
37 tv.tv_usec = (tick_interval % 1000) * 1000;
44 while((res = select(1, &rdset, 0, 0, &tv)) == -1 && errno == EINTR);
46 if(res > 0 && FD_ISSET(0, &rdset)) {
47 while((c = fgetc(stdin)) >= 0) {
56 tv.tv_sec = next / 1000;
57 tv.tv_usec = (next % 1000) * 1000;
70 if((fd = open(termfile, O_RDWR | O_NONBLOCK)) == -1) {
71 fprintf(stderr, "failed to open terminal device: %s: %s\n", termfile, strerror(errno));
75 if(tcgetattr(fd, &term) == -1) {
76 fprintf(stderr, "failed to get terminal attributes: %s\n", strerror(errno));
80 term.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON);
81 term.c_oflag &= ~OPOST;
82 term.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
83 term.c_cflag = (term.c_cflag & ~(CSIZE | PARENB)) | CS8;
85 if(tcsetattr(fd, TCSAFLUSH, &term) == -1) {
86 fprintf(stderr, "failed to change terminal attributes: %s\n", strerror(errno));
97 open("ansitris.log", O_WRONLY | O_CREAT, 0664);
100 if(init_game() == -1) {
110 tcsetattr(0, TCSAFLUSH, &saved_term);
117 gettimeofday(&tv, 0);
119 return (tv.tv_sec - tv0.tv_sec) * 1000 + (tv.tv_usec - tv0.tv_usec) / 1000;