GUI: Added support for registers in the gui

This commit is contained in:
(Tim) Efthimis Kritikos 2024-02-05 21:25:00 +00:00
parent 1f3f26d91e
commit e5705a8477
5 changed files with 101 additions and 4 deletions

2
cpu.c
View File

@ -123,6 +123,7 @@ int cpu_simdata_malloc(struct simdata_t *simdata){
simdata->fetch_data=malloc_fetch_data(); simdata->fetch_data=malloc_fetch_data();
simdata->decode_data=malloc_decode_data(); simdata->decode_data=malloc_decode_data();
simdata->exec_data=malloc_exec_data(); simdata->exec_data=malloc_exec_data();
simdata->registers=malloc(sizeof(struct registers_t));
if((simdata->fetch_data!=NULL)&&(simdata->decode_data!=NULL)&&(simdata->exec_data!=NULL)) if((simdata->fetch_data!=NULL)&&(simdata->decode_data!=NULL)&&(simdata->exec_data!=NULL))
return 1; return 1;
else else
@ -133,4 +134,5 @@ void cpu_simdata_free(struct simdata_t *simdata){
free_fetch_data(simdata->fetch_data); free_fetch_data(simdata->fetch_data);
free_decode_data(simdata->decode_data); free_decode_data(simdata->decode_data);
free_exec_data(simdata->exec_data); free_exec_data(simdata->exec_data);
free(simdata->registers);
} }

14
cpu.h
View File

@ -50,5 +50,19 @@ void cpu_simdata_free(struct simdata_t *simdata);
int cpu_simdata_malloc(struct simdata_t *simdata); int cpu_simdata_malloc(struct simdata_t *simdata);
int cpu_cycle_clock(struct simdata_t *simdata); int cpu_cycle_clock(struct simdata_t *simdata);
// +===================+
// | BIT | USAGE |
// |-----+-------------|
// | 0 | ZERO |
// |-----+-------------|
// | 1 | CARRY |
// |-----+-------------|
// | 2 | SIGN |
//
struct registers_t{
uint32_t GPR[8];
uint32_t FLAGS;
};
#endif #endif
#define CPU_HEADER #define CPU_HEADER

87
gui.c
View File

