GUI: Added an option to run multiple cycles per frame when in run mode so that the bottleneck isn't the terminal as much

This commit is contained in:
(Tim) Efthimis Kritikos 2024-02-17 00:07:29 +00:00
parent 519c762287
commit 8f817a17b7
3 changed files with 32 additions and 18 deletions

1
cpu.c
View File

@ -452,6 +452,7 @@ int cpu_cycle_clock(struct simdata_t *simdata){
state=0; state=0;
else else
state++; state++;
simdata->current_clock++;
return 0; return 0;
} }

23
gui.c
View File

@ -23,6 +23,7 @@
#include "assembly.h" #include "assembly.h"
#include <stdlib.h> #include <stdlib.h>
#include "cpu.h" #include "cpu.h"
#include "gui.h"
#include <locale.h> #include <locale.h>
#define GENERAL_STACK_MAX_WIDTH 16 #define GENERAL_STACK_MAX_WIDTH 16
@ -31,6 +32,8 @@
int terminal_width; int terminal_width;
int terminal_height; int terminal_height;
struct gui_settings_t *gui_settings;
WINDOW *tabs; WINDOW *tabs;
WINDOW *general_memdump; WINDOW *general_memdump;
WINDOW *general_stack; WINDOW *general_stack;
@ -71,7 +74,7 @@ char *tab_name[]={"Overview","Memory","Internal"};
unsigned int CURRENT_TAB=0; 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(){ void update_tabs(){
wattron(tabs,A_BOLD); wattron(tabs,A_BOLD);
@ -97,7 +100,7 @@ void update_tabs(){
wattron(tabs,A_BOLD); wattron(tabs,A_BOLD);
x+=strlen(tab_name[i])+2+3; x+=strlen(tab_name[i])+2+3;
} }
switch(CPU_STATE){ switch(GUI_CPU_STATE){
case GUI_CPU_RUNNING: case GUI_CPU_RUNNING:
wattron(tabs,COLOR_PAIR(6)); wattron(tabs,COLOR_PAIR(6));
mvwprintw(tabs,0,terminal_width-13,"[ RUNNING "); mvwprintw(tabs,0,terminal_width-13,"[ RUNNING ");
@ -190,6 +193,9 @@ int start_gui(){
x+=terminal_width/2; x+=terminal_width/2;
x++; x++;
gui_settings=malloc(sizeof(struct gui_settings_t));
gui_settings->cycles_per_frame=100;
if(gui_ncurses_refresh()) if(gui_ncurses_refresh())
return 1; return 1;
return 0; return 0;
@ -707,11 +713,12 @@ int clear_back_window=1;
int update_gui(struct simdata_t *simdata){ int update_gui(struct simdata_t *simdata){
if(simdata->cpu_state==CPU_HALTED) if(simdata->cpu_state==CPU_HALTED)
CPU_STATE=GUI_CPU_STOPPED; GUI_CPU_STATE=GUI_CPU_STOPPED;
if(clear_back_window){ if(clear_back_window){
clear(); clear();
clear_back_window=0; clear_back_window=0;
} }
if((simdata->current_clock)%(gui_settings->cycles_per_frame)==0 || GUI_CPU_STATE!=GUI_CPU_RUNNING ){
update_tabs(); update_tabs();
if(update_general_memdump(simdata)) if(update_general_memdump(simdata))
return 1; return 1;
@ -723,6 +730,7 @@ int update_gui(struct simdata_t *simdata){
return 1; return 1;
if(update_general_terminal_output(simdata)) if(update_general_terminal_output(simdata))
return 1; return 1;
}
if(gui_ncurses_refresh()) if(gui_ncurses_refresh())
return 1; return 1;
return 0; return 0;
@ -733,7 +741,7 @@ int gui_continue_request(struct simdata_t *simdata){
int release=0; int release=0;
while(release==0){ while(release==0){
if(((inch=getch())==ERR)){ if(((inch=getch())==ERR)){
if(CPU_STATE==GUI_CPU_SINGLE_STEPPING) if(GUI_CPU_STATE==GUI_CPU_SINGLE_STEPPING)
return 1; return 1;
else else
release=1; release=1;
@ -741,11 +749,12 @@ int gui_continue_request(struct simdata_t *simdata){
switch(inch){ switch(inch){
case 'r': case 'r':
if(simdata->cpu_state!=CPU_HALTED){ if(simdata->cpu_state!=CPU_HALTED){
if(CPU_STATE==GUI_CPU_RUNNING){ if(GUI_CPU_STATE==GUI_CPU_RUNNING){
CPU_STATE=GUI_CPU_SINGLE_STEPPING; GUI_CPU_STATE=GUI_CPU_SINGLE_STEPPING;
update_gui(simdata);
nodelay(stdscr, FALSE); nodelay(stdscr, FALSE);
}else{ }else{
CPU_STATE=GUI_CPU_RUNNING; GUI_CPU_STATE=GUI_CPU_RUNNING;
nodelay(stdscr, TRUE); nodelay(stdscr, TRUE);
} }
} }

4
gui.h
View File

@ -5,3 +5,7 @@ int gui_continue_request(struct simdata_t*);
int end_gui(); int end_gui();
int gui_error(char *); int gui_error(char *);
int update_gui(struct simdata_t *); int update_gui(struct simdata_t *);
struct gui_settings_t{
uint8_t cycles_per_frame;
};