Skip to navigation

Elite on the BBC Micro and NES

Universe: SPIN

[NES version, Bank 0]

Name: SPIN [Show more] Type: Subroutine Category: Universe Summary: Randomly spawn cargo from a destroyed ship
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * Main flight loop (Part 11 of 16) calls SPIN * Main flight loop (Part 11 of 16) calls via SPIN2

Arguments: Y The type of cargo to consider spawning (typically #PLT or #OIL)
Other entry points: SPIN2 Remove any randomness: spawn cargo of a specific type (given in X), and always spawn the number given in A
.SPIN JSR DORND ; Fetch a random number, and jump to oh if it is BPL oh ; positive (50% chance) TYA ; Copy the cargo type from Y into A and X TAX LDY #0 ; Set Y = 0 to use as an index into the ship's blueprint ; in the call to GetShipBlueprint STA CNT ; Store the random number in CNT JSR GetShipBlueprint ; Fetch the first byte of the hit ship's blueprint, ; which determines the maximum number of bits of ; debris shown when the ship is destroyed AND CNT ; AND with the random number we fetched above AND #15 ; Reduce the random number in A to the range 0-15 .SPIN2 STA CNT ; Store the result in CNT, so CNT contains a random ; number between 0 and the maximum number of bits of ; debris that this ship will release when destroyed ; (to a maximum of 15 bits of debris) .spl DEC CNT ; Decrease the loop counter BMI oh ; We're going to go round a loop using CNT as a counter ; so this checks whether the counter was zero and jumps ; to oh when it gets there (which might be straight ; away) LDA #0 ; Call SFS1 to spawn the specified cargo from the now JSR SFS1 ; deceased parent ship, giving the spawned canister an ; AI flag of 0 (no AI, no E.C.M., non-hostile) JMP spl ; Loop back to spawn the next bit of random cargo