Total weirdness

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems.

Moderator: Moderators

Post Reply
toastie
Posts: 5
Joined: Tue Jul 28, 2009 11:59 pm

Total weirdness

Post by toastie »

Hello,

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:

Code: Select all

infinite: 
WaitForVBlank:
	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:
mic_
Posts: 922
Joined: Thu Oct 05, 2006 6:29 am

Post by mic_ »

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.
User avatar
Banshaku
Posts: 2404
Joined: Tue Jun 24, 2008 8:38 pm
Location: Japan
Contact:

Post by Banshaku »

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 :)

edit:

mic_ beat me for the answer it seems :)
Cybergoth
Posts: 29
Joined: Thu Sep 14, 2006 1:35 am

Re: Total weirdness

Post by Cybergoth »

toastie wrote:

Code: Select all

lda Player_X
sbc #1 ; if this is adc, sprite moves faster 
sta Player_X
You can also just INC/DEC Player_X :)
toastie
Posts: 5
Joined: Tue Jul 28, 2009 11:59 pm

Post by toastie »

Wow, thank you so much guys!
Post Reply