summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/CMakeLists.txt12
-rw-r--r--src/common/bit_set.h2
-rw-r--r--src/common/common_paths.h18
-rw-r--r--src/common/emu_window.cpp107
-rw-r--r--src/common/emu_window.h290
-rw-r--r--src/common/file_util.cpp59
-rw-r--r--src/common/file_util.h20
-rw-r--r--src/common/key_map.cpp152
-rw-r--r--src/common/key_map.h93
-rw-r--r--src/common/logging/backend.cpp1
-rw-r--r--src/common/logging/log.h1
-rw-r--r--src/common/logging/text_formatter.cpp2
-rw-r--r--src/common/scm_rev.cpp.in2
-rw-r--r--src/common/string_util.cpp2
-rw-r--r--src/common/thread.cpp2
-rw-r--r--src/common/timer.cpp3
-rw-r--r--src/common/x64/xbyak_abi.h178
-rw-r--r--src/common/x64/xbyak_util.h49
18 files changed, 254 insertions, 739 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt
index 74a271f08..5aecf6e6e 100644
--- a/src/common/CMakeLists.txt
+++ b/src/common/CMakeLists.txt
@@ -3,11 +3,9 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/scm_rev.cpp.in" "${CMAKE_CURRENT_SOU
set(SRCS
break_points.cpp
- emu_window.cpp
file_util.cpp
framebuffer_layout.cpp
hash.cpp
- key_map.cpp
logging/filter.cpp
logging/text_formatter.cpp
logging/backend.cpp
@@ -34,11 +32,9 @@ set(HEADERS
common_funcs.h
common_paths.h
common_types.h
- emu_window.h
file_util.h
framebuffer_layout.h
hash.h
- key_map.h
linear_disk_cache.h
logging/text_formatter.h
logging/filter.h
@@ -71,9 +67,15 @@ if(ARCHITECTURE_x86_64)
set(HEADERS ${HEADERS}
x64/abi.h
x64/cpu_detect.h
- x64/emitter.h)
+ x64/emitter.h
+ x64/xbyak_abi.h
+ x64/xbyak_util.h
+ )
endif()
create_directory_groups(${SRCS} ${HEADERS})
add_library(common STATIC ${SRCS} ${HEADERS})
+if (ARCHITECTURE_x86_64)
+ target_link_libraries(common xbyak)
+endif()
diff --git a/src/common/bit_set.h b/src/common/bit_set.h
index c48b3b769..3059d0cb0 100644
--- a/src/common/bit_set.h
+++ b/src/common/bit_set.h
@@ -16,7 +16,7 @@ namespace Common {
// Helper functions:
-#ifdef _WIN32
+#ifdef _MSC_VER
template <typename T>
static inline int CountSetBits(T v) {
// from https://graphics.stanford.edu/~seander/bithacks.html
diff --git a/src/common/common_paths.h b/src/common/common_paths.h
index 37304d236..b56105306 100644
--- a/src/common/common_paths.h
+++ b/src/common/common_paths.h
@@ -32,22 +32,10 @@
// Subdirs in the User dir returned by GetUserPath(D_USER_IDX)
#define CONFIG_DIR "config"
-#define GAMECONFIG_DIR "game_config"
-#define MAPS_DIR "maps"
#define CACHE_DIR "cache"
#define SDMC_DIR "sdmc"
#define NAND_DIR "nand"
#define SYSDATA_DIR "sysdata"
-#define SHADERCACHE_DIR "shader_cache"
-#define STATESAVES_DIR "state_saves"
-#define SCREENSHOTS_DIR "screenShots"
-#define DUMP_DIR "dump"
-#define DUMP_TEXTURES_DIR "textures"
-#define DUMP_FRAMES_DIR "frames"
-#define DUMP_AUDIO_DIR "audio"
-#define LOGS_DIR "logs"
-#define SHADERS_DIR "shaders"
-#define SYSCONF_DIR "sysconf"
// Filenames
// Files in the directory returned by GetUserPath(D_CONFIG_IDX)
@@ -57,9 +45,3 @@
// Sys files
#define SHARED_FONT "shared_font.bin"
-
-// Files in the directory returned by GetUserPath(D_LOGS_IDX)
-#define MAIN_LOG "emu.log"
-
-// Files in the directory returned by GetUserPath(D_SYSCONF_IDX)
-#define SYSCONF "SYSCONF"
diff --git a/src/common/emu_window.cpp b/src/common/emu_window.cpp
deleted file mode 100644
index e3a9e08e6..000000000
--- a/src/common/emu_window.cpp
+++ /dev/null
@@ -1,107 +0,0 @@
-// Copyright 2014 Citra Emulator Project
-// Licensed under GPLv2 or any later version
-// Refer to the license.txt file included.
-
-#include <algorithm>
-#include <cmath>
-#include "common/assert.h"
-#include "common/key_map.h"
-#include "emu_window.h"
-#include "video_core/video_core.h"
-
-void EmuWindow::ButtonPressed(Service::HID::PadState pad) {
- pad_state.hex |= pad.hex;
-}
-
-void EmuWindow::ButtonReleased(Service::HID::PadState pad) {
- pad_state.hex &= ~pad.hex;
-}
-
-void EmuWindow::CirclePadUpdated(float x, float y) {
- constexpr int MAX_CIRCLEPAD_POS = 0x9C; // Max value for a circle pad position
-
- // Make sure the coordinates are in the unit circle,
- // otherwise normalize it.
- float r = x * x + y * y;
- if (r > 1) {
- r = std::sqrt(r);
- x /= r;
- y /= r;
- }
-
- circle_pad_x = static_cast<s16>(x * MAX_CIRCLEPAD_POS);
- circle_pad_y = static_cast<s16>(y * MAX_CIRCLEPAD_POS);
-}
-
-/**
- * Check if the given x/y coordinates are within the touchpad specified by the framebuffer layout
- * @param layout FramebufferLayout object describing the framebuffer size and screen positions
- * @param framebuffer_x Framebuffer x-coordinate to check
- * @param framebuffer_y Framebuffer y-coordinate to check
- * @return True if the coordinates are within the touchpad, otherwise false
- */
-static bool IsWithinTouchscreen(const Layout::FramebufferLayout& layout, unsigned framebuffer_x,
- unsigned framebuffer_y) {
- return (
- framebuffer_y >= layout.bottom_screen.top && framebuffer_y < layout.bottom_screen.bottom &&
- framebuffer_x >= layout.bottom_screen.left && framebuffer_x < layout.bottom_screen.right);
-}
-
-std::tuple<unsigned, unsigned> EmuWindow::ClipToTouchScreen(unsigned new_x, unsigned new_y) {
- new_x = std::max(new_x, framebuffer_layout.bottom_screen.left);
- new_x = std::min(new_x, framebuffer_layout.bottom_screen.right - 1);
-
- new_y = std::max(new_y, framebuffer_layout.bottom_screen.top);
- new_y = std::min(new_y, framebuffer_layout.bottom_screen.bottom - 1);
-
- return std::make_tuple(new_x, new_y);
-}
-
-void EmuWindow::TouchPressed(unsigned framebuffer_x, unsigned framebuffer_y) {
- if (!IsWithinTouchscreen(framebuffer_layout, framebuffer_x, framebuffer_y))
- return;
-
- touch_x = VideoCore::kScreenBottomWidth *
- (framebuffer_x - framebuffer_layout.bottom_screen.left) /
- (framebuffer_layout.bottom_screen.right - framebuffer_layout.bottom_screen.left);
- touch_y = VideoCore::kScreenBottomHeight *
- (framebuffer_y - framebuffer_layout.bottom_screen.top) /
- (framebuffer_layout.bottom_screen.bottom - framebuffer_layout.bottom_screen.top);
-
- touch_pressed = true;
- pad_state.touch.Assign(1);
-}
-
-void EmuWindow::TouchReleased() {
- touch_pressed = false;
- touch_x = 0;
- touch_y = 0;
- pad_state.touch.Assign(0);
-}
-
-void EmuWindow::TouchMoved(unsigned framebuffer_x, unsigned framebuffer_y) {
- if (!touch_pressed)
- return;
-
- if (!IsWithinTouchscreen(framebuffer_layout, framebuffer_x, framebuffer_y))
- std::tie(framebuffer_x, framebuffer_y) = ClipToTouchScreen(framebuffer_x, framebuffer_y);
-
- TouchPressed(framebuffer_x, framebuffer_y);
-}
-
-void EmuWindow::UpdateCurrentFramebufferLayout(unsigned width, unsigned height) {
- Layout::FramebufferLayout layout;
- switch (Settings::values.layout_option) {
- case Settings::LayoutOption::SingleScreen:
- layout = Layout::SingleFrameLayout(width, height, Settings::values.swap_screen);
- break;
- case Settings::LayoutOption::LargeScreen:
- layout = Layout::LargeFrameLayout(width, height, Settings::values.swap_screen);
- break;
- case Settings::LayoutOption::Default:
- default:
- layout = Layout::DefaultFrameLayout(width, height, Settings::values.swap_screen);
- break;
- }
- NotifyFramebufferLayoutChanged(layout);
-}
diff --git a/src/common/emu_window.h b/src/common/emu_window.h
deleted file mode 100644
index 835c4d500..000000000
--- a/src/common/emu_window.h
+++ /dev/null
@@ -1,290 +0,0 @@
-// Copyright 2014 Citra Emulator Project
-// Licensed under GPLv2 or any later version
-// Refer to the license.txt file included.
-
-#pragma once
-
-#include <tuple>
-#include <utility>
-#include "common/common_types.h"
-#include "common/framebuffer_layout.h"
-#include "common/math_util.h"
-#include "core/hle/service/hid/hid.h"
-
-/**
- * Abstraction class used to provide an interface between emulation code and the frontend
- * (e.g. SDL, QGLWidget, GLFW, etc...).
- *
- * Design notes on the interaction between EmuWindow and the emulation core:
- * - Generally, decisions on anything visible to the user should be left up to the GUI.
- * For example, the emulation core should not try to dictate some window title or size.
- * This stuff is not the core's business and only causes problems with regards to thread-safety
- * anyway.
- * - Under certain circumstances, it may be desirable for the core to politely request the GUI
- * to set e.g. a minimum window size. However, the GUI should always be free to ignore any
- * such hints.
- * - EmuWindow may expose some of its state as read-only to the emulation core, however care
- * should be taken to make sure the provided information is self-consistent. This requires
- * some sort of synchronization (most of this is still a TODO).
- * - DO NOT TREAT THIS CLASS AS A GUI TOOLKIT ABSTRACTION LAYER. That's not what it is. Please
- * re-read the upper points again and think about it if you don't see this.
- */
-class EmuWindow {
-public:
- /// Data structure to store emuwindow configuration
- struct WindowConfig {
- bool fullscreen;
- int res_width;
- int res_height;
- std::pair<unsigned, unsigned> min_client_area_size;
- };
-
- /// Swap buffers to display the next frame
- virtual void SwapBuffers() = 0;
-
- /// Polls window events
- virtual void PollEvents() = 0;
-
- /// Makes the graphics context current for the caller thread
- virtual void MakeCurrent() = 0;
-
- /// Releases (dunno if this is the "right" word) the GLFW context from the caller thread
- virtual void DoneCurrent() = 0;
-
- virtual void ReloadSetKeymaps() = 0;
-
- /**
- * Signals a button press action to the HID module.
- * @param pad_state indicates which button to press
- * @note only handles real buttons (A/B/X/Y/...), excluding analog inputs like the circle pad.
- */
- void ButtonPressed(Service::HID::PadState pad_state);
-
- /**
- * Signals a button release action to the HID module.
- * @param pad_state indicates which button to press
- * @note only handles real buttons (A/B/X/Y/...), excluding analog inputs like the circle pad.
- */
- void ButtonReleased(Service::HID::PadState pad_state);
-
- /**
- * Signals a circle pad change action to the HID module.
- * @param x new x-coordinate of the circle pad, in the range [-1.0, 1.0]
- * @param y new y-coordinate of the circle pad, in the range [-1.0, 1.0]
- * @note the coordinates will be normalized if the radius is larger than 1
- */
- void CirclePadUpdated(float x, float y);
-
- /**
- * Signal that a touch pressed event has occurred (e.g. mouse click pressed)
- * @param framebuffer_x Framebuffer x-coordinate that was pressed
- * @param framebuffer_y Framebuffer y-coordinate that was pressed
- */
- void TouchPressed(unsigned framebuffer_x, unsigned framebuffer_y);
-
- /// Signal that a touch released event has occurred (e.g. mouse click released)
- void TouchReleased();
-
- /**
- * Signal that a touch movement event has occurred (e.g. mouse was moved over the emu window)
- * @param framebuffer_x Framebuffer x-coordinate
- * @param framebuffer_y Framebuffer y-coordinate
- */
- void TouchMoved(unsigned framebuffer_x, unsigned framebuffer_y);
-
- /**
- * Gets the current pad state (which buttons are pressed).
- * @note This should be called by the core emu thread to get a state set by the window thread.
- * @note This doesn't include analog input like circle pad direction
- * @todo Fix this function to be thread-safe.
- * @return PadState object indicating the current pad state
- */
- Service::HID::PadState GetPadState() const {
- return pad_state;
- }
-
- /**
- * Gets the current circle pad state.
- * @note This should be called by the core emu thread to get a state set by the window thread.
- * @todo Fix this function to be thread-safe.
- * @return std::tuple of (x, y), where `x` and `y` are the circle pad coordinates
- */
- std::tuple<s16, s16> GetCirclePadState() const {
- return std::make_tuple(circle_pad_x, circle_pad_y);
- }
-
- /**
- * Gets the current touch screen state (touch X/Y coordinates and whether or not it is pressed).
- * @note This should be called by the core emu thread to get a state set by the window thread.
- * @todo Fix this function to be thread-safe.
- * @return std::tuple of (x, y, pressed) where `x` and `y` are the touch coordinates and
- * `pressed` is true if the touch screen is currently being pressed
- */
- std::tuple<u16, u16, bool> GetTouchState() const {
- return std::make_tuple(touch_x, touch_y, touch_pressed);
- }
-
- /**
- * Gets the current accelerometer state (acceleration along each three axis).
- * Axis explained:
- * +x is the same direction as LEFT on D-pad.
- * +y is normal to the touch screen, pointing outward.
- * +z is the same direction as UP on D-pad.
- * Units:
- * 1 unit of return value = 1/512 g (measured by hw test),
- * where g is the gravitational acceleration (9.8 m/sec2).
- * @note This should be called by the core emu thread to get a state set by the window thread.
- * @todo Implement accelerometer input in front-end.
- * @return std::tuple of (x, y, z)
- */
- std::tuple<s16, s16, s16> GetAccelerometerState() const {
- // stubbed
- return std::make_tuple(0, -512, 0);
- }
-
- /**
- * Gets the current gyroscope state (angular rates about each three axis).
- * Axis explained:
- * +x is the same direction as LEFT on D-pad.
- * +y is normal to the touch screen, pointing outward.
- * +z is the same direction as UP on D-pad.
- * Orientation is determined by right-hand rule.
- * Units:
- * 1 unit of return value = (1/coef) deg/sec,
- * where coef is the return value of GetGyroscopeRawToDpsCoefficient().
- * @note This should be called by the core emu thread to get a state set by the window thread.
- * @todo Implement gyroscope input in front-end.
- * @return std::tuple of (x, y, z)
- */
- std::tuple<s16, s16, s16> GetGyroscopeState() const {
- // stubbed
- return std::make_tuple(0, 0, 0);
- }
-
- /**
- * Gets the coefficient for units conversion of gyroscope state.
- * The conversion formula is r = coefficient * v,
- * where v is angular rate in deg/sec,
- * and r is the gyroscope state.
- * @return float-type coefficient
- */
- f32 GetGyroscopeRawToDpsCoefficient() const {
- return 14.375f; // taken from hw test, and gyroscope's document
- }
-
- /**
- * Returns currently active configuration.
- * @note Accesses to the returned object need not be consistent because it may be modified in
- * another thread
- */
- const WindowConfig& GetActiveConfig() const {
- return active_config;
- }
-
- /**
- * Requests the internal configuration to be replaced by the specified argument at some point in
- * the future.
- * @note This method is thread-safe, because it delays configuration changes to the GUI event
- * loop. Hence there is no guarantee on when the requested configuration will be active.
- */
- void SetConfig(const WindowConfig& val) {
- config = val;
- }
-
- /**
- * Gets the framebuffer layout (width, height, and screen regions)
- * @note This method is thread-safe
- */
- const Layout::FramebufferLayout& GetFramebufferLayout() const {
- return framebuffer_layout;
- }
-
- /**
- * Convenience method to update the current frame layout
- * Read from the current settings to determine which layout to use.
- */
- void UpdateCurrentFramebufferLayout(unsigned width, unsigned height);
-
-protected:
- EmuWindow() {
- // TODO: Find a better place to set this.
- config.min_client_area_size = std::make_pair(400u, 480u);
- active_config = config;
- pad_state.hex = 0;
- touch_x = 0;
- touch_y = 0;
- circle_pad_x = 0;
- circle_pad_y = 0;
- touch_pressed = false;
- }
- virtual ~EmuWindow() {}
-
- /**
- * Processes any pending configuration changes from the last SetConfig call.
- * This method invokes OnMinimalClientAreaChangeRequest if the corresponding configuration
- * field changed.
- * @note Implementations will usually want to call this from the GUI thread.
- * @todo Actually call this in existing implementations.
- */
- void ProcessConfigurationChanges() {
- // TODO: For proper thread safety, we should eventually implement a proper
- // multiple-writer/single-reader queue...
-
- if (config.min_client_area_size != active_config.min_client_area_size) {
- OnMinimalClientAreaChangeRequest(config.min_client_area_size);
- config.min_client_area_size = active_config.min_client_area_size;
- }
- }
-
- /**
- * Update framebuffer layout with the given parameter.
- * @note EmuWindow implementations will usually use this in window resize event handlers.
- */
- void NotifyFramebufferLayoutChanged(const Layout::FramebufferLayout& layout) {
- framebuffer_layout = layout;
- }
-
- /**
- * Update internal client area size with the given parameter.
- * @note EmuWindow implementations will usually use this in window resize event handlers.
- */
- void NotifyClientAreaSizeChanged(const std::pair<unsigned, unsigned>& size) {
- client_area_width = size.first;
- client_area_height = size.second;
- }
-
-private:
- /**
- * Handler called when the minimal client area was requested to be changed via SetConfig.
- * For the request to be honored, EmuWindow implementations will usually reimplement this
- * function.
- */
- virtual void OnMinimalClientAreaChangeRequest(
- const std::pair<unsigned, unsigned>& minimal_size) {
- // By default, ignore this request and do nothing.
- }
-
- Layout::FramebufferLayout framebuffer_layout; ///< Current framebuffer layout
-
- unsigned client_area_width; ///< Current client width, should be set by window impl.
- unsigned client_area_height; ///< Current client height, should be set by window impl.
-
- WindowConfig config; ///< Internal configuration (changes pending for being applied in
- /// ProcessConfigurationChanges)
- WindowConfig active_config; ///< Internal active configuration
-
- bool touch_pressed; ///< True if touchpad area is currently pressed, otherwise false
-
- u16 touch_x; ///< Touchpad X-position in native 3DS pixel coordinates (0-320)
- u16 touch_y; ///< Touchpad Y-position in native 3DS pixel coordinates (0-240)
-
- s16 circle_pad_x; ///< Circle pad X-position in native 3DS pixel coordinates (-156 - 156)
- s16 circle_pad_y; ///< Circle pad Y-position in native 3DS pixel coordinates (-156 - 156)
-
- /**
- * Clip the provided coordinates to be inside the touchscreen area.
- */
- std::tuple<unsigned, unsigned> ClipToTouchScreen(unsigned new_x, unsigned new_y);
-
- Service::HID::PadState pad_state;
-};
diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp
index b6161f2dc..1a1f5d9b5 100644
--- a/src/common/file_util.cpp
+++ b/src/common/file_util.cpp
@@ -40,9 +40,20 @@
#endif
#if defined(__APPLE__)
+// CFURL contains __attribute__ directives that gcc does not know how to parse, so we need to just
+// ignore them if we're not using clang. The macro is only used to prevent linking against
+// functions that don't exist on older versions of macOS, and the worst case scenario is a linker
+// error, so this is perfectly safe, just inconvenient.
+#ifndef __clang__
+#define availability(...)
+#endif
#include <CoreFoundation/CFBundle.h>
#include <CoreFoundation/CFString.h>
#include <CoreFoundation/CFURL.h>
+#ifdef availability
+#undef availability
+#endif
+
#endif
#include <algorithm>
@@ -701,24 +712,9 @@ const std::string& GetUserPath(const unsigned int DirIDX, const std::string& new
paths[D_CACHE_IDX] = cache_dir + DIR_SEP EMU_DATA_DIR DIR_SEP;
}
#endif
-
- paths[D_GAMECONFIG_IDX] = paths[D_USER_IDX] + GAMECONFIG_DIR DIR_SEP;
- paths[D_MAPS_IDX] = paths[D_USER_IDX] + MAPS_DIR DIR_SEP;
paths[D_SDMC_IDX] = paths[D_USER_IDX] + SDMC_DIR DIR_SEP;
paths[D_NAND_IDX] = paths[D_USER_IDX] + NAND_DIR DIR_SEP;
paths[D_SYSDATA_IDX] = paths[D_USER_IDX] + SYSDATA_DIR DIR_SEP;
- paths[D_SHADERCACHE_IDX] = paths[D_USER_IDX] + SHADERCACHE_DIR DIR_SEP;
- paths[D_SHADERS_IDX] = paths[D_USER_IDX] + SHADERS_DIR DIR_SEP;
- paths[D_STATESAVES_IDX] = paths[D_USER_IDX] + STATESAVES_DIR DIR_SEP;
- paths[D_SCREENSHOTS_IDX] = paths[D_USER_IDX] + SCREENSHOTS_DIR DIR_SEP;
- paths[D_DUMP_IDX] = paths[D_USER_IDX] + DUMP_DIR DIR_SEP;
- paths[D_DUMPFRAMES_IDX] = paths[D_DUMP_IDX] + DUMP_FRAMES_DIR DIR_SEP;
- paths[D_DUMPAUDIO_IDX] = paths[D_DUMP_IDX] + DUMP_AUDIO_DIR DIR_SEP;
- paths[D_DUMPTEXTURES_IDX] = paths[D_DUMP_IDX] + DUMP_TEXTURES_DIR DIR_SEP;
- paths[D_LOGS_IDX] = paths[D_USER_IDX] + LOGS_DIR DIR_SEP;
- paths[F_DEBUGGERCONFIG_IDX] = paths[D_CONFIG_IDX] + DEBUGGER_CONFIG;
- paths[F_LOGGERCONFIG_IDX] = paths[D_CONFIG_IDX] + LOGGER_CONFIG;
- paths[F_MAINLOG_IDX] = paths[D_LOGS_IDX] + MAIN_LOG;
}
if (!newPath.empty()) {
@@ -732,48 +728,15 @@ const std::string& GetUserPath(const unsigned int DirIDX, const std::string& new
switch (DirIDX) {
case D_ROOT_IDX:
paths[D_USER_IDX] = paths[D_ROOT_IDX] + DIR_SEP;
- paths[D_SYSCONF_IDX] = paths[D_USER_IDX] + SYSCONF_DIR + DIR_SEP;
- paths[F_SYSCONF_IDX] = paths[D_SYSCONF_IDX] + SYSCONF;
break;
case D_USER_IDX:
paths[D_USER_IDX] = paths[D_ROOT_IDX] + DIR_SEP;
paths[D_CONFIG_IDX] = paths[D_USER_IDX] + CONFIG_DIR DIR_SEP;
- paths[D_GAMECONFIG_IDX] = paths[D_USER_IDX] + GAMECONFIG_DIR DIR_SEP;
- paths[D_MAPS_IDX] = paths[D_USER_IDX] + MAPS_DIR DIR_SEP;
paths[D_CACHE_IDX] = paths[D_USER_IDX] + CACHE_DIR DIR_SEP;
paths[D_SDMC_IDX] = paths[D_USER_IDX] + SDMC_DIR DIR_SEP;
paths[D_NAND_IDX] = paths[D_USER_IDX] + NAND_DIR DIR_SEP;
- paths[D_SHADERCACHE_IDX] = paths[D_USER_IDX] + SHADERCACHE_DIR DIR_SEP;
- paths[D_SHADERS_IDX] = paths[D_USER_IDX] + SHADERS_DIR DIR_SEP;
- paths[D_STATESAVES_IDX] = paths[D_USER_IDX] + STATESAVES_DIR DIR_SEP;
- paths[D_SCREENSHOTS_IDX] = paths[D_USER_IDX] + SCREENSHOTS_DIR DIR_SEP;
- paths[D_DUMP_IDX] = paths[D_USER_IDX] + DUMP_DIR DIR_SEP;
- paths[D_DUMPFRAMES_IDX] = paths[D_DUMP_IDX] + DUMP_FRAMES_DIR DIR_SEP;
- paths[D_DUMPAUDIO_IDX] = paths[D_DUMP_IDX] + DUMP_AUDIO_DIR DIR_SEP;
- paths[D_DUMPTEXTURES_IDX] = paths[D_DUMP_IDX] + DUMP_TEXTURES_DIR DIR_SEP;
- paths[D_LOGS_IDX] = paths[D_USER_IDX] + LOGS_DIR DIR_SEP;
- paths[D_SYSCONF_IDX] = paths[D_USER_IDX] + SYSCONF_DIR DIR_SEP;
- paths[F_EMUCONFIG_IDX] = paths[D_CONFIG_IDX] + EMU_CONFIG;
- paths[F_DEBUGGERCONFIG_IDX] = paths[D_CONFIG_IDX] + DEBUGGER_CONFIG;
- paths[F_LOGGERCONFIG_IDX] = paths[D_CONFIG_IDX] + LOGGER_CONFIG;
- paths[F_MAINLOG_IDX] = paths[D_LOGS_IDX] + MAIN_LOG;
break;
-
- case D_CONFIG_IDX:
- paths[F_EMUCONFIG_IDX] = paths[D_CONFIG_IDX] + EMU_CONFIG;
- paths[F_DEBUGGERCONFIG_IDX] = paths[D_CONFIG_IDX] + DEBUGGER_CONFIG;
- paths[F_LOGGERCONFIG_IDX] = paths[D_CONFIG_IDX] + LOGGER_CONFIG;
- break;
-
- case D_DUMP_IDX:
- paths[D_DUMPFRAMES_IDX] = paths[D_DUMP_IDX] + DUMP_FRAMES_DIR DIR_SEP;
- paths[D_DUMPAUDIO_IDX] = paths[D_DUMP_IDX] + DUMP_AUDIO_DIR DIR_SEP;
- paths[D_DUMPTEXTURES_IDX] = paths[D_DUMP_IDX] + DUMP_TEXTURES_DIR DIR_SEP;
- break;
-
- case D_LOGS_IDX:
- paths[F_MAINLOG_IDX] = paths[D_LOGS_IDX] + MAIN_LOG;
}
}
diff --git a/src/common/file_util.h b/src/common/file_util.h
index ac58607c5..94adfcd7e 100644
--- a/src/common/file_util.h
+++ b/src/common/file_util.h
@@ -21,31 +21,11 @@ enum {
D_USER_IDX,
D_ROOT_IDX,
D_CONFIG_IDX,
- D_GAMECONFIG_IDX,
- D_MAPS_IDX,
D_CACHE_IDX,
- D_SHADERCACHE_IDX,
- D_SHADERS_IDX,
- D_STATESAVES_IDX,
- D_SCREENSHOTS_IDX,
D_SDMC_IDX,
D_NAND_IDX,
D_SYSDATA_IDX,
- D_HIRESTEXTURES_IDX,
- D_DUMP_IDX,
- D_DUMPFRAMES_IDX,
- D_DUMPAUDIO_IDX,
- D_DUMPTEXTURES_IDX,
- D_DUMPDSP_IDX,
D_LOGS_IDX,
- D_SYSCONF_IDX,
- F_EMUCONFIG_IDX,
- F_DEBUGGERCONFIG_IDX,
- F_LOGGERCONFIG_IDX,
- F_MAINLOG_IDX,
- F_RAMDUMP_IDX,
- F_ARAMDUMP_IDX,
- F_SYSCONF_IDX,
NUM_PATH_INDICES
};
diff --git a/src/common/key_map.cpp b/src/common/key_map.cpp
deleted file mode 100644
index 97cafe9c9..000000000
--- a/src/common/key_map.cpp
+++ /dev/null
@@ -1,152 +0,0 @@
-// Copyright 2014 Citra Emulator Project
-// Licensed under GPLv2 or any later version
-// Refer to the license.txt file included.
-
-#include <map>
-#include "common/emu_window.h"
-#include "common/key_map.h"
-
-namespace KeyMap {
-
-// TODO (wwylele): currently we treat c-stick as four direction buttons
-// and map it directly to EmuWindow::ButtonPressed.
-// It should go the analog input way like circle pad does.
-const std::array<KeyTarget, Settings::NativeInput::NUM_INPUTS> mapping_targets = {{
- Service::HID::PAD_A,
- Service::HID::PAD_B,
- Service::HID::PAD_X,
- Service::HID::PAD_Y,
- Service::HID::PAD_L,
- Service::HID::PAD_R,
- Service::HID::PAD_ZL,
- Service::HID::PAD_ZR,
- Service::HID::PAD_START,
- Service::HID::PAD_SELECT,
- Service::HID::PAD_NONE,
- Service::HID::PAD_UP,
- Service::HID::PAD_DOWN,
- Service::HID::PAD_LEFT,
- Service::HID::PAD_RIGHT,
- Service::HID::PAD_C_UP,
- Service::HID::PAD_C_DOWN,
- Service::HID::PAD_C_LEFT,
- Service::HID::PAD_C_RIGHT,
-
- IndirectTarget::CirclePadUp,
- IndirectTarget::CirclePadDown,
- IndirectTarget::CirclePadLeft,
- IndirectTarget::CirclePadRight,
- IndirectTarget::CirclePadModifier,
-}};
-
-static std::map<HostDeviceKey, KeyTarget> key_map;
-static int next_device_id = 0;
-
-static bool circle_pad_up = false;
-static bool circle_pad_down = false;
-static bool circle_pad_left = false;
-static bool circle_pad_right = false;
-static bool circle_pad_modifier = false;
-
-static void UpdateCirclePad(EmuWindow& emu_window) {
- constexpr float SQRT_HALF = 0.707106781f;
- int x = 0, y = 0;
-
- if (circle_pad_right)
- ++x;
- if (circle_pad_left)
- --x;
- if (circle_pad_up)
- ++y;
- if (circle_pad_down)
- --y;
-
- float modifier = circle_pad_modifier ? Settings::values.pad_circle_modifier_scale : 1.0f;
- emu_window.CirclePadUpdated(x * modifier * (y == 0 ? 1.0f : SQRT_HALF),
- y * modifier * (x == 0 ? 1.0f : SQRT_HALF));
-}
-
-int NewDeviceId() {
- return next_device_id++;
-}
-
-void SetKeyMapping(HostDeviceKey key, KeyTarget target) {
- key_map[key] = target;
-}
-
-void ClearKeyMapping(int device_id) {
- auto iter = key_map.begin();
- while (iter != key_map.end()) {
- if (iter->first.device_id == device_id)
- key_map.erase(iter++);
- else
- ++iter;
- }
-}
-
-void PressKey(EmuWindow& emu_window, HostDeviceKey key) {
- auto target = key_map.find(key);
- if (target == key_map.end())
- return;
-
- if (target->second.direct) {
- emu_window.ButtonPressed({{target->second.target.direct_target_hex}});
- } else {
- switch (target->second.target.indirect_target) {
- case IndirectTarget::CirclePadUp:
- circle_pad_up = true;
- UpdateCirclePad(emu_window);
- break;
- case IndirectTarget::CirclePadDown:
- circle_pad_down = true;
- UpdateCirclePad(emu_window);
- break;
- case IndirectTarget::CirclePadLeft:
- circle_pad_left = true;
- UpdateCirclePad(emu_window);
- break;
- case IndirectTarget::CirclePadRight:
- circle_pad_right = true;
- UpdateCirclePad(emu_window);
- break;
- case IndirectTarget::CirclePadModifier:
- circle_pad_modifier = true;
- UpdateCirclePad(emu_window);
- break;
- }
- }
-}
-
-void ReleaseKey(EmuWindow& emu_window, HostDeviceKey key) {
- auto target = key_map.find(key);
- if (target == key_map.end())
- return;
-
- if (target->second.direct) {
- emu_window.ButtonReleased({{target->second.target.direct_target_hex}});
- } else {
- switch (target->second.target.indirect_target) {
- case IndirectTarget::CirclePadUp:
- circle_pad_up = false;
- UpdateCirclePad(emu_window);
- break;
- case IndirectTarget::CirclePadDown:
- circle_pad_down = false;
- UpdateCirclePad(emu_window);
- break;
- case IndirectTarget::CirclePadLeft:
- circle_pad_left = false;
- UpdateCirclePad(emu_window);
- break;
- case IndirectTarget::CirclePadRight:
- circle_pad_right = false;
- UpdateCirclePad(emu_window);
- break;
- case IndirectTarget::CirclePadModifier:
- circle_pad_modifier = false;
- UpdateCirclePad(emu_window);
- break;
- }
- }
-}
-}
diff --git a/src/common/key_map.h b/src/common/key_map.h
deleted file mode 100644
index 040794578..000000000
--- a/src/common/key_map.h
+++ /dev/null
@@ -1,93 +0,0 @@
-// Copyright 2014 Citra Emulator Project
-// Licensed under GPLv2 or any later version
-// Refer to the license.txt file included.
-
-#pragma once
-
-#include <array>
-#include <tuple>
-#include "core/hle/service/hid/hid.h"
-
-class EmuWindow;
-
-namespace KeyMap {
-
-/**
- * Represents key mapping targets that are not real 3DS buttons.
- * They will be handled by KeyMap and translated to 3DS input.
- */
-enum class IndirectTarget {
- CirclePadUp,
- CirclePadDown,
- CirclePadLeft,
- CirclePadRight,
- CirclePadModifier,
-};
-
-/**
- * Represents a key mapping target. It can be a PadState that represents real 3DS buttons,
- * or an IndirectTarget.
- */
-struct KeyTarget {
- bool direct;
- union {
- u32 direct_target_hex;
- IndirectTarget indirect_target;
- } target;
-
- KeyTarget() : direct(true) {
- target.direct_target_hex = 0;
- }
-
- KeyTarget(Service::HID::PadState pad) : direct(true) {
- target.direct_target_hex = pad.hex;
- }
-
- KeyTarget(IndirectTarget i) : direct(false) {
- target.indirect_target = i;
- }
-};
-
-/**
- * Represents a key for a specific host device.
- */
-struct HostDeviceKey {
- int key_code;
- int device_id; ///< Uniquely identifies a host device
-
- bool operator<(const HostDeviceKey& other) const {
- return std::tie(key_code, device_id) < std::tie(other.key_code, other.device_id);
- }
-
- bool operator==(const HostDeviceKey& other) const {
- return std::tie(key_code, device_id) == std::tie(other.key_code, other.device_id);
- }
-};
-
-extern const std::array<KeyTarget, Settings::NativeInput::NUM_INPUTS> mapping_targets;
-
-/**
- * Generates a new device id, which uniquely identifies a host device within KeyMap.
- */
-int NewDeviceId();
-
-/**
- * Maps a device-specific key to a target (a PadState or an IndirectTarget).
- */
-void SetKeyMapping(HostDeviceKey key, KeyTarget target);
-
-/**
- * Clears all key mappings belonging to one device.
- */
-void ClearKeyMapping(int device_id);
-
-/**
- * Maps a key press action and call the corresponding function in EmuWindow
- */
-void PressKey(EmuWindow& emu_window, HostDeviceKey key);
-
-/**
- * Maps a key release action and call the corresponding function in EmuWindow
- */
-void ReleaseKey(EmuWindow& emu_window, HostDeviceKey key);
-}
diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp
index 7fd397fe5..3ea102229 100644
--- a/src/common/logging/backend.cpp
+++ b/src/common/logging/backend.cpp
@@ -50,6 +50,7 @@ namespace Log {
SUB(Service, CAM) \
SUB(Service, CECD) \
SUB(Service, CFG) \
+ SUB(Service, CSND) \
SUB(Service, DSP) \
SUB(Service, DLP) \
SUB(Service, HID) \
diff --git a/src/common/logging/log.h b/src/common/logging/log.h
index 96d0dfb8c..9d8c18d8e 100644
--- a/src/common/logging/log.h
+++ b/src/common/logging/log.h
@@ -67,6 +67,7 @@ enum class Class : ClassType {
Service_CAM, ///< The CAM (Camera) service
Service_CECD, ///< The CECD (StreetPass) service
Service_CFG, ///< The CFG (Configuration) service
+ Service_CSND, ///< The CSND (CWAV format process) service
Service_DSP, ///< The DSP (DSP control) service
Service_DLP, ///< The DLP (Download Play) service
Service_HID, ///< The HID (Human interface device) service
diff --git a/src/common/logging/text_formatter.cpp b/src/common/logging/text_formatter.cpp
index d61c1696b..9d423766f 100644
--- a/src/common/logging/text_formatter.cpp
+++ b/src/common/logging/text_formatter.cpp
@@ -7,7 +7,7 @@
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
-#include <Windows.h>
+#include <windows.h>
#endif
#include "common/assert.h"
diff --git a/src/common/scm_rev.cpp.in b/src/common/scm_rev.cpp.in
index 09366e801..79b404bb8 100644
--- a/src/common/scm_rev.cpp.in
+++ b/src/common/scm_rev.cpp.in
@@ -1,5 +1,5 @@
// Copyright 2014 Citra Emulator Project
-// Licensed under GPLv2
+// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include "common/scm_rev.h"
diff --git a/src/common/string_util.cpp b/src/common/string_util.cpp
index df1008180..bad311793 100644
--- a/src/common/string_util.cpp
+++ b/src/common/string_util.cpp
@@ -14,7 +14,7 @@
#ifdef _WIN32
#include <codecvt>
-#include <Windows.h>
+#include <windows.h>
#include "common/common_funcs.h"
#else
#include <iconv.h>
diff --git a/src/common/thread.cpp b/src/common/thread.cpp
index 9bb2f4e1d..9e207118f 100644
--- a/src/common/thread.cpp
+++ b/src/common/thread.cpp
@@ -6,7 +6,7 @@
#ifdef __APPLE__
#include <mach/mach.h>
#elif defined(_WIN32)
-#include <Windows.h>
+#include <windows.h>
#else
#if defined(__Bitrig__) || defined(__DragonFly__) || defined(__FreeBSD__) || defined(__OpenBSD__)
#include <pthread_np.h>
diff --git a/src/common/timer.cpp b/src/common/timer.cpp
index e843cbd9c..c9803109e 100644
--- a/src/common/timer.cpp
+++ b/src/common/timer.cpp
@@ -4,7 +4,8 @@
#include <time.h>
#ifdef _WIN32
-#include <Windows.h>
+#include <windows.h>
+// windows.h needs to be included before other windows headers
#include <mmsystem.h>
#include <sys/timeb.h>
#else
diff --git a/src/common/x64/xbyak_abi.h b/src/common/x64/xbyak_abi.h
new file mode 100644
index 000000000..6090d93e1
--- /dev/null
+++ b/src/common/x64/xbyak_abi.h
@@ -0,0 +1,178 @@
+// Copyright 2016 Citra Emulator Project
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#pragma once
+
+#include <initializer_list>
+#include <xbyak.h>
+#include "common/assert.h"
+#include "common/bit_set.h"
+
+namespace Common {
+namespace X64 {
+
+int RegToIndex(const Xbyak::Reg& reg) {
+ using Kind = Xbyak::Reg::Kind;
+ ASSERT_MSG((reg.getKind() & (Kind::REG | Kind::XMM)) != 0,
+ "RegSet only support GPRs and XMM registers.");
+ ASSERT_MSG(reg.getIdx() < 16, "RegSet only supports XXM0-15.");
+ return reg.getIdx() + (reg.getKind() == Kind::REG ? 0 : 16);
+}
+
+inline Xbyak::Reg64 IndexToReg64(int reg_index) {
+ ASSERT(reg_index < 16);
+ return Xbyak::Reg64(reg_index);
+}
+
+inline Xbyak::Xmm IndexToXmm(int reg_index) {
+ ASSERT(reg_index >= 16 && reg_index < 32);
+ return Xbyak::Xmm(reg_index - 16);
+}
+
+inline Xbyak::Reg IndexToReg(int reg_index) {
+ if (reg_index < 16) {
+ return IndexToReg64(reg_index);
+ } else {
+ return IndexToXmm(reg_index);
+ }
+}
+
+inline BitSet32 BuildRegSet(std::initializer_list<Xbyak::Reg> regs) {
+ BitSet32 bits;
+ for (const Xbyak::Reg& reg : regs) {
+ bits[RegToIndex(reg)] = true;
+ }
+ return bits;
+}
+
+const BitSet32 ABI_ALL_GPRS(0x0000FFFF);
+const BitSet32 ABI_ALL_XMMS(0xFFFF0000);
+
+#ifdef _WIN32
+
+// Microsoft x64 ABI
+const Xbyak::Reg ABI_RETURN = Xbyak::util::rax;
+const Xbyak::Reg ABI_PARAM1 = Xbyak::util::rcx;
+const Xbyak::Reg ABI_PARAM2 = Xbyak::util::rdx;
+const Xbyak::Reg ABI_PARAM3 = Xbyak::util::r8;
+const Xbyak::Reg ABI_PARAM4 = Xbyak::util::r9;
+
+const BitSet32 ABI_ALL_CALLER_SAVED = BuildRegSet({
+ // GPRs
+ Xbyak::util::rcx, Xbyak::util::rdx, Xbyak::util::r8, Xbyak::util::r9, Xbyak::util::r10,
+ Xbyak::util::r11,
+ // XMMs
+ Xbyak::util::xmm0, Xbyak::util::xmm1, Xbyak::util::xmm2, Xbyak::util::xmm3, Xbyak::util::xmm4,
+ Xbyak::util::xmm5,
+});
+
+const BitSet32 ABI_ALL_CALLEE_SAVED = BuildRegSet({
+ // GPRs
+ Xbyak::util::rbx, Xbyak::util::rsi, Xbyak::util::rdi, Xbyak::util::rbp, Xbyak::util::r12,
+ Xbyak::util::r13, Xbyak::util::r14, Xbyak::util::r15,
+ // XMMs
+ Xbyak::util::xmm6, Xbyak::util::xmm7, Xbyak::util::xmm8, Xbyak::util::xmm9, Xbyak::util::xmm10,
+ Xbyak::util::xmm11, Xbyak::util::xmm12, Xbyak::util::xmm13, Xbyak::util::xmm14,
+ Xbyak::util::xmm15,
+});
+
+constexpr size_t ABI_SHADOW_SPACE = 0x20;
+
+#else
+
+// System V x86-64 ABI
+const Xbyak::Reg ABI_RETURN = Xbyak::util::rax;
+const Xbyak::Reg ABI_PARAM1 = Xbyak::util::rdi;
+const Xbyak::Reg ABI_PARAM2 = Xbyak::util::rsi;
+const Xbyak::Reg ABI_PARAM3 = Xbyak::util::rdx;
+const Xbyak::Reg ABI_PARAM4 = Xbyak::util::rcx;
+
+const BitSet32 ABI_ALL_CALLER_SAVED = BuildRegSet({
+ // GPRs
+ Xbyak::util::rcx, Xbyak::util::rdx, Xbyak::util::rdi, Xbyak::util::rsi, Xbyak::util::r8,
+ Xbyak::util::r9, Xbyak::util::r10, Xbyak::util::r11,
+ // XMMs
+ Xbyak::util::xmm0, Xbyak::util::xmm1, Xbyak::util::xmm2, Xbyak::util::xmm3, Xbyak::util::xmm4,
+ Xbyak::util::xmm5, Xbyak::util::xmm6, Xbyak::util::xmm7, Xbyak::util::xmm8, Xbyak::util::xmm9,
+ Xbyak::util::xmm10, Xbyak::util::xmm11, Xbyak::util::xmm12, Xbyak::util::xmm13,
+ Xbyak::util::xmm14, Xbyak::util::xmm15,
+});
+
+const BitSet32 ABI_ALL_CALLEE_SAVED = BuildRegSet({
+ // GPRs
+ Xbyak::util::rbx, Xbyak::util::rbp, Xbyak::util::r12, Xbyak::util::r13, Xbyak::util::r14,
+ Xbyak::util::r15,
+});
+
+constexpr size_t ABI_SHADOW_SPACE = 0;
+
+#endif
+
+void ABI_CalculateFrameSize(BitSet32 regs, size_t rsp_alignment, size_t needed_frame_size,
+ s32* out_subtraction, s32* out_xmm_offset) {
+ int count = (regs & ABI_ALL_GPRS).Count();
+ rsp_alignment -= count * 8;
+ size_t subtraction = 0;
+ int xmm_count = (regs & ABI_ALL_XMMS).Count();
+ if (xmm_count) {
+ // If we have any XMMs to save, we must align the stack here.
+ subtraction = rsp_alignment & 0xF;
+ }
+ subtraction += 0x10 * xmm_count;
+ size_t xmm_base_subtraction = subtraction;
+ subtraction += needed_frame_size;
+ subtraction += ABI_SHADOW_SPACE;
+ // Final alignment.
+ rsp_alignment -= subtraction;
+ subtraction += rsp_alignment & 0xF;
+
+ *out_subtraction = (s32)subtraction;
+ *out_xmm_offset = (s32)(subtraction - xmm_base_subtraction);
+}
+
+size_t ABI_PushRegistersAndAdjustStack(Xbyak::CodeGenerator& code, BitSet32 regs,
+ size_t rsp_alignment, size_t needed_frame_size = 0) {
+ s32 subtraction, xmm_offset;
+ ABI_CalculateFrameSize(regs, rsp_alignment, needed_frame_size, &subtraction, &xmm_offset);
+
+ for (int reg_index : (regs & ABI_ALL_GPRS)) {
+ code.push(IndexToReg64(reg_index));
+ }
+
+ if (subtraction != 0) {
+ code.sub(code.rsp, subtraction);
+ }
+
+ for (int reg_index : (regs & ABI_ALL_XMMS)) {
+ code.movaps(code.xword[code.rsp + xmm_offset], IndexToXmm(reg_index));
+ xmm_offset += 0x10;
+ }
+
+ return ABI_SHADOW_SPACE;
+}
+
+void ABI_PopRegistersAndAdjustStack(Xbyak::CodeGenerator& code, BitSet32 regs, size_t rsp_alignment,
+ size_t needed_frame_size = 0) {
+ s32 subtraction, xmm_offset;
+ ABI_CalculateFrameSize(regs, rsp_alignment, needed_frame_size, &subtraction, &xmm_offset);
+
+ for (int reg_index : (regs & ABI_ALL_XMMS)) {
+ code.movaps(IndexToXmm(reg_index), code.xword[code.rsp + xmm_offset]);
+ xmm_offset += 0x10;
+ }
+
+ if (subtraction != 0) {
+ code.add(code.rsp, subtraction);
+ }
+
+ // GPRs need to be popped in reverse order
+ for (int reg_index = 15; reg_index >= 0; reg_index--) {
+ if (regs[reg_index]) {
+ code.pop(IndexToReg64(reg_index));
+ }
+ }
+}
+
+} // namespace X64
+} // namespace Common
diff --git a/src/common/x64/xbyak_util.h b/src/common/x64/xbyak_util.h
new file mode 100644
index 000000000..0f52f704b
--- /dev/null
+++ b/src/common/x64/xbyak_util.h
@@ -0,0 +1,49 @@
+// Copyright 2016 Citra Emulator Project
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#pragma once
+
+#include <type_traits>
+#include <xbyak.h>
+#include "common/x64/xbyak_abi.h"
+
+namespace Common {
+namespace X64 {
+
+// Constants for use with cmpps/cmpss
+enum {
+ CMP_EQ = 0,
+ CMP_LT = 1,
+ CMP_LE = 2,
+ CMP_UNORD = 3,
+ CMP_NEQ = 4,
+ CMP_NLT = 5,
+ CMP_NLE = 6,
+ CMP_ORD = 7,
+};
+
+inline bool IsWithin2G(uintptr_t ref, uintptr_t target) {
+ u64 distance = target - (ref + 5);
+ return !(distance >= 0x8000'0000ULL && distance <= ~0x8000'0000ULL);
+}
+
+inline bool IsWithin2G(const Xbyak::CodeGenerator& code, uintptr_t target) {
+ return IsWithin2G(reinterpret_cast<uintptr_t>(code.getCurr()), target);
+}
+
+template <typename T>
+inline void CallFarFunction(Xbyak::CodeGenerator& code, const T f) {
+ static_assert(std::is_pointer<T>(), "Argument must be a (function) pointer.");
+ size_t addr = reinterpret_cast<size_t>(f);
+ if (IsWithin2G(code, addr)) {
+ code.call(f);
+ } else {
+ // ABI_RETURN is a safe temp register to use before a call
+ code.mov(ABI_RETURN, addr);
+ code.call(ABI_RETURN);
+ }
+}
+
+} // namespace X64
+} // namespace Common