Skip to navigation


Drawing lines: DrawClippedLine (Part 5 of 6)

Name: DrawClippedLine (Part 5 of 6) [Show more] Type: Subroutine Category: Drawing lines Summary: Calculate the deltas for our clipped vector line
Context: See this subroutine in context in the source code References: No direct references to this subroutine in this source file
.draw15 LDA #4 \ If bit 7 of V is set, so the direction of the x-delta BIT V \ is to the left, set A = 4 BMI draw16 LDA #155 \ Otherwise the direction of the x-delta is to the \ right, so set A = 155 .draw16 STA W \ Set W = 4 or 155, depending on the direction of the \ x-delta, so W is the value of the x-coordinate at the \ edge of the screen in the direction given in V LDA #0 \ If bit 6 of V is set, so the direction of the y-delta BVS draw17 \ is down, set A = 0 LDA #151 \ Otherwise the direction of the y-delta is up, so set \ A = 151 .draw17 STA G \ Set G = 0 or 151, depending on the direction of the \ y-delta, so W is the value of the y-coordinate at the \ edge of the screen in the direction given in V JMP draw19 \ Jump to draw19 .draw18 LSR I \ Right-shift (I T) ROR T LSR J \ Right-shift (J U) ROR U .draw19 \ Back in part 1 we set the following values: \ \ * (I T) is the line's |x-delta| \ * (J U) is the line's |y-delta| \ \ We now reduce these 16-bit values to 8-bit values by \ shifting them until they fit into one byte each LDA I \ If the high bytes of either of the line delta's is ORA J \ non-zero, loop up to draw18 to right-shift both deltas BNE draw18 \ We now have the following: \ \ * T = |x-delta| \ * U = |y-delta| LDA #255 \ If T <> 255, jump to draw20 CMP T BNE draw20 LSR T \ T = 255, which is too big to use as our line delta, so LSR U \ divide both T and U by 2 .draw20 CMP U \ If U <> 255, jump to draw21 BNE draw21 LSR T \ U = 255, which is too big to use as our line delta, so LSR U \ divide both T and U by 2 .draw21 INC T \ Increment T to give us our final |x-delta|, so it is \ at least 1 INC U \ Increment U to give us our final |y-delta|, so it is \ at least 1