GUI: Added terminal output window

This commit is contained in:
(Tim) Efthimis Kritikos 2024-02-13 21:28:42 +00:00
parent 966a0eee14
commit fe1bcfb471
3 changed files with 100 additions and 11 deletions

91
gui.c
View File

@ -35,6 +35,7 @@ WINDOW *general_memdump;
WINDOW *general_stack;
WINDOW *general_disas;
WINDOW *general_registers;
WINDOW *general_terminal_output;
int monochrome;
@ -60,6 +61,8 @@ int gui_ncurses_refresh(){
return 1;
if(wrefresh(general_registers)==ERR)
return 1;
if(wrefresh(general_terminal_output)==ERR)
return 1;
return 0;
}
@ -145,42 +148,52 @@ int start_gui(){
update_tabs();
int len;
int y1_divider;
int y1_divider,y2_divider;
int border=4;
if( (terminal_height-2*border)*0.2 < 8 )
if( (terminal_height-2*border-1)*0.2 < 8 )
y1_divider=terminal_height-border-8;
else if ( ( terminal_height - 2*border )*0.2 < 15 )
y1_divider=terminal_height-border-11;
else
y1_divider=(terminal_height-border*2)*0.8;
y2_divider=(3*(terminal_height-2*border-1)/4);
int x=border;
int middle;
general_memdump=newwin(y1_divider,terminal_width/2,x,border);
x+=terminal_width/2;
x++;
x+=3;
middle=x;
len=(terminal_width/6)>GENERAL_DISAS_WIDTH?GENERAL_DISAS_WIDTH:(terminal_width/6);
general_disas=newwin(y1_divider,len,4,x);
general_disas=newwin(y2_divider,len,4,x);
x+=len;
x+=3;
len=(terminal_width/6)>GENERAL_STACK_MAX_WIDTH?GENERAL_STACK_MAX_WIDTH:(terminal_width/6);
general_stack=newwin(y1_divider,len,4,x);
general_stack=newwin(y2_divider,len,4,x);
x+=len;
general_registers=newwin(terminal_height-y1_divider-border-1,terminal_width/2,y1_divider+border+1,border);
x+=terminal_width/2;
x++;
general_terminal_output=newwin(terminal_height-y2_divider-border-1,terminal_width/2-3*border,y2_divider+border+1,middle);
scrollok(general_terminal_output,TRUE);
x+=terminal_width/2;
x++;
if(gui_ncurses_refresh())
return 1;
return 0;
}
int gui_error(char *str){
WINDOW *error_win = newwin(3,40,terminal_height/2-1,terminal_width/2-20);
box(error_win, 0 , 0);
@ -197,7 +210,7 @@ int gui_error(char *str){
wattroff(error_win,COLOR_PAIR(1));
}
//// WARNING!! THIS ASSUMES THAT ADDRESS IS CORRECTLY ALIGNED!!
//// WARNING!! THIS ASSUMES THAT ADDRESS IS CORRECTLY ALIGNED WITH THE INSTRUCTION START/END!!
int select_instruction_color(struct simdata_t *simdata, WINDOW* window,uint32_t ADDRESS, int applyremove){
if(simdata->cpu_gui_hints){
struct instr_list_t* pointer;
@ -519,10 +532,66 @@ int update_general_registers(struct simdata_t *simdata){
}
}
}
if(height!=34242321)
return 0;
else
return 0;
return 0;
}
int term_curs_x,term_curs_y;
int update_general_terminal_output(struct simdata_t *simdata){
int width,height;
werase(general_terminal_output);
getmaxyx(general_terminal_output,height,width);
box(general_terminal_output, 0 , 0);
mvwprintw(general_terminal_output,0,width/2-7,"[ TERM OUTPUT ]");
term_curs_x=0;
term_curs_y=0;
for(uint64_t i=0;i < simdata->terminal_output_size;i++){
char c=simdata->terminal_output[i];
if(c>=' '&&c<='~'){
mvwprintw(general_terminal_output,term_curs_y+1,term_curs_x+1,"%c",c);
term_curs_x++;
if(term_curs_x>=width-2){
term_curs_x=0;
term_curs_y++;
}
if(term_curs_y>=height-2){
wscrl(general_terminal_output,1);
term_curs_y--;
for(int i=0;i<width;i++){
mvwprintw(general_terminal_output,term_curs_y+1,i," ");
}
box(general_terminal_output, 0 , 0);
mvwprintw(general_terminal_output,0,width/2-7,"[ TERM OUTPUT ]");
}
}else{
switch(c){
case 0x0a:
term_curs_x=0;
term_curs_y++;
if(term_curs_y>=height-2){
wscrl(general_terminal_output,1);
term_curs_y--;
for(int i=0;i<width;i++){
mvwprintw(general_terminal_output,term_curs_y+1,i," ");
}
box(general_terminal_output, 0 , 0);
mvwprintw(general_terminal_output,0,width/2-7,"[ TERM OUTPUT ]");
}
break;
default:
werase(general_terminal_output);
box(general_terminal_output, 0 , 0);
mvwprintw(general_terminal_output,0,width/2-7,"[ TERM OUTPUT ]");
mvwprintw(general_terminal_output,1,1,"Invalid output");
return 0;
}
}
}
mvwchgat(general_terminal_output,term_curs_y+1,term_curs_x+1, 1, A_REVERSE, 0, NULL);
return 0;
}
int clear_back_window=1;
@ -543,13 +612,15 @@ int update_gui(struct simdata_t *simdata){
return 1;
if(update_general_registers(simdata))
return 1;
if(update_general_terminal_output(simdata))
return 1;
if(gui_ncurses_refresh())
return 1;
return 0;
}
int gui_continue_request(struct simdata_t *simdata){
char inch;
int inch;
int release=0;
while(release==0){
if(((inch=getch())==ERR)){

View File

@ -42,10 +42,20 @@ struct simdata_t *init_simdata(){
ret->cpu_gui_hints->decoding_list=NULL;
ret->cpu_gui_hints->fetching_list=NULL;
ret->cpu_gui_hints->executing_list=NULL;
ret->terminal_output=malloc(0);
ret->terminal_output_size=0;
return ret;
}
int terminal_output(char c,struct simdata_t *simdata){
simdata->terminal_output=realloc(simdata->terminal_output,simdata->terminal_output_size+1);
if(!simdata->terminal_output)
return 1;
simdata->terminal_output[simdata->terminal_output_size]=c;
simdata->terminal_output_size++;
return 0;
}
void free_instr_list(struct instr_list_t **addr_of_tofree){
struct instr_list_t *tofree=*addr_of_tofree;
while(tofree){
@ -72,5 +82,6 @@ void free_simdata(struct simdata_t *p){
free_instr_list(&p->cpu_gui_hints->fetching_list);
free_instr_list(&p->cpu_gui_hints->executing_list);
free(p->cpu_gui_hints);
free(p->terminal_output);
free(p);
}

View File

@ -9,12 +9,18 @@ enum CPU_STATE_t{
struct simdata_t{
long unsigned int current_clock;
uint8_t *RAM;
struct fetch_data_t *fetch_data;
struct decode_data_t *decode_data;
struct exec_data_t *exec_data;
struct registers_t *registers;
enum CPU_STATE_t cpu_state;
struct cpu_gui_hints_t *cpu_gui_hints;
char* terminal_output;
uint64_t terminal_output_size;
};
struct instr_list_t{
@ -33,6 +39,7 @@ struct simdata_t *init_simdata();
void free_simdata(struct simdata_t *);
int add_to_instr_list(struct instr_list_t **addr_of_toadd,uint32_t address);
void free_instr_list(struct instr_list_t **addr_of_tofree);
int terminal_output(char c,struct simdata_t *simdata);
enum GUI_CPU_STATE_t{
GUI_CPU_RUNNING,