--- nono/vm/keyboard.cpp 2026/04/29 17:05:18 1.1.1.11 +++ nono/vm/keyboard.cpp 2026/04/29 17:05:51 1.1.1.17 @@ -88,7 +88,7 @@ // MakeKey()/BreakKey() : // | // | KEY_INPUT Message : -// | - - - - - - - - - - - -> KeyInputCallback() +// | - - - - - - - - - - - -> KeyInputMessage() // o | // : MD::KeyInput() // | @@ -100,15 +100,36 @@ #include "keyboard.h" #include "config.h" +#include "mainapp.h" #include "scheduler.h" #include "syncer.h" #include "uimessage.h" #include +// +// 文字入力しか持たないキーボードの下位クラス +// + // コンストラクタ -Keyboard::Keyboard() +DumbKeyboard::DumbKeyboard() : inherited(OBJ_KEYBOARD) { +} + +// デストラクタ +DumbKeyboard::~DumbKeyboard() +{ +} + + +// +// 通常のキーボード +// + +// コンストラクタ +Keyboard::Keyboard() + : inherited() +{ pressed.resize(KC_max); } @@ -121,14 +142,16 @@ Keyboard::~Keyboard() bool Keyboard::Init() { - if (inherited::Init() == false) { - return false; + // LUNA ならスケジューラとの連携が必要。 + // キーリピートをソフトウェアで処理しないといけないため。 + if (gMainApp.Has(VMCap::LUNA)) { + syncer = GetSyncer(); } - syncer = GetSyncer(); + uimessage = gMainApp.GetUIMessage(); scheduler->ConnectMessage(MessageID::KEY_INPUT, this, - ToMessageCallback(&Keyboard::KeyInputCallback)); + ToMessageCallback(&Keyboard::KeyInputMessage)); return true; } @@ -146,7 +169,7 @@ Keyboard::ResetHard(bool poweron) } // キー通知 - syncer->RequestKeyPressed(Any()); + SyncKeyPressed(Any()); } // 内部状態をリセット @@ -164,7 +187,7 @@ Keyboard::PowerOff() std::fill(pressed.begin(), pressed.end(), false); // キーが全部解放されたので通知 - syncer->RequestKeyPressed(false); + SyncKeyPressed(false); DoDisconnect(); } @@ -236,7 +259,7 @@ Keyboard::CharInput(uint charcode) // キー入力メッセージコールバック void -Keyboard::KeyInputCallback(MessageID msgid, uint32 arg) +Keyboard::KeyInputMessage(MessageID msgid, uint32 arg) { uint keystat = arg; switch (keystat) { @@ -272,7 +295,7 @@ Keyboard::DoConnect() } // UI に通知する - UIMessage::Post(UIMessage::KEYBOARD); + uimessage->Post(UIMessage::KEYBOARD); } void @@ -286,7 +309,38 @@ Keyboard::DoDisconnect() MDDisconnect(); // UI に通知する - UIMessage::Post(UIMessage::KEYBOARD); + uimessage->Post(UIMessage::KEYBOARD); +} + +// キーの押し下げ状態を設定する。 +// 初期化時以外で pressed を変更するときはこの関数を使用すること。 +void +Keyboard::SetPressed(uint keycode, bool ismake) +{ + // キーがどれか1つでも押されてる間は VM の高速実行を抑制する。 + // すべてのキーが離されたら高速モードを許可する。 + if (ismake) { + bool prev = Any(); + pressed[keycode] = true; + if (prev == false) { + SyncKeyPressed(true); + } + } else { + pressed[keycode] = false; + if (Any() == false) { + SyncKeyPressed(false); + } + } +} + +// LUNA なら、キーの押し下げ状態 (いずれかでも押し下げなら true) を +// syncer にも通知する。 +void +Keyboard::SyncKeyPressed(bool any_pressed) +{ + if (syncer) { + syncer->RequestKeyPressed(any_pressed); + } } // キー入力を1つ処理する。 @@ -315,7 +369,7 @@ Keyboard::KeyInputCommon(uint keystat) if (loglevel >= 1) { std::string msg; - msg += string_format("%d(", keycode); + msg += string_format("%u(", keycode); msg += GetKeyName(keycode); msg += ")"; @@ -340,20 +394,7 @@ Keyboard::KeyInputCommon(uint keystat) } } - // キーがどれか1つでも押されてる間は VM の高速実行を抑制する。 - // すべてのキーが離されたら高速モードを許可する。 - if (ismake) { - bool prev = Any(); - pressed[keycode] = true; - if (prev == false) { - syncer->RequestKeyPressed(true); - } - } else { - pressed[keycode] = false; - if (Any() == false) { - syncer->RequestKeyPressed(false); - } - } + SetPressed(keycode, ismake); // キーの状態が変わったので UI に通知。 // KC_FLAG_POST が立っていればキーコードも送信 (char 入力モード用)。 @@ -366,7 +407,7 @@ Keyboard::KeyInputCommon(uint keystat) } else { arg = 0; } - UIMessage::Post(UIMessage::KEYBOARD, arg); + uimessage->Post(UIMessage::KEYBOARD, arg); // LUNA の LED キー消灯はキー開放を送信 if (ledflag == KC_FLAG_LED_BREAK) { @@ -417,7 +458,7 @@ Keyboard::GetKeyName(uint keycode) Keyboard::keyname { "(none)", // 00 "BREAK", // 01 - "COPY", // 02 + NULL, // 02 "romaji", // 03 "code", // 04 "kigou", // 05 @@ -435,7 +476,7 @@ Keyboard::keyname { "ESC", // 10 "BS", // 11 "enter", // 12 - "INS", // 13 + NULL, // 13 "space", // 14 "DEL", // 15 "XFER", // 16 @@ -449,8 +490,8 @@ Keyboard::keyname { "right", // 1e "down", // 1f - "ROLLUP", // 20 - "ROLLDOWN", // 21 + "INS", // 20 + "COPY", // 21 "1", // 22 "2", // 23 "3", // 24 @@ -466,8 +507,8 @@ Keyboard::keyname { "backslash", // 2e "", // 2f - "OPT1", // 30 - "OPT2", // 31 + "CUT", // 30 + "PASTE", // 31 "Q", // 32 "W", // 33 "E", // 34 @@ -483,7 +524,7 @@ Keyboard::keyname { "hira", // 3e "zenkaku", // 3f - "HOME", // 40 + NULL, // 40 "UNDO", // 41 "A", // 42 "S", // 43 @@ -497,8 +538,8 @@ Keyboard::keyname { "semicolon", // 4b "colon", // 4c "bracketright", // 4d - NULL, // 4e - NULL, // 4f + "OPT1", // 4e + "OPT2", // 4f "XF1", // 50 "XF2", // 51 @@ -517,7 +558,7 @@ Keyboard::keyname { "XF4", // 5e "XF5", // 5f - NULL, // 60 + "HOME", // 60 "PAD_plus", // 61 "PAD_minus", // 62 "PAD_7", // 63 @@ -534,8 +575,8 @@ Keyboard::keyname { "PAD_enter", // 6e "PAD_CLR", // 6f - NULL, // 70 - NULL, // 71 + "ROLLUP", // 70 + "ROLLDOWN", // 71 "F1", // 72 "F2", // 73 "F3", // 74