Help Kodiak64 for FREE!

Click here to read how.

Share this page

Kodiak64 Newsletter

100% free, 100% spam-free!

(You can view a sample here).


ORA: A Special Use in Branch Testing

Posted on

By Kodiak


In a recent post, I talked about some special uses for the EOR instruction, particularly with regard to saving CPU time on addition and subtraction.

Now it's the turn of ORA, which can also be used for adding within certain conditions on 6502, as per this Codebase piece on Combining Bits / Substitute Logical Operations.

Changing track from maths, a nice little hack you can apply (and which is used occasionally in Parallaxian) is where you start with something prosaic like this:

Bloaty way to test multiple conditions for same trigger condition
(20* cycles until EFFECT is reached, takes 16 bytes of RAM)

LDA ZPPLANEBLOWMODE ; Disable effect if plane is exploding
BNE QUIT
LDA ZPTAILSLIDE ; Disable effect if plane is tail-sliding
BNE QUIT
LDA ZPTURNSTATUS ; Disable effect if plane is turning
BNE QUIT
LDA ZPRESPAWN ; Disable effect if plane is respawning
BNE QUIT
; EFFECT ...
...
...
QUIT RTS



The above assumes, in all instances of the variables being tested, that 01 = relevant condition is active and 00 = relevant condition is inactive (i.e. turned off).

Note that if any single one - or more - or all - of those conditions is / are active, the effect will not be performed; in other words, all of those conditions must = 00 for the effect to be executed.

You could, in plain English, say this:

"If any one or more of ZPPLANEBLOWMODE or ZPTAILSLIDE or ZPTURNSTATUS or ZPRESPAWN is turned on, then we do not perform the effect."

So we can convert that sentence into code thus:

Compact way to test multiple conditions for same trigger condition
(14* cycles until EFFECT is reached, takes 10 bytes of RAM)

LDA ZPPLANEBLOWMODE ; Disable effect if plane is exploding
ORA ZPTAILSLIDE ; Disable effect if plane is tail-sliding
ORA ZPTURNSTATUS ; Disable effect if plane is turning
ORA ZPRESPAWN ; Disable effect if plane is respawning
BNE QUIT
; EFFECT ...
...
...
QUIT RTS



By the same token, you could use AND everywhere instead of ORA and finish with a BEQ to the exit location, but the key aim is always the same: to save some needless branch-testing cycles and RAM by using ORA or AND in this fashion.

SCHEDULED AS AN EXCLUSIVE FEATURE ARTICLE IN THE JAN 2021 NEWSLETTER: FLD Three Ways - CPU + RAM efficient ways to perform FLD.

____

Similar post:

Illegal Opcode SAX/AXS: A Practical Use

Interested in coding games on the C64? Check out this book on Amazon (and yes, I get a tiny pittance if you buy via the banner below):



____


PS: Don't forget to check the home page regularly for more articles like this and visit the Everything64 Forum to comment further.

And of course, kindly follow me on Twitter and subscribe to my YouTube channel!

Help Make Parallaxian Happen

If you really want to help get Parallaxian finished, kindly support the continuation of its development via one of the options below, so that I can devote the necessary time to it; it's a truly huge project and although the toughest technical challenges have been completed, there remains a lot of hard work to get it over the finishing line.

Way #1: Start Your Amazon Sessions via Kodiak64.com (Costs You Nothing!)


This one should be the easiest because it's a painless and indirect way to help me for something you would be doing anyway, regardless of my request for help.

So how does it work?

Well, it makes no difference what you're buying on Amazon... whether it's a garden gnome for your dad, jewellery for your wife, the new C64 Maxi for yourself or an obscure first edition by an even more obscure 17th century Belgian poet for someone you very much dislike.

The point is, if you buy anything on Amazon, even your groceries, I will automatically receive a commission as long as your Amazon session begins as a click on an Amazon product banner on this website or just on any generic Amazon link on this website (such as those listed below):

amazon.co.uk

amazon.com

amazon.it

amazon.de

amazon.se


So, you would make your daily visit to Kodiak64.com to check out what's new and then, while you're here, enter Amazon via one of those links to order whatever you were planning on buying anyway, thus doing your bit to advance Parallaxian's development.

Simple!

Way #2: Purchase Merch from the Kodiak64 Shop


Hosted externally (for now) on Teespring, the Kodiak64 shop features limited edition C64-related merchandise, for which I have mostly set my margin at 15% of the retail price (to keep it as low as worthwhile).

6502 LOVE


I intend to change designs every month to keep things fresh, albeit with the core themes remaining Commodore 64 centric.

Way #3: PayPal Donation


Finally, at the highest rung of the altruism ladder among the 3 options, maybe you could consider a small, recurring monthly donation (and depending on your tax situation, you might even be able to designate it as a charitable donation rather than let the taxman have it).

And don't worry, you can cancel at any time... but in the meantime, it would be a welcome contribution, however petite.

Oh, and as a special thank you, all who do this will be credited in the game (unless you opt out of it if you have the same kind of incognito hermit tendencies I do).



Help Kodiak64 for FREE!

Click here to read how.

Share this page

Kodiak64 Newsletter

100% free, 100% spam-free!

(You can view a sample here).