ref: 96b4a252f20aec887a58d07a5bcd34bb4365c1e0
parent: 844b0885556b8f5ff1f211c08ba52f75bc86a37a
author: Olav Sørensen <[email protected]>
date: Thu Apr 7 08:50:48 EDT 2022
Fix possible out-of-sync between replayer pos and tracker pos
--- a/src/pt2_header.h
+++ b/src/pt2_header.h
@@ -14,7 +14,7 @@
#include "pt2_unicode.h"
#include "pt2_palette.h"
-#define PROG_VER_STR "1.43"
+#define PROG_VER_STR "1.44"
#ifdef _WIN32
#define DIR_DELIMITER '\\'
@@ -210,7 +210,10 @@
TEXT_EDIT_HEX = 2
};
-int8_t *allocMemForAllSamples(void); // pt2_replayer.c
+// pt2_replayer.c
+int8_t *allocMemForAllSamples(void);
+void setReplayerPosToTrackerPos(void);
+// -------------------------
void restartSong(void);
void resetSong(void);
--- a/src/pt2_replayer.c
+++ b/src/pt2_replayer.c
@@ -35,6 +35,14 @@
0x10, 0x13, 0x16, 0x1A, 0x20, 0x2B, 0x40, 0x80
};
+void setReplayerPosToTrackerPos(void)
+{
+ modPattern = (int8_t)song->currPattern;
+ modOrder = song->currOrder;
+ song->row = song->currRow;
+ song->tick = 0;
+}
+
int8_t *allocMemForAllSamples(void)
{
// allocate memory for all sample data blocks (+ 2 extra, for quirk + safety)
@@ -707,7 +715,7 @@
switch (cmd)
{
case 0x9: sampleOffset(ch); return; // note the returns here, not breaks!
- case 0xB: positionJump(ch); return;
+ case 0xB: positionJump(ch); return;
case 0xD: patternBreak(ch); return;
case 0xE: E_Commands(ch); return;
case 0xF: setSpeed(ch); return;
@@ -1270,6 +1278,13 @@
posJumpAssert = false;
modRenderDone = true;
+ /* The replayer is one tick ahead (unfortunately), so if the user was to stop the mod at the previous tick
+ ** before a position jump (pattern loop, pattern break, position jump, row 63->0 transition, etc),
+ ** it would be possible for the replayer to be at another order/pattern than the tracker.
+ ** Let's set the replayer state to the tracker state on mod stop, to fix possible confusion.
+ */
+ setReplayerPosToTrackerPos();
+
doStopSong = false; // just in case this flag was stuck from command F00 (stop song)
}
@@ -1280,9 +1295,10 @@
audio.tickSampleCounter64 = 0; // zero tick sample counter so that it will instantly initiate a tick
song->currRow = song->row = startRow & 0x3F;
- song->tick = song->speed;
- ciaSetBPM = -1;
+ song->tick = song->speed-1;
+ ciaSetBPM = -1; // fix possibly stuck "set BPM" flag
+
editor.playMode = PLAY_MODE_PATTERN;
editor.currMode = MODE_PLAY;
editor.didQuantize = false;
@@ -1323,8 +1339,6 @@
doStopIt(false);
turnOffVoices();
- audio.tickSampleCounter64 = 0; // zero tick sample counter so that it will instantly initiate a tick
- ciaSetBPM = -1;
if (row != -1)
{
@@ -1376,6 +1390,8 @@
editor.currMode = oldMode;
song->tick = song->speed-1;
+ ciaSetBPM = -1; // fix possibly stuck "set BPM" flag
+
modRenderDone = false;
editor.songPlaying = true;
editor.didQuantize = false;
@@ -1382,6 +1398,8 @@
if (editor.playMode != PLAY_MODE_PATTERN)
editor.musicTime64 = 0; // don't reset playback counter in "play/rec pattern" mode
+
+ audio.tickSampleCounter64 = 0; // zero tick sample counter so that it will instantly initiate a tick
if (audioWasntLocked)
unlockAudio();