Jump to content
IGNORED

What should I use for small example programs? SWCHA or if-thens?


Random Terrain

  

5 members have voted

  1. 1. What should I use for most example programs?

    • If-thens using joy0up, joy0down, joy0left and joy0right?
      4
    • Advanced joystick reading using SWCHA?
      1

  • Please sign in to vote in this poll.

Recommended Posts

I'm going to start making little example programs for the bB page pretty soon. Since just about every program will use a joystick, do I encourage new users to use advanced joystick reading with SWCHA since it can even handle broken joysticks or do I use If-thens with joy0up, joy0down, joy0left and joy0right?

 

I'll go with the one that gets the most votes unless somebody posts a reason that is so convincing that it overrides the votes. :D

Edited by Random Terrain
Link to comment
Share on other sites

I'm going to start making little example programs for the bB page pretty soon. Since just about every program will use a joystick, do I encourage new users to use advanced joystick reading with SWCHA since it can even handle broken joysticks or do I use If-thens with joy0up, joy0down, joy0left and joy0right?

 

I'll go with the one that gets the most votes unless somebody posts a reason that is so convincing that it overrides the votes. :D

 

I wouldn't mind seeing the SWCHA one just because it could require 5 if_thens (the directions plus the button) to check one joystick otherwise. Also, you could check both joysticks using the same logic.

Edited by Cliff Friedel
Link to comment
Share on other sites

Disclaimer: I have not explored the SWCHA method yet.

 

That being said what makes brain sense is joy0left. Just by looking at the command you can tell it has something to do with the joystick and moving it left. SWCHA is an abstract concept that newbies shouldn't be subjected to.

 

The tender, fragile newb should be eased into SWCHA by having seperate, moderate level tutorials and examples. When yer just figuring things out joy0whatever is a very good method.

 

Any command like SWCHA that needs its own highly descriptive tutorial/example may not be appropriate for fresh fish.

Edited by theloon
Link to comment
Share on other sites

Disclaimer: I have not explored the SWCHA method yet.

 

That being said what makes brain sense is joy0left. Just by looking at the command you can tell it has something to do with the joystick and moving it left. SWCHA is an abstract concept that newbies shouldn't be subjected to.

 

The tender, fragile newb should be eased into SWCHA by having seperate, moderate level tutorials and examples. When yer just figuring things out joy0whatever is a very good method.

 

Any command like SWCHA that needs its own highly descriptive tutorial/example may not be appropriate for fresh fish.

That's pretty convincing. Only thing I can say against it is that new users don't need to know how it works to use it. Kind of like electricity and a light switch.

Link to comment
Share on other sites

Disclaimer: I have not explored the SWCHA method yet.

 

That being said what makes brain sense is joy0left. Just by looking at the command you can tell it has something to do with the joystick and moving it left. SWCHA is an abstract concept that newbies shouldn't be subjected to.

 

The tender, fragile newb should be eased into SWCHA by having seperate, moderate level tutorials and examples. When yer just figuring things out joy0whatever is a very good method.

 

Any command like SWCHA that needs its own highly descriptive tutorial/example may not be appropriate for fresh fish.

That's pretty convincing. Only thing I can say against it is that new users don't need to know how it works to use it. Kind of like electricity and a light switch.

 

That's true to an extent, they can't modify it to their liking if they don't know what any of it means.

I say if-thens are a lot easier to understand for newbies to bB. You should do normal if then ones for people trying to learn, then explain SWCHA to the more advanced users.

Link to comment
Share on other sites

The "long list of if-thens" is almost always more efficient in terms of both cycles and space than SWCHA methods with on-goto/gosubs.

 

However, one advantage to using SWCHA is when you need to read a particular joystick direction more than once per frame. If you need to do that, first assign SWCHA to a variable once per frame, otherwise weird bugs may occur on real hardware - emulators might only register joystick movement once per frame while hardware can do it continuously.

 

Even if you do assign SWCHA to a variable, it's still worse to use on-goto/gosub to check the variable - just check the individual bits in if-thens.

Link to comment
Share on other sites

The "long list of if-thens" is almost always more efficient in terms of both cycles and space than SWCHA methods with on-goto/gosubs.

So SWCHA isn't really faster? I thought it used fewer cycles? I thought it was faster (at least using goto) and had the benefit of ignoring invalid combinations?

Link to comment
Share on other sites

The "long list of if-thens" is almost always more efficient in terms of both cycles and space than SWCHA methods with on-goto/gosubs.

So SWCHA isn't really faster? I thought it used fewer cycles? I thought it was faster (at least using goto) and had the benefit of ignoring invalid combinations?

We had a discussion about this once. Compare the basic routine:

 if joy0left then player0x=player0x-1
 if joy0right then player0x=player0x+1
 if joy0up then player0y=player0y-1
 if joy0down then player0y=player0y+1

This should use only 28 bytes, and invalid combinations like left/right and up/down together will cancel each other out.

 

The on-goto option might start like this:

 myJoystick=SWCHA/16
 on myJoystick goto j1 j2 j3 j4 j5 j6 j7 j8 j9 j10 j11 j12 j13 j14 j15 j16
j1 ....

Well, I don't want to code the whole thing, but just the on..goto alone, without even considering the 16 routines j1-j16 you'd need, already uses more than the 28 bytes above, and will certainly use more cycles.

Link to comment
Share on other sites

