Skip to content

Commit

Permalink
ADD: Support keyboard
Browse files Browse the repository at this point in the history
* bochs input kbd
* toggle scaling window
  • Loading branch information
bajdcc committed Feb 2, 2018
1 parent d8a1d43 commit ecf8091
Show file tree
Hide file tree
Showing 16 changed files with 389 additions and 30 deletions.
282 changes: 279 additions & 3 deletions CCGameFramework/base/bochs/gui/d2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "gui.h"
#include "../bochs.h"
#include "../plugin.h"
#include "../iodev/iodev.h"
#include "render/Direct2DRender.h"

static unsigned prev_cursor_x = 0;
Expand All @@ -15,9 +16,274 @@ static Bit8u h_panning = 0, v_panning = 0;
static Bit16u line_compare = 1023;
static RGBQUAD cmap_index[259];

std::threadsafe_queue<Bit32u> bx_d2d_gui_c::kbd_events;

static bx_d2d_gui_c *theGui = NULL;
IMPLEMENT_GUI_PLUGIN_CODE(d2d)

Bit32u win32_to_bx_key[2][0x100] =
{
{ /* normal-keys */
/* 0x00 - 0x0f */
0,
BX_KEY_ESC,
BX_KEY_1,
BX_KEY_2,
BX_KEY_3,
BX_KEY_4,
BX_KEY_5,
BX_KEY_6,
BX_KEY_7,
BX_KEY_8,
BX_KEY_9,
BX_KEY_0,
BX_KEY_MINUS,
BX_KEY_EQUALS,
BX_KEY_BACKSPACE,
BX_KEY_TAB,
/* 0x10 - 0x1f */
BX_KEY_Q,
BX_KEY_W,
BX_KEY_E,
BX_KEY_R,
BX_KEY_T,
BX_KEY_Y,
BX_KEY_U,
BX_KEY_I,
BX_KEY_O,
BX_KEY_P,
BX_KEY_LEFT_BRACKET,
BX_KEY_RIGHT_BRACKET,
BX_KEY_ENTER,
BX_KEY_CTRL_L,
BX_KEY_A,
BX_KEY_S,
/* 0x20 - 0x2f */
BX_KEY_D,
BX_KEY_F,
BX_KEY_G,
BX_KEY_H,
BX_KEY_J,
BX_KEY_K,
BX_KEY_L,
BX_KEY_SEMICOLON,
BX_KEY_SINGLE_QUOTE,
BX_KEY_GRAVE,
BX_KEY_SHIFT_L,
BX_KEY_BACKSLASH,
BX_KEY_Z,
BX_KEY_X,
BX_KEY_C,
BX_KEY_V,
/* 0x30 - 0x3f */
BX_KEY_B,
BX_KEY_N,
BX_KEY_M,
BX_KEY_COMMA,
BX_KEY_PERIOD,
BX_KEY_SLASH,
BX_KEY_SHIFT_R,
BX_KEY_KP_MULTIPLY,
BX_KEY_ALT_L,
BX_KEY_SPACE,
BX_KEY_CAPS_LOCK,
BX_KEY_F1,
BX_KEY_F2,
BX_KEY_F3,
BX_KEY_F4,
BX_KEY_F5,
/* 0x40 - 0x4f */
BX_KEY_F6,
BX_KEY_F7,
BX_KEY_F8,
BX_KEY_F9,
BX_KEY_F10,
BX_KEY_PAUSE,
BX_KEY_SCRL_LOCK,
BX_KEY_KP_HOME,
BX_KEY_KP_UP,
BX_KEY_KP_PAGE_UP,
BX_KEY_KP_SUBTRACT,
BX_KEY_KP_LEFT,
BX_KEY_KP_5,
BX_KEY_KP_RIGHT,
BX_KEY_KP_ADD,
BX_KEY_KP_END,
/* 0x50 - 0x5f */
BX_KEY_KP_DOWN,
BX_KEY_KP_PAGE_DOWN,
BX_KEY_KP_INSERT,
BX_KEY_KP_DELETE,
0,
0,
BX_KEY_LEFT_BACKSLASH,
BX_KEY_F11,
BX_KEY_F12,
0,
0,
0,
0,
0,
0,
0,
/* 0x60 - 0x6f */
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
/* 0x70 - 0x7f */
0, /* Todo: "Katakana" key (ibm 133) for Japanese 106 keyboard */
0,
0,
0, /* Todo: "Ro" key (ibm 56) for Japanese 106 keyboard */
0,
0,
0,
0,
0,
0, /* Todo: "convert" key (ibm 132) for Japanese 106 keyboard */
0,
0, /* Todo: "non-convert" key (ibm 131) for Japanese 106 keyboard */
0,
0, /* Todo: "Yen" key (ibm 14) for Japanese 106 keyboard */
0,
0,
},
{ /* extended-keys */
/* 0x00 - 0x0f */
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
/* 0x10 - 0x1f */
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
BX_KEY_KP_ENTER,
BX_KEY_CTRL_R,
0,
0,
/* 0x20 - 0x2f */
0,
BX_KEY_POWER_CALC,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
/* 0x30 - 0x3f */
0,
0,
BX_KEY_INT_HOME,
0,
0,
BX_KEY_KP_DIVIDE,
0,
BX_KEY_PRINT,
BX_KEY_ALT_R,
0,
0,
0,
0,
0,
0,
0,
/* 0x40 - 0x4f */
0,
0,
0,
0,
0,
BX_KEY_NUM_LOCK,
BX_KEY_CTRL_BREAK,
BX_KEY_HOME,
BX_KEY_UP,
BX_KEY_PAGE_UP,
0,
BX_KEY_LEFT,
0,
BX_KEY_RIGHT,
0,
BX_KEY_END,
/* 0x50 - 0x5f */
BX_KEY_DOWN,
BX_KEY_PAGE_DOWN,
BX_KEY_INSERT,
BX_KEY_DELETE,
0,
0,
0,
0,
0,
0,
0,
BX_KEY_WIN_L,
BX_KEY_WIN_R,
BX_KEY_MENU,
BX_KEY_POWER_POWER,
BX_KEY_POWER_SLEEP,
/* 0x60 - 0x6f */
0,
0,
0,
BX_KEY_POWER_WAKE,
0,
BX_KEY_INT_SEARCH,
BX_KEY_INT_FAV,
0,
BX_KEY_INT_STOP,
BX_KEY_INT_FORWARD,
BX_KEY_INT_BACK,
BX_KEY_POWER_MYCOMP,
BX_KEY_INT_MAIL,
0,
0,
0,
}
};

