It is currently Tue Oct 17, 2017 5:28 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 20 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: CC65 pause pattern
PostPosted: Mon Sep 19, 2016 12:37 pm 
Offline
User avatar

Joined: Sun Sep 26, 2010 10:29 pm
Posts: 35
thefox wrote:
-Basti- wrote:
Code:
static unsigned char input = pad_poll(0);
static unsigned char lf_input = pad_state(0);

This calls pad_poll/pad_state once during the initialization of the program, not what you want. (I can't even remember if this is valid in C, or only C++.)


Sorry my bad, I made a mistake when summarizing my problem. input and lf_input are written each frame through my input-routine.

I fooled around a bit more with my code and found out, that using function pad_trigger instead of pad_poll solves my problem without comparing any input of the last frame. :shock:

Could somebody explain the difference between function pad_trigger and pad_poll?


Top
 Profile  
 
 Post subject: Re: CC65 pause pattern
PostPosted: Mon Sep 19, 2016 12:42 pm 
Offline
User avatar

Joined: Sun Sep 26, 2010 10:29 pm
Posts: 35
While i am optimizing my input routine at the moment, I wonder if C`s switch-case statement is recommendable instead of a large if-statement cascade, when using CC65?


Top
 Profile  
 
 Post subject: Re: CC65 pause pattern
PostPosted: Mon Sep 19, 2016 1:16 pm 
Offline

Joined: Sun Apr 13, 2008 11:12 am
Posts: 6276
Location: Seattle
Yeah, switch is much better, because cc65 doesn't really do much optimization. It ends up producing a cmp #imm / jeq @label cascade instead of "calculate lvalue and rvalue and compare and then jump".

Switch also groups everything with the same MSB together, so it'll be better if it collides with C's type promotion.


Top
 Profile  
 
 Post subject: Re: CC65 pause pattern
PostPosted: Mon Sep 19, 2016 2:58 pm 
Offline

Joined: Sun Mar 27, 2016 7:56 pm
Posts: 137
-Basti- wrote:
Could somebody explain the difference between function pad_trigger and pad_poll?

Ah! It seems that neslib actually already does the method I described (though in a slightly more roundabout way). So, you don't need to calculate that yourself after all, just use pad_trigger's value, which is equivalent to pressed.

EDIT: It's worth noting that pad_trigger seems to call pad_poll for some reason, though. You should update the variables each frame like this to avoid polling multiple times in a frame, which could make you miss button presses:
Code:
pressed = pad_trigger(0);
pad = pad_state(0);


Top
 Profile  
 
 Post subject: Re: CC65 pause pattern
PostPosted: Mon Sep 26, 2016 6:02 am 
Offline

Joined: Mon May 27, 2013 9:40 am
Posts: 351
I use *only* pad_poll and Nicole's method and I can get both button presses which have just been performed during the current frame and button presses which were performed before. I find it more simple.

Code:
while (1) {
    pad_this_frame = pad0;
    pad0 = pad_poll (0);
    pad_this_frame = (pad_this_frame ^ pad0) & pad0;

    if (pad0 & PAD_B) {
        // PAD B was pressed sometime in the past and it's still down.
    }

    if (pad_this_frame & PAD_A) {
        // PAD A has been pressed *this* frame, and *not* before
    }
}


Seems to work fine.

_________________
http://www.mojontwins.com


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 20 posts ]  Go to page Previous  1, 2

All times are UTC - 7 hours


Who is online

Users browsing this forum: pinkpuff and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group