From 9f987da7a62cf2039845888b0088bdf0f814f561 Mon Sep 17 00:00:00 2001 From: "(Tim) Efthimis Kritikos" Date: Thu, 22 Feb 2024 00:04:56 +0000 Subject: [PATCH] GUI: Added basic support for freeing up unused parts of the cpu output buffer --- gui.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ gui.h | 1 + simdata.c | 10 ++++++++-- 3 files changed, 62 insertions(+), 2 deletions(-) diff --git a/gui.c b/gui.c index 4c31965..1734ece 100644 --- a/gui.c +++ b/gui.c @@ -784,11 +784,15 @@ int update_debug_simdata(struct simdata_t *simdata){ mvwprintw(debug_simdata,1,1,"simdata->terminal_output_size: "); if(simdata->terminal_output_size<100*1024) wattron(debug_simdata,COLOR_PAIR(11)); + else if (simdata->terminal_output_size<500*1024) + wattron(debug_simdata,COLOR_PAIR(10)); else wattron(debug_simdata,COLOR_PAIR(15)); wprintw(debug_simdata,"%d%s",term_size,term_size_unit); if(simdata->terminal_output_size<100*1024) wattroff(debug_simdata,COLOR_PAIR(11)); + else if (simdata->terminal_output_size<500*1024) + wattroff(debug_simdata,COLOR_PAIR(10)); else wattroff(debug_simdata,COLOR_PAIR(15)); if(height==3) @@ -972,6 +976,55 @@ int gui_continue_request(struct simdata_t *simdata){ return 0; } +int clean_cpu_output(struct simdata_t *simdata){ + uint32_t last_vect_disp=0; + uint32_t second_last_vect_disp=simdata->terminal_output_size/4;//TODO: I shouldn't have to initialise this. GCC gives a warning erroneously + int vector=0; + int vstate=0; + uint32_t disps_found=0; + if(!simdata) + return 0; + for(uint64_t i=0;i < simdata->terminal_output_size/4;i++){ + uint32_t c=simdata->terminal_output[i]; + if(vector){ + switch(vstate){ + case 0: /*start of line*/ + if(c==0x00000001) + vector=0; + else if(c==0x00000003){ + second_last_vect_disp=last_vect_disp; + last_vect_disp=i*4; + disps_found++; + }else + vstate++; + break; + case 1: + case 2: + case 3: + vstate++; + break; + case 4: + vstate=0; + break; + } + }else{ + switch(c){ + case 0xffffffff: + vector=1; + break; + } + } + } + if(disps_found>=2){ + int final_data_size=simdata->terminal_output_size-(second_last_vect_disp+4); + memmove((uint8_t*)simdata->terminal_output+4,(uint8_t*)simdata->terminal_output+simdata->terminal_output_size-final_data_size,final_data_size); + simdata->terminal_output[0]=0xFFFFFFFF; + simdata->terminal_output=realloc(simdata->terminal_output,final_data_size+4); + simdata->terminal_output_size=final_data_size+4; + } + return 0; +} + int end_gui(){ if(endwin()==ERR) return 1; diff --git a/gui.h b/gui.h index 54fad9e..07a960e 100644 --- a/gui.h +++ b/gui.h @@ -5,6 +5,7 @@ int gui_continue_request(struct simdata_t*); int end_gui(); int gui_error(char *); int update_gui(struct simdata_t *); +int clean_cpu_output(struct simdata_t *simdata); struct gui_settings_t{ uint8_t cycles_per_frame; diff --git a/simdata.c b/simdata.c index 4d8c2f9..9faa5a2 100644 --- a/simdata.c +++ b/simdata.c @@ -20,6 +20,7 @@ #include #include "simdata.h" #include +#include "gui.h" // for cleaning the cpu output struct simdata_t *init_simdata(){ struct simdata_t * ret=malloc(sizeof(struct simdata_t)); @@ -47,12 +48,17 @@ struct simdata_t *init_simdata(){ return ret; } +uint8_t output_counter=0; + int terminal_output(uint32_t c,struct simdata_t *simdata){ simdata->terminal_output=realloc(simdata->terminal_output,simdata->terminal_output_size+4); if(!simdata->terminal_output) return 1; - *(uint32_t*)(simdata->terminal_output+simdata->terminal_output_size/4)=c; - simdata->terminal_output_size+=4; + simdata->terminal_output[simdata->terminal_output_size/4]=c; + simdata->terminal_output_size=simdata->terminal_output_size+4; + output_counter++; + if((output_counter%100)==0) + clean_cpu_output(simdata); return 0; }