Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 15 additions & 0 deletions .appveyor/AfterBuild.macos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash
set -ex

cd "$APPVEYOR_BUILD_FOLDER/src_rebuild"

for renderer in opengl vulkan
do
for config in Debug Release Release_dev
do
cd "$APPVEYOR_BUILD_FOLDER/src_rebuild/bin/macos_arm64_${renderer}/${config}"
cp -R "$APPVEYOR_BUILD_FOLDER/data/"* ./
tar -czf "REDRIVER2_macOS_arm64_${renderer}_${config}.tar.gz" *
mv "REDRIVER2_macOS_arm64_${renderer}_${config}.tar.gz" "$APPVEYOR_BUILD_FOLDER/src_rebuild/bin/${config}/"
done
done
4 changes: 4 additions & 0 deletions .appveyor/AfterBuild.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#!/usr/bin/env bash
set -ex

if [ "$(uname -s)" = "Darwin" ]; then
exec "${APPVEYOR_BUILD_FOLDER}/.appveyor/AfterBuild.macos.sh"
fi

for config in debug release release_dev
do
cd "${APPVEYOR_BUILD_FOLDER}/src_rebuild/bin/${config^}"
Expand Down
36 changes: 36 additions & 0 deletions .appveyor/Build.macos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env bash
set -ex

cd "$APPVEYOR_BUILD_FOLDER/src_rebuild"

# Strip any cached project files between renderer variants so premake
# regenerates the makefile with the right --renderer option.
rm -rf project_gmake_macosx

NCPU=$(sysctl -n hw.ncpu)

# ---------- OpenGL build (default) ----------
premake5 gmake
pushd project_gmake_macosx > /dev/null
for config in debug_arm64 release_arm64 release_dev_arm64
do
make config=$config -j$NCPU
done
popd > /dev/null

# Stash the OpenGL artifacts before regenerating for Vulkan.
mkdir -p bin/macos_arm64_opengl
cp -R bin/Debug bin/Release bin/Release_dev bin/macos_arm64_opengl/

# ---------- Vulkan / MoltenVK build ----------
rm -rf project_gmake_macosx
premake5 --renderer=vulkan gmake
pushd project_gmake_macosx > /dev/null
for config in debug_arm64 release_arm64 release_dev_arm64
do
make config=$config -j$NCPU
done
popd > /dev/null

mkdir -p bin/macos_arm64_vulkan
cp -R bin/Debug bin/Release bin/Release_dev bin/macos_arm64_vulkan/
4 changes: 4 additions & 0 deletions .appveyor/Build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#!/usr/bin/env bash
set -ex

if [ "$(uname -s)" = "Darwin" ]; then
exec "${APPVEYOR_BUILD_FOLDER}/.appveyor/Build.macos.sh"
fi

# Configure
cd "$APPVEYOR_BUILD_FOLDER/src_rebuild"
./premake5 gmake2
Expand Down
15 changes: 15 additions & 0 deletions .appveyor/Install.macos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash
set -ex

# AppVeyor's macOS image ships Homebrew but not the package set we need.
# This installs everything required to build both renderer backends —
# OpenGL (default) and Vulkan/MoltenVK (opt-in via --renderer=vulkan).

brew update

# Common deps for both backends
brew install premake sdl2 jpeg openal-soft

# Vulkan backend deps. shaderc is statically linked from libshaderc_combined.a
# at link time so the produced binary doesn't need a runtime SPIR-V compiler.
brew install vulkan-headers vulkan-loader molten-vk shaderc
7 changes: 7 additions & 0 deletions .appveyor/Install.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
#!/usr/bin/env bash
set -ex

# AppVeyor runs `sh:` steps on every non-Windows image. Delegate to a
# macOS-specific script when the worker is macOS so the Linux-only
# apt/flatpak path below doesn't try to run.
if [ "$(uname -s)" = "Darwin" ]; then
exec "${APPVEYOR_BUILD_FOLDER}/.appveyor/Install.macos.sh"
fi

cd "$APPVEYOR_BUILD_FOLDER/src_rebuild"

# Download premake5
Expand Down
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,15 @@ src_rebuild/obj/*
src_rebuild/project_*
src_rebuild/*.make
src_rebuild/Makefile

# Driver 2 game data (CD images + extracted FMV/XA — too large for git)
data/install/*.bin
data/install/*.cue
data/DRIVER2/FMV/
data/DRIVER2/XA/
data/REDRIVER2.log

# Build outputs
src_rebuild/bin/
src_rebuild/obj/
src_rebuild/project_gmake_*/
167 changes: 167 additions & 0 deletions BUILD_MACOS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
# REDRIVER2 — Building on macOS Apple Silicon

