Skip to navigation


Universe: SpawnSpaceStation

[NES version, Bank 0]

Name: SpawnSpaceStation [Show more] Type: Subroutine Category: Universe Summary: Add a space station to the local bubble of universe if we are close enough to the station's orbit
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * Main flight loop (Part 14 of 16) calls SpawnSpaceStation
.SpawnSpaceStation ; We now check the distance from our ship (at the ; origin) towards the point where we will spawn the ; space station if we are close enough ; ; This point is calculated by starting at the planet's ; centre and adding 2 * nosev, which takes us to a point ; above the planet's surface, at an altitude that ; matches the planet's radius ; ; This point pitches and rolls around the planet as the ; nosev vector rotates with the planet, and if our ship ; is within a distance of (100 0) from this point in all ; three axes, then we spawn the space station at this ; point, with the station's slot facing towards the ; planet, along the nosev vector ; ; This works because in the following, we calculate the ; station's coordinates one axis at a time, and store ; the results in the INWK block, so by the time we have ; calculated and checked all three, the ship data block ; is set up with the correct spawning coordinates SETUP_PPU_FOR_ICON_BAR ; If the PPU has started drawing the icon bar, configure ; the PPU to use nametable 0 and pattern table 0 LDX #0 ; Call MAS1 with X = 0, Y = 9 to do the following: LDY #9 ; JSR MAS1 ; (x_sign x_hi x_lo) += (nosev_x_hi nosev_x_lo) * 2 ; ; A = |x_sign| BNE MA23S2 ; If A > 0, jump to MA23S2 to skip the following, as we ; are too far from the planet in the x-direction to ; bump into a space station LDX #3 ; Call MAS1 with X = 3, Y = 11 to do the following: LDY #11 ; JSR MAS1 ; (y_sign y_hi y_lo) += (nosev_y_hi nosev_y_lo) * 2 ; ; A = |y_sign| BNE MA23S2 ; If A > 0, jump to MA23S2 to skip the following, as we ; are too far from the planet in the y-direction to ; bump into a space station LDX #6 ; Call MAS1 with X = 6, Y = 13 to do the following: LDY #13 ; JSR MAS1 ; (z_sign z_hi z_lo) += (nosev_z_hi nosev_z_lo) * 2 ; ; A = |z_sign| BNE MA23S2 ; If A > 0, jump to MA23S2 to skip the following, as we ; are too far from the planet in the z-direction to ; bump into a space station LDA #100 ; Call FAROF2 to compare x, y and z with 100 * 2, which JSR FAROF2 ; will clear the C flag if the distance to the point is ; < 200 or set the C flag if it is >= 200 BCS MA23S2 ; Jump to MA23S2 if the distance to point (x, y, z) is ; >= 100 (i.e. we must be near enough to the planet to ; bump into a space station) JSR NWSPS ; Add a new space station to our local bubble of ; universe SEC ; Set the C flag to indicate that we have added the ; space station RTS ; Return from the subroutine .MA23S2 SETUP_PPU_FOR_ICON_BAR ; If the PPU has started drawing the icon bar, configure ; the PPU to use nametable 0 and pattern table 0 CLC ; Clear the C flag to indicate that we have not added ; the space station RTS ; Return from the subroutine