Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dreamcast Port #7453

Draft
wants to merge 41 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
fd75da9
Add Sega Dreamcast port
azihassan Jul 13, 2024
c037e62
Add Dreamcast CI job
azihassan Aug 4, 2024
c6badf3
Store save files in ramdisk
azihassan Jul 24, 2024
5f7e715
Fix fonts fatal error
azihassan Aug 9, 2024
6cb0513
Disable unpacked MPQs
azihassan Aug 12, 2024
336f046
Build in release mode
azihassan Aug 14, 2024
cae4e31
Store save files in VMU to test multiplayer mode
azihassan Aug 15, 2024
5ed9ab4
Reduce multiplayer saving frequency to once per 10 minutes of gameplay
azihassan Aug 18, 2024
aaf2a17
Save to VMU using vmu_pkg_* API
azihassan Aug 20, 2024
dc8124b
Remove /vmu from MPQ search paths
azihassan Aug 24, 2024
733f88a
Remove HP log that crashes console for some reason
azihassan Aug 30, 2024
fb6e5c0
Update spawn.mpq URL & set build mode to release
azihassan Aug 30, 2024
7d1aec8
Use GPF port of SDL for performance reasons
azihassan Sep 5, 2024
2e12ccc
Comment memory-related preprocessor lines to fix compilation error
azihassan Sep 5, 2024
54276d9
Remove SDL_stdinc.h patch since the memfuncs.h header is no longer be…
azihassan Sep 6, 2024
819e48b
Remove -O3, no perf gain was noticed after adding it
azihassan Sep 7, 2024
2b60fcc
Fix shareware framerate
azihassan Sep 8, 2024
d11ef3f
Include data directory in elf artifact
azihassan Sep 8, 2024
679cca5
Temporarily disable single player mode due to save file sizes
azihassan Sep 10, 2024
dc4e01c
Add GPF SDL port installation code to Dockerfile
azihassan Sep 13, 2024
72c7e30
Handle L and R buttons in code
azihassan Sep 13, 2024
6eb3678
Add docs and release steps
azihassan Sep 20, 2024
65818af
Fix formatting to match .clang-format specs
azihassan Oct 6, 2024
7dbeed9
Wrap dreamcast-specific code if ifdef __DREAMCAST__
azihassan Oct 6, 2024
0f9e1a4
Merge pull request #11 from azihassan/fix/ISSUE-10-formatting
azihassan Oct 6, 2024
5f36c72
Disable libfmt builtin types for Dreamcast
azihassan Oct 7, 2024
3d1495c
Merge pull request #12 from azihassan/fix/ISSUE-8-libfmt
azihassan Oct 7, 2024
bb94f5a
Remove obsolete libfmt patching shenanigans
azihassan Oct 7, 2024
dcac99b
Fix typo in DREAMCAST ifdef lines
azihassan Oct 7, 2024
f63f914
Remove obsolete ramdisk code
azihassan Oct 7, 2024
aa2f9e2
Merge pull request #13 from azihassan/fix/ISSUE-2-ramdisk
azihassan Oct 11, 2024
51ab7b7
Restore unpacked MPQ support
azihassan Oct 21, 2024
25c05e8
Merge pull request #17 from azihassan/fix/ISSUE-15-unpacked-mpqs
azihassan Oct 22, 2024
df4540b
Disable LTO
azihassan Oct 14, 2024
8873aa8
Enable DMA driver once before SDL_Init
azihassan Oct 19, 2024
56aaa4e
Merge pull request #16 from azihassan/fix/ISSUE-14-palette-crash
azihassan Oct 23, 2024
e29611e
Merge branch 'diasurgical:master' into dreamcast
azihassan Oct 26, 2024
1027d09
Fix extra font detection issue when loading from SD card
azihassan Oct 29, 2024
3d7e734
Merge pull request #18 from azihassan/fix/ISSUE-15-unpacked-mpqs
azihassan Oct 29, 2024
3a0d56c
Disable stash from NPC menu
azihassan Nov 16, 2024
a01d52c
Merge pull request #19 from azihassan/fix/ISSUE-1-disable-stash
azihassan Nov 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/clang-format-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- master
- dreamcast
paths-ignore:
- '*.md'
- 'docs/**'
Expand Down
133 changes: 133 additions & 0 deletions .github/workflows/dreamcast.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
---
name: Sega Dreamcast

