--- nono/vm/lunakbd.cpp 2026/04/29 17:04:36 1.1.1.4 +++ nono/vm/lunakbd.cpp 2026/04/29 17:04:50 1.1.1.8 @@ -15,13 +15,12 @@ // ということにする。 #include "lunakbd.h" -#include "mystring.h" #include "sio.h" // コンストラクタ LunaKeyboard::LunaKeyboard() { - monitor.Init(30, 1); + monitor_size = nnSize(30, 1); memset(reptable, 0, sizeof(reptable)); led.resize(2); @@ -41,7 +40,7 @@ LunaKeyboard::LunaKeyboard() for (int i = 1; i < 3; i++) { mouse_event[i].dev = this; mouse_event[i].func = (DeviceCallback_t)&LunaKeyboard::MouseCallback; - mouse_event[i].time = 0; + mouse_event[i].time = 2_msec * i; mouse_event[i].SetName(string_format("Mouse Slot%d", i)); } } @@ -55,13 +54,19 @@ LunaKeyboard::~LunaKeyboard() void LunaKeyboard::ResetHard() { - // マウスサンプリングは電源オン時は有効らしい + // 動作中のタイマーは一旦とめる + key_event.Stop(); + for (int i = 0; i < countof(mouse_event); i++) { + mouse_event[i].Stop(); + } + + // で、マウスサンプリングは電源オン時から有効らしい mouse_event[0].Start(); } // モニター -bool -LunaKeyboard::MonitorUpdate() +void +LunaKeyboard::MonitorUpdate(TextScreen& monitor) { int x, y; monitor.Clear(); @@ -81,8 +86,6 @@ LunaKeyboard::MonitorUpdate() (mouse_l ? 'L' : '-'), (mouse_m ? 'M' : '-'), (mouse_r ? 'R' : '-')); - - return true; } // LUNA キーコードから LED 番号を返す。LED キーでなければ -1 を返す。 @@ -170,7 +173,7 @@ LunaKeyboard::BreakKeyCommon(uint lunake void LunaKeyboard::SetKeyEvent(uint code) { - uint64 now = gScheduler->GetVirtTime(); + uint64 now = gMPU->GetVirtTime(); // t は現在の仮想時刻に対応するスロット uint64 t = (now / 2_msec) % 10; @@ -214,8 +217,10 @@ LunaKeyboard::MouseInput(int x, int y, b // キー入力コールバック // SIO に送信するタイミングで呼ばれる。 void -LunaKeyboard::KeyboardCallback(int code) +LunaKeyboard::KeyboardCallback(Event& ev) { + int& code = ev.code; + gSIO->Rx(1, code); key_sending = false; @@ -228,7 +233,7 @@ LunaKeyboard::KeyboardCallback(int code) // マウスサンプリングコールバック // 20msec ごとに呼ばれる。 void -LunaKeyboard::MouseSamplingCallback(int arg) +LunaKeyboard::MouseSamplingCallback(Event& ev) { int reset_x = 0; int reset_y = 0; @@ -278,13 +283,11 @@ LunaKeyboard::MouseSamplingCallback(int // 1バイト目はここで送信 gSIO->Rx(1, b); - // 2バイト目は 2msec 秒後に予約 - mouse_event[1].time = 2_msec; + // 2バイト目は 2msec 秒後に送信 mouse_event[1].code = (uint8)mouse_x; mouse_event[1].Start(); - // 3バイト目は 4msec 秒後に予約 - mouse_event[2].time = 4_msec; + // 3バイト目は 4msec 秒後に送信 mouse_event[2].code = (uint8)mouse_y; mouse_event[2].Start(); } else { @@ -299,15 +302,14 @@ LunaKeyboard::MouseSamplingCallback(int prev_m = mouse_m; // 20msec 後に再び自分を呼び出す - mouse_event[0].time = 20_msec; - mouse_event[0].Start(); + ev.Start(); } // マウスの後続バイトを送出するイベントコールバック void -LunaKeyboard::MouseCallback(int code) +LunaKeyboard::MouseCallback(Event& ev) { - gSIO->Rx(1, code); + gSIO->Rx(1, ev.code); } // ホストからの制御