Wednesday, November 30, 2011

TUTORIAL #11 – CHARTILE “Is used to define which character shape will be displayed on the world map”


TUTORIAL #11 – CHARTILE “Is used to define which character shape will be displayed on the world map”.



I will be going through the subroutine CHARTILE 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 all the defined graphic tiles/shapes in a final array called MAPSTORE.  This MAPSTORE array stores all 200 graphic tiles that will be displayed on the computer screen.  What subroutine CHARTILE does is overwrite the center graphic tile with the shape that will represent your character such as the fighter or a horse or a ship, etc…  To do this you will store the value representing the character shape in a specific MAPSTORE,X array memory location, this specific memory location defines the exact location on the screen that the character shape will be displayed.



205  ********************************



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



206   CHARTILE           LDA   CHAR



Line 206 is used to “[L]oa[D] the [A]ccumulator” or register A with the value held in CHAR, which was defined in the INITIAL subroutine!  So, you are setting the value of A to equal the HEX value in CHAR, which is the representing value of the character shape of the fighter.  When the game begins the character shape will start out as the fighter and will change to other transportation modes as the game progresses, this CHARTILE subroutine is what makes that process happen.



Also, line 206 has a header titled CHARTILE, which allows it to be called from a separate statement as a subroutine.  In this case it is used to initialize the variables with a HEX value of $07 or the decimal value equal to 7.  This is the value used to represent the character shape of the fighter, which is initialized in subroutine INITIAL at line 95.



207                                CMP  #$0B



Once the value of CHAR is loaded into register A, Line 207 is used to “[C]o[MP]are” what is in register A to the HEX value $0B or the decimal value of 11!  The value in CHAR is the number 11 represents the shape/tile graphic for the character of the fighter.



208                                BEQ HORSE1



Line 208 is used to “[B]ranch on Result Zero Z=1”, which means that if the value in register A is compared to #$0B and it equals this value, in this case 11, then the program will branch or call jump to subroutine HORSE1.   Otherwise the program moves on to the next code line 209.



209                                CMP  #$00



Line 209 is used to “[C]o[MP]are” what is in register A to the HEX value $00 or the decimal value of 0!  The value in CHAR will represent the shape/tile graphic for the character in the middle of the screen.



210                                BEQ SHIP1



Line 210 is used to “[B]ranch on Result Zero Z=1”, which means that if the value in register A is compared to #$00 and it equals this value, in this case 0, then the program will branch or call jump to subroutine SHIP1.   Otherwise the program moves on to the next code line 211.



211                                CMP  #$01



Line 211 is used to “[C]o[MP]are” what is in register A to the HEX value $01 or the decimal value of 1!  The value in CHAR will represent the shape/tile graphic for the character in the middle of the screen.



212                                BEQ RAFT1



Line 212 is used to “[B]ranch on Result Zero Z=1”, which means that if the value in register A is compared to #$01 and it equals this value, in this case 1, then the program will branch or call jump to subroutine RAFT1.   Otherwise the program moves on to the next code line 213.



213                                CMP  #$0A



Line 213 is used to “[C]o[MP]are” what is in register A to the HEX value $0A or the decimal value of 10!  The value in CHAR will represent the shape/tile graphic for the character in the middle of the screen.



214                                BEQ CART1



Line 214 is used to “[B]ranch on Result Zero Z=1”, which means that if the value in register A is compared to #$0A and it equals this value, in this case 10, then the program will branch or call jump to subroutine CART1.   Otherwise the program moves on to the next code line 214.



215                                CMP  #$0C



Line 215 is used to “[C]o[MP]are” what is in register A to the HEX value $0C or the decimal value of 12!  The value in CHAR will represent the shape/tile graphic for the character in the middle of the screen.



216                                BEQ LANDSPR



Line 216 is used to “[B]ranch on Result Zero Z=1”, which means that if the value in register A is compared to #$0C and it equals this value, in this case 12, then the program will branch or call jump to subroutine LANDSPR.   Otherwise the program moves on to the next code line 217.



217                                CMP  #$07



Line 217 is used to “[C]o[MP]are” what is in register A to the HEX value $07 or the decimal value of 7!  The value in CHAR will represent the shape/tile graphic for the character in the middle of the screen.



218                                BEQ CHARC1



Line 218 is used to “[B]ranch on Result Zero Z=1”, which means that if the value in register A is compared to #$07 and it equals this value, in this case 7, then the program will branch or call jump to subroutine CHARC1.   Otherwise the program moves on to the next code line 219.



