It is currently Tue Jul 17, 2018 4:59 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Buttons buttons buttons
PostPosted: Mon May 01, 2006 6:16 pm 
Offline
User avatar

Joined: Tue Jan 17, 2006 10:39 am
Posts: 143
Location: North Carolina
Hello All,


I need some help/advice with the A & B buttons. I've setup my A & B buttons so that they allow for one action per press (no "rapid fire" action). However, when implemented this now the actions assigned to the buttons flash really quick. So my question is how do I get the actions "take some time" to execute so that the user actually sees whats happening when the A or B button is pressed. Any advice/hints/pointers would greatly be appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 01, 2006 6:52 pm 
Offline
User avatar

Joined: Sun Jun 05, 2005 2:04 pm
Posts: 2149
Location: Minneapolis, Minnesota, United States
Okay, I sort of understand what you are saying, like is it like a sprite changing? Like a kick move? Or something along the lines of that? Well, what you'd want to do is probably set up a counter, so have it like this:

apress:
lda counter
beq +
dec counter
.... blah code....
+
rts


The Counter would have a value of how many frames you want to wait. If you are doing this in vblank/nmi. I don't know how you could not, but... At the end of your joypad reading routine, restore the value of the counter. So if you don't get this routine, it waits a certain amount of frames, and when it's done, it just goes to +, which just returns. I'm sure you got it, right?


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 01, 2006 9:20 pm 
Offline
User avatar

Joined: Mon Sep 20, 2004 4:07 pm
Posts: 34
Location: South Dakota
I usually keep two variables for joypad input, one for the current frame, and one for the previous frame. Then, when I want to check for a button press (as opposed to a held button), I just check if(current && !previous)

Code:
;check if B button has just been pressed
    lda joypad_cur
    and #BUTTON_B
    beq notpressed

    lda joypad_prev
    and #BUTTON_B
    bne notpressed

    (code for when the button is pressed)

notpressed:


When you have both the current and previous joypad states, you can compare for:
- button is pressed and already was (held)
- button is pressed and wasn't before (just pressed)
- button is up and already was (nothing)
- button is up and was pressed before (just released)

Is that what you needed?

_________________
- abonetochew


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 01, 2006 10:05 pm 
Offline
User avatar

Joined: Sun Sep 19, 2004 10:59 pm
Posts: 1418
One slightly simpler way of doing that:
Code:
;check if B button has just been pressed
    lda joypad_cur
    eor joypad_prev
    and joypad_cur
    and #BUTTON_B
    beq notpressed

    (code for when the button is pressed)

notpressed:


An even further simplification is to perform the "(cur XOR prev) AND cur" calculation immediately after reading the button states and caching it - in fact, a vast majority of licensed NES games do exactly this.

_________________
Quietust, QMT Productions
P.S. If you don't get this note, let me know and I'll write you another.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 03, 2006 8:07 pm 
Offline
User avatar

Joined: Tue Jan 17, 2006 10:39 am
Posts: 143
Location: North Carolina
Hi,

Thanks for your responses. I'm not sure I explained my issue very clearly (just want to make sure so I'm not putting anyone on the wrong path). I had used the key detection thread (http://nesdev.com/bbs/viewtopic.php?t=67) to setup my A & B buttons to use the one press "feature" (abonetochew & quietust .. I *think* this is what you were suggesting?). My problem comes in after that. Once you press the button my sprite displays so quickly that its basically a flicker on the screen. Just barely noticeable. I think this is what celius was talking about (waiting X amount of frames). However, I tried his method and it didn't work out for me...
Maybe its the way I'm doing things (keep in mind I'm still pretty new at this (-; )


Code:
; for A button

 lda $4016 
 sta A.CurStat

 lda A.OldStat   
 eor #$ff   
 and A.CurStat
 sta A.NewStat
 lda A.CurStat
 sta A.OldStat

 lda A.NewStat
 beq not_pushed

; just changing the sprite tiles to reflect the action
 lda #$71                               
 sta SPR0.T   
 lda #$7B
 sta SPR1.T
 lda #$76
 sta SPR2.T
 lda #$77
 sta SPR3.T
 lda #$7A
 sta SPR4.T

.....

not_pushed:


BTW, if there is a better way than what I'm doing above then please point me in the right direction :)

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 03, 2006 8:20 pm 
Offline
User avatar

Joined: Sun Jun 05, 2005 2:04 pm
Posts: 2149
Location: Minneapolis, Minnesota, United States
I honestly am horrible at joypad routines. This is how I do mine:
Code:
joypad:
   ldx #$01
   stx $4016
   dex
   stx $4016

   lda $4016
   and #1
   bne akey
   lda $4016
   and #1
   bne bkey
   lda $4016
   and #1
   bne sekey
   lda $4016
   and #1
   bne slkey
   lda $4016
   and #1
   bne upkey
   ....
   rts


I know you can do it alot simpler, I've just never cared enough to do it differently. This actually works fine, but you can save much space with other methods. It's how I learned to do it, so I just do it that way.

But about your issue, I don't know how else you could do this besides counting frames. This is what I'd do:

Code:
nmi:
     lda #3
     sta $4014
     jsr joypad
     lda $63     ;just some random variable
     bmi showkick
     rti

showkick:
     dec $74    ;another random variable as a counter
     bne +
     ;restore sprites
     lda #$10   ;say you want to wait #$10 frames each kick
     sta $74
     lda #$00
     sta $63
+
      rts
joypad:
.....
akey:
     lda $63
     bmi +
    dec $63
     ;store sprites
+
    rts


I don't know, but that's what I'd probably do. If you want it to be shown for a certain amount of frames, then you have to wait that many frames, there's no way around it. Sorry, but I don't know what else to say if that won't work for you.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 1 guest


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