Greetings,
I spent a couple of enjoyable hours reading through some of this boards threads last night. This is my first post.
I have recently returned to 65xx assembly after a very long hiatus (my last time was in the early 80s).
For the heck of it (and to keep my mind sharp), my first foray back is to cobble together an Atari 2600 4k game binary.
As I experiment and learn the 2600, I find myself wishing I had a set of fast constant-time 6507 flag to mask conversion snippets.
Before I wrack my brain reinventing the wheel, I thought I'd check if anyone on this board knows of an existing set.
What I'm looking for is a set of "bithacks" for converting processor flag states (or boolean combination of processor flag states) to canonical 8-bit masks in A, in the least number of cycles but in constant-time.
By canonical mask I mean -1/0 (all bits on or all bits off), similar to Forth flags.
By constant-time I mean either
branchless or using
"ballasted" branches, so that all conditional paths through the code end up taking exactly the same number of cycles.
I'm perfectly fine with using undocumented 6507 opcodes, as they seem to be commonly used in 2600 homebrews.
Here are a couple of examples (I have no idea if these are optimal or not).
~C -> -1/0:
Code:
a900 lda #$00 (2)
e900 sbc #$00 (2)
C -> -1/0:
Code:
a900 lda #$00 (2)
e900 sbc #$00 (2)
49ff eor #$ff (2)
... and so on and so forth, including useful boolean combinations of N, V, C, Z.
Cheers,
Mark