diff --git a/gui.c b/gui.c index 835f0ec..d6eca83 100644 --- a/gui.c +++ b/gui.c @@ -25,6 +25,7 @@ int terminal_width; int terminal_height; WINDOW *tabs; +WINDOW *general_memdump; int monochrome; @@ -42,21 +43,24 @@ int gui_ncurses_refresh(){ return 1; if(wrefresh(tabs)==ERR) return 1; + if(wrefresh(general_memdump)==ERR) + return 1; return 0; } -char *tab_name[]={"Overview","Memory","Test"}; +char *tab_name[]={"Overview","Memory","Internal"}; unsigned int CURRENT_TAB=0; -enum CPU_STATE_t CPU_STATE=STOPPED; +enum CPU_STATE_t CPU_STATE=SINGLE_STEPPING; +//enum CPU_STATE_t CPU_STATE=STOPPED; void update_tabs(){ wattron(tabs,COLOR_PAIR(2)); for(int i=0;iRAM[temp_address++]); + for (int i=0;iRAM[ADDRESS]>=0x20&&simdata->RAM[ADDRESS]<0x7F)?simdata->RAM[ADDRESS]:'.'); + ADDRESS++; + } + } + } + return 0; +} + +int update_gui(struct simdata_t *simdata){ + clear(); + update_tabs(); + if(update_general_memdump(simdata)) + return 1; + if(gui_ncurses_refresh()) + return 1; + return 0; +} + int gui_continue_request(){ if(getch()==ERR) return 1; diff --git a/gui.h b/gui.h index 7a8f5d1..8ace09c 100644 --- a/gui.h +++ b/gui.h @@ -1,4 +1,7 @@ +#include "simdata.h" + int start_gui(); int gui_continue_request(); int end_gui(); int gui_error(char *); +int update_gui(struct simdata_t *); diff --git a/main.c b/main.c index f088a07..cc249a7 100644 --- a/main.c +++ b/main.c @@ -21,7 +21,6 @@ #include #include "gui.h" #include "simdata.h" -#include "stdint.h" #include #include @@ -69,14 +68,14 @@ int main(int argc, char* argd[] ){ } fseek(rom, 0, SEEK_SET); - uint8_t *RAM=malloc(16777216); //Maximum addressable memory - if(!RAM){ - gui_error("failed to allocate 16MiB of memory for the system ram"); + struct simdata_t *simdata = init_simdata(); + if(!simdata){ + gui_error("failed to initialise simdata"); return 1; } - if(fread(RAM, 16777216, 1, rom)==0){ + if(fread(simdata->RAM, 16777216, 1, rom)==0){ printf("ERROR: failed to read input file\n"); - free(RAM); + free_simdata(simdata); return 1; } fclose(rom); @@ -85,33 +84,25 @@ int main(int argc, char* argd[] ){ /// INITIALISE GUI /// if(start_gui()){ printf("Failed on start_gui()\n"); - free(RAM); + free_simdata(simdata); return 1; } - struct simdata_t *simdata = init_simdata(); - if(!simdata){ - gui_error("failed to initialise simdata"); - free(RAM); - return 1; - } + update_gui(simdata); if(gui_continue_request()){ end_gui(); printf("Failed on gui_continue_request()\n"); free_simdata(simdata); - free(RAM); return 1; } if(end_gui()){ printf("Failed on end_gui()\n"); free_simdata(simdata); - free(RAM); return 1; } free_simdata(simdata); - free(RAM); return 0; } diff --git a/simdata.c b/simdata.c index 7a147c4..01f6f44 100644 --- a/simdata.c +++ b/simdata.c @@ -19,15 +19,27 @@ #include #include "simdata.h" +#include struct simdata_t *init_simdata(){ struct simdata_t * ret=malloc(sizeof(struct simdata_t)); - if(ret){ + + if(!ret){ ret->current_clock=0; + return 0; } + + ret->RAM=malloc(16777216); //Maximum addressable memory + if(!ret->RAM){ + printf("failed to allocate 16MiB of memory for the system ram"); + free(ret); + return 0; + } + return ret; } void free_simdata(struct simdata_t *p){ + free(p->RAM); free(p); } diff --git a/simdata.h b/simdata.h index 7037009..d4d7439 100644 --- a/simdata.h +++ b/simdata.h @@ -1,6 +1,11 @@ +#ifndef SIMDATA_HEADER +#include + struct simdata_t{ long unsigned int current_clock; + uint8_t *RAM; }; + struct simdata_t *init_simdata(); void free_simdata(struct simdata_t *); @@ -10,3 +15,5 @@ enum CPU_STATE_t{ SINGLE_STEPPING, STOPPED }; +#endif +#define SIMDATA_HEADER