Skip to navigation

Setup: ResetVariables

Name: ResetVariables [Show more] Type: Subroutine Category: Setup Summary: Reset most variables to prepare for a new flight
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * NewGame calls ResetVariables
.ResetVariables LDX #0 \ Set A = 0 to use as our zero value TXA \ Set X = 0 to use as a counter for zeroing 256 bytes in \ the rset1 loop STA alienSlot \ Set alienSlot = 0 to clear out the first alien slot \ (we clear out the other three slots below) STA forceFactor+7 \ Set the force factor for yFlapsLift = 0 STA hitTimer \ Set hitTimer = 0 to cancel any alien explosions STA randomNumbers \ Set randomNumbers = 0 to reset the pointer for the \ list of random numbers STA scoreLo \ Set (scoreHi scoreLo) = 0 to reset the current score STA scoreHi .rset1 \ This loop zeroes the whole page at pointStatus, which \ zeroes both pointStatus and objectStatus, resetting \ all the point and object statuses STA pointStatus,X \ Zero the X-th byte of pointStatus DEX \ Decrement the byte counter BNE rset1 \ Loop back until we have zeroed the whole page \ We now zero all the workspace variables from xTurnHi \ to yPlaneHi, so their default values are all zero \ unless they are explicitly set below LDX #255 \ Set X = 255 to use as a counter for zeroing 255 bytes \ in the rset2 loop STA relatedPoints \ Set relatedPoints = 0 to reset the relatedPoints list STA mainLoopCounter \ Set mainLoopCounter = 0 to reset the main loop counter .rset2 STA xTurnHi-1,X \ Zero the X-1-th byte of the workspace variables DEX \ Decrement the byte counter BNE rset2 \ Loop back until we have zeroed from xTurnHi to \ yPlaneHi \ We now zero the eight bytes at alienState to reset the \ state of the aliens LDX #7 \ Set X = 7 to use as a counter for zeroing eight bytes \ in the following loop .rset3 STA alienState,X \ Zero the X-th byte of alienState DEX \ Decrement the byte counter BPL rset3 \ Loop back until we have zeroed alienState to \ alienState+7 LDA #&48 \ Set (zPlaneHi zPlaneLo) = &485C STA zPlaneHi LDA #&5C STA zPlaneLo LDA #&C6 \ Set (xPlaneHi xPlaneLo) = &C6E5 STA xPlaneHi LDA #&E5 STA xPlaneLo LDA #&0A \ Set (yPlaneHi yPlaneLo) = &000A STA yPlaneLo STA alienSpeed \ Set alienSpeed = 10, the movement speed for the first \ wave of aliens LDA #242 \ Set the force factor for zLiftDrag = 242, which is STA forceFactor+5 \ quickly adjusted by +10 for the undercarriage being \ down and -200 for the flaps being off, giving a \ starting value of 52 when we are sitting on the runway LDA #1 \ Set ucStatus = 1, so the undercarriage is down STA ucStatus STA brakesStatus \ Set brakesStatus = 1, so the brakes are on STA landingStatus \ Set landingStatus = 1, so we do all landing tasks JSR IndicatorU \ Update the undercarriage indicator LDA #1 \ Set onGround = 1, so we start on the ground STA onGround LDA #47 \ Set lineBuffer2Count = 47, so line buffer 2 is empty STA lineBuffer2Count LDA #255 \ Set themeStatus = 255, so the Theme is disabled STA themeStatus STA lineBuffer1Count \ Set lineBuffer1Count = 255, so line buffer 1 is empty \ We now zero the eight bytes at alienObjectId, so no \ objects are associated with any aliens LDX #7 \ Set X = 7 to use as a counter for zeroing eight bytes \ in the following loop STX xRotationHi \ Set xRotationHi = 7, so the plane tilts backwards by \ 7/256 = 9.84 degrees when its wheels are on the ground .rset4 STA alienObjectId,X \ Zero the X-th byte of alienObjectId DEX \ Decrement the byte counter BPL rset4 \ Loop back until we have zeroed all 8 alienObjectId \ bytes \ We now zero alienSlot+1 to alienSlot+3 to clear out \ the rest of the alien slots (we already zeroed \ alienSlot above) LDX #2 \ Set X = 2 to use as a counter for zeroing three bytes \ in the following loop .rset5 STA alienSlot+1,X \ Zero the X-th byte of alienSlot+1 DEX \ Decrement the byte counter BPL rset5 \ Loop back until we have zeroed all three bytes JSR IndicatorT \ Update the Theme indicator LDX #11 \ Update the thrust indicator JSR UpdateIndicator LDA #65 \ Set fuelLevel = 65, to indicate a full tank STA fuelLevel \ We now drain the fuel tank one point at a time, \ updating the fuel gauge as we go so the fuel gauge \ gets cleared down to empty at the same time as \ the value in fuelLevel .rset6 DEC fuelLevel \ Decrement the counter in fuelLevel JSR UpdateFuelGauge \ Update the fuel gauge LDA fuelLevel \ Loop back until fuelLevel = 0, by which point we have BNE rset6 \ reset the fuel tanks and cleared the fuel gauge \ Fall through into ResetRadar to reset the radar \ display