OpenDUNE: SDL game (#5385)

Co-authored-by: Gabriele Baldassarre <gabriele@gabrielebaldassarre.com>
This commit is contained in:
Máximo Castañeda
2020-11-11 08:02:57 +01:00
committed by GitHub
parent 9a313af501
commit da717df94e
3 changed files with 944 additions and 0 deletions

View File

@@ -0,0 +1,65 @@
resource app_flags B_SINGLE_LAUNCH | B_ARGV_ONLY;
resource app_version {
major = 0,
middle = 9,
minor = 0,
variety = B_APPV_FINAL,
internal = 0,
short_info = "OpenDUNE",
long_info = "Open source re-creation of the popular game \"Dune II\""
};
resource app_signature "application/x-vnd.opendune";
resource vector_icon {
$"6E6369660503EAC16E03EFD4A5053304003F05FF0D0208BF18CC0CBF4DCC0FB8"
$"8FCBBAB35CBFB6B35CC654B35CB935BEC3B365B863B3E1BF14B35FBFB6B35CBF"
$"65B35CC27EB35CC71FB5D4C50FB447CA1FB815CC10BFB6CC10BBABCC10C32BC8"
$"5BC889CAA5C64BC621CAB8BFB6CC10C314CC10BF81CC100405FE02C42DC258C9"
$"91C2F3C7BCBFFCCB65C5E9C118CA44C8D1CA22BB76C4FCBFC6BF2DBC6EC024C3"
$"1EBE35C42DC2580207C42DC2B5C434C2B5C403C2B5C3D3C26FC3DEC299C3D3C2"
$"6DC333C100C3A3C1B9C318C0D4C352C080C326C09BC37EC066C3D1C09FC3B7C0"
$"74C451C172C487C241C484C239C493C273C444C2B2C475C2A5C43CC2B40209BE"
$"88C027BE9BC027BE6CC027BE3EC002BE50C01ABE1FBFDABE50BF81BE27BFA0BE"
$"B6BF33BFACBED4BF2BBEF9C0D9BE7DC2C7BF66C1E4BEAEC2EFBF86C2D5BFE8C2"
$"F540C2B5C010C252BFF6C27AC016C1A1BF66BFE0BF86C0CEBF40BF75BFA5BEC0"
$"C014BF14BFD5BEAFC0210207BD63C1A4BD88C1A4BD58C1A4BD40C19DBD4BC1A1"
$"BD11C189BD0EC123BCFAC153BD21C0F6BD51C09FBD37C0C9BD6BC073BDD0C07E"
$"BDA4C064BDFCC099BDF0C0FDBE0AC0D1BDDBC120BDB9C16BBDC9C145BDAAC18E"
$"020AC118CAA1C119CAA1C100CAA1C0D9CA88C0EACA98BCFBC6E8BCB947BC9AC3"
$"F8BCBDC257BD1DC235BCEAC231BD50C23ABD71C299BD76C266BD43C4C7C13CC9"
$"E7BEA4C76FC1C3C9E4C2C5C9CEC247C9DBC2F8C9C8C32BCA20C326C9EDC331CA"
$"53C2D9CA86C30CCA80C24ACA95C11ACAA1C1B3CA9EC119CAA1020DC446CA4DC4"
$"4CCA4DC41BCA4DC3EBCA03C3F4CA2FC3E1C9D1C433C996C401C9A0C6DCC90BC9"
$"7DC62EC8CAC7CDC9EDC52BC942C323C9D8C417C8D6C274C798C1E1C846C208C6"
$"12C18BC460C2A5C464C2A2C435C2C1C3E0C28BC3FCC2B6C3C3C260C3FAC20BC3"
$"CFC227C40EC1FDC7BFC12CC5ECC0C6C8A1C15EC9E0C2C2C958C1E6CA97C3EACA"
$"27C678CAB0C53CC95BC84FC458CA4BC73DC9B4C452CA4C020EC0C5CB64C144CB"
$"91BF53CAE2BCDDC922BE015ABA37C6DEB889BFBEB889C380B889BC69BC00B72A"
$"B9DBB963BD2FB5F0C037B44EBE9DB4F5C0E2B408C24DB3AAC194B3D1C177B37C"
$"BFB6B364C099B364BE0FB364BB0AB44EBC7BB3B7B971B4F5B6D3B72AB802B5F0"
$"B4AEB963B35CBFBEB35CBC69B35CC380B7B0C922B50AC6DEB8D45ABB98CB64BA"
$"26CAE2BCE2CBD9BFB6CC18BE45CC18C099CC18C24CCBD3C177CC00C1C7CBB602"
$"07C51EB6CEC53DB6CEC50EB6CEC4EDB6C0C4FDB6CAC480B67CC397B60BC40DB6"
$"3FC368B5F6C368B590C353B5BFC37CB562C3E2B561C3B3B54CC460B599C550B6"
$"23C4DBB5DAC57BB63EC56DB6A3C588B677C55BB6BF0209C6CAC804C6E1C804C6"
$"B2C804C687C7E6C699C7FAC664C7C1C68BC763C666C786C8ABC566C9E4BFB1C9"
$"E4C298C9E4BCC6C698B80BC8B8BA0EC673B7E7C694B788C671B7ADC6B8B763C7"
$"17B784C6F2B761C95DB9ABCA9DBFB1CA9DBC92CA9DC2CBC70AC7EBC94FC5CBC6"
$"F8C7FC0207C545C935C556C935C526C935C4F7C90BC509C926C4DBC8E0C512C8"
$"8AC4E7C8A6C541C86CC59EC82AC570C84BC5C7C80BC61FC83DC601C814C63EC8"
$"66C60CC8BEC635C8A0C5DCC8E2C577C926C5A9C905C567C930020ABFB6CC6DC3"
$"0FCC6DBF80CC6DBF14CC69BF49CC6CB84ECC1420BFB620C68020BC7CB668B70D"
$"B435B969B897B4B4BEBCB309BB8CB347BF0FB303BFB620BF6320C27D20C757B5"
$"8AC520B3E0C8E2B6B3CB0AB9EFCA2AB838CBF6BBBCCC6DBFB6CC6DBDADCC6DC3"
$"28C89CC8CBCB12C662C638CB23020BBFB6B3B9C254B3B9BF68B3B9BECAB3C2BF"
$"19B3BCBBC9B3FCB6EFB78BB8FFB554B4DDB9C5B3B9BFB6B3B9BCABB3B9C61DBF"
$"1DCBB0B8BACB5FBF1DCBB0BF1DCBB0BF1DCBB0BF4FCBB2BFB65EBF835EC2DE5E"
$"C81AC847C5D9CA7CCA6CC6005EBFB65EC2F65EBDCBCA65BA44CB43BBF6C992B8"
$"A5C6E8B61EC85DB736C4D1B48D060A000100000A030107000A040108000A0401"
$"09000A04010A000A02020B0C00"
};

View File

@@ -0,0 +1,97 @@
SUMMARY="Open-source clone of Dune II: The Battle for Arrakis"
DESCRIPTION="An open source re-creation of the popular game \"Dune II\", \
originally made by Westwood Studios, and released by Virgin Entertainment.
It attempts to re-create the original game and apply modern technology to \
it to allow it to be run natively on most operating systems.
Please note that you must provide the original Dune II 1.07 data files in \
/boot/home/config/non-packaged/data/opendune directory \
for the game to run properly."
HOMEPAGE="http://www.opendune.org/"
COPYRIGHT="2009-2018 OpenDUNE Developers"
LICENSE="GNU GPL v2"
REVISION="1"
SOURCE_URI="https://github.com/OpenDUNE/OpenDUNE/archive/$portVersion.tar.gz"
CHECKSUM_SHA256="8d5ed67669df1f17a44c097d9b6bee4e0623ce2a37f11938ce9cd77de546d06c"
SOURCE_FILENAME="OpenDUNE-$portVersion.tar.gz"
SOURCE_DIR="OpenDUNE-$portVersion"
PATCHES="opendune-$portVersion.patchset"
ADDITIONAL_FILES="opendune.rdef"
ARCHITECTURES="!x86_gcc2 ?x86 x86_64"
SECONDARY_ARCHITECTURES="x86"
GLOBAL_WRITABLE_FILES="
settings/opendune.ini keep-old
"
USER_SETTINGS_FILES="
settings/opendune directory
settings/opendune/savegames directory
settings/opendune/opendune.ini template settings/opendune.ini
"
PROVIDES="
opendune$secondaryArchSuffix = $portVersion
app:OpenDUNE = $portVersion
"
REQUIRES="
haiku$secondaryArchSuffix
lib:libSDL_1.2$secondaryArchSuffix
lib:libSDL_image_1.2$secondaryArchSuffix
"
BUILD_REQUIRES="
haiku${secondaryArchSuffix}_devel
devel:libSDL_1.2$secondaryArchSuffix
devel:libSDL_image_1.2$secondaryArchSuffix
"
BUILD_PREREQUIRES="
cmd:awk
cmd:gcc$secondaryArchSuffix
cmd:git
cmd:ld$secondaryArchSuffix
cmd:make
cmd:pkg_config$secondaryArchSuffix
cmd:sed
cmd:which
"
BUILD()
{
_dune2_data_dir=$(finddir B_USER_NONPACKAGED_DATA_DIRECTORY)/opendune
export CFLAGS="-mmmx -DDUNE_DATA_DIR='\\\"${_dune2_data_dir}\\\"'"
export LDFLAGS="-lstdc++"
./configure \
--disable-assert \
--binary-name="OpenDUNE" \
--install-dir="" \
--binary-dir="${appsDir#/}" \
--data-dir="${dataDir#/}/opendune" \
--prefix-dir=""
make $jobsArg V=1
}
INSTALL()
{
mkdir -p $dataDir/opendune/
make install DO_NOT_INSTALL_DOCS=1 DO_NOT_INSTALL_LICENSE=1
sed -e "s|the desired location|$(finddir B_USER_SETTINGS_DIRECTORY)\/opendune|g" \
$sourceDir/bin/opendune.ini.sample > $sourceDir/bin/opendune.ini.tmp \
&& mv $sourceDir/bin/opendune.ini.tmp $sourceDir/bin/opendune.ini.sample
sed -e "s|;savedir=\/home\/user\/.config\/opendune|savedir=$(finddir B_USER_SETTINGS_DIRECTORY)\/opendune/savegames|g" \
$sourceDir/bin/opendune.ini.sample > $sourceDir/bin/opendune.ini.tmp \
&& mv $sourceDir/bin/opendune.ini.tmp $sourceDir/bin/opendune.ini.sample
cp $sourceDir/bin/opendune.ini.sample $settingsDir/opendune.ini
cp $sourceDir/bundle/*.txt $dataDir/opendune
cp $sourceDir/bundle/COPYING $dataDir/opendune
addResourcesToBinaries $portDir/additional-files/opendune.rdef $appsDir/OpenDUNE
addAppDeskbarSymlink $appsDir/OpenDUNE OpenDUNE
}

View File

@@ -0,0 +1,782 @@
From e548da4082671534856a6b513eb7c9d00ee6689f Mon Sep 17 00:00:00 2001
From: Gabriele Baldassarre <gabriele@gabrielebaldassarre.com>
Date: Mon, 22 Oct 2018 23:00:12 +0200
Subject: initial set of defines for Haiku
diff --git a/src/os/strings.h b/src/os/strings.h
index daac831..bdea121 100644
--- a/src/os/strings.h
+++ b/src/os/strings.h
@@ -84,13 +84,13 @@
#if !defined(__MINGW32__) && defined(__GNUC__) && !defined(snprintf)
/* (v)snprintf is in fact C99, but we like to use it over (v)sprintf for the obvious reasons */
- #if !defined(__APPLE__) && !defined(TOS) && !defined(__FreeBSD__) && !defined(__DJGPP__)
+ #if !defined(__APPLE__) && !defined(TOS) && !defined(__FreeBSD__) && !defined(__DJGPP__) && !defined(__HAIKU__)
extern int snprintf (char *__restrict __s, size_t __maxlen, __const char *__restrict __format, ...) __THROW __attribute__ ((__format__ (__printf__, 3, 4)));
extern int vsnprintf (char *__restrict __s, size_t __maxlen, __const char *__restrict __format, va_list __arg) __THROW __attribute__ ((__format__ (__printf__, 3, 0)));
#endif /* __APPLE__ */
#endif /* __GCC__ */
- #if !defined(__MINGW32__) && defined(__GNUC__) && !defined(strdup) && !defined(__APPLE__) && !defined(TOS) && !defined(__FreeBSD__) && !defined(__DJGPP__)
+ #if !defined(__MINGW32__) && defined(__GNUC__) && !defined(strdup) && !defined(__APPLE__) && !defined(TOS) && !defined(__FreeBSD__) && !defined(__DJGPP__) && !defined(__HAIKU__)
/* strdup is not ANSI-C, but our own implemention would only be slower */
extern char *strdup (__const char *__s);
#endif /* __GCC__ */
--
2.19.1
From 439c5b7b19a5501aaa37c610817f8673323f1f1f Mon Sep 17 00:00:00 2001
From: Gabriele Baldassarre <gabriele@gabrielebaldassarre.com>
Date: Tue, 23 Oct 2018 00:23:24 +0200
Subject: added support for Haiku paths
diff --git a/src/file.c b/src/file.c
index 4d3f4dc..0b08d60 100644
--- a/src/file.c
+++ b/src/file.c
@@ -25,6 +25,10 @@
#include "config.h"
#include "inifile.h"
+#ifdef __HAIKU__
+#include <StorageDefs.h>
+#endif /* HAIKU */
+
/* Set DUNE_DATA_DIR at compile time. e.g. */
/* #define DUNE_DATA_DIR "/usr/local/share/opendune" */
@@ -36,8 +40,13 @@
#endif
#endif
+#ifdef __HAIKU__
+static char g_dune_data_dir[B_PATH_NAME_LENGTH] = DUNE_DATA_DIR;
+static char g_personal_data_dir[B_PATH_NAME_LENGTH] = ".";
+#else
static char g_dune_data_dir[1024] = DUNE_DATA_DIR;
static char g_personal_data_dir[1024] = ".";
+#endif
/* In order to avoid to open/close the same .PAK file multiple time
* in a row, we cache the last opened PAK file.
diff --git a/src/inifile.c b/src/inifile.c
index d51996a..1600f0e 100644
--- a/src/inifile.c
+++ b/src/inifile.c
@@ -3,6 +3,11 @@
#ifdef OSX
#include <CoreFoundation/CoreFoundation.h>
#endif /* OSX */
+#ifdef __HAIKU__
+#include <FindDirectory.h>
+#include <StorageDefs.h>
+#include <unistd.h>
+#endif /* HAIKU */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -40,7 +45,9 @@ bool Load_IniFile(void)
1) %APPDATA%/OpenDUNE (win32)
~/Library/Application Support/OpenDUNE (Mac OS X)
~/.config/opendune (Linux)
- 2) current directory
+ B_USER_SETTINGS_DIRECTORY (Haiku)
+ 2) B_SYSTEM_SETTINGS_DIRECTORY (Haiku)
+ current directory
3) data/ dir
4) parent of bundle dir (Mac OS X)
*/
@@ -53,18 +60,40 @@ bool Load_IniFile(void)
f = fopen(path, "rb");
}
#elif !defined(TOS) && !defined(DOS) /* _WIN32 */
+ #if defined(__HAIKU__)
+ char path[B_PATH_NAME_LENGTH];
+ char buffer[B_PATH_NAME_LENGTH];
+ #else
char path[PATH_MAX];
+ #endif
char * homeDir;
homeDir = getenv("HOME");
if (homeDir != NULL) {
#if defined(__APPLE__)
snprintf(path, sizeof(path), "%s/Library/Application Support/OpenDUNE/opendune.ini", homeDir);
-#else /* __APPLE__ */
+#elif defined(__HAIKU__) /* __APPLE__ */
+ if(find_directory(B_USER_SETTINGS_DIRECTORY, 0, true, buffer, sizeof(buffer)) == B_OK){
+ snprintf(path, sizeof(path), "%s/opendune/opendune.ini", buffer);
+ }
+#else /* __HAIKU__ */
snprintf(path, sizeof(path), "%s/.config/opendune/opendune.ini", homeDir);
-#endif /* __APPLE__ */
+#endif
f = fopen(path, "rb");
}
#endif /* not TOS, not _WIN32 */
+
+#if defined(__HAIKU__)
+ /* B_SYSTEM_SETTINGS_DIRECTORY */
+ if (f == NULL) {
+ char haiku_msg[B_PATH_NAME_LENGTH + 50];
+ snprintf(haiku_msg, sizeof(haiku_msg), "%s not found; using default one...\n", path);
+ Warning(haiku_msg);
+ if(find_directory(B_SYSTEM_SETTINGS_DIRECTORY, 0, true, buffer, sizeof(buffer)) == B_OK){
+ snprintf(path, sizeof(path), "%s/opendune.ini", buffer);
+ f = fopen(path, "rb");
+ }
+ }
+#endif
if (f == NULL) {
/* current directory */
f = fopen("opendune.ini", "rb");
--
2.19.1
From 1c636a36ab749fae4daf8dcf912b5b078102b0e1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?M=C3=A1ximo=20Casta=C3=B1eda?= <antiswen@yahoo.es>
Date: Wed, 28 Oct 2020 14:32:14 +0100
Subject: Use the correct endian.h
diff --git a/src/os/endian.h b/src/os/endian.h
index f8e9361..f8e3e86 100644
--- a/src/os/endian.h
+++ b/src/os/endian.h
@@ -26,6 +26,8 @@
#define __LITTLE_ENDIAN 1234
#define __BIG_ENDIAN 4321
#define __BYTE_ORDER __LITTLE_ENDIAN
+#elif defined(__HAIKU__)
+ #include <posix/endian.h>
#else
#include <endian.h>
#endif /* _WIN32 */
--
2.28.0
From 3bd7f4073916c5fa75582a044b03ed4f1b7287c6 Mon Sep 17 00:00:00 2001
From: Thomas Bernard <miniupnp@free.fr>
Date: Thu, 9 Apr 2020 22:21:46 +0200
Subject: -Fix: Tile_PackTile() is now a macro
we should avoid to call Tile_MoveByRandom() several times
fixes #331
Bug introduced by 9c34a82b30df6dca449549d9d7a76acbbae333af
https://github.com/OpenDUNE/OpenDUNE/releases/tag/0.9
diff --git a/src/map.c b/src/map.c
index 234b08e..3f97403 100644
--- a/src/map.c
+++ b/src/map.c
@@ -984,7 +984,8 @@ uint16 Map_FindLocationTile(uint16 locationID, uint8 houseID)
s = Structure_Find(&find);
if (s != NULL) {
- ret = Tile_PackTile(Tile_MoveByRandom(s->o.position, 120, true));
+ tile32 unpacked = Tile_MoveByRandom(s->o.position, 120, true);
+ ret = Tile_PackTile(unpacked);
} else {
Unit *u;
@@ -995,7 +996,8 @@ uint16 Map_FindLocationTile(uint16 locationID, uint8 houseID)
u = Unit_Find(&find);
if (u != NULL) {
- ret = Tile_PackTile(Tile_MoveByRandom(u->o.position, 120, true));
+ tile32 unpacked = Tile_MoveByRandom(u->o.position, 120, true);
+ ret = Tile_PackTile(unpacked);
} else {
ret = Tile_PackXY(mapInfo->minX + Tools_RandomLCG_Range(0, mapInfo->sizeX), mapInfo->minY + Tools_RandomLCG_Range(0, mapInfo->sizeY));
}
@@ -1588,7 +1590,8 @@ void Map_CreateLandscape(uint32 seed)
j = Tools_Random_256() & 0x1F;
while (j-- != 0) {
while (true) {
- packed = Tile_PackTile(Tile_MoveByRandom(tile, Tools_Random_256() & 0x3F, true));
+ tile32 unpacked = Tile_MoveByRandom(tile, Tools_Random_256() & 0x3F, true);
+ packed = Tile_PackTile(unpacked);
if (!Tile_IsOutOfMap(packed)) break;
}
--
2.28.0
From a03da1d4c068717acdcddbfc91a3b54097d9d1d1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?M=C3=A1ximo=20Casta=C3=B1eda?= <antiswen@yahoo.es>
Date: Wed, 28 Oct 2020 16:11:07 +0100
Subject: Remove keyboard scancode magic
diff --git a/src/video/video_sdl.c b/src/video/video_sdl.c
index 5cfebc0..af9c209 100644
--- a/src/video/video_sdl.c
+++ b/src/video/video_sdl.c
@@ -635,7 +635,7 @@ void Video_Tick(void)
/* use "translated" KeySym */
sym = sdlkey_map[event.key.keysym.scancode];
}
-#else /* defined(__APPLE__) */
+#elif !defined(__APPLE__) && !defined(__HAIKU__)
if (event.key.keysym.scancode == 0) {
#endif /* defined(__APPLE__) */
/* scancode 0 : retrieve from sym */
@@ -645,15 +645,15 @@ void Video_Tick(void)
continue;
}
scancode = s_SDL_keymap[sym];
-#if !defined(__APPLE__)
+#if !defined(__APPLE__) && !defined(__HAIKU__)
} else {
scancode = (uint8)event.key.keysym.scancode;
-#if !defined(_WIN32) && !defined(__APPLE__)
+#if !defined(_WIN32) && !defined(__APPLE__) && !defined(__HAIKU__)
/* Linux adds 8 to all scancodes */
scancode -= 8;
-#endif /* !defined(_WIN32) && !defined(__APPLE__) */
+#endif /* !defined(_WIN32) && !defined(__APPLE__) && !defined(__HAIKU__) */
}
-#endif /* defined(__APPLE__) */
+#endif /* !defined(__APPLE__) && !defined(__HAIKU__) */
if (scancode & 0x80) {
Video_Key_Callback(0xe0);
scancode &= 0x7f;
--
2.28.0
From 1df2d2876399ccd44fe2dcb1b1b44f909947641e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?M=C3=A1ximo=20Casta=C3=B1eda?= <antiswen@yahoo.es>
Date: Sun, 1 Nov 2020 20:19:20 +0100
Subject: Fix: solve CTRL key disabling keyboard
diff --git a/src/input/input.c b/src/input/input.c
index f0d3cc6..4a1b510 100644
--- a/src/input/input.c
+++ b/src/input/input.c
@@ -206,7 +206,7 @@ void Input_EventHandler(uint8 key)
key = s_keyTranslate[key & 0x7F];
}
- if ((s_activeInputMap[7] & 0x4) != 0) return; /* 0x3a : LCTRL */
+ /*if ((s_activeInputMap[7] & 0x4) != 0) return;*/ /* 0x3a : LCTRL */
if ((s_activeInputMap[7] & 0x50) != 0) state |= 0x04; /* 0x3c 0x3e : LALT RALT => ALT */
key = Input_Keyboard_Translate(key) & 0xFF;
--
2.28.0
From cc5208edadd3944b2eb0dc5f8ea91af7d323b27e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?M=C3=A1ximo=20Casta=C3=B1eda?= <antiswen@yahoo.es>
Date: Thu, 29 Oct 2020 20:57:40 +0100
Subject: Add visible error messages
diff --git a/Makefile.src.in b/Makefile.src.in
index 828b32f..4de7d06 100644
--- a/Makefile.src.in
+++ b/Makefile.src.in
@@ -26,8 +26,9 @@ CONFIG_CACHE_SOURCE = $(SRC_OBJS_DIR)/!!CONFIG_CACHE_SOURCE!!
CONFIG_CACHE_VERSION = $(SRC_OBJS_DIR)/!!CONFIG_CACHE_VERSION!!
OBJS_C := !!OBJS_C!!
+OBJS_CXX := !!OBJS_CXX!!
OBJS_S := !!OBJS_S!!
-OBJS := $(OBJS_C) $(OBJS_S)
+OBJS := $(OBJS_C) $(OBJS_CXX) $(OBJS_S)
SRCS := !!SRCS!!
# All C-files depend on those 3 files
@@ -79,7 +80,7 @@ RES := $(shell if [ "`cat $(CONFIG_CACHE_VERSION) 2>/dev/null`" != "$(REV) $(MOD
ifndef MAKEDEPEND
# The slow, but always correct, dep-check
DEP_MASK := %.d
-DEPS := $(OBJS_C:%.o=%.d)
+DEPS := $(OBJS_C:%.o=%.d) $(OBJS_CXX:%.o=%.d)
# Only include the deps if we are compiling everything
ifeq ($(filter %.o clean mrproper, $(MAKECMDGOALS)),)
@@ -98,6 +99,10 @@ $(OBJS_C:%.o=%.d): %.d: $(SRC_DIR)/%.c $(FILE_DEP)
$(E) '$(STAGE) DEP $(<:$(SRC_DIR)/%.c=%.c)'
$(Q)$(CC_HOST) $(CFLAGS) -MM $< | sed 's@^$(@F:%.d=%.o):@$@ $(@:%.d=%.o):@' > $@
+$(OBJS_CXX:%.o=%.d): %.d: $(SRC_DIR)/%.cpp $(FILE_DEP)
+ $(E) '$(STAGE) DEP $(<:$(SRC_DIR)/%.cpp=%.cpp)'
+ $(Q)$(CC_HOST) $(CFLAGS) -MM $< | sed 's@^$(@F:%.d=%.o):@$@ $(@:%.d=%.o):@' > $@
+
else
# The much faster, but can be wrong, dep-check
DEP_MASK :=
@@ -178,6 +183,10 @@ $(OBJS_C): %.o: $(SRC_DIR)/%.c $(DEP_MASK) $(FILE_DEP)
$(E) '$(STAGE) Compiling $(<:$(SRC_DIR)/%.c=%.c)'
$(Q)$(CC_HOST) $(CFLAGS) -c -o $@ $<
+$(OBJS_CXX): %.o: $(SRC_DIR)/%.cpp $(DEP_MASK) $(FILE_DEP)
+ $(E) '$(STAGE) Compiling $(<:$(SRC_DIR)/%.cpp=%.cpp)'
+ $(Q)$(CC_HOST) $(CFLAGS) -c -o $@ $<
+
$(OBJS_S): %.o: $(SRC_DIR)/%.s
$(E) '$(STAGE) Assembling $(<:$(SRC_DIR)/%.s=%.s)'
$(Q)$(AS_HOST) $(ASFLAGS) -o $@ $<
diff --git a/config.lib b/config.lib
index 09bd456..0cadf2b 100644
--- a/config.lib
+++ b/config.lib
@@ -1872,6 +1872,7 @@ make_sed() {
s@!!CONFIG_CACHE_VERSION!!@config.cache.version@g;
s@!!CONFIG_CACHE_SOURCE_LIST!!@config.cache.source.list@g;
s@!!CONFIG_CACHE_PWD!!@config.cache.pwd@g;
+ s@!!OBJS_CXX!!@$OBJS_CXX@g;
s@!!OBJS_C!!@$OBJS_C@g;
s@!!OBJS_S!!@$OBJS_S@g;
s@!!SRCS!!@$SRCS@g;
diff --git a/configure b/configure
index 4619b0b..986a0c8 100755
--- a/configure
+++ b/configure
@@ -125,6 +125,7 @@ AWKCOMMAND='
SRCS="`< $ROOT_DIR/source.list tr '\r' '\n' | $awk \"$AWKCOMMAND\" | $PIPE_SORT`"
OBJS_C="` echo \"$SRCS\" | $awk ' { ORS = \" \" } /\.c$/ { gsub(\".c$\", \".o\", $0); print $0; }'`"
+OBJS_CXX="` echo \"$SRCS\" | $awk ' { ORS = \" \" } /\.cpp$/ { gsub(\".cpp$\", \".o\", $0); print $0; }'`"
OBJS_S="` echo \"$SRCS\" | $awk ' { ORS = \" \" } /\.s$/ { gsub(\".s$\", \".o\", $0); print $0; }'`"
SRCS="` echo \"$SRCS\" | $awk ' { ORS = \" \" } { print $0; }'`"
diff --git a/source.list b/source.list
index 58a5a38..f6aa25c 100644
--- a/source.list
+++ b/source.list
@@ -97,7 +97,11 @@ os/endian.c
#if OSX
os/error_osx.c
#else
- os/error.c
+ #if HAIKU
+ os/error_haiku.cpp
+ #else
+ os/error.c
+ #endif
#endif
#if TOS
os/readdir_atari.c
diff --git a/src/os/error_haiku.cpp b/src/os/error_haiku.cpp
new file mode 100644
index 0000000..22875de
--- /dev/null
+++ b/src/os/error_haiku.cpp
@@ -0,0 +1,79 @@
+/** @file src/os/error_haiku.c System dependent error messages for Haiku. */
+
+#include <Alert.h>
+#include <AppFileInfo.h>
+#include <Application.h>
+#include <File.h>
+#include <image.h>
+
+extern "C" {
+
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+#include "strings.h"
+
+#include "error.h"
+
+static void AppInit(void) {
+ image_info info;
+ int32 cookie = 0;
+ while (get_next_image_info(B_CURRENT_TEAM, &cookie, &info) == B_OK) {
+ if (info.type == B_APP_IMAGE) {
+ BFile me(info.name, O_RDONLY);
+ if (me.InitCheck() == B_OK) {
+ BAppFileInfo app_info(&me);
+ if (app_info.InitCheck() == B_OK) {
+ char signature[B_MIME_TYPE_LENGTH];
+ if (app_info.GetSignature(signature) == B_OK) {
+ new BApplication(signature);
+ return;
+ }
+ }
+ }
+ }
+ }
+ new BApplication("application/x-vnd.opendune");
+}
+
+void Error(const char *format, ...) {
+ char message[512];
+ va_list ap;
+
+ va_start(ap, format);
+ vsnprintf(message, sizeof(message), format, ap);
+ vfprintf(stderr, format, ap);
+ va_end(ap);
+
+ // Some checks are done before initializing SDL, so we may not have SDL
+ // nor a BApplication to show the alert
+ if (be_app == NULL) {
+ AppInit();
+ }
+ BAlert* alert = new BAlert("Error - OpenDUNE", message, "OK", NULL, NULL,
+ B_WIDTH_AS_USUAL, B_STOP_ALERT);
+ alert->SetShortcut(0, B_ESCAPE);
+ alert->Go();
+}
+
+void Warning(const char *format, ...) {
+ char message[512];
+ va_list ap;
+
+ va_start(ap, format);
+ vsnprintf(message, sizeof(message), format, ap);
+ vfprintf(stderr, format, ap);
+ va_end(ap);
+}
+
+#ifdef _DEBUG
+void Debug(const char *format, ...) {
+ va_list ap;
+
+ va_start(ap, format);
+ vfprintf(stdout, format, ap);
+ va_end(ap);
+}
+#endif
+
+}
--
2.28.0
From ace9f930ce398bd23fa5977c82885941855e0d19 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?M=C3=A1ximo=20Casta=C3=B1eda?= <antiswen@yahoo.es>
Date: Fri, 30 Oct 2020 12:42:28 +0100
Subject: snooze-based timer loop
Couldn't make the volatile counter in the SIGALRM handler work as it's
supposed to. May be due to bad assumptions, bad code, bad compiler or
a multitude of reasons. So just ditch it and use snooze and system_time.
It's smooth now and doesn't hog the CPU.
diff --git a/src/timer.c b/src/timer.c
index bd35a4b..85de1d6 100644
--- a/src/timer.c
+++ b/src/timer.c
@@ -16,6 +16,8 @@
#include <mint/sysvars.h>
#elif defined(__WATCOMC__)
#include <time.h>
+#elif defined(__HAIKU__)
+ #include <OS.h>
#else
/* Linux / Mac OS X / etc. */
#if !defined(__USE_POSIX)
@@ -52,7 +54,7 @@ typedef struct TimerNode {
static HANDLE s_timerMainThread = NULL;
static HANDLE s_timerThread = NULL;
static int s_timerTime;
-#elif !defined(TOS) && !defined(DOS)
+#elif !defined(TOS) && !defined(DOS) && !defined(__HAIKU__)
static struct itimerval s_timerTime;
#endif /* _WIN32 */
@@ -137,6 +139,24 @@ void SleepAndProcessBackgroundTasks(void)
Timer_InterruptRun(0);
}
+#elif defined(__HAIKU__)
+void SleepAndProcessBackgroundTasks(void)
+{
+ static bigtime_t next_trigger = 0;
+ if (next_trigger == 0) next_trigger = system_time();
+
+ while (snooze_until(next_trigger, B_SYSTEM_TIMEBASE) != B_OK)
+ /* We were interrupted, snooze again */
+ ;
+
+ int dont_callonce = 0;
+ do {
+ next_trigger += s_timerSpeed;
+ Timer_InterruptRun(dont_callonce);
+ dont_callonce = 1;
+ } while (system_time() - next_trigger > 0);
+}
+
#elif !defined(_WIN32) || defined(WITH_SDL) || defined(WITH_SDL2)
#if defined(_WIN32)
static volatile int s_timer_count = 0;
@@ -195,7 +215,7 @@ void CALLBACK Timer_InterruptWindows(LPVOID arg, BOOLEAN TimerOrWaitFired) {
}
#endif /* _WIN32 */
-#if !defined(TOS) && !defined(DOS)
+#if !defined(TOS) && !defined(DOS) && !defined(__HAIKU__)
/**
* Suspend the timer interrupt handling.
@@ -241,7 +261,7 @@ void Timer_Init(void)
#if 0
Xbtimer(0/* Timer A */, 1/* divider = 4 */, s_timerSpeed * 6144 / 10000, Timer_Handler);
#endif
-#elif defined(DOS)
+#elif defined(DOS) || defined(__HAIKU__)
/* */
#else
s_timerTime.it_value.tv_sec = 0;
@@ -258,7 +278,7 @@ void Timer_Init(void)
sigaction(SIGALRM, &timerSignal, NULL);
}
#endif /* _WIN32 */
-#if !defined(TOS) && !defined(DOS)
+#if !defined(TOS) && !defined(DOS) && !defined(__HAIKU__)
Timer_InterruptResume();
#endif /* !defined(TOS) && !defined(DOS) */
}
@@ -268,7 +288,7 @@ void Timer_Init(void)
*/
void Timer_Uninit(void)
{
-#if !defined(TOS) && !defined(DOS)
+#if !defined(TOS) && !defined(DOS) && !defined(__HAIKU__)
Timer_InterruptSuspend();
#endif /* !defined(TOS) && !defined(DOS) */
#if defined(_WIN32)
--
2.28.0
From d247964aaa7932e8d02340878fae54bf4deda3af Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?M=C3=A1ximo=20Casta=C3=B1eda?= <antiswen@yahoo.es>
Date: Sun, 1 Nov 2020 16:26:50 +0100
Subject: Add sound
For some reason my system, SDL or whatever does not like U8 format.
Change to a format that does produce sound, use the existing conversion for the frequency, as the SDL function only converts for integer (and maybe only powers of two) relations, and let SDL convert the format.
diff --git a/src/audio/dsp_sdl.c b/src/audio/dsp_sdl.c
index 0b1004e..9b0b8f2 100644
--- a/src/audio/dsp_sdl.c
+++ b/src/audio/dsp_sdl.c
@@ -22,7 +22,7 @@ static void DSP_Callback(void *userdata, Uint8 *stream, int len)
if (s_status == 0 || s_bufferLen == 0 || s_buffer == NULL) {
/* no more sample to play : */
- memset(stream, 0x80, len); /* fill buffer with silence */
+ memset(stream, s_spec.silence, len); /* fill buffer with silence */
SDL_PauseAudio(1); /* stop playback */
return;
}
@@ -33,7 +33,7 @@ static void DSP_Callback(void *userdata, Uint8 *stream, int len)
s_buffer += len;
} else {
memcpy(stream, s_buffer, s_bufferLen);
- memset(stream + s_bufferLen, 0x80, len - s_bufferLen); /* fill buffer end with silence */
+ memset(stream + s_bufferLen, s_spec.silence, len - s_bufferLen); /* fill buffer end with silence */
s_bufferLen = 0;
s_buffer = NULL;
s_status = 0;
@@ -66,8 +66,8 @@ bool DSP_Init(void)
{
if (SDL_InitSubSystem(SDL_INIT_AUDIO) != 0) return false;
- s_spec.freq = 22050;
- s_spec.format = AUDIO_U8;
+ s_spec.freq = 44100;
+ s_spec.format = AUDIO_S16;
s_spec.channels = 1;
s_spec.samples = 512;
s_spec.callback = DSP_Callback;
@@ -126,10 +126,29 @@ static void DSP_ConvertAudio(uint32 freq)
s_bufferLen = newlen;
}
+static void DSP_ReConvertAudio()
+{
+ SDL_AudioCVT cvt;
+ if (!SDL_BuildAudioCVT(&cvt, AUDIO_U8, 1, s_spec.freq, s_spec.format, s_spec.channels, s_spec.freq)) {
+ printf("BACVT ERROR\n");
+ }
+ uint32 newlen = s_bufferLen * cvt.len_mult;
+
+ if (s_dataLen < newlen) {
+ s_data = realloc(s_data, newlen);
+ s_dataLen = newlen;
+ }
+
+ cvt.buf = s_data;
+ cvt.len = s_bufferLen;
+
+ SDL_ConvertAudio(&cvt);
+ s_bufferLen = cvt.len_cvt;
+}
+
void DSP_Play(const uint8 *data)
{
DSP_Stop();
-
data += READ_LE_UINT16(data + 20);
if (*data != 1) return;
@@ -143,6 +162,7 @@ void DSP_Play(const uint8 *data)
memcpy(s_data, data + 6, s_bufferLen);
DSP_ConvertAudio(1000000 / (256 - data[4]));
+ DSP_ReConvertAudio();
s_buffer = s_data;
s_status = 2;
--
2.28.0
From 91b8cc6cc5373dc42e1624f7c1e90a4c2e7102eb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?M=C3=A1ximo=20Casta=C3=B1eda?= <antiswen@yahoo.es>
Date: Mon, 2 Nov 2020 12:43:36 +0100
Subject: Add MIDI music
diff --git a/source.list b/source.list
index f6aa25c..7bf42da 100644
--- a/source.list
+++ b/source.list
@@ -46,7 +46,11 @@ audio/midi_atari.c
#if OSX
audio/midi_osx.c
#else
- audio/midi_none.c
+ #if HAIKU
+ audio/midi_haiku.cpp
+ #else
+ audio/midi_none.c
+ #endif
#endif
#endif
#endif
diff --git a/src/audio/midi_haiku.cpp b/src/audio/midi_haiku.cpp
new file mode 100644
index 0000000..a2c678f
--- /dev/null
+++ b/src/audio/midi_haiku.cpp
@@ -0,0 +1,110 @@
+#include <midi/MidiSynth.h>
+
+extern "C" {
+#include "midi.h"
+#include "../os/error.h"
+
+static BMidiSynth *s_synth = NULL;
+
+bool midi_init(void)
+{
+ s_synth = new BMidiSynth();
+ if (s_synth == NULL) {
+ midi_uninit();
+ return false;
+ }
+ if (s_synth->EnableInput(true, true) != B_OK || !s_synth->IsInputEnabled()) {
+ midi_uninit();
+ return false;
+ }
+ return true;
+}
+
+void midi_uninit(void)
+{
+ delete s_synth;
+ s_synth = NULL;
+}
+
+void midi_send(uint32 data)
+{
+ if (s_synth == NULL) return;
+
+ uchar byte1 = data & 0xFF;
+ uchar byte2 = (data >> 8) & 0xFF;
+ uchar byte3 = (data >> 16) & 0xFF;
+ uchar channel = (byte1 & 0x0F) + 1;
+
+ switch (byte1 & 0xF0) {
+ case B_NOTE_OFF:
+ s_synth->NoteOff(channel, byte2, byte3);
+ return;
+
+ case B_NOTE_ON:
+ s_synth->NoteOn(channel, byte2, byte3);
+ return;
+
+ case B_KEY_PRESSURE:
+ s_synth->KeyPressure(channel, byte2, byte3);
+ return;
+
+ case B_CONTROL_CHANGE:
+ s_synth->ControlChange(channel, byte2, byte3);
+ return;
+
+ case B_PROGRAM_CHANGE:
+ s_synth->ProgramChange(channel, byte2);
+ return;
+
+ case B_CHANNEL_PRESSURE:
+ s_synth->ChannelPressure(channel, byte2);
+ return;
+
+ case B_PITCH_BEND:
+ s_synth->PitchBend(channel, byte2, byte3);
+ return;
+
+ case 0xF0:
+ switch (byte1) {
+ case B_SYS_EX_START:
+ /* We don't do this here */
+ Warning("Sysex MIDI through midi_send(%u)\n", data);
+ return;
+
+ case B_MIDI_TIME_CODE:
+ case B_SONG_POSITION:
+ case B_SONG_SELECT:
+ case B_CABLE_MESSAGE:
+ case B_TUNE_REQUEST:
+ case B_SYS_EX_END:
+ s_synth->SystemCommon(byte1, byte2, byte3);
+ return;
+
+ case B_TIMING_CLOCK:
+ case B_START:
+ case B_CONTINUE:
+ case B_STOP:
+ case B_ACTIVE_SENSING:
+ case B_SYSTEM_RESET:
+ s_synth->SystemRealTime(byte1);
+ return;
+
+ }
+ return;
+ }
+}
+
+uint16 midi_send_string(const uint8 * data, uint16 len)
+{
+ if (s_synth == NULL) return len;
+
+ /* This is only used for sysex messages */
+ s_synth->SystemExclusive((void *)data, len, true);
+ return len;
+}
+
+void midi_reset(void)
+{
+}
+
+}
--
2.28.0