@ -22,6 +22,7 @@
#include "simdata.h" #include "simdata.h"
#include "assembly.h" #include "assembly.h"
#include <stdlib.h> #include <stdlib.h>
#include "cpu.h"
#define GENERAL_STACK_MAX_WIDTH 16 #define GENERAL_STACK_MAX_WIDTH 16
#define GENERAL_DISAS_WIDTH 41 #define GENERAL_DISAS_WIDTH 41
@ -33,6 +34,7 @@ WINDOW *tabs;
WINDOW *general_memdump; WINDOW *general_memdump;
WINDOW *general_stack; WINDOW *general_stack;
WINDOW *general_disas; WINDOW *general_disas;
WINDOW *general_registers;
int monochrome; int monochrome;
@ -56,6 +58,8 @@ int gui_ncurses_refresh(){
return 1; return 1;
if(wrefresh(general_disas)==ERR) if(wrefresh(general_disas)==ERR)
return 1; return 1;
if(wrefresh(general_registers)==ERR)
return 1;
return 0; return 0;
} }
@ -132,21 +136,38 @@ int start_gui(){
tabs = newwin(1,terminal_width,0,0); tabs = newwin(1,terminal_width,0,0);
update_tabs(); update_tabs();
int len; int len;
int x=4;
general_memdump=newwin(terminal_height*0.8,terminal_width/2,x,5); int y1_divider;
int border=4;
if( (terminal_height-2*border)*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;
int x=border;
general_memdump=newwin(y1_divider,terminal_width/2,x,border);
x+=terminal_width/2; x+=terminal_width/2;
x++; x++;
x+=3; x+=3;
len=(terminal_width/6)>GENERAL_DISAS_WIDTH?GENERAL_DISAS_WIDTH:(terminal_width/6); len=(terminal_width/6)>GENERAL_DISAS_WIDTH?GENERAL_DISAS_WIDTH:(terminal_width/6);
general_disas=newwin(terminal_height*0.8,len,4,x); general_disas=newwin(y1_divider,len,4,x);
x+=len; x+=len;
x+=3; x+=3;
len=(terminal_width/6)>GENERAL_STACK_MAX_WIDTH?GENERAL_STACK_MAX_WIDTH:(terminal_width/6); len=(terminal_width/6)>GENERAL_STACK_MAX_WIDTH?GENERAL_STACK_MAX_WIDTH:(terminal_width/6);
general_stack=newwin(terminal_height*0.8,len,4,x); general_stack=newwin(y1_divider,len,4,x);
x+=len; x+=len;
general_registers=newwin(terminal_height-y1_divider-border-1,terminal_width/2,y1_divider+border+1,border);
x+=terminal_width/2;
x++;
if(gui_ncurses_refresh()) if(gui_ncurses_refresh())
return 1; return 1;
return 0; return 0;
@ -313,6 +334,62 @@ int update_general_memdump(struct simdata_t *simdata){
return 0; return 0;
} }
int update_general_registers(struct simdata_t *simdata){
int width,height;
getmaxyx(general_registers,height,width);
box(general_registers, 0 , 0);
mvwprintw(general_registers,0,terminal_width/4-7,"[ REGISTERS ]");
if(simdata->registers==NULL)
mvwprintw(general_registers,1,1,"Registers data structure not initialised");
else{
int per_line=width/35;
if(per_line==0)
mvwprintw(general_registers,1,1,"too small window");
else{
int center_x_offset=((width-2)-35*per_line)/2;
int lines_used=(8/(int)per_line<8/(float)per_line)?8/per_line+1:8/per_line;
int center_y_offset=((height-2)-(lines_used+2))/2;
if((lines_used+2)>(height-2)||width<37)
mvwprintw(general_registers,1,1,"too small window");
else{
int n=0,y=0;
while(y!=lines_used){
for(int i=0;i<per_line;i++){
if(n<8){
mvwprintw(general_registers,1+y+center_y_offset,1+i*35+center_x_offset,"R%d: %08X (%lf) ",n,simdata->registers->GPR[n],(double)simdata->registers->GPR[n]);
n++;
}
}
y++;
}
for(int i=0;i<35*per_line;i++)
mvwaddch(general_registers,1+center_y_offset+lines_used,center_x_offset+i,ACS_HLINE);
wattron(general_registers,A_BOLD);
mvwprintw(general_registers,1+center_y_offset+lines_used+1,1+center_x_offset," ZERO");
wattroff(general_registers,A_BOLD);
wprintw(general_registers,": %c ",(simdata->registers->FLAGS&1)?'1':'0');
wattron(general_registers,A_BOLD);
wprintw(general_registers,"CARRY");
wattroff(general_registers,A_BOLD);
wprintw(general_registers,": %c ",(simdata->registers->FLAGS&2)?'1':'0');
wattron(general_registers,A_BOLD);
wprintw(general_registers,"SIGN");
wattroff(general_registers,A_BOLD);
wprintw(general_registers,": %c ",(simdata->registers->FLAGS&4)?'1':'0');
}
}
}
if(height!=34242321)
return 0;
else
return 0;
}
int clear_back_window=1; int clear_back_window=1;
int update_gui(struct simdata_t *simdata){ int update_gui(struct simdata_t *simdata){
@ -327,6 +404,8 @@ int update_gui(struct simdata_t *simdata){
return 1; return 1;
if(update_general_disas(simdata)) if(update_general_disas(simdata))
return 1; return 1;
if(update_general_registers(simdata))
return 1;
if(gui_ncurses_refresh()) if(gui_ncurses_refresh())
return 1; return 1;
return 0; return 0;

View File

@ -38,6 +38,7 @@ struct simdata_t *init_simdata(){
ret->PC=0; ret->PC=0;
ret->SP=0; ret->SP=0;
ret->registers=NULL;
return ret; return ret;
} }

View File

@ -9,6 +9,7 @@ struct simdata_t{
struct fetch_data_t *fetch_data; struct fetch_data_t *fetch_data;
struct decode_data_t *decode_data; struct decode_data_t *decode_data;
struct exec_data_t *exec_data; struct exec_data_t *exec_data;
struct registers_t *registers;
}; };
struct simdata_t *init_simdata(); struct simdata_t *init_simdata();