ports/doom: Use SDL2 instead of our own frontend

This allows doom to play sounds!
This commit is contained in:
Bananymous 2025-08-06 18:26:36 +03:00
parent 6250710bbd
commit 2f725848f4
6 changed files with 58 additions and 310 deletions

View File

@ -2,20 +2,22 @@
NAME='doom' NAME='doom'
VERSION='git' VERSION='git'
DOWNLOAD_URL="https://github.com/ozkl/doomgeneric.git#613f870b6fa83ede448a247de5a2571092fa729d" DOWNLOAD_URL="https://github.com/ozkl/doomgeneric.git#5041246e859052e2e258ca6edb4e1e9bbd98fcf5"
DEPENDENCIES=('SDL2' 'SDL2_mixer' 'timidity')
configure() { configure() {
make --directory doomgeneric clean rm -rf doomgeneric/build
} }
build() { build() {
if [ ! -f ../doom1.wad ]; then if [ ! -f ../doom1.wad ]; then
wget https://distro.ibiblio.org/slitaz/sources/packages/d/doom1.wad -O ../doom1.wad || exit 1 wget https://distro.ibiblio.org/slitaz/sources/packages/d/doom1.wad -O ../doom1.wad || exit 1
fi fi
make --directory doomgeneric --file Makefile.banan_os -j$(nproc) || exit 1
CFLAGS='-std=c11' make --directory doomgeneric --file Makefile.sdl CC="$CC" SDL_PATH="$BANAN_SYSROOT/usr/bin/" || exit 1
} }
install() { install() {
cp doomgeneric/build/doom "${BANAN_SYSROOT}/bin/" || exit 1 cp doomgeneric/doomgeneric "${BANAN_SYSROOT}/bin/doom" || exit 1
cp ../doom1.wad "$BANAN_SYSROOT/home/user/" || exit 1 cp ../doom1.wad "$BANAN_SYSROOT/home/user/" || exit 1
} }

View File

