Cleaning up the "keyboard" module. Also general fixups here and there, and cleanups of earlier cleanups.
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
*
|
||||
* The Emulator's Windows core.
|
||||
*
|
||||
* Version: @(#)win.c 1.0.28 2017/10/22
|
||||
* Version: @(#)win.c 1.0.29 2017/10/24
|
||||
*
|
||||
* Authors: Sarah Walker, <http://pcem-emulator.co.uk/>
|
||||
* Miran Grca, <mgrca8@gmail.com>
|
||||
@@ -43,6 +43,7 @@
|
||||
#include "../device.h"
|
||||
#include "../nvr.h"
|
||||
#include "../mouse.h"
|
||||
#include "../keyboard.h"
|
||||
#include "../cdrom/cdrom.h"
|
||||
#include "../cdrom/cdrom_image.h"
|
||||
#include "../cdrom/cdrom_null.h"
|
||||
@@ -54,7 +55,6 @@
|
||||
#include "../sound/sound.h"
|
||||
#define GLOBAL
|
||||
#include "../plat.h"
|
||||
#include "../plat_keyboard.h"
|
||||
#include "../plat_mouse.h"
|
||||
#include "../plat_midi.h"
|
||||
#include "../ui.h"
|
||||
@@ -62,7 +62,7 @@
|
||||
#include "win_d3d.h"
|
||||
|
||||
|
||||
#define TIMER_1SEC 1
|
||||
#define TIMER_1SEC 1 /* ID of the one-second timer */
|
||||
|
||||
|
||||
typedef struct {
|
||||
@@ -81,7 +81,6 @@ LCID lang_id; /* current language ID used */
|
||||
DWORD dwSubLangID;
|
||||
RECT oldclip; /* mouse rect */
|
||||
int infocus = 1;
|
||||
int recv_key[272]; /* keyboard input buffer */
|
||||
|
||||
char openfilestring[260];
|
||||
WCHAR wopenfilestring[260];
|
||||
@@ -180,7 +179,6 @@ ResetAllMenus(void)
|
||||
CheckMenuItem(menuMain, IDM_LOG_SERIAL, MF_UNCHECKED);
|
||||
# endif
|
||||
# ifdef ENABLE_NIC_LOG
|
||||
/*FIXME: should be network_setlog(1:0) */
|
||||
CheckMenuItem(menuMain, IDM_LOG_NIC, MF_UNCHECKED);
|
||||
# endif
|
||||
#endif
|
||||
@@ -392,9 +390,9 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
#ifdef USE_RDP
|
||||
case IDM_VID_RDP:
|
||||
#endif
|
||||
CheckMenuItem(hmenu, IDM_VID_DDRAW + vid_api, MF_UNCHECKED);
|
||||
CheckMenuItem(hmenu, IDM_VID_DDRAW+vid_api, MF_UNCHECKED);
|
||||
plat_setvid(LOWORD(wParam) - IDM_VID_DDRAW);
|
||||
CheckMenuItem(hmenu, IDM_VID_DDRAW + vid_api, MF_CHECKED);
|
||||
CheckMenuItem(hmenu, IDM_VID_DDRAW+vid_api, MF_CHECKED);
|
||||
config_save();
|
||||
break;
|
||||
|
||||
@@ -407,9 +405,9 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
case IDM_VID_FS_43:
|
||||
case IDM_VID_FS_SQ:
|
||||
case IDM_VID_FS_INT:
|
||||
CheckMenuItem(hmenu, IDM_VID_FS_FULL + video_fullscreen_scale, MF_UNCHECKED);
|
||||
CheckMenuItem(hmenu, IDM_VID_FS_FULL+video_fullscreen_scale, MF_UNCHECKED);
|
||||
video_fullscreen_scale = LOWORD(wParam) - IDM_VID_FS_FULL;
|
||||
CheckMenuItem(hmenu, IDM_VID_FS_FULL + video_fullscreen_scale, MF_CHECKED);
|
||||
CheckMenuItem(hmenu, IDM_VID_FS_FULL+video_fullscreen_scale, MF_CHECKED);
|
||||
device_force_redraw();
|
||||
config_save();
|
||||
break;
|
||||
@@ -418,9 +416,9 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
case IDM_VID_SCALE_2X:
|
||||
case IDM_VID_SCALE_3X:
|
||||
case IDM_VID_SCALE_4X:
|
||||
CheckMenuItem(hmenu, IDM_VID_SCALE_1X + scale, MF_UNCHECKED);
|
||||
CheckMenuItem(hmenu, IDM_VID_SCALE_1X+scale, MF_UNCHECKED);
|
||||
scale = LOWORD(wParam) - IDM_VID_SCALE_1X;
|
||||
CheckMenuItem(hmenu, IDM_VID_SCALE_1X + scale, MF_CHECKED);
|
||||
CheckMenuItem(hmenu, IDM_VID_SCALE_1X+scale, MF_CHECKED);
|
||||
device_force_redraw();
|
||||
video_force_resize_set(1);
|
||||
config_save();
|
||||
@@ -451,9 +449,9 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
case IDM_VID_GRAYCT_601:
|
||||
case IDM_VID_GRAYCT_709:
|
||||
case IDM_VID_GRAYCT_AVE:
|
||||
CheckMenuItem(hmenu, IDM_VID_GRAYCT_601 + video_graytype, MF_UNCHECKED);
|
||||
CheckMenuItem(hmenu, IDM_VID_GRAYCT_601+video_graytype, MF_UNCHECKED);
|
||||
video_graytype = LOWORD(wParam) - IDM_VID_GRAYCT_601;
|
||||
CheckMenuItem(hmenu, IDM_VID_GRAYCT_601 + video_graytype, MF_CHECKED);
|
||||
CheckMenuItem(hmenu, IDM_VID_GRAYCT_601+video_graytype, MF_CHECKED);
|
||||
device_force_redraw();
|
||||
config_save();
|
||||
break;
|
||||
@@ -463,9 +461,9 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
case IDM_VID_GRAY_AMBER:
|
||||
case IDM_VID_GRAY_GREEN:
|
||||
case IDM_VID_GRAY_WHITE:
|
||||
CheckMenuItem(hmenu, IDM_VID_GRAY_RGB + video_grayscale, MF_UNCHECKED);
|
||||
CheckMenuItem(hmenu, IDM_VID_GRAY_RGB+video_grayscale, MF_UNCHECKED);
|
||||
video_grayscale = LOWORD(wParam) - IDM_VID_GRAY_RGB;
|
||||
CheckMenuItem(hmenu, IDM_VID_GRAY_RGB + video_grayscale, MF_CHECKED);
|
||||
CheckMenuItem(hmenu, IDM_VID_GRAY_RGB+video_grayscale, MF_CHECKED);
|
||||
device_force_redraw();
|
||||
config_save();
|
||||
break;
|
||||
@@ -592,7 +590,7 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
return(0);
|
||||
|
||||
case WM_INPUT:
|
||||
process_raw_input(lParam, infocus);
|
||||
keyboard_handle(lParam, infocus);
|
||||
break;
|
||||
|
||||
case WM_SETFOCUS:
|
||||
@@ -609,7 +607,6 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
case WM_KILLFOCUS:
|
||||
infocus = 0;
|
||||
releasemouse();
|
||||
memset(recv_key, 0, sizeof(recv_key));
|
||||
if (video_fullscreen)
|
||||
leave_fullscreen_flag = 1;
|
||||
if (hook_enabled) {
|
||||
@@ -1001,7 +998,6 @@ WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpszArg, int nFunsterStil)
|
||||
}
|
||||
|
||||
/* Initialize the input (keyboard, mouse, game) module. */
|
||||
memset(recv_key, 0x00, sizeof(recv_key));
|
||||
device.usUsagePage = 0x01;
|
||||
device.usUsage = 0x06;
|
||||
device.dwFlags = RIDEV_NOHOTKEYS;
|
||||
@@ -1013,7 +1009,7 @@ WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpszArg, int nFunsterStil)
|
||||
MB_OK | MB_ICONERROR);
|
||||
return(4);
|
||||
}
|
||||
get_registry_key_map();
|
||||
keyboard_getkeymap();
|
||||
|
||||
/* Create the status bar window. */
|
||||
StatusBarCreate(hwndMain, IDC_STATUS, hinstance);
|
||||
@@ -1038,21 +1034,9 @@ WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpszArg, int nFunsterStil)
|
||||
return(5);
|
||||
}
|
||||
|
||||
#if 0
|
||||
/* Initialize the rendering window, or fullscreen. */
|
||||
if (start_in_fullscreen) {
|
||||
startblit();
|
||||
vid_apis[0][vid_api].close();
|
||||
video_fullscreen = 1;
|
||||
vid_apis[1][vid_api].init(hwndRender);
|
||||
leave_fullscreen_flag = 0;
|
||||
endblit();
|
||||
device_force_redraw();
|
||||
}
|
||||
#endif
|
||||
if (start_in_fullscreen) {
|
||||
if (start_in_fullscreen)
|
||||
plat_setfullscreen(1);
|
||||
}
|
||||
|
||||
/* Set up the current window size. */
|
||||
plat_resize(scrnsz_x, scrnsz_y);
|
||||
@@ -1073,9 +1057,6 @@ WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpszArg, int nFunsterStil)
|
||||
/* Set the PAUSE mode depending on the renderer. */
|
||||
plat_pause(0);
|
||||
|
||||
/* Initialize raw keyboard input buffer. */
|
||||
memset(recv_key, 0x00, sizeof(recv_key));
|
||||
|
||||
/*
|
||||
* Everything has been configured, and all seems to work,
|
||||
* so now it is time to start the main thread to do some
|
||||
@@ -1103,16 +1084,13 @@ WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpszArg, int nFunsterStil)
|
||||
DispatchMessage(&messages);
|
||||
}
|
||||
|
||||
if (mouse_capture && recv_key[0x58] && recv_key[0x42]) {
|
||||
if (mouse_capture && keyboard_ismsexit()) {
|
||||
ClipCursor(&oldclip);
|
||||
ShowCursor(TRUE);
|
||||
mouse_capture = 0;
|
||||
}
|
||||
|
||||
if (video_fullscreen &&
|
||||
(recv_key[0x1D] || recv_key[0x9D]) &&
|
||||
(recv_key[0x38] || recv_key[0xB8]) &&
|
||||
(recv_key[0x51] || recv_key[0xD1])) {
|
||||
if (video_fullscreen && keyboard_isfsexit()) {
|
||||
/* Signal "exit fullscreen mode". */
|
||||
plat_setfullscreen(0);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
* Platform support defintions for Win32.
|
||||
*
|
||||
* Version: @(#)win.h 1.0.7 2017/10/19
|
||||
* Version: @(#)win.h 1.0.8 2017/10/24
|
||||
*
|
||||
* Authors: Sarah Walker, <http://pcem-emulator.co.uk/>
|
||||
* Miran Grca, <mgrca8@gmail.com>
|
||||
@@ -56,8 +56,6 @@ extern LCID lang_id;
|
||||
extern HICON hIcon[512];
|
||||
|
||||
extern int status_is_open;
|
||||
extern int mousecapture;
|
||||
extern int recv_key[272];
|
||||
|
||||
extern char openfilestring[260];
|
||||
extern WCHAR wopenfilestring[260];
|
||||
@@ -77,6 +75,11 @@ extern void do_stop(void);
|
||||
extern void set_language(int id);
|
||||
extern int get_vidpause(void);
|
||||
|
||||
extern void keyboard_getkeymap(void);
|
||||
extern void keyboard_handle(LPARAM lParam, int infocus);
|
||||
|
||||
extern int fdd_type_to_icon(int type);
|
||||
|
||||
#ifdef EMU_DEVICE_H
|
||||
extern uint8_t deviceconfig_open(HWND hwnd, device_t *device);
|
||||
#endif
|
||||
@@ -90,11 +93,6 @@ extern void win_settings_open(HWND hwnd);
|
||||
extern void hard_disk_add_open(HWND hwnd, int is_existing);
|
||||
extern int hard_disk_was_added(void);
|
||||
|
||||
extern void get_registry_key_map(void);
|
||||
extern void process_raw_input(LPARAM lParam, int infocus);
|
||||
|
||||
extern int fdd_type_to_icon(int type);
|
||||
|
||||
|
||||
/* Functions in win_about.c: */
|
||||
extern void AboutDialogCreate(HWND hwnd);
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
see COPYING for more details
|
||||
*/
|
||||
#include <stdint.h>
|
||||
#include "../86box.h"
|
||||
#include "../device.h"
|
||||
#include "../video/video.h"
|
||||
#include "win_ddraw.h"
|
||||
|
||||
@@ -17,114 +19,9 @@ static HWND ddraw_hwnd;
|
||||
static int ddraw_w, ddraw_h;
|
||||
|
||||
|
||||
extern "C" void fatal(const char *format, ...);
|
||||
extern "C" void pclog(const char *format, ...);
|
||||
|
||||
extern "C" void device_force_redraw(void);
|
||||
|
||||
extern "C" int ddraw_fs_init(HWND h);
|
||||
extern "C" void ddraw_fs_close(void);
|
||||
extern "C" int ddraw_fs_pause(void);
|
||||
extern "C" void ddraw_fs_take_screenshot(wchar_t *fn);
|
||||
|
||||
extern void ddraw_common_take_screenshot(wchar_t *fn, IDirectDrawSurface7 *pDDSurface);
|
||||
|
||||
|
||||
static void blit_memtoscreen(int, int, int, int, int, int);
|
||||
|
||||
|
||||
int ddraw_fs_init(HWND h)
|
||||
{
|
||||
ddraw_w = GetSystemMetrics(SM_CXSCREEN);
|
||||
ddraw_h = GetSystemMetrics(SM_CYSCREEN);
|
||||
|
||||
cgapal_rebuild();
|
||||
|
||||
if (FAILED(DirectDrawCreate(NULL, &lpdd, NULL)))
|
||||
return 0;
|
||||
|
||||
if (FAILED(lpdd->QueryInterface(IID_IDirectDraw7, (LPVOID *)&lpdd7)))
|
||||
return 0;
|
||||
|
||||
lpdd->Release();
|
||||
lpdd = NULL;
|
||||
|
||||
atexit(ddraw_fs_close);
|
||||
|
||||
if (FAILED(lpdd7->SetCooperativeLevel(h, DDSCL_SETFOCUSWINDOW |
|
||||
DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_ALLOWREBOOT)))
|
||||
return 0;
|
||||
|
||||
if (FAILED(lpdd7->SetDisplayMode(ddraw_w, ddraw_h, 32, 0 ,0)))
|
||||
return 0;
|
||||
|
||||
memset(&ddsd, 0, sizeof(ddsd));
|
||||
ddsd.dwSize = sizeof(ddsd);
|
||||
|
||||
ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
|
||||
ddsd.dwBackBufferCount = 1;
|
||||
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
|
||||
if (FAILED(lpdd7->CreateSurface(&ddsd, &lpdds_pri, NULL)))
|
||||
return 0;
|
||||
|
||||
ddsd.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER;
|
||||
if (FAILED(lpdds_pri->GetAttachedSurface(&ddsd.ddsCaps, &lpdds_back2)))
|
||||
return 0;
|
||||
|
||||
memset(&ddsd, 0, sizeof(ddsd));
|
||||
ddsd.dwSize = sizeof(ddsd);
|
||||
|
||||
ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
|
||||
ddsd.dwWidth = 2048;
|
||||
ddsd.dwHeight = 2048;
|
||||
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY;
|
||||
if (FAILED(lpdd7->CreateSurface(&ddsd, &lpdds_back, NULL)))
|
||||
{
|
||||
ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
|
||||
ddsd.dwWidth = 2048;
|
||||
ddsd.dwHeight = 2048;
|
||||
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
|
||||
if (FAILED(lpdd7->CreateSurface(&ddsd, &lpdds_back, NULL)))
|
||||
return 0;
|
||||
}
|
||||
|
||||
pclog("DDRAW_INIT complete\n");
|
||||
ddraw_hwnd = h;
|
||||
|
||||
video_setblit(blit_memtoscreen);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ddraw_fs_close(void)
|
||||
{
|
||||
if (lpdds_back2)
|
||||
{
|
||||
lpdds_back2->Release();
|
||||
lpdds_back2 = NULL;
|
||||
}
|
||||
if (lpdds_back)
|
||||
{
|
||||
lpdds_back->Release();
|
||||
lpdds_back = NULL;
|
||||
}
|
||||
if (lpdds_pri)
|
||||
{
|
||||
lpdds_pri->Release();
|
||||
lpdds_pri = NULL;
|
||||
}
|
||||
if (lpdd_clipper)
|
||||
{
|
||||
lpdd_clipper->Release();
|
||||
lpdd_clipper = NULL;
|
||||
}
|
||||
if (lpdd7)
|
||||
{
|
||||
lpdd7->Release();
|
||||
lpdd7 = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void ddraw_fs_size(RECT window_rect, RECT *r_dest, int w, int h)
|
||||
{
|
||||
int ratio_w, ratio_h;
|
||||
@@ -175,6 +72,7 @@ static void ddraw_fs_size(RECT window_rect, RECT *r_dest, int w, int h)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void blit_memtoscreen(int x, int y, int y1, int y2, int w, int h)
|
||||
{
|
||||
RECT r_src;
|
||||
@@ -247,6 +145,98 @@ static void blit_memtoscreen(int x, int y, int y1, int y2, int w, int h)
|
||||
}
|
||||
|
||||
|
||||
int ddraw_fs_init(HWND h)
|
||||
{
|
||||
ddraw_w = GetSystemMetrics(SM_CXSCREEN);
|
||||
ddraw_h = GetSystemMetrics(SM_CYSCREEN);
|
||||
|
||||
cgapal_rebuild();
|
||||
|
||||
if (FAILED(DirectDrawCreate(NULL, &lpdd, NULL)))
|
||||
return 0;
|
||||
|
||||
if (FAILED(lpdd->QueryInterface(IID_IDirectDraw7, (LPVOID *)&lpdd7)))
|
||||
return 0;
|
||||
|
||||
lpdd->Release();
|
||||
lpdd = NULL;
|
||||
|
||||
atexit(ddraw_fs_close);
|
||||
|
||||
if (FAILED(lpdd7->SetCooperativeLevel(h, DDSCL_SETFOCUSWINDOW |
|
||||
DDSCL_CREATEDEVICEWINDOW | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_ALLOWREBOOT)))
|
||||
return 0;
|
||||
|
||||
if (FAILED(lpdd7->SetDisplayMode(ddraw_w, ddraw_h, 32, 0 ,0)))
|
||||
return 0;
|
||||
|
||||
memset(&ddsd, 0, sizeof(ddsd));
|
||||
ddsd.dwSize = sizeof(ddsd);
|
||||
ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
|
||||
ddsd.dwBackBufferCount = 1;
|
||||
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
|
||||
if (FAILED(lpdd7->CreateSurface(&ddsd, &lpdds_pri, NULL)))
|
||||
return 0;
|
||||
|
||||
ddsd.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER;
|
||||
if (FAILED(lpdds_pri->GetAttachedSurface(&ddsd.ddsCaps, &lpdds_back2)))
|
||||
return 0;
|
||||
|
||||
memset(&ddsd, 0, sizeof(ddsd));
|
||||
ddsd.dwSize = sizeof(ddsd);
|
||||
ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
|
||||
ddsd.dwWidth = 2048;
|
||||
ddsd.dwHeight = 2048;
|
||||
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY;
|
||||
if (FAILED(lpdd7->CreateSurface(&ddsd, &lpdds_back, NULL)))
|
||||
{
|
||||
ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
|
||||
ddsd.dwWidth = 2048;
|
||||
ddsd.dwHeight = 2048;
|
||||
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
|
||||
if (FAILED(lpdd7->CreateSurface(&ddsd, &lpdds_back, NULL)))
|
||||
return 0;
|
||||
}
|
||||
|
||||
pclog("DDRAW_INIT complete\n");
|
||||
ddraw_hwnd = h;
|
||||
|
||||
video_setblit(blit_memtoscreen);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
void ddraw_fs_close(void)
|
||||
{
|
||||
if (lpdds_back2)
|
||||
{
|
||||
lpdds_back2->Release();
|
||||
lpdds_back2 = NULL;
|
||||
}
|
||||
if (lpdds_back)
|
||||
{
|
||||
lpdds_back->Release();
|
||||
lpdds_back = NULL;
|
||||
}
|
||||
if (lpdds_pri)
|
||||
{
|
||||
lpdds_pri->Release();
|
||||
lpdds_pri = NULL;
|
||||
}
|
||||
if (lpdd_clipper)
|
||||
{
|
||||
lpdd_clipper->Release();
|
||||
lpdd_clipper = NULL;
|
||||
}
|
||||
if (lpdd7)
|
||||
{
|
||||
lpdd7->Release();
|
||||
lpdd7 = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
ddraw_fs_pause(void)
|
||||
{
|
||||
|
||||
@@ -8,11 +8,11 @@
|
||||
*
|
||||
* Windows raw keyboard input handler.
|
||||
*
|
||||
* Version: @(#)win_keyboard.c 1.0.3 2017/10/16
|
||||
* Version: @(#)win_keyboard.c 1.0.4 2017/10/24
|
||||
*
|
||||
* Author: Miran Grca, <mgrca8@gmail.com>
|
||||
*
|
||||
* Copyright 2016-2017 Miran Grca.
|
||||
* Copyright 2016,2017 Miran Grca.
|
||||
*/
|
||||
#define UNICODE
|
||||
#define _WIN32_WINNT 0x0501
|
||||
@@ -26,182 +26,161 @@
|
||||
#include <stdlib.h>
|
||||
#include "../86box.h"
|
||||
#include "../device.h"
|
||||
#include "../keyboard.h"
|
||||
#include "../plat.h"
|
||||
#include "../plat_keyboard.h"
|
||||
#include "win.h"
|
||||
|
||||
|
||||
#ifndef MAPVK_VK_TO_VSC
|
||||
#define MAPVK_VK_TO_VSC 0
|
||||
#endif
|
||||
|
||||
static uint16_t scancode_map[65536];
|
||||
|
||||
|
||||
/* This is so we can disambiguate scan codes that would otherwise conflict and get
|
||||
passed on incorrectly. */
|
||||
UINT16 convert_scan_code(UINT16 scan_code)
|
||||
static UINT16
|
||||
convert_scan_code(UINT16 scan_code)
|
||||
{
|
||||
switch (scan_code)
|
||||
{
|
||||
case 0xE001:
|
||||
switch (scan_code) {
|
||||
case 0xE001:
|
||||
return 0xF001;
|
||||
case 0xE002:
|
||||
case 0xE002:
|
||||
return 0xF002;
|
||||
case 0xE0AA:
|
||||
case 0xE0AA:
|
||||
return 0xF003;
|
||||
case 0xE005:
|
||||
case 0xE005:
|
||||
return 0xF005;
|
||||
case 0xE006:
|
||||
case 0xE006:
|
||||
return 0xF006;
|
||||
case 0xE007:
|
||||
case 0xE007:
|
||||
return 0xF007;
|
||||
case 0xE071:
|
||||
case 0xE071:
|
||||
return 0xF008;
|
||||
case 0xE072:
|
||||
case 0xE072:
|
||||
return 0xF009;
|
||||
case 0xE07F:
|
||||
case 0xE07F:
|
||||
return 0xF00A;
|
||||
case 0xE0E1:
|
||||
case 0xE0E1:
|
||||
return 0xF00B;
|
||||
case 0xE0EE:
|
||||
case 0xE0EE:
|
||||
return 0xF00C;
|
||||
case 0xE0F1:
|
||||
case 0xE0F1:
|
||||
return 0xF00D;
|
||||
case 0xE0FE:
|
||||
case 0xE0FE:
|
||||
return 0xF00E;
|
||||
case 0xE0EF:
|
||||
case 0xE0EF:
|
||||
return 0xF00F;
|
||||
|
||||
default:
|
||||
default:
|
||||
return scan_code;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void get_registry_key_map()
|
||||
|
||||
void
|
||||
keyboard_getkeymap(void)
|
||||
{
|
||||
WCHAR *keyName = L"SYSTEM\\CurrentControlSet\\Control\\Keyboard Layout";
|
||||
WCHAR *valueName = L"Scancode Map";
|
||||
unsigned char buf[32768];
|
||||
DWORD bufSize;
|
||||
HKEY hKey;
|
||||
int j;
|
||||
UINT32 *bufEx2;
|
||||
int scMapCount;
|
||||
UINT16 *bufEx;
|
||||
int scancode_unmapped;
|
||||
int scancode_mapped;
|
||||
WCHAR *keyName = L"SYSTEM\\CurrentControlSet\\Control\\Keyboard Layout";
|
||||
WCHAR *valueName = L"Scancode Map";
|
||||
unsigned char buf[32768];
|
||||
DWORD bufSize;
|
||||
HKEY hKey;
|
||||
int j;
|
||||
UINT32 *bufEx2;
|
||||
int scMapCount;
|
||||
UINT16 *bufEx;
|
||||
int scancode_unmapped;
|
||||
int scancode_mapped;
|
||||
|
||||
/* First, prepare the default scan code map list which is 1:1.
|
||||
Remappings will be inserted directly into it.
|
||||
65536 bytes so scan codes fit in easily and it's easy to find what each maps too,
|
||||
since each array element is a scan code and provides for E0, etc. ones too. */
|
||||
for (j = 0; j < 65536; j++)
|
||||
scancode_map[j] = convert_scan_code(j);
|
||||
/* First, prepare the default scan code map list which is 1:1.
|
||||
* Remappings will be inserted directly into it.
|
||||
* 65536 bytes so scan codes fit in easily and it's easy to find
|
||||
* what each maps too, since each array element is a scan code
|
||||
* and provides for E0, etc. ones too.
|
||||
*/
|
||||
for (j = 0; j < 65536; j++)
|
||||
scancode_map[j] = convert_scan_code(j);
|
||||
|
||||
bufSize = 32768;
|
||||
/* Get the scan code remappings from:
|
||||
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout */
|
||||
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, keyName, 0, 1, &hKey) == ERROR_SUCCESS)
|
||||
{
|
||||
if(RegQueryValueEx(hKey, valueName, NULL, NULL, buf, &bufSize) == ERROR_SUCCESS)
|
||||
{
|
||||
bufEx2 = (UINT32 *) buf;
|
||||
scMapCount = bufEx2[2];
|
||||
if ((bufSize != 0) && (scMapCount != 0))
|
||||
{
|
||||
bufEx = (UINT16 *) (buf + 12);
|
||||
for (j = 0; j < scMapCount*2; j += 2)
|
||||
{
|
||||
/* Each scan code is 32-bit: 16 bits of remapped scan code,
|
||||
and 16 bits of original scan code. */
|
||||
scancode_unmapped = bufEx[j + 1];
|
||||
scancode_mapped = bufEx[j];
|
||||
/* Get the scan code remappings from:
|
||||
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout */
|
||||
bufSize = 32768;
|
||||
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, keyName, 0, 1, &hKey) == ERROR_SUCCESS) {
|
||||
if (RegQueryValueEx(hKey, valueName, NULL, NULL, buf, &bufSize) == ERROR_SUCCESS) {
|
||||
bufEx2 = (UINT32 *) buf;
|
||||
scMapCount = bufEx2[2];
|
||||
if ((bufSize != 0) && (scMapCount != 0)) {
|
||||
bufEx = (UINT16 *) (buf + 12);
|
||||
for (j = 0; j < scMapCount*2; j += 2) {
|
||||
/* Each scan code is 32-bit: 16 bits of remapped scan code,
|
||||
and 16 bits of original scan code. */
|
||||
scancode_unmapped = bufEx[j + 1];
|
||||
scancode_mapped = bufEx[j];
|
||||
|
||||
scancode_mapped = convert_scan_code(scancode_mapped);
|
||||
scancode_mapped = convert_scan_code(scancode_mapped);
|
||||
|
||||
/* Fixes scan code map logging. */
|
||||
scancode_map[scancode_unmapped] = scancode_mapped;
|
||||
}
|
||||
/* Fixes scan code map logging. */
|
||||
scancode_map[scancode_unmapped] = scancode_mapped;
|
||||
}
|
||||
}
|
||||
RegCloseKey(hKey);
|
||||
}
|
||||
RegCloseKey(hKey);
|
||||
}
|
||||
}
|
||||
|
||||
void process_raw_input(LPARAM lParam, int infocus)
|
||||
|
||||
void
|
||||
keyboard_handle(LPARAM lParam, int infocus)
|
||||
{
|
||||
uint32_t ri_size = 0;
|
||||
UINT size;
|
||||
RAWINPUT *raw;
|
||||
USHORT scancode;
|
||||
uint32_t ri_size = 0;
|
||||
UINT size;
|
||||
RAWINPUT *raw;
|
||||
USHORT scancode;
|
||||
|
||||
if (!infocus)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (! infocus) return;
|
||||
|
||||
GetRawInputData((HRAWINPUT)lParam, RID_INPUT, NULL, &size, sizeof(RAWINPUTHEADER));
|
||||
GetRawInputData((HRAWINPUT)lParam, RID_INPUT, NULL,
|
||||
&size, sizeof(RAWINPUTHEADER));
|
||||
|
||||
raw = malloc(size);
|
||||
raw = malloc(size);
|
||||
if (raw == NULL) return;
|
||||
|
||||
if (raw == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
/* Here we read the raw input data for the keyboard */
|
||||
ri_size = GetRawInputData((HRAWINPUT)(lParam), RID_INPUT,
|
||||
raw, &size, sizeof(RAWINPUTHEADER));
|
||||
if (ri_size != size) return;
|
||||
|
||||
/* Here we read the raw input data for the keyboard */
|
||||
ri_size = GetRawInputData((HRAWINPUT)(lParam), RID_INPUT, raw, &size, sizeof(RAWINPUTHEADER));
|
||||
/* If the input is keyboard, we process it */
|
||||
if (raw->header.dwType == RIM_TYPEKEYBOARD) {
|
||||
RAWKEYBOARD rawKB = raw->data.keyboard;
|
||||
scancode = rawKB.MakeCode;
|
||||
|
||||
if(ri_size != size)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/* If the input is keyboard, we process it */
|
||||
if (raw->header.dwType == RIM_TYPEKEYBOARD)
|
||||
{
|
||||
RAWKEYBOARD rawKB = raw->data.keyboard;
|
||||
scancode = rawKB.MakeCode;
|
||||
|
||||
/* If it's not a scan code that starts with 0xE1 */
|
||||
if (!(rawKB.Flags & RI_KEY_E1))
|
||||
{
|
||||
if (rawKB.Flags & RI_KEY_E0)
|
||||
{
|
||||
scancode |= (0xE0 << 8);
|
||||
}
|
||||
|
||||
/* Remap it according to the list from the Registry */
|
||||
scancode = scancode_map[scancode];
|
||||
|
||||
if ((scancode >> 8) == 0xF0)
|
||||
{
|
||||
scancode |= 0x100; /* Extended key code in disambiguated format */
|
||||
}
|
||||
else if ((scancode >> 8) == 0xE0)
|
||||
{
|
||||
scancode |= 0x80; /* Normal extended key code */
|
||||
}
|
||||
|
||||
/* If it's not 0 (therefore not 0xE1, 0xE2, etc),
|
||||
then pass it on to the rawinputkey array */
|
||||
if (!(scancode & 0xf00))
|
||||
{
|
||||
recv_key[scancode & 0x1ff] = !(rawKB.Flags & RI_KEY_BREAK);
|
||||
}
|
||||
/* If it's not a scan code that starts with 0xE1 */
|
||||
if (!(rawKB.Flags & RI_KEY_E1)) {
|
||||
if (rawKB.Flags & RI_KEY_E0) {
|
||||
scancode |= (0xE0 << 8);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (rawKB.MakeCode == 0x1D)
|
||||
{
|
||||
scancode = 0xFF;
|
||||
}
|
||||
if (!(scancode & 0xf00))
|
||||
{
|
||||
recv_key[scancode & 0x1ff] = !(rawKB.Flags & RI_KEY_BREAK);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
free(raw);
|
||||
/* Remap it according to the list from the Registry */
|
||||
scancode = scancode_map[scancode];
|
||||
|
||||
if ((scancode >> 8) == 0xF0) {
|
||||
/* Extended key code in disambiguated format */
|
||||
scancode |= 0x100;
|
||||
} else if ((scancode >> 8) == 0xE0) {
|
||||
/* Normal extended key code */
|
||||
scancode |= 0x80;
|
||||
}
|
||||
|
||||
/* If it's not 0 (therefore not 0xE1, 0xE2, etc),
|
||||
send it to the PC keyboard. */
|
||||
if (!(scancode & 0xf00))
|
||||
keyboard_input(!(rawKB.Flags & RI_KEY_BREAK), scancode & 0x1ff);
|
||||
} else {
|
||||
if (rawKB.MakeCode == 0x1D) {
|
||||
scancode = 0xFF;
|
||||
}
|
||||
if (!(scancode & 0xf00))
|
||||
keyboard_input(!(rawKB.Flags & RI_KEY_BREAK), scancode & 0x1ff);
|
||||
}
|
||||
}
|
||||
|
||||
free(raw);
|
||||
}
|
||||
|
||||
@@ -109,3 +109,11 @@ StatusWindowCreate(HWND hwndParent)
|
||||
hwndParent, StatusWindowProcedure);
|
||||
ShowWindow(hwnd, SW_SHOW);
|
||||
}
|
||||
|
||||
|
||||
/* Tell the Status window to update. */
|
||||
void
|
||||
ui_status_update(void)
|
||||
{
|
||||
SendMessage(hwndStatus, WM_USER, 0, 0);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
* Platform video API support for Win32.
|
||||
*
|
||||
* Version: @(#)win_video.c 1.0.2 2017/10/22
|
||||
* Version: @(#)win_video.c 1.0.3 2017/10/24
|
||||
*
|
||||
* Author: Fred N. van Kempen, <decwiz@yahoo.com>
|
||||
*
|
||||
@@ -116,24 +116,38 @@ plat_vidapi(char *name)
|
||||
}
|
||||
|
||||
|
||||
/* Return the VIDAPI name for the given number. */
|
||||
char *
|
||||
plat_vidapi_name(void)
|
||||
plat_vidapi_name(int api)
|
||||
{
|
||||
switch(vid_api) {
|
||||
case 0:
|
||||
return("ddraw");
|
||||
case 1:
|
||||
default:
|
||||
return("default"); /* Direct3D is default. */
|
||||
char *name = "default";
|
||||
|
||||
switch(api) {
|
||||
case 0:
|
||||
name = "ddraw";
|
||||
break;
|
||||
|
||||
case 1:
|
||||
#if 0
|
||||
/* Direct3D is default. */
|
||||
name = "d3d";
|
||||
#endif
|
||||
break;
|
||||
|
||||
#ifdef USE_VNC
|
||||
case 2:
|
||||
return("vnc");
|
||||
case 2:
|
||||
name = "vnc";
|
||||
break;
|
||||
|
||||
#endif
|
||||
#ifdef USE_RDP
|
||||
case 3:
|
||||
return("rdp");
|
||||
case 3:
|
||||
name = "rdp";
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
return(name);
|
||||
}
|
||||
|
||||
|
||||
@@ -148,9 +162,6 @@ plat_setvid(int api)
|
||||
|
||||
/* Close the (old) API. */
|
||||
vid_apis[0][vid_api].close();
|
||||
#ifdef USE_WX
|
||||
ui_check_menu_item(IDM_View_WX+vid_api, 0);
|
||||
#endif
|
||||
vid_api = api;
|
||||
|
||||
if (vid_apis[0][vid_api].local)
|
||||
@@ -159,9 +170,6 @@ plat_setvid(int api)
|
||||
ShowWindow(hwndRender, SW_HIDE);
|
||||
|
||||
/* Initialize the (new) API. */
|
||||
#ifdef USE_WX
|
||||
ui_check_menu_item(IDM_View_WX+vid_api, 1);
|
||||
#endif
|
||||
i = vid_apis[0][vid_api].init((void *)hwndRender);
|
||||
endblit();
|
||||
if (! i) return(0);
|
||||
@@ -255,7 +263,7 @@ take_screenshot(void)
|
||||
switch(vid_api) {
|
||||
case 0: /* ddraw */
|
||||
wcsftime(path, 128, L"%Y%m%d_%H%M%S.bmp", info);
|
||||
plat_append_filename(path, cfg_path, fn, 1024);
|
||||
wcscat(path, fn);
|
||||
if (video_fullscreen)
|
||||
ddraw_fs_take_screenshot(path);
|
||||
else
|
||||
@@ -265,7 +273,7 @@ take_screenshot(void)
|
||||
|
||||
case 1: /* d3d9 */
|
||||
wcsftime(fn, 128, L"%Y%m%d_%H%M%S.png", info);
|
||||
plat_append_filename(path, cfg_path, fn, 1024);
|
||||
wcscat(path, fn);
|
||||
if (video_fullscreen)
|
||||
d3d_fs_take_screenshot(path);
|
||||
else
|
||||
@@ -276,7 +284,7 @@ take_screenshot(void)
|
||||
#ifdef USE_VNC
|
||||
case 2: /* vnc */
|
||||
wcsftime(fn, 128, L"%Y%m%d_%H%M%S.png", info);
|
||||
plat_append_filename(path, cfg_path, fn, 1024);
|
||||
wcscat(path, fn);
|
||||
vnc_take_screenshot(path);
|
||||
pclog("Screenshot: fn='%ls'\n", path);
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user