--- nono/vm/lunakbd.cpp 2026/04/29 17:04:29 1.1.1.2 +++ nono/vm/lunakbd.cpp 2026/04/29 17:04:36 1.1.1.4 @@ -1,6 +1,7 @@ // // nono -// Copyright (C) 2018 isaki@NetBSD.org +// Copyright (C) 2020 nono project +// Licensed under nono-license.txt // // キーボードとマウス @@ -23,6 +24,7 @@ LunaKeyboard::LunaKeyboard() monitor.Init(30, 1); memset(reptable, 0, sizeof(reptable)); + led.resize(2); key_event.dev = this; key_event.func = (DeviceCallback_t)&LunaKeyboard::KeyboardCallback; @@ -54,7 +56,7 @@ void LunaKeyboard::ResetHard() { // マウスサンプリングは電源オン時は有効らしい - gScheduler->AddEvent(&mouse_event[0]); + mouse_event[0].Start(); } // モニター @@ -83,6 +85,19 @@ LunaKeyboard::MonitorUpdate() return true; } +// LUNA キーコードから LED 番号を返す。LED キーでなければ -1 を返す。 +int +LunaKeyboard::LunaKey2LED(uint lunakey) const +{ + // 2つしかないのでこのくらいでいいか + if (lunakey == LunaKey_kana) + return 0; + if (lunakey == LunaKey_CAPS) + return 1; + + return -1; +} + // キーを押した void LunaKeyboard::MakeKey(uint keycode) @@ -102,11 +117,18 @@ LunaKeyboard::MakeKey(uint keycode) return; } + // LED はトグル? + int n = LunaKey2LED(lunakey); + if (n >= 0) { + led[n] = !led[n]; + } + // キーが押された putlog(1, "MakeKey %d(%s)", lunakey, keyname[lunakey]); reptable[lunakey] = 1; // イベントを登録 + // (LED キーの自動 Break はイベントコールバック側で処理する) SetKeyEvent(lunakey); } @@ -124,6 +146,18 @@ LunaKeyboard::BreakKey(uint keycode) return; } + // LED キーはここでは処理しない (MakeKey() で処理してある) + if (LunaKey2LED(lunakey) >= 0) { + return; + } + + BreakKeyCommon(lunakey); +} + +// キーを離した (通常キーと LED キーの場合の両方から呼ばれる) +void +LunaKeyboard::BreakKeyCommon(uint lunakey) +{ // キーが離された putlog(2, "BreakKey %d(%s)", lunakey, keyname[lunakey]); reptable[lunakey] = 0; @@ -159,7 +193,7 @@ LunaKeyboard::SetKeyEvent(uint code) key_sending = true; key_event.time = target - now; key_event.code = code; - gScheduler->AddEvent(&key_event); + key_event.Start(); } } @@ -184,6 +218,11 @@ LunaKeyboard::KeyboardCallback(int code) { gSIO->Rx(1, code); key_sending = false; + + // かなと CAP キーの押下なら、続けてキーの復旧も送る。 + if (LunaKey2LED(code) >= 0) { + BreakKeyCommon(code); + } } // マウスサンプリングコールバック @@ -211,6 +250,12 @@ LunaKeyboard::MouseSamplingCallback(int mouse_l != prev_l || mouse_m != prev_m) { + putlog(2, "Mouse Sampling x=%d y=%d %c%c%c", + mouse_x, mouse_y, + (mouse_r ? 'L' : '-'), + (mouse_m ? 'M' : '-'), + (mouse_l ? 'R' : '-')); + // 1バイト目、ボタン状態。 // mouse_[rlm] 変数は押し下げが true、LUNA のマウスは押し下げが %0 uint8 b = 0x80 | @@ -236,12 +281,14 @@ LunaKeyboard::MouseSamplingCallback(int // 2バイト目は 2msec 秒後に予約 mouse_event[1].time = 2_msec; mouse_event[1].code = (uint8)mouse_x; - gScheduler->AddEvent(&mouse_event[1]); + mouse_event[1].Start(); // 3バイト目は 4msec 秒後に予約 mouse_event[2].time = 4_msec; mouse_event[2].code = (uint8)mouse_y; - gScheduler->AddEvent(&mouse_event[2]); + mouse_event[2].Start(); + } else { + putlog(3, "Mouse Sampling inactive"); } // 積算リセット @@ -253,7 +300,7 @@ LunaKeyboard::MouseSamplingCallback(int // 20msec 後に再び自分を呼び出す mouse_event[0].time = 20_msec; - gScheduler->AddEvent(&mouse_event[0]); + mouse_event[0].Start(); } // マウスの後続バイトを送出するイベントコールバック @@ -263,6 +310,12 @@ LunaKeyboard::MouseCallback(int code) gSIO->Rx(1, code); } +// ホストからの制御 +void +LunaKeyboard::Command(uint32 data) +{ +} + // 共通キーコードを LUNA キーコードに変換して返す。 // LUNA キーがなければ NoKey を返す。 uint