It is currently Sat Oct 21, 2017 5:48 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Sun Feb 24, 2008 11:15 pm 
Offline
User avatar

Joined: Mon Sep 27, 2004 8:33 am
Posts: 3715
Location: Central Texas, USA
I wrote a clean example of how to queue controller button/D-pad presses inside an NMI, then read them from the main program outside the NMI. This allows the user to input lots of presses without the game losing any. The size of the queue can be adjusted to up to 128 presses, plenty for most programs. The example prints button presses, then waits half a second before checking the queue again, allowing you to easily queue up a bunch of presses, then watch them properly print out in sequence. Code assembles with ca65.

controller_queue.zip

These are the core routines that implement the queue:
Code:
; Adds byte A to queue
queue_press:
    ldx write_pos
    sta queue,x
    dex
    bpl :+
    ldx #queue_size
:   stx write_pos

    cpx read_pos
    beq queue_overflowed
   
    rts

; Removes byte from queue into A, or 0 if queue is empty
read_queue:
    lda #0
    ldx read_pos
    cpx write_pos
    beq @empty
   
    lda queue,x
    dex
    bpl :+
    ldx #queue_size
:   stx read_pos

@empty:
    cmp #0
    rts


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

All times are UTC - 7 hours


Who is online

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