This code appears in the following versions (click to see it in the source code):
Code variations between these versions are shown below.
Name: Main flight loop (Part 1 of 16) Type: Subroutine Category: Main loop Summary: Seed the random number generator Deep dive: Program flow of the main game loop Generating random numbers
The main flight loop covers most of the flight-specific aspects of Elite. This section covers the following: * Seed the random number generator
This variation is blank in the Cassette, Disc (flight), 6502 Second Processor and Master versions.
* Update the sound channel's duration counter to ensure sounds are allocated a minimum duration (unless they are stopped by a higher priority sound)
.M% LDA K% \ We want to seed the random number generator with a \ pretty random number, so fetch the contents of K%, \ which is the x_lo coordinate of the planet. This value \ will be fairly unpredictable, so it's a pretty good \ candidate STA RAND \ Store the seed in the first byte of the four-byte \ random number seed that's stored in RAND
Other entry points: M% The entry point for the main flight loop
Because the Electron only has two sound channels (one noise and one tone), each sound is allocated a minimum duration, during which time it can only be stopped by a higher priority sound coming along.
This variation is blank in the Cassette, Disc (flight), 6502 Second Processor and Master versions.
\ The following processes each sound channel to ensure \ that sounds last for their minimum duration (see the \ SFX variable for more details) LDA #0 \ Set A = 0 so we can use it for resetting the sound \ channel's duration and priority values below LDX #1 \ Set X as a sound channel counter, starting with \ channel 1 and then doing channel 0 .SFXL DEC SFXDU,X \ Decrement this sound channel's SFXDU duration value BPL P%+8 \ If the duration is still positive, skip the following \ two instructions STA SFXDU,X \ The duration just reached zero, so the sound on this STA SFXPR,X \ channel has reached the end of its minimum duration, \ so we zero the channel's SFXDU duration and SFXPR \ priority values so any new sounds that need to be made \ will be made regardless of priority DEX \ Decrement the sound channel BPL SFXL \ Loop back to process the next sound channel until we \ have done both
This variation is blank in the Cassette, Disc (flight), 6502 Second Processor and Electron versions.
\LDA TRIBCT \ These instructions are commented out in the original \BEQ NOMVETR \ source \JMP MVTRIBS \ \.NOMVETR