shithub: ft²

Download patch

ref: 452664b3e1586c1f7f8cdc3dc890b6adcc0a8c5b
parent: 987da7a42f90ce6322a4ec259aa9c35015690ca6
author: Olav Sørensen <olav.sorensen@live.no>
date: Mon Dec 9 11:05:44 EST 2024

Fix invisible food (number) in Nibbles (v1.89 bug)

--- a/src/ft2_gfxdata.h
+++ b/src/ft2_gfxdata.h
@@ -10,7 +10,7 @@
 extern const uint8_t font4BMP[13604];
 extern const uint8_t font6BMP[532];
 extern const uint8_t font7BMP[472];
-extern const uint8_t font8BMP[368];
+extern const uint8_t font8BMP[368]; // small font for piano key and Nibbles (snake food number)
 
 // ft2_bmp_logo.c
 extern const uint8_t ft2AboutLogoBMP[23172];
--- a/src/ft2_gui.h
+++ b/src/ft2_gui.h
@@ -31,6 +31,9 @@
 #define FONT7_CHAR_W 6
 #define FONT7_CHAR_H 7
 #define FONT7_WIDTH 140
+#define FONT8_WIDTH 80
+#define FONT8_CHAR_W 5
+#define FONT8_CHAR_H 7
 
 enum
 {
--- a/src/ft2_header.h
+++ b/src/ft2_header.h
@@ -12,7 +12,7 @@
 #endif
 #include "ft2_replayer.h"
 
-#define PROG_VER_STR "1.89"
+#define PROG_VER_STR "1.90"
 
 // do NOT change these! It will only mess things up...
 
--- a/src/ft2_inst_ed.c
+++ b/src/ft2_inst_ed.c
@@ -1582,15 +1582,15 @@
 	const uint32_t fg = video.palette[fgPalette];
 	const uint32_t bg = video.palette[bgPalette];
 	uint32_t *dstPtr = &video.frameBuffer[(yPos * SCREEN_W) + xPos];
-	const uint8_t *srcPtr = &bmp.font8[val * 5];
+	const uint8_t *srcPtr = &bmp.font8[val * FONT8_CHAR_W];
 
-	for (int32_t y = 0; y < 7; y++)
+	for (int32_t y = 0; y < FONT8_CHAR_H; y++)
 	{
-		for (int32_t x = 0; x < 5; x++)
+		for (int32_t x = 0; x < FONT8_CHAR_W; x++)
 			dstPtr[x] = srcPtr[x] ? fg : bg;
 
 		dstPtr += SCREEN_W;
-		srcPtr += 80;
+		srcPtr += FONT8_WIDTH;
 	}
 }
 
--- a/src/ft2_nibbles.c
+++ b/src/ft2_nibbles.c
@@ -44,7 +44,6 @@
 static const char nibblesCheatCode1[] = "skip", nibblesCheatCode2[] = "triton";
 static char nibblesCheatBuffer[16];
 
-static const char convHexTable2[10] = { 7, 8, 9, 10, 11, 12, 13, 16, 17, 18 };
 static const uint8_t NI_Speeds[4] = { 12, 8, 6, 4 };
 static bool NI_EternalLives;
 static uint8_t NI_CheatIndex, NI_CurSpeed, NI_CurTick60Hz, NI_CurSpeed60Hz, NI_Screen[51][23], NI_Level;
@@ -101,6 +100,24 @@
 // ------------------------------------------------------------------------
 // ------------------------------------------------------------------------
 
+static void drawNibblesFoodNumber(int32_t xOut, int32_t yOut, int32_t number)
+{
+	if (number > 9)
+		return;
+
+	uint32_t *dstPtr = &video.frameBuffer[(yOut * SCREEN_W) + xOut];
+	uint8_t *srcPtr = &bmp.font8[number * FONT8_CHAR_W];
+
+	for (int32_t y = 0; y < FONT8_CHAR_H; y++, srcPtr += FONT8_WIDTH, dstPtr += SCREEN_W)
+	{
+		for (int32_t x = 0; x < FONT8_CHAR_W; x++)
+		{
+			if (srcPtr[x] != 0)
+				dstPtr[x] = video.palette[PAL_FORGRND];
+		}
+	}
+}
+
 static void redrawNibblesScreen(void)
 {
 	if (!editor.NI_Play)
@@ -128,7 +145,7 @@
 			}
 			else
 			{
-				charOut(xs + 2, ys, PAL_FORGRND, convHexTable2[NI_Number]);
+				drawNibblesFoodNumber(xs+2, ys, NI_Number);
 			}
 		}
 	}
@@ -340,8 +357,8 @@
 {
 	while (true)
 	{
-		const int16_t x = rand() % 51;
-		const int16_t y = rand() % 23;
+		int16_t x = rand() % 51;
+		int16_t y = rand() % 23;
 
 		bool blockIsSuitable;
 
@@ -370,7 +387,8 @@
 				fillRect(xs, ys, 8, 7, PAL_BCKGRND);
 			}
 
-			charOut((x * 8) + 154, (y * 7) + 7, PAL_FORGRND, convHexTable2[NI_Number]);
+			drawNibblesFoodNumber((x * 8) + 154, (y * 7) + 7, NI_Number);
+
 			break;
 		}
 	}
--- a/src/gfxdata/ft2_bmp_fonts.c
+++ b/src/gfxdata/ft2_bmp_fonts.c
@@ -1238,7 +1238,7 @@
 	0x10,0x11,0x11,0x10,0x01,0x11,0x00,0x01,0x11,0x00,0x11,0x11,0x00,0x01,0x00,0x00
 };
 
-const uint8_t font8BMP[368] = // small font for piano key
+const uint8_t font8BMP[368] = // small font for piano key and Nibbles (snake food number)
 {
 	0x42,0x4D,0x70,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x3E,0x00,0x00,0x00,0x28,0x00,0x00,0x00,0x50,0x00,0x00,0x00,0x07,0x00,
 	0x00,0x00,0x01,0x00,0x04,0x00,0x02,0x00,0x00,0x00,0x32,0x01,0x00,0x00,0x12,0x0B,0x00,0x00,0x12,0x0B,0x00,0x00,0x02,0x00,
--