Mesen/Core/OekaKidsTablet.h

78 lines
1.8 KiB
C
Raw Normal View History

2016-07-30 21:27:14 +00:00
#pragma once
#include "stdafx.h"
#include "BaseControlDevice.h"
class OekaKidsTablet : public BaseControlDevice
{
private:
bool _strobe = false;
bool _shift = false;
uint32_t _stateBuffer = 0;
protected:
enum Buttons { Click, Touch };
bool HasCoordinates() override { return true; }
string GetKeyNames() override
{
return "CT";
}
void InternalSetStateFromInput() override
{
if(EmulationSettings::InputEnabled()) {
MousePosition pos = KeyManager::GetMousePosition();
SetPressedState(Buttons::Click, KeyManager::IsMouseButtonPressed(MouseButton::LeftButton));
SetPressedState(Buttons::Touch, pos.Y >= 48 || KeyManager::IsMouseButtonPressed(MouseButton::LeftButton));
SetCoordinates(pos);
}
}
void StreamState(bool saving) override
{
BaseControlDevice::StreamState(saving);
Stream(_strobe, _shift, _stateBuffer);
}
2016-07-30 21:27:14 +00:00
public:
OekaKidsTablet() : BaseControlDevice(BaseControlDevice::ExpDevicePort)
{
}
uint8_t ReadRAM(uint16_t addr) override
{
if(addr == 0x4017) {
if(_strobe) {
if(_shift) {
return (_stateBuffer & 0x40000) ? 0x00 : 0x08;
} else {
return 0x04;
}
} else {
return 0x00;
}
}
return 0;
}
void WriteRAM(uint16_t addr, uint8_t value) override
{
_strobe = (value & 0x01) == 0x01;
bool shift = ((value >> 1) & 0x01) == 0x01;
if(_strobe) {
if(!_shift && shift) {
_stateBuffer <<= 1;
}
_shift = shift;
} else {
MousePosition pos = GetCoordinates();
2016-07-30 21:27:14 +00:00
uint8_t xPosition = (uint8_t)((double)std::max(0, pos.X + 8) / 256.0 * 240);
uint8_t yPosition = (uint8_t)((double)std::max(0, pos.Y - 14) / 240.0 * 256);
2016-07-30 21:27:14 +00:00
_stateBuffer = (xPosition << 10) | (yPosition << 2) | (IsPressed(OekaKidsTablet::Buttons::Touch) ? 0x02 : 0x00) | (IsPressed(OekaKidsTablet::Buttons::Click) ? 0x01 : 0x00);
}
}
2016-07-30 21:27:14 +00:00
};