@ -1,224 +0,0 @@
From 0f37d9f2df042eb8ba021dd91b898c1f07d86b58 Mon Sep 17 00:00:00 2001
From: Bananymous <bananymousosq@gmail.com>
Date: Fri, 18 Oct 2024 03:44:10 +0300
Subject: [PATCH] Add support for banan-os
---
doomgeneric/Makefile.banan_os | 57 +++++++++++
doomgeneric/doomgeneric_banan_os.cpp | 138 +++++++++++++++++++++++++++
2 files changed, 200 insertions(+)
create mode 100644 doomgeneric/Makefile.banan_os
create mode 100644 doomgeneric/doomgeneric_banan_os.cpp
diff --git a/doomgeneric/Makefile.banan_os b/doomgeneric/Makefile.banan_os
new file mode 100644
index 0000000..0878148
--- /dev/null
+++ b/doomgeneric/Makefile.banan_os
@@ -0,0 +1,57 @@
+################################################################
+#
+# $Id:$
+#
+# $Log:$
+#
+
+ifeq ($(V),1)
+ VB=''
+else
+ VB=@
+endif
+
+CC=$(BANAN_ARCH)-pc-banan_os-gcc
+CXX=$(BANAN_ARCH)-pc-banan_os-g++
+CFLAGS+=-O3 -std=c11 -Wall -DNORMALUNIX -DLINUX -DSNDSERV -D_DEFAULT_SOURCE
+CXXFLAGS+=$(CFLAGS) --std=c++20
+LDFLAGS+=
+LIBS+=-lgui -linput -lstdc++
+
+# subdirectory for objects
+OBJDIR=build
+OUTPUT=$(OBJDIR)/doom
+
+SRC_DOOM = dummy.o am_map.o doomdef.o doomstat.o dstrings.o d_event.o d_items.o d_iwad.o d_loop.o d_main.o d_mode.o d_net.o f_finale.o f_wipe.o g_game.o hu_lib.o hu_stuff.o info.o i_cdmus.o i_endoom.o i_joystick.o i_scale.o i_sound.o i_system.o i_timer.o memio.o m_argv.o m_bbox.o m_cheat.o m_config.o m_controls.o m_fixed.o m_menu.o m_misc.o m_random.o p_ceilng.o p_doors.o p_enemy.o p_floor.o p_inter.o p_lights.o p_map.o p_maputl.o p_mobj.o p_plats.o p_pspr.o p_saveg.o p_setup.o p_sight.o p_spec.o p_switch.o p_telept.o p_tick.o p_user.o r_bsp.o r_data.o r_draw.o r_main.o r_plane.o r_segs.o r_sky.o r_things.o sha1.o sounds.o statdump.o st_lib.o st_stuff.o s_sound.o tables.o v_video.o wi_stuff.o w_checksum.o w_file.o w_main.o w_wad.o z_zone.o w_file_stdc.o i_input.o i_video.o doomgeneric.o doomgeneric_banan_os.o
+OBJS += $(addprefix $(OBJDIR)/, $(SRC_DOOM))
+
+all: $(OUTPUT)
+
+clean:
+ rm -rf $(OBJDIR)
+ rm -f $(OUTPUT)
+ rm -f $(OUTPUT).gdb
+ rm -f $(OUTPUT).map
+
+$(OUTPUT): $(OBJS)
+ @echo [Linking $@]
+ $(VB)$(CC) $(CFLAGS) $(LDFLAGS) $(OBJS) \
+ -o $(OUTPUT) $(LIBS) -Wl,-Map,$(OUTPUT).map
+ @echo [Size]
+ -$(CROSS_COMPILE)size $(OUTPUT)
+
+$(OBJS): | $(OBJDIR)
+
+$(OBJDIR):
+ mkdir -p $(OBJDIR)
+
+$(OBJDIR)/%.o: %.c
+ @echo [Compiling $<]
+ $(VB)$(CC) $(CFLAGS) -c $< -o $@
+
+$(OBJDIR)/%.o: %.cpp
+ @echo [Compiling $<]
+ $(VB)$(CXX) $(CXXFLAGS) -c $< -o $@
+
+print:
+ @echo OBJS: $(OBJS)
\ No newline at end of file
diff --git a/doomgeneric/doomgeneric_banan_os.cpp b/doomgeneric/doomgeneric_banan_os.cpp
new file mode 100644
index 0000000..9161771
--- /dev/null
+++ b/doomgeneric/doomgeneric_banan_os.cpp
@@ -0,0 +1,139 @@
+extern "C"
+{
+#include "doomgeneric.h"
+#include "doomkeys.h"
+}
+
+#include <assert.h>
+#include <ctype.h>
+#include <fcntl.h>
+#include <stdint.h>
+#include <string.h>
+#include <sys/banan-os.h>
+#include <sys/framebuffer.h>
+#include <sys/mman.h>
+#include <time.h>
+
+#include <LibGUI/Window.h>
+
+#define MIN(a, b) ((a) < (b) ? (a) : (b))
+
+static BAN::UniqPtr<LibGUI::Window> s_window;
+
+static constexpr size_t s_key_queue_size = 16;
+static unsigned short s_key_queue[s_key_queue_size];
+static size_t s_key_read_index = 0;
+static size_t s_key_write_index = 0;
+
+extern "C"
+{
+
+void DG_Init()
+{
+ s_window = MUST(LibGUI::Window::create(DOOMGENERIC_RESX, DOOMGENERIC_RESY, "DOOM"_sv));
+ s_window->set_key_event_callback(
+ [](LibGUI::EventPacket::KeyEvent::event_t event)
+ {
+ unsigned short doom_key = 0;
+ switch (event.key)
+ {
+ case LibInput::Key::Enter:
+ doom_key = KEY_ENTER;
+ break;
+ case LibInput::Key::Escape:
+ doom_key = KEY_ESCAPE;
+ break;
+ case LibInput::Key::ArrowLeft:
+ doom_key = KEY_LEFTARROW;
+ break;
+ case LibInput::Key::ArrowUp:
+ doom_key = KEY_UPARROW;
+ break;
+ case LibInput::Key::ArrowRight:
+ doom_key = KEY_RIGHTARROW;
+ break;
+ case LibInput::Key::ArrowDown:
+ doom_key = KEY_DOWNARROW;
+ break;
+ case LibInput::Key::LeftCtrl:
+ case LibInput::Key::RightCtrl:
+ doom_key = KEY_FIRE;
+ break;
+ case LibInput::Key::Space:
+ doom_key = KEY_USE;
+ break;
+ case LibInput::Key::RightShift:
+ doom_key = KEY_RSHIFT;
+ break;
+ default:
+ {
+ const char* utf8 = LibInput::key_to_utf8(event.key, event.modifier);
+ if (utf8 && strlen(utf8) == 1 && isalpha(*utf8))
+ doom_key = tolower(*utf8);
+ }
+ }
+
+ if (doom_key == 0)
+ return;
+
+ s_key_queue[s_key_write_index] = doom_key | (int)event.pressed() << 8;
+ s_key_write_index = (s_key_write_index + 1) % s_key_queue_size;
+ }
+ );
+}
+
+void DG_DrawFrame()
+{
+ auto& texture = s_window->texture();
+ for (size_t y = 0; y < DOOMGENERIC_RESY; y++)
+ for (size_t x = 0; x < DOOMGENERIC_RESX; x++)
+ texture.set_pixel(x, y, 0xFF000000 | DG_ScreenBuffer[y * DOOMGENERIC_RESX + x]);
+ s_window->invalidate();
+ s_window->poll_events();
+}
+
+void DG_SleepMs(uint32_t ms)
+{
+ struct timespec ts;
+ ts.tv_sec = ms / 1000;
+ ts.tv_nsec = (ms % 1000) * 1000000;
+ nanosleep(&ts, NULL);
+}
+
+uint32_t DG_GetTicksMs()
+{
+ struct timespec ts;
+ clock_gettime(CLOCK_MONOTONIC, &ts);
+ return (ts.tv_sec * 1000) + (ts.tv_nsec / 1000000);
+}
+
+int DG_GetKey(int* pressed, unsigned char* doomKey)
+{
+ if (s_key_read_index == s_key_write_index)
+ return 0;
+
+ unsigned short key_data = s_key_queue[s_key_read_index];
+ s_key_read_index = (s_key_read_index + 1) % s_key_queue_size;
+
+ *pressed = key_data >> 8;
+ *doomKey = key_data & 0xFF;
+
+ return 1;
+}
+
+void DG_SetWindowTitle(const char* title)
+{
+ (void)title;
+}
+
+int main(int argc, char** argv)
+{
+ doomgeneric_Create(argc, argv);
+
+ for (;;)
+ doomgeneric_Tick();
+
+ return 0;
+}
+
+}
--
2.45.2

