Aviator on the BBC Micro

# Drawing lines: ClipStartOfLine (Part 2 of 5)

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

If slope is /
(UU TT) = |start_x + start_y - 159|
Clear bit 7 of WW

If slope is \
(UU TT) = |start_y - start_x|
Set bit 7 of WW

(Q P) = |x-delta| + |y-delta| + 2

.clip5

LDA V                  \ If either bit 7 or bit 6 of V are set, but not both,
ASL A                  \ then if we EOR them we will get a 1, so this jumps to
EOR V                  \ clip6 if this is the case
BMI clip6

\ If we get here then bits 6 and 7 of V are the same, so
\ the line slope is up-right or down-left, i.e. /

LDA #0                 \ Set WW = 0, so bit 7 is clear
STA WW

LDA R                  \ Set (UU TT) = (RR R) + (SS S)
CLC                    \
ADC S                  \ starting with the low bytes
STA TT

LDA RR                 \ And then the high bytes
STA UU

LDA TT                 \ Set (UU TT) = (UU TT) - 159
SEC                    \
SBC #159               \ starting with the low bytes
STA TT

LDA UU                 \ And then the high bytes, so we now have:
SBC #0                 \
STA UU                 \   (UU TT) = start_x + start_y - 159

JMP clip7

.clip6

\ If we get here then bits 6 and 7 of V are different,
\ so the line slope is up-right or down-left, i.e. \

LDA #%10000000         \ Set WW = %10000000, so bit 7 is set
STA WW

LDA S                  \ Set (UU TT) = (SS S) - (RR R)
SEC                    \
SBC R                  \ starting with the low bytes
STA TT

LDA SS                 \ And then the high bytes, so now we have:
SBC RR                 \
STA UU                 \   (UU TT) = start_y - start_x

.clip7

LDA #0                 \ Set (UU TT) = 0 - (UU TT)
SEC                    \
SBC TT                 \ starting with the low bytes
STA TT

LDA #0                 \ And then the high bytes, so (UU TT) is now positive,
SBC UU                 \ so:
STA UU                 \
\   (UU TT) = |UU TT|
\           = |start_x + start_y - 159| if slope is /
\             |start_y - start_x|       if slope is \

.clip8

LDA T                  \ Set (Q P) = (I T) + (J U)
CLC                    \
ADC U                  \ starting with the low bytes
STA P

LDA I                  \ And then the high bytes, so: