Skip to navigation

Elite on the BBC Micro and NES

Version analysis of LL9 (Part 10 of 12)

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

Code variations between these versions are shown below.

Name: LL9 (Part 10 of 12) Type: Subroutine Category: Drawing ships Summary: Draw ship: Calculate the visibility of each of the ship's edges

Code variation 1 of 15A variation in the comments only

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

and draw the visible ones using flicker-free animation
Deep dive: Drawing ships
This part calculates which edges are visible - in other words, which lines we should draw - and clips them to fit on the screen.

Code variation 2 of 15A variation in the comments only

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

Visible edges are drawn using flicker-free animation, which erases the corresponding edge from the on-screen ship at the same time.
When we get here, the heap at XX3 contains all the visible vertex screen coordinates.
.LL170 LDY #3 \ Fetch byte #3 of the ship's blueprint, which contains CLC \ the low byte of the offset to the edges data LDA (XX0),Y ADC XX0 \ Set V = low byte edges offset + XX0 STA V LDY #16 \ Fetch byte #16 of the ship's blueprint, which contains LDA (XX0),Y \ the high byte of the offset to the edges data ADC XX0+1 \ Set V+1 = high byte edges offset + XX0+1 STA V+1 \ \ So V(1 0) now points to the start of the edges data \ for this ship

Code variation 3 of 15Minor and very low-impact

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

LDY #5 \ Fetch byte #5 of the ship's blueprint, which contains LDA (XX0),Y \ the maximum heap size for plotting the ship (which is STA T1 \ 1 + 4 * the maximum number of visible edges) and store \ it in T1 LDY XX17 \ Set Y to the edge counter in XX17
LDY #5 \ Fetch byte #5 of the ship's blueprint, which contains LDA (XX0),Y \ the maximum heap size for plotting the ship (which is STA CNT \ 1 + 4 * the maximum number of visible edges) and store \ it in CNT
.LL75

Code variation 4 of 15Specific to an individual platform

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

LDY #0 \ Set Y = 0 so we start with byte #0
 LDA (V),Y              \ Fetch byte #0 for this edge, which contains the
                        \ visibility distance for this edge, beyond which the
                        \ edge is not shown

Code variation 5 of 15Minor and very low-impact

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

CMP XX4 \ If XX4 > the visibility distance, where XX4 contains BCC LL78 \ the ship's z-distance reduced to 0-31 (which we set in \ part 2), then this edge is too far away to be visible, \ so jump down to LL78 to move on to the next edge
CMP XX4 \ If XX4 > the visibility distance, where XX4 contains BCC LL79-3 \ the ship's z-distance reduced to 0-31 (which we set in \ part 2), then this edge is too far away to be visible, \ so jump down to LL78 (via LL79-3) to move on to the \ next edge
 INY                    \ Increment Y to point to byte #1

 LDA (V),Y              \ Fetch byte #1 for this edge into A, so:
                        \
                        \   A = %ffff ffff, where:
                        \
                        \     * Bits 0-3 = the number of face 1
                        \
                        \     * Bits 4-7 = the number of face 2

Code variation 6 of 15Specific to an individual platform

This variation is blank in the Master version.

INY \ Increment Y to point to byte #2
 STA P                  \ Store byte #1 into P

 AND #%00001111         \ Extract the number of face 1 into X
 TAX

 LDA XX2,X              \ If XX2+X is non-zero then we decided in part 5 that
 BNE LL79               \ face 1 is visible, so jump to LL79

 LDA P                  \ Fetch byte #1 for this edge into A

 LSR A                  \ Shift right four times to extract the number of face 2
 LSR A                  \ from bits 4-7 into X
 LSR A
 LSR A
 TAX

Code variation 7 of 15Minor and very low-impact

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

LDA XX2,X \ If XX2+X is zero then we decided in part 5 that BEQ LL78 \ face 2 is hidden, so jump to LL78
LDA XX2,X \ If XX2+X is non-zero then we decided in part 5 that BNE LL79 \ face 2 is visible, so skip the following instruction JMP LL78 \ Face 2 is hidden, so jump to LL78
.LL79

                        \ We now build the screen line for this edge, as
                        \ follows:
                        \
                        \   XX15(1 0) = start x-coordinate
                        \
                        \   XX15(3 2) = start y-coordinate
                        \
                        \   XX15(5 4) = end x-coordinate
                        \
                        \   XX12(1 0) = end y-coordinate
                        \
                        \ We can then pass this to the line clipping routine
                        \ before storing the resulting line in the ship line
                        \ heap