Build port of REDRIVER2 for macOS arm64 (Apple Silicon — M1/M2/M3/M4).
Also works on Intel macs (x86_64) via the same automatic prefix
detection.

## Prerequisites

1. **Xcode Command Line Tools**

```bash
xcode-select --install
```

2. **Homebrew** — https://brew.sh

3. **Dependencies via Homebrew**

OpenGL build (default):

```bash
brew install premake sdl2 jpeg openal-soft
```

Vulkan / MoltenVK build (optional):

```bash
brew install premake sdl2 jpeg openal-soft \
vulkan-headers vulkan-loader molten-vk shaderc
```

On Apple Silicon brew installs under `/opt/homebrew`; on Intel macs
it's `/usr/local`. `premake5.lua` detects either automatically.

## Build

```bash
git clone https://github.com/OpenDriver2/REDRIVER2.git
cd REDRIVER2
git submodule update --init --recursive
cd src_rebuild

# OpenGL backend (default)
premake5 gmake

# OR: Vulkan / MoltenVK backend
premake5 --renderer=vulkan gmake

cd project_gmake_macosx

# Apple Silicon
make config=release_arm64 -j$(sysctl -n hw.ncpu)

# Intel
make config=release_x64 -j$(sysctl -n hw.ncpu)
```

Available configurations: `debug_arm64`, `release_arm64`,
`release_dev_arm64` (and the matching `x64` variants).

Final binary: `src_rebuild/bin/Release/REDRIVER2`.

## Running the game

