mirror of
https://github.com/sp00nznet/xboxrecomp.git
synced 2026-12-06 02:22:30 +00:00
Linux port: surgical edits to existing files + Linux-rewritten sources
Mirrored from sp00nznet/burnout3 linux-port branch (commit bc15743),
where these changes were developed and verified to link a 38 MB ELF64
burnout3 binary on Debian 13.
Targeted edits to existing files (windows.h -> portable xbox_winnt.h
include + #if _WIN32 guards on Win32-only bodies):
- src/kernel/kernel.h: windows.h -> platform/xbox_winnt.h
- src/kernel/xbox_memory_layout.h: windows.h -> platform/xbox_winnt.h
- src/kernel/kernel_hal.c: intrin.h guarded; __declspec(thread)
-> XBOX_THREAD_LOCAL macro
- src/kernel/kernel_crypto.c: bcrypt.h + SHA_INTERNAL struct gated
behind #if _WIN32 (dead code, but
SHA-1/RC4/HMAC are portable software)
- src/d3d/d3d8_xbox.h: windows.h -> platform/xbox_winnt.h
- src/d3d/d3d8_internal.h: portable d3d8_GetDevice decl moved
outside the D3D11 section; the rest
is #if _WIN32 (struct wrappers use
ID3D11_* fields)
- src/input/xinput_xbox.h: windows.h -> platform/xbox_winnt.h
- src/audio/dsound_xbox.h: windows.h -> platform/xbox_winnt.h
- src/nv2a/nv2a_mmio_hook.h: windows.h -> platform/xbox_winnt.h
- src/nv2a/qemu_shim.h: #ifdef _WIN32 windows.h block ->
portable xbox_winnt.h include;
removed the #ifdef _WIN32 gate on
QemuMutex/Cond/Thread definitions
(the Win32 API is provided on POSIX
by win32_compat now)
CMakeLists Linux branches (WIN32 keeps existing libs; POSIX links the
platform layer + SDL2 + OpenSSL + libepoxy + libm as appropriate):
- top-level: add src/platform subdir
- src/kernel: link platform + OpenSSL::Crypto on POSIX (replaces bcrypt)
- src/d3d: on POSIX use d3d8_gl.c + SDL2 + libepoxy
- src/input: on POSIX use platform + SDL2 (xinput_device.c is rewritten
with an SDL2 GameController backend under #else)
- src/audio: link platform on POSIX
- src/apu: on POSIX use platform + SDL2 + libm (replaces winmm)
Linux-rewritten source files (copied wholesale from the burnout3 port):
- src/kernel/kernel_path.c: POSIX rewrite under #else (XDG save dir,
UTF-8 paths, mkdir_p)
- src/kernel/kernel_file.c: POSIX rewrite (open/read/pread/stat/opendir
/fnmatch); Win32 path preserved under #if
- src/kernel/kernel_bridge.c: 32-bit<->64-bit handle table (Xbox memory
slots are 32-bit, native HANDLEs are 64-bit);
file-I/O bridges now delegate to xbox_Nt*File
on both platforms
- src/input/xinput_device.c: SDL2 GameController backend (#else block)
- src/apu/apu_mmio_hook.c: g_apu_state moved outside the Win32 guard;
x86-64 VEH instruction decoder #if _WIN32
(POSIX equivalent goes through sigaction +
ucontext_t)
- src/apu/apu_core.c: <mmsystem.h> include guarded; waveOut stays
inactive on POSIX (waveOut* are inert shims
in win32_compat)
- src/nv2a/nv2a_mmio_hook.c: whole body #if _WIN32 + POSIX stubs
- src/nv2a/nv2a_pb_replay.c: include + Win32 helpers swap
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -27,6 +27,11 @@ option(XBOXRECOMP_BUILD_EXAMPLES "Build example programs" OFF)
|
||||
|
||||
# ── Runtime Libraries ─────────────────────────────────────────
|
||||
|
||||
# Platform: Win32/NT type vocabulary + POSIX implementation of generic
|
||||
# Win32 host primitives. Carries no Xbox semantics; provides the foundation
|
||||
# the kernel HLE and the graphics/audio/input layers build on.
|
||||
add_subdirectory(src/platform)
|
||||
|
||||
# Core: Xbox kernel replacement (memory layout, file I/O, threading, sync)
|
||||
add_subdirectory(src/kernel)
|
||||
|
||||
|
||||
@@ -32,4 +32,10 @@ if(MSVC)
|
||||
)
|
||||
endif()
|
||||
|
||||
target_link_libraries(xbox_apu PRIVATE kernel32 winmm)
|
||||
if(WIN32)
|
||||
target_link_libraries(xbox_apu PRIVATE kernel32 winmm)
|
||||
else()
|
||||
# Linux: platform layer (Win32 primitives on POSIX) + SDL2 audio + libm
|
||||
find_package(SDL2 REQUIRED)
|
||||
target_link_libraries(xbox_apu PRIVATE platform SDL2::SDL2 m)
|
||||
endif()
|
||||
|
||||
+52
-2
@@ -21,6 +21,7 @@
|
||||
|
||||
#include "apu_state.h"
|
||||
#include "apu.h"
|
||||
#include "apu_xaudio2.h"
|
||||
#include "fpconv.h"
|
||||
|
||||
/* ============================================================
|
||||
@@ -44,7 +45,7 @@ int g_dbg_voice_monitor = -1;
|
||||
uint64_t g_dbg_muted_voices[4] = { 0 };
|
||||
|
||||
/* Global audio mute — disables all AWD/mixer sound playback */
|
||||
volatile int g_audio_muted = 1; /* Start muted; set to 0 to enable */
|
||||
volatile int g_audio_muted = 0; /* 0 = audio enabled */
|
||||
|
||||
/* ============================================================
|
||||
* Debug frame markers (minimal stubs)
|
||||
@@ -150,11 +151,15 @@ static struct {
|
||||
} g_test_tone = { false, 0.0, 0.0, 0 };
|
||||
|
||||
/* ============================================================
|
||||
* Monitor - waveOut audio output (replaces SDL stubs)
|
||||
* Monitor - Audio output (XAudio2 primary, waveOut fallback)
|
||||
* ============================================================ */
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include <mmsystem.h>
|
||||
#pragma comment(lib, "winmm.lib")
|
||||
#endif
|
||||
/* On Linux, waveOut* are inert stubs from win32_compat.h: the APU's
|
||||
* waveOut fallback path stays inactive and never produces audio. */
|
||||
|
||||
/* Ring of waveOut buffers for double-buffering */
|
||||
#define WAVEOUT_NUM_BUFS 4
|
||||
@@ -179,6 +184,13 @@ void mcpx_apu_monitor_init(MCPXAPUState *d, Error **errp)
|
||||
d->monitor.queued_bytes_low = 1024;
|
||||
d->monitor.queued_bytes_high = 3072;
|
||||
|
||||
/* Try XAudio2 first (lower latency) */
|
||||
if (xa2_init()) {
|
||||
fprintf(stderr, "[APU] Using XAudio2 audio backend\n");
|
||||
return;
|
||||
}
|
||||
fprintf(stderr, "[APU] XAudio2 unavailable, falling back to waveOut\n");
|
||||
|
||||
WAVEFORMATEX wfx = { 0 };
|
||||
wfx.wFormatTag = WAVE_FORMAT_PCM;
|
||||
wfx.nChannels = 2;
|
||||
@@ -214,6 +226,10 @@ void mcpx_apu_monitor_init(MCPXAPUState *d, Error **errp)
|
||||
void mcpx_apu_monitor_finalize(MCPXAPUState *d)
|
||||
{
|
||||
(void)d;
|
||||
if (xa2_is_active()) {
|
||||
xa2_shutdown();
|
||||
return;
|
||||
}
|
||||
if (!g_waveout.initialized) return;
|
||||
|
||||
waveOutReset(g_waveout.hwo);
|
||||
@@ -232,6 +248,40 @@ void mcpx_apu_monitor_frame(MCPXAPUState *d)
|
||||
return;
|
||||
}
|
||||
|
||||
/* XAudio2 path: render and submit a buffer */
|
||||
if (xa2_is_active()) {
|
||||
int buf_size = xa2_get_buffer_size();
|
||||
int16_t xa2_tmp[1024][2]; /* matches XA2_BUF_SAMPLES max */
|
||||
int remaining = buf_size;
|
||||
int out_offset = 0;
|
||||
|
||||
while (remaining > 0) {
|
||||
int chunk = (remaining < MIXER_FRAME_SAMPLES) ? remaining : MIXER_FRAME_SAMPLES;
|
||||
memset(d->monitor.frame_buf, 0, sizeof(d->monitor.frame_buf));
|
||||
|
||||
if (g_test_tone.active && !g_audio_muted) {
|
||||
for (int i = 0; i < chunk; i++) {
|
||||
int16_t s = (int16_t)(sin(g_test_tone.phase) * g_test_tone.amplitude);
|
||||
d->monitor.frame_buf[i][0] = s;
|
||||
d->monitor.frame_buf[i][1] = s;
|
||||
g_test_tone.phase += g_test_tone.phase_inc;
|
||||
if (g_test_tone.phase >= 2.0 * M_PI)
|
||||
g_test_tone.phase -= 2.0 * M_PI;
|
||||
}
|
||||
}
|
||||
|
||||
if (!g_audio_muted)
|
||||
mixer_render(d->monitor.frame_buf, chunk);
|
||||
|
||||
memcpy(xa2_tmp + out_offset, d->monitor.frame_buf, chunk * 2 * sizeof(int16_t));
|
||||
out_offset += chunk;
|
||||
remaining -= chunk;
|
||||
}
|
||||
|
||||
xa2_submit_samples((const int16_t *)xa2_tmp, buf_size);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!g_waveout.initialized) return;
|
||||
|
||||
int idx = g_waveout.next_buf;
|
||||
|
||||
+13
-3
@@ -6,17 +6,25 @@
|
||||
*/
|
||||
|
||||
#include "apu.h"
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/* Global APU state pointer -- referenced from main.c regardless of which
|
||||
* platform's MMIO hook is active, so define it before the #if guard. */
|
||||
MCPXAPUState *g_apu_state = NULL;
|
||||
|
||||
/* The MMIO hook is a Win32-VEH x86-64 instruction decoder. On Linux the
|
||||
* equivalent goes through sigaction + ucontext_t (Stage 2 / main.c). For
|
||||
* now the whole body is Windows-only so apu_emu links on Debian. */
|
||||
#if defined(_WIN32)
|
||||
#include <windows.h>
|
||||
|
||||
/* APU MMIO base in Xbox VA space */
|
||||
#define APU_MMIO_BASE 0xFE800000u
|
||||
#define APU_MMIO_SIZE 0x00080000u /* 512KB */
|
||||
|
||||
/* Global APU state */
|
||||
MCPXAPUState *g_apu_state = NULL;
|
||||
/* (g_apu_state is defined above, outside the Win32 guard) */
|
||||
|
||||
/* Statistics */
|
||||
static int g_apu_mmio_read_count = 0;
|
||||
@@ -251,3 +259,5 @@ bool apu_hook_handle_mmio(PCONTEXT ctx, uintptr_t fault_addr,
|
||||
uint32_t mmio_offset = fault_xbox_va - APU_MMIO_BASE;
|
||||
return apu_decode_and_handle(ctx, mmio_offset, is_write);
|
||||
}
|
||||
|
||||
#endif /* _WIN32 */
|
||||
|
||||
@@ -10,6 +10,11 @@ target_include_directories(xbox_dsound PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
# Links to APU emulation for mixer voices
|
||||
target_link_libraries(xbox_dsound PUBLIC xbox_apu)
|
||||
|
||||
if(NOT WIN32)
|
||||
# Linux: needs the platform layer for NT types / win32_compat
|
||||
target_link_libraries(xbox_dsound PUBLIC platform)
|
||||
endif()
|
||||
|
||||
if(MSVC)
|
||||
target_compile_options(xbox_dsound PRIVATE /W4 /O2)
|
||||
else()
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#define BURNOUT3_DSOUND_XBOX_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <windows.h>
|
||||
#include "platform/xbox_winnt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
+24
-13
@@ -1,21 +1,32 @@
|
||||
# D3D8 → D3D11 Compatibility Layer
|
||||
# Implements Xbox D3D8 interface backed by Direct3D 11
|
||||
# Xbox D3D8 Compatibility Layer
|
||||
# _WIN32 -> backed by Direct3D 11 (d3d8_*.c, d3d8_combiners.c, d3d8_vsh.c)
|
||||
# POSIX -> backed by OpenGL 3.3 core via SDL2 + libepoxy (d3d8_gl.c)
|
||||
|
||||
add_library(xbox_d3d8 STATIC
|
||||
d3d8_device.c
|
||||
d3d8_resources.c
|
||||
d3d8_shaders.c
|
||||
d3d8_states.c
|
||||
d3d8_combiners.c
|
||||
d3d8_vsh.c
|
||||
)
|
||||
if(WIN32)
|
||||
add_library(xbox_d3d8 STATIC
|
||||
d3d8_device.c
|
||||
d3d8_resources.c
|
||||
d3d8_shaders.c
|
||||
d3d8_states.c
|
||||
d3d8_combiners.c
|
||||
d3d8_vsh.c
|
||||
)
|
||||
target_link_libraries(xbox_d3d8 PUBLIC d3d11 dxgi dxguid d3dcompiler)
|
||||
else()
|
||||
add_library(xbox_d3d8 STATIC
|
||||
d3d8_gl.c
|
||||
)
|
||||
find_package(SDL2 REQUIRED)
|
||||
find_package(PkgConfig REQUIRED)
|
||||
pkg_check_modules(EPOXY REQUIRED epoxy)
|
||||
target_include_directories(xbox_d3d8 PRIVATE ${EPOXY_INCLUDE_DIRS})
|
||||
target_link_libraries(xbox_d3d8 PUBLIC platform SDL2::SDL2 ${EPOXY_LIBRARIES})
|
||||
endif()
|
||||
|
||||
target_include_directories(xbox_d3d8 PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
target_link_libraries(xbox_d3d8 PUBLIC d3d11 dxgi dxguid d3dcompiler)
|
||||
|
||||
if(MSVC)
|
||||
target_compile_options(xbox_d3d8 PRIVATE /W4 /O2)
|
||||
else()
|
||||
target_compile_options(xbox_d3d8 PRIVATE -Wall -Wextra -O2)
|
||||
target_compile_options(xbox_d3d8 PRIVATE -Wall -Wextra -Wno-unused-parameter -O2)
|
||||
endif()
|
||||
|
||||
@@ -11,6 +11,15 @@
|
||||
#define COBJMACROS
|
||||
#include "d3d8_xbox.h"
|
||||
|
||||
/* Portable: D3D8 device accessor used by recompiled code on both backends
|
||||
* (d3d8_device.c on Windows, d3d8_gl.c on POSIX). */
|
||||
IDirect3DDevice8 *d3d8_GetDevice(void);
|
||||
|
||||
#if defined(_WIN32)
|
||||
/* === Everything below is the D3D11 backend. The POSIX d3d8_compat
|
||||
* library (d3d8_gl.c) implements its own internal state and does not
|
||||
* need any of these declarations. === */
|
||||
|
||||
#include <d3d11.h>
|
||||
#include <dxgi.h>
|
||||
|
||||
@@ -144,4 +153,6 @@ void d3d8_states_apply(void);
|
||||
/* Create sampler state from TSS and apply to slot */
|
||||
void d3d8_states_apply_sampler(DWORD stage);
|
||||
|
||||
#endif /* _WIN32 -- end of D3D11 backend section */
|
||||
|
||||
#endif /* BURNOUT3_D3D8_INTERNAL_H */
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@
|
||||
#define BURNOUT3_D3D8_XBOX_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <windows.h>
|
||||
#include "platform/xbox_winnt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
@@ -6,7 +6,12 @@ add_library(xbox_input STATIC
|
||||
|
||||
target_include_directories(xbox_input PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
target_link_libraries(xbox_input PUBLIC xinput)
|
||||
if(WIN32)
|
||||
target_link_libraries(xbox_input PUBLIC xinput)
|
||||
else()
|
||||
find_package(SDL2 REQUIRED)
|
||||
target_link_libraries(xbox_input PUBLIC platform SDL2::SDL2)
|
||||
endif()
|
||||
|
||||
if(MSVC)
|
||||
target_compile_options(xbox_input PRIVATE /W4 /O2)
|
||||
|
||||
+146
-29
@@ -1,30 +1,31 @@
|
||||
/**
|
||||
* Xbox Input → XInput Compatibility Layer
|
||||
* Xbox Input Compatibility Layer
|
||||
*
|
||||
* Translates Xbox controller API calls to Windows XInput.
|
||||
* Handles the structural differences between Xbox gamepad
|
||||
* (analog buttons as bytes, separate trigger channels) and
|
||||
* XInput (digital buttons, combined trigger axis).
|
||||
* Translates the Xbox controller API to a host gamepad backend.
|
||||
* Handles the structural differences between the Xbox gamepad
|
||||
* (analog buttons as bytes, separate trigger channels) and the host
|
||||
* (digital face buttons, trigger axes).
|
||||
*
|
||||
* Key differences:
|
||||
* - Xbox A/B/X/Y/Black/White are analog (0-255), XInput is digital
|
||||
* - Xbox triggers are analog buttons, XInput treats them as axes
|
||||
* - Xbox has separate L/R trigger values, XInput combines them
|
||||
* _WIN32 -> Windows XInput
|
||||
* POSIX -> SDL2 GameController
|
||||
*/
|
||||
|
||||
#include "xinput_xbox.h"
|
||||
#include <xinput.h>
|
||||
#include <string.h>
|
||||
|
||||
/* ======================================================================== */
|
||||
#if defined(_WIN32)
|
||||
/* ==================== XInput backend ================================== */
|
||||
/* ======================================================================== */
|
||||
|
||||
#include <xinput.h>
|
||||
#pragma comment(lib, "xinput.lib")
|
||||
|
||||
/* Track controller connection state */
|
||||
static BOOL g_controller_connected[XBOX_MAX_CONTROLLERS] = { FALSE };
|
||||
static BOOL g_controller_connected[XBOX_MAX_CONTROLLERS] = { FALSE };
|
||||
static DWORD g_last_packet[XBOX_MAX_CONTROLLERS] = { 0 };
|
||||
|
||||
void xbox_InputInit(void)
|
||||
{
|
||||
/* Probe all controller slots */
|
||||
for (DWORD i = 0; i < XBOX_MAX_CONTROLLERS; i++) {
|
||||
XINPUT_STATE state;
|
||||
DWORD result = XInputGetState(i, &state);
|
||||
@@ -37,9 +38,8 @@ DWORD xbox_InputGetState(DWORD dwPort, XBOX_INPUT_STATE *pState)
|
||||
XINPUT_STATE xi_state;
|
||||
DWORD result;
|
||||
|
||||
if (dwPort >= XBOX_MAX_CONTROLLERS || !pState) {
|
||||
if (dwPort >= XBOX_MAX_CONTROLLERS || !pState)
|
||||
return ERROR_DEVICE_NOT_CONNECTED;
|
||||
}
|
||||
|
||||
result = XInputGetState(dwPort, &xi_state);
|
||||
if (result != ERROR_SUCCESS) {
|
||||
@@ -50,14 +50,10 @@ DWORD xbox_InputGetState(DWORD dwPort, XBOX_INPUT_STATE *pState)
|
||||
g_controller_connected[dwPort] = TRUE;
|
||||
g_last_packet[dwPort] = xi_state.dwPacketNumber;
|
||||
|
||||
/* Translate XInput state to Xbox format */
|
||||
memset(pState, 0, sizeof(XBOX_INPUT_STATE));
|
||||
pState->dwPacketNumber = xi_state.dwPacketNumber;
|
||||
|
||||
/* Digital buttons map directly (same bit positions for d-pad, start, back, thumbs) */
|
||||
pState->Gamepad.wButtons = xi_state.Gamepad.wButtons & 0x00FF;
|
||||
|
||||
/* Analog buttons: XInput has digital A/B/X/Y, we map to 0 or 255 */
|
||||
pState->Gamepad.bAnalogButtons[XBOX_BUTTON_A] =
|
||||
(xi_state.Gamepad.wButtons & XINPUT_GAMEPAD_A) ? 255 : 0;
|
||||
pState->Gamepad.bAnalogButtons[XBOX_BUTTON_B] =
|
||||
@@ -66,18 +62,13 @@ DWORD xbox_InputGetState(DWORD dwPort, XBOX_INPUT_STATE *pState)
|
||||
(xi_state.Gamepad.wButtons & XINPUT_GAMEPAD_X) ? 255 : 0;
|
||||
pState->Gamepad.bAnalogButtons[XBOX_BUTTON_Y] =
|
||||
(xi_state.Gamepad.wButtons & XINPUT_GAMEPAD_Y) ? 255 : 0;
|
||||
|
||||
/* Black/White → Left/Right shoulder */
|
||||
pState->Gamepad.bAnalogButtons[XBOX_BUTTON_BLACK] =
|
||||
(xi_state.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_SHOULDER) ? 255 : 0;
|
||||
pState->Gamepad.bAnalogButtons[XBOX_BUTTON_WHITE] =
|
||||
(xi_state.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_SHOULDER) ? 255 : 0;
|
||||
|
||||
/* Triggers: XInput gives 0-255, matches Xbox analog button range */
|
||||
pState->Gamepad.bAnalogButtons[XBOX_BUTTON_LTRIGGER] = xi_state.Gamepad.bLeftTrigger;
|
||||
pState->Gamepad.bAnalogButtons[XBOX_BUTTON_RTRIGGER] = xi_state.Gamepad.bRightTrigger;
|
||||
|
||||
/* Thumbsticks: same range (-32768 to 32767) */
|
||||
pState->Gamepad.sThumbLX = xi_state.Gamepad.sThumbLX;
|
||||
pState->Gamepad.sThumbLY = xi_state.Gamepad.sThumbLY;
|
||||
pState->Gamepad.sThumbRX = xi_state.Gamepad.sThumbRX;
|
||||
@@ -90,13 +81,11 @@ DWORD xbox_InputSetState(DWORD dwPort, const XBOX_VIBRATION *pVibration)
|
||||
{
|
||||
XINPUT_VIBRATION xi_vib;
|
||||
|
||||
if (dwPort >= XBOX_MAX_CONTROLLERS || !pVibration) {
|
||||
if (dwPort >= XBOX_MAX_CONTROLLERS || !pVibration)
|
||||
return ERROR_DEVICE_NOT_CONNECTED;
|
||||
}
|
||||
|
||||
xi_vib.wLeftMotorSpeed = pVibration->wLeftMotorSpeed;
|
||||
xi_vib.wRightMotorSpeed = pVibration->wRightMotorSpeed;
|
||||
|
||||
return XInputSetState(dwPort, &xi_vib);
|
||||
}
|
||||
|
||||
@@ -111,9 +100,8 @@ DWORD xbox_InputGetCapabilities(DWORD dwPort, DWORD dwFlags, XBOX_INPUT_CAPABILI
|
||||
XINPUT_CAPABILITIES xi_caps;
|
||||
DWORD result;
|
||||
|
||||
if (dwPort >= XBOX_MAX_CONTROLLERS || !pCaps) {
|
||||
if (dwPort >= XBOX_MAX_CONTROLLERS || !pCaps)
|
||||
return ERROR_DEVICE_NOT_CONNECTED;
|
||||
}
|
||||
|
||||
result = XInputGetCapabilities(dwPort, dwFlags, &xi_caps);
|
||||
if (result != ERROR_SUCCESS) return result;
|
||||
@@ -122,6 +110,135 @@ DWORD xbox_InputGetCapabilities(DWORD dwPort, DWORD dwFlags, XBOX_INPUT_CAPABILI
|
||||
pCaps->Type = xi_caps.Type;
|
||||
pCaps->SubType = xi_caps.SubType;
|
||||
pCaps->Flags = xi_caps.Flags;
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
/* ======================================================================== */
|
||||
#else /* !_WIN32 */
|
||||
/* ==================== SDL2 GameController backend ===================== */
|
||||
/* ======================================================================== */
|
||||
|
||||
#include <SDL.h>
|
||||
|
||||
static SDL_GameController *g_pads[XBOX_MAX_CONTROLLERS];
|
||||
static BOOL g_controller_connected[XBOX_MAX_CONTROLLERS];
|
||||
static DWORD g_packet[XBOX_MAX_CONTROLLERS];
|
||||
|
||||
/* Open up to XBOX_MAX_CONTROLLERS attached game controllers. */
|
||||
static void open_controllers(void)
|
||||
{
|
||||
int slot = 0;
|
||||
for (int i = 0; i < SDL_NumJoysticks() && slot < XBOX_MAX_CONTROLLERS; i++) {
|
||||
if (!SDL_IsGameController(i))
|
||||
continue;
|
||||
if (!g_pads[slot]) {
|
||||
g_pads[slot] = SDL_GameControllerOpen(i);
|
||||
g_controller_connected[slot] = (g_pads[slot] != NULL);
|
||||
}
|
||||
slot++;
|
||||
}
|
||||
}
|
||||
|
||||
void xbox_InputInit(void)
|
||||
{
|
||||
if (!SDL_WasInit(SDL_INIT_GAMECONTROLLER))
|
||||
SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER);
|
||||
open_controllers();
|
||||
}
|
||||
|
||||
DWORD xbox_InputGetState(DWORD dwPort, XBOX_INPUT_STATE *pState)
|
||||
{
|
||||
if (dwPort >= XBOX_MAX_CONTROLLERS || !pState)
|
||||
return ERROR_DEVICE_NOT_CONNECTED;
|
||||
|
||||
SDL_GameController *c = g_pads[dwPort];
|
||||
if (!c || !SDL_GameControllerGetAttached(c)) {
|
||||
g_controller_connected[dwPort] = FALSE;
|
||||
return ERROR_DEVICE_NOT_CONNECTED;
|
||||
}
|
||||
|
||||
SDL_GameControllerUpdate();
|
||||
g_controller_connected[dwPort] = TRUE;
|
||||
|
||||
memset(pState, 0, sizeof(XBOX_INPUT_STATE));
|
||||
pState->dwPacketNumber = ++g_packet[dwPort];
|
||||
|
||||
WORD btn = 0;
|
||||
if (SDL_GameControllerGetButton(c, SDL_CONTROLLER_BUTTON_DPAD_UP)) btn |= XBOX_GAMEPAD_DPAD_UP;
|
||||
if (SDL_GameControllerGetButton(c, SDL_CONTROLLER_BUTTON_DPAD_DOWN)) btn |= XBOX_GAMEPAD_DPAD_DOWN;
|
||||
if (SDL_GameControllerGetButton(c, SDL_CONTROLLER_BUTTON_DPAD_LEFT)) btn |= XBOX_GAMEPAD_DPAD_LEFT;
|
||||
if (SDL_GameControllerGetButton(c, SDL_CONTROLLER_BUTTON_DPAD_RIGHT)) btn |= XBOX_GAMEPAD_DPAD_RIGHT;
|
||||
if (SDL_GameControllerGetButton(c, SDL_CONTROLLER_BUTTON_START)) btn |= XBOX_GAMEPAD_START;
|
||||
if (SDL_GameControllerGetButton(c, SDL_CONTROLLER_BUTTON_BACK)) btn |= XBOX_GAMEPAD_BACK;
|
||||
if (SDL_GameControllerGetButton(c, SDL_CONTROLLER_BUTTON_LEFTSTICK)) btn |= XBOX_GAMEPAD_LEFT_THUMB;
|
||||
if (SDL_GameControllerGetButton(c, SDL_CONTROLLER_BUTTON_RIGHTSTICK)) btn |= XBOX_GAMEPAD_RIGHT_THUMB;
|
||||
pState->Gamepad.wButtons = btn;
|
||||
|
||||
pState->Gamepad.bAnalogButtons[XBOX_BUTTON_A] =
|
||||
SDL_GameControllerGetButton(c, SDL_CONTROLLER_BUTTON_A) ? 255 : 0;
|
||||
pState->Gamepad.bAnalogButtons[XBOX_BUTTON_B] =
|
||||
SDL_GameControllerGetButton(c, SDL_CONTROLLER_BUTTON_B) ? 255 : 0;
|
||||
pState->Gamepad.bAnalogButtons[XBOX_BUTTON_X] =
|
||||
SDL_GameControllerGetButton(c, SDL_CONTROLLER_BUTTON_X) ? 255 : 0;
|
||||
pState->Gamepad.bAnalogButtons[XBOX_BUTTON_Y] =
|
||||
SDL_GameControllerGetButton(c, SDL_CONTROLLER_BUTTON_Y) ? 255 : 0;
|
||||
pState->Gamepad.bAnalogButtons[XBOX_BUTTON_BLACK] =
|
||||
SDL_GameControllerGetButton(c, SDL_CONTROLLER_BUTTON_LEFTSHOULDER) ? 255 : 0;
|
||||
pState->Gamepad.bAnalogButtons[XBOX_BUTTON_WHITE] =
|
||||
SDL_GameControllerGetButton(c, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER) ? 255 : 0;
|
||||
|
||||
/* SDL trigger axes are 0..32767 -> Xbox analog button 0..255 */
|
||||
pState->Gamepad.bAnalogButtons[XBOX_BUTTON_LTRIGGER] =
|
||||
(BYTE)(SDL_GameControllerGetAxis(c, SDL_CONTROLLER_AXIS_TRIGGERLEFT) >> 7);
|
||||
pState->Gamepad.bAnalogButtons[XBOX_BUTTON_RTRIGGER] =
|
||||
(BYTE)(SDL_GameControllerGetAxis(c, SDL_CONTROLLER_AXIS_TRIGGERRIGHT) >> 7);
|
||||
|
||||
/* SDL Y axis points down; the Xbox Y axis points up -- invert.
|
||||
* Use (-1 - v) so v = -32768 does not overflow SHORT. */
|
||||
pState->Gamepad.sThumbLX = SDL_GameControllerGetAxis(c, SDL_CONTROLLER_AXIS_LEFTX);
|
||||
pState->Gamepad.sThumbLY =
|
||||
(SHORT)(-1 - SDL_GameControllerGetAxis(c, SDL_CONTROLLER_AXIS_LEFTY));
|
||||
pState->Gamepad.sThumbRX = SDL_GameControllerGetAxis(c, SDL_CONTROLLER_AXIS_RIGHTX);
|
||||
pState->Gamepad.sThumbRY =
|
||||
(SHORT)(-1 - SDL_GameControllerGetAxis(c, SDL_CONTROLLER_AXIS_RIGHTY));
|
||||
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
DWORD xbox_InputSetState(DWORD dwPort, const XBOX_VIBRATION *pVibration)
|
||||
{
|
||||
if (dwPort >= XBOX_MAX_CONTROLLERS || !pVibration)
|
||||
return ERROR_DEVICE_NOT_CONNECTED;
|
||||
|
||||
SDL_GameController *c = g_pads[dwPort];
|
||||
if (!c) return ERROR_DEVICE_NOT_CONNECTED;
|
||||
|
||||
/* SDL rumble needs a duration; refresh for ~1s on each call (the game
|
||||
* polls vibration continuously). */
|
||||
SDL_GameControllerRumble(c, pVibration->wLeftMotorSpeed,
|
||||
pVibration->wRightMotorSpeed, 1000);
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
BOOL xbox_InputIsConnected(DWORD dwPort)
|
||||
{
|
||||
if (dwPort >= XBOX_MAX_CONTROLLERS) return FALSE;
|
||||
return g_controller_connected[dwPort];
|
||||
}
|
||||
|
||||
DWORD xbox_InputGetCapabilities(DWORD dwPort, DWORD dwFlags, XBOX_INPUT_CAPABILITIES *pCaps)
|
||||
{
|
||||
(void)dwFlags;
|
||||
if (dwPort >= XBOX_MAX_CONTROLLERS || !pCaps)
|
||||
return ERROR_DEVICE_NOT_CONNECTED;
|
||||
if (!g_pads[dwPort])
|
||||
return ERROR_DEVICE_NOT_CONNECTED;
|
||||
|
||||
memset(pCaps, 0, sizeof(XBOX_INPUT_CAPABILITIES));
|
||||
pCaps->Type = 1; /* XINPUT_DEVTYPE_GAMEPAD */
|
||||
pCaps->SubType = 1; /* XINPUT_DEVSUBTYPE_GAMEPAD */
|
||||
pCaps->Flags = 0;
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
#endif /* _WIN32 */
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#define BURNOUT3_XINPUT_XBOX_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <windows.h>
|
||||
#include "platform/xbox_winnt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
@@ -24,9 +24,18 @@ set(KERNEL_SOURCES
|
||||
|
||||
add_library(xbox_kernel STATIC ${KERNEL_SOURCES})
|
||||
|
||||
target_include_directories(xbox_kernel PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
target_include_directories(xbox_kernel PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_SOURCE_DIR}/src
|
||||
)
|
||||
|
||||
target_link_libraries(xbox_kernel PUBLIC kernel32 bcrypt)
|
||||
if(WIN32)
|
||||
target_link_libraries(xbox_kernel PUBLIC kernel32 bcrypt)
|
||||
else()
|
||||
# Linux: platform layer (POSIX host primitives) + OpenSSL for crypto.
|
||||
find_package(OpenSSL REQUIRED)
|
||||
target_link_libraries(xbox_kernel PUBLIC platform OpenSSL::Crypto)
|
||||
endif()
|
||||
|
||||
if(MSVC)
|
||||
target_compile_options(xbox_kernel PRIVATE /W4 /WX- /O2 /GS- /Gy)
|
||||
|
||||
+5
-4
@@ -15,10 +15,11 @@
|
||||
#ifndef XBOX_KERNEL_H
|
||||
#define XBOX_KERNEL_H
|
||||
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
#include <windows.h>
|
||||
/*
|
||||
* NT type vocabulary. On Windows this resolves to <windows.h>; on Linux it
|
||||
* provides the same types natively (see src/platform/xbox_winnt.h).
|
||||
*/
|
||||
#include "platform/xbox_winnt.h"
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
|
||||
+217
-562
File diff suppressed because it is too large
Load Diff
@@ -17,10 +17,15 @@
|
||||
*/
|
||||
|
||||
#include "kernel.h"
|
||||
#include <bcrypt.h>
|
||||
#include <string.h>
|
||||
|
||||
/* SHA-1 / RC4 / HMAC below are portable software implementations, so the
|
||||
* only platform dependency is BCrypt's types in the (unused) SHA_INTERNAL
|
||||
* struct. Keep it Windows-only. */
|
||||
#if defined(_WIN32)
|
||||
#include <bcrypt.h>
|
||||
#pragma comment(lib, "bcrypt.lib")
|
||||
#endif
|
||||
|
||||
/* ============================================================================
|
||||
* SHA-1
|
||||
@@ -33,11 +38,13 @@
|
||||
/* We use a wrapper since XBOX_SHA_CONTEXT may not be large enough for
|
||||
* BCrypt's internal state. Store BCrypt handles in a separate mapping. */
|
||||
|
||||
#if defined(_WIN32)
|
||||
typedef struct _SHA_INTERNAL {
|
||||
BCRYPT_ALG_HANDLE hAlg;
|
||||
BCRYPT_HASH_HANDLE hHash;
|
||||
UCHAR hashObject[256]; /* BCrypt hash object buffer */
|
||||
} SHA_INTERNAL;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Since XBOX_SHA_CONTEXT is only 92 bytes (State[5] + Count[2] + Buffer[64]),
|
||||
|
||||
+646
-306
File diff suppressed because it is too large
Load Diff
@@ -12,7 +12,9 @@
|
||||
*/
|
||||
|
||||
#include "kernel.h"
|
||||
#if defined(_WIN32)
|
||||
#include <intrin.h>
|
||||
#endif
|
||||
|
||||
/* ============================================================================
|
||||
* IRQL Simulation
|
||||
@@ -27,7 +29,7 @@
|
||||
* allows code that checks IRQL to function correctly.
|
||||
* ============================================================================ */
|
||||
|
||||
static __declspec(thread) KIRQL g_current_irql = PASSIVE_LEVEL;
|
||||
static XBOX_THREAD_LOCAL KIRQL g_current_irql = PASSIVE_LEVEL;
|
||||
|
||||
/*
|
||||
* KfRaiseIrql - Raises IRQL to the specified level.
|
||||
|
||||
+234
-165
@@ -1,64 +1,26 @@
|
||||
/*
|
||||
* kernel_path.c - Xbox→Windows Path Translation
|
||||
* kernel_path.c - Xbox device-path translation
|
||||
*
|
||||
* Translates Xbox device-style paths to Windows filesystem paths:
|
||||
* \Device\CdRom0\ → <game_dir>\Burnout 3 Takedown\
|
||||
* D:\ → <game_dir>\Burnout 3 Takedown\
|
||||
* T:\ → <save_dir>\TitleData\
|
||||
* U:\ → <save_dir>\UserData\
|
||||
* Z:\ → <save_dir>\Cache\
|
||||
* Translates Xbox device-style paths to host filesystem paths:
|
||||
* \Device\CdRom0\ -> <game_dir>/
|
||||
* D:\ -> <game_dir>/
|
||||
* T:\ -> <save_dir>/TitleData/
|
||||
* U:\ -> <save_dir>/UserData/
|
||||
* Z:\ -> <save_dir>/Cache/
|
||||
*
|
||||
* The Win32 build emits UTF-16 paths (for CreateFileW); the Linux build
|
||||
* emits UTF-8 paths with '/' separators (for open()).
|
||||
*/
|
||||
|
||||
#include "kernel.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <shlobj.h>
|
||||
|
||||
/* Base directories - set at init */
|
||||
static WCHAR s_game_dir[MAX_PATH]; /* Path to game disc content */
|
||||
static WCHAR s_save_dir[MAX_PATH]; /* Base for save/cache directories */
|
||||
static BOOL s_initialized = FALSE;
|
||||
|
||||
void xbox_path_init(const char* game_dir, const char* save_dir)
|
||||
{
|
||||
WCHAR save_base[MAX_PATH];
|
||||
|
||||
if (game_dir) {
|
||||
MultiByteToWideChar(CP_UTF8, 0, game_dir, -1, s_game_dir, MAX_PATH);
|
||||
} else {
|
||||
/* Default: current directory + "Burnout 3 Takedown" */
|
||||
GetCurrentDirectoryW(MAX_PATH, s_game_dir);
|
||||
wcscat_s(s_game_dir, MAX_PATH, L"\\Burnout 3 Takedown");
|
||||
}
|
||||
|
||||
if (save_dir) {
|
||||
MultiByteToWideChar(CP_UTF8, 0, save_dir, -1, s_save_dir, MAX_PATH);
|
||||
} else {
|
||||
/* Default: AppData\Local\Burnout3 */
|
||||
if (SUCCEEDED(SHGetFolderPathW(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, save_base))) {
|
||||
swprintf_s(s_save_dir, MAX_PATH, L"%s\\Burnout3", save_base);
|
||||
} else {
|
||||
GetCurrentDirectoryW(MAX_PATH, s_save_dir);
|
||||
wcscat_s(s_save_dir, MAX_PATH, L"\\SaveData");
|
||||
}
|
||||
}
|
||||
|
||||
/* Ensure trailing backslashes are stripped for consistent concatenation */
|
||||
size_t len = wcslen(s_game_dir);
|
||||
if (len > 0 && s_game_dir[len - 1] == L'\\')
|
||||
s_game_dir[len - 1] = L'\0';
|
||||
|
||||
len = wcslen(s_save_dir);
|
||||
if (len > 0 && s_save_dir[len - 1] == L'\\')
|
||||
s_save_dir[len - 1] = L'\0';
|
||||
|
||||
s_initialized = TRUE;
|
||||
xbox_log(XBOX_LOG_INFO, XBOX_LOG_PATH, "Path init: game=%S, save=%S", s_game_dir, s_save_dir);
|
||||
}
|
||||
#include <ctype.h>
|
||||
|
||||
/*
|
||||
* Helper: check if an ANSI string starts with a prefix (case-insensitive).
|
||||
* Returns the number of chars consumed from the prefix, or 0 if no match.
|
||||
* Platform-independent.
|
||||
*/
|
||||
static int match_prefix(const char* path, const char* prefix)
|
||||
{
|
||||
@@ -71,121 +33,96 @@ static int match_prefix(const char* path, const char* prefix)
|
||||
return i;
|
||||
}
|
||||
|
||||
BOOL xbox_translate_path(const char* xbox_path, WCHAR* win_path_buf, DWORD buf_size)
|
||||
{
|
||||
const char* remainder = NULL;
|
||||
const WCHAR* base_dir = NULL;
|
||||
const WCHAR* sub_dir = NULL;
|
||||
int skip;
|
||||
/* A device-path translation rule, shared by both backends. */
|
||||
typedef struct {
|
||||
const char* prefix; /* Xbox path prefix (backslash form) */
|
||||
int to_save; /* 1 = under save_dir, 0 = under game_dir */
|
||||
const char* sub_win; /* sub-directory, Win32 backslash form */
|
||||
const char* sub_posix; /* sub-directory, POSIX slash form */
|
||||
} path_rule;
|
||||
|
||||
if (!xbox_path || !win_path_buf || buf_size == 0)
|
||||
static const path_rule s_rules[] = {
|
||||
{ "\\Device\\CdRom0\\", 0, NULL, NULL },
|
||||
{ "\\Device\\Harddisk0\\Partition1\\", 0, NULL, NULL },
|
||||
{ "D:\\", 0, NULL, NULL },
|
||||
{ "d:\\", 0, NULL, NULL },
|
||||
{ "T:\\", 1, "\\TitleData","/TitleData" },
|
||||
{ "U:\\", 1, "\\UserData", "/UserData" },
|
||||
{ "Z:\\", 1, "\\Cache", "/Cache" },
|
||||
{ "\\??\\D:\\", 0, NULL, NULL },
|
||||
{ "\\??\\T:\\", 1, "\\TitleData","/TitleData" },
|
||||
};
|
||||
#define PATH_RULE_COUNT ((int)(sizeof(s_rules) / sizeof(s_rules[0])))
|
||||
|
||||
/* ======================================================================== */
|
||||
#if defined(_WIN32)
|
||||
/* ======================================================================== */
|
||||
|
||||
#include <shlobj.h>
|
||||
|
||||
static WCHAR s_game_dir[MAX_PATH];
|
||||
static WCHAR s_save_dir[MAX_PATH];
|
||||
static BOOL s_initialized = FALSE;
|
||||
|
||||
void xbox_path_init(const char* game_dir, const char* save_dir)
|
||||
{
|
||||
WCHAR save_base[MAX_PATH];
|
||||
|
||||
if (game_dir) {
|
||||
MultiByteToWideChar(CP_UTF8, 0, game_dir, -1, s_game_dir, MAX_PATH);
|
||||
} else {
|
||||
GetCurrentDirectoryW(MAX_PATH, s_game_dir);
|
||||
wcscat_s(s_game_dir, MAX_PATH, L"\\Burnout 3 Takedown");
|
||||
}
|
||||
|
||||
if (save_dir) {
|
||||
MultiByteToWideChar(CP_UTF8, 0, save_dir, -1, s_save_dir, MAX_PATH);
|
||||
} else {
|
||||
if (SUCCEEDED(SHGetFolderPathW(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, save_base))) {
|
||||
swprintf_s(s_save_dir, MAX_PATH, L"%s\\Burnout3", save_base);
|
||||
} else {
|
||||
GetCurrentDirectoryW(MAX_PATH, s_save_dir);
|
||||
wcscat_s(s_save_dir, MAX_PATH, L"\\SaveData");
|
||||
}
|
||||
}
|
||||
|
||||
size_t len = wcslen(s_game_dir);
|
||||
if (len > 0 && s_game_dir[len - 1] == L'\\')
|
||||
s_game_dir[len - 1] = L'\0';
|
||||
|
||||
len = wcslen(s_save_dir);
|
||||
if (len > 0 && s_save_dir[len - 1] == L'\\')
|
||||
s_save_dir[len - 1] = L'\0';
|
||||
|
||||
s_initialized = TRUE;
|
||||
xbox_log(XBOX_LOG_INFO, XBOX_LOG_PATH, "Path init: game=%S, save=%S", s_game_dir, s_save_dir);
|
||||
}
|
||||
|
||||
BOOL xbox_translate_path(const char* xbox_path, xbox_host_char* host_path_buf, DWORD buf_size)
|
||||
{
|
||||
const char* remainder = NULL;
|
||||
const WCHAR* base_dir = NULL;
|
||||
const char* sub_dir = NULL;
|
||||
int skip;
|
||||
|
||||
if (!xbox_path || !host_path_buf || buf_size == 0)
|
||||
return FALSE;
|
||||
|
||||
if (!s_initialized)
|
||||
xbox_path_init(NULL, NULL);
|
||||
|
||||
/* \Device\CdRom0\ → game disc */
|
||||
skip = match_prefix(xbox_path, "\\Device\\CdRom0\\");
|
||||
if (skip) {
|
||||
remainder = xbox_path + skip;
|
||||
base_dir = s_game_dir;
|
||||
sub_dir = NULL;
|
||||
goto translate;
|
||||
for (int i = 0; i < PATH_RULE_COUNT; i++) {
|
||||
skip = match_prefix(xbox_path, s_rules[i].prefix);
|
||||
if (skip) {
|
||||
remainder = xbox_path + skip;
|
||||
base_dir = s_rules[i].to_save ? s_save_dir : s_game_dir;
|
||||
sub_dir = s_rules[i].sub_win;
|
||||
goto translate;
|
||||
}
|
||||
}
|
||||
|
||||
/* \Device\Harddisk0\Partition1\ → game disc (alternative) */
|
||||
skip = match_prefix(xbox_path, "\\Device\\Harddisk0\\Partition1\\");
|
||||
if (skip) {
|
||||
remainder = xbox_path + skip;
|
||||
base_dir = s_game_dir;
|
||||
sub_dir = NULL;
|
||||
goto translate;
|
||||
}
|
||||
|
||||
/* C:\ → system partition (dashboard files, XIP archives) */
|
||||
skip = match_prefix(xbox_path, "C:\\");
|
||||
if (skip) {
|
||||
remainder = xbox_path + skip;
|
||||
base_dir = s_game_dir;
|
||||
sub_dir = NULL;
|
||||
goto translate;
|
||||
}
|
||||
|
||||
/* c:\ (lowercase variant) */
|
||||
skip = match_prefix(xbox_path, "c:\\");
|
||||
if (skip) {
|
||||
remainder = xbox_path + skip;
|
||||
base_dir = s_game_dir;
|
||||
sub_dir = NULL;
|
||||
goto translate;
|
||||
}
|
||||
|
||||
/* D:\ → game disc */
|
||||
skip = match_prefix(xbox_path, "D:\\");
|
||||
if (skip) {
|
||||
remainder = xbox_path + skip;
|
||||
base_dir = s_game_dir;
|
||||
sub_dir = NULL;
|
||||
goto translate;
|
||||
}
|
||||
|
||||
/* d:\ (lowercase variant) */
|
||||
skip = match_prefix(xbox_path, "d:\\");
|
||||
if (skip) {
|
||||
remainder = xbox_path + skip;
|
||||
base_dir = s_game_dir;
|
||||
sub_dir = NULL;
|
||||
goto translate;
|
||||
}
|
||||
|
||||
/* T:\ → TitleData (save games) */
|
||||
skip = match_prefix(xbox_path, "T:\\");
|
||||
if (!skip) skip = match_prefix(xbox_path, "t:\\");
|
||||
if (skip) {
|
||||
remainder = xbox_path + skip;
|
||||
base_dir = s_save_dir;
|
||||
sub_dir = L"\\TitleData";
|
||||
goto translate;
|
||||
}
|
||||
|
||||
/* U:\ → UserData */
|
||||
skip = match_prefix(xbox_path, "U:\\");
|
||||
if (skip) {
|
||||
remainder = xbox_path + skip;
|
||||
base_dir = s_save_dir;
|
||||
sub_dir = L"\\UserData";
|
||||
goto translate;
|
||||
}
|
||||
|
||||
/* Z:\ → Cache */
|
||||
skip = match_prefix(xbox_path, "Z:\\");
|
||||
if (skip) {
|
||||
remainder = xbox_path + skip;
|
||||
base_dir = s_save_dir;
|
||||
sub_dir = L"\\Cache";
|
||||
goto translate;
|
||||
}
|
||||
|
||||
/* \??\D:\ variant (NT object manager prefix) */
|
||||
skip = match_prefix(xbox_path, "\\??\\D:\\");
|
||||
if (skip) {
|
||||
remainder = xbox_path + skip;
|
||||
base_dir = s_game_dir;
|
||||
sub_dir = NULL;
|
||||
goto translate;
|
||||
}
|
||||
|
||||
skip = match_prefix(xbox_path, "\\??\\T:\\");
|
||||
if (skip) {
|
||||
remainder = xbox_path + skip;
|
||||
base_dir = s_save_dir;
|
||||
sub_dir = L"\\TitleData";
|
||||
goto translate;
|
||||
}
|
||||
|
||||
/* Unrecognized path - try to use as-is by converting to wide */
|
||||
xbox_log(XBOX_LOG_WARN, XBOX_LOG_PATH, "Unrecognized Xbox path: %s", xbox_path);
|
||||
MultiByteToWideChar(CP_ACP, 0, xbox_path, -1, win_path_buf, buf_size);
|
||||
MultiByteToWideChar(CP_ACP, 0, xbox_path, -1, host_path_buf, buf_size);
|
||||
return TRUE;
|
||||
|
||||
translate:
|
||||
@@ -193,26 +130,158 @@ translate:
|
||||
WCHAR remainder_wide[MAX_PATH];
|
||||
MultiByteToWideChar(CP_ACP, 0, remainder, -1, remainder_wide, MAX_PATH);
|
||||
|
||||
/* Convert forward slashes to backslashes in remainder */
|
||||
for (WCHAR* p = remainder_wide; *p; p++) {
|
||||
if (*p == L'/') *p = L'\\';
|
||||
}
|
||||
|
||||
if (sub_dir) {
|
||||
swprintf_s(win_path_buf, buf_size, L"%s%s\\%s", base_dir, sub_dir, remainder_wide);
|
||||
} else {
|
||||
swprintf_s(win_path_buf, buf_size, L"%s\\%s", base_dir, remainder_wide);
|
||||
}
|
||||
WCHAR sub_wide[MAX_PATH];
|
||||
MultiByteToWideChar(CP_ACP, 0, sub_dir, -1, sub_wide, MAX_PATH);
|
||||
swprintf_s(host_path_buf, buf_size, L"%s%s\\%s", base_dir, sub_wide, remainder_wide);
|
||||
|
||||
/* Ensure save directories exist */
|
||||
if (sub_dir) {
|
||||
WCHAR dir_path[MAX_PATH];
|
||||
swprintf_s(dir_path, MAX_PATH, L"%s%s", base_dir, sub_dir);
|
||||
swprintf_s(dir_path, MAX_PATH, L"%s%s", base_dir, sub_wide);
|
||||
CreateDirectoryW(s_save_dir, NULL);
|
||||
CreateDirectoryW(dir_path, NULL);
|
||||
} else {
|
||||
swprintf_s(host_path_buf, buf_size, L"%s\\%s", base_dir, remainder_wide);
|
||||
}
|
||||
|
||||
XBOX_TRACE(XBOX_LOG_PATH, "%s -> %S", xbox_path, win_path_buf);
|
||||
XBOX_TRACE(XBOX_LOG_PATH, "%s -> %S", xbox_path, host_path_buf);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/* ======================================================================== */
|
||||
#else /* !_WIN32 -- POSIX / Linux */
|
||||
/* ======================================================================== */
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <errno.h>
|
||||
|
||||
static char s_game_dir[MAX_PATH];
|
||||
static char s_save_dir[MAX_PATH];
|
||||
static BOOL s_initialized = FALSE;
|
||||
|
||||
/* Strip a single trailing '/' (but never the root '/'). */
|
||||
static void strip_trailing_slash(char* s)
|
||||
{
|
||||
size_t len = strlen(s);
|
||||
if (len > 1 && s[len - 1] == '/')
|
||||
s[len - 1] = '\0';
|
||||
}
|
||||
|
||||
/* Recursively create a directory and all missing parents. */
|
||||
static void mkdir_p(const char* path)
|
||||
{
|
||||
char tmp[MAX_PATH];
|
||||
size_t len = strlen(path);
|
||||
if (len == 0 || len >= sizeof(tmp))
|
||||
return;
|
||||
memcpy(tmp, path, len + 1);
|
||||
|
||||
for (char* p = tmp + 1; *p; p++) {
|
||||
if (*p == '/') {
|
||||
*p = '\0';
|
||||
if (mkdir(tmp, 0755) != 0 && errno != EEXIST)
|
||||
xbox_log(XBOX_LOG_WARN, XBOX_LOG_PATH, "mkdir %s: %s", tmp, strerror(errno));
|
||||
*p = '/';
|
||||
}
|
||||
}
|
||||
if (mkdir(tmp, 0755) != 0 && errno != EEXIST)
|
||||
xbox_log(XBOX_LOG_WARN, XBOX_LOG_PATH, "mkdir %s: %s", tmp, strerror(errno));
|
||||
}
|
||||
|
||||
void xbox_path_init(const char* game_dir, const char* save_dir)
|
||||
{
|
||||
if (game_dir) {
|
||||
snprintf(s_game_dir, sizeof(s_game_dir), "%s", game_dir);
|
||||
} else {
|
||||
char cwd[MAX_PATH];
|
||||
if (!getcwd(cwd, sizeof(cwd)))
|
||||
snprintf(cwd, sizeof(cwd), ".");
|
||||
snprintf(s_game_dir, sizeof(s_game_dir), "%s/Burnout 3 Takedown", cwd);
|
||||
}
|
||||
|
||||
if (save_dir) {
|
||||
snprintf(s_save_dir, sizeof(s_save_dir), "%s", save_dir);
|
||||
} else {
|
||||
/* XDG base-directory spec: $XDG_DATA_HOME or ~/.local/share */
|
||||
const char* xdg = getenv("XDG_DATA_HOME");
|
||||
if (xdg && xdg[0]) {
|
||||
snprintf(s_save_dir, sizeof(s_save_dir), "%s/burnout3", xdg);
|
||||
} else {
|
||||
const char* home = getenv("HOME");
|
||||
snprintf(s_save_dir, sizeof(s_save_dir), "%s/.local/share/burnout3",
|
||||
(home && home[0]) ? home : ".");
|
||||
}
|
||||
}
|
||||
|
||||
strip_trailing_slash(s_game_dir);
|
||||
strip_trailing_slash(s_save_dir);
|
||||
|
||||
s_initialized = TRUE;
|
||||
xbox_log(XBOX_LOG_INFO, XBOX_LOG_PATH, "Path init: game=%s, save=%s",
|
||||
s_game_dir, s_save_dir);
|
||||
}
|
||||
|
||||
BOOL xbox_translate_path(const char* xbox_path, xbox_host_char* host_path_buf, DWORD buf_size)
|
||||
{
|
||||
const char* remainder = NULL;
|
||||
const char* base_dir = NULL;
|
||||
const char* sub_dir = NULL;
|
||||
int skip;
|
||||
|
||||
if (!xbox_path || !host_path_buf || buf_size == 0)
|
||||
return FALSE;
|
||||
|
||||
if (!s_initialized)
|
||||
xbox_path_init(NULL, NULL);
|
||||
|
||||
for (int i = 0; i < PATH_RULE_COUNT; i++) {
|
||||
skip = match_prefix(xbox_path, s_rules[i].prefix);
|
||||
if (skip) {
|
||||
remainder = xbox_path + skip;
|
||||
base_dir = s_rules[i].to_save ? s_save_dir : s_game_dir;
|
||||
sub_dir = s_rules[i].sub_posix;
|
||||
goto translate;
|
||||
}
|
||||
}
|
||||
|
||||
/* Unrecognized path: pass through, just normalize separators. */
|
||||
xbox_log(XBOX_LOG_WARN, XBOX_LOG_PATH, "Unrecognized Xbox path: %s", xbox_path);
|
||||
snprintf(host_path_buf, buf_size, "%s", xbox_path);
|
||||
for (char* p = host_path_buf; *p; p++)
|
||||
if (*p == '\\') *p = '/';
|
||||
return TRUE;
|
||||
|
||||
translate:
|
||||
{
|
||||
char remainder_posix[MAX_PATH];
|
||||
snprintf(remainder_posix, sizeof(remainder_posix), "%s", remainder);
|
||||
|
||||
/* Xbox paths use backslashes -> POSIX slashes. */
|
||||
for (char* p = remainder_posix; *p; p++)
|
||||
if (*p == '\\') *p = '/';
|
||||
|
||||
if (sub_dir) {
|
||||
snprintf(host_path_buf, buf_size, "%s%s/%s",
|
||||
base_dir, sub_dir, remainder_posix);
|
||||
|
||||
/* Ensure the save directory tree exists. */
|
||||
char dir_path[MAX_PATH];
|
||||
snprintf(dir_path, sizeof(dir_path), "%s%s", base_dir, sub_dir);
|
||||
mkdir_p(dir_path);
|
||||
} else {
|
||||
snprintf(host_path_buf, buf_size, "%s/%s", base_dir, remainder_posix);
|
||||
}
|
||||
|
||||
XBOX_TRACE(XBOX_LOG_PATH, "%s -> %s", xbox_path, host_path_buf);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* _WIN32 */
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
#ifndef XBOX_MEMORY_LAYOUT_H
|
||||
#define XBOX_MEMORY_LAYOUT_H
|
||||
|
||||
#include <windows.h>
|
||||
#include "platform/xbox_winnt.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -24,6 +24,12 @@ static int g_mmio_read_count = 0;
|
||||
static int g_mmio_write_count = 0;
|
||||
static int g_mmio_decode_fail = 0;
|
||||
|
||||
/* Global APU state pointer is declared in apu.h and referenced from main.c
|
||||
* (regardless of whether the MMIO hook is active). Keep its definition
|
||||
* outside the Win32 guard. */
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
||||
/* ============================================================
|
||||
* x86-64 register access helpers
|
||||
* ============================================================ */
|
||||
@@ -410,3 +416,17 @@ bool nv2a_hook_handle_vram(uintptr_t fault_addr, uint32_t fault_xbox_va)
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#else /* !_WIN32 -- SIGSEGV-based MMIO trapping deferred to main.c port */
|
||||
|
||||
void nv2a_hook_init(ptrdiff_t xbox_mem_offset)
|
||||
{ (void)xbox_mem_offset; }
|
||||
|
||||
bool nv2a_hook_handle_mmio(PCONTEXT ctx, uintptr_t fault_addr,
|
||||
uint32_t fault_xbox_va, int is_write)
|
||||
{ (void)ctx; (void)fault_addr; (void)fault_xbox_va; (void)is_write; return false; }
|
||||
|
||||
bool nv2a_hook_handle_vram(uintptr_t fault_addr, uint32_t fault_xbox_va)
|
||||
{ (void)fault_addr; (void)fault_xbox_va; return false; }
|
||||
|
||||
#endif /* _WIN32 */
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#ifndef BURNOUT3_NV2A_MMIO_HOOK_H
|
||||
#define BURNOUT3_NV2A_MMIO_HOOK_H
|
||||
|
||||
#include <windows.h>
|
||||
#include "platform/xbox_winnt.h"
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
|
||||
@@ -21,12 +21,10 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include "platform/xbox_winnt.h"
|
||||
#include "../d3d/d3d8_xbox.h"
|
||||
|
||||
/* Captured push buffer data for each menu state (game-specific) */
|
||||
#ifdef GAME_HAS_PB_DATA
|
||||
/* Captured push buffer data for each menu state */
|
||||
#include "menu_pushbuffer_data.h"
|
||||
#include "menu_pb_main_menu.h"
|
||||
#include "menu_pb_world_tour.h"
|
||||
@@ -36,17 +34,6 @@
|
||||
#include "menu_pb_road_rage.h"
|
||||
#include "menu_pb_crash_select.h"
|
||||
#include "menu_pb_driver_details.h"
|
||||
#endif
|
||||
|
||||
/* The entire replay implementation is game-specific (burnout3 menu system).
|
||||
* When GAME_HAS_PB_DATA is not defined, provide empty stubs. */
|
||||
#ifndef GAME_HAS_PB_DATA
|
||||
|
||||
void nv2a_pb_replay_frame(void) {}
|
||||
void nv2a_pb_replay_set_active(int active) { (void)active; }
|
||||
int nv2a_pb_replay_is_active(void) { return 0; }
|
||||
|
||||
#else /* GAME_HAS_PB_DATA */
|
||||
|
||||
/* Push buffer command encoding */
|
||||
#define PB_INC_MASK 0xE0030003
|
||||
@@ -351,5 +338,3 @@ int nv2a_pb_replay_is_active(void)
|
||||
{
|
||||
return g_replay_active;
|
||||
}
|
||||
|
||||
#endif /* GAME_HAS_PB_DATA */
|
||||
|
||||
+4
-11
@@ -18,12 +18,9 @@
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
#include <windows.h>
|
||||
#endif
|
||||
/* The QEMU shim uses Win32-style threading primitives. On Windows this comes
|
||||
* from <windows.h>; on POSIX it comes from win32_compat (via xbox_winnt.h). */
|
||||
#include "platform/xbox_winnt.h"
|
||||
|
||||
/* ============================================================
|
||||
* Basic QEMU types
|
||||
@@ -101,11 +98,9 @@ static inline uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c) {
|
||||
#endif
|
||||
|
||||
/* ============================================================
|
||||
* Threading (replace QEMU mutexes with Win32 equivalents)
|
||||
* Threading (Win32-style; portable via win32_compat on POSIX)
|
||||
* ============================================================ */
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
typedef struct QemuMutex {
|
||||
CRITICAL_SECTION cs;
|
||||
} QemuMutex;
|
||||
@@ -147,8 +142,6 @@ static inline void qemu_cond_wait(QemuCond *c, QemuMutex *m) {
|
||||
SleepConditionVariableCS(&c->cv, &m->cs, INFINITE);
|
||||
}
|
||||
|
||||
#endif /* _WIN32 */
|
||||
|
||||
/* ============================================================
|
||||
* Memory regions (stub)
|
||||
* ============================================================ */
|
||||
|
||||
Reference in New Issue
Block a user