Skip to navigation

Elite on the BBC Micro and NES

Drawing circles: TT14

[NES version, Bank 0]

Name: TT14 [Show more] Type: Subroutine Category: Drawing circles Summary: Draw a circle with crosshairs on a chart
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * TT22 calls TT14 * TT23 calls TT14

Draw a circle with crosshairs at the current system's galactic coordinates.
.TT126 LDA #104 ; Set QQ19 = 104, for the x-coordinate of the centre of STA QQ19 ; the fixed circle on the Short-range Chart LDA #90 ; Set QQ19+1 = 90, for the y-coordinate of the centre of STA QQ19+1 ; the fixed circle on the Short-range Chart LDA #16 ; Set QQ19+2 = 16, the size of the crosshairs on the STA QQ19+2 ; Short-range Chart JSR TT15 ; Draw the set of crosshairs defined in QQ19, at the ; exact coordinates as this is the Short-range Chart LDA QQ14 ; Set K = QQ14 + (QQ14 / 32) LSR A ; LSR A ; So K is the circle's radius, based on the fuel level LSR A ; in QQ14 (so K is in the range 0 to 73, as the latter LSR A ; division gets rounded up by the ADC adding in the C LSR A ; flag, and QQ14 is in the range 0 to 70) ADC QQ14 STA K JMP TT128 ; Jump to TT128 to draw a circle with the centre at the ; same coordinates as the crosshairs, (QQ19, QQ19+1), ; and radius K that reflects the current fuel levels, ; returning from the subroutine using a tail call .TT14 LDA QQ11 ; If the view type in QQ11 is $9C (Short-range Chart), CMP #$9C ; jump up to TT126 to draw the crosshairs and circle for BEQ TT126 ; that view ; Otherwise this is the Long-range Chart, so we draw the ; crosshairs and circle for that view instead LDA QQ14 ; Set K = QQ14/4 - QQ14/16 LSR A ; = 0.1875 * QQ14 LSR A ; STA K ; So K scales the fuel level in QQ14 to act as the LSR A ; circle's radius, scaling the fuel level from a range LSR A ; of 0 to 70 down to a range of 0 to 13, so the fuel STA T1 ; circle has a maximum radius of 13 pixels on the LDA K ; Long-range Chart SEC SBC T1 STA K ; We now set the pixel coordinates of the crosshairs in ; QQ9 and QQ9+1 so they fit into the chart, with a ; 31-pixel margin on the left and an 8-pixel margin at ; the top (to which we will add another 24 pixels below) ; ; The Long-range Chart is twice as wide as it is high, ; so we need to scale the y-coordinate in QQ19+1 by an ; extra division by 2 when compared to the x-coordinate LDA QQ0 ; Set QQ19 = 31 + QQ9 - (QQ9 / 4) LSR A ; = 31 + 0.75 * QQ9 LSR A ; STA T1 ; So this scales the x-coordinate from a range of 0 to LDA QQ0 ; 255 into a range from 31 to 222, so it fits nicely SEC ; into the Long-range Chart SBC T1 CLC ADC #31 STA QQ19 LDA QQ1 ; Set QQ19+1 = 8 + (QQ10 - (QQ10 / 4)) / 2 LSR A ; = 8 + 0.375 * QQ10 LSR A ; STA T1 ; So this scales the y-coordinate from a range of 0 to LDA QQ1 ; 255 into a range from 8 to 127, so it fits nicely SEC ; into the Long-range Chart SBC T1 LSR A CLC ADC #8 STA QQ19+1 LDA #7 ; Set QQ19+2 = 7, the size of the crosshairs on the STA QQ19+2 ; Long-range Chart JSR TT15 ; Draw the set of crosshairs defined in QQ19, which will ; be drawn 24 pixels to the right of QQ19+1 LDA QQ19+1 ; Add 24 to the y-coordinate of the crosshairs in QQ19+1 CLC ; so that the centre of the circle matches the centre ADC #24 ; of the crosshairs STA QQ19+1 ; Fall through into TT128 to draw a circle with the ; centre at the same coordinates as the crosshairs, ; (QQ19, QQ19+1), and radius K that reflects the ; current fuel levels