diff --git a/Makefile b/Makefile index aa5043c..433808b 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ all:first -first:gui.o main.o simdata.o +first:gui.o main.o simdata.o assembly.o gcc -ggdb $^ -fsanitize=address -lncurses -ltinfo -o $@ %.o:%.c @@ -8,4 +8,4 @@ first:gui.o main.o simdata.o .PHONY: clean clean: - rm -f gui.o main.o simdata.o + rm -f gui.o main.o simdata.o assembly.o diff --git a/assembly.c b/assembly.c new file mode 100644 index 0000000..9147790 --- /dev/null +++ b/assembly.c @@ -0,0 +1,17 @@ +#include "assembly.h" +#include +#include + + +// Max instruction width is 25 characters without the null char + +char *disassemble(uint32_t opcode){ + char *ret=malloc(26); + if (!ret) + return NULL; + if(opcode!=0x01ABCDEF) + memcpy(ret,"placeholder",12); + else + memcpy(ret,"easter egg",11); + return ret; +} diff --git a/assembly.h b/assembly.h new file mode 100644 index 0000000..373cff4 --- /dev/null +++ b/assembly.h @@ -0,0 +1,3 @@ +#include "stdint.h" + +char* disassemble(uint32_t opcode); diff --git a/gui.c b/gui.c index fae82df..5c56f11 100644 --- a/gui.c +++ b/gui.c @@ -20,8 +20,11 @@ #include #include #include "simdata.h" +#include "assembly.h" +#include #define GENERAL_STACK_MAX_WIDTH 16 +#define GENERAL_DISAS_WIDTH 41 int terminal_width; int terminal_height; @@ -29,6 +32,7 @@ int terminal_height; WINDOW *tabs; WINDOW *general_memdump; WINDOW *general_stack; +WINDOW *general_disas; int monochrome; @@ -50,6 +54,8 @@ int gui_ncurses_refresh(){ return 1; if(wrefresh(general_stack)==ERR) return 1; + if(wrefresh(general_disas)==ERR) + return 1; return 0; } @@ -126,12 +132,19 @@ int start_gui(){ mvprintw((terminal_height-3)/2+3,terminal_width/2-15,"Initialising the simulator..."); tabs = newwin(1,terminal_width,0,0); update_tabs(); + int len; int x=4; general_memdump=newwin(terminal_height*0.8,terminal_width/2,x,5); x+=terminal_width/2; + x++; x+=3; - int len=(terminal_width/6)>GENERAL_STACK_MAX_WIDTH?GENERAL_STACK_MAX_WIDTH:(terminal_width/6); + len=(terminal_width/6)>GENERAL_DISAS_WIDTH?GENERAL_DISAS_WIDTH:(terminal_width/6); + general_disas=newwin(terminal_height*0.8,len,4,x); + x+=len; + + x+=3; + len=(terminal_width/6)>GENERAL_STACK_MAX_WIDTH?GENERAL_STACK_MAX_WIDTH:(terminal_width/6); general_stack=newwin(terminal_height*0.8,len,4,x); x+=len; @@ -156,6 +169,55 @@ int gui_error(char *str){ wattroff(error_win,COLOR_PAIR(1)); } +int update_general_disas(struct simdata_t *simdata){ + int width,height; + getmaxyx(general_disas,height,width); + box(general_disas, 0 , 0); + int offset_arrow; + if(width<41) + offset_arrow=2; + else + offset_arrow=3; + mvwprintw(general_disas,0,width/2-7,"[ DISASSEMBLY ]"); + if(width<18){ + mvwprintw(general_disas,1,1,"too small window"); + }else{ + uint32_t ADDRESS=(simdata->PC-(height/2-2)*3)&0x00FFFFFF; + for (int i=2;iPC) + wattron(general_disas,A_BOLD); + mvwprintw(general_disas,i,4+overall_offset,"%06X",ADDRESS); + char* disas=disassemble(*(uint32_t*)(simdata->RAM+ADDRESS)); + int space_left=width-14-2+(overall_offset?0:1); + if(space_left<25) + disas[space_left+1]=0; + mvwprintw(general_disas,i,13+overall_offset,"%s",disas); + if(ADDRESS==simdata->PC) + wattroff(general_disas,A_BOLD); + + ADDRESS=(ADDRESS+3)&0xFFFFFF; + free(disas); + } + mvwaddch(general_disas,height/2,offset_arrow,ACS_RARROW); + mvwaddch(general_disas,height/2,offset_arrow-1,ACS_ULCORNER); + mvwaddch(general_disas,height/2+1,offset_arrow-1,ACS_VLINE); + mvwaddch(general_disas,height/2+2,offset_arrow-1,ACS_VLINE); + mvwaddch(general_disas,height/2+3,offset_arrow-1,ACS_VLINE); + mvwaddch(general_disas,height/2+4,offset_arrow-1,ACS_VLINE); + mvwaddch(general_disas,height/2+5,offset_arrow-1,ACS_VLINE); + mvwaddch(general_disas,height/2+6,offset_arrow-1,'P'); + if(offset_arrow==2) + mvwaddch(general_disas,height/2+7,offset_arrow-1,'C'); + else + mvwaddch(general_disas,height/2+6,offset_arrow,'C'); + } + return 0; +} + int update_general_stack(struct simdata_t *simdata){ int width,height; getmaxyx(general_stack,height,width); @@ -209,9 +271,7 @@ int update_general_stack(struct simdata_t *simdata){ else mvwaddch(general_stack,height/2+4,offset_arrow,'P'); } - if(height!=1433241) return 0; - return 1; } int update_general_memdump(struct simdata_t *simdata){ @@ -251,6 +311,8 @@ int update_gui(struct simdata_t *simdata){ return 1; if(update_general_stack(simdata)) return 1; + if(update_general_disas(simdata)) + return 1; if(gui_ncurses_refresh()) return 1; return 0; diff --git a/main.c b/main.c index cc249a7..c182ec0 100644 --- a/main.c +++ b/main.c @@ -40,7 +40,7 @@ int main(int argc, char* argd[] ){ break; case 'i': infile=optarg; - break; + break; default: help(argd[0]); return 1;