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

PayPal Donation


I would ask you if 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).



Share this page

Kodiak64 Newsletter

100% free, 100% spam-free!

(You can view a sample here).