summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/CMakeLists.txt2
-rw-r--r--src/core/arm/dyncom/arm_dyncom_interpreter.cpp63
-rw-r--r--src/core/arm/skyeye_common/vfp/vfp.cpp20
-rw-r--r--src/core/arm/skyeye_common/vfp/vfp.h1
-rw-r--r--src/core/arm/skyeye_common/vfp/vfpdouble.cpp2
-rw-r--r--src/core/arm/skyeye_common/vfp/vfpinstr.cpp35
-rw-r--r--src/core/arm/skyeye_common/vfp/vfpsingle.cpp2
-rw-r--r--src/core/file_sys/archive_backend.h17
-rw-r--r--src/core/file_sys/archive_extsavedata.cpp59
-rw-r--r--src/core/file_sys/archive_extsavedata.h45
-rw-r--r--src/core/file_sys/archive_romfs.cpp5
-rw-r--r--src/core/file_sys/archive_romfs.h6
-rw-r--r--src/core/file_sys/archive_savedata.cpp25
-rw-r--r--src/core/file_sys/archive_savedata.h19
-rw-r--r--src/core/file_sys/disk_archive.h7
-rw-r--r--src/core/hle/service/apt_a.cpp29
-rw-r--r--src/core/hle/service/fs/archive.cpp59
-rw-r--r--src/core/hle/service/fs/archive.h3
-rw-r--r--src/core/hle/service/fs/fs_user.cpp17
-rw-r--r--src/core/hle/service/ptm_u.cpp47
-rw-r--r--src/core/mem_map.cpp3
-rw-r--r--src/core/mem_map.h1
-rw-r--r--src/core/mem_map_funcs.cpp10
23 files changed, 391 insertions, 86 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
index fdd97c184..89ea70d23 100644
--- a/src/core/CMakeLists.txt
+++ b/src/core/CMakeLists.txt
@@ -17,6 +17,7 @@ set(SRCS
arm/skyeye_common/vfp/vfpdouble.cpp
arm/skyeye_common/vfp/vfpinstr.cpp
arm/skyeye_common/vfp/vfpsingle.cpp
+ file_sys/archive_extsavedata.cpp
file_sys/archive_romfs.cpp
file_sys/archive_savedata.cpp
file_sys/archive_sdmc.cpp
@@ -104,6 +105,7 @@ set(HEADERS
arm/skyeye_common/vfp/vfp_helper.h
arm/arm_interface.h
file_sys/archive_backend.h
+ file_sys/archive_extsavedata.h
file_sys/archive_romfs.h
file_sys/archive_savedata.h
file_sys/archive_sdmc.h
diff --git a/src/core/arm/dyncom/arm_dyncom_interpreter.cpp b/src/core/arm/dyncom/arm_dyncom_interpreter.cpp
index 53da7ca9c..ce316ead6 100644
--- a/src/core/arm/dyncom/arm_dyncom_interpreter.cpp
+++ b/src/core/arm/dyncom/arm_dyncom_interpreter.cpp
@@ -2559,7 +2559,22 @@ ARM_INST_PTR INTERPRETER_TRANSLATE(ssat)(unsigned int inst, int index)
return inst_base;
}
-ARM_INST_PTR INTERPRETER_TRANSLATE(ssat16)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SSAT16"); }
+ARM_INST_PTR INTERPRETER_TRANSLATE(ssat16)(unsigned int inst, int index)
+{
+ arm_inst* const inst_base = (arm_inst*)AllocBuffer(sizeof(arm_inst) + sizeof(ssat_inst));
+ ssat_inst* const inst_cream = (ssat_inst*)inst_base->component;
+
+ inst_base->cond = BITS(inst, 28, 31);
+ inst_base->idx = index;
+ inst_base->br = NON_BRANCH;
+ inst_base->load_r15 = 0;
+
+ inst_cream->Rn = BITS(inst, 0, 3);
+ inst_cream->Rd = BITS(inst, 12, 15);
+ inst_cream->sat_imm = BITS(inst, 16, 19);
+
+ return inst_base;
+}
ARM_INST_PTR INTERPRETER_TRANSLATE(ssub8)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("SSUB8"); }
ARM_INST_PTR INTERPRETER_TRANSLATE(ssub16)(unsigned int inst, int index)
{
@@ -3165,7 +3180,10 @@ ARM_INST_PTR INTERPRETER_TRANSLATE(usat)(unsigned int inst, int index)
{
return INTERPRETER_TRANSLATE(ssat)(inst, index);
}
-ARM_INST_PTR INTERPRETER_TRANSLATE(usat16)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("USAT16"); }
+ARM_INST_PTR INTERPRETER_TRANSLATE(usat16)(unsigned int inst, int index)
+{
+ return INTERPRETER_TRANSLATE(ssat16)(inst, index);
+}
ARM_INST_PTR INTERPRETER_TRANSLATE(usub16)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("USUB16"); }
ARM_INST_PTR INTERPRETER_TRANSLATE(usub8)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("USUB8"); }
ARM_INST_PTR INTERPRETER_TRANSLATE(usubaddx)(unsigned int inst, int index) { UNIMPLEMENTED_INSTRUCTION("USUBADDX"); }
@@ -5583,6 +5601,26 @@ unsigned InterpreterMainLoop(ARMul_State* state) {
}
SSAT16_INST:
+ {
+ if (inst_base->cond == 0xE || CondPassed(cpu, inst_base->cond)) {
+ ssat_inst* const inst_cream = (ssat_inst*)inst_base->component;
+ const u8 saturate_to = inst_cream->sat_imm;
+
+ bool sat1 = false;
+ bool sat2 = false;
+
+ RD = (ARMul_SignedSatQ((s16)RN, saturate_to, &sat1) & 0xFFFF) |
+ ARMul_SignedSatQ((s32)RN >> 16, saturate_to, &sat2) << 16;
+
+ if (sat1 || sat2)
+ cpu->Cpsr |= (1 << 27);
+ }
+
+ cpu->Reg[15] += GET_INST_SIZE(cpu);
+ INC_PC(sizeof(ssat_inst));
+ FETCH_INST;
+ GOTO_NEXT_INST;
+ }
SSUB8_INST:
STC_INST:
{
@@ -6363,6 +6401,27 @@ unsigned InterpreterMainLoop(ARMul_State* state) {
}
USAT16_INST:
+ {
+ if (inst_base->cond == 0xE || CondPassed(cpu, inst_base->cond)) {
+ ssat_inst* const inst_cream = (ssat_inst*)inst_base->component;
+ const u8 saturate_to = inst_cream->sat_imm;
+
+ bool sat1 = false;
+ bool sat2 = false;
+
+ RD = (ARMul_UnsignedSatQ((s16)RN, saturate_to, &sat1) & 0xFFFF) |
+ ARMul_UnsignedSatQ((s32)RN >> 16, saturate_to, &sat2) << 16;
+
+ if (sat1 || sat2)
+ cpu->Cpsr |= (1 << 27);
+ }
+
+ cpu->Reg[15] += GET_INST_SIZE(cpu);
+ INC_PC(sizeof(ssat_inst));
+ FETCH_INST;
+ GOTO_NEXT_INST;
+ }
+
USUB16_INST:
USUB8_INST:
USUBADDX_INST:
diff --git a/src/core/arm/skyeye_common/vfp/vfp.cpp b/src/core/arm/skyeye_common/vfp/vfp.cpp
index 5c036caeb..10d640f37 100644
--- a/src/core/arm/skyeye_common/vfp/vfp.cpp
+++ b/src/core/arm/skyeye_common/vfp/vfp.cpp
@@ -141,7 +141,7 @@ unsigned VFPMRRC(ARMul_State* state, unsigned type, u32 instr, u32* value1, u32*
{
if (CoProc == 10 && (OPC_1 & 0xD) == 1)
{
- VFP_DEBUG_UNIMPLEMENTED(VMOVBRRSS);
+ VMOVBRRSS(state, BIT(20), Rt, Rt2, BIT(5)<<4|CRm, value1, value2);
return ARMul_DONE;
}
@@ -175,7 +175,7 @@ unsigned VFPMCRR(ARMul_State* state, unsigned type, u32 instr, u32 value1, u32 v
{
if (CoProc == 10 && (OPC_1 & 0xD) == 1)
{
- VFP_DEBUG_UNIMPLEMENTED(VMOVBRRSS);
+ VMOVBRRSS(state, BIT(20), Rt, Rt2, BIT(5)<<4|CRm, &value1, &value2);
return ARMul_DONE;
}
@@ -504,6 +504,22 @@ void VMOVBRRD(ARMul_State* state, ARMword to_arm, ARMword t, ARMword t2, ARMword
state->ExtReg[n*2] = *value1;
}
}
+void VMOVBRRSS(ARMul_State* state, ARMword to_arm, ARMword t, ARMword t2, ARMword n, ARMword* value1, ARMword* value2)
+{
+ DBG("VMOV(BRRSS) :\n");
+ if (to_arm)
+ {
+ DBG("\tr[%d-%d] <= s[%d-%d]=[%x-%x]\n", t2, t, n+1, n, state->ExtReg[n+1], state->ExtReg[n]);
+ *value1 = state->ExtReg[n+0];
+ *value2 = state->ExtReg[n+1];
+ }
+ else
+ {
+ DBG("\ts[%d-%d] <= r[%d-%d]=[%x-%x]\n", n+1, n, t2, t, *value2, *value1);
+ state->ExtReg[n+0] = *value1;
+ state->ExtReg[n+1] = *value2;
+ }
+}
/* ----------- MCR ------------ */
void VMSR(ARMul_State* state, ARMword reg, ARMword Rt)
diff --git a/src/core/arm/skyeye_common/vfp/vfp.h b/src/core/arm/skyeye_common/vfp/vfp.h
index f9e8d521d..539fb0131 100644
--- a/src/core/arm/skyeye_common/vfp/vfp.h
+++ b/src/core/arm/skyeye_common/vfp/vfp.h
@@ -97,6 +97,7 @@ u32 vfp_double_cpdo(ARMul_State* state, u32 inst, u32 fpscr);
void VMRS(ARMul_State * state, ARMword reg, ARMword Rt, ARMword *value);
void VMOVBRS(ARMul_State * state, ARMword to_arm, ARMword t, ARMword n, ARMword *value);
void VMOVBRRD(ARMul_State * state, ARMword to_arm, ARMword t, ARMword t2, ARMword n, ARMword *value1, ARMword *value2);
+void VMOVBRRSS(ARMul_State* state, ARMword to_arm, ARMword t, ARMword t2, ARMword n, ARMword* value1, ARMword* value2);
void VMOVI(ARMul_State * state, ARMword single, ARMword d, ARMword imm);
void VMOVR(ARMul_State * state, ARMword single, ARMword d, ARMword imm);
/* MCR */
diff --git a/src/core/arm/skyeye_common/vfp/vfpdouble.cpp b/src/core/arm/skyeye_common/vfp/vfpdouble.cpp
index 765c1f6bc..a9df490ba 100644
--- a/src/core/arm/skyeye_common/vfp/vfpdouble.cpp
+++ b/src/core/arm/skyeye_common/vfp/vfpdouble.cpp
@@ -1064,7 +1064,7 @@ vfp_double_multiply(struct vfp_double *vdd, struct vfp_double *vdn,
#define NEG_SUBTRACT (1 << 1)
static u32
-vfp_double_multiply_accumulate(ARMul_State* state, int dd, int dn, int dm, u32 fpscr, u32 negate, char *func)
+vfp_double_multiply_accumulate(ARMul_State* state, int dd, int dn, int dm, u32 fpscr, u32 negate, const char *func)
{
struct vfp_double vdd, vdp, vdn, vdm;
u32 exceptions;
diff --git a/src/core/arm/skyeye_common/vfp/vfpinstr.cpp b/src/core/arm/skyeye_common/vfp/vfpinstr.cpp
index 27dc8a008..cc70fc33c 100644
--- a/src/core/arm/skyeye_common/vfp/vfpinstr.cpp
+++ b/src/core/arm/skyeye_common/vfp/vfpinstr.cpp
@@ -2702,7 +2702,7 @@ ARM_INST_PTR INTERPRETER_TRANSLATE(vmovbrrss)(unsigned int inst, int index)
inst_cream->t = BITS(inst, 12, 15);
inst_cream->t2 = BITS(inst, 16, 19);
inst_cream->m = BITS(inst, 0, 3)<<1|BIT(inst, 5);
-
+
return inst_base;
}
#endif
@@ -2711,10 +2711,11 @@ VMOVBRRSS_INST:
{
if ((inst_base->cond == 0xe) || CondPassed(cpu, inst_base->cond)) {
CHECK_VFP_ENABLED;
-
- vmovbrrss_inst *inst_cream = (vmovbrrss_inst *)inst_base->component;
-
- VFP_DEBUG_UNIMPLEMENTED(VMOVBRRSS);
+
+ vmovbrrss_inst* const inst_cream = (vmovbrrss_inst*)inst_base->component;
+
+ VMOVBRRSS(cpu, inst_cream->to_arm, inst_cream->t, inst_cream->t2, inst_cream->m,
+ &cpu->Reg[inst_cream->t], &cpu->Reg[inst_cream->t2]);
}
cpu->Reg[15] += GET_INST_SIZE(cpu);
INC_PC(sizeof(vmovbrrss_inst));
@@ -2729,15 +2730,29 @@ DYNCOM_FILL_ACTION(vmovbrrss),
int DYNCOM_TAG(vmovbrrss)(cpu_t *cpu, addr_t pc, uint32_t instr, tag_t *tag, addr_t *new_pc, addr_t *next_pc)
{
int instr_size = INSTR_SIZE;
- DBG("\t\tin %s instruction is not implemented.\n", __FUNCTION__);
- arm_tag_trap(cpu, pc, instr, tag, new_pc, next_pc);
+
+ arm_tag_continue(cpu, pc, instr, tag, new_pc, next_pc);
+ if (instr >> 28 != 0xE)
+ *tag |= TAG_CONDITIONAL;
+
return instr_size;
}
#endif
#ifdef VFP_DYNCOM_TRANS
-int DYNCOM_TRANS(vmovbrrss)(cpu_t *cpu, uint32_t instr, BasicBlock *bb, addr_t pc){
- DBG("\t\tin %s instruction is not implemented.\n", __FUNCTION__);
- arch_arm_undef(cpu, bb, instr);
+int DYNCOM_TRANS(vmovbrrss)(cpu_t *cpu, uint32_t instr, BasicBlock *bb, addr_t pc)
+{
+ int to_arm = BIT(20) == 1;
+ int t = BITS(12, 15);
+ int t2 = BITS(16, 19);
+ int n = BIT(5)<<4 | BITS(0, 3);
+ if (to_arm) {
+ LET(t, IBITCAST32(FR32(n + 0)));
+ LET(t2, IBITCAST32(FR32(n + 1)));
+ }
+ else {
+ LETFPS(n + 0, FPBITCAST32(R(t)));
+ LETFPS(n + 1, FPBITCAST32(R(t2)));
+ }
return No_exp;
}
#endif
diff --git a/src/core/arm/skyeye_common/vfp/vfpsingle.cpp b/src/core/arm/skyeye_common/vfp/vfpsingle.cpp
index 6c33d8b78..08d0d719f 100644
--- a/src/core/arm/skyeye_common/vfp/vfpsingle.cpp
+++ b/src/core/arm/skyeye_common/vfp/vfpsingle.cpp
@@ -957,7 +957,7 @@ vfp_single_multiply(struct vfp_single *vsd, struct vfp_single *vsn, struct vfp_s
#define NEG_SUBTRACT (1 << 1)
static u32
-vfp_single_multiply_accumulate(ARMul_State* state, int sd, int sn, s32 m, u32 fpscr, u32 negate, char *func)
+vfp_single_multiply_accumulate(ARMul_State* state, int sd, int sn, s32 m, u32 fpscr, u32 negate, const char *func)
{
{
diff --git a/src/core/file_sys/archive_backend.h b/src/core/file_sys/archive_backend.h
index e153917ea..1612c35c2 100644
--- a/src/core/file_sys/archive_backend.h
+++ b/src/core/file_sys/archive_backend.h
@@ -46,6 +46,9 @@ public:
Path(const char* path) : type(Char), string(path) {
}
+ Path(std::vector<u8> binary_data) : type(Binary), binary(std::move(binary_data)) {
+ }
+
Path(LowPathType type, u32 size, u32 pointer) : type(type) {
switch (type) {
case Binary:
@@ -175,6 +178,20 @@ public:
}
/**
+ * Tries to open the archive of this type with the specified path
+ * @param path Path to the archive
+ * @return ResultCode of the operation
+ */
+ virtual ResultCode Open(const Path& path) = 0;
+
+ /**
+ * Deletes the archive contents and then re-creates the base folder
+ * @param path Path to the archive
+ * @return ResultCode of the operation, 0 on success
+ */
+ virtual ResultCode Format(const Path& path) const = 0;
+
+ /**
* Get a descriptive name for the archive (e.g. "RomFS", "SaveData", etc.)
*/
virtual std::string GetName() const = 0;
diff --git a/src/core/file_sys/archive_extsavedata.cpp b/src/core/file_sys/archive_extsavedata.cpp
new file mode 100644
index 000000000..4759ef3ae
--- /dev/null
+++ b/src/core/file_sys/archive_extsavedata.cpp
@@ -0,0 +1,59 @@
+// Copyright 2014 Citra Emulator Project
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#include <sys/stat.h>
+
+#include "common/common_types.h"
+#include "common/file_util.h"
+
+#include "core/file_sys/archive_extsavedata.h"
+#include "core/file_sys/disk_archive.h"
+#include "core/settings.h"
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+// FileSys namespace
+
+namespace FileSys {
+
+static std::string GetExtSaveDataPath(const std::string& mount_point, const Path& path) {
+ std::vector<u8> vec_data = path.AsBinary();
+ const u32* data = reinterpret_cast<const u32*>(vec_data.data());
+ u32 media_type = data[0];
+ u32 save_low = data[1];
+ u32 save_high = data[2];
+ return Common::StringFromFormat("%s%s/%08X/%08X/", mount_point.c_str(), media_type == 0 ? "nand" : "sdmc", save_high, save_low);
+}
+
+Archive_ExtSaveData::Archive_ExtSaveData(const std::string& mount_point)
+ : DiskArchive(mount_point), concrete_mount_point(mount_point) {
+ LOG_INFO(Service_FS, "Directory %s set as base for ExtSaveData.", this->mount_point.c_str());
+}
+
+bool Archive_ExtSaveData::Initialize() {
+ if (!FileUtil::CreateFullPath(mount_point)) {
+ LOG_ERROR(Service_FS, "Unable to create ExtSaveData base path.");
+ return false;
+ }
+
+ return true;
+}
+
+ResultCode Archive_ExtSaveData::Open(const Path& path) {
+ std::string fullpath = GetExtSaveDataPath(mount_point, path);
+ if (!FileUtil::Exists(fullpath)) {
+ // TODO(Subv): Check error code, this one is probably wrong
+ return ResultCode(ErrorDescription::FS_NotFormatted, ErrorModule::FS,
+ ErrorSummary::InvalidState, ErrorLevel::Status);
+ }
+ concrete_mount_point = fullpath;
+ return RESULT_SUCCESS;
+}
+
+ResultCode Archive_ExtSaveData::Format(const Path& path) const {
+ std::string fullpath = GetExtSaveDataPath(mount_point, path);
+ FileUtil::CreateFullPath(fullpath);
+ return RESULT_SUCCESS;
+}
+
+} // namespace FileSys
diff --git a/src/core/file_sys/archive_extsavedata.h b/src/core/file_sys/archive_extsavedata.h
new file mode 100644
index 000000000..a3a144799
--- /dev/null
+++ b/src/core/file_sys/archive_extsavedata.h
@@ -0,0 +1,45 @@
+// Copyright 2014 Citra Emulator Project
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#pragma once
+
+#include "common/common_types.h"
+
+#include "core/file_sys/disk_archive.h"
+#include "core/loader/loader.h"
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+// FileSys namespace
+
+namespace FileSys {
+
+/// File system interface to the ExtSaveData archive
+class Archive_ExtSaveData final : public DiskArchive {
+public:
+ Archive_ExtSaveData(const std::string& mount_point);
+
+ /**
+ * Initialize the archive.
+ * @return true if it initialized successfully
+ */
+ bool Initialize();
+
+ ResultCode Open(const Path& path) override;
+ ResultCode Format(const Path& path) const override;
+ std::string GetName() const override { return "ExtSaveData"; }
+
+ const std::string& GetMountPoint() const override {
+ return concrete_mount_point;
+ }
+
+protected:
+ /**
+ * This holds the full directory path for this archive, it is only set after a successful call to Open,
+ * this is formed as <base extsavedatapath>/<type>/<high>/<low>.
+ * See GetExtSaveDataPath for the code that extracts this data from an archive path.
+ */
+ std::string concrete_mount_point;
+};
+
+} // namespace FileSys
diff --git a/src/core/file_sys/archive_romfs.cpp b/src/core/file_sys/archive_romfs.cpp
index fdaf73179..2fc3831b7 100644
--- a/src/core/file_sys/archive_romfs.cpp
+++ b/src/core/file_sys/archive_romfs.cpp
@@ -62,4 +62,9 @@ std::unique_ptr<DirectoryBackend> Archive_RomFS::OpenDirectory(const Path& path)
return Common::make_unique<Directory_RomFS>();
}
+ResultCode Archive_RomFS::Format(const Path& path) const {
+ LOG_WARNING(Service_FS, "Attempted to format ROMFS.");
+ return UnimplementedFunction(ErrorModule::FS);
+}
+
} // namespace FileSys
diff --git a/src/core/file_sys/archive_romfs.h b/src/core/file_sys/archive_romfs.h
index 5e918f92d..d4b1eb7f2 100644
--- a/src/core/file_sys/archive_romfs.h
+++ b/src/core/file_sys/archive_romfs.h
@@ -83,6 +83,12 @@ public:
*/
std::unique_ptr<DirectoryBackend> OpenDirectory(const Path& path) const override;
+ ResultCode Open(const Path& path) override {
+ return RESULT_SUCCESS;
+ }
+
+ ResultCode Format(const Path& path) const override;
+
private:
friend class File_RomFS;
diff --git a/src/core/file_sys/archive_savedata.cpp b/src/core/file_sys/archive_savedata.cpp
index 97853567c..280d4ff5d 100644
--- a/src/core/file_sys/archive_savedata.cpp
+++ b/src/core/file_sys/archive_savedata.cpp
@@ -16,18 +16,29 @@
namespace FileSys {
-Archive_SaveData::Archive_SaveData(const std::string& mount_point, u64 program_id)
- : DiskArchive(mount_point + Common::StringFromFormat("%016X", program_id) + DIR_SEP) {
+Archive_SaveData::Archive_SaveData(const std::string& mount_point)
+ : DiskArchive(mount_point) {
LOG_INFO(Service_FS, "Directory %s set as SaveData.", this->mount_point.c_str());
}
-bool Archive_SaveData::Initialize() {
- if (!FileUtil::CreateFullPath(mount_point)) {
- LOG_ERROR(Service_FS, "Unable to create SaveData path.");
- return false;
+ResultCode Archive_SaveData::Open(const Path& path) {
+ if (concrete_mount_point.empty())
+ concrete_mount_point = Common::StringFromFormat("%s%016X", mount_point.c_str(), Kernel::g_program_id) + DIR_SEP;
+ if (!FileUtil::Exists(concrete_mount_point)) {
+ // When a SaveData archive is created for the first time, it is not yet formatted
+ // and the save file/directory structure expected by the game has not yet been initialized.
+ // Returning the NotFormatted error code will signal the game to provision the SaveData archive
+ // with the files and folders that it expects.
+ return ResultCode(ErrorDescription::FS_NotFormatted, ErrorModule::FS,
+ ErrorSummary::InvalidState, ErrorLevel::Status);
}
+ return RESULT_SUCCESS;
+}
- return true;
+ResultCode Archive_SaveData::Format(const Path& path) const {
+ FileUtil::DeleteDirRecursively(concrete_mount_point);
+ FileUtil::CreateFullPath(concrete_mount_point);
+ return RESULT_SUCCESS;
}
} // namespace FileSys
diff --git a/src/core/file_sys/archive_savedata.h b/src/core/file_sys/archive_savedata.h
index 5b0ce29e6..07c7f7eff 100644
--- a/src/core/file_sys/archive_savedata.h
+++ b/src/core/file_sys/archive_savedata.h
@@ -17,15 +17,20 @@ namespace FileSys {
/// File system interface to the SaveData archive
class Archive_SaveData final : public DiskArchive {
public:
- Archive_SaveData(const std::string& mount_point, u64 program_id);
-
- /**
- * Initialize the archive.
- * @return true if it initialized successfully
- */
- bool Initialize();
+ Archive_SaveData(const std::string& mount_point);
std::string GetName() const override { return "SaveData"; }
+
+ ResultCode Open(const Path& path) override;
+
+ ResultCode Format(const Path& path) const override;
+
+ const std::string& GetMountPoint() const override {
+ return concrete_mount_point;
+ }
+
+protected:
+ std::string concrete_mount_point;
};
} // namespace FileSys
diff --git a/src/core/file_sys/disk_archive.h b/src/core/file_sys/disk_archive.h
index 018ebd2ed..f18d96f5a 100644
--- a/src/core/file_sys/disk_archive.h
+++ b/src/core/file_sys/disk_archive.h
@@ -25,6 +25,7 @@ public:
DiskArchive(const std::string& mount_point_) : mount_point(mount_point_) {}
virtual std::string GetName() const = 0;
+ virtual ResultCode Format(const Path& path) const { return RESULT_SUCCESS; }
std::unique_ptr<FileBackend> OpenFile(const Path& path, const Mode mode) const override;
bool DeleteFile(const Path& path) const override;
bool RenameFile(const Path& src_path, const Path& dest_path) const override;
@@ -34,11 +35,15 @@ public:
bool RenameDirectory(const Path& src_path, const Path& dest_path) const override;
std::unique_ptr<DirectoryBackend> OpenDirectory(const Path& path) const override;
+ virtual ResultCode Open(const Path& path) override {
+ return RESULT_SUCCESS;
+ }
+
/**
* Getter for the path used for this Archive
* @return Mount point of that passthrough archive
*/
- const std::string& GetMountPoint() const {
+ virtual const std::string& GetMountPoint() const {
return mount_point;
}
diff --git a/src/core/hle/service/apt_a.cpp b/src/core/hle/service/apt_a.cpp
index dcf5ec4fe..4b0f761d9 100644
--- a/src/core/hle/service/apt_a.cpp
+++ b/src/core/hle/service/apt_a.cpp
@@ -6,22 +6,31 @@
#include "core/hle/hle.h"
#include "core/hle/service/apt_a.h"
+namespace APT_U {
+ extern void Initialize(Service::Interface* self);
+ extern void GetLockHandle(Service::Interface* self);
+ extern void ReceiveParameter(Service::Interface* self);
+ extern void GlanceParameter(Service::Interface* self);
+}
+
////////////////////////////////////////////////////////////////////////////////////////////////////
// Namespace APT_A
namespace APT_A {
const Interface::FunctionInfo FunctionTable[] = {
- {0x00010040, nullptr, "GetLockHandle?"},
- {0x00020080, nullptr, "Initialize?"},
- {0x00030040, nullptr, "Enable?"},
- {0x00040040, nullptr, "Finalize?"},
- {0x00050040, nullptr, "GetAppletManInfo?"},
- {0x00060040, nullptr, "GetAppletInfo?"},
- {0x003B0040, nullptr, "CancelLibraryApplet?"},
- {0x00430040, nullptr, "NotifyToWait?"},
- {0x004B00C2, nullptr, "AppletUtility?"},
- {0x00550040, nullptr, "WriteInputToNsState?"},
+ {0x00010040, APT_U::GetLockHandle, "GetLockHandle?"},
+ {0x00020080, APT_U::Initialize, "Initialize?"},
+ {0x00030040, nullptr, "Enable?"},
+ {0x00040040, nullptr, "Finalize?"},
+ {0x00050040, nullptr, "GetAppletManInfo?"},
+ {0x00060040, nullptr, "GetAppletInfo?"},
+ {0x003B0040, nullptr, "CancelLibraryApplet?"},
+ {0x00430040, nullptr, "NotifyToWait?"},
+ {0x004B00C2, nullptr, "AppletUtility?"},
+ {0x00550040, nullptr, "WriteInputToNsState?"},
+ {0x000D0080, APT_U::ReceiveParameter, "ReceiveParameter" },
+ {0x000E0080, APT_U::GlanceParameter, "GlanceParameter" },
};
////////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/core/hle/service/fs/archive.cpp b/src/core/hle/service/fs/archive.cpp
index 487bf3aa7..f19ca3a9f 100644
--- a/src/core/hle/service/fs/archive.cpp
+++ b/src/core/hle/service/fs/archive.cpp
@@ -11,6 +11,7 @@
#include "common/math_util.h"
#include "core/file_sys/archive_savedata.h"
+#include "core/file_sys/archive_extsavedata.h"
#include "core/file_sys/archive_backend.h"
#include "core/file_sys/archive_sdmc.h"
#include "core/file_sys/directory_backend.h"
@@ -224,25 +225,20 @@ static Archive* GetArchive(ArchiveHandle handle) {
return (itr == handle_map.end()) ? nullptr : itr->second;
}
-ResultVal<ArchiveHandle> OpenArchive(ArchiveIdCode id_code) {
+ResultVal<ArchiveHandle> OpenArchive(ArchiveIdCode id_code, FileSys::Path& archive_path) {
LOG_TRACE(Service_FS, "Opening archive with id code 0x%08X", id_code);
auto itr = id_code_map.find(id_code);
if (itr == id_code_map.end()) {
- if (id_code == ArchiveIdCode::SaveData) {
- // When a SaveData archive is created for the first time, it is not yet formatted
- // and the save file/directory structure expected by the game has not yet been initialized.
- // Returning the NotFormatted error code will signal the game to provision the SaveData archive
- // with the files and folders that it expects.
- // The FormatSaveData service call will create the SaveData archive when it is called.
- return ResultCode(ErrorDescription::FS_NotFormatted, ErrorModule::FS,
- ErrorSummary::InvalidState, ErrorLevel::Status);
- }
// TODO: Verify error against hardware
return ResultCode(ErrorDescription::NotFound, ErrorModule::FS,
ErrorSummary::NotFound, ErrorLevel::Permanent);
}
+ ResultCode res = itr->second->backend->Open(archive_path);
+ if (!res.IsSuccess())
+ return res;
+
// This should never even happen in the first place with 64-bit handles,
while (handle_map.count(next_handle) != 0) {
++next_handle;
@@ -395,25 +391,14 @@ ResultVal<Handle> OpenDirectoryFromArchive(ArchiveHandle archive_handle, const F
}
ResultCode FormatSaveData() {
- // TODO(Subv): Actually wipe the savedata folder after creating or opening it
-
// Do not create the archive again if it already exists
- if (id_code_map.find(ArchiveIdCode::SaveData) != id_code_map.end())
- return UnimplementedFunction(ErrorModule::FS); // TODO(Subv): Find the correct error code
-
- // Create the SaveData archive
- std::string savedata_directory = FileUtil::GetUserPath(D_SAVEDATA_IDX);
- auto savedata_archive = Common::make_unique<FileSys::Archive_SaveData>(savedata_directory,
- Kernel::g_program_id);
-
- if (savedata_archive->Initialize()) {
- CreateArchive(std::move(savedata_archive), ArchiveIdCode::SaveData);
- return RESULT_SUCCESS;
- } else {
- LOG_ERROR(Service_FS, "Can't instantiate SaveData archive with path %s",
- savedata_archive->GetMountPoint().c_str());
- return UnimplementedFunction(ErrorModule::FS); // TODO(Subv): Find the proper error code
+ auto archive_itr = id_code_map.find(ArchiveIdCode::SaveData);
+ if (archive_itr == id_code_map.end()) {
+ return UnimplementedFunction(ErrorModule::FS); // TODO(Subv): Find the right error
}
+
+ // Use an empty path, we do not use it when formatting the savedata
+ return archive_itr->second->backend->Format(FileSys::Path());
}
/// Initialize archives
@@ -430,6 +415,26 @@ void ArchiveInit() {
CreateArchive(std::move(sdmc_archive), ArchiveIdCode::SDMC);
else
LOG_ERROR(Service_FS, "Can't instantiate SDMC archive with path %s", sdmc_directory.c_str());
+
+ // Create the SaveData archive
+ std::string savedata_directory = FileUtil::GetUserPath(D_SAVEDATA_IDX);
+ auto savedata_archive = Common::make_unique<FileSys::Archive_SaveData>(savedata_directory);
+ CreateArchive(std::move(savedata_archive), ArchiveIdCode::SaveData);
+
+ std::string extsavedata_directory = FileUtil::GetUserPath(D_EXTSAVEDATA);
+ auto extsavedata_archive = Common::make_unique<FileSys::Archive_ExtSaveData>(extsavedata_directory);
+ if (extsavedata_archive->Initialize())
+ CreateArchive(std::move(extsavedata_archive), ArchiveIdCode::ExtSaveData);
+ else
+ LOG_ERROR(Service_FS, "Can't instantiate ExtSaveData archive with path %s", extsavedata_directory.c_str());
+
+ std::string sharedextsavedata_directory = FileUtil::GetUserPath(D_EXTSAVEDATA);
+ auto sharedextsavedata_archive = Common::make_unique<FileSys::Archive_ExtSaveData>(sharedextsavedata_directory);
+ if (sharedextsavedata_archive->Initialize())
+ CreateArchive(std::move(sharedextsavedata_archive), ArchiveIdCode::SharedExtSaveData);
+ else
+ LOG_ERROR(Service_FS, "Can't instantiate SharedExtSaveData archive with path %s",
+ sharedextsavedata_directory.c_str());
}
/// Shutdown archives
diff --git a/src/core/hle/service/fs/archive.h b/src/core/hle/service/fs/archive.h
index b39bc41b6..c23b8cc46 100644
--- a/src/core/hle/service/fs/archive.h
+++ b/src/core/hle/service/fs/archive.h
@@ -29,9 +29,10 @@ typedef u64 ArchiveHandle;
/**
* Opens an archive
* @param id_code IdCode of the archive to open
+ * @param archive_path Path to the archive, used with Binary paths
* @return Handle to the opened archive
*/
-ResultVal<ArchiveHandle> OpenArchive(ArchiveIdCode id_code);
+ResultVal<ArchiveHandle> OpenArchive(ArchiveIdCode id_code, FileSys::Path& archive_path);
/**
* Closes an archive
diff --git a/src/core/hle/service/fs/fs_user.cpp b/src/core/hle/service/fs/fs_user.cpp
index b1a465274..7eb32146d 100644
--- a/src/core/hle/service/fs/fs_user.cpp
+++ b/src/core/hle/service/fs/fs_user.cpp
@@ -107,14 +107,7 @@ static void OpenFileDirectly(Service::Interface* self) {
LOG_DEBUG(Service_FS, "archive_path=%s file_path=%s, mode=%u attributes=%d",
archive_path.DebugStr().c_str(), file_path.DebugStr().c_str(), mode.hex, attributes);
- if (archive_path.GetType() != FileSys::Empty) {
- LOG_ERROR(Service_FS, "archive LowPath type other than empty is currently unsupported");
- cmd_buff[1] = UnimplementedFunction(ErrorModule::FS).raw;
- cmd_buff[3] = 0;
- return;
- }
-
- ResultVal<ArchiveHandle> archive_handle = OpenArchive(archive_id);
+ ResultVal<ArchiveHandle> archive_handle = OpenArchive(archive_id, archive_path);
if (archive_handle.Failed()) {
LOG_ERROR(Service_FS, "failed to get a handle for archive");
cmd_buff[1] = archive_handle.Code().raw;
@@ -376,13 +369,7 @@ static void OpenArchive(Service::Interface* self) {
LOG_DEBUG(Service_FS, "archive_path=%s", archive_path.DebugStr().c_str());
- if (archive_path.GetType() != FileSys::Empty) {
- LOG_ERROR(Service_FS, "archive LowPath type other than empty is currently unsupported");
- cmd_buff[1] = UnimplementedFunction(ErrorModule::FS).raw;
- return;
- }
-
- ResultVal<ArchiveHandle> handle = OpenArchive(archive_id);
+ ResultVal<ArchiveHandle> handle = OpenArchive(archive_id, archive_path);
cmd_buff[1] = handle.Code().raw;
if (handle.Succeeded()) {
cmd_buff[2] = *handle & 0xFFFFFFFF;
diff --git a/src/core/hle/service/ptm_u.cpp b/src/core/hle/service/ptm_u.cpp
index d1498f05c..9cc700c46 100644
--- a/src/core/hle/service/ptm_u.cpp
+++ b/src/core/hle/service/ptm_u.cpp
@@ -3,6 +3,8 @@
// Refer to the license.txt file included.
#include "common/log.h"
+#include "common/make_unique.h"
+#include "core/file_sys/archive_extsavedata.h"
#include "core/hle/hle.h"
#include "core/hle/service/ptm_u.h"
@@ -11,6 +13,24 @@
namespace PTM_U {
+/**
+ * Represents the gamecoin file structure in the SharedExtData archive
+ * More information in 3dbrew (http://www.3dbrew.org/wiki/Extdata#Shared_Extdata_0xf000000b_gamecoin.dat)
+ */
+struct GameCoin {
+ u32 magic; ///< Magic number: 0x4F00
+ u16 total_coins; ///< Total Play Coins
+ u16 total_coins_on_date; ///< Total Play Coins obtained on the date stored below.
+ u32 step_count; ///< Total step count at the time a new Play Coin was obtained.
+ u32 last_step_count; ///< Step count for the day the last Play Coin was obtained
+ u16 year;
+ u8 month;
+ u8 day;
+};
+static const GameCoin default_game_coin = { 0x4F00, 42, 0, 0, 0, 2014, 12, 29 };
+static std::unique_ptr<FileSys::Archive_ExtSaveData> ptm_shared_extsavedata;
+static const std::vector<u8> ptm_shared_extdata_id = {0, 0, 0, 0, 0x0B, 0, 0, 0xF0, 0, 0, 0, 0};
+
/// Charge levels used by PTM functions
enum class ChargeLevels : u32 {
CriticalBattery = 1,
@@ -120,6 +140,33 @@ const Interface::FunctionInfo FunctionTable[] = {
Interface::Interface() {
Register(FunctionTable, ARRAY_SIZE(FunctionTable));
+ // Create the SharedExtSaveData archive 0xF000000B and the gamecoin.dat file
+ // TODO(Subv): In the future we should use the FS service to query this archive
+ std::string extsavedata_directory = FileUtil::GetUserPath(D_EXTSAVEDATA);
+ ptm_shared_extsavedata = Common::make_unique<FileSys::Archive_ExtSaveData>(extsavedata_directory);
+ if (!ptm_shared_extsavedata->Initialize()) {
+ LOG_CRITICAL(Service_PTM, "Could not initialize ExtSaveData archive for the PTM:U service");
+ return;
+ }
+ FileSys::Path archive_path(ptm_shared_extdata_id);
+ ResultCode result = ptm_shared_extsavedata->Open(archive_path);
+ // If the archive didn't exist, create the files inside
+ if (result.description == ErrorDescription::FS_NotFormatted) {
+ // Format the archive to clear the directories
+ ptm_shared_extsavedata->Format(archive_path);
+ // Open it again to get a valid archive now that the folder exists
+ ptm_shared_extsavedata->Open(archive_path);
+ FileSys::Path gamecoin_path("gamecoin.dat");
+ FileSys::Mode open_mode = {};
+ open_mode.write_flag = 1;
+ open_mode.create_flag = 1;
+ // Open the file and write the default gamecoin information
+ auto gamecoin = ptm_shared_extsavedata->OpenFile(gamecoin_path, open_mode);
+ if (gamecoin != nullptr) {
+ gamecoin->Write(0, sizeof(GameCoin), 1, reinterpret_cast<const u8*>(&default_game_coin));
+ gamecoin->Close();
+ }
+ }
}
} // namespace
diff --git a/src/core/mem_map.cpp b/src/core/mem_map.cpp
index eea6c5bf1..a14e8303e 100644
--- a/src/core/mem_map.cpp
+++ b/src/core/mem_map.cpp
@@ -21,6 +21,7 @@ u8* g_heap = nullptr; ///< Application heap (main memory)
u8* g_heap_linear = nullptr; ///< Linear heap
u8* g_vram = nullptr; ///< Video memory (VRAM) pointer
u8* g_shared_mem = nullptr; ///< Shared memory
+u8* g_dsp_mem = nullptr; ///< DSP memory
u8* g_kernel_mem; ///< Kernel memory
static u8* physical_bootrom = nullptr; ///< Bootrom physical memory
@@ -32,6 +33,7 @@ static u8* physical_fcram = nullptr; ///< Main physical memory (FCRAM)
static u8* physical_heap_gsp = nullptr; ///< GSP heap physical memory
static u8* physical_vram = nullptr; ///< Video physical memory (VRAM)
static u8* physical_shared_mem = nullptr; ///< Physical shared memory
+static u8* physical_dsp_mem = nullptr; ///< Physical DSP memory
static u8* physical_kernel_mem; ///< Kernel memory
// We don't declare the IO region in here since its handled by other means.
@@ -41,6 +43,7 @@ static MemoryView g_views[] = {
{&g_heap, &physical_fcram, HEAP_VADDR, HEAP_SIZE, MV_IS_PRIMARY_RAM},
{&g_shared_mem, &physical_shared_mem, SHARED_MEMORY_VADDR, SHARED_MEMORY_SIZE, 0},
{&g_system_mem, &physical_system_mem, SYSTEM_MEMORY_VADDR, SYSTEM_MEMORY_SIZE, 0},
+ {&g_dsp_mem, &physical_dsp_mem, DSP_MEMORY_VADDR, DSP_MEMORY_SIZE, 0},
{&g_kernel_mem, &physical_kernel_mem, KERNEL_MEMORY_VADDR, KERNEL_MEMORY_SIZE, 0},
{&g_heap_linear, &physical_heap_gsp, HEAP_LINEAR_VADDR, HEAP_LINEAR_SIZE, 0},
};
diff --git a/src/core/mem_map.h b/src/core/mem_map.h
index a2ef9d3af..fad40ae0c 100644
--- a/src/core/mem_map.h
+++ b/src/core/mem_map.h
@@ -134,6 +134,7 @@ extern u8* g_heap; ///< Application heap (main memory)
extern u8* g_vram; ///< Video memory (VRAM)
extern u8* g_shared_mem; ///< Shared memory
extern u8* g_kernel_mem; ///< Kernel memory
+extern u8* g_dsp_mem; ///< DSP memory
extern u8* g_system_mem; ///< System memory
extern u8* g_exefs_code; ///< ExeFS:/.code is loaded here
diff --git a/src/core/mem_map_funcs.cpp b/src/core/mem_map_funcs.cpp
index fdf382ed6..97ef1c5a3 100644
--- a/src/core/mem_map_funcs.cpp
+++ b/src/core/mem_map_funcs.cpp
@@ -82,6 +82,10 @@ inline void Read(T &var, const VAddr vaddr) {
} else if ((vaddr >= CONFIG_MEMORY_VADDR) && (vaddr < CONFIG_MEMORY_VADDR_END)) {
ConfigMem::Read<T>(var, vaddr);
+ // DSP memory
+ } else if ((vaddr >= DSP_MEMORY_VADDR) && (vaddr < DSP_MEMORY_VADDR_END)) {
+ var = *((const T*)&g_dsp_mem[vaddr - DSP_MEMORY_VADDR]);
+
// VRAM
} else if ((vaddr >= VRAM_VADDR) && (vaddr < VRAM_VADDR_END)) {
var = *((const T*)&g_vram[vaddr - VRAM_VADDR]);
@@ -122,8 +126,10 @@ inline void Write(const VAddr vaddr, const T data) {
} else if ((vaddr >= VRAM_VADDR) && (vaddr < VRAM_VADDR_END)) {
*(T*)&g_vram[vaddr - VRAM_VADDR] = data;
- //} else if ((vaddr & 0xFFF00000) == 0x1FF00000) {
- // _assert_msg_(MEMMAP, false, "umimplemented write to DSP memory");
+ // DSP memory
+ } else if ((vaddr >= DSP_MEMORY_VADDR) && (vaddr < DSP_MEMORY_VADDR_END)) {
+ *(T*)&g_dsp_mem[vaddr - DSP_MEMORY_VADDR] = data;
+
//} else if ((vaddr & 0xFFFF0000) == 0x1FF80000) {
// _assert_msg_(MEMMAP, false, "umimplemented write to Configuration Memory");
//} else if ((vaddr & 0xFFFFF000) == 0x1FF81000) {