diff --git a/ameteor/source/CMakeLists.txt b/ameteor/source/CMakeLists.txt index 4834007..c168117 100644 --- a/ameteor/source/CMakeLists.txt +++ b/ameteor/source/CMakeLists.txt @@ -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 diff --git a/ameteor/source/cfg/config.cpp b/ameteor/source/cfg/config.cpp deleted file mode 100644 index 4448cca..0000000 --- a/ameteor/source/cfg/config.cpp +++ /dev/null @@ -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 . - -#include "ameteor/cfg/config.hpp" -#include "ameteor.hpp" -#include -#include -#include - -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 - } - } -} diff --git a/ameteor/include/ameteor/cfg/config.hpp b/mym/include/mym/config.hpp similarity index 50% rename from ameteor/include/ameteor/cfg/config.hpp rename to mym/include/mym/config.hpp index 294fe9e..1aa63e6 100644 --- a/ameteor/include/ameteor/cfg/config.hpp +++ b/mym/include/mym/config.hpp @@ -14,51 +14,48 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#ifndef __CONFIG_HPP__ -#define __CONFIG_HPP__ +#ifndef __MYM_CONFIG_HPP__ +#define __MYM_CONFIG_HPP__ #include #include -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 Config_t; + private: + typedef std::map Config_t; - static const std::string _empty_string_; - Config_t m_conf; - }; - } + static const std::string _empty_string_; + Config_t m_conf; + }; } #endif diff --git a/mym/source/CMakeLists.txt b/mym/source/CMakeLists.txt index 349cb5d..b3377bd 100644 --- a/mym/source/CMakeLists.txt +++ b/mym/source/CMakeLists.txt @@ -13,6 +13,7 @@ set(mym_SRC filters/hq4x.cpp audio.cpp + config.cpp events.cpp window.cpp ) diff --git a/mym/source/config.cpp b/mym/source/config.cpp new file mode 100644 index 0000000..1f93870 --- /dev/null +++ b/mym/source/config.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 . + +#include "mym/config.hpp" +#include +#include +#include +#include + +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 + } +} diff --git a/text/configurator.hpp b/text/configurator.hpp index c1dfeb8..f9e4774 100644 --- a/text/configurator.hpp +++ b/text/configurator.hpp @@ -17,7 +17,7 @@ #ifndef __CONFIGURATOR_HPP__ #define __CONFIGURATOR_HPP__ -#include +#include 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;