Aviator on the BBC Micro

# Drawing lines: DrawClippedLine (Part 3 of 6)

```       Name: DrawClippedLine (Part 3 of 6)                           [Show more]
Type: Subroutine
Category: Drawing lines
Summary: Work out whether the line's end point is on-screen
Context: See this subroutine in context in the source code
References: No direct references to this subroutine in this source file

\ We now repeat the above process, but for the line's
\ end point, whose y-coordinate is in (H G) and
\ x-coordinate is in (QQ W). Refer to the previous part
\ for a detailed description

LDA #0                 \ Set A = 0 so we can capture bits 4 to 7 for the end
\ point

LDX G                  \ Set (Y X) to the end point's y-coordinate in (H G)
LDY H

BEQ draw7              \ This section sets the following:
PHP                    \
LDX #0                 \   * If H < 0, C = 0 and X = 0
PLP                    \   * If H = 0, C = 1 and X = G
CLC                    \   * If H > 0, C = 1 and X = 255
BMI draw8
DEX

.draw7

SEC                    \ See above

.draw8

ROR A                  \ This section sets bits 6 and 7, which will become
CPX #152               \ bits 4 and 5 of the final result:
ROR A                  \
EOR #%01000000         \                             Bit 6 (4)     Bit 7 (5)
\   Off top of screen            0             1
\   On-screen                    0             0
\   Off bottom of screen         1             0

LDX W                  \ Set (Y X) to the end point's x-coordinate in (QQ W)
LDY QQ

BEQ draw9              \ This section sets the following:
PHP                    \
LDX #0                 \   * If QQ < 0, X = 0
PLP                    \   * If QQ = 0, X = W
BMI draw9              \   * If QQ > 0, X = 255
DEX

.draw9

CPX #4                 \ This section sets bits 6 and 7:
ROR A                  \
CPX #156               \                             Bit 6     Bit 7
ROR A                  \   Off right of screen         0         1
EOR #%01000000         \   On-screen                   0         0
\   Off left of screen          1         0

STA UU                 \ Store A in UU
\
\ So UU contains the clipping requirements for the end
\ point, in bits 4 to 7, as follows:
\
\                             Bit 4     Bit 5
\   Off top of screen           0         1
\   On-screen                   0         0
\   Off bottom of screen        1         0
\
\                             Bit 6     Bit 7
\   Off right of screen         0         1
\   On-screen                   0         0
\   Off left of screen          1         0
```