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.