From ebe789aa52afa359894f0d11d2958b1439a3acca Mon Sep 17 00:00:00 2001 From: Rickey Fehr Date: Tue, 23 Sep 2025 16:15:50 -0700 Subject: [PATCH 1/4] Add git hash baked into ROM for bug reports --- Makefile | 6 ++++++ include/version.h | 7 +++++++ source/game.c | 1 + 3 files changed, 14 insertions(+) create mode 100644 include/version.h diff --git a/Makefile b/Makefile index 9bee64f..d76c021 100644 --- a/Makefile +++ b/Makefile @@ -38,11 +38,17 @@ GRAPHICS := graphics #--------------------------------------------------------------------------------- ARCH := -mthumb -mthumb-interwork +GIT_DIRTY := $(shell git diff-index --quiet HEAD -- || echo "-dirty") +GIT_HASH := $(shell git rev-parse --short HEAD) +GIT_C_FLAGS := -DGIT_HASH=\"$(GIT_HASH)\" -DGIT_DIRTY=\"$(GIT_DIRTY)\" + CFLAGS := -g -O3 -Wall -Werror\ -mcpu=arm7tdmi -mtune=arm7tdmi \ -ffast-math -fomit-frame-pointer -funroll-loops \ $(ARCH) +CFLAGS += $(GIT_C_FLAGS) + CFLAGS += $(INCLUDE) CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions diff --git a/include/version.h b/include/version.h new file mode 100644 index 0000000..8e1345b --- /dev/null +++ b/include/version.h @@ -0,0 +1,7 @@ +#ifndef VERSION_H +#define VERSION_H + +__attribute__((used)) +const char gba_version[] = "GBA_VERSION:" GIT_HASH GIT_DIRTY; + +#endif // VERSION_H diff --git a/source/game.c b/source/game.c index 625ecc6..018ebb6 100644 --- a/source/game.c +++ b/source/game.c @@ -28,6 +28,7 @@ #include "soundbank.h" #include "list.h" +#include "version.h" static uint rng_seed = 0; From 56bbc2ff9ae5b7aa5056d3f874e16da46ad0a249 Mon Sep 17 00:00:00 2001 From: Rickey Fehr Date: Tue, 23 Sep 2025 17:14:18 -0700 Subject: [PATCH 2/4] Add defaults for GIT_HASH and GIT_DIRTY --- Makefile | 2 +- include/version.h | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index d76c021..5ac91f7 100644 --- a/Makefile +++ b/Makefile @@ -39,7 +39,7 @@ GRAPHICS := graphics ARCH := -mthumb -mthumb-interwork GIT_DIRTY := $(shell git diff-index --quiet HEAD -- || echo "-dirty") -GIT_HASH := $(shell git rev-parse --short HEAD) +GIT_HASH := $(shell git rev-parse --short HEAD || echo "undef") GIT_C_FLAGS := -DGIT_HASH=\"$(GIT_HASH)\" -DGIT_DIRTY=\"$(GIT_DIRTY)\" CFLAGS := -g -O3 -Wall -Werror\ diff --git a/include/version.h b/include/version.h index 8e1345b..85be8ff 100644 --- a/include/version.h +++ b/include/version.h @@ -1,7 +1,15 @@ #ifndef VERSION_H #define VERSION_H +#ifndef GIT_HASH +#define GIT_HASH "undef" +#endif + +#ifndef GIT_DIRTY +#define GIT_DIRTY "-dirty" +#endif + __attribute__((used)) -const char gba_version[] = "GBA_VERSION:" GIT_HASH GIT_DIRTY; +const char balatro_version[] = "GBALATRO_VERSION:" GIT_HASH GIT_DIRTY; #endif // VERSION_H From 36bcf0fa3027282b3612181cc293898823da7602 Mon Sep 17 00:00:00 2001 From: Rickey Fehr Date: Wed, 24 Sep 2025 20:44:13 -0700 Subject: [PATCH 3/4] Move version into C file --- Makefile | 2 +- source/game.c | 1 - include/version.h => source/version.c | 7 +------ 3 files changed, 2 insertions(+), 8 deletions(-) rename include/version.h => source/version.c (68%) diff --git a/Makefile b/Makefile index 5ac91f7..d187d39 100644 --- a/Makefile +++ b/Makefile @@ -54,7 +54,7 @@ CFLAGS += $(INCLUDE) CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions ASFLAGS := -g $(ARCH) -LDFLAGS = -g $(ARCH) -Wl,-Map,$(notdir $*.map) +LDFLAGS = -g $(ARCH) -Wl,-Map,$(notdir $*.map),--undefined=balatro_version #--------------------------------------------------------------------------------- # any extra libraries we wish to link with the project diff --git a/source/game.c b/source/game.c index 018ebb6..625ecc6 100644 --- a/source/game.c +++ b/source/game.c @@ -28,7 +28,6 @@ #include "soundbank.h" #include "list.h" -#include "version.h" static uint rng_seed = 0; diff --git a/include/version.h b/source/version.c similarity index 68% rename from include/version.h rename to source/version.c index 85be8ff..9d850d8 100644 --- a/include/version.h +++ b/source/version.c @@ -1,6 +1,3 @@ -#ifndef VERSION_H -#define VERSION_H - #ifndef GIT_HASH #define GIT_HASH "undef" #endif @@ -9,7 +6,5 @@ #define GIT_DIRTY "-dirty" #endif -__attribute__((used)) +__attribute__((section(".version"), used)) const char balatro_version[] = "GBALATRO_VERSION:" GIT_HASH GIT_DIRTY; - -#endif // VERSION_H From 88726cbb39b39ef20f0fd048dc9240e2168e87f1 Mon Sep 17 00:00:00 2001 From: Rickey Fehr Date: Wed, 24 Sep 2025 20:49:01 -0700 Subject: [PATCH 4/4] Add script to get version --- scripts/build_bug_report.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 scripts/build_bug_report.py diff --git a/scripts/build_bug_report.py b/scripts/build_bug_report.py new file mode 100644 index 0000000..017127a --- /dev/null +++ b/scripts/build_bug_report.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python3 + +import sys +import re + +def grep_binary_offsets(path, pattern): + with open(path, "rb") as f: + data = f.read() + + results = [] + for match in re.finditer(rb"[ -~]{4,}", data): + s = match.group() + if re.search(pattern.encode(), s): + results.append((match.start(), s.decode("utf-8", errors="ignore"))) + return results + +if __name__ == "__main__": + if len(sys.argv) < 2: + print("Usage: python script.py ") + sys.exit(1) + + file_path = sys.argv[1] + pattern = "GBALATRO_VERSION" + + for offset, text in grep_binary_offsets(file_path, pattern): + version = text.split(":")[1] + print(f"git hash: {version}")