219                                RTS



Line 219 is used to “[R]e[T]urn from [S]ubroutine”, which means that after the SUB-subroutine of each character tile shape reference is called and updated, it returns back to here and then subroutine CHARTILE will be complete and return to the original line statement that called it. 



220   HORSE1              LDA   #$0B          ; HORSE



Since CHAR was equal to $0B or 11 the HORSE1 sub-subroutine was called.  Line 220 is used to “[L]oa[D] the [A]ccumulator” or register A with the value HEX $0B, which was compared to in the CHARTILE subroutine!  So, you are setting the value of A to equal the HEX value that was equal to the value of CHAR, which in this case is the representing value of the character shape for the HORSE.  The ;HORSE is used as a description reference line similar to a comment to give detail about the specific code line.  Anything after the ; is ignored by the compiler.



Also, line 220 has a header titled HORSE1, which allows it to be called from a separate statement as a SUB-subroutine.  In this case it is used to initialize the variables CHAR with a new HEX value of $0B or the decimal value equal to 11 and then start that value with the specific array location in MAPSTORE,X to be used as the shape in the middle of the screen.  This is the value used to represent the character shape of the HORSE.



221                                STA   CHAR



Line 221 is used to “[ST]ore the [A]ccumulator” or take the value that has been stored in register A and place it in variable CHAR, which in this case equals 11!   By setting CHAR to 11 it establishes the variable CHAR with a new value that represents the HORSE and will stay this value until a new mode of transportation or the original character shape of the fighter is designated in the game.



222                                LDX   #$6E



Line 222 is used to “[L]oa[D] register [X]” or register X with the value equal to 110!  So, you are setting the value of X to equal the HEX value of $6E, which equals decimal value of 110.



223                                STA   MAPSTORE,X



Line 223 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 at location X which in this example would be the value in CHAR or decimal 11, stored in array MAPSTORE at location X equal to 110, where 110 is represented by the graphic tile in the middle of the screen out of the 200 tiles.  Remember, tiles are counted 0 to 19 for the top horizontal screen line and then they go down one tile screen line and count 20 to 39, etc… till you get to tile 199!



224                                RTS



Line 224 is used to “[R]e[T]urn from [S]ubroutine”, which means that after the SUB-subroutine HORSE1 has updated the new shape and location values, it returns back to subroutine CHARTILE which will then immediately return to the original line statement that called it. 



225   SHIP1                  LDA   #$00



Since CHAR was equal to $00 or 0 the SHIP1 sub-subroutine was called.  Line 225 is used to “[L]oa[D] the [A]ccumulator” or register A with the value HEX $00, which was compared to in the CHARTILE subroutine!  So, you are setting the value of A to equal the HEX value that was equal to the value of CHAR, which in this case is the representing value of the character shape for the SHIP. 



Also, line 225 has a header titled SHIP1, which allows it to be called from a separate statement as a SUB-subroutine.  In this case it is used to initialize the variables CHAR with a new HEX value of $00 or the decimal value equal to 0 and then start that value with the specific array location in MAPSTORE,X to be used as the shape in the middle of the screen.  This is the value used to represent the character shape of the SHIP.



226                                STA   CHAR



Line 226 is used to “[ST]ore the [A]ccumulator” or take the value that has been stored in register A and place it in variable CHAR, which in this case equals 0!   By setting CHAR to 0 it establishes the variable CHAR with a new value that represents the SHIP and will stay this value until a new mode of transportation or the original character shape of the fighter is designated in the game.



227                                LDX   #$6E



Line 227 is used to “[L]oa[D] register [X]” or register X with the value equal to 110!  So, you are setting the value of X to equal the HEX value of $6E, which equals decimal value of 110.



228                                STA   MAPSTORE,X



Line 228 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 at location X which in this example would be the value in CHAR or decimal 0, stored in array MAPSTORE at location X equal to 110, where 110 is represented by the graphic tile in the middle of the screen out of the 200 tiles.  Remember, tiles are counted 0 to 19 for the top horizontal screen line and then they go down one tile screen line and count 20 to 39, etc… till you get to tile 199!



229                                RTS



Line 229 is used to “[R]e[T]urn from [S]ubroutine”, which means that after the SUB-subroutine SHIP1 has updated the new shape and location values, it returns back to subroutine CHARTILE which will then immediately return to the original line statement that called it. 



