From 0cfbf253c980495553c83ec3321215e91ee9daf8 Mon Sep 17 00:00:00 2001 From: "(Tim) Efthimis Kritikos" Date: Fri, 26 Jan 2024 16:11:57 +0000 Subject: [PATCH] GUI: Added stack window --- gui.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- simdata.c | 1 + simdata.h | 1 + 3 files changed, 81 insertions(+), 2 deletions(-) diff --git a/gui.c b/gui.c index 412bd19..fae82df 100644 --- a/gui.c +++ b/gui.c @@ -21,11 +21,14 @@ #include #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;iGENERAL_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;iSP) + 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; diff --git a/simdata.c b/simdata.c index 92e7b0f..c6bb695 100644 --- a/simdata.c +++ b/simdata.c @@ -37,6 +37,7 @@ struct simdata_t *init_simdata(){ } ret->PC=0; + ret->SP=0; return ret; } diff --git a/simdata.h b/simdata.h index 8761597..4a51d94 100644 --- a/simdata.h +++ b/simdata.h @@ -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();