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;
else
state++;
simdata->current_clock++;
return 0;
}

45
gui.c
View File

@ -23,6 +23,7 @@
#include "assembly.h"
#include <stdlib.h>
#include "cpu.h"
#include "gui.h"
#include <locale.h>
#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);
}
}

4
gui.h
View File

@ -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;
};