Skip to navigation

Aviator on the BBC Micro

Drawing lines: ClipStartOfLine (Part 3 of 5)

Name: ClipStartOfLine (Part 3 of 5) [Show more] Type: Subroutine Category: Drawing lines Summary: Work out the deltas depending on the steepness of slope
Context: See this subroutine in context in the source code References: No direct references to this subroutine in this source file

Shallow horizontal: Bit 7 of HH = direction of the y-delta (PP N) = |x-delta| + 1 Clear bit 6 of WW Steep vertical: Bit 7 of HH = direction of the x-delta (PP N) = |y-delta| + 1 Set bit 6 of WW Set (RR R) = (SS S), so start_x is set to start_y
.clip9 LDA #0 \ Set K = 0, though this has no effect as we don't use STA K \ K in the following LDA I \ If I < J, then (I T) < (J U), so jump to clip11 CMP J BCC clip11 BNE clip10 \ If I > J, then (I T) > (J U), so jump to clip10 \ If we get here then I = J LDA T \ If T < U, then (I T) < (J U), so jump to clip11 CMP U BCC clip11 .clip10 \ If we get here, then (I T) >= (J U), which is the same \ as |x-delta| >= |y-delta|, so this is a shallow \ horizontal slope LDA V \ Set HH = V STA HH \ \ so bit 7 of HH is set to bit 7 of V, i.e. the \ direction of the y-delta LDA T \ Set (PP N) = (I T) + 1 CLC \ ADC #1 \ starting with the low bytes STA N LDA I \ And then the high bytes, so: ADC #0 \ STA PP \ (PP N) = |x-delta| + 1 JMP clip12 \ Jump down to clip12 to move on to the next stage .clip11 \ If we get here, then (I T) < (J U), which is the same \ as |x-delta| < |y-delta|, so this is a steep vertical \ slope LDA V \ Set HH = V << 1 ASL A \ STA HH \ so bit 7 of HH is set to bit 6 of V, i.e. the \ direction of the x-delta LDA U \ Set (PP N) = (J U) + 1 CLC \ ADC #1 \ starting with the low bytes STA N LDA J \ And then the high bytes, so: ADC #0 \ STA PP \ (PP N) = |y-delta| + 1 LDA WW \ Set bit 6 of WW ORA #%01000000 STA WW LDA S \ Set (RR R) = (SS S) STA R \ LDA SS \ so the x-coordinate of the line's start point is now STA RR \ the y-coordinate of the start point