Monday, November 28, 2011

TUTORIAL #7 – PREPROW “Stores each map reference HEX number in a MAPROW array”



TUTORIAL #7 – PREPROW  “Stores each map reference HEX number in a MAPROW array”  This mean that previously when we mentioned before in line 841:



841      MAP1              DFB      $0C,$FE,$FE,$FE,$FE,$FE,$FE,$FE,$FE,$FE,$FE,$FE,$AE



All the number and types of shape/tile graphics, which are defined in this map address line, are after HEX reference $0C.  We are now going to take each one of these HEX reference numbers and store them in an array called MAPROW that will store each of the 12 HEX values.



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





133  ********************************



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



134   PREPROW          LDA   ROWNO



Line 134 is used to “[L]oa[D] the [A]ccumulator” or register A with the value equal to the value held in ROWNO!  So, you are setting the value of A to equal the predefined value of ROWNO, which is defined within the INITIAL subroutine.  Also, line 134 has a header titled PREPROW, which allows it to be called from a separate statement as a subroutine.  In this case it is used to obtain the HEX value that represents the number and type of shapes within a Map Address line.



135                               ASL   A



Line 135 is used to “[A]ccumulator [S]hift [L]eft one bit” which takes the binary value in register A and shifts in one bit to the left.  So, if register A equals HEX 34 or decimal 52, then the binary value equals 00110100, which is in the accumulator.  Now you shift the binary value to the left by one and you get 01101000, which equals HEX 68 or decimal 104.



136                               TAX



Line 136 is used to “[T]ransfer [A]ccumulator to index X” which takes the value in register A and transfers it to register X.  So, if register A equals HEX 34 or decimal 52, then register X will now equal HEX 34 or decimal 52.



137                                LDA   MAPADR,X



Line 137 is used to “[L]oa[D] the [A]ccumulator” or register A with the value equal to that held in array MAPADR,X!  As mentioned above, the MAP1 address is stored in a memory location for example in HEX memory location $6800.  When you load A with the address from MAPADR,X you will get the 00 byte from the $6800 address and load it in register A.



138                                STA   LOW



Line 138 is used to “[ST]ore the [A]ccumulator” or take the value that has been stored in register A and place it in variable LOW, which in this case is equal to HEX value $00.   Again, LOW is a used to represents the low byte of the memory address location where MAPADR 1 starts.



139                                LDA   MAPADR+1,X



Line 139 is used to “[L]oa[D] the [A]ccumulator” or register A with the value equal to that held in array MAPADR+1,X!  As mentioned above, the MAP1 address is stored in a memory location for example $6800.  When you load A with the address from MAPADR+1,X you will get the 68 byte from the $6800 address and load it in register A.



140                                STA   HIGH



Line 140 is used to “[ST]ore the [A]ccumulator” or take the value that has been stored in register A and place it in variable HIGH, which in this case is equal to HEX value $68.   Again, HIGH is a used to represents the high byte of the memory address location where MAPADR 1 starts.



141                                LDX   #$00



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



142                                LDY   #$01



Line 142 is used to “[L]oa[D] register [Y]” or register Y with the value equal to one!  So, you are setting the value of Y to equal the HEX value of $01, which equals decimal value of 1.



143   CONTT                LDA   (LOW),Y



Line 143 is used to “[L]oa[D] the [A]ccumulator” or register A with the value in the array LOW from array location 1.  Remember that Map Address 1 on line 841 is setup like an array with a starting memory location and all the bytes in the address are stored within the array.  So, as in Tutorial #6 when we needed to retrieve the HEX value $0C, now we will get the next number in the sequence since Y equals 1 we are going to retrieve the first shape/tile graphics reference number, which is HEX $FE.



Line 143 has a header titled CONTT, 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 obtain each progressive HEX reference that represents the number and type of shapes within a Map Address line.  You will see X and Y be incremented so the MAPROW array can be used to store each HEX reference within a separate X incremented array value.  This will step through and store each of the HEX $FE values until it gets to the last HEX $AE value.



144                                STA   MAPROW,X



Line 144 is used to “[ST]ore the [A]ccumulator” or take the value that has been stored in register A and place it in variable PREPMAP, which in this case equal HEX value $0C or decimal value 12.  



145                                INY



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



146                                INX



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



147                                CPX   PREPMAP



Line 147 is used to “[C]om[P]are [X]” what is in register X to the value that is held within PREPMAP.  Since the value of PREPMAP is equal to, in this case, HEX $0C or 12, then X will continue to be compared to this value and if it doesn’t equal this value it will call CONTT again, increment X and Y again, and try to compare X against PREPMAP again.  This happens until X finally equal PREPMAP.  Once this is accomplished it will finish the CONTT subroutine loop and then return to the subroutine that called it.



148                                BLT   CONTT



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



149                                RTS



Line 149 is used to “[R]e[T]urn from [S]ubroutine”, which means that all the actions in the PREPMAP subroutine have been completed.   In this case, since PREMAP was initiated from BEGIN when the program starts and will continue to be called from subroutine START8 after.



So, when subroutine CONTT finishes for the first time you should have the following accomplished: 



Array MAPROW should have the following values stored within it:



MAPROW,0 = $FE

MAPROW,1 = $FE

MAPROW,2 = $FE

MAPROW,3 = $FE

MAPROW,4 = $FE

MAPROW,5 = $FE

MAPROW,6 = $FE

MAPROW,7 = $FE

MAPROW,8 = $FE

MAPROW,9 = $FE

MAPROW,10 = $FE

MAPROW,11 = $AE





These are all the reference numbers for each shape/tile graphic on horizontal world map line #1.  When subroutine PREPROW is called again to store the next horizontal world map line #2, these values will changes again and again based on the reference numbers from each map address line.

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

ultima_revisited@yahoo.com

Joe

No comments:

Post a Comment