diff --git a/com1.out b/com1.out index 10c4e1d..70ff6a0 100644 Binary files a/com1.out and b/com1.out differ diff --git a/iso/boot/kernel.elf b/iso/boot/kernel.elf index 8e5c86c..ff425bf 100755 Binary files a/iso/boot/kernel.elf and b/iso/boot/kernel.elf differ diff --git a/src/kernel/kmain.c b/src/kernel/kmain.c index c2f8806..21ddf39 100644 --- a/src/kernel/kmain.c +++ b/src/kernel/kmain.c @@ -35,7 +35,7 @@ void kmain(unsigned int multiboot_info_address) clear(); colorputs(ascii_title, 10); colorputs(" by @xamidev - star the repo for a cookie!\n\n", 14); - + timer_install(); serial_printf(2, "%d\tinitialized timer handler", global_ticks); keyboard_install(); diff --git a/src/kernel/shell.c b/src/kernel/shell.c index e5325ec..853a92f 100644 --- a/src/kernel/shell.c +++ b/src/kernel/shell.c @@ -65,7 +65,8 @@ void shell_install() register_command("uptime", program_uptime); register_command("echo", program_echo); register_command("sysinfo", program_sysinfo); - + register_command("conway", program_conway); + for (;;) { char input_buffer[BUFFER_SIZE]; diff --git a/src/libc/crypto.c b/src/libc/crypto.c index df39fe7..b9c261e 100644 --- a/src/libc/crypto.c +++ b/src/libc/crypto.c @@ -1,4 +1,5 @@ #include "crypto.h" +#include "../libc/stdint.h" int lcg(int seed) { @@ -22,3 +23,21 @@ int randint(int seed) int x = lcg(seed); return x; } + +static uint32_t next = 1; + +uint32_t rand() +{ + next = next * 1103515245 + 12345; + return (next/65536) % 32768; +} + +float rand_float() +{ + return rand() / 32767.0f; +} + +void srand(uint32_t seed) +{ + next = seed; +} diff --git a/src/libc/crypto.h b/src/libc/crypto.h index dd8c561..04a54b1 100644 --- a/src/libc/crypto.h +++ b/src/libc/crypto.h @@ -3,7 +3,12 @@ #define RAND_MAX 1024 +#include "../libc/stdint.h" + int lcg(int seed); int randint(int seed); +uint32_t rand(); +float rand_float(); +void srand(uint32_t seed); #endif diff --git a/src/programs/conway.c b/src/programs/conway.c new file mode 100644 index 0000000..703512d --- /dev/null +++ b/src/programs/conway.c @@ -0,0 +1,132 @@ +#include "conway.h" +#include "../libc/stdio.h" +#include "../kernel/system.h" +#include "../libc/crypto.h" +#include "../libc/stdint.h" +#include "../drivers/serial.h" +#include "../libc/string.h" + +void print_grid(const unsigned char grid[X][Y]) +{ + for (int i=0; i= 0 && ni < X && nj >= 0) + { + if (grid[ni][nj] == LIVE) live_neighbors++; + } + } + } + return live_neighbors; +} + +void grid_new_generation(unsigned char grid[X][Y], unsigned char temp[X][Y]) +{ + for (int i=0; i SOUP_PROB ? LIVE : DEAD; + } + } +} + +void program_conway(int argc, char* argv[]) +{ + clear(); + unsigned char grid[X][Y] = {0}; + unsigned char temp[X][Y] = {0}; + + if (argc == 1) + { + soup(grid); + } else if (argc == 2 && strcmp(argv[1], "-g") == 0) { + grid[1][2] = LIVE; + grid[2][3] = LIVE; + grid[3][1] = LIVE; + grid[3][2] = LIVE; + grid[3][3] = LIVE; + } else if (argc == 2 && strcmp(argv[1], "-l") == 0) { + grid[10][3] = LIVE; grid[10][4] = LIVE; grid[10][5] = LIVE; grid[10][6] = LIVE; + grid[11][2] = LIVE; grid[11][6] = LIVE; + grid[12][6] = LIVE; + grid[13][2] = LIVE; grid[13][5] = LIVE; + } + + print_grid(grid); + puts("generation 0"); + for (int i=1; i