TUTORIAL #14 – DRAW “Is used to help redraw the section of the world map on the screen after each character move of UP/DOWN/RIGHT/LEFT”
I will be going through the subroutine DRAW 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 in the program you have the world map
section of the screen drawn and the program is waiting for you to make a move
decision of UP/DOWN/LEFT or RIGHT! Once
this move decision is entered with a key stroke then the program will shift all
the graphic tiles/shapes and redraw the display screen with a new section of
the world map.
360 ********************************
This is just a comment line to separate each subroutine and
helps to define the start of the DRAW subroutine.
361 DRAW LDX #$00
Line 361 is used to “[L]oa[D] register [X]” or
register X with the value equal to HEX $00!
So, you are setting the register X to equal the HEX value of $00, which
equals decimal value of 0. This is what
is called a zero reset statement used to reset or start a register value that
will be used within a loop statement.
Also, line 361 has a header titled DRAW, which allows it to
be called as a separate subroutine from the START8A subroutine.
362 DRAW1 LDY BYTEA
Line 362 is used to “[L]oa[D] register [Y]” or
register Y with the value in BYTEA! So,
you are setting the register Y to equal the value of BYTEA, which was set to
zero in the CLRSET subroutine.
Also, line 362 has a header titled DRAW1, which allows it to
be called as a separate SUB-subroutine within the DRAW subroutine. In this case it is used within a loop so we
don’t have to call the DRAW subroutine and reset the register of X to zero
again.
363 LDA HI,X
Line 363 is used to “[L]oa[D] the [A]ccumulator”
or register A with the value equal to that held in array HI,X!
364 STA HIGH
Line 364 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.
Again, HIGH is a used to
represents the HIGH byte of the memory address location where SHPADR starts.
365 LDA LO,X
Line 365 is used to “[L]oa[D] the [A]ccumulator”
or register A with the value equal to that held in array LO,X!
366 STA LOW
Line 366 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.
Again, LOW is a used to
represents the high byte of the memory address location where SHPADR starts.
367 LDA TEMP,X
Line 367 is used to “[L]oa[D] the [A]ccumulator”
or register A with the value equal to that held in array TEMP,X.
368 STA (LOW),Y
Line 368 is used to “[ST]ore
the [A]ccumulator” or take the value that has
been stored in register A and place it in array (LOW),Y.
Again, this array will be used to help draw the new transportation mode
shape from the TEMP arrays.
368 INY
Line 369 is used to “[IN]crement
register [Y]” or take the value that has been
stored in register Y and add 1 to it.
370 LDA TEMP1,X
Line 370 is used to “[L]oa[D] the [A]ccumulator”
or register A with the value equal to that held in array TEMP1,X.
371 STA (LOW),Y
Line 371 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),Y.
372 INX
Line 372 is used to “[IN]crement
register [X]” or take the value that has been
stored in register X and add 1 to it.
373 CPX #$A0
;160 LINES
Line 373 is used to “[C]om[P]are [X]” what is in register X
to the value that is held within #$A0, which is equal to 160. Remember that 160 equal’s the number of
horizontal lines down the display screen that make up all the lines for the
shapes/tile graphics. So this statement
is basically doing a comparison to see if the last graphic line has been hit
and then start drawing from the top of the screen again. Also, the “;160 lines” is just a comment to
tell you that the value of HEX #$A0 is equal to 160 display screen horizontal
graphic lines.
374 BLT
DRAW1
Line 374 is used to “[B]ranch
on [L]ess [T]han”,
which means that as long as the value in register X is less than [<] 160 it
will continue to call the subroutine with the header DRAW1. Once the value of X is greater than [>]
160 and has hit the bottom of the graphics screen, it will bypass line 374 and
continue to line 375.
375 INC BYTEA
Line 375 is used to “[INC]rement”
the variable BYTEA by 1 or take the value that has been stored in variable
BYTEA and add 1 to it. Remember that
BYTEA stands for the number of bytes in the shape which is two per
shape/graphic tile, so by incrementing x2, which the next two statements do,
you are side stepping to the right two bytes to get ready to start drawing the
next column of shapes down the display screen.
If you didn’t do this double increment, you would end up drawing right
on top of the shapes you just had drawn to the screen!
376 INC BYTEA
Line 376 is used to “[INC]rement”
the variable BYTEA by 1 or take the value that has been stored in variable
BYTEA and add 1 to it. AGAIN**** Remember that BYTEA stands for the number of
bytes in the shape which is two per shape/graphic tile, so by incrementing x2,
which the next two statements do, you are side stepping to the right two bytes
to get ready to start drawing the next column of shapes down the display screen
377 RTS
Line 377 is used to “[R]e[T]urn from [S]ubroutine”,
which means that all the actions in this subroutine have been completed and is
return to the subroutine that called it, which would actually be the START1A
subroutine.
So, when subroutine DRAW finishes you should have the
following accomplished:
After each time you move your character on the screen the
entire display screen must shift the opposite direction to the direction of
your movement. So, for example if you want your character to move to the RIGHT,
all the graphic tiles/shapes on the display screen will shift [1] position to
the LEFT and then be redrawn to the screen.
The DRAW subroutine is used for that purpose. We can’t use the initial DRAW subroutine
because if functions a little different.
The main difference is DRAW is use at the initial display screen draw
phase at the start of the program, where DRAW is used after the program has
started and draws the tiles after they have been shifted [1] position to the
RIGHT/LEFT/UP or DOWN.
No comments:
Post a Comment