Cleaned up some code.

This commit is contained in:
rheiny 2007-02-11 16:08:53 +00:00
parent 1dcf46fa78
commit 1c539a66a4
1 changed files with 283 additions and 186 deletions

View File

@ -29,6 +29,7 @@
#include "input.h" #include "input.h"
#include "keyboard.h" #include "keyboard.h"
#include "joystick.h" #include "joystick.h"
#include "gui.h"
#include "../../fceu.h" //mbg merge 7/17/06 added #include "../../fceu.h" //mbg merge 7/17/06 added
#include "keyscan.h" #include "keyscan.h"
@ -1008,6 +1009,8 @@ static void DoTBConfig(HWND hParent, const char *text, char *_template, ButtConf
**/ **/
BOOL CALLBACK InputConCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) BOOL CALLBACK InputConCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{ {
const unsigned int NUMBER_OF_PORTS = 2;
const char * const nes_description[6] = { const char * const nes_description[6] = {
"<none>", "<none>",
"Gamepad", "Gamepad",
@ -1017,7 +1020,6 @@ BOOL CALLBACK InputConCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPara
"Arkanoid Paddle" "Arkanoid Paddle"
}; };
const unsigned int NUMBER_OF_PORTS = 2;
const unsigned int NUMBER_OF_NES_DEVICES = sizeof(nes_description) / sizeof(*nes_description); const unsigned int NUMBER_OF_NES_DEVICES = sizeof(nes_description) / sizeof(*nes_description);
const char * const famicom_description[14] = const char * const famicom_description[14] =
@ -1039,40 +1041,91 @@ BOOL CALLBACK InputConCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPara
const static unsigned int NUMBER_OF_FAMICOM_DEVICES = sizeof(famicom_description) / sizeof(*famicom_description); const static unsigned int NUMBER_OF_FAMICOM_DEVICES = sizeof(famicom_description) / sizeof(*famicom_description);
static const int haven[6]= { 0, 1, 0, 1, 1, 0 }; static const int configurable_nes[6]= { 0, 1, 0, 1, 1, 0 };
static const int havef[14]= { 0,0,0,0, 1,1,0,0, 1,1,1,0, 0,0 }; static const int configurable_fam[14]= { 0,0,0,0, 1,1,0,0, 1,1,1,0, 0,0 };
int port; const unsigned int FAMICOM_POSITION = 2;
switch(uMsg) switch(uMsg)
{ {
case WM_INITDIALOG: case WM_INITDIALOG:
// Add the help text
SetDlgItemText(hwndDlg, LBL_INPUT_HELP, "Select the device you want to be enabled on input ports 1 and 2, and the Famicom expansion port. You may configure the device listed above each drop-down list by pressing \"Configure\", if applicable. The device currently being emulated on the each port is listed above the drop down list; loading certain games will override your settings, but only temporarily. If you select a device to be on the emulated Famicom Expansion Port, you should probably have emulated gamepads on the emulated NES-style input ports."); SetDlgItemText(hwndDlg, LBL_INPUT_HELP, "Select the device you want to be enabled on input ports 1 and 2, and the Famicom expansion port. You may configure the device listed above each drop-down list by pressing \"Configure\", if applicable. The device currently being emulated on the each port is listed above the drop down list; loading certain games will override your settings, but only temporarily. If you select a device to be on the emulated Famicom Expansion Port, you should probably have emulated gamepads on the emulated NES-style input ports.");
int current_device; // Initialize the controls for the input ports
for(unsigned int port = 0; port < NUMBER_OF_PORTS; port++)
for(port = 0; port < NUMBER_OF_PORTS; port++)
{ {
for(current_device = 0; current_device < NUMBER_OF_NES_DEVICES; current_device++) // Initialize the combobox
for(unsigned int current_device = 0; current_device < NUMBER_OF_NES_DEVICES; current_device++)
{ {
SendDlgItemMessage(hwndDlg, COMBO_PAD1 + port, CB_ADDSTRING, 0, (LPARAM)(LPSTR)nes_description[current_device]); SendDlgItemMessage(hwndDlg,
COMBO_PAD1 + port,
CB_ADDSTRING, 0,
(LPARAM)(LPSTR)nes_description[current_device]
);
} }
SendDlgItemMessage(hwndDlg, COMBO_PAD1 + port, CB_SETCURSEL, UsrInputType[port],(LPARAM)(LPSTR)0); // Update the combobox selection according to the
EnableWindow(GetDlgItem(hwndDlg,BTN_PORT1 + port) ,haven[InputType[port]]); // currently selected input mode.
SetDlgItemText(hwndDlg, TXT_PAD1 + port, (LPTSTR)nes_description[InputType[port]]); SendDlgItemMessage(hwndDlg,
COMBO_PAD1 + port,
CB_SETCURSEL,
UsrInputType[port],
(LPARAM)(LPSTR)0
);
// Enable the configuration button if necessary.
EnableWindow(
GetDlgItem(hwndDlg, BTN_PORT1 + port),
configurable_nes[InputType[port]]
);
// Update the label that displays the input device.
SetDlgItemText(
hwndDlg,
TXT_PAD1 + port,
(LPTSTR)nes_description[InputType[port]]
);
} }
for(current_device = 0; current_device < NUMBER_OF_FAMICOM_DEVICES; current_device++) // Initialize the Famicom combobox
for(unsigned current_device = 0; current_device < NUMBER_OF_FAMICOM_DEVICES; current_device++)
{ {
SendDlgItemMessage(hwndDlg, COMBO_FAM, CB_ADDSTRING, 0, (LPARAM)(LPSTR)famicom_description[current_device]); SendDlgItemMessage(
hwndDlg,
COMBO_FAM,
CB_ADDSTRING,
0,
(LPARAM)(LPSTR)famicom_description[current_device]
);
} }
SendDlgItemMessage(hwndDlg, COMBO_FAM, CB_SETCURSEL, UsrInputType[2], (LPARAM)(LPSTR)0); // Update the combobox selection according to the
EnableWindow(GetDlgItem(hwndDlg, BTN_FAM), havef[InputType[2]]); // currently selected input mode.
SetDlgItemText(hwndDlg, TXT_FAM, (LPTSTR)famicom_description[InputType[2]]); SendDlgItemMessage(
hwndDlg,
COMBO_FAM,
CB_SETCURSEL,
UsrInputType[FAMICOM_POSITION],
(LPARAM)(LPSTR)0
);
// Enable the configuration button if necessary.
EnableWindow(
GetDlgItem(hwndDlg, BTN_FAM),
configurable_fam[InputType[FAMICOM_POSITION]]
);
// Update the label that displays the input device.
SetDlgItemText(
hwndDlg,
TXT_FAM,
(LPTSTR)famicom_description[InputType[FAMICOM_POSITION]]
);
// Initialize the auto key controls
extern int autoHoldKey, autoHoldClearKey; extern int autoHoldKey, autoHoldClearKey;
char btext[128]; char btext[128];
@ -1105,6 +1158,8 @@ BOOL CALLBACK InputConCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPara
SetDlgItemText(hwndDlg, LBL_CLEAR_AH, btext); SetDlgItemText(hwndDlg, LBL_CLEAR_AH, btext);
CenterWindowOnScreen(hwndDlg);
break; break;
case WM_CLOSE: case WM_CLOSE:
@ -1113,7 +1168,7 @@ BOOL CALLBACK InputConCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPara
case WM_COMMAND: case WM_COMMAND:
if(HIWORD(wParam)==CBN_SELENDOK) if(HIWORD(wParam) == CBN_SELENDOK)
{ {
switch(LOWORD(wParam)) switch(LOWORD(wParam))
{ {
@ -1121,20 +1176,60 @@ BOOL CALLBACK InputConCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPara
case COMBO_PAD2: case COMBO_PAD2:
{ {
unsigned int sel_input = LOWORD(wParam) - COMBO_PAD1; unsigned int sel_input = LOWORD(wParam) - COMBO_PAD1;
UsrInputType[sel_input] = InputType[sel_input] = SendDlgItemMessage(hwndDlg, LOWORD(wParam), CB_GETCURSEL, 0, (LPARAM)(LPSTR)0);
EnableWindow( GetDlgItem(hwndDlg, LOWORD(wParam) + 2), haven[InputType[sel_input]]); // Update the user input type
SetDlgItemText(hwndDlg, TXT_PAD1 + sel_input, (LPTSTR)nes_description[InputType[sel_input]]); UsrInputType[sel_input] =
InputType[sel_input] =
SendDlgItemMessage(
hwndDlg,
LOWORD(wParam),
CB_GETCURSEL,
0,
(LPARAM)(LPSTR)0
);
// Enable or disable the configuration button
EnableWindow(
GetDlgItem(hwndDlg, LOWORD(wParam) + 2),
configurable_nes[InputType[sel_input]]
);
// Update the text field
SetDlgItemText(
hwndDlg,
TXT_PAD1 + sel_input,
(LPTSTR)nes_description[InputType[sel_input]]
);
} }
break; break;
case COMBO_FAM: case COMBO_FAM:
UsrInputType[2] =
InputType[2] =
SendDlgItemMessage(hwndDlg, COMBO_FAM, CB_GETCURSEL, 0, (LPARAM)(LPSTR)0);
EnableWindow(GetDlgItem(hwndDlg, BTN_FAM), havef[InputType[2]]); // Update the user input type of the famicom
SetDlgItemText(hwndDlg, TXT_FAM, (LPTSTR)famicom_description[InputType[2]]); UsrInputType[FAMICOM_POSITION] =
InputType[FAMICOM_POSITION] =
SendDlgItemMessage(
hwndDlg,
COMBO_FAM,
CB_GETCURSEL,
0,
(LPARAM)(LPSTR)0
);
// Enable or disable the configuration button
EnableWindow(
GetDlgItem(hwndDlg, BTN_FAM),
configurable_fam[InputType[FAMICOM_POSITION]]
);
// Update the text field
SetDlgItemText(
hwndDlg,
TXT_FAM,
(LPTSTR)famicom_description[InputType[FAMICOM_POSITION]]
);
break; break;
} }
@ -1147,10 +1242,11 @@ BOOL CALLBACK InputConCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPara
{ {
case BTN_FAM: case BTN_FAM:
{ {
const char *text = famicom_description[InputType[2]]; const char *text = famicom_description[InputType[FAMICOM_POSITION]];
DoTBType = DoTBPort = 0; DoTBType = DoTBPort = 0;
switch(InputType[2]) switch(InputType[FAMICOM_POSITION])
{ {
case SIFC_FTRAINERA: case SIFC_FTRAINERA:
case SIFC_FTRAINERB: case SIFC_FTRAINERB:
@ -1167,6 +1263,7 @@ BOOL CALLBACK InputConCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPara
break; break;
} }
} }
break; break;
case BTN_PORT2: case BTN_PORT2:
@ -1201,6 +1298,7 @@ BOOL CALLBACK InputConCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPara
break; break;
} }
} }
break; break;
case BTN_AUTO_HOLD: // auto-hold button case BTN_AUTO_HOLD: // auto-hold button
@ -1228,6 +1326,7 @@ BOOL CALLBACK InputConCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPara
SetDlgItemText(hwndDlg, LBL_AUTO_HOLD, btext); SetDlgItemText(hwndDlg, LBL_AUTO_HOLD, btext);
} }
break; break;
case BTN_CLEAR_AH: // auto-hold clear button case BTN_CLEAR_AH: // auto-hold clear button
{ {
char btext[128] = { 0 }; char btext[128] = { 0 };
@ -1280,8 +1379,6 @@ void ConfigInput(HWND hParent)
} }
} }
void DestroyInput(void) void DestroyInput(void)
{ {
if(lpDI) if(lpDI)