2017-11-20 04:08:23 +00:00
|
|
|
#pragma once
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "BaseControlDevice.h"
|
|
|
|
|
|
|
|
class SuborKeyboard : public BaseControlDevice
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
uint8_t _row = 0;
|
|
|
|
uint8_t _column = 0;
|
|
|
|
bool _enabled = false;
|
|
|
|
|
|
|
|
protected:
|
2017-12-16 19:06:00 +00:00
|
|
|
string GetKeyNames() override
|
|
|
|
{
|
|
|
|
return "ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567891234567890120123456789edpmdmncdsasbemglrcpcsasbteeehidududlr123";
|
|
|
|
}
|
|
|
|
|
2017-11-20 04:08:23 +00:00
|
|
|
enum Buttons
|
|
|
|
{
|
2017-12-16 19:06:00 +00:00
|
|
|
A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z,
|
|
|
|
Num0, Num1, Num2, Num3, Num4, Num5, Num6, Num7, Num8, Num9,
|
|
|
|
F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12,
|
|
|
|
Numpad0, Numpad1, Numpad2, Numpad3, Numpad4, Numpad5, Numpad6, Numpad7, Numpad8, Numpad9,
|
|
|
|
NumpadEnter, NumpadDot, NumpadPlus, NumpadMultiply, NumpadDivide, NumpadMinus, NumLock,
|
|
|
|
Comma, Dot, SemiColon, Apostrophe,
|
|
|
|
Slash, Backslash,
|
|
|
|
Equal, Minus, Grave,
|
|
|
|
LeftBracket, RightBracket,
|
|
|
|
CapsLock, Pause,
|
|
|
|
Ctrl, Shift, Alt,
|
|
|
|
Space, Backspace, Tab, Esc, Enter,
|
|
|
|
End, Home,
|
|
|
|
Ins, Delete,
|
|
|
|
PageUp, PageDown,
|
|
|
|
Up, Down, Left, Right,
|
|
|
|
Unknown1, Unknown2, Unknown3,
|
2017-11-20 04:08:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Buttons _keyboardMatrix[104] = {
|
|
|
|
Num4, G, F, C, F2, E, Num5, V,
|
|
|
|
Num2, D, S, End, F1, W, Num3, X,
|
|
|
|
Ins, Backspace, PageDown, Right, F8, PageUp, Delete, Home,
|
|
|
|
Num9, I, L, Comma, F5, O, Num0, Dot,
|
|
|
|
RightBracket, Enter, Up, Left, F7, LeftBracket, Backslash, Down,
|
|
|
|
Q, CapsLock, Z, Tab, Esc, A, Num1, Ctrl,
|
|
|
|
Num7, Y, K, M, F4, U, Num8, J,
|
|
|
|
Minus, SemiColon, Apostrophe, Slash, F6, P, Equal, Shift,
|
|
|
|
T, H, N, Space, F3, R, Num6, B,
|
|
|
|
Numpad6, NumpadEnter, Numpad4, Numpad8, Numpad2, Unknown1, Unknown2, Unknown3,
|
2017-12-16 19:06:00 +00:00
|
|
|
Alt, Numpad4, Numpad7, F11, F12, Numpad1, Numpad2, Numpad8,
|
2017-11-20 04:08:23 +00:00
|
|
|
NumpadMinus, NumpadPlus, NumpadMultiply, Numpad9, F10, Numpad5, NumpadDivide, NumLock,
|
|
|
|
Grave, Numpad6, Pause, Space, F9, Numpad3, NumpadDot, Numpad0
|
|
|
|
};
|
|
|
|
|
|
|
|
void InternalSetStateFromInput() override
|
|
|
|
{
|
|
|
|
for(KeyMapping keyMapping : _keyMappings) {
|
|
|
|
for(int i = 0; i < 99; i++) {
|
|
|
|
SetPressedState(i, keyMapping.SuborKeyboardButtons[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t GetActiveKeys(uint8_t row, uint8_t column)
|
|
|
|
{
|
|
|
|
uint8_t result = 0;
|
|
|
|
uint32_t baseIndex = row * 8 + (column ? 4 : 0);
|
|
|
|
for(int i = 0; i < 4; i++) {
|
|
|
|
if(IsPressed(_keyboardMatrix[baseIndex + i])) {
|
|
|
|
result |= 0x10;
|
|
|
|
}
|
|
|
|
result >>= 1;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void StreamState(bool saving) override
|
|
|
|
{
|
|
|
|
BaseControlDevice::StreamState(saving);
|
|
|
|
Stream(_row, _column, _enabled);
|
|
|
|
}
|
|
|
|
|
2017-11-21 00:15:17 +00:00
|
|
|
void RefreshStateBuffer() override
|
|
|
|
{
|
|
|
|
_row = 0;
|
|
|
|
_column = 0;
|
|
|
|
}
|
|
|
|
|
2017-11-20 04:08:23 +00:00
|
|
|
public:
|
2018-07-14 02:19:26 +00:00
|
|
|
SuborKeyboard(shared_ptr<Console> console, KeyMappingSet keyMappings) : BaseControlDevice(console, BaseControlDevice::ExpDevicePort, keyMappings)
|
2017-11-20 04:08:23 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-12-18 02:11:54 +00:00
|
|
|
bool IsKeyboard() override
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-11-20 04:08:23 +00:00
|
|
|
uint8_t ReadRAM(uint16_t addr) override
|
|
|
|
{
|
|
|
|
if(addr == 0x4017) {
|
|
|
|
if(_enabled) {
|
|
|
|
uint8_t value = ((~GetActiveKeys(_row, _column)) << 1) & 0x1E;
|
|
|
|
return value;
|
|
|
|
} else {
|
|
|
|
return 0x1E;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WriteRAM(uint16_t addr, uint8_t value) override
|
|
|
|
{
|
|
|
|
StrobeProcessWrite(value);
|
|
|
|
|
|
|
|
uint8_t prevColumn = _column;
|
|
|
|
_column = (value & 0x02) >> 1;
|
|
|
|
_enabled = (value & 0x04) != 0;
|
|
|
|
|
|
|
|
if(_enabled) {
|
|
|
|
if(!_column && prevColumn) {
|
|
|
|
_row = (_row + 1) % 13;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|