Jump to content
Random Terrain

Stupid question about CTRLPF and program speed

Recommended Posts

Since I can't figure out how to use XOR to flip sprite/playfield priority using the fire button with the batari Basic version of [url="http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#ctrlpf"]CTRLPF[/url], I had to use more code.

Here's comes the stupid question. Which bit of code should be faster:

[code]
BitOp_Flip_CTRLPF{2} = !BitOp_Flip_CTRLPF{2}

CTRLPF = $01

if BitOp_Flip_CTRLPF{2} then CTRLPF = $05
[/code]



[code]
BitOp_Flip_CTRLPF{2} = !BitOp_Flip_CTRLPF{2}

if !BitOp_Flip_CTRLPF{2} then CTRLPF = $01

if BitOp_Flip_CTRLPF{2} then CTRLPF = $05
[/code]


My guess is the first one, but I don't know if an if-then is faster than "CTRLPF = $01".

Or maybe there is a faster, better way than either one of those, such as getting XOR to work with the bB version of CTRLPF. Edited by Random Terrain

Share this post


Link to post
Share on other sites
Don't have the knowledge for reply which is the fastest but what about
[code]
BitOp_Flip_CTRLPF{2} = !BitOp_Flip_CTRLPF{2}

if BitOp_Flip_CTRLPF{2} then CTRLPF = $05 else CTRLPF = $01

[/code]

Share this post


Link to post
Share on other sites
Rather than count cycles, I tested all of these in my [URL=http://www.atariage.com/forums/topic/146335-cycles-used-by-bb-operations/page__view__findpost__p__1951876]cycle tester[/URL]. I knew the answer to RT's routines without it, but I wasn't sure how abaudrand's answer would place.

RT, your first one is faster on average than the second.

abaudrand, yours is slightly faster on average than RT's first one.

RT, your thought about using XOR is good, but you can't do something like "CTRLPF=(CTRLPF^4)", since CTRLPF is a write-only register.

Here's one that's faster than the others, and still uses only bit 2 of BitOp_Flip_CTRLPF...

[code]
BitOp_Flip_CTRLPF=BitOp_Flip_CTRLPF^4
CTRLPF=(BitOp_Flip_CTRLPF&4)+1
[/code]

The first line inverts BitOp_Flip_CTRLPF{2} like the originals, but produces more compact assembly.
The second line assigns either 4+1 or 0+1 to CTRLPF, depending on the value in BitOp_Flip_CTRLPF{2}.

Share this post


Link to post
Share on other sites
[quote name='RevEng' timestamp='1306678038' post='2289914']Here's one that's faster than the others, and still uses only bit 2 of BitOp_Flip_CTRLPF...

[code]
BitOp_Flip_CTRLPF=BitOp_Flip_CTRLPF^4

CTRLPF=(BitOp_Flip_CTRLPF&4)+1
[/code]

The first line inverts BitOp_Flip_CTRLPF{2} like the originals, but produces more compact assembly.

The second line assigns either 4+1 or 0+1 to CTRLPF, depending on the value in BitOp_Flip_CTRLPF{2}.
[/quote]
Thanks. So on the bB page, I can say that users can use a{2} = !a{2} or a = a ^ %00000100 or a = a ^ 4.

Examples:

[code]
a{0} = !a{0} or  a = a ^ %00000001 or a = a ^ 1

a{1} = !a{1}   or   a = a ^ %00000010 or a = a ^ 2

a{2} = !a{2}   or   a = a ^ %00000100 or a = a ^ 4

a{3} = !a{3}   or   a = a ^ %00001000 or a = a ^ 8

a{4} = !a{4}   or   a = a ^ %00010000 or a = a ^ 16

a{5} = !a{5}   or   a = a ^ %00100000 or a = a ^ 32

a{6} = !a{6}   or   a = a ^ %01000000 or a = a ^ 64

a{7} = !a{7}   or   a = a ^ %10000000 or a = a ^ 128
[/code]
If I'm not mistaken, I can tell them that the last two produce more compact assembly. Is that correct?




[quote name='Omegamatrix' timestamp='1306678786' post='2289917']
If you want to try some inline assembly then:


[code] asm
lda #1
bit INPT4
bpl .fireButtonPressed
lda #5
.fireButtonPressed:
sta CTRLPF
end[/code]
[/quote]
Thanks. I'm doing this for an example program, so I better stick with something that resembles bB code for now. Edited by Random Terrain

Share this post


Link to post
Share on other sites
[quote name='Random Terrain' timestamp='1306697573' post='2290113']
Thanks. So on the bB page, I can say that users can use a{2} = !a{2} or a = a ^ %00000100 or a = a ^ 4.[/quote]
Yup

[quote name='Random Terrain' timestamp='1306697573' post='2290113']
If I'm not mistaken, I can tell them that the last two produce more compact assembly. Is that correct?[/quote]
That's correct. I confirmed it by comparing the generated asm code for both methods

Share this post


Link to post
Share on other sites
[quote name='RevEng' timestamp='1306704161' post='2290204']
[quote name='Random Terrain' timestamp='1306697573' post='2290113']
Thanks. So on the bB page, I can say that users can use a{2} = !a{2} or a = a ^ %00000100 or a = a ^ 4.[/quote]
Yup

[quote name='Random Terrain' timestamp='1306697573' post='2290113']
If I'm not mistaken, I can tell them that the last two produce more compact assembly. Is that correct?[/quote]
That's correct. I confirmed it by comparing the generated asm code for both methods
[/quote]
Thanks. I'll go update the page right now so I won't forget.

Share this post


Link to post
Share on other sites
after recompiling my program, the RevEng method saved me [b]26 bytes of rom [/b]!!! I couldn't imagine it could spare so much just with a mathematical operation.
Before this post, I've put this into the vblank
[code]
vblank
if a{4} then a{4}=0:return
if !a{4} then a{4}=1
return
[/code]

I use this code in the vblank to create an artificial flickering if i want an object to be displayed on odd frame but not on even frame.
I also use this method to alternate objects colors each frame to give the illusion of another color.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...