Skip to navigation

Elite on the BBC Micro and NES

Main loop: Main flight loop (Part 1 of 16)

[NES version, Bank 0]

Name: Main flight loop (Part 1 of 16) [Show more] Type: Subroutine Category: Main loop Summary: Seed the random number generator Deep dive: Program flow of the main game loop Generating random numbers
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * Main game loop (Part 2 of 6) calls via M%

The main flight loop covers most of the flight-specific aspects of Elite. This section covers the following: * Seed the random number generator
Other entry points: M% The entry point for the main flight loop
.M% LDA QQ11 ; If this is not the space view, jump to main1 to skip BNE main1 ; the following, as we only need to flip the drawing ; bitplane for animating the space view JSR FlipDrawingPlane ; Flip the drawing bitplane so we draw into the bitplane ; that isn't visible on-screen .main1 SETUP_PPU_FOR_ICON_BAR ; If the PPU has started drawing the icon bar, configure ; the PPU to use nametable 0 and pattern table 0 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 EOR nmiTimerLo ; EOR the value of K% with the low byte of the NMI ; timer, which gets updated by the NMI interrupt ; routine, so this will be fairly unpredictable too STA RAND ; Store the seed in the first byte of the four-byte ; random number seed that's stored in RAND