# Charts: TT105

## [BBC Master version]

```       Name: TT105                                                   [Show more]
Type: Subroutine
Category: Charts
Summary: Draw crosshairs on the Short-range Chart, with clipping
Context: See this subroutine in context in the source code
Variations: See code variations for this subroutine in the different versions
References: This subroutine is called as follows:
* TT103 calls TT105

Check whether the crosshairs are close enough to the current system to appear
on the Short-range Chart, and if so, draw them.

.TT105

LDA QQ9                \ Set A = QQ9 - QQ0, the horizontal distance between the
SEC                    \ crosshairs (QQ9) and the current system (QQ0)
SBC QQ0

BCS P%+6               \ If the subtraction didn't underflow, skip the next two
\ instructions

EOR #&FF               \ The subtraction underflowed, so negate the result
ADC #1                 \ using two's complement so that it is positive, i.e.
\ A = |QQ9 - QQ0|, the absolute horizontal distance

CMP #29                \ If the absolute horizontal distance in A >= 29, then
BCS TT180              \ the crosshairs are too far from the current system to
\ return from the subroutine (as TT180 contains an RTS)

LDA QQ9                \ Set A = QQ9 - QQ0, the horizontal distance between the
SEC                    \ crosshairs (QQ9) and the current system (QQ0)
SBC QQ0

BPL TT179              \ If the horizontal distance in A is positive, then skip
\ the next two instructions

CMP #233               \ If the horizontal distance in A < -23, then the
BCC TT180              \ crosshairs are too far from the current system to
\ return from the subroutine (as TT180 contains an RTS)

.TT179

ASL A                  \ Set QQ19 = 104 + A * 4
ASL A                  \
CLC                    \ 104 is the x-coordinate of the centre of the chart,
ADC #104               \ so this sets QQ19 to the screen pixel x-coordinate
JSR SCALEY2            \
STA QQ19               \ The call to SCALEY2 has no effect as it only contains
\ an RTS, but having this call instruction here would
\ enable different scaling to be applied by altering
\ the SCALE routines. This code is left over from the
\ conversion to other platforms, where the scale factor
\ might need to be different

LDA QQ10               \ Set A = QQ10 - QQ1, the vertical distance between the
SEC                    \ crosshairs (QQ10) and the current system (QQ1)
SBC QQ1

BCS P%+6               \ If the subtraction didn't underflow, skip the next two
\ instructions

EOR #&FF               \ The subtraction underflowed, so negate the result
ADC #1                 \ using two's complement so that it is positive, i.e.
\ A = |QQ10 - QQ0|, the absolute vertical distance

CMP #35                \ If the absolute vertical distance in A >= 35, then
BCS TT180              \ the crosshairs are too far from the current system to
\ return from the subroutine (as TT180 contains an RTS)

LDA QQ10               \ Set A = QQ10 - QQ1, the vertical distance between the
SEC                    \ crosshairs (QQ10) and the current system (QQ1)
SBC QQ1

ASL A                  \ Set QQ19+1 = 90 + A * 2
CLC                    \
ADC #90                \ 90 is the y-coordinate of the centre of the chart,
JSR SCALEY2            \ so this sets QQ19+1 to the screen pixel x-coordinate
STA QQ19+1             \ of the crosshairs
\
\ The call to SCALEY2 has no effect as it only contains
\ an RTS, but having this call instruction here would
\ enable different scaling to be applied by altering
\ the SCALE routines. This code is left over from the
\ conversion to other platforms, where the scale factor
\ might need to be different

LDA #8                 \ Set QQ19+2 to 8 denote crosshairs of size 8
STA QQ19+2

LDA #GREEN             \ Switch to stripe 3-1-3-1, which is white/yellow in the
STA COL                \ chart view

JMP TT15               \ Jump to TT15 to draw crosshairs of size 8 at the
\ crosshairs coordinates, returning from the subroutine
\ using a tail call
```