From fba8c1f2f41c7b3aba2b8b9f1f5c2d829518d3a5 Mon Sep 17 00:00:00 2001 From: "(Tim) Efthimis Kritikos" Date: Fri, 16 Feb 2024 19:12:03 +0000 Subject: [PATCH] GUI: Added support for double buffering on the vector display for smoother motion --- gui.c | 17 +++++++++++------ programs/3d_renderer.asm | 27 ++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/gui.c b/gui.c index 9aaeb3d..3dd8d9d 100644 --- a/gui.c +++ b/gui.c @@ -598,8 +598,10 @@ int update_general_terminal_output(struct simdata_t *simdata){ 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)); + uint8_t* vector_working_frame_buffer=malloc((height*4)*(width*2)); + uint8_t* vector_display_frame_buffer=malloc((height*4)*(width*2)); + memset(vector_working_frame_buffer,0,(height*4)*(width*2)); + memset(vector_display_frame_buffer,0,(height*4)*(width*2)); int vector=0; int vstate=0; @@ -615,7 +617,9 @@ int update_general_terminal_output(struct simdata_t *simdata){ if(c==0x00000001) vector=0; else if(c==0x00000002) - memset(vector_frame_buffer,0,(height*4)*(width*2)); + memset(vector_working_frame_buffer,0,(height*4)*(width*2)); + else if(c==0x00000003) + memcpy(vector_display_frame_buffer,vector_working_frame_buffer,(height*4)*(width*2)); else vstate++; break; @@ -641,7 +645,7 @@ int update_general_terminal_output(struct simdata_t *simdata){ 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)); + braille_frame_buffer_line(vector_working_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; } @@ -690,10 +694,11 @@ int update_general_terminal_output(struct simdata_t *simdata){ 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); + print_braille_frame_buffer(general_terminal_output,vector_display_frame_buffer,(width-2)*2,(height-2)*4); mvwprintw(general_terminal_output,0,width/2-9,"[ VECTOR DISPLAY ]"); } - free(vector_frame_buffer); + free(vector_working_frame_buffer); + free(vector_display_frame_buffer); return 0; } diff --git a/programs/3d_renderer.asm b/programs/3d_renderer.asm index 6854424..a48ee38 100644 --- a/programs/3d_renderer.asm +++ b/programs/3d_renderer.asm @@ -6,6 +6,23 @@ MOV $0xFFFF,%R1l MOV $0xFFFF,%R1h MOV %R1,(%R4) CALL $RENDER +MOV $>DATA_START,%R0l +MOV $DATA_START,%R0l +MOV $DATA_START,%R0l @@ -16,6 +33,11 @@ MOV $0x0001,%R6l MOV $0x0000,%R6h MOV $0x0004,%R5l MOV $0x0000,%R5h +MOV $0xFFFC,%R4l +MOV $0x00FF,%R4h +MOV $0x0002,%R1l +MOV $0x0000,%R1h #Clear the frame +MOV %R1,(%R4) :RENDER_LOOP MOV $0xFFFF,%R1l MOV $0xFFFF,%R1h @@ -71,7 +93,10 @@ MOV %R2,(%R4) SUB %R6,%R7 JMP,NZ $RENDER_LOOP -HALT +MOV $0x0003,%R1l +MOV $0x0000,%R1h #Display the frame +MOV %R1,(%R4) +RET