mc.mitm: check in missing switch analog stick source files

This commit is contained in:
ndeadly 2021-06-20 23:51:37 +02:00
parent 34698dbd53
commit c6866db302
2 changed files with 90 additions and 0 deletions

View file

@ -0,0 +1,54 @@
/*
* Copyright (c) 2020-2021 ndeadly
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "switch_analog_stick.hpp"
namespace ams::controller {
void SwitchAnalogStick::SetData(uint16_t x, uint16_t y) {
m_xy[0] = x & 0xff;
m_xy[1] = (x >> 8) | ((y & 0xff) << 4);
m_xy[2] = (y >> 4) & 0xff;
}
void SwitchAnalogStick::SetX(uint16_t x) {
m_xy[0] = x & 0xff;
m_xy[1] |= x >> 8;
}
void SwitchAnalogStick::SetY(uint16_t y) {
m_xy[1] |= (y & 0xff) << 4;
m_xy[2] = (y >> 4) & 0xff;
}
uint16_t SwitchAnalogStick::GetX(void) {
return m_xy[0] | ((m_xy[1] & 0xf) << 8);
}
uint16_t SwitchAnalogStick::GetY(void) {
return (m_xy[1] >> 4) | (m_xy[2] << 4);
}
void SwitchAnalogStick::InvertX(void) {
m_xy[0] ^= 0xff;
m_xy[1] ^= 0x0f;
}
void SwitchAnalogStick::InvertY(void) {
m_xy[1] ^= 0xf0;
m_xy[2] ^= 0xff;
}
}

View file

@ -0,0 +1,36 @@
/*
* Copyright (c) 2020-2021 ndeadly
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <switch.h>
namespace ams::controller {
constexpr auto UINT12_MAX = 0xfff;
constexpr auto STICK_ZERO = 0x800;
struct SwitchAnalogStick {
void SetData(uint16_t x, uint16_t y);
void SetX(uint16_t x);
void SetY(uint16_t y);
uint16_t GetX(void);
uint16_t GetY(void);
void InvertX(void);
void InvertY(void);
uint8_t m_xy[3];
};
}