mirror of
https://github.com/libretro/meteor-libretro.git
synced 2026-11-07 04:16:01 -10:00
Moved config to mym
This commit is contained in:
1 parent
037b50da27
commit
b746faeba9
6 files changed
+181
-187
No files matched your search
@@ -10,7 +10,6 @@ set(CMAKE_CXX_FLAGS_RELEASE
|
||||
"${CMAKE_CXX_FLAGS_RELEASE} -fno-exceptions -fno-rtti")
|
||||
|
||||
set(AMeteor_SRC
|
||||
cfg/config.cpp
|
||||
audio/dsound.cpp
|
||||
audio/sound1.cpp
|
||||
audio/sound2.cpp
|
||||
|
||||
@@ -1,151 +0,0 @@
|
||||
// Meteor - A Nintendo Gameboy Advance emulator
|
||||
// Copyright (C) 2009-2011 Philippe Daouadi
|
||||
//
|
||||
// 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "ameteor/cfg/config.hpp"
|
||||
#include "ameteor.hpp"
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <limits.h>
|
||||
|
||||
namespace AMeteor
|
||||
{
|
||||
namespace Cfg
|
||||
{
|
||||
const std::string Config::_empty_string_;
|
||||
|
||||
bool Config::LoadFile(const char* filename)
|
||||
{
|
||||
std::ifstream file(filename);
|
||||
if (!file)
|
||||
return false;
|
||||
|
||||
char buf[256];
|
||||
std::string str;
|
||||
size_t pos;
|
||||
|
||||
while (file.getline(buf, 255, '\n'))
|
||||
{
|
||||
str = buf;
|
||||
if (str.empty() || str[0] == '#' || str[0] == ';')
|
||||
continue;
|
||||
pos = str.find('=');
|
||||
if (pos == std::string::npos)
|
||||
continue;
|
||||
m_conf[str.substr(0, pos)] = str.substr(pos+1);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Config::SaveFile(const char* filename) const
|
||||
{
|
||||
std::ofstream file(filename);
|
||||
if (!file)
|
||||
return false;
|
||||
|
||||
for (Config_t::const_iterator iter = m_conf.begin();
|
||||
iter != m_conf.end(); ++iter)
|
||||
{
|
||||
file << iter->first << '=' << iter->second << '\n';
|
||||
if (!file)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int Config::GetInt(const std::string& key) const
|
||||
{
|
||||
if (!m_conf.count(key))
|
||||
return INT_MIN;
|
||||
std::istringstream ss;
|
||||
ss.str(m_conf.at(key));
|
||||
int out;
|
||||
ss >> std::hex >> out;
|
||||
if (!ss)
|
||||
return INT_MIN;
|
||||
return out;
|
||||
}
|
||||
|
||||
void Config::SetInt(const std::string& key, int val)
|
||||
{
|
||||
std::ostringstream ss;
|
||||
ss << std::hex << val;
|
||||
m_conf[key] = ss.str();
|
||||
}
|
||||
|
||||
void Config::InitAMeteor()
|
||||
{
|
||||
AMeteor::_keypad.ResetBindings();
|
||||
|
||||
int tmp;
|
||||
#define ASSIGN_BUTTON(btn, def) \
|
||||
tmp = GetInt("keyboard_" #btn); \
|
||||
if (tmp != INT_MIN) \
|
||||
AMeteor::_keypad.BindKey(tmp, AMeteor::Keypad::BTN_##btn); \
|
||||
else \
|
||||
{ \
|
||||
SetInt("keyboard_" #btn, def); \
|
||||
AMeteor::_keypad.BindKey(def, AMeteor::Keypad::BTN_##btn); \
|
||||
}
|
||||
ASSIGN_BUTTON(A , 0x77);
|
||||
ASSIGN_BUTTON(B , 0x78);
|
||||
ASSIGN_BUTTON(L , 0x71);
|
||||
ASSIGN_BUTTON(R , 0x73);
|
||||
ASSIGN_BUTTON(START , 0x61);
|
||||
ASSIGN_BUTTON(SELECT, 0x7A);
|
||||
ASSIGN_BUTTON(LEFT , 0xFF51);
|
||||
ASSIGN_BUTTON(UP , 0xFF52);
|
||||
ASSIGN_BUTTON(RIGHT , 0xFF53);
|
||||
ASSIGN_BUTTON(DOWN , 0xFF54);
|
||||
#undef ASSIGN_BUTTON
|
||||
|
||||
#define ASSIGN_BUTTON(btn) \
|
||||
tmp = GetInt("joy_" #btn); \
|
||||
if (tmp != INT_MIN) \
|
||||
AMeteor::_keypad.BindJoy((tmp >> 16) & 0xFFFF, tmp & 0xFFFF, \
|
||||
AMeteor::Keypad::BTN_##btn);
|
||||
ASSIGN_BUTTON(A );
|
||||
ASSIGN_BUTTON(B );
|
||||
ASSIGN_BUTTON(L );
|
||||
ASSIGN_BUTTON(R );
|
||||
ASSIGN_BUTTON(START );
|
||||
ASSIGN_BUTTON(SELECT);
|
||||
ASSIGN_BUTTON(LEFT );
|
||||
ASSIGN_BUTTON(UP );
|
||||
ASSIGN_BUTTON(RIGHT );
|
||||
ASSIGN_BUTTON(DOWN );
|
||||
#undef ASSIGN_BUTTON
|
||||
|
||||
#define ASSIGN_BUTTON(btn) \
|
||||
tmp = GetInt("joyaxis_" #btn); \
|
||||
if (tmp != INT_MIN) \
|
||||
AMeteor::_keypad.BindAxis((tmp >> 16) & 0xFFFF, tmp & 0xFFFF, \
|
||||
AMeteor::Keypad::BTN_##btn);
|
||||
ASSIGN_BUTTON(A );
|
||||
ASSIGN_BUTTON(B );
|
||||
ASSIGN_BUTTON(L );
|
||||
ASSIGN_BUTTON(R );
|
||||
ASSIGN_BUTTON(START );
|
||||
ASSIGN_BUTTON(SELECT);
|
||||
ASSIGN_BUTTON(LEFT );
|
||||
ASSIGN_BUTTON(UP );
|
||||
ASSIGN_BUTTON(RIGHT );
|
||||
ASSIGN_BUTTON(DOWN );
|
||||
#undef ASSIGN_BUTTON
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,51 +14,48 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef __CONFIG_HPP__
|
||||
#define __CONFIG_HPP__
|
||||
#ifndef __MYM_CONFIG_HPP__
|
||||
#define __MYM_CONFIG_HPP__
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
namespace AMeteor
|
||||
namespace mym
|
||||
{
|
||||
namespace Cfg
|
||||
class Config
|
||||
{
|
||||
class Config
|
||||
{
|
||||
public:
|
||||
void Clear()
|
||||
{
|
||||
m_conf.clear();
|
||||
}
|
||||
public:
|
||||
void Clear()
|
||||
{
|
||||
m_conf.clear();
|
||||
}
|
||||
|
||||
bool LoadFile(const char* file);
|
||||
bool SaveFile(const char* file) const;
|
||||
bool LoadFile(const char* file);
|
||||
bool SaveFile(const char* file) const;
|
||||
|
||||
const std::string& GetStr(const std::string& key) const
|
||||
{
|
||||
if (m_conf.count(key))
|
||||
return m_conf.at(key);
|
||||
else
|
||||
return _empty_string_;
|
||||
}
|
||||
void SetStr(const std::string& key, const std::string& val)
|
||||
{
|
||||
m_conf[key] = val;
|
||||
}
|
||||
const std::string& GetStr(const std::string& key) const
|
||||
{
|
||||
if (m_conf.count(key))
|
||||
return m_conf.at(key);
|
||||
else
|
||||
return _empty_string_;
|
||||
}
|
||||
void SetStr(const std::string& key, const std::string& val)
|
||||
{
|
||||
m_conf[key] = val;
|
||||
}
|
||||
|
||||
int GetInt(const std::string& key) const;
|
||||
void SetInt(const std::string& key, int val);
|
||||
int GetInt(const std::string& key) const;
|
||||
void SetInt(const std::string& key, int val);
|
||||
|
||||
void InitAMeteor();
|
||||
void InitAMeteor();
|
||||
|
||||
private:
|
||||
typedef std::map<std::string, std::string> Config_t;
|
||||
private:
|
||||
typedef std::map<std::string, std::string> Config_t;
|
||||
|
||||
static const std::string _empty_string_;
|
||||
Config_t m_conf;
|
||||
};
|
||||
}
|
||||
static const std::string _empty_string_;
|
||||
Config_t m_conf;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -13,6 +13,7 @@ set(mym_SRC
|
||||
filters/hq4x.cpp
|
||||
|
||||
audio.cpp
|
||||
config.cpp
|
||||
events.cpp
|
||||
window.cpp
|
||||
)
|
||||
|
||||
@@ -0,0 +1,148 @@
|
||||
// Meteor - A Nintendo Gameboy Advance emulator
|
||||
// Copyright (C) 2009-2011 Philippe Daouadi
|
||||
//
|
||||
// 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "mym/config.hpp"
|
||||
#include <ameteor.hpp>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <limits.h>
|
||||
|
||||
namespace mym
|
||||
{
|
||||
const std::string Config::_empty_string_;
|
||||
|
||||
bool Config::LoadFile(const char* filename)
|
||||
{
|
||||
std::ifstream file(filename);
|
||||
if (!file)
|
||||
return false;
|
||||
|
||||
char buf[256];
|
||||
std::string str;
|
||||
size_t pos;
|
||||
|
||||
while (file.getline(buf, 255, '\n'))
|
||||
{
|
||||
str = buf;
|
||||
if (str.empty() || str[0] == '#' || str[0] == ';')
|
||||
continue;
|
||||
pos = str.find('=');
|
||||
if (pos == std::string::npos)
|
||||
continue;
|
||||
m_conf[str.substr(0, pos)] = str.substr(pos+1);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Config::SaveFile(const char* filename) const
|
||||
{
|
||||
std::ofstream file(filename);
|
||||
if (!file)
|
||||
return false;
|
||||
|
||||
for (Config_t::const_iterator iter = m_conf.begin();
|
||||
iter != m_conf.end(); ++iter)
|
||||
{
|
||||
file << iter->first << '=' << iter->second << '\n';
|
||||
if (!file)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int Config::GetInt(const std::string& key) const
|
||||
{
|
||||
if (!m_conf.count(key))
|
||||
return INT_MIN;
|
||||
std::istringstream ss;
|
||||
ss.str(m_conf.at(key));
|
||||
int out;
|
||||
ss >> std::hex >> out;
|
||||
if (!ss)
|
||||
return INT_MIN;
|
||||
return out;
|
||||
}
|
||||
|
||||
void Config::SetInt(const std::string& key, int val)
|
||||
{
|
||||
std::ostringstream ss;
|
||||
ss << std::hex << val;
|
||||
m_conf[key] = ss.str();
|
||||
}
|
||||
|
||||
void Config::InitAMeteor()
|
||||
{
|
||||
AMeteor::_keypad.ResetBindings();
|
||||
|
||||
int tmp;
|
||||
#define ASSIGN_BUTTON(btn, def) \
|
||||
tmp = GetInt("keyboard_" #btn); \
|
||||
if (tmp != INT_MIN) \
|
||||
AMeteor::_keypad.BindKey(tmp, AMeteor::Keypad::BTN_##btn); \
|
||||
else \
|
||||
{ \
|
||||
SetInt("keyboard_" #btn, def); \
|
||||
AMeteor::_keypad.BindKey(def, AMeteor::Keypad::BTN_##btn); \
|
||||
}
|
||||
ASSIGN_BUTTON(A , 0x77);
|
||||
ASSIGN_BUTTON(B , 0x78);
|
||||
ASSIGN_BUTTON(L , 0x71);
|
||||
ASSIGN_BUTTON(R , 0x73);
|
||||
ASSIGN_BUTTON(START , 0x61);
|
||||
ASSIGN_BUTTON(SELECT, 0x7A);
|
||||
ASSIGN_BUTTON(LEFT , 0xFF51);
|
||||
ASSIGN_BUTTON(UP , 0xFF52);
|
||||
ASSIGN_BUTTON(RIGHT , 0xFF53);
|
||||
ASSIGN_BUTTON(DOWN , 0xFF54);
|
||||
#undef ASSIGN_BUTTON
|
||||
|
||||
#define ASSIGN_BUTTON(btn) \
|
||||
tmp = GetInt("joy_" #btn); \
|
||||
if (tmp != INT_MIN) \
|
||||
AMeteor::_keypad.BindJoy((tmp >> 16) & 0xFFFF, tmp & 0xFFFF, \
|
||||
AMeteor::Keypad::BTN_##btn);
|
||||
ASSIGN_BUTTON(A );
|
||||
ASSIGN_BUTTON(B );
|
||||
ASSIGN_BUTTON(L );
|
||||
ASSIGN_BUTTON(R );
|
||||
ASSIGN_BUTTON(START );
|
||||
ASSIGN_BUTTON(SELECT);
|
||||
ASSIGN_BUTTON(LEFT );
|
||||
ASSIGN_BUTTON(UP );
|
||||
ASSIGN_BUTTON(RIGHT );
|
||||
ASSIGN_BUTTON(DOWN );
|
||||
#undef ASSIGN_BUTTON
|
||||
|
||||
#define ASSIGN_BUTTON(btn) \
|
||||
tmp = GetInt("joyaxis_" #btn); \
|
||||
if (tmp != INT_MIN) \
|
||||
AMeteor::_keypad.BindAxis((tmp >> 16) & 0xFFFF, tmp & 0xFFFF, \
|
||||
AMeteor::Keypad::BTN_##btn);
|
||||
ASSIGN_BUTTON(A );
|
||||
ASSIGN_BUTTON(B );
|
||||
ASSIGN_BUTTON(L );
|
||||
ASSIGN_BUTTON(R );
|
||||
ASSIGN_BUTTON(START );
|
||||
ASSIGN_BUTTON(SELECT);
|
||||
ASSIGN_BUTTON(LEFT );
|
||||
ASSIGN_BUTTON(UP );
|
||||
ASSIGN_BUTTON(RIGHT );
|
||||
ASSIGN_BUTTON(DOWN );
|
||||
#undef ASSIGN_BUTTON
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@
|
||||
#ifndef __CONFIGURATOR_HPP__
|
||||
#define __CONFIGURATOR_HPP__
|
||||
|
||||
#include <ameteor/cfg/config.hpp>
|
||||
#include <mym/config.hpp>
|
||||
|
||||
class Configurator
|
||||
{
|
||||
@@ -40,7 +40,7 @@ class Configurator
|
||||
}
|
||||
|
||||
private:
|
||||
AMeteor::Cfg::Config m_cfg;
|
||||
mym::Config m_cfg;
|
||||
|
||||
std::string m_batteryPath;
|
||||
std::string m_sstatePath;
|
||||
|
||||
Reference in new issue
Block a user