game-music-emu: Merge branch 'master' of bitbucket.org:mpyne/game-music-emu (fb84e)

From b3ba9e886a8b3e470b07da98d291b1413dd606d0 Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Thu, 5 Oct 2023 11:56:24 +0300
Subject: [PATCH 1/2] Vgm_Emu::Vgm_Emu() : initialize psg_dual and psg_t6w28.

Cures the valgrind warnings:

Loading file ../../test.vgz by file path...
==26165== Conditional jump or move depends on uninitialised value(s)
==26165==    at 0x41E3509: Vgm_Emu::update_eq(blip_eq_t const&) (Vgm_Emu.cpp:262)
==26165==    by 0x41A0469: Classic_Emu::set_equalizer_(gme_equalizer_t const&) (Classic_Emu.cpp:41)
==26165==    by 0x41AC9BB: Music_Emu::set_equalizer(gme_equalizer_t const&) (Music_Emu.cpp:101)
==26165==    by 0x41E2D44: Vgm_Emu::Vgm_Emu() (Vgm_Emu.cpp:43)
==26165==    by 0x41E32DE: new_vgm_emu() (Vgm_Emu.cpp:206)
==26165==    by 0x41A8E62: gme_internal_new_emu_(gme_type_t_ const*, int, bool) (gme.cpp:223)
==26165==    by 0x41A8FC8: gme_new_emu (gme.cpp:260)
==26165==    by 0x41A8CCF: gme_open_file (gme.cpp:186)
==26165==    by 0x804A480: Music_Player::load_file(char const*, bool) (Music_Player.cpp:115)
==26165==    by 0x804AD82: main (player.cpp:121)

Fixes: https://bitbucket.org/mpyne/game-music-emu/issues/246

Co-authored-by: Wohlstand <admin@wohlnet.ru>
---
 gme/Vgm_Emu.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/gme/Vgm_Emu.cpp b/gme/Vgm_Emu.cpp
