alekmaul / pvsneslib

PVSnesLib : A small, open and free development kit for the Nintendo SNES
MIT License
860 stars 75 forks source link

[Feature] spcPause(), spcResume(), spcGetStartPos() #213

Open malayli opened 1 year ago

malayli commented 1 year ago

Feature request

Creating these 2 functions will allow a better control on a music IT file:

Advanced Feature request

Creating this function will help developers to simply get the current startPos value:

So they can pass it to spcPlay(startPos) after stopping a music with spcStop().

Notes

These are the explanation of KungFuFurby that might help you to implement this feature:

startpos refers to an orderlist ID. You can retrieve the orderlist ID directly from $2143/$F7... but of course, the ASM I ported over way back when didn't include this function for whatever reason on the 65816 side.

Copy over this snippet of code, giving it a different name: https://github.com/alekmaul/pvsneslib/blob/862adbf4831cd6033f01433d01f0da4e405d864f/pvsneslib/source/snesmodwla.asm#L794-L805

Replace all instances of REG_APUIO2 with REG_APUIO3. I'd say put your modified function somewhere in https://github.com/alekmaul/pvsneslib/blob/master/pvsneslib/include/snes/sound.h ...but I don't see a good return type example from here. I'm thinking a u8

KungFuFurby commented 1 year ago

A little bit of fine print: Pause and resume won't restart exactly from where you left off in the song: this is because the orderlist position is used. There may be some carryover problems because the song is reinitialized anyways the way things currently are handled, meaning we still have some resetting going on... I may want to do something different.

I also haven't looked at the way TCC handles its parameters yet to properly integrate with its C++-side code.

malayli commented 1 year ago

@KungFuFurby Therefore, is it impossible to implement this feature? Or does it need refactoring or new development?

KungFuFurby commented 1 year ago

It's not impossible. Within the context of the methodology that would be used, it would have some limitations... in its earliest iteration, due to carryover problems. Later iterations can customize the SPC700 side so that it can resume exactly where it left off (spcGetStartPos(), which I am considering renaming to spcGetPos() for more generalized reasons, can stay since it still serves a purpose).

malayli commented 1 year ago

@KungFuFurby Ok thank you! (sorry for late reply!). @alekmaul Can we add this feature request to next major version of PVSnesLib? (5.0.0?)

alekmaul commented 1 year ago

yes, why not :)