GUI: Added stack window

This commit is contained in:
(Tim) Efthimis Kritikos 2024-01-26 16:11:57 +00:00
parent 16c70777f2
commit 0cfbf253c9
3 changed files with 81 additions and 2 deletions

81
gui.c
View File

@ -21,11 +21,14 @@
#include <string.h>
#include "simdata.h"
#define GENERAL_STACK_MAX_WIDTH 16
int terminal_width;
int terminal_height;
WINDOW *tabs;
WINDOW *general_memdump;
WINDOW *general_stack;
int monochrome;
@ -45,6 +48,8 @@ int gui_ncurses_refresh(){
return 1;
if(wrefresh(general_memdump)==ERR)
return 1;
if(wrefresh(general_stack)==ERR)
return 1;
return 0;
}
@ -56,6 +61,7 @@ enum CPU_STATE_t CPU_STATE=SINGLE_STEPPING;
//enum CPU_STATE_t CPU_STATE=STOPPED;
void update_tabs(){
wattron(tabs,A_BOLD);
wattron(tabs,COLOR_PAIR(2));
for(int i=0;i<terminal_width;i++)
mvwprintw(tabs,0,i," ");
@ -70,9 +76,12 @@ void update_tabs(){
x+=2;
if(i==CURRENT_TAB)
wattron(tabs,COLOR_PAIR(3));
else
else{
wattron(tabs,COLOR_PAIR(2));
wattroff(tabs,A_BOLD);
}
mvwprintw(tabs,0,x," %s ",tab_name[i]);
wattron(tabs,A_BOLD);
x+=strlen(tab_name[i])+2+3;
}
switch(CPU_STATE){
@ -117,7 +126,15 @@ int start_gui(){
mvprintw((terminal_height-3)/2+3,terminal_width/2-15,"Initialising the simulator...");
tabs = newwin(1,terminal_width,0,0);
update_tabs();
general_memdump=newwin(terminal_height*0.8,terminal_width/2,4,5);
int x=4;
general_memdump=newwin(terminal_height*0.8,terminal_width/2,x,5);
x+=terminal_width/2;
x+=3;
int 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);
x+=len;
if(gui_ncurses_refresh())
return 1;
return 0;
@ -139,6 +156,64 @@ int gui_error(char *str){
wattroff(error_win,COLOR_PAIR(1));
}
int update_general_stack(struct simdata_t *simdata){
int width,height;
getmaxyx(general_stack,height,width);
box(general_stack, 0 , 0);
mvwprintw(general_stack,0,width/2-4,"[ STACK ]");
if(width<13){
mvwprintw(general_stack,1,1,"too small window");
}else{
// Calculate config based on window size
int offset_data,offset_arrow;
if(width<14){
offset_data=3;
offset_arrow=2;
}else{
offset_data=5;
offset_arrow=3;
}
// draw data
uint32_t ADDRESS=(simdata->SP-(height/2-2)*4)&0x00FFFFFF;
for(int i=0;i<height-4;i++){
if(ADDRESS==simdata->SP)
wattron(general_stack,A_BOLD);
mvwprintw(general_stack,i+2,offset_data,"%08X",*(uint32_t*)(simdata->RAM+ADDRESS));
if(ADDRESS==simdata->SP)
wattroff(general_stack,A_BOLD);
ADDRESS=(ADDRESS+4)&0xFFFFFF;
}
// draw graphics
mvwaddch(general_stack,height/4-2,offset_arrow-1,ACS_UARROW);
mvwaddch(general_stack,height/4-1,offset_arrow-1,ACS_VLINE);
mvwaddch(general_stack,height/4 ,offset_arrow-1,ACS_VLINE);
mvwaddch(general_stack,height/4+1,offset_arrow-1,ACS_VLINE);
if(offset_arrow!=2)
mvwprintw(general_stack,height/4+2,1,"(+)");
else
mvwprintw(general_stack,height/4+2,offset_arrow-1,"+");
mvwaddch(general_stack,height/2,offset_arrow,ACS_RARROW);
mvwaddch(general_stack,height/2,offset_arrow-1,ACS_ULCORNER);
mvwaddch(general_stack,height/2+1,offset_arrow-1,ACS_VLINE);
mvwaddch(general_stack,height/2+2,offset_arrow-1,ACS_VLINE);
mvwaddch(general_stack,height/2+3,offset_arrow-1,ACS_VLINE);
mvwaddch(general_stack,height/2+4,offset_arrow-1,'S');
if(offset_arrow==2)
mvwaddch(general_stack,height/2+5,offset_arrow-1,'P');
else
mvwaddch(general_stack,height/2+4,offset_arrow,'P');
}
if(height!=1433241)
return 0;
return 1;
}
int update_general_memdump(struct simdata_t *simdata){
int width,height;
getmaxyx(general_memdump,height,width);
@ -174,6 +249,8 @@ int update_gui(struct simdata_t *simdata){
update_tabs();
if(update_general_memdump(simdata))
return 1;
if(update_general_stack(simdata))
return 1;
if(gui_ncurses_refresh())
return 1;
return 0;

View File

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

View File

@ -5,6 +5,7 @@ struct simdata_t{
long unsigned int current_clock;
uint8_t *RAM;
uint32_t PC;
uint32_t SP;
};
struct simdata_t *init_simdata();