From 16dca326cedd8214bb4f182a269189fcac8d65ac Mon Sep 17 00:00:00 2001 From: Eva Grace DeThomas Date: Sat, 28 Sep 2024 22:50:19 -0700 Subject: [PATCH 01/24] First component of guy --- Makefile | 1 + user/guy.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 user/guy.c diff --git a/Makefile b/Makefile index 2584e4a..a144cc2 100644 --- a/Makefile +++ b/Makefile @@ -120,6 +120,7 @@ UPROGS=\ $U/_echo\ $U/_forktest\ $U/_grep\ + $U/_guy\ $U/_init\ $U/_kill\ $U/_ln\ diff --git a/user/guy.c b/user/guy.c new file mode 100644 index 0000000..f755929 --- /dev/null +++ b/user/guy.c @@ -0,0 +1,14 @@ +#include "kernel/types.h" +#include "kernel/stat.h" +#include "user/user.h" + +void printGuy() { + printf(" O \n"); + printf(" /|\\ \n"); + printf(" / \\ \n"); +} + +int main () { + printGuy(); + return 0; +} From 1bfb66786afc21cbf3673c950860427a5abfa4d4 Mon Sep 17 00:00:00 2001 From: Eva Grace DeThomas Date: Sat, 28 Sep 2024 23:42:20 -0700 Subject: [PATCH 02/24] Guy running partially implemented --- user/guy | 0 user/guy.c | 34 ++++++++++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 user/guy diff --git a/user/guy b/user/guy new file mode 100644 index 0000000..e69de29 diff --git a/user/guy.c b/user/guy.c index f755929..71da2cc 100644 --- a/user/guy.c +++ b/user/guy.c @@ -2,13 +2,39 @@ #include "kernel/stat.h" #include "user/user.h" -void printGuy() { +void clearScreen() { + printf("\033[H\033[J"); +} + +void printGuy(int pos) { + for (int j = 0; j < pos; j++) { + printf(" "); + } + printf(" O \n"); - printf(" /|\\ \n"); - printf(" / \\ \n"); + + for (int j = 0; j < pos; j++) { + printf(" "); + } + printf(" /|\\ \n"); + + for (int j = 0; j < pos; j++) { + printf(" "); + } + printf(" / \\ \n"); +} + +void guyRun() { + for (int i = 0; i < 30; i++) { + clearScreen(); + printGuy(i); + sleep(5); + } } int main () { - printGuy(); + + guyRun(); + return 0; } From 0d098a8f187652db7441a40cafd970587729da04 Mon Sep 17 00:00:00 2001 From: Eva Grace DeThomas Date: Sun, 29 Sep 2024 00:14:31 -0700 Subject: [PATCH 03/24] Committing with new plan for run --- user/guy.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/user/guy.c b/user/guy.c index 71da2cc..b68e849 100644 --- a/user/guy.c +++ b/user/guy.c @@ -24,11 +24,21 @@ void printGuy(int pos) { printf(" / \\ \n"); } +void print_guy(int pos) { + char *buffer = (char *)malloc(128*pos*20); + strcpy(buffer, " O \n"); + printf(buffer); + strcpy + free(buffer); +} + + + void guyRun() { for (int i = 0; i < 30; i++) { clearScreen(); - printGuy(i); - sleep(5); + print_guy(i); + sleep(0.5); } } From 76d6e17f39b5c4860bba802fcea9d61f3360dd25 Mon Sep 17 00:00:00 2001 From: Eva Grace DeThomas Date: Sun, 29 Sep 2024 14:39:28 -0700 Subject: [PATCH 04/24] malloc nearly working --- user/guy.c | 44 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/user/guy.c b/user/guy.c index b68e849..df832d6 100644 --- a/user/guy.c +++ b/user/guy.c @@ -26,25 +26,59 @@ void printGuy(int pos) { void print_guy(int pos) { char *buffer = (char *)malloc(128*pos*20); - strcpy(buffer, " O \n"); + + strcpy(buffer, " O \n /|\\ \n / \\ \n\0"); + printf(buffer); - strcpy + free(buffer); } +void print_guy_run(int pos) { + char *buffer = (char *)malloc((pos*3 + 12)*sizeof(char)); + char *spaces = (char *)malloc(pos*sizeof(char)); + + for (int i = 0; i < pos; i++) { + spaces[i] = ' '; + } + + + char *head = (char *)malloc(10 * sizeof(char)); + strcpy(head, " O \n"); + + memcpy(buffer, spaces, strlen(spaces) +1); + memcpy(buffer + pos, head, strlen(head) + 1); + memcpy(buffer + pos + strlen(head), spaces, strlen(spaces) + 1); + + + char *torso = (char *)malloc(10 * sizeof(char)); + strcpy(torso, " /|\\ \n"); + + memcpy(buffer + pos * 2 + strlen(head), torso, strlen(torso) + 1); + + printf(buffer); + free(buffer); + free(head); + free(torso); + + +} + + void guyRun() { for (int i = 0; i < 30; i++) { clearScreen(); - print_guy(i); + printGuy(i); sleep(0.5); } } int main () { - guyRun(); - + //guyRun(); + //printGuy(30); + print_guy_run(30); return 0; } From 8a0f9ded88267f627a8b16b1f7a80f4d6b1eb809 Mon Sep 17 00:00:00 2001 From: Eva Grace DeThomas Date: Sun, 29 Sep 2024 14:46:00 -0700 Subject: [PATCH 05/24] full guy theregit add . --- user/guy.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/user/guy.c b/user/guy.c index df832d6..2ea5868 100644 --- a/user/guy.c +++ b/user/guy.c @@ -36,7 +36,7 @@ void print_guy(int pos) { void print_guy_run(int pos) { - char *buffer = (char *)malloc((pos*3 + 12)*sizeof(char)); + char *buffer = (char *)malloc((pos*3 + 30)*sizeof(char)); char *spaces = (char *)malloc(pos*sizeof(char)); for (int i = 0; i < pos; i++) { @@ -45,7 +45,7 @@ void print_guy_run(int pos) { char *head = (char *)malloc(10 * sizeof(char)); - strcpy(head, " O \n"); + strcpy(head, " O \n"); memcpy(buffer, spaces, strlen(spaces) +1); memcpy(buffer + pos, head, strlen(head) + 1); @@ -54,14 +54,20 @@ void print_guy_run(int pos) { char *torso = (char *)malloc(10 * sizeof(char)); strcpy(torso, " /|\\ \n"); - - memcpy(buffer + pos * 2 + strlen(head), torso, strlen(torso) + 1); + char *legs = (char *)malloc(10 * sizeof(char)); + strcpy(legs, " / \\ \n"); + + memcpy(buffer + (pos * 2) + strlen(head), torso, strlen(torso) + 1); + memcpy(buffer + (pos * 2) + strlen(head) + strlen(torso), spaces, strlen(spaces) + 1); + memcpy(buffer + (pos * 3) + strlen(head) + strlen(torso), legs, strlen(legs) + 1); + printf(buffer); free(buffer); free(head); free(torso); - + free(legs); + free(spaces); } From 43150eae06adbb5e7ecfe0b5149921d3ee3bb925 Mon Sep 17 00:00:00 2001 From: Eva Grace DeThomas Date: Sun, 29 Sep 2024 14:53:11 -0700 Subject: [PATCH 06/24] Committing guy running, need to fix sleep --- user/guy.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/user/guy.c b/user/guy.c index 2ea5868..408baf5 100644 --- a/user/guy.c +++ b/user/guy.c @@ -63,6 +63,7 @@ void print_guy_run(int pos) { memcpy(buffer + (pos * 3) + strlen(head) + strlen(torso), legs, strlen(legs) + 1); printf(buffer); + free(buffer); free(head); free(torso); @@ -73,18 +74,20 @@ void print_guy_run(int pos) { -void guyRun() { +void guyRun1() { for (int i = 0; i < 30; i++) { clearScreen(); - printGuy(i); - sleep(0.5); + sleep(1); + print_guy_run(i); + sleep(1); } + printf("%s", "hello"); } int main () { - //guyRun(); + guyRun1(); //printGuy(30); - print_guy_run(30); + //print_guy_run(30); return 0; } From c153790b48d5098cc11112540fb78992c8284468 Mon Sep 17 00:00:00 2001 From: Eva Grace DeThomas Date: Sun, 29 Sep 2024 15:27:30 -0700 Subject: [PATCH 07/24] Added a sleep_ms system call and make a guy call in user space --- kernel/syscall.c | 2 ++ kernel/syscall.h | 1 + kernel/sysproc.c | 22 ++++++++++++++++++++++ user/guy.c | 3 +-- user/user.h | 1 + user/usys.pl | 1 + 6 files changed, 28 insertions(+), 2 deletions(-) diff --git a/kernel/syscall.c b/kernel/syscall.c index ed65409..9e5ecaf 100644 --- a/kernel/syscall.c +++ b/kernel/syscall.c @@ -93,6 +93,7 @@ extern uint64 sys_dup(void); extern uint64 sys_getpid(void); extern uint64 sys_sbrk(void); extern uint64 sys_sleep(void); +extern uint64 sys_sleep_ms(void); extern uint64 sys_uptime(void); extern uint64 sys_open(void); extern uint64 sys_write(void); @@ -118,6 +119,7 @@ static uint64 (*syscalls[])(void) = { [SYS_getpid] sys_getpid, [SYS_sbrk] sys_sbrk, [SYS_sleep] sys_sleep, +[SYS_sleep_ms] sys_sleep_ms, [SYS_uptime] sys_uptime, [SYS_open] sys_open, [SYS_write] sys_write, diff --git a/kernel/syscall.h b/kernel/syscall.h index bc5f356..c9779a5 100644 --- a/kernel/syscall.h +++ b/kernel/syscall.h @@ -20,3 +20,4 @@ #define SYS_link 19 #define SYS_mkdir 20 #define SYS_close 21 +#define SYS_sleep_ms 22 diff --git a/kernel/sysproc.c b/kernel/sysproc.c index 1de184e..672528d 100644 --- a/kernel/sysproc.c +++ b/kernel/sysproc.c @@ -67,6 +67,28 @@ sys_sleep(void) release(&tickslock); return 0; } +uint64 +sys_sleep_ms(void) +{ + int n; + uint ticks0; + + argint(0, &n); + acquire(&tickslock); + + uint militicks = n / 10; + + ticks0 = ticks; + while(ticks - ticks0 < militicks){ + if(killed(myproc())){ + release(&tickslock); + return -1; + } + sleep(&ticks, &tickslock); + } + release(&tickslock); + return 0; +} uint64 sys_kill(void) diff --git a/user/guy.c b/user/guy.c index 408baf5..508080c 100644 --- a/user/guy.c +++ b/user/guy.c @@ -77,9 +77,8 @@ void print_guy_run(int pos) { void guyRun1() { for (int i = 0; i < 30; i++) { clearScreen(); - sleep(1); print_guy_run(i); - sleep(1); + sleep_ms(10); } printf("%s", "hello"); } diff --git a/user/user.h b/user/user.h index 2e6fc55..5b550d4 100644 --- a/user/user.h +++ b/user/user.h @@ -22,6 +22,7 @@ int getpid(void); char* sbrk(int); int sleep(int); int uptime(void); +int sleep_ms(int); // ulib.c int stat(const char*, struct stat*); diff --git a/user/usys.pl b/user/usys.pl index 01e426e..123c3b6 100755 --- a/user/usys.pl +++ b/user/usys.pl @@ -36,3 +36,4 @@ sub entry { entry("sbrk"); entry("sleep"); entry("uptime"); +entry("sleep_ms"); From 918a221726ad33f41364e710325ccbfb07467427 Mon Sep 17 00:00:00 2001 From: Eva Grace DeThomas Date: Sun, 29 Sep 2024 15:56:36 -0700 Subject: [PATCH 08/24] guy run --- kernel/sysproc.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/kernel/sysproc.c b/kernel/sysproc.c index 672528d..6d82c77 100644 --- a/kernel/sysproc.c +++ b/kernel/sysproc.c @@ -76,10 +76,11 @@ sys_sleep_ms(void) argint(0, &n); acquire(&tickslock); - uint militicks = n / 10; - + uint target_ticks = (n + 1000 - 1) / 1000; + ticks0 = ticks; - while(ticks - ticks0 < militicks){ + + while(ticks - ticks0 < target_ticks){ if(killed(myproc())){ release(&tickslock); return -1; From e8496f9e163f512246bcbbdcb5f22e080d346263 Mon Sep 17 00:00:00 2001 From: Eva Grace DeThomas Date: Sun, 29 Sep 2024 16:14:58 -0700 Subject: [PATCH 09/24] Guy gets mad mostly done --- user/guy.c | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/user/guy.c b/user/guy.c index 508080c..1be3443 100644 --- a/user/guy.c +++ b/user/guy.c @@ -1,6 +1,8 @@ #include "kernel/types.h" #include "kernel/stat.h" #include "user/user.h" +#define RED "\033[31m" +#define RESET "\033[0m" void clearScreen() { printf("\033[H\033[J"); @@ -24,8 +26,8 @@ void printGuy(int pos) { printf(" / \\ \n"); } -void print_guy(int pos) { - char *buffer = (char *)malloc(128*pos*20); +void print_guy() { + char *buffer = (char *)malloc(128*20); strcpy(buffer, " O \n /|\\ \n / \\ \n\0"); @@ -72,21 +74,37 @@ void print_guy_run(int pos) { } +void guy_color() { + printf("%s", RED); + print_guy(); + printf("%s", RESET); +} + -void guyRun1() { +void guy_run() { for (int i = 0; i < 30; i++) { clearScreen(); print_guy_run(i); sleep_ms(10); } - printf("%s", "hello"); + for (int i = 30; i >0; i--) { + clearScreen(); + print_guy_run(i); + sleep_ms(10); + } } -int main () { +int main (int argc, char *argv[]) { + + if (argc == 1) { + print_guy(); + } else if (strcmp(argv[1], "run") == 0) { + guy_run(); + } else { + printf("Fail"); + } - guyRun1(); - //printGuy(30); - //print_guy_run(30); + guy_color(); return 0; } From c9a8023d9dd7a2ce0af37babb8966ef9efdd02f5 Mon Sep 17 00:00:00 2001 From: Eva Grace DeThomas Date: Sun, 29 Sep 2024 17:01:11 -0700 Subject: [PATCH 10/24] Committing with celebrate --- user/guy.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 68 insertions(+), 3 deletions(-) diff --git a/user/guy.c b/user/guy.c index 1be3443..6de76d0 100644 --- a/user/guy.c +++ b/user/guy.c @@ -3,6 +3,7 @@ #include "user/user.h" #define RED "\033[31m" #define RESET "\033[0m" +#define GREEN "\033[32m" void clearScreen() { printf("\033[H\033[J"); @@ -36,6 +37,36 @@ void print_guy() { free(buffer); } +void print_guy_U() { + char *buffer = (char *)malloc(128*20); + + strcpy(buffer, "\n O \n /|\\ \n / \\ \n\0"); + + printf(buffer); + + free(buffer); +} + +void print_guy_L() { + char *buffer = (char *)malloc(128*20); + + strcpy(buffer, " O \n /|\\ \n / \\ \n\0"); + + printf(buffer); + + free(buffer); +} + +void print_guy_R() { + char *buffer = (char *)malloc(128*20); + + strcpy(buffer, " O \n /|\\ \n / \\ \n\0"); + + printf(buffer); + + free(buffer); +} + void print_guy_run(int pos) { char *buffer = (char *)malloc((pos*3 + 30)*sizeof(char)); @@ -76,6 +107,16 @@ void print_guy_run(int pos) { void guy_color() { printf("%s", RED); + for (int i = 0; i < 15; i++) { + clearScreen(); + if (i % 2 == 0) { + print_guy_L(); + } else { + print_guy_R(); + } + sleep_ms(10); + } + clearScreen(); print_guy(); printf("%s", RESET); } @@ -83,28 +124,52 @@ void guy_color() { void guy_run() { - for (int i = 0; i < 30; i++) { + for (int i = 0; i < 20; i++) { clearScreen(); print_guy_run(i); sleep_ms(10); } - for (int i = 30; i >0; i--) { + for (int i = 20; i >0; i--) { clearScreen(); print_guy_run(i); sleep_ms(10); } +} + +void guy_celebrate() { + clearScreen(); + print_guy_U(); + printf("%s", GREEN); + for (int i = 0; i < 15; i++) { + clearScreen(); + if (i % 2 == 0) { + print_guy_U(); + } else { + print_guy(); + } + sleep_ms(10); + } + clearScreen(); + printf(" YAY!\n"); + print_guy(); + + printf("%s", RESET); } +guy_ + int main (int argc, char *argv[]) { if (argc == 1) { print_guy(); } else if (strcmp(argv[1], "run") == 0) { guy_run(); + } else if ((strcmp(argv[1], "gets") == 0) && (strcmp(argv[2], "mad") == 0)) { + guy_color(); } else { printf("Fail"); } - guy_color(); + guy_celebrate(); return 0; } From 8972bbb77afc192049fab7d5fe675301d1ce73f7 Mon Sep 17 00:00:00 2001 From: Eva Grace DeThomas Date: Sun, 29 Sep 2024 20:34:19 -0700 Subject: [PATCH 11/24] Revert "Committing with celebrate" This reverts commit c9a8023d9dd7a2ce0af37babb8966ef9efdd02f5. --- user/guy.c | 71 +++--------------------------------------------------- 1 file changed, 3 insertions(+), 68 deletions(-) diff --git a/user/guy.c b/user/guy.c index 6de76d0..1be3443 100644 --- a/user/guy.c +++ b/user/guy.c @@ -3,7 +3,6 @@ #include "user/user.h" #define RED "\033[31m" #define RESET "\033[0m" -#define GREEN "\033[32m" void clearScreen() { printf("\033[H\033[J"); @@ -37,36 +36,6 @@ void print_guy() { free(buffer); } -void print_guy_U() { - char *buffer = (char *)malloc(128*20); - - strcpy(buffer, "\n O \n /|\\ \n / \\ \n\0"); - - printf(buffer); - - free(buffer); -} - -void print_guy_L() { - char *buffer = (char *)malloc(128*20); - - strcpy(buffer, " O \n /|\\ \n / \\ \n\0"); - - printf(buffer); - - free(buffer); -} - -void print_guy_R() { - char *buffer = (char *)malloc(128*20); - - strcpy(buffer, " O \n /|\\ \n / \\ \n\0"); - - printf(buffer); - - free(buffer); -} - void print_guy_run(int pos) { char *buffer = (char *)malloc((pos*3 + 30)*sizeof(char)); @@ -107,16 +76,6 @@ void print_guy_run(int pos) { void guy_color() { printf("%s", RED); - for (int i = 0; i < 15; i++) { - clearScreen(); - if (i % 2 == 0) { - print_guy_L(); - } else { - print_guy_R(); - } - sleep_ms(10); - } - clearScreen(); print_guy(); printf("%s", RESET); } @@ -124,52 +83,28 @@ void guy_color() { void guy_run() { - for (int i = 0; i < 20; i++) { + for (int i = 0; i < 30; i++) { clearScreen(); print_guy_run(i); sleep_ms(10); } - for (int i = 20; i >0; i--) { + for (int i = 30; i >0; i--) { clearScreen(); print_guy_run(i); sleep_ms(10); } -} - -void guy_celebrate() { - clearScreen(); - print_guy_U(); - printf("%s", GREEN); - for (int i = 0; i < 15; i++) { - clearScreen(); - if (i % 2 == 0) { - print_guy_U(); - } else { - print_guy(); - } - sleep_ms(10); - } - clearScreen(); - printf(" YAY!\n"); - print_guy(); - - printf("%s", RESET); } -guy_ - int main (int argc, char *argv[]) { if (argc == 1) { print_guy(); } else if (strcmp(argv[1], "run") == 0) { guy_run(); - } else if ((strcmp(argv[1], "gets") == 0) && (strcmp(argv[2], "mad") == 0)) { - guy_color(); } else { printf("Fail"); } - guy_celebrate(); + guy_color(); return 0; } From a54666faf83ea0690335c73031cfc357ca12b4c1 Mon Sep 17 00:00:00 2001 From: Eva Grace DeThomas Date: Sun, 29 Sep 2024 20:52:57 -0700 Subject: [PATCH 12/24] Adding guy2 just in case --- Makefile | 1 + user/guy.h | 6 ++ user/guy2.c | 173 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 180 insertions(+) create mode 100644 user/guy.h create mode 100644 user/guy2.c diff --git a/Makefile b/Makefile index a144cc2..726f819 100644 --- a/Makefile +++ b/Makefile @@ -121,6 +121,7 @@ UPROGS=\ $U/_forktest\ $U/_grep\ $U/_guy\ + $U/_guy2\ $U/_init\ $U/_kill\ $U/_ln\ diff --git a/user/guy.h b/user/guy.h new file mode 100644 index 0000000..af3264f --- /dev/null +++ b/user/guy.h @@ -0,0 +1,6 @@ +#ifndef MYFILE_H +#define MYFILE_H + +void guy_color(); + +#endif // MYFILE_H diff --git a/user/guy2.c b/user/guy2.c new file mode 100644 index 0000000..5e2eeea --- /dev/null +++ b/user/guy2.c @@ -0,0 +1,173 @@ +#include "kernel/types.h" +#include "kernel/stat.h" +#include "user/user.h" +#define RED "\033[31m" +#define RESET "\033[0m" +#define GREEN "\033[32m" + +void clearScreen() { + printf("\033[H\033[J"); +} + +void printGuy(int pos) { + for (int j = 0; j < pos; j++) { + printf(" "); + } + + printf(" O \n"); + + for (int j = 0; j < pos; j++) { + printf(" "); + } + printf(" /|\\ \n"); + + for (int j = 0; j < pos; j++) { + printf(" "); + } + printf(" / \\ \n"); +} + +void print_guy() { + char *buffer = (char *)malloc(128*20); + + strcpy(buffer, " O \n /|\\ \n / \\ \n\0"); + + printf(buffer); + + free(buffer); +} + +void print_guy_U() { + char *buffer = (char *)malloc(128*20); + + strcpy(buffer, "\n O \n /|\\ \n / \\ \n\0"); + + printf(buffer); + + free(buffer); +} + +void print_guy_L() { + char *buffer = (char *)malloc(128*20); + + strcpy(buffer, " O \n /|\\ \n / \\ \n\0"); + + printf(buffer); + + free(buffer); +} + +void print_guy_R() { + char *buffer = (char *)malloc(128*20); + + strcpy(buffer, " O \n /|\\ \n / \\ \n\0"); + + printf(buffer); + + free(buffer); +} + + +void print_guy_run(int pos) { + char *buffer = (char *)malloc((pos*3 + 30)*sizeof(char)); + char *spaces = (char *)malloc(pos*sizeof(char)); + + for (int i = 0; i < pos; i++) { + spaces[i] = ' '; + } + + + char *head = (char *)malloc(10 * sizeof(char)); + strcpy(head, " O \n"); + + memcpy(buffer, spaces, strlen(spaces) +1); + memcpy(buffer + pos, head, strlen(head) + 1); + memcpy(buffer + pos + strlen(head), spaces, strlen(spaces) + 1); + + + char *torso = (char *)malloc(10 * sizeof(char)); + strcpy(torso, " /|\\ \n"); + + char *legs = (char *)malloc(10 * sizeof(char)); + strcpy(legs, " / \\ \n"); + + memcpy(buffer + (pos * 2) + strlen(head), torso, strlen(torso) + 1); + memcpy(buffer + (pos * 2) + strlen(head) + strlen(torso), spaces, strlen(spaces) + 1); + memcpy(buffer + (pos * 3) + strlen(head) + strlen(torso), legs, strlen(legs) + 1); + + printf(buffer); + + free(buffer); + free(head); + free(torso); + free(legs); + free(spaces); + +} + +void guy_color() { + printf("%s", RED); + for (int i = 0; i < 15; i++) { + clearScreen(); + if (i % 2 == 0) { + print_guy_L(); + } else { + print_guy_R(); + } + sleep_ms(10); + } + clearScreen(); + print_guy(); + printf("%s", RESET); +} + + + +void guy_run() { + for (int i = 0; i < 20; i++) { + clearScreen(); + print_guy_run(i); + sleep_ms(10); + } + for (int i = 20; i >0; i--) { + clearScreen(); + print_guy_run(i); + sleep_ms(10); + } +} + +void guy_celebrate() { + clearScreen(); + print_guy_U(); + printf("%s", GREEN); + for (int i = 0; i < 15; i++) { + clearScreen(); + if (i % 2 == 0) { + print_guy_U(); + } else { + print_guy(); + } + sleep_ms(10); + } + clearScreen(); + printf(" YAY!\n"); + print_guy(); + + printf("%s", RESET); +} + +int main (int argc, char *argv[]) { + + if (argc == 1) { + print_guy(); + } else if (strcmp(argv[1], "run") == 0) { + guy_run(); + } else if ((strcmp(argv[1], "gets") == 0) && (strcmp(argv[2], "mad") == 0)) { + guy_color(); + } else { + printf("Fail"); + } + + guy_celebrate(); + return 0; +} From 54b1f7165cb36bae93d2e278ebdc3873b4f86623 Mon Sep 17 00:00:00 2001 From: Eva Grace DeThomas Date: Sun, 29 Sep 2024 22:59:05 -0700 Subject: [PATCH 13/24] Finally figured out a lil interface git add . --- Makefile | 6 +- user/guy.c => kernel/guy2.c | 72 +++++++++++++- user/FogOSGraphix | 193 ++++++++++++++++++++++++++++++++++++ user/guy2.c | 22 +--- user/init.c | 4 +- user/user.h | 3 + 6 files changed, 271 insertions(+), 29 deletions(-) rename user/guy.c => kernel/guy2.c (59%) create mode 100644 user/FogOSGraphix diff --git a/Makefile b/Makefile index 726f819..def8466 100644 --- a/Makefile +++ b/Makefile @@ -87,7 +87,7 @@ $U/initcode: $U/initcode.S tags: $(OBJS) _init etags *.S *.c -ULIB = $U/ulib.o $U/usys.o $U/printf.o $U/umalloc.o +ULIB = $U/ulib.o $U/usys.o $U/printf.o $U/guy2.o $U/umalloc.o _%: %.o $(ULIB) $(LD) $(LDFLAGS) -T $U/user.ld -o $@ $^ @@ -103,7 +103,7 @@ $U/usys.o : $U/usys.S $U/_forktest: $U/forktest.o $(ULIB) # forktest has less library code linked in - needs to be small # in order to be able to max out the proc table. - $(LD) $(LDFLAGS) -N -e main -Ttext 0 -o $U/_forktest $U/forktest.o $U/ulib.o $U/usys.o $U/umalloc.o $U/printf.o + $(LD) $(LDFLAGS) -N -e main -Ttext 0 -o $U/_forktest $U/forktest.o $U/ulib.o $U/usys.o $U/guy2.o $U/umalloc.o $U/printf.o $(OBJDUMP) -S $U/_forktest > $U/forktest.asm mkfs/mkfs: mkfs/mkfs.c $K/fs.h $K/param.h @@ -120,8 +120,6 @@ UPROGS=\ $U/_echo\ $U/_forktest\ $U/_grep\ - $U/_guy\ - $U/_guy2\ $U/_init\ $U/_kill\ $U/_ln\ diff --git a/user/guy.c b/kernel/guy2.c similarity index 59% rename from user/guy.c rename to kernel/guy2.c index 1be3443..b61e687 100644 --- a/user/guy.c +++ b/kernel/guy2.c @@ -1,8 +1,8 @@ #include "kernel/types.h" -#include "kernel/stat.h" -#include "user/user.h" +#include "ulib.c" #define RED "\033[31m" #define RESET "\033[0m" +#define GREEN "\033[32m" void clearScreen() { printf("\033[H\033[J"); @@ -36,6 +36,36 @@ void print_guy() { free(buffer); } +void print_guy_U() { + char *buffer = (char *)malloc(128*20); + + strcpy(buffer, "\n O \n /|\\ \n / \\ \n\0"); + + printf(buffer); + + free(buffer); +} + +void print_guy_L() { + char *buffer = (char *)malloc(128*20); + + strcpy(buffer, " O \n /|\\ \n / \\ \n\0"); + + printf(buffer); + + free(buffer); +} + +void print_guy_R() { + char *buffer = (char *)malloc(128*20); + + strcpy(buffer, " O \n /|\\ \n / \\ \n\0"); + + printf(buffer); + + free(buffer); +} + void print_guy_run(int pos) { char *buffer = (char *)malloc((pos*3 + 30)*sizeof(char)); @@ -76,6 +106,16 @@ void print_guy_run(int pos) { void guy_color() { printf("%s", RED); + for (int i = 0; i < 15; i++) { + clearScreen(); + if (i % 2 == 0) { + print_guy_L(); + } else { + print_guy_R(); + } + sleep_ms(10); + } + clearScreen(); print_guy(); printf("%s", RESET); } @@ -83,16 +123,36 @@ void guy_color() { void guy_run() { - for (int i = 0; i < 30; i++) { + for (int i = 0; i < 20; i++) { clearScreen(); print_guy_run(i); sleep_ms(10); } - for (int i = 30; i >0; i--) { + for (int i = 20; i >0; i--) { clearScreen(); print_guy_run(i); sleep_ms(10); } +} + +void guy_celebrate() { + clearScreen(); + print_guy_U(); + printf("%s", GREEN); + for (int i = 0; i < 15; i++) { + clearScreen(); + if (i % 2 == 0) { + print_guy_U(); + } else { + print_guy(); + } + sleep_ms(10); + } + clearScreen(); + printf(" YAY!\n"); + print_guy(); + + printf("%s", RESET); } int main (int argc, char *argv[]) { @@ -101,10 +161,12 @@ int main (int argc, char *argv[]) { print_guy(); } else if (strcmp(argv[1], "run") == 0) { guy_run(); + } else if ((strcmp(argv[1], "gets") == 0) && (strcmp(argv[2], "mad") == 0)) { + guy_color(); } else { printf("Fail"); } - guy_color(); + guy_celebrate(); return 0; } diff --git a/user/FogOSGraphix b/user/FogOSGraphix new file mode 100644 index 0000000..f0d62c5 --- /dev/null +++ b/user/FogOSGraphix @@ -0,0 +1,193 @@ +#include "kernel/types.h" +#include "kernel/stat.h" +#include "kernel/fcntl.h" +#include "user/user.h" + +// +// wrapper so that it's OK if main() does not call exit(). +// +void +_main() +{ + extern int main(); + main(); + exit(0); +} + +char* +strcpy(char *s, const char *t) +{ + char *os; + + os = s; + while((*s++ = *t++) != 0) + ; + return os; +} + +int +strcmp(const char *p, const char *q) +{ + while(*p && *p == *q) + p++, q++; + return (uchar)*p - (uchar)*q; +} + +uint +strlen(const char *s) +{ + int n; + + for(n = 0; s[n]; n++) + ; + return n; +} + +void* +memset(void *dst, int c, uint n) +{ + char *cdst = (char *) dst; + int i; + for(i = 0; i < n; i++){ + cdst[i] = c; + } + return dst; +} + +char* +strchr(const char *s, char c) +{ + for(; *s; s++) + if(*s == c) + return (char*)s; + return 0; +} + +char* +gets(char *buf, int max) +{ + fgets(0, buf, max); + return buf; +} + +int +fgets(int fd, char *buf, int max) +{ + int i, cc; + char c; + + for(i=0; i+1 < max; ){ + cc = read(fd, &c, 1); + if(cc < 1) + break; + buf[i++] = c; + if(c == '\n' || c == '\r') + break; + } + buf[i] = '\0'; + return i; +} + +int +getline(char **lineptr, uint *n, int fd) +{ + if (*lineptr == 0 && *n == 0) { + *n = 128; + *lineptr = malloc(*n); + } + + char *buf = *lineptr; + uint total_read = 0; + while (1) { + int read_sz = fgets(fd, buf + total_read, *n - total_read); + if (read_sz == 0) { + return total_read; + } else if (read_sz == -1) { + // error + return -1; + } + + total_read += read_sz; + if (buf[total_read - 1] == '\n') { + break; + } + + uint new_n = *n * 2; + char *new_buf = malloc(new_n); + memcpy(new_buf, buf, *n); + free(buf); + + buf = new_buf; + + *n = new_n; + *lineptr = buf; + } + + return total_read; +} + + +int +stat(const char *n, struct stat *st) +{ + int fd; + int r; + + fd = open(n, O_RDONLY); + if(fd < 0) + return -1; + r = fstat(fd, st); + close(fd); + return r; +} + +int +atoi(const char *s) +{ + int n; + + n = 0; + while('0' <= *s && *s <= '9') + n = n*10 + *s++ - '0'; + return n; +} + +void* +memmove(void *vdst, const void *vsrc, int n) +{ + char *dst; + const char *src; + + dst = vdst; + src = vsrc; + if (src > dst) { + while(n-- > 0) + *dst++ = *src++; + } else { + dst += n; + src += n; + while(n-- > 0) + *--dst = *--src; + } + return vdst; +} + +int +memcmp(const void *s1, const void *s2, uint n) +{ + const char *p1 = s1, *p2 = s2; + while (n-- > 0) { + if (*p1 != *p2) { + return *p1 - *p2; + } + p1++; + p2++; + } + return 0; +} + +void * +memcpy(void *dst, const void *src, uint n) +{ + return memmove(dst, src, n); +} diff --git a/user/guy2.c b/user/guy2.c index 5e2eeea..8dcad9d 100644 --- a/user/guy2.c +++ b/user/guy2.c @@ -1,10 +1,10 @@ #include "kernel/types.h" -#include "kernel/stat.h" #include "user/user.h" #define RED "\033[31m" #define RESET "\033[0m" #define GREEN "\033[32m" + void clearScreen() { printf("\033[H\033[J"); } @@ -29,7 +29,7 @@ void printGuy(int pos) { void print_guy() { char *buffer = (char *)malloc(128*20); - +// char *buffer = (char *)malloc(1); strcpy(buffer, " O \n /|\\ \n / \\ \n\0"); printf(buffer); @@ -105,7 +105,7 @@ void print_guy_run(int pos) { } -void guy_color() { +void guy_mad() { printf("%s", RED); for (int i = 0; i < 15; i++) { clearScreen(); @@ -155,19 +155,3 @@ void guy_celebrate() { printf("%s", RESET); } - -int main (int argc, char *argv[]) { - - if (argc == 1) { - print_guy(); - } else if (strcmp(argv[1], "run") == 0) { - guy_run(); - } else if ((strcmp(argv[1], "gets") == 0) && (strcmp(argv[2], "mad") == 0)) { - guy_color(); - } else { - printf("Fail"); - } - - guy_celebrate(); - return 0; -} diff --git a/user/init.c b/user/init.c index 55d27d3..bf80399 100644 --- a/user/init.c +++ b/user/init.c @@ -32,6 +32,8 @@ main(void) printf(" U ||----w |\n"); printf(" || ||\n"); + guy_mad(); + for(;;){ printf("init: starting sh\n"); pid = fork(); @@ -51,7 +53,7 @@ main(void) wpid = wait((int *) 0); if(wpid == pid){ // the shell exited; restart it. - break; + break; } else if(wpid < 0){ printf("init: wait returned an error\n"); exit(1); diff --git a/user/user.h b/user/user.h index 5b550d4..021d072 100644 --- a/user/user.h +++ b/user/user.h @@ -42,3 +42,6 @@ void free(void*); int atoi(const char*); int memcmp(const void *, const void *, uint); void *memcpy(void *, const void *, uint); + +//guy2.c +void guy_mad(void); From da612da7e3091c13ecd13323a55b49379b059db1 Mon Sep 17 00:00:00 2001 From: Eva Grace DeThomas Date: Sun, 29 Sep 2024 23:30:55 -0700 Subject: [PATCH 14/24] Animation intro --- user/guy2.c | 27 +++++++++++++++++++++++++-- user/init.c | 11 +---------- user/user.h | 2 +- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/user/guy2.c b/user/guy2.c index 8dcad9d..eb624fe 100644 --- a/user/guy2.c +++ b/user/guy2.c @@ -121,6 +121,21 @@ void guy_mad() { printf("%s", RESET); } +void guy_move_head() { + for (int i = 0; i < 15; i++) { + clearScreen(); + if (i % 2 == 0) { + print_guy_L(); + } else { + print_guy_R(); + } + sleep_ms(10); + } + clearScreen(); + print_guy(); + printf("%s", RESET); +} + void guy_run() { @@ -136,7 +151,7 @@ void guy_run() { } } -void guy_celebrate() { +void guy_celebrate_intro() { clearScreen(); print_guy_U(); printf("%s", GREEN); @@ -150,7 +165,15 @@ void guy_celebrate() { sleep_ms(10); } clearScreen(); - printf(" YAY!\n"); + printf(" WELCOME TO FogOS !!\n"); + + sleep(2); + guy_run(); + printf("Type guy info to see more of me.\n"); + guy_move_head(); + + + print_guy(); printf("%s", RESET); diff --git a/user/init.c b/user/init.c index bf80399..956c579 100644 --- a/user/init.c +++ b/user/init.c @@ -23,16 +23,7 @@ main(void) dup(0); // stdout dup(0); // stderr - printf(" __________________\n"); - printf("< Welcome to FogOS >\n"); - printf(" ------------------\n"); - printf(" \\ ^__^\n"); - printf(" \\ (**)\\_______\n"); - printf(" (__)\\ )\\/\\\n"); - printf(" U ||----w |\n"); - printf(" || ||\n"); - - guy_mad(); + guy_celebrate_intro(); for(;;){ printf("init: starting sh\n"); diff --git a/user/user.h b/user/user.h index 021d072..14170be 100644 --- a/user/user.h +++ b/user/user.h @@ -44,4 +44,4 @@ int memcmp(const void *, const void *, uint); void *memcpy(void *, const void *, uint); //guy2.c -void guy_mad(void); +void guy_celebrate_intro(void); From f4e9add0d9ca314d1ecc46cff991094c88b3ba9c Mon Sep 17 00:00:00 2001 From: Eva Grace DeThomas Date: Sun, 29 Sep 2024 23:34:58 -0700 Subject: [PATCH 15/24] Intro done --- user/guy2.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/user/guy2.c b/user/guy2.c index eb624fe..bf38504 100644 --- a/user/guy2.c +++ b/user/guy2.c @@ -165,16 +165,10 @@ void guy_celebrate_intro() { sleep_ms(10); } clearScreen(); - printf(" WELCOME TO FogOS !!\n"); - - sleep(2); + sleep(1); guy_run(); - printf("Type guy info to see more of me.\n"); guy_move_head(); - - - - print_guy(); + printf("WELCOME TO FogOS !! Type guy info to see more of me.\n"); printf("%s", RESET); } From c6832f1d4b320f4b4ffb6109a7c3e01075692d21 Mon Sep 17 00:00:00 2001 From: Eva Grace DeThomas Date: Mon, 30 Sep 2024 00:09:13 -0700 Subject: [PATCH 16/24] Intro fixed, all functions are added --- Makefile | 1 + user/guy | 0 user/guy.c | 17 +++++++++++++++++ user/guy2.c | 39 +++++++++++++++++++-------------------- user/user.h | 12 ++++++++++++ 5 files changed, 49 insertions(+), 20 deletions(-) delete mode 100644 user/guy create mode 100644 user/guy.c diff --git a/Makefile b/Makefile index def8466..08117e8 100644 --- a/Makefile +++ b/Makefile @@ -120,6 +120,7 @@ UPROGS=\ $U/_echo\ $U/_forktest\ $U/_grep\ + $U/_guy\ $U/_init\ $U/_kill\ $U/_ln\ diff --git a/user/guy b/user/guy deleted file mode 100644 index e69de29..0000000 diff --git a/user/guy.c b/user/guy.c new file mode 100644 index 0000000..36aeeef --- /dev/null +++ b/user/guy.c @@ -0,0 +1,17 @@ +#include "user/user.h" +#include "kernel/types.h" + +int main (int argc, char *argv[]) { + if (argc == 1) { + print_guy(); + } else if (strcmp(argv[1], "run") == 0) { + guy_run(); + } else if ((strcmp(argv[1], "gets") == 0) && (strcmp(argv[2], "mad") == 0)) { + guy_mad(); + } else { + printf("Fail"); + } + + guy_celebrate(); + return 0; +} diff --git a/user/guy2.c b/user/guy2.c index bf38504..a30cbd9 100644 --- a/user/guy2.c +++ b/user/guy2.c @@ -1,5 +1,5 @@ -#include "kernel/types.h" #include "user/user.h" +#include "kernel/types.h" #define RED "\033[31m" #define RESET "\033[0m" #define GREEN "\033[32m" @@ -9,24 +9,6 @@ void clearScreen() { printf("\033[H\033[J"); } -void printGuy(int pos) { - for (int j = 0; j < pos; j++) { - printf(" "); - } - - printf(" O \n"); - - for (int j = 0; j < pos; j++) { - printf(" "); - } - printf(" /|\\ \n"); - - for (int j = 0; j < pos; j++) { - printf(" "); - } - printf(" / \\ \n"); -} - void print_guy() { char *buffer = (char *)malloc(128*20); // char *buffer = (char *)malloc(1); @@ -133,7 +115,6 @@ void guy_move_head() { } clearScreen(); print_guy(); - printf("%s", RESET); } @@ -151,6 +132,24 @@ void guy_run() { } } +void guy_celebrate() { + clearScreen(); + print_guy_U(); + printf("%s", GREEN); + for (int i = 0; i < 15; i++) { + clearScreen(); + if (i % 2 == 0) { + print_guy_U(); + } else { + print_guy(); + } + sleep_ms(10); + } + clearScreen(); + print_guy(); + printf("%s", RESET); +} + void guy_celebrate_intro() { clearScreen(); print_guy_U(); diff --git a/user/user.h b/user/user.h index 14170be..a9f6711 100644 --- a/user/user.h +++ b/user/user.h @@ -1,3 +1,4 @@ +#include "kernel/types.h" struct stat; // system calls @@ -45,3 +46,14 @@ void *memcpy(void *, const void *, uint); //guy2.c void guy_celebrate_intro(void); +void clearScreen(void); +void printGuy(int pos); +void print_guy(void); +void print_guy_U(void); +void print_guy_L(void); +void print_guy_R(void); +void print_guy_run(int pos); +void guy_mad(void); +void guy_move_head(void); +void guy_run(void); +void guy_celebrate(void); From 4e255a0ab181147be1bfe98092d10da930df3ccb Mon Sep 17 00:00:00 2001 From: Eva Grace DeThomas Date: Mon, 30 Sep 2024 00:40:37 -0700 Subject: [PATCH 17/24] More progress --- user/guy.c | 9 +++++---- user/guy2.c | 19 ++++++++++++++++++- user/ls.c | 2 ++ user/user.h | 1 + 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/user/guy.c b/user/guy.c index 36aeeef..47c720b 100644 --- a/user/guy.c +++ b/user/guy.c @@ -8,10 +8,11 @@ int main (int argc, char *argv[]) { guy_run(); } else if ((strcmp(argv[1], "gets") == 0) && (strcmp(argv[2], "mad") == 0)) { guy_mad(); + } else if (strcmp(argv[1], "info") == 0) { + guy_info(); } else { - printf("Fail"); - } - - guy_celebrate(); + guy_mad(); + printf("Mistyped, try again"); + } return 0; } diff --git a/user/guy2.c b/user/guy2.c index a30cbd9..094b1cd 100644 --- a/user/guy2.c +++ b/user/guy2.c @@ -150,6 +150,23 @@ void guy_celebrate() { printf("%s", RESET); } +void guy_info() { + print_guy(); + guy_celebrate(); + printf("%s", GREEN); + printf("I'm your OS buddy! As you interact with the OS, you can type \n\"guy celebrate\", \"guy gets mad\", or \"guy run\" \nas you get bored/frustrated.\nYou will also find me scattered across various functions in the OS that call on the \"guy\" library !!\nTry calling ls to see an example.\n"); + printf("%s", RESET); +} + +void print_message(char* mes) { + print_guy(); + printf(" ^"); + printf(" / \\n"); + printf(" | | \n"); + printf(" | | \n"); + printf("%s", mes); +} + void guy_celebrate_intro() { clearScreen(); print_guy_U(); @@ -167,7 +184,7 @@ void guy_celebrate_intro() { sleep(1); guy_run(); guy_move_head(); - printf("WELCOME TO FogOS !! Type guy info to see more of me.\n"); + printf("WELCOME TO FogOS !! Type \"guy info\" to see more of me.\n"); printf("%s", RESET); } diff --git a/user/ls.c b/user/ls.c index c67b84b..3173608 100644 --- a/user/ls.c +++ b/user/ls.c @@ -41,6 +41,8 @@ ls(char *path) return; } + guy_celebrate(); + switch(st.type){ case T_DEVICE: case T_FILE: diff --git a/user/user.h b/user/user.h index a9f6711..a3a6c04 100644 --- a/user/user.h +++ b/user/user.h @@ -57,3 +57,4 @@ void guy_mad(void); void guy_move_head(void); void guy_run(void); void guy_celebrate(void); +void guy_info(void); From ed939386d35196bfbfa86577946f6948e84cc01e Mon Sep 17 00:00:00 2001 From: Eva Grace DeThomas Date: Mon, 30 Sep 2024 01:05:10 -0700 Subject: [PATCH 18/24] Committing with functionality almost completegit add . --- user/guy2.c | 5 +++-- user/ls.c | 1 + user/user.h | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/user/guy2.c b/user/guy2.c index 094b1cd..3e57b3c 100644 --- a/user/guy2.c +++ b/user/guy2.c @@ -158,13 +158,14 @@ void guy_info() { printf("%s", RESET); } -void print_message(char* mes) { +void print_mes(char* str) { print_guy(); printf(" ^"); printf(" / \\n"); printf(" | | \n"); printf(" | | \n"); - printf("%s", mes); + printf("%s", str); + free(str); } void guy_celebrate_intro() { diff --git a/user/ls.c b/user/ls.c index 3173608..a32ee8d 100644 --- a/user/ls.c +++ b/user/ls.c @@ -42,6 +42,7 @@ ls(char *path) } guy_celebrate(); + printf("WOO! All the files!\n"); switch(st.type){ case T_DEVICE: diff --git a/user/user.h b/user/user.h index a3a6c04..8ed7be9 100644 --- a/user/user.h +++ b/user/user.h @@ -58,3 +58,4 @@ void guy_move_head(void); void guy_run(void); void guy_celebrate(void); void guy_info(void); +void guy_mes(char* str); From 855d73f603047c53399cdf1aa5e5933e5262ffc4 Mon Sep 17 00:00:00 2001 From: Eva Grace DeThomas Date: Mon, 30 Sep 2024 01:30:42 -0700 Subject: [PATCH 19/24] Committing full functionality --- user/guy.c | 1 - user/guy2.c | 2 ++ user/ls.c | 4 ++++ user/rm.c | 7 +++++++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/user/guy.c b/user/guy.c index 47c720b..2e099f4 100644 --- a/user/guy.c +++ b/user/guy.c @@ -11,7 +11,6 @@ int main (int argc, char *argv[]) { } else if (strcmp(argv[1], "info") == 0) { guy_info(); } else { - guy_mad(); printf("Mistyped, try again"); } return 0; diff --git a/user/guy2.c b/user/guy2.c index 3e57b3c..31fbdb0 100644 --- a/user/guy2.c +++ b/user/guy2.c @@ -100,6 +100,7 @@ void guy_mad() { } clearScreen(); print_guy(); + printf("RAHHHHHHHHHH!!"); printf("%s", RESET); } @@ -130,6 +131,7 @@ void guy_run() { print_guy_run(i); sleep_ms(10); } + printf("OS ROCKS!!\n"); } void guy_celebrate() { diff --git a/user/ls.c b/user/ls.c index a32ee8d..2645c34 100644 --- a/user/ls.c +++ b/user/ls.c @@ -2,6 +2,8 @@ #include "kernel/stat.h" #include "user/user.h" #include "kernel/fs.h" +#define RESET "\033[0m" +#define GREEN "\033[32m" char* fmtname(char *path) @@ -42,7 +44,9 @@ ls(char *path) } guy_celebrate(); + printf("%s", GREEN); printf("WOO! All the files!\n"); + printf("%s", RESET); switch(st.type){ case T_DEVICE: diff --git a/user/rm.c b/user/rm.c index 26b8f1f..8452869 100644 --- a/user/rm.c +++ b/user/rm.c @@ -1,6 +1,8 @@ #include "kernel/types.h" #include "kernel/stat.h" #include "user/user.h" +#define RED "\033[31m" +#define RESET "\033[0m" int main(int argc, char *argv[]) @@ -12,6 +14,11 @@ main(int argc, char *argv[]) exit(1); } + guy_mad(); + printf("%s", RED); + printf("REMOVE IT !!\n"); + printf("%s", RESET); + for(i = 1; i < argc; i++){ if(unlink(argv[i]) < 0){ fprintf(2, "rm: %s failed to delete\n", argv[i]); From 58e0cfc8b20672270707f30c6c319867ad83e0af Mon Sep 17 00:00:00 2001 From: Eva Grace DeThomas Date: Mon, 30 Sep 2024 09:55:03 -0700 Subject: [PATCH 20/24] Committing with everything printing nice --- user/guy.c | 2 ++ user/guy2.c | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/user/guy.c b/user/guy.c index 2e099f4..f39f3e1 100644 --- a/user/guy.c +++ b/user/guy.c @@ -10,6 +10,8 @@ int main (int argc, char *argv[]) { guy_mad(); } else if (strcmp(argv[1], "info") == 0) { guy_info(); + } else if (strcmp(argv[1], "celebrate") == 0) { + guy_celebrate(); } else { printf("Mistyped, try again"); } diff --git a/user/guy2.c b/user/guy2.c index 31fbdb0..c66038e 100644 --- a/user/guy2.c +++ b/user/guy2.c @@ -11,7 +11,6 @@ void clearScreen() { void print_guy() { char *buffer = (char *)malloc(128*20); -// char *buffer = (char *)malloc(1); strcpy(buffer, " O \n /|\\ \n / \\ \n\0"); printf(buffer); @@ -100,7 +99,7 @@ void guy_mad() { } clearScreen(); print_guy(); - printf("RAHHHHHHHHHH!!"); + printf("RAHHHHHHHHHH!!\n"); printf("%s", RESET); } From f7ba2fb20d6d807fc8e3b14ae4821490895cd29c Mon Sep 17 00:00:00 2001 From: Eva Grace DeThomas Date: Mon, 30 Sep 2024 10:03:39 -0700 Subject: [PATCH 21/24] Better formatted code --- user/guy2.c | 46 ++++++++++++++-------------------------------- user/user.h | 4 ++-- 2 files changed, 16 insertions(+), 34 deletions(-) diff --git a/user/guy2.c b/user/guy2.c index c66038e..516e881 100644 --- a/user/guy2.c +++ b/user/guy2.c @@ -5,79 +5,62 @@ #define GREEN "\033[32m" -void clearScreen() { +void clear_screen() { printf("\033[H\033[J"); } void print_guy() { char *buffer = (char *)malloc(128*20); strcpy(buffer, " O \n /|\\ \n / \\ \n\0"); - printf(buffer); - free(buffer); } void print_guy_U() { char *buffer = (char *)malloc(128*20); - strcpy(buffer, "\n O \n /|\\ \n / \\ \n\0"); - printf(buffer); - free(buffer); } void print_guy_L() { char *buffer = (char *)malloc(128*20); - strcpy(buffer, " O \n /|\\ \n / \\ \n\0"); - printf(buffer); - free(buffer); } void print_guy_R() { char *buffer = (char *)malloc(128*20); - strcpy(buffer, " O \n /|\\ \n / \\ \n\0"); - printf(buffer); - free(buffer); } void print_guy_run(int pos) { + //initializing final buffer and buffer for pos number of spaces char *buffer = (char *)malloc((pos*3 + 30)*sizeof(char)); char *spaces = (char *)malloc(pos*sizeof(char)); - + //Creating body for (int i = 0; i < pos; i++) { spaces[i] = ' '; } - - char *head = (char *)malloc(10 * sizeof(char)); strcpy(head, " O \n"); - memcpy(buffer, spaces, strlen(spaces) +1); memcpy(buffer + pos, head, strlen(head) + 1); memcpy(buffer + pos + strlen(head), spaces, strlen(spaces) + 1); - - char *torso = (char *)malloc(10 * sizeof(char)); strcpy(torso, " /|\\ \n"); - char *legs = (char *)malloc(10 * sizeof(char)); strcpy(legs, " / \\ \n"); - + //Coping body with pos number of spaces into buffer memcpy(buffer + (pos * 2) + strlen(head), torso, strlen(torso) + 1); memcpy(buffer + (pos * 2) + strlen(head) + strlen(torso), spaces, strlen(spaces) + 1); memcpy(buffer + (pos * 3) + strlen(head) + strlen(torso), legs, strlen(legs) + 1); - + //Freeing everything printf(buffer); - free(buffer); free(head); free(torso); @@ -97,7 +80,7 @@ void guy_mad() { } sleep_ms(10); } - clearScreen(); + clear_screen(); print_guy(); printf("RAHHHHHHHHHH!!\n"); printf("%s", RESET); @@ -105,7 +88,7 @@ void guy_mad() { void guy_move_head() { for (int i = 0; i < 15; i++) { - clearScreen(); + clear_screen(); if (i % 2 == 0) { print_guy_L(); } else { @@ -113,7 +96,7 @@ void guy_move_head() { } sleep_ms(10); } - clearScreen(); + clear_screen(); print_guy(); } @@ -121,12 +104,12 @@ void guy_move_head() { void guy_run() { for (int i = 0; i < 20; i++) { - clearScreen(); + clear_screen(); print_guy_run(i); sleep_ms(10); } for (int i = 20; i >0; i--) { - clearScreen(); + clear_screen(); print_guy_run(i); sleep_ms(10); } @@ -134,11 +117,11 @@ void guy_run() { } void guy_celebrate() { - clearScreen(); + clear_screen(); print_guy_U(); printf("%s", GREEN); for (int i = 0; i < 15; i++) { - clearScreen(); + clear_screen(); if (i % 2 == 0) { print_guy_U(); } else { @@ -146,7 +129,7 @@ void guy_celebrate() { } sleep_ms(10); } - clearScreen(); + clear_screen(); print_guy(); printf("%s", RESET); } @@ -182,11 +165,10 @@ void guy_celebrate_intro() { } sleep_ms(10); } - clearScreen(); + clear_screen(); sleep(1); guy_run(); guy_move_head(); printf("WELCOME TO FogOS !! Type \"guy info\" to see more of me.\n"); - printf("%s", RESET); } diff --git a/user/user.h b/user/user.h index 8ed7be9..31042ae 100644 --- a/user/user.h +++ b/user/user.h @@ -46,8 +46,8 @@ void *memcpy(void *, const void *, uint); //guy2.c void guy_celebrate_intro(void); -void clearScreen(void); -void printGuy(int pos); +void clear_screen(void); +void print_guy(int pos); void print_guy(void); void print_guy_U(void); void print_guy_L(void); From b07a42525fa59570ec27bb3e1a665456829a4289 Mon Sep 17 00:00:00 2001 From: Eva Grace DeThomas Date: Mon, 30 Sep 2024 14:17:41 -0700 Subject: [PATCH 22/24] Documentation --- docs/guy.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 docs/guy.md diff --git a/docs/guy.md b/docs/guy.md new file mode 100644 index 0000000..79275e4 --- /dev/null +++ b/docs/guy.md @@ -0,0 +1,15 @@ +Documentation for guy: + +For project01, I created a guy.c file that connects to a guy2.c file containing a graphics library for anyone to use. + +All of the functions within user.h under guy.c are available for use directly in any program that you would wish. + +When starting up FogOS, you will see the first animation of guy, and you can see more by typing guy.info. You can also use ls or rm to see more animations I added in to xv6. + +To create this guy library, I had to add a sleep_ms() system call to the kernel, which uses ceiling division to calculate the number of misk rotations in a milisecond, and in turn, sleep for +one milisecond. This is used within each animation, giving the code time to gather each image before printing it out. I also utilized a clear_screen() function, which works the same way as colors do for +this OS. + +The animations execute by running sleep, clear screen and print in a loop. If the CPU is struggling or already handling a lot, sleep_ms may lag some, resulting in a less pretty animation. + +To fix this, quit other applications on your machine. From f5ba642910e5e8641ddec65ef6159a3e839fd480 Mon Sep 17 00:00:00 2001 From: Eva Grace DeThomas Date: Mon, 30 Sep 2024 14:21:44 -0700 Subject: [PATCH 23/24] docs --- docs/guy.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/guy.md b/docs/guy.md index 79275e4..85274b8 100644 --- a/docs/guy.md +++ b/docs/guy.md @@ -13,3 +13,8 @@ this OS. The animations execute by running sleep, clear screen and print in a loop. If the CPU is struggling or already handling a lot, sleep_ms may lag some, resulting in a less pretty animation. To fix this, quit other applications on your machine. + +Challenges and road blocks in creating this: + +Reduced the lag in my animation by writing the entire thing to a buffer, then printing the buffer rather than running a few individual loops at once. See man_run() for an example of this. +Furhter, I really wanted the animation to work when a seg fault occurs, but this is pretty difficult since FogOS doesn't have signals yet. I spent around 2 hours troubleshooting possible ways to get this to work. Since a seg faulting is caught and handled in the hardware and kernel, having the usertrap() function communicate with the user space would take a lot of extra work. From cc0f9ed3eef2a0c81004355ee26a663e319c1ee0 Mon Sep 17 00:00:00 2001 From: Eva Grace DeThomas Date: Mon, 30 Sep 2024 14:33:29 -0700 Subject: [PATCH 24/24] Taking out unneccessary files --- kernel/guy2.c | 172 -------------------------------------------------- user/guy2.c | 6 +- user/user.h | 2 +- 3 files changed, 4 insertions(+), 176 deletions(-) delete mode 100644 kernel/guy2.c diff --git a/kernel/guy2.c b/kernel/guy2.c deleted file mode 100644 index b61e687..0000000 --- a/kernel/guy2.c +++ /dev/null @@ -1,172 +0,0 @@ -#include "kernel/types.h" -#include "ulib.c" -#define RED "\033[31m" -#define RESET "\033[0m" -#define GREEN "\033[32m" - -void clearScreen() { - printf("\033[H\033[J"); -} - -void printGuy(int pos) { - for (int j = 0; j < pos; j++) { - printf(" "); - } - - printf(" O \n"); - - for (int j = 0; j < pos; j++) { - printf(" "); - } - printf(" /|\\ \n"); - - for (int j = 0; j < pos; j++) { - printf(" "); - } - printf(" / \\ \n"); -} - -void print_guy() { - char *buffer = (char *)malloc(128*20); - - strcpy(buffer, " O \n /|\\ \n / \\ \n\0"); - - printf(buffer); - - free(buffer); -} - -void print_guy_U() { - char *buffer = (char *)malloc(128*20); - - strcpy(buffer, "\n O \n /|\\ \n / \\ \n\0"); - - printf(buffer); - - free(buffer); -} - -void print_guy_L() { - char *buffer = (char *)malloc(128*20); - - strcpy(buffer, " O \n /|\\ \n / \\ \n\0"); - - printf(buffer); - - free(buffer); -} - -void print_guy_R() { - char *buffer = (char *)malloc(128*20); - - strcpy(buffer, " O \n /|\\ \n / \\ \n\0"); - - printf(buffer); - - free(buffer); -} - - -void print_guy_run(int pos) { - char *buffer = (char *)malloc((pos*3 + 30)*sizeof(char)); - char *spaces = (char *)malloc(pos*sizeof(char)); - - for (int i = 0; i < pos; i++) { - spaces[i] = ' '; - } - - - char *head = (char *)malloc(10 * sizeof(char)); - strcpy(head, " O \n"); - - memcpy(buffer, spaces, strlen(spaces) +1); - memcpy(buffer + pos, head, strlen(head) + 1); - memcpy(buffer + pos + strlen(head), spaces, strlen(spaces) + 1); - - - char *torso = (char *)malloc(10 * sizeof(char)); - strcpy(torso, " /|\\ \n"); - - char *legs = (char *)malloc(10 * sizeof(char)); - strcpy(legs, " / \\ \n"); - - memcpy(buffer + (pos * 2) + strlen(head), torso, strlen(torso) + 1); - memcpy(buffer + (pos * 2) + strlen(head) + strlen(torso), spaces, strlen(spaces) + 1); - memcpy(buffer + (pos * 3) + strlen(head) + strlen(torso), legs, strlen(legs) + 1); - - printf(buffer); - - free(buffer); - free(head); - free(torso); - free(legs); - free(spaces); - -} - -void guy_color() { - printf("%s", RED); - for (int i = 0; i < 15; i++) { - clearScreen(); - if (i % 2 == 0) { - print_guy_L(); - } else { - print_guy_R(); - } - sleep_ms(10); - } - clearScreen(); - print_guy(); - printf("%s", RESET); -} - - - -void guy_run() { - for (int i = 0; i < 20; i++) { - clearScreen(); - print_guy_run(i); - sleep_ms(10); - } - for (int i = 20; i >0; i--) { - clearScreen(); - print_guy_run(i); - sleep_ms(10); - } -} - -void guy_celebrate() { - clearScreen(); - print_guy_U(); - printf("%s", GREEN); - for (int i = 0; i < 15; i++) { - clearScreen(); - if (i % 2 == 0) { - print_guy_U(); - } else { - print_guy(); - } - sleep_ms(10); - } - clearScreen(); - printf(" YAY!\n"); - print_guy(); - - printf("%s", RESET); -} - -int main (int argc, char *argv[]) { - - if (argc == 1) { - print_guy(); - } else if (strcmp(argv[1], "run") == 0) { - guy_run(); - } else if ((strcmp(argv[1], "gets") == 0) && (strcmp(argv[2], "mad") == 0)) { - guy_color(); - } else { - printf("Fail"); - } - - guy_celebrate(); - return 0; -} diff --git a/user/guy2.c b/user/guy2.c index 516e881..49418ce 100644 --- a/user/guy2.c +++ b/user/guy2.c @@ -72,7 +72,7 @@ void print_guy_run(int pos) { void guy_mad() { printf("%s", RED); for (int i = 0; i < 15; i++) { - clearScreen(); + clear_screen(); if (i % 2 == 0) { print_guy_L(); } else { @@ -153,11 +153,11 @@ void print_mes(char* str) { } void guy_celebrate_intro() { - clearScreen(); + clear_screen(); print_guy_U(); printf("%s", GREEN); for (int i = 0; i < 15; i++) { - clearScreen(); + clear_screen(); if (i % 2 == 0) { print_guy_U(); } else { diff --git a/user/user.h b/user/user.h index 31042ae..e5d1e1a 100644 --- a/user/user.h +++ b/user/user.h @@ -47,7 +47,7 @@ void *memcpy(void *, const void *, uint); //guy2.c void guy_celebrate_intro(void); void clear_screen(void); -void print_guy(int pos); +void print_guy(void); void print_guy(void); void print_guy_U(void); void print_guy_L(void);