on: # yamllint disable-line rule:truthy
push:
branches:
- master
- dreamcast
paths-ignore:
- '*.md'
- 'docs/**'
pull_request:
types: [opened, synchronize]
paths-ignore:
- '*.md'
- 'docs/**'
release:
types: [published]
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest
container: azihassan/kallistios:docker
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Build unpack_and_minify_mpq
run: |
git clone https://github.com/diasurgical/devilutionx-mpq-tools/ && \
cd devilutionx-mpq-tools && \
cmake -S. -Bbuild-rel -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF && \
cmake --build build-rel && \
cmake --install build-rel

- name: Download and unpack spawn.mpq
run: |
#devilutionx-assets spawn.mpq fails with unpack_and_minify_mpq
#curl -LO https://github.com/diasurgical/devilutionx-assets/releases/download/v4/spawn.mpq
curl -LO https://raw.githubusercontent.com/d07RiV/diabloweb/3a5a51e84d5dab3cfd4fef661c46977b091aaa9c/spawn.mpq
unpack_and_minify_mpq spawn.mpq
rm spawn.mpq

- name: Download and unpack fonts.mpq
run: |
curl -LO https://github.com/diasurgical/devilutionx-assets/releases/download/v4/fonts.mpq && \
unpack_and_minify_mpq fonts.mpq && \
rm fonts.mpq

- name: Uninstall kos-ports SDL 1.2
run: |
source /opt/toolchains/dc/kos/environ.sh && \
cd /opt/toolchains/dc/kos-ports/SDL && \
make uninstall || echo 'SDL 1.2 uninstall finished with non zero status, proceding anyway'