View File

@ -0,0 +1,27 @@
From a4e6b807885a7cb4a507b4e114743aa0004376ad Mon Sep 17 00:00:00 2001
From: Oskari Alaranta <oskari.alaranta@bananymous.com>
Date: Sun, 10 Aug 2025 01:57:38 +0300
Subject: [PATCH] add support for custom SDL path
---
doomgeneric/Makefile.sdl | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/doomgeneric/Makefile.sdl b/doomgeneric/Makefile.sdl
index 38402da..8c2f84e 100644
--- a/doomgeneric/Makefile.sdl
+++ b/doomgeneric/Makefile.sdl
@@ -12,8 +12,8 @@ else
endif
-SDL_CFLAGS = `sdl2-config --cflags`
-SDL_LIBS = `sdl2-config --cflags --libs` -lSDL2_mixer
+SDL_CFLAGS = `$(SDL_PATH)sdl2-config --cflags`
+SDL_LIBS = `$(SDL_PATH)sdl2-config --cflags --libs` -lSDL2_mixer
CC=clang # gcc or g++
--
2.50.1

View File

@ -1,34 +0,0 @@
From c28fd460c15a3d4cc5aac35d1ea5744f1722cab4 Mon Sep 17 00:00:00 2001
From: Bananymous <bananymousosq@gmail.com>
Date: Wed, 3 Apr 2024 21:39:22 +0300
Subject: [PATCH] Call exit() on I_Quit() and I_Error()
---
doomgeneric/i_system.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/doomgeneric/i_system.c b/doomgeneric/i_system.c
index 5d00091..bfb204f 100644
--- a/doomgeneric/i_system.c
+++ b/doomgeneric/i_system.c
@@ -257,6 +257,8 @@ void I_Quit (void)
entry = entry->next;
}
+ exit(0);
+
#if ORIGCODE
SDL_Quit();
@@ -403,6 +405,8 @@ void I_Error (char *error, ...)
entry = entry->next;
}
+ exit(1);
+
exit_gui_popup = !M_ParmExists("-nogui");
// Pop up a GUI dialog box to show the error message, if the
--
2.47.1

