summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/citra/CMakeLists.txt5
-rw-r--r--src/citra/citra.cpp9
-rw-r--r--src/citra/config.cpp65
-rw-r--r--src/citra/config.h24
-rw-r--r--src/citra/default_ini.h30
-rw-r--r--src/citra/emu_window/emu_window_glfw.cpp47
-rw-r--r--src/citra/emu_window/emu_window_glfw.h6
-rw-r--r--src/citra_qt/CMakeLists.txt2
-rw-r--r--src/citra_qt/bootmanager.cpp54
-rw-r--r--src/citra_qt/bootmanager.hxx3
-rw-r--r--src/citra_qt/config.cpp79
-rw-r--r--src/citra_qt/config.h23
-rw-r--r--src/citra_qt/main.cpp5
-rw-r--r--src/common/common_paths.h44
-rw-r--r--src/common/console_listener.cpp10
-rw-r--r--src/common/emu_window.h10
-rw-r--r--src/common/file_util.cpp118
-rw-r--r--src/common/file_util.h31
-rw-r--r--src/common/log.h1
-rw-r--r--src/common/log_manager.cpp1
-rw-r--r--src/core/CMakeLists.txt2
-rw-r--r--src/core/file_sys/archive_sdmc.cpp6
-rw-r--r--src/core/file_sys/archive_sdmc.h4
-rw-r--r--src/core/file_sys/directory.h10
-rw-r--r--src/core/file_sys/directory_sdmc.cpp43
-rw-r--r--src/core/file_sys/directory_sdmc.h9
-rw-r--r--src/core/file_sys/file.h15
-rw-r--r--src/core/file_sys/file_romfs.cpp19
-rw-r--r--src/core/file_sys/file_romfs.h15
-rw-r--r--src/core/file_sys/file_sdmc.cpp72
-rw-r--r--src/core/file_sys/file_sdmc.h17
-rw-r--r--src/core/hle/kernel/archive.cpp11
-rw-r--r--src/core/hle/service/apt.cpp34
-rw-r--r--src/core/hle/service/gsp.cpp1
-rw-r--r--src/core/mem_map_funcs.cpp2
-rw-r--r--src/core/settings.cpp11
-rw-r--r--src/core/settings.h29
37 files changed, 673 insertions, 194 deletions
diff --git a/src/citra/CMakeLists.txt b/src/citra/CMakeLists.txt
index f10f3e603..f2add394f 100644
--- a/src/citra/CMakeLists.txt
+++ b/src/citra/CMakeLists.txt
@@ -1,9 +1,12 @@
set(SRCS
emu_window/emu_window_glfw.cpp
citra.cpp
+ config.cpp
)
set(HEADERS
emu_window/emu_window_glfw.h
+ config.h
+ default_ini.h
resource.h
)
@@ -16,7 +19,7 @@ endif()
add_executable(citra ${SRCS} ${HEADERS})
target_link_libraries(citra core common video_core)
-target_link_libraries(citra ${OPENGL_gl_LIBRARY} ${GLFW_LIBRARIES})
+target_link_libraries(citra ${OPENGL_gl_LIBRARY} ${GLFW_LIBRARIES} inih)
if (APPLE)
target_link_libraries(citra iconv pthread ${COREFOUNDATION_LIBRARY})
diff --git a/src/citra/citra.cpp b/src/citra/citra.cpp
index 7dc721dc3..46781defa 100644
--- a/src/citra/citra.cpp
+++ b/src/citra/citra.cpp
@@ -4,12 +4,12 @@
#include "common/common.h"
#include "common/log_manager.h"
-#include "common/file_util.h"
#include "core/system.h"
#include "core/core.h"
#include "core/loader/loader.h"
+#include "citra/config.h"
#include "citra/emu_window/emu_window_glfw.h"
/// Application entry point
@@ -21,13 +21,16 @@ int __cdecl main(int argc, char **argv) {
return -1;
}
+ Config config;
+
std::string boot_filename = argv[1];
EmuWindow_GLFW* emu_window = new EmuWindow_GLFW;
System::Init(emu_window);
- if (Loader::ResultStatus::Success != Loader::LoadFile(boot_filename)) {
- ERROR_LOG(BOOT, "Failed to load ROM!");
+ Loader::ResultStatus load_result = Loader::LoadFile(boot_filename);
+ if (Loader::ResultStatus::Success != load_result) {
+ ERROR_LOG(BOOT, "Failed to load ROM (Error %i)!", load_result);
return -1;
}
diff --git a/src/citra/config.cpp b/src/citra/config.cpp
new file mode 100644
index 000000000..1d5e9c717
--- /dev/null
+++ b/src/citra/config.cpp
@@ -0,0 +1,65 @@
+// Copyright 2014 Citra Emulator Project
+// Licensed under GPLv2
+// Refer to the license.txt file included.
+
+#include <GLFW/glfw3.h>
+
+#include "citra/default_ini.h"
+#include "common/file_util.h"
+#include "core/settings.h"
+
+#include "config.h"
+
+Config::Config() {
+ // TODO: Don't hardcode the path; let the frontend decide where to put the config files.
+ glfw_config_loc = FileUtil::GetUserPath(D_CONFIG_IDX) + "glfw-config.ini";
+ glfw_config = new INIReader(glfw_config_loc);
+
+ Reload();
+}
+
+bool Config::LoadINI(INIReader* config, const char* location, const std::string& default_contents, bool retry) {
+ if (config->ParseError() < 0) {
+ if (retry) {
+ ERROR_LOG(CONFIG, "Failed to load %s. Creating file from defaults...", location);
+ FileUtil::CreateFullPath(location);
+ FileUtil::WriteStringToFile(true, default_contents, location);
+ *config = INIReader(location); // Reopen file
+
+ return LoadINI(config, location, default_contents, false);
+ }
+ ERROR_LOG(CONFIG, "Failed.");
+ return false;
+ }
+ INFO_LOG(CONFIG, "Successfully loaded %s", location);
+ return true;
+}
+
+void Config::ReadControls() {
+ Settings::values.pad_a_key = glfw_config->GetInteger("Controls", "pad_a", GLFW_KEY_A);
+ Settings::values.pad_b_key = glfw_config->GetInteger("Controls", "pad_b", GLFW_KEY_S);
+ Settings::values.pad_x_key = glfw_config->GetInteger("Controls", "pad_x", GLFW_KEY_Z);
+ Settings::values.pad_y_key = glfw_config->GetInteger("Controls", "pad_y", GLFW_KEY_X);
+ Settings::values.pad_l_key = glfw_config->GetInteger("Controls", "pad_l", GLFW_KEY_Q);
+ Settings::values.pad_r_key = glfw_config->GetInteger("Controls", "pad_r", GLFW_KEY_W);
+ Settings::values.pad_start_key = glfw_config->GetInteger("Controls", "pad_start", GLFW_KEY_M);
+ Settings::values.pad_select_key = glfw_config->GetInteger("Controls", "pad_select", GLFW_KEY_N);
+ Settings::values.pad_home_key = glfw_config->GetInteger("Controls", "pad_home", GLFW_KEY_B);
+ Settings::values.pad_dup_key = glfw_config->GetInteger("Controls", "pad_dup", GLFW_KEY_T);
+ Settings::values.pad_ddown_key = glfw_config->GetInteger("Controls", "pad_ddown", GLFW_KEY_G);
+ Settings::values.pad_dleft_key = glfw_config->GetInteger("Controls", "pad_dleft", GLFW_KEY_F);
+ Settings::values.pad_dright_key = glfw_config->GetInteger("Controls", "pad_dright", GLFW_KEY_H);
+ Settings::values.pad_sup_key = glfw_config->GetInteger("Controls", "pad_sup", GLFW_KEY_UP);
+ Settings::values.pad_sdown_key = glfw_config->GetInteger("Controls", "pad_sdown", GLFW_KEY_DOWN);
+ Settings::values.pad_sleft_key = glfw_config->GetInteger("Controls", "pad_sleft", GLFW_KEY_LEFT);
+ Settings::values.pad_sright_key = glfw_config->GetInteger("Controls", "pad_sright", GLFW_KEY_RIGHT);
+}
+
+void Config::Reload() {
+ LoadINI(glfw_config, glfw_config_loc.c_str(), DefaultINI::glfw_config_file);
+ ReadControls();
+}
+
+Config::~Config() {
+ delete glfw_config;
+}
diff --git a/src/citra/config.h b/src/citra/config.h
new file mode 100644
index 000000000..de0570b42
--- /dev/null
+++ b/src/citra/config.h
@@ -0,0 +1,24 @@
+// Copyright 2014 Citra Emulator Project
+// Licensed under GPLv2
+// Refer to the license.txt file included.
+
+#pragma once
+
+#include <map>
+
+#include <inih/cpp/INIReader.h>
+
+#include "common/common_types.h"
+
+class Config {
+ INIReader* glfw_config;
+ std::string glfw_config_loc;
+
+ bool LoadINI(INIReader* config, const char* location, const std::string& default_contents="", bool retry=true);
+ void ReadControls();
+public:
+ Config();
+ ~Config();
+
+ void Reload();
+};
diff --git a/src/citra/default_ini.h b/src/citra/default_ini.h
new file mode 100644
index 000000000..11b985e1b
--- /dev/null
+++ b/src/citra/default_ini.h
@@ -0,0 +1,30 @@
+// Copyright 2014 Citra Emulator Project
+// Licensed under GPLv2
+// Refer to the license.txt file included.
+
+#pragma once
+
+namespace DefaultINI {
+
+const char* glfw_config_file = R"(
+[Controls]
+pad_start =
+pad_select =
+pad_home =
+pad_dup =
+pad_ddown =
+pad_dleft =
+pad_dright =
+pad_a =
+pad_b =
+pad_x =
+pad_y =
+pad_r =
+pad_l =
+pad_sup =
+pad_sdown =
+pad_sleft =
+pad_sright =
+)";
+
+}
diff --git a/src/citra/emu_window/emu_window_glfw.cpp b/src/citra/emu_window/emu_window_glfw.cpp
index b911e60c5..661521eb7 100644
--- a/src/citra/emu_window/emu_window_glfw.cpp
+++ b/src/citra/emu_window/emu_window_glfw.cpp
@@ -6,26 +6,9 @@
#include "video_core/video_core.h"
-#include "citra/emu_window/emu_window_glfw.h"
+#include "core/settings.h"
-static const std::pair<int, HID_User::PadState> default_key_map[] = {
- { GLFW_KEY_A, HID_User::PAD_A },
- { GLFW_KEY_B, HID_User::PAD_B },
- { GLFW_KEY_BACKSLASH, HID_User::PAD_SELECT },
- { GLFW_KEY_ENTER, HID_User::PAD_START },
- { GLFW_KEY_RIGHT, HID_User::PAD_RIGHT },
- { GLFW_KEY_LEFT, HID_User::PAD_LEFT },
- { GLFW_KEY_UP, HID_User::PAD_UP },
- { GLFW_KEY_DOWN, HID_User::PAD_DOWN },
- { GLFW_KEY_R, HID_User::PAD_R },
- { GLFW_KEY_L, HID_User::PAD_L },
- { GLFW_KEY_X, HID_User::PAD_X },
- { GLFW_KEY_Y, HID_User::PAD_Y },
- { GLFW_KEY_H, HID_User::PAD_CIRCLE_RIGHT },
- { GLFW_KEY_F, HID_User::PAD_CIRCLE_LEFT },
- { GLFW_KEY_T, HID_User::PAD_CIRCLE_UP },
- { GLFW_KEY_G, HID_User::PAD_CIRCLE_DOWN },
-};
+#include "citra/emu_window/emu_window_glfw.h"
/// Called by GLFW when a key event occurs
void EmuWindow_GLFW::OnKeyEvent(GLFWwindow* win, int key, int scancode, int action, int mods) {
@@ -48,14 +31,9 @@ void EmuWindow_GLFW::OnKeyEvent(GLFWwindow* win, int key, int scancode, int acti
/// EmuWindow_GLFW constructor
EmuWindow_GLFW::EmuWindow_GLFW() {
-
- // Register a new ID for the default keyboard
keyboard_id = KeyMap::NewDeviceId();
- // Set default key mappings for keyboard
- for (auto mapping : default_key_map) {
- KeyMap::SetKeyMapping({mapping.first, keyboard_id}, mapping.second);
- }
+ ReloadSetKeymaps();
// Initialize the window
if(glfwInit() != GL_TRUE) {
@@ -111,3 +89,22 @@ void EmuWindow_GLFW::MakeCurrent() {
void EmuWindow_GLFW::DoneCurrent() {
glfwMakeContextCurrent(NULL);
}
+
+void EmuWindow_GLFW::ReloadSetKeymaps() {
+ KeyMap::SetKeyMapping({Settings::values.pad_a_key, keyboard_id}, HID_User::PAD_A);
+ KeyMap::SetKeyMapping({Settings::values.pad_b_key, keyboard_id}, HID_User::PAD_B);
+ KeyMap::SetKeyMapping({Settings::values.pad_select_key, keyboard_id}, HID_User::PAD_SELECT);
+ KeyMap::SetKeyMapping({Settings::values.pad_start_key, keyboard_id}, HID_User::PAD_START);
+ KeyMap::SetKeyMapping({Settings::values.pad_dright_key, keyboard_id}, HID_User::PAD_RIGHT);
+ KeyMap::SetKeyMapping({Settings::values.pad_dleft_key, keyboard_id}, HID_User::PAD_LEFT);
+ KeyMap::SetKeyMapping({Settings::values.pad_dup_key, keyboard_id}, HID_User::PAD_UP);
+ KeyMap::SetKeyMapping({Settings::values.pad_ddown_key, keyboard_id}, HID_User::PAD_DOWN);
+ KeyMap::SetKeyMapping({Settings::values.pad_r_key, keyboard_id}, HID_User::PAD_R);
+ KeyMap::SetKeyMapping({Settings::values.pad_l_key, keyboard_id}, HID_User::PAD_L);
+ KeyMap::SetKeyMapping({Settings::values.pad_x_key, keyboard_id}, HID_User::PAD_X);
+ KeyMap::SetKeyMapping({Settings::values.pad_y_key, keyboard_id}, HID_User::PAD_Y);
+ KeyMap::SetKeyMapping({Settings::values.pad_sright_key, keyboard_id}, HID_User::PAD_CIRCLE_RIGHT);
+ KeyMap::SetKeyMapping({Settings::values.pad_sleft_key, keyboard_id}, HID_User::PAD_CIRCLE_LEFT);
+ KeyMap::SetKeyMapping({Settings::values.pad_sup_key, keyboard_id}, HID_User::PAD_CIRCLE_UP);
+ KeyMap::SetKeyMapping({Settings::values.pad_sdown_key, keyboard_id}, HID_User::PAD_CIRCLE_DOWN);
+}
diff --git a/src/citra/emu_window/emu_window_glfw.h b/src/citra/emu_window/emu_window_glfw.h
index 29325bb75..d38a11c2c 100644
--- a/src/citra/emu_window/emu_window_glfw.h
+++ b/src/citra/emu_window/emu_window_glfw.h
@@ -27,7 +27,11 @@ public:
static void OnKeyEvent(GLFWwindow* win, int key, int scancode, int action, int mods);
+ void ReloadSetKeymaps() override;
+
private:
GLFWwindow* m_render_window; ///< Internal GLFW render window
- int keyboard_id; ///< Device id of keyboard for use with KeyMap
+
+ /// Device id of keyboard for use with KeyMap
+ int keyboard_id;
};
diff --git a/src/citra_qt/CMakeLists.txt b/src/citra_qt/CMakeLists.txt
index 426e4ef99..98a48a69a 100644
--- a/src/citra_qt/CMakeLists.txt
+++ b/src/citra_qt/CMakeLists.txt
@@ -4,6 +4,7 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(SRCS
config/controller_config.cpp
config/controller_config_util.cpp
+ config.cpp
debugger/callstack.cpp
debugger/disassembler.cpp
debugger/graphics.cpp
@@ -18,6 +19,7 @@ set(SRCS
set(HEADERS
config/controller_config.hxx
config/controller_config_util.hxx
+ config.h
debugger/callstack.hxx
debugger/disassembler.hxx
debugger/graphics.hxx
diff --git a/src/citra_qt/bootmanager.cpp b/src/citra_qt/bootmanager.cpp
index cf4d8b32b..5dce9e570 100644
--- a/src/citra_qt/bootmanager.cpp
+++ b/src/citra_qt/bootmanager.cpp
@@ -6,12 +6,11 @@
#include "bootmanager.hxx"
#include "core/core.h"
-#include "core/loader/loader.h"
-#include "core/hw/hw.h"
+#include "core/settings.h"
#include "video_core/video_core.h"
-#include "version.h"
+#include "citra_qt/version.h"
#define APP_NAME "citra"
#define APP_VERSION "0.1-" VERSION
@@ -102,40 +101,15 @@ private:
GRenderWindow* parent_;
};
-
EmuThread& GRenderWindow::GetEmuThread()
{
return emu_thread;
}
-static const std::pair<int, HID_User::PadState> default_key_map[] = {
- { Qt::Key_A, HID_User::PAD_A },
- { Qt::Key_B, HID_User::PAD_B },
- { Qt::Key_Backslash, HID_User::PAD_SELECT },
- { Qt::Key_Enter, HID_User::PAD_START },
- { Qt::Key_Right, HID_User::PAD_RIGHT },
- { Qt::Key_Left, HID_User::PAD_LEFT },
- { Qt::Key_Up, HID_User::PAD_UP },
- { Qt::Key_Down, HID_User::PAD_DOWN },
- { Qt::Key_R, HID_User::PAD_R },
- { Qt::Key_L, HID_User::PAD_L },
- { Qt::Key_X, HID_User::PAD_X },
- { Qt::Key_Y, HID_User::PAD_Y },
- { Qt::Key_H, HID_User::PAD_CIRCLE_RIGHT },
- { Qt::Key_F, HID_User::PAD_CIRCLE_LEFT },
- { Qt::Key_T, HID_User::PAD_CIRCLE_UP },
- { Qt::Key_G, HID_User::PAD_CIRCLE_DOWN },
-};
-
-GRenderWindow::GRenderWindow(QWidget* parent) : QWidget(parent), emu_thread(this)
+GRenderWindow::GRenderWindow(QWidget* parent) : QWidget(parent), emu_thread(this), keyboard_id(0)
{
- // Register a new ID for the default keyboard
keyboard_id = KeyMap::NewDeviceId();
-
- // Set default key mappings for keyboard
- for (auto mapping : default_key_map) {
- KeyMap::SetKeyMapping({mapping.first, keyboard_id}, mapping.second);
- }
+ ReloadSetKeymaps();
// TODO: One of these flags might be interesting: WA_OpaquePaintEvent, WA_NoBackground, WA_DontShowOnScreen, WA_DeleteOnClose
QGLFormat fmt;
@@ -245,3 +219,23 @@ void GRenderWindow::keyReleaseEvent(QKeyEvent* event)
HID_User::PadUpdateComplete();
}
+void GRenderWindow::ReloadSetKeymaps()
+{
+ KeyMap::SetKeyMapping({Settings::values.pad_a_key, keyboard_id}, HID_User::PAD_A);
+ KeyMap::SetKeyMapping({Settings::values.pad_b_key, keyboard_id}, HID_User::PAD_B);
+ KeyMap::SetKeyMapping({Settings::values.pad_select_key, keyboard_id}, HID_User::PAD_SELECT);
+ KeyMap::SetKeyMapping({Settings::values.pad_start_key, keyboard_id}, HID_User::PAD_START);
+ KeyMap::SetKeyMapping({Settings::values.pad_dright_key, keyboard_id}, HID_User::PAD_RIGHT);
+ KeyMap::SetKeyMapping({Settings::values.pad_dleft_key, keyboard_id}, HID_User::PAD_LEFT);
+ KeyMap::SetKeyMapping({Settings::values.pad_dup_key, keyboard_id}, HID_User::PAD_UP);
+ KeyMap::SetKeyMapping({Settings::values.pad_ddown_key, keyboard_id}, HID_User::PAD_DOWN);
+ KeyMap::SetKeyMapping({Settings::values.pad_r_key, keyboard_id}, HID_User::PAD_R);
+ KeyMap::SetKeyMapping({Settings::values.pad_l_key, keyboard_id}, HID_User::PAD_L);
+ KeyMap::SetKeyMapping({Settings::values.pad_x_key, keyboard_id}, HID_User::PAD_X);
+ KeyMap::SetKeyMapping({Settings::values.pad_y_key, keyboard_id}, HID_User::PAD_Y);
+ KeyMap::SetKeyMapping({Settings::values.pad_sright_key, keyboard_id}, HID_User::PAD_CIRCLE_RIGHT);
+ KeyMap::SetKeyMapping({Settings::values.pad_sleft_key, keyboard_id}, HID_User::PAD_CIRCLE_LEFT);
+ KeyMap::SetKeyMapping({Settings::values.pad_sup_key, keyboard_id}, HID_User::PAD_CIRCLE_UP);
+ KeyMap::SetKeyMapping({Settings::values.pad_sdown_key, keyboard_id}, HID_User::PAD_CIRCLE_DOWN);
+}
+
diff --git a/src/citra_qt/bootmanager.hxx b/src/citra_qt/bootmanager.hxx
index eedf19471..816ffed2e 100644
--- a/src/citra_qt/bootmanager.hxx
+++ b/src/citra_qt/bootmanager.hxx
@@ -107,6 +107,8 @@ public:
void keyPressEvent(QKeyEvent* event);
void keyReleaseEvent(QKeyEvent* event);
+ void ReloadSetKeymaps() override;
+
public slots:
void moveContext();
@@ -117,5 +119,6 @@ private:
QByteArray geometry;
+ /// Device id of keyboard for use with KeyMap
int keyboard_id;
};
diff --git a/src/citra_qt/config.cpp b/src/citra_qt/config.cpp
new file mode 100644
index 000000000..1b116edc5
--- /dev/null
+++ b/src/citra_qt/config.cpp
@@ -0,0 +1,79 @@
+// Copyright 2014 Citra Emulator Project
+// Licensed under GPLv2
+// Refer to the license.txt file included.
+
+#include <QString>
+#include <QStringList>
+
+#include "core/settings.h"
+#include "common/file_util.h"
+
+#include "config.h"
+
+Config::Config() {
+
+ // TODO: Don't hardcode the path; let the frontend decide where to put the config files.
+ qt_config_loc = FileUtil::GetUserPath(D_CONFIG_IDX) + "qt-config.ini";
+ FileUtil::CreateFullPath(qt_config_loc);
+ qt_config = new QSettings(QString::fromStdString(qt_config_loc), QSettings::IniFormat);
+
+ Reload();
+}
+
+void Config::ReadControls() {
+ qt_config->beginGroup("Controls");
+ Settings::values.pad_a_key = qt_config->value("pad_a", Qt::Key_A).toInt();
+ Settings::values.pad_b_key = qt_config->value("pad_b", Qt::Key_S).toInt();
+ Settings::values.pad_x_key = qt_config->value("pad_x", Qt::Key_Z).toInt();
+ Settings::values.pad_y_key = qt_config->value("pad_y", Qt::Key_X).toInt();
+ Settings::values.pad_l_key = qt_config->value("pad_l", Qt::Key_Q).toInt();
+ Settings::values.pad_r_key = qt_config->value("pad_r", Qt::Key_W).toInt();
+ Settings::values.pad_start_key = qt_config->value("pad_start", Qt::Key_M).toInt();
+ Settings::values.pad_select_key = qt_config->value("pad_select", Qt::Key_N).toInt();
+ Settings::values.pad_home_key = qt_config->value("pad_home", Qt::Key_B).toInt();
+ Settings::values.pad_dup_key = qt_config->value("pad_dup", Qt::Key_T).toInt();
+ Settings::values.pad_ddown_key = qt_config->value("pad_ddown", Qt::Key_G).toInt();
+ Settings::values.pad_dleft_key = qt_config->value("pad_dleft", Qt::Key_F).toInt();
+ Settings::values.pad_dright_key = qt_config->value("pad_dright", Qt::Key_H).toInt();
+ Settings::values.pad_sup_key = qt_config->value("pad_sup", Qt::Key_Up).toInt();
+ Settings::values.pad_sdown_key = qt_config->value("pad_sdown", Qt::Key_Down).toInt();
+ Settings::values.pad_sleft_key = qt_config->value("pad_sleft", Qt::Key_Left).toInt();
+ Settings::values.pad_sright_key = qt_config->value("pad_sright", Qt::Key_Right).toInt();
+ qt_config->endGroup();
+}
+
+void Config::SaveControls() {
+ qt_config->beginGroup("Controls");
+ qt_config->setValue("pad_a", Settings::values.pad_a_key);
+ qt_config->setValue("pad_b", Settings::values.pad_b_key);
+ qt_config->setValue("pad_x", Settings::values.pad_x_key);
+ qt_config->setValue("pad_y", Settings::values.pad_y_key);
+ qt_config->setValue("pad_l", Settings::values.pad_l_key);
+ qt_config->setValue("pad_r", Settings::values.pad_r_key);
+ qt_config->setValue("pad_start", Settings::values.pad_start_key);
+ qt_config->setValue("pad_select", Settings::values.pad_select_key);
+ qt_config->setValue("pad_home", Settings::values.pad_home_key);
+ qt_config->setValue("pad_dup", Settings::values.pad_dup_key);
+ qt_config->setValue("pad_ddown", Settings::values.pad_ddown_key);
+ qt_config->setValue("pad_dleft", Settings::values.pad_dleft_key);
+ qt_config->setValue("pad_dright", Settings::values.pad_dright_key);
+ qt_config->setValue("pad_sup", Settings::values.pad_sup_key);
+ qt_config->setValue("pad_sdown", Settings::values.pad_sdown_key);
+ qt_config->setValue("pad_sleft", Settings::values.pad_sleft_key);
+ qt_config->setValue("pad_sright", Settings::values.pad_sright_key);
+ qt_config->endGroup();
+}
+
+void Config::Reload() {
+ ReadControls();
+}
+
+void Config::Save() {
+ SaveControls();
+}
+
+Config::~Config() {
+ Save();
+
+ delete qt_config;
+}
diff --git a/src/citra_qt/config.h b/src/citra_qt/config.h
new file mode 100644
index 000000000..ae390be6b
--- /dev/null
+++ b/src/citra_qt/config.h
@@ -0,0 +1,23 @@
+// Copyright 2014 Citra Emulator Project
+// Licensed under GPLv2
+// Refer to the license.txt file included.
+
+#pragma once
+
+#include <QSettings>
+
+#include "common/common_types.h"
+
+class Config {
+ QSettings* qt_config;
+ std::string qt_config_loc;
+
+ void ReadControls();
+ void SaveControls();
+public:
+ Config();
+ ~Config();
+
+ void Reload();
+ void Save();
+};
diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp
index 1bf9bc53c..bac6a6bb8 100644
--- a/src/citra_qt/main.cpp
+++ b/src/citra_qt/main.cpp
@@ -26,12 +26,16 @@
#include "core/core.h"
#include "core/loader/loader.h"
#include "core/arm/disassembler/load_symbol_map.h"
+#include "citra_qt/config.h"
#include "version.h"
GMainWindow::GMainWindow()
{
+ LogManager::Init();
+ Config config;
+
ui.setupUi(this);
statusBar()->hide();
@@ -112,7 +116,6 @@ GMainWindow::GMainWindow()
show();
- LogManager::Init();
System::Init(render_window);
}
diff --git a/src/common/common_paths.h b/src/common/common_paths.h
index 7cd5b1f35..ae08d082a 100644
--- a/src/common/common_paths.h
+++ b/src/common/common_paths.h
@@ -7,25 +7,25 @@
// Make sure we pick up USER_DIR if set in config.h
#include "common/common.h"
-// Directory seperators, do we need this?
+// Directory separators, do we need this?
#define DIR_SEP "/"
#define DIR_SEP_CHR '/'
#ifndef MAX_PATH
-#define MAX_PATH 260
+#define MAX_PATH 260
#endif
// The user data dir
#define ROOT_DIR "."
#ifdef _WIN32
#define USERDATA_DIR "user"
- #define EMU_DATA_DIR "emu"
+ #define EMU_DATA_DIR "Citra Emulator"
#else
#define USERDATA_DIR "user"
#ifdef USER_DIR
#define EMU_DATA_DIR USER_DIR
#else
- #define EMU_DATA_DIR ".emu"
+ #define EMU_DATA_DIR ".citra-emu"
#endif
#endif
@@ -48,30 +48,30 @@
#define JAP_DIR "JAP"
// Subdirs in the User dir returned by GetUserPath(D_USER_IDX)
-#define CONFIG_DIR "config"
-#define GAMECONFIG_DIR "game_config"
-#define MAPS_DIR "maps"
-#define CACHE_DIR "cache"
+#define CONFIG_DIR "config"
+#define GAMECONFIG_DIR "game_config"
+#define MAPS_DIR "maps"
+#define CACHE_DIR "cache"
#define SDMC_DIR "sdmc"
-#define SHADERCACHE_DIR "shader_cache"
-#define STATESAVES_DIR "state_saves"
-#define SCREENSHOTS_DIR "screenShots"
-#define DUMP_DIR "dump"
-#define DUMP_TEXTURES_DIR "textures"
-#define DUMP_FRAMES_DIR "frames"
-#define DUMP_AUDIO_DIR "audio"
-#define LOGS_DIR "logs"
-#define SHADERS_DIR "shaders"
-#define SYSCONF_DIR "sysconf"
+#define SHADERCACHE_DIR "shader_cache"
+#define STATESAVES_DIR "state_saves"
+#define SCREENSHOTS_DIR "screenShots"
+#define DUMP_DIR "dump"
+#define DUMP_TEXTURES_DIR "textures"
+#define DUMP_FRAMES_DIR "frames"
+#define DUMP_AUDIO_DIR "audio"
+#define LOGS_DIR "logs"
+#define SHADERS_DIR "shaders"
+#define SYSCONF_DIR "sysconf"
// Filenames
// Files in the directory returned by GetUserPath(D_CONFIG_IDX)
#define EMU_CONFIG "emu.ini"
-#define DEBUGGER_CONFIG "debugger.ini"
-#define LOGGER_CONFIG "logger.ini"
+#define DEBUGGER_CONFIG "debugger.ini"
+#define LOGGER_CONFIG "logger.ini"
// Files in the directory returned by GetUserPath(D_LOGS_IDX)
-#define MAIN_LOG "emu.log"
+#define MAIN_LOG "emu.log"
// Files in the directory returned by GetUserPath(D_SYSCONF_IDX)
-#define SYSCONF "SYSCONF"
+#define SYSCONF "SYSCONF"
diff --git a/src/common/console_listener.cpp b/src/common/console_listener.cpp
index 40122224c..53f20d754 100644
--- a/src/common/console_listener.cpp
+++ b/src/common/console_listener.cpp
@@ -241,16 +241,6 @@ void ConsoleListener::PixelSpace(int Left, int Top, int Width, int Height, bool
void ConsoleListener::Log(LogTypes::LOG_LEVELS Level, const char *Text)
{
#if defined(_WIN32)
- /*
- const int MAX_BYTES = 1024*10;
- char Str[MAX_BYTES];
- va_list ArgPtr;
- int Cnt;
- va_start(ArgPtr, Text);
- Cnt = vsnprintf(Str, MAX_BYTES, Text, ArgPtr);
- va_end(ArgPtr);
- */
- DWORD cCharsWritten;
WORD Color;
switch (Level)
diff --git a/src/common/emu_window.h b/src/common/emu_window.h
index 23f178fdf..34cecb40b 100644
--- a/src/common/emu_window.h
+++ b/src/common/emu_window.h
@@ -16,7 +16,7 @@ class EmuWindow
public:
/// Data structure to store an emuwindow configuration
- struct Config{
+ struct WindowConfig {
bool fullscreen;
int res_width;
int res_height;
@@ -34,17 +34,19 @@ public:
/// Releases (dunno if this is the "right" word) the GLFW context from the caller thread
virtual void DoneCurrent() = 0;
+ virtual void ReloadSetKeymaps() = 0;
+
/// Signals a key press action to the HID module
static void KeyPressed(KeyMap::HostDeviceKey key);
/// Signals a key release action to the HID module
static void KeyReleased(KeyMap::HostDeviceKey key);
- Config GetConfig() const {
+ WindowConfig GetConfig() const {
return m_config;
}
- void SetConfig(const Config& val) {
+ void SetConfig(const WindowConfig& val) {
m_config = val;
}
@@ -86,6 +88,6 @@ protected:
int m_client_area_height; ///< Current client height, should be set by window impl.
private:
- Config m_config; ///< Internal configuration
+ WindowConfig m_config; ///< Internal configuration
};
diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp
index 40cd32d96..78a642599 100644
--- a/src/common/file_util.cpp
+++ b/src/common/file_util.cpp
@@ -648,7 +648,7 @@ std::string GetSysDirectory()
return sysDir;
}
-// Returns a string with a Dolphin data dir or file in the user's home
+// Returns a string with a Citra data dir or file in the user's home
// directory. To be used in "multi-user" mode (that is, installed).
const std::string& GetUserPath(const unsigned int DirIDX, const std::string &newPath)
{
@@ -668,22 +668,22 @@ const std::string& GetUserPath(const unsigned int DirIDX, const std::string &new
getenv("PWD") : "") + DIR_SEP EMU_DATA_DIR DIR_SEP;
#endif
- paths[D_CONFIG_IDX] = paths[D_USER_IDX] + CONFIG_DIR DIR_SEP;
- paths[D_GAMECONFIG_IDX] = paths[D_USER_IDX] + GAMECONFIG_DIR DIR_SEP;
- paths[D_MAPS_IDX] = paths[D_USER_IDX] + MAPS_DIR DIR_SEP;
- paths[D_CACHE_IDX] = paths[D_USER_IDX] + CACHE_DIR DIR_SEP;
+ paths[D_CONFIG_IDX] = paths[D_USER_IDX] + CONFIG_DIR DIR_SEP;
+ paths[D_GAMECONFIG_IDX] = paths[D_USER_IDX] + GAMECONFIG_DIR DIR_SEP;
+ paths[D_MAPS_IDX] = paths[D_USER_IDX] + MAPS_DIR DIR_SEP;
+ paths[D_CACHE_IDX] = paths[D_USER_IDX] + CACHE_DIR DIR_SEP;
paths[D_SDMC_IDX] = paths[D_USER_IDX] + SDMC_DIR DIR_SEP;
paths[D_SHADERCACHE_IDX] = paths[D_USER_IDX] + SHADERCACHE_DIR DIR_SEP;
paths[D_SHADERS_IDX] = paths[D_USER_IDX] + SHADERS_DIR DIR_SEP;
- paths[D_STATESAVES_IDX] = paths[D_USER_IDX] + STATESAVES_DIR DIR_SEP;
+ paths[D_STATESAVES_IDX] = paths[D_USER_IDX] + STATESAVES_DIR DIR_SEP;
paths[D_SCREENSHOTS_IDX] = paths[D_USER_IDX] + SCREENSHOTS_DIR DIR_SEP;
- paths[D_DUMP_IDX] = paths[D_USER_IDX] + DUMP_DIR DIR_SEP;
- paths[D_DUMPFRAMES_IDX] = paths[D_DUMP_IDX] + DUMP_FRAMES_DIR DIR_SEP;
- paths[D_DUMPAUDIO_IDX] = paths[D_DUMP_IDX] + DUMP_AUDIO_DIR DIR_SEP;
- paths[D_DUMPTEXTURES_IDX] = paths[D_DUMP_IDX] + DUMP_TEXTURES_DIR DIR_SEP;
- paths[D_LOGS_IDX] = paths[D_USER_IDX] + LOGS_DIR DIR_SEP;
- paths[F_DEBUGGERCONFIG_IDX] = paths[D_CONFIG_IDX] + DEBUGGER_CONFIG;
- paths[F_LOGGERCONFIG_IDX] = paths[D_CONFIG_IDX] + LOGGER_CONFIG;
+ paths[D_DUMP_IDX] = paths[D_USER_IDX] + DUMP_DIR DIR_SEP;
+ paths[D_DUMPFRAMES_IDX] = paths[D_DUMP_IDX] + DUMP_FRAMES_DIR DIR_SEP;
+ paths[D_DUMPAUDIO_IDX] = paths[D_DUMP_IDX] + DUMP_AUDIO_DIR DIR_SEP;
+ paths[D_DUMPTEXTURES_IDX] = paths[D_DUMP_IDX] + DUMP_TEXTURES_DIR DIR_SEP;
+ paths[D_LOGS_IDX] = paths[D_USER_IDX] + LOGS_DIR DIR_SEP;
+ paths[F_DEBUGGERCONFIG_IDX] = paths[D_CONFIG_IDX] + DEBUGGER_CONFIG;
+ paths[F_LOGGERCONFIG_IDX] = paths[D_CONFIG_IDX] + LOGGER_CONFIG;
paths[F_MAINLOG_IDX] = paths[D_LOGS_IDX] + MAIN_LOG;
}
@@ -702,44 +702,44 @@ const std::string& GetUserPath(const unsigned int DirIDX, const std::string &new
switch (DirIDX)
{
case D_ROOT_IDX:
- paths[D_USER_IDX] = paths[D_ROOT_IDX] + DIR_SEP;
- paths[D_SYSCONF_IDX] = paths[D_USER_IDX] + SYSCONF_DIR + DIR_SEP;
- paths[F_SYSCONF_IDX] = paths[D_SYSCONF_IDX] + SYSCONF;
+ paths[D_USER_IDX] = paths[D_ROOT_IDX] + DIR_SEP;
+ paths[D_SYSCONF_IDX] = paths[D_USER_IDX] + SYSCONF_DIR + DIR_SEP;
+ paths[F_SYSCONF_IDX] = paths[D_SYSCONF_IDX] + SYSCONF;
break;
case D_USER_IDX:
- paths[D_USER_IDX] = paths[D_ROOT_IDX] + DIR_SEP;
- paths[D_CONFIG_IDX] = paths[D_USER_IDX] + CONFIG_DIR DIR_SEP;
- paths[D_GAMECONFIG_IDX] = paths[D_USER_IDX] + GAMECONFIG_DIR DIR_SEP;
- paths[D_MAPS_IDX] = paths[D_USER_IDX] + MAPS_DIR DIR_SEP;
- paths[D_CACHE_IDX] = paths[D_USER_IDX] + CACHE_DIR DIR_SEP;
+ paths[D_USER_IDX] = paths[D_ROOT_IDX] + DIR_SEP;
+ paths[D_CONFIG_IDX] = paths[D_USER_IDX] + CONFIG_DIR DIR_SEP;
+ paths[D_GAMECONFIG_IDX] = paths[D_USER_IDX] + GAMECONFIG_DIR DIR_SEP;
+ paths[D_MAPS_IDX] = paths[D_USER_IDX] + MAPS_DIR DIR_SEP;
+ paths[D_CACHE_IDX] = paths[D_USER_IDX] + CACHE_DIR DIR_SEP;
paths[D_SDMC_IDX] = paths[D_USER_IDX] + SDMC_DIR DIR_SEP;
paths[D_SHADERCACHE_IDX] = paths[D_USER_IDX] + SHADERCACHE_DIR DIR_SEP;
paths[D_SHADERS_IDX] = paths[D_USER_IDX] + SHADERS_DIR DIR_SEP;
- paths[D_STATESAVES_IDX] = paths[D_USER_IDX] + STATESAVES_DIR DIR_SEP;
+ paths[D_STATESAVES_IDX] = paths[D_USER_IDX] + STATESAVES_DIR DIR_SEP;
paths[D_SCREENSHOTS_IDX] = paths[D_USER_IDX] + SCREENSHOTS_DIR DIR_SEP;
- paths[D_DUMP_IDX] = paths[D_USER_IDX] + DUMP_DIR DIR_SEP;
- paths[D_DUMPFRAMES_IDX] = paths[D_DUMP_IDX] + DUMP_FRAMES_DIR DIR_SEP;
- paths[D_DUMPAUDIO_IDX] = paths[D_DUMP_IDX] + DUMP_AUDIO_DIR DIR_SEP;
- paths[D_DUMPTEXTURES_IDX] = paths[D_DUMP_IDX] + DUMP_TEXTURES_DIR DIR_SEP;
- paths[D_LOGS_IDX] = paths[D_USER_IDX] + LOGS_DIR DIR_SEP;
+ paths[D_DUMP_IDX] = paths[D_USER_IDX] + DUMP_DIR DIR_SEP;
+ paths[D_DUMPFRAMES_IDX] = paths[D_DUMP_IDX] + DUMP_FRAMES_DIR DIR_SEP;
+ paths[D_DUMPAUDIO_IDX] = paths[D_DUMP_IDX] + DUMP_AUDIO_DIR DIR_SEP;
+ paths[D_DUMPTEXTURES_IDX] = paths[D_DUMP_IDX] + DUMP_TEXTURES_DIR DIR_SEP;
+ paths[D_LOGS_IDX] = paths[D_USER_IDX] + LOGS_DIR DIR_SEP;
paths[D_SYSCONF_IDX] = paths[D_USER_IDX] + SYSCONF_DIR DIR_SEP;
- paths[F_EMUCONFIG_IDX] = paths[D_CONFIG_IDX] + EMU_CONFIG;
- paths[F_DEBUGGERCONFIG_IDX] = paths[D_CONFIG_IDX] + DEBUGGER_CONFIG;
- paths[F_LOGGERCONFIG_IDX] = paths[D_CONFIG_IDX] + LOGGER_CONFIG;
+ paths[F_EMUCONFIG_IDX] = paths[D_CONFIG_IDX] + EMU_CONFIG;
+ paths[F_DEBUGGERCONFIG_IDX] = paths[D_CONFIG_IDX] + DEBUGGER_CONFIG;
+ paths[F_LOGGERCONFIG_IDX] = paths[D_CONFIG_IDX] + LOGGER_CONFIG;
paths[F_MAINLOG_IDX] = paths[D_LOGS_IDX] + MAIN_LOG;
break;
case D_CONFIG_IDX:
- paths[F_EMUCONFIG_IDX] = paths[D_CONFIG_IDX] + EMU_CONFIG;
- paths[F_DEBUGGERCONFIG_IDX] = paths[D_CONFIG_IDX] + DEBUGGER_CONFIG;
- paths[F_LOGGERCONFIG_IDX] = paths[D_CONFIG_IDX] + LOGGER_CONFIG;
+ paths[F_EMUCONFIG_IDX] = paths[D_CONFIG_IDX] + EMU_CONFIG;
+ paths[F_DEBUGGERCONFIG_IDX] = paths[D_CONFIG_IDX] + DEBUGGER_CONFIG;
+ paths[F_LOGGERCONFIG_IDX] = paths[D_CONFIG_IDX] + LOGGER_CONFIG;
break;
case D_DUMP_IDX:
- paths[D_DUMPFRAMES_IDX] = paths[D_DUMP_IDX] + DUMP_FRAMES_DIR DIR_SEP;
- paths[D_DUMPAUDIO_IDX] = paths[D_DUMP_IDX] + DUMP_AUDIO_DIR DIR_SEP;
- paths[D_DUMPTEXTURES_IDX] = paths[D_DUMP_IDX] + DUMP_TEXTURES_DIR DIR_SEP;
+ paths[D_DUMPFRAMES_IDX] = paths[D_DUMP_IDX] + DUMP_FRAMES_DIR DIR_SEP;
+ paths[D_DUMPAUDIO_IDX] = paths[D_DUMP_IDX] + DUMP_AUDIO_DIR DIR_SEP;
+ paths[D_DUMPTEXTURES_IDX] = paths[D_DUMP_IDX] + DUMP_TEXTURES_DIR DIR_SEP;
break;
case D_LOGS_IDX:
@@ -763,12 +763,12 @@ const std::string& GetUserPath(const unsigned int DirIDX, const std::string &new
// return dir;
//}
-bool WriteStringToFile(bool text_file, const std::string &str, const char *filename)
+size_t WriteStringToFile(bool text_file, const std::string &str, const char *filename)
{
return FileUtil::IOFile(filename, text_file ? "w" : "wb").WriteBytes(str.data(), str.size());
}
-bool ReadFileToString(bool text_file, const char *filename, std::string &str)
+size_t ReadFileToString(bool text_file, const char *filename, std::string &str)
{
FileUtil::IOFile file(filename, text_file ? "r" : "rb");
auto const f = file.GetHandle();
@@ -780,6 +780,48 @@ bool ReadFileToString(bool text_file, const char *filename, std::string &str)
return file.ReadArray(&str[0], str.size());
}
+/**
+ * Splits the filename into 8.3 format
+ * Loosely implemented following https://en.wikipedia.org/wiki/8.3_filename
+ * @param filename The normal filename to use
+ * @param short_name A 9-char array in which the short name will be written
+ * @param extension A 4-char array in which the extension will be written
+ */
+void SplitFilename83(const std::string& filename, std::array<char, 9>& short_name,
+ std::array<char, 4>& extension) {
+ const std::string forbidden_characters = ".\"/\\[]:;=, ";
+
+ // On a FAT32 partition, 8.3 names are stored as a 11 bytes array, filled with spaces.
+ short_name = {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '\0'};
+ extension = {' ', ' ', ' ', '\0'};
+
+ std::string::size_type point = filename.rfind('.');
+ if (point == filename.size() - 1)
+ point = filename.rfind('.', point);
+
+ // Get short name.
+ int j = 0;
+ for (char letter : filename.substr(0, point)) {
+ if (forbidden_characters.find(letter, 0) != std::string::npos)
+ continue;
+ if (j == 8) {
+ // TODO(Link Mauve): also do that for filenames containing a space.
+ // TODO(Link Mauve): handle multiple files having the same short name.
+ short_name[6] = '~';
+ short_name[7] = '1';
+ break;
+ }
+ short_name[j++] = toupper(letter);
+ }
+
+ // Get extension.
+ if (point != std::string::npos) {
+ j = 0;
+ for (char letter : filename.substr(point + 1, 3))
+ extension[j++] = toupper(letter);
+ }
+}
+
IOFile::IOFile()
: m_file(NULL), m_good(true)
{}
diff --git a/src/common/file_util.h b/src/common/file_util.h
index cddcd1951..173ce6623 100644
--- a/src/common/file_util.h
+++ b/src/common/file_util.h
@@ -4,11 +4,12 @@
#pragma once
+#include <array>
#include <fstream>
#include <cstdio>
+#include <cstring>
#include <string>
#include <vector>
-#include <string.h>
#include "common/common.h"
#include "common/string_util.h"
@@ -47,7 +48,7 @@ enum {
namespace FileUtil
{
-// FileSystem tree node/
+// FileSystem tree node/
struct FSTEntry
{
bool isDirectory;
@@ -85,13 +86,13 @@ bool Delete(const std::string &filename);
// Deletes a directory filename, returns true on success
bool DeleteDir(const std::string &filename);
-// renames file srcFilename to destFilename, returns true on success
+// renames file srcFilename to destFilename, returns true on success
bool Rename(const std::string &srcFilename, const std::string &destFilename);
-// copies file srcFilename to destFilename, returns true on success
+// copies file srcFilename to destFilename, returns true on success
bool Copy(const std::string &srcFilename, const std::string &destFilename);
-// creates an empty file filename, returns true on success
+// creates an empty file filename, returns true on success
bool CreateEmptyFile(const std::string &filename);
// Scans the directory tree gets, starting from _Directory and adds the
@@ -110,7 +111,7 @@ void CopyDir(const std::string &source_path, const std::string &dest_path);
// Set the current directory to given directory
bool SetCurrentDir(const std::string &directory);
-// Returns a pointer to a string with a Dolphin data dir in the user's home
+// Returns a pointer to a string with a Citra data dir in the user's home
// directory. To be used in "multi-user" mode (that is, installed).
const std::string& GetUserPath(const unsigned int DirIDX, const std::string &newPath="");
@@ -128,8 +129,18 @@ std::string GetBundleDirectory();
std::string &GetExeDirectory();
#endif
-bool WriteStringToFile(bool text_file, const std::string &str, const char *filename);
-bool ReadFileToString(bool text_file, const char *filename, std::string &str);
+size_t WriteStringToFile(bool text_file, const std::string &str, const char *filename);
+size_t ReadFileToString(bool text_file, const char *filename, std::string &str);
+
+/**
+ * Splits the filename into 8.3 format
+ * Loosely implemented following https://en.wikipedia.org/wiki/8.3_filename
+ * @param filename The normal filename to use
+ * @param short_name A 9-char array in which the short name will be written
+ * @param extension A 4-char array in which the extension will be written
+ */
+void SplitFilename83(const std::string& filename, std::array<char, 9>& short_name,
+ std::array<char, 4>& extension);
// simple wrapper for cstdlib file functions to
// hopefully will make error checking easier
@@ -142,10 +153,10 @@ public:
IOFile(const std::string& filename, const char openmode[]);
~IOFile();
-
+
IOFile(IOFile&& other);
IOFile& operator=(IOFile&& other);
-
+
void Swap(IOFile& other);
bool Open(const std::string& filename, const char openmode[]);
diff --git a/src/common/log.h b/src/common/log.h
index 291534c67..bfd73f8a5 100644
--- a/src/common/log.h
+++ b/src/common/log.h
@@ -28,6 +28,7 @@ enum LOG_TYPE {
COMMANDPROCESSOR,
COMMON,
CONSOLE,
+ CONFIG,
DISCIO,
FILEMON,
DSPHLE,
diff --git a/src/common/log_manager.cpp b/src/common/log_manager.cpp
index 28b72fa20..4d590d98f 100644
--- a/src/common/log_manager.cpp
+++ b/src/common/log_manager.cpp
@@ -30,6 +30,7 @@ LogManager::LogManager()
m_Log[LogTypes::MASTER_LOG] = new LogContainer("*", "Master Log");
m_Log[LogTypes::BOOT] = new LogContainer("BOOT", "Boot");
m_Log[LogTypes::COMMON] = new LogContainer("COMMON", "Common");
+ m_Log[LogTypes::CONFIG] = new LogContainer("CONFIG", "Configuration");
m_Log[LogTypes::DISCIO] = new LogContainer("DIO", "Disc IO");
m_Log[LogTypes::FILEMON] = new LogContainer("FileMon", "File Monitor");
m_Log[LogTypes::PAD] = new LogContainer("PAD", "Pad");
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
index 2b26292fd..06df9a677 100644
--- a/src/core/CMakeLists.txt
+++ b/src/core/CMakeLists.txt
@@ -56,6 +56,7 @@ set(SRCS
core_timing.cpp
mem_map.cpp
mem_map_funcs.cpp
+ settings.cpp
system.cpp
)
@@ -117,6 +118,7 @@ set(HEADERS
core.h
core_timing.h
mem_map.h
+ settings.h
system.h
)
diff --git a/src/core/file_sys/archive_sdmc.cpp b/src/core/file_sys/archive_sdmc.cpp
index 30d33be5f..213923c02 100644
--- a/src/core/file_sys/archive_sdmc.cpp
+++ b/src/core/file_sys/archive_sdmc.cpp
@@ -24,6 +24,10 @@ Archive_SDMC::Archive_SDMC(const std::string& mount_point) {
Archive_SDMC::~Archive_SDMC() {
}
+/**
+ * Initialize the archive.
+ * @return true if it initialized successfully
+ */
bool Archive_SDMC::Initialize() {
if (!FileUtil::IsDirectory(mount_point)) {
WARN_LOG(FILESYS, "Directory %s not found, disabling SDMC.", mount_point.c_str());
@@ -42,6 +46,8 @@ bool Archive_SDMC::Initialize() {
std::unique_ptr<File> Archive_SDMC::OpenFile(const std::string& path, const Mode mode) const {
DEBUG_LOG(FILESYS, "called path=%s mode=%d", path.c_str(), mode);
File_SDMC* file = new File_SDMC(this, path, mode);
+ if (!file->Open())
+ return nullptr;
return std::unique_ptr<File>(file);
}
diff --git a/src/core/file_sys/archive_sdmc.h b/src/core/file_sys/archive_sdmc.h
index 946f8b957..f68648e6f 100644
--- a/src/core/file_sys/archive_sdmc.h
+++ b/src/core/file_sys/archive_sdmc.h
@@ -20,6 +20,10 @@ public:
Archive_SDMC(const std::string& mount_point);
~Archive_SDMC() override;
+ /**
+ * Initialize the archive.
+ * @return true if it initialized successfully
+ */
bool Initialize();
/**
diff --git a/src/core/file_sys/directory.h b/src/core/file_sys/directory.h
index cf9a2010b..e10431337 100644
--- a/src/core/file_sys/directory.h
+++ b/src/core/file_sys/directory.h
@@ -4,6 +4,8 @@
#pragma once
+#include <cstddef>
+
#include "common/common_types.h"
#include "core/hle/kernel/kernel.h"
@@ -17,9 +19,9 @@ namespace FileSys {
const size_t FILENAME_LENGTH = 0x20C / 2;
struct Entry {
char16_t filename[FILENAME_LENGTH]; // Entry name (UTF-16, null-terminated)
- char short_name[8]; // 8.3 file name ('longfilename' -> 'LONGFI~1')
+ std::array<char, 9> short_name; // 8.3 file name ('longfilename' -> 'LONGFI~1', null-terminated)
char unknown1; // unknown (observed values: 0x0A, 0x70, 0xFD)
- char extension[3]; // 8.3 file extension (set to spaces for directories)
+ std::array<char, 4> extension; // 8.3 file extension (set to spaces for directories, null-terminated)
char unknown2; // unknown (always 0x01)
char unknown3; // unknown (0x00 or 0x08)
char is_directory; // directory flag
@@ -29,6 +31,10 @@ struct Entry {
u64 file_size; // file size (for files only)
};
static_assert(sizeof(Entry) == 0x228, "Directory Entry struct isn't exactly 0x228 bytes long!");
+static_assert(offsetof(Entry, short_name) == 0x20C, "Wrong offset for short_name in Entry.");
+static_assert(offsetof(Entry, extension) == 0x216, "Wrong offset for extension in Entry.");
+static_assert(offsetof(Entry, is_archive) == 0x21E, "Wrong offset for is_archive in Entry.");
+static_assert(offsetof(Entry, file_size) == 0x220, "Wrong offset for file_size in Entry.");
class Directory : NonCopyable {
public:
diff --git a/src/core/file_sys/directory_sdmc.cpp b/src/core/file_sys/directory_sdmc.cpp
index 11e867857..36951564d 100644
--- a/src/core/file_sys/directory_sdmc.cpp
+++ b/src/core/file_sys/directory_sdmc.cpp
@@ -20,8 +20,8 @@ Directory_SDMC::Directory_SDMC(const Archive_SDMC* archive, const std::string& p
// the root directory we set while opening the archive.
// For example, opening /../../usr/bin can give the emulated program your installed programs.
std::string absolute_path = archive->GetMountPoint() + path;
- entry_count = FileUtil::ScanDirectoryTree(absolute_path, entry);
- current_entry = 0;
+ FileUtil::ScanDirectoryTree(absolute_path, directory);
+ children_iterator = directory.children.begin();
}
Directory_SDMC::~Directory_SDMC() {
@@ -35,44 +35,39 @@ Directory_SDMC::~Directory_SDMC() {
* @return Number of entries listed
*/
u32 Directory_SDMC::Read(const u32 count, Entry* entries) {
- u32 i;
- for (i = 0; i < count && current_entry < entry_count; ++i) {
- FileUtil::FSTEntry file = entry.children[current_entry];
- std::string filename = file.virtualName;
- WARN_LOG(FILESYS, "File %s: size=%d dir=%d", filename.c_str(), file.size, file.isDirectory);
+ u32 entries_read = 0;
+
+ while (entries_read < count && children_iterator != directory.children.cend()) {
+ const FileUtil::FSTEntry& file = *children_iterator;
+ const std::string& filename = file.virtualName;
+ Entry& entry = entries[entries_read];
- Entry* entry = &entries[i];
+ WARN_LOG(FILESYS, "File %s: size=%d dir=%d", filename.c_str(), file.size, file.isDirectory);
// TODO(Link Mauve): use a proper conversion to UTF-16.
for (int j = 0; j < FILENAME_LENGTH; ++j) {
- entry->filename[j] = filename[j];
+ entry.filename[j] = filename[j];
if (!filename[j])
break;
}
- // Split the filename into 8.3 format.
- // TODO(Link Mauve): move that to common, I guess, and make it more robust to long filenames.
- std::string::size_type n = filename.rfind('.');
- if (n == std::string::npos) {
- strncpy(entry->short_name, filename.c_str(), 8);
- memset(entry->extension, '\0', 3);
- } else {
- strncpy(entry->short_name, filename.substr(0, n).c_str(), 8);
- strncpy(entry->extension, filename.substr(n + 1).c_str(), 8);
- }
+ FileUtil::SplitFilename83(filename, entry.short_name, entry.extension);
- entry->is_directory = file.isDirectory;
- entry->file_size = file.size;
+ entry.is_directory = file.isDirectory;
+ entry.is_hidden = (filename[0] == '.');
+ entry.is_read_only = 0;
+ entry.file_size = file.size;
// We emulate a SD card where the archive bit has never been cleared, as it would be on
// most user SD cards.
// Some homebrews (blargSNES for instance) are known to mistakenly use the archive bit as a
// file bit.
- entry->is_archive = !file.isDirectory;
+ entry.is_archive = !file.isDirectory;
- ++current_entry;
+ ++entries_read;
+ ++children_iterator;
}
- return i;
+ return entries_read;
}
/**
diff --git a/src/core/file_sys/directory_sdmc.h b/src/core/file_sys/directory_sdmc.h
index 0bc6c9eff..cb8d32fda 100644
--- a/src/core/file_sys/directory_sdmc.h
+++ b/src/core/file_sys/directory_sdmc.h
@@ -37,9 +37,12 @@ public:
bool Close() const override;
private:
- u32 entry_count;
- u32 current_entry;
- FileUtil::FSTEntry entry;
+ u32 total_entries_in_directory;
+ FileUtil::FSTEntry directory;
+
+ // We need to remember the last entry we returned, so a subsequent call to Read will continue
+ // from the next one. This iterator will always point to the next unread entry.
+ std::vector<FileUtil::FSTEntry>::iterator children_iterator;
};
} // namespace FileSys
diff --git a/src/core/file_sys/file.h b/src/core/file_sys/file.h
index f7b009f5a..4013b6c3e 100644
--- a/src/core/file_sys/file.h
+++ b/src/core/file_sys/file.h
@@ -19,6 +19,12 @@ public:
virtual ~File() { }
/**
+ * Open the file
+ * @return true if the file opened correctly
+ */
+ virtual bool Open() = 0;
+
+ /**
* Read data from the file
* @param offset Offset in bytes to start reading data from
* @param length Length in bytes of data to read from file
@@ -31,8 +37,8 @@ public:
* Write data to the file
* @param offset Offset in bytes to start writing data to
* @param length Length in bytes of data to write to file
- * @param buffer Buffer to write data from
* @param flush The flush parameters (0 == do not flush)
+ * @param buffer Buffer to read data from
* @return Number of bytes written
*/
virtual size_t Write(const u64 offset, const u32 length, const u32 flush, const u8* buffer) const = 0;
@@ -44,6 +50,13 @@ public:
virtual size_t GetSize() const = 0;
/**
+ * Set the size of the file in bytes
+ * @param size New size of the file
+ * @return true if successful
+ */
+ virtual bool SetSize(const u64 size) const = 0;
+
+ /**
* Close the file
* @return true if the file closed correctly
*/
diff --git a/src/core/file_sys/file_romfs.cpp b/src/core/file_sys/file_romfs.cpp
index 00f3c2ea8..b55708df4 100644
--- a/src/core/file_sys/file_romfs.cpp
+++ b/src/core/file_sys/file_romfs.cpp
@@ -18,6 +18,14 @@ File_RomFS::~File_RomFS() {
}
/**
+ * Open the file
+ * @return true if the file opened correctly
+ */
+bool File_RomFS::Open() {
+ return false;
+}
+
+/**
* Read data from the file
* @param offset Offset in bytes to start reading data from
* @param length Length in bytes of data to read from file
@@ -32,8 +40,8 @@ size_t File_RomFS::Read(const u64 offset, const u32 length, u8* buffer) const {
* Write data to the file
* @param offset Offset in bytes to start writing data to
* @param length Length in bytes of data to write to file
- * @param buffer Buffer to write data from
* @param flush The flush parameters (0 == do not flush)
+ * @param buffer Buffer to read data from
* @return Number of bytes written
*/
size_t File_RomFS::Write(const u64 offset, const u32 length, const u32 flush, const u8* buffer) const {
@@ -49,6 +57,15 @@ size_t File_RomFS::GetSize() const {
}
/**
+ * Set the size of the file in bytes
+ * @param size New size of the file
+ * @return true if successful
+ */
+bool File_RomFS::SetSize(const u64 size) const {
+ return false;
+}
+
+/**
* Close the file
* @return true if the file closed correctly
*/
diff --git a/src/core/file_sys/file_romfs.h b/src/core/file_sys/file_romfs.h
index 5db43d4a0..5196701d3 100644
--- a/src/core/file_sys/file_romfs.h
+++ b/src/core/file_sys/file_romfs.h
@@ -20,6 +20,12 @@ public:
~File_RomFS() override;
/**
+ * Open the file
+ * @return true if the file opened correctly
+ */
+ bool Open() override;
+
+ /**
* Read data from the file
* @param offset Offset in bytes to start reading data from
* @param length Length in bytes of data to read from file
@@ -32,8 +38,8 @@ public:
* Write data to the file
* @param offset Offset in bytes to start writing data to
* @param length Length in bytes of data to write to file
- * @param buffer Buffer to write data from
* @param flush The flush parameters (0 == do not flush)
+ * @param buffer Buffer to read data from
* @return Number of bytes written
*/
size_t Write(const u64 offset, const u32 length, const u32 flush, const u8* buffer) const override;
@@ -45,6 +51,13 @@ public:
size_t GetSize() const override;
/**
+ * Set the size of the file in bytes
+ * @param size New size of the file
+ * @return true if successful
+ */
+ bool SetSize(const u64 size) const override;
+
+ /**
* Close the file
* @return true if the file closed correctly
*/
diff --git a/src/core/file_sys/file_sdmc.cpp b/src/core/file_sys/file_sdmc.cpp
index 76adc6403..26204392c 100644
--- a/src/core/file_sys/file_sdmc.cpp
+++ b/src/core/file_sys/file_sdmc.cpp
@@ -19,31 +19,56 @@ File_SDMC::File_SDMC(const Archive_SDMC* archive, const std::string& path, const
// TODO(Link Mauve): normalize path into an absolute path without "..", it can currently bypass
// the root directory we set while opening the archive.
// For example, opening /../../etc/passwd can give the emulated program your users list.
- std::string real_path = archive->GetMountPoint() + path;
+ this->path = archive->GetMountPoint() + path;
+ this->mode.hex = mode.hex;
+}
+
+File_SDMC::~File_SDMC() {
+ Close();
+}
- if (!mode.create_flag && !FileUtil::Exists(real_path)) {
- file = nullptr;
- return;
+/**
+ * Open the file
+ * @return true if the file opened correctly
+ */
+bool File_SDMC::Open() {
+ if (!mode.create_flag && !FileUtil::Exists(path)) {
+ ERROR_LOG(FILESYS, "Non-existing file %s can’t be open without mode create.", path.c_str());
+ return false;
}
std::string mode_string;
- if (mode.read_flag)
- mode_string += "r";
- if (mode.write_flag)
- mode_string += "w";
+ if (mode.read_flag && mode.write_flag)
+ mode_string = "w+";
+ else if (mode.read_flag)
+ mode_string = "r";
+ else if (mode.write_flag)
+ mode_string = "w";
- file = new FileUtil::IOFile(real_path, mode_string.c_str());
-}
-
-File_SDMC::~File_SDMC() {
- Close();
+ file = new FileUtil::IOFile(path, mode_string.c_str());
+ return true;
}
+/**
+ * Read data from the file
+ * @param offset Offset in bytes to start reading data from
+ * @param length Length in bytes of data to read from file
+ * @param buffer Buffer to read data into
+ * @return Number of bytes read
+ */
size_t File_SDMC::Read(const u64 offset, const u32 length, u8* buffer) const {
file->Seek(offset, SEEK_SET);
return file->ReadBytes(buffer, length);
}
+/**
+ * Write data to the file
+ * @param offset Offset in bytes to start writing data to
+ * @param length Length in bytes of data to write to file
+ * @param flush The flush parameters (0 == do not flush)
+ * @param buffer Buffer to read data from
+ * @return Number of bytes written
+ */
size_t File_SDMC::Write(const u64 offset, const u32 length, const u32 flush, const u8* buffer) const {
file->Seek(offset, SEEK_SET);
size_t written = file->WriteBytes(buffer, length);
@@ -52,10 +77,29 @@ size_t File_SDMC::Write(const u64 offset, const u32 length, const u32 flush, con
return written;
}
+/**
+ * Get the size of the file in bytes
+ * @return Size of the file in bytes
+ */
size_t File_SDMC::GetSize() const {
- return file->GetSize();
+ return static_cast<size_t>(file->GetSize());
+}
+
+/**
+ * Set the size of the file in bytes
+ * @param size New size of the file
+ * @return true if successful
+ */
+bool File_SDMC::SetSize(const u64 size) const {
+ file->Resize(size);
+ file->Flush();
+ return true;
}
+/**
+ * Close the file
+ * @return true if the file closed correctly
+ */
bool File_SDMC::Close() const {
return file->Close();
}
diff --git a/src/core/file_sys/file_sdmc.h b/src/core/file_sys/file_sdmc.h
index b2e46f449..df032f7c0 100644
--- a/src/core/file_sys/file_sdmc.h
+++ b/src/core/file_sys/file_sdmc.h
@@ -23,6 +23,12 @@ public:
~File_SDMC() override;
/**
+ * Open the file
+ * @return true if the file opened correctly
+ */
+ bool Open() override;
+
+ /**
* Read data from the file
* @param offset Offset in bytes to start reading data from
* @param length Length in bytes of data to read from file
@@ -35,8 +41,8 @@ public:
* Write data to the file
* @param offset Offset in bytes to start writing data to
* @param length Length in bytes of data to write to file
- * @param buffer Buffer to write data from
* @param flush The flush parameters (0 == do not flush)
+ * @param buffer Buffer to read data from
* @return Number of bytes written
*/
size_t Write(const u64 offset, const u32 length, const u32 flush, const u8* buffer) const override;
@@ -48,12 +54,21 @@ public:
size_t GetSize() const override;
/**
+ * Set the size of the file in bytes
+ * @param size New size of the file
+ * @return true if successful
+ */
+ bool SetSize(const u64 size) const override;
+
+ /**
* Close the file
* @return true if the file closed correctly
*/
bool Close() const override;
private:
+ std::string path;
+ Mode mode;
FileUtil::IOFile* file;
};
diff --git a/src/core/hle/kernel/archive.cpp b/src/core/hle/kernel/archive.cpp
index fa4972994..86aba7489 100644
--- a/src/core/hle/kernel/archive.cpp
+++ b/src/core/hle/kernel/archive.cpp
@@ -181,6 +181,14 @@ public:
break;
}
+ case FileCommand::SetSize:
+ {
+ u64 size = cmd_buff[1] | ((u64)cmd_buff[2] << 32);
+ DEBUG_LOG(KERNEL, "SetSize %s %s size=%d", GetTypeName().c_str(), GetName().c_str(), size);
+ backend->SetSize(size);
+ break;
+ }
+
case FileCommand::Close:
{
DEBUG_LOG(KERNEL, "Close %s %s", GetTypeName().c_str(), GetName().c_str());
@@ -366,6 +374,9 @@ Handle OpenFileFromArchive(Handle archive_handle, const std::string& path, const
file->path = path;
file->backend = archive->backend->OpenFile(path, mode);
+ if (!file->backend)
+ return 0;
+
return handle;
}
diff --git a/src/core/hle/service/apt.cpp b/src/core/hle/service/apt.cpp
index e97e7dbf7..3753f1107 100644
--- a/src/core/hle/service/apt.cpp
+++ b/src/core/hle/service/apt.cpp
@@ -73,6 +73,36 @@ void ReceiveParameter(Service::Interface* self) {
WARN_LOG(KERNEL, "(STUBBED) called app_id=0x%08X, buffer_size=0x%08X", app_id, buffer_size);
}
+/**
+* APT_U::GlanceParameter service function
+* Inputs:
+* 1 : AppID
+* 2 : Parameter buffer size, max size is 0x1000
+* Outputs:
+* 1 : Result of function, 0 on success, otherwise error code
+* 2 : Unknown, for now assume AppID of the process which sent these parameters
+* 3 : Unknown, for now assume Signal type
+* 4 : Actual parameter buffer size, this is <= to the the input size
+* 5 : Value
+* 6 : Handle from the source process which set the parameters, likely used for shared memory
+* 7 : Size
+* 8 : Output parameter buffer ptr
+*/
+void GlanceParameter(Service::Interface* self) {
+ u32* cmd_buff = Service::GetCommandBuffer();
+ u32 app_id = cmd_buff[1];
+ u32 buffer_size = cmd_buff[2];
+ cmd_buff[1] = 0; // No error
+ cmd_buff[2] = 0;
+ cmd_buff[3] = static_cast<u32>(SignalType::AppJustStarted); // Signal type
+ cmd_buff[4] = 0;
+ cmd_buff[5] = 0;
+ cmd_buff[6] = 0;
+ cmd_buff[7] = 0;
+ cmd_buff[8] = 0;
+ WARN_LOG(KERNEL, "(STUBBED) called app_id=0x%08X, buffer_size=0x%08X", app_id, buffer_size);
+}
+
const Interface::FunctionInfo FunctionTable[] = {
{0x00010040, GetLockHandle, "GetLockHandle"},
{0x00020080, Initialize, "Initialize"},
@@ -87,7 +117,7 @@ const Interface::FunctionInfo FunctionTable[] = {
{0x000B0040, InquireNotification, "InquireNotification"},
{0x000C0104, nullptr, "SendParameter"},
{0x000D0080, ReceiveParameter, "ReceiveParameter"},
- {0x000E0080, nullptr, "GlanceParameter"},
+ {0x000E0080, GlanceParameter, "GlanceParameter"},
{0x000F0100, nullptr, "CancelParameter"},
{0x001000C2, nullptr, "DebugFunc"},
{0x001100C0, nullptr, "MapProgramIdForDebug"},
@@ -152,6 +182,8 @@ const Interface::FunctionInfo FunctionTable[] = {
{0x004C0000, nullptr, "SetFatalErrDispMode"},
{0x004D0080, nullptr, "GetAppletProgramInfo"},
{0x004E0000, nullptr, "HardwareResetAsync"},
+ {0x004F0080, nullptr, "SetApplicationCpuTimeLimit"},
+ {0x00500040, nullptr, "GetApplicationCpuTimeLimit"},
};
////////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/core/hle/service/gsp.cpp b/src/core/hle/service/gsp.cpp
index accbe84e3..614d9584d 100644
--- a/src/core/hle/service/gsp.cpp
+++ b/src/core/hle/service/gsp.cpp
@@ -358,6 +358,7 @@ const Interface::FunctionInfo FunctionTable[] = {
{0x001C0040, nullptr, "SetLedForceOff"},
{0x001D0040, nullptr, "SetTestCommand"},
{0x001E0080, nullptr, "SetInternalPriorities"},
+ {0x001F0082, nullptr, "StoreDataCache"},
};
////////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/core/mem_map_funcs.cpp b/src/core/mem_map_funcs.cpp
index f510df835..90951812b 100644
--- a/src/core/mem_map_funcs.cpp
+++ b/src/core/mem_map_funcs.cpp
@@ -287,7 +287,7 @@ void Write64(const VAddr addr, const u64 data) {
}
void WriteBlock(const VAddr addr, const u8* data, const size_t size) {
- int offset = 0;
+ u32 offset = 0;
while (offset < (size & ~3)) {
Write32(addr + offset, *(u32*)&data[offset]);
offset += 4;
diff --git a/src/core/settings.cpp b/src/core/settings.cpp
new file mode 100644
index 000000000..c486f6274
--- /dev/null
+++ b/src/core/settings.cpp
@@ -0,0 +1,11 @@
+// Copyright 2014 Citra Emulator Project
+// Licensed under GPLv2
+// Refer to the license.txt file included.
+
+#include "settings.h"
+
+namespace Settings {
+
+Values values = {};
+
+}
diff --git a/src/core/settings.h b/src/core/settings.h
new file mode 100644
index 000000000..a84c3d4b6
--- /dev/null
+++ b/src/core/settings.h
@@ -0,0 +1,29 @@
+// Copyright 2014 Citra Emulator Project
+// Licensed under GPLv2
+// Refer to the license.txt file included.
+
+#pragma once
+
+namespace Settings {
+
+struct Values {
+ int pad_a_key;
+ int pad_b_key;
+ int pad_x_key;
+ int pad_y_key;
+ int pad_l_key;
+ int pad_r_key;
+ int pad_start_key;
+ int pad_select_key;
+ int pad_home_key;
+ int pad_dup_key;
+ int pad_ddown_key;
+ int pad_dleft_key;
+ int pad_dright_key;
+ int pad_sup_key;
+ int pad_sdown_key;
+ int pad_sleft_key;
+ int pad_sright_key;
+} extern values;
+
+}