230   RAFT1                 LDA   #$01



Since CHAR was equal to $01 or 1 the RAFT1 sub-subroutine was called.  Line 230 is used to “[L]oa[D] the [A]ccumulator” or register A with the value HEX $01, which was compared to in the CHARTILE subroutine!  So, you are setting the value of A to equal the HEX value that was equal to the value of CHAR, which in this case is the representing value of the character shape for the RAFT. 



Also, line 230 has a header titled RAFT1, which allows it to be called from a separate statement as a SUB-subroutine.  In this case it is used to initialize the variables CHAR with a new HEX value of $01 or the decimal value equal to 1 and then start that value with the specific array location in MAPSTORE,X to be used as the shape in the middle of the screen.  This is the value used to represent the character shape of the RAFT.



231                                STA   CHAR



Line 231 is used to “[ST]ore the [A]ccumulator” or take the value that has been stored in register A and place it in variable CHAR, which in this case equals 1!   By setting CHAR to 0 it establishes the variable CHAR with a new value that represents the RAFT and will stay this value until a new mode of transportation or the original character shape of the fighter is designated in the game.



232                                LDX   #$6E



Line 232 is used to “[L]oa[D] register [X]” or register X with the value equal to 110!  So, you are setting the value of X to equal the HEX value of $6E, which equals decimal value of 110.



233                                STA   MAPSTORE,X



Line 233 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 at location X which in this example would be the value in CHAR or decimal 1, stored in array MAPSTORE at location X equal to 110, where 110 is represented by the graphic tile in the middle of the screen out of the 200 tiles.  Remember, tiles are counted 0 to 19 for the top horizontal screen line and then they go down one tile screen line and count 20 to 39, etc… till you get to tile 199!



234                                RTS



Line 234 is used to “[R]e[T]urn from [S]ubroutine”, which means that after the SUB-subroutine RAFT1 has updated the new shape and location values, it returns back to subroutine CHARTILE which will then immediately return to the original line statement that called it. 



235   CART1                 LDA   #$0A



Since CHAR was equal to $0A or 10 the CART1 sub-subroutine was called.  Line 235 is used to “[L]oa[D] the [A]ccumulator” or register A with the value HEX $0A, which was compared to in the CHARTILE subroutine!  So, you are setting the value of A to equal the HEX value that was equal to the value of CHAR, which in this case is the representing value of the character shape for the CART. 



Also, line 235 has a header titled CART1, which allows it to be called from a separate statement as a SUB-subroutine.  In this case it is used to initialize the variables CHAR with a new HEX value of $0A or the decimal value equal to 10 and then start that value with the specific array location in MAPSTORE,X to be used as the shape in the middle of the screen.  This is the value used to represent the character shape of the CART.



236                                STA   CHAR



Line 236 is used to “[ST]ore the [A]ccumulator” or take the value that has been stored in register A and place it in variable CHAR, which in this case equals 10!   By setting CHAR to 10 it establishes the variable CHAR with a new value that represents the CART and will stay this value until a new mode of transportation or the original character shape of the fighter is designated in the game.



237                                LDX   #$6E



Line 237 is used to “[L]oa[D] register [X]” or register X with the value equal to 110!  So, you are setting the value of X to equal the HEX value of $6E, which equals decimal value of 110.



238                                STA   MAPSTORE,X



Line 238 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 at location X which in this example would be the value in CHAR or decimal 10, stored in array MAPSTORE at location X equal to 110, where 110 is represented by the graphic tile in the middle of the screen out of the 200 tiles.  Remember, tiles are counted 0 to 19 for the top horizontal screen line and then they go down one tile screen line and count 20 to 39, etc… till you get to tile 199!



239                                RTS



Line 239 is used to “[R]e[T]urn from [S]ubroutine”, which means that after the SUB-subroutine CART1 has updated the new shape and location values, it returns back to subroutine CHARTILE which will then immediately return to the original line statement that called it. 



240   LANDSPR            LDA   #$0C



Since CHAR was equal to $0C or 12 the LANDSPR sub-subroutine was called.  Line 240 is used to “[L]oa[D] the [A]ccumulator” or register A with the value HEX $0C, which was compared to in the CHARTILE subroutine!  So, you are setting the value of A to equal the HEX value that was equal to the value of CHAR, which in this case is the representing value of the character shape for the LANDSPR. 