index c62aa82..8185852 100644
--- a/gme/Vgm_Emu.cpp
+++ b/gme/Vgm_Emu.cpp
@@ -30,6 +30,8 @@ using std::max;
 Vgm_Emu::Vgm_Emu()
 {
 	disable_oversampling_ = false;
+	psg_dual = false;
+	psg_t6w28 = false;
 	psg_rate   = 0;
 	set_type( gme_vgm_type );
 	

From 4bca4b40958fe65358c0847ec49d8711de53750a Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <sezeroz@gmail.com>
Date: Thu, 5 Oct 2023 11:56:50 +0300
Subject: [PATCH 2/2] move BLARGG_BIG_ENDIAN/BLARGG_LITTLE_ENDIAN definition to
 build system.

---
 Android.mk          |  2 +-
 CMakeLists.txt      |  8 +++++++
 gme/blargg_endian.h | 52 +--------------------------------------------
 3 files changed, 10 insertions(+), 52 deletions(-)

diff --git a/Android.mk b/Android.mk
index d33d222..3beeb76 100644
--- a/Android.mk
+++ b/Android.mk
@@ -9,7 +9,7 @@ FILE_LIST	:= $(wildcard $(LOCAL_PATH)/gme/*.cpp)
 LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)
 LOCAL_CPPFLAGS := -Wall -W -Wextra -std=c++11 -O2 -DBLARGG_BUILD_DLL \
 	-DLIBGME_VISIBILITY -fvisibility=hidden -fvisibility-inlines-hidden \
-	-fwrapv -DVGM_YM2612_GENS
+	-fwrapv -DVGM_YM2612_GENS -DBLARGG_LITTLE_ENDIAN=1
 LOCAL_SANITIZE := undefined
 LOCAL_CPP_FEATURES := exceptions
 
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1644db3..5cc62c4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2,6 +2,7 @@
 project(libgme)
 cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
 
+include (TestBigEndian)
 include (CheckCXXCompilerFlag)
 include (CTest)
 
@@ -69,6 +70,13 @@ option(ENABLE_UBSAN "Enable Undefined Behavior Sanitizer error-checking" ON)
 option(BUILD_FRAMEWORK "Build framework instead of dylib (on macOS)" OFF)
 
 
+test_big_endian(WORDS_BIGENDIAN)
+if(WORDS_BIGENDIAN)
+    add_definitions(-DBLARGG_BIG_ENDIAN=1)
+else()
+    add_definitions(-DBLARGG_LITTLE_ENDIAN=1)
+endif()
+
 # static builds need to find static zlib (and static forms of other needed
 # libraries.  Ensure CMake looks only for static libs if we're doing a static
 # build.  See https://stackoverflow.com/a/44738756
diff --git a/gme/blargg_endian.h b/gme/blargg_endian.h
index c3e81c2..9690889 100644
--- a/gme/blargg_endian.h
+++ b/gme/blargg_endian.h
@@ -19,57 +19,7 @@
 
 // BLARGG_BIG_ENDIAN, BLARGG_LITTLE_ENDIAN: Determined automatically, otherwise only
 // one may be #defined to 1. Only needed if something actually depends on byte order.
-#if !defined (BLARGG_BIG_ENDIAN) && !defined (BLARGG_LITTLE_ENDIAN)
-#if defined(__ORDER_LITTLE_ENDIAN__) && defined(__ORDER_BIG_ENDIAN__) && defined(__BYTE_ORDER__)
-	#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
-		#define BLARGG_LITTLE_ENDIAN 1
-	#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
-		#define BLARGG_BIG_ENDIAN 1
-	#endif
-#elif defined(__linux__)
-	#include <endian.h>
-	#if __BYTE_ORDER == __LITTLE_ENDIAN
-		#define BLARGG_LITTLE_ENDIAN 1
-	#elif __BYTE_ORDER == __BIG_ENDIAN
-		#define BLARGG_BIG_ENDIAN 1
-	#endif
-#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__APPLE__) || \
-	defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
-	#include <machine/endian.h>
-	#if BYTE_ORDER == LITTLE_ENDIAN
-		#define BLARGG_LITTLE_ENDIAN 1
-	#elif BYTE_ORDER == BIG_ENDIAN
-		#define BLARGG_BIG_ENDIAN 1
-	#endif
-#elif defined(BLARGG_CPU_X86) || defined(_WIN32)
-	#define BLARGG_LITTLE_ENDIAN 1
-#elif defined(__ARMEB__) || defined(__THUMBEB__) || defined(__AARCH64EB__) || \
-	defined(_MIPSEB) || defined(__MIPSEB) || defined(__MIPSEB__)
-	#define BLARGG_BIG_ENDIAN 1
-#elif defined(__ARMEL__) || defined(__THUMBEL__) || defined(__AARCH64EL__) || \
-	defined(_MIPSEL) || defined(__MIPSEL) || defined(__MIPSEL__)
-	#define BLARGG_LITTLE_ENDIAN 1
-#elif defined(__MORPHOS__) || (defined(__amigaos__) && (defined(__NEWLIB__)))
-	#include <machine/endian.h>
-	#if (BYTE_ORDER == LITTLE_ENDIAN)
-		#define BLARGG_LITTLE_ENDIAN 1
-	#elif (BYTE_ORDER == BIG_ENDIAN)
-		#define BLARGG_BIG_ENDIAN 1
-	#endif
-#elif defined(__amigaos__) && defined(__CLIB2__)
-	#include <unistd.h>
-	#if (BYTE_ORDER == LITTLE_ENDIAN)
-		#define BLARGG_LITTLE_ENDIAN 1
-	#elif (BYTE_ORDER == BIG_ENDIAN)
-		#define BLARGG_BIG_ENDIAN 1
-	#endif
-#elif defined(__mc68000__) || defined(__M68K__) || defined(__m68k__) || defined(__MC68K__)
-	#define BLARGG_BIG_ENDIAN 1
-#elif defined(__hppa) || defined(__hppa__)
-	#define BLARGG_BIG_ENDIAN 1
-#endif
-#endif
-
+// BLARGG_BIG_ENDIAN or BLARGG_LITTLE_ENDIAN must be defined by the build system.
 #if !defined(BLARGG_BIG_ENDIAN) && !defined(BLARGG_LITTLE_ENDIAN)
 	#error Unspecified endianness.
 #endif