shithub: pt2-clone

Download patch

ref: 0699e2c43053653db63616e42ae2080ffd2dc73c
parent: ee2f1a650e94caef7c57e3484b0c10737f59b801
author: Olav Sørensen <olav.sorensen@live.no>
date: Thu Aug 12 08:52:37 EDT 2021

Small cleanup

--- a/src/pt2_header.h
+++ b/src/pt2_header.h
@@ -42,9 +42,6 @@
 */
 #define SCOPE_HZ 64
 
-#define AMIGA_PAL_VBLANK_HZ 49.9204092835
-
-#define FONT_BMP_WIDTH 
 #define FONT_CHAR_W 8 // actual data length is 7, includes right spacing (1px column)
 #define FONT_CHAR_H 5
 
@@ -67,12 +64,16 @@
 
 #define POSED_LIST_SIZE 12
 
-
-// main crystal oscillator
+// main crystal oscillator for PAL Amiga systems
 #define AMIGA_PAL_XTAL_HZ 28375160
 
-#define PAULA_PAL_CLK (AMIGA_PAL_XTAL_HZ / 8)
-#define CIA_PAL_CLK (AMIGA_PAL_XTAL_HZ / 40)
+#define AMIGA_PAL_CCK_HZ (AMIGA_PAL_XTAL_HZ/8.0)
+
+// nominal framerate in normal PAL videomodes (~49.92Hz)
+#define AMIGA_PAL_VBLANK_HZ (AMIGA_PAL_CCK_HZ / (double)(313*227))
+
+#define PAULA_PAL_CLK AMIGA_PAL_CCK_HZ
+#define CIA_PAL_CLK (AMIGA_PAL_CCK_HZ / 5.0)
 
 #define PAL_PAULA_MIN_SAFE_PERIOD 124
 #define PAL_PAULA_MAX_SAFE_HZ (PAULA_PAL_CLK / (double)PAL_PAULA_MIN_SAFE_PERIOD)
--- a/src/pt2_replayer.c
+++ b/src/pt2_replayer.c
@@ -398,7 +398,7 @@
 	ch->n_period -= (ch->n_cmd & 0xFF) & lowMask;
 	lowMask = 0xFF;
 
-	if ((ch->n_period & 0xFFF) < 113)
+	if ((ch->n_period & 0xFFF) < 113) // PT BUG: unsigned comparison, underflow not clamped!
 		ch->n_period = (ch->n_period & 0xF000) | 113;
 
 	paulaSetPeriod(ch->n_chanindex, ch->n_period & 0xFFF);
@@ -542,24 +542,21 @@
 	const uint8_t vibratoPos = (ch->n_vibratopos >> 2) & 0x1F;
 	const uint8_t vibratoType = ch->n_wavecontrol & 3;
 
-	if (vibratoType == 0)
+	if (vibratoType == 0) // sine
 	{
 		vibratoData = vibratoTable[vibratoPos];
 	}
-	else
+	else if (vibratoType == 1) // ramp
 	{
-		if (vibratoType == 1)
-		{
-			if (ch->n_vibratopos < 128)
-				vibratoData = vibratoPos << 3;
-			else
-				vibratoData = 255 - (vibratoPos << 3);
-		}
+		if (ch->n_vibratopos < 128)
+			vibratoData = vibratoPos << 3;
 		else
-		{
-			vibratoData = 255;
-		}
+			vibratoData = 255 - (vibratoPos << 3);
 	}
+	else // square
+	{
+		vibratoData = 255;
+	}
 
 	vibratoData = (vibratoData * (ch->n_vibratocmd & 0xF)) >> 7;
 
@@ -609,24 +606,21 @@
 	const uint8_t tremoloPos = (ch->n_tremolopos >> 2) & 0x1F;
 	const uint8_t tremoloType = (ch->n_wavecontrol >> 4) & 3;
 
-	if (tremoloType == 0)
+	if (tremoloType == 0) // sine
 	{
 		tremoloData = vibratoTable[tremoloPos];
 	}
-	else
+	else if (tremoloType == 1) // ramp
 	{
-		if (tremoloType == 1)
-		{
-			if (ch->n_vibratopos < 128) // PT bug, should've been ch->n_tremolopos
-				tremoloData = tremoloPos << 3;
-			else
-				tremoloData = 255 - (tremoloPos << 3);
-		}
+		if (ch->n_vibratopos < 128) // PT bug, should've been ch->n_tremolopos
+			tremoloData = tremoloPos << 3;
 		else
-		{
-			tremoloData = 255;
-		}
+			tremoloData = 255 - (tremoloPos << 3);
 	}
+	else // square
+	{
+		tremoloData = 255;
+	}
 
 	tremoloData = ((uint16_t)tremoloData * (ch->n_tremolocmd & 0xF)) >> 6;
 
@@ -909,8 +903,6 @@
 	}
 }
 
-static bool firstNextPos = true;
-
 static void updateUIPositions(void)
 {
 	// don't update UI under MOD2WAV/PAT2SMP rendering
@@ -984,8 +976,6 @@
 		if (modPattern > MAX_PATTERNS-1)
 			modPattern = MAX_PATTERNS-1;
 	}
-
-	firstNextPos = false;
 }
 
 static void increasePlaybackTimer(void)