This page is a mirror of Tepples' nesdev forum mirror (URL TBD).
Last updated on Oct-18-2019 Download

Total weirdness

Total weirdness
by on (#49286)

I am writing my first ever NES rom using nesasm and I am having the strangest problem ever.

Basically, I am incrementing the x position of a sprite on every frame (I'm using VBlank). And for some reason, when i move the sprite one way (adc), it moves faster than when I move it the other way (sbc). This is basically what I'm doing:

   lda VBlankOrNo
   cmp #1
   bne WaitForVBlank
   dec VBlankOrNoagain.
   lda Player_X
   sbc #1 ; if this is adc, sprite moves faster
   sta Player_X
   lda #3
   sta $4014

   jmp infinite

I'm sure that I'm doing something completely wrong, and I apologize for the noob questions, but if someone can nudge me in the right direction, I would appreciate it.

EDIT: Can someone move this to the newbie section. I didn't mean to post it here. :oops:

by on (#49287)
ADC and SBC both take the carry flag into account. So if you want them to behave as "ADD" and "SUB" would (if they existed on the 6502), use CLC right before ADC, and SEC before SBC.

by on (#49288)
Welcome to nesdev.

It doesn't means that what you did is wrong since there is many way to do the same thing.

Just make sure that before you do an addition with adc that you clear the carry flag (clc) and when you subtract that you set it (sec). If you don't do this, all kind of strange things may happens.

I had an error like that recently by forgetting to do that same thing by accident. It's a common mistake :)


mic_ beat me for the answer it seems :)
Re: Total weirdness
by on (#49292)
toastie wrote:
lda Player_X
sbc #1 ; if this is adc, sprite moves faster
sta Player_X

You can also just INC/DEC Player_X :)

by on (#49293)
Wow, thank you so much guys!