--- nono/vm/lunakbd.cpp 2026/04/29 17:05:33 1.1.1.16 +++ nono/vm/lunakbd.cpp 2026/04/29 17:06:00 1.1.1.18 @@ -16,6 +16,7 @@ // 同様に高速走行を抑制したいため、キー扱いとしていることに留意。 #include "lunakbd.h" +#include "event.h" #include "monitor.h" #include "scheduler.h" #include "sio.h" @@ -27,7 +28,7 @@ LunaKeyboard::LunaKeyboard() led.resize(2); monitor = gMonitorManager->Regist(ID_MONITOR_KEYBOARD, this); - monitor->func = ToMonitorCallback(&LunaKeyboard::MonitorUpdate); + monitor->SetCallback(&LunaKeyboard::MonitorScreen); monitor->SetSize(40, 4); } @@ -44,11 +45,18 @@ LunaKeyboard::Init() return false; } + // LUNA-88K は左 [SHIFT] が 0x0d、右 [SHIFT] が 0x0c。 + if (gMainApp.IsLUNA88K()) { + keycode2lunakey_table[0x0c] = LunaKey_SHIFT_R; + keycode2lunakey_table[0x0d] = LunaKey_SHIFT_L; + } + sio = GetSIODevice(); - event.func = ToEventCallback(&LunaKeyboard::Callback); - event.SetName("Keyboard/Mouse"); - scheduler->RegistEvent(event); + auto evman = GetEventManager(); + event = evman->Regist(this, + ToEventCallback(&LunaKeyboard::Callback), + "Keyboard/Mouse"); return true; } @@ -91,7 +99,7 @@ LunaKeyboard::MDDisconnect() // モニター void -LunaKeyboard::MonitorUpdate(Monitor *, TextScreen& screen) +LunaKeyboard::MonitorScreen(Monitor *, TextScreen& screen) { int x; int y; @@ -206,7 +214,7 @@ LunaKeyboard::KeyInput(uint keystat) // LED 状態が変更になったので全走査指示。 // KeyInputCommon() 内で一度ポストしてるので無駄気味だが仕方ない… - UIMessage::Post(UIMessage::KEYBOARD); + uimessage->Post(UIMessage::KEYBOARD); } // LUNA のキーボードはキーボード側でキーリピートしないので @@ -270,8 +278,8 @@ LunaKeyboard::Start(uint64 period) uint64 now = scheduler->GetVirtTime(); uint64 target = ((now / period) + 1) * period; // XXX メンバの event.vtime 参照してるけどどうするかね - if (event.IsRunning() == false || target < event.vtime) { - event.time = target - now; + if (event->IsRunning() == false || target < event->vtime) { + event->time = target - now; scheduler->RestartEvent(event); } } @@ -280,7 +288,7 @@ LunaKeyboard::Start(uint64 period) // キー入力、マウス入力、ブザー出力のいずれかが発生している間 2msec ごとに // 呼ばれる。 void -LunaKeyboard::Callback(Event& ev) +LunaKeyboard::Callback(Event *ev) { uint64 now = scheduler->GetVirtTime(); uint mdkey; @@ -414,7 +422,7 @@ LunaKeyboard::Command(uint32 data) uint code = data & 0x01; uint on = data & 0x10; led[code] = (bool)on; - UIMessage::Post(UIMessage::KEYBOARD); + uimessage->Post(UIMessage::KEYBOARD); if (loglevel >= 1) { const auto name = GetKeyName(LED2Keycode(code)); putlogn("Command $%02x LED $%x(%s) %s", @@ -439,7 +447,7 @@ LunaKeyboard::Command(uint32 data) data, buzzer_msec, buzzer_freq); uint64 now = scheduler->GetVirtTime(); - buzzer_end = now + buzzer_msec * 1_msec; + buzzer_end = now + msec_to_nsec(buzzer_msec); // VM スレッド内なので MakeKey() ではなく KeyInput() を直接呼ぶ KeyInput(KC_buzzer | KC_FLAG_MAKE); Start(2_msec); @@ -474,7 +482,7 @@ LunaKeyboard::Command(uint32 data) // 共通キーコードから LUNA キーコードに変換する。 // ぶっちゃけた話共通キーコードは LUNA キーコードをベースにしているので、 // 穴がある以外は全部透過。 -/*static*/ const uint +/*static*/ uint LunaKeyboard::keycode2lunakey_table[KC_max] = { NoKey, // [00] NoKey, // [01] @@ -510,8 +518,8 @@ LunaKeyboard::keycode2lunakey_table[KC_m LunaKey_right, // [1e] LunaKey_down, // [1f] - NoKey, // [20] - NoKey, // [21] + LunaKey_INSERT, // [20] + LunaKey_COPY, // [21] LunaKey_1, // [22] LunaKey_2, // [23] LunaKey_3, // [24] @@ -527,8 +535,8 @@ LunaKeyboard::keycode2lunakey_table[KC_m LunaKey_backslash, // [2e] LunaKey_buzzer, // [2f] - NoKey, // [30] - NoKey, // [31] + LunaKey_CUT, // [30] + LunaKey_PASTE, // [31] LunaKey_Q, // [32] LunaKey_W, // [33] LunaKey_E, // [34] @@ -578,7 +586,7 @@ LunaKeyboard::keycode2lunakey_table[KC_m NoKey, // [5e] NoKey, // [5f] - NoKey, // [60] + LunaKey_PAD_HOME, // [60] LunaKey_PAD_plus, // [61] LunaKey_PAD_minus, // [62] LunaKey_PAD_7, // [63]