1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-29 12:50:28 +00:00

Shifts essential modifiers up to the Keyboard class.

I had forgotten that mappers are not exposed.
This commit is contained in:
Thomas Harte 2019-09-22 13:48:50 -04:00
parent 8f88addf9f
commit 077c7d767f
8 changed files with 27 additions and 20 deletions

View File

@ -10,13 +10,14 @@
using namespace Inputs; using namespace Inputs;
Keyboard::Keyboard() { Keyboard::Keyboard(const std::set<Key> &essential_modifiers) : essential_modifiers_(essential_modifiers) {
for(int k = 0; k < int(Key::Help); ++k) { for(int k = 0; k < int(Key::Help); ++k) {
observed_keys_.insert(Key(k)); observed_keys_.insert(Key(k));
} }
} }
Keyboard::Keyboard(const std::set<Key> &observed_keys) : observed_keys_(observed_keys), is_exclusive_(false) {} Keyboard::Keyboard(const std::set<Key> &observed_keys, const std::set<Key> &essential_modifiers) :
observed_keys_(observed_keys), essential_modifiers_(essential_modifiers), is_exclusive_(false) {}
void Keyboard::set_key_pressed(Key key, char value, bool is_pressed) { void Keyboard::set_key_pressed(Key key, char value, bool is_pressed) {
std::size_t key_offset = static_cast<std::size_t>(key); std::size_t key_offset = static_cast<std::size_t>(key);
@ -28,6 +29,10 @@ void Keyboard::set_key_pressed(Key key, char value, bool is_pressed) {
if(delegate_) delegate_->keyboard_did_change_key(this, key, is_pressed); if(delegate_) delegate_->keyboard_did_change_key(this, key, is_pressed);
} }
const std::set<Inputs::Keyboard::Key> &Keyboard::get_essential_modifiers() {
return essential_modifiers_;
}
void Keyboard::reset_all_keys() { void Keyboard::reset_all_keys() {
std::fill(key_states_.begin(), key_states_.end(), false); std::fill(key_states_.begin(), key_states_.end(), false);
if(delegate_) delegate_->reset_all_keys(this); if(delegate_) delegate_->reset_all_keys(this);

View File

@ -39,10 +39,10 @@ class Keyboard {
}; };
/// Constructs a Keyboard that declares itself to observe all keys. /// Constructs a Keyboard that declares itself to observe all keys.
Keyboard(); Keyboard(const std::set<Key> &essential_modifiers = {});
/// Constructs a Keyboard that declares itself to observe only members of @c observed_keys. /// Constructs a Keyboard that declares itself to observe only members of @c observed_keys.
Keyboard(const std::set<Key> &observed_keys); Keyboard(const std::set<Key> &observed_keys, const std::set<Key> &essential_modifiers);
// Host interface. // Host interface.
virtual void set_key_pressed(Key key, char value, bool is_pressed); virtual void set_key_pressed(Key key, char value, bool is_pressed);
@ -51,10 +51,18 @@ class Keyboard {
/// @returns a set of all Keys that this keyboard responds to. /// @returns a set of all Keys that this keyboard responds to.
virtual const std::set<Key> &observed_keys(); virtual const std::set<Key> &observed_keys();
/* /// @returns the list of modifiers that this keyboard considers 'essential' (i.e. both mapped and highly used).
virtual const std::set<Inputs::Keyboard::Key> &get_essential_modifiers();
/*!
@returns @c true if this keyboard, on its original machine, looked @returns @c true if this keyboard, on its original machine, looked
like a complete keyboard i.e. if a user would expect this keyboard like a complete keyboard i.e. if a user would expect this keyboard
to be the only thing a real keyboard maps to. to be the only thing a real keyboard maps to.
So this would be true of something like the Amstrad CPC, which has a full
keyboard, but it would be false of something like the Sega Master System
which has some buttons that you'd expect an emulator to map to its host
keyboard but which does not offer a full keyboard.
*/ */
virtual bool is_exclusive(); virtual bool is_exclusive();
@ -68,6 +76,7 @@ class Keyboard {
private: private:
std::set<Key> observed_keys_; std::set<Key> observed_keys_;
std::set<Key> essential_modifiers_;
std::vector<bool> key_states_; std::vector<bool> key_states_;
Delegate *delegate_ = nullptr; Delegate *delegate_ = nullptr;
bool is_exclusive_ = true; bool is_exclusive_ = true;

View File

@ -86,13 +86,3 @@ uint16_t KeyboardMapper::mapped_key_for_key(Inputs::Keyboard::Key key) {
#undef Bind #undef Bind
} }
} }
std::set<Inputs::Keyboard::Key> KeyboardMapper::get_essential_modifiers() {
// Control is fairly optional for a Mac, but option, meta and shift
// are essential.
return {
Inputs::Keyboard::Key::LeftShift, Inputs::Keyboard::Key::RightShift,
Inputs::Keyboard::Key::LeftOption, Inputs::Keyboard::Key::RightOption,
Inputs::Keyboard::Key::LeftMeta, Inputs::Keyboard::Key::RightMeta,
};
}

View File

@ -292,7 +292,6 @@ class Keyboard {
*/ */
class KeyboardMapper: public KeyboardMachine::MappedMachine::KeyboardMapper { class KeyboardMapper: public KeyboardMachine::MappedMachine::KeyboardMapper {
uint16_t mapped_key_for_key(Inputs::Keyboard::Key key) final; uint16_t mapped_key_for_key(Inputs::Keyboard::Key key) final;
std::set<Inputs::Keyboard::Key> get_essential_modifiers() final;
}; };
} }

