BBC Micro Elite

# Drawing lines: LASLI

```       Name: LASLI                                             [View in context]
Type: Subroutine
Category: Drawing lines
Summary: Draw the laser lines for when we fire our lasers

Draw the laser lines, aiming them to slightly different place each time so
they appear to flicker and dance. Also heat up the laser temperature and drain
some energy.

Other entry points:

LASLI2               Just draw the current laser lines without moving the
centre point, draining energy or heating up. This has
the effect of removing the lines from the screen

.LASLI
{
JSR DORND              \ Set A and X to random numbers

AND #7                 \ Restrict A to a random value in the range 0 to 7

ADC #Y-4               \ Set LASY to four pixels above the centre of the
STA LASY               \ screen (#Y), plus our random number, so the laser
\ dances above and below the centre point

JSR DORND              \ Set A and X to random numbers

AND #7                 \ Restrict A to a random value in the range 0 to 7

ADC #X-4               \ Set LASX to four pixels left of the centre of the
STA LASX               \ screen (#X), plus our random number, so the laser
\ dances to the left and right of the centre point

LDA GNTMP              \ Add 8 to the laser temperature in GNTMP
STA GNTMP

JSR DENGY              \ Call DENGY to deplete our energy banks by 1

.^LASLI2

LDA QQ11               \ If this is not a space view (i.e. QQ11 is non-zero)
BNE PU1-1              \ then jump to MA9 to return from the main flight loop
\ (as PU1-1 is an RTS)

LDA #32                \ Call las with A = 32 and Y = 224 to draw one set of
LDY #224               \ laser lines
JSR las

LDA #48                \ Fall through into las with A = 48 and Y = 208 to draw
LDY #208               \ a second set of lines

\ The following routine draws two laser lines, one from
\ the centre point down to point A on the bottom row,
\ and the other from the centre point down to point Y
\ on the bottom row. We therefore get lines from the
\ centre point to points 32, 48, 208 and 224 along the
\ bottom row, giving us the triangular laser effect
\ we're after

.las

STA X2                 \ Set X2 = A

LDA LASX               \ Set (X1, Y1) to the random centre point we set above
STA X1
LDA LASY
STA Y1

LDA #2*Y-1             \ Set Y2 = 2 * #Y - 1. The constant #Y is 96, the
STA Y2                 \ y-coordinate of the mid-point of the space view, so
\ this sets Y2 to 191, the y-coordinate of the bottom
\ pixel row of the space view

JSR LOIN               \ Draw a line from (X1, Y1) to (X2, Y2), so that's from
\ the centre point to (A, 191)

LDA LASX               \ Set (X1, Y1) to the random centre point we set above
STA X1
LDA LASY
STA Y1

STY X2                 \ Set X2 = Y

LDA #2*Y-1             \ Set Y2 = 2 * #Y - 1, the y-coordinate of the bottom
STA Y2                 \ pixel row of the space view (as before)

JMP LOIN               \ Draw a line from (X1, Y1) to (X2, Y2), so that's from
\ the centre point to (Y, 191), and return from
\ the subroutine using a tail call
}
```