Skip to navigation


Dashboard: SP2

[NES version, Bank 0]

Name: SP2 [Show more] Type: Subroutine Category: Dashboard Summary: Draw a dot on the compass, given the planet/station vector
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * COMPAS calls SP2

Draw a dot on the compass to represent the planet or station, whose normalised vector is in XX15. XX15 to XX15+2 The normalised vector to the planet or space station, stored as x in XX15, y in XX15+1 and z in XX15+2
.SP2 LDA XX15 ; Set A to the x-coordinate of the planet or station to ; show on the compass, which will be in the range -96 to ; +96 as the vector has been normalised JSR SPS2 ; Set X = A / 16, so X will be from -6 to +6, which ; is the x-offset from the centre of the compass of the ; dot we want to draw. Returns with the C flag clear TXA ; Set the x-coordinate of sprite 13 (the compass dot) to CLC ; 220 + X, as 220 is the pixel x-coordinate of the ADC #220 ; centre of the compass, and X is in the range -6 to +6, STA xSprite13 ; so the dot is in the x-coordinate range 214 to 226 LDA XX15+1 ; Set A to the y-coordinate of the planet or station to ; show on the compass, which will be in the range -96 to ; +96 as the vector has been normalised JSR SPS2 ; Set X = A / 16, so X will be from -6 to +6, which ; is the x-offset from the centre of the compass of the ; dot we want to draw. Returns with the C flag clear ; We now set the y-coordinate of sprite 13 (the compass ; dot) to 186, as 186 is the pixel y-coordinate of the ; centre of the compass, and X is in the range -6 to +6, ; so the dot is in the y-coordinate range 180 to 192 STX T ; Set T = X for use in the calculation below LDA #186+YPAL ; Set A to the pixel y-coordinate of the compass centre SEC ; Set the y-coordinate of sprite 13 to A - X SBC T STA ySprite13 LDA #247 ; Set A to 247, which is the tile number that contains a ; full dot in green, for when the planet or station in ; the compass is in front of us LDX XX15+2 ; If the z-coordinate of the XX15 vector is positive, BPL P%+4 ; skip the following instruction LDA #246 ; The z-coordinate of XX15 is negative, so the planet or ; station is behind us and the compass dot should be ; hollow and yellow, so set A to 246, which is the tile ; number for the hollow yellow dot STA pattSprite13 ; Set the pattern number for sprite 13 to A, so we draw ; the compass dot using the correct pattern RTS ; Return from the subroutine