struct dcpu16_hw *hw = (struct dcpu16_hw *)cl->screen->screenData;
struct keyboard_ *keyboard = (struct keyboard_ *)hw->data;
- keysym_rfbtodcpu(key, &dcpu_key);
+ hw->vm->trace_cb_("%s>> down:%u rfb_key:0x%04x", down, key);
- fprintf(stderr, "%s: down:%u key:0x%04x dcpu_key:0x%04x\n",
- __func__,
- down,
- key,
- dcpu_key);
-
- fprintf(stderr, "%s: hw:%p name:%s vm:%p\n",
- __func__,
- VOIDP(hw),
- hw->name_,
- VOIDP(hw->vm));
+ if (keysym_rfbtodcpu(key, &dcpu_key)) {
+ /* unhandled key event */
+ return;
+ }
keyboard->keys_pressed[dcpu_key] = (down ? 1 : 0);
if (down) {
dcpu16_interrupt(hw->vm, keyboard->interrupt_message);
}
}
-
-void keyboard_vnc_associate(struct dcpu16_hw *hw, rfbScreenInfoPtr rfbScreen) {
- rfbScreen->screenData = hw;
- rfbScreen->kbdAddEvent = keyboard_rfbevent_;
-}
#endif /* HAVE_LIBVNCSERVER */
static
(void)vm;
keyboard->interrupt_message = 0;
- memset(keyboard->buf, 0, keyboard->buf_sz);
+ keyboard->buf_head = 0;
+ keyboard->buf_tail = 0;
+ memset(keyboard->keys_pressed, 0, sizeof keyboard->keys_pressed);
}
static
}
}
-static struct dcpu16_hw hw_ = {
- .vm = NULL,
+static struct dcpu16_hw_ctl_cmd ctl_[] = {
+ { "buffer_size", "const size_t *", "size_t *", "get or set current buffer size" },
+ { "associate_rfbScreen", "rfbScreenInfoPtr", "NULL", "associates this keyboard instance with an rfb display" },
+ { NULL, NULL, NULL, NULL }
+};
+static
+int keyboard_data_ctl_(struct dcpu16_hw *hw, const char *cmd, void *data_in, void *data_out) {
+ if (strcmp(cmd, "buffer_size") == 0) {
+ struct keyboard_ *keyboard = (struct keyboard_ *)hw->data;
+ void *tmp_ptr;
+ const size_t *buf_sz_in = (const size_t *)data_in;
+ size_t *buf_sz_out = (size_t *)data_out;
+
+ if (buf_sz_out) {
+ *buf_sz_out = keyboard->buf_sz;
+ }
+
+ if (buf_sz_in) {
+ hw->vm->trace_cb_("%s>> resizing buffer from %zu to %zu", __func__, keyboard->buf_sz, *buf_sz_in);
+
+ tmp_ptr = realloc(keyboard->buf, *buf_sz_in);
+ if (tmp_ptr == NULL) {
+ hw->vm->warn_cb_("%s():%s", "realloc", strerror(errno));
+ return -1;
+ }
+ keyboard->buf = tmp_ptr;
+ keyboard->buf_sz = *buf_sz_in;
+ keyboard->buf_head = keyboard->buf_tail = 0;
+ }
+
+ return 0;
+ }
+
+#ifdef HAVE_LIBVNCSERVER
+ if (strcmp(cmd, "associate_rfbScreen") == 0) {
+ rfbScreenInfoPtr rfbScreen = (rfbScreenInfoPtr)data_in;
+ (void)data_out;
+
+ if (rfbScreen == NULL)
+ return -EFAULT;
+
+ rfbScreen->screenData = hw;
+ rfbScreen->kbdAddEvent = keyboard_rfbevent_;
+
+ return 0;
+ }
+#endif /* HAVE_LIBVNCSERVER */
+
+ return -EINVAL;
+}
+
+
+struct dcpu16_hw_module dcpu16_hw_module_keyboard = {
.name_ = "Generic Keyboard (compatible)",
+
.id_l = 0x7406,
.id_h = 0x30cf,
.ver = 0x0001,
.hwi = keyboard_hwi_,
.cycle = keyboard_cycle_,
.reset = keyboard_reset_,
- .data = (struct keyboard_ *)NULL
-};
-struct dcpu16_hw_module dcpu16_hw_module_keyboard = {
- .template = &hw_,
.data_init = keyboard_data_init_,
.data_free = keyboard_data_free_,
+ .ctl = keyboard_data_ctl_,
+ .ctl_cmd = ctl_,
};