Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.
In my routine, I am able to load a register, use AND, and the value is changed. But after that, ill do the same with another register, and the value does not change....
LDA $70 ;46 is in $70
AND #$F0 ;i use this for checking bits, I want to make the (6) in the value (46) to 0, so now the value in A is 40
STA $70 ;40 into $70
Now here is where I get no change...
LDA $84 ;95 is in $84
AND #$FD ;i use this cause I want the (5) in the value (95) to become (D) making 95 into 9D, but nothing happens, and 95 still remains...
AND is used to clear bits, and OR (ORA in the 6502) is used to set bits. To set part of an arbitrary value (i.e. you don't know the value beforehand) you must first clear the bits you want to change with AND and then set them to the values you want with OR. The exceptions are when you want the modified bits to be all 0 (an AND alone can do it) or all 1 (an OR alone will do). If you want to flip bits (0 becomes 1 and 1 becomes 0) you can use a XOR (EOR on the 6502).
infidelity wrote:Id like to see if a hex value matches #8, and if it does, to branch to whatever i want.
When you say an "hex value" do you mean a nibble? Like the "8" in $38 or $8D? If so, you need to clear the bits you don't care about and then compare normally:
LDA #$FF ;11111111 in binary.
AND #$F0 ;11110000 in binary. 11110000 is the result in this case.
LSR A
LSR A
LSR A
LSR A ;A is not the same as 0000**** where **** is the same as the top 4 bits of the result of AND #$F0 since we just moved it right 4 bits.
CMP CompareValue ;Do your compare.
;Branch
infidelity wrote:I need to preserve the original left bits, while being able to properly compare then alter the right bits. I hope that makes sense.
For that you'd typically have the value stored in RAM before clearing the irrelevant half, so that later you can load it back from RAM to compare the other half.