Jump to content

Photo

Button check - am I doing this the hard way?


4 replies to this topic

#1 Karl G OFFLINE  

Karl G

    Dragonstomper

  • 734 posts

Posted Wed Jan 2, 2019 12:27 PM

I have some code to check for the fire button, set a bit as a button restrainer if fire is hit and play a sound, or clear the bit if the fire button is not pressed.  It works fine, but it seems like an awful lot of code to me.  Is there a more optimal way to accomplish this than what I am doing here?  Here are the relevant bits of code:

Boolean         ds 1
FireHitBit0 = Boolean
bit0 = %00000001
bit0mask = %11111110

And...

    bit INPT4
    bmi ____no_button_press
    lda FireHitBit0
    and #bit0
    bne ____end_button_check
    lda FireHitBit0
    ora #bit0
    sta FireHitBit0
    lda #31
    sta AUDF0
    lda #4
    sta AUDC0
    lda #$F
    sta AUDV0
    jmp ____end_button_check
____no_button_press
    lda FireHitBit0
    and #bit0mask
    sta FireHitBit0
____end_button_check

Thanks in advance for any input.



#2 DEBRO OFFLINE  

DEBRO

    Stargunner

  • 1,955 posts
  • Location:Atlanta, GA

Posted Wed Jan 2, 2019 9:05 PM

Hi there,

 

Do you need D0 for this check or can you use D7? Are the other registers free for use too? If you can use D7 then it could be a simple compare as such...

   lda INPT4                        ; read left port action button
   and #%10000000                   ; safe to avoid any reads from D6 - D0
   bmi .actionButtonNotPressed      ; branch if action button not pressed
   cmp actionButtonDebounce
   beq .endActionButtonCheck        ; branch if action button held previously
   ldx #31
   stx AUDF0
   stx AUDV0                        ; only lower nybble used for volume
   ldx #4
   stx AUDC0
.actionButtonNotPressed
   sta actionButtonDebounce         ; set debounce value for next frame compare
.endActionButtonCheck

Edited by DEBRO, Wed Jan 2, 2019 9:12 PM.


#3 Karl G OFFLINE  

Karl G

    Dragonstomper

  • Topic Starter
  • 734 posts

Posted Thu Jan 3, 2019 8:44 AM

Thanks!  This is the kind of thing I was looking for.  Presumably I need to do an ORA actionButtonDebounce before the STA line to avoid wiping out the other bit values in the byte, though?

 

Edit: it looks like the "cmp actionButtonDebounce" is also assuming that bit 7 is the only bit used in the actionButtonDebounce byte?



#4 DEBRO OFFLINE  

DEBRO

    Stargunner

  • 1,955 posts
  • Location:Atlanta, GA

Posted Thu Jan 3, 2019 11:08 AM

Hi there

 

Thanks!  This is the kind of thing I was looking for.  Presumably I need to do an ORA actionButtonDebounce before the STA line to avoid wiping out the other bit values in the byte, though?

 

Edit: it looks like the "cmp actionButtonDebounce" is also assuming that bit 7 is the only bit used in the actionButtonDebounce byte?

 

There should be no need to ORA before setting the value. This is because the value is set from the read of INPT4 and should represent the state when comparing in the next frame.

 

You are correct that I'm assuming the other bits of actionButtonDebounce are not used. If you need to use those bits for other needs; you would need to isolate them before the compare.



#5 bogax OFFLINE  

bogax

    Dragonstomper

  • 787 posts

Posted Mon Jan 7, 2019 10:47 AM

here's one

 

 
    ;  a = accumulator  C = carry flag, I = INPT4,  f = your flags,
    ;  f7 = bit 7 of flags, the debounce (restrainer) bit (sort of, maybe you'd say that was C)
    ;  f7 = previous I7  we want to check for !I7 & f7 = 1
 
    lda flags
    and #$80
    clc
    sbc INPT4     ;   C = !I7 & f7,  a7 = !I7 ^ f7
    and #$80
    eor flags     ;  a7 = !I7
    eor #$80
    sta flags
    bcc skip_audio
    

Edited by bogax, Mon Jan 7, 2019 10:49 AM.





0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users