diff options
author | StapleButter <thetotalworm@gmail.com> | 2017-09-21 04:35:55 +0200 |
---|---|---|
committer | StapleButter <thetotalworm@gmail.com> | 2017-09-21 04:35:55 +0200 |
commit | 2eea801d261bbcf1a44c2fd4857832b7b74104fb (patch) | |
tree | 55b3679877f49cf57c05822a5311e884991c383c /src/wx | |
parent | 76c5451ad9951aecd53a9edcc6485de40170691f (diff) |
goodbye wx crap. you will not be missed.
Diffstat (limited to 'src/wx')
-rw-r--r-- | src/wx/EmuConfig.cpp | 84 | ||||
-rw-r--r-- | src/wx/EmuConfig.h | 45 | ||||
-rw-r--r-- | src/wx/InputConfig.cpp | 378 | ||||
-rw-r--r-- | src/wx/InputConfig.h | 64 | ||||
-rw-r--r-- | src/wx/Platform.cpp | 262 | ||||
-rw-r--r-- | src/wx/main.cpp | 728 | ||||
-rw-r--r-- | src/wx/main.h | 123 | ||||
-rw-r--r-- | src/wx/scancode_wx2sdl.h | 336 |
8 files changed, 0 insertions, 2020 deletions
diff --git a/src/wx/EmuConfig.cpp b/src/wx/EmuConfig.cpp deleted file mode 100644 index a8822a6..0000000 --- a/src/wx/EmuConfig.cpp +++ /dev/null @@ -1,84 +0,0 @@ -/* - Copyright 2016-2017 StapleButter - - This file is part of melonDS. - - melonDS is free software: you can redistribute it and/or modify it under - the terms of the GNU General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your option) - any later version. - - melonDS is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with melonDS. If not, see http://www.gnu.org/licenses/. -*/ - -#include "../types.h" -#include "EmuConfig.h" -#include "../Config.h" - - -wxBEGIN_EVENT_TABLE(EmuConfigDialog, wxDialog) - EVT_COMMAND(1001, wxEVT_BUTTON, EmuConfigDialog::OnOk) - EVT_COMMAND(1002, wxEVT_BUTTON, EmuConfigDialog::OnCancel) -wxEND_EVENT_TABLE() - - -EmuConfigDialog::EmuConfigDialog(wxWindow* parent) - : wxDialog(parent, -1, "Emulation settings - melonDS") -{ - wxBoxSizer* vboxmain = new wxBoxSizer(wxVERTICAL); - - cbDirectBoot = new wxCheckBox(this, wxID_ANY, "Boot game directly"); - vboxmain->Add(cbDirectBoot, 0, wxALL&(~wxBOTTOM), 15); - cbDirectBoot->SetValue(Config::DirectBoot != 0); - - cbThreaded3D = new wxCheckBox(this, wxID_ANY, "Threaded 3D renderer"); - vboxmain->Add(cbThreaded3D, 0, wxALL&(~wxBOTTOM), 15); - cbThreaded3D->SetValue(Config::Threaded3D != 0); - - cbBindAnyAddr = new wxCheckBox(this, wxID_ANY, "Wifi: bind socket to any address"); - vboxmain->Add(cbBindAnyAddr, 0, wxALL&(~wxBOTTOM), 15); - cbBindAnyAddr->SetValue(Config::SocketBindAnyAddr != 0); - - { - wxPanel* p = new wxPanel(this); - wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL); - - wxButton* ok = new wxButton(p, 1001, "OK"); - sizer->Add(ok); - - wxButton* cancel = new wxButton(p, 1002, "Cancel"); - sizer->Add(3, 0); - sizer->Add(cancel); - - p->SetSizer(sizer); - vboxmain->Add(p, 0, wxALL|wxALIGN_RIGHT, 15); - } - - SetSizer(vboxmain); - Fit(); -} - -EmuConfigDialog::~EmuConfigDialog() -{ -} - -void EmuConfigDialog::OnOk(wxCommandEvent& event) -{ - Config::DirectBoot = cbDirectBoot->GetValue() ? 1:0; - Config::Threaded3D = cbThreaded3D->GetValue() ? 1:0; - Config::SocketBindAnyAddr = cbBindAnyAddr->GetValue() ? 1:0; - Config::Save(); - - Close(); -} - -void EmuConfigDialog::OnCancel(wxCommandEvent& event) -{ - Close(); -} - diff --git a/src/wx/EmuConfig.h b/src/wx/EmuConfig.h deleted file mode 100644 index 907692f..0000000 --- a/src/wx/EmuConfig.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - Copyright 2016-2017 StapleButter - - This file is part of melonDS. - - melonDS is free software: you can redistribute it and/or modify it under - the terms of the GNU General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your option) - any later version. - - melonDS is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with melonDS. If not, see http://www.gnu.org/licenses/. -*/ - -#ifndef WX_EMUCONFIG_H -#define WX_EMUCONFIG_H - -#include <wx/wxprec.h> -#ifndef WX_PRECOMP -#include <wx/wx.h> -#endif - -class EmuConfigDialog : public wxDialog -{ -public: - EmuConfigDialog(wxWindow* parent); - ~EmuConfigDialog(); - -private: - wxDECLARE_EVENT_TABLE(); - - void OnOk(wxCommandEvent& event); - void OnCancel(wxCommandEvent& event); - - wxCheckBox* cbDirectBoot; - wxCheckBox* cbThreaded3D; - wxCheckBox* cbBindAnyAddr; -}; - -#endif // WX_EMUCONFIG_H - diff --git a/src/wx/InputConfig.cpp b/src/wx/InputConfig.cpp deleted file mode 100644 index 010b7a9..0000000 --- a/src/wx/InputConfig.cpp +++ /dev/null @@ -1,378 +0,0 @@ -/* - Copyright 2016-2017 StapleButter - - This file is part of melonDS. - - melonDS is free software: you can redistribute it and/or modify it under - the terms of the GNU General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your option) - any later version. - - melonDS is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with melonDS. If not, see http://www.gnu.org/licenses/. -*/ - -#include "../types.h" -#include "InputConfig.h" -#include "../Config.h" -#include "scancode_wx2sdl.h" - - -wxBEGIN_EVENT_TABLE(InputConfigDialog, wxDialog) - EVT_COMMAND(1001, wxEVT_BUTTON, InputConfigDialog::OnOk) - EVT_COMMAND(1002, wxEVT_BUTTON, InputConfigDialog::OnCancel) - - EVT_TIMER(wxID_ANY, InputConfigDialog::OnPoll) - EVT_CHAR_HOOK(InputConfigDialog::OnKeyDown) -wxEND_EVENT_TABLE() - - -InputConfigDialog::InputConfigDialog(wxWindow* parent) - : wxDialog(parent, -1, "Input configuration - melonDS") -{ - int keyorder[12] = {0, 1, 10, 11, 5, 4, 6, 7, 9, 8, 3, 2}; - char keylabels[12][8] = {"A:", "B:", "Select:", "Start:", "Right:", "Left:", "Up:", "Down:", "R:", "L:", "X:", "Y:"}; - - memcpy(keymapping, Config::KeyMapping, 12*sizeof(int)); - memcpy(joymapping, Config::JoyMapping, 12*sizeof(int)); - - wxBoxSizer* vboxmain = new wxBoxSizer(wxVERTICAL); - - { - wxPanel* p = new wxPanel(this); - wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL); - - wxStaticBox* kbdside = new wxStaticBox(p, wxID_ANY, "Keyboard"); - { - wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL); - wxPanel* p = new wxPanel(kbdside); - wxFlexGridSizer* grid = new wxFlexGridSizer(2, 3, 8); - - for (int i = 0; i < 12; i++) - { - int j = keyorder[i]; - - wxStaticText* label = new wxStaticText(p, wxID_ANY, keylabels[j]); - grid->Add(label, 0, wxALIGN_RIGHT|wxALIGN_CENTRE_VERTICAL); - - // SDL_GetScancodeName() doesn't take the keyboard layout into account, - // which can be inconvenient - const char* keyname = SDL_GetKeyName(SDL_GetKeyFromScancode((SDL_Scancode)keymapping[j])); - - wxStaticText* btn = new wxStaticText(p, 100+j, keyname, - wxDefaultPosition, wxDefaultSize, - wxALIGN_CENTRE_HORIZONTAL | wxBORDER_SUNKEN | wxST_NO_AUTORESIZE); - btn->SetMinSize(wxSize(120, btn->GetSize().GetHeight())); - grid->Add(btn); - - btn->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)); - btn->SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT)); - - btn->Connect(100+j, wxEVT_LEFT_UP, wxMouseEventHandler(InputConfigDialog::OnConfigureKey)); - btn->Connect(100+j, wxEVT_ENTER_WINDOW, wxMouseEventHandler(InputConfigDialog::OnFancybuttonHover)); - btn->Connect(100+j, wxEVT_LEAVE_WINDOW, wxMouseEventHandler(InputConfigDialog::OnFancybuttonHover)); - } - - p->SetSizer(grid); - sizer->Add(p, 0, wxALL, 15); - kbdside->SetSizer(sizer); - } - sizer->Add(kbdside); - - wxStaticBox* joyside = new wxStaticBox(p, wxID_ANY, "Joystick"); - { - wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL); - wxPanel* p = new wxPanel(joyside); - wxFlexGridSizer* grid = new wxFlexGridSizer(2, 3, 8); - - for (int i = 0; i < 12; i++) - { - int j = keyorder[i]; - - wxStaticText* label = new wxStaticText(p, wxID_ANY, keylabels[j]); - grid->Add(label, 0, wxALIGN_RIGHT|wxALIGN_CENTRE_VERTICAL); - - char keyname[16]; - JoyMappingName(joymapping[j], keyname); - - wxStaticText* btn = new wxStaticText(p, 200+j, keyname, - wxDefaultPosition, wxDefaultSize, - wxALIGN_CENTRE_HORIZONTAL | wxBORDER_SUNKEN | wxST_NO_AUTORESIZE); - btn->SetMinSize(wxSize(120, btn->GetSize().GetHeight())); - grid->Add(btn); - - btn->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)); - btn->SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT)); - - btn->Connect(200+j, wxEVT_LEFT_UP, wxMouseEventHandler(InputConfigDialog::OnConfigureJoy)); - btn->Connect(200+j, wxEVT_ENTER_WINDOW, wxMouseEventHandler(InputConfigDialog::OnFancybuttonHover)); - btn->Connect(200+j, wxEVT_LEAVE_WINDOW, wxMouseEventHandler(InputConfigDialog::OnFancybuttonHover)); - } - - p->SetSizer(grid); - sizer->Add(p, 0, wxALL, 15); - - /*wxComboBox* joycombo = new wxComboBox(joyside, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_DROPDOWN | wxCB_READONLY); - - int numjoys = SDL_NumJoysticks(); - if (numjoys > 0) - { - for (int i = 0; i < numjoys; i++) - { - const char* name = SDL_JoystickNameForIndex(i); - joycombo->Insert(name, i); - } - } - else - { - joycombo->Append("(no joystick)"); - joycombo->Enable(false); - } - - sizer->Add(joycombo, 0, wxALL&(~wxTOP), 15);*/ - - joyside->SetSizer(sizer); - } - sizer->Add(15, 0); - sizer->Add(joyside); - - p->SetSizer(sizer); - vboxmain->Add(p, 0, wxALL&(~wxBOTTOM), 15); - } - - { - wxPanel* p = new wxPanel(this); - wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL); - - wxButton* ok = new wxButton(p, 1001, "OK"); - sizer->Add(ok); - - wxButton* cancel = new wxButton(p, 1002, "Cancel"); - sizer->Add(3, 0); - sizer->Add(cancel); - - p->SetSizer(sizer); - vboxmain->Add(p, 0, wxALL|wxALIGN_RIGHT, 15); - } - - SetSizer(vboxmain); - Fit(); - - polltimer = new wxTimer(this); - pollid = 0; - - njoys = SDL_NumJoysticks(); - if (njoys) joy = SDL_JoystickOpen(0); -} - -InputConfigDialog::~InputConfigDialog() -{ - delete polltimer; - - if (njoys) SDL_JoystickClose(0); -} - -void InputConfigDialog::OnOk(wxCommandEvent& event) -{ - memcpy(Config::KeyMapping, keymapping, 12*sizeof(int)); - memcpy(Config::JoyMapping, joymapping, 12*sizeof(int)); - Config::Save(); - - Close(); -} - -void InputConfigDialog::OnCancel(wxCommandEvent& event) -{ - Close(); -} - -void InputConfigDialog::OnKeyDown(wxKeyEvent& event) -{ - if (pollid < 100) return; - int id = pollid - 100; - - SDL_Scancode code = scancode_wx2sdl(event); - - if (code == SDL_SCANCODE_ESCAPE) - { - if (pollid >= 200) polltimer->Stop(); - pollbtn->SetLabel(pollbtntext); - pollid = 0; - - pollbtn->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)); - pollbtn->SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT)); - pollbtn->Refresh(); - return; - } - else if ((code == SDL_SCANCODE_BACKSPACE) && (pollid >= 200)) - { - id = pollid - 200; - if (id >= 12) return; - - joymapping[id] = -1; - - char keyname[16]; - JoyMappingName(joymapping[id], keyname); - pollbtn->SetLabel(keyname); - - polltimer->Stop(); - pollid = 0; - - pollbtn->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)); - pollbtn->SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT)); - pollbtn->Refresh(); - return; - } - - if (id >= 12) return; - - keymapping[id] = code; - - pollbtn->Enable(true); - - const char* keyname = SDL_GetKeyName(SDL_GetKeyFromScancode(code)); - pollbtn->SetLabel(keyname); - - polltimer->Stop(); - pollid = 0; - - pollbtn->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)); - pollbtn->SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT)); - pollbtn->Refresh(); -} - -// black magic going on there -// these two event handlers are in the InputConfigDialog class for convenience, -// but when they're called, 'this' points to a wxStaticText instance - -void InputConfigDialog::OnConfigureKey(wxMouseEvent& event) -{ - wxStaticText* btn = (wxStaticText*)this; - InputConfigDialog* parent = (InputConfigDialog*)btn->GetParent()->GetParent()->GetParent()->GetParent(); - if (parent->pollid != 0) return; - - parent->pollbtn = btn; - parent->pollbtntext = btn->GetLabel(); - parent->pollid = event.GetId(); - - btn->SetLabel("[press key]"); - btn->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNHIGHLIGHT)); - btn->SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT)); - btn->Refresh(); -} - -void InputConfigDialog::OnConfigureJoy(wxMouseEvent& event) -{ - wxStaticText* btn = (wxStaticText*)this; - InputConfigDialog* parent = (InputConfigDialog*)btn->GetParent()->GetParent()->GetParent()->GetParent(); - if (parent->pollid != 0) return; - - parent->pollbtn = btn; - parent->pollbtntext = btn->GetLabel(); - parent->pollid = event.GetId(); - parent->polltimer->Start(50); - - btn->SetLabel("[press button]"); - btn->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNHIGHLIGHT)); - btn->SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT)); - btn->Refresh(); -} - -void InputConfigDialog::OnPoll(wxTimerEvent& event) -{ - if (pollid < 200) return; - - int id = pollid - 200; - if (id >= 12) return; - - int nbuttons = SDL_JoystickNumButtons(joy); - for (int i = 0; i < nbuttons; i++) - { - if (SDL_JoystickGetButton(joy, i)) - { - joymapping[id] = i; - - char keyname[16]; - JoyMappingName(joymapping[id], keyname); - pollbtn->SetLabel(keyname); - - polltimer->Stop(); - pollid = 0; - - pollbtn->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)); - pollbtn->SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT)); - pollbtn->Refresh(); - return; - } - } - - u8 blackhat = SDL_JoystickGetHat(joy, 0); - if (blackhat) - { - if (blackhat & 0x1) blackhat = 0x1; - else if (blackhat & 0x2) blackhat = 0x2; - else if (blackhat & 0x4) blackhat = 0x4; - else blackhat = 0x8; - - joymapping[id] = 0x100 | blackhat; - - char keyname[16]; - JoyMappingName(joymapping[id], keyname); - pollbtn->SetLabel(keyname); - - polltimer->Stop(); - pollid = 0; - - pollbtn->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)); - pollbtn->SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT)); - pollbtn->Refresh(); - return; - } -} - -void InputConfigDialog::OnFancybuttonHover(wxMouseEvent& event) -{ - wxStaticText* btn = (wxStaticText*)this; - InputConfigDialog* parent = (InputConfigDialog*)btn->GetParent()->GetParent()->GetParent()->GetParent(); - if (event.GetId() == parent->pollid) return; - - if (event.Entering()) - { - btn->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNHIGHLIGHT)); - btn->SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT)); - } - else - { - btn->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)); - btn->SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT)); - } - btn->Refresh(); -} - -void InputConfigDialog::JoyMappingName(int id, char* str) -{ - if (id < 0) - { - strcpy(str, "None"); - return; - } - - if (id & 0x100) - { - switch (id & 0xF) - { - case 0x1: strcpy(str, "Up"); break; - case 0x2: strcpy(str, "Right"); break; - case 0x4: strcpy(str, "Down"); break; - case 0x8: strcpy(str, "Left"); break; - } - } - else - { - sprintf(str, "Button %d", id+1); - } -} diff --git a/src/wx/InputConfig.h b/src/wx/InputConfig.h deleted file mode 100644 index 0ca3bca..0000000 --- a/src/wx/InputConfig.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - Copyright 2016-2017 StapleButter - - This file is part of melonDS. - - melonDS is free software: you can redistribute it and/or modify it under - the terms of the GNU General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your option) - any later version. - - melonDS is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with melonDS. If not, see http://www.gnu.org/licenses/. -*/ - -#ifndef WX_INPUTCONFIG_H -#define WX_INPUTCONFIG_H - -#include <wx/wxprec.h> -#ifndef WX_PRECOMP -#include <wx/wx.h> -#endif - -#include <SDL2/SDL.h> - -class InputConfigDialog : public wxDialog -{ -public: - InputConfigDialog(wxWindow* parent); - ~InputConfigDialog(); - -private: - wxDECLARE_EVENT_TABLE(); - - void OnOk(wxCommandEvent& event); - void OnCancel(wxCommandEvent& event); - - void OnConfigureKey(wxMouseEvent& event); - void OnConfigureJoy(wxMouseEvent& event); - - void OnPoll(wxTimerEvent& event); - - void OnKeyDown(wxKeyEvent& event); - void OnFancybuttonHover(wxMouseEvent& event); - - void JoyMappingName(int id, char* str); - - int njoys; - SDL_Joystick* joy; - - wxTimer* polltimer; - int pollid; - wxStaticText* pollbtn; - wxString pollbtntext; - - int keymapping[12]; - int joymapping[12]; -}; - -#endif // WX_INPUTCONFIG_H - diff --git a/src/wx/Platform.cpp b/src/wx/Platform.cpp deleted file mode 100644 index 48c3bfa..0000000 --- a/src/wx/Platform.cpp +++ /dev/null @@ -1,262 +0,0 @@ -/* - Copyright 2016-2017 StapleButter - - This file is part of melonDS. - - melonDS is free software: you can redistribute it and/or modify it under - the terms of the GNU General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your option) - any later version. - - melonDS is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with melonDS. If not, see http://www.gnu.org/licenses/. -*/ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include "../Platform.h" -#include "../Config.h" - -#include <wx/wxprec.h> -#ifndef WX_PRECOMP -#include <wx/wx.h> -#endif - -#ifdef __WXMSW__ - #include <winsock2.h> - #include <ws2tcpip.h> - #define socket_t SOCKET - #define sockaddr_t SOCKADDR - #define pcap_dev_name description -#else - #include <unistd.h> - #include <arpa/inet.h> - #include <sys/socket.h> - #define socket_t int - #define sockaddr_t struct sockaddr - #define closesocket close - #define pcap_dev_name name -#endif - -#ifndef INVALID_SOCKET -#define INVALID_SOCKET (socket_t)-1 -#endif - - -namespace Platform -{ - - -class Thread : public wxThread -{ -public: - Thread(void (*func)()) - : wxThread(wxTHREAD_JOINABLE) - { - this->Func = func; - } - - ~Thread() {} - -protected: - virtual ExitCode Entry() - { - Func(); - return (ExitCode)0; - } - -private: - void (*Func)(); -}; - - -socket_t MPSocket; -sockaddr_t MPSendAddr; -u8 PacketBuffer[2048]; - -#define NIFI_VER 1 - - -void* Thread_Create(void (*func)()) -{ - Thread* ret = new Thread(func); - ret->Run(); - return (void*)ret; -} - -void Thread_Free(void* thread) -{ - delete (Thread*)thread; -} - -void Thread_Wait(void* thread) -{ - ((Thread*)thread)->Wait(); -} - - -void* Semaphore_Create() -{ - return (void*)new wxSemaphore(); -} - -void Semaphore_Free(void* sema) -{ - delete (wxSemaphore*)sema; -} - -void Semaphore_Reset(void* sema) -{ - while (((wxSemaphore*)sema)->TryWait() == wxSEMA_NO_ERROR); -} - -void Semaphore_Wait(void* sema) -{ - ((wxSemaphore*)sema)->Wait(); -} - -void Semaphore_Post(void* sema) -{ - ((wxSemaphore*)sema)->Post(); -} - - -bool MP_Init() -{ - int opt_true = 1; - int res; - -#ifdef __WXMSW__ - WSADATA wsadata; - if (WSAStartup(MAKEWORD(2, 2), &wsadata) != 0) - { - return false; - } -#endif // __WXMSW__ - - MPSocket = socket(AF_INET, SOCK_DGRAM, 0); - if (MPSocket < 0) - { - return false; - } - - res = setsockopt(MPSocket, SOL_SOCKET, SO_REUSEADDR, (const char*)&opt_true, sizeof(int)); - if (res < 0) - { - closesocket(MPSocket); - MPSocket = INVALID_SOCKET; - return false; - } - - sockaddr_t saddr; - saddr.sa_family = AF_INET; - *(u32*)&saddr.sa_data[2] = htonl(Config::SocketBindAnyAddr ? INADDR_ANY : INADDR_LOOPBACK); - *(u16*)&saddr.sa_data[0] = htons(7064); - res = bind(MPSocket, &saddr, sizeof(sockaddr_t)); - if (res < 0) - { - closesocket(MPSocket); - MPSocket = INVALID_SOCKET; - return false; - } - - res = setsockopt(MPSocket, SOL_SOCKET, SO_BROADCAST, (const char*)&opt_true, sizeof(int)); - if (res < 0) - { - closesocket(MPSocket); - MPSocket = INVALID_SOCKET; - return false; - } - - MPSendAddr.sa_family = AF_INET; - *(u32*)&MPSendAddr.sa_data[2] = htonl(INADDR_BROADCAST); - *(u16*)&MPSendAddr.sa_data[0] = htons(7064); - - return true; -} - -void MP_DeInit() -{ - if (MPSocket >= 0) - closesocket(MPSocket); - -#ifdef __WXMSW__ - WSACleanup(); -#endif // __WXMSW__ -} - -int MP_SendPacket(u8* data, int len) -{ - if (MPSocket < 0) - return 0; - - if (len > 2048-8) - { - printf("MP_SendPacket: error: packet too long (%d)\n", len); - return 0; - } - - *(u32*)&PacketBuffer[0] = htonl(0x4946494E); // NIFI - PacketBuffer[4] = NIFI_VER; - PacketBuffer[5] = 0; - *(u16*)&PacketBuffer[6] = htons(len); - memcpy(&PacketBuffer[8], data, len); - - int slen = sendto(MPSocket, (const char*)PacketBuffer, len+8, 0, &MPSendAddr, sizeof(sockaddr_t)); - if (slen < 8) return 0; - return slen - 8; -} - -int MP_RecvPacket(u8* data, bool block) -{ - if (MPSocket < 0) - return 0; - - fd_set fd; - struct timeval tv; - - FD_ZERO(&fd); - FD_SET(MPSocket, &fd); - tv.tv_sec = 0; - tv.tv_usec = block ? 5000 : 0; - - if (!select(MPSocket+1, &fd, 0, 0, &tv)) - { - return 0; - } - - sockaddr_t fromAddr; - socklen_t fromLen = sizeof(sockaddr_t); - int rlen = recvfrom(MPSocket, (char*)PacketBuffer, 2048, 0, &fromAddr, &fromLen); - if (rlen < 8+24) - { - return 0; - } - rlen -= 8; - - if (ntohl(*(u32*)&PacketBuffer[0]) != 0x4946494E) - { - return 0; - } - - if (PacketBuffer[4] != NIFI_VER) - { - return 0; - } - - if (ntohs(*(u16*)&PacketBuffer[6]) != rlen) - { - return 0; - } - - memcpy(data, &PacketBuffer[8], rlen); - return rlen; -} - - -} diff --git a/src/wx/main.cpp b/src/wx/main.cpp deleted file mode 100644 index 302f5da..0000000 --- a/src/wx/main.cpp +++ /dev/null @@ -1,728 +0,0 @@ -/* - Copyright 2016-2017 StapleButter - - This file is part of melonDS. - - melonDS is free software: you can redistribute it and/or modify it under - the terms of the GNU General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your option) - any later version. - - melonDS is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with melonDS. If not, see http://www.gnu.org/licenses/. -*/ - -#include "../types.h" -#include "main.h" -#include "../version.h" -#include "../Config.h" -#include "../NDS.h" -#include "../GPU.h" -#include "../GPU3D.h" -#include "../SPU.h" -#include "../Wifi.h" -#include "../Platform.h" - -#include "InputConfig.h" -#include "EmuConfig.h" - - -// blarg -#ifndef SDL_PIXELFORMAT_RGBA32 -#define SDL_PIXELFORMAT_RGBA32 SDL_PIXELFORMAT_ABGR8888 -#endif // SDL_PIXELFORMAT_RGBA32 - - -wxIMPLEMENT_APP_NO_MAIN(wxApp_melonDS); - - -int main(int argc, char** argv) -{ - srand(time(NULL)); - - // http://stackoverflow.com/questions/14543333/joystick-wont-work-using-sdl - SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1"); - - if (SDL_Init(SDL_INIT_EVERYTHING) < 0) - { - printf("SDL shat itself :(\n"); - return 1; - } - - int ret = wxEntry(argc, argv); - - SDL_Quit(); - return ret; -} - -#ifdef __WXMSW__ - -int CALLBACK WinMain(HINSTANCE hinst, HINSTANCE hprev, LPSTR cmdline, int cmdshow) -{ - char cmdargs[16][256]; - int arg = 0; - int j = 0; - bool inquote = false; - int len = strlen(cmdline); - for (int i = 0; i < len; i++) - { - char c = cmdline[i]; - if (c == '\0') break; - if (c == '"') inquote = !inquote; - if (!inquote && c==' ') - { - if (arg < 16) cmdargs[arg][j] = '\0'; - arg++; - j = 0; - } - else - { - if (arg < 16 && j < 255) cmdargs[arg][j] = c; - j++; - } - } - if (arg < 16) cmdargs[arg][j] = '\0'; - - return main(arg, (char**)cmdargs); -} - -#endif // __WXMSW__ - - -bool _fileexists(char* name) -{ - FILE* f = fopen(name, "rb"); - if (!f) return false; - fclose(f); - return true; -} - - -bool wxApp_melonDS::OnInit() -{ - printf("melonDS " MELONDS_VERSION "\n" MELONDS_URL "\n"); - - Config::Load(); - - if (!_fileexists("bios7.bin") || !_fileexists("bios9.bin") || !_fileexists("firmware.bin")) - { - wxMessageBox( - "One or more of the following required files don't exist or couldn't be accessed:\n\n" - "bios7.bin -- ARM7 BIOS\n" - "bios9.bin -- ARM9 BIOS\n" - "firmware.bin -- firmware image\n\n" - "Dump the files from your DS and place them in the directory you run melonDS from.\n" - "Make sure that the files can be accessed.", - "melonDS", - wxICON_ERROR); - - return false; - } - - emuthread = new EmuThread(); - if (emuthread->Run() != wxTHREAD_NO_ERROR) - { - printf("thread shat itself :( giving up now\n"); - delete emuthread; - return false; - } - - MainFrame* melon = new MainFrame(); - melon->Show(true); - - melon->emuthread = emuthread; - emuthread->parent = melon; - - return true; -} - -int wxApp_melonDS::OnExit() -{ - emuthread->Wait(); - delete emuthread; - - return wxApp::OnExit(); -} - - -wxBEGIN_EVENT_TABLE(MainFrame, wxFrame) - EVT_CLOSE(MainFrame::OnClose) - - EVT_MENU(ID_OPENROM, MainFrame::OnOpenROM) - EVT_MENU(ID_EXIT, MainFrame::OnCloseFromMenu) - - EVT_MENU(ID_RUN, MainFrame::OnRun) - EVT_MENU(ID_PAUSE, MainFrame::OnPause) - EVT_MENU(ID_RESET, MainFrame::OnReset) - - EVT_MENU(ID_EMUCONFIG, MainFrame::OnEmuConfig) - EVT_MENU(ID_INPUTCONFIG, MainFrame::OnInputConfig) -wxEND_EVENT_TABLE() - - -MainFrame::MainFrame() - : wxFrame(NULL, wxID_ANY, "melonDS " MELONDS_VERSION) -{ - wxMenu* filemenu = new wxMenu(); - filemenu->Append(ID_OPENROM, "Open ROM..."); - filemenu->AppendSeparator(); - filemenu->Append(ID_EXIT, "Quit"); - - wxMenu* systemmenu = new wxMenu(); - systemmenu->Append(ID_RUN, "Run"); - systemmenu->AppendCheckItem(ID_PAUSE, "Pause"); - systemmenu->AppendSeparator(); - systemmenu->Append(ID_RESET, "Reset"); - - wxMenu* settingsmenu = new wxMenu(); - settingsmenu->Append(ID_EMUCONFIG, "Emulation"); - settingsmenu->Append(ID_INPUTCONFIG, "Input"); - - wxMenuBar* melonbar = new wxMenuBar(); - melonbar->Append(filemenu, "File"); - melonbar->Append(systemmenu, "System"); - melonbar->Append(settingsmenu, "Settings"); - - SetMenuBar(melonbar); - - SetClientSize(256, 256); - SetMinSize(GetSize()); - - NDS::Init(); - rompath = wxEmptyString; - GetMenuBar()->Enable(ID_PAUSE, false); - GetMenuBar()->Enable(ID_RESET, false); - - joy = NULL; - joyid = -1; -} - -void MainFrame::OnClose(wxCloseEvent& event) -{ - emuthread->EmuPause(); - emuthread->EmuExit(); - - NDS::DeInit(); - - if (joy) - { - SDL_JoystickClose(joy); - joy = NULL; - joyid = -1; - } - - Destroy(); - emuthread->parent = NULL; - - Config::Save(); -} - -void MainFrame::OnCloseFromMenu(wxCommandEvent& event) -{ - Close(); -} - -void MainFrame::OnOpenROM(wxCommandEvent& event) -{ - wxFileDialog opener(this, _("Open ROM"), "", "", "DS ROM (*.nds)|*.nds;*.srl|Any file|*.*", wxFD_OPEN|wxFD_FILE_MUST_EXIST); - if (opener.ShowModal() == wxID_CANCEL) - return; - - emuthread->EmuPause(); - - rompath = opener.GetPath(); - NDS::LoadROM(rompath.mb_str(), Config::DirectBoot); - - emuthread->EmuRun(); - GetMenuBar()->Enable(ID_PAUSE, true); - GetMenuBar()->Check(ID_PAUSE, false); - GetMenuBar()->Enable(ID_RESET, true); - - if (!joy) - { - if (SDL_NumJoysticks() > 0) - { - joy = SDL_JoystickOpen(0); - joyid = SDL_JoystickInstanceID(joy); - } - } -} - -void MainFrame::OnRun(wxCommandEvent& event) -{ - // TODO: reduce duplicate code - - if (!emuthread->EmuIsRunning()) - { - NDS::LoadBIOS(); - } - - emuthread->EmuRun(); - GetMenuBar()->Enable(ID_PAUSE, true); - GetMenuBar()->Check(ID_PAUSE, false); - GetMenuBar()->Enable(ID_RESET, true); - - if (!joy) - { - if (SDL_NumJoysticks() > 0) - { - joy = SDL_JoystickOpen(0); - joyid = SDL_JoystickInstanceID(joy); - } - } -} - -void MainFrame::OnPause(wxCommandEvent& event) -{ - if (!emuthread->EmuIsPaused()) - { - emuthread->EmuPause(); - GetMenuBar()->Check(ID_PAUSE, true); - } - else - { - emuthread->EmuRun(); - GetMenuBar()->Check(ID_PAUSE, false); - } -} - -void MainFrame::OnReset(wxCommandEvent& event) -{ - emuthread->EmuPause(); - - if (!rompath.IsEmpty()) - NDS::LoadROM(rompath.mb_str(), Config::DirectBoot); - else - NDS::LoadBIOS(); - - emuthread->EmuRun(); - GetMenuBar()->Enable(ID_PAUSE, true); - GetMenuBar()->Check(ID_PAUSE, false); - GetMenuBar()->Enable(ID_RESET, true); - - if (!joy) - { - if (SDL_NumJoysticks() > 0) - { - joy = SDL_JoystickOpen(0); - joyid = SDL_JoystickInstanceID(joy); - } - } -} - -void MainFrame::OnEmuConfig(wxCommandEvent& event) -{ - bool oldpause = emuthread->EmuIsPaused(); - if (!oldpause && emuthread->EmuIsRunning()) - emuthread->EmuPause(); - - EmuConfigDialog dlg(this); - dlg.ShowModal(); - - if (emuthread->EmuIsRunning()) - { - // apply threaded 3D setting - GPU3D::SoftRenderer::SetupRenderThread(); - - if (Wifi::MPInited) - { - Platform::MP_DeInit(); - Platform::MP_Init(); - } - } - - if (!oldpause && emuthread->EmuIsRunning()) - emuthread->EmuRun(); -} - -void MainFrame::OnInputConfig(wxCommandEvent& event) -{ - if (joy) - { - SDL_JoystickClose(joy); - joy = NULL; - joyid = -1; - } - - InputConfigDialog dlg(this); - dlg.ShowModal(); - - if (SDL_NumJoysticks() > 0) - { - joy = SDL_JoystickOpen(0); - joyid = SDL_JoystickInstanceID(joy); - } -} - - -EmuThread::EmuThread() - : wxThread(wxTHREAD_JOINABLE) -{ -} - -EmuThread::~EmuThread() -{ -} - -static void AudioCallback(void* data, Uint8* stream, int len) -{ - SPU::ReadOutput((s16*)stream, len>>2); -} - -wxThread::ExitCode EmuThread::Entry() -{ - emustatus = 3; - emupaused = false; - - limitfps = true; - - sdlwin = SDL_CreateWindow("melonDS " MELONDS_VERSION, - SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, - Config::WindowWidth, Config::WindowHeight, - SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI); - - SDL_SetWindowMinimumSize(sdlwin, 256, 384); - - sdlrend = SDL_CreateRenderer(sdlwin, -1, SDL_RENDERER_ACCELERATED);// | SDL_RENDERER_PRESENTVSYNC); - sdltex = SDL_CreateTexture(sdlrend, SDL_PIXELFORMAT_RGBA32, SDL_TEXTUREACCESS_STREAMING, 256, 384); - - SDL_SetRenderDrawColor(sdlrend, 0, 0, 0, 255); - - SDL_LockTexture(sdltex, NULL, &texpixels, &texstride); - memset(texpixels, 0, texstride*384); - SDL_UnlockTexture(sdltex); - - topsrc.x = 0; topsrc.y = 0; - topsrc.w = 256; topsrc.h = 192; - botsrc.x = 0; botsrc.y = 192; - botsrc.w = 256; botsrc.h = 192; - - topdst.x = 0; topdst.y = 0; - topdst.w = 256; topdst.h = 192; - botdst.x = 0; botdst.y = 192; - botdst.w = 256; botdst.h = 192; - - SDL_AudioSpec whatIwant, whatIget; - memset(&whatIwant, 0, sizeof(SDL_AudioSpec)); - whatIwant.freq = 32824; // 32823.6328125 - whatIwant.format = AUDIO_S16LSB; - whatIwant.channels = 2; - whatIwant.samples = 1024; - whatIwant.callback = AudioCallback; - audio = SDL_OpenAudioDevice(NULL, 0, &whatIwant, &whatIget, 0); - if (!audio) - { - printf("Audio init failed: %s\n", SDL_GetError()); - } - else - { - SDL_PauseAudioDevice(audio, 0); - } - - Touching = false; - axismask = 0; - - u32 nframes = 0; - u32 starttick = SDL_GetTicks(); - u32 lasttick = starttick; - u32 lastmeasuretick = lasttick; - u32 fpslimitcount = 0; - - for (;;) - { - if (emustatus == 0) break; - - ProcessEvents(); - - if (emustatus == 0) break; - - if (emustatus == 1) - { - u32 nlines = NDS::RunFrame(); - - SDL_LockTexture(sdltex, NULL, &texpixels, &texstride); - if (texstride == 256*4) - { - memcpy(texpixels, GPU::Framebuffer, 256*384*4); - } - else - { - int dsty = 0; - for (int y = 0; y < 256*384; y+=256) - { - memcpy(&((u8*)texpixels)[dsty], &GPU::Framebuffer[y], 256*4); - dsty += texstride; - } - } - SDL_UnlockTexture(sdltex); - - SDL_RenderClear(sdlrend); - SDL_RenderCopy(sdlrend, sdltex, &topsrc, &topdst); - SDL_RenderCopy(sdlrend, sdltex, &botsrc, &botdst); - SDL_RenderPresent(sdlrend); - - // framerate limiter based off SDL2_gfx - float framerate; - if (nlines == 263) framerate = 1000.0f / 60.0f; - else framerate = ((1000.0f * nlines) / 263.0f) / 60.0f; - - fpslimitcount++; - u32 curtick = SDL_GetTicks(); - u32 delay = curtick - lasttick; - lasttick = curtick; - - u32 wantedtick = starttick + (u32)((float)fpslimitcount * framerate); - if (curtick < wantedtick && limitfps) - { - Sleep(wantedtick - curtick); - } - else - { - fpslimitcount = 0; - starttick = curtick; - } - - nframes++; - if (nframes >= 30) - { - u32 tick = SDL_GetTicks(); - u32 diff = tick - lastmeasuretick; - lastmeasuretick = tick; - - u32 fps = (nframes * 1000) / diff; - nframes = 0; - - float fpstarget; - if (framerate < 1) fpstarget = 999; - else fpstarget = 1000.0f/framerate; - - char melontitle[100]; - sprintf(melontitle, "%d/%.0f FPS | melonDS " MELONDS_VERSION, fps, fpstarget); - SDL_SetWindowTitle(sdlwin, melontitle); - } - } - else - { - nframes = 0; - lasttick = SDL_GetTicks(); - starttick = lasttick; - lastmeasuretick = lasttick; - fpslimitcount = 0; - - Sleep(50); - - SDL_RenderCopy(sdlrend, sdltex, NULL, NULL); - SDL_RenderPresent(sdlrend); - - if (emustatus == 2) - { - char* melontitle = "Paused - melonDS " MELONDS_VERSION; - SDL_SetWindowTitle(sdlwin, melontitle); - } - - emupaused = true; - } - } - - emupaused = true; - - if (audio) SDL_CloseAudioDevice(audio); - - SDL_DestroyTexture(sdltex); - SDL_DestroyRenderer(sdlrend); - SDL_DestroyWindow(sdlwin); - - return (wxThread::ExitCode)0; -} - -void EmuThread::ProcessEvents() -{ - bool running = (emustatus == 1); - SDL_Event evt; - - while (SDL_PollEvent(&evt)) - { - switch (evt.type) - { - case SDL_WINDOWEVENT: - if (evt.window.event == SDL_WINDOWEVENT_CLOSE) - { - if (parent) parent->Close(); - EmuExit(); - return; - } - if (evt.window.event != SDL_WINDOWEVENT_EXPOSED) - { - if (evt.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) - { - int w = evt.window.data1; - int h = evt.window.data2; - - // SDL_SetWindowMinimumSize() doesn't seem to work on Linux. oh well - if ((w < 256) || (h < 384)) - { - if (w < 256) w = 256; - if (h < 384) h = 384; - SDL_SetWindowSize(sdlwin, w, h); - } - - int ratio = (w * 384) / h; - if (ratio > 256) - { - // borders on the sides - - int screenw = (4 * (h/2)) / 3; - int gap = (w - screenw) / 2; - - topdst.x = gap; topdst.y = 0; - topdst.w = screenw; topdst.h = h/2; - - botdst.x = gap; botdst.y = h/2; - botdst.w = screenw; botdst.h = h/2; - } - else - { - // separator - - int screenh = (3 * w) / 4; - int gap = h - (screenh*2); - - topdst.x = 0; topdst.y = 0; - topdst.w = w; topdst.h = screenh; - - botdst.x = 0; botdst.y = screenh + gap; - botdst.w = w; botdst.h = screenh; - } - - Config::WindowWidth = w; - Config::WindowHeight = h; - } - } - break; - - case SDL_MOUSEBUTTONDOWN: - if (!running) return; - if (evt.button.button == SDL_BUTTON_LEFT) - { - if (evt.button.x >= botdst.x && evt.button.x < (botdst.x+botdst.w) && - evt.button.y >= botdst.y && evt.button.y < (botdst.y+botdst.h)) - { - Touching = true; - NDS::PressKey(16+6); - - int mx, my; - SDL_GetGlobalMouseState(&mx, &my); - txoffset = mx - evt.button.x; - tyoffset = my - evt.button.y; - } - } - break; - - case SDL_KEYDOWN: - if (!running) return; - for (int i = 0; i < 10; i++) - if (evt.key.keysym.scancode == Config::KeyMapping[i]) NDS::PressKey(i); - if (evt.key.keysym.scancode == Config::KeyMapping[10]) NDS::PressKey(16); - if (evt.key.keysym.scancode == Config::KeyMapping[11]) NDS::PressKey(17); - if (evt.key.keysym.scancode == SDL_SCANCODE_F12) NDS::debug(0); - if (evt.key.keysym.scancode == SDL_SCANCODE_TAB) limitfps = !limitfps; - break; - - case SDL_KEYUP: - if (!running) return; - for (int i = 0; i < 10; i++) - if (evt.key.keysym.scancode == Config::KeyMapping[i]) NDS::ReleaseKey(i); - if (evt.key.keysym.scancode == Config::KeyMapping[10]) NDS::ReleaseKey(16); - if (evt.key.keysym.scancode == Config::KeyMapping[11]) NDS::ReleaseKey(17); - //if (evt.key.keysym.scancode == SDL_SCANCODE_TAB) limitfps = true; - break; - - case SDL_JOYBUTTONDOWN: - if (!running) return; - if (evt.jbutton.which != parent->joyid) return; - for (int i = 0; i < 10; i++) - if (evt.jbutton.button == Config::JoyMapping[i]) NDS::PressKey(i); - if (evt.jbutton.button == Config::JoyMapping[10]) NDS::PressKey(16); - if (evt.jbutton.button == Config::JoyMapping[11]) NDS::PressKey(17); - break; - - case SDL_JOYBUTTONUP: - if (!running) return; - if (evt.jbutton.which != parent->joyid) return; - for (int i = 0; i < 10; i++) - if (evt.jbutton.button == Config::JoyMapping[i]) NDS::ReleaseKey(i); - if (evt.jbutton.button == Config::JoyMapping[10]) NDS::ReleaseKey(16); - if (evt.jbutton.button == Config::JoyMapping[11]) NDS::ReleaseKey(17); - break; - - case SDL_JOYHATMOTION: - if (!running) return; - if (evt.jhat.which != parent->joyid) return; - if (evt.jhat.hat != 0) return; - for (int i = 0; i < 12; i++) - { - int j = (i >= 10) ? (i+6) : i; - if (Config::JoyMapping[i] == 0x101) - (evt.jhat.value & SDL_HAT_UP) ? NDS::PressKey(j) : NDS::ReleaseKey(j); - else if (Config::JoyMapping[i] == 0x102) - (evt.jhat.value & SDL_HAT_RIGHT) ? NDS::PressKey(j) : NDS::ReleaseKey(j); - else if (Config::JoyMapping[i] == 0x104) - (evt.jhat.value & SDL_HAT_DOWN) ? NDS::PressKey(j) : NDS::ReleaseKey(j); - else if (Config::JoyMapping[i] == 0x108) - (evt.jhat.value & SDL_HAT_LEFT) ? NDS::PressKey(j) : NDS::ReleaseKey(j); - } - break; - - case SDL_JOYAXISMOTION: - if (!running) return; - if (evt.jaxis.which != parent->joyid) return; - if (evt.jaxis.axis == 0) - { - if (evt.jaxis.value >= 16384) { NDS::PressKey(4); axismask |= 0x1; } - else if (axismask & 0x1) { NDS::ReleaseKey(4); axismask &= ~0x1; } - if (evt.jaxis.value <= -16384) { NDS::PressKey(5); axismask |= 0x2; } - else if (axismask & 0x2) { NDS::ReleaseKey(5); axismask &= ~0x2; } - } - else if (evt.jaxis.axis == 1) - { - if (evt.jaxis.value >= 16384) { NDS::PressKey(7); axismask |= 0x4; } - else if (axismask & 0x4) { NDS::ReleaseKey(7); axismask &= ~0x4; } - if (evt.jaxis.value <= -16384) { NDS::PressKey(6); axismask |= 0x8; } - else if (axismask & 0x8) { NDS::ReleaseKey(6); axismask &= ~0x8; } - } - break; - } - } - - if (Touching && running) - { - int mx, my; - u32 btn = SDL_GetGlobalMouseState(&mx, &my); - if (!(btn & SDL_BUTTON(SDL_BUTTON_LEFT))) - { - Touching = false; - NDS::ReleaseKey(16+6); - NDS::ReleaseScreen(); - } - else - { - mx -= (txoffset + botdst.x); - my -= (tyoffset + botdst.y); - - if (botdst.w != 256) mx = (mx * 256) / botdst.w; - if (botdst.h != 192) my = (my * 192) / botdst.h; - - if (mx < 0) mx = 0; - else if (mx > 255) mx = 255; - - if (my < 0) my = 0; - else if (my > 191) my = 191; - - NDS::TouchScreen(mx, my); - } - } -} diff --git a/src/wx/main.h b/src/wx/main.h deleted file mode 100644 index 34ac43f..0000000 --- a/src/wx/main.h +++ /dev/null @@ -1,123 +0,0 @@ -/* - Copyright 2016-2017 StapleButter - - This file is part of melonDS. - - melonDS is free software: you can redistribute it and/or modify it under - the terms of the GNU General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your option) - any later version. - - melonDS is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with melonDS. If not, see http://www.gnu.org/licenses/. -*/ - -#ifndef WX_MAIN_H -#define WX_MAIN_H - -#include <wx/wxprec.h> -#ifndef WX_PRECOMP -#include <wx/wx.h> -#endif - -#include <SDL2/SDL.h> - -enum -{ - ID_OPENROM = 1, - ID_EXIT, - - ID_RUN, - ID_PAUSE, - ID_RESET, - - ID_EMUCONFIG, - ID_INPUTCONFIG, -}; - -class EmuThread; - -class wxApp_melonDS : public wxApp -{ -public: - virtual bool OnInit(); - virtual int OnExit(); - - EmuThread* emuthread; -}; - -class MainFrame : public wxFrame -{ -public: - MainFrame(); - - SDL_Joystick* joy; - SDL_JoystickID joyid; - - EmuThread* emuthread; - - wxString rompath; - -private: - wxDECLARE_EVENT_TABLE(); - - void OnClose(wxCloseEvent& event); - void OnCloseFromMenu(wxCommandEvent& event); - void OnOpenROM(wxCommandEvent& event); - - void OnRun(wxCommandEvent& event); - void OnPause(wxCommandEvent& event); - void OnReset(wxCommandEvent& event); - - void OnEmuConfig(wxCommandEvent& event); - void OnInputConfig(wxCommandEvent& event); - - void ProcessSDLEvents(); -}; - -class EmuThread : public wxThread -{ -public: - EmuThread(); - ~EmuThread(); - - void EmuRun() { emustatus = 1; emupaused = false; SDL_RaiseWindow(sdlwin); } - void EmuPause() { emustatus = 2; while (!emupaused); } - void EmuExit() { emustatus = 0; } - - bool EmuIsRunning() { return (emustatus == 1) || (emustatus == 2); } - bool EmuIsPaused() { return (emustatus == 2) && emupaused; } - - MainFrame* parent; - -protected: - virtual ExitCode Entry(); - void ProcessEvents(); - - SDL_Window* sdlwin; - SDL_Renderer* sdlrend; - SDL_Texture* sdltex; - - SDL_Rect topsrc, topdst; - SDL_Rect botsrc, botdst; - - SDL_AudioDeviceID audio; - - bool Touching; - int txoffset, tyoffset; - - void* texpixels; - int texstride; - - u32 axismask; - - int emustatus; - volatile bool emupaused; - bool limitfps; -}; - -#endif // WX_MAIN_H diff --git a/src/wx/scancode_wx2sdl.h b/src/wx/scancode_wx2sdl.h deleted file mode 100644 index a1030ee..0000000 --- a/src/wx/scancode_wx2sdl.h +++ /dev/null @@ -1,336 +0,0 @@ -/* - Copyright 2016-2017 StapleButter - - This file is part of melonDS. - - melonDS is free software: you can redistribute it and/or modify it under - the terms of the GNU General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your option) - any later version. - - melonDS is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with melonDS. If not, see http://www.gnu.org/licenses/. -*/ - - -// conversion from wxWdgets-provided platform-specific keycodes to SDL scancodes -// much of this is taken from the SDL source code - - -#ifdef __WXMSW__ -static const SDL_Scancode windows_scancode_table[] = -{ - /* 0 1 2 3 4 5 6 7 */ - /* 8 9 A B C D E F */ - SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_ESCAPE, SDL_SCANCODE_1, SDL_SCANCODE_2, SDL_SCANCODE_3, SDL_SCANCODE_4, SDL_SCANCODE_5, SDL_SCANCODE_6, /* 0 */ - SDL_SCANCODE_7, SDL_SCANCODE_8, SDL_SCANCODE_9, SDL_SCANCODE_0, SDL_SCANCODE_MINUS, SDL_SCANCODE_EQUALS, SDL_SCANCODE_BACKSPACE, SDL_SCANCODE_TAB, /* 0 */ - - SDL_SCANCODE_Q, SDL_SCANCODE_W, SDL_SCANCODE_E, SDL_SCANCODE_R, SDL_SCANCODE_T, SDL_SCANCODE_Y, SDL_SCANCODE_U, SDL_SCANCODE_I, /* 1 */ - SDL_SCANCODE_O, SDL_SCANCODE_P, SDL_SCANCODE_LEFTBRACKET, SDL_SCANCODE_RIGHTBRACKET, SDL_SCANCODE_RETURN, SDL_SCANCODE_LCTRL, SDL_SCANCODE_A, SDL_SCANCODE_S, /* 1 */ - - SDL_SCANCODE_D, SDL_SCANCODE_F, SDL_SCANCODE_G, SDL_SCANCODE_H, SDL_SCANCODE_J, SDL_SCANCODE_K, SDL_SCANCODE_L, SDL_SCANCODE_SEMICOLON, /* 2 */ - SDL_SCANCODE_APOSTROPHE, SDL_SCANCODE_GRAVE, SDL_SCANCODE_LSHIFT, SDL_SCANCODE_BACKSLASH, SDL_SCANCODE_Z, SDL_SCANCODE_X, SDL_SCANCODE_C, SDL_SCANCODE_V, /* 2 */ - - SDL_SCANCODE_B, SDL_SCANCODE_N, SDL_SCANCODE_M, SDL_SCANCODE_COMMA, SDL_SCANCODE_PERIOD, SDL_SCANCODE_SLASH, SDL_SCANCODE_RSHIFT, SDL_SCANCODE_PRINTSCREEN,/* 3 */ - SDL_SCANCODE_LALT, SDL_SCANCODE_SPACE, SDL_SCANCODE_CAPSLOCK, SDL_SCANCODE_F1, SDL_SCANCODE_F2, SDL_SCANCODE_F3, SDL_SCANCODE_F4, SDL_SCANCODE_F5, /* 3 */ - - SDL_SCANCODE_F6, SDL_SCANCODE_F7, SDL_SCANCODE_F8, SDL_SCANCODE_F9, SDL_SCANCODE_F10, SDL_SCANCODE_NUMLOCKCLEAR, SDL_SCANCODE_SCROLLLOCK, SDL_SCANCODE_HOME, /* 4 */ - SDL_SCANCODE_UP, SDL_SCANCODE_PAGEUP, SDL_SCANCODE_KP_MINUS, SDL_SCANCODE_LEFT, SDL_SCANCODE_KP_5, SDL_SCANCODE_RIGHT, SDL_SCANCODE_KP_PLUS, SDL_SCANCODE_END, /* 4 */ - - SDL_SCANCODE_DOWN, SDL_SCANCODE_PAGEDOWN, SDL_SCANCODE_INSERT, SDL_SCANCODE_DELETE, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_NONUSBACKSLASH,SDL_SCANCODE_F11, /* 5 */ - SDL_SCANCODE_F12, SDL_SCANCODE_PAUSE, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_LGUI, SDL_SCANCODE_RGUI, SDL_SCANCODE_APPLICATION, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, /* 5 */ - - SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_F13, SDL_SCANCODE_F14, SDL_SCANCODE_F15, SDL_SCANCODE_F16, /* 6 */ - SDL_SCANCODE_F17, SDL_SCANCODE_F18, SDL_SCANCODE_F19, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, /* 6 */ - - SDL_SCANCODE_INTERNATIONAL2, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_INTERNATIONAL1, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, /* 7 */ - SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_INTERNATIONAL4, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_INTERNATIONAL5, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_INTERNATIONAL3, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN /* 7 */ -}; -#endif -#ifdef __WXGTK__ -#include <gdk/gdkkeysyms.h> -static const struct { - int keysym; - SDL_Scancode scancode; -} KeySymToSDLScancode[] = { - { GDK_Return, SDL_SCANCODE_RETURN }, - { GDK_Escape, SDL_SCANCODE_ESCAPE }, - { GDK_BackSpace, SDL_SCANCODE_BACKSPACE }, - { GDK_Tab, SDL_SCANCODE_TAB }, - { GDK_Caps_Lock, SDL_SCANCODE_CAPSLOCK }, - { GDK_F1, SDL_SCANCODE_F1 }, - { GDK_F2, SDL_SCANCODE_F2 }, - { GDK_F3, SDL_SCANCODE_F3 }, - { GDK_F4, SDL_SCANCODE_F4 }, - { GDK_F5, SDL_SCANCODE_F5 }, - { GDK_F6, SDL_SCANCODE_F6 }, - { GDK_F7, SDL_SCANCODE_F7 }, - { GDK_F8, SDL_SCANCODE_F8 }, - { GDK_F9, SDL_SCANCODE_F9 }, - { GDK_F10, SDL_SCANCODE_F10 }, - { GDK_F11, SDL_SCANCODE_F11 }, - { GDK_F12, SDL_SCANCODE_F12 }, - { GDK_Print, SDL_SCANCODE_PRINTSCREEN }, - { GDK_Scroll_Lock, SDL_SCANCODE_SCROLLLOCK }, - { GDK_Pause, SDL_SCANCODE_PAUSE }, - { GDK_Insert, SDL_SCANCODE_INSERT }, - { GDK_Home, SDL_SCANCODE_HOME }, - { GDK_Prior, SDL_SCANCODE_PAGEUP }, - { GDK_Delete, SDL_SCANCODE_DELETE }, - { GDK_End, SDL_SCANCODE_END }, - { GDK_Next, SDL_SCANCODE_PAGEDOWN }, - { GDK_Right, SDL_SCANCODE_RIGHT }, - { GDK_Left, SDL_SCANCODE_LEFT }, - { GDK_Down, SDL_SCANCODE_DOWN }, - { GDK_Up, SDL_SCANCODE_UP }, - { GDK_Num_Lock, SDL_SCANCODE_NUMLOCKCLEAR }, - { GDK_KP_Divide, SDL_SCANCODE_KP_DIVIDE }, - { GDK_KP_Multiply, SDL_SCANCODE_KP_MULTIPLY }, - { GDK_KP_Subtract, SDL_SCANCODE_KP_MINUS }, - { GDK_KP_Add, SDL_SCANCODE_KP_PLUS }, - { GDK_KP_Enter, SDL_SCANCODE_KP_ENTER }, - { GDK_KP_Delete, SDL_SCANCODE_KP_PERIOD }, - { GDK_KP_End, SDL_SCANCODE_KP_1 }, - { GDK_KP_Down, SDL_SCANCODE_KP_2 }, - { GDK_KP_Next, SDL_SCANCODE_KP_3 }, - { GDK_KP_Left, SDL_SCANCODE_KP_4 }, - { GDK_KP_Begin, SDL_SCANCODE_KP_5 }, - { GDK_KP_Right, SDL_SCANCODE_KP_6 }, - { GDK_KP_Home, SDL_SCANCODE_KP_7 }, - { GDK_KP_Up, SDL_SCANCODE_KP_8 }, - { GDK_KP_Prior, SDL_SCANCODE_KP_9 }, - { GDK_KP_Insert, SDL_SCANCODE_KP_0 }, - { GDK_KP_Decimal, SDL_SCANCODE_KP_PERIOD }, - { GDK_KP_1, SDL_SCANCODE_KP_1 }, - { GDK_KP_2, SDL_SCANCODE_KP_2 }, - { GDK_KP_3, SDL_SCANCODE_KP_3 }, - { GDK_KP_4, SDL_SCANCODE_KP_4 }, - { GDK_KP_5, SDL_SCANCODE_KP_5 }, - { GDK_KP_6, SDL_SCANCODE_KP_6 }, - { GDK_KP_7, SDL_SCANCODE_KP_7 }, - { GDK_KP_8, SDL_SCANCODE_KP_8 }, - { GDK_KP_9, SDL_SCANCODE_KP_9 }, - { GDK_KP_0, SDL_SCANCODE_KP_0 }, - { GDK_KP_Decimal, SDL_SCANCODE_KP_PERIOD }, - { GDK_Hyper_R, SDL_SCANCODE_APPLICATION }, - { GDK_KP_Equal, SDL_SCANCODE_KP_EQUALS }, - { GDK_F13, SDL_SCANCODE_F13 }, - { GDK_F14, SDL_SCANCODE_F14 }, - { GDK_F15, SDL_SCANCODE_F15 }, - { GDK_F16, SDL_SCANCODE_F16 }, - { GDK_F17, SDL_SCANCODE_F17 }, - { GDK_F18, SDL_SCANCODE_F18 }, - { GDK_F19, SDL_SCANCODE_F19 }, - { GDK_F20, SDL_SCANCODE_F20 }, - { GDK_F21, SDL_SCANCODE_F21 }, - { GDK_F22, SDL_SCANCODE_F22 }, - { GDK_F23, SDL_SCANCODE_F23 }, - { GDK_F24, SDL_SCANCODE_F24 }, - { GDK_Execute, SDL_SCANCODE_EXECUTE }, - { GDK_Help, SDL_SCANCODE_HELP }, - { GDK_Menu, SDL_SCANCODE_MENU }, - { GDK_Select, SDL_SCANCODE_SELECT }, - { GDK_Cancel, SDL_SCANCODE_STOP }, - { GDK_Redo, SDL_SCANCODE_AGAIN }, - { GDK_Undo, SDL_SCANCODE_UNDO }, - { GDK_Find, SDL_SCANCODE_FIND }, - { GDK_KP_Separator, SDL_SCANCODE_KP_COMMA }, - { GDK_Sys_Req, SDL_SCANCODE_SYSREQ }, - { GDK_Control_L, SDL_SCANCODE_LCTRL }, - { GDK_Shift_L, SDL_SCANCODE_LSHIFT }, - { GDK_Alt_L, SDL_SCANCODE_LALT }, - { GDK_Meta_L, SDL_SCANCODE_LGUI }, - { GDK_Super_L, SDL_SCANCODE_LGUI }, - { GDK_Control_R, SDL_SCANCODE_RCTRL }, - { GDK_Shift_R, SDL_SCANCODE_RSHIFT }, - { GDK_Alt_R, SDL_SCANCODE_RALT }, - { GDK_ISO_Level3_Shift, SDL_SCANCODE_RALT }, - { GDK_Meta_R, SDL_SCANCODE_RGUI }, - { GDK_Super_R, SDL_SCANCODE_RGUI }, - { GDK_Mode_switch, SDL_SCANCODE_MODE }, - { GDK_period, SDL_SCANCODE_PERIOD }, - { GDK_comma, SDL_SCANCODE_COMMA }, - { GDK_slash, SDL_SCANCODE_SLASH }, - { GDK_backslash, SDL_SCANCODE_BACKSLASH }, - { GDK_minus, SDL_SCANCODE_MINUS }, - { GDK_equal, SDL_SCANCODE_EQUALS }, - { GDK_space, SDL_SCANCODE_SPACE }, - { GDK_grave, SDL_SCANCODE_GRAVE }, - { GDK_apostrophe, SDL_SCANCODE_APOSTROPHE }, - { GDK_bracketleft, SDL_SCANCODE_LEFTBRACKET }, - { GDK_bracketright, SDL_SCANCODE_RIGHTBRACKET }, -}; -#endif - - -SDL_Scancode scancode_wx2sdl(wxKeyEvent& event) -{ -#ifdef __WXMSW__ - - u32 wParam = event.GetRawKeyCode(); - u32 lParam = event.GetRawKeyFlags(); - - SDL_Scancode code; - char bIsExtended; - int nScanCode = (lParam >> 16) & 0xFF; - - /* 0x45 here to work around both pause and numlock sharing the same scancode, so use the VK key to tell them apart */ - if (nScanCode == 0 || nScanCode == 0x45) - { - switch(wParam) - { - case VK_CLEAR: return SDL_SCANCODE_CLEAR; - case VK_MODECHANGE: return SDL_SCANCODE_MODE; - case VK_SELECT: return SDL_SCANCODE_SELECT; - case VK_EXECUTE: return SDL_SCANCODE_EXECUTE; - case VK_HELP: return SDL_SCANCODE_HELP; - case VK_PAUSE: return SDL_SCANCODE_PAUSE; - case VK_NUMLOCK: return SDL_SCANCODE_NUMLOCKCLEAR; - - case VK_F13: return SDL_SCANCODE_F13; - case VK_F14: return SDL_SCANCODE_F14; - case VK_F15: return SDL_SCANCODE_F15; - case VK_F16: return SDL_SCANCODE_F16; - case VK_F17: return SDL_SCANCODE_F17; - case VK_F18: return SDL_SCANCODE_F18; - case VK_F19: return SDL_SCANCODE_F19; - case VK_F20: return SDL_SCANCODE_F20; - case VK_F21: return SDL_SCANCODE_F21; - case VK_F22: return SDL_SCANCODE_F22; - case VK_F23: return SDL_SCANCODE_F23; - case VK_F24: return SDL_SCANCODE_F24; - - case VK_OEM_NEC_EQUAL: return SDL_SCANCODE_KP_EQUALS; - case VK_BROWSER_BACK: return SDL_SCANCODE_AC_BACK; - case VK_BROWSER_FORWARD: return SDL_SCANCODE_AC_FORWARD; - case VK_BROWSER_REFRESH: return SDL_SCANCODE_AC_REFRESH; - case VK_BROWSER_STOP: return SDL_SCANCODE_AC_STOP; - case VK_BROWSER_SEARCH: return SDL_SCANCODE_AC_SEARCH; - case VK_BROWSER_FAVORITES: return SDL_SCANCODE_AC_BOOKMARKS; - case VK_BROWSER_HOME: return SDL_SCANCODE_AC_HOME; - case VK_VOLUME_MUTE: return SDL_SCANCODE_AUDIOMUTE; - case VK_VOLUME_DOWN: return SDL_SCANCODE_VOLUMEDOWN; - case VK_VOLUME_UP: return SDL_SCANCODE_VOLUMEUP; - - case VK_MEDIA_NEXT_TRACK: return SDL_SCANCODE_AUDIONEXT; - case VK_MEDIA_PREV_TRACK: return SDL_SCANCODE_AUDIOPREV; - case VK_MEDIA_STOP: return SDL_SCANCODE_AUDIOSTOP; - case VK_MEDIA_PLAY_PAUSE: return SDL_SCANCODE_AUDIOPLAY; - case VK_LAUNCH_MAIL: return SDL_SCANCODE_MAIL; - case VK_LAUNCH_MEDIA_SELECT: return SDL_SCANCODE_MEDIASELECT; - - case VK_OEM_102: return SDL_SCANCODE_NONUSBACKSLASH; - - case VK_ATTN: return SDL_SCANCODE_SYSREQ; - case VK_CRSEL: return SDL_SCANCODE_CRSEL; - case VK_EXSEL: return SDL_SCANCODE_EXSEL; - case VK_OEM_CLEAR: return SDL_SCANCODE_CLEAR; - - case VK_LAUNCH_APP1: return SDL_SCANCODE_APP1; - case VK_LAUNCH_APP2: return SDL_SCANCODE_APP2; - - default: return SDL_SCANCODE_UNKNOWN; - } - } - - if (nScanCode > 127) - return SDL_SCANCODE_UNKNOWN; - - code = windows_scancode_table[nScanCode]; - - bIsExtended = (lParam & (1 << 24)) != 0; - if (!bIsExtended) - { - switch (code) - { - case SDL_SCANCODE_HOME: - return SDL_SCANCODE_KP_7; - case SDL_SCANCODE_UP: - return SDL_SCANCODE_KP_8; - case SDL_SCANCODE_PAGEUP: - return SDL_SCANCODE_KP_9; - case SDL_SCANCODE_LEFT: - return SDL_SCANCODE_KP_4; - case SDL_SCANCODE_RIGHT: - return SDL_SCANCODE_KP_6; - case SDL_SCANCODE_END: - return SDL_SCANCODE_KP_1; - case SDL_SCANCODE_DOWN: - return SDL_SCANCODE_KP_2; - case SDL_SCANCODE_PAGEDOWN: - return SDL_SCANCODE_KP_3; - case SDL_SCANCODE_INSERT: - return SDL_SCANCODE_KP_0; - case SDL_SCANCODE_DELETE: - return SDL_SCANCODE_KP_PERIOD; - case SDL_SCANCODE_PRINTSCREEN: - return SDL_SCANCODE_KP_MULTIPLY; - default: - break; - } - } - else - { - switch (code) - { - case SDL_SCANCODE_RETURN: - return SDL_SCANCODE_KP_ENTER; - case SDL_SCANCODE_LALT: - return SDL_SCANCODE_RALT; - case SDL_SCANCODE_LCTRL: - return SDL_SCANCODE_RCTRL; - case SDL_SCANCODE_SLASH: - return SDL_SCANCODE_KP_DIVIDE; - case SDL_SCANCODE_CAPSLOCK: - return SDL_SCANCODE_KP_PLUS; - default: - break; - } - } - - return code; - -#endif -#ifdef __WXGTK__ - - int keysym = event.GetRawKeyCode(); - - if (keysym == 0) - { - return SDL_SCANCODE_UNKNOWN; - } - - if (keysym >= GDK_a && keysym <= GDK_z) - { - return (SDL_Scancode)(SDL_SCANCODE_A + (keysym - GDK_a)); - } - if (keysym >= GDK_A && keysym <= GDK_Z) - { - return (SDL_Scancode)(SDL_SCANCODE_A + (keysym - GDK_A)); - } - - if (keysym == GDK_0) - { - return SDL_SCANCODE_0; - } - if (keysym >= GDK_1 && keysym <= GDK_9) - { - return (SDL_Scancode)(SDL_SCANCODE_1 + (keysym - GDK_1)); - } - - for (int i = 0; i < SDL_arraysize(KeySymToSDLScancode); ++i) - { - if (keysym == KeySymToSDLScancode[i].keysym) - { - return KeySymToSDLScancode[i].scancode; - } - } - return SDL_SCANCODE_UNKNOWN; - -#endif - return SDL_SCANCODE_UNKNOWN; -} |