1.26.3.0: Apply bounds and error checking for the joystick configuration (fixes #434)

This commit is contained in:
tomcw 2017-07-03 21:48:21 +01:00
parent 63359637ec
commit 1c145ff154
7 changed files with 46 additions and 18 deletions

View File

@ -251,8 +251,8 @@ DISK_ICON ICON "DISK.ICO"
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,26,2,4
PRODUCTVERSION 1,26,2,4
FILEVERSION 1,26,3,0
PRODUCTVERSION 1,26,3,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
@ -270,12 +270,12 @@ BEGIN
VALUE "Comments", "https://github.com/AppleWin"
VALUE "CompanyName", "AppleWin"
VALUE "FileDescription", "Apple //e Emulator for Windows"
VALUE "FileVersion", "1, 26, 2, 4"
VALUE "FileVersion", "1, 26, 3, 0"
VALUE "InternalName", "APPLEWIN"
VALUE "LegalCopyright", " 1994-2017 Michael O'Brien, Oliver Schmidt, Tom Charlesworth, Michael Pohoreski, Nick Westgate, Linards Ticmanis"
VALUE "OriginalFilename", "APPLEWIN.EXE"
VALUE "ProductName", "Apple //e Emulator"
VALUE "ProductVersion", "1, 26, 2, 4"
VALUE "ProductVersion", "1, 26, 3, 0"
END
END
BLOCK "VarFileInfo"

View File

@ -460,10 +460,10 @@ void GetProgramDirectory(void)
//===========================================================================
// Backwards compatibility with AppleWin <1.24.0
static void LoadConfigOldJoystick(const UINT uJoyNum)
static void LoadConfigOldJoystick_v1(const UINT uJoyNum)
{
DWORD dwOldJoyType;
if (!REGLOAD(TEXT(uJoyNum==0 ? REGVALUE_OLD_JOYSTICK0_EMU_TYPE : REGVALUE_OLD_JOYSTICK1_EMU_TYPE), &dwOldJoyType))
if (!REGLOAD(TEXT(uJoyNum==0 ? REGVALUE_OLD_JOYSTICK0_EMU_TYPE1 : REGVALUE_OLD_JOYSTICK1_EMU_TYPE1), &dwOldJoyType))
return; // EG. Old AppleWin never installed
UINT uNewJoyType;
@ -567,13 +567,17 @@ void LoadConfiguration(void)
DWORD dwJoyType;
if (REGLOAD(TEXT(REGVALUE_JOYSTICK0_EMU_TYPE), &dwJoyType))
JoySetJoyType(JN_JOYSTICK0, dwJoyType);
else if (REGLOAD(TEXT(REGVALUE_OLD_JOYSTICK0_EMU_TYPE2), &dwJoyType)) // GH#434
JoySetJoyType(JN_JOYSTICK0, dwJoyType);
else
LoadConfigOldJoystick(JN_JOYSTICK0);
LoadConfigOldJoystick_v1(JN_JOYSTICK0);
if (REGLOAD(TEXT(REGVALUE_JOYSTICK1_EMU_TYPE), &dwJoyType))
JoySetJoyType(JN_JOYSTICK1, dwJoyType);
else if (REGLOAD(TEXT(REGVALUE_OLD_JOYSTICK1_EMU_TYPE2), &dwJoyType)) // GH#434
JoySetJoyType(JN_JOYSTICK1, dwJoyType);
else
LoadConfigOldJoystick(JN_JOYSTICK1);
LoadConfigOldJoystick_v1(JN_JOYSTICK1);
DWORD dwSoundType;
REGLOAD(TEXT("Sound Emulation"), &dwSoundType);

View File

@ -80,10 +80,12 @@ enum AppMode_e
#define REGVALUE_SAVESTATE_FILENAME "Save State Filename"
#define REGVALUE_SAVE_STATE_ON_EXIT "Save State On Exit"
#define REGVALUE_HDD_ENABLED "Harddisk Enable"
#define REGVALUE_JOYSTICK0_EMU_TYPE "Joystick0 Emu Type" // Added at 1.24.0 (previously was "Joystick 0 Emulation")
#define REGVALUE_JOYSTICK1_EMU_TYPE "Joystick1 Emu Type" // Added at 1.24.0 (previously was "Joystick 1 Emulation")
#define REGVALUE_OLD_JOYSTICK0_EMU_TYPE "Joystick 0 Emulation" // Deprecated from 1.24.0
#define REGVALUE_OLD_JOYSTICK1_EMU_TYPE "Joystick 1 Emulation" // Deprecated from 1.24.0
#define REGVALUE_JOYSTICK0_EMU_TYPE "Joystick0 Emu Type v3" // GH#434: Added at 1.26.3.0 (previously was "Joystick0 Emu Type")
#define REGVALUE_JOYSTICK1_EMU_TYPE "Joystick1 Emu Type v3" // GH#434: Added at 1.26.3.0 (previously was "Joystick1 Emu Type")
#define REGVALUE_OLD_JOYSTICK0_EMU_TYPE2 "Joystick0 Emu Type" // GH#434: Deprecated from 1.26.3.0 (previously was "Joystick 0 Emulation")
#define REGVALUE_OLD_JOYSTICK1_EMU_TYPE2 "Joystick1 Emu Type" // GH#434: Deprecated from 1.26.3.0 (previously was "Joystick 1 Emulation")
#define REGVALUE_OLD_JOYSTICK0_EMU_TYPE1 "Joystick 0 Emulation" // Deprecated from 1.24.0
#define REGVALUE_OLD_JOYSTICK1_EMU_TYPE1 "Joystick 1 Emulation" // Deprecated from 1.24.0
#define REGVALUE_PDL_XTRIM "PDL X-Trim"
#define REGVALUE_PDL_YTRIM "PDL Y-Trim"
#define REGVALUE_SCROLLLOCK_TOGGLE "ScrollLock Toggle"

View File

@ -211,8 +211,12 @@ BOOL CPageInput::DlgProcInternal(HWND hWnd, UINT message, WPARAM wparam, LPARAM
void CPageInput::DlgOK(HWND hWnd)
{
const UINT uNewJoyType0 = SendDlgItemMessage(hWnd, IDC_JOYSTICK0, CB_GETCURSEL, 0, 0);
const UINT uNewJoyType1 = SendDlgItemMessage(hWnd, IDC_JOYSTICK1, CB_GETCURSEL, 0, 0);
UINT uNewJoyType0 = SendDlgItemMessage(hWnd, IDC_JOYSTICK0, CB_GETCURSEL, 0, 0);
if (uNewJoyType0 >= J0C_MAX) uNewJoyType0 = 0; // GH#434
UINT uNewJoyType1 = SendDlgItemMessage(hWnd, IDC_JOYSTICK1, CB_GETCURSEL, 0, 0);
if (uNewJoyType1 >= J1C_MAX) uNewJoyType1 = 0; // GH#434
const bool bIsSlot4Mouse = m_PropertySheetHelper.GetConfigNew().m_Slot[4] == CT_MouseInterface;
if (JoySetEmulationType(hWnd, m_nJoy0ChoiceTranlationTbl[uNewJoyType0], JN_JOYSTICK0, bIsSlot4Mouse))
@ -306,9 +310,9 @@ void CPageInput::InitJoystickChoices(HWND hWnd, int nJoyNum, int nIdcValue)
// . the other Joystick type (if it exists) from this new list
// . the mouse if the mousecard is plugged in
int removedItemCompensation = 0;
for(UINT i=nJC_KEYBD_CURSORS; i<nJC_MAX; i++)
for (UINT i=nJC_KEYBD_CURSORS; i<nJC_MAX; i++)
{
if( ( (i == nJC_KEYBD_CURSORS) || (i == nJC_KEYBD_NUMPAD) ) &&
if ( ( (i == nJC_KEYBD_CURSORS) || (i == nJC_KEYBD_NUMPAD) ) &&
( (JoyGetJoyType(nOtherJoyNum) == nJC_KEYBD_CURSORS) || (JoyGetJoyType(nOtherJoyNum) == nJC_KEYBD_NUMPAD) )
)
{

View File

@ -91,7 +91,12 @@ void CPropertySheetHelper::FillComboBox(HWND window, int controlid, LPCTSTR choi
SendMessage(combowindow, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)choices);
choices += _tcslen(choices)+1;
}
SendMessage(combowindow, CB_SETCURSEL, currentchoice, 0);
if (SendMessage(combowindow, CB_SETCURSEL, currentchoice, 0) == (LRESULT)-1 && currentchoice != -1)
{
_ASSERT(0);
SendMessage(combowindow, CB_SETCURSEL, 0, 0); // GH#434: Failed to set currentchoice, so select item-0
}
}
void CPropertySheetHelper::SaveComputerType(eApple2Type NewApple2Type)

View File

@ -817,6 +817,19 @@ void JoySetJoyType(UINT num, DWORD type)
if (num > JN_JOYSTICK1)
return;
if (num == JN_JOYSTICK0) // GH#434
{
_ASSERT(type < J0C_MAX);
if (type >= J0C_MAX)
return;
}
else
{
_ASSERT(type < J1C_MAX);
if (type >= J1C_MAX)
return;
}
joytype[num] = type;
// Refresh centre positions whenever 'joytype' changes

View File

@ -3,7 +3,7 @@
enum JOYNUM {JN_JOYSTICK0=0, JN_JOYSTICK1};
enum JOY0CHOICE {J0C_DISABLED=0, J0C_JOYSTICK1, J0C_KEYBD_CURSORS, J0C_KEYBD_NUMPAD, J0C_MOUSE, J0C_MAX};
enum JOY1CHOICE {J1C_DISABLED=0, J1C_JOYSTICK2, J1C_KEYBD_CURSORS, J1C_KEYBD_NUMPAD, J1C_MOUSE, J0C_JOYSTICK1_THUMBSTICK2, J1C_MAX};
enum JOY1CHOICE {J1C_DISABLED=0, J1C_JOYSTICK2, J1C_KEYBD_CURSORS, J1C_KEYBD_NUMPAD, J1C_MOUSE, J1C_JOYSTICK1_THUMBSTICK2, J1C_MAX};
enum {JOYSTICK_MODE_FLOATING=0, JOYSTICK_MODE_CENTERING}; // Joystick centering control