Any idea what would cause two different results

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

Moderator: Moderators

Post Reply
Pennywise
Posts: 70
Joined: Tue Jul 14, 2009 11:04 am

Any idea what would cause two different results

Post by Pennywise »

The first is how the code is supposed to work and the second is the problem area.

Code: Select all

$DFFE:B1 7A     LDA ($7A),Y @ $BE6E = #$46                                     A:01 X:FF Y:00 S:FB P:nvUbdIZc 
$E000:C8        INY                                                            A:46 X:FF Y:00 S:FB P:nvUbdIzc 
$E001:48        PHA                                                            A:46 X:FF Y:01 S:FB P:nvUbdIzc 
$E002:29 0F     AND #$0F                                                       A:46 X:FF Y:01 S:FA P:nvUbdIzc 
$E004:85 76     STA $0076 = #$00                                               A:06 X:FF Y:01 S:FA P:nvUbdIzc 
$E006:C6 76     DEC $0076 = #$06                                               A:06 X:FF Y:01 S:FA P:nvUbdIzc 
$E008:68        PLA                                                            A:06 X:FF Y:01 S:FA P:nvUbdIzc 
$E009:2A        ROL                                                            A:46 X:FF Y:01 S:FB P:nvUbdIzc 
$E00A:2A        ROL                                                            A:8C X:FF Y:01 S:FB P:NvUbdIzc 

Code: Select all

$DFFE:B1 7A     LDA ($7A),Y @ $BC63 = #$46                                     A:01 X:FF Y:00 S:FB P:nvUbdIZC 
$E000:C8        INY                                                            A:46 X:FF Y:00 S:FB P:nvUbdIzC 
$E001:48        PHA                                                            A:46 X:FF Y:01 S:FB P:nvUbdIzC 
$E002:29 0F     AND #$0F                                                       A:46 X:FF Y:01 S:FA P:nvUbdIzC 
$E004:85 76     STA $0076 = #$00                                               A:06 X:FF Y:01 S:FA P:nvUbdIzC 
$E006:C6 76     DEC $0076 = #$06                                               A:06 X:FF Y:01 S:FA P:nvUbdIzC 
$E008:68        PLA                                                            A:06 X:FF Y:01 S:FA P:nvUbdIzC 
$E009:2A        ROL                                                            A:46 X:FF Y:01 S:FB P:nvUbdIzC 
$E00A:2A        ROL                                                            A:8D X:FF Y:01 S:FB P:NvUbdIzc 
I don't understand why the first ROL is turning 46 into 8D when it should be 8C. Anyone have any idea why this happening.
3gengames
Formerly 65024U
Posts: 2281
Joined: Sat Mar 27, 2010 12:57 pm

Re: Any idea what would cause two different results

Post by 3gengames »

Because the carry is set in the 2nd one, that's what it's supposed to do the ROL and ROR. Move the bits over one and the new bit is equal to the carry code. If you don't want anything from the carry being put into the variable and want it to bring in a zero, use ASL and LSR.
User avatar
tokumaru
Posts: 12106
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Any idea what would cause two different results

Post by tokumaru »

Yeah, something that happened before this code set the carry in the second case, and the carry is being rolled into A.
User avatar
rainwarrior
Posts: 8062
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Any idea what would cause two different results

Post by rainwarrior »

You can see exactly what the problem is if you look at the rightmost column of your trace.

Anyhow, to chime in redundantly (sorry), your first ROL should be an ASL if you don't want it to pick up whatever was in the carry. (You don't show us enough code to know what sets the carry, none of your instructions before ROL modify it.)
Post Reply