diff --git a/cpu.c b/cpu.c index ccc14dc..f902333 100644 --- a/cpu.c +++ b/cpu.c @@ -327,7 +327,8 @@ int exec(struct simdata_t *simdata){ if(simdata->exec_data->in_op1->OP_ADDR==REGISTER){ *(uint32_t*)(simdata->RAM+(simdata->registers->GPR[simdata->exec_data->out_op->data]&0x00FFFFFF))=simdata->registers->GPR[simdata->exec_data->in_op1->data]; if(simdata->registers->GPR[simdata->exec_data->out_op->data]==0x00FFFFFC) - terminal_output(simdata->registers->GPR[simdata->exec_data->in_op1->data],simdata); + if(terminal_output(simdata->registers->GPR[simdata->exec_data->in_op1->data],simdata)) + return 1; }else return 1; break; diff --git a/gui.c b/gui.c index 1e07044..86faccb 100644 --- a/gui.c +++ b/gui.c @@ -23,6 +23,7 @@ #include "assembly.h" #include #include "cpu.h" +#include #define GENERAL_STACK_MAX_WIDTH 16 #define GENERAL_DISAS_WIDTH 41 @@ -114,6 +115,7 @@ void update_tabs(){ } int start_gui(){ + setlocale(LC_ALL, ""); if(!initscr()) return 1; monochrome=( has_colors() == FALSE ); @@ -537,59 +539,168 @@ int update_general_registers(struct simdata_t *simdata){ int term_curs_x,term_curs_y; +wchar_t braille_lookup[256]={ +L'⠀',L'⠁',L'⠂',L'⠃',L'⠄',L'⠅',L'⠆',L'⠇',L'⠈',L'⠉',L'⠊',L'⠋',L'⠌',L'⠍',L'⠎',L'⠏',L'⠐',L'⠑',L'⠒',L'⠓',L'⠔',L'⠕',L'⠖',L'⠗',L'⠘',L'⠙',L'⠚',L'⠛',L'⠜',L'⠝',L'⠞',L'⠟', +L'⠠',L'⠡',L'⠢',L'⠣',L'⠤',L'⠥',L'⠦',L'⠧',L'⠨',L'⠩',L'⠪',L'⠫',L'⠬',L'⠭',L'⠮',L'⠯',L'⠰',L'⠱',L'⠲',L'⠳',L'⠴',L'⠵',L'⠶',L'⠷',L'⠸',L'⠹',L'⠺',L'⠻',L'⠼',L'⠽',L'⠾',L'⠿', +L'⡀',L'⡁',L'⡂',L'⡃',L'⡄',L'⡅',L'⡆',L'⡇',L'⡈',L'⡉',L'⡊',L'⡋',L'⡌',L'⡍',L'⡎',L'⡏',L'⡐',L'⡑',L'⡒',L'⡓',L'⡔',L'⡕',L'⡖',L'⡗',L'⡘',L'⡙',L'⡚',L'⡛',L'⡜',L'⡝',L'⡞',L'⡟',L'⡠',L'⡡',L'⡢',L'⡣',L'⡤',L'⡥',L'⡦',L'⡧',L'⡨',L'⡩',L'⡪',L'⡫',L'⡬',L'⡭',L'⡮',L'⡯',L'⡰',L'⡱',L'⡲',L'⡳',L'⡴',L'⡵',L'⡶',L'⡷',L'⡸',L'⡹',L'⡺',L'⡻',L'⡼',L'⡽',L'⡾',L'⡿', +L'⢀',L'⢁',L'⢂',L'⢃',L'⢄',L'⢅',L'⢆',L'⢇',L'⢈',L'⢉',L'⢊',L'⢋',L'⢌',L'⢍',L'⢎',L'⢏',L'⢐',L'⢑',L'⢒',L'⢓',L'⢔',L'⢕',L'⢖',L'⢗',L'⢘',L'⢙',L'⢚',L'⢛',L'⢜',L'⢝',L'⢞',L'⢟',L'⢠',L'⢡',L'⢢',L'⢣',L'⢤',L'⢥',L'⢦',L'⢧',L'⢨',L'⢩',L'⢪',L'⢫',L'⢬',L'⢭',L'⢮',L'⢯',L'⢰',L'⢱',L'⢲',L'⢳',L'⢴',L'⢵',L'⢶',L'⢷',L'⢸',L'⢹',L'⢺',L'⢻',L'⢼',L'⢽',L'⢾',L'⢿', +L'⣀',L'⣁',L'⣂',L'⣃',L'⣄',L'⣅',L'⣆',L'⣇',L'⣈',L'⣉',L'⣊',L'⣋',L'⣌',L'⣍',L'⣎',L'⣏',L'⣐',L'⣑',L'⣒',L'⣓',L'⣔',L'⣕',L'⣖',L'⣗',L'⣘',L'⣙',L'⣚',L'⣛',L'⣜',L'⣝',L'⣞',L'⣟',L'⣠',L'⣡',L'⣢',L'⣣',L'⣤',L'⣥',L'⣦',L'⣧',L'⣨',L'⣩',L'⣪',L'⣫',L'⣬',L'⣭',L'⣮',L'⣯',L'⣰',L'⣱',L'⣲',L'⣳',L'⣴',L'⣵',L'⣶',L'⣷',L'⣸',L'⣹',L'⣺',L'⣻',L'⣼',L'⣽',L'⣾',L'⣿', +}; + +int print_braille_frame_buffer(WINDOW* win,uint8_t *buffer,int width,int height){ + for(int h=0;h=0){ + addr=x+y*buffer_width; + if(addr>0&&addr<(uint64_t)(buffer_width*buffer_height)&&x0) + buffer[addr]=1; + y=y+1; + p=p+2*dy-2*dx; + }else{ + addr=x+y*buffer_width; + if(addr>0&&addr<(uint64_t)(buffer_width*buffer_height)&&x0) + buffer[addr]=1; + p=p+2*dy; + } + x=x+1; + } +} + int update_general_terminal_output(struct simdata_t *simdata){ int width,height; werase(general_terminal_output); getmaxyx(general_terminal_output,height,width); - box(general_terminal_output, 0 , 0); - mvwprintw(general_terminal_output,0,width/2-7,"[ TERM OUTPUT ]"); term_curs_x=0; term_curs_y=0; + uint8_t* vector_frame_buffer=malloc((height*4)*(width*2)); + memset(vector_frame_buffer,0,(height*4)*(width*2)); - for(uint64_t i=0;i < simdata->terminal_output_size;i++){ - char c=simdata->terminal_output[i]; - if(c>=' '&&c<='~'){ - mvwprintw(general_terminal_output,term_curs_y+1,term_curs_x+1,"%c",c); - term_curs_x++; - if(term_curs_x>=width-2){ - term_curs_x=0; - term_curs_y++; - } - if(term_curs_y>=height-2){ - wscrl(general_terminal_output,1); - term_curs_y--; - for(int i=0;iterminal_output_size;i+=4){ + uint32_t c=simdata->terminal_output[i/4]; + if(vector){ + float x0,y0,x1,y1; + switch(vstate){ + case 0: /*start of line*/ + if(c==0x00000001) + vector=0; + else if(c==0x00000002) + memset(vector_frame_buffer,0,(height*4)*(width*2)); + else + vstate++; + break; + case 1: /*x of start*/ + x0=*(float*)&c; + vstate++; + break; + case 2: /*y of start*/ + y0=*(float*)&c; + vstate++; + break; + case 3: /*x of end*/ + x1=*(float*)&c; + vstate++; + break; + case 4: /*y of end*/ + y1=*(float*)&c; + float min_dim=(vfb_width>vfb_height)?vfb_height:vfb_width; + int xoff=0,yoff=0; + x0*=1.25; + x1*=1.25; + if(vfb_width>vfb_height) + xoff=(vfb_width-vfb_height)/2; + else + yoff=(vfb_height-vfb_width)/2; + braille_frame_buffer_line(vector_frame_buffer,vfb_width,vfb_height,xoff+(x0+1)*(min_dim/2),yoff+(y0+1)*(min_dim/2),xoff+(x1+1)*(min_dim/2),yoff+(y1+1)*(min_dim/2)); + vstate=0; + break; } }else{ - switch(c){ - case 0x0a: + if(c>=' '&&c<='~'){ + mvwprintw(general_terminal_output,term_curs_y+1,term_curs_x+1,"%c",c); + term_curs_x++; + if(term_curs_x>=width-2){ term_curs_x=0; term_curs_y++; - if(term_curs_y>=height-2){ - wscrl(general_terminal_output,1); - term_curs_y--; - for(int i=0;i=height-2){ + wscrl(general_terminal_output,1); + term_curs_y--; + for(int i=0;i=height-2){ + wscrl(general_terminal_output,1); + term_curs_y--; + box(general_terminal_output, 0 , 0); + mvwprintw(general_terminal_output,0,width/2-7,"[ TERM OUTPUT ]"); } + break; + default: + werase(general_terminal_output); box(general_terminal_output, 0 , 0); mvwprintw(general_terminal_output,0,width/2-7,"[ TERM OUTPUT ]"); - } - break; - default: - werase(general_terminal_output); - box(general_terminal_output, 0 , 0); - mvwprintw(general_terminal_output,0,width/2-7,"[ TERM OUTPUT ]"); - mvwprintw(general_terminal_output,1,1,"Invalid output"); - return 0; + mvwprintw(general_terminal_output,1,1,"Invalid output"); + return 0; + } } } } - mvwchgat(general_terminal_output,term_curs_y+1,term_curs_x+1, 1, A_REVERSE, 0, NULL); + box(general_terminal_output, 0 , 0); + if(!vector){ + mvwchgat(general_terminal_output,term_curs_y+1,term_curs_x+1, 1, A_REVERSE, 0, NULL); + mvwprintw(general_terminal_output,0,width/2-7,"[ TERM OUTPUT ]"); + }else{ + print_braille_frame_buffer(general_terminal_output,vector_frame_buffer,(width-2)*2,(height-2)*4); + mvwprintw(general_terminal_output,0,width/2-9,"[ VECTOR DISPLAY ]"); + } + free(vector_frame_buffer); return 0; } @@ -647,6 +758,7 @@ int gui_continue_request(struct simdata_t *simdata){ release=1; break; default: + break; } } return 0; diff --git a/simdata.c b/simdata.c index 42193f2..1af7b73 100644 --- a/simdata.c +++ b/simdata.c @@ -47,12 +47,12 @@ struct simdata_t *init_simdata(){ return ret; } -int terminal_output(char c,struct simdata_t *simdata){ - simdata->terminal_output=realloc(simdata->terminal_output,simdata->terminal_output_size+1); +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; - simdata->terminal_output[simdata->terminal_output_size]=c; - simdata->terminal_output_size++; + *(uint32_t*)(simdata->terminal_output+simdata->terminal_output_size/4)=c; + simdata->terminal_output_size+=4; return 0; } diff --git a/simdata.h b/simdata.h index 106718f..9fc78b6 100644 --- a/simdata.h +++ b/simdata.h @@ -19,7 +19,7 @@ struct simdata_t{ struct cpu_gui_hints_t *cpu_gui_hints; - char* terminal_output; + uint32_t* terminal_output; uint64_t terminal_output_size; }; @@ -39,7 +39,7 @@ struct simdata_t *init_simdata(); void free_simdata(struct simdata_t *); int add_to_instr_list(struct instr_list_t **addr_of_toadd,uint32_t address); void free_instr_list(struct instr_list_t **addr_of_tofree); -int terminal_output(char c,struct simdata_t *simdata); +int terminal_output(uint32_t c,struct simdata_t *simdata); enum GUI_CPU_STATE_t{ GUI_CPU_RUNNING, diff --git a/test.asm b/test.asm index 9f594f6..4a3a04d 100644 --- a/test.asm +++ b/test.asm @@ -30,4 +30,22 @@ MOV $0x006c,%R1l MOV %R1,(%R0) MOV $0x006f,%R1l MOV %R1,(%R0) -JMP $000000 +MOV $0xFFFF,%R1l +MOV $0xFFFF,%R1h +MOV %R1,(%R0) +MOV $0x0000,%R1l +MOV $0x0000,%R1h +MOV %R1,(%R0) +MOV $0xcccd,%R1l +MOV $0xbf4c,%R1h +MOV %R1,(%R0) +MOV $0xcccd,%R1l +MOV $0xbf4c,%R1h +MOV %R1,(%R0) +MOV $0xcccd,%R1l +MOV $0x3f4c,%R1h +MOV %R1,(%R0) +MOV $0xcccd,%R1l +MOV $0x3f4c,%R1h +MOV %R1,(%R0) +HALT