Aviator on the BBC Micro

# Drawing lines: DrawIndicatorLine

```       Name: DrawIndicatorLine                                       [Show more]
Type: Subroutine
Category: Drawing lines
Summary: Draw a line on indicators 0 to 7, i.e. a dial hand (0-6) or an
artificial horizon (7)
Deep dive: Line buffers
Context: See this subroutine in context in the source code
References: This subroutine is called as follows:
* UpdateIndicator (Part 11 of 15) calls DrawIndicatorLine

Arguments:

S                    Start point x-coordinate (artificial horizon only)

H                    Start point y-coordinate (artificial horizon only)

W                    Magnitude of x-coordinate of line's vector |x-delta|

G                    Magnitude of y-coordinate of line's vector |y-delta|

R                    Direction of vector (T, U):

* Bit 7 is the direction of the x-delta

* Bit 6 is the direction of the y-delta

Direction is like a clock, so positive (clear) is up and
right

X                    The indicator number (0-7)

WW                   The indicator number (0-7)

.DrawIndicatorLine

LDA indicatorLineI,X   \ Set I = x-coordinate of the starting point of the
STA I                  \ current line

LDA indicatorLineJ,X   \ Set J = y-coordinate of the starting point of the
STA J                  \ current line

LDA indicatorLineT,X   \ Set T = x-delta of the current line
STA T

LDA indicatorLineU,X   \ Set U = y-delta of the current line
STA U

LDA indicatorLineV,X   \ Set V = direction of the current line
STA V

LDA #128               \ Set N = 128 so the call to DrawVectorLine erases the
STA N                  \ current line

JSR DrawVectorLine     \ Erase a line from (I, J) as a vector (T, U) with
\ direction V

LDX WW                 \ If this is not indicator 7, jump to dinl2
CPX #7
BNE dinl2

\ If we get here then this is the artificial horizon
\ (indicator 7)

LDA #%11111111         \ Set A to the pixel byte for four white pixels, to use
\ for the bottom row of pixels in the centre block of
\ the artificial horizon's centre line

LDY #2                 \ We want to redraw the three pixel rows in the centre
\ block of the artificial horizon's centre line, which
\ from bottom to top contain 3 pixels, 1 pixel and 1
\ pixel, so so set a counter in Y for 3 bytes

.dinl1

STA row23_block13_2,Y  \ Redraw the Y-th pixel row in the centre block

LDA #%01000100         \ The top two pixel rows of the centre block contain the
\ vertical mark at the centre of the indicator, so set A
\ to the appropriate single-pixel byte

DEY                    \ Decrement the counter to move up to the next pixel row

BPL dinl1              \ Loop back until we have redrawn all three pixel rows
\ in the centre block

LDA #%00110011         \ Redraw the two-pixels at the left end of the
STA row23_block12_4    \ artificial horizon's centre line

LDA #%10001000         \ Redraw the single pixel at the right end of the
STA row23_block14_4    \ artificial horizon's centre line

LDA S                  \ Fetch the x-coordinate of the starting point of the
\ new line from S

STA I                  \ Set I = the x-coordinate of the starting point of the
\ new line to draw

STA indicatorLineI,X   \ Store the x-coordinate in indicatorLineI, so we can
\ use it to erase the line later

LDA H                  \ Set A = the y-coordinate of the starting point of the
\ new line to draw

STA indicatorLineJ,X   \ Store the y-coordinate in indicatorLineJ, so we can
\ use it to erase the line later

BNE dinl3              \ Jump to dinl3 to draw the new line (this BNE is
\ effectively a JMP as A is never zero)

.dinl2

\ If we get here then this is indicator 0-6, so it's a
\ hand-based dial

LDA indicatorLineI,X   \ Set I = x-coordinate of starting point of hand, which
STA I                  \ is a fixed value for hand-based dials

LDA indicatorLineJ,X   \ Set J = y-coordinate of starting point of hand, which
\ is a fixed value for hand-based dials

.dinl3

STA J                  \ Store A in J as the y-coordinate of the starting
\ point of the new line to draw

LDA W                  \ Fetch the x-delta of the new line from W

STA T                  \ Set T = the x-delta of the new line

STA indicatorLineT,X   \ Store the x-delta in indicatorLineT, so we can use it
\ to erase the line later

LDA G                  \ Fetch the y-delta of the new line from G

STA U                  \ Set U = the y-delta of the new line

STA indicatorLineU,X   \ Store the y-delta in indicatorLineU, so we can use it
\ to erase the line later

LDA R                  \ Fetch the direction of the new line from R

STA V                  \ Set V = the direction of the new line

STA indicatorLineV,X   \ Store the direction in indicatorLineV, so we can use
\ it to erase the line later

LDA #0                 \ Set N = 0 so the call to DrawVectorLine draws the new
STA N                  \ line

JSR DrawVectorLine     \ Draw a line from (I, J) as a vector (T, U) with
\ direction V

RTS                    \ Return from the subroutine
```