Skip to content

Commit

Permalink
Assigning Joystick to BBC Keyboard
Browse files Browse the repository at this point in the history
- Assigning host joystick axes and buttons to BBC keyboard
- Look for disk specific keyboard mapping file (disk name with .kmap extension)
- Look for disk specific extra preferences file
- Fixed displaying buttons assigned to Shift
- Added Unassign to keyboard mapping dialog
- Start "Press key for shifted press..." dialog with "Shifted" checbox checked
  • Loading branch information
monkeyman79 committed Jan 30, 2021
1 parent 037ae3a commit 1eac76b
Show file tree
Hide file tree
Showing 13 changed files with 615 additions and 50 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ Ken Lowe, Dominic Beesley)
* Fixed BCD mode in ADC and SBC instructions.
* Fixed key selection dialog box layout for Windows 10.
* Added -DebugLabels command line option to load BeebAsm compatible debug labels.
* Added PC joystick to BBC keyboard mapping.

Version 4.14 (J.G.Harston, Steve Pick, Mike Wyatt)
------------
Expand Down
64 changes: 64 additions & 0 deletions Documents/KeyMapInfo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,67 @@ Data for default key mapping:
-9 0 0 -9 0 1
-9 0 0 -9 0 1
-9 0 0 -9 0 1 // 255
-9 0 0 -9 0 1 // 256 - Joystick 1 Up
-9 0 0 -9 0 1 // Joystick 1 Down
-9 0 0 -9 0 1 // Joystick 1 Left
-9 0 0 -9 0 1 // Joystick 1 Right
-9 0 0 -9 0 1 // Joystick 1 Axis 3 - (Z-)
-9 0 0 -9 0 1 // Joystick 1 Axis 3 + (Z+)
-9 0 0 -9 0 1 // Joystick 1 Axis 4 - (R-)
-9 0 0 -9 0 1 // Joystick 1 Axis 4 + (R+)
-9 0 0 -9 0 1 // Joystick 1 Axis 5 - (U-)
-9 0 0 -9 0 1 // Joystick 1 Axis 5 + (U+)
-9 0 0 -9 0 1 // Joystick 1 Axis 6 - (V-)
-9 0 0 -9 0 1 // Joystick 1 Axis 6 + (V+)
-9 0 0 -9 0 1 // Joystick 1 Axis 7 - (Hat Up)
-9 0 0 -9 0 1 // Joystick 1 Axis 7 + (Hat Down)
-9 0 0 -9 0 1 // Joystick 1 Axis 8 - (Hat Left)
-9 0 0 -9 0 1 // Joystick 1 Axis 8 + (Hat Right)
-9 0 0 -9 0 1 // 272 - Joystick 1 Button 1
-9 0 0 -9 0 1 // Joystick 1 Button 2
-9 0 0 -9 0 1 // Joystick 1 Button 3
-9 0 0 -9 0 1 // Joystick 1 Button 4
-9 0 0 -9 0 1 // Joystick 1 Button 5
-9 0 0 -9 0 1 // Joystick 1 Button 6
-9 0 0 -9 0 1 // Joystick 1 Button 7
-9 0 0 -9 0 1 // Joystick 1 Button 8
-9 0 0 -9 0 1 // Joystick 1 Button 9
-9 0 0 -9 0 1 // Joystick 1 Button 10
-9 0 0 -9 0 1 // Joystick 1 Button 11
-9 0 0 -9 0 1 // Joystick 1 Button 12
-9 0 0 -9 0 1 // Joystick 1 Button 13
-9 0 0 -9 0 1 // Joystick 1 Button 14
-9 0 0 -9 0 1 // Joystick 1 Button 15
-9 0 0 -9 0 1 // Joystick 1 Button 16
-9 0 0 -9 0 1 // 288 - Joystick 2 Up
-9 0 0 -9 0 1 // Joystick 2 Down
-9 0 0 -9 0 1 // Joystick 2 Left
-9 0 0 -9 0 1 // Joystick 2 Right
-9 0 0 -9 0 1 // Joystick 2 Axis 3 - (Z-)
-9 0 0 -9 0 1 // Joystick 2 Axis 3 + (Z+)
-9 0 0 -9 0 1 // Joystick 2 Axis 4 - (R-)
-9 0 0 -9 0 1 // Joystick 2 Axis 4 + (R+)
-9 0 0 -9 0 1 // Joystick 2 Axis 5 - (U-)
-9 0 0 -9 0 1 // Joystick 2 Axis 5 + (U+)
-9 0 0 -9 0 1 // Joystick 2 Axis 6 - (V-)
-9 0 0 -9 0 1 // Joystick 2 Axis 6 + (V+)
-9 0 0 -9 0 1 // Joystick 2 Axis 7 - (Hat Up)
-9 0 0 -9 0 1 // Joystick 2 Axis 7 + (Hat Down)
-9 0 0 -9 0 1 // Joystick 2 Axis 8 - (Hat Left)
-9 0 0 -9 0 1 // Joystick 2 Axis 8 + (Hat Right)
-9 0 0 -9 0 1 // 304 - Joystick 2 Button 1
-9 0 0 -9 0 1 // Joystick 2 Button 2
-9 0 0 -9 0 1 // Joystick 2 Button 3
-9 0 0 -9 0 1 // Joystick 2 Button 4
-9 0 0 -9 0 1 // Joystick 2 Button 5
-9 0 0 -9 0 1 // Joystick 2 Button 6
-9 0 0 -9 0 1 // Joystick 2 Button 7
-9 0 0 -9 0 1 // Joystick 2 Button 8
-9 0 0 -9 0 1 // Joystick 2 Button 9
-9 0 0 -9 0 1 // Joystick 2 Button 10
-9 0 0 -9 0 1 // Joystick 2 Button 11
-9 0 0 -9 0 1 // Joystick 2 Button 12
-9 0 0 -9 0 1 // Joystick 2 Button 13
-9 0 0 -9 0 1 // Joystick 2 Button 14
-9 0 0 -9 0 1 // Joystick 2 Button 15
-9 0 0 -9 0 1 // 319 - Joystick 2 Button 16
57 changes: 54 additions & 3 deletions Help/keyboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,62 @@ <h2>Custom Key Mappings</h2>
or save a new file.</li>

