XOR in BASIC ???????

All aspects of programming on the Commander X16.
Post Reply
User avatar
ahenry3068
Posts: 1195
Joined: Tue Apr 04, 2023 9:57 pm

XOR in BASIC ???????

Post by ahenry3068 »

Apparently this BASIC doesn't support the XOR keywoard.
Is there any way I can do an effective XOR by combining OR, AND & NOT..

It seems to me that should be possible but I'm not coming up with the algorithm.

I'm writing a GOSUB to do 3D Buttons. I've gotten the initial Button set up
pretty well to my satisfaction now I'm working on doing the "PUSH BUTTON"
GOSUB. I could just hard code the PushButton Colors. But, I like to
make my GOSUB's easily reusable. I want the PUSHBUTTON routine
to determine the colors to use. The easiest way to do that is to read the
Pallette Entries and XOR R,G,B with FF. Redraw the button, Then
XOR it again to restore the original colors.

If I can't figure it out I'll probably just Hard Code the colors but I'm holding out hope :).
User avatar
ahenry3068
Posts: 1195
Joined: Tue Apr 04, 2023 9:57 pm

Re: XOR in BASIC ???????

Post by ahenry3068 »

I put this here for a reason. And maybe someone else is looking for an answer too.
So I won't delete. I got my answer on DISCORD. Two tricks to use.

P XOR I is equivalent to (P OR I) AND NOT(P AND I)

If expecting a 16 bit result that is all she wrote. If expecting an 8 bit result you then have to.
P XOR I >>>>> ((P OR I) AND NOT(P AND I)) AND 255

Another trick. If the value you want to XOR with is $FF

Then X = 255 - X is the same as X XOR $FF

Hope this helps someone else.
Post Reply