From f11d357ab94c6c171057af924bfbcbcacc56e0c7 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Thu, 28 Nov 2019 01:55:33 +1000 Subject: [PATCH] Compile fixes for Android --- CMakeLists.txt | 15 ++++-- dep/CMakeLists.txt | 12 ++++- dep/YBaseLib | 2 +- src/CMakeLists.txt | 5 +- src/common/heap_array.h | 2 +- src/common/types.h | 2 +- src/core/CMakeLists.txt | 27 ++++++---- src/core/bios.h | 1 + src/core/bus.h | 1 + src/core/core.vcxproj | 16 +++--- src/core/cpu_code_cache.cpp | 19 +++++-- src/core/cpu_code_cache.h | 65 ++++++++++++++++++++++++ src/core/cpu_recompiler_code_generator.h | 1 + src/core/cpu_recompiler_types.h | 16 ++++-- src/core/cpu_types.h | 63 ----------------------- src/core/dma.h | 1 + src/core/host_interface.cpp | 41 ++++++++++++--- src/core/settings.h | 1 + src/core/spu.cpp | 4 +- 19 files changed, 187 insertions(+), 107 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4cdc371a0..bb7bf996b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,7 +29,9 @@ endif() # Required libraries. -find_package(SDL2 REQUIRED) +if(NOT ANDROID) + find_package(SDL2 REQUIRED) +endif() # Set _DEBUG macro for Debug builds. @@ -72,7 +74,10 @@ if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") endif() set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-switch") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-switch -Wno-class-memaccess -Wno-invalid-offsetof") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-switch") + if(NOT ANDROID) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-class-memaccess -Wno-invalid-offsetof") + endif() endif() @@ -91,7 +96,7 @@ elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86" OR ${CMAKE_SYSTEM_PROCESSOR} STR set(CPU_ARCH "x86") elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64") set(CPU_ARCH "aarch64") -elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm") +elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm" OR ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "armv7-a") set(CPU_ARCH "arm") else() message(FATAL_ERROR "Unknown system processor: " ${CMAKE_SYSTEM_PROCESSOR}) @@ -107,3 +112,7 @@ find_package(Threads REQUIRED) enable_testing() add_subdirectory(dep) add_subdirectory(src) + +if(ANDROID) + add_subdirectory(android/app/src/cpp) +endif() \ No newline at end of file diff --git a/dep/CMakeLists.txt b/dep/CMakeLists.txt index 3a2643e5b..a0c1486db 100644 --- a/dep/CMakeLists.txt +++ b/dep/CMakeLists.txt @@ -1,16 +1,20 @@ add_subdirectory(glad) add_subdirectory(imgui) add_subdirectory(libcue) -add_subdirectory(nativefiledialog) add_subdirectory(simpleini) add_subdirectory(stb) +if(NOT ANDROID) + add_subdirectory(nativefiledialog) +endif() + ###################### YBaseLib ############################ set(YBASELIB_SRC_BASE ${CMAKE_SOURCE_DIR}/dep/YBaseLib/Source) set(YBASELIB_INCLUDES ${CMAKE_SOURCE_DIR}/dep/YBaseLib/Include) set(YBASELIB_SRC_FILES ${YBASELIB_SRC_BASE}/YBaseLib/Android + ${YBASELIB_SRC_BASE}/YBaseLib/Android/AndroidBarrier.cpp ${YBASELIB_SRC_BASE}/YBaseLib/Android/AndroidConditionVariable.cpp ${YBASELIB_SRC_BASE}/YBaseLib/Android/AndroidEvent.cpp ${YBASELIB_SRC_BASE}/YBaseLib/Android/AndroidFileSystem.cpp @@ -86,4 +90,8 @@ set(YBASELIB_SRC_FILES add_library(YBaseLib STATIC ${YBASELIB_SRC_FILES}) target_include_directories(YBaseLib PRIVATE ${YBASELIB_INCLUDES} ${YBASELIB_SRC_BASE}) target_include_directories(YBaseLib PUBLIC ${YBASELIB_INCLUDES}) -target_link_libraries(YBaseLib Threads::Threads) +target_link_libraries(YBaseLib PUBLIC Threads::Threads) + +if(ANDROID) + target_link_libraries(YBaseLib PRIVATE log) +endif() \ No newline at end of file diff --git a/dep/YBaseLib b/dep/YBaseLib index 9c5869b61..7004a8b56 160000 --- a/dep/YBaseLib +++ b/dep/YBaseLib @@ -1 +1 @@ -Subproject commit 9c5869b61158382ac8d4254961f33b1e9a6d2091 +Subproject commit 7004a8b562373915bb56ea73171c4f3b43fafdea diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index da4e77fe0..4c372b8d3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,3 +1,6 @@ add_subdirectory(common) add_subdirectory(core) -add_subdirectory(duckstation) + +if(NOT ANDROID) + add_subdirectory(duckstation) +endif() diff --git a/src/common/heap_array.h b/src/common/heap_array.h index d85c30249..f40fcf834 100644 --- a/src/common/heap_array.h +++ b/src/common/heap_array.h @@ -20,7 +20,7 @@ public: HeapArray(const this_type& copy) { - m_data = new T[size]; + m_data = new T[SIZE]; std::copy(copy.cbegin(), copy.cend(), begin()); } diff --git a/src/common/types.h b/src/common/types.h index a5b33c021..8f1c8ea00 100644 --- a/src/common/types.h +++ b/src/common/types.h @@ -176,7 +176,7 @@ ALWAYS_INLINE constexpr bool ConvertToBool(TValue value) // Unsafe integer to boolean template -ALWAYS_INLINE constexpr bool ConvertToBoolUnchecked(TValue value) +ALWAYS_INLINE bool ConvertToBoolUnchecked(TValue value) { // static_assert(sizeof(uint8) == sizeof(bool)); bool ret; diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 0ac1200eb..496620b76 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -13,14 +13,6 @@ add_library(core cpu_core.inl cpu_disasm.cpp cpu_disasm.h - cpu_recompiler_code_generator.cpp - cpu_recompiler_code_generator.h - cpu_recompiler_code_generator_generic.cpp - cpu_recompiler_register_cache.cpp - cpu_recompiler_register_cache.h - cpu_recompiler_thunks.cpp - cpu_recompiler_thunks.h - cpu_recompiler_types.h cpu_types.cpp cpu_types.h digital_controller.cpp @@ -66,9 +58,21 @@ add_library(core types.h ) +set(RECOMPILER_SRCS + cpu_recompiler_code_generator.cpp + cpu_recompiler_code_generator.h + cpu_recompiler_code_generator_generic.cpp + cpu_recompiler_register_cache.cpp + cpu_recompiler_register_cache.h + cpu_recompiler_thunks.cpp + cpu_recompiler_thunks.h + cpu_recompiler_types.h +) + target_include_directories(core PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/..") target_include_directories(core PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/..") -target_link_libraries(core PRIVATE Threads::Threads YBaseLib common imgui glad simpleini stb) +target_link_libraries(core PUBLIC Threads::Threads YBaseLib common imgui) +target_link_libraries(core PRIVATE glad simpleini stb) if(WIN32) target_sources(core PRIVATE @@ -79,7 +83,10 @@ endif() if(${CPU_ARCH} STREQUAL "x64") target_include_directories(core PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../../dep/xbyak/xbyak") - target_sources(core PRIVATE cpu_recompiler_code_generator_x64.cpp) + target_compile_definitions(core PRIVATE "WITH_RECOMPILER=1") + target_sources(core PRIVATE ${RECOMPILER_SRCS} + cpu_recompiler_code_generator_x64.cpp + ) message("Building x64 recompiler") else() message("Not building recompiler") diff --git a/src/core/bios.h b/src/core/bios.h index 997be8a11..31a9c220b 100644 --- a/src/core/bios.h +++ b/src/core/bios.h @@ -1,6 +1,7 @@ #pragma once #include "types.h" #include +#include #include #include diff --git a/src/core/bus.h b/src/core/bus.h index 021520b0f..d86542fa5 100644 --- a/src/core/bus.h +++ b/src/core/bus.h @@ -5,6 +5,7 @@ #include "types.h" #include #include +#include class StateWrapper; diff --git a/src/core/core.vcxproj b/src/core/core.vcxproj index 546cc405b..a280ac044 100644 --- a/src/core/core.vcxproj +++ b/src/core/core.vcxproj @@ -260,7 +260,7 @@ Level4 Disabled - ENABLE_VOODOO=1;_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + WITH_RECOMPILER=1;_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) true ProgramDatabase $(SolutionDir)dep\msvc\include;$(SolutionDir)dep\YBaseLib\Include;$(SolutionDir)dep\glad\include;$(SolutionDir)dep\stb\include;$(SolutionDir)dep\imgui\include;$(SolutionDir)dep\simpleini\include;$(SolutionDir)dep\xbyak\xbyak;$(SolutionDir)src;%(AdditionalIncludeDirectories) @@ -282,7 +282,7 @@ Level4 Disabled - ENABLE_VOODOO=1;_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + WITH_RECOMPILER=1;_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) true ProgramDatabase $(SolutionDir)dep\msvc\include;$(SolutionDir)dep\YBaseLib\Include;$(SolutionDir)dep\glad\include;$(SolutionDir)dep\stb\include;$(SolutionDir)dep\imgui\include;$(SolutionDir)dep\simpleini\include;$(SolutionDir)dep\xbyak\xbyak;$(SolutionDir)src;%(AdditionalIncludeDirectories) @@ -304,7 +304,7 @@ Level4 Disabled - ENABLE_VOODOO=1;_ITERATOR_DEBUG_LEVEL=1;_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUGFAST;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + WITH_RECOMPILER=1;_ITERATOR_DEBUG_LEVEL=1;_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUGFAST;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) true ProgramDatabase $(SolutionDir)dep\msvc\include;$(SolutionDir)dep\YBaseLib\Include;$(SolutionDir)dep\glad\include;$(SolutionDir)dep\stb\include;$(SolutionDir)dep\imgui\include;$(SolutionDir)dep\simpleini\include;$(SolutionDir)dep\xbyak\xbyak;$(SolutionDir)src;%(AdditionalIncludeDirectories) @@ -329,7 +329,7 @@ Level4 Disabled - ENABLE_VOODOO=1;_ITERATOR_DEBUG_LEVEL=1;_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUGFAST;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + WITH_RECOMPILER=1;_ITERATOR_DEBUG_LEVEL=1;_CRT_SECURE_NO_WARNINGS;WIN32;_DEBUGFAST;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) true ProgramDatabase $(SolutionDir)dep\msvc\include;$(SolutionDir)dep\YBaseLib\Include;$(SolutionDir)dep\glad\include;$(SolutionDir)dep\stb\include;$(SolutionDir)dep\imgui\include;$(SolutionDir)dep\simpleini\include;$(SolutionDir)dep\xbyak\xbyak;$(SolutionDir)src;%(AdditionalIncludeDirectories) @@ -355,7 +355,7 @@ MaxSpeed true - ENABLE_VOODOO=1;_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + WITH_RECOMPILER=1;_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) $(SolutionDir)dep\msvc\include;$(SolutionDir)dep\YBaseLib\Include;$(SolutionDir)dep\glad\include;$(SolutionDir)dep\stb\include;$(SolutionDir)dep\imgui\include;$(SolutionDir)dep\simpleini\include;$(SolutionDir)dep\xbyak\xbyak;$(SolutionDir)src;%(AdditionalIncludeDirectories) true false @@ -378,7 +378,7 @@ MaxSpeed true - ENABLE_VOODOO=1;_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + WITH_RECOMPILER=1;_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) $(SolutionDir)dep\msvc\include;$(SolutionDir)dep\YBaseLib\Include;$(SolutionDir)dep\glad\include;$(SolutionDir)dep\stb\include;$(SolutionDir)dep\imgui\include;$(SolutionDir)dep\simpleini\include;$(SolutionDir)dep\xbyak\xbyak;$(SolutionDir)src;%(AdditionalIncludeDirectories) true true @@ -402,7 +402,7 @@ MaxSpeed true - ENABLE_VOODOO=1;_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + WITH_RECOMPILER=1;_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) $(SolutionDir)dep\msvc\include;$(SolutionDir)dep\YBaseLib\Include;$(SolutionDir)dep\glad\include;$(SolutionDir)dep\stb\include;$(SolutionDir)dep\imgui\include;$(SolutionDir)dep\simpleini\include;$(SolutionDir)dep\xbyak\xbyak;$(SolutionDir)src;%(AdditionalIncludeDirectories) true false @@ -425,7 +425,7 @@ MaxSpeed true - ENABLE_VOODOO=1;_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + WITH_RECOMPILER=1;_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) $(SolutionDir)dep\msvc\include;$(SolutionDir)dep\YBaseLib\Include;$(SolutionDir)dep\glad\include;$(SolutionDir)dep\stb\include;$(SolutionDir)dep\imgui\include;$(SolutionDir)dep\simpleini\include;$(SolutionDir)dep\xbyak\xbyak;$(SolutionDir)src;%(AdditionalIncludeDirectories) true true diff --git a/src/core/cpu_code_cache.cpp b/src/core/cpu_code_cache.cpp index f99488ca7..c7b67deb7 100644 --- a/src/core/cpu_code_cache.cpp +++ b/src/core/cpu_code_cache.cpp @@ -2,11 +2,14 @@ #include "YBaseLib/Log.h" #include "cpu_core.h" #include "cpu_disasm.h" -#include "cpu_recompiler_code_generator.h" -#include "cpu_recompiler_thunks.h" #include "system.h" Log_SetChannel(CPU::CodeCache); +#ifdef WITH_RECOMPILER +#include "cpu_recompiler_code_generator.h" +#include "cpu_recompiler_thunks.h" +#endif + namespace CPU { constexpr bool USE_BLOCK_LINKING = true; @@ -23,11 +26,15 @@ void CodeCache::Initialize(System* system, Core* core, Bus* bus, bool use_recomp m_system = system; m_core = core; m_bus = bus; - m_use_recompiler = use_recompiler; +#ifdef WITH_RECOMPILER + m_use_recompiler = use_recompiler; m_code_buffer = std::make_unique(RECOMPILER_CODE_CACHE_SIZE, RECOMPILER_FAR_CODE_CACHE_SIZE); m_asm_functions = std::make_unique(); m_asm_functions->Generate(m_code_buffer.get()); +#else + m_use_recompiler = false; +#endif } void CodeCache::Execute() @@ -120,11 +127,13 @@ void CodeCache::Execute() void CodeCache::SetUseRecompiler(bool enable) { +#ifdef WITH_RECOMPILER if (m_use_recompiler == enable) return; m_use_recompiler = enable; Flush(); +#endif } void CodeCache::Flush() @@ -134,7 +143,9 @@ void CodeCache::Flush() it.clear(); m_blocks.clear(); +#ifdef WITH_RECOMPILER m_code_buffer->Reset(); +#endif } void CodeCache::LogCurrentState() @@ -297,6 +308,7 @@ bool CodeCache::CompileBlock(CodeBlock* block) return false; } +#ifdef WITH_RECOMPILER if (m_use_recompiler) { // Ensure we're not going to run out of space while compiling this block. @@ -316,6 +328,7 @@ bool CodeCache::CompileBlock(CodeBlock* block) return false; } } +#endif return true; } diff --git a/src/core/cpu_code_cache.h b/src/core/cpu_code_cache.h index 8801295de..9c00dd821 100644 --- a/src/core/cpu_code_cache.h +++ b/src/core/cpu_code_cache.h @@ -18,6 +18,69 @@ namespace Recompiler { class ASMFunctions; } +union CodeBlockKey +{ + u32 bits; + + BitField user_mode; + BitField aligned_pc; + + ALWAYS_INLINE u32 GetPC() const { return aligned_pc << 2; } + ALWAYS_INLINE void SetPC(u32 pc) { aligned_pc = pc >> 2; } + + ALWAYS_INLINE CodeBlockKey& operator=(const CodeBlockKey& rhs) + { + bits = rhs.bits; + return *this; + } + + ALWAYS_INLINE bool operator==(const CodeBlockKey& rhs) const { return bits == rhs.bits; } + ALWAYS_INLINE bool operator!=(const CodeBlockKey& rhs) const { return bits != rhs.bits; } + ALWAYS_INLINE bool operator<(const CodeBlockKey& rhs) const { return bits < rhs.bits; } +}; + +struct CodeBlockInstruction +{ + Instruction instruction; + u32 pc; + + bool is_branch_instruction : 1; + bool is_branch_delay_slot : 1; + bool is_load_instruction : 1; + bool is_store_instruction : 1; + bool is_load_delay_slot : 1; + bool is_last_instruction : 1; + bool has_load_delay : 1; + bool can_trap : 1; +}; + +struct CodeBlock +{ + using HostCodePointer = void (*)(Core*); + + CodeBlock(const CodeBlockKey key_) : key(key_) {} + + CodeBlockKey key; + u32 host_code_size = 0; + HostCodePointer host_code = nullptr; + + std::vector instructions; + std::vector link_predecessors; + std::vector link_successors; + + bool invalidated = false; + + const u32 GetPC() const { return key.GetPC(); } + const u32 GetSizeInBytes() const { return static_cast(instructions.size()) * sizeof(Instruction); } + const u32 GetStartPageIndex() const { return (key.GetPC() / CPU_CODE_CACHE_PAGE_SIZE); } + const u32 GetEndPageIndex() const { return ((key.GetPC() + GetSizeInBytes()) / CPU_CODE_CACHE_PAGE_SIZE); } + bool IsInRAM() const + { + // TODO: Constant + return key.GetPC() < 0x200000; + } +}; + class CodeCache { public: @@ -69,8 +132,10 @@ private: Core* m_core; Bus* m_bus; +#ifdef WITH_RECOMPILER std::unique_ptr m_code_buffer; std::unique_ptr m_asm_functions; +#endif BlockMap m_blocks; diff --git a/src/core/cpu_recompiler_code_generator.h b/src/core/cpu_recompiler_code_generator.h index cfaac15fb..d71905d3e 100644 --- a/src/core/cpu_recompiler_code_generator.h +++ b/src/core/cpu_recompiler_code_generator.h @@ -5,6 +5,7 @@ #include "common/jit_code_buffer.h" +#include "cpu_code_cache.h" #include "cpu_recompiler_register_cache.h" #include "cpu_recompiler_thunks.h" #include "cpu_recompiler_types.h" diff --git a/src/core/cpu_recompiler_types.h b/src/core/cpu_recompiler_types.h index e1c84fb4f..de9e1a640 100644 --- a/src/core/cpu_recompiler_types.h +++ b/src/core/cpu_recompiler_types.h @@ -46,6 +46,7 @@ enum class Condition : u8 }; #if defined(Y_CPU_X64) + using HostReg = Xbyak::Operand::Code; using CodeEmitter = Xbyak::CodeGenerator; enum : u32 @@ -63,15 +64,22 @@ constexpr u32 MAX_FAR_HOST_BYTES_PER_INSTRUCTION = 128; constexpr bool SHIFTS_ARE_IMPLICITLY_MASKED = true; #else -using HostReg = void; -using CodeEmitter = void; + +using HostReg = int; + +class CodeEmitter +{ +}; + enum : u32 { - HostReg_Count = 0 + HostReg_Count = 1 }; + constexpr HostReg HostReg_Invalid = static_cast(HostReg_Count); -constexpr OperandSize HostPointerSize = OperandSize_64; +constexpr RegSize HostPointerSize = RegSize_64; constexpr bool SHIFTS_ARE_IMPLICITLY_MASKED = false; + #endif } // namespace Recompiler diff --git a/src/core/cpu_types.h b/src/core/cpu_types.h index 0480026e3..b02535c97 100644 --- a/src/core/cpu_types.h +++ b/src/core/cpu_types.h @@ -380,67 +380,4 @@ struct Cop0Registers } dcic; }; -union CodeBlockKey -{ - u32 bits; - - BitField user_mode; - BitField aligned_pc; - - ALWAYS_INLINE u32 GetPC() const { return aligned_pc << 2; } - ALWAYS_INLINE void SetPC(u32 pc) { aligned_pc = pc >> 2; } - - ALWAYS_INLINE CodeBlockKey& operator=(const CodeBlockKey& rhs) - { - bits = rhs.bits; - return *this; - } - - ALWAYS_INLINE bool operator==(const CodeBlockKey& rhs) const { return bits == rhs.bits; } - ALWAYS_INLINE bool operator!=(const CodeBlockKey& rhs) const { return bits != rhs.bits; } - ALWAYS_INLINE bool operator<(const CodeBlockKey& rhs) const { return bits < rhs.bits; } -}; - -struct CodeBlockInstruction -{ - Instruction instruction; - u32 pc; - - bool is_branch_instruction : 1; - bool is_branch_delay_slot : 1; - bool is_load_instruction : 1; - bool is_store_instruction : 1; - bool is_load_delay_slot : 1; - bool is_last_instruction : 1; - bool has_load_delay : 1; - bool can_trap : 1; -}; - -struct CodeBlock -{ - using HostCodePointer = void (*)(Core*); - - CodeBlock(const CodeBlockKey key_) : key(key_) {} - - CodeBlockKey key; - u32 host_code_size = 0; - HostCodePointer host_code = nullptr; - - std::vector instructions; - std::vector link_predecessors; - std::vector link_successors; - - bool invalidated = false; - - const u32 GetPC() const { return key.GetPC(); } - const u32 GetSizeInBytes() const { return static_cast(instructions.size()) * sizeof(Instruction); } - const u32 GetStartPageIndex() const { return (key.GetPC() / CPU_CODE_CACHE_PAGE_SIZE); } - const u32 GetEndPageIndex() const { return ((key.GetPC() + GetSizeInBytes()) / CPU_CODE_CACHE_PAGE_SIZE); } - bool IsInRAM() const - { - // TODO: Constant - return key.GetPC() < 0x200000; - } -}; - } // namespace CPU diff --git a/src/core/dma.h b/src/core/dma.h index c7c9f9344..dc66b77ca 100644 --- a/src/core/dma.h +++ b/src/core/dma.h @@ -2,6 +2,7 @@ #include "common/bitfield.h" #include "types.h" #include +#include class StateWrapper; diff --git a/src/core/host_interface.cpp b/src/core/host_interface.cpp index 0a1c5d469..06048b7cc 100644 --- a/src/core/host_interface.cpp +++ b/src/core/host_interface.cpp @@ -15,6 +15,33 @@ Log_SetChannel(HostInterface); #include #endif +#ifdef ANDROID + +#include + +static std::string GetRelativePath(const std::string& path, const char* new_filename) +{ + const char* last = std::strrchr(path.c_str(), '/'); + if (!last) + return new_filename; + + std::string new_path(path.c_str(), last - path.c_str() + 1); + new_path += new_filename; + return new_path; +} + +#else + +#include + +static std::string GetRelativePath(const std::string& path, const char* new_filename) +{ + return std::filesystem::path(path).replace_filename(new_filename).string(); +} + +#endif + + HostInterface::HostInterface() { m_settings.SetDefaults(); @@ -83,8 +110,6 @@ std::optional> HostInterface::GetBIOSImage(ConsoleRegion region) } \ } while (0) -#define RELATIVE_PATH(filename) std::filesystem::path(m_settings.bios_path).replace_filename(filename).string() - // Try the configured image. TRY_FILENAME(m_settings.bios_path); @@ -92,18 +117,18 @@ std::optional> HostInterface::GetBIOSImage(ConsoleRegion region) switch (region) { case ConsoleRegion::NTSC_J: - TRY_FILENAME(RELATIVE_PATH("scph1000.bin")); - TRY_FILENAME(RELATIVE_PATH("scph5500.bin")); + TRY_FILENAME(GetRelativePath(m_settings.bios_path, "scph1000.bin")); + TRY_FILENAME(GetRelativePath(m_settings.bios_path, "scph5500.bin")); break; case ConsoleRegion::NTSC_U: - TRY_FILENAME(RELATIVE_PATH("scph1001.bin")); - TRY_FILENAME(RELATIVE_PATH("scph5501.bin")); + TRY_FILENAME(GetRelativePath(m_settings.bios_path, "scph1001.bin")); + TRY_FILENAME(GetRelativePath(m_settings.bios_path, "scph5501.bin")); break; case ConsoleRegion::PAL: - TRY_FILENAME(RELATIVE_PATH("scph1002.bin")); - TRY_FILENAME(RELATIVE_PATH("scph5502.bin")); + TRY_FILENAME(GetRelativePath(m_settings.bios_path, "scph1002.bin")); + TRY_FILENAME(GetRelativePath(m_settings.bios_path, "scph5502.bin")); break; default: diff --git a/src/core/settings.h b/src/core/settings.h index 90a542e4c..77ca4c265 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -1,6 +1,7 @@ #pragma once #include "types.h" #include +#include struct Settings { diff --git a/src/core/spu.cpp b/src/core/spu.cpp index 385f7eebe..86d33c30e 100644 --- a/src/core/spu.cpp +++ b/src/core/spu.cpp @@ -1054,7 +1054,7 @@ void SPU::DrawDebugStateWindow() ImGui::SameLine(offsets[2]); ImGui::TextColored(m_SPUCNT.external_audio_enable ? active_color : inactive_color, "External Audio"); ImGui::SameLine(offsets[3]); - ImGui::TextColored(m_SPUCNT.ram_transfer_mode != RAMTransferMode::Stopped ? active_color : inactive_color, + ImGui::TextColored(m_SPUCNT.ram_transfer_mode != RAMTransferMode::Stopped ? active_color : inactive_color, "%s", transfer_modes[static_cast(m_SPUCNT.ram_transfer_mode.GetValue())]); ImGui::Text("Status: "); @@ -1138,7 +1138,7 @@ void SPU::DrawDebugStateWindow() ImGui::NextColumn(); ImGui::TextColored(color, "%08X", v.regs.adsr.bits); ImGui::NextColumn(); - ImGui::TextColored(color, adsr_phases[static_cast(v.adsr_phase)]); + ImGui::TextColored(color, "%s", adsr_phases[static_cast(v.adsr_phase)]); ImGui::NextColumn(); ImGui::TextColored(color, "%d", ZeroExtend32(v.regs.adsr_volume)); ImGui::NextColumn();