[1959914] Input Config - add hotkey assignment to input presets

[1959913] Input Config - ability to save/load input presets
This commit is contained in:
mauzus 2008-05-21 15:35:37 +00:00
parent 335d52614f
commit ce73828279
5 changed files with 153 additions and 2 deletions

View File

@ -68,6 +68,7 @@ void FCEUI_SetNTSCTH(int n, int tint, int hue);
void FCEUI_SetInput(int port, int type, void *ptr, int attrib);
void FCEUI_SetInputFC(int type, void *ptr, int attrib);
void FCEUI_DisableFourScore(int s);
void FCEUI_UseInputPreset(int preset);
#define SI_NONE 0
#define SI_GAMEPAD 1

View File

@ -481,4 +481,5 @@ DUMMY(FCEUD_AviStop)
void FCEUI_AviVideoUpdate(const unsigned char* buffer) { }
int FCEUD_ShowStatusIcon(void) {return 0;}
int FCEUI_AviIsRecording(void) {return 0;}
void FCEUI_UseInputPreset(int preset) { }

View File

@ -60,6 +60,8 @@ int InitDInput(void)
}
return 1;
}
static void PresetExport(int preset);
static void PresetImport(int preset);
static uint32 MouseData[3];
static int screenmode=0;
@ -163,6 +165,11 @@ ButtConfig GamePadConfig[4][10]={
GPZ()
};
ButtConfig GamePadPreset1[4][10]={GPZ(),GPZ(),GPZ(),GPZ()};
ButtConfig GamePadPreset2[4][10]={GPZ(),GPZ(),GPZ(),GPZ()};
ButtConfig GamePadPreset3[4][10]={GPZ(),GPZ(),GPZ(),GPZ()};
char *InputPresetDir = 0;
extern int rapidAlternator; // for auto-fire / autofire
int DesynchAutoFire=0; // A and B not at same time
uint32 JSAutoHeld=0, JSAutoHeldAffected=0; // for auto-hold
@ -583,6 +590,9 @@ CFGSTRUCT InputConfig[]={
AC(HyperShotButtons),
AC(MahjongButtons),
AC(GamePadConfig),
AC(GamePadPreset1),
AC(GamePadPreset2),
AC(GamePadPreset3),
AC(fkbmap),
AC(suborkbmap),
ENDCFGSTRUCT
@ -1301,6 +1311,27 @@ BOOL CALLBACK InputConCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPara
break;
case BTN_PRESET_SET1:
MessageBox(0, "Current input configuration has been set as Preset 1.", "FCE Ultra Message", MB_ICONINFORMATION | MB_OK | MB_SETFOREGROUND | MB_TOPMOST);
memcpy(GamePadPreset1, GamePadConfig, sizeof(GamePadConfig));
break;
case BTN_PRESET_SET2:
MessageBox(0, "Current input configuration has been set as Preset 2.", "FCE Ultra Message", MB_ICONINFORMATION | MB_OK | MB_SETFOREGROUND | MB_TOPMOST);
memcpy(GamePadPreset2, GamePadConfig, sizeof(GamePadConfig));
break;
case BTN_PRESET_SET3:
MessageBox(0, "Current input configuration has been set as Preset 3.", "FCE Ultra Message", MB_ICONINFORMATION | MB_OK | MB_SETFOREGROUND | MB_TOPMOST);
memcpy(GamePadPreset3, GamePadConfig, sizeof(GamePadConfig));
break;
case BTN_PRESET_EXPORT1: PresetExport(1); break;
case BTN_PRESET_EXPORT2: PresetExport(2); break;
case BTN_PRESET_EXPORT3: PresetExport(3); break;
case BTN_PRESET_IMPORT1: PresetImport(1); break;
case BTN_PRESET_IMPORT2: PresetImport(2); break;
case BTN_PRESET_IMPORT3: PresetImport(3); break;
case BTN_AUTO_HOLD: // auto-hold button
{
char btext[128] = { 0 };
@ -1477,3 +1508,109 @@ void FCEUD_TurboOff(void)
turbo = false;
}
void FCEUI_UseInputPreset(int preset)
{
switch(preset)
{
case 0: memcpy(GamePadConfig, GamePadPreset1, sizeof(GamePadPreset1)); break;
case 1: memcpy(GamePadConfig, GamePadPreset2, sizeof(GamePadPreset2)); break;
case 2: memcpy(GamePadConfig, GamePadPreset3, sizeof(GamePadPreset3)); break;
}
FCEU_DispMessage("Using input preset %d.",preset+1);
}
static void PresetExport(int preset)
{
const char filter[]="Input Preset File(*.pre)\0*.pre\0";
char nameo[2048];
OPENFILENAME ofn;
memset(&ofn,0,sizeof(ofn));
ofn.lStructSize=sizeof(ofn);
ofn.hInstance=fceu_hInstance;
ofn.lpstrTitle="Export Input Preset To...";
ofn.lpstrFilter=filter;
nameo[0]=0;
ofn.lpstrFile=nameo;
ofn.nMaxFile=256;
ofn.Flags=OFN_EXPLORER|OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT;
ofn.lpstrInitialDir=InputPresetDir;
if(GetSaveFileName(&ofn))
{
int i;
//Save the directory
if(ofn.nFileOffset < 1024)
{
free(InputPresetDir);
InputPresetDir=(char*)malloc(strlen(ofn.lpstrFile)+1);
strcpy(InputPresetDir,ofn.lpstrFile);
InputPresetDir[ofn.nFileOffset]=0;
}
//quick get length of nameo
for(i=0;i<2048;i++)
{
if(nameo[i] == 0)
{
break;
}
}
//add .pre if nameo doesn't have it
if((i < 4 || nameo[i-4] != '.') && i < 2040)
{
nameo[i] = '.';
nameo[i+1] = 'p';
nameo[i+2] = 'r';
nameo[i+3] = 'e';
nameo[i+4] = 0;
}
FILE *fp=FCEUD_UTF8fopen(nameo,"w");
switch(preset)
{
case 1: fwrite(GamePadPreset1,1,sizeof(GamePadPreset1),fp); break;
case 2: fwrite(GamePadPreset2,1,sizeof(GamePadPreset2),fp); break;
case 3: fwrite(GamePadPreset3,1,sizeof(GamePadPreset3),fp); break;
}
fclose(fp);
}
}
static void PresetImport(int preset)
{
const char filter[]="Input Preset File(*.pre)\0*.pre\0";
char nameo[2048];
OPENFILENAME ofn;
memset(&ofn,0,sizeof(ofn));
ofn.lStructSize=sizeof(ofn);
ofn.hInstance=fceu_hInstance;
ofn.lpstrTitle="Import Input Preset......";
ofn.lpstrFilter=filter;
nameo[0]=0;
ofn.lpstrFile=nameo;
ofn.nMaxFile=256;
ofn.Flags=OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_HIDEREADONLY;
ofn.lpstrInitialDir=InputPresetDir;
if(GetOpenFileName(&ofn))
{
//Save the directory
if(ofn.nFileOffset < 1024)
if(ofn.nFileOffset < 1024)
{
free(InputPresetDir);
InputPresetDir=(char*)malloc(strlen(ofn.lpstrFile)+1);
strcpy(InputPresetDir,ofn.lpstrFile);
InputPresetDir[ofn.nFileOffset]=0;
}
FILE *fp=FCEUD_UTF8fopen(nameo,"r");
switch(preset)
{
case 1: fread(GamePadPreset1,1,sizeof(GamePadPreset1),fp); break;
case 2: fread(GamePadPreset2,1,sizeof(GamePadPreset2),fp); break;
case 3: fread(GamePadPreset3,1,sizeof(GamePadPreset3),fp); break;
}
fclose(fp);
}
}

View File

@ -545,6 +545,7 @@ static void CommandMovieSelectSlot(void);
static void CommandMovieRecord(void);
static void CommandMovieReplay(void);
static void CommandSoundAdjust(void);
static void CommandUsePreset(void);
static void ViewSlots(void);
struct EMUCMDTABLE FCEUI_CommandTable[]=
@ -667,6 +668,9 @@ struct EMUCMDTABLE FCEUI_CommandTable[]=
{ EMUCMD_VSUNI_TOGGLE_DIP_9, EMUCMDTYPE_VSUNI, CommandToggleDip, 0, 0, "Toggle Dipswitch 9", },
{ EMUCMD_MISC_REWIND, EMUCMDTYPE_MISC, FCEUI_Rewind, 0, 0, "Rewind", },
{ EMUCMD_MISC_SHOWSTATES, EMUCMDTYPE_MISC, ViewSlots, 0,0, "View save slots", },
{ EMUCMD_MISC_USE_INPUT_PRESET_1, EMUCMDTYPE_MISC, CommandUsePreset, 0,0, "Use Input Preset 1", },
{ EMUCMD_MISC_USE_INPUT_PRESET_2, EMUCMDTYPE_MISC, CommandUsePreset, 0,0, "Use Input Preset 2", },
{ EMUCMD_MISC_USE_INPUT_PRESET_3, EMUCMDTYPE_MISC, CommandUsePreset, 0,0, "Use Input Preset 3", },
};
#define NUM_EMU_CMDS (sizeof(FCEUI_CommandTable)/sizeof(FCEUI_CommandTable[0]))
@ -794,3 +798,8 @@ static void CommandSoundAdjust(void)
FCEUD_SoundVolumeAdjust(n);
}
static void CommandUsePreset(void)
{
FCEUI_UseInputPreset(execcmd-EMUCMD_MISC_USE_INPUT_PRESET_1);
}

View File

@ -149,6 +149,9 @@ enum EMUCMD
EMUCMD_VSUNI_TOGGLE_DIP_9,
EMUCMD_MISC_REWIND,
EMUCMD_MISC_SHOWSTATES,
EMUCMD_MISC_USE_INPUT_PRESET_1,
EMUCMD_MISC_USE_INPUT_PRESET_2,
EMUCMD_MISC_USE_INPUT_PRESET_3,
EMUCMD_MAX
};