Page 2 of 2

Re: Custom char issue in 6502

Posted: Sat Feb 25, 2023 2:42 am
by MartinC
Thanks Chysn, you're right that is really elegant, reusing the same pointer for both purposes.

Re: Custom char issue in 6502

Posted: Sat Feb 25, 2023 7:33 am
by MartinC
Worked a treat and my routine is working primo :D Thanks for the help

Re: Custom char issue in 6502

Posted: Tue Mar 07, 2023 11:16 am
by MartinC
So is there a short cut using the same EOR method to adding / subtracting 72? I have a char set with 144 characters, first 72 are normal video, final 72 are reversed and I need code to switch between them.

I tried EOR and got the wrong answer. So I just wrote the longer version with adc/sbc.

24 EOR 97 = 121

So 24 EOR 121 = 97

But if I do 25 EOR 121 = 96 (and I need 98 as a result).

25 EOR 123 = 98

I'm probably being very dumb - but if I have to write code to calculate the EOR operand, I may as well just write the longer adc/sbc version? Or not?

Cheers

Martin

Re: Custom char issue in 6502

Posted: Tue Mar 07, 2023 6:53 pm
by chysn
MartinC wrote: Tue Mar 07, 2023 11:16 am So is there a short cut using the same EOR method to adding / subtracting 72?
TL;DR: No, not really.

You have to think about EOR, its operand, and the Accumulator, in binary terms. It's not anything like addition or subtraction. Each bit in the accumulator is set to 1 if and only if the corresponding operand bit's value is different than the one in the accumulator. So repeated operations with the same operand will cause the same bits to flip, resulting in moving back and forth between two values.

While I think it would be informative to see your actual code, it sounds like your best bet here is ADC/SBC.

Re: Custom char issue in 6502

Posted: Sat Mar 11, 2023 3:30 am
by MartinC
Thanks - it's working that way just fine, just trying to be efficient :D

Re: Custom char issue in 6502

Posted: Sun Mar 12, 2023 6:17 am
by Mike
Here's my take on it, the four instructions in $02A1..$02A6:

Image

Upon the G 02A1 command and subsequent monitor G commands, $23 in the Accumulator toggles with $6B, and this also works as expected with all other values in the range $00..$8F.
MartinC wrote:Thanks - it's working that way just fine, just trying to be efficient :D
One suggestion: at this stage, your code should not try to be all too clever. Getting it working correctly is far more important!

Especially the scheme of "toggling upon toggle" is prone to failures. Miss one of those instances and they get out of sync. It is much more robust to toggle only at one place and then choose either the original range (when off) or 72 added to the range (when on).