Elite on the BBC Micro and NES

# Version analysis of EDGES

This code appears in the following versions (click to see it in the source code):

Code variations between these versions are shown below.

```       Name: EDGES
Type: Subroutine
Category: Drawing lines
Summary: Draw a horizontal line given a centre and a half-width

Set X1 and X2 to the x-coordinates of the ends of the horizontal line with
centre x-coordinate YY(1 0), and length A in either direction from the centre
(so a total line length of 2 * A). In other words, this line:

X1             YY(1 0)             X2
+-----------------+-----------------+
<- A ->           <- A ->

The resulting line gets clipped to the edges of the screen, if needed. If the
calculation doesn't overflow, we return with the C flag clear, otherwise the C
flag gets set to indicate failure and the Y-th LSO entry gets set to 0.

Arguments:

A                    The half-length of the line

YY(1 0)              The centre x-coordinate

Returns:

C flag               Clear if the line fits on-screen, set if it doesn't

X1, X2               The x-coordinates of the clipped line

LSO+Y                If the line doesn't fit, LSO+Y is set to 0

Y                    Y is preserved

```

Code variation 1 of 5A variation in the comments only

This variation is blank in the Cassette, Disc (flight), 6502 Second Processor and Master versions.

```Docked Other entry points:

PL44                 Clear the C flag and return from the subroutine
```
```
.EDGES

STA T                  \ Set T to the line's half-length in argument A

CLC                    \ We now calculate:
STA X2                 \  (A X2) = YY(1 0) + A
\
\ to set X2 to the x-coordinate of the right end of the
\ line, starting with the low bytes

LDA YY+1               \ And then adding the high bytes

BMI ED1                \ If the addition is negative then the calculation has

BEQ P%+6               \ If the high byte A from the result is 0, skip the
\ next two instructions, as the result already fits on
\ the screen

```

Code variation 2 of 5Specific to an individual platform

Tap on a block to expand it, and tap it again to revert.

```Cassette, Flight, Docked, 6502SPMaster LDA #254               \ The high byte is positive and non-zero, so we went
STA X2                 \ past the right edge of the screen, so clip X2 to the
\ x-coordinate of the right edge of the screen
LDA #255               \ The high byte is positive and non-zero, so we went
STA X2                 \ past the right edge of the screen, so clip X2 to the
\ x-coordinate of the right edge of the screen
```
``` LDA YY                 \ We now calculate:
SEC                    \
SBC T                  \   (A X1) = YY(1 0) - argument A
STA X1                 \
\ to set X1 to the x-coordinate of the left end of the
\ line, starting with the low bytes

LDA YY+1               \ And then subtracting the high bytes
SBC #0

BNE ED3                \ If the high byte subtraction is non-zero, then skip
\ to ED3

CLC                    \ Otherwise the high byte of the subtraction was zero,
\ so the line fits on-screen and we clear the C flag to
\ indicate success

RTS                    \ Return from the subroutine

.ED3

BPL ED1                \ If the addition is positive then the calculation has

```

Code variation 3 of 5Specific to an individual platform

Tap on a block to expand it, and tap it again to revert.

```Cassette, Flight, Docked, 6502SPMaster LDA #2                 \ The high byte is negative and non-zero, so we went
STA X1                 \ past the left edge of the screen, so clip X1 to the
\ x-coordinate of the left edge of the screen
LDA #0                 \ The high byte is negative and non-zero, so we went
STA X1                 \ past the left edge of the screen, so clip X1 to the
\ x-coordinate of the left edge of the screen
```

Code variation 4 of 5A variation in the labels only

This variation is blank in the Cassette, Disc (flight), 6502 Second Processor and Master versions.

```Docked.PL44
```
``` CLC                    \ The line does fit on-screen, so clear the C flag to
\ indicate success

RTS                    \ Return from the subroutine

.ED1

LDA #0                 \ Set the Y-th byte of the LSO block to 0
STA LSO,Y

```

Code variation 5 of 5Minor and very low-impact

Tap on a block to expand it, and tap it again to revert.

```Cassette, Flight, 6502SP, MasterDocked SEC                    \ The line does not fit on the screen, so set the C flag
\ to indicate this result

RTS                    \ Return from the subroutine
\ The line does not fit on the screen, so fall through
\ into PL21 to set the C flag to indicate this result
```