Language…
9 users online: cozyduck, Dark Mario Bros, Firstnamebutt, Golden Yoshi, Isikoro, krizeth, monkey03297, qantuum,  Ringo - Guests: 239 - Bots: 308
Users: 64,795 (2,376 active)
Latest user: mathew

!base (Solved)

Can someone explain why something like the following works when converting addresses for sa-1 roms?

Code
STA $00|!base

I've seen a couple instances of this:

Code
STA $00+!base

Which makes sense, asar adds the two values. But the xkas/asar manual says that "|" is a bitwise OR which, to me, doesn't make much sense in this context.
A bitwise OR is actually addition without carrying over digits.

In the case of SA-1, $0100-$1FFF move to $6100-$7FFF. $6000 is equivalent to %0110000000000000 in binary, whereas $1FFF is %0001111111111111 - as you can see, nothing in the $0100-$1FFF range overlaps the bits from $6000, so a bitwise OR will behave exactly like addition.

I can really think of only one benefit of using OR rather than addition. If you do something like $6100|!base, you'll get out $6100 (so nothing changes and the address points to the correct place), but if you do $6100+!base, you'll get $C100, which is in ROM. That's actually quite a big benefit, as you can't accidentally blow up an address. Such a thing can happen if you use an SA-1 converter tool on a hybrid resource.

This is similar to why |!bank is used - nothing from $000000 to $7FFFFF (ignore for a second that fact that banks $FE and $FF aren't RAM) has its MSB set, so an OR with $800000 (which is a single 1 followed by 23 zeros) behaves like addition, except it can't overflow and completely screw up the address.

Makes me wonder if using OR has other benefits I can't think of.
Thank you for the explanation, this makes sense now.