Just want to send some love to
php and
plp. They push the processor flags to the stack and then pull them back! That's outstanding and exciting to me because they allowed me to
Code: Select all
lda FORWARD_last
php
sta tA+1
iny ;it is 01 now
sty FORWARD_last
lda CurrentColumn
and #11110000b
plp
beq +
sec
sbc #16
+ sta t18
That runs before the main loop of see2vi. It fixes the colors and the screens from messing up when she turns around.
Those two instructions allow for the flags to be recorded, load the accumulator, and then branch according to the recorded flags! Awesome!!
edit:
php and
plp use the stack so you should read tokumaru's stack explaination on page 31 of this thread
https://forums.nesdev.com/viewtopic.php ... &start=454. 1.) Make sure everything you push on the stack inside of a function is pulled from the stack before the
rts at the end of the function. 2.) Since jsring pushes 2 bytes on the stack and
rts pulls two bytes from the stack, you shouldn't ever try to do something like
Code: Select all
function1:
lda variable
php
jsr function2
rts ;end of function1
function2:
plp
bne +
;other code here
+ rts ;end of function2
That would mess up your game considerably because after a
jsr function1 it would push 2 bytes on the stack for its rts to use, then the
php would push a third byte, then the
jsr function2 would push a fourth and fifth byte on the stack to be used by function2's rts, and the plp would pull the fifth byte pushed on the stack in this example. Your game would perish.
Hopefully that will help you to fully understand tokumaru's explaination. The stack is fun and helpful; just be cautious.
edit: added "a" before "jsr function1"; hopefully you can understand this easier.