Cleaning up the "keyboard" module. Also general fixups here and there, and cleanups of earlier cleanups.

This commit is contained in:
waltje
2017-10-24 22:10:21 -04:00
parent 659e07221d
commit 5abd25ba58
17 changed files with 533 additions and 546 deletions

View File

@@ -8,7 +8,7 @@
*
* Configuration file handler.
*
* Version: @(#)config.c 1.0.25 2017/10/21
* Version: @(#)config.c 1.0.26 2017/10/24
*
* Authors: Sarah Walker,
* Miran Grca, <mgrca8@gmail.com>
@@ -1174,7 +1174,7 @@ save_general(void)
if (vid_resize == 0)
config_delete_var(cat, "vid_resize");
va_name = plat_vidapi_name();
va_name = plat_vidapi_name(vid_api);
if (!strcmp(va_name, "default")) {
config_delete_var(cat, "vid_renderer");
} else {

View File

@@ -8,7 +8,7 @@
*
* Host to guest keyboard interface and keyboard scan code sets.
*
* Version: @(#)keyboard.c 1.0.5 2017/10/16
* Version: @(#)keyboard.c 1.0.6 2017/10/24
*
* Authors: Sarah Walker, <http://pcem-emulator.co.uk/>
* Miran Grca, <mgrca8@gmail.com>
@@ -22,20 +22,33 @@
#include <wchar.h>
#include "86box.h"
#include "ibm.h"
#include "plat_keyboard.h"
#include "keyboard.h"
int keybsendcallback = 0;
int64_t keybsenddelay;
#if 0
int keybsendcallback = 0;
#endif
int64_t keybsenddelay;
/* bit 0 = repeat, bit 1 = makes break code? */
uint8_t keyboard_set3_flags[272];
uint8_t keyboard_set3_all_repeat;
uint8_t keyboard_set3_all_break;
void (*keyboard_send)(uint8_t val);
void (*keyboard_poll)(void);
int keyboard_scan;
typedef struct
{
int scancodes_make[9];
int scancodes_break[9];
static int recv_key[272]; /* keyboard input buffer */
typedef struct {
int scancodes_make[9];
int scancodes_break[9];
} scancode;
/*272 = 256 + 16 fake interim scancodes for disambiguation purposes.*/
static scancode scancode_set1[272] =
{
@@ -428,101 +441,144 @@ static int scorder[272] = {0x38, 0xB8, 0x1D, 0x9D, 0xFF, 0x2A, 0x36,0x103, 0x00,
0xEE, 0xEF, 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD,
0xFE,0x100,0x101,0x102,0x104,0x105,0x106,0x107,0x108,0x109,0x10A,0x10B,0x10C,0x10D,0x10E,0x10F};
/* bit 0 = repeat, bit 1 = makes break code? */
uint8_t set3_flags[272];
uint8_t set3_all_repeat = 0;
uint8_t set3_all_break = 0;
void (*keyboard_send)(uint8_t val);
void (*keyboard_poll)();
int keyboard_scan = 1;
void keyboard_process()
void
keyboard_init(void)
{
int c;
int d;
scancode *scancodes;
memset(recv_key, 0x00, sizeof(recv_key));
if (AT)
{
switch (mode & 3)
{
case 1:
default:
scancodes = scancode_set1;
break;
case 2:
scancodes = scancode_set2;
break;
case 3:
scancodes = scancode_set3;
break;
}
if (mode & 0x20) scancodes = scancode_set1;
}
else
{
scancodes = scancode_xt;
}
keyboard_scan = 1;
if (!keyboard_scan) return;
if (TANDY) scancodes = scancode_tandy;
for (c = 0; c < 272; c++)
{
if (recv_key[scorder[c]])
keydelay[scorder[c]]++;
else
keydelay[scorder[c]] = 0;
}
for (c = 0; c < 272; c++)
{
if (recv_key[scorder[c]] != oldkey[scorder[c]])
{
oldkey[scorder[c]] = recv_key[scorder[c]];
if ( recv_key[scorder[c]] && scancodes[scorder[c]].scancodes_make[0] == -1)
continue;
if (!recv_key[scorder[c]] && scancodes[scorder[c]].scancodes_break[0] == -1)
continue;
if (AT && ((mode & 3) == 3))
{
if (!set3_all_break && !recv_key[scorder[c]] && !(set3_flags[scancodes[scorder[c]].scancodes_make[0]] & 2))
continue;
}
d = 0;
if (recv_key[scorder[c]])
{
while (scancodes[scorder[c]].scancodes_make[d] != -1)
keyboard_send(scancodes[scorder[c]].scancodes_make[d++]);
}
else
{
while (scancodes[scorder[c]].scancodes_break[d] != -1)
keyboard_send(scancodes[scorder[c]].scancodes_break[d++]);
}
}
}
for (c = 0; c < 272; c++)
{
if (AT && ((mode & 3) == 3))
{
if (scancodes[scorder[c]].scancodes_make[0] == -1)
continue;
if (!set3_all_repeat && !recv_key[scorder[c]] && !(set3_flags[scancodes[scorder[c]].scancodes_make[0]] & 1))
continue;
}
if (keydelay[scorder[c]] >= 30)
{
keydelay[scorder[c]] -= 10;
if (scancodes[scorder[c]].scancodes_make[0] == -1)
continue;
d = 0;
while (scancodes[scorder[c]].scancodes_make[d] != -1)
keyboard_send(scancodes[scorder[c]].scancodes_make[d++]);
}
}
memset(keyboard_set3_flags, 0x00, sizeof(keyboard_set3_flags));
keyboard_set3_all_repeat = 0;
keyboard_set3_all_break = 0;
}
void
keyboard_process(void)
{
scancode *scancodes;
int c, d;
if (AT) {
switch (keyboard_mode & 3) {
case 1:
default:
scancodes = scancode_set1;
break;
case 2:
scancodes = scancode_set2;
break;
case 3:
scancodes = scancode_set3;
break;
}
if (keyboard_mode & 0x20) scancodes = scancode_set1;
} else {
scancodes = scancode_xt;
}
if (!keyboard_scan) return;
if (TANDY) scancodes = scancode_tandy;
for (c = 0; c < 272; c++) {
if (recv_key[scorder[c]])
keydelay[scorder[c]]++;
else
keydelay[scorder[c]] = 0;
}
for (c = 0; c < 272; c++) {
if (recv_key[scorder[c]] != oldkey[scorder[c]]) {
oldkey[scorder[c]] = recv_key[scorder[c]];
if (recv_key[scorder[c]] &&
scancodes[scorder[c]].scancodes_make[0] == -1) continue;
if (!recv_key[scorder[c]] &&
scancodes[scorder[c]].scancodes_break[0] == -1) continue;
if (AT && ((keyboard_mode & 3) == 3)) {
if (!keyboard_set3_all_break &&
!recv_key[scorder[c]] &&
!(keyboard_set3_flags[scancodes[scorder[c]].scancodes_make[0]] & 2)) continue;
}
d = 0;
if (recv_key[scorder[c]]) {
while (scancodes[scorder[c]].scancodes_make[d] != -1)
keyboard_send(scancodes[scorder[c]].scancodes_make[d++]);
} else {
while (scancodes[scorder[c]].scancodes_break[d] != -1)
keyboard_send(scancodes[scorder[c]].scancodes_break[d++]);
}
}
}
for (c = 0; c < 272; c++) {
if (AT && ((keyboard_mode & 3) == 3)) {
if (scancodes[scorder[c]].scancodes_make[0] == -1) continue;
if (!keyboard_set3_all_repeat &&
!recv_key[scorder[c]] &&
!(keyboard_set3_flags[scancodes[scorder[c]].scancodes_make[0]] & 1)) continue;
}
if (keydelay[scorder[c]] >= 30) {
keydelay[scorder[c]] -= 10;
if (scancodes[scorder[c]].scancodes_make[0] == -1) continue;
d = 0;
while (scancodes[scorder[c]].scancodes_make[d] != -1)
keyboard_send(scancodes[scorder[c]].scancodes_make[d++]);
}
}
}
/* Handle a keystroke event from the UI layer. */
void
keyboard_input(int down, uint16_t scan)
{
int key;
#if 0
pclog("KBD: kbinput %d %04x\n", down, scan);
#endif
if ((scan >> 8) == 0xf0) {
scan &= 0x00ff;
scan |= 0x0100; /* ext key code in disambiguated format */
} else if ((scan >> 8) == 0xe0) {
scan &= 0x00ff;
scan |= 0x0080; /* normal extended key code */
}
/* First key. */
key = (scan >> 8) & 0xff;
if (key > 0)
recv_key[key] = down;
/* Second key. */
key = scan & 0xff;
if (key > 0)
recv_key[key] = down;
}
/* Do we have Control-Alt-PgDn in the keyboard buffer? */
int
keyboard_isfsexit(void)
{
return( (recv_key[0x1D] || recv_key[0x9D]) &&
(recv_key[0x38] || recv_key[0xB8]) &&
(recv_key[0x51] || recv_key[0xD1]) );
}
/* Do we have F8-F12 in the keyboard buffer? */
int
keyboard_ismsexit(void)
{
return( recv_key[0x42] && recv_key[0x58] );
}

View File

@@ -8,10 +8,11 @@
*
* Host to guest keyboard interface and keyboard scan code sets.
*
* Version: @(#)keyboard.h 1.0.1 2017/08/23
* Version: @(#)keyboard.h 1.0.3 2017/10/24
*
* Authors: Sarah Walker, <http://pcem-emulator.co.uk/>
* Miran Grca, <mgrca8@gmail.com>
*
* Copyright 2008-2017 Sarah Walker.
* Copyright 2016,2017 Miran Grca.
*/
@@ -19,18 +20,28 @@
# define EMU_KEYBOARD_H
extern int keyboard_scan;
extern int pcem_key[272];
extern uint8_t mode;
#ifdef __cplusplus
extern "C" {
#endif
extern uint8_t set3_flags[272];
extern uint8_t set3_all_repeat;
extern uint8_t set3_all_break;
extern uint8_t keyboard_mode;
extern int keyboard_scan;
extern uint8_t keyboard_set3_flags[272];
extern uint8_t keyboard_set3_all_repeat;
extern uint8_t keyboard_set3_all_break;
extern void (*keyboard_send)(uint8_t val);
extern void (*keyboard_poll)(void);
extern void keyboard_process(void);
extern void (*keyboard_send)(uint8_t val);
extern void (*keyboard_poll)(void);
extern void keyboard_init(void);
extern void keyboard_close(void);
extern void keyboard_poll_host(void);
extern void keyboard_process(void);
extern uint16_t keyboard_convert(int ch);
extern void keyboard_input(int down, uint16_t scan);
extern int keyboard_isfsexit(void);
extern int keyboard_ismsexit(void);
#endif /*EMU_KEYBOARD_H*/

View File

@@ -8,7 +8,7 @@
*
* Intel 8042 (AT keyboard controller) emulation.
*
* Version: @(#)keyboard_at.c 1.0.5 2017/10/19
* Version: @(#)keyboard_at.c 1.0.6 2017/10/24
*
* Authors: Sarah Walker, <http://pcem-emulator.co.uk/>
* Miran Grca, <mgrca8@gmail.com>
@@ -111,7 +111,7 @@ int first_write = 1;
int dtrans = 0;
/* Bits 0 - 1 = scan code set, bit 6 = translate or not. */
uint8_t mode = 0x42;
uint8_t keyboard_mode = 0x42;
/* Non-translated to translated scan codes. */
static uint8_t nont_to_t[256] = { 0xFF, 0x43, 0x41, 0x3F, 0x3D, 0x3B, 0x3C, 0x58, 0x64, 0x44, 0x42, 0x40, 0x3E, 0x0F, 0x29, 0x59,
@@ -213,18 +213,18 @@ uint8_t sc_or = 0;
void keyboard_at_adddata_keyboard(uint8_t val)
{
/* Modification by OBattler: Allow for scan code translation. */
if ((mode & 0x40) && (val == 0xf0) && !(mode & 0x20))
if ((keyboard_mode & 0x40) && (val == 0xf0) && !(keyboard_mode & 0x20))
{
sc_or = 0x80;
return;
}
/* Skip break code if translated make code has bit 7 set. */
if ((mode & 0x40) && (sc_or == 0x80) && (nont_to_t[val] & 0x80) && !(mode & 0x20))
if ((keyboard_mode & 0x40) && (sc_or == 0x80) && (nont_to_t[val] & 0x80) && !(keyboard_mode & 0x20))
{
sc_or = 0;
return;
}
key_queue[key_queue_end] = (((mode & 0x40) && !(mode & 0x20)) ? (nont_to_t[val] | sc_or) : val);
key_queue[key_queue_end] = (((keyboard_mode & 0x40) && !(keyboard_mode & 0x20)) ? (nont_to_t[val] | sc_or) : val);
key_queue_end = (key_queue_end + 1) & 0xf;
if (sc_or == 0x80) sc_or = 0;
return;
@@ -290,21 +290,21 @@ write_register:
keyboard_at_log("Mouse interrupt is now %s\n", (val & 0x02) ? "enabled" : "disabled");
/* Addition by OBattler: Scan code translate ON/OFF. */
mode &= 0x93;
mode |= (val & MODE_MASK);
keyboard_mode &= 0x93;
keyboard_mode |= (val & MODE_MASK);
if (first_write)
{
/* A bit of a hack, but it will make the keyboard behave correctly, regardless
of what the BIOS sets here. */
mode &= 0xFC;
dtrans = mode & (CCB_TRANSLATE | CCB_PCMODE);
if ((mode & (CCB_TRANSLATE | CCB_PCMODE)) == CCB_TRANSLATE)
keyboard_mode &= 0xFC;
dtrans = keyboard_mode & (CCB_TRANSLATE | CCB_PCMODE);
if ((keyboard_mode & (CCB_TRANSLATE | CCB_PCMODE)) == CCB_TRANSLATE)
{
/* Bit 6 on, bit 5 off, the only case in which translation is on,
therefore, set to set 2. */
mode |= 2;
keyboard_mode |= 2;
}
keyboard_at.default_mode = (mode & 3);
keyboard_at.default_mode = (keyboard_mode & 3);
first_write = 0;
/* No else because in all other cases, translation is off, so we need to keep it
set to set 0 which the mode &= 0xFC above will set it. */
@@ -338,8 +338,8 @@ write_register:
case 0xcf: /*??? - sent by MegaPC BIOS*/
keyboard_at_log("??? - sent by MegaPC BIOS\n");
/* To make sure the keyboard works correctly on the MegaPC. */
mode &= 0xFC;
mode |= 2;
keyboard_mode &= 0xFC;
keyboard_mode |= 2;
break;
case 0xd1: /*Write output port*/
@@ -392,14 +392,14 @@ bad_command:
case 0xf0: /*Get/set scancode set*/
if (val == 0)
{
keyboard_at_adddata_keyboard(mode & 3);
keyboard_at_adddata_keyboard(keyboard_mode & 3);
}
else
{
if (val <= 3)
{
mode &= 0xFC;
mode |= (val & 3);
keyboard_mode &= 0xFC;
keyboard_mode |= (val & 3);
}
keyboard_at_adddata_keyboard(0xfa);
}
@@ -469,31 +469,31 @@ bad_command:
break;
case 0xf6: /*Set defaults*/
set3_all_break = 0;
set3_all_repeat = 0;
memset(set3_flags, 0, 272);
mode = (mode & 0xFC) | keyboard_at.default_mode;
keyboard_set3_all_break = 0;
keyboard_set3_all_repeat = 0;
memset(keyboard_set3_flags, 0, 272);
keyboard_mode = (keyboard_mode & 0xFC) | keyboard_at.default_mode;
keyboard_at_adddata_keyboard(0xfa);
break;
case 0xf7: /*Set all keys to repeat*/
set3_all_break = 1;
keyboard_set3_all_break = 1;
keyboard_at_adddata_keyboard(0xfa);
break;
case 0xf8: /*Set all keys to give make/break codes*/
set3_all_break = 1;
keyboard_set3_all_break = 1;
keyboard_at_adddata_keyboard(0xfa);
break;
case 0xf9: /*Set all keys to give make codes only*/
set3_all_break = 0;
keyboard_set3_all_break = 0;
keyboard_at_adddata_keyboard(0xfa);
break;
case 0xfa: /*Set all keys to repeat and give make/break codes*/
set3_all_repeat = 1;
set3_all_break = 1;
keyboard_set3_all_repeat = 1;
keyboard_set3_all_break = 1;
keyboard_at_adddata_keyboard(0xfa);
break;
@@ -506,8 +506,8 @@ bad_command:
keyboard_at_adddata_keyboard(0xfa);
keyboard_at_adddata_keyboard(0xaa);
/* Set system flag to 1 and scan code set to 2. */
mode &= 0xFC;
mode |= 2;
keyboard_mode &= 0xFC;
keyboard_mode |= 2;
break;
default:
@@ -851,8 +851,8 @@ uint8_t keyboard_at_read(uint16_t port, void *priv)
break;
case 0x64:
temp = (keyboard_at.status & 0xFB) | (mode & CCB_SYSTEM);
/* if (mode & CCB_IGNORELOCK) */ temp |= STAT_LOCK;
temp = (keyboard_at.status & 0xFB) | (keyboard_mode & CCB_SYSTEM);
/* if (keyboard_mode & CCB_IGNORELOCK) */ temp |= STAT_LOCK;
keyboard_at.status &= ~(STAT_RTIMEOUT/* | STAT_TTIMEOUT*/);
break;
}
@@ -864,7 +864,7 @@ void keyboard_at_reset(void)
keyboard_at.initialised = 0;
keyboard_at.status = STAT_LOCK | STAT_CD;
keyboard_at.mem[0] = 0x31;
mode = 0x02 | dtrans;
keyboard_mode = 0x02 | dtrans;
keyboard_at.default_mode = 2;
first_write = 1;
keyboard_at.wantirq = 0;
@@ -882,7 +882,7 @@ void keyboard_at_reset(void)
sc_or = 0;
memset(set3_flags, 0, 272);
memset(keyboard_set3_flags, 0, 272);
}
static void at_refresh(void *p)

View File

@@ -8,7 +8,7 @@
*
* Main emulator module where most things are controlled.
*
* Version: @(#)pc.c 1.0.32 2017/10/22
* Version: @(#)pc.c 1.0.33 2017/10/24
*
* Authors: Sarah Walker, <http://pcem-emulator.co.uk/>
* Miran Grca, <mgrca8@gmail.com>
@@ -73,7 +73,6 @@
#include "ui.h"
#include "plat.h"
#include "plat_joystick.h"
#include "plat_keyboard.h"
#include "plat_midi.h"
#include "plat_mouse.h"
@@ -114,9 +113,9 @@ int sreadlnum,
segawrites,
scycles_lost;
float mips, flops;
int cycles_lost = 0; // video
int insc = 0; // cpu
int emu_fps = 0, fps; // video
int cycles_lost = 0; /* video */
int insc = 0; /* cpu */
int emu_fps = 0, fps; /* video */
int framecount;
int CPUID;
@@ -125,7 +124,7 @@ int atfullspeed;
int cpuspeed2;
int clockrate;
int gfx_present[GFX_MAX]; // should not be here
int gfx_present[GFX_MAX]; /* should not be here */
wchar_t exe_path[1024]; /* path (dir) of executable */
wchar_t cfg_path[1024]; /* path (dir) of user data */
@@ -145,6 +144,7 @@ pclog(const char *format, ...)
{
#ifndef RELEASE_BUILD
va_list ap;
va_start(ap, format);
vprintf(format, ap);
va_end(ap);
@@ -280,7 +280,7 @@ set_screen_size_natural(void)
* Perform initial startup of the PC.
*
* This is the platform-indepenent part of the startup,
* where we check commandline arguments and loading a
* where we check commandline arguments and load a
* configuration file.
*/
int
@@ -520,6 +520,7 @@ again2:
codegen_init();
#endif
keyboard_init();
mouse_init();
#ifdef WALTJE
serial_init();
@@ -774,6 +775,7 @@ pc_close(thread_t *ptr)
config_save();
#if 0
//FIXME: need to move this to Plat. */
if (mouse_capture) {
ClipCursor(&oldclip);
ShowCursor(TRUE);
@@ -831,10 +833,7 @@ pc_thread(void *param)
while (! *quitp) {
/* Update the Stat(u)s window with the current info. */
if (status_update_needed) {
#if 0
pclog("Updating STATS window..\n");
// ui_status_update();
#endif
ui_status_update();
status_update_needed = 0;
}
@@ -966,20 +965,10 @@ pc_thread(void *param)
/* If requested, leave full-screen mode. */
if (leave_fullscreen_flag) {
#if 1
pclog("Leaving full-screen mode..\n");
plat_setfullscreen(0);
#else
SendMessage(hwndMain, WM_LEAVEFULLSCREEN, 0, 0);
#endif
leave_fullscreen_flag = 0;
}
#if 0
/* Do we really need this all the time? */
if (video_fullscreen && infocus)
SetCursorPos(9999, 9999);
#endif
}
pclog("PC: main thread done.\n");

View File

@@ -8,7 +8,7 @@
*
* Define the various platform support functions.
*
* Version: @(#)plat.h 1.0.13 2017/10/22
* Version: @(#)plat.h 1.0.14 2017/10/24
*
* Authors: Miran Grca, <mgrca8@gmail.com>
* Fred N. van Kempen, <decwiz@yahoo.com>
@@ -58,7 +58,7 @@ extern uint32_t plat_get_ticks(void);
extern void plat_delay_ms(uint32_t count);
extern void plat_pause(int p);
extern int plat_vidapi(char *name);
extern char * plat_vidapi_name(void);
extern char *plat_vidapi_name(int api);
extern int plat_setvid(int api);
extern void plat_setfullscreen(int on);
extern void plat_resize(int max_x, int max_y);

View File

@@ -1,22 +0,0 @@
/* Copyright holders: Sarah Walker
see COPYING for more details
*/
#ifdef __cplusplus
extern "C" {
#endif
void keyboard_init();
void keyboard_close();
void keyboard_poll_host();
extern int recv_key[272];
extern int rawinputkey[272];
#ifndef __unix
#define KEY_LCONTROL 0x1d
#define KEY_RCONTROL (0x1d | 0x80)
#define KEY_END (0x4f | 0x80)
#endif
#ifdef __cplusplus
}
#endif

View File

@@ -13,8 +13,6 @@
#include <wchar.h>
#include "ibm.h"
#include "pit.h"
#include "plat_keyboard.h"
#include "plat_mouse.h"
PPI ppi;

View File

@@ -8,7 +8,7 @@
*
* Define the various UI functions.
*
* Version: @(#)ui.h 1.0.5 2017/10/16
* Version: @(#)ui.h 1.0.6 2017/10/24
*
* Authors: Miran Grca, <mgrca8@gmail.com>
* Fred N. van Kempen, <decwiz@yahoo.com>
@@ -53,6 +53,7 @@ extern void ui_check_menu_item(int id, int checked);
#define SB_TEXT 0x60
extern wchar_t *ui_window_title(wchar_t *s);
extern void ui_status_update(void);
extern int ui_sb_find_part(int tag);
extern void ui_sb_update_panes(void);
extern void ui_sb_update_tip(int meaning);

View File

@@ -8,7 +8,7 @@
*
* Implement the VNC remote renderer with LibVNCServer.
*
* Version: @(#)vnc.c 1.0.6 2017/10/22
* Version: @(#)vnc.c 1.0.7 2017/10/24
*
* Authors: Fred N. van Kempen, <decwiz@yahoo.com>
* Based on raw code by RichardG, <richardg867@gmail.com>
@@ -26,9 +26,9 @@
#include "86box.h"
#include "device.h"
#include "video/video.h"
#include "keyboard.h"
#include "mouse.h"
#include "plat.h"
#include "plat_keyboard.h"
#include "ui.h"
#include "vnc.h"

View File

@@ -22,7 +22,7 @@
* NOTE: The values are as defined in the Microsoft document named
* "Keyboard Scan Code Specification", version 1.3a of 2000/03/16.
*
* Version: @(#)vnc_keymap.c 1.0.1 2017/10/22
* Version: @(#)vnc_keymap.c 1.0.2 2017/10/24
*
* Authors: Fred N. van Kempen, <decwiz@yahoo.com>
* Based on raw code by RichardG, <richardg867@gmail.com>
@@ -35,8 +35,8 @@
#include <string.h>
#include <wchar.h>
#include "86box.h"
#include "keyboard.h"
#include "plat.h"
#include "plat_keyboard.h"
#include "vnc.h"
@@ -183,7 +183,7 @@ static int keysyms_00[] = {
0x2a2b, /* 0x7c (XK_bar) */
0x2a1b, /* 0x7d (XK_braceright) */
0x2a29, /* 0x7e (XK_asciitilde) */
0xe071, /* 0x7f (XK_delete) */
0x0053, /* 0x7f (XK_delete) */
0x0000, /* 0x80 */
0x0000,
@@ -371,7 +371,7 @@ static int keysyms_ff[] = {
0x0000, /* 0x21 (XK_Kanji; Kanji, Kanji convert) */
0x0000, /* 0x22 (XK_Muhenkan; Cancel Conversion) */
0x0000, /* 0x23 (XK_Henkan_Mode; Start/Stop Conversion) */
0x0000, /* 0x24 (#define XK_Romaji; to Romaji) */
0x0000, /* 0x24 (XK_Romaji; to Romaji) */
0x0000, /* 0x25 (XK_Hiragana; to Hiragana) */
0x0000, /* 0x26 (XK_Katakana; to Katakana) */
0x0000, /* 0x27 (XK_Hiragana_Katakana; Hiragana/Katakana toggle) */
@@ -421,14 +421,14 @@ static int keysyms_ff[] = {
0x0000,
0x0000,
0x006c, /* 0x50 (XK_Home) */
0x006b, /* 0x51 (XK_Left) */
0x0075, /* 0x52 (XK_Up) */
0x0074, /* 0x53 (XK_Right) */
0x0072, /* 0x54 (XK_Down) */
0x007d, /* 0x55 (XK_Prior, XK_Page_Up) */
0x007a, /* 0x56 (XK_Next, XK_Page_Down) */
0x0069, /* 0x57 (XK_End) */
0xe047, /* 0x50 (XK_Home) */
0xe04b, /* 0x51 (XK_Left) */
0xe048, /* 0x52 (XK_Up) */
0xe04d, /* 0x53 (XK_Right) */
0xe050, /* 0x54 (XK_Down) */
0xe049, /* 0x55 (XK_Prior, XK_Page_Up) */
0xe051, /* 0x56 (XK_Next, XK_Page_Down) */
0xe04f, /* 0x57 (XK_End) */
0x0000, /* 0x58 (XK_Begin) */
0x0000,
@@ -442,11 +442,11 @@ static int keysyms_ff[] = {
0x0000, /* 0x60 (XK_Select) */
0x0000, /* 0x61 (XK_Print) */
0x0000, /* 0x62 (XK_Execute) */
0xe070, /* 0x63 (XK_Insert) */
0xe052, /* 0x63 (XK_Insert) */
0x0000,
0x0000, /* 0x65 (XK_Undo) */
0x0000, /* 0x66 (XK_Redo) */
0x00dd, /* 0x67 (XK_Menu) */
0xe05d, /* 0x67 (XK_Menu) */
0x0000, /* 0x68 (XK_Find) */
0x0000, /* 0x69 (XK_Cancel) */
@@ -475,7 +475,7 @@ static int keysyms_ff[] = {
0x0000, /* 0x7e (XK_Mode_switch,XK_script_switch) */
0x0045, /* 0x7f (XK_Num_Lock) */
0x0000, /* 0x80 (XK_KP_Space) */
0x0039, /* 0x80 (XK_KP_Space) */
0x0000,
0x0000,
0x0000,
@@ -485,11 +485,11 @@ static int keysyms_ff[] = {
0x0000,
0x0000, /* 0x88 */
0x0000, /* 0x89 (XK_KP_Tab) */
0x000f, /* 0x89 (XK_KP_Tab) */
0x0000,
0x0000,
0x0000,
0x001c, /* 0x8d (XK_KP_Enter) */
0xe01c, /* 0x8d (XK_KP_Enter) */
0x0000,
0x0000,
@@ -498,18 +498,18 @@ static int keysyms_ff[] = {
0x0000, /* 0x92 (XK_KP_F2) */
0x0000, /* 0x93 (XK_KP_F3) */
0x0000, /* 0x94 (XK_KP_F4) */
0x006c, /* 0x95 (XK_KP_Home) */
0x006b, /* 0x96 (XK_KP_Left) */
0x0075, /* 0x97 (XK_KP_Up) */
0x0047, /* 0x95 (XK_KP_Home) */
0x004b, /* 0x96 (XK_KP_Left) */
0x0048, /* 0x97 (XK_KP_Up) */
0x0074, /* 0x98 (XK_KP_Right) */
0x0072, /* 0x99 (XK_KP_Down) */
0x007d, /* 0x9a (XK_KP_Prior,XK_KP_Page_Up) */
0x007a, /* 0x9b (XK_KP_Next,XK_KP_Page_Down) */
0x0069, /* 0x9c (XK_KP_End) */
0x004d, /* 0x98 (XK_KP_Right) */
0x0050, /* 0x99 (XK_KP_Down) */
0x0049, /* 0x9a (XK_KP_Prior,XK_KP_Page_Up) */
0x0051, /* 0x9b (XK_KP_Next,XK_KP_Page_Down) */
0x004f, /* 0x9c (XK_KP_End) */
0x0000, /* 0x9d (XK_KP_Begin) */
0x0000, /* 0x9e (XK_KP_Insert) */
0xe071, /* 0x9f (XK_KP_Delete) */
0x0052, /* 0x9e (XK_KP_Insert) */
0x0053, /* 0x9f (XK_KP_Delete) */
0x0000, /* 0xa0 */
0x0000,
@@ -527,7 +527,7 @@ static int keysyms_ff[] = {
0x0000, /* 0xac (XK_KP_Separator) */
0x004a, /* 0xad (XK_KP_Subtract) */
0x0000, /* 0xae (XK_KP_Decimal) */
0x00b5, /* 0xaf (XK_KP_Divide) */
0x0035, /* 0xaf (XK_KP_Divide) */
0x0052, /* 0xb0 (XK_KP_0) */
0x004f, /* 0xb1 (XK_KP_1) */
@@ -543,7 +543,7 @@ static int keysyms_ff[] = {
0x0000,
0x0000,
0x0000,
0x0000, /* 0xbd (XK_KP_Equal) */
0x000d, /* 0xbd (XK_KP_Equal) */
0x003b, /* 0xbe (XK_F1) */
0x003c, /* 0xbf (XK_F2) */
@@ -589,10 +589,10 @@ static int keysyms_ff[] = {
0x001d, /* 0xe3 (XK_Control_L) */
0xe01d, /* 0xe4 (XK_Control_R) */
0x003a, /* 0xe5 (XK_Caps_Lock) */
0x0000, /* 0xe6 (XK_Shift_Lock) */
0x0000, /* 0xe7 (XK_Meta_L) */
0x003a, /* 0xe6 (XK_Shift_Lock) */
0xe05b, /* 0xe7 (XK_Meta_L) */
0x0000, /* 0xe8 (XK_Meta_R) */
0xe05c, /* 0xe8 (XK_Meta_R) */
0x0038, /* 0xe9 (XK_Alt_L) */
0xe038, /* 0xea (XK_Alt_R) */
0x0000, /* 0xeb (XK_Super_L) */
@@ -624,7 +624,7 @@ static int keysyms_ff[] = {
void
vnc_kbinput(int down, int k)
{
int key, scan;
uint16_t scan;
#if 0
pclog("VNC: kbinput %d %04x\n", down, k);
@@ -652,13 +652,6 @@ vnc_kbinput(int down, int k)
else pclog("VNC: translated to %02x %02x\n", (scan>>8)&0xff, scan&0xff);
#endif
/* First key. */
key = (scan >> 8) & 0xff;
if (key > 0)
recv_key[key] = down;
/* Second key. */
key = scan & 0xff;
if (key > 0)
recv_key[key] = down;
/* Send this scancode sequence to the PC keyboard. */
keyboard_input(down, scan);
}

View File

@@ -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);
}

View File

@@ -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);

View File

@@ -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)
{

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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;