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: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.
- 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: Select all
.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
Code: Select all
.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
If there's anything else you'd like to know, please point me to it.