2006-02-25 20:50:29 +00:00
|
|
|
/*
|
|
|
|
AppleWin : An Apple //e emulator for Windows
|
|
|
|
|
|
|
|
Copyright (C) 1994-1996, Michael O'Brien
|
|
|
|
Copyright (C) 1999-2001, Oliver Schmidt
|
|
|
|
Copyright (C) 2002-2005, Tom Charlesworth
|
2007-04-01 15:24:52 +00:00
|
|
|
Copyright (C) 2006-2007, Tom Charlesworth, Michael Pohoreski
|
2006-02-25 20:50:29 +00:00
|
|
|
|
|
|
|
AppleWin is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
AppleWin is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with AppleWin; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Description: Keyboard emulation
|
|
|
|
*
|
|
|
|
* Author: Various
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "StdAfx.h"
|
2010-02-14 21:11:26 +00:00
|
|
|
|
2018-02-24 15:12:40 +00:00
|
|
|
#include "Applewin.h"
|
2014-08-13 20:30:35 +00:00
|
|
|
#include "Frame.h"
|
|
|
|
#include "Keyboard.h"
|
2015-05-31 21:53:53 +00:00
|
|
|
#include "Pravets.h"
|
2014-08-13 20:30:35 +00:00
|
|
|
#include "Tape.h"
|
2015-12-05 16:50:27 +00:00
|
|
|
#include "YamlHelper.h"
|
2016-10-22 22:20:23 +00:00
|
|
|
#include "Video.h" // Needed by TK3000 //e, to refresh the frame at each |Mode| change
|
2018-07-27 20:55:53 +00:00
|
|
|
#include "Log.h"
|
2006-02-25 20:50:29 +00:00
|
|
|
|
2006-06-26 16:59:48 +00:00
|
|
|
static BYTE asciicode[2][10] = {
|
2018-07-15 14:38:37 +00:00
|
|
|
// VK_LEFT/UP/RIGHT/DOWN/SELECT, VK_PRINT/EXECUTE/SNAPSHOT/INSERT/DELETE
|
2019-01-19 10:18:16 +00:00
|
|
|
{0x08,0x00,0x15,0x00,0x00, 0x00,0x00,0x00,0x00,0x00}, // Apple II
|
2018-07-15 14:38:37 +00:00
|
|
|
{0x08,0x0B,0x15,0x0A,0x00, 0x00,0x00,0x00,0x00,0x7F} // Apple //e
|
2006-06-26 16:59:48 +00:00
|
|
|
}; // Convert PC arrow keys to Apple keycodes
|
|
|
|
|
2009-02-14 03:35:19 +00:00
|
|
|
bool g_bShiftKey = false;
|
|
|
|
bool g_bCtrlKey = false;
|
|
|
|
bool g_bAltKey = false;
|
|
|
|
|
2016-10-22 22:20:23 +00:00
|
|
|
static bool g_bTK3KModeKey = false; //TK3000 //e |Mode| key
|
|
|
|
|
2009-06-20 13:43:12 +00:00
|
|
|
static bool g_bCapsLock = true; //Caps lock key for Apple2 and Lat/Cyr lock for Pravets8
|
2008-06-20 23:47:25 +00:00
|
|
|
static bool g_bP8CapsLock = true; //Caps lock key of Pravets 8A/C
|
2006-02-25 20:50:29 +00:00
|
|
|
static BYTE keycode = 0; // Current Apple keycode
|
|
|
|
static BOOL keywaiting = 0;
|
2019-03-03 14:32:19 +00:00
|
|
|
static bool g_bAltGrSendsWM_CHAR = false;
|
2006-02-25 20:50:29 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// ----- ALL GLOBALLY ACCESSIBLE FUNCTIONS ARE BELOW THIS LINE -----
|
|
|
|
//
|
|
|
|
|
2019-03-03 14:32:19 +00:00
|
|
|
void KeybSetAltGrSendsWM_CHAR(bool state)
|
|
|
|
{
|
|
|
|
g_bAltGrSendsWM_CHAR = state;
|
|
|
|
}
|
|
|
|
|
2006-02-25 20:50:29 +00:00
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
void KeybReset()
|
|
|
|
{
|
2019-04-16 20:24:32 +00:00
|
|
|
keycode = 0;
|
2006-02-25 20:50:29 +00:00
|
|
|
keywaiting = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
2018-07-27 20:55:53 +00:00
|
|
|
bool KeybGetCapsStatus()
|
2006-02-25 20:50:29 +00:00
|
|
|
{
|
2006-06-26 16:59:48 +00:00
|
|
|
return g_bCapsLock;
|
2006-02-25 20:50:29 +00:00
|
|
|
}
|
2018-07-27 20:55:53 +00:00
|
|
|
|
2008-06-20 23:47:25 +00:00
|
|
|
//===========================================================================
|
|
|
|
bool KeybGetP8CapsStatus()
|
|
|
|
{
|
|
|
|
return g_bP8CapsLock;
|
|
|
|
}
|
2018-07-27 20:55:53 +00:00
|
|
|
|
2008-06-20 23:47:25 +00:00
|
|
|
//===========================================================================
|
2018-07-27 20:55:53 +00:00
|
|
|
bool KeybGetAltStatus()
|
2008-06-20 23:47:25 +00:00
|
|
|
{
|
2018-07-27 20:55:53 +00:00
|
|
|
return g_bAltKey;
|
2008-06-20 23:47:25 +00:00
|
|
|
}
|
2018-07-27 20:55:53 +00:00
|
|
|
|
2006-02-25 20:50:29 +00:00
|
|
|
//===========================================================================
|
2018-07-27 20:55:53 +00:00
|
|
|
bool KeybGetCtrlStatus()
|
2006-02-25 20:50:29 +00:00
|
|
|
{
|
2006-06-26 16:59:48 +00:00
|
|
|
return g_bCtrlKey;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
2018-07-27 20:55:53 +00:00
|
|
|
bool KeybGetShiftStatus()
|
2006-06-26 16:59:48 +00:00
|
|
|
{
|
|
|
|
return g_bShiftKey;
|
2006-02-25 20:50:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
void KeybUpdateCtrlShiftStatus()
|
|
|
|
{
|
2018-07-23 21:27:33 +00:00
|
|
|
g_bAltKey = (GetKeyState( VK_MENU ) < 0) ? true : false; // L or R alt
|
2018-07-27 20:55:53 +00:00
|
|
|
g_bCtrlKey = (GetKeyState( VK_CONTROL) < 0) ? true : false; // L or R ctrl
|
|
|
|
g_bShiftKey = (GetKeyState( VK_SHIFT ) < 0) ? true : false; // L or R shift
|
2006-02-25 20:50:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
2018-06-30 13:30:30 +00:00
|
|
|
BYTE KeybGetKeycode () // Used by IORead_C01x() and TapeRead() for Pravets8A
|
2006-02-25 20:50:29 +00:00
|
|
|
{
|
|
|
|
return keycode;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
2018-07-27 20:55:53 +00:00
|
|
|
|
|
|
|
bool IsVirtualKeyAnAppleIIKey(WPARAM wparam);
|
|
|
|
|
|
|
|
void KeybQueueKeypress (WPARAM key, Keystroke_e bASCII)
|
2006-02-25 20:50:29 +00:00
|
|
|
{
|
2018-05-30 21:38:10 +00:00
|
|
|
if (bASCII == ASCII) // WM_CHAR
|
2006-07-01 06:44:09 +00:00
|
|
|
{
|
2009-02-17 02:25:18 +00:00
|
|
|
if (g_bFreshReset && key == VK_CANCEL) // OLD HACK: 0x03
|
2006-07-01 06:44:09 +00:00
|
|
|
{
|
2009-02-17 02:25:18 +00:00
|
|
|
g_bFreshReset = false;
|
2006-07-01 06:44:09 +00:00
|
|
|
return; // Swallow spurious CTRL-C caused by CTRL-BREAK
|
|
|
|
}
|
2009-01-06 22:02:31 +00:00
|
|
|
|
2009-02-17 02:25:18 +00:00
|
|
|
g_bFreshReset = false;
|
2016-10-22 22:20:23 +00:00
|
|
|
if ((key > 0x7F) && !g_bTK3KModeKey) // When in TK3000 mode, we have special keys which need remapping
|
2006-02-25 20:50:29 +00:00
|
|
|
return;
|
|
|
|
|
2007-05-28 11:16:42 +00:00
|
|
|
if (!IS_APPLE2)
|
2006-07-01 06:44:09 +00:00
|
|
|
{
|
2008-06-20 23:47:25 +00:00
|
|
|
P8Shift = false;
|
2006-07-01 06:44:09 +00:00
|
|
|
if (g_bCapsLock && (key >= 'a') && (key <='z'))
|
2008-06-20 23:47:25 +00:00
|
|
|
{
|
|
|
|
P8Shift = true;
|
2009-01-06 22:02:31 +00:00
|
|
|
keycode = key - 32;
|
2008-06-20 23:47:25 +00:00
|
|
|
}
|
2006-07-01 06:44:09 +00:00
|
|
|
else
|
2008-06-20 23:47:25 +00:00
|
|
|
{
|
2009-01-06 22:02:31 +00:00
|
|
|
keycode = key;
|
2008-06-20 23:47:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//The latter line should be applied for Pravtes 8A/C only, but not for Pravets 82/M !!!
|
|
|
|
if ((g_bCapsLock == false) && (key >= 'A') && (key <='Z'))
|
|
|
|
{
|
2009-01-06 22:02:31 +00:00
|
|
|
P8Shift = true;
|
|
|
|
if (g_Apple2Type == A2TYPE_PRAVETS8A)
|
|
|
|
keycode = key + 32;
|
2008-06-20 23:47:25 +00:00
|
|
|
}
|
2009-01-06 22:02:31 +00:00
|
|
|
|
2008-06-20 23:47:25 +00:00
|
|
|
//Remap some keys for Pravets82/M
|
|
|
|
if (g_Apple2Type == A2TYPE_PRAVETS82)
|
2008-07-26 21:44:35 +00:00
|
|
|
{
|
2009-01-06 22:02:31 +00:00
|
|
|
if (key == 64)
|
|
|
|
keycode = 96;
|
|
|
|
if (key == '^')
|
|
|
|
keycode = '~';
|
|
|
|
|
2009-01-09 21:59:22 +00:00
|
|
|
if (g_bCapsLock == false) //cyrillic letters
|
2008-06-20 23:47:25 +00:00
|
|
|
{
|
|
|
|
if (key == '`') keycode = '^';
|
2008-07-26 21:44:35 +00:00
|
|
|
if (key == 92) keycode = '@'; // \ to @
|
|
|
|
if (key == 124) keycode = 92;
|
2008-06-20 23:47:25 +00:00
|
|
|
}
|
2009-01-09 21:59:22 +00:00
|
|
|
else //(g_bCapsLock == true) //latin letters
|
2009-01-05 22:59:26 +00:00
|
|
|
{
|
2009-01-06 22:02:31 +00:00
|
|
|
if (key == 91) keycode = 123;
|
|
|
|
if (key == 93) keycode = 125;
|
|
|
|
if (key == 124) keycode = 92;
|
2008-07-26 21:44:35 +00:00
|
|
|
}
|
|
|
|
}
|
2009-01-09 21:59:22 +00:00
|
|
|
if (g_Apple2Type == A2TYPE_PRAVETS8M) //Pravets 8M charset is still uncertain
|
|
|
|
{
|
|
|
|
if (g_bCapsLock == false) //cyrillic letters
|
|
|
|
{
|
|
|
|
if (key == '[') keycode = '{';
|
|
|
|
if (key == ']') keycode = '}';
|
|
|
|
if (key == '`') keycode = '~'; //96= key `~
|
|
|
|
if (key == 92) keycode = 96;
|
|
|
|
}
|
|
|
|
else //latin letters
|
|
|
|
{
|
|
|
|
if (key == '`')
|
|
|
|
keycode = '^'; //96= key `~
|
|
|
|
}
|
|
|
|
}
|
2008-06-20 23:47:25 +00:00
|
|
|
//Remap some keys for Pravets8A/C, which has a different charset for Pravtes82/M, whose keys MUST NOT be remapped.
|
|
|
|
if (g_Apple2Type == A2TYPE_PRAVETS8A) //&& (g_bCapsLock == false))
|
2008-07-26 21:52:35 +00:00
|
|
|
{
|
2008-06-20 23:47:25 +00:00
|
|
|
if (g_bCapsLock == false) //i.e. cyrillic letters
|
|
|
|
{
|
2009-01-06 22:02:31 +00:00
|
|
|
if (key == '[') keycode = '{';
|
|
|
|
if (key == ']') keycode = '}';
|
|
|
|
if (key == '`') keycode = '~';
|
|
|
|
if (key == 92) keycode = 96;
|
2010-08-17 07:52:23 +00:00
|
|
|
if (GetCapsLockAllowed() == true)
|
2009-01-06 22:02:31 +00:00
|
|
|
{
|
2019-02-07 18:08:53 +00:00
|
|
|
if ((key == 92) || (key == 124)) keycode = 96; //Ý to Þ
|
2009-01-06 22:02:31 +00:00
|
|
|
//This shall be rewriten, so that enabling CAPS_LOCK (i.e. F10) will not invert these keys values)
|
|
|
|
//The same for latin letters.
|
|
|
|
if ((key == '{') || (key == '}') || (key == '~') || (key == 124) || (key == '^') || (key == 95))
|
|
|
|
P8Shift = true;
|
|
|
|
}
|
2008-06-20 23:47:25 +00:00
|
|
|
}
|
2009-01-06 22:02:31 +00:00
|
|
|
else //i.e. latin letters
|
2008-06-20 23:47:25 +00:00
|
|
|
{
|
2018-07-27 20:55:53 +00:00
|
|
|
if (GetCapsLockAllowed() == false)
|
2008-06-20 23:47:25 +00:00
|
|
|
{
|
2009-01-06 22:02:31 +00:00
|
|
|
if (key == '{') keycode = '[';
|
|
|
|
if (key == '}') keycode = ']';
|
|
|
|
if (key == 124)
|
|
|
|
keycode = 92;
|
|
|
|
/*if (key == 92)
|
|
|
|
keycode = 124;*/
|
2008-07-26 21:44:35 +00:00
|
|
|
//Characters ` and ~ cannot be generated in 7bit character mode, so they are replaced with
|
2008-06-20 23:47:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-01-06 22:02:31 +00:00
|
|
|
if (key == '{') keycode = 91;
|
|
|
|
if (key == '}') keycode = 93;
|
|
|
|
if (key == 124) keycode = 92;
|
|
|
|
if ((key == '[') || (key == ']') || (key == 92) || (key == '^') || (key == 95))
|
|
|
|
P8Shift= true;
|
|
|
|
if (key == 96) //This line shall generate sth. else i.e. ` In fact. this character is not generateable by the pravets keyboard.
|
2008-07-26 21:52:35 +00:00
|
|
|
{
|
|
|
|
keycode = '^';
|
|
|
|
P8Shift= true;
|
|
|
|
}
|
2009-01-06 22:02:31 +00:00
|
|
|
if (key == 126) keycode = '^';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-10-22 22:20:23 +00:00
|
|
|
// Remap for the TK3000 //e, which had a special |Mode| key for displaying accented chars on screen
|
2019-02-07 18:08:53 +00:00
|
|
|
// Borrowed from Fábio Belavenuto's TK3000e emulator (Copyright (C) 2004) - http://code.google.com/p/tk3000e/
|
2016-10-22 22:20:23 +00:00
|
|
|
if (g_bTK3KModeKey) // We already switch this on only if the the TK3000 is currently being emulated
|
|
|
|
{
|
|
|
|
if ((key >= 0xC0) && (key <= 0xDA)) key += 0x20; // Convert uppercase to lowercase
|
|
|
|
switch (key)
|
|
|
|
{
|
2019-02-07 18:08:53 +00:00
|
|
|
case 0xE0: key = '_'; break; // à
|
|
|
|
case 0xE1: key = '@'; break; // á
|
|
|
|
case 0xE2: key = '\\'; break; // â
|
|
|
|
case 0xE3: key = '['; break; // ã
|
|
|
|
case 0xE7: key = ']'; break; // ç
|
|
|
|
case 0xE9: key = '`'; break; // é
|
|
|
|
case 0xEA: key = '&'; break; // ê
|
|
|
|
case 0xED: key = '{'; break; // í
|
|
|
|
case 0xF3: key = '~'; break; // ó
|
|
|
|
case 0xF4: key = '}'; break; // ô
|
|
|
|
case 0xF5: key = '#'; break; // õ
|
|
|
|
case 0xFA: key = '|'; break; // ú
|
2016-10-22 22:20:23 +00:00
|
|
|
}
|
|
|
|
if (key > 0x7F) return; // Get out
|
|
|
|
if ((key >= 'a') && (key <= 'z') && (g_bCapsLock))
|
|
|
|
keycode = key - ('a'-'A');
|
|
|
|
else
|
|
|
|
keycode = key;
|
|
|
|
}
|
2006-07-01 06:44:09 +00:00
|
|
|
}
|
2006-02-25 20:50:29 +00:00
|
|
|
else
|
2006-07-01 06:44:09 +00:00
|
|
|
{
|
2008-06-20 23:47:25 +00:00
|
|
|
if (g_Apple2Type == A2TYPE_PRAVETS8A)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-01-06 22:02:31 +00:00
|
|
|
if (key >= '`')
|
|
|
|
keycode = key - 32;
|
|
|
|
else
|
|
|
|
keycode = key;
|
2008-06-20 23:47:25 +00:00
|
|
|
}
|
2006-07-01 06:44:09 +00:00
|
|
|
}
|
2008-07-26 21:44:35 +00:00
|
|
|
}
|
2018-05-30 21:38:10 +00:00
|
|
|
else //(bASCII != ASCII) // WM_KEYDOWN
|
2006-02-25 20:50:29 +00:00
|
|
|
{
|
2009-02-17 02:25:18 +00:00
|
|
|
// Note: VK_CANCEL is Control-Break
|
2006-06-11 15:49:38 +00:00
|
|
|
if ((key == VK_CANCEL) && (GetKeyState(VK_CONTROL) < 0))
|
2006-02-25 20:50:29 +00:00
|
|
|
{
|
2009-02-17 02:25:18 +00:00
|
|
|
g_bFreshReset = true;
|
|
|
|
CtrlReset();
|
2006-02-25 20:50:29 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((key == VK_INSERT) && (GetKeyState(VK_SHIFT) < 0))
|
|
|
|
{
|
|
|
|
// Shift+Insert
|
|
|
|
ClipboardInitiatePaste();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-10-22 22:20:23 +00:00
|
|
|
if (key == VK_SCROLL)
|
|
|
|
{ // For the TK3000 //e we use Scroll Lock to switch between Apple ][ and accented chars modes
|
|
|
|
if (g_Apple2Type == A2TYPE_TK30002E)
|
|
|
|
{
|
|
|
|
g_bTK3KModeKey = (GetKeyState(VK_SCROLL) & 1) ? true : false; // Sync with the Scroll Lock status
|
|
|
|
FrameRefreshStatus(DRAW_LEDS); // TODO: Implement |Mode| LED in the UI; make it appear only when in TK3000 mode
|
|
|
|
VideoRedrawScreen(); // TODO: Still need to implement page mode switching and 'whatnot'
|
|
|
|
}
|
2018-07-15 14:38:37 +00:00
|
|
|
return;
|
2016-10-22 22:20:23 +00:00
|
|
|
}
|
|
|
|
|
2018-07-15 14:38:37 +00:00
|
|
|
if (key >= VK_LEFT && key <= VK_DELETE)
|
|
|
|
{
|
|
|
|
BYTE n = asciicode[IS_APPLE2 ? 0 : 1][key - VK_LEFT]; // Convert to Apple arrow keycode
|
|
|
|
if (!n)
|
|
|
|
return;
|
|
|
|
keycode = n;
|
|
|
|
}
|
2019-03-03 14:32:19 +00:00
|
|
|
else if (g_bAltGrSendsWM_CHAR && (GetKeyState(VK_RMENU) < 0)) // Right Alt (aka Alt Gr) - GH#558, GH#625
|
2018-07-15 14:38:37 +00:00
|
|
|
{
|
2018-07-27 20:55:53 +00:00
|
|
|
if (IsVirtualKeyAnAppleIIKey(key))
|
|
|
|
{
|
|
|
|
// When Alt Gr is down, then WM_CHAR is not posted - so fix this.
|
|
|
|
// NB. Still get WM_KEYDOWN/WM_KEYUP for the virtual key, so AKD works.
|
|
|
|
WPARAM newKey = key;
|
|
|
|
|
|
|
|
// Translate if shift or ctrl is down
|
|
|
|
if (key >= 'A' && key <= 'Z')
|
|
|
|
{
|
|
|
|
if ( (GetKeyState(VK_SHIFT) >= 0) && !g_bCapsLock )
|
|
|
|
newKey += 'a' - 'A'; // convert to lowercase key
|
2018-07-29 21:34:09 +00:00
|
|
|
else if (GetHookAltGrControl() && GetKeyState(VK_CONTROL) < 0)
|
2018-07-27 20:55:53 +00:00
|
|
|
newKey -= 'A' - 1; // convert to control-key
|
|
|
|
}
|
|
|
|
|
|
|
|
PostMessage(g_hFrameWindow, WM_CHAR, newKey, 0);
|
|
|
|
}
|
|
|
|
|
2018-07-23 21:27:33 +00:00
|
|
|
return;
|
2018-07-15 14:38:37 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-02-25 20:50:29 +00:00
|
|
|
return;
|
2018-07-15 14:38:37 +00:00
|
|
|
}
|
2006-02-25 20:50:29 +00:00
|
|
|
}
|
|
|
|
|
2017-10-29 10:50:08 +00:00
|
|
|
keywaiting = 1;
|
2006-02-25 20:50:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
static HGLOBAL hglb = NULL;
|
|
|
|
static LPTSTR lptstr = NULL;
|
|
|
|
static bool g_bPasteFromClipboard = false;
|
|
|
|
static bool g_bClipboardActive = false;
|
|
|
|
|
|
|
|
void ClipboardInitiatePaste()
|
|
|
|
{
|
|
|
|
if (g_bClipboardActive)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_bPasteFromClipboard = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ClipboardDone()
|
|
|
|
{
|
|
|
|
if (g_bClipboardActive)
|
|
|
|
{
|
|
|
|
g_bClipboardActive = false;
|
|
|
|
GlobalUnlock(hglb);
|
|
|
|
CloseClipboard();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ClipboardInit()
|
|
|
|
{
|
|
|
|
ClipboardDone();
|
|
|
|
|
|
|
|
if (!IsClipboardFormatAvailable(CF_TEXT))
|
|
|
|
return;
|
|
|
|
|
2006-05-14 00:44:38 +00:00
|
|
|
if (!OpenClipboard(g_hFrameWindow))
|
2006-02-25 20:50:29 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
hglb = GetClipboardData(CF_TEXT);
|
|
|
|
if (hglb == NULL)
|
|
|
|
{
|
|
|
|
CloseClipboard();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
lptstr = (char*) GlobalLock(hglb);
|
|
|
|
if (lptstr == NULL)
|
|
|
|
{
|
|
|
|
CloseClipboard();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_bPasteFromClipboard = false;
|
|
|
|
g_bClipboardActive = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char ClipboardCurrChar(bool bIncPtr)
|
|
|
|
{
|
|
|
|
char nKey;
|
|
|
|
int nInc = 1;
|
|
|
|
|
|
|
|
if((lptstr[0] == 0x0D) && (lptstr[1] == 0x0A))
|
|
|
|
{
|
|
|
|
nKey = 0x0D;
|
|
|
|
nInc = 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nKey = lptstr[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
if(bIncPtr)
|
|
|
|
lptstr += nInc;
|
|
|
|
|
|
|
|
return nKey;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
|
2018-06-12 20:50:27 +00:00
|
|
|
const UINT kAKDNumElements = 256/64;
|
|
|
|
static uint64_t g_AKDFlags[2][kAKDNumElements] = { {0,0,0,0}, // normal
|
|
|
|
{0,0,0,0}}; // extended
|
2018-05-30 21:38:10 +00:00
|
|
|
|
2018-07-27 20:55:53 +00:00
|
|
|
static bool IsVirtualKeyAnAppleIIKey(WPARAM wparam)
|
2018-05-30 21:38:10 +00:00
|
|
|
{
|
|
|
|
if (wparam == VK_BACK ||
|
|
|
|
wparam == VK_TAB ||
|
|
|
|
wparam == VK_RETURN ||
|
|
|
|
wparam == VK_ESCAPE ||
|
|
|
|
wparam == VK_SPACE ||
|
|
|
|
(wparam >= VK_LEFT && wparam <= VK_DOWN) ||
|
|
|
|
wparam == VK_DELETE ||
|
|
|
|
(wparam >= '0' && wparam <= '9') ||
|
2018-06-02 21:26:29 +00:00
|
|
|
(wparam >= 'A' && wparam <= 'Z') ||
|
|
|
|
(wparam >= VK_NUMPAD0 && wparam <= VK_NUMPAD9) ||
|
|
|
|
(wparam >= VK_MULTIPLY && wparam <= VK_DIVIDE) ||
|
|
|
|
(wparam >= VK_OEM_1 && wparam <= VK_OEM_3) || // 7 in total
|
|
|
|
(wparam >= VK_OEM_4 && wparam <= VK_OEM_8) || // 5 in total
|
|
|
|
(wparam == VK_OEM_102))
|
2018-07-27 20:55:53 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// NB. Don't need to be concerned about if numpad/cursors are used for joystick,
|
|
|
|
// since parent calls JoyProcessKey() just before this.
|
|
|
|
void KeybAnyKeyDown(UINT message, WPARAM wparam, bool bIsExtended)
|
|
|
|
{
|
|
|
|
if (wparam > 255)
|
|
|
|
{
|
|
|
|
_ASSERT(0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsVirtualKeyAnAppleIIKey(wparam))
|
2018-05-30 21:38:10 +00:00
|
|
|
{
|
2018-06-02 21:26:29 +00:00
|
|
|
UINT offset = wparam >> 6;
|
|
|
|
UINT bit = wparam & 0x3f;
|
2018-06-12 20:50:27 +00:00
|
|
|
UINT idx = !bIsExtended ? 0 : 1;
|
2018-05-30 21:38:10 +00:00
|
|
|
|
2018-06-02 21:26:29 +00:00
|
|
|
if (message == WM_KEYDOWN)
|
2018-06-12 20:50:27 +00:00
|
|
|
g_AKDFlags[idx][offset] |= (1LL<<bit);
|
2018-06-02 21:26:29 +00:00
|
|
|
else
|
2018-06-12 20:50:27 +00:00
|
|
|
g_AKDFlags[idx][offset] &= ~(1LL<<bit);
|
2018-05-30 21:38:10 +00:00
|
|
|
}
|
2018-05-28 16:27:38 +00:00
|
|
|
}
|
|
|
|
|
2018-06-02 21:26:29 +00:00
|
|
|
static bool IsAKD(void)
|
|
|
|
{
|
2018-06-12 20:50:27 +00:00
|
|
|
uint64_t* p = &g_AKDFlags[0][0];
|
|
|
|
|
|
|
|
for (UINT i=0; i<sizeof(g_AKDFlags)/sizeof(g_AKDFlags[0][0]); i++)
|
|
|
|
if (p[i])
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
2018-06-02 21:26:29 +00:00
|
|
|
}
|
|
|
|
|
2018-05-28 16:27:38 +00:00
|
|
|
//===========================================================================
|
|
|
|
|
2018-06-30 13:30:30 +00:00
|
|
|
BYTE KeybReadData (void)
|
2006-02-25 20:50:29 +00:00
|
|
|
{
|
2016-09-06 20:38:00 +00:00
|
|
|
LogFileTimeUntilFirstKeyRead();
|
|
|
|
|
2018-06-02 21:26:29 +00:00
|
|
|
if (g_bPasteFromClipboard)
|
2006-02-25 20:50:29 +00:00
|
|
|
ClipboardInit();
|
|
|
|
|
2018-06-02 21:26:29 +00:00
|
|
|
if (g_bClipboardActive)
|
2006-02-25 20:50:29 +00:00
|
|
|
{
|
|
|
|
if(*lptstr == 0)
|
|
|
|
ClipboardDone();
|
|
|
|
else
|
|
|
|
return 0x80 | ClipboardCurrChar(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
return keycode | (keywaiting ? 0x80 : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
|
2018-06-30 13:30:30 +00:00
|
|
|
BYTE KeybReadFlag (void)
|
2006-02-25 20:50:29 +00:00
|
|
|
{
|
2018-06-02 21:26:29 +00:00
|
|
|
if (g_bPasteFromClipboard)
|
2006-02-25 20:50:29 +00:00
|
|
|
ClipboardInit();
|
|
|
|
|
2018-06-02 21:26:29 +00:00
|
|
|
if (g_bClipboardActive)
|
2006-02-25 20:50:29 +00:00
|
|
|
{
|
|
|
|
if(*lptstr == 0)
|
|
|
|
ClipboardDone();
|
|
|
|
else
|
|
|
|
return 0x80 | ClipboardCurrChar(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
keywaiting = 0;
|
2017-10-29 10:50:08 +00:00
|
|
|
|
2018-05-28 21:36:00 +00:00
|
|
|
if (IS_APPLE2) // Include Pravets machines too?
|
|
|
|
return keycode;
|
|
|
|
|
|
|
|
// AKD
|
|
|
|
|
2018-06-02 21:26:29 +00:00
|
|
|
return keycode | (IsAKD() ? 0x80 : 0);
|
2006-02-25 20:50:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
void KeybToggleCapsLock ()
|
|
|
|
{
|
2007-05-28 11:16:42 +00:00
|
|
|
if (!IS_APPLE2)
|
2006-02-25 20:50:29 +00:00
|
|
|
{
|
2006-06-26 16:59:48 +00:00
|
|
|
g_bCapsLock = (GetKeyState(VK_CAPITAL) & 1);
|
2006-02-25 20:50:29 +00:00
|
|
|
FrameRefreshStatus(DRAW_LEDS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-20 23:47:25 +00:00
|
|
|
//===========================================================================
|
|
|
|
void KeybToggleP8ACapsLock ()
|
|
|
|
{
|
2008-07-28 20:33:22 +00:00
|
|
|
_ASSERT(g_Apple2Type == A2TYPE_PRAVETS8A);
|
2009-01-06 22:02:31 +00:00
|
|
|
P8CAPS_ON = !P8CAPS_ON;
|
|
|
|
FrameRefreshStatus(DRAW_LEDS);
|
|
|
|
// g_bP8CapsLock= g_bP8CapsLock?false:true; //The same as the upper, but slower
|
2008-06-20 23:47:25 +00:00
|
|
|
}
|
|
|
|
|
2006-02-25 20:50:29 +00:00
|
|
|
//===========================================================================
|
|
|
|
|
2015-12-05 16:50:27 +00:00
|
|
|
#define SS_YAML_KEY_LASTKEY "Last Key"
|
2018-11-01 21:14:16 +00:00
|
|
|
#define SS_YAML_KEY_KEYWAITING "Key Waiting"
|
2015-12-05 16:50:27 +00:00
|
|
|
|
|
|
|
static std::string KeybGetSnapshotStructName(void)
|
|
|
|
{
|
|
|
|
static const std::string name("Keyboard");
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
void KeybSaveSnapshot(YamlSaveHelper& yamlSaveHelper)
|
|
|
|
{
|
|
|
|
YamlSaveHelper::Label state(yamlSaveHelper, "%s:\n", KeybGetSnapshotStructName().c_str());
|
2018-06-16 10:36:43 +00:00
|
|
|
yamlSaveHelper.SaveHexUint8(SS_YAML_KEY_LASTKEY, keycode);
|
2018-11-01 21:14:16 +00:00
|
|
|
yamlSaveHelper.SaveBool(SS_YAML_KEY_KEYWAITING, keywaiting ? true : false);
|
2015-12-05 16:50:27 +00:00
|
|
|
}
|
|
|
|
|
2018-11-01 21:14:16 +00:00
|
|
|
void KeybLoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT version)
|
2015-12-05 16:50:27 +00:00
|
|
|
{
|
|
|
|
if (!yamlLoadHelper.GetSubMap(KeybGetSnapshotStructName()))
|
|
|
|
return;
|
|
|
|
|
2018-06-16 10:36:43 +00:00
|
|
|
keycode = (BYTE) yamlLoadHelper.LoadUint(SS_YAML_KEY_LASTKEY);
|
2015-12-05 16:50:27 +00:00
|
|
|
|
2018-11-01 21:14:16 +00:00
|
|
|
if (version == 2)
|
|
|
|
keywaiting = (BOOL) yamlLoadHelper.LoadBool(SS_YAML_KEY_KEYWAITING);
|
|
|
|
|
2015-12-05 16:50:27 +00:00
|
|
|
yamlLoadHelper.PopMap();
|
|
|
|
}
|