This code appears in the following versions (click to see it in the source code):
Code variations between these versions are shown below.
.STPY LDY Y1 \ Set A = Y = Y1 TYA LDX X1 \ Set X = X1 CPY Y2 \ If Y1 >= Y2, jump down to LI15, as the coordinates are BCS LI15 \ already in the order that we want DEC SWAP \ Otherwise decrement SWAP from 0 to &FF, to denote that \ we are swapping the coordinates around LDA X2 \ Swap the values of X1 and X2 STA X1 STX X2 TAX \ Set X = X1 LDA Y2 \ Swap the values of Y1 and Y2 STA Y1 STY Y2 TAY \ Set Y = A = Y1 .LI15 \ By this point we know the line is vertical-ish and \ Y1 >= Y2, so we're going from top to bottom as we go \ from Y1 to Y2Type: Subroutine Category: Drawing lines Summary: Draw a line: Line has a steep gradient, step up along y-axis Deep dive: Elite's line-drawing algorithm
This routine draws a line from (X1, Y1) to (X2, Y2). It has multiple stages. If we get here, then: * |delta_y| >= |delta_x| * The line is closer to being vertical than horizontal * We are going to step up along the y-axis * We potentially swap coordinates to make sure Y1 >= Y2
STA SC \ Store this value in SC, so SC(1 0) now contains the \ screen address of the far left end (x-coordinate = 0) \ of the horizontal pixel row that we want to draw the \ start of our line on
This variation is blank in the Cassette, Disc (flight), Disc (docked) and Electron versions.
BCC P%+4 \ If bit 7 of X1 was set, so X1 > 127, increment the INC SC+1 \ high byte of SC(1 0) to point to the second page on \ this screen row, as this page contains the right half \ of the row
This variation is blank in the Electron version.
Tap on a block to expand it, and tap it again to revert.
LDA TWOS,X \ Fetch a one-pixel byte from TWOS where pixel X is set, STA R \ and store it in R
Part 5 of the LOIN routine in the advanced versions uses logarithms to speed up the multiplication.
This variation is blank in the 6502 Second Processor and Master versions.
LDA Y1 \ Set Y = Y1 mod 8, which is the pixel row within the AND #7 \ character block at which we want to draw the start of TAY \ our line (as each character block has 8 rows)
This variation is blank in the Cassette, Disc (flight), Disc (docked), 6502 Second Processor and Master versions.
TXA \ Set X = X1 mod 8, which is the pixel column within the AND #7 \ character block at which we want to draw the start of TAX \ our line (as each character block has 8 rows) LDA TWOS,X \ Fetch a mode 4 one-pixel byte with the pixel position STA R \ at X and store it in R to act as a mask