mirror of
https://github.com/TomHarte/CLK.git
synced 2025-01-10 16:30:07 +00:00
Add most of the keyboard.
This commit is contained in:
parent
1628af2ffc
commit
a1f6e93e22
130
Machines/Commodore/Plus4/Keyboard.cpp
Normal file
130
Machines/Commodore/Plus4/Keyboard.cpp
Normal file
@ -0,0 +1,130 @@
|
||||
//
|
||||
// Keyboard.cpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 13/12/2024.
|
||||
// Copyright 2024 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#include "Keyboard.hpp"
|
||||
|
||||
using namespace Commodore::Plus4;
|
||||
|
||||
uint16_t KeyboardMapper::mapped_key_for_key(Inputs::Keyboard::Key key) const {
|
||||
#define BIND(source, dest) case Inputs::Keyboard::Key::source: return Commodore::Plus4::dest
|
||||
switch(key) {
|
||||
default: break;
|
||||
|
||||
BIND(k0, k0); BIND(k1, k1); BIND(k2, k2); BIND(k3, k3); BIND(k4, k4);
|
||||
BIND(k5, k5); BIND(k6, k6); BIND(k7, k7); BIND(k8, k8); BIND(k9, k9);
|
||||
BIND(Q, Q); BIND(W, W); BIND(E, E); BIND(R, R); BIND(T, T);
|
||||
BIND(Y, Y); BIND(U, U); BIND(I, I); BIND(O, O); BIND(P, P);
|
||||
BIND(A, A); BIND(S, S); BIND(D, D); BIND(F, F); BIND(G, G);
|
||||
BIND(H, H); BIND(J, J); BIND(K, K); BIND(L, L);
|
||||
BIND(Z, Z); BIND(X, X); BIND(C, C); BIND(V, V);
|
||||
BIND(B, B); BIND(N, N); BIND(M, M);
|
||||
|
||||
BIND(Backspace, InsDel);
|
||||
BIND(Escape, Escape);
|
||||
BIND(F1, F1_F4);
|
||||
BIND(F2, F2_F5);
|
||||
BIND(F3, F3_F6);
|
||||
BIND(F4, Help_F7);
|
||||
BIND(Enter, Return);
|
||||
BIND(Space, Space);
|
||||
|
||||
BIND(Up, Up); BIND(Down, Down); BIND(Left, Left); BIND(Right, Right);
|
||||
|
||||
BIND(LeftShift, Shift); BIND(RightShift, Shift);
|
||||
BIND(LeftControl, Control); BIND(RightControl, Control);
|
||||
BIND(LeftOption, Commodore); BIND(RightOption, Commodore);
|
||||
|
||||
BIND(FullStop, FullStop); BIND(Comma, Comma);
|
||||
BIND(Semicolon, Semicolon); BIND(Quote, Colon);
|
||||
BIND(Equals, Equals); BIND(ForwardSlash, Slash);
|
||||
|
||||
// TODO:
|
||||
// At
|
||||
// GBP
|
||||
// Asterisk
|
||||
// Clear_Home
|
||||
// Run_Stop
|
||||
}
|
||||
#undef BIND
|
||||
return MachineTypes::MappedKeyboardMachine::KeyNotMapped;
|
||||
}
|
||||
|
||||
//const uint16_t *CharacterMapper::sequence_for_character(char character) const {
|
||||
//#define KEYS(...) {__VA_ARGS__, MachineTypes::MappedKeyboardMachine::KeyEndSequence}
|
||||
//#define SHIFT(...) {KeyLShift, __VA_ARGS__, MachineTypes::MappedKeyboardMachine::KeyEndSequence}
|
||||
//#define X {MachineTypes::MappedKeyboardMachine::KeyNotMapped}
|
||||
// static KeySequence key_sequences[] = {
|
||||
// /* NUL */ X, /* SOH */ X,
|
||||
// /* STX */ X, /* ETX */ X,
|
||||
// /* EOT */ X, /* ENQ */ X,
|
||||
// /* ACK */ X, /* BEL */ X,
|
||||
// /* BS */ KEYS(KeyDelete), /* HT */ X,
|
||||
// /* LF */ KEYS(KeyReturn), /* VT */ X,
|
||||
// /* FF */ X, /* CR */ X,
|
||||
// /* SO */ X, /* SI */ X,
|
||||
// /* DLE */ X, /* DC1 */ X,
|
||||
// /* DC2 */ X, /* DC3 */ X,
|
||||
// /* DC4 */ X, /* NAK */ X,
|
||||
// /* SYN */ X, /* ETB */ X,
|
||||
// /* CAN */ X, /* EM */ X,
|
||||
// /* SUB */ X, /* ESC */ X,
|
||||
// /* FS */ X, /* GS */ X,
|
||||
// /* RS */ X, /* US */ X,
|
||||
// /* space */ KEYS(KeySpace), /* ! */ SHIFT(Key1),
|
||||
// /* " */ SHIFT(Key2), /* # */ SHIFT(Key3),
|
||||
// /* $ */ SHIFT(Key4), /* % */ SHIFT(Key5),
|
||||
// /* & */ SHIFT(Key6), /* ' */ SHIFT(Key7),
|
||||
// /* ( */ SHIFT(Key8), /* ) */ SHIFT(Key9),
|
||||
// /* * */ KEYS(KeyAsterisk), /* + */ KEYS(KeyPlus),
|
||||
// /* , */ KEYS(KeyComma), /* - */ KEYS(KeyDash),
|
||||
// /* . */ KEYS(KeyFullStop), /* / */ KEYS(KeySlash),
|
||||
// /* 0 */ KEYS(Key0), /* 1 */ KEYS(Key1),
|
||||
// /* 2 */ KEYS(Key2), /* 3 */ KEYS(Key3),
|
||||
// /* 4 */ KEYS(Key4), /* 5 */ KEYS(Key5),
|
||||
// /* 6 */ KEYS(Key6), /* 7 */ KEYS(Key7),
|
||||
// /* 8 */ KEYS(Key8), /* 9 */ KEYS(Key9),
|
||||
// /* : */ KEYS(KeyColon), /* ; */ KEYS(KeySemicolon),
|
||||
// /* < */ SHIFT(KeyComma), /* = */ KEYS(KeyEquals),
|
||||
// /* > */ SHIFT(KeyFullStop), /* ? */ SHIFT(KeySlash),
|
||||
// /* @ */ KEYS(KeyAt), /* A */ KEYS(KeyA),
|
||||
// /* B */ KEYS(KeyB), /* C */ KEYS(KeyC),
|
||||
// /* D */ KEYS(KeyD), /* E */ KEYS(KeyE),
|
||||
// /* F */ KEYS(KeyF), /* G */ KEYS(KeyG),
|
||||
// /* H */ KEYS(KeyH), /* I */ KEYS(KeyI),
|
||||
// /* J */ KEYS(KeyJ), /* K */ KEYS(KeyK),
|
||||
// /* L */ KEYS(KeyL), /* M */ KEYS(KeyM),
|
||||
// /* N */ KEYS(KeyN), /* O */ KEYS(KeyO),
|
||||
// /* P */ KEYS(KeyP), /* Q */ KEYS(KeyQ),
|
||||
// /* R */ KEYS(KeyR), /* S */ KEYS(KeyS),
|
||||
// /* T */ KEYS(KeyT), /* U */ KEYS(KeyU),
|
||||
// /* V */ KEYS(KeyV), /* W */ KEYS(KeyW),
|
||||
// /* X */ KEYS(KeyX), /* Y */ KEYS(KeyY),
|
||||
// /* Z */ KEYS(KeyZ), /* [ */ SHIFT(KeyColon),
|
||||
// /* \ */ X, /* ] */ SHIFT(KeySemicolon),
|
||||
// /* ^ */ X, /* _ */ X,
|
||||
// /* ` */ X, /* a */ KEYS(KeyA),
|
||||
// /* b */ KEYS(KeyB), /* c */ KEYS(KeyC),
|
||||
// /* d */ KEYS(KeyD), /* e */ KEYS(KeyE),
|
||||
// /* f */ KEYS(KeyF), /* g */ KEYS(KeyG),
|
||||
// /* h */ KEYS(KeyH), /* i */ KEYS(KeyI),
|
||||
// /* j */ KEYS(KeyJ), /* k */ KEYS(KeyK),
|
||||
// /* l */ KEYS(KeyL), /* m */ KEYS(KeyM),
|
||||
// /* n */ KEYS(KeyN), /* o */ KEYS(KeyO),
|
||||
// /* p */ KEYS(KeyP), /* q */ KEYS(KeyQ),
|
||||
// /* r */ KEYS(KeyR), /* s */ KEYS(KeyS),
|
||||
// /* t */ KEYS(KeyT), /* u */ KEYS(KeyU),
|
||||
// /* v */ KEYS(KeyV), /* w */ KEYS(KeyW),
|
||||
// /* x */ KEYS(KeyX), /* y */ KEYS(KeyY),
|
||||
// /* z */ KEYS(KeyZ)
|
||||
// };
|
||||
//#undef KEYS
|
||||
//#undef SHIFT
|
||||
//#undef X
|
||||
//
|
||||
// return table_lookup_sequence_for_character(key_sequences, character);
|
||||
//}
|
76
Machines/Commodore/Plus4/Keyboard.hpp
Normal file
76
Machines/Commodore/Plus4/Keyboard.hpp
Normal file
@ -0,0 +1,76 @@
|
||||
//
|
||||
// Keyboard.hpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 13/12/2024.
|
||||
// Copyright 2024 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../../KeyboardMachine.hpp"
|
||||
#include "../../Utility/Typer.hpp"
|
||||
|
||||
namespace Commodore::Plus4 {
|
||||
|
||||
static constexpr uint16_t key(const int line, const int mask) {
|
||||
return uint16_t((mask << 3) | line);
|
||||
}
|
||||
static constexpr size_t line(const uint16_t key) {
|
||||
return key & 7;
|
||||
}
|
||||
static constexpr uint8_t mask(const uint16_t key) {
|
||||
return uint8_t(key >> 3);
|
||||
}
|
||||
|
||||
enum Key: uint16_t {
|
||||
InsDel = key(0, 0x01), Return = key(0, 0x02),
|
||||
GBP = key(0, 0x04), Help_F7 = key(0, 0x08),
|
||||
F1_F4 = key(0, 0x10), F2_F5 = key(0, 0x20),
|
||||
F3_F6 = key(0, 0x40), At = key(0, 0x80),
|
||||
|
||||
k3 = key(1, 0x01), W = key(1, 0x02),
|
||||
A = key(1, 0x04), k4 = key(1, 0x08),
|
||||
Z = key(1, 0x10), S = key(1, 0x20),
|
||||
E = key(1, 0x40), Shift = key(1, 0x80),
|
||||
|
||||
k5 = key(2, 0x01), R = key(2, 0x02),
|
||||
D = key(2, 0x04), k6 = key(2, 0x08),
|
||||
C = key(2, 0x10), F = key(2, 0x20),
|
||||
T = key(2, 0x40), X = key(2, 0x80),
|
||||
|
||||
k7 = key(3, 0x01), Y = key(3, 0x02),
|
||||
G = key(3, 0x04), k8 = key(3, 0x08),
|
||||
B = key(3, 0x10), H = key(3, 0x20),
|
||||
U = key(3, 0x40), V = key(3, 0x80),
|
||||
|
||||
k9 = key(4, 0x01), I = key(4, 0x02),
|
||||
J = key(4, 0x04), k0 = key(4, 0x08),
|
||||
M = key(4, 0x10), K = key(4, 0x20),
|
||||
O = key(4, 0x40), N = key(4, 0x80),
|
||||
|
||||
Down = key(5, 0x01), P = key(5, 0x02),
|
||||
L = key(5, 0x04), Up = key(5, 0x08),
|
||||
FullStop = key(5, 0x10), Colon = key(5, 0x20),
|
||||
Minus = key(5, 0x40), Comma = key(5, 0x80),
|
||||
|
||||
Left = key(6, 0x01), Asterisk = key(6, 0x02),
|
||||
Semicolon = key(6, 0x04), Right = key(6, 0x08),
|
||||
Escape = key(6, 0x10), Equals = key(6, 0x20),
|
||||
Plus = key(6, 0x40), Slash = key(6, 0x80),
|
||||
|
||||
k1 = key(7, 0x01), Clear_Home = key(7, 0x02),
|
||||
Control = key(7, 0x04), k2 = key(7, 0x08),
|
||||
Space = key(7, 0x10), Commodore = key(7, 0x20),
|
||||
Q = key(7, 0x40), Run_Stop = key(7, 0x80),
|
||||
};
|
||||
|
||||
struct KeyboardMapper: public MachineTypes::MappedKeyboardMachine::KeyboardMapper {
|
||||
uint16_t mapped_key_for_key(Inputs::Keyboard::Key key) const final;
|
||||
};
|
||||
|
||||
//struct CharacterMapper: public ::Utility::CharacterMapper {
|
||||
// const uint16_t *sequence_for_character(char character) const final;
|
||||
//};
|
||||
|
||||
}
|
@ -9,6 +9,7 @@
|
||||
#include "Plus4.hpp"
|
||||
|
||||
#include "Interrupts.hpp"
|
||||
#include "Keyboard.hpp"
|
||||
#include "Pager.hpp"
|
||||
#include "Video.hpp"
|
||||
|
||||
@ -100,6 +101,7 @@ private:
|
||||
class ConcreteMachine:
|
||||
public CPU::MOS6502::BusHandler,
|
||||
public Interrupts::Delegate,
|
||||
public MachineTypes::MappedKeyboardMachine,
|
||||
public MachineTypes::TimedMachine,
|
||||
public MachineTypes::ScanProducer,
|
||||
public MachineTypes::MediaTarget,
|
||||
@ -205,14 +207,18 @@ public:
|
||||
case 0xff04: timers_.write<4>(*value); break;
|
||||
case 0xff05: timers_.write<5>(*value); break;
|
||||
|
||||
case 0xff08:
|
||||
printf("Keyboard: %02x\n", *value);
|
||||
|
||||
keyboard_latch_ = (*value & 2) ? 0xff : 0xfb;
|
||||
// TODO: keyboard. Low bits on the data bus select keyboard lines.
|
||||
// Pressed keys drain to 0.
|
||||
// TODO: possibly fd30 imputes joystick inputs here too?
|
||||
break;
|
||||
case 0xff08: {
|
||||
keyboard_latch_ = ~(
|
||||
((*value & 0x01) ? 0x00 : key_states_[0]) |
|
||||
((*value & 0x02) ? 0x00 : key_states_[1]) |
|
||||
((*value & 0x04) ? 0x00 : key_states_[2]) |
|
||||
((*value & 0x08) ? 0x00 : key_states_[3]) |
|
||||
((*value & 0x10) ? 0x00 : key_states_[4]) |
|
||||
((*value & 0x20) ? 0x00 : key_states_[5]) |
|
||||
((*value & 0x40) ? 0x00 : key_states_[6]) |
|
||||
((*value & 0x80) ? 0x00 : key_states_[7])
|
||||
);
|
||||
} break;
|
||||
|
||||
case 0xff09:
|
||||
interrupts_.set_status(*value);
|
||||
@ -290,12 +296,27 @@ private:
|
||||
std::vector<uint8_t> kernel_;
|
||||
std::vector<uint8_t> basic_;
|
||||
|
||||
uint8_t keyboard_latch_ = 0xff;
|
||||
|
||||
Interrupts interrupts_;
|
||||
Cycles timers_subcycles_;
|
||||
Timers timers_;
|
||||
Video video_;
|
||||
|
||||
// MARK: - MappedKeyboardMachine.
|
||||
MappedKeyboardMachine::KeyboardMapper *get_keyboard_mapper() override {
|
||||
static Commodore::Plus4::KeyboardMapper keyboard_mapper_;
|
||||
return &keyboard_mapper_;
|
||||
}
|
||||
|
||||
void set_key_state(uint16_t key, bool is_pressed) override {
|
||||
if(is_pressed) {
|
||||
key_states_[line(key)] |= mask(key);
|
||||
} else {
|
||||
key_states_[line(key)] &= ~mask(key);
|
||||
}
|
||||
}
|
||||
|
||||
std::array<uint8_t, 8> key_states_{};
|
||||
uint8_t keyboard_latch_ = 0xff;
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user