From 09510201965cda416a7392bf9af8da684f150547 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 7 Jul 2012 20:56:46 +0300 Subject: [PATCH] (360/Xbox 1) Refactor XInput driver with portability in mind --- 360/frontend-xdk/main.c | 6 +-- 360/xdk_d3d.cpp | 55 +++++++++++++++------ 360/xdk_d3d.h | 4 +- config.def.h | 6 +-- console/griffin/griffin.c | 2 +- console/griffin/hook.h | 10 ++-- driver.c | 4 +- driver.h | 2 +- general.h | 2 +- input/xinput2_input.c | 24 ++++----- msvc/RetroArch-Xbox1/RetroArch-Xbox1.vcproj | 10 ++-- settings.c | 4 +- 12 files changed, 78 insertions(+), 51 deletions(-) diff --git a/360/frontend-xdk/main.c b/360/frontend-xdk/main.c index 2787d4b52d..880bd41e35 100644 --- a/360/frontend-xdk/main.c +++ b/360/frontend-xdk/main.c @@ -262,7 +262,7 @@ int main(int argc, char *argv[]) init_libretro_sym(); video_xdk_d3d.start(); - input_xinput2.init(); + input_xinput.init(); rarch_input_set_default_keybind_names_for_emulator(); @@ -273,7 +273,7 @@ begin_loop: { bool repeat = false; - input_xinput2.poll(NULL); + input_xinput.poll(NULL); rarch_set_auto_viewport(g_extern.frame_cache.width, g_extern.frame_cache.height); @@ -297,7 +297,7 @@ begin_shutdown: menu_free(); video_xdk_d3d.stop(); - input_xinput2.free(NULL); + input_xinput.free(NULL); rarch_exec(); return 0; diff --git a/360/xdk_d3d.cpp b/360/xdk_d3d.cpp index 135794e663..408e222bf6 100644 --- a/360/xdk_d3d.cpp +++ b/360/xdk_d3d.cpp @@ -80,8 +80,14 @@ static void xdk_d3d_set_viewport(bool force_full) d3d->d3d_render_device->Clear(0, NULL, D3DCLEAR_TARGET, 0xff000000, 1.0f, 0); +#ifdef _XBOX360 int width = d3d->video_mode.fIsHiDef ? 1280 : 640; int height = d3d->video_mode.fIsHiDef ? 720 : 480; +#else + // FIXME: Hardcoded for Xbox 1 for now + int width = 640; + int height = 480; +#endif int m_viewport_x_temp, m_viewport_y_temp, m_viewport_width_temp, m_viewport_height_temp; float m_zNear, m_zFar; @@ -163,8 +169,10 @@ static void xdk_d3d_set_rotation(void * data, unsigned orientation) break; } +#ifdef HAVE_HLSL /* TODO: Move to D3DXMATRIX here */ hlsl_set_proj_matrix(XMMatrixRotationZ(angle)); +#endif d3d->should_resize = TRUE; } @@ -224,16 +232,15 @@ static void *xdk_d3d_init(const video_info_t *video, const input_driver_t **inpu return NULL; } - // Get video settings - - memset(&d3d->video_mode, 0, sizeof(d3d->video_mode)); - - XGetVideoMode(&d3d->video_mode); - memset(&d3d->d3dpp, 0, sizeof(d3d->d3dpp)); // no letterboxing in 4:3 mode (if widescreen is // unsupported +#ifdef _XBOX360 + // Get video settings + memset(&d3d->video_mode, 0, sizeof(d3d->video_mode)); + XGetVideoMode(&d3d->video_mode); + if(!d3d->video_mode.fIsWideScreen) d3d->d3dpp.Flags |= D3DPRESENTFLAG_NO_LETTERBOX; @@ -245,25 +252,27 @@ static void *xdk_d3d_init(const video_info_t *video, const input_driver_t **inpu if(g_console.gamma_correction_enable) { d3d->d3dpp.BackBufferFormat = g_console.color_format ? (D3DFORMAT)MAKESRGBFMT(D3DFMT_A8R8G8B8) : (D3DFORMAT)MAKESRGBFMT(D3DFMT_LIN_A1R5G5B5); -#ifdef _XBOX360 d3d->d3dpp.FrontBufferFormat = (D3DFORMAT)MAKESRGBFMT(D3DFMT_LE_X8R8G8B8); -#endif } else { d3d->d3dpp.BackBufferFormat = g_console.color_format ? D3DFMT_A8R8G8B8 : D3DFMT_LIN_A1R5G5B5; -#ifdef _XBOX360 d3d->d3dpp.FrontBufferFormat = D3DFMT_LE_X8R8G8B8; -#endif } - - d3d->d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE; -#ifdef _XBOX360 d3d->d3dpp.MultiSampleQuality = 0; d3d->d3dpp.PresentationInterval = video->vsync ? D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE; #else + /* Xbox 1 */ + d3d->d3dpp.BackBufferFormat = g_console.color_format ? D3DFMT_A8R8G8B8 : D3DFMT_LIN_A1R5G5B5; + + //FIXME: Hardcoded right now + d3d->d3dpp.BackBufferWidth = 640; + d3d->d3dpp.BackBufferHeight = 480; + d3d->d3dpp.FullScreen_PresentationInterval = video->vsync ? D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE; #endif + + d3d->d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE; d3d->d3dpp.BackBufferCount = 2; d3d->d3dpp.EnableAutoDepthStencil = FALSE; d3d->d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; @@ -276,7 +285,11 @@ static void *xdk_d3d_init(const video_info_t *video, const input_driver_t **inpu #endif d3d->d3d_render_device->CreateTexture(512, 512, 1, 0, D3DFMT_LIN_X1R5G5B5, - 0, &d3d->lpTexture, NULL); + 0, &d3d->lpTexture +#ifdef _XBOX360 + , NULL +#endif + ); #ifdef HAVE_FBO xdk_d3d_init_fbo(d3d); @@ -305,6 +318,7 @@ static void *xdk_d3d_init(const video_info_t *video, const input_driver_t **inpu memcpy(verts_ptr, init_verts, sizeof(init_verts)); d3d->vertex_buf->Unlock(); +#ifdef _XBOX360 static const D3DVERTEXELEMENT VertexElements[] = { { 0, 0 * sizeof(float), D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 }, @@ -313,6 +327,9 @@ static void *xdk_d3d_init(const video_info_t *video, const input_driver_t **inpu }; d3d->d3d_render_device->CreateVertexDeclaration(VertexElements, &d3d->v_decl); +#else + //TODO: Xbox 1 +#endif d3d->d3d_render_device->Clear(0, NULL, D3DCLEAR_TARGET, 0xff000000, 1.0f, 0); @@ -321,8 +338,14 @@ static void *xdk_d3d_init(const video_info_t *video, const input_driver_t **inpu d3d->d3d_render_device->SetRenderState(D3DRS_ZENABLE, FALSE); D3DVIEWPORT vp = {0}; +#ifdef _XBOX360 vp.Width = d3d->video_mode.fIsHiDef ? 1280 : 640; vp.Height = d3d->video_mode.fIsHiDef ? 720 : 480; +#else + /* FIXME: Xbox 1 - hardcoded */ + vp.Width = 640; + vp.Height = 480; +#endif vp.MinZ = 0.0f; vp.MaxZ = 1.0f; d3d->d3d_render_device->SetViewport(&vp); @@ -443,7 +466,11 @@ static bool xdk_d3d_frame(void *data, const void *frame, d3d->d3d_render_device->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER); d3d->d3d_render_device->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER); +#ifdef _XBOX360 d3d->d3d_render_device->SetVertexDeclaration(d3d->v_decl); +#else + // TODO: Xbox 1 +#endif d3d->d3d_render_device->SetStreamSource(0, d3d->vertex_buf, #ifdef _XBOX360 0, diff --git a/360/xdk_d3d.h b/360/xdk_d3d.h index 8ee1fbcf3b..89e242ecd2 100644 --- a/360/xdk_d3d.h +++ b/360/xdk_d3d.h @@ -91,11 +91,11 @@ typedef struct xdk_d3d_video LPDIRECT3DTEXTURE_PTR lpTexture; D3DTexture lpTexture_ot_as16srgb; LPDIRECT3DTEXTURE_PTR lpTexture_ot; -#ifdef _XBOX360 +#if defined(_XBOX360) IDirect3DVertexDeclaration9* v_decl; + XVIDEO_MODE video_mode; #endif D3DPRESENT_PARAMETERS d3dpp; - XVIDEO_MODE video_mode; LPDIRECT3DSURFACE_PTR lpSurface; } xdk_d3d_video_t; diff --git a/config.def.h b/config.def.h index c7a38f5485..beb7c3132c 100644 --- a/config.def.h +++ b/config.def.h @@ -65,7 +65,7 @@ enum INPUT_PS3, INPUT_XENON360, INPUT_WII, - INPUT_XDK360, + INPUT_XINPUT, INPUT_LINUXRAW, INPUT_NULL }; @@ -128,8 +128,8 @@ enum #if defined(XENON) #define INPUT_DEFAULT_DRIVER INPUT_XENON360 -#elif defined(_XBOX360) -#define INPUT_DEFAULT_DRIVER INPUT_XDK360 +#elif defined(_XBOX360) || defined(_XBOX) || defined(HAVE_XINPUT2) || defined(HAVE_XINPUT_XBOX1) +#define INPUT_DEFAULT_DRIVER INPUT_XINPUT #elif defined(HAVE_SDL) #define INPUT_DEFAULT_DRIVER INPUT_SDL #elif defined(__CELLOS_LV2__) diff --git a/console/griffin/griffin.c b/console/griffin/griffin.c index f0bfd70bf5..b8a53ae09b 100644 --- a/console/griffin/griffin.c +++ b/console/griffin/griffin.c @@ -123,7 +123,7 @@ INPUT #include "../../wii/input.c" #endif -#ifdef HAVE_XINPUT2 +#if defined(HAVE_XINPUT_XBOX1) || defined(HAVE_XINPUT2) #include "../../input/xinput2_input.c" #endif diff --git a/console/griffin/hook.h b/console/griffin/hook.h index b3d38a75d9..a8e041f05d 100644 --- a/console/griffin/hook.h +++ b/console/griffin/hook.h @@ -73,12 +73,12 @@ #if defined(_XBOX360) -#define input_init_func() xinput2_input_init() -#define input_poll_func() xinput2_input_poll(driver.input_data) +#define input_init_func() xinput_input_init() +#define input_poll_func() xinput_input_poll(driver.input_data) #define input_input_state_func(retro_keybinds, port, device, index, id) \ - xinput2_input_state(driver.input_data, retro_keybinds, port, device, index, id) -#define input_key_pressed_func(key) xinput2_input_key_pressed(driver.input_data, key) -#define input_free_func() xinput2_input_free_input(driver.input_data) + xinput_input_state(driver.input_data, retro_keybinds, port, device, index, id) +#define input_key_pressed_func(key) xinput_input_key_pressed(driver.input_data, key) +#define input_free_func() xinput_input_free_input(driver.input_data) #endif diff --git a/driver.c b/driver.c index 4c2e07a555..b8f9ec2413 100644 --- a/driver.c +++ b/driver.c @@ -119,8 +119,8 @@ static const input_driver_t *input_drivers[] = { #ifdef XENON &input_xenon360, #endif -#ifdef HAVE_XINPUT2 - &input_xinput2, +#if defined(HAVE_XINPUT2) || defined(HAVE_XINPUT_XBOX1) + &input_xinput, #endif #ifdef GEKKO &input_wii, diff --git a/driver.h b/driver.h index 431aa06551..3399e22196 100644 --- a/driver.h +++ b/driver.h @@ -246,7 +246,7 @@ extern const input_driver_t input_x; extern const input_driver_t input_ps3; extern const input_driver_t input_xenon360; extern const input_driver_t input_wii; -extern const input_driver_t input_xinput2; +extern const input_driver_t input_xinput; extern const input_driver_t input_linuxraw; extern const input_driver_t input_null; //////////////////////////////////////////////// diff --git a/general.h b/general.h index 1ece494b95..9ded9fba8c 100644 --- a/general.h +++ b/general.h @@ -245,7 +245,7 @@ struct console_settings #ifdef RARCH_CONSOLE uint32_t input_loop; #endif -#ifdef _XBOX360 +#ifdef _XBOX uint32_t color_format; DWORD volume_device_type; #endif diff --git a/input/xinput2_input.c b/input/xinput2_input.c index 41623990fc..381ee5af97 100644 --- a/input/xinput2_input.c +++ b/input/xinput2_input.c @@ -29,7 +29,7 @@ static uint64_t state[4]; static unsigned pads_connected; -static void xinput2_input_poll(void *data) +static void xinput_input_poll(void *data) { (void)data; @@ -54,7 +54,7 @@ static void xinput2_input_poll(void *data) } } -static int16_t xinput2_input_state(void *data, const struct retro_keybind **binds, +static int16_t xinput_input_state(void *data, const struct retro_keybind **binds, unsigned port, unsigned device, unsigned index, unsigned id) { @@ -65,7 +65,7 @@ static int16_t xinput2_input_state(void *data, const struct retro_keybind **bind return (state[player] & button) ? 1 : 0; } -static void xinput2_input_free_input(void *data) +static void xinput_input_free_input(void *data) { (void)data; } @@ -99,7 +99,7 @@ void xdk360_input_map_dpad_to_stick(uint32_t map_dpad_enum, uint32_t controller_ } #endif -static void* xinput2_input_init(void) +static void* xinput_input_init(void) { #ifdef _XBOX for(unsigned i = 0; i < 4; i++) @@ -108,7 +108,7 @@ static void* xinput2_input_init(void) return (void*)-1; } -static bool xinput2_input_key_pressed(void *data, int key) +static bool xinput_input_key_pressed(void *data, int key) { (void)data; bool retval = false; @@ -164,12 +164,12 @@ static bool xinput2_input_key_pressed(void *data, int key) return retval; } -const input_driver_t input_xinput2 = +const input_driver_t input_xinput = { - xinput2_input_init, - xinput2_input_poll, - xinput2_input_state, - xinput2_input_key_pressed, - xinput2_input_free_input, - "xinput2" + xinput_input_init, + xinput_input_poll, + xinput_input_state, + xinput_input_key_pressed, + xinput_input_free_input, + "xinput" }; diff --git a/msvc/RetroArch-Xbox1/RetroArch-Xbox1.vcproj b/msvc/RetroArch-Xbox1/RetroArch-Xbox1.vcproj index 4368d6ba4b..af3a7293e0 100644 --- a/msvc/RetroArch-Xbox1/RetroArch-Xbox1.vcproj +++ b/msvc/RetroArch-Xbox1/RetroArch-Xbox1.vcproj @@ -21,7 +21,7 @@ Optimization="0" OptimizeForProcessor="2" AdditionalIncludeDirectories=""$(SolutionDir)\msvc-stdint";"$(SolutionDir)\msvc-71"" - PreprocessorDefinitions="_DEBUG;_XBOX;_XBOX1;RARCH_CONSOLE;PACKAGE_VERSION=\"0.9.6\";__STDC_CONSTANT_MACROS;HAVE_ZLIB;HAVE_GRIFFIN" + PreprocessorDefinitions="_DEBUG;_XBOX;_XBOX1;RARCH_CONSOLE;HAVE_XINPUT_XBOX1;PACKAGE_VERSION=\"0.9.6\";__STDC_CONSTANT_MACROS;HAVE_ZLIB;HAVE_GRIFFIN" MinimalRebuild="TRUE" BasicRuntimeChecks="3" RuntimeLibrary="1" @@ -68,7 +68,7 @@ OmitFramePointers="TRUE" OptimizeForProcessor="2" AdditionalIncludeDirectories=""$(SolutionDir)\msvc-stdint";"$(SolutionDir)\msvc-71"" - PreprocessorDefinitions="NDEBUG;_XBOX;_XBOX1;RARCH_CONSOLE;PACKAGE_VERSION=\"0.9.6\";__STDC_CONSTANT_MACROS;HAVE_ZLIB;PROFILE;HAVE_GRIFFIN" + PreprocessorDefinitions="NDEBUG;_XBOX;_XBOX1;RARCH_CONSOLE;HAVE_XINPUT_XBOX1;PACKAGE_VERSION=\"0.9.6\";__STDC_CONSTANT_MACROS;HAVE_ZLIB;PROFILE;HAVE_GRIFFIN" StringPooling="TRUE" RuntimeLibrary="0" BufferSecurityCheck="TRUE" @@ -119,7 +119,7 @@ OmitFramePointers="TRUE" OptimizeForProcessor="2" AdditionalIncludeDirectories=""$(SolutionDir)\msvc-stdint";"$(SolutionDir)\msvc-71"" - PreprocessorDefinitions="NDEBUG;_XBOX;_XBOX1;RARCH_CONSOLE;PACKAGE_VERSION=\"0.9.6\";__STDC_CONSTANT_MACROS;HAVE_ZLIB;PROFILE;FASTCAP;HAVE_GRIFFIN" + PreprocessorDefinitions="NDEBUG;_XBOX;_XBOX1;RARCH_CONSOLE;HAVE_XINPUT_XBOX1;PACKAGE_VERSION=\"0.9.6\";__STDC_CONSTANT_MACROS;HAVE_ZLIB;PROFILE;FASTCAP;HAVE_GRIFFIN" StringPooling="TRUE" RuntimeLibrary="0" BufferSecurityCheck="TRUE" @@ -171,7 +171,7 @@ OmitFramePointers="TRUE" OptimizeForProcessor="2" AdditionalIncludeDirectories=""$(SolutionDir)\msvc-stdint";"$(SolutionDir)\msvc-71"" - PreprocessorDefinitions="NDEBUG;_XBOX;_XBOX1;RARCH_CONSOLE;PACKAGE_VERSION=\"0.9.6\";__STDC_CONSTANT_MACROS;HAVE_ZLIB;HAVE_GRIFFIN;inline=_inline" + PreprocessorDefinitions="NDEBUG;_XBOX;_XBOX1;RARCH_CONSOLE;HAVE_XINPUT_XBOX1;PACKAGE_VERSION=\"0.9.6\";__STDC_CONSTANT_MACROS;HAVE_ZLIB;HAVE_GRIFFIN;inline=_inline" StringPooling="TRUE" RuntimeLibrary="0" BufferSecurityCheck="TRUE" @@ -221,7 +221,7 @@ OmitFramePointers="TRUE" OptimizeForProcessor="2" AdditionalIncludeDirectories=""$(SolutionDir)\msvc-stdint";"$(SolutionDir)\msvc-71"" - PreprocessorDefinitions="NDEBUG;_XBOX;_XBOX1;RARCH_CONSOLE;PACKAGE_VERSION=\"0.9.6\";__STDC_CONSTANT_MACROS;HAVE_ZLIB;LTCG;HAVE_GRIFFIN" + PreprocessorDefinitions="NDEBUG;_XBOX;_XBOX1;RARCH_CONSOLE;HAVE_XINPUT_XBOX1;PACKAGE_VERSION=\"0.9.6\";__STDC_CONSTANT_MACROS;HAVE_ZLIB;LTCG;HAVE_GRIFFIN" StringPooling="TRUE" RuntimeLibrary="0" BufferSecurityCheck="TRUE" diff --git a/settings.c b/settings.c index 7d3f4c8773..ebc9bc7da7 100644 --- a/settings.c +++ b/settings.c @@ -114,8 +114,8 @@ const char *config_get_default_input(void) return "x"; case INPUT_XENON360: return "xenon360"; - case INPUT_XDK360: - return "xinput2"; + case INPUT_XINPUT: + return "xinput"; case INPUT_WII: return "wii"; case INPUT_LINUXRAW: