Hello!
I need some help with the task of moving a sprite. The problem is that, with some directions, the sprite moves faster than it should... I thing it has something to do with the carry flag, but I tried to CLC before any arithmetic operation to clear the carry bit, and it was still happening.
Thanks.
Moving a sprite!
Moderator: Moderators
Ok sorry, these are the routines that move the sprite left/right and up/down. The quantmov variable is 2 or 1 whether the B button is down or not. But that's not the problem. That's just to make it run when B is pressed, and when you press it, it twices both directions.
http://www.copypastecode.com/25047/
Also, don't care about the CLC ops. That was just to try.
http://www.copypastecode.com/25047/
Also, don't care about the CLC ops. That was just to try.
- MetalSlime
- Posts: 186
- Joined: Tue Aug 19, 2008 11:01 pm
- Location: Japan
Re: Moving a sprite!
Clear the carry before adding, set the carry before subtracting:Ypsilon wrote:Hello!
I need some help with the task of moving a sprite. The problem is that, with some directions, the sprite moves faster than it should... I thing it has something to do with the carry flag, but I tried to CLC before any arithmetic operation to clear the carry bit, and it was still happening.
Thanks.
;adding
CLC
ADC #$02 ;or whatever
subtracting
SEC
SBC #$02
MetalSlime runs away.
Did you get it working?Ypsilon wrote:Okey! That's perfect. Thanks everyone!tepples wrote:You guessed correctly that it has something to do with two's complement. When you subtract n on a 6502, you actually add 255-n. To make the subtraction work as expected, you need to set the carry so that you add 255-n+1 = 256-n = -n (mod 256).