Elite on the BBC Micro and NES

# Drawing pixels: PIXEL2

## [BBC Master version]

```       Name: PIXEL2                                                  [Show more]
Type: Subroutine
Category: Drawing pixels
Summary: Draw a stardust particle relative to the screen centre
Context: See this subroutine in context in the source code
Variations: See code variations for this subroutine in the different versions
References: This subroutine is called as follows:
* FLIP calls PIXEL2
* nWq calls PIXEL2
* STARS1 calls PIXEL2
* STARS2 calls PIXEL2
* STARS6 calls PIXEL2

Draw a point (X1, Y1) from the middle of the screen with a size determined by
a distance value. Used to draw stardust particles.

Arguments:

X1                   The x-coordinate offset

Y1                   The y-coordinate offset (positive means up the screen
from the centre, negative means down the screen)

ZZ                   The distance of the point (further away = smaller point)

.PIXEL2

LDA X1                 \ Fetch the x-coordinate offset into A

BPL PX21               \ If the x-coordinate offset is positive, jump to PX21
\ to skip the following negation

EOR #%01111111         \ The x-coordinate offset is negative, so flip all the
CLC                    \ bits apart from the sign bit and add 1, to convert it
ADC #1                 \ from a sign-magnitude number to a signed number

.PX21

EOR #%10000000         \ Set X = X1 + 128
TAX                    \
\ So X is now the offset converted to an x-coordinate,
\ centred on x-coordinate 128

LDA Y1                 \ Fetch the y-coordinate offset into A and clear the
AND #%01111111         \ sign bit, so A = |Y1|

CMP #96                \ If |Y1| >= 96 then it's off the screen (as 96 is half
BCS PXR1               \ the screen height), so return from the subroutine (as
\ PXR1 contains an RTS)

LDA Y1                 \ Fetch the y-coordinate offset into A

BPL PX22               \ If the y-coordinate offset is positive, jump to PX22
\ to skip the following negation

EOR #%01111111         \ The y-coordinate offset is negative, so flip all the
ADC #1                 \ bits apart from the sign bit and add 1, to convert it
\ from a sign-magnitude number to a signed number

.PX22

STA T                  \ Set A = 97 - Y1
LDA #97                \
SBC T                  \ So if Y is positive we display the point up from the
\ centre at y-coordinate 97, while a negative Y means
\ down from the centre

\ Fall through into PIXEL to draw the stardust at the
\ screen coordinates in (X, A)
```