I wasn't happy with the current fix from 1.1.3, so I decided to refactor it.
I also checked and that problem fixed by 1.1.3, also occurs in both qwertymodo and DarkShock patches.
The issue with the fix from 1.1.3 is that while it fixes replaying tracks under certain conditions, it can also theoretically cancel out resuming a track from a certain sample offset.
Take this example:
- A track is currently playing.
- Game requests to interrupt this track to play another.
- MSU-1 code saves the current sample offset of the current track and starts playing the new track.
- New track finishes playing and the previous track is resumed.
- Now, we haven't really started replaying the previous track because either the SPC isn't muted yet or because the current volume is below the threshold; we have just loaded it into MSU-1.
- Game repeats a request for playing this track, forcing a reload of the track which causes the resume sample offset to be lost, making the track plays from the beginning.
To fix this, I've added a new bitflag that is reset when the track has just been loaded into MSU-1 and set when it actually starts playing. We check for this flag when the requested track is the loaded track.
Now we only replay a track under this condition when the loaded track had previously started playing and when it's currently not playing.
Other than that, I went through another pass of the code to improve whatever was left to improve.
Not much was left to improve because I've had this done multiple times back in 2019, but the minor stuff I could find was also improved.
I also did a cycle comparison between my hack and qwertymodo's when executing the default (nop) code at NMI, which is executed once every frame at VBLANK and needs to be the most optimized.
Mine is the same for versions 1.1.2 (2019), 1.1.3 and 1.1.4.
|Hack||CPU cycles||Master Clock cycles|
|qwertymodo (NO MSU-1)||32||208|
As you can see my hack performs 45% faster than qwertymodo's and 38% slower than qwertymodo's without MSU-1.
Since no extra code is ever executed when there is no MSU-1, the comparison against his NO MSU-1 is moot.
The complete instruction-by-instruction cycle table:
Mine 1.1.2(2019), 1.1.3, 1.1.4:
qwertymodo (NO MSU-1):
Download v1.1.4: https://mega.nz/folder/wIE1gQ5S#rbpeeX5pcNFAXfV9XVt2bA
EDIT: Fixed Master Clock cycles calculation by correctly multiplying stack access cycles by 8.
EDIT: Replaced download link.
EDIT: Added support for the french translation.
EDIT: Added extra features to the make scripts.