commit f2ce6fc09d05f6a654712c0a5ef3be59f6f711af Author: (Tim) Efthimis Kritikos Date: Mon Jan 22 12:11:07 2024 +0000 Initial commit: created project skeleton diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fb596ee --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.o +first diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1bb8525 --- /dev/null +++ b/Makefile @@ -0,0 +1,11 @@ +all:first + +first:gui.o main.o simdata.o + gcc $^ -fsanitize=address -lncurses -ltinfo -o $@ + +%.o:%.c + gcc -c $< -Wall -Wextra -Werror -fsanitize=address + +.PHONY: clean +clean: + rm -f gui.o main.o simdata.o diff --git a/README.md b/README.md new file mode 100644 index 0000000..31c07e0 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ + +First - A simple computer architecture simulator for COMS30046 diff --git a/gui.c b/gui.c new file mode 100644 index 0000000..e1daed0 --- /dev/null +++ b/gui.c @@ -0,0 +1,50 @@ +#include + +int terminal_width; +int terminal_height; + +WINDOW *tabs; + +int get_terminal_size(){ + int new_height,new_width; + getmaxyx(stdscr,new_height,new_width); + int changed=(new_width!=terminal_width)||(new_height!=terminal_height); + terminal_width=new_width; + terminal_height=new_height; + return changed; +} + +int gui_ncurses_refresh(){ + if(refresh()==ERR) + return 1; + if(wrefresh(tabs)==ERR) + return 1; + return 0; +} + +int start_gui(){ + if(!initscr()) + return 1; + curs_set(0); + get_terminal_size(); + mvprintw((terminal_height-3)/2+3,terminal_width/2-15,"Initialising the simulator..."); + tabs = newwin(3,terminal_width,0,0); + box(tabs, 0 , 0); + mvwprintw(tabs,1,2,"[ 0 Overview ]"); + mvwprintw(tabs,1,17," 1 Memory "); + if(gui_ncurses_refresh()) + return 1; + return 0; +} + +int gui_continue_request(){ + if(getch()==ERR) + return 1; + return 0; +} + +int end_gui(){ + if(endwin()==ERR) + return 1; + return 0; +} diff --git a/gui.h b/gui.h new file mode 100644 index 0000000..75b71ab --- /dev/null +++ b/gui.h @@ -0,0 +1,3 @@ +int start_gui(); +int gui_continue_request(); +int end_gui(); diff --git a/main.c b/main.c new file mode 100644 index 0000000..9d97055 --- /dev/null +++ b/main.c @@ -0,0 +1,30 @@ +#include +#include "gui.h" +#include "simdata.h" + +int main(){ + struct simdata_t *simdata = init_simdata(); + if(!simdata){ + printf("failed to initialise simdata"); + return 1; + } + if(start_gui()){ + printf("Failed on start_gui()\n"); + free_simdata(simdata); + return 1; + } + if(gui_continue_request()){ + printf("Failed on gui_continue_request()\n"); + free_simdata(simdata); + return 1; + } + + if(end_gui()){ + printf("Failed on end_gui()\n"); + free_simdata(simdata); + return 1; + } + + free_simdata(simdata); + return 0; +} diff --git a/simdata.c b/simdata.c new file mode 100644 index 0000000..6e6d71b --- /dev/null +++ b/simdata.c @@ -0,0 +1,14 @@ +#include +#include "simdata.h" + +struct simdata_t *init_simdata(){ + struct simdata_t * ret=malloc(sizeof(struct simdata_t)); + if(ret){ + ret->current_clock=0; + } + return ret; +} + +void free_simdata(struct simdata_t *p){ + free(p); +} diff --git a/simdata.h b/simdata.h new file mode 100644 index 0000000..c6e15ae --- /dev/null +++ b/simdata.h @@ -0,0 +1,6 @@ +struct simdata_t{ + long unsigned int current_clock; +}; +struct simdata_t *init_simdata(); + +void free_simdata(struct simdata_t *);