Initial commit: created project skeleton

This commit is contained in:
(Tim) Efthimis Kritikos 2024-01-22 12:11:07 +00:00
commit f2ce6fc09d
8 changed files with 118 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*.o
first

11
Makefile Normal file
View File

@ -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

2
README.md Normal file
View File

@ -0,0 +1,2 @@
First - A simple computer architecture simulator for COMS30046

50
gui.c Normal file
View File

@ -0,0 +1,50 @@
#include <ncurses.h>
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;
}

3
gui.h Normal file
View File

@ -0,0 +1,3 @@
int start_gui();
int gui_continue_request();
int end_gui();

30
main.c Normal file
View File

@ -0,0 +1,30 @@
#include <stdio.h>
#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;
}

14
simdata.c Normal file
View File

@ -0,0 +1,14 @@
#include <stdlib.h>
#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);
}

6
simdata.h Normal file
View File

@ -0,0 +1,6 @@
struct simdata_t{
long unsigned int current_clock;
};
struct simdata_t *init_simdata();
void free_simdata(struct simdata_t *);