It is currently Sat Nov 18, 2017 8:20 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 18 posts ]  Go to page Previous  1, 2
Author Message
PostPosted: Thu May 22, 2014 3:18 am 
Offline
User avatar

Joined: Mon Nov 06, 2006 9:34 am
Posts: 164
Location: Potsdam, Germany
Movax12 wrote:
miau, I took a look at your source for any inspiration. I was wondering if you would be willing to explain your NMI routine's cmd priority/task queue system. What does it allow you to do? And/or, if you would be willing to explain the source with a bit more detail I would appreciate it. I have something I think is similar and would like to compare.

Some parts of the vblank code are from when I originally started NES development so it's a bit awkward, but here is how it should work:

- have a stack with addresses of functions to jsr to during vblank ("vblank commands")
- push a command with Vblank.cmd.exec
- the stack pointer does not advance automatically, the same function gets called once everytime the ppu enters vblank until it calls Vblank.cmd.end
- Vblank.cmd.replace changes the address at the top of the stack, making the supplied address the next command to be executed and discarding the current one

...except that's not quite how it works?! There's a high priority version of Vblank.cmd.exec and I don't recall why it is even needed with the stack-based approach. At this point, I'd rather rewrite the whole thing properly than spend any more time looking at it, heh.
Also, I probably should have used a queue instead of a stack, that would have been more logical and intuitive. Then again, queues can be a bit fiddly to implement and a priority system could be costly cpu-wise.

In any case, here's a usage example for the current Vblank.cmd interface:
Code:
.proc letsDoSomethingOverMultipleVblanks ;can be called outside of vblank/NMI
    Vblank.cmd.exec firstVblank
    rts
firstVblank:
    ;do stuff
    Vblank.cmd.replace secondVblank
    rts
secondVblank:
    ;do other stuff
    Vblank.cmd.replace thirdVblank
    rts
thirdVblank:
    ;do other stuff
    jsr Vblank.cmd.end
    rts
.endproc

And another one:
Code:
.proc letsGonnaDoSomethingOverMultipleVblanksAgain ;can be called outside of vblank/NMI
    .bss
    counter: .res 1
    .code
    lda #32
    sta counter
    Vblank.cmd.exec vblank
    rts
vblank:
    ;do stuff once per vblank for 32 vblanks
    ;...like redrawing one row of the nametable per vblank
    dec counter
    bne @doNotEndYet
        jsr Vblank.cmd.end
    @doNotEndYet:
    rts
.endproc


How are you handling Vblank/NMI tasks?
If there's anything else you'd like to know, please point me to it.


Top
 Profile  
 
PostPosted: Thu May 22, 2014 9:06 am 
Offline
User avatar

Joined: Sun Jan 02, 2011 11:50 am
Posts: 522
There are some similarities to how I do it, and you have given me some things to think about.
For me, I have a list of addresses to be accessed in NMI. To try to speed things up I store these addresses at $0100 and switch the stack pointer to point to these addresses when running these commands. Every RTS executes the next routine in the list (fast!). This makes it fairly quick to access anything that wants to run in vblank. The last address in the stack always must point to returnFromChain.

The parameter whichVectorList exists because I have three lists of routines to execute. (High priority PPU update routines, call always routines (even in missed frame), and routines that can be called at the end of NMI that don't need vblank time.)

Code:
privatefunc startChain, {whichVectorList a}
   
    ; save normal stack:
    tsx
    stx realStack
    ; transfer and save new temp stack:
    _ x := whichVectorList
    stx currentNMIstack
    txs
    rts ; load the CPU program counter with the first hooked vector.
endfunc

privatefunc returnFromChain
    ldx realStack
    txs
    return currentNMIstack
endfunc


Top
 Profile  
 
PostPosted: Sat May 24, 2014 3:14 am 
Offline
User avatar

Joined: Mon Nov 06, 2006 9:34 am
Posts: 164
Location: Potsdam, Germany
Well, that gives me things to think about.

Having multiple lists and using actual stack addresses is neat, I think I will adapt that for other projects.


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

All times are UTC - 7 hours


Who is online

Users browsing this forum: Punch 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