diff options
| -rw-r--r-- | userspace/snake2.c | 55 | ||||
| -rw-r--r-- | userspace/snake2.h | 10 |
2 files changed, 30 insertions, 35 deletions
diff --git a/userspace/snake2.c b/userspace/snake2.c index 78be50d..3b179ac 100644 --- a/userspace/snake2.c +++ b/userspace/snake2.c @@ -1,55 +1,40 @@ #include <stdio.h> - -int data4[100]; - -// syscall will be move to newlib? -#define SYSCALL_CLONE 83 - -int _clone(void) -{ - return syscall(SYSCALL_CLONE,0,0,0); -} +#include "snake2.h" static char lastc='d'; int main() { - printf("setvbuf returned %i\n",setvbuf(stdin,NULL,_IONBF,0)); - printf("setvbuf returned %i\n",setvbuf(stdout,NULL,_IONBF,0)); - printf("\033c"); - printf("\033HFOOL-SNAKE"); - //printf("\033d\033d\033dFOOL-SNAKE"); - printf("\033d"); - char snake[]="FOOLSNAKESFOOL"; + // turn off buffering for stdin and stdout + setvbuf(stdin,NULL,_IONBF,0); + setvbuf(stdout,NULL,_IONBF,0); - int thr=_clone(); - if(thr==0) - { - uint64_t x=0; + printf("\033c\033HFOOL-SNAKE\033d\n"); // title + char snake[]="FOOLSNAKES"; // snakes letters + + int thread=_clone(); // we want to threads + uint64_t x=0; // counter + if(thread==0) // thread 1 + { while(1) { - for(int i=0;i<10000000;i++); + for(int i=0;i<10000000;i++); // naive wait x++; - if(lastc=='d')printf("\033f"); - if(lastc=='a')printf("\033b"); - if(lastc=='w')printf("\033u"); - if(lastc=='s')printf("\033d"); + if(lastc=='d')printf("\033f"); //rigth + if(lastc=='a')printf("\033b"); //left + if(lastc=='w')printf("\033u"); //up + if(lastc=='s')printf("\033d"); //down - printf("\033[0;%im\033b%c",31+(uint8_t)(x%6),snake[x%10]); + // put letter + printf("\033[0;%im\033b%c",31+(uint8_t)(x%6),snake[x%10]); } } - else - { - while(1) - { - char c=fgetc(stdin); - lastc=c; - } - } + else while(1) lastc=fgetc(stdin); // thread 2 } + diff --git a/userspace/snake2.h b/userspace/snake2.h new file mode 100644 index 0000000..06ca797 --- /dev/null +++ b/userspace/snake2.h @@ -0,0 +1,10 @@ +////////////////////////////////////////////////// + +// this syscall will be move to newlib later! +#define SYSCALL_CLONE 83 + +int _clone(void) +{ + return syscall(SYSCALL_CLONE,0,0,0); +} +// |