View File

@ -78,6 +78,11 @@ template <Analyser::Static::Macintosh::Target::Model model> class ConcreteMachin
using Target = Analyser::Static::Macintosh::Target; using Target = Analyser::Static::Macintosh::Target;
ConcreteMachine(const Target &target, const ROMMachine::ROMFetcher &rom_fetcher) : ConcreteMachine(const Target &target, const ROMMachine::ROMFetcher &rom_fetcher) :
KeyboardMachine::MappedMachine({
Inputs::Keyboard::Key::LeftShift, Inputs::Keyboard::Key::RightShift,
Inputs::Keyboard::Key::LeftOption, Inputs::Keyboard::Key::RightOption,
Inputs::Keyboard::Key::LeftMeta, Inputs::Keyboard::Key::RightMeta,
}),
mc68000_(*this), mc68000_(*this),
iwm_(CLOCK_RATE), iwm_(CLOCK_RATE),
video_(audio_, drive_speed_accumulator_), video_(audio_, drive_speed_accumulator_),

View File

@ -10,7 +10,7 @@
using namespace KeyboardMachine; using namespace KeyboardMachine;
MappedMachine::MappedMachine() { MappedMachine::MappedMachine(const std::set<Inputs::Keyboard::Key> &essential_modifiers) : keyboard_(essential_modifiers) {
keyboard_.set_delegate(this); keyboard_.set_delegate(this);
} }

View File

@ -57,7 +57,7 @@ class Machine: public KeyActions {
*/ */
class MappedMachine: public Inputs::Keyboard::Delegate, public Machine { class MappedMachine: public Inputs::Keyboard::Delegate, public Machine {
public: public:
MappedMachine(); MappedMachine(const std::set<Inputs::Keyboard::Key> &essential_modifiers = {});
/*! /*!
A keyboard mapper attempts to provide a physical mapping between host keys and emulated keys. A keyboard mapper attempts to provide a physical mapping between host keys and emulated keys.
@ -66,7 +66,6 @@ class MappedMachine: public Inputs::Keyboard::Delegate, public Machine {
class KeyboardMapper { class KeyboardMapper {
public: public:
virtual uint16_t mapped_key_for_key(Inputs::Keyboard::Key key) = 0; virtual uint16_t mapped_key_for_key(Inputs::Keyboard::Key key) = 0;
virtual std::set<Inputs::Keyboard::Key> get_essential_modifiers() { return {}; }
}; };
/// Terminates a key sequence from the character mapper. /// Terminates a key sequence from the character mapper.

View File

@ -101,7 +101,7 @@ class ConcreteMachine:
audio_queue_, audio_queue_,
sn76489_divider), sn76489_divider),
speaker_(sn76489_), speaker_(sn76489_),
keyboard_({Inputs::Keyboard::Key::Enter, Inputs::Keyboard::Key::Escape}) { keyboard_({Inputs::Keyboard::Key::Enter, Inputs::Keyboard::Key::Escape}, {}) {
// Pick the clock rate based on the region. // Pick the clock rate based on the region.
const double clock_rate = target.region == Target::Region::Europe ? 3546893.0 : 3579540.0; const double clock_rate = target.region == Target::Region::Europe ? 3546893.0 : 3579540.0;
speaker_.set_input_rate(static_cast<float>(clock_rate / sn76489_divider)); speaker_.set_input_rate(static_cast<float>(clock_rate / sn76489_divider));