bx_d2d_gui_c::bx_d2d_gui_c()
{
buffer = X86WindowElementRenderer::GetBuffer();
Expand Down Expand Up @@ -287,6 +553,13 @@ void bx_d2d_gui_c::graphics_tile_update(Bit8u* tile, unsigned x, unsigned y)

void bx_d2d_gui_c::handle_events()
{
Bit32u key, key_event;
while (GetKeyboardEvent(key))
{
key_event = win32_to_bx_key[(key & 0x100) ? 1 : 0][key & 0xff];
if (key & BX_KEY_RELEASED) key_event |= BX_KEY_RELEASED;
DEV_kbd_gen_scancode(key_event);
}
}

void bx_d2d_gui_c::flush()
Expand Down Expand Up @@ -370,8 +643,11 @@ void bx_d2d_gui_c::set_mouse_mode_absxy(bx_bool mode)
{
}

#if BX_SHOW_IPS
void bx_d2d_gui_c::show_ips(Bit32u ips_count)
void bx_d2d_gui_c::AddKeyboardEvent(Bit32u evt)
{
kbd_events.push(evt);
}
#endif
BOOL bx_d2d_gui_c::GetKeyboardEvent(Bit32u &evt)
{
return kbd_events.try_pop(evt);
}
11 changes: 8 additions & 3 deletions CCGameFramework/base/bochs/gui/d2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define GUI_D2D_H

#include "../bochs.h"
#include "base/utils.h"
#include "ui/gdi/Gdi.h"

class bx_d2d_gui_c : public bx_gui_c {
Expand All @@ -12,13 +13,17 @@ class bx_d2d_gui_c : public bx_gui_c {
virtual void get_capabilities(Bit16u *xres, Bit16u *yres, Bit16u *bpp);
virtual void set_tooltip(unsigned hbar_id, const char *tip);
virtual void set_mouse_mode_absxy(bx_bool mode);
#if BX_SHOW_IPS
virtual void show_ips(Bit32u ips_count);
#endif
private:
BYTE * buffer{ nullptr };
CSize size;
BOOL error{ FALSE };

public:
static void AddKeyboardEvent(Bit32u);
static BOOL GetKeyboardEvent(Bit32u&);

private:
static std::threadsafe_queue<Bit32u> kbd_events;
};

#endif
6 changes: 3 additions & 3 deletions CCGameFramework/base/bochs/iodev/iodev.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
#ifndef IODEV_H
#define IODEV_H

#include "bochs.h"
#include "plugin.h"
#include "param_names.h"
#include "../bochs.h"
#include "../plugin.h"
#include "../param_names.h"

/* number of IRQ lines supported. In an ISA PC there are two
PIC chips cascaded together. each has 8 IRQ lines, so there
Expand Down
Loading

0 comments on commit ecf8091

Please sign in to comment.