- name: Install GPF SDL 1.2
run: |
git clone -b SDL-dreamhal--GLDC https://github.com/GPF/SDL-1.2 && \
cd SDL-1.2 && \
source /opt/toolchains/dc/kos/environ.sh && \
make -f Makefile.dc && \
cp /opt/toolchains/dc/kos/addons/lib/dreamcast/libSDL.a /usr/lib/ && \
cp include/* /usr/include/SDL/

- name: Configure CMake
run: |
source /opt/toolchains/dc/kos/environ.sh && \
#uncomment when using packed save files
#without this, cmake can't find the kos-ports bzip2 & zlib libraries
#export CMAKE_PREFIX_PATH=/opt/toolchains/dc/kos-ports/libbz2/inst/:/opt/toolchains/dc/kos-ports/zlib/inst/ && \
kos-cmake \
-S . \
-DCMAKE_BUILD_TYPE=Release \
-B build

- name: Build DevilutionX
run: |
source /opt/toolchains/dc/kos/environ.sh && cd build && kos-make

- name: Generate .cdi
run: |
source /opt/toolchains/dc/kos/environ.sh && \
mv spawn build/data/spawn && \
mv fonts/fonts/ build/data/fonts/ && \
mkdcdisc -e build/devilutionx.elf -o build/devilutionx.cdi --name 'Diablo 1' -d build/data/

- name: Prepare elf package
run: rm -rf build/data/spawn && rm -rf build/data/fonts/fonts/

- name: Upload .elf Package
if: ${{ !env.ACT }}
uses: actions/upload-artifact@v4
with:
name: devilutionx
path: |
build/data
build/devilutionx.elf

- name: Upload .cdi Package
if: ${{ !env.ACT }}
uses: actions/upload-artifact@v4
with:
name: devilutionx.cdi
path: ./build/devilutionx.cdi

- name: Prepare Releases
if: ${{ github.event_name == 'release' && !env.ACT }}
run: |
apk add zip && \
cd build && \
zip -r devilutionx-dreamcast.zip data/ devilutionx.elf && \
zip -r devilutionx-dreamcast.cdi.zip devilutionx.cdi

- name: Update Release .cdi
if: ${{ github.event_name == 'release' && !env.ACT }}
uses: svenstaro/upload-release-action@v2
with:
file: ./build/devilutionx-dreamcast.cdi.zip
overwrite: true

- name: Update Release .elf
if: ${{ github.event_name == 'release' && !env.ACT }}
uses: svenstaro/upload-release-action@v2
with:
file: ./build/devilutionx-dreamcast.zip
overwrite: true
2 changes: 1 addition & 1 deletion 3rdParty/libfmt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ if(DEVILUTIONX_WINDOWS_NO_WCHAR)
endif()

# Reduces the overall binary size by 8 KiB.
if(TARGET_PLATFORM STREQUAL "rg99")
if(TARGET_PLATFORM STREQUAL "rg99" OR PLATFORM_DREAMCAST)
target_compile_definitions(fmt PUBLIC FMT_BUILTIN_TYPES=0)
endif()

Expand Down
4 changes: 4 additions & 0 deletions CMake/Platforms.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,7 @@ endif()
if(NXDK)
include(platforms/xbox_nxdk)
endif()

if(PLATFORM_DREAMCAST)
include(platforms/dreamcast)
endif()
50 changes: 50 additions & 0 deletions CMake/platforms/dreamcast.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
set(BUILD_TESTING OFF)
set(NONET ON)
set(ASAN OFF)
set(UBSAN OFF)

set(USE_SDL1 ON)
set(SDL1_VIDEO_MODE_BPP 8)
set(SDL1_VIDEO_MODE_FLAGS SDL_FULLSCREEN|SDL_DOUBLEBUF|SDL_HWSURFACE|SDL_HWPALETTE)
set(DEFAULT_WIDTH 640)
set(DEFAULT_HEIGHT 480)
set(DEVILUTIONX_GAMEPAD_TYPE Nintendo)

set(NOSOUND ON)
set(DEVILUTIONX_STATIC_ZLIB ON)
set(UNPACKED_MPQS ON)
set(UNPACKED_SAVES ON)
set(DEVILUTIONX_SYSTEM_LIBFMT OFF)
set(DEVILUTIONX_STATIC_LUA ON)
set(DEVILUTIONX_DISABLE_STRIP ON)

set(DEVILUTIONX_ASSETS_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/data/")
set(BUILD_ASSETS_MPQ OFF)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/threads-stub")
list(APPEND DEVILUTIONX_PLATFORM_COMPILE_DEFINITIONS __DREAMCAST__)
add_compile_options(-fpermissive)

#SDL Joystick hat mapping (D-pad)
set(JOY_HAT_DPAD_UP_HAT 0)
set(JOY_HAT_DPAD_RIGHT_HAT 0)
set(JOY_HAT_DPAD_DOWN_HAT 0)
set(JOY_HAT_DPAD_LEFT_HAT 0)
set(JOY_HAT_DPAD_UP 1)
set(JOY_HAT_DPAD_RIGHT 2)
set(JOY_HAT_DPAD_DOWN 4)
set(JOY_HAT_DPAD_LEFT 8)

#SDL Joystick button mapping
set(JOY_BUTTON_A 2)
set(JOY_BUTTON_B 1)
set(JOY_BUTTON_X 5)
set(JOY_BUTTON_Y 6)

set(JOY_BUTTON_START 3)

#GPF SDL files
set(SDL_INCLUDE_DIR /usr/include/SDL/)
set(SDL_LIBRARY /usr/lib/libSDL.a)

add_compile_options(-flto=none)
60 changes: 60 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
FROM azihassan/kallistios:fdffe33635239d46bcccf0d5c4d59bb7d2d91f38

RUN echo "Building unpack_and_minify_mpq..."
RUN git clone https://github.com/diasurgical/devilutionx-mpq-tools/ && \
cd devilutionx-mpq-tools && \
cmake -S. -Bbuild-rel -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF && \
cmake --build build-rel && \
cmake --install build-rel

RUN echo "Cloning project..."
WORKDIR /opt/toolchains/dc/kos/
RUN git clone -b dreamcast https://github.com/azihassan/devilutionX.git

RUN echo "Uninstall kos-ports SDL 1.2..."
RUN source /opt/toolchains/dc/kos/environ.sh && \
cd /opt/toolchains/dc/kos-ports/SDL && \
make uninstall || echo 'SDL 1.2 uninstall finished with non zero status, proceding anyway'

RUN echo "Install GPF SDL 1.2..."
RUN git clone -b SDL-dreamhal--GLDC https://github.com/GPF/SDL-1.2 && \
cd SDL-1.2 && \
source /opt/toolchains/dc/kos/environ.sh && \
make -f Makefile.dc && \
cp /opt/toolchains/dc/kos/addons/lib/dreamcast/libSDL.a /usr/lib/ && \
cp include/* /usr/include/SDL/

WORKDIR /opt/toolchains/dc/kos/devilutionX
RUN echo "Downloading and unpacking spawn.mpq..."
RUN curl -LO https://raw.githubusercontent.com/d07RiV/diabloweb/3a5a51e84d5dab3cfd4fef661c46977b091aaa9c/spawn.mpq && \
unpack_and_minify_mpq spawn.mpq && \
rm spawn.mpq

RUN echo "Downloading and unpacking fonts.mpq..."
RUN curl -LO https://github.com/diasurgical/devilutionx-assets/releases/download/v4/fonts.mpq && \
unpack_and_minify_mpq fonts.mpq && \
rm fonts.mpq

#WORKDIR /opt/toolchains/dc/kos/devilutionX
#RUN echo "Copying and unpacking diabdat.mpq..."
#COPY DIABDAT.MPQ .
#RUN unpack_and_minify_mpq DIABDAT.MPQ

RUN echo "Configuring CMake..."
RUN source /opt/toolchains/dc/kos/environ.sh && \
#uncomment when using packed save files
#without this, cmake can't find the kos-ports bzip2 & zlib libraries
#export CMAKE_PREFIX_PATH=/opt/toolchains/dc/kos-ports/libbz2/inst/:/opt/toolchains/dc/kos-ports/zlib/inst/ && \
kos-cmake -S. -Bbuild

RUN echo "Compiling..."
RUN source /opt/toolchains/dc/kos/environ.sh && cd build && kos-make

RUN echo "Generating CDI"
RUN source /opt/toolchains/dc/kos/environ.sh && \
mv spawn build/data/spawn && \
mv fonts/fonts/ build/data/fonts/ && \
#mv diabdat build/data/diabdat && \
mkdcdisc -e build/devilutionx.elf -o build/devilutionx.cdi --name 'Diablo 1' -d build/data/

ENTRYPOINT ["sh", "-c", "source /opt/toolchains/dc/kos/environ.sh && \"$@\"", "-s"]
4 changes: 4 additions & 0 deletions Source/DiabloUI/mainmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ void MainmenuEsc()

void MainmenuLoad(const char *name)
{
#ifndef __DREAMCAST__
// single player save files are too big for the VMU
// todo reactivate when SD card saving is implemented
vecMenuItems.push_back(std::make_unique<UiListItem>(_("Single Player"), MAINMENU_SINGLE_PLAYER));
#endif
vecMenuItems.push_back(std::make_unique<UiListItem>(_("Multi Player"), MAINMENU_MULTIPLAYER));
vecMenuItems.push_back(std::make_unique<UiListItem>(_("Settings"), MAINMENU_SETTINGS));
vecMenuItems.push_back(std::make_unique<UiListItem>(_("Support"), MAINMENU_SHOW_SUPPORT));
Expand Down
2 changes: 1 addition & 1 deletion Source/appfat.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace devilution {
#ifndef _DEBUG
#define assert(exp)
#else
#define assert(exp) (void)((exp) || (assert_fail(__LINE__, __FILE__, #exp), 0))
#define assert(exp) (void)((exp) || (devilution::assert_fail(__LINE__, __FILE__, #exp), 0))
#endif

/**
Expand Down
48 changes: 46 additions & 2 deletions Source/controls/devices/joystick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ StaticVector<ControllerButtonEvent, 4> Joystick::ToControllerButtonEvents(const
return { ControllerButtonEvent { ControllerButton_BUTTON_RIGHTSTICK, up } };
#endif
#ifdef JOY_BUTTON_LEFTSHOULDER
case JOY_BUTTON_LEFTSHOULDER:
case JOY_BUTTON_LEFTSHOULDER: {
Log("ToControllerButtonEvents JOY_BUTTON_LEFTSHOULDER pressed");
return { ControllerButtonEvent { ControllerButton_BUTTON_LEFTSHOULDER, up } };
}
#endif
#ifdef JOY_BUTTON_RIGHTSHOULDER
case JOY_BUTTON_RIGHTSHOULDER:
Expand Down Expand Up @@ -101,6 +103,20 @@ StaticVector<ControllerButtonEvent, 4> Joystick::ToControllerButtonEvents(const
}
case SDL_JOYAXISMOTION:
case SDL_JOYBALLMOTION:
#ifdef __DREAMCAST__
if (event.jaxis.axis == 3) {
Log("BUTTON_LEFTSHOULDER detected");
Log("event.jbutton.button = {}", event.jbutton.button);
Log("event.jbutton.state == SDL_RELEASED = {}", event.jbutton.state == SDL_RELEASED);
return { ControllerButtonEvent { ControllerButton_BUTTON_LEFTSHOULDER, event.jaxis.value < 255 } };
}
if (event.jaxis.axis == 2) {
Log("BUTTON_RIGHTSHOULDER detected");
Log("event.jbutton.button = {}", event.jbutton.button);
Log("event.jbutton.state == SDL_RELEASED = {}", event.jbutton.state == SDL_RELEASED);
return { ControllerButtonEvent { ControllerButton_BUTTON_RIGHTSHOULDER, event.jaxis.value < 255 } };
}
#endif
// ProcessAxisMotion() requires a ControllerButtonEvent parameter
// so provide one here using ControllerButton_NONE
return { ControllerButtonEvent { ControllerButton_NONE, false } };
Expand Down Expand Up @@ -211,8 +227,10 @@ int Joystick::ToSdlJoyButton(ControllerButton button)
return JOY_BUTTON_RIGHTSTICK;
#endif
#ifdef JOY_BUTTON_LEFTSHOULDER
case ControllerButton_BUTTON_LEFTSHOULDER:
case ControllerButton_BUTTON_LEFTSHOULDER: {
Log("ToSdlJoyButton JOY_BUTTON_LEFTSHOULDER pressed");
return JOY_BUTTON_LEFTSHOULDER;
}
#endif
#ifdef JOY_BUTTON_RIGHTSHOULDER
case ControllerButton_BUTTON_RIGHTSHOULDER:
Expand Down Expand Up @@ -292,6 +310,31 @@ bool Joystick::IsPressed(ControllerButton button) const
return joyButton < numButtons && SDL_JoystickGetButton(sdl_joystick_, joyButton) != 0;
}

#ifdef __DREAMCAST__
bool Joystick::ProcessAxisMotion(const SDL_Event &event)
{
if (event.type != SDL_JOYAXISMOTION)
return false;

Log("ProcessAxisMotion event.jaxis.axis = {}", event.jaxis.axis);
Log("ProcessAxisMotion event.jaxis.value = {}", event.jaxis.value);
Log("ProcessAxisMotion event.jbutton.button = {}", event.jbutton.button);
Log("event.jbutton.state == SDL_RELEASED = {}", event.jbutton.state == SDL_RELEASED);

switch (event.jaxis.axis) {
case 0: // horizontal
leftStickXUnscaled = event.jaxis.value;
leftStickNeedsScaling = true;
return true;
case 1: // vertical
leftStickYUnscaled = event.jaxis.value;
leftStickNeedsScaling = true;
return true;
default:
return false;
}
}
#else //! ifdef __DREAMCAST__
bool Joystick::ProcessAxisMotion(const SDL_Event &event)
{
if (event.type != SDL_JOYAXISMOTION)
Expand Down Expand Up @@ -330,6 +373,7 @@ bool Joystick::ProcessAxisMotion(const SDL_Event &event)
return false;
#endif
}
#endif

void Joystick::Add(int deviceIndex)
{
Expand Down
Loading