diff --git a/iso/boot/kernel.elf b/iso/boot/kernel.elf index 8602aa2..a94e3f2 100755 Binary files a/iso/boot/kernel.elf and b/iso/boot/kernel.elf differ diff --git a/os.iso b/os.iso index 1eea564..ca153f1 100644 Binary files a/os.iso and b/os.iso differ diff --git a/src/kernel/kmain.c b/src/kernel/kmain.c index 4371303..246ca7c 100644 --- a/src/kernel/kmain.c +++ b/src/kernel/kmain.c @@ -36,7 +36,7 @@ int kmain(int retvalue) // TODO: Grub modules to load programs - //timer_install(); + timer_install(); keyboard_install(); shell_install(); diff --git a/src/kernel/shell.c b/src/kernel/shell.c index d94cb2c..7129da8 100644 --- a/src/kernel/shell.c +++ b/src/kernel/shell.c @@ -1,6 +1,7 @@ #include "system.h" #include "../libc/stdio.h" #include "../libc/string.h" +#include "../programs/programs.h" #define BUFFER_SIZE 256 @@ -26,6 +27,10 @@ void shell_install() { printf("%d", 4/0); } + else if (strcmp(input_buffer, "words") == 0) + { + program_words(); + } else { printf("Unknown command %s\n", input_buffer); } diff --git a/src/kernel/system.h b/src/kernel/system.h index 09933cf..f551d0c 100644 --- a/src/kernel/system.h +++ b/src/kernel/system.h @@ -22,5 +22,8 @@ void delay(int ticks); void keyboard_install(); char keyboard_getchar(); void shell_install(); + +extern volatile unsigned long global_ticks; + #endif diff --git a/src/kernel/timer.c b/src/kernel/timer.c index 36539a7..5e28741 100644 --- a/src/kernel/timer.c +++ b/src/kernel/timer.c @@ -1,16 +1,11 @@ #include "system.h" #include "../libc/stdio.h" -int timer_ticks = 0; +volatile unsigned long global_ticks = 0; void timer_handler() { - timer_ticks++; - - if(timer_ticks % 18 == 0) - { - puts("One second has passed\n"); - } + global_ticks++; } void timer_install() @@ -21,6 +16,6 @@ void timer_install() void delay(int ticks) { unsigned long eticks; - eticks = timer_ticks + ticks; - while ((unsigned long)timer_ticks < eticks); + eticks = global_ticks + ticks; + while (global_ticks < eticks); } diff --git a/src/libc/crypto.c b/src/libc/crypto.c index e69de29..df39fe7 100644 --- a/src/libc/crypto.c +++ b/src/libc/crypto.c @@ -0,0 +1,24 @@ +#include "crypto.h" + +int lcg(int seed) +{ + int x = seed; + + // Constants (ZX81 LCG) + int a = 75; + int c = 74; + long m = 65537; + + for (int i=0; i<10; i++) + { + x = (a*x + c) % m; + } + + return x; +} + +int randint(int seed) +{ + int x = lcg(seed); + return x; +} diff --git a/src/libc/crypto.h b/src/libc/crypto.h new file mode 100644 index 0000000..dd8c561 --- /dev/null +++ b/src/libc/crypto.h @@ -0,0 +1,9 @@ +#ifndef CRYPTO_H +#define CRYPTO_H + +#define RAND_MAX 1024 + +int lcg(int seed); +int randint(int seed); + +#endif diff --git a/src/programs/programs.h b/src/programs/programs.h new file mode 100644 index 0000000..9842cd9 --- /dev/null +++ b/src/programs/programs.h @@ -0,0 +1,6 @@ +#ifndef PROGRAMS_H +#define PROGRAMS_H + +void program_words(); + +#endif diff --git a/src/programs/words.c b/src/programs/words.c new file mode 100644 index 0000000..129f1e6 --- /dev/null +++ b/src/programs/words.c @@ -0,0 +1,52 @@ + +#include "../libc/stdio.h" +#include "../libc/crypto.h" +#include "../kernel/system.h" + +char* words[] = +{ + "I", "us", "they", "my", + "a", "an", "is", "are", "for", "while", "not", "none", "yes", "no", + "absolutely", "addition", "additive", "afternoon", "architect", "ask", + "be", "blindfold", "brilliant", "boy", "brilliant", "bring", "buddy", + "career", "caterpillar", "change", "cheeky", "chop", + "decide", "demonstrate", "draw", "druggist", + "eagle", "ear", "effort", "evening", + "fabric", "famous", "fuse", + "generation", "generous", "girl", "gypsy", "grip", + "habit", "handsome", "helmet", "help", "horror", + "insist", "inventor", "itself", "ivory", + "jog", "joint", "joke", "judge", + "karate", "kebab", "kitchen", + "lamb", "lawnmower", "left", "lock", + "math", "medicine", "most", + "noodles", "nowadays", "nowhere", + "ocean", "older", "ounce", + "part", "pathetic", "pastime", + "quite", "quits", "quotation", + "race", "raise", "reality", + "safe", "scare", "screen", + "taught", "temple", "that", "this", + "unable", "unkind", "usual", + "velvet", "vivid", "vote", + "we", "warm", "watch", + "xylophone", + "yolk", "young", "your", + "zebra", "zodiac", "zucchini", +}; + +int words_size = sizeof(words)/sizeof(words[0]); + +// Generates 5 random words +void program_words() +{ + for (int i=0; i<10; i++) + { + int random = randint(global_ticks); + char* word = words[random%words_size]; + //printf("Global ticks: %d\nRandom integer: %d\nWord: %s\n", global_ticks, random, word); + printf("%s ", word); + delay(10); + } + puts("\n"); +}