GUI: Added hexdump window

This commit is contained in:
(Tim) Efthimis Kritikos 2024-01-23 19:35:57 +00:00
parent 756d8a49d9
commit 988b6802bb
5 changed files with 74 additions and 21 deletions

48
gui.c
View File

@ -25,6 +25,7 @@ int terminal_width;
int terminal_height; int terminal_height;
WINDOW *tabs; WINDOW *tabs;
WINDOW *general_memdump;
int monochrome; int monochrome;
@ -42,21 +43,24 @@ int gui_ncurses_refresh(){
return 1; return 1;
if(wrefresh(tabs)==ERR) if(wrefresh(tabs)==ERR)
return 1; return 1;
if(wrefresh(general_memdump)==ERR)
return 1;
return 0; return 0;
} }
char *tab_name[]={"Overview","Memory","Test"}; char *tab_name[]={"Overview","Memory","Internal"};
unsigned int CURRENT_TAB=0; 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(){ void update_tabs(){
wattron(tabs,COLOR_PAIR(2)); wattron(tabs,COLOR_PAIR(2));
for(int i=0;i<terminal_width;i++) for(int i=0;i<terminal_width;i++)
wprintw(tabs," "); mvwprintw(tabs,0,i," ");
int x=1; int x=2;
for(unsigned int i=0;i<sizeof(tab_name)/sizeof(tab_name[0]);i++){ for(unsigned int i=0;i<sizeof(tab_name)/sizeof(tab_name[0]);i++){
if(i==CURRENT_TAB) if(i==CURRENT_TAB)
wattron(tabs,COLOR_PAIR(4)); wattron(tabs,COLOR_PAIR(4));
@ -113,6 +117,7 @@ int start_gui(){
mvprintw((terminal_height-3)/2+3,terminal_width/2-15,"Initialising the simulator..."); mvprintw((terminal_height-3)/2+3,terminal_width/2-15,"Initialising the simulator...");
tabs = newwin(1,terminal_width,0,0); tabs = newwin(1,terminal_width,0,0);
update_tabs(); update_tabs();
general_memdump=newwin(terminal_height*0.8,terminal_width/2,4,5);
if(gui_ncurses_refresh()) if(gui_ncurses_refresh())
return 1; return 1;
return 0; return 0;
@ -134,6 +139,41 @@ int gui_error(char *str){
wattroff(error_win,COLOR_PAIR(1)); wattroff(error_win,COLOR_PAIR(1));
} }
int update_general_memdump(struct simdata_t *simdata){
int width,height;
getmaxyx(general_memdump,height,width);
box(general_memdump, 0 , 0);
mvwprintw(general_memdump,0,terminal_width/4-6,"[ MEMDUMP ]");
if(width<16){
mvwprintw(general_memdump,1,1,"too small window");
}else{
int n=(width-12)/4;
uint32_t ADDRESS=0;
for(int h=0;h<height-3;h++){
wmove(general_memdump,h+2,2+(width-12)%2);
wprintw(general_memdump,"%06x ",ADDRESS);
uint32_t temp_address=ADDRESS;
for (int i=0;i<n;i++)
wprintw(general_memdump,"%02x ",simdata->RAM[temp_address++]);
for (int i=0;i<n;i++){
wprintw(general_memdump,"%c",(simdata->RAM[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(){ int gui_continue_request(){
if(getch()==ERR) if(getch()==ERR)
return 1; return 1;

3
gui.h
View File

@ -1,4 +1,7 @@
#include "simdata.h"
int start_gui(); int start_gui();
int gui_continue_request(); int gui_continue_request();
int end_gui(); int end_gui();
int gui_error(char *); int gui_error(char *);
int update_gui(struct simdata_t *);

23
main.c
View File

@ -21,7 +21,6 @@
#include <stdlib.h> #include <stdlib.h>
#include "gui.h" #include "gui.h"
#include "simdata.h" #include "simdata.h"
#include "stdint.h"
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>
@ -69,14 +68,14 @@ int main(int argc, char* argd[] ){
} }
fseek(rom, 0, SEEK_SET); fseek(rom, 0, SEEK_SET);
uint8_t *RAM=malloc(16777216); //Maximum addressable memory struct simdata_t *simdata = init_simdata();
if(!RAM){ if(!simdata){
gui_error("failed to allocate 16MiB of memory for the system ram"); gui_error("failed to initialise simdata");
return 1; 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"); printf("ERROR: failed to read input file\n");
free(RAM); free_simdata(simdata);
return 1; return 1;
} }
fclose(rom); fclose(rom);
@ -85,33 +84,25 @@ int main(int argc, char* argd[] ){
/// INITIALISE GUI /// /// INITIALISE GUI ///
if(start_gui()){ if(start_gui()){
printf("Failed on start_gui()\n"); printf("Failed on start_gui()\n");
free(RAM); free_simdata(simdata);
return 1; return 1;
} }
struct simdata_t *simdata = init_simdata(); update_gui(simdata);
if(!simdata){
gui_error("failed to initialise simdata");
free(RAM);
return 1;
}
if(gui_continue_request()){ if(gui_continue_request()){
end_gui(); end_gui();
printf("Failed on gui_continue_request()\n"); printf("Failed on gui_continue_request()\n");
free_simdata(simdata); free_simdata(simdata);
free(RAM);
return 1; return 1;
} }
if(end_gui()){ if(end_gui()){
printf("Failed on end_gui()\n"); printf("Failed on end_gui()\n");
free_simdata(simdata); free_simdata(simdata);
free(RAM);
return 1; return 1;
} }
free_simdata(simdata); free_simdata(simdata);
free(RAM);
return 0; return 0;
} }

View File

@ -19,15 +19,27 @@
#include <stdlib.h> #include <stdlib.h>
#include "simdata.h" #include "simdata.h"
#include <stdio.h>
struct simdata_t *init_simdata(){ struct simdata_t *init_simdata(){
struct simdata_t * ret=malloc(sizeof(struct simdata_t)); struct simdata_t * ret=malloc(sizeof(struct simdata_t));
if(ret){
if(!ret){
ret->current_clock=0; 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; return ret;
} }
void free_simdata(struct simdata_t *p){ void free_simdata(struct simdata_t *p){
free(p->RAM);
free(p); free(p);
} }

View File

@ -1,6 +1,11 @@
#ifndef SIMDATA_HEADER
#include <stdint.h>
struct simdata_t{ struct simdata_t{
long unsigned int current_clock; long unsigned int current_clock;
uint8_t *RAM;
}; };
struct simdata_t *init_simdata(); struct simdata_t *init_simdata();
void free_simdata(struct simdata_t *); void free_simdata(struct simdata_t *);
@ -10,3 +15,5 @@ enum CPU_STATE_t{
SINGLE_STEPPING, SINGLE_STEPPING,
STOPPED STOPPED
}; };
#endif
#define SIMDATA_HEADER