Also, line 240 has a header titled SHIP1, which allows it to be called from a separate statement as a SUB-subroutine.  In this case it is used to initialize the variables CHAR with a new HEX value of $0C or the decimal value equal to 12 and then start that value with the specific array location in MAPSTORE,X to be used as the shape in the middle of the screen.  This is the value used to represent the character shape of the LANDSPR.



241                                STA   CHAR



Line 241 is used to “[ST]ore the [A]ccumulator” or take the value that has been stored in register A and place it in variable CHAR, which in this case equals 12!   By setting CHAR to 12 it establishes the variable CHAR with a new value that represents the SHIP and will stay this value until a new mode of transportation or the original character shape of the fighter is designated in the game.



242                                LDX   #$6E



Line 242 is used to “[L]oa[D] register [X]” or register X with the value equal to 110!  So, you are setting the value of X to equal the HEX value of $6E, which equals decimal value of 110.



243                                STA   MAPSTORE,X



Line 243 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 at location X which in this example would be the value in CHAR or decimal 12, stored in array MAPSTORE at location X equal to 110, where 110 is represented by the graphic tile in the middle of the screen out of the 200 tiles.  Remember, tiles are counted 0 to 19 for the top horizontal screen line and then they go down one tile screen line and count 20 to 39, etc… till you get to tile 199!



244                                RTS



Line 244 is used to “[R]e[T]urn from [S]ubroutine”, which means that after the SUB-subroutine LANDSPR has updated the new shape and location values, it returns back to subroutine CHARTILE which will then immediately return to the original line statement that called it. 



245   CHARC1              LDA   #$07



Since CHAR was equal to $07 or 7 the CHARC1 sub-subroutine was called.  Line 245 is used to “[L]oa[D] the [A]ccumulator” or register A with the value HEX $07, which was compared to in the CHARTILE subroutine!  So, you are setting the value of A to equal the HEX value that was equal to the value of CHAR, which in this case is the representing value of the character shape for the CHARaCter. 



Also, line 245 has a header titled CHARC1, which allows it to be called from a separate statement as a SUB-subroutine.  In this case it is used to initialize the variables CHAR with a new HEX value of $07 or the decimal value equal to 7 and then start that value with the specific array location in MAPSTORE,X to be used as the shape in the middle of the screen.  This is the value used to represent the character shape of the CHARaCter.



246                                STA   CHAR



Line 246 is used to “[ST]ore the [A]ccumulator” or take the value that has been stored in register A and place it in variable CHAR, which in this case equals 7!   By setting CHAR to 7 it establishes the variable CHAR with a new value that represents the CHARC and will stay this value until a new mode of transportation is designated in the game.



247                                LDX   #$6E



Line 247 is used to “[L]oa[D] register [X]” or register X with the value equal to 110!  So, you are setting the value of X to equal the HEX value of $6E, which equals decimal value of 110.



248                                STA   MAPSTORE,X



Line 248 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 at location X which in this example would be the value in CHAR or decimal 7, stored in array MAPSTORE at location X equal to 110, where 110 is represented by the graphic tile in the middle of the screen out of the 200 tiles. 



249                                RTS



Line 249 is used to “[R]e[T]urn from [S]ubroutine”, which means that after the SUB-subroutine CHARC1 has updated the new shape and location values, it returns back to subroutine CHARTILE which will then immediately return to the original line statement that called it. 



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



You should have taken the initial value of CHAR, which is HEX $07 or decimal 7 when the game begins, and run it through subroutine CHARTILE to compare it to the [6] defined shape values;



SHIP

RAFT

CART

HORSE

LANDSPEEDER

FIGHTER – Main Character shape”



When CHAR is equal to one of these values it redefines the new value of CHAR and changes the shape which will be displayed in the middle of the screen.  This subroutine gets called whenever the game starts or after a new mode of transportation is designated within the game.

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

ultima_revisited@yahoo.com

Joe

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


TUTORIAL #9 – TILEPLC “Is used to store each shape/graphic tile from the left edge of the map to the 20th tile past the starting tile column value”


TUTORIAL #9 – TILEPLC “Is used to store each shape/graphic tile from the left edge of the map to the 20th tile past the starting tile column value”.

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

Now that you have the HIGH and LOW bytes for the number and type of shapes/tile graphics for one line of the world map, you will store them in the array ROWFNL,X.

174  ********************************

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

175   TILEPLC               LDY   #$00

