Elite on the BBC Micro and NES

# Universe: TT54

## [6502 Second Processor version]

```       Name: TT54                                                    [Show more]
Type: Subroutine
Category: Universe
Summary: Twist the selected system's seeds
Deep dive: Twisting the system seeds
Galaxy and system seeds
Context: See this subroutine in context in the source code
References: This subroutine is called as follows:
* cpl calls TT54

This routine twists the three 16-bit seeds in QQ15 once.

If we start with seeds s0, s1 and s2 and we want to work out their new values
after we perform a twist (let's call the new values s0Â´, s1Â´ and s2Â´), then:

s0Â´ = s1
s1Â´ = s2
s2Â´ = s0 + s1 + s2

So given an existing set of seeds in s0, s1 and s2, we can get the new values
s0Â´, s1Â´ and s2Â´ simply by doing the above sums. And if we want to do the
above in-place without creating three new sÂ´ variables, then we can do the
following:

tmp = s0 + s1
s0 = s1
s1 = s2
s2 = tmp + s1

So this is what we do in this routine, where each seed is a 16-bit number.

.TT54

LDA QQ15               \ X = tmp_lo = s0_lo + s1_lo
CLC
TAX

LDA QQ15+1             \ Y = tmp_hi = s1_hi + s1_hi + C
TAY

LDA QQ15+2             \ s0_lo = s1_lo
STA QQ15

LDA QQ15+3             \ s0_hi = s1_hi
STA QQ15+1

LDA QQ15+5             \ s1_hi = s2_hi
STA QQ15+3

LDA QQ15+4             \ s1_lo = s2_lo
STA QQ15+2

CLC                    \ s2_lo = X + s1_lo
TXA