Fix Wizardry crash when open Config dialog on Wizardry's Start Page:

- Needed to init the Serial Port menu choices
- Added extra NULL check too
Cleaned-up PropertySheetPage.cpp code.
This commit is contained in:
tomch 2009-12-12 11:04:22 +00:00
parent 8238547a1c
commit 0aec4c7f63
3 changed files with 695 additions and 680 deletions

View File

@ -47,12 +47,10 @@ TCHAR* szJoyChoice3 = TEXT("Keyboard (standard)\0");
TCHAR* szJoyChoice4 = TEXT("Keyboard (centering)\0");
TCHAR* szJoyChoice5 = TEXT("Mouse\0");
const int g_nMaxJoyChoiceLen = 40;
bool ConfigRun = false;
static const int g_nMaxJoyChoiceLen = 40;
//eApple2Type NewApple2Type = 0;
DWORD NewApple2Type = 0;
DWORD NewCloneType = 0;
DWORD NewApple2Combo = 0;
static DWORD NewApple2Type = 0; // TC-FIXME: Also a local NewApple2Type!
static DWORD NewCloneType = 0; // TC-FIXME: Also a local NewCloneType!
enum JOY0CHOICE {J0C_DISABLED=0, J0C_JOYSTICK1, J0C_KEYBD_STANDARD, J0C_KEYBD_CENTERING, J0C_MOUSE, J0C_MAX};
TCHAR* pszJoy0Choices[J0C_MAX] = { szJoyChoice0,
@ -104,7 +102,6 @@ char *g_apVideoModeDesc[ NUM_VIDEO_MODES ] =
TCHAR discchoices[] = TEXT("Authentic Speed\0")
TEXT("Enhanced Speed\0");
const UINT VOLUME_MIN = 0;
const UINT VOLUME_MAX = 59;
@ -130,35 +127,38 @@ static UINT g_bEnableFreezeDlgButton = UNDEFINED;
//
enum {
enum
{
CLONETYPE_PRAVETS82=0,
CLONETYPE_PRAVETS8M,
CLONETYPE_PRAVETS8A,
CLONETYPE_NUM
};
DWORD g_uCloneType = CLONETYPE_PRAVETS82 ;
DWORD g_uCloneType = CLONETYPE_PRAVETS82;
static TCHAR g_CloneChoices[] = TEXT("Pravets 82\0") // Bulgarian
TEXT("Pravets 8M\0") // Bulgarian
TEXT("Pravets 8A\0"); // Bulgarian
//===========================================================================
static void FillComboBox (HWND window, int controlid, LPCTSTR choices, int currentchoice)
static void FillComboBox(HWND window, int controlid, LPCTSTR choices, int currentchoice)
{
HWND combowindow = GetDlgItem(window,controlid);
SendMessage(combowindow,CB_RESETCONTENT,0,0);
while (*choices) {
SendMessage(combowindow,CB_ADDSTRING,0,(LPARAM)(LPCTSTR)choices);
_ASSERT(choices);
HWND combowindow = GetDlgItem(window, controlid);
SendMessage(combowindow, CB_RESETCONTENT, 0, 0);
while (choices && *choices)
{
SendMessage(combowindow, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)choices);
choices += _tcslen(choices)+1;
}
SendMessage(combowindow,CB_SETCURSEL,currentchoice,0);
SendMessage(combowindow, CB_SETCURSEL, currentchoice, 0);
}
//===========================================================================
static void EnableTrackbar (HWND window, BOOL enable)
static void EnableTrackbar(HWND window, BOOL enable)
{
EnableWindow(GetDlgItem(window,IDC_SLIDER_CPU_SPEED),enable);
EnableWindow(GetDlgItem(window,IDC_0_5_MHz),enable);
@ -182,7 +182,6 @@ static void InitJoystickChoices(HWND window, int nJoyNum, int nIdcValue)
TCHAR** ppszJoyChoices;
int nOtherJoyNum = nJoyNum == JN_JOYSTICK0 ? JN_JOYSTICK1 : JN_JOYSTICK0;
if(nJoyNum == JN_JOYSTICK0)
{
pnzJoystickChoices = joystick0choices;
@ -227,7 +226,9 @@ static void InitJoystickChoices(HWND window, int nJoyNum, int nIdcValue)
if( ( (i == nJC_KEYBD_STANDARD) || (i == nJC_KEYBD_CENTERING) ) &&
( (joytype[nOtherJoyNum] == nJC_KEYBD_STANDARD) || (joytype[nOtherJoyNum] == nJC_KEYBD_CENTERING) )
)
{
continue;
}
if(joytype[nOtherJoyNum] != i)
{
@ -263,8 +264,8 @@ static eApple2Type GetApple2Type(DWORD NewCompType, DWORD NewCloneType)
}
}
// ====================================================================
void Config_Save_Video()
{
REGSAVE(TEXT(REGVALUE_VIDEO_MODE ),g_eVideoType);
@ -273,6 +274,7 @@ void Config_Save_Video()
}
// ====================================================================
void Config_Load_Video()
{
REGLOAD(TEXT(REGVALUE_VIDEO_MODE ),&g_eVideoType);
@ -331,7 +333,7 @@ static void ConfigDlg_OK(HWND window, UINT afterclose)
SetCurrentCLK6502();
if (NewApple2Type > A2TYPE_CLONE)
NewCloneType = NewApple2Type - A2TYPE_CLONE;
NewCloneType = NewApple2Type - A2TYPE_CLONE; // TC-FIXME: Must be global scope (ie. g_NewCloneType)
if ((NewApple2Type == A2TYPE_PRAVETS82) || (NewApple2Type == A2TYPE_PRAVETS8A) || (NewApple2Type == A2TYPE_PRAVETS8M))
REGSAVE(TEXT(REGVALUE_APPLE2_TYPE),A2TYPE_CLONE );
@ -360,10 +362,11 @@ static void ConfigDlg_CANCEL(HWND window)
//---------------------------------------------------------------------------
static BOOL CALLBACK ConfigDlgProc (HWND window,
static BOOL CALLBACK ConfigDlgProc( HWND window,
UINT message,
WPARAM wparam,
LPARAM lparam) {
LPARAM lparam)
{
static UINT afterclose = 0;
switch (message)
@ -385,7 +388,6 @@ static BOOL CALLBACK ConfigDlgProc (HWND window,
case PSN_APPLY:
SetWindowLong(window, DWL_MSGRESULT, PSNRET_NOERROR); // Changes are valid
ConfigDlg_OK(window, afterclose);
ConfigRun = true;
break;
case PSN_QUERYCANCEL:
// Can use this to ask user to confirm cancel
@ -439,7 +441,8 @@ static BOOL CALLBACK ConfigDlgProc (HWND window,
TEXT("itself the next time it is started.\n\n")
TEXT("Would you like to restart the emulator now?"),
TEXT("Configuration"),
MB_ICONQUESTION | MB_YESNO | MB_SETFOREGROUND) == IDYES) {
MB_ICONQUESTION | MB_YESNO | MB_SETFOREGROUND) == IDYES)
{
afterclose = WM_USER_RESTART;
PropSheet_PressButton(GetParent(window), PSBTN_OK);
}
@ -503,19 +506,18 @@ static BOOL CALLBACK ConfigDlgProc (HWND window,
case WM_LBUTTONDOWN:
{
POINT pt = {LOWORD(lparam),
HIWORD(lparam)};
POINT pt = { LOWORD(lparam), HIWORD(lparam) };
ClientToScreen(window,&pt);
RECT rect;
GetWindowRect(GetDlgItem(window,IDC_SLIDER_CPU_SPEED),&rect);
if ((pt.x >= rect.left) && (pt.x <= rect.right) &&
(pt.y >= rect.top) && (pt.y <= rect.bottom)) {
(pt.y >= rect.top) && (pt.y <= rect.bottom))
{
CheckRadioButton(window, IDC_AUTHENTIC_SPEED, IDC_CUSTOM_SPEED, IDC_CUSTOM_SPEED);
EnableTrackbar(window,1);
SetFocus(GetDlgItem(window,IDC_SLIDER_CPU_SPEED));
ScreenToClient(GetDlgItem(window,IDC_SLIDER_CPU_SPEED),&pt);
PostMessage(GetDlgItem(window,IDC_SLIDER_CPU_SPEED),WM_LBUTTONDOWN,
wparam,MAKELONG(pt.x,pt.y));
PostMessage(GetDlgItem(window,IDC_SLIDER_CPU_SPEED),WM_LBUTTONDOWN,wparam,MAKELONG(pt.x,pt.y));
}
break;
}
@ -524,6 +526,7 @@ static BOOL CALLBACK ConfigDlgProc (HWND window,
SendDlgItemMessage(window,IDC_SLIDER_CPU_SPEED,WM_SYSCOLORCHANGE,0,0);
break;
}
return 0;
}
@ -574,7 +577,7 @@ static void InputDlg_CANCEL(HWND window)
//---------------------------------------------------------------------------
static BOOL CALLBACK InputDlgProc (HWND window,
static BOOL CALLBACK InputDlgProc(HWND window,
UINT message,
WPARAM wparam,
LPARAM lparam)
@ -603,7 +606,7 @@ static BOOL CALLBACK InputDlgProc (HWND window,
InputDlg_CANCEL(window);
break;
/* // Could use this to display PDL() value
/* // Could use this to display PDL() value
case UDN_DELTAPOS:
LPNMUPDOWN lpnmud = (LPNMUPDOWN) lparam;
if (lpnmud->hdr.idFrom == IDC_SPIN_XTRIM)
@ -619,7 +622,7 @@ static BOOL CALLBACK InputDlgProc (HWND window,
y = SendDlgItemMessage(window, IDC_SPIN_YTRIM, UDM_GETPOS, 0, 0);
}
break;
*/
*/
}
}
break;
@ -1211,12 +1214,12 @@ static void AdvancedDlg_OK(HWND window, UINT afterclose)
"you shall set the emulated computer type "
"to Clone from the Configuration tab.\n\n"),
TEXT("Clone type changed"),
MB_ICONQUESTION | MB_OK | MB_SETFOREGROUND) ;
MB_ICONQUESTION | MB_OK | MB_SETFOREGROUND);
g_uCloneType = NewApple2Clone - (APPLECLONE_MASK|APPLE2E_MASK);
}
}
if (NewApple2Type > A2TYPE_APPLE2PLUS)
if (NewApple2Type > A2TYPE_APPLE2PLUS) // TC-FIXME: Must be global scope (ie. g_NewApple2Type)
g_uTheFreezesF8Rom = false;
//
@ -1354,11 +1357,13 @@ static BOOL CALLBACK AdvancedDlgProc (HWND window,
static BOOL get_tfename(int number, char **ppname, char **ppdescription)
{
if (tfe_enumadapter_open()) {
if (tfe_enumadapter_open())
{
char *pname = NULL;
char *pdescription = NULL;
while (number--) {
while (number--)
{
if (!tfe_enumadapter(&pname, &pdescription))
break;
@ -1366,7 +1371,8 @@ static BOOL get_tfename(int number, char **ppname, char **ppdescription)
lib_free(pdescription);
}
if (tfe_enumadapter(&pname, &pdescription)) {
if (tfe_enumadapter(&pname, &pdescription))
{
*ppname = pname;
*ppdescription = pdescription;
tfe_enumadapter_close();
@ -1375,6 +1381,7 @@ static BOOL get_tfename(int number, char **ppname, char **ppdescription)
tfe_enumadapter_close();
}
return FALSE;
}
@ -1389,37 +1396,40 @@ static int gray_ungray_items(HWND hwnd)
REGLOAD(TEXT("Uthernet Disabled") ,(DWORD *)&disabled);
get_disabled_state(&disabled);
if (disabled) {
if (disabled)
{
EnableWindow(GetDlgItem(hwnd, IDC_TFE_SETTINGS_ENABLE_T), 0);
EnableWindow(GetDlgItem(hwnd, IDC_TFE_SETTINGS_ENABLE), 0);
EnableWindow(GetDlgItem(hwnd, IDOK), 0);
SetWindowText(GetDlgItem(hwnd,IDC_TFE_SETTINGS_INTERFACE_NAME), "");
SetWindowText(GetDlgItem(hwnd,IDC_TFE_SETTINGS_INTERFACE_DESC), "");
enable = 0;
} else {
enable = SendMessage(GetDlgItem(hwnd, IDC_TFE_SETTINGS_ENABLE),
CB_GETCURSEL, 0, 0) ? 1 : 0;
}
else
{
enable = SendMessage(GetDlgItem(hwnd, IDC_TFE_SETTINGS_ENABLE), CB_GETCURSEL, 0, 0) ? 1 : 0;
}
EnableWindow(GetDlgItem(hwnd, IDC_TFE_SETTINGS_INTERFACE_T), enable);
EnableWindow(GetDlgItem(hwnd, IDC_TFE_SETTINGS_INTERFACE), enable);
if (enable) {
if (enable)
{
char *pname = NULL;
char *pdescription = NULL;
number = SendMessage(GetDlgItem(hwnd, IDC_TFE_SETTINGS_INTERFACE),
CB_GETCURSEL, 0, 0);
number = SendMessage(GetDlgItem(hwnd, IDC_TFE_SETTINGS_INTERFACE), CB_GETCURSEL, 0, 0);
if (get_tfename(number, &pname, &pdescription)) {
SetWindowText(GetDlgItem(hwnd, IDC_TFE_SETTINGS_INTERFACE_NAME),
pname);
SetWindowText(GetDlgItem(hwnd, IDC_TFE_SETTINGS_INTERFACE_DESC),
pdescription);
if (get_tfename(number, &pname, &pdescription))
{
SetWindowText(GetDlgItem(hwnd, IDC_TFE_SETTINGS_INTERFACE_NAME), pname);
SetWindowText(GetDlgItem(hwnd, IDC_TFE_SETTINGS_INTERFACE_DESC), pdescription);
lib_free(pname);
lib_free(pdescription);
}
} else {
}
else
{
SetWindowText(GetDlgItem(hwnd, IDC_TFE_SETTINGS_INTERFACE_NAME), "");
SetWindowText(GetDlgItem(hwnd, IDC_TFE_SETTINGS_INTERFACE_DESC), "");
}
@ -1427,7 +1437,8 @@ static int gray_ungray_items(HWND hwnd)
return disabled ? 1 : 0;
}
static uilib_localize_dialog_param tfe_dialog[] = {
static uilib_localize_dialog_param tfe_dialog[] =
{
{0, IDS_TFE_CAPTION, -1},
{IDC_TFE_SETTINGS_ENABLE_T, IDS_TFE_ETHERNET, 0},
{IDC_TFE_SETTINGS_INTERFACE_T, IDS_TFE_INTERFACE, 0},
@ -1436,13 +1447,15 @@ static uilib_localize_dialog_param tfe_dialog[] = {
{0, 0, 0}
};
static uilib_dialog_group tfe_leftgroup[] = {
static uilib_dialog_group tfe_leftgroup[] =
{
{IDC_TFE_SETTINGS_ENABLE_T, 0},
{IDC_TFE_SETTINGS_INTERFACE_T, 0},
{0, 0}
};
static uilib_dialog_group tfe_rightgroup[] = {
static uilib_dialog_group tfe_rightgroup[] =
{
{IDC_TFE_SETTINGS_ENABLE, 0},
{IDC_TFE_SETTINGS_INTERFACE, 0},
{0, 0}
@ -1462,7 +1475,7 @@ static void init_tfe_dialog(HWND hwnd)
uilib_adjust_group_width(hwnd, tfe_leftgroup);
uilib_move_group(hwnd, tfe_rightgroup, xsize + 30);
// resources_get_value("ETHERNET_ACTIVE", (void *)&tfe_enabled);
//resources_get_value("ETHERNET_ACTIVE", (void *)&tfe_enabled);
get_tfe_enabled(&tfe_enable);
//resources_get_value("ETHERNET_AS_RR", (void *)&tfe_as_rr_net);
@ -1473,10 +1486,11 @@ static void init_tfe_dialog(HWND hwnd)
SendMessage(temp_hwnd, CB_ADDSTRING, 0, (LPARAM)"Uthernet");
SendMessage(temp_hwnd, CB_SETCURSEL, (WPARAM)active_value, 0);
// resources_get_value("ETHERNET_INTERFACE", (void *)&interface_name);
//resources_get_value("ETHERNET_INTERFACE", (void *)&interface_name);
interface_name = (char *) get_tfe_interface();
if (tfe_enumadapter_open()) {
if (tfe_enumadapter_open())
{
int cnt = 0;
char *pname;
@ -1484,22 +1498,23 @@ static void init_tfe_dialog(HWND hwnd)
temp_hwnd=GetDlgItem(hwnd,IDC_TFE_SETTINGS_INTERFACE);
for (cnt = 0; tfe_enumadapter(&pname, &pdescription); cnt++) {
for (cnt = 0; tfe_enumadapter(&pname, &pdescription); cnt++)
{
BOOL this_entry = FALSE;
if (strcmp(pname, interface_name) == 0) {
if (strcmp(pname, interface_name) == 0)
{
this_entry = TRUE;
}
SetWindowText(GetDlgItem(hwnd, IDC_TFE_SETTINGS_INTERFACE_NAME),
pname);
SetWindowText(GetDlgItem(hwnd, IDC_TFE_SETTINGS_INTERFACE_DESC),
pdescription);
SetWindowText(GetDlgItem(hwnd, IDC_TFE_SETTINGS_INTERFACE_NAME), pname);
SetWindowText(GetDlgItem(hwnd, IDC_TFE_SETTINGS_INTERFACE_DESC), pdescription);
SendMessage(temp_hwnd, CB_ADDSTRING, 0, (LPARAM)pname);
lib_free(pname);
lib_free(pdescription);
if (this_entry) {
if (this_entry)
{
SendMessage(GetDlgItem(hwnd, IDC_TFE_SETTINGS_INTERFACE),
CB_SETCURSEL, (WPARAM)cnt, 0);
}
@ -1508,7 +1523,8 @@ static void init_tfe_dialog(HWND hwnd)
tfe_enumadapter_close();
}
if (gray_ungray_items(hwnd)) {
if (gray_ungray_items(hwnd))
{
/* we have a problem: TFE is disabled. Give a message to the user */
MessageBox( hwnd,
"TFE support is not available on your system,\n"
@ -1523,7 +1539,6 @@ static void init_tfe_dialog(HWND hwnd)
}
}
static void save_tfe_dialog(HWND hwnd)
{
int active_value;
@ -1531,29 +1546,31 @@ static void save_tfe_dialog(HWND hwnd)
char buffer[256];
buffer[255] = 0;
GetDlgItemText(hwnd, IDC_TFE_SETTINGS_INTERFACE, buffer, 255);
GetDlgItemText(hwnd, IDC_TFE_SETTINGS_INTERFACE, buffer, sizeof(buffer)-1);
// RGJ - Added check for NULL interface so we don't set it active without a valid interface selected
if (strlen(buffer) > 0) {
if (strlen(buffer) > 0)
{
RegSaveString(TEXT("Configuration"), TEXT("Uthernet Interface"), 1, buffer);
active_value = SendMessage(GetDlgItem(hwnd, IDC_TFE_SETTINGS_ENABLE),
CB_GETCURSEL, 0, 0);
active_value = SendMessage(GetDlgItem(hwnd, IDC_TFE_SETTINGS_ENABLE), CB_GETCURSEL, 0, 0);
tfe_enabled = active_value >= 1 ? 1 : 0;
REGSAVE(TEXT("Uthernet Active") ,tfe_enabled);
} else {
}
else
{
REGSAVE(TEXT("Uthernet Active") ,0);
}
}
static BOOL CALLBACK TfeDlgProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
switch (msg) {
switch (msg)
{
case WM_COMMAND:
switch (LOWORD(wparam)) {
switch (LOWORD(wparam))
{
case IDOK:
save_tfe_dialog(hwnd);
/* FALL THROUGH */
@ -1579,17 +1596,15 @@ static BOOL CALLBACK TfeDlgProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lpara
init_tfe_dialog(hwnd);
return TRUE;
}
return FALSE;
}
void ui_tfe_settings_dialog(HWND hwnd)
{
DialogBox(g_hInstance, (LPCTSTR)IDD_TFE_SETTINGS_DIALOG, hwnd,
TfeDlgProc);
DialogBox(g_hInstance, (LPCTSTR)IDD_TFE_SETTINGS_DIALOG, hwnd, TfeDlgProc);
}
//===========================================================================
//Setup
@ -1639,7 +1654,6 @@ void PSP_Init()
g_bEnableFreezeDlgButton = UNDEFINED;
int i = PropertySheet(&PropSheetHeader); // Result: 0=Cancel, 1=OK
}
DWORD PSP_GetVolumeMax()
@ -1693,7 +1707,7 @@ string BrowseToFile(HWND hWindow, TCHAR* pszTitle, TCHAR* REGVALUE,TCHAR* FILEMA
ofn.lpstrTitle = pszTitle;
int nRes = GetOpenFileName(&ofn);
if(nRes) //Okay is pressed
if(nRes) // Okay is pressed
{
strcpy(g_szNewFilename, &szFilename[ofn.nFileOffset]);
@ -1704,12 +1718,12 @@ string BrowseToFile(HWND hWindow, TCHAR* pszTitle, TCHAR* REGVALUE,TCHAR* FILEMA
PathName = szFilename;
PathName.append (g_szNewFilename);
}
else //Cancel is pressed.
else // Cancel is pressed
{
RegLoadString(TEXT("Configuration"), REGVALUE, 1, szFilename,MAX_PATH);
PathName = szFilename;
}
strcpy(g_szNewFilename, PathToFile); //RAPCS, line 3 (last).
return PathName;
}

View File

@ -1245,12 +1245,13 @@ char* CSuperSerialCard::GetSerialPortChoices()
return m_aySerialPortChoices;
}
// Called by LoadConfiguration()
void CSuperSerialCard::SetSerialPortName(const char* pSerialPortName)
{
strncpy(m_ayCurrentSerialPortName, pSerialPortName, SIZEOF_SERIALCHOICE_ITEM);
if (m_vecSerialPortsItems.empty())
ScanCOMPorts();
// Init m_aySerialPortChoices, so that we have choices to show if serial is active when we 1st open Config dialog
GetSerialPortChoices();
if (strncmp(TEXT_SERIAL_COM, pSerialPortName, sizeof(TEXT_SERIAL_COM)-1) == 0)
{

View File

@ -455,8 +455,8 @@ void SoundCore_SetFade(eFADE FadeType)
//-----------------------------------------------------------------------------
// If AppleWin started by double-clicking a .dsk, the our window won't have focus when volumes are set (so gets ignored).
// Subsequent setting (to the same volume) will get ignores, as DirectSound thinks that volume is already set.
// If AppleWin started by double-clicking a .dsk, then our window won't have focus when volumes are set (so gets ignored).
// Subsequent setting (to the same volume) will get ignored, as DirectSound thinks that volume is already set.
void SoundCore_TweakVolumes()
{