REDRIVER2 needs the original Driver 2 (PSX) data files alongside the
executable. See the
[installation wiki](https://github.com/OpenDriver2/REDRIVER2/wiki/Installation-instructions)
for the asset extraction steps.

## Optional environment variables

To point at non-Homebrew dependency installs:

```bash
export MAC_SDL2_DIR=/path/to/sdl2
export MAC_OPENAL_DIR=/path/to/openal-soft
export MAC_JPEG_DIR=/path/to/jpeg
# Vulkan-only:
export MAC_VULKAN_HEADERS=/path/to/vulkan-headers
export MAC_VULKAN_LOADER=/path/to/vulkan-loader
export MAC_MOLTENVK=/path/to/molten-vk
```

## What changed for macOS arm64

Summary of the deltas vs upstream:

### Build system
- `src_rebuild/premake5.lua` — `system:macosx` filter with `x64` and
`arm64` platforms, Homebrew `includedirs`/`libdirs`, framework links
(`Cocoa`, `OpenGL` or `Metal`+`QuartzCore`+`IOSurface`+`vulkan`),
rpaths for the brew dylibs. Adds the `--renderer={opengl|vulkan}`
option that gates the OpenGL vs Vulkan source files.
- `src_rebuild/premake5_psycross.lua` — equivalent macOS filter on the
static-lib side, plus `removefiles` to switch `PsyX_render.cpp` ↔
`PsyX_render_vk.cpp` based on the renderer option.
- `src_rebuild/premake_modules/usage/usage.lua` — guard so the custom
`uses` API doesn't collide with the one premake5 ≥ beta8 ships in
core.

### arm64 / 64-bit portability
- `src_rebuild/Game/driver2.h` — `trap()` now uses `__builtin_trap()`
instead of the x86-only `__asm__("int3")`.
- `src_rebuild/PsyCross/include/psx/libgpu.h` — `P_LEN = 3` on arm64
(same value used for x86_64), so the prim-tag struct lays out
identically across all 64-bit targets.
- `src_rebuild/PsyCross/include/psx/types.h` — on LP64 (macOS arm64/x64,
Linux x64) `u_long` and `ulong` map to `uint32_t` so the PSX 32-bit
semantics are preserved. Pre-defines `_U_LONG`/`_U_INT`/`_U_CHAR`/
`_U_SHORT` on macOS to stop `<sys/types.h>` from re-declaring those
types as 64-bit.
- `premake5.lua` adds a forced `-include` of `psx/types.h` on the macOS
filter so those guards are seen before any system header.

### macOS-specific headers
- `<malloc.h>` (non-existent on macOS) replaced by `<stdlib.h>` with a
guard in:
- `src_rebuild/PsyCross/src/psx/LIBCD.C`
- `src_rebuild/utils/fs.cpp`
- `src_rebuild/utils/audio_source/snd_wav_cache.cpp`
- `src_rebuild/utils/targa.cpp`
- `src_rebuild/Game/dr2locale.c`
- `src_rebuild/tools/font_tool/font_tool_main.cpp`
- `LIBCD.C` and `utils/fs.{cpp,h}` — `__unix__` guards extended to
include `__APPLE__` (macOS doesn't define `__unix__`).

### Pointer→int casts on LP64
Pointers are 64-bit on arm64/x86_64; `(int)ptr` loses information and
clang treats that as an error. Routed through `intptr_t` /
`u_intptr`:
- `src_rebuild/Game/dr2locale.h` — `GET_GAME_TXT`/`GET_MISSION_TXT`
- `src_rebuild/Game/C/civ_ai.c` — `Random2((int)straight)`
- `src_rebuild/Game/C/dr2roads.c` — `(int)plane & 3`
- `src_rebuild/Game/C/draw.c` — `primtab`/`primptr` checks
- `src_rebuild/Game/C/event.c` — `FIXEDH((int)ev->node * RSIN(...))`
- `src_rebuild/Game/C/glaunch.c` — `(int)param` in several callbacks
- `src_rebuild/Game/C/mission.c` — `(u_int)((char*)...)`

### Stricter C++ checks
- `src_rebuild/PsyCross/src/psx/LIBETC.C` — pointer→int cast routed
via `intptr_t` (`ResetCallback`/`VSyncCallback`).
- `src_rebuild/PsyCross/src/psx/LIBGPU.C` — explicit `(DR_TPAGE*)opri`
cast.
- `src_rebuild/PsyCross/src/psx/LIBSPU.C` — added `psx/libetc.h`
include for `ResetCallback()`.

### Missing GTE function
- `src_rebuild/Game/C/targets.c:327` — `RotTransPers()` is declared but
not defined inside PsyCross. Replaced with the equivalent
`gte_RotTransPers()` macro and the otz output captured locally.

## Status

- ✅ Clean build on arm64 (Apple Silicon).
- ✅ Native Mach-O arm64 binary (`file` confirms `arm64`).
- ⚠️ macOS OpenGL has been *deprecated* since 10.14 but the legacy
driver still works up to OpenGL 4.1. PsyCross uses GL 2.x so it
runs, though Apple's GL-on-Metal compatibility layer has subtly
different sync behaviour and produces flicker / dropped primitives
on some scenes.
- ⚠️ The Vulkan / MoltenVK backend (opt-in via `--renderer=vulkan`)
side-steps the GL-on-Metal issues. Currently a work-in-progress —
Driver 2 main menu, HUD and 3D world geometry render; some passes
(blend modes, stencil, scissor, framebuffer-back-to-VRAM) are still
in flight.
- ⚠️ A full playtest hasn't been run end-to-end — the game requires
the original Driver 2 assets to launch.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,4 @@ See [Contributing to project](https://github.com/OpenDriver2/REDRIVER2/wiki/Cont
- **Gh0stBlade** - HLE Emulator code used as a base for Psy-Cross [(link)](https://github.com/TOMB5/TOMB5/tree/master/EMULATOR)
- **Ben Lincoln** - [This Dust Remembers What It Once Was](https://www.beneaththewaves.net/Software/This_Dust_Remembers_What_It_Once_Was.html) (*TDR*)
- **Stohrendorf** - [Symdump](https://github.com/stohrendorf/symdump) utility
- **ebellumat** - macOS Apple Silicon (arm64) port, Vulkan / MoltenVK backend
6 changes: 5 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ skip_tags: true
image:
- Visual Studio 2019
- Ubuntu2004
- macos-sonoma

environment:
data_folder: '%APPVEYOR_BUILD_FOLDER%\data'
Expand Down Expand Up @@ -50,6 +51,9 @@ artifacts:

- path: src_rebuild\bin\*\*.tar.gz
name: Linux Binaries

- path: io.github.opendriver2.Redriver2.flatpak
name: Linux Flatpak

- path: src_rebuild/bin/*/REDRIVER2_macOS_arm64_*.tar.gz
name: macOS Binaries
4 changes: 2 additions & 2 deletions data/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pad1device=-1 # player 1 controller device; -1 for automatic assignment
pad2device=-1 # player 2 controller device; -1 for automatic assignment

[render]
windowWidth=1280
windowWidth=960
windowHeight=720
fullscreen=0 # enable full screen mode; it takes screen resolution
pgxpTextureMapping=1
Expand All @@ -97,7 +97,7 @@ fieldOfView=256 # 128..384, 256 is default
disableChicagoBridges=0 # Experimental: also activate AI roads
freeCamera=1 # Press F7 in game to enable
fastLoadingScreens=1
widescreenOverlays=1 # set 1 to see map, bars and stats aligned to screen corners
widescreenOverlays=0 # set 1 to see map, bars and stats aligned to screen corners
driver1music=0 # put Driver 1's MUSIC.BIN as D1MUSIC.BIN to DRIVER2\SOUND folder
overrideContent=0 # this enables texture and car model modding
userChases=RacingFreak,Snoopi,Olanov,Vortex,Fireboyd78
Loading