📄 wince_cfg.cpp
字号:
/* PocketCultMAME - MAME Emulator for PocketPC
(c) Copyright 2006 Manuel Castrillo Mart韓ez
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <windows.h>
#include <stdlib.h>
#include "wince_cfg.h"
#include "osdepend.h"
#include "vidsys.h"
#include "audio.h"
extern "C" {
cfgStruct DefConfig;
cfgStruct GameConfig;
extern char path_mame[];
}
#define MAX_LINE_LEN 521
extern HWND hWnd;
int getConfigValueInt(char* pchFileName, char* pchSection, char* pchKey, int iDefaultValue, int min, int max)
{
FILE* pfoConfigFile;
char chLine[MAX_LINE_LEN + 1];
char* pchToken;
int returnValue;
if ((pfoConfigFile = fopen(pchFileName, "r")) != NULL) { // open the config file
while(fgets(chLine, MAX_LINE_LEN, pfoConfigFile) != NULL) { // grab one line
pchToken = strtok(chLine, "[]"); // check if there's a section key
if((pchToken != NULL) && (pchToken[0] != '#') && (strcmp(pchToken, pchSection) == 0)) {
while(fgets(chLine, MAX_LINE_LEN, pfoConfigFile) != NULL) { // get the next line
pchToken = strtok(chLine, "\t =\n\r"); // check if it has a key=value pair
if((pchToken != NULL) && (pchToken[0] != '#') && (strcmp(pchToken, pchKey) == 0)) {
char* pchPtr = strtok(NULL, "\t =#\n\r"); // get the value if it matches our key
if (pchPtr != NULL) {
returnValue = strtol(pchPtr, NULL, 0); // return as integer
if( returnValue < min || returnValue > max )
return( iDefaultValue ); // Value beyond the limits
else
return( returnValue ); // Return the valid value
} else {
return iDefaultValue; // no value found
}
}
}
}
}
fclose(pfoConfigFile);
}
return iDefaultValue; // no value found
}
void getConfigValueString(char* pchFileName, char* pchSection, char* pchKey, char* pchValue, int iSize, char* pchDefaultValue)
{
FILE* pfoConfigFile;
char chLine[MAX_LINE_LEN + 1];
char* pchToken;
if ((pfoConfigFile = fopen(pchFileName, "r")) != NULL) { // open the config file
while(fgets(chLine, MAX_LINE_LEN, pfoConfigFile) != NULL) { // grab one line
pchToken = strtok(chLine, "[]"); // check if there's a section key
if((pchToken != NULL) && (pchToken[0] != '#') && (strcmp(pchToken, pchSection) == 0)) {
while(fgets(chLine, MAX_LINE_LEN, pfoConfigFile) != NULL) { // get the next line
pchToken = strtok(chLine, "\t =\n\r"); // check if it has a key=value pair
if((pchToken != NULL) && (pchToken[0] != '#') && (strcmp(pchToken, pchKey) == 0)) {
char* pchPtr = strtok(NULL, "\t=#\n\r"); // get the value if it matches our key
if (pchPtr != NULL) {
strncpy(pchValue, pchPtr, iSize); // copy to destination
return;
} else {
strncpy(pchValue, pchDefaultValue, iSize); // no value found, return the default
return;
}
}
}
}
}
fclose(pfoConfigFile);
}
strncpy(pchValue, pchDefaultValue, iSize); // no value found, return the default
}
void loadConfiguration( char *configFilename, cfgStruct &cfg )
{
char chFileName[MAX_PATH + 1];
strncpy(chFileName, path_mame, sizeof(chFileName));
strcat(chFileName, "configs\\");
strcat(chFileName, configFilename);
strcat(chFileName, ".cfg");
// Video configuration
cfg.vidOrientation = getConfigValueInt( chFileName, "Video", "Orientation", DefConfig.vidOrientation, 0, 4 );
cfg.vidScaling = getConfigValueInt( chFileName, "Video", "Scaling", DefConfig.vidScaling, 0, 2 );
cfg.vidFx = getConfigValueInt( chFileName, "Video", "Fx", DefConfig.vidFx, 0, 2 );
cfg.vid2700G_lowRes = getConfigValueInt( chFileName, "Video", "2700G_lowRes", DefConfig.vid2700G_lowRes, 0, FORCE_i2700Gqvga );
cfg.vidShowFPS = getConfigValueInt( chFileName, "Video", "ShowFPS", DefConfig.vidShowFPS, 0, 1 );
// Sound configuration
cfg.sndEnabled = getConfigValueInt( chFileName, "Sound", "Enabled", DefConfig.sndEnabled, 0, 1 );
cfg.sndFreq = getConfigValueInt( chFileName, "Sound", "Frequency", DefConfig.sndFreq, 0, 2 );
cfg.sndBits = getConfigValueInt( chFileName, "Sound", "Bits", DefConfig.sndBits, AUDIO_FORMAT_8BITS, AUDIO_FORMAT_16BITS );
cfg.sndStereo = getConfigValueInt( chFileName, "Sound", "Stereo", DefConfig.sndStereo, AUDIO_FORMAT_MONO, AUDIO_FORMAT_STEREO);
// Input configuration
cfg.inpAnalogControls = getConfigValueInt( chFileName, "Input", "AnalogControls", DefConfig.inpAnalogControls, ANALOG_DISABLED, ANALOG_JOYSTYLUS );
cfg.inpAnalogSensibility = getConfigValueInt( chFileName, "Input", "AnalogSensibility", DefConfig.inpAnalogSensibility, 0, 9 );
cfg.inpKeyUp = getConfigValueInt( chFileName, "Input", "KeyUp", DefConfig.inpKeyUp, 0, 0xFFFF );
cfg.inpKeyUpCode = getConfigValueInt( chFileName, "Input", "KeyUpCode", DefConfig.inpKeyUpCode, 0, 0xFFFF );
cfg.inpKeyDown = getConfigValueInt( chFileName, "Input", "KeyDown", DefConfig.inpKeyDown, 0, 0xFFFF );
cfg.inpKeyDownCode = getConfigValueInt( chFileName, "Input", "KeyDownCode", DefConfig.inpKeyDownCode, 0, 0xFFFF );
cfg.inpKeyLeft = getConfigValueInt( chFileName, "Input", "KeyLeft", DefConfig.inpKeyLeft, 0, 0xFFFF );
cfg.inpKeyLeftCode = getConfigValueInt( chFileName, "Input", "KeyLeftCode", DefConfig.inpKeyLeftCode, 0, 0xFFFF );
cfg.inpKeyRight = getConfigValueInt( chFileName, "Input", "KeyRight", DefConfig.inpKeyRight, 0, 0xFFFF );
cfg.inpKeyRightCode = getConfigValueInt( chFileName, "Input", "KeyRightCode", DefConfig.inpKeyRightCode, 0, 0xFFFF );
cfg.inpKeyA = getConfigValueInt( chFileName, "Input", "KeyA", DefConfig.inpKeyA, 0, 0xFFFF );
cfg.inpKeyACode = getConfigValueInt( chFileName, "Input", "KeyACode", DefConfig.inpKeyACode, 0, 0xFFFF );
cfg.inpKeyB = getConfigValueInt( chFileName, "Input", "KeyB", DefConfig.inpKeyB, 0, 0xFFFF );
cfg.inpKeyBCode = getConfigValueInt( chFileName, "Input", "KeyBCode", DefConfig.inpKeyBCode, 0, 0xFFFF );
cfg.inpKeyC = getConfigValueInt( chFileName, "Input", "KeyC", DefConfig.inpKeyC, 0, 0xFFFF );
cfg.inpKeyCCode = getConfigValueInt( chFileName, "Input", "KeyCCode", DefConfig.inpKeyCCode, 0, 0xFFFF );
cfg.inpKeyD = getConfigValueInt( chFileName, "Input", "KeyD", DefConfig.inpKeyD, 0, 0xFFFF );
cfg.inpKeyDCode = getConfigValueInt( chFileName, "Input", "KeyDCode", DefConfig.inpKeyDCode, 0, 0xFFFF );
cfg.inpKeyE = getConfigValueInt( chFileName, "Input", "KeyE", DefConfig.inpKeyE, 0, 0xFFFF );
cfg.inpKeyECode = getConfigValueInt( chFileName, "Input", "KeyECode", DefConfig.inpKeyECode, 0, 0xFFFF );
cfg.inpKeyF = getConfigValueInt( chFileName, "Input", "KeyF", DefConfig.inpKeyF, 0, 0xFFFF );
cfg.inpKeyFCode = getConfigValueInt( chFileName, "Input", "KeyFCode", DefConfig.inpKeyFCode, 0, 0xFFFF );
cfg.inpKeyG = getConfigValueInt( chFileName, "Input", "KeyG", DefConfig.inpKeyG, 0, 0xFFFF );
cfg.inpKeyGCode = getConfigValueInt( chFileName, "Input", "KeyGCode", DefConfig.inpKeyGCode, 0, 0xFFFF );
cfg.inpOnscreenButtonsOrientation = getConfigValueInt( chFileName, "Input", "OnscreenButtonsOrientation", DefConfig.inpOnscreenButtonsOrientation, ONSCREENBUTTONS_HORIZONTAL, ONSCREENBUTTONS_VERTICAL );
cfg.inpOnscreenRed = getConfigValueInt( chFileName, "Input", "OnscreenRedButton", DefConfig.inpOnscreenRed, 0, 0xFFFF );
cfg.inpOnscreenGreen = getConfigValueInt( chFileName, "Input", "OnscreenGreenButton", DefConfig.inpOnscreenGreen, 0, 0xFFFF );
cfg.inpOnscreenYellow = getConfigValueInt( chFileName, "Input", "OnscreenYellowButton", DefConfig.inpOnscreenYellow, 0, 0xFFFF );
cfg.inpAutofire = getConfigValueInt( chFileName, "Input", "Autofire", DefConfig.inpAutofire, AUTOFIRE_MAX, AUTOFIRE_DISABLED );
}
void saveConfiguration( char *configFilename, cfgStruct &cfg )
{
FILE * ConfigurationFile;
char line[1024];
// Check config dir
WIN32_FIND_DATA fd;
HANDLE hFind;
TCHAR configPathTChar[MAX_PATH];
char configPathChar[MAX_PATH];
sprintf(configPathChar,"%sconfigs\0", path_mame);
mbstowcs( configPathTChar, configPathChar, MAX_PATH );
hFind = FindFirstFile( configPathTChar, &fd);
if( !(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) )
{
if( !CreateDirectory( configPathTChar, NULL ) )
{
MessageBox( hWnd, _T("Error creating directory for configurations."), _T("Error"), MB_OK | MB_ICONEXCLAMATION );
exit(0);
}
}
strcat( configPathChar, "\\" );
strcat( configPathChar, configFilename );
strcat( configPathChar, ".cfg" );
// Save values
ConfigurationFile = fopen( configPathChar, "wt" );
fputs( "[Video]\n", ConfigurationFile ); // Video configuration
sprintf( line, "Orientation=%d\n", cfg.vidOrientation );
fputs( line, ConfigurationFile );
sprintf( line, "Scaling=%d\n", cfg.vidScaling );
fputs( line, ConfigurationFile );
sprintf( line, "Fx=%d\n", cfg.vidFx );
fputs( line, ConfigurationFile );
sprintf( line, "2700G_lowRes=%d\n", cfg.vid2700G_lowRes );
fputs( line, ConfigurationFile );
sprintf( line, "ShowFPS=%d\n", cfg.vidShowFPS );
fputs( line, ConfigurationFile );
fputs( "[Sound]\n", ConfigurationFile ); // Sound configuration
sprintf( line, "Enabled=%d\n", cfg.sndEnabled );
fputs( line, ConfigurationFile );
sprintf( line, "Frequency=%d\n", cfg.sndFreq );
fputs( line, ConfigurationFile );
sprintf( line, "Bits=%d\n", cfg.sndBits );
fputs( line, ConfigurationFile );
sprintf( line, "Stereo=%d\n", cfg.sndStereo );
fputs( line, ConfigurationFile );
fputs( "[Input]\n", ConfigurationFile ); // Input configuration
sprintf( line, "AnalogControls=%d\n", cfg.inpAnalogControls );
fputs( line, ConfigurationFile );
sprintf( line, "AnalogSensibility=%d\n", cfg.inpAnalogSensibility );
fputs( line, ConfigurationFile );
sprintf( line, "KeyUp=%d\n", cfg.inpKeyUp );
fputs( line, ConfigurationFile );
sprintf( line, "KeyUpCode=%d\n", cfg.inpKeyUpCode );
fputs( line, ConfigurationFile );
sprintf( line, "KeyDown=%d\n", cfg.inpKeyDown );
fputs( line, ConfigurationFile );
sprintf( line, "KeyDownCode=%d\n", cfg.inpKeyDownCode );
fputs( line, ConfigurationFile );
sprintf( line, "KeyLeft=%d\n", cfg.inpKeyLeft );
fputs( line, ConfigurationFile );
sprintf( line, "KeyLeftCode=%d\n", cfg.inpKeyLeftCode );
fputs( line, ConfigurationFile );
sprintf( line, "KeyRight=%d\n", cfg.inpKeyRight );
fputs( line, ConfigurationFile );
sprintf( line, "KeyRightCode=%d\n", cfg.inpKeyRightCode );
fputs( line, ConfigurationFile );
sprintf( line, "KeyA=%d\n", cfg.inpKeyA );
fputs( line, ConfigurationFile );
sprintf( line, "KeyACode=%d\n", cfg.inpKeyACode );
fputs( line, ConfigurationFile );
sprintf( line, "KeyB=%d\n", cfg.inpKeyB );
fputs( line, ConfigurationFile );
sprintf( line, "KeyBCode=%d\n", cfg.inpKeyBCode );
fputs( line, ConfigurationFile );
sprintf( line, "KeyC=%d\n", cfg.inpKeyC );
fputs( line, ConfigurationFile );
sprintf( line, "KeyCCode=%d\n", cfg.inpKeyCCode );
fputs( line, ConfigurationFile );
sprintf( line, "KeyD=%d\n", cfg.inpKeyD );
fputs( line, ConfigurationFile );
sprintf( line, "KeyDCode=%d\n", cfg.inpKeyDCode );
fputs( line, ConfigurationFile );
sprintf( line, "KeyE=%d\n", cfg.inpKeyE );
fputs( line, ConfigurationFile );
sprintf( line, "KeyECode=%d\n", cfg.inpKeyECode );
fputs( line, ConfigurationFile );
sprintf( line, "KeyF=%d\n", cfg.inpKeyF );
fputs( line, ConfigurationFile );
sprintf( line, "KeyFCode=%d\n", cfg.inpKeyFCode );
fputs( line, ConfigurationFile );
sprintf( line, "KeyG=%d\n", cfg.inpKeyG );
fputs( line, ConfigurationFile );
sprintf( line, "KeyGCode=%d\n", cfg.inpKeyGCode );
fputs( line, ConfigurationFile );
sprintf( line, "OnscreenButtonsOrientation=%d\n", cfg.inpOnscreenButtonsOrientation );
fputs( line, ConfigurationFile );
sprintf( line, "OnscreenRedButton=%d\n", cfg.inpOnscreenRed );
fputs( line, ConfigurationFile );
sprintf( line, "OnscreenGreenButton=%d\n", cfg.inpOnscreenGreen );
fputs( line, ConfigurationFile );
sprintf( line, "OnscreenYellowButton=%d\n", cfg.inpOnscreenYellow );
fputs( line, ConfigurationFile );
sprintf( line, "Autofire=%d\n", cfg.inpAutofire );
fputs( line, ConfigurationFile );
fclose(ConfigurationFile);
}
void setInitialConfiguration(void)
{
// Video configuration
DefConfig.vidOrientation = OPTION_AUTO;
DefConfig.vidScaling = OPTION_AUTO;
DefConfig.vidFx = OPTION_DISABLED;
DefConfig.vid2700G_lowRes = OPTION_DISABLED;
DefConfig.vidShowFPS = OPTION_DISABLED;
// Sound configuration
DefConfig.sndEnabled = OPTION_ENABLED;
DefConfig.sndFreq = 0;
DefConfig.sndBits = AUDIO_FORMAT_16BITS;
DefConfig.sndStereo = AUDIO_FORMAT_MONO;
// Input configuration
DefConfig.inpAnalogControls = ANALOG_DISABLED;
DefConfig.inpAnalogSensibility = 6;
DefConfig.inpKeyUp = OSD_JOY_UP;
DefConfig.inpKeyUpCode = OPTION_AUTO;
DefConfig.inpKeyDown = OSD_JOY_DOWN;
DefConfig.inpKeyDownCode = OPTION_AUTO;
DefConfig.inpKeyLeft = OSD_JOY_LEFT;
DefConfig.inpKeyLeftCode = OPTION_AUTO;
DefConfig.inpKeyRight = OSD_JOY_RIGHT;
DefConfig.inpKeyRightCode = OPTION_AUTO;
DefConfig.inpKeyA = OSD_JOY_FIRE1;
DefConfig.inpKeyACode = OPTION_AUTO;
DefConfig.inpKeyB = OSD_JOY_FIRE2;
DefConfig.inpKeyBCode = OPTION_AUTO;
DefConfig.inpKeyC = OSD_JOY_FIRE3;
DefConfig.inpKeyCCode = OPTION_AUTO;
DefConfig.inpKeyD = OSD_JOY_FIRE4;
DefConfig.inpKeyDCode = OPTION_AUTO;
DefConfig.inpKeyE = OSD_KEY_3;
DefConfig.inpKeyECode = OPTION_AUTO;
DefConfig.inpKeyF = OSD_KEY_1;
DefConfig.inpKeyFCode = OPTION_AUTO;
DefConfig.inpKeyG = OSD_KEY_ESC;
DefConfig.inpKeyGCode = OPTION_AUTO;
DefConfig.inpOnscreenRed = OSD_JOY_FIRE1;
DefConfig.inpOnscreenGreen = OSD_JOY_FIRE2;
DefConfig.inpOnscreenYellow = OSD_JOY_FIRE3;
DefConfig.inpAutofire = AUTOFIRE_DISABLED;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -