It is currently Tue Mar 26, 2019 7:08 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Fri Nov 26, 2004 9:34 pm 
Offline

Joined: Wed Nov 17, 2004 1:31 am
Posts: 8
Location: Hong Kong
Hello,

I would like to ask if I don't want the subroutine to be run continuously when the user didn't release the key-pad button, what should I do? I have several ideas, which one is better or else you have any better solution / method for me?

Idea (1):

Code:
main_loop:
  key_detection:
    (save the pressed key pattern)
  key_compare:
    (compare the pressed key with the saved key pattern, if they are the same, skip key_detection in the comming looping, otherwise, allows key_detection)



Idea (2):

Code:
main_loop:
  key_detection:
  wait_key_release:
    (do the key_detection until all the key are released)



Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 26, 2004 9:50 pm 
Online
Site Admin
User avatar

Joined: Mon Sep 20, 2004 6:04 am
Posts: 3663
Location: Indianapolis
I like idea 1 a lot better, and that's how I've always done it. Waiting for the key to be released would increase the response times (which might already be behind by about a frame anyways, not that anyone would notice, heh)

Feel free to use this code, if you like using macros. I find it makes the source code much cleaner-looking and quicker to type. (it's made for CA65)

Code:
;---------------------------------------------------------
;---------------------------------------------------------
;       Check Controller
;       (macro: controller button,branch,(optional)branch
;---------------------------------------------------------
.macro  controller button,not_pressed,button_held
        .ifblank button_held
                lda joy1
                and #button
                beq not_pressed
        .endif
        .ifnblank button_held
                lda joy1
                and #button
                beq not_pressed
                and joy1old
                bne button_held
        .endif
.endmacro


I define a bit for each button, then use it like:

controller a_button,not_a,not_a ; branch if A is not pressed or held

controller a_button,not_a,a_held ; seperate branches for not pressed and for held

controller a_button,not_a ; branch if not pressed


Last edited by Memblers on Fri Nov 26, 2004 9:55 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 26, 2004 9:53 pm 
Online
Site Admin
User avatar

Joined: Mon Sep 20, 2004 6:04 am
Posts: 3663
Location: Indianapolis
BTW, in there joy1 and joy1old are RAM bytes where I stored the controller data. I do the actual controller reading in the NMI.


Top
 Profile  
 
 Post subject: Thanks very much
PostPosted: Fri Nov 26, 2004 10:09 pm 
Offline

Joined: Wed Nov 17, 2004 1:31 am
Posts: 8
Location: Hong Kong
I understand, and I have implemented the function with idea (1). However, I haven't tried the code as you provided at the moment. I will try afterward.

However, for the code I have done. I found one problem. If I didn't release the button, the subroutine does not run. It meets my requirement. However, once I release the button, the subroutine will run which I didn't expect to be occurred.
i.e. it is the problem of handling the positive-edge detection and negetive-edge detection. Can I do it in software?

Regards,
Sunny


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 26, 2004 10:16 pm 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 21217
Location: NE Indiana, USA (NTSC)
Yes you can do edge detection in software. Super Mario Bros. does it.

Read the controller data into joy1 as you normally would, then do
Code:
  lda joy1old
  eor #$ff
  and joy1
  sta joy1new
  lda joy1
  sta joy1old

before reading commands from joy1new. A somewhat longer subroutine can be used to handle autorepeat like on a PC keyboard.


Top
 Profile  
 
 Post subject: I want to know more...
PostPosted: Sun Nov 28, 2004 6:39 pm 
Offline

Joined: Wed Nov 17, 2004 1:31 am
Posts: 8
Location: Hong Kong
tepples wrote:
Read the controller data into joy1 as you normally would, then do
Code:
  lda joy1old
  eor #$ff
  and joy1
  sta joy1new
  lda joy1
  sta joy1old

before reading commands from joy1new. A somewhat longer subroutine can be used to handle autorepeat like on a PC keyboard.


I do want to know what is the use of the code? Should I use joy1, joy1new or joy1old for determination?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 28, 2004 8:14 pm 
Online
Site Admin
User avatar

Joined: Mon Sep 20, 2004 6:04 am
Posts: 3663
Location: Indianapolis
In that code, joy1new would be for checking for a new key press.

The EOR #$FF flips the old state (so not pressed = 1), ANDs it with the current state, so only the newly pressed button's bits are set.


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

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 0 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