View File

@ -0,0 +1,25 @@
From fd5308b45021ca18e7703d810e2e2ba86c174669 Mon Sep 17 00:00:00 2001
From: Oskari Alaranta <oskari.alaranta@bananymous.com>
Date: Sun, 10 Aug 2025 01:56:26 +0300
Subject: [PATCH] set timidity config path
---
doomgeneric/i_sdlmusic.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/doomgeneric/i_sdlmusic.c b/doomgeneric/i_sdlmusic.c
index f56392f..80b9021 100644
--- a/doomgeneric/i_sdlmusic.c
+++ b/doomgeneric/i_sdlmusic.c
@@ -110,7 +110,7 @@ static boolean sdl_was_initialized = false;
static boolean musicpaused = false;
static int current_music_volume;
-char *timidity_cfg_path = "";
+char *timidity_cfg_path = "/etc/timidity.cfg";
static char *temp_timidity_cfg = NULL;
--
2.50.1

View File

@ -1,48 +0,0 @@
From 70c235938f0b64c4f08a478d3107e5254ad904c6 Mon Sep 17 00:00:00 2001
From: Bananymous <bananymousosq@gmail.com>
Date: Wed, 27 Nov 2024 13:28:42 +0200
Subject: [PATCH] Remove unnecessary copy from framebuffer
---
doomgeneric/doomgeneric.c | 2 --
doomgeneric/doomgeneric_banan_os.cpp | 6 +++---
2 files changed, 3 insertions(+), 5 deletions(-)
diff --git a/doomgeneric/doomgeneric.c b/doomgeneric/doomgeneric.c
index 782a7e7..f4eb63e 100644
--- a/doomgeneric/doomgeneric.c
+++ b/doomgeneric/doomgeneric.c
@@ -18,8 +18,6 @@ void doomgeneric_Create(int argc, char **argv)
M_FindResponseFile();
- DG_ScreenBuffer = malloc(DOOMGENERIC_RESX * DOOMGENERIC_RESY * 4);
-
DG_Init();
D_DoomMain ();
diff --git a/doomgeneric/doomgeneric_banan_os.cpp b/doomgeneric/doomgeneric_banan_os.cpp
index d00c30d..9d13b43 100644
--- a/doomgeneric/doomgeneric_banan_os.cpp
+++ b/doomgeneric/doomgeneric_banan_os.cpp
@@ -80,14 +80,13 @@ void DG_Init()
s_key_write_index = (s_key_write_index + 1) % s_key_queue_size;
}
);
+
+ ASSERT(DG_ScreenBuffer == nullptr);
+ DG_ScreenBuffer = s_window->texture().pixels().data();
}
void DG_DrawFrame()
{
- auto& texture = s_window->texture();
- for (size_t y = 0; y < DOOMGENERIC_RESY; y++)
- for (size_t x = 0; x < DOOMGENERIC_RESX; x++)
- texture.set_pixel(x, y, 0xFF000000 | DG_ScreenBuffer[y * DOOMGENERIC_RESX + x]);
s_window->invalidate();
s_window->poll_events();
}
--
2.47.1