.WARP LDA MANY+AST \ Set X to the total number of asteroids, escape pods CLC \ and cargo canisters in the vicinity ADC MANY+ESC CLC \ The second CLC instruction has no effect, as there is ADC MANY+OIL \ is no way that adding the number of asteroids and the TAX \ number escape pods will cause a carry LDA FRIN+2,X \ If the slot at FRIN+2+X is non-zero, then we have \ something else in the vicinity besides asteroids, \ escape pods and cargo canisters, so to check whether \ we can jump, we first grab the slot contents into A ORA SSPR \ If there is a space station nearby, then SSPR will \ be non-zero, so OR'ing with SSPR will produce a \ a non-zero result if either A or SSPR are non-zero BNE WA1 \ A is non-zero if we have either a ship or a space \ station in the vicinity, in which case jump to WA1 to \ make a low beep to show that we can't do an in-system \ jump LDY K%+8 \ Otherwise we can do an in-system jump, so now we fetch \ the byte at K%+8, which contains the z_sign for the \ first ship slot, i.e. the distance of the planet BMI WA3 \ If the planet's z_sign is negative, then the planet \ is behind us, so jump to WA3 to skip the following TAY \ Set A = Y = 0 (as we didn't BNE above) so the call \ to MAS2 measures the distance to the planet JSR MAS2 \ Call MAS2 to set A to the largest distance to the \ planet in any of the three axes (we could also call \ routine m to do the same thing, as A = 0) CMP #2 \ If A < 2 then jump to WA1 to abort the in-system jump BCC WA1 \ with a low beep, as we are facing the planet and are \ too close to jump in that direction .WA3 LDY K%+NI%+8 \ Fetch the z_sign (byte #8) of the second ship in the \ ship data workspace at K%, which is reserved for the \ space station BMI WA2 \ If the station's z_sign is negative, then it is \ behind us, so jump to WA2 to skip the following LDY #NI% \ Set Y to point to the offset of the ship data block \ for the station, which is NI% (as each block is NI% \ bytes long, and the station is the second block) JSR m \ Call m to set A to the largest distance to the station \ in any of the three axes CMP #2 \ If A < 2 then jump to WA1 to abort the in-system jump BCC WA1 \ with a low beep, as we are facing the station and are \ too close to jump in that direction .WA2 \ If we get here, then we can do an in-system jump, as \ we don't have any ships or space stations in the \ vicinity, we are not in witchspace, and if we are \ facing the planet, we aren't too close to jump \ towards it \ \ We do an in-system jump by moving the planet, rather \ than moving our own local bubble (this is why \ in-system jumps drag asteroids, cargo canisters and \ escape pods along for the ride). Specifically, we move \ them in the z-axis by a fixed amount in the opposite \ direction to travel, thus performing a jump towards \ our destination LDA #&81 \ Set R = R = P = &81 STA S STA R STA P LDA K%+8 \ Set A = z_sign for the planet JSR ADD \ Set (A X) = (A P) + (S R) \ = (z_sign &81) + &8181 \ = (z_sign &81) - &0181 \ \ This moves the planet against the direction of travel \ by reducing z_sign by 1, as the above maths is: \ \ z_sign 00000000 \ + 00000000 10000001 \ - 00000001 10000001 \ \ or: \ \ z_sign 00000000 \ + 00000000 00000000 \ - 00000001 00000000 \ \ i.e. the high byte is z_sign - 1, making sure the sign \ is preserved STA K%+8 \ Set the planet's z_sign to the high byte of the result LDA K%+NI%+8 \ Set A = z_sign for the station JSR ADD \ Set (A X) = (A P) + (S R) \ = (z_sign &81) + &8181 \ = (z_sign &81) - &0181 \ \ which moves the station against the direction of \ travel by reducing z_sign by 1 STA K%+NI%+8 \ Set the planet's z_sign to the high byte of the result LDA #1 \ These instructions have no effect, as the call to STA QQ11 \ LOOK1 below starts by setting QQ11 to 0; instead they \ just set the current view type in QQ11 to 1 for the \ duration of the next three instructions STA MCNT \ Set the main loop counter to 1, so the next iteration \ through the main loop will potentially spawn ships \ (see part 2 of the main game loop at me3) LSR A \ Set EV, the extra vessels spawning counter, to 0 STA EV \ (the LSR produces a 0 as A was previously 1) LDX VIEW \ Set X to the current view (front, rear, left or right) JMP LOOK1 \ and jump to LOOK1 to initialise that view, returning \ from the subroutine using a tail call .WA1 LDA #40 \ If we get here then we can't do an in-system jump, so JMP NOISE \ call the NOISE routine with A = 40 to make a long, low \ beep and return from the subroutine using a tail callName: WARP [Show more] Type: Subroutine Category: Flight Summary: Perform an in-system jumpContext: 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: * Main flight loop (Part 3 of 16) calls WARP

This is called when we press "J" during flight. The following checks are performed: * Make sure we don't have any ships or space stations in the vicinity * Make sure we are not in witchspace * If we are facing the planet, make sure we aren't too close If the above checks are passed, then we perform an in-system jump by moving the planet in the opposite direction to travel, so we appear to jump in space. This means that any asteroids, cargo canisters or escape pods get dragged along for the ride.

[X]

Subroutine ADD (category: Maths (Arithmetic))

Calculate (A X) = (A P) + (S R)

[X]

Configuration variable: AST = 9

Ship type for an asteroid

[X]

Configuration variable: ESC = 11

Ship type for an escape pod

[X]

Workspace K% (category: Workspaces)

Ship data blocks and ship line heaps

[X]

Subroutine LOOK1 (category: Flight)

Initialise the space view

[X]

Subroutine MAS2 (category: Maths (Geometry))

Calculate a cap on the maximum distance to the planet

[X]

Configuration variable: NI% = 36

The number of bytes in each ship's data block (as stored in INWK and K%)

[X]

Subroutine NOISE (category: Sound)

Make the sound whose number is in A

[X]

Configuration variable: OIL = 10

Ship type for a cargo canister

[X]

Label WA1 is local to this routine

[X]

Label WA2 is local to this routine

[X]

Label WA3 is local to this routine

[X]

Entry point m in subroutine MAS2 (category: Maths (Geometry))

Do not include A in the calculation