Line 175 is used to “[L]oa[D] register [Y]” with the value equal to zero!  So, you are setting X to equal the HEX value of $00, which equals decimal value of 0.  Also, line 175 has a header titled TILEPLC, which allows it to be called from a separate statement as a subroutine.  In this case it is used store the HIGH and LOW byte of each HEX value that represents the number and type of shapes within the array ROWFNL,X.

176                                 LDX   #$00

Line 176 is used to “[L]oa[D] register [X]” with the value equal to zero!  So, you are setting X to equal the HEX value of $00, which equals decimal value of 0. 

177   TILEPLC1             LDA   LBYTE,Y



Line 177 is used to “[L]oa[D] the [A]ccumulator” or register A with the value from array LBYTE location Y, which mean as Y is incremented so will each value within the array LBYTE.  Remember previously we stored the value of the type of shape/tile graphic in LBYTE,Y on the first go around. So in this example we are going to store each type of shape in a final array ROWFNL and count through a loop using the value in HBYTE, which equals the number of that type of shape on the world map.

Line 177 has a header titled TILEPLC1, 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 progressive HEX reference number from array LBYTE,Y, which is the shape type.  You will see Y incremented so that the HBYTE array can be used for the counter to store the number of that type of shape.  This will step through and store each shape values until it gets to the last shape on the line of the world map.  Every time this subroutine is called it is used to process each horizontal world map line.

178                                STA   ROWFNL,X

Line 178 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 ROWFNL,X which in this example equal to the number and type of each shape/tile graphics for each world map line.

179                                INX

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

180                                INC   STEPR1

Line 180 is used to “[INC]rement” the variable STEPR1 by 1 or take the value that has been stored variable STEPR1 and add 1 to it.

181                                LDA   STEPR1

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

182                                CMP  HBYTE,Y



Once the value of STEPR1 is loaded into register A, Line 182 is used to “[C]o[MP]are” what is in register A to the HEX value of array HBYTE,Y.  The value in array HBYTE,Y is the number of each type of shape/tile graphic for a line on the world map so as HBYTE,Y increments it stores the type of shape within the array ROWFNL,X.  The example would be:  if the original HEX was $FE then HBYTE,Y would equal 15 and the as LBYTE equals 14 or the shape type, in this case OCEAN, it is storing a 14 every time STEPR1 is incremented until it compares with HBYTE,Y.  Once this comparison happens, it increments to the next shape and advances through the loop again for that number of shapes.

183                                BLT   TILEPLC1

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

184                                INY

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

185                                LDA   #$00

Line 185 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 0.

186                                 STA   STEPR1

Line 186 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 equals zero!   By setting SETPR1 to zero it lets the next HBYTE,Y loop count through the next number of shape/tile graphics on the line of the world map.

187                                CPX   COLMADD

Line 187 is used to “[C]om[P]are [X]” what is in register X to the value that is held within COLMADD.  Since the value of COLOMADD is equal to the 20th column after the initial COLUMN value, so X will continue to be compared to this value and if it doesn’t equal this value it will call TILEPLC1 again, increment X again, and continue to try to compare X against COLMADD until X finally equal COLMADD and when this is accomplished it will finish the TILEPLC subroutine loop and then return to the subroutine that called it.

188                                BLT   TILEPLC1

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

189                                RTS

Line 189 is used to “[R]e[T]urn from [S]ubroutine”, which means that all the actions in the TILEPLC subroutine have been completed.   In this case, since TILEPLC 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 TILEPLC finishes you should have the following accomplished: 

All the shapes/tile graphics on a horizontal line of the world map will be stored in the array ROWFNL up to the 20th tile past the initial COLUMN value.  So for example array ROWFNL would have the following values stored in it.  It would have 15, OCEAN tiles, then another 15 OCEAN tiles, and another 15 OCEAN tiles, etc… until it got to the 20th tile after the initial COLUMN value, which is equal to COLMADD.

ROWFNL,0 = 14

ROWFNL,1 = 14

ROWFNL,2 = 14

ROWFNL,3 = 14

ROWFNL,4 = 14

ROWFNL,5 = 14

ROWFNL,6 = 14

ROWFNL,7 = 14

Etc…

ROWFNL,57=14



This subroutine will initially get called to create the 10 rows of shapes/tile graphics that are shown on the start screen with the character in the middle.  Each time your character moves then this subroutine will get called from START8 and generate the shapes/tile graphics for the next 10 rows of shapes on the screen.


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

ultima_revisited@yahoo.com

Joe