Skip to navigation

Main title Loop: ResetVariables

Name: ResetVariables [Show more] Type: Subroutine Category: Main title Loop Summary: Reset all the game's main variables
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * MainGameLoop calls ResetVariables * MainTitleLoop calls ResetVariables * SecretCodeError calls ResetVariables
.ResetVariables SEC \ Set bit 7 of gameInProgress to indicate that a game is ROR gameInProgress \ not currently in progress and that we are in the title \ and preview screens (so the interrupt handler doesn't \ update the game) \ We now zero the following variable blocks: \ \ * &0000 to &008F (Zero page workspace) \ \ * &0100 to &01BF (Stack variables workspace) \ \ * &0900 to &09EF (xObject) \ \ * &0A00 to &0AEF (yObjectLo) \ \ * &0C00 to &0CE3 (Main variable workspace) \ \ and set the following variable block to %10000000: \ \ * &0CE4 to &0CEF (Main variable workspace) LDX #0 \ Set X to use as a byte counter to run from 0 to &EF .rese1 LDA #0 \ Set A = 0 so we can zero the following variable blocks STA xObject,X \ Zero the X-th byte of xObject STA yObjectLo,X \ Zero the X-th byte of yObjectLo CPX #&90 \ If X >= &90 then skip the following instruction BCS rese2 STA &0000,X \ Zero the X-th byte of zero page .rese2 CPX #&C0 \ If X >= &C0 then skip the following instruction BCS rese3 STA &0100,X \ Zero the X-th byte of &0100 .rese3 CPX #&E4 \ If X < &E4 then skip the following instruction, BCC rese4 \ leaving A = 0, so we zero &0C00 to &0CE3 LDA #%10000000 \ If we get here then X >= &E4, so set A = %10000000 to \ set bit 7 of &0CE4 to &0CEF .rese4 STA &0C00,X \ Set the X-th byte of &0CE4 to A INX \ Increment the byte counter CPX #&F0 \ Loop back until we have processed X from &E4 to &EF BCC rese1 \ to set &0CE4 to &0CEF to &80 \ Fall through into ResetTilesObjects to reset the tile \ visibility table and deallocate all object numbers