GUI: Added a vector graphics display using braille characters to form a frame buffer in the terminal window
This commit is contained in:
parent
591d07f478
commit
ed415511dc
3
cpu.c
3
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;
|
||||
|
130
gui.c
130
gui.c
@ -23,6 +23,7 @@
|
||||
#include "assembly.h"
|
||||
#include <stdlib.h>
|
||||
#include "cpu.h"
|
||||
#include <locale.h>
|
||||
|
||||
#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,18 +539,120 @@ 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<height/4;h++){
|
||||
for(int w=0;w<width/2;w++){
|
||||
uint8_t select=0;
|
||||
if(buffer[w*2 +width*(h*4 )])
|
||||
select|=0x01;
|
||||
if(buffer[w*2 +width*(h*4+1)])
|
||||
select|=0x02;
|
||||
if(buffer[w*2 +width*(h*4+2)])
|
||||
select|=0x04;
|
||||
if(buffer[w*2 +width*(h*4+3)])
|
||||
select|=0x40;
|
||||
if(buffer[w*2+1 +width*(h*4 )])
|
||||
select|=0x08;
|
||||
if(buffer[w*2+1 +width*(h*4+1 )])
|
||||
select|=0x10;
|
||||
if(buffer[w*2+1 +width*(h*4+2 )])
|
||||
select|=0x20;
|
||||
if(buffer[w*2+1 +width*(h*4+3 )])
|
||||
select|=0x80;
|
||||
mvwprintw(win,h+1,w+1,"%lc",braille_lookup[select]);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void braille_frame_buffer_line(uint8_t *buffer,int buffer_width,int buffer_height,int x0, int y0, int x1, int y1){
|
||||
int dx,dy,p,x,y;
|
||||
dx=x1-x0;
|
||||
dy=y1-y0;
|
||||
x=x0;
|
||||
y=y0;
|
||||
p=2*dy-dx;
|
||||
uint32_t addr;
|
||||
while(x<x1){
|
||||
if(p>=0){
|
||||
addr=x+y*buffer_width;
|
||||
if(addr>0&&addr<(uint64_t)(buffer_width*buffer_height)&&x<buffer_width&&x>0)
|
||||
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)&&x<buffer_width&&x>0)
|
||||
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];
|
||||
int vector=0;
|
||||
int vstate=0;
|
||||
|
||||
int vfb_width=(width-2)*2;
|
||||
int vfb_height=(height-2)*4;
|
||||
for(uint64_t i=0;i < simdata->terminal_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{
|
||||
if(c>=' '&&c<='~'){
|
||||
mvwprintw(general_terminal_output,term_curs_y+1,term_curs_x+1,"%c",c);
|
||||
term_curs_x++;
|
||||
@ -562,20 +666,18 @@ int update_general_terminal_output(struct simdata_t *simdata){
|
||||
for(int i=0;i<width;i++){
|
||||
mvwprintw(general_terminal_output,term_curs_y+1,i," ");
|
||||
}
|
||||
box(general_terminal_output, 0 , 0);
|
||||
mvwprintw(general_terminal_output,0,width/2-7,"[ TERM OUTPUT ]");
|
||||
}
|
||||
}else{
|
||||
switch(c){
|
||||
case 0xffffffff:
|
||||
vector=1;
|
||||
break;
|
||||
case 0x0a:
|
||||
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<width;i++){
|
||||
mvwprintw(general_terminal_output,term_curs_y+1,i," ");
|
||||
}
|
||||
box(general_terminal_output, 0 , 0);
|
||||
mvwprintw(general_terminal_output,0,width/2-7,"[ TERM OUTPUT ]");
|
||||
}
|
||||
@ -589,7 +691,16 @@ int update_general_terminal_output(struct simdata_t *simdata){
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
|
20
test.asm
20
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
|
||||
|
Loading…
Reference in New Issue
Block a user