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
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.
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.
.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 shipWhen we get here, the heap at XX3 contains all the visible vertex screen coordinates.
.LL75
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
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
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
.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
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 \ \ Byte #2 contains the vertex number multiplied by 4, \ so we can use it as an index into the heap at XX3 to \ fetch the vertex's screen coordinates, which are \ stored as four bytes containing two 16-bit numbers
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 \ \ Byte #3 contains the vertex number multiplied by 4, \ so we can use it as an index into the heap at XX3 to \ fetch the vertex's screen coordinates, which are \ stored as four bytes containing two 16-bit numbers
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
LDA XX3,X \ Fetch the x_lo coordinate of the edge's end vertex STA XX15+4 \ from the XX3 heap into XX15+4
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
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