shithub: ft2-clone

Download patch

ref: 402bc1e2a864e72139a5669c18b2008bd0d765bb
parent: 6c3d4b444a9a087946cf974ce394497ffe598872
author: Olav Sørensen <olav.sorensen@live.no>
date: Tue Apr 21 15:46:54 EDT 2020

Fixed some minor bugs

1) The custom directory paths in the config could contain unwanted junk at the end if  the loaded config file was saved from real FT2
2) If you were skilled enough to beat the very last Nibbles level, your potential entry in the highscore table would show garbled stage graphics
3) Show a warning if either of the Buttons/Desktop palette colors are so dark that you might have issues seeing the walls in Nibbles

--- a/src/ft2_config.c
+++ b/src/ft2_config.c
@@ -111,6 +111,23 @@
 	config.patternsPath[80-1] = '\0';
 	config.tracksPath[80-1] = '\0';
 
+	// clear data after the actual Pascal string length. FT2 can save garbage in that area.
+
+	if (config.modulesPathLen < 80)
+		memset(&config.modulesPath[config.modulesPathLen], 0, 80-config.modulesPathLen);
+
+	if (config.instrPathLen < 80)
+		memset(&config.instrPath[config.instrPathLen], 0, 80-config.instrPathLen);
+
+	if (config.samplesPathLen < 80)
+		memset(&config.samplesPath[config.samplesPathLen], 0, 80-config.samplesPathLen);
+
+	if (config.patternsPathLen < 80)
+		memset(&config.patternsPath[config.patternsPathLen], 0, 80-config.patternsPathLen);
+
+	if (config.tracksPathLen < 80)
+		memset(&config.tracksPath[config.tracksPathLen], 0, 80-config.tracksPathLen);
+
 	config.boostLevel = CLAMP(config.boostLevel, 1, 32);
 	config.masterVol = CLAMP(config.masterVol, 0, 256);
 	config.ptnMaxChannels = CLAMP(config.ptnMaxChannels, 0, 3);
--- a/src/ft2_header.h
+++ b/src/ft2_header.h
@@ -12,7 +12,7 @@
 #endif
 #include "ft2_replayer.h"
 
-#define PROG_VER_STR "1.20"
+#define PROG_VER_STR "1.21"
 
 // do NOT change these! It will only mess things up...
 
--- a/src/ft2_nibbles.c
+++ b/src/ft2_nibbles.c
@@ -54,6 +54,53 @@
 static nibbleCrd NI_P1[256], NI_P2[256];
 static nibbleBufferTyp nibblesBuffer[2];
 
+/* Non-FT2 feature: Check if either the Desktop or Buttons palette color
+** is so close to black that the player would have troubles seeing the walls
+** when playing Nibbles.
+*/
+// ------------------------------------------------------------------------
+// ------------------------------------------------------------------------
+static uint8_t rgb24ToLuminosity(uint32_t rgb24)
+{
+	const uint8_t R = RGB32_R(rgb24);
+	const uint8_t G = RGB32_G(rgb24);
+	const uint8_t B = RGB32_B(rgb24);
+
+	// get highest channel value
+	uint8_t hi = 0;
+	if (hi < R) hi = R;
+	if (hi < G) hi = G;
+	if (hi < B) hi = B;
+
+	// get lowest channel value
+	uint8_t lo = 255;
+	if (lo > R) lo = R;
+	if (lo > G) lo = G;
+	if (lo > B) lo = B;
+
+	return (hi + lo) >> 1; // 0..255
+}
+
+static bool wallColorsAreCloseToBlack(void)
+{
+#define LUMINOSITY_THRESHOLD 4
+
+	uint8_t wallColor1L = rgb24ToLuminosity(video.palette[PAL_DESKTOP]);
+	uint8_t wallColor2L = rgb24ToLuminosity(video.palette[PAL_BUTTONS]);
+
+	/* Since the rest of the wall colors are based on lower and higher
+	** contrast values from these two primary colors, we don't really
+	** need to check them all.
+	*/
+
+	if (wallColor1L <= LUMINOSITY_THRESHOLD || wallColor2L <= LUMINOSITY_THRESHOLD)
+		return true;
+
+	return false;
+}
+// ------------------------------------------------------------------------
+// ------------------------------------------------------------------------
+
 static void redrawNibblesScreen(void)
 {
 	uint8_t x, y, c;
@@ -409,6 +456,10 @@
 		editor.NI_Play = false;
 		okBox(0, "Nibbles message", "GAME OVER");
 
+		// prevent highscore table from showing overflowing level graphics
+		if (NI_Level >= NI_MAXLEVEL)
+			NI_Level = NI_MAXLEVEL - 1;
+
 		if (NI_P1Score > config.NI_HighScore[9].score)
 		{
 			strcpy(name, "Unknown");
@@ -786,6 +837,9 @@
 		return;
 	}
 
+	if (wallColorsAreCloseToBlack())
+		okBox(0, "Nibbles warning", "The Desktop/Button colors are set to values that make the walls hard to see!");
+
 	assert(config.NI_Speed < 4);
 	NI_CurSpeed = NI_Speeds[config.NI_Speed];
 
@@ -798,7 +852,7 @@
 	NI_P2Score = 0;
 	NI_P1Lives = 5;
 	NI_P2Lives = 5;
-	NI_Level = 0;
+	NI_Level = 1;
 
 	newNibblesGame();
 }