-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathqio.c
executable file
·185 lines (151 loc) · 2.56 KB
/
qio.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
qio.c
880924 ACH conversion to Atari ST & Acylon C
880925 ACH + add bonus for captured Quixes
891216 ACH Tidied up code for Sozobon C and general release of source
*/
#include "defs.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#ifdef __WIN32__
# include <conio.h>
static int wait_key;
#else
# include <sys/types.h>
# include <termios.h>
static struct termios otios;
#endif
void
set_io(int wait)
{
#ifdef __WIN32__
wait_key = wait;
#else
struct termios ntios;
ntios = otios;
ntios.c_cc[VMIN] = wait;
ntios.c_cc[VTIME] = 0;
/* ntios.c_lflag |= ISIG; */
ntios.c_lflag &= ~(ICANON|ECHO|ECHONL|ECHOCTL);
/* ntios.c_oflag &= ~(OPOST); */
if (tcsetattr(0, TCSANOW, &ntios)) {
printf("Oops\n");
exit(2);
}
#endif
}
void
init_io(void)
{
setvbuf(stdin, NULL, _IONBF, 0);
setvbuf(stdout, NULL, _IONBF, 0);
#ifdef TERMIOS
if (tcgetattr(0, &otios)) {
printf("Oops\n");
exit(2);
}
set_io(0);
#endif
}
void
fini_io(void)
{
#ifdef TERMIOS
(void) tcsetattr(0, TCSANOW, &otios);
#endif
}
#ifdef __WIN32__
int
getkey(void)
{
if (wait_key || kbhit())
return getch();
return EOF;
}
#else
int
getkey(void)
{
unsigned char ch;
if (read(STDIN_FILENO, &ch, 1) == 1)
return ch;
return EOF;
}
#endif
void
quit(void)
{
#ifdef CURSORON
puts (CURSORON);
#endif
clearscreen();
fini_io();
}
void
init(void)
{
int i;
init_io();
/* Initialise ALL variables */
sparxnum=quixnum=menleft=area_left=last_killed=0;
percent=fildes=startdir=siz=maxarea=xmax=ymax=fuse=0;
bord_min=bord_max=line_min=line_max=lastx=lasty=0;
bonus_men=fuse_lit=nohighscore=0;
for( i=0; i<MAXQUIX; i++ ){
quix[i].x=quix[i].y=quix[i].direction=quix[i].d_time=quix[i].start=0;
quix[i].cought = FALSE;
} /* for */
for(i=0; i<BOUNDARY_LEN; i++) {
boundary[i].x=boundary[i].y=0;
temp[i].x=temp[i].y=0;
} /* for */
inchar = EOF;
C_UP = INT_UP;
C_DOWN = INT_DOWN;
C_LEFT = INT_LEFT;
C_RIGHT = INT_RIGHT;
bonus_men = 1;
bord_min = 2;
line_max = BOUNDARY_LEN - 2;
xmax = MAX_X - 3;
ymax = MAX_Y - 3;
maxarea = (xmax - 2) * (ymax - 2);
clearscreen();
}
void
nap(unsigned int x)
{
#ifdef HAVE_USLEEP
(void) usleep(x * NAP_FACTOR);
#else
for (x *= NAP_FACTOR; x; x--)
;
#endif
} /* nap */
void
move(int x, int y)
{
#ifdef ATARI_ST
Cconws( "\033Y" );
Cconout( y +32 );
Cconout( x +32 );
#endif
#ifdef VT52
(void) printf("\033Y%c%c", y+32, x+32);
#endif
#ifdef ANSI
(void) printf("\033[%d;%dH", y+1, x+1);
#endif
}
void
clearscreen(void)
{
print(HOME);
print(CLEARS);
} /* clearscreen */
int
ISBORDER(int X)
{
return ((X) <= bord_max);
} /* ISBORDER */