Skip to content

Commit e63016e

Browse files
committed
Switch Dreamcast to GPF SDL for DMA video and hardware palette
Replace kos-ports SDL with GPF SDL (SDL-dreamhal--GLDC) which provides PVR DMA framebuffer transfer and native 8bpp hardware palette support. This bypasses the manual 8bpp-to-16bpp conversion in dc_video.cpp, roughly doubling framerate from ~20-25 to ~40-50 FPS. Signed-off-by: Panagiotis Georgiadis <pgeorgia@redhat.com>
1 parent 3bc5033 commit e63016e

5 files changed

Lines changed: 46 additions & 8 deletions

File tree

CMake/platforms/dreamcast.cmake

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ set(DEFAULT_AUDIO_RESAMPLING_QUALITY 0)
2424
set(DEFAULT_PER_PIXEL_LIGHTING 0)
2525
set(DEVILUTIONX_PALETTE_TRANSPARENCY_BLACK_16_LUT ON CACHE BOOL "" FORCE)
2626

27+
# GPF SDL supports 8bpp with hardware palette - lets SDL handle the
28+
# palette-to-RGB conversion internally via PVR DMA, avoiding the
29+
# manual 8bpp->16bpp conversion in dc_video.cpp entirely.
30+
set(SDL1_VIDEO_MODE_BPP 8)
31+
set(SDL1_VIDEO_MODE_FLAGS SDL_DOUBLEBUF|SDL_HWSURFACE)
32+
2733
set(DEFAULT_WIDTH 640)
2834
set(DEFAULT_HEIGHT 480)
2935

@@ -32,11 +38,12 @@ set(UNPACKED_SAVES ON)
3238

3339
set(DEVILUTIONX_GAMEPAD_TYPE Generic)
3440

35-
set(JOY_BUTTON_A 0)
41+
# GPF SDL button IDs (from SDL_dreamcast.h SDL_DC_button enum)
42+
set(JOY_BUTTON_A 2)
3643
set(JOY_BUTTON_B 1)
37-
set(JOY_BUTTON_X 2)
38-
set(JOY_BUTTON_Y 3)
39-
set(JOY_BUTTON_START 4)
44+
set(JOY_BUTTON_X 5)
45+
set(JOY_BUTTON_Y 6)
46+
set(JOY_BUTTON_START 3)
4047

4148
set(JOY_HAT_DPAD_UP_HAT 0)
4249
set(JOY_HAT_DPAD_DOWN_HAT 0)

CMake/platforms/dreamcast.toolchain.cmake

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ set(DREAMCAST ON)
1515

1616
# 3. Add our include paths
1717
# KOS ports often hide headers in subdirectories
18+
# GPF SDL installs to KOS_BASE/addons/include/dreamcast/SDL/
1819
list(APPEND CMAKE_INCLUDE_PATH
1920
"$ENV{KOS_PORTS}/include/zlib"
2021
"$ENV{KOS_PORTS}/include/bzlib"
21-
"$ENV{KOS_PORTS}/include/SDL"
22+
"$ENV{KOS_BASE}/addons/include/dreamcast/SDL"
2223
)
2324

2425
# 4. Force libraries (The "Nuclear Option" for sub-projects)
@@ -28,9 +29,10 @@ set(ZLIB_LIBRARY "$ENV{KOS_PORTS}/lib/libz.a" CACHE FILEPATH "ZLIB Library" FORC
2829
set(BZIP2_INCLUDE_DIR "$ENV{KOS_PORTS}/include/bzlib" CACHE PATH "BZip2 Include Dir" FORCE)
2930
set(BZIP2_LIBRARIES "$ENV{KOS_PORTS}/lib/libbz2.a" CACHE FILEPATH "BZip2 Library" FORCE)
3031

31-
# 5. Force SDL1 - MUST set SDL_LIBRARY without -lpthreads (KOS has built-in threading)
32-
set(SDL_INCLUDE_DIR "$ENV{KOS_PORTS}/include/SDL" CACHE PATH "SDL Include Dir" FORCE)
33-
set(SDL_LIBRARY "$ENV{KOS_PORTS}/lib/libSDL.a" CACHE FILEPATH "SDL Library" FORCE)
32+
# 5. Force SDL1 - GPF SDL (SDL-dreamhal--GLDC) for DMA video and hardware palette
33+
# GPF SDL installs via its Makefile.dc to KOS_BASE/addons/{lib,include}/dreamcast/
34+
set(SDL_INCLUDE_DIR "$ENV{KOS_BASE}/addons/include/dreamcast/SDL" CACHE PATH "SDL Include Dir" FORCE)
35+
set(SDL_LIBRARY "$ENV{KOS_BASE}/addons/lib/dreamcast/libSDL.a" CACHE FILEPATH "SDL Library" FORCE)
3436

3537
# 6. Fix libfmt and magic_enum compilation
3638
# Disable long double support because sh4-gcc's long double (64-bit) confuses libfmt

Packaging/dreamcast/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ File[0-9]*.xxx
3535
File[0-9]*.gif
3636
File[0-9]*.smk
3737

38+
# GPF SDL source (cloned by build.sh)
39+
SDL-gpf/
40+
3841
# Build tool output
3942
*.o
4043

Packaging/dreamcast/build.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,21 @@ if [ ! -x "${MKDCDISC}" ]; then
3030
exit 1
3131
fi
3232

33+
GPF_SDL_DIR="${SCRIPT_DIR}/SDL-gpf"
34+
GPF_SDL_LIB="${KOS_BASE}/addons/lib/dreamcast/libSDL.a"
35+
36+
if [ ! -f "${GPF_SDL_LIB}" ]; then
37+
echo "Building GPF SDL (SDL-dreamhal--GLDC) for DMA video..."
38+
if [ ! -d "${GPF_SDL_DIR}" ]; then
39+
git clone --depth 1 -b SDL-dreamhal--GLDC \
40+
https://github.com/GPF/SDL-1.2 "${GPF_SDL_DIR}"
41+
fi
42+
make -C "${GPF_SDL_DIR}" -f Makefile.dc -j"$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 4)"
43+
echo "GPF SDL installed to ${GPF_SDL_LIB}"
44+
else
45+
echo "GPF SDL already installed at ${GPF_SDL_LIB}"
46+
fi
47+
3348
rm -rf "${BUILD_DIR}"
3449
mkdir -p "${BUILD_DIR}"
3550

Source/utils/display.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@
6363
#endif
6464
#endif
6565

66+
#ifdef __DREAMCAST__
67+
#include <SDL_dreamcast.h>
68+
#endif
69+
6670
namespace devilution {
6771

6872
extern SDLSurfaceUniquePtr RendererTextureSurface; /** defined in dx.cpp */
@@ -485,6 +489,13 @@ void SetVideoModeToPrimary(bool fullscreen, int width, int height)
485489
#ifdef __3DS__
486490
flags &= ~SDL_FULLSCREEN;
487491
flags |= Get3DSScalingFlag(*GetOptions().Graphics.fitToScreen, width, height);
492+
#endif
493+
#ifdef __DREAMCAST__
494+
SDL_DC_SetVideoDriver(SDL_DC_DMA_VIDEO);
495+
SDL_DC_VerticalWait(SDL_FALSE);
496+
SDL_DC_ShowAskHz(SDL_FALSE);
497+
SDL_DC_EmulateKeyboard(SDL_FALSE);
498+
SDL_DC_EmulateMouse(SDL_FALSE);
488499
#endif
489500
SetVideoMode(width, height, SDL1_VIDEO_MODE_BPP, flags);
490501
if (OutputRequiresScaling())

0 commit comments

Comments
 (0)