GUI: Added disassembly window
This commit is contained in:
parent
0cfbf253c9
commit
d14c27382b
4
Makefile
4
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
|
||||
|
17
assembly.c
Normal file
17
assembly.c
Normal file
@ -0,0 +1,17 @@
|
||||
#include "assembly.h"
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
// 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;
|
||||
}
|
3
assembly.h
Normal file
3
assembly.h
Normal file
@ -0,0 +1,3 @@
|
||||
#include "stdint.h"
|
||||
|
||||
char* disassemble(uint32_t opcode);
|
68
gui.c
68
gui.c
@ -20,8 +20,11 @@
|
||||
#include <ncurses.h>
|
||||
#include <string.h>
|
||||
#include "simdata.h"
|
||||
#include "assembly.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#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;i<height-2;i++){
|
||||
int overall_offset=offset_arrow-2;
|
||||
|
||||
mvwaddch(general_disas,i,11+overall_offset,ACS_VLINE);
|
||||
|
||||
if(ADDRESS==simdata->PC)
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user