From 452664b3e1586c1f7f8cdc3dc890b6adcc0a8c5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olav=20S=C3=B8rensen?= Date: Mon, 9 Dec 2024 16:05:44 +0100 Subject: [PATCH] Fix invisible food (number) in Nibbles (v1.89 bug) --- src/ft2_gfxdata.h | 2 +- src/ft2_gui.h | 3 +++ src/ft2_header.h | 2 +- src/ft2_inst_ed.c | 8 ++++---- src/ft2_nibbles.c | 28 +++++++++++++++++++++++----- src/gfxdata/ft2_bmp_fonts.c | 2 +- 6 files changed, 33 insertions(+), 12 deletions(-) diff --git a/src/ft2_gfxdata.h b/src/ft2_gfxdata.h index c63dc3c..46f2484 100644 --- a/src/ft2_gfxdata.h +++ b/src/ft2_gfxdata.h @@ -10,7 +10,7 @@ extern const uint8_t font3BMP[584]; 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]; diff --git a/src/ft2_gui.h b/src/ft2_gui.h index 0adbef3..0b8d93f 100644 --- 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 { diff --git a/src/ft2_header.h b/src/ft2_header.h index 6c5c96c..af2c6f4 100644 --- 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... diff --git a/src/ft2_inst_ed.c b/src/ft2_inst_ed.c index 816fe2b..0d4d6bd 100644 --- a/src/ft2_inst_ed.c +++ b/src/ft2_inst_ed.c @@ -1582,15 +1582,15 @@ static void pianoNumberOut(uint16_t xPos, uint16_t yPos, uint8_t fgPalette, uint 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; } } diff --git a/src/ft2_nibbles.c b/src/ft2_nibbles.c index 821ba80..4aab195 100644 --- a/src/ft2_nibbles.c +++ b/src/ft2_nibbles.c @@ -44,7 +44,6 @@ typedef struct 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 bool wallColorsAreCloseToBlack(void) // ------------------------------------------------------------------------ // ------------------------------------------------------------------------ +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 @@ static void redrawNibblesScreen(void) } else { - charOut(xs + 2, ys, PAL_FORGRND, convHexTable2[NI_Number]); + drawNibblesFoodNumber(xs+2, ys, NI_Number); } } } @@ -340,8 +357,8 @@ static void nibblesGenNewNumber(void) { 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 @@ static void nibblesGenNewNumber(void) 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; } } diff --git a/src/gfxdata/ft2_bmp_fonts.c b/src/gfxdata/ft2_bmp_fonts.c index b1db971..625943f 100644 --- a/src/gfxdata/ft2_bmp_fonts.c +++ b/src/gfxdata/ft2_bmp_fonts.c @@ -1238,7 +1238,7 @@ const uint8_t font7BMP[472] = 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,