Skip to navigation

Elite on the BBC Micro and NES

Universe: SOLAR

[NES version, Bank 0]

Name: SOLAR [Show more] Type: Subroutine Category: Universe Summary: Set up various aspects of arriving in a new system Deep dive: The Trumbles mission
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * PlayDemo calls SOLAR * TT18 calls SOLAR

Halve our legal status, update the missile indicators, and set up data blocks and slots for the planet and sun.
.SOLAR LDA TRIBBLE ; If we have no Trumbles in the hold, skip to nobirths BEQ nobirths ; If we get here then we have Trumbles in the hold, so ; this is where they breed LDA #0 ; Trumbles eat food during the hyperspace journey, so STA QQ20 ; zero the amount of food in the hold JSR DORND ; Take the number of Trumbles from TRIBBLE(1 0), add a AND #15 ; random number between 4 and 15, and double the result, ADC TRIBBLE ; storing the resulting number in TRIBBLE(1 0) ORA #4 ; ROL A ; We start with the low byte STA TRIBBLE ROL TRIBBLE+1 ; And then do the high byte BPL P%+5 ; If bit 7 of the high byte is set, then rotate the high ROR TRIBBLE+1 ; byte back to the right, so the number of Trumbles is ; always positive .nobirths LSR FIST ; Halve our legal status in FIST, making us less bad, ; and moving bit 0 into the C flag (so every time we ; arrive in a new system, our legal status improves a ; bit) JSR ZINF ; Call ZINF to reset the INWK ship workspace, which ; doesn't affect the C flag LDA QQ15+1 ; Fetch s0_hi AND #%00000011 ; Extract bits 0-1 (which also help to determine the ; economy), which will be between 0 and 3 ADC #3 ; Add 3 + C, to get a result between 3 and 7, clearing ; the C flag in the process STA INWK+8 ; Store the result in z_sign in byte #6 LDX QQ15+2 ; Set the C flag if s1_lo >= 128, otherwise clear it CPX #128 ROR A ; Halve A and set the sign bit to the C flag, and set STA INWK+2 ; x_sign to the result, so this moves the planet to the ; right or left of centre ROL A ; Set A to x_sign << 1, ready for us to roll in the ; sign bit again for y_sign LDX QQ15+3 ; Set the C flag if s1_hi >= 128, otherwise clear it CPX #128 ROR A ; Set the sign bit to the C flag and set y_sign to the STA INWK+5 ; result, so this moves the planet up or down from the ; centre JSR SOS1 ; Call SOS1 to set up the planet's data block and add it ; to FRIN, where it will get put in the first slot as ; it's the first one to be added to our local bubble of ; this new system's universe LDA QQ15+3 ; Fetch s1_hi, extract bits 0-2, set bits 0 and 7 and AND #%00000111 ; store in z_sign, so the sun is behind us at a distance ORA #%10000001 ; of 1 to 7 STA INWK+8 LDA QQ15+5 ; Fetch s2_hi, extract bits 0-1 and store in x_sign and AND #%00000011 ; y_sign, so the sun is either dead centre in our rear STA INWK+2 ; laser crosshairs, or off to the top left by a distance STA INWK+1 ; of 1 or 2 when we look out the back LDA #0 ; Set the pitch and roll counters to 0 (no rotation) STA INWK+29 STA INWK+30 STA FRIN+1 ; Set the second slot in the FRIN table to 0, which ; sets this slot to empty, so when we call NWSHP below ; the new sun that gets created will go into FRIN+1 STA SSPR ; Set the "space station present" flag to 0, as we are ; no longer in the space station's safe zone LDA #129 ; Set A = 129, the ship type for the sun JSR NWSHP ; Call NWSHP to set up the sun's data block and add it ; to FRIN, where it will get put in the second slot as ; it's the second one to be added to our local bubble ; of this new system's universe