diff --git a/src/citra/emu_window/emu_window_glfw.cpp b/src/citra/emu_window/emu_window_glfw.cpp index f882a825e..6b15a734f 100644 --- a/src/citra/emu_window/emu_window_glfw.cpp +++ b/src/citra/emu_window/emu_window_glfw.cpp @@ -5,12 +5,33 @@ #include "common/common.h" #include "video_core/video_core.h" +#include "core/hw/hid.h" + +#include #include "citra/citra.h" #include "citra/emu_window/emu_window_glfw.h" -static void OnKeyEvent(GLFWwindow* win, int key, int action) { - // TODO(bunnei): ImplementMe +typedef std::map GLFWKeyMapping; + +GLFWKeyMapping g_key_mapping; + +u32 g_button_reg; + +static void OnKeyEvent(GLFWwindow* win, int key, int scancode, int action, int mods ) { + try { + HID::PAD button = g_key_mapping.at(key); + if (action == GLFW_RELEASE) { + g_button_reg &= 0xffffffff ^ button; + } + else if (action == GLFW_PRESS){ + g_button_reg |= button; + } + HID::SetButtonReg(g_button_reg); + } + catch (std::out_of_range& e){ + + } } static void OnWindowSizeEvent(GLFWwindow* win, int width, int height) { @@ -19,6 +40,24 @@ static void OnWindowSizeEvent(GLFWwindow* win, int width, int height) { emu_window->SetClientAreaHeight(height); } +void SetKeyDefaults() { + g_key_mapping['Y'] = HID::PAD::PAD_A; + g_key_mapping['H'] = HID::PAD::PAD_B; + g_key_mapping['Z'] = HID::PAD::PAD_START; + g_key_mapping['X'] = HID::PAD::PAD_SELECT; + + g_key_mapping['W'] = HID::PAD::PAD_UP; + g_key_mapping['A'] = HID::PAD::PAD_LEFT; + g_key_mapping['S'] = HID::PAD::PAD_DOWN; + g_key_mapping['D'] = HID::PAD::PAD_RIGHT; + + g_key_mapping['6'] = HID::PAD::PAD_R; + g_key_mapping['7'] = HID::PAD::PAD_L; + g_key_mapping['U'] = HID::PAD::PAD_X; + g_key_mapping['J'] = HID::PAD::PAD_Y; +} + + /// EmuWindow_GLFW constructor EmuWindow_GLFW::EmuWindow_GLFW() { // Initialize the window @@ -46,9 +85,11 @@ EmuWindow_GLFW::EmuWindow_GLFW() { // Setup callbacks glfwSetWindowUserPointer(m_render_window, this); - //glfwSetKeyCallback(m_render_window, OnKeyEvent); + glfwSetKeyCallback(m_render_window, (GLFWkeyfun)OnKeyEvent); //glfwSetWindowSizeCallback(m_render_window, OnWindowSizeEvent); + SetKeyDefaults(); + DoneCurrent(); } diff --git a/src/citra_qt/key_bindings.cpp b/src/citra_qt/key_bindings.cpp index b49ead464..305d7574b 100644 --- a/src/citra_qt/key_bindings.cpp +++ b/src/citra_qt/key_bindings.cpp @@ -1,3 +1,7 @@ +// Copyright 2014 Citra Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + #include #include #include @@ -64,7 +68,7 @@ void RegisterKeyBinding(const QKeySequence keySeq, const HID::PAD pad) } void createNameMap() { - for (int i = 0; i < HID::numPadItems; i++){ + for (int i = 0; i < HID::g_num_pad_items; i++){ names[(HID::PAD)(1 << i)] = QString(HID::PAD_NAMES[i]); reverseNames[QString(HID::PAD_NAMES[i])] = (HID::PAD)(1 << i); } diff --git a/src/citra_qt/key_bindings.hxx b/src/citra_qt/key_bindings.hxx index 690934a47..fdcbbad63 100644 --- a/src/citra_qt/key_bindings.hxx +++ b/src/citra_qt/key_bindings.hxx @@ -1,3 +1,7 @@ +// Copyright 2014 Citra Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + #include #include "ui_key_bindings.h" #include "core/hw/hid.h" diff --git a/src/core/core.vcxproj.filters b/src/core/core.vcxproj.filters index 24548c7fb..1dd33334a 100644 --- a/src/core/core.vcxproj.filters +++ b/src/core/core.vcxproj.filters @@ -167,11 +167,13 @@ hle\kernel - hle\kernel - + + + + hw @@ -319,4 +321,4 @@ - \ No newline at end of file + diff --git a/src/core/hle/service/gsp.cpp b/src/core/hle/service/gsp.cpp index 3d2e7580e..34b8535fb 100644 --- a/src/core/hle/service/gsp.cpp +++ b/src/core/hle/service/gsp.cpp @@ -22,7 +22,7 @@ GraphicsDebugger g_debugger; //Handle to irq memory -Handle memIRQ; +Handle g_mem_irq; /// GSP shared memory GX command buffer header @@ -126,8 +126,8 @@ void RegisterInterruptRelayQueue(Service::Interface* self) { Kernel::SetPermanentLock(event_handle, true); cmd_buff[2] = g_thread_id; // ThreadID - memIRQ = Kernel::CreateSharedMemory(0x1000); //page size for now - cmd_buff[4] = memIRQ; + g_mem_irq = Kernel::CreateSharedMemory(0x1000); //page size for now + cmd_buff[4] = g_mem_irq; } diff --git a/src/core/hw/hid.h b/src/core/hw/hid.h index ab64e1284..e97b25a64 100644 --- a/src/core/hw/hid.h +++ b/src/core/hw/hid.h @@ -1,3 +1,7 @@ +// Copyright 2014 Citra Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + #pragma once #include "common/common_types.h" @@ -13,15 +17,10 @@ struct Registers { extern Registers g_regs; enum { - OFFSET_BUTTONS = 0x1c, //TODO: it works using the shared mem mapping with all homebrew tested, however the wiki states 0x10146000 as the paddr + OFFSET_BUTTONS = 0x1c, }; - -enum { - REG_BUTTONS = 0x1EC46000 //does not work due to confusion between shared mem and hardware IO -}; - -const int numPadItems = 12; // figure out a better way :( +const int g_num_pad_items = 12; enum PAD { PAD_A = (1 << 0), @@ -38,7 +37,7 @@ enum PAD { PAD_Y = (1 << 11), }; -char * const PAD_NAMES[] = { +const char * const PAD_NAMES[] = { "PAD_A", "PAD_B", "PAD_SELECT", @@ -53,7 +52,7 @@ char * const PAD_NAMES[] = { "PAD_Y" }; -void SetButtonReg(u32 buttonData); +void SetButtonReg(u32 button_data); /// Update hardware void Update(); diff --git a/src/core/hw/hw.cpp b/src/core/hw/hw.cpp index bb3c7ae68..62e707549 100644 --- a/src/core/hw/hw.cpp +++ b/src/core/hw/hw.cpp @@ -107,4 +107,4 @@ void Shutdown() { NOTICE_LOG(HW, "shutdown OK"); } -} \ No newline at end of file +} diff --git a/src/video_core/renderer_opengl/renderer_opengl.cpp b/src/video_core/renderer_opengl/renderer_opengl.cpp index 70af47c59..0b89235ff 100644 --- a/src/video_core/renderer_opengl/renderer_opengl.cpp +++ b/src/video_core/renderer_opengl/renderer_opengl.cpp @@ -261,7 +261,6 @@ void RendererOpenGL::Init() { glScissor(0, 0, m_resolution_width, m_resolution_height); glClearDepth(1.0f); - GLenum err = glewInit(); if (GLEW_OK != err) { ERROR_LOG(RENDER, "Failed to initialize GLEW! Error message: \"%s\". Exiting...", diff --git a/src/video_core/video_core.cpp b/src/video_core/video_core.cpp index 3b8039de4..b53555bf1 100644 --- a/src/video_core/video_core.cpp +++ b/src/video_core/video_core.cpp @@ -35,6 +35,10 @@ void Init(EmuWindow* emu_window) { // Known problem with GLEW prevents contexts above 2.x on OSX unless glewExperimental is enabled. glewExperimental = GL_TRUE; #endif +#if EMU_PLATFORM == PLATFORM_WINDOWS + glewExperimental = GL_TRUE; +#endif + g_emu_window = emu_window; g_emu_window->MakeCurrent();