Wednesday, November 23, 2011

TUTORIAL #5 - CLRSET - "Reset specific variables during movement"



TUTORIAL #5 – CLRSET “Initialize all variables after each movement of the character”



I will be going through the subroutine CLRSET line-by-line and explaining what each line of code is doing and how it affects the outcome of the program.



Subroutine CLRSET is called from one of four movement subroutines:  MVRHT, MVLFT, MVUP, or MVDOWN, this subroutine is used with the UP, DOWN, LEFT, and RIGHT movement of the character tile. 



The subroutine CLRSET is used to reinitialize specific variables after you move your character UP, DOWN, LEFT, or RIGHT!  As you move around the world map you need specific counter variables to be reset to zero, this subroutine make this work without causing the ONE-TIME start variable to reset and error the program.  You have to use a separate subroutine to initialize the updating variables because if you used the INITIAL subroutine again it would start all the variable back to step one in the program and would make the program think it was starting for the first time.  Since specific variable get incremented and de-incremented during the running of the program, once the program starts you only want these certain variable to reset and creating a separate subroutine just for these specific variable allows you to accomplish this.



110  ***** CLEAR VARIABLES ******



This is just a comment line to separate each subroutine and helps to define the start of the clrset subroutine. 



111   CLRSET                LDA   #$00



Line 111 is used to “[L]oa[D] the [A]ccumulator” or register A with the value equal to zero!  So, you are setting the value of A to equal the HEX value of $00, which equals decimal value of 0.  Also, line 111 has a header titled CLRSET, which allows it to be called from a separate statement as a subroutine.  In this case it is used to initialize all the variables with a zero, a HEX value, a DECIMAL value, or a CONSTANT.



112                                STA   TCOUNT



Line 112 is used to “[ST]ore the [A]ccumulator” or take the value that has been stored in register A and place it in variable TCOUNT, which in this case equal HEX value $00 or the decimal value of 0.   TCOUNT is a simple loop incremental counter used within the LOADSHP subroutine to check when 10 rows of tiles have been drawn.



113                                STA   MAPCOUNT



Line 113 is used to “[ST]ore the [A]ccumulator” or take the value that has been stored in register A and place it in variable MAPCOUNT, which in this case equal HEX value $00 or the decimal value of 0.   MAPCOUNT is a used within LOADMAP and LOADSHP subroutines.  It is used as an incremental counter within these subroutines and will be explained more with these two subroutines.



114                                STA   STEPPB



Line 114 is used to “[ST]ore the [A]ccumulator” or take the value that has been stored in register A and place it in variable STEPPB, which in this case equal HEX value $00 or the decimal value of 0.   STEPPB is a used within the LOADSHP subroutine.  It is used as an incremental counter to check when each of the two byes for each shape has been drawn on the screen line by line.



115                                STA   LINEA



Line 115 is used to “[ST]ore the [A]ccumulator” or take the value that has been stored in register A and place it in variable LINEA, which in this case equal HEX value $00 or the decimal value of 0.   LINEA is a used as a loop counter to keep track of the160 bytes lines that a referenced from line 0 to 159 down the screen. As LINEA increments by 1 then the next line byte is referenced and displayed until LINEA reaches 159.



116                                STA   BYTEA



Line 116 is used to “[ST]ore the [A]ccumulator” or take the value that has been stored in register A and place it in variable BYTEA, which in this case equal HEX value $00 or the decimal value of 0.   BYTEA is a used as a loop counter to keep track of the 40 bytes that a referenced across the screen.  As BYTEA increments by 1 then the next tile byte is referenced and displayed until BYTEA reaches 39.



117                                STA   TPCNT



Line 117 is used to “[ST]ore the [A]ccumulator” or take the value that has been stored in register A and place it in variable TPCNT, which in this case equal HEX value $00 or the decimal value of 0.   TPCNT is used within the LOADMAP subroutine which stands for "Temp Counter".  It is used within a loop routine to count up to 20 for the number of tiles stored to be displayed on the each column of the screen.



118                                STA   STEPR1



Line 118 is used to “[ST]ore the [A]ccumulator” or take the value that has been stored in register A and place it in variable STEPR1, which in this case equal HEX value $00 or the decimal value of 0.   STEPR1 is used within the TILEPLC subroutine and is part of an incremental counter that checks when the number of tiles drawn equals the 20th tile after COLMADD.



119                                STA   TMAPCNT



Line 119 is used to “[ST]ore the [A]ccumulator” or take the value that has been stored in register A and place it in variable TPCNT, which in this case equal HEX value $00 or the decimal value of 0.   TMAPCNT is used within the LOADSHP subroutine, which stand for "Temp Map Counter".



120                                RTS



Line 120 is used to “[R]e[T]urn from [S]ubroutine”, which means that all the variables in the CLRSET subroutine have been RESET and initialized with ZERO values.   In this case, since CLRSET was initiated from one of the four movement subroutines; MVRHT, MVLFT, MVUP, or MVDOWN, it will return this line that called it and continue on through the subroutine.

As always, please email me any questions you might have.

ultima_revisited@yahoo.com

Joe

No comments:

Post a Comment