.MLOOP LDX #$FF ; Set the stack pointer to $01FF, which is the standard TXS ; location for the 6502 stack, so this instruction ; effectively resets the stack LDX GNTMP ; If the laser temperature in GNTMP is non-zero, BEQ EE20 ; decrement it (i.e. cool it down a bit) DEC GNTMP .EE20 LDX LASCT ; Set X to the value of LASCT, the laser pulse count BEQ NOLASCT ; If X = 0 then jump to NOLASCT to skip reducing LASCT, ; as it can't be reduced any further DEX ; Decrement the value of LASCT in X BEQ P%+3 ; If X = 0, skip the next instruction DEX ; Decrement the value of LASCT in X again STX LASCT ; Store the decremented value of X in LASCT, so LASCT ; gets reduced by 2, but not into negative territory .NOLASCT LDA QQ11 ; If QQ11 is non-zero then this is not the space view, BNE P%+5 ; so skip the following instruction as only the space ; view has the dashboard JSR DIALS ; Call DIALS to update the dashboard LDA QQ11 ; If this is a space view, jump to plus13 to skip the BEQ plus13 ; following five instructions AND PATG ; If PATG = $FF (author names are shown on start-up) LSR A ; and bit 0 of QQ11 is 1 (the current view is type 1), BCS plus13 ; then skip the following two instructions LDY #2 ; Wait for 2/50 of a second (0.04 seconds) on PAL JSR DELAY ; systems, or 2/60 of a second (0.03 seconds) on NTSC, ; to slow the main loop down a bit .plus13 LDA TRIBBLE+1 ; If the high byte of TRIBBLE(1 0), the number of BEQ nobabies ; Trumbles in the hold, is zero, jump to nobabies to ; skip the following ; We have a lot of Trumbles in the hold, so let's see if ; any of them are breeding (note that Trumbles always ; breed when we jump into a new system in the SOLAR ; routine, but when we have lots of them, they also ; breed here in the main flight loop) JSR DORND ; Set A and X to random numbers CMP #220 ; If A >= 220 then set the C flag (14% chance) LDA TRIBBLE ; Add the C flag to TRIBBLE(1 0), starting with the low ADC #0 ; bytes STA TRIBBLE BCC nobabies ; And then the high bytes INC TRIBBLE+1 ; ; So there is a 14% chance of a Trumble being born BPL nobabies ; If the high byte of TRIBBLE(1 0) is now $80, then DEC TRIBBLE+1 ; decrement it back to $7F, so the number of Trumbles ; never goes above $7FFF (32767) .nobabies LDA TRIBBLE+1 ; If the high byte of TRIBBLE(1 0), the number of BEQ NOSQUEEK ; Trumbles in the hold, is zero, jump to NOSQUEEK to ; skip the following ; We have a lot of Trumbles in the hold, so they are ; probably making a bit of a noise STA T ; Store the high byte of the number of Trumbles in T LDA CABTMP ; If the cabin temperature is >= 224 then skip the ASL T CMP #224 ; instruction and leave the value of A as a lower value, BCS P%+4 ; so the chances of the Trumbles making a noise in hot ; temperatures is lessened (specifically, this is the ; temperature at which the fuel scoops start working) ASL T ; Set T = T * 2 JSR DORND ; Set A and X to random numbers CMP T ; If A >= T then jump to NOSQUEEK to skip making any BCS NOSQUEEK ; noise, so there is a higher chance of Trumbles making ; noise when there are lots of them and the cabin ; temperature is cool enough for the fuel scoops to be ; disabled (so they start to go quieter when things get ; too hot) ; If we get here then we want to make the noise of ; Trumbles living in our ship JSR DORND ; Set X to a random number in the range 64 to 255, which ORA #64 ; we will use as the frequency of the sound of Trumble TAX ; chatter (so they make a randomly pitched noise that's ; not too high) LDA #$80 ; Set A = $80 to pass to NOISE2 as the sustain volume ; and release length for when the cabin is relatively ; cool, so that's a sustain volume of 8 and a release ; length of 0 ; ; This makes the sounds more staccato and softer LDY CABTMP ; If the cabin temperature is < 224, jump to CPY #224 ; burnthebastards to make the noise of Trumbles lightly BCC burnthebastards ; toasting TXA ; Clip X to a random number in the range 0 to 15, so the AND #15 ; frequency of the Trumble chatter gets lower as the TAX ; cabin gets hotter LDA #$F1 ; Set A = $F1 to pass to NOISE2 as the sustain volume ; and release length for when the cabin is really hot, ; so that's a sustain volume of 15 and a release length ; of 1 ; ; This makes the sounds more drawn out and louder .burnthebastards LDY #sfxtrib ; Call the NOISE2 routine with Y = sfxtrib and A and X JSR NOISE2 ; set according to the cabin temperature: ; ; * A = $80, X = 64 to 255 when the cabin is cool ; (quieter, higher-pitched, more staccato squeaks) ; ; * A = $F1, X = 0 to 15 when the cabin is hot ; (louder, lower-pitched, more drawn out squeaks) ; ; This makes the sound of Trumbles either partying or ; or being slowly roasted .NOSQUEEK JSR TT17 ; Scan the keyboard for the cursor keys or joystick, ; returning the cursor's delta values in X and Y and ; the key pressed in AName: Main game loop (Part 5 of 6) [Show more] Type: Subroutine Category: Main loop Summary: Cool down lasers, make calls to update the dashboard Deep dive: Program flow of the main game loop The dashboard indicators The Trumbles missionContext: 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 MLOOP * Main game loop (Part 3 of 6) calls via MLOOP * Main game loop (Part 4 of 6) calls via MLOOP * Main game loop (Part 6 of 6) calls via MLOOP
This is the first half of the minimal game loop, which we iterate when we are docked. This section covers the following: * Cool down lasers * Make calls to update the dashboard
Other entry points: MLOOP The entry point for the main game loop. This entry point comes after the call to the main flight loop and spawning routines, so it marks the start of the main game loop for when we are docked (as we don't need to call the main flight loop or spawning routines if we aren't in space)
[X]
Subroutine DELAY (category: Utility routines)
Wait for a specified time, in either 1/50s of a second (on PAL systems) or 1/60s of a second (on NTSC systems)
[X]
Subroutine DIALS (Part 1 of 4) (category: Dashboard)
Update the dashboard: speed indicator
[X]
Subroutine DORND (category: Maths (Arithmetic))
Generate random numbers
[X]
Label EE20 is local to this routine
[X]
Subroutine NOISE2 (category: Sound)
Make a sound effect with a specific volume and release length
[X]
Label NOLASCT is local to this routine
[X]
Label NOSQUEEK is local to this routine
[X]
Variable PATG in workspace Option variables
Configuration setting to show the author names on the start-up screen and enable manual hyperspace mis-jumps
[X]
Subroutine TT17 (category: Keyboard)
Scan the keyboard for cursor key or joystick movement
[X]
Label burnthebastards is local to this routine
[X]
Label nobabies is local to this routine
[X]
Label plus13 is local to this routine
[X]
Configuration variable sfxtrib = 14
Sound 14 = Trumbles dying