<li>Select your mapping using menu item "Options -> User Defined Mapping".
You can also use the "Save Preferences" option to save the default user
key mapping file that gets loaded when BeebEm starts up.</li>
You can also use the "Save Preferences" option to save the default user
key mapping file that gets loaded when BeebEm starts up.</li>
</ol>

<!-- End of content -->
<h2>Mappings PC Joystick to BBC Keys</h2>

<p>To enable PC joystick to BBC keys mapping, use menu item "Options ->
Joystick To Key Mapping". Most likely you will also need to switch to
user defined keyboard mapping using menu item "Option -> User Defined
Mapping". This will allow you to use your own PC joystick to BBC keys
assignments.</p>

<p>Mapping PC joystick axes and buttons to BBC keys is very similar to
mapping PC keys, as described above. Instead of pressing PC key, press
the joystick button or move the joystick in the direction that you want
to map to the selected BBC key. Just make sure that the "Joystick To
Key Mapping" option is enabled.</p>

<p>As with PC keys, you can map joystick actions to BBC keys in shifted and
unshifted state separately. The most common scenario is to assign a
joystick action to the same BBC key in both shifted and unshifted state.
To do that, just click on the BBC key that you want to map, and move
joystick or press button twice - once for unshifted and second time for
shifted state.</p>

<p>Additionally, you can assign some joystick button to the SHIFT key itself.
This can be exploited to assign one joystick button as a modifier for
other joystick actions - useful for games which have a lot of keyboard
contols such as Elite.</p>

<p>PC joystick to BBC keyboard mapping is independed from enabling PC joystick
acting as BBC joystick. If you enable both, primary PC joystick axes
(primary stick up, down, left and right) and first two buttons are mapped
to BBC joystick. You can map other axes and buttons to BBC keys. You can
even map those axes and buttons which are acting as BBC joystick to BBC
keys. In that case, the PC joystick action will be seen as both BBC
joystick action and BBC key press.</p>

<p>To remove mapping from previously mapped joystick action, click on the
'Unassign' button. It will display small window and wait for the
joystick action. Press the joystick button or move the joystick in the
direction that you want to unmap. The same window will be displayed again,
giving you opportunity to unmap the joystick action in both unshifted and
shifted state at one go. You can press 'OK' button at this moment to
skip the second unassignment.</p>

<p>Joystick mappings are kept together with keyboard mappings in .kmap files.
Once joystick mapping for a game is ready, click menu item "Options ->
Save User Key Mapping". Save the mapping in the directory where the disk
image is located and with the same name as disk image, but with additional
'.kmap' extension. For example, if the game's disk image is 'game.ssd',
save the mapping as 'game.ssd.kmap'. Next time you open this image with
BeebEm, it will automatically load keyboard and joystick mapping from that
mapping file.</p>

<!-- End of content -->
</td>

<td width="10%"></td>
Expand Down
7 changes: 7 additions & 0 deletions Help/menus.html
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,13 @@ <h2>Options Menu</h2>
</td>
</tr>

<tr>
<td width="20%">Joystick To Key Mapping</td>
<td width="80%">Switch on or off mapping PC joystick to BBC keyboard.
See the <a href="keyboard.html">Keyboard Mappings</a> section.
</td>
</tr>

