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){
|
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];
|
*(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)
|
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
|
}else
|
||||||
return 1;
|
return 1;
|
||||||
break;
|
break;
|
||||||
|
182
gui.c
182
gui.c
@ -23,6 +23,7 @@
|
|||||||
#include "assembly.h"
|
#include "assembly.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "cpu.h"
|
#include "cpu.h"
|
||||||
|
#include <locale.h>
|
||||||
|
|
||||||
#define GENERAL_STACK_MAX_WIDTH 16
|
#define GENERAL_STACK_MAX_WIDTH 16
|
||||||
#define GENERAL_DISAS_WIDTH 41
|
#define GENERAL_DISAS_WIDTH 41
|
||||||
@ -114,6 +115,7 @@ void update_tabs(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
int start_gui(){
|
int start_gui(){
|
||||||
|
setlocale(LC_ALL, "");
|
||||||
if(!initscr())
|
if(!initscr())
|
||||||
return 1;
|
return 1;
|
||||||
monochrome=( has_colors() == FALSE );
|
monochrome=( has_colors() == FALSE );
|
||||||
@ -537,59 +539,168 @@ int update_general_registers(struct simdata_t *simdata){
|
|||||||
|
|
||||||
int term_curs_x,term_curs_y;
|
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 update_general_terminal_output(struct simdata_t *simdata){
|
||||||
int width,height;
|
int width,height;
|
||||||
werase(general_terminal_output);
|
werase(general_terminal_output);
|
||||||
getmaxyx(general_terminal_output,height,width);
|
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_x=0;
|
||||||
term_curs_y=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++){
|
int vector=0;
|
||||||
char c=simdata->terminal_output[i];
|
int vstate=0;
|
||||||
if(c>=' '&&c<='~'){
|
|
||||||
mvwprintw(general_terminal_output,term_curs_y+1,term_curs_x+1,"%c",c);
|
int vfb_width=(width-2)*2;
|
||||||
term_curs_x++;
|
int vfb_height=(height-2)*4;
|
||||||
if(term_curs_x>=width-2){
|
for(uint64_t i=0;i < simdata->terminal_output_size;i+=4){
|
||||||
term_curs_x=0;
|
uint32_t c=simdata->terminal_output[i/4];
|
||||||
term_curs_y++;
|
if(vector){
|
||||||
}
|
float x0,y0,x1,y1;
|
||||||
if(term_curs_y>=height-2){
|
switch(vstate){
|
||||||
wscrl(general_terminal_output,1);
|
case 0: /*start of line*/
|
||||||
term_curs_y--;
|
if(c==0x00000001)
|
||||||
for(int i=0;i<width;i++){
|
vector=0;
|
||||||
mvwprintw(general_terminal_output,term_curs_y+1,i," ");
|
else if(c==0x00000002)
|
||||||
}
|
memset(vector_frame_buffer,0,(height*4)*(width*2));
|
||||||
box(general_terminal_output, 0 , 0);
|
else
|
||||||
mvwprintw(general_terminal_output,0,width/2-7,"[ TERM OUTPUT ]");
|
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{
|
}else{
|
||||||
switch(c){
|
if(c>=' '&&c<='~'){
|
||||||
case 0x0a:
|
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_x=0;
|
||||||
term_curs_y++;
|
term_curs_y++;
|
||||||
if(term_curs_y>=height-2){
|
}
|
||||||
wscrl(general_terminal_output,1);
|
if(term_curs_y>=height-2){
|
||||||
term_curs_y--;
|
wscrl(general_terminal_output,1);
|
||||||
for(int i=0;i<width;i++){
|
term_curs_y--;
|
||||||
mvwprintw(general_terminal_output,term_curs_y+1,i," ");
|
for(int i=0;i<width;i++){
|
||||||
|
mvwprintw(general_terminal_output,term_curs_y+1,i," ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}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--;
|
||||||
|
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);
|
box(general_terminal_output, 0 , 0);
|
||||||
mvwprintw(general_terminal_output,0,width/2-7,"[ TERM OUTPUT ]");
|
mvwprintw(general_terminal_output,0,width/2-7,"[ TERM OUTPUT ]");
|
||||||
}
|
mvwprintw(general_terminal_output,1,1,"Invalid output");
|
||||||
break;
|
return 0;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -647,6 +758,7 @@ int gui_continue_request(struct simdata_t *simdata){
|
|||||||
release=1;
|
release=1;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -47,12 +47,12 @@ struct simdata_t *init_simdata(){
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int terminal_output(char c,struct simdata_t *simdata){
|
int terminal_output(uint32_t c,struct simdata_t *simdata){
|
||||||
simdata->terminal_output=realloc(simdata->terminal_output,simdata->terminal_output_size+1);
|
simdata->terminal_output=realloc(simdata->terminal_output,simdata->terminal_output_size+4);
|
||||||
if(!simdata->terminal_output)
|
if(!simdata->terminal_output)
|
||||||
return 1;
|
return 1;
|
||||||
simdata->terminal_output[simdata->terminal_output_size]=c;
|
*(uint32_t*)(simdata->terminal_output+simdata->terminal_output_size/4)=c;
|
||||||
simdata->terminal_output_size++;
|
simdata->terminal_output_size+=4;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ struct simdata_t{
|
|||||||
|
|
||||||
struct cpu_gui_hints_t *cpu_gui_hints;
|
struct cpu_gui_hints_t *cpu_gui_hints;
|
||||||
|
|
||||||
char* terminal_output;
|
uint32_t* terminal_output;
|
||||||
uint64_t terminal_output_size;
|
uint64_t terminal_output_size;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ struct simdata_t *init_simdata();
|
|||||||
void free_simdata(struct simdata_t *);
|
void free_simdata(struct simdata_t *);
|
||||||
int add_to_instr_list(struct instr_list_t **addr_of_toadd,uint32_t address);
|
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);
|
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{
|
enum GUI_CPU_STATE_t{
|
||||||
GUI_CPU_RUNNING,
|
GUI_CPU_RUNNING,
|
||||||
|
20
test.asm
20
test.asm
@ -30,4 +30,22 @@ MOV $0x006c,%R1l
|
|||||||
MOV %R1,(%R0)
|
MOV %R1,(%R0)
|
||||||
MOV $0x006f,%R1l
|
MOV $0x006f,%R1l
|
||||||
MOV %R1,(%R0)
|
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