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

This commit is contained in:
(Tim) Efthimis Kritikos 2024-03-24 13:14:07 +00:00
parent 3f4b03c307
commit 99c0af752b

View File

@ -14,6 +14,68 @@ void drawbox(WINDOW *win,int x0, int y0, int x1, int y1){
mvwaddch(win,y1, x1, ACS_LRCORNER); 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 update_internals(WINDOW *win,struct simdata_t *simdata){
int width,height; int width,height;
werase(win); werase(win);
@ -94,55 +156,9 @@ int update_internals(WINDOW *win,struct simdata_t *simdata){
starty+=1; starty+=1;
/* EXECUTE BOX */ /* EXECUTE BOX */
wattron(win,A_BOLD); 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);
drawbox(win,startx+20+boxwidth/2-50/2,starty,startx+20+boxwidth/2-50/2+50,starty+21); exec_arrow_y=box_ret_dimensions->arrow1_y;
mvwprintw(win,starty,startx+20+boxwidth/2-8,"[ EXECUTE UNIT ]"); free(box_ret_dimensions);
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;
}
/* Wait for exec arrow */ /* Wait for exec arrow */
mvwaddch(win,decode_arrow_exit_y,startx+20+50,ACS_LTEE); 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 else
return 0; return 0;
} }