From e3769421bb4330327fe45072ca7667b10f28f090 Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Mon, 18 Sep 2023 00:12:20 -0400 Subject: [PATCH] second: fix off-by-one error in box/vlin drawing --- demos/second/part18_3d/3d.inc | 110 +++++++++++++++++++++++++++- demos/second/part18_3d/draw_boxes.s | 50 +++++++++++-- 2 files changed, 151 insertions(+), 9 deletions(-) diff --git a/demos/second/part18_3d/3d.inc b/demos/second/part18_3d/3d.inc index 82c65b9a..40da6e8e 100644 --- a/demos/second/part18_3d/3d.inc +++ b/demos/second/part18_3d/3d.inc @@ -8,7 +8,7 @@ ; BOX x1,y1 to x2,y2 ; CLEAR - -num_scenes=5 +num_scenes=8 frame15: .byte SET_COLOR | BLACK @@ -26,6 +26,19 @@ frame15: ; .byte SET_COLOR | DARK_BLUE ; .byte HLIN,0,39,13 +; .byte SET_COLOR | GREEN +; .byte BOX, 2,2,3,3 ; goes to 6 only top +; .byte BOX, 4,3,5,4 +; .byte BOX, 6,4,7,5 +; .byte BOX, 8,5,9,6 + +; .byte SET_COLOR | GREEN +; .byte VLIN, 2,3,2 ; goes to 6 only top +; .byte VLIN, 3,4,4 +; .byte VLIN, 4,5,6 +; .byte VLIN, 5,6,8 + + ; .byte SET_COLOR | GREEN ; .byte BOX, 2,2,10,12 ; goes to 6 only top ; .byte BOX, 12,3,20,12 @@ -126,3 +139,98 @@ frame19: .byte HLIN, 30, 35, 28 .byte VLIN, 21, 26, 28 .byte END + +frame20: + .byte SET_COLOR | BLACK + .byte CLEAR + .byte SET_COLOR | BROWN + .byte BOX, 4, 6, 35,41 + .byte SET_COLOR | MEDIUM_BLUE + .byte BOX, 18, 9, 21, 17 + .byte BOX, 26, 10, 29, 17 + .byte BOX, 34, 10, 35, 17 + .byte BOX, 18, 26, 21, 33 + .byte BOX, 25, 26, 29, 33 + .byte BOX, 34, 30, 35, 34 + .byte SET_COLOR | LIGHT_BLUE + .byte BOX, 31, 21, 35, 27 + .byte HLIN, 32, 35, 20 + .byte HLIN, 34, 35, 29 + .byte SET_COLOR | GREY1 + .byte BOX, 34, 22, 35, 28 + .byte HLIN, 32, 35, 24 + .byte HLIN, 4,6,39 + .byte HLIN, 4,19,40 + .byte HLIN, 4,29,41 + .byte SET_COLOR | RED + .byte HLIN, 34, 35, 26 + .byte SET_COLOR | ORANGE + .byte PLOT, 33, 25 + .byte END + +frame21: + .byte SET_COLOR | BLACK + .byte CLEAR + .byte SET_COLOR | BROWN + .byte BOX, 4, 6, 35, 41 + .byte SET_COLOR | MEDIUM_BLUE + .byte BOX, 7, 7, 11, 16 + .byte BOX, 16, 8, 20, 16 + .byte BOX, 25, 9, 28, 17 + .byte BOX, 33, 9, 35, 17 + .byte BOX, 7, 25, 11, 34 + .byte BOX, 16,26, 20, 34 + .byte BOX, 25,26, 28, 34 + .byte BOX, 33,28, 35, 33 + .byte SET_COLOR | GREY1 + .byte BOX, 32,20,35,21 + .byte SET_COLOR | LIGHT_BLUE + .byte BOX, 31, 22, 35,26 + .byte HLIN, 33, 35, 21 + .byte HLIN, 32, 35, 27 + .byte SET_COLOR | GREY1 + .byte BOX, 33,23,35,24 + .byte SET_COLOR | ORANGE + .byte VLIN, 24,26,35 + .byte END + +frame22: + .byte SET_COLOR | BLACK + .byte CLEAR + .byte SET_COLOR | GREY1 + .byte BOX, 4,6,31,41 + .byte SET_COLOR | BROWN + .byte BOX, 32, 6, 35, 32 + .byte SET_COLOR | MEDIUM_BLUE + .byte BOX, 4, 6, 5, 14 + .byte BOX, 12, 7, 15, 15 + .byte BOX, 20, 8, 23, 16 + .byte BOX, 4, 25, 5, 35 + .byte BOX, 11,25, 15, 34 + .byte BOX, 20,25, 22, 33 + .byte SET_COLOR | GREY1 + .byte BOX, 32,22,35,25 + .byte BOX, 32,32,33,41 + .byte BOX, 34,33,35,41 + .byte SET_COLOR | LIGHT_BLUE + .byte BOX, 30,20,33,21 + .byte HLIN, 30,31,19 + .byte BOX, 30,24,31,26 + .byte PLOT, 32,25 + .byte SET_COLOR | ORANGE + .byte HLIN, 33,34,24 + .byte PLOT, 33,23 + .byte SET_COLOR | DARK_BLUE + .byte VLIN, 19,26,29 + .byte HLIN, 30,32,22 + .byte HLIN, 30,31,23 + .byte SET_COLOR | LIGHT_BLUE + .byte PLOT, 31,22 + .byte SET_COLOR | BLACK + .byte BOX, 31,34, 33,35 + .byte BOX, 32,35, 35,36 + .byte HLIN, 34,35,37 + .byte END + + + diff --git a/demos/second/part18_3d/draw_boxes.s b/demos/second/part18_3d/draw_boxes.s index 8082da27..6ac42cf3 100644 --- a/demos/second/part18_3d/draw_boxes.s +++ b/demos/second/part18_3d/draw_boxes.s @@ -16,6 +16,7 @@ CLEAR = $01 BOX = $02 HLIN = $03 VLIN = $04 +PLOT = $05 BLACK = $00 RED = $01 @@ -111,6 +112,17 @@ clear_screen: ; draw box ;================================= ;================================= + + ; blurgh. Cases + ; Y1=EVEN, Y2=ODD -> loop Y1/2 to Y2/2, inclusive + ; Y1=ODD, Y2=ODD -> HLIN, loop (Y1/2)+1 to Y2/2 inclusive + ; Y1=EVEN, Y2=EVEN-> loop Y1/2 to (Y2/2)-1, HLIN + ; Y1=ODD, Y2=EVEN -> HLIN, loop (Y1/2)+1 to (Y2/2)-1, HLIN + ; 2/3 case, 1 to 1 + ; 3/5 case, (>1) 2 to 2 + ; 2/4 case, 1 to 1 (<2) + ; 3/4 case, 2 to 1 (!) + ; 3/6 case, 2 to 2 draw_box: iny lda (INL),Y @@ -154,6 +166,14 @@ odd_bottom_draw_box: even_draw_box_start: draw_box_yloop: + +draw_box_yend_smc: + cpy #0 + bcc bbbb + beq bbbb + jmp done_draw_box_yloop ; bge + +bbbb: lda gr_offsets_l,Y sta draw_box_xloop_smc+1 @@ -172,11 +192,14 @@ draw_box_xloop_smc: bcs draw_box_xloop ; bge iny -draw_box_yend_smc: - cpy #0 - bcc draw_box_yloop ; less than - beq draw_box_yloop ; equal +;draw_box_yend_smc: +; cpy #0 +; bcc draw_box_yloop ; less than +; beq draw_box_yloop ; equal + jmp draw_box_yloop + +done_draw_box_yloop: ; done ; if Y2 was even we need to fixup and draw one more line @@ -272,6 +295,14 @@ odd_bottom_vlin: even_vlin_start: vlin_yloop: +vlin_yend_smc: + cpy #0 + bcc cccc + beq cccc + jmp done_vlin_yloop ; + +cccc: + lda gr_offsets_l,Y sta vlin_xloop_smc+1 @@ -287,12 +318,15 @@ vlin_xloop_smc: sta $400,X iny -vlin_yend_smc: - cpy #0 - bcc vlin_yloop ; less than - beq vlin_yloop ; equal +;vlin_yend_smc: +; cpy #0 +; bcc vlin_yloop ; less than +; beq vlin_yloop ; equal + + jmp vlin_yloop ; done +done_vlin_yloop: ; if Y2 was even we need to fixup and draw one more line