.LL30 SKIP 0 ; LL30 is a synonym for LOIN ; ; In the BBC Micro cassette and disc versions of Elite, ; LL30 and LOIN are synonyms for the same routine, ; presumably because the two developers each had their ; own line routines to start with, and then chose one of ; them for the final game .LOIN STY YSAV ; Store Y into YSAV, so we can preserve it across the ; call to this subroutine LDA #128 ; Set S2 = 128, which is the starting point for the STA S2 ; slope error (representing half a pixel) ASL A ; Set SWAP = 0, as %10000000 << 1 = 0 STA SWAP LDA X2 ; Set A = X2 - X1 SBC X1 ; = delta_x ; ; This subtraction works as the ASL A above sets the C ; flag BCS LI1 ; If X2 > X1 then A is already positive and we can skip ; the next three instructions EOR #%11111111 ; Negate the result in A by flipping all the bits and ADC #1 ; adding 1, i.e. using two's complement to make it ; positive .LI1 STA P2 ; Store A in P2, so P2 = |X2 - X1|, or |delta_x| SEC ; Set the C flag, ready for the subtraction below LDA Y2 ; Set A = Y2 - Y1 SBC Y1 ; = delta_y ; ; This subtraction works as we either set the C flag ; above, or we skipped that SEC instruction with a BCS BCS LI2 ; If Y2 > Y1 then A is already positive and we can skip ; the next two instructions EOR #%11111111 ; Negate the result in A by flipping all the bits and ADC #1 ; adding 1, i.e. using two's complement to make it ; positive .LI2 STA Q2 ; Store A in Q2, so Q2 = |Y2 - Y1|, or |delta_y| CMP P2 ; If Q2 < P2, jump to STPX to step along the x-axis, as BCC STPX ; the line is closer to being horizontal than vertical JMP STPY ; Otherwise Q2 >= P2 so jump to STPY to step along the ; y-axis, as the line is closer to being vertical than ; horizontalName: LOIN (Part 1 of 7) [Show more] Type: Subroutine Category: Drawing lines Summary: Draw a line: Calculate the line gradient in the form of deltas Deep dive: Bresenham's line algorithmContext: See this subroutine in context in the source code References: This subroutine is called as follows: * BLINE calls LOIN * WPLS2 calls LOIN * LASLI calls via LL30 * LL9 (Part 12 of 12) calls via LL30 * NLIN2 calls via LL30 * TT15 calls via LL30
This routine draws a line from (X1, Y1) to (X2, Y2). It has multiple stages. This stage calculates the line deltas.
Arguments: X1 The screen x-coordinate of the start of the line Y1 The screen y-coordinate of the start of the line X2 The screen x-coordinate of the end of the line Y2 The screen y-coordinate of the end of the line
Returns: Y Y is preserved
Other entry points: LL30 LL30 is a synonym for LOIN and draws a line from (X1, Y1) to (X2, Y2)
[X]
Label LI1 is local to this routine
[X]
Label LI2 is local to this routine
[X]
Label STPX in subroutine LOIN (Part 2 of 7)
[X]
Label STPY in subroutine LOIN (Part 5 of 7)