From 8f817a17b77ac2ed8ff9309bcc187c3ea3db3c68 Mon Sep 17 00:00:00 2001 From: "(Tim) Efthimis Kritikos" Date: Sat, 17 Feb 2024 00:07:29 +0000 Subject: [PATCH] GUI: Added an option to run multiple cycles per frame when in run mode so that the bottleneck isn't the terminal as much --- cpu.c | 1 + gui.c | 45 +++++++++++++++++++++++++++------------------ gui.h | 4 ++++ 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/cpu.c b/cpu.c index b4911d7..22829d2 100644 --- a/cpu.c +++ b/cpu.c @@ -452,6 +452,7 @@ int cpu_cycle_clock(struct simdata_t *simdata){ state=0; else state++; + simdata->current_clock++; return 0; } diff --git a/gui.c b/gui.c index 3dd8d9d..08a14a2 100644 --- a/gui.c +++ b/gui.c @@ -23,6 +23,7 @@ #include "assembly.h" #include #include "cpu.h" +#include "gui.h" #include #define GENERAL_STACK_MAX_WIDTH 16 @@ -31,6 +32,8 @@ int terminal_width; int terminal_height; +struct gui_settings_t *gui_settings; + WINDOW *tabs; WINDOW *general_memdump; WINDOW *general_stack; @@ -71,7 +74,7 @@ char *tab_name[]={"Overview","Memory","Internal"}; unsigned int CURRENT_TAB=0; -enum GUI_CPU_STATE_t CPU_STATE=GUI_CPU_SINGLE_STEPPING; +enum GUI_CPU_STATE_t GUI_CPU_STATE=GUI_CPU_SINGLE_STEPPING; void update_tabs(){ wattron(tabs,A_BOLD); @@ -97,7 +100,7 @@ void update_tabs(){ wattron(tabs,A_BOLD); x+=strlen(tab_name[i])+2+3; } - switch(CPU_STATE){ + switch(GUI_CPU_STATE){ case GUI_CPU_RUNNING: wattron(tabs,COLOR_PAIR(6)); mvwprintw(tabs,0,terminal_width-13,"[ RUNNING "); @@ -190,6 +193,9 @@ int start_gui(){ x+=terminal_width/2; x++; + gui_settings=malloc(sizeof(struct gui_settings_t)); + gui_settings->cycles_per_frame=100; + if(gui_ncurses_refresh()) return 1; return 0; @@ -707,22 +713,24 @@ int clear_back_window=1; int update_gui(struct simdata_t *simdata){ if(simdata->cpu_state==CPU_HALTED) - CPU_STATE=GUI_CPU_STOPPED; + GUI_CPU_STATE=GUI_CPU_STOPPED; if(clear_back_window){ clear(); clear_back_window=0; } - update_tabs(); - if(update_general_memdump(simdata)) - return 1; - if(update_general_stack(simdata)) - return 1; - if(update_general_disas(simdata)) - return 1; - if(update_general_registers(simdata)) - return 1; - if(update_general_terminal_output(simdata)) - return 1; + if((simdata->current_clock)%(gui_settings->cycles_per_frame)==0 || GUI_CPU_STATE!=GUI_CPU_RUNNING ){ + update_tabs(); + if(update_general_memdump(simdata)) + return 1; + if(update_general_stack(simdata)) + return 1; + if(update_general_disas(simdata)) + return 1; + if(update_general_registers(simdata)) + return 1; + if(update_general_terminal_output(simdata)) + return 1; + } if(gui_ncurses_refresh()) return 1; return 0; @@ -733,7 +741,7 @@ int gui_continue_request(struct simdata_t *simdata){ int release=0; while(release==0){ if(((inch=getch())==ERR)){ - if(CPU_STATE==GUI_CPU_SINGLE_STEPPING) + if(GUI_CPU_STATE==GUI_CPU_SINGLE_STEPPING) return 1; else release=1; @@ -741,11 +749,12 @@ int gui_continue_request(struct simdata_t *simdata){ switch(inch){ case 'r': if(simdata->cpu_state!=CPU_HALTED){ - if(CPU_STATE==GUI_CPU_RUNNING){ - CPU_STATE=GUI_CPU_SINGLE_STEPPING; + if(GUI_CPU_STATE==GUI_CPU_RUNNING){ + GUI_CPU_STATE=GUI_CPU_SINGLE_STEPPING; + update_gui(simdata); nodelay(stdscr, FALSE); }else{ - CPU_STATE=GUI_CPU_RUNNING; + GUI_CPU_STATE=GUI_CPU_RUNNING; nodelay(stdscr, TRUE); } } diff --git a/gui.h b/gui.h index aab1ff0..54fad9e 100644 --- a/gui.h +++ b/gui.h @@ -5,3 +5,7 @@ int gui_continue_request(struct simdata_t*); int end_gui(); int gui_error(char *); int update_gui(struct simdata_t *); + +struct gui_settings_t{ + uint8_t cycles_per_frame; +};