diff --git a/.gitmodules b/.gitmodules index d24c43d0..7216cf44 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,7 @@ [submodule "thirdparty/PowerRecomp"] path = thirdparty/PowerRecomp url = https://github.com/hedge-dev/PowerRecomp +[submodule "thirdparty/SDL"] + path = thirdparty/SDL + url = https://github.com/libsdl-org/SDL.git + branch = SDL2 diff --git a/CMakeLists.txt b/CMakeLists.txt index ec9d2137..f7c07e1d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,8 @@ endif() set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") +set(SDL_STATIC ON) + add_subdirectory(${SWA_THIRDPARTY_ROOT}) project("UnleashedRecomp-ALL") diff --git a/UnleashedRecomp/CMakeLists.txt b/UnleashedRecomp/CMakeLists.txt index bcac3205..573d4119 100644 --- a/UnleashedRecomp/CMakeLists.txt +++ b/UnleashedRecomp/CMakeLists.txt @@ -3,6 +3,7 @@ set(TARGET_NAME "SWA") file(GLOB "*.cpp") add_compile_definitions(SWA_IMPL) +add_compile_definitions(SDL_MAIN_HANDLED) add_compile_options( "/D_HAS_EXCEPTIONS=0" "/fp:strict" @@ -14,6 +15,11 @@ add_compile_options( file(GLOB SWA_RECOMPILED_SOURCES "ppc/*.cpp") +set(SWA_PRECOMPILED_HEADERS + "ppc/ppc_recomp_shared.h" + "stdafx.h" +) + set(SWA_KERNEL_CXX_SOURCES "kernel/imports.cpp" "kernel/xdm.cpp" @@ -30,6 +36,7 @@ set(SWA_CPU_CXX_SOURCES set(SWA_GPU_CXX_SOURCES "gpu/window.cpp" + "gpu/video.cpp" ) set(SWA_APU_CXX_SOURCES @@ -54,13 +61,14 @@ add_executable(UnleashedRecomp ${SWA_RECOMPILED_SOURCES} ${SWA_CXX_SOURCES}) set_target_properties(UnleashedRecomp PROPERTIES OUTPUT_NAME ${TARGET_NAME}) target_link_libraries(UnleashedRecomp PUBLIC - PowerUtils - o1heap - xxHash::xxhash - unordered_dense::unordered_dense + PowerUtils + o1heap + xxHash::xxhash + unordered_dense::unordered_dense + SDL2::SDL2-static winmm ntdll comctl32 ) target_include_directories(UnleashedRecomp PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) -target_precompile_headers(UnleashedRecomp PUBLIC "ppc/ppc_recomp_shared.h") +target_precompile_headers(UnleashedRecomp PUBLIC ${SWA_PRECOMPILED_HEADERS}) diff --git a/UnleashedRecomp/cpu/guest_thread.cpp b/UnleashedRecomp/cpu/guest_thread.cpp index 0edb3464..b5338cb2 100644 --- a/UnleashedRecomp/cpu/guest_thread.cpp +++ b/UnleashedRecomp/cpu/guest_thread.cpp @@ -136,8 +136,3 @@ DWORD SetThreadIdealProcessorImpl(uint32_t hThread, DWORD dwIdealProcessor) GUEST_FUNCTION_HOOK(sub_82DFA2E8, SetThreadNameImpl); GUEST_FUNCTION_HOOK(sub_82BD57A8, GetThreadPriorityImpl); GUEST_FUNCTION_HOOK(sub_82BD5910, SetThreadIdealProcessorImpl); - -void GuestThread::InitHooks() -{ - -} diff --git a/UnleashedRecomp/cpu/guest_thread.h b/UnleashedRecomp/cpu/guest_thread.h index e37fad85..fd7f8ff7 100644 --- a/UnleashedRecomp/cpu/guest_thread.h +++ b/UnleashedRecomp/cpu/guest_thread.h @@ -17,5 +17,4 @@ struct GuestThread static void SetThreadName(uint32_t id, const char* name); static void SetLastError(DWORD error); static PPCContext* Invoke(uint32_t address); - static void InitHooks(); -}; \ No newline at end of file +}; diff --git a/UnleashedRecomp/gpu/Window.cpp b/UnleashedRecomp/gpu/Window.cpp index a4b8a232..1bddcd54 100644 --- a/UnleashedRecomp/gpu/Window.cpp +++ b/UnleashedRecomp/gpu/Window.cpp @@ -1 +1,19 @@ -#include "Window.h" \ No newline at end of file +#include "window.h" +#include +#include + +SDL_Window* Window::s_window = nullptr; +void* Window::s_windowHandle = nullptr; + +void Window::Init() +{ + auto title = Config::Language == ELanguage_Japanese + ? "Sonic World Adventure" + : "SONIC UNLEASHED"; + + SDL_InitSubSystem(SDL_INIT_VIDEO); + SDL_EventState(SDL_SYSWMEVENT, SDL_ENABLE); + + s_window = SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, SDL_WINDOW_RESIZABLE); +} + diff --git a/UnleashedRecomp/gpu/Window.h b/UnleashedRecomp/gpu/Window.h index 7b9637ef..a0457388 100644 --- a/UnleashedRecomp/gpu/Window.h +++ b/UnleashedRecomp/gpu/Window.h @@ -1 +1,10 @@ -#pragma once \ No newline at end of file +#pragma once +#include + +struct Window +{ + static SDL_Window* s_window; + static void* s_windowHandle; + + static void Init(); +}; diff --git a/UnleashedRecomp/gpu/video.cpp b/UnleashedRecomp/gpu/video.cpp new file mode 100644 index 00000000..e9de774b --- /dev/null +++ b/UnleashedRecomp/gpu/video.cpp @@ -0,0 +1,23 @@ +#include +#include "video.h" +#include "window.h" +#include "kernel/function.h" + +void VdInitializeSystem() +{ + Window::Init(); +} + +void* VdGetGlobalDevice() +{ + return nullptr; +} + +// Direct3D stubs +GUEST_FUNCTION_STUB(sub_824EB290); +GUEST_FUNCTION_STUB(sub_82BDA8C0); +GUEST_FUNCTION_STUB(sub_82BE05B8); + +// Movie player stubs +GUEST_FUNCTION_STUB(sub_82AE3638); +GUEST_FUNCTION_STUB(sub_82AE2BF8); diff --git a/UnleashedRecomp/gpu/video.h b/UnleashedRecomp/gpu/video.h new file mode 100644 index 00000000..9ab4054a --- /dev/null +++ b/UnleashedRecomp/gpu/video.h @@ -0,0 +1,4 @@ +#pragma once + +void VdInitializeSystem(); +SWA_API void* VdGetGlobalDevice(); diff --git a/UnleashedRecomp/kernel/heap.cpp b/UnleashedRecomp/kernel/heap.cpp index 4cf184ff..44438375 100644 --- a/UnleashedRecomp/kernel/heap.cpp +++ b/UnleashedRecomp/kernel/heap.cpp @@ -103,7 +103,7 @@ uint32_t RtlSizeHeap(uint32_t heapHandle, uint32_t flags, uint32_t memoryPointer return 0; } -uint32_t XAlloc(uint32_t size, uint32_t flags) +SWA_API uint32_t XAlloc(uint32_t size, uint32_t flags) { void* ptr = (flags & 0x80000000) != 0 ? gUserHeap.AllocPhysical(size, (1ull << ((flags >> 24) & 0xF))) : @@ -116,7 +116,7 @@ uint32_t XAlloc(uint32_t size, uint32_t flags) return gMemory.MapVirtual(ptr); } -void XFree(uint32_t baseAddress, uint32_t flags) +SWA_API void XFree(uint32_t baseAddress, uint32_t flags) { if (baseAddress != NULL) gUserHeap.Free(gMemory.Translate(baseAddress)); @@ -132,4 +132,4 @@ GUEST_FUNCTION_HOOK(sub_82BD6FD0, RtlSizeHeap); // Seems like these handle allocation of virtual and physical pages GUEST_FUNCTION_HOOK(sub_831CC9C8, XAlloc); -GUEST_FUNCTION_HOOK(sub_831CCA60, XFree); \ No newline at end of file +GUEST_FUNCTION_HOOK(sub_831CCA60, XFree); diff --git a/UnleashedRecomp/kernel/imports.cpp b/UnleashedRecomp/kernel/imports.cpp index e26c0774..f6c0e08b 100644 --- a/UnleashedRecomp/kernel/imports.cpp +++ b/UnleashedRecomp/kernel/imports.cpp @@ -30,31 +30,11 @@ DWORD GuestTimeoutToMilliseconds(XLPQWORD timeout) return timeout ? (*timeout * -1) / 10000 : INFINITE; } -void XboxKrnlVersion() -{ - printf("!!! STUB !!! XboxKrnlVersion\n"); -} - -void VdGpuClockInMHz() -{ - printf("!!! STUB !!! VdGpuClockInMHz\n"); -} - void VdHSIOCalibrationLock() { printf("!!! STUB !!! VdHSIOCalibrationLock\n"); } -void VdGlobalXamDevice() -{ - printf("!!! STUB !!! VdGlobalXamDevice\n"); -} - -void VdGlobalDevice() -{ - printf("!!! STUB !!! VdGlobalDevice\n"); -} - void KeCertMonitorData() { printf("!!! STUB !!! KeCertMonitorData\n"); diff --git a/UnleashedRecomp/kernel/memory.cpp b/UnleashedRecomp/kernel/memory.cpp index d6581682..2e1b791b 100644 --- a/UnleashedRecomp/kernel/memory.cpp +++ b/UnleashedRecomp/kernel/memory.cpp @@ -31,7 +31,7 @@ uint32_t Memory::MapVirtual(void* host) const noexcept return static_cast(static_cast(host) - base); } -extern "C" void* MmGetHostAddress(uint32_t ptr) +SWA_API void* MmGetHostAddress(uint32_t ptr) { return gMemory.Translate(ptr); -} \ No newline at end of file +} diff --git a/UnleashedRecomp/kernel/memory.h b/UnleashedRecomp/kernel/memory.h index 4e6d9ace..591602f8 100644 --- a/UnleashedRecomp/kernel/memory.h +++ b/UnleashedRecomp/kernel/memory.h @@ -18,4 +18,5 @@ public: uint32_t MapVirtual(void* host) const noexcept; }; -extern Memory gMemory; \ No newline at end of file +SWA_API void* MmGetHostAddress(uint32_t ptr); +extern Memory gMemory; diff --git a/UnleashedRecomp/main.cpp b/UnleashedRecomp/main.cpp index 63064a2b..675699ca 100644 --- a/UnleashedRecomp/main.cpp +++ b/UnleashedRecomp/main.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -18,7 +19,8 @@ Memory gMemory{ reinterpret_cast(0x100000000), 0x100000000 }; Heap gUserHeap; CodeCache gCodeCache; -int main() +// Name inspired from nt's entry point +void KiSystemStartup() { #ifdef _WIN32 CoInitializeEx(nullptr, COINIT_MULTITHREADED); @@ -50,16 +52,18 @@ int main() // OS mounts game data to D: XamContentCreateEx(0, "D", &gameContent, OPEN_EXISTING, nullptr, nullptr, 0, 0, nullptr); +} +uint32_t LdrLoadModule(const char* path) +{ auto loadResult = LoadFile(FileSystem::TransformPath(GAME_XEX_PATH)); if (!loadResult.has_value()) { - assert("Failed to load default.xex" && false); - return 1; + assert("Failed to load module" && false); + return 0; } auto* xex = reinterpret_cast(loadResult->data()); - auto headers = reinterpret_cast(&xex[1]); auto security = reinterpret_cast((char*)xex + xex->AddressOfSecurityInfo); gMemory.Alloc(security->ImageBase, security->SizeOfImage, MEM_COMMIT); @@ -89,6 +93,17 @@ int main() } } + return entry; +} + +int main() +{ + KiSystemStartup(); + + uint32_t entry = LdrLoadModule(FileSystem::TransformPath(GAME_XEX_PATH)); + + VdInitializeSystem(); + GuestThread::Start(entry); return 0; diff --git a/UnleashedRecomp/stdafx.h b/UnleashedRecomp/stdafx.h index 6ef9cc44..7c42db8e 100644 --- a/UnleashedRecomp/stdafx.h +++ b/UnleashedRecomp/stdafx.h @@ -12,4 +12,4 @@ #include "framework.h" #include "Mutex.h" -#include "Config.h" \ No newline at end of file +#include "Config.h" diff --git a/thirdparty/CMakeLists.txt b/thirdparty/CMakeLists.txt index 9a680635..9a27798c 100644 --- a/thirdparty/CMakeLists.txt +++ b/thirdparty/CMakeLists.txt @@ -15,4 +15,5 @@ FetchContent_MakeAvailable(unordered_dense) FetchContent_MakeAvailable(xxHash) add_subdirectory(${SWA_THIRDPARTY_ROOT}/PowerRecomp) -add_subdirectory(${SWA_THIRDPARTY_ROOT}/o1heap) \ No newline at end of file +add_subdirectory(${SWA_THIRDPARTY_ROOT}/o1heap) +add_subdirectory(${SWA_THIRDPARTY_ROOT}/SDL) diff --git a/thirdparty/PowerRecomp b/thirdparty/PowerRecomp index c4de7026..54cb41c4 160000 --- a/thirdparty/PowerRecomp +++ b/thirdparty/PowerRecomp @@ -1 +1 @@ -Subproject commit c4de70262f0bc6e44c95df99772c136d1bdd71cc +Subproject commit 54cb41c4db6aee0c347835490405bd19f97f6c20 diff --git a/thirdparty/SDL b/thirdparty/SDL new file mode 160000 index 00000000..1edaad17 --- /dev/null +++ b/thirdparty/SDL @@ -0,0 +1 @@ +Subproject commit 1edaad17218d67b567c149badce9ef0fc67f65fa