Code variation 8 of 15Specific to an individual platform

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

INY \ Increment Y to point to byte #2
 LDA (V),Y              \ Fetch byte #2 for this edge into X, which contains
 TAX                    \ the number of the vertex at the start of the edge

Code variation 9 of 15Specific to an individual platform

This variation is blank in the Master version.

INY \ Increment Y to point to byte #3 LDA (V),Y \ Fetch byte #3 for this edge into Q, which contains STA Q \ the number of the vertex at the end of the edge

Code variation 10 of 15Minor and very low-impact

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

LDA XX3+1,X \ Fetch the x_hi coordinate of the edge's start vertex STA XX15+1 \ from the XX3 heap into XX15+1 LDA XX3,X \ Fetch the x_lo coordinate of the edge's start vertex STA XX15 \ from the XX3 heap into XX15
LDA XX3,X \ Fetch the x_lo coordinate of the edge's start vertex STA XX15 \ from the XX3 heap into XX15 LDA XX3+1,X \ Fetch the x_hi coordinate of the edge's start vertex STA XX15+1 \ from the XX3 heap into XX15+1
 LDA XX3+2,X            \ Fetch the y_lo coordinate of the edge's start vertex
 STA XX15+2             \ from the XX3 heap into XX15+2

 LDA XX3+3,X            \ Fetch the y_hi coordinate of the edge's start vertex
 STA XX15+3             \ from the XX3 heap into XX15+3

Code variation 11 of 15Specific to an individual platform

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

LDX Q \ Set X to the number of the vertex at the end of the \ edge, which we stored in Q
INY \ Increment Y to point to byte #3 LDA (V),Y \ Fetch byte #3 for this edge into X, which contains TAX \ the number of the vertex at the end of the edge
 LDA XX3,X              \ Fetch the x_lo coordinate of the edge's end vertex
 STA XX15+4             \ from the XX3 heap into XX15+4

Code variation 12 of 15Minor and very low-impact

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

LDA XX3+3,X \ Fetch the y_hi coordinate of the edge's end vertex STA XX12+1 \ from the XX3 heap into XX11+1 LDA XX3+2,X \ Fetch the y_lo coordinate of the edge's end vertex STA XX12 \ from the XX3 heap into XX12
LDA XX3+2,X \ Fetch the y_lo coordinate of the edge's end vertex STA XX12 \ from the XX3 heap into XX12 LDA XX3+3,X \ Fetch the y_hi coordinate of the edge's end vertex STA XX12+1 \ from the XX3 heap into XX11+1
 LDA XX3+1,X            \ Fetch the x_hi coordinate of the edge's end vertex
 STA XX15+5             \ from the XX3 heap into XX15+5

Code variation 13 of 15A variation in the labels only

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

JSR LL147 \ Call LL147 to see if the new line segment needs to be \ clipped to fit on-screen, returning the clipped line's \ end-points in (X1, Y1) and (X2, Y2)
JSR CLIP2 \ Call CLIP2 to see if the new line segment needs to be \ clipped to fit on-screen, returning the clipped line's \ end-points in (X1, Y1) and (X2, Y2)

Code variation 14 of 15Minor and very low-impact

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

BCS LL78 \ If the C flag is set then the line is not visible on \ screen, so jump to LL78 so we don't store this line \ in the ship line heap
BCS LL79-3 \ If the C flag is set then the line is not visible on \ screen, so jump to LL78 (via LL79-3) so we don't store \ this line in the ship line heap JMP LL80 \ Jump down to part 11 to draw this edge

Code variation 15 of 15Related to the Master version

The Master implements flicker-free ship drawing using the LSPUT routine, which manages the erasing and drawing of individual lines.

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

JSR LSPUT \ Draw this edge using flicker-free animation, by first \ drawing the ship's new line and then erasing the \ corresponding old line from the screen