Tuesday, November 29, 2011

TUTORIAL #10 – LOADMAP “Is used to store each 20 graphic tile/shapes that will be displayed on one of the ten horizontal lines on the screen”.



TUTORIAL #10 – LOADMAP “Is used to store each 20 graphic tile/shapes that will be displayed on one of the ten horizontal lines on the screen”.



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



At this point you have stored a number of shape/graphic tiles for one line on the world map in array ROWFNL,X which you will grab 20 of these graphic tile/shapes from this array and store them in a final array called MAPSTORE.  This MAPSTORE array will eventually store all 200 graphic tiles that will be used later to help draw all 200 graphic tiles on the screen.



190  ********************************



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



191   LOADMAP          LDY   MAPCOUNT



Line 191 is used to “[L]oa[D] register [Y]” with the value held in MAPCOUNT, which is equal to zero.  This was initialized in subroutine INITIAL!  So, you are setting Y to equal the HEX value of $00 but the reason you don’t use an initial value of zero such as #$00 is because as this subroutine is called again it must be able to progress in steps of 20 to help store all 200 graphic tiles.  If Y was initialized to zero each time when this subroutine was called it would just keep writing over the same 20 tiles in the array memory locations instead of incrementing and adding each additional group of 20 tiles till you get to a total of 200 tiles.  By using MAPCOUNT you are able to call this subroutine again and again and maintain a master counter value that doesn’t get erased until all 200 tiles are stored. 



Also, line 191 has a header titled LOADMAP which allows it to be called from a separate statement as a subroutine.  In this case it is used to store each of the 20 graphic tiles for each world map line on the computer screen to finally store all 200 graphic tiles in array MAPSTORE that will eventually be displayed on the screen.



192                                LDX   COLUMN1



Line 192 is used to “[L]oa[D] register [X]” with the value held in COLUMN1, which was initialized in the subroutine INITIAL!  The reason we use the temporary variable COLUMN1 instead of variable COLUMN is because we need to maintain an original column value and use the temporary value of column that can be incremented or decremented without losing the initial COLUMN value.  Whenever the game is saved and restored this original value will have that save screen location stored in it and this new original screen display column value.



So, in this example you are setting X to equal the HEX value in COLUMN1, which gives the starting location of the top-left corner of the world map shown on the screen when the game starts.  This is helpful because instead of wasting time looping through a counter starting at zero and counting up, this allows you to start at the initial column value and then count through to the next 20 graphic tiles or columns in this case.



193   LOADMP1          LDA   ROWFNL,X



Line 193 is used to “[L]oa[D] the [A]ccumulator” or register A with the value from array ROWFNL  location X, which mean as X is incremented so will each value within the array ROWFNL increment.  Remember previously we stored the values of each type of shape/tile graphic in array ROWFNL on the first go around. So in this example we are going to load each type of shape that was stored in ROWFNL and place it in the accumulator, and as X is incremented so will the shape that goes into register A.



Line 193 has a header titled LOADMP1, which allows it to be called again from a separate statement to be used as a loop.  In this case the loop is used to store each group of 20 shapes and store them in array MAPSTORE, which are 20 shapes at a time.



194                                STA   MAPSTORE,Y



Line 194 is used to “[ST]ore the [A]ccumulator” or take the value that has been stored in register A and place it in the array MAPSTORE,Y which in this example will be each of the 20 shapes per world map line and eventually it will store all 200 world map shape/graphic tiles shown on the computer screen.



195                                INC   MAPCOUNT



Line 195 is used to “[INC]rement” the variable MAPCOUNT by 1 or take the value that has been stored in variable MAPCOUNT and add 1 to it.  The MAPCOUNT variable will count up 20 at a time per subroutine call but will keep its value and on the next call statement it will count up again from 20 to 40, and then 40 to 60, till it gets to the final 200 shapes.  After this final count it will get reset to zero.



196                                INY



Line 196 is used to “[IN]crement register [Y]” or take the value that has been stored in register Y and add 1 to it.



197                                INX



Line 197 is used to “[IN]crement register [X]” or take the value that has been stored in register X and add 1 to it.



198                                INC   TPCNT



Line 198 is used to “[INC]rement” the variable TPCNT by 1 or take the value that has been stored variable TPCNT and add 1 to it.  Variable TPCNT or “Temporary Point Count” is used as a temporary 20 count loop cycle that gets reset after each 20 counts.



199                                LDA   TPCNT



Line 199 is used to “[L]oa[D] the [A]ccumulator” or register A with the value equal to what has been stored in variable TPCNT!  So, you are setting the value of A to equal the decimal value of TPCNT, which in this case has just been increased by 1.



200                                CMP  #$14



Once the value of TPCNT is loaded into register A, Line 200 is used to “[C]o[MP]are” what is in register A to the HEX value #$14 or decimal value of 20!  The value in TPCNT is the number of each type of shape/tile graphic for a line on the world map shown on the computer screen.  So as TPCNT increments it stores the type of shape within the array ROWFNL,X and places it in the final array MAPSTORE, once it get to 20 it has stored the correct number of shapes and then resets the loop function.



201                                BLT   LOADMP1



Line 201 is used to “[B]ranch on [L]ess [T]han”, which means that as long as the value in register A is less than [<] 20 it will continue to call the subroutine with the header LOADMP1.  Once the value of A is greater than [>] 20 it will bypass line 201 and continue to line 202.  



202                                LDA   #$00



Line 202 is used to “[L]oa[D] the [A]ccumulator” with the HEX value of zero!  So you could think of it as [A] holding the value of [0].



203                                STA   TPCNT



Line 203 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 equals zero!   By setting TPCNT to zero it lets the variable TPCNT to be reset and used again within another counter loop for the next 20 shapes.



204                                RTS



Line 204 is used to “[R]e[T]urn from [S]ubroutine”, which means that all the actions in the LOADMAP subroutine have been completed.   In this case, since LOADMAP was initiated from BEGIN when the program it will return to that subroutine.  On further call to this subroutine it will continue to be called from subroutine START8 instead.



So, when subroutine LOADMAP finishes you should have the following accomplished: 



You should have taken 20 shapes such as an OCEAN, MOUNTAIN, etc from array ROWFNL that were designated as the starting location of your character on the screen and stored them in the main array MAPSTORE for final screed draw usage.  This final array will be used to help draw the 200 graphic tiles of the world map on the computer screen.



An example of what might be stored in MAPSTORE:



MAPSTORE,0 = 14   “OCEAN”

MAPSTORE,1 = 14   “OCEAN”

MAPSTORE,2 = 15   “MOUNTAIN”

MAPSTORE,3 = 4   “PLAINS”

MAPSTORE,4 = 4   “PLAINS”

MAPSTORE,5 = 4   “PLAINS”

MAPSTORE,6 = 4   “PLAINS”

MAPSTORE,7 = 3   “TREES”

MAPSTORE,8 = 3   “TREES”

MAPSTORE,9 = 3   “TREES”

MAPSTORE,10 = 15   “MOUNTAIN”

MAPSTORE,11 = 15   “MOUNTAIN”



THRU



MAPSTORE,19 = 14  “OCEAN”



This could be the top line of the world map shown on the computer screen.   This process will happen 10 more times to store all 200 shapes for the entire computer screen.


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

ultima_revisited@yahoo.com

Joe


No comments:

Post a Comment