From 19deb0581c09d2234afb65af2e8dccbad356bcc0 Mon Sep 17 00:00:00 2001 From: "(Tim) Efthimis Kritikos" Date: Fri, 16 Feb 2024 17:06:27 +0000 Subject: [PATCH] Project: fixed several small bugs and changed the implementation of the line drawing algorythm for the braille display to one that actually works --- Makefile | 2 +- assembly.c | 6 +++--- cpu.c | 5 +++-- gui.c | 35 ++++++++++++++--------------------- test.asm | 18 +++++++++--------- 5 files changed, 30 insertions(+), 36 deletions(-) diff --git a/Makefile b/Makefile index b301b1a..c381255 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,7 @@ first: ${OBJECT_FILES} %.rom:%.asm first $(QUIET_FAS) - ${Q}./first -i test.asm -a test.rom + ${Q}./first -i $< -a $@ %.o:%.c ${QUIET_CC} diff --git a/assembly.c b/assembly.c index ff39bd5..483a03c 100644 --- a/assembly.c +++ b/assembly.c @@ -328,8 +328,8 @@ int64_t assemble_line(char *line, struct assembler_context_t *assembler_context) while(line[x]==' ')x++; if(line[x]==0||line[x]=='#') return -1;//empty line or comment - if( ((call=strncmp(line,"JMP ",4))==0) || (strncmp(line,"CALL ",5)==0) ){ - if(call){ + if( (strncmp(line,"JMP,",4)==0) || (strncmp(line,"JMP ",4)==0) || ((call=strncmp(line,"CALL ",5))==0) ){ + if(!call){ x=4; opcode=0x10; }else{ @@ -652,7 +652,7 @@ int64_t assemble_line(char *line, struct assembler_context_t *assembler_context) }else{ temp=imm->value; free(imm); - return temp; + return (temp&0xFF000000)>>24|(temp&0x00FF0000)>>8|(temp&0x0000FF00)<<8|(temp&0x000000FF>>24); } }else return -2; diff --git a/cpu.c b/cpu.c index 482997b..cf6f90f 100644 --- a/cpu.c +++ b/cpu.c @@ -82,6 +82,7 @@ int decode(struct simdata_t *simdata){ simdata->exec_data->in_op1->data=op1; simdata->exec_data->in_op2->data=op2; switch(opcode){ + case 0x00: case 0x01: case 0x02: case 0x03: @@ -274,8 +275,8 @@ int exec(struct simdata_t *simdata){ break; case ALU_SUB: case ALU_CMP: - result = simdata->registers->GPR[simdata->exec_data->in_op1->data] - - simdata->registers->GPR[simdata->exec_data->in_op2->data]; + result = simdata->registers->GPR[simdata->exec_data->in_op2->data] - + simdata->registers->GPR[simdata->exec_data->in_op1->data]; simdata->registers->FLAGS=(simdata->registers->FLAGS&0xFFFFFFFD)| (simdata->registers->GPR[simdata->exec_data->out_op->data] > simdata->registers->GPR[simdata->exec_data->in_op1->data])<<1; break; diff --git a/gui.c b/gui.c index 9e44a94..9aaeb3d 100644 --- a/gui.c +++ b/gui.c @@ -574,27 +574,20 @@ int print_braille_frame_buffer(WINDOW* win,uint8_t *buffer,int width,int height) } 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; + + int dx = abs(x1-x0), sx = x0dy ? dx : -dy)/2, e2; + uint32_t addr; - while(x=0){ - addr=x+y*buffer_width; - if(addr>0&&addr<(uint64_t)(buffer_width*buffer_height)&&x0) + for(;;){ + addr=x0+y0*buffer_width; + if(addr>0&&addr<(uint64_t)(buffer_width*buffer_height)&&x00) 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; + if (x0==x1 && y0==y1) break; + e2 = err; + if (e2 >-dx) { err -= dy; x0 += sx; } + if (e2 < dy) { err += dx; y0 += sy; } } } @@ -613,8 +606,8 @@ int update_general_terminal_output(struct simdata_t *simdata){ 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]; + for(uint64_t i=0;i < simdata->terminal_output_size/4;i++){ + uint32_t c=simdata->terminal_output[i]; if(vector){ float x0,y0,x1,y1; switch(vstate){ diff --git a/test.asm b/test.asm index 903b0f2..0900f13 100644 --- a/test.asm +++ b/test.asm @@ -42,20 +42,20 @@ MOV %R1,(%R0) MOV $0x0000,%R1l MOV $0x0000,%R1h MOV %R1,(%R0) -MOV $0xcccd,%R1l -MOV $0xbf4c,%R1h +MOV $0x0000,%R1l +MOV $0xbf80,%R1h MOV %R1,(%R0) -MOV $0xcccd,%R1l -MOV $0xbf4c,%R1h +MOV $0x0000,%R1l +MOV $0xbf80,%R1h MOV %R1,(%R0) -MOV $0xcccd,%R1l -MOV $0x3f4c,%R1h +MOV $0x0000,%R1l +MOV $0x0000,%R1h +MOV %R1,(%R0) +MOV $0x0000,%R1l +MOV $0x3f80,%R1h MOV %R1,(%R0) #Test Indirect read/writes -MOV $0xcccd,%R1l -MOV $0x3f4c,%R1h -MOV %R1,(%R0) MOV $>TR_LOW,%R0l MOV $