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

Any idea what would cause two different results

Any idea what would cause two different results
by on (#106993)
The first is how the code is supposed to work and the second is the problem area.

Code:
$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:
$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.
Re: Any idea what would cause two different results
by on (#106996)
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.
Re: Any idea what would cause two different results
by on (#106997)
Yeah, something that happened before this code set the carry in the second case, and the carry is being rolled into A.
Re: Any idea what would cause two different results
by on (#106999)
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.)