diff --git a/.gitignore b/.gitignore index 5b44aa35..82ec559d 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,7 @@ newlib/examples/hello newlib/examples/jacobi newlib/examples/echo newlib/examples/tests +newlib/examples/hangman newlib/tmp/* newlib/x86/* metalsvm.elf diff --git a/arch/x86/kernel/kb.c b/arch/x86/kernel/kb.c index ce377862..7307852e 100644 --- a/arch/x86/kernel/kb.c +++ b/arch/x86/kernel/kb.c @@ -109,15 +109,14 @@ static void keyboard_handler(struct state *r) * you would add 128 to the scancode when you look for it */ kputchar(kbdus[scancode]); - if (kb_buffer.size <= kb_buffer.maxsize) { + if (kb_buffer.size <= kb_buffer.maxsize && kb_buffer.buffer != NULL) { memcpy(kb_buffer.buffer + kb_buffer.size, &kbdus[scancode], 1); kb_buffer.size++; + if (scancode == 28 || scancode == 15 || kb_buffer.size >= kb_buffer.maxsize) { + wakeup_task(kb_buffer.tid); + reschedule(); + } } - if (scancode == 28 || scancode == 15 || kb_buffer.size >= kb_buffer.maxsize) { - wakeup_task(kb_buffer.tid); - reschedule(); - } - } } diff --git a/kernel/tests.c b/kernel/tests.c index 3b8eb57b..35ebecc8 100644 --- a/kernel/tests.c +++ b/kernel/tests.c @@ -119,7 +119,7 @@ static int STDCALL join_test(void* arg) int test_init(void) { - char* argv[] = {"/bin/hello", NULL}; + char* argv[] = {"/bin/hangman", NULL}; //sem_init(&producing, 1); //sem_init(&consuming, 0); @@ -131,7 +131,7 @@ int test_init(void) //create_kernel_task(NULL, consumer, NULL); //create_kernel_task(NULL, ping, NULL); //create_user_task(NULL, "/bin/hello", argv); - create_user_task(NULL, "/bin/hello", argv); + create_user_task(NULL, "/bin/hangman", argv); //create_user_task(NULL, "/bin/jacobi", argv); return 0; diff --git a/newlib/examples/Makefile b/newlib/examples/Makefile index e1a373f9..f63906cb 100644 --- a/newlib/examples/Makefile +++ b/newlib/examples/Makefile @@ -11,7 +11,7 @@ LDFLAGS = default: all -all: hello tests jacobi +all: hello tests jacobi hangman jacobi: jacobi.o $(CC_FOR_TARGET) -T link.ld -o $@ $(LDFLAGS) $< -lm @@ -31,6 +31,13 @@ hello: hello.o $(OBJCOPY_FOR_TARGET) $(STRIP_DEBUG) $@ chmod a-x $@.sym +hangman: hangman.o + $(CC_FOR_TARGET) -T link.ld -o $@ $(LDFLAGS) $< + $(OBJCOPY_FOR_TARGET) $(KEEP_DEBUG) $@ $@.sym + $(OBJCOPY_FOR_TARGET) $(STRIP_DEBUG) $@ + chmod a-x $@.sym + + clean: $(RM) hello tests *.sym *.o *~ diff --git a/newlib/examples/hangman.c b/newlib/examples/hangman.c new file mode 100644 index 00000000..e558b0ef --- /dev/null +++ b/newlib/examples/hangman.c @@ -0,0 +1,41 @@ +#include +#include +#include + +int Spiel () +{ + //Variablen + + char* Wort = malloc(100*sizeof(char)); + char* Raten = malloc(100*sizeof(char));; + int Versuche = 10; + + printf("Spieler 1 geben sie das Wort ein :"); + scanf("%s", Wort); + + printf("\n\nNun, Spieler 2 errate bitte das Wort\n"); + + while(Raten!=Wort && Versuche > 0){ + printf("Deine Antwort:"); + scanf("%s", Raten); + + + if(!strcmp(Raten,Wort)) + { + printf("ToLL! Das Wort ist richtig"); + return 0; + } + else + { + printf("Schade das Wort ist falsch"); + } + Versuche--; + } + return 0; +}//Spielen + +int main(int argc, char** argv) +{ + Spiel(); +} + diff --git a/newlib/examples/test b/newlib/examples/test index 28d14454..e7cf92e9 100644 --- a/newlib/examples/test +++ b/newlib/examples/test @@ -1 +1,3 @@ -123456789 +test +hallo +huso