2024-03-05 00:49:40 +00:00
|
|
|
#include <ncurses.h>
|
|
|
|
#include "simdata.h"
|
|
|
|
#include "cpu.h"
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
void drawbox(WINDOW *win,int x0, int y0, int x1, int y1){
|
|
|
|
mvwhline(win,y0, x0, 0, x1-x0);
|
|
|
|
mvwhline(win,y1, x0, 0, x1-x0);
|
|
|
|
mvwvline(win,y0, x0, 0, y1-y0);
|
|
|
|
mvwvline(win,y0, x1, 0, y1-y0);
|
|
|
|
mvwaddch(win,y0, x0, ACS_ULCORNER);
|
|
|
|
mvwaddch(win,y1, x0, ACS_LLCORNER);
|
|
|
|
mvwaddch(win,y0, x1, ACS_URCORNER);
|
|
|
|
mvwaddch(win,y1, x1, ACS_LRCORNER);
|
|
|
|
}
|
|
|
|
|
|
|
|
int update_internals(WINDOW *win,struct simdata_t *simdata){
|
|
|
|
int width,height;
|
|
|
|
werase(win);
|
|
|
|
getmaxyx(win,height,width);
|
|
|
|
box(win, 0 , 0);
|
|
|
|
|
|
|
|
mvwprintw(win,0,width/2-6,"[ INTERNALS ]");
|
|
|
|
|
|
|
|
if(simdata->registers==NULL||simdata->exec_data==NULL){
|
|
|
|
mvwprintw(win,1,1,"Data not initialised");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int graph_height,graph_width;
|
|
|
|
switch(simdata->cpu_structure){
|
|
|
|
case CPU_STRUCTURE_SIMPLE_PIPELINED:
|
|
|
|
graph_height=42;
|
2024-03-06 02:37:55 +00:00
|
|
|
graph_width=82;
|
2024-03-05 00:49:40 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
graph_height=1;
|
|
|
|
graph_height=41;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
int starty,startx,boxwidth;
|
|
|
|
starty=height/2-graph_height/2;
|
|
|
|
startx=width/2-graph_width/2;
|
|
|
|
|
|
|
|
switch(simdata->cpu_structure){
|
|
|
|
case CPU_STRUCTURE_SIMPLE_PIPELINED:
|
|
|
|
int fetch_arrow_enter_y;
|
|
|
|
int decode_arrow_exit_y;
|
2024-03-06 02:37:55 +00:00
|
|
|
int exec_arrow_y;
|
2024-03-05 00:49:40 +00:00
|
|
|
boxwidth=50;
|
|
|
|
|
|
|
|
/* FETCH BOX */
|
2024-03-06 02:37:55 +00:00
|
|
|
drawbox(win,startx+20+boxwidth/2-50/2,starty,startx+20+boxwidth/2-50/2+50,starty+6);
|
|
|
|
mvwprintw(win,starty,startx+20+boxwidth/2-4,"[ FETCH ]");
|
2024-03-05 00:49:40 +00:00
|
|
|
starty+=2;
|
2024-03-06 02:37:55 +00:00
|
|
|
mvwprintw(win,starty,startx+20+boxwidth/2-27/2,"wait_for_exec=%d exec_done=%d",simdata->fetch_data->wait_for_exec,simdata->fetch_data->exec_done);
|
|
|
|
starty+=2;
|
|
|
|
mvwprintw(win,starty,startx+20+boxwidth/2-26/2,"fetch_wait=%d decode_done=%d",simdata->fetch_data->fetch_wait,simdata->fetch_data->decode_done);
|
2024-03-05 00:49:40 +00:00
|
|
|
fetch_arrow_enter_y=starty;
|
|
|
|
starty+=2;
|
|
|
|
|
|
|
|
/* -------> */
|
2024-03-06 02:37:55 +00:00
|
|
|
mvwaddch(win,starty,startx+20+boxwidth/2,ACS_TTEE);
|
2024-03-05 00:49:40 +00:00
|
|
|
starty++;
|
2024-03-06 02:37:55 +00:00
|
|
|
mvwvline(win,starty,startx+20+boxwidth/2, 0, 2);
|
2024-03-05 00:49:40 +00:00
|
|
|
starty+=2;
|
2024-03-06 02:37:55 +00:00
|
|
|
mvwaddch(win,starty,startx+20+boxwidth/2,'V');
|
2024-03-05 00:49:40 +00:00
|
|
|
starty+=1;
|
|
|
|
|
|
|
|
starty+=1;
|
|
|
|
|
|
|
|
/* DECODE BOX */
|
2024-03-06 02:37:55 +00:00
|
|
|
drawbox(win,startx+20+boxwidth/2-50/2,starty,startx+20+boxwidth/2-50/2+50,starty+6);
|
|
|
|
mvwprintw(win,starty,startx+20+boxwidth/2-5,"[ DECODE ]");
|
2024-03-05 00:49:40 +00:00
|
|
|
starty+=2;
|
2024-03-06 02:37:55 +00:00
|
|
|
mvwprintw(win,starty,startx+20+boxwidth/2-19/2,"valid=%d exec_done=%d",simdata->decode_data->valid,simdata->decode_data->exec_done);
|
2024-03-05 00:49:40 +00:00
|
|
|
decode_arrow_exit_y=starty;
|
|
|
|
starty+=2;
|
2024-03-06 02:37:55 +00:00
|
|
|
mvwprintw(win,starty,startx+20+boxwidth/2-41/2,"in_bytecode=0x%08X address=0x%06X",simdata->decode_data->in_bytecode,simdata->decode_data->address);
|
2024-03-05 00:49:40 +00:00
|
|
|
starty+=2;
|
|
|
|
|
|
|
|
/* -------> */
|
2024-03-06 02:37:55 +00:00
|
|
|
mvwaddch(win,starty,startx+20+boxwidth/2,ACS_TTEE);
|
2024-03-05 00:49:40 +00:00
|
|
|
starty++;
|
2024-03-06 02:37:55 +00:00
|
|
|
mvwvline(win,starty,startx+20+boxwidth/2, 0, 2);
|
2024-03-05 00:49:40 +00:00
|
|
|
starty+=2;
|
2024-03-06 02:37:55 +00:00
|
|
|
mvwaddch(win,starty,startx+20+boxwidth/2,'V');
|
2024-03-05 00:49:40 +00:00
|
|
|
starty+=1;
|
|
|
|
|
|
|
|
starty+=1;
|
|
|
|
|
|
|
|
/* EXECUTE BOX */
|
2024-03-06 02:37:55 +00:00
|
|
|
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 ]");
|
2024-03-05 00:49:40 +00:00
|
|
|
starty+=2;
|
|
|
|
char *tofree;
|
|
|
|
|
2024-03-06 02:37:55 +00:00
|
|
|
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)) );
|
2024-03-05 00:49:40 +00:00
|
|
|
free(tofree);
|
|
|
|
starty+=2;
|
|
|
|
|
2024-03-06 02:37:55 +00:00
|
|
|
mvwprintw(win,starty,startx+20+boxwidth/2-41/2,"ALU_OP=%s ", (tofree=ALU_OP_t_to_string(simdata->exec_data->ALU_OP)) );
|
2024-03-05 00:49:40 +00:00
|
|
|
free(tofree);
|
2024-03-06 02:37:55 +00:00
|
|
|
mvwprintw(win,starty,startx+20+boxwidth/2-41/2+20,"cycles_left=%d ", simdata->exec_data->cycles_left );
|
2024-03-05 00:49:40 +00:00
|
|
|
starty+=2;
|
|
|
|
|
2024-03-06 02:37:55 +00:00
|
|
|
|
|
|
|
mvwprintw(win,starty,startx+20+boxwidth/2-41/2,"COND=%s", (tofree=COND_t_to_string(simdata->exec_data->COND)) );
|
2024-03-05 00:49:40 +00:00
|
|
|
free(tofree);
|
2024-03-06 02:37:55 +00:00
|
|
|
mvwprintw(win,starty,startx+20+boxwidth/2-41/2+20,"address=%06X", simdata->exec_data->address);
|
2024-03-05 00:49:40 +00:00
|
|
|
starty+=2;
|
|
|
|
|
2024-03-06 02:37:55 +00:00
|
|
|
|
2024-03-05 00:49:40 +00:00
|
|
|
// Operand boxes
|
|
|
|
struct exec_op_t *cur;
|
|
|
|
for(int i=0;i<3;i++){
|
2024-03-06 02:37:55 +00:00
|
|
|
drawbox(win,startx+20+boxwidth/2-45/2,starty,startx+20+boxwidth/2-50/2+45,starty+3);
|
2024-03-05 00:49:40 +00:00
|
|
|
wattron(win,A_REVERSE);
|
|
|
|
switch(i){
|
|
|
|
case 0:
|
2024-03-06 02:37:55 +00:00
|
|
|
mvwprintw(win,starty,startx+20+5," Input operand 1 ");
|
2024-03-05 00:49:40 +00:00
|
|
|
cur=simdata->exec_data->in_op1;
|
|
|
|
break;
|
|
|
|
case 1:
|
2024-03-06 02:37:55 +00:00
|
|
|
exec_arrow_y=starty;
|
|
|
|
mvwprintw(win,starty,startx+20+5," Input operand 2 ");
|
2024-03-05 00:49:40 +00:00
|
|
|
cur=simdata->exec_data->in_op2;
|
|
|
|
break;
|
|
|
|
case 2:
|
2024-03-06 02:37:55 +00:00
|
|
|
mvwprintw(win,starty,startx+20+5," Output operand ");
|
2024-03-05 00:49:40 +00:00
|
|
|
cur=simdata->exec_data->out_op;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
wattroff(win,A_REVERSE);
|
|
|
|
starty+=2;
|
2024-03-06 02:37:55 +00:00
|
|
|
mvwprintw(win,starty,startx+20+7,"data=%06X OP_ADDR=%s",cur->data , (tofree=OP_ADDR_t_to_string(cur->OP_ADDR)) );
|
2024-03-05 00:49:40 +00:00
|
|
|
free(tofree);
|
|
|
|
starty+=2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Wait for exec arrow */
|
2024-03-06 02:37:55 +00:00
|
|
|
mvwaddch(win,decode_arrow_exit_y,startx+20+50,ACS_LTEE);
|
|
|
|
mvwhline(win,decode_arrow_exit_y,startx+20+51, 0, 3);
|
|
|
|
mvwaddch(win,decode_arrow_exit_y,startx+20+54,ACS_LRCORNER);
|
|
|
|
mvwvline(win,fetch_arrow_enter_y+1,startx+20+54, 0,decode_arrow_exit_y-fetch_arrow_enter_y-1);
|
|
|
|
mvwaddch(win,fetch_arrow_enter_y,startx+20+54,ACS_URCORNER);
|
|
|
|
mvwhline(win,fetch_arrow_enter_y,startx+20+53, 0, 1);
|
|
|
|
mvwaddch(win,fetch_arrow_enter_y,startx+20+52,'<');
|
|
|
|
mvwprintw(win,fetch_arrow_enter_y+(decode_arrow_exit_y-fetch_arrow_enter_y-1)/2-1,startx+20+55,"Wait");
|
|
|
|
mvwprintw(win,fetch_arrow_enter_y+(decode_arrow_exit_y-fetch_arrow_enter_y-1)/2 ,startx+20+55,"For");
|
|
|
|
mvwprintw(win,fetch_arrow_enter_y+(decode_arrow_exit_y-fetch_arrow_enter_y-1)/2+1,startx+20+55,"Exec");
|
|
|
|
|
|
|
|
/* Decode done arrow */
|
|
|
|
mvwaddch(win,decode_arrow_exit_y,startx+20,ACS_RTEE);
|
|
|
|
mvwhline(win,decode_arrow_exit_y,startx+17, 0, 3);
|
|
|
|
mvwaddch(win,decode_arrow_exit_y,startx+16,ACS_LLCORNER);
|
|
|
|
mvwvline(win,fetch_arrow_enter_y+1,startx+16, 0,decode_arrow_exit_y-fetch_arrow_enter_y-1);
|
|
|
|
mvwaddch(win,fetch_arrow_enter_y,startx+16,ACS_ULCORNER);
|
|
|
|
mvwhline(win,fetch_arrow_enter_y,startx+17, 0, 1);
|
|
|
|
mvwaddch(win,fetch_arrow_enter_y,startx+18,'>');
|
|
|
|
mvwprintw(win,fetch_arrow_enter_y+(decode_arrow_exit_y-fetch_arrow_enter_y-1)/2 ,startx+10,"Decode");
|
|
|
|
mvwprintw(win,fetch_arrow_enter_y+(decode_arrow_exit_y-fetch_arrow_enter_y-1)/2+1,startx+12,"Done");
|
|
|
|
|
|
|
|
decode_arrow_exit_y+=2;//a bit of a hack i know
|
|
|
|
|
|
|
|
/* Exec done (decode) arrow */
|
|
|
|
mvwaddch(win,exec_arrow_y,startx+20,ACS_RTEE);
|
|
|
|
mvwhline(win,exec_arrow_y,startx+17, 0, 3);
|
|
|
|
mvwaddch(win,exec_arrow_y,startx+16,ACS_LLCORNER);
|
|
|
|
mvwvline(win,decode_arrow_exit_y+1,startx+16, 0,exec_arrow_y-decode_arrow_exit_y-1);
|
|
|
|
mvwaddch(win,decode_arrow_exit_y,startx+16,ACS_ULCORNER);
|
|
|
|
mvwhline(win,decode_arrow_exit_y,startx+17, 0, 1);
|
|
|
|
mvwaddch(win,decode_arrow_exit_y,startx+18,'>');
|
|
|
|
mvwprintw(win,decode_arrow_exit_y+(exec_arrow_y-decode_arrow_exit_y-1)/2 ,startx+12,"Exec");
|
|
|
|
mvwprintw(win,decode_arrow_exit_y+(exec_arrow_y-decode_arrow_exit_y-1)/2+1,startx+12,"Done");
|
|
|
|
|
|
|
|
fetch_arrow_enter_y-=2;//a bit of a hack i know
|
|
|
|
exec_arrow_y+=3;
|
|
|
|
|
|
|
|
/* Exec done (fetch) arrow */
|
|
|
|
mvwaddch(win,exec_arrow_y,startx+20,ACS_RTEE);
|
|
|
|
mvwhline(win,exec_arrow_y,startx+9, 0, 11);
|
|
|
|
mvwaddch(win,exec_arrow_y,startx+8,ACS_LLCORNER);
|
|
|
|
mvwvline(win,fetch_arrow_enter_y+1,startx+8, 0,exec_arrow_y-fetch_arrow_enter_y-1);
|
|
|
|
mvwaddch(win,fetch_arrow_enter_y,startx+8,ACS_ULCORNER);
|
|
|
|
mvwhline(win,fetch_arrow_enter_y,startx+9, 0, 9);
|
|
|
|
mvwaddch(win,fetch_arrow_enter_y,startx+18,'>');
|
|
|
|
mvwprintw(win,fetch_arrow_enter_y+(exec_arrow_y-fetch_arrow_enter_y-1)/2 ,startx+4,"Exec");
|
|
|
|
mvwprintw(win,fetch_arrow_enter_y+(exec_arrow_y-fetch_arrow_enter_y-1)/2+1,startx+4,"Done");
|
2024-03-05 00:49:40 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
mvwprintw(win,starty,startx,"No graph available for this cpu structure");
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(height==3)
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|