From 99c0af752b4959164c4fa98c61a98c4557ad7381 Mon Sep 17 00:00:00 2001 From: "(Tim) Efthimis Kritikos" Date: Sun, 24 Mar 2024 13:14:07 +0000 Subject: [PATCH] GUI: Moved the drawing code of the exec window in gui internals into a sepparate function so that i can easily draw the window multiple times --- gui_internals.c | 115 +++++++++++++++++++++++++++--------------------- 1 file changed, 65 insertions(+), 50 deletions(-) diff --git a/gui_internals.c b/gui_internals.c index 7484aff..bb2dac9 100644 --- a/gui_internals.c +++ b/gui_internals.c @@ -14,6 +14,68 @@ void drawbox(WINDOW *win,int x0, int y0, int x1, int y1){ mvwaddch(win,y1, x1, ACS_LRCORNER); } +struct box_ret_dimensions_t{ + int arrow1_y; +}; + +struct box_ret_dimensions_t* draw_exec(WINDOW *win, int startx,int starty,int endx,int endy,struct exec_data_t* exec_data){ + struct box_ret_dimensions_t* box_ret_dimensions=malloc(sizeof(struct box_ret_dimensions_t)); + if(!box_ret_dimensions) + return 0; + + wattron(win,A_BOLD); + int boxwidth=endx-startx; + drawbox(win,startx,starty,startx+50,endy); + mvwprintw(win,starty,startx+boxwidth/2-8,"[ EXECUTE UNIT ]"); + wattroff(win,A_BOLD); + starty+=2; + char *tofree; + + mvwprintw(win,starty,startx+boxwidth/2-41/2,"valid=%d EXEC_ACTION=%s",exec_data->valid, (tofree=EXEC_ACTION_t_to_string(exec_data->EXEC_ACTION)) ); + free(tofree); + starty+=2; + + mvwprintw(win,starty,startx+boxwidth/2-41/2,"ALU_OP=%s ", (tofree=ALU_OP_t_to_string(exec_data->ALU_OP)) ); + free(tofree); + mvwprintw(win,starty,startx+boxwidth/2-41/2+20,"cycles_left=%d ", exec_data->cycles_left ); + starty+=2; + + + mvwprintw(win,starty,startx+boxwidth/2-41/2,"COND=%s", (tofree=COND_t_to_string(exec_data->COND)) ); + free(tofree); + mvwprintw(win,starty,startx+boxwidth/2-41/2+20,"address=%06X", exec_data->address); + starty+=2; + + + // Operand boxes + struct exec_op_t *cur; + for(int i=0;i<3;i++){ + drawbox(win,startx+boxwidth/2-45/2,starty,startx+boxwidth/2-50/2+45,starty+3); + wattron(win,A_REVERSE); + switch(i){ + case 0: + mvwprintw(win,starty,startx+5," Input operand 1 "); + cur=exec_data->in_op1; + break; + case 1: + box_ret_dimensions->arrow1_y=starty; + mvwprintw(win,starty,startx+5," Input operand 2 "); + cur=exec_data->in_op2; + break; + case 2: + mvwprintw(win,starty,startx+5," Output operand "); + cur=exec_data->out_op; + break; + } + wattroff(win,A_REVERSE); + starty+=2; + mvwprintw(win,starty,startx+7,"data=%06X OP_ADDR=%s",cur->data , (tofree=OP_ADDR_t_to_string(cur->OP_ADDR)) ); + free(tofree); + starty+=2; + } + return box_ret_dimensions; +} + int update_internals(WINDOW *win,struct simdata_t *simdata){ int width,height; werase(win); @@ -94,55 +156,9 @@ int update_internals(WINDOW *win,struct simdata_t *simdata){ starty+=1; /* EXECUTE BOX */ - wattron(win,A_BOLD); - drawbox(win,startx+20+boxwidth/2-50/2,starty,startx+20+boxwidth/2-50/2+50,starty+21); - mvwprintw(win,starty,startx+20+boxwidth/2-8,"[ EXECUTE UNIT ]"); - wattroff(win,A_BOLD); - starty+=2; - char *tofree; - - mvwprintw(win,starty,startx+20+boxwidth/2-41/2,"valid=%d EXEC_ACTION=%s",simdata->exec_data->valid, (tofree=EXEC_ACTION_t_to_string(simdata->exec_data->EXEC_ACTION)) ); - free(tofree); - starty+=2; - - mvwprintw(win,starty,startx+20+boxwidth/2-41/2,"ALU_OP=%s ", (tofree=ALU_OP_t_to_string(simdata->exec_data->ALU_OP)) ); - free(tofree); - mvwprintw(win,starty,startx+20+boxwidth/2-41/2+20,"cycles_left=%d ", simdata->exec_data->cycles_left ); - starty+=2; - - - mvwprintw(win,starty,startx+20+boxwidth/2-41/2,"COND=%s", (tofree=COND_t_to_string(simdata->exec_data->COND)) ); - free(tofree); - mvwprintw(win,starty,startx+20+boxwidth/2-41/2+20,"address=%06X", simdata->exec_data->address); - starty+=2; - - - // Operand boxes - struct exec_op_t *cur; - for(int i=0;i<3;i++){ - drawbox(win,startx+20+boxwidth/2-45/2,starty,startx+20+boxwidth/2-50/2+45,starty+3); - wattron(win,A_REVERSE); - switch(i){ - case 0: - mvwprintw(win,starty,startx+20+5," Input operand 1 "); - cur=simdata->exec_data->in_op1; - break; - case 1: - exec_arrow_y=starty; - mvwprintw(win,starty,startx+20+5," Input operand 2 "); - cur=simdata->exec_data->in_op2; - break; - case 2: - mvwprintw(win,starty,startx+20+5," Output operand "); - cur=simdata->exec_data->out_op; - break; - } - wattroff(win,A_REVERSE); - starty+=2; - mvwprintw(win,starty,startx+20+7,"data=%06X OP_ADDR=%s",cur->data , (tofree=OP_ADDR_t_to_string(cur->OP_ADDR)) ); - free(tofree); - starty+=2; - } + struct box_ret_dimensions_t* box_ret_dimensions=draw_exec(win,startx+20+boxwidth/2-50/2,starty,startx+20+boxwidth/2-50/2+50,starty+21,simdata->exec_data); + exec_arrow_y=box_ret_dimensions->arrow1_y; + free(box_ret_dimensions); /* Wait for exec arrow */ mvwaddch(win,decode_arrow_exit_y,startx+20+50,ACS_LTEE); @@ -205,4 +221,3 @@ int update_internals(WINDOW *win,struct simdata_t *simdata){ else return 0; } -