The "long list of if-thens" is almost always more efficient in terms of both cycles and space than SWCHA methods with on-goto/gosubs.

So SWCHA isn't really faster? I thought it used fewer cycles? I thought it was faster (at least using goto) and had the benefit of ignoring invalid combinations?

We had a discussion about this once. Compare the basic routine:

 if joy0left then player0x=player0x-1
 if joy0right then player0x=player0x+1
 if joy0up then player0y=player0y-1
 if joy0down then player0y=player0y+1

This should use only 28 bytes, and invalid combinations like left/right and up/down together will cancel each other out.

 

The on-goto option might start like this:

 myJoystick=SWCHA/16
 on myJoystick goto j1 j2 j3 j4 j5 j6 j7 j8 j9 j10 j11 j12 j13 j14 j15 j16
j1 ....

Well, I don't want to code the whole thing, but just the on..goto alone, without even considering the 16 routines j1-j16 you'd need, already uses more than the 28 bytes above, and will certainly use more cycles.

Thanks, so if you had a different image or animation for 16 directions, it would still save bytes and cycles to use if-thens?

 

Should I remove the Robert M SWCHA section from the bB page if it really isn't faster/better?

Link to comment
Share on other sites

The "long list of if-thens" is almost always more efficient in terms of both cycles and space than SWCHA methods with on-goto/gosubs.

So SWCHA isn't really faster? I thought it used fewer cycles? I thought it was faster (at least using goto) and had the benefit of ignoring invalid combinations?

We had a discussion about this once. Compare the basic routine:

 if joy0left then player0x=player0x-1
 if joy0right then player0x=player0x+1
 if joy0up then player0y=player0y-1
 if joy0down then player0y=player0y+1

This should use only 28 bytes, and invalid combinations like left/right and up/down together will cancel each other out.

 

The on-goto option might start like this:

 myJoystick=SWCHA/16
 on myJoystick goto j1 j2 j3 j4 j5 j6 j7 j8 j9 j10 j11 j12 j13 j14 j15 j16
j1 ....

Well, I don't want to code the whole thing, but just the on..goto alone, without even considering the 16 routines j1-j16 you'd need, already uses more than the 28 bytes above, and will certainly use more cycles.

Thanks, so if you had a different image or animation for 16 directions, it would still save bytes and cycles to use if-thens?

 

Should I remove the Robert M SWCHA section from the bB page if it really isn't faster/better?

There is a point at which the on..goto will become more efficient. 16 frames of graphics (where you'd have 16 if-thens) will likely be one of them.

 

As for the Robert M SWCHA thing, I wouldn't remove it, as it may be better, for example, you are doing something different for up-left than for up and left individually, and the part about passing through walls may be true as well (though that may not be a problem anyway in a properly-coded game with a list of if-thens.) I would add that the SWCHA method often is less efficient in terms of cycles and space than if-thens because that comes as a surprise to many.

Link to comment
Share on other sites

Thanks. I'll update that section now.

Here's my first try at updating that section. The only thing that has changed so far is adding the first paragraph:

 

http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#swcha

 

When I read my adapted sentences, it sounds a little weird, but maybe I can reword it later to sound better on a day when my brain is working better.

Link to comment
Share on other sites

Thanks. I'll update that section now.

Here's my first try at updating that section. The only thing that has changed so far is adding the first paragraph:

 

http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#swcha

 

When I read my adapted sentences, it sounds a little weird, but maybe I can reword it later to sound better on a day when my brain is working better.

I think the first paragraph should be third, just before the example, and changed a bit. My comment about on...goto was more a general statement rather than relating to SWCHA specifically, but in the case where you have a different sprite for each direction, on...goto may be better. Maybe this makes more sense:
It may be surprising, but the SWCHA method is often less efficient in terms of cycles and space than if-thens. There is a point at which the on…goto with SWCHA will become more efficient. For example, if you are doing something different for up-left than for up and left individually, such as a diagonal sprite, SWCHA may be the better choice.
Link to comment
Share on other sites

Even though I kind of like the SWCHA method, I voted for the "if-then" statements.

 

By the way, on your page it says "The position of both joysticks is stored in a read-only memory register of the TIA labeled SWCHA." SWCHA is a register of the RIOT chip, not the TIA chip, and it can be configured for either input (read) or output (write). So you might want to change that to "The position of both joysticks is stored in an IO memory register of the RIOT labeled SWCHA."

 

Michael

Link to comment
Share on other sites

Even though I kind of like the SWCHA method, I voted for the "if-then" statements.

 

By the way, on your page it says "The position of both joysticks is stored in a read-only memory register of the TIA labeled SWCHA." SWCHA is a register of the RIOT chip, not the TIA chip, and it can be configured for either input (read) or output (write). So you might want to change that to "The position of both joysticks is stored in an IO memory register of the RIOT labeled SWCHA."

Thanks. I'll update the page and the comments in the two example programs.

Link to comment
Share on other sites

I thought I saw a comment somewhere that said SWCHA is more reliable for reading "flaky" joysticks. Is this just my neurons firing crooked again?

I don't know, but it makes sense. The thing I like about the SWCHA method is that it's so much easier to handle diagonals. Sure, it uses more overhead-- but ROM is cheap. :)

 

Michael

Link to comment
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.
Note: Your post will require moderator approval before it will be visible.

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...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...