summaryrefslogtreecommitdiffstats
path: root/src/core/hle
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/hle')
-rw-r--r--src/core/hle/function_wrappers.h4
-rw-r--r--src/core/hle/service/apt/apt.cpp2
-rw-r--r--src/core/hle/service/ptm/ptm.cpp2
-rw-r--r--src/core/hle/service/soc_u.cpp71
-rw-r--r--src/core/hle/shared_page.cpp7
-rw-r--r--src/core/hle/shared_page.h10
-rw-r--r--src/core/hle/svc.cpp4
7 files changed, 54 insertions, 46 deletions
diff --git a/src/core/hle/function_wrappers.h b/src/core/hle/function_wrappers.h
index 7875971ce..f6eb900f0 100644
--- a/src/core/hle/function_wrappers.h
+++ b/src/core/hle/function_wrappers.h
@@ -256,9 +256,9 @@ void Wrap() {
func(((s64)PARAM(1) << 32) | PARAM(0));
}
-template <void func(const char*)>
+template <void func(const char*, int len)>
void Wrap() {
- func((char*)Memory::GetPointer(PARAM(0)));
+ func((char*)Memory::GetPointer(PARAM(0)), PARAM(1));
}
template <void func(u8)>
diff --git a/src/core/hle/service/apt/apt.cpp b/src/core/hle/service/apt/apt.cpp
index a8ddceb8c..366d1eacf 100644
--- a/src/core/hle/service/apt/apt.cpp
+++ b/src/core/hle/service/apt/apt.cpp
@@ -600,7 +600,7 @@ void Unwrap(Service::Interface* self) {
// Decrypts the ciphertext using AES-CCM
auto pdata = HW::AES::DecryptVerifyCCM(cipher, nonce, HW::AES::KeySlotID::APTWrap);
- IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
+ IPC::RequestBuilder rb = rp.MakeBuilder(1, 4);
if (!pdata.empty()) {
// Splits the plaintext and put the nonce in between
Memory::WriteBlock(output, pdata.data(), nonce_offset);
diff --git a/src/core/hle/service/ptm/ptm.cpp b/src/core/hle/service/ptm/ptm.cpp
index 8a343a613..e373ed47a 100644
--- a/src/core/hle/service/ptm/ptm.cpp
+++ b/src/core/hle/service/ptm/ptm.cpp
@@ -138,9 +138,9 @@ void Init() {
ASSERT_MSG(archive_result.Succeeded(), "Could not open the PTM SharedExtSaveData archive!");
FileSys::Path gamecoin_path("/gamecoin.dat");
+ Service::FS::CreateFileInArchive(*archive_result, gamecoin_path, sizeof(GameCoin));
FileSys::Mode open_mode = {};
open_mode.write_flag.Assign(1);
- open_mode.create_flag.Assign(1);
// Open the file and write the default gamecoin information
auto gamecoin_result =
Service::FS::OpenFileFromArchive(*archive_result, gamecoin_path, open_mode);
diff --git a/src/core/hle/service/soc_u.cpp b/src/core/hle/service/soc_u.cpp
index dcc5c3c90..530614e6f 100644
--- a/src/core/hle/service/soc_u.cpp
+++ b/src/core/hle/service/soc_u.cpp
@@ -362,18 +362,18 @@ static void Socket(Interface* self) {
return;
}
- u32 socket_handle = static_cast<u32>(::socket(domain, type, protocol));
+ u32 ret = static_cast<u32>(::socket(domain, type, protocol));
- if ((s32)socket_handle != SOCKET_ERROR_VALUE)
- open_sockets[socket_handle] = {socket_handle, true};
+ if ((s32)ret != SOCKET_ERROR_VALUE)
+ open_sockets[ret] = {ret, true};
int result = 0;
- if ((s32)socket_handle == SOCKET_ERROR_VALUE)
- result = TranslateError(GET_ERRNO);
+ if ((s32)ret == SOCKET_ERROR_VALUE)
+ ret = TranslateError(GET_ERRNO);
cmd_buffer[0] = IPC::MakeHeader(2, 2, 0);
cmd_buffer[1] = result;
- cmd_buffer[2] = socket_handle;
+ cmd_buffer[2] = ret;
}
static void Bind(Interface* self) {
@@ -393,15 +393,15 @@ static void Bind(Interface* self) {
sockaddr sock_addr = CTRSockAddr::ToPlatform(ctr_sock_addr);
- int res = ::bind(socket_handle, &sock_addr, std::max<u32>(sizeof(sock_addr), len));
+ int ret = ::bind(socket_handle, &sock_addr, std::max<u32>(sizeof(sock_addr), len));
int result = 0;
- if (res != 0)
- result = TranslateError(GET_ERRNO);
+ if (ret != 0)
+ ret = TranslateError(GET_ERRNO);
cmd_buffer[0] = IPC::MakeHeader(5, 2, 0);
cmd_buffer[1] = result;
- cmd_buffer[2] = res;
+ cmd_buffer[2] = ret;
}
static void Fcntl(Interface* self) {
@@ -426,8 +426,7 @@ static void Fcntl(Interface* self) {
#else
int ret = ::fcntl(socket_handle, F_GETFL, 0);
if (ret == SOCKET_ERROR_VALUE) {
- result = TranslateError(GET_ERRNO);
- posix_ret = -1;
+ posix_ret = TranslateError(GET_ERRNO);
return;
}
posix_ret = 0;
@@ -439,8 +438,7 @@ static void Fcntl(Interface* self) {
unsigned long tmp = (ctr_arg & 4 /* O_NONBLOCK */) ? 1 : 0;
int ret = ioctlsocket(socket_handle, FIONBIO, &tmp);
if (ret == SOCKET_ERROR_VALUE) {
- result = TranslateError(GET_ERRNO);
- posix_ret = -1;
+ posix_ret = TranslateError(GET_ERRNO);
return;
}
auto iter = open_sockets.find(socket_handle);
@@ -449,8 +447,7 @@ static void Fcntl(Interface* self) {
#else
int flags = ::fcntl(socket_handle, F_GETFL, 0);
if (flags == SOCKET_ERROR_VALUE) {
- result = TranslateError(GET_ERRNO);
- posix_ret = -1;
+ posix_ret = TranslateError(GET_ERRNO);
return;
}
@@ -460,15 +457,13 @@ static void Fcntl(Interface* self) {
int ret = ::fcntl(socket_handle, F_SETFL, flags);
if (ret == SOCKET_ERROR_VALUE) {
- result = TranslateError(GET_ERRNO);
- posix_ret = -1;
+ posix_ret = TranslateError(GET_ERRNO);
return;
}
#endif
} else {
LOG_ERROR(Service_SOC, "Unsupported command (%d) in fcntl call", ctr_cmd);
- result = TranslateError(EINVAL); // TODO: Find the correct error
- posix_ret = -1;
+ posix_ret = TranslateError(EINVAL); // TODO: Find the correct error
return;
}
}
@@ -481,7 +476,7 @@ static void Listen(Interface* self) {
int ret = ::listen(socket_handle, backlog);
int result = 0;
if (ret != 0)
- result = TranslateError(GET_ERRNO);
+ ret = TranslateError(GET_ERRNO);
cmd_buffer[0] = IPC::MakeHeader(3, 2, 0);
cmd_buffer[1] = result;
@@ -504,7 +499,7 @@ static void Accept(Interface* self) {
int result = 0;
if ((s32)ret == SOCKET_ERROR_VALUE) {
- result = TranslateError(GET_ERRNO);
+ ret = TranslateError(GET_ERRNO);
} else {
CTRSockAddr ctr_addr = CTRSockAddr::FromPlatform(addr);
Memory::WriteBlock(cmd_buffer[0x104 >> 2], &ctr_addr, sizeof(ctr_addr));
@@ -545,7 +540,7 @@ static void Close(Interface* self) {
int result = 0;
if (ret != 0)
- result = TranslateError(GET_ERRNO);
+ ret = TranslateError(GET_ERRNO);
cmd_buffer[2] = ret;
cmd_buffer[1] = result;
@@ -589,7 +584,7 @@ static void SendTo(Interface* self) {
int result = 0;
if (ret == SOCKET_ERROR_VALUE)
- result = TranslateError(GET_ERRNO);
+ ret = TranslateError(GET_ERRNO);
cmd_buffer[2] = ret;
cmd_buffer[1] = result;
@@ -638,7 +633,7 @@ static void RecvFrom(Interface* self) {
int result = 0;
int total_received = ret;
if (ret == SOCKET_ERROR_VALUE) {
- result = TranslateError(GET_ERRNO);
+ ret = TranslateError(GET_ERRNO);
total_received = 0;
} else {
// Write only the data we received to avoid overwriting parts of the buffer with zeros
@@ -673,7 +668,7 @@ static void Poll(Interface* self) {
std::vector<pollfd> platform_pollfd(nfds);
std::transform(ctr_fds.begin(), ctr_fds.end(), platform_pollfd.begin(), CTRPollFD::ToPlatform);
- const int ret = ::poll(platform_pollfd.data(), nfds, timeout);
+ int ret = ::poll(platform_pollfd.data(), nfds, timeout);
// Now update the output pollfd structure
std::transform(platform_pollfd.begin(), platform_pollfd.end(), ctr_fds.begin(),
@@ -683,7 +678,7 @@ static void Poll(Interface* self) {
int result = 0;
if (ret == SOCKET_ERROR_VALUE)
- result = TranslateError(GET_ERRNO);
+ ret = TranslateError(GET_ERRNO);
cmd_buffer[1] = result;
cmd_buffer[2] = ret;
@@ -710,7 +705,7 @@ static void GetSockName(Interface* self) {
int result = 0;
if (ret != 0)
- result = TranslateError(GET_ERRNO);
+ ret = TranslateError(GET_ERRNO);
cmd_buffer[2] = ret;
cmd_buffer[1] = result;
@@ -724,7 +719,7 @@ static void Shutdown(Interface* self) {
int ret = ::shutdown(socket_handle, how);
int result = 0;
if (ret != 0)
- result = TranslateError(GET_ERRNO);
+ ret = TranslateError(GET_ERRNO);
cmd_buffer[2] = ret;
cmd_buffer[1] = result;
}
@@ -750,7 +745,7 @@ static void GetPeerName(Interface* self) {
int result = 0;
if (ret != 0)
- result = TranslateError(GET_ERRNO);
+ ret = TranslateError(GET_ERRNO);
cmd_buffer[2] = ret;
cmd_buffer[1] = result;
@@ -777,7 +772,7 @@ static void Connect(Interface* self) {
int ret = ::connect(socket_handle, &input_addr, sizeof(input_addr));
int result = 0;
if (ret != 0)
- result = TranslateError(GET_ERRNO);
+ ret = TranslateError(GET_ERRNO);
cmd_buffer[0] = IPC::MakeHeader(6, 2, 0);
cmd_buffer[1] = result;
@@ -815,7 +810,7 @@ static void GetSockOpt(Interface* self) {
int optname = TranslateSockOpt(cmd_buffer[3]);
socklen_t optlen = (socklen_t)cmd_buffer[4];
- int ret = -1;
+ int ret = 0;
int err = 0;
if (optname < 0) {
@@ -830,9 +825,8 @@ static void GetSockOpt(Interface* self) {
// >> 2 = convert to u32 offset instead of byte offset (cmd_buffer = u32*)
char* optval = reinterpret_cast<char*>(Memory::GetPointer(cmd_buffer[0x104 >> 2]));
- ret = ::getsockopt(socket_handle, level, optname, optval, &optlen);
- err = 0;
- if (ret == SOCKET_ERROR_VALUE) {
+ err = ::getsockopt(socket_handle, level, optname, optval, &optlen);
+ if (err == SOCKET_ERROR_VALUE) {
err = TranslateError(GET_ERRNO);
}
}
@@ -849,7 +843,7 @@ static void SetSockOpt(Interface* self) {
u32 level = cmd_buffer[2];
int optname = TranslateSockOpt(cmd_buffer[3]);
- int ret = -1;
+ int ret = 0;
int err = 0;
if (optname < 0) {
@@ -862,9 +856,8 @@ static void SetSockOpt(Interface* self) {
socklen_t optlen = static_cast<socklen_t>(cmd_buffer[4]);
const char* optval = reinterpret_cast<const char*>(Memory::GetPointer(cmd_buffer[8]));
- ret = static_cast<u32>(::setsockopt(socket_handle, level, optname, optval, optlen));
- err = 0;
- if (ret == SOCKET_ERROR_VALUE) {
+ err = static_cast<u32>(::setsockopt(socket_handle, level, optname, optval, optlen));
+ if (err == SOCKET_ERROR_VALUE) {
err = TranslateError(GET_ERRNO);
}
}
diff --git a/src/core/hle/shared_page.cpp b/src/core/hle/shared_page.cpp
index d0d92487d..5978ccdd4 100644
--- a/src/core/hle/shared_page.cpp
+++ b/src/core/hle/shared_page.cpp
@@ -6,6 +6,7 @@
#include <cstring>
#include <ctime>
#include "core/core_timing.h"
+#include "core/hle/service/ptm/ptm.h"
#include "core/hle/shared_page.h"
////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -73,6 +74,12 @@ void Init() {
// Some games wait until this value becomes 0x1, before asking running_hw
shared_page.unknown_value = 0x1;
+ // Set to a completely full battery
+ shared_page.battery_state.charge_level.Assign(
+ static_cast<u8>(Service::PTM::ChargeLevels::CompletelyFull));
+ shared_page.battery_state.is_adapter_connected.Assign(1);
+ shared_page.battery_state.is_charging.Assign(1);
+
update_time_event =
CoreTiming::RegisterEvent("SharedPage::UpdateTimeCallback", UpdateTimeCallback);
CoreTiming::ScheduleEvent(0, update_time_event);
diff --git a/src/core/hle/shared_page.h b/src/core/hle/shared_page.h
index 106e47efc..864695ae1 100644
--- a/src/core/hle/shared_page.h
+++ b/src/core/hle/shared_page.h
@@ -10,6 +10,7 @@
* write access, according to 3dbrew; this is not emulated)
*/
+#include "common/bit_field.h"
#include "common/common_funcs.h"
#include "common/common_types.h"
#include "common/swap.h"
@@ -29,6 +30,13 @@ struct DateTime {
};
static_assert(sizeof(DateTime) == 0x20, "Datetime size is wrong");
+union BatteryState {
+ u8 raw;
+ BitField<0, 1, u8> is_adapter_connected;
+ BitField<1, 1, u8> is_charging;
+ BitField<2, 3, u8> charge_level;
+};
+
struct SharedPageDef {
// Most of these names are taken from the 3dbrew page linked above.
u32_le date_time_counter; // 0
@@ -44,7 +52,7 @@ struct SharedPageDef {
INSERT_PADDING_BYTES(0x80 - 0x68); // 68
float_le sliderstate_3d; // 80
u8 ledstate_3d; // 84
- INSERT_PADDING_BYTES(1); // 85
+ BatteryState battery_state; // 85
u8 unknown_value; // 86
INSERT_PADDING_BYTES(0xA0 - 0x87); // 87
u64_le menu_title_id; // A0
diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp
index 4e0c3fb8b..2db823c61 100644
--- a/src/core/hle/svc.cpp
+++ b/src/core/hle/svc.cpp
@@ -467,8 +467,8 @@ static void Break(u8 break_reason) {
}
/// Used to output a message on a debug hardware unit - does nothing on a retail unit
-static void OutputDebugString(const char* string) {
- LOG_DEBUG(Debug_Emulated, "%s", string);
+static void OutputDebugString(const char* string, int len) {
+ LOG_DEBUG(Debug_Emulated, "%.*s", len, string);
}
/// Get resource limit