1 /***************************************************************************
2 platform.cpp - Platoform dependent utilities, implementation
4 begin : Sun Nov 28 2007
5 copyright : (C) 2007 by Maurizio Monge
6 email : monge@linuz.sns.it
7 ***************************************************************************/
9 /***************************************************************************
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
16 ***************************************************************************/
18 #if defined(_WIN32) || defined(_WIN64)
31 handle
= GetStdHandle(STD_INPUT_HANDLE
);
32 pipe
= !GetConsoleMode(handle
,&val
);
36 SetConsoleMode(handle
, val
& ~(ENABLE_MOUSE_INPUT
|ENABLE_WINDOW_INPUT
));
37 FlushConsoleInputBuffer(handle
);
41 bool input_available() {
49 if(!PeekNamedPipe(handle
, NULL
, 0, NULL
, &val
, NULL
) )
55 GetNumberOfConsoleInputEvents(handle
, &val
);
64 return GetTickCount() / 10;
67 bool start_engine(const char *prog
, FILE **in
, FILE **out
)
69 printf("Error, start_engine unimplemented on windows!\n");
73 #else //defined(_WIN32) || defined(_WIN64)
78 #include <sys/types.h>
91 bool input_available()
93 int n
= fileno(stdin
);
96 struct timeval tv
= { 0, 0 };
103 while(select(n
+1, &ifds
, NULL
, &efds
, &tv
)==-1)
105 printf("select: %s\n", strerror(errno
));
107 return FD_ISSET(0, &ifds
) || FD_ISSET(0, &efds
);
113 gettimeofday(&tv
,NULL
);
114 return tv
.tv_sec
*100 + tv
.tv_usec
/10000;
117 // void *map_file(const char *file_name, uint32_t *size)
123 // fd = open( file_name, O_RDONLY);
129 // *size = st.st_size;
131 // addr = mmap( NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
132 // if(addr == (void*)-1)
143 // void unmap_file(void*addr, uint32_t size)
145 // munmap(addr, size);
148 bool start_engine(const char *prog
, FILE **in
, FILE **out
)
159 execlp(prog
, prog
, NULL
);
160 fprintf(stderr
, "Error, could not run %s!\n", prog
);
163 *in
= fdopen(pin
[0], "r");
164 *out
= fdopen(pout
[1], "w");
167 fprintf(*out
, "xboard\n");
168 fprintf(*out
, "protover 2\n");
169 //fprintf(*out, "post\n");
170 fprintf(*out
, "easy\n");
171 fprintf(*out
, "new\n");
172 fprintf(*out
, "force\n");
176 #endif //defined(_WIN32) || defined(_WIN64)