Tuesday, November 29, 2011

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

No comments:

Post a Comment