Custom char issue in 6502

Basic and Machine Language

Moderator: Moderators

MartinC
Vic 20 Drifter
Posts: 33
Joined: Tue Oct 25, 2022 12:18 pm
Website: https://winterfam.co.uk
Location: Kent,uk
Occupation: Author

Re: Custom char issue in 6502

Post by MartinC »

Thanks Chysn, you're right that is really elegant, reusing the same pointer for both purposes.
MartinC
Vic 20 Drifter
Posts: 33
Joined: Tue Oct 25, 2022 12:18 pm
Website: https://winterfam.co.uk
Location: Kent,uk
Occupation: Author

Re: Custom char issue in 6502

Post by MartinC »

Worked a treat and my routine is working primo :D Thanks for the help
MartinC
Vic 20 Drifter
Posts: 33
Joined: Tue Oct 25, 2022 12:18 pm
Website: https://winterfam.co.uk
Location: Kent,uk
Occupation: Author

Re: Custom char issue in 6502

Post 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
User avatar
chysn
Vic 20 Scientist
Posts: 1205
Joined: Tue Oct 22, 2019 12:36 pm
Website: http://www.beigemaze.com
Location: Michigan, USA
Occupation: Software Dev Manager

Re: Custom char issue in 6502

Post 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.
MartinC
Vic 20 Drifter
Posts: 33
Joined: Tue Oct 25, 2022 12:18 pm
Website: https://winterfam.co.uk
Location: Kent,uk
Occupation: Author

Re: Custom char issue in 6502

Post by MartinC »

Thanks - it's working that way just fine, just trying to be efficient :D
User avatar
Mike
Herr VC
Posts: 4841
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Custom char issue in 6502

Post 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).
Post Reply