From a8ecd677edc2d3a83939d4a749710762eca944f0 Mon Sep 17 00:00:00 2001
From: Anders Jenbo <[EMAIL REDACTED]>
Date: Fri, 24 Apr 2026 01:54:49 +0200
Subject: [PATCH] Add DOS platform support (DJGPP) (#15377)
* dos: Some initial work.
* dos: Turn off buffer on stdio SDL_IOStreams.
Seeking breaks otherwise. We might be able to just fflush() before or seeking
instead?
* dos: Audio implementation using the Sound Blaster 16.
* dos: remove audio Pump interface.
Turns out DosBox-X was having trouble with the Sound Blaster or something;
standard DosBox works correctly directly from the interrupt handler, and
without doubling the buffer size.
* dos: just dump and restore the stdio buffer when seeking.
This is MUCH faster than just leaving buffering disabled, and also works
around getting bogus reads after an fseek. SDL_LoadWAV on test/sample.wav
no longer takes several seconds to finish, and comes up with the correct
data.
I wonder if we're triggering this in LoadWAV because we're malloc'ing data
between seeks/reads, and it's causing the djgpp transfer buffer to change. Or
maybe the Fat DS trick is confusing it? I don't know, I haven't had time to
debug it, it might just be a legit libc bug in djgpp too, for all I know.
* dos: Protect audio device "thread" iterations when streams are locked.
This uses an old trick we used in SDL 1.2 for MacOS Classic, which did its
audio callback in a hardware interrupt. If the audio is locked when the
interrupt fires, make a note of it and return immediately. When the lock is
released, if the interrupt has been fired, run the audio device iteration
right then.
Since there isn't a big device lock in SDL3 (available to the app, at least),
this keeps a counter of when any SDL_AudioStream is locked, which is probably
good enough.
* dos: Implemented initial video subsystem.
This uses VESA interfaces to manage the display and works with the software
renderer.
Events aren't hooked up yet, so prepare to close DosBox on each run. :)
* dos: Whoops, forgot to add these to revision control. Core and Main support.
* dos: Wired up basic filesystem support.
This gets most of the rendering examples, which use SDL_GetBasePath() to
find textures to load, working.
* dos: Fixed compiler warning.
* dos: Initial mouse support!
* dos: Move interrupt hooking code into core/dos.
* dos: Initial keyboard support!
* dos: Use a simple ring buffer for keyboard events.
Of course Quake 1 solved this better, haha. It's smart: less memory, dirt
simple, and you don't even have to worry about synchronizing with the
interrupt handler, because it's safe for both sides no matter when an
interrupt fires.
* ci: add djgpp job
[sdl-ci-filter djgpp]
[sdl-ci-artifacts]
* dos: Fix build issues after rebase onto current main
- SDL_runapp.c: Add SDL_PLATFORM_DOS to the exclusion list so the
generic
SDL_RunApp() is disabled when the DOS-specific one is compiled.
- SDL.c: Exclude SDL_Gtk_Quit() on DOS. DJGPP defines __unix__ which
sets
SDL_PLATFORM_UNIX, but DOS has no GTK/display server. The GTK source
is not compiled (CMake UNIX is false for DOS) so this was a link
error.
- sdlplatform.cmake: Add DOS case to SDL_DetectCMakePlatform so the
platform is properly detected from CMAKE_SYSTEM_NAME=DOS.
- i586-pc-msdosdjgpp.cmake: Add i386-pc-msdosdjgpp-gcc as a fallback
compiler name, since some DJGPP toolchain builds use the i386 prefix.
* Add 8-bit palette support to DOS VESA driver
* Add VBE page-flipping, state restore, and robust keyboard handling
- Implement double-buffered page-flipping for VBE modes with >1 image
page
- Save and restore full VBE state on video init/quit for clean mode
switching
- Improve DOS keyboard handling: support extended scancodes and Pause
key
- Lock ISR code/data to prevent page faults during interrupts
- Always vsync when blitting in single-buffered modes to reduce tearing
* Refactor Sound Blaster audio mixing to main loop
Move audio mixing out of IRQ handler to main loop for improved
stability and to avoid reentrancy issues. Add SDL_DOS_PumpAudio
function, update DMA buffer handling, and adjust sample rate to 22050
Hz.
Silence stale DMA buffer halves to prevent stutter during load.
* Add DOS timer support and update build config
* Add support for pre-SB16 8-bit mono Sound Blaster audio
Detect SB version and select 8-bit mono or 16-bit stereo mode.
Handle DMA and DSP setup for both SB16 and pre-SB16 hardware.
Add FORCE_SB_8BIT option for testing in DOSBox.
* Add SB Pro stereo support and simplify IRQ handler
* Add DOS joystick driver support
* Improve DOS hardware handling and clarify memory allocation
- Poll Sound Blaster DSP status instead of fixed delay after speaker-on
- Clarify DPMI conventional memory is always locked; update comments
- Document and justify DMA memory allocation strategy
- Free IRET wrapper after restoring interrupt vector to avoid leaks
- Throttle joystick axis polling to ~60 Hz to reduce BIOS timing loop
cost
- Always poll joystick buttons directly for responsiveness
* Query and use mouse sensitivity from INT 33h function 0x1B
* Add support for VESA banked framebuffer modes
Implement banked framebuffer access for VBE 1.2+ modes without LFB.
Detect and initialize banked modes, copy framebuffer data using bank
switching, and blank the framebuffer on mode set. Page-flipping is
disabled in banked mode.
* Add optional vsync to page flipping in DOS VESA driver
* Add cooperative threading support for DOS platform
* Move SoundBlaster audio mixing to SDL audio thread
* Fix DOS platform comments and workarounds for DJGPP support
* Fix SoundBlaster IRQ handling and DMA setup for DOS
- Pass IRQ number to DOS_EndOfInterrupt and handle slave PIC EOI
- Validate DMA channel from BLASTER variable
- Correct DMA page register selection for SB16
- Improve BLASTER variable parsing and error messages
- Unmask/mask IRQs on correct PIC in DOS_HookInterrupt
- Rename SDL_dosjoystick.c to SDL_sysjoystick.c
- Include SDL_main_callbacks.h in SDL_sysmain_runapp.c
- Add include guard to SDL_systhread_c.h
* Add DOS platform options and preseed cache for DJGPP
Disable unsupported SDL features when building for DOS. Add
PreseedDOSCache.cmake to pre-populate CMake cache variables for DJGPP.
* cmake: use a 8.3 naming scheme for tests on DOS
* Apply code style
* Update include/SDL3/SDL_platform_defines.h
Co-authored-by: Anonymous Maarten <madebr@users.noreply.github.com>
* Code review clean up
- Split DOS VESA mode-setting into its own file
- Replace magic numbers with named constants
- Update copyright dates to 2026
- Substract time taken by other threads form delays
* Fix DOS bugs and improve compatibility
- Disable fseeko64 for DJGPP due to broken implementation
- Refactor DOS timer delay to always yield and avoid busy-waiting
- Fix animated cursor rendering in DOS VESA backend
- Always set display mode when creating DOS VESA window
- Work around DJGPP allowing invalid file access in testfile.c
- Bump max threads to 16
- Apply workarounds for threading tests
* Add DOS platform documentation and fix a few issues
- Fix fullscreen default resolution
- Improve best mode matching
- Fix builds on GCC older than 7.0
- Fix text input events
* Fix keyboard mapping of "*"
* Fix running, and existing, under PCem
* Apply suggestions from code review
Co-authored-by: Cameron Cawley <ccawley2011@gmail.com>
* Pre-mix audio in ring buffer and copy to DMA via IRQ thread
* Video fixes and optimizations
* DOS: Fix Intel 740 and VGA compatability
* DOS: Update readme
* DOS: Fix thread ID, get GPU name
* DOS: Cap mouse range
* DOS: Map test resources to 8.3 names
* DOS: Skip unsupported WM color modes
* Fix "windowed" resolution selection
* DOS: Hide INDEX8 modes behind SDL_DOS_ALLOW_INDEX8_MODES
* Remove SDL_HINT_DOS_ALLOW_INDEX8_MODES and order modes logically
* Don't convert cursor if dest is not INDEX8
---------
Co-authored-by: Ryan C. Gordon <icculus@icculus.org>
Co-authored-by: Anonymous Maarten <anonymous.maarten@gmail.com>
Co-authored-by: Cameron Cawley <ccawley2011@gmail.com>
Co-authored-by: Gleb Mazovetskiy <glex.spb@gmail.com>
Co-authored-by: Jay Petacat <jay@jayschwa.net>
Tested-by: Cameron Cawley <ccawley2011@gmail.com>
---
.../actions/setup-djgpp-toolchain/action.yml | 66 ++
.github/workflows/create-test-plan.py | 16 +
.github/workflows/generic.yml | 4 +
CMakeLists.txt | 65 +-
build-scripts/djgpp-platform-overrides.cmake | 17 +
build-scripts/i586-pc-msdosdjgpp.cmake | 82 ++
cmake/PreseedDOSCache.cmake | 208 ++++
cmake/macros.cmake | 2 +-
cmake/sdlplatform.cmake | 2 +
docs/README-dos.md | 90 ++
include/SDL3/SDL_hints.h | 17 +
include/SDL3/SDL_main.h | 13 +
include/SDL3/SDL_platform_defines.h | 10 +
include/build_config/SDL_build_config.h.cmake | 7 +-
src/SDL.c | 2 +
src/audio/SDL_audio.c | 3 +
src/audio/SDL_sysaudio.h | 1 +
src/audio/dos/SDL_dosaudio_sb.c | 631 ++++++++++++
src/audio/dos/SDL_dosaudio_sb.h | 47 +
src/core/dos/SDL_dos.c | 142 +++
src/core/dos/SDL_dos.h | 156 +++
src/core/dos/SDL_dos_scheduler.c | 318 ++++++
src/core/dos/SDL_dos_scheduler.h | 107 ++
src/dynapi/SDL_dynapi.h | 2 +
src/filesystem/dos/SDL_sysfilesystem.c | 105 ++
src/joystick/SDL_joystick.c | 3 +
src/joystick/SDL_sysjoystick.h | 1 +
src/joystick/dos/SDL_sysjoystick.c | 342 +++++++
src/main/SDL_runapp.c | 3 +-
src/main/dos/SDL_sysmain_runapp.c | 51 +
src/stdlib/SDL_string.c | 2 +-
src/thread/SDL_thread_c.h | 2 +
src/thread/dos/SDL_sysmutex.c | 122 +++
src/thread/dos/SDL_syssem.c | 115 +++
src/thread/dos/SDL_systhread.c | 87 ++
src/thread/dos/SDL_systhread_c.h | 28 +
src/thread/dos/SDL_systls.c | 63 ++
src/time/unix/SDL_systime.c | 2 +
src/timer/dos/SDL_systimer.c | 70 ++
src/video/SDL_sysvideo.h | 1 +
src/video/SDL_video.c | 3 +
src/video/dos/SDL_dosevents.c | 397 +++++++
src/video/dos/SDL_dosevents_c.h | 31 +
src/video/dos/SDL_dosframebuffer.c | 969 ++++++++++++++++++
src/video/dos/SDL_dosframebuffer_c.h | 34 +
src/video/dos/SDL_dosmodes.c | 688 +++++++++++++
src/video/dos/SDL_dosmodes.h | 50 +
src/video/dos/SDL_dosmouse.c | 170 +++
src/video/dos/SDL_dosmouse.h | 39 +
src/video/dos/SDL_dosvideo.c | 356 +++++++
src/video/dos/SDL_dosvideo.h | 89 ++
test/CMakeLists.txt | 197 ++--
test/testfile.c | 8 +
test/testime.c | 4 +
test/testsem.c | 4 +
test/testutils.c | 55 +
test/testwm.c | 3 +
test/torturethread.c | 8 +-
58 files changed, 6013 insertions(+), 97 deletions(-)
create mode 100644 .github/actions/setup-djgpp-toolchain/action.yml
create mode 100644 build-scripts/djgpp-platform-overrides.cmake
create mode 100644 build-scripts/i586-pc-msdosdjgpp.cmake
create mode 100644 cmake/PreseedDOSCache.cmake
create mode 100644 docs/README-dos.md
create mode 100644 src/audio/dos/SDL_dosaudio_sb.c
create mode 100644 src/audio/dos/SDL_dosaudio_sb.h
create mode 100644 src/core/dos/SDL_dos.c
create mode 100644 src/core/dos/SDL_dos.h
create mode 100644 src/core/dos/SDL_dos_scheduler.c
create mode 100644 src/core/dos/SDL_dos_scheduler.h
create mode 100644 src/filesystem/dos/SDL_sysfilesystem.c
create mode 100644 src/joystick/dos/SDL_sysjoystick.c
create mode 100644 src/main/dos/SDL_sysmain_runapp.c
create mode 100644 src/thread/dos/SDL_sysmutex.c
create mode 100644 src/thread/dos/SDL_syssem.c
create mode 100644 src/thread/dos/SDL_systhread.c
create mode 100644 src/thread/dos/SDL_systhread_c.h
create mode 100644 src/thread/dos/SDL_systls.c
create mode 100644 src/timer/dos/SDL_systimer.c
create mode 100644 src/video/dos/SDL_dosevents.c
create mode 100644 src/video/dos/SDL_dosevents_c.h
create mode 100644 src/video/dos/SDL_dosframebuffer.c
create mode 100644 src/video/dos/SDL_dosframebuffer_c.h
create mode 100644 src/video/dos/SDL_dosmodes.c
create mode 100644 src/video/dos/SDL_dosmodes.h
create mode 100644 src/video/dos/SDL_dosmouse.c
create mode 100644 src/video/dos/SDL_dosmouse.h
create mode 100644 src/video/dos/SDL_dosvideo.c
create mode 100644 src/video/dos/SDL_dosvideo.h
diff --git a/.github/actions/setup-djgpp-toolchain/action.yml b/.github/actions/setup-djgpp-toolchain/action.yml
new file mode 100644
index 0000000000000..7b10dc8afb357
--- /dev/null
+++ b/.github/actions/setup-djgpp-toolchain/action.yml
@@ -0,0 +1,66 @@
+name: 'Setup DJGPP toolchain'
+description: 'Download DJGPP and setup CMake toolchain'
+runs:
+ using: 'composite'
+ steps:
+ - name: 'Calculate variables'
+ id: calc
+ shell: sh
+ run: |
+ version="12.2.0"
+ case "${{ runner.os }}-${{ runner.arch }}" in
+ "Linux-X86")
+ archive="djgpp-linux32-gcc1220.tar.bz2"
+ ;;
+ "Linux-X64")
+ archive="djgpp-linux64-gcc1220.tar.bz2"
+ ;;
+ "macOS-X86" | "macOS-X64" | "macOS-ARM64")
+ archive="djgpp-osx-gcc1220.tar.bz2"
+ ;;
+ "Windows-X86" | "Windows-X64")
+ archive="djgpp-mingw-gcc1220.zip"
+ ;;
+ *)
+ echo "Unsupported ${{ runner.os }}-${{ runner.arch }}"
+ exit 1;
+ ;;
+ esac
+ echo "url=https://github.com/andrewwutw/build-djgpp/releases/download/v3.4/${archive}" >> ${GITHUB_OUTPUT}
+ echo "archive=${archive}" >> ${GITHUB_OUTPUT}
+ echo "version=${version}" >> ${GITHUB_OUTPUT}
+ echo "cache-key=${archive}-${{ inputs.version }}-${{ runner.os }}-${{ runner.arch }}" >> ${GITHUB_OUTPUT}
+ - name: 'Restore cached ${{ steps.calc.outputs.archive }}'
+ id: cache-restore
+ uses: actions/cache/restore@v4
+ with:
+ path: '${{ runner.temp }}/${{ steps.calc.outputs.archive }}'
+ key: ${{ steps.calc.outputs.cache-key }}
+ - name: 'Download DJGPP ${{ steps.calc.outputs.version }} for ${{ runner.os }} (${{ runner.arch }})'
+ if: ${{ !steps.cache-restore.outputs.cache-hit || steps.cache-restore.outputs.cache-hit == 'false' }}
+ shell: pwsh
+ run: |
+ Invoke-WebRequest "${{ steps.calc.outputs.url }}" -OutFile "${{ runner.temp }}/${{ steps.calc.outputs.archive }}"
+ - name: 'Cache ${{ steps.calc.outputs.archive }}'
+ if: ${{ !steps.cache-restore.outputs.cache-hit || steps.cache-restore.outputs.cache-hit == 'false' }}
+ uses: actions/cache/save@v4
+ with:
+ path: '${{ runner.temp }}/${{ steps.calc.outputs.archive }}'
+ key: ${{ steps.calc.outputs.cache-key }}
+ - name: 'Extract DJGP archive'
+ shell: pwsh
+ run: |
+ $archive = "${{ steps.calc.outputs.archive }}";
+ if ($archive.EndsWith(".bz2")) {
+ # Remove ".bz2" suffix
+ $tar_archive = $archive.Substring(0, $archive.Length - 4)
+ 7z "-o${{ runner.temp }}" x "${{ runner.temp }}/${{ steps.calc.outputs.archive }}"
+ 7z "-o${{ runner.temp }}" x "${{ runner.temp }}/$tar_archive"
+ } else {
+ 7z "-o${{ runner.temp }}" x "${{ runner.temp }}/${{ steps.calc.outputs.archive }}"
+ }
+ - name: 'Set output variables'
+ id: final
+ shell: pwsh
+ run: |
+ echo "${{ runner.temp }}/djgpp/bin" >> $env:GITHUB_PATH
diff --git a/.github/workflows/create-test-plan.py b/.github/workflows/create-test-plan.py
index f84ca1b153a97..c0e847c05f10f 100755
--- a/.github/workflows/create-test-plan.py
+++ b/.github/workflows/create-test-plan.py
@@ -58,6 +58,7 @@ class SdlPlatform(Enum):
NetBSD = "netbsd"
OpenBSD = "openbsd"
NGage = "ngage"
+ DJGPP = "djgpp"
class Msys2Platform(Enum):
@@ -149,6 +150,7 @@ class JobSpec:
"openbsd": JobSpec(name="OpenBSD", os=JobOs.UbuntuLatest, platform=SdlPlatform.OpenBSD, artifact="SDL-openbsd-x64", ),
"freebsd": JobSpec(name="FreeBSD", os=JobOs.UbuntuLatest, platform=SdlPlatform.FreeBSD, artifact="SDL-freebsd-x64", ),
"ngage": JobSpec(name="N-Gage", os=JobOs.WindowsLatest, platform=SdlPlatform.NGage, artifact="SDL-ngage", ),
+ "djgpp": JobSpec(name="DOS (DJGPP)", os=JobOs.UbuntuLatest, platform=SdlPlatform.DJGPP, artifact="SDL-djgpp", ),
}
@@ -821,6 +823,20 @@ def spec_to_job(spec: JobSpec, key: str, trackmem_symbol_names: bool, ctest_args
job.setup_gage_sdk_path = "C:/ngagesdk"
job.cmake_toolchain_file = "C:/ngagesdk/cmake/ngage-toolchain.cmake"
job.test_pkg_config = False
+ case SdlPlatform.DJGPP:
+ build_parallel = False
+ job.ccache = True
+ job.apt_packages = ["ccache", "libfl-dev"] # djgpp needs libfl.so.2
+ job.cmake_build_type = "Release"
+ job.setup_ninja = True
+ job.static_lib = StaticLibType.A
+ job.shared_lib = None
+ job.clang_tidy = False
+ job.werror = False # FIXME: enable SDL_WERROR
+ job.shared = False
+ job.run_tests = False
+ job.test_pkg_config = False
+ job.cmake_toolchain_file = "$GITHUB_WORKSPACE/build-scripts/i586-pc-msdosdjgpp.cmake"
case _:
raise ValueError(f"Unsupported platform={spec.platform}")
diff --git a/.github/workflows/generic.yml b/.github/workflows/generic.yml
index 82fcbaf15666d..10f241c023d01 100644
--- a/.github/workflows/generic.yml
+++ b/.github/workflows/generic.yml
@@ -100,6 +100,10 @@ jobs:
uses: ./.github/actions/setup-loongarch64-toolchain
id: setup-loongarch64-toolchain
if: ${{ matrix.platform.platform == 'loongarch64' }}
+ - name: 'Set up DJGPP toolchain'
+ uses: ./.github/actions/setup-djgpp-toolchain
+ id: setup-djgpp-toolchain
+ if: ${{ matrix.platform.platform == 'djgpp' }}
- name: 'Setup Intel oneAPI toolchain'
id: intel
if: ${{ matrix.platform.intel }}
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 111e0cb0b1577..86b0214b85f64 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -78,6 +78,7 @@ include("${SDL3_SOURCE_DIR}/cmake/3rdparty.cmake")
include("${SDL3_SOURCE_DIR}/cmake/PreseedMSVCCache.cmake")
include("${SDL3_SOURCE_DIR}/cmake/PreseedEmscriptenCache.cmake")
include("${SDL3_SOURCE_DIR}/cmake/PreseedNokiaNGageCache.cmake")
+include("${SDL3_SOURCE_DIR}/cmake/PreseedDOSCache.cmake")
SDL_DetectCompiler()
SDL_DetectTargetCPUArchitectures(SDL_CPUS)
@@ -163,7 +164,7 @@ endif()
# The hidraw support doesn't catch Xbox, PS4 and Nintendo controllers,
# so we'll just use libusb when it's available. libusb does not support iOS,
# so we default to yes on iOS.
-if(IOS OR TVOS OR VISIONOS OR WATCHOS OR ANDROID OR NGAGE)
+if(IOS OR TVOS OR VISIONOS OR WATCHOS OR ANDROID OR NGAGE OR DOS)
set(SDL_HIDAPI_LIBUSB_AVAILABLE FALSE)
else()
set(SDL_HIDAPI_LIBUSB_AVAILABLE TRUE)
@@ -207,7 +208,7 @@ if(EMSCRIPTEN)
set(SDL_SHARED_AVAILABLE OFF)
endif()
-if(VITA OR PSP OR PS2 OR N3DS OR RISCOS OR NGAGE)
+if(VITA OR PSP OR PS2 OR N3DS OR RISCOS OR NGAGE OR DOS)
set(SDL_SHARED_AVAILABLE OFF)
endif()
@@ -425,6 +426,21 @@ if(VITA)
set_option(VIDEO_VITA_PVR "Build with PSVita PVR gles/gles2 support" OFF)
endif()
+if(DOS)
+ set(SDL_GPU OFF)
+ set(SDL_CAMERA OFF)
+ set(SDL_HAPTIC OFF)
+ set(SDL_HIDAPI OFF)
+ set(SDL_POWER OFF)
+ set(SDL_SENSOR OFF)
+ set(SDL_DIALOG OFF)
+ set(SDL_DUMMYCAMERA OFF)
+ set(SDL_OFFSCREEN OFF)
+ set(SDL_RENDER_GPU OFF)
+ set(SDL_TRAY OFF)
+ set(SDL_PROCESS OFF)
+endif()
+
if (NGAGE)
set(SDL_GPU OFF)
set(SDL_CAMERA OFF)
@@ -3332,6 +3348,51 @@ elseif(N3DS)
"${SDL3_SOURCE_DIR}/src/io/n3ds/*.h"
)
+elseif(DOS)
+ sdl_glob_sources("${SDL3_SOURCE_DIR}/src/main/dos/*.c")
+ sdl_glob_sources("${SDL3_SOURCE_DIR}/src/core/dos/*.c")
+
+ set(SDL_AUDIO_DRIVER_DOS_SOUNDBLASTER 1)
+ sdl_glob_sources("${SDL3_SOURCE_DIR}/src/audio/dos/*.c")
+ set(HAVE_SDL_AUDIO TRUE)
+
+ set(SDL_VIDEO_DRIVER_DOSVESA 1)
+ sdl_glob_sources("${SDL3_SOURCE_DIR}/src/video/dos/*.c")
+ set(HAVE_SDL_VIDEO TRUE)
+
+ set(SDL_FSOPS_POSIX 1)
+ sdl_sources("${SDL3_SOURCE_DIR}/src/filesystem/posix/SDL_sysfsops.c")
+ set(HAVE_SDL_FSOPS TRUE)
+
+ set(SDL_FILESYSTEM_DOS 1)
+ sdl_glob_sources("${SDL3_SOURCE_DIR}/src/filesystem/dos/*.c")
+ set(HAVE_SDL_FILESYSTEM TRUE)
+
+ # Wall-clock time (SDL_GetDateTimeLocalized etc.) reuses the Unix implementation;
+ # DJGPP provides gettimeofday/localtime so this works as-is.
+ set(SDL_TIME_UNIX 1)
+ sdl_glob_sources("${SDL3_SOURCE_DIR}/src/time/unix/*.c")
+ set(HAVE_SDL_TIME TRUE)
+
+ set(SDL_TIMER_DOS 1)
+ sdl_glob_sources("${SDL3_SOURCE_DIR}/src/timer/dos/*.c")
+ set(HAVE_SDL_TIMERS TRUE)
+
+ set(SDL_JOYSTICK_DOS 1)
+ sdl_glob_sources("${SDL3_SOURCE_DIR}/src/joystick/dos/*.c")
+ set(HAVE_SDL_JOYSTICK TRUE)
+
+ set(SDL_THREAD_DOS 1)
+ sdl_glob_sources(
+ "${SDL3_SOURCE_DIR}/src/thread/generic/SDL_syscond.c"
+ "${SDL3_SOURCE_DIR}/src/thread/generic/SDL_syscond_c.h"
+ "${SDL3_SOURCE_DIR}/src/thread/generic/SDL_sysrwlock.c"
+ "${SDL3_SOURCE_DIR}/src/thread/generic/SDL_sysrwlock_c.h"
+ "${SDL3_SOURCE_DIR}/src/thread/dos/*.c"
+ "${SDL3_SOURCE_DIR}/src/thread/dos/*.h"
+ )
+ set(HAVE_SDL_THREADS TRUE)
+
elseif(NGAGE)
enable_language(CXX)
diff --git a/build-scripts/djgpp-platform-overrides.cmake b/build-scripts/djgpp-platform-overrides.cmake
new file mode 100644
index 0000000000000..c919f843f5b36
--- /dev/null
+++ b/build-scripts/djgpp-platform-overrides.cmake
@@ -0,0 +1,17 @@
+# DJGPP platform overrides for DOS
+#
+# CMake's built-in Platform/DOS.cmake assumes OpenWatcom naming conventions
+# (no prefix, .lib suffix, CMAKE_LINK_LIBRARY_SUFFIX=".lib"). DJGPP uses
+# standard Unix/GCC conventions for its system libraries (lib prefix, .a
+# suffix — e.g. libm.a).
+#
+# This file is loaded via CMAKE_USER_MAKE_RULES_OVERRIDE in the toolchain
+# file, which runs *after* the platform module has set its defaults, giving
+# us the final say on these variables.
+
+set(CMAKE_STATIC_LIBRARY_PREFIX "lib")
+set(CMAKE_STATIC_LIBRARY_SUFFIX ".a")
+set(CMAKE_LINK_LIBRARY_SUFFIX "")
+set(CMAKE_FIND_LIBRARY_PREFIXES "lib" "")
+set(CMAKE_FIND_LIBRARY_SUFFIXES ".a" ".lib")
+set(CMAKE_EXECUTABLE_SUFFIX ".exe")
\ No newline at end of file
diff --git a/build-scripts/i586-pc-msdosdjgpp.cmake b/build-scripts/i586-pc-msdosdjgpp.cmake
new file mode 100644
index 0000000000000..8a4e765f14bbc
--- /dev/null
+++ b/build-scripts/i586-pc-msdosdjgpp.cmake
@@ -0,0 +1,82 @@
+set(CMAKE_SYSTEM_NAME DOS)
+
+set(DJGPP TRUE)
+
+# CMake's Platform/DOS.cmake assumes OpenWatcom naming conventions (no prefix,
+# .lib suffix). DJGPP uses standard Unix/GCC conventions for its system
+# libraries (lib prefix, .a suffix — e.g. libm.a), so we override the platform
+# defaults via CMAKE_USER_MAKE_RULES_OVERRIDE, which runs *after* the platform
+# module has set its defaults, giving us the final say on these variables.
+# The path must be cached because CMake re-parses the toolchain file during
+# try_compile, where CMAKE_CURRENT_LIST_DIR may point elsewhere.
+set(DJGPP_PLATFORM_OVERRIDES "${CMAKE_CURRENT_LIST_DIR}/djgpp-platform-overrides.cmake" CACHE FILEPATH "" FORCE)
+set(CMAKE_USER_MAKE_RULES_OVERRIDE "${DJGPP_PLATFORM_OVERRIDES}")
+
+set(CMAKE_STATIC_LIBRARY_PREFIX "lib")
+set(CMAKE_STATIC_LIBRARY_SUFFIX ".a")
+set(CMAKE_SHARED_LIBRARY_PREFIX "")
+set(CMAKE_SHARED_LIBRARY_SUFFIX ".dll")
+set(CMAKE_IMPORT_LIBRARY_PREFIX "lib")
+set(CMAKE_IMPORT_LIBRARY_SUFFIX ".a")
+set(CMAKE_EXECUTABLE_SUFFIX ".exe")
+set(CMAKE_LINK_LIBRARY_SUFFIX "")
+set(CMAKE_DL_LIBS "")
+
+set(CMAKE_FIND_LIBRARY_PREFIXES "lib")
+set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
+
+#
+# CMake toolchain file for DJGPP. Usage:
+#
+# 1. Download and extract DGJPP
+# 2. Add directory containing i586-pc-msdosdjgpp-gcc to PATH environment variable
+# 3. When configuring your CMake project, specify the toolchain file like this:
+#
+# cmake -DCMAKE_TOOLCHAIN_FILE=path/to/i586-pc-msdosdjgpp.cmake ...
+#
+
+# specify the cross compiler
+find_program(CMAKE_C_COMPILER NAMES "i586-pc-msdosdjgpp-gcc" "i386-pc-msdosdjgpp-gcc" REQUIRED)
+find_program(CMAKE_CXX_COMPILER NAMES "i586-pc-msdosdjgpp-g++" "i386-pc-msdosdjgpp-g++" REQUIRED)
+
+execute_process(COMMAND "${CMAKE_C_COMPILER}" -print-search-dirs
+ RESULT_VARIABLE CC_SEARCH_DIRS_RESULT
+ OUTPUT_VARIABLE CC_SEARCH_DIRS_OUTPUT)
+
+if(CC_SEARCH_DIRS_RESULT)
+ message(FATAL_ERROR "Could not determine search dirs")
+endif()
+
+string(REGEX MATCH ".*libraries: (.*).*" CC_SD_LIBS "${CC_SEARCH_DIRS_OUTPUT}")
+string(STRIP "${CMAKE_MATCH_1}" CC_SEARCH_DIRS)
+string(REPLACE ":" ";" CC_SEARCH_DIRS "${CC_SEARCH_DIRS}")
+
+foreach(CC_SEARCH_DIR ${CC_SEARCH_DIRS})
+ if(CC_SEARCH_DIR MATCHES "=.*")
+ string(REGEX MATCH "=(.*)" CC_LIB "${CC_SEARCH_DIR}")
+ set(CC_SEARCH_DIR "${CMAKE_MATCH_1}")
+ endif()
+ if(IS_DIRECTORY "${CC_SEARCH_DIR}")
+ if(IS_DIRECTORY "${CC_SEARCH_DIR}/../include" OR IS_DIRECTORY "${CC_SEARCH_DIR}/../lib" OR IS_DIRECTORY "${CC_SEARCH_DIR}/../bin")
+ list(APPEND CC_ROOTS "${CC_SEARCH_DIR}/..")
+ else()
+ list(APPEND CC_ROOTS "${CC_SEARCH_DIR}")
+ endif()
+ endif()
+endforeach()
+
+list(APPEND CMAKE_FIND_ROOT_PATH ${CC_ROOTS})
+
+# search for programs in the host directories
+set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
+
+# for libraries, headers and packages in the target directories
+if(NOT DEFINED CACHE{CMAKE_FIND_ROOT_PATH_MODE_LIBRARY})
+ set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
+endif()
+if(NOT DEFINED CACHE{CMAKE_FIND_ROOT_PATH_MODE_INCLUDE})
+ set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
+endif()
+if(NOT DEFINED CACHE{CMAKE_FIND_ROOT_PATH_MODE_PACKAGE})
+ set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
+endif()
\ No newline at end of file
diff --git a/cmake/PreseedDOSCache.cmake b/cmake/PreseedDOSCache.cmake
new file mode 100644
index 0000000000000..e5a37a41ca7a1
--- /dev/null
+++ b/cmake/PreseedDOSCache.cmake
@@ -0,0 +1,208 @@
+if(CMAKE_SYSTEM_NAME STREQUAL "DOS")
+ function(SDL_Preseed_CMakeCache)
+ # SIMD intrinsics: disabled for DOS regardless of compiler version.
+ # The DJGPP cross-compiler can *compile* SSE/AVX/MMX, but no real DOS
+ # target machine supports them. Enabling these caused audio breakage.
+ set(COMPILER_SUPPORTS_ARMNEON "" CACHE INTERNAL "Test COMPILER_SUPPORTS_ARMNEON")
+ set(COMPILER_SUPPORTS_AVX "" CACHE INTERNAL "Test COMPILER_SUPPORTS_AVX")
+ set(COMPILER_SUPPORTS_AVX2 "" CACHE INTERNAL "Test COMPILER_SUPPORTS_AVX2")
+ set(COMPILER_SUPPORTS_AVX512F "" CACHE INTERNAL "Test COMPILER_SUPPORTS_AVX512F")
+ set(COMPILER_SUPPORTS_MMX "" CACHE INTERNAL "Test COMPILER_SUPPORTS_MMX")
+ set(COMPILER_SUPPORTS_SSE "" CACHE INTERNAL "Test COMPILER_SUPPORTS_SSE")
+ set(COMPILER_SUPPORTS_SSE2 "" CACHE INTERNAL "Test COMPILER_SUPPORTS_SSE2")
+ set(COMPILER_SUPPORTS_SSE3 "" CACHE INTERNAL "Test COMPILER_SUPPORTS_SSE3")
+ set(COMPILER_SUPPORTS_SSE4_1 "" CACHE INTERNAL "Test COMPILER_SUPPORTS_SSE4_1")
+ set(COMPILER_SUPPORTS_SSE4_2 "" CACHE INTERNAL "Test COMPILER_SUPPORTS_SSE4_2")
+
+ check_c_source_compiles("
+ #if !defined(__GNUC__) || (__GNUC__ < 7)
+ #error Preseeding is only supported for DJGPP GCC 7 or newer
+ #endif
+ int main(int argc, char **argv) { return 0; }
+ " CAN_PRESEED
+ )
+ if(CAN_PRESEED)
+ set(COMPILER_SUPPORTS_FDIAGNOSTICS_COLOR_ALWAYS "1" CACHE INTERNAL "Test COMPILER_SUPPORTS_FDIAGNOSTICS_COLOR_ALWAYS")
+ set(COMPILER_SUPPORTS_GCC_ATOMICS "" CACHE INTERNAL "Test COMPILER_SUPPORTS_GCC_ATOMICS")
+ set(COMPILER_SUPPORTS_SYNC_LOCK_TEST_AND_SET "1" CACHE INTERNAL "Test COMPILER_SUPPORTS_SYNC_LOCK_TEST_AND_SET")
+ set(HAVE_CLANG_COMMENT_BLOCK_COMMANDS "" CACHE INTERNAL "Test HAVE_CLANG_COMMENT_BLOCK_COMMANDS")
+ set(HAVE_ALLOCA_H "" CACHE INTERNAL "Have include alloca.h")
+ set(HAVE_LIBM "1" CACHE INTERNAL "Have library m")
+ set(HAVE_POSIX_SPAWN "" CACHE INTERNAL "Have symbol posix_spawn")
+ set(HAVE_FSEEKO "1" CACHE INTERNAL "Have symbol fseeko")
+ set(HAVE_OFF64_T "1" CACHE INTERNAL "Have symbol off64_t")
+ set(LIBC_HAS_ABS "1" CACHE INTERNAL "Have symbol abs")
+ set(LIBC_HAS_ACOS "1" CACHE INTERNAL "Have symbol acos")
+ set(LIBC_HAS_ACOSF "1" CACHE INTERNAL "Have symbol acosf")
+ set(LIBC_HAS_ASIN "1" CACHE INTERNAL "Have symbol asin")
+ set(LIBC_HAS_ASINF "1" CACHE INTERNAL "Have symbol asinf")
+ set(LIBC_HAS_ATAN "1" CACHE INTERNAL "Have symbol atan")
+ set(LIBC_HAS_ATAN2 "1" CACHE INTERNAL "Have symbol atan2")
+ set(LIBC_HAS_ATAN2F "1" CACHE INTERNAL "Have symbol atan2f")
+ set(LIBC_HAS_ATANF "1" CACHE INTERNAL "Have symbol atanf")
+ set(LIBC_HAS_ATOF "1" CACHE INTERNAL "Have symbol atof")
+ set(LIBC_HAS_ATOI "1" CACHE INTERNAL "Have symbol atoi")
+ set(LIBC_HAS_BCOPY "1" CACHE INTERNAL "Have symbol bcopy")
+ set(LIBC_HAS_CALLOC "" CACHE INTERNAL "Have symbol calloc")
+ set(LIBC_HAS_CEIL "1" CACHE INTERNAL "Have symbol ceil")
+ set(LIBC_HAS_CEILF "1" CACHE INTERNAL "Have symbol ceilf")
+ set(LIBC_HAS_COPYSIGN "1" CACHE INTERNAL "Have symbol copysign")
+ set(LIBC_HAS_COPYSIGNF "1" CACHE INTERNAL "Have symbol copysignf")
+ set(LIBC_HAS_COS "1" CACHE INTERNAL "Have symbol cos"
(Patch may be truncated, please check the link at the top of this post.)