<tr>
<td width="20%">Freeze when inactive</td>
<td width="80%">When selected BeebEm will freeze when you switch
Expand Down
16 changes: 9 additions & 7 deletions Src/BeebEm.rc
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ BEGIN
CONTROL "_ �",IDK_UNDERSCORE,"Button",BS_OWNERDRAW | WS_TABSTOP,269,33,17,14
CONTROL "^ ~",IDK_CARET,"Button",BS_OWNERDRAW | WS_TABSTOP,243,19,17,14
CONTROL "SFT LK",IDK_SHIFT_LOCK,"Button",BS_OWNERDRAW | WS_TABSTOP,9,62,29,14
CONTROL "Unassign",IDK_UNASSIGN,"Button",BS_OWNERDRAW | WS_TABSTOP,9,101,36,14
END

IDD_KEYBOARD_LINKS DIALOG 0, 0, 160, 66
Expand Down Expand Up @@ -165,7 +166,7 @@ STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | WS_CAPT
CAPTION "Press key for unshifted press..."
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
LTEXT "Assigned to PC key(s):",IDC_STATIC,7,7,74,8
LTEXT "Assigned to PC key(s):",IDC_ASSIGNED_KEYS_LBL,7,7,74,8
LTEXT "Static",IDC_ASSIGNED_KEYS,15,21,127,8
CONTROL "Shift",IDC_SHIFT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,15,40,31,10
PUSHBUTTON "OK",IDOK,92,39,50,14
Expand Down Expand Up @@ -330,9 +331,9 @@ END
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION VERSION_MAJOR,VERSION_MINOR,0,0
PRODUCTVERSION VERSION_MAJOR,VERSION_MINOR,0,0
FILEFLAGSMASK 0x3fL
FILEVERSION VERSION_MAJOR,VERSION_MINOR,0,0
PRODUCTVERSION VERSION_MAJOR,VERSION_MINOR,0,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
Expand All @@ -354,8 +355,8 @@ BEGIN
VALUE "LegalCopyright", "Copyright � 2009"
VALUE "OriginalFilename", "BeebEm.exe"
VALUE "ProductName", "BeebEm"
VALUE "ProductVersion", VERSION_STRING
END
VALUE "ProductVersion", VERSION_STRING
END
END
BLOCK "VarFileInfo"
BEGIN
Expand Down Expand Up @@ -710,7 +711,8 @@ BEGIN
MENUITEM "&Joystick", IDM_JOYSTICK
MENUITEM "&Analogue Mousestick", IDM_ANALOGUE_MOUSESTICK
MENUITEM "&Digital Mousestick", IDM_DIGITAL_MOUSESTICK
MENUITEM "&Freeze when inactive", IDM_FREEZEINACTIVE
MENUITEM "Joystick To Key Mapping", IDM_JOYSTICK_TO_KEYS
MENUITEM "&Freeze when inactive", IDM_FREEZEINACTIVE
MENUITEM "&Hide Cursor", IDM_HIDECURSOR
MENUITEM SEPARATOR
MENUITEM "&Define User Key Mapping", IDM_DEFINEKEYMAP
Expand Down
78 changes: 76 additions & 2 deletions Src/SelectKeyDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Boston, MA 02110-1301, USA.
/****************************************************************************/

static bool IsDlgItemChecked(HWND hDlg, int nIDDlgItem);
static void DlgItemCheck(HWND hDlg, int nIDDlgItem, bool checked);

SelectKeyDialog* selectKeyDialog;

Expand All @@ -40,14 +41,15 @@ SelectKeyDialog::SelectKeyDialog(
HINSTANCE hInstance,
HWND hwndParent,
const std::string& Title,
const std::string& SelectedKey) :
const std::string& SelectedKey,
bool doingShifted) :
m_hInstance(hInstance),
m_hwnd(nullptr),
m_hwndParent(hwndParent),
m_Title(Title),
m_SelectedKey(SelectedKey),
m_Key(-1),
m_Shift(false)
m_Shift(doingShifted)
{
}

Expand Down Expand Up @@ -101,16 +103,28 @@ INT_PTR SelectKeyDialog::DlgProc(
SetWindowText(m_hwnd, m_Title.c_str());

SetDlgItemText(m_hwnd, IDC_ASSIGNED_KEYS, m_SelectedKey.c_str());

// If the selected keys is empty (as opposed to "Not assigned"), we are currently unassigning.
// Hide the "Assigned to:" label
if (m_SelectedKey.empty())
SetDlgItemText(m_hwnd, IDC_ASSIGNED_KEYS_LBL, "");

// If doing shifted key, start with the Shift checkbox checked because that's most likely
// what the user wants
DlgItemCheck(m_hwnd, IDC_SHIFT, m_Shift);

return TRUE;

case WM_ACTIVATE:
if (LOWORD(wParam) == WA_INACTIVE)
{
hCurrentDialog = nullptr;
mainWin->m_JoystickTarget = nullptr;
}
else
{
hCurrentDialog = m_hwnd;
mainWin->m_JoystickTarget = m_hwnd;
hCurrentAccelTable = nullptr;
}
break;
Expand Down Expand Up @@ -186,22 +200,82 @@ int SelectKeyDialog::Key() const

/****************************************************************************/

bool SelectKeyDialog::Shift() const
{
return m_Shift;
}

/****************************************************************************/

static bool IsDlgItemChecked(HWND hDlg, int nIDDlgItem)
{
return SendDlgItemMessage(hDlg, nIDDlgItem, BM_GETCHECK, 0, 0) == BST_CHECKED;
}

/****************************************************************************/

static void DlgItemCheck(HWND hDlg, int nIDDlgItem, bool checked)
{
SendDlgItemMessage(hDlg, nIDDlgItem, BM_SETCHECK, checked ? BST_CHECKED : BST_UNCHECKED, 0);
}

/****************************************************************************/

LPCSTR SelectKeyDialog::KeyName(int Key)
{
static CHAR Character[2]; // Used to return single characters.

if (Key >= 256 && Key < BEEB_VKEY_COUNT)
{
static CHAR Name[16]; // Buffer for joystick button or axis name
Key -= 256;
if (Key > BEEB_VKEY_JOY2_AXES - BEEB_VKEY_JOY1_AXES)
{
strcpy(Name, "Joy2");
Key -= BEEB_VKEY_JOY2_AXES - BEEB_VKEY_JOY1_AXES;
}
else
{
strcpy(Name, "Joy1");
}

if (Key < BEEB_VKEY_JOY1_BTN1 - BEEB_VKEY_JOY1_AXES)
{
if (Key == BEEB_JOY_AX_UP)
{
strcat(Name, "Up");
}
else if (Key == BEEB_JOY_AX_DOWN)
{
strcat(Name, "Down");
}
else if (Key == BEEB_JOY_AX_LEFT)
{
strcat(Name, "Left");
}
else if (Key == BEEB_JOY_AX_RIGHT)
{
strcat(Name, "Right");
}
else
{
sprintf(Name + strlen(Name), "Axis%d", (Key / 2) + 1);
strcat(Name, (Key & 1) ? "+" : "-");
}
}
else
{
sprintf(Name + strlen(Name), "Btn%d", Key - (BEEB_VKEY_JOY1_BTN1 - BEEB_VKEY_JOY1_AXES) + 1);
}
return Name;
}

switch (Key)
{
case 8: return "Backspace";
case 9: return "Tab";
case 13: return "Enter";
case 16: return "Shift";
case 17: return "Ctrl";
case 18: return "Alt";
case 19: return "Break";
Expand Down
4 changes: 3 additions & 1 deletion Src/SelectKeyDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class SelectKeyDialog
HINSTANCE hInstance,
HWND hwndParent,
const std::string& Title,
const std::string& SelectedKey
const std::string& SelectedKey,
bool doingShifted = false
);

bool Open();
Expand All @@ -39,6 +40,7 @@ class SelectKeyDialog
bool HandleMessage(const MSG& msg);

int Key() const;
bool Shift() const;

static LPCSTR KeyName(int Key);

Expand Down
9 changes: 6 additions & 3 deletions Src/beebemrc.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ Boston, MA 02110-1301, USA.
#define IDK_BACKSLASH 81
#define IDK_UNDERSCORE 82
#define IDK_CARET 83
#define IDK_UNASSIGN 84
#define IDR_MENU 101
#define IDI_BEEBEM 102
#define IDD_USERKYBRD 103
Expand Down Expand Up @@ -186,6 +187,7 @@ Boston, MA 02110-1301, USA.
#define IDC_SHIFT 1088
#define IDC_DEBUGTELETEXTBRK 1089
#define IDC_ASSIGNED_KEYS 1090
#define IDC_ASSIGNED_KEYS_LBL 1091
#define IDM_ABOUT 40001
#define IDM_DISC 40002
#define IDM_LOADDISC0 40002
Expand Down Expand Up @@ -433,16 +435,17 @@ Boston, MA 02110-1301, USA.
#define ID_VIEW_DD_2560X1440 40294
#define ID_VIEW_DD_3840X2160 40295
#define IDM_EMUPAUSED 40296
#define IDM_JOYSTICK_TO_KEYS 40297
#define IDC_STATIC -1

// Next default values for new objects
//
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NO_MFC 1
#define _APS_NEXT_RESOURCE_VALUE 118
#define _APS_NEXT_COMMAND_VALUE 40297
#define _APS_NEXT_CONTROL_VALUE 1090
#define _APS_NEXT_COMMAND_VALUE 40298
#define _APS_NEXT_CONTROL_VALUE 1092
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
Loading

0 comments on commit 1eac76b

Please sign in to comment.