id
int64 0
755k
| file_name
stringlengths 3
109
| file_path
stringlengths 13
185
| content
stringlengths 31
9.38M
| size
int64 31
9.38M
| language
stringclasses 1
value | extension
stringclasses 11
values | total_lines
int64 1
340k
| avg_line_length
float64 2.18
149k
| max_line_length
int64 7
2.22M
| alphanum_fraction
float64 0
1
| repo_name
stringlengths 6
65
| repo_stars
int64 100
47.3k
| repo_forks
int64 0
12k
| repo_open_issues
int64 0
3.4k
| repo_license
stringclasses 9
values | repo_extraction_date
stringclasses 92
values | exact_duplicates_redpajama
bool 2
classes | near_duplicates_redpajama
bool 2
classes | exact_duplicates_githubcode
bool 2
classes | exact_duplicates_stackv2
bool 1
class | exact_duplicates_stackv1
bool 2
classes | near_duplicates_githubcode
bool 2
classes | near_duplicates_stackv1
bool 2
classes | near_duplicates_stackv2
bool 1
class |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
5,206
|
cellRec.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellRec.cpp
|
#include "stdafx.h"
#include "Emu/Cell/lv2/sys_memory.h"
#include "Emu/Cell/timers.hpp"
#include "Emu/Cell/PPUModule.h"
#include "Emu/IdManager.h"
#include "Emu/system_config.h"
#include "Emu/VFS.h"
#include "Emu/Audio/AudioBackend.h"
#include "cellRec.h"
#include "cellSysutil.h"
#include "util/media_utils.h"
#include "util/video_provider.h"
extern "C"
{
#include <libavutil/pixfmt.h>
}
LOG_CHANNEL(cellRec);
extern atomic_t<recording_mode> g_recording_mode;
template<>
void fmt_class_string<CellRecError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_REC_ERROR_OUT_OF_MEMORY);
STR_CASE(CELL_REC_ERROR_FATAL);
STR_CASE(CELL_REC_ERROR_INVALID_VALUE);
STR_CASE(CELL_REC_ERROR_FILE_OPEN);
STR_CASE(CELL_REC_ERROR_FILE_WRITE);
STR_CASE(CELL_REC_ERROR_INVALID_STATE);
STR_CASE(CELL_REC_ERROR_FILE_NO_DATA);
}
return unknown;
});
}
// Helper to distinguish video type
enum : s32
{
VIDEO_TYPE_MPEG4 = 0x0000,
VIDEO_TYPE_AVC_MP = 0x1000,
VIDEO_TYPE_AVC_BL = 0x2000,
VIDEO_TYPE_MJPEG = 0x3000,
VIDEO_TYPE_M4HD = 0x4000,
};
// Helper to distinguish video quality
enum : s32
{
VIDEO_QUALITY_0 = 0x000, // small
VIDEO_QUALITY_1 = 0x100, // middle
VIDEO_QUALITY_2 = 0x200, // large
VIDEO_QUALITY_3 = 0x300, // youtube
VIDEO_QUALITY_4 = 0x400,
VIDEO_QUALITY_5 = 0x500,
VIDEO_QUALITY_6 = 0x600, // HD720
VIDEO_QUALITY_7 = 0x700,
};
enum class rec_state : u32
{
closed = 0x2710,
stopped = 0x2711,
started = 0xBEEF, // I don't know the value of this
};
struct rec_param
{
s32 ppu_thread_priority = CELL_REC_PARAM_PPU_THREAD_PRIORITY_DEFAULT;
s32 spu_thread_priority = CELL_REC_PARAM_SPU_THREAD_PRIORITY_DEFAULT;
s32 capture_priority = CELL_REC_PARAM_CAPTURE_PRIORITY_HIGHEST;
s32 use_system_spu = CELL_REC_PARAM_USE_SYSTEM_SPU_DISABLE;
s32 fit_to_youtube = 0;
s32 xmb_bgm = CELL_REC_PARAM_XMB_BGM_DISABLE;
s32 mpeg4_fast_encode = CELL_REC_PARAM_MPEG4_FAST_ENCODE_DISABLE;
u32 ring_sec = 0;
s32 video_input = CELL_REC_PARAM_VIDEO_INPUT_DISABLE;
s32 audio_input = CELL_REC_PARAM_AUDIO_INPUT_DISABLE;
s32 audio_input_mix_vol = CELL_REC_PARAM_AUDIO_INPUT_MIX_VOL_MIN;
s32 reduce_memsize = CELL_REC_PARAM_REDUCE_MEMSIZE_DISABLE;
s32 show_xmb = 0;
std::string filename;
std::string metadata_filename;
CellRecSpursParam spurs_param{};
struct
{
std::string game_title;
std::string movie_title;
std::string description;
std::string userdata;
std::string to_string() const
{
return fmt::format("{ game_title='%s', movie_title='%s', description='%s', userdata='%s' }", game_title, movie_title, description, userdata);
}
} movie_metadata{};
struct
{
bool is_set = false;
u32 type = 0;
u64 start_time = 0;
u64 end_time = 0;
std::string title;
std::vector<std::string> tags;
std::string to_string() const
{
std::string scene_metadata_tags;
for (usz i = 0; i < tags.size(); i++)
{
if (i > 0) scene_metadata_tags += ", ";
fmt::append(scene_metadata_tags, "'%s'", tags[i]);
}
return fmt::format("{ is_set=%d, type=%d, start_time=%d, end_time=%d, title='%s', tags=[ %s ] }", is_set, type, start_time, end_time, title, scene_metadata_tags);
}
} scene_metadata{};
std::string to_string() const
{
std::string priority;
for (usz i = 0; i < 8; i++)
{
if (i > 0) priority += ", ";
fmt::append(priority, "%d", spurs_param.priority[i]);
}
return fmt::format("ppu_thread_priority=%d, spu_thread_priority=%d, capture_priority=%d, use_system_spu=%d, fit_to_youtube=%d, "
"xmb_bgm=%d, mpeg4_fast_encode=%d, ring_sec=%d, video_input=%d, audio_input=%d, audio_input_mix_vol=%d, reduce_memsize=%d, "
"show_xmb=%d, filename='%s', metadata_filename='%s', spurs_param={ pSpurs=*0x%x, spu_usage_rate=%d, priority=[ %s ], "
"movie_metadata=%s, scene_metadata=%s",
ppu_thread_priority, spu_thread_priority, capture_priority, use_system_spu, fit_to_youtube, xmb_bgm, mpeg4_fast_encode, ring_sec,
video_input, audio_input, audio_input_mix_vol, reduce_memsize, show_xmb, filename, metadata_filename, spurs_param.pSpurs, spurs_param.spu_usage_rate,
priority, movie_metadata.to_string(), scene_metadata.to_string());
}
bool use_external_audio() const
{
return audio_input != CELL_REC_PARAM_AUDIO_INPUT_DISABLE // != DISABLE means that cellRec will add samples on its own
&& audio_input_mix_vol > CELL_REC_PARAM_AUDIO_INPUT_MIX_VOL_MIN; // We need to mix cellRec audio with internal audio
}
bool use_internal_audio() const
{
return audio_input == CELL_REC_PARAM_AUDIO_INPUT_DISABLE // DISABLE means that cellRec won't add samples on its own
|| audio_input_mix_vol < CELL_REC_PARAM_AUDIO_INPUT_MIX_VOL_MAX; // We need to mix cellRec audio with internal audio
}
bool use_internal_video() const
{
return video_input == CELL_REC_PARAM_VIDEO_INPUT_DISABLE; // DISABLE means that cellRec won't add frames on its own
}
};
static constexpr u32 rec_framerate = 30; // Always 30 fps
static constexpr u32 rec_channels = 2; // Always 2 channels
class rec_video_sink final : public utils::video_sink
{
public:
rec_video_sink() : utils::video_sink()
{
m_framerate = rec_framerate;
}
void set_sample_rate(u32 sample_rate)
{
m_sample_rate = sample_rate;
}
void stop(bool flush = true) override
{
cellRec.notice("Stopping video sink. flush=%d", flush);
std::scoped_lock lock(m_video_mtx, m_audio_mtx);
m_flush = flush;
m_paused = false;
m_frames_to_encode.clear();
m_samples_to_encode.clear();
has_error = false;
}
void pause(bool flush = true) override
{
cellRec.notice("Pausing video sink. flush=%d", flush);
std::scoped_lock lock(m_video_mtx, m_audio_mtx);
m_flush = flush;
m_paused = true;
}
void resume() override
{
cellRec.notice("Resuming video sink");
std::scoped_lock lock(m_video_mtx, m_audio_mtx);
m_flush = false;
m_paused = false;
}
encoder_frame get_frame()
{
std::lock_guard lock_video(m_video_mtx);
if (!m_frames_to_encode.empty())
{
encoder_frame frame = std::move(m_frames_to_encode.front());
m_frames_to_encode.pop_front();
return frame;
}
return {};
}
encoder_sample get_sample()
{
std::lock_guard lock(m_audio_mtx);
if (!m_samples_to_encode.empty())
{
encoder_sample block = std::move(m_samples_to_encode.front());
m_samples_to_encode.pop_front();
return block;
}
return {};
}
};
struct rec_info
{
vm::ptr<CellRecCallback> cb{};
vm::ptr<void> cbUserData{};
atomic_t<rec_state> state = rec_state::closed;
rec_param param{};
// These buffers are used by the game to inject one frame into the recording.
// This apparently happens right before a frame is rendered to the screen.
// It is only possible to inject a frame if the game has the external input mode enabled.
vm::bptr<u8> video_input_buffer{}; // Used by the game to inject a frame right before it would render a frame to the screen.
vm::bptr<u8> audio_input_buffer{}; // Used by the game to inject audio: 2-channel interleaved (left-right) * 256 samples * sizeof(f32) at 48000 kHz
// Wrapper for our audio data
struct audio_block
{
// 2-channel interleaved (left-right), 256 samples, float
static constexpr usz block_size = rec_channels * CELL_REC_AUDIO_BLOCK_SAMPLES * sizeof(f32);
std::array<u8, block_size> block{};
s64 pts{};
};
std::vector<utils::video_sink::encoder_frame> video_ringbuffer;
std::vector<audio_block> audio_ringbuffer;
usz video_ring_pos = 0;
usz audio_ring_pos = 0;
usz video_ring_frame_count = 0;
usz audio_ring_block_count = 0;
usz next_video_ring_pos()
{
const usz pos = video_ring_pos;
video_ring_pos = (video_ring_pos + 1) % video_ringbuffer.size();
return pos;
}
usz next_audio_ring_pos()
{
const usz pos = audio_ring_pos;
audio_ring_pos = (audio_ring_pos + 1) % audio_ringbuffer.size();
return pos;
}
std::shared_ptr<rec_video_sink> sink;
std::shared_ptr<utils::video_encoder> encoder;
std::unique_ptr<named_thread<std::function<void()>>> video_provider_thread;
atomic_t<bool> paused = false;
// Video parameters
utils::video_encoder::frame_format output_format{};
utils::video_encoder::frame_format input_format{};
u32 video_bps = 512000;
s32 video_codec_id = 12; // AV_CODEC_ID_MPEG4
s32 max_b_frames = 2;
static constexpr u32 fps = rec_framerate; // Always 30 fps
// Audio parameters
u32 sample_rate = 48000;
u32 audio_bps = 64000;
s32 audio_codec_id = 86018; // AV_CODEC_ID_AAC
static constexpr u32 channels = rec_channels; // Always 2 channels
// Recording duration
atomic_t<u64> recording_time_start = 0;
atomic_t<u64> pause_time_start = 0;
atomic_t<u64> pause_time_total = 0;
atomic_t<u64> recording_time_total = 0;
shared_mutex mutex;
void set_video_params(s32 video_format);
void set_audio_params(s32 audio_format);
void start_video_provider();
void pause_video_provider();
void stop_video_provider(bool flush);
};
void rec_info::set_video_params(s32 video_format)
{
const s32 video_type = video_format & 0xf000;
const s32 video_quality = video_format & 0xf00;
switch (video_format)
{
case CELL_REC_PARAM_VIDEO_FMT_MPEG4_SMALL_512K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_MPEG4_MIDDLE_512K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_MPEG4_LARGE_512K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_AVC_MP_SMALL_512K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_AVC_MP_MIDDLE_512K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_AVC_BL_SMALL_512K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_AVC_BL_MIDDLE_512K_30FPS:
video_bps = 512000;
break;
case CELL_REC_PARAM_VIDEO_FMT_MPEG4_SMALL_768K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_MPEG4_MIDDLE_768K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_MPEG4_LARGE_768K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_AVC_MP_SMALL_768K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_AVC_MP_MIDDLE_768K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_AVC_BL_SMALL_768K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_AVC_BL_MIDDLE_768K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_M4HD_SMALL_768K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_M4HD_MIDDLE_768K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_YOUTUBE:
video_bps = 768000;
break;
case CELL_REC_PARAM_VIDEO_FMT_MPEG4_LARGE_1024K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_AVC_MP_MIDDLE_1024K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_AVC_BL_MIDDLE_1024K_30FPS:
video_bps = 1024000;
break;
case CELL_REC_PARAM_VIDEO_FMT_MPEG4_LARGE_1536K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_AVC_MP_MIDDLE_1536K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_AVC_BL_MIDDLE_1536K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_M4HD_LARGE_1536K_30FPS:
video_bps = 1536000;
break;
case CELL_REC_PARAM_VIDEO_FMT_MPEG4_LARGE_2048K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_M4HD_LARGE_2048K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_M4HD_HD720_2048K_30FPS:
video_bps = 2048000;
break;
case CELL_REC_PARAM_VIDEO_FMT_MJPEG_SMALL_5000K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_MJPEG_MIDDLE_5000K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_M4HD_HD720_5000K_30FPS:
video_bps = 5000000;
break;
case CELL_REC_PARAM_VIDEO_FMT_MJPEG_LARGE_11000K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_MJPEG_HD720_11000K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_M4HD_HD720_11000K_30FPS:
video_bps = 11000000;
break;
case CELL_REC_PARAM_VIDEO_FMT_MJPEG_HD720_20000K_30FPS:
video_bps = 20000000;
break;
case CELL_REC_PARAM_VIDEO_FMT_MJPEG_HD720_25000K_30FPS:
video_bps = 25000000;
break;
case 0x3791:
case 0x37a1:
case 0x3790:
case 0x37a0:
default:
// TODO: confirm bitrate
video_bps = 512000;
break;
}
max_b_frames = 2;
switch (video_type)
{
default:
case VIDEO_TYPE_MPEG4:
video_codec_id = 12; // AV_CODEC_ID_MPEG4
break;
case VIDEO_TYPE_AVC_MP:
video_codec_id = 27; // AV_CODEC_ID_H264
break;
case VIDEO_TYPE_AVC_BL:
video_codec_id = 27; // AV_CODEC_ID_H264
max_b_frames = 0; // Apparently baseline H264 does not support B-Frames
break;
case VIDEO_TYPE_MJPEG:
video_codec_id = 7; // AV_CODEC_ID_MJPEG
break;
case VIDEO_TYPE_M4HD:
// TODO: no idea if these are H264 or MPEG4
video_codec_id = 12; // AV_CODEC_ID_MPEG4
break;
}
const bool wide = g_cfg.video.aspect_ratio == video_aspect::_16_9;
bool hd = true;
switch(g_cfg.video.resolution)
{
case video_resolution::_1080p:
case video_resolution::_1080i:
case video_resolution::_720p:
case video_resolution::_1600x1080p:
case video_resolution::_1440x1080p:
case video_resolution::_1280x1080p:
case video_resolution::_960x1080p:
hd = true;
break;
case video_resolution::_480p:
case video_resolution::_480i:
case video_resolution::_576p:
case video_resolution::_576i:
hd = false;
break;
}
switch (video_quality)
{
case VIDEO_QUALITY_0: // small
input_format.width = wide ? 368 : 320;
input_format.height = wide ? 208 : 240;
break;
case VIDEO_QUALITY_1: // middle
input_format.width = wide ? 480 : 368;
input_format.height = 272;
break;
case VIDEO_QUALITY_2: // large
input_format.width = wide ? 640 : 480;
input_format.height = 368;
break;
case VIDEO_QUALITY_3: // youtube
input_format.width = 320;
input_format.height = 240;
break;
case VIDEO_QUALITY_4:
case VIDEO_QUALITY_5:
// TODO:
break;
case VIDEO_QUALITY_6: // HD720
input_format.width = hd ? 1280 : (wide ? 864 : 640);
input_format.height = hd ? 720 : 480;
break;
case VIDEO_QUALITY_7:
default:
// TODO:
input_format.width = 1280;
input_format.height = 720;
break;
}
output_format.av_pixel_format = AVPixelFormat::AV_PIX_FMT_YUV420P;
output_format.width = input_format.width;
output_format.height = input_format.height;
output_format.pitch = input_format.width * 4; // unused
switch (param.video_input)
{
case CELL_REC_PARAM_VIDEO_INPUT_ARGB_4_3:
case CELL_REC_PARAM_VIDEO_INPUT_ARGB_16_9:
input_format.av_pixel_format = AVPixelFormat::AV_PIX_FMT_ARGB;
input_format.pitch = input_format.width * 4;
break;
case CELL_REC_PARAM_VIDEO_INPUT_RGBA_4_3:
case CELL_REC_PARAM_VIDEO_INPUT_RGBA_16_9:
input_format.av_pixel_format = AVPixelFormat::AV_PIX_FMT_RGBA;
input_format.pitch = input_format.width * 4;
break;
case CELL_REC_PARAM_VIDEO_INPUT_YUV420PLANAR_16_9:
input_format.av_pixel_format = AVPixelFormat::AV_PIX_FMT_YUV420P;
input_format.pitch = input_format.width * 4; // TODO
break;
case CELL_REC_PARAM_VIDEO_INPUT_DISABLE:
default:
input_format.av_pixel_format = AVPixelFormat::AV_PIX_FMT_RGBA;
input_format.width = 1280;
input_format.height = 720;
input_format.pitch = input_format.width * 4; // unused
break;
}
cellRec.notice("set_video_params: video_format=0x%x, video_type=0x%x, video_quality=0x%x, video_bps=%d, video_codec_id=%d, wide=%d, hd=%d, input_format=%s, output_format=%s", video_format, video_type, video_quality, video_bps, video_codec_id, wide, hd, input_format.to_string(), output_format.to_string());
}
void rec_info::set_audio_params(s32 audio_format)
{
// Get the codec
switch (audio_format)
{
case CELL_REC_PARAM_AUDIO_FMT_AAC_96K:
case CELL_REC_PARAM_AUDIO_FMT_AAC_128K:
case CELL_REC_PARAM_AUDIO_FMT_AAC_64K:
audio_codec_id = 86018; // AV_CODEC_ID_AAC
break;
case CELL_REC_PARAM_AUDIO_FMT_ULAW_384K:
case CELL_REC_PARAM_AUDIO_FMT_ULAW_768K:
// TODO: no idea what this is
audio_codec_id = 65542; // AV_CODEC_ID_PCM_MULAW
break;
case CELL_REC_PARAM_AUDIO_FMT_PCM_384K:
case CELL_REC_PARAM_AUDIO_FMT_PCM_768K:
case CELL_REC_PARAM_AUDIO_FMT_PCM_1536K:
audio_codec_id = 65556; // AV_CODEC_ID_PCM_F32BE
//audio_codec_id = 65557; // AV_CODEC_ID_PCM_F32LE // TODO: maybe this one?
break;
default:
audio_codec_id = 86018; // AV_CODEC_ID_AAC
break;
}
// Get the sampling rate
switch (audio_format)
{
case CELL_REC_PARAM_AUDIO_FMT_AAC_96K:
case CELL_REC_PARAM_AUDIO_FMT_AAC_128K:
case CELL_REC_PARAM_AUDIO_FMT_AAC_64K:
case CELL_REC_PARAM_AUDIO_FMT_PCM_1536K:
sample_rate = 48000;
break;
case CELL_REC_PARAM_AUDIO_FMT_ULAW_384K:
case CELL_REC_PARAM_AUDIO_FMT_ULAW_768K:
// TODO: no idea what this is
sample_rate = 48000;
break;
case CELL_REC_PARAM_AUDIO_FMT_PCM_384K:
sample_rate = 12000;
break;
case CELL_REC_PARAM_AUDIO_FMT_PCM_768K:
sample_rate = 24000;
break;
default:
sample_rate = 48000;
break;
}
// Get the bitrate
switch (audio_format)
{
case CELL_REC_PARAM_AUDIO_FMT_AAC_64K:
audio_bps = 64000;
break;
case CELL_REC_PARAM_AUDIO_FMT_AAC_96K:
audio_bps = 96000;
break;
case CELL_REC_PARAM_AUDIO_FMT_AAC_128K:
audio_bps = 128000;
break;
case CELL_REC_PARAM_AUDIO_FMT_PCM_1536K:
audio_bps = 1536000;
break;
case CELL_REC_PARAM_AUDIO_FMT_ULAW_384K:
case CELL_REC_PARAM_AUDIO_FMT_PCM_384K:
audio_bps = 384000;
break;
case CELL_REC_PARAM_AUDIO_FMT_ULAW_768K:
case CELL_REC_PARAM_AUDIO_FMT_PCM_768K:
audio_bps = 768000;
break;
default:
audio_bps = 96000;
break;
}
cellRec.notice("set_audio_params: audio_format=0x%x, audio_codec_id=%d, sample_rate=%d, audio_bps=%d", audio_format, audio_codec_id, sample_rate, audio_bps);
}
void rec_info::start_video_provider()
{
const bool was_paused = paused.exchange(false);
if (video_provider_thread && was_paused)
{
// Resume
const u64 pause_time_end = get_system_time();
ensure(pause_time_end > pause_time_start);
pause_time_total += (pause_time_end - pause_time_start);
if (param.use_internal_video() || param.use_internal_audio())
{
utils::video_provider& video_provider = g_fxo->get<utils::video_provider>();
video_provider.set_pause_time_us(pause_time_total);
}
cellRec.notice("Resuming video provider.");
return;
}
cellRec.notice("Starting video provider.");
recording_time_start = get_system_time();
pause_time_start = 0;
pause_time_total = 0;
if (param.use_internal_video() || param.use_internal_audio())
{
utils::video_provider& video_provider = g_fxo->get<utils::video_provider>();
video_provider.set_pause_time_us(0);
}
video_provider_thread = std::make_unique<named_thread<std::function<void()>>>("cellRec video provider", [this]()
{
const bool use_internal_audio = param.use_internal_audio();
const bool use_external_audio = param.use_external_audio();
const bool use_external_video = !param.use_internal_video();
const bool use_ring_buffer = param.ring_sec > 0;
const usz frame_size = input_format.pitch * input_format.height;
audio_block buffer_external{}; // for cellRec input
audio_block buffer_internal{}; // for cellAudio input
s64 last_video_pts = -1;
s64 last_audio_pts = -1;
cellRec.notice("video_provider_thread: use_ring_buffer=%d, video_ringbuffer_size=%d, audio_ringbuffer_size=%d, ring_sec=%d, frame_size=%d, use_internal_video=%d, use_external_audio=%d, use_internal_audio=%d", use_ring_buffer, video_ringbuffer.size(), audio_ringbuffer.size(), param.ring_sec, frame_size, encoder->use_internal_video, use_external_audio, encoder->use_internal_audio);
while (thread_ctrl::state() != thread_state::aborting && encoder)
{
if (encoder->has_error)
{
cellRec.error("Encoder error. Sending error status.");
sysutil_register_cb([this](ppu_thread& ppu) -> s32
{
if (cb)
{
cb(ppu, CELL_REC_STATUS_ERR, CELL_REC_ERROR_FILE_WRITE, cbUserData);
}
return CELL_OK;
});
return;
}
if (paused)
{
thread_ctrl::wait_for(10000);
continue;
}
// We only care for new video frames or audio samples that can be properly encoded, so we check the timestamps and pts.
const usz timestamp_ms = (get_system_time() - recording_time_start - pause_time_total) / 1000;
/////////////////
// VIDEO //
/////////////////
// TODO: wait for flip before adding a frame
if (use_external_video)
{
// The video frames originate from cellRec instead of our render pipeline.
if (const s64 pts = encoder->get_pts(timestamp_ms); pts > last_video_pts)
{
if (video_input_buffer)
{
if (use_ring_buffer)
{
// The video frames originate from cellRec and are stored in a ringbuffer.
utils::video_sink::encoder_frame& frame_data = video_ringbuffer[next_video_ring_pos()];
frame_data.pts = pts;
frame_data.width = input_format.width;
frame_data.height = input_format.height;
frame_data.av_pixel_format = input_format.av_pixel_format;
frame_data.data.resize(frame_size);
std::memcpy(frame_data.data.data(), video_input_buffer.get_ptr(), frame_data.data.size());
video_ring_frame_count++;
}
else
{
// The video frames originate from cellRec and are pushed to the encoder immediately.
std::vector<u8> frame(frame_size);
std::memcpy(frame.data(), video_input_buffer.get_ptr(), frame.size());
encoder->add_frame(frame, input_format.pitch, input_format.width, input_format.height, input_format.av_pixel_format, timestamp_ms);
}
}
last_video_pts = pts;
}
}
else if (sink)
{
// The video frames originate from our render pipeline.
utils::video_sink::encoder_frame frame = sink->get_frame();
if (const s64 pts = encoder->get_pts(frame.timestamp_ms); pts > last_video_pts && !frame.data.empty())
{
if (use_ring_buffer)
{
// The video frames originate from our render pipeline and are stored in a ringbuffer.
frame.pts = pts;
video_ringbuffer[next_video_ring_pos()] = std::move(frame);
video_ring_frame_count++;
}
else
{
// The video frames originate from our render pipeline and are directly encoded by the encoder.
encoder->add_frame(frame.data, frame.pitch, frame.width, frame.height, frame.av_pixel_format, frame.timestamp_ms);
}
last_video_pts = pts;
}
}
/////////////////
// AUDIO //
/////////////////
const usz timestamp_us = get_system_time() - recording_time_start - pause_time_total;
bool got_new_samples = false;
if (use_external_audio)
{
if (const s64 pts = encoder->get_audio_pts(timestamp_us); pts > last_audio_pts)
{
if (audio_input_buffer)
{
// The audio samples originate from cellRec instead of our render pipeline.
// TODO: This needs to be synchronized with the game somehow if possible.
std::memcpy(buffer_external.block.data(), audio_input_buffer.get_ptr(), buffer_external.block.size());
buffer_external.pts = pts;
got_new_samples = true;
}
last_audio_pts = pts;
}
}
if (sink && use_internal_audio)
{
// The audio samples originate from cellAudio and are stored in a ringbuffer.
utils::video_sink::encoder_sample sample = sink->get_sample();
if (!sample.data.empty() && sample.channels >= channels && sample.sample_count >= CELL_REC_AUDIO_BLOCK_SAMPLES)
{
s64 pts = encoder->get_audio_pts(sample.timestamp_us);
// Each encoder_sample can have more than one block
for (u32 i = 0; i < sample.sample_count; i += CELL_REC_AUDIO_BLOCK_SAMPLES)
{
if (pts > last_audio_pts)
{
const f32* src = reinterpret_cast<const f32*>(&sample.data[i * sample.channels * sizeof(f32)]);
// Copy the new samples to the internal buffer if we need them for volume mixing below.
// Otherwise copy them directly to the external buffer which is used for output later.
audio_block& dst_buffer = got_new_samples ? buffer_internal : buffer_external;
if (sample.channels > channels)
{
// Downmix channels
AudioBackend::downmix(CELL_REC_AUDIO_BLOCK_SAMPLES * sample.channels, sample.channels, audio_channel_layout::stereo, src, reinterpret_cast<f32*>(dst_buffer.block.data()));
}
else
{
std::memcpy(dst_buffer.block.data(), src, audio_block::block_size);
}
// Mix external and internal audio with param.audio_input_mix_vol if we already got samples from cellRec.
if (got_new_samples)
{
const float volume = std::clamp(param.audio_input_mix_vol / 100.0f, 0.0f, 1.0f);
const f32* src = reinterpret_cast<const f32*>(buffer_internal.block.data());
f32* dst = reinterpret_cast<f32*>(buffer_external.block.data());
for (u32 sample = 0; sample < (CELL_REC_AUDIO_BLOCK_SAMPLES * channels); sample++)
{
*dst = std::clamp(*dst + (*src++ * volume), -1.0f, 1.0f);
++dst;
}
}
last_audio_pts = std::max(pts, last_audio_pts); // The cellAudio pts may be older than the pts from cellRec
buffer_external.pts = last_audio_pts;
got_new_samples = true;
}
// We only take the first sample for simplicity for now
break;
// Increase pts for each sample block
//pts++;
}
}
}
if (got_new_samples)
{
if (use_ring_buffer)
{
// Copy new sample to ringbuffer
audio_ringbuffer[next_audio_ring_pos()] = buffer_external;
audio_ring_block_count++;
}
else
{
// Push new sample to encoder
encoder->add_audio_samples(buffer_external.block.data(), CELL_REC_AUDIO_BLOCK_SAMPLES, channels, timestamp_us);
}
}
// Update recording time
recording_time_total = encoder->get_timestamp_ms(encoder->last_video_pts());
thread_ctrl::wait_for(1);
}
});
}
void rec_info::pause_video_provider()
{
cellRec.notice("Pausing video provider.");
if (video_provider_thread)
{
paused = true;
pause_time_start = get_system_time();
}
}
void rec_info::stop_video_provider(bool flush)
{
cellRec.notice("Stopping video provider.");
if (video_provider_thread)
{
auto& thread = *video_provider_thread;
thread = thread_state::aborting;
thread();
video_provider_thread.reset();
}
// Flush the ringbuffer if necessary.
// This should only happen if the video sink is not the encoder itself.
// In this case the encoder should have been idle until now.
if (flush && param.ring_sec > 0 && (!video_ringbuffer.empty() || !audio_ringbuffer.empty()))
{
cellRec.notice("Flushing video ringbuffer.");
// Fill encoder with data from ringbuffer
// TODO: ideally the encoder should do this on the fly and overwrite old frames in the file.
ensure(encoder);
encoder->encode();
const usz frame_count = std::min(video_ringbuffer.size(), video_ring_frame_count);
const usz video_start_offset = video_ring_frame_count < video_ringbuffer.size() ? 0 : video_ring_frame_count;
const s64 video_start_pts = video_ringbuffer.empty() ? 0 : video_ringbuffer[video_start_offset % video_ringbuffer.size()].pts;
const usz block_count = std::min(audio_ringbuffer.size(), audio_ring_block_count);
const usz audio_start_offset = audio_ring_block_count < audio_ringbuffer.size() ? 0 : audio_ring_block_count;
const s64 audio_start_pts = audio_ringbuffer.empty() ? 0 : audio_ringbuffer[audio_start_offset % audio_ringbuffer.size()].pts;
// Try to add the frames and samples in proper order
for (usz sync_timestamp_us = 0, frame = 0, block = 0; frame < frame_count || block < block_count; frame++)
{
// Add one frame
if (frame < frame_count)
{
const usz pos = (video_start_offset + frame) % video_ringbuffer.size();
utils::video_sink::encoder_frame& frame_data = video_ringbuffer[pos];
const usz timestamp_ms = encoder->get_timestamp_ms(frame_data.pts - video_start_pts);
encoder->add_frame(frame_data.data, frame_data.pitch, frame_data.width, frame_data.height, frame_data.av_pixel_format, timestamp_ms);
// Increase sync timestamp
sync_timestamp_us = timestamp_ms * 1000;
}
// Add all the samples that fit into the last frame
for (usz i = block; i < block_count; i++)
{
const usz pos = (audio_start_offset + i) % audio_ringbuffer.size();
const audio_block& sample_block = audio_ringbuffer[pos];
const usz timestamp_us = encoder->get_audio_timestamp_us(sample_block.pts - audio_start_pts);
// Stop adding new samples if the sync timestamp is exceeded, unless we already added all the frames.
if (timestamp_us > sync_timestamp_us && frame < frame_count)
{
break;
}
encoder->add_audio_samples(sample_block.block.data(), CELL_REC_AUDIO_BLOCK_SAMPLES, channels, timestamp_us);
block++;
}
}
video_ringbuffer.clear();
audio_ringbuffer.clear();
}
}
bool create_path(std::string& out, std::string dir_name, const std::string& file_name)
{
out.clear();
if (dir_name.size() + file_name.size() > CELL_REC_MAX_PATH_LEN)
{
return false;
}
out = std::move(dir_name);
if (!out.empty() && out.back() != '/')
{
out += '/';
}
out += file_name;
return true;
}
u32 cellRecQueryMemSize(vm::cptr<CellRecParam> pParam); // Forward declaration
error_code cellRecOpen(vm::cptr<char> pDirName, vm::cptr<char> pFileName, vm::cptr<CellRecParam> pParam, u32 container, vm::ptr<CellRecCallback> cb, vm::ptr<void> cbUserData)
{
cellRec.todo("cellRecOpen(pDirName=%s, pFileName=%s, pParam=*0x%x, container=0x%x, cb=*0x%x, cbUserData=*0x%x)", pDirName, pFileName, pParam, container, cb, cbUserData);
auto& rec = g_fxo->get<rec_info>();
if (rec.state != rec_state::closed)
{
return CELL_REC_ERROR_INVALID_STATE;
}
if (!pParam || !pDirName || !pFileName)
{
return CELL_REC_ERROR_INVALID_VALUE;
}
std::string options;
for (s32 i = 0; i < pParam->numOfOpt; i++)
{
if (i > 0) options += ", ";
fmt::append(options, "%d", pParam->pOpt[i].option);
}
cellRec.notice("cellRecOpen: pParam={ videoFmt=0x%x, audioFmt=0x%x, numOfOpt=0x%x, options=[ %s ] }", pParam->videoFmt, pParam->audioFmt, pParam->numOfOpt, options);
const u32 mem_size = cellRecQueryMemSize(pParam);
if (container == SYS_MEMORY_CONTAINER_ID_INVALID)
{
if (mem_size != 0)
{
return CELL_REC_ERROR_INVALID_VALUE;
}
}
else
{
// NOTE: Most likely tries to allocate a complete container. But we use g_fxo instead.
// TODO: how much data do we actually need ?
rec.video_input_buffer = vm::cast(vm::alloc(mem_size, vm::main));
rec.audio_input_buffer = vm::cast(vm::alloc(mem_size, vm::main));
if (!rec.video_input_buffer || !rec.audio_input_buffer)
{
return CELL_REC_ERROR_OUT_OF_MEMORY;
}
}
switch (pParam->videoFmt)
{
case CELL_REC_PARAM_VIDEO_FMT_MPEG4_SMALL_512K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_MPEG4_SMALL_768K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_MPEG4_MIDDLE_512K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_MPEG4_MIDDLE_768K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_MPEG4_LARGE_512K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_MPEG4_LARGE_768K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_MPEG4_LARGE_1024K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_MPEG4_LARGE_1536K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_MPEG4_LARGE_2048K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_AVC_MP_SMALL_512K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_AVC_MP_SMALL_768K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_AVC_MP_MIDDLE_512K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_AVC_MP_MIDDLE_768K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_AVC_MP_MIDDLE_1024K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_AVC_MP_MIDDLE_1536K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_AVC_BL_SMALL_512K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_AVC_BL_SMALL_768K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_AVC_BL_MIDDLE_512K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_AVC_BL_MIDDLE_768K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_AVC_BL_MIDDLE_1024K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_AVC_BL_MIDDLE_1536K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_MJPEG_SMALL_5000K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_MJPEG_MIDDLE_5000K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_MJPEG_LARGE_11000K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_MJPEG_HD720_11000K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_MJPEG_HD720_20000K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_MJPEG_HD720_25000K_30FPS:
case 0x3791:
case 0x37a1:
case 0x3790:
case 0x37a0:
case CELL_REC_PARAM_VIDEO_FMT_M4HD_SMALL_768K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_M4HD_MIDDLE_768K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_M4HD_LARGE_1536K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_M4HD_LARGE_2048K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_M4HD_HD720_2048K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_M4HD_HD720_5000K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_M4HD_HD720_11000K_30FPS:
case CELL_REC_PARAM_VIDEO_FMT_YOUTUBE:
break;
default:
return CELL_REC_ERROR_INVALID_VALUE;
}
const s32 video_type = pParam->videoFmt & 0xf000;
const s32 video_quality = pParam->videoFmt & 0xf00;
switch (pParam->audioFmt)
{
case CELL_REC_PARAM_AUDIO_FMT_AAC_96K:
case CELL_REC_PARAM_AUDIO_FMT_AAC_128K:
case CELL_REC_PARAM_AUDIO_FMT_AAC_64K:
{
// Do not allow MJPEG or AVC_MP video format
if (video_type == VIDEO_TYPE_AVC_MP || video_type == VIDEO_TYPE_MJPEG)
{
return CELL_REC_ERROR_INVALID_VALUE;
}
[[fallthrough]];
}
case CELL_REC_PARAM_AUDIO_FMT_ULAW_384K:
case CELL_REC_PARAM_AUDIO_FMT_ULAW_768K:
{
// Do not allow AVC_MP video format
if (video_type == VIDEO_TYPE_AVC_MP)
{
return CELL_REC_ERROR_INVALID_VALUE;
}
break;
}
case CELL_REC_PARAM_AUDIO_FMT_PCM_384K:
case CELL_REC_PARAM_AUDIO_FMT_PCM_768K:
case CELL_REC_PARAM_AUDIO_FMT_PCM_1536K:
{
// Only allow MJPEG video format
if (video_type != VIDEO_TYPE_MJPEG)
{
return CELL_REC_ERROR_INVALID_VALUE;
}
break;
}
default:
return CELL_REC_ERROR_INVALID_VALUE;
}
rec.param = {};
u32 spurs_param = 0;
bool abort_loop = false;
for (s32 i = 0; i < pParam->numOfOpt; i++)
{
const CellRecOption& opt = pParam->pOpt[i];
switch (opt.option)
{
case CELL_REC_OPTION_PPU_THREAD_PRIORITY:
{
if (opt.value.ppu_thread_priority > 0xbff)
{
return CELL_REC_ERROR_INVALID_VALUE;
}
rec.param.ppu_thread_priority = opt.value.ppu_thread_priority;
break;
}
case CELL_REC_OPTION_SPU_THREAD_PRIORITY:
{
if (opt.value.spu_thread_priority - 0x10U > 0xef)
{
return CELL_REC_ERROR_INVALID_VALUE;
}
rec.param.spu_thread_priority = opt.value.spu_thread_priority;
break;
}
case CELL_REC_OPTION_CAPTURE_PRIORITY:
{
rec.param.capture_priority = opt.value.capture_priority;
break;
}
case CELL_REC_OPTION_USE_SYSTEM_SPU:
{
if (video_quality == VIDEO_QUALITY_6 || video_quality == VIDEO_QUALITY_7)
{
// TODO: Seems differ if video_quality is VIDEO_QUALITY_6 or VIDEO_QUALITY_7
}
rec.param.use_system_spu = opt.value.use_system_spu;
break;
}
case CELL_REC_OPTION_FIT_TO_YOUTUBE:
{
rec.param.fit_to_youtube = opt.value.fit_to_youtube;
break;
}
case CELL_REC_OPTION_XMB_BGM:
{
rec.param.xmb_bgm = opt.value.xmb_bgm;
break;
}
case CELL_REC_OPTION_RING_SEC:
{
rec.param.ring_sec = opt.value.ring_sec;
break;
}
case CELL_REC_OPTION_MPEG4_FAST_ENCODE:
{
rec.param.mpeg4_fast_encode = opt.value.mpeg4_fast_encode;
break;
}
case CELL_REC_OPTION_VIDEO_INPUT:
{
const u32 v_input = (opt.value.video_input & 0xffU);
if (v_input > CELL_REC_PARAM_VIDEO_INPUT_YUV420PLANAR_16_9)
{
return CELL_REC_ERROR_INVALID_VALUE;
}
rec.param.video_input = v_input;
break;
}
case CELL_REC_OPTION_AUDIO_INPUT:
{
rec.param.audio_input = opt.value.audio_input;
if (opt.value.audio_input == CELL_REC_PARAM_AUDIO_INPUT_DISABLE)
{
rec.param.audio_input_mix_vol = CELL_REC_PARAM_AUDIO_INPUT_MIX_VOL_MIN;
}
else
{
rec.param.audio_input_mix_vol = CELL_REC_PARAM_AUDIO_INPUT_MIX_VOL_MAX;
}
break;
}
case CELL_REC_OPTION_AUDIO_INPUT_MIX_VOL:
{
rec.param.audio_input_mix_vol = opt.value.audio_input_mix_vol;
break;
}
case CELL_REC_OPTION_REDUCE_MEMSIZE:
{
rec.param.reduce_memsize = opt.value.reduce_memsize != CELL_REC_PARAM_REDUCE_MEMSIZE_DISABLE;
break;
}
case CELL_REC_OPTION_SHOW_XMB:
{
rec.param.show_xmb = (opt.value.show_xmb != 0);
break;
}
case CELL_REC_OPTION_METADATA_FILENAME:
{
if (opt.value.metadata_filename)
{
std::string path;
if (!create_path(path, pDirName.get_ptr(), opt.value.metadata_filename.get_ptr()))
{
return CELL_REC_ERROR_INVALID_VALUE;
}
rec.param.metadata_filename = path;
}
else
{
abort_loop = true; // TODO: Apparently this doesn't return an error but goes to the callback section instead...
}
break;
}
case CELL_REC_OPTION_SPURS:
{
spurs_param = opt.value.pSpursParam.addr();
if (!opt.value.pSpursParam || !opt.value.pSpursParam->pSpurs) // TODO: check both or only pSpursParam ?
{
return CELL_REC_ERROR_INVALID_VALUE;
}
if (opt.value.pSpursParam->spu_usage_rate < 1 || opt.value.pSpursParam->spu_usage_rate > 100)
{
return CELL_REC_ERROR_INVALID_VALUE;
}
rec.param.spurs_param.spu_usage_rate = opt.value.pSpursParam->spu_usage_rate;
[[fallthrough]];
}
case 100:
{
if (spurs_param)
{
// TODO:
}
break;
}
default:
{
cellRec.warning("cellRecOpen: unknown option %d", opt.option);
break;
}
}
if (abort_loop)
{
break;
}
}
// NOTE: The abort_loop variable I chose is actually a goto to the callback section at the end of the function.
if (!abort_loop)
{
if (rec.param.video_input != CELL_REC_PARAM_VIDEO_INPUT_DISABLE)
{
if (video_type == VIDEO_TYPE_MJPEG || video_type == VIDEO_TYPE_M4HD)
{
if (rec.param.video_input != CELL_REC_PARAM_VIDEO_INPUT_YUV420PLANAR_16_9)
{
return CELL_REC_ERROR_INVALID_VALUE;
}
}
else if (rec.param.video_input == CELL_REC_PARAM_VIDEO_INPUT_YUV420PLANAR_16_9)
{
return CELL_REC_ERROR_INVALID_VALUE;
}
}
if (!create_path(rec.param.filename, pDirName.get_ptr(), pFileName.get_ptr()))
{
return CELL_REC_ERROR_INVALID_VALUE;
}
if (!rec.param.filename.starts_with("/dev_hdd0") && !rec.param.filename.starts_with("/dev_hdd1"))
{
return CELL_REC_ERROR_INVALID_VALUE;
}
//if (spurs_param)
//{
// if (error_code error = cellSpurs_0xD9A9C592();
// {
// return error;
// }
//}
}
if (!cb)
{
return CELL_REC_ERROR_INVALID_VALUE;
}
cellRec.notice("cellRecOpen: Using parameters: %s", rec.param.to_string());
rec.cb = cb;
rec.cbUserData = cbUserData;
rec.video_ringbuffer.clear();
rec.audio_ringbuffer.clear();
rec.video_ring_pos = 0;
rec.audio_ring_pos = 0;
rec.video_ring_frame_count = 0;
rec.audio_ring_block_count = 0;
rec.recording_time_start = 0;
rec.recording_time_total = 0;
rec.pause_time_start = 0;
rec.pause_time_total = 0;
rec.paused = false;
rec.set_video_params(pParam->videoFmt);
rec.set_audio_params(pParam->audioFmt);
if (rec.param.ring_sec > 0)
{
const usz audio_ring_buffer_size = static_cast<usz>(std::ceil((rec.param.ring_sec * rec.sample_rate) / static_cast<f32>(CELL_REC_AUDIO_BLOCK_SAMPLES)));
const usz video_ring_buffer_size = rec.param.ring_sec * rec.fps;
cellRec.notice("Preparing ringbuffer for %d seconds. video_ring_buffer_size=%d, audio_ring_buffer_size=%d, pitch=%d, width=%d, height=%d", rec.param.ring_sec, video_ring_buffer_size, audio_ring_buffer_size, rec.input_format.pitch, rec.input_format.width, rec.input_format.height);
rec.audio_ringbuffer.resize(audio_ring_buffer_size);
rec.video_ringbuffer.resize(video_ring_buffer_size);
}
if (rec.param.use_internal_audio() || rec.param.use_internal_video())
{
rec.sink = std::make_shared<rec_video_sink>();
rec.sink->use_internal_audio = rec.param.use_internal_audio();
rec.sink->use_internal_video = rec.param.use_internal_video();
rec.sink->set_sample_rate(rec.sample_rate);
}
rec.encoder = std::make_shared<utils::video_encoder>();
rec.encoder->use_internal_audio = false; // We use the other sink
rec.encoder->use_internal_video = false; // We use the other sink
rec.encoder->set_path(vfs::get(rec.param.filename));
rec.encoder->set_framerate(rec.fps);
rec.encoder->set_video_bitrate(rec.video_bps);
rec.encoder->set_video_codec(rec.video_codec_id);
rec.encoder->set_sample_rate(rec.sample_rate);
rec.encoder->set_audio_channels(rec.channels);
rec.encoder->set_audio_bitrate(rec.audio_bps);
rec.encoder->set_audio_codec(rec.audio_codec_id);
rec.encoder->set_output_format(rec.output_format);
sysutil_register_cb([&rec](ppu_thread& ppu) -> s32
{
rec.state = rec_state::stopped;
rec.cb(ppu, CELL_REC_STATUS_OPEN, CELL_OK, rec.cbUserData);
return CELL_OK;
});
return CELL_OK;
}
error_code cellRecClose(s32 isDiscard)
{
cellRec.todo("cellRecClose(isDiscard=0x%x)", isDiscard);
auto& rec = g_fxo->get<rec_info>();
if (rec.state == rec_state::closed)
{
return CELL_REC_ERROR_INVALID_STATE;
}
sysutil_register_cb([=, &rec](ppu_thread& ppu) -> s32
{
bool is_valid_range = true;
if (isDiscard)
{
// No need to flush the encoder
rec.stop_video_provider(false);
rec.encoder->stop(false);
if (rec.sink)
{
rec.sink->stop(true);
}
if (fs::is_file(rec.param.filename))
{
cellRec.warning("cellRecClose: removing discarded recording '%s'", rec.param.filename);
if (!fs::remove_file(rec.param.filename))
{
cellRec.error("cellRecClose: failed to remove recording '%s'", rec.param.filename);
}
}
}
else
{
// Flush to make sure we encode all remaining frames
rec.stop_video_provider(true);
rec.encoder->stop(true);
rec.recording_time_total = rec.encoder->get_timestamp_ms(rec.encoder->last_video_pts());
if (rec.sink)
{
rec.sink->stop(true);
}
const s64 start_pts = rec.encoder->get_pts(rec.param.scene_metadata.start_time);
const s64 end_pts = rec.encoder->get_pts(rec.param.scene_metadata.end_time);
const s64 last_pts = rec.encoder->last_video_pts();
is_valid_range = start_pts >= 0 && end_pts <= last_pts;
}
vm::dealloc(rec.video_input_buffer.addr(), vm::main);
vm::dealloc(rec.audio_input_buffer.addr(), vm::main);
// Release the video sink if it was used
if (rec.param.use_internal_video() || rec.param.use_internal_audio())
{
const recording_mode old_mode = g_recording_mode.exchange(recording_mode::stopped);
if (old_mode == recording_mode::rpcs3)
{
cellRec.error("cellRecClose: Unexpected recording mode %s found while stopping video capture.", old_mode);
}
utils::video_provider& video_provider = g_fxo->get<utils::video_provider>();
if (!video_provider.set_video_sink(nullptr, recording_mode::cell))
{
cellRec.error("cellRecClose failed to release video sink");
}
}
rec.param = {};
rec.encoder.reset();
rec.sink.reset();
rec.audio_ringbuffer.clear();
rec.video_ringbuffer.clear();
rec.state = rec_state::closed;
if (is_valid_range)
{
rec.cb(ppu, CELL_REC_STATUS_CLOSE, CELL_OK, rec.cbUserData);
}
else
{
rec.cb(ppu, CELL_REC_STATUS_ERR, CELL_REC_ERROR_FILE_NO_DATA, rec.cbUserData);
}
return CELL_OK;
});
return CELL_OK;
}
error_code cellRecStop()
{
cellRec.todo("cellRecStop()");
auto& rec = g_fxo->get<rec_info>();
if (rec.state != rec_state::started)
{
return CELL_REC_ERROR_INVALID_STATE;
}
sysutil_register_cb([&rec](ppu_thread& ppu) -> s32
{
// cellRecStop actually just pauses the recording
rec.pause_video_provider();
if (rec.sink)
{
rec.sink->pause(true);
}
ensure(!!rec.encoder);
rec.encoder->pause(true);
rec.recording_time_total = rec.encoder->get_timestamp_ms(rec.encoder->last_video_pts());
rec.state = rec_state::stopped;
rec.cb(ppu, CELL_REC_STATUS_STOP, CELL_OK, rec.cbUserData);
return CELL_OK;
});
return CELL_OK;
}
error_code cellRecStart()
{
cellRec.todo("cellRecStart()");
auto& rec = g_fxo->get<rec_info>();
if (rec.state != rec_state::stopped)
{
return CELL_REC_ERROR_INVALID_STATE;
}
sysutil_register_cb([&rec](ppu_thread& ppu) -> s32
{
// Start/resume the recording
ensure(!!rec.encoder);
if (rec.param.ring_sec == 0)
{
rec.encoder->encode();
}
// Setup a video sink if it is needed
if (rec.param.use_internal_video() || rec.param.use_internal_audio())
{
utils::video_provider& video_provider = g_fxo->get<utils::video_provider>();
if (rec.sink && !video_provider.set_video_sink(rec.sink, recording_mode::cell))
{
cellRec.error("Failed to set video sink");
rec.cb(ppu, CELL_REC_STATUS_ERR, CELL_REC_ERROR_FATAL, rec.cbUserData);
return CELL_OK;
}
// Force rsx recording
g_recording_mode = recording_mode::cell;
}
else
{
// Force stop rsx recording
g_recording_mode = recording_mode::stopped;
}
rec.start_video_provider();
if (rec.sink)
{
rec.sink->resume();
}
if (rec.encoder->has_error)
{
rec.cb(ppu, CELL_REC_STATUS_ERR, CELL_REC_ERROR_FILE_OPEN, rec.cbUserData);
}
else
{
rec.state = rec_state::started;
rec.cb(ppu, CELL_REC_STATUS_START, CELL_OK, rec.cbUserData);
}
return CELL_OK;
});
return CELL_OK;
}
u32 cellRecQueryMemSize(vm::cptr<CellRecParam> pParam)
{
cellRec.notice("cellRecQueryMemSize(pParam=*0x%x)", pParam);
if (!pParam)
{
return 0x900000;
}
u32 video_size = 0x600000; // 6 MB
u32 audio_size = 0x100000; // 1 MB
u32 external_input_size = 0;
u32 reduce_memsize = 0;
s32 video_type = pParam->videoFmt & 0xf000;
s32 video_quality = pParam->videoFmt & 0xf00;
switch (video_type)
{
case VIDEO_TYPE_MPEG4:
{
switch (video_quality)
{
case VIDEO_QUALITY_0:
case VIDEO_QUALITY_3:
video_size = 0x600000; // 6 MB
break;
case VIDEO_QUALITY_1:
video_size = 0x700000; // 7 MB
break;
case VIDEO_QUALITY_2:
video_size = 0x800000; // 8 MB
break;
default:
video_size = 0x900000; // 9 MB
break;
}
audio_size = 0x100000; // 1 MB
break;
}
case VIDEO_TYPE_AVC_BL:
case VIDEO_TYPE_AVC_MP:
{
switch (video_quality)
{
case VIDEO_QUALITY_0:
case VIDEO_QUALITY_3:
video_size = 0x800000; // 8 MB
break;
default:
video_size = 0x900000; // 9 MB
break;
}
audio_size = 0x100000; // 1 MB
break;
}
case VIDEO_TYPE_M4HD:
{
switch (video_quality)
{
case VIDEO_QUALITY_0:
case VIDEO_QUALITY_1:
video_size = 0x600000; // 6 MB
break;
case VIDEO_QUALITY_2:
video_size = 0x700000; // 7 MB
break;
default:
video_size = 0x1000000; // 16 MB
break;
}
audio_size = 0x100000; // 1 MB
break;
}
default:
{
switch (video_quality)
{
case VIDEO_QUALITY_0:
video_size = 0x300000; // 3 MB
break;
case VIDEO_QUALITY_1:
case VIDEO_QUALITY_2:
video_size = 0x400000; // 4 MB
break;
case VIDEO_QUALITY_6:
video_size = 0x700000; // 7 MB
break;
default:
video_size = 0xd00000; // 14 MB
break;
}
audio_size = 0; // 0 MB
break;
}
}
for (s32 i = 0; i < pParam->numOfOpt; i++)
{
const CellRecOption& opt = pParam->pOpt[i];
switch (opt.option)
{
case CELL_REC_OPTION_REDUCE_MEMSIZE:
{
if (opt.value.reduce_memsize == CELL_REC_PARAM_REDUCE_MEMSIZE_DISABLE)
{
reduce_memsize = 0; // 0 MB
}
else
{
if (video_type == VIDEO_TYPE_M4HD && (video_quality == VIDEO_QUALITY_1 || video_quality == VIDEO_QUALITY_2))
{
reduce_memsize = 0x200000; // 2 MB
}
else
{
reduce_memsize = 0x300000; // 3 MB
}
}
break;
}
case CELL_REC_OPTION_VIDEO_INPUT:
case CELL_REC_OPTION_AUDIO_INPUT:
{
if (opt.value.audio_input != CELL_REC_PARAM_AUDIO_INPUT_DISABLE)
{
if (video_type == VIDEO_TYPE_MJPEG || (video_type == VIDEO_TYPE_M4HD && video_quality != VIDEO_QUALITY_6))
{
external_input_size = 0x100000; // 1MB
}
}
break;
}
case CELL_REC_OPTION_AUDIO_INPUT_MIX_VOL:
{
// NOTE: Doesn't seem to check opt.value.audio_input
if (video_type == VIDEO_TYPE_MJPEG || (video_type == VIDEO_TYPE_M4HD && video_quality != VIDEO_QUALITY_6))
{
external_input_size = 0x100000; // 1MB
}
break;
}
default:
break;
}
}
u32 size = video_size + audio_size + external_input_size;
if (size > reduce_memsize)
{
size -= reduce_memsize;
}
else
{
size = 0;
}
return size;
}
void cellRecGetInfo(s32 info, vm::ptr<u64> pValue)
{
cellRec.todo("cellRecGetInfo(info=0x%x, pValue=*0x%x)", info, pValue);
if (!pValue)
{
return;
}
*pValue = 0;
auto& rec = g_fxo->get<rec_info>();
switch (info)
{
case CELL_REC_INFO_VIDEO_INPUT_ADDR:
{
*pValue = rec.video_input_buffer.addr();
break;
}
case CELL_REC_INFO_VIDEO_INPUT_WIDTH:
{
*pValue = rec.input_format.width;
break;
}
case CELL_REC_INFO_VIDEO_INPUT_PITCH:
{
*pValue = rec.input_format.pitch;
break;
}
case CELL_REC_INFO_VIDEO_INPUT_HEIGHT:
{
*pValue = rec.input_format.height;
break;
}
case CELL_REC_INFO_AUDIO_INPUT_ADDR:
{
*pValue = rec.audio_input_buffer.addr();
break;
}
case CELL_REC_INFO_MOVIE_TIME_MSEC:
{
if (rec.state == rec_state::stopped)
{
*pValue = rec.recording_time_total;
}
break;
}
case CELL_REC_INFO_SPURS_SYSTEMWORKLOAD_ID:
{
if (rec.param.spurs_param.pSpurs)
{
// TODO
//cellSpurs_0xE279681F();
}
*pValue = 0xffffffff;
break;
}
default:
{
break;
}
}
}
error_code cellRecSetInfo(s32 setInfo, u64 value)
{
cellRec.todo("cellRecSetInfo(setInfo=0x%x, value=0x%x)", setInfo, value);
auto& rec = g_fxo->get<rec_info>();
if (rec.state != rec_state::stopped)
{
return CELL_REC_ERROR_INVALID_STATE;
}
switch (setInfo)
{
case CELL_REC_SETINFO_MOVIE_START_TIME_MSEC:
{
// TODO: check if this is actually identical to scene metadata
rec.param.scene_metadata.start_time = value;
cellRec.notice("cellRecSetInfo: changed movie start time to %d", value);
break;
}
case CELL_REC_SETINFO_MOVIE_END_TIME_MSEC:
{
// TODO: check if this is actually identical to scene metadata
rec.param.scene_metadata.end_time = value;
cellRec.notice("cellRecSetInfo: changed movie end time to %d", value);
break;
}
case CELL_REC_SETINFO_MOVIE_META:
{
if (!value)
{
return CELL_REC_ERROR_INVALID_VALUE;
}
vm::ptr<CellRecMovieMetadata> movie_metadata = vm::cast(value);
if (!movie_metadata || !movie_metadata->gameTitle || !movie_metadata->movieTitle ||
strnlen(movie_metadata->gameTitle.get_ptr(), CELL_REC_MOVIE_META_GAME_TITLE_LEN) >= CELL_REC_MOVIE_META_GAME_TITLE_LEN ||
strnlen(movie_metadata->movieTitle.get_ptr(), CELL_REC_MOVIE_META_MOVIE_TITLE_LEN) >= CELL_REC_MOVIE_META_MOVIE_TITLE_LEN)
{
return CELL_REC_ERROR_INVALID_VALUE;
}
if ((movie_metadata->description && strnlen(movie_metadata->description.get_ptr(), CELL_REC_MOVIE_META_DESCRIPTION_LEN) >= CELL_REC_MOVIE_META_DESCRIPTION_LEN) ||
(movie_metadata->userdata && strnlen(movie_metadata->userdata.get_ptr(), CELL_REC_MOVIE_META_USERDATA_LEN) >= CELL_REC_MOVIE_META_USERDATA_LEN))
{
return CELL_REC_ERROR_INVALID_VALUE;
}
rec.param.movie_metadata = {};
rec.param.movie_metadata.game_title = std::string{movie_metadata->gameTitle.get_ptr()};
rec.param.movie_metadata.movie_title = std::string{movie_metadata->movieTitle.get_ptr()};
if (movie_metadata->description)
{
rec.param.movie_metadata.description = std::string{movie_metadata->description.get_ptr()};
}
if (movie_metadata->userdata)
{
rec.param.movie_metadata.userdata = std::string{movie_metadata->userdata.get_ptr()};
}
cellRec.notice("cellRecSetInfo: changed movie metadata to %s", rec.param.movie_metadata.to_string());
break;
}
case CELL_REC_SETINFO_SCENE_META:
{
if (!value)
{
return CELL_REC_ERROR_INVALID_VALUE;
}
vm::ptr<CellRecSceneMetadata> scene_metadata = vm::cast(value);
if (!scene_metadata || !scene_metadata->title ||
scene_metadata->type > CELL_REC_SCENE_META_TYPE_CLIP_USER ||
scene_metadata->tagNum > CELL_REC_SCENE_META_TAG_NUM ||
strnlen(scene_metadata->title.get_ptr(), CELL_REC_SCENE_META_TITLE_LEN) >= CELL_REC_SCENE_META_TITLE_LEN)
{
return CELL_REC_ERROR_INVALID_VALUE;
}
for (u32 i = 0; i < scene_metadata->tagNum; i++)
{
if (!scene_metadata->tag[i] ||
strnlen(scene_metadata->tag[i].get_ptr(), CELL_REC_SCENE_META_TAG_LEN) >= CELL_REC_SCENE_META_TAG_LEN)
{
return CELL_REC_ERROR_INVALID_VALUE;
}
}
rec.param.scene_metadata = {};
rec.param.scene_metadata.is_set = true;
rec.param.scene_metadata.type = scene_metadata->type;
rec.param.scene_metadata.start_time = scene_metadata->startTime;
rec.param.scene_metadata.end_time = scene_metadata->endTime;
rec.param.scene_metadata.title = std::string{scene_metadata->title.get_ptr()};
rec.param.scene_metadata.tags.resize(scene_metadata->tagNum);
for (u32 i = 0; i < scene_metadata->tagNum; i++)
{
if (scene_metadata->tag[i])
{
rec.param.scene_metadata.tags[i] = std::string{scene_metadata->tag[i].get_ptr()};
}
}
cellRec.notice("cellRecSetInfo: changed scene metadata to %s", rec.param.scene_metadata.to_string());
break;
}
default:
{
return CELL_REC_ERROR_INVALID_VALUE;
}
}
return CELL_OK;
}
DECLARE(ppu_module_manager::cellRec)("cellRec", []()
{
REG_FUNC(cellRec, cellRecOpen);
REG_FUNC(cellRec, cellRecClose);
REG_FUNC(cellRec, cellRecGetInfo);
REG_FUNC(cellRec, cellRecStop);
REG_FUNC(cellRec, cellRecStart);
REG_FUNC(cellRec, cellRecQueryMemSize);
REG_FUNC(cellRec, cellRecSetInfo);
});
| 52,668
|
C++
|
.cpp
| 1,641
| 28.872639
| 384
| 0.699648
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
5,207
|
cellRemotePlay.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellRemotePlay.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
#include "cellRemotePlay.h"
LOG_CHANNEL(cellRemotePlay);
template <>
void fmt_class_string<CellRemotePlayError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](CellRemotePlayError value)
{
switch (value)
{
STR_CASE(CELL_REMOTEPLAY_ERROR_INTERNAL);
}
return unknown;
});
}
error_code cellRemotePlayGetStatus()
{
cellRemotePlay.todo("cellRemotePlayGetStatus()");
return CELL_OK;
}
error_code cellRemotePlaySetComparativeVolume(f32 comparativeAudioVolume)
{
cellRemotePlay.todo("cellRemotePlaySetComparativeVolume(comparativeAudioVolume=%f)", comparativeAudioVolume);
return CELL_OK;
}
error_code cellRemotePlayGetPeerInfo()
{
cellRemotePlay.todo("cellRemotePlayGetPeerInfo()");
return CELL_OK;
}
error_code cellRemotePlayGetSharedMemory()
{
cellRemotePlay.todo("cellRemotePlayGetSharedMemory()");
return CELL_OK;
}
error_code cellRemotePlayEncryptAllData()
{
cellRemotePlay.todo("cellRemotePlayEncryptAllData()");
return CELL_OK;
}
error_code cellRemotePlayStopPeerVideoOut()
{
cellRemotePlay.todo("cellRemotePlayStopPeerVideoOut()");
return CELL_OK;
}
error_code cellRemotePlayGetComparativeVolume(vm::ptr<f32> pComparativeAudioVolume)
{
cellRemotePlay.todo("cellRemotePlayGetComparativeVolume(pComparativeAudioVolume=*0x%x)", pComparativeAudioVolume);
if (pComparativeAudioVolume)
{
*pComparativeAudioVolume = 1.f;
}
return CELL_OK;
}
error_code cellRemotePlayBreak()
{
cellRemotePlay.todo("cellRemotePlayBreak()");
return CELL_OK;
}
DECLARE(ppu_module_manager::cellRemotePlay)("cellRemotePlay", []()
{
REG_FUNC(cellRemotePlay, cellRemotePlayGetStatus);
REG_FUNC(cellRemotePlay, cellRemotePlaySetComparativeVolume);
REG_FUNC(cellRemotePlay, cellRemotePlayGetPeerInfo);
REG_FUNC(cellRemotePlay, cellRemotePlayGetSharedMemory);
REG_FUNC(cellRemotePlay, cellRemotePlayEncryptAllData);
REG_FUNC(cellRemotePlay, cellRemotePlayStopPeerVideoOut);
REG_FUNC(cellRemotePlay, cellRemotePlayGetComparativeVolume);
REG_FUNC(cellRemotePlay, cellRemotePlayBreak);
});
| 2,076
|
C++
|
.cpp
| 71
| 27.43662
| 115
| 0.828141
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| true
| false
| false
| true
| false
| false
|
5,208
|
sys_game_.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/sys_game_.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
#include "Emu/Cell/lv2/sys_mutex.h"
#include "Emu/Cell/lv2/sys_process.h"
#include "sysPrxForUser.h"
LOG_CHANNEL(sysPrxForUser);
extern vm::gvar<u32> g_ppu_exit_mutex;
extern vm::gvar<vm::ptr<void()>> g_ppu_atexitspawn;
extern vm::gvar<vm::ptr<void()>> g_ppu_at_Exitspawn;
static u32 get_string_array_size(vm::cpptr<char> list, u32& out_count)
{
//out_count = 0;
u32 result = 8;
for (u32 i = 0; list; i++)
{
if (const vm::cptr<char> str = list[i])
{
out_count++;
result += ((static_cast<u32>(std::strlen(str.get_ptr())) + 0x10) & -0x10) + 8;
continue;
}
break;
}
return result;
}
static u32 get_exitspawn_size(vm::cptr<char> path, vm::cpptr<char> argv, vm::cpptr<char> envp, u32& arg_count, u32& env_count)
{
arg_count = 1;
env_count = 0;
u32 result = ((static_cast<u32>(std::strlen(path.get_ptr())) + 0x10) & -0x10) + 8;
result += get_string_array_size(argv, arg_count);
result += get_string_array_size(envp, env_count);
if ((arg_count + env_count) % 2)
{
result += 8;
}
return result;
}
static void put_string_array(vm::pptr<char, u32, u64> pstr, vm::ptr<char>& str, u32 count, vm::cpptr<char> list)
{
for (u32 i = 0; i < count; i++)
{
const u32 len = static_cast<u32>(std::strlen(list[i].get_ptr()));
std::memcpy(str.get_ptr(), list[i].get_ptr(), len + 1);
pstr[i] = str;
str += (len + 0x10) & -0x10;
}
pstr[count] = vm::null;
}
static void put_exitspawn(vm::ptr<void> out, vm::cptr<char> path, u32 argc, vm::cpptr<char> argv, u32 envc, vm::cpptr<char> envp)
{
vm::pptr<char, u32, u64> pstr = vm::cast(out.addr());
vm::ptr<char> str = vm::static_ptr_cast<char>(out) + (argc + envc + (argc + envc) % 2) * 8 + 0x10;
const u32 len = static_cast<u32>(std::strlen(path.get_ptr()));
std::memcpy(str.get_ptr(), path.get_ptr(), len + 1);
*pstr++ = str;
str += (len + 0x10) & -0x10;
put_string_array(pstr, str, argc - 1, argv);
put_string_array(pstr + argc, str, envc, envp);
}
static void exitspawn(ppu_thread& ppu, vm::cptr<char> path, vm::cpptr<char> argv, vm::cpptr<char> envp, u32 data, u32 data_size, s32 prio, u64 _flags)
{
sys_mutex_lock(ppu, *g_ppu_exit_mutex, 0);
u32 arg_count = 0;
u32 env_count = 0;
u32 alloc_size = get_exitspawn_size(path, argv, envp, arg_count, env_count);
if (alloc_size > 0x1000)
{
argv = vm::null;
envp = vm::null;
arg_count = 0;
env_count = 0;
alloc_size = get_exitspawn_size(path, vm::null, vm::null, arg_count, env_count);
}
alloc_size += 0x30;
if (data_size > 0)
{
alloc_size += 0x1030;
}
u32 alloc_addr = vm::alloc(alloc_size, vm::main);
if (!alloc_addr)
{
// TODO (process atexit)
return _sys_process_exit(ppu, CELL_ENOMEM, 0, 0);
}
put_exitspawn(vm::cast(alloc_addr + 0x30), path, arg_count, argv, env_count, envp);
if (data_size)
{
std::memcpy(vm::base(alloc_addr + alloc_size - 0x1000), vm::base(data), std::min<u32>(data_size, 0x1000));
}
vm::ptr<sys_exit2_param> arg = vm::cast(alloc_addr);
arg->x0 = 0x85;
arg->this_size = 0x30;
arg->next_size = alloc_size - 0x30;
arg->prio = prio;
arg->flags = _flags;
arg->args = vm::cast(alloc_addr + 0x30);
if ((_flags >> 62) == 0 && *g_ppu_atexitspawn)
{
// Execute atexitspawn
g_ppu_atexitspawn->operator()(ppu);
}
if ((_flags >> 62) == 1 && *g_ppu_at_Exitspawn)
{
// Execute at_Exitspawn
g_ppu_at_Exitspawn->operator()(ppu);
}
// TODO (process atexit)
return _sys_process_exit2(ppu, 0, arg, alloc_size, 0x10000000);
}
void sys_game_process_exitspawn(ppu_thread& ppu, vm::cptr<char> path, vm::cpptr<char> argv, vm::cpptr<char> envp, u32 data, u32 data_size, s32 prio, u64 flags)
{
sysPrxForUser.warning("sys_game_process_exitspawn(path=%s, argv=**0x%x, envp=**0x%x, data=*0x%x, data_size=0x%x, prio=%d, flags=0x%x)", path, argv, envp, data, data_size, prio, flags);
return exitspawn(ppu, path, argv, envp, data, data_size, prio, (flags & 0xf0) | (1ull << 63));
}
void sys_game_process_exitspawn2(ppu_thread& ppu, vm::cptr<char> path, vm::cpptr<char> argv, vm::cpptr<char> envp, u32 data, u32 data_size, s32 prio, u64 flags)
{
sysPrxForUser.warning("sys_game_process_exitspawn2(path=%s, argv=**0x%x, envp=**0x%x, data=*0x%x, data_size=0x%x, prio=%d, flags=0x%x)", path, argv, envp, data, data_size, prio, flags);
return exitspawn(ppu, path, argv, envp, data, data_size, prio, (flags >> 62) >= 2 ? flags & 0xf0 : flags & 0xc0000000000000f0ull);
}
error_code sys_game_board_storage_read()
{
sysPrxForUser.todo("sys_game_board_storage_read()");
return CELL_OK;
}
error_code sys_game_board_storage_write()
{
sysPrxForUser.todo("sys_game_board_storage_write()");
return CELL_OK;
}
error_code sys_game_get_rtc_status()
{
sysPrxForUser.todo("sys_game_get_rtc_status()");
return CELL_OK;
}
error_code sys_game_get_system_sw_version()
{
sysPrxForUser.todo("sys_game_get_system_sw_version()");
return CELL_OK;
}
error_code sys_game_get_temperature()
{
sysPrxForUser.todo("sys_game_get_temperature()");
return CELL_OK;
}
error_code sys_game_watchdog_clear()
{
sysPrxForUser.todo("sys_game_watchdog_clear()");
return CELL_OK;
}
error_code sys_game_watchdog_start()
{
sysPrxForUser.todo("sys_game_watchdog_start()");
return CELL_OK;
}
error_code sys_game_watchdog_stop()
{
sysPrxForUser.todo("sys_game_watchdog_stop()");
return CELL_OK;
}
void sysPrxForUser_sys_game_init()
{
REG_FUNC(sysPrxForUser, sys_game_process_exitspawn2);
REG_FUNC(sysPrxForUser, sys_game_process_exitspawn);
REG_FUNC(sysPrxForUser, sys_game_board_storage_read);
REG_FUNC(sysPrxForUser, sys_game_board_storage_write);
REG_FUNC(sysPrxForUser, sys_game_get_rtc_status);
REG_FUNC(sysPrxForUser, sys_game_get_system_sw_version);
REG_FUNC(sysPrxForUser, sys_game_get_temperature);
REG_FUNC(sysPrxForUser, sys_game_watchdog_clear);
REG_FUNC(sysPrxForUser, sys_game_watchdog_start);
REG_FUNC(sysPrxForUser, sys_game_watchdog_stop);
}
| 5,927
|
C++
|
.cpp
| 173
| 32.184971
| 186
| 0.684874
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| true
| false
| false
| true
| false
| false
|
5,209
|
cellWebBrowser.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellWebBrowser.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
#include "cellWebBrowser.h"
#include "Emu/IdManager.h"
LOG_CHANNEL(cellSysutil);
struct browser_info
{
vm::ptr<CellWebBrowserSystemCallback> system_cb{};
vm::ptr<void> userData{};
shared_mutex mutex;
};
error_code cellWebBrowserActivate()
{
cellSysutil.todo("cellWebBrowserActivate()");
return CELL_OK;
}
error_code cellWebBrowserConfig()
{
cellSysutil.todo("cellWebBrowserConfig()");
return CELL_OK;
}
error_code cellWebBrowserConfig2(vm::cptr<CellWebBrowserConfig2> config, u32 version)
{
cellSysutil.todo("cellWebBrowserConfig2(config=*0x%x, version=%d)", config, version);
return CELL_OK;
}
error_code cellWebBrowserConfigGetHeapSize()
{
cellSysutil.todo("cellWebBrowserConfigGetHeapSize()");
return CELL_OK;
}
error_code cellWebBrowserConfigGetHeapSize2()
{
cellSysutil.todo("cellWebBrowserConfigGetHeapSize2()");
return CELL_OK;
}
error_code cellWebBrowserConfigSetCustomExit()
{
cellSysutil.todo("cellWebBrowserConfigSetCustomExit()");
return CELL_OK;
}
error_code cellWebBrowserConfigSetDisableTabs()
{
cellSysutil.todo("cellWebBrowserConfigSetDisableTabs()");
return CELL_OK;
}
error_code cellWebBrowserConfigSetErrorHook2()
{
cellSysutil.todo("cellWebBrowserConfigSetErrorHook2()");
return CELL_OK;
}
error_code cellWebBrowserConfigSetFullScreen2(vm::cptr<CellWebBrowserConfig2> config, u32 full)
{
cellSysutil.todo("cellWebBrowserConfigSetFullScreen2(config=*0x%x, full=%d)", config, full);
return CELL_OK;
}
error_code cellWebBrowserConfigSetFullVersion2()
{
cellSysutil.todo("cellWebBrowserConfigSetFullVersion2()");
return CELL_OK;
}
error_code cellWebBrowserConfigSetFunction()
{
cellSysutil.todo("cellWebBrowserConfigSetFunction()");
return CELL_OK;
}
error_code cellWebBrowserConfigSetFunction2(vm::ptr<CellWebBrowserConfig2> config, u32 funcset)
{
cellSysutil.todo("cellWebBrowserConfigSetFunction2(config=*0x%x, funcset=0x%x)", config, funcset);
return CELL_OK;
}
error_code cellWebBrowserConfigSetHeapSize()
{
cellSysutil.todo("cellWebBrowserConfigSetHeapSize()");
return CELL_OK;
}
error_code cellWebBrowserConfigSetHeapSize2(vm::ptr<CellWebBrowserConfig2> config, u32 size)
{
cellSysutil.todo("cellWebBrowserConfigSetHeapSize(config=*0x%x, size=0x%x)", config, size);
return CELL_OK;
}
error_code cellWebBrowserConfigSetMimeSet()
{
cellSysutil.todo("cellWebBrowserConfigSetMimeSet()");
return CELL_OK;
}
error_code cellWebBrowserConfigSetNotifyHook2(vm::cptr<CellWebBrowserConfig2> config, vm::ptr<CellWebBrowserNotify> cb, vm::ptr<void> userdata)
{
cellSysutil.todo("cellWebBrowserConfigSetNotifyHook2(config=*0x%x, cb=*0x%x, userdata=*0x%x)", config, cb, userdata);
return CELL_OK;
}
error_code cellWebBrowserConfigSetRequestHook2()
{
cellSysutil.todo("cellWebBrowserConfigSetRequestHook2()");
return CELL_OK;
}
error_code cellWebBrowserConfigSetStatusHook2()
{
cellSysutil.todo("cellWebBrowserConfigSetStatusHook2()");
return CELL_OK;
}
error_code cellWebBrowserConfigSetTabCount2(vm::cptr<CellWebBrowserConfig2> config, u32 tab_count)
{
cellSysutil.todo("cellWebBrowserConfigSetTabCount2(config=*0x%x, tab_count=%d)", config, tab_count);
return CELL_OK;
}
error_code cellWebBrowserConfigSetUnknownMIMETypeHook2(vm::cptr<CellWebBrowserConfig2> config, vm::ptr<CellWebBrowserMIMETypeCallback> cb, vm::ptr<void> userdata)
{
cellSysutil.todo("cellWebBrowserConfigSetUnknownMIMETypeHook2(config=*0x%x, cb=*0x%x, userdata=*0x%x)", config, cb, userdata);
return CELL_OK;
}
error_code cellWebBrowserConfigSetVersion()
{
cellSysutil.todo("cellWebBrowserConfigSetVersion()");
return CELL_OK;
}
error_code cellWebBrowserConfigSetViewCondition2(vm::ptr<CellWebBrowserConfig2> config, u32 cond)
{
cellSysutil.todo("cellWebBrowserConfigSetViewCondition2(config=*0x%x, cond=0x%x)", config, cond);
return CELL_OK;
}
error_code cellWebBrowserConfigSetViewRect2()
{
cellSysutil.todo("cellWebBrowserConfigSetViewRect2()");
return CELL_OK;
}
error_code cellWebBrowserConfigWithVer()
{
cellSysutil.todo("cellWebBrowserConfigWithVer()");
return CELL_OK;
}
error_code cellWebBrowserCreate()
{
cellSysutil.todo("cellWebBrowserCreate()");
return CELL_OK;
}
error_code cellWebBrowserCreate2()
{
cellSysutil.todo("cellWebBrowserCreate2()");
return CELL_OK;
}
error_code cellWebBrowserCreateRender2()
{
cellSysutil.todo("cellWebBrowserCreateRender2()");
return CELL_OK;
}
error_code cellWebBrowserCreateRenderWithRect2()
{
cellSysutil.todo("cellWebBrowserCreateRenderWithRect2()");
return CELL_OK;
}
error_code cellWebBrowserCreateWithConfig()
{
cellSysutil.todo("cellWebBrowserCreateWithConfig()");
return CELL_OK;
}
error_code cellWebBrowserCreateWithConfigFull()
{
cellSysutil.todo("cellWebBrowserCreateWithConfigFull()");
return CELL_OK;
}
error_code cellWebBrowserCreateWithRect2()
{
cellSysutil.todo("cellWebBrowserCreateWithRect2()");
return CELL_OK;
}
error_code cellWebBrowserDeactivate()
{
cellSysutil.todo("cellWebBrowserDeactivate()");
return CELL_OK;
}
error_code cellWebBrowserDestroy()
{
cellSysutil.todo("cellWebBrowserDestroy()");
return CELL_OK;
}
error_code cellWebBrowserDestroy2()
{
cellSysutil.todo("cellWebBrowserDestroy2()");
return CELL_OK;
}
error_code cellWebBrowserEstimate()
{
cellSysutil.todo("cellWebBrowserEstimate()");
return CELL_OK;
}
error_code cellWebBrowserEstimate2(vm::cptr<CellWebBrowserConfig2> config, vm::ptr<u32> memSize)
{
cellSysutil.warning("cellWebBrowserEstimate2(config=*0x%x, memSize=*0x%x)", config, memSize);
// TODO: When cellWebBrowser stuff is implemented, change this to some real
// needed memory buffer size.
*memSize = 1 * 1024 * 1024; // 1 MB
return CELL_OK;
}
error_code cellWebBrowserGetUsrdataOnGameExit(vm::ptr<CellWebBrowserUsrdata> ptr)
{
cellSysutil.todo("cellWebBrowserGetUsrdataOnGameExit(ptr=*0x%x)", ptr);
return CELL_OK;
}
error_code cellWebBrowserInitialize(vm::ptr<CellWebBrowserSystemCallback> system_cb, u32 container)
{
cellSysutil.todo("cellWebBrowserInitialize(system_cb=*0x%x, container=0x%x)", system_cb, container);
auto& browser = g_fxo->get<browser_info>();
browser.system_cb = system_cb;
sysutil_register_cb([=, &browser](ppu_thread& ppu) -> s32
{
system_cb(ppu, CELL_SYSUTIL_WEBBROWSER_INITIALIZING_FINISHED, browser.userData);
return CELL_OK;
});
return CELL_OK;
}
error_code cellWebBrowserNavigate2()
{
cellSysutil.todo("cellWebBrowserNavigate2()");
return CELL_OK;
}
error_code cellWebBrowserSetLocalContentsAdditionalTitleID()
{
cellSysutil.todo("cellWebBrowserSetLocalContentsAdditionalTitleID()");
return CELL_OK;
}
error_code cellWebBrowserSetSystemCallbackUsrdata()
{
cellSysutil.todo("cellWebBrowserSetSystemCallbackUsrdata()");
return CELL_OK;
}
void cellWebBrowserShutdown()
{
cellSysutil.todo("cellWebBrowserShutdown()");
auto& browser = g_fxo->get<browser_info>();
sysutil_register_cb([=, &browser](ppu_thread& ppu) -> s32
{
browser.system_cb(ppu, CELL_SYSUTIL_WEBBROWSER_SHUTDOWN_FINISHED, browser.userData);
return CELL_OK;
});
}
error_code cellWebBrowserUpdatePointerDisplayPos2()
{
cellSysutil.todo("cellWebBrowserUpdatePointerDisplayPos2()");
return CELL_OK;
}
error_code cellWebBrowserWakeupWithGameExit()
{
cellSysutil.todo("cellWebBrowserWakeupWithGameExit()");
return CELL_OK;
}
error_code cellWebComponentCreate()
{
cellSysutil.todo("cellWebComponentCreate()");
return CELL_OK;
}
error_code cellWebComponentCreateAsync()
{
cellSysutil.todo("cellWebComponentCreateAsync()");
return CELL_OK;
}
error_code cellWebComponentDestroy()
{
cellSysutil.todo("cellWebComponentDestroy()");
return CELL_OK;
}
void cellSysutil_WebBrowser_init()
{
REG_FUNC(cellSysutil, cellWebBrowserActivate);
REG_FUNC(cellSysutil, cellWebBrowserConfig);
REG_FUNC(cellSysutil, cellWebBrowserConfig2);
REG_FUNC(cellSysutil, cellWebBrowserConfigGetHeapSize);
REG_FUNC(cellSysutil, cellWebBrowserConfigGetHeapSize2);
REG_FUNC(cellSysutil, cellWebBrowserConfigSetCustomExit);
REG_FUNC(cellSysutil, cellWebBrowserConfigSetDisableTabs);
REG_FUNC(cellSysutil, cellWebBrowserConfigSetErrorHook2);
REG_FUNC(cellSysutil, cellWebBrowserConfigSetFullScreen2);
REG_FUNC(cellSysutil, cellWebBrowserConfigSetFullVersion2);
REG_FUNC(cellSysutil, cellWebBrowserConfigSetFunction);
REG_FUNC(cellSysutil, cellWebBrowserConfigSetFunction2);
REG_FUNC(cellSysutil, cellWebBrowserConfigSetHeapSize);
REG_FUNC(cellSysutil, cellWebBrowserConfigSetHeapSize2);
REG_FUNC(cellSysutil, cellWebBrowserConfigSetMimeSet);
REG_FUNC(cellSysutil, cellWebBrowserConfigSetNotifyHook2);
REG_FUNC(cellSysutil, cellWebBrowserConfigSetRequestHook2);
REG_FUNC(cellSysutil, cellWebBrowserConfigSetStatusHook2);
REG_FUNC(cellSysutil, cellWebBrowserConfigSetTabCount2);
REG_FUNC(cellSysutil, cellWebBrowserConfigSetUnknownMIMETypeHook2);
REG_FUNC(cellSysutil, cellWebBrowserConfigSetVersion);
REG_FUNC(cellSysutil, cellWebBrowserConfigSetViewCondition2);
REG_FUNC(cellSysutil, cellWebBrowserConfigSetViewRect2);
REG_FUNC(cellSysutil, cellWebBrowserConfigWithVer);
REG_FUNC(cellSysutil, cellWebBrowserCreate);
REG_FUNC(cellSysutil, cellWebBrowserCreate2);
REG_FUNC(cellSysutil, cellWebBrowserCreateRender2);
REG_FUNC(cellSysutil, cellWebBrowserCreateRenderWithRect2);
REG_FUNC(cellSysutil, cellWebBrowserCreateWithConfig);
REG_FUNC(cellSysutil, cellWebBrowserCreateWithConfigFull);
REG_FUNC(cellSysutil, cellWebBrowserCreateWithRect2);
REG_FUNC(cellSysutil, cellWebBrowserDeactivate);
REG_FUNC(cellSysutil, cellWebBrowserDestroy);
REG_FUNC(cellSysutil, cellWebBrowserDestroy2);
REG_FUNC(cellSysutil, cellWebBrowserEstimate);
REG_FUNC(cellSysutil, cellWebBrowserEstimate2);
REG_FUNC(cellSysutil, cellWebBrowserGetUsrdataOnGameExit);
REG_FUNC(cellSysutil, cellWebBrowserInitialize);
REG_FUNC(cellSysutil, cellWebBrowserNavigate2);
REG_FUNC(cellSysutil, cellWebBrowserSetLocalContentsAdditionalTitleID);
REG_FUNC(cellSysutil, cellWebBrowserSetSystemCallbackUsrdata);
REG_FUNC(cellSysutil, cellWebBrowserShutdown);
REG_FUNC(cellSysutil, cellWebBrowserUpdatePointerDisplayPos2);
REG_FUNC(cellSysutil, cellWebBrowserWakeupWithGameExit);
REG_FUNC(cellSysutil, cellWebComponentCreate);
REG_FUNC(cellSysutil, cellWebComponentCreateAsync);
REG_FUNC(cellSysutil, cellWebComponentDestroy);
}
| 10,286
|
C++
|
.cpp
| 311
| 31.360129
| 162
| 0.828762
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| true
| false
| false
| true
| false
| false
|
5,210
|
cellSysutilAvc2.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellSysutilAvc2.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
#include "Emu/IdManager.h"
#include "util/asm.hpp"
#include "sceNp.h"
#include "sceNp2.h"
#include "cellSysutilAvc2.h"
#include "cellSysutil.h"
LOG_CHANNEL(cellSysutilAvc2);
template<>
void fmt_class_string<CellSysutilAvc2Error>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_AVC2_ERROR_UNKNOWN);
STR_CASE(CELL_AVC2_ERROR_NOT_SUPPORTED);
STR_CASE(CELL_AVC2_ERROR_NOT_INITIALIZED);
STR_CASE(CELL_AVC2_ERROR_ALREADY_INITIALIZED);
STR_CASE(CELL_AVC2_ERROR_INVALID_ARGUMENT);
STR_CASE(CELL_AVC2_ERROR_OUT_OF_MEMORY);
STR_CASE(CELL_AVC2_ERROR_ERROR_BAD_ID);
STR_CASE(CELL_AVC2_ERROR_INVALID_STATUS);
STR_CASE(CELL_AVC2_ERROR_TIMEOUT);
STR_CASE(CELL_AVC2_ERROR_NO_SESSION);
STR_CASE(CELL_AVC2_ERROR_WINDOW_ALREADY_EXISTS);
STR_CASE(CELL_AVC2_ERROR_TOO_MANY_WINDOWS);
STR_CASE(CELL_AVC2_ERROR_TOO_MANY_PEER_WINDOWS);
STR_CASE(CELL_AVC2_ERROR_WINDOW_NOT_FOUND);
}
return unknown;
});
}
template<>
void fmt_class_string<CellSysutilAvc2AttributeId>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](CellSysutilAvc2AttributeId value)
{
switch (value)
{
STR_CASE(CELL_SYSUTIL_AVC2_ATTRIBUTE_VOICE_DETECT_EVENT_TYPE);
STR_CASE(CELL_SYSUTIL_AVC2_ATTRIBUTE_VOICE_DETECT_INTERVAL_TIME);
STR_CASE(CELL_SYSUTIL_AVC2_ATTRIBUTE_VOICE_DETECT_SIGNAL_LEVEL);
STR_CASE(CELL_SYSUTIL_AVC2_ATTRIBUTE_VOICE_MAX_BITRATE);
STR_CASE(CELL_SYSUTIL_AVC2_ATTRIBUTE_VOICE_DATA_FEC);
STR_CASE(CELL_SYSUTIL_AVC2_ATTRIBUTE_VOICE_PACKET_CONTENTION);
STR_CASE(CELL_SYSUTIL_AVC2_ATTRIBUTE_VOICE_DTX_MODE);
STR_CASE(CELL_SYSUTIL_AVC2_ATTRIBUTE_MIC_STATUS_DETECTION);
STR_CASE(CELL_SYSUTIL_AVC2_ATTRIBUTE_MIC_SETTING_NOTIFICATION);
STR_CASE(CELL_SYSUTIL_AVC2_ATTRIBUTE_VOICE_MUTING_NOTIFICATION);
STR_CASE(CELL_SYSUTIL_AVC2_ATTRIBUTE_CAMERA_STATUS_DETECTION);
}
return unknown;
});
}
// Callback handle tag type
struct avc2_cb_handle_t{};
struct avc2_settings
{
avc2_settings() = default;
avc2_settings(const avc2_settings&) = delete;
avc2_settings& operator=(const avc2_settings&) = delete;
SAVESTATE_INIT_POS(52);
shared_mutex mutex_cb;
vm::ptr<CellSysutilAvc2Callback> avc2_cb{};
vm::ptr<void> avc2_cb_arg{};
u32 streaming_mode = CELL_SYSUTIL_AVC2_STREAMING_MODE_NORMAL;
u8 mic_out_stream_sharing = 0;
u8 video_stream_sharing = 0;
u32 total_video_bitrate = 0;
std::set<u16> voice_muting_players;
bool voice_muting = 1;
bool video_muting = 1;
bool speaker_muting = 1;
f32 speaker_volume_level = 40.0f;
static bool saveable(bool /*is_writing*/) noexcept
{
return GET_SERIALIZATION_VERSION(cellSysutil) != 0;
}
avc2_settings(utils::serial& ar) noexcept
{
[[maybe_unused]] const s32 version = GET_SERIALIZATION_VERSION(cellSysutil);
if (version == 0)
{
return;
}
save(ar);
}
void save(utils::serial& ar)
{
[[maybe_unused]] const s32 version = GET_OR_USE_SERIALIZATION_VERSION(ar.is_writing(), cellSysutil);
ar(avc2_cb, avc2_cb_arg, streaming_mode, mic_out_stream_sharing, video_stream_sharing, total_video_bitrate);
if (ar.is_writing() || version >= 2)
{
ar(voice_muting_players, voice_muting, video_muting, speaker_muting, speaker_volume_level);
}
}
void register_cb_call(u32 event, u32 error_code)
{
// This is equivalent to the dispatcher code
sysutil_register_cb_with_id<avc2_cb_handle_t>([=, this](ppu_thread& cb_ppu) -> s32
{
vm::ptr<CellSysutilAvc2Callback> avc2_cb{};
vm::ptr<void> avc2_cb_arg{};
{
std::lock_guard lock(this->mutex_cb);
avc2_cb = this->avc2_cb;
avc2_cb_arg = this->avc2_cb_arg;
}
if (avc2_cb)
{
avc2_cb(cb_ppu, event, error_code, avc2_cb_arg);
if ((event == CELL_AVC2_EVENT_LOAD_FAILED ||
event == CELL_AVC2_EVENT_UNLOAD_SUCCEEDED ||
event == CELL_AVC2_EVENT_UNLOAD_FAILED) &&
error_code < 2)
{
sysutil_unregister_cb_with_id<avc2_cb_handle_t>();
std::lock_guard lock(this->mutex_cb);
this->avc2_cb = vm::null;
this->avc2_cb_arg = vm::null;
}
}
return 0;
});
}
};
error_code cellSysutilAvc2GetPlayerInfo(vm::cptr<SceNpMatching2RoomMemberId> player_id, vm::ptr<CellSysutilAvc2PlayerInfo> player_info)
{
cellSysutilAvc2.todo("cellSysutilAvc2GetPlayerInfo(player_id=*0x%x, player_info=*0x%x)", player_id, player_info);
if (!player_id || !player_info)
return CELL_AVC2_ERROR_INVALID_ARGUMENT;
player_info->connected = 1;
player_info->joined = 1;
player_info->mic_attached = CELL_AVC2_MIC_STATUS_DETACHED;
player_info->member_id = *player_id;
return CELL_OK;
}
error_code cellSysutilAvc2JoinChat(vm::cptr<SceNpMatching2RoomId> room_id, vm::ptr<CellSysutilAvc2EventId> eventId, vm::ptr<CellSysutilAvc2EventParam> eventParam)
{
cellSysutilAvc2.todo("cellSysutilAvc2JoinChat(room_id=*0x%x, eventId=*0x%x, eventParam=*0x%x)", room_id, eventId, eventParam);
// NOTE: room_id should be null if the current mode is Direct WAN/LAN
auto& settings = g_fxo->get<avc2_settings>();
[[maybe_unused]] u64 id = 0UL;
if (room_id)
{
id = *room_id;
}
else if (settings.streaming_mode != CELL_SYSUTIL_AVC2_STREAMING_MODE_NORMAL)
{
return CELL_AVC2_ERROR_INVALID_ARGUMENT;
}
// TODO: join chat
return CELL_OK;
}
error_code cellSysutilAvc2StopStreaming()
{
cellSysutilAvc2.todo("cellSysutilAvc2StopStreaming()");
return CELL_OK;
}
error_code cellSysutilAvc2ChangeVideoResolution(u32 resolution)
{
cellSysutilAvc2.todo("cellSysutilAvc2ChangeVideoResolution(resolution=0x%x)", resolution);
return CELL_OK;
}
error_code cellSysutilAvc2ShowScreen()
{
cellSysutilAvc2.todo("cellSysutilAvc2ShowScreen()");
return CELL_OK;
}
error_code cellSysutilAvc2GetVideoMuting(vm::ptr<u8> muting)
{
cellSysutilAvc2.todo("cellSysutilAvc2GetVideoMuting(muting=*0x%x)", muting);
if (!muting)
return CELL_AVC2_ERROR_INVALID_ARGUMENT;
const auto& settings = g_fxo->get<avc2_settings>();
*muting = settings.video_muting;
return CELL_OK;
}
error_code cellSysutilAvc2GetWindowAttribute(SceNpMatching2RoomMemberId member_id, vm::ptr<CellSysutilAvc2WindowAttribute> attr)
{
cellSysutilAvc2.todo("cellSysutilAvc2GetWindowAttribute(member_id=0x%x, attr=*0x%x)", member_id, attr);
if (!attr)
return CELL_AVC2_ERROR_INVALID_ARGUMENT;
switch (attr->attr_id)
{
case CELL_SYSUTIL_AVC2_WINDOW_ATTRIBUTE_ALPHA:
break;
case CELL_SYSUTIL_AVC2_WINDOW_ATTRIBUTE_TRANSITION_TYPE:
break;
case CELL_SYSUTIL_AVC2_WINDOW_ATTRIBUTE_TRANSITION_DURATION:
break;
case CELL_SYSUTIL_AVC2_WINDOW_ATTRIBUTE_STRING_VISIBLE:
break;
case CELL_SYSUTIL_AVC2_WINDOW_ATTRIBUTE_ROTATION:
break;
case CELL_SYSUTIL_AVC2_WINDOW_ATTRIBUTE_ZORDER:
break;
case CELL_SYSUTIL_AVC2_WINDOW_ATTRIBUTE_SURFACE:
break;
default:
break;
}
return CELL_OK;
}
error_code cellSysutilAvc2StopStreaming2(u32 mediaType)
{
cellSysutilAvc2.todo("cellSysutilAvc2StopStreaming2(mediaType=0x%x)", mediaType);
if (mediaType != CELL_SYSUTIL_AVC2_VOICE_CHAT && mediaType != CELL_SYSUTIL_AVC2_VIDEO_CHAT)
return CELL_AVC2_ERROR_INVALID_ARGUMENT;
return CELL_OK;
}
error_code cellSysutilAvc2SetVoiceMuting(u8 muting)
{
cellSysutilAvc2.todo("cellSysutilAvc2SetVoiceMuting(muting=0x%x)", muting);
auto& settings = g_fxo->get<avc2_settings>();
settings.voice_muting = muting;
return CELL_OK;
}
error_code cellSysutilAvc2StartVoiceDetection()
{
cellSysutilAvc2.todo("cellSysutilAvc2StartVoiceDetection()");
return CELL_OK;
}
error_code cellSysutilAvc2StopVoiceDetection()
{
cellSysutilAvc2.todo("cellSysutilAvc2StopVoiceDetection()");
return CELL_OK;
}
error_code cellSysutilAvc2GetAttribute(vm::ptr<CellSysutilAvc2Attribute> attr)
{
cellSysutilAvc2.todo("cellSysutilAvc2GetAttribute(attr=*0x%x)", attr);
if (!attr)
return CELL_AVC2_ERROR_INVALID_ARGUMENT;
switch (attr->attr_id)
{
case CELL_SYSUTIL_AVC2_ATTRIBUTE_VOICE_DETECT_EVENT_TYPE:
break;
case CELL_SYSUTIL_AVC2_ATTRIBUTE_VOICE_DETECT_INTERVAL_TIME:
break;
case CELL_SYSUTIL_AVC2_ATTRIBUTE_VOICE_DETECT_SIGNAL_LEVEL:
break;
case CELL_SYSUTIL_AVC2_ATTRIBUTE_VOICE_MAX_BITRATE:
break;
case CELL_SYSUTIL_AVC2_ATTRIBUTE_VOICE_DATA_FEC:
break;
case CELL_SYSUTIL_AVC2_ATTRIBUTE_VOICE_PACKET_CONTENTION:
break;
case CELL_SYSUTIL_AVC2_ATTRIBUTE_VOICE_DTX_MODE:
break;
case CELL_SYSUTIL_AVC2_ATTRIBUTE_MIC_STATUS_DETECTION:
break;
case CELL_SYSUTIL_AVC2_ATTRIBUTE_MIC_SETTING_NOTIFICATION:
break;
case CELL_SYSUTIL_AVC2_ATTRIBUTE_VOICE_MUTING_NOTIFICATION:
break;
case CELL_SYSUTIL_AVC2_ATTRIBUTE_CAMERA_STATUS_DETECTION:
break;
default:
break;
}
return CELL_OK;
}
error_code cellSysutilAvc2SetSpeakerVolumeLevel(f32 level)
{
cellSysutilAvc2.todo("cellSysutilAvc2SetSpeakerVolumeLevel(level=0x%x)", level);
auto& settings = g_fxo->get<avc2_settings>();
settings.speaker_volume_level = level;
return CELL_OK;
}
error_code cellSysutilAvc2SetWindowString(SceNpMatching2RoomMemberId member_id, vm::cptr<char> string)
{
cellSysutilAvc2.todo("cellSysutilAvc2SetWindowString(member_id=0x%x, string=%s)", member_id, string);
if (!string || std::strlen(string.get_ptr()) >= 64)
return CELL_AVC2_ERROR_INVALID_ARGUMENT;
return CELL_OK;
}
error_code cellSysutilAvc2EstimateMemoryContainerSize(vm::cptr<CellSysutilAvc2InitParam> initparam, vm::ptr<u32> size)
{
cellSysutilAvc2.todo("cellSysutilAvc2EstimateMemoryContainerSize(initparam=*0x%x, size=*0x%x)", initparam, size);
if (!initparam || !size)
return CELL_AVC2_ERROR_INVALID_ARGUMENT;
switch (initparam->avc_init_param_version)
{
case 100:
{
*size = 0x400000;
break;
}
case 110:
case 120:
case 130:
case 140:
{
if (initparam->media_type == CELL_SYSUTIL_AVC2_VOICE_CHAT)
{
*size = 0x300000;
}
else if (initparam->media_type == CELL_SYSUTIL_AVC2_VIDEO_CHAT)
{
u32 estimated_size = 0x40e666;
u32 max_windows = initparam->video_param.max_video_windows;
s32 window_count = max_windows;
if (initparam->video_param.video_stream_sharing == CELL_SYSUTIL_AVC2_VIDEO_SHARING_MODE_2)
{
window_count++;
}
if (initparam->video_param.max_video_resolution == CELL_SYSUTIL_AVC2_VIDEO_RESOLUTION_QQVGA)
{
estimated_size = (static_cast<u32>(window_count) * 0x12c00 & 0xfff00000) + 0x50e666;
}
else if (initparam->video_param.max_video_resolution == CELL_SYSUTIL_AVC2_VIDEO_RESOLUTION_QVGA)
{
estimated_size += (static_cast<u32>(window_count) * 0x4b000 & 0xfff00000) + 0x100000;
}
if (initparam->video_param.frame_mode == CELL_SYSUTIL_AVC2_FRAME_MODE_NORMAL)
{
window_count = max_windows - 1;
}
else
{
window_count = 1;
}
u32 val = max_windows * 10000;
if (initparam->video_param.max_video_resolution == CELL_SYSUTIL_AVC2_VIDEO_RESOLUTION_QQVGA)
{
val += window_count * 0x96000 + 0x10c9e0; // 0x96000 = 160x120x32
}
else
{
val += static_cast<s32>(static_cast<f64>(window_count) * 1258291.2) + 0x1ed846;
}
estimated_size = ((estimated_size + ((static_cast<int>(val) >> 7) + static_cast<u32>(static_cast<int>(val) < 0 && (val & 0x7f) != 0)) * 0x80 + 0x80080) & 0xfff00000) + 0x100000;
*size = estimated_size;
}
else
{
*size = 0;
return CELL_AVC2_ERROR_INVALID_ARGUMENT;
}
break;
}
default:
{
return CELL_AVC2_ERROR_INVALID_ARGUMENT;
}
}
return CELL_OK;
}
error_code cellSysutilAvc2SetVideoMuting(u8 muting)
{
cellSysutilAvc2.todo("cellSysutilAvc2SetVideoMuting(muting=0x%x)", muting);
if (muting > 1) // Weird check, lol
return CELL_AVC2_ERROR_INVALID_ARGUMENT;
auto& settings = g_fxo->get<avc2_settings>();
settings.video_muting = muting;
return CELL_OK;
}
error_code cellSysutilAvc2SetPlayerVoiceMuting(SceNpMatching2RoomMemberId member_id, u8 muting)
{
cellSysutilAvc2.todo("cellSysutilAvc2SetPlayerVoiceMuting(member_id=0x%x, muting=0x%x)", member_id, muting);
auto& settings = g_fxo->get<avc2_settings>();
if (muting)
{
settings.voice_muting_players.insert(member_id);
}
else
{
settings.voice_muting_players.erase(member_id);
}
return CELL_OK;
}
error_code cellSysutilAvc2SetStreamingTarget(vm::cptr<CellSysutilAvc2StreamingTarget> target)
{
cellSysutilAvc2.todo("cellSysutilAvc2SetStreamingTarget(target=*0x%x)", target);
return CELL_OK;
}
error_code cellSysutilAvc2Unload()
{
cellSysutilAvc2.todo("cellSysutilAvc2Unload()");
auto& settings = g_fxo->get<avc2_settings>();
std::lock_guard lock(settings.mutex_cb);
if (!settings.avc2_cb)
{
return CELL_AVC2_ERROR_NOT_INITIALIZED;
}
sysutil_unregister_cb_with_id<avc2_cb_handle_t>();
settings.avc2_cb = vm::null;
settings.avc2_cb_arg = vm::null;
return CELL_OK;
}
error_code cellSysutilAvc2UnloadAsync()
{
cellSysutilAvc2.todo("cellSysutilAvc2UnloadAsync()");
auto& settings = g_fxo->get<avc2_settings>();
settings.register_cb_call(CELL_AVC2_EVENT_UNLOAD_SUCCEEDED, 0);
return CELL_OK;
}
error_code cellSysutilAvc2DestroyWindow(SceNpMatching2RoomMemberId member_id)
{
cellSysutilAvc2.todo("cellSysutilAvc2DestroyWindow(member_id=0x%x)", member_id);
return CELL_OK;
}
error_code cellSysutilAvc2SetWindowPosition(SceNpMatching2RoomMemberId member_id, f32 x, f32 y, f32 z)
{
cellSysutilAvc2.todo("cellSysutilAvc2SetWindowPosition(member_id=0x%x, x=0x%x, y=0x%x, z=0x%x)", member_id, x, y, z);
return CELL_OK;
}
error_code cellSysutilAvc2GetSpeakerVolumeLevel(vm::ptr<f32> level)
{
cellSysutilAvc2.todo("cellSysutilAvc2GetSpeakerVolumeLevel(level=*0x%x)", level);
if (!level)
return CELL_AVC2_ERROR_INVALID_ARGUMENT;
const auto& settings = g_fxo->get<avc2_settings>();
*level = settings.speaker_volume_level;
return CELL_OK;
}
error_code cellSysutilAvc2IsCameraAttached(vm::ptr<u8> status)
{
cellSysutilAvc2.todo("cellSysutilAvc2IsCameraAttached(status=*0x%x)", status);
if (!status)
return CELL_AVC2_ERROR_INVALID_ARGUMENT;
*status = CELL_AVC2_CAMERA_STATUS_DETACHED;
return CELL_OK;
}
error_code cellSysutilAvc2MicRead(vm::ptr<void> ptr, vm::ptr<u32> pSize)
{
cellSysutilAvc2.todo("cellSysutilAvc2MicRead(ptr=*0x%x, pSize=*0x%x)", ptr, pSize);
const auto& settings = g_fxo->get<avc2_settings>();
if (!settings.mic_out_stream_sharing)
return CELL_OK;
if (!ptr || !pSize)
{
// Not checked on real hardware
cellSysutilAvc2.warning("cellSysutilAvc2MicRead: ptr or pSize is null");
if (pSize)
{
*pSize = 0;
}
return CELL_OK;
}
// TODO: ringbuffer (holds 100ms of 16kHz single channel f32 samples)
std::vector<u8> buf{};
u32 size_read = 0;
if (u32 size_to_read = *pSize; size_to_read > 0 && !buf.empty())
{
size_read = std::min(size_to_read, ::size32(buf));
std::memcpy(ptr.get_ptr(), buf.data(), size_read);
}
*pSize = size_read;
return CELL_OK;
}
error_code cellSysutilAvc2GetPlayerVoiceMuting(SceNpMatching2RoomMemberId member_id, vm::ptr<u8> muting)
{
cellSysutilAvc2.todo("cellSysutilAvc2GetPlayerVoiceMuting(member_id=0x%x, muting=*0x%x)", member_id, muting);
if (!muting)
return CELL_AVC2_ERROR_INVALID_ARGUMENT;
const auto& settings = g_fxo->get<avc2_settings>();
*muting = settings.voice_muting_players.contains(member_id);
return CELL_OK;
}
error_code cellSysutilAvc2JoinChatRequest(vm::cptr<SceNpMatching2RoomId> room_id)
{
cellSysutilAvc2.warning("cellSysutilAvc2JoinChatRequest(room_id=*0x%x)", room_id);
// NOTE: room_id should be null if the current mode is Direct WAN/LAN
auto& settings = g_fxo->get<avc2_settings>();
[[maybe_unused]] u64 id = 0UL;
if (room_id)
{
id = *room_id;
}
else if (settings.streaming_mode != CELL_SYSUTIL_AVC2_STREAMING_MODE_NORMAL)
{
return CELL_AVC2_ERROR_INVALID_ARGUMENT;
}
// TODO: join chat
settings.register_cb_call(CELL_AVC2_EVENT_JOIN_SUCCEEDED, 0);
return CELL_OK;
}
error_code cellSysutilAvc2StartStreaming()
{
cellSysutilAvc2.todo("cellSysutilAvc2StartStreaming()");
return CELL_OK;
}
error_code cellSysutilAvc2SetWindowAttribute(SceNpMatching2RoomMemberId member_id, vm::cptr<CellSysutilAvc2WindowAttribute> attr)
{
cellSysutilAvc2.todo("cellSysutilAvc2SetWindowAttribute(member_id=0x%x, attr=*0x%x)", member_id, attr);
if (!attr)
return CELL_AVC2_ERROR_INVALID_ARGUMENT;
switch (attr->attr_id)
{
case CELL_SYSUTIL_AVC2_WINDOW_ATTRIBUTE_ALPHA:
break;
case CELL_SYSUTIL_AVC2_WINDOW_ATTRIBUTE_TRANSITION_TYPE:
break;
case CELL_SYSUTIL_AVC2_WINDOW_ATTRIBUTE_TRANSITION_DURATION:
break;
case CELL_SYSUTIL_AVC2_WINDOW_ATTRIBUTE_STRING_VISIBLE:
break;
case CELL_SYSUTIL_AVC2_WINDOW_ATTRIBUTE_ROTATION:
break;
case CELL_SYSUTIL_AVC2_WINDOW_ATTRIBUTE_ZORDER:
break;
case CELL_SYSUTIL_AVC2_WINDOW_ATTRIBUTE_SURFACE:
break;
default:
break;
}
return CELL_OK;
}
error_code cellSysutilAvc2GetWindowShowStatus(SceNpMatching2RoomMemberId member_id, vm::ptr<u8> visible)
{
cellSysutilAvc2.todo("cellSysutilAvc2GetWindowShowStatus(member_id=0x%x, visible=*0x%x)", member_id, visible);
if (!visible)
return CELL_AVC2_ERROR_INVALID_ARGUMENT;
*visible = 0;
return CELL_OK;
}
error_code cellSysutilAvc2InitParam(u16 version, vm::ptr<CellSysutilAvc2InitParam> option)
{
cellSysutilAvc2.todo("cellSysutilAvc2InitParam(version=%d, option=*0x%x)", version, option);
if (!option)
return CELL_AVC2_ERROR_INVALID_ARGUMENT;
*option = {};
option->avc_init_param_version = version;
switch (version)
{
case 100:
case 110:
case 120:
case 130:
case 140:
break;
default:
return CELL_AVC2_ERROR_INVALID_ARGUMENT;
}
return CELL_OK;
}
error_code cellSysutilAvc2GetWindowSize(SceNpMatching2RoomMemberId member_id, vm::ptr<f32> width, vm::ptr<f32> height)
{
cellSysutilAvc2.todo("cellSysutilAvc2GetWindowSize(member_id=0x%x, width=*0x%x, height=*0x%x)", member_id, width, height);
if (!width || !height)
return CELL_AVC2_ERROR_INVALID_ARGUMENT;
return CELL_OK;
}
error_code cellSysutilAvc2SetStreamPriority(u8 priority)
{
cellSysutilAvc2.todo("cellSysutilAvc2SetStreamPriority(priority=0x%x)", priority);
return CELL_OK;
}
error_code cellSysutilAvc2LeaveChatRequest()
{
cellSysutilAvc2.notice("cellSysutilAvc2LeaveChatRequest()");
auto& settings = g_fxo->get<avc2_settings>();
settings.register_cb_call(CELL_AVC2_EVENT_LEAVE_SUCCEEDED, 0);
return CELL_OK;
}
error_code cellSysutilAvc2IsMicAttached(vm::ptr<u8> status)
{
cellSysutilAvc2.todo("cellSysutilAvc2IsMicAttached(status=*0x%x)", status);
ensure(!!status); // I couldn't find any error value for this (should be CELL_AVC2_ERROR_INVALID_ARGUMENT if anything)
*status = CELL_AVC2_MIC_STATUS_DETACHED;
return CELL_OK;
}
error_code cellSysutilAvc2CreateWindow(SceNpMatching2RoomMemberId member_id)
{
cellSysutilAvc2.todo("cellSysutilAvc2CreateWindow(member_id=0x%x)", member_id);
return CELL_OK;
}
error_code cellSysutilAvc2GetSpeakerMuting(vm::ptr<u8> muting)
{
cellSysutilAvc2.todo("cellSysutilAvc2GetSpeakerMuting(muting=*0x%x)", muting);
if (!muting)
return CELL_AVC2_ERROR_INVALID_ARGUMENT;
const auto& settings = g_fxo->get<avc2_settings>();
*muting = settings.speaker_muting;
return CELL_OK;
}
error_code cellSysutilAvc2ShowWindow(SceNpMatching2RoomMemberId member_id)
{
cellSysutilAvc2.todo("cellSysutilAvc2ShowWindow(member_id=0x%x)", member_id);
return CELL_OK;
}
error_code cellSysutilAvc2SetWindowSize(SceNpMatching2RoomMemberId member_id, f32 width, f32 height)
{
cellSysutilAvc2.todo("cellSysutilAvc2SetWindowSize(member_id=0x%x, width=0x%x, height=0x%x)", member_id, width, height);
return CELL_OK;
}
error_code cellSysutilAvc2EnumPlayers(vm::ptr<s32> players_num, vm::ptr<SceNpMatching2RoomMemberId> players_id)
{
cellSysutilAvc2.todo("cellSysutilAvc2EnumPlayers(players_num=*0x%x, players_id=*0x%x)", players_num, players_id);
if (!players_num)
return CELL_AVC2_ERROR_INVALID_ARGUMENT;
// Apparently this function is supposed to be called twice.
// Once with null to get the player count and then again to fill the ID list.
if (players_id)
{
for (int i = 0; i < *players_num; i++)
{
players_id[i] = i + 1;
}
}
else
{
*players_num = 1;
}
return CELL_OK;
}
error_code cellSysutilAvc2GetWindowString(SceNpMatching2RoomMemberId member_id, vm::ptr<char> string, vm::ptr<u8> len)
{
cellSysutilAvc2.todo("cellSysutilAvc2GetWindowString(member_id=0x%x, string=*0x%x, len=*0x%x)", member_id, string, len);
if (!string || !len)
return CELL_AVC2_ERROR_INVALID_ARGUMENT;
return CELL_OK;
}
error_code cellSysutilAvc2LeaveChat()
{
cellSysutilAvc2.todo("cellSysutilAvc2LeaveChat()");
return CELL_OK;
}
error_code cellSysutilAvc2SetSpeakerMuting(u8 muting)
{
cellSysutilAvc2.todo("cellSysutilAvc2SetSpeakerMuting(muting=0x%x)", muting);
auto& settings = g_fxo->get<avc2_settings>();
settings.speaker_muting = muting;
return CELL_OK;
}
error_code cellSysutilAvc2Load_shared(SceNpMatching2ContextId /*ctx_id*/, u32 /*container*/, vm::ptr<CellSysutilAvc2Callback> callback_func, vm::ptr<void> user_data, vm::cptr<CellSysutilAvc2InitParam> init_param)
{
if (!init_param || !init_param->avc_init_param_version ||
!(init_param->avc_init_param_version == 100 ||
init_param->avc_init_param_version == 110 ||
init_param->avc_init_param_version == 120 ||
init_param->avc_init_param_version == 130 ||
init_param->avc_init_param_version == 140)
)
{
return CELL_AVC2_ERROR_INVALID_ARGUMENT;
}
auto& settings = g_fxo->get<avc2_settings>();
switch (init_param->media_type)
{
case CELL_SYSUTIL_AVC2_VOICE_CHAT:
{
if (init_param->max_players < 2 ||
init_param->max_players > 64 ||
init_param->spu_load_average > 100 ||
init_param->voice_param.voice_quality != CELL_SYSUTIL_AVC2_VOICE_QUALITY_NORMAL ||
init_param->voice_param.max_speakers == 0 ||
init_param->voice_param.max_speakers > 16
)
{
return CELL_AVC2_ERROR_INVALID_ARGUMENT;
}
u32 streaming_mode = init_param->direct_streaming_mode;
if (init_param->avc_init_param_version >= 120)
{
switch (init_param->direct_streaming_mode)
{
case CELL_SYSUTIL_AVC2_STREAMING_MODE_NORMAL:
streaming_mode = CELL_SYSUTIL_AVC2_STREAMING_MODE_NORMAL;
break;
case CELL_SYSUTIL_AVC2_STREAMING_MODE_DIRECT_WAN:
break;
case CELL_SYSUTIL_AVC2_STREAMING_MODE_DIRECT_LAN:
if (init_param->streaming_mode.mode == CELL_SYSUTIL_AVC2_STREAMING_MODE_NORMAL)
{
settings.streaming_mode = streaming_mode;
return CELL_AVC2_ERROR_INVALID_ARGUMENT;
}
break;
default:
return CELL_AVC2_ERROR_INVALID_ARGUMENT;
}
}
else if (init_param->avc_init_param_version >= 110)
{
switch (init_param->direct_streaming_mode)
{
case CELL_SYSUTIL_AVC2_STREAMING_MODE_NORMAL:
case CELL_SYSUTIL_AVC2_STREAMING_MODE_DIRECT_WAN:
break;
case CELL_SYSUTIL_AVC2_STREAMING_MODE_DIRECT_LAN:
default:
return CELL_AVC2_ERROR_INVALID_ARGUMENT;
}
}
else
{
streaming_mode = settings.streaming_mode;
}
settings.streaming_mode = streaming_mode;
settings.mic_out_stream_sharing = init_param->voice_param.mic_out_stream_sharing;
if (!callback_func)
{
return CELL_AVC2_ERROR_INVALID_ARGUMENT;
}
std::lock_guard lock(settings.mutex_cb);
if (settings.avc2_cb)
{
return CELL_AVC2_ERROR_ALREADY_INITIALIZED;
}
settings.avc2_cb = callback_func;
settings.avc2_cb_arg = user_data;
break;
}
case CELL_SYSUTIL_AVC2_VIDEO_CHAT:
{
if (false) // TODO: syscall to check container
{
return CELL_AVC2_ERROR_INVALID_ARGUMENT;
}
if (init_param->avc_init_param_version <= 140)
{
if (false) // TODO
{
return CELL_AVC2_ERROR_OUT_OF_MEMORY;
}
}
if (callback_func)
{
return CELL_AVC2_ERROR_INVALID_ARGUMENT;
}
if (init_param->video_param.max_video_windows == 0 ||
init_param->video_param.max_video_windows > (init_param->video_param.frame_mode == CELL_SYSUTIL_AVC2_FRAME_MODE_NORMAL ? 6 : 16))
{
return CELL_AVC2_ERROR_INVALID_ARGUMENT;
}
if (init_param->video_param.max_video_bitrate < 1000 || init_param->video_param.max_video_bitrate > 512000)
{
return CELL_AVC2_ERROR_INVALID_ARGUMENT;
}
if (init_param->video_param.max_video_framerate == 0 || init_param->video_param.max_video_framerate > 30)
{
return CELL_AVC2_ERROR_INVALID_ARGUMENT;
}
s32 bitrate = 0;
switch (init_param->video_param.max_video_resolution)
{
case CELL_SYSUTIL_AVC2_VIDEO_RESOLUTION_QQVGA:
bitrate = 76800;
break;
case CELL_SYSUTIL_AVC2_VIDEO_RESOLUTION_QVGA:
bitrate = 307200;
break;
default:
break;
}
u32 total_bitrate = 0;
if (bitrate != 0)
{
u32 window_count = init_param->video_param.max_video_windows;
if (init_param->video_param.video_stream_sharing == CELL_SYSUTIL_AVC2_VIDEO_SHARING_MODE_2)
{
window_count++;
}
total_bitrate = utils::align<u32>(window_count * bitrate, 0x100000) + 0x100000;
}
settings.video_stream_sharing = init_param->video_param.video_stream_sharing;
settings.total_video_bitrate = total_bitrate;
break;
}
default:
return CELL_AVC2_ERROR_NOT_SUPPORTED;
}
return CELL_OK;
}
error_code cellSysutilAvc2Load(SceNpMatching2ContextId ctx_id, u32 container, vm::ptr<CellSysutilAvc2Callback> callback_func, vm::ptr<void> user_data, vm::cptr<CellSysutilAvc2InitParam> init_param)
{
cellSysutilAvc2.warning("cellSysutilAvc2Load(ctx_id=0x%x, container=0x%x, callback_func=*0x%x, user_data=*0x%x, init_param=*0x%x)", ctx_id, container, callback_func, user_data, init_param);
error_code error = cellSysutilAvc2Load_shared(ctx_id, container, callback_func, user_data, init_param);
if (error != CELL_OK)
return error;
return CELL_OK;
}
error_code cellSysutilAvc2LoadAsync(SceNpMatching2ContextId ctx_id, u32 container, vm::ptr<CellSysutilAvc2Callback> callback_func, vm::ptr<void> user_data, vm::cptr<CellSysutilAvc2InitParam> init_param)
{
cellSysutilAvc2.warning("cellSysutilAvc2LoadAsync(ctx_id=0x%x, container=0x%x, callback_func=*0x%x, user_data=*0x%x, init_param=*0x%x)", ctx_id, container, callback_func, user_data, init_param);
error_code error = cellSysutilAvc2Load_shared(ctx_id, container, callback_func, user_data, init_param);
if (error != CELL_OK)
return error;
auto& settings = g_fxo->get<avc2_settings>();
settings.register_cb_call(CELL_AVC2_EVENT_LOAD_SUCCEEDED, 0);
return CELL_OK;
}
error_code cellSysutilAvc2SetAttribute(vm::cptr<CellSysutilAvc2Attribute> attr)
{
if (!attr)
{
cellSysutilAvc2.todo("cellSysutilAvc2SetAttribute(attr=*0x%x)", attr);
return CELL_AVC2_ERROR_INVALID_ARGUMENT;
}
cellSysutilAvc2.todo("cellSysutilAvc2SetAttribute(%s=%d)", attr->attr_id, attr->attr_param.int_param);
switch (attr->attr_id)
{
case CELL_SYSUTIL_AVC2_ATTRIBUTE_VOICE_DETECT_EVENT_TYPE:
break;
case CELL_SYSUTIL_AVC2_ATTRIBUTE_VOICE_DETECT_INTERVAL_TIME:
break;
case CELL_SYSUTIL_AVC2_ATTRIBUTE_VOICE_DETECT_SIGNAL_LEVEL:
break;
case CELL_SYSUTIL_AVC2_ATTRIBUTE_VOICE_MAX_BITRATE:
break;
case CELL_SYSUTIL_AVC2_ATTRIBUTE_VOICE_DATA_FEC:
break;
case CELL_SYSUTIL_AVC2_ATTRIBUTE_VOICE_PACKET_CONTENTION:
break;
case CELL_SYSUTIL_AVC2_ATTRIBUTE_VOICE_DTX_MODE:
break;
case CELL_SYSUTIL_AVC2_ATTRIBUTE_MIC_STATUS_DETECTION:
break;
case CELL_SYSUTIL_AVC2_ATTRIBUTE_MIC_SETTING_NOTIFICATION:
break;
case CELL_SYSUTIL_AVC2_ATTRIBUTE_VOICE_MUTING_NOTIFICATION:
break;
case CELL_SYSUTIL_AVC2_ATTRIBUTE_CAMERA_STATUS_DETECTION:
break;
default:
break;
}
return CELL_OK;
}
error_code cellSysutilAvc2Unload2(u32 mediaType)
{
cellSysutilAvc2.todo("cellSysutilAvc2Unload2(mediaType=0x%x)", mediaType);
auto& settings = g_fxo->get<avc2_settings>();
switch (mediaType)
{
case CELL_SYSUTIL_AVC2_VOICE_CHAT:
{
std::lock_guard lock(settings.mutex_cb);
if (!settings.avc2_cb)
{
return CELL_AVC2_ERROR_NOT_INITIALIZED;
}
// TODO: return error if the video chat is still loaded (probably CELL_AVC2_ERROR_INVALID_STATUS)
sysutil_unregister_cb_with_id<avc2_cb_handle_t>();
settings.avc2_cb = vm::null;
settings.avc2_cb_arg = vm::null;
break;
}
case CELL_SYSUTIL_AVC2_VIDEO_CHAT:
{
// TODO
break;
}
default:
return CELL_AVC2_ERROR_INVALID_ARGUMENT;
}
return CELL_OK;
}
error_code cellSysutilAvc2UnloadAsync2(u32 mediaType)
{
cellSysutilAvc2.todo("cellSysutilAvc2UnloadAsync2(mediaType=0x%x)", mediaType);
if (mediaType != CELL_SYSUTIL_AVC2_VOICE_CHAT && mediaType != CELL_SYSUTIL_AVC2_VIDEO_CHAT)
return CELL_AVC2_ERROR_INVALID_ARGUMENT;
auto& settings = g_fxo->get<avc2_settings>();
if (mediaType == CELL_SYSUTIL_AVC2_VOICE_CHAT)
settings.register_cb_call(CELL_AVC2_EVENT_UNLOAD_SUCCEEDED, 0);
else
settings.register_cb_call(CELL_AVC2_EVENT_UNLOAD_SUCCEEDED, 2);
return CELL_OK;
}
error_code cellSysutilAvc2StartStreaming2(u32 mediaType)
{
cellSysutilAvc2.todo("cellSysutilAvc2StartStreaming2(mediaType=0x%x)", mediaType);
if (mediaType != CELL_SYSUTIL_AVC2_VOICE_CHAT && mediaType != CELL_SYSUTIL_AVC2_VIDEO_CHAT)
return CELL_AVC2_ERROR_INVALID_ARGUMENT;
return CELL_OK;
}
error_code cellSysutilAvc2HideScreen()
{
cellSysutilAvc2.todo("cellSysutilAvc2HideScreen()");
return CELL_OK;
}
error_code cellSysutilAvc2HideWindow(SceNpMatching2RoomMemberId member_id)
{
cellSysutilAvc2.todo("cellSysutilAvc2HideWindow(member_id=0x%x)", member_id);
return CELL_OK;
}
error_code cellSysutilAvc2GetVoiceMuting(vm::ptr<u8> muting)
{
cellSysutilAvc2.todo("cellSysutilAvc2GetVoiceMuting(muting=*0x%x)", muting);
if (!muting)
return CELL_AVC2_ERROR_INVALID_ARGUMENT;
const auto& settings = g_fxo->get<avc2_settings>();
*muting = settings.voice_muting;
return CELL_OK;
}
error_code cellSysutilAvc2GetScreenShowStatus(vm::ptr<u8> visible)
{
cellSysutilAvc2.todo("cellSysutilAvc2GetScreenShowStatus(visible=*0x%x)", visible);
if (!visible)
return CELL_AVC2_ERROR_INVALID_ARGUMENT;
*visible = 0;
return CELL_OK;
}
error_code cellSysutilAvc2GetWindowPosition(SceNpMatching2RoomMemberId member_id, vm::ptr<f32> x, vm::ptr<f32> y, vm::ptr<f32> z)
{
cellSysutilAvc2.todo("cellSysutilAvc2GetWindowPosition(member_id=0x%x, x=*0x%x, y=*0x%x, z=*0x%x)", member_id, x, y, z);
if (!x || !y || !z)
return CELL_AVC2_ERROR_INVALID_ARGUMENT;
return CELL_OK;
}
DECLARE(ppu_module_manager::cellSysutilAvc2)("cellSysutilAvc2", []()
{
REG_FUNC(cellSysutilAvc2, cellSysutilAvc2GetPlayerInfo);
REG_FUNC(cellSysutilAvc2, cellSysutilAvc2JoinChat);
REG_FUNC(cellSysutilAvc2, cellSysutilAvc2StopStreaming);
REG_FUNC(cellSysutilAvc2, cellSysutilAvc2ChangeVideoResolution);
REG_FUNC(cellSysutilAvc2, cellSysutilAvc2ShowScreen);
REG_FUNC(cellSysutilAvc2, cellSysutilAvc2GetVideoMuting);
REG_FUNC(cellSysutilAvc2, cellSysutilAvc2GetWindowAttribute);
REG_FUNC(cellSysutilAvc2, cellSysutilAvc2StopStreaming2);
REG_FUNC(cellSysutilAvc2, cellSysutilAvc2SetVoiceMuting);
REG_FUNC(cellSysutilAvc2, cellSysutilAvc2StartVoiceDetection);
REG_FUNC(cellSysutilAvc2, cellSysutilAvc2UnloadAsync);
REG_FUNC(cellSysutilAvc2, cellSysutilAvc2StopVoiceDetection);
REG_FUNC(cellSysutilAvc2, cellSysutilAvc2GetAttribute);
REG_FUNC(cellSysutilAvc2, cellSysutilAvc2LoadAsync);
REG_FUNC(cellSysutilAvc2, cellSysutilAvc2SetSpeakerVolumeLevel);
REG_FUNC(cellSysutilAvc2, cellSysutilAvc2SetWindowString);
REG_FUNC(cellSysutilAvc2, cellSysutilAvc2EstimateMemoryContainerSize);
REG_FUNC(cellSysutilAvc2, cellSysutilAvc2SetVideoMuting);
REG_FUNC(cellSysutilAvc2, cellSysutilAvc2SetPlayerVoiceMuting);
REG_FUNC(cellSysutilAvc2, cellSysutilAvc2SetStreamingTarget);
REG_FUNC(cellSysutilAvc2, cellSysutilAvc2Unload);
REG_FUNC(cellSysutilAvc2, cellSysutilAvc2DestroyWindow);
REG_FUNC(cellSysutilAvc2, cellSysutilAvc2SetWindowPosition);
REG_FUNC(cellSysutilAvc2, cellSysutilAvc2GetSpeakerVolumeLevel);
REG_FUNC(cellSysutilAvc2, cellSysutilAvc2IsCameraAttached);
REG_FUNC(cellSysutilAvc2, cellSysutilAvc2MicRead);
REG_FUNC(cellSysutilAvc2, cellSysutilAvc2GetPlayerVoiceMuting);
REG_FUNC(cellSysutilAvc2, cellSysutilAvc2JoinChatRequest);
REG_FUNC(cellSysutilAvc2, cellSysutilAvc2StartStreaming);
REG_FUNC(cellSysutilAvc2, cellSysutilAvc2SetWindowAttribute);
REG_FUNC(cellSysutilAvc2, cellSysutilAvc2GetWindowShowStatus);
REG_FUNC(cellSysutilAvc2, cellSysutilAvc2InitParam);
REG_FUNC(cellSysutilAvc2, cellSysutilAvc2GetWindowSize);
REG_FUNC(cellSysutilAvc2, cellSysutilAvc2SetStreamPriority);
REG_FUNC(cellSysutilAvc2, cellSysutilAvc2LeaveChatRequest);
REG_FUNC(cellSysutilAvc2, cellSysutilAvc2IsMicAttached);
REG_FUNC(cellSysutilAvc2, cellSysutilAvc2CreateWindow);
REG_FUNC(cellSysutilAvc2, cellSysutilAvc2GetSpeakerMuting);
REG_FUNC(cellSysutilAvc2, cellSysutilAvc2ShowWindow);
REG_FUNC(cellSysutilAvc2, cellSysutilAvc2SetWindowSize);
REG_FUNC(cellSysutilAvc2, cellSysutilAvc2EnumPlayers);
REG_FUNC(cellSysutilAvc2, cellSysutilAvc2GetWindowString);
REG_FUNC(cellSysutilAvc2, cellSysutilAvc2LeaveChat);
REG_FUNC(cellSysutilAvc2, cellSysutilAvc2SetSpeakerMuting);
REG_FUNC(cellSysutilAvc2, cellSysutilAvc2Load);
REG_FUNC(cellSysutilAvc2, cellSysutilAvc2SetAttribute);
REG_FUNC(cellSysutilAvc2, cellSysutilAvc2UnloadAsync2);
REG_FUNC(cellSysutilAvc2, cellSysutilAvc2StartStreaming2);
REG_FUNC(cellSysutilAvc2, cellSysutilAvc2HideScreen);
REG_FUNC(cellSysutilAvc2, cellSysutilAvc2HideWindow);
REG_FUNC(cellSysutilAvc2, cellSysutilAvc2GetVoiceMuting);
REG_FUNC(cellSysutilAvc2, cellSysutilAvc2GetScreenShowStatus);
REG_FUNC(cellSysutilAvc2, cellSysutilAvc2Unload2);
REG_FUNC(cellSysutilAvc2, cellSysutilAvc2GetWindowPosition);
});
| 33,330
|
C++
|
.cpp
| 962
| 31.980249
| 212
| 0.767637
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
5,211
|
cellSysutil.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellSysutil.cpp
|
#include "stdafx.h"
#include "Emu/System.h"
#include "Emu/system_config.h"
#include "Emu/IdManager.h"
#include "Emu/VFS.h"
#include "Emu/Cell/PPUModule.h"
#include "Emu/Cell/Modules/cellGame.h"
#include "Emu/Cell/lv2/sys_game.h"
#include "Emu/Cell/lv2/sys_process.h"
#include "cellSysutil.h"
#include "Utilities/StrUtil.h"
#include "Utilities/lockless.h"
#include <span>
#include <deque>
LOG_CHANNEL(cellSysutil);
template<>
void fmt_class_string<CellSysutilError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_SYSUTIL_ERROR_TYPE);
STR_CASE(CELL_SYSUTIL_ERROR_VALUE);
STR_CASE(CELL_SYSUTIL_ERROR_SIZE);
STR_CASE(CELL_SYSUTIL_ERROR_NUM);
STR_CASE(CELL_SYSUTIL_ERROR_BUSY);
STR_CASE(CELL_SYSUTIL_ERROR_STATUS);
STR_CASE(CELL_SYSUTIL_ERROR_MEMORY);
STR_CASE(CELL_SYSUTIL_ERROR_3D_SUPPORT);
}
return unknown;
});
}
template<>
void fmt_class_string<CellBgmplaybackError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_SYSUTIL_BGMPLAYBACK_ERROR_PARAM);
STR_CASE(CELL_SYSUTIL_BGMPLAYBACK_ERROR_BUSY);
STR_CASE(CELL_SYSUTIL_BGMPLAYBACK_ERROR_GENERIC);
STR_CASE(CELL_SYSUTIL_BGMPLAYBACK_EX_ERROR_PARAM);
STR_CASE(CELL_SYSUTIL_BGMPLAYBACK_EX_ERROR_ALREADY_SETPARAM);
STR_CASE(CELL_SYSUTIL_BGMPLAYBACK_EX_ERROR_DISABLE_SETPARAM);
STR_CASE(CELL_SYSUTIL_BGMPLAYBACK_EX_ERROR_GENERIC);
}
return unknown;
});
}
atomic_t<usz> g_sysutil_callback_id_assigner = 0;
struct sysutil_cb_manager
{
struct alignas(8) registered_dispatcher
{
u32 event_code = 0;
u32 func_addr = 0;
};
std::array<atomic_t<registered_dispatcher>, 32> dispatchers{};
struct alignas(8) registered_cb
{
ENABLE_BITWISE_SERIALIZATION;
vm::ptr<CellSysutilCallback> callback;
vm::ptr<void> user_data;
};
atomic_t<registered_cb> callbacks[4]{};
struct dispatcher_cb
{
std::function<s32(ppu_thread&)> func;
std::shared_ptr<atomic_t<bool>> call_active;
};
std::deque<lf_queue<std::shared_ptr<atomic_t<bool>>>> registered_callbacks_abort_handles = []()
{
// Do resize for deque (cheap container which can store all non-movable value types)
std::deque<lf_queue<std::shared_ptr<atomic_t<bool>>>> result;
for (usz i = 0 ; i < g_sysutil_callback_id_assigner; i++)
{
result.emplace_back();
}
return result;
}();
lf_queue<dispatcher_cb> registered;
atomic_t<bool> draw_cb_started{};
atomic_t<u64> read_counter{0};
SAVESTATE_INIT_POS(13);
sysutil_cb_manager() = default;
sysutil_cb_manager(utils::serial& ar)
{
ar(callbacks);
}
void save(utils::serial& ar)
{
ensure(!registered);
ar(callbacks);
}
};
void sysutil_register_cb_with_id_internal(std::function<s32(ppu_thread&)>&& cb, usz call_id)
{
auto& cbm = *ensure(g_fxo->try_get<sysutil_cb_manager>());
sysutil_cb_manager::dispatcher_cb info{std::move(cb)};
if (call_id != umax)
{
info.call_active = std::make_shared<atomic_t<bool>>(true);
::at32(cbm.registered_callbacks_abort_handles, call_id).push(info.call_active);
}
cbm.registered.push(std::move(info));
}
extern void sysutil_unregister_cb_with_id_internal(usz call_id)
{
const auto cbm = g_fxo->try_get<sysutil_cb_manager>();
if (!cbm)
{
return;
}
for (auto&& abort_handle : ::at32(cbm->registered_callbacks_abort_handles, call_id).pop_all())
{
// Deactivate the existing event once
abort_handle->store(false);
}
}
extern void sysutil_register_cb(std::function<s32(ppu_thread&)>&& cb)
{
sysutil_register_cb_with_id_internal(std::move(cb), umax);
}
extern s32 sysutil_send_system_cmd(u64 status, u64 param)
{
s32 count = 0;
if (auto cbm = g_fxo->try_get<sysutil_cb_manager>())
{
if (status == CELL_SYSUTIL_DRAWING_BEGIN)
{
if (cbm->draw_cb_started.exchange(true))
{
cellSysutil.error("Tried to enqueue a second or more DRAWING_BEGIN callback!");
return CELL_SYSUTIL_ERROR_BUSY;
}
}
else if (status == CELL_SYSUTIL_DRAWING_END)
{
if (!cbm->draw_cb_started.exchange(false))
{
cellSysutil.error("Tried to enqueue a DRAWING_END callback without a BEGIN callback!");
return -1;
}
}
else if (status == CELL_SYSUTIL_REQUEST_EXITGAME)
{
abort_lv2_watchdog();
}
for (sysutil_cb_manager::registered_cb cb : cbm->callbacks)
{
if (cb.callback)
{
cbm->registered.push(sysutil_cb_manager::dispatcher_cb{[=](ppu_thread& ppu) -> s32
{
// TODO: check it and find the source of the return value (void isn't equal to CELL_OK)
cb.callback(ppu, status, param, cb.user_data);
return CELL_OK;
}});
count++;
}
}
}
return count;
}
extern u64 get_sysutil_cb_manager_read_count()
{
if (auto cbm = g_fxo->try_get<sysutil_cb_manager>())
{
return cbm->read_counter;
}
return 0;
}
extern bool send_open_home_menu_cmds()
{
auto status = g_fxo->try_get<SysutilMenuOpenStatus>();
if (!status || status->active)
{
return false;
}
// TODO: handle CELL_SYSUTIL_BGMPLAYBACK_STATUS_DISABLE
if (sysutil_send_system_cmd(CELL_SYSUTIL_DRAWING_BEGIN, 0) < 0 ||
sysutil_send_system_cmd(CELL_SYSUTIL_SYSTEM_MENU_OPEN, 0) < 0 ||
sysutil_send_system_cmd(CELL_SYSUTIL_BGMPLAYBACK_PLAY, 0) < 0)
{
return false;
}
status->active = true;
return true;
}
extern void send_close_home_menu_cmds()
{
auto status = g_fxo->try_get<SysutilMenuOpenStatus>();
if (!status || !status->active)
{
return;
}
// TODO: handle CELL_SYSUTIL_BGMPLAYBACK_STATUS_DISABLE
sysutil_send_system_cmd(CELL_SYSUTIL_BGMPLAYBACK_STOP, 0);
sysutil_send_system_cmd(CELL_SYSUTIL_SYSTEM_MENU_CLOSE, 0);
sysutil_send_system_cmd(CELL_SYSUTIL_DRAWING_END, 0);
status->active = false;
}
template <>
void fmt_class_string<CellSysutilLang>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](CellSysutilLang value)
{
switch (value)
{
case CELL_SYSUTIL_LANG_JAPANESE: return "Japanese";
case CELL_SYSUTIL_LANG_ENGLISH_US: return "English (US)";
case CELL_SYSUTIL_LANG_FRENCH: return "French";
case CELL_SYSUTIL_LANG_SPANISH: return "Spanish";
case CELL_SYSUTIL_LANG_GERMAN: return "German";
case CELL_SYSUTIL_LANG_ITALIAN: return "Italian";
case CELL_SYSUTIL_LANG_DUTCH: return "Dutch";
case CELL_SYSUTIL_LANG_PORTUGUESE_PT: return "Portuguese (Portugal)";
case CELL_SYSUTIL_LANG_RUSSIAN: return "Russian";
case CELL_SYSUTIL_LANG_KOREAN: return "Korean";
case CELL_SYSUTIL_LANG_CHINESE_T: return "Chinese (Traditional)";
case CELL_SYSUTIL_LANG_CHINESE_S: return "Chinese (Simplified)";
case CELL_SYSUTIL_LANG_FINNISH: return "Finnish";
case CELL_SYSUTIL_LANG_SWEDISH: return "Swedish";
case CELL_SYSUTIL_LANG_DANISH: return "Danish";
case CELL_SYSUTIL_LANG_NORWEGIAN: return "Norwegian";
case CELL_SYSUTIL_LANG_POLISH: return "Polish";
case CELL_SYSUTIL_LANG_ENGLISH_GB: return "English (UK)";
case CELL_SYSUTIL_LANG_PORTUGUESE_BR: return "Portuguese (Brazil)";
case CELL_SYSUTIL_LANG_TURKISH: return "Turkish";
}
return unknown;
});
}
template <>
void fmt_class_string<CellSysutilLicenseArea>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](CellSysutilLicenseArea value)
{
switch (value)
{
case CELL_SYSUTIL_LICENSE_AREA_J: return "SCEJ";
case CELL_SYSUTIL_LICENSE_AREA_A: return "SCEA";
case CELL_SYSUTIL_LICENSE_AREA_E: return "SCEE";
case CELL_SYSUTIL_LICENSE_AREA_H: return "SCEH";
case CELL_SYSUTIL_LICENSE_AREA_K: return "SCEK";
case CELL_SYSUTIL_LICENSE_AREA_C: return "SCH";
case CELL_SYSUTIL_LICENSE_AREA_OTHER: return "Other";
}
return unknown;
});
}
template <>
void fmt_class_string<CellSysutilParamId>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto value)
{
switch (value)
{
case CELL_SYSUTIL_SYSTEMPARAM_ID_LANG: return "ID_LANG";
case CELL_SYSUTIL_SYSTEMPARAM_ID_ENTER_BUTTON_ASSIGN: return "ID_ENTER_BUTTON_ASSIGN";
case CELL_SYSUTIL_SYSTEMPARAM_ID_DATE_FORMAT: return "ID_DATE_FORMAT";
case CELL_SYSUTIL_SYSTEMPARAM_ID_TIME_FORMAT: return "ID_TIME_FORMAT";
case CELL_SYSUTIL_SYSTEMPARAM_ID_TIMEZONE: return "ID_TIMEZONE";
case CELL_SYSUTIL_SYSTEMPARAM_ID_SUMMERTIME: return "ID_SUMMERTIME";
case CELL_SYSUTIL_SYSTEMPARAM_ID_GAME_PARENTAL_LEVEL: return "ID_GAME_PARENTAL_LEVEL";
case CELL_SYSUTIL_SYSTEMPARAM_ID_LICENSE_AREA: return "ID_LICENSE_AREA";
case CELL_SYSUTIL_SYSTEMPARAM_ID_GAME_PARENTAL_LEVEL0_RESTRICT: return "ID_GAME_PARENTAL_LEVEL0_RESTRICT";
case CELL_SYSUTIL_SYSTEMPARAM_ID_CURRENT_USER_HAS_NP_ACCOUNT: return "ID_CURRENT_USER_HAS_NP_ACCOUNT";
case CELL_SYSUTIL_SYSTEMPARAM_ID_CAMERA_PLFREQ: return "ID_CAMERA_PLFREQ";
case CELL_SYSUTIL_SYSTEMPARAM_ID_PAD_RUMBLE: return "ID_PAD_RUMBLE";
case CELL_SYSUTIL_SYSTEMPARAM_ID_KEYBOARD_TYPE: return "ID_KEYBOARD_TYPE";
case CELL_SYSUTIL_SYSTEMPARAM_ID_JAPANESE_KEYBOARD_ENTRY_METHOD: return "ID_JAPANESE_KEYBOARD_ENTRY_METHOD";
case CELL_SYSUTIL_SYSTEMPARAM_ID_CHINESE_KEYBOARD_ENTRY_METHOD: return "ID_CHINESE_KEYBOARD_ENTRY_METHOD";
case CELL_SYSUTIL_SYSTEMPARAM_ID_PAD_AUTOOFF: return "ID_PAD_AUTOOFF";
case CELL_SYSUTIL_SYSTEMPARAM_ID_MAGNETOMETER: return "ID_MAGNETOMETER";
case CELL_SYSUTIL_SYSTEMPARAM_ID_NICKNAME: return "ID_NICKNAME";
case CELL_SYSUTIL_SYSTEMPARAM_ID_CURRENT_USERNAME: return "ID_CURRENT_USERNAME";
case CELL_SYSUTIL_SYSTEMPARAM_ID_x1008: return "ID_x1008";
case CELL_SYSUTIL_SYSTEMPARAM_ID_x1011: return "ID_x1011";
case CELL_SYSUTIL_SYSTEMPARAM_ID_x1012: return "ID_x1012";
case CELL_SYSUTIL_SYSTEMPARAM_ID_x1024: return "ID_x1024";
}
return unknown;
});
}
// Common string checks used in libsysutil functions
s32 sysutil_check_name_string(const char* src, s32 minlen, s32 maxlen)
{
s32 lastpos;
if (g_ps3_process_info.sdk_ver > 0x36FFFF)
{
// Limit null terminator boundary to before buffer max size
lastpos = std::max(maxlen - 1, 0);
}
else
{
// Limit null terminator boundary to one after buffer max size
lastpos = maxlen;
}
char cur = src[0];
if (cur == '_')
{
// Invalid character at start
return -1;
}
for (s32 index = 0;; cur = src[++index])
{
if (cur == '\0' || index == maxlen)
{
if (minlen > index || (maxlen == index && src[lastpos]))
{
// String length is invalid
return -2;
}
// OK
return 0;
}
if (cur >= 'A' && cur <= 'Z')
{
continue;
}
if (cur >= '0' && cur <= '9')
{
continue;
}
if (cur == '-' || cur == '_')
{
continue;
}
// Invalid character found
return -1;
}
}
error_code _cellSysutilGetSystemParamInt()
{
UNIMPLEMENTED_FUNC(cellSysutil);
return CELL_OK;
}
error_code cellSysutilGetSystemParamInt(CellSysutilParamId id, vm::ptr<s32> value)
{
cellSysutil.warning("cellSysutilGetSystemParamInt(id=0x%x(%s), value=*0x%x)", id, id, value);
if (!value)
{
return CELL_SYSUTIL_ERROR_VALUE;
}
// TODO: load this information from config (preferably "sys/" group)
switch (id)
{
case CELL_SYSUTIL_SYSTEMPARAM_ID_LANG:
*value = g_cfg.sys.language;
break;
case CELL_SYSUTIL_SYSTEMPARAM_ID_ENTER_BUTTON_ASSIGN:
*value = static_cast<s32>(g_cfg.sys.enter_button_assignment.get());
break;
case CELL_SYSUTIL_SYSTEMPARAM_ID_DATE_FORMAT:
*value = CELL_SYSUTIL_DATE_FMT_DDMMYYYY;
break;
case CELL_SYSUTIL_SYSTEMPARAM_ID_TIME_FORMAT:
*value = CELL_SYSUTIL_TIME_FMT_CLOCK24;
break;
case CELL_SYSUTIL_SYSTEMPARAM_ID_TIMEZONE:
*value = 180;
break;
case CELL_SYSUTIL_SYSTEMPARAM_ID_SUMMERTIME:
*value = 0;
break;
case CELL_SYSUTIL_SYSTEMPARAM_ID_GAME_PARENTAL_LEVEL:
*value = CELL_SYSUTIL_GAME_PARENTAL_OFF;
break;
case CELL_SYSUTIL_SYSTEMPARAM_ID_LICENSE_AREA:
{
if (g_ps3_process_info.sdk_ver > 0x23FFFFu)
{
return CELL_SYSUTIL_ERROR_VALUE;
}
extern s32 cellSysutilGetLicenseArea();
// Identical until proved otherwise
*value = cellSysutilGetLicenseArea();
break;
}
case CELL_SYSUTIL_SYSTEMPARAM_ID_GAME_PARENTAL_LEVEL0_RESTRICT:
*value = CELL_SYSUTIL_GAME_PARENTAL_LEVEL0_RESTRICT_OFF;
break;
// Report user has an NP account when np_psn_status is Fake or RPCN
case CELL_SYSUTIL_SYSTEMPARAM_ID_CURRENT_USER_HAS_NP_ACCOUNT:
*value = g_cfg.net.psn_status != np_psn_status::disabled;
break;
case CELL_SYSUTIL_SYSTEMPARAM_ID_CAMERA_PLFREQ:
*value = CELL_SYSUTIL_CAMERA_PLFREQ_DISABLED;
break;
case CELL_SYSUTIL_SYSTEMPARAM_ID_PAD_RUMBLE:
*value = CELL_SYSUTIL_PAD_RUMBLE_ON;
break;
case CELL_SYSUTIL_SYSTEMPARAM_ID_KEYBOARD_TYPE:
*value = g_cfg.sys.keyboard_type;
break;
case CELL_SYSUTIL_SYSTEMPARAM_ID_JAPANESE_KEYBOARD_ENTRY_METHOD:
*value = CELL_SYSUTIL_KEYBOARD_ENTRY_METHOD_ROMAJI_INPUT;
break;
case CELL_SYSUTIL_SYSTEMPARAM_ID_CHINESE_KEYBOARD_ENTRY_METHOD:
*value = CELL_SYSUTIL_KEYBOARD_ENTRY_METHOD_ZHUYIN_INPUT;
break;
case CELL_SYSUTIL_SYSTEMPARAM_ID_PAD_AUTOOFF:
*value = CELL_SYSUTIL_PAD_AUTOOFF_OFF;
break;
case CELL_SYSUTIL_SYSTEMPARAM_ID_MAGNETOMETER:
*value = CELL_SYSUTIL_MAGNETOMETER_OFF;
break;
default:
return CELL_SYSUTIL_ERROR_VALUE;
}
return CELL_OK;
}
error_code cellSysutilGetSystemParamString(CellSysutilParamId id, vm::ptr<char> buf, u32 bufsize)
{
cellSysutil.trace("cellSysutilGetSystemParamString(id=0x%x(%s), buf=*0x%x, bufsize=%d)", id, id, buf, bufsize);
if (!buf)
{
return CELL_SYSUTIL_ERROR_VALUE;
}
u32 copy_size;
std::string param_str = "Unknown";
bool report_use = false;
switch (id)
{
case CELL_SYSUTIL_SYSTEMPARAM_ID_NICKNAME:
{
copy_size = CELL_SYSUTIL_SYSTEMPARAM_NICKNAME_SIZE;
param_str = g_cfg.sys.system_name.to_string();
break;
}
case CELL_SYSUTIL_SYSTEMPARAM_ID_CURRENT_USERNAME:
{
const fs::file username(vfs::get(fmt::format("/dev_hdd0/home/%08u/localusername", Emu.GetUsrId())));
if (!username)
{
cellSysutil.error("cellSysutilGetSystemParamString(): Username for user %08u doesn't exist. Did you delete the username file?", Emu.GetUsrId());
}
else
{
// Read current username
param_str = username.to_string();
}
copy_size = CELL_SYSUTIL_SYSTEMPARAM_CURRENT_USERNAME_SIZE;
break;
}
case CELL_SYSUTIL_SYSTEMPARAM_ID_x1011: // Same as x1012
case CELL_SYSUTIL_SYSTEMPARAM_ID_x1012: copy_size = 0x400; report_use = true; break;
case CELL_SYSUTIL_SYSTEMPARAM_ID_x1024: copy_size = 0x100; report_use = true; break;
case CELL_SYSUTIL_SYSTEMPARAM_ID_x1008: copy_size = 0x4; report_use = true; break;
default:
{
return CELL_SYSUTIL_ERROR_VALUE;
}
}
if (bufsize != copy_size)
{
return CELL_SYSUTIL_ERROR_SIZE;
}
if (report_use)
{
cellSysutil.error("cellSysutilGetSystemParamString: Unknown ParamId 0x%x", id);
}
std::span dst(buf.get_ptr(), copy_size);
strcpy_trunc(dst, param_str);
return CELL_OK;
}
// Note: the way we do things here is inaccurate(but maybe sufficient)
// The real function goes over a table of 0x20 entries[ event_code:u32 callback_addr:u32 ]
// Those callbacks are registered through cellSysutilRegisterCallbackDispatcher(u32 event_code, vm::ptr<void> func_addr)
// The function goes through all the callback looking for one callback associated with event 0x100, if any is found it is called with parameters r3=0x101 r4=0
// This particular CB seems to be associated with sysutil itself
// Then it checks for events on an event_queue associated with sysutil, checks if any cb is associated with that event and calls them with parameters that come from the event
error_code cellSysutilCheckCallback(ppu_thread& ppu)
{
cellSysutil.trace("cellSysutilCheckCallback()");
auto& cbm = g_fxo->get<sysutil_cb_manager>();
bool read = false;
for (auto&& func : cbm.registered.pop_all())
{
if (func.call_active && !*func.call_active)
{
continue;
}
read = true;
if (s32 res = func.func(ppu))
{
// Currently impossible
return not_an_error(res);
}
if (ppu.is_stopped())
{
return {};
}
}
if (read)
{
cbm.read_counter++;
}
return CELL_OK;
}
error_code cellSysutilRegisterCallback(u32 slot, vm::ptr<CellSysutilCallback> func, vm::ptr<void> userdata)
{
cellSysutil.warning("cellSysutilRegisterCallback(slot=%d, func=*0x%x, userdata=*0x%x)", slot, func, userdata);
if (slot >= 4)
{
return CELL_SYSUTIL_ERROR_VALUE;
}
auto& cbm = g_fxo->get<sysutil_cb_manager>();
cbm.callbacks[slot].store({func, userdata});
return CELL_OK;
}
error_code cellSysutilUnregisterCallback(u32 slot)
{
cellSysutil.warning("cellSysutilUnregisterCallback(slot=%d)", slot);
if (slot >= 4)
{
return CELL_SYSUTIL_ERROR_VALUE;
}
auto& cbm = g_fxo->get<sysutil_cb_manager>();
cbm.callbacks[slot].store({});
return CELL_OK;
}
struct bgm_manager
{
shared_mutex mtx;
CellSysutilBgmPlaybackExtraParam param{};
CellSysutilBgmPlaybackStatus status{};
bgm_manager()
{
status.enableState = CELL_SYSUTIL_BGMPLAYBACK_STATUS_DISABLE;
status.playerState = CELL_SYSUTIL_BGMPLAYBACK_STATUS_STOP;
}
};
error_code cellSysutilEnableBgmPlayback()
{
cellSysutil.warning("cellSysutilEnableBgmPlayback()");
auto& bgm = g_fxo->get<bgm_manager>();
std::lock_guard lock(bgm.mtx);
bgm.status.enableState = CELL_SYSUTIL_BGMPLAYBACK_STATUS_ENABLE;
return CELL_OK;
}
error_code cellSysutilEnableBgmPlaybackEx(vm::ptr<CellSysutilBgmPlaybackExtraParam> param)
{
cellSysutil.warning("cellSysutilEnableBgmPlaybackEx(param=*0x%x)", param);
if (!param ||
param->systemBgmFadeInTime < CELL_SYSUTIL_BGMPLAYBACK_FADE_INVALID || param->systemBgmFadeInTime > 60000 ||
param->systemBgmFadeOutTime < CELL_SYSUTIL_BGMPLAYBACK_FADE_INVALID || param->systemBgmFadeOutTime > 60000 ||
param->gameBgmFadeInTime < CELL_SYSUTIL_BGMPLAYBACK_FADE_INVALID || param->gameBgmFadeInTime > 60000 ||
param->gameBgmFadeOutTime < CELL_SYSUTIL_BGMPLAYBACK_FADE_INVALID || param->gameBgmFadeOutTime > 60000)
{
return CELL_SYSUTIL_BGMPLAYBACK_EX_ERROR_PARAM;
}
auto& bgm = g_fxo->get<bgm_manager>();
std::lock_guard lock(bgm.mtx);
bgm.param.systemBgmFadeInTime = param->systemBgmFadeInTime;
bgm.param.systemBgmFadeOutTime = param->systemBgmFadeOutTime;
bgm.param.gameBgmFadeInTime = param->gameBgmFadeInTime;
bgm.param.gameBgmFadeOutTime = param->gameBgmFadeOutTime;
bgm.status.enableState = CELL_SYSUTIL_BGMPLAYBACK_STATUS_ENABLE;
return CELL_OK;
}
error_code cellSysutilDisableBgmPlayback()
{
cellSysutil.warning("cellSysutilDisableBgmPlayback()");
auto& bgm = g_fxo->get<bgm_manager>();
std::lock_guard lock(bgm.mtx);
bgm.status.enableState = CELL_SYSUTIL_BGMPLAYBACK_STATUS_DISABLE;
// TODO: fade from system bgm to game bgm if necessary
return CELL_OK;
}
error_code cellSysutilDisableBgmPlaybackEx(vm::ptr<CellSysutilBgmPlaybackExtraParam> param)
{
cellSysutil.warning("cellSysutilDisableBgmPlaybackEx(param=*0x%x)", param);
if (!param ||
param->systemBgmFadeInTime < CELL_SYSUTIL_BGMPLAYBACK_FADE_INVALID || param->systemBgmFadeInTime > 60000 ||
param->systemBgmFadeOutTime < CELL_SYSUTIL_BGMPLAYBACK_FADE_INVALID || param->systemBgmFadeOutTime > 60000 ||
param->gameBgmFadeInTime < CELL_SYSUTIL_BGMPLAYBACK_FADE_INVALID || param->gameBgmFadeInTime > 60000 ||
param->gameBgmFadeOutTime < CELL_SYSUTIL_BGMPLAYBACK_FADE_INVALID || param->gameBgmFadeOutTime > 60000)
{
return CELL_SYSUTIL_BGMPLAYBACK_EX_ERROR_PARAM;
}
auto& bgm = g_fxo->get<bgm_manager>();
std::lock_guard lock(bgm.mtx);
bgm.param.systemBgmFadeInTime = param->systemBgmFadeInTime;
bgm.param.systemBgmFadeOutTime = param->systemBgmFadeOutTime;
bgm.param.gameBgmFadeInTime = param->gameBgmFadeInTime;
bgm.param.gameBgmFadeOutTime = param->gameBgmFadeOutTime;
bgm.status.enableState = CELL_SYSUTIL_BGMPLAYBACK_STATUS_DISABLE;
// TODO: fade from system bgm to game bgm if necessary
return CELL_OK;
}
error_code cellSysutilGetBgmPlaybackStatus(vm::ptr<CellSysutilBgmPlaybackStatus> status)
{
cellSysutil.trace("cellSysutilGetBgmPlaybackStatus(status=*0x%x)", status);
if (!status)
{
return CELL_SYSUTIL_BGMPLAYBACK_ERROR_PARAM;
}
auto& bgm = g_fxo->get<bgm_manager>();
std::lock_guard lock(bgm.mtx);
*status = bgm.status;
return CELL_OK;
}
error_code cellSysutilGetBgmPlaybackStatus2(vm::ptr<CellSysutilBgmPlaybackStatus2> status2)
{
cellSysutil.trace("cellSysutilGetBgmPlaybackStatus2(status2=*0x%x)", status2);
if (!status2)
{
return CELL_SYSUTIL_BGMPLAYBACK_EX_ERROR_PARAM;
}
auto& bgm = g_fxo->get<bgm_manager>();
std::lock_guard lock(bgm.mtx);
status2->playerState = bgm.status.playerState;
memset(status2->reserved, 0, sizeof(status2->reserved));
return CELL_OK;
}
error_code cellSysutilSetBgmPlaybackExtraParam(vm::ptr<CellSysutilBgmPlaybackExtraParam> param)
{
cellSysutil.warning("cellSysutilSetBgmPlaybackExtraParam(param=*0x%x)", param);
if (!param ||
param->systemBgmFadeInTime < CELL_SYSUTIL_BGMPLAYBACK_FADE_INVALID || param->systemBgmFadeInTime > 60000 ||
param->systemBgmFadeOutTime < CELL_SYSUTIL_BGMPLAYBACK_FADE_INVALID || param->systemBgmFadeOutTime > 60000 ||
param->gameBgmFadeInTime < CELL_SYSUTIL_BGMPLAYBACK_FADE_INVALID || param->gameBgmFadeInTime > 60000 ||
param->gameBgmFadeOutTime < CELL_SYSUTIL_BGMPLAYBACK_FADE_INVALID || param->gameBgmFadeOutTime > 60000)
{
return CELL_SYSUTIL_BGMPLAYBACK_EX_ERROR_PARAM;
}
auto& bgm = g_fxo->get<bgm_manager>();
std::lock_guard lock(bgm.mtx);
bgm.param.systemBgmFadeInTime = param->systemBgmFadeInTime;
bgm.param.systemBgmFadeOutTime = param->systemBgmFadeOutTime;
bgm.param.gameBgmFadeInTime = param->gameBgmFadeInTime;
bgm.param.gameBgmFadeOutTime = param->gameBgmFadeOutTime;
// TODO: apparently you are only able to set this only once and while bgm is enabled
return CELL_OK;
}
error_code cellSysutilRegisterCallbackDispatcher(u32 event_code, u32 func_addr)
{
cellSysutil.warning("cellSysutilRegisterCallbackDispatcher(event_code=0x%x, func_addr=0x%x)", event_code, func_addr);
auto& cbm = g_fxo->get<sysutil_cb_manager>();
for (u32 i = 0; i < cbm.dispatchers.size(); i++)
{
if (cbm.dispatchers[i].atomic_op([&](sysutil_cb_manager::registered_dispatcher& dispatcher)
{
if (dispatcher.event_code == 0)
{
dispatcher.event_code = event_code;
dispatcher.func_addr = func_addr;
return true;
}
return false;
}))
{
return CELL_OK;
}
}
return 0x8002b004;
}
error_code cellSysutilUnregisterCallbackDispatcher(u32 event_code)
{
cellSysutil.warning("cellSysutilUnregisterCallbackDispatcher(event_code=0x%x)", event_code);
auto& cbm = g_fxo->get<sysutil_cb_manager>();
for (u32 i = 0; i < cbm.dispatchers.size(); i++)
{
if (cbm.dispatchers[i].atomic_op([&](sysutil_cb_manager::registered_dispatcher& dispatcher)
{
if (dispatcher.event_code == event_code)
{
dispatcher.event_code = 0;
dispatcher.func_addr = 0;
return true;
}
return false;
}))
{
return CELL_OK;
}
}
return 0x8002b005;
}
error_code cellSysutilPacketRead()
{
cellSysutil.todo("cellSysutilPacketRead()");
return CELL_OK;
}
error_code cellSysutilPacketWrite()
{
cellSysutil.todo("cellSysutilPacketWrite()");
return CELL_OK;
}
error_code cellSysutilPacketBegin()
{
cellSysutil.todo("cellSysutilPacketBegin()");
return CELL_OK;
}
error_code cellSysutilPacketEnd()
{
cellSysutil.todo("cellSysutilPacketEnd()");
return CELL_OK;
}
error_code cellSysutilGameDataAssignVmc()
{
cellSysutil.todo("cellSysutilGameDataAssignVmc()");
return CELL_OK;
}
error_code cellSysutilGameDataExit(u32 unk)
{
cellSysutil.todo("cellSysutilGameDataExit(unk=%d)", unk);
if (unk > 4)
{
return CELL_GAMEDATA_ERROR_PARAM;
}
return CELL_OK;
}
error_code cellSysutilGameExit_I()
{
cellSysutil.warning("cellSysutilGameExit_I()");
return cellSysutilGameDataExit(0);
}
error_code cellSysutilGamePowerOff_I()
{
cellSysutil.warning("cellSysutilGamePowerOff_I()");
return cellSysutilGameDataExit(1);
}
error_code cellSysutilGameReboot_I()
{
cellSysutil.warning("cellSysutilGameReboot_I()");
return cellSysutilGameDataExit(4);
}
error_code cellSysutilSharedMemoryAlloc()
{
cellSysutil.todo("cellSysutilSharedMemoryAlloc()");
return CELL_OK;
}
error_code cellSysutilSharedMemoryFree()
{
cellSysutil.todo("cellSysutilSharedMemoryFree()");
return CELL_OK;
}
error_code cellSysutilNotification()
{
cellSysutil.todo("cellSysutilNotification()");
return CELL_OK;
}
error_code _ZN4cxml7Element11AppendChildERS0_()
{
UNIMPLEMENTED_FUNC(cellSysutil);
return CELL_OK;
}
error_code _ZN4cxml8DocumentC1Ev()
{
UNIMPLEMENTED_FUNC(cellSysutil);
return CELL_OK;
}
error_code _ZN4cxml8DocumentD1Ev()
{
UNIMPLEMENTED_FUNC(cellSysutil);
return CELL_OK;
}
error_code _ZN4cxml8Document5ClearEv()
{
UNIMPLEMENTED_FUNC(cellSysutil);
return CELL_OK;
}
error_code _ZN4cxml8Document5WriteEPFiPKvjPvES3_()
{
UNIMPLEMENTED_FUNC(cellSysutil);
return CELL_OK;
}
error_code _ZN4cxml8Document12RegisterFileEPKvjPNS_4FileE()
{
UNIMPLEMENTED_FUNC(cellSysutil);
return CELL_OK;
}
error_code _ZN4cxml8Document13CreateElementEPKciPNS_7ElementE()
{
UNIMPLEMENTED_FUNC(cellSysutil);
return CELL_OK;
}
error_code _ZN4cxml8Document14SetHeaderMagicEPKc()
{
UNIMPLEMENTED_FUNC(cellSysutil);
return CELL_OK;
}
error_code _ZN4cxml8Document16CreateFromBufferEPKvjb()
{
UNIMPLEMENTED_FUNC(cellSysutil);
return CELL_OK;
}
error_code _ZN4cxml8Document18GetDocumentElementEv()
{
UNIMPLEMENTED_FUNC(cellSysutil);
return CELL_OK;
}
error_code _ZNK4cxml4File7GetAddrEv()
{
UNIMPLEMENTED_FUNC(cellSysutil);
return CELL_OK;
}
error_code _ZNK4cxml7Element12GetAttributeEPKcPNS_9AttributeE()
{
UNIMPLEMENTED_FUNC(cellSysutil);
return CELL_OK;
}
error_code _ZNK4cxml7Element13GetFirstChildEv()
{
UNIMPLEMENTED_FUNC(cellSysutil);
return CELL_OK;
}
error_code _ZNK4cxml7Element14GetNextSiblingEv()
{
UNIMPLEMENTED_FUNC(cellSysutil);
return CELL_OK;
}
error_code _ZNK4cxml9Attribute6GetIntEPi()
{
UNIMPLEMENTED_FUNC(cellSysutil);
return CELL_OK;
}
error_code _ZNK4cxml9Attribute7GetFileEPNS_4FileE()
{
UNIMPLEMENTED_FUNC(cellSysutil);
return CELL_OK;
}
error_code _ZN8cxmlutil6SetIntERKN4cxml7ElementEPKci()
{
UNIMPLEMENTED_FUNC(cellSysutil);
return CELL_OK;
}
error_code _ZN8cxmlutil6GetIntERKN4cxml7ElementEPKcPi()
{
UNIMPLEMENTED_FUNC(cellSysutil);
return CELL_OK;
}
error_code _ZN8cxmlutil7SetFileERKN4cxml7ElementEPKcRKNS0_4FileE()
{
UNIMPLEMENTED_FUNC(cellSysutil);
return CELL_OK;
}
error_code _ZN8cxmlutil8GetFloatERKN4cxml7ElementEPKcPf()
{
UNIMPLEMENTED_FUNC(cellSysutil);
return CELL_OK;
}
error_code _ZN8cxmlutil8SetFloatERKN4cxml7ElementEPKcf()
{
UNIMPLEMENTED_FUNC(cellSysutil);
return CELL_OK;
}
error_code _ZN8cxmlutil9GetStringERKN4cxml7ElementEPKcPS5_Pj()
{
UNIMPLEMENTED_FUNC(cellSysutil);
return CELL_OK;
}
error_code _ZN8cxmlutil9SetStringERKN4cxml7ElementEPKcS5_()
{
UNIMPLEMENTED_FUNC(cellSysutil);
return CELL_OK;
}
error_code _ZN8cxmlutil16CheckElementNameERKN4cxml7ElementEPKc()
{
UNIMPLEMENTED_FUNC(cellSysutil);
return CELL_OK;
}
error_code _ZN8cxmlutil16FindChildElementERKN4cxml7ElementEPKcS5_S5_()
{
UNIMPLEMENTED_FUNC(cellSysutil);
return CELL_OK;
}
error_code _ZN8cxmlutil7GetFileERKN4cxml7ElementEPKcPNS0_4FileE()
{
UNIMPLEMENTED_FUNC(cellSysutil);
return CELL_OK;
}
error_code _ZN16sysutil_cxmlutil11FixedMemory3EndEi()
{
UNIMPLEMENTED_FUNC(cellSysutil);
return CELL_OK;
}
error_code _ZN16sysutil_cxmlutil11FixedMemory5BeginEi()
{
UNIMPLEMENTED_FUNC(cellSysutil);
return CELL_OK;
}
error_code _ZN16sysutil_cxmlutil11FixedMemory8AllocateEN4cxml14AllocationTypeEPvS3_jPS3_Pj()
{
UNIMPLEMENTED_FUNC(cellSysutil);
return CELL_OK;
}
error_code _ZN16sysutil_cxmlutil12PacketWriter5WriteEPKvjPv()
{
UNIMPLEMENTED_FUNC(cellSysutil);
return CELL_OK;
}
error_code _ZN16sysutil_cxmlutil12PacketWriterC1EiiRN4cxml8DocumentE()
{
UNIMPLEMENTED_FUNC(cellSysutil);
return CELL_OK;
}
error_code cellSysutil_E1EC7B6A(vm::ptr<u32> unk)
{
cellSysutil.todo("cellSysutil_E1EC7B6A(unk=*0x%x)", unk);
*unk = 0;
return CELL_OK;
}
extern void cellSysutil_SaveData_init();
extern void cellSysutil_GameData_init();
extern void cellSysutil_MsgDialog_init();
extern void cellSysutil_OskDialog_init();
extern void cellSysutil_Storage_init();
extern void cellSysutil_Sysconf_init();
extern void cellSysutil_SysutilAvc_init();
extern void cellSysutil_WebBrowser_init();
extern void cellSysutil_AudioOut_init();
extern void cellSysutil_VideoOut_init();
extern void cellSysutil_SysCache_init();
DECLARE(ppu_module_manager::cellSysutil)("cellSysutil", []()
{
cellSysutil_SaveData_init(); // cellSaveData functions
cellSysutil_GameData_init(); // cellGameData, cellHddGame functions
cellSysutil_MsgDialog_init(); // cellMsgDialog functions
cellSysutil_OskDialog_init(); // cellOskDialog functions
cellSysutil_Storage_init(); // cellStorage functions
cellSysutil_Sysconf_init(); // cellSysconf functions
cellSysutil_SysutilAvc_init(); // cellSysutilAvc functions
cellSysutil_WebBrowser_init(); // cellWebBrowser, cellWebComponent functions
cellSysutil_AudioOut_init(); // cellAudioOut functions
cellSysutil_VideoOut_init(); // cellVideoOut functions
cellSysutil_SysCache_init(); // cellSysCache functions
REG_FUNC(cellSysutil, _cellSysutilGetSystemParamInt);
REG_FUNC(cellSysutil, cellSysutilGetSystemParamInt);
REG_FUNC(cellSysutil, cellSysutilGetSystemParamString);
REG_FUNC(cellSysutil, cellSysutilCheckCallback);
REG_FUNC(cellSysutil, cellSysutilRegisterCallback);
REG_FUNC(cellSysutil, cellSysutilUnregisterCallback);
REG_FUNC(cellSysutil, cellSysutilGetBgmPlaybackStatus);
REG_FUNC(cellSysutil, cellSysutilGetBgmPlaybackStatus2);
REG_FUNC(cellSysutil, cellSysutilEnableBgmPlayback);
REG_FUNC(cellSysutil, cellSysutilEnableBgmPlaybackEx);
REG_FUNC(cellSysutil, cellSysutilDisableBgmPlayback);
REG_FUNC(cellSysutil, cellSysutilDisableBgmPlaybackEx);
REG_FUNC(cellSysutil, cellSysutilSetBgmPlaybackExtraParam);
REG_FUNC(cellSysutil, cellSysutilRegisterCallbackDispatcher);
REG_FUNC(cellSysutil, cellSysutilUnregisterCallbackDispatcher);
REG_FUNC(cellSysutil, cellSysutilPacketRead);
REG_FUNC(cellSysutil, cellSysutilPacketWrite);
REG_FUNC(cellSysutil, cellSysutilPacketBegin);
REG_FUNC(cellSysutil, cellSysutilPacketEnd);
REG_FUNC(cellSysutil, cellSysutilGameDataAssignVmc);
REG_FUNC(cellSysutil, cellSysutilGameDataExit);
REG_FUNC(cellSysutil, cellSysutilGameExit_I);
REG_FUNC(cellSysutil, cellSysutilGamePowerOff_I);
REG_FUNC(cellSysutil, cellSysutilGameReboot_I);
REG_FUNC(cellSysutil, cellSysutilSharedMemoryAlloc);
REG_FUNC(cellSysutil, cellSysutilSharedMemoryFree);
REG_FUNC(cellSysutil, cellSysutilNotification);
REG_FUNC(cellSysutil, _ZN4cxml7Element11AppendChildERS0_);
REG_FUNC(cellSysutil, _ZN4cxml8DocumentC1Ev);
REG_FUNC(cellSysutil, _ZN4cxml8DocumentD1Ev);
REG_FUNC(cellSysutil, _ZN4cxml8Document5ClearEv);
REG_FUNC(cellSysutil, _ZN4cxml8Document5WriteEPFiPKvjPvES3_);
REG_FUNC(cellSysutil, _ZN4cxml8Document12RegisterFileEPKvjPNS_4FileE);
REG_FUNC(cellSysutil, _ZN4cxml8Document13CreateElementEPKciPNS_7ElementE);
REG_FUNC(cellSysutil, _ZN4cxml8Document14SetHeaderMagicEPKc);
REG_FUNC(cellSysutil, _ZN4cxml8Document16CreateFromBufferEPKvjb);
REG_FUNC(cellSysutil, _ZN4cxml8Document18GetDocumentElementEv);
REG_FUNC(cellSysutil, _ZNK4cxml4File7GetAddrEv);
REG_FUNC(cellSysutil, _ZNK4cxml7Element12GetAttributeEPKcPNS_9AttributeE);
REG_FUNC(cellSysutil, _ZNK4cxml7Element13GetFirstChildEv);
REG_FUNC(cellSysutil, _ZNK4cxml7Element14GetNextSiblingEv);
REG_FUNC(cellSysutil, _ZNK4cxml9Attribute6GetIntEPi);
REG_FUNC(cellSysutil, _ZNK4cxml9Attribute7GetFileEPNS_4FileE);
REG_FUNC(cellSysutil, _ZN8cxmlutil6SetIntERKN4cxml7ElementEPKci);
REG_FUNC(cellSysutil, _ZN8cxmlutil6GetIntERKN4cxml7ElementEPKcPi);
REG_FUNC(cellSysutil, _ZN8cxmlutil7SetFileERKN4cxml7ElementEPKcRKNS0_4FileE);
REG_FUNC(cellSysutil, _ZN8cxmlutil8GetFloatERKN4cxml7ElementEPKcPf);
REG_FUNC(cellSysutil, _ZN8cxmlutil8SetFloatERKN4cxml7ElementEPKcf);
REG_FUNC(cellSysutil, _ZN8cxmlutil9GetStringERKN4cxml7ElementEPKcPS5_Pj);
REG_FUNC(cellSysutil, _ZN8cxmlutil9SetStringERKN4cxml7ElementEPKcS5_);
REG_FUNC(cellSysutil, _ZN8cxmlutil16CheckElementNameERKN4cxml7ElementEPKc);
REG_FUNC(cellSysutil, _ZN8cxmlutil16FindChildElementERKN4cxml7ElementEPKcS5_S5_);
REG_FUNC(cellSysutil, _ZN8cxmlutil7GetFileERKN4cxml7ElementEPKcPNS0_4FileE);
REG_FUNC(cellSysutil, _ZN16sysutil_cxmlutil11FixedMemory3EndEi);
REG_FUNC(cellSysutil, _ZN16sysutil_cxmlutil11FixedMemory5BeginEi);
REG_FUNC(cellSysutil, _ZN16sysutil_cxmlutil11FixedMemory8AllocateEN4cxml14AllocationTypeEPvS3_jPS3_Pj);
REG_FUNC(cellSysutil, _ZN16sysutil_cxmlutil12PacketWriter5WriteEPKvjPv);
REG_FUNC(cellSysutil, _ZN16sysutil_cxmlutil12PacketWriterC1EiiRN4cxml8DocumentE);
REG_FNID(cellSysutil, 0xE1EC7B6A, cellSysutil_E1EC7B6A);
});
| 32,557
|
C++
|
.cpp
| 993
| 30.437059
| 174
| 0.774261
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
5,212
|
cellAudioOut.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellAudioOut.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
#include "Emu/Cell/lv2/sys_rsxaudio.h"
#include "Emu/IdManager.h"
#include "Emu/System.h"
#include "Emu/system_config.h"
#include "Loader/PSF.h"
#include "cellAudioOut.h"
#include "cellAudio.h"
LOG_CHANNEL(cellSysutil);
template<>
void fmt_class_string<CellAudioOutError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_AUDIO_OUT_ERROR_NOT_IMPLEMENTED);
STR_CASE(CELL_AUDIO_OUT_ERROR_ILLEGAL_CONFIGURATION);
STR_CASE(CELL_AUDIO_OUT_ERROR_ILLEGAL_PARAMETER);
STR_CASE(CELL_AUDIO_OUT_ERROR_PARAMETER_OUT_OF_RANGE);
STR_CASE(CELL_AUDIO_OUT_ERROR_DEVICE_NOT_FOUND);
STR_CASE(CELL_AUDIO_OUT_ERROR_UNSUPPORTED_AUDIO_OUT);
STR_CASE(CELL_AUDIO_OUT_ERROR_UNSUPPORTED_SOUND_MODE);
STR_CASE(CELL_AUDIO_OUT_ERROR_CONDITION_BUSY);
}
return unknown;
});
}
audio_out_configuration::audio_out_configuration()
{
audio_out& primary_output = ::at32(out, CELL_AUDIO_OUT_PRIMARY);
audio_out& secondary_output = ::at32(out, CELL_AUDIO_OUT_SECONDARY);
std::vector<CellAudioOutSoundMode>& primary_modes = primary_output.sound_modes;
std::vector<CellAudioOutSoundMode>& secondary_modes = secondary_output.sound_modes;
const psf::registry sfo = psf::load_object(Emu.GetSfoDir(true) + "/PARAM.SFO");
const s32 sound_format = psf::get_integer(sfo, "SOUND_FORMAT", psf::sound_format_flag::lpcm_2); // Default to Linear PCM 2 Ch.
const bool supports_lpcm_2 = (sound_format & psf::sound_format_flag::lpcm_2); // Linear PCM 2 Ch.
const bool supports_lpcm_5_1 = (sound_format & psf::sound_format_flag::lpcm_5_1); // Linear PCM 5.1 Ch.
const bool supports_lpcm_7_1 = (sound_format & psf::sound_format_flag::lpcm_7_1); // Linear PCM 7.1 Ch.
const bool supports_ac3 = (sound_format & psf::sound_format_flag::ac3); // Dolby Digital 5.1 Ch.
const bool supports_dts = (sound_format & psf::sound_format_flag::dts); // DTS 5.1 Ch.
if (supports_lpcm_2) cellSysutil.notice("cellAudioOut: found support for Linear PCM 2 Ch.");
if (supports_lpcm_5_1) cellSysutil.notice("cellAudioOut: found support for Linear PCM 5.1 Ch.");
if (supports_lpcm_7_1) cellSysutil.notice("cellAudioOut: found support for Linear PCM 7.1 Ch.");
if (supports_ac3) cellSysutil.notice("cellAudioOut: found support for Dolby Digital 5.1 Ch.");
if (supports_dts) cellSysutil.notice("cellAudioOut: found support for DTS 5.1 Ch.");
std::array<bool, 2> initial_mode_selected = {};
const auto add_sound_mode = [&](u32 index, u8 type, u8 channel, u8 fs, u32 layout, bool supported)
{
audio_out& output = ::at32(out, index);
bool& selected = ::at32(initial_mode_selected, index);
CellAudioOutSoundMode mode{};
mode.type = type;
mode.channel = channel;
mode.fs = fs;
mode.layout = layout;
output.sound_modes.push_back(std::move(mode));
if (!selected && supported)
{
// Pre-select the first available sound mode
output.channels = channel;
output.encoder = type;
output.sound_mode = output.sound_modes.back();
selected = true;
}
};
// TODO: more formats:
// - Each LPCM with other sample frequencies (we currently only support 48 kHz)
// - AAC
// - Dolby Digital Plus
// - Dolby TrueHD
// - DTS-HD High Resolution Audio
// - DTS-HD Master Audio
// - ...
switch (g_cfg.audio.format)
{
case audio_format::stereo:
{
break; // Already added by default
}
case audio_format::surround_7_1:
{
// Linear PCM 7.1 Ch. 48 kHz
add_sound_mode(CELL_AUDIO_OUT_PRIMARY, CELL_AUDIO_OUT_CODING_TYPE_LPCM, CELL_AUDIO_OUT_CHNUM_8, CELL_AUDIO_OUT_FS_48KHZ, CELL_AUDIO_OUT_SPEAKER_LAYOUT_8CH_LREClrxy, supports_lpcm_7_1);
[[fallthrough]]; // Also add all available 5.1 formats in case the game doesn't like 7.1
}
case audio_format::surround_5_1:
{
// Linear PCM 5.1 Ch. 48 kHz
add_sound_mode(CELL_AUDIO_OUT_PRIMARY, CELL_AUDIO_OUT_CODING_TYPE_LPCM, CELL_AUDIO_OUT_CHNUM_6, CELL_AUDIO_OUT_FS_48KHZ, CELL_AUDIO_OUT_SPEAKER_LAYOUT_6CH_LREClr, supports_lpcm_5_1);
// Dolby Digital 5.1 Ch.
add_sound_mode(CELL_AUDIO_OUT_PRIMARY, CELL_AUDIO_OUT_CODING_TYPE_AC3, CELL_AUDIO_OUT_CHNUM_6, CELL_AUDIO_OUT_FS_48KHZ, CELL_AUDIO_OUT_SPEAKER_LAYOUT_6CH_LREClr, supports_ac3);
// DTS 5.1 Ch.
add_sound_mode(CELL_AUDIO_OUT_PRIMARY, CELL_AUDIO_OUT_CODING_TYPE_DTS, CELL_AUDIO_OUT_CHNUM_6, CELL_AUDIO_OUT_FS_48KHZ, CELL_AUDIO_OUT_SPEAKER_LAYOUT_6CH_LREClr, supports_dts);
break;
}
case audio_format::automatic: // Automatic based on supported formats
{
if (supports_lpcm_7_1) // Linear PCM 7.1 Ch.
{
add_sound_mode(CELL_AUDIO_OUT_PRIMARY, CELL_AUDIO_OUT_CODING_TYPE_LPCM, CELL_AUDIO_OUT_CHNUM_8, CELL_AUDIO_OUT_FS_48KHZ, CELL_AUDIO_OUT_SPEAKER_LAYOUT_8CH_LREClrxy, supports_lpcm_7_1);
}
if (supports_lpcm_5_1) // Linear PCM 5.1 Ch.
{
add_sound_mode(CELL_AUDIO_OUT_PRIMARY, CELL_AUDIO_OUT_CODING_TYPE_LPCM, CELL_AUDIO_OUT_CHNUM_6, CELL_AUDIO_OUT_FS_48KHZ, CELL_AUDIO_OUT_SPEAKER_LAYOUT_6CH_LREClr, supports_lpcm_5_1);
}
if (supports_ac3) // Dolby Digital 5.1 Ch.
{
add_sound_mode(CELL_AUDIO_OUT_PRIMARY, CELL_AUDIO_OUT_CODING_TYPE_AC3, CELL_AUDIO_OUT_CHNUM_6, CELL_AUDIO_OUT_FS_48KHZ, CELL_AUDIO_OUT_SPEAKER_LAYOUT_6CH_LREClr, supports_ac3);
}
if (supports_dts) // DTS 5.1 Ch.
{
add_sound_mode(CELL_AUDIO_OUT_PRIMARY, CELL_AUDIO_OUT_CODING_TYPE_DTS, CELL_AUDIO_OUT_CHNUM_6, CELL_AUDIO_OUT_FS_48KHZ, CELL_AUDIO_OUT_SPEAKER_LAYOUT_6CH_LREClr, supports_dts);
}
break;
}
case audio_format::manual: // Manual based on selected formats
{
const u32 selected_formats = g_cfg.audio.formats;
if (selected_formats & static_cast<u32>(audio_format_flag::lpcm_7_1_48khz)) // Linear PCM 7.1 Ch. 48 kHz
add_sound_mode(CELL_AUDIO_OUT_PRIMARY, CELL_AUDIO_OUT_CODING_TYPE_LPCM, CELL_AUDIO_OUT_CHNUM_8, CELL_AUDIO_OUT_FS_48KHZ, CELL_AUDIO_OUT_SPEAKER_LAYOUT_8CH_LREClrxy, supports_lpcm_7_1);
if (selected_formats & static_cast<u32>(audio_format_flag::lpcm_5_1_48khz)) // Linear PCM 5.1 Ch. 48 kHz
add_sound_mode(CELL_AUDIO_OUT_PRIMARY, CELL_AUDIO_OUT_CODING_TYPE_LPCM, CELL_AUDIO_OUT_CHNUM_6, CELL_AUDIO_OUT_FS_48KHZ, CELL_AUDIO_OUT_SPEAKER_LAYOUT_6CH_LREClr, supports_lpcm_5_1);
if (selected_formats & static_cast<u32>(audio_format_flag::ac3)) // Dolby Digital 5.1 Ch.
add_sound_mode(CELL_AUDIO_OUT_PRIMARY, CELL_AUDIO_OUT_CODING_TYPE_AC3, CELL_AUDIO_OUT_CHNUM_6, CELL_AUDIO_OUT_FS_48KHZ, CELL_AUDIO_OUT_SPEAKER_LAYOUT_6CH_LREClr, supports_ac3);
if (selected_formats & static_cast<u32>(audio_format_flag::dts)) // DTS 5.1 Ch.
add_sound_mode(CELL_AUDIO_OUT_PRIMARY, CELL_AUDIO_OUT_CODING_TYPE_DTS, CELL_AUDIO_OUT_CHNUM_6, CELL_AUDIO_OUT_FS_48KHZ, CELL_AUDIO_OUT_SPEAKER_LAYOUT_6CH_LREClr, supports_dts);
break;
}
}
// Always add Linear PCM 2 Ch. to the primary output
add_sound_mode(CELL_AUDIO_OUT_PRIMARY, CELL_AUDIO_OUT_CODING_TYPE_LPCM, CELL_AUDIO_OUT_CHNUM_2, CELL_AUDIO_OUT_FS_48KHZ, CELL_AUDIO_OUT_SPEAKER_LAYOUT_2CH, true);
// The secondary output only supports Linear PCM 2 Ch.
add_sound_mode(CELL_AUDIO_OUT_SECONDARY, CELL_AUDIO_OUT_CODING_TYPE_LPCM, CELL_AUDIO_OUT_CHNUM_2, CELL_AUDIO_OUT_FS_48KHZ, CELL_AUDIO_OUT_SPEAKER_LAYOUT_2CH, true);
ensure(!primary_modes.empty() && ::at32(initial_mode_selected, CELL_AUDIO_OUT_PRIMARY));
ensure(!secondary_modes.empty() && ::at32(initial_mode_selected, CELL_AUDIO_OUT_SECONDARY));
for (const CellAudioOutSoundMode& mode : primary_modes)
{
cellSysutil.notice("cellAudioOut: added primary mode: type=%d, channel=%d, fs=%d, layout=%d", mode.type, mode.channel, mode.fs, mode.layout);
}
for (const CellAudioOutSoundMode& mode : secondary_modes)
{
cellSysutil.notice("cellAudioOut: added secondary mode: type=%d, channel=%d, fs=%d, layout=%d", mode.type, mode.channel, mode.fs, mode.layout);
}
cellSysutil.notice("cellAudioOut: initial primary output configuration: channels=%d, encoder=%d, downmixer=%d", primary_output.channels, primary_output.encoder, primary_output.downmixer);
cellSysutil.notice("cellAudioOut: initial secondary output configuration: channels=%d, encoder=%d, downmixer=%d", secondary_output.channels, secondary_output.encoder, secondary_output.downmixer);
}
audio_out_configuration::audio_out_configuration(utils::serial& ar)
: audio_out_configuration()
{
// Load configuartion (ar is reading)
save(ar);
}
void audio_out_configuration::save(utils::serial& ar)
{
GET_OR_USE_SERIALIZATION_VERSION(ar.is_writing(), cellAudioOut);
for (auto& state : out)
{
ar(state.state, state.channels, state.encoder, state.downmixer, state.copy_control, state.sound_modes, state.sound_mode);
}
}
std::pair<AudioChannelCnt, AudioChannelCnt> audio_out_configuration::audio_out::get_channel_count_and_downmixer() const
{
std::pair<AudioChannelCnt, AudioChannelCnt> ret;
switch (sound_mode.channel)
{
case 2: ret.first = AudioChannelCnt::STEREO; break;
case 6: ret.first = AudioChannelCnt::SURROUND_5_1; break;
case 8: ret.first = AudioChannelCnt::SURROUND_7_1; break;
default:
fmt::throw_exception("Unsupported channel count in cellAudioOut sound_mode: %d", sound_mode.channel);
}
switch (downmixer)
{
case CELL_AUDIO_OUT_DOWNMIXER_NONE: ret.second = AudioChannelCnt::SURROUND_7_1; break;
case CELL_AUDIO_OUT_DOWNMIXER_TYPE_A: ret.second = AudioChannelCnt::STEREO; break;
case CELL_AUDIO_OUT_DOWNMIXER_TYPE_B: ret.second = AudioChannelCnt::SURROUND_5_1; break;
default:
fmt::throw_exception("Unsupported downmixer in cellAudioOut config: %d", downmixer);
}
return ret;
}
error_code cellAudioOutGetNumberOfDevice(u32 audioOut);
error_code cellAudioOutGetSoundAvailability(u32 audioOut, u32 type, u32 fs, u32 option)
{
cellSysutil.warning("cellAudioOutGetSoundAvailability(audioOut=%d, type=%d, fs=0x%x, option=%d)", audioOut, type, fs, option);
switch (audioOut)
{
case CELL_AUDIO_OUT_PRIMARY: break;
// case CELL_AUDIO_OUT_SECONDARY: break; // TODO: enable if we ever actually support peripheral output
default: return not_an_error(0);
}
s32 available = 0;
// Check if the requested audio parameters are available and find the max supported channel count
audio_out_configuration& cfg = g_fxo->get<audio_out_configuration>();
std::lock_guard lock(cfg.mtx);
const audio_out_configuration::audio_out& out = ::at32(cfg.out, audioOut);
for (const CellAudioOutSoundMode& mode : out.sound_modes)
{
if (mode.type == type && static_cast<u32>(mode.fs) == fs)
{
available = std::max<u32>(available, mode.channel);
}
}
return not_an_error(available);
}
error_code cellAudioOutGetSoundAvailability2(u32 audioOut, u32 type, u32 fs, u32 ch, u32 option)
{
cellSysutil.warning("cellAudioOutGetSoundAvailability2(audioOut=%d, type=%d, fs=0x%x, ch=%d, option=%d)", audioOut, type, fs, ch, option);
switch (audioOut)
{
case CELL_AUDIO_OUT_PRIMARY: break;
// case CELL_AUDIO_OUT_SECONDARY: break; // TODO: enable if we ever actually support peripheral output
default: return not_an_error(0);
}
// Check if the requested audio parameters are available
audio_out_configuration& cfg = g_fxo->get<audio_out_configuration>();
std::lock_guard lock(cfg.mtx);
const audio_out_configuration::audio_out& out = ::at32(cfg.out, audioOut);
for (const CellAudioOutSoundMode& mode : out.sound_modes)
{
if (mode.type == type && static_cast<u32>(mode.fs) == fs && mode.channel == ch)
{
return not_an_error(ch);
}
}
return not_an_error(0);
}
error_code cellAudioOutGetState(u32 audioOut, u32 deviceIndex, vm::ptr<CellAudioOutState> state)
{
cellSysutil.warning("cellAudioOutGetState(audioOut=0x%x, deviceIndex=0x%x, state=*0x%x)", audioOut, deviceIndex, state);
if (!state)
{
return CELL_AUDIO_OUT_ERROR_ILLEGAL_PARAMETER;
}
const auto num = cellAudioOutGetNumberOfDevice(audioOut);
if (num < 0)
{
return num;
}
CellAudioOutState _state{};
if (deviceIndex >= num + 0u)
{
if (audioOut == CELL_AUDIO_OUT_SECONDARY)
{
// Error codes are not returned here
// Random (uninitialized) data from the stack seems to be returned here
// Although it was constant on my tests so let's write that
_state.state = 0x10;
_state.soundMode.layout = 0xD00C1680;
*state = _state;
return CELL_OK;
}
return CELL_AUDIO_OUT_ERROR_PARAMETER_OUT_OF_RANGE;
}
switch (audioOut)
{
case CELL_AUDIO_OUT_PRIMARY:
case CELL_AUDIO_OUT_SECONDARY:
{
audio_out_configuration& cfg = g_fxo->get<audio_out_configuration>();
std::lock_guard lock(cfg.mtx);
const audio_out_configuration::audio_out& out = ::at32(cfg.out, audioOut);
_state.state = out.state;
_state.encoder = out.encoder;
_state.downMixer = out.downmixer;
_state.soundMode = out.sound_mode;
break;
}
default:
return CELL_AUDIO_OUT_ERROR_ILLEGAL_PARAMETER;
}
*state = _state;
return CELL_OK;
}
error_code cellAudioOutConfigure(u32 audioOut, vm::ptr<CellAudioOutConfiguration> config, vm::ptr<CellAudioOutOption> option, u32 waitForEvent)
{
cellSysutil.warning("cellAudioOutConfigure(audioOut=%d, config=*0x%x, option=*0x%x, waitForEvent=%d)", audioOut, config, option, waitForEvent);
if (!config)
{
return CELL_AUDIO_OUT_ERROR_ILLEGAL_PARAMETER;
}
switch (audioOut)
{
case CELL_AUDIO_OUT_PRIMARY:
break;
case CELL_AUDIO_OUT_SECONDARY:
return CELL_AUDIO_OUT_ERROR_UNSUPPORTED_AUDIO_OUT; // The secondary output only supports one format and can't be reconfigured
default:
return CELL_AUDIO_OUT_ERROR_ILLEGAL_PARAMETER;
}
bool needs_reset = false;
audio_out_configuration& cfg = g_fxo->get<audio_out_configuration>();
{
std::lock_guard lock(cfg.mtx);
audio_out_configuration::audio_out& out = ::at32(cfg.out, audioOut);
// Apparently the set config does not necessarily have to exist in the list of sound modes.
if (out.channels != config->channel || out.encoder != config->encoder || out.downmixer != config->downMixer)
{
out.channels = config->channel;
out.encoder = config->encoder;
if (config->downMixer > CELL_AUDIO_OUT_DOWNMIXER_TYPE_B) // PS3 ignores invalid downMixer values and keeps the previous valid one instead
{
cellSysutil.warning("cellAudioOutConfigure: Invalid downmixing mode configured: %d. Keeping old mode: downMixer=%d",
config->downMixer, out.downmixer);
}
else
{
out.downmixer = config->downMixer;
}
// Try to find the best sound mode for this configuration
const auto it = std::find_if(out.sound_modes.cbegin(), out.sound_modes.cend(), [&out](const CellAudioOutSoundMode& mode)
{
return mode.type == out.encoder && mode.channel == out.channels;
});
if (it != out.sound_modes.cend())
{
out.sound_mode = *it;
}
else
{
cellSysutil.warning("cellAudioOutConfigure: Could not find an ideal sound mode for %d channel output. Keeping old mode: channels=%d, encoder=%d, fs=%d",
config->channel, out.sound_mode.channel, out.sound_mode.type, out.sound_mode.fs);
}
needs_reset = true;
}
}
if (needs_reset)
{
const auto reset_audio = [audioOut]() -> void
{
audio_out_configuration& cfg = g_fxo->get<audio_out_configuration>();
{
std::lock_guard lock(cfg.mtx);
::at32(cfg.out, audioOut).state = CELL_AUDIO_OUT_OUTPUT_STATE_DISABLED;
}
audio::configure_audio(true);
audio::configure_rsxaudio();
{
std::lock_guard lock(cfg.mtx);
::at32(cfg.out, audioOut).state = CELL_AUDIO_OUT_OUTPUT_STATE_ENABLED;
}
};
if (waitForEvent)
{
reset_audio();
}
else
{
Emu.CallFromMainThread(reset_audio);
}
}
cellSysutil.notice("cellAudioOutConfigure: channels=%d, encoder=%d, downMixer=%d", config->channel, config->encoder, config->downMixer);
return CELL_OK;
}
error_code cellAudioOutGetConfiguration(u32 audioOut, vm::ptr<CellAudioOutConfiguration> config, vm::ptr<CellAudioOutOption> option)
{
cellSysutil.warning("cellAudioOutGetConfiguration(audioOut=%d, config=*0x%x, option=*0x%x)", audioOut, config, option);
if (!config)
{
return CELL_AUDIO_OUT_ERROR_ILLEGAL_PARAMETER;
}
switch (audioOut)
{
case CELL_AUDIO_OUT_PRIMARY:
break;
case CELL_AUDIO_OUT_SECONDARY:
return CELL_AUDIO_OUT_ERROR_UNSUPPORTED_AUDIO_OUT; // The secondary output only supports one format and can't be reconfigured
default:
return CELL_AUDIO_OUT_ERROR_ILLEGAL_PARAMETER;
}
audio_out_configuration& cfg = g_fxo->get<audio_out_configuration>();
std::lock_guard lock(cfg.mtx);
const audio_out_configuration::audio_out& out = ::at32(cfg.out, audioOut);
// Return the active config.
CellAudioOutConfiguration _config{};
_config.channel = out.channels;
_config.encoder = out.encoder;
_config.downMixer = out.downmixer;
*config = _config;
return CELL_OK;
}
error_code cellAudioOutGetNumberOfDevice(u32 audioOut)
{
cellSysutil.warning("cellAudioOutGetNumberOfDevice(audioOut=%d)", audioOut);
switch (audioOut)
{
case CELL_AUDIO_OUT_PRIMARY:
return not_an_error(1);
case CELL_AUDIO_OUT_SECONDARY:
return not_an_error(0);
default:
break;
}
return CELL_AUDIO_OUT_ERROR_ILLEGAL_PARAMETER;
}
error_code cellAudioOutGetDeviceInfo(u32 audioOut, u32 deviceIndex, vm::ptr<CellAudioOutDeviceInfo> info)
{
cellSysutil.todo("cellAudioOutGetDeviceInfo(audioOut=%d, deviceIndex=%d, info=*0x%x)", audioOut, deviceIndex, info);
if (!info)
{
return CELL_AUDIO_OUT_ERROR_ILLEGAL_PARAMETER;
}
const auto num = cellAudioOutGetNumberOfDevice(audioOut);
if (num < 0)
{
return num;
}
if (deviceIndex >= num + 0u)
{
if (audioOut == CELL_AUDIO_OUT_SECONDARY)
{
// Error codes are not returned here
*info = {};
return CELL_OK;
}
return CELL_AUDIO_OUT_ERROR_PARAMETER_OUT_OF_RANGE;
}
audio_out_configuration& cfg = g_fxo->get<audio_out_configuration>();
std::lock_guard lock(cfg.mtx);
const audio_out_configuration::audio_out& out = ::at32(cfg.out, audioOut);
ensure(out.sound_modes.size() <= 16);
CellAudioOutDeviceInfo _info{};
_info.portType = CELL_AUDIO_OUT_PORT_HDMI;
_info.availableModeCount = ::narrow<u8>(out.sound_modes.size());
_info.state = CELL_AUDIO_OUT_DEVICE_STATE_AVAILABLE;
_info.latency = 13;
for (usz i = 0; i < out.sound_modes.size(); i++)
{
_info.availableModes[i] = ::at32(out.sound_modes, i);
}
*info = _info;
return CELL_OK;
}
error_code cellAudioOutSetCopyControl(u32 audioOut, u32 control)
{
cellSysutil.warning("cellAudioOutSetCopyControl(audioOut=%d, control=%d)", audioOut, control);
if (control > CELL_AUDIO_OUT_COPY_CONTROL_COPY_NEVER)
{
return CELL_AUDIO_OUT_ERROR_ILLEGAL_PARAMETER;
}
switch (audioOut)
{
case CELL_AUDIO_OUT_PRIMARY:
break;
case CELL_AUDIO_OUT_SECONDARY:
return CELL_AUDIO_OUT_ERROR_UNSUPPORTED_AUDIO_OUT; // TODO: enable if we ever actually support peripheral output
default:
return CELL_AUDIO_OUT_ERROR_ILLEGAL_PARAMETER;
}
audio_out_configuration& cfg = g_fxo->get<audio_out_configuration>();
std::lock_guard lock(cfg.mtx);
::at32(cfg.out, audioOut).copy_control = control;
return CELL_OK;
}
error_code cellAudioOutRegisterCallback(u32 slot, vm::ptr<CellAudioOutCallback> function, vm::ptr<void> userData)
{
cellSysutil.todo("cellAudioOutRegisterCallback(slot=%d, function=*0x%x, userData=*0x%x)", slot, function, userData);
return CELL_OK;
}
error_code cellAudioOutUnregisterCallback(u32 slot)
{
cellSysutil.todo("cellAudioOutUnregisterCallback(slot=%d)", slot);
return CELL_OK;
}
void cellSysutil_AudioOut_init()
{
REG_FUNC(cellSysutil, cellAudioOutGetState);
REG_FUNC(cellSysutil, cellAudioOutConfigure);
REG_FUNC(cellSysutil, cellAudioOutGetSoundAvailability);
REG_FUNC(cellSysutil, cellAudioOutGetSoundAvailability2);
REG_FUNC(cellSysutil, cellAudioOutGetDeviceInfo);
REG_FUNC(cellSysutil, cellAudioOutGetNumberOfDevice);
REG_FUNC(cellSysutil, cellAudioOutGetConfiguration);
REG_FUNC(cellSysutil, cellAudioOutSetCopyControl);
REG_FUNC(cellSysutil, cellAudioOutRegisterCallback);
REG_FUNC(cellSysutil, cellAudioOutUnregisterCallback);
}
| 19,866
|
C++
|
.cpp
| 479
| 38.807933
| 196
| 0.741233
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
5,213
|
cellSync2.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellSync2.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
#include "cellSync2.h"
#include "Utilities/StrUtil.h"
LOG_CHANNEL(cellSync2);
vm::gvar<CellSync2CallerThreadType> gCellSync2CallerThreadTypePpuThread;
vm::gvar<CellSync2Notifier> gCellSync2NotifierPpuThread;
vm::gvar<CellSync2CallerThreadType> gCellSync2CallerThreadTypePpuFiber;
vm::gvar<CellSync2Notifier> gCellSync2NotifierPpuFiber;
vm::gvar<CellSync2Notifier> gCellSync2NotifierSpursTask;
vm::gvar<CellSync2Notifier> gCellSync2NotifierSpursJobQueueJob;
template<>
void fmt_class_string<CellSync2Error>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_SYNC2_ERROR_AGAIN);
STR_CASE(CELL_SYNC2_ERROR_INVAL);
STR_CASE(CELL_SYNC2_ERROR_NOMEM);
STR_CASE(CELL_SYNC2_ERROR_DEADLK);
STR_CASE(CELL_SYNC2_ERROR_PERM);
STR_CASE(CELL_SYNC2_ERROR_BUSY);
STR_CASE(CELL_SYNC2_ERROR_STAT);
STR_CASE(CELL_SYNC2_ERROR_ALIGN);
STR_CASE(CELL_SYNC2_ERROR_NULL_POINTER);
STR_CASE(CELL_SYNC2_ERROR_NOT_SUPPORTED_THREAD);
STR_CASE(CELL_SYNC2_ERROR_NO_NOTIFIER);
STR_CASE(CELL_SYNC2_ERROR_NO_SPU_CONTEXT_STORAGE);
}
return unknown;
});
}
error_code _cellSync2MutexAttributeInitialize(vm::ptr<CellSync2MutexAttribute> attr, u32 sdkVersion)
{
cellSync2.warning("_cellSync2MutexAttributeInitialize(attr=*0x%x, sdkVersion=0x%x)", attr, sdkVersion);
if (!attr)
return CELL_SYNC2_ERROR_NULL_POINTER;
attr->sdkVersion = sdkVersion;
attr->threadTypes = CELL_SYNC2_THREAD_TYPE_PPU_THREAD | CELL_SYNC2_THREAD_TYPE_PPU_FIBER |
CELL_SYNC2_THREAD_TYPE_SPURS_TASK | CELL_SYNC2_THREAD_TYPE_SPURS_JOB |
CELL_SYNC2_THREAD_TYPE_SPURS_JOBQUEUE_JOB;
attr->maxWaiters = 15;
attr->recursive = false;
strcpy_trunc(attr->name, "CellSync2Mutex");
return CELL_OK;
}
error_code cellSync2MutexEstimateBufferSize(vm::cptr<CellSync2MutexAttribute> attr, vm::ptr<u32> bufferSize)
{
cellSync2.todo("cellSync2MutexEstimateBufferSize(attr=*0x%x, bufferSize=*0x%x)", attr, bufferSize);
if (!attr || !bufferSize)
return CELL_SYNC2_ERROR_NULL_POINTER;
if (attr->maxWaiters > 0x8000)
return CELL_SYNC2_ERROR_INVAL;
return CELL_OK;
}
error_code cellSync2MutexInitialize(vm::ptr<CellSync2Mutex> mutex, vm::ptr<void> buffer, vm::cptr<CellSync2MutexAttribute> attr)
{
cellSync2.todo("cellSync2MutexInitialize(mutex=*0x%x, buffer=*0x%x, attr=*0x%x)", mutex, buffer, attr);
if (!mutex || !attr)
return CELL_SYNC2_ERROR_NULL_POINTER;
if ((attr->maxWaiters > 0) && !buffer)
return CELL_SYNC2_ERROR_NULL_POINTER;
if (attr->maxWaiters > 0x8000)
return CELL_SYNC2_ERROR_INVAL;
return CELL_OK;
}
error_code cellSync2MutexFinalize(vm::ptr<CellSync2Mutex> mutex)
{
cellSync2.todo("cellSync2MutexFinalize(mutex=*0x%x)", mutex);
if (!mutex)
return CELL_SYNC2_ERROR_NULL_POINTER;
return CELL_OK;
}
error_code cellSync2MutexLock(vm::ptr<CellSync2Mutex> mutex, vm::cptr<CellSync2ThreadConfig> config)
{
cellSync2.todo("cellSync2MutexLock(mutex=*0x%x, config=*0x%x)", mutex, config);
if (!mutex)
return CELL_SYNC2_ERROR_NULL_POINTER;
return CELL_OK;
}
error_code cellSync2MutexTryLock(vm::ptr<CellSync2Mutex> mutex, vm::cptr<CellSync2ThreadConfig> config)
{
cellSync2.todo("cellSync2MutexTryLock(mutex=*0x%x, config=*0x%x)", mutex, config);
if (!mutex)
return CELL_SYNC2_ERROR_NULL_POINTER;
return CELL_OK;
}
error_code cellSync2MutexUnlock(vm::ptr<CellSync2Mutex> mutex, vm::cptr<CellSync2ThreadConfig> config)
{
cellSync2.todo("cellSync2MutexUnlock(mutex=*0x%x, config=*0x%x)", mutex, config);
if (!mutex)
return CELL_SYNC2_ERROR_NULL_POINTER;
return CELL_OK;
}
error_code _cellSync2CondAttributeInitialize(vm::ptr<CellSync2CondAttribute> attr, u32 sdkVersion)
{
cellSync2.warning("_cellSync2CondAttributeInitialize(attr=*0x%x, sdkVersion=0x%x)", attr, sdkVersion);
if (!attr)
return CELL_SYNC2_ERROR_NULL_POINTER;
attr->sdkVersion = sdkVersion;
attr->maxWaiters = 15;
strcpy_trunc(attr->name, "CellSync2Cond");
return CELL_OK;
}
error_code cellSync2CondEstimateBufferSize(vm::cptr<CellSync2CondAttribute> attr, vm::ptr<u32> bufferSize)
{
cellSync2.todo("cellSync2CondEstimateBufferSize(attr=*0x%x, bufferSize=*0x%x)", attr, bufferSize);
if (!attr || !bufferSize)
return CELL_SYNC2_ERROR_NULL_POINTER;
if (attr->maxWaiters == 0 || attr->maxWaiters > 0x8000)
return CELL_SYNC2_ERROR_INVAL;
return CELL_OK;
}
error_code cellSync2CondInitialize(vm::ptr<CellSync2Cond> cond, vm::ptr<CellSync2Mutex> mutex, vm::ptr<void> buffer, vm::cptr<CellSync2CondAttribute> attr)
{
cellSync2.todo("cellSync2CondInitialize(cond=*0x%x, mutex=*0x%x, buffer=*0x%x, attr=*0x%x)", cond, mutex, buffer, attr);
if (!cond || !mutex || !buffer || !attr)
return CELL_SYNC2_ERROR_NULL_POINTER;
if (attr->maxWaiters == 0)
return CELL_SYNC2_ERROR_INVAL;
return CELL_OK;
}
error_code cellSync2CondFinalize(vm::ptr<CellSync2Cond> cond)
{
cellSync2.todo("cellSync2CondFinalize(cond=*0x%x)", cond);
if (!cond)
return CELL_SYNC2_ERROR_NULL_POINTER;
return CELL_OK;
}
error_code cellSync2CondWait(vm::ptr<CellSync2Cond> cond, vm::cptr<CellSync2ThreadConfig> config)
{
cellSync2.todo("cellSync2CondWait(cond=*0x%x, config=*0x%x)", cond, config);
if (!cond)
return CELL_SYNC2_ERROR_NULL_POINTER;
return CELL_OK;
}
error_code cellSync2CondSignal(vm::ptr<CellSync2Cond> cond, vm::cptr<CellSync2ThreadConfig> config)
{
cellSync2.todo("cellSync2CondSignal(cond=*0x%x, config=*0x%x)", cond, config);
if (!cond)
return CELL_SYNC2_ERROR_NULL_POINTER;
return CELL_OK;
}
error_code cellSync2CondSignalAll(vm::ptr<CellSync2Cond> cond, vm::cptr<CellSync2ThreadConfig> config)
{
cellSync2.todo("cellSync2CondSignalAll(cond=*0x%x, config=*0x%x)", cond, config);
if (!cond)
return CELL_SYNC2_ERROR_NULL_POINTER;
return CELL_OK;
}
error_code _cellSync2SemaphoreAttributeInitialize(vm::ptr<CellSync2SemaphoreAttribute> attr, u32 sdkVersion)
{
cellSync2.warning("_cellSync2SemaphoreAttributeInitialize(attr=*0x%x, sdkVersion=0x%x)", attr, sdkVersion);
if (!attr)
return CELL_SYNC2_ERROR_NULL_POINTER;
attr->sdkVersion = sdkVersion;
attr->threadTypes = CELL_SYNC2_THREAD_TYPE_PPU_THREAD | CELL_SYNC2_THREAD_TYPE_PPU_FIBER |
CELL_SYNC2_THREAD_TYPE_SPURS_TASK | CELL_SYNC2_THREAD_TYPE_SPURS_JOB |
CELL_SYNC2_THREAD_TYPE_SPURS_JOBQUEUE_JOB;
attr->maxWaiters = 1;
strcpy_trunc(attr->name, "CellSync2Semaphore");
return CELL_OK;
}
error_code cellSync2SemaphoreEstimateBufferSize(vm::cptr<CellSync2SemaphoreAttribute> attr, vm::ptr<u32> bufferSize)
{
cellSync2.todo("cellSync2SemaphoreEstimateBufferSize(attr=*0x%x, bufferSize=*0x%x)", attr, bufferSize);
if (!attr || !bufferSize)
return CELL_SYNC2_ERROR_NULL_POINTER;
if (attr->maxWaiters == 0 || attr->maxWaiters > 0x8000)
return CELL_SYNC2_ERROR_INVAL;
return CELL_OK;
}
error_code cellSync2SemaphoreInitialize(vm::ptr<CellSync2Semaphore> semaphore, vm::ptr<void> buffer, s32 initialValue, vm::cptr<CellSync2SemaphoreAttribute> attr)
{
cellSync2.todo("cellSync2SemaphoreInitialize(semaphore=*0x%x, buffer=*0x%x, initialValue=0x%x, attr=*0x%x)", semaphore, buffer, initialValue, attr);
if (!semaphore || !attr || ((attr->maxWaiters >= 2) && !buffer))
return CELL_SYNC2_ERROR_NULL_POINTER;
if ((initialValue > s32{0x7FFFFF}) || (initialValue < s32{-0x800000}) || (attr->maxWaiters == 0) || ((attr->maxWaiters == 1) && buffer))
return CELL_SYNC2_ERROR_INVAL;
return CELL_OK;
}
error_code cellSync2SemaphoreFinalize(vm::ptr<CellSync2Semaphore> semaphore)
{
cellSync2.todo("cellSync2SemaphoreFinalize(semaphore=*0x%x)", semaphore);
if (!semaphore)
return CELL_SYNC2_ERROR_NULL_POINTER;
return CELL_OK;
}
error_code cellSync2SemaphoreAcquire(vm::ptr<CellSync2Semaphore> semaphore, u32 count, vm::cptr<CellSync2ThreadConfig> config)
{
cellSync2.todo("cellSync2SemaphoreAcquire(semaphore=*0x%x, count=0x%x, config=*0x%x)", semaphore, count, config);
if (!semaphore)
return CELL_SYNC2_ERROR_NULL_POINTER;
if (count > 0x7FFFFF)
return CELL_SYNC2_ERROR_INVAL;
return CELL_OK;
}
error_code cellSync2SemaphoreTryAcquire(vm::ptr<CellSync2Semaphore> semaphore, u32 count, vm::cptr<CellSync2ThreadConfig> config)
{
cellSync2.todo("cellSync2SemaphoreTryAcquire(semaphore=*0x%x, count=0x%x, config=*0x%x)", semaphore, count, config);
if (!semaphore)
return CELL_SYNC2_ERROR_NULL_POINTER;
if (count > 0x7FFFFF)
return CELL_SYNC2_ERROR_INVAL;
return CELL_OK;
}
error_code cellSync2SemaphoreRelease(vm::ptr<CellSync2Semaphore> semaphore, u32 count, vm::cptr<CellSync2ThreadConfig> config)
{
cellSync2.todo("cellSync2SemaphoreRelease(semaphore=*0x%x, count=0x%x, config=*0x%x)", semaphore, count, config);
if (!semaphore)
return CELL_SYNC2_ERROR_NULL_POINTER;
if (count > 0x7FFFFF)
return CELL_SYNC2_ERROR_INVAL;
return CELL_OK;
}
error_code cellSync2SemaphoreGetCount(vm::ptr<CellSync2Semaphore> semaphore, vm::ptr<s32> count)
{
cellSync2.todo("cellSync2SemaphoreGetCount(semaphore=*0x%x, count=*0x%x)", semaphore, count);
if (!semaphore || !count)
return CELL_SYNC2_ERROR_NULL_POINTER;
return CELL_OK;
}
error_code _cellSync2QueueAttributeInitialize(vm::ptr<CellSync2QueueAttribute> attr, u32 sdkVersion)
{
cellSync2.warning("_cellSync2QueueAttributeInitialize(attr=*0x%x, sdkVersion=0x%x)", attr, sdkVersion);
if (!attr)
return CELL_SYNC2_ERROR_NULL_POINTER;
attr->sdkVersion = sdkVersion;
attr->threadTypes = CELL_SYNC2_THREAD_TYPE_PPU_THREAD | CELL_SYNC2_THREAD_TYPE_PPU_FIBER |
CELL_SYNC2_THREAD_TYPE_SPURS_TASK | CELL_SYNC2_THREAD_TYPE_SPURS_JOB |
CELL_SYNC2_THREAD_TYPE_SPURS_JOBQUEUE_JOB;
attr->elementSize = 16;
attr->depth = 1024;
attr->maxPushWaiters = 15;
attr->maxPopWaiters = 15;
strcpy_trunc(attr->name, "CellSync2Queue");
return CELL_OK;
}
error_code cellSync2QueueEstimateBufferSize(vm::cptr<CellSync2QueueAttribute> attr, vm::ptr<u32> bufferSize)
{
cellSync2.todo("cellSync2QueueEstimateBufferSize(attr=*0x%x, bufferSize=*0x%x)", attr, bufferSize);
if (!attr || !bufferSize)
return CELL_SYNC2_ERROR_NULL_POINTER;
if (attr->elementSize == 0u || attr->elementSize > 0x4000u || attr->elementSize % 16u || attr->depth == 0u || attr->depth > 0xFFFFFFFCu ||
attr->maxPushWaiters > 0x8000u || attr->maxPopWaiters > 0x8000u)
return CELL_SYNC2_ERROR_INVAL;
return CELL_OK;
}
error_code cellSync2QueueInitialize(vm::ptr<CellSync2Queue> queue, vm::ptr<void> buffer, vm::cptr<CellSync2QueueAttribute> attr)
{
cellSync2.todo("cellSync2QueueInitialize(queue=*0x%x, buffer=*0x%x, attr=*0x%x)", queue, buffer, attr);
if (!queue || !buffer || !attr)
return CELL_SYNC2_ERROR_NULL_POINTER;
if (attr->elementSize == 0u || attr->elementSize > 0x4000u || attr->elementSize % 16u || attr->depth == 0u || attr->depth > 0xFFFFFFFCu ||
attr->maxPushWaiters > 0x8000u || attr->maxPopWaiters > 0x8000u)
return CELL_SYNC2_ERROR_INVAL;
return CELL_OK;
}
error_code cellSync2QueueFinalize(vm::ptr<CellSync2Queue> queue)
{
cellSync2.todo("cellSync2QueueFinalize(queue=*0x%x)", queue);
if (!queue)
return CELL_SYNC2_ERROR_NULL_POINTER;
return CELL_OK;
}
error_code cellSync2QueuePush(vm::ptr<CellSync2Queue> queue, vm::cptr<void> data, vm::cptr<CellSync2ThreadConfig> config)
{
cellSync2.todo("cellSync2QueuePush(queue=*0x%x, data=*0x%x, config=*0x%x)", queue, data, config);
if (!queue || !data)
return CELL_SYNC2_ERROR_NULL_POINTER;
return CELL_OK;
}
error_code cellSync2QueueTryPush(vm::ptr<CellSync2Queue> queue, vm::cpptr<void> data, u32 numData, vm::cptr<CellSync2ThreadConfig> config)
{
cellSync2.todo("cellSync2QueueTryPush(queue=*0x%x, data=**0x%x, numData=0x%x, config=*0x%x)", queue, data, numData, config);
if (!queue || !data)
return CELL_SYNC2_ERROR_NULL_POINTER;
return CELL_OK;
}
error_code cellSync2QueuePop(vm::ptr<CellSync2Queue> queue, vm::ptr<void> buffer, vm::cptr<CellSync2ThreadConfig> config)
{
cellSync2.todo("cellSync2QueuePop(queue=*0x%x, buffer=*0x%x, config=*0x%x)", queue, buffer, config);
if (!queue || !buffer)
return CELL_SYNC2_ERROR_NULL_POINTER;
return CELL_OK;
}
error_code cellSync2QueueTryPop(vm::ptr<CellSync2Queue> queue, vm::ptr<void> buffer, vm::cptr<CellSync2ThreadConfig> config)
{
cellSync2.todo("cellSync2QueueTryPop(queue=*0x%x, buffer=*0x%x, config=*0x%x)", queue, buffer, config);
if (!queue || !buffer)
return CELL_SYNC2_ERROR_NULL_POINTER;
return CELL_OK;
}
error_code cellSync2QueueGetSize(vm::ptr<CellSync2Queue> queue, vm::ptr<u32> size)
{
cellSync2.todo("cellSync2QueueGetSize(queue=*0x%x, size=*0x%x)", queue, size);
if (!queue || !size)
return CELL_SYNC2_ERROR_NULL_POINTER;
return CELL_OK;
}
error_code cellSync2QueueGetDepth(vm::ptr<CellSync2Queue> queue, vm::ptr<u32> depth)
{
cellSync2.todo("cellSync2QueueGetDepth(queue=*0x%x, depth=*0x%x)", queue, depth);
if (!queue || !depth)
return CELL_SYNC2_ERROR_NULL_POINTER;
return CELL_OK;
}
DECLARE(ppu_module_manager::cellSync2)("cellSync2", []()
{
REG_VAR(cellSync2, gCellSync2CallerThreadTypePpuThread);
REG_VAR(cellSync2, gCellSync2NotifierPpuThread);
REG_VAR(cellSync2, gCellSync2CallerThreadTypePpuFiber);
REG_VAR(cellSync2, gCellSync2NotifierPpuFiber);
REG_VAR(cellSync2, gCellSync2NotifierSpursTask);
REG_VAR(cellSync2, gCellSync2NotifierSpursJobQueueJob);
REG_FUNC(cellSync2, _cellSync2MutexAttributeInitialize);
REG_FUNC(cellSync2, cellSync2MutexEstimateBufferSize);
REG_FUNC(cellSync2, cellSync2MutexInitialize);
REG_FUNC(cellSync2, cellSync2MutexFinalize);
REG_FUNC(cellSync2, cellSync2MutexLock);
REG_FUNC(cellSync2, cellSync2MutexTryLock);
REG_FUNC(cellSync2, cellSync2MutexUnlock);
REG_FUNC(cellSync2, _cellSync2CondAttributeInitialize);
REG_FUNC(cellSync2, cellSync2CondEstimateBufferSize);
REG_FUNC(cellSync2, cellSync2CondInitialize);
REG_FUNC(cellSync2, cellSync2CondFinalize);
REG_FUNC(cellSync2, cellSync2CondWait);
REG_FUNC(cellSync2, cellSync2CondSignal);
REG_FUNC(cellSync2, cellSync2CondSignalAll);
REG_FUNC(cellSync2, _cellSync2SemaphoreAttributeInitialize);
REG_FUNC(cellSync2, cellSync2SemaphoreEstimateBufferSize);
REG_FUNC(cellSync2, cellSync2SemaphoreInitialize);
REG_FUNC(cellSync2, cellSync2SemaphoreFinalize);
REG_FUNC(cellSync2, cellSync2SemaphoreAcquire);
REG_FUNC(cellSync2, cellSync2SemaphoreTryAcquire);
REG_FUNC(cellSync2, cellSync2SemaphoreRelease);
REG_FUNC(cellSync2, cellSync2SemaphoreGetCount);
REG_FUNC(cellSync2, _cellSync2QueueAttributeInitialize);
REG_FUNC(cellSync2, cellSync2QueueEstimateBufferSize);
REG_FUNC(cellSync2, cellSync2QueueInitialize);
REG_FUNC(cellSync2, cellSync2QueueFinalize);
REG_FUNC(cellSync2, cellSync2QueuePush);
REG_FUNC(cellSync2, cellSync2QueueTryPush);
REG_FUNC(cellSync2, cellSync2QueuePop);
REG_FUNC(cellSync2, cellSync2QueueTryPop);
REG_FUNC(cellSync2, cellSync2QueueGetSize);
REG_FUNC(cellSync2, cellSync2QueueGetDepth);
});
| 14,849
|
C++
|
.cpp
| 350
| 40.137143
| 162
| 0.778033
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| true
| false
| false
| true
| false
| false
|
5,214
|
cellFont.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellFont.cpp
|
#include "stdafx.h"
#include "Emu/VFS.h"
#include "Emu/Cell/PPUModule.h"
#include <stb_truetype.h>
#include "cellFont.h"
LOG_CHANNEL(cellFont);
template <>
void fmt_class_string<CellFontError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_FONT_ERROR_FATAL);
STR_CASE(CELL_FONT_ERROR_INVALID_PARAMETER);
STR_CASE(CELL_FONT_ERROR_UNINITIALIZED);
STR_CASE(CELL_FONT_ERROR_INITIALIZE_FAILED);
STR_CASE(CELL_FONT_ERROR_INVALID_CACHE_BUFFER);
STR_CASE(CELL_FONT_ERROR_ALREADY_INITIALIZED);
STR_CASE(CELL_FONT_ERROR_ALLOCATION_FAILED);
STR_CASE(CELL_FONT_ERROR_NO_SUPPORT_FONTSET);
STR_CASE(CELL_FONT_ERROR_OPEN_FAILED);
STR_CASE(CELL_FONT_ERROR_READ_FAILED);
STR_CASE(CELL_FONT_ERROR_FONT_OPEN_FAILED);
STR_CASE(CELL_FONT_ERROR_FONT_NOT_FOUND);
STR_CASE(CELL_FONT_ERROR_FONT_OPEN_MAX);
STR_CASE(CELL_FONT_ERROR_FONT_CLOSE_FAILED);
STR_CASE(CELL_FONT_ERROR_ALREADY_OPENED);
STR_CASE(CELL_FONT_ERROR_NO_SUPPORT_FUNCTION);
STR_CASE(CELL_FONT_ERROR_NO_SUPPORT_CODE);
STR_CASE(CELL_FONT_ERROR_NO_SUPPORT_GLYPH);
STR_CASE(CELL_FONT_ERROR_BUFFER_SIZE_NOT_ENOUGH);
STR_CASE(CELL_FONT_ERROR_RENDERER_ALREADY_BIND);
STR_CASE(CELL_FONT_ERROR_RENDERER_UNBIND);
STR_CASE(CELL_FONT_ERROR_RENDERER_INVALID);
STR_CASE(CELL_FONT_ERROR_RENDERER_ALLOCATION_FAILED);
STR_CASE(CELL_FONT_ERROR_ENOUGH_RENDERING_BUFFER);
STR_CASE(CELL_FONT_ERROR_NO_SUPPORT_SURFACE);
}
return unknown;
});
}
// Functions
error_code cellFontInitializeWithRevision(u64 revisionFlags, vm::ptr<CellFontConfig> config)
{
cellFont.todo("cellFontInitializeWithRevision(revisionFlags=0x%llx, config=*0x%x)", revisionFlags, config);
if (config->fc_size < 24)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (config->flags != 0u)
{
cellFont.error("cellFontInitializeWithRevision: Unknown flags (0x%x)", config->flags);
}
// TODO
return CELL_OK;
}
void cellFontGetRevisionFlags(vm::ptr<u64> revisionFlags)
{
cellFont.notice("cellFontGetRevisionFlags(*0x%x)", revisionFlags);
if (revisionFlags)
{
*revisionFlags = 100;
}
}
error_code cellFontEnd()
{
cellFont.todo("cellFontEnd()");
if (false) // TODO
{
return CELL_FONT_ERROR_UNINITIALIZED;
}
return CELL_OK;
}
error_code cellFontSetFontsetOpenMode(vm::cptr<CellFontLibrary> library, u32 openMode)
{
cellFont.todo("cellFontSetFontsetOpenMode(library=*0x%x, openMode=0x%x)", library, openMode);
if (false) // TODO
{
return CELL_FONT_ERROR_UNINITIALIZED;
}
if (!library)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
// TODO: set openMode
return CELL_OK;
}
error_code cellFontOpenFontMemory(vm::ptr<CellFontLibrary> library, u32 fontAddr, u32 fontSize, u32 subNum, u32 uniqueId, vm::ptr<CellFont> font)
{
cellFont.todo("cellFontOpenFontMemory(library=*0x%x, fontAddr=0x%x, fontSize=%d, subNum=%d, uniqueId=%d, font=*0x%x)", library, fontAddr, fontSize, subNum, uniqueId, font);
if (!font)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
// TODO: reset some font fields here
if (!library)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (false) // TODO
{
return CELL_FONT_ERROR_UNINITIALIZED;
}
if (!fontAddr || uniqueId < 0)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
// TODO
font->stbfont = vm::_ptr<stbtt_fontinfo>(font.addr() + font.size()); // hack: use next bytes of the struct
if (!stbtt_InitFont(font->stbfont, vm::_ptr<unsigned char>(fontAddr), 0))
{
return CELL_FONT_ERROR_FONT_OPEN_FAILED;
}
font->renderer_addr = 0;
font->fontdata_addr = fontAddr;
font->origin = CELL_FONT_OPEN_MEMORY;
return CELL_OK;
}
error_code cellFontOpenFontFile(vm::ptr<CellFontLibrary> library, vm::cptr<char> fontPath, u32 subNum, s32 uniqueId, vm::ptr<CellFont> font)
{
cellFont.todo("cellFontOpenFontFile(library=*0x%x, fontPath=%s, subNum=%d, uniqueId=%d, font=*0x%x)", library, fontPath, subNum, uniqueId, font);
if (!font)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
// TODO: reset some font fields here
if (!library)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (false) // TODO
{
return CELL_FONT_ERROR_UNINITIALIZED;
}
if (!fontPath || uniqueId < 0)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
// TODO
fs::file f(vfs::get(fontPath.get_ptr()));
if (!f)
{
return CELL_FONT_ERROR_FONT_OPEN_FAILED;
}
u32 fileSize = ::size32(f);
u32 bufferAddr = vm::alloc(fileSize, vm::main); // Freed in cellFontCloseFont
f.read(vm::base(bufferAddr), fileSize);
s32 ret = cellFontOpenFontMemory(library, bufferAddr, fileSize, subNum, uniqueId, font);
font->origin = CELL_FONT_OPEN_FONT_FILE;
return ret;
}
error_code cellFontOpenFontset(vm::ptr<CellFontLibrary> library, vm::ptr<CellFontType> fontType, vm::ptr<CellFont> font)
{
cellFont.warning("cellFontOpenFontset(library=*0x%x, fontType=*0x%x, font=*0x%x)", library, fontType, font);
if (!font)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
// TODO: reset some font fields here
if (!library || !fontType)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (false) // TODO
{
return CELL_FONT_ERROR_UNINITIALIZED;
}
// TODO
if (fontType->map != CELL_FONT_MAP_UNICODE)
{
cellFont.warning("cellFontOpenFontset: Only Unicode is supported");
}
std::string file;
switch (fontType->type)
{
case CELL_FONT_TYPE_RODIN_SANS_SERIF_LATIN: file = "/dev_flash/data/font/SCE-PS3-RD-R-LATIN.TTF"; break;
case CELL_FONT_TYPE_RODIN_SANS_SERIF_LIGHT_LATIN: file = "/dev_flash/data/font/SCE-PS3-RD-L-LATIN.TTF"; break;
case CELL_FONT_TYPE_RODIN_SANS_SERIF_BOLD_LATIN: file = "/dev_flash/data/font/SCE-PS3-RD-B-LATIN.TTF"; break;
case CELL_FONT_TYPE_RODIN_SANS_SERIF_LATIN2: file = "/dev_flash/data/font/SCE-PS3-RD-R-LATIN2.TTF"; break;
case CELL_FONT_TYPE_RODIN_SANS_SERIF_LIGHT_LATIN2: file = "/dev_flash/data/font/SCE-PS3-RD-L-LATIN2.TTF"; break;
case CELL_FONT_TYPE_RODIN_SANS_SERIF_BOLD_LATIN2: file = "/dev_flash/data/font/SCE-PS3-RD-B-LATIN2.TTF"; break;
case CELL_FONT_TYPE_MATISSE_SERIF_LATIN: file = "/dev_flash/data/font/SCE-PS3-MT-R-LATIN.TTF"; break;
case CELL_FONT_TYPE_NEWRODIN_GOTHIC_JAPANESE: file = "/dev_flash/data/font/SCE-PS3-NR-R-JPN.TTF"; break;
case CELL_FONT_TYPE_NEWRODIN_GOTHIC_LIGHT_JAPANESE: file = "/dev_flash/data/font/SCE-PS3-NR-L-JPN.TTF"; break;
case CELL_FONT_TYPE_NEWRODIN_GOTHIC_BOLD_JAPANESE: file = "/dev_flash/data/font/SCE-PS3-NR-B-JPN.TTF"; break;
case CELL_FONT_TYPE_YD_GOTHIC_KOREAN: file = "/dev_flash/data/font/SCE-PS3-YG-R-KOR.TTF"; break;
case CELL_FONT_TYPE_SEURAT_MARU_GOTHIC_LATIN: file = "/dev_flash/data/font/SCE-PS3-SR-R-LATIN.TTF"; break;
case CELL_FONT_TYPE_SEURAT_MARU_GOTHIC_LATIN2: file = "/dev_flash/data/font/SCE-PS3-SR-R-LATIN2.TTF"; break;
case CELL_FONT_TYPE_VAGR_SANS_SERIF_ROUND: file = "/dev_flash/data/font/SCE-PS3-VR-R-LATIN.TTF"; break;
case CELL_FONT_TYPE_VAGR_SANS_SERIF_ROUND_LATIN2: file = "/dev_flash/data/font/SCE-PS3-VR-R-LATIN2.TTF"; break;
case CELL_FONT_TYPE_SEURAT_MARU_GOTHIC_JAPANESE: file = "/dev_flash/data/font/SCE-PS3-SR-R-JPN.TTF"; break;
case CELL_FONT_TYPE_NEWRODIN_GOTHIC_JP_SET:
case CELL_FONT_TYPE_NEWRODIN_GOTHIC_LATIN_SET:
case CELL_FONT_TYPE_NEWRODIN_GOTHIC_RODIN_SET:
case CELL_FONT_TYPE_NEWRODIN_GOTHIC_RODIN2_SET:
case CELL_FONT_TYPE_NEWRODIN_GOTHIC_YG_RODIN2_SET:
case CELL_FONT_TYPE_NEWRODIN_GOTHIC_YG_DFHEI5_SET:
case CELL_FONT_TYPE_NEWRODIN_GOTHIC_YG_DFHEI5_RODIN_SET:
case CELL_FONT_TYPE_NEWRODIN_GOTHIC_YG_DFHEI5_RODIN2_SET:
case CELL_FONT_TYPE_DFHEI5_GOTHIC_YG_NEWRODIN_TCH_SET:
case CELL_FONT_TYPE_DFHEI5_GOTHIC_YG_NEWRODIN_RODIN_TCH_SET:
case CELL_FONT_TYPE_DFHEI5_GOTHIC_YG_NEWRODIN_RODIN2_TCH_SET:
case CELL_FONT_TYPE_DFHEI5_GOTHIC_YG_NEWRODIN_SCH_SET:
case CELL_FONT_TYPE_DFHEI5_GOTHIC_YG_NEWRODIN_RODIN_SCH_SET:
case CELL_FONT_TYPE_DFHEI5_GOTHIC_YG_NEWRODIN_RODIN2_SCH_SET:
case CELL_FONT_TYPE_SEURAT_MARU_GOTHIC_RSANS_SET:
case CELL_FONT_TYPE_SEURAT_CAPIE_MARU_GOTHIC_RSANS_SET:
case CELL_FONT_TYPE_SEURAT_CAPIE_MARU_GOTHIC_JP_SET:
case CELL_FONT_TYPE_SEURAT_MARU_GOTHIC_YG_DFHEI5_RSANS_SET:
case CELL_FONT_TYPE_SEURAT_CAPIE_MARU_GOTHIC_YG_DFHEI5_RSANS_SET:
case CELL_FONT_TYPE_VAGR_SEURAT_CAPIE_MARU_GOTHIC_RSANS_SET:
case CELL_FONT_TYPE_VAGR_SEURAT_CAPIE_MARU_GOTHIC_YG_DFHEI5_RSANS_SET:
case CELL_FONT_TYPE_NEWRODIN_GOTHIC_YG_LIGHT_SET:
case CELL_FONT_TYPE_NEWRODIN_GOTHIC_YG_RODIN_LIGHT_SET:
case CELL_FONT_TYPE_NEWRODIN_GOTHIC_YG_RODIN2_LIGHT_SET:
case CELL_FONT_TYPE_NEWRODIN_GOTHIC_RODIN_LIGHT_SET:
case CELL_FONT_TYPE_NEWRODIN_GOTHIC_RODIN2_LIGHT_SET:
case CELL_FONT_TYPE_NEWRODIN_GOTHIC_YG_BOLD_SET:
case CELL_FONT_TYPE_NEWRODIN_GOTHIC_YG_RODIN_BOLD_SET:
case CELL_FONT_TYPE_NEWRODIN_GOTHIC_YG_RODIN2_BOLD_SET:
case CELL_FONT_TYPE_NEWRODIN_GOTHIC_RODIN_BOLD_SET:
case CELL_FONT_TYPE_NEWRODIN_GOTHIC_RODIN2_BOLD_SET:
case CELL_FONT_TYPE_SEURAT_MARU_GOTHIC_RSANS2_SET:
case CELL_FONT_TYPE_SEURAT_CAPIE_MARU_GOTHIC_RSANS2_SET:
case CELL_FONT_TYPE_SEURAT_MARU_GOTHIC_YG_DFHEI5_RSANS2_SET:
case CELL_FONT_TYPE_SEURAT_CAPIE_MARU_GOTHIC_YG_DFHEI5_RSANS2_SET:
case CELL_FONT_TYPE_SEURAT_CAPIE_MARU_GOTHIC_YG_DFHEI5_VAGR2_SET:
case CELL_FONT_TYPE_SEURAT_CAPIE_MARU_GOTHIC_VAGR2_SET:
cellFont.warning("cellFontOpenFontset: fontType->type = %d not supported yet. RD-R-LATIN.TTF will be used instead.", fontType->type);
file = "/dev_flash/data/font/SCE-PS3-RD-R-LATIN.TTF";
break;
default:
return { CELL_FONT_ERROR_NO_SUPPORT_FONTSET, fontType->type };
}
error_code ret = cellFontOpenFontFile(library, vm::make_str(file), 0, 0, font); //TODO: Find the correct values of subNum, uniqueId
font->origin = CELL_FONT_OPEN_FONTSET;
return ret;
}
error_code cellFontOpenFontInstance(vm::ptr<CellFont> openedFont, vm::ptr<CellFont> font)
{
cellFont.todo("cellFontOpenFontInstance(openedFont=*0x%x, font=*0x%x)", openedFont, font);
if (!font)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
// TODO: reset some font fields
if (false) // TODO
{
return CELL_FONT_ERROR_UNINITIALIZED;
}
if (!openedFont)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (false) // TODO: check field 0x10
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
// TODO
font->renderer_addr = openedFont->renderer_addr;
font->scale_x = openedFont->scale_x;
font->scale_y = openedFont->scale_y;
font->slant = openedFont->slant;
font->stbfont = openedFont->stbfont;
font->origin = CELL_FONT_OPEN_FONT_INSTANCE;
return CELL_OK;
}
error_code cellFontSetFontOpenMode(vm::cptr<CellFontLibrary> library, u32 openMode)
{
cellFont.todo("cellFontSetFontOpenMode(library=*0x%x, openMode=0x%x)", library, openMode);
if (false) // TODO
{
return CELL_FONT_ERROR_UNINITIALIZED;
}
if (!library)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
// TODO: set openMode
return CELL_OK;
}
error_code cellFontCreateRenderer(vm::cptr<CellFontLibrary> library, vm::ptr<CellFontRendererConfig> config, vm::ptr<CellFontRenderer> renderer)
{
cellFont.todo("cellFontCreateRenderer(library=*0x%x, config=*0x%x, Renderer=*0x%x)", library, config, renderer);
// Write data in Renderer
if (!library || !config || !renderer)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (false) // TODO: check lib_func
{
return CELL_FONT_ERROR_NO_SUPPORT_FUNCTION;
}
return CELL_OK;
}
void cellFontRenderSurfaceInit(vm::ptr<CellFontRenderSurface> surface, vm::ptr<void> buffer, s32 bufferWidthByte, s32 pixelSizeByte, s32 w, s32 h)
{
cellFont.notice("cellFontRenderSurfaceInit(surface=*0x%x, buffer=*0x%x, bufferWidthByte=%d, pixelSizeByte=%d, w=%d, h=%d)", surface, buffer, bufferWidthByte, pixelSizeByte, w, h);
if (!surface)
{
return;
}
const u32 width = w & ~w >> 0x1f;
const u32 height = h & ~h >> 0x1f;
surface->buffer = buffer;
surface->widthByte = bufferWidthByte;
surface->pixelSizeByte = pixelSizeByte;
surface->width = width;
surface->height = height;
surface->sc_x0 = 0;
surface->sc_y0 = 0;
surface->sc_x1 = width;
surface->sc_y1 = height;
}
void cellFontRenderSurfaceSetScissor(vm::ptr<CellFontRenderSurface> surface, s32 x0, s32 y0, u32 w, u32 h)
{
cellFont.warning("cellFontRenderSurfaceSetScissor(surface=*0x%x, x0=%d, y0=%d, w=%d, h=%d)", surface, x0, y0, w, h);
if (!surface)
{
return;
}
// TODO: sdk check ?
if (true)
{
if (surface->width != 0)
{
u32 sc_x0 = 0;
u32 sc_x1 = 0;
if (x0 < 0)
{
if (static_cast<u32>(-x0) < w)
{
sc_x1 = surface->width;
if (x0 + w < sc_x1)
{
sc_x1 = x0 + w;
}
}
}
else
{
const u32 width = surface->width;
sc_x0 = width;
sc_x1 = width;
if (static_cast<u32>(x0) <= sc_x0)
{
sc_x0 = x0;
const u32 w_min = std::min(w, width);
if (x0 + w_min <= width)
{
sc_x1 = x0 + w_min;
}
}
}
surface->sc_x0 = sc_x0;
surface->sc_x1 = sc_x1;
}
if (surface->height != 0)
{
u32 sc_y0 = 0;
u32 sc_y1 = 0;
if (y0 < 0)
{
if (static_cast<u32>(-y0) < h)
{
sc_y1 = surface->height;
if (y0 + h < sc_y1)
{
sc_y1 = y0 + h;
}
}
}
else
{
const u32 height = surface->height;
sc_y0 = height;
sc_y1 = height;
if (static_cast<u32>(y0) <= sc_y0)
{
sc_y0 = y0;
const u32 h_min = std::min(h, height);
if (y0 + h_min <= sc_y1)
{
sc_y1 = y0 + h_min;
}
}
}
surface->sc_y0 = sc_y0;
surface->sc_y1 = sc_y1;
}
}
else
{
if (surface->width != 0)
{
if (static_cast<s32>(surface->sc_x0) < x0)
{
surface->sc_x0 = x0;
}
if (static_cast<s32>(w + x0) < static_cast<s32>(surface->sc_x1))
{
surface->sc_x1 = w + x0;
}
}
if (surface->height != 0)
{
if (static_cast<s32>(surface->sc_y0) < y0)
{
surface->sc_y0 = y0;
}
if (static_cast<s32>(h + y0) < static_cast<s32>(surface->sc_y1))
{
surface->sc_y1 = h + y0;
}
}
}
}
error_code cellFontSetScalePixel(vm::ptr<CellFont> font, f32 w, f32 h)
{
cellFont.todo("cellFontSetScalePixel(font=*0x%x, w=%f, h=%f)", font, w, h);
if (!font)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
font->scale_x = w;
font->scale_y = h;
// TODO:
//font->scalePointH = (h * something) / font->resolutionDpiV;
//font->scalePointW = (w * something) / font->resolutionDpiH;
return CELL_OK;
}
error_code cellFontGetHorizontalLayout(vm::ptr<CellFont> font, vm::ptr<CellFontHorizontalLayout> layout)
{
cellFont.todo("cellFontGetHorizontalLayout(font=*0x%x, layout=*0x%x)", font, layout);
if (!layout)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
*layout = {};
if (!font)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
s32 ascent, descent, lineGap;
const f32 scale = stbtt_ScaleForPixelHeight(font->stbfont, font->scale_y);
stbtt_GetFontVMetrics(font->stbfont, &ascent, &descent, &lineGap);
layout->baseLineY = ascent * scale;
layout->lineHeight = (ascent-descent+lineGap) * scale;
layout->effectHeight = lineGap * scale;
return CELL_OK;
}
error_code cellFontBindRenderer(vm::ptr<CellFont> font, vm::ptr<CellFontRenderer> renderer)
{
cellFont.warning("cellFontBindRenderer(font=*0x%x, renderer=*0x%x)", font, renderer);
if (!font || !renderer || !renderer->systemReserved[0x10])
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (font->renderer_addr)
{
return CELL_FONT_ERROR_RENDERER_ALREADY_BIND;
}
// TODO
//renderer->systemReserved[2] = (void *)font->resolutionDpiH;
//renderer->systemReserved[3] = (void *)font->resolutionDpiV;
//renderer->systemReserved[4] = (void *)font->scalePointW;
//renderer->systemReserved[5] = (void *)font->scalePointH;
//renderer->systemReserved[6] = (void *)font->scalePixelW;
//renderer->systemReserved[7] = (void *)font->scalePixelH;
//renderer->systemReserved[8] = *(void **)&font->font_weight;
//renderer->systemReserved[9] = *(void **)&font->field_0x5c;
font->renderer_addr = renderer.addr();
return CELL_OK;
}
error_code cellFontUnbindRenderer(vm::ptr<CellFont> font)
{
cellFont.warning("cellFontBindRenderer(font=*0x%x)", font);
if (!font)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (!font->renderer_addr)
{
return CELL_FONT_ERROR_RENDERER_UNBIND;
}
font->renderer_addr = 0;
return CELL_OK;
}
error_code cellFontDestroyRenderer(vm::ptr<CellFontRenderer> renderer)
{
cellFont.todo("cellFontDestroyRenderer(renderer=*0x%x)", renderer);
if (!renderer || !renderer->systemReserved[0x10])
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (false) // TODO: check func
{
return CELL_FONT_ERROR_NO_SUPPORT_FUNCTION;
}
if (false) // TODO: call func
{
renderer->systemReserved[0x10] = vm::null;
}
return CELL_OK;
}
error_code cellFontSetupRenderScalePixel(vm::ptr<CellFont> font, f32 w, f32 h)
{
cellFont.todo("cellFontSetupRenderScalePixel(font=*0x%x, w=%f, h=%f)", font, w, h);
if (!font)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (false) // TODO (!font->field_0xc || !font->library)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (!font->renderer_addr)
{
return CELL_FONT_ERROR_RENDERER_UNBIND;
}
// TODO:
//if (w == something)
//{
// w = font->scalePixelW;
//}
//if (h == something)
//{
// h = font->scalePixelH;
//}
//font->field_0x14 + 0x10 = (w * something) / font->resolutionDpiH;
//font->field_0x14 + 0x14 = (h * something) / font->resolutionDpiV;
//font->field_0x14 + 0x18 = w;
//font->field_0x14 + 0x1c = h;
//font->field_0x78 = 0;
return CELL_OK;
}
error_code cellFontGetRenderCharGlyphMetrics(vm::ptr<CellFont> font, u32 code, vm::ptr<CellFontGlyphMetrics> metrics)
{
cellFont.todo("cellFontGetRenderCharGlyphMetrics(font=*0x%x, code=0x%x, metrics=*0x%x)", font, code, metrics);
if (!font)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (false) // TODO (!font->field_0xc || !font->library)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (!font->renderer_addr)
{
return CELL_FONT_ERROR_RENDERER_UNBIND;
}
if (!metrics)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
// TODO: ?
return CELL_OK;
}
error_code cellFontRenderCharGlyphImage(vm::ptr<CellFont> font, u32 code, vm::ptr<CellFontRenderSurface> surface, f32 x, f32 y, vm::ptr<CellFontGlyphMetrics> metrics, vm::ptr<CellFontImageTransInfo> transInfo)
{
cellFont.notice("cellFontRenderCharGlyphImage(font=*0x%x, code=0x%x, surface=*0x%x, x=%f, y=%f, metrics=*0x%x, transInfo=*0x%x)", font, code, surface, x, y, metrics, transInfo);
if (!font->renderer_addr)
{
return CELL_FONT_ERROR_RENDERER_UNBIND;
}
// Render the character
s32 width, height, xoff, yoff;
const f32 scale = stbtt_ScaleForPixelHeight(font->stbfont, font->scale_y);
unsigned char* box = stbtt_GetCodepointBitmap(font->stbfont, scale, scale, code, &width, &height, &xoff, &yoff);
if (!box)
{
return CELL_OK;
}
// Get the baseLineY value
s32 ascent, descent, lineGap;
stbtt_GetFontVMetrics(font->stbfont, &ascent, &descent, &lineGap);
const s32 baseLineY = static_cast<int>(ascent * scale); // ???
// Move the rendered character to the surface
unsigned char* buffer = vm::_ptr<unsigned char>(surface->buffer.addr());
for (u32 ypos = 0; ypos < static_cast<u32>(height); ypos++)
{
if (static_cast<u32>(y) + ypos + yoff + baseLineY >= static_cast<u32>(surface->height))
break;
for (u32 xpos = 0; xpos < static_cast<u32>(width); xpos++)
{
if (static_cast<u32>(x) + xpos >= static_cast<u32>(surface->width))
break;
// TODO: There are some oddities in the position of the character in the final buffer
buffer[(static_cast<s32>(y) + ypos + yoff + baseLineY) * surface->width + static_cast<s32>(x) + xpos] = box[ypos * width + xpos];
}
}
stbtt_FreeBitmap(box, nullptr);
return CELL_OK;
}
error_code cellFontEndLibrary(vm::cptr<CellFontLibrary> library)
{
cellFont.todo("cellFontEndLibrary(library=*0x%x)", library);
if (false) // TODO
{
return CELL_FONT_ERROR_UNINITIALIZED;
}
return CELL_OK;
}
error_code cellFontSetEffectSlant(vm::ptr<CellFont> font, f32 slantParam)
{
cellFont.trace("cellFontSetEffectSlant(font=*0x%x, slantParam=%f)", font, slantParam);
if (!font)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
// TODO: I think this clamps instead of returning an error
if (slantParam < -1.0f || slantParam > 1.0f)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
font->slant = slantParam;
return CELL_OK;
}
error_code cellFontGetEffectSlant(vm::ptr<CellFont> font, vm::ptr<f32> slantParam)
{
cellFont.trace("cellFontSetEffectSlant(font=*0x%x, slantParam=*0x%x)", font, slantParam);
if (!font || !slantParam)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
*slantParam = font->slant;
return CELL_OK;
}
error_code cellFontGetFontIdCode(vm::ptr<CellFont> font, u32 code, vm::ptr<u32> fontId, vm::ptr<u32> fontCode)
{
cellFont.todo("cellFontGetFontIdCode(font=*0x%x, code=%d, fontId=*0x%x, fontCode=*0x%x)", font, code, fontId, fontCode);
if (fontId)
{
*fontId = 0;
}
if (fontCode)
{
*fontCode = 0;
}
if (!font) // TODO || !font->library)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
// TODO: some other code goes here
if (false) // TODO (!font->field_0x2)
{
if (false) // TODO (font->field_0x60 != code)
{
if (false) // TODO
{
return CELL_FONT_ERROR_NO_SUPPORT_CODE;
}
// TODO: some other stuff
return CELL_OK;
}
if (fontId)
{
//*fontId = font->field_0x64; // TODO
}
if (fontCode)
{
//*fontCode = font->field_0x68; // TODO
}
}
else
{
if (fontId)
{
//*fontId = font->field_0x8 & 0x7fffffff; // TODO
}
if (fontCode)
{
*fontCode = code;
}
}
return CELL_OK;
}
error_code cellFontCloseFont(vm::ptr<CellFont> font)
{
cellFont.todo("cellFontCloseFont(font=*0x%x)", font);
if (!font)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (font->origin == CELL_FONT_OPEN_FONTSET ||
font->origin == CELL_FONT_OPEN_FONT_FILE ||
font->origin == CELL_FONT_OPEN_MEMORY)
{
vm::dealloc(font->fontdata_addr, vm::main);
}
return CELL_OK;
}
error_code cellFontGetCharGlyphMetrics(vm::ptr<CellFont> font, u32 code, vm::ptr<CellFontGlyphMetrics> metrics)
{
cellFont.todo("cellFontGetCharGlyphMetrics(font=*0x%x, code=0x%x, metrics=*0x%x)", font, code, metrics);
if (!font || !metrics)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (false) // TODO (!font->field_0xc || !font->library)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (false) // TODO
{
return CELL_FONT_ERROR_NO_SUPPORT_CODE;
}
s32 x0, y0, x1, y1;
s32 advanceWidth, leftSideBearing;
const f32 scale = stbtt_ScaleForPixelHeight(font->stbfont, font->scale_y);
stbtt_GetCodepointBox(font->stbfont, code, &x0, &y0, &x1, &y1);
stbtt_GetCodepointHMetrics(font->stbfont, code, &advanceWidth, &leftSideBearing);
// TODO: Add the rest of the information
metrics->width = (x1-x0) * scale;
metrics->height = (y1-y0) * scale;
metrics->h_bearingX = leftSideBearing * scale;
metrics->h_bearingY = 0.f;
metrics->h_advance = advanceWidth * scale;
metrics->v_bearingX = 0.f;
metrics->v_bearingY = 0.f;
metrics->v_advance = 0.f;
return CELL_OK;
}
error_code cellFontGraphicsSetFontRGBA(vm::ptr<CellFontGraphicsDrawContext> context, vm::ptr<f32> fontRGBA)
{
cellFont.todo("cellFontGraphicsSetFontRGBA(context=*0x%x, fontRGBA=*0x%x)", context, fontRGBA);
if (!context || !fontRGBA) // TODO || (context->magic != 0xcf50))
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
// TODO
//context->field_0x70 = fontRGBA[0];
//context->field_0x74 = fontRGBA[1];
//context->field_0x78 = fontRGBA[2];
//context->field_0x7c = fontRGBA[3];
return CELL_OK;
}
error_code cellFontOpenFontsetOnMemory(vm::ptr<CellFontLibrary> library, vm::ptr<CellFontType> fontType, vm::ptr<CellFont> font)
{
cellFont.todo("cellFontOpenFontsetOnMemory(library=*0x%x, fontType=*0x%x, font=*0x%x)", library, fontType, font);
if (!font)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
// TODO: reset some font fields here
if (!library || !fontType)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (false) // TODO
{
return CELL_FONT_ERROR_UNINITIALIZED;
}
if (fontType->map != CELL_FONT_MAP_UNICODE)
{
cellFont.warning("cellFontOpenFontsetOnMemory: Only Unicode is supported");
}
return CELL_OK;
}
error_code cellFontGraphicsSetScalePixel(vm::ptr<CellFontGraphicsDrawContext> context, f32 w, f32 h)
{
cellFont.todo("cellFontGraphicsSetScalePixel(context=*0x%x, w=%f, h=%f)", context, w, h);
if (!context) // TODO || (context->magic != 0xcf50))
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
// TODO
//context->field_0x10 = (w * something) / context->field_0x8;
//context->field_0x14 = (h * something) / context->field_0xc;
//context->field_0x18 = w;
//context->field_0x1c = h;
return CELL_OK;
}
error_code cellFontGraphicsGetScalePixel(vm::ptr<CellFontGraphicsDrawContext> context, vm::ptr<f32> w, vm::ptr<f32> h)
{
cellFont.todo("cellFontGraphicsGetScalePixel(context=*0x%x, w=*0x%x, h=*0x%x)", context, w, h);
if (w)
{
*w = 0.0;
}
if (h)
{
*h = 0.0;
}
if (!context) // TODO || context->magic != 0xcf50)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (w)
{
//*w = context->field_0x18; // TODO
}
if (h)
{
//*h = context->field_0x1c; // TODO
}
return CELL_OK;
}
error_code cellFontSetEffectWeight(vm::ptr<CellFont> font, f32 effectWeight)
{
cellFont.warning("cellFontSetEffectWeight(font=*0x%x, effectWeight=%f)", font, effectWeight);
if (!font)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
// TODO: set effect weight (probably clamped)
return CELL_OK;
}
error_code cellFontGlyphSetupVertexesGlyph(vm::ptr<CellFontGlyph> glyph, f32 controlDistance, vm::ptr<u32> mappedBuf, u32 mappedBufSize, vm::ptr<CellFontVertexesGlyph> vGlyph, vm::ptr<u32> dataSize)
{
cellFont.todo("cellFontGlyphSetupVertexesGlyph(glyph=*0x%x, controlDistance=%f, mappedBuf=*0x%x, mappedBufSize=0x%x, vGlyph=*0x%x, dataSize=*0x%x)", glyph, controlDistance, mappedBuf, mappedBufSize, vGlyph, dataSize);
//if (in_r8)
//{
// *in_r8 = 0; // ???
//}
if (!dataSize)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
dataSize[0] = 0;
dataSize[1] = 0;
if (mappedBufSize == 0)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
// TODO
return CELL_OK;
}
error_code cellFontGetVerticalLayout(vm::ptr<CellFont> font, vm::ptr<CellFontVerticalLayout> layout)
{
cellFont.todo("cellFontGetVerticalLayout(font=*0x%x, layout=*0x%x)", font, layout);
if (!layout)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
*layout = {};
if (!font)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
// TODO
return CELL_OK;
}
error_code cellFontGetRenderCharGlyphMetricsVertical(vm::ptr<CellFont> font, u32 code, vm::ptr<CellFontGlyphMetrics> metrics)
{
cellFont.todo("cellFontGetRenderCharGlyphMetricsVertical(font=*0x%x, code=0x%x, metrics=*0x%x)", font, code, metrics);
if (!font)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (false) // TODO (!font->field_0xc || !font->library)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (false) // TODO (!font->field_0x14)
{
return CELL_FONT_ERROR_RENDERER_UNBIND;
}
// TODO
return CELL_OK;
}
error_code cellFontSetScalePoint(vm::ptr<CellFont> font, f32 w, f32 h)
{
cellFont.todo("cellFontSetScalePoint(font=*0x%x, w=%f, h=%f)", font, w, h);
if (!font)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
// TODO
//font->scalePointW = w;
//font->scalePointH = h;
//font->scalePixelW = (w * font->resolutionDpiH) / something;
//font->scalePixelH = (h * font->resolutionDpiV) / something;
return CELL_OK;
}
error_code cellFontSetupRenderEffectSlant(vm::ptr<CellFont> font, f32 effectSlant)
{
cellFont.todo("cellFontSetupRenderEffectSlant(font=*0x%x, effectSlant=%f)", font, effectSlant);
if (!font)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (false) // TODO (!font->field_0xc || !font->library)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (false) // TODO (!font->field_0x14)
{
return CELL_FONT_ERROR_RENDERER_UNBIND;
}
// TODO:
//font->effectSlant = effectSlant; // TODO: probably clamped
//font->field_0x78 = 0;
return CELL_OK;
}
error_code cellFontGraphicsSetLineRGBA(vm::ptr<CellFontGraphicsDrawContext> context, vm::ptr<f32> lineRGBA)
{
cellFont.todo("cellFontGraphicsSetLineRGBA(context=*0x%x, lineRGBA=*0x%x)", context, lineRGBA);
if (!context || !lineRGBA) // TODO || (context->magic != 0xcf50))
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
// TODO
//context->lineColorR = lineRGBA[0];
//context->lineColorG = lineRGBA[1];
//context->lineColorB = lineRGBA[2];
//context->lineColorA = lineRGBA[3];
return CELL_OK;
}
error_code cellFontGraphicsSetDrawType(vm::ptr<CellFontGraphicsDrawContext> context, u32 type)
{
cellFont.todo("cellFontGraphicsSetDrawType(context=*0x%x, type=0x%x)", context, type);
if (!context) // TODO || (context->magic != 0xcf50))
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
//context->field_0x42 = type; // TODO
return CELL_OK;
}
error_code cellFontEndGraphics(vm::cptr<CellFontGraphics> graphics)
{
cellFont.todo("cellFontEndGraphics(graphics=*0x%x)", graphics);
if (!graphics)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (false) // TODO
{
return CELL_FONT_ERROR_UNINITIALIZED;
}
return CELL_OK;
}
error_code cellFontGraphicsSetupDrawContext(vm::cptr<CellFontGraphics> graphics, vm::ptr<CellFontGraphicsDrawContext> context)
{
cellFont.todo("cellFontGraphicsSetupDrawContext(graphics=*0x%x, context=*0x%x)", graphics, context);
if (!graphics && !context)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
// TODO
//context->magic = 0xcf50;
//context->field_0x50 = something;
//context->field_0x54 = something;
//context->field_0x58 = something;
//context->field_0x5c = something;
//context->field_0x2 = 0;
//context->field_0x8 = 72;
//context->field_0x42 = 1;
//context->field_0x4c = 0;
//context->field_0x4 = 0;
//context->field_0xc = 72;
//context->field_0x14 = 0;
//context->field_0x10 = 0;
//context->field_0x1c = 0;
//context->field_0x18 = 0;
//context->field_0x20 = 0;
//context->field_0x24 = 0;
//context->field_0x28 = 0;
//context->field_0x2c = 0;
//context->field_0x30 = 0;
//context->field_0x34 = 0;
//context->field_0x38 = 0;
//context->field_0x3c = 0;
//context->field_0x40 = 0;
//context->field_0x44 = 0;
//context->field_0x48 = 0;
//context->field_0x7c = something;
//context->field_0x78 = something;
//context->field_0x74 = something;
//context->field_0x70 = something;
//context->lineColorB = 0.0;
//context->lineColorG = 0.0;
//context->lineColorR = 0.0;
//context->lineColorA = something;
//context->field_0xc0 = 0;
//context->field_0x80 = something;
//context->field_0xbc = something;
//context->field_0xa8 = something;
//context->field_0x94 = something;
//context->field_0xb8 = 0;
//context->field_0xb4 = 0;
//context->field_0xb0 = 0;
//context->field_0xac = 0;
//context->field_0xa4 = 0;
//context->field_0xa0 = 0;
//context->field_0x9c = 0;
//context->field_0x98 = 0;
//context->field_0x90 = 0;
//context->field_0x8c = 0;
//context->field_0x88 = 0;
//context->field_0x84 = 0;
//context->field_0xfc = 0;
//context->field_0xf8 = 0;
//context->field_0xf4 = 0;
//context->field_0xf0 = 0;
//context->field_0xec = 0;
//context->field_0xe8 = 0;
//context->field_0xe4 = 0;
//context->field_0xe0 = 0;
//context->field_0xdc = 0;
//context->field_0xd8 = 0;
//context->field_0xd4 = 0;
//context->field_0xd0 = 0;
//context->field_0xcc = 0;
//context->field_0xc8 = 0;
//context->field_0xc4 = 0;
return CELL_OK;
}
error_code cellFontSetupRenderEffectWeight(vm::ptr<CellFont> font, f32 additionalWeight)
{
cellFont.todo("cellFontSetupRenderEffectWeight(font=*0x%x, additionalWeight=%f)", font, additionalWeight);
if (!font)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (false) // TODO (!font->field_0xc || !font->library)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (false) // TODO (!font->field_0x14)
{
return CELL_FONT_ERROR_RENDERER_UNBIND;
}
// TODO: set weight
return CELL_OK;
}
error_code cellFontGlyphGetOutlineControlDistance(vm::ptr<CellFontGlyph> glyph, f32 maxScale, f32 baseControlDistance, vm::ptr<f32> controlDistance)
{
cellFont.todo("cellFontGlyphGetOutlineControlDistance(glyph=*0x%x, maxScale=%f, baseControlDistance=%f, controlDistance=*0x%x)", glyph, maxScale, baseControlDistance, controlDistance);
if (!glyph || !controlDistance || maxScale <= 0.0f)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
// TODO
//*controlDistance = (something / maxScale) * baseControlDistance;
return CELL_OK;
}
error_code cellFontGlyphGetVertexesGlyphSize(vm::ptr<CellFontGlyph> glyph, f32 controlDistance, vm::ptr<u32> useSize)
{
cellFont.todo("cellFontGlyphGetVertexesGlyphSize(glyph=*0x%x, controlDistance=%f, useSize=*0x%x)", glyph, controlDistance, useSize);
if (false) // TODO (!in_r5)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
//*in_r5 = 0; // TODO
if (!glyph)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
// TODO
return CELL_OK;
}
error_code cellFontGenerateCharGlyph(vm::ptr<CellFont> font, u32 code, vm::pptr<CellFontGlyph> glyph)
{
cellFont.todo("cellFontGenerateCharGlyph(font=*0x%x, code=0x%x, glyph=*0x%x)", font, code, glyph);
if (false) // TODO
{
return CELL_FONT_ERROR_NO_SUPPORT_FUNCTION;
}
if (!font)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
// TODO
return CELL_OK;
}
error_code cellFontDeleteGlyph(vm::ptr<CellFont> font, vm::ptr<CellFontGlyph> glyph)
{
cellFont.todo("cellFontDeleteGlyph(font=*0x%x, glyph=*0x%x)", font, glyph);
if (false) // TODO
{
return CELL_FONT_ERROR_NO_SUPPORT_FUNCTION;
}
if (!font)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (false && !glyph) // TODO
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
// TODO
return CELL_OK;
}
error_code cellFontExtend(u32 a1, u32 a2, u32 a3)
{
cellFont.todo("cellFontExtend(a1=0x%x, a2=0x%x, a3=0x%x)", a1, a2, a3);
//In a test I did: a1=0xcfe00000, a2=0x0, a3=(pointer to something)
if (a1 == 0xcfe00000)
{
if (a2 != 0 || a3 == 0)
{
//Something happens
}
if (vm::read32(a3) == 0u)
{
//Something happens
}
//Something happens
}
//Something happens?
return CELL_OK;
}
error_code cellFontRenderCharGlyphImageVertical(vm::ptr<CellFont> font, u32 code, vm::ptr<CellFontRenderSurface> surface, f32 x, f32 y, vm::ptr<CellFontGlyphMetrics> metrics, vm::ptr<CellFontImageTransInfo> transInfo)
{
cellFont.todo("cellFontRenderCharGlyphImageVertical(font=*0x%x, code=0x%x, surface=*0x%x, x=%f, y=%f, metrics=*0x%x, transInfo=*0x%x)", font, code, surface, x, y, metrics, transInfo);
return CELL_OK;
}
error_code cellFontSetResolutionDpi(vm::ptr<CellFont> font, u32 hDpi, u32 vDpi)
{
cellFont.todo("cellFontSetResolutionDpi(font=*0x%x, hDpi=0x%x, vDpi=0x%x)", font, hDpi, vDpi);
if (!font)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
// TODO
// font->resolutionDpiH = hDpi == 0 ? 72 : hDpi;
// font->resolutionDpiV = vDpi == 0 ? 72 : vDpi;
return CELL_OK;
}
error_code cellFontGetCharGlyphMetricsVertical(vm::ptr<CellFont> font, u32 code, vm::ptr<CellFontGlyphMetrics> metrics)
{
cellFont.todo("cellFontGetCharGlyphMetricsVertical(font=*0x%x, code=0x%x, metrics=*0x%x)", font, code, metrics);
if (!font || !metrics)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (false) // TODO (!font->field_0xc || !font->library)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (false) // TODO
{
return CELL_FONT_ERROR_NO_SUPPORT_CODE;
}
// TODO
return CELL_OK;
}
error_code cellFontGetRenderEffectWeight(vm::ptr<CellFont> font, vm::ptr<f32> effectWeight)
{
cellFont.todo("cellFontGetRenderEffectWeight(font=*0x%x, effectWeight=*0x%x)", font, effectWeight);
if (!font)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (false) // TODO (!font->field_0xc || !font->library)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (false) // TODO (!font->field_0x14)
{
return CELL_FONT_ERROR_RENDERER_UNBIND;
}
if (effectWeight) // Technically unchecked in firmware
{
// TODO
//*effectWeight = font->field_0x14 + 0x20;
}
return CELL_OK;
}
error_code cellFontGraphicsGetDrawType(vm::ptr<CellFontGraphicsDrawContext> context, vm::ptr<u32> type)
{
cellFont.todo("cellFontGraphicsGetDrawType(context=*0x%x, type=*0x%x)", context, type);
if (!context || !type)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (false) // TODO (context->magic != 0xcf50)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
//*type = context->field_0x42; // TODO
return CELL_OK;
}
error_code cellFontGetKerning(vm::ptr<CellFont> font, u32 preCode, u32 code, vm::ptr<CellFontKerning> kerning)
{
cellFont.todo("cellFontGetKerning(font=*0x%x, preCode=0x%x, code=0x%x, kerning=*0x%x)", font, preCode, code, kerning);
if (!kerning)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
*kerning = {};
if (!font)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (false) // TODO (!font->field_0xc || !font->library)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (preCode == 0 || code == 0)
{
return CELL_OK;
}
// TODO
return CELL_OK;
}
error_code cellFontGetRenderScaledKerning(vm::ptr<CellFont> font, u32 preCode, u32 code, vm::ptr<CellFontKerning> kerning)
{
cellFont.todo("cellFontGetRenderScaledKerning(font=*0x%x, preCode=0x%x, code=0x%x, kerning=*0x%x)", font, preCode, code, kerning);
if (!kerning)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
*kerning = {};
if (!font)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (false) // TODO: !font->field_0x14
{
return CELL_FONT_ERROR_RENDERER_UNBIND;
}
if (false) // TODO (!font->field_0xc || !font->library)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (preCode == 0 || code == 0)
{
return CELL_OK;
}
// TODO
return CELL_OK;
}
error_code cellFontGetRenderScalePixel(vm::ptr<CellFont> font, vm::ptr<f32> w, vm::ptr<f32> h)
{
cellFont.todo("cellFontGetRenderScalePixel(font=*0x%x, w=*0x%x, h=*0x%x)", font, w, h);
if (!font)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (false) // TODO (!font->field_0xc || !font->library)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (false) // TODO: !font->field_0x14
{
return CELL_FONT_ERROR_RENDERER_UNBIND;
}
if (w)
{
//*w = font->field_0x14 + 0x18; // TODO
}
if (h)
{
//*h = font->field_0x14 + 0x1c; // TODO
}
return CELL_OK;
}
error_code cellFontGlyphGetScalePixel(vm::ptr<CellFontGlyph> glyph, vm::ptr<f32> w, vm::ptr<f32> h)
{
cellFont.todo("cellFontGlyphGetScalePixel(glyph=*0x%x, w=*0x%x, h=*0x%x)", glyph, w, h);
if (!glyph)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (w)
{
*w = 0.0f;
}
if (h)
{
*h = 0.0f;
}
if (!glyph->Outline.generateEnv)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (w)
{
//*w = glyph->Outline.generateEnv[0]; // TODO
}
if (h)
{
//*h = glyph->Outline.generateEnv[1]; // TODO
}
return CELL_OK;
}
error_code cellFontGlyphGetHorizontalShift(vm::ptr<CellFontGlyph> glyph, vm::ptr<f32> shiftX, vm::ptr<f32> shiftY)
{
cellFont.todo("cellFontGlyphGetHorizontalShift(glyph=*0x%x, shiftX=*0x%x, shiftY=*0x%x)", glyph, shiftX, shiftY);
if (false) // TODO
{
return CELL_FONT_ERROR_NO_SUPPORT_FUNCTION;
}
if (!glyph)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (glyph->Outline.generateEnv)
{
if (shiftX)
{
*shiftX = 0.0;
}
if (shiftY)
{
//*shiftY = glyph->Outline.generateEnv + 0x48; // TODO
}
}
return CELL_OK;
}
error_code cellFontRenderCharGlyphImageHorizontal(vm::ptr<CellFont> font, u32 code, vm::ptr<CellFontRenderSurface> surface, f32 x, f32 y, vm::ptr<CellFontGlyphMetrics> metrics, vm::ptr<CellFontImageTransInfo> transInfo)
{
cellFont.todo("cellFontRenderCharGlyphImageHorizontal(font=*0x%x, code=0x%x, surface=*0x%x, x=%f, y=%f, metrics=*0x%x, transInfo=*0x%x)", font, code, surface, x, y, metrics, transInfo);
return CELL_OK;
}
error_code cellFontGetEffectWeight(vm::ptr<CellFont> font, vm::ptr<f32> effectWeight)
{
cellFont.todo("cellFontGetEffectWeight(font=*0x%x, effectWeight=*0x%x)", font, effectWeight);
if (!font || !effectWeight)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
//*effectWeight = font->weight * something; // TODO
return CELL_OK;
}
error_code cellFontGetScalePixel(vm::ptr<CellFont> font, vm::ptr<f32> w, vm::ptr<f32> h)
{
cellFont.todo("cellFontGetScalePixel(font=*0x%x, w=*0x%x, h=*0x%x)", font, w, h);
if (!font)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (w)
{
//*w = font->scalePixelW; // TODO
}
if (h)
{
//*h = font->scalePixelH; // TODO
}
return CELL_OK;
}
error_code cellFontClearFileCache()
{
cellFont.todo("cellFontClearFileCache()");
return CELL_OK;
}
error_code cellFontAdjustFontScaling(vm::ptr<CellFont> font, f32 fontScale)
{
cellFont.todo("cellFontAdjustFontScaling(font=*0x%x, fontScale=%f)", font, fontScale);
if (!font)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (false) // TODO (!font->field_0x2)
{
return CELL_FONT_ERROR_NO_SUPPORT_FUNCTION;
}
// TODO: set font scale (probably clamped)
return CELL_OK;
}
error_code cellFontSetupRenderScalePoint(vm::ptr<CellFont> font, f32 w, f32 h)
{
cellFont.todo("cellFontSetupRenderScalePoint(font=*0x%x, w=%f, h=%f)", font, w, h);
if (!font)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (false) // TODO (!font->field_0xc || !font->library)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (!font->renderer_addr)
{
return CELL_FONT_ERROR_RENDERER_UNBIND;
}
// TODO:
//if (w == something)
//{
// w = font->scalePointW;
//}
//if (h == something)
//{
// h = font->scalePointH;
//}
//font->field_0x14 + 0x10 = w;
//font->field_0x14 + 0x14 = h;
//font->field_0x14 + 0x18 = (w * font->resolutionDpiH / something;
//font->field_0x14 + 0x1c = (h * font->resolutionDpiV / something;
//font->field_0x78 = 0;
return CELL_OK;
}
error_code cellFontGlyphGetVerticalShift(vm::ptr<CellFontGlyph> glyph, vm::ptr<f32> shiftX, vm::ptr<f32> shiftY)
{
cellFont.todo("cellFontGlyphGetVerticalShift(glyph=*0x%x, shiftX=*0x%x, shiftY=*0x%x)", glyph, shiftX, shiftY);
if (false) // TODO
{
return CELL_FONT_ERROR_NO_SUPPORT_FUNCTION;
}
if (!glyph || !glyph->Outline.generateEnv)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
// TODO
//fVar1 = glyph->Outline.generateEnv + 0x4c;
//fVar2 = glyph->Outline.generateEnv + 0x48;
//if (fVar1 == something)
//{
// fVar1 = (glyph->Outline.generateEnv + 0x4) / (glyph->Outline.generateEnv + 0x14) * (glyph->Outline.generateEnv + 0x18);
//}
//if (shiftX)
//{
// *shiftX = glyph->Outline.generateEnv + 0x38;
//}
//if (shiftY)
//{
// *shiftY = -fVar2 + fVar1 + (glyph->Outline.generateEnv + 0x3c);
//}
return CELL_OK;
}
error_code cellFontGetGlyphExpandBufferInfo(vm::ptr<CellFont> font, vm::ptr<s32> pointN, vm::ptr<s32> contourN)
{
cellFont.todo("cellFontGetGlyphExpandBufferInfo(font=*0x%x, pointN=*0x%x, contourN=*0x%x)", font, pointN, contourN);
if (pointN)
{
*pointN = 0;
}
if (contourN)
{
*contourN = 0;
}
if (!font)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (false) // TODO (!something || !font->library)
{
return CELL_FONT_ERROR_UNINITIALIZED;
}
if (false) // TODO (!font->field_0xc)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
// TODO
return CELL_OK;
}
error_code cellFontGetLibrary(vm::ptr<CellFont> font, vm::cpptr<CellFontLibrary> library, vm::ptr<u32> type)
{
cellFont.todo("cellFontGetLibrary(font=*0x%x, library=*0x%x, type=*0x%x)", font, library, type);
if (!font || !library)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
// TODO
//**library = font->library;
if (!(*library))
{
return CELL_FONT_ERROR_UNINITIALIZED;
}
if (type)
{
*type = (*library)->libraryType;
}
return CELL_OK;
}
error_code cellFontVertexesGlyphRelocate(vm::ptr<CellFontVertexesGlyph> vGlyph, vm::ptr<CellFontVertexesGlyph> vGlyph2, vm::ptr<CellFontVertexesGlyphSubHeader> subHeader, vm::ptr<u32> localBuf, u32 copySize)
{
cellFont.todo("cellFontVertexesGlyphRelocate(vGlyph=*0x%x, vGlyph2=*0x%x, subHeader=*0x%x, localBuf=*0x%x, copySize=0x%x)", vGlyph, vGlyph2, subHeader, localBuf, copySize);
if (!vGlyph2)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (vGlyph2 != vGlyph)
{
vGlyph2->subHeader = vm::null;
vGlyph2->data = vm::null;
}
if (!vGlyph || !subHeader)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
return CELL_OK;
}
error_code cellFontGetInitializedRevisionFlags(vm::ptr<u64> revisionFlags)
{
cellFont.todo("cellFontGetInitializedRevisionFlags(revisionFlags=*0x%x)", revisionFlags);
if (revisionFlags)
{
*revisionFlags = 0;
}
if (false) // TODO
{
return CELL_FONT_ERROR_UNINITIALIZED;
}
if (revisionFlags)
{
//*revisionFlags = something; // TODO
}
return CELL_OK;
}
error_code cellFontGetResolutionDpi(vm::ptr<CellFont> font, vm::ptr<u32> hDpi, vm::ptr<u32> vDpi)
{
cellFont.todo("cellFontGetResolutionDpi(font=*0x%x, hDpi=*0x%x, vDpi=*0x%x)", font, hDpi, vDpi);
if (!font)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (hDpi)
{
//*hDpi = font->resolutionDpiH; // TODO
}
if (vDpi)
{
//*vDpi = font->resolutionDpiV; // TODO
}
return CELL_OK;
}
error_code cellFontGlyphRenderImageVertical(vm::ptr<CellFontGlyph> font, vm::ptr<CellFontGlyphStyle> style, vm::ptr<CellFontRenderer> renderer, vm::ptr<CellFontRenderSurface> surf, f32 x, f32 y, vm::ptr<CellFontGlyphMetrics> metrics, vm::ptr<CellFontImageTransInfo> transInfo)
{
cellFont.todo("cellFontGlyphRenderImageVertical(font=*0x%x, style=*0x%x, renderer=*0x%x, surf=*0x%x, x=%f, y=%f, metrics=*0x%x, transInfo=*0x%x)", font, style, renderer, surf, x, y, metrics, transInfo);
if (false) // TODO
{
return CELL_FONT_ERROR_NO_SUPPORT_FUNCTION;
}
if (!font || !renderer || !renderer->systemReserved[0x10])
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
// TODO
return CELL_OK;
}
error_code cellFontGlyphRenderImageHorizontal(vm::ptr<CellFontGlyph> font, vm::ptr<CellFontGlyphStyle> style, vm::ptr<CellFontRenderer> renderer, vm::ptr<CellFontRenderSurface> surf, f32 x, f32 y, vm::ptr<CellFontGlyphMetrics> metrics, vm::ptr<CellFontImageTransInfo> transInfo)
{
cellFont.todo("cellFontGlyphRenderImageHorizontal(font=*0x%x, style=*0x%x, renderer=*0x%x, surf=*0x%x, x=%f, y=%f, metrics=*0x%x, transInfo=*0x%x)", font, style, renderer, surf, x, y, metrics, transInfo);
if (false) // TODO
{
return CELL_FONT_ERROR_NO_SUPPORT_FUNCTION;
}
if (!font || !renderer || !renderer->systemReserved[0x10])
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
// TODO
return CELL_OK;
}
error_code cellFontAdjustGlyphExpandBuffer(vm::ptr<CellFont> font, s32 pointN, s32 contourN)
{
cellFont.todo("cellFontAdjustGlyphExpandBuffer(font=*0x%x, pointN=%d, contourN=%d)", font, pointN, contourN);
if (!font)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (false) // TODO (!something || !font->library)
{
return CELL_FONT_ERROR_UNINITIALIZED;
}
if (false) // TODO (!font->field_0xc)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
return CELL_OK;
}
error_code cellFontGetRenderScalePoint(vm::ptr<CellFont> font, vm::ptr<f32> w, vm::ptr<f32> h)
{
cellFont.todo("cellFontGetRenderScalePoint(font=*0x%x, w=*0x%x, h=*0x%x)", font, w, h);
if (!font)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (false) // TODO (!font->field_0xc || !font->library)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (false) // TODO: !font->field_0x14
{
return CELL_FONT_ERROR_RENDERER_UNBIND;
}
if (w)
{
//*w = font->field_0x14 + 0x10; // TODO
}
if (h)
{
//*h = font->field_0x14 + 0x14; // TODO
}
return CELL_OK;
}
error_code cellFontGraphicsGetFontRGBA(vm::ptr<CellFontGraphicsDrawContext> context, vm::ptr<f32> fontRGBA)
{
cellFont.todo("cellFontGraphicsGetFontRGBA(context=*0x%x, fontRGBA=*0x%x)", context, fontRGBA);
if (!context || !fontRGBA)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (false) // TODO: (context->magic != 0xcf50)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
// TODO
//fontRGBA[0] = context->field_0x70;
//fontRGBA[1] = context->field_0x74;
//fontRGBA[2] = context->field_0x78;
//fontRGBA[3] = context->field_0x7c;
return CELL_OK;
}
error_code cellFontGlyphGetOutlineVertexes(vm::ptr<CellFontGlyph> glyph, f32 controlDistance, vm::ptr<CellFontGetOutlineVertexesIF> getIF, vm::ptr<CellFontGlyphBoundingBox> bbox, vm::ptr<u32> vcount)
{
cellFont.todo("cellFontGlyphGetOutlineVertexes(glyph=*0x%x, controlDistance=%f, getIF=*0x%x, bbox=*0x%x, vcount=*0x%x)", glyph, controlDistance, getIF, bbox, vcount);
if (!glyph)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (!bbox)
{
//bbox = something; // TODO
}
if (glyph->Outline.contoursCount == 0)
{
if (vcount)
{
vcount[0] = 0;
vcount[1] = 0;
vcount[2] = 0;
vcount[3] = 0;
}
//if (in_r7)
//{
// *in_r7 = 0; // ???
//}
return CELL_OK;
}
// TODO
return CELL_OK;
}
error_code cellFontDelete(vm::cptr<CellFontLibrary> library, vm::ptr<void> p)
{
cellFont.todo("cellFontDelete(library=*0x%x, p=*0x%x)", library, p);
if (!library || !p)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
// TODO
return CELL_OK;
}
error_code cellFontPatchWorks(s32 param_1, u64 param_2)
{
cellFont.todo("cellFontPatchWorks(param_1=0x%x, param_2=0x%x)", param_1, param_2);
return CELL_OK;
}
error_code cellFontGlyphRenderImage(vm::ptr<CellFontGlyph> font, vm::ptr<CellFontGlyphStyle> style, vm::ptr<CellFontRenderer> renderer, vm::ptr<CellFontRenderSurface> surf, f32 x, f32 y, vm::ptr<CellFontGlyphMetrics> metrics, vm::ptr<CellFontImageTransInfo> transInfo)
{
cellFont.todo("cellFontGlyphRenderImage(font=*0x%x, style=*0x%x, renderer=*0x%x, surf=*0x%x, x=%f, y=%f, metrics=*0x%x, transInfo=*0x%x)", font, style, renderer, surf, x, y, metrics, transInfo);
if (false) // TODO
{
return CELL_FONT_ERROR_NO_SUPPORT_FUNCTION;
}
if (!font || !renderer || !renderer->systemReserved[0x10])
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
// TODO
return CELL_OK;
}
error_code cellFontGetBindingRenderer(vm::ptr<CellFont> font, vm::pptr<CellFontRenderer> renderer)
{
cellFont.todo("cellFontGetBindingRenderer(font=*0x%x, renderer=*0x%x)", font, renderer);
if (!renderer)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (font)
{
// TODO: may return CELL_FONT_ERROR_RENDERER_UNBIND
//*renderer = font->field_0x14;
}
else
{
*renderer = vm::null;
}
return CELL_OK;
}
error_code cellFontGenerateCharGlyphVertical(vm::ptr<CellFont> font, u32 code, vm::pptr<CellFontGlyph> glyph)
{
cellFont.todo("cellFontGenerateCharGlyphVertical(font=*0x%x, code=0x%x, glyph=*0x%x)", font, code, glyph);
if (false) // TODO
{
return CELL_FONT_ERROR_NO_SUPPORT_FUNCTION;
}
if (!font)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
// TODO
return CELL_OK;
}
error_code cellFontGetRenderEffectSlant(vm::ptr<CellFont> font, vm::ptr<f32> effectSlant)
{
cellFont.todo("cellFontGetRenderEffectSlant(font=*0x%x, effectSlant=*0x%x)", font, effectSlant);
if (!font)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (false) // TODO (!font->field_0xc || !font->library)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (false) // TODO (!font->field_0x14)
{
return CELL_FONT_ERROR_RENDERER_UNBIND;
}
if (effectSlant) // Technically unchecked in firmware
{
// TODO
//*effectSlant = font->field_0x14 + 0x24;
}
return CELL_OK;
}
error_code cellFontGetScalePoint(vm::ptr<CellFont> font, vm::ptr<f32> w, vm::ptr<f32> h)
{
cellFont.todo("cellFontGetScalePoint(font=*0x%x, w=*0x%x, h=*0x%x)", font, w, h);
if (!font)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (w)
{
//*w = font->scalePointW; // TODO
}
if (h)
{
//*h = font->scalePointH; // TODO
}
return CELL_OK;
}
error_code cellFontGraphicsGetLineRGBA(vm::ptr<CellFontGraphicsDrawContext> context, vm::ptr<f32> lineRGBA)
{
cellFont.todo("cellFontGraphicsGetLineRGBA(context=*0x%x, lineRGBA=*0x%x)", context, lineRGBA);
if (!context || !lineRGBA)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (false) // TODO: (context->magic != 0xcf50)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
// TODO
//lineRGBA[0] = context->lineColorR;
//lineRGBA[1] = context->lineColorG;
//lineRGBA[2] = context->lineColorB;
//lineRGBA[3] = context->lineColorA;
return CELL_OK;
}
error_code cellFontControl()
{
cellFont.todo("cellFontControl()");
return CELL_OK;
}
error_code cellFontStatic()
{
cellFont.todo("cellFontStatic()");
return CELL_OK;
}
DECLARE(ppu_module_manager::cellFont)("cellFont", []()
{
REG_FUNC(cellFont, cellFontSetFontsetOpenMode);
REG_FUNC(cellFont, cellFontSetFontOpenMode);
REG_FUNC(cellFont, cellFontCreateRenderer);
REG_FUNC(cellFont, cellFontGetHorizontalLayout);
REG_FUNC(cellFont, cellFontDestroyRenderer);
REG_FUNC(cellFont, cellFontSetupRenderScalePixel);
REG_FUNC(cellFont, cellFontOpenFontInstance);
REG_FUNC(cellFont, cellFontSetScalePixel);
REG_FUNC(cellFont, cellFontGetRenderCharGlyphMetrics);
REG_FUNC(cellFont, cellFontEndLibrary);
REG_FUNC(cellFont, cellFontBindRenderer);
REG_FUNC(cellFont, cellFontEnd);
REG_FUNC(cellFont, cellFontSetEffectSlant);
REG_FUNC(cellFont, cellFontGetEffectSlant);
REG_FUNC(cellFont, cellFontRenderCharGlyphImage);
REG_FUNC(cellFont, cellFontRenderSurfaceInit);
REG_FUNC(cellFont, cellFontGetFontIdCode);
REG_FUNC(cellFont, cellFontOpenFontset);
REG_FUNC(cellFont, cellFontCloseFont);
REG_FUNC(cellFont, cellFontRenderSurfaceSetScissor);
REG_FUNC(cellFont, cellFontGetCharGlyphMetrics);
REG_FUNC(cellFont, cellFontInitializeWithRevision);
REG_FUNC(cellFont, cellFontGraphicsSetFontRGBA);
REG_FUNC(cellFont, cellFontOpenFontsetOnMemory);
REG_FUNC(cellFont, cellFontOpenFontFile);
REG_FUNC(cellFont, cellFontGraphicsSetScalePixel);
REG_FUNC(cellFont, cellFontGraphicsGetScalePixel);
REG_FUNC(cellFont, cellFontSetEffectWeight);
REG_FUNC(cellFont, cellFontGlyphSetupVertexesGlyph);
REG_FUNC(cellFont, cellFontGetVerticalLayout);
REG_FUNC(cellFont, cellFontGetRenderCharGlyphMetricsVertical);
REG_FUNC(cellFont, cellFontSetScalePoint);
REG_FUNC(cellFont, cellFontSetupRenderEffectSlant);
REG_FUNC(cellFont, cellFontGraphicsSetLineRGBA);
REG_FUNC(cellFont, cellFontGraphicsSetDrawType);
REG_FUNC(cellFont, cellFontEndGraphics);
REG_FUNC(cellFont, cellFontGraphicsSetupDrawContext);
REG_FUNC(cellFont, cellFontOpenFontMemory);
REG_FUNC(cellFont, cellFontSetupRenderEffectWeight);
REG_FUNC(cellFont, cellFontGlyphGetOutlineControlDistance);
REG_FUNC(cellFont, cellFontGlyphGetVertexesGlyphSize);
REG_FUNC(cellFont, cellFontGenerateCharGlyph);
REG_FUNC(cellFont, cellFontDeleteGlyph);
REG_FUNC(cellFont, cellFontExtend);
REG_FUNC(cellFont, cellFontRenderCharGlyphImageVertical);
REG_FUNC(cellFont, cellFontSetResolutionDpi);
REG_FUNC(cellFont, cellFontGetCharGlyphMetricsVertical);
REG_FUNC(cellFont, cellFontUnbindRenderer);
REG_FUNC(cellFont, cellFontGetRevisionFlags);
REG_FUNC(cellFont, cellFontGetRenderEffectWeight);
REG_FUNC(cellFont, cellFontGraphicsGetDrawType);
REG_FUNC(cellFont, cellFontGetKerning);
REG_FUNC(cellFont, cellFontGetRenderScaledKerning);
REG_FUNC(cellFont, cellFontGetRenderScalePixel);
REG_FUNC(cellFont, cellFontGlyphGetScalePixel);
REG_FUNC(cellFont, cellFontGlyphGetHorizontalShift);
REG_FUNC(cellFont, cellFontRenderCharGlyphImageHorizontal);
REG_FUNC(cellFont, cellFontGetEffectWeight);
REG_FUNC(cellFont, cellFontGetScalePixel);
REG_FUNC(cellFont, cellFontClearFileCache);
REG_FUNC(cellFont, cellFontAdjustFontScaling);
REG_FUNC(cellFont, cellFontSetupRenderScalePoint);
REG_FUNC(cellFont, cellFontGlyphGetVerticalShift);
REG_FUNC(cellFont, cellFontGetGlyphExpandBufferInfo);
REG_FUNC(cellFont, cellFontGetLibrary);
REG_FUNC(cellFont, cellFontVertexesGlyphRelocate);
REG_FUNC(cellFont, cellFontGetInitializedRevisionFlags);
REG_FUNC(cellFont, cellFontGetResolutionDpi);
REG_FUNC(cellFont, cellFontGlyphRenderImageVertical);
REG_FUNC(cellFont, cellFontGlyphRenderImageHorizontal);
REG_FUNC(cellFont, cellFontAdjustGlyphExpandBuffer);
REG_FUNC(cellFont, cellFontGetRenderScalePoint);
REG_FUNC(cellFont, cellFontGraphicsGetFontRGBA);
REG_FUNC(cellFont, cellFontGlyphGetOutlineVertexes);
REG_FUNC(cellFont, cellFontDelete);
REG_FUNC(cellFont, cellFontPatchWorks);
REG_FUNC(cellFont, cellFontGlyphRenderImage);
REG_FUNC(cellFont, cellFontGetBindingRenderer);
REG_FUNC(cellFont, cellFontGenerateCharGlyphVertical);
REG_FUNC(cellFont, cellFontGetRenderEffectSlant);
REG_FUNC(cellFont, cellFontGetScalePoint);
REG_FUNC(cellFont, cellFontGraphicsGetLineRGBA);
REG_FUNC(cellFont, cellFontControl);
REG_FUNC(cellFont, cellFontStatic);
});
| 56,886
|
C++
|
.cpp
| 1,842
| 28.451683
| 278
| 0.72219
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
5,215
|
StaticHLE.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/StaticHLE.cpp
|
#include "stdafx.h"
#include "StaticHLE.h"
#include "Emu/Cell/PPUModule.h"
#include "Emu/Cell/PPUOpcodes.h"
#include "Emu/IdManager.h"
LOG_CHANNEL(static_hle);
// for future use
DECLARE(ppu_module_manager::static_hle) ("static_hle", []()
{
});
std::vector<std::array<std::string, 6>> shle_patterns_list
{
{ "2BA5000778630020788400207C6B1B78419D00702C2500004D82002028A5000F", "FF", "36D0", "05C4", "sys_libc", "memcpy" },
{ "2BA5000778630020788400207C6B1B78419D00702C2500004D82002028A5000F", "5C", "87A0", "05C4", "sys_libc", "memcpy" },
{ "2B8500077CA32A14788406207C6A1B78409D009C3903000198830000788B45E4", "B4", "1453", "00D4", "sys_libc", "memset" },
{ "280500087C661B7840800020280500004D8200207CA903A69886000038C60001", "F8", "F182", "0118", "sys_libc", "memset" },
{ "2B8500077CA32A14788406207C6A1B78409D009C3903000198830000788B45E4", "70", "DFDA", "00D4", "sys_libc", "memset" },
{ "7F832000FB61FFD8FBE1FFF8FB81FFE0FBA1FFE8FBC1FFF07C7B1B787C9F2378", "FF", "25B5", "12D4", "sys_libc", "memmove" },
{ "2B850007409D00B07C6923785520077E2F800000409E00ACE8030000E9440000", "FF", "71F1", "0158", "sys_libc", "memcmp" },
{ "280500007CE32050788B0760418200E028850100786A07607C2A580040840210", "FF", "87F2", "0470", "sys_libc", "memcmp" },
{ "2B850007409D00B07C6923785520077E2F800000409E00ACE8030000E9440000", "68", "EF18", "0158", "sys_libc", "memcmp" },
};
statichle_handler::statichle_handler(int)
{
load_patterns();
}
statichle_handler::~statichle_handler()
{
}
bool statichle_handler::load_patterns()
{
for (u32 i = 0; i < shle_patterns_list.size(); i++)
{
auto& pattern = shle_patterns_list[i];
if (pattern[0].size() != 64)
{
static_hle.error("[%d]:Start pattern length != 64", i);
continue;
}
if (pattern[1].size() != 2)
{
static_hle.error("[%d]:Crc16_length != 2", i);
continue;
}
if (pattern[2].size() != 4)
{
static_hle.error("[d]:Crc16 length != 4", i);
continue;
}
if (pattern[3].size() != 4)
{
static_hle.error("[d]:Total length != 4", i);
continue;
}
shle_pattern dapat;
auto char_to_u8 = [&](u8 char1, u8 char2) -> u16
{
if (char1 == '.' && char2 == '.')
return 0xFFFF;
if (char1 == '.' || char2 == '.')
{
static_hle.error("[%d]:Broken byte pattern", i);
return -1;
}
const u8 hv = char1 > '9' ? char1 - 'A' + 10 : char1 - '0';
const u8 lv = char2 > '9' ? char2 - 'A' + 10 : char2 - '0';
return (hv << 4) | lv;
};
for (u32 j = 0; j < 32; j++)
dapat.start_pattern[j] = char_to_u8(pattern[0][j * 2], pattern[0][(j * 2) + 1]);
dapat.crc16_length = ::narrow<u8>(char_to_u8(pattern[1][0], pattern[1][1]));
dapat.crc16 = (char_to_u8(pattern[2][0], pattern[2][1]) << 8) | char_to_u8(pattern[2][2], pattern[2][3]);
dapat.total_length = (char_to_u8(pattern[3][0], pattern[3][1]) << 8) | char_to_u8(pattern[3][2], pattern[3][3]);
dapat._module = pattern[4];
dapat.name = pattern[5];
dapat.fnid = ppu_generate_id(dapat.name.c_str());
static_hle.notice("Added a pattern for %s(id:0x%X)", dapat.name, dapat.fnid);
hle_patterns.push_back(std::move(dapat));
}
return true;
}
#define POLY 0x8408
u16 statichle_handler::gen_CRC16(const u8* data_p, usz length)
{
unsigned int data;
if (length == 0)
return 0;
unsigned int crc = 0xFFFF;
do
{
data = *data_p++;
for (unsigned char i = 0; i < 8; i++)
{
if ((crc ^ data) & 1)
crc = (crc >> 1) ^ POLY;
else
crc >>= 1;
data >>= 1;
}
} while (--length != 0);
crc = ~crc;
data = crc;
crc = (crc << 8) | ((data >> 8) & 0xff);
return static_cast<u16>(crc);
}
bool statichle_handler::check_against_patterns(vm::cptr<u8>& data, u32 size, u32 addr)
{
for (auto& pat : hle_patterns)
{
if (size < pat.total_length)
continue;
// check start pattern
int i = 0;
for (i = 0; i < 32; i++)
{
if (pat.start_pattern[i] == 0xFFFF)
continue;
if (data[i] != pat.start_pattern[i])
break;
}
if (i != 32)
continue;
// start pattern ok, checking middle part
if (pat.crc16_length != 0)
if (gen_CRC16(&data[32], pat.crc16_length) != pat.crc16)
continue;
// we got a match!
static_hle.success("Found function %s at 0x%x", pat.name, addr);
// patch the code
const auto smodule = ppu_module_manager::get_module(pat._module);
if (smodule == nullptr)
{
static_hle.error("Couldn't find module: %s", pat._module);
return false;
}
const auto sfunc = &::at32(smodule->functions, pat.fnid);
const u32 target = g_fxo->get<ppu_function_manager>().func_addr(sfunc->index, true);
// write stub
vm::write32(addr, ppu_instructions::LIS(0, (target&0xFFFF0000)>>16));
vm::write32(addr+4, ppu_instructions::ORI(0, 0, target&0xFFFF));
vm::write32(addr+8, ppu_instructions::MTCTR(0));
vm::write32(addr+12, ppu_instructions::BCTR());
return true;
}
return false;
}
| 4,857
|
C++
|
.cpp
| 146
| 30.349315
| 117
| 0.645437
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| false
| false
|
5,216
|
cellMusicExport.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellMusicExport.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
#include "Emu/IdManager.h"
#include "Emu/VFS.h"
#include "Utilities/StrUtil.h"
#include "cellSysutil.h"
LOG_CHANNEL(cellMusicExport);
// Return Codes
enum CellMusicExportError : u32
{
CELL_MUSIC_EXPORT_UTIL_ERROR_BUSY = 0x8002c601,
CELL_MUSIC_EXPORT_UTIL_ERROR_INTERNAL = 0x8002c602,
CELL_MUSIC_EXPORT_UTIL_ERROR_PARAM = 0x8002c603,
CELL_MUSIC_EXPORT_UTIL_ERROR_ACCESS_ERROR = 0x8002c604,
CELL_MUSIC_EXPORT_UTIL_ERROR_DB_INTERNAL = 0x8002c605,
CELL_MUSIC_EXPORT_UTIL_ERROR_DB_REGIST = 0x8002c606,
CELL_MUSIC_EXPORT_UTIL_ERROR_SET_META = 0x8002c607,
CELL_MUSIC_EXPORT_UTIL_ERROR_FLUSH_META = 0x8002c608,
CELL_MUSIC_EXPORT_UTIL_ERROR_MOVE = 0x8002c609,
CELL_MUSIC_EXPORT_UTIL_ERROR_INITIALIZE = 0x8002c60a,
};
template<>
void fmt_class_string<CellMusicExportError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_MUSIC_EXPORT_UTIL_ERROR_BUSY);
STR_CASE(CELL_MUSIC_EXPORT_UTIL_ERROR_INTERNAL);
STR_CASE(CELL_MUSIC_EXPORT_UTIL_ERROR_PARAM);
STR_CASE(CELL_MUSIC_EXPORT_UTIL_ERROR_ACCESS_ERROR);
STR_CASE(CELL_MUSIC_EXPORT_UTIL_ERROR_DB_INTERNAL);
STR_CASE(CELL_MUSIC_EXPORT_UTIL_ERROR_DB_REGIST);
STR_CASE(CELL_MUSIC_EXPORT_UTIL_ERROR_SET_META);
STR_CASE(CELL_MUSIC_EXPORT_UTIL_ERROR_FLUSH_META);
STR_CASE(CELL_MUSIC_EXPORT_UTIL_ERROR_MOVE);
STR_CASE(CELL_MUSIC_EXPORT_UTIL_ERROR_INITIALIZE);
}
return unknown;
});
}
enum
{
CELL_MUSIC_EXPORT_UTIL_VERSION_CURRENT = 0,
CELL_MUSIC_EXPORT_UTIL_HDD_PATH_MAX = 1055,
CELL_MUSIC_EXPORT_UTIL_MUSIC_TITLE_MAX_LENGTH = 64,
CELL_MUSIC_EXPORT_UTIL_GAME_TITLE_MAX_LENGTH = 64,
CELL_MUSIC_EXPORT_UTIL_GAME_COMMENT_MAX_SIZE = 1024,
};
struct CellMusicExportSetParam
{
vm::bptr<char> title;
vm::bptr<char> game_title;
vm::bptr<char> artist;
vm::bptr<char> genre;
vm::bptr<char> game_comment;
vm::bptr<char> reserved1;
vm::bptr<void> reserved2;
};
using CellMusicExportUtilFinishCallback = void(s32 result, vm::ptr<void> userdata);
struct music_export
{
atomic_t<s32> progress = 0; // 0x0-0xFFFF for 0-100%
};
bool check_music_path(const std::string& file_path)
{
if (file_path.size() >= CELL_MUSIC_EXPORT_UTIL_HDD_PATH_MAX)
{
return false;
}
for (char c : file_path)
{
if (!((c >= 'a' && c <= 'z') ||
(c >= 'A' && c <= 'Z') ||
(c >= '0' && c <= '9') ||
c == '-' || c == '_' ||
c == '/' || c == '.'))
{
return false;
}
}
if (!file_path.starts_with("/dev_hdd0"sv) &&
!file_path.starts_with("/dev_bdvd"sv) &&
!file_path.starts_with("/dev_hdd1"sv))
{
return false;
}
if (file_path.find(".."sv) != umax)
{
return false;
}
return true;
}
std::string get_available_music_path(const std::string& filename)
{
const std::string music_dir = "/dev_hdd0/music/";
std::string dst_path = vfs::get(music_dir + filename);
// Do not overwrite existing files. Add a suffix instead.
for (u32 i = 0; fs::exists(dst_path); i++)
{
const std::string suffix = fmt::format("_%d", i);
std::string new_filename = filename;
if (const usz pos = new_filename.find_last_of('.'); pos != std::string::npos)
{
new_filename.insert(pos, suffix);
}
else
{
new_filename.append(suffix);
}
dst_path = vfs::get(music_dir + new_filename);
}
return dst_path;
}
error_code cellMusicExportInitialize(u32 version, u32 container, vm::ptr<CellMusicExportUtilFinishCallback> funcFinish, vm::ptr<void> userdata)
{
cellMusicExport.warning("cellMusicExportInitialize(version=0x%x, container=0x%x, funcFinish=*0x%x, userdata=*0x%x)", version, container, funcFinish, userdata);
if (version != CELL_MUSIC_EXPORT_UTIL_VERSION_CURRENT)
{
return CELL_MUSIC_EXPORT_UTIL_ERROR_PARAM;
}
if (container != 0xfffffffe)
{
if (false) // TODO: Check if memory container size >= 0x300000
{
return CELL_MUSIC_EXPORT_UTIL_ERROR_PARAM;
}
}
if (!funcFinish)
{
return CELL_MUSIC_EXPORT_UTIL_ERROR_PARAM;
}
sysutil_register_cb([=](ppu_thread& ppu) -> s32
{
funcFinish(ppu, CELL_OK, userdata);
return CELL_OK;
});
return CELL_OK;
}
error_code cellMusicExportInitialize2(u32 version, vm::ptr<CellMusicExportUtilFinishCallback> funcFinish, vm::ptr<void> userdata)
{
cellMusicExport.notice("cellMusicExportInitialize2(version=0x%x, funcFinish=*0x%x, userdata=*0x%x)", version, funcFinish, userdata);
if (version != CELL_MUSIC_EXPORT_UTIL_VERSION_CURRENT)
{
return CELL_MUSIC_EXPORT_UTIL_ERROR_PARAM;
}
if (!funcFinish)
{
return CELL_MUSIC_EXPORT_UTIL_ERROR_PARAM;
}
sysutil_register_cb([=](ppu_thread& ppu) -> s32
{
funcFinish(ppu, CELL_OK, userdata);
return CELL_OK;
});
return CELL_OK;
}
error_code cellMusicExportFinalize(vm::ptr<CellMusicExportUtilFinishCallback> funcFinish, vm::ptr<void> userdata)
{
cellMusicExport.notice("cellMusicExportFinalize(funcFinish=*0x%x, userdata=*0x%x)", funcFinish, userdata);
if (!funcFinish)
{
return CELL_MUSIC_EXPORT_UTIL_ERROR_PARAM;
}
sysutil_register_cb([=](ppu_thread& ppu) -> s32
{
funcFinish(ppu, CELL_OK, userdata);
return CELL_OK;
});
return CELL_OK;
}
error_code cellMusicExportFromFile(vm::cptr<char> srcHddDir, vm::cptr<char> srcHddFile, vm::ptr<CellMusicExportSetParam> param, vm::ptr<CellMusicExportUtilFinishCallback> funcFinish, vm::ptr<void> userdata)
{
cellMusicExport.todo("cellMusicExportFromFile(srcHddDir=%s, srcHddFile=%s, param=*0x%x, funcFinish=*0x%x, userdata=*0x%x)", srcHddDir, srcHddFile, param, funcFinish, userdata);
if (!param || !funcFinish)
{
return CELL_MUSIC_EXPORT_UTIL_ERROR_PARAM;
}
// TODO: check param members ?
cellMusicExport.notice("cellMusicExportFromFile: param: title=%s, game_title=%s, artist=%s, genre=%s, game_comment=%s", param->title, param->game_title, param->artist, param->genre, param->game_comment);
const std::string file_path = fmt::format("%s/%s", srcHddDir.get_ptr(), srcHddFile.get_ptr());
if (!check_music_path(file_path))
{
return { CELL_MUSIC_EXPORT_UTIL_ERROR_PARAM, file_path };
}
std::string filename;
if (srcHddFile)
{
fmt::append(filename, "%s", srcHddFile.get_ptr());
}
if (filename.empty())
{
return { CELL_MUSIC_EXPORT_UTIL_ERROR_PARAM, "filename empty" };
}
sysutil_register_cb([=](ppu_thread& ppu) -> s32
{
auto& mexp = g_fxo->get<music_export>();
mexp.progress = 0; // 0%
const std::string src_path = vfs::get(file_path);
const std::string dst_path = get_available_music_path(filename);
cellMusicExport.notice("Copying file from '%s' to '%s'", file_path, dst_path);
// TODO: We ignore metadata for now
if (!fs::create_path(fs::get_parent_dir(dst_path)) || !fs::copy_file(src_path, dst_path, false))
{
// TODO: find out which error is used
cellMusicExport.error("Failed to copy file from '%s' to '%s' (%s)", src_path, dst_path, fs::g_tls_error);
funcFinish(ppu, CELL_MUSIC_EXPORT_UTIL_ERROR_MOVE, userdata);
return CELL_OK;
}
if (!file_path.starts_with("/dev_bdvd"sv))
{
cellMusicExport.notice("Removing file '%s'", src_path);
if (!fs::remove_file(src_path))
{
// TODO: find out if an error is used here
cellMusicExport.error("Failed to remove file '%s' (%s)", src_path, fs::g_tls_error);
}
}
// TODO: track progress during file copy
mexp.progress = 0xFFFF; // 100%
funcFinish(ppu, CELL_OK, userdata);
return CELL_OK;
});
return CELL_OK;
}
error_code cellMusicExportProgress(vm::ptr<CellMusicExportUtilFinishCallback> funcFinish, vm::ptr<void> userdata)
{
cellMusicExport.todo("cellMusicExportProgress(funcFinish=*0x%x, userdata=*0x%x)", funcFinish, userdata);
if (!funcFinish)
{
return CELL_MUSIC_EXPORT_UTIL_ERROR_PARAM;
}
sysutil_register_cb([=](ppu_thread& ppu) -> s32
{
// Set the status as 0x0-0xFFFF (0-100%) depending on the copy status.
// Only the copy or move of the movie and metadata files is considered for the progress.
const auto& mexp = g_fxo->get<music_export>();
funcFinish(ppu, mexp.progress, userdata);
return CELL_OK;
});
return CELL_OK;
}
DECLARE(ppu_module_manager::cellMusicExport)("cellMusicExportUtility", []()
{
REG_FUNC(cellMusicExportUtility, cellMusicExportInitialize);
REG_FUNC(cellMusicExportUtility, cellMusicExportInitialize2);
REG_FUNC(cellMusicExportUtility, cellMusicExportFinalize);
REG_FUNC(cellMusicExportUtility, cellMusicExportFromFile);
REG_FUNC(cellMusicExportUtility, cellMusicExportProgress);
});
| 8,470
|
C++
|
.cpp
| 251
| 31.183267
| 206
| 0.717088
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
5,217
|
sceNpUtil.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/sceNpUtil.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
#include "Emu/IdManager.h"
#include "sceNp.h"
#include "sceNpUtil.h"
LOG_CHANNEL(sceNpUtil);
struct bandwidth_test
{
atomic_t<u32> status = SCE_NP_UTIL_BANDWIDTH_TEST_STATUS_NONE;
atomic_t<bool> abort = false;
atomic_t<bool> shutdown = false;
atomic_t<bool> finished = false;
SceNpUtilBandwidthTestResult test_result{};
static constexpr auto thread_name = "HLE SceNpBandwidthTest"sv;
void operator()()
{
status = SCE_NP_UTIL_BANDWIDTH_TEST_STATUS_RUNNING;
u32 fake_sleep_count = 0;
while (thread_ctrl::state() != thread_state::aborting)
{
if (abort || shutdown)
{
break;
}
// TODO: run proper bandwidth test, probably with cellHttp
thread_ctrl::wait_for(1000); // wait 1ms
if (fake_sleep_count++ > 100) // end fake bandwidth test after 100 ms
{
break;
}
}
test_result.upload_bps = 100'000'000.0;
test_result.download_bps = 100'000'000.0;
test_result.result = CELL_OK;
status = SCE_NP_UTIL_BANDWIDTH_TEST_STATUS_FINISHED;
finished = true;
}
};
struct sce_np_util_manager
{
shared_mutex mtx{};
std::unique_ptr<named_thread<bandwidth_test>> bandwidth_test_thread;
~sce_np_util_manager()
{
join_thread();
}
void join_thread()
{
if (bandwidth_test_thread)
{
auto& thread = *bandwidth_test_thread;
thread = thread_state::aborting;
thread();
bandwidth_test_thread.reset();
}
}
};
error_code sceNpUtilBandwidthTestInitStart([[maybe_unused]] ppu_thread& ppu, u32 prio, u32 stack)
{
sceNpUtil.todo("sceNpUtilBandwidthTestInitStart(prio=%d, stack=%d)", prio, stack);
auto& util_manager = g_fxo->get<sce_np_util_manager>();
std::lock_guard lock(util_manager.mtx);
if (util_manager.bandwidth_test_thread)
{
return SCE_NP_ERROR_ALREADY_INITIALIZED;
}
util_manager.bandwidth_test_thread = std::make_unique<named_thread<bandwidth_test>>();
return CELL_OK;
}
error_code sceNpUtilBandwidthTestGetStatus()
{
sceNpUtil.notice("sceNpUtilBandwidthTestGetStatus()");
auto& util_manager = g_fxo->get<sce_np_util_manager>();
std::lock_guard lock(util_manager.mtx);
if (!util_manager.bandwidth_test_thread)
{
return SCE_NP_ERROR_NOT_INITIALIZED;
}
return not_an_error(util_manager.bandwidth_test_thread->status);
}
error_code sceNpUtilBandwidthTestShutdown([[maybe_unused]] ppu_thread& ppu, vm::ptr<SceNpUtilBandwidthTestResult> result)
{
sceNpUtil.warning("sceNpUtilBandwidthTestShutdown(result=*0x%x)", result);
auto& util_manager = g_fxo->get<sce_np_util_manager>();
std::lock_guard lock(util_manager.mtx);
if (!util_manager.bandwidth_test_thread)
{
return SCE_NP_ERROR_NOT_INITIALIZED;
}
util_manager.bandwidth_test_thread->shutdown = true;
while (!util_manager.bandwidth_test_thread->finished)
{
thread_ctrl::wait_for(1000);
}
if (result) // TODO: what happens when this is null ?
{
*result = util_manager.bandwidth_test_thread->test_result;
}
util_manager.join_thread();
return CELL_OK;
}
error_code sceNpUtilBandwidthTestAbort()
{
sceNpUtil.todo("sceNpUtilBandwidthTestAbort()");
auto& util_manager = g_fxo->get<sce_np_util_manager>();
std::lock_guard lock(util_manager.mtx);
if (!util_manager.bandwidth_test_thread)
{
return SCE_NP_ERROR_NOT_INITIALIZED;
}
// TODO: cellHttpTransactionAbortConnection();
util_manager.bandwidth_test_thread->abort = true;
return CELL_OK;
}
DECLARE(ppu_module_manager::sceNpUtil)("sceNpUtil", []()
{
REG_FUNC(sceNpUtil, sceNpUtilBandwidthTestInitStart);
REG_FUNC(sceNpUtil, sceNpUtilBandwidthTestShutdown);
REG_FUNC(sceNpUtil, sceNpUtilBandwidthTestGetStatus);
REG_FUNC(sceNpUtil, sceNpUtilBandwidthTestAbort);
});
| 3,661
|
C++
|
.cpp
| 121
| 27.760331
| 121
| 0.747645
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
5,218
|
cellResc.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellResc.cpp
|
#include "stdafx.h"
#include "Emu/IdManager.h"
#include "Emu/Cell/PPUModule.h"
#include "Emu/RSX/GCM.h"
#include "cellResc.h"
#include "cellVideoOut.h"
LOG_CHANNEL(cellResc);
template <>
void fmt_class_string<CellRescError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](CellRescError value)
{
switch (value)
{
STR_CASE(CELL_RESC_ERROR_NOT_INITIALIZED);
STR_CASE(CELL_RESC_ERROR_REINITIALIZED);
STR_CASE(CELL_RESC_ERROR_BAD_ALIGNMENT);
STR_CASE(CELL_RESC_ERROR_BAD_ARGUMENT);
STR_CASE(CELL_RESC_ERROR_LESS_MEMORY);
STR_CASE(CELL_RESC_ERROR_GCM_FLIP_QUE_FULL);
STR_CASE(CELL_RESC_ERROR_BAD_COMBINATION);
STR_CASE(CELL_RESC_ERROR_x308);
}
return unknown;
});
}
error_code cellRescInit(vm::cptr<CellRescInitConfig> initConfig)
{
cellResc.todo("cellRescInit(initConfig=*0x%x)", initConfig);
auto& resc_manager = g_fxo->get<cell_resc_manager>();
if (resc_manager.is_initialized)
{
return CELL_RESC_ERROR_REINITIALIZED;
}
if (!initConfig || initConfig->size > 28) // TODO: more checks
{
return CELL_RESC_ERROR_BAD_ARGUMENT;
}
resc_manager.config =
{
initConfig->size,
initConfig->resourcePolicy,
initConfig->supportModes,
initConfig->ratioMode,
initConfig->palTemporalMode,
initConfig->interlaceMode,
initConfig->flipMode
};
resc_manager.is_initialized = true;
return CELL_OK;
}
void cellRescExit()
{
cellResc.todo("cellRescExit()");
auto& resc_manager = g_fxo->get<cell_resc_manager>();
resc_manager.is_initialized = false;
}
error_code cellRescVideoOutResolutionId2RescBufferMode(u32 resolutionId, vm::cptr<u32> bufferMode)
{
cellResc.todo("cellRescVideoOutResolutionId2RescBufferMode(resolutionId=%d, bufferMode=*0x%x)", resolutionId, bufferMode);
if (!bufferMode || !resolutionId || resolutionId > CELL_VIDEO_OUT_RESOLUTION_576)
{
return CELL_RESC_ERROR_BAD_ARGUMENT;
}
return CELL_OK;
}
error_code cellRescSetDsts(u32 bufferMode, vm::cptr<CellRescDsts> dsts)
{
cellResc.todo("cellRescSetDsts(bufferMode=%d, dsts=*0x%x)", bufferMode, dsts);
auto& resc_manager = g_fxo->get<cell_resc_manager>();
if (!resc_manager.is_initialized)
{
return CELL_RESC_ERROR_NOT_INITIALIZED;
}
if (!dsts || !bufferMode || bufferMode > CELL_RESC_1920x1080) // TODO: is the bufferMode check correct?
{
return CELL_RESC_ERROR_BAD_ARGUMENT;
}
return CELL_OK;
}
error_code cellRescSetDisplayMode(u32 bufferMode)
{
cellResc.todo("cellRescSetDisplayMode(bufferMode=%d)", bufferMode);
auto& resc_manager = g_fxo->get<cell_resc_manager>();
if (!resc_manager.is_initialized)
{
return CELL_RESC_ERROR_NOT_INITIALIZED;
}
if (!bufferMode || bufferMode > CELL_RESC_1920x1080 || !(resc_manager.config.support_modes & bufferMode)) // TODO: is the bufferMode check correct?
{
return CELL_RESC_ERROR_BAD_ARGUMENT;
}
if (bufferMode == CELL_RESC_720x576)
{
const u32 pal_mode = resc_manager.config.pal_temporal_mode;
const u32 flip_mode = resc_manager.config.flip_mode;
// Check if palTemporalMode is any INTERPOLATE mode or CELL_RESC_PAL_60_DROP
if ((pal_mode - CELL_RESC_PAL_60_INTERPOLATE) <= CELL_RESC_PAL_60_INTERPOLATE || pal_mode == CELL_RESC_PAL_60_DROP)
{
if (flip_mode == CELL_RESC_DISPLAY_HSYNC)
{
return CELL_RESC_ERROR_BAD_COMBINATION;
}
}
if (pal_mode == CELL_RESC_PAL_60_FOR_HSYNC)
{
if (flip_mode == CELL_RESC_DISPLAY_VSYNC)
{
return CELL_RESC_ERROR_BAD_COMBINATION;
}
}
}
resc_manager.buffer_mode = bufferMode;
return CELL_OK;
}
error_code cellRescAdjustAspectRatio(f32 horizontal, f32 vertical)
{
cellResc.todo("cellRescAdjustAspectRatio(horizontal=%f, vertical=%f)", horizontal, vertical);
auto& resc_manager = g_fxo->get<cell_resc_manager>();
if (!resc_manager.is_initialized)
{
return CELL_RESC_ERROR_NOT_INITIALIZED;
}
if (horizontal < 0.5f || horizontal > 2.0f || vertical < 0.5f || vertical > 2.0f)
{
return CELL_RESC_ERROR_BAD_ARGUMENT;
}
return CELL_OK;
}
error_code cellRescSetPalInterpolateDropFlexRatio(f32 ratio)
{
cellResc.todo("cellRescSetPalInterpolateDropFlexRatio(ratio=%f)", ratio);
auto& resc_manager = g_fxo->get<cell_resc_manager>();
if (!resc_manager.is_initialized)
{
return CELL_RESC_ERROR_NOT_INITIALIZED;
}
if (ratio < 0.0f || ratio > 1.0f)
{
return CELL_RESC_ERROR_BAD_ARGUMENT;
}
return CELL_OK;
}
error_code cellRescGetBufferSize(vm::ptr<s32> colorBuffers, vm::ptr<s32> vertexArray, vm::ptr<s32> fragmentShader)
{
cellResc.todo("cellRescGetBufferSize(colorBuffers=*0x%x, vertexArray=*0x%x, fragmentShader=*0x%x)", colorBuffers, vertexArray, fragmentShader);
auto& resc_manager = g_fxo->get<cell_resc_manager>();
if (!resc_manager.is_initialized)
{
return CELL_RESC_ERROR_NOT_INITIALIZED;
}
//if (something)
//{
// return CELL_RESC_ERROR_x308;
//}
//if (colorBuffers)
//{
// colorBuffers = something
//}
//if (vertexArray)
//{
// vertexArray = something
//}
//if (fragmentShader)
//{
// fragmentShader = something
//}
return CELL_OK;
}
s32 cellRescGetNumColorBuffers(u32 dstMode, u32 palTemporalMode, s32 reserved)
{
cellResc.todo("cellRescGetNumColorBuffers(dstMode=%d, palTemporalMode=%d, reserved=%d)", dstMode, palTemporalMode, reserved);
if (reserved != 0)
{
return CELL_RESC_ERROR_BAD_ARGUMENT;
}
if (dstMode == CELL_RESC_720x576)
{
// Check if palTemporalMode is any INTERPOLATE mode
if ((palTemporalMode - CELL_RESC_PAL_60_INTERPOLATE) <= CELL_RESC_PAL_60_INTERPOLATE)
{
return 6;
}
if (palTemporalMode == CELL_RESC_PAL_60_DROP)
{
return 3;
}
}
return 2;
}
error_code cellRescGcmSurface2RescSrc(vm::cptr<CellGcmSurface> gcmSurface, vm::cptr<CellRescSrc> rescSrc)
{
cellResc.todo("cellRescGcmSurface2RescSrc(gcmSurface=*0x%x, rescSrc=*0x%x)", gcmSurface, rescSrc);
if (!gcmSurface || !rescSrc)
{
return CELL_RESC_ERROR_BAD_ARGUMENT;
}
return CELL_OK;
}
error_code cellRescSetSrc(s32 idx, vm::cptr<CellRescSrc> src)
{
cellResc.todo("cellRescSetSrc(idx=0x%x, src=*0x%x)", idx, src);
auto& resc_manager = g_fxo->get<cell_resc_manager>();
if (!resc_manager.is_initialized)
{
return CELL_RESC_ERROR_NOT_INITIALIZED;
}
if (idx >= SRC_BUFFER_NUM || !src || !src->width || !src->height || src->height > 4096) // TODO: is this correct?
{
return CELL_RESC_ERROR_BAD_ARGUMENT;
}
return CELL_OK;
}
error_code cellRescSetConvertAndFlip(vm::ptr<CellGcmContextData> con, s32 idx)
{
cellResc.todo("cellRescSetConvertAndFlip(con=*0x%x, idx=0x%x)", con, idx);
auto& resc_manager = g_fxo->get<cell_resc_manager>();
if (!resc_manager.is_initialized)
{
return CELL_RESC_ERROR_NOT_INITIALIZED;
}
if (idx >= SRC_BUFFER_NUM)
{
return CELL_RESC_ERROR_BAD_ARGUMENT;
}
return CELL_OK;
}
error_code cellRescSetWaitFlip(vm::ptr<CellGcmContextData> con)
{
cellResc.todo("cellRescSetWaitFlip(con=*0x%x)", con);
return CELL_OK;
}
error_code cellRescSetBufferAddress(vm::cptr<u32> colorBuffers, vm::cptr<u32> vertexArray, vm::cptr<u32> fragmentShader)
{
cellResc.todo("cellRescSetBufferAddress(colorBuffers=*0x%x, vertexArray=*0x%x, fragmentShader=*0x%x)", colorBuffers, vertexArray, fragmentShader);
auto& resc_manager = g_fxo->get<cell_resc_manager>();
if (!resc_manager.is_initialized)
{
return CELL_RESC_ERROR_NOT_INITIALIZED;
}
if (!colorBuffers || !vertexArray || !fragmentShader)
{
return CELL_RESC_ERROR_BAD_ARGUMENT;
}
if (!colorBuffers.aligned(128) || !vertexArray.aligned(4) || !fragmentShader.aligned(64)) // clrlwi with 25, 30, 26
{
return CELL_RESC_ERROR_BAD_ALIGNMENT;
}
return CELL_OK;
}
void cellRescSetFlipHandler(vm::ptr<void(u32)> handler)
{
cellResc.todo("cellRescSetFlipHandler(handler=*0x%x)", handler);
}
void cellRescResetFlipStatus()
{
cellResc.todo("cellRescResetFlipStatus()");
}
s32 cellRescGetFlipStatus()
{
cellResc.todo("cellRescGetFlipStatus()");
return 0;
}
s32 cellRescGetRegisterCount()
{
cellResc.todo("cellRescGetRegisterCount()");
return 0;
}
u64 cellRescGetLastFlipTime()
{
cellResc.todo("cellRescGetLastFlipTime()");
return 0;
}
void cellRescSetRegisterCount(s32 regCount)
{
cellResc.todo("cellRescSetRegisterCount(regCount=0x%x)", regCount);
}
void cellRescSetVBlankHandler(vm::ptr<void(u32)> handler)
{
cellResc.todo("cellRescSetVBlankHandler(handler=*0x%x)", handler);
}
error_code cellRescCreateInterlaceTable(vm::ptr<void> ea_addr, f32 srcH, CellRescTableElement depth, s32 length)
{
cellResc.todo("cellRescCreateInterlaceTable(ea_addr=0x%x, srcH=%f, depth=%d, length=%d)", ea_addr, srcH, +depth, length);
if (!ea_addr || srcH <= 0.0f || depth > CELL_RESC_ELEMENT_FLOAT || length <= 0) // TODO: srcH check correct?
{
return CELL_RESC_ERROR_BAD_ARGUMENT;
}
auto& resc_manager = g_fxo->get<cell_resc_manager>();
if (!resc_manager.buffer_mode)
{
return CELL_RESC_ERROR_BAD_COMBINATION;
}
return CELL_OK;
}
DECLARE(ppu_module_manager::cellResc)("cellResc", []()
{
REG_FUNC(cellResc, cellRescSetConvertAndFlip);
REG_FUNC(cellResc, cellRescSetWaitFlip);
REG_FUNC(cellResc, cellRescSetFlipHandler);
REG_FUNC(cellResc, cellRescGcmSurface2RescSrc);
REG_FUNC(cellResc, cellRescGetNumColorBuffers);
REG_FUNC(cellResc, cellRescSetDsts);
REG_FUNC(cellResc, cellRescResetFlipStatus);
REG_FUNC(cellResc, cellRescSetPalInterpolateDropFlexRatio);
REG_FUNC(cellResc, cellRescGetRegisterCount);
REG_FUNC(cellResc, cellRescAdjustAspectRatio);
REG_FUNC(cellResc, cellRescSetDisplayMode);
REG_FUNC(cellResc, cellRescExit);
REG_FUNC(cellResc, cellRescInit);
REG_FUNC(cellResc, cellRescGetBufferSize);
REG_FUNC(cellResc, cellRescGetLastFlipTime);
REG_FUNC(cellResc, cellRescSetSrc);
REG_FUNC(cellResc, cellRescSetRegisterCount);
REG_FUNC(cellResc, cellRescSetBufferAddress);
REG_FUNC(cellResc, cellRescGetFlipStatus);
REG_FUNC(cellResc, cellRescVideoOutResolutionId2RescBufferMode);
REG_FUNC(cellResc, cellRescSetVBlankHandler);
REG_FUNC(cellResc, cellRescCreateInterlaceTable);
});
| 9,907
|
C++
|
.cpp
| 320
| 28.68125
| 148
| 0.75458
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| true
| false
| false
| true
| false
| false
|
5,219
|
sys_crashdump.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/sys_crashdump.cpp
|
#include "stdafx.h"
#include "sys_crashdump.h"
#include "Emu/Cell/PPUModule.h"
LOG_CHANNEL(sys_crashdump);
error_code sys_crash_dump_get_user_log_area(u8 index, vm::ptr<sys_crash_dump_log_area_info_t> entry)
{
sys_crashdump.todo("sys_crash_dump_get_user_log_area(index=%d, entry=*0x%x)", index, entry);
if (index > SYS_CRASH_DUMP_MAX_LOG_AREA || !entry)
{
return CELL_EINVAL;
}
return CELL_OK;
}
error_code sys_crash_dump_set_user_log_area(u8 index, vm::ptr<sys_crash_dump_log_area_info_t> new_entry)
{
sys_crashdump.todo("sys_crash_dump_set_user_log_area(index=%d, new_entry=*0x%x)", index, new_entry);
if (index > SYS_CRASH_DUMP_MAX_LOG_AREA || !new_entry)
{
return CELL_EINVAL;
}
return CELL_OK;
}
DECLARE(ppu_module_manager::sys_crashdump) ("sys_crashdump", []()
{
REG_FUNC(sys_crashdump, sys_crash_dump_get_user_log_area);
REG_FUNC(sys_crashdump, sys_crash_dump_set_user_log_area);
});
| 915
|
C++
|
.cpp
| 27
| 32
| 104
| 0.723864
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| true
| false
| false
| true
| false
| false
|
5,220
|
sceNpCommerce2.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/sceNpCommerce2.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
#include "Emu/IdManager.h"
#include "sceNpCommerce2.h"
#include "sceNp.h"
#include "cellSysutil.h"
#include "Emu/Cell/lv2/sys_process.h"
#include "Emu/NP/np_handler.h"
#include "Emu/NP/np_contexts.h"
LOG_CHANNEL(sceNpCommerce2);
template <>
void fmt_class_string<SceNpCommerce2Error>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](SceNpCommerce2Error value)
{
switch (value)
{
STR_CASE(SCE_NP_COMMERCE2_ERROR_NOT_INITIALIZED);
STR_CASE(SCE_NP_COMMERCE2_ERROR_ALREADY_INITIALIZED);
STR_CASE(SCE_NP_COMMERCE2_ERROR_INVALID_ARGUMENT);
STR_CASE(SCE_NP_COMMERCE2_ERROR_UNSUPPORTED_VERSION);
STR_CASE(SCE_NP_COMMERCE2_ERROR_CTX_MAX);
STR_CASE(SCE_NP_COMMERCE2_ERROR_INVALID_INDEX);
STR_CASE(SCE_NP_COMMERCE2_ERROR_INVALID_SKUID);
STR_CASE(SCE_NP_COMMERCE2_ERROR_INVALID_SKU_NUM);
STR_CASE(SCE_NP_COMMERCE2_ERROR_INVALID_MEMORY_CONTAINER);
STR_CASE(SCE_NP_COMMERCE2_ERROR_INSUFFICIENT_MEMORY_CONTAINER);
STR_CASE(SCE_NP_COMMERCE2_ERROR_OUT_OF_MEMORY);
STR_CASE(SCE_NP_COMMERCE2_ERROR_CTX_NOT_FOUND);
STR_CASE(SCE_NP_COMMERCE2_ERROR_CTXID_NOT_AVAILABLE);
STR_CASE(SCE_NP_COMMERCE2_ERROR_REQ_NOT_FOUND);
STR_CASE(SCE_NP_COMMERCE2_ERROR_REQID_NOT_AVAILABLE);
STR_CASE(SCE_NP_COMMERCE2_ERROR_ABORTED);
STR_CASE(SCE_NP_COMMERCE2_ERROR_RESPONSE_BUF_TOO_SMALL);
STR_CASE(SCE_NP_COMMERCE2_ERROR_COULD_NOT_RECV_WHOLE_RESPONSE_DATA);
STR_CASE(SCE_NP_COMMERCE2_ERROR_INVALID_RESULT_DATA);
STR_CASE(SCE_NP_COMMERCE2_ERROR_UNKNOWN);
STR_CASE(SCE_NP_COMMERCE2_ERROR_SERVER_MAINTENANCE);
STR_CASE(SCE_NP_COMMERCE2_ERROR_SERVER_UNKNOWN);
STR_CASE(SCE_NP_COMMERCE2_ERROR_INSUFFICIENT_BUF_SIZE);
STR_CASE(SCE_NP_COMMERCE2_ERROR_REQ_MAX);
STR_CASE(SCE_NP_COMMERCE2_ERROR_INVALID_TARGET_TYPE);
STR_CASE(SCE_NP_COMMERCE2_ERROR_INVALID_TARGET_ID);
STR_CASE(SCE_NP_COMMERCE2_ERROR_INVALID_SIZE);
STR_CASE(SCE_NP_COMMERCE2_ERROR_DATA_NOT_FOUND);
STR_CASE(SCE_NP_COMMERCE2_SERVER_ERROR_BAD_REQUEST);
STR_CASE(SCE_NP_COMMERCE2_SERVER_ERROR_UNKNOWN_ERROR);
STR_CASE(SCE_NP_COMMERCE2_SERVER_ERROR_SESSION_EXPIRED);
STR_CASE(SCE_NP_COMMERCE2_SERVER_ERROR_ACCESS_PERMISSION_DENIED);
STR_CASE(SCE_NP_COMMERCE2_SERVER_ERROR_NO_SUCH_CATEGORY);
STR_CASE(SCE_NP_COMMERCE2_SERVER_ERROR_NO_SUCH_PRODUCT);
STR_CASE(SCE_NP_COMMERCE2_SERVER_ERROR_NOT_ELIGIBILITY);
STR_CASE(SCE_NP_COMMERCE2_SERVER_ERROR_INVALID_SKU);
STR_CASE(SCE_NP_COMMERCE2_SERVER_ERROR_ACCOUNT_SUSPENDED1);
STR_CASE(SCE_NP_COMMERCE2_SERVER_ERROR_ACCOUNT_SUSPENDED2);
STR_CASE(SCE_NP_COMMERCE2_SERVER_ERROR_OVER_SPENDING_LIMIT);
STR_CASE(SCE_NP_COMMERCE2_SERVER_ERROR_INVALID_VOUCHER);
STR_CASE(SCE_NP_COMMERCE2_SERVER_ERROR_VOUCHER_ALREADY_CONSUMED);
STR_CASE(SCE_NP_COMMERCE2_SERVER_ERROR_EXCEEDS_AGE_LIMIT_IN_BROWSING);
STR_CASE(SCE_NP_COMMERCE2_SYSTEM_UTIL_ERROR_INVALID_VOUCHER);
}
return unknown;
});
}
void initialize_common_data(SceNpCommerce2CommonData* common_data, vm::ptr<void> data, u32 internal_data_addr, u32 internal_data_size)
{
std::memset(common_data, 0, sizeof(SceNpCommerce2CommonData));
common_data->version = SCE_NP_COMMERCE2_VERSION;
common_data->buf_head = data.addr();
common_data->data = internal_data_addr;
common_data->data_size = internal_data_size;
}
error_code check_and_get_data(vm::ptr<void> /*data*/, u32 data_size, u32& /*internal_data_addr*/, u32& /*internal_data_size*/)
{
if (data_size < 60)
return SCE_NP_COMMERCE2_ERROR_INVALID_RESULT_DATA;
// TODO: check and extract data
if (true)
return SCE_NP_COMMERCE2_ERROR_INVALID_RESULT_DATA;
return not_an_error(60);
}
error_code sceNpCommerce2ExecuteStoreBrowse(s32 targetType, vm::cptr<char> targetId, s32 userdata)
{
sceNpCommerce2.todo("sceNpCommerce2ExecuteStoreBrowse(targetType=%d, targetId=%s, userdata=%d)", targetType, targetId, userdata);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Com2_init)
return SCE_NP_COMMERCE2_ERROR_NOT_INITIALIZED;
if (targetType < SCE_NP_COMMERCE2_STORE_BROWSE_TYPE_CATEGORY || targetType > SCE_NP_COMMERCE2_STORE_BROWSE_TYPE_PRODUCT_CODE)
return SCE_NP_COMMERCE2_ERROR_INVALID_TARGET_TYPE;
if (targetType < SCE_NP_COMMERCE2_STORE_BROWSE_TYPE_PRODUCT_CODE && (!targetId || !targetId[0]))
return SCE_NP_COMMERCE2_ERROR_INVALID_TARGET_ID;
return CELL_OK;
}
error_code sceNpCommerce2GetStoreBrowseUserdata(vm::ptr<s32> userdata)
{
sceNpCommerce2.todo("sceNpCommerce2GetStoreBrowseUserdata(userdata=*0x%x)", userdata);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Com2_init)
return SCE_NP_COMMERCE2_ERROR_NOT_INITIALIZED;
if (!userdata)
return SCE_NP_COMMERCE2_ERROR_INVALID_ARGUMENT;
*userdata = 0; // TODO
return CELL_OK;
}
error_code sceNpCommerce2Init()
{
sceNpCommerce2.warning("sceNpCommerce2Init()");
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (nph.is_NP_Com2_init)
return SCE_NP_COMMERCE2_ERROR_ALREADY_INITIALIZED;
if (!nph.is_NP_init)
return SCE_NP_ERROR_NOT_INITIALIZED;
nph.is_NP_Com2_init = true;
return CELL_OK;
}
error_code sceNpCommerce2Term()
{
sceNpCommerce2.warning("sceNpCommerce2Term()");
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
nph.is_NP_Com2_init = false;
return CELL_OK;
}
error_code sceNpCommerce2CreateCtx(u32 version, vm::cptr<SceNpId> npId, vm::ptr<SceNpCommerce2Handler> handler, vm::ptr<void> arg, vm::ptr<u32> ctx_id)
{
sceNpCommerce2.warning("sceNpCommerce2CreateCtx(version=%d, npId=*0x%x, handler=*0x%x, arg=*0x%x, ctx_id=*0x%x)", version, npId, handler, arg, ctx_id);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Com2_init)
return SCE_NP_COMMERCE2_ERROR_NOT_INITIALIZED;
if (version > SCE_NP_COMMERCE2_VERSION)
return SCE_NP_COMMERCE2_ERROR_UNSUPPORTED_VERSION;
if (false) // TODO
return SCE_NP_COMMERCE2_ERROR_CTX_MAX;
if (!npId)
return SCE_NP_COMMERCE2_ERROR_INVALID_ARGUMENT;
if (ctx_id)
*ctx_id = create_commerce2_context(version, npId, handler, arg);
else
sceNpCommerce2.warning("sceNpCommerce2CreateCtx: ctx_id is null");
return CELL_OK;
}
s32 sceNpCommerce2DestroyCtx(u32 ctx_id)
{
sceNpCommerce2.warning("sceNpCommerce2DestroyCtx(ctx_id=%d)", ctx_id);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Com2_init)
return SCE_NP_COMMERCE2_ERROR_NOT_INITIALIZED;
if (!destroy_commerce2_context(ctx_id))
{
return SCE_NP_COMMERCE2_ERROR_CTX_NOT_FOUND;
}
return CELL_OK;
}
error_code sceNpCommerce2EmptyStoreCheckStart(u32 ctx_id, s32 store_check_type, vm::cptr<char> target_id)
{
sceNpCommerce2.warning("sceNpCommerce2EmptyStoreCheckStart(ctx_id=%d, store_check_type=%d, target_id=*0x%x(%s))", ctx_id, store_check_type, target_id, target_id);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Com2_init)
return SCE_NP_COMMERCE2_ERROR_NOT_INITIALIZED;
if (!target_id || !target_id[0])
return SCE_NP_COMMERCE2_ERROR_INVALID_TARGET_ID;
if (store_check_type != SCE_NP_COMMERCE2_STORE_CHECK_TYPE_CATEGORY)
return SCE_NP_COMMERCE2_ERROR_INVALID_ARGUMENT;
const auto ctx = get_commerce2_context(ctx_id);
if (!ctx)
{
return SCE_NP_COMMERCE2_ERROR_CTX_NOT_FOUND; // TODO: verify
}
if (ctx->context_callback)
{
sysutil_register_cb([=, context_callback = ctx->context_callback, context_callback_param = ctx->context_callback_param](ppu_thread& cb_ppu) -> s32
{
context_callback(cb_ppu, ctx_id, 0, SCE_NP_COMMERCE2_EVENT_EMPTY_STORE_CHECK_DONE, 0, context_callback_param);
return 0;
});
}
return CELL_OK;
}
error_code sceNpCommerce2EmptyStoreCheckAbort(u32 ctx_id)
{
sceNpCommerce2.todo("sceNpCommerce2EmptyStoreCheckAbort(ctx_id=%d)", ctx_id);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Com2_init)
return SCE_NP_COMMERCE2_ERROR_NOT_INITIALIZED;
return CELL_OK;
}
error_code sceNpCommerce2EmptyStoreCheckFinish(u32 ctx_id, vm::ptr<s32> is_empty)
{
sceNpCommerce2.warning("sceNpCommerce2EmptyStoreCheckFinish(ctx_id=%d, is_empty=*0x%x)", ctx_id, is_empty);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Com2_init)
return SCE_NP_COMMERCE2_ERROR_NOT_INITIALIZED;
if (!is_empty)
return SCE_NP_COMMERCE2_ERROR_INVALID_ARGUMENT;
*is_empty = SCE_NP_COMMERCE2_STORE_IS_NOT_EMPTY;
return CELL_OK;
}
error_code sceNpCommerce2CreateSessionStart(u32 ctx_id)
{
sceNpCommerce2.warning("sceNpCommerce2CreateSessionStart(ctx_id=%d)", ctx_id);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Com2_init)
return SCE_NP_COMMERCE2_ERROR_NOT_INITIALIZED;
const auto ctx = get_commerce2_context(ctx_id);
if (!ctx)
{
return SCE_NP_COMMERCE2_ERROR_CTX_NOT_FOUND;
}
if (ctx->context_callback)
{
sysutil_register_cb([=, context_callback = ctx->context_callback, context_callback_param = ctx->context_callback_param](ppu_thread& cb_ppu) -> s32
{
context_callback(cb_ppu, ctx_id, 0, SCE_NP_COMMERCE2_EVENT_CREATE_SESSION_DONE, 0, context_callback_param);
return 0;
});
}
return CELL_OK;
}
error_code sceNpCommerce2CreateSessionAbort(u32 ctx_id)
{
sceNpCommerce2.todo("sceNpCommerce2CreateSessionAbort(ctx_id=%d)", ctx_id);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Com2_init)
return SCE_NP_COMMERCE2_ERROR_NOT_INITIALIZED;
const auto ctx = get_commerce2_context(ctx_id);
if (!ctx)
return SCE_NP_COMMERCE2_ERROR_CTX_NOT_FOUND;
return CELL_OK;
}
s32 sceNpCommerce2CreateSessionFinish(u32 ctx_id, vm::ptr<SceNpCommerce2SessionInfo> sessionInfo)
{
sceNpCommerce2.warning("sceNpCommerce2CreateSessionFinish(ctx_id=%d, sessionInfo=*0x%x)", ctx_id, sessionInfo);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Com2_init)
return SCE_NP_COMMERCE2_ERROR_NOT_INITIALIZED;
const auto ctx = get_commerce2_context(ctx_id);
if (!ctx)
return SCE_NP_COMMERCE2_ERROR_CTX_NOT_FOUND;
s32 sdk_ver{};
[[maybe_unused]] s32 ret = process_get_sdk_version(process_getpid(), sdk_ver);
if (sdk_ver < 0x300000)
{
std::memset(sessionInfo.get_ptr(), 0, 8); // currencyCode, decimals
}
else
{
std::memset(sessionInfo.get_ptr(), 0, 44); // sizeof(SceNpCommerce2SessionInfo) - reserved
}
// TODO
if (false)
{
sessionInfo->currencyCode[0] = 'U';
sessionInfo->currencyCode[1] = 'S';
sessionInfo->currencyCode[2] = 'D';
sessionInfo->currencyCode[3] = '\0';
sessionInfo->decimals = 2;
sessionInfo->currencySymbol[0] = '$';
sessionInfo->currencySymbol[1] = '\0';
sessionInfo->currencySymbol[2] = '\0';
sessionInfo->currencySymbol[3] = '\0';
sessionInfo->symbolPosition = SCE_NP_COMMERCE2_SYM_POS_PRE;
sessionInfo->symbolWithSpace = false;
sessionInfo->padding1[3];
sessionInfo->thousandSeparator[0] = ',';
sessionInfo->thousandSeparator[1] = '\0';
sessionInfo->thousandSeparator[2] = '\0';
sessionInfo->thousandSeparator[3] = '\0';
sessionInfo->decimalLetter[0] = '.';
sessionInfo->decimalLetter[1] = '\0';
sessionInfo->decimalLetter[2] = '\0';
sessionInfo->decimalLetter[3] = '\0';
}
return CELL_OK;
}
error_code sceNpCommerce2GetCategoryContentsCreateReq(u32 ctx_id, vm::ptr<u32> req_id)
{
sceNpCommerce2.todo("sceNpCommerce2GetCategoryContentsCreateReq(ctx_id=%d, req_id=*0x%x)", ctx_id, req_id);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Com2_init)
return SCE_NP_COMMERCE2_ERROR_NOT_INITIALIZED;
if (!req_id)
return SCE_NP_COMMERCE2_ERROR_INVALID_ARGUMENT;
return CELL_OK;
}
error_code sceNpCommerce2GetCategoryContentsStart(u32 req_id, vm::cptr<char> categoryId, u32 startPosition, u32 maxCountOfResults)
{
sceNpCommerce2.todo("sceNpCommerce2GetCategoryContentsStart(req_id=%d, categoryId=%s, startPosition=%d, maxCountOfResults=%d)", req_id, categoryId, startPosition, maxCountOfResults);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Com2_init)
return SCE_NP_COMMERCE2_ERROR_NOT_INITIALIZED;
if (!categoryId || maxCountOfResults > SCE_NP_COMMERCE2_GETCAT_MAX_COUNT)
return SCE_NP_COMMERCE2_ERROR_INVALID_ARGUMENT;
return CELL_OK;
}
error_code get_result(u32 /* req_id */, vm::ptr<void> buf, u32 buf_size, vm::ptr<u32> fill_size)
{
if (!buf || !buf_size || ! fill_size)
return SCE_NP_COMMERCE2_ERROR_INVALID_ARGUMENT;
// TODO
return CELL_OK;
}
error_code sceNpCommerce2GetCategoryContentsGetResult(u32 req_id, vm::ptr<void> buf, u32 buf_size, vm::ptr<u32> fill_size)
{
sceNpCommerce2.todo("sceNpCommerce2GetCategoryContentsGetResult(req_id=%d, buf=*0x%x, buf_size=%d, fill_size=*0x%x)", req_id, buf, buf_size, fill_size);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Com2_init)
return SCE_NP_COMMERCE2_ERROR_NOT_INITIALIZED;
if (buf_size < SCE_NP_COMMERCE2_RECV_BUF_SIZE)
return SCE_NP_COMMERCE2_ERROR_INSUFFICIENT_BUF_SIZE;
return get_result(req_id, buf, buf_size, fill_size);
}
error_code sceNpCommerce2InitGetCategoryContentsResult(vm::ptr<SceNpCommerce2GetCategoryContentsResult> result, vm::ptr<void> data, u32 data_size)
{
sceNpCommerce2.todo("sceNpCommerce2InitGetCategoryContentsResult(result=*0x%x, data=*0x%x, data_size=%d)", result, data, data_size);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Com2_init)
return SCE_NP_COMMERCE2_ERROR_NOT_INITIALIZED;
if (!result || !data || !data_size)
return SCE_NP_COMMERCE2_ERROR_INVALID_ARGUMENT;
u32 internal_data_addr = 0, internal_data_size = 0;
error_code error = check_and_get_data(data, data_size, internal_data_addr, internal_data_size);
if (error < 0)
return error;
std::memset(result.get_ptr(), 0, sizeof(SceNpCommerce2GetCategoryContentsResult));
initialize_common_data(&result->commonData, data, internal_data_addr, internal_data_size);
return CELL_OK;
}
error_code sceNpCommerce2GetCategoryInfo(vm::cptr<SceNpCommerce2GetCategoryContentsResult> result, vm::ptr<SceNpCommerce2CategoryInfo> categoryInfo)
{
sceNpCommerce2.todo("sceNpCommerce2GetCategoryInfo(result=*0x%x, categoryInfo=*0x%x)", result, categoryInfo);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Com2_init)
return SCE_NP_COMMERCE2_ERROR_NOT_INITIALIZED;
if (!result || !categoryInfo)
return SCE_NP_COMMERCE2_ERROR_INVALID_ARGUMENT;
// Hack to stop crashes in some games
return SCE_NP_COMMERCE2_ERROR_SERVER_MAINTENANCE;
}
error_code sceNpCommerce2GetContentInfo(vm::cptr<SceNpCommerce2GetCategoryContentsResult> result, u32 index, vm::ptr<SceNpCommerce2ContentInfo> contentInfo)
{
sceNpCommerce2.todo("sceNpCommerce2GetContentInfo(result=*0x%x, index=%d, contentInfo=*0x%x)", result, index, contentInfo);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Com2_init)
return SCE_NP_COMMERCE2_ERROR_NOT_INITIALIZED;
if (!result || !contentInfo)
return SCE_NP_COMMERCE2_ERROR_INVALID_ARGUMENT;
return CELL_OK;
}
error_code sceNpCommerce2GetCategoryInfoFromContentInfo(vm::cptr<SceNpCommerce2ContentInfo> contentInfo, vm::ptr<SceNpCommerce2CategoryInfo> categoryInfo)
{
sceNpCommerce2.todo("sceNpCommerce2GetCategoryInfoFromContentInfo(contentInfo=*0x%x, categoryInfo=*0x%x)", contentInfo, categoryInfo);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Com2_init)
return SCE_NP_COMMERCE2_ERROR_NOT_INITIALIZED;
if (!contentInfo || !categoryInfo)
return SCE_NP_COMMERCE2_ERROR_INVALID_ARGUMENT;
return CELL_OK;
}
error_code sceNpCommerce2GetGameProductInfoFromContentInfo(vm::cptr<SceNpCommerce2ContentInfo> contentInfo, vm::ptr<SceNpCommerce2GameProductInfo> gameProductInfo)
{
sceNpCommerce2.todo("sceNpCommerce2GetGameProductInfoFromContentInfo(contentInfo=*0x%x, gameProductInfo=*0x%x)", contentInfo, gameProductInfo);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Com2_init)
return SCE_NP_COMMERCE2_ERROR_NOT_INITIALIZED;
if (!contentInfo || !gameProductInfo)
return SCE_NP_COMMERCE2_ERROR_INVALID_ARGUMENT;
return CELL_OK;
}
error_code sceNpCommerce2DestroyGetCategoryContentsResult(vm::ptr<SceNpCommerce2GetCategoryContentsResult> result)
{
sceNpCommerce2.todo("sceNpCommerce2DestroyGetCategoryContentsResult(result=*0x%x)", result);
return CELL_OK;
}
error_code sceNpCommerce2GetProductInfoCreateReq(u32 ctx_id, vm::ptr<u32> req_id)
{
sceNpCommerce2.todo("sceNpCommerce2GetProductInfoCreateReq(ctx_id=%d, req_id=*0x%x)", ctx_id, req_id);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Com2_init)
return SCE_NP_COMMERCE2_ERROR_NOT_INITIALIZED;
if (!req_id)
return SCE_NP_COMMERCE2_ERROR_INVALID_ARGUMENT;
const auto ctx = get_commerce2_context(ctx_id);
if (!ctx)
return SCE_NP_COMMERCE2_ERROR_CTX_NOT_FOUND;
return CELL_OK;
}
error_code sceNpCommerce2GetProductInfoStart(u32 req_id, vm::cptr<char> categoryId, vm::cptr<char> productId)
{
sceNpCommerce2.todo("sceNpCommerce2GetProductInfoStart(req_id=%d, categoryId=%s, productId=%s)", req_id, categoryId, productId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Com2_init)
return SCE_NP_COMMERCE2_ERROR_NOT_INITIALIZED;
if (!productId)
return SCE_NP_COMMERCE2_ERROR_INVALID_ARGUMENT;
return CELL_OK;
}
error_code sceNpCommerce2GetProductInfoGetResult(u32 req_id, vm::ptr<void> buf, u32 buf_size, vm::ptr<u32> fill_size)
{
sceNpCommerce2.todo("sceNpCommerce2GetProductInfoGetResult(req_id=%d, buf=*0x%x, buf_size=%d, fill_size=*0x%x)", req_id, buf, buf_size, fill_size);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Com2_init)
return SCE_NP_COMMERCE2_ERROR_NOT_INITIALIZED;
if (buf_size < SCE_NP_COMMERCE2_RECV_BUF_SIZE)
return SCE_NP_COMMERCE2_ERROR_INSUFFICIENT_BUF_SIZE;
return get_result(req_id, buf, buf_size, fill_size);
}
error_code sceNpCommerce2InitGetProductInfoResult(vm::ptr<SceNpCommerce2GetProductInfoResult> result, vm::ptr<void> data, u32 data_size)
{
sceNpCommerce2.todo("sceNpCommerce2InitGetProductInfoResult(result=*0x%x, data=*0x%x, data_size=%d)", result, data, data_size);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Com2_init)
return SCE_NP_COMMERCE2_ERROR_NOT_INITIALIZED;
if (!result || !data || !data_size)
return SCE_NP_COMMERCE2_ERROR_INVALID_ARGUMENT;
u32 internal_data_addr = 0, internal_data_size = 0;
error_code error = check_and_get_data(data, data_size, internal_data_addr, internal_data_size);
if (error < 0)
return error;
std::memset(result.get_ptr(), 0, sizeof(SceNpCommerce2GetProductInfoResult));
initialize_common_data(&result->commonData, data, internal_data_addr, internal_data_size);
return CELL_OK;
}
error_code sceNpCommerce2GetGameProductInfo(vm::cptr<SceNpCommerce2GetProductInfoResult> result, vm::ptr<SceNpCommerce2GameProductInfo> gameProductInfo)
{
sceNpCommerce2.todo("sceNpCommerce2GetGameProductInfo(result=*0x%x, gameProductInfo=*0x%x)", result, gameProductInfo);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Com2_init)
return SCE_NP_COMMERCE2_ERROR_NOT_INITIALIZED;
if (!result || !gameProductInfo)
return SCE_NP_COMMERCE2_ERROR_INVALID_ARGUMENT;
return CELL_OK;
}
error_code sceNpCommerce2DestroyGetProductInfoResult(vm::ptr<SceNpCommerce2GetProductInfoResult> result)
{
sceNpCommerce2.todo("sceNpCommerce2DestroyGetProductInfoResult(result=*0x%x)", result);
return CELL_OK;
}
error_code sceNpCommerce2GetProductInfoListCreateReq(u32 ctx_id, vm::ptr<u32> req_id)
{
sceNpCommerce2.todo("sceNpCommerce2GetProductInfoListCreateReq(ctx_id=%d, req_id=*0x%x)", ctx_id, req_id);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Com2_init)
return SCE_NP_COMMERCE2_ERROR_NOT_INITIALIZED;
if (!req_id)
return SCE_NP_COMMERCE2_ERROR_INVALID_ARGUMENT;
const auto ctx = get_commerce2_context(ctx_id);
if (!ctx)
return SCE_NP_COMMERCE2_ERROR_CTX_NOT_FOUND;
return CELL_OK;
}
error_code sceNpCommerce2GetProductInfoListStart(u32 req_id, vm::cpptr<char> productIds, u32 productNum)
{
sceNpCommerce2.todo("sceNpCommerce2GetProductInfoListStart(req_id=%d, productIds=*0x%x, productNum=%d)", req_id, productIds, productNum);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Com2_init)
return SCE_NP_COMMERCE2_ERROR_NOT_INITIALIZED;
if (!productIds || !productNum || productNum > SCE_NP_COMMERCE2_GETPRODLIST_MAX_COUNT)
return SCE_NP_COMMERCE2_ERROR_INVALID_ARGUMENT;
return CELL_OK;
}
error_code sceNpCommerce2GetProductInfoListGetResult(u32 req_id, vm::ptr<void> buf, u32 buf_size, vm::ptr<u32> fill_size)
{
sceNpCommerce2.todo("sceNpCommerce2GetProductInfoListGetResult(req_id=%d, buf=*0x%x, buf_size=%d, fill_size=*0x%x)", req_id, buf, buf_size, fill_size);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Com2_init)
return SCE_NP_COMMERCE2_ERROR_NOT_INITIALIZED;
if (buf_size < SCE_NP_COMMERCE2_RECV_BUF_SIZE)
return SCE_NP_COMMERCE2_ERROR_INSUFFICIENT_BUF_SIZE;
return get_result(req_id, buf, buf_size, fill_size);
}
error_code sceNpCommerce2InitGetProductInfoListResult(vm::ptr<SceNpCommerce2GetProductInfoListResult> result, vm::ptr<void> data, u32 data_size)
{
sceNpCommerce2.todo("sceNpCommerce2InitGetProductInfoListResult(result=*0x%x, data=*0x%x, data_size=%d)", result, data, data_size);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Com2_init)
return SCE_NP_COMMERCE2_ERROR_NOT_INITIALIZED;
if (!result || !data || !data_size)
return SCE_NP_COMMERCE2_ERROR_INVALID_ARGUMENT;
u32 internal_data_addr = 0, internal_data_size = 0;
error_code error = check_and_get_data(data, data_size, internal_data_addr, internal_data_size);
if (error < 0)
return error;
std::memset(result.get_ptr(), 0, sizeof(SceNpCommerce2GetProductInfoListResult));
initialize_common_data(&result->commonData, data, internal_data_addr, internal_data_size);
return CELL_OK;
}
error_code sceNpCommerce2GetGameProductInfoFromGetProductInfoListResult(vm::cptr<SceNpCommerce2GetProductInfoListResult> result, u32 index, vm::ptr<SceNpCommerce2GameProductInfo> gameProductInfo)
{
sceNpCommerce2.todo("sceNpCommerce2GetGameProductInfoFromGetProductInfoListResult(result=*0x%x, index=%d, data=*0x%x)", result, index, gameProductInfo);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Com2_init)
return SCE_NP_COMMERCE2_ERROR_NOT_INITIALIZED;
if (!result || !gameProductInfo)
return SCE_NP_COMMERCE2_ERROR_INVALID_ARGUMENT;
return CELL_OK;
}
error_code sceNpCommerce2DestroyGetProductInfoListResult(vm::ptr<SceNpCommerce2GetProductInfoListResult> result)
{
sceNpCommerce2.todo("sceNpCommerce2DestroyGetProductInfoListResult(result=*0x%x)", result);
return CELL_OK;
}
error_code sceNpCommerce2GetContentRatingInfoFromGameProductInfo(vm::cptr<SceNpCommerce2GameProductInfo> gameProductInfo, vm::ptr<SceNpCommerce2ContentRatingInfo> contentRatingInfo)
{
sceNpCommerce2.todo("sceNpCommerce2GetContentRatingInfoFromGameProductInfo(gameProductInfo=*0x%x, contentRatingInfo=*0x%x)", gameProductInfo, contentRatingInfo);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Com2_init)
return SCE_NP_COMMERCE2_ERROR_NOT_INITIALIZED;
if (!gameProductInfo || !contentRatingInfo)
return SCE_NP_COMMERCE2_ERROR_INVALID_ARGUMENT;
return CELL_OK;
}
error_code sceNpCommerce2GetContentRatingInfoFromCategoryInfo(vm::cptr<SceNpCommerce2CategoryInfo> categoryInfo, vm::ptr<SceNpCommerce2ContentRatingInfo> contentRatingInfo)
{
sceNpCommerce2.todo("sceNpCommerce2GetContentRatingInfoFromCategoryInfo(categoryInfo=*0x%x, contentRatingInfo=*0x%x)", categoryInfo, contentRatingInfo);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Com2_init)
return SCE_NP_COMMERCE2_ERROR_NOT_INITIALIZED;
if (!categoryInfo || !contentRatingInfo)
return SCE_NP_COMMERCE2_ERROR_INVALID_ARGUMENT;
return CELL_OK;
}
error_code sceNpCommerce2GetContentRatingDescriptor(vm::cptr<SceNpCommerce2ContentRatingInfo> contentRatingInfo, u32 index, vm::ptr<SceNpCommerce2ContentRatingDescriptor> contentRatingDescriptor)
{
sceNpCommerce2.todo("sceNpCommerce2GetContentRatingDescriptor(contentRatingInfo=*0x%x, index=%d, contentRatingDescriptor=*0x%x)", contentRatingInfo, index, contentRatingDescriptor);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Com2_init)
return SCE_NP_COMMERCE2_ERROR_NOT_INITIALIZED;
if (!contentRatingInfo || !contentRatingDescriptor)
return SCE_NP_COMMERCE2_ERROR_INVALID_ARGUMENT;
return CELL_OK;
}
error_code sceNpCommerce2GetGameSkuInfoFromGameProductInfo(vm::cptr<SceNpCommerce2GameProductInfo> gameProductInfo, u32 index, vm::ptr<SceNpCommerce2GameSkuInfo> gameSkuInfo)
{
sceNpCommerce2.todo("sceNpCommerce2GetGameSkuInfoFromGameProductInfo(gameProductInfo=*0x%x, index=%d, gameSkuInfo=*0x%x)", gameProductInfo, index, gameSkuInfo);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Com2_init)
return SCE_NP_COMMERCE2_ERROR_NOT_INITIALIZED;
if (!gameProductInfo || !gameSkuInfo)
return SCE_NP_COMMERCE2_ERROR_INVALID_ARGUMENT;
return CELL_OK;
}
error_code sceNpCommerce2GetPrice(u32 ctx_id, vm::ptr<char> buf, u32 buflen, u32 price)
{
sceNpCommerce2.todo("sceNpCommerce2GetPrice(ctx_id=%d, buf=*0x%x, buflen=%d, price=%d)", ctx_id, buf, buflen, price);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Com2_init)
return SCE_NP_COMMERCE2_ERROR_NOT_INITIALIZED;
const auto ctx = get_commerce2_context(ctx_id);
if (!ctx)
return SCE_NP_COMMERCE2_ERROR_CTX_NOT_FOUND;
return CELL_OK;
}
error_code sceNpCommerce2DoCheckoutStartAsync(u32 ctx_id, vm::cpptr<char> sku_ids, u32 sku_num, u32 container)
{
sceNpCommerce2.todo("sceNpCommerce2DoCheckoutStartAsync(ctx_id=%d, sku_ids=*0x%x, sku_num=%d, container=%d)", ctx_id, sku_ids, sku_num, container);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Com2_init)
return SCE_NP_COMMERCE2_ERROR_NOT_INITIALIZED;
if (sku_num > SCE_NP_COMMERCE2_SKU_CHECKOUT_MAX)
return SCE_NP_COMMERCE2_ERROR_INVALID_SKU_NUM;
for (u32 i = 0; i < sku_num; i++)
{
if (!sku_ids || !sku_ids[i] || !sku_ids[i][0])
return SCE_NP_COMMERCE2_ERROR_INVALID_SKUID;
}
if (false) // TODO
return SCE_NP_COMMERCE2_ERROR_INVALID_MEMORY_CONTAINER;
if (false) // TODO
return SCE_NP_COMMERCE2_ERROR_INSUFFICIENT_MEMORY_CONTAINER;
const auto ctx = get_commerce2_context(ctx_id);
if (!ctx)
return SCE_NP_COMMERCE2_ERROR_CTX_NOT_FOUND;
return CELL_OK;
}
error_code sceNpCommerce2DoCheckoutFinishAsync(u32 ctx_id)
{
sceNpCommerce2.todo("sceNpCommerce2DoCheckoutFinishAsync(ctx_id=%d)", ctx_id);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Com2_init)
return SCE_NP_COMMERCE2_ERROR_NOT_INITIALIZED;
const auto ctx = get_commerce2_context(ctx_id);
if (!ctx)
return SCE_NP_COMMERCE2_ERROR_CTX_NOT_FOUND;
return CELL_OK;
}
error_code sceNpCommerce2DoProductBrowseStartAsync(u32 ctx_id, vm::cptr<char> product_id, u32 container, vm::cptr<SceNpCommerce2ProductBrowseParam> param)
{
sceNpCommerce2.todo("sceNpCommerce2DoProductBrowseStartAsync(ctx_id=%d, product_id=%s, container=%d, param=*0x%x)", ctx_id, product_id, container, param);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Com2_init)
return SCE_NP_COMMERCE2_ERROR_NOT_INITIALIZED;
if (!product_id || !product_id[0])
return SCE_NP_COMMERCE2_ERROR_INVALID_ARGUMENT;
if (param && param->size != sizeof(SceNpCommerce2ProductBrowseParam))
return SCE_NP_COMMERCE2_ERROR_INVALID_SIZE;
if (false) // TODO
return SCE_NP_COMMERCE2_ERROR_INVALID_MEMORY_CONTAINER;
if (false) // TODO
return SCE_NP_COMMERCE2_ERROR_INSUFFICIENT_MEMORY_CONTAINER;
const auto ctx = get_commerce2_context(ctx_id);
if (!ctx)
return SCE_NP_COMMERCE2_ERROR_CTX_NOT_FOUND;
return CELL_OK;
}
error_code sceNpCommerce2DoProductBrowseFinishAsync(u32 ctx_id)
{
sceNpCommerce2.todo("sceNpCommerce2DoProductBrowseFinishAsync(ctx_id=%d)", ctx_id);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Com2_init)
return SCE_NP_COMMERCE2_ERROR_NOT_INITIALIZED;
const auto ctx = get_commerce2_context(ctx_id);
if (!ctx)
return SCE_NP_COMMERCE2_ERROR_CTX_NOT_FOUND;
return CELL_OK;
}
error_code sceNpCommerce2DoDlListStartAsync(u32 ctx_id, vm::cptr<char> service_id, vm::cpptr<char> sku_ids, u32 sku_num, u32 container)
{
sceNpCommerce2.todo("sceNpCommerce2DoDlListStartAsync(ctx_id=%d, service_id=%s, sku_ids=*0x%x, sku_num=%d, container=%d)", ctx_id, service_id, sku_ids, sku_num, container);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Com2_init)
return SCE_NP_COMMERCE2_ERROR_NOT_INITIALIZED;
if (sku_num > SCE_NP_COMMERCE2_SKU_CHECKOUT_MAX)
return SCE_NP_COMMERCE2_ERROR_INVALID_SKU_NUM;
if (sku_num == 0)
{
if (!service_id)
return SCE_NP_COMMERCE2_ERROR_INVALID_ARGUMENT;
}
else
{
for (u32 i = 0; i < sku_num; i++)
{
if (!sku_ids || !sku_ids[i] || !sku_ids[i][0])
return SCE_NP_COMMERCE2_ERROR_INVALID_SKUID;
}
}
if (false) // TODO
return SCE_NP_COMMERCE2_ERROR_INVALID_MEMORY_CONTAINER;
if (false) // TODO
return SCE_NP_COMMERCE2_ERROR_INSUFFICIENT_MEMORY_CONTAINER;
const auto ctx = get_commerce2_context(ctx_id);
if (!ctx)
return SCE_NP_COMMERCE2_ERROR_CTX_NOT_FOUND;
return CELL_OK;
}
error_code sceNpCommerce2DoDlListFinishAsync(u32 ctx_id)
{
sceNpCommerce2.todo("sceNpCommerce2DoDlListFinishAsync(ctx_id=%d)", ctx_id);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Com2_init)
return SCE_NP_COMMERCE2_ERROR_NOT_INITIALIZED;
const auto ctx = get_commerce2_context(ctx_id);
if (!ctx)
return SCE_NP_COMMERCE2_ERROR_CTX_NOT_FOUND;
return CELL_OK;
}
error_code sceNpCommerce2DoProductCodeStartAsync(u32 ctx_id, u32 container, vm::cptr<SceNpCommerce2ProductCodeParam> param)
{
sceNpCommerce2.todo("sceNpCommerce2DoProductCodeStartAsync(ctx_id=%d, container=%d, param=*0x%x)", ctx_id, container, param);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Com2_init)
return SCE_NP_COMMERCE2_ERROR_NOT_INITIALIZED;
if (!param)
return SCE_NP_COMMERCE2_ERROR_INVALID_ARGUMENT;
if (param->size != sizeof(SceNpCommerce2ProductCodeParam))
return SCE_NP_COMMERCE2_ERROR_INVALID_SIZE;
if (param->inputMode != SCE_NP_COMMERCE2_PRODUCT_CODE_INPUT_MODE_USER_INPUT)
{
if (param->inputMode != SCE_NP_COMMERCE2_PRODUCT_CODE_INPUT_MODE_CODE_SPECIFIED)
return SCE_NP_COMMERCE2_ERROR_INVALID_TARGET_TYPE;
if (!param->code1[0] || !param->code2[0] || !param->code3[0])
return SCE_NP_COMMERCE2_ERROR_INVALID_TARGET_ID;
for (u32 i = 0; i < SCE_NP_COMMERCE2_PRODUCT_CODE_BLOCK_LEN; i++)
{
if (!isalnum(param->code1[i]) || !isalnum(param->code2[i]) || !isalnum(param->code3[i]))
return SCE_NP_COMMERCE2_ERROR_INVALID_TARGET_ID;
}
}
if (false) // TODO
return SCE_NP_COMMERCE2_ERROR_INVALID_MEMORY_CONTAINER;
if (false) // TODO
return SCE_NP_COMMERCE2_ERROR_INSUFFICIENT_MEMORY_CONTAINER;
const auto ctx = get_commerce2_context(ctx_id);
if (!ctx)
return SCE_NP_COMMERCE2_ERROR_CTX_NOT_FOUND;
return CELL_OK;
}
error_code sceNpCommerce2DoProductCodeFinishAsync(u32 ctx_id)
{
sceNpCommerce2.todo("sceNpCommerce2DoProductCodeFinishAsync(ctx_id=%d)", ctx_id);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Com2_init)
return SCE_NP_COMMERCE2_ERROR_NOT_INITIALIZED;
const auto ctx = get_commerce2_context(ctx_id);
if (!ctx)
return SCE_NP_COMMERCE2_ERROR_CTX_NOT_FOUND;
return CELL_OK;
}
error_code sceNpCommerce2GetBGDLAvailability(vm::ptr<b8> bgdlAvailability)
{
sceNpCommerce2.todo("sceNpCommerce2GetBGDLAvailability(bgdlAvailability=*0x%x)", bgdlAvailability);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Com2_init)
return SCE_NP_COMMERCE2_ERROR_NOT_INITIALIZED;
if (!bgdlAvailability)
return SCE_NP_COMMERCE2_ERROR_INVALID_ARGUMENT;
*bgdlAvailability = false; // TODO
return CELL_OK;
}
error_code sceNpCommerce2SetBGDLAvailability(b8 bgdlAvailability)
{
sceNpCommerce2.todo("sceNpCommerce2SetBGDLAvailability(bgdlAvailability=%d)", bgdlAvailability);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Com2_init)
return SCE_NP_COMMERCE2_ERROR_NOT_INITIALIZED;
return CELL_OK;
}
error_code sceNpCommerce2AbortReq(u32 req_id)
{
sceNpCommerce2.todo("sceNpCommerce2AbortReq(req_id=%d)", req_id);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Com2_init)
return SCE_NP_COMMERCE2_ERROR_NOT_INITIALIZED;
return CELL_OK;
}
error_code sceNpCommerce2DestroyReq(u32 req_id)
{
sceNpCommerce2.todo("sceNpCommerce2DestroyReq(req_id=%d)", req_id);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Com2_init)
return SCE_NP_COMMERCE2_ERROR_NOT_INITIALIZED;
return CELL_OK;
}
error_code sceNpCommerce2DoServiceListStartAsync(u32 ctx_id, vm::ptr<char> serviceId, u32 container, vm::ptr<SceNpCommerce2ProductBrowseParam> param)
{
sceNpCommerce2.todo("sceNpCommerce2DoServiceListStartAsync(ctx_id=%d, serviceId=*0x%x, container=%d, param=*0x%x)", ctx_id, serviceId, container, param);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Com2_init)
return SCE_NP_COMMERCE2_ERROR_NOT_INITIALIZED;
if (!param || !serviceId)
return SCE_NP_COMMERCE2_ERROR_INVALID_ARGUMENT;
if (param->size != sizeof(SceNpCommerce2ProductBrowseParam))
return SCE_NP_COMMERCE2_ERROR_INVALID_SIZE;
if (!serviceId[0])
return SCE_NP_COMMERCE2_ERROR_INVALID_TARGET_ID;
if (false) // TODO
return SCE_NP_COMMERCE2_ERROR_INVALID_MEMORY_CONTAINER;
if (false) // TODO
return SCE_NP_COMMERCE2_ERROR_INSUFFICIENT_MEMORY_CONTAINER;
const auto ctx = get_commerce2_context(ctx_id);
if (!ctx)
return SCE_NP_COMMERCE2_ERROR_CTX_NOT_FOUND;
return CELL_OK;
}
error_code sceNpCommerce2DoServiceListFinishAsync(u32 ctx_id)
{
sceNpCommerce2.todo("sceNpCommerce2DoServiceListFinishAsync(ctx_id=%d)", ctx_id);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Com2_init)
return SCE_NP_COMMERCE2_ERROR_NOT_INITIALIZED;
const auto ctx = get_commerce2_context(ctx_id);
if (!ctx)
return SCE_NP_COMMERCE2_ERROR_CTX_NOT_FOUND;
return CELL_OK;
}
DECLARE(ppu_module_manager::sceNpCommerce2)("sceNpCommerce2", []()
{
REG_FUNC(sceNpCommerce2, sceNpCommerce2ExecuteStoreBrowse);
REG_FUNC(sceNpCommerce2, sceNpCommerce2GetStoreBrowseUserdata);
REG_FUNC(sceNpCommerce2, sceNpCommerce2Init);
REG_FUNC(sceNpCommerce2, sceNpCommerce2Term);
REG_FUNC(sceNpCommerce2, sceNpCommerce2CreateCtx);
REG_FUNC(sceNpCommerce2, sceNpCommerce2DestroyCtx);
REG_FUNC(sceNpCommerce2, sceNpCommerce2EmptyStoreCheckStart);
REG_FUNC(sceNpCommerce2, sceNpCommerce2EmptyStoreCheckAbort);
REG_FUNC(sceNpCommerce2, sceNpCommerce2EmptyStoreCheckFinish);
REG_FUNC(sceNpCommerce2, sceNpCommerce2CreateSessionStart);
REG_FUNC(sceNpCommerce2, sceNpCommerce2CreateSessionAbort);
REG_FUNC(sceNpCommerce2, sceNpCommerce2CreateSessionFinish);
REG_FUNC(sceNpCommerce2, sceNpCommerce2GetCategoryContentsCreateReq);
REG_FUNC(sceNpCommerce2, sceNpCommerce2GetCategoryContentsStart);
REG_FUNC(sceNpCommerce2, sceNpCommerce2GetCategoryContentsGetResult);
REG_FUNC(sceNpCommerce2, sceNpCommerce2InitGetCategoryContentsResult);
REG_FUNC(sceNpCommerce2, sceNpCommerce2GetCategoryInfo);
REG_FUNC(sceNpCommerce2, sceNpCommerce2GetContentInfo);
REG_FUNC(sceNpCommerce2, sceNpCommerce2GetCategoryInfoFromContentInfo);
REG_FUNC(sceNpCommerce2, sceNpCommerce2GetGameProductInfoFromContentInfo);
REG_FUNC(sceNpCommerce2, sceNpCommerce2DestroyGetCategoryContentsResult);
REG_FUNC(sceNpCommerce2, sceNpCommerce2GetProductInfoCreateReq);
REG_FUNC(sceNpCommerce2, sceNpCommerce2GetProductInfoStart);
REG_FUNC(sceNpCommerce2, sceNpCommerce2GetProductInfoGetResult);
REG_FUNC(sceNpCommerce2, sceNpCommerce2InitGetProductInfoResult);
REG_FUNC(sceNpCommerce2, sceNpCommerce2GetGameProductInfo);
REG_FUNC(sceNpCommerce2, sceNpCommerce2DestroyGetProductInfoResult);
REG_FUNC(sceNpCommerce2, sceNpCommerce2GetProductInfoListCreateReq);
REG_FUNC(sceNpCommerce2, sceNpCommerce2GetProductInfoListStart);
REG_FUNC(sceNpCommerce2, sceNpCommerce2GetProductInfoListGetResult);
REG_FUNC(sceNpCommerce2, sceNpCommerce2InitGetProductInfoListResult);
REG_FUNC(sceNpCommerce2, sceNpCommerce2GetGameProductInfoFromGetProductInfoListResult);
REG_FUNC(sceNpCommerce2, sceNpCommerce2DestroyGetProductInfoListResult);
REG_FUNC(sceNpCommerce2, sceNpCommerce2GetContentRatingInfoFromGameProductInfo);
REG_FUNC(sceNpCommerce2, sceNpCommerce2GetContentRatingInfoFromCategoryInfo);
REG_FUNC(sceNpCommerce2, sceNpCommerce2GetContentRatingDescriptor);
REG_FUNC(sceNpCommerce2, sceNpCommerce2GetGameSkuInfoFromGameProductInfo);
REG_FUNC(sceNpCommerce2, sceNpCommerce2GetPrice);
REG_FUNC(sceNpCommerce2, sceNpCommerce2DoCheckoutStartAsync);
REG_FUNC(sceNpCommerce2, sceNpCommerce2DoCheckoutFinishAsync);
REG_FUNC(sceNpCommerce2, sceNpCommerce2DoProductBrowseStartAsync);
REG_FUNC(sceNpCommerce2, sceNpCommerce2DoProductBrowseFinishAsync);
REG_FUNC(sceNpCommerce2, sceNpCommerce2DoDlListStartAsync);
REG_FUNC(sceNpCommerce2, sceNpCommerce2DoDlListFinishAsync);
REG_FUNC(sceNpCommerce2, sceNpCommerce2DoProductCodeStartAsync);
REG_FUNC(sceNpCommerce2, sceNpCommerce2DoProductCodeFinishAsync);
REG_FUNC(sceNpCommerce2, sceNpCommerce2GetBGDLAvailability);
REG_FUNC(sceNpCommerce2, sceNpCommerce2SetBGDLAvailability);
REG_FUNC(sceNpCommerce2, sceNpCommerce2AbortReq);
REG_FUNC(sceNpCommerce2, sceNpCommerce2DestroyReq);
REG_FUNC(sceNpCommerce2, sceNpCommerce2DoServiceListStartAsync);
REG_FUNC(sceNpCommerce2, sceNpCommerce2DoServiceListFinishAsync);
});
| 37,739
|
C++
|
.cpp
| 819
| 43.637363
| 195
| 0.776664
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
5,221
|
sys_heap.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/sys_heap.cpp
|
#include "stdafx.h"
#include "Emu/IdManager.h"
#include "Emu/Cell/PPUModule.h"
#include "sysPrxForUser.h"
LOG_CHANNEL(sysPrxForUser);
struct HeapInfo
{
static const u32 id_base = 1;
static const u32 id_step = 1;
static const u32 id_count = 1023;
SAVESTATE_INIT_POS(22);
const std::string name;
HeapInfo(const char* name)
: name(name)
{
}
};
u32 _sys_heap_create_heap(vm::cptr<char> name, u32 arg2, u32 arg3, u32 arg4)
{
sysPrxForUser.warning("_sys_heap_create_heap(name=%s, arg2=0x%x, arg3=0x%x, arg4=0x%x)", name, arg2, arg3, arg4);
return idm::make<HeapInfo>(name.get_ptr());
}
error_code _sys_heap_delete_heap(u32 heap)
{
sysPrxForUser.warning("_sys_heap_delete_heap(heap=0x%x)", heap);
idm::remove<HeapInfo>(heap);
return CELL_OK;
}
u32 _sys_heap_malloc(u32 heap, u32 size)
{
sysPrxForUser.warning("_sys_heap_malloc(heap=0x%x, size=0x%x)", heap, size);
return vm::alloc(size, vm::main);
}
u32 _sys_heap_memalign(u32 heap, u32 align, u32 size)
{
sysPrxForUser.warning("_sys_heap_memalign(heap=0x%x, align=0x%x, size=0x%x)", heap, align, size);
return vm::alloc(size, vm::main, std::max<u32>(align, 0x10000));
}
error_code _sys_heap_free(u32 heap, u32 addr)
{
sysPrxForUser.warning("_sys_heap_free(heap=0x%x, addr=0x%x)", heap, addr);
vm::dealloc(addr, vm::main);
return CELL_OK;
}
error_code _sys_heap_alloc_heap_memory()
{
sysPrxForUser.todo("_sys_heap_alloc_heap_memory()");
return CELL_OK;
}
error_code _sys_heap_get_mallinfo()
{
sysPrxForUser.todo("_sys_heap_get_mallinfo()");
return CELL_OK;
}
error_code _sys_heap_get_total_free_size()
{
sysPrxForUser.todo("_sys_heap_get_total_free_size()");
return CELL_OK;
}
error_code _sys_heap_stats()
{
sysPrxForUser.todo("_sys_heap_stats()");
return CELL_OK;
}
void sysPrxForUser_sys_heap_init()
{
REG_FUNC(sysPrxForUser, _sys_heap_create_heap);
REG_FUNC(sysPrxForUser, _sys_heap_delete_heap);
REG_FUNC(sysPrxForUser, _sys_heap_malloc);
REG_FUNC(sysPrxForUser, _sys_heap_memalign);
REG_FUNC(sysPrxForUser, _sys_heap_free);
REG_FUNC(sysPrxForUser, _sys_heap_alloc_heap_memory);
REG_FUNC(sysPrxForUser, _sys_heap_get_mallinfo);
REG_FUNC(sysPrxForUser, _sys_heap_get_total_free_size);
REG_FUNC(sysPrxForUser, _sys_heap_stats);
}
| 2,236
|
C++
|
.cpp
| 76
| 27.618421
| 114
| 0.731993
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| false
| false
|
5,222
|
HLE_PATCHES.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/HLE_PATCHES.cpp
|
#include "stdafx.h"
#include "Emu/IdManager.h"
#include "Emu/Cell/PPUModule.h"
#include "Utilities/Thread.h"
#include "Emu/Cell/lv2/sys_spu.h"
#include "Emu/Cell/lv2/sys_sync.h"
#include <thread>
// SONIC THE HEDGEDOG: a fix for a race condition between SPUs and PPUs causing missing graphics (SNR is overriden when non-empty)
void WaitForSPUsToEmptySNRs(ppu_thread& ppu, u32 spu_id, u32 snr_mask)
{
ppu.state += cpu_flag::wait;
auto [spu, group] = lv2_spu_group::get_thread(spu_id);
if ((!spu && spu_id != umax) || snr_mask % 4 == 0)
{
return;
}
// Wait until specified SNRs are reported empty at least once
for (bool has_busy = true; has_busy && !ppu.is_stopped(); std::this_thread::yield())
{
has_busy = false;
auto for_one = [&](u32, spu_thread& spu)
{
if ((snr_mask & 1) && spu.ch_snr1.get_count())
{
has_busy = true;
return;
}
if ((snr_mask & 2) && spu.ch_snr2.get_count())
{
has_busy = true;
}
};
if (spu)
{
// Wait for a single SPU
for_one(spu->id, *spu);
}
else
{
// Wait for all SPUs
idm::select<named_thread<spu_thread>>(for_one);
}
}
}
DECLARE(ppu_module_manager::hle_patches)("RPCS3_HLE_LIBRARY", []()
{
REG_FUNC(RPCS3_HLE_LIBRARY, WaitForSPUsToEmptySNRs);
});
| 1,258
|
C++
|
.cpp
| 48
| 23.458333
| 130
| 0.659167
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
5,223
|
sys_spinlock.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/sys_spinlock.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
#include "sysPrxForUser.h"
LOG_CHANNEL(sysPrxForUser);
void sys_spinlock_initialize(vm::ptr<atomic_be_t<u32>> lock)
{
sysPrxForUser.trace("sys_spinlock_initialize(lock=*0x%x)", lock);
if (*lock)
{
*lock = 0;
}
}
error_code sys_spinlock_lock(ppu_thread& ppu, vm::ptr<atomic_be_t<u32>> lock)
{
sysPrxForUser.trace("sys_spinlock_lock(lock=*0x%x)", lock);
// Try to exchange with 0xabadcafe, repeat until exchanged with 0
while (*lock || lock->exchange(0xabadcafe))
{
if (ppu.test_stopped())
{
ppu.state += cpu_flag::again;
return {};
}
}
return CELL_OK;
}
error_code sys_spinlock_trylock(vm::ptr<atomic_be_t<u32>> lock)
{
sysPrxForUser.trace("sys_spinlock_trylock(lock=*0x%x)", lock);
if (*lock || lock->exchange(0xabadcafe))
{
return not_an_error(CELL_EBUSY);
}
return CELL_OK;
}
void sys_spinlock_unlock(vm::ptr<atomic_be_t<u32>> lock)
{
sysPrxForUser.trace("sys_spinlock_unlock(lock=*0x%x)", lock);
*lock = 0;
}
void sysPrxForUser_sys_spinlock_init()
{
REG_FUNC(sysPrxForUser, sys_spinlock_initialize);
REG_FUNC(sysPrxForUser, sys_spinlock_lock);
REG_FUNC(sysPrxForUser, sys_spinlock_trylock);
REG_FUNC(sysPrxForUser, sys_spinlock_unlock);
}
| 1,244
|
C++
|
.cpp
| 47
| 24.404255
| 77
| 0.728885
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| false
| false
|
5,224
|
cellVideoUpload.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellVideoUpload.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
#include "cellVideoUpload.h"
#include "cellSysutil.h"
LOG_CHANNEL(cellVideoUpload);
template<>
void fmt_class_string<CellVideoUploadError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_VIDEO_UPLOAD_ERROR_CANCEL);
STR_CASE(CELL_VIDEO_UPLOAD_ERROR_NETWORK);
STR_CASE(CELL_VIDEO_UPLOAD_ERROR_SERVICE_STOP);
STR_CASE(CELL_VIDEO_UPLOAD_ERROR_SERVICE_BUSY);
STR_CASE(CELL_VIDEO_UPLOAD_ERROR_SERVICE_UNAVAILABLE);
STR_CASE(CELL_VIDEO_UPLOAD_ERROR_SERVICE_QUOTA);
STR_CASE(CELL_VIDEO_UPLOAD_ERROR_ACCOUNT_STOP);
STR_CASE(CELL_VIDEO_UPLOAD_ERROR_OUT_OF_MEMORY);
STR_CASE(CELL_VIDEO_UPLOAD_ERROR_FATAL);
STR_CASE(CELL_VIDEO_UPLOAD_ERROR_INVALID_VALUE);
STR_CASE(CELL_VIDEO_UPLOAD_ERROR_FILE_OPEN);
STR_CASE(CELL_VIDEO_UPLOAD_ERROR_INVALID_STATE);
}
return unknown;
});
}
error_code cellVideoUploadInitialize(vm::cptr<CellVideoUploadParam> pParam, vm::ptr<CellVideoUploadCallback> cb, vm::ptr<void> userdata)
{
cellVideoUpload.todo("cellVideoUploadInitialize(pParam=*0x%x, cb=*0x%x, userdata=*0x%x)", pParam, cb, userdata);
sysutil_register_cb([=](ppu_thread& ppu) -> s32
{
vm::var<char[]> pResultURL(128);
cb(ppu, CELL_VIDEO_UPLOAD_STATUS_INITIALIZED, CELL_OK, pResultURL, userdata);
cb(ppu, CELL_VIDEO_UPLOAD_STATUS_FINALIZED, CELL_OK, pResultURL, userdata);
return CELL_OK;
});
return CELL_OK;
}
DECLARE(ppu_module_manager::cellVideoUpload)("cellVideoUpload", []()
{
REG_FUNC(cellVideoUpload, cellVideoUploadInitialize);
});
| 1,601
|
C++
|
.cpp
| 44
| 33.772727
| 136
| 0.75501
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| true
| false
| false
| true
| false
| false
|
5,225
|
cellScreenshot.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellScreenshot.cpp
|
#include "stdafx.h"
#include "Emu/System.h"
#include "Emu/IdManager.h"
#include "Emu/VFS.h"
#include "Emu/Cell/PPUModule.h"
#include "cellScreenshot.h"
LOG_CHANNEL(cellScreenshot);
template<>
void fmt_class_string<CellScreenShotError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_SCREENSHOT_ERROR_INTERNAL);
STR_CASE(CELL_SCREENSHOT_ERROR_PARAM);
STR_CASE(CELL_SCREENSHOT_ERROR_DECODE);
STR_CASE(CELL_SCREENSHOT_ERROR_NOSPACE);
STR_CASE(CELL_SCREENSHOT_ERROR_UNSUPPORTED_COLOR_FORMAT);
}
return unknown;
});
}
std::string screenshot_info::get_overlay_path() const
{
return vfs::get(overlay_dir_name + "/" + overlay_file_name);
}
std::string screenshot_info::get_photo_title() const
{
std::string photo = photo_title;
if (photo.empty())
photo = Emu.GetTitle();
return photo;
}
std::string screenshot_info::get_game_title() const
{
std::string game = game_title;
if (game.empty())
game = Emu.GetTitle();
return game;
}
std::string screenshot_info::get_game_comment() const
{
return game_comment;
}
std::string screenshot_info::get_screenshot_path(const std::string& date_path) const
{
u32 counter = 0;
std::string path = vfs::get("/dev_hdd0/photo/" + date_path + "/" + get_photo_title());
std::string suffix = ".png";
while (!Emu.IsStopped() && fs::is_file(path + suffix))
{
suffix = fmt::format("_%d.png", ++counter);
}
return path + suffix;
}
error_code cellScreenShotSetParameter(vm::cptr<CellScreenShotSetParam> param)
{
cellScreenshot.warning("cellScreenShotSetParameter(param=*0x%x)", param);
if (!param) // TODO: check if param->reserved must be null
return CELL_SCREENSHOT_ERROR_PARAM;
if (param->photo_title && !memchr(param->photo_title.get_ptr(), '\0', CELL_SCREENSHOT_PHOTO_TITLE_MAX_LENGTH))
return CELL_SCREENSHOT_ERROR_PARAM;
if (param->game_title && !memchr(param->game_title.get_ptr(), '\0', CELL_SCREENSHOT_GAME_TITLE_MAX_LENGTH))
return CELL_SCREENSHOT_ERROR_PARAM;
if (param->game_comment && !memchr(param->game_comment.get_ptr(), '\0', CELL_SCREENSHOT_GAME_COMMENT_MAX_SIZE))
return CELL_SCREENSHOT_ERROR_PARAM;
auto& manager = g_fxo->get<screenshot_manager>();
std::lock_guard lock(manager.mutex);
if (param->photo_title && param->photo_title[0] != '\0')
manager.photo_title = std::string(param->photo_title.get_ptr());
else
manager.photo_title = "";
if (param->game_title && param->game_title[0] != '\0')
manager.game_title = std::string(param->game_title.get_ptr());
else
manager.game_title = "";
if (param->game_comment && param->game_comment[0] != '\0')
manager.game_comment = std::string(param->game_comment.get_ptr());
else
manager.game_comment = "";
cellScreenshot.notice("cellScreenShotSetParameter(photo_title=%s, game_title=%s, game_comment=%s)", manager.photo_title, manager.game_title, manager.game_comment);
return CELL_OK;
}
error_code cellScreenShotSetOverlayImage(vm::cptr<char> srcDir, vm::cptr<char> srcFile, s32 offset_x, s32 offset_y)
{
cellScreenshot.warning("cellScreenShotSetOverlayImage(srcDir=%s, srcFile=%s, offset_x=%d, offset_y=%d)", srcDir, srcFile, offset_x, offset_y);
if (!srcDir || !srcFile)
return CELL_SCREENSHOT_ERROR_PARAM;
// TODO: check srcDir (size 1024) and srcFile (size 64) for '-' or '_' or '.' or '/' in some manner (range checks?)
// Make sure that srcDir starts with /dev_hdd0, /dev_bdvd, /app_home or /host_root
if (strncmp(srcDir.get_ptr(), "/dev_hdd0", 9) && strncmp(srcDir.get_ptr(), "/dev_bdvd", 9) && strncmp(srcDir.get_ptr(), "/app_home", 9) && strncmp(srcDir.get_ptr(), "/host_root", 10))
{
return CELL_SCREENSHOT_ERROR_PARAM;
}
auto& manager = g_fxo->get<screenshot_manager>();
std::lock_guard lock(manager.mutex);
manager.overlay_dir_name = std::string(srcDir.get_ptr());
manager.overlay_file_name = std::string(srcFile.get_ptr());
manager.overlay_offset_x = offset_x;
manager.overlay_offset_y = offset_y;
return CELL_OK;
}
error_code cellScreenShotEnable()
{
cellScreenshot.trace("cellScreenShotEnable()");
auto& manager = g_fxo->get<screenshot_manager>();
std::lock_guard lock(manager.mutex);
if (!std::exchange(manager.is_enabled, true))
{
cellScreenshot.warning("cellScreenShotEnable(): Enabled");
}
return CELL_OK;
}
error_code cellScreenShotDisable()
{
cellScreenshot.trace("cellScreenShotDisable()");
auto& manager = g_fxo->get<screenshot_manager>();
std::lock_guard lock(manager.mutex);
if (std::exchange(manager.is_enabled, false))
{
cellScreenshot.warning("cellScreenShotDisable(): Disabled");
}
return CELL_OK;
}
DECLARE(ppu_module_manager::cellScreenShot)("cellScreenShotUtility", []()
{
REG_FUNC(cellScreenShotUtility, cellScreenShotSetParameter);
REG_FUNC(cellScreenShotUtility, cellScreenShotSetOverlayImage);
REG_FUNC(cellScreenShotUtility, cellScreenShotEnable);
REG_FUNC(cellScreenShotUtility, cellScreenShotDisable);
});
| 4,941
|
C++
|
.cpp
| 132
| 35.204545
| 184
| 0.730551
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| false
| false
|
5,226
|
cellGem.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellGem.cpp
|
#include "stdafx.h"
#include "cellGem.h"
#include "cellCamera.h"
#include "Emu/Cell/lv2/sys_event.h"
#include "Emu/Cell/PPUModule.h"
#include "Emu/Cell/timers.hpp"
#include "Emu/Io/MouseHandler.h"
#include "Emu/Io/gem_config.h"
#include "Emu/system_config.h"
#include "Emu/System.h"
#include "Emu/IdManager.h"
#include "Emu/RSX/Overlays/overlay_cursor.h"
#include "Input/pad_thread.h"
#ifdef HAVE_LIBEVDEV
#include "Input/evdev_gun_handler.h"
#endif
#include <cmath> // for fmod
#include <type_traits>
LOG_CHANNEL(cellGem);
extern u32 get_buffer_size_by_format(s32 format, s32 width, s32 height);
template <>
void fmt_class_string<gem_btn>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](gem_btn value)
{
switch (value)
{
case gem_btn::start: return "Start";
case gem_btn::select: return "Select";
case gem_btn::triangle: return "Triangle";
case gem_btn::circle: return "Circle";
case gem_btn::cross: return "Cross";
case gem_btn::square: return "Square";
case gem_btn::move: return "Move";
case gem_btn::t: return "T";
case gem_btn::count: return "Count";
case gem_btn::x_axis: return "X-Axis";
case gem_btn::y_axis: return "Y-Axis";
}
return unknown;
});
}
template <>
void fmt_class_string<CellGemError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_GEM_ERROR_RESOURCE_ALLOCATION_FAILED);
STR_CASE(CELL_GEM_ERROR_ALREADY_INITIALIZED);
STR_CASE(CELL_GEM_ERROR_UNINITIALIZED);
STR_CASE(CELL_GEM_ERROR_INVALID_PARAMETER);
STR_CASE(CELL_GEM_ERROR_INVALID_ALIGNMENT);
STR_CASE(CELL_GEM_ERROR_UPDATE_NOT_FINISHED);
STR_CASE(CELL_GEM_ERROR_UPDATE_NOT_STARTED);
STR_CASE(CELL_GEM_ERROR_CONVERT_NOT_FINISHED);
STR_CASE(CELL_GEM_ERROR_CONVERT_NOT_STARTED);
STR_CASE(CELL_GEM_ERROR_WRITE_NOT_FINISHED);
STR_CASE(CELL_GEM_ERROR_NOT_A_HUE);
}
return unknown;
});
}
template <>
void fmt_class_string<CellGemStatus>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_GEM_NOT_CONNECTED);
STR_CASE(CELL_GEM_SPHERE_NOT_CALIBRATED);
STR_CASE(CELL_GEM_SPHERE_CALIBRATING);
STR_CASE(CELL_GEM_COMPUTING_AVAILABLE_COLORS);
STR_CASE(CELL_GEM_HUE_NOT_SET);
STR_CASE(CELL_GEM_NO_VIDEO);
STR_CASE(CELL_GEM_TIME_OUT_OF_RANGE);
STR_CASE(CELL_GEM_NOT_CALIBRATED);
STR_CASE(CELL_GEM_NO_EXTERNAL_PORT_DEVICE);
}
return unknown;
});
}
template <>
void fmt_class_string<CellGemVideoConvertFormatEnum>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto format)
{
switch (format)
{
STR_CASE(CELL_GEM_NO_VIDEO_OUTPUT);
STR_CASE(CELL_GEM_RGBA_640x480);
STR_CASE(CELL_GEM_YUV_640x480);
STR_CASE(CELL_GEM_YUV422_640x480);
STR_CASE(CELL_GEM_YUV411_640x480);
STR_CASE(CELL_GEM_RGBA_320x240);
STR_CASE(CELL_GEM_BAYER_RESTORED);
STR_CASE(CELL_GEM_BAYER_RESTORED_RGGB);
STR_CASE(CELL_GEM_BAYER_RESTORED_RASTERIZED);
}
return unknown;
});
}
// last 4 out of 7 ports (7,6,5,4). index starts at 1
static u32 port_num(u32 gem_num)
{
ensure(gem_num < CELL_GEM_MAX_NUM);
return CELL_PAD_MAX_PORT_NUM - gem_num;
}
// last 4 out of 7 ports (6,5,4,3). index starts at 0
static u32 pad_num(u32 gem_num)
{
ensure(gem_num < CELL_GEM_MAX_NUM);
return (CELL_PAD_MAX_PORT_NUM - 1) - gem_num;
}
// **********************
// * HLE helper structs *
// **********************
#ifdef HAVE_LIBEVDEV
struct gun_handler
{
public:
gun_handler() = default;
static constexpr auto thread_name = "Evdev Gun Thread"sv;
evdev_gun_handler handler{};
atomic_t<u32> num_devices{0};
void operator()()
{
if (g_cfg.io.move != move_handler::gun)
{
return;
}
while (thread_ctrl::state() != thread_state::aborting && !Emu.IsStopped())
{
const bool is_active = !Emu.IsPaused() && handler.is_init();
if (is_active)
{
for (u32 i = 0; i < num_devices; i++)
{
std::scoped_lock lock(handler.mutex);
handler.poll(i);
}
}
thread_ctrl::wait_for(is_active ? 1000 : 10000);
}
}
};
using gun_thread = named_thread<gun_handler>;
#endif
cfg_gems g_cfg_gem;
struct gem_config_data
{
public:
void operator()();
static constexpr auto thread_name = "Gem Thread"sv;
atomic_t<u8> state = 0;
struct gem_color
{
float r, g, b;
gem_color() : r(0.0f), g(0.0f), b(0.0f) {}
gem_color(float r_, float g_, float b_)
{
r = std::clamp(r_, 0.0f, 1.0f);
g = std::clamp(g_, 0.0f, 1.0f);
b = std::clamp(b_, 0.0f, 1.0f);
}
static inline const gem_color& get_default_color(u32 gem_num)
{
static const gem_color gold = gem_color(1.0f, 0.85f, 0.0f);
static const gem_color green = gem_color(0.0f, 1.0f, 0.0f);
static const gem_color red = gem_color(1.0f, 0.0f, 0.0f);
static const gem_color pink = gem_color(0.9f, 0.0f, 0.5f);
switch (gem_num)
{
case 0: return green;
case 1: return gold;
case 2: return red;
case 3: return pink;
default: fmt::throw_exception("unexpected gem_num %d", gem_num);
}
}
};
struct gem_controller
{
u32 status = CELL_GEM_STATUS_DISCONNECTED; // Connection status (CELL_GEM_STATUS_DISCONNECTED or CELL_GEM_STATUS_READY)
u32 ext_status = CELL_GEM_NO_EXTERNAL_PORT_DEVICE; // External port connection status
u32 ext_id = 0; // External device ID (type). For example SHARP_SHOOTER_DEVICE_ID
u32 port = 0; // Assigned port
bool enabled_magnetometer = false; // Whether the magnetometer is enabled (probably used for additional rotational precision)
bool calibrated_magnetometer = false; // Whether the magnetometer is calibrated
bool enabled_filtering = false; // Whether filtering is enabled
bool enabled_tracking = false; // Whether tracking is enabled
bool enabled_LED = false; // Whether the LED is enabled
bool hue_set = false; // Whether the hue was set
u8 rumble = 0; // Rumble intensity
gem_color sphere_rgb = {}; // RGB color of the sphere LED
u32 hue = 0; // Tracking hue of the motion controller
f32 distance{1500.0f}; // Distance from the camera in mm
f32 radius{10.0f}; // Radius of the sphere in camera pixels
bool is_calibrating{false}; // Whether or not we are currently calibrating
u64 calibration_start_us{0}; // The start timestamp of the calibration in microseconds
static constexpr u64 calibration_time_us = 500000; // The calibration supposedly takes 0.5 seconds (500000 microseconds)
ENABLE_BITWISE_SERIALIZATION;
};
CellGemAttribute attribute = {};
CellGemVideoConvertAttribute vc_attribute = {};
s32 video_data_out_size = -1;
std::vector<u8> video_data_in;
u64 status_flags = 0;
bool enable_pitch_correction = false;
u32 inertial_counter = 0;
std::array<gem_controller, CELL_GEM_MAX_NUM> controllers;
u32 connected_controllers = 0;
atomic_t<bool> video_conversion_in_progress{false};
atomic_t<bool> update_started{false};
u32 camera_frame{};
u32 memory_ptr{};
shared_mutex mtx;
u64 start_timestamp_us = 0;
// helper functions
bool is_controller_ready(u32 gem_num) const
{
return controllers[gem_num].status == CELL_GEM_STATUS_READY;
}
bool is_controller_calibrating(u32 gem_num)
{
gem_controller& gem = controllers[gem_num];
if (gem.is_calibrating)
{
if ((get_guest_system_time() - gem.calibration_start_us) >= gem_controller::calibration_time_us)
{
gem.is_calibrating = false;
gem.calibration_start_us = 0;
gem.calibrated_magnetometer = true;
gem.enabled_tracking = true;
gem.hue = 1;
status_flags = CELL_GEM_FLAG_CALIBRATION_SUCCEEDED | CELL_GEM_FLAG_CALIBRATION_OCCURRED;
}
}
return gem.is_calibrating;
}
void reset_controller(u32 gem_num)
{
if (gem_num >= CELL_GEM_MAX_NUM)
{
return;
}
bool is_connected = false;
switch (g_cfg.io.move)
{
case move_handler::fake:
{
connected_controllers = 0;
std::lock_guard lock(pad::g_pad_mutex);
const auto handler = pad::get_current_handler();
for (u32 i = 0; i < std::min<u32>(attribute.max_connect, CELL_GEM_MAX_NUM); i++)
{
const auto& pad = ::at32(handler->GetPads(), pad_num(i));
if (pad && (pad->m_port_status & CELL_PAD_STATUS_CONNECTED))
{
connected_controllers++;
if (gem_num == i)
{
is_connected = true;
}
}
}
break;
}
case move_handler::mouse:
case move_handler::raw_mouse:
{
auto& handler = g_fxo->get<MouseHandlerBase>();
std::lock_guard mouse_lock(handler.mutex);
// Make sure that the mouse handler is initialized
handler.Init(std::min<u32>(attribute.max_connect, CELL_GEM_MAX_NUM));
const MouseInfo& info = handler.GetInfo();
connected_controllers = std::min<u32>({ info.now_connect, attribute.max_connect, CELL_GEM_MAX_NUM });
if (gem_num < connected_controllers)
{
is_connected = true;
}
break;
}
#ifdef HAVE_LIBEVDEV
case move_handler::gun:
{
gun_thread& gun = g_fxo->get<gun_thread>();
std::scoped_lock lock(gun.handler.mutex);
gun.num_devices = gun.handler.init() ? gun.handler.get_num_guns() : 0;
connected_controllers = std::min<u32>(std::min<u32>(attribute.max_connect, CELL_GEM_MAX_NUM), gun.num_devices);
if (gem_num < connected_controllers)
{
is_connected = true;
}
break;
}
#endif
case move_handler::null:
break;
}
gem_controller& controller = ::at32(controllers, gem_num);
controller = {};
controller.sphere_rgb = gem_color::get_default_color(gem_num);
// Assign status and port number
if (is_connected)
{
controller.status = CELL_GEM_STATUS_READY;
controller.port = port_num(gem_num);
}
}
gem_config_data()
{
if (!g_cfg_gem.load())
{
cellGem.notice("Could not load gem config. Using defaults.");
}
cellGem.notice("Gem config=\n", g_cfg_gem.to_string());
};
SAVESTATE_INIT_POS(15);
void save(utils::serial& ar)
{
ar(state);
if (!state)
{
return;
}
[[maybe_unused]] const s32 version = GET_OR_USE_SERIALIZATION_VERSION(ar.is_writing(), cellGem);
ar(attribute, vc_attribute, status_flags, enable_pitch_correction, inertial_counter, controllers
, connected_controllers, update_started, camera_frame, memory_ptr, start_timestamp_us);
}
gem_config_data(utils::serial& ar)
{
save(ar);
if (ar.is_writing())
return;
if (!g_cfg_gem.load())
{
cellGem.notice("Could not load gem config. Using defaults.");
}
cellGem.notice("Gem config=\n", g_cfg_gem.to_string());
}
};
static inline int32_t cellGemGetVideoConvertSize(s32 output_format)
{
switch (output_format)
{
case CELL_GEM_RGBA_320x240: // RGBA output; 320*240*4-byte output buffer required
return 320 * 240 * 4;
case CELL_GEM_RGBA_640x480: // RGBA output; 640*480*4-byte output buffer required
return 640 * 480 * 4;
case CELL_GEM_YUV_640x480: // YUV output; 640*480+640*480+640*480-byte output buffer required (contiguous)
return 640 * 480 + 640 * 480 + 640 * 480;
case CELL_GEM_YUV422_640x480: // YUV output; 640*480+320*480+320*480-byte output buffer required (contiguous)
return 640 * 480 + 320 * 480 + 320 * 480;
case CELL_GEM_YUV411_640x480: // YUV411 output; 640*480+320*240+320*240-byte output buffer required (contiguous)
return 640 * 480 + 320 * 240 + 320 * 240;
case CELL_GEM_BAYER_RESTORED: // Bayer pattern output, 640x480, gamma and white balance applied, output buffer required
case CELL_GEM_BAYER_RESTORED_RGGB: // Restored Bayer output, 2x2 pixels rearranged into 320x240 RG1G2B
case CELL_GEM_BAYER_RESTORED_RASTERIZED: // Restored Bayer output, R,G1,G2,B rearranged into 4 contiguous 320x240 1-channel rasters
return 640 * 480;
case CELL_GEM_NO_VIDEO_OUTPUT: // Disable video output
return 0;
default:
return -1;
}
}
namespace gem
{
bool convert_image_format(CellCameraFormat input_format, CellGemVideoConvertFormatEnum output_format,
const std::vector<u8>& video_data_in, u32 width, u32 height,
u8* video_data_out, u32 video_data_out_size)
{
if (output_format != CELL_GEM_NO_VIDEO_OUTPUT && !video_data_out)
{
return false;
}
const u32 required_in_size = get_buffer_size_by_format(static_cast<s32>(input_format), width, height);
const s32 required_out_size = cellGemGetVideoConvertSize(output_format);
if (video_data_in.size() != required_in_size)
{
cellGem.error("convert: in_size mismatch: required=%d, actual=%d", required_in_size, video_data_in.size());
return false;
}
if (required_out_size < 0 || video_data_out_size != static_cast<u32>(required_out_size))
{
cellGem.error("convert: out_size unknown: required=%d, format %d", required_out_size, output_format);
return false;
}
if (required_out_size == 0)
{
return false;
}
switch (output_format)
{
case CELL_GEM_RGBA_640x480: // RGBA output; 640*480*4-byte output buffer required
{
switch (input_format)
{
case CELL_CAMERA_RAW8:
{
const u32 in_pitch = width;
const u32 out_pitch = width * 4;
for (u32 y = 0; y < height - 1; y += 2)
{
const u8* src = &video_data_in[y * in_pitch];
const u8* src0 = src;
const u8* src1 = src + in_pitch;
u8* dst_row = video_data_out + y * out_pitch;
u8* dst0 = dst_row;
u8* dst1 = dst_row + out_pitch;
for (uint32_t x = 0; x < width - 1; x += 2, src0 += 2, src1 += 2, dst0 += 8, dst1 += 8)
{
const uint8_t b = src0[0];
const uint8_t g0 = src0[1];
const uint8_t g1 = src1[0];
const uint8_t r = src1[1];
const uint8_t top[4] = { r, g0, b, 255 };
const uint8_t bottom[4] = { r, g1, b, 255 };
// Top-Left
std::memcpy(dst0, top, 4);
// Top-Right Pixel
std::memcpy(dst0 + 4, top, 4);
// Bottom-Left Pixel
std::memcpy(dst1, bottom, 4);
// Bottom-Right Pixel
std::memcpy(dst1 + 4, bottom, 4);
}
}
break;
}
case CELL_CAMERA_RGBA:
{
std::memcpy(video_data_out, video_data_in.data(), std::min<usz>(required_in_size, required_out_size));
break;
}
default:
{
cellGem.error("Unimplemented: Converting %s to %s", input_format, output_format);
std::memcpy(video_data_out, video_data_in.data(), std::min<usz>(required_in_size, required_out_size));
return false;
}
}
break;
}
case CELL_GEM_BAYER_RESTORED: // Bayer pattern output, 640x480, gamma and white balance applied, output buffer required
{
if (input_format == CELL_CAMERA_RAW8)
{
std::memcpy(video_data_out, video_data_in.data(), std::min<usz>(required_in_size, required_out_size));
}
else
{
cellGem.error("Unimplemented: Converting %s to %s", input_format, output_format);
return false;
}
break;
}
case CELL_GEM_RGBA_320x240: // RGBA output; 320*240*4-byte output buffer required
case CELL_GEM_YUV_640x480: // YUV output; 640*480+640*480+640*480-byte output buffer required (contiguous)
case CELL_GEM_YUV422_640x480: // YUV output; 640*480+320*480+320*480-byte output buffer required (contiguous)
case CELL_GEM_YUV411_640x480: // YUV411 output; 640*480+320*240+320*240-byte output buffer required (contiguous)
case CELL_GEM_BAYER_RESTORED_RGGB: // Restored Bayer output, 2x2 pixels rearranged into 320x240 RG1G2B
case CELL_GEM_BAYER_RESTORED_RASTERIZED: // Restored Bayer output, R,G1,G2,B rearranged into 4 contiguous 320x240 1-channel rasters
{
cellGem.error("Unimplemented: Converting %s to %s", input_format, output_format);
return false;
}
case CELL_GEM_NO_VIDEO_OUTPUT: // Disable video output
{
cellGem.trace("Ignoring frame conversion for CELL_GEM_NO_VIDEO_OUTPUT");
break;
}
default:
{
cellGem.error("Trying to convert %s to %s", input_format, output_format);
return false;
}
}
return true;
}
}
void gem_config_data::operator()()
{
cellGem.notice("Starting thread");
while (thread_ctrl::state() != thread_state::aborting && !Emu.IsStopped())
{
while (!video_conversion_in_progress && thread_ctrl::state() != thread_state::aborting && !Emu.IsStopped())
{
thread_ctrl::wait_for(1000);
}
if (thread_ctrl::state() == thread_state::aborting || Emu.IsStopped())
{
return;
}
CellGemVideoConvertAttribute vc;
{
std::scoped_lock lock(mtx);
vc = vc_attribute;
}
if (g_cfg.io.camera != camera_handler::qt)
{
video_conversion_in_progress = false;
continue;
}
const auto& shared_data = g_fxo->get<gem_camera_shared>();
if (gem::convert_image_format(shared_data.format, vc.output_format, video_data_in, shared_data.width, shared_data.height, vc_attribute.video_data_out ? vc_attribute.video_data_out.get_ptr() : nullptr, video_data_out_size))
{
cellGem.trace("Converted video frame of format %s to %s", shared_data.format.load(), vc.output_format.get());
}
video_conversion_in_progress = false;
}
}
using gem_config = named_thread<gem_config_data>;
/**
* \brief Verifies that a Move controller id is valid
* \param gem_num Move controler ID to verify
* \return True if the ID is valid, false otherwise
*/
static bool check_gem_num(u32 gem_num)
{
return gem_num < CELL_GEM_MAX_NUM;
}
static inline void draw_overlay_cursor(u32 gem_num, const gem_config::gem_controller&, s32 x_pos, s32 y_pos, s32 x_max, s32 y_max)
{
const s16 x = static_cast<s16>(x_pos / (x_max / static_cast<f32>(rsx::overlays::overlay::virtual_width)));
const s16 y = static_cast<s16>(y_pos / (y_max / static_cast<f32>(rsx::overlays::overlay::virtual_height)));
// Note: We shouldn't use sphere_rgb here. The game will set it to black in many cases.
const gem_config_data::gem_color& rgb = gem_config_data::gem_color::get_default_color(gem_num);
const color4f color = { rgb.r, rgb.g, rgb.b, 0.85f };
rsx::overlays::set_cursor(rsx::overlays::cursor_offset::cell_gem + gem_num, x, y, color, 2'000'000, false);
}
static inline void pos_to_gem_image_state(u32 gem_num, const gem_config::gem_controller& controller, vm::ptr<CellGemImageState>& gem_image_state, s32 x_pos, s32 y_pos, s32 x_max, s32 y_max)
{
const auto& shared_data = g_fxo->get<gem_camera_shared>();
if (x_max <= 0) x_max = shared_data.width;
if (y_max <= 0) y_max = shared_data.height;
const f32 scaling_width = x_max / static_cast<f32>(shared_data.width);
const f32 scaling_height = y_max / static_cast<f32>(shared_data.height);
const f32 mmPerPixel = CELL_GEM_SPHERE_RADIUS_MM / controller.radius;
// Image coordinates in pixels
const f32 image_x = static_cast<f32>(x_pos) / scaling_width;
const f32 image_y = static_cast<f32>(y_pos) / scaling_height;
// Centered image coordinates in pixels
const f32 centered_x = image_x - (shared_data.width / 2.f);
const f32 centered_y = (shared_data.height / 2.f) - image_y; // Image coordinates increase downwards, so we have to invert this
// Camera coordinates in mm (centered, so it's the same as world coordinates)
const f32 camera_x = centered_x * mmPerPixel;
const f32 camera_y = centered_y * mmPerPixel;
// Image coordinates in pixels
gem_image_state->u = image_x;
gem_image_state->v = image_y;
// Projected camera coordinates in mm
gem_image_state->projectionx = camera_x / controller.distance;
gem_image_state->projectiony = camera_y / controller.distance;
if (g_cfg.io.show_move_cursor)
{
draw_overlay_cursor(gem_num, controller, x_pos, y_pos, x_max, y_max);
}
}
static inline void pos_to_gem_state(u32 gem_num, const gem_config::gem_controller& controller, vm::ptr<CellGemState>& gem_state, s32 x_pos, s32 y_pos, s32 x_max, s32 y_max)
{
const auto& shared_data = g_fxo->get<gem_camera_shared>();
if (x_max <= 0) x_max = shared_data.width;
if (y_max <= 0) y_max = shared_data.height;
const f32 scaling_width = x_max / static_cast<f32>(shared_data.width);
const f32 scaling_height = y_max / static_cast<f32>(shared_data.height);
const f32 mmPerPixel = CELL_GEM_SPHERE_RADIUS_MM / controller.radius;
// Image coordinates in pixels
const f32 image_x = static_cast<f32>(x_pos) / scaling_width;
const f32 image_y = static_cast<f32>(y_pos) / scaling_height;
// Centered image coordinates in pixels
const f32 centered_x = image_x - (shared_data.width / 2.f);
const f32 centered_y = (shared_data.height / 2.f) - image_y; // Image coordinates increase downwards, so we have to invert this
// Camera coordinates in mm (centered, so it's the same as world coordinates)
const f32 camera_x = centered_x * mmPerPixel;
const f32 camera_y = centered_y * mmPerPixel;
// World coordinates in mm
gem_state->pos[0] = camera_x;
gem_state->pos[1] = camera_y;
gem_state->pos[2] = static_cast<f32>(controller.distance);
gem_state->pos[3] = 0.f;
gem_state->quat[0] = 320.f - image_x;
gem_state->quat[1] = (y_pos / scaling_width) - 180.f;
gem_state->quat[2] = 1200.f;
// TODO: calculate handle position based on our world coordinate and the angles
gem_state->handle_pos[0] = camera_x;
gem_state->handle_pos[1] = camera_y;
gem_state->handle_pos[2] = static_cast<f32>(controller.distance + 10);
gem_state->handle_pos[3] = 0.f;
if (g_cfg.io.show_move_cursor)
{
draw_overlay_cursor(gem_num, controller, x_pos, y_pos, x_max, y_max);
}
}
extern bool is_input_allowed();
/**
* \brief Maps Move controller data (digital buttons, and analog Trigger data) to DS3 pad input.
* Unavoidably buttons conflict with DS3 mappings, which is problematic for some games.
* \param gem_num gem index to use
* \param digital_buttons Bitmask filled with CELL_GEM_CTRL_* values
* \param analog_t Analog value of Move's Trigger. Currently mapped to R2.
* \return true on success, false if controller is disconnected
*/
static void ds3_input_to_pad(const u32 gem_num, be_t<u16>& digital_buttons, be_t<u16>& analog_t)
{
digital_buttons = 0;
analog_t = 0;
if (!is_input_allowed())
{
return;
}
std::lock_guard lock(pad::g_pad_mutex);
const auto handler = pad::get_current_handler();
const auto& pad = ::at32(handler->GetPads(), pad_num(gem_num));
if (!(pad->m_port_status & CELL_PAD_STATUS_CONNECTED))
{
return;
}
const auto& cfg = ::at32(g_cfg_gem.players, gem_num);
cfg->handle_input(pad, true, [&](gem_btn btn, u16 value, bool pressed)
{
if (!pressed)
return;
switch (btn)
{
case gem_btn::start:
digital_buttons |= CELL_GEM_CTRL_START;
break;
case gem_btn::select:
digital_buttons |= CELL_GEM_CTRL_SELECT;
break;
case gem_btn::square:
digital_buttons |= CELL_GEM_CTRL_SQUARE;
break;
case gem_btn::cross:
digital_buttons |= CELL_GEM_CTRL_CROSS;
break;
case gem_btn::circle:
digital_buttons |= CELL_GEM_CTRL_CIRCLE;
break;
case gem_btn::triangle:
digital_buttons |= CELL_GEM_CTRL_TRIANGLE;
break;
case gem_btn::move:
digital_buttons |= CELL_GEM_CTRL_MOVE;
break;
case gem_btn::t:
digital_buttons |= CELL_GEM_CTRL_T;
analog_t = std::max<u16>(analog_t, value);
break;
case gem_btn::x_axis:
case gem_btn::y_axis:
case gem_btn::count:
break;
}
});
}
constexpr u16 ds3_max_x = 255;
constexpr u16 ds3_max_y = 255;
static inline void ds3_get_stick_values(u32 gem_num, const std::shared_ptr<Pad>& pad, s32& x_pos, s32& y_pos)
{
x_pos = 0;
y_pos = 0;
const auto& cfg = ::at32(g_cfg_gem.players, gem_num);
cfg->handle_input(pad, true, [&](gem_btn btn, u16 value, bool pressed)
{
if (!pressed)
return;
switch (btn)
{
case gem_btn::x_axis:
x_pos = value;
break;
case gem_btn::y_axis:
y_pos = value;
break;
default:
break;
}
});
}
template <typename T>
static void ds3_pos_to_gem_state(u32 gem_num, const gem_config::gem_controller& controller, T& gem_state)
{
if (!gem_state || !is_input_allowed())
{
return;
}
std::lock_guard lock(pad::g_pad_mutex);
const auto handler = pad::get_current_handler();
const auto& pad = ::at32(handler->GetPads(), pad_num(gem_num));
if (!(pad->m_port_status & CELL_PAD_STATUS_CONNECTED))
{
return;
}
s32 ds3_pos_x, ds3_pos_y;
ds3_get_stick_values(gem_num, pad, ds3_pos_x, ds3_pos_y);
if constexpr (std::is_same_v<T, vm::ptr<CellGemState>>)
{
pos_to_gem_state(gem_num, controller, gem_state, ds3_pos_x, ds3_pos_y, ds3_max_x, ds3_max_y);
}
else if constexpr (std::is_same_v<T, vm::ptr<CellGemImageState>>)
{
pos_to_gem_image_state(gem_num, controller, gem_state, ds3_pos_x, ds3_pos_y, ds3_max_x, ds3_max_y);
}
}
/**
* \brief Maps external Move controller data to DS3 input. (This can be input from any physical pad, not just the DS3)
* Implementation detail: CellGemExtPortData's digital/analog fields map the same way as
* libPad, so no translation is needed.
* \param gem_num gem index to use
* \param ext External data to modify
* \return true on success, false if controller is disconnected
*/
static void ds3_input_to_ext(const u32 gem_num, const gem_config::gem_controller& controller, CellGemExtPortData& ext)
{
ext = {};
if (!is_input_allowed())
{
return;
}
std::lock_guard lock(pad::g_pad_mutex);
const auto handler = pad::get_current_handler();
const auto& pad = ::at32(handler->GetPads(), pad_num(gem_num));
if (!(pad->m_port_status & CELL_PAD_STATUS_CONNECTED))
{
return;
}
ext.status = 0; // CELL_GEM_EXT_CONNECTED | CELL_GEM_EXT_EXT0 | CELL_GEM_EXT_EXT1
ext.analog_left_x = pad->m_analog_left_x; // HACK: these pad members are actually only set in cellPad
ext.analog_left_y = pad->m_analog_left_y;
ext.analog_right_x = pad->m_analog_right_x;
ext.analog_right_y = pad->m_analog_right_y;
ext.digital1 = pad->m_digital_1;
ext.digital2 = pad->m_digital_2;
if (controller.ext_id == SHARP_SHOOTER_DEVICE_ID)
{
// TODO set custom[0] bits as follows:
// 1xxxxxxx: RL reload button is pressed.
// x1xxxxxx: T button trigger is pressed.
// xxxxx001: Firing mode selector is in position 1.
// xxxxx010: Firing mode selector is in position 2.
// xxxxx100: Firing mode selector is in position 3.
}
}
/**
* \brief Maps Move controller data (digital buttons, and analog Trigger data) to mouse input.
* \param mouse_no Mouse index number to use
* \param digital_buttons Bitmask filled with CELL_GEM_CTRL_* values
* \param analog_t Analog value of Move's Trigger.
* \return true on success, false if mouse_no is invalid
*/
static bool mouse_input_to_pad(const u32 mouse_no, be_t<u16>& digital_buttons, be_t<u16>& analog_t)
{
digital_buttons = 0;
analog_t = 0;
if (!is_input_allowed())
{
return false;
}
auto& handler = g_fxo->get<MouseHandlerBase>();
std::scoped_lock lock(handler.mutex);
// Make sure that the mouse handler is initialized
handler.Init(std::min<u32>(g_fxo->get<gem_config>().attribute.max_connect, CELL_GEM_MAX_NUM));
if (mouse_no >= handler.GetMice().size())
{
return false;
}
std::set<MouseButtonCodes> pressed_buttons;
const Mouse& mouse_data = ::at32(handler.GetMice(), mouse_no);
const auto is_pressed = [&mouse_data, &pressed_buttons](MouseButtonCodes button) -> bool
{
// Only allow each button to be used for one action unless it's the combo button.
return (mouse_data.buttons & button) && (button == (CELL_MOUSE_BUTTON_3 + 0u/*fix warning*/) || pressed_buttons.insert(button).second);
};
digital_buttons = 0;
if ((is_pressed(CELL_MOUSE_BUTTON_3) && is_pressed(CELL_MOUSE_BUTTON_1)) || is_pressed(CELL_MOUSE_BUTTON_6))
digital_buttons |= CELL_GEM_CTRL_SELECT;
if ((is_pressed(CELL_MOUSE_BUTTON_3) && is_pressed(CELL_MOUSE_BUTTON_2)) || is_pressed(CELL_MOUSE_BUTTON_7))
digital_buttons |= CELL_GEM_CTRL_START;
if ((is_pressed(CELL_MOUSE_BUTTON_3) && is_pressed(CELL_MOUSE_BUTTON_4)) || is_pressed(CELL_MOUSE_BUTTON_8))
digital_buttons |= CELL_GEM_CTRL_TRIANGLE;
if (is_pressed(CELL_MOUSE_BUTTON_3) && is_pressed(CELL_MOUSE_BUTTON_5))
digital_buttons |= CELL_GEM_CTRL_SQUARE;
if (is_pressed(CELL_MOUSE_BUTTON_1))
digital_buttons |= CELL_GEM_CTRL_T;
if (is_pressed(CELL_MOUSE_BUTTON_2))
digital_buttons |= CELL_GEM_CTRL_MOVE;
if (is_pressed(CELL_MOUSE_BUTTON_4))
digital_buttons |= CELL_GEM_CTRL_CIRCLE;
if (is_pressed(CELL_MOUSE_BUTTON_5))
digital_buttons |= CELL_GEM_CTRL_CROSS;
analog_t = (mouse_data.buttons & CELL_MOUSE_BUTTON_1) ? 0xFFFF : 0;
return true;
}
template <typename T>
static void mouse_pos_to_gem_state(const u32 mouse_no, const gem_config::gem_controller& controller, T& gem_state)
{
if (!gem_state || !is_input_allowed())
{
return;
}
auto& handler = g_fxo->get<MouseHandlerBase>();
std::scoped_lock lock(handler.mutex);
// Make sure that the mouse handler is initialized
handler.Init(std::min<u32>(g_fxo->get<gem_config>().attribute.max_connect, CELL_GEM_MAX_NUM));
if (mouse_no >= handler.GetMice().size())
{
return;
}
const auto& mouse = ::at32(handler.GetMice(), mouse_no);
if constexpr (std::is_same_v<T, vm::ptr<CellGemState>>)
{
pos_to_gem_state(mouse_no, controller, gem_state, mouse.x_pos, mouse.y_pos, mouse.x_max, mouse.y_max);
}
else if constexpr (std::is_same_v<T, vm::ptr<CellGemImageState>>)
{
pos_to_gem_image_state(mouse_no, controller, gem_state, mouse.x_pos, mouse.y_pos, mouse.x_max, mouse.y_max);
}
}
#ifdef HAVE_LIBEVDEV
static bool gun_input_to_pad(const u32 gem_no, be_t<u16>& digital_buttons, be_t<u16>& analog_t)
{
digital_buttons = 0;
analog_t = 0;
if (!is_input_allowed())
return false;
gun_thread& gun = g_fxo->get<gun_thread>();
std::scoped_lock lock(gun.handler.mutex);
if (gun.handler.get_button(gem_no, gun_button::btn_left) == 1)
digital_buttons |= CELL_GEM_CTRL_T;
if (gun.handler.get_button(gem_no, gun_button::btn_right) == 1)
digital_buttons |= CELL_GEM_CTRL_MOVE;
if (gun.handler.get_button(gem_no, gun_button::btn_middle) == 1)
digital_buttons |= CELL_GEM_CTRL_START;
if (gun.handler.get_button(gem_no, gun_button::btn_1) == 1)
digital_buttons |= CELL_GEM_CTRL_CROSS;
if (gun.handler.get_button(gem_no, gun_button::btn_2) == 1)
digital_buttons |= CELL_GEM_CTRL_CIRCLE;
if (gun.handler.get_button(gem_no, gun_button::btn_3) == 1)
digital_buttons |= CELL_GEM_CTRL_SELECT;
if (gun.handler.get_button(gem_no, gun_button::btn_5) == 1)
digital_buttons |= CELL_GEM_CTRL_TRIANGLE;
if (gun.handler.get_button(gem_no, gun_button::btn_6) == 1)
digital_buttons |= CELL_GEM_CTRL_SQUARE;
analog_t = gun.handler.get_button(gem_no, gun_button::btn_left) ? 0xFFFF : 0;
return true;
}
template <typename T>
static void gun_pos_to_gem_state(const u32 gem_no, const gem_config::gem_controller& controller, T& gem_state)
{
if (!gem_state || !is_input_allowed())
return;
int x_pos, y_pos, x_max, y_max;
{
gun_thread& gun = g_fxo->get<gun_thread>();
std::scoped_lock lock(gun.handler.mutex);
x_pos = gun.handler.get_axis_x(gem_no);
y_pos = gun.handler.get_axis_y(gem_no);
x_max = gun.handler.get_axis_x_max(gem_no);
y_max = gun.handler.get_axis_y_max(gem_no);
}
if constexpr (std::is_same_v<T, vm::ptr<CellGemState>>)
{
pos_to_gem_state(gem_no, controller, gem_state, x_pos, y_pos, x_max, y_max);
}
else if constexpr (std::is_same_v<T, vm::ptr<CellGemImageState>>)
{
pos_to_gem_image_state(gem_no, controller, gem_state, x_pos, y_pos, x_max, y_max);
}
}
#endif
// *********************
// * cellGem functions *
// *********************
error_code cellGemCalibrate(u32 gem_num)
{
cellGem.todo("cellGemCalibrate(gem_num=%d)", gem_num);
auto& gem = g_fxo->get<gem_config>();
std::scoped_lock lock(gem.mtx);
if (!gem.state)
{
return CELL_GEM_ERROR_UNINITIALIZED;
}
if (!check_gem_num(gem_num))
{
return CELL_GEM_ERROR_INVALID_PARAMETER;
}
if (gem.is_controller_calibrating(gem_num))
{
return CELL_EBUSY;
}
gem.controllers[gem_num].is_calibrating = true;
gem.controllers[gem_num].calibration_start_us = get_guest_system_time();
return CELL_OK;
}
error_code cellGemClearStatusFlags(u32 gem_num, u64 mask)
{
cellGem.todo("cellGemClearStatusFlags(gem_num=%d, mask=0x%x)", gem_num, mask);
auto& gem = g_fxo->get<gem_config>();
std::scoped_lock lock(gem.mtx);
if (!gem.state)
{
return CELL_GEM_ERROR_UNINITIALIZED;
}
if (!check_gem_num(gem_num))
{
return CELL_GEM_ERROR_INVALID_PARAMETER;
}
gem.status_flags &= ~mask;
return CELL_OK;
}
error_code cellGemConvertVideoFinish()
{
cellGem.warning("cellGemConvertVideoFinish()");
auto& gem = g_fxo->get<gem_config>();
if (!gem.state)
{
return CELL_GEM_ERROR_UNINITIALIZED;
}
if (!gem.video_conversion_in_progress)
{
return CELL_GEM_ERROR_CONVERT_NOT_STARTED;
}
while (gem.video_conversion_in_progress && !Emu.IsStopped())
{
thread_ctrl::wait_for(100);
}
return CELL_OK;
}
error_code cellGemConvertVideoStart(vm::cptr<void> video_frame)
{
cellGem.warning("cellGemConvertVideoStart(video_frame=*0x%x)", video_frame);
auto& gem = g_fxo->get<gem_config>();
if (!gem.state)
{
return CELL_GEM_ERROR_UNINITIALIZED;
}
if (!video_frame)
{
return CELL_GEM_ERROR_INVALID_PARAMETER;
}
if (!video_frame.aligned(128))
{
return CELL_GEM_ERROR_INVALID_ALIGNMENT;
}
if (gem.video_conversion_in_progress)
{
return CELL_GEM_ERROR_CONVERT_NOT_FINISHED;
}
const auto& shared_data = g_fxo->get<gem_camera_shared>();
gem.video_data_in.resize(shared_data.size);
std::memcpy(gem.video_data_in.data(), video_frame.get_ptr(), gem.video_data_in.size());
gem.video_conversion_in_progress = true;
return CELL_OK;
}
error_code cellGemEnableCameraPitchAngleCorrection(u32 enable_flag)
{
cellGem.todo("cellGemEnableCameraPitchAngleCorrection(enable_flag=%d)", enable_flag);
auto& gem = g_fxo->get<gem_config>();
std::scoped_lock lock(gem.mtx);
if (!gem.state)
{
return CELL_GEM_ERROR_UNINITIALIZED;
}
gem.enable_pitch_correction = !!enable_flag;
return CELL_OK;
}
error_code cellGemEnableMagnetometer(u32 gem_num, u32 enable)
{
cellGem.todo("cellGemEnableMagnetometer(gem_num=%d, enable=0x%x)", gem_num, enable);
auto& gem = g_fxo->get<gem_config>();
std::scoped_lock lock(gem.mtx);
if (!gem.state)
{
return CELL_GEM_ERROR_UNINITIALIZED;
}
if (!check_gem_num(gem_num))
{
return CELL_GEM_ERROR_INVALID_PARAMETER;
}
if (!gem.is_controller_ready(gem_num))
{
return CELL_GEM_NOT_CONNECTED;
}
// NOTE: RE doesn't show this check but it is mentioned in the docs, so I'll leave it here for now.
//if (!gem.controllers[gem_num].calibrated_magnetometer)
//{
// return CELL_GEM_NOT_CALIBRATED;
//}
gem.controllers[gem_num].enabled_magnetometer = !!enable;
return CELL_OK;
}
error_code cellGemEnableMagnetometer2(u32 gem_num, u32 enable)
{
cellGem.trace("cellGemEnableMagnetometer2(gem_num=%d, enable=0x%x)", gem_num, enable);
auto& gem = g_fxo->get<gem_config>();
std::scoped_lock lock(gem.mtx);
if (!gem.state)
{
return CELL_GEM_ERROR_UNINITIALIZED;
}
if (!check_gem_num(gem_num))
{
return CELL_GEM_ERROR_INVALID_PARAMETER;
}
if (!gem.is_controller_ready(gem_num))
{
return CELL_GEM_NOT_CONNECTED;
}
if (!gem.controllers[gem_num].calibrated_magnetometer)
{
return CELL_GEM_NOT_CALIBRATED;
}
gem.controllers[gem_num].enabled_magnetometer = !!enable;
return CELL_OK;
}
error_code cellGemEnd(ppu_thread& ppu)
{
cellGem.warning("cellGemEnd()");
auto& gem = g_fxo->get<gem_config>();
std::scoped_lock lock(gem.mtx);
if (gem.state.compare_and_swap_test(1, 0))
{
if (u32 addr = std::exchange(gem.memory_ptr, 0))
{
sys_memory_free(ppu, addr);
}
return CELL_OK;
}
return CELL_GEM_ERROR_UNINITIALIZED;
}
error_code cellGemFilterState(u32 gem_num, u32 enable)
{
cellGem.warning("cellGemFilterState(gem_num=%d, enable=%d)", gem_num, enable);
auto& gem = g_fxo->get<gem_config>();
std::scoped_lock lock(gem.mtx);
if (!gem.state)
{
return CELL_GEM_ERROR_UNINITIALIZED;
}
if (!check_gem_num(gem_num))
{
return CELL_GEM_ERROR_INVALID_PARAMETER;
}
gem.controllers[gem_num].enabled_filtering = !!enable;
return CELL_OK;
}
error_code cellGemForceRGB(u32 gem_num, float r, float g, float b)
{
cellGem.todo("cellGemForceRGB(gem_num=%d, r=%f, g=%f, b=%f)", gem_num, r, g, b);
auto& gem = g_fxo->get<gem_config>();
std::scoped_lock lock(gem.mtx);
if (!gem.state)
{
return CELL_GEM_ERROR_UNINITIALIZED;
}
if (!check_gem_num(gem_num))
{
return CELL_GEM_ERROR_INVALID_PARAMETER;
}
// TODO: Adjust brightness
//if (const f32 sum = r + g + b; sum > 2.f)
//{
// color = color * (2.f / sum)
//}
gem.controllers[gem_num].sphere_rgb = gem_config::gem_color(r, g, b);
gem.controllers[gem_num].enabled_tracking = false;
return CELL_OK;
}
error_code cellGemGetAccelerometerPositionInDevice(u32 gem_num, vm::ptr<f32> pos)
{
cellGem.todo("cellGemGetAccelerometerPositionInDevice(gem_num=%d, pos=*0x%x)", gem_num, pos);
auto& gem = g_fxo->get<gem_config>();
if (!gem.state)
{
return CELL_GEM_ERROR_UNINITIALIZED;
}
if (!check_gem_num(gem_num) || !pos)
{
return CELL_GEM_ERROR_INVALID_PARAMETER;
}
// TODO
pos[0] = 0.0f;
pos[1] = 0.0f;
pos[2] = 0.0f;
pos[3] = 0.0f;
return CELL_OK;
}
error_code cellGemGetAllTrackableHues(vm::ptr<u8> hues)
{
cellGem.todo("cellGemGetAllTrackableHues(hues=*0x%x)");
auto& gem = g_fxo->get<gem_config>();
if (!gem.state)
{
return CELL_GEM_ERROR_UNINITIALIZED;
}
if (!hues)
{
return CELL_GEM_ERROR_INVALID_PARAMETER;
}
for (u32 i = 0; i < 360; i++)
{
hues[i] = true;
}
return CELL_OK;
}
error_code cellGemGetCameraState(vm::ptr<CellGemCameraState> camera_state)
{
cellGem.todo("cellGemGetCameraState(camera_state=0x%x)", camera_state);
[[maybe_unused]] auto& gem = g_fxo->get<gem_config>();
if (!camera_state)
{
return CELL_GEM_ERROR_INVALID_PARAMETER;
}
// TODO: use correct camera settings
camera_state->exposure = 0;
camera_state->exposure_time = 1.0f / 60.0f;
camera_state->gain = 1.0;
camera_state->pitch_angle = 0.0;
camera_state->pitch_angle_estimate = 0.0;
return CELL_OK;
}
error_code cellGemGetEnvironmentLightingColor(vm::ptr<f32> r, vm::ptr<f32> g, vm::ptr<f32> b)
{
cellGem.todo("cellGemGetEnvironmentLightingColor(r=*0x%x, g=*0x%x, b=*0x%x)", r, g, b);
auto& gem = g_fxo->get<gem_config>();
if (!gem.state)
{
return CELL_GEM_ERROR_UNINITIALIZED;
}
if (!r || !g || !b)
{
return CELL_GEM_ERROR_INVALID_PARAMETER;
}
// default to 128
*r = 128;
*g = 128;
*b = 128;
// NOTE: RE doesn't show this check but it is mentioned in the docs, so I'll leave it here for now.
//if (!gem.controllers[gem_num].calibrated_magnetometer)
//{
// return CELL_GEM_ERROR_LIGHTING_NOT_CALIBRATED; // This error doesn't really seem to be a real thing.
//}
return CELL_OK;
}
error_code cellGemGetHuePixels(vm::cptr<void> camera_frame, u32 hue, vm::ptr<u8> pixels)
{
cellGem.todo("cellGemGetHuePixels(camera_frame=*0x%x, hue=%d, pixels=*0x%x)", camera_frame, hue, pixels);
auto& gem = g_fxo->get<gem_config>();
if (!gem.state)
{
return CELL_GEM_ERROR_UNINITIALIZED;
}
if (!camera_frame || !pixels || hue > 359)
{
return CELL_GEM_ERROR_INVALID_PARAMETER;
}
std::memset(pixels.get_ptr(), 0, 640 * 480 * sizeof(u8));
// TODO
return CELL_OK;
}
error_code cellGemGetImageState(u32 gem_num, vm::ptr<CellGemImageState> gem_image_state)
{
cellGem.warning("cellGemGetImageState(gem_num=%d, image_state=&0x%x)", gem_num, gem_image_state);
auto& gem = g_fxo->get<gem_config>();
if (!gem.state)
{
return CELL_GEM_ERROR_UNINITIALIZED;
}
if (!check_gem_num(gem_num) || !gem_image_state)
{
return CELL_GEM_ERROR_INVALID_PARAMETER;
}
*gem_image_state = {};
if (g_cfg.io.move != move_handler::null)
{
auto& shared_data = g_fxo->get<gem_camera_shared>();
const auto& controller = gem.controllers[gem_num];
gem_image_state->frame_timestamp = shared_data.frame_timestamp_us.load();
gem_image_state->timestamp = gem_image_state->frame_timestamp + 10;
gem_image_state->r = controller.radius; // Radius in camera pixels
gem_image_state->distance = controller.distance; // 1.5 meters away from camera
gem_image_state->visible = gem.is_controller_ready(gem_num);
gem_image_state->r_valid = true;
switch (g_cfg.io.move)
{
case move_handler::fake:
ds3_pos_to_gem_state(gem_num, controller, gem_image_state);
break;
case move_handler::mouse:
case move_handler::raw_mouse:
mouse_pos_to_gem_state(gem_num, controller, gem_image_state);
break;
#ifdef HAVE_LIBEVDEV
case move_handler::gun:
gun_pos_to_gem_state(gem_num, controller, gem_image_state);
break;
#endif
case move_handler::null:
fmt::throw_exception("Unreachable");
}
}
return CELL_OK;
}
error_code cellGemGetInertialState(u32 gem_num, u32 state_flag, u64 timestamp, vm::ptr<CellGemInertialState> inertial_state)
{
cellGem.warning("cellGemGetInertialState(gem_num=%d, state_flag=%d, timestamp=0x%x, inertial_state=0x%x)", gem_num, state_flag, timestamp, inertial_state);
auto& gem = g_fxo->get<gem_config>();
std::scoped_lock lock(gem.mtx);
if (!gem.state)
{
return CELL_GEM_ERROR_UNINITIALIZED;
}
if (!check_gem_num(gem_num) || !inertial_state || !gem.is_controller_ready(gem_num))
{
return CELL_GEM_ERROR_INVALID_PARAMETER;
}
if (false) // TODO
{
return CELL_GEM_TIME_OUT_OF_RANGE;
}
*inertial_state = {};
if (g_cfg.io.move != move_handler::null)
{
ds3_input_to_ext(gem_num, gem.controllers[gem_num], inertial_state->ext);
inertial_state->timestamp = (get_guest_system_time() - gem.start_timestamp_us);
inertial_state->counter = gem.inertial_counter++;
inertial_state->accelerometer[0] = 10; // Current gravity in m/s²
switch (g_cfg.io.move)
{
case move_handler::fake:
ds3_input_to_pad(gem_num, inertial_state->pad.digitalbuttons, inertial_state->pad.analog_T);
break;
case move_handler::mouse:
case move_handler::raw_mouse:
mouse_input_to_pad(gem_num, inertial_state->pad.digitalbuttons, inertial_state->pad.analog_T);
break;
#ifdef HAVE_LIBEVDEV
case move_handler::gun:
gun_input_to_pad(gem_num, inertial_state->pad.digitalbuttons, inertial_state->pad.analog_T);
break;
#endif
case move_handler::null:
fmt::throw_exception("Unreachable");
}
}
return CELL_OK;
}
error_code cellGemGetInfo(vm::ptr<CellGemInfo> info)
{
cellGem.trace("cellGemGetInfo(info=*0x%x)", info);
auto& gem = g_fxo->get<gem_config>();
reader_lock lock(gem.mtx);
if (!gem.state)
{
return CELL_GEM_ERROR_UNINITIALIZED;
}
if (!info)
{
return CELL_GEM_ERROR_INVALID_PARAMETER;
}
// TODO: Support connecting PlayStation Move controllers
switch (g_cfg.io.move)
{
case move_handler::fake:
{
gem.connected_controllers = 0;
std::lock_guard lock(pad::g_pad_mutex);
const auto handler = pad::get_current_handler();
for (u32 i = 0; i < CELL_GEM_MAX_NUM; i++)
{
const auto& pad = ::at32(handler->GetPads(), pad_num(i));
const bool connected = (pad && (pad->m_port_status & CELL_PAD_STATUS_CONNECTED) && i < gem.attribute.max_connect);
if (connected)
{
gem.connected_controllers++;
gem.controllers[i].status = CELL_GEM_STATUS_READY;
gem.controllers[i].port = port_num(i);
}
else
{
gem.controllers[i].status = CELL_GEM_STATUS_DISCONNECTED;
gem.controllers[i].port = 0;
}
}
break;
}
case move_handler::raw_mouse:
{
gem.connected_controllers = 0;
auto& handler = g_fxo->get<MouseHandlerBase>();
std::lock_guard mouse_lock(handler.mutex);
const MouseInfo& info = handler.GetInfo();
for (u32 i = 0; i < CELL_GEM_MAX_NUM; i++)
{
const bool connected = i < gem.attribute.max_connect && info.status[i] == CELL_MOUSE_STATUS_CONNECTED;
if (connected)
{
gem.connected_controllers++;
gem.controllers[i].status = CELL_GEM_STATUS_READY;
gem.controllers[i].port = port_num(i);
}
else
{
gem.controllers[i].status = CELL_GEM_STATUS_DISCONNECTED;
gem.controllers[i].port = 0;
}
}
break;
}
default:
{
break;
}
}
info->max_connect = gem.attribute.max_connect;
info->now_connect = gem.connected_controllers;
for (int i = 0; i < CELL_GEM_MAX_NUM; i++)
{
info->status[i] = gem.controllers[i].status;
info->port[i] = gem.controllers[i].port;
}
return CELL_OK;
}
u32 GemGetMemorySize(s32 max_connect)
{
return max_connect <= 2 ? 0x120000 : 0x140000;
}
error_code cellGemGetMemorySize(s32 max_connect)
{
cellGem.warning("cellGemGetMemorySize(max_connect=%d)", max_connect);
if (max_connect > CELL_GEM_MAX_NUM || max_connect <= 0)
{
return CELL_GEM_ERROR_INVALID_PARAMETER;
}
return not_an_error(GemGetMemorySize(max_connect));
}
error_code cellGemGetRGB(u32 gem_num, vm::ptr<float> r, vm::ptr<float> g, vm::ptr<float> b)
{
cellGem.todo("cellGemGetRGB(gem_num=%d, r=*0x%x, g=*0x%x, b=*0x%x)", gem_num, r, g, b);
auto& gem = g_fxo->get<gem_config>();
reader_lock lock(gem.mtx);
if (!gem.state)
{
return CELL_GEM_ERROR_UNINITIALIZED;
}
if (!check_gem_num(gem_num) || !r || !g || !b)
{
return CELL_GEM_ERROR_INVALID_PARAMETER;
}
const gem_config_data::gem_color& sphere_color = gem.controllers[gem_num].sphere_rgb;
*r = sphere_color.r;
*g = sphere_color.g;
*b = sphere_color.b;
return CELL_OK;
}
error_code cellGemGetRumble(u32 gem_num, vm::ptr<u8> rumble)
{
cellGem.todo("cellGemGetRumble(gem_num=%d, rumble=*0x%x)", gem_num, rumble);
auto& gem = g_fxo->get<gem_config>();
reader_lock lock(gem.mtx);
if (!gem.state)
{
return CELL_GEM_ERROR_UNINITIALIZED;
}
if (!check_gem_num(gem_num) || !rumble)
{
return CELL_GEM_ERROR_INVALID_PARAMETER;
}
*rumble = gem.controllers[gem_num].rumble;
return CELL_OK;
}
error_code cellGemGetState(u32 gem_num, u32 flag, u64 time_parameter, vm::ptr<CellGemState> gem_state)
{
cellGem.warning("cellGemGetState(gem_num=%d, flag=0x%x, time=0x%llx, gem_state=*0x%x)", gem_num, flag, time_parameter, gem_state);
auto& gem = g_fxo->get<gem_config>();
reader_lock lock(gem.mtx);
if (!gem.state)
{
return CELL_GEM_ERROR_UNINITIALIZED;
}
if (!check_gem_num(gem_num) || flag > CELL_GEM_STATE_FLAG_TIMESTAMP || !gem_state)
{
return CELL_GEM_ERROR_INVALID_PARAMETER;
}
if (!gem.is_controller_ready(gem_num))
{
return not_an_error(CELL_GEM_NOT_CONNECTED);
}
// TODO: Get the gem state at the specified time
//if (flag == CELL_GEM_STATE_FLAG_CURRENT_TIME)
//{
// // now + time_parameter (time_parameter in microseconds). Positive values actually allow predictions for the future state.
//}
//else if (flag == CELL_GEM_STATE_FLAG_LATEST_IMAGE_TIME)
//{
// // When the sphere was registered during the last camera frame (time_parameter may also have an impact)
//}
//else // CELL_GEM_STATE_FLAG_TIMESTAMP
//{
// // As specified by time_parameter.
//}
if (false) // TODO: check if there is data for the specified time_parameter and flag
{
return CELL_GEM_TIME_OUT_OF_RANGE;
}
const auto& controller = gem.controllers[gem_num];
*gem_state = {};
if (g_cfg.io.move != move_handler::null)
{
ds3_input_to_ext(gem_num, controller, gem_state->ext);
u32 tracking_flags = CELL_GEM_TRACKING_FLAG_VISIBLE;
if (controller.enabled_tracking)
tracking_flags |= CELL_GEM_TRACKING_FLAG_POSITION_TRACKED;
gem_state->tracking_flags = tracking_flags;
gem_state->timestamp = (get_guest_system_time() - gem.start_timestamp_us);
gem_state->camera_pitch_angle = 0.f;
gem_state->quat[3] = 1.f;
switch (g_cfg.io.move)
{
case move_handler::fake:
ds3_input_to_pad(gem_num, gem_state->pad.digitalbuttons, gem_state->pad.analog_T);
ds3_pos_to_gem_state(gem_num, controller, gem_state);
break;
case move_handler::mouse:
case move_handler::raw_mouse:
mouse_input_to_pad(gem_num, gem_state->pad.digitalbuttons, gem_state->pad.analog_T);
mouse_pos_to_gem_state(gem_num, controller, gem_state);
break;
#ifdef HAVE_LIBEVDEV
case move_handler::gun:
gun_input_to_pad(gem_num, gem_state->pad.digitalbuttons, gem_state->pad.analog_T);
gun_pos_to_gem_state(gem_num, controller, gem_state);
break;
#endif
case move_handler::null:
fmt::throw_exception("Unreachable");
}
}
if (false) // TODO: check if we are computing colors
{
return CELL_GEM_COMPUTING_AVAILABLE_COLORS;
}
if (gem.is_controller_calibrating(gem_num))
{
return CELL_GEM_SPHERE_CALIBRATING;
}
if (!controller.calibrated_magnetometer)
{
return CELL_GEM_SPHERE_NOT_CALIBRATED;
}
if (!controller.hue_set)
{
return CELL_GEM_HUE_NOT_SET;
}
return CELL_OK;
}
error_code cellGemGetStatusFlags(u32 gem_num, vm::ptr<u64> flags)
{
cellGem.trace("cellGemGetStatusFlags(gem_num=%d, flags=*0x%x)", gem_num, flags);
auto& gem = g_fxo->get<gem_config>();
reader_lock lock(gem.mtx);
if (!gem.state)
{
return CELL_GEM_ERROR_UNINITIALIZED;
}
if (!check_gem_num(gem_num) || !flags)
{
return CELL_GEM_ERROR_INVALID_PARAMETER;
}
*flags = gem.status_flags;
return CELL_OK;
}
error_code cellGemGetTrackerHue(u32 gem_num, vm::ptr<u32> hue)
{
cellGem.warning("cellGemGetTrackerHue(gem_num=%d, hue=*0x%x)", gem_num, hue);
auto& gem = g_fxo->get<gem_config>();
reader_lock lock(gem.mtx);
if (!gem.state)
{
return CELL_GEM_ERROR_UNINITIALIZED;
}
if (!check_gem_num(gem_num) || !hue)
{
return CELL_GEM_ERROR_INVALID_PARAMETER;
}
const auto& controller = gem.controllers[gem_num];
if (!controller.enabled_tracking || controller.hue > 359)
{
return { CELL_GEM_ERROR_NOT_A_HUE, controller.hue };
}
*hue = controller.hue;
return CELL_OK;
}
error_code cellGemHSVtoRGB(f32 h, f32 s, f32 v, vm::ptr<f32> r, vm::ptr<f32> g, vm::ptr<f32> b)
{
cellGem.warning("cellGemHSVtoRGB(h=%f, s=%f, v=%f, r=*0x%x, g=*0x%x, b=*0x%x)", h, s, v, r, g, b);
if (s < 0.0f || s > 1.0f || v < 0.0f || v > 1.0f || !r || !g || !b)
{
return CELL_GEM_ERROR_INVALID_PARAMETER;
}
h = std::clamp(h, 0.0f, 360.0f);
const f32 c = v * s;
const f32 x = c * (1.0f - fabs(fmod(h / 60.0f, 2.0f) - 1.0f));
const f32 m = v - c;
f32 r_tmp{};
f32 g_tmp{};
f32 b_tmp{};
if (h < 60.0f)
{
r_tmp = c;
g_tmp = x;
}
else if (h < 120.0f)
{
r_tmp = x;
g_tmp = c;
}
else if (h < 180.0f)
{
g_tmp = c;
b_tmp = x;
}
else if (h < 240.0f)
{
g_tmp = x;
b_tmp = c;
}
else if (h < 300.0f)
{
r_tmp = x;
b_tmp = c;
}
else
{
r_tmp = c;
b_tmp = x;
}
*r = (r_tmp + m) * 255.0f;
*g = (g_tmp + m) * 255.0f;
*b = (b_tmp + m) * 255.0f;
return CELL_OK;
}
error_code cellGemInit(ppu_thread& ppu, vm::cptr<CellGemAttribute> attribute)
{
cellGem.warning("cellGemInit(attribute=*0x%x)", attribute);
auto& gem = g_fxo->get<gem_config>();
if (!attribute || !attribute->spurs_addr || !attribute->max_connect || attribute->max_connect > CELL_GEM_MAX_NUM)
{
return CELL_GEM_ERROR_INVALID_PARAMETER;
}
std::scoped_lock lock(gem.mtx);
if (!gem.state.compare_and_swap_test(0, 1))
{
return CELL_GEM_ERROR_ALREADY_INITIALIZED;
}
if (!attribute->memory_ptr)
{
vm::var<u32> addr(0);
// Decrease memory stats
if (sys_memory_allocate(ppu, GemGetMemorySize(attribute->max_connect), SYS_MEMORY_PAGE_SIZE_64K, +addr) != CELL_OK)
{
return CELL_GEM_ERROR_RESOURCE_ALLOCATION_FAILED;
}
gem.memory_ptr = *addr;
}
else
{
gem.memory_ptr = 0;
}
gem.update_started = false;
gem.camera_frame = 0;
gem.status_flags = 0;
gem.attribute = *attribute;
for (int gem_num = 0; gem_num < CELL_GEM_MAX_NUM; gem_num++)
{
gem.reset_controller(gem_num);
}
// TODO: is this correct?
gem.start_timestamp_us = get_guest_system_time();
return CELL_OK;
}
error_code cellGemInvalidateCalibration(s32 gem_num)
{
cellGem.todo("cellGemInvalidateCalibration(gem_num=%d)", gem_num);
auto& gem = g_fxo->get<gem_config>();
std::scoped_lock lock(gem.mtx);
if (!gem.state)
{
return CELL_GEM_ERROR_UNINITIALIZED;
}
if (!check_gem_num(gem_num))
{
return CELL_GEM_ERROR_INVALID_PARAMETER;
}
gem.controllers[gem_num].calibrated_magnetometer = false;
// TODO: does this really stop an ongoing calibration ?
gem.controllers[gem_num].is_calibrating = false;
gem.controllers[gem_num].calibration_start_us = 0;
// TODO: gem.status_flags (probably not changed)
return CELL_OK;
}
s32 cellGemIsTrackableHue(u32 hue)
{
cellGem.todo("cellGemIsTrackableHue(hue=%d)", hue);
auto& gem = g_fxo->get<gem_config>();
if (!gem.state)
{
return CELL_GEM_ERROR_UNINITIALIZED;
}
if (hue > 359)
{
return CELL_GEM_ERROR_INVALID_PARAMETER;
}
return 1; // potentially true if less than 20 pixels have the hue
}
error_code cellGemPrepareCamera(s32 max_exposure, f32 image_quality)
{
cellGem.todo("cellGemPrepareCamera(max_exposure=%d, image_quality=%f)", max_exposure, image_quality);
auto& gem = g_fxo->get<gem_config>();
if (!gem.state)
{
return CELL_GEM_ERROR_UNINITIALIZED;
}
if (false) // TODO: Check if the camera is currently being prepared.
{
return CELL_EBUSY;
}
max_exposure = std::clamp(max_exposure, static_cast<s32>(CELL_GEM_MIN_CAMERA_EXPOSURE), static_cast<s32>(CELL_GEM_MAX_CAMERA_EXPOSURE));
image_quality = std::clamp(image_quality, 0.0f, 1.0f);
// TODO: prepare camera
return CELL_OK;
}
error_code cellGemPrepareVideoConvert(vm::cptr<CellGemVideoConvertAttribute> vc_attribute)
{
cellGem.warning("cellGemPrepareVideoConvert(vc_attribute=*0x%x)", vc_attribute);
auto& gem = g_fxo->get<gem_config>();
if (!gem.state)
{
return CELL_GEM_ERROR_UNINITIALIZED;
}
if (!vc_attribute)
{
return CELL_GEM_ERROR_INVALID_PARAMETER;
}
const CellGemVideoConvertAttribute vc = *vc_attribute;
if (vc.version != CELL_GEM_VERSION)
{
return CELL_GEM_ERROR_INVALID_PARAMETER;
}
if (vc.output_format != CELL_GEM_NO_VIDEO_OUTPUT)
{
if (!vc.video_data_out)
{
return CELL_GEM_ERROR_INVALID_PARAMETER;
}
}
if ((vc.conversion_flags & CELL_GEM_COMBINE_PREVIOUS_INPUT_FRAME) && !vc.buffer_memory)
{
return CELL_GEM_ERROR_INVALID_PARAMETER;
}
if (!vc.video_data_out.aligned(128) || !vc.buffer_memory.aligned(16))
{
return CELL_GEM_ERROR_INVALID_ALIGNMENT;
}
gem.vc_attribute = vc;
const s32 buffer_size = cellGemGetVideoConvertSize(vc.output_format);
gem.video_data_out_size = buffer_size;
return CELL_OK;
}
error_code cellGemReadExternalPortDeviceInfo(u32 gem_num, vm::ptr<u32> ext_id, vm::ptr<u8[CELL_GEM_EXTERNAL_PORT_DEVICE_INFO_SIZE]> ext_info)
{
cellGem.todo("cellGemReadExternalPortDeviceInfo(gem_num=%d, ext_id=*0x%x, ext_info=%s)", gem_num, ext_id, ext_info);
auto& gem = g_fxo->get<gem_config>();
if (!gem.state)
{
return CELL_GEM_ERROR_UNINITIALIZED;
}
if (!check_gem_num(gem_num) || !ext_id)
{
return CELL_GEM_ERROR_INVALID_PARAMETER;
}
if (!gem.is_controller_ready(gem_num))
{
return CELL_GEM_NOT_CONNECTED;
}
if (!(gem.controllers[gem_num].ext_status & CELL_GEM_EXT_CONNECTED))
{
return CELL_GEM_NO_EXTERNAL_PORT_DEVICE;
}
*ext_id = gem.controllers[gem_num].ext_id;
return CELL_OK;
}
error_code cellGemReset(u32 gem_num)
{
cellGem.todo("cellGemReset(gem_num=%d)", gem_num);
auto& gem = g_fxo->get<gem_config>();
if (!gem.state)
{
return CELL_GEM_ERROR_UNINITIALIZED;
}
if (!check_gem_num(gem_num))
{
return CELL_GEM_ERROR_INVALID_PARAMETER;
}
gem.reset_controller(gem_num);
// TODO: is this correct?
gem.start_timestamp_us = get_guest_system_time();
return CELL_OK;
}
error_code cellGemSetRumble(u32 gem_num, u8 rumble)
{
cellGem.trace("cellGemSetRumble(gem_num=%d, rumble=0x%x)", gem_num, rumble);
auto& gem = g_fxo->get<gem_config>();
std::scoped_lock lock(gem.mtx);
if (!gem.state)
{
return CELL_GEM_ERROR_UNINITIALIZED;
}
if (!check_gem_num(gem_num))
{
return CELL_GEM_ERROR_INVALID_PARAMETER;
}
gem.controllers[gem_num].rumble = rumble;
return CELL_OK;
}
error_code cellGemSetYaw(u32 gem_num, vm::ptr<f32> z_direction)
{
cellGem.todo("cellGemSetYaw(gem_num=%d, z_direction=*0x%x)", gem_num, z_direction);
auto& gem = g_fxo->get<gem_config>();
std::scoped_lock lock(gem.mtx);
if (!gem.state)
{
return CELL_GEM_ERROR_UNINITIALIZED;
}
if (!z_direction || !check_gem_num(gem_num))
{
return CELL_GEM_ERROR_INVALID_PARAMETER;
}
// TODO
return CELL_OK;
}
error_code cellGemTrackHues(vm::cptr<u32> req_hues, vm::ptr<u32> res_hues)
{
cellGem.todo("cellGemTrackHues(req_hues=*0x%x, res_hues=*0x%x)", req_hues, res_hues);
auto& gem = g_fxo->get<gem_config>();
std::scoped_lock lock(gem.mtx);
if (!gem.state)
{
return CELL_GEM_ERROR_UNINITIALIZED;
}
if (!req_hues)
{
return CELL_GEM_ERROR_INVALID_PARAMETER;
}
for (u32 i = 0; i < CELL_GEM_MAX_NUM; i++)
{
if (req_hues[i] == CELL_GEM_DONT_CARE_HUE)
{
gem.controllers[i].enabled_tracking = true;
gem.controllers[i].enabled_LED = true;
switch (i)
{
default:
case 0:
gem.controllers[i].hue = 240; // blue
break;
case 1:
gem.controllers[i].hue = 0; // red
break;
case 2:
gem.controllers[i].hue = 120; // green
break;
case 3:
gem.controllers[i].hue = 300; // purple
break;
}
if (res_hues)
{
res_hues[i] = gem.controllers[i].hue;
}
}
else if (req_hues[i] == CELL_GEM_DONT_TRACK_HUE)
{
gem.controllers[i].enabled_tracking = false;
gem.controllers[i].enabled_LED = false;
if (res_hues)
{
res_hues[i] = CELL_GEM_DONT_TRACK_HUE;
}
}
else
{
if (req_hues[i] > 359)
{
cellGem.warning("cellGemTrackHues: req_hues[%d]=%d -> this can lead to unexpected behavior", i, req_hues[i]);
}
gem.controllers[i].enabled_tracking = true;
gem.controllers[i].enabled_LED = true;
gem.controllers[i].hue = req_hues[i];
if (res_hues)
{
res_hues[i] = gem.controllers[i].hue;
}
}
gem.controllers[i].hue_set = true;
}
return CELL_OK;
}
error_code cellGemUpdateFinish()
{
cellGem.warning("cellGemUpdateFinish()");
auto& gem = g_fxo->get<gem_config>();
if (!gem.state)
{
return CELL_GEM_ERROR_UNINITIALIZED;
}
std::scoped_lock lock(gem.mtx);
if (!gem.update_started.exchange(false))
{
return CELL_GEM_ERROR_UPDATE_NOT_STARTED;
}
if (!gem.camera_frame)
{
return not_an_error(CELL_GEM_NO_VIDEO);
}
return CELL_OK;
}
error_code cellGemUpdateStart(vm::cptr<void> camera_frame, u64 timestamp)
{
cellGem.warning("cellGemUpdateStart(camera_frame=*0x%x, timestamp=%d)", camera_frame, timestamp);
auto& gem = g_fxo->get<gem_config>();
if (!gem.state)
{
return CELL_GEM_ERROR_UNINITIALIZED;
}
std::scoped_lock lock(gem.mtx);
// Update is starting even when camera_frame is null
if (gem.update_started.exchange(true))
{
return CELL_GEM_ERROR_UPDATE_NOT_FINISHED;
}
if (!camera_frame.aligned(128))
{
return CELL_GEM_ERROR_INVALID_ALIGNMENT;
}
gem.camera_frame = camera_frame.addr();
if (!camera_frame)
{
return not_an_error(CELL_GEM_NO_VIDEO);
}
return CELL_OK;
}
error_code cellGemWriteExternalPort(u32 gem_num, vm::ptr<u8[CELL_GEM_EXTERNAL_PORT_OUTPUT_SIZE]> data)
{
cellGem.todo("cellGemWriteExternalPort(gem_num=%d, data=%s)", gem_num, data);
auto& gem = g_fxo->get<gem_config>();
if (!gem.state)
{
return CELL_GEM_ERROR_UNINITIALIZED;
}
if (!check_gem_num(gem_num))
{
return CELL_GEM_ERROR_INVALID_PARAMETER;
}
if (!gem.is_controller_ready(gem_num))
{
return CELL_GEM_NOT_CONNECTED;
}
if (false) // TODO: check if this is still writing to the external port
{
return CELL_GEM_ERROR_WRITE_NOT_FINISHED;
}
return CELL_OK;
}
DECLARE(ppu_module_manager::cellGem)("libgem", []()
{
REG_FUNC(libgem, cellGemCalibrate);
REG_FUNC(libgem, cellGemClearStatusFlags);
REG_FUNC(libgem, cellGemConvertVideoFinish);
REG_FUNC(libgem, cellGemConvertVideoStart);
REG_FUNC(libgem, cellGemEnableCameraPitchAngleCorrection);
REG_FUNC(libgem, cellGemEnableMagnetometer);
REG_FUNC(libgem, cellGemEnableMagnetometer2);
REG_FUNC(libgem, cellGemEnd);
REG_FUNC(libgem, cellGemFilterState);
REG_FUNC(libgem, cellGemForceRGB);
REG_FUNC(libgem, cellGemGetAccelerometerPositionInDevice);
REG_FUNC(libgem, cellGemGetAllTrackableHues);
REG_FUNC(libgem, cellGemGetCameraState);
REG_FUNC(libgem, cellGemGetEnvironmentLightingColor);
REG_FUNC(libgem, cellGemGetHuePixels);
REG_FUNC(libgem, cellGemGetImageState);
REG_FUNC(libgem, cellGemGetInertialState);
REG_FUNC(libgem, cellGemGetInfo);
REG_FUNC(libgem, cellGemGetMemorySize);
REG_FUNC(libgem, cellGemGetRGB);
REG_FUNC(libgem, cellGemGetRumble);
REG_FUNC(libgem, cellGemGetState);
REG_FUNC(libgem, cellGemGetStatusFlags);
REG_FUNC(libgem, cellGemGetTrackerHue);
REG_FUNC(libgem, cellGemHSVtoRGB);
REG_FUNC(libgem, cellGemInit);
REG_FUNC(libgem, cellGemInvalidateCalibration);
REG_FUNC(libgem, cellGemIsTrackableHue);
REG_FUNC(libgem, cellGemPrepareCamera);
REG_FUNC(libgem, cellGemPrepareVideoConvert);
REG_FUNC(libgem, cellGemReadExternalPortDeviceInfo);
REG_FUNC(libgem, cellGemReset);
REG_FUNC(libgem, cellGemSetRumble);
REG_FUNC(libgem, cellGemSetYaw);
REG_FUNC(libgem, cellGemTrackHues);
REG_FUNC(libgem, cellGemUpdateFinish);
REG_FUNC(libgem, cellGemUpdateStart);
REG_FUNC(libgem, cellGemWriteExternalPort);
});
| 61,004
|
C++
|
.cpp
| 1,919
| 28.998958
| 224
| 0.696837
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| false
| false
|
5,227
|
cellVoice.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellVoice.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
#include "Emu/Cell/lv2/sys_event.h"
#include "Emu/Cell/lv2/sys_process.h"
#include "cellVoice.h"
LOG_CHANNEL(cellVoice);
template<>
void fmt_class_string<CellVoiceError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_VOICE_ERROR_ADDRESS_INVALID);
STR_CASE(CELL_VOICE_ERROR_ARGUMENT_INVALID);
STR_CASE(CELL_VOICE_ERROR_CONTAINER_INVALID);
STR_CASE(CELL_VOICE_ERROR_DEVICE_NOT_PRESENT);
STR_CASE(CELL_VOICE_ERROR_EVENT_DISPATCH);
STR_CASE(CELL_VOICE_ERROR_EVENT_QUEUE);
STR_CASE(CELL_VOICE_ERROR_GENERAL);
STR_CASE(CELL_VOICE_ERROR_LIBVOICE_INITIALIZED);
STR_CASE(CELL_VOICE_ERROR_LIBVOICE_NOT_INIT);
STR_CASE(CELL_VOICE_ERROR_NOT_IMPLEMENTED);
STR_CASE(CELL_VOICE_ERROR_PORT_INVALID);
STR_CASE(CELL_VOICE_ERROR_RESOURCE_INSUFFICIENT);
STR_CASE(CELL_VOICE_ERROR_SERVICE_ATTACHED);
STR_CASE(CELL_VOICE_ERROR_SERVICE_DETACHED);
STR_CASE(CELL_VOICE_ERROR_SERVICE_HANDLE);
STR_CASE(CELL_VOICE_ERROR_SERVICE_NOT_FOUND);
STR_CASE(CELL_VOICE_ERROR_SHAREDMEMORY);
STR_CASE(CELL_VOICE_ERROR_TOPOLOGY);
}
return unknown;
});
}
void voice_manager::reset()
{
id_ctr = 0;
port_source = 0;
ports.clear();
queue_keys.clear();
}
void voice_manager::save(utils::serial& ar)
{
GET_OR_USE_SERIALIZATION_VERSION(ar.is_writing(), cellVoice);
ar(id_ctr, port_source, ports, queue_keys, voice_service_started);
}
error_code cellVoiceConnectIPortToOPort(u32 ips, u32 ops)
{
cellVoice.todo("cellVoiceConnectIPortToOPort(ips=%d, ops=%d)", ips, ops);
auto& manager = g_fxo->get<voice_manager>();
reader_lock lock(manager.mtx);
if (!manager.is_init)
return CELL_VOICE_ERROR_LIBVOICE_NOT_INIT;
auto iport = manager.access_port(ips);
if (!iport || iport->info.portType >= CELLVOICE_PORTTYPE_OUT_PCMAUDIO)
return CELL_VOICE_ERROR_TOPOLOGY;
auto oport = manager.access_port(ops);
if (!oport || oport->info.portType <= CELLVOICE_PORTTYPE_IN_VOICE)
return CELL_VOICE_ERROR_TOPOLOGY;
return CELL_OK;
}
error_code cellVoiceCreateNotifyEventQueue(ppu_thread& ppu, vm::ptr<u32> id, vm::ptr<u64> key)
{
cellVoice.warning("cellVoiceCreateNotifyEventQueue(id=*0x%x, key=*0x%x)", id, key);
auto& manager = g_fxo->get<voice_manager>();
reader_lock lock(manager.mtx);
if (!manager.is_init)
return CELL_VOICE_ERROR_LIBVOICE_NOT_INIT;
vm::var<sys_event_queue_attribute_t> attr;
attr->protocol = SYS_SYNC_FIFO;
attr->type = SYS_PPU_QUEUE;
attr->name_u64 = 0;
for (u64 i = 0; i < 10; i++)
{
// Create an event queue "bruteforcing" an available key
const u64 key_value = 0x80004d494f323285ull + i;
if (CellError res{sys_event_queue_create(ppu, id, attr, key_value, 0x40) + 0u})
{
if (res != CELL_EEXIST)
{
return res;
}
}
else
{
*key = key_value;
return CELL_OK;
}
}
return CELL_VOICE_ERROR_EVENT_QUEUE;
}
error_code cellVoiceCreatePort(vm::ptr<u32> portId, vm::cptr<CellVoicePortParam> pArg)
{
cellVoice.warning("cellVoiceCreatePort(portId=*0x%x, pArg=*0x%x)", portId, pArg);
auto& manager = g_fxo->get<voice_manager>();
std::scoped_lock lock(manager.mtx);
if (!manager.is_init)
return CELL_VOICE_ERROR_LIBVOICE_NOT_INIT;
if (!pArg)
return CELL_VOICE_ERROR_ARGUMENT_INVALID;
switch (pArg->portType)
{
case CELLVOICE_PORTTYPE_IN_PCMAUDIO:
case CELLVOICE_PORTTYPE_OUT_PCMAUDIO:
{
if (pArg->pcmaudio.format.dataType > CELLVOICE_PCM_INTEGER_LITTLE_ENDIAN)
return CELL_VOICE_ERROR_ARGUMENT_INVALID;
break;
}
case CELLVOICE_PORTTYPE_IN_VOICE:
case CELLVOICE_PORTTYPE_OUT_VOICE:
{
// Must be an exact value
switch (pArg->voice.bitrate)
{
case CELLVOICE_BITRATE_3850:
case CELLVOICE_BITRATE_4650:
case CELLVOICE_BITRATE_5700:
case CELLVOICE_BITRATE_7300:
case CELLVOICE_BITRATE_14400:
case CELLVOICE_BITRATE_16000:
case CELLVOICE_BITRATE_22533:
break;
default:
{
return CELL_VOICE_ERROR_ARGUMENT_INVALID;
}
}
break;
}
case CELLVOICE_PORTTYPE_IN_MIC:
case CELLVOICE_PORTTYPE_OUT_SECONDARY:
{
break;
}
default:
return CELL_VOICE_ERROR_ARGUMENT_INVALID;
}
if (manager.ports.size() > CELLVOICE_MAX_PORT)
return CELL_VOICE_ERROR_RESOURCE_INSUFFICIENT;
// Id: bits [8,15] seem to contain a "random" value
// bits [0,7] are based on creation counter modulo 0xa0
// The rest are set to zero and ignored.
manager.id_ctr++; manager.id_ctr %= 0xa0;
// It isn't known whether bits[8,15] are guaranteed to be non-zero
constexpr u32 min_value = 1;
for (u32 ctr2 = min_value; ctr2 < CELLVOICE_MAX_PORT + min_value; ctr2++)
{
const auto [port, success] = manager.ports.try_emplace(static_cast<u16>((ctr2 << 8) | manager.id_ctr));
if (success)
{
port->second.info = *pArg;
*portId = port->first;
return CELL_OK;
}
}
fmt::throw_exception("Unreachable");
}
error_code cellVoiceDeletePort(u32 portId)
{
cellVoice.warning("cellVoiceDeletePort(portId=%d)", portId);
auto& manager = g_fxo->get<voice_manager>();
std::scoped_lock lock(manager.mtx);
if (!manager.is_init)
return CELL_VOICE_ERROR_LIBVOICE_NOT_INIT;
if (manager.ports.erase(static_cast<u16>(portId)) == 0)
return CELL_VOICE_ERROR_TOPOLOGY;
return CELL_OK;
}
error_code cellVoiceDisconnectIPortFromOPort(u32 ips, u32 ops)
{
cellVoice.todo("cellVoiceDisconnectIPortFromOPort(ips=%d, ops=%d)", ips, ops);
auto& manager = g_fxo->get<voice_manager>();
reader_lock lock(manager.mtx);
if (!manager.is_init)
return CELL_VOICE_ERROR_LIBVOICE_NOT_INIT;
auto iport = manager.access_port(ips);
if (!iport || iport->info.portType >= CELLVOICE_PORTTYPE_OUT_PCMAUDIO)
return CELL_VOICE_ERROR_TOPOLOGY;
auto oport = manager.access_port(ops);
if (!oport || oport->info.portType <= CELLVOICE_PORTTYPE_IN_VOICE)
return CELL_VOICE_ERROR_TOPOLOGY;
return CELL_OK;
}
error_code cellVoiceEnd()
{
cellVoice.warning("cellVoiceEnd()");
auto& manager = g_fxo->get<voice_manager>();
std::scoped_lock lock(manager.mtx);
if (!manager.is_init)
return CELL_VOICE_ERROR_LIBVOICE_NOT_INIT;
if (std::exchange(manager.voice_service_started, false))
{
for (auto& key_pair : manager.queue_keys)
{
if (auto queue = lv2_event_queue::find(key_pair.first))
{
for (const auto& source : key_pair.second)
{
queue->send(source, CELLVOICE_EVENT_SERVICE_DETACHED, 0, 0);
}
}
}
}
manager.reset();
manager.is_init = false;
return CELL_OK;
}
error_code cellVoiceGetBitRate(u32 portId, vm::ptr<u32> bitrate)
{
cellVoice.warning("cellVoiceGetBitRate(portId=%d, bitrate=*0x%x)", portId, bitrate);
auto& manager = g_fxo->get<voice_manager>();
reader_lock lock(manager.mtx);
if (!manager.is_init)
return CELL_VOICE_ERROR_LIBVOICE_NOT_INIT;
// No nullptr check!
// Constant value for errors (meaning unknown)
*bitrate = 0x4f323285;
auto port = manager.access_port(portId);
if (!port || (port->info.portType != CELLVOICE_PORTTYPE_IN_VOICE && port->info.portType != CELLVOICE_PORTTYPE_OUT_VOICE))
return CELL_VOICE_ERROR_TOPOLOGY;
*bitrate = port->info.voice.bitrate;
return CELL_OK;
}
error_code cellVoiceGetMuteFlag(u32 portId, vm::ptr<u16> bMuted)
{
cellVoice.warning("cellVoiceGetMuteFlag(portId=%d, bMuted=*0x%x)", portId, bMuted);
auto& manager = g_fxo->get<voice_manager>();
reader_lock lock(manager.mtx);
if (!manager.is_init)
return CELL_VOICE_ERROR_LIBVOICE_NOT_INIT;
auto port = manager.access_port(portId);
if (!port)
return CELL_VOICE_ERROR_TOPOLOGY;
*bMuted = port->info.bMute;
return CELL_OK;
}
error_code cellVoiceGetPortAttr(u32 portId, u32 attr, vm::ptr<void> attrValue)
{
cellVoice.todo("cellVoiceGetPortAttr(portId=%d, attr=%d, attrValue=*0x%x)", portId, attr, attrValue);
auto& manager = g_fxo->get<voice_manager>();
reader_lock lock(manager.mtx);
if (!manager.is_init)
return CELL_VOICE_ERROR_LIBVOICE_NOT_INIT;
auto port = manager.access_port(portId);
if (!port)
return CELL_VOICE_ERROR_TOPOLOGY;
// Report detached microphone
return not_an_error(CELL_VOICE_ERROR_DEVICE_NOT_PRESENT);
}
error_code cellVoiceGetPortInfo(u32 portId, vm::ptr<CellVoiceBasePortInfo> pInfo)
{
cellVoice.todo("cellVoiceGetPortInfo(portId=%d, pInfo=*0x%x)", portId, pInfo);
auto& manager = g_fxo->get<voice_manager>();
reader_lock lock(manager.mtx);
if (!manager.is_init)
return CELL_VOICE_ERROR_LIBVOICE_NOT_INIT;
auto port = manager.access_port(portId);
if (!port)
return CELL_VOICE_ERROR_TOPOLOGY;
if (!manager.voice_service_started)
return CELL_VOICE_ERROR_SERVICE_DETACHED;
// No nullptr check!
pInfo->portType = port->info.portType;
// TODO
return CELL_OK;
}
error_code cellVoiceGetSignalState(u32 portId, u32 attr, vm::ptr<void> attrValue)
{
cellVoice.todo("cellVoiceGetSignalState(portId=%d, attr=%d, attrValue=*0x%x)", portId, attr, attrValue);
auto& manager = g_fxo->get<voice_manager>();
reader_lock lock(manager.mtx);
if (!manager.is_init)
return CELL_VOICE_ERROR_LIBVOICE_NOT_INIT;
auto port = manager.access_port(portId);
if (!port)
return CELL_VOICE_ERROR_TOPOLOGY;
// Report detached microphone
return not_an_error(CELL_VOICE_ERROR_DEVICE_NOT_PRESENT);
}
error_code cellVoiceGetVolume(u32 portId, vm::ptr<f32> volume)
{
cellVoice.warning("cellVoiceGetVolume(portId=%d, volume=*0x%x)", portId, volume);
auto& manager = g_fxo->get<voice_manager>();
reader_lock lock(manager.mtx);
if (!manager.is_init)
return CELL_VOICE_ERROR_LIBVOICE_NOT_INIT;
auto port = manager.access_port(portId);
// No nullptr check!
// Constant value for errors (meaning unknown)
*volume = std::bit_cast<f32, s32>(0x4f323285);
if (!port)
return CELL_VOICE_ERROR_TOPOLOGY;
*volume = port->info.volume;
return CELL_OK;
}
error_code cellVoiceInit(vm::ptr<CellVoiceInitParam> pArg)
{
cellVoice.todo("cellVoiceInit(pArg=*0x%x)", pArg);
auto& manager = g_fxo->get<voice_manager>();
std::scoped_lock lock(manager.mtx);
if (manager.is_init)
return CELL_VOICE_ERROR_LIBVOICE_INITIALIZED;
if (!pArg)
return CELL_VOICE_ERROR_ARGUMENT_INVALID;
manager.is_init = true;
return CELL_OK;
}
error_code cellVoiceInitEx(vm::ptr<CellVoiceInitParam> pArg)
{
cellVoice.todo("cellVoiceInitEx(pArg=*0x%x)", pArg);
auto& manager = g_fxo->get<voice_manager>();
if (manager.is_init)
return CELL_VOICE_ERROR_LIBVOICE_INITIALIZED;
if (!pArg)
return CELL_VOICE_ERROR_ARGUMENT_INVALID;
manager.is_init = true;
return CELL_OK;
}
error_code cellVoicePausePort(u32 portId)
{
cellVoice.todo("cellVoicePausePort(portId=%d)", portId);
auto& manager = g_fxo->get<voice_manager>();
reader_lock lock(manager.mtx);
if (!manager.is_init)
return CELL_VOICE_ERROR_LIBVOICE_NOT_INIT;
auto port = manager.access_port(portId);
if (!port)
return CELL_VOICE_ERROR_TOPOLOGY;
return CELL_OK;
}
error_code cellVoicePausePortAll()
{
cellVoice.todo("cellVoicePausePortAll()");
auto& manager = g_fxo->get<voice_manager>();
reader_lock lock(manager.mtx);
if (!manager.is_init)
return CELL_VOICE_ERROR_LIBVOICE_NOT_INIT;
return CELL_OK;
}
error_code cellVoiceRemoveNotifyEventQueue(u64 key)
{
cellVoice.warning("cellVoiceRemoveNotifyEventQueue(key=0x%llx)", key);
auto& manager = g_fxo->get<voice_manager>();
std::scoped_lock lock(manager.mtx);
if (!manager.is_init)
return CELL_VOICE_ERROR_LIBVOICE_NOT_INIT;
if (manager.queue_keys.erase(key) == 0)
return CELL_VOICE_ERROR_EVENT_QUEUE;
return CELL_OK;
}
error_code cellVoiceResetPort(u32 portId)
{
cellVoice.todo("cellVoiceResetPort(portId=%d)", portId);
auto& manager = g_fxo->get<voice_manager>();
reader_lock lock(manager.mtx);
if (!manager.is_init)
return CELL_VOICE_ERROR_LIBVOICE_NOT_INIT;
auto port = manager.access_port(portId);
if (!port)
return CELL_VOICE_ERROR_TOPOLOGY;
return CELL_OK;
}
error_code cellVoiceResumePort(u32 portId)
{
cellVoice.todo("cellVoiceResumePort(portId=%d)", portId);
auto& manager = g_fxo->get<voice_manager>();
reader_lock lock(manager.mtx);
if (!manager.is_init)
return CELL_VOICE_ERROR_LIBVOICE_NOT_INIT;
auto port = manager.access_port(portId);
if (!port)
return CELL_VOICE_ERROR_TOPOLOGY;
return CELL_OK;
}
error_code cellVoiceResumePortAll()
{
cellVoice.todo("cellVoiceResumePortAll()");
auto& manager = g_fxo->get<voice_manager>();
reader_lock lock(manager.mtx);
if (!manager.is_init)
return CELL_VOICE_ERROR_LIBVOICE_NOT_INIT;
return CELL_OK;
}
error_code cellVoiceSetBitRate(u32 portId, CellVoiceBitRate bitrate)
{
cellVoice.warning("cellVoiceSetBitRate(portId=%d, bitrate=%d)", portId, +bitrate);
auto& manager = g_fxo->get<voice_manager>();
std::scoped_lock lock(manager.mtx);
if (!manager.is_init)
return CELL_VOICE_ERROR_LIBVOICE_NOT_INIT;
auto port = manager.access_port(portId);
if (!port || (port->info.portType != CELLVOICE_PORTTYPE_IN_VOICE && port->info.portType != CELLVOICE_PORTTYPE_OUT_VOICE))
return CELL_VOICE_ERROR_TOPOLOGY;
// TODO: Check ordering of checks.
switch (bitrate)
{
case CELLVOICE_BITRATE_3850:
case CELLVOICE_BITRATE_4650:
case CELLVOICE_BITRATE_5700:
case CELLVOICE_BITRATE_7300:
case CELLVOICE_BITRATE_14400:
case CELLVOICE_BITRATE_16000:
case CELLVOICE_BITRATE_22533:
break;
default:
{
return CELL_VOICE_ERROR_ARGUMENT_INVALID;
}
}
port->info.voice.bitrate = bitrate;
return CELL_OK;
}
error_code cellVoiceSetMuteFlag(u32 portId, u16 bMuted)
{
cellVoice.warning("cellVoiceSetMuteFlag(portId=%d, bMuted=%d)", portId, bMuted);
auto& manager = g_fxo->get<voice_manager>();
std::scoped_lock lock(manager.mtx);
if (!manager.is_init)
return CELL_VOICE_ERROR_LIBVOICE_NOT_INIT;
auto port = manager.access_port(portId);
if (!port)
return CELL_VOICE_ERROR_TOPOLOGY;
port->info.bMute = bMuted;
return CELL_OK;
}
error_code cellVoiceSetMuteFlagAll(u16 bMuted)
{
cellVoice.warning("cellVoiceSetMuteFlagAll(bMuted=%d)", bMuted);
auto& manager = g_fxo->get<voice_manager>();
reader_lock lock(manager.mtx);
if (!manager.is_init)
return CELL_VOICE_ERROR_LIBVOICE_NOT_INIT;
// Doesn't change port->bMute value
return CELL_OK;
}
error_code cellVoiceSetNotifyEventQueue(u64 key, u64 source)
{
cellVoice.warning("cellVoiceSetNotifyEventQueue(key=0x%llx, source=0x%llx)", key, source);
auto& manager = g_fxo->get<voice_manager>();
std::scoped_lock lock(manager.mtx);
if (!manager.is_init)
return CELL_VOICE_ERROR_LIBVOICE_NOT_INIT;
// Note: it is allowed to enqueue the key twice (another source is enqueued with FIFO ordering)
// It is not allowed to enqueue an invalid key
if (!lv2_event_queue::find(key))
return CELL_VOICE_ERROR_EVENT_QUEUE;
if (!source)
{
// same thing as sys_event_port_send with port.name == 0
// Try to give different port id everytime
source = ((process_getpid() + 1ull) << 32) | (lv2_event_port::id_base + manager.port_source * lv2_event_port::id_step);
manager.port_source = (manager.port_source + 1) % lv2_event_port::id_count;
}
manager.queue_keys[key].push_back(source);
return CELL_OK;
}
error_code cellVoiceSetPortAttr(u32 portId, u32 attr, vm::ptr<void> attrValue)
{
cellVoice.todo("cellVoiceSetPortAttr(portId=%d, attr=%d, attrValue=*0x%x)", portId, attr, attrValue);
auto& manager = g_fxo->get<voice_manager>();
std::scoped_lock lock(manager.mtx);
if (!manager.is_init)
return CELL_VOICE_ERROR_LIBVOICE_NOT_INIT;
auto port = manager.access_port(portId);
if (!port)
return CELL_VOICE_ERROR_TOPOLOGY;
// Report detached microphone
return not_an_error(CELL_VOICE_ERROR_DEVICE_NOT_PRESENT);
}
error_code cellVoiceSetVolume(u32 portId, f32 volume)
{
cellVoice.warning("cellVoiceSetVolume(portId=%d, volume=%f)", portId, volume);
auto& manager = g_fxo->get<voice_manager>();
std::scoped_lock lock(manager.mtx);
if (!manager.is_init)
return CELL_VOICE_ERROR_LIBVOICE_NOT_INIT;
auto port = manager.access_port(portId);
if (!port)
return CELL_VOICE_ERROR_TOPOLOGY;
port->info.volume = volume;
return CELL_OK;
}
error_code VoiceStart(voice_manager& manager)
{
if (std::exchange(manager.voice_service_started, true))
return CELL_OK;
for (auto& key_pair : manager.queue_keys)
{
if (auto queue = lv2_event_queue::find(key_pair.first))
{
for (const auto& source : key_pair.second)
{
queue->send(source, CELLVOICE_EVENT_SERVICE_ATTACHED, 0, 0);
}
}
}
return CELL_OK;
}
error_code cellVoiceStart()
{
cellVoice.warning("cellVoiceStart()");
auto& manager = g_fxo->get<voice_manager>();
std::scoped_lock lock(manager.mtx);
if (!manager.is_init)
return CELL_VOICE_ERROR_LIBVOICE_NOT_INIT;
return VoiceStart(manager);
}
error_code cellVoiceStartEx(vm::ptr<CellVoiceStartParam> pArg)
{
cellVoice.todo("cellVoiceStartEx(pArg=*0x%x)", pArg);
auto& manager = g_fxo->get<voice_manager>();
std::scoped_lock lock(manager.mtx);
if (!manager.is_init)
return CELL_VOICE_ERROR_LIBVOICE_NOT_INIT;
if (!pArg)
return CELL_VOICE_ERROR_ARGUMENT_INVALID;
// TODO: Check provided memory container
return VoiceStart(manager);
}
error_code cellVoiceStop()
{
cellVoice.warning("cellVoiceStop()");
auto& manager = g_fxo->get<voice_manager>();
std::scoped_lock lock(manager.mtx);
if (!manager.is_init)
return CELL_VOICE_ERROR_LIBVOICE_NOT_INIT;
if (!std::exchange(manager.voice_service_started, false))
return CELL_OK;
for (auto& key_pair : manager.queue_keys)
{
if (auto queue = lv2_event_queue::find(key_pair.first))
{
for (const auto& source : key_pair.second)
{
queue->send(source, CELLVOICE_EVENT_SERVICE_DETACHED, 0, 0);
}
}
}
return CELL_OK;
}
error_code cellVoiceUpdatePort(u32 portId, vm::cptr<CellVoicePortParam> pArg)
{
cellVoice.warning("cellVoiceUpdatePort(portId=%d, pArg=*0x%x)", portId, pArg);
auto& manager = g_fxo->get<voice_manager>();
std::scoped_lock lock(manager.mtx);
if (!manager.is_init)
return CELL_VOICE_ERROR_LIBVOICE_NOT_INIT;
if (!pArg)
return CELL_VOICE_ERROR_ARGUMENT_INVALID;
auto port = manager.access_port(portId);
if (!port)
return CELL_VOICE_ERROR_TOPOLOGY;
// Not all info is updated
port->info.bMute = pArg->bMute;
port->info.volume = pArg->volume;
port->info.threshold = pArg->threshold;
if (port->info.portType == CELLVOICE_PORTTYPE_IN_VOICE || port->info.portType == CELLVOICE_PORTTYPE_OUT_VOICE)
{
port->info.voice.bitrate = pArg->voice.bitrate;
}
return CELL_OK;
}
error_code cellVoiceWriteToIPort(u32 ips, vm::cptr<void> data, vm::ptr<u32> size)
{
cellVoice.todo("cellVoiceWriteToIPort(ips=%d, data=*0x%x, size=*0x%x)", ips, data, size);
auto& manager = g_fxo->get<voice_manager>();
reader_lock lock(manager.mtx);
if (!manager.is_init)
return CELL_VOICE_ERROR_LIBVOICE_NOT_INIT;
auto iport = manager.access_port(ips);
if (!iport || iport->info.portType >= CELLVOICE_PORTTYPE_OUT_PCMAUDIO)
return CELL_VOICE_ERROR_TOPOLOGY;
return CELL_OK;
}
error_code cellVoiceWriteToIPortEx(u32 ips, vm::cptr<void> data, vm::ptr<u32> size, u32 numFrameLost)
{
cellVoice.todo("cellVoiceWriteToIPortEx(ips=%d, data=*0x%x, size=*0x%x, numFrameLost=%d)", ips, data, size, numFrameLost);
auto& manager = g_fxo->get<voice_manager>();
reader_lock lock(manager.mtx);
if (!manager.is_init)
return CELL_VOICE_ERROR_LIBVOICE_NOT_INIT;
auto iport = manager.access_port(ips);
if (!iport || iport->info.portType >= CELLVOICE_PORTTYPE_OUT_PCMAUDIO)
return CELL_VOICE_ERROR_TOPOLOGY;
return CELL_OK;
}
error_code cellVoiceWriteToIPortEx2(u32 ips, vm::cptr<void> data, vm::ptr<u32> size, s16 frameGaps)
{
cellVoice.todo("cellVoiceWriteToIPortEx2(ips=%d, data=*0x%x, size=*0x%x, frameGaps=%d)", ips, data, size, frameGaps);
auto& manager = g_fxo->get<voice_manager>();
reader_lock lock(manager.mtx);
if (!manager.is_init)
return CELL_VOICE_ERROR_LIBVOICE_NOT_INIT;
auto iport = manager.access_port(ips);
if (!iport || iport->info.portType >= CELLVOICE_PORTTYPE_OUT_PCMAUDIO)
return CELL_VOICE_ERROR_TOPOLOGY;
return CELL_OK;
}
error_code cellVoiceReadFromOPort(u32 ops, vm::ptr<void> data, vm::ptr<u32> size)
{
// Spammy TODO
cellVoice.trace("cellVoiceReadFromOPort(ops=%d, data=*0x%x, size=*0x%x)", ops, data, size);
auto& manager = g_fxo->get<voice_manager>();
reader_lock lock(manager.mtx);
if (!manager.is_init)
return CELL_VOICE_ERROR_LIBVOICE_NOT_INIT;
auto oport = manager.access_port(ops);
if (!oport || oport->info.portType <= CELLVOICE_PORTTYPE_IN_VOICE)
return CELL_VOICE_ERROR_TOPOLOGY;
if (size)
*size = 0;
return CELL_OK;
}
error_code cellVoiceDebugTopology()
{
UNIMPLEMENTED_FUNC(cellVoice);
if (!g_fxo->get<voice_manager>().is_init)
return CELL_VOICE_ERROR_LIBVOICE_NOT_INIT;
return CELL_VOICE_ERROR_NOT_IMPLEMENTED;
}
DECLARE(ppu_module_manager::cellVoice)("cellVoice", []()
{
REG_FUNC(cellVoice, cellVoiceConnectIPortToOPort);
REG_FUNC(cellVoice, cellVoiceCreateNotifyEventQueue);
REG_FUNC(cellVoice, cellVoiceCreatePort);
REG_FUNC(cellVoice, cellVoiceDeletePort);
REG_FUNC(cellVoice, cellVoiceDisconnectIPortFromOPort);
REG_FUNC(cellVoice, cellVoiceEnd);
REG_FUNC(cellVoice, cellVoiceGetBitRate);
REG_FUNC(cellVoice, cellVoiceGetMuteFlag);
REG_FUNC(cellVoice, cellVoiceGetPortAttr);
REG_FUNC(cellVoice, cellVoiceGetPortInfo);
REG_FUNC(cellVoice, cellVoiceGetSignalState);
REG_FUNC(cellVoice, cellVoiceGetVolume);
REG_FUNC(cellVoice, cellVoiceInit);
REG_FUNC(cellVoice, cellVoiceInitEx);
REG_FUNC(cellVoice, cellVoicePausePort);
REG_FUNC(cellVoice, cellVoicePausePortAll);
REG_FUNC(cellVoice, cellVoiceRemoveNotifyEventQueue);
REG_FUNC(cellVoice, cellVoiceResetPort);
REG_FUNC(cellVoice, cellVoiceResumePort);
REG_FUNC(cellVoice, cellVoiceResumePortAll);
REG_FUNC(cellVoice, cellVoiceSetBitRate);
REG_FUNC(cellVoice, cellVoiceSetMuteFlag);
REG_FUNC(cellVoice, cellVoiceSetMuteFlagAll);
REG_FUNC(cellVoice, cellVoiceSetNotifyEventQueue);
REG_FUNC(cellVoice, cellVoiceSetPortAttr);
REG_FUNC(cellVoice, cellVoiceSetVolume);
REG_FUNC(cellVoice, cellVoiceStart);
REG_FUNC(cellVoice, cellVoiceStartEx);
REG_FUNC(cellVoice, cellVoiceStop);
REG_FUNC(cellVoice, cellVoiceUpdatePort);
REG_FUNC(cellVoice, cellVoiceWriteToIPort);
REG_FUNC(cellVoice, cellVoiceWriteToIPortEx);
REG_FUNC(cellVoice, cellVoiceWriteToIPortEx2);
REG_FUNC(cellVoice, cellVoiceReadFromOPort);
REG_FUNC(cellVoice, cellVoiceDebugTopology);
});
| 22,315
|
C++
|
.cpp
| 660
| 31.272727
| 123
| 0.749018
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| false
| false
|
5,228
|
libsynth2.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/libsynth2.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
#include "libsynth2.h"
LOG_CHANNEL(libsynth2);
template<>
void fmt_class_string<CellSoundSynth2Error>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_SOUND_SYNTH2_ERROR_FATAL);
STR_CASE(CELL_SOUND_SYNTH2_ERROR_INVALID_PARAMETER);
STR_CASE(CELL_SOUND_SYNTH2_ERROR_ALREADY_INITIALIZED);
}
return unknown;
});
}
error_code cellSoundSynth2Config(s16 param, s32 value)
{
libsynth2.todo("cellSoundSynth2Config(param=%d, value=%d)", param, value);
return CELL_OK;
}
error_code cellSoundSynth2Init(s16 flag)
{
libsynth2.todo("cellSoundSynth2Init(flag=%d)", flag);
return CELL_OK;
}
error_code cellSoundSynth2Exit()
{
libsynth2.todo("cellSoundSynth2Exit()");
return CELL_OK;
}
void cellSoundSynth2SetParam(u16 reg, u16 value)
{
libsynth2.todo("cellSoundSynth2SetParam(register=0x%x, value=0x%x)", reg, value);
}
u16 cellSoundSynth2GetParam(u16 reg)
{
libsynth2.todo("cellSoundSynth2GetParam(register=0x%x)", reg);
return 0;
}
void cellSoundSynth2SetSwitch(u16 reg, u32 value)
{
libsynth2.todo("cellSoundSynth2SetSwitch(register=0x%x, value=0x%x)", reg, value);
}
u32 cellSoundSynth2GetSwitch(u16 reg)
{
libsynth2.todo("cellSoundSynth2GetSwitch(register=0x%x)", reg);
return 0;
}
error_code cellSoundSynth2SetAddr(u16 reg, u32 value)
{
libsynth2.todo("cellSoundSynth2SetAddr(register=0x%x, value=0x%x)", reg, value);
return CELL_OK;
}
u32 cellSoundSynth2GetAddr(u16 reg)
{
libsynth2.todo("cellSoundSynth2GetAddr(register=0x%x)", reg);
return 0;
}
error_code cellSoundSynth2SetEffectAttr(s16 bus, vm::ptr<CellSoundSynth2EffectAttr> attr)
{
libsynth2.todo("cellSoundSynth2SetEffectAttr(bus=%d, attr=*0x%x)", bus, attr);
return CELL_OK;
}
error_code cellSoundSynth2SetEffectMode(s16 bus, vm::ptr<CellSoundSynth2EffectAttr> attr)
{
libsynth2.todo("cellSoundSynth2SetEffectMode(bus=%d, attr=*0x%x)", bus, attr);
return CELL_OK;
}
void cellSoundSynth2SetCoreAttr(u16 entry, u16 value)
{
libsynth2.todo("cellSoundSynth2SetCoreAttr(entry=0x%x, value=0x%x)", entry, value);
}
error_code cellSoundSynth2Generate(u16 samples, vm::ptr<f32> Lout, vm::ptr<f32> Rout, vm::ptr<f32> Ls, vm::ptr<f32> Rs)
{
libsynth2.todo("cellSoundSynth2Generate(samples=0x%x, Lout=*0x%x, Rout=*0x%x, Ls=*0x%x, Rs=*0x%x)", samples, Lout, Rout, Ls, Rs);
return CELL_OK;
}
error_code cellSoundSynth2VoiceTrans(s16 channel, u16 mode, vm::ptr<u8> m_addr, u32 s_addr, u32 size)
{
libsynth2.todo("cellSoundSynth2VoiceTrans(channel=%d, mode=0x%x, m_addr=*0x%x, s_addr=0x%x, size=0x%x)", channel, mode, m_addr, s_addr, size);
return CELL_OK;
}
error_code cellSoundSynth2VoiceTransStatus(s16 channel, s16 flag)
{
libsynth2.todo("cellSoundSynth2VoiceTransStatus(channel=%d, flag=%d)", channel, flag);
return CELL_OK;
}
u16 cellSoundSynth2Note2Pitch(u16 center_note, u16 center_fine, u16 note, s16 fine)
{
libsynth2.todo("cellSoundSynth2Note2Pitch(center_note=0x%x, center_fine=0x%x, note=0x%x, fine=%d)", center_note, center_fine, note, fine);
return 0;
}
u16 cellSoundSynth2Pitch2Note(u16 center_note, u16 center_fine, u16 pitch)
{
libsynth2.todo("cellSoundSynth2Pitch2Note(center_note=0x%x, center_fine=0x%x, pitch=0x%x)", center_note, center_fine, pitch);
return 0;
}
DECLARE(ppu_module_manager::libsynth2)("libsynth2", []()
{
REG_FUNC(libsynth2, cellSoundSynth2Config);
REG_FUNC(libsynth2, cellSoundSynth2Init);
REG_FUNC(libsynth2, cellSoundSynth2Exit);
REG_FUNC(libsynth2, cellSoundSynth2SetParam);
REG_FUNC(libsynth2, cellSoundSynth2GetParam);
REG_FUNC(libsynth2, cellSoundSynth2SetSwitch);
REG_FUNC(libsynth2, cellSoundSynth2GetSwitch);
REG_FUNC(libsynth2, cellSoundSynth2SetAddr);
REG_FUNC(libsynth2, cellSoundSynth2GetAddr);
REG_FUNC(libsynth2, cellSoundSynth2SetEffectAttr);
REG_FUNC(libsynth2, cellSoundSynth2SetEffectMode);
REG_FUNC(libsynth2, cellSoundSynth2SetCoreAttr);
REG_FUNC(libsynth2, cellSoundSynth2Generate);
REG_FUNC(libsynth2, cellSoundSynth2VoiceTrans);
REG_FUNC(libsynth2, cellSoundSynth2VoiceTransStatus);
REG_FUNC(libsynth2, cellSoundSynth2Note2Pitch);
REG_FUNC(libsynth2, cellSoundSynth2Pitch2Note);
});
| 4,183
|
C++
|
.cpp
| 120
| 33.083333
| 143
| 0.78529
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| true
| false
| false
| true
| false
| false
|
5,229
|
cellKb.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellKb.cpp
|
#include "stdafx.h"
#include "Emu/IdManager.h"
#include "Emu/System.h"
#include "Emu/Cell/PPUModule.h"
#include "Emu/Io/KeyboardHandler.h"
#include "cellKb.h"
error_code sys_config_start(ppu_thread& ppu);
error_code sys_config_stop(ppu_thread& ppu);
extern bool is_input_allowed();
LOG_CHANNEL(cellKb);
template<>
void fmt_class_string<CellKbError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_KB_ERROR_FATAL);
STR_CASE(CELL_KB_ERROR_INVALID_PARAMETER);
STR_CASE(CELL_KB_ERROR_ALREADY_INITIALIZED);
STR_CASE(CELL_KB_ERROR_UNINITIALIZED);
STR_CASE(CELL_KB_ERROR_RESOURCE_ALLOCATION_FAILED);
STR_CASE(CELL_KB_ERROR_READ_FAILED);
STR_CASE(CELL_KB_ERROR_NO_DEVICE);
STR_CASE(CELL_KB_ERROR_SYS_SETTING_FAILED);
}
return unknown;
});
}
KeyboardHandlerBase::KeyboardHandlerBase(utils::serial* ar)
{
if (!ar)
{
return;
}
u32 max_connect = 0;
(*ar)(max_connect);
if (max_connect)
{
Emu.PostponeInitCode([this, max_connect]()
{
std::lock_guard<std::mutex> lock(m_mutex);
AddConsumer(keyboard_consumer::identifier::cellKb, max_connect);
auto lk = init.init();
});
}
}
void KeyboardHandlerBase::save(utils::serial& ar)
{
u32 max_connect = 0;
const auto inited = init.access();
if (inited)
{
std::lock_guard<std::mutex> lock(m_mutex);
if (auto it = m_consumers.find(keyboard_consumer::identifier::cellKb); it != m_consumers.end())
{
max_connect = it->second.GetInfo().max_connect;
}
}
ar(max_connect);
}
error_code cellKbInit(ppu_thread& ppu, u32 max_connect)
{
cellKb.warning("cellKbInit(max_connect=%d)", max_connect);
auto& handler = g_fxo->get<KeyboardHandlerBase>();
auto init = handler.init.init();
if (!init)
return CELL_KB_ERROR_ALREADY_INITIALIZED;
if (max_connect == 0 || max_connect > CELL_KB_MAX_KEYBOARDS)
{
init.cancel();
return CELL_KB_ERROR_INVALID_PARAMETER;
}
sys_config_start(ppu);
std::lock_guard<std::mutex> lock(handler.m_mutex);
handler.AddConsumer(keyboard_consumer::identifier::cellKb, std::min(max_connect, 7u));
return CELL_OK;
}
error_code cellKbEnd(ppu_thread& ppu)
{
cellKb.notice("cellKbEnd()");
auto& handler = g_fxo->get<KeyboardHandlerBase>();
const auto init = handler.init.reset();
if (!init)
return CELL_KB_ERROR_UNINITIALIZED;
{
std::lock_guard<std::mutex> lock(handler.m_mutex);
handler.RemoveConsumer(keyboard_consumer::identifier::cellKb);
}
// TODO
sys_config_stop(ppu);
return CELL_OK;
}
error_code cellKbClearBuf(u32 port_no)
{
cellKb.trace("cellKbClearBuf(port_no=%d)", port_no);
auto& handler = g_fxo->get<KeyboardHandlerBase>();
const auto init = handler.init.access();
if (!init)
return CELL_KB_ERROR_UNINITIALIZED;
if (port_no >= CELL_KB_MAX_KEYBOARDS)
return CELL_KB_ERROR_INVALID_PARAMETER;
std::lock_guard<std::mutex> lock(handler.m_mutex);
keyboard_consumer& consumer = handler.GetConsumer(keyboard_consumer::identifier::cellKb);
const KbInfo& current_info = consumer.GetInfo();
if (port_no >= consumer.GetKeyboards().size() || current_info.status[port_no] != CELL_KB_STATUS_CONNECTED)
return not_an_error(CELL_KB_ERROR_NO_DEVICE);
KbData& current_data = consumer.GetData(port_no);
current_data.len = 0;
current_data.led = 0;
current_data.mkey = 0;
for (int i = 0; i < CELL_KB_MAX_KEYCODES; i++)
{
current_data.buttons[i] = KbButton(CELL_KEYC_NO_EVENT, 0, false);
}
return CELL_OK;
}
u16 cellKbCnvRawCode(u32 arrange, u32 mkey, u32 led, u16 rawcode)
{
cellKb.trace("cellKbCnvRawCode(arrange=%d, mkey=%d, led=%d, rawcode=0x%x)", arrange, mkey, led, rawcode);
// CELL_KB_RAWDAT
if (rawcode <= CELL_KEYC_E_UNDEF ||
rawcode == CELL_KEYC_ESCAPE ||
rawcode == CELL_KEYC_106_KANJI ||
(rawcode >= CELL_KEYC_CAPS_LOCK && rawcode <= CELL_KEYC_NUM_LOCK) ||
rawcode == CELL_KEYC_APPLICATION ||
rawcode == CELL_KEYC_KANA ||
rawcode == CELL_KEYC_HENKAN ||
rawcode == CELL_KEYC_MUHENKAN)
{
return rawcode | CELL_KB_RAWDAT;
}
const bool is_alt = mkey & (CELL_KB_MKEY_L_ALT | CELL_KB_MKEY_R_ALT);
const bool is_shift = mkey & (CELL_KB_MKEY_L_SHIFT | CELL_KB_MKEY_R_SHIFT);
const bool is_caps_lock = led & (CELL_KB_LED_CAPS_LOCK);
const bool is_num_lock = led & (CELL_KB_LED_NUM_LOCK);
const bool is_shift_lock = is_caps_lock && (arrange == CELL_KB_MAPPING_GERMAN_GERMANY || arrange == CELL_KB_MAPPING_FRENCH_FRANCE);
// CELL_KB_NUMPAD
if (is_num_lock)
{
//if (rawcode == CELL_KEYC_KPAD_NUMLOCK) return 0x00 | CELL_KB_KEYPAD; // 'Num Lock' (unreachable)
if (rawcode == CELL_KEYC_KPAD_SLASH) return 0x2F | CELL_KB_KEYPAD; // '/'
if (rawcode == CELL_KEYC_KPAD_ASTERISK) return 0x2A | CELL_KB_KEYPAD; // '*'
if (rawcode == CELL_KEYC_KPAD_MINUS) return 0x2D | CELL_KB_KEYPAD; // '-'
if (rawcode == CELL_KEYC_KPAD_PLUS) return 0x2B | CELL_KB_KEYPAD; // '+'
if (rawcode == CELL_KEYC_KPAD_ENTER) return 0x0A | CELL_KB_KEYPAD; // '\n'
if (rawcode == CELL_KEYC_KPAD_0) return 0x30 | CELL_KB_KEYPAD; // '0'
if (rawcode >= CELL_KEYC_KPAD_1 && rawcode <= CELL_KEYC_KPAD_9) return (rawcode - 0x28) | CELL_KB_KEYPAD; // '1' - '9'
}
// ASCII
const auto get_ascii = [&](u16 raw, u16 shifted = 0, u16 altered = 0)
{
// Usually caps lock only applies uppercase to letters, but some layouts treat it as shift lock for all keys.
if ((is_shift || (is_caps_lock && (is_shift_lock || std::isalpha(raw)))) && shifted)
{
return shifted;
}
if (is_alt && altered)
{
return altered;
}
return raw;
};
if (arrange == CELL_KB_MAPPING_106) // (Japanese)
{
if (rawcode == CELL_KEYC_1) return get_ascii('1', '!');
if (rawcode == CELL_KEYC_2) return get_ascii('2', '"');
if (rawcode == CELL_KEYC_3) return get_ascii('3', '#');
if (rawcode == CELL_KEYC_4) return get_ascii('4', '$');
if (rawcode == CELL_KEYC_5) return get_ascii('5', '%');
if (rawcode == CELL_KEYC_6) return get_ascii('6', '&');
if (rawcode == CELL_KEYC_7) return get_ascii('7', '\'');
if (rawcode == CELL_KEYC_8) return get_ascii('8', '(');
if (rawcode == CELL_KEYC_9) return get_ascii('9', ')');
if (rawcode == CELL_KEYC_0) return get_ascii('0', '~');
if (rawcode == CELL_KEYC_ACCENT_CIRCONFLEX_106) return get_ascii('^', '~');
if (rawcode == CELL_KEYC_ATMARK_106) return get_ascii('@', '`');
if (rawcode == CELL_KEYC_LEFT_BRACKET_106) return get_ascii('[', '{');
if (rawcode == CELL_KEYC_RIGHT_BRACKET_106) return get_ascii(']', '}');
if (rawcode == CELL_KEYC_SEMICOLON) return get_ascii(';', '+');
if (rawcode == CELL_KEYC_COLON_106) return get_ascii(':', '*');
if (rawcode == CELL_KEYC_COMMA) return get_ascii(',', '<');
if (rawcode == CELL_KEYC_PERIOD) return get_ascii('.', '>');
if (rawcode == CELL_KEYC_SLASH) return get_ascii('/', '?');
if (rawcode == CELL_KEYC_BACKSLASH_106) return get_ascii('\\', '_');
if (rawcode == CELL_KEYC_YEN_106) return get_ascii(190, '|'); // ¥
}
else if (arrange == CELL_KB_MAPPING_101) // (US)
{
if (rawcode == CELL_KEYC_1) return get_ascii('1', '!');
if (rawcode == CELL_KEYC_2) return get_ascii('2', '@');
if (rawcode == CELL_KEYC_3) return get_ascii('3', '#');
if (rawcode == CELL_KEYC_4) return get_ascii('4', '$');
if (rawcode == CELL_KEYC_5) return get_ascii('5', '%');
if (rawcode == CELL_KEYC_6) return get_ascii('6', '^');
if (rawcode == CELL_KEYC_7) return get_ascii('7', '&');
if (rawcode == CELL_KEYC_8) return get_ascii('8', '*');
if (rawcode == CELL_KEYC_9) return get_ascii('9', '(');
if (rawcode == CELL_KEYC_0) return get_ascii('0', ')');
if (rawcode == CELL_KEYC_MINUS) return get_ascii('-', '_');
if (rawcode == CELL_KEYC_EQUAL_101) return get_ascii('=', '+');
if (rawcode == CELL_KEYC_LEFT_BRACKET_101) return get_ascii('[', '{');
if (rawcode == CELL_KEYC_RIGHT_BRACKET_101) return get_ascii(']', '}');
if (rawcode == CELL_KEYC_BACKSLASH_101) return get_ascii('\\', '|');
if (rawcode == CELL_KEYC_SEMICOLON) return get_ascii(';', ':');
if (rawcode == CELL_KEYC_QUOTATION_101) return get_ascii('\'', '"');
if (rawcode == CELL_KEYC_COMMA) return get_ascii(',', '<');
if (rawcode == CELL_KEYC_PERIOD) return get_ascii('.', '>');
if (rawcode == CELL_KEYC_SLASH) return get_ascii('/', '?');
if (rawcode == CELL_KEYC_BACK_QUOTE) return get_ascii('`', '~');
}
else if (arrange == CELL_KB_MAPPING_GERMAN_GERMANY)
{
if (rawcode == CELL_KEYC_1) return get_ascii('1', '!');
if (rawcode == CELL_KEYC_2) return get_ascii('2', '"');
if (rawcode == CELL_KEYC_3) return get_ascii('3', 245); // §
if (rawcode == CELL_KEYC_4) return get_ascii('4', '$');
if (rawcode == CELL_KEYC_5) return get_ascii('5', '%');
if (rawcode == CELL_KEYC_6) return get_ascii('6', '&');
if (rawcode == CELL_KEYC_7) return get_ascii('7', '/', '{');
if (rawcode == CELL_KEYC_8) return get_ascii('8', '(', '[');
if (rawcode == CELL_KEYC_9) return get_ascii('9', ')', ']');
if (rawcode == CELL_KEYC_0) return get_ascii('0', '=', '}');
if (rawcode == CELL_KEYC_MINUS) return get_ascii('-', '_');
if (rawcode == CELL_KEYC_ACCENT_CIRCONFLEX_106) return get_ascii('^', 248); // °
if (rawcode == CELL_KEYC_COMMA) return get_ascii(',', ';');
if (rawcode == CELL_KEYC_PERIOD) return get_ascii('.', ':');
if (rawcode == CELL_KEYC_KPAD_PLUS) return get_ascii('+', '*', '~');
if (rawcode == CELL_KEYC_LESS) return get_ascii('<', '>', '|');
if (rawcode == CELL_KEYC_HASHTAG) return get_ascii('#', '\'');
if (rawcode == CELL_KEYC_SSHARP) return get_ascii(225, '?', '\\'); // ß
if (rawcode == CELL_KEYC_BACK_QUOTE) return get_ascii(239, '`'); // ´
if (rawcode == CELL_KEYC_Q) return get_ascii('q', 'Q', '@');
}
if (rawcode >= CELL_KEYC_A && rawcode <= CELL_KEYC_Z) // 'A' - 'Z'
{
if (is_shift != is_caps_lock)
{
return rawcode + 0x3D; // Return uppercase if exactly one is active.
}
return rawcode + 0x5D; // Return lowercase if none or both are active.
}
if (rawcode >= CELL_KEYC_1 && rawcode <= CELL_KEYC_9) return rawcode + 0x13; // '1' - '9'
if (rawcode == CELL_KEYC_0) return 0x30; // '0'
if (rawcode == CELL_KEYC_ENTER) return 0x0A; // '\n'
//if (rawcode == CELL_KEYC_ESC) return 0x1B; // 'ESC' (unreachable)
if (rawcode == CELL_KEYC_BS) return 0x08; // '\b'
if (rawcode == CELL_KEYC_TAB) return 0x09; // '\t'
if (rawcode == CELL_KEYC_SPACE) return 0x20; // 'space'
// TODO: Add more keys and layouts
return 0x0000;
}
error_code cellKbGetInfo(vm::ptr<CellKbInfo> info)
{
cellKb.trace("cellKbGetInfo(info=*0x%x)", info);
auto& handler = g_fxo->get<KeyboardHandlerBase>();
const auto init = handler.init.access();
if (!init)
return CELL_KB_ERROR_UNINITIALIZED;
if (!info)
return CELL_KB_ERROR_INVALID_PARAMETER;
std::memset(info.get_ptr(), 0, info.size());
std::lock_guard<std::mutex> lock(handler.m_mutex);
keyboard_consumer& consumer = handler.GetConsumer(keyboard_consumer::identifier::cellKb);
const KbInfo& current_info = consumer.GetInfo();
info->max_connect = current_info.max_connect;
info->now_connect = current_info.now_connect;
info->info = current_info.info;
for (u32 i = 0; i < CELL_KB_MAX_KEYBOARDS; i++)
{
info->status[i] = current_info.status[i];
}
return CELL_OK;
}
error_code cellKbRead(u32 port_no, vm::ptr<CellKbData> data)
{
cellKb.trace("cellKbRead(port_no=%d, data=*0x%x)", port_no, data);
auto& handler = g_fxo->get<KeyboardHandlerBase>();
const auto init = handler.init.access();
if (!init)
return CELL_KB_ERROR_UNINITIALIZED;
if (port_no >= CELL_KB_MAX_KEYBOARDS || !data)
return CELL_KB_ERROR_INVALID_PARAMETER;
std::lock_guard<std::mutex> lock(handler.m_mutex);
keyboard_consumer& consumer = handler.GetConsumer(keyboard_consumer::identifier::cellKb);
const KbInfo& current_info = consumer.GetInfo();
if (port_no >= consumer.GetKeyboards().size() || current_info.status[port_no] != CELL_KB_STATUS_CONNECTED)
return not_an_error(CELL_KB_ERROR_NO_DEVICE);
KbData& current_data = consumer.GetData(port_no);
if (current_info.is_null_handler || (current_info.info & CELL_KB_INFO_INTERCEPTED) || !is_input_allowed())
{
data->led = 0;
data->mkey = 0;
data->len = 0;
}
else
{
data->led = current_data.led;
data->mkey = current_data.mkey;
data->len = std::min<s32>(CELL_KB_MAX_KEYCODES, current_data.len);
}
if (current_data.len > 0)
{
for (s32 i = 0; i < current_data.len; i++)
{
data->keycode[i] = current_data.buttons[i].m_keyCode;
}
KbConfig& current_config = consumer.GetConfig(port_no);
// For single character mode to work properly we need to "flush" the buffer after reading or else we'll constantly get the same key presses with each call.
// Actual key repeats are handled by adding a new key code to the buffer periodically. Key releases are handled in a similar fashion.
// Warning: Don't do this in packet mode, which is basically the mouse and keyboard gaming mode. Otherwise games like Unreal Tournament will be unplayable.
if (current_config.read_mode == CELL_KB_RMODE_INPUTCHAR)
{
current_data.len = 0;
}
}
return CELL_OK;
}
error_code cellKbSetCodeType(u32 port_no, u32 type)
{
cellKb.trace("cellKbSetCodeType(port_no=%d, type=%d)", port_no, type);
auto& handler = g_fxo->get<KeyboardHandlerBase>();
const auto init = handler.init.access();
if (!init)
return CELL_KB_ERROR_UNINITIALIZED;
if (port_no >= CELL_KB_MAX_KEYBOARDS || type > CELL_KB_CODETYPE_ASCII)
return CELL_KB_ERROR_INVALID_PARAMETER;
std::lock_guard<std::mutex> lock(handler.m_mutex);
keyboard_consumer& consumer = handler.GetConsumer(keyboard_consumer::identifier::cellKb);
if (port_no >= consumer.GetKeyboards().size())
return CELL_OK;
KbConfig& current_config = consumer.GetConfig(port_no);
current_config.code_type = type;
// can also return CELL_KB_ERROR_SYS_SETTING_FAILED
return CELL_OK;
}
error_code cellKbSetLEDStatus(u32 port_no, u8 led)
{
cellKb.trace("cellKbSetLEDStatus(port_no=%d, led=%d)", port_no, led);
auto& handler = g_fxo->get<KeyboardHandlerBase>();
const auto init = handler.init.access();
if (!init)
return CELL_KB_ERROR_UNINITIALIZED;
if (port_no >= CELL_KB_MAX_KEYBOARDS)
return CELL_KB_ERROR_INVALID_PARAMETER;
if (led > 7)
return CELL_KB_ERROR_SYS_SETTING_FAILED;
std::lock_guard<std::mutex> lock(handler.m_mutex);
keyboard_consumer& consumer = handler.GetConsumer(keyboard_consumer::identifier::cellKb);
if (port_no >= consumer.GetKeyboards().size() || consumer.GetInfo().status[port_no] != CELL_KB_STATUS_CONNECTED)
return CELL_KB_ERROR_FATAL;
KbData& current_data = consumer.GetData(port_no);
current_data.led = static_cast<u32>(led);
return CELL_OK;
}
error_code cellKbSetReadMode(u32 port_no, u32 rmode)
{
cellKb.trace("cellKbSetReadMode(port_no=%d, rmode=%d)", port_no, rmode);
auto& handler = g_fxo->get<KeyboardHandlerBase>();
const auto init = handler.init.access();
if (!init)
return CELL_KB_ERROR_UNINITIALIZED;
if (port_no >= CELL_KB_MAX_KEYBOARDS || rmode > CELL_KB_RMODE_PACKET)
return CELL_KB_ERROR_INVALID_PARAMETER;
std::lock_guard<std::mutex> lock(handler.m_mutex);
keyboard_consumer& consumer = handler.GetConsumer(keyboard_consumer::identifier::cellKb);
if (port_no >= consumer.GetKeyboards().size())
return CELL_OK;
KbConfig& current_config = consumer.GetConfig(port_no);
current_config.read_mode = rmode;
// Key repeat must be disabled in packet mode. But let's just always enable it otherwise.
Keyboard& keyboard = consumer.GetKeyboards()[port_no];
keyboard.m_key_repeat = rmode != CELL_KB_RMODE_PACKET;
// can also return CELL_KB_ERROR_SYS_SETTING_FAILED
return CELL_OK;
}
error_code cellKbGetConfiguration(u32 port_no, vm::ptr<CellKbConfig> config)
{
cellKb.trace("cellKbGetConfiguration(port_no=%d, config=*0x%x)", port_no, config);
auto& handler = g_fxo->get<KeyboardHandlerBase>();
const auto init = handler.init.access();
if (!init)
return CELL_KB_ERROR_UNINITIALIZED;
if (port_no >= CELL_KB_MAX_KEYBOARDS)
return CELL_KB_ERROR_INVALID_PARAMETER;
std::lock_guard<std::mutex> lock(handler.m_mutex);
keyboard_consumer& consumer = handler.GetConsumer(keyboard_consumer::identifier::cellKb);
const KbInfo& current_info = consumer.GetInfo();
if (port_no >= consumer.GetKeyboards().size() || current_info.status[port_no] != CELL_KB_STATUS_CONNECTED)
return not_an_error(CELL_KB_ERROR_NO_DEVICE);
// tests show that config is checked only after the device's status
if (!config)
return CELL_KB_ERROR_INVALID_PARAMETER;
const KbConfig& current_config = consumer.GetConfig(port_no);
config->arrange = current_config.arrange;
config->read_mode = current_config.read_mode;
config->code_type = current_config.code_type;
// can also return CELL_KB_ERROR_SYS_SETTING_FAILED
return CELL_OK;
}
void cellKb_init()
{
REG_FUNC(sys_io, cellKbInit);
REG_FUNC(sys_io, cellKbEnd);
REG_FUNC(sys_io, cellKbClearBuf);
REG_FUNC(sys_io, cellKbCnvRawCode);
REG_FUNC(sys_io, cellKbGetInfo);
REG_FUNC(sys_io, cellKbRead);
REG_FUNC(sys_io, cellKbSetCodeType);
REG_FUNC(sys_io, cellKbSetLEDStatus);
REG_FUNC(sys_io, cellKbSetReadMode);
REG_FUNC(sys_io, cellKbGetConfiguration);
}
| 17,901
|
C++
|
.cpp
| 413
| 40.72155
| 157
| 0.655069
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| false
| false
|
5,230
|
cellSysconf.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellSysconf.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
#include "cellSysutil.h"
#include "cellSysconf.h"
LOG_CHANNEL(cellSysconf);
template<>
void fmt_class_string<CellSysConfError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_SYSCONF_ERROR_PARAM);
}
return unknown;
});
}
error_code cellSysconfAbort()
{
cellSysconf.todo("cellSysconfAbort()");
return CELL_OK;
}
error_code cellSysconfOpen(u32 type, vm::ptr<CellSysconfCallback> func, vm::ptr<void> userdata, vm::ptr<void> extparam, u32 id)
{
cellSysconf.todo("cellSysconfOpen(type=%d, func=*0x%x, userdata=*0x%x, extparam=*0x%x, id=%d)", type, func, userdata, extparam, id);
sysutil_register_cb([=](ppu_thread& ppu) -> s32
{
func(ppu, CELL_OK, userdata);
return CELL_OK;
});
return CELL_OK;
}
error_code cellSysconfBtGetDeviceList(vm::ptr<CellSysconfBtDeviceList> deviceList)
{
cellSysconf.todo("cellSysconfBtGetDeviceList(deviceList=*0x%x)", deviceList);
if (!deviceList)
{
return CELL_SYSCONF_ERROR_PARAM;
}
return CELL_OK;
}
void cellSysutil_Sysconf_init()
{
REG_FUNC(cellSysutil, cellSysconfAbort);
REG_FUNC(cellSysutil, cellSysconfOpen);
}
DECLARE(ppu_module_manager::cellSysconf)("cellSysconfExtUtility", []()
{
REG_FUNC(cellSysconfExtUtility, cellSysconfBtGetDeviceList);
});
| 1,341
|
C++
|
.cpp
| 50
| 24.86
| 133
| 0.755869
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| false
| false
|
5,231
|
cellAudio.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellAudio.cpp
|
#include "stdafx.h"
#include "Emu/System.h"
#include "Emu/system_config.h"
#include "Emu/Cell/PPUModule.h"
#include "Emu/Cell/lv2/sys_process.h"
#include "Emu/Cell/lv2/sys_event.h"
#include "Emu/Cell/Modules/cellAudioOut.h"
#include "cellAudio.h"
#include "util/video_provider.h"
#include <cmath>
LOG_CHANNEL(cellAudio);
extern atomic_t<recording_mode> g_recording_mode;
extern void lv2_sleep(u64 timeout, ppu_thread* ppu = nullptr);
vm::gvar<char, AUDIO_PORT_OFFSET * AUDIO_PORT_COUNT> g_audio_buffer;
struct alignas(16) aligned_index_t
{
be_t<u64> index;
u8 pad[8];
};
vm::gvar<aligned_index_t, AUDIO_PORT_COUNT> g_audio_indices;
template <>
void fmt_class_string<CellAudioError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](CellAudioError value)
{
switch (value)
{
STR_CASE(CELL_AUDIO_ERROR_ALREADY_INIT);
STR_CASE(CELL_AUDIO_ERROR_AUDIOSYSTEM);
STR_CASE(CELL_AUDIO_ERROR_NOT_INIT);
STR_CASE(CELL_AUDIO_ERROR_PARAM);
STR_CASE(CELL_AUDIO_ERROR_PORT_FULL);
STR_CASE(CELL_AUDIO_ERROR_PORT_ALREADY_RUN);
STR_CASE(CELL_AUDIO_ERROR_PORT_NOT_OPEN);
STR_CASE(CELL_AUDIO_ERROR_PORT_NOT_RUN);
STR_CASE(CELL_AUDIO_ERROR_TRANS_EVENT);
STR_CASE(CELL_AUDIO_ERROR_PORT_OPEN);
STR_CASE(CELL_AUDIO_ERROR_SHAREDMEMORY);
STR_CASE(CELL_AUDIO_ERROR_MUTEX);
STR_CASE(CELL_AUDIO_ERROR_EVENT_QUEUE);
STR_CASE(CELL_AUDIO_ERROR_AUDIOSYSTEM_NOT_FOUND);
STR_CASE(CELL_AUDIO_ERROR_TAG_NOT_FOUND);
}
return unknown;
});
}
cell_audio_config::cell_audio_config()
{
raw = audio::get_raw_config();
}
void cell_audio_config::reset(bool backend_changed)
{
if (!backend || backend_changed)
{
backend.reset();
backend = Emu.GetCallbacks().get_audio();
}
cellAudio.notice("cellAudio initializing. Backend: %s", backend->GetName());
const AudioFreq freq = AudioFreq::FREQ_48K;
const AudioSampleSize sample_size = raw.convert_to_s16 ? AudioSampleSize::S16 : AudioSampleSize::FLOAT;
const auto& [req_ch_cnt, downmix] = AudioBackend::get_channel_count_and_downmixer(0); // CELL_AUDIO_OUT_PRIMARY
f64 cb_frame_len = 0.0;
u32 ch_cnt = 2;
audio_channel_layout ch_layout = audio_channel_layout::stereo;
if (backend->Open(raw.audio_device, freq, sample_size, req_ch_cnt, raw.channel_layout))
{
cb_frame_len = backend->GetCallbackFrameLen();
ch_cnt = backend->get_channels();
ch_layout = backend->get_channel_layout();
cellAudio.notice("Opened audio backend (sampling_rate=%d, sample_size=%d, channels=%d, layout=%s)", backend->get_sampling_rate(), backend->get_sample_size(), backend->get_channels(), backend->get_channel_layout());
}
else
{
cellAudio.error("Failed to open audio backend. Make sure that no other application is running that might block audio access (e.g. Netflix).");
}
audio_downmix = downmix;
backend_ch_cnt = ch_cnt;
backend_channel_layout = ch_layout;
audio_channels = static_cast<u32>(req_ch_cnt);
audio_sampling_rate = static_cast<u32>(freq);
audio_block_period = AUDIO_BUFFER_SAMPLES * 1'000'000 / audio_sampling_rate;
audio_sample_size = static_cast<u32>(sample_size);
audio_min_buffer_duration = cb_frame_len + u32{AUDIO_BUFFER_SAMPLES} * 2.0 / audio_sampling_rate; // Add 2 blocks to allow jitter compensation
audio_buffer_length = AUDIO_BUFFER_SAMPLES * audio_channels;
desired_buffer_duration = std::max(static_cast<s64>(audio_min_buffer_duration * 1000), raw.desired_buffer_duration) * 1000llu;
buffering_enabled = raw.buffering_enabled && raw.renderer != audio_renderer::null;
minimum_block_period = audio_block_period / 2;
maximum_block_period = (6 * audio_block_period) / 5;
desired_full_buffers = buffering_enabled ? static_cast<u32>(desired_buffer_duration / audio_block_period) + 3 : 2;
num_allocated_buffers = desired_full_buffers + EXTRA_AUDIO_BUFFERS;
fully_untouched_timeout = static_cast<u64>(audio_block_period) * 2;
partially_untouched_timeout = static_cast<u64>(audio_block_period) * 4;
const bool raw_time_stretching_enabled = buffering_enabled && raw.enable_time_stretching && (raw.time_stretching_threshold > 0);
time_stretching_enabled = raw_time_stretching_enabled;
time_stretching_threshold = raw.time_stretching_threshold / 100.0f;
// Warn if audio backend does not support all requested features
if (raw.buffering_enabled && !buffering_enabled)
{
cellAudio.error("Audio backend %s does not support buffering, this option will be ignored.", backend->GetName());
if (raw.enable_time_stretching)
{
cellAudio.error("Audio backend %s does not support time stretching, this option will be ignored.", backend->GetName());
}
}
}
audio_ringbuffer::audio_ringbuffer(cell_audio_config& _cfg)
: backend(_cfg.backend)
, cfg(_cfg)
, buf_sz(AUDIO_BUFFER_SAMPLES * _cfg.audio_channels)
{
// Initialize buffers
if (cfg.num_allocated_buffers > MAX_AUDIO_BUFFERS)
{
fmt::throw_exception("MAX_AUDIO_BUFFERS is too small");
}
for (u32 i = 0; i < cfg.num_allocated_buffers; i++)
{
buffer[i].reset(new float[buf_sz]{});
}
// Init audio dumper if enabled
if (cfg.raw.dump_to_file)
{
m_dump.Open(static_cast<AudioChannelCnt>(cfg.audio_channels), static_cast<AudioFreq>(cfg.audio_sampling_rate), AudioSampleSize::FLOAT);
}
// Configure resampler
resampler.set_params(static_cast<AudioChannelCnt>(cfg.audio_channels), static_cast<AudioFreq>(cfg.audio_sampling_rate));
resampler.set_tempo(RESAMPLER_MAX_FREQ_VAL);
const f64 buffer_dur_mult = [&]()
{
if (cfg.buffering_enabled)
{
return cfg.desired_buffer_duration / 1'000'000.0 + 0.02; // Add 20ms to buffer to keep buffering algorithm happy
}
return cfg.audio_min_buffer_duration;
}();
cb_ringbuf.set_buf_size(static_cast<u32>(cfg.backend_ch_cnt * cfg.audio_sampling_rate * cfg.audio_sample_size * buffer_dur_mult));
backend->SetWriteCallback(std::bind(&audio_ringbuffer::backend_write_callback, this, std::placeholders::_1, std::placeholders::_2));
backend->SetStateCallback(std::bind(&audio_ringbuffer::backend_state_callback, this, std::placeholders::_1));
}
audio_ringbuffer::~audio_ringbuffer()
{
if (get_backend_playing())
{
flush();
}
backend->Close();
}
f32 audio_ringbuffer::set_frequency_ratio(f32 new_ratio)
{
frequency_ratio = static_cast<f32>(resampler.set_tempo(new_ratio));
return frequency_ratio;
}
float* audio_ringbuffer::get_buffer(u32 num) const
{
AUDIT(num < cfg.num_allocated_buffers);
AUDIT(buffer[num]);
return buffer[num].get();
}
u32 audio_ringbuffer::backend_write_callback(u32 size, void *buf)
{
if (!backend_active.observe()) backend_active = true;
return static_cast<u32>(cb_ringbuf.pop(buf, size, true));
}
void audio_ringbuffer::backend_state_callback(AudioStateEvent event)
{
if (event == AudioStateEvent::DEFAULT_DEVICE_MAYBE_CHANGED)
{
backend_device_changed = true;
}
}
u64 audio_ringbuffer::get_timestamp()
{
return get_system_time();
}
float* audio_ringbuffer::get_current_buffer() const
{
return get_buffer(cur_pos);
}
u64 audio_ringbuffer::get_enqueued_samples() const
{
AUDIT(cfg.buffering_enabled);
const u64 ringbuf_samples = cb_ringbuf.get_used_size() / (cfg.audio_sample_size * cfg.backend_ch_cnt);
if (cfg.time_stretching_enabled)
{
return ringbuf_samples + resampler.samples_available();
}
return ringbuf_samples;
}
u64 audio_ringbuffer::get_enqueued_playtime() const
{
AUDIT(cfg.buffering_enabled);
return get_enqueued_samples() * 1'000'000 / cfg.audio_sampling_rate;
}
void audio_ringbuffer::enqueue(bool enqueue_silence, bool force)
{
AUDIT(cur_pos < cfg.num_allocated_buffers);
// Prepare buffer
static float silence_buffer[u32{AUDIO_MAX_CHANNELS_COUNT} * u32{AUDIO_BUFFER_SAMPLES}]{};
float* buf = silence_buffer;
if (!enqueue_silence)
{
buf = buffer[cur_pos].get();
cur_pos = (cur_pos + 1) % cfg.num_allocated_buffers;
}
if (!backend_active.observe() && !force)
{
// backend is not ready yet
return;
}
// Enqueue audio
if (cfg.time_stretching_enabled)
{
resampler.put_samples(buf, AUDIO_BUFFER_SAMPLES);
}
else
{
// Since time stretching step is skipped, we can commit to buffer directly
commit_data(buf, AUDIO_BUFFER_SAMPLES);
}
}
void audio_ringbuffer::enqueue_silence(u32 buf_count, bool force)
{
for (u32 i = 0; i < buf_count; i++)
{
enqueue(true, force);
}
}
void audio_ringbuffer::process_resampled_data()
{
if (!cfg.time_stretching_enabled) return;
const auto& [buffer, samples] = resampler.get_samples(static_cast<u32>(cb_ringbuf.get_free_size() / (cfg.audio_sample_size * cfg.backend_ch_cnt)));
commit_data(buffer, samples);
}
void audio_ringbuffer::commit_data(f32* buf, u32 sample_cnt)
{
const u32 sample_cnt_in = sample_cnt * cfg.audio_channels;
const u32 sample_cnt_out = sample_cnt * cfg.backend_ch_cnt;
// Dump audio if enabled
m_dump.WriteData(buf, sample_cnt_in * static_cast<u32>(AudioSampleSize::FLOAT));
// Record audio if enabled
if (g_recording_mode != recording_mode::stopped)
{
utils::video_provider& provider = g_fxo->get<utils::video_provider>();
provider.present_samples(reinterpret_cast<u8*>(buf), sample_cnt, cfg.audio_channels);
}
// Downmix if necessary
AudioBackend::downmix(sample_cnt_in, cfg.audio_channels, cfg.backend_channel_layout, buf, buf);
if (cfg.backend->get_convert_to_s16())
{
AudioBackend::convert_to_s16(sample_cnt_out, buf, buf);
}
cb_ringbuf.push(buf, sample_cnt_out * cfg.audio_sample_size);
}
void audio_ringbuffer::play()
{
if (playing)
{
return;
}
playing = true;
play_timestamp = get_timestamp();
backend->Play();
}
void audio_ringbuffer::flush()
{
backend->Pause();
cb_ringbuf.writer_flush();
resampler.flush();
backend_active = false;
playing = false;
if (frequency_ratio != RESAMPLER_MAX_FREQ_VAL)
{
frequency_ratio = set_frequency_ratio(RESAMPLER_MAX_FREQ_VAL);
}
}
u64 audio_ringbuffer::update(bool emu_is_paused)
{
// Check emulator pause state
if (emu_is_paused)
{
// Emulator paused
if (playing)
{
flush();
}
}
else
{
// Emulator unpaused
play();
}
// Prepare timestamp
const u64 timestamp = get_timestamp();
// Store and return timestamp
update_timestamp = timestamp;
return timestamp;
}
void audio_port::tag(s32 offset)
{
auto port_buf = get_vm_ptr(offset);
// This tag will be used to make sure that the game has finished writing the audio for the next audio period
// We use -0.0f in case games check if the buffer is empty. -0.0f == 0.0f evaluates to true, but std::signbit can be used to distinguish them
const f32 tag = -0.0f;
const u32 tag_first_pos = num_channels == 2 ? PORT_BUFFER_TAG_FIRST_2CH : PORT_BUFFER_TAG_FIRST_8CH;
const u32 tag_delta = num_channels == 2 ? PORT_BUFFER_TAG_DELTA_2CH : PORT_BUFFER_TAG_DELTA_8CH;
for (u32 tag_pos = tag_first_pos, tag_nr = 0; tag_nr < PORT_BUFFER_TAG_COUNT; tag_pos += tag_delta, tag_nr++)
{
port_buf[tag_pos] = tag;
last_tag_value[tag_nr] = -0.0f;
}
prev_touched_tag_nr = -1;
}
cell_audio_thread::cell_audio_thread(utils::serial& ar)
: cell_audio_thread()
{
ar(init);
if (!init)
{
return;
}
ar(key_count, event_period);
keys.resize(ar);
for (key_info& k : keys)
{
ar(k.start_period, k.flags, k.source);
k.port = lv2_event_queue::load_ptr(ar, k.port, "audio");
}
ar(ports);
}
void cell_audio_thread::save(utils::serial& ar)
{
ar(init);
if (!init)
{
return;
}
USING_SERIALIZATION_VERSION(cellAudio);
ar(key_count, event_period);
ar(keys.size());
for (const key_info& k : keys)
{
ar(k.start_period, k.flags, k.source);
lv2_event_queue::save_ptr(ar, k.port.get());
}
ar(ports);
}
std::tuple<u32, u32, u32, u32> cell_audio_thread::count_port_buffer_tags()
{
AUDIT(cfg.buffering_enabled);
u32 active = 0;
u32 in_progress = 0;
u32 untouched = 0;
u32 incomplete = 0;
for (audio_port& port : ports)
{
if (port.state != audio_port_state::started) continue;
active++;
auto port_buf = port.get_vm_ptr();
// Find the last tag that has been touched
const u32 tag_first_pos = port.num_channels == 2 ? PORT_BUFFER_TAG_FIRST_2CH : PORT_BUFFER_TAG_FIRST_8CH;
const u32 tag_delta = port.num_channels == 2 ? PORT_BUFFER_TAG_DELTA_2CH : PORT_BUFFER_TAG_DELTA_8CH;
u32 last_touched_tag_nr = port.prev_touched_tag_nr;
bool retouched = false;
for (u32 tag_pos = tag_first_pos, tag_nr = 0; tag_nr < PORT_BUFFER_TAG_COUNT; tag_pos += tag_delta, tag_nr++)
{
const f32 val = port_buf[tag_pos];
f32& last_val = port.last_tag_value[tag_nr];
if (val != last_val || (last_val == -0.0f && std::signbit(last_val) && !std::signbit(val)))
{
last_val = val;
retouched |= (tag_nr <= port.prev_touched_tag_nr) && port.prev_touched_tag_nr != umax;
last_touched_tag_nr = tag_nr;
}
}
// Decide whether the buffer is untouched, in progress, incomplete, or complete
if (last_touched_tag_nr == umax)
{
// no tag has been touched yet
untouched++;
}
else if (last_touched_tag_nr == PORT_BUFFER_TAG_COUNT - 1)
{
if (retouched)
{
// we retouched, so wait at least once more to make sure no more tags get touched
in_progress++;
}
// buffer has been completely filled
port.prev_touched_tag_nr = last_touched_tag_nr;
}
else if (last_touched_tag_nr == port.prev_touched_tag_nr)
{
if (retouched)
{
// we retouched, so wait at least once more to make sure no more tags get touched
in_progress++;
}
else
{
// hasn't been touched since the last call
incomplete++;
}
}
else
{
// the touched tag changed since the last call
in_progress++;
port.prev_touched_tag_nr = last_touched_tag_nr;
}
}
return std::make_tuple(active, in_progress, untouched, incomplete);
}
void cell_audio_thread::reset_ports(s32 offset)
{
// Memset buffer to 0 and tag
for (audio_port& port : ports)
{
if (port.state != audio_port_state::started) continue;
memset(port.get_vm_ptr(offset), 0, port.block_size() * sizeof(float));
if (cfg.buffering_enabled)
{
port.tag(offset);
}
}
}
void cell_audio_thread::advance(u64 timestamp)
{
ringbuffer->process_resampled_data();
std::unique_lock lock(mutex);
// update ports
reset_ports(0);
for (audio_port& port : ports)
{
if (port.state != audio_port_state::started) continue;
port.global_counter = m_counter;
port.active_counter++;
port.timestamp = timestamp;
port.cur_pos = port.position(1);
*port.index = port.cur_pos;
}
if (cfg.buffering_enabled)
{
// Calculate rolling average of enqueued playtime
m_average_playtime = cfg.period_average_alpha * ringbuffer->get_enqueued_playtime() + (1.0f - cfg.period_average_alpha) * m_average_playtime;
}
m_counter++;
m_last_period_end = timestamp;
m_dynamic_period = 0;
// send aftermix event (normal audio event)
std::array<std::shared_ptr<lv2_event_queue>, MAX_AUDIO_EVENT_QUEUES> queues;
u32 queue_count = 0;
event_period++;
for (const key_info& key_inf : keys)
{
if (key_inf.flags & CELL_AUDIO_EVENTFLAG_NOMIX)
{
continue;
}
if ((queues[queue_count] = key_inf.port))
{
u32 periods = 1;
if (key_inf.flags & CELL_AUDIO_EVENTFLAG_DECIMATE_2)
{
periods *= 2;
}
if (key_inf.flags & CELL_AUDIO_EVENTFLAG_DECIMATE_4)
{
// If both flags are set periods is set to x8
periods *= 4;
}
if ((event_period ^ key_inf.start_period) & (periods - 1))
{
// The time has not come for this key to receive event
queues[queue_count].reset();
continue;
}
event_sources[queue_count] = key_inf.source;
event_data3[queue_count] = (key_inf.flags & CELL_AUDIO_EVENTFLAG_BEFOREMIX) ? key_inf.source : 0;
queue_count++;
}
}
lock.unlock();
for (u32 i = 0; i < queue_count; i++)
{
lv2_obj::notify_all_t notify;
queues[i]->send(event_sources[i], CELL_AUDIO_EVENT_MIX, 0, event_data3[i]);
}
}
namespace audio
{
cell_audio_config::raw_config get_raw_config()
{
return
{
.audio_device = g_cfg.audio.audio_device,
.buffering_enabled = static_cast<bool>(g_cfg.audio.enable_buffering),
.desired_buffer_duration = g_cfg.audio.desired_buffer_duration,
.enable_time_stretching = static_cast<bool>(g_cfg.audio.enable_time_stretching),
.time_stretching_threshold = g_cfg.audio.time_stretching_threshold,
.convert_to_s16 = static_cast<bool>(g_cfg.audio.convert_to_s16),
.dump_to_file = static_cast<bool>(g_cfg.audio.dump_to_file),
.channel_layout = g_cfg.audio.channel_layout,
.renderer = g_cfg.audio.renderer,
.provider = g_cfg.audio.provider
};
}
void configure_audio(bool force_reset)
{
if (g_cfg.audio.provider != audio_provider::cell_audio)
{
return;
}
if (auto& g_audio = g_fxo->get<cell_audio>(); g_fxo->is_init<cell_audio>())
{
// Only reboot the audio renderer if a relevant setting changed
const cell_audio_config::raw_config new_raw = get_raw_config();
if (const cell_audio_config::raw_config raw = g_audio.cfg.raw;
force_reset ||
raw.audio_device != new_raw.audio_device ||
raw.desired_buffer_duration != new_raw.desired_buffer_duration ||
raw.buffering_enabled != new_raw.buffering_enabled ||
raw.time_stretching_threshold != new_raw.time_stretching_threshold ||
raw.enable_time_stretching != new_raw.enable_time_stretching ||
raw.convert_to_s16 != new_raw.convert_to_s16 ||
raw.renderer != new_raw.renderer ||
raw.dump_to_file != new_raw.dump_to_file)
{
std::lock_guard lock{g_audio.emu_cfg_upd_m};
g_audio.cfg.new_raw = new_raw;
g_audio.m_update_configuration = raw.renderer != new_raw.renderer ? audio_backend_update::ALL : audio_backend_update::PARAM;
}
}
}
}
void cell_audio_thread::update_config(bool backend_changed)
{
std::lock_guard lock(mutex);
// Clear ringbuffer
ringbuffer.reset();
// Reload config
cfg.reset(backend_changed);
// Allocate ringbuffer
ringbuffer.reset(new audio_ringbuffer(cfg));
// Reset thread state
reset_counters();
}
void cell_audio_thread::reset_counters()
{
m_counter = 0;
m_start_time = ringbuffer->get_timestamp();
m_last_period_end = m_start_time;
m_dynamic_period = 0;
m_audio_should_restart = true;
}
cell_audio_thread::cell_audio_thread()
{
}
void cell_audio_thread::operator()()
{
// Initialize loop variables (regardless of provider in order to initialize timestamps)
reset_counters();
if (cfg.raw.provider != audio_provider::cell_audio)
{
return;
}
// Init audio config
cfg.reset();
// Allocate ringbuffer
ringbuffer.reset(new audio_ringbuffer(cfg));
thread_ctrl::scoped_priority high_prio(+1);
while (Emu.IsPaused())
{
thread_ctrl::wait_for(5000);
}
u32 untouched_expected = 0;
u32 loop_count = 0;
// Main cellAudio loop
while (thread_ctrl::state() != thread_state::aborting)
{
loop_count++;
const audio_backend_update update_req = m_update_configuration.observe();
if (update_req != audio_backend_update::NONE)
{
cellAudio.warning("Updating cell_audio_thread configuration");
{
std::lock_guard lock{emu_cfg_upd_m};
cfg.raw = cfg.new_raw;
m_update_configuration = audio_backend_update::NONE;
}
update_config(update_req == audio_backend_update::ALL);
}
const bool emu_paused = Emu.IsPaused();
const u64 timestamp = ringbuffer->update(emu_paused || m_backend_failed);
if (emu_paused)
{
m_audio_should_restart = true;
ringbuffer->flush();
thread_ctrl::wait_for(10000);
continue;
}
// TODO: (no idea how much of this is already implemented)
// The hardware heartbeat interval of libaudio is ~5.3ms.
// As soon as one interval starts, libaudio waits for ~2.6ms (half of the interval) before it mixes the audio.
// There are 2 different types of games:
// - Normal games:
// Once the audio was mixed, we send the CELL_AUDIO_EVENT_MIX event and the game can process audio.
// - Latency sensitive games:
// If CELL_AUDIO_EVENTFLAG_BEFOREMIX is specified, we immediately send the CELL_AUDIO_EVENT_MIX event and the game can process audio.
// We then have to wait for a maximum of ~2.6ms for cellAudioSendAck and then mix immediately.
const u64 time_since_last_period = timestamp - m_last_period_end;
// Handle audio restart
if (m_audio_should_restart)
{
// align to 5.(3)ms on global clock - some games seem to prefer this
const s64 audio_period_alignment_delta = (timestamp - m_start_time) % cfg.audio_block_period;
if (audio_period_alignment_delta > cfg.period_comparison_margin)
{
thread_ctrl::wait_for(audio_period_alignment_delta - cfg.period_comparison_margin);
}
if (cfg.buffering_enabled)
{
// Restart algorithm
cellAudio.trace("restarting audio");
ringbuffer->enqueue_silence(cfg.desired_full_buffers, true);
finish_port_volume_stepping();
m_average_playtime = static_cast<f32>(ringbuffer->get_enqueued_playtime());
untouched_expected = 0;
}
m_audio_should_restart = false;
continue;
}
bool operational = ringbuffer->get_operational_status();
if (!operational && loop_count % 128 == 0)
{
update_config(true);
operational = ringbuffer->get_operational_status();
}
if (ringbuffer->device_changed())
{
cellAudio.warning("Default device changed, attempting to switch...");
update_config(false);
if (operational != ringbuffer->get_operational_status())
{
continue;
}
}
if (!m_backend_failed && !operational)
{
cellAudio.error("Backend stopped unexpectedly (likely device change). Attempting to recover...");
m_backend_failed = true;
}
else if (m_backend_failed && operational)
{
cellAudio.success("Backend recovered");
m_backend_failed = false;
}
if (!cfg.buffering_enabled)
{
const u64 period_end = (m_counter * cfg.audio_block_period) + m_start_time;
const s64 time_left = period_end - timestamp;
if (time_left > cfg.period_comparison_margin)
{
thread_ctrl::wait_for(time_left - cfg.period_comparison_margin);
continue;
}
}
else
{
const u64 enqueued_samples = ringbuffer->get_enqueued_samples();
const f32 frequency_ratio = ringbuffer->get_frequency_ratio();
const u64 enqueued_playtime = ringbuffer->get_enqueued_playtime();
const u64 enqueued_buffers = enqueued_samples / AUDIO_BUFFER_SAMPLES;
const auto tag_info = count_port_buffer_tags();
const u32 active_ports = std::get<0>(tag_info);
const u32 in_progress = std::get<1>(tag_info);
const u32 untouched = std::get<2>(tag_info);
const u32 incomplete = std::get<3>(tag_info);
// Ratio between the rolling average of the audio period, and the desired audio period
const f32 average_playtime_ratio = m_average_playtime / cfg.audio_buffer_length;
// Use the above average ratio to decide how much buffer we should be aiming for
f32 desired_duration_adjusted = cfg.desired_buffer_duration + (cfg.audio_block_period / 2.0f);
if (average_playtime_ratio < 1.0f)
{
desired_duration_adjusted /= std::max(average_playtime_ratio, 0.25f);
}
if (cfg.time_stretching_enabled)
{
// 1.0 means exactly as desired
// <1.0 means not as full as desired
// >1.0 means more full than desired
const f32 desired_duration_rate = enqueued_playtime / desired_duration_adjusted;
// update frequency ratio if necessary
if (desired_duration_rate < cfg.time_stretching_threshold)
{
const f32 normalized_desired_duration_rate = desired_duration_rate / cfg.time_stretching_threshold;
// change frequency ratio in steps
const f32 req_time_stretching_step = (normalized_desired_duration_rate + frequency_ratio) / 2.0f;
if (std::abs(req_time_stretching_step - frequency_ratio) > cfg.time_stretching_step)
{
ringbuffer->set_frequency_ratio(req_time_stretching_step);
}
}
else if (frequency_ratio != RESAMPLER_MAX_FREQ_VAL)
{
ringbuffer->set_frequency_ratio(RESAMPLER_MAX_FREQ_VAL);
}
}
// 1.0 means exactly as desired
// <1.0 means not as full as desired
// >1.0 means more full than desired
const f32 desired_duration_rate = enqueued_playtime / desired_duration_adjusted;
if (desired_duration_rate >= 1.0f)
{
// more full than desired
const f32 multiplier = 1.0f / desired_duration_rate;
m_dynamic_period = cfg.maximum_block_period - static_cast<u64>((cfg.maximum_block_period - cfg.audio_block_period) * multiplier);
}
else
{
// not as full as desired
const f32 multiplier = desired_duration_rate * desired_duration_rate; // quite aggressive, but helps more times than it hurts
m_dynamic_period = cfg.minimum_block_period + static_cast<u64>((cfg.audio_block_period - cfg.minimum_block_period) * multiplier);
}
const s64 time_left = m_dynamic_period - time_since_last_period;
if (time_left > cfg.period_comparison_margin)
{
thread_ctrl::wait_for(time_left - cfg.period_comparison_margin);
continue;
}
// Fast path for 0 ports active
if (active_ports == 0)
{
// no need to mix, just enqueue silence and advance time
cellAudio.trace("enqueuing silence: no active ports, enqueued_buffers=%llu", enqueued_buffers);
ringbuffer->enqueue_silence();
untouched_expected = 0;
advance(timestamp);
continue;
}
// Wait until buffers have been touched
//cellAudio.error("active=%u, in_progress=%u, untouched=%u, incomplete=%u", active_ports, in_progress, untouched, incomplete);
if (untouched > untouched_expected)
{
// Games may sometimes "skip" audio periods entirely if they're falling behind (a sort of "frameskip" for audio)
// As such, if the game doesn't touch buffers for too long we advance time hoping the game recovers
if (
(untouched == active_ports && time_since_last_period > cfg.fully_untouched_timeout) ||
(time_since_last_period > cfg.partially_untouched_timeout) || g_cfg.audio.disable_sampling_skip
)
{
// There's no audio in the buffers, simply advance time and hope the game recovers
cellAudio.trace("advancing time: untouched=%u/%u (expected=%u), enqueued_buffers=%llu", untouched, active_ports, untouched_expected, enqueued_buffers);
untouched_expected = untouched;
advance(timestamp);
continue;
}
cellAudio.trace("waiting: untouched=%u/%u (expected=%u), enqueued_buffers=%llu", untouched, active_ports, untouched_expected, enqueued_buffers);
thread_ctrl::wait_for(1000);
continue;
}
// Fast-path for when there is no audio in the buffers
if (untouched == active_ports)
{
// There's no audio in the buffers, simply advance time
cellAudio.trace("enqueuing silence: untouched=%u/%u (expected=%u), enqueued_buffers=%llu", untouched, active_ports, untouched_expected, enqueued_buffers);
ringbuffer->enqueue_silence();
untouched_expected = untouched;
advance(timestamp);
continue;
}
// Wait for buffer(s) to be completely filled
if (in_progress > 0)
{
cellAudio.trace("waiting: in_progress=%u/%u, enqueued_buffers=%u", in_progress, active_ports, enqueued_buffers);
thread_ctrl::wait_for(500);
continue;
}
//cellAudio.error("active=%u, untouched=%u, in_progress=%d, incomplete=%d, enqueued_buffers=%u", active_ports, untouched, in_progress, incomplete, enqueued_buffers);
// Store number of untouched buffers for future reference
untouched_expected = untouched;
// Log if we enqueued untouched/incomplete buffers
if (untouched > 0 || incomplete > 0)
{
cellAudio.trace("enqueueing: untouched=%u/%u (expected=%u), incomplete=%u/%u enqueued_buffers=%llu", untouched, active_ports, untouched_expected, incomplete, active_ports, enqueued_buffers);
}
}
// Mix
float* buf = ringbuffer->get_current_buffer();
switch (cfg.audio_channels)
{
case 2:
switch (cfg.audio_downmix)
{
case AudioChannelCnt::SURROUND_7_1:
mix<AudioChannelCnt::STEREO, AudioChannelCnt::SURROUND_7_1>(buf);
break;
case AudioChannelCnt::STEREO:
mix<AudioChannelCnt::STEREO, AudioChannelCnt::STEREO>(buf);
break;
case AudioChannelCnt::SURROUND_5_1:
mix<AudioChannelCnt::STEREO, AudioChannelCnt::SURROUND_5_1>(buf);
break;
}
break;
case 6:
switch (cfg.audio_downmix)
{
case AudioChannelCnt::SURROUND_7_1:
mix<AudioChannelCnt::SURROUND_5_1, AudioChannelCnt::SURROUND_7_1>(buf);
break;
case AudioChannelCnt::STEREO:
mix<AudioChannelCnt::SURROUND_5_1, AudioChannelCnt::STEREO>(buf);
break;
case AudioChannelCnt::SURROUND_5_1:
mix<AudioChannelCnt::SURROUND_5_1, AudioChannelCnt::SURROUND_5_1>(buf);
break;
}
break;
case 8:
switch (cfg.audio_downmix)
{
case AudioChannelCnt::SURROUND_7_1:
mix<AudioChannelCnt::SURROUND_7_1, AudioChannelCnt::SURROUND_7_1>(buf);
break;
case AudioChannelCnt::STEREO:
mix<AudioChannelCnt::SURROUND_7_1, AudioChannelCnt::STEREO>(buf);
break;
case AudioChannelCnt::SURROUND_5_1:
mix<AudioChannelCnt::SURROUND_7_1, AudioChannelCnt::SURROUND_5_1>(buf);
break;
}
break;
default:
fmt::throw_exception("Unsupported channel count in cell_audio_config: %d", cfg.audio_channels);
}
// Enqueue
ringbuffer->enqueue();
// Advance time
advance(timestamp);
}
// Destroy ringbuffer
ringbuffer.reset();
}
audio_port* cell_audio_thread::open_port()
{
for (u32 i = 0; i < AUDIO_PORT_COUNT; i++)
{
if (ports[i].state.compare_and_swap_test(audio_port_state::closed, audio_port_state::opened))
{
return &ports[i];
}
}
return nullptr;
}
template <AudioChannelCnt channels, AudioChannelCnt downmix>
void cell_audio_thread::mix(float* out_buffer, s32 offset)
{
AUDIT(out_buffer != nullptr);
constexpr u32 out_channels = static_cast<u32>(channels);
constexpr u32 out_buffer_sz = out_channels * AUDIO_BUFFER_SAMPLES;
const float master_volume = g_cfg.audio.volume / 100.0f;
// Reset out_buffer
std::memset(out_buffer, 0, out_buffer_sz * sizeof(float));
// mixing
for (audio_port& port : ports)
{
if (port.state != audio_port_state::started) continue;
auto buf = port.get_vm_ptr(offset);
static constexpr float minus_3db = 0.707f; // value taken from https://www.dolby.com/us/en/technologies/a-guide-to-dolby-metadata.pdf
float m = master_volume;
// part of cellAudioSetPortLevel functionality
// spread port volume changes over 13ms
auto step_volume = [master_volume, &m](audio_port& port)
{
const audio_port::level_set_t param = port.level_set.load();
if (param.inc != 0.0f)
{
port.level += param.inc;
const bool dec = param.inc < 0.0f;
if ((!dec && param.value - port.level <= 0.0f) || (dec && param.value - port.level >= 0.0f))
{
port.level = param.value;
port.level_set.compare_and_swap(param, { param.value, 0.0f });
}
}
m = port.level * master_volume;
};
if (port.num_channels == 2)
{
for (u32 out = 0, in = 0; out < out_buffer_sz; out += out_channels, in += 2)
{
step_volume(port);
const float left = buf[in + 0] * m;
const float right = buf[in + 1] * m;
out_buffer[out + 0] += left;
out_buffer[out + 1] += right;
}
}
else if (port.num_channels == 8)
{
for (u32 out = 0, in = 0; out < out_buffer_sz; out += out_channels, in += 8)
{
step_volume(port);
const float left = buf[in + 0] * m;
const float right = buf[in + 1] * m;
const float center = buf[in + 2] * m;
const float low_freq = buf[in + 3] * m;
const float side_left = buf[in + 4] * m;
const float side_right = buf[in + 5] * m;
const float rear_left = buf[in + 6] * m;
const float rear_right = buf[in + 7] * m;
if constexpr (downmix == AudioChannelCnt::STEREO)
{
// Don't mix in the lfe as per dolby specification and based on documentation
const float mid = center * 0.5f;
out_buffer[out + 0] += left * minus_3db + mid + side_left * 0.5f + rear_left * 0.5f;
out_buffer[out + 1] += right * minus_3db + mid + side_right * 0.5f + rear_right * 0.5f;
}
else if constexpr (downmix == AudioChannelCnt::SURROUND_5_1)
{
out_buffer[out + 0] += left;
out_buffer[out + 1] += right;
if constexpr (out_channels >= 6) // Only mix the surround channels into the output if surround output is configured
{
out_buffer[out + 2] += center;
out_buffer[out + 3] += low_freq;
if constexpr (out_channels == 6)
{
out_buffer[out + 4] += side_left + rear_left;
out_buffer[out + 5] += side_right + rear_right;
}
else // When using 7.1 ouput, out_buffer[out + 4] and out_buffer[out + 5] are the rear channels, so the side channels need to be mixed into [out + 6] and [out + 7]
{
out_buffer[out + 6] += side_left + rear_left;
out_buffer[out + 7] += side_right + rear_right;
}
}
}
else
{
out_buffer[out + 0] += left;
out_buffer[out + 1] += right;
if constexpr (out_channels >= 6) // Only mix the surround channels into the output if surround output is configured
{
out_buffer[out + 2] += center;
out_buffer[out + 3] += low_freq;
if constexpr (out_channels == 6)
{
out_buffer[out + 4] += side_left;
out_buffer[out + 5] += side_right;
}
else
{
out_buffer[out + 4] += rear_left;
out_buffer[out + 5] += rear_right;
out_buffer[out + 6] += side_left;
out_buffer[out + 7] += side_right;
}
}
}
}
}
else
{
fmt::throw_exception("Unknown channel count (port=%u, channel=%d)", port.number, port.num_channels);
}
}
}
void cell_audio_thread::finish_port_volume_stepping()
{
// part of cellAudioSetPortLevel functionality
for (audio_port& port : ports)
{
if (port.state != audio_port_state::started) continue;
const audio_port::level_set_t param = port.level_set.load();
port.level = param.value;
port.level_set.compare_and_swap(param, { param.value, 0.0f });
}
}
error_code cellAudioInit()
{
cellAudio.warning("cellAudioInit()");
auto& g_audio = g_fxo->get<cell_audio>();
std::lock_guard lock(g_audio.mutex);
if (g_audio.init)
{
return CELL_AUDIO_ERROR_ALREADY_INIT;
}
std::memset(g_audio_buffer.get_ptr(), 0, g_audio_buffer.alloc_size);
std::memset(g_audio_indices.get_ptr(), 0, g_audio_indices.alloc_size);
for (u32 i = 0; i < AUDIO_PORT_COUNT; i++)
{
g_audio.ports[i].number = i;
g_audio.ports[i].addr = g_audio_buffer + AUDIO_PORT_OFFSET * i;
g_audio.ports[i].index = (g_audio_indices + i).ptr(&aligned_index_t::index);
g_audio.ports[i].state = audio_port_state::closed;
}
g_audio.init = 1;
return CELL_OK;
}
error_code cellAudioQuit()
{
cellAudio.warning("cellAudioQuit()");
auto& g_audio = g_fxo->get<cell_audio>();
std::lock_guard lock(g_audio.mutex);
if (!g_audio.init)
{
return CELL_AUDIO_ERROR_NOT_INIT;
}
// NOTE: Do not clear event queues here. They are handled independently.
g_audio.init = 0;
return CELL_OK;
}
error_code cellAudioPortOpen(vm::ptr<CellAudioPortParam> audioParam, vm::ptr<u32> portNum)
{
cellAudio.warning("cellAudioPortOpen(audioParam=*0x%x, portNum=*0x%x)", audioParam, portNum);
auto& g_audio = g_fxo->get<cell_audio>();
if (!g_audio.init)
{
return CELL_AUDIO_ERROR_NOT_INIT;
}
if (!audioParam || !portNum)
{
return CELL_AUDIO_ERROR_PARAM;
}
const u64 num_channels = audioParam->nChannel;
const u64 num_blocks = audioParam->nBlock;
const u64 attr = audioParam->attr;
// check attributes
if (num_channels != CELL_AUDIO_PORT_2CH &&
num_channels != CELL_AUDIO_PORT_8CH &&
num_channels != 0)
{
return CELL_AUDIO_ERROR_PARAM;
}
if (num_blocks != 2 &&
num_blocks != 4 &&
num_blocks != CELL_AUDIO_BLOCK_8 &&
num_blocks != CELL_AUDIO_BLOCK_16 &&
num_blocks != CELL_AUDIO_BLOCK_32)
{
return CELL_AUDIO_ERROR_PARAM;
}
// list unsupported flags
if (attr & CELL_AUDIO_PORTATTR_BGM)
{
cellAudio.todo("cellAudioPortOpen(): CELL_AUDIO_PORTATTR_BGM");
}
if (attr & CELL_AUDIO_PORTATTR_OUT_SECONDARY)
{
cellAudio.todo("cellAudioPortOpen(): CELL_AUDIO_PORTATTR_OUT_SECONDARY");
}
if (attr & CELL_AUDIO_PORTATTR_OUT_PERSONAL_0)
{
cellAudio.todo("cellAudioPortOpen(): CELL_AUDIO_PORTATTR_OUT_PERSONAL_0");
}
if (attr & CELL_AUDIO_PORTATTR_OUT_PERSONAL_1)
{
cellAudio.todo("cellAudioPortOpen(): CELL_AUDIO_PORTATTR_OUT_PERSONAL_1");
}
if (attr & CELL_AUDIO_PORTATTR_OUT_PERSONAL_2)
{
cellAudio.todo("cellAudioPortOpen(): CELL_AUDIO_PORTATTR_OUT_PERSONAL_2");
}
if (attr & CELL_AUDIO_PORTATTR_OUT_PERSONAL_3)
{
cellAudio.todo("cellAudioPortOpen(): CELL_AUDIO_PORTATTR_OUT_PERSONAL_3");
}
if (attr & CELL_AUDIO_PORTATTR_OUT_NO_ROUTE)
{
cellAudio.todo("cellAudioPortOpen(): CELL_AUDIO_PORTATTR_OUT_NO_ROUTE");
}
if (attr & 0xFFFFFFFFF0EFEFEEULL)
{
cellAudio.todo("cellAudioPortOpen(): unknown attributes (0x%llx)", attr);
}
// Waiting for VSH and doing some more things
lv2_sleep(200);
std::lock_guard lock(g_audio.mutex);
if (!g_audio.init)
{
return CELL_AUDIO_ERROR_NOT_INIT;
}
// Open audio port
audio_port* port = g_audio.open_port();
if (!port)
{
return CELL_AUDIO_ERROR_PORT_FULL;
}
// TODO: is this necessary in any way? (Based on libaudio.prx)
//const u64 num_channels_non_0 = std::max<u64>(1, num_channels);
port->num_channels = ::narrow<u32>(num_channels);
port->num_blocks = ::narrow<u32>(num_blocks);
port->attr = attr;
port->size = ::narrow<u32>(num_channels * num_blocks * AUDIO_BUFFER_SAMPLES * sizeof(f32));
port->cur_pos = 0;
port->global_counter = g_audio.m_counter;
port->active_counter = 0;
port->timestamp = get_guest_system_time(g_audio.m_last_period_end);
if (attr & CELL_AUDIO_PORTATTR_INITLEVEL)
{
port->level = audioParam->level;
}
else
{
port->level = 1.0f;
}
port->level_set.store({ port->level, 0.0f });
if (port->level <= -1.0f)
{
return CELL_AUDIO_ERROR_PORT_OPEN;
}
*portNum = port->number;
return CELL_OK;
}
error_code cellAudioGetPortConfig(u32 portNum, vm::ptr<CellAudioPortConfig> portConfig)
{
cellAudio.trace("cellAudioGetPortConfig(portNum=%d, portConfig=*0x%x)", portNum, portConfig);
auto& g_audio = g_fxo->get<cell_audio>();
std::lock_guard lock(g_audio.mutex);
if (!g_audio.init)
{
return CELL_AUDIO_ERROR_NOT_INIT;
}
if (!portConfig || portNum >= AUDIO_PORT_COUNT)
{
return CELL_AUDIO_ERROR_PARAM;
}
audio_port& port = g_audio.ports[portNum];
portConfig->readIndexAddr = port.index;
switch (audio_port_state state = port.state.load())
{
case audio_port_state::closed:
portConfig->status = CELL_AUDIO_STATUS_CLOSE;
break;
case audio_port_state::opened:
portConfig->status = CELL_AUDIO_STATUS_READY;
break;
case audio_port_state::started:
portConfig->status = CELL_AUDIO_STATUS_RUN;
break;
default:
cellAudio.error("Invalid port state (%d: %d)", portNum, static_cast<u32>(state));
return CELL_AUDIO_ERROR_AUDIOSYSTEM;
}
portConfig->nChannel = port.num_channels;
portConfig->nBlock = port.num_blocks;
portConfig->portSize = port.size;
portConfig->portAddr = port.addr.addr();
return CELL_OK;
}
error_code cellAudioPortStart(u32 portNum)
{
cellAudio.warning("cellAudioPortStart(portNum=%d)", portNum);
auto& g_audio = g_fxo->get<cell_audio>();
if (!g_audio.init)
{
return CELL_AUDIO_ERROR_NOT_INIT;
}
if (portNum >= AUDIO_PORT_COUNT)
{
return CELL_AUDIO_ERROR_PARAM;
}
// Waiting for VSH
lv2_sleep(30);
std::lock_guard lock(g_audio.mutex);
if (!g_audio.init)
{
return CELL_AUDIO_ERROR_NOT_INIT;
}
switch (audio_port_state state = g_audio.ports[portNum].state.compare_and_swap(audio_port_state::opened, audio_port_state::started))
{
case audio_port_state::closed: return CELL_AUDIO_ERROR_PORT_NOT_OPEN;
case audio_port_state::started: return CELL_AUDIO_ERROR_PORT_ALREADY_RUN;
case audio_port_state::opened: return CELL_OK;
default: fmt::throw_exception("Invalid port state (%d: %d)", portNum, static_cast<u32>(state));
}
}
error_code cellAudioPortClose(u32 portNum)
{
cellAudio.warning("cellAudioPortClose(portNum=%d)", portNum);
auto& g_audio = g_fxo->get<cell_audio>();
std::lock_guard lock(g_audio.mutex);
if (!g_audio.init)
{
return CELL_AUDIO_ERROR_NOT_INIT;
}
if (portNum >= AUDIO_PORT_COUNT)
{
return CELL_AUDIO_ERROR_PARAM;
}
switch (audio_port_state state = g_audio.ports[portNum].state.exchange(audio_port_state::closed))
{
case audio_port_state::closed: return CELL_AUDIO_ERROR_PORT_NOT_OPEN;
case audio_port_state::started: return CELL_OK;
case audio_port_state::opened: return CELL_OK;
default: fmt::throw_exception("Invalid port state (%d: %d)", portNum, static_cast<u32>(state));
}
}
error_code cellAudioPortStop(u32 portNum)
{
cellAudio.warning("cellAudioPortStop(portNum=%d)", portNum);
auto& g_audio = g_fxo->get<cell_audio>();
std::lock_guard lock(g_audio.mutex);
if (!g_audio.init)
{
return CELL_AUDIO_ERROR_NOT_INIT;
}
if (portNum >= AUDIO_PORT_COUNT)
{
return CELL_AUDIO_ERROR_PARAM;
}
switch (audio_port_state state = g_audio.ports[portNum].state.compare_and_swap(audio_port_state::started, audio_port_state::opened))
{
case audio_port_state::closed: return CELL_AUDIO_ERROR_PORT_NOT_RUN;
case audio_port_state::started: return CELL_OK;
case audio_port_state::opened: return CELL_AUDIO_ERROR_PORT_NOT_RUN;
default: fmt::throw_exception("Invalid port state (%d: %d)", portNum, static_cast<u32>(state));
}
}
error_code cellAudioGetPortTimestamp(u32 portNum, u64 tag, vm::ptr<u64> stamp)
{
cellAudio.trace("cellAudioGetPortTimestamp(portNum=%d, tag=0x%llx, stamp=*0x%x)", portNum, tag, stamp);
auto& g_audio = g_fxo->get<cell_audio>();
std::lock_guard lock(g_audio.mutex);
if (!g_audio.init)
{
return CELL_AUDIO_ERROR_NOT_INIT;
}
if (portNum >= AUDIO_PORT_COUNT)
{
return CELL_AUDIO_ERROR_PARAM;
}
audio_port& port = g_audio.ports[portNum];
if (port.state == audio_port_state::closed)
{
return CELL_AUDIO_ERROR_PORT_NOT_OPEN;
}
if (port.global_counter < tag)
{
return CELL_AUDIO_ERROR_TAG_NOT_FOUND;
}
const u64 delta_tag = port.global_counter - tag;
const u64 delta_tag_stamp = delta_tag * g_audio.cfg.audio_block_period;
// Apparently no error is returned if stamp is null
*stamp = get_guest_system_time(port.timestamp - delta_tag_stamp);
return CELL_OK;
}
error_code cellAudioGetPortBlockTag(u32 portNum, u64 blockNo, vm::ptr<u64> tag)
{
cellAudio.trace("cellAudioGetPortBlockTag(portNum=%d, blockNo=0x%llx, tag=*0x%x)", portNum, blockNo, tag);
auto& g_audio = g_fxo->get<cell_audio>();
std::lock_guard lock(g_audio.mutex);
if (!g_audio.init)
{
return CELL_AUDIO_ERROR_NOT_INIT;
}
if (portNum >= AUDIO_PORT_COUNT)
{
return CELL_AUDIO_ERROR_PARAM;
}
audio_port& port = g_audio.ports[portNum];
if (port.state == audio_port_state::closed)
{
return CELL_AUDIO_ERROR_PORT_NOT_OPEN;
}
if (blockNo >= port.num_blocks)
{
return CELL_AUDIO_ERROR_PARAM;
}
// Apparently no error is returned if tag is null
*tag = port.global_counter + blockNo - port.cur_pos;
return CELL_OK;
}
error_code cellAudioSetPortLevel(u32 portNum, float level)
{
cellAudio.trace("cellAudioSetPortLevel(portNum=%d, level=%f)", portNum, level);
auto& g_audio = g_fxo->get<cell_audio>();
std::lock_guard lock(g_audio.mutex);
if (!g_audio.init)
{
return CELL_AUDIO_ERROR_NOT_INIT;
}
if (portNum >= AUDIO_PORT_COUNT)
{
return CELL_AUDIO_ERROR_PARAM;
}
audio_port& port = g_audio.ports[portNum];
if (port.state == audio_port_state::closed)
{
return CELL_AUDIO_ERROR_PORT_NOT_OPEN;
}
if (level >= 0.0f)
{
port.level_set.exchange({ level, (port.level - level) / 624.0f });
}
else
{
cellAudio.todo("cellAudioSetPortLevel(%d): negative level value (%f)", portNum, level);
}
return CELL_OK;
}
static error_code AudioCreateNotifyEventQueue(ppu_thread& ppu, vm::ptr<u32> id, vm::ptr<u64> key, u32 queue_type)
{
vm::var<sys_event_queue_attribute_t> attr;
attr->protocol = SYS_SYNC_FIFO;
attr->type = queue_type;
attr->name_u64 = 0;
for (u64 i = 0; i < MAX_AUDIO_EVENT_QUEUES; i++)
{
// Create an event queue "bruteforcing" an available key
const u64 key_value = 0x80004d494f323221ull + i;
// This originally reads from a global sdk value set by cellAudioInit
// So check initialization as well
const u32 queue_depth = g_fxo->get<cell_audio>().init && g_ps3_process_info.sdk_ver <= 0x35FFFF ? 2 : 8;
if (CellError res{sys_event_queue_create(ppu, id, attr, key_value, queue_depth) + 0u})
{
if (res != CELL_EEXIST)
{
return res;
}
}
else
{
*key = key_value;
return CELL_OK;
}
}
return CELL_AUDIO_ERROR_EVENT_QUEUE;
}
error_code cellAudioCreateNotifyEventQueue(ppu_thread& ppu, vm::ptr<u32> id, vm::ptr<u64> key)
{
cellAudio.warning("cellAudioCreateNotifyEventQueue(id=*0x%x, key=*0x%x)", id, key);
return AudioCreateNotifyEventQueue(ppu, id, key, SYS_PPU_QUEUE);
}
error_code cellAudioCreateNotifyEventQueueEx(ppu_thread& ppu, vm::ptr<u32> id, vm::ptr<u64> key, u32 iFlags)
{
cellAudio.warning("cellAudioCreateNotifyEventQueueEx(id=*0x%x, key=*0x%x, iFlags=0x%x)", id, key, iFlags);
if (iFlags & ~CELL_AUDIO_CREATEEVENTFLAG_SPU)
{
return CELL_AUDIO_ERROR_PARAM;
}
const u32 queue_type = (iFlags & CELL_AUDIO_CREATEEVENTFLAG_SPU) ? SYS_SPU_QUEUE : SYS_PPU_QUEUE;
return AudioCreateNotifyEventQueue(ppu, id, key, queue_type);
}
error_code AudioSetNotifyEventQueue(ppu_thread& ppu, u64 key, u32 iFlags)
{
auto& g_audio = g_fxo->get<cell_audio>();
if (!g_audio.init)
{
return CELL_AUDIO_ERROR_NOT_INIT;
}
// Waiting for VSH
lv2_sleep(20, &ppu);
// Dirty hack for sound: confirm the creation of _mxr000 event queue by _cellsurMixerMain thread
constexpr u64 c_mxr000 = 0x8000cafe0246030;
if (key == c_mxr000 || key == 0)
{
bool has_sur_mixer_thread = false;
for (usz count = 0; !lv2_event_queue::find(c_mxr000) && count < 100; count++)
{
if (has_sur_mixer_thread || idm::select<named_thread<ppu_thread>>([&](u32 id, named_thread<ppu_thread>& test_ppu)
{
// Confirm thread existence
if (id == ppu.id)
{
return false;
}
const auto ptr = test_ppu.ppu_tname.load();
if (!ptr)
{
return false;
}
return *ptr == "_cellsurMixerMain"sv;
}).ret)
{
has_sur_mixer_thread = true;
}
else
{
break;
}
if (ppu.is_stopped())
{
ppu.state += cpu_flag::again;
return {};
}
cellAudio.error("AudioSetNotifyEventQueue(): Waiting for _mxr000. x%d", count);
lv2_sleep(50'000, &ppu);
}
if (has_sur_mixer_thread && lv2_event_queue::find(c_mxr000))
{
key = c_mxr000;
}
}
std::lock_guard lock(g_audio.mutex);
if (!g_audio.init)
{
return CELL_AUDIO_ERROR_NOT_INIT;
}
auto q = lv2_event_queue::find(key);
if (!q)
{
return CELL_AUDIO_ERROR_TRANS_EVENT;
}
for (auto i = g_audio.keys.cbegin(); i != g_audio.keys.cend();) // check for duplicates
{
if (i->port == q)
{
return CELL_AUDIO_ERROR_TRANS_EVENT;
}
if (!lv2_obj::check(i->port))
{
// Cleanup, avoid cases where there are multiple ports with the same key
i = g_audio.keys.erase(i);
}
else
{
i++;
}
}
// Set unique source associated with the key
g_audio.keys.push_back
({
.start_period = g_audio.event_period,
.flags = iFlags,
.source = ((process_getpid() + u64{}) << 32) + lv2_event_port::id_base + (g_audio.key_count++ * lv2_event_port::id_step),
.ack_timestamp = 0,
.port = std::move(q)
});
g_audio.key_count %= lv2_event_port::id_count;
return CELL_OK;
}
error_code cellAudioSetNotifyEventQueue(ppu_thread& ppu, u64 key)
{
ppu.state += cpu_flag::wait;
cellAudio.warning("cellAudioSetNotifyEventQueue(key=0x%llx)", key);
return AudioSetNotifyEventQueue(ppu, key, 0);
}
error_code cellAudioSetNotifyEventQueueEx(ppu_thread& ppu, u64 key, u32 iFlags)
{
ppu.state += cpu_flag::wait;
cellAudio.todo("cellAudioSetNotifyEventQueueEx(key=0x%llx, iFlags=0x%x)", key, iFlags);
if (iFlags & (~0u >> 5))
{
return CELL_AUDIO_ERROR_PARAM;
}
return AudioSetNotifyEventQueue(ppu, key, iFlags);
}
error_code AudioRemoveNotifyEventQueue(u64 key, u32 iFlags)
{
auto& g_audio = g_fxo->get<cell_audio>();
std::lock_guard lock(g_audio.mutex);
if (!g_audio.init)
{
return CELL_AUDIO_ERROR_NOT_INIT;
}
for (auto i = g_audio.keys.cbegin(); i != g_audio.keys.cend(); i++)
{
if (lv2_obj::check(i->port) && i->port->key == key)
{
if (i->flags != iFlags)
{
break;
}
g_audio.keys.erase(i);
return CELL_OK;
}
}
return CELL_AUDIO_ERROR_TRANS_EVENT;
}
error_code cellAudioRemoveNotifyEventQueue(u64 key)
{
cellAudio.warning("cellAudioRemoveNotifyEventQueue(key=0x%llx)", key);
return AudioRemoveNotifyEventQueue(key, 0);
}
error_code cellAudioRemoveNotifyEventQueueEx(u64 key, u32 iFlags)
{
cellAudio.todo("cellAudioRemoveNotifyEventQueueEx(key=0x%llx, iFlags=0x%x)", key, iFlags);
if (iFlags & (~0u >> 5))
{
return CELL_AUDIO_ERROR_PARAM;
}
return AudioRemoveNotifyEventQueue(key, iFlags);
}
error_code cellAudioAddData(u32 portNum, vm::ptr<float> src, u32 samples, float volume)
{
cellAudio.trace("cellAudioAddData(portNum=%d, src=*0x%x, samples=%d, volume=%f)", portNum, src, samples, volume);
auto& g_audio = g_fxo->get<cell_audio>();
std::unique_lock lock(g_audio.mutex);
if (!g_audio.init)
{
return CELL_AUDIO_ERROR_NOT_INIT;
}
if (portNum >= AUDIO_PORT_COUNT || !src || !src.aligned() || samples != CELL_AUDIO_BLOCK_SAMPLES)
{
return CELL_AUDIO_ERROR_PARAM;
}
const audio_port& port = g_audio.ports[portNum];
const auto dst = port.get_vm_ptr();
lock.unlock();
volume = std::isfinite(volume) ? std::clamp(volume, -16.f, 16.f) : 0.f;
for (u32 i = 0; i < samples * port.num_channels; i++)
{
dst[i] += src[i] * volume; // mix all channels
}
return CELL_OK;
}
error_code cellAudioAdd2chData(u32 portNum, vm::ptr<float> src, u32 samples, float volume)
{
cellAudio.trace("cellAudioAdd2chData(portNum=%d, src=*0x%x, samples=%d, volume=%f)", portNum, src, samples, volume);
auto& g_audio = g_fxo->get<cell_audio>();
std::unique_lock lock(g_audio.mutex);
if (!g_audio.init)
{
return CELL_AUDIO_ERROR_NOT_INIT;
}
if (portNum >= AUDIO_PORT_COUNT || !src || !src.aligned() || samples != CELL_AUDIO_BLOCK_SAMPLES)
{
return CELL_AUDIO_ERROR_PARAM;
}
const audio_port& port = g_audio.ports[portNum];
const auto dst = port.get_vm_ptr();
lock.unlock();
volume = std::isfinite(volume) ? std::clamp(volume, -16.f, 16.f) : 0.f;
if (port.num_channels == 2)
{
for (u32 i = 0; i < samples; i++)
{
dst[i * 2 + 0] += src[i * 2 + 0] * volume; // mix L ch
dst[i * 2 + 1] += src[i * 2 + 1] * volume; // mix R ch
}
}
else if (port.num_channels == 8)
{
for (u32 i = 0; i < samples; i++)
{
dst[i * 8 + 0] += src[i * 2 + 0] * volume; // mix L ch
dst[i * 8 + 1] += src[i * 2 + 1] * volume; // mix R ch
//dst[i * 8 + 2] += 0.0f; // center
//dst[i * 8 + 3] += 0.0f; // LFE
//dst[i * 8 + 4] += 0.0f; // rear L
//dst[i * 8 + 5] += 0.0f; // rear R
//dst[i * 8 + 6] += 0.0f; // side L
//dst[i * 8 + 7] += 0.0f; // side R
}
}
else
{
cellAudio.error("cellAudioAdd2chData(portNum=%d): invalid port.channel value (%d)", portNum, port.num_channels);
}
return CELL_OK;
}
error_code cellAudioAdd6chData(u32 portNum, vm::ptr<float> src, float volume)
{
cellAudio.trace("cellAudioAdd6chData(portNum=%d, src=*0x%x, volume=%f)", portNum, src, volume);
auto& g_audio = g_fxo->get<cell_audio>();
std::unique_lock lock(g_audio.mutex);
if (!g_audio.init)
{
return CELL_AUDIO_ERROR_NOT_INIT;
}
if (portNum >= AUDIO_PORT_COUNT || !src || !src.aligned())
{
return CELL_AUDIO_ERROR_PARAM;
}
const audio_port& port = g_audio.ports[portNum];
const auto dst = port.get_vm_ptr();
lock.unlock();
volume = std::isfinite(volume) ? std::clamp(volume, -16.f, 16.f) : 0.f;
if (port.num_channels == 8)
{
for (u32 i = 0; i < CELL_AUDIO_BLOCK_SAMPLES; i++)
{
// Channel order in src is Front Left, Center, Front Right, Surround Left, Surround Right, LFE
dst[i * 8 + 0] += src[i * 6 + 0] * volume; // mix L ch
dst[i * 8 + 1] += src[i * 6 + 2] * volume; // mix R ch
dst[i * 8 + 2] += src[i * 6 + 1] * volume; // mix center
dst[i * 8 + 3] += src[i * 6 + 5] * volume; // mix LFE
dst[i * 8 + 4] += src[i * 6 + 3] * volume; // mix rear L
dst[i * 8 + 5] += src[i * 6 + 4] * volume; // mix rear R
//dst[i * 8 + 6] += 0.0f; // side L
//dst[i * 8 + 7] += 0.0f; // side R
}
}
else
{
cellAudio.error("cellAudioAdd6chData(portNum=%d): invalid port.channel value (%d)", portNum, port.num_channels);
}
return CELL_OK;
}
error_code cellAudioMiscSetAccessoryVolume(u32 devNum, float volume)
{
cellAudio.todo("cellAudioMiscSetAccessoryVolume(devNum=%d, volume=%f)", devNum, volume);
auto& g_audio = g_fxo->get<cell_audio>();
std::unique_lock lock(g_audio.mutex);
if (!g_audio.init)
{
return CELL_AUDIO_ERROR_NOT_INIT;
}
// TODO
return CELL_OK;
}
error_code cellAudioSendAck(u64 data3)
{
cellAudio.trace("cellAudioSendAck(data3=0x%llx)", data3);
auto& g_audio = g_fxo->get<cell_audio>();
std::unique_lock lock(g_audio.mutex);
if (!g_audio.init)
{
return CELL_AUDIO_ERROR_NOT_INIT;
}
// TODO: error checks
for (cell_audio_thread::key_info& k : g_audio.keys)
{
if (k.source == data3)
{
k.ack_timestamp = get_system_time();
break;
}
}
return CELL_OK;
}
error_code cellAudioSetPersonalDevice(s32 iPersonalStream, s32 iDevice)
{
cellAudio.todo("cellAudioSetPersonalDevice(iPersonalStream=%d, iDevice=%d)", iPersonalStream, iDevice);
auto& g_audio = g_fxo->get<cell_audio>();
std::unique_lock lock(g_audio.mutex);
if (!g_audio.init)
{
return CELL_AUDIO_ERROR_NOT_INIT;
}
if (iPersonalStream < 0 || iPersonalStream >= 4 ||
(iDevice != CELL_AUDIO_PERSONAL_DEVICE_PRIMARY && (iDevice < 0 || iDevice >= 5)))
{
return CELL_AUDIO_ERROR_PARAM;
}
// TODO
return CELL_OK;
}
error_code cellAudioUnsetPersonalDevice(s32 iPersonalStream)
{
cellAudio.todo("cellAudioUnsetPersonalDevice(iPersonalStream=%d)", iPersonalStream);
auto& g_audio = g_fxo->get<cell_audio>();
std::unique_lock lock(g_audio.mutex);
if (!g_audio.init)
{
return CELL_AUDIO_ERROR_NOT_INIT;
}
if (iPersonalStream < 0 || iPersonalStream >= 4)
{
return CELL_AUDIO_ERROR_PARAM;
}
// TODO
return CELL_OK;
}
DECLARE(ppu_module_manager::cellAudio)("cellAudio", []()
{
// Private variables
REG_VAR(cellAudio, g_audio_buffer).flag(MFF_HIDDEN);
REG_VAR(cellAudio, g_audio_indices).flag(MFF_HIDDEN);
REG_FUNC(cellAudio, cellAudioInit);
REG_FUNC(cellAudio, cellAudioPortClose);
REG_FUNC(cellAudio, cellAudioPortStop);
REG_FUNC(cellAudio, cellAudioGetPortConfig);
REG_FUNC(cellAudio, cellAudioPortStart);
REG_FUNC(cellAudio, cellAudioQuit);
REG_FUNC(cellAudio, cellAudioPortOpen);
REG_FUNC(cellAudio, cellAudioSetPortLevel);
REG_FUNC(cellAudio, cellAudioCreateNotifyEventQueue);
REG_FUNC(cellAudio, cellAudioCreateNotifyEventQueueEx);
REG_FUNC(cellAudio, cellAudioMiscSetAccessoryVolume);
REG_FUNC(cellAudio, cellAudioSetNotifyEventQueue);
REG_FUNC(cellAudio, cellAudioSetNotifyEventQueueEx);
REG_FUNC(cellAudio, cellAudioGetPortTimestamp);
REG_FUNC(cellAudio, cellAudioAdd2chData);
REG_FUNC(cellAudio, cellAudioAdd6chData);
REG_FUNC(cellAudio, cellAudioAddData);
REG_FUNC(cellAudio, cellAudioGetPortBlockTag);
REG_FUNC(cellAudio, cellAudioRemoveNotifyEventQueue);
REG_FUNC(cellAudio, cellAudioRemoveNotifyEventQueueEx);
REG_FUNC(cellAudio, cellAudioSendAck);
REG_FUNC(cellAudio, cellAudioSetPersonalDevice);
REG_FUNC(cellAudio, cellAudioUnsetPersonalDevice);
});
| 55,531
|
C++
|
.cpp
| 1,685
| 29.940653
| 216
| 0.700331
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| false
| false
|
5,232
|
cellRtcAlarm.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellRtcAlarm.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
LOG_CHANNEL(cellRtcAlarm);
error_code cellRtcAlarmRegister()
{
UNIMPLEMENTED_FUNC(cellRtcAlarm);
return CELL_OK;
}
error_code cellRtcAlarmUnregister()
{
UNIMPLEMENTED_FUNC(cellRtcAlarm);
return CELL_OK;
}
error_code cellRtcAlarmNotification()
{
UNIMPLEMENTED_FUNC(cellRtcAlarm);
return CELL_OK;
}
error_code cellRtcAlarmStopRunning()
{
UNIMPLEMENTED_FUNC(cellRtcAlarm);
return CELL_OK;
}
error_code cellRtcAlarmGetStatus()
{
UNIMPLEMENTED_FUNC(cellRtcAlarm);
return CELL_OK;
}
DECLARE(ppu_module_manager::cellRtcAlarm)("cellRtcAlarm", []()
{
REG_FUNC(cellRtcAlarm, cellRtcAlarmRegister);
REG_FUNC(cellRtcAlarm, cellRtcAlarmUnregister);
REG_FUNC(cellRtcAlarm, cellRtcAlarmNotification);
REG_FUNC(cellRtcAlarm, cellRtcAlarmStopRunning);
REG_FUNC(cellRtcAlarm, cellRtcAlarmGetStatus);
});
| 860
|
C++
|
.cpp
| 36
| 22.277778
| 62
| 0.822521
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| true
| false
| false
| true
| false
| false
|
5,233
|
cellPhotoExport.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellPhotoExport.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
#include "Emu/IdManager.h"
#include "Emu/VFS.h"
#include "Utilities/StrUtil.h"
#include "cellSysutil.h"
LOG_CHANNEL(cellPhotoExport);
// Return Codes
enum CellPhotoExportError : u32
{
CELL_PHOTO_EXPORT_UTIL_ERROR_BUSY = 0x8002c201,
CELL_PHOTO_EXPORT_UTIL_ERROR_INTERNAL = 0x8002c202,
CELL_PHOTO_EXPORT_UTIL_ERROR_PARAM = 0x8002c203,
CELL_PHOTO_EXPORT_UTIL_ERROR_ACCESS_ERROR = 0x8002c204,
CELL_PHOTO_EXPORT_UTIL_ERROR_DB_INTERNAL = 0x8002c205,
CELL_PHOTO_EXPORT_UTIL_ERROR_DB_REGIST = 0x8002c206,
CELL_PHOTO_EXPORT_UTIL_ERROR_SET_META = 0x8002c207,
CELL_PHOTO_EXPORT_UTIL_ERROR_FLUSH_META = 0x8002c208,
CELL_PHOTO_EXPORT_UTIL_ERROR_MOVE = 0x8002c209,
CELL_PHOTO_EXPORT_UTIL_ERROR_INITIALIZE = 0x8002c20a,
};
template<>
void fmt_class_string<CellPhotoExportError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_PHOTO_EXPORT_UTIL_ERROR_BUSY);
STR_CASE(CELL_PHOTO_EXPORT_UTIL_ERROR_INTERNAL);
STR_CASE(CELL_PHOTO_EXPORT_UTIL_ERROR_PARAM);
STR_CASE(CELL_PHOTO_EXPORT_UTIL_ERROR_ACCESS_ERROR);
STR_CASE(CELL_PHOTO_EXPORT_UTIL_ERROR_DB_INTERNAL);
STR_CASE(CELL_PHOTO_EXPORT_UTIL_ERROR_DB_REGIST);
STR_CASE(CELL_PHOTO_EXPORT_UTIL_ERROR_SET_META);
STR_CASE(CELL_PHOTO_EXPORT_UTIL_ERROR_FLUSH_META);
STR_CASE(CELL_PHOTO_EXPORT_UTIL_ERROR_MOVE);
STR_CASE(CELL_PHOTO_EXPORT_UTIL_ERROR_INITIALIZE);
}
return unknown;
});
}
enum
{
CELL_PHOTO_EXPORT_UTIL_VERSION_CURRENT = 0
};
enum
{
CELL_PHOTO_EXPORT_UTIL_HDD_PATH_MAX = 1055,
CELL_PHOTO_EXPORT_UTIL_PHOTO_TITLE_MAX_LENGTH = 64,
CELL_PHOTO_EXPORT_UTIL_GAME_TITLE_MAX_LENGTH = 64,
CELL_PHOTO_EXPORT_UTIL_GAME_COMMENT_MAX_SIZE = 1024,
};
struct CellPhotoExportSetParam
{
vm::bptr<char> photo_title;
vm::bptr<char> game_title;
vm::bptr<char> game_comment;
vm::bptr<void> reserved;
};
using CellPhotoExportUtilFinishCallback = void(s32 result, vm::ptr<void> userdata);
struct photo_export
{
atomic_t<s32> progress = 0; // 0x0-0xFFFF for 0-100%
};
bool check_photo_path(const std::string& file_path)
{
if (file_path.size() >= CELL_PHOTO_EXPORT_UTIL_HDD_PATH_MAX)
{
return false;
}
for (char c : file_path)
{
if (!((c >= 'a' && c <= 'z') ||
(c >= 'A' && c <= 'Z') ||
(c >= '0' && c <= '9') ||
c == '-' || c == '_' ||
c == '/' || c == '.'))
{
return false;
}
}
if (!file_path.starts_with("/dev_hdd0"sv) &&
!file_path.starts_with("/dev_bdvd"sv) &&
!file_path.starts_with("/dev_hdd1"sv))
{
return false;
}
if (file_path.find(".."sv) != umax)
{
return false;
}
return true;
}
std::string get_available_photo_path(const std::string& filename)
{
const std::string photo_dir = "/dev_hdd0/photo/";
std::string dst_path = vfs::get(photo_dir + filename);
// Do not overwrite existing files. Add a suffix instead.
for (u32 i = 0; fs::exists(dst_path); i++)
{
const std::string suffix = fmt::format("_%d", i);
std::string new_filename = filename;
if (const usz pos = new_filename.find_last_of('.'); pos != std::string::npos)
{
new_filename.insert(pos, suffix);
}
else
{
new_filename.append(suffix);
}
dst_path = vfs::get(photo_dir + new_filename);
}
return dst_path;
}
error_code cellPhotoInitialize(s32 version, u32 container, vm::ptr<CellPhotoExportUtilFinishCallback> funcFinish, vm::ptr<void> userdata)
{
cellPhotoExport.notice("cellPhotoInitialize(version=%d, container=%d, funcFinish=*0x%x, userdata=*0x%x)", version, container, funcFinish, userdata);
if (version != CELL_PHOTO_EXPORT_UTIL_VERSION_CURRENT)
{
return CELL_PHOTO_EXPORT_UTIL_ERROR_PARAM;
}
if (container != 0xfffffffe)
{
// TODO
}
if (!funcFinish)
{
return CELL_PHOTO_EXPORT_UTIL_ERROR_PARAM;
}
sysutil_register_cb([=](ppu_thread& ppu) -> s32
{
funcFinish(ppu, CELL_OK, userdata);
return CELL_OK;
});
return CELL_OK;
}
error_code cellPhotoFinalize(vm::ptr<CellPhotoExportUtilFinishCallback> funcFinish, vm::ptr<void> userdata)
{
cellPhotoExport.notice("cellPhotoFinalize(funcFinish=*0x%x, userdata=*0x%x)", funcFinish, userdata);
if (!funcFinish)
{
return CELL_PHOTO_EXPORT_UTIL_ERROR_PARAM;
}
sysutil_register_cb([=](ppu_thread& ppu) -> s32
{
funcFinish(ppu, CELL_OK, userdata);
return CELL_OK;
});
return CELL_OK;
}
error_code cellPhotoRegistFromFile(vm::cptr<char> path, vm::cptr<char> photo_title, vm::cptr<char> game_title, vm::cptr<char> game_comment, vm::ptr<CellPhotoExportUtilFinishCallback> funcFinish, vm::ptr<void> userdata)
{
cellPhotoExport.todo("cellPhotoRegistFromFile(path=%s, photo_title=%s, game_title=%s, game_comment=%s, funcFinish=*0x%x, userdata=*0x%x)", path, photo_title, game_title, game_comment, funcFinish, userdata);
if (!path || !funcFinish)
{
return CELL_PHOTO_EXPORT_UTIL_ERROR_PARAM;
}
const std::string file_path = path.get_ptr();
if (!check_photo_path(file_path))
{
return { CELL_PHOTO_EXPORT_UTIL_ERROR_PARAM, file_path };
}
const std::string filename = file_path.substr(file_path.find_last_of('/') + 1);
if (filename.empty())
{
return { CELL_PHOTO_EXPORT_UTIL_ERROR_PARAM, "filename empty" };
}
sysutil_register_cb([=](ppu_thread& ppu) -> s32
{
auto& pexp = g_fxo->get<photo_export>();
pexp.progress = 0; // 0%
const std::string src_path = vfs::get(file_path);
const std::string dst_path = get_available_photo_path(filename);
cellPhotoExport.notice("Copying file from '%s' to '%s'", file_path, dst_path);
// TODO: We ignore metadata for now
if (!fs::create_path(fs::get_parent_dir(dst_path)) || !fs::copy_file(src_path, dst_path, false))
{
// TODO: find out which error is used
cellPhotoExport.error("Failed to copy file from '%s' to '%s' (%s)", src_path, dst_path, fs::g_tls_error);
funcFinish(ppu, CELL_PHOTO_EXPORT_UTIL_ERROR_MOVE, userdata);
return CELL_OK;
}
if (file_path.starts_with("/dev_hdd0"sv))
{
cellPhotoExport.notice("Removing file '%s'", src_path);
if (!fs::remove_file(src_path))
{
// TODO: find out if an error is used here
cellPhotoExport.error("Failed to remove file '%s' (%s)", src_path, fs::g_tls_error);
}
}
// TODO: track progress during file copy
pexp.progress = 0xFFFF; // 100%
funcFinish(ppu, CELL_OK, userdata);
return CELL_OK;
});
return CELL_OK;
}
error_code cellPhotoExportInitialize(u32 version, u32 container, vm::ptr<CellPhotoExportUtilFinishCallback> funcFinish, vm::ptr<void> userdata)
{
cellPhotoExport.notice("cellPhotoExportInitialize(version=0x%x, container=0x%x, funcFinish=*0x%x, userdata=*0x%x)", version, container, funcFinish, userdata);
if (version != CELL_PHOTO_EXPORT_UTIL_VERSION_CURRENT)
{
return CELL_PHOTO_EXPORT_UTIL_ERROR_PARAM;
}
if (container != 0xfffffffe)
{
// TODO
}
if (!funcFinish)
{
return CELL_PHOTO_EXPORT_UTIL_ERROR_PARAM;
}
sysutil_register_cb([=](ppu_thread& ppu) -> s32
{
funcFinish(ppu, CELL_OK, userdata);
return CELL_OK;
});
return CELL_OK;
}
error_code cellPhotoExportInitialize2(u32 version, vm::ptr<CellPhotoExportUtilFinishCallback> funcFinish, vm::ptr<void> userdata)
{
cellPhotoExport.notice("cellPhotoExportInitialize2(version=0x%x, funcFinish=*0x%x, userdata=*0x%x)", version, funcFinish, userdata);
if (version != CELL_PHOTO_EXPORT_UTIL_VERSION_CURRENT)
{
return CELL_PHOTO_EXPORT_UTIL_ERROR_PARAM;
}
if (!funcFinish)
{
return CELL_PHOTO_EXPORT_UTIL_ERROR_PARAM;
}
sysutil_register_cb([=](ppu_thread& ppu) -> s32
{
funcFinish(ppu, CELL_OK, userdata);
return CELL_OK;
});
return CELL_OK;
}
error_code cellPhotoExportFinalize(vm::ptr<CellPhotoExportUtilFinishCallback> funcFinish, vm::ptr<void> userdata)
{
cellPhotoExport.notice("cellPhotoExportFinalize(funcFinish=*0x%x, userdata=*0x%x)", funcFinish, userdata);
if (!funcFinish)
{
return CELL_PHOTO_EXPORT_UTIL_ERROR_PARAM;
}
sysutil_register_cb([=](ppu_thread& ppu) -> s32
{
funcFinish(ppu, CELL_OK, userdata);
return CELL_OK;
});
return CELL_OK;
}
error_code cellPhotoExportFromFile(vm::cptr<char> srcHddDir, vm::cptr<char> srcHddFile, vm::ptr<CellPhotoExportSetParam> param, vm::ptr<CellPhotoExportUtilFinishCallback> funcFinish, vm::ptr<void> userdata)
{
cellPhotoExport.todo("cellPhotoExportFromFile(srcHddDir=%s, srcHddFile=%s, param=*0x%x, funcFinish=*0x%x, userdata=*0x%x)", srcHddDir, srcHddFile, param, funcFinish, userdata);
if (!param || !funcFinish)
{
return CELL_PHOTO_EXPORT_UTIL_ERROR_PARAM;
}
// TODO: check param members ?
cellPhotoExport.notice("cellPhotoExportFromFile: param: photo_title=%s, game_title=%s, game_comment=%s", param->photo_title, param->game_title, param->game_comment);
const std::string file_path = fmt::format("%s/%s", srcHddDir.get_ptr(), srcHddFile.get_ptr());
if (!check_photo_path(file_path))
{
return { CELL_PHOTO_EXPORT_UTIL_ERROR_PARAM, file_path };
}
std::string filename;
if (srcHddFile)
{
fmt::append(filename, "%s", srcHddFile.get_ptr());
}
if (filename.empty())
{
return { CELL_PHOTO_EXPORT_UTIL_ERROR_PARAM, "filename empty" };
}
sysutil_register_cb([=](ppu_thread& ppu) -> s32
{
auto& pexp = g_fxo->get<photo_export>();
pexp.progress = 0; // 0%
const std::string src_path = vfs::get(file_path);
const std::string dst_path = get_available_photo_path(filename);
cellPhotoExport.notice("Copying file from '%s' to '%s'", file_path, dst_path);
// TODO: We ignore metadata for now
if (!fs::create_path(fs::get_parent_dir(dst_path)) || !fs::copy_file(src_path, dst_path, false))
{
// TODO: find out which error is used
cellPhotoExport.error("Failed to copy file from '%s' to '%s' (%s)", src_path, dst_path, fs::g_tls_error);
funcFinish(ppu, CELL_PHOTO_EXPORT_UTIL_ERROR_MOVE, userdata);
return CELL_OK;
}
if (file_path.starts_with("/dev_hdd0"sv))
{
cellPhotoExport.notice("Removing file '%s'", src_path);
if (!fs::remove_file(src_path))
{
// TODO: find out if an error is used here
cellPhotoExport.error("Failed to remove file '%s' (%s)", src_path, fs::g_tls_error);
}
}
// TODO: track progress during file copy
pexp.progress = 0xFFFF; // 100%
funcFinish(ppu, CELL_OK, userdata);
return CELL_OK;
});
return CELL_OK;
}
error_code cellPhotoExportFromFileWithCopy(vm::cptr<char> srcHddDir, vm::cptr<char> srcHddFile, vm::ptr<CellPhotoExportSetParam> param, vm::ptr<CellPhotoExportUtilFinishCallback> funcFinish, vm::ptr<void> userdata)
{
cellPhotoExport.todo("cellPhotoExportFromFileWithCopy(srcHddDir=%s, srcHddFile=%s, param=*0x%x, funcFinish=*0x%x, userdata=*0x%x)", srcHddDir, srcHddFile, param, funcFinish, userdata);
if (!param || !funcFinish)
{
return CELL_PHOTO_EXPORT_UTIL_ERROR_PARAM;
}
// TODO: check param members ?
cellPhotoExport.notice("cellPhotoExportFromFileWithCopy: param: photo_title=%s, game_title=%s, game_comment=%s", param->photo_title, param->game_title, param->game_comment);
const std::string file_path = fmt::format("%s/%s", srcHddDir.get_ptr(), srcHddFile.get_ptr());
if (!check_photo_path(file_path))
{
return { CELL_PHOTO_EXPORT_UTIL_ERROR_PARAM, file_path };
}
std::string filename;
if (srcHddFile)
{
fmt::append(filename, "%s", srcHddFile.get_ptr());
}
if (filename.empty())
{
return { CELL_PHOTO_EXPORT_UTIL_ERROR_PARAM, "filename empty" };
}
sysutil_register_cb([=](ppu_thread& ppu) -> s32
{
auto& pexp = g_fxo->get<photo_export>();
pexp.progress = 0; // 0%
const std::string src_path = vfs::get(file_path);
const std::string dst_path = get_available_photo_path(filename);
cellPhotoExport.notice("Copying file from '%s' to '%s'", file_path, dst_path);
// TODO: We ignore metadata for now
if (!fs::create_path(fs::get_parent_dir(dst_path)) || !fs::copy_file(src_path, dst_path, false))
{
// TODO: find out which error is used
cellPhotoExport.error("Failed to copy file from '%s' to '%s' (%s)", src_path, dst_path, fs::g_tls_error);
funcFinish(ppu, CELL_PHOTO_EXPORT_UTIL_ERROR_MOVE, userdata);
return CELL_OK;
}
// TODO: track progress during file copy
pexp.progress = 0xFFFF; // 100%
funcFinish(ppu, CELL_OK, userdata);
return CELL_OK;
});
return CELL_OK;
}
error_code cellPhotoExportProgress(vm::ptr<CellPhotoExportUtilFinishCallback> funcFinish, vm::ptr<void> userdata)
{
cellPhotoExport.notice("cellPhotoExportProgress(funcFinish=*0x%x, userdata=*0x%x)", funcFinish, userdata);
if (!funcFinish)
{
return CELL_PHOTO_EXPORT_UTIL_ERROR_PARAM;
}
sysutil_register_cb([=](ppu_thread& ppu) -> s32
{
// Set the status as 0x0-0xFFFF (0-100%) depending on the copy status.
// Only the copy or move of the movie and metadata files is considered for the progress.
const auto& pexp = g_fxo->get<photo_export>();
funcFinish(ppu, pexp.progress, userdata);
return CELL_OK;
});
return CELL_OK;
}
DECLARE(ppu_module_manager::cellPhotoExport)("cellPhotoUtility", []()
{
REG_FUNC(cellPhotoUtility, cellPhotoInitialize);
REG_FUNC(cellPhotoUtility, cellPhotoFinalize);
REG_FUNC(cellPhotoUtility, cellPhotoRegistFromFile);
REG_FUNC(cellPhotoUtility, cellPhotoExportInitialize);
REG_FUNC(cellPhotoUtility, cellPhotoExportInitialize2);
REG_FUNC(cellPhotoUtility, cellPhotoExportFinalize);
REG_FUNC(cellPhotoUtility, cellPhotoExportFromFile);
REG_FUNC(cellPhotoUtility, cellPhotoExportFromFileWithCopy);
REG_FUNC(cellPhotoUtility, cellPhotoExportProgress);
});
| 13,458
|
C++
|
.cpp
| 381
| 32.687664
| 218
| 0.717502
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
5,234
|
sceNpClans.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/sceNpClans.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
#include "Emu/IdManager.h"
#include "sceNp.h"
#include "sceNpClans.h"
LOG_CHANNEL(sceNpClans);
template<>
void fmt_class_string<SceNpClansError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(SCE_NP_CLANS_ERROR_ALREADY_INITIALIZED);
STR_CASE(SCE_NP_CLANS_ERROR_NOT_INITIALIZED);
STR_CASE(SCE_NP_CLANS_ERROR_NOT_SUPPORTED);
STR_CASE(SCE_NP_CLANS_ERROR_OUT_OF_MEMORY);
STR_CASE(SCE_NP_CLANS_ERROR_INVALID_ARGUMENT);
STR_CASE(SCE_NP_CLANS_ERROR_EXCEEDS_MAX);
STR_CASE(SCE_NP_CLANS_ERROR_BAD_RESPONSE);
STR_CASE(SCE_NP_CLANS_ERROR_BAD_DATA);
STR_CASE(SCE_NP_CLANS_ERROR_BAD_REQUEST);
STR_CASE(SCE_NP_CLANS_ERROR_INVALID_SIGNATURE);
STR_CASE(SCE_NP_CLANS_ERROR_INSUFFICIENT);
STR_CASE(SCE_NP_CLANS_ERROR_INTERNAL_BUFFER);
STR_CASE(SCE_NP_CLANS_ERROR_SERVER_MAINTENANCE);
STR_CASE(SCE_NP_CLANS_ERROR_SERVER_END_OF_SERVICE);
STR_CASE(SCE_NP_CLANS_ERROR_SERVER_BEFORE_START_OF_SERVICE);
STR_CASE(SCE_NP_CLANS_ERROR_ABORTED);
STR_CASE(SCE_NP_CLANS_ERROR_SERVICE_UNAVAILABLE);
STR_CASE(SCE_NP_CLANS_SERVER_ERROR_BAD_REQUEST);
STR_CASE(SCE_NP_CLANS_SERVER_ERROR_INVALID_TICKET);
STR_CASE(SCE_NP_CLANS_SERVER_ERROR_INVALID_SIGNATURE);
STR_CASE(SCE_NP_CLANS_SERVER_ERROR_TICKET_EXPIRED);
STR_CASE(SCE_NP_CLANS_SERVER_ERROR_INVALID_NPID);
STR_CASE(SCE_NP_CLANS_SERVER_ERROR_FORBIDDEN);
STR_CASE(SCE_NP_CLANS_SERVER_ERROR_INTERNAL_SERVER_ERROR);
STR_CASE(SCE_NP_CLANS_SERVER_ERROR_BANNED);
STR_CASE(SCE_NP_CLANS_SERVER_ERROR_BLACKLISTED);
STR_CASE(SCE_NP_CLANS_SERVER_ERROR_INVALID_ENVIRONMENT);
STR_CASE(SCE_NP_CLANS_SERVER_ERROR_NO_SUCH_CLAN_SERVICE);
STR_CASE(SCE_NP_CLANS_SERVER_ERROR_NO_SUCH_CLAN);
STR_CASE(SCE_NP_CLANS_SERVER_ERROR_NO_SUCH_CLAN_MEMBER);
STR_CASE(SCE_NP_CLANS_SERVER_ERROR_BEFORE_HOURS);
STR_CASE(SCE_NP_CLANS_SERVER_ERROR_CLOSED_SERVICE);
STR_CASE(SCE_NP_CLANS_SERVER_ERROR_PERMISSION_DENIED);
STR_CASE(SCE_NP_CLANS_SERVER_ERROR_CLAN_LIMIT_REACHED);
STR_CASE(SCE_NP_CLANS_SERVER_ERROR_CLAN_LEADER_LIMIT_REACHED);
STR_CASE(SCE_NP_CLANS_SERVER_ERROR_CLAN_MEMBER_LIMIT_REACHED);
STR_CASE(SCE_NP_CLANS_SERVER_ERROR_CLAN_JOINED_LIMIT_REACHED);
STR_CASE(SCE_NP_CLANS_SERVER_ERROR_MEMBER_STATUS_INVALID);
STR_CASE(SCE_NP_CLANS_SERVER_ERROR_DUPLICATED_CLAN_NAME);
STR_CASE(SCE_NP_CLANS_SERVER_ERROR_CLAN_LEADER_CANNOT_LEAVE);
STR_CASE(SCE_NP_CLANS_SERVER_ERROR_INVALID_ROLE_PRIORITY);
STR_CASE(SCE_NP_CLANS_SERVER_ERROR_ANNOUNCEMENT_LIMIT_REACHED);
STR_CASE(SCE_NP_CLANS_SERVER_ERROR_CLAN_CONFIG_MASTER_NOT_FOUND);
STR_CASE(SCE_NP_CLANS_SERVER_ERROR_DUPLICATED_CLAN_TAG);
STR_CASE(SCE_NP_CLANS_SERVER_ERROR_EXCEEDS_CREATE_CLAN_FREQUENCY);
STR_CASE(SCE_NP_CLANS_SERVER_ERROR_CLAN_PASSPHRASE_INCORRECT);
STR_CASE(SCE_NP_CLANS_SERVER_ERROR_CANNOT_RECORD_BLACKLIST_ENTRY);
STR_CASE(SCE_NP_CLANS_SERVER_ERROR_NO_SUCH_CLAN_ANNOUNCEMENT);
STR_CASE(SCE_NP_CLANS_SERVER_ERROR_VULGAR_WORDS_POSTED);
STR_CASE(SCE_NP_CLANS_SERVER_ERROR_BLACKLIST_LIMIT_REACHED);
STR_CASE(SCE_NP_CLANS_SERVER_ERROR_NO_SUCH_BLACKLIST_ENTRY);
STR_CASE(SCE_NP_CLANS_SERVER_ERROR_INVALID_NP_MESSAGE_FORMAT);
STR_CASE(SCE_NP_CLANS_SERVER_ERROR_FAILED_TO_SEND_NP_MESSAGE);
}
return unknown;
});
}
error_code sceNpClansInit(vm::cptr<SceNpCommunicationId> commId, vm::cptr<SceNpCommunicationPassphrase> passphrase, vm::ptr<void> pool, vm::ptr<u32> poolSize, u32 flags)
{
sceNpClans.warning("sceNpClansInit(commId=*0x%x, passphrase=*0x%x, pool=*0x%x, poolSize=*0x%x, flags=0x%x)", commId, passphrase, pool, poolSize, flags);
auto& clans_manager = g_fxo->get<sce_np_clans_manager>();
if (clans_manager.is_initialized)
{
return SCE_NP_CLANS_ERROR_ALREADY_INITIALIZED;
}
if (!commId || !passphrase)
{
return SCE_NP_CLANS_ERROR_INVALID_ARGUMENT;
}
if (flags != 0)
{
return SCE_NP_CLANS_ERROR_NOT_SUPPORTED;
}
clans_manager.is_initialized = true;
return CELL_OK;
}
error_code sceNpClansTerm()
{
sceNpClans.warning("sceNpClansTerm()");
auto& clans_manager = g_fxo->get<sce_np_clans_manager>();
if (!clans_manager.is_initialized)
{
return SCE_NP_CLANS_ERROR_NOT_INITIALIZED;
}
clans_manager.is_initialized = false;
return CELL_OK;
}
error_code sceNpClansCreateRequest(vm::ptr<SceNpClansRequestHandle> handle, u64 flags)
{
sceNpClans.todo("sceNpClansCreateRequest(handle=*0x%x, flags=0x%llx)", handle, flags);
if (!g_fxo->get<sce_np_clans_manager>().is_initialized)
{
return SCE_NP_CLANS_ERROR_NOT_INITIALIZED;
}
if (!handle)
{
return SCE_NP_CLANS_ERROR_INVALID_ARGUMENT;
}
if (flags != 0)
{
return SCE_NP_CLANS_ERROR_NOT_SUPPORTED;
}
return CELL_OK;
}
error_code sceNpClansDestroyRequest(vm::ptr<SceNpClansRequestHandle> handle)
{
sceNpClans.todo("sceNpClansDestroyRequest(handle=*0x%x)", handle);
if (!g_fxo->get<sce_np_clans_manager>().is_initialized)
{
return SCE_NP_CLANS_ERROR_NOT_INITIALIZED;
}
return CELL_OK;
}
error_code sceNpClansAbortRequest(vm::ptr<SceNpClansRequestHandle> handle)
{
sceNpClans.todo("sceNpClansAbortRequest(handle=*0x%x)", handle);
if (!g_fxo->get<sce_np_clans_manager>().is_initialized)
{
return SCE_NP_CLANS_ERROR_NOT_INITIALIZED;
}
return CELL_OK;
}
error_code sceNpClansCreateClan(vm::ptr<SceNpClansRequestHandle> handle, vm::cptr<char> name, vm::cptr<char> tag, vm::ptr<SceNpClanId> clanId)
{
sceNpClans.todo("sceNpClansCreateClan(handle=*0x%x, name=%s, tag=%s, clanId=*0x%x)", handle, name, tag, clanId);
if (!g_fxo->get<sce_np_clans_manager>().is_initialized)
{
return SCE_NP_CLANS_ERROR_NOT_INITIALIZED;
}
if (!name || !tag || !clanId)
{
return SCE_NP_CLANS_ERROR_INVALID_ARGUMENT;
}
if (strlen(name.get_ptr()) > SCE_NP_CLANS_CLAN_NAME_MAX_LENGTH || strlen(tag.get_ptr()) > SCE_NP_CLANS_CLAN_TAG_MAX_LENGTH)
{
return SCE_NP_CLANS_ERROR_EXCEEDS_MAX;
}
return CELL_OK;
}
error_code sceNpClansDisbandClan(vm::ptr<SceNpClansRequestHandle> handle, SceNpClanId clanId)
{
sceNpClans.todo("sceNpClansDisbandClan(handle=*0x%x, clanId=*0x%x)", handle, clanId);
if (!g_fxo->get<sce_np_clans_manager>().is_initialized)
{
return SCE_NP_CLANS_ERROR_NOT_INITIALIZED;
}
return CELL_OK;
}
error_code sceNpClansGetClanList(vm::ptr<SceNpClansRequestHandle> handle, vm::cptr<SceNpClansPagingRequest> paging, vm::ptr<SceNpClansEntry> clanList, vm::ptr<SceNpClansPagingResult> pageResult)
{
sceNpClans.todo("sceNpClansGetClanList(handle=*0x%x, paging=*0x%x, clanList=*0x%x, pageResult=*0x%x)", handle, paging, clanList, pageResult);
if (!g_fxo->get<sce_np_clans_manager>().is_initialized)
{
return SCE_NP_CLANS_ERROR_NOT_INITIALIZED;
}
if (!pageResult || (paging && !clanList)) // TODO: confirm
{
return SCE_NP_CLANS_ERROR_INVALID_ARGUMENT;
}
if (paging)
{
if (paging->startPos > SCE_NP_CLANS_PAGING_REQUEST_START_POSITION_MAX || paging->max > SCE_NP_CLANS_PAGING_REQUEST_PAGE_MAX)
{
return SCE_NP_CLANS_ERROR_EXCEEDS_MAX;
}
}
return CELL_OK;
}
error_code sceNpClansGetClanListByNpId(vm::ptr<SceNpClansRequestHandle> handle, vm::cptr<SceNpClansPagingRequest> paging, vm::cptr<SceNpId> npid, vm::ptr<SceNpClansEntry> clanList, vm::ptr<SceNpClansPagingResult> pageResult)
{
sceNpClans.todo("sceNpClansGetClanListByNpId(handle=*0x%x, paging=*0x%x, npid=*0x%x, clanList=*0x%x, pageResult=*0x%x)", handle, paging, npid, clanList, pageResult);
if (!g_fxo->get<sce_np_clans_manager>().is_initialized)
{
return SCE_NP_CLANS_ERROR_NOT_INITIALIZED;
}
if (!npid || !pageResult || (paging && !clanList)) // TODO: confirm
{
return SCE_NP_CLANS_ERROR_INVALID_ARGUMENT;
}
if (paging)
{
if (paging->startPos > SCE_NP_CLANS_PAGING_REQUEST_START_POSITION_MAX || paging->max > SCE_NP_CLANS_PAGING_REQUEST_PAGE_MAX)
{
return SCE_NP_CLANS_ERROR_EXCEEDS_MAX;
}
}
return CELL_OK;
}
error_code sceNpClansSearchByProfile(vm::ptr<SceNpClansRequestHandle> handle, vm::cptr<SceNpClansPagingRequest> paging, vm::cptr<SceNpClansSearchableProfile> search, vm::ptr<SceNpClansClanBasicInfo> results, vm::ptr<SceNpClansPagingResult> pageResult)
{
sceNpClans.todo("sceNpClansSearchByProfile(handle=*0x%x, paging=*0x%x, search=*0x%x, results=*0x%x, pageResult=*0x%x)", handle, paging, search, results, pageResult);
if (!g_fxo->get<sce_np_clans_manager>().is_initialized)
{
return SCE_NP_CLANS_ERROR_NOT_INITIALIZED;
}
if (!search || !pageResult || (paging && !results)) // TODO: confirm
{
return SCE_NP_CLANS_ERROR_INVALID_ARGUMENT;
}
if (paging)
{
if (paging->startPos > SCE_NP_CLANS_PAGING_REQUEST_START_POSITION_MAX || paging->max > SCE_NP_CLANS_PAGING_REQUEST_PAGE_MAX)
{
return SCE_NP_CLANS_ERROR_EXCEEDS_MAX;
}
}
return CELL_OK;
}
error_code sceNpClansSearchByName(vm::ptr<SceNpClansRequestHandle> handle, vm::cptr<SceNpClansPagingRequest> paging, vm::cptr<SceNpClansSearchableName> search, vm::ptr<SceNpClansClanBasicInfo> results, vm::ptr<SceNpClansPagingResult> pageResult)
{
sceNpClans.todo("sceNpClansSearchByName(handle=*0x%x, paging=*0x%x, search=*0x%x, results=*0x%x, pageResult=*0x%x)", handle, paging, search, results, pageResult);
if (!g_fxo->get<sce_np_clans_manager>().is_initialized)
{
return SCE_NP_CLANS_ERROR_NOT_INITIALIZED;
}
if (!search || !pageResult || (paging && !results)) // TODO: confirm
{
return SCE_NP_CLANS_ERROR_INVALID_ARGUMENT;
}
if (paging)
{
if (paging->startPos > SCE_NP_CLANS_PAGING_REQUEST_START_POSITION_MAX || paging->max > SCE_NP_CLANS_PAGING_REQUEST_PAGE_MAX)
{
return SCE_NP_CLANS_ERROR_EXCEEDS_MAX;
}
}
return CELL_OK;
}
error_code sceNpClansGetClanInfo(vm::ptr<SceNpClansRequestHandle> handle, SceNpClanId clanId, vm::ptr<SceNpClansClanInfo> info)
{
sceNpClans.todo("sceNpClansGetClanInfo(handle=*0x%x, clanId=%d, info=*0x%x)", handle, clanId, info);
if (!g_fxo->get<sce_np_clans_manager>().is_initialized)
{
return SCE_NP_CLANS_ERROR_NOT_INITIALIZED;
}
if (!info)
{
// TODO: add more checks for info
return SCE_NP_CLANS_ERROR_INVALID_ARGUMENT;
}
return CELL_OK;
}
error_code sceNpClansUpdateClanInfo(vm::ptr<SceNpClansRequestHandle> handle, SceNpClanId clanId, vm::cptr<SceNpClansUpdatableClanInfo> info)
{
sceNpClans.todo("sceNpClansUpdateClanInfo(handle=*0x%x, clanId=%d, info=*0x%x)", handle, clanId, info);
if (!g_fxo->get<sce_np_clans_manager>().is_initialized)
{
return SCE_NP_CLANS_ERROR_NOT_INITIALIZED;
}
if (!info)
{
// TODO: add more checks for info
return SCE_NP_CLANS_ERROR_INVALID_ARGUMENT;
}
//if (info->something > X)
//{
// return SCE_NP_CLANS_ERROR_EXCEEDS_MAX;
//}
return CELL_OK;
}
error_code sceNpClansGetMemberList(vm::ptr<SceNpClansRequestHandle> handle, SceNpClanId clanId, vm::cptr<SceNpClansPagingRequest> paging, SceNpClansMemberStatus status, vm::ptr<SceNpClansMemberEntry> memList, vm::ptr<SceNpClansPagingResult> pageResult)
{
sceNpClans.todo("sceNpClansGetMemberList(handle=*0x%x, clanId=%d, paging=*0x%x, status=%d, memList=*0x%x, pageResult=*0x%x)", handle, clanId, paging, status, memList, pageResult);
if (!g_fxo->get<sce_np_clans_manager>().is_initialized)
{
return SCE_NP_CLANS_ERROR_NOT_INITIALIZED;
}
if (!pageResult || (paging && !memList)) // TODO: confirm
{
return SCE_NP_CLANS_ERROR_INVALID_ARGUMENT;
}
if (paging)
{
if (paging->startPos > SCE_NP_CLANS_PAGING_REQUEST_START_POSITION_MAX || paging->max > SCE_NP_CLANS_PAGING_REQUEST_PAGE_MAX)
{
return SCE_NP_CLANS_ERROR_EXCEEDS_MAX;
}
}
return CELL_OK;
}
error_code sceNpClansGetMemberInfo(vm::ptr<SceNpClansRequestHandle> handle, SceNpClanId clanId, vm::cptr<SceNpId> npid, vm::ptr<SceNpClansMemberEntry> memInfo)
{
sceNpClans.todo("sceNpClansGetMemberInfo(handle=*0x%x, clanId=%d, npid=*0x%x, memInfo=*0x%x)", handle, clanId, npid, memInfo);
if (!g_fxo->get<sce_np_clans_manager>().is_initialized)
{
return SCE_NP_CLANS_ERROR_NOT_INITIALIZED;
}
if (!npid || !memInfo)
{
return SCE_NP_CLANS_ERROR_INVALID_ARGUMENT;
}
return CELL_OK;
}
error_code sceNpClansUpdateMemberInfo(vm::ptr<SceNpClansRequestHandle> handle, SceNpClanId clanId, vm::cptr<SceNpClansUpdatableMemberInfo> info)
{
sceNpClans.todo("sceNpClansUpdateMemberInfo(handle=*0x%x, clanId=%d, memInfo=*0x%x)", handle, clanId, info);
if (!g_fxo->get<sce_np_clans_manager>().is_initialized)
{
return SCE_NP_CLANS_ERROR_NOT_INITIALIZED;
}
if (!info)
{
// TODO: add more checks for info
return SCE_NP_CLANS_ERROR_INVALID_ARGUMENT;
}
//if (info->something > X)
//{
// return SCE_NP_CLANS_ERROR_EXCEEDS_MAX;
//}
return CELL_OK;
}
error_code sceNpClansChangeMemberRole(vm::ptr<SceNpClansRequestHandle> handle, SceNpClanId clanId, vm::cptr<SceNpId> npid, u32 role)
{
sceNpClans.todo("sceNpClansChangeMemberRole(handle=*0x%x, clanId=%d, npid=*0x%x, role=%d)", handle, clanId, npid, role);
if (!g_fxo->get<sce_np_clans_manager>().is_initialized)
{
return SCE_NP_CLANS_ERROR_NOT_INITIALIZED;
}
if (!npid || role > SCE_NP_CLANS_ROLE_LEADER) // TODO: check if role can be 0
{
return SCE_NP_CLANS_ERROR_INVALID_ARGUMENT;
}
return CELL_OK;
}
error_code sceNpClansGetAutoAcceptStatus(vm::ptr<SceNpClansRequestHandle> handle, SceNpClanId clanId, vm::ptr<b8> enable)
{
sceNpClans.todo("sceNpClansGetAutoAcceptStatus(handle=*0x%x, clanId=%d, enable=*0x%x)", handle, clanId, enable);
if (!g_fxo->get<sce_np_clans_manager>().is_initialized)
{
return SCE_NP_CLANS_ERROR_NOT_INITIALIZED;
}
if (!enable)
{
return SCE_NP_CLANS_ERROR_INVALID_ARGUMENT;
}
return CELL_OK;
}
error_code sceNpClansUpdateAutoAcceptStatus(vm::ptr<SceNpClansRequestHandle> handle, SceNpClanId clanId, b8 enable)
{
sceNpClans.todo("sceNpClansUpdateAutoAcceptStatus(handle=*0x%x, clanId=%d, enable=%d)", handle, clanId, enable);
if (!g_fxo->get<sce_np_clans_manager>().is_initialized)
{
return SCE_NP_CLANS_ERROR_NOT_INITIALIZED;
}
return CELL_OK;
}
error_code sceNpClansJoinClan(vm::ptr<SceNpClansRequestHandle> handle, SceNpClanId clanId)
{
sceNpClans.todo("sceNpClansJoinClan(handle=*0x%x, clanId=%d)", handle, clanId);
if (!g_fxo->get<sce_np_clans_manager>().is_initialized)
{
return SCE_NP_CLANS_ERROR_NOT_INITIALIZED;
}
return CELL_OK;
}
error_code sceNpClansLeaveClan(vm::ptr<SceNpClansRequestHandle> handle, SceNpClanId clanId)
{
sceNpClans.todo("sceNpClansLeaveClan(handle=*0x%x, clanId=%d)", handle, clanId);
if (!g_fxo->get<sce_np_clans_manager>().is_initialized)
{
return SCE_NP_CLANS_ERROR_NOT_INITIALIZED;
}
return CELL_OK;
}
error_code sceNpClansKickMember(vm::ptr<SceNpClansRequestHandle> handle, SceNpClanId clanId, vm::cptr<SceNpId> npid, vm::cptr<SceNpClansMessage> message)
{
sceNpClans.todo("sceNpClansKickMember(handle=*0x%x, clanId=%d, npid=*0x%x, message=*0x%x)", handle, clanId, npid, message);
if (!g_fxo->get<sce_np_clans_manager>().is_initialized)
{
return SCE_NP_CLANS_ERROR_NOT_INITIALIZED;
}
if (!npid)
{
return SCE_NP_CLANS_ERROR_INVALID_ARGUMENT;
}
if (message)
{
if (strlen(message->body) > SCE_NP_CLANS_MESSAGE_BODY_MAX_LENGTH || strlen(message->subject) > SCE_NP_CLANS_MESSAGE_SUBJECT_MAX_LENGTH) // TODO: correct max?
{
return SCE_NP_CLANS_ERROR_EXCEEDS_MAX;
}
}
return CELL_OK;
}
error_code sceNpClansSendInvitation(vm::ptr<SceNpClansRequestHandle> handle, SceNpClanId clanId, vm::cptr<SceNpId> npid, vm::cptr<SceNpClansMessage> message)
{
sceNpClans.todo("sceNpClansSendInvitation(handle=*0x%x, clanId=%d, npid=*0x%x, message=*0x%x)", handle, clanId, npid, message);
if (!g_fxo->get<sce_np_clans_manager>().is_initialized)
{
return SCE_NP_CLANS_ERROR_NOT_INITIALIZED;
}
if (!npid)
{
return SCE_NP_CLANS_ERROR_INVALID_ARGUMENT;
}
if (message)
{
if (strlen(message->body) > SCE_NP_CLANS_MESSAGE_BODY_MAX_LENGTH || strlen(message->subject) > SCE_NP_CLANS_MESSAGE_SUBJECT_MAX_LENGTH) // TODO: correct max?
{
return SCE_NP_CLANS_ERROR_EXCEEDS_MAX;
}
}
return CELL_OK;
}
error_code sceNpClansCancelInvitation(vm::ptr<SceNpClansRequestHandle> handle, SceNpClanId clanId, vm::cptr<SceNpId> npid)
{
sceNpClans.todo("sceNpClansCancelInvitation(handle=*0x%x, clanId=%d, npid=*0x%x)", handle, clanId, npid);
if (!g_fxo->get<sce_np_clans_manager>().is_initialized)
{
return SCE_NP_CLANS_ERROR_NOT_INITIALIZED;
}
if (!npid)
{
return SCE_NP_CLANS_ERROR_INVALID_ARGUMENT;
}
return CELL_OK;
}
error_code sceNpClansSendInvitationResponse(vm::ptr<SceNpClansRequestHandle> handle, SceNpClanId clanId, vm::cptr<SceNpClansMessage> message, b8 accept)
{
sceNpClans.todo("sceNpClansSendInvitationResponse(handle=*0x%x, clanId=%d, message=*0x%x, accept=%d)", handle, clanId, message, accept);
if (!g_fxo->get<sce_np_clans_manager>().is_initialized)
{
return SCE_NP_CLANS_ERROR_NOT_INITIALIZED;
}
if (message)
{
if (strlen(message->body) > SCE_NP_CLANS_MESSAGE_BODY_MAX_LENGTH || strlen(message->subject) > SCE_NP_CLANS_MESSAGE_SUBJECT_MAX_LENGTH) // TODO: correct max?
{
return SCE_NP_CLANS_ERROR_EXCEEDS_MAX;
}
}
return CELL_OK;
}
error_code sceNpClansSendMembershipRequest(vm::ptr<SceNpClansRequestHandle> handle, u32 clanId, vm::cptr<SceNpClansMessage> message)
{
sceNpClans.todo("sceNpClansSendMembershipRequest(handle=*0x%x, clanId=%d, message=*0x%x)", handle, clanId, message);
if (!g_fxo->get<sce_np_clans_manager>().is_initialized)
{
return SCE_NP_CLANS_ERROR_NOT_INITIALIZED;
}
if (message)
{
if (strlen(message->body) > SCE_NP_CLANS_MESSAGE_BODY_MAX_LENGTH || strlen(message->subject) > SCE_NP_CLANS_MESSAGE_SUBJECT_MAX_LENGTH) // TODO: correct max?
{
return SCE_NP_CLANS_ERROR_EXCEEDS_MAX;
}
}
return CELL_OK;
}
error_code sceNpClansCancelMembershipRequest(vm::ptr<SceNpClansRequestHandle> handle, SceNpClanId clanId)
{
sceNpClans.todo("sceNpClansCancelMembershipRequest(handle=*0x%x, clanId=%d)", handle, clanId);
if (!g_fxo->get<sce_np_clans_manager>().is_initialized)
{
return SCE_NP_CLANS_ERROR_NOT_INITIALIZED;
}
return CELL_OK;
}
error_code sceNpClansSendMembershipResponse(vm::ptr<SceNpClansRequestHandle> handle, SceNpClanId clanId, vm::cptr<SceNpId> npid, vm::cptr<SceNpClansMessage> message, b8 allow)
{
sceNpClans.todo("sceNpClansSendMembershipResponse(handle=*0x%x, clanId=%d, npid=*0x%x, message=*0x%x, allow=%d)", handle, clanId, npid, message, allow);
if (!g_fxo->get<sce_np_clans_manager>().is_initialized)
{
return SCE_NP_CLANS_ERROR_NOT_INITIALIZED;
}
if (!npid)
{
return SCE_NP_CLANS_ERROR_INVALID_ARGUMENT;
}
if (message)
{
if (strlen(message->body) > SCE_NP_CLANS_MESSAGE_BODY_MAX_LENGTH || strlen(message->subject) > SCE_NP_CLANS_MESSAGE_SUBJECT_MAX_LENGTH) // TODO: correct max?
{
return SCE_NP_CLANS_ERROR_EXCEEDS_MAX;
}
}
return CELL_OK;
}
error_code sceNpClansGetBlacklist(vm::ptr<SceNpClansRequestHandle> handle, SceNpClanId clanId, vm::cptr<SceNpClansPagingRequest> paging, vm::ptr<SceNpClansBlacklistEntry> bl, vm::ptr<SceNpClansPagingResult> pageResult)
{
sceNpClans.todo("sceNpClansGetBlacklist(handle=*0x%x, clanId=%d, paging=*0x%x, bl=*0x%x, pageResult=*0x%x)", handle, clanId, paging, bl, pageResult);
if (!g_fxo->get<sce_np_clans_manager>().is_initialized)
{
return SCE_NP_CLANS_ERROR_NOT_INITIALIZED;
}
if (!pageResult || (paging && !bl)) // TODO: confirm
{
return SCE_NP_CLANS_ERROR_INVALID_ARGUMENT;
}
if (paging)
{
if (paging->startPos > SCE_NP_CLANS_PAGING_REQUEST_START_POSITION_MAX || paging->max > SCE_NP_CLANS_PAGING_REQUEST_PAGE_MAX)
{
return SCE_NP_CLANS_ERROR_EXCEEDS_MAX;
}
}
return CELL_OK;
}
error_code sceNpClansAddBlacklistEntry(vm::ptr<SceNpClansRequestHandle> handle, SceNpClanId clanId, vm::cptr<SceNpId> npid)
{
sceNpClans.todo("sceNpClansAddBlacklistEntry(handle=*0x%x, clanId=%d, npid=*0x%x)", handle, clanId, npid);
if (!g_fxo->get<sce_np_clans_manager>().is_initialized)
{
return SCE_NP_CLANS_ERROR_NOT_INITIALIZED;
}
if (!npid)
{
return SCE_NP_CLANS_ERROR_INVALID_ARGUMENT;
}
return CELL_OK;
}
error_code sceNpClansRemoveBlacklistEntry(vm::ptr<SceNpClansRequestHandle> handle, SceNpClanId clanId, vm::cptr<SceNpId> npid)
{
sceNpClans.todo("sceNpClansRemoveBlacklistEntry(handle=*0x%x, clanId=%d, npid=*0x%x)", handle, clanId, npid);
if (!g_fxo->get<sce_np_clans_manager>().is_initialized)
{
return SCE_NP_CLANS_ERROR_NOT_INITIALIZED;
}
if (!npid)
{
return SCE_NP_CLANS_ERROR_INVALID_ARGUMENT;
}
return CELL_OK;
}
error_code sceNpClansRetrieveAnnouncements(vm::ptr<SceNpClansRequestHandle> handle, SceNpClanId clanId, vm::cptr<SceNpClansPagingRequest> paging, vm::ptr<SceNpClansMessageEntry> mlist, vm::ptr<SceNpClansPagingResult> pageResult)
{
sceNpClans.todo("sceNpClansRetrieveAnnouncements(handle=*0x%x, clanId=%d, paging=*0x%x, mlist=*0x%x, pageResult=*0x%x)", handle, clanId, paging, mlist, pageResult);
if (!g_fxo->get<sce_np_clans_manager>().is_initialized)
{
return SCE_NP_CLANS_ERROR_NOT_INITIALIZED;
}
if (!pageResult || (paging && !mlist)) // TODO: confirm
{
return SCE_NP_CLANS_ERROR_INVALID_ARGUMENT;
}
if (paging)
{
if (paging->startPos > SCE_NP_CLANS_PAGING_REQUEST_START_POSITION_MAX || paging->max > SCE_NP_CLANS_PAGING_REQUEST_PAGE_MAX)
{
return SCE_NP_CLANS_ERROR_EXCEEDS_MAX;
}
}
return CELL_OK;
}
error_code sceNpClansPostAnnouncement(vm::ptr<SceNpClansRequestHandle> handle, SceNpClanId clanId, vm::cptr<SceNpClansMessage> message, vm::cptr<SceNpClansMessageData> data, u32 duration, vm::ptr<SceNpClansMessageId> mId)
{
sceNpClans.todo("sceNpClansPostAnnouncement(handle=*0x%x, clanId=%d, message=*0x%x, data=*0x%x, duration=%d, mId=*0x%x)", handle, clanId, message, data, duration, mId);
if (!g_fxo->get<sce_np_clans_manager>().is_initialized)
{
return SCE_NP_CLANS_ERROR_NOT_INITIALIZED;
}
if (!message || !mId || duration == 0)
{
return SCE_NP_CLANS_ERROR_INVALID_ARGUMENT;
}
if (!data) // TODO verify
{
return SCE_NP_CLANS_ERROR_NOT_SUPPORTED;
}
if (strlen(message->body) > SCE_NP_CLANS_ANNOUNCEMENT_MESSAGE_BODY_MAX_LENGTH || strlen(message->subject) > SCE_NP_CLANS_MESSAGE_SUBJECT_MAX_LENGTH) // TODO: correct max?
{
return SCE_NP_CLANS_ERROR_EXCEEDS_MAX;
}
return CELL_OK;
}
error_code sceNpClansRemoveAnnouncement(vm::ptr<SceNpClansRequestHandle> handle, SceNpClanId clanId, SceNpClansMessageId mId)
{
sceNpClans.todo("sceNpClansPostAnnouncement(handle=*0x%x, clanId=%d, mId=%d)", handle, clanId, mId);
if (!g_fxo->get<sce_np_clans_manager>().is_initialized)
{
return SCE_NP_CLANS_ERROR_NOT_INITIALIZED;
}
return CELL_OK;
}
error_code sceNpClansPostChallenge(vm::ptr<SceNpClansRequestHandle> handle, SceNpClanId clanId, SceNpClanId targetClan, vm::cptr<SceNpClansMessage> message, vm::cptr<SceNpClansMessageData> data, u32 duration, vm::ptr<SceNpClansMessageId> mId)
{
sceNpClans.todo("sceNpClansPostChallenge(handle=*0x%x, clanId=%d, targetClan=%d, message=*0x%x, data=*0x%x, duration=%d, mId=*0x%x)", handle, clanId, targetClan, message, data, duration, mId);
if (!g_fxo->get<sce_np_clans_manager>().is_initialized)
{
return SCE_NP_CLANS_ERROR_NOT_INITIALIZED;
}
if (!message || !mId || duration == 0)
{
return SCE_NP_CLANS_ERROR_INVALID_ARGUMENT;
}
if (!data) // TODO verify
{
return SCE_NP_CLANS_ERROR_NOT_SUPPORTED;
}
if (strlen(message->body) > SCE_NP_CLANS_ANNOUNCEMENT_MESSAGE_BODY_MAX_LENGTH || strlen(message->subject) > SCE_NP_CLANS_MESSAGE_SUBJECT_MAX_LENGTH) // TODO: correct max?
{
return SCE_NP_CLANS_ERROR_EXCEEDS_MAX;
}
return CELL_OK;
}
error_code sceNpClansRetrievePostedChallenges(vm::ptr<SceNpClansRequestHandle> handle, SceNpClanId clanId, SceNpClanId targetClan, vm::cptr<SceNpClansPagingRequest> paging, vm::ptr<SceNpClansMessageEntry> mList, vm::ptr<SceNpClansPagingResult> pageResult)
{
sceNpClans.todo("sceNpClansRetrievePostedChallenges(handle=*0x%x, clanId=%d, targetClan=%d, paging=*0x%x, mList=*0x%x, pageResult=*0x%x)", handle, clanId, targetClan, paging, mList, pageResult);
if (!g_fxo->get<sce_np_clans_manager>().is_initialized)
{
return SCE_NP_CLANS_ERROR_NOT_INITIALIZED;
}
if (!pageResult || (paging && !mList)) // TODO: confirm
{
return SCE_NP_CLANS_ERROR_INVALID_ARGUMENT;
}
if (paging)
{
if (paging->startPos > SCE_NP_CLANS_PAGING_REQUEST_START_POSITION_MAX || paging->max > SCE_NP_CLANS_PAGING_REQUEST_PAGE_MAX)
{
return SCE_NP_CLANS_ERROR_EXCEEDS_MAX;
}
}
return CELL_OK;
}
error_code sceNpClansRemovePostedChallenge(vm::ptr<SceNpClansRequestHandle> handle, SceNpClanId clanId, SceNpClanId targetClan, SceNpClansMessageId mId)
{
sceNpClans.todo("sceNpClansRemovePostedChallenge(handle=*0x%x, clanId=%d, targetClan=%d, mId=%d)", handle, clanId, targetClan, mId);
if (!g_fxo->get<sce_np_clans_manager>().is_initialized)
{
return SCE_NP_CLANS_ERROR_NOT_INITIALIZED;
}
return CELL_OK;
}
error_code sceNpClansRetrieveChallenges(vm::ptr<SceNpClansRequestHandle> handle, SceNpClanId clanId, vm::cptr<SceNpClansPagingRequest> paging, vm::ptr<SceNpClansMessageEntry> mList, vm::ptr<SceNpClansPagingResult> pageResult)
{
sceNpClans.todo("sceNpClansRetrieveChallenges(handle=*0x%x, clanId=%d, paging=*0x%x, mList=*0x%x, pageResult=*0x%x)", handle, clanId, paging, mList, pageResult);
if (!g_fxo->get<sce_np_clans_manager>().is_initialized)
{
return SCE_NP_CLANS_ERROR_NOT_INITIALIZED;
}
if (!pageResult || (paging && !mList)) // TODO: confirm
{
return SCE_NP_CLANS_ERROR_INVALID_ARGUMENT;
}
if (paging)
{
if (paging->startPos > SCE_NP_CLANS_PAGING_REQUEST_START_POSITION_MAX || paging->max > SCE_NP_CLANS_PAGING_REQUEST_PAGE_MAX)
{
return SCE_NP_CLANS_ERROR_EXCEEDS_MAX;
}
}
return CELL_OK;
}
error_code sceNpClansRemoveChallenge(SceNpClansRequestHandle handle, SceNpClanId clanId, SceNpClansMessageId mId)
{
sceNpClans.todo("sceNpClansRemoveChallenge(handle=*0x%x, clanId=%d, mId=%d)", handle, clanId, mId);
if (!g_fxo->get<sce_np_clans_manager>().is_initialized)
{
return SCE_NP_CLANS_ERROR_NOT_INITIALIZED;
}
return CELL_OK;
}
DECLARE(ppu_module_manager::sceNpClans)("sceNpClans", []()
{
REG_FUNC(sceNpClans, sceNpClansInit);
REG_FUNC(sceNpClans, sceNpClansTerm);
REG_FUNC(sceNpClans, sceNpClansCreateRequest);
REG_FUNC(sceNpClans, sceNpClansDestroyRequest);
REG_FUNC(sceNpClans, sceNpClansAbortRequest);
REG_FUNC(sceNpClans, sceNpClansCreateClan);
REG_FUNC(sceNpClans, sceNpClansDisbandClan);
REG_FUNC(sceNpClans, sceNpClansGetClanList);
REG_FUNC(sceNpClans, sceNpClansGetClanListByNpId);
REG_FUNC(sceNpClans, sceNpClansSearchByProfile);
REG_FUNC(sceNpClans, sceNpClansSearchByName);
REG_FUNC(sceNpClans, sceNpClansGetClanInfo);
REG_FUNC(sceNpClans, sceNpClansUpdateClanInfo);
REG_FUNC(sceNpClans, sceNpClansGetMemberList);
REG_FUNC(sceNpClans, sceNpClansGetMemberInfo);
REG_FUNC(sceNpClans, sceNpClansUpdateMemberInfo);
REG_FUNC(sceNpClans, sceNpClansChangeMemberRole);
REG_FUNC(sceNpClans, sceNpClansGetAutoAcceptStatus);
REG_FUNC(sceNpClans, sceNpClansUpdateAutoAcceptStatus);
REG_FUNC(sceNpClans, sceNpClansJoinClan);
REG_FUNC(sceNpClans, sceNpClansLeaveClan);
REG_FUNC(sceNpClans, sceNpClansKickMember);
REG_FUNC(sceNpClans, sceNpClansSendInvitation);
REG_FUNC(sceNpClans, sceNpClansCancelInvitation);
REG_FUNC(sceNpClans, sceNpClansSendInvitationResponse);
REG_FUNC(sceNpClans, sceNpClansSendMembershipRequest);
REG_FUNC(sceNpClans, sceNpClansCancelMembershipRequest);
REG_FUNC(sceNpClans, sceNpClansSendMembershipResponse);
REG_FUNC(sceNpClans, sceNpClansGetBlacklist);
REG_FUNC(sceNpClans, sceNpClansAddBlacklistEntry);
REG_FUNC(sceNpClans, sceNpClansRemoveBlacklistEntry);
REG_FUNC(sceNpClans, sceNpClansRetrieveAnnouncements);
REG_FUNC(sceNpClans, sceNpClansPostAnnouncement);
REG_FUNC(sceNpClans, sceNpClansRemoveAnnouncement);
REG_FUNC(sceNpClans, sceNpClansPostChallenge);
REG_FUNC(sceNpClans, sceNpClansRetrievePostedChallenges);
REG_FUNC(sceNpClans, sceNpClansRemovePostedChallenge);
REG_FUNC(sceNpClans, sceNpClansRetrieveChallenges);
REG_FUNC(sceNpClans, sceNpClansRemoveChallenge);
});
| 27,957
|
C++
|
.cpp
| 708
| 37.063559
| 256
| 0.758735
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| false
| false
|
5,235
|
sceNp.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/sceNp.cpp
|
#include "stdafx.h"
#include "Emu/System.h"
#include "Emu/system_utils.hpp"
#include "Emu/VFS.h"
#include "Emu/Cell/PPUModule.h"
#include "Emu/Cell/Modules/cellUserInfo.h"
#include "Emu/Io/interception.h"
#include "Utilities/StrUtil.h"
#include "sysPrxForUser.h"
#include "Emu/IdManager.h"
#include "Crypto/unedat.h"
#include "Crypto/unself.h"
#include "cellRtc.h"
#include "sceNp.h"
#include "cellSysutil.h"
#include "Emu/Cell/lv2/sys_time.h"
#include "Emu/Cell/lv2/sys_fs.h"
#include "Emu/Cell/lv2/sys_sync.h"
#include "Emu/NP/np_handler.h"
#include "Emu/NP/np_contexts.h"
#include "Emu/NP/np_helpers.h"
#include "Emu/NP/np_structs_extra.h"
#include "Emu/system_config.h"
#include "Emu/RSX/Overlays/overlay_manager.h"
#include "Emu/RSX/Overlays/Network/overlay_recvmessage_dialog.h"
#include "Emu/RSX/Overlays/Network/overlay_sendmessage_dialog.h"
LOG_CHANNEL(sceNp);
error_code sceNpManagerGetNpId(vm::ptr<SceNpId> npId);
error_code sceNpCommerceGetCurrencyInfo(vm::ptr<SceNpCommerceProductCategory> pc, vm::ptr<SceNpCommerceCurrencyInfo> info);
error_code check_text(vm::cptr<char> text);
template <>
void fmt_class_string<SceNpError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(GAME_ERR_NOT_XMBBUY_CONTENT);
STR_CASE(SCE_NP_ERROR_NOT_INITIALIZED);
STR_CASE(SCE_NP_ERROR_ALREADY_INITIALIZED);
STR_CASE(SCE_NP_ERROR_INVALID_ARGUMENT);
STR_CASE(SCE_NP_ERROR_OUT_OF_MEMORY);
STR_CASE(SCE_NP_ERROR_ID_NO_SPACE);
STR_CASE(SCE_NP_ERROR_ID_NOT_FOUND);
STR_CASE(SCE_NP_ERROR_SESSION_RUNNING);
STR_CASE(SCE_NP_ERROR_LOGINID_ALREADY_EXISTS);
STR_CASE(SCE_NP_ERROR_INVALID_TICKET_SIZE);
STR_CASE(SCE_NP_ERROR_INVALID_STATE);
STR_CASE(SCE_NP_ERROR_ABORTED);
STR_CASE(SCE_NP_ERROR_OFFLINE);
STR_CASE(SCE_NP_ERROR_VARIANT_ACCOUNT_ID);
STR_CASE(SCE_NP_ERROR_GET_CLOCK);
STR_CASE(SCE_NP_ERROR_INSUFFICIENT_BUFFER);
STR_CASE(SCE_NP_ERROR_EXPIRED_TICKET);
STR_CASE(SCE_NP_ERROR_TICKET_PARAM_NOT_FOUND);
STR_CASE(SCE_NP_ERROR_UNSUPPORTED_TICKET_VERSION);
STR_CASE(SCE_NP_ERROR_TICKET_STATUS_CODE_INVALID);
STR_CASE(SCE_NP_ERROR_INVALID_TICKET_VERSION);
STR_CASE(SCE_NP_ERROR_ALREADY_USED);
STR_CASE(SCE_NP_ERROR_DIFFERENT_USER);
STR_CASE(SCE_NP_ERROR_ALREADY_DONE);
STR_CASE(SCE_NP_BASIC_ERROR_ALREADY_INITIALIZED);
STR_CASE(SCE_NP_BASIC_ERROR_NOT_INITIALIZED);
STR_CASE(SCE_NP_BASIC_ERROR_NOT_SUPPORTED);
STR_CASE(SCE_NP_BASIC_ERROR_OUT_OF_MEMORY);
STR_CASE(SCE_NP_BASIC_ERROR_INVALID_ARGUMENT);
STR_CASE(SCE_NP_BASIC_ERROR_BAD_ID);
STR_CASE(SCE_NP_BASIC_ERROR_IDS_DIFFER);
STR_CASE(SCE_NP_BASIC_ERROR_PARSER_FAILED);
STR_CASE(SCE_NP_BASIC_ERROR_TIMEOUT);
STR_CASE(SCE_NP_BASIC_ERROR_NO_EVENT);
STR_CASE(SCE_NP_BASIC_ERROR_EXCEEDS_MAX);
STR_CASE(SCE_NP_BASIC_ERROR_INSUFFICIENT);
STR_CASE(SCE_NP_BASIC_ERROR_NOT_REGISTERED);
STR_CASE(SCE_NP_BASIC_ERROR_DATA_LOST);
STR_CASE(SCE_NP_BASIC_ERROR_BUSY);
STR_CASE(SCE_NP_BASIC_ERROR_STATUS);
STR_CASE(SCE_NP_BASIC_ERROR_CANCEL);
STR_CASE(SCE_NP_BASIC_ERROR_INVALID_MEMORY_CONTAINER);
STR_CASE(SCE_NP_BASIC_ERROR_INVALID_DATA_ID);
STR_CASE(SCE_NP_BASIC_ERROR_BROKEN_DATA);
STR_CASE(SCE_NP_BASIC_ERROR_BLOCKLIST_ADD_FAILED);
STR_CASE(SCE_NP_BASIC_ERROR_BLOCKLIST_IS_FULL);
STR_CASE(SCE_NP_BASIC_ERROR_SEND_FAILED);
STR_CASE(SCE_NP_BASIC_ERROR_NOT_CONNECTED);
STR_CASE(SCE_NP_BASIC_ERROR_INSUFFICIENT_DISK_SPACE);
STR_CASE(SCE_NP_BASIC_ERROR_INTERNAL_FAILURE);
STR_CASE(SCE_NP_BASIC_ERROR_DOES_NOT_EXIST);
STR_CASE(SCE_NP_BASIC_ERROR_INVALID);
STR_CASE(SCE_NP_BASIC_ERROR_UNKNOWN);
STR_CASE(SCE_NP_EXT_ERROR_CONTEXT_DOES_NOT_EXIST);
STR_CASE(SCE_NP_EXT_ERROR_CONTEXT_ALREADY_EXISTS);
STR_CASE(SCE_NP_EXT_ERROR_NO_CONTEXT);
STR_CASE(SCE_NP_EXT_ERROR_NO_ORIGIN);
STR_CASE(SCE_NP_UTIL_ERROR_INVALID_ARGUMENT);
STR_CASE(SCE_NP_UTIL_ERROR_OUT_OF_MEMORY);
STR_CASE(SCE_NP_UTIL_ERROR_INSUFFICIENT);
STR_CASE(SCE_NP_UTIL_ERROR_PARSER_FAILED);
STR_CASE(SCE_NP_UTIL_ERROR_INVALID_PROTOCOL_ID);
STR_CASE(SCE_NP_UTIL_ERROR_INVALID_NP_ID);
STR_CASE(SCE_NP_UTIL_ERROR_INVALID_NP_LOBBY_ID);
STR_CASE(SCE_NP_UTIL_ERROR_INVALID_NP_ROOM_ID);
STR_CASE(SCE_NP_UTIL_ERROR_INVALID_NP_ENV);
STR_CASE(SCE_NP_UTIL_ERROR_INVALID_TITLEID);
STR_CASE(SCE_NP_UTIL_ERROR_INVALID_CHARACTER);
STR_CASE(SCE_NP_UTIL_ERROR_INVALID_ESCAPE_STRING);
STR_CASE(SCE_NP_UTIL_ERROR_UNKNOWN_TYPE);
STR_CASE(SCE_NP_UTIL_ERROR_UNKNOWN);
STR_CASE(SCE_NP_UTIL_ERROR_NOT_MATCH);
STR_CASE(SCE_NP_UTIL_ERROR_UNKNOWN_PLATFORM_TYPE);
STR_CASE(SCE_NP_FRIENDLIST_ERROR_ALREADY_INITIALIZED);
STR_CASE(SCE_NP_FRIENDLIST_ERROR_NOT_INITIALIZED);
STR_CASE(SCE_NP_FRIENDLIST_ERROR_OUT_OF_MEMORY);
STR_CASE(SCE_NP_FRIENDLIST_ERROR_INVALID_MEMORY_CONTAINER);
STR_CASE(SCE_NP_FRIENDLIST_ERROR_INSUFFICIENT);
STR_CASE(SCE_NP_FRIENDLIST_ERROR_CANCEL);
STR_CASE(SCE_NP_FRIENDLIST_ERROR_STATUS);
STR_CASE(SCE_NP_FRIENDLIST_ERROR_BUSY);
STR_CASE(SCE_NP_FRIENDLIST_ERROR_INVALID_ARGUMENT);
STR_CASE(SCE_NP_PROFILE_ERROR_ALREADY_INITIALIZED);
STR_CASE(SCE_NP_PROFILE_ERROR_NOT_INITIALIZED);
STR_CASE(SCE_NP_PROFILE_ERROR_OUT_OF_MEMORY);
STR_CASE(SCE_NP_PROFILE_ERROR_NOT_SUPPORTED);
STR_CASE(SCE_NP_PROFILE_ERROR_INSUFFICIENT);
STR_CASE(SCE_NP_PROFILE_ERROR_CANCEL);
STR_CASE(SCE_NP_PROFILE_ERROR_STATUS);
STR_CASE(SCE_NP_PROFILE_ERROR_BUSY);
STR_CASE(SCE_NP_PROFILE_ERROR_INVALID_ARGUMENT);
STR_CASE(SCE_NP_PROFILE_ERROR_ABORT);
STR_CASE(SCE_NP_COMMUNITY_ERROR_ALREADY_INITIALIZED);
STR_CASE(SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED);
STR_CASE(SCE_NP_COMMUNITY_ERROR_OUT_OF_MEMORY);
STR_CASE(SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT);
STR_CASE(SCE_NP_COMMUNITY_ERROR_NO_TITLE_SET);
STR_CASE(SCE_NP_COMMUNITY_ERROR_NO_LOGIN);
STR_CASE(SCE_NP_COMMUNITY_ERROR_TOO_MANY_OBJECTS);
STR_CASE(SCE_NP_COMMUNITY_ERROR_TRANSACTION_STILL_REFERENCED);
STR_CASE(SCE_NP_COMMUNITY_ERROR_ABORTED);
STR_CASE(SCE_NP_COMMUNITY_ERROR_NO_RESOURCE);
STR_CASE(SCE_NP_COMMUNITY_ERROR_BAD_RESPONSE);
STR_CASE(SCE_NP_COMMUNITY_ERROR_BODY_TOO_LARGE);
STR_CASE(SCE_NP_COMMUNITY_ERROR_HTTP_SERVER);
STR_CASE(SCE_NP_COMMUNITY_ERROR_INVALID_SIGNATURE);
STR_CASE(SCE_NP_COMMUNITY_ERROR_TIMEOUT);
STR_CASE(SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT);
STR_CASE(SCE_NP_COMMUNITY_ERROR_UNKNOWN_TYPE);
STR_CASE(SCE_NP_COMMUNITY_ERROR_INVALID_ID);
STR_CASE(SCE_NP_COMMUNITY_ERROR_INVALID_ONLINE_ID);
STR_CASE(SCE_NP_COMMUNITY_ERROR_INVALID_TICKET);
STR_CASE(SCE_NP_COMMUNITY_ERROR_CLIENT_HANDLE_ALREADY_EXISTS);
STR_CASE(SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_BUFFER);
STR_CASE(SCE_NP_COMMUNITY_ERROR_INVALID_TYPE);
STR_CASE(SCE_NP_COMMUNITY_ERROR_TRANSACTION_ALREADY_END);
STR_CASE(SCE_NP_COMMUNITY_ERROR_TRANSACTION_BEFORE_END);
STR_CASE(SCE_NP_COMMUNITY_ERROR_BUSY_BY_ANOTEHR_TRANSACTION);
STR_CASE(SCE_NP_COMMUNITY_ERROR_INVALID_ALIGNMENT);
STR_CASE(SCE_NP_COMMUNITY_ERROR_TOO_MANY_NPID);
STR_CASE(SCE_NP_COMMUNITY_ERROR_TOO_LARGE_RANGE);
STR_CASE(SCE_NP_COMMUNITY_ERROR_INVALID_PARTITION);
STR_CASE(SCE_NP_COMMUNITY_ERROR_TOO_MANY_SLOTID);
STR_CASE(SCE_NP_COMMUNITY_SERVER_ERROR_BAD_REQUEST);
STR_CASE(SCE_NP_COMMUNITY_SERVER_ERROR_INVALID_TICKET);
STR_CASE(SCE_NP_COMMUNITY_SERVER_ERROR_INVALID_SIGNATURE);
STR_CASE(SCE_NP_COMMUNITY_SERVER_ERROR_EXPIRED_TICKET);
STR_CASE(SCE_NP_COMMUNITY_SERVER_ERROR_INVALID_NPID);
STR_CASE(SCE_NP_COMMUNITY_SERVER_ERROR_FORBIDDEN);
STR_CASE(SCE_NP_COMMUNITY_SERVER_ERROR_INTERNAL_SERVER_ERROR);
STR_CASE(SCE_NP_COMMUNITY_SERVER_ERROR_VERSION_NOT_SUPPORTED);
STR_CASE(SCE_NP_COMMUNITY_SERVER_ERROR_SERVICE_UNAVAILABLE);
STR_CASE(SCE_NP_COMMUNITY_SERVER_ERROR_PLAYER_BANNED);
STR_CASE(SCE_NP_COMMUNITY_SERVER_ERROR_CENSORED);
STR_CASE(SCE_NP_COMMUNITY_SERVER_ERROR_RANKING_RECORD_FORBIDDEN);
STR_CASE(SCE_NP_COMMUNITY_SERVER_ERROR_USER_PROFILE_NOT_FOUND);
STR_CASE(SCE_NP_COMMUNITY_SERVER_ERROR_UPLOADER_DATA_NOT_FOUND);
STR_CASE(SCE_NP_COMMUNITY_SERVER_ERROR_QUOTA_MASTER_NOT_FOUND);
STR_CASE(SCE_NP_COMMUNITY_SERVER_ERROR_RANKING_TITLE_NOT_FOUND);
STR_CASE(SCE_NP_COMMUNITY_SERVER_ERROR_BLACKLISTED_USER_ID);
STR_CASE(SCE_NP_COMMUNITY_SERVER_ERROR_GAME_RANKING_NOT_FOUND);
STR_CASE(SCE_NP_COMMUNITY_SERVER_ERROR_RANKING_STORE_NOT_FOUND);
STR_CASE(SCE_NP_COMMUNITY_SERVER_ERROR_NOT_BEST_SCORE);
STR_CASE(SCE_NP_COMMUNITY_SERVER_ERROR_LATEST_UPDATE_NOT_FOUND);
STR_CASE(SCE_NP_COMMUNITY_SERVER_ERROR_RANKING_BOARD_MASTER_NOT_FOUND);
STR_CASE(SCE_NP_COMMUNITY_SERVER_ERROR_RANKING_GAME_DATA_MASTER_NOT_FOUND);
STR_CASE(SCE_NP_COMMUNITY_SERVER_ERROR_INVALID_ANTICHEAT_DATA);
STR_CASE(SCE_NP_COMMUNITY_SERVER_ERROR_TOO_LARGE_DATA);
STR_CASE(SCE_NP_COMMUNITY_SERVER_ERROR_NO_SUCH_USER_NPID);
STR_CASE(SCE_NP_COMMUNITY_SERVER_ERROR_INVALID_ENVIRONMENT);
STR_CASE(SCE_NP_COMMUNITY_SERVER_ERROR_INVALID_ONLINE_NAME_CHARACTER);
STR_CASE(SCE_NP_COMMUNITY_SERVER_ERROR_INVALID_ONLINE_NAME_LENGTH);
STR_CASE(SCE_NP_COMMUNITY_SERVER_ERROR_INVALID_ABOUT_ME_CHARACTER);
STR_CASE(SCE_NP_COMMUNITY_SERVER_ERROR_INVALID_ABOUT_ME_LENGTH);
STR_CASE(SCE_NP_COMMUNITY_SERVER_ERROR_INVALID_SCORE);
STR_CASE(SCE_NP_COMMUNITY_SERVER_ERROR_OVER_THE_RANKING_LIMIT);
STR_CASE(SCE_NP_COMMUNITY_SERVER_ERROR_FAIL_TO_CREATE_SIGNATURE);
STR_CASE(SCE_NP_COMMUNITY_SERVER_ERROR_RANKING_MASTER_INFO_NOT_FOUND);
STR_CASE(SCE_NP_COMMUNITY_SERVER_ERROR_OVER_THE_GAME_DATA_LIMIT);
STR_CASE(SCE_NP_COMMUNITY_SERVER_ERROR_SELF_DATA_NOT_FOUND);
STR_CASE(SCE_NP_COMMUNITY_SERVER_ERROR_USER_NOT_ASSIGNED);
STR_CASE(SCE_NP_COMMUNITY_SERVER_ERROR_GAME_DATA_ALREADY_EXISTS);
STR_CASE(SCE_NP_COMMUNITY_SERVER_ERROR_TOO_MANY_RESULTS);
STR_CASE(SCE_NP_COMMUNITY_SERVER_ERROR_NOT_RECORDABLE_VERSION);
STR_CASE(SCE_NP_COMMUNITY_SERVER_ERROR_USER_STORAGE_TITLE_MASTER_NOT_FOUND);
STR_CASE(SCE_NP_COMMUNITY_SERVER_ERROR_INVALID_VIRTUAL_USER);
STR_CASE(SCE_NP_COMMUNITY_SERVER_ERROR_USER_STORAGE_DATA_NOT_FOUND);
STR_CASE(SCE_NP_COMMUNITY_SERVER_ERROR_CONDITIONS_NOT_SATISFIED);
STR_CASE(SCE_NP_COMMUNITY_SERVER_ERROR_MATCHING_BEFORE_SERVICE);
STR_CASE(SCE_NP_COMMUNITY_SERVER_ERROR_MATCHING_END_OF_SERVICE);
STR_CASE(SCE_NP_COMMUNITY_SERVER_ERROR_MATCHING_MAINTENANCE);
STR_CASE(SCE_NP_COMMUNITY_SERVER_ERROR_RANKING_BEFORE_SERVICE);
STR_CASE(SCE_NP_COMMUNITY_SERVER_ERROR_RANKING_END_OF_SERVICE);
STR_CASE(SCE_NP_COMMUNITY_SERVER_ERROR_RANKING_MAINTENANCE);
STR_CASE(SCE_NP_COMMUNITY_SERVER_ERROR_NO_SUCH_TITLE);
STR_CASE(SCE_NP_COMMUNITY_SERVER_ERROR_TITLE_USER_STORAGE_BEFORE_SERVICE);
STR_CASE(SCE_NP_COMMUNITY_SERVER_ERROR_TITLE_USER_STORAGE_END_OF_SERVICE);
STR_CASE(SCE_NP_COMMUNITY_SERVER_ERROR_TITLE_USER_STORAGE_MAINTENANCE);
STR_CASE(SCE_NP_COMMUNITY_SERVER_ERROR_UNSPECIFIED);
STR_CASE(SCE_NP_COMMERCE_ERROR_NOT_INITIALIZED);
STR_CASE(SCE_NP_COMMERCE_ERROR_ALREADY_INITIALIZED);
STR_CASE(SCE_NP_COMMERCE_ERROR_OUT_OF_MEMORY);
STR_CASE(SCE_NP_COMMERCE_ERROR_UNSUPPORTED_VERSION);
STR_CASE(SCE_NP_COMMERCE_ERROR_CTX_MAX);
STR_CASE(SCE_NP_COMMERCE_ERROR_CTX_NOT_FOUND);
STR_CASE(SCE_NP_COMMERCE_ERROR_CTXID_NOT_AVAILABLE);
STR_CASE(SCE_NP_COMMERCE_ERROR_REQ_MAX);
STR_CASE(SCE_NP_COMMERCE_ERROR_REQ_NOT_FOUND);
STR_CASE(SCE_NP_COMMERCE_ERROR_REQID_NOT_AVAILABLE);
STR_CASE(SCE_NP_COMMERCE_ERROR_INVALID_CATEGORY_ID);
STR_CASE(SCE_NP_COMMERCE_ERROR_INVALID_LANG_CODE);
STR_CASE(SCE_NP_COMMERCE_ERROR_REQ_BUSY);
STR_CASE(SCE_NP_COMMERCE_ERROR_INSUFFICIENT_BUFFER);
STR_CASE(SCE_NP_COMMERCE_ERROR_INVALID_REQ_STATE);
STR_CASE(SCE_NP_COMMERCE_ERROR_INVALID_CTX_STATE);
STR_CASE(SCE_NP_COMMERCE_ERROR_UNKNOWN);
STR_CASE(SCE_NP_COMMERCE_ERROR_INVALID_REQ_TYPE);
STR_CASE(SCE_NP_COMMERCE_ERROR_INVALID_MEMORY_CONTAINER);
STR_CASE(SCE_NP_COMMERCE_ERROR_INSUFFICIENT_MEMORY_CONTAINER);
STR_CASE(SCE_NP_COMMERCE_ERROR_INVALID_DATA_FLAG_TYPE);
STR_CASE(SCE_NP_COMMERCE_ERROR_INVALID_DATA_FLAG_STATE);
STR_CASE(SCE_NP_COMMERCE_ERROR_DATA_FLAG_NUM_NOT_FOUND);
STR_CASE(SCE_NP_COMMERCE_ERROR_DATA_FLAG_INFO_NOT_FOUND);
STR_CASE(SCE_NP_COMMERCE_ERROR_INVALID_PROVIDER_ID);
STR_CASE(SCE_NP_COMMERCE_ERROR_INVALID_DATA_FLAG_NUM);
STR_CASE(SCE_NP_COMMERCE_ERROR_INVALID_SKU_ID);
STR_CASE(SCE_NP_COMMERCE_ERROR_INVALID_DATA_FLAG_ID);
STR_CASE(SCE_NP_COMMERCE_ERROR_GPC_SEND_REQUEST);
STR_CASE(SCE_NP_COMMERCE_ERROR_GDF_SEND_REQUEST);
STR_CASE(SCE_NP_COMMERCE_ERROR_SDF_SEND_REQUEST);
STR_CASE(SCE_NP_COMMERCE_ERROR_PARSE_PRODUCT_CATEGORY);
STR_CASE(SCE_NP_COMMERCE_ERROR_CURRENCY_INFO_NOT_FOUND);
STR_CASE(SCE_NP_COMMERCE_ERROR_CATEGORY_INFO_NOT_FOUND);
STR_CASE(SCE_NP_COMMERCE_ERROR_CHILD_CATEGORY_COUNT_NOT_FOUND);
STR_CASE(SCE_NP_COMMERCE_ERROR_CHILD_CATEGORY_INFO_NOT_FOUND);
STR_CASE(SCE_NP_COMMERCE_ERROR_SKU_COUNT_NOT_FOUND);
STR_CASE(SCE_NP_COMMERCE_ERROR_SKU_INFO_NOT_FOUND);
STR_CASE(SCE_NP_COMMERCE_ERROR_PLUGIN_LOAD_FAILURE);
STR_CASE(SCE_NP_COMMERCE_ERROR_INVALID_SKU_NUM);
STR_CASE(SCE_NP_COMMERCE_ERROR_INVALID_GPC_PROTOCOL_VERSION);
STR_CASE(SCE_NP_COMMERCE_ERROR_CHECKOUT_UNEXPECTED);
STR_CASE(SCE_NP_COMMERCE_ERROR_CHECKOUT_OUT_OF_SERVICE);
STR_CASE(SCE_NP_COMMERCE_ERROR_CHECKOUT_INVALID_SKU);
STR_CASE(SCE_NP_COMMERCE_ERROR_CHECKOUT_SERVER_BUSY);
STR_CASE(SCE_NP_COMMERCE_ERROR_CHECKOUT_MAINTENANCE);
STR_CASE(SCE_NP_COMMERCE_ERROR_CHECKOUT_ACCOUNT_SUSPENDED);
STR_CASE(SCE_NP_COMMERCE_ERROR_CHECKOUT_OVER_SPENDING_LIMIT);
STR_CASE(SCE_NP_COMMERCE_ERROR_CHECKOUT_NOT_ENOUGH_MONEY);
STR_CASE(SCE_NP_COMMERCE_ERROR_CHECKOUT_UNKNOWN);
STR_CASE(SCE_NP_COMMERCE_BROWSE_SERVER_ERROR_UNKNOWN);
STR_CASE(SCE_NP_COMMERCE_BROWSE_SERVER_ERROR_INVALID_CREDENTIALS);
STR_CASE(SCE_NP_COMMERCE_BROWSE_SERVER_ERROR_INVALID_CATEGORY_ID);
STR_CASE(SCE_NP_COMMERCE_BROWSE_SERVER_ERROR_SERVICE_END);
STR_CASE(SCE_NP_COMMERCE_BROWSE_SERVER_ERROR_SERVICE_STOP);
STR_CASE(SCE_NP_COMMERCE_BROWSE_SERVER_ERROR_SERVICE_BUSY);
STR_CASE(SCE_NP_COMMERCE_BROWSE_SERVER_ERROR_UNSUPPORTED_VERSION);
STR_CASE(SCE_NP_COMMERCE_BROWSE_SERVER_ERROR_INTERNAL_SERVER);
STR_CASE(SCE_NP_COMMERCE_GDF_SERVER_ERROR_UNKNOWN);
STR_CASE(SCE_NP_COMMERCE_GDF_SERVER_ERROR_INVALID_CREDENTIALS);
STR_CASE(SCE_NP_COMMERCE_GDF_SERVER_ERROR_INVALID_FLAGLIST);
STR_CASE(SCE_NP_COMMERCE_GDF_SERVER_ERROR_SERVICE_END);
STR_CASE(SCE_NP_COMMERCE_GDF_SERVER_ERROR_SERVICE_STOP);
STR_CASE(SCE_NP_COMMERCE_GDF_SERVER_ERROR_SERVICE_BUSY);
STR_CASE(SCE_NP_COMMERCE_GDF_SERVER_ERROR_UNSUPPORTED_VERSION);
STR_CASE(SCE_NP_COMMERCE_SDF_SERVER_ERROR_UNKNOWN);
STR_CASE(SCE_NP_COMMERCE_SDF_SERVER_ERROR_INVALID_CREDENTIALS);
STR_CASE(SCE_NP_COMMERCE_SDF_SERVER_ERROR_INVALID_FLAGLIST);
STR_CASE(SCE_NP_COMMERCE_SDF_SERVER_ERROR_SERVICE_END);
STR_CASE(SCE_NP_COMMERCE_SDF_SERVER_ERROR_SERVICE_STOP);
STR_CASE(SCE_NP_COMMERCE_SDF_SERVER_ERROR_SERVICE_BUSY);
STR_CASE(SCE_NP_COMMERCE_SDF_SERVER_ERROR_UNSUPPORTED_VERSION);
STR_CASE(SCE_NP_DRM_ERROR_LICENSE_NOT_FOUND);
STR_CASE(SCE_NP_DRM_ERROR_OUT_OF_MEMORY);
STR_CASE(SCE_NP_DRM_ERROR_INVALID_PARAM);
STR_CASE(SCE_NP_DRM_ERROR_SERVER_RESPONSE);
STR_CASE(SCE_NP_DRM_ERROR_NO_ENTITLEMENT);
STR_CASE(SCE_NP_DRM_ERROR_BAD_ACT);
STR_CASE(SCE_NP_DRM_ERROR_BAD_FORMAT);
STR_CASE(SCE_NP_DRM_ERROR_NO_LOGIN);
STR_CASE(SCE_NP_DRM_ERROR_INTERNAL);
STR_CASE(SCE_NP_DRM_ERROR_BAD_PERM);
STR_CASE(SCE_NP_DRM_ERROR_UNKNOWN_VERSION);
STR_CASE(SCE_NP_DRM_ERROR_TIME_LIMIT);
STR_CASE(SCE_NP_DRM_ERROR_DIFFERENT_ACCOUNT_ID);
STR_CASE(SCE_NP_DRM_ERROR_DIFFERENT_DRM_TYPE);
STR_CASE(SCE_NP_DRM_ERROR_SERVICE_NOT_STARTED);
STR_CASE(SCE_NP_DRM_ERROR_BUSY);
STR_CASE(SCE_NP_DRM_ERROR_IO);
STR_CASE(SCE_NP_DRM_ERROR_FORMAT);
STR_CASE(SCE_NP_DRM_ERROR_FILENAME);
STR_CASE(SCE_NP_DRM_ERROR_K_LICENSEE);
STR_CASE(SCE_NP_AUTH_EINVAL);
STR_CASE(SCE_NP_AUTH_ENOMEM);
STR_CASE(SCE_NP_AUTH_ESRCH);
STR_CASE(SCE_NP_AUTH_EBUSY);
STR_CASE(SCE_NP_AUTH_EABORT);
STR_CASE(SCE_NP_AUTH_EEXIST);
STR_CASE(SCE_NP_AUTH_EINVALID_ARGUMENT);
STR_CASE(SCE_NP_AUTH_ERROR_SERVICE_END);
STR_CASE(SCE_NP_AUTH_ERROR_SERVICE_DOWN);
STR_CASE(SCE_NP_AUTH_ERROR_SERVICE_BUSY);
STR_CASE(SCE_NP_AUTH_ERROR_SERVER_MAINTENANCE);
STR_CASE(SCE_NP_AUTH_ERROR_INVALID_DATA_LENGTH);
STR_CASE(SCE_NP_AUTH_ERROR_INVALID_USER_AGENT);
STR_CASE(SCE_NP_AUTH_ERROR_INVALID_VERSION);
STR_CASE(SCE_NP_AUTH_ERROR_INVALID_SERVICE_ID);
STR_CASE(SCE_NP_AUTH_ERROR_INVALID_CREDENTIAL);
STR_CASE(SCE_NP_AUTH_ERROR_INVALID_ENTITLEMENT_ID);
STR_CASE(SCE_NP_AUTH_ERROR_INVALID_CONSUMED_COUNT);
STR_CASE(SCE_NP_AUTH_ERROR_INVALID_CONSOLE_ID);
STR_CASE(SCE_NP_AUTH_ERROR_CONSOLE_ID_SUSPENDED);
STR_CASE(SCE_NP_AUTH_ERROR_ACCOUNT_CLOSED);
STR_CASE(SCE_NP_AUTH_ERROR_ACCOUNT_SUSPENDED);
STR_CASE(SCE_NP_AUTH_ERROR_ACCOUNT_RENEW_EULA);
STR_CASE(SCE_NP_AUTH_ERROR_ACCOUNT_RENEW_ACCOUNT1);
STR_CASE(SCE_NP_AUTH_ERROR_ACCOUNT_RENEW_ACCOUNT2);
STR_CASE(SCE_NP_AUTH_ERROR_ACCOUNT_RENEW_ACCOUNT3);
STR_CASE(SCE_NP_AUTH_ERROR_ACCOUNT_RENEW_ACCOUNT4);
STR_CASE(SCE_NP_AUTH_ERROR_ACCOUNT_RENEW_ACCOUNT5);
STR_CASE(SCE_NP_AUTH_ERROR_ACCOUNT_RENEW_ACCOUNT6);
STR_CASE(SCE_NP_AUTH_ERROR_ACCOUNT_RENEW_ACCOUNT7);
STR_CASE(SCE_NP_AUTH_ERROR_ACCOUNT_RENEW_ACCOUNT8);
STR_CASE(SCE_NP_AUTH_ERROR_ACCOUNT_RENEW_ACCOUNT9);
STR_CASE(SCE_NP_AUTH_ERROR_ACCOUNT_RENEW_ACCOUNT10);
STR_CASE(SCE_NP_AUTH_ERROR_ACCOUNT_RENEW_ACCOUNT11);
STR_CASE(SCE_NP_AUTH_ERROR_ACCOUNT_RENEW_ACCOUNT12);
STR_CASE(SCE_NP_AUTH_ERROR_ACCOUNT_RENEW_ACCOUNT13);
STR_CASE(SCE_NP_AUTH_ERROR_ACCOUNT_RENEW_ACCOUNT14);
STR_CASE(SCE_NP_AUTH_ERROR_ACCOUNT_RENEW_ACCOUNT15);
STR_CASE(SCE_NP_AUTH_ERROR_ACCOUNT_RENEW_ACCOUNT16);
STR_CASE(SCE_NP_AUTH_ERROR_UNKNOWN);
STR_CASE(SCE_NP_CORE_UTIL_ERROR_INVALID_ARGUMENT);
STR_CASE(SCE_NP_CORE_UTIL_ERROR_OUT_OF_MEMORY);
STR_CASE(SCE_NP_CORE_UTIL_ERROR_INSUFFICIENT);
STR_CASE(SCE_NP_CORE_UTIL_ERROR_PARSER_FAILED);
STR_CASE(SCE_NP_CORE_UTIL_ERROR_INVALID_PROTOCOL_ID);
STR_CASE(SCE_NP_CORE_UTIL_ERROR_INVALID_EXTENSION);
STR_CASE(SCE_NP_CORE_UTIL_ERROR_INVALID_TEXT);
STR_CASE(SCE_NP_CORE_UTIL_ERROR_UNKNOWN_TYPE);
STR_CASE(SCE_NP_CORE_UTIL_ERROR_UNKNOWN);
STR_CASE(SCE_NP_CORE_PARSER_ERROR_NOT_INITIALIZED);
STR_CASE(SCE_NP_CORE_PARSER_ERROR_ALREADY_INITIALIZED);
STR_CASE(SCE_NP_CORE_PARSER_ERROR_OUT_OF_MEMORY);
STR_CASE(SCE_NP_CORE_PARSER_ERROR_INSUFFICIENT);
STR_CASE(SCE_NP_CORE_PARSER_ERROR_INVALID_FORMAT);
STR_CASE(SCE_NP_CORE_PARSER_ERROR_INVALID_ARGUMENT);
STR_CASE(SCE_NP_CORE_PARSER_ERROR_INVALID_HANDLE);
STR_CASE(SCE_NP_CORE_PARSER_ERROR_INVALID_ICON);
STR_CASE(SCE_NP_CORE_PARSER_ERROR_UNKNOWN);
STR_CASE(SCE_NP_CORE_ERROR_ALREADY_INITIALIZED);
STR_CASE(SCE_NP_CORE_ERROR_NOT_INITIALIZED);
STR_CASE(SCE_NP_CORE_ERROR_INVALID_ARGUMENT);
STR_CASE(SCE_NP_CORE_ERROR_OUT_OF_MEMORY);
STR_CASE(SCE_NP_CORE_ERROR_ID_NOT_AVAILABLE);
STR_CASE(SCE_NP_CORE_ERROR_USER_OFFLINE);
STR_CASE(SCE_NP_CORE_ERROR_SESSION_RUNNING);
STR_CASE(SCE_NP_CORE_ERROR_SESSION_NOT_ESTABLISHED);
STR_CASE(SCE_NP_CORE_ERROR_SESSION_INVALID_STATE);
STR_CASE(SCE_NP_CORE_ERROR_SESSION_ID_TOO_LONG);
STR_CASE(SCE_NP_CORE_ERROR_SESSION_INVALID_NAMESPACE);
STR_CASE(SCE_NP_CORE_ERROR_CONNECTION_TIMEOUT);
STR_CASE(SCE_NP_CORE_ERROR_GETSOCKOPT);
STR_CASE(SCE_NP_CORE_ERROR_SSL_NOT_INITIALIZED);
STR_CASE(SCE_NP_CORE_ERROR_SSL_ALREADY_INITIALIZED);
STR_CASE(SCE_NP_CORE_ERROR_SSL_NO_CERT);
STR_CASE(SCE_NP_CORE_ERROR_SSL_NO_TRUSTWORTHY_CA);
STR_CASE(SCE_NP_CORE_ERROR_SSL_INVALID_CERT);
STR_CASE(SCE_NP_CORE_ERROR_SSL_CERT_VERIFY);
STR_CASE(SCE_NP_CORE_ERROR_SSL_CN_CHECK);
STR_CASE(SCE_NP_CORE_ERROR_SSL_HANDSHAKE_FAILED);
STR_CASE(SCE_NP_CORE_ERROR_SSL_SEND);
STR_CASE(SCE_NP_CORE_ERROR_SSL_RECV);
STR_CASE(SCE_NP_CORE_ERROR_SSL_CREATE_CTX);
STR_CASE(SCE_NP_CORE_ERROR_PARSE_PEM);
STR_CASE(SCE_NP_CORE_ERROR_INVALID_INITIATE_STREAM);
STR_CASE(SCE_NP_CORE_ERROR_SASL_NOT_SUPPORTED);
STR_CASE(SCE_NP_CORE_ERROR_NAMESPACE_ALREADY_EXISTS);
STR_CASE(SCE_NP_CORE_ERROR_FROM_ALREADY_EXISTS);
STR_CASE(SCE_NP_CORE_ERROR_MODULE_NOT_REGISTERED);
STR_CASE(SCE_NP_CORE_ERROR_MODULE_FROM_NOT_FOUND);
STR_CASE(SCE_NP_CORE_ERROR_UNKNOWN_NAMESPACE);
STR_CASE(SCE_NP_CORE_ERROR_INVALID_VERSION);
STR_CASE(SCE_NP_CORE_ERROR_LOGIN_TIMEOUT);
STR_CASE(SCE_NP_CORE_ERROR_TOO_MANY_SESSIONS);
STR_CASE(SCE_NP_CORE_ERROR_SENDLIST_NOT_FOUND);
STR_CASE(SCE_NP_CORE_ERROR_NO_ID);
STR_CASE(SCE_NP_CORE_ERROR_LOAD_CERTS);
STR_CASE(SCE_NP_CORE_ERROR_NET_SELECT);
STR_CASE(SCE_NP_CORE_ERROR_DISCONNECTED);
STR_CASE(SCE_NP_CORE_ERROR_TICKET_TOO_SMALL);
STR_CASE(SCE_NP_CORE_ERROR_INVALID_TICKET);
STR_CASE(SCE_NP_CORE_ERROR_INVALID_ONLINEID);
STR_CASE(SCE_NP_CORE_ERROR_GETHOSTBYNAME);
STR_CASE(SCE_NP_CORE_ERROR_UNDEFINED_STREAM_ERROR);
STR_CASE(SCE_NP_CORE_ERROR_INTERNAL);
STR_CASE(SCE_NP_CORE_ERROR_DNS_HOST_NOT_FOUND);
STR_CASE(SCE_NP_CORE_ERROR_DNS_TRY_AGAIN);
STR_CASE(SCE_NP_CORE_ERROR_DNS_NO_RECOVERY);
STR_CASE(SCE_NP_CORE_ERROR_DNS_NO_DATA);
STR_CASE(SCE_NP_CORE_ERROR_DNS_NO_ADDRESS);
STR_CASE(SCE_NP_CORE_SERVER_ERROR_CONFLICT);
STR_CASE(SCE_NP_CORE_SERVER_ERROR_NOT_AUTHORIZED);
STR_CASE(SCE_NP_CORE_SERVER_ERROR_REMOTE_CONNECTION_FAILED);
STR_CASE(SCE_NP_CORE_SERVER_ERROR_RESOURCE_CONSTRAINT);
STR_CASE(SCE_NP_CORE_SERVER_ERROR_SYSTEM_SHUTDOWN);
STR_CASE(SCE_NP_CORE_SERVER_ERROR_UNSUPPORTED_CLIENT_VERSION);
STR_CASE(SCE_NP_DRM_INSTALL_ERROR_FORMAT);
STR_CASE(SCE_NP_DRM_INSTALL_ERROR_CHECK);
STR_CASE(SCE_NP_DRM_INSTALL_ERROR_UNSUPPORTED);
STR_CASE(SCE_NP_DRM_SERVER_ERROR_SERVICE_IS_END);
STR_CASE(SCE_NP_DRM_SERVER_ERROR_SERVICE_STOP_TEMPORARILY);
STR_CASE(SCE_NP_DRM_SERVER_ERROR_SERVICE_IS_BUSY);
STR_CASE(SCE_NP_DRM_SERVER_ERROR_INVALID_USER_CREDENTIAL);
STR_CASE(SCE_NP_DRM_SERVER_ERROR_INVALID_PRODUCT_ID);
STR_CASE(SCE_NP_DRM_SERVER_ERROR_ACCOUNT_IS_CLOSED);
STR_CASE(SCE_NP_DRM_SERVER_ERROR_ACCOUNT_IS_SUSPENDED);
STR_CASE(SCE_NP_DRM_SERVER_ERROR_ACTIVATED_CONSOLE_IS_FULL);
STR_CASE(SCE_NP_DRM_SERVER_ERROR_CONSOLE_NOT_ACTIVATED);
STR_CASE(SCE_NP_DRM_SERVER_ERROR_PRIMARY_CONSOLE_CANNOT_CHANGED);
STR_CASE(SCE_NP_DRM_SERVER_ERROR_UNKNOWN);
STR_CASE(SCE_NP_SIGNALING_ERROR_NOT_INITIALIZED);
STR_CASE(SCE_NP_SIGNALING_ERROR_ALREADY_INITIALIZED);
STR_CASE(SCE_NP_SIGNALING_ERROR_OUT_OF_MEMORY);
STR_CASE(SCE_NP_SIGNALING_ERROR_CTXID_NOT_AVAILABLE);
STR_CASE(SCE_NP_SIGNALING_ERROR_CTX_NOT_FOUND);
STR_CASE(SCE_NP_SIGNALING_ERROR_REQID_NOT_AVAILABLE);
STR_CASE(SCE_NP_SIGNALING_ERROR_REQ_NOT_FOUND);
STR_CASE(SCE_NP_SIGNALING_ERROR_PARSER_CREATE_FAILED);
STR_CASE(SCE_NP_SIGNALING_ERROR_PARSER_FAILED);
STR_CASE(SCE_NP_SIGNALING_ERROR_INVALID_NAMESPACE);
STR_CASE(SCE_NP_SIGNALING_ERROR_NETINFO_NOT_AVAILABLE);
STR_CASE(SCE_NP_SIGNALING_ERROR_PEER_NOT_RESPONDING);
STR_CASE(SCE_NP_SIGNALING_ERROR_CONNID_NOT_AVAILABLE);
STR_CASE(SCE_NP_SIGNALING_ERROR_CONN_NOT_FOUND);
STR_CASE(SCE_NP_SIGNALING_ERROR_PEER_UNREACHABLE);
STR_CASE(SCE_NP_SIGNALING_ERROR_TERMINATED_BY_PEER);
STR_CASE(SCE_NP_SIGNALING_ERROR_TIMEOUT);
STR_CASE(SCE_NP_SIGNALING_ERROR_CTX_MAX);
STR_CASE(SCE_NP_SIGNALING_ERROR_RESULT_NOT_FOUND);
STR_CASE(SCE_NP_SIGNALING_ERROR_CONN_IN_PROGRESS);
STR_CASE(SCE_NP_SIGNALING_ERROR_INVALID_ARGUMENT);
STR_CASE(SCE_NP_SIGNALING_ERROR_OWN_NP_ID);
STR_CASE(SCE_NP_SIGNALING_ERROR_TOO_MANY_CONN);
STR_CASE(SCE_NP_SIGNALING_ERROR_TERMINATED_BY_MYSELF);
STR_CASE(SCE_NP_CUSTOM_MENU_ERROR_ALREADY_INITIALIZED);
STR_CASE(SCE_NP_CUSTOM_MENU_ERROR_NOT_INITIALIZED);
STR_CASE(SCE_NP_CUSTOM_MENU_ERROR_OUT_OF_MEMORY);
STR_CASE(SCE_NP_CUSTOM_MENU_ERROR_NOT_SUPPORTED);
STR_CASE(SCE_NP_CUSTOM_MENU_ERROR_INSUFFICIENT);
STR_CASE(SCE_NP_CUSTOM_MENU_ERROR_CANCEL);
STR_CASE(SCE_NP_CUSTOM_MENU_ERROR_STATUS);
STR_CASE(SCE_NP_CUSTOM_MENU_ERROR_BUSY);
STR_CASE(SCE_NP_CUSTOM_MENU_ERROR_INVALID_ARGUMENT);
STR_CASE(SCE_NP_CUSTOM_MENU_ERROR_ABORT);
STR_CASE(SCE_NP_CUSTOM_MENU_ERROR_NOT_REGISTERED);
STR_CASE(SCE_NP_CUSTOM_MENU_ERROR_EXCEEDS_MAX);
STR_CASE(SCE_NP_CUSTOM_MENU_ERROR_INVALID_CHARACTER);
STR_CASE(SCE_NP_EULA_ERROR_UNKNOWN);
STR_CASE(SCE_NP_EULA_ERROR_INVALID_ARGUMENT);
STR_CASE(SCE_NP_EULA_ERROR_NOT_INITIALIZED);
STR_CASE(SCE_NP_EULA_ERROR_ALREADY_INITIALIZED);
STR_CASE(SCE_NP_EULA_ERROR_OUT_OF_MEMORY);
STR_CASE(SCE_NP_EULA_ERROR_BUSY);
STR_CASE(SCE_NP_EULA_ERROR_EULA_NOT_FOUND);
STR_CASE(SCE_NP_EULA_ERROR_NET_OUT_OF_MEMORY);
STR_CASE(SCE_NP_EULA_ERROR_CONF_FORMAT);
STR_CASE(SCE_NP_EULA_ERROR_CONF_INVALID_FILENAME);
STR_CASE(SCE_NP_EULA_ERROR_CONF_TOO_MANY_EULA_FILES);
STR_CASE(SCE_NP_EULA_ERROR_CONF_INVALID_LANGUAGE);
STR_CASE(SCE_NP_EULA_ERROR_CONF_INVALID_COUNTRY);
STR_CASE(SCE_NP_EULA_ERROR_CONF_INVALID_NPCOMMID);
STR_CASE(SCE_NP_EULA_ERROR_CONF_INVALID_EULA_VERSION);
STR_CASE(SCE_NP_MATCHING_ERROR_NOT_INITIALIZED);
STR_CASE(SCE_NP_MATCHING_ERROR_ALREADY_INITIALIZED);
STR_CASE(SCE_NP_MATCHING_ERROR_INVALID_ARG);
STR_CASE(SCE_NP_MATCHING_ERROR_TERMINATED);
STR_CASE(SCE_NP_MATCHING_ERROR_TIMEOUT);
STR_CASE(SCE_NP_MATCHING_ERROR_OUT_OF_MEMORY);
STR_CASE(SCE_NP_MATCHING_ERROR_CTXID_NOT_AVAIL);
STR_CASE(SCE_NP_MATCHING_ERROR_CTX_ALREADY_EXIST);
STR_CASE(SCE_NP_MATCHING_ERROR_CTX_NOT_FOUND);
STR_CASE(SCE_NP_MATCHING_ERROR_LOBBY_NOT_FOUND);
STR_CASE(SCE_NP_MATCHING_ERROR_ROOM_NOT_FOUND);
STR_CASE(SCE_NP_MATCHING_ERROR_MEMBER_NOT_FOUND);
STR_CASE(SCE_NP_MATCHING_ERROR_TOO_BIG_VALUE);
STR_CASE(SCE_NP_MATCHING_ERROR_IVALID_ATTR_TYPE);
STR_CASE(SCE_NP_MATCHING_ERROR_INVALID_ATTR_ID);
STR_CASE(SCE_NP_MATCHING_ERROR_ALREADY_REQUESTED);
STR_CASE(SCE_NP_MATCHING_ERROR_LIMITTED_SEATING);
STR_CASE(SCE_NP_MATCHING_ERROR_LOCKED);
STR_CASE(SCE_NP_MATCHING_ERROR_CTX_STILL_RUNNING);
STR_CASE(SCE_NP_MATCHING_ERROR_INSUFFICIENT_BUFFER);
STR_CASE(SCE_NP_MATCHING_ERROR_REQUEST_NOT_ALLOWED);
STR_CASE(SCE_NP_MATCHING_ERROR_CTX_MAX);
STR_CASE(SCE_NP_MATCHING_ERROR_INVALID_REQ_ID);
STR_CASE(SCE_NP_MATCHING_ERROR_RESULT_NOT_FOUND);
STR_CASE(SCE_NP_MATCHING_ERROR_BUSY);
STR_CASE(SCE_NP_MATCHING_ERROR_ALREADY_JOINED_ROOM);
STR_CASE(SCE_NP_MATCHING_ERROR_ROOM_MAX);
STR_CASE(SCE_NP_MATCHING_ERROR_QUICK_MATCH_PLAYER_NOT_FOUND);
STR_CASE(SCE_NP_MATCHING_ERROR_COND_MAX);
STR_CASE(SCE_NP_MATCHING_ERROR_INVALID_COND);
STR_CASE(SCE_NP_MATCHING_ERROR_INVALID_ATTR);
STR_CASE(SCE_NP_MATCHING_ERROR_COMP_OP_INEQUALITY_MAX);
STR_CASE(SCE_NP_MATCHING_ERROR_RESULT_OVERFLOWED);
STR_CASE(SCE_NP_MATCHING_ERROR_HTTPXML_TIMEOUT);
STR_CASE(SCE_NP_MATCHING_ERROR_CANCELED);
STR_CASE(SCE_NP_MATCHING_ERROR_SEARCH_JOIN_ROOM_NOT_FOUND);
STR_CASE(SCE_NP_MATCHING_ERROR_INVALID_COMP_OP);
STR_CASE(SCE_NP_MATCHING_ERROR_INVALID_COMP_TYPE);
STR_CASE(SCE_NP_MATCHING_ERROR_REQUEST_NOT_FOUND);
STR_CASE(SCE_NP_MATCHING_ERROR_INTERNAL_ERROR);
STR_CASE(SCE_NP_MATCHING_ERROR_INVALID_PROTOCOL_ID);
STR_CASE(SCE_NP_MATCHING_ERROR_ATTR_NOT_SPECIFIED);
STR_CASE(SCE_NP_MATCHING_ERROR_SYSUTIL_INVALID_RESULT);
STR_CASE(SCE_NP_MATCHING_ERROR_PLUGIN_LOAD_FAILURE);
STR_CASE(SCE_NP_MATCHING_ERROR_INVALID_ATTR_VALUE);
STR_CASE(SCE_NP_MATCHING_ERROR_DUPLICATE);
STR_CASE(SCE_NP_MATCHING_ERROR_INVALID_MEMORY_CONTAINER);
STR_CASE(SCE_NP_MATCHING_ERROR_SHUTDOWN);
STR_CASE(SCE_NP_MATCHING_ERROR_SYSUTIL_SERVER_BUSY);
STR_CASE(SCE_NP_MATCHING_ERROR_SEND_INVITATION_PARTIALLY_FAILED);
STR_CASE(SCE_NP_MATCHING_ERROR_UTILITY_UNAVAILABLE);
STR_CASE(SCE_NP_MATCHING_SERVER_ERROR_OUT_OF_SERVICE);
STR_CASE(SCE_NP_MATCHING_SERVER_ERROR_MAINTENANCE);
STR_CASE(SCE_NP_MATCHING_SERVER_ERROR_SERVER_BUSY);
STR_CASE(SCE_NP_MATCHING_SERVER_ERROR_ACCESS_FORBIDDEN);
STR_CASE(SCE_NP_MATCHING_SERVER_ERROR_NO_SUCH_SERVER);
STR_CASE(SCE_NP_MATCHING_SERVER_ERROR_NO_SUCH_LOBBY);
STR_CASE(SCE_NP_MATCHING_SERVER_ERROR_NO_SUCH_ROOM);
STR_CASE(SCE_NP_MATCHING_SERVER_ERROR_NO_SUCH_USER);
STR_CASE(SCE_NP_MATCHING_SERVER_ERROR_NOT_ALLOWED);
STR_CASE(SCE_NP_MATCHING_SERVER_ERROR_UNKNOWN);
STR_CASE(SCE_NP_MATCHING_SERVER_ERROR_BAD_REQUEST_STANZA);
STR_CASE(SCE_NP_MATCHING_SERVER_ERROR_REQUEST_FORBIDDEN);
STR_CASE(SCE_NP_MATCHING_SERVER_ERROR_INTERNAL_ERROR);
STR_CASE(SCE_NP_MATCHING_SERVER_ERROR_ROOM_OVER);
STR_CASE(SCE_NP_MATCHING_SERVER_ERROR_ROOM_CLOSED);
}
return unknown;
});
}
void message_data::print() const
{
sceNp.notice("commId: %s, msgId: %d, mainType: %d, subType: %d, subject: %s, body: %s, data_size: %d", static_cast<const char *>(commId.data), msgId, mainType, subType, subject, body, data.size());
}
extern void lv2_sleep(u64 timeout, ppu_thread* ppu = nullptr);
error_code sceNpInit(u32 poolsize, vm::ptr<void> poolptr)
{
sceNp.warning("sceNpInit(poolsize=0x%x, poolptr=*0x%x)", poolsize, poolptr);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
std::lock_guard lock(nph.mutex_status);
if (nph.is_NP_init)
{
return SCE_NP_ERROR_ALREADY_INITIALIZED;
}
if (poolsize == 0 || !poolptr)
{
return SCE_NP_ERROR_INVALID_ARGUMENT;
}
if (poolsize < SCE_NP_MIN_POOL_SIZE)
{
return SCE_NP_ERROR_INSUFFICIENT_BUFFER;
}
nph.init_NP(poolsize, poolptr);
nph.is_NP_init = true;
return CELL_OK;
}
error_code sceNpTerm()
{
sceNp.warning("sceNpTerm()");
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
std::lock_guard lock(nph.mutex_status);
if (!nph.is_NP_init)
{
return SCE_NP_ERROR_NOT_INITIALIZED;
}
nph.terminate_NP();
nph.is_NP_init = false;
idm::clear<signaling_ctx>();
auto& sigh = g_fxo->get<named_thread<signaling_handler>>();
sigh.clear_sig_ctx();
// TODO: Other contexts(special handling for transaction contexts?)
return CELL_OK;
}
error_code npDrmIsAvailable(vm::cptr<u8> k_licensee_addr, vm::cptr<char> drm_path)
{
if (!drm_path)
{
return SCE_NP_DRM_ERROR_INVALID_PARAM;
}
u128 k_licensee{};
if (k_licensee_addr)
{
std::memcpy(&k_licensee, k_licensee_addr.get_ptr(), sizeof(k_licensee));
sceNp.notice("npDrmIsAvailable(): KLicense key or KLIC=%s", std::bit_cast<be_t<u128>>(k_licensee));
}
if (Emu.GetFakeCat() == "PE")
{
std::memcpy(&k_licensee, NP_PSP_KEY_2, sizeof(k_licensee));
sceNp.success("npDrmIsAvailable(): PSP remaster KLicense key applied.");
}
std::string enc_drm_path;
ensure(vm::read_string(drm_path.addr(), 0x100, enc_drm_path, true), "Secret access violation");
sceNp.warning(u8"npDrmIsAvailable(): drm_path=“%s”", enc_drm_path);
auto& npdrmkeys = g_fxo->get<loaded_npdrm_keys>();
const auto [fs_error, ppath, real_path, enc_file, type] = lv2_file::open(enc_drm_path, 0, 0);
if (fs_error)
{
return {fs_error, enc_drm_path};
}
u32 magic;
enc_file.read<u32>(magic);
enc_file.seek(0);
if (magic == "SCE\0"_u32)
{
if (!k_licensee_addr)
k_licensee = get_default_self_klic();
if (verify_npdrm_self_headers(enc_file, reinterpret_cast<u8*>(&k_licensee)))
{
npdrmkeys.install_decryption_key(k_licensee);
}
else
{
sceNp.error(u8"npDrmIsAvailable(): Failed to verify sce file “%s”", enc_drm_path);
return {SCE_NP_DRM_ERROR_NO_ENTITLEMENT, enc_drm_path};
}
}
else if (magic == "NPD\0"_u32)
{
// edata / sdata files
NPD_HEADER npd;
if (VerifyEDATHeaderWithKLicense(enc_file, enc_drm_path, reinterpret_cast<u8*>(&k_licensee), &npd))
{
// Check if RAP-free
if (npd.license == 3)
{
npdrmkeys.install_decryption_key(k_licensee);
}
else
{
const std::string rap_file = rpcs3::utils::get_rap_file_path(npd.content_id);
if (fs::file rap_fd{rap_file})
{
if (rap_fd.size() < sizeof(u128))
{
sceNp.error("npDrmIsAvailable(): Rap file too small: '%s' (%d bytes)", rap_file, rap_fd.size());
return {SCE_NP_DRM_ERROR_BAD_FORMAT, enc_drm_path};
}
npdrmkeys.install_decryption_key(GetEdatRifKeyFromRapFile(rap_fd));
}
else
{
sceNp.error("npDrmIsAvailable(): Rap file not found: '%s' (%s)", rap_file, fs::g_tls_error);
return {SCE_NP_DRM_ERROR_LICENSE_NOT_FOUND, enc_drm_path};
}
}
}
else
{
sceNp.error(u8"npDrmIsAvailable(): Failed to verify npd file “%s”", enc_drm_path);
return {SCE_NP_DRM_ERROR_NO_ENTITLEMENT, enc_drm_path};
}
}
else
{
// for now assume its just unencrypted
sceNp.notice(u8"npDrmIsAvailable(): Assuming npdrm file is unencrypted at “%s”", enc_drm_path);
}
return CELL_OK;
}
error_code sceNpDrmIsAvailable(ppu_thread& ppu, vm::cptr<u8> k_licensee_addr, vm::cptr<char> drm_path)
{
sceNp.warning("sceNpDrmIsAvailable(k_licensee=*0x%x, drm_path=*0x%x)", k_licensee_addr, drm_path);
if (!drm_path)
{
return SCE_NP_DRM_ERROR_INVALID_PARAM;
}
lv2_obj::sleep(ppu);
const auto ret = npDrmIsAvailable(k_licensee_addr, drm_path);
lv2_sleep(25'000, &ppu);
return ret;
}
error_code sceNpDrmIsAvailable2(ppu_thread& ppu, vm::cptr<u8> k_licensee_addr, vm::cptr<char> drm_path)
{
sceNp.warning("sceNpDrmIsAvailable2(k_licensee=*0x%x, drm_path=*0x%x)", k_licensee_addr, drm_path);
if (!drm_path)
{
return SCE_NP_DRM_ERROR_INVALID_PARAM;
}
lv2_obj::sleep(ppu);
const auto ret = npDrmIsAvailable(k_licensee_addr, drm_path);
// TODO: Accurate sleep time
//lv2_sleep(20000, &ppu);
return ret;
}
error_code npDrmVerifyUpgradeLicense(vm::cptr<char> content_id)
{
if (!content_id)
{
return SCE_NP_DRM_ERROR_INVALID_PARAM;
}
std::string content_str;
ensure(vm::read_string(content_id.addr(), 0x2f, content_str, true), "Secret access violation");
sceNp.warning("npDrmVerifyUpgradeLicense(): content_id=%s", content_str);
if (!rpcs3::utils::verify_c00_unlock_edat(content_str))
return SCE_NP_DRM_ERROR_LICENSE_NOT_FOUND;
return CELL_OK;
}
error_code sceNpDrmVerifyUpgradeLicense(vm::cptr<char> content_id)
{
sceNp.warning("sceNpDrmVerifyUpgradeLicense(content_id=*0x%x)", content_id);
return npDrmVerifyUpgradeLicense(content_id);
}
error_code sceNpDrmVerifyUpgradeLicense2(vm::cptr<char> content_id)
{
sceNp.warning("sceNpDrmVerifyUpgradeLicense2(content_id=*0x%x)", content_id);
return npDrmVerifyUpgradeLicense(content_id);
}
error_code sceNpDrmExecuteGamePurchase()
{
sceNp.todo("sceNpDrmExecuteGamePurchase()");
// TODO:
// 0. Check if the game can be purchased (return GAME_ERR_NOT_XMBBUY_CONTENT otherwise)
// 1. Send game termination request
// 2. "Buy game" transaction (a.k.a. do nothing for now)
// 3. Reboot game with CELL_GAME_ATTRIBUTE_XMBBUY attribute set (cellGameBootCheck)
return CELL_OK;
}
error_code sceNpDrmGetTimelimit(vm::cptr<char> path, vm::ptr<u64> time_remain)
{
sceNp.warning("sceNpDrmGetTimelimit(path=%s, time_remain=*0x%x)", path, time_remain);
if (!path || !time_remain)
{
return SCE_NP_DRM_ERROR_INVALID_PARAM;
}
vm::var<s64> sec;
vm::var<s64> nsec;
// Get system time (real or fake) to compare to
error_code ret = sys_time_get_current_time(sec, nsec);
if (ret != CELL_OK)
{
return ret;
}
std::string enc_drm_path;
ensure(vm::read_string(path.addr(), 0x100, enc_drm_path, true), "Secret access violation");
const auto [fs_error, ppath, real_path, enc_file, type] = lv2_file::open(enc_drm_path, 0, 0);
if (fs_error)
{
return {fs_error, enc_drm_path};
}
u32 magic;
NPD_HEADER npd;
enc_file.read<u32>(magic);
enc_file.seek(0);
// Read expiration time from NPD header which is Unix timestamp in milliseconds
if (magic == "SCE\0"_u32)
{
if (!get_npdrm_self_header(enc_file, npd))
{
sceNp.error("sceNpDrmGetTimelimit(): Failed to read NPD header from sce file '%s'", enc_drm_path);
return {SCE_NP_DRM_ERROR_BAD_FORMAT, enc_drm_path};
}
}
else if (magic == "NPD\0"_u32)
{
// edata / sdata files
EDAT_HEADER edat;
read_npd_edat_header(&enc_file, npd, edat);
}
else
{
// Unknown file type
return {SCE_NP_DRM_ERROR_BAD_FORMAT, enc_drm_path};
}
// Convert time to milliseconds
s64 msec = *sec * 1000ll + *nsec / 1000ll;
// Return the remaining time in microseconds
if (npd.activate_time != 0 && msec < npd.activate_time)
{
return SCE_NP_DRM_ERROR_SERVICE_NOT_STARTED;
}
if (npd.expire_time == 0)
{
*time_remain = SCE_NP_DRM_TIME_INFO_ENDLESS;
return CELL_OK;
}
if (msec >= npd.expire_time)
{
return SCE_NP_DRM_ERROR_TIME_LIMIT;
}
*time_remain = (npd.expire_time - msec) * 1000ll;
return CELL_OK;
}
error_code sceNpDrmProcessExitSpawn(ppu_thread& ppu, vm::cptr<u8> klicensee, vm::cptr<char> path, vm::cpptr<char> argv, vm::cpptr<char> envp, u32 data, u32 data_size, s32 prio, u64 flags)
{
sceNp.warning("sceNpDrmProcessExitSpawn(klicensee=*0x%x, path=*0x%x, argv=**0x%x, envp=**0x%x, data=*0x%x, data_size=0x%x, prio=%d, flags=0x%x)", klicensee, path, argv, envp, data, data_size, prio, flags);
if (s32 error = npDrmIsAvailable(klicensee, path))
{
return error;
}
ppu_execute<&sys_game_process_exitspawn>(ppu, path, argv, envp, data, data_size, prio, flags);
return CELL_OK;
}
error_code sceNpDrmProcessExitSpawn2(ppu_thread& ppu, vm::cptr<u8> klicensee, vm::cptr<char> path, vm::cpptr<char> argv, vm::cpptr<char> envp, u32 data, u32 data_size, s32 prio, u64 flags)
{
sceNp.warning("sceNpDrmProcessExitSpawn2(klicensee=*0x%x, path=*0x%x, argv=**0x%x, envp=**0x%x, data=*0x%x, data_size=0x%x, prio=%d, flags=0x%x)", klicensee, path, argv, envp, data, data_size, prio, flags);
if (s32 error = npDrmIsAvailable(klicensee, path))
{
return error;
}
// TODO: check if SCE_NP_DRM_EXITSPAWN2_EXIT_WO_FINI logic is implemented
ppu_execute<&sys_game_process_exitspawn2>(ppu, path, argv, envp, data, data_size, prio, flags);
return CELL_OK;
}
error_code sceNpBasicRegisterHandler(vm::cptr<SceNpCommunicationId> context, vm::ptr<SceNpBasicEventHandler> handler, vm::ptr<void> arg)
{
sceNp.warning("sceNpBasicRegisterHandler(context=*0x%x(%s), handler=*0x%x, arg=*0x%x)", context, context ? context->data : "", handler, arg);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_BASIC_ERROR_NOT_INITIALIZED;
}
if (nph.basic_handler_registered)
{
return SCE_NP_BASIC_ERROR_EXCEEDS_MAX;
}
if (!context || !handler)
{
return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT;
}
nph.register_basic_handler(context, handler, arg, false);
return CELL_OK;
}
error_code sceNpBasicRegisterContextSensitiveHandler(vm::cptr<SceNpCommunicationId> context, vm::ptr<SceNpBasicEventHandler> handler, vm::ptr<void> arg)
{
sceNp.notice("sceNpBasicRegisterContextSensitiveHandler(context=*0x%x(%s), handler=*0x%x, arg=*0x%x)", context, context ? context->data : "", handler, arg);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_BASIC_ERROR_NOT_INITIALIZED;
}
if (nph.basic_handler_registered)
{
return SCE_NP_BASIC_ERROR_EXCEEDS_MAX;
}
if (!context || !handler)
{
return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT;
}
nph.register_basic_handler(context, handler, arg, true);
return CELL_OK;
}
error_code sceNpBasicUnregisterHandler()
{
sceNp.notice("sceNpBasicUnregisterHandler()");
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_BASIC_ERROR_NOT_INITIALIZED;
}
if (!nph.basic_handler_registered)
{
return SCE_NP_BASIC_ERROR_NOT_REGISTERED;
}
nph.basic_handler_registered = false;
return CELL_OK;
}
error_code sceNpBasicSetPresence(vm::cptr<u8> data, u32 size)
{
sceNp.warning("sceNpBasicSetPresence(data=*0x%x, size=%d)", data, size);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_BASIC_ERROR_NOT_INITIALIZED;
}
if (!nph.basic_handler_registered)
{
return SCE_NP_BASIC_ERROR_NOT_REGISTERED;
}
if (size > SCE_NP_BASIC_MAX_PRESENCE_SIZE)
{
return SCE_NP_BASIC_ERROR_EXCEEDS_MAX;
}
// Not checked by API
ensure(data || !size, "Access violation");
std::vector pr_data(data.get_ptr(), data.get_ptr() + size);
nph.set_presence(std::nullopt, pr_data);
return CELL_OK;
}
error_code sceNpBasicSetPresenceDetails(vm::cptr<SceNpBasicPresenceDetails> pres, u32 options)
{
sceNp.warning("sceNpBasicSetPresenceDetails(pres=*0x%x, options=0x%x)", pres, options);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_BASIC_ERROR_NOT_INITIALIZED;
}
if (!nph.basic_handler_registered)
{
return SCE_NP_BASIC_ERROR_NOT_REGISTERED;
}
if (options < SCE_NP_BASIC_PRESENCE_OPTIONS_SET_DATA || options > SCE_NP_BASIC_PRESENCE_OPTIONS_ALL_OPTIONS)
{
return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT;
}
// Not checked by API
ensure(pres, "Access violation");
if (pres->size > SCE_NP_BASIC_MAX_PRESENCE_SIZE)
{
return SCE_NP_BASIC_ERROR_EXCEEDS_MAX;
}
std::optional<std::string> pr_status;
if (options & SCE_NP_BASIC_PRESENCE_OPTIONS_SET_STATUS)
{
pr_status = std::optional(std::string(reinterpret_cast<const char*>(&pres->status[0])));
}
std::optional<std::vector<u8>> pr_data;
if (options & SCE_NP_BASIC_PRESENCE_OPTIONS_SET_DATA)
{
const u8* ptr = &pres->data[0];
pr_data = std::vector(ptr, ptr + pres->size);
}
nph.set_presence(pr_status, pr_data);
return CELL_OK;
}
error_code sceNpBasicSetPresenceDetails2(vm::cptr<SceNpBasicPresenceDetails2> pres, u32 options)
{
sceNp.warning("sceNpBasicSetPresenceDetails2(pres=*0x%x, options=0x%x)", pres, options);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_BASIC_ERROR_NOT_INITIALIZED;
}
if (!nph.basic_handler_registered)
{
return SCE_NP_BASIC_ERROR_NOT_REGISTERED;
}
if (options < SCE_NP_BASIC_PRESENCE_OPTIONS_SET_DATA || options > SCE_NP_BASIC_PRESENCE_OPTIONS_ALL_OPTIONS || pres->struct_size != sizeof(SceNpBasicPresenceDetails2))
{
return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT;
}
// Not checked by API
ensure(pres, "Access violation");
if (pres->size > SCE_NP_BASIC_MAX_PRESENCE_SIZE)
{
return SCE_NP_BASIC_ERROR_EXCEEDS_MAX;
}
std::optional<std::string> pr_status;
if (options & SCE_NP_BASIC_PRESENCE_OPTIONS_SET_STATUS)
{
pr_status = std::optional(std::string(reinterpret_cast<const char*>(&pres->status[0])));
}
std::optional<std::vector<u8>> pr_data;
if (options & SCE_NP_BASIC_PRESENCE_OPTIONS_SET_DATA)
{
const u8* ptr = &pres->data[0];
pr_data = std::vector(ptr, ptr + pres->size);
}
nph.set_presence(pr_status, pr_data);
return CELL_OK;
}
error_code sceNpBasicSendMessage(vm::cptr<SceNpId> to, vm::cptr<void> data, u32 size)
{
sceNp.warning("sceNpBasicSendMessage(to=*0x%x, data=*0x%x, size=%d)", to, data, size);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_BASIC_ERROR_NOT_INITIALIZED;
}
if (!nph.basic_handler_registered)
{
return SCE_NP_BASIC_ERROR_NOT_REGISTERED;
}
if (!to || to->handle.data[0] == '\0' || !data || !size)
{
return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT;
}
if (size > SCE_NP_BASIC_MAX_MESSAGE_SIZE)
{
return SCE_NP_BASIC_ERROR_EXCEEDS_MAX;
}
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return not_an_error(SCE_NP_BASIC_ERROR_NOT_CONNECTED);
}
message_data msg_data = {
.commId = nph.get_basic_handler_context(),
.msgId = 0,
.mainType = SCE_NP_BASIC_MESSAGE_MAIN_TYPE_GENERAL,
.subType = SCE_NP_BASIC_MESSAGE_GENERAL_SUBTYPE_NONE,
.msgFeatures = {},
.data = std::vector<u8>(static_cast<const u8*>(data.get_ptr()), static_cast<const u8*>(data.get_ptr()) + size)};
std::set<std::string> npids;
npids.insert(std::string(to->handle.data));
nph.send_message(msg_data, npids);
return CELL_OK;
}
error_code sceNpBasicSendMessageGui(ppu_thread& ppu, vm::cptr<SceNpBasicMessageDetails> msg, sys_memory_container_t containerId)
{
sceNp.warning("sceNpBasicSendMessageGui(msg=*0x%x, containerId=%d)", msg, containerId);
if (msg)
{
sceNp.notice("sceNpBasicSendMessageGui: msgId: %d, mainType: %d, subType: %d, msgFeatures: %d, count: %d, npids: *0x%x", msg->msgId, msg->mainType, msg->subType, msg->msgFeatures, msg->count, msg->npids);
for (u32 i = 0; i < msg->count && msg->npids; i++)
{
sceNp.trace("sceNpBasicSendMessageGui: NpId[%d] = %s", i, static_cast<char*>(&msg->npids[i].handle.data[0]));
}
sceNp.notice("sceNpBasicSendMessageGui: subject: %s", msg->subject);
sceNp.notice("sceNpBasicSendMessageGui: body: %s", msg->body);
}
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_BASIC_ERROR_NOT_INITIALIZED;
}
if (!nph.basic_handler_registered)
{
return SCE_NP_BASIC_ERROR_NOT_REGISTERED;
}
if (!msg || msg->count > SCE_NP_BASIC_SEND_MESSAGE_MAX_RECIPIENTS || (msg->msgFeatures & ~SCE_NP_BASIC_MESSAGE_FEATURES_ALL_FEATURES) ||
msg->mainType > SCE_NP_BASIC_MESSAGE_MAIN_TYPE_URL_ATTACHMENT || msg->msgId != 0ull)
{
return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT;
}
if (!(msg->msgFeatures & SCE_NP_BASIC_MESSAGE_FEATURES_BOOTABLE))
{
switch (msg->mainType)
{
case SCE_NP_BASIC_MESSAGE_MAIN_TYPE_DATA_ATTACHMENT:
if (msg->subType != SCE_NP_BASIC_MESSAGE_DATA_ATTACHMENT_SUBTYPE_ACTION_USE)
return SCE_NP_BASIC_ERROR_NOT_SUPPORTED;
break;
case SCE_NP_BASIC_MESSAGE_MAIN_TYPE_CUSTOM_DATA:
if (msg->subType != SCE_NP_BASIC_MESSAGE_CUSTOM_DATA_SUBTYPE_ACTION_USE)
return SCE_NP_BASIC_ERROR_NOT_SUPPORTED;
break;
case SCE_NP_BASIC_MESSAGE_MAIN_TYPE_URL_ATTACHMENT:
if (msg->subType != SCE_NP_BASIC_MESSAGE_URL_ATTACHMENT_SUBTYPE_ACTION_USE)
return SCE_NP_BASIC_ERROR_NOT_SUPPORTED;
break;
case SCE_NP_BASIC_MESSAGE_MAIN_TYPE_GENERAL:
case SCE_NP_BASIC_MESSAGE_MAIN_TYPE_ADD_FRIEND:
if (msg->subType != 0) // SCE_NP_BASIC_MESSAGE_GENERAL_SUBTYPE_NONE, SCE_NP_BASIC_MESSAGE_ADD_FRIEND_SUBTYPE_NONE
return SCE_NP_BASIC_ERROR_NOT_SUPPORTED;
if (msg->data)
return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT;
break;
case SCE_NP_BASIC_MESSAGE_MAIN_TYPE_INVITE:
if (msg->subType > SCE_NP_BASIC_MESSAGE_INVITE_SUBTYPE_ACTION_ACCEPT)
return SCE_NP_BASIC_ERROR_NOT_SUPPORTED;
break;
default:
return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT;
}
}
else if (msg->mainType == SCE_NP_BASIC_MESSAGE_MAIN_TYPE_INVITE)
{
if (msg->subType != SCE_NP_BASIC_MESSAGE_INVITE_SUBTYPE_ACTION_ACCEPT)
return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT;
}
else if (msg->mainType == SCE_NP_BASIC_MESSAGE_MAIN_TYPE_CUSTOM_DATA)
{
if (msg->subType != SCE_NP_BASIC_MESSAGE_CUSTOM_DATA_SUBTYPE_ACTION_USE)
return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT;
}
else
{
return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT;
}
if (!msg->data && msg->mainType != SCE_NP_BASIC_MESSAGE_MAIN_TYPE_ADD_FRIEND)
return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT;
if (!msg->size)
return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT;
if (msg->count > SCE_NP_BASIC_SEND_MESSAGE_MAX_RECIPIENTS)
return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT;
if (msg->mainType == SCE_NP_BASIC_MESSAGE_MAIN_TYPE_ADD_FRIEND && msg->count != 1u)
return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT;
if (msg->npids)
{
for (u32 i = 0; i < msg->count; i++)
{
if (!msg->npids[i].handle.data[0])
return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT;
}
}
u32 length_subject = 0;
u32 length_body = 0;
if (msg->subject)
{
if (msg->mainType == SCE_NP_BASIC_MESSAGE_MAIN_TYPE_ADD_FRIEND)
return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT;
error_code err = check_text(msg->subject);
if (err < 0)
return err;
length_subject = static_cast<u32>(err);
if (length_subject > SCE_NP_BASIC_SUBJECT_CHARACTER_MAX)
return SCE_NP_BASIC_ERROR_EXCEEDS_MAX;
}
if (msg->body)
{
error_code err = check_text(msg->body);
if (err < 0)
return err;
length_body = static_cast<u32>(err);
if (length_body > SCE_NP_BASIC_BODY_CHARACTER_MAX)
return SCE_NP_BASIC_ERROR_EXCEEDS_MAX;
}
switch (msg->mainType)
{
case SCE_NP_BASIC_MESSAGE_MAIN_TYPE_DATA_ATTACHMENT:
case SCE_NP_BASIC_MESSAGE_MAIN_TYPE_CUSTOM_DATA:
if (msg->size > SCE_NP_BASIC_MAX_MESSAGE_ATTACHMENT_SIZE)
return SCE_NP_BASIC_ERROR_EXCEEDS_MAX;
break;
case SCE_NP_BASIC_MESSAGE_MAIN_TYPE_INVITE:
if (msg->size > SCE_NP_BASIC_MAX_INVITATION_DATA_SIZE)
return SCE_NP_BASIC_ERROR_EXCEEDS_MAX;
break;
case SCE_NP_BASIC_MESSAGE_MAIN_TYPE_URL_ATTACHMENT:
if (msg->size > SCE_NP_BASIC_MAX_URL_ATTACHMENT_SIZE)
return SCE_NP_BASIC_ERROR_EXCEEDS_MAX;
break;
default:
break;
}
if (msg->msgFeatures & SCE_NP_BASIC_MESSAGE_FEATURES_ASSUME_SEND)
{
if (msg->mainType > SCE_NP_BASIC_MESSAGE_MAIN_TYPE_CUSTOM_DATA)
return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT;
if (!msg->count || !length_body)
return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT;
if (msg->mainType != SCE_NP_BASIC_MESSAGE_MAIN_TYPE_ADD_FRIEND && !length_subject)
return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT;
}
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return not_an_error(SCE_NP_BASIC_ERROR_NOT_CONNECTED);
}
// Prepare message data
message_data msg_data = {
.commId = nph.get_basic_handler_context(),
.msgId = msg->msgId,
.mainType = msg->mainType,
.subType = msg->subType,
.msgFeatures = msg->msgFeatures};
std::set<std::string> npids;
if (msg->npids)
{
for (u32 i = 0; i < msg->count; i++)
{
npids.insert(std::string(msg->npids[i].handle.data));
}
}
if (msg->subject)
{
msg_data.subject = std::string(msg->subject.get_ptr());
}
if (msg->body)
{
msg_data.body = std::string(msg->body.get_ptr());
}
if (msg->size)
{
msg_data.data.assign(msg->data.get_ptr(), msg->data.get_ptr() + msg->size);
}
sceNp.trace("Message Data:\n%s", fmt::buf_to_hexstring(msg->data.get_ptr(), msg->size));
error_code result = CELL_CANCEL;
ppu.state += cpu_flag::wait;
if (auto manager = g_fxo->try_get<rsx::overlays::display_manager>())
{
auto recv_dlg = manager->create<rsx::overlays::sendmessage_dialog>();
result = recv_dlg->Exec(msg_data, npids);
}
else
{
input::SetIntercepted(true);
Emu.BlockingCallFromMainThread([=, &result, msg_data = std::move(msg_data), npids = std::move(npids)]() mutable
{
auto send_dlg = Emu.GetCallbacks().get_sendmessage_dialog();
result = send_dlg->Exec(msg_data, npids);
});
input::SetIntercepted(false);
}
s32 callback_result = result == CELL_OK ? 0 : -1;
s32 event = 0;
switch (msg->mainType)
{
case SCE_NP_BASIC_MESSAGE_MAIN_TYPE_DATA_ATTACHMENT:
event = SCE_NP_BASIC_EVENT_SEND_ATTACHMENT_RESULT;
break;
case SCE_NP_BASIC_MESSAGE_MAIN_TYPE_GENERAL:
event = SCE_NP_BASIC_EVENT_SEND_MESSAGE_RESULT;
break;
case SCE_NP_BASIC_MESSAGE_MAIN_TYPE_ADD_FRIEND:
event = SCE_NP_BASIC_EVENT_ADD_FRIEND_RESULT;
break;
case SCE_NP_BASIC_MESSAGE_MAIN_TYPE_INVITE:
event = SCE_NP_BASIC_EVENT_SEND_INVITATION_RESULT;
break;
case SCE_NP_BASIC_MESSAGE_MAIN_TYPE_CUSTOM_DATA:
event = SCE_NP_BASIC_EVENT_SEND_CUSTOM_DATA_RESULT;
break;
case SCE_NP_BASIC_MESSAGE_MAIN_TYPE_URL_ATTACHMENT:
event = SCE_NP_BASIC_EVENT_SEND_URL_ATTACHMENT_RESULT;
break;
}
nph.send_basic_event(event, callback_result, 0);
return CELL_OK;
}
error_code sceNpBasicSendMessageAttachment(ppu_thread& ppu, vm::cptr<SceNpId> to, vm::cptr<char> subject, vm::cptr<char> body, vm::cptr<void> data, u32 size, sys_memory_container_t containerId)
{
sceNp.warning("sceNpBasicSendMessageAttachment(to=*0x%x, subject=%s, body=%s, data=%s, size=%d, containerId=%d)", to, subject, body, data, size, containerId);
vm::var<SceNpBasicMessageDetails> msg;
msg->msgId = 0;
msg->mainType = SCE_NP_BASIC_MESSAGE_MAIN_TYPE_DATA_ATTACHMENT;
msg->subType = SCE_NP_BASIC_MESSAGE_DATA_ATTACHMENT_SUBTYPE_ACTION_USE;
msg->msgFeatures = 0;
msg->npids = vm::const_ptr_cast<SceNpId>(to);
msg->count = 1;
msg->subject = vm::const_ptr_cast<char>(subject);
msg->body = vm::const_ptr_cast<char>(body);
msg->data = vm::static_ptr_cast<u8>(vm::const_ptr_cast<void>(data));
msg->size = size;
return sceNpBasicSendMessageGui(ppu, msg, containerId);
}
error_code recv_message_gui(ppu_thread& ppu, u16 mainType, u32 recvOptions);
error_code sceNpBasicRecvMessageAttachment(ppu_thread& ppu, sys_memory_container_t containerId)
{
sceNp.warning("sceNpBasicRecvMessageAttachment(containerId=%d)", containerId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_BASIC_ERROR_NOT_INITIALIZED;
}
if (!nph.basic_handler_registered)
{
return SCE_NP_BASIC_ERROR_NOT_REGISTERED;
}
const u16 main_type = SCE_NP_BASIC_MESSAGE_MAIN_TYPE_DATA_ATTACHMENT;
const u32 options = 0;
return recv_message_gui(ppu, main_type, options);
}
error_code sceNpBasicRecvMessageAttachmentLoad(SceNpBasicAttachmentDataId id, vm::ptr<void> buffer, vm::ptr<u32> size)
{
sceNp.warning("sceNpBasicRecvMessageAttachmentLoad(id=%d, buffer=*0x%x, size=*0x%x)", id, buffer, size);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_BASIC_ERROR_NOT_INITIALIZED;
}
if (!nph.basic_handler_registered)
{
return SCE_NP_BASIC_ERROR_NOT_REGISTERED;
}
if (!buffer || !size)
{
return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT;
}
if (id != SCE_NP_BASIC_SELECTED_INVITATION_DATA && id != SCE_NP_BASIC_SELECTED_MESSAGE_DATA)
{
return SCE_NP_BASIC_ERROR_INVALID_DATA_ID;
}
const auto opt_msg = nph.get_message_selected(id);
if (!opt_msg)
{
return SCE_NP_BASIC_ERROR_INVALID_DATA_ID;
}
// Not sure about this
// nph.clear_message_selected(id);
const auto msg_pair = opt_msg.value();
const auto msg = msg_pair->second;
const u32 orig_size = *size;
const u32 size_to_copy = std::min(static_cast<u32>(msg.data.size()), orig_size);
memcpy(buffer.get_ptr(), msg.data.data(), size_to_copy);
sceNp.trace("Message Data received:\n%s", fmt::buf_to_hexstring(static_cast<u8*>(buffer.get_ptr()), size_to_copy));
*size = size_to_copy;
if (size_to_copy < msg.data.size())
{
return SCE_NP_BASIC_ERROR_DATA_LOST;
}
return CELL_OK;
}
error_code sceNpBasicRecvMessageCustom(ppu_thread& ppu, u16 mainType, u32 recvOptions, sys_memory_container_t containerId)
{
sceNp.warning("sceNpBasicRecvMessageCustom(mainType=%d, recvOptions=%d, containerId=%d)", mainType, recvOptions, containerId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_BASIC_ERROR_NOT_INITIALIZED;
}
if (!nph.basic_handler_registered)
{
return SCE_NP_BASIC_ERROR_NOT_REGISTERED;
}
if (mainType != SCE_NP_BASIC_MESSAGE_MAIN_TYPE_INVITE && mainType != SCE_NP_BASIC_MESSAGE_MAIN_TYPE_CUSTOM_DATA)
{
return SCE_NP_BASIC_ERROR_NOT_SUPPORTED;
}
if ((recvOptions & ~SCE_NP_BASIC_RECV_MESSAGE_OPTIONS_ALL_OPTIONS))
{
return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT;
}
return recv_message_gui(ppu, mainType, recvOptions);
}
error_code recv_message_gui(ppu_thread& ppu, u16 mainType, u32 recvOptions)
{
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
error_code result = CELL_CANCEL;
SceNpBasicMessageRecvAction recv_result{};
u64 chosen_msg_id{};
ppu.state += cpu_flag::wait;
if (auto manager = g_fxo->try_get<rsx::overlays::display_manager>())
{
auto recv_dlg = manager->create<rsx::overlays::recvmessage_dialog>();
result = recv_dlg->Exec(static_cast<SceNpBasicMessageMainType>(mainType), static_cast<SceNpBasicMessageRecvOptions>(recvOptions), recv_result, chosen_msg_id);
}
else
{
input::SetIntercepted(true);
Emu.BlockingCallFromMainThread([=, &result, &recv_result, &chosen_msg_id]()
{
auto recv_dlg = Emu.GetCallbacks().get_recvmessage_dialog();
result = recv_dlg->Exec(static_cast<SceNpBasicMessageMainType>(mainType), static_cast<SceNpBasicMessageRecvOptions>(recvOptions), recv_result, chosen_msg_id);
});
input::SetIntercepted(false);
}
if (result != CELL_OK)
{
return not_an_error(SCE_NP_BASIC_ERROR_CANCEL);
}
const auto opt_msg = nph.get_message(chosen_msg_id);
if (!opt_msg)
{
sceNp.fatal("sceNpBasicRecvMessageCustom: message is invalid: chosen_msg_id=%d", chosen_msg_id);
return SCE_NP_BASIC_ERROR_CANCEL;
}
const auto msg_pair = opt_msg.value();
const auto& msg = msg_pair->second;
u32 event_to_send;
SceNpBasicAttachmentData data{};
data.size = static_cast<u32>(msg.data.size());
switch (mainType)
{
case SCE_NP_BASIC_MESSAGE_MAIN_TYPE_DATA_ATTACHMENT:
event_to_send = SCE_NP_BASIC_EVENT_RECV_ATTACHMENT_RESULT;
data.id = SCE_NP_BASIC_SELECTED_MESSAGE_DATA;
break;
case SCE_NP_BASIC_MESSAGE_MAIN_TYPE_INVITE:
event_to_send = SCE_NP_BASIC_EVENT_RECV_INVITATION_RESULT;
data.id = SCE_NP_BASIC_SELECTED_INVITATION_DATA;
break;
case SCE_NP_BASIC_MESSAGE_MAIN_TYPE_CUSTOM_DATA:
event_to_send = SCE_NP_BASIC_EVENT_RECV_CUSTOM_DATA_RESULT;
data.id = SCE_NP_BASIC_SELECTED_MESSAGE_DATA;
break;
default:
fmt::throw_exception("recv_message_gui: Unexpected main type %d", mainType);
}
np::basic_event to_add{};
to_add.event = event_to_send;
strcpy_trunc(to_add.from.userId.handle.data, msg_pair->first);
strcpy_trunc(to_add.from.name.data, msg_pair->first);
if (mainType == SCE_NP_BASIC_MESSAGE_MAIN_TYPE_DATA_ATTACHMENT)
{
to_add.data.resize(sizeof(SceNpBasicAttachmentData));
SceNpBasicAttachmentData* att_data = reinterpret_cast<SceNpBasicAttachmentData*>(to_add.data.data());
*att_data = data;
extra_nps::print_SceNpBasicAttachmentData(att_data);
}
else
{
to_add.data.resize(sizeof(SceNpBasicExtendedAttachmentData));
SceNpBasicExtendedAttachmentData* att_data = reinterpret_cast<SceNpBasicExtendedAttachmentData*>(to_add.data.data());
att_data->flags = 0; // ?
att_data->msgId = chosen_msg_id;
att_data->data = data;
att_data->userAction = recv_result;
att_data->markedAsUsed = (recvOptions & SCE_NP_BASIC_RECV_MESSAGE_OPTIONS_PRESERVE) ? 0 : 1;
extra_nps::print_SceNpBasicExtendedAttachmentData(att_data);
}
nph.set_message_selected(data.id, chosen_msg_id);
// Is this sent if used from home menu but not from sceNpBasicRecvMessageCustom, not sure
// sysutil_send_system_cmd(CELL_SYSUTIL_NP_INVITATION_SELECTED, 0);
nph.queue_basic_event(to_add);
nph.send_basic_event(event_to_send, 0, 0);
return CELL_OK;
}
error_code sceNpBasicMarkMessageAsUsed(SceNpBasicMessageId msgId)
{
sceNp.todo("sceNpBasicMarkMessageAsUsed(msgId=%d)", msgId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_BASIC_ERROR_NOT_INITIALIZED;
}
if (!nph.basic_handler_registered)
{
return SCE_NP_BASIC_ERROR_NOT_REGISTERED;
}
//if (!msgId > ?)
//{
// return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT;
//}
return CELL_OK;
}
error_code sceNpBasicAbortGui()
{
sceNp.warning("sceNpBasicAbortGui()");
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_BASIC_ERROR_NOT_INITIALIZED;
}
if (!nph.basic_handler_registered)
{
return SCE_NP_BASIC_ERROR_NOT_REGISTERED;
}
g_fxo->get<np_state>().abort_gui_flag = true;
return CELL_OK;
}
error_code sceNpBasicAddFriend(ppu_thread& ppu, vm::cptr<SceNpId> contact, vm::cptr<char> body, sys_memory_container_t containerId)
{
sceNp.warning("sceNpBasicAddFriend(contact=*0x%x, body=%s, containerId=%d)", contact, body, containerId);
vm::var<SceNpBasicMessageDetails> msg;
msg->msgId = 0;
msg->mainType = SCE_NP_BASIC_MESSAGE_MAIN_TYPE_ADD_FRIEND;
msg->subType = SCE_NP_BASIC_MESSAGE_ADD_FRIEND_SUBTYPE_NONE;
msg->msgFeatures = 0;
msg->npids = vm::const_ptr_cast<SceNpId>(contact);
msg->count = 1;
msg->subject = vm::null;
msg->body = vm::const_ptr_cast<char>(body);
msg->data = vm::null;
msg->size = 0;
return sceNpBasicSendMessageGui(ppu, msg, containerId);
}
error_code sceNpBasicGetFriendListEntryCount(vm::ptr<u32> count)
{
sceNp.trace("sceNpBasicGetFriendListEntryCount(count=*0x%x)", count);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_BASIC_ERROR_NOT_INITIALIZED;
}
if (!count)
{
return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT;
}
// TODO: Find the correct test which returns SCE_NP_ERROR_ID_NOT_FOUND
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_ERROR_ID_NOT_FOUND;
}
*count = nph.get_num_friends();
return CELL_OK;
}
error_code sceNpBasicGetFriendListEntry(u32 index, vm::ptr<SceNpId> npid)
{
sceNp.trace("sceNpBasicGetFriendListEntry(index=%d, npid=*0x%x)", index, npid);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_BASIC_ERROR_NOT_INITIALIZED;
}
if (!npid)
{
// TODO: check index
return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT;
}
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_BASIC_ERROR_BUSY;
}
const auto [error, res_npid] = nph.get_friend_by_index(index);
if (error)
{
return error;
}
memcpy(npid.get_ptr(), &res_npid.value(), sizeof(SceNpId));
return CELL_OK;
}
error_code sceNpBasicGetFriendPresenceByIndex(u32 index, vm::ptr<SceNpUserInfo> user, vm::ptr<SceNpBasicPresenceDetails> pres, u32 options)
{
sceNp.warning("sceNpBasicGetFriendPresenceByIndex(index=%d, user=*0x%x, pres=*0x%x, options=%d)", index, user, pres, options);
if (!pres)
{
return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT;
}
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_BASIC_ERROR_NOT_INITIALIZED;
}
if (!user)
{
// TODO: check index and (options & SCE_NP_BASIC_PRESENCE_OPTIONS_ALL_OPTIONS) depending on fw
return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT;
}
return nph.get_friend_presence_by_index(index, user.get_ptr(), pres.get_ptr());
}
error_code sceNpBasicGetFriendPresenceByIndex2(u32 index, vm::ptr<SceNpUserInfo> user, vm::ptr<SceNpBasicPresenceDetails2> pres, u32 options)
{
sceNp.warning("sceNpBasicGetFriendPresenceByIndex2(index=%d, user=*0x%x, pres=*0x%x, options=%d)", index, user, pres, options);
if (!pres)
{
return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT;
}
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_BASIC_ERROR_NOT_INITIALIZED;
}
if (!user)
{
// TODO: check index and (options & SCE_NP_BASIC_PRESENCE_OPTIONS_ALL_OPTIONS) depending on fw
return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT;
}
return nph.get_friend_presence_by_index(index, user.get_ptr(), pres.get_ptr());
}
error_code sceNpBasicGetFriendPresenceByNpId(vm::cptr<SceNpId> npid, vm::ptr<SceNpBasicPresenceDetails> pres, u32 options)
{
sceNp.warning("sceNpBasicGetFriendPresenceByNpId(npid=*0x%x, pres=*0x%x, options=%d)", npid, pres, options);
if (!pres)
{
return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT;
}
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_BASIC_ERROR_NOT_INITIALIZED;
}
if (!npid)
{
// TODO: check (options & SCE_NP_BASIC_PRESENCE_OPTIONS_ALL_OPTIONS) depending on fw
return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT;
}
return nph.get_friend_presence_by_npid(*npid, pres.get_ptr());
}
error_code sceNpBasicGetFriendPresenceByNpId2(vm::cptr<SceNpId> npid, vm::ptr<SceNpBasicPresenceDetails2> pres, u32 options)
{
sceNp.warning("sceNpBasicGetFriendPresenceByNpId2(npid=*0x%x, pres=*0x%x, options=%d)", npid, pres, options);
if (!pres)
{
return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT;
}
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_BASIC_ERROR_NOT_INITIALIZED;
}
if (!npid)
{
// TODO: check (options & SCE_NP_BASIC_PRESENCE_OPTIONS_ALL_OPTIONS) depending on fw
return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT;
}
return nph.get_friend_presence_by_npid(*npid, pres.get_ptr());
}
error_code sceNpBasicAddPlayersHistory(vm::cptr<SceNpId> npid, vm::cptr<char> description)
{
sceNp.warning("sceNpBasicAddPlayersHistory(npid=*0x%x, description=*0x%x)", npid, description);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_BASIC_ERROR_NOT_INITIALIZED;
}
if (!npid || npid->handle.data[0] == '\0')
{
return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT;
}
if (description && strlen(description.get_ptr()) > SCE_NP_BASIC_DESCRIPTION_CHARACTER_MAX)
{
return SCE_NP_BASIC_ERROR_EXCEEDS_MAX;
}
nph.add_player_to_history(npid.get_ptr(), description ? description.get_ptr() : nullptr);
return CELL_OK;
}
error_code sceNpBasicAddPlayersHistoryAsync(vm::cptr<SceNpId> npids, u32 count, vm::cptr<char> description, vm::ptr<u32> reqId)
{
sceNp.warning("sceNpBasicAddPlayersHistoryAsync(npids=*0x%x, count=%d, description=*0x%x, reqId=*0x%x)", npids, count, description, reqId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_BASIC_ERROR_NOT_INITIALIZED;
}
if (!count)
{
return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT;
}
if (count > SCE_NP_BASIC_PLAYER_HISTORY_MAX_PLAYERS)
{
return SCE_NP_BASIC_ERROR_EXCEEDS_MAX;
}
if (!npids)
{
return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT;
}
for (u32 i = 0; i < count; i++)
{
if (npids[i].handle.data[0] == '\0')
{
return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT;
}
}
if (description && strlen(description.get_ptr()) > SCE_NP_BASIC_DESCRIPTION_CHARACTER_MAX)
{
return SCE_NP_BASIC_ERROR_EXCEEDS_MAX;
}
auto req_id = nph.add_players_to_history(npids.get_ptr(), description ? description.get_ptr() : nullptr, count);
if (reqId)
{
*reqId = req_id;
}
return CELL_OK;
}
error_code sceNpBasicGetPlayersHistoryEntryCount(u32 options, vm::ptr<u32> count)
{
sceNp.warning("sceNpBasicGetPlayersHistoryEntryCount(options=%d, count=*0x%x)", options, count);
if (options > SCE_NP_BASIC_PLAYERS_HISTORY_OPTIONS_ALL)
{
return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT;
}
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_BASIC_ERROR_NOT_INITIALIZED;
}
if (!nph.basic_handler_registered)
{
return SCE_NP_BASIC_ERROR_NOT_REGISTERED;
}
if (!count)
{
return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT;
}
// TODO: Find the correct test which returns SCE_NP_ERROR_ID_NOT_FOUND
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_ERROR_ID_NOT_FOUND;
}
*count = nph.get_players_history_count(options);
return CELL_OK;
}
error_code sceNpBasicGetPlayersHistoryEntry(u32 options, u32 index, vm::ptr<SceNpId> npid)
{
sceNp.warning("sceNpBasicGetPlayersHistoryEntry(options=%d, index=%d, npid=*0x%x)", options, index, npid);
if (options > SCE_NP_BASIC_PLAYERS_HISTORY_OPTIONS_ALL)
{
return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT;
}
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_BASIC_ERROR_NOT_INITIALIZED;
}
if (!nph.basic_handler_registered)
{
return SCE_NP_BASIC_ERROR_NOT_REGISTERED;
}
if (!npid)
{
// TODO: Check index
return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT;
}
// TODO: Find the correct test which returns SCE_NP_ERROR_ID_NOT_FOUND
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_ERROR_ID_NOT_FOUND;
}
if (!nph.get_player_history_entry(options, index, npid.get_ptr()))
{
return SCE_NP_ERROR_ID_NOT_FOUND;
}
return CELL_OK;
}
error_code sceNpBasicAddBlockListEntry(vm::cptr<SceNpId> npid)
{
sceNp.warning("sceNpBasicAddBlockListEntry(npid=*0x%x)", npid);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_BASIC_ERROR_NOT_INITIALIZED;
}
if (!nph.basic_handler_registered)
{
return SCE_NP_BASIC_ERROR_NOT_REGISTERED;
}
if (!npid || npid->handle.data[0] == '\0')
{
return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT;
}
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return not_an_error(SCE_NP_BASIC_ERROR_NOT_CONNECTED);
}
return CELL_OK;
}
error_code sceNpBasicGetBlockListEntryCount(vm::ptr<u32> count)
{
sceNp.warning("sceNpBasicGetBlockListEntryCount(count=*0x%x)", count);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_BASIC_ERROR_NOT_INITIALIZED;
}
if (!count)
{
return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT;
}
// TODO: Find the correct test which returns SCE_NP_ERROR_ID_NOT_FOUND
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_ERROR_ID_NOT_FOUND;
}
// TODO: Check if there are block lists
*count = nph.get_num_blocks();
return CELL_OK;
}
error_code sceNpBasicGetBlockListEntry(u32 index, vm::ptr<SceNpId> npid)
{
sceNp.todo("sceNpBasicGetBlockListEntry(index=%d, npid=*0x%x)", index, npid);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_BASIC_ERROR_NOT_INITIALIZED;
}
if (!npid)
{
// TODO: check index
return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT;
}
// TODO: Find the correct test which returns SCE_NP_ERROR_ID_NOT_FOUND
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_ERROR_ID_NOT_FOUND;
}
return CELL_OK;
}
error_code sceNpBasicGetMessageAttachmentEntryCount(vm::ptr<u32> count)
{
sceNp.todo("sceNpBasicGetMessageAttachmentEntryCount(count=*0x%x)", count);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_BASIC_ERROR_NOT_INITIALIZED;
}
if (!nph.basic_handler_registered)
{
return SCE_NP_BASIC_ERROR_NOT_REGISTERED;
}
if (!count)
{
return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT;
}
// TODO: Find the correct test which returns SCE_NP_ERROR_ID_NOT_FOUND
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_ERROR_ID_NOT_FOUND;
}
// TODO: Check if there are message attachments
*count = 0;
return CELL_OK;
}
error_code sceNpBasicGetMessageAttachmentEntry(u32 index, vm::ptr<SceNpUserInfo> from)
{
sceNp.todo("sceNpBasicGetMessageAttachmentEntry(index=%d, from=*0x%x)", index, from);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_BASIC_ERROR_NOT_INITIALIZED;
}
if (!nph.basic_handler_registered)
{
return SCE_NP_BASIC_ERROR_NOT_REGISTERED;
}
if (!from)
{
// TODO: check index
return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT;
}
// TODO: Find the correct test which returns SCE_NP_ERROR_ID_NOT_FOUND
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_ERROR_ID_NOT_FOUND;
}
return CELL_OK;
}
error_code sceNpBasicGetCustomInvitationEntryCount(vm::ptr<u32> count)
{
sceNp.todo("sceNpBasicGetCustomInvitationEntryCount(count=*0x%x)", count);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_BASIC_ERROR_NOT_INITIALIZED;
}
if (!nph.basic_handler_registered)
{
return SCE_NP_BASIC_ERROR_NOT_REGISTERED;
}
if (!count)
{
return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT;
}
// TODO: Find the correct test which returns SCE_NP_ERROR_ID_NOT_FOUND
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_ERROR_ID_NOT_FOUND;
}
// TODO: Check if there are custom invitations
*count = 0;
return CELL_OK;
}
error_code sceNpBasicGetCustomInvitationEntry(u32 index, vm::ptr<SceNpUserInfo> from)
{
sceNp.todo("sceNpBasicGetCustomInvitationEntry(index=%d, from=*0x%x)", index, from);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_BASIC_ERROR_NOT_INITIALIZED;
}
if (!nph.basic_handler_registered)
{
return SCE_NP_BASIC_ERROR_NOT_REGISTERED;
}
if (!from)
{
// TODO: check index
return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT;
}
// TODO: Find the correct test which returns SCE_NP_ERROR_ID_NOT_FOUND
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_ERROR_ID_NOT_FOUND;
}
return CELL_OK;
}
error_code sceNpBasicGetMatchingInvitationEntryCount(vm::ptr<u32> count)
{
sceNp.todo("sceNpBasicGetMatchingInvitationEntryCount(count=*0x%x)", count);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_BASIC_ERROR_NOT_INITIALIZED;
}
if (!nph.basic_handler_registered)
{
return SCE_NP_BASIC_ERROR_NOT_REGISTERED;
}
if (!count)
{
return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT;
}
// TODO: Find the correct test which returns SCE_NP_ERROR_ID_NOT_FOUND
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_ERROR_ID_NOT_FOUND;
}
// TODO: Check if there are matching invitations
*count = 0;
return CELL_OK;
}
error_code sceNpBasicGetMatchingInvitationEntry(u32 index, vm::ptr<SceNpUserInfo> from)
{
sceNp.todo("sceNpBasicGetMatchingInvitationEntry(index=%d, from=*0x%x)", index, from);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_BASIC_ERROR_NOT_INITIALIZED;
}
if (!nph.basic_handler_registered)
{
return SCE_NP_BASIC_ERROR_NOT_REGISTERED;
}
if (!from)
{
// TODO: check index
return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT;
}
// TODO: Find the correct test which returns SCE_NP_ERROR_ID_NOT_FOUND
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_ERROR_ID_NOT_FOUND;
}
return CELL_OK;
}
error_code sceNpBasicGetClanMessageEntryCount(vm::ptr<u32> count)
{
sceNp.todo("sceNpBasicGetClanMessageEntryCount(count=*0x%x)", count);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_BASIC_ERROR_NOT_INITIALIZED;
}
if (!nph.basic_handler_registered)
{
return SCE_NP_BASIC_ERROR_NOT_REGISTERED;
}
if (!count)
{
return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT;
}
// TODO: Find the correct test which returns SCE_NP_ERROR_ID_NOT_FOUND
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_ERROR_ID_NOT_FOUND;
}
// TODO: Check if there are clan messages
*count = 0;
return CELL_OK;
}
error_code sceNpBasicGetClanMessageEntry(u32 index, vm::ptr<SceNpUserInfo> from)
{
sceNp.todo("sceNpBasicGetClanMessageEntry(index=%d, from=*0x%x)", index, from);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_BASIC_ERROR_NOT_INITIALIZED;
}
if (!nph.basic_handler_registered)
{
return SCE_NP_BASIC_ERROR_NOT_REGISTERED;
}
if (!from)
{
// TODO: check index
return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT;
}
// TODO: Find the correct test which returns SCE_NP_ERROR_ID_NOT_FOUND
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_ERROR_ID_NOT_FOUND;
}
return CELL_OK;
}
error_code sceNpBasicGetMessageEntryCount(u32 type, vm::ptr<u32> count)
{
sceNp.todo("sceNpBasicGetMessageEntryCount(type=%d, count=*0x%x)", type, count);
// TODO: verify this check and its location
if (type > SCE_NP_BASIC_MESSAGE_INFO_TYPE_BOOTABLE_CUSTOM_DATA_MESSAGE)
{
return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT;
}
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_BASIC_ERROR_NOT_INITIALIZED;
}
if (!count)
{
return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT;
}
// TODO: Find the correct test which returns SCE_NP_ERROR_ID_NOT_FOUND
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_ERROR_ID_NOT_FOUND;
}
// TODO: Check if there are messages
*count = 0;
return CELL_OK;
}
error_code sceNpBasicGetMessageEntry(u32 type, u32 index, vm::ptr<SceNpUserInfo> from)
{
sceNp.todo("sceNpBasicGetMessageEntry(type=%d, index=%d, from=*0x%x)", type, index, from);
// TODO: verify this check and its location
if (type > SCE_NP_BASIC_MESSAGE_INFO_TYPE_BOOTABLE_CUSTOM_DATA_MESSAGE)
{
return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT;
}
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_BASIC_ERROR_NOT_INITIALIZED;
}
if (!from)
{
// TODO: check index
return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT;
}
// TODO: Find the correct test which returns SCE_NP_ERROR_ID_NOT_FOUND
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_ERROR_ID_NOT_FOUND;
}
return CELL_OK;
}
error_code sceNpBasicGetEvent(vm::ptr<s32> event, vm::ptr<SceNpUserInfo> from, vm::ptr<u8> data, vm::ptr<u32> size)
{
sceNp.trace("sceNpBasicGetEvent(event=*0x%x, from=*0x%x, data=*0x%x, size=*0x%x)", event, from, data, size);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_BASIC_ERROR_NOT_INITIALIZED;
}
if (!nph.basic_handler_registered)
{
return SCE_NP_BASIC_ERROR_NOT_REGISTERED;
}
if (!event || !from || !data || !size)
{
return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT;
}
return nph.get_basic_event(event, from, data, size);
}
error_code sceNpCommerceCreateCtx(u32 version, vm::ptr<SceNpId> npId, vm::ptr<SceNpCommerceHandler> handler, vm::ptr<void> arg, vm::ptr<u32> ctx_id)
{
sceNp.todo("sceNpCommerceCreateCtx(version=%d, event=*0x%x, from=*0x%x, arg=*0x%x, ctx_id=*0x%x)", version, npId, handler, arg, ctx_id);
if (false) // TODO
return SCE_NP_COMMERCE_ERROR_NOT_INITIALIZED;
if (version != SCE_NP_COMMERCE_VERSION)
return SCE_NP_COMMERCE_ERROR_UNSUPPORTED_VERSION;
if (false) // TODO
return SCE_NP_COMMERCE_ERROR_CTX_MAX;
return CELL_OK;
}
error_code sceNpCommerceDestroyCtx(u32 ctx_id)
{
sceNp.todo("sceNpCommerceDestroyCtx(ctx_id=%d)", ctx_id);
if (false) // TODO
return SCE_NP_COMMERCE_ERROR_NOT_INITIALIZED;
if (false) // TODO
return SCE_NP_COMMERCE_ERROR_CTX_NOT_FOUND;
return CELL_OK;
}
error_code sceNpCommerceInitProductCategory(vm::ptr<SceNpCommerceProductCategory> pc, vm::cptr<void> data, u32 data_size)
{
sceNp.todo("sceNpCommerceInitProductCategory(pc=*0x%x, data=*0x%x, data_size=%d)", pc, data, data_size);
if (!pc) // Not really checked
return SCE_NP_COMMERCE_ERROR_PARSE_PRODUCT_CATEGORY;
pc->data = data;
pc->dataSize = data_size;
if (data_size < 4)
return SCE_NP_COMMERCE_ERROR_PARSE_PRODUCT_CATEGORY;
const u32 version = SCE_NP_COMMERCE_VERSION; // TODO: *data
pc->version = version;
if (pc->version != SCE_NP_COMMERCE_VERSION)
return SCE_NP_COMMERCE_ERROR_INVALID_GPC_PROTOCOL_VERSION;
if (data_size < 8)
return SCE_NP_COMMERCE_ERROR_PARSE_PRODUCT_CATEGORY;
//const u32 unk = data + 4;
//if (unk != 0)
//{
// if (unk < 256)
// return unk | SCE_NP_COMMERCE_BROWSE_SERVER_ERROR_UNKNOWN;
// return SCE_NP_COMMERCE_BROWSE_SERVER_ERROR_UNKNOWN;
//}
vm::var<SceNpCommerceCurrencyInfo> info;
error_code err = sceNpCommerceGetCurrencyInfo(pc, info);
if (err != CELL_OK)
return SCE_NP_COMMERCE_ERROR_PARSE_PRODUCT_CATEGORY;
if (false) // TODO
{
pc->dval = 10;
while (false) // TODO
{
pc->dval *= 10;
}
}
else
{
pc->dval = 0;
}
return CELL_OK;
}
void sceNpCommerceDestroyProductCategory(vm::ptr<SceNpCommerceProductCategory> pc)
{
sceNp.todo("sceNpCommerceDestroyProductCategory(pc=*0x%x)", pc);
if (pc)
{
pc->dataSize = 0;
pc->data = vm::null;
}
}
error_code sceNpCommerceGetProductCategoryStart(u32 ctx_id, vm::cptr<char> category_id, s32 lang_code, vm::ptr<u32> req_id)
{
sceNp.todo("sceNpCommerceGetProductCategoryStart(ctx_id=%d, category_id=%s, lang_code=%d, req_id=*0x%x)", ctx_id, category_id, lang_code, req_id);
if (false) // TODO
return SCE_NP_COMMERCE_ERROR_NOT_INITIALIZED;
if (false) // TODO
return SCE_NP_COMMERCE_ERROR_CTX_NOT_FOUND;
return CELL_OK;
}
error_code sceNpCommerceGetProductCategoryFinish(u32 req_id)
{
sceNp.todo("sceNpCommerceGetProductCategoryFinish(req_id=%d)", req_id);
if (false) // TODO
return SCE_NP_COMMERCE_ERROR_NOT_INITIALIZED;
return CELL_OK;
}
error_code sceNpCommerceGetProductCategoryResult(u32 req_id, vm::ptr<void> buf, u32 buf_size, vm::ptr<u32> fill_size)
{
sceNp.todo("sceNpCommerceGetProductCategoryResult(req_id=%d, buf=*0x%x, buf_size=%d, fill_size=*0x%x)", req_id, buf, buf_size, fill_size);
if (false) // TODO
return SCE_NP_COMMERCE_ERROR_NOT_INITIALIZED;
if (buf_size == 0)
return SCE_NP_COMMERCE_ERROR_INSUFFICIENT_BUFFER;
if (!fill_size) // Not really checked afaict
return SCE_NP_COMMERCE_ERROR_INSUFFICIENT_BUFFER;
*fill_size = 0;
return CELL_OK;
}
error_code sceNpCommerceGetProductCategoryAbort(u32 req_id)
{
sceNp.todo("sceNpCommerceGetProductCategoryAbort(req_id=%d)", req_id);
if (false) // TODO
return SCE_NP_COMMERCE_ERROR_NOT_INITIALIZED;
return CELL_OK;
}
vm::cptr<char> sceNpCommerceGetProductId(vm::ptr<SceNpCommerceProductSkuInfo> info)
{
sceNp.todo("sceNpCommerceGetProductId(info=*0x%x)", info);
// if (info) return info->data + 0x38;
return vm::null;
}
vm::cptr<char> sceNpCommerceGetProductName(vm::ptr<SceNpCommerceProductSkuInfo> info)
{
sceNp.todo("sceNpCommerceGetProductName(info=*0x%x)", info);
// if (info) return info->data + 0x68;
return vm::null;
}
vm::cptr<char> sceNpCommerceGetCategoryDescription(vm::ptr<SceNpCommerceCategoryInfo> info)
{
sceNp.todo("sceNpCommerceGetCategoryDescription(info=*0x%x)", info);
// if (info) return info->data + 0xf8;
return vm::null;
}
vm::cptr<char> sceNpCommerceGetCategoryId(vm::ptr<SceNpCommerceCategoryInfo> info)
{
sceNp.todo("sceNpCommerceGetCategoryId(info=*0x%x)", info);
// if (info) return info->data;
return vm::null;
}
vm::cptr<char> sceNpCommerceGetCategoryImageURL(vm::ptr<SceNpCommerceCategoryInfo> info)
{
sceNp.todo("sceNpCommerceGetCategoryImageURL(info=*0x%x)", info);
// if (info) return info->data + 0x278;
return vm::null;
}
error_code sceNpCommerceGetCategoryInfo(vm::ptr<SceNpCommerceProductCategory> pc, vm::ptr<SceNpCommerceCategoryInfo> info)
{
sceNp.todo("sceNpCommerceGetCategoryInfo(pc=*0x%x, info=*0x%x)", pc, info);
if (!pc || pc->dataSize < 776)
return SCE_NP_COMMERCE_ERROR_CATEGORY_INFO_NOT_FOUND;
if (info)
{
info->pc = pc;
// TODO
//info->data = pc->data + 16;
//pc->data + 0x307 = 0;
//pc->data + 0x47 = 0;
//pc->data + 0x107 = 0;
//pc->data + 0x287 = 0;
}
return CELL_OK;
}
vm::cptr<char> sceNpCommerceGetCategoryName(vm::ptr<SceNpCommerceCategoryInfo> info)
{
sceNp.todo("sceNpCommerceGetCategoryName(info=*0x%x)", info);
// if (info) return info->data + 0x38;
return vm::null;
}
vm::cptr<char> sceNpCommerceGetCurrencyCode(vm::ptr<SceNpCommerceCurrencyInfo> info)
{
sceNp.todo("sceNpCommerceGetCurrencyCode(info=*0x%x)", info);
//if (info) return info->data;
return vm::null;
}
u32 sceNpCommerceGetCurrencyDecimals(vm::ptr<SceNpCommerceCurrencyInfo> info)
{
sceNp.todo("sceNpCommerceGetCurrencyDecimals(info=*0x%x)", info);
if (info)
{
//return (info->data + 7) |
// (info->data + 6) << 8 |
// (info->data + 5) << 0x10 |
// (info->data + 4) << 0x18;
}
return 0;
}
error_code sceNpCommerceGetCurrencyInfo(vm::ptr<SceNpCommerceProductCategory> pc, vm::ptr<SceNpCommerceCurrencyInfo> info)
{
sceNp.todo("sceNpCommerceGetCurrencyInfo(pc=*0x%x, info=*0x%x)", pc, info);
if (!pc || pc->dataSize < 16)
return SCE_NP_COMMERCE_ERROR_CURRENCY_INFO_NOT_FOUND;
if (info)
{
info->pc = pc;
// TODO
//info->data = pc->data + 8;
//pc->data + 0xb = 0;
}
return CELL_OK;
}
error_code sceNpCommerceGetNumOfChildCategory(vm::ptr<SceNpCommerceProductCategory> pc, vm::ptr<u32> num)
{
sceNp.todo("sceNpCommerceGetNumOfChildCategory(pc=*0x%x, num=*0x%x)", pc, num);
if (!pc || pc->dataSize < 780)
return SCE_NP_COMMERCE_ERROR_CHILD_CATEGORY_COUNT_NOT_FOUND;
//if (num) *num = pc->data + 0x308;
return CELL_OK;
}
error_code sceNpCommerceGetNumOfChildProductSku(vm::ptr<SceNpCommerceProductCategory> pc, vm::ptr<u32> num)
{
sceNp.todo("sceNpCommerceGetNumOfChildProductSku(pc=*0x%x, num=*0x%x)", pc, num);
if (!pc || pc->dataSize < 780) // TODO: some other check
return SCE_NP_COMMERCE_ERROR_SKU_COUNT_NOT_FOUND;
//if (num) *num = something;
return CELL_OK;
}
vm::cptr<char> sceNpCommerceGetSkuDescription(vm::ptr<SceNpCommerceProductSkuInfo> info)
{
sceNp.todo("sceNpCommerceGetSkuDescription(info=*0x%x)", info);
//if (info) return info->data + 0x168;
return vm::null;
}
vm::cptr<char> sceNpCommerceGetSkuId(vm::ptr<SceNpCommerceProductSkuInfo> info)
{
sceNp.todo("sceNpCommerceGetSkuId(info=*0x%x)", info);
//if (info) return info->data;
return vm::null;
}
vm::cptr<char> sceNpCommerceGetSkuImageURL(vm::ptr<SceNpCommerceProductSkuInfo> info)
{
sceNp.todo("sceNpCommerceGetSkuImageURL(info=*0x%x)", info);
//if (info) return info->data + 0x2e8;
return vm::null;
}
vm::cptr<char> sceNpCommerceGetSkuName(vm::ptr<SceNpCommerceProductSkuInfo> info)
{
sceNp.todo("sceNpCommerceGetSkuName(info=*0x%x)", info);
//if (info) return info->data + 0x128;
return vm::null;
}
void sceNpCommerceGetSkuPrice(vm::ptr<SceNpCommerceProductSkuInfo> info, vm::ptr<SceNpCommercePrice> price)
{
sceNp.todo("sceNpCommerceGetSkuPrice(info=*0x%x, price=*0x%x)", info, price);
if (!price)
return;
if (info && info->pc && info->pc->dval)
{
// TODO
//price->integer = something / info->pc->dval;
//price->fractional = something - static_cast<int>(price->integer) * info->pc->dval;
return;
}
// TODO
//price->integer = something;
price->fractional = 0;
}
vm::cptr<char> sceNpCommerceGetSkuUserData(vm::ptr<SceNpCommerceProductSkuInfo> info)
{
sceNp.todo("sceNpCommerceGetSkuUserData(info=*0x%x)", info);
//if (info) return info->data + 0x368;
return vm::null;
}
error_code sceNpCommerceSetDataFlagStart(u32 arg1, u32 arg2, u32 arg3, u32 arg4, u32 arg5)
{
sceNp.todo("sceNpCommerceSetDataFlagStart(arg1=0x%x, arg2=0x%x, arg3=0x%x, arg4=0x%x, arg5=0x%x)", arg1, arg2, arg3, arg4, arg5);
if (false) // TODO
return SCE_NP_COMMERCE_ERROR_NOT_INITIALIZED;
if (arg4 == 0 || arg4 > 16)
return SCE_NP_COMMERCE_ERROR_INVALID_DATA_FLAG_NUM;
if (false) // TODO
return SCE_NP_COMMERCE_ERROR_CTX_NOT_FOUND;
return CELL_OK;
}
error_code sceNpCommerceGetDataFlagStart(u32 arg1, u32 arg2, u32 arg3, u32 arg4, u32 arg5)
{
sceNp.todo("sceNpCommerceGetDataFlagStart(arg1=0x%x, arg2=0x%x, arg3=0x%x, arg4=0x%x, arg5=0x%x)", arg1, arg2, arg3, arg4, arg5);
if (false) // TODO
return SCE_NP_COMMERCE_ERROR_NOT_INITIALIZED;
if (arg4 == 0 || arg4 > 16)
return SCE_NP_COMMERCE_ERROR_INVALID_DATA_FLAG_NUM;
if (false) // TODO
return SCE_NP_COMMERCE_ERROR_CTX_NOT_FOUND;
return CELL_OK;
}
error_code sceNpCommerceSetDataFlagFinish()
{
UNIMPLEMENTED_FUNC(sceNp);
if (false) // TODO
return SCE_NP_COMMERCE_ERROR_NOT_INITIALIZED;
return CELL_OK;
}
error_code sceNpCommerceGetDataFlagFinish()
{
UNIMPLEMENTED_FUNC(sceNp);
if (false) // TODO
return SCE_NP_COMMERCE_ERROR_NOT_INITIALIZED;
return CELL_OK;
}
error_code sceNpCommerceGetDataFlagState(u32 arg1, u32 arg2, u32 arg3)
{
sceNp.todo("sceNpCommerceGetDataFlagState(arg1=0x%x, arg2=0x%x, arg3=0x%x)", arg1, arg2, arg3);
if (false) // TODO
return SCE_NP_COMMERCE_ERROR_NOT_INITIALIZED;
if (arg3 == 0 || arg3 > 16)
return SCE_NP_COMMERCE_ERROR_INVALID_DATA_FLAG_NUM;
return CELL_OK;
}
error_code sceNpCommerceGetDataFlagAbort()
{
UNIMPLEMENTED_FUNC(sceNp);
if (false) // TODO
return SCE_NP_COMMERCE_ERROR_NOT_INITIALIZED;
return CELL_OK;
}
error_code sceNpCommerceGetChildCategoryInfo(vm::ptr<SceNpCommerceProductCategory> pc, u32 child_index, vm::ptr<SceNpCommerceCategoryInfo> info)
{
sceNp.todo("sceNpCommerceGetChildCategoryInfo(pc=*0x%x, child_index=%d, info=*0x%x)", pc, child_index, info);
if (!pc || !info) // Not really checked I think
return SCE_NP_COMMERCE_ERROR_CHILD_CATEGORY_INFO_NOT_FOUND;
const u32 offset = child_index * 760;
if (offset + 1540 > pc->dataSize)
return SCE_NP_COMMERCE_ERROR_CHILD_CATEGORY_INFO_NOT_FOUND;
// TODO
//auto child = pc->data + offset + 780;
//info->pc = pc;
//info->data = child + 780;
//child + 0x603 = 0;
//child + 0x343 = 0;
//child + 0x403 = 0;
//child + 0x583 = 0;
return CELL_OK;
}
error_code sceNpCommerceGetChildProductSkuInfo(vm::ptr<SceNpCommerceProductCategory> pc, u32 child_index, vm::ptr<SceNpCommerceProductSkuInfo> info)
{
sceNp.todo("sceNpCommerceGetChildProductSkuInfo(pc=*0x%x, child_index=%d, info=*0x%x)", pc, child_index, info);
if (!pc || !info) // Not really checked I think
return SCE_NP_COMMERCE_ERROR_SKU_INFO_NOT_FOUND;
if (pc->dataSize > 780)
return SCE_NP_COMMERCE_ERROR_SKU_INFO_NOT_FOUND;
// TODO
//const u32 child_offset = child_index * 1004;
//const u32 offset = (pc->data + 776) * 760 + offset;
//if (offset + 788 > pc->dataSize)
// return SCE_NP_COMMERCE_ERROR_SKU_INFO_NOT_FOUND;
//auto child = pc->data + offset;
//info->pc = pc;
//info->data = child + 784;
//child + 0x6f7 = 0;
//child + 0x347 = 0;
//child + 0x377 = 0;
//child + 0x437 = 0;
//child + 0x477 = 0;
//child + 0x5f7 = 0;
//child + 0x677 = 0;
return CELL_OK;
}
error_code sceNpCommerceDoCheckoutStartAsync(u32 ctx_id, vm::cpptr<char> sku_ids, u32 sku_num, sys_memory_container_t container, vm::ptr<u32> req_id)
{
sceNp.todo("sceNpCommerceDoCheckoutStartAsync(ctx_id=%d, sku_ids=*0x%x, sku_num=%d, container=%d, req_id=*0x%x)", ctx_id, sku_ids, sku_num, container, req_id);
if (false) // TODO
return SCE_NP_COMMERCE_ERROR_NOT_INITIALIZED;
if (!sku_num || sku_num > 16)
return SCE_NP_COMMERCE_ERROR_INVALID_SKU_NUM;
if (false) // TODO
return SCE_NP_COMMERCE_ERROR_CTX_NOT_FOUND;
if (false) // TODO
return SCE_NP_COMMERCE_ERROR_INVALID_MEMORY_CONTAINER;
if (false) // TODO
return SCE_NP_COMMERCE_ERROR_INSUFFICIENT_MEMORY_CONTAINER;
// TODO: get sku_ids
return CELL_OK;
}
error_code sceNpCommerceDoCheckoutFinishAsync(u32 req_id)
{
sceNp.todo("sceNpCommerceDoCheckoutFinishAsync(req_id=%d)", req_id);
if (false) // TODO
return SCE_NP_COMMERCE_ERROR_NOT_INITIALIZED;
return CELL_OK;
}
error_code sceNpCustomMenuRegisterActions(vm::cptr<SceNpCustomMenu> menu, vm::ptr<SceNpCustomMenuEventHandler> handler, vm::ptr<void> userArg, u64 options)
{
sceNp.todo("sceNpCustomMenuRegisterActions(menu=*0x%x, handler=*0x%x, userArg=*0x%x, options=0x%x)", menu, handler, userArg, options);
// TODO: Is there any error if options is not 0 ?
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_CUSTOM_MENU_ERROR_NOT_INITIALIZED;
}
if (!menu || !handler) // TODO: handler check might come later
{
return SCE_NP_CUSTOM_MENU_ERROR_INVALID_ARGUMENT;
}
if (menu->numActions > SCE_NP_CUSTOM_MENU_ACTION_ITEMS_TOTAL_MAX)
{
return SCE_NP_CUSTOM_MENU_ERROR_EXCEEDS_MAX;
}
std::vector<np::np_handler::custom_menu_action> actions;
for (u32 i = 0; i < menu->numActions; i++)
{
if (!menu->actions || !menu->actions[i].name)
{
return SCE_NP_CUSTOM_MENU_ERROR_INVALID_ARGUMENT;
}
// TODO: Is there any error if menu->actions[i].options is not 0 ?
// TODO: check name
if (false)
{
return SCE_NP_UTIL_ERROR_INVALID_CHARACTER;
}
if (!memchr(menu->actions[i].name.get_ptr(), '\0', SCE_NP_CUSTOM_MENU_ACTION_CHARACTER_MAX))
{
return SCE_NP_CUSTOM_MENU_ERROR_EXCEEDS_MAX;
}
np::np_handler::custom_menu_action action{};
action.id = static_cast<s32>(actions.size());
action.mask = menu->actions[i].mask;
action.name = menu->actions[i].name.get_ptr();
sceNp.notice("Registering menu action: id=%d, mask=0x%x, name=%s", action.id, action.mask, action.name);
actions.push_back(std::move(action));
}
// TODO: add the custom menu to the friendlist and profile dialogs
std::lock_guard lock(nph.mutex_custom_menu);
nph.custom_menu_handler = handler;
nph.custom_menu_user_arg = userArg;
nph.custom_menu_actions = std::move(actions);
nph.custom_menu_registered = true;
nph.custom_menu_activation = {};
nph.custom_menu_exception_list = {};
return CELL_OK;
}
error_code sceNpCustomMenuActionSetActivation(vm::cptr<SceNpCustomMenuIndexArray> array, u64 options)
{
sceNp.todo("sceNpCustomMenuActionSetActivation(array=*0x%x, options=0x%x)", array, options);
// TODO: Is there any error if options is not 0 ?
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_CUSTOM_MENU_ERROR_NOT_INITIALIZED;
}
std::lock_guard lock(nph.mutex_custom_menu);
if (!nph.custom_menu_registered)
{
return SCE_NP_CUSTOM_MENU_ERROR_NOT_REGISTERED;
}
if (!array)
{
return SCE_NP_CUSTOM_MENU_ERROR_INVALID_ARGUMENT;
}
nph.custom_menu_activation = *array;
return CELL_OK;
}
error_code sceNpCustomMenuRegisterExceptionList(vm::cptr<SceNpCustomMenuActionExceptions> items, u32 numItems, u64 options)
{
sceNp.todo("sceNpCustomMenuRegisterExceptionList(items=*0x%x, numItems=%d, options=0x%x)", items, numItems, options);
// TODO: Is there any error if options is not 0 ?
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_CUSTOM_MENU_ERROR_NOT_INITIALIZED;
}
std::lock_guard lock(nph.mutex_custom_menu);
if (!nph.custom_menu_registered)
{
return SCE_NP_CUSTOM_MENU_ERROR_NOT_REGISTERED;
}
if (numItems > SCE_NP_CUSTOM_MENU_EXCEPTION_ITEMS_MAX)
{
return SCE_NP_CUSTOM_MENU_ERROR_EXCEEDS_MAX;
}
if (!items)
{
return SCE_NP_CUSTOM_MENU_ERROR_INVALID_ARGUMENT;
}
nph.custom_menu_exception_list.clear();
for (u32 i = 0; i < numItems; i++)
{
// TODO: Are the exceptions checked ?
nph.custom_menu_exception_list.push_back(items[i]);
}
return CELL_OK;
}
error_code sceNpFriendlist(vm::ptr<SceNpFriendlistResultHandler> resultHandler, vm::ptr<void> userArg, sys_memory_container_t containerId)
{
sceNp.warning("sceNpFriendlist(resultHandler=*0x%x, userArg=*0x%x, containerId=%d)", resultHandler, userArg, containerId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_FRIENDLIST_ERROR_NOT_INITIALIZED;
}
// TODO: SCE_NP_FRIENDLIST_ERROR_BUSY
if (!resultHandler)
{
return SCE_NP_FRIENDLIST_ERROR_INVALID_ARGUMENT;
}
vm::var<SceNpId> id;
error_code err = sceNpManagerGetNpId(id);
if (err != CELL_OK)
return err;
// TODO: handler
return CELL_OK;
}
error_code sceNpFriendlistCustom(SceNpFriendlistCustomOptions options, vm::ptr<SceNpFriendlistResultHandler> resultHandler, vm::ptr<void> userArg, sys_memory_container_t containerId)
{
sceNp.warning("sceNpFriendlistCustom(options=0x%x, resultHandler=*0x%x, userArg=*0x%x, containerId=%d)", options, resultHandler, userArg, containerId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_FRIENDLIST_ERROR_NOT_INITIALIZED;
}
// TODO: SCE_NP_FRIENDLIST_ERROR_BUSY
if (!resultHandler)
{
return SCE_NP_FRIENDLIST_ERROR_INVALID_ARGUMENT;
}
vm::var<SceNpId> id;
error_code err = sceNpManagerGetNpId(id);
if (err != CELL_OK)
return err;
// TODO: handler
return CELL_OK;
}
error_code sceNpFriendlistAbortGui()
{
sceNp.todo("sceNpFriendlistAbortGui()");
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_FRIENDLIST_ERROR_NOT_INITIALIZED;
}
// TODO: abort friendlist GUI interaction
return CELL_OK;
}
error_code sceNpLookupInit()
{
sceNp.warning("sceNpLookupInit()");
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (nph.is_NP_Lookup_init)
{
return SCE_NP_COMMUNITY_ERROR_ALREADY_INITIALIZED;
}
if (!nph.is_NP_init)
{
return SCE_NP_ERROR_NOT_INITIALIZED;
}
nph.is_NP_Lookup_init = true;
return CELL_OK;
}
error_code sceNpLookupTerm()
{
sceNp.warning("sceNpLookupTerm()");
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Lookup_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (!nph.is_NP_init)
{
return SCE_NP_ERROR_NOT_INITIALIZED;
}
nph.is_NP_Lookup_init = false;
return CELL_OK;
}
error_code sceNpLookupCreateTitleCtx(vm::cptr<SceNpCommunicationId> communicationId, vm::cptr<SceNpId> selfNpId)
{
sceNp.warning("sceNpLookupCreateTitleCtx(communicationId=*0x%x(%s), selfNpId=0x%x)", communicationId, communicationId ? communicationId->data : "", selfNpId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Lookup_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (!communicationId || !selfNpId)
{
return SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT;
}
return not_an_error(create_lookup_title_context(communicationId));
}
error_code sceNpLookupDestroyTitleCtx(s32 titleCtxId)
{
sceNp.warning("sceNpLookupDestroyTitleCtx(titleCtxId=%d)", titleCtxId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Lookup_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (!destroy_lookup_title_context(titleCtxId))
return SCE_NP_COMMUNITY_ERROR_INVALID_ID;
return CELL_OK;
}
error_code sceNpLookupCreateTransactionCtx(s32 titleCtxId)
{
sceNp.warning("sceNpLookupCreateTransactionCtx(titleCtxId=%d)", titleCtxId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Lookup_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ONLINE_ID;
}
return not_an_error(create_lookup_transaction_context(titleCtxId));
}
error_code sceNpLookupDestroyTransactionCtx(s32 transId)
{
sceNp.warning("sceNpLookupDestroyTransactionCtx(transId=%d)", transId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Lookup_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (!destroy_lookup_transaction_context(transId))
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ID;
}
return CELL_OK;
}
error_code sceNpLookupSetTimeout(s32 ctxId, usecond_t timeout)
{
sceNp.todo("sceNpLookupSetTimeout(ctxId=%d, timeout=%d)", ctxId, timeout);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Lookup_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (timeout < 10000000) // 10 seconds
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
return CELL_OK;
}
error_code sceNpLookupAbortTransaction(s32 transId)
{
sceNp.todo("sceNpLookupAbortTransaction(transId=%d)", transId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Lookup_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
return CELL_OK;
}
error_code sceNpLookupWaitAsync(s32 transId, vm::ptr<s32> result)
{
sceNp.todo("sceNpLookupWaitAsync(transId=%d, result=%d)", transId, result);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Lookup_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
return CELL_OK;
}
error_code sceNpLookupPollAsync(s32 transId, vm::ptr<s32> result)
{
sceNp.todo("sceNpLookupPollAsync(transId=%d, result=*0x%x)", transId, result);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Lookup_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
*result = 0;
return CELL_OK;
}
error_code sceNpLookupNpId(s32 transId, vm::cptr<SceNpOnlineId> onlineId, vm::ptr<SceNpId> npId, vm::ptr<void> option)
{
sceNp.todo("sceNpLookupNpId(transId=%d, onlineId=*0x%x, npId=*0x%x, option=*0x%x)", transId, onlineId, npId, option);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Lookup_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (!onlineId || !npId)
{
return SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT;
}
if (option) // option check at least until fw 4.71
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ONLINE_ID;
}
// Hack - better than nothing for now
memset(npId.get_ptr(), 0, sizeof(SceNpId));
memcpy(npId->handle.data, onlineId->data, sizeof(npId->handle.data) - 1);
return CELL_OK;
}
error_code sceNpLookupNpIdAsync(s32 transId, vm::cptr<SceNpOnlineId> onlineId, vm::ptr<SceNpId> npId, s32 prio, vm::ptr<void> option)
{
sceNp.todo("sceNpLookupNpIdAsync(transId=%d, onlineId=*0x%x, npId=*0x%x, prio=%d, option=*0x%x)", transId, onlineId, npId, prio, option);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Lookup_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (!onlineId || !npId)
{
return SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT;
}
if (option) // option check at least until fw 4.71
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ONLINE_ID;
}
// Hack - better than nothing for now
memset(npId.get_ptr(), 0, sizeof(SceNpId));
memcpy(npId->handle.data, onlineId->data, sizeof(npId->handle.data) - 1);
return CELL_OK;
}
error_code sceNpLookupUserProfile(s32 transId, vm::cptr<SceNpId> npId, vm::ptr<SceNpUserInfo> userInfo, vm::ptr<SceNpAboutMe> aboutMe, vm::ptr<SceNpMyLanguages> languages,
vm::ptr<SceNpCountryCode> countryCode, vm::ptr<SceNpAvatarImage> avatarImage, vm::ptr<void> option)
{
sceNp.todo("sceNpLookupUserProfile(transId=%d, npId=*0x%x, userInfo=*0x%x, aboutMe=*0x%x, languages=*0x%x, countryCode=*0x%x, avatarImage=*0x%x, option=*0x%x)", transId, npId, userInfo, aboutMe,
languages, countryCode, avatarImage, option);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Lookup_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (!npId)
{
return SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT;
}
if (option) // option check at least until fw 4.71
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ONLINE_ID;
}
return CELL_OK;
}
error_code sceNpLookupUserProfileAsync(s32 transId, vm::cptr<SceNpId> npId, vm::ptr<SceNpUserInfo> userInfo, vm::ptr<SceNpAboutMe> aboutMe, vm::ptr<SceNpMyLanguages> languages,
vm::ptr<SceNpCountryCode> countryCode, vm::ptr<SceNpAvatarImage> avatarImage, s32 prio, vm::ptr<void> option)
{
sceNp.todo("sceNpLookupUserProfile(transId=%d, npId=*0x%x, userInfo=*0x%x, aboutMe=*0x%x, languages=*0x%x, countryCode=*0x%x, avatarImage=*0x%x, prio=%d, option=*0x%x)", transId, npId, userInfo,
aboutMe, languages, countryCode, avatarImage, prio, option);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Lookup_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (!npId)
{
return SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT;
}
if (option) // option check at least until fw 4.71
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ONLINE_ID;
}
return CELL_OK;
}
error_code sceNpLookupUserProfileWithAvatarSize(s32 transId, s32 avatarSizeType, vm::cptr<SceNpId> npId, vm::ptr<SceNpUserInfo> userInfo, vm::ptr<SceNpAboutMe> aboutMe,
vm::ptr<SceNpMyLanguages> languages, vm::ptr<SceNpCountryCode> countryCode, vm::ptr<void> avatarImageData, u32 avatarImageDataMaxSize, vm::ptr<u32> avatarImageDataSize, vm::ptr<void> option)
{
sceNp.todo("sceNpLookupUserProfileWithAvatarSize(transId=%d, avatarSizeType=%d, npId=*0x%x, userInfo=*0x%x, aboutMe=*0x%x, languages=*0x%x, countryCode=*0x%x, avatarImageData=*0x%x, "
"avatarImageDataMaxSize=%d, avatarImageDataSize=*0x%x, option=*0x%x)",
transId, avatarSizeType, npId, userInfo, aboutMe, languages, countryCode, avatarImageData, avatarImageDataMaxSize, avatarImageDataSize, option);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Lookup_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (!npId)
{
return SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT;
}
if (option) // option check at least until fw 4.71
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ONLINE_ID;
}
return CELL_OK;
}
error_code sceNpLookupUserProfileWithAvatarSizeAsync(s32 transId, s32 avatarSizeType, vm::cptr<SceNpId> npId, vm::ptr<SceNpUserInfo> userInfo, vm::ptr<SceNpAboutMe> aboutMe,
vm::ptr<SceNpMyLanguages> languages, vm::ptr<SceNpCountryCode> countryCode, vm::ptr<void> avatarImageData, u32 avatarImageDataMaxSize, vm::ptr<u32> avatarImageDataSize, s32 prio,
vm::ptr<void> option)
{
sceNp.todo("sceNpLookupUserProfileWithAvatarSizeAsync(transId=%d, avatarSizeType=%d, npId=*0x%x, userInfo=*0x%x, aboutMe=*0x%x, languages=*0x%x, countryCode=*0x%x, avatarImageData=*0x%x, "
"avatarImageDataMaxSize=%d, avatarImageDataSize=*0x%x, prio=%d, option=*0x%x)",
transId, avatarSizeType, npId, userInfo, aboutMe, languages, countryCode, avatarImageData, avatarImageDataMaxSize, avatarImageDataSize, prio, option);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Lookup_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (!npId)
{
return SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT;
}
if (option) // option check at least until fw 4.71
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ONLINE_ID;
}
return CELL_OK;
}
error_code sceNpLookupAvatarImage(s32 transId, vm::ptr<SceNpAvatarUrl> avatarUrl, vm::ptr<SceNpAvatarImage> avatarImage, vm::ptr<void> option)
{
sceNp.todo("sceNpLookupAvatarImage(transId=%d, avatarUrl=*0x%x, avatarImage=*0x%x, option=*0x%x)", transId, avatarUrl, avatarImage, option);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Lookup_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (!avatarUrl || !avatarImage)
{
return SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT;
}
if (option) // option check at least until fw 4.71
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ONLINE_ID;
}
return CELL_OK;
}
error_code sceNpLookupAvatarImageAsync(s32 transId, vm::ptr<SceNpAvatarUrl> avatarUrl, vm::ptr<SceNpAvatarImage> avatarImage, s32 prio, vm::ptr<void> option)
{
sceNp.todo("sceNpLookupAvatarImageAsync(transId=%d, avatarUrl=*0x%x, avatarImage=*0x%x, prio=%d, option=*0x%x)", transId, avatarUrl, avatarImage, prio, option);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Lookup_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (!avatarUrl || !avatarImage)
{
return SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT;
}
if (option) // option check at least until fw 4.71
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ONLINE_ID;
}
return CELL_OK;
}
error_code sceNpLookupTitleStorage()
{
UNIMPLEMENTED_FUNC(sceNp);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Lookup_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
return CELL_OK;
}
error_code sceNpLookupTitleStorageAsync()
{
UNIMPLEMENTED_FUNC(sceNp);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Lookup_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
return CELL_OK;
}
error_code sceNpLookupTitleSmallStorage(s32 transId, vm::ptr<void> data, u32 maxSize, vm::ptr<u32> contentLength, vm::ptr<void> option)
{
sceNp.todo("sceNpLookupTitleSmallStorage(transId=%d, data=*0x%x, maxSize=%d, contentLength=*0x%x, option=*0x%x)", transId, data, maxSize, contentLength, option);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Lookup_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (!data)
{
return SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT;
}
if (option) // option check at least until fw 4.71
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
//if (something > maxSize)
//{
// return SCE_NP_COMMUNITY_ERROR_BODY_TOO_LARGE;
//}
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ONLINE_ID;
}
return CELL_OK;
}
error_code sceNpLookupTitleSmallStorageAsync(s32 transId, vm::ptr<void> data, u32 maxSize, vm::ptr<u32> contentLength, s32 prio, vm::ptr<void> option)
{
sceNp.todo("sceNpLookupTitleSmallStorageAsync(transId=%d, data=*0x%x, maxSize=%d, contentLength=*0x%x, prio=%d, option=*0x%x)", transId, data, maxSize, contentLength, prio, option);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Lookup_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (!data)
{
return SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT;
}
if (option) // option check at least until fw 4.71
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
//if (something > maxSize)
//{
// return SCE_NP_COMMUNITY_ERROR_BODY_TOO_LARGE;
//}
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ONLINE_ID;
}
// TSS are game specific data we don't have access to, set buf to 0, return size 0
std::memset(data.get_ptr(), 0, maxSize);
*contentLength = 0;
return CELL_OK;
}
error_code sceNpManagerRegisterCallback(vm::ptr<SceNpManagerCallback> callback, vm::ptr<void> arg)
{
sceNp.warning("sceNpManagerRegisterCallback(callback=*0x%x, arg=*0x%x)", callback, arg);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_ERROR_NOT_INITIALIZED;
}
if (!callback)
{
return SCE_NP_ERROR_INVALID_ARGUMENT;
}
nph.manager_cb = callback;
nph.manager_cb_arg = arg;
return CELL_OK;
}
error_code sceNpManagerUnregisterCallback()
{
sceNp.warning("sceNpManagerUnregisterCallback()");
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_ERROR_NOT_INITIALIZED;
}
nph.manager_cb.set(0);
return CELL_OK;
}
error_code sceNpManagerGetStatus(vm::ptr<s32> status)
{
sceNp.trace("sceNpManagerGetStatus(status=*0x%x)", status);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_ERROR_NOT_INITIALIZED;
}
if (!status)
{
return SCE_NP_ERROR_INVALID_ARGUMENT;
}
*status = nph.get_psn_status();
return CELL_OK;
}
error_code sceNpManagerGetNetworkTime(vm::ptr<CellRtcTick> pTick)
{
sceNp.warning("sceNpManagerGetNetworkTime(pTick=*0x%x)", pTick);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return not_an_error(SCE_NP_ERROR_NOT_INITIALIZED);
}
if (!pTick)
{
return SCE_NP_ERROR_INVALID_ARGUMENT;
}
if (nph.get_psn_status() == SCE_NP_MANAGER_STATUS_OFFLINE)
{
return not_an_error(SCE_NP_ERROR_OFFLINE);
}
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_ERROR_INVALID_STATE;
}
pTick->tick = nph.get_network_time();
return CELL_OK;
}
error_code sceNpManagerGetOnlineId(vm::ptr<SceNpOnlineId> onlineId)
{
sceNp.warning("sceNpManagerGetOnlineId(onlineId=*0x%x)", onlineId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_ERROR_NOT_INITIALIZED;
}
if (!onlineId)
{
return SCE_NP_ERROR_INVALID_ARGUMENT;
}
if (nph.get_psn_status() == SCE_NP_MANAGER_STATUS_OFFLINE)
{
return not_an_error(SCE_NP_ERROR_OFFLINE);
}
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_LOGGING_IN && nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_ERROR_INVALID_STATE;
}
memcpy(onlineId.get_ptr(), &nph.get_online_id(), onlineId.size());
return CELL_OK;
}
error_code sceNpManagerGetNpId(vm::ptr<SceNpId> npId)
{
sceNp.trace("sceNpManagerGetNpId(npId=*0x%x)", npId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_ERROR_NOT_INITIALIZED;
}
if (!npId)
{
return SCE_NP_ERROR_INVALID_ARGUMENT;
}
if (nph.get_psn_status() == SCE_NP_MANAGER_STATUS_OFFLINE)
{
return not_an_error(SCE_NP_ERROR_OFFLINE);
}
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_LOGGING_IN && nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_ERROR_INVALID_STATE;
}
memcpy(npId.get_ptr(), &nph.get_npid(), npId.size());
return CELL_OK;
}
error_code sceNpManagerGetOnlineName(ppu_thread& ppu, vm::ptr<SceNpOnlineName> onlineName)
{
ppu.state += cpu_flag::wait;
sceNp.trace("sceNpManagerGetOnlineName(onlineName=*0x%x)", onlineName);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_ERROR_NOT_INITIALIZED;
}
if (!onlineName)
{
return SCE_NP_ERROR_INVALID_ARGUMENT;
}
if (nph.get_psn_status() == SCE_NP_MANAGER_STATUS_OFFLINE)
{
return not_an_error(SCE_NP_ERROR_OFFLINE);
}
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_ERROR_INVALID_STATE;
}
ppu.check_state();
std::memcpy(onlineName.get_ptr(), &nph.get_online_name(), onlineName.size());
return CELL_OK;
}
error_code sceNpManagerGetAvatarUrl(ppu_thread& ppu, vm::ptr<SceNpAvatarUrl> avatarUrl)
{
ppu.state += cpu_flag::wait;
sceNp.trace("sceNpManagerGetAvatarUrl(avatarUrl=*0x%x)", avatarUrl);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_ERROR_NOT_INITIALIZED;
}
if (!avatarUrl)
{
return SCE_NP_ERROR_INVALID_ARGUMENT;
}
if (nph.get_psn_status() == SCE_NP_MANAGER_STATUS_OFFLINE)
{
return not_an_error(SCE_NP_ERROR_OFFLINE);
}
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_ERROR_INVALID_STATE;
}
ppu.check_state();
std::memcpy(avatarUrl.get_ptr(), &nph.get_avatar_url(), avatarUrl.size());
return CELL_OK;
}
error_code sceNpManagerGetMyLanguages(vm::ptr<SceNpMyLanguages> myLanguages)
{
sceNp.trace("sceNpManagerGetMyLanguages(myLanguages=*0x%x)", myLanguages);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_ERROR_NOT_INITIALIZED;
}
if (!myLanguages)
{
return SCE_NP_ERROR_INVALID_ARGUMENT;
}
if (nph.get_psn_status() == SCE_NP_MANAGER_STATUS_OFFLINE)
{
return not_an_error(SCE_NP_ERROR_OFFLINE);
}
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_ERROR_INVALID_STATE;
}
myLanguages->language1 = SCE_NP_LANG_ENGLISH_US;
myLanguages->language2 = g_cfg.sys.language != CELL_SYSUTIL_LANG_ENGLISH_US ? g_cfg.sys.language : -1;
myLanguages->language3 = -1;
return CELL_OK;
}
error_code sceNpManagerGetAccountRegion(vm::ptr<SceNpCountryCode> countryCode, vm::ptr<s32> language)
{
sceNp.warning("sceNpManagerGetAccountRegion(countryCode=*0x%x, language=*0x%x)", countryCode, language);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_ERROR_NOT_INITIALIZED;
}
if (!countryCode || !language)
{
return SCE_NP_ERROR_INVALID_ARGUMENT;
}
if (nph.get_psn_status() == SCE_NP_MANAGER_STATUS_OFFLINE)
{
return not_an_error(SCE_NP_ERROR_OFFLINE);
}
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_LOGGING_IN && nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_ERROR_INVALID_STATE;
}
const std::string ccode = g_cfg.net.country.to_string();
std::memset(countryCode.get_ptr(), 0, sizeof(countryCode));
ensure(ccode.size() == sizeof(SceNpCountryCode::data));
std::memcpy(countryCode->data, ccode.data(), sizeof(SceNpCountryCode::data));
*language = CELL_SYSUTIL_LANG_ENGLISH_US;
return CELL_OK;
}
error_code sceNpManagerGetAccountAge(vm::ptr<s32> age)
{
sceNp.warning("sceNpManagerGetAccountAge(age=*0x%x)", age);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_ERROR_NOT_INITIALIZED;
}
if (!age)
{
return SCE_NP_ERROR_INVALID_ARGUMENT;
}
if (nph.get_psn_status() == SCE_NP_MANAGER_STATUS_OFFLINE)
{
return not_an_error(SCE_NP_ERROR_OFFLINE);
}
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_LOGGING_IN && nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_ERROR_INVALID_STATE;
}
*age = 18;
return CELL_OK;
}
error_code sceNpManagerGetContentRatingFlag(vm::ptr<s32> isRestricted, vm::ptr<s32> age)
{
sceNp.trace("sceNpManagerGetContentRatingFlag(isRestricted=*0x%x, age=*0x%x)", isRestricted, age);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_ERROR_NOT_INITIALIZED;
}
if (!isRestricted || !age)
{
return SCE_NP_ERROR_INVALID_ARGUMENT;
}
if (nph.get_psn_status() == SCE_NP_MANAGER_STATUS_OFFLINE)
{
return not_an_error(SCE_NP_ERROR_OFFLINE);
}
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_LOGGING_IN && nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_ERROR_INVALID_STATE;
}
// TODO: read user's parental control information
*isRestricted = 0;
*age = 18;
return CELL_OK;
}
error_code sceNpManagerGetChatRestrictionFlag(vm::ptr<s32> isRestricted)
{
sceNp.trace("sceNpManagerGetChatRestrictionFlag(isRestricted=*0x%x)", isRestricted);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_ERROR_NOT_INITIALIZED;
}
if (!isRestricted)
{
return SCE_NP_ERROR_INVALID_ARGUMENT;
}
if (nph.get_psn_status() == SCE_NP_MANAGER_STATUS_OFFLINE)
{
return not_an_error(SCE_NP_ERROR_OFFLINE);
}
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_LOGGING_IN && nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_ERROR_INVALID_STATE;
}
// TODO: read user's parental control information
*isRestricted = 0;
return CELL_OK;
}
error_code sceNpManagerGetCachedInfo(CellSysutilUserId userId, vm::ptr<SceNpManagerCacheParam> param)
{
sceNp.warning("sceNpManagerGetCachedInfo(userId=%d, param=*0x%x)", userId, param);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_ERROR_NOT_INITIALIZED;
}
if (!param)
{
return SCE_NP_ERROR_INVALID_ARGUMENT;
}
if (userId != CELL_SYSUTIL_USERID_CURRENT && userId != Emu.GetUsrId())
{
return CELL_ENOENT;
}
param->size = sizeof(SceNpManagerCacheParam);
param->onlineId = nph.get_online_id();
param->npId = nph.get_npid();
param->onlineName = nph.get_online_name();
param->avatarUrl = nph.get_avatar_url();
return CELL_OK;
}
error_code sceNpManagerGetPsHandle(vm::ptr<SceNpOnlineId> onlineId)
{
sceNp.warning("sceNpManagerGetPsHandle(onlineId=*0x%x)", onlineId);
return sceNpManagerGetOnlineId(onlineId);
}
error_code sceNpManagerRequestTicket(vm::cptr<SceNpId> npId, vm::cptr<char> serviceId, vm::cptr<void> cookie, u32 cookieSize, vm::cptr<char> entitlementId, u32 consumedCount)
{
sceNp.warning("sceNpManagerRequestTicket(npId=*0x%x, serviceId=%s, cookie=*0x%x, cookieSize=%d, entitlementId=%s, consumedCount=%d)", npId, serviceId, cookie, cookieSize, entitlementId, consumedCount);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_ERROR_NOT_INITIALIZED;
}
if (!npId || !serviceId || cookieSize > SCE_NP_COOKIE_MAX_SIZE)
{
return SCE_NP_AUTH_EINVALID_ARGUMENT;
}
if (nph.get_psn_status() == SCE_NP_MANAGER_STATUS_OFFLINE)
{
return not_an_error(SCE_NP_ERROR_OFFLINE);
}
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_LOGGING_IN && nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_ERROR_INVALID_STATE;
}
nph.req_ticket(0x00020001, npId.get_ptr(), serviceId.get_ptr(), static_cast<const u8*>(cookie.get_ptr()), cookieSize, entitlementId.get_ptr(), consumedCount);
return CELL_OK;
}
error_code sceNpManagerRequestTicket2(vm::cptr<SceNpId> npId, vm::cptr<SceNpTicketVersion> version, vm::cptr<char> serviceId,
vm::cptr<void> cookie, u32 cookieSize, vm::cptr<char> entitlementId, u32 consumedCount)
{
sceNp.warning("sceNpManagerRequestTicket2(npId=*0x%x, version=*0x%x, serviceId=%s, cookie=*0x%x, cookieSize=%d, entitlementId=%s, consumedCount=%d)", npId, version, serviceId, cookie, cookieSize,
entitlementId, consumedCount);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_ERROR_NOT_INITIALIZED;
}
if (!npId || !serviceId || cookieSize > SCE_NP_COOKIE_MAX_SIZE)
{
return SCE_NP_AUTH_EINVALID_ARGUMENT;
}
if (nph.get_psn_status() == SCE_NP_MANAGER_STATUS_OFFLINE)
{
return not_an_error(SCE_NP_ERROR_OFFLINE);
}
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_LOGGING_IN && nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_ERROR_INVALID_STATE;
}
nph.req_ticket(0x00020001, npId.get_ptr(), serviceId.get_ptr(), static_cast<const u8*>(cookie.get_ptr()), cookieSize, entitlementId.get_ptr(), consumedCount);
return CELL_OK;
}
error_code sceNpManagerGetTicket(vm::ptr<void> buffer, vm::ptr<u32> bufferSize)
{
sceNp.warning("sceNpManagerGetTicket(buffer=*0x%x, bufferSize=*0x%x)", buffer, bufferSize);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_ERROR_NOT_INITIALIZED;
}
if (!bufferSize)
{
return SCE_NP_ERROR_INVALID_ARGUMENT;
}
const auto& ticket = nph.get_ticket();
*bufferSize = static_cast<u32>(ticket.size());
if (!buffer)
{
return CELL_OK;
}
if (*bufferSize < ticket.size())
{
return SCE_NP_ERROR_INVALID_ARGUMENT;
}
memcpy(buffer.get_ptr(), ticket.data(), ticket.size());
return CELL_OK;
}
error_code sceNpManagerGetTicketParam(s32 paramId, vm::ptr<SceNpTicketParam> param)
{
sceNp.notice("sceNpManagerGetTicketParam(paramId=%d, param=*0x%x)", paramId, param);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_ERROR_NOT_INITIALIZED;
}
if (!param || paramId < SCE_NP_TICKET_PARAM_SERIAL_ID || paramId > SCE_NP_TICKET_PARAM_SUBJECT_DOB)
{
return SCE_NP_ERROR_INVALID_ARGUMENT;
}
const auto& ticket = nph.get_ticket();
if (ticket.empty())
{
return SCE_NP_ERROR_INVALID_STATE;
}
if (!ticket.get_value(paramId, param))
{
return SCE_NP_ERROR_INVALID_STATE;
}
return CELL_OK;
}
error_code sceNpManagerGetEntitlementIdList(vm::ptr<SceNpEntitlementId> entIdList, u32 entIdListNum)
{
sceNp.todo("sceNpManagerGetEntitlementIdList(entIdList=*0x%x, entIdListNum=%d)", entIdList, entIdListNum);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_ERROR_NOT_INITIALIZED;
}
return not_an_error(0);
}
error_code sceNpManagerGetEntitlementById(vm::cptr<char> entId, vm::ptr<SceNpEntitlement> ent)
{
sceNp.todo("sceNpManagerGetEntitlementById(entId=%s, ent=*0x%x)", entId, ent);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_ERROR_NOT_INITIALIZED;
}
if (!entId)
{
return SCE_NP_ERROR_INVALID_ARGUMENT;
}
return CELL_OK;
}
error_code sceNpManagerGetSigninId(vm::ptr<void> signInId)
{
sceNp.todo("sceNpManagerGetSigninId(signInId==*0x%x)", signInId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_ERROR_NOT_INITIALIZED;
}
if (!signInId)
{
return SCE_NP_ERROR_INVALID_ARGUMENT;
}
std::memset(signInId.get_ptr(), 0, 64); // signInId seems to be a 64 byte thing
return CELL_OK;
}
error_code sceNpManagerSubSignin(CellSysutilUserId userId, vm::ptr<SceNpManagerSubSigninCallback> cb_func, vm::ptr<void> cb_arg, s32 flag)
{
sceNp.todo("sceNpManagerSubSignin(userId=%d, cb_func=*0x%x, cb_arg=*0x%x, flag=%d)", userId, cb_func, cb_arg, flag);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_ERROR_NOT_INITIALIZED;
}
return CELL_OK;
}
error_code sceNpManagerSubSigninAbortGui()
{
sceNp.todo("sceNpManagerSubSigninAbortGui()");
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_ERROR_NOT_INITIALIZED;
}
return CELL_OK;
}
error_code sceNpManagerSubSignout(vm::ptr<SceNpId> npId)
{
sceNp.todo("sceNpManagerSubSignout(npId=*0x%x)", npId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_ERROR_NOT_INITIALIZED;
}
return CELL_OK;
}
// FUN_000146fc
error_code check_attr_id(vm::cptr<SceNpMatchingAttr> attr)
{
ensure(!!attr);
if (!attr) return SCE_NP_MATCHING_ERROR_INVALID_ATTR_ID; // Satisfy compiler
switch (attr->type)
{
case SCE_NP_MATCHING_ATTR_TYPE_BASIC_BIN:
{
return SCE_NP_MATCHING_ERROR_INVALID_ATTR_ID;
}
case SCE_NP_MATCHING_ATTR_TYPE_BASIC_NUM:
{
if (attr->id < SCE_NP_MATCHING_ROOM_ATTR_ID_TOTAL_SLOT ||
attr->id > SCE_NP_MATCHING_ROOM_ATTR_ID_ROOM_SEARCH_FLAG)
return SCE_NP_MATCHING_ERROR_INVALID_ATTR_ID;
break;
}
case SCE_NP_MATCHING_ATTR_TYPE_GAME_BIN:
case SCE_NP_MATCHING_ATTR_TYPE_GAME_NUM:
{
if (attr->id < 1 || attr->id > 16)
return SCE_NP_MATCHING_ERROR_INVALID_ATTR_ID;
break;
}
default:
break;
}
return CELL_OK;
}
// FUN_0001476c
error_code check_duplicate_attr(vm::cptr<SceNpMatchingAttr> attribute)
{
std::set<s32> attr_type_id;
for (auto attr = attribute; !!attr; attr = attr->next)
{
// There are 4 types times 16 ids
const s32 type_id = (attr->type - 1) * 16 + attr->id - 1;
if (!attr_type_id.insert(type_id).second)
return SCE_NP_MATCHING_ERROR_DUPLICATE;
}
return CELL_OK;
}
// FUN_00011718
error_code check_attr_id_and_duplicate(vm::cptr<SceNpMatchingAttr> attribute)
{
for (auto attr = attribute; !!attr; attr = attr->next)
{
error_code err = check_attr_id(attr);
if (err != CELL_OK)
return err;
}
return check_duplicate_attr(attribute);
}
// FUN_000245e0
error_code check_text(vm::cptr<char> text)
{
if (!text)
return SCE_NP_UTIL_ERROR_INVALID_ARGUMENT;
u32 count = 0;
while (true)
{
const char c = *text;
if (c == '\0')
break;
const u32 val = static_cast<u32>(static_cast<u8>(c));
if (c < '\0')
{
if ((val & 0xe0) == 0xc0 && val > 0xc1 &&
(text[1] & 0xc0U) == 0x80)
{
text += 2;
}
else if ((val & 0xf0) == 0xe0 &&
(text[1] & 0xc0U) == 0x80 &&
(text[2] & 0xc0U) == 0x80)
{
text += 3;
}
else
{
if ((val & 0xf8) != 0xf0 ||
(text[1] & 0xc0U) != 0x80 ||
(text[2] & 0xc0U) != 0x80 ||
(text[3] & 0xc0U) != 0x80)
{
return SCE_NP_UTIL_ERROR_INVALID_CHARACTER;
}
text += 4;
}
}
else
{
if (false) // TODO: check current char
return SCE_NP_UTIL_ERROR_INVALID_CHARACTER;
text++;
}
count++;
}
return not_an_error(count);
}
error_code sceNpMatchingCreateCtx(vm::ptr<SceNpId> npId, vm::ptr<SceNpMatchingHandler> handler, vm::ptr<void> arg, vm::ptr<u32> ctx_id)
{
sceNp.warning("sceNpMatchingCreateCtx(npId=*0x%x, handler=*0x%x, arg=*0x%x, ctx_id=*0x%x)", npId, handler, arg, ctx_id);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (nph.is_NP2_Match2_init)
{
return SCE_NP_MATCHING_ERROR_UTILITY_UNAVAILABLE;
}
if (!nph.is_NP_init)
{
return SCE_NP_MATCHING_ERROR_NOT_INITIALIZED;
}
// assumed checks done on vsh
if (!npId || !handler || !ctx_id)
{
return SCE_NP_MATCHING_ERROR_INVALID_ARG;
}
const s32 id = create_matching_context(npId, handler, arg);
if (!id)
{
return SCE_NP_MATCHING_ERROR_CTX_MAX;
}
nph.set_current_gui_ctx_id(id);
*ctx_id = static_cast<u32>(id);
return CELL_OK;
}
error_code sceNpMatchingDestroyCtx(u32 ctx_id)
{
sceNp.warning("sceNpMatchingDestroyCtx(ctx_id=%d)", ctx_id);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (nph.is_NP2_Match2_init)
return SCE_NP_MATCHING_ERROR_UTILITY_UNAVAILABLE;
if (!nph.is_NP_init)
return SCE_NP_MATCHING_ERROR_NOT_INITIALIZED;
if (!destroy_matching_context(ctx_id))
return SCE_NP_MATCHING_ERROR_CTX_NOT_FOUND;
nph.set_current_gui_ctx_id(0);
return CELL_OK;
}
error_code sceNpMatchingGetResult(u32 ctx_id, u32 req_id, vm::ptr<void> buf, vm::ptr<u32> size, vm::ptr<s32> event)
{
sceNp.warning("sceNpMatchingGetResult(ctx_id=%d, req_id=%d, buf=*0x%x, size=*0x%x, event=*0x%x)", ctx_id, req_id, buf, size, event);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (nph.is_NP2_Match2_init)
return SCE_NP_MATCHING_ERROR_UTILITY_UNAVAILABLE;
if (!nph.is_NP_init)
return SCE_NP_MATCHING_ERROR_NOT_INITIALIZED;
if (!size)
return SCE_NP_MATCHING_ERROR_INVALID_ARG;
return nph.get_matching_result(ctx_id, req_id, buf, size, event);
// const u64 id_check = static_cast<s64>(static_cast<s32>(req_id)) >> 0x17 & 0x3f;
// if (id_check > 32 || (1ULL << id_check & 0x1f89ad040U) == 0)
// return SCE_NP_MATCHING_ERROR_INVALID_REQ_ID;
}
error_code sceNpMatchingGetResultGUI(vm::ptr<void> buf, vm::ptr<u32> size, vm::ptr<s32> event)
{
sceNp.warning("sceNpMatchingGetResultGUI(buf=*0x%x, size=*0x%x, event=*0x%x)", buf, size, event);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (nph.is_NP2_Match2_init)
return SCE_NP_MATCHING_ERROR_UTILITY_UNAVAILABLE;
if (!size)
return SCE_NP_MATCHING_ERROR_INVALID_ARG;
return nph.get_result_gui(buf, size, event);
}
error_code matching_set_room_info(u32 ctx_id, vm::ptr<SceNpLobbyId> lobby_id, vm::ptr<SceNpRoomId> room_id, vm::ptr<SceNpMatchingAttr> attr, vm::ptr<u32> req_id, bool limit)
{
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (nph.is_NP2_Match2_init)
return SCE_NP_MATCHING_ERROR_UTILITY_UNAVAILABLE;
if (!nph.is_NP_init)
return SCE_NP_MATCHING_ERROR_NOT_INITIALIZED;
if (limit)
{
static u64 last_call = 0;
if (last_call != 0 && (get_system_time() - last_call) < 30'000'000)
return SCE_NP_MATCHING_ERROR_BUSY;
last_call = get_system_time();
}
if (!lobby_id || !room_id || !req_id || !attr)
return SCE_NP_MATCHING_ERROR_INVALID_ARG;
error_code err = check_attr_id_and_duplicate(attr);
if (err != CELL_OK)
return err;
auto res = nph.set_room_info_gui(ctx_id, lobby_id, room_id, attr);
if (res < 0)
return res;
*req_id = res;
return CELL_OK;
}
error_code sceNpMatchingSetRoomInfo(u32 ctx_id, vm::ptr<SceNpLobbyId> lobby_id, vm::ptr<SceNpRoomId> room_id, vm::ptr<SceNpMatchingAttr> attr, vm::ptr<u32> req_id)
{
sceNp.warning("sceNpMatchingSetRoomInfo(ctx_id=%d, lobby_id=*0x%x, room_id=*0x%x, attr=*0x%x, req_id=*0x%x)", ctx_id, lobby_id, room_id, attr, req_id);
return matching_set_room_info(ctx_id, lobby_id, room_id, attr, req_id, true);
}
error_code sceNpMatchingSetRoomInfoNoLimit(u32 ctx_id, vm::ptr<SceNpLobbyId> lobby_id, vm::ptr<SceNpRoomId> room_id, vm::ptr<SceNpMatchingAttr> attr, vm::ptr<u32> req_id)
{
sceNp.warning("sceNpMatchingSetRoomInfoNoLimit(ctx_id=%d, lobby_id=*0x%x, room_id=*0x%x, attr=*0x%x, req_id=*0x%x)", ctx_id, lobby_id, room_id, attr, req_id);
return matching_set_room_info(ctx_id, lobby_id, room_id, attr, req_id, false);
}
error_code matching_get_room_info(u32 ctx_id, vm::ptr<SceNpLobbyId> lobby_id, vm::ptr<SceNpRoomId> room_id, vm::ptr<SceNpMatchingAttr> attr, vm::ptr<u32> req_id, bool limit)
{
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (nph.is_NP2_Match2_init)
return SCE_NP_MATCHING_ERROR_UTILITY_UNAVAILABLE;
if (!nph.is_NP_init)
return SCE_NP_MATCHING_ERROR_NOT_INITIALIZED;
if (limit)
{
static u64 last_call = 0;
if (last_call != 0 && (get_system_time() - last_call) < 30'000'000)
return SCE_NP_MATCHING_ERROR_BUSY;
last_call = get_system_time();
}
if (!lobby_id || !room_id || !req_id || !attr)
return SCE_NP_MATCHING_ERROR_INVALID_ARG;
error_code err = check_attr_id_and_duplicate(attr);
if (err != CELL_OK)
return err;
auto res = nph.get_room_info_gui(ctx_id, lobby_id, room_id, attr);
if (res < 0)
return res;
*req_id = res;
return CELL_OK;
}
error_code sceNpMatchingGetRoomInfo(u32 ctx_id, vm::ptr<SceNpLobbyId> lobby_id, vm::ptr<SceNpRoomId> room_id, vm::ptr<SceNpMatchingAttr> attr, vm::ptr<u32> req_id)
{
sceNp.warning("sceNpMatchingGetRoomInfo(ctx_id=%d, lobby_id=*0x%x, room_id=*0x%x, attr=*0x%x, req_id=*0x%x)", ctx_id, lobby_id, room_id, attr, req_id);
return matching_get_room_info(ctx_id, lobby_id, room_id, attr, req_id, true);
}
error_code sceNpMatchingGetRoomInfoNoLimit(u32 ctx_id, vm::ptr<SceNpLobbyId> lobby_id, vm::ptr<SceNpRoomId> room_id, vm::ptr<SceNpMatchingAttr> attr, vm::ptr<u32> req_id)
{
sceNp.warning("sceNpMatchingGetRoomInfoNoLimit(ctx_id=%d, lobby_id=*0x%x, room_id=*0x%x, attr=*0x%x, req_id=*0x%x)", ctx_id, lobby_id, room_id, attr, req_id);
return matching_get_room_info(ctx_id, lobby_id, room_id, attr, req_id, false);
}
error_code sceNpMatchingSetRoomSearchFlag(u32 ctx_id, vm::ptr<SceNpLobbyId> lobby_id, vm::ptr<SceNpRoomId> room_id, s32 flag, vm::ptr<u32> req_id)
{
sceNp.warning("sceNpMatchingSetRoomSearchFlag(ctx_id=%d, lobby_id=*0x%x, room_id=*0x%x, flag=%d, req_id=*0x%x)", ctx_id, lobby_id, room_id, flag, req_id);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (nph.is_NP2_Match2_init)
return SCE_NP_MATCHING_ERROR_UTILITY_UNAVAILABLE;
if (!nph.is_NP_init)
return SCE_NP_MATCHING_ERROR_NOT_INITIALIZED;
if (!lobby_id || !room_id || !req_id || (flag < SCE_NP_MATCHING_ROOM_SEARCH_FLAG_OPEN || flag > SCE_NP_MATCHING_ROOM_SEARCH_FLAG_STEALTH))
return SCE_NP_MATCHING_ERROR_INVALID_ARG;
auto res = nph.set_room_search_flag_gui(ctx_id, lobby_id, room_id, flag);
if (res < 0)
return res;
*req_id = res;
return CELL_OK;
}
error_code sceNpMatchingGetRoomSearchFlag(u32 ctx_id, vm::ptr<SceNpLobbyId> lobby_id, vm::ptr<SceNpRoomId> room_id, vm::ptr<u32> req_id)
{
sceNp.warning("sceNpMatchingGetRoomSearchFlag(ctx_id=%d, lobby_id=*0x%x, room_id=*0x%x, req_id=*0x%x)", ctx_id, lobby_id, room_id, req_id);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (nph.is_NP2_Match2_init)
return SCE_NP_MATCHING_ERROR_UTILITY_UNAVAILABLE;
if (!nph.is_NP_init)
return SCE_NP_MATCHING_ERROR_NOT_INITIALIZED;
if (!lobby_id || !room_id || !req_id)
return SCE_NP_MATCHING_ERROR_INVALID_ARG;
auto res = nph.get_room_search_flag_gui(ctx_id, lobby_id, room_id);
if (res < 0)
return res;
*req_id = res;
return CELL_OK;
}
error_code matching_get_room_member_list(u32 ctx_id, vm::ptr<SceNpRoomId> room_id, vm::ptr<u32> buflen, vm::ptr<void> buf)
{
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (nph.is_NP2_Match2_init)
return SCE_NP_MATCHING_ERROR_UTILITY_UNAVAILABLE;
if (!nph.is_NP_init)
return SCE_NP_MATCHING_ERROR_NOT_INITIALIZED;
if (!buflen)
return SCE_NP_MATCHING_ERROR_INVALID_ARG;
return nph.get_room_member_list_local_gui(ctx_id, room_id, buflen, buf);
}
error_code sceNpMatchingGetRoomMemberListLocal(u32 ctx_id, vm::ptr<SceNpRoomId> room_id, vm::ptr<u32> buflen, vm::ptr<void> buf)
{
sceNp.warning("sceNpMatchingGetRoomMemberListLocal(ctx_id=%d, room_id=*0x%x, buflen=*0x%x, buf=*0x%x)", ctx_id, room_id, buflen, buf);
return matching_get_room_member_list(ctx_id, room_id, buflen, buf);
}
// FUN_00014bdc
error_code check_room_list_params([[maybe_unused]] u32 ctx_id, vm::ptr<SceNpCommunicationId> communicationId, vm::ptr<SceNpMatchingReqRange> range, vm::ptr<SceNpMatchingSearchCondition> cond,
vm::ptr<SceNpMatchingAttr> attribute, vm::ptr<SceNpMatchingGUIHandler> handler, int param_7, int param_8)
{
if (!communicationId || !range || !handler)
return SCE_NP_MATCHING_ERROR_INVALID_ARG;
if ((!param_8 && !range->start) || range->max > 20)
return SCE_NP_MATCHING_ERROR_INVALID_ARG;
u32 total_count = 0;
u32 inequality_count = 0;
u32 max_count = 10;
if (param_7 != 0)
{
max_count = 9;
}
for (auto con = cond; !!con; con = con->next)
{
if (++total_count > max_count)
return SCE_NP_MATCHING_ERROR_COND_MAX;
if (con->comp_type != SCE_NP_MATCHING_CONDITION_TYPE_VALUE ||
con->comp_op < SCE_NP_MATCHING_CONDITION_SEARCH_EQ ||
con->comp_op > SCE_NP_MATCHING_CONDITION_SEARCH_GE)
return SCE_NP_MATCHING_ERROR_INVALID_COND;
if (con->comp_op > SCE_NP_MATCHING_CONDITION_SEARCH_NE &&
++inequality_count > max_count)
return SCE_NP_MATCHING_ERROR_COMP_OP_INEQUALITY_MAX;
switch (con->target_attr_type)
{
case SCE_NP_MATCHING_ATTR_TYPE_BASIC_BIN:
case SCE_NP_MATCHING_ATTR_TYPE_GAME_BIN:
{
return SCE_NP_MATCHING_ERROR_INVALID_COND;
}
case SCE_NP_MATCHING_ATTR_TYPE_BASIC_NUM:
{
if (param_7 == 0)
{
if (con->target_attr_id < SCE_NP_MATCHING_ROOM_ATTR_ID_TOTAL_SLOT ||
con->target_attr_id > SCE_NP_MATCHING_ROOM_ATTR_ID_ROOM_SEARCH_FLAG)
return SCE_NP_MATCHING_ERROR_INVALID_COND;
}
else
{
if (con->target_attr_id == SCE_NP_MATCHING_ROOM_ATTR_ID_TOTAL_SLOT)
return SCE_NP_MATCHING_ERROR_INVALID_COND;
}
break;
}
case SCE_NP_MATCHING_ATTR_TYPE_GAME_NUM:
{
const u32 max_id = (param_7 == 0) ? 16 : 8;
if (con->target_attr_id < 1 || con->target_attr_id > max_id)
return SCE_NP_MATCHING_ERROR_INVALID_COND;
break;
}
default:
break;
}
}
return check_attr_id_and_duplicate(attribute);
}
error_code matching_get_room_list(u32 ctx_id, vm::ptr<SceNpCommunicationId> communicationId, vm::ptr<SceNpMatchingReqRange> range, vm::ptr<SceNpMatchingSearchCondition> cond,
vm::ptr<SceNpMatchingAttr> attr, vm::ptr<SceNpMatchingGUIHandler> handler, vm::ptr<void> arg, bool limit)
{
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (nph.is_NP2_Match2_init)
return SCE_NP_MATCHING_ERROR_UTILITY_UNAVAILABLE;
// TODO: add limiter
// This check is used in all sceNpMatchingGetRoomList functions
error_code err = check_room_list_params(ctx_id, communicationId, range, cond, attr, handler, 1, 0);
if (err != CELL_OK)
return err;
return nph.get_room_list_gui(ctx_id, communicationId, range, cond, attr, handler, arg, limit);
}
error_code sceNpMatchingGetRoomListLimitGUI(u32 ctx_id, vm::ptr<SceNpCommunicationId> communicationId, vm::ptr<SceNpMatchingReqRange> range, vm::ptr<SceNpMatchingSearchCondition> cond,
vm::ptr<SceNpMatchingAttr> attr, vm::ptr<SceNpMatchingGUIHandler> handler, vm::ptr<void> arg)
{
sceNp.warning("sceNpMatchingGetRoomListLimitGUI(ctx_id=%d, communicationId=*0x%x, range=*0x%x, cond=*0x%x, attr=*0x%x, handler=*0x%x, arg=*0x%x)", ctx_id, communicationId, range, cond, attr, handler, arg);
return matching_get_room_list(ctx_id, communicationId, range, cond, attr, handler, arg, true);
}
error_code sceNpMatchingKickRoomMember(u32 ctx_id, vm::cptr<SceNpRoomId> room_id, vm::cptr<SceNpId> user_id, vm::ptr<u32> req_id)
{
sceNp.todo("sceNpMatchingKickRoomMember(ctx_id=%d, room_id=*0x%x, user_id=*0x%x, req_id=*0x%x)", ctx_id, room_id, user_id, req_id);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (nph.is_NP2_Match2_init)
return SCE_NP_MATCHING_ERROR_UTILITY_UNAVAILABLE;
if (!nph.is_NP_init)
return SCE_NP_MATCHING_ERROR_NOT_INITIALIZED;
if (!room_id || !user_id || !req_id)
return SCE_NP_MATCHING_ERROR_INVALID_ARG;
if (false) // TODO
return SCE_NP_MATCHING_ERROR_BUSY;
if (false) // TODO
return SCE_NP_MATCHING_ERROR_CTX_NOT_FOUND;
return CELL_OK;
}
error_code sceNpMatchingKickRoomMemberWithOpt(u32 ctx_id, vm::cptr<SceNpRoomId> room_id, vm::cptr<SceNpId> user_id, vm::cptr<void> opt, s32 opt_len, vm::ptr<u32> req_id)
{
sceNp.todo("sceNpMatchingKickRoomMemberWithOpt(ctx_id=%d, room_id=*0x%x, user_id=*0x%x, opt=*0x%x, opt_len=%d, req_id=*0x%x)", ctx_id, room_id, user_id, opt, opt_len, req_id);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (nph.is_NP2_Match2_init)
return SCE_NP_MATCHING_ERROR_UTILITY_UNAVAILABLE;
if (!nph.is_NP_init)
return SCE_NP_MATCHING_ERROR_NOT_INITIALIZED;
if (!room_id || !user_id || !req_id)
return SCE_NP_MATCHING_ERROR_INVALID_ARG;
if (opt && (opt_len < 0 || opt_len > 16))
return SCE_NP_MATCHING_ERROR_INVALID_ARG;
if (false) // TODO
return SCE_NP_MATCHING_ERROR_BUSY;
if (false) // TODO
return SCE_NP_MATCHING_ERROR_CTX_NOT_FOUND;
return CELL_OK;
}
error_code sceNpMatchingQuickMatchGUI(u32 ctx_id, vm::cptr<SceNpCommunicationId> communicationId, vm::cptr<SceNpMatchingSearchCondition> cond, s32 available_num, s32 timeout,
vm::ptr<SceNpMatchingGUIHandler> handler, vm::ptr<void> arg)
{
sceNp.warning("sceNpMatchingQuickMatchGUI(ctx_id=%d, communicationId=*0x%x, cond=*0x%x, available_num=%d, timeout=%d, handler=*0x%x, arg=*0x%x)", ctx_id, communicationId, cond, available_num, timeout,
handler, arg);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (nph.is_NP2_Match2_init)
return SCE_NP_MATCHING_ERROR_UTILITY_UNAVAILABLE;
if (!communicationId || !handler || available_num < 2 || timeout < 1)
return SCE_NP_MATCHING_ERROR_INVALID_ARG;
u32 total_count = 0;
constexpr u32 max_count = 9;
for (auto con = cond; !!con; con = con->next)
{
if (++total_count > max_count)
return SCE_NP_MATCHING_ERROR_COND_MAX;
if (con->comp_op < SCE_NP_MATCHING_CONDITION_SEARCH_EQ ||
con->comp_op > SCE_NP_MATCHING_CONDITION_SEARCH_NE)
return SCE_NP_MATCHING_ERROR_INVALID_COMP_OP;
if (con->comp_type == 1) // weird, should be != SCE_NP_MATCHING_CONDITION_TYPE_VALUE
return SCE_NP_MATCHING_ERROR_INVALID_COMP_TYPE;
switch (con->target_attr_type)
{
case SCE_NP_MATCHING_ATTR_TYPE_BASIC_BIN:
case SCE_NP_MATCHING_ATTR_TYPE_BASIC_NUM:
case SCE_NP_MATCHING_ATTR_TYPE_GAME_BIN:
{
return SCE_NP_MATCHING_ERROR_INVALID_COND;
}
case SCE_NP_MATCHING_ATTR_TYPE_GAME_NUM:
{
if (con->target_attr_id < 1 || con->target_attr_id > 8)
return SCE_NP_MATCHING_ERROR_INVALID_COND;
break;
}
default:
break;
}
}
return nph.quickmatch_gui(ctx_id, communicationId, cond, available_num, timeout, handler, arg);
}
error_code sceNpMatchingSendInvitationGUI(u32 ctx_id, vm::cptr<SceNpRoomId> room_id, vm::cptr<SceNpCommunicationId> communicationId, vm::cptr<SceNpId> dsts, s32 num, s32 slot_type,
vm::cptr<char> subject, vm::cptr<char> body, sys_memory_container_t container, vm::ptr<SceNpMatchingGUIHandler> handler, vm::ptr<void> arg)
{
sceNp.todo("sceNpMatchingSendInvitationGUI(ctx_id=%d, room_id=*0x%x, communicationId=*0x%x, dsts=*0x%x, num=%d, slot_type=%d, subject=%s, body=%s, container=%d, handler=*0x%x, arg=*0x%x)", ctx_id,
room_id, communicationId, dsts, num, slot_type, subject, body, container, handler, arg);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (nph.is_NP2_Match2_init)
return SCE_NP_MATCHING_ERROR_UTILITY_UNAVAILABLE;
if (!room_id || !communicationId || !subject || !body) // TODO: || (in_stack_0000007c != 0)
return SCE_NP_MATCHING_ERROR_INVALID_ARG;
if (dsts && (num <= 0 || num > SCE_NP_MATCHING_INVITATION_DESTINATION_MAX))
return SCE_NP_MATCHING_ERROR_INVALID_ARG;
error_code err = check_text(subject);
if (err < 0)
return err;
if (err > 16)
return SCE_NP_MATCHING_ERROR_INVALID_ARG;
err = check_text(body);
if (err < 0)
return err;
if (err > 128)
return SCE_NP_MATCHING_ERROR_INVALID_ARG;
if (slot_type < SCE_NP_MATCHING_ROOM_SLOT_TYPE_PUBLIC || slot_type > SCE_NP_MATCHING_ROOM_SLOT_TYPE_PRIVATE)
return SCE_NP_MATCHING_ERROR_INVALID_ARG;
if (false) // TODO
return SCE_NP_MATCHING_ERROR_BUSY;
// TODO: set callback: handler + arg
err = CELL_OK; // SendInvitation
if (err != CELL_OK && static_cast<u32>(err) != SCE_NP_MATCHING_ERROR_BUSY)
{
// TODO ?
}
return err;
}
error_code sceNpMatchingAcceptInvitationGUI(u32 ctx_id, vm::cptr<SceNpCommunicationId> communicationId, sys_memory_container_t container, vm::ptr<SceNpMatchingGUIHandler> handler, vm::ptr<void> arg)
{
sceNp.todo("sceNpMatchingAcceptInvitationGUI(ctx_id=%d, communicationId=*0x%x, container=%d, handler=*0x%x, arg=*0x%x)", ctx_id, communicationId, container, handler, arg);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (nph.is_NP2_Match2_init)
return SCE_NP_MATCHING_ERROR_UTILITY_UNAVAILABLE;
if (!communicationId || !handler)
return SCE_NP_MATCHING_ERROR_INVALID_ARG;
if (false) // TODO
return SCE_NP_MATCHING_ERROR_BUSY;
// TODO: set callback: handler + arg
error_code err = CELL_OK; // AcceptInvitation
if (err != CELL_OK && static_cast<u32>(err) != SCE_NP_MATCHING_ERROR_BUSY)
{
// TODO ?
}
return err;
}
// FUN_00014d90
error_code check_attr_create_room(vm::cptr<SceNpMatchingAttr> attribute)
{
for (auto attr = attribute; !!attr; attr = attr->next)
{
error_code err = check_attr_id(attr);
if (err != CELL_OK)
return err;
if (attr->type == SCE_NP_MATCHING_ATTR_TYPE_BASIC_NUM)
{
if (attr->id >= SCE_NP_MATCHING_ROOM_ATTR_ID_CUR_TOTAL_NUM &&
attr->id <= SCE_NP_MATCHING_ROOM_ATTR_ID_CUR_PRIVATE_NUM)
return SCE_NP_MATCHING_ERROR_INVALID_ATTR_ID;
if (attr->value.num > 1 &&
(attr->id == SCE_NP_MATCHING_ROOM_ATTR_ID_PRIVILEGE_TYPE ||
attr->id == SCE_NP_MATCHING_ROOM_ATTR_ID_ROOM_SEARCH_FLAG))
return SCE_NP_MATCHING_ERROR_INVALID_ATTR_VALUE;
}
else if (attr->type == SCE_NP_MATCHING_ATTR_TYPE_GAME_BIN)
{
const u32 max_size = attr->id < 3 ? 256 : 64;
if (attr->value.data.size > max_size)
return SCE_NP_MATCHING_ERROR_INVALID_ATTR;
}
}
error_code err = check_duplicate_attr(attribute);
if (err != CELL_OK)
return err;
bool found_total_slots = false;
bool found_private_slots = false;
u32 total_slots = 0;
u32 private_slots = 0;
for (auto attr = attribute; !!attr; attr = attr->next)
{
if (attr->type == SCE_NP_MATCHING_ATTR_TYPE_BASIC_NUM)
{
if (attr->id == SCE_NP_MATCHING_ROOM_ATTR_ID_TOTAL_SLOT)
{
total_slots = attr->value.num;
found_total_slots = true;
}
else if (attr->id == SCE_NP_MATCHING_ROOM_ATTR_ID_PRIVATE_SLOT)
{
private_slots = attr->value.num;
found_private_slots = true;
}
if (found_total_slots && found_private_slots)
{
if ((total_slots > 0 && total_slots <= 16) &&
static_cast<s32>(private_slots) >= 0 &&
static_cast<s32>(total_slots - private_slots) > 0)
{
return CELL_OK;
}
return SCE_NP_MATCHING_ERROR_INVALID_ARG;
}
}
}
return SCE_NP_MATCHING_ERROR_ATTR_NOT_SPECIFIED;
}
error_code matching_create_room(u32 ctx_id, vm::cptr<SceNpCommunicationId> communicationId, vm::cptr<SceNpMatchingAttr> attr, vm::ptr<SceNpMatchingGUIHandler> handler, vm::ptr<void> arg)
{
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (nph.is_NP2_Match2_init)
{
return SCE_NP_MATCHING_ERROR_UTILITY_UNAVAILABLE;
}
if (!communicationId || !handler)
return SCE_NP_MATCHING_ERROR_INVALID_ARG;
// This check is used in all sceNpMatchingCreateRoom functions
error_code err = check_attr_create_room(attr);
if (err != CELL_OK)
return err;
return nph.create_room_gui(ctx_id, communicationId, attr, handler, arg);
}
error_code sceNpMatchingCreateRoomGUI(u32 ctx_id, vm::cptr<SceNpCommunicationId> communicationId, vm::cptr<SceNpMatchingAttr> attr, vm::ptr<SceNpMatchingGUIHandler> handler, vm::ptr<void> arg)
{
sceNp.warning("sceNpMatchingCreateRoomGUI(ctx_id=%d, communicationId=*0x%x, attr=*0x%x, handler=*0x%x, arg=*0x%x)", ctx_id, communicationId, attr, handler, arg);
return matching_create_room(ctx_id, communicationId, attr, handler, arg);
}
error_code matching_join_room(u32 ctx_id, vm::ptr<SceNpRoomId> room_id, vm::ptr<SceNpMatchingGUIHandler> handler, vm::ptr<void> arg)
{
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (nph.is_NP2_Match2_init)
return SCE_NP_MATCHING_ERROR_UTILITY_UNAVAILABLE;
if (!room_id || !handler)
return SCE_NP_MATCHING_ERROR_INVALID_ARG;
return nph.join_room_gui(ctx_id, room_id, handler, arg);
}
error_code sceNpMatchingJoinRoomGUI(u32 ctx_id, vm::ptr<SceNpRoomId> room_id, vm::ptr<SceNpMatchingGUIHandler> handler, vm::ptr<void> arg)
{
sceNp.warning("sceNpMatchingJoinRoomGUI(ctx_id=%d, room_id=*0x%x, handler=*0x%x, arg=*0x%x)", ctx_id, room_id, handler, arg);
return matching_join_room(ctx_id, room_id, handler, arg);
}
error_code sceNpMatchingLeaveRoom(u32 ctx_id, vm::cptr<SceNpRoomId> room_id, vm::ptr<u32> req_id)
{
sceNp.warning("sceNpMatchingLeaveRoom(ctx_id=%d, room_id=*0x%x, req_id=*0x%x)", ctx_id, room_id, req_id);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (nph.is_NP2_Match2_init)
return SCE_NP_MATCHING_ERROR_UTILITY_UNAVAILABLE;
if (!nph.is_NP_init)
return SCE_NP_MATCHING_ERROR_NOT_INITIALIZED;
auto res = nph.leave_room_gui(ctx_id, room_id);
if (res < 0)
return res;
*req_id = res;
return CELL_OK;
}
error_code sceNpMatchingSearchJoinRoomGUI(u32 ctx_id, vm::cptr<SceNpCommunicationId> communicationId, vm::cptr<SceNpMatchingSearchCondition> cond, vm::cptr<SceNpMatchingAttr> attr,
vm::ptr<SceNpMatchingGUIHandler> handler, vm::ptr<void> arg)
{
sceNp.warning("sceNpMatchingSearchJoinRoomGUI(ctx_id=%d, communicationId=*0x%x, cond=*0x%x, attr=*0x%x, handler=*0x%x, arg=*0x%x)", ctx_id, communicationId, cond, attr, handler, arg);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (nph.is_NP2_Match2_init)
return SCE_NP_MATCHING_ERROR_UTILITY_UNAVAILABLE;
if (!communicationId || !handler)
return SCE_NP_MATCHING_ERROR_INVALID_ARG;
u32 total_count = 0;
u32 inequality_count = 0;
constexpr u32 max_count = 9;
for (auto con = cond; !!con; con = con->next)
{
if (++total_count > max_count)
return SCE_NP_MATCHING_ERROR_COND_MAX;
if (con->comp_type != SCE_NP_MATCHING_CONDITION_TYPE_VALUE ||
con->comp_op < SCE_NP_MATCHING_CONDITION_SEARCH_EQ ||
con->comp_op > SCE_NP_MATCHING_CONDITION_SEARCH_GE)
return SCE_NP_MATCHING_ERROR_INVALID_COND;
if (con->comp_op > SCE_NP_MATCHING_CONDITION_SEARCH_NE &&
++inequality_count > max_count)
return SCE_NP_MATCHING_ERROR_COMP_OP_INEQUALITY_MAX;
switch (con->target_attr_type)
{
case SCE_NP_MATCHING_ATTR_TYPE_BASIC_BIN:
case SCE_NP_MATCHING_ATTR_TYPE_GAME_BIN:
{
return SCE_NP_MATCHING_ERROR_INVALID_COND;
}
case SCE_NP_MATCHING_ATTR_TYPE_BASIC_NUM:
{
if (con->target_attr_id != SCE_NP_MATCHING_ROOM_ATTR_ID_TOTAL_SLOT)
return SCE_NP_MATCHING_ERROR_INVALID_COND;
break;
}
case SCE_NP_MATCHING_ATTR_TYPE_GAME_NUM:
{
if (con->target_attr_id < 1 || con->target_attr_id > 8)
return SCE_NP_MATCHING_ERROR_INVALID_COND;
break;
}
default:
break;
}
}
error_code err = check_attr_id_and_duplicate(attr);
if (err != CELL_OK)
return err;
return nph.searchjoin_gui(ctx_id, communicationId, cond, attr, handler, arg);
}
error_code sceNpMatchingGrantOwnership(u32 ctx_id, vm::cptr<SceNpRoomId> room_id, vm::cptr<SceNpId> user_id, vm::ptr<u32> req_id)
{
sceNp.todo("sceNpMatchingGrantOwnership(ctx_id=%d, room_id=*0x%x, user_id=*0x%x, req_id=*0x%x)", ctx_id, room_id, user_id, req_id);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (nph.is_NP2_Match2_init)
return SCE_NP_MATCHING_ERROR_UTILITY_UNAVAILABLE;
if (!nph.is_NP_init)
return SCE_NP_MATCHING_ERROR_NOT_INITIALIZED;
if (!room_id || !user_id || !req_id)
return SCE_NP_MATCHING_ERROR_INVALID_ARG;
if (false) // TODO
return SCE_NP_MATCHING_ERROR_BUSY;
if (false) // TODO
return SCE_NP_MATCHING_ERROR_CTX_NOT_FOUND;
return CELL_OK;
}
error_code sceNpProfileCallGui(vm::cptr<SceNpId> npid, vm::ptr<SceNpProfileResultHandler> handler, vm::ptr<void> userArg, u64 options)
{
sceNp.todo("sceNpProfileCallGui(npid=*0x%x, handler=*0x%x, userArg=*0x%x, options=0x%x)", npid, handler, userArg, options);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_ERROR_NOT_INITIALIZED;
}
// TODO: SCE_NP_PROFILE_ERROR_BUSY
if (!handler)
{
return SCE_NP_PROFILE_ERROR_INVALID_ARGUMENT;
}
vm::var<SceNpId> id;
error_code err = sceNpManagerGetNpId(id);
if (err != CELL_OK)
return err;
return CELL_OK;
}
error_code sceNpProfileAbortGui()
{
sceNp.todo("sceNpProfileAbortGui()");
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_ERROR_NOT_INITIALIZED;
}
return CELL_OK;
}
error_code sceNpScoreInit()
{
sceNp.warning("sceNpScoreInit()");
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (nph.is_NP_Score_init)
{
return SCE_NP_COMMUNITY_ERROR_ALREADY_INITIALIZED;
}
if (!nph.is_NP_init)
{
return SCE_NP_ERROR_NOT_INITIALIZED;
}
nph.is_NP_Score_init = true;
return CELL_OK;
}
error_code sceNpScoreTerm()
{
sceNp.warning("sceNpScoreTerm()");
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Score_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (!nph.is_NP_init)
{
return SCE_NP_ERROR_NOT_INITIALIZED;
}
nph.is_NP_Score_init = false;
return CELL_OK;
}
error_code sceNpScoreCreateTitleCtx(vm::cptr<SceNpCommunicationId> communicationId, vm::cptr<SceNpCommunicationPassphrase> passphrase, vm::cptr<SceNpId> selfNpId)
{
sceNp.warning("sceNpScoreCreateTitleCtx(communicationId=*0x%x(%s), passphrase=*0x%x, selfNpId=*0x%x)", communicationId, communicationId ? np::communication_id_to_string(*communicationId).c_str() : "", passphrase, selfNpId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Score_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (!communicationId || !passphrase || !selfNpId)
{
return SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT;
}
s32 id = create_score_context(communicationId, passphrase);
if (id > 0)
{
return not_an_error(id);
}
return id;
}
error_code sceNpScoreDestroyTitleCtx(s32 titleCtxId)
{
sceNp.warning("sceNpScoreDestroyTitleCtx(titleCtxId=%d)", titleCtxId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Score_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (!destroy_score_context(titleCtxId))
return SCE_NP_COMMUNITY_ERROR_INVALID_ID;
return CELL_OK;
}
error_code sceNpScoreCreateTransactionCtx(s32 titleCtxId)
{
sceNp.warning("sceNpScoreCreateTransactionCtx(titleCtxId=%d)", titleCtxId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Score_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (nph.get_psn_status() == SCE_NP_MANAGER_STATUS_OFFLINE)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ONLINE_ID;
}
auto score = idm::get<score_ctx>(titleCtxId);
if (!score)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ID;
}
s32 id = create_score_transaction_context(score);
if (id > 0)
{
return not_an_error(id);
}
return id;
}
error_code sceNpScoreDestroyTransactionCtx(s32 transId)
{
sceNp.warning("sceNpScoreDestroyTransactionCtx(transId=%d)", transId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Score_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (!destroy_score_transaction_context(transId))
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ID;
}
return CELL_OK;
}
error_code sceNpScoreSetTimeout(s32 ctxId, usecond_t timeout)
{
sceNp.warning("sceNpScoreSetTimeout(ctxId=%d, timeout=%d)", ctxId, timeout);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Score_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (timeout < 10'000'000) // 10 seconds
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
const u32 idm_id = static_cast<u32>(ctxId);
if (idm_id >= score_transaction_ctx::id_base && idm_id < (score_transaction_ctx::id_base + score_transaction_ctx::id_count))
{
auto trans = idm::get<score_transaction_ctx>(ctxId);
if (!trans)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ID;
}
trans->timeout = timeout;
}
else if (idm_id >= score_ctx::id_base && idm_id < (score_ctx::id_base + score_ctx::id_count))
{
auto score = idm::get<score_ctx>(ctxId);
if (!ctxId)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ID;
}
score->timeout = timeout;
}
else
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ID;
}
return CELL_OK;
}
error_code sceNpScoreSetPlayerCharacterId(s32 ctxId, SceNpScorePcId pcId)
{
sceNp.warning("sceNpScoreSetPlayerCharacterId(ctxId=%d, pcId=%d)", ctxId, pcId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (pcId < 0)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
if (!nph.is_NP_Score_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (static_cast<u32>(ctxId) >= score_transaction_ctx::id_base)
{
auto trans = idm::get<score_transaction_ctx>(ctxId);
if (!trans)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ID;
}
trans->pcId = pcId;
}
else
{
auto score = idm::get<score_ctx>(ctxId);
if (!ctxId)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ID;
}
score->pcId = pcId;
}
return CELL_OK;
}
error_code sceNpScoreWaitAsync(s32 transId, vm::ptr<s32> result)
{
sceNp.warning("sceNpScoreWaitAsync(transId=%d, result=*0x%x)", transId, result);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Score_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
auto trans = idm::get<score_transaction_ctx>(transId);
if (!trans)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ID;
}
*result = trans->wait_for_completion();
return CELL_OK;
}
error_code sceNpScorePollAsync(s32 transId, vm::ptr<s32> result)
{
sceNp.warning("sceNpScorePollAsync(transId=%d, result=*0x%x)", transId, result);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Score_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
auto trans = idm::get<score_transaction_ctx>(transId);
if (!trans)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ID;
}
auto res = trans->get_transaction_status();
if (!res)
{
return not_an_error(1);
}
*result = *res;
return CELL_OK;
}
std::pair<std::optional<error_code>, std::shared_ptr<score_transaction_ctx>> get_score_transaction_context(s32 transId, bool reset_transaction = true)
{
auto trans_ctx = idm::get<score_transaction_ctx>(transId);
if (!trans_ctx)
{
return {SCE_NP_COMMUNITY_ERROR_INVALID_ID, {}};
}
if (reset_transaction)
{
// Check for games reusing score transaction context
// Unsure about the actual behaviour, only one game does this afaik(Marvel vs Capcom Origins)
// For now we just clean the context and pretend it's a new one
std::lock_guard lock(trans_ctx->mutex);
if (trans_ctx->result)
{
if (trans_ctx->thread.joinable())
trans_ctx->thread.join();
trans_ctx->result = {};
trans_ctx->tdata = {};
}
}
return {{}, trans_ctx};
}
error_code scenp_score_get_board_info(s32 transId, SceNpScoreBoardId boardId, vm::ptr<SceNpScoreBoardInfo> boardInfo, vm::ptr<void> option, bool async)
{
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Score_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (!boardInfo)
{
return SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT;
}
if (option) // option check at least until fw 4.71
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ONLINE_ID;
}
auto [res, trans_ctx] = get_score_transaction_context(transId);
if (res)
return *res;
nph.get_board_infos(trans_ctx, boardId, boardInfo, async);
if (async)
{
return CELL_OK;
}
return *trans_ctx->result;
}
error_code sceNpScoreGetBoardInfo(s32 transId, SceNpScoreBoardId boardId, vm::ptr<SceNpScoreBoardInfo> boardInfo, vm::ptr<void> option)
{
sceNp.warning("sceNpScoreGetBoardInfo(transId=%d, boardId=%d, boardInfo=*0x%x, option=*0x%x)", transId, boardId, boardInfo, option);
return scenp_score_get_board_info(transId, boardId, boardInfo, option, false);
}
error_code sceNpScoreGetBoardInfoAsync(s32 transId, SceNpScoreBoardId boardId, vm::ptr<SceNpScoreBoardInfo> boardInfo, s32 prio, vm::ptr<void> option)
{
sceNp.warning("sceNpScoreGetBoardInfo(transId=%d, boardId=%d, boardInfo=*0x%x, prio=%d, option=*0x%x)", transId, boardId, boardInfo, prio, option);
return scenp_score_get_board_info(transId, boardId, boardInfo, option, true);
}
error_code scenp_score_record_score(s32 transId, SceNpScoreBoardId boardId, SceNpScoreValue score, vm::cptr<SceNpScoreComment> scoreComment, vm::cptr<SceNpScoreGameInfo> gameInfo,
vm::ptr<SceNpScoreRankNumber> tmpRank, vm::ptr<SceNpScoreRecordOptParam> option, bool async)
{
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Score_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ONLINE_ID;
}
auto [res, trans_ctx] = get_score_transaction_context(transId);
if (res)
return *res;
const u8* data = nullptr;
u32 data_size = 0;
if (!gameInfo)
{
if (option && option->vsInfo)
{
if (option->size != 0xCu)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ALIGNMENT;
}
if (option->reserved)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
data = &option->vsInfo->data[0];
data_size = option->vsInfo->infoSize;
}
}
else
{
data = &gameInfo->nativeData[0];
data_size = 64;
}
nph.record_score(trans_ctx, boardId, score, scoreComment, data, data_size, tmpRank, async);
if (async)
{
return CELL_OK;
}
return *trans_ctx->result;
}
error_code sceNpScoreRecordScore(s32 transId, SceNpScoreBoardId boardId, SceNpScoreValue score, vm::cptr<SceNpScoreComment> scoreComment, vm::cptr<SceNpScoreGameInfo> gameInfo,
vm::ptr<SceNpScoreRankNumber> tmpRank, vm::ptr<SceNpScoreRecordOptParam> option)
{
sceNp.warning("sceNpScoreRecordScore(transId=%d, boardId=%d, score=%d, scoreComment=*0x%x, gameInfo=*0x%x, tmpRank=*0x%x, option=*0x%x)", transId, boardId, score, scoreComment, gameInfo, tmpRank, option);
return scenp_score_record_score(transId, boardId, score, scoreComment, gameInfo, tmpRank, option, false);
}
error_code sceNpScoreRecordScoreAsync(s32 transId, SceNpScoreBoardId boardId, SceNpScoreValue score, vm::cptr<SceNpScoreComment> scoreComment, vm::cptr<SceNpScoreGameInfo> gameInfo,
vm::ptr<SceNpScoreRankNumber> tmpRank, s32 prio, vm::ptr<SceNpScoreRecordOptParam> option)
{
sceNp.warning("sceNpScoreRecordScoreAsync(transId=%d, boardId=%d, score=%d, scoreComment=*0x%x, gameInfo=*0x%x, tmpRank=*0x%x, prio=%d, option=*0x%x)", transId, boardId, score, scoreComment, gameInfo,
tmpRank, prio, option);
return scenp_score_record_score(transId, boardId, score, scoreComment, gameInfo, tmpRank, option, true);
}
error_code scenp_score_record_game_data(s32 transId, SceNpScoreBoardId boardId, SceNpScoreValue score, u32 totalSize, u32 sendSize, vm::cptr<void> data, vm::ptr<void> /* option */, bool async)
{
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Score_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (!data)
{
return SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT;
}
auto [res, trans_ctx] = get_score_transaction_context(transId, false);
if (res)
return *res;
if (!nph.is_NP_init)
{
return SCE_NP_ERROR_NOT_INITIALIZED;
}
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ONLINE_ID;
}
nph.record_score_data(trans_ctx, boardId, score, totalSize, sendSize, static_cast<const u8*>(data.get_ptr()), async);
if (async)
{
return CELL_OK;
}
return *trans_ctx->result;
}
error_code sceNpScoreRecordGameData(s32 transId, SceNpScoreBoardId boardId, SceNpScoreValue score, u32 totalSize, u32 sendSize, vm::cptr<void> data, vm::ptr<void> option)
{
sceNp.warning("sceNpScoreRecordGameData(transId=%d, boardId=%d, score=%d, totalSize=%d, sendSize=%d, data=*0x%x, option=*0x%x)", transId, boardId, score, totalSize, sendSize, data, option);
return scenp_score_record_game_data(transId, boardId, score, totalSize, sendSize, data, option, false);
}
error_code sceNpScoreRecordGameDataAsync(s32 transId, SceNpScoreBoardId boardId, SceNpScoreValue score, u32 totalSize, u32 sendSize, vm::cptr<void> data, s32 prio, vm::ptr<void> option)
{
sceNp.warning("sceNpScoreRecordGameDataAsync(transId=%d, boardId=%d, score=%d, totalSize=%d, sendSize=%d, data=*0x%x, prio=%d, option=*0x%x)", transId, boardId, score, totalSize, sendSize, data, prio, option);
return scenp_score_record_game_data(transId, boardId, score, totalSize, sendSize, data, option, true);
}
error_code scenp_score_get_game_data(s32 transId, SceNpScoreBoardId boardId, vm::cptr<SceNpId> npId, vm::ptr<u32> totalSize, u32 recvSize, vm::ptr<void> data, vm::ptr<void> /* option */, bool async)
{
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Score_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (!npId || !data)
{
return SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT;
}
auto [res, trans_ctx] = get_score_transaction_context(transId, false);
if (res)
return *res;
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ONLINE_ID;
}
nph.get_score_data(trans_ctx, boardId, *npId, totalSize, recvSize, data, async);
if (async)
{
return CELL_OK;
}
return *trans_ctx->result;
}
error_code sceNpScoreGetGameData(s32 transId, SceNpScoreBoardId boardId, vm::cptr<SceNpId> npId, vm::ptr<u32> totalSize, u32 recvSize, vm::ptr<void> data, vm::ptr<void> option)
{
sceNp.warning("sceNpScoreGetGameData(transId=%d, boardId=%d, npId=*0x%x, totalSize=*0x%x, recvSize=%d, data=*0x%x, option=*0x%x)", transId, boardId, npId, totalSize, recvSize, data, option);
return scenp_score_get_game_data(transId, boardId, npId, totalSize, recvSize, data, option, false);
}
error_code sceNpScoreGetGameDataAsync(s32 transId, SceNpScoreBoardId boardId, vm::cptr<SceNpId> npId, vm::ptr<u32> totalSize, u32 recvSize, vm::ptr<void> data, s32 prio, vm::ptr<void> option)
{
sceNp.warning("sceNpScoreGetGameDataAsync(transId=%d, boardId=%d, npId=*0x%x, totalSize=*0x%x, recvSize=%d, data=*0x%x, prio=%d, option=*0x%x)", transId, boardId, npId, totalSize, recvSize, data, prio,
option);
return scenp_score_get_game_data(transId, boardId, npId, totalSize, recvSize, data, option, true);
}
template <typename T>
error_code scenp_score_get_ranking_by_npid(s32 transId, SceNpScoreBoardId boardId, T npIdArray, u32 npIdArraySize, vm::ptr<SceNpScorePlayerRankData> rankArray, u32 rankArraySize,
vm::ptr<SceNpScoreComment> commentArray, u32 commentArraySize, vm::ptr<void> infoArray, u32 infoArraySize, u32 arrayNum, vm::ptr<CellRtcTick> lastSortDate,
vm::ptr<SceNpScoreRankNumber> totalRecord, vm::ptr<void> /* option */, bool async)
{
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Score_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (!npIdArray)
{
return SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT;
}
if (!arrayNum)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
if (arrayNum > SCE_NP_SCORE_MAX_NPID_NUM_PER_TRANS)
{
return SCE_NP_COMMUNITY_ERROR_TOO_MANY_NPID;
}
auto [res, trans_ctx] = get_score_transaction_context(transId);
if (res)
return *res;
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ONLINE_ID;
}
if (commentArray && commentArraySize != (arrayNum * sizeof(SceNpScoreComment)))
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ALIGNMENT;
}
if (infoArray && infoArraySize != (arrayNum * sizeof(SceNpScoreGameInfo)) && infoArraySize != (arrayNum * sizeof(SceNpScoreVariableSizeGameInfo)))
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ALIGNMENT;
}
// SceNpScorePlayerRankData changed with 180.002
const bool deprecated = (rankArraySize == (arrayNum * sizeof(SceNpScorePlayerRankData_deprecated)));
if (rankArraySize != (arrayNum * sizeof(SceNpScorePlayerRankData)) && !deprecated)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ALIGNMENT;
}
std::vector<std::pair<SceNpId, s32>> npid_vec;
static constexpr bool is_npid = std::is_same_v<T, vm::cptr<SceNpId>>;
static constexpr bool is_npidpcid = std::is_same_v<T, vm::cptr<SceNpScoreNpIdPcId>>;
static_assert(is_npid || is_npidpcid, "T should be vm::cptr<SceNpId> or vm::cptr<SceNpScoreNpIdPcId>");
if constexpr (is_npid)
{
if (npIdArraySize != (arrayNum * sizeof(SceNpId)))
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ALIGNMENT;
}
for (u32 index = 0; index < arrayNum; index++)
{
npid_vec.push_back(std::make_pair(npIdArray[index], 0));
}
}
else if constexpr (is_npidpcid)
{
if (npIdArraySize != (arrayNum * sizeof(SceNpScoreNpIdPcId)))
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ALIGNMENT;
}
for (u32 index = 0; index < arrayNum; index++)
{
npid_vec.push_back(std::make_pair(npIdArray[index].npId, npIdArray[index].pcId));
}
}
nph.get_score_npid(trans_ctx, boardId, npid_vec, rankArray, rankArraySize, commentArray, commentArraySize, infoArray, infoArraySize, arrayNum, lastSortDate, totalRecord, async, deprecated);
if (async)
{
return CELL_OK;
}
return *trans_ctx->result;
}
error_code sceNpScoreGetRankingByNpId(s32 transId, SceNpScoreBoardId boardId, vm::cptr<SceNpId> npIdArray, u32 npIdArraySize, vm::ptr<SceNpScorePlayerRankData> rankArray, u32 rankArraySize,
vm::ptr<SceNpScoreComment> commentArray, u32 commentArraySize, vm::ptr<void> infoArray, u32 infoArraySize, u32 arrayNum, vm::ptr<CellRtcTick> lastSortDate,
vm::ptr<SceNpScoreRankNumber> totalRecord, vm::ptr<void> option)
{
sceNp.warning("sceNpScoreGetRankingByNpId(transId=%d, boardId=%d, npIdArray=*0x%x, npIdArraySize=%d, rankArray=*0x%x, rankArraySize=%d, commentArray=*0x%x, commentArraySize=%d, infoArray=*0x%x, "
"infoArraySize=%d, arrayNum=%d, lastSortDate=*0x%x, totalRecord=*0x%x, option=*0x%x)",
transId, boardId, npIdArray, npIdArraySize, rankArray, rankArraySize, commentArray, commentArraySize, infoArray, infoArraySize, arrayNum, lastSortDate, totalRecord, option);
return scenp_score_get_ranking_by_npid(transId, boardId, npIdArray, npIdArraySize, rankArray, rankArraySize, commentArray, commentArraySize, infoArray,
infoArraySize, arrayNum, lastSortDate, totalRecord, option, false);
}
error_code sceNpScoreGetRankingByNpIdAsync(s32 transId, SceNpScoreBoardId boardId, vm::cptr<SceNpId> npIdArray, u32 npIdArraySize, vm::ptr<SceNpScorePlayerRankData> rankArray, u32 rankArraySize,
vm::ptr<SceNpScoreComment> commentArray, u32 commentArraySize, vm::ptr<void> infoArray, u32 infoArraySize, u32 arrayNum, vm::ptr<CellRtcTick> lastSortDate,
vm::ptr<SceNpScoreRankNumber> totalRecord, s32 prio, vm::ptr<void> option)
{
sceNp.warning("sceNpScoreGetRankingByNpIdAsync(transId=%d, boardId=%d, npIdArray=*0x%x, npIdArraySize=%d, rankArray=*0x%x, rankArraySize=%d, commentArray=*0x%x, commentArraySize=%d, infoArray=*0x%x, "
"infoArraySize=%d, arrayNum=%d, lastSortDate=*0x%x, totalRecord=*0x%x, prio=%d, option=*0x%x)",
transId, boardId, npIdArray, npIdArraySize, rankArray, rankArraySize, commentArray, commentArraySize, infoArray, infoArraySize, arrayNum, lastSortDate, totalRecord, prio, option);
return scenp_score_get_ranking_by_npid(transId, boardId, npIdArray, npIdArraySize, rankArray, rankArraySize, commentArray, commentArraySize, infoArray,
infoArraySize, arrayNum, lastSortDate, totalRecord, option, true);
}
error_code scenp_score_get_ranking_by_range(s32 transId, SceNpScoreBoardId boardId, SceNpScoreRankNumber startSerialRank, vm::ptr<SceNpScoreRankData> rankArray, u32 rankArraySize,
vm::ptr<SceNpScoreComment> commentArray, u32 commentArraySize, vm::ptr<void> infoArray, u32 infoArraySize, u32 arrayNum, vm::ptr<CellRtcTick> lastSortDate,
vm::ptr<SceNpScoreRankNumber> totalRecord, vm::ptr<void> option, bool async)
{
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Score_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
auto [res, trans_ctx] = get_score_transaction_context(transId);
if (res)
return *res;
if (option)
{
vm::ptr<u32> opt_ptr = vm::static_ptr_cast<u32>(option);
if (opt_ptr[0] != 0xCu)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
if (opt_ptr[1])
{
vm::ptr<u32> ssr_ptr = vm::cast(opt_ptr[1]);
startSerialRank = *ssr_ptr;
}
// It also uses opt_ptr[2] for unknown purposes
}
if (!startSerialRank)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
if (!rankArray || !totalRecord || !lastSortDate)
{
return SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT;
}
if (arrayNum > SCE_NP_SCORE_MAX_RANGE_NUM_PER_TRANS)
{
return SCE_NP_COMMUNITY_ERROR_TOO_LARGE_RANGE;
}
if (commentArray && commentArraySize != (arrayNum * sizeof(SceNpScoreComment)))
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ALIGNMENT;
}
if (infoArray && infoArraySize != (arrayNum * sizeof(SceNpScoreGameInfo)) && infoArraySize != (arrayNum * sizeof(SceNpScoreVariableSizeGameInfo)))
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ALIGNMENT;
}
// SceNpScoreRankData changed with 180.002
const bool deprecated = (rankArraySize == (arrayNum * sizeof(SceNpScoreRankData_deprecated)));
if (rankArraySize != (arrayNum * sizeof(SceNpScoreRankData)) && !deprecated)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ALIGNMENT;
}
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ONLINE_ID;
}
nph.get_score_range(trans_ctx, boardId, startSerialRank, rankArray, rankArraySize, commentArray, commentArraySize, infoArray, infoArraySize, arrayNum, lastSortDate, totalRecord, async, deprecated);
if (async)
{
return CELL_OK;
}
return *trans_ctx->result;
}
error_code sceNpScoreGetRankingByRange(s32 transId, SceNpScoreBoardId boardId, SceNpScoreRankNumber startSerialRank, vm::ptr<SceNpScoreRankData> rankArray, u32 rankArraySize,
vm::ptr<SceNpScoreComment> commentArray, u32 commentArraySize, vm::ptr<void> infoArray, u32 infoArraySize, u32 arrayNum, vm::ptr<CellRtcTick> lastSortDate,
vm::ptr<SceNpScoreRankNumber> totalRecord, vm::ptr<void> option)
{
sceNp.warning("sceNpScoreGetRankingByRange(transId=%d, boardId=%d, startSerialRank=%d, rankArray=*0x%x, rankArraySize=%d, commentArray=*0x%x, commentArraySize=%d, infoArray=*0x%x, infoArraySize=%d, "
"arrayNum=%d, lastSortDate=*0x%x, totalRecord=*0x%x, option=*0x%x)",
transId, boardId, startSerialRank, rankArray, rankArraySize, commentArray, commentArraySize, infoArray, infoArraySize, arrayNum, lastSortDate, totalRecord, option);
return scenp_score_get_ranking_by_range(transId, boardId, startSerialRank, rankArray, rankArraySize, commentArray, commentArraySize, infoArray, infoArraySize,
arrayNum, lastSortDate, totalRecord, option, false);
}
error_code sceNpScoreGetRankingByRangeAsync(s32 transId, SceNpScoreBoardId boardId, SceNpScoreRankNumber startSerialRank, vm::ptr<SceNpScoreRankData> rankArray, u32 rankArraySize,
vm::ptr<SceNpScoreComment> commentArray, u32 commentArraySize, vm::ptr<void> infoArray, u32 infoArraySize, u32 arrayNum, vm::ptr<CellRtcTick> lastSortDate,
vm::ptr<SceNpScoreRankNumber> totalRecord, s32 prio, vm::ptr<void> option)
{
sceNp.warning("sceNpScoreGetRankingByRangeAsync(transId=%d, boardId=%d, startSerialRank=%d, rankArray=*0x%x, rankArraySize=%d, commentArray=*0x%x, commentArraySize=%d, infoArray=*0x%x, "
"infoArraySize=%d, arrayNum=%d, lastSortDate=*0x%x, totalRecord=*0x%x, prio=%d, option=*0x%x)",
transId, boardId, startSerialRank, rankArray, rankArraySize, commentArray, commentArraySize, infoArray, infoArraySize, arrayNum, lastSortDate, totalRecord, prio, option);
return scenp_score_get_ranking_by_range(transId, boardId, startSerialRank, rankArray, rankArraySize, commentArray, commentArraySize, infoArray, infoArraySize,
arrayNum, lastSortDate, totalRecord, option, true);
}
error_code scenp_score_get_friends_ranking(s32 transId, SceNpScoreBoardId boardId, s32 includeSelf, vm::ptr<SceNpScoreRankData> rankArray, u32 rankArraySize, vm::ptr<SceNpScoreComment> commentArray,
u32 commentArraySize, vm::ptr<SceNpScoreGameInfo> infoArray, u32 infoArraySize, u32 arrayNum, vm::ptr<CellRtcTick> lastSortDate, vm::ptr<SceNpScoreRankNumber> totalRecord, vm::ptr<void> option,
bool async)
{
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Score_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
auto [res, trans_ctx] = get_score_transaction_context(transId);
if (res)
return *res;
if (!rankArray || !totalRecord || !lastSortDate)
{
return SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT;
}
if (arrayNum > SCE_NP_SCORE_MAX_SELECTED_FRIENDS_NUM || option) // option check at least until fw 4.71
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
if (commentArray && commentArraySize != (arrayNum * sizeof(SceNpScoreComment)))
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ALIGNMENT;
}
if (infoArray && infoArraySize != (arrayNum * sizeof(SceNpScoreGameInfo)) && infoArraySize != (arrayNum * sizeof(SceNpScoreVariableSizeGameInfo)))
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ALIGNMENT;
}
// The SceNpScoreRankData changed with 180.002
const bool deprecated = (rankArraySize == (arrayNum * sizeof(SceNpScoreRankData_deprecated)));
if (rankArraySize != (arrayNum * sizeof(SceNpScoreRankData)) && !deprecated)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ALIGNMENT;
}
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ONLINE_ID;
}
nph.get_score_friend(trans_ctx, boardId, includeSelf, rankArray, rankArraySize, commentArray, commentArraySize, infoArray, infoArraySize, arrayNum, lastSortDate, totalRecord, async, deprecated);
if (async)
{
return CELL_OK;
}
return *trans_ctx->result;
}
error_code sceNpScoreGetFriendsRanking(s32 transId, SceNpScoreBoardId boardId, s32 includeSelf, vm::ptr<SceNpScoreRankData> rankArray, u32 rankArraySize, vm::ptr<SceNpScoreComment> commentArray,
u32 commentArraySize, vm::ptr<SceNpScoreGameInfo> infoArray, u32 infoArraySize, u32 arrayNum, vm::ptr<CellRtcTick> lastSortDate, vm::ptr<SceNpScoreRankNumber> totalRecord, vm::ptr<void> option)
{
sceNp.warning("sceNpScoreGetFriendsRanking(transId=%d, boardId=%d, includeSelf=%d, rankArray=*0x%x, rankArraySize=%d, commentArray=*0x%x, commentArraySize=%d, infoArray=*0x%x, infoArraySize=%d, "
"arrayNum=%d, lastSortDate=*0x%x, totalRecord=*0x%x, option=*0x%x)",
transId, boardId, includeSelf, rankArray, rankArraySize, commentArray, commentArraySize, infoArray, infoArraySize, arrayNum, lastSortDate, totalRecord, option);
return scenp_score_get_friends_ranking(transId, boardId, includeSelf, rankArray, rankArraySize, commentArray, commentArraySize, infoArray, infoArraySize,
arrayNum, lastSortDate, totalRecord, option, false);
}
error_code sceNpScoreGetFriendsRankingAsync(s32 transId, SceNpScoreBoardId boardId, s32 includeSelf, vm::ptr<SceNpScoreRankData> rankArray, u32 rankArraySize, vm::ptr<SceNpScoreComment> commentArray,
u32 commentArraySize, vm::ptr<SceNpScoreGameInfo> infoArray, u32 infoArraySize, u32 arrayNum, vm::ptr<CellRtcTick> lastSortDate, vm::ptr<SceNpScoreRankNumber> totalRecord, s32 prio,
vm::ptr<void> option)
{
sceNp.warning("sceNpScoreGetFriendsRankingAsync(transId=%d, boardId=%d, includeSelf=%d, rankArray=*0x%x, rankArraySize=%d, commentArray=*0x%x, commentArraySize=%d, infoArray=*0x%x, infoArraySize=%d, "
"arrayNum=%d, lastSortDate=*0x%x, totalRecord=*0x%x, prio=%d, option=*0x%x)",
transId, boardId, includeSelf, rankArray, rankArraySize, commentArray, commentArraySize, infoArray, infoArraySize, arrayNum, lastSortDate, totalRecord, prio, option);
return scenp_score_get_friends_ranking(transId, boardId, includeSelf, rankArray, rankArraySize, commentArray, commentArraySize, infoArray, infoArraySize,
arrayNum, lastSortDate, totalRecord, option, true);
}
error_code scenp_score_censor_comment(s32 transId, vm::cptr<char> comment, vm::ptr<void> option, bool async)
{
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Score_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (!comment)
{
return SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT;
}
if (strlen(comment.get_ptr()) > SCE_NP_SCORE_CENSOR_COMMENT_MAXLEN || option) // option check at least until fw 4.71
{
// TODO: is SCE_NP_SCORE_CENSOR_COMMENT_MAXLEN + 1 allowed ?
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ONLINE_ID;
}
auto [res, trans_ctx] = get_score_transaction_context(transId);
if (res)
return *res;
// TODO: actual implementation of this
trans_ctx->result = CELL_OK;
if (async)
{
return CELL_OK;
}
return *trans_ctx->result;
}
error_code sceNpScoreCensorComment(s32 transId, vm::cptr<char> comment, vm::ptr<void> option)
{
sceNp.todo("sceNpScoreCensorComment(transId=%d, comment=%s, option=*0x%x)", transId, comment, option);
return scenp_score_censor_comment(transId, comment, option, false);
}
error_code sceNpScoreCensorCommentAsync(s32 transId, vm::cptr<char> comment, s32 prio, vm::ptr<void> option)
{
sceNp.todo("sceNpScoreCensorCommentAsync(transId=%d, comment=%s, prio=%d, option=*0x%x)", transId, comment, prio, option);
return scenp_score_censor_comment(transId, comment, option, true);
}
error_code scenp_score_sanitize_comment(s32 transId, vm::cptr<char> comment, vm::ptr<char> sanitizedComment, vm::ptr<void> /* option */, bool async)
{
if (!sanitizedComment)
{
return SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT;
}
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Score_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (!comment)
{
return SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT;
}
const auto comment_len = strlen(comment.get_ptr());
if (comment_len > SCE_NP_SCORE_CENSOR_COMMENT_MAXLEN)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
auto [res, trans_ctx] = get_score_transaction_context(transId);
if (res)
return *res;
// TODO: actual implementation of this
memcpy(sanitizedComment.get_ptr(), comment.get_ptr(), comment_len + 1);
trans_ctx->result = CELL_OK;
if (async)
{
return CELL_OK;
}
return *trans_ctx->result;
}
error_code sceNpScoreSanitizeComment(s32 transId, vm::cptr<char> comment, vm::ptr<char> sanitizedComment, vm::ptr<void> option)
{
sceNp.warning("sceNpScoreSanitizeComment(transId=%d, comment=%s, sanitizedComment=*0x%x, option=*0x%x)", transId, comment, sanitizedComment, option);
return scenp_score_sanitize_comment(transId, comment, sanitizedComment, option, false);
}
error_code sceNpScoreSanitizeCommentAsync(s32 transId, vm::cptr<char> comment, vm::ptr<char> sanitizedComment, s32 prio, vm::ptr<void> option)
{
sceNp.warning("sceNpScoreSanitizeCommentAsync(transId=%d, comment=%s, sanitizedComment=*0x%x, prio=%d, option=*0x%x)", transId, comment, sanitizedComment, prio, option);
return scenp_score_sanitize_comment(transId, comment, sanitizedComment, option, true);
}
error_code sceNpScoreGetRankingByNpIdPcId(s32 transId, SceNpScoreBoardId boardId, vm::cptr<SceNpScoreNpIdPcId> idArray, u32 idArraySize, vm::ptr<SceNpScorePlayerRankData> rankArray, u32 rankArraySize,
vm::ptr<SceNpScoreComment> commentArray, u32 commentArraySize, vm::ptr<void> infoArray, u32 infoArraySize, u32 arrayNum, vm::ptr<CellRtcTick> lastSortDate,
vm::ptr<SceNpScoreRankNumber> totalRecord, vm::ptr<void> option)
{
sceNp.warning("sceNpScoreGetRankingByNpIdPcId(transId=%d, boardId=%d, idArray=*0x%x, idArraySize=%d, rankArray=*0x%x, rankArraySize=%d, commentArray=*0x%x, commentArraySize=%d, infoArray=*0x%x, "
"infoArraySize=%d, arrayNum=%d, lastSortDate=*0x%x, totalRecord=*0x%x, option=*0x%x)",
transId, boardId, idArray, idArraySize, rankArray, rankArraySize, commentArray, commentArraySize, infoArray, infoArraySize, arrayNum, lastSortDate, totalRecord, option);
return scenp_score_get_ranking_by_npid(transId, boardId, idArray, idArraySize, rankArray, rankArraySize, commentArray, commentArraySize, infoArray,
infoArraySize, arrayNum, lastSortDate, totalRecord, option, false);
}
error_code sceNpScoreGetRankingByNpIdPcIdAsync(s32 transId, SceNpScoreBoardId boardId, vm::cptr<SceNpScoreNpIdPcId> idArray, u32 idArraySize, vm::ptr<SceNpScorePlayerRankData> rankArray,
u32 rankArraySize, vm::ptr<SceNpScoreComment> commentArray, u32 commentArraySize, vm::ptr<void> infoArray, u32 infoArraySize, u32 arrayNum, vm::ptr<CellRtcTick> lastSortDate,
vm::ptr<SceNpScoreRankNumber> totalRecord, s32 prio, vm::ptr<void> option)
{
sceNp.warning("sceNpScoreGetRankingByNpIdPcIdAsync(transId=%d, boardId=%d, idArray=*0x%x, idArraySize=%d, rankArray=*0x%x, rankArraySize=%d, commentArray=*0x%x, commentArraySize=%d, infoArray=*0x%x, "
"infoArraySize=%d, arrayNum=%d, lastSortDate=*0x%x, totalRecord=*0x%x, prio=%d, option=*0x%x)",
transId, boardId, idArray, idArraySize, rankArray, rankArraySize, commentArray, commentArraySize, infoArray, infoArraySize, arrayNum, lastSortDate, totalRecord, prio, option);
return scenp_score_get_ranking_by_npid(transId, boardId, idArray, idArraySize, rankArray, rankArraySize, commentArray, commentArraySize, infoArray,
infoArraySize, arrayNum, lastSortDate, totalRecord, option, true);
}
error_code sceNpScoreAbortTransaction(s32 transId)
{
sceNp.warning("sceNpScoreAbortTransaction(transId=%d)", transId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Score_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
auto trans = idm::get<score_transaction_ctx>(transId);
if (!trans)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ID;
}
trans->abort_transaction();
return CELL_OK;
}
error_code sceNpScoreGetClansMembersRankingByNpId(s32 transId, SceNpClanId clanId, SceNpScoreBoardId boardId, vm::cptr<SceNpId> idArray, u32 idArraySize, vm::ptr<SceNpScorePlayerRankData> rankArray,
u32 rankArraySize, vm::ptr<SceNpScoreComment> commentArray, u32 commentArraySize, vm::ptr<SceNpScoreGameInfo> infoArray, u32 infoArraySize, vm::ptr<SceNpScoreClansMemberDescription> descriptArray,
u32 descriptArraySize, u32 arrayNum, vm::ptr<SceNpScoreClanBasicInfo> clanInfo, vm::ptr<CellRtcTick> lastSortDate, vm::ptr<SceNpScoreRankNumber> totalRecord, vm::ptr<void> option)
{
sceNp.todo("sceNpScoreGetClansMembersRankingByNpId(transId=%d, clanId=%d, boardId=%d, idArray=*0x%x, idArraySize=%d, rankArray=*0x%x, rankArraySize=%d, commentArray=*0x%x, commentArraySize=%d, "
"infoArray=*0x%x, infoArraySize=%d, descriptArray=*0x%x, descriptArraySize=%d, arrayNum=%d, clanInfo=*0x%x, lastSortDate=*0x%x, totalRecord=*0x%x, option=*0x%x)",
transId, clanId, boardId, idArray, idArraySize, rankArray, rankArraySize, commentArray, commentArraySize, infoArray, infoArraySize, descriptArray, descriptArraySize, arrayNum, clanInfo,
lastSortDate, totalRecord, option);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Score_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (!idArray || !rankArray || !totalRecord || !lastSortDate || !arrayNum)
{
return SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT;
}
if (option) // option check at least until fw 4.71
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
if (arrayNum > SCE_NP_SCORE_MAX_NPID_NUM_PER_TRANS)
{
return SCE_NP_COMMUNITY_ERROR_TOO_MANY_NPID;
}
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ONLINE_ID;
}
return CELL_OK;
}
error_code sceNpScoreGetClansMembersRankingByNpIdAsync(s32 transId, SceNpClanId clanId, SceNpScoreBoardId boardId, vm::cptr<SceNpId> idArray, u32 idArraySize,
vm::ptr<SceNpScorePlayerRankData> rankArray, u32 rankArraySize, vm::ptr<SceNpScoreComment> commentArray, u32 commentArraySize, vm::ptr<SceNpScoreGameInfo> infoArray, u32 infoArraySize,
vm::ptr<SceNpScoreClansMemberDescription> descriptArray, u32 descriptArraySize, u32 arrayNum, vm::ptr<SceNpScoreClanBasicInfo> clanInfo, vm::ptr<CellRtcTick> lastSortDate,
vm::ptr<SceNpScoreRankNumber> totalRecord, s32 prio, vm::ptr<void> option)
{
sceNp.todo("sceNpScoreGetClansMembersRankingByNpIdAsync(transId=%d, clanId=%d, boardId=%d, idArray=*0x%x, idArraySize=%d, rankArray=*0x%x, rankArraySize=%d, commentArray=*0x%x, commentArraySize=%d, "
"infoArray=*0x%x, infoArraySize=%d, descriptArray=*0x%x, descriptArraySize=%d, arrayNum=%d, clanInfo=*0x%x, lastSortDate=*0x%x, totalRecord=*0x%x, prio=%d, option=*0x%x)",
transId, clanId, boardId, idArray, idArraySize, rankArray, rankArraySize, commentArray, commentArraySize, infoArray, infoArraySize, descriptArray, descriptArraySize, arrayNum, clanInfo,
lastSortDate, totalRecord, prio, option);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Score_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (!idArray || !arrayNum)
{
return SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT;
}
if (option) // option check at least until fw 4.71
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
return CELL_OK;
}
error_code sceNpScoreGetClansMembersRankingByNpIdPcId(s32 transId, SceNpClanId clanId, SceNpScoreBoardId boardId, vm::cptr<SceNpId> idArray, u32 idArraySize,
vm::ptr<SceNpScorePlayerRankData> rankArray, u32 rankArraySize, vm::ptr<SceNpScoreComment> commentArray, u32 commentArraySize, vm::ptr<SceNpScoreGameInfo> infoArray, u32 infoArraySize,
vm::ptr<SceNpScoreClansMemberDescription> descriptArray, u32 descriptArraySize, u32 arrayNum, vm::ptr<SceNpScoreClanBasicInfo> clanInfo, vm::ptr<CellRtcTick> lastSortDate,
vm::ptr<SceNpScoreRankNumber> totalRecord, vm::ptr<void> option)
{
sceNp.todo("sceNpScoreGetClansMembersRankingByNpIdPcId(transId=%d, clanId=%d, boardId=%d, idArray=*0x%x, idArraySize=%d, rankArray=*0x%x, rankArraySize=%d, commentArray=*0x%x, commentArraySize=%d, "
"infoArray=*0x%x, infoArraySize=%d, descriptArray=*0x%x, descriptArraySize=%d, arrayNum=%d, clanInfo=*0x%x, lastSortDate=*0x%x, totalRecord=*0x%x, option=*0x%x)",
transId, clanId, boardId, idArray, idArraySize, rankArray, rankArraySize, commentArray, commentArraySize, infoArray, infoArraySize, descriptArray, descriptArraySize, arrayNum, clanInfo,
lastSortDate, totalRecord, option);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Score_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (!idArray || !rankArray || !totalRecord || !lastSortDate || !arrayNum)
{
return SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT;
}
if (option) // option check at least until fw 4.71
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
if (arrayNum > SCE_NP_SCORE_MAX_NPID_NUM_PER_TRANS)
{
return SCE_NP_COMMUNITY_ERROR_TOO_MANY_NPID;
}
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ONLINE_ID;
}
return CELL_OK;
}
error_code sceNpScoreGetClansMembersRankingByNpIdPcIdAsync(s32 transId, SceNpClanId clanId, SceNpScoreBoardId boardId, vm::cptr<SceNpId> idArray, u32 idArraySize,
vm::ptr<SceNpScorePlayerRankData> rankArray, u32 rankArraySize, vm::ptr<SceNpScoreComment> commentArray, u32 commentArraySize, vm::ptr<SceNpScoreGameInfo> infoArray, u32 infoArraySize,
vm::ptr<SceNpScoreClansMemberDescription> descriptArray, u32 descriptArraySize, u32 arrayNum, vm::ptr<SceNpScoreClanBasicInfo> clanInfo, vm::ptr<CellRtcTick> lastSortDate,
vm::ptr<SceNpScoreRankNumber> totalRecord, s32 prio, vm::ptr<void> option)
{
sceNp.todo(
"sceNpScoreGetClansMembersRankingByNpIdPcIdAsync(transId=%d, clanId=%d, boardId=%d, idArray=*0x%x, idArraySize=%d, rankArray=*0x%x, rankArraySize=%d, commentArray=*0x%x, commentArraySize=%d, "
"infoArray=*0x%x, infoArraySize=%d, descriptArray=*0x%x, descriptArraySize=%d, arrayNum=%d, clanInfo=*0x%x, lastSortDate=*0x%x, totalRecord=*0x%x, prio=%d, option=*0x%x)",
transId, clanId, boardId, idArray, idArraySize, rankArray, rankArraySize, commentArray, commentArraySize, infoArray, infoArraySize, descriptArray, descriptArraySize, arrayNum, clanInfo,
lastSortDate, totalRecord, prio, option);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Score_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (!idArray || !arrayNum)
{
return SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT;
}
if (option) // option check at least until fw 4.71
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
return CELL_OK;
}
error_code sceNpScoreGetClansRankingByRange(s32 transId, SceNpScoreClansBoardId clanBoardId, SceNpScoreRankNumber startSerialRank, vm::ptr<SceNpScoreClanIdRankData> rankArray, u32 rankArraySize,
vm::ptr<void> reserved1, u32 reservedSize1, vm::ptr<void> reserved2, u32 reservedSize2, u32 arrayNum, vm::ptr<CellRtcTick> lastSortDate, vm::ptr<SceNpScoreRankNumber> totalRecord,
vm::ptr<void> option)
{
sceNp.todo("sceNpScoreGetClansRankingByRange(transId=%d, clanBoardId=%d, startSerialRank=%d, rankArray=*0x%x, rankArraySize=%d, reserved1=*0x%x, reservedSize1=%d, reserved2=*0x%x, reservedSize2=%d, "
"arrayNum=%d, lastSortDate=*0x%x, totalRecord=*0x%x, option=*0x%x)",
transId, clanBoardId, startSerialRank, rankArray, rankArraySize, reserved1, reservedSize1, reserved2, reservedSize2, arrayNum, lastSortDate, totalRecord, option);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Score_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (!rankArray || !totalRecord || !lastSortDate || !arrayNum)
{
return SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT;
}
if (!startSerialRank || reserved1 || reservedSize1 || reserved2 || reservedSize2 || option) // reserved and option checks at least until fw 4.71
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
if (arrayNum > SCE_NP_SCORE_MAX_CLAN_NUM_PER_TRANS)
{
return SCE_NP_COMMUNITY_ERROR_TOO_LARGE_RANGE;
}
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ONLINE_ID;
}
return CELL_OK;
}
error_code sceNpScoreGetClansRankingByRangeAsync(s32 transId, SceNpScoreClansBoardId clanBoardId, SceNpScoreRankNumber startSerialRank, vm::ptr<SceNpScoreClanIdRankData> rankArray, u32 rankArraySize,
vm::ptr<void> reserved1, u32 reservedSize1, vm::ptr<void> reserved2, u32 reservedSize2, u32 arrayNum, vm::ptr<CellRtcTick> lastSortDate, vm::ptr<SceNpScoreRankNumber> totalRecord, s32 prio,
vm::ptr<void> option)
{
sceNp.todo("sceNpScoreGetClansRankingByRangeAsync(transId=%d, clanBoardId=%d, startSerialRank=%d, rankArray=*0x%x, rankArraySize=%d, reserved1=*0x%x, reservedSize1=%d, reserved2=*0x%x, "
"reservedSize2=%d, arrayNum=%d, lastSortDate=*0x%x, totalRecord=*0x%x, prio=%d, option=*0x%x)",
transId, clanBoardId, startSerialRank, rankArray, rankArraySize, reserved1, reservedSize1, reserved2, reservedSize2, arrayNum, lastSortDate, totalRecord, prio, option);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Score_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (!arrayNum)
{
return SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT;
}
if (!startSerialRank || reserved1 || reservedSize1 || reserved2 || reservedSize2 || option) // reserved and option checks at least until fw 4.71
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
return CELL_OK;
}
error_code sceNpScoreGetClanMemberGameData(
s32 transId, SceNpScoreBoardId boardId, SceNpClanId clanId, vm::cptr<SceNpId> npId, vm::ptr<u32> totalSize, u32 recvSize, vm::ptr<void> data, vm::ptr<void> option)
{
sceNp.todo("sceNpScoreGetClanMemberGameData(transId=%d, boardId=%d, clanId=%d, npId=*0x%x, totalSize=*0x%x, recvSize=%d, data=*0x%x, option=*0x%x)", transId, boardId, clanId, npId, totalSize,
recvSize, data, option);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Score_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (!npId || !totalSize || !data)
{
return SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT;
}
if (option) // option check at least until fw 4.71
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ONLINE_ID;
}
return CELL_OK;
}
error_code sceNpScoreGetClanMemberGameDataAsync(
s32 transId, SceNpScoreBoardId boardId, SceNpClanId clanId, vm::cptr<SceNpId> npId, vm::ptr<u32> totalSize, u32 recvSize, vm::ptr<void> data, s32 prio, vm::ptr<void> option)
{
sceNp.todo("sceNpScoreGetClanMemberGameDataAsync(transId=%d, boardId=%d, clanId=%d, npId=*0x%x, totalSize=*0x%x, recvSize=%d, data=*0x%x, prio=%d, option=*0x%x)", transId, boardId, clanId, npId,
totalSize, recvSize, data, prio, option);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Score_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (option) // option check at least until fw 4.71
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
return CELL_OK;
}
error_code sceNpScoreGetClansRankingByClanId(s32 transId, SceNpScoreClansBoardId clanBoardId, vm::cptr<SceNpClanId> clanIdArray, u32 clanIdArraySize, vm::ptr<SceNpScoreClanIdRankData> rankArray,
u32 rankArraySize, vm::ptr<void> reserved1, u32 reservedSize1, vm::ptr<void> reserved2, u32 reservedSize2, u32 arrayNum, vm::ptr<CellRtcTick> lastSortDate,
vm::ptr<SceNpScoreRankNumber> totalRecord, vm::ptr<void> option)
{
sceNp.todo("sceNpScoreGetClansRankingByClanId(transId=%d, clanBoardId=%d, clanIdArray=*0x%x, clanIdArraySize=%d, rankArray=*0x%x, rankArraySize=%d, reserved1=*0x%x, reservedSize1=%d, "
"reserved2=*0x%x, reservedSize2=%d, arrayNum=%d, lastSortDate=*0x%x, totalRecord=*0x%x, option=*0x%x)",
transId, clanBoardId, clanIdArray, clanIdArraySize, rankArray, rankArraySize, reserved1, reservedSize1, reserved2, reservedSize2, arrayNum, lastSortDate, totalRecord, option);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Score_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (!clanIdArray || !rankArray || !totalRecord || !lastSortDate || !arrayNum)
{
return SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT;
}
if (reserved1 || reservedSize1 || reserved2 || reservedSize2 || option) // reserved and option checks at least until fw 4.71
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
if (arrayNum > SCE_NP_SCORE_MAX_NPID_NUM_PER_TRANS)
{
return SCE_NP_COMMUNITY_ERROR_TOO_MANY_NPID;
}
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ONLINE_ID;
}
return CELL_OK;
}
error_code sceNpScoreGetClansRankingByClanIdAsync(s32 transId, SceNpScoreClansBoardId clanBoardId, vm::cptr<SceNpClanId> clanIdArray, u32 clanIdArraySize, vm::ptr<SceNpScoreClanIdRankData> rankArray,
u32 rankArraySize, vm::ptr<void> reserved1, u32 reservedSize1, vm::ptr<void> reserved2, u32 reservedSize2, u32 arrayNum, vm::ptr<CellRtcTick> lastSortDate,
vm::ptr<SceNpScoreRankNumber> totalRecord, s32 prio, vm::ptr<void> option)
{
sceNp.todo("sceNpScoreGetClansRankingByRangeAsync(transId=%d, clanBoardId=%d, clanIdArray=*0x%x, clanIdArraySize=%d, rankArray=*0x%x, rankArraySize=%d, reserved1=*0x%x, reservedSize1=%d, "
"reserved2=*0x%x, reservedSize2=%d, arrayNum=%d, lastSortDate=*0x%x, totalRecord=*0x%x, prio=%d, option=*0x%x)",
transId, clanBoardId, clanIdArray, clanIdArraySize, rankArray, rankArraySize, reserved1, reservedSize1, reserved2, reservedSize2, arrayNum, lastSortDate, totalRecord, prio, option);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Score_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (!arrayNum)
{
return SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT;
}
if (reserved1 || reservedSize1 || reserved2 || reservedSize2 || option) // reserved and option checks at least until fw 4.71
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
return CELL_OK;
}
error_code sceNpScoreGetClansMembersRankingByRange(s32 transId, SceNpClanId clanId, SceNpScoreBoardId boardId, SceNpScoreRankNumber startSerialRank, vm::ptr<SceNpScoreClanIdRankData> rankArray,
u32 rankArraySize, vm::ptr<SceNpScoreComment> commentArray, u32 commentArraySize, vm::ptr<SceNpScoreGameInfo> infoArray, u32 infoArraySize, vm::ptr<SceNpScoreClansMemberDescription> descriptArray,
u32 descriptArraySize, u32 arrayNum, vm::ptr<SceNpScoreClanBasicInfo> clanInfo, vm::ptr<CellRtcTick> lastSortDate, vm::ptr<SceNpScoreRankNumber> totalRecord, vm::ptr<void> option)
{
sceNp.todo("sceNpScoreGetClansMembersRankingByRange(transId=%d, clanId=%d, boardId=%d, startSerialRank=%d, rankArray=*0x%x, rankArraySize=%d, commentArray=*0x%x, commentArraySize=%d, "
"infoArray=*0x%x, infoArraySize=%d, descriptArray=*0x%x, descriptArraySize=%d, arrayNum=%d, clanInfo=*0x%x, lastSortDate=*0x%x, totalRecord=*0x%x, option=*0x%x)",
transId, clanId, boardId, startSerialRank, rankArray, rankArraySize, commentArray, commentArraySize, infoArray, infoArraySize, descriptArray, descriptArraySize, arrayNum, clanInfo, lastSortDate,
totalRecord, option);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Score_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (!rankArray || !totalRecord || !lastSortDate || !arrayNum)
{
return SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT;
}
if (!startSerialRank || option) // option check at least until fw 4.71
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
if (arrayNum > SCE_NP_SCORE_MAX_RANGE_NUM_PER_TRANS)
{
return SCE_NP_COMMUNITY_ERROR_TOO_LARGE_RANGE;
}
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ONLINE_ID;
}
return CELL_OK;
}
error_code sceNpScoreGetClansMembersRankingByRangeAsync(s32 transId, SceNpClanId clanId, SceNpScoreBoardId boardId, SceNpScoreRankNumber startSerialRank, vm::ptr<SceNpScoreClanIdRankData> rankArray,
u32 rankArraySize, vm::ptr<SceNpScoreComment> commentArray, u32 commentArraySize, vm::ptr<SceNpScoreGameInfo> infoArray, u32 infoArraySize, vm::ptr<SceNpScoreClansMemberDescription> descriptArray,
u32 descriptArraySize, u32 arrayNum, vm::ptr<SceNpScoreClanBasicInfo> clanInfo, vm::ptr<CellRtcTick> lastSortDate, vm::ptr<SceNpScoreRankNumber> totalRecord, s32 prio, vm::ptr<void> option)
{
sceNp.todo("sceNpScoreGetClansMembersRankingByRangeAsync(transId=%d, clanId=%d, boardId=%d, startSerialRank=%d, rankArray=*0x%x, rankArraySize=%d, commentArray=*0x%x, commentArraySize=%d, "
"infoArray=*0x%x, infoArraySize=%d, descriptArray=*0x%x, descriptArraySize=%d, arrayNum=%d, clanInfo=*0x%x, lastSortDate=*0x%x, totalRecord=*0x%x, prio=%d, option=*0x%x)",
transId, clanId, boardId, startSerialRank, rankArray, rankArraySize, commentArray, commentArraySize, infoArray, infoArraySize, descriptArray, descriptArraySize, arrayNum, clanInfo, lastSortDate,
totalRecord, prio, option);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Score_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (!arrayNum)
{
return SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT;
}
if (!startSerialRank || option) // option check at least until fw 4.71
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
return CELL_OK;
}
error_code sceNpSignalingCreateCtx(vm::ptr<SceNpId> npId, vm::ptr<SceNpSignalingHandler> handler, vm::ptr<void> arg, vm::ptr<u32> ctx_id)
{
sceNp.warning("sceNpSignalingCreateCtx(npId=*0x%x, handler=*0x%x, arg=*0x%x, ctx_id=*0x%x)", npId, handler, arg, ctx_id);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_SIGNALING_ERROR_NOT_INITIALIZED;
}
if (!npId || !ctx_id)
{
return SCE_NP_SIGNALING_ERROR_INVALID_ARGUMENT;
}
u32 id = create_signaling_context(npId, handler, arg);
if (!id)
{
return SCE_NP_SIGNALING_ERROR_CTX_MAX;
}
*ctx_id = id;
auto& sigh = g_fxo->get<named_thread<signaling_handler>>();
sigh.add_sig_ctx(id);
return CELL_OK;
}
error_code sceNpSignalingDestroyCtx(u32 ctx_id)
{
sceNp.warning("sceNpSignalingDestroyCtx(ctx_id=%d)", ctx_id);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_SIGNALING_ERROR_NOT_INITIALIZED;
}
if (!destroy_signaling_context(ctx_id))
{
return SCE_NP_SIGNALING_ERROR_CTX_NOT_FOUND;
}
auto& sigh = g_fxo->get<named_thread<signaling_handler>>();
sigh.remove_sig_ctx(ctx_id);
return CELL_OK;
}
error_code sceNpSignalingAddExtendedHandler(u32 ctx_id, vm::ptr<SceNpSignalingHandler> handler, vm::ptr<void> arg)
{
sceNp.warning("sceNpSignalingAddExtendedHandler(ctx_id=%d, handler=*0x%x, arg=*0x%x)", ctx_id, handler, arg);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_SIGNALING_ERROR_NOT_INITIALIZED;
}
auto ctx = get_signaling_context(ctx_id);
if (!ctx)
{
return SCE_NP_SIGNALING_ERROR_CTX_NOT_FOUND;
}
std::lock_guard lock(ctx->mutex);
ctx->ext_handler = handler;
ctx->ext_arg = arg;
return CELL_OK;
}
error_code sceNpSignalingSetCtxOpt(u32 ctx_id, s32 optname, s32 optval)
{
sceNp.todo("sceNpSignalingSetCtxOpt(ctx_id=%d, optname=%d, optval=%d)", ctx_id, optname, optval);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_SIGNALING_ERROR_NOT_INITIALIZED;
}
if (!optname || !optval)
{
return SCE_NP_SIGNALING_ERROR_INVALID_ARGUMENT;
}
auto ctx = get_signaling_context(ctx_id);
if (!ctx)
{
return SCE_NP_SIGNALING_ERROR_CTX_NOT_FOUND;
}
// TODO
return CELL_OK;
}
error_code sceNpSignalingGetCtxOpt(u32 ctx_id, s32 optname, vm::ptr<s32> optval)
{
sceNp.todo("sceNpSignalingGetCtxOpt(ctx_id=%d, optname=%d, optval=*0x%x)", ctx_id, optname, optval);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_SIGNALING_ERROR_NOT_INITIALIZED;
}
if (!optname || !optval)
{
return SCE_NP_SIGNALING_ERROR_INVALID_ARGUMENT;
}
auto ctx = get_signaling_context(ctx_id);
if (!ctx)
{
return SCE_NP_SIGNALING_ERROR_CTX_NOT_FOUND;
}
// TODO
return CELL_OK;
}
error_code sceNpSignalingActivateConnection(u32 ctx_id, vm::ptr<SceNpId> npId, vm::ptr<u32> conn_id)
{
sceNp.warning("sceNpSignalingActivateConnection(ctx_id=%d, npId=*0x%x, conn_id=*0x%x)", ctx_id, npId, conn_id);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_SIGNALING_ERROR_NOT_INITIALIZED;
}
if (!npId || !conn_id)
{
return SCE_NP_SIGNALING_ERROR_INVALID_ARGUMENT;
}
if (np::is_same_npid(nph.get_npid(), *npId))
return SCE_NP_SIGNALING_ERROR_OWN_NP_ID;
auto& sigh = g_fxo->get<named_thread<signaling_handler>>();
*conn_id = sigh.init_sig1(*npId);
return CELL_OK;
}
error_code sceNpSignalingDeactivateConnection(u32 ctx_id, u32 conn_id)
{
sceNp.warning("sceNpSignalingDeactivateConnection(ctx_id=%d, conn_id=%d)", ctx_id, conn_id);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_SIGNALING_ERROR_NOT_INITIALIZED;
}
auto& sigh = g_fxo->get<named_thread<signaling_handler>>();
sigh.stop_sig(conn_id, true);
return CELL_OK;
}
error_code sceNpSignalingTerminateConnection(u32 ctx_id, u32 conn_id)
{
sceNp.warning("sceNpSignalingTerminateConnection(ctx_id=%d, conn_id=%d)", ctx_id, conn_id);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_SIGNALING_ERROR_NOT_INITIALIZED;
}
auto& sigh = g_fxo->get<named_thread<signaling_handler>>();
sigh.stop_sig(conn_id, false);
return CELL_OK;
}
error_code sceNpSignalingGetConnectionStatus(u32 ctx_id, u32 conn_id, vm::ptr<s32> conn_status, vm::ptr<np_in_addr> peer_addr, vm::ptr<np_in_port_t> peer_port)
{
sceNp.warning("sceNpSignalingGetConnectionStatus(ctx_id=%d, conn_id=%d, conn_status=*0x%x, peer_addr=*0x%x, peer_port=*0x%x)", ctx_id, conn_id, conn_status, peer_addr, peer_port);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_SIGNALING_ERROR_NOT_INITIALIZED;
}
if (!conn_status)
{
return SCE_NP_SIGNALING_ERROR_INVALID_ARGUMENT;
}
auto& sigh = g_fxo->get<named_thread<signaling_handler>>();
const auto si = sigh.get_sig_infos(conn_id);
if (!si)
{
*conn_status = SCE_NP_SIGNALING_CONN_STATUS_INACTIVE;
return SCE_NP_SIGNALING_ERROR_CONN_NOT_FOUND;
}
*conn_status = si->conn_status;
if (peer_addr)
(*peer_addr).np_s_addr = si->addr; // infos.addr is already BE
if (peer_port)
*peer_port = si->port;
return CELL_OK;
}
error_code sceNpSignalingGetConnectionInfo(u32 ctx_id, u32 conn_id, s32 code, vm::ptr<SceNpSignalingConnectionInfo> info)
{
sceNp.warning("sceNpSignalingGetConnectionInfo(ctx_id=%d, conn_id=%d, code=%d, info=*0x%x)", ctx_id, conn_id, code, info);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_SIGNALING_ERROR_NOT_INITIALIZED;
}
if (!info)
{
return SCE_NP_SIGNALING_ERROR_INVALID_ARGUMENT;
}
auto& sigh = g_fxo->get<named_thread<signaling_handler>>();
const auto si = sigh.get_sig_infos(conn_id);
if (!si)
return SCE_NP_SIGNALING_ERROR_CONN_NOT_FOUND;
switch (code)
{
case SCE_NP_SIGNALING_CONN_INFO_RTT:
{
info->rtt = si->rtt;
break;
}
case SCE_NP_SIGNALING_CONN_INFO_BANDWIDTH:
{
info->bandwidth = 100'000'000; // 100 MBPS HACK
break;
}
case SCE_NP_SIGNALING_CONN_INFO_PEER_NPID:
{
info->npId = si->npid;
break;
}
case SCE_NP_SIGNALING_CONN_INFO_PEER_ADDRESS:
{
info->address.port = std::bit_cast<u16, be_t<u16>>(si->port);
info->address.addr.np_s_addr = si->addr;
break;
}
case SCE_NP_SIGNALING_CONN_INFO_MAPPED_ADDRESS:
{
info->address.port = std::bit_cast<u16, be_t<u16>>(si->mapped_port);
info->address.addr.np_s_addr = si->mapped_addr;
break;
}
case SCE_NP_SIGNALING_CONN_INFO_PACKET_LOSS:
{
info->packet_loss = 0; // HACK
break;
}
default:
{
return SCE_NP_SIGNALING_ERROR_INVALID_ARGUMENT;
}
}
return CELL_OK;
}
error_code sceNpSignalingGetConnectionFromNpId(u32 ctx_id, vm::ptr<SceNpId> npId, vm::ptr<u32> conn_id)
{
sceNp.notice("sceNpSignalingGetConnectionFromNpId(ctx_id=%d, npId=*0x%x, conn_id=*0x%x)", ctx_id, npId, conn_id);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_SIGNALING_ERROR_NOT_INITIALIZED;
}
if (!npId || !conn_id)
{
return SCE_NP_SIGNALING_ERROR_INVALID_ARGUMENT;
}
if (np::is_same_npid(*npId, nph.get_npid()))
{
return SCE_NP_SIGNALING_ERROR_OWN_NP_ID;
}
auto& sigh = g_fxo->get<named_thread<signaling_handler>>();
const auto found_conn_id = sigh.get_conn_id_from_npid(*npId);
if (!found_conn_id)
{
return SCE_NP_SIGNALING_ERROR_CONN_NOT_FOUND;
}
*conn_id = *found_conn_id;
return CELL_OK;
}
error_code sceNpSignalingGetConnectionFromPeerAddress(u32 ctx_id, np_in_addr_t peer_addr, np_in_port_t peer_port, vm::ptr<u32> conn_id)
{
sceNp.warning("sceNpSignalingGetConnectionFromPeerAddress(ctx_id=%d, peer_addr=0x%x, peer_port=%d, conn_id=*0x%x)", ctx_id, peer_addr, peer_port, conn_id);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_SIGNALING_ERROR_NOT_INITIALIZED;
}
if (!conn_id)
{
return SCE_NP_SIGNALING_ERROR_INVALID_ARGUMENT;
}
auto& sigh = g_fxo->get<named_thread<signaling_handler>>();
const auto found_conn_id = sigh.get_conn_id_from_addr(peer_addr, peer_port);
if (!found_conn_id)
{
return SCE_NP_SIGNALING_ERROR_CONN_NOT_FOUND;
}
*conn_id = *found_conn_id;
return CELL_OK;
}
error_code sceNpSignalingGetLocalNetInfo(u32 ctx_id, vm::ptr<SceNpSignalingNetInfo> info)
{
sceNp.warning("sceNpSignalingGetLocalNetInfo(ctx_id=%d, info=*0x%x)", ctx_id, info);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_SIGNALING_ERROR_NOT_INITIALIZED;
}
if (!info || info->size != sizeof(SceNpSignalingNetInfo))
{
return SCE_NP_SIGNALING_ERROR_INVALID_ARGUMENT;
}
info->local_addr = nph.get_local_ip_addr();
info->mapped_addr = nph.get_public_ip_addr();
// Pure speculation below
info->nat_status = SCE_NP_SIGNALING_NETINFO_NAT_STATUS_TYPE2;
info->upnp_status = nph.get_upnp_status();
info->npport_status = SCE_NP_SIGNALING_NETINFO_NPPORT_STATUS_OPEN;
info->npport = SCE_NP_PORT;
return CELL_OK;
}
error_code sceNpSignalingGetPeerNetInfo(u32 ctx_id, vm::ptr<SceNpId> npId, vm::ptr<u32> req_id)
{
sceNp.todo("sceNpSignalingGetPeerNetInfo(ctx_id=%d, npId=*0x%x, req_id=*0x%x)", ctx_id, npId, req_id);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_SIGNALING_ERROR_NOT_INITIALIZED;
}
if (!npId || !req_id)
{
return SCE_NP_SIGNALING_ERROR_INVALID_ARGUMENT;
}
return CELL_OK;
}
error_code sceNpSignalingCancelPeerNetInfo(u32 ctx_id, u32 req_id)
{
sceNp.todo("sceNpSignalingCancelPeerNetInfo(ctx_id=%d, req_id=%d)", ctx_id, req_id);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_SIGNALING_ERROR_NOT_INITIALIZED;
}
return CELL_OK;
}
error_code sceNpSignalingGetPeerNetInfoResult(u32 ctx_id, u32 req_id, vm::ptr<SceNpSignalingNetInfo> info)
{
sceNp.todo("sceNpSignalingGetPeerNetInfoResult(ctx_id=%d, req_id=%d, info=*0x%x)", ctx_id, req_id, info);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_init)
{
return SCE_NP_SIGNALING_ERROR_NOT_INITIALIZED;
}
if (!info)
{
// TODO: check info->size
return SCE_NP_SIGNALING_ERROR_INVALID_ARGUMENT;
}
return CELL_OK;
}
error_code sceNpUtilCanonicalizeNpIdForPs3(vm::ptr<SceNpId> npId)
{
sceNp.warning("sceNpUtilCanonicalizeNpIdForPs3(npId=*0x%x)", npId);
if (!npId)
return SCE_NP_UTIL_ERROR_INVALID_ARGUMENT;
// TODO: These checks are commented out for compatibility with RPCN for now
//if (npId->reserved[0] != 1)
// return SCE_NP_UTIL_ERROR_INVALID_NP_ID;
//if (!npId->unk1[1])
//{
// npId->unk1[1] = "ps3\0"_u32;
//}
return CELL_OK;
}
error_code sceNpUtilCanonicalizeNpIdForPsp(vm::ptr<SceNpId> npId)
{
sceNp.warning("sceNpUtilCanonicalizeNpIdForPsp(npId=*0x%x)", npId);
if (!npId)
return SCE_NP_UTIL_ERROR_INVALID_ARGUMENT;
// TODO: These checks are commented out for compatibility with RPCN for now
//if (npId->reserved[0] != 1)
// return SCE_NP_UTIL_ERROR_INVALID_NP_ID;
//if (!npId->unk1[1])
//{
// npId->unk1[1] = "psp\0"_u32; // TODO: confirm
//}
return CELL_OK;
}
error_code sceNpUtilCmpNpId(vm::ptr<SceNpId> id1, vm::ptr<SceNpId> id2)
{
sceNp.trace("sceNpUtilCmpNpId(id1=*0x%x(%s), id2=*0x%x(%s))", id1, id1 ? id1->handle.data : "", id2, id2 ? id2->handle.data : "");
if (!id1 || !id2)
{
return SCE_NP_UTIL_ERROR_INVALID_ARGUMENT;
}
if (!np::is_same_npid(*id1, *id2))
return not_an_error(SCE_NP_UTIL_ERROR_NOT_MATCH);
return CELL_OK;
}
error_code sceNpUtilCmpNpIdInOrder(vm::cptr<SceNpId> id1, vm::cptr<SceNpId> id2, vm::ptr<s32> order)
{
sceNp.trace("sceNpUtilCmpNpIdInOrder(id1=*0x%x, id2=*0x%x, order=*0x%x)", id1, id2, order);
if (!id1 || !id2)
{
return SCE_NP_UTIL_ERROR_INVALID_ARGUMENT;
}
// if (id1->reserved[0] != 1 || id2->reserved[0] != 1)
// {
// return SCE_NP_UTIL_ERROR_INVALID_NP_ID;
// }
if (s32 res = strncmp(id1->handle.data, id2->handle.data, 16))
{
*order = std::clamp<s32>(res, -1, 1);
return CELL_OK;
}
if (s32 res = std::memcmp(id1->unk1, id2->unk1, 4))
{
*order = std::clamp<s32>(res, -1, 1);
return CELL_OK;
}
const u8 opt14 = id1->opt[4];
const u8 opt24 = id2->opt[4];
if (opt14 == 0 && opt24 == 0)
{
*order = 0;
return CELL_OK;
}
if (opt14 != 0 && opt24 != 0)
{
s32 res = std::memcmp(id1->unk1 + 1, id2->unk1 + 1, 4);
*order = std::clamp<s32>(res, -1, 1);
return CELL_OK;
}
s32 res = std::memcmp((opt14 != 0 ? id1 : id2)->unk1 + 1, "ps3", 4);
*order = std::clamp<s32>(res, -1, 1);
return CELL_OK;
}
error_code sceNpUtilCmpOnlineId(vm::cptr<SceNpId> id1, vm::cptr<SceNpId> id2)
{
sceNp.warning("sceNpUtilCmpOnlineId(id1=*0x%x, id2=*0x%x)", id1, id2);
if (!id1 || !id2)
{
return SCE_NP_UTIL_ERROR_INVALID_ARGUMENT;
}
// if (id1->reserved[0] != 1 || id2->reserved[0] != 1)
// {
// return SCE_NP_UTIL_ERROR_INVALID_NP_ID;
// }
if (strncmp(id1->handle.data, id2->handle.data, 16) != 0)
{
return SCE_NP_UTIL_ERROR_NOT_MATCH;
}
return CELL_OK;
}
error_code sceNpUtilGetPlatformType(vm::cptr<SceNpId> npId)
{
sceNp.warning("sceNpUtilGetPlatformType(npId=*0x%x)", npId);
if (!npId)
{
return SCE_NP_UTIL_ERROR_INVALID_ARGUMENT;
}
switch (npId->unk1[1])
{
case "ps4\0"_u32:
return not_an_error(SCE_NP_PLATFORM_TYPE_PS4);
case "psp2"_u32:
return not_an_error(SCE_NP_PLATFORM_TYPE_VITA);
case "ps3\0"_u32:
return not_an_error(SCE_NP_PLATFORM_TYPE_PS3);
case 0u:
return not_an_error(SCE_NP_PLATFORM_TYPE_NONE);
default:
break;
}
return SCE_NP_UTIL_ERROR_UNKNOWN_PLATFORM_TYPE;
}
error_code sceNpUtilSetPlatformType(vm::ptr<SceNpId> npId, SceNpPlatformType platformType)
{
sceNp.warning("sceNpUtilSetPlatformType(npId=*0x%x, platformType=%d)", npId, platformType);
if (!npId)
{
return SCE_NP_UTIL_ERROR_INVALID_ARGUMENT;
}
switch (platformType)
{
case SCE_NP_PLATFORM_TYPE_PS4:
npId->unk1[1] = "ps4\0"_u32; break;
case SCE_NP_PLATFORM_TYPE_VITA:
npId->unk1[1] = "psp2"_u32; break;
case SCE_NP_PLATFORM_TYPE_PS3:
npId->unk1[1] = "ps3\0"_u32; break;
case SCE_NP_PLATFORM_TYPE_NONE:
npId->unk1[1] = 0; break;
default:
return SCE_NP_UTIL_ERROR_UNKNOWN_PLATFORM_TYPE;
}
return CELL_OK;
}
error_code _sceNpSysutilClientMalloc()
{
UNIMPLEMENTED_FUNC(sceNp);
return CELL_OK;
}
error_code _sceNpSysutilClientFree()
{
UNIMPLEMENTED_FUNC(sceNp);
return CELL_OK;
}
s32 _Z33_sce_np_sysutil_send_empty_packetiPN16sysutil_cxmlutil11FixedMemoryEPKcS3_()
{
sceNp.todo("_Z33_sce_np_sysutil_send_empty_packetiPN16sysutil_cxmlutil11FixedMemoryEPKcS3_()");
return CELL_OK;
}
s32 _Z27_sce_np_sysutil_send_packetiRN4cxml8DocumentE()
{
sceNp.todo("_Z27_sce_np_sysutil_send_packetiRN4cxml8DocumentE()");
return CELL_OK;
}
s32 _Z36_sce_np_sysutil_recv_packet_fixedmemiPN16sysutil_cxmlutil11FixedMemoryERN4cxml8DocumentERNS2_7ElementE()
{
sceNp.todo("_Z36_sce_np_sysutil_recv_packet_fixedmemiPN16sysutil_cxmlutil11FixedMemoryERN4cxml8DocumentERNS2_7ElementE()");
return CELL_OK;
}
s32 _Z40_sce_np_sysutil_recv_packet_fixedmem_subiPN16sysutil_cxmlutil11FixedMemoryERN4cxml8DocumentERNS2_7ElementE()
{
sceNp.todo("_Z40_sce_np_sysutil_recv_packet_fixedmem_subiPN16sysutil_cxmlutil11FixedMemoryERN4cxml8DocumentERNS2_7ElementE()");
return CELL_OK;
}
s32 _Z27_sce_np_sysutil_recv_packetiRN4cxml8DocumentERNS_7ElementE()
{
sceNp.todo("_Z27_sce_np_sysutil_recv_packetiRN4cxml8DocumentERNS_7ElementE()");
return CELL_OK;
}
s32 _Z29_sce_np_sysutil_cxml_set_npidRN4cxml8DocumentERNS_7ElementEPKcPK7SceNpId()
{
sceNp.todo("_Z29_sce_np_sysutil_cxml_set_npidRN4cxml8DocumentERNS_7ElementEPKcPK7SceNpId()");
return CELL_OK;
}
s32 _Z31_sce_np_sysutil_send_packet_subiRN4cxml8DocumentE()
{
sceNp.todo("_Z31_sce_np_sysutil_send_packet_subiRN4cxml8DocumentE()");
return CELL_OK;
}
s32 _Z37sce_np_matching_set_matching2_runningb()
{
sceNp.todo("_Z37sce_np_matching_set_matching2_runningb()");
return CELL_OK;
}
s32 _Z32_sce_np_sysutil_cxml_prepare_docPN16sysutil_cxmlutil11FixedMemoryERN4cxml8DocumentEPKcRNS2_7ElementES6_i()
{
sceNp.todo("_Z32_sce_np_sysutil_cxml_prepare_docPN16sysutil_cxmlutil11FixedMemoryERN4cxml8DocumentEPKcRNS2_7ElementES6_i()");
return CELL_OK;
}
DECLARE(ppu_module_manager::sceNp)
("sceNp", []() {
REG_FUNC(sceNp, sceNpInit);
REG_FUNC(sceNp, sceNpTerm);
REG_FUNC(sceNp, sceNpDrmIsAvailable);
REG_FUNC(sceNp, sceNpDrmIsAvailable2);
REG_FUNC(sceNp, sceNpDrmVerifyUpgradeLicense);
REG_FUNC(sceNp, sceNpDrmVerifyUpgradeLicense2);
REG_FUNC(sceNp, sceNpDrmExecuteGamePurchase);
REG_FUNC(sceNp, sceNpDrmGetTimelimit);
REG_FUNC(sceNp, sceNpDrmProcessExitSpawn);
REG_FUNC(sceNp, sceNpDrmProcessExitSpawn2);
REG_FUNC(sceNp, sceNpBasicRegisterHandler);
REG_FUNC(sceNp, sceNpBasicRegisterContextSensitiveHandler);
REG_FUNC(sceNp, sceNpBasicUnregisterHandler);
REG_FUNC(sceNp, sceNpBasicSetPresence);
REG_FUNC(sceNp, sceNpBasicSetPresenceDetails);
REG_FUNC(sceNp, sceNpBasicSetPresenceDetails2);
REG_FUNC(sceNp, sceNpBasicSendMessage);
REG_FUNC(sceNp, sceNpBasicSendMessageGui);
REG_FUNC(sceNp, sceNpBasicSendMessageAttachment);
REG_FUNC(sceNp, sceNpBasicRecvMessageAttachment);
REG_FUNC(sceNp, sceNpBasicRecvMessageAttachmentLoad);
REG_FUNC(sceNp, sceNpBasicRecvMessageCustom);
REG_FUNC(sceNp, sceNpBasicMarkMessageAsUsed);
REG_FUNC(sceNp, sceNpBasicAbortGui);
REG_FUNC(sceNp, sceNpBasicAddFriend);
REG_FUNC(sceNp, sceNpBasicGetFriendListEntryCount);
REG_FUNC(sceNp, sceNpBasicGetFriendListEntry);
REG_FUNC(sceNp, sceNpBasicGetFriendPresenceByIndex);
REG_FUNC(sceNp, sceNpBasicGetFriendPresenceByIndex2);
REG_FUNC(sceNp, sceNpBasicGetFriendPresenceByNpId);
REG_FUNC(sceNp, sceNpBasicGetFriendPresenceByNpId2);
REG_FUNC(sceNp, sceNpBasicAddPlayersHistory);
REG_FUNC(sceNp, sceNpBasicAddPlayersHistoryAsync);
REG_FUNC(sceNp, sceNpBasicGetPlayersHistoryEntryCount);
REG_FUNC(sceNp, sceNpBasicGetPlayersHistoryEntry);
REG_FUNC(sceNp, sceNpBasicAddBlockListEntry);
REG_FUNC(sceNp, sceNpBasicGetBlockListEntryCount);
REG_FUNC(sceNp, sceNpBasicGetBlockListEntry);
REG_FUNC(sceNp, sceNpBasicGetMessageAttachmentEntryCount);
REG_FUNC(sceNp, sceNpBasicGetMessageAttachmentEntry);
REG_FUNC(sceNp, sceNpBasicGetCustomInvitationEntryCount);
REG_FUNC(sceNp, sceNpBasicGetCustomInvitationEntry);
REG_FUNC(sceNp, sceNpBasicGetMatchingInvitationEntryCount);
REG_FUNC(sceNp, sceNpBasicGetMatchingInvitationEntry);
REG_FUNC(sceNp, sceNpBasicGetClanMessageEntryCount);
REG_FUNC(sceNp, sceNpBasicGetClanMessageEntry);
REG_FUNC(sceNp, sceNpBasicGetMessageEntryCount);
REG_FUNC(sceNp, sceNpBasicGetMessageEntry);
REG_FUNC(sceNp, sceNpBasicGetEvent);
REG_FUNC(sceNp, sceNpCommerceCreateCtx);
REG_FUNC(sceNp, sceNpCommerceDestroyCtx);
REG_FUNC(sceNp, sceNpCommerceInitProductCategory);
REG_FUNC(sceNp, sceNpCommerceDestroyProductCategory);
REG_FUNC(sceNp, sceNpCommerceGetProductCategoryStart);
REG_FUNC(sceNp, sceNpCommerceGetProductCategoryFinish);
REG_FUNC(sceNp, sceNpCommerceGetProductCategoryResult);
REG_FUNC(sceNp, sceNpCommerceGetProductCategoryAbort);
REG_FUNC(sceNp, sceNpCommerceGetProductId);
REG_FUNC(sceNp, sceNpCommerceGetProductName);
REG_FUNC(sceNp, sceNpCommerceGetCategoryDescription);
REG_FUNC(sceNp, sceNpCommerceGetCategoryId);
REG_FUNC(sceNp, sceNpCommerceGetCategoryImageURL);
REG_FUNC(sceNp, sceNpCommerceGetCategoryInfo);
REG_FUNC(sceNp, sceNpCommerceGetCategoryName);
REG_FUNC(sceNp, sceNpCommerceGetCurrencyCode);
REG_FUNC(sceNp, sceNpCommerceGetCurrencyDecimals);
REG_FUNC(sceNp, sceNpCommerceGetCurrencyInfo);
REG_FUNC(sceNp, sceNpCommerceGetNumOfChildCategory);
REG_FUNC(sceNp, sceNpCommerceGetNumOfChildProductSku);
REG_FUNC(sceNp, sceNpCommerceGetSkuDescription);
REG_FUNC(sceNp, sceNpCommerceGetSkuId);
REG_FUNC(sceNp, sceNpCommerceGetSkuImageURL);
REG_FUNC(sceNp, sceNpCommerceGetSkuName);
REG_FUNC(sceNp, sceNpCommerceGetSkuPrice);
REG_FUNC(sceNp, sceNpCommerceGetSkuUserData);
REG_FUNC(sceNp, sceNpCommerceSetDataFlagStart);
REG_FUNC(sceNp, sceNpCommerceGetDataFlagStart);
REG_FUNC(sceNp, sceNpCommerceSetDataFlagFinish);
REG_FUNC(sceNp, sceNpCommerceGetDataFlagFinish);
REG_FUNC(sceNp, sceNpCommerceGetDataFlagState);
REG_FUNC(sceNp, sceNpCommerceGetDataFlagAbort);
REG_FUNC(sceNp, sceNpCommerceGetChildCategoryInfo);
REG_FUNC(sceNp, sceNpCommerceGetChildProductSkuInfo);
REG_FUNC(sceNp, sceNpCommerceDoCheckoutStartAsync);
REG_FUNC(sceNp, sceNpCommerceDoCheckoutFinishAsync);
REG_FUNC(sceNp, sceNpCustomMenuRegisterActions);
REG_FUNC(sceNp, sceNpCustomMenuActionSetActivation);
REG_FUNC(sceNp, sceNpCustomMenuRegisterExceptionList);
REG_FUNC(sceNp, sceNpFriendlist);
REG_FUNC(sceNp, sceNpFriendlistCustom);
REG_FUNC(sceNp, sceNpFriendlistAbortGui);
REG_FUNC(sceNp, sceNpLookupInit);
REG_FUNC(sceNp, sceNpLookupTerm);
REG_FUNC(sceNp, sceNpLookupCreateTitleCtx);
REG_FUNC(sceNp, sceNpLookupDestroyTitleCtx);
REG_FUNC(sceNp, sceNpLookupCreateTransactionCtx);
REG_FUNC(sceNp, sceNpLookupDestroyTransactionCtx);
REG_FUNC(sceNp, sceNpLookupSetTimeout);
REG_FUNC(sceNp, sceNpLookupAbortTransaction);
REG_FUNC(sceNp, sceNpLookupWaitAsync);
REG_FUNC(sceNp, sceNpLookupPollAsync);
REG_FUNC(sceNp, sceNpLookupNpId);
REG_FUNC(sceNp, sceNpLookupNpIdAsync);
REG_FUNC(sceNp, sceNpLookupUserProfile);
REG_FUNC(sceNp, sceNpLookupUserProfileAsync);
REG_FUNC(sceNp, sceNpLookupUserProfileWithAvatarSize);
REG_FUNC(sceNp, sceNpLookupUserProfileWithAvatarSizeAsync);
REG_FUNC(sceNp, sceNpLookupAvatarImage);
REG_FUNC(sceNp, sceNpLookupAvatarImageAsync);
REG_FUNC(sceNp, sceNpLookupTitleStorage);
REG_FUNC(sceNp, sceNpLookupTitleStorageAsync);
REG_FUNC(sceNp, sceNpLookupTitleSmallStorage);
REG_FUNC(sceNp, sceNpLookupTitleSmallStorageAsync);
REG_FUNC(sceNp, sceNpManagerRegisterCallback);
REG_FUNC(sceNp, sceNpManagerUnregisterCallback);
REG_FUNC(sceNp, sceNpManagerGetStatus);
REG_FUNC(sceNp, sceNpManagerGetNetworkTime);
REG_FUNC(sceNp, sceNpManagerGetOnlineId);
REG_FUNC(sceNp, sceNpManagerGetNpId);
REG_FUNC(sceNp, sceNpManagerGetOnlineName);
REG_FUNC(sceNp, sceNpManagerGetAvatarUrl);
REG_FUNC(sceNp, sceNpManagerGetMyLanguages);
REG_FUNC(sceNp, sceNpManagerGetAccountRegion);
REG_FUNC(sceNp, sceNpManagerGetAccountAge);
REG_FUNC(sceNp, sceNpManagerGetContentRatingFlag);
REG_FUNC(sceNp, sceNpManagerGetChatRestrictionFlag);
REG_FUNC(sceNp, sceNpManagerGetCachedInfo);
REG_FUNC(sceNp, sceNpManagerGetPsHandle);
REG_FUNC(sceNp, sceNpManagerRequestTicket);
REG_FUNC(sceNp, sceNpManagerRequestTicket2);
REG_FUNC(sceNp, sceNpManagerGetTicket);
REG_FUNC(sceNp, sceNpManagerGetTicketParam);
REG_FUNC(sceNp, sceNpManagerGetEntitlementIdList);
REG_FUNC(sceNp, sceNpManagerGetEntitlementById);
REG_FUNC(sceNp, sceNpManagerGetSigninId);
REG_FUNC(sceNp, sceNpManagerSubSignin);
REG_FUNC(sceNp, sceNpManagerSubSigninAbortGui);
REG_FUNC(sceNp, sceNpManagerSubSignout);
REG_FUNC(sceNp, sceNpMatchingCreateCtx);
REG_FUNC(sceNp, sceNpMatchingDestroyCtx);
REG_FUNC(sceNp, sceNpMatchingGetResult);
REG_FUNC(sceNp, sceNpMatchingGetResultGUI);
REG_FUNC(sceNp, sceNpMatchingSetRoomInfo);
REG_FUNC(sceNp, sceNpMatchingSetRoomInfoNoLimit);
REG_FUNC(sceNp, sceNpMatchingGetRoomInfo);
REG_FUNC(sceNp, sceNpMatchingGetRoomInfoNoLimit);
REG_FUNC(sceNp, sceNpMatchingSetRoomSearchFlag);
REG_FUNC(sceNp, sceNpMatchingGetRoomSearchFlag);
REG_FUNC(sceNp, sceNpMatchingGetRoomMemberListLocal);
REG_FUNC(sceNp, sceNpMatchingGetRoomListLimitGUI);
REG_FUNC(sceNp, sceNpMatchingKickRoomMember);
REG_FUNC(sceNp, sceNpMatchingKickRoomMemberWithOpt);
REG_FUNC(sceNp, sceNpMatchingQuickMatchGUI);
REG_FUNC(sceNp, sceNpMatchingSendInvitationGUI);
REG_FUNC(sceNp, sceNpMatchingAcceptInvitationGUI);
REG_FUNC(sceNp, sceNpMatchingCreateRoomGUI);
REG_FUNC(sceNp, sceNpMatchingJoinRoomGUI);
REG_FUNC(sceNp, sceNpMatchingLeaveRoom);
REG_FUNC(sceNp, sceNpMatchingSearchJoinRoomGUI);
REG_FUNC(sceNp, sceNpMatchingGrantOwnership);
REG_FUNC(sceNp, sceNpProfileCallGui);
REG_FUNC(sceNp, sceNpProfileAbortGui);
REG_FUNC(sceNp, sceNpScoreInit);
REG_FUNC(sceNp, sceNpScoreTerm);
REG_FUNC(sceNp, sceNpScoreCreateTitleCtx);
REG_FUNC(sceNp, sceNpScoreDestroyTitleCtx);
REG_FUNC(sceNp, sceNpScoreCreateTransactionCtx);
REG_FUNC(sceNp, sceNpScoreDestroyTransactionCtx);
REG_FUNC(sceNp, sceNpScoreSetTimeout);
REG_FUNC(sceNp, sceNpScoreSetPlayerCharacterId);
REG_FUNC(sceNp, sceNpScoreWaitAsync);
REG_FUNC(sceNp, sceNpScorePollAsync);
REG_FUNC(sceNp, sceNpScoreGetBoardInfo);
REG_FUNC(sceNp, sceNpScoreGetBoardInfoAsync);
REG_FUNC(sceNp, sceNpScoreRecordScore);
REG_FUNC(sceNp, sceNpScoreRecordScoreAsync);
REG_FUNC(sceNp, sceNpScoreRecordGameData);
REG_FUNC(sceNp, sceNpScoreRecordGameDataAsync);
REG_FUNC(sceNp, sceNpScoreGetGameData);
REG_FUNC(sceNp, sceNpScoreGetGameDataAsync);
REG_FUNC(sceNp, sceNpScoreGetRankingByNpId);
REG_FUNC(sceNp, sceNpScoreGetRankingByNpIdAsync);
REG_FUNC(sceNp, sceNpScoreGetRankingByRange);
REG_FUNC(sceNp, sceNpScoreGetRankingByRangeAsync);
REG_FUNC(sceNp, sceNpScoreGetFriendsRanking);
REG_FUNC(sceNp, sceNpScoreGetFriendsRankingAsync);
REG_FUNC(sceNp, sceNpScoreCensorComment);
REG_FUNC(sceNp, sceNpScoreCensorCommentAsync);
REG_FUNC(sceNp, sceNpScoreSanitizeComment);
REG_FUNC(sceNp, sceNpScoreSanitizeCommentAsync);
REG_FUNC(sceNp, sceNpScoreGetRankingByNpIdPcId);
REG_FUNC(sceNp, sceNpScoreGetRankingByNpIdPcIdAsync);
REG_FUNC(sceNp, sceNpScoreAbortTransaction);
REG_FUNC(sceNp, sceNpScoreGetClansMembersRankingByNpId);
REG_FUNC(sceNp, sceNpScoreGetClansMembersRankingByNpIdAsync);
REG_FUNC(sceNp, sceNpScoreGetClansMembersRankingByNpIdPcId);
REG_FUNC(sceNp, sceNpScoreGetClansMembersRankingByNpIdPcIdAsync);
REG_FUNC(sceNp, sceNpScoreGetClansMembersRankingByRange);
REG_FUNC(sceNp, sceNpScoreGetClansMembersRankingByRangeAsync);
REG_FUNC(sceNp, sceNpScoreGetClanMemberGameData);
REG_FUNC(sceNp, sceNpScoreGetClanMemberGameDataAsync);
REG_FUNC(sceNp, sceNpScoreGetClansRankingByClanId);
REG_FUNC(sceNp, sceNpScoreGetClansRankingByClanIdAsync);
REG_FUNC(sceNp, sceNpScoreGetClansRankingByRange);
REG_FUNC(sceNp, sceNpScoreGetClansRankingByRangeAsync);
REG_FUNC(sceNp, sceNpSignalingCreateCtx);
REG_FUNC(sceNp, sceNpSignalingDestroyCtx);
REG_FUNC(sceNp, sceNpSignalingAddExtendedHandler);
REG_FUNC(sceNp, sceNpSignalingSetCtxOpt);
REG_FUNC(sceNp, sceNpSignalingGetCtxOpt);
REG_FUNC(sceNp, sceNpSignalingActivateConnection);
REG_FUNC(sceNp, sceNpSignalingDeactivateConnection);
REG_FUNC(sceNp, sceNpSignalingTerminateConnection);
REG_FUNC(sceNp, sceNpSignalingGetConnectionStatus);
REG_FUNC(sceNp, sceNpSignalingGetConnectionInfo);
REG_FUNC(sceNp, sceNpSignalingGetConnectionFromNpId);
REG_FUNC(sceNp, sceNpSignalingGetConnectionFromPeerAddress);
REG_FUNC(sceNp, sceNpSignalingGetLocalNetInfo);
REG_FUNC(sceNp, sceNpSignalingGetPeerNetInfo);
REG_FUNC(sceNp, sceNpSignalingCancelPeerNetInfo);
REG_FUNC(sceNp, sceNpSignalingGetPeerNetInfoResult);
REG_FUNC(sceNp, sceNpUtilCanonicalizeNpIdForPs3);
REG_FUNC(sceNp, sceNpUtilCanonicalizeNpIdForPsp);
REG_FUNC(sceNp, sceNpUtilCmpNpId);
REG_FUNC(sceNp, sceNpUtilCmpNpIdInOrder);
REG_FUNC(sceNp, sceNpUtilCmpOnlineId);
REG_FUNC(sceNp, sceNpUtilGetPlatformType);
REG_FUNC(sceNp, sceNpUtilSetPlatformType);
REG_FUNC(sceNp, _sceNpSysutilClientMalloc);
REG_FUNC(sceNp, _sceNpSysutilClientFree);
REG_FUNC(sceNp, _Z33_sce_np_sysutil_send_empty_packetiPN16sysutil_cxmlutil11FixedMemoryEPKcS3_);
REG_FUNC(sceNp, _Z27_sce_np_sysutil_send_packetiRN4cxml8DocumentE);
REG_FUNC(sceNp, _Z36_sce_np_sysutil_recv_packet_fixedmemiPN16sysutil_cxmlutil11FixedMemoryERN4cxml8DocumentERNS2_7ElementE);
REG_FUNC(sceNp, _Z40_sce_np_sysutil_recv_packet_fixedmem_subiPN16sysutil_cxmlutil11FixedMemoryERN4cxml8DocumentERNS2_7ElementE);
REG_FUNC(sceNp, _Z27_sce_np_sysutil_recv_packetiRN4cxml8DocumentERNS_7ElementE);
REG_FUNC(sceNp, _Z29_sce_np_sysutil_cxml_set_npidRN4cxml8DocumentERNS_7ElementEPKcPK7SceNpId);
REG_FUNC(sceNp, _Z31_sce_np_sysutil_send_packet_subiRN4cxml8DocumentE);
REG_FUNC(sceNp, _Z37sce_np_matching_set_matching2_runningb);
REG_FUNC(sceNp, _Z32_sce_np_sysutil_cxml_prepare_docPN16sysutil_cxmlutil11FixedMemoryERN4cxml8DocumentEPKcRNS2_7ElementES6_i);
});
| 230,910
|
C++
|
.cpp
| 5,944
| 36.190949
| 224
| 0.741336
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| false
| false
|
5,236
|
cellUsbd.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellUsbd.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
#include "cellUsbd.h"
LOG_CHANNEL(cellUsbd);
template<>
void fmt_class_string<CellUsbdError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_USBD_ERROR_NOT_INITIALIZED);
STR_CASE(CELL_USBD_ERROR_ALREADY_INITIALIZED);
STR_CASE(CELL_USBD_ERROR_NO_MEMORY);
STR_CASE(CELL_USBD_ERROR_INVALID_PARAM);
STR_CASE(CELL_USBD_ERROR_INVALID_TRANSFER_TYPE);
STR_CASE(CELL_USBD_ERROR_LDD_ALREADY_REGISTERED);
STR_CASE(CELL_USBD_ERROR_LDD_NOT_ALLOCATED);
STR_CASE(CELL_USBD_ERROR_LDD_NOT_RELEASED);
STR_CASE(CELL_USBD_ERROR_LDD_NOT_FOUND);
STR_CASE(CELL_USBD_ERROR_DEVICE_NOT_FOUND);
STR_CASE(CELL_USBD_ERROR_PIPE_NOT_ALLOCATED);
STR_CASE(CELL_USBD_ERROR_PIPE_NOT_RELEASED);
STR_CASE(CELL_USBD_ERROR_PIPE_NOT_FOUND);
STR_CASE(CELL_USBD_ERROR_IOREQ_NOT_ALLOCATED);
STR_CASE(CELL_USBD_ERROR_IOREQ_NOT_RELEASED);
STR_CASE(CELL_USBD_ERROR_IOREQ_NOT_FOUND);
STR_CASE(CELL_USBD_ERROR_CANNOT_GET_DESCRIPTOR);
STR_CASE(CELL_USBD_ERROR_FATAL);
}
return unknown;
});
}
error_code cellUsbdInit()
{
cellUsbd.warning("cellUsbdInit()");
return CELL_OK;
}
error_code cellUsbdEnd()
{
cellUsbd.warning("cellUsbdEnd()");
return CELL_OK;
}
error_code cellUsbdSetThreadPriority()
{
UNIMPLEMENTED_FUNC(cellUsbd);
return CELL_OK;
}
error_code cellUsbdSetThreadPriority2()
{
UNIMPLEMENTED_FUNC(cellUsbd);
return CELL_OK;
}
error_code cellUsbdGetThreadPriority()
{
UNIMPLEMENTED_FUNC(cellUsbd);
return CELL_OK;
}
error_code cellUsbdRegisterLdd()
{
UNIMPLEMENTED_FUNC(cellUsbd);
return CELL_OK;
}
error_code cellUsbdRegisterCompositeLdd()
{
UNIMPLEMENTED_FUNC(cellUsbd);
return CELL_OK;
}
error_code cellUsbdRegisterExtraLdd()
{
UNIMPLEMENTED_FUNC(cellUsbd);
return CELL_OK;
}
error_code cellUsbdRegisterExtraLdd2()
{
UNIMPLEMENTED_FUNC(cellUsbd);
return CELL_OK;
}
error_code cellUsbdUnregisterLdd()
{
UNIMPLEMENTED_FUNC(cellUsbd);
return CELL_OK;
}
error_code cellUsbdUnregisterCompositeLdd()
{
UNIMPLEMENTED_FUNC(cellUsbd);
return CELL_OK;
}
error_code cellUsbdUnregisterExtraLdd()
{
UNIMPLEMENTED_FUNC(cellUsbd);
return CELL_OK;
}
error_code cellUsbdOpenPipe()
{
UNIMPLEMENTED_FUNC(cellUsbd);
return CELL_OK;
}
error_code cellUsbdClosePipe()
{
UNIMPLEMENTED_FUNC(cellUsbd);
return CELL_OK;
}
error_code cellUsbdControlTransfer()
{
UNIMPLEMENTED_FUNC(cellUsbd);
return CELL_OK;
}
error_code cellUsbdBulkTransfer()
{
UNIMPLEMENTED_FUNC(cellUsbd);
return CELL_OK;
}
error_code cellUsbdInterruptTransfer()
{
UNIMPLEMENTED_FUNC(cellUsbd);
return CELL_OK;
}
error_code cellUsbdIsochronousTransfer()
{
UNIMPLEMENTED_FUNC(cellUsbd);
return CELL_OK;
}
error_code cellUsbdHSIsochronousTransfer()
{
UNIMPLEMENTED_FUNC(cellUsbd);
return CELL_OK;
}
error_code cellUsbdScanStaticDescriptor()
{
UNIMPLEMENTED_FUNC(cellUsbd);
return CELL_OK;
}
error_code cellUsbdGetDeviceSpeed()
{
UNIMPLEMENTED_FUNC(cellUsbd);
return CELL_OK;
}
error_code cellUsbdGetDeviceLocation()
{
UNIMPLEMENTED_FUNC(cellUsbd);
return CELL_OK;
}
error_code cellUsbdSetPrivateData()
{
UNIMPLEMENTED_FUNC(cellUsbd);
return CELL_OK;
}
error_code cellUsbdGetPrivateData()
{
UNIMPLEMENTED_FUNC(cellUsbd);
return CELL_OK;
}
error_code cellUsbdAllocateMemory()
{
UNIMPLEMENTED_FUNC(cellUsbd);
return CELL_OK;
}
error_code cellUsbdAllocateMemoryFromContainer()
{
UNIMPLEMENTED_FUNC(cellUsbd);
return CELL_OK;
}
error_code cellUsbdAllocateSharedMemory()
{
UNIMPLEMENTED_FUNC(cellUsbd);
return CELL_OK;
}
error_code cellUsbdFreeMemory()
{
UNIMPLEMENTED_FUNC(cellUsbd);
return CELL_OK;
}
error_code cellUsbdResetDevice()
{
UNIMPLEMENTED_FUNC(cellUsbd);
return CELL_OK;
}
DECLARE(ppu_module_manager::cellUsbd)("cellUsbd", []()
{
REG_FUNC(cellUsbd, cellUsbdInit);
REG_FUNC(cellUsbd, cellUsbdEnd);
REG_FUNC(cellUsbd, cellUsbdSetThreadPriority);
REG_FUNC(cellUsbd, cellUsbdSetThreadPriority2);
REG_FUNC(cellUsbd, cellUsbdGetThreadPriority);
REG_FUNC(cellUsbd, cellUsbdRegisterLdd);
REG_FUNC(cellUsbd, cellUsbdRegisterCompositeLdd);
REG_FUNC(cellUsbd, cellUsbdRegisterExtraLdd);
REG_FUNC(cellUsbd, cellUsbdRegisterExtraLdd2);
REG_FUNC(cellUsbd, cellUsbdUnregisterLdd);
REG_FUNC(cellUsbd, cellUsbdUnregisterCompositeLdd);
REG_FUNC(cellUsbd, cellUsbdUnregisterExtraLdd);
REG_FUNC(cellUsbd, cellUsbdOpenPipe);
REG_FUNC(cellUsbd, cellUsbdClosePipe);
REG_FUNC(cellUsbd, cellUsbdControlTransfer);
REG_FUNC(cellUsbd, cellUsbdBulkTransfer);
REG_FUNC(cellUsbd, cellUsbdInterruptTransfer);
REG_FUNC(cellUsbd, cellUsbdIsochronousTransfer);
REG_FUNC(cellUsbd, cellUsbdHSIsochronousTransfer);
REG_FUNC(cellUsbd, cellUsbdScanStaticDescriptor);
REG_FUNC(cellUsbd, cellUsbdGetDeviceSpeed);
REG_FUNC(cellUsbd, cellUsbdGetDeviceLocation);
REG_FUNC(cellUsbd, cellUsbdSetPrivateData);
REG_FUNC(cellUsbd, cellUsbdGetPrivateData);
REG_FUNC(cellUsbd, cellUsbdAllocateMemory);
REG_FUNC(cellUsbd, cellUsbdAllocateMemoryFromContainer);
REG_FUNC(cellUsbd, cellUsbdAllocateSharedMemory);
REG_FUNC(cellUsbd, cellUsbdFreeMemory);
REG_FUNC(cellUsbd, cellUsbdResetDevice);
});
| 5,156
|
C++
|
.cpp
| 210
| 22.619048
| 71
| 0.806406
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| true
| false
| false
| true
| false
| false
|
5,237
|
cellFontFT.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellFontFT.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
#include "cellFontFT.h"
LOG_CHANNEL(cellFontFT);
error_code cellFontInitLibraryFreeTypeWithRevision(u64 revisionFlags, vm::ptr<CellFontLibraryConfigFT> config, vm::pptr<CellFontLibrary> lib)
{
cellFontFT.todo("cellFontInitLibraryFreeTypeWithRevision(revisionFlags=0x%llx, config=*0x%x, lib=**0x%x)", revisionFlags, config, lib);
if (!lib)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
*lib = {};
if (!config)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (false) // TODO
{
return CELL_FONT_ERROR_UNINITIALIZED;
}
lib->set(vm::alloc(sizeof(CellFontLibrary), vm::main));
return CELL_OK;
}
error_code cellFontInitLibraryFreeType(vm::ptr<CellFontLibraryConfigFT> config, vm::pptr<CellFontLibrary> lib)
{
cellFontFT.todo("cellFontInitLibraryFreeType(config=*0x%x, lib=**0x%x)", config, lib);
uint64_t revisionFlags = 0LL;
//cellFontFTGetStubRevisionFlags(&revisionFlags);
return cellFontInitLibraryFreeTypeWithRevision(revisionFlags, config, lib);
}
void cellFontFTGetRevisionFlags(vm::ptr<u64> revisionFlags)
{
cellFontFT.notice("cellFontFTGetRevisionFlags(revisionFlags=*0x%x)", revisionFlags);
if (revisionFlags)
{
*revisionFlags = 0x43;
}
}
error_code cellFontFTGetInitializedRevisionFlags(vm::ptr<u64> revisionFlags)
{
cellFontFT.notice("cellFontFTGetInitializedRevisionFlags(revisionFlags=*0x%x)", revisionFlags);
if (!revisionFlags)
{
return CELL_FONT_ERROR_INVALID_PARAMETER;
}
if (false) // TODO
{
return CELL_FONT_ERROR_UNINITIALIZED;
}
//*revisionFlags = something; // TODO
return CELL_OK;
}
error_code FTCacheStream_CacheEnd()
{
UNIMPLEMENTED_FUNC(cellFontFT);
return CELL_OK;
}
error_code FTCacheStream_CacheInit()
{
UNIMPLEMENTED_FUNC(cellFontFT);
return CELL_OK;
}
error_code FTCacheStream_CalcCacheIndexSize()
{
UNIMPLEMENTED_FUNC(cellFontFT);
return CELL_OK;
}
error_code FTCacheStream_End()
{
UNIMPLEMENTED_FUNC(cellFontFT);
return CELL_OK;
}
error_code FTCacheStream_Init()
{
UNIMPLEMENTED_FUNC(cellFontFT);
return CELL_OK;
}
error_code FTFaceH_Close()
{
UNIMPLEMENTED_FUNC(cellFontFT);
return CELL_OK;
}
error_code FTFaceH_FontFamilyName()
{
UNIMPLEMENTED_FUNC(cellFontFT);
return CELL_OK;
}
error_code FTFaceH_FontStyleName()
{
UNIMPLEMENTED_FUNC(cellFontFT);
return CELL_OK;
}
error_code FTFaceH_GetAscender()
{
UNIMPLEMENTED_FUNC(cellFontFT);
return CELL_OK;
}
error_code FTFaceH_GetBoundingBoxHeight()
{
UNIMPLEMENTED_FUNC(cellFontFT);
return CELL_OK;
}
error_code FTFaceH_GetBoundingBoxMaxX()
{
UNIMPLEMENTED_FUNC(cellFontFT);
return CELL_OK;
}
error_code FTFaceH_GetBoundingBoxMaxY()
{
UNIMPLEMENTED_FUNC(cellFontFT);
return CELL_OK;
}
error_code FTFaceH_GetBoundingBoxMinX()
{
UNIMPLEMENTED_FUNC(cellFontFT);
return CELL_OK;
}
error_code FTFaceH_GetBoundingBoxMinY()
{
UNIMPLEMENTED_FUNC(cellFontFT);
return CELL_OK;
}
error_code FTFaceH_GetBoundingBoxWidth()
{
UNIMPLEMENTED_FUNC(cellFontFT);
return CELL_OK;
}
error_code FTFaceH_GetCompositeCodes()
{
UNIMPLEMENTED_FUNC(cellFontFT);
return CELL_OK;
}
error_code FTFaceH_GetGlyphImage()
{
UNIMPLEMENTED_FUNC(cellFontFT);
return CELL_OK;
}
error_code FTFaceH_GetGlyphMetrics()
{
UNIMPLEMENTED_FUNC(cellFontFT);
return CELL_OK;
}
error_code FTFaceH_GetKerning()
{
UNIMPLEMENTED_FUNC(cellFontFT);
return CELL_OK;
}
error_code FTFaceH_GetMaxHorizontalAdvance()
{
UNIMPLEMENTED_FUNC(cellFontFT);
return CELL_OK;
}
error_code FTFaceH_GetMaxVerticalAdvance()
{
UNIMPLEMENTED_FUNC(cellFontFT);
return CELL_OK;
}
error_code FTFaceH_GetRenderBufferSize()
{
UNIMPLEMENTED_FUNC(cellFontFT);
return CELL_OK;
}
error_code FTFaceH_GetRenderEffectSlant()
{
UNIMPLEMENTED_FUNC(cellFontFT);
return CELL_OK;
}
error_code FTFaceH_GetRenderEffectWeight()
{
UNIMPLEMENTED_FUNC(cellFontFT);
return CELL_OK;
}
error_code FTFaceH_GetRenderScale()
{
UNIMPLEMENTED_FUNC(cellFontFT);
return CELL_OK;
}
error_code FTFaceH_GetRenderScalePixel()
{
UNIMPLEMENTED_FUNC(cellFontFT);
return CELL_OK;
}
error_code FTFaceH_GetRenderScalePoint()
{
UNIMPLEMENTED_FUNC(cellFontFT);
return CELL_OK;
}
error_code FTFaceH_SetCompositeCodes()
{
UNIMPLEMENTED_FUNC(cellFontFT);
return CELL_OK;
}
error_code FTFaceH_SetRenderEffectSlant()
{
UNIMPLEMENTED_FUNC(cellFontFT);
return CELL_OK;
}
error_code FTFaceH_SetRenderEffectWeight()
{
UNIMPLEMENTED_FUNC(cellFontFT);
return CELL_OK;
}
error_code FTFaceH_SetRenderScalePixel()
{
UNIMPLEMENTED_FUNC(cellFontFT);
return CELL_OK;
}
error_code FTFaceH_SetRenderScalePoint()
{
UNIMPLEMENTED_FUNC(cellFontFT);
return CELL_OK;
}
error_code FTManager_CloseFace()
{
UNIMPLEMENTED_FUNC(cellFontFT);
return CELL_OK;
}
error_code FTManager_Done_FreeType()
{
UNIMPLEMENTED_FUNC(cellFontFT);
return CELL_OK;
}
error_code FTManager_Init_FreeType()
{
UNIMPLEMENTED_FUNC(cellFontFT);
return CELL_OK;
}
error_code FTManager_OpenFileFace()
{
UNIMPLEMENTED_FUNC(cellFontFT);
return CELL_OK;
}
error_code FTManager_OpenMemFace()
{
UNIMPLEMENTED_FUNC(cellFontFT);
return CELL_OK;
}
error_code FTManager_OpenStreamFace()
{
UNIMPLEMENTED_FUNC(cellFontFT);
return CELL_OK;
}
error_code FTManager_SetFontOpenMode()
{
UNIMPLEMENTED_FUNC(cellFontFT);
return CELL_OK;
}
DECLARE(ppu_module_manager::cellFontFT)("cellFontFT", []()
{
REG_FUNC(cellFontFT, cellFontInitLibraryFreeType);
REG_FUNC(cellFontFT, cellFontInitLibraryFreeTypeWithRevision);
REG_FUNC(cellFontFT, cellFontFTGetRevisionFlags);
REG_FUNC(cellFontFT, cellFontFTGetInitializedRevisionFlags);
REG_FUNC(cellFontFT, FTCacheStream_CacheEnd);
REG_FUNC(cellFontFT, FTCacheStream_CacheInit);
REG_FUNC(cellFontFT, FTCacheStream_CalcCacheIndexSize);
REG_FUNC(cellFontFT, FTCacheStream_End);
REG_FUNC(cellFontFT, FTCacheStream_Init);
REG_FUNC(cellFontFT, FTFaceH_Close);
REG_FUNC(cellFontFT, FTFaceH_FontFamilyName);
REG_FUNC(cellFontFT, FTFaceH_FontStyleName);
REG_FUNC(cellFontFT, FTFaceH_GetAscender);
REG_FUNC(cellFontFT, FTFaceH_GetBoundingBoxHeight);
REG_FUNC(cellFontFT, FTFaceH_GetBoundingBoxMaxX);
REG_FUNC(cellFontFT, FTFaceH_GetBoundingBoxMaxY);
REG_FUNC(cellFontFT, FTFaceH_GetBoundingBoxMinX);
REG_FUNC(cellFontFT, FTFaceH_GetBoundingBoxMinY);
REG_FUNC(cellFontFT, FTFaceH_GetBoundingBoxWidth);
REG_FUNC(cellFontFT, FTFaceH_GetCompositeCodes);
REG_FUNC(cellFontFT, FTFaceH_GetGlyphImage);
REG_FUNC(cellFontFT, FTFaceH_GetGlyphMetrics);
REG_FUNC(cellFontFT, FTFaceH_GetKerning);
REG_FUNC(cellFontFT, FTFaceH_GetMaxHorizontalAdvance);
REG_FUNC(cellFontFT, FTFaceH_GetMaxVerticalAdvance);
REG_FUNC(cellFontFT, FTFaceH_GetRenderBufferSize);
REG_FUNC(cellFontFT, FTFaceH_GetRenderEffectSlant);
REG_FUNC(cellFontFT, FTFaceH_GetRenderEffectWeight);
REG_FUNC(cellFontFT, FTFaceH_GetRenderScale);
REG_FUNC(cellFontFT, FTFaceH_GetRenderScalePixel);
REG_FUNC(cellFontFT, FTFaceH_GetRenderScalePoint);
REG_FUNC(cellFontFT, FTFaceH_SetCompositeCodes);
REG_FUNC(cellFontFT, FTFaceH_SetRenderEffectSlant);
REG_FUNC(cellFontFT, FTFaceH_SetRenderEffectWeight);
REG_FUNC(cellFontFT, FTFaceH_SetRenderScalePixel);
REG_FUNC(cellFontFT, FTFaceH_SetRenderScalePoint);
REG_FUNC(cellFontFT, FTManager_CloseFace);
REG_FUNC(cellFontFT, FTManager_Done_FreeType);
REG_FUNC(cellFontFT, FTManager_Init_FreeType);
REG_FUNC(cellFontFT, FTManager_OpenFileFace);
REG_FUNC(cellFontFT, FTManager_OpenMemFace);
REG_FUNC(cellFontFT, FTManager_OpenStreamFace);
REG_FUNC(cellFontFT, FTManager_SetFontOpenMode);
});
| 7,469
|
C++
|
.cpp
| 293
| 23.726962
| 141
| 0.814898
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| false
| false
|
5,238
|
cellMic.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellMic.cpp
|
#include "stdafx.h"
#include "Emu/System.h"
#include "Emu/system_config.h"
#include "Emu/Cell/PPUModule.h"
#include "Utilities/StrUtil.h"
#include "cellMic.h"
#include <Emu/IdManager.h>
#include <Emu/Cell/lv2/sys_event.h>
#include <numeric>
LOG_CHANNEL(cellMic);
template<>
void fmt_class_string<CellMicInError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_MICIN_ERROR_ALREADY_INIT);
STR_CASE(CELL_MICIN_ERROR_DEVICE);
STR_CASE(CELL_MICIN_ERROR_NOT_INIT);
STR_CASE(CELL_MICIN_ERROR_PARAM);
STR_CASE(CELL_MICIN_ERROR_PORT_FULL);
STR_CASE(CELL_MICIN_ERROR_ALREADY_OPEN);
STR_CASE(CELL_MICIN_ERROR_NOT_OPEN);
STR_CASE(CELL_MICIN_ERROR_NOT_RUN);
STR_CASE(CELL_MICIN_ERROR_TRANS_EVENT);
STR_CASE(CELL_MICIN_ERROR_OPEN);
STR_CASE(CELL_MICIN_ERROR_SHAREDMEMORY);
STR_CASE(CELL_MICIN_ERROR_MUTEX);
STR_CASE(CELL_MICIN_ERROR_EVENT_QUEUE);
STR_CASE(CELL_MICIN_ERROR_DEVICE_NOT_FOUND);
STR_CASE(CELL_MICIN_ERROR_FATAL);
STR_CASE(CELL_MICIN_ERROR_DEVICE_NOT_SUPPORT);
}
return unknown;
});
}
template<>
void fmt_class_string<CellMicInErrorDsp>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_MICIN_ERROR_DSP);
STR_CASE(CELL_MICIN_ERROR_DSP_ASSERT);
STR_CASE(CELL_MICIN_ERROR_DSP_PATH);
STR_CASE(CELL_MICIN_ERROR_DSP_FILE);
STR_CASE(CELL_MICIN_ERROR_DSP_PARAM);
STR_CASE(CELL_MICIN_ERROR_DSP_MEMALLOC);
STR_CASE(CELL_MICIN_ERROR_DSP_POINTER);
STR_CASE(CELL_MICIN_ERROR_DSP_FUNC);
STR_CASE(CELL_MICIN_ERROR_DSP_MEM);
STR_CASE(CELL_MICIN_ERROR_DSP_ALIGN16);
STR_CASE(CELL_MICIN_ERROR_DSP_ALIGN128);
STR_CASE(CELL_MICIN_ERROR_DSP_EAALIGN128);
STR_CASE(CELL_MICIN_ERROR_DSP_LIB_HANDLER);
STR_CASE(CELL_MICIN_ERROR_DSP_LIB_INPARAM);
STR_CASE(CELL_MICIN_ERROR_DSP_LIB_NOSPU);
STR_CASE(CELL_MICIN_ERROR_DSP_LIB_SAMPRATE);
}
return unknown;
});
}
void mic_context::operator()()
{
// Timestep in microseconds
constexpr u64 TIMESTEP = 256ull * 1'000'000ull / 48000ull;
u64 timeout = 0;
while (thread_ctrl::state() != thread_state::aborting)
{
if (timeout != 0)
{
thread_ctrl::wait_on(wakey, 0, timeout);
wakey.store(0);
}
std::lock_guard lock(mutex);
if (std::none_of(mic_list.begin(), mic_list.end(), [](const microphone_device& dev) { return dev.is_registered(); }))
{
timeout = umax;
continue;
}
else
{
timeout = TIMESTEP - (std::chrono::duration_cast<std::chrono::microseconds>(steady_clock::now().time_since_epoch()).count() % TIMESTEP);
}
for (auto& mic_entry : mic_list)
{
mic_entry.update_audio();
}
auto mic_queue = lv2_event_queue::find(event_queue_key);
if (!mic_queue)
continue;
for (usz dev_num = 0; dev_num < mic_list.size(); dev_num++)
{
microphone_device& device = ::at32(mic_list, dev_num);
if (device.has_data())
{
mic_queue->send(event_queue_source, CELLMIC_DATA, dev_num, 0);
}
}
}
// Cleanup
std::lock_guard lock(mutex);
for (auto& mic_entry : mic_list)
{
mic_entry.close_microphone();
}
}
void mic_context::wake_up()
{
wakey.store(1);
wakey.notify_one();
}
void mic_context::load_config_and_init()
{
mic_list = {};
const std::vector<std::string> device_list = fmt::split(g_cfg.audio.microphone_devices.to_string(), {"@@@"});
if (!device_list.empty())
{
// We only register the first device. The rest is registered with cellAudioInRegisterDevice.
if (g_cfg.audio.microphone_type == microphone_handler::singstar)
{
microphone_device& device = ::at32(mic_list, 0);
device = microphone_device(microphone_handler::singstar);
device.set_registered(true);
device.add_device(device_list[0]);
// Singstar uses the same device for 2 players
if (device_list.size() >= 2)
{
device.add_device(device_list[1]);
}
wake_up();
}
else
{
[[maybe_unused]] const u32 index = register_device(device_list[0]);
}
}
}
u32 mic_context::register_device(const std::string& device_name)
{
usz index = mic_list.size();
for (usz i = 0; i < mic_list.size(); i++)
{
microphone_device& device = ::at32(mic_list, i);
if (!device.is_registered())
{
if (index == mic_list.size())
{
index = i;
}
}
else if (device_name == device.get_device_name())
{
// TODO: what happens if the device is registered twice?
return ::narrow<u32>(i);
}
}
// TODO: Check max mics properly
ensure(index < mic_list.size(), "cellMic max mics exceeded during registration");
switch (g_cfg.audio.microphone_type)
{
case microphone_handler::standard:
case microphone_handler::real_singstar:
case microphone_handler::rocksmith:
{
microphone_device& device = ::at32(mic_list, index);
device = microphone_device(g_cfg.audio.microphone_type.get());
device.set_registered(true);
device.add_device(device_name);
if (auto mic_queue = lv2_event_queue::find(event_queue_key))
{
mic_queue->send(event_queue_source, CELLMIC_ATTACH, index, 0);
}
break;
}
case microphone_handler::singstar:
case microphone_handler::null:
default:
break;
}
wake_up();
return ::narrow<u32>(index);
}
void mic_context::unregister_device(u32 dev_num)
{
// Don't allow to unregister the first device for now.
if (dev_num == 0 || dev_num >= mic_list.size())
{
return;
}
microphone_device& device = ::at32(mic_list, dev_num);
device = microphone_device();
if (auto mic_queue = lv2_event_queue::find(event_queue_key))
{
mic_queue->send(event_queue_source, CELLMIC_DETACH, dev_num, 0);
}
}
bool mic_context::check_device(u32 dev_num)
{
if (dev_num >= mic_list.size())
return false;
microphone_device& device = ::at32(mic_list, dev_num);
return device.is_registered();
}
// Static functions
template <u32 bytesize>
inline void microphone_device::variable_byteswap(const void* src, void* dst)
{
if constexpr (bytesize == 4)
{
*static_cast<u32*>(dst) = *static_cast<const be_t<u32>*>(src);
}
else if constexpr (bytesize == 2)
{
*static_cast<u16*>(dst) = *static_cast<const be_t<u16>*>(src);
}
else
{
fmt::throw_exception("variable_byteswap with bytesize %d unimplemented", bytesize);
}
}
inline u32 microphone_device::convert_16_bit_pcm_to_float(const std::vector<u8>& buffer, u32 num_bytes)
{
static_assert((float_buf_size % sizeof(f32)) == 0);
float_buf.resize(float_buf_size, 0);
const u32 bytes_to_write = static_cast<u32>(num_bytes * (sizeof(f32) / sizeof(s16)));
ensure(bytes_to_write <= float_buf.size());
const be_t<s16>* src = utils::bless<const be_t<s16>>(buffer.data());
be_t<f32>* dst = reinterpret_cast<be_t<f32>*>(float_buf.data());
for (usz i = 0; i < num_bytes / sizeof(s16); i++)
{
const be_t<s16> sample = *src++;
const be_t<f32> normalized_sample_be = std::clamp(static_cast<f32>(sample) / std::numeric_limits<s16>::max(), -1.0f, 1.0f);
*dst++ = normalized_sample_be;
}
return bytes_to_write;
}
// Public functions
microphone_device::microphone_device(microphone_handler type)
{
device_type = type;
}
void microphone_device::add_device(const std::string& name)
{
devices.push_back(mic_device{
.name = name
});
}
error_code microphone_device::open_microphone(const u8 type, const u32 dsp_r, const u32 raw_r, const u8 channels)
{
signal_types = type;
dsp_samplingrate = dsp_r;
raw_samplingrate = raw_r;
num_channels = channels;
// Adjust number of channels depending on microphone type
switch (device_type)
{
case microphone_handler::standard:
break;
case microphone_handler::singstar:
case microphone_handler::real_singstar:
// SingStar mic has always 2 channels, each channel represent a physical microphone
ensure(num_channels >= 2);
if (num_channels > 2)
{
cellMic.error("Tried to open a SingStar-type device with num_channels = %d", num_channels);
num_channels = 2;
}
break;
case microphone_handler::rocksmith:
num_channels = 1;
break;
case microphone_handler::null:
default:
ensure(false);
break;
}
ALCenum num_al_channels;
switch (num_channels)
{
case 1:
num_al_channels = AL_FORMAT_MONO16;
break;
case 2:
// If we're using SingStar each device needs to be mono
if (device_type == microphone_handler::singstar)
num_al_channels = AL_FORMAT_MONO16;
else
num_al_channels = AL_FORMAT_STEREO16;
break;
case 4:
num_al_channels = AL_FORMAT_QUAD16;
break;
default:
cellMic.warning("Requested an invalid number of %d channels. Defaulting to 4 channels instead.", num_channels);
num_al_channels = AL_FORMAT_QUAD16;
num_channels = 4;
break;
}
// Real firmware tries 4, 2 and then 1 channels if the channel count is not supported
// TODO: The used channel count may vary for Sony's camera devices
for (bool found_valid_channels = false; !found_valid_channels;)
{
switch (num_al_channels)
{
case AL_FORMAT_QUAD16:
if (alcIsExtensionPresent(nullptr, "AL_EXT_MCFORMATS") == AL_TRUE)
{
found_valid_channels = true;
break;
}
cellMic.warning("Requested 4 channels but AL_EXT_MCFORMATS not available, trying 2 channels next");
num_al_channels = AL_FORMAT_STEREO16;
num_channels = 2;
break;
case AL_FORMAT_STEREO16:
if (true) // TODO: check stereo capability
{
found_valid_channels = true;
break;
}
cellMic.warning("Requested 2 channels but extension is not available, trying 1 channel next");
num_al_channels = AL_FORMAT_MONO16;
num_channels = 1;
break;
case AL_FORMAT_MONO16:
found_valid_channels = true;
break;
default:
ensure(false);
break;
}
}
// Ensure that the code above delivers what it should
switch (num_al_channels)
{
case AL_FORMAT_QUAD16:
ensure(num_channels == 4 && device_type != microphone_handler::singstar && device_type != microphone_handler::real_singstar);
break;
case AL_FORMAT_STEREO16:
ensure(num_channels == 2 && device_type != microphone_handler::singstar);
break;
case AL_FORMAT_MONO16:
ensure(num_channels == 1 || (num_channels == 2 && device_type == microphone_handler::singstar));
break;
default:
ensure(false);
break;
}
// Make sure we use a proper sampling rate
const auto fixup_samplingrate = [this](u32& rate) -> bool
{
// TODO: The used sample rate may vary for Sony's camera devices
const std::array<u32, 7> samplingrates = { rate, 48000u, 32000u, 24000u, 16000u, 12000u, 8000u };
const auto test_samplingrate = [&samplingrates](const u32& rate)
{
// TODO: actually check if device supports sampling rates
return std::any_of(samplingrates.cbegin() + 1, samplingrates.cend(), [&rate](const u32& r){ return r == rate; });
};
for (u32 samplingrate : samplingrates)
{
if (test_samplingrate(samplingrate))
{
// Use this sampling rate
raw_samplingrate = samplingrate;
cellMic.notice("Using sampling rate %d.", samplingrate);
return true;
}
cellMic.warning("Requested sampling rate %d, but we do not support it. Trying next sampling rate...", samplingrate);
}
return false;
};
if (!fixup_samplingrate(raw_samplingrate))
{
return CELL_MICIN_ERROR_DEVICE_NOT_SUPPORT;
}
aux_samplingrate = dsp_samplingrate = raw_samplingrate; // Same rate for now
ensure(!devices.empty());
ALCdevice* device = alcCaptureOpenDevice(devices[0].name.c_str(), raw_samplingrate, num_al_channels, inbuf_size);
if (ALCenum err = alcGetError(device); err != ALC_NO_ERROR || !device)
{
cellMic.error("Error opening capture device %s (error=0x%x, device=*0x%x)", devices[0].name, err, device);
#ifdef _WIN32
cellMic.error("Make sure microphone use is authorized under \"Microphone privacy settings\" in windows configuration");
#endif
return CELL_MICIN_ERROR_DEVICE_NOT_SUPPORT;
}
devices[0].device = device;
devices[0].buf.resize(inbuf_size, 0);
if (device_type == microphone_handler::singstar && devices.size() >= 2)
{
// Open a 2nd microphone into the same device
device = alcCaptureOpenDevice(devices[1].name.c_str(), raw_samplingrate, AL_FORMAT_MONO16, inbuf_size);
if (ALCenum err = alcGetError(device); err != ALC_NO_ERROR || !device)
{
// Ignore it and move on
cellMic.error("Error opening 2nd SingStar capture device %s (error=0x%x, device=*0x%x)", devices[1].name, err, device);
}
else
{
devices[1].device = device;
devices[1].buf.resize(inbuf_size, 0);
}
}
if (device_type != microphone_handler::real_singstar)
{
temp_buf.resize(inbuf_size, 0);
}
sample_size = (bit_resolution / 8) * num_channels;
mic_opened = true;
return CELL_OK;
}
error_code microphone_device::close_microphone()
{
if (mic_started)
{
stop_microphone();
}
for (mic_device& micdevice : devices)
{
if (alcCaptureCloseDevice(micdevice.device) != ALC_TRUE)
{
cellMic.error("Error closing capture device %s", micdevice.name);
}
micdevice.device = nullptr;
micdevice.buf.clear();
}
temp_buf.clear();
mic_opened = false;
return CELL_OK;
}
error_code microphone_device::start_microphone()
{
for (const mic_device& micdevice : devices)
{
alcCaptureStart(micdevice.device);
if (ALCenum err = alcGetError(micdevice.device); err != ALC_NO_ERROR)
{
cellMic.error("Error starting capture of device %s (error=0x%x)", micdevice.name, err);
stop_microphone();
return CELL_MICIN_ERROR_FATAL;
}
}
mic_started = true;
return CELL_OK;
}
error_code microphone_device::stop_microphone()
{
for (const mic_device& micdevice : devices)
{
alcCaptureStop(micdevice.device);
if (ALCenum err = alcGetError(micdevice.device); err != ALC_NO_ERROR)
{
cellMic.error("Error stopping capture of device %s (error=0x%x)", micdevice.name, err);
}
}
mic_started = false;
return CELL_OK;
}
void microphone_device::update_audio()
{
if (mic_registered && mic_opened && mic_started)
{
if (signal_types == CELLMIC_SIGTYPE_NULL)
return;
const u32 num_samples = capture_audio();
if ((signal_types & CELLMIC_SIGTYPE_RAW) ||
(signal_types & CELLMIC_SIGTYPE_DSP))
{
get_data(num_samples);
}
if (signal_types & CELLMIC_SIGTYPE_RAW)
{
get_raw(num_samples);
}
if (signal_types & CELLMIC_SIGTYPE_DSP)
{
get_dsp(num_samples);
}
// TODO: aux?
}
}
bool microphone_device::has_data() const
{
return mic_registered && mic_opened && mic_started && (rbuf_raw.has_data() || rbuf_dsp.has_data());
}
u32 microphone_device::capture_audio()
{
ensure(sample_size > 0);
u32 num_samples = inbuf_size / sample_size;
for (const mic_device& micdevice : devices)
{
ALCint samples_in = 0;
alcGetIntegerv(micdevice.device, ALC_CAPTURE_SAMPLES, 1, &samples_in);
if (ALCenum err = alcGetError(micdevice.device); err != ALC_NO_ERROR)
{
cellMic.error("Error getting number of captured samples of device %s (error=0x%x)", micdevice.name, err);
return CELL_MICIN_ERROR_FATAL;
}
num_samples = std::min<u32>(num_samples, samples_in);
}
if (num_samples == 0)
{
return 0;
}
for (mic_device& micdevice : devices)
{
alcCaptureSamples(micdevice.device, micdevice.buf.data(), num_samples);
if (ALCenum err = alcGetError(micdevice.device); err != ALC_NO_ERROR)
{
cellMic.error("Error capturing samples of device %s (error=0x%x)", micdevice.name, err);
}
}
return num_samples;
}
// Private functions
void microphone_device::get_data(const u32 num_samples)
{
if (num_samples == 0)
{
return;
}
switch (device_type)
{
case microphone_handler::real_singstar:
{
// Straight copy from device. No need for intermediate buffer.
break;
}
case microphone_handler::standard:
case microphone_handler::rocksmith:
{
constexpr u8 channel_size = bit_resolution / 8;
const usz bufsize = num_samples * sample_size;
const std::vector<u8>& buf = ::at32(devices, 0).buf;
ensure(bufsize <= buf.size());
ensure(bufsize <= temp_buf.size());
u8* tmp_ptr = temp_buf.data();
// BE Translation
for (u32 index = 0; index < bufsize; index += channel_size)
{
microphone_device::variable_byteswap<channel_size>(buf.data() + index, tmp_ptr + index);
}
break;
}
case microphone_handler::singstar:
{
ensure(sample_size == 4);
// Each device buffer contains 16 bit mono samples
const usz bufsize = num_samples * sizeof(u16);
const std::vector<u8>& buf_0 = ::at32(devices, 0).buf;
ensure(bufsize <= buf_0.size());
u8* tmp_ptr = temp_buf.data();
// Mixing the 2 mics into the 2 destination channels
if (devices.size() == 2)
{
const std::vector<u8>& buf_1 = ::at32(devices, 1).buf;
ensure(bufsize <= buf_1.size());
for (u32 index = 0; index < (num_samples * 4); index += 4)
{
const u32 src_index = index / 2;
tmp_ptr[index] = buf_0[src_index];
tmp_ptr[index + 1] = buf_0[src_index + 1];
tmp_ptr[index + 2] = buf_1[src_index];
tmp_ptr[index + 3] = buf_1[src_index + 1];
}
}
else
{
for (u32 index = 0; index < (num_samples * 4); index += 4)
{
const u32 src_index = index / 2;
tmp_ptr[index] = buf_0[src_index];
tmp_ptr[index + 1] = buf_0[src_index + 1];
tmp_ptr[index + 2] = 0;
tmp_ptr[index + 3] = 0;
}
}
break;
}
case microphone_handler::null:
ensure(false);
break;
}
}
void microphone_device::get_raw(const u32 num_samples)
{
if (num_samples == 0)
{
return;
}
const std::vector<u8>& buf = device_type == microphone_handler::real_singstar ? ::at32(devices, 0).buf : temp_buf;
const u32 bufsize = num_samples * sample_size;
ensure(bufsize <= buf.size());
rbuf_raw.write_bytes(buf.data(), bufsize);
}
void microphone_device::get_dsp(const u32 num_samples)
{
if (num_samples == 0)
{
return;
}
const std::vector<u8>& buf = device_type == microphone_handler::real_singstar ? ::at32(devices, 0).buf : temp_buf;
const u32 bufsize = num_samples * sample_size;
ensure(bufsize <= buf.size());
if (attr_dsptype != 0x01)
{
// Convert 16-bit PCM audio data to 32-bit float (DSP format)
const u32 bufsize_float = convert_16_bit_pcm_to_float(buf, bufsize);
rbuf_dsp.write_bytes(float_buf.data(), bufsize_float);
}
else
{
// The same as device RAW stream format, except that the data byte is always big-endian
rbuf_dsp.write_bytes(buf.data(), bufsize);
}
}
/// Initialization/Shutdown Functions
error_code cellMicInit()
{
cellMic.notice("cellMicInit()");
auto& mic_thr = g_fxo->get<mic_thread>();
const std::lock_guard lock(mic_thr.mutex);
if (mic_thr.init)
return CELL_MICIN_ERROR_ALREADY_INIT;
mic_thr.load_config_and_init();
mic_thr.init = 1;
return CELL_OK;
}
error_code cellMicEnd()
{
cellMic.notice("cellMicEnd()");
auto& mic_thr = g_fxo->get<mic_thread>();
const std::lock_guard lock(mic_thr.mutex);
if (!mic_thr.init)
return CELL_MICIN_ERROR_NOT_INIT;
// TODO
mic_thr.init = 0;
mic_thr.event_queue_key = 0;
mic_thr.event_queue_source = 0;
return CELL_OK;
}
/// Open/Close Microphone Functions
error_code cellMicOpenEx(s32 dev_num, s32 rawSampleRate, s32 rawChannel, s32 DSPSampleRate, s32 bufferSizeMS, u8 signalType)
{
cellMic.notice("cellMicOpenEx(dev_num=%d, rawSampleRate=%d, rawChannel=%d, DSPSampleRate=%d, bufferSizeMS=%d, signalType=0x%x)",
dev_num, rawSampleRate, rawChannel, DSPSampleRate, bufferSizeMS, signalType);
auto& mic_thr = g_fxo->get<mic_thread>();
const std::lock_guard lock(mic_thr.mutex);
if (!mic_thr.init)
return CELL_MICIN_ERROR_NOT_INIT;
if (!mic_thr.check_device(dev_num))
return CELL_MICIN_ERROR_DEVICE_NOT_FOUND;
microphone_device& device = ::at32(mic_thr.mic_list, dev_num);
if (device.is_opened())
return CELL_MICIN_ERROR_ALREADY_OPEN;
// TODO: bufferSizeMS
return device.open_microphone(signalType, DSPSampleRate, rawSampleRate, rawChannel);
}
error_code cellMicOpen(s32 dev_num, s32 sampleRate)
{
cellMic.trace("cellMicOpen(dev_num=%d sampleRate=%d)", dev_num, sampleRate);
return cellMicOpenEx(dev_num, sampleRate, 1, sampleRate, 0x80, CELLMIC_SIGTYPE_DSP);
}
error_code cellMicOpenRaw(s32 dev_num, s32 sampleRate, s32 maxChannels)
{
cellMic.trace("cellMicOpenRaw(dev_num=%d, sampleRate=%d, maxChannels=%d)", dev_num, sampleRate, maxChannels);
return cellMicOpenEx(dev_num, sampleRate, maxChannels, sampleRate, 0x80, CELLMIC_SIGTYPE_RAW);
}
s32 cellMicIsOpen(s32 dev_num)
{
cellMic.trace("cellMicIsOpen(dev_num=%d)", dev_num);
auto& mic_thr = g_fxo->get<mic_thread>();
const std::lock_guard lock(mic_thr.mutex);
if (!mic_thr.init)
return false;
if (!mic_thr.check_device(dev_num))
return false;
microphone_device& device = ::at32(mic_thr.mic_list, dev_num);
return device.is_opened();
}
s32 cellMicIsAttached(s32 dev_num)
{
cellMic.trace("cellMicIsAttached(dev_num=%d)", dev_num);
// TODO
return 1;
}
error_code cellMicClose(s32 dev_num)
{
cellMic.trace("cellMicClose(dev_num=%d)", dev_num);
auto& mic_thr = g_fxo->get<mic_thread>();
const std::lock_guard lock(mic_thr.mutex);
if (!mic_thr.init)
return CELL_MICIN_ERROR_NOT_INIT;
if (!mic_thr.check_device(dev_num))
return CELL_MICIN_ERROR_DEVICE_NOT_FOUND;
microphone_device& device = ::at32(mic_thr.mic_list, dev_num);
if (!device.is_opened())
return CELL_MICIN_ERROR_NOT_OPEN;
return device.close_microphone();
}
/// Starting/Stopping Microphone Functions
error_code cellMicStartEx(s32 dev_num, u32 iflags)
{
cellMic.todo("cellMicStartEx(dev_num=%d, iflags=%d)", dev_num, iflags);
if ((iflags & 0xfffffffc) != 0) // iflags > 3
return CELL_MICIN_ERROR_PARAM;
auto& mic_thr = g_fxo->get<mic_thread>();
const std::lock_guard lock(mic_thr.mutex);
if (!mic_thr.init)
return CELL_MICIN_ERROR_NOT_INIT;
if (!mic_thr.check_device(dev_num))
return CELL_MICIN_ERROR_DEVICE_NOT_FOUND;
microphone_device& device = ::at32(mic_thr.mic_list, dev_num);
if (!device.is_opened())
return CELL_MICIN_ERROR_NOT_OPEN;
// TODO: flags
cellMic.success("We're getting started mate!");
return device.start_microphone();
}
error_code cellMicStart(s32 dev_num)
{
cellMic.trace("cellMicStart(dev_num=%d)", dev_num);
return cellMicStartEx(dev_num, 0);
}
error_code cellMicStop(s32 dev_num)
{
cellMic.trace("cellMicStop(dev_num=%d)", dev_num);
auto& mic_thr = g_fxo->get<mic_thread>();
const std::lock_guard lock(mic_thr.mutex);
if (!mic_thr.init)
return CELL_MICIN_ERROR_NOT_INIT;
if (!mic_thr.check_device(dev_num))
return CELL_MICIN_ERROR_DEVICE_NOT_FOUND;
microphone_device& device = ::at32(mic_thr.mic_list, dev_num);
if (!device.is_opened())
return CELL_MICIN_ERROR_NOT_OPEN;
if (device.is_started())
{
return device.stop_microphone();
}
return CELL_OK;
}
/// Microphone Attributes/States Functions
error_code cellMicGetDeviceAttr(s32 dev_num, CellMicDeviceAttr deviceAttributes, vm::ptr<s32> arg1, vm::ptr<s32> arg2)
{
cellMic.trace("cellMicGetDeviceAttr(dev_num=%d, deviceAttribute=%d, arg1=*0x%x, arg2=*0x%x)", dev_num, +deviceAttributes, arg1, arg2);
auto& mic_thr = g_fxo->get<mic_thread>();
const std::lock_guard lock(mic_thr.mutex);
if (!mic_thr.init)
return CELL_MICIN_ERROR_NOT_INIT;
if (dev_num < 0)
return CELL_MICIN_ERROR_PARAM;
if (!mic_thr.check_device(dev_num))
return CELL_MICIN_ERROR_DEVICE_NOT_FOUND;
microphone_device& device = ::at32(mic_thr.mic_list, dev_num);
if (arg1)
{
switch (deviceAttributes)
{
case CELLMIC_DEVATTR_CHANVOL:
if (*arg1 > 2 || !arg2)
return CELL_MICIN_ERROR_PARAM;
if (*arg1 == 0)
{
// Calculate average volume of the channels
*arg2 = std::accumulate(device.attr_chanvol.begin(), device.attr_chanvol.end(), 0u) / ::size32(device.attr_chanvol);
}
else
{
*arg2 = ::at32(device.attr_chanvol, *arg1 - 1);
}
break;
case CELLMIC_DEVATTR_LED: *arg1 = device.attr_led; break;
case CELLMIC_DEVATTR_GAIN: *arg1 = device.attr_gain; break;
case CELLMIC_DEVATTR_VOLUME: *arg1 = device.attr_volume; break;
case CELLMIC_DEVATTR_AGC: *arg1 = device.attr_agc; break;
case CELLMIC_DEVATTR_DSPTYPE: *arg1 = device.attr_dsptype; break;
default: return CELL_MICIN_ERROR_PARAM;
}
}
return CELL_OK;
}
error_code cellMicSetDeviceAttr(s32 dev_num, CellMicDeviceAttr deviceAttributes, u32 arg1, u32 arg2)
{
cellMic.trace("cellMicSetDeviceAttr(dev_num=%d, deviceAttributes=%d, arg1=%d, arg2=%d)", dev_num, +deviceAttributes, arg1, arg2);
auto& mic_thr = g_fxo->get<mic_thread>();
const std::lock_guard lock(mic_thr.mutex);
if (!mic_thr.init)
return CELL_MICIN_ERROR_NOT_INIT;
if (!mic_thr.check_device(dev_num))
return CELL_MICIN_ERROR_DEVICE_NOT_FOUND;
microphone_device& device = ::at32(mic_thr.mic_list, dev_num);
switch (deviceAttributes)
{
case CELLMIC_DEVATTR_CHANVOL:
// Used by SingStar to set the volume of each mic
if (arg1 > 2)
return CELL_MICIN_ERROR_PARAM;
if (arg1 == 0)
{
device.attr_chanvol.fill(arg2);
}
else
{
::at32(device.attr_chanvol, arg1 - 1) = arg2;
}
break;
case CELLMIC_DEVATTR_LED: device.attr_led = arg1; break;
case CELLMIC_DEVATTR_GAIN: device.attr_gain = arg1; break;
case CELLMIC_DEVATTR_VOLUME: device.attr_volume = arg1; break;
case CELLMIC_DEVATTR_AGC: device.attr_agc = arg1; break;
case CELLMIC_DEVATTR_DSPTYPE: device.attr_dsptype = arg1; break;
default: return CELL_MICIN_ERROR_PARAM;
}
return CELL_OK;
}
error_code cellMicGetSignalAttr(s32 dev_num, CellMicSignalAttr sig_attrib, vm::ptr<void> value)
{
cellMic.todo("cellMicGetSignalAttr(dev_num=%d, sig_attrib=%d, value=*0x%x)", dev_num, +sig_attrib, value);
if (!value)
return CELL_MICIN_ERROR_PARAM;
auto& mic_thr = g_fxo->get<mic_thread>();
const std::lock_guard lock(mic_thr.mutex);
if (!mic_thr.init)
return CELL_MICIN_ERROR_NOT_INIT;
if (!mic_thr.check_device(dev_num))
return CELL_MICIN_ERROR_DEVICE_NOT_FOUND;
microphone_device& device = ::at32(mic_thr.mic_list, dev_num);
if (!device.is_opened())
return CELL_MICIN_ERROR_NOT_OPEN;
// TODO
return CELL_OK;
}
error_code cellMicSetSignalAttr(s32 dev_num, CellMicSignalAttr sig_attrib, vm::ptr<void> value)
{
cellMic.todo("cellMicSetSignalAttr(dev_num=%d, sig_attrib=%d, value=*0x%x)", dev_num, +sig_attrib, value);
if (!value)
return CELL_MICIN_ERROR_PARAM;
auto& mic_thr = g_fxo->get<mic_thread>();
const std::lock_guard lock(mic_thr.mutex);
if (!mic_thr.init)
return CELL_MICIN_ERROR_NOT_INIT;
if (!mic_thr.check_device(dev_num))
return CELL_MICIN_ERROR_DEVICE_NOT_FOUND;
microphone_device& device = ::at32(mic_thr.mic_list, dev_num);
if (!device.is_opened())
return CELL_MICIN_ERROR_NOT_OPEN;
// TODO
return CELL_OK;
}
error_code cellMicGetSignalState(s32 dev_num, CellMicSignalState sig_state, vm::ptr<void> value)
{
cellMic.trace("cellMicGetSignalState(dev_num=%d, sig_state=%d, value=*0x%x)", dev_num, +sig_state, value);
if (!value)
return CELL_MICIN_ERROR_PARAM;
auto& mic_thr = g_fxo->get<mic_thread>();
const std::lock_guard lock(mic_thr.mutex);
if (!mic_thr.init)
return CELL_MICIN_ERROR_NOT_INIT;
if (!mic_thr.check_device(dev_num))
return CELL_MICIN_ERROR_DEVICE_NOT_FOUND;
microphone_device& device = ::at32(mic_thr.mic_list, dev_num);
if (!device.is_opened())
return CELL_MICIN_ERROR_NOT_OPEN;
be_t<u32>* ival = vm::_ptr<u32>(value.addr());
be_t<f32>* fval = vm::_ptr<f32>(value.addr());
// TODO
switch (sig_state)
{
case CELLMIC_SIGSTATE_LOCTALK:
*ival = 9; // Someone is probably talking (0 to 10)
break;
case CELLMIC_SIGSTATE_FARTALK:
*ival = 1; // The speakers are probably off (0 to 10)
break;
case CELLMIC_SIGSTATE_NSR:
*fval = 0.0f; // No noise reduction
break;
case CELLMIC_SIGSTATE_AGC:
*fval = 1.0f; // No gain applied
break;
case CELLMIC_SIGSTATE_MICENG:
*fval = 40.0f; // 40 decibels
break;
case CELLMIC_SIGSTATE_SPKENG:
*fval = 10.0f; // 10 decibels
break;
default:
return CELL_MICIN_ERROR_PARAM;
}
return CELL_OK;
}
error_code cellMicGetFormatEx(s32 dev_num, vm::ptr<CellMicInputFormatI> format, /*CellMicSignalType*/u32 type)
{
cellMic.trace("cellMicGetFormatEx(dev_num=%d, format=*0x%x, type=0x%x)", dev_num, format, type);
if (!format)
return CELL_MICIN_ERROR_PARAM;
auto& mic_thr = g_fxo->get<mic_thread>();
const std::lock_guard lock(mic_thr.mutex);
if (!mic_thr.init)
return CELL_MICIN_ERROR_NOT_INIT;
if (!mic_thr.check_device(dev_num))
return CELL_MICIN_ERROR_DEVICE_NOT_FOUND;
microphone_device& device = ::at32(mic_thr.mic_list, dev_num);
if (!device.is_opened())
return CELL_MICIN_ERROR_NOT_OPEN;
// TODO: type
format->subframeSize = device.get_bit_resolution() / 8; // Probably?
format->bitResolution = device.get_bit_resolution();
format->sampleRate = device.get_raw_samplingrate();
format->channelNum = device.get_num_channels();
format->dataType = device.get_datatype();
return CELL_OK;
}
error_code cellMicGetFormat(s32 dev_num, vm::ptr<CellMicInputFormatI> format)
{
cellMic.todo("cellMicGetFormat(dev_num=%d, format=*0x%x)", dev_num, format);
return cellMicGetFormatEx(dev_num, format, CELLMIC_SIGTYPE_DSP);
}
error_code cellMicGetFormatRaw(s32 dev_num, vm::ptr<CellMicInputFormatI> format)
{
cellMic.trace("cellMicGetFormatRaw(dev_num=%d, format=0x%x)", dev_num, format);
return cellMicGetFormatEx(dev_num, format, CELLMIC_SIGTYPE_RAW);
}
error_code cellMicGetFormatAux(s32 dev_num, vm::ptr<CellMicInputFormatI> format)
{
cellMic.todo("cellMicGetFormatAux(dev_num=%d, format=0x%x)", dev_num, format);
return cellMicGetFormatEx(dev_num, format, CELLMIC_SIGTYPE_AUX);
}
error_code cellMicGetFormatDsp(s32 dev_num, vm::ptr<CellMicInputFormatI> format)
{
cellMic.todo("cellMicGetFormatDsp(dev_num=%d, format=0x%x)", dev_num, format);
return cellMicGetFormatEx(dev_num, format, CELLMIC_SIGTYPE_DSP);
}
/// Event Queue Functions
error_code cellMicSetNotifyEventQueue(u64 key)
{
cellMic.todo("cellMicSetNotifyEventQueue(key=0x%llx)", key);
auto& mic_thr = g_fxo->get<mic_thread>();
const std::lock_guard lock(mic_thr.mutex);
if (!mic_thr.init)
return CELL_MICIN_ERROR_NOT_INIT;
// default mic queue size = 4
auto mic_queue = lv2_event_queue::find(key);
if (!mic_queue)
return CELL_MICIN_ERROR_EVENT_QUEUE;
mic_thr.event_queue_key = key;
// TODO: Properly generate/handle mic events
for (usz i = 0; i < mic_thr.mic_list.size(); i++)
{
microphone_device& device = ::at32(mic_thr.mic_list, i);
if (device.is_registered())
{
mic_queue->send(0, CELLMIC_ATTACH, i, 0);
}
}
return CELL_OK;
}
error_code cellMicSetNotifyEventQueue2(u64 key, u64 source, u64 flag)
{
cellMic.todo("cellMicSetNotifyEventQueue2(key=0x%llx, source=0x%llx, flag=0x%llx", key, source, flag);
auto& mic_thr = g_fxo->get<mic_thread>();
const std::lock_guard lock(mic_thr.mutex);
if (!mic_thr.init)
return CELL_MICIN_ERROR_NOT_INIT;
// default mic queue size = 4
auto mic_queue = lv2_event_queue::find(key);
if (!mic_queue)
return CELL_MICIN_ERROR_EVENT_QUEUE;
mic_thr.event_queue_key = key;
mic_thr.event_queue_source = source;
// TODO: Properly generate/handle mic events
for (usz i = 0; i < mic_thr.mic_list.size(); i++)
{
microphone_device& device = ::at32(mic_thr.mic_list, i);
if (device.is_registered())
{
mic_queue->send(source, CELLMIC_ATTACH, i, 0);
}
}
return CELL_OK;
}
error_code cellMicRemoveNotifyEventQueue(u64 key)
{
cellMic.warning("cellMicRemoveNotifyEventQueue(key=0x%llx)", key);
auto& mic_thr = g_fxo->get<mic_thread>();
const std::lock_guard lock(mic_thr.mutex);
if (!mic_thr.init)
return CELL_MICIN_ERROR_NOT_INIT;
mic_thr.event_queue_key = 0;
mic_thr.event_queue_source = 0;
return CELL_OK;
}
/// Reading Functions
error_code cell_mic_read(s32 dev_num, vm::ptr<void> data, s32 max_bytes, /*CellMicSignalType*/u32 type)
{
auto& mic_thr = g_fxo->get<mic_thread>();
const std::lock_guard lock(mic_thr.mutex);
if (!mic_thr.init)
return CELL_MICIN_ERROR_NOT_INIT;
if (!mic_thr.check_device(dev_num))
return CELL_MICIN_ERROR_DEVICE_NOT_FOUND;
microphone_device& device = ::at32(mic_thr.mic_list, dev_num);
if (!device.is_opened() || !(device.get_signal_types() & type))
return CELL_MICIN_ERROR_NOT_OPEN;
if (!data)
return not_an_error(0);
switch (type)
{
case CELLMIC_SIGTYPE_DSP: return not_an_error(device.read_dsp(vm::_ptr<u8>(data.addr()), max_bytes));
case CELLMIC_SIGTYPE_AUX: return not_an_error(0); // TODO
case CELLMIC_SIGTYPE_RAW: return not_an_error(device.read_raw(vm::_ptr<u8>(data.addr()), max_bytes));
default:
fmt::throw_exception("Invalid CELLMIC_SIGTYPE %d", type);
}
return not_an_error(0);
}
error_code cellMicReadRaw(s32 dev_num, vm::ptr<void> data, s32 max_bytes)
{
cellMic.trace("cellMicReadRaw(dev_num=%d, data=0x%x, maxBytes=%d)", dev_num, data, max_bytes);
return cell_mic_read(dev_num, data, max_bytes, CELLMIC_SIGTYPE_RAW);
}
error_code cellMicRead(s32 dev_num, vm::ptr<void> data, u32 max_bytes)
{
cellMic.warning("cellMicRead(dev_num=%d, data=0x%x, maxBytes=0x%x)", dev_num, data, max_bytes);
return cell_mic_read(dev_num, data, max_bytes, CELLMIC_SIGTYPE_DSP);
}
error_code cellMicReadAux(s32 dev_num, vm::ptr<void> data, s32 max_bytes)
{
cellMic.todo("cellMicReadAux(dev_num=%d, data=0x%x, max_bytes=0x%x)", dev_num, data, max_bytes);
return cell_mic_read(dev_num, data, max_bytes, CELLMIC_SIGTYPE_AUX);
}
error_code cellMicReadDsp(s32 dev_num, vm::ptr<void> data, s32 max_bytes)
{
cellMic.warning("cellMicReadDsp(dev_num=%d, data=0x%x, max_bytes=0x%x)", dev_num, data, max_bytes);
return cell_mic_read(dev_num, data, max_bytes, CELLMIC_SIGTYPE_DSP);
}
/// Unimplemented Functions
error_code cellMicReset(s32 dev_num)
{
cellMic.todo("cellMicReset(dev_num=%d)", dev_num);
auto& mic_thr = g_fxo->get<mic_thread>();
const std::lock_guard lock(mic_thr.mutex);
if (!mic_thr.init)
return CELL_MICIN_ERROR_NOT_INIT;
if (!mic_thr.check_device(dev_num))
return CELL_MICIN_ERROR_DEVICE_NOT_FOUND;
microphone_device& device = ::at32(mic_thr.mic_list, dev_num);
if (!device.is_opened())
return CELL_MICIN_ERROR_NOT_OPEN;
// TODO
return CELL_OK;
}
error_code cellMicGetDeviceGUID(s32 dev_num, vm::ptr<u32> ptr_guid)
{
cellMic.todo("cellMicGetDeviceGUID(dev_num=%d ptr_guid=*0x%x)", dev_num, ptr_guid);
if (!ptr_guid)
return CELL_MICIN_ERROR_PARAM;
*ptr_guid = 0xffffffff;
auto& mic_thr = g_fxo->get<mic_thread>();
const std::lock_guard lock(mic_thr.mutex);
if (!mic_thr.init)
return CELL_MICIN_ERROR_NOT_INIT;
// TODO
return CELL_OK;
}
error_code cellMicGetDeviceIdentifier(s32 dev_num, vm::ptr<u32> ptr_id)
{
cellMic.todo("cellMicGetDeviceIdentifier(dev_num=%d, ptr_id=*0x%x)", dev_num, ptr_id);
if (ptr_id)
*ptr_id = 0x0;
auto& mic_thr = g_fxo->get<mic_thread>();
const std::lock_guard lock(mic_thr.mutex);
if (!mic_thr.init)
return CELL_MICIN_ERROR_NOT_INIT;
// TODO
return CELL_OK;
}
error_code cellMicGetType(s32 dev_num, vm::ptr<s32> ptr_type)
{
cellMic.trace("cellMicGetType(dev_num=%d, ptr_type=*0x%x)", dev_num, ptr_type);
if (!ptr_type)
return CELL_MICIN_ERROR_PARAM;
auto& mic_thr = g_fxo->get<mic_thread>();
const std::lock_guard lock(mic_thr.mutex);
if (!mic_thr.init)
return CELL_MICIN_ERROR_NOT_INIT;
// TODO: get proper type (log message is trace because of massive spam)
*ptr_type = CELLMIC_TYPE_USBAUDIO; // Needed for Guitar Hero: Warriors of Rock (BLUS30487)
return CELL_OK;
}
error_code cellMicGetStatus(s32 dev_num, vm::ptr<CellMicStatus> status)
{
cellMic.todo("cellMicGetStatus(dev_num=%d, status=*0x%x)", dev_num, status);
auto& mic_thr = g_fxo->get<mic_thread>();
const std::lock_guard lock(mic_thr.mutex);
if (!mic_thr.init)
return CELL_MICIN_ERROR_NOT_INIT;
if (dev_num < 0 || !status)
return CELL_MICIN_ERROR_PARAM;
// TODO
if (dev_num < static_cast<s32>(mic_thr.mic_list.size()))
{
const microphone_device& device = ::at32(mic_thr.mic_list, dev_num);
status->raw_samprate = device.get_raw_samplingrate();
status->dsp_samprate = device.get_raw_samplingrate();
status->isStart = device.is_started();
status->isOpen = device.is_opened();
status->dsp_volume = 5; // TODO: 0 - 5 volume
status->local_voice = 10; // TODO: 0 - 10 confidence
status->remote_voice = 0; // TODO: 0 - 10 confidence
status->mic_energy = 60; // TODO: Db
status->spk_energy = 60; // TODO: Db
}
return CELL_OK;
}
error_code cellMicStopEx()
{
cellMic.fatal("cellMicStopEx: unexpected function");
return CELL_OK;
}
error_code cellMicSysShareClose()
{
UNIMPLEMENTED_FUNC(cellMic);
return CELL_OK;
}
error_code cellMicSetMultiMicNotifyEventQueue()
{
UNIMPLEMENTED_FUNC(cellMic);
return CELL_OK;
}
error_code cellMicSysShareStop()
{
UNIMPLEMENTED_FUNC(cellMic);
return CELL_OK;
}
error_code cellMicSysShareOpen()
{
UNIMPLEMENTED_FUNC(cellMic);
return CELL_OK;
}
error_code cellMicCommand()
{
UNIMPLEMENTED_FUNC(cellMic);
return CELL_OK;
}
error_code cellMicSysShareStart()
{
UNIMPLEMENTED_FUNC(cellMic);
return CELL_OK;
}
error_code cellMicSysShareInit()
{
UNIMPLEMENTED_FUNC(cellMic);
return CELL_OK;
}
error_code cellMicSysShareEnd()
{
UNIMPLEMENTED_FUNC(cellMic);
return CELL_OK;
}
DECLARE(ppu_module_manager::cellMic)("cellMic", []()
{
REG_FUNC(cellMic, cellMicInit);
REG_FUNC(cellMic, cellMicEnd);
REG_FUNC(cellMic, cellMicOpen);
REG_FUNC(cellMic, cellMicClose);
REG_FUNC(cellMic, cellMicGetDeviceGUID);
REG_FUNC(cellMic, cellMicGetType);
REG_FUNC(cellMic, cellMicIsAttached);
REG_FUNC(cellMic, cellMicIsOpen);
REG_FUNC(cellMic, cellMicGetDeviceAttr);
REG_FUNC(cellMic, cellMicSetDeviceAttr);
REG_FUNC(cellMic, cellMicGetSignalAttr);
REG_FUNC(cellMic, cellMicSetSignalAttr);
REG_FUNC(cellMic, cellMicGetSignalState);
REG_FUNC(cellMic, cellMicStart);
REG_FUNC(cellMic, cellMicRead);
REG_FUNC(cellMic, cellMicStop);
REG_FUNC(cellMic, cellMicReset);
REG_FUNC(cellMic, cellMicSetNotifyEventQueue);
REG_FUNC(cellMic, cellMicSetNotifyEventQueue2);
REG_FUNC(cellMic, cellMicRemoveNotifyEventQueue);
REG_FUNC(cellMic, cellMicOpenEx);
REG_FUNC(cellMic, cellMicStartEx);
REG_FUNC(cellMic, cellMicGetFormatRaw);
REG_FUNC(cellMic, cellMicGetFormatAux);
REG_FUNC(cellMic, cellMicGetFormatDsp);
REG_FUNC(cellMic, cellMicOpenRaw);
REG_FUNC(cellMic, cellMicReadRaw);
REG_FUNC(cellMic, cellMicReadAux);
REG_FUNC(cellMic, cellMicReadDsp);
REG_FUNC(cellMic, cellMicGetStatus);
REG_FUNC(cellMic, cellMicStopEx); // this function shouldn't exist
REG_FUNC(cellMic, cellMicSysShareClose);
REG_FUNC(cellMic, cellMicGetFormat);
REG_FUNC(cellMic, cellMicSetMultiMicNotifyEventQueue);
REG_FUNC(cellMic, cellMicGetFormatEx);
REG_FUNC(cellMic, cellMicSysShareStop);
REG_FUNC(cellMic, cellMicSysShareOpen);
REG_FUNC(cellMic, cellMicCommand);
REG_FUNC(cellMic, cellMicSysShareStart);
REG_FUNC(cellMic, cellMicSysShareInit);
REG_FUNC(cellMic, cellMicSysShareEnd);
REG_FUNC(cellMic, cellMicGetDeviceIdentifier);
});
| 38,644
|
C++
|
.cpp
| 1,209
| 29.387924
| 139
| 0.718074
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
5,239
|
cellHttpUtil.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellHttpUtil.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
#include "Utilities/LUrlParser.h"
#include "cellHttpUtil.h"
#ifdef _WIN32
#include <windows.h>
#include <codecvt>
#ifdef _MSC_VER
#pragma comment(lib, "Winhttp.lib")
#endif
#endif
LOG_CHANNEL(cellHttpUtil);
template <>
void fmt_class_string<CellHttpUtilError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_HTTP_UTIL_ERROR_NO_MEMORY);
STR_CASE(CELL_HTTP_UTIL_ERROR_NO_BUFFER);
STR_CASE(CELL_HTTP_UTIL_ERROR_NO_STRING);
STR_CASE(CELL_HTTP_UTIL_ERROR_INSUFFICIENT);
STR_CASE(CELL_HTTP_UTIL_ERROR_INVALID_URI);
STR_CASE(CELL_HTTP_UTIL_ERROR_INVALID_HEADER);
STR_CASE(CELL_HTTP_UTIL_ERROR_INVALID_REQUEST);
STR_CASE(CELL_HTTP_UTIL_ERROR_INVALID_RESPONSE);
STR_CASE(CELL_HTTP_UTIL_ERROR_INVALID_LENGTH);
STR_CASE(CELL_HTTP_UTIL_ERROR_INVALID_CHARACTER);
}
return unknown;
});
}
error_code cellHttpUtilParseUri(vm::ptr<CellHttpUri> uri, vm::cptr<char> str, vm::ptr<void> pool, u32 size, vm::ptr<u32> required)
{
cellHttpUtil.trace("cellHttpUtilParseUri(uri=*0x%x, str=%s, pool=*0x%x, size=%d, required=*0x%x)", uri, str, pool, size, required);
if (!str)
{
return CELL_HTTP_UTIL_ERROR_NO_STRING;
}
if (!pool || !uri)
{
if (!required)
{
return CELL_HTTP_UTIL_ERROR_NO_BUFFER;
}
}
LUrlParser::clParseURL URL = LUrlParser::clParseURL::ParseURL(str.get_ptr());
if ( URL.IsValid() )
{
std::string scheme = URL.m_Scheme;
std::string host = URL.m_Host;
std::string path = URL.m_Path;
std::string username = URL.m_UserName;
std::string password = URL.m_Password;
u32 schemeOffset = 0;
u32 hostOffset = ::size32(scheme) + 1;
u32 pathOffset = hostOffset + ::size32(host) + 1;
u32 usernameOffset = pathOffset + ::size32(path) + 1;
u32 passwordOffset = usernameOffset + ::size32(username) + 1;
u32 totalSize = passwordOffset + ::size32(password) + 1;
//called twice, first to setup pool, then to populate.
if (!uri)
{
*required = totalSize;
return CELL_OK;
}
else
{
std::memcpy(vm::base(pool.addr() + schemeOffset), scheme.c_str(), scheme.length() + 1);
std::memcpy(vm::base(pool.addr() + hostOffset), host.c_str(), host.length() + 1);
std::memcpy(vm::base(pool.addr() + pathOffset), path.c_str(), path.length() + 1);
std::memcpy(vm::base(pool.addr() + usernameOffset), username.c_str(), username.length() + 1);
std::memcpy(vm::base(pool.addr() + passwordOffset), password.c_str(), password.length() + 1);
uri->scheme.set(pool.addr() + schemeOffset);
uri->hostname.set(pool.addr() + hostOffset);
uri->path.set(pool.addr() + pathOffset);
uri->username.set(pool.addr() + usernameOffset);
uri->password.set(pool.addr() + passwordOffset);
if (!URL.m_Port.empty())
{
int port = stoi(URL.m_Port);
uri->port = port;
}
else
{
uri->port = 80;
}
return CELL_OK;
}
}
else
{
std::string parseError;
switch(URL.m_ErrorCode)
{
case LUrlParser::LUrlParserError_Ok:
parseError = "No error, URL was parsed fine";
break;
case LUrlParser::LUrlParserError_Uninitialized:
parseError = "Error, LUrlParser is uninitialized";
break;
case LUrlParser::LUrlParserError_NoUrlCharacter:
parseError = "Error, the URL has invalid characters";
break;
case LUrlParser::LUrlParserError_InvalidSchemeName:
parseError = "Error, the URL has an invalid scheme";
break;
case LUrlParser::LUrlParserError_NoDoubleSlash:
parseError = "Error, the URL did not contain a double slash";
break;
case LUrlParser::LUrlParserError_NoAtSign:
parseError = "Error, the URL did not contain an @ sign";
break;
case LUrlParser::LUrlParserError_UnexpectedEndOfLine:
parseError = "Error, unexpectedly got the end of the line";
break;
case LUrlParser::LUrlParserError_NoSlash:
parseError = "Error, URI didn't contain a slash";
break;
default:
parseError = "Error, unknown error #" + std::to_string(static_cast<int>(URL.m_ErrorCode));
break;
}
cellHttpUtil.error("%s, while parsing URI, %s.", parseError, str.get_ptr());
return -1;
}
}
error_code cellHttpUtilParseUriPath(vm::ptr<CellHttpUriPath> path, vm::cptr<char> str, vm::ptr<void> pool, u32 size, vm::ptr<u32> required)
{
cellHttpUtil.todo("cellHttpUtilParseUriPath(path=*0x%x, str=%s, pool=*0x%x, size=%d, required=*0x%x)", path, str, pool, size, required);
if (!str)
{
return CELL_HTTP_UTIL_ERROR_NO_STRING;
}
if (!pool || !path)
{
if (!required)
{
return CELL_HTTP_UTIL_ERROR_NO_BUFFER;
}
}
return CELL_OK;
}
error_code cellHttpUtilParseProxy(vm::ptr<CellHttpUri> uri, vm::cptr<char> str, vm::ptr<void> pool, u32 size, vm::ptr<u32> required)
{
cellHttpUtil.todo("cellHttpUtilParseProxy(uri=*0x%x, str=%s, pool=*0x%x, size=%d, required=*0x%x)", uri, str, pool, size, required);
if (!str)
{
return CELL_HTTP_UTIL_ERROR_NO_STRING;
}
if (!pool || !uri)
{
if (!required)
{
return CELL_HTTP_UTIL_ERROR_NO_BUFFER;
}
}
return CELL_OK;
}
error_code cellHttpUtilParseStatusLine(vm::ptr<CellHttpStatusLine> resp, vm::cptr<char> str, u32 len, vm::ptr<void> pool, u32 size, vm::ptr<u32> required, vm::ptr<u32> parsedLength)
{
cellHttpUtil.todo("cellHttpUtilParseStatusLine(resp=*0x%x, str=%s, len=%d, pool=*0x%x, size=%d, required=*0x%x, parsedLength=*0x%x)", resp, str, len, pool, size, required, parsedLength);
if (!str)
{
return CELL_HTTP_UTIL_ERROR_NO_STRING;
}
if (!pool || !resp)
{
if (!required)
{
return CELL_HTTP_UTIL_ERROR_NO_BUFFER;
}
}
return CELL_OK;
}
error_code cellHttpUtilParseHeader(vm::ptr<CellHttpHeader> header, vm::cptr<char> str, u32 len, vm::ptr<void> pool, u32 size, vm::ptr<u32> required, vm::ptr<u32> parsedLength)
{
cellHttpUtil.todo("cellHttpUtilParseHeader(header=*0x%x, str=%s, len=%d, pool=*0x%x, size=%d, required=*0x%x, parsedLength=*0x%x)", header, str, len, pool, size, required, parsedLength);
if (!str)
{
return CELL_HTTP_UTIL_ERROR_NO_STRING;
}
if (!pool || !header)
{
if (!required)
{
return CELL_HTTP_UTIL_ERROR_NO_BUFFER;
}
}
return CELL_OK;
}
error_code cellHttpUtilBuildRequestLine(vm::cptr<CellHttpRequestLine> req, vm::ptr<char> buf, u32 len, vm::ptr<u32> required)
{
cellHttpUtil.notice("cellHttpUtilBuildRequestLine(req=*0x%x, buf=*0x%x, len=%d, required=*0x%x)", req, buf, len, required);
if (!req || !req->method || !req->path || !req->protocol)
{
return CELL_HTTP_UTIL_ERROR_INVALID_REQUEST;
}
std::string path = fmt::format("%s", req->path);
if (path.empty())
{
path += '/';
}
// TODO: are the numbers properly formatted ?
const std::string result = fmt::format("%s %s %s/%d.%d\r\n", req->method, path, req->protocol, req->majorVersion, req->minorVersion);
if (buf)
{
if (len < result.size())
{
return CELL_HTTP_UTIL_ERROR_INSUFFICIENT;
}
std::memcpy(buf.get_ptr(), result.c_str(), result.size());
}
if (required)
{
*required = ::narrow<u32>(result.size());
}
return CELL_OK;
}
error_code cellHttpUtilBuildHeader(vm::cptr<CellHttpHeader> header, vm::ptr<char> buf, u32 len, vm::ptr<u32> required)
{
cellHttpUtil.notice("cellHttpUtilBuildHeader(header=*0x%x, buf=*0x%x, len=%d, required=*0x%x)", header, buf, len, required);
if (!header || !header->name)
{
return CELL_HTTP_UTIL_ERROR_INVALID_HEADER;
}
const std::string result = fmt::format("%s: %s\r\n", header->name, header->value);
if (buf)
{
if (len < result.size())
{
return CELL_HTTP_UTIL_ERROR_INSUFFICIENT;
}
std::memcpy(buf.get_ptr(), result.c_str(), result.size());
}
if (required)
{
*required = ::narrow<u32>(result.size());
}
return CELL_OK;
}
error_code cellHttpUtilBuildUri(vm::cptr<CellHttpUri> uri, vm::ptr<char> buf, u32 len, vm::ptr<u32> required, s32 flags)
{
cellHttpUtil.todo("cellHttpUtilBuildUri(uri=*0x%x, buf=*0x%x, len=%d, required=*0x%x, flags=%d)", uri, buf, len, required, flags);
if (!uri || !uri->hostname)
{
return CELL_HTTP_UTIL_ERROR_INVALID_URI;
}
std::string result;
if (!(flags & CELL_HTTP_UTIL_URI_FLAG_NO_SCHEME))
{
if (uri->scheme && uri->scheme[0])
{
result = fmt::format("%s", uri->scheme);
}
else if (uri->port == 443u)
{
result = "https"; // TODO: confirm
}
else
{
result = "http"; // TODO: confirm
}
fmt::append(result, "://");
}
if (!(flags & CELL_HTTP_UTIL_URI_FLAG_NO_CREDENTIALS) && uri->username && uri->username[0])
{
fmt::append(result, "%s", uri->username);
if (!(flags & CELL_HTTP_UTIL_URI_FLAG_NO_PASSWORD) && uri->password && uri->password[0])
{
fmt::append(result, ":%s", uri->password);
}
fmt::append(result, "@");
}
fmt::append(result, "%s", uri->hostname);
if (true) // TODO: there seems to be a case where the port isn't added
{
fmt::append(result, ":%d", uri->port);
}
if (!(flags & CELL_HTTP_UTIL_URI_FLAG_NO_PATH) && uri->path && uri->path[0])
{
fmt::append(result, "%s", uri->path);
}
const u32 size_needed = ::narrow<u32>(result.size() + 1); // Including '\0'
if (buf)
{
if (len < size_needed)
{
return CELL_HTTP_UTIL_ERROR_INSUFFICIENT;
}
std::memcpy(buf.get_ptr(), result.c_str(), size_needed);
}
if (required)
{
*required = size_needed;
}
return CELL_OK;
}
error_code cellHttpUtilCopyUri(vm::ptr<CellHttpUri> dest, vm::cptr<CellHttpUri> src, vm::ptr<void> pool, u32 poolSize, vm::ptr<u32> required)
{
cellHttpUtil.todo("cellHttpUtilCopyUri(dest=*0x%x, src=*0x%x, pool=*0x%x, poolSize=%d, required=*0x%x)", dest, src, pool, poolSize, required);
if (!src)
{
return CELL_HTTP_UTIL_ERROR_NO_BUFFER;
}
if (!pool || !dest)
{
if (!required)
{
return CELL_HTTP_UTIL_ERROR_NO_BUFFER;
}
}
return CELL_OK;
}
error_code cellHttpUtilMergeUriPath(vm::ptr<CellHttpUri> uri, vm::cptr<CellHttpUri> src, vm::cptr<char> path, vm::ptr<void> pool, u32 poolSize, vm::ptr<u32> required)
{
cellHttpUtil.todo("cellHttpUtilMergeUriPath(uri=*0x%x, src=*0x%x, path=%s, pool=*0x%x, poolSize=%d, required=*0x%x)", uri, src, path, pool, poolSize, required);
if (!path)
{
return CELL_HTTP_UTIL_ERROR_NO_STRING;
}
if (!src)
{
return CELL_HTTP_UTIL_ERROR_NO_BUFFER;
}
if (!pool || !uri)
{
if (!required)
{
return CELL_HTTP_UTIL_ERROR_NO_BUFFER;
}
}
return CELL_OK;
}
error_code cellHttpUtilSweepPath(vm::ptr<char> dst, vm::cptr<char> src, u32 srcSize)
{
cellHttpUtil.todo("cellHttpUtilSweepPath(dst=*0x%x, src=%s, srcSize=%d)", dst, src, srcSize);
if (!dst || !src)
{
return CELL_HTTP_UTIL_ERROR_NO_BUFFER;
}
if (!srcSize)
{
return CELL_OK;
}
u32 pos = 0;
if (src[pos] != '/')
{
std::memcpy(dst.get_ptr(), src.get_ptr(), srcSize - 1);
dst[srcSize - 1] = '\0';
return CELL_OK;
}
// TODO
return CELL_OK;
}
error_code cellHttpUtilCopyStatusLine(vm::ptr<CellHttpStatusLine> dest, vm::cptr<CellHttpStatusLine> src, vm::ptr<void> pool, u32 poolSize, vm::ptr<u32> required)
{
cellHttpUtil.todo("cellHttpUtilCopyStatusLine(dest=*0x%x, src=*0x%x, pool=*0x%x, poolSize=%d, required=*0x%x)", dest, src, pool, poolSize, required);
if (!src)
{
return CELL_HTTP_UTIL_ERROR_NO_BUFFER;
}
if (!pool || !dest)
{
if (!required)
{
return CELL_HTTP_UTIL_ERROR_NO_BUFFER;
}
}
return CELL_OK;
}
error_code cellHttpUtilCopyHeader(vm::ptr<CellHttpHeader> dest, vm::cptr<CellHttpHeader> src, vm::ptr<void> pool, u32 poolSize, vm::ptr<u32> required)
{
cellHttpUtil.todo("cellHttpUtilCopyHeader(dest=*0x%x, src=*0x%x, pool=*0x%x, poolSize=%d, required=*0x%x)", dest, src, pool, poolSize, required);
if (!src)
{
return CELL_HTTP_UTIL_ERROR_NO_BUFFER;
}
if (!pool || !dest)
{
if (!required)
{
return CELL_HTTP_UTIL_ERROR_NO_BUFFER;
}
}
return CELL_OK;
}
error_code cellHttpUtilAppendHeaderValue(vm::ptr<CellHttpHeader> dest, vm::cptr<CellHttpHeader> src, vm::cptr<char> value, vm::ptr<void> pool, u32 poolSize, vm::ptr<u32> required)
{
cellHttpUtil.todo("cellHttpUtilAppendHeaderValue(dest=*0x%x, src=*0x%x, value=%s, pool=*0x%x, poolSize=%d, required=*0x%x)", dest, src, value, pool, poolSize, required);
if (!src)
{
return CELL_HTTP_UTIL_ERROR_NO_BUFFER;
}
if (!pool || !dest)
{
if (!required)
{
return CELL_HTTP_UTIL_ERROR_NO_BUFFER;
}
}
return CELL_OK;
}
error_code cellHttpUtilEscapeUri(vm::ptr<char> out, u32 outSize, vm::cptr<u8> in, u32 inSize, vm::ptr<u32> required)
{
cellHttpUtil.todo("cellHttpUtilEscapeUri(out=*0x%x, outSize=%d, in=*0x%x, inSize=%d, required=*0x%x)", out, outSize, in, inSize, required);
if (!in || !inSize)
{
return CELL_HTTP_UTIL_ERROR_NO_STRING;
}
if (!out && !required)
{
return CELL_HTTP_UTIL_ERROR_NO_BUFFER;
}
u32 size_needed = 0;
u32 out_pos = 0;
s32 rindex = 0;
if (const u32 end = in.addr() + inSize; end && end >= in.addr())
{
rindex = inSize;
}
for (u32 pos = 0; rindex >= 0; rindex--, pos++)
{
char c1 = in[pos];
if (false) // DAT[c1] == '\x03') // TODO
{
size_needed += 3;
if (out)
{
if (outSize < size_needed)
{
return CELL_HTTP_UTIL_ERROR_NO_MEMORY;
}
const char* chars = "0123456789ABCDEF";
out[out_pos++] = '%'; // 0x25
out[out_pos++] = chars[c1 >> 4];
out[out_pos++] = chars[c1 & 0xf];
}
}
else
{
size_needed++;
if (out)
{
if (outSize < size_needed)
{
return CELL_HTTP_UTIL_ERROR_NO_MEMORY;
}
out[out_pos++] = c1;
}
}
}
size_needed++;
if (out)
{
if (outSize < size_needed)
{
return CELL_HTTP_UTIL_ERROR_NO_MEMORY;
}
out[out_pos] = '\0';
}
if (required)
{
*required = size_needed;
}
return CELL_OK;
}
error_code cellHttpUtilUnescapeUri(vm::ptr<u8> out, u32 size, vm::cptr<char> in, vm::ptr<u32> required)
{
cellHttpUtil.todo("cellHttpUtilUnescapeUri(out=*0x%x, size=%d, in=*0x%x, required=*0x%x)", out, size, in, required);
if (!in)
{
return CELL_HTTP_UTIL_ERROR_NO_STRING;
}
if (!out && !required)
{
return CELL_HTTP_UTIL_ERROR_NO_BUFFER;
}
if (required)
{
*required = 0; // TODO
}
return CELL_OK;
}
error_code cellHttpUtilFormUrlEncode(vm::ptr<char> out, u32 outSize, vm::cptr<u8> in, u32 inSize, vm::ptr<u32> required)
{
cellHttpUtil.todo("cellHttpUtilFormUrlEncode(out=*0x%x, outSize=%d, in=*0x%x, inSize=%d, required=*0x%x)", out, outSize, in, inSize, required);
if (!in || !inSize)
{
return CELL_HTTP_UTIL_ERROR_NO_STRING;
}
if (!out && !required)
{
return CELL_HTTP_UTIL_ERROR_NO_BUFFER;
}
u32 size_needed = 0;
u32 out_pos = 0;
s32 rindex = 0;
if (const u32 end = in.addr() + inSize; end && end >= in.addr())
{
rindex = inSize;
}
for (u32 pos = 0; rindex >= 0; rindex--, pos++)
{
char c1 = in[pos];
if (c1 == ' ')
{
size_needed++;
if (out)
{
if (outSize < size_needed)
{
return CELL_HTTP_UTIL_ERROR_NO_MEMORY;
}
out[out_pos++] = '+';
}
}
else if (false) // DAT[c1] == '\x03') // TODO
{
size_needed += 3;
if (out)
{
if (outSize < size_needed)
{
return CELL_HTTP_UTIL_ERROR_NO_MEMORY;
}
const char* chars = "0123456789ABCDEF";
out[out_pos++] = '%'; // 0x25
out[out_pos++] = chars[c1 >> 4];
out[out_pos++] = chars[c1 & 0xf];
}
}
else
{
size_needed++;
if (out)
{
if (outSize < size_needed)
{
return CELL_HTTP_UTIL_ERROR_NO_MEMORY;
}
out[out_pos++] = c1;
}
}
}
size_needed++;
if (out)
{
if (outSize < size_needed)
{
return CELL_HTTP_UTIL_ERROR_NO_MEMORY;
}
out[out_pos++] = '\0';
}
if (required)
{
*required = size_needed;
}
return CELL_OK;
}
error_code cellHttpUtilFormUrlDecode(vm::ptr<u8> out, u32 size, vm::cptr<char> in, vm::ptr<u32> required)
{
cellHttpUtil.todo("cellHttpUtilFormUrlDecode(out=*0x%x, size=%d, in=%s, required=*0x%x)", out, size, in, required);
if (!in)
{
return CELL_HTTP_UTIL_ERROR_NO_STRING;
}
if (!out && !required)
{
return CELL_HTTP_UTIL_ERROR_NO_BUFFER;
}
u32 size_needed = 0;
u32 out_pos = 0;
for (s32 index = 0, pos = 0;; index++)
{
size_needed = index + 1;
char c1 = in[pos++];
if (!c1)
{
break;
}
if (out && (size < size_needed))
{
return CELL_HTTP_UTIL_ERROR_NO_MEMORY;
}
if (c1 == '%')
{
const char c2 = in[pos++];
const char c3 = in[pos++];
if (!c2 || !c3)
{
return CELL_HTTP_UTIL_ERROR_INVALID_URI;
}
const auto check_char = [](b8 c)
{
u32 utmp = static_cast<u32>(c);
s32 stmp = utmp - 48;
if (static_cast<u8>(c - 48) > 9)
{
stmp = utmp - 55;
if (static_cast<u8>(c + 191) > 5)
{
stmp = -1;
if (static_cast<u8>(c + 159) < 6)
{
stmp = utmp - 87;
}
}
}
return stmp;
};
const s32 tmp1 = check_char(c2);
const s32 tmp2 = check_char(c3);
if (tmp1 < 0 || tmp2 < 0)
{
return CELL_HTTP_UTIL_ERROR_INVALID_URI;
}
if (out)
{
out[out_pos++] = static_cast<char>((tmp1 & 0xffffffff) << 4) + static_cast<char>(tmp2);
}
}
else
{
if (out)
{
out[out_pos++] = (c1 == '+' ? ' ' : c1);
}
}
}
if (out)
{
if (size < size_needed)
{
return CELL_HTTP_UTIL_ERROR_NO_MEMORY;
}
out[out_pos] = '\0';
}
if (required)
{
*required = size_needed;
}
return CELL_OK;
}
error_code cellHttpUtilBase64Encoder(vm::ptr<char> out, vm::cptr<void> input, u32 len)
{
cellHttpUtil.todo("cellHttpUtilBase64Encoder(out=*0x%x, input=*0x%x, len=%d)", out, input, len);
if (!input || !len)
{
return CELL_HTTP_UTIL_ERROR_NO_STRING;
}
if (!out)
{
return CELL_HTTP_UTIL_ERROR_NO_BUFFER;
}
return CELL_OK;
}
error_code cellHttpUtilBase64Decoder(vm::ptr<char> output, vm::cptr<void> in, u32 len)
{
cellHttpUtil.todo("cellHttpUtilBase64Decoder(output=*0x%x, in=*0x%x, len=%d)", output, in, len);
if (!in)
{
return CELL_HTTP_UTIL_ERROR_NO_STRING;
}
if ((len & 3) != 0)
{
return CELL_HTTP_UTIL_ERROR_INVALID_LENGTH;
}
if (!output)
{
return CELL_HTTP_UTIL_ERROR_NO_BUFFER;
}
return CELL_OK;
}
DECLARE(ppu_module_manager::cellHttpUtil)("cellHttpUtil", []()
{
REG_FUNC(cellHttpUtil, cellHttpUtilParseUri);
REG_FUNC(cellHttpUtil, cellHttpUtilParseUriPath);
REG_FUNC(cellHttpUtil, cellHttpUtilParseProxy);
REG_FUNC(cellHttpUtil, cellHttpUtilParseStatusLine);
REG_FUNC(cellHttpUtil, cellHttpUtilParseHeader);
REG_FUNC(cellHttpUtil, cellHttpUtilBuildRequestLine);
REG_FUNC(cellHttpUtil, cellHttpUtilBuildHeader);
REG_FUNC(cellHttpUtil, cellHttpUtilBuildUri);
REG_FUNC(cellHttpUtil, cellHttpUtilCopyUri);
REG_FUNC(cellHttpUtil, cellHttpUtilMergeUriPath);
REG_FUNC(cellHttpUtil, cellHttpUtilSweepPath);
REG_FUNC(cellHttpUtil, cellHttpUtilCopyStatusLine);
REG_FUNC(cellHttpUtil, cellHttpUtilCopyHeader);
REG_FUNC(cellHttpUtil, cellHttpUtilAppendHeaderValue);
REG_FUNC(cellHttpUtil, cellHttpUtilEscapeUri);
REG_FUNC(cellHttpUtil, cellHttpUtilUnescapeUri);
REG_FUNC(cellHttpUtil, cellHttpUtilFormUrlEncode);
REG_FUNC(cellHttpUtil, cellHttpUtilFormUrlDecode);
REG_FUNC(cellHttpUtil, cellHttpUtilBase64Encoder);
REG_FUNC(cellHttpUtil, cellHttpUtilBase64Decoder);
});
| 19,046
|
C++
|
.cpp
| 698
| 24.310888
| 187
| 0.670386
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
5,240
|
sys_spu_.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/sys_spu_.cpp
|
#include "stdafx.h"
#include "Emu/VFS.h"
#include "Emu/Cell/PPUModule.h"
#include "Emu/Cell/lv2/sys_spu.h"
#include "Crypto/unself.h"
#include "Loader/ELF.h"
#include "sysPrxForUser.h"
LOG_CHANNEL(sysPrxForUser);
spu_printf_cb_t g_spu_printf_agcb;
spu_printf_cb_t g_spu_printf_dgcb;
spu_printf_cb_t g_spu_printf_atcb;
spu_printf_cb_t g_spu_printf_dtcb;
struct spu_elf_ldr
{
be_t<u32> _vtable;
vm::bptr<void> src;
be_t<u32> x8;
be_t<u64> ehdr_off;
be_t<u64> phdr_off;
s32 get_ehdr(vm::ptr<elf_ehdr<elf_be, u64>> out) const
{
if (!src)
{
return -1;
}
if (_vtable == vm::cast(u32{1}))
{
vm::ptr<elf_ehdr<elf_be, u32>> ehdr = vm::cast(src.addr() + ehdr_off);
std::memcpy(out.get_ptr(), ehdr.get_ptr(), 0x10); // Not needed?
out->e_type = ehdr->e_type;
out->e_machine = ehdr->e_machine;
out->e_version = ehdr->e_version;
out->e_entry = ehdr->e_entry;
out->e_phoff = ehdr->e_phoff;
out->e_shoff = ehdr->e_shoff;
out->e_flags = ehdr->e_flags;
out->e_ehsize = ehdr->e_ehsize;
out->e_phentsize = ehdr->e_phentsize;
out->e_phnum = ehdr->e_phnum;
out->e_shentsize = ehdr->e_shentsize;
out->e_shnum = ehdr->e_shnum;
out->e_shstrndx = ehdr->e_shstrndx;
}
else
{
vm::ptr<elf_ehdr<elf_be, u64>> ehdr = vm::cast(src.addr() + ehdr_off);
*out = *ehdr;
}
return 0;
}
s32 get_phdr(vm::ptr<elf_phdr<elf_be, u64>> out, u32 count) const
{
if (!src)
{
return -1;
}
if (_vtable == vm::cast(u32{1}))
{
vm::ptr<elf_ehdr<elf_be, u32>> ehdr = vm::cast(src.addr() + ehdr_off);
vm::ptr<elf_phdr<elf_be, u32>> phdr = vm::cast(src.addr() + (phdr_off ? +phdr_off : +ehdr->e_phoff));
for (; count; count--, phdr++, out++)
{
out->p_type = phdr->p_type;
out->p_flags = phdr->p_flags;
out->p_offset = phdr->p_offset;
out->p_vaddr = phdr->p_vaddr;
out->p_paddr = phdr->p_paddr;
out->p_filesz = phdr->p_filesz;
out->p_memsz = phdr->p_memsz;
out->p_align = phdr->p_align;
}
}
else
{
vm::ptr<elf_ehdr<elf_be, u64>> ehdr = vm::cast(src.addr() + ehdr_off);
vm::ptr<elf_phdr<elf_be, u64>> phdr = vm::cast(src.addr() + (phdr_off ? +phdr_off : +ehdr->e_phoff));
std::memcpy(out.get_ptr(), phdr.get_ptr(), sizeof(*out) * count);
}
return 0;
}
};
struct spu_elf_info
{
u8 e_class;
vm::bptr<spu_elf_ldr> ldr;
struct sce_hdr
{
be_t<u32> se_magic;
be_t<u32> se_hver;
be_t<u16> se_flags;
be_t<u16> se_type;
be_t<u32> se_meta;
be_t<u64> se_hsize;
be_t<u64> se_esize;
} sce0;
struct self_hdr
{
be_t<u64> se_htype;
be_t<u64> se_appinfooff;
be_t<u64> se_elfoff;
be_t<u64> se_phdroff;
be_t<u64> se_shdroff;
be_t<u64> se_secinfoff;
be_t<u64> se_sceveroff;
be_t<u64> se_controloff;
be_t<u64> se_controlsize;
be_t<u64> pad;
} self;
// Doesn't exist there
spu_elf_ldr _overlay;
error_code init(vm::ptr<void> src, s32 arg2 = 0)
{
if (!src)
{
return CELL_EINVAL;
}
u32 ehdr_off = 0;
u32 phdr_off = 0;
// Check SCE header if found
std::memcpy(&sce0, src.get_ptr(), sizeof(sce0));
if (sce0.se_magic == 0x53434500u /* SCE\0 */)
{
if (sce0.se_hver != 2u || sce0.se_type != 1u || sce0.se_meta == 0u)
{
return CELL_ENOEXEC;
}
std::memcpy(&self, static_cast<const uchar*>(src.get_ptr()) + sizeof(sce0), sizeof(self));
ehdr_off = static_cast<u32>(+self.se_elfoff);
phdr_off = static_cast<u32>(+self.se_phdroff);
if (self.se_htype != 3u || !ehdr_off || !phdr_off)
{
return CELL_ENOEXEC;
}
}
// Check ELF header
vm::ptr<elf_ehdr<elf_be, u32>> ehdr = vm::cast(src.addr() + ehdr_off);
if (ehdr->e_magic != "\177ELF"_u32 || ehdr->e_data != 2u /* BE */)
{
return CELL_ENOEXEC;
}
if (ehdr->e_class != 1u && ehdr->e_class != 2u)
{
return CELL_ENOEXEC;
}
e_class = ehdr->e_class;
ldr = vm::get_addr(&_overlay);
ldr->_vtable = vm::cast(u32{e_class}); // TODO
ldr->src = vm::static_ptr_cast<u8>(src);
ldr->x8 = arg2;
ldr->ehdr_off = ehdr_off;
ldr->phdr_off = phdr_off;
return CELL_OK;
}
};
error_code sys_spu_elf_get_information(u32 elf_img, vm::ptr<u32> entry, vm::ptr<s32> nseg)
{
sysPrxForUser.warning("sys_spu_elf_get_information(elf_img=0x%x, entry=*0x%x, nseg=*0x%x)", elf_img, entry, nseg);
// Initialize ELF loader
vm::var<spu_elf_info> info({0});
if (auto res = info->init(vm::cast(elf_img)))
{
return res;
}
// Reject SCE header
if (info->sce0.se_magic == 0x53434500u)
{
return CELL_ENOEXEC;
}
// Load ELF header
vm::var<elf_ehdr<elf_be, u64>> ehdr({0});
if (info->ldr->get_ehdr(ehdr) || ehdr->e_machine != elf_machine::spu || !ehdr->e_phnum)
{
return CELL_ENOEXEC;
}
// Load program headers
vm::var<elf_phdr<elf_be, u64>[]> phdr(ehdr->e_phnum);
if (info->ldr->get_phdr(phdr, ehdr->e_phnum))
{
return CELL_ENOEXEC;
}
const s32 num_segs = sys_spu_image::get_nsegs<false>(phdr);
if (num_segs < 0)
{
return CELL_ENOEXEC;
}
*entry = static_cast<u32>(ehdr->e_entry);
*nseg = num_segs;
return CELL_OK;
}
error_code sys_spu_elf_get_segments(u32 elf_img, vm::ptr<sys_spu_segment> segments, s32 nseg)
{
sysPrxForUser.warning("sys_spu_elf_get_segments(elf_img=0x%x, segments=*0x%x, nseg=0x%x)", elf_img, segments, nseg);
// Initialize ELF loader
vm::var<spu_elf_info> info({0});
if (auto res = info->init(vm::cast(elf_img)))
{
return res;
}
// Load ELF header
vm::var<elf_ehdr<elf_be, u64>> ehdr({0});
if (info->ldr->get_ehdr(ehdr) || ehdr->e_machine != elf_machine::spu || !ehdr->e_phnum)
{
return CELL_ENOEXEC;
}
// Load program headers
vm::var<elf_phdr<elf_be, u64>[]> phdr(ehdr->e_phnum);
if (info->ldr->get_phdr(phdr, ehdr->e_phnum))
{
return CELL_ENOEXEC;
}
const s32 num_segs = sys_spu_image::fill<false>(segments, nseg, phdr, elf_img);
if (num_segs == -2)
{
return CELL_ENOMEM;
}
else if (num_segs < 0)
{
return CELL_ENOEXEC;
}
return CELL_OK;
}
error_code sys_spu_image_import(ppu_thread& ppu, vm::ptr<sys_spu_image> img, u32 src, u32 type)
{
sysPrxForUser.warning("sys_spu_image_import(img=*0x%x, src=0x%x, type=%d)", img, src, type);
if (type != SYS_SPU_IMAGE_PROTECT && type != SYS_SPU_IMAGE_DIRECT)
{
return CELL_EINVAL;
}
// Initialize ELF loader
vm::var<spu_elf_info> info({0});
if (auto res = info->init(vm::cast(src)))
{
return res;
}
// Reject SCE header
if (info->sce0.se_magic == 0x53434500u)
{
return CELL_ENOEXEC;
}
// Load ELF header
vm::var<elf_ehdr<elf_be, u64>> ehdr({0});
if (info->ldr->get_ehdr(ehdr) || ehdr->e_machine != elf_machine::spu || !ehdr->e_phnum)
{
return CELL_ENOEXEC;
}
// Load program headers
vm::var<elf_phdr<elf_be, u64>[]> phdr(ehdr->e_phnum);
if (info->ldr->get_phdr(phdr, ehdr->e_phnum))
{
return CELL_ENOEXEC;
}
if (type == SYS_SPU_IMAGE_PROTECT)
{
u32 img_size = 0;
for (const auto& p : phdr)
{
if (p.p_type != 1u && p.p_type != 4u)
{
return CELL_ENOEXEC;
}
img_size = std::max<u32>(img_size, static_cast<u32>(p.p_offset + p.p_filesz));
}
return _sys_spu_image_import(ppu, img, src, img_size, 0);
}
else
{
s32 num_segs = sys_spu_image::get_nsegs(phdr);
if (num_segs < 0)
{
return CELL_ENOEXEC;
}
img->nsegs = num_segs;
img->entry_point = static_cast<u32>(ehdr->e_entry);
vm::ptr<sys_spu_segment> segs = vm::cast(vm::alloc(num_segs * sizeof(sys_spu_segment), vm::main));
if (!segs)
{
return CELL_ENOMEM;
}
if (sys_spu_image::fill(segs, num_segs, phdr, src) != num_segs)
{
vm::dealloc(segs.addr());
return CELL_ENOEXEC;
}
img->type = SYS_SPU_IMAGE_TYPE_USER;
img->segs = segs;
return CELL_OK;
}
}
error_code sys_spu_image_close(ppu_thread& ppu, vm::ptr<sys_spu_image> img)
{
sysPrxForUser.warning("sys_spu_image_close(img=*0x%x)", img);
if (img->type == SYS_SPU_IMAGE_TYPE_USER)
{
//_sys_free(img->segs.addr());
vm::dealloc(img->segs.addr(), vm::main);
}
else if (img->type == SYS_SPU_IMAGE_TYPE_KERNEL)
{
// Call the syscall
return _sys_spu_image_close(ppu, img);
}
else
{
return CELL_EINVAL;
}
return CELL_OK;
}
error_code sys_raw_spu_load(s32 id, vm::cptr<char> path, vm::ptr<u32> entry)
{
sysPrxForUser.warning("sys_raw_spu_load(id=%d, path=%s, entry=*0x%x)", id, path, entry);
const fs::file elf_file = fs::file(vfs::get(path.get_ptr()));
if (!elf_file)
{
return CELL_ENOENT;
}
sys_spu_image img;
img.load(elf_file);
img.deploy(vm::_ptr<u8>(RAW_SPU_BASE_ADDR + RAW_SPU_OFFSET * id), std::span(img.segs.get_ptr(), img.nsegs));
img.free();
*entry = img.entry_point;
return CELL_OK;
}
error_code sys_raw_spu_image_load(s32 id, vm::ptr<sys_spu_image> img)
{
sysPrxForUser.warning("sys_raw_spu_image_load(id=%d, img=*0x%x)", id, img);
// Load SPU segments
img->deploy(vm::_ptr<u8>(RAW_SPU_BASE_ADDR + RAW_SPU_OFFSET * id), std::span(img->segs.get_ptr(), img->nsegs));
// Use MMIO
vm::write32(RAW_SPU_BASE_ADDR + RAW_SPU_OFFSET * id + RAW_SPU_PROB_OFFSET + SPU_NPC_offs, img->entry_point);
return CELL_OK;
}
error_code _sys_spu_printf_initialize(spu_printf_cb_t agcb, spu_printf_cb_t dgcb, spu_printf_cb_t atcb, spu_printf_cb_t dtcb)
{
sysPrxForUser.warning("_sys_spu_printf_initialize(agcb=*0x%x, dgcb=*0x%x, atcb=*0x%x, dtcb=*0x%x)", agcb, dgcb, atcb, dtcb);
// register callbacks
g_spu_printf_agcb = agcb;
g_spu_printf_dgcb = dgcb;
g_spu_printf_atcb = atcb;
g_spu_printf_dtcb = dtcb;
return CELL_OK;
}
error_code _sys_spu_printf_finalize()
{
sysPrxForUser.warning("_sys_spu_printf_finalize()");
g_spu_printf_agcb = vm::null;
g_spu_printf_dgcb = vm::null;
g_spu_printf_atcb = vm::null;
g_spu_printf_dtcb = vm::null;
return CELL_OK;
}
error_code _sys_spu_printf_attach_group(ppu_thread& ppu, u32 group)
{
sysPrxForUser.warning("_sys_spu_printf_attach_group(group=0x%x)", group);
if (!g_spu_printf_agcb)
{
return CELL_ESTAT;
}
return g_spu_printf_agcb(ppu, group);
}
error_code _sys_spu_printf_detach_group(ppu_thread& ppu, u32 group)
{
sysPrxForUser.warning("_sys_spu_printf_detach_group(group=0x%x)", group);
if (!g_spu_printf_dgcb)
{
return CELL_ESTAT;
}
return g_spu_printf_dgcb(ppu, group);
}
error_code _sys_spu_printf_attach_thread(ppu_thread& ppu, u32 thread)
{
sysPrxForUser.warning("_sys_spu_printf_attach_thread(thread=0x%x)", thread);
if (!g_spu_printf_atcb)
{
return CELL_ESTAT;
}
return g_spu_printf_atcb(ppu, thread);
}
error_code _sys_spu_printf_detach_thread(ppu_thread& ppu, u32 thread)
{
sysPrxForUser.warning("_sys_spu_printf_detach_thread(thread=0x%x)", thread);
if (!g_spu_printf_dtcb)
{
return CELL_ESTAT;
}
return g_spu_printf_dtcb(ppu, thread);
}
void sysPrxForUser_sys_spu_init()
{
REG_FUNC(sysPrxForUser, sys_spu_elf_get_information);
REG_FUNC(sysPrxForUser, sys_spu_elf_get_segments);
REG_FUNC(sysPrxForUser, sys_spu_image_import);
REG_FUNC(sysPrxForUser, sys_spu_image_close);
REG_FUNC(sysPrxForUser, sys_raw_spu_load);
REG_FUNC(sysPrxForUser, sys_raw_spu_image_load);
REG_FUNC(sysPrxForUser, _sys_spu_printf_initialize);
REG_FUNC(sysPrxForUser, _sys_spu_printf_finalize);
REG_FUNC(sysPrxForUser, _sys_spu_printf_attach_group);
REG_FUNC(sysPrxForUser, _sys_spu_printf_detach_group);
REG_FUNC(sysPrxForUser, _sys_spu_printf_attach_thread);
REG_FUNC(sysPrxForUser, _sys_spu_printf_detach_thread);
}
| 11,350
|
C++
|
.cpp
| 401
| 25.605985
| 125
| 0.655881
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| true
| false
| false
| true
| false
| false
|
5,241
|
cellVideoOut.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellVideoOut.cpp
|
#include "stdafx.h"
#include "Emu/system_config_types.h"
#include "Emu/Cell/ErrorCodes.h"
#include "Emu/Cell/PPUModule.h"
#include "Emu/IdManager.h"
#include "Emu/RSX/rsx_utils.h"
#include "Emu/RSX/RSXThread.h"
#include "cellVideoOut.h"
LOG_CHANNEL(cellSysutil);
// NOTE: Unused in this module, but used by gs_frame to determine window size
const extern std::unordered_map<video_resolution, std::pair<int, int>, value_hash<video_resolution>> g_video_out_resolution_map
{
{ video_resolution::_1080p, { 1920, 1080 } },
{ video_resolution::_1080i, { 1920, 1080 } },
{ video_resolution::_720p, { 1280, 720 } },
{ video_resolution::_480p, { 720, 480 } },
{ video_resolution::_480i, { 720, 480 } },
{ video_resolution::_576p, { 720, 576 } },
{ video_resolution::_576i, { 720, 576 } },
{ video_resolution::_1600x1080p, { 1600, 1080 } },
{ video_resolution::_1440x1080p, { 1440, 1080 } },
{ video_resolution::_1280x1080p, { 1280, 1080 } },
{ video_resolution::_960x1080p, { 960, 1080 } },
};
const extern std::unordered_map<video_resolution, CellVideoOutResolutionId, value_hash<video_resolution>> g_video_out_resolution_id
{
{ video_resolution::_1080p, CELL_VIDEO_OUT_RESOLUTION_1080 },
{ video_resolution::_1080i, CELL_VIDEO_OUT_RESOLUTION_1080 },
{ video_resolution::_720p, CELL_VIDEO_OUT_RESOLUTION_720 },
{ video_resolution::_480p, CELL_VIDEO_OUT_RESOLUTION_480 },
{ video_resolution::_480i, CELL_VIDEO_OUT_RESOLUTION_480 },
{ video_resolution::_576p, CELL_VIDEO_OUT_RESOLUTION_576 },
{ video_resolution::_576i, CELL_VIDEO_OUT_RESOLUTION_576 },
{ video_resolution::_1600x1080p, CELL_VIDEO_OUT_RESOLUTION_1600x1080 },
{ video_resolution::_1440x1080p, CELL_VIDEO_OUT_RESOLUTION_1440x1080 },
{ video_resolution::_1280x1080p, CELL_VIDEO_OUT_RESOLUTION_1280x1080 },
{ video_resolution::_960x1080p, CELL_VIDEO_OUT_RESOLUTION_960x1080 },
};
const extern std::unordered_map<video_resolution, CellVideoOutScanMode, value_hash<video_resolution>> g_video_out_scan_mode
{
{ video_resolution::_1080p, CELL_VIDEO_OUT_SCAN_MODE_PROGRESSIVE },
{ video_resolution::_1080i, CELL_VIDEO_OUT_SCAN_MODE_INTERLACE },
{ video_resolution::_720p, CELL_VIDEO_OUT_SCAN_MODE_PROGRESSIVE },
{ video_resolution::_480p, CELL_VIDEO_OUT_SCAN_MODE_PROGRESSIVE },
{ video_resolution::_480i, CELL_VIDEO_OUT_SCAN_MODE_INTERLACE },
{ video_resolution::_576p, CELL_VIDEO_OUT_SCAN_MODE_PROGRESSIVE },
{ video_resolution::_576i, CELL_VIDEO_OUT_SCAN_MODE_INTERLACE },
{ video_resolution::_1600x1080p, CELL_VIDEO_OUT_SCAN_MODE_PROGRESSIVE },
{ video_resolution::_1440x1080p, CELL_VIDEO_OUT_SCAN_MODE_PROGRESSIVE },
{ video_resolution::_1280x1080p, CELL_VIDEO_OUT_SCAN_MODE_PROGRESSIVE },
{ video_resolution::_960x1080p, CELL_VIDEO_OUT_SCAN_MODE_PROGRESSIVE },
};
const extern std::unordered_map<video_aspect, CellVideoOutDisplayAspect, value_hash<video_aspect>> g_video_out_aspect_id
{
{ video_aspect::_16_9, CELL_VIDEO_OUT_ASPECT_16_9 },
{ video_aspect::_4_3, CELL_VIDEO_OUT_ASPECT_4_3 },
};
template<>
void fmt_class_string<CellVideoOutError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_VIDEO_OUT_ERROR_NOT_IMPLEMENTED);
STR_CASE(CELL_VIDEO_OUT_ERROR_ILLEGAL_CONFIGURATION);
STR_CASE(CELL_VIDEO_OUT_ERROR_ILLEGAL_PARAMETER);
STR_CASE(CELL_VIDEO_OUT_ERROR_PARAMETER_OUT_OF_RANGE);
STR_CASE(CELL_VIDEO_OUT_ERROR_DEVICE_NOT_FOUND);
STR_CASE(CELL_VIDEO_OUT_ERROR_UNSUPPORTED_VIDEO_OUT);
STR_CASE(CELL_VIDEO_OUT_ERROR_UNSUPPORTED_DISPLAY_MODE);
STR_CASE(CELL_VIDEO_OUT_ERROR_CONDITION_BUSY);
STR_CASE(CELL_VIDEO_OUT_ERROR_VALUE_IS_NOT_SET);
}
return unknown;
});
}
error_code cellVideoOutGetNumberOfDevice(u32 videoOut);
error_code _IntGetResolutionInfo(u8 resolution_id, CellVideoOutResolution* resolution)
{
// NOTE: Some resolution IDs that return values on hw have unknown resolution enumerants
switch (resolution_id)
{
case CELL_VIDEO_OUT_RESOLUTION_1080: *resolution = { 0x780, 0x438 }; break;
case CELL_VIDEO_OUT_RESOLUTION_720: *resolution = { 0x500, 0x2d0 }; break;
case CELL_VIDEO_OUT_RESOLUTION_480: *resolution = { 0x2d0, 0x1e0 }; break;
case CELL_VIDEO_OUT_RESOLUTION_576: *resolution = { 0x2d0, 0x240 }; break;
case CELL_VIDEO_OUT_RESOLUTION_1600x1080: *resolution = { 0x640, 0x438 }; break;
case CELL_VIDEO_OUT_RESOLUTION_1440x1080: *resolution = { 0x5a0, 0x438 }; break;
case CELL_VIDEO_OUT_RESOLUTION_1280x1080: *resolution = { 0x500, 0x438 }; break;
case CELL_VIDEO_OUT_RESOLUTION_960x1080: *resolution = { 0x3c0, 0x438 }; break;
case 0x64: *resolution = { 0x550, 0x300 }; break;
case CELL_VIDEO_OUT_RESOLUTION_720_3D_FRAME_PACKING: *resolution = { 0x500, 0x5be }; break;
case 0x82: *resolution = { 0x780, 0x438 }; break;
case 0x83: *resolution = { 0x780, 0x89d }; break;
case CELL_VIDEO_OUT_RESOLUTION_640x720_3D_FRAME_PACKING: *resolution = { 0x280, 0x5be }; break;
case CELL_VIDEO_OUT_RESOLUTION_800x720_3D_FRAME_PACKING: *resolution = { 0x320, 0x5be }; break;
case CELL_VIDEO_OUT_RESOLUTION_960x720_3D_FRAME_PACKING: *resolution = { 0x3c0, 0x5be }; break;
case CELL_VIDEO_OUT_RESOLUTION_1024x720_3D_FRAME_PACKING: *resolution = { 0x400, 0x5be }; break;
case CELL_VIDEO_OUT_RESOLUTION_720_DUALVIEW_FRAME_PACKING: *resolution = { 0x500, 0x5be }; break;
case 0x92: *resolution = { 0x780, 0x438 }; break;
case CELL_VIDEO_OUT_RESOLUTION_640x720_DUALVIEW_FRAME_PACKING: *resolution = { 0x280, 0x5be }; break;
case CELL_VIDEO_OUT_RESOLUTION_800x720_DUALVIEW_FRAME_PACKING: *resolution = { 0x320, 0x5be }; break;
case CELL_VIDEO_OUT_RESOLUTION_960x720_DUALVIEW_FRAME_PACKING: *resolution = { 0x3c0, 0x5be }; break;
case CELL_VIDEO_OUT_RESOLUTION_1024x720_DUALVIEW_FRAME_PACKING: *resolution = { 0x400, 0x5be }; break;
case 0xa1: *resolution = { 0x780, 0x438 }; break;
default: return CELL_VIDEO_OUT_ERROR_ILLEGAL_PARAMETER;
}
return CELL_OK;
}
error_code cellVideoOutGetState(u32 videoOut, u32 deviceIndex, vm::ptr<CellVideoOutState> state)
{
cellSysutil.trace("cellVideoOutGetState(videoOut=%d, deviceIndex=%d, state=*0x%x)", videoOut, deviceIndex, state);
if (!state)
{
return CELL_VIDEO_OUT_ERROR_ILLEGAL_PARAMETER;
}
const auto device_count = cellVideoOutGetNumberOfDevice(videoOut);
if (device_count < 0 || deviceIndex >= static_cast<u32>(device_count))
{
return CELL_VIDEO_OUT_ERROR_DEVICE_NOT_FOUND;
}
switch (videoOut)
{
case CELL_VIDEO_OUT_PRIMARY:
{
const auto& conf = g_fxo->get<rsx::avconf>();
state->state = CELL_VIDEO_OUT_OUTPUT_STATE_ENABLED;
state->colorSpace = CELL_VIDEO_OUT_COLOR_SPACE_RGB;
state->displayMode.resolutionId = conf.state ? conf.resolution_id : ::at32(g_video_out_resolution_id, g_cfg.video.resolution);
state->displayMode.scanMode = conf.state ? conf.scan_mode : ::at32(g_video_out_scan_mode, g_cfg.video.resolution);
state->displayMode.conversion = CELL_VIDEO_OUT_DISPLAY_CONVERSION_NONE;
state->displayMode.aspect = conf.state ? conf.aspect : ::at32(g_video_out_aspect_id, g_cfg.video.aspect_ratio);
state->displayMode.refreshRates = CELL_VIDEO_OUT_REFRESH_RATE_59_94HZ;
return CELL_OK;
}
case CELL_VIDEO_OUT_SECONDARY:
*state = { CELL_VIDEO_OUT_OUTPUT_STATE_DISABLED }; // ???
return CELL_OK;
}
return CELL_VIDEO_OUT_ERROR_UNSUPPORTED_VIDEO_OUT;
}
error_code cellVideoOutGetResolution(u32 resolutionId, vm::ptr<CellVideoOutResolution> resolution)
{
cellSysutil.trace("cellVideoOutGetResolution(resolutionId=0x%x, resolution=*0x%x)", resolutionId, resolution);
if (!resolution)
{
return CELL_VIDEO_OUT_ERROR_ILLEGAL_PARAMETER;
}
CellVideoOutResolution res;
error_code result;
if (result = _IntGetResolutionInfo(resolutionId, &res); result == CELL_OK)
{
*resolution = res;
}
return result;
}
error_code cellVideoOutConfigure(u32 videoOut, vm::ptr<CellVideoOutConfiguration> config, vm::ptr<CellVideoOutOption> option, u32 waitForEvent)
{
cellSysutil.warning("cellVideoOutConfigure(videoOut=%d, config=*0x%x, option=*0x%x, waitForEvent=%d)", videoOut, config, option, waitForEvent);
if (!config)
{
return CELL_VIDEO_OUT_ERROR_ILLEGAL_PARAMETER;
}
if (!config->pitch)
{
return CELL_VIDEO_OUT_ERROR_PARAMETER_OUT_OF_RANGE;
}
if (config->resolutionId == 0x92 || config->resolutionId == 0xa1)
{
return CELL_VIDEO_OUT_ERROR_ILLEGAL_CONFIGURATION;
}
CellVideoOutResolution res;
if (_IntGetResolutionInfo(config->resolutionId, &res) != CELL_OK ||
(config->resolutionId >= CELL_VIDEO_OUT_RESOLUTION_720_3D_FRAME_PACKING && g_cfg.video.stereo_render_mode == stereo_render_mode_options::disabled))
{
// Resolution not supported
cellSysutil.error("Unusual resolution requested: 0x%x", config->resolutionId);
return CELL_VIDEO_OUT_ERROR_UNSUPPORTED_DISPLAY_MODE;
}
auto& conf = g_fxo->get<rsx::avconf>();
conf.resolution_id = config->resolutionId;
conf.stereo_mode = (config->resolutionId >= CELL_VIDEO_OUT_RESOLUTION_720_3D_FRAME_PACKING) ? g_cfg.video.stereo_render_mode.get() : stereo_render_mode_options::disabled;
conf.aspect = config->aspect;
conf.format = config->format;
conf.scanline_pitch = config->pitch;
conf.resolution_x = res.width;
conf.resolution_y = res.height;
conf.state = 1;
// TODO: What happens if the aspect is unknown? Let's treat it as auto for now.
if (conf.aspect != CELL_VIDEO_OUT_ASPECT_4_3 && conf.aspect != CELL_VIDEO_OUT_ASPECT_16_9)
{
if (conf.aspect != CELL_VIDEO_OUT_ASPECT_AUTO)
{
cellSysutil.error("Selected unknown aspect 0x%x. Falling back to aspect %s.", conf.aspect, g_cfg.video.aspect_ratio.get());
}
// Resolve 'auto' or unknown options to actual aspect ratio
conf.aspect = ::at32(g_video_out_aspect_id, g_cfg.video.aspect_ratio);
}
cellSysutil.notice("Selected video configuration: resolutionId=0x%x, aspect=0x%x=>0x%x, format=0x%x", config->resolutionId, config->aspect, conf.aspect, config->format);
// This function resets VSYNC to be enabled
rsx::get_current_renderer()->requested_vsync = true;
return CELL_OK;
}
error_code cellVideoOutGetConfiguration(u32 videoOut, vm::ptr<CellVideoOutConfiguration> config, vm::ptr<CellVideoOutOption> option)
{
cellSysutil.warning("cellVideoOutGetConfiguration(videoOut=%d, config=*0x%x, option=*0x%x)", videoOut, config, option);
if (!config)
{
return CELL_VIDEO_OUT_ERROR_ILLEGAL_PARAMETER;
}
if (option) *option = {};
*config = {};
switch (videoOut)
{
case CELL_VIDEO_OUT_PRIMARY:
{
if (const auto& conf = g_fxo->get<rsx::avconf>(); conf.state)
{
config->resolutionId = conf.resolution_id;
config->format = conf.format;
config->aspect = conf.aspect;
config->pitch = conf.scanline_pitch;
}
else
{
config->resolutionId = ::at32(g_video_out_resolution_id, g_cfg.video.resolution);
config->format = CELL_VIDEO_OUT_BUFFER_COLOR_FORMAT_X8R8G8B8;
config->aspect = ::at32(g_video_out_aspect_id, g_cfg.video.aspect_ratio);
CellVideoOutResolution res;
ensure(_IntGetResolutionInfo(config->resolutionId, &res) == CELL_OK); // "Invalid video configuration"
config->pitch = 4 * res.width;
}
return CELL_OK;
}
case CELL_VIDEO_OUT_SECONDARY:
return CELL_OK;
}
return CELL_VIDEO_OUT_ERROR_UNSUPPORTED_VIDEO_OUT;
}
error_code cellVideoOutGetDeviceInfo(u32 videoOut, u32 deviceIndex, vm::ptr<CellVideoOutDeviceInfo> info)
{
cellSysutil.warning("cellVideoOutGetDeviceInfo(videoOut=%d, deviceIndex=%d, info=*0x%x)", videoOut, deviceIndex, info);
if (!info)
{
return CELL_VIDEO_OUT_ERROR_ILLEGAL_PARAMETER;
}
const auto device_count = cellVideoOutGetNumberOfDevice(videoOut);
if (device_count < 0 || deviceIndex >= static_cast<u32>(device_count))
{
return CELL_VIDEO_OUT_ERROR_DEVICE_NOT_FOUND;
}
// Use standard dummy values for now.
info->portType = CELL_VIDEO_OUT_PORT_HDMI;
info->colorSpace = CELL_VIDEO_OUT_COLOR_SPACE_RGB;
info->latency = 100;
info->state = CELL_VIDEO_OUT_DEVICE_STATE_AVAILABLE;
info->rgbOutputRange = 1;
info->colorInfo.blueX = 0xFFFF;
info->colorInfo.blueY = 0xFFFF;
info->colorInfo.greenX = 0xFFFF;
info->colorInfo.greenY = 0xFFFF;
info->colorInfo.redX = 0xFFFF;
info->colorInfo.redY = 0xFFFF;
info->colorInfo.whiteX = 0xFFFF;
info->colorInfo.whiteY = 0xFFFF;
info->colorInfo.gamma = 100;
u32 mode_count = 0;
const auto add_mode = [&](u8 resolutionId, u8 scanMode, u8 conversion, u8 aspect)
{
info->availableModes[mode_count].resolutionId = resolutionId;
info->availableModes[mode_count].scanMode = scanMode;
info->availableModes[mode_count].conversion = conversion;
info->availableModes[mode_count].aspect = aspect;
info->availableModes[mode_count].refreshRates = CELL_VIDEO_OUT_REFRESH_RATE_60HZ | CELL_VIDEO_OUT_REFRESH_RATE_59_94HZ;
mode_count++;
};
switch (g_cfg.video.resolution.get())
{
case video_resolution::_1080p:
add_mode(CELL_VIDEO_OUT_RESOLUTION_1080, CELL_VIDEO_OUT_SCAN_MODE_PROGRESSIVE, CELL_VIDEO_OUT_DISPLAY_CONVERSION_NONE, CELL_VIDEO_OUT_ASPECT_16_9);
add_mode(CELL_VIDEO_OUT_RESOLUTION_1600x1080, CELL_VIDEO_OUT_SCAN_MODE_PROGRESSIVE, CELL_VIDEO_OUT_DISPLAY_CONVERSION_TO_1080, CELL_VIDEO_OUT_ASPECT_16_9);
add_mode(CELL_VIDEO_OUT_RESOLUTION_1440x1080, CELL_VIDEO_OUT_SCAN_MODE_PROGRESSIVE, CELL_VIDEO_OUT_DISPLAY_CONVERSION_TO_1080, CELL_VIDEO_OUT_ASPECT_16_9);
add_mode(CELL_VIDEO_OUT_RESOLUTION_1280x1080, CELL_VIDEO_OUT_SCAN_MODE_PROGRESSIVE, CELL_VIDEO_OUT_DISPLAY_CONVERSION_TO_1080, CELL_VIDEO_OUT_ASPECT_16_9);
add_mode(CELL_VIDEO_OUT_RESOLUTION_960x1080, CELL_VIDEO_OUT_SCAN_MODE_PROGRESSIVE, CELL_VIDEO_OUT_DISPLAY_CONVERSION_TO_1080, CELL_VIDEO_OUT_ASPECT_16_9);
break;
case video_resolution::_1080i:
add_mode(CELL_VIDEO_OUT_RESOLUTION_1080, CELL_VIDEO_OUT_SCAN_MODE_INTERLACE, CELL_VIDEO_OUT_DISPLAY_CONVERSION_NONE, CELL_VIDEO_OUT_ASPECT_16_9);
add_mode(CELL_VIDEO_OUT_RESOLUTION_1600x1080, CELL_VIDEO_OUT_SCAN_MODE_INTERLACE, CELL_VIDEO_OUT_DISPLAY_CONVERSION_TO_1080, CELL_VIDEO_OUT_ASPECT_16_9);
add_mode(CELL_VIDEO_OUT_RESOLUTION_1440x1080, CELL_VIDEO_OUT_SCAN_MODE_INTERLACE, CELL_VIDEO_OUT_DISPLAY_CONVERSION_TO_1080, CELL_VIDEO_OUT_ASPECT_16_9);
add_mode(CELL_VIDEO_OUT_RESOLUTION_1280x1080, CELL_VIDEO_OUT_SCAN_MODE_INTERLACE, CELL_VIDEO_OUT_DISPLAY_CONVERSION_TO_1080, CELL_VIDEO_OUT_ASPECT_16_9);
add_mode(CELL_VIDEO_OUT_RESOLUTION_960x1080, CELL_VIDEO_OUT_SCAN_MODE_INTERLACE, CELL_VIDEO_OUT_DISPLAY_CONVERSION_TO_1080, CELL_VIDEO_OUT_ASPECT_16_9);
break;
case video_resolution::_720p:
add_mode(CELL_VIDEO_OUT_RESOLUTION_720, CELL_VIDEO_OUT_SCAN_MODE_PROGRESSIVE, CELL_VIDEO_OUT_DISPLAY_CONVERSION_NONE, CELL_VIDEO_OUT_ASPECT_16_9);
break;
case video_resolution::_480p:
add_mode(CELL_VIDEO_OUT_RESOLUTION_480, CELL_VIDEO_OUT_SCAN_MODE_PROGRESSIVE, CELL_VIDEO_OUT_DISPLAY_CONVERSION_NONE, CELL_VIDEO_OUT_ASPECT_4_3);
if (g_cfg.video.aspect_ratio == video_aspect::_16_9)
{
add_mode(CELL_VIDEO_OUT_RESOLUTION_480, CELL_VIDEO_OUT_SCAN_MODE_PROGRESSIVE, CELL_VIDEO_OUT_DISPLAY_CONVERSION_NONE, CELL_VIDEO_OUT_ASPECT_16_9);
}
break;
case video_resolution::_480i:
add_mode(CELL_VIDEO_OUT_RESOLUTION_480, CELL_VIDEO_OUT_SCAN_MODE_INTERLACE, CELL_VIDEO_OUT_DISPLAY_CONVERSION_NONE, CELL_VIDEO_OUT_ASPECT_4_3);
if (g_cfg.video.aspect_ratio == video_aspect::_16_9)
{
add_mode(CELL_VIDEO_OUT_RESOLUTION_480, CELL_VIDEO_OUT_SCAN_MODE_INTERLACE, CELL_VIDEO_OUT_DISPLAY_CONVERSION_NONE, CELL_VIDEO_OUT_ASPECT_16_9);
}
break;
case video_resolution::_576p:
add_mode(CELL_VIDEO_OUT_RESOLUTION_576, CELL_VIDEO_OUT_SCAN_MODE_PROGRESSIVE, CELL_VIDEO_OUT_DISPLAY_CONVERSION_NONE, CELL_VIDEO_OUT_ASPECT_4_3);
add_mode(CELL_VIDEO_OUT_RESOLUTION_480, CELL_VIDEO_OUT_SCAN_MODE_PROGRESSIVE, CELL_VIDEO_OUT_DISPLAY_CONVERSION_NONE, CELL_VIDEO_OUT_ASPECT_4_3);
if (g_cfg.video.aspect_ratio == video_aspect::_16_9)
{
add_mode(CELL_VIDEO_OUT_RESOLUTION_576, CELL_VIDEO_OUT_SCAN_MODE_PROGRESSIVE, CELL_VIDEO_OUT_DISPLAY_CONVERSION_NONE, CELL_VIDEO_OUT_ASPECT_16_9);
add_mode(CELL_VIDEO_OUT_RESOLUTION_480, CELL_VIDEO_OUT_SCAN_MODE_PROGRESSIVE, CELL_VIDEO_OUT_DISPLAY_CONVERSION_NONE, CELL_VIDEO_OUT_ASPECT_16_9);
}
break;
case video_resolution::_576i:
add_mode(CELL_VIDEO_OUT_RESOLUTION_576, CELL_VIDEO_OUT_SCAN_MODE_INTERLACE, CELL_VIDEO_OUT_DISPLAY_CONVERSION_NONE, CELL_VIDEO_OUT_ASPECT_4_3);
add_mode(CELL_VIDEO_OUT_RESOLUTION_480, CELL_VIDEO_OUT_SCAN_MODE_INTERLACE, CELL_VIDEO_OUT_DISPLAY_CONVERSION_NONE, CELL_VIDEO_OUT_ASPECT_4_3);
if (g_cfg.video.aspect_ratio == video_aspect::_16_9)
{
add_mode(CELL_VIDEO_OUT_RESOLUTION_576, CELL_VIDEO_OUT_SCAN_MODE_INTERLACE, CELL_VIDEO_OUT_DISPLAY_CONVERSION_NONE, CELL_VIDEO_OUT_ASPECT_16_9);
add_mode(CELL_VIDEO_OUT_RESOLUTION_480, CELL_VIDEO_OUT_SCAN_MODE_INTERLACE, CELL_VIDEO_OUT_DISPLAY_CONVERSION_NONE, CELL_VIDEO_OUT_ASPECT_16_9);
}
break;
case video_resolution::_1600x1080p:
add_mode(CELL_VIDEO_OUT_RESOLUTION_1600x1080, CELL_VIDEO_OUT_SCAN_MODE_PROGRESSIVE, CELL_VIDEO_OUT_DISPLAY_CONVERSION_TO_1080, CELL_VIDEO_OUT_ASPECT_16_9);
break;
case video_resolution::_1440x1080p:
add_mode(CELL_VIDEO_OUT_RESOLUTION_1440x1080, CELL_VIDEO_OUT_SCAN_MODE_PROGRESSIVE, CELL_VIDEO_OUT_DISPLAY_CONVERSION_TO_1080, CELL_VIDEO_OUT_ASPECT_16_9);
break;
case video_resolution::_1280x1080p:
add_mode(CELL_VIDEO_OUT_RESOLUTION_1280x1080, CELL_VIDEO_OUT_SCAN_MODE_PROGRESSIVE, CELL_VIDEO_OUT_DISPLAY_CONVERSION_TO_1080, CELL_VIDEO_OUT_ASPECT_16_9);
break;
case video_resolution::_960x1080p:
add_mode(CELL_VIDEO_OUT_RESOLUTION_960x1080, CELL_VIDEO_OUT_SCAN_MODE_PROGRESSIVE, CELL_VIDEO_OUT_DISPLAY_CONVERSION_TO_1080, CELL_VIDEO_OUT_ASPECT_16_9);
break;
}
if (g_cfg.video.stereo_render_mode != stereo_render_mode_options::disabled && g_cfg.video.resolution == video_resolution::_720p)
{
// Register 3D-capable display mode
if (true) // TODO
{
// 3D stereo
add_mode(CELL_VIDEO_OUT_RESOLUTION_720_3D_FRAME_PACKING, CELL_VIDEO_OUT_SCAN_MODE_PROGRESSIVE, CELL_VIDEO_OUT_DISPLAY_CONVERSION_NONE, CELL_VIDEO_OUT_ASPECT_16_9);
add_mode(CELL_VIDEO_OUT_RESOLUTION_1024x720_3D_FRAME_PACKING, CELL_VIDEO_OUT_SCAN_MODE_PROGRESSIVE, CELL_VIDEO_OUT_DISPLAY_CONVERSION_TO_720_3D_FRAME_PACKING, CELL_VIDEO_OUT_ASPECT_16_9);
add_mode(CELL_VIDEO_OUT_RESOLUTION_960x720_3D_FRAME_PACKING, CELL_VIDEO_OUT_SCAN_MODE_PROGRESSIVE, CELL_VIDEO_OUT_DISPLAY_CONVERSION_TO_720_3D_FRAME_PACKING, CELL_VIDEO_OUT_ASPECT_16_9);
add_mode(CELL_VIDEO_OUT_RESOLUTION_800x720_3D_FRAME_PACKING, CELL_VIDEO_OUT_SCAN_MODE_PROGRESSIVE, CELL_VIDEO_OUT_DISPLAY_CONVERSION_TO_720_3D_FRAME_PACKING, CELL_VIDEO_OUT_ASPECT_16_9);
add_mode(CELL_VIDEO_OUT_RESOLUTION_640x720_3D_FRAME_PACKING, CELL_VIDEO_OUT_SCAN_MODE_PROGRESSIVE, CELL_VIDEO_OUT_DISPLAY_CONVERSION_TO_720_3D_FRAME_PACKING, CELL_VIDEO_OUT_ASPECT_16_9);
}
else
{
// SimulView
add_mode(CELL_VIDEO_OUT_RESOLUTION_720_SIMULVIEW_FRAME_PACKING, CELL_VIDEO_OUT_SCAN_MODE_PROGRESSIVE, CELL_VIDEO_OUT_DISPLAY_CONVERSION_TO_720_3D_FRAME_PACKING, CELL_VIDEO_OUT_ASPECT_16_9);
add_mode(CELL_VIDEO_OUT_RESOLUTION_1024x720_SIMULVIEW_FRAME_PACKING, CELL_VIDEO_OUT_SCAN_MODE_PROGRESSIVE, CELL_VIDEO_OUT_DISPLAY_CONVERSION_TO_720_3D_FRAME_PACKING, CELL_VIDEO_OUT_ASPECT_16_9);
add_mode(CELL_VIDEO_OUT_RESOLUTION_960x720_SIMULVIEW_FRAME_PACKING, CELL_VIDEO_OUT_SCAN_MODE_PROGRESSIVE, CELL_VIDEO_OUT_DISPLAY_CONVERSION_TO_720_3D_FRAME_PACKING, CELL_VIDEO_OUT_ASPECT_16_9);
add_mode(CELL_VIDEO_OUT_RESOLUTION_800x720_SIMULVIEW_FRAME_PACKING, CELL_VIDEO_OUT_SCAN_MODE_PROGRESSIVE, CELL_VIDEO_OUT_DISPLAY_CONVERSION_TO_720_3D_FRAME_PACKING, CELL_VIDEO_OUT_ASPECT_16_9);
add_mode(CELL_VIDEO_OUT_RESOLUTION_640x720_SIMULVIEW_FRAME_PACKING, CELL_VIDEO_OUT_SCAN_MODE_PROGRESSIVE, CELL_VIDEO_OUT_DISPLAY_CONVERSION_TO_720_3D_FRAME_PACKING, CELL_VIDEO_OUT_ASPECT_16_9);
}
}
info->availableModeCount = mode_count;
return CELL_OK;
}
error_code cellVideoOutGetNumberOfDevice(u32 videoOut)
{
cellSysutil.warning("cellVideoOutGetNumberOfDevice(videoOut=%d)", videoOut);
switch (videoOut)
{
case CELL_VIDEO_OUT_PRIMARY: return not_an_error(1);
case CELL_VIDEO_OUT_SECONDARY: return not_an_error(0);
}
return CELL_VIDEO_OUT_ERROR_UNSUPPORTED_VIDEO_OUT;
}
error_code cellVideoOutGetResolutionAvailability(u32 videoOut, u32 resolutionId, u32 aspect, u32 option)
{
cellSysutil.warning("cellVideoOutGetResolutionAvailability(videoOut=%d, resolutionId=0x%x, aspect=%d, option=%d)", videoOut, resolutionId, aspect, option);
switch (videoOut)
{
case CELL_VIDEO_OUT_PRIMARY:
{
// NOTE: Result is boolean
if (aspect != CELL_VIDEO_OUT_ASPECT_AUTO && aspect != static_cast<u32>(::at32(g_video_out_aspect_id, g_cfg.video.aspect_ratio)))
{
return not_an_error(0);
}
if (resolutionId == static_cast<u32>(::at32(g_video_out_resolution_id, g_cfg.video.resolution)))
{
// Perfect match
return not_an_error(1);
}
if ((g_cfg.video.stereo_render_mode != stereo_render_mode_options::disabled) && g_cfg.video.resolution == video_resolution::_720p)
{
switch (resolutionId)
{
case CELL_VIDEO_OUT_RESOLUTION_720_3D_FRAME_PACKING:
case CELL_VIDEO_OUT_RESOLUTION_1024x720_3D_FRAME_PACKING:
case CELL_VIDEO_OUT_RESOLUTION_960x720_3D_FRAME_PACKING:
case CELL_VIDEO_OUT_RESOLUTION_800x720_3D_FRAME_PACKING:
case CELL_VIDEO_OUT_RESOLUTION_640x720_3D_FRAME_PACKING:
return not_an_error(1);
default:
break;
}
}
return not_an_error(0);
}
case CELL_VIDEO_OUT_SECONDARY: return not_an_error(0);
}
return CELL_VIDEO_OUT_ERROR_UNSUPPORTED_VIDEO_OUT;
}
// Temporarily
#ifndef _MSC_VER
#pragma GCC diagnostic ignored "-Wunused-parameter"
#endif
error_code cellVideoOutGetConvertCursorColorInfo(vm::ptr<u8> rgbOutputRange)
{
cellSysutil.todo("cellVideoOutGetConvertCursorColorInfo(rgbOutputRange=*0x%x)", rgbOutputRange);
if (!rgbOutputRange)
{
return CELL_VIDEO_OUT_ERROR_ILLEGAL_PARAMETER; // TODO: Speculative
}
*rgbOutputRange = CELL_VIDEO_OUT_RGB_OUTPUT_RANGE_FULL; // Or CELL_VIDEO_OUT_RGB_OUTPUT_RANGE_LIMITED
return CELL_OK;
}
error_code cellVideoOutDebugSetMonitorType(u32 videoOut, u32 monitorType)
{
cellSysutil.todo("cellVideoOutDebugSetMonitorType(videoOut=%d, monitorType=%d)", videoOut, monitorType);
return CELL_OK;
}
error_code cellVideoOutRegisterCallback(u32 slot, vm::ptr<CellVideoOutCallback> function, vm::ptr<void> userData)
{
cellSysutil.todo("cellVideoOutRegisterCallback(slot=%d, function=*0x%x, userData=*0x%x)", slot, function, userData);
return CELL_OK;
}
error_code cellVideoOutUnregisterCallback(u32 slot)
{
cellSysutil.todo("cellVideoOutUnregisterCallback(slot=%d)", slot);
return CELL_OK;
}
void cellSysutil_VideoOut_init()
{
REG_FUNC(cellSysutil, cellVideoOutGetState);
REG_FUNC(cellSysutil, cellVideoOutGetResolution).flag(MFF_PERFECT);
REG_FUNC(cellSysutil, cellVideoOutConfigure);
REG_FUNC(cellSysutil, cellVideoOutGetConfiguration);
REG_FUNC(cellSysutil, cellVideoOutGetDeviceInfo);
REG_FUNC(cellSysutil, cellVideoOutGetNumberOfDevice);
REG_FUNC(cellSysutil, cellVideoOutGetResolutionAvailability);
REG_FUNC(cellSysutil, cellVideoOutGetConvertCursorColorInfo);
REG_FUNC(cellSysutil, cellVideoOutDebugSetMonitorType);
REG_FUNC(cellSysutil, cellVideoOutRegisterCallback);
REG_FUNC(cellSysutil, cellVideoOutUnregisterCallback);
}
| 23,567
|
C++
|
.cpp
| 456
| 49.212719
| 197
| 0.748947
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| false
| false
|
5,242
|
cellSysutilAvcExt.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellSysutilAvcExt.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
#include "Emu/Cell/Modules/cellSysutilAvc.h"
LOG_CHANNEL(cellSysutilAvcExt);
error_code cellSysutilAvcSetAttribute(CellSysUtilAvcAttribute attr_id, vm::ptr<void> param);
error_code cellSysutilAvcLoadAsync(vm::ptr<CellSysutilAvcCallback> func, vm::ptr<void> userdata, sys_memory_container_t container, CellSysUtilAvcMediaType media, CellSysUtilAvcVideoQuality videoQuality, CellSysUtilAvcVoiceQuality voiceQuality, vm::ptr<CellSysutilAvcRequestId> request_id);
error_code cellSysutilAvcExtIsMicAttached(vm::ptr<s32> status)
{
cellSysutilAvcExt.todo("cellSysutilAvcExtIsMicAttached(status=*0x%x)", status);
ensure(!!status); // Not actually checked
return CELL_OK;
}
error_code cellSysutilAvcExtStopCameraDetection()
{
cellSysutilAvcExt.todo("cellSysutilAvcExtStopCameraDetection()");
return CELL_OK;
}
error_code cellSysutilAvcExtSetWindowRotation(vm::ptr<SceNpId> player_id, f32 rotation_x, f32 rotation_y, f32 rotation_z, CellSysutilAvcTransitionType transition_type)
{
cellSysutilAvcExt.todo("cellSysutilAvcExtSetWindowRotation(player_id=*0x%x, rotation_x=%f, rotation_y=%f, rotation_z=%f, transition_type=0x%x)", player_id, rotation_x, rotation_y, rotation_z, +transition_type);
return CELL_OK;
}
error_code cellSysutilAvcExtGetWindowPosition(vm::ptr<SceNpId> player_id, vm::ptr<f32> position_x, vm::ptr<f32> position_y, vm::ptr<f32> position_z)
{
cellSysutilAvcExt.todo("cellSysutilAvcExtGetWindowPosition(player_id=*0x%x, position_x=*0x%x, position_y=*0x%x, position_z=*0x%x)", player_id, position_x, position_y, position_z);
if (!player_id || !position_x || !position_y || !position_z)
return CELL_AVC_ERROR_INVALID_ARGUMENT;
return CELL_OK;
}
error_code cellSysutilAvcExtSetHideNamePlate()
{
cellSysutilAvcExt.todo("cellSysutilAvcExtSetHideNamePlate()");
return CELL_OK;
}
error_code cellSysutilAvcExtSetWindowPosition(vm::ptr<SceNpId> player_id, f32 position_x, f32 position_y, f32 position_z, CellSysutilAvcTransitionType transition_type)
{
cellSysutilAvcExt.todo("cellSysutilAvcExtSetWindowPosition(player_id=*0x%x, position_x=%f, position_y=%f, position_z=%f, transition_type=0x%x)", player_id, position_x, position_y, position_z, +transition_type);
return CELL_OK;
}
error_code cellSysutilAvcExtGetWindowSize(vm::ptr<SceNpId> player_id, vm::ptr<f32> size_x, vm::ptr<f32> size_y)
{
cellSysutilAvcExt.todo("cellSysutilAvcExtGetWindowSize(player_id=*0x%x, size_x=*0x%x, size_y=*0x%x)", player_id, size_x, size_y);
if (!player_id || !size_x || !size_y)
return CELL_AVC_ERROR_INVALID_ARGUMENT;
return CELL_OK;
}
error_code cellSysutilAvcExtStartCameraDetection()
{
cellSysutilAvcExt.todo("cellSysutilAvcExtStartCameraDetection()");
return CELL_OK;
}
error_code cellSysutilAvcExtGetWindowShowStatus(vm::ptr<SceNpId> player_id, vm::ptr<b8> is_visible)
{
cellSysutilAvcExt.todo("cellSysutilAvcExtGetWindowShowStatus(player_id=*0x%x, is_visible=*0x%x)", player_id, is_visible);
if (!player_id || !is_visible)
return CELL_AVC_ERROR_INVALID_ARGUMENT;
return CELL_OK;
}
error_code cellSysutilAvcExtSetChatMode(u32 mode)
{
cellSysutilAvcExt.todo("cellSysutilAvcExtSetChatMode(mode=0x%x)", mode);
return CELL_OK;
}
error_code cellSysutilAvcExtGetNamePlateShowStatus(vm::ptr<b8> is_visible)
{
cellSysutilAvcExt.todo("cellSysutilAvcExtGetNamePlateShowStatus(is_visible=*0x%x)", is_visible);
if (!is_visible)
return CELL_AVC_ERROR_INVALID_ARGUMENT;
return CELL_OK;
}
error_code cellSysutilAvcExtSetWindowAlpha(vm::ptr<SceNpId> player_id, f32 alpha, CellSysutilAvcTransitionType transition_type)
{
cellSysutilAvcExt.todo("cellSysutilAvcExtSetWindowAlpha(player_id=*0x%x, alpha=%f, transition_type=0x%x)", player_id, alpha, +transition_type);
if (!player_id || transition_type > CELL_SYSUTIL_AVC_TRANSITION_EXPONENT)
return CELL_AVC_ERROR_INVALID_ARGUMENT;
return CELL_OK;
}
error_code cellSysutilAvcExtSetWindowSize(vm::ptr<SceNpId> player_id, f32 size_x, f32 size_y, CellSysutilAvcTransitionType transition_type)
{
cellSysutilAvcExt.todo("cellSysutilAvcExtSetWindowSize(player_id=*0x%x, size_x=%f, size_y=%f, transition_type=0x%x)", player_id, size_x, size_y, +transition_type);
if (!player_id || transition_type > CELL_SYSUTIL_AVC_TRANSITION_EXPONENT)
return CELL_AVC_ERROR_INVALID_ARGUMENT;
return CELL_OK;
}
error_code cellSysutilAvcExtShowPanelEx(CellSysutilAvcTransitionType transition_type)
{
cellSysutilAvcExt.todo("cellSysutilAvcExtShowPanelEx(transition_type=0x%x)", +transition_type);
return CELL_OK;
}
error_code cellSysutilAvcExtLoadAsyncEx(vm::ptr<CellSysutilAvcCallback> func, vm::ptr<void> userdata, sys_memory_container_t container,
CellSysUtilAvcMediaType media, CellSysUtilAvcVideoQuality videoQuality, CellSysUtilAvcVoiceQuality voiceQuality, vm::ptr<CellSysutilAvcOptionParam> option, vm::ptr<CellSysutilAvcRequestId> request_id)
{
cellSysutilAvcExt.todo("cellSysutilAvcExtLoadAsyncEx(func=*0x%x, userdata=*0x%x, container=0x%x, media=0x%x, videoQuality=0x%x, voiceQuality=0x%x, option=*0x%x, request_id=*0x%x)",
func, userdata, container, +media, +videoQuality, +voiceQuality, option, request_id);
if (!option)
return CELL_AVC_ERROR_INVALID_ARGUMENT;
switch (option->avcOptionParamVersion)
{
case CELL_SYSUTIL_AVC_OPTION_PARAM_VERSION:
if (option->sharingVideoBuffer && media == CELL_SYSUTIL_AVC_VOICE_CHAT)
return CELL_AVC_ERROR_INVALID_ARGUMENT;
//cellSysutilAvcSetAttribute(0x10000100, &option->sharingVideoBuffer);
break;
case 180:
if (option->sharingVideoBuffer && media == CELL_SYSUTIL_AVC_VOICE_CHAT)
return CELL_AVC_ERROR_INVALID_ARGUMENT;
//cellSysutilAvcSetAttribute(0x10000100, &option->sharingVideoBuffer);
//cellSysutilAvcSetAttribute(0x10000102, &option->maxPlayers);
break;
default:
return CELL_AVC_ERROR_UNKNOWN;
}
return cellSysutilAvcLoadAsync(func, userdata, container, media, videoQuality, voiceQuality, request_id);
}
error_code cellSysutilAvcExtSetShowNamePlate()
{
cellSysutilAvcExt.todo("cellSysutilAvcExtSetShowNamePlate()");
return CELL_OK;
}
error_code cellSysutilAvcExtStopVoiceDetection()
{
cellSysutilAvcExt.todo("cellSysutilAvcExtStopVoiceDetection()");
return CELL_OK;
}
error_code cellSysutilAvcExtShowWindow(vm::ptr<SceNpId> player_id, CellSysutilAvcTransitionType transition_type)
{
cellSysutilAvcExt.todo("cellSysutilAvcExtStopVoiceDetection(player_id=*0x%x, transition_type=0x%x)", player_id, +transition_type);
if (!player_id || transition_type > CELL_SYSUTIL_AVC_TRANSITION_EXPONENT)
return CELL_AVC_ERROR_INVALID_ARGUMENT;
return CELL_OK;
}
error_code cellSysutilAvcExtIsCameraAttached(vm::ptr<s32> status)
{
cellSysutilAvcExt.todo("cellSysutilAvcExtIsCameraAttached(status=*0x%x)", status);
ensure(!!status); // Not actually checked
return CELL_OK;
}
error_code cellSysutilAvcExtHidePanelEx(CellSysutilAvcTransitionType transition_type)
{
cellSysutilAvcExt.todo("cellSysutilAvcExtHidePanelEx(transition_type=0x%x)", +transition_type);
return CELL_OK;
}
error_code cellSysutilAvcExtHideWindow(vm::ptr<SceNpId> player_id, CellSysutilAvcTransitionType transition_type)
{
cellSysutilAvcExt.todo("cellSysutilAvcExtHideWindow(player_id=*0x%x, transition_type=0x%x)", player_id, +transition_type);
if (!player_id || transition_type > CELL_SYSUTIL_AVC_TRANSITION_EXPONENT)
return CELL_AVC_ERROR_INVALID_ARGUMENT;
return CELL_OK;
}
error_code cellSysutilAvcExtSetChatGroup()
{
cellSysutilAvcExt.todo("cellSysutilAvcExtSetChatGroup()");
return CELL_OK;
}
error_code cellSysutilAvcExtGetWindowRotation(vm::ptr<SceNpId> player_id, vm::ptr<f32> rotation_x, vm::ptr<f32> rotation_y, vm::ptr<f32> rotation_z)
{
cellSysutilAvcExt.todo("cellSysutilAvcExtGetWindowRotation(player_id=*0x%x, rotation_x=*0x%x, rotation_y=*0x%x, rotation_z=*0x%x)", player_id, rotation_x, rotation_y, rotation_z);
if (!player_id || !rotation_x || !rotation_y || !rotation_z)
return CELL_AVC_ERROR_INVALID_ARGUMENT;
return CELL_OK;
}
error_code cellSysutilAvcExtStartMicDetection()
{
cellSysutilAvcExt.todo("cellSysutilAvcExtStartMicDetection()");
return CELL_OK;
}
error_code cellSysutilAvcExtGetWindowAlpha(vm::ptr<SceNpId> player_id, vm::ptr<f32> alpha)
{
cellSysutilAvcExt.todo("cellSysutilAvcExtGetWindowAlpha(player_id=*0x%x, alpha=*0x%x)", player_id, alpha);
if (!player_id || !alpha)
return CELL_AVC_ERROR_INVALID_ARGUMENT;
return CELL_OK;
}
error_code cellSysutilAvcExtStartVoiceDetection()
{
cellSysutilAvcExt.todo("cellSysutilAvcExtStartVoiceDetection()");
return CELL_OK;
}
error_code cellSysutilAvcExtGetSurfacePointer(vm::ptr<SceNpId> player_id, vm::pptr<void> surface_ptr, vm::ptr<s32> surface_size, vm::ptr<s32> surface_size_x, vm::ptr<s32> surface_size_y)
{
cellSysutilAvcExt.todo("cellSysutilAvcExtGetSurfacePointer(player_id=*0x%x, surface_ptr=*0x%x, surface_size=*0x%x, surface_size_x=*0x%x, surface_size_y=*0x%x)", player_id, surface_ptr, surface_size, surface_size_x, surface_size_y);
if (!player_id || !surface_ptr || !surface_size || !surface_size_x || !surface_size_y)
return CELL_AVC_ERROR_INVALID_ARGUMENT;
return CELL_OK;
}
error_code cellSysutilAvcExtStopMicDetection()
{
cellSysutilAvcExt.todo("cellSysutilAvcExtStopMicDetection()");
return CELL_OK;
}
error_code cellSysutilAvcExtInitOptionParam(s32 avcOptionParamVersion, vm::ptr<CellSysutilAvcOptionParam> option)
{
cellSysutilAvcExt.notice("cellSysutilAvcExtInitOptionParam(avcOptionParamVersion=0x%x, option=*0x%x)", avcOptionParamVersion, option);
if (!option)
return CELL_AVC_ERROR_INVALID_ARGUMENT;
option->avcOptionParamVersion = avcOptionParamVersion;
switch (option->avcOptionParamVersion)
{
case CELL_SYSUTIL_AVC_OPTION_PARAM_VERSION:
break;
case 180:
option->maxPlayers = 16;
break;
default:
return CELL_AVC_ERROR_UNKNOWN;
}
option->sharingVideoBuffer = false;
return CELL_OK;
}
error_code cellSysutilAvcExtSetWindowZorder(vm::ptr<SceNpId> player_id, u32 zorder)
{
cellSysutilAvcExt.todo("cellSysutilAvcExtSetWindowZorder(player_id=*0x%x, zorder=0x%x)", player_id, zorder);
if (!player_id || zorder < CELL_SYSUTIL_AVC_ZORDER_FORWARD_MOST || zorder > CELL_SYSUTIL_AVC_ZORDER_BEHIND_MOST)
return CELL_AVC_ERROR_INVALID_ARGUMENT;
return CELL_OK;
}
DECLARE(ppu_module_manager::cellSysutilAvcExt)("cellSysutilAvcExt", []()
{
REG_FUNC(cellSysutilAvcExt, cellSysutilAvcExtIsMicAttached);
REG_FUNC(cellSysutilAvcExt, cellSysutilAvcExtStopCameraDetection);
REG_FUNC(cellSysutilAvcExt, cellSysutilAvcExtSetWindowRotation);
REG_FUNC(cellSysutilAvcExt, cellSysutilAvcExtGetWindowPosition);
REG_FUNC(cellSysutilAvcExt, cellSysutilAvcExtSetHideNamePlate);
REG_FUNC(cellSysutilAvcExt, cellSysutilAvcExtSetWindowPosition);
REG_FUNC(cellSysutilAvcExt, cellSysutilAvcExtGetWindowSize);
REG_FUNC(cellSysutilAvcExt, cellSysutilAvcExtStartCameraDetection);
REG_FUNC(cellSysutilAvcExt, cellSysutilAvcExtGetWindowShowStatus);
REG_FUNC(cellSysutilAvcExt, cellSysutilAvcExtSetChatMode);
REG_FUNC(cellSysutilAvcExt, cellSysutilAvcExtGetNamePlateShowStatus);
REG_FUNC(cellSysutilAvcExt, cellSysutilAvcExtSetWindowAlpha);
REG_FUNC(cellSysutilAvcExt, cellSysutilAvcExtSetWindowSize);
REG_FUNC(cellSysutilAvcExt, cellSysutilAvcExtShowPanelEx);
REG_FUNC(cellSysutilAvcExt, cellSysutilAvcExtLoadAsyncEx);
REG_FUNC(cellSysutilAvcExt, cellSysutilAvcExtSetShowNamePlate);
REG_FUNC(cellSysutilAvcExt, cellSysutilAvcExtStopVoiceDetection);
REG_FUNC(cellSysutilAvcExt, cellSysutilAvcExtShowWindow);
REG_FUNC(cellSysutilAvcExt, cellSysutilAvcExtIsCameraAttached);
REG_FUNC(cellSysutilAvcExt, cellSysutilAvcExtHidePanelEx);
REG_FUNC(cellSysutilAvcExt, cellSysutilAvcExtHideWindow);
REG_FUNC(cellSysutilAvcExt, cellSysutilAvcExtSetChatGroup);
REG_FUNC(cellSysutilAvcExt, cellSysutilAvcExtGetWindowRotation);
REG_FUNC(cellSysutilAvcExt, cellSysutilAvcExtStartMicDetection);
REG_FUNC(cellSysutilAvcExt, cellSysutilAvcExtGetWindowAlpha);
REG_FUNC(cellSysutilAvcExt, cellSysutilAvcExtStartVoiceDetection);
REG_FUNC(cellSysutilAvcExt, cellSysutilAvcExtGetSurfacePointer);
REG_FUNC(cellSysutilAvcExt, cellSysutilAvcExtStopMicDetection);
REG_FUNC(cellSysutilAvcExt, cellSysutilAvcExtInitOptionParam);
REG_FUNC(cellSysutilAvcExt, cellSysutilAvcExtSetWindowZorder);
});
| 12,234
|
C++
|
.cpp
| 249
| 47.120482
| 289
| 0.813077
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
5,243
|
cellL10n.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellL10n.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
#include "Emu/Memory/vm_ref.h"
#ifdef _WIN32
#include <Windows.h>
#endif
#ifdef _WIN32
typedef int HostCode;
#else
#include <iconv.h>
#include <errno.h>
typedef const char *HostCode;
#endif
#include "cellL10n.h"
#include "util/asm.hpp"
LOG_CHANNEL(cellL10n);
// Translate code id to code name. some codepage may has another name.
// If this makes your compilation fail, try replace the string code with one in "iconv -l"
bool _L10nCodeParse(s32 code, HostCode& retCode)
{
#ifdef _WIN32
retCode = 0;
if ((code >= _L10N_CODE_) || (code < 0)) return false;
switch (code)
{
case L10N_UTF8: retCode = 65001; return false;
case L10N_UTF16: retCode = 1200; return false; // 1200=LE,1201=BE
case L10N_UTF32: retCode = 12000; return false; // 12000=LE,12001=BE
case L10N_UCS2: retCode = 1200; return false; // Not in OEM, but just the same as UTF16
case L10N_UCS4: retCode = 12000; return false; // Not in OEM, but just the same as UTF32
//All OEM Code Pages are Multi-Byte, not wchar_t,u16,u32.
case L10N_ISO_8859_1: retCode = 28591; return true;
case L10N_ISO_8859_2: retCode = 28592; return true;
case L10N_ISO_8859_3: retCode = 28593; return true;
case L10N_ISO_8859_4: retCode = 28594; return true;
case L10N_ISO_8859_5: retCode = 28595; return true;
case L10N_ISO_8859_6: retCode = 28596; return true;
case L10N_ISO_8859_7: retCode = 28597; return true;
case L10N_ISO_8859_8: retCode = 28598; return true;
case L10N_ISO_8859_9: retCode = 28599; return true;
case L10N_ISO_8859_10: retCode = 28600; return true;
case L10N_ISO_8859_11: retCode = 28601; return true;
case L10N_ISO_8859_13: retCode = 28603; return true; // No ISO-8859-12 ha ha.
case L10N_ISO_8859_14: retCode = 28604; return true;
case L10N_ISO_8859_15: retCode = 28605; return true;
case L10N_ISO_8859_16: retCode = 28606; return true;
case L10N_CODEPAGE_437: retCode = 437; return true;
case L10N_CODEPAGE_850: retCode = 850; return true;
case L10N_CODEPAGE_863: retCode = 863; return true;
case L10N_CODEPAGE_866: retCode = 866; return true;
case L10N_CODEPAGE_932: retCode = 932; return true;
case L10N_CODEPAGE_936: retCode = 936; return true; // GBK
case L10N_GBK: retCode = 936; return true;
case L10N_CODEPAGE_949: retCode = 949; return true; // UHC
case L10N_UHC: retCode = 949; return true; // UHC
case L10N_CODEPAGE_950: retCode = 950; return true;
case L10N_CODEPAGE_1251: retCode = 1251; return true; // CYRL
case L10N_CODEPAGE_1252: retCode = 1252; return true; // ANSI
case L10N_EUC_CN: retCode = 51936; return true; // GB2312
case L10N_EUC_JP: retCode = 51932; return true;
case L10N_EUC_KR: retCode = 51949; return true;
case L10N_ISO_2022_JP: retCode = 50222; return true;
case L10N_JIS: retCode = 50222; return true;
// Maybe 708/720/864/1256/10004/20420/28596/
case L10N_ARIB: retCode = 20420; return true; // TODO: think that should be ARABIC.
case L10N_HZ: retCode = 52936; return true;
case L10N_GB18030: retCode = 54936; return true;
case L10N_RIS_506: retCode = 932; return true; // MS_KANJI, TODO: Code page
case L10N_SHIFT_JIS: retCode = 932; return true; // SJIS
case L10N_MUSIC_SHIFT_JIS: retCode = 932; return true; // MSJIS
// These are only supported with FW 3.10 and above
case L10N_CODEPAGE_852: retCode = 852; return true;
case L10N_CODEPAGE_1250: retCode = 1250; return true; // EE
case L10N_CODEPAGE_737: retCode = 737; return true;
case L10N_CODEPAGE_1253: retCode = 1253; return true; // Greek
case L10N_CODEPAGE_857: retCode = 857; return true;
case L10N_CODEPAGE_1254: retCode = 1254; return true; // Turk
case L10N_CODEPAGE_775: retCode = 775; return true;
case L10N_CODEPAGE_1257: retCode = 1257; return true; // WINBALTRIM
case L10N_CODEPAGE_855: retCode = 855; return true;
case L10N_CODEPAGE_858: retCode = 858; return true;
case L10N_CODEPAGE_860: retCode = 860; return true;
case L10N_CODEPAGE_861: retCode = 861; return true;
case L10N_CODEPAGE_865: retCode = 865; return true;
case L10N_CODEPAGE_869: retCode = 869; return true;
case L10N_BIG5: retCode = 950; return true; // Codepage 950
default: return false;
}
#else
if ((code >= _L10N_CODE_) || (code < 0)) return false;
switch (code)
{
// I don't know these Unicode Variants is LB or BE.
case L10N_UTF8: retCode = "UTF-8"; return true;
case L10N_UTF16: retCode = "UTF-16"; return true;
case L10N_UTF32: retCode = "UTF-32"; return true;
case L10N_UCS2: retCode = "UCS-2"; return true;
case L10N_UCS4: retCode = "UCS-4"; return true;
case L10N_ISO_8859_1: retCode = "ISO-8859-1"; return true;
case L10N_ISO_8859_2: retCode = "ISO-8859-2"; return true;
case L10N_ISO_8859_3: retCode = "ISO-8859-3"; return true;
case L10N_ISO_8859_4: retCode = "ISO-8859-4"; return true;
case L10N_ISO_8859_5: retCode = "ISO-8859-5"; return true;
case L10N_ISO_8859_6: retCode = "ISO-8859-6"; return true;
case L10N_ISO_8859_7: retCode = "ISO-8859-7"; return true;
case L10N_ISO_8859_8: retCode = "ISO-8859-8"; return true;
case L10N_ISO_8859_9: retCode = "ISO-8859-9"; return true;
case L10N_ISO_8859_10: retCode = "ISO-8859-10"; return true;
case L10N_ISO_8859_11: retCode = "ISO-8859-11"; return true;
case L10N_ISO_8859_13: retCode = "ISO-8859-13"; return true; // No ISO-8859-12 ha ha.
case L10N_ISO_8859_14: retCode = "ISO-8859-14"; return true;
case L10N_ISO_8859_15: retCode = "ISO-8859-15"; return true;
case L10N_ISO_8859_16: retCode = "ISO-8859-16"; return true;
case L10N_CODEPAGE_437: retCode = "CP437"; return true;
case L10N_CODEPAGE_850: retCode = "CP850"; return true;
case L10N_CODEPAGE_863: retCode = "CP863"; return true;
case L10N_CODEPAGE_866: retCode = "CP866"; return true;
case L10N_CODEPAGE_932: retCode = "CP932"; return true;
case L10N_CODEPAGE_936: retCode = "CP936"; return true;
case L10N_GBK: retCode = "CP936"; return true;
case L10N_CODEPAGE_949: retCode = "CP949"; return true;
case L10N_UHC: retCode = "CP949"; return true;
case L10N_CODEPAGE_950: retCode = "CP950"; return true;
case L10N_BIG5: retCode = "CP950"; return true; // BIG5 = CodePage 950
case L10N_CODEPAGE_1251: retCode = "CP1251"; return true; // CYRL
case L10N_CODEPAGE_1252: retCode = "CP1252"; return true; // ANSI
case L10N_EUC_CN: retCode = "EUC-CN"; return true; // GB2312
case L10N_EUC_JP: retCode = "EUC-JP"; return true;
case L10N_EUC_KR: retCode = "EUC-KR"; return true;
case L10N_ISO_2022_JP: retCode = "ISO-2022-JP"; return true;
case L10N_JIS: retCode = "ISO-2022-JP"; return true;
case L10N_ARIB: retCode = "ARABIC"; return true; // TODO: think that should be ARABIC.
case L10N_HZ: retCode = "HZ"; return true;
case L10N_GB18030: retCode = "GB18030"; return true;
case L10N_RIS_506: retCode = "Shift_JIS"; return true; // MS_KANJI
case L10N_SHIFT_JIS: retCode = "Shift_JIS"; return true; // CP932 for Microsoft
case L10N_MUSIC_SHIFT_JIS: retCode = "Shift_JIS"; return true; // MusicShiftJIS
// These are only supported with FW 3.10 and below
case L10N_CODEPAGE_852: retCode = "CP852"; return true;
case L10N_CODEPAGE_1250: retCode = "CP1250"; return true; // EE
case L10N_CODEPAGE_737: retCode = "CP737"; return true;
case L10N_CODEPAGE_1253: retCode = "CP1253"; return true; // Greek
case L10N_CODEPAGE_857: retCode = "CP857"; return true;
case L10N_CODEPAGE_1254: retCode = "CP1254"; return true; // Turk
case L10N_CODEPAGE_775: retCode = "CP775"; return true;
case L10N_CODEPAGE_1257: retCode = "CP1257"; return true; // WINBALTRIM
case L10N_CODEPAGE_855: retCode = "CP855"; return true;
case L10N_CODEPAGE_858: retCode = "CP858"; return true;
case L10N_CODEPAGE_860: retCode = "CP860"; return true;
case L10N_CODEPAGE_861: retCode = "CP861"; return true;
case L10N_CODEPAGE_865: retCode = "CP865"; return true;
case L10N_CODEPAGE_869: retCode = "CP869"; return true;
default: return false;
}
#endif
}
#ifdef _WIN32
// Use code page to transform std::string to std::wstring.
s32 _OEM2Wide(HostCode oem_code, const std::string& src, std::wstring& dst)
{
//Such length returned should include the '\0' character.
const s32 length = MultiByteToWideChar(oem_code, 0, src.c_str(), -1, nullptr, 0);
wchar_t *store = new wchar_t[length]();
MultiByteToWideChar(oem_code, 0, src.c_str(), -1, static_cast<LPWSTR>(store), length);
dst = std::wstring(store);
delete[] store;
store = nullptr;
return length - 1;
}
// Use Code page to transform std::wstring to std::string.
s32 _Wide2OEM(HostCode oem_code, const std::wstring& src, std::string& dst)
{
//Such length returned should include the '\0' character.
const s32 length = WideCharToMultiByte(oem_code, 0, src.c_str(), -1, nullptr, 0, nullptr, nullptr);
char *store = new char[length]();
WideCharToMultiByte(oem_code, 0, src.c_str(), -1, store, length, nullptr, nullptr);
dst = std::string(store);
delete[] store;
store = nullptr;
return length - 1;
}
// Convert Codepage to Codepage (all char*)
std::string _OemToOem(HostCode src_code, HostCode dst_code, const std::string& str)
{
std::wstring wide; std::string result;
_OEM2Wide(src_code, str, wide);
_Wide2OEM(dst_code, wide, result);
return result;
}
#endif
s32 _ConvertStr(s32 src_code, const void *src, s32 src_len, s32 dst_code, void *dst, s32 *dst_len, [[maybe_unused]] bool allowIncomplete)
{
HostCode srcCode = 0, dstCode = 0; //OEM code pages
bool src_page_converted = _L10nCodeParse(src_code, srcCode); //Check if code is in list.
bool dst_page_converted = _L10nCodeParse(dst_code, dstCode);
if (((!src_page_converted) && (srcCode == 0))
|| ((!dst_page_converted) && (dstCode == 0)))
return ConverterUnknown;
#ifdef _WIN32
const std::string wrapped_source = std::string(static_cast<const char *>(src), src_len);
const std::string target = _OemToOem(srcCode, dstCode, wrapped_source);
if (dst != nullptr)
{
if (target.length() > static_cast<usz>(*dst_len)) return DSTExhausted;
memcpy(dst, target.c_str(), target.length());
}
*dst_len = ::narrow<s32>(target.size());
return ConversionOK;
#else
s32 retValue = ConversionOK;
iconv_t ict = iconv_open(dstCode, srcCode);
usz srcLen = src_len;
if (dst != NULL)
{
usz dstLen = *dst_len;
usz ictd = iconv(ict, utils::bless<char*>(&src), &srcLen, utils::bless<char*>(&dst), &dstLen);
*dst_len -= dstLen;
if (ictd == umax)
{
if (errno == EILSEQ)
retValue = SRCIllegal; //Invalid multi-byte sequence
else if (errno == E2BIG)
retValue = DSTExhausted;//Not enough space
else if (errno == EINVAL)
{
if (allowIncomplete)
*dst_len = -1; // TODO: correct value?
else
retValue = SRCIllegal;
}
}
}
else
{
*dst_len = 0;
char buf[16];
while (srcLen > 0)
{
//char *bufPtr = buf;
usz bufLeft = sizeof(buf);
usz ictd = iconv(ict, utils::bless<char*>(&src), &srcLen, utils::bless<char*>(&dst), &bufLeft);
*dst_len += sizeof(buf) - bufLeft;
if (ictd == umax && errno != E2BIG)
{
if (errno == EILSEQ)
retValue = SRCIllegal;
else if (errno == EINVAL)
{
if (allowIncomplete)
*dst_len = -1; // TODO: correct value?
else
retValue = SRCIllegal;
}
break;
}
}
}
iconv_close(ict);
return retValue;
#endif
}
s32 _L10nConvertStr(s32 src_code, vm::cptr<void> src, vm::cptr<s32> src_len, s32 dst_code, vm::ptr<void> dst, vm::ptr<s32> dst_len)
{
s32 dstLen = *dst_len;
s32 result = _ConvertStr(src_code, src.get_ptr(), *src_len, dst_code, dst ? dst.get_ptr() : nullptr, &dstLen, false);
*dst_len = dstLen;
return result;
}
s32 _L10nConvertChar(s32 src_code, const void *src, s32 src_len, s32 dst_code, vm::ptr<void> dst, vm::ptr<s32> dst_len)
{
s32 dstLen = 0x7FFFFFFF;
s32 result = _ConvertStr(src_code, src, src_len, dst_code, dst.get_ptr(), &dstLen, true);
*dst_len = dstLen;
return result;
}
s32 _L10nConvertCharNoResult(s32 src_code, const void *src, s32 src_len, s32 dst_code, vm::ptr<void> dst)
{
s32 dstLen = 0x7FFFFFFF;
[[maybe_unused]] s32 result = _ConvertStr(src_code, src, src_len, dst_code, dst.get_ptr(), &dstLen, true);
return dstLen;
}
s32 UCS2toEUCJP()
{
cellL10n.todo("UCS2toEUCJP()");
return 0;
}
s32 l10n_convert()
{
cellL10n.todo("l10n_convert()");
return 0;
}
s32 UCS2toUTF32()
{
cellL10n.todo("UCS2toUTF32()");
return 0;
}
s32 jis2kuten()
{
cellL10n.todo("jis2kuten()");
return 0;
}
s32 UTF8toGB18030()
{
cellL10n.todo("UTF8toGB18030()");
return ConversionOK;
}
s32 JISstoUTF8s(vm::cptr<u8> src, vm::cptr<s32> src_len, vm::ptr<u8> dst, vm::ptr<s32> dst_len)
{
cellL10n.todo("JISstoUTF8s(src=*0x%x, src_len=*0x%x, dst=*0x%x, dst_len=*0x%x)", src, src_len, dst, dst_len);
return ConversionOK;
}
s32 SjisZen2Han(vm::cptr<u16> src)
{
cellL10n.todo("SjisZen2Han(src=*0x%x)", src);
return ConversionOK;
}
s32 ToSjisLower()
{
cellL10n.todo("ToSjisLower()");
return ConversionOK;
}
s32 UCS2toGB18030()
{
cellL10n.todo("UCS2toGB18030()");
return ConversionOK;
}
s32 HZstoUCS2s(vm::cptr<u8> src, vm::cptr<s32> src_len, vm::ptr<u16> dst, vm::ptr<s32> dst_len)
{
cellL10n.todo("HZstoUCS2s(src=*0x%x, src_len=*0x%x, dst=*0x%x, dst_len=*0x%x)", src, src_len, dst, dst_len);
return ConversionOK;
}
s32 UCS2stoHZs(vm::cptr<u16> src, vm::cptr<s32> src_len, vm::ptr<u8> dst, vm::ptr<s32> dst_len)
{
cellL10n.todo("UCS2stoHZs(src=*0x%x, src_len=*0x%x, dst=*0x%x, dst_len=*0x%x)", src, src_len, dst, dst_len);
return ConversionOK;
}
s32 UCS2stoSJISs(vm::cptr<u16> src, vm::cptr<s32> src_len, vm::ptr<u8> dst, vm::ptr<s32> dst_len)
{
cellL10n.todo("UCS2stoSJISs(src=*0x%x, src_len=*0x%x, dst=*0x%x, dst_len=*0x%x)", src, src_len, dst, dst_len);
return ConversionOK;
}
s32 kuten2eucjp()
{
cellL10n.todo("kuten2eucjp()");
return 0;
}
s32 sjis2jis()
{
cellL10n.todo("sjis2jis()");
return 0;
}
s32 EUCKRstoUCS2s(vm::cptr<u8> src, vm::cptr<s32> src_len, vm::ptr<u16> dst, vm::ptr<s32> dst_len)
{
cellL10n.todo("EUCKRstoUCS2s(src=*0x%x, src_len=*0x%x, dst=*0x%x, dst_len=*0x%x)", src, src_len, dst, dst_len);
return ConversionOK;
}
s32 UHCstoEUCKRs(vm::cptr<u8> src, vm::cptr<s32> src_len, vm::ptr<u8> dst, vm::ptr<s32> dst_len)
{
cellL10n.todo("UHCstoEUCKRs(src=*0x%x, src_len=*0x%x, dst=*0x%x, dst_len=*0x%x)", src, src_len, dst, dst_len);
return ConversionOK;
}
s32 jis2sjis()
{
cellL10n.todo("jis2sjis()");
return 0;
}
s32 jstrnchk(vm::cptr<u8> src, s32 src_len)
{
u8 r = 0;
for (s32 len = 0; len < src_len; len++)
{
if (src)
{
if (*src >= 0xa1 && *src <= 0xfe)
{
cellL10n.warning("jstrnchk: EUCJP (src=*0x%x, src_len=*0x%x)", src, src_len);
r |= L10N_STR_EUCJP;
}
else if( ((*src >= 0x81 && *src <= 0x9f) || (*src >= 0xe0 && *src <= 0xfc)) || (*src >= 0x40 && *src <= 0xfc && *src != 0x7f) )
{
cellL10n.warning("jstrnchk: SJIS (src=*0x%x, src_len=*0x%x)", src, src_len);
r |= L10N_STR_SJIS;
}
// ISO-2022-JP. (JIS X 0202) That's an inaccurate general range which (contains ASCII and UTF-8 characters?).
else if (*src >= 0x21 && *src <= 0x7e)
{
cellL10n.warning("jstrnchk: JIS (src=*0x%x, src_len=*0x%x)", src, src_len);
r |= L10N_STR_JIS;
}
else
{
cellL10n.todo("jstrnchk: Unimplemented (src=*0x%x, src_len=*0x%x)", src, src_len);
}
// TODO:
// L10N_STR_ASCII
// L10N_STR_UTF8
// L10N_STR_UNKNOWN
// L10N_STR_ILLEGAL
// L10N_STR_ERROR
}
src++;
}
return r;
}
s32 L10nConvert()
{
cellL10n.todo("L10nConvert()");
return 0;
}
s32 EUCCNstoUTF8s()
{
cellL10n.todo("EUCCNstoUTF8s()");
return ConversionOK;
}
s32 GBKstoUCS2s()
{
cellL10n.todo("GBKstoUCS2s()");
return ConversionOK;
}
s32 eucjphan2zen(vm::cptr<u16> src)
{
cellL10n.todo("eucjphan2zen()");
return *src; // Returns the character itself if conversion fails
}
s32 ToSjisHira()
{
cellL10n.todo("ToSjisHira()");
return ConversionOK;
}
s32 GBKtoUCS2()
{
cellL10n.todo("GBKtoUCS2()");
return ConversionOK;
}
s32 eucjp2jis()
{
cellL10n.todo("eucjp2jis()");
return CELL_OK;
}
s32 UTF32stoUTF8s(vm::cptr<u32> src, vm::cptr<s32> src_len, vm::ptr<u8> dst, vm::ptr<s32> dst_len)
{
cellL10n.todo("UTF32stoUTF8s(src=*0x%x, src_len=*0x%x, dst=*0x%x, dst_len=*0x%x)", src, src_len, dst, dst_len);
return ConversionOK;
}
s32 sjishan2zen()
{
cellL10n.todo("sjishan2zen()");
return 0;
}
s32 UCS2toSBCS()
{
cellL10n.todo("UCS2toSBCS()");
return 0;
}
s32 UTF8stoGBKs()
{
cellL10n.todo("UCS2toSBCS()");
return ConversionOK;
}
s32 UTF8toUCS2()
{
cellL10n.todo("UTF8toUCS2()");
return 0;
}
s32 UCS2stoUTF8s(vm::cptr<u16> src, vm::cptr<s32> src_len, vm::ptr<u8> dst, vm::ptr<s32> dst_len)
{
cellL10n.todo("UCS2stoUTF8s(src=*0x%x, src_len=*0x%x, dst=*0x%x, dst_len=*0x%x)", src, src_len, dst, dst_len);
return ConversionOK;
}
s32 EUCKRstoUTF8s()
{
cellL10n.todo("EUCKRstoUTF8s()");
return ConversionOK;
}
s32 UTF16stoUTF32s(vm::cptr<u16> src, vm::cptr<s32> src_len, vm::ptr<u32> dst, vm::ptr<s32> dst_len)
{
cellL10n.warning("UTF16stoUTF32s(src=*0x%x, src_len=*0x%x, dst=*0x%x, dst_len=*0x%x)", src, src_len, dst, dst_len);
return _L10nConvertStr(L10N_UTF16, src, src_len, L10N_UTF32, dst, dst_len);
}
s32 UTF8toEUCKR()
{
cellL10n.todo("UTF8toEUCKR()");
return 0;
}
s32 UTF16toUTF8()
{
cellL10n.todo("UTF16toUTF8()");
return 0;
}
s32 ARIBstoUTF8s()
{
cellL10n.todo("ARIBstoUTF8s()");
return ConversionOK;
}
s32 SJISstoUTF8s(vm::cptr<void> src, vm::cptr<s32> src_len, vm::ptr<void> dst, vm::ptr<s32> dst_len)
{
cellL10n.warning("SJISstoUTF8s(src=*0x%x, src_len=*0x%x, dst=*0x%x, dst_len=*0x%x)", src, src_len, dst, dst_len);
return _L10nConvertStr(L10N_CODEPAGE_932, src, src_len, L10N_UTF8, dst, dst_len);
}
s32 sjiszen2han(vm::cptr<u16> src)
{
cellL10n.todo("sjiszen2han()");
return *src; // Returns the character itself if conversion fails
}
s32 ToEucJpLower()
{
cellL10n.todo("ToEucJpLower()");
return ConversionOK;
}
s32 MSJIStoUTF8()
{
cellL10n.todo("MSJIStoUTF8()");
return 0;
}
s32 UCS2stoMSJISs()
{
cellL10n.todo("UCS2stoMSJISs()");
return ConversionOK;
}
s32 EUCJPtoUTF8()
{
cellL10n.todo("EUCJPtoUTF8()");
return 0;
}
s32 eucjp2sjis()
{
cellL10n.todo("eucjp2sjis()");
return 0;
}
s32 ToEucJpHira()
{
cellL10n.todo("ToEucJpHira()");
return ConversionOK;
}
s32 UHCstoUCS2s()
{
cellL10n.todo("UHCstoUCS2s()");
return ConversionOK;
}
s32 ToEucJpKata()
{
cellL10n.todo("ToEucJpKata()");
return ConversionOK;
}
s32 HZstoUTF8s(vm::cptr<u8> src, vm::cptr<s32> src_len, vm::ptr<u8> dst, vm::ptr<s32> dst_len)
{
cellL10n.todo("HZstoUTF8s(src=*0x%x, src_len=*0x%x, dst=*0x%x, dst_len=*0x%x)", src, src_len, dst, dst_len);
return ConversionOK;
}
s32 UTF8toMSJIS()
{
cellL10n.todo("UTF8toMSJIS()");
return 0;
}
s32 BIG5toUTF8()
{
cellL10n.todo("BIG5toUTF8()");
return 0;
}
s32 EUCJPstoSJISs(vm::cptr<u8> src, vm::cptr<s32> src_len, vm::ptr<u8> dst, vm::ptr<s32> dst_len)
{
cellL10n.todo("EUCJPstoSJISs(src=*0x%x, src_len=*0x%x, dst=*0x%x, dst_len=*0x%x)", src, src_len, dst, dst_len);
return ConversionOK;
}
s32 UTF8stoBIG5s()
{
cellL10n.todo("UTF8stoBIG5s()");
return ConversionOK;
}
s32 UTF16stoUCS2s(vm::cptr<u16> src, vm::cptr<s32> src_len, vm::ptr<u16> dst, vm::ptr<s32> dst_len)
{
cellL10n.warning("UTF16stoUCS2s(src=*0x%x, src_len=*0x%x, dst=*0x%x, dst_len=*0x%x)", src, src_len, dst, dst_len);
return _L10nConvertStr(L10N_UTF16, src, src_len, L10N_UCS2, dst, dst_len);
}
s32 UCS2stoGB18030s()
{
cellL10n.todo("UCS2stoGB18030s()");
return ConversionOK;
}
s32 EUCJPtoSJIS()
{
cellL10n.todo("EUCJPtoSJIS()");
return 0;
}
s32 EUCJPtoUCS2()
{
cellL10n.todo("EUCJPtoUCS2()");
return 0;
}
s32 UCS2stoGBKs()
{
cellL10n.todo("UCS2stoGBKs()");
return ConversionOK;
}
s32 EUCKRtoUHC()
{
cellL10n.todo("EUCKRtoUHC()");
return 0;
}
s32 UCS2toSJIS(u16 ch, vm::ptr<void> dst)
{
cellL10n.todo("UCS2toSJIS(ch=%d, dst=*0x%x)", ch, dst);
// Should be L10N_UCS2 (16bit) not L10N_UTF8 (8bit) and L10N_SHIFT_JIS
// return _L10nConvertCharNoResult(L10N_UTF8, &ch, sizeof(ch), L10N_CODEPAGE_932, dst);
return 0;
}
s32 MSJISstoUTF8s()
{
cellL10n.todo("MSJISstoUTF8s()");
return ConversionOK;
}
s32 EUCJPstoUTF8s(vm::cptr<u8> src, vm::cptr<s32> src_len, vm::ptr<u8> dst, vm::ptr<s32> dst_len)
{
cellL10n.todo("EUCJPstoUTF8s(src=*0x%x, src_len=*0x%x, dst=*0x%x, dst_len=*0x%x)", src, src_len, dst, dst_len);
return ConversionOK;
}
s32 UCS2toBIG5()
{
cellL10n.todo("UCS2toBIG5()");
return 0;
}
s32 UTF8stoEUCKRs()
{
cellL10n.todo("UTF8stoEUCKRs()");
return ConversionOK;
}
s32 UHCstoUTF8s()
{
cellL10n.todo("UHCstoUTF8s()");
return ConversionOK;
}
s32 GB18030stoUCS2s()
{
cellL10n.todo("GB18030stoUCS2s()");
return ConversionOK;
}
s32 SJIStoUTF8(u8 ch, vm::ptr<void> dst, vm::ptr<s32> dst_len)
{
cellL10n.todo("SJIStoUTF8(ch=%d, dst=*0x%x, dst_len=*0x%x)", ch, dst, dst_len);
return 0;
}
s32 JISstoSJISs(vm::cptr<u8> src, vm::cptr<s32> src_len, vm::ptr<u8> dst, vm::ptr<s32> dst_len)
{
cellL10n.todo("JISstoSJISs(src=*0x%x, src_len=*0x%x, dst=*0x%x, dst_len=*0x%x)", src, src_len, dst, dst_len);
return 0;
}
s32 UTF8toUTF16()
{
cellL10n.todo("UTF8toUTF16()");
return 0;
}
s32 UTF8stoMSJISs()
{
cellL10n.todo("UTF8stoMSJISs()");
return ConversionOK;
}
s32 EUCKRtoUTF8()
{
cellL10n.todo("EUCKRtoUTF8()");
return 0;
}
s32 SjisHan2Zen()
{
cellL10n.todo("SjisHan2Zen()");
return ConversionOK;
}
s32 UCS2toUTF16()
{
cellL10n.todo("UCS2toUTF16()");
return 0;
}
s32 UCS2toMSJIS()
{
cellL10n.todo("UCS2toMSJIS()");
return 0;
}
s32 sjis2kuten()
{
cellL10n.todo("sjis2kuten()");
return 0;
}
s32 UCS2toUHC()
{
cellL10n.todo("UCS2toUHC()");
return 0;
}
s32 UTF32toUCS2()
{
cellL10n.todo("UTF32toUCS2()");
return 0;
}
s32 ToSjisUpper()
{
cellL10n.todo("ToSjisUpper()");
return ConversionOK;
}
s32 UTF8toEUCJP()
{
cellL10n.todo("UTF8toEUCJP()");
return 0;
}
s32 UCS2stoEUCJPs()
{
cellL10n.todo("UCS2stoEUCJPs()");
return ConversionOK;
}
s32 UTF16toUCS2()
{
cellL10n.todo("UTF16toUCS2()");
return 0;
}
s32 UCS2stoUTF16s(vm::cptr<u16> src, vm::cptr<s32> src_len, vm::ptr<u16> dst, vm::ptr<s32> dst_len)
{
cellL10n.todo("UCS2stoUTF16s(src=*0x%x, src_len=*0x%x, dst=*0x%x, dst_len=*0x%x)", src, src_len, dst, dst_len);
return ConversionOK;
}
s32 UCS2stoEUCCNs()
{
cellL10n.todo("UCS2stoEUCCNs()");
return ConversionOK;
}
s32 SBCSstoUTF8s(vm::cptr<u8> src, vm::cptr<s32> src_len, vm::ptr<u8> dst, vm::ptr<s32> dst_len, s32 enc)
{
cellL10n.warning("SBCSstoUTF8s(src=*0x%x, src_len=*0x%x, dst=*0x%x, dst_len=*0x%x, enc=*0x%x)", src, src_len, dst, dst_len, enc);
return _L10nConvertStr(enc, src, src_len, L10N_UTF8, dst, dst_len); // Might not work in some scenarios
}
s32 SJISstoJISs(vm::cptr<u8> src, vm::cptr<s32> src_len, vm::ptr<u8> dst, vm::ptr<s32> dst_len)
{
cellL10n.todo("SJISstoJISs(src=*0x%x, src_len=*0x%x, dst=*0x%x, dst_len=*0x%x)", src, src_len, dst, dst_len);
return 0;
}
s32 SBCStoUTF8()
{
cellL10n.todo("SBCStoUTF8()");
return 0;
}
s32 UTF8toUTF32()
{
cellL10n.todo("UTF8toUTF32()");
return 0;
}
s32 jstrchk(vm::cptr<u8> jstr)
{
cellL10n.todo("jstrchk(jstr=*0x%x) -> utf8", jstr);
// TODO: Actually detect the type of the string
return L10N_STR_UTF8;
}
s32 UHCtoEUCKR()
{
cellL10n.todo("UHCtoEUCKR()");
return 0;
}
s32 kuten2jis()
{
cellL10n.todo("kuten2jis()");
return 0;
}
s32 UTF8toEUCCN()
{
cellL10n.todo("UTF8toEUCCN()");
return 0;
}
s32 EUCCNtoUTF8()
{
cellL10n.todo("EUCCNtoUTF8()");
return 0;
}
s32 EucJpZen2Han()
{
cellL10n.todo("EucJpZen2Han()");
return ConversionOK;
}
s32 UTF32stoUTF16s(vm::cptr<u32> src, vm::cptr<s32> src_len, vm::ptr<u16> dst, vm::ptr<s32> dst_len)
{
cellL10n.todo("UTF32stoUTF16s(src=*0x%x, src_len=*0x%x, dst=*0x%x, dst_len=*0x%x)", src, src_len, dst, dst_len);
return ConversionOK;
}
s32 GBKtoUTF8()
{
cellL10n.todo("GBKtoUTF8()");
return 0;
}
s32 ToEucJpUpper()
{
cellL10n.todo("ToEucJpUpper()");
return ConversionOK;
}
s32 UCS2stoJISs()
{
cellL10n.todo("UCS2stoJISs()");
return ConversionOK;
}
s32 UTF8stoGB18030s()
{
cellL10n.todo("UTF8stoGB18030s()");
return ConversionOK;
}
s32 EUCKRstoUHCs(vm::cptr<u8> src, vm::cptr<s32> src_len, vm::ptr<u8> dst, vm::ptr<s32> dst_len)
{
cellL10n.todo("EUCKRstoUHCs(src=*0x%x, src_len=*0x%x, dst=*0x%x, dst_len=*0x%x)", src, src_len, dst, dst_len);
return 0;
}
s32 UTF8stoUTF32s(vm::cptr<u8> src, vm::cptr<s32> src_len, vm::ptr<u32> dst, vm::ptr<s32> dst_len)
{
cellL10n.todo("UTF8stoUTF32s(src=*0x%x, src_len=*0x%x, dst=*0x%x, dst_len=*0x%x)", src, src_len, dst, dst_len);
return ConversionOK;
}
s32 UTF8stoEUCCNs()
{
cellL10n.todo("UTF8stoEUCCNs()");
return ConversionOK;
}
s32 EUCJPstoUCS2s(vm::cptr<u8> src, vm::cptr<s32> src_len, vm::ptr<u16> dst, vm::ptr<s32> dst_len)
{
cellL10n.todo("EUCJPstoUCS2s(src=*0x%x, src_len=*0x%x, dst=*0x%x, dst_len=*0x%x)", src, src_len, dst, dst_len);
return 0;
}
s32 UHCtoUCS2()
{
cellL10n.todo("UHCtoUCS2()");
return 0;
}
s32 L10nConvertStr(s32 src_code, vm::cptr<void> src, vm::ptr<s32> src_len, s32 dst_code, vm::ptr<void> dst, vm::ptr<s32> dst_len)
{
cellL10n.error("L10nConvertStr(src_code=%d, src=*0x%x, src_len=*0x%x, dst_code=%d, dst=*0x%x, dst_len=*0x%x)", src_code, src, src_len, dst_code, dst, dst_len);
return _L10nConvertStr(src_code, src, src_len, dst_code, dst, dst_len);
}
s32 GBKstoUTF8s()
{
cellL10n.todo("GBKstoUTF8s()");
return ConversionOK;
}
s32 UTF8toUHC()
{
cellL10n.todo("UTF8toUHC()");
return 0;
}
s32 UTF32toUTF8()
{
cellL10n.todo("UTF32toUTF8()");
return 0;
}
s32 sjis2eucjp()
{
cellL10n.todo("sjis2eucjp()");
return 0;
}
s32 UCS2toEUCCN()
{
cellL10n.todo("UCS2toEUCCN()");
return 0;
}
s32 UTF8stoUHCs()
{
cellL10n.todo("UTF8stoUHCs()");
return ConversionOK;
}
s32 EUCKRtoUCS2()
{
cellL10n.todo("EUCKRtoUCS2()");
return 0;
}
s32 UTF32toUTF16()
{
cellL10n.todo("UTF32toUTF16()");
return 0;
}
s32 EUCCNstoUCS2s()
{
cellL10n.todo("EUCCNstoUCS2s()");
return ConversionOK;
}
s32 SBCSstoUCS2s()
{
cellL10n.todo("SBCSstoUCS2s()");
return ConversionOK;
}
s32 UTF8stoJISs(vm::cptr<u8> src, vm::cptr<s32> src_len, vm::ptr<u8> dst, vm::ptr<s32> dst_len)
{
cellL10n.todo("UTF8stoJISs(src=*0x%x, src_len=*0x%x, dst=*0x%x, dst_len=*0x%x)", src, src_len, dst, dst_len);
return 0;
}
s32 ToSjisKata()
{
cellL10n.todo("ToSjisKata()");
return 0;
}
s32 jis2eucjp()
{
cellL10n.todo("jis2eucjp()");
return 0;
}
s32 BIG5toUCS2()
{
cellL10n.todo("BIG5toUCS2()");
return 0;
}
s32 UCS2toGBK()
{
cellL10n.todo("UCS2toGBK()");
return 0;
}
s32 UTF16toUTF32()
{
cellL10n.todo("UTF16toUTF32()");
return 0;
}
s32 l10n_convert_str(s32 cd, vm::cptr<void> src, vm::ptr<s32> src_len, vm::ptr<void> dst, vm::ptr<s32> dst_len)
{
cellL10n.warning("l10n_convert_str(cd=%d, src=*0x%x, src_len=*0x%x, dst=*0x%x, dst_len=*0x%x)", cd, src, src_len, dst, dst_len);
s32 src_code = cd >> 16;
s32 dst_code = cd & 0xffff;
return _L10nConvertStr(src_code, src, src_len, dst_code, dst, dst_len);
}
s32 EUCJPstoJISs(vm::cptr<u8> src, vm::cptr<s32> src_len, vm::ptr<u8> dst, vm::ptr<s32> dst_len)
{
cellL10n.warning("EUCJPstoJISs(src=*0x%x, src_len=*0x%x, dst=*0x%x, dst_len=*0x%x)", src, src_len, dst, dst_len);
return _L10nConvertStr(L10N_EUC_JP, src, src_len, L10N_ISO_2022_JP, dst, dst_len);
}
s32 UTF8stoARIBs()
{
cellL10n.todo("UTF8stoARIBs()");
return ConversionOK;
}
s32 JISstoEUCJPs()
{
cellL10n.todo("JISstoEUCJPs()");
return ConversionOK;
}
s32 EucJpHan2Zen()
{
cellL10n.todo("EucJpHan2Zen()");
return ConversionOK;
}
s32 isEucJpKigou()
{
cellL10n.todo("isEucJpKigou()");
return 0;
}
s32 UCS2toUTF8()
{
cellL10n.todo("UCS2toUTF8()");
return 0;
}
s32 GB18030toUCS2()
{
cellL10n.todo("GB18030toUCS2()");
return 0;
}
s32 UHCtoUTF8()
{
cellL10n.todo("UHCtoUTF8()");
return 0;
}
s32 MSJIStoUCS2()
{
cellL10n.todo("MSJIStoUCS2()");
return 0;
}
s32 UTF8toGBK()
{
cellL10n.todo("UTF8toGBK()");
return 0;
}
s32 kuten2sjis()
{
cellL10n.todo("kuten2sjis()");
return 0;
}
s32 UTF8toSBCS()
{
cellL10n.todo("UTF8toSBCS()");
return 0;
}
s32 SJIStoUCS2()
{
cellL10n.todo("SJIStoUCS2()");
return 0;
}
s32 eucjpzen2han(vm::cptr<u16> src)
{
cellL10n.todo("eucjpzen2han()");
return *src; // Returns the character itself if conversion fails
}
s32 UCS2stoARIBs()
{
cellL10n.todo("UCS2stoARIBs()");
return ConversionOK;
}
s32 isSjisKigou()
{
cellL10n.todo("isSjisKigou()");
return 0;
}
s32 UTF8stoEUCJPs()
{
cellL10n.todo("UTF8stoEUCJPs()");
return ConversionOK;
}
s32 UCS2toEUCKR()
{
cellL10n.todo("UCS2toEUCKR()");
return 0;
}
s32 SBCStoUCS2()
{
cellL10n.todo("SBCStoUCS2()");
return 0;
}
s32 MSJISstoUCS2s()
{
cellL10n.todo("MSJISstoUCS2s()");
return ConversionOK;
}
s32 l10n_get_converter(u32 src_code, u32 dst_code)
{
cellL10n.warning("l10n_get_converter(src_code=%d, dst_code=%d)", src_code, dst_code);
return (src_code << 16) | dst_code;
}
s32 GB18030stoUTF8s()
{
cellL10n.todo("GB18030stoUTF8s()");
return ConversionOK;
}
s32 SJISstoEUCJPs(vm::cptr<u8> src, vm::cptr<s32> src_len, vm::ptr<u8> dst, vm::ptr<s32> dst_len)
{
cellL10n.todo("SJISstoEUCJPs(src=*0x%x, src_len=*0x%x, dst=*0x%x, dst_len=*0x%x)", src, src_len, dst, dst_len);
return 0;
}
s32 UTF32stoUCS2s(vm::cptr<u32> src, vm::cptr<s32> src_len, vm::ptr<u16> dst, vm::ptr<s32> dst_len)
{
cellL10n.todo("UTF32stoUCS2s(src=*0x%x, src_len=*0x%x, dst=*0x%x, dst_len=*0x%x)", src, src_len, dst, dst_len);
return ConversionOK;
}
s32 BIG5stoUTF8s(vm::cptr<u8> src, vm::cptr<s32> src_len, vm::ptr<u8> dst, vm::ptr<s32> dst_len)
{
cellL10n.todo("BIG5stoUTF8s(src=*0x%x, src_len=*0x%x, dst=*0x%x, dst_len=*0x%x)", src, src_len, dst, dst_len);
return 0;
}
s32 EUCCNtoUCS2()
{
cellL10n.todo("EUCCNtoUCS2()");
return CELL_OK;
}
s32 UTF8stoSBCSs()
{
cellL10n.todo("UTF8stoSBCSs()");
return ConversionOK;
}
s32 UCS2stoEUCKRs(vm::cptr<u16> src, vm::cptr<s32> src_len, vm::ptr<u8> dst, vm::ptr<s32> dst_len)
{
cellL10n.todo("UCS2stoEUCKRs(src=*0x%x, src_len=*0x%x, dst=*0x%x, dst_len=*0x%x)", src, src_len, dst, dst_len);
return 0;
}
s32 UTF8stoSJISs()
{
cellL10n.todo("UTF8stoSJISs()");
return ConversionOK;
}
s32 UTF8stoHZs()
{
cellL10n.todo("UTF8stoHZs()");
return 0;
}
s32 eucjp2kuten()
{
cellL10n.todo("eucjp2kuten()");
return 0;
}
s32 UTF8toBIG5()
{
cellL10n.todo("UTF8toBIG5()");
return 0;
}
s32 UTF16stoUTF8s(vm::cptr<u16> utf16, vm::ref<s32> utf16_len, vm::ptr<u8> utf8, vm::ref<s32> utf8_len)
{
cellL10n.error("UTF16stoUTF8s(utf16=*0x%x, utf16_len=*0x%x, utf8=*0x%x, utf8_len=*0x%x)", utf16, utf16_len.addr(), utf8, utf8_len.addr());
const u32 max_len = utf8_len; utf8_len = 0;
for (u32 i = 0, len = 0; i < static_cast<u32>(utf16_len); i++, utf8_len = len)
{
const u16 ch = utf16[i];
// increase required length (TODO)
len = len + 1;
// validate character (TODO)
//if ()
//{
// utf16_len -= i;
// return SRCIllegal;
//}
if (utf8)
{
if (len > max_len)
{
utf16_len -= i;
return DSTExhausted;
}
if (ch <= 0x7f)
{
*utf8++ = static_cast<u8>(ch);
}
else
{
*utf8++ = '?'; // TODO
}
}
}
return ConversionOK;
}
s32 JISstoUCS2s()
{
cellL10n.todo("JISstoUCS2s()");
return ConversionOK;
}
s32 GB18030toUTF8()
{
cellL10n.todo("GB18030toUTF8()");
return 0;
}
s32 UTF8toSJIS(u8 ch, vm::ptr<u8> dst, vm::ptr<s32> dst_len) // Doesn't work backwards
{
cellL10n.warning("UTF8toSJIS(ch=%d, dst=*0x%x, dst_len=*0x%x)", ch, dst, dst_len);
return _L10nConvertChar(L10N_UTF8, &ch, sizeof(ch), L10N_CODEPAGE_932, dst, dst_len);
}
s32 ARIBstoUCS2s()
{
cellL10n.todo("ARIBstoUCS2s()");
return ConversionOK;
}
s32 UCS2stoUTF32s(vm::cptr<u16> src, vm::cptr<s32> src_len, vm::ptr<u32> dst, vm::ptr<s32> dst_len)
{
cellL10n.todo("UCS2stoUTF32s(src=*0x%x, src_len=*0x%x, dst=*0x%x, dst_len=*0x%x)", src, src_len, dst, dst_len);
return ConversionOK;
}
s32 UCS2stoSBCSs()
{
cellL10n.todo("UCS2stoSBCSs()");
return ConversionOK;
}
s32 UCS2stoBIG5s()
{
cellL10n.todo("UCS2stoBIG5s()");
return ConversionOK;
}
s32 UCS2stoUHCs()
{
cellL10n.todo("UCS2stoUHCs()");
return ConversionOK;
}
s32 SJIStoEUCJP()
{
cellL10n.todo("SJIStoEUCJP()");
return 0;
}
s32 UTF8stoUTF16s(vm::cptr<u8> src, vm::cptr<s32> src_len, vm::ptr<u16> dst, vm::ptr<s32> dst_len)
{
cellL10n.warning("UTF8stoUTF16s(src=*0x%x, src_len=*0x%x, dst=*0x%x, dst_len=*0x%x)", src, src_len, dst, dst_len);
return _L10nConvertStr(L10N_UTF8, src, src_len, L10N_UTF16, dst, dst_len);
}
s32 SJISstoUCS2s(vm::cptr<u8> src, vm::cptr<s32> src_len, vm::ptr<u16> dst, vm::ptr<s32> dst_len)
{
cellL10n.warning("SJISstoUCS2s(src=*0x%x, src_len=*0x%x, dst=*0x%x, dst_len=*0x%x)", src, src_len, dst, dst_len);
return _L10nConvertStr(L10N_CODEPAGE_932, src, src_len, L10N_UCS2, dst, dst_len);
}
s32 BIG5stoUCS2s()
{
cellL10n.todo("BIG5stoUCS2s()");
return ConversionOK;
}
s32 UTF8stoUCS2s(vm::cptr<u8> src, vm::cptr<s32> src_len, vm::ptr<u16> dst, vm::ptr<s32> dst_len)
{
cellL10n.todo("UTF8stoUCS2s(src=*0x%x, src_len=*0x%x, dst=*0x%x, dst_len=*0x%x)", src, src_len, dst, dst_len);
return ConversionOK;
}
DECLARE(ppu_module_manager::cellL10n)("cellL10n", []()
{
REG_FUNC(cellL10n, UCS2toEUCJP);
REG_FUNC(cellL10n, l10n_convert);
REG_FUNC(cellL10n, UCS2toUTF32);
REG_FUNC(cellL10n, jis2kuten);
REG_FUNC(cellL10n, UTF8toGB18030);
REG_FUNC(cellL10n, JISstoUTF8s);
REG_FUNC(cellL10n, SjisZen2Han);
REG_FUNC(cellL10n, ToSjisLower);
REG_FUNC(cellL10n, UCS2toGB18030);
REG_FUNC(cellL10n, HZstoUCS2s);
REG_FUNC(cellL10n, UCS2stoHZs);
REG_FUNC(cellL10n, UCS2stoSJISs);
REG_FUNC(cellL10n, kuten2eucjp);
REG_FUNC(cellL10n, sjis2jis);
REG_FUNC(cellL10n, EUCKRstoUCS2s);
REG_FUNC(cellL10n, UHCstoEUCKRs);
REG_FUNC(cellL10n, jis2sjis);
REG_FUNC(cellL10n, jstrnchk);
REG_FUNC(cellL10n, L10nConvert);
REG_FUNC(cellL10n, EUCCNstoUTF8s);
REG_FUNC(cellL10n, GBKstoUCS2s);
REG_FUNC(cellL10n, eucjphan2zen);
REG_FUNC(cellL10n, ToSjisHira);
REG_FUNC(cellL10n, GBKtoUCS2);
REG_FUNC(cellL10n, eucjp2jis);
REG_FUNC(cellL10n, UTF32stoUTF8s);
REG_FUNC(cellL10n, sjishan2zen);
REG_FUNC(cellL10n, UCS2toSBCS);
REG_FUNC(cellL10n, UTF8stoGBKs);
REG_FUNC(cellL10n, UTF8toUCS2);
REG_FUNC(cellL10n, UCS2stoUTF8s);
REG_FUNC(cellL10n, EUCKRstoUTF8s);
REG_FUNC(cellL10n, UTF16stoUTF32s);
REG_FUNC(cellL10n, UTF8toEUCKR);
REG_FUNC(cellL10n, UTF16toUTF8);
REG_FUNC(cellL10n, ARIBstoUTF8s);
REG_FUNC(cellL10n, SJISstoUTF8s);
REG_FUNC(cellL10n, sjiszen2han);
REG_FUNC(cellL10n, ToEucJpLower);
REG_FUNC(cellL10n, MSJIStoUTF8);
REG_FUNC(cellL10n, UCS2stoMSJISs);
REG_FUNC(cellL10n, EUCJPtoUTF8);
REG_FUNC(cellL10n, eucjp2sjis);
REG_FUNC(cellL10n, ToEucJpHira);
REG_FUNC(cellL10n, UHCstoUCS2s);
REG_FUNC(cellL10n, ToEucJpKata);
REG_FUNC(cellL10n, HZstoUTF8s);
REG_FUNC(cellL10n, UTF8toMSJIS);
REG_FUNC(cellL10n, BIG5toUTF8);
REG_FUNC(cellL10n, EUCJPstoSJISs);
REG_FUNC(cellL10n, UTF8stoBIG5s);
REG_FUNC(cellL10n, UTF16stoUCS2s);
REG_FUNC(cellL10n, UCS2stoGB18030s);
REG_FUNC(cellL10n, EUCJPtoSJIS);
REG_FUNC(cellL10n, EUCJPtoUCS2);
REG_FUNC(cellL10n, UCS2stoGBKs);
REG_FUNC(cellL10n, EUCKRtoUHC);
REG_FUNC(cellL10n, UCS2toSJIS);
REG_FUNC(cellL10n, MSJISstoUTF8s);
REG_FUNC(cellL10n, EUCJPstoUTF8s);
REG_FUNC(cellL10n, UCS2toBIG5);
REG_FUNC(cellL10n, UTF8stoEUCKRs);
REG_FUNC(cellL10n, UHCstoUTF8s);
REG_FUNC(cellL10n, GB18030stoUCS2s);
REG_FUNC(cellL10n, SJIStoUTF8);
REG_FUNC(cellL10n, JISstoSJISs);
REG_FUNC(cellL10n, UTF8toUTF16);
REG_FUNC(cellL10n, UTF8stoMSJISs);
REG_FUNC(cellL10n, EUCKRtoUTF8);
REG_FUNC(cellL10n, SjisHan2Zen);
REG_FUNC(cellL10n, UCS2toUTF16);
REG_FUNC(cellL10n, UCS2toMSJIS);
REG_FUNC(cellL10n, sjis2kuten);
REG_FUNC(cellL10n, UCS2toUHC);
REG_FUNC(cellL10n, UTF32toUCS2);
REG_FUNC(cellL10n, ToSjisUpper);
REG_FUNC(cellL10n, UTF8toEUCJP);
REG_FUNC(cellL10n, UCS2stoEUCJPs);
REG_FUNC(cellL10n, UTF16toUCS2);
REG_FUNC(cellL10n, UCS2stoUTF16s);
REG_FUNC(cellL10n, UCS2stoEUCCNs);
REG_FUNC(cellL10n, SBCSstoUTF8s);
REG_FUNC(cellL10n, SJISstoJISs);
REG_FUNC(cellL10n, SBCStoUTF8);
REG_FUNC(cellL10n, UTF8toUTF32);
REG_FUNC(cellL10n, jstrchk);
REG_FUNC(cellL10n, UHCtoEUCKR);
REG_FUNC(cellL10n, kuten2jis);
REG_FUNC(cellL10n, UTF8toEUCCN);
REG_FUNC(cellL10n, EUCCNtoUTF8);
REG_FUNC(cellL10n, EucJpZen2Han);
REG_FUNC(cellL10n, UTF32stoUTF16s);
REG_FUNC(cellL10n, GBKtoUTF8);
REG_FUNC(cellL10n, ToEucJpUpper);
REG_FUNC(cellL10n, UCS2stoJISs);
REG_FUNC(cellL10n, UTF8stoGB18030s);
REG_FUNC(cellL10n, EUCKRstoUHCs);
REG_FUNC(cellL10n, UTF8stoUTF32s);
REG_FUNC(cellL10n, UTF8stoEUCCNs);
REG_FUNC(cellL10n, EUCJPstoUCS2s);
REG_FUNC(cellL10n, UHCtoUCS2);
REG_FUNC(cellL10n, L10nConvertStr);
REG_FUNC(cellL10n, GBKstoUTF8s);
REG_FUNC(cellL10n, UTF8toUHC);
REG_FUNC(cellL10n, UTF32toUTF8);
REG_FUNC(cellL10n, sjis2eucjp);
REG_FUNC(cellL10n, UCS2toEUCCN);
REG_FUNC(cellL10n, UTF8stoUHCs);
REG_FUNC(cellL10n, EUCKRtoUCS2);
REG_FUNC(cellL10n, UTF32toUTF16);
REG_FUNC(cellL10n, EUCCNstoUCS2s);
REG_FUNC(cellL10n, SBCSstoUCS2s);
REG_FUNC(cellL10n, UTF8stoJISs);
REG_FUNC(cellL10n, ToSjisKata);
REG_FUNC(cellL10n, jis2eucjp);
REG_FUNC(cellL10n, BIG5toUCS2);
REG_FUNC(cellL10n, UCS2toGBK);
REG_FUNC(cellL10n, UTF16toUTF32);
REG_FUNC(cellL10n, l10n_convert_str);
REG_FUNC(cellL10n, EUCJPstoJISs);
REG_FUNC(cellL10n, UTF8stoARIBs);
REG_FUNC(cellL10n, JISstoEUCJPs);
REG_FUNC(cellL10n, EucJpHan2Zen);
REG_FUNC(cellL10n, isEucJpKigou);
REG_FUNC(cellL10n, UCS2toUTF8);
REG_FUNC(cellL10n, GB18030toUCS2);
REG_FUNC(cellL10n, UHCtoUTF8);
REG_FUNC(cellL10n, MSJIStoUCS2);
REG_FUNC(cellL10n, UTF8toGBK);
REG_FUNC(cellL10n, kuten2sjis);
REG_FUNC(cellL10n, UTF8toSBCS);
REG_FUNC(cellL10n, SJIStoUCS2);
REG_FUNC(cellL10n, eucjpzen2han);
REG_FUNC(cellL10n, UCS2stoARIBs);
REG_FUNC(cellL10n, isSjisKigou);
REG_FUNC(cellL10n, UTF8stoEUCJPs);
REG_FUNC(cellL10n, UCS2toEUCKR);
REG_FUNC(cellL10n, SBCStoUCS2);
REG_FUNC(cellL10n, MSJISstoUCS2s);
REG_FUNC(cellL10n, l10n_get_converter);
REG_FUNC(cellL10n, GB18030stoUTF8s);
REG_FUNC(cellL10n, SJISstoEUCJPs);
REG_FUNC(cellL10n, UTF32stoUCS2s);
REG_FUNC(cellL10n, BIG5stoUTF8s);
REG_FUNC(cellL10n, EUCCNtoUCS2);
REG_FUNC(cellL10n, UTF8stoSBCSs);
REG_FUNC(cellL10n, UCS2stoEUCKRs);
REG_FUNC(cellL10n, UTF8stoSJISs);
REG_FUNC(cellL10n, UTF8stoHZs);
REG_FUNC(cellL10n, eucjp2kuten);
REG_FUNC(cellL10n, UTF8toBIG5);
REG_FUNC(cellL10n, UTF16stoUTF8s);
REG_FUNC(cellL10n, JISstoUCS2s);
REG_FUNC(cellL10n, GB18030toUTF8);
REG_FUNC(cellL10n, UTF8toSJIS);
REG_FUNC(cellL10n, ARIBstoUCS2s);
REG_FUNC(cellL10n, UCS2stoUTF32s);
REG_FUNC(cellL10n, UCS2stoSBCSs);
REG_FUNC(cellL10n, UCS2stoBIG5s);
REG_FUNC(cellL10n, UCS2stoUHCs);
REG_FUNC(cellL10n, SJIStoEUCJP);
REG_FUNC(cellL10n, UTF8stoUTF16s);
REG_FUNC(cellL10n, SJISstoUCS2s);
REG_FUNC(cellL10n, BIG5stoUCS2s);
REG_FUNC(cellL10n, UTF8stoUCS2s);
});
| 40,255
|
C++
|
.cpp
| 1,341
| 28.127517
| 160
| 0.681219
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| false
| false
|
5,244
|
sys_lwcond_.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/sys_lwcond_.cpp
|
#include "stdafx.h"
#include "Emu/system_config.h"
#include "Emu/Cell/PPUModule.h"
#include "Emu/Cell/lv2/sys_lwmutex.h"
#include "Emu/Cell/lv2/sys_lwcond.h"
#include "Emu/Cell/lv2/sys_cond.h"
#include "sysPrxForUser.h"
LOG_CHANNEL(sysPrxForUser);
error_code sys_lwcond_create(ppu_thread& ppu, vm::ptr<sys_lwcond_t> lwcond, vm::ptr<sys_lwmutex_t> lwmutex, vm::ptr<sys_lwcond_attribute_t> attr)
{
sysPrxForUser.trace("sys_lwcond_create(lwcond=*0x%x, lwmutex=*0x%x, attr=*0x%x)", lwcond, lwmutex, attr);
vm::var<u32> out_id;
vm::var<sys_cond_attribute_t> attrs;
attrs->pshared = SYS_SYNC_NOT_PROCESS_SHARED;
attrs->name_u64 = attr->name_u64;
if (auto res = g_cfg.core.hle_lwmutex ? sys_cond_create(ppu, out_id, lwmutex->sleep_queue, attrs) : _sys_lwcond_create(ppu, out_id, lwmutex->sleep_queue, lwcond, std::bit_cast<be_t<u64>>(attr->name_u64)))
{
return res;
}
lwcond->lwmutex = lwmutex;
lwcond->lwcond_queue = *out_id;
return CELL_OK;
}
error_code sys_lwcond_destroy(ppu_thread& ppu, vm::ptr<sys_lwcond_t> lwcond)
{
sysPrxForUser.trace("sys_lwcond_destroy(lwcond=*0x%x)", lwcond);
if (g_cfg.core.hle_lwmutex)
{
return sys_cond_destroy(ppu, lwcond->lwcond_queue);
}
if (error_code res = _sys_lwcond_destroy(ppu, lwcond->lwcond_queue))
{
return res;
}
lwcond->lwcond_queue = lwmutex_dead;
return CELL_OK;
}
error_code sys_lwcond_signal(ppu_thread& ppu, vm::ptr<sys_lwcond_t> lwcond)
{
sysPrxForUser.trace("sys_lwcond_signal(lwcond=*0x%x)", lwcond);
if (g_cfg.core.hle_lwmutex)
{
return sys_cond_signal(ppu, lwcond->lwcond_queue);
}
const vm::ptr<sys_lwmutex_t> lwmutex = lwcond->lwmutex;
if ((lwmutex->attribute & SYS_SYNC_ATTR_PROTOCOL_MASK) == SYS_SYNC_RETRY)
{
return _sys_lwcond_signal(ppu, lwcond->lwcond_queue, 0, u32{umax}, 2);
}
if (lwmutex->vars.owner.load() == ppu.id)
{
// if owns the mutex
lwmutex->all_info++;
// call the syscall
if (error_code res = _sys_lwcond_signal(ppu, lwcond->lwcond_queue, lwmutex->sleep_queue, u32{umax}, 1))
{
static_cast<void>(ppu.test_stopped());
lwmutex->all_info--;
if (res + 0u != CELL_EPERM)
{
return res;
}
}
return CELL_OK;
}
if (error_code res = sys_lwmutex_trylock(ppu, lwmutex))
{
// if locking failed
if (res + 0u != CELL_EBUSY)
{
return CELL_ESRCH;
}
// call the syscall
return _sys_lwcond_signal(ppu, lwcond->lwcond_queue, 0, u32{umax}, 2);
}
// if locking succeeded
lwmutex->lock_var.atomic_op([](sys_lwmutex_t::sync_var_t& var)
{
var.waiter++;
var.owner = lwmutex_reserved;
});
// call the syscall
if (error_code res = _sys_lwcond_signal(ppu, lwcond->lwcond_queue, lwmutex->sleep_queue, u32{umax}, 3))
{
static_cast<void>(ppu.test_stopped());
lwmutex->lock_var.atomic_op([&](sys_lwmutex_t::sync_var_t& var)
{
var.waiter--;
var.owner = ppu.id;
});
// unlock the lightweight mutex
sys_lwmutex_unlock(ppu, lwmutex);
if (res + 0u != CELL_ENOENT)
{
return res;
}
}
return CELL_OK;
}
error_code sys_lwcond_signal_all(ppu_thread& ppu, vm::ptr<sys_lwcond_t> lwcond)
{
sysPrxForUser.trace("sys_lwcond_signal_all(lwcond=*0x%x)", lwcond);
if (g_cfg.core.hle_lwmutex)
{
return sys_cond_signal_all(ppu, lwcond->lwcond_queue);
}
const vm::ptr<sys_lwmutex_t> lwmutex = lwcond->lwmutex;
if ((lwmutex->attribute & SYS_SYNC_ATTR_PROTOCOL_MASK) == SYS_SYNC_RETRY)
{
return _sys_lwcond_signal_all(ppu, lwcond->lwcond_queue, lwmutex->sleep_queue, 2);
}
if (lwmutex->vars.owner.load() == ppu.id)
{
// if owns the mutex, call the syscall
const error_code res = _sys_lwcond_signal_all(ppu, lwcond->lwcond_queue, lwmutex->sleep_queue, 1);
if (res <= 0)
{
// return error or CELL_OK
return res;
}
static_cast<void>(ppu.test_stopped());
lwmutex->all_info += +res;
return CELL_OK;
}
if (error_code res = sys_lwmutex_trylock(ppu, lwmutex))
{
// if locking failed
if (res + 0u != CELL_EBUSY)
{
return CELL_ESRCH;
}
// call the syscall
return _sys_lwcond_signal_all(ppu, lwcond->lwcond_queue, lwmutex->sleep_queue, 2);
}
// if locking succeeded, call the syscall
error_code res = _sys_lwcond_signal_all(ppu, lwcond->lwcond_queue, lwmutex->sleep_queue, 1);
static_cast<void>(ppu.test_stopped());
if (res > 0)
{
lwmutex->all_info += +res;
res = CELL_OK;
}
// unlock mutex
sys_lwmutex_unlock(ppu, lwmutex);
return res;
}
error_code sys_lwcond_signal_to(ppu_thread& ppu, vm::ptr<sys_lwcond_t> lwcond, u64 ppu_thread_id)
{
sysPrxForUser.trace("sys_lwcond_signal_to(lwcond=*0x%x, ppu_thread_id=0x%llx)", lwcond, ppu_thread_id);
if (g_cfg.core.hle_lwmutex)
{
if (ppu_thread_id == u32{umax})
{
return sys_cond_signal(ppu, lwcond->lwcond_queue);
}
return sys_cond_signal_to(ppu, lwcond->lwcond_queue, static_cast<u32>(ppu_thread_id));
}
const vm::ptr<sys_lwmutex_t> lwmutex = lwcond->lwmutex;
if ((lwmutex->attribute & SYS_SYNC_ATTR_PROTOCOL_MASK) == SYS_SYNC_RETRY)
{
return _sys_lwcond_signal(ppu, lwcond->lwcond_queue, 0, ppu_thread_id, 2);
}
if (lwmutex->vars.owner.load() == ppu.id)
{
// if owns the mutex
lwmutex->all_info++;
// call the syscall
if (error_code res = _sys_lwcond_signal(ppu, lwcond->lwcond_queue, lwmutex->sleep_queue, ppu_thread_id, 1))
{
static_cast<void>(ppu.test_stopped());
lwmutex->all_info--;
return res;
}
return CELL_OK;
}
if (error_code res = sys_lwmutex_trylock(ppu, lwmutex))
{
// if locking failed
if (res + 0u != CELL_EBUSY)
{
return CELL_ESRCH;
}
// call the syscall
return _sys_lwcond_signal(ppu, lwcond->lwcond_queue, 0, ppu_thread_id, 2);
}
// if locking succeeded
lwmutex->lock_var.atomic_op([](sys_lwmutex_t::sync_var_t& var)
{
var.waiter++;
var.owner = lwmutex_reserved;
});
// call the syscall
if (error_code res = _sys_lwcond_signal(ppu, lwcond->lwcond_queue, lwmutex->sleep_queue, ppu_thread_id, 3))
{
static_cast<void>(ppu.test_stopped());
lwmutex->lock_var.atomic_op([&](sys_lwmutex_t::sync_var_t& var)
{
var.waiter--;
var.owner = ppu.id;
});
// unlock the lightweight mutex
sys_lwmutex_unlock(ppu, lwmutex);
return res;
}
return CELL_OK;
}
error_code sys_lwcond_wait(ppu_thread& ppu, vm::ptr<sys_lwcond_t> lwcond, u64 timeout)
{
sysPrxForUser.trace("sys_lwcond_wait(lwcond=*0x%x, timeout=0x%llx)", lwcond, timeout);
if (g_cfg.core.hle_lwmutex)
{
return sys_cond_wait(ppu, lwcond->lwcond_queue, timeout);
}
auto& sstate = *ppu.optional_savestate_state;
const auto lwcond_ec = sstate.try_read<error_code>().second;
const be_t<u32> tid(ppu.id);
const vm::ptr<sys_lwmutex_t> lwmutex = lwcond->lwmutex;
if (lwmutex->vars.owner.load() != tid)
{
// if not owner of the mutex
return CELL_EPERM;
}
// save old recursive value
const be_t<u32> recursive_value = !lwcond_ec ? lwmutex->recursive_count : sstate.operator be_t<u32>();
// set special value
lwmutex->vars.owner = lwmutex_reserved;
lwmutex->recursive_count = 0;
// call the syscall
const error_code res = !lwcond_ec ? _sys_lwcond_queue_wait(ppu, lwcond->lwcond_queue, lwmutex->sleep_queue, timeout) : lwcond_ec;
static_cast<void>(ppu.test_stopped());
if (ppu.state & cpu_flag::again)
{
sstate.pos = 0;
sstate(error_code{}, recursive_value); // Not aborted on mutex sleep
return {};
}
if (res == CELL_OK || res + 0u == CELL_ESRCH)
{
if (res == CELL_OK)
{
lwmutex->all_info--;
}
// restore owner and recursive value
const auto old = lwmutex->vars.owner.exchange(tid);
lwmutex->recursive_count = recursive_value;
if (old == lwmutex_free || old == lwmutex_dead)
{
fmt::throw_exception("Locking failed (lwmutex=*0x%x, owner=0x%x)", lwmutex, old);
}
return res;
}
if (res + 0u == CELL_EBUSY || res + 0u == CELL_ETIMEDOUT)
{
if (error_code res2 = sys_lwmutex_lock(ppu, lwmutex, 0))
{
return res2;
}
if (ppu.state & cpu_flag::again)
{
sstate.pos = 0;
sstate(res, recursive_value);
return {};
}
// if successfully locked, restore recursive value
lwmutex->recursive_count = recursive_value;
if (res + 0u == CELL_EBUSY)
{
return CELL_OK;
}
return res;
}
if (res + 0u == CELL_EDEADLK)
{
// restore owner and recursive value
const auto old = lwmutex->vars.owner.exchange(tid);
lwmutex->recursive_count = recursive_value;
if (old == lwmutex_free || old == lwmutex_dead)
{
fmt::throw_exception("Locking failed (lwmutex=*0x%x, owner=0x%x)", lwmutex, old);
}
return not_an_error(CELL_ETIMEDOUT);
}
fmt::throw_exception("Unexpected syscall result (lwcond=*0x%x, result=0x%x)", lwcond, +res);
}
void sysPrxForUser_sys_lwcond_init(ppu_static_module* _this)
{
REG_FUNC(sysPrxForUser, sys_lwcond_create);
REG_FUNC(sysPrxForUser, sys_lwcond_destroy);
REG_FUNC(sysPrxForUser, sys_lwcond_signal);
REG_FUNC(sysPrxForUser, sys_lwcond_signal_all);
REG_FUNC(sysPrxForUser, sys_lwcond_signal_to);
REG_FUNC(sysPrxForUser, sys_lwcond_wait);
_this->add_init_func([](ppu_static_module*)
{
REINIT_FUNC(sys_lwcond_create).flag(g_cfg.core.hle_lwmutex ? MFF_FORCED_HLE : MFF_PERFECT);
REINIT_FUNC(sys_lwcond_destroy).flag(g_cfg.core.hle_lwmutex ? MFF_FORCED_HLE : MFF_PERFECT);
REINIT_FUNC(sys_lwcond_signal).flag(g_cfg.core.hle_lwmutex ? MFF_FORCED_HLE : MFF_PERFECT);
REINIT_FUNC(sys_lwcond_signal_all).flag(g_cfg.core.hle_lwmutex ? MFF_FORCED_HLE : MFF_PERFECT);
REINIT_FUNC(sys_lwcond_signal_to).flag(g_cfg.core.hle_lwmutex ? MFF_FORCED_HLE : MFF_PERFECT);
REINIT_FUNC(sys_lwcond_wait).flag(g_cfg.core.hle_lwmutex ? MFF_FORCED_HLE : MFF_PERFECT);
});
}
| 9,571
|
C++
|
.cpp
| 302
| 28.923841
| 205
| 0.693682
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| false
| false
|
5,245
|
cellCrossController.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellCrossController.cpp
|
#include "stdafx.h"
#include "Emu/System.h"
#include "Emu/Cell/PPUModule.h"
#include "Emu/IdManager.h"
#include "Emu/localized_string.h"
#include "cellSysutil.h"
#include "cellCrossController.h"
#include "cellMsgDialog.h"
LOG_CHANNEL(cellCrossController);
template <>
void fmt_class_string<CellCrossControllerError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](CellCrossControllerError value)
{
switch (value)
{
STR_CASE(CELL_CROSS_CONTROLLER_ERROR_CANCEL);
STR_CASE(CELL_CROSS_CONTROLLER_ERROR_NETWORK);
STR_CASE(CELL_CROSS_CONTROLLER_ERROR_OUT_OF_MEMORY);
STR_CASE(CELL_CROSS_CONTROLLER_ERROR_FATAL);
STR_CASE(CELL_CROSS_CONTROLLER_ERROR_INVALID_PKG_FILENAME);
STR_CASE(CELL_CROSS_CONTROLLER_ERROR_INVALID_SIG_FILENAME);
STR_CASE(CELL_CROSS_CONTROLLER_ERROR_INVALID_ICON_FILENAME);
STR_CASE(CELL_CROSS_CONTROLLER_ERROR_INVALID_VALUE);
STR_CASE(CELL_CROSS_CONTROLLER_ERROR_PKG_FILE_OPEN);
STR_CASE(CELL_CROSS_CONTROLLER_ERROR_SIG_FILE_OPEN);
STR_CASE(CELL_CROSS_CONTROLLER_ERROR_ICON_FILE_OPEN);
STR_CASE(CELL_CROSS_CONTROLLER_ERROR_INVALID_STATE);
STR_CASE(CELL_CROSS_CONTROLLER_ERROR_INVALID_PKG_FILE);
STR_CASE(CELL_CROSS_CONTROLLER_ERROR_INTERNAL);
}
return unknown;
});
}
void finish_callback(ppu_thread& ppu, s32 button_type, vm::ptr<void> userdata); // Forward declaration
struct cross_controller
{
atomic_t<s32> status{0};
std::unique_ptr<named_thread<std::function<void()>>> connection_thread;
vm::ptr<CellCrossControllerCallback> callback = vm::null;
vm::ptr<void> userdata = vm::null;
void on_connection_established(s32 status)
{
ensure(!!callback);
close_msg_dialog();
sysutil_register_cb([this, status](ppu_thread& ppu) -> s32
{
callback(ppu, CELL_CROSS_CONTROLLER_STATUS_FINALIZED, status, vm::null, userdata);
return CELL_OK;
});
}
void run_thread(vm::cptr<CellCrossControllerPackageInfo> pPkgInfo)
{
ensure(!!pPkgInfo);
ensure(!!callback);
const std::string msg = fmt::format("%s\n\n%s",
get_localized_string(localized_string_id::CELL_CROSS_CONTROLLER_MSG, pPkgInfo->pTitle.get_ptr()),
get_localized_string(localized_string_id::CELL_CROSS_CONTROLLER_FW_MSG));
vm::bptr<CellMsgDialogCallback> msg_dialog_callback = vm::null;
msg_dialog_callback.set(g_fxo->get<ppu_function_manager>().func_addr(FIND_FUNC(finish_callback)));
// TODO: Show icons from comboplay_plugin.rco in dialog. Maybe use a new dialog or add an optional icon to this one.
error_code res = open_msg_dialog(false, CELL_MSGDIALOG_TYPE_DISABLE_CANCEL_OFF, vm::make_str(msg), msg_dialog_source::_cellCrossController, msg_dialog_callback, userdata);
sysutil_register_cb([this, res](ppu_thread& ppu) -> s32
{
callback(ppu, CELL_CROSS_CONTROLLER_STATUS_INITIALIZED, res == CELL_OK ? +CELL_OK : +CELL_CROSS_CONTROLLER_ERROR_INTERNAL, vm::null, userdata);
return CELL_OK;
});
status = CELL_CROSS_CONTROLLER_STATUS_INITIALIZED;
connection_thread = std::make_unique<named_thread<std::function<void()>>>(fmt::format("Cross-Controller Thread"), [this]()
{
while (thread_ctrl::state() != thread_state::aborting)
{
if (Emu.IsPaused())
{
thread_ctrl::wait_for(10'000);
continue;
}
// TODO: establish connection to PS Vita
if (false)
{
on_connection_established(CELL_OK);
}
thread_ctrl::wait_for(1000);
}
status = CELL_CROSS_CONTROLLER_STATUS_FINALIZED;
});
}
void stop_thread()
{
if (connection_thread)
{
auto& thread = *connection_thread;
thread = thread_state::aborting;
thread();
connection_thread.reset();
}
};
};
void finish_callback(ppu_thread& ppu, s32 button_type, vm::ptr<void> userdata)
{
cross_controller& cc = g_fxo->get<cross_controller>();
// This function should only be called when the user canceled the dialog
ensure(cc.callback && button_type == CELL_MSGDIALOG_BUTTON_ESCAPE);
cc.callback(ppu, CELL_CROSS_CONTROLLER_STATUS_FINALIZED, CELL_CROSS_CONTROLLER_ERROR_CANCEL, vm::null, userdata);
cc.stop_thread();
}
error_code cellCrossControllerInitialize(vm::cptr<CellCrossControllerParam> pParam, vm::cptr<CellCrossControllerPackageInfo> pPkgInfo, vm::ptr<CellCrossControllerCallback> cb, vm::ptr<void> userdata) // LittleBigPlanet 2 and 3
{
cellCrossController.todo("cellCrossControllerInitialize(pParam=*0x%x, pPkgInfo=*0x%x, cb=*0x%x, userdata=*0x%x)", pParam, pPkgInfo, cb, userdata);
if (pParam)
{
cellCrossController.notice("cellCrossControllerInitialize: pParam: pPackageFileName=%s, pSignatureFileName=%s, pIconFileName=%s", pParam->pPackageFileName, pParam->pSignatureFileName, pParam->pIconFileName);
}
if (pPkgInfo)
{
cellCrossController.notice("cellCrossControllerInitialize: pPkgInfo: pTitle=%s, pTitleId=%s, pAppVer=%s", pPkgInfo->pTitle, pPkgInfo->pTitleId, pPkgInfo->pAppVer);
}
cross_controller& cc = g_fxo->get<cross_controller>();
if (cc.status == CELL_CROSS_CONTROLLER_STATUS_INITIALIZED) // TODO: confirm this logic
{
return CELL_CROSS_CONTROLLER_ERROR_INVALID_STATE;
}
if (!pParam || !pPkgInfo)
{
return CELL_CROSS_CONTROLLER_ERROR_INVALID_VALUE;
}
// Check if the strings exceed the allowed size (not counting null terminators)
if (!pParam->pPackageFileName || !memchr(pParam->pPackageFileName.get_ptr(), '\0', CELL_CROSS_CONTROLLER_PARAM_FILE_NAME_LEN + 1))
{
return CELL_CROSS_CONTROLLER_ERROR_INVALID_PKG_FILENAME;
}
if (!pParam->pSignatureFileName || !memchr(pParam->pSignatureFileName.get_ptr(), '\0', CELL_CROSS_CONTROLLER_PARAM_FILE_NAME_LEN + 1))
{
return CELL_CROSS_CONTROLLER_ERROR_INVALID_SIG_FILENAME;
}
if (!pParam->pIconFileName || !memchr(pParam->pIconFileName.get_ptr(), '\0', CELL_CROSS_CONTROLLER_PARAM_FILE_NAME_LEN + 1))
{
return CELL_CROSS_CONTROLLER_ERROR_INVALID_ICON_FILENAME;
}
if (!pPkgInfo->pAppVer || !memchr(pPkgInfo->pAppVer.get_ptr(), '\0', CELL_CROSS_CONTROLLER_PKG_APP_VER_LEN + 1) ||
!pPkgInfo->pTitleId || !memchr(pPkgInfo->pTitleId.get_ptr(), '\0', CELL_CROSS_CONTROLLER_PKG_TITLE_ID_LEN + 1) ||
!pPkgInfo->pTitle || !memchr(pPkgInfo->pTitle.get_ptr(), '\0', CELL_CROSS_CONTROLLER_PKG_TITLE_LEN + 1) ||
!cb)
{
return CELL_CROSS_CONTROLLER_ERROR_INVALID_VALUE;
}
cc.callback = cb;
cc.userdata = userdata;
cc.run_thread(pPkgInfo);
return CELL_OK;
}
DECLARE(ppu_module_manager::cellCrossController)("cellCrossController", []()
{
REG_FUNC(cellCrossController, cellCrossControllerInitialize);
// Helper Function
REG_HIDDEN_FUNC(finish_callback);
});
| 6,499
|
C++
|
.cpp
| 157
| 38.522293
| 226
| 0.74409
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
5,246
|
cellSail.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellSail.cpp
|
#include "stdafx.h"
#include "Emu/VFS.h"
#include "Emu/Cell/PPUModule.h"
#include "cellSail.h"
#include "cellPamf.h"
LOG_CHANNEL(cellSail);
template <>
void fmt_class_string<CellSailError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_SAIL_ERROR_INVALID_ARG);
STR_CASE(CELL_SAIL_ERROR_INVALID_STATE);
STR_CASE(CELL_SAIL_ERROR_UNSUPPORTED_STREAM);
STR_CASE(CELL_SAIL_ERROR_INDEX_OUT_OF_RANGE);
STR_CASE(CELL_SAIL_ERROR_EMPTY);
STR_CASE(CELL_SAIL_ERROR_FULLED);
STR_CASE(CELL_SAIL_ERROR_USING);
STR_CASE(CELL_SAIL_ERROR_NOT_AVAILABLE);
STR_CASE(CELL_SAIL_ERROR_CANCEL);
STR_CASE(CELL_SAIL_ERROR_MEMORY);
STR_CASE(CELL_SAIL_ERROR_INVALID_FD);
STR_CASE(CELL_SAIL_ERROR_FATAL);
}
return unknown;
});
}
error_code cellSailMemAllocatorInitialize(vm::ptr<CellSailMemAllocator> pSelf, vm::ptr<CellSailMemAllocatorFuncs> pCallbacks)
{
cellSail.warning("cellSailMemAllocatorInitialize(pSelf=*0x%x, pCallbacks=*0x%x)", pSelf, pCallbacks);
pSelf->callbacks = pCallbacks;
return CELL_OK;
}
error_code cellSailFutureInitialize(vm::ptr<CellSailFuture> pSelf)
{
cellSail.todo("cellSailFutureInitialize(pSelf=*0x%x)", pSelf);
return CELL_OK;
}
error_code cellSailFutureFinalize(vm::ptr<CellSailFuture> pSelf)
{
cellSail.todo("cellSailFutureFinalize(pSelf=*0x%x)", pSelf);
return CELL_OK;
}
error_code cellSailFutureReset(vm::ptr<CellSailFuture> pSelf, b8 wait)
{
cellSail.todo("cellSailFutureReset(pSelf=*0x%x, wait=%d)", pSelf, wait);
return CELL_OK;
}
error_code cellSailFutureSet(vm::ptr<CellSailFuture> pSelf, s32 result)
{
cellSail.todo("cellSailFutureSet(pSelf=*0x%x, result=%d)", pSelf, result);
return CELL_OK;
}
error_code cellSailFutureGet(vm::ptr<CellSailFuture> pSelf, u64 timeout, vm::ptr<s32> pResult)
{
cellSail.todo("cellSailFutureGet(pSelf=*0x%x, timeout=%lld, result=*0x%x)", pSelf, timeout, pResult);
return CELL_OK;
}
error_code cellSailFutureIsDone(vm::ptr<CellSailFuture> pSelf, vm::ptr<s32> pResult)
{
cellSail.todo("cellSailFutureIsDone(pSelf=*0x%x, result=*0x%x)", pSelf, pResult);
return CELL_OK;
}
error_code cellSailDescriptorGetStreamType()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailDescriptorGetUri()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailDescriptorGetMediaInfo()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailDescriptorSetAutoSelection(vm::ptr<CellSailDescriptor> pSelf, b8 autoSelection)
{
cellSail.warning("cellSailDescriptorSetAutoSelection(pSelf=*0x%x, autoSelection=%d)", pSelf, autoSelection);
if (pSelf)
{
pSelf->autoSelection = autoSelection;
return autoSelection;
}
return CELL_OK;
}
error_code cellSailDescriptorIsAutoSelection(vm::ptr<CellSailDescriptor> pSelf)
{
cellSail.warning("cellSailDescriptorIsAutoSelection(pSelf=*0x%x)", pSelf);
if (pSelf)
{
return pSelf->autoSelection;
}
return CELL_OK;
}
error_code cellSailDescriptorCreateDatabase(vm::ptr<CellSailDescriptor> pSelf, vm::ptr<void> pDatabase, u32 size, u64 arg)
{
cellSail.warning("cellSailDescriptorCreateDatabase(pSelf=*0x%x, pDatabase=*0x%x, size=0x%x, arg=0x%llx)", pSelf, pDatabase, size, arg);
switch (pSelf->streamType)
{
case CELL_SAIL_STREAM_PAMF:
{
u32 addr = pSelf->sp_;
auto ptr = vm::ptr<CellPamfReader>::make(addr);
memcpy(pDatabase.get_ptr(), ptr.get_ptr(), sizeof(CellPamfReader));
break;
}
default:
cellSail.error("Unhandled stream type: %d", pSelf->streamType);
}
return CELL_OK;
}
error_code cellSailDescriptorDestroyDatabase()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailDescriptorOpen()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailDescriptorClose()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailDescriptorSetEs()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailDescriptorClearEs()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailDescriptorGetCapabilities()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailDescriptorInquireCapability()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailDescriptorSetParameter()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailSoundAdapterInitialize(vm::ptr<CellSailSoundAdapter> pSelf, vm::cptr<CellSailSoundAdapterFuncs> pCallbacks, vm::ptr<void> pArg)
{
cellSail.warning("cellSailSoundAdapterInitialize(pSelf=*0x%x, pCallbacks=*0x%x, pArg=*0x%x)", pSelf, pCallbacks, pArg);
if (pSelf->initialized)
{
return CELL_SAIL_ERROR_INVALID_STATE;
}
if (pSelf->registered)
{
return CELL_SAIL_ERROR_INVALID_STATE;
}
pSelf->pMakeup = pCallbacks->pMakeup;
pSelf->pCleanup = pCallbacks->pCleanup;
pSelf->pFormatChanged = pCallbacks->pFormatChanged;
pSelf->arg = pArg;
pSelf->initialized = true;
pSelf->registered = false;
return CELL_OK;
}
error_code cellSailSoundAdapterFinalize(vm::ptr<CellSailSoundAdapter> pSelf)
{
cellSail.warning("cellSailSoundAdapterFinalize(pSelf=*0x%x)", pSelf);
if (!pSelf->initialized)
{
return CELL_SAIL_ERROR_INVALID_STATE;
}
if (pSelf->registered)
{
return CELL_SAIL_ERROR_INVALID_STATE;
}
return CELL_OK;
}
error_code cellSailSoundAdapterSetPreferredFormat(vm::ptr<CellSailSoundAdapter> pSelf, vm::cptr<CellSailAudioFormat> pFormat)
{
cellSail.warning("cellSailSoundAdapterSetPreferredFormat(pSelf=*0x%x, pFormat=*0x%x)", pSelf, pFormat);
pSelf->format = *pFormat;
return CELL_OK;
}
error_code cellSailSoundAdapterGetFrame(vm::ptr<CellSailSoundAdapter> pSelf, u32 samples, vm::ptr<CellSailSoundFrameInfo> pInfo)
{
cellSail.todo("cellSailSoundAdapterGetFrame(pSelf=*0x%x, samples=%d, pInfo=*0x%x)", pSelf, samples, pInfo);
if (!pSelf->initialized)
{
return CELL_SAIL_ERROR_INVALID_STATE;
}
if (pSelf->registered)
{
return CELL_SAIL_ERROR_INVALID_STATE;
}
if (samples > 2048)
{
return CELL_SAIL_ERROR_INVALID_ARG;
}
return CELL_OK;
}
error_code cellSailSoundAdapterGetFormat(vm::ptr<CellSailSoundAdapter> pSelf, vm::ptr<CellSailAudioFormat> pFormat)
{
cellSail.warning("cellSailSoundAdapterGetFormat(pSelf=*0x%x, pFormat=*0x%x)", pSelf, pFormat);
*pFormat = pSelf->format;
return CELL_OK;
}
error_code cellSailSoundAdapterUpdateAvSync()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailSoundAdapterPtsToTimePosition()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailGraphicsAdapterInitialize(vm::ptr<CellSailGraphicsAdapter> pSelf, vm::cptr<CellSailGraphicsAdapterFuncs> pCallbacks, vm::ptr<void> pArg)
{
cellSail.warning("cellSailGraphicsAdapterInitialize(pSelf=*0x%x, pCallbacks=*0x%x, pArg=*0x%x)", pSelf, pCallbacks, pArg);
if (pSelf->initialized)
{
return CELL_SAIL_ERROR_INVALID_STATE;
}
if (pSelf->registered)
{
return CELL_SAIL_ERROR_INVALID_STATE;
}
pSelf->pMakeup = pCallbacks->pMakeup;
pSelf->pCleanup = pCallbacks->pCleanup;
pSelf->pFormatChanged = pCallbacks->pFormatChanged;
pSelf->pAlloc = pCallbacks->pAlloc;
pSelf->pFree = pCallbacks->pFree;
pSelf->arg = pArg;
pSelf->initialized = true;
pSelf->registered = true;
return CELL_OK;
}
error_code cellSailGraphicsAdapterFinalize(vm::ptr<CellSailGraphicsAdapter> pSelf)
{
cellSail.todo("cellSailGraphicsAdapterFinalize(pSelf=*0x%x)", pSelf);
if (!pSelf->initialized)
{
return CELL_SAIL_ERROR_INVALID_STATE;
}
if (pSelf->registered)
{
return CELL_SAIL_ERROR_INVALID_STATE;
}
return CELL_OK;
}
error_code cellSailGraphicsAdapterSetPreferredFormat(vm::ptr<CellSailGraphicsAdapter> pSelf, vm::cptr<CellSailVideoFormat> pFormat)
{
cellSail.warning("cellSailGraphicsAdapterSetPreferredFormat(pSelf=*0x%x, pFormat=*0x%x)", pSelf, pFormat);
pSelf->format = *pFormat;
return CELL_OK;
}
error_code cellSailGraphicsAdapterGetFrame(vm::ptr<CellSailGraphicsAdapter> pSelf, vm::ptr<CellSailGraphicsFrameInfo> pInfo)
{
cellSail.todo("cellSailGraphicsAdapterGetFrame(pSelf=*0x%x, pInfo=*0x%x)", pSelf, pInfo);
return CELL_OK;
}
error_code cellSailGraphicsAdapterGetFrame2(vm::ptr<CellSailGraphicsAdapter> pSelf, vm::ptr<CellSailGraphicsFrameInfo> pInfo, vm::ptr<CellSailGraphicsFrameInfo> pPrevInfo, vm::ptr<u64> pFlipTime, u64 flags)
{
cellSail.todo("cellSailGraphicsAdapterGetFrame2(pSelf=*0x%x, pInfo=*0x%x, pPrevInfo=*0x%x, flipTime=*0x%x, flags=0x%llx)", pSelf, pInfo, pPrevInfo, pFlipTime, flags);
return CELL_OK;
}
error_code cellSailGraphicsAdapterGetFormat(vm::ptr<CellSailGraphicsAdapter> pSelf, vm::ptr<CellSailVideoFormat> pFormat)
{
cellSail.warning("cellSailGraphicsAdapterGetFormat(pSelf=*0x%x, pFormat=*0x%x)", pSelf, pFormat);
*pFormat = pSelf->format;
return CELL_OK;
}
error_code cellSailGraphicsAdapterUpdateAvSync()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailGraphicsAdapterPtsToTimePosition()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailAuReceiverInitialize()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailAuReceiverFinalize()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailAuReceiverGet()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailRendererAudioInitialize()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailRendererAudioFinalize()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailRendererAudioNotifyCallCompleted()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailRendererAudioNotifyFrameDone()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailRendererAudioNotifyOutputEos()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailRendererVideoInitialize()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailRendererVideoFinalize()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailRendererVideoNotifyCallCompleted()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailRendererVideoNotifyFrameDone()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailRendererVideoNotifyOutputEos()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailSourceInitialize()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailSourceFinalize()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailSourceNotifyCallCompleted()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailSourceNotifyInputEos()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailSourceNotifyStreamOut()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailSourceNotifySessionError()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailSourceNotifyMediaStateChanged()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailSourceNotifyOpenCompleted()
{
cellSail.fatal("cellSailSourceNotifyOpenCompleted: unexpected function");
return CELL_OK;
}
error_code cellSailSourceNotifyStartCompleted()
{
cellSail.fatal("cellSailSourceNotifyStartCompleted: unexpected function");
return CELL_OK;
}
error_code cellSailSourceNotifyStopCompleted()
{
cellSail.fatal("cellSailSourceNotifyStopCompleted: unexpected function");
return CELL_OK;
}
error_code cellSailSourceNotifyReadCompleted()
{
cellSail.fatal("cellSailSourceNotifyReadCompleted: unexpected function");
return CELL_OK;
}
error_code cellSailSourceSetDiagHandler()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailSourceNotifyCloseCompleted()
{
cellSail.fatal("cellSailSourceNotifyCloseCompleted: unexpected function");
return CELL_OK;
}
error_code cellSailMp4MovieGetBrand()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailMp4MovieIsCompatibleBrand()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailMp4MovieGetMovieInfo()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailMp4MovieGetTrackByIndex()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailMp4MovieGetTrackById()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailMp4MovieGetTrackByTypeAndIndex()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailMp4TrackGetTrackInfo()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailMp4TrackGetTrackReferenceCount()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailMp4TrackGetTrackReference()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailAviMovieGetMovieInfo()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailAviMovieGetStreamByIndex()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailAviMovieGetStreamByTypeAndIndex()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailAviMovieGetHeader()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailAviStreamGetMediaType()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailAviStreamGetHeader()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailPlayerInitialize()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailPlayerInitialize2(ppu_thread& ppu,
vm::ptr<CellSailPlayer> pSelf,
vm::ptr<CellSailMemAllocator> pAllocator,
vm::ptr<CellSailPlayerFuncNotified> pCallback,
vm::ptr<void> callbackArg,
vm::ptr<CellSailPlayerAttribute> pAttribute,
vm::ptr<CellSailPlayerResource> pResource)
{
cellSail.warning("cellSailPlayerInitialize2(pSelf=*0x%x, pAllocator=*0x%x, pCallback=*0x%x, callbackArg=*0x%x, pAttribute=*0x%x, pResource=*0x%x)",
pSelf, pAllocator, pCallback, callbackArg, pAttribute, pResource);
pSelf->allocator = *pAllocator;
pSelf->callback = pCallback;
pSelf->callbackArg = callbackArg;
pSelf->attribute = *pAttribute;
pSelf->resource = *pResource;
pSelf->booted = false;
pSelf->paused = true;
{
CellSailEvent event{};
event.u32x2.major = CELL_SAIL_EVENT_PLAYER_STATE_CHANGED;
event.u32x2.minor = 0;
pSelf->callback(ppu, pSelf->callbackArg, event, CELL_SAIL_PLAYER_STATE_INITIALIZED, 0);
}
return CELL_OK;
}
error_code cellSailPlayerFinalize(vm::ptr<CellSailPlayer> pSelf)
{
cellSail.todo("cellSailPlayerFinalize(pSelf=*0x%x)", pSelf);
if (pSelf->sAdapter)
{
pSelf->sAdapter->registered = false;
}
if (pSelf->gAdapter)
{
pSelf->gAdapter->registered = false;
}
return CELL_OK;
}
error_code cellSailPlayerRegisterSource()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailPlayerGetRegisteredProtocols()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailPlayerSetSoundAdapter(vm::ptr<CellSailPlayer> pSelf, u32 index, vm::ptr<CellSailSoundAdapter> pAdapter)
{
cellSail.warning("cellSailPlayerSetSoundAdapter(pSelf=*0x%x, index=%d, pAdapter=*0x%x)", pSelf, index, pAdapter);
if (index > pSelf->attribute.maxAudioStreamNum)
{
return CELL_SAIL_ERROR_INVALID_ARG;
}
pSelf->sAdapter = pAdapter;
pAdapter->index = index;
pAdapter->registered = true;
return CELL_OK;
}
error_code cellSailPlayerSetGraphicsAdapter(vm::ptr<CellSailPlayer> pSelf, u32 index, vm::ptr<CellSailGraphicsAdapter> pAdapter)
{
cellSail.warning("cellSailPlayerSetGraphicsAdapter(pSelf=*0x%x, index=%d, pAdapter=*0x%x)", pSelf, index, pAdapter);
if (index > pSelf->attribute.maxVideoStreamNum)
{
return CELL_SAIL_ERROR_INVALID_ARG;
}
pSelf->gAdapter = pAdapter;
pAdapter->index = index;
pAdapter->registered = true;
return CELL_OK;
}
error_code cellSailPlayerSetAuReceiver()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailPlayerSetRendererAudio()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailPlayerSetRendererVideo()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailPlayerSetParameter(vm::ptr<CellSailPlayer> pSelf, s32 parameterType, u64 param0, u64 param1)
{
cellSail.warning("cellSailPlayerSetParameter(pSelf=*0x%x, parameterType=0x%x, param0=0x%llx, param1=0x%llx)", pSelf, parameterType, param0, param1);
switch (parameterType)
{
case CELL_SAIL_PARAMETER_GRAPHICS_ADAPTER_BUFFER_RELEASE_DELAY: pSelf->graphics_adapter_buffer_release_delay = static_cast<u32>(param1); break; // TODO: Stream index
case CELL_SAIL_PARAMETER_CONTROL_PPU_THREAD_STACK_SIZE: pSelf->control_ppu_thread_stack_size = static_cast<u32>(param0); break;
case CELL_SAIL_PARAMETER_ENABLE_APOST_SRC: pSelf->enable_apost_src = static_cast<u32>(param1); break; // TODO: Stream index
default: cellSail.todo("cellSailPlayerSetParameter(): unimplemented parameter %s", ParameterCodeToName(parameterType));
}
return CELL_OK;
}
error_code cellSailPlayerGetParameter(vm::ptr<CellSailPlayer> pSelf, s32 parameterType, vm::ptr<u64> pParam0, vm::ptr<u64> pParam1)
{
cellSail.todo("cellSailPlayerGetParameter(pSelf=*0x%x, parameterType=0x%x, param0=*0x%x, param1=*0x%x)", pSelf, parameterType, pParam0, pParam1);
switch (parameterType)
{
case 0:
default: cellSail.error("cellSailPlayerGetParameter(): unimplemented parameter %s", ParameterCodeToName(parameterType));
}
return CELL_OK;
}
error_code cellSailPlayerSubscribeEvent()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailPlayerUnsubscribeEvent()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailPlayerReplaceEventHandler()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailPlayerBoot(ppu_thread& ppu, vm::ptr<CellSailPlayer> pSelf, u64 userParam)
{
cellSail.warning("cellSailPlayerBoot(pSelf=*0x%x, userParam=%d)", pSelf, userParam);
{
CellSailEvent event{};
event.u32x2.major = CELL_SAIL_EVENT_PLAYER_STATE_CHANGED;
event.u32x2.minor = 0;
pSelf->callback(ppu, pSelf->callbackArg, event, CELL_SAIL_PLAYER_STATE_BOOT_TRANSITION, 0);
}
// TODO: Do stuff here
pSelf->booted = true;
{
CellSailEvent event{};
event.u32x2.major = CELL_SAIL_EVENT_PLAYER_CALL_COMPLETED;
event.u32x2.minor = CELL_SAIL_PLAYER_CALL_BOOT;
pSelf->callback(ppu, pSelf->callbackArg, event, 0, 0);
}
return CELL_OK;
}
error_code cellSailPlayerAddDescriptor(vm::ptr<CellSailPlayer> pSelf, vm::ptr<CellSailDescriptor> pDesc)
{
cellSail.warning("cellSailPlayerAddDescriptor(pSelf=*0x%x, pDesc=*0x%x)", pSelf, pDesc);
if (pSelf && pSelf->descriptors < 3 && pDesc)
{
pSelf->descriptors++;
pSelf->registeredDescriptors[pSelf->descriptors] = pDesc;
pDesc->registered = true;
}
else
{
cellSail.error("Descriptor limit reached or the descriptor is unspecified! This should never happen, report this to a developer.");
}
return CELL_OK;
}
error_code cellSailPlayerCreateDescriptor(vm::ptr<CellSailPlayer> pSelf, s32 streamType, vm::ptr<void> pMediaInfo, vm::cptr<char> pUri, vm::pptr<CellSailDescriptor> ppDesc)
{
cellSail.todo("cellSailPlayerCreateDescriptor(pSelf=*0x%x, streamType=%d, pMediaInfo=*0x%x, pUri=%s, ppDesc=**0x%x)", pSelf, streamType, pMediaInfo, pUri, ppDesc);
u32 descriptorAddress = vm::alloc(sizeof(CellSailDescriptor), vm::main);
auto descriptor = vm::ptr<CellSailDescriptor>::make(descriptorAddress);
*ppDesc = descriptor;
descriptor->streamType = streamType;
descriptor->registered = false;
//pSelf->descriptors = 0;
pSelf->repeatMode = 0;
switch (streamType)
{
case CELL_SAIL_STREAM_PAMF:
{
std::string uri = pUri.get_ptr();
if (uri.starts_with("x-cell-fs://"))
{
if (fs::file f{ vfs::get(uri.substr(12)) })
{
u32 size = ::size32(f);
u32 buffer = vm::alloc(size, vm::main);
auto bufPtr = vm::cptr<PamfHeader>::make(buffer);
PamfHeader *buf = const_cast<PamfHeader*>(bufPtr.get_ptr());
ensure(f.read(buf, size) == size);
u32 sp_ = vm::alloc(sizeof(CellPamfReader), vm::main);
auto sp = vm::ptr<CellPamfReader>::make(sp_);
[[maybe_unused]] u32 err = cellPamfReaderInitialize(sp, bufPtr, size, 0);
descriptor->buffer = buffer;
descriptor->sp_ = sp_;
}
else
{
cellSail.warning("Couldn't open PAMF: %s", uri.c_str());
}
}
else
{
cellSail.warning("Unhandled uri: %s", uri.c_str());
}
break;
}
default:
cellSail.error("Unhandled stream type: %d", streamType);
}
return CELL_OK;
}
error_code cellSailPlayerDestroyDescriptor(vm::ptr<CellSailPlayer> pSelf, vm::ptr<CellSailDescriptor> pDesc)
{
cellSail.todo("cellSailPlayerAddDescriptor(pSelf=*0x%x, pDesc=*0x%x)", pSelf, pDesc);
if (pDesc->registered)
return CELL_SAIL_ERROR_INVALID_STATE;
return CELL_OK;
}
error_code cellSailPlayerRemoveDescriptor(vm::ptr<CellSailPlayer> pSelf, vm::ptr<CellSailDescriptor> ppDesc)
{
cellSail.warning("cellSailPlayerAddDescriptor(pSelf=*0x%x, pDesc=*0x%x)", pSelf, ppDesc);
if (pSelf->descriptors > 0)
{
ppDesc = pSelf->registeredDescriptors[pSelf->descriptors];
// TODO: Figure out how properly free a descriptor. Use game specified memory dealloc function?
//delete &pSelf->registeredDescriptors[pSelf->descriptors];
pSelf->descriptors--;
}
return pSelf->descriptors;
}
error_code cellSailPlayerGetDescriptorCount(vm::ptr<CellSailPlayer> pSelf)
{
cellSail.warning("cellSailPlayerGetDescriptorCount(pSelf=*0x%x)", pSelf);
return not_an_error(pSelf->descriptors);
}
error_code cellSailPlayerGetCurrentDescriptor()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailPlayerOpenStream()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailPlayerCloseStream()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailPlayerOpenEsAudio()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailPlayerOpenEsVideo()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailPlayerOpenEsUser()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailPlayerReopenEsAudio()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailPlayerReopenEsVideo()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailPlayerReopenEsUser()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailPlayerCloseEsAudio()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailPlayerCloseEsVideo()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailPlayerCloseEsUser()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailPlayerStart()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailPlayerStop()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailPlayerNext()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailPlayerCancel()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailPlayerSetPaused(vm::ptr<CellSailPlayer> pSelf, b8 paused)
{
cellSail.todo("cellSailPlayerSetPaused(pSelf=*0x%x, paused=%d)", pSelf, paused);
return CELL_OK;
}
s32 cellSailPlayerIsPaused(vm::ptr<CellSailPlayer> pSelf)
{
cellSail.warning("cellSailPlayerIsPaused(pSelf=*0x%x)", pSelf);
return pSelf->paused;
}
s32 cellSailPlayerSetRepeatMode(vm::ptr<CellSailPlayer> pSelf, s32 repeatMode, vm::ptr<CellSailStartCommand> pCommand)
{
cellSail.warning("cellSailPlayerSetRepeatMode(pSelf=*0x%x, repeatMode=%d, pCommand=*0x%x)", pSelf, repeatMode, pCommand);
pSelf->repeatMode = repeatMode;
pSelf->playbackCommand = pCommand;
return pSelf->repeatMode;
}
s32 cellSailPlayerGetRepeatMode(vm::ptr<CellSailPlayer> pSelf, vm::ptr<CellSailStartCommand> pCommand)
{
cellSail.warning("cellSailPlayerGetRepeatMode(pSelf=*0x%x, pCommand=*0x%x)", pSelf, pCommand);
pCommand = pSelf->playbackCommand;
return pSelf->repeatMode;
}
error_code cellSailPlayerSetEsAudioMuted()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailPlayerSetEsVideoMuted()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailPlayerIsEsAudioMuted()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailPlayerIsEsVideoMuted()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailPlayerDumpImage()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
error_code cellSailPlayerUnregisterSource()
{
UNIMPLEMENTED_FUNC(cellSail);
return CELL_OK;
}
DECLARE(ppu_module_manager::cellSail)("cellSail", []()
{
static ppu_static_module cellSailAvi("cellSailAvi");
[[maybe_unused]] vm::ptr<CellSailMp4MovieInfo<>> test;
REG_FUNC(cellSail, cellSailMemAllocatorInitialize);
REG_FUNC(cellSail, cellSailFutureInitialize);
REG_FUNC(cellSail, cellSailFutureFinalize);
REG_FUNC(cellSail, cellSailFutureReset);
REG_FUNC(cellSail, cellSailFutureSet);
REG_FUNC(cellSail, cellSailFutureGet);
REG_FUNC(cellSail, cellSailFutureIsDone);
REG_FUNC(cellSail, cellSailDescriptorGetStreamType);
REG_FUNC(cellSail, cellSailDescriptorGetUri);
REG_FUNC(cellSail, cellSailDescriptorGetMediaInfo);
REG_FUNC(cellSail, cellSailDescriptorSetAutoSelection);
REG_FUNC(cellSail, cellSailDescriptorIsAutoSelection);
REG_FUNC(cellSail, cellSailDescriptorCreateDatabase);
REG_FUNC(cellSail, cellSailDescriptorDestroyDatabase);
REG_FUNC(cellSail, cellSailDescriptorOpen);
REG_FUNC(cellSail, cellSailDescriptorClose);
REG_FUNC(cellSail, cellSailDescriptorSetEs);
REG_FUNC(cellSail, cellSailDescriptorClearEs);
REG_FUNC(cellSail, cellSailDescriptorGetCapabilities);
REG_FUNC(cellSail, cellSailDescriptorInquireCapability);
REG_FUNC(cellSail, cellSailDescriptorSetParameter);
REG_FUNC(cellSail, cellSailSoundAdapterInitialize);
REG_FUNC(cellSail, cellSailSoundAdapterFinalize);
REG_FUNC(cellSail, cellSailSoundAdapterSetPreferredFormat);
REG_FUNC(cellSail, cellSailSoundAdapterGetFrame);
REG_FUNC(cellSail, cellSailSoundAdapterGetFormat);
REG_FUNC(cellSail, cellSailSoundAdapterUpdateAvSync);
REG_FUNC(cellSail, cellSailSoundAdapterPtsToTimePosition);
REG_FUNC(cellSail, cellSailGraphicsAdapterInitialize);
REG_FUNC(cellSail, cellSailGraphicsAdapterFinalize);
REG_FUNC(cellSail, cellSailGraphicsAdapterSetPreferredFormat);
REG_FUNC(cellSail, cellSailGraphicsAdapterGetFrame);
REG_FUNC(cellSail, cellSailGraphicsAdapterGetFrame2);
REG_FUNC(cellSail, cellSailGraphicsAdapterGetFormat);
REG_FUNC(cellSail, cellSailGraphicsAdapterUpdateAvSync);
REG_FUNC(cellSail, cellSailGraphicsAdapterPtsToTimePosition);
REG_FUNC(cellSail, cellSailAuReceiverInitialize);
REG_FUNC(cellSail, cellSailAuReceiverFinalize);
REG_FUNC(cellSail, cellSailAuReceiverGet);
REG_FUNC(cellSail, cellSailRendererAudioInitialize);
REG_FUNC(cellSail, cellSailRendererAudioFinalize);
REG_FUNC(cellSail, cellSailRendererAudioNotifyCallCompleted);
REG_FUNC(cellSail, cellSailRendererAudioNotifyFrameDone);
REG_FUNC(cellSail, cellSailRendererAudioNotifyOutputEos);
REG_FUNC(cellSail, cellSailRendererVideoInitialize);
REG_FUNC(cellSail, cellSailRendererVideoFinalize);
REG_FUNC(cellSail, cellSailRendererVideoNotifyCallCompleted);
REG_FUNC(cellSail, cellSailRendererVideoNotifyFrameDone);
REG_FUNC(cellSail, cellSailRendererVideoNotifyOutputEos);
REG_FUNC(cellSail, cellSailSourceInitialize);
REG_FUNC(cellSail, cellSailSourceFinalize);
REG_FUNC(cellSail, cellSailSourceNotifyCallCompleted);
REG_FUNC(cellSail, cellSailSourceNotifyInputEos);
REG_FUNC(cellSail, cellSailSourceNotifyStreamOut);
REG_FUNC(cellSail, cellSailSourceNotifySessionError);
REG_FUNC(cellSail, cellSailSourceNotifyMediaStateChanged);
REG_FUNC(cellSail, cellSailSourceSetDiagHandler);
{
// these functions shouldn't exist
REG_FUNC(cellSail, cellSailSourceNotifyOpenCompleted);
REG_FUNC(cellSail, cellSailSourceNotifyStartCompleted);
REG_FUNC(cellSail, cellSailSourceNotifyStopCompleted);
REG_FUNC(cellSail, cellSailSourceNotifyReadCompleted);
REG_FUNC(cellSail, cellSailSourceNotifyCloseCompleted);
}
REG_FUNC(cellSail, cellSailMp4MovieGetBrand);
REG_FUNC(cellSail, cellSailMp4MovieIsCompatibleBrand);
REG_FUNC(cellSail, cellSailMp4MovieGetMovieInfo);
REG_FUNC(cellSail, cellSailMp4MovieGetTrackByIndex);
REG_FUNC(cellSail, cellSailMp4MovieGetTrackById);
REG_FUNC(cellSail, cellSailMp4MovieGetTrackByTypeAndIndex);
REG_FUNC(cellSail, cellSailMp4TrackGetTrackInfo);
REG_FUNC(cellSail, cellSailMp4TrackGetTrackReferenceCount);
REG_FUNC(cellSail, cellSailMp4TrackGetTrackReference);
REG_FUNC(cellSail, cellSailAviMovieGetMovieInfo);
REG_FUNC(cellSail, cellSailAviMovieGetStreamByIndex);
REG_FUNC(cellSail, cellSailAviMovieGetStreamByTypeAndIndex);
REG_FUNC(cellSail, cellSailAviMovieGetHeader);
REG_FUNC(cellSail, cellSailAviStreamGetMediaType);
REG_FUNC(cellSail, cellSailAviStreamGetHeader);
REG_FUNC(cellSail, cellSailPlayerInitialize);
REG_FUNC(cellSail, cellSailPlayerInitialize2);
REG_FUNC(cellSail, cellSailPlayerFinalize);
REG_FUNC(cellSail, cellSailPlayerRegisterSource);
REG_FUNC(cellSail, cellSailPlayerGetRegisteredProtocols);
REG_FUNC(cellSail, cellSailPlayerSetSoundAdapter);
REG_FUNC(cellSail, cellSailPlayerSetGraphicsAdapter);
REG_FUNC(cellSail, cellSailPlayerSetAuReceiver);
REG_FUNC(cellSail, cellSailPlayerSetRendererAudio);
REG_FUNC(cellSail, cellSailPlayerSetRendererVideo);
REG_FUNC(cellSail, cellSailPlayerSetParameter);
REG_FUNC(cellSail, cellSailPlayerGetParameter);
REG_FUNC(cellSail, cellSailPlayerSubscribeEvent);
REG_FUNC(cellSail, cellSailPlayerUnsubscribeEvent);
REG_FUNC(cellSail, cellSailPlayerReplaceEventHandler);
REG_FUNC(cellSail, cellSailPlayerBoot);
REG_FUNC(cellSail, cellSailPlayerCreateDescriptor);
REG_FUNC(cellSail, cellSailPlayerDestroyDescriptor);
REG_FUNC(cellSail, cellSailPlayerAddDescriptor);
REG_FUNC(cellSail, cellSailPlayerRemoveDescriptor);
REG_FUNC(cellSail, cellSailPlayerGetDescriptorCount);
REG_FUNC(cellSail, cellSailPlayerGetCurrentDescriptor);
REG_FUNC(cellSail, cellSailPlayerOpenStream);
REG_FUNC(cellSail, cellSailPlayerCloseStream);
REG_FUNC(cellSail, cellSailPlayerOpenEsAudio);
REG_FUNC(cellSail, cellSailPlayerOpenEsVideo);
REG_FUNC(cellSail, cellSailPlayerOpenEsUser);
REG_FUNC(cellSail, cellSailPlayerReopenEsAudio);
REG_FUNC(cellSail, cellSailPlayerReopenEsVideo);
REG_FUNC(cellSail, cellSailPlayerReopenEsUser);
REG_FUNC(cellSail, cellSailPlayerCloseEsAudio);
REG_FUNC(cellSail, cellSailPlayerCloseEsVideo);
REG_FUNC(cellSail, cellSailPlayerCloseEsUser);
REG_FUNC(cellSail, cellSailPlayerStart);
REG_FUNC(cellSail, cellSailPlayerStop);
REG_FUNC(cellSail, cellSailPlayerNext);
REG_FUNC(cellSail, cellSailPlayerCancel);
REG_FUNC(cellSail, cellSailPlayerSetPaused);
REG_FUNC(cellSail, cellSailPlayerIsPaused);
REG_FUNC(cellSail, cellSailPlayerSetRepeatMode);
REG_FUNC(cellSail, cellSailPlayerGetRepeatMode);
REG_FUNC(cellSail, cellSailPlayerSetEsAudioMuted);
REG_FUNC(cellSail, cellSailPlayerSetEsVideoMuted);
REG_FUNC(cellSail, cellSailPlayerIsEsAudioMuted);
REG_FUNC(cellSail, cellSailPlayerIsEsVideoMuted);
REG_FUNC(cellSail, cellSailPlayerDumpImage);
REG_FUNC(cellSail, cellSailPlayerUnregisterSource);
});
| 30,982
|
C++
|
.cpp
| 996
| 29.103414
| 206
| 0.80442
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| false
| false
|
5,247
|
sceNpTus.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/sceNpTus.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
#include "Emu/IdManager.h"
#include "sceNp.h"
#include "sceNpTus.h"
#include "Emu/NP/np_handler.h"
LOG_CHANNEL(sceNpTus);
bool is_slot_array_valid(vm::cptr<SceNpTusSlotId> slotIdArray, s32 arrayNum)
{
for (s32 i = 0; i < arrayNum; i++)
{
if (slotIdArray[i] < 0)
{
return false;
}
}
return true;
}
const SceNpOnlineId& get_scenp_online_id(const SceNpId& target_npid)
{
return target_npid.handle;
}
const SceNpOnlineId& get_scenp_online_id(const SceNpTusVirtualUserId& target_npid)
{
return target_npid;
}
error_code sceNpTusInit(s32 prio)
{
sceNpTus.warning("sceNpTusInit(prio=%d)", prio);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (nph.is_NP_TUS_init)
{
return SCE_NP_COMMUNITY_ERROR_ALREADY_INITIALIZED;
}
if (!nph.is_NP_init)
{
return SCE_NP_ERROR_NOT_INITIALIZED;
}
nph.is_NP_TUS_init = true;
return CELL_OK;
}
error_code sceNpTusTerm()
{
sceNpTus.warning("sceNpTusTerm()");
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_TUS_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (!nph.is_NP_init)
{
return SCE_NP_ERROR_NOT_INITIALIZED;
}
nph.is_NP_TUS_init = false;
return CELL_OK;
}
error_code sceNpTusCreateTitleCtx(vm::cptr<SceNpCommunicationId> communicationId, vm::cptr<SceNpCommunicationPassphrase> passphrase, vm::cptr<SceNpId> selfNpId)
{
sceNpTus.warning("sceNpTusCreateTitleCtx(communicationId=*0x%x, passphrase=*0x%x, selfNpId=*0x%x)", communicationId, passphrase, selfNpId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_TUS_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (!communicationId || !passphrase || !selfNpId)
{
return SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT;
}
s32 id = create_tus_context(communicationId, passphrase);
if (id > 0)
{
return not_an_error(id);
}
return id;
}
error_code sceNpTusDestroyTitleCtx(s32 titleCtxId)
{
sceNpTus.warning("sceNpTusDestroyTitleCtx(titleCtxId=%d)", titleCtxId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_TUS_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (!destroy_tus_context(titleCtxId))
return SCE_NP_COMMUNITY_ERROR_INVALID_ID;
return CELL_OK;
}
error_code sceNpTusCreateTransactionCtx(s32 titleCtxId)
{
sceNpTus.warning("sceNpTusCreateTransactionCtx(titleCtxId=%d)", titleCtxId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_TUS_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (nph.get_psn_status() == SCE_NP_MANAGER_STATUS_OFFLINE)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ONLINE_ID;
}
auto tus = idm::get<tus_ctx>(titleCtxId);
if (!tus)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ID;
}
s32 id = create_tus_transaction_context(tus);
if (id > 0)
{
return not_an_error(id);
}
return id;
}
error_code sceNpTusDestroyTransactionCtx(s32 transId)
{
sceNpTus.warning("sceNpTusDestroyTransactionCtx(transId=%d)", transId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_TUS_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (!destroy_tus_transaction_context(transId))
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ID;
}
return CELL_OK;
}
error_code sceNpTusSetTimeout(s32 ctxId, u32 timeout)
{
sceNpTus.warning("sceNpTusSetTimeout(ctxId=%d, timeout=%d)", ctxId, timeout);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_TUS_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (timeout < 10'000'000) // 10 seconds
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
const u32 idm_id = static_cast<u32>(ctxId);
if (idm_id >= tus_transaction_ctx::id_base && idm_id < (tus_transaction_ctx::id_base + tus_transaction_ctx::id_count))
{
auto trans = idm::get<tus_transaction_ctx>(ctxId);
if (!trans)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ID;
}
trans->timeout = timeout;
}
else if (idm_id >= tus_ctx::id_base && idm_id < (tus_ctx::id_base + tus_ctx::id_count))
{
auto tus = idm::get<tus_ctx>(ctxId);
if (!ctxId)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ID;
}
tus->timeout = timeout;
}
else
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ID;
}
return CELL_OK;
}
error_code sceNpTusAbortTransaction(s32 transId)
{
sceNpTus.warning("sceNpTusAbortTransaction(transId=%d)", transId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_TUS_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
auto trans = idm::get<tus_transaction_ctx>(transId);
if (!trans)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ID;
}
trans->abort_transaction();
return CELL_OK;
}
error_code sceNpTusWaitAsync(s32 transId, vm::ptr<s32> result)
{
sceNpTus.warning("sceNpTusWaitAsync(transId=%d, result=*0x%x)", transId, result);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_TUS_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
auto trans = idm::get<tus_transaction_ctx>(transId);
if (!trans)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ID;
}
*result = trans->wait_for_completion();
return CELL_OK;
}
error_code sceNpTusPollAsync(s32 transId, vm::ptr<s32> result)
{
sceNpTus.warning("sceNpTusPollAsync(transId=%d, result=*0x%x)", transId, result);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_TUS_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
auto trans = idm::get<tus_transaction_ctx>(transId);
if (!trans)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ID;
}
auto res = trans->get_transaction_status();
if (!res)
{
return not_an_error(1);
}
*result = *res;
return CELL_OK;
}
template<typename T>
error_code scenp_tus_set_multislot_variable(s32 transId, T targetNpId, vm::cptr<SceNpTusSlotId> slotIdArray, vm::cptr<s64> variableArray, s32 arrayNum, vm::ptr<void> option, bool vuser, bool async)
{
if (!slotIdArray || !variableArray)
{
return SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT;
}
if (arrayNum == 0 || option)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
if (arrayNum > SCE_NP_TUS_MAX_SLOT_NUM_PER_TRANS)
{
return SCE_NP_COMMUNITY_ERROR_TOO_MANY_SLOTID;
}
if (!is_slot_array_valid(slotIdArray, arrayNum))
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_TUS_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (!targetNpId)
{
return SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT;
}
// Probable vsh behaviour
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ONLINE_ID;
}
auto trans_ctx = idm::get<tus_transaction_ctx>(transId);
if (!trans_ctx)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ID;
}
nph.tus_set_multislot_variable(trans_ctx, get_scenp_online_id(*targetNpId.get_ptr()), slotIdArray, variableArray, arrayNum, vuser, async);
if (async)
{
return CELL_OK;
}
return *trans_ctx->result;
}
error_code sceNpTusSetMultiSlotVariable(s32 transId, vm::cptr<SceNpId> targetNpId, vm::cptr<SceNpTusSlotId> slotIdArray, vm::cptr<s64> variableArray, s32 arrayNum, vm::ptr<void> option)
{
sceNpTus.warning("sceNpTusSetMultiSlotVariable(transId=%d, targetNpId=*0x%x, slotIdArray=*0x%x, variableArray=*0x%x, arrayNum=%d, option=*0x%x)", transId, targetNpId, slotIdArray, variableArray, arrayNum, option);
return scenp_tus_set_multislot_variable(transId, targetNpId, slotIdArray, variableArray, arrayNum, option, false, false);
}
error_code sceNpTusSetMultiSlotVariableVUser(s32 transId, vm::cptr<SceNpTusVirtualUserId> targetVirtualUserId, vm::cptr<SceNpTusSlotId> slotIdArray, vm::cptr<s64> variableArray, s32 arrayNum, vm::ptr<void> option)
{
sceNpTus.warning("sceNpTusSetMultiSlotVariableVUser(transId=%d, targetVirtualUserId=*0x%x, slotIdArray=*0x%x, variableArray=*0x%x, arrayNum=%d, option=*0x%x)", transId, targetVirtualUserId, slotIdArray, variableArray, arrayNum, option);
return scenp_tus_set_multislot_variable(transId, targetVirtualUserId, slotIdArray, variableArray, arrayNum, option, true, false);
}
error_code sceNpTusSetMultiSlotVariableAsync(s32 transId, vm::cptr<SceNpId> targetNpId, vm::cptr<SceNpTusSlotId> slotIdArray, vm::cptr<s64> variableArray, s32 arrayNum, vm::ptr<void> option)
{
sceNpTus.warning("sceNpTusSetMultiSlotVariableAsync(transId=%d, targetNpId=*0x%x, slotIdArray=*0x%x, variableArray=*0x%x, arrayNum=%d, option=*0x%x)", transId, targetNpId, slotIdArray, variableArray, arrayNum, option);
return scenp_tus_set_multislot_variable(transId, targetNpId, slotIdArray, variableArray, arrayNum, option, false, true);
}
error_code sceNpTusSetMultiSlotVariableVUserAsync(s32 transId, vm::cptr<SceNpTusVirtualUserId> targetVirtualUserId, vm::cptr<SceNpTusSlotId> slotIdArray, vm::cptr<s64> variableArray, s32 arrayNum, vm::ptr<void> option)
{
sceNpTus.warning("sceNpTusSetMultiSlotVariableVUserAsync(transId=%d, targetVirtualUserId=*0x%x, slotIdArray=*0x%x, variableArray=*0x%x, arrayNum=%d, option=*0x%x)", transId, targetVirtualUserId, slotIdArray, variableArray, arrayNum, option);
return scenp_tus_set_multislot_variable(transId, targetVirtualUserId, slotIdArray, variableArray, arrayNum, option, true, true);
}
template<typename T>
error_code scenp_tus_get_multislot_variable(s32 transId, T targetNpId, vm::cptr<SceNpTusSlotId> slotIdArray, vm::ptr<SceNpTusVariable> variableArray, u32 variableArraySize, s32 arrayNum, vm::ptr<void> option, bool vuser, bool async)
{
if (!slotIdArray || !variableArray)
{
return SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT;
}
if (arrayNum == 0 || option)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
if (variableArraySize != arrayNum * sizeof(SceNpTusVariable))
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ALIGNMENT;
}
if (arrayNum > SCE_NP_TUS_MAX_SLOT_NUM_PER_TRANS)
{
return SCE_NP_COMMUNITY_ERROR_TOO_MANY_SLOTID;
}
if (!is_slot_array_valid(slotIdArray, arrayNum))
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_TUS_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (!targetNpId)
{
return SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT;
}
// Probable vsh behaviour
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ONLINE_ID;
}
auto trans_ctx = idm::get<tus_transaction_ctx>(transId);
if (!trans_ctx)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ID;
}
nph.tus_get_multislot_variable(trans_ctx, get_scenp_online_id(*targetNpId.get_ptr()), slotIdArray, variableArray, arrayNum, vuser, async);
if (async)
{
return CELL_OK;
}
return *trans_ctx->result;
}
error_code sceNpTusGetMultiSlotVariable(s32 transId, vm::cptr<SceNpId> targetNpId, vm::cptr<SceNpTusSlotId> slotIdArray, vm::ptr<SceNpTusVariable> variableArray, u32 variableArraySize, s32 arrayNum, vm::ptr<void> option)
{
sceNpTus.warning("sceNpTusGetMultiSlotVariable(transId=%d, targetNpId=*0x%x, slotIdArray=*0x%x, variableArray=*0x%x, variableArraySize=%d, arrayNum=%d, option=*0x%x)", transId, targetNpId, slotIdArray, variableArray, variableArraySize, arrayNum, option);
return scenp_tus_get_multislot_variable(transId, targetNpId, slotIdArray, variableArray, variableArraySize, arrayNum, option, false, false);
}
error_code sceNpTusGetMultiSlotVariableVUser(s32 transId, vm::cptr<SceNpTusVirtualUserId> targetVirtualUserId, vm::cptr<SceNpTusSlotId> slotIdArray, vm::ptr<SceNpTusVariable> variableArray, u32 variableArraySize, s32 arrayNum, vm::ptr<void> option)
{
sceNpTus.warning("sceNpTusGetMultiSlotVariableVUser(transId=%d, targetVirtualUserId=*0x%x, slotIdArray=*0x%x, variableArray=*0x%x, variableArraySize=%d, arrayNum=%d, option=*0x%x)", transId, targetVirtualUserId, slotIdArray, variableArray, variableArraySize, arrayNum, option);
return scenp_tus_get_multislot_variable(transId, targetVirtualUserId, slotIdArray, variableArray, variableArraySize, arrayNum, option, true, false);
}
error_code sceNpTusGetMultiSlotVariableAsync(s32 transId, vm::cptr<SceNpId> targetNpId, vm::cptr<SceNpTusSlotId> slotIdArray, vm::ptr<SceNpTusVariable> variableArray, u32 variableArraySize, s32 arrayNum, vm::ptr<void> option)
{
sceNpTus.warning("sceNpTusGetMultiSlotVariableAsync(transId=%d, targetNpId=*0x%x, slotIdArray=*0x%x, variableArray=*0x%x, variableArraySize=%d, arrayNum=%d, option=*0x%x)", transId, targetNpId, slotIdArray, variableArray, variableArraySize, arrayNum, option);
return scenp_tus_get_multislot_variable(transId, targetNpId, slotIdArray, variableArray, variableArraySize, arrayNum, option, false, true);
}
error_code sceNpTusGetMultiSlotVariableVUserAsync(s32 transId, vm::cptr<SceNpTusVirtualUserId> targetVirtualUserId, vm::cptr<SceNpTusSlotId> slotIdArray, vm::ptr<SceNpTusVariable> variableArray, u32 variableArraySize, s32 arrayNum, vm::ptr<void> option)
{
sceNpTus.warning("sceNpTusGetMultiSlotVariableVUserAsync(transId=%d, targetVirtualUserId=*0x%x, slotIdArray=*0x%x, variableArray=*0x%x, variableArraySize=%d, arrayNum=%d, option=*0x%x)", transId, targetVirtualUserId, slotIdArray, variableArray, variableArraySize, arrayNum, option);
return scenp_tus_get_multislot_variable(transId, targetVirtualUserId, slotIdArray, variableArray, variableArraySize, arrayNum, option, true, true);
}
template<typename T>
error_code scenp_tus_get_multiuser_variable(s32 transId, T targetNpIdArray, SceNpTusSlotId slotId, vm::ptr<SceNpTusVariable> variableArray, u32 variableArraySize, s32 arrayNum, vm::ptr<void> option, bool vuser, bool async)
{
if (!variableArray)
{
return SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT;
}
if (arrayNum == 0 || option)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
if (arrayNum > SCE_NP_SCORE_MAX_NPID_NUM_PER_TRANS)
{
return SCE_NP_COMMUNITY_ERROR_TOO_MANY_NPID;
}
if (variableArraySize != arrayNum * sizeof(SceNpTusVariable))
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ALIGNMENT;
}
if (slotId < 0)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_TUS_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (!targetNpIdArray)
{
return SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT;
}
// Probable vsh behaviour
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ONLINE_ID;
}
auto trans_ctx = idm::get<tus_transaction_ctx>(transId);
if (!trans_ctx)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ID;
}
std::vector<SceNpOnlineId> online_ids;
for (s32 i = 0; i < arrayNum; i++)
{
online_ids.push_back(get_scenp_online_id(targetNpIdArray[i]));
}
nph.tus_get_multiuser_variable(trans_ctx, std::move(online_ids), slotId, variableArray, arrayNum, vuser, async);
if (async)
{
return CELL_OK;
}
return *trans_ctx->result;
}
error_code sceNpTusGetMultiUserVariable(s32 transId, vm::cptr<SceNpId> targetNpIdArray, SceNpTusSlotId slotId, vm::ptr<SceNpTusVariable> variableArray, u32 variableArraySize, s32 arrayNum, vm::ptr<void> option)
{
sceNpTus.warning("sceNpTusGetMultiUserVariable(transId=%d, targetNpIdArray=*0x%x, slotId=%d, variableArray=*0x%x, variableArraySize=%d, arrayNum=%d, option=*0x%x)", transId, targetNpIdArray, slotId, variableArray, variableArraySize, arrayNum, option);
return scenp_tus_get_multiuser_variable(transId, targetNpIdArray, slotId, variableArray, variableArraySize, arrayNum, option, false, false);
}
error_code sceNpTusGetMultiUserVariableVUser(s32 transId, vm::cptr<SceNpTusVirtualUserId> targetVirtualUserIdArray, SceNpTusSlotId slotId, vm::ptr<SceNpTusVariable> variableArray, u32 variableArraySize, s32 arrayNum, vm::ptr<void> option)
{
sceNpTus.warning("sceNpTusGetMultiUserVariableVUser(transId=%d, targetVirtualUserIdArray=*0x%x, slotId=%d, variableArray=*0x%x, variableArraySize=%d, arrayNum=%d, option=*0x%x)", transId, targetVirtualUserIdArray, slotId, variableArray, variableArraySize, arrayNum, option);
return scenp_tus_get_multiuser_variable(transId, targetVirtualUserIdArray, slotId, variableArray, variableArraySize, arrayNum, option, true, false);
}
error_code sceNpTusGetMultiUserVariableAsync(s32 transId, vm::cptr<SceNpId> targetNpIdArray, SceNpTusSlotId slotId, vm::ptr<SceNpTusVariable> variableArray, u32 variableArraySize, s32 arrayNum, vm::ptr<void> option)
{
sceNpTus.warning("sceNpTusGetMultiUserVariableAsync(transId=%d, targetNpIdArray=*0x%x, slotId=%d, variableArray=*0x%x, variableArraySize=%d, arrayNum=%d, option=*0x%x)", transId, targetNpIdArray, slotId, variableArray, variableArraySize, arrayNum, option);
return scenp_tus_get_multiuser_variable(transId, targetNpIdArray, slotId, variableArray, variableArraySize, arrayNum, option, false, true);
}
error_code sceNpTusGetMultiUserVariableVUserAsync(s32 transId, vm::cptr<SceNpTusVirtualUserId> targetVirtualUserIdArray, SceNpTusSlotId slotId, vm::ptr<SceNpTusVariable> variableArray, u32 variableArraySize, s32 arrayNum, vm::ptr<void> option)
{
sceNpTus.warning("sceNpTusGetMultiUserVariableVUserAsync(transId=%d, targetVirtualUserIdArray=*0x%x, slotId=%d, variableArray=*0x%x, variableArraySize=%d, arrayNum=%d, option=*0x%x)", transId, targetVirtualUserIdArray, slotId, variableArray, variableArraySize, arrayNum, option);
return scenp_tus_get_multiuser_variable(transId, targetVirtualUserIdArray, slotId, variableArray, variableArraySize, arrayNum, option, true, true);
}
error_code scenp_tus_get_friends_variable(s32 transId, SceNpTusSlotId slotId, s32 includeSelf, s32 sortType, vm::ptr<SceNpTusVariable> variableArray, u32 variableArraySize, s32 arrayNum, vm::ptr<void> option, bool async)
{
if (!variableArray)
{
return SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT;
}
if (arrayNum == 0)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
// Undocumented behaviour and structure unknown
// Also checks a u32* at offset 4 of the struct for nullptr in which case it behaves like option == nullptr
if (option && *static_cast<u32*>(option.get_ptr()) != 0xC)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
if (sortType < SCE_NP_TUS_VARIABLE_SORTTYPE_DESCENDING_DATE || sortType > SCE_NP_TUS_VARIABLE_SORTTYPE_ASCENDING_VALUE)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
if (arrayNum > SCE_NP_SCORE_MAX_SELECTED_FRIENDS_NUM)
{
return SCE_NP_COMMUNITY_ERROR_TOO_MANY_NPID;
}
if (variableArraySize != arrayNum * sizeof(SceNpTusVariable))
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ALIGNMENT;
}
if (slotId < 0)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_TUS_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
// Probable vsh behaviour
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ONLINE_ID;
}
auto trans_ctx = idm::get<tus_transaction_ctx>(transId);
if (!trans_ctx)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ID;
}
nph.tus_get_friends_variable(trans_ctx, slotId, includeSelf, sortType, variableArray, arrayNum, async);
if (async)
{
return CELL_OK;
}
return *trans_ctx->result;
}
error_code sceNpTusGetFriendsVariable(s32 transId, SceNpTusSlotId slotId, s32 includeSelf, s32 sortType, vm::ptr<SceNpTusVariable> variableArray, u32 variableArraySize, s32 arrayNum, vm::ptr<void> option)
{
sceNpTus.warning("sceNpTusGetFriendsVariable(transId=%d, slotId=%d, includeSelf=%d, sortType=%d, variableArray=*0x%x, variableArraySize=%d, arrayNum=%d, option=*0x%x)", transId, slotId, includeSelf, sortType, variableArray, variableArraySize, arrayNum, option);
return scenp_tus_get_friends_variable(transId, slotId, includeSelf, sortType, variableArray, variableArraySize, arrayNum, option, false);
}
error_code sceNpTusGetFriendsVariableAsync(s32 transId, SceNpTusSlotId slotId, s32 includeSelf, s32 sortType, vm::ptr<SceNpTusVariable> variableArray, u32 variableArraySize, s32 arrayNum, vm::ptr<void> option)
{
sceNpTus.warning("sceNpTusGetFriendsVariableAsync(transId=%d, slotId=%d, includeSelf=%d, sortType=%d, variableArray=*0x%x, variableArraySize=%d, arrayNum=%d, option=*0x%x)", transId, slotId, includeSelf, sortType, variableArray, variableArraySize, arrayNum, option);
return scenp_tus_get_friends_variable(transId, slotId, includeSelf, sortType, variableArray, variableArraySize, arrayNum, option, true);
}
template<typename T>
error_code scenp_tus_add_and_get_variable(s32 transId, T targetNpId, SceNpTusSlotId slotId, s64 inVariable, vm::ptr<SceNpTusVariable> outVariable, u32 outVariableSize, vm::ptr<SceNpTusAddAndGetVariableOptParam> option, bool vuser, bool async)
{
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_TUS_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (slotId < 0)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
if ((option && option->size != sizeof(SceNpTusAddAndGetVariableOptParam)) || outVariableSize != sizeof(SceNpTusVariable))
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ALIGNMENT;
}
if (!targetNpId)
{
return SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT;
}
// Probable vsh behaviour
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ONLINE_ID;
}
auto trans_ctx = idm::get<tus_transaction_ctx>(transId);
if (!trans_ctx)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ID;
}
nph.tus_add_and_get_variable(trans_ctx, get_scenp_online_id(*targetNpId.get_ptr()), slotId, inVariable, outVariable, option, vuser, async);
if (async)
{
return CELL_OK;
}
return *trans_ctx->result;
}
error_code sceNpTusAddAndGetVariable(s32 transId, vm::cptr<SceNpId> targetNpId, SceNpTusSlotId slotId, s64 inVariable, vm::ptr<SceNpTusVariable> outVariable, u32 outVariableSize, vm::ptr<SceNpTusAddAndGetVariableOptParam> option)
{
sceNpTus.warning("sceNpTusAddAndGetVariable(transId=%d, targetNpId=*0x%x, slotId=%d, inVariable=%d, outVariable=*0x%x, outVariableSize=%d, option=*0x%x)", transId, targetNpId, slotId, inVariable, outVariable, outVariableSize, option);
return scenp_tus_add_and_get_variable(transId, targetNpId, slotId, inVariable, outVariable, outVariableSize, option, false, false);
}
error_code sceNpTusAddAndGetVariableVUser(s32 transId, vm::cptr<SceNpTusVirtualUserId> targetVirtualUserId, SceNpTusSlotId slotId, s64 inVariable, vm::ptr<SceNpTusVariable> outVariable, u32 outVariableSize, vm::ptr<SceNpTusAddAndGetVariableOptParam> option)
{
sceNpTus.warning("sceNpTusAddAndGetVariableVUser(transId=%d, targetVirtualUserId=*0x%x, slotId=%d, inVariable=%d, outVariable=*0x%x, outVariableSize=%d, option=*0x%x)", transId, targetVirtualUserId, slotId, inVariable, outVariable, outVariableSize, option);
return scenp_tus_add_and_get_variable(transId, targetVirtualUserId, slotId, inVariable, outVariable, outVariableSize, option, true, false);
}
error_code sceNpTusAddAndGetVariableAsync(s32 transId, vm::cptr<SceNpId> targetNpId, SceNpTusSlotId slotId, s64 inVariable, vm::ptr<SceNpTusVariable> outVariable, u32 outVariableSize, vm::ptr<SceNpTusAddAndGetVariableOptParam> option)
{
sceNpTus.warning("sceNpTusAddAndGetVariableAsync(transId=%d, targetNpId=*0x%x, slotId=%d, inVariable=%d, outVariable=*0x%x, outVariableSize=%d, option=*0x%x)", transId, targetNpId, slotId, inVariable, outVariable, outVariableSize, option);
return scenp_tus_add_and_get_variable(transId, targetNpId, slotId, inVariable, outVariable, outVariableSize, option, false, true);
}
error_code sceNpTusAddAndGetVariableVUserAsync(s32 transId, vm::cptr<SceNpTusVirtualUserId> targetVirtualUserId, SceNpTusSlotId slotId, s64 inVariable, vm::ptr<SceNpTusVariable> outVariable, u32 outVariableSize, vm::ptr<SceNpTusAddAndGetVariableOptParam> option)
{
sceNpTus.warning("sceNpTusAddAndGetVariableVUserAsync(transId=%d, targetVirtualUserId=*0x%x, slotId=%d, inVariable=%d, outVariable=*0x%x, outVariableSize=%d, option=*0x%x)", transId, targetVirtualUserId, slotId, inVariable, outVariable, outVariableSize, option);
return scenp_tus_add_and_get_variable(transId, targetVirtualUserId, slotId, inVariable, outVariable, outVariableSize, option, true, true);
}
template<typename T>
error_code scenp_tus_try_and_set_variable(s32 transId, T targetNpId, SceNpTusSlotId slotId, s32 opeType, s64 variable, vm::ptr<SceNpTusVariable> resultVariable, u32 resultVariableSize, vm::ptr<SceNpTusTryAndSetVariableOptParam> option, bool vuser, bool async)
{
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_TUS_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (!resultVariable)
{
return SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT;
}
if (slotId < 0)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
if ((option && option->size != sizeof(SceNpTusTryAndSetVariableOptParam)) || resultVariableSize != sizeof(SceNpTusVariable))
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ALIGNMENT;
}
if (!targetNpId)
{
return SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT;
}
// Probable vsh behaviour
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ONLINE_ID;
}
auto trans_ctx = idm::get<tus_transaction_ctx>(transId);
if (!trans_ctx)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ID;
}
nph.tus_try_and_set_variable(trans_ctx, get_scenp_online_id(*targetNpId.get_ptr()), slotId, opeType, variable, resultVariable, option, vuser, async);
if (async)
{
return CELL_OK;
}
return *trans_ctx->result;
}
error_code sceNpTusTryAndSetVariable(s32 transId, vm::cptr<SceNpId> targetNpId, SceNpTusSlotId slotId, s32 opeType, s64 variable, vm::ptr<SceNpTusVariable> resultVariable, u32 resultVariableSize, vm::ptr<SceNpTusTryAndSetVariableOptParam> option)
{
sceNpTus.warning("sceNpTusTryAndSetVariable(transId=%d, targetNpId=*0x%x, slotId=%d, opeType=%d, variable=%d, resultVariable=*0x%x, resultVariableSize=%d, option=*0x%x)", transId, targetNpId, slotId, opeType, variable, resultVariable, resultVariableSize, option);
return scenp_tus_try_and_set_variable(transId, targetNpId, slotId, opeType, variable, resultVariable, resultVariableSize, option, false, false);
}
error_code sceNpTusTryAndSetVariableVUser(s32 transId, vm::cptr<SceNpTusVirtualUserId> targetVirtualUserId, SceNpTusSlotId slotId, s32 opeType, s64 variable, vm::ptr<SceNpTusVariable> resultVariable, u32 resultVariableSize, vm::ptr<SceNpTusTryAndSetVariableOptParam> option)
{
sceNpTus.warning("sceNpTusTryAndSetVariableVUser(transId=%d, targetVirtualUserId=*0x%x, slotId=%d, opeType=%d, variable=%d, resultVariable=*0x%x, resultVariableSize=%d, option=*0x%x)", transId, targetVirtualUserId, slotId, opeType, variable, resultVariable, resultVariableSize, option);
return scenp_tus_try_and_set_variable(transId, targetVirtualUserId, slotId, opeType, variable, resultVariable, resultVariableSize, option, true, false);
}
error_code sceNpTusTryAndSetVariableAsync(s32 transId, vm::cptr<SceNpId> targetNpId, SceNpTusSlotId slotId, s32 opeType, s64 variable, vm::ptr<SceNpTusVariable> resultVariable, u32 resultVariableSize, vm::ptr<SceNpTusTryAndSetVariableOptParam> option)
{
sceNpTus.warning("sceNpTusTryAndSetVariableAsync(transId=%d, targetNpId=*0x%x, slotId=%d, opeType=%d, variable=%d, resultVariable=*0x%x, resultVariableSize=%d, option=*0x%x)", transId, targetNpId, slotId, opeType, variable, resultVariable, resultVariableSize, option);
return scenp_tus_try_and_set_variable(transId, targetNpId, slotId, opeType, variable, resultVariable, resultVariableSize, option, false, true);
}
error_code sceNpTusTryAndSetVariableVUserAsync(s32 transId, vm::cptr<SceNpTusVirtualUserId> targetVirtualUserId, SceNpTusSlotId slotId, s32 opeType, s64 variable, vm::ptr<SceNpTusVariable> resultVariable, u32 resultVariableSize, vm::ptr<SceNpTusTryAndSetVariableOptParam> option)
{
sceNpTus.warning("sceNpTusTryAndSetVariableVUserAsync(transId=%d, targetVirtualUserId=*0x%x, slotId=%d, opeType=%d, variable=%d, resultVariable=*0x%x, resultVariableSize=%d, option=*0x%x)", transId, targetVirtualUserId, slotId, opeType, variable, resultVariable, resultVariableSize, option);
return scenp_tus_try_and_set_variable(transId, targetVirtualUserId, slotId, opeType, variable, resultVariable, resultVariableSize, option, true, true);
}
template<typename T>
error_code scenp_tus_delete_multislot_variable(s32 transId, T targetNpId, vm::cptr<SceNpTusSlotId> slotIdArray, s32 arrayNum, vm::ptr<void> option, bool vuser, bool async)
{
if (!slotIdArray)
{
return SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT;
}
if (arrayNum == 0 || option)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
if (arrayNum > SCE_NP_TUS_MAX_SLOT_NUM_PER_TRANS)
{
return SCE_NP_COMMUNITY_ERROR_TOO_MANY_SLOTID;
}
if (!is_slot_array_valid(slotIdArray, arrayNum))
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_TUS_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
// Probable vsh behaviour
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ONLINE_ID;
}
auto trans_ctx = idm::get<tus_transaction_ctx>(transId);
if (!trans_ctx)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ID;
}
nph.tus_delete_multislot_variable(trans_ctx, get_scenp_online_id(*targetNpId.get_ptr()), slotIdArray, arrayNum, vuser, async);
if (async)
{
return CELL_OK;
}
return *trans_ctx->result;
}
error_code sceNpTusDeleteMultiSlotVariable(s32 transId, vm::cptr<SceNpId> targetNpId, vm::cptr<SceNpTusSlotId> slotIdArray, s32 arrayNum, vm::ptr<void> option)
{
sceNpTus.warning("sceNpTusDeleteMultiSlotVariable(transId=%d, targetNpId=*0x%x, slotIdArray=*0x%x, arrayNum=%d, option=*0x%x)", transId, targetNpId, slotIdArray, arrayNum, option);
return scenp_tus_delete_multislot_variable(transId, targetNpId, slotIdArray, arrayNum, option, false, false);
}
error_code sceNpTusDeleteMultiSlotVariableVUser(s32 transId, vm::cptr<SceNpTusVirtualUserId> targetVirtualUserId, vm::cptr<SceNpTusSlotId> slotIdArray, s32 arrayNum, vm::ptr<void> option)
{
sceNpTus.warning("sceNpTusDeleteMultiSlotVariableVUser(transId=%d, targetVirtualUserId=*0x%x, slotIdArray=*0x%x, arrayNum=%d, option=*0x%x)", transId, targetVirtualUserId, slotIdArray, arrayNum, option);
return scenp_tus_delete_multislot_variable(transId, targetVirtualUserId, slotIdArray, arrayNum, option, true, false);
}
error_code sceNpTusDeleteMultiSlotVariableAsync(s32 transId, vm::cptr<SceNpId> targetNpId, vm::cptr<SceNpTusSlotId> slotIdArray, s32 arrayNum, vm::ptr<void> option)
{
sceNpTus.warning("sceNpTusDeleteMultiSlotVariableAsync(transId=%d, targetNpId=*0x%x, slotIdArray=*0x%x, arrayNum=%d, option=*0x%x)", transId, targetNpId, slotIdArray, arrayNum, option);
return scenp_tus_delete_multislot_variable(transId, targetNpId, slotIdArray, arrayNum, option, false, true);
}
error_code sceNpTusDeleteMultiSlotVariableVUserAsync(s32 transId, vm::cptr<SceNpTusVirtualUserId> targetVirtualUserId, vm::cptr<SceNpTusSlotId> slotIdArray, s32 arrayNum, vm::ptr<void> option)
{
sceNpTus.warning("sceNpTusDeleteMultiSlotVariableVUserAsync(transId=%d, targetVirtualUserId=*0x%x, slotIdArray=*0x%x, arrayNum=%d, option=*0x%x)", transId, targetVirtualUserId, slotIdArray, arrayNum, option);
return scenp_tus_delete_multislot_variable(transId, targetVirtualUserId, slotIdArray, arrayNum, option, true, true);
}
template<typename T>
error_code scenp_tus_set_data(s32 transId, T targetNpId, SceNpTusSlotId slotId, u32 totalSize, u32 sendSize, vm::cptr<void> data, vm::cptr<SceNpTusDataInfo> info, u32 infoStructSize, vm::ptr<SceNpTusSetDataOptParam> option, bool vuser, bool async)
{
if (slotId < 0 || !data || !totalSize)
{
return SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT;
}
if ((option && option->size != sizeof(SceNpTusSetDataOptParam)) || (info && infoStructSize != sizeof(SceNpTusDataInfo)))
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ALIGNMENT;
}
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_TUS_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (!targetNpId)
{
return SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT;
}
// Probable vsh behaviour
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ONLINE_ID;
}
auto trans_ctx = idm::get<tus_transaction_ctx>(transId);
if (!trans_ctx)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ID;
}
nph.tus_set_data(trans_ctx, get_scenp_online_id(*targetNpId.get_ptr()), slotId, totalSize, sendSize, data, info, option, vuser, async);
if (async)
{
return CELL_OK;
}
return *trans_ctx->result;
}
error_code sceNpTusSetData(s32 transId, vm::cptr<SceNpId> targetNpId, SceNpTusSlotId slotId, u32 totalSize, u32 sendSize, vm::cptr<void> data, vm::cptr<SceNpTusDataInfo> info, u32 infoStructSize, vm::ptr<SceNpTusSetDataOptParam> option)
{
sceNpTus.warning("sceNpTusSetData(transId=%d, targetNpId=*0x%x, slotId=%d, totalSize=%d, sendSize=%d, data=*0x%x, info=*0x%x, infoStructSize=%d, option=*0x%x)", transId, targetNpId, slotId, totalSize, sendSize, data, info, infoStructSize, option);
return scenp_tus_set_data(transId, targetNpId, slotId, totalSize, sendSize, data, info, infoStructSize, option, false, false);
}
error_code sceNpTusSetDataVUser(s32 transId, vm::cptr<SceNpTusVirtualUserId> targetVirtualUserId, SceNpTusSlotId slotId, u32 totalSize, u32 sendSize, vm::cptr<void> data, vm::cptr<SceNpTusDataInfo> info, u32 infoStructSize, vm::ptr<SceNpTusSetDataOptParam> option)
{
sceNpTus.warning("sceNpTusSetDataVUser(transId=%d, targetVirtualUserId=*0x%x, slotId=%d, totalSize=%d, sendSize=%d, data=*0x%x, info=*0x%x, infoStructSize=%d, option=*0x%x)", transId, targetVirtualUserId, slotId, totalSize, sendSize, data, info, infoStructSize, option);
return scenp_tus_set_data(transId, targetVirtualUserId, slotId, totalSize, sendSize, data, info, infoStructSize, option, true, false);
}
error_code sceNpTusSetDataAsync(s32 transId, vm::cptr<SceNpId> targetNpId, SceNpTusSlotId slotId, u32 totalSize, u32 sendSize, vm::cptr<void> data, vm::cptr<SceNpTusDataInfo> info, u32 infoStructSize, vm::ptr<SceNpTusSetDataOptParam> option)
{
sceNpTus.warning("sceNpTusSetDataAsync(transId=%d, targetNpId=*0x%x, slotId=%d, totalSize=%d, sendSize=%d, data=*0x%x, info=*0x%x, infoStructSize=%d, option=*0x%x)", transId, targetNpId, slotId, totalSize, sendSize, data, info, infoStructSize, option);
return scenp_tus_set_data(transId, targetNpId, slotId, totalSize, sendSize, data, info, infoStructSize, option, false, true);
}
error_code sceNpTusSetDataVUserAsync(s32 transId, vm::cptr<SceNpTusVirtualUserId> targetVirtualUserId, SceNpTusSlotId slotId, u32 totalSize, u32 sendSize, vm::cptr<void> data, vm::cptr<SceNpTusDataInfo> info, u32 infoStructSize, vm::ptr<SceNpTusSetDataOptParam> option)
{
sceNpTus.warning("sceNpTusSetDataVUserAsync(transId=%d, targetVirtualUserId=*0x%x, slotId=%d, totalSize=%d, sendSize=%d, data=*0x%x, info=*0x%x, infoStructSize=%d, option=*0x%x)", transId, targetVirtualUserId, slotId, totalSize, sendSize, data, info, infoStructSize, option);
return scenp_tus_set_data(transId, targetVirtualUserId, slotId, totalSize, sendSize, data, info, infoStructSize, option, true, true);
}
template<typename T>
error_code scenp_tus_get_data(s32 transId, T targetNpId, SceNpTusSlotId slotId, vm::ptr<SceNpTusDataStatus> dataStatus, u32 dataStatusSize, vm::ptr<void> data, u32 recvSize, vm::ptr<void> option, bool vuser, bool async)
{
if (!targetNpId)
{
return SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT;
}
if (option || slotId < 0)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
if (dataStatusSize != sizeof(SceNpTusDataStatus))
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ALIGNMENT;
}
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_TUS_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
// Probable vsh behaviour
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ONLINE_ID;
}
auto trans_ctx = idm::get<tus_transaction_ctx>(transId);
if (!trans_ctx)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ID;
}
nph.tus_get_data(trans_ctx, get_scenp_online_id(*targetNpId.get_ptr()), slotId, dataStatus, data, recvSize, vuser, async);
if (async)
{
return CELL_OK;
}
return *trans_ctx->result;
}
error_code sceNpTusGetData(s32 transId, vm::cptr<SceNpId> targetNpId, SceNpTusSlotId slotId, vm::ptr<SceNpTusDataStatus> dataStatus, u32 dataStatusSize, vm::ptr<void> data, u32 recvSize, vm::ptr<void> option)
{
sceNpTus.warning("sceNpTusGetData(transId=%d, targetNpId=*0x%x, slotId=%d, dataStatus=*0x%x, dataStatusSize=%d, data=*0x%x, recvSize=%d, option=*0x%x)", transId, targetNpId, slotId, dataStatus, dataStatusSize, data, recvSize, option);
return scenp_tus_get_data(transId, targetNpId, slotId, dataStatus, dataStatusSize, data, recvSize, option, false, false);
}
error_code sceNpTusGetDataVUser(s32 transId, vm::cptr<SceNpTusVirtualUserId> targetVirtualUserId, SceNpTusSlotId slotId, vm::ptr<SceNpTusDataStatus> dataStatus, u32 dataStatusSize, vm::ptr<void> data, u32 recvSize, vm::ptr<void> option)
{
sceNpTus.warning("sceNpTusGetDataVUser(transId=%d, targetVirtualUserId=*0x%x, slotId=%d, dataStatus=*0x%x, dataStatusSize=%d, data=*0x%x, recvSize=%d, option=*0x%x)", transId, targetVirtualUserId, slotId, dataStatus, dataStatusSize, data, recvSize, option);
return scenp_tus_get_data(transId, targetVirtualUserId, slotId, dataStatus, dataStatusSize, data, recvSize, option, true, false);
}
error_code sceNpTusGetDataAsync(s32 transId, vm::cptr<SceNpId> targetNpId, SceNpTusSlotId slotId, vm::ptr<SceNpTusDataStatus> dataStatus, u32 dataStatusSize, vm::ptr<void> data, u32 recvSize, vm::ptr<void> option)
{
sceNpTus.warning("sceNpTusGetDataAsync(transId=%d, targetNpId=*0x%x, slotId=%d, dataStatus=*0x%x, dataStatusSize=%d, data=*0x%x, recvSize=%d, option=*0x%x)", transId, targetNpId, slotId, dataStatus, dataStatusSize, data, recvSize, option);
return scenp_tus_get_data(transId, targetNpId, slotId, dataStatus, dataStatusSize, data, recvSize, option, false, true);
}
error_code sceNpTusGetDataVUserAsync(s32 transId, vm::cptr<SceNpTusVirtualUserId> targetVirtualUserId, SceNpTusSlotId slotId, vm::ptr<SceNpTusDataStatus> dataStatus, u32 dataStatusSize, vm::ptr<void> data, u32 recvSize, vm::ptr<void> option)
{
sceNpTus.warning("sceNpTusGetDataVUserAsync(transId=%d, targetVirtualUserId=*0x%x, slotId=%d, dataStatus=*0x%x, dataStatusSize=%d, data=*0x%x, recvSize=%d, option=*0x%x)", transId, targetVirtualUserId, slotId, dataStatus, dataStatusSize, data, recvSize, option);
return scenp_tus_get_data(transId, targetVirtualUserId, slotId, dataStatus, dataStatusSize, data, recvSize, option, true, true);
}
template<typename T>
error_code scenp_tus_get_multislot_data_status(s32 transId, T targetNpId, vm::cptr<SceNpTusSlotId> slotIdArray, vm::ptr<SceNpTusDataStatus> statusArray, u32 statusArraySize, s32 arrayNum, vm::ptr<void> option, bool vuser, bool async)
{
if (!slotIdArray || !statusArray)
{
return SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT;
}
if (arrayNum == 0 || option)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
if (statusArraySize != arrayNum * sizeof(SceNpTusDataStatus))
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ALIGNMENT;
}
if (arrayNum > SCE_NP_TUS_MAX_SLOT_NUM_PER_TRANS)
{
return SCE_NP_COMMUNITY_ERROR_TOO_MANY_SLOTID;
}
if (!is_slot_array_valid(slotIdArray, arrayNum))
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_TUS_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (!targetNpId)
{
return SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT;
}
// Probable vsh behaviour
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ONLINE_ID;
}
auto trans_ctx = idm::get<tus_transaction_ctx>(transId);
if (!trans_ctx)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ID;
}
nph.tus_get_multislot_data_status(trans_ctx, get_scenp_online_id(*targetNpId.get_ptr()), slotIdArray, statusArray, arrayNum, vuser, async);
if (async)
{
return CELL_OK;
}
return *trans_ctx->result;
}
error_code sceNpTusGetMultiSlotDataStatus(s32 transId, vm::cptr<SceNpId> targetNpId, vm::cptr<SceNpTusSlotId> slotIdArray, vm::ptr<SceNpTusDataStatus> statusArray, u32 statusArraySize, s32 arrayNum, vm::ptr<void> option)
{
sceNpTus.warning("sceNpTusGetMultiSlotDataStatus(transId=%d, targetNpId=*0x%x, slotIdArray=*0x%x, statusArray=*0x%x, statusArraySize=%d, arrayNum=%d, option=*0x%x)", transId, targetNpId, slotIdArray, statusArray, statusArraySize, arrayNum, option);
return scenp_tus_get_multislot_data_status(transId, targetNpId, slotIdArray, statusArray, statusArraySize, arrayNum, option, false, false);
}
error_code sceNpTusGetMultiSlotDataStatusVUser(s32 transId, vm::cptr<SceNpTusVirtualUserId> targetVirtualUserId, vm::cptr<SceNpTusSlotId> slotIdArray, vm::ptr<SceNpTusDataStatus> statusArray, u32 statusArraySize, s32 arrayNum, vm::ptr<void> option)
{
sceNpTus.warning("sceNpTusGetMultiSlotDataStatusVUser(transId=%d, targetVirtualUserId=*0x%x, slotIdArray=*0x%x, statusArray=*0x%x, statusArraySize=%d, arrayNum=%d, option=*0x%x)", transId, targetVirtualUserId, slotIdArray, statusArray, statusArraySize, arrayNum, option);
return scenp_tus_get_multislot_data_status(transId, targetVirtualUserId, slotIdArray, statusArray, statusArraySize, arrayNum, option, true, false);
}
error_code sceNpTusGetMultiSlotDataStatusAsync(s32 transId, vm::cptr<SceNpId> targetNpId, vm::cptr<SceNpTusSlotId> slotIdArray, vm::ptr<SceNpTusDataStatus> statusArray, u32 statusArraySize, s32 arrayNum, vm::ptr<void> option)
{
sceNpTus.warning("sceNpTusGetMultiSlotDataStatusAsync(transId=%d, targetNpId=*0x%x, slotIdArray=*0x%x, statusArray=*0x%x, statusArraySize=%d, arrayNum=%d, option=*0x%x)", transId, targetNpId, slotIdArray, statusArray, statusArraySize, arrayNum, option);
return scenp_tus_get_multislot_data_status(transId, targetNpId, slotIdArray, statusArray, statusArraySize, arrayNum, option, false, true);
}
error_code sceNpTusGetMultiSlotDataStatusVUserAsync(s32 transId, vm::cptr<SceNpTusVirtualUserId> targetVirtualUserId, vm::cptr<SceNpTusSlotId> slotIdArray, vm::ptr<SceNpTusDataStatus> statusArray, u32 statusArraySize, s32 arrayNum, vm::ptr<void> option)
{
sceNpTus.warning("sceNpTusGetMultiSlotDataStatusVUserAsync(transId=%d, targetVirtualUserId=*0x%x, slotIdArray=*0x%x, statusArray=*0x%x, statusArraySize=%d, arrayNum=%d, option=*0x%x)", transId, targetVirtualUserId, slotIdArray, statusArray, statusArraySize, arrayNum, option);
return scenp_tus_get_multislot_data_status(transId, targetVirtualUserId, slotIdArray, statusArray, statusArraySize, arrayNum, option, true, true);
}
template<typename T>
error_code scenp_tus_get_multiuser_data_status(s32 transId, T targetNpIdArray, SceNpTusSlotId slotId, vm::ptr<SceNpTusDataStatus> statusArray, u32 statusArraySize, s32 arrayNum, vm::ptr<void> option, bool vuser, bool async)
{
if (!statusArray)
{
return SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT;
}
if (arrayNum == 0 || option)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
if (arrayNum > SCE_NP_SCORE_MAX_NPID_NUM_PER_TRANS)
{
return SCE_NP_COMMUNITY_ERROR_TOO_MANY_NPID;
}
if (statusArraySize != arrayNum * sizeof(SceNpTusDataStatus))
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ALIGNMENT;
}
if (slotId < 0)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_TUS_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (!targetNpIdArray)
{
return SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT;
}
// Probable vsh behaviour
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ONLINE_ID;
}
auto trans_ctx = idm::get<tus_transaction_ctx>(transId);
if (!trans_ctx)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ID;
}
std::vector<SceNpOnlineId> online_ids;
for (s32 i = 0; i < arrayNum; i++)
{
online_ids.push_back(get_scenp_online_id(targetNpIdArray[i]));
}
nph.tus_get_multiuser_data_status(trans_ctx, std::move(online_ids), slotId, statusArray, arrayNum, vuser, async);
if (async)
{
return CELL_OK;
}
return *trans_ctx->result;
}
error_code sceNpTusGetMultiUserDataStatus(s32 transId, vm::cptr<SceNpId> targetNpIdArray, SceNpTusSlotId slotId, vm::ptr<SceNpTusDataStatus> statusArray, u32 statusArraySize, s32 arrayNum, vm::ptr<void> option)
{
sceNpTus.warning("sceNpTusGetMultiUserDataStatus(transId=%d, targetNpIdArray=*0x%x, slotId=%d, statusArray=*0x%x, statusArraySize=%d, arrayNum=%d, option=*0x%x)", transId, targetNpIdArray, slotId, statusArray, statusArraySize, arrayNum, option);
return scenp_tus_get_multiuser_data_status(transId, targetNpIdArray, slotId, statusArray, statusArraySize, arrayNum, option, false, false);
}
error_code sceNpTusGetMultiUserDataStatusVUser(s32 transId, vm::cptr<SceNpTusVirtualUserId> targetVirtualUserIdArray, SceNpTusSlotId slotId, vm::ptr<SceNpTusDataStatus> statusArray, u32 statusArraySize, s32 arrayNum, vm::ptr<void> option)
{
sceNpTus.warning("sceNpTusGetMultiUserDataStatusVUser(transId=%d, targetVirtualUserIdArray=*0x%x, slotId=%d, statusArray=*0x%x, statusArraySize=%d, arrayNum=%d, option=*0x%x)", transId, targetVirtualUserIdArray, slotId, statusArray, statusArraySize, arrayNum, option);
return scenp_tus_get_multiuser_data_status(transId, targetVirtualUserIdArray, slotId, statusArray, statusArraySize, arrayNum, option, true, false);
}
error_code sceNpTusGetMultiUserDataStatusAsync(s32 transId, vm::cptr<SceNpId> targetNpIdArray, SceNpTusSlotId slotId, vm::ptr<SceNpTusDataStatus> statusArray, u32 statusArraySize, s32 arrayNum, vm::ptr<void> option)
{
sceNpTus.warning("sceNpTusGetMultiUserDataStatusAsync(transId=%d, targetNpIdArray=*0x%x, slotId=%d, statusArray=*0x%x, statusArraySize=%d, arrayNum=%d, option=*0x%x)", transId, targetNpIdArray, slotId, statusArray, statusArraySize, arrayNum, option);
return scenp_tus_get_multiuser_data_status(transId, targetNpIdArray, slotId, statusArray, statusArraySize, arrayNum, option, false, true);
}
error_code sceNpTusGetMultiUserDataStatusVUserAsync(s32 transId, vm::cptr<SceNpTusVirtualUserId> targetVirtualUserIdArray, SceNpTusSlotId slotId, vm::ptr<SceNpTusDataStatus> statusArray, u32 statusArraySize, s32 arrayNum, vm::ptr<void> option)
{
sceNpTus.warning("sceNpTusGetMultiUserDataStatusVUserAsync(transId=%d, targetVirtualUserIdArray=*0x%x, slotId=%d, statusArray=*0x%x, statusArraySize=%d, arrayNum=%d, option=*0x%x)", transId, targetVirtualUserIdArray, slotId, statusArray, statusArraySize, arrayNum, option);
return scenp_tus_get_multiuser_data_status(transId, targetVirtualUserIdArray, slotId, statusArray, statusArraySize, arrayNum, option, true, true);
}
error_code scenp_tus_get_friends_data_status(s32 transId, SceNpTusSlotId slotId, s32 includeSelf, s32 sortType, vm::ptr<SceNpTusDataStatus> statusArray, u32 statusArraySize, s32 arrayNum, vm::ptr<void> option, bool async)
{
if (!statusArray)
{
return SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT;
}
if (arrayNum == 0)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
// Undocumented behaviour and structure unknown
// Also checks a u32* at offset 4 of the struct for nullptr in which case it behaves like option == nullptr
if (option && *static_cast<u32*>(option.get_ptr()) != 0xC)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
if (sortType != SCE_NP_TUS_DATASTATUS_SORTTYPE_DESCENDING_DATE && sortType != SCE_NP_TUS_DATASTATUS_SORTTYPE_ASCENDING_DATE)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
if (arrayNum > SCE_NP_SCORE_MAX_SELECTED_FRIENDS_NUM)
{
return SCE_NP_COMMUNITY_ERROR_TOO_MANY_NPID;
}
if (statusArraySize != arrayNum * sizeof(SceNpTusDataStatus))
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ALIGNMENT;
}
if (slotId < 0)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_TUS_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
// Probable vsh behaviour
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ONLINE_ID;
}
auto trans_ctx = idm::get<tus_transaction_ctx>(transId);
if (!trans_ctx)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ID;
}
nph.tus_get_friends_data_status(trans_ctx, slotId, includeSelf, sortType, statusArray, arrayNum, async);
if (async)
{
return CELL_OK;
}
return *trans_ctx->result;
}
error_code sceNpTusGetFriendsDataStatus(s32 transId, SceNpTusSlotId slotId, s32 includeSelf, s32 sortType, vm::ptr<SceNpTusDataStatus> statusArray, u32 statusArraySize, s32 arrayNum, vm::ptr<void> option)
{
sceNpTus.warning("sceNpTusGetFriendsDataStatus(transId=%d, slotId=%d, includeSelf=%d, sortType=%d, statusArray=*0x%x, statusArraySize=%d, arrayNum=%d, option=*0x%x)", transId, slotId, includeSelf, sortType, statusArray, statusArraySize, arrayNum, option);
return scenp_tus_get_friends_data_status(transId, slotId, includeSelf, sortType, statusArray, statusArraySize, arrayNum, option, false);
}
error_code sceNpTusGetFriendsDataStatusAsync(s32 transId, SceNpTusSlotId slotId, s32 includeSelf, s32 sortType, vm::ptr<SceNpTusDataStatus> statusArray, u32 statusArraySize, s32 arrayNum, vm::ptr<void> option)
{
sceNpTus.warning("sceNpTusGetFriendsDataStatusAsync(transId=%d, slotId=%d, includeSelf=%d, sortType=%d, statusArray=*0x%x, statusArraySize=%d, arrayNum=%d, option=*0x%x)", transId, slotId, includeSelf, sortType, statusArray, statusArraySize, arrayNum, option);
return scenp_tus_get_friends_data_status(transId, slotId, includeSelf, sortType, statusArray, statusArraySize, arrayNum, option, true);
}
template<typename T>
error_code scenp_tus_delete_multislot_data(s32 transId, T targetNpId, vm::cptr<SceNpTusSlotId> slotIdArray, s32 arrayNum, vm::ptr<void> option, bool vuser, bool async)
{
if (!slotIdArray)
{
return SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT;
}
if (arrayNum == 0 || option)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
if (arrayNum > SCE_NP_TUS_MAX_SLOT_NUM_PER_TRANS)
{
return SCE_NP_COMMUNITY_ERROR_TOO_MANY_SLOTID;
}
if (!is_slot_array_valid(slotIdArray, arrayNum))
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT;
}
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_TUS_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
// Probable vsh behaviour
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ONLINE_ID;
}
auto trans_ctx = idm::get<tus_transaction_ctx>(transId);
if (!trans_ctx)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ID;
}
nph.tus_delete_multislot_data(trans_ctx, get_scenp_online_id(*targetNpId.get_ptr()), slotIdArray, arrayNum, vuser, async);
if (async)
{
return CELL_OK;
}
return *trans_ctx->result;
}
error_code sceNpTusDeleteMultiSlotData(s32 transId, vm::cptr<SceNpId> targetNpId, vm::cptr<SceNpTusSlotId> slotIdArray, s32 arrayNum, vm::ptr<void> option)
{
sceNpTus.warning("sceNpTusDeleteMultiSlotData(transId=%d, targetNpId=*0x%x, slotIdArray=*0x%x, arrayNum=%d, option=*0x%x)", transId, targetNpId, slotIdArray, arrayNum, option);
return scenp_tus_delete_multislot_data(transId, targetNpId, slotIdArray, arrayNum, option, false, false);
}
error_code sceNpTusDeleteMultiSlotDataVUser(s32 transId, vm::cptr<SceNpTusVirtualUserId> targetVirtualUserId, vm::cptr<SceNpTusSlotId> slotIdArray, s32 arrayNum, vm::ptr<void> option)
{
sceNpTus.warning("sceNpTusDeleteMultiSlotDataVUser(transId=%d, targetVirtualUserId=*0x%x, slotIdArray=*0x%x, arrayNum=%d, option=*0x%x)", transId, targetVirtualUserId, slotIdArray, arrayNum, option);
return scenp_tus_delete_multislot_data(transId, targetVirtualUserId, slotIdArray, arrayNum, option, true, false);
}
error_code sceNpTusDeleteMultiSlotDataAsync(s32 transId, vm::cptr<SceNpId> targetNpId, vm::cptr<SceNpTusSlotId> slotIdArray, s32 arrayNum, vm::ptr<void> option)
{
sceNpTus.warning("sceNpTusDeleteMultiSlotDataAsync(transId=%d, targetNpId=*0x%x, slotIdArray=*0x%x, arrayNum=%d, option=*0x%x)", transId, targetNpId, slotIdArray, arrayNum, option);
return scenp_tus_delete_multislot_data(transId, targetNpId, slotIdArray, arrayNum, option, false, true);
}
error_code sceNpTusDeleteMultiSlotDataVUserAsync(s32 transId, vm::cptr<SceNpTusVirtualUserId> targetVirtualUserId, vm::cptr<SceNpTusSlotId> slotIdArray, s32 arrayNum, vm::ptr<void> option)
{
sceNpTus.warning("sceNpTusDeleteMultiSlotDataVUserAsync(transId=%d, targetVirtualUserId=*0x%x, slotIdArray=*0x%x, arrayNum=%d, option=*0x%x)", transId, targetVirtualUserId, slotIdArray, arrayNum, option);
return scenp_tus_delete_multislot_data(transId, targetVirtualUserId, slotIdArray, arrayNum, option, true, true);
}
void scenp_tss_no_file(const std::shared_ptr<tus_transaction_ctx>& trans, vm::ptr<SceNpTssDataStatus> dataStatus)
{
// TSS are files stored on PSN by developers, no dumps available atm
std::memset(dataStatus.get_ptr(), 0, sizeof(SceNpTssDataStatus));
trans->result = not_an_error(0);
}
error_code sceNpTssGetData(s32 transId, SceNpTssSlotId slotId, vm::ptr<SceNpTssDataStatus> dataStatus, u32 dataStatusSize, vm::ptr<void> data, u32 recvSize, vm::ptr<SceNpTssGetDataOptParam> option)
{
sceNpTus.warning("sceNpTssGetData(transId=%d, slotId=%d, dataStatus=*0x%x, dataStatusSize=%d, data=*0x%x, recvSize=%d, option=*0x%x)", transId, slotId, dataStatus, dataStatusSize, data, recvSize, option);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_TUS_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ONLINE_ID;
}
if (!dataStatus)
{
return SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT;
}
auto trans_ctx = idm::get<tus_transaction_ctx>(transId);
if (!trans_ctx)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ID;
}
scenp_tss_no_file(trans_ctx, dataStatus);
return CELL_OK;
}
error_code sceNpTssGetDataAsync(s32 transId, SceNpTssSlotId slotId, vm::ptr<SceNpTssDataStatus> dataStatus, u32 dataStatusSize, vm::ptr<void> data, u32 recvSize, vm::ptr<SceNpTssGetDataOptParam> option)
{
sceNpTus.warning("sceNpTssGetDataAsync(transId=%d, slotId=%d, dataStatus=*0x%x, dataStatusSize=%d, data=*0x%x, recvSize=%d, option=*0x%x)", transId, slotId, dataStatus, dataStatusSize, data, recvSize, option);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_TUS_init)
{
return SCE_NP_COMMUNITY_ERROR_NOT_INITIALIZED;
}
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ONLINE_ID;
}
if (!dataStatus)
{
return SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT;
}
auto trans_ctx = idm::get<tus_transaction_ctx>(transId);
if (!trans_ctx)
{
return SCE_NP_COMMUNITY_ERROR_INVALID_ID;
}
scenp_tss_no_file(trans_ctx, dataStatus);
return CELL_OK;
}
error_code sceNpTssGetDataNoLimit()
{
UNIMPLEMENTED_FUNC(sceNpTus);
return CELL_OK;
}
error_code sceNpTssGetDataNoLimitAsync()
{
UNIMPLEMENTED_FUNC(sceNpTus);
return CELL_OK;
}
DECLARE(ppu_module_manager::sceNpTus)("sceNpTus", []()
{
REG_FUNC(sceNpTus, sceNpTusInit);
REG_FUNC(sceNpTus, sceNpTusTerm);
REG_FUNC(sceNpTus, sceNpTusCreateTitleCtx);
REG_FUNC(sceNpTus, sceNpTusDestroyTitleCtx);
REG_FUNC(sceNpTus, sceNpTusCreateTransactionCtx);
REG_FUNC(sceNpTus, sceNpTusDestroyTransactionCtx);
REG_FUNC(sceNpTus, sceNpTusSetTimeout);
REG_FUNC(sceNpTus, sceNpTusAbortTransaction);
REG_FUNC(sceNpTus, sceNpTusWaitAsync);
REG_FUNC(sceNpTus, sceNpTusPollAsync);
REG_FUNC(sceNpTus, sceNpTusSetMultiSlotVariable);
REG_FUNC(sceNpTus, sceNpTusSetMultiSlotVariableVUser);
REG_FUNC(sceNpTus, sceNpTusSetMultiSlotVariableAsync);
REG_FUNC(sceNpTus, sceNpTusSetMultiSlotVariableVUserAsync);
REG_FUNC(sceNpTus, sceNpTusGetMultiSlotVariable);
REG_FUNC(sceNpTus, sceNpTusGetMultiSlotVariableVUser);
REG_FUNC(sceNpTus, sceNpTusGetMultiSlotVariableAsync);
REG_FUNC(sceNpTus, sceNpTusGetMultiSlotVariableVUserAsync);
REG_FUNC(sceNpTus, sceNpTusGetMultiUserVariable);
REG_FUNC(sceNpTus, sceNpTusGetMultiUserVariableVUser);
REG_FUNC(sceNpTus, sceNpTusGetMultiUserVariableAsync);
REG_FUNC(sceNpTus, sceNpTusGetMultiUserVariableVUserAsync);
REG_FUNC(sceNpTus, sceNpTusGetFriendsVariable);
REG_FUNC(sceNpTus, sceNpTusGetFriendsVariableAsync);
REG_FUNC(sceNpTus, sceNpTusAddAndGetVariable);
REG_FUNC(sceNpTus, sceNpTusAddAndGetVariableVUser);
REG_FUNC(sceNpTus, sceNpTusAddAndGetVariableAsync);
REG_FUNC(sceNpTus, sceNpTusAddAndGetVariableVUserAsync);
REG_FUNC(sceNpTus, sceNpTusTryAndSetVariable);
REG_FUNC(sceNpTus, sceNpTusTryAndSetVariableVUser);
REG_FUNC(sceNpTus, sceNpTusTryAndSetVariableAsync);
REG_FUNC(sceNpTus, sceNpTusTryAndSetVariableVUserAsync);
REG_FUNC(sceNpTus, sceNpTusDeleteMultiSlotVariable);
REG_FUNC(sceNpTus, sceNpTusDeleteMultiSlotVariableVUser);
REG_FUNC(sceNpTus, sceNpTusDeleteMultiSlotVariableAsync);
REG_FUNC(sceNpTus, sceNpTusDeleteMultiSlotVariableVUserAsync);
REG_FUNC(sceNpTus, sceNpTusSetData);
REG_FUNC(sceNpTus, sceNpTusSetDataVUser);
REG_FUNC(sceNpTus, sceNpTusSetDataAsync);
REG_FUNC(sceNpTus, sceNpTusSetDataVUserAsync);
REG_FUNC(sceNpTus, sceNpTusGetData);
REG_FUNC(sceNpTus, sceNpTusGetDataVUser);
REG_FUNC(sceNpTus, sceNpTusGetDataAsync);
REG_FUNC(sceNpTus, sceNpTusGetDataVUserAsync);
REG_FUNC(sceNpTus, sceNpTusGetMultiSlotDataStatus);
REG_FUNC(sceNpTus, sceNpTusGetMultiSlotDataStatusVUser);
REG_FUNC(sceNpTus, sceNpTusGetMultiSlotDataStatusAsync);
REG_FUNC(sceNpTus, sceNpTusGetMultiSlotDataStatusVUserAsync);
REG_FUNC(sceNpTus, sceNpTusGetMultiUserDataStatus);
REG_FUNC(sceNpTus, sceNpTusGetMultiUserDataStatusVUser);
REG_FUNC(sceNpTus, sceNpTusGetMultiUserDataStatusAsync);
REG_FUNC(sceNpTus, sceNpTusGetMultiUserDataStatusVUserAsync);
REG_FUNC(sceNpTus, sceNpTusGetFriendsDataStatus);
REG_FUNC(sceNpTus, sceNpTusGetFriendsDataStatusAsync);
REG_FUNC(sceNpTus, sceNpTusDeleteMultiSlotData);
REG_FUNC(sceNpTus, sceNpTusDeleteMultiSlotDataVUser);
REG_FUNC(sceNpTus, sceNpTusDeleteMultiSlotDataAsync);
REG_FUNC(sceNpTus, sceNpTusDeleteMultiSlotDataVUserAsync);
REG_FUNC(sceNpTus, sceNpTssGetData);
REG_FUNC(sceNpTus, sceNpTssGetDataAsync);
REG_FUNC(sceNpTus, sceNpTssGetDataNoLimit);
REG_FUNC(sceNpTus, sceNpTssGetDataNoLimitAsync);
});
| 58,774
|
C++
|
.cpp
| 1,177
| 47.744265
| 292
| 0.781562
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
5,248
|
cellVpost.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellVpost.cpp
|
#include "stdafx.h"
#include "Emu/IdManager.h"
#include "Emu/Cell/PPUModule.h"
#ifdef _MSC_VER
#pragma warning(push, 0)
#else
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wall"
#pragma GCC diagnostic ignored "-Wextra"
#pragma GCC diagnostic ignored "-Wold-style-cast"
#endif
extern "C"
{
#include "libswscale/swscale.h"
}
#ifdef _MSC_VER
#pragma warning(pop)
#else
#pragma GCC diagnostic pop
#endif
#include "cellVpost.h"
LOG_CHANNEL(cellVpost);
template<>
void fmt_class_string<CellVpostError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_VPOST_ERROR_Q_ARG_CFG_NULL);
STR_CASE(CELL_VPOST_ERROR_Q_ARG_CFG_INVALID);
STR_CASE(CELL_VPOST_ERROR_Q_ARG_ATTR_NULL);
STR_CASE(CELL_VPOST_ERROR_O_ARG_CFG_NULL);
STR_CASE(CELL_VPOST_ERROR_O_ARG_CFG_INVALID);
STR_CASE(CELL_VPOST_ERROR_O_ARG_RSRC_NULL);
STR_CASE(CELL_VPOST_ERROR_O_ARG_RSRC_INVALID);
STR_CASE(CELL_VPOST_ERROR_O_ARG_HDL_NULL);
STR_CASE(CELL_VPOST_ERROR_O_FATAL_QUERY_FAIL);
STR_CASE(CELL_VPOST_ERROR_O_FATAL_CREATEMON_FAIL);
STR_CASE(CELL_VPOST_ERROR_O_FATAL_INITSPURS_FAIL);
STR_CASE(CELL_VPOST_ERROR_C_ARG_HDL_NULL);
STR_CASE(CELL_VPOST_ERROR_C_ARG_HDL_INVALID);
STR_CASE(CELL_VPOST_ERROR_C_FATAL_LOCKMON_FAIL);
STR_CASE(CELL_VPOST_ERROR_C_FATAL_UNLOCKMON_FAIL);
STR_CASE(CELL_VPOST_ERROR_C_FATAL_DESTROYMON_FAIL);
STR_CASE(CELL_VPOST_ERROR_C_FATAL_FINSPURS_FAIL);
STR_CASE(CELL_VPOST_ERROR_E_ARG_HDL_NULL);
STR_CASE(CELL_VPOST_ERROR_E_ARG_HDL_INVALID);
STR_CASE(CELL_VPOST_ERROR_E_ARG_INPICBUF_NULL);
STR_CASE(CELL_VPOST_ERROR_E_ARG_INPICBUF_INVALID);
STR_CASE(CELL_VPOST_ERROR_E_ARG_CTRL_NULL);
STR_CASE(CELL_VPOST_ERROR_E_ARG_CTRL_INVALID);
STR_CASE(CELL_VPOST_ERROR_E_ARG_OUTPICBUF_NULL);
STR_CASE(CELL_VPOST_ERROR_E_ARG_OUTPICBUF_INVALID);
STR_CASE(CELL_VPOST_ERROR_E_ARG_PICINFO_NULL);
STR_CASE(CELL_VPOST_ERROR_E_FATAL_LOCKMON_FAIL);
STR_CASE(CELL_VPOST_ERROR_E_FATAL_UNLOCKMON_FAIL);
STR_CASE(CELL_VPOST_ENT_ERROR_Q_ARG_ATTR_NULL);
STR_CASE(CELL_VPOST_ENT_ERROR_O_ARG_RSRC_NULL);
STR_CASE(CELL_VPOST_ENT_ERROR_O_ARG_RSRC_INVALID);
STR_CASE(CELL_VPOST_ENT_ERROR_O_ARG_HDL_NULL);
STR_CASE(CELL_VPOST_ENT_ERROR_O_FATAL_QUERY_FAIL);
STR_CASE(CELL_VPOST_ENT_ERROR_O_FATAL_CSPUCORE_FAIL);
STR_CASE(CELL_VPOST_ENT_ERROR_C_ARG_HDL_NULL);
STR_CASE(CELL_VPOST_ENT_ERROR_C_ARG_HDL_INVALID);
STR_CASE(CELL_VPOST_ENT_ERROR_C_FATAL_SNDCMD_FAIL);
STR_CASE(CELL_VPOST_ENT_ERROR_C_FATAL_RCVRES_FAIL);
STR_CASE(CELL_VPOST_ENT_ERROR_C_FATAL_DSPUCORE_FAIL);
STR_CASE(CELL_VPOST_ENT_ERROR_E_ARG_HDL_NULL);
STR_CASE(CELL_VPOST_ENT_ERROR_E_ARG_HDL_INVALID);
STR_CASE(CELL_VPOST_ENT_ERROR_E_ARG_INPICBUF_NULL);
STR_CASE(CELL_VPOST_ENT_ERROR_E_ARG_INPICBUF_INVALID);
STR_CASE(CELL_VPOST_ENT_ERROR_E_ARG_INPICINFO_NULL);
STR_CASE(CELL_VPOST_ENT_ERROR_E_ARG_INPICINFO_INVALID);
STR_CASE(CELL_VPOST_ENT_ERROR_E_ARG_CTRL_NULL);
STR_CASE(CELL_VPOST_ENT_ERROR_E_ARG_CTRL_INVALID);
STR_CASE(CELL_VPOST_ENT_ERROR_E_ARG_COMB_INVALID);
STR_CASE(CELL_VPOST_ENT_ERROR_E_ARG_OUTPICBUF_NULL);
STR_CASE(CELL_VPOST_ENT_ERROR_E_ARG_OUTPICBUF_INVALID);
STR_CASE(CELL_VPOST_ENT_ERROR_E_ARG_OUTPICINFO_NULL);
STR_CASE(CELL_VPOST_ENT_ERROR_E_FATAL_SNDCMD_FAIL);
STR_CASE(CELL_VPOST_ENT_ERROR_E_FATAL_RCVRES_FAIL);
STR_CASE(CELL_VPOST_ENT_ERROR_E_FATAL_SPUCORE_FAIL);
STR_CASE(CELL_VPOST_IPC_ERROR_Q_ARG_ATTR_NULL);
STR_CASE(CELL_VPOST_IPC_ERROR_O_ARG_RSRC_NULL);
STR_CASE(CELL_VPOST_IPC_ERROR_O_ARG_RSRC_INVALID);
STR_CASE(CELL_VPOST_IPC_ERROR_O_ARG_HDL_NULL);
STR_CASE(CELL_VPOST_IPC_ERROR_O_FATAL_QUERY_FAIL);
STR_CASE(CELL_VPOST_IPC_ERROR_O_FATAL_CSPUCORE_FAIL);
STR_CASE(CELL_VPOST_IPC_ERROR_C_ARG_HDL_NULL);
STR_CASE(CELL_VPOST_IPC_ERROR_C_ARG_HDL_INVALID);
STR_CASE(CELL_VPOST_IPC_ERROR_C_FATAL_SNDCMD_FAIL);
STR_CASE(CELL_VPOST_IPC_ERROR_C_FATAL_RCVRES_FAIL);
STR_CASE(CELL_VPOST_IPC_ERROR_C_FATAL_DSPUCORE_FAIL);
STR_CASE(CELL_VPOST_IPC_ERROR_E_ARG_HDL_NULL);
STR_CASE(CELL_VPOST_IPC_ERROR_E_ARG_HDL_INVALID);
STR_CASE(CELL_VPOST_IPC_ERROR_E_ARG_INPICBUF_NULL);
STR_CASE(CELL_VPOST_IPC_ERROR_E_ARG_INPICBUF_INVALID);
STR_CASE(CELL_VPOST_IPC_ERROR_E_ARG_INPICINFO_NULL);
STR_CASE(CELL_VPOST_IPC_ERROR_E_ARG_INPICINFO_INVALID);
STR_CASE(CELL_VPOST_IPC_ERROR_E_ARG_CTRL_NULL);
STR_CASE(CELL_VPOST_IPC_ERROR_E_ARG_CTRL_INVALID);
STR_CASE(CELL_VPOST_IPC_ERROR_E_ARG_COMB_INVALID);
STR_CASE(CELL_VPOST_IPC_ERROR_E_ARG_OUTPICBUF_NULL);
STR_CASE(CELL_VPOST_IPC_ERROR_E_ARG_OUTPICBUF_INVALID);
STR_CASE(CELL_VPOST_IPC_ERROR_E_ARG_OUTPICINFO_NULL);
STR_CASE(CELL_VPOST_IPC_ERROR_E_FATAL_SNDCMD_FAIL);
STR_CASE(CELL_VPOST_IPC_ERROR_E_FATAL_RCVRES_FAIL);
STR_CASE(CELL_VPOST_IPC_ERROR_E_FATAL_SPUCORE_FAIL);
STR_CASE(CELL_VPOST_VSC_ERROR_Q_ARG_ATTR_NULL);
STR_CASE(CELL_VPOST_VSC_ERROR_O_ARG_RSRC_NULL);
STR_CASE(CELL_VPOST_VSC_ERROR_O_ARG_RSRC_INVALID);
STR_CASE(CELL_VPOST_VSC_ERROR_O_ARG_HDL_NULL);
STR_CASE(CELL_VPOST_VSC_ERROR_O_FATAL_QUERY_FAIL);
STR_CASE(CELL_VPOST_VSC_ERROR_O_FATAL_CSPUCORE_FAIL);
STR_CASE(CELL_VPOST_VSC_ERROR_C_ARG_HDL_NULL);
STR_CASE(CELL_VPOST_VSC_ERROR_C_ARG_HDL_INVALID);
STR_CASE(CELL_VPOST_VSC_ERROR_C_FATAL_SNDCMD_FAIL);
STR_CASE(CELL_VPOST_VSC_ERROR_C_FATAL_RCVRES_FAIL);
STR_CASE(CELL_VPOST_VSC_ERROR_C_FATAL_DSPUCORE_FAIL);
STR_CASE(CELL_VPOST_VSC_ERROR_E_ARG_HDL_NULL);
STR_CASE(CELL_VPOST_VSC_ERROR_E_ARG_HDL_INVALID);
STR_CASE(CELL_VPOST_VSC_ERROR_E_ARG_INPICBUF_NULL);
STR_CASE(CELL_VPOST_VSC_ERROR_E_ARG_INPICBUF_INVALID);
STR_CASE(CELL_VPOST_VSC_ERROR_E_ARG_INPICINFO_NULL);
STR_CASE(CELL_VPOST_VSC_ERROR_E_ARG_INPICINFO_INVALID);
STR_CASE(CELL_VPOST_VSC_ERROR_E_ARG_CTRL_NULL);
STR_CASE(CELL_VPOST_VSC_ERROR_E_ARG_CTRL_INVALID);
STR_CASE(CELL_VPOST_VSC_ERROR_E_ARG_COMB_INVALID);
STR_CASE(CELL_VPOST_VSC_ERROR_E_ARG_OUTPICBUF_NULL);
STR_CASE(CELL_VPOST_VSC_ERROR_E_ARG_OUTPICBUF_INVALID);
STR_CASE(CELL_VPOST_VSC_ERROR_E_ARG_OUTPICINFO_NULL);
STR_CASE(CELL_VPOST_VSC_ERROR_E_FATAL_SNDCMD_FAIL);
STR_CASE(CELL_VPOST_VSC_ERROR_E_FATAL_RCVRES_FAIL);
STR_CASE(CELL_VPOST_VSC_ERROR_E_FATAL_SPUCORE_FAIL);
STR_CASE(CELL_VPOST_CSC_ERROR_Q_ARG_ATTR_NULL);
STR_CASE(CELL_VPOST_CSC_ERROR_O_ARG_RSRC_NULL);
STR_CASE(CELL_VPOST_CSC_ERROR_O_ARG_RSRC_INVALID);
STR_CASE(CELL_VPOST_CSC_ERROR_O_ARG_HDL_NULL);
STR_CASE(CELL_VPOST_CSC_ERROR_O_FATAL_QUERY_FAIL);
STR_CASE(CELL_VPOST_CSC_ERROR_O_FATAL_CSPUCORE_FAIL);
STR_CASE(CELL_VPOST_CSC_ERROR_C_ARG_HDL_NULL);
STR_CASE(CELL_VPOST_CSC_ERROR_C_ARG_HDL_INVALID);
STR_CASE(CELL_VPOST_CSC_ERROR_C_FATAL_SNDCMD_FAIL);
STR_CASE(CELL_VPOST_CSC_ERROR_C_FATAL_RCVRES_FAIL);
STR_CASE(CELL_VPOST_CSC_ERROR_C_FATAL_DSPUCORE_FAIL);
STR_CASE(CELL_VPOST_CSC_ERROR_E_ARG_HDL_NULL);
STR_CASE(CELL_VPOST_CSC_ERROR_E_ARG_HDL_INVALID);
STR_CASE(CELL_VPOST_CSC_ERROR_E_ARG_INPICBUF_NULL);
STR_CASE(CELL_VPOST_CSC_ERROR_E_ARG_INPICBUF_INVALID);
STR_CASE(CELL_VPOST_CSC_ERROR_E_ARG_INPICINFO_NULL);
STR_CASE(CELL_VPOST_CSC_ERROR_E_ARG_INPICINFO_INVALID);
STR_CASE(CELL_VPOST_CSC_ERROR_E_ARG_CTRL_NULL);
STR_CASE(CELL_VPOST_CSC_ERROR_E_ARG_CTRL_INVALID);
STR_CASE(CELL_VPOST_CSC_ERROR_E_ARG_COMB_INVALID);
STR_CASE(CELL_VPOST_CSC_ERROR_E_ARG_OUTPICBUF_NULL);
STR_CASE(CELL_VPOST_CSC_ERROR_E_ARG_OUTPICBUF_INVALID);
STR_CASE(CELL_VPOST_CSC_ERROR_E_ARG_OUTPICINFO_NULL);
STR_CASE(CELL_VPOST_CSC_ERROR_E_FATAL_SNDCMD_FAIL);
STR_CASE(CELL_VPOST_CSC_ERROR_E_FATAL_RCVRES_FAIL);
STR_CASE(CELL_VPOST_CSC_ERROR_E_FATAL_SPUCORE_FAIL);
}
return unknown;
});
}
error_code cellVpostQueryAttr(vm::cptr<CellVpostCfgParam> cfgParam, vm::ptr<CellVpostAttr> attr)
{
cellVpost.warning("cellVpostQueryAttr(cfgParam=*0x%x, attr=*0x%x)", cfgParam, attr);
// TODO: check cfgParam and output values
attr->delay = 0;
attr->memSize = 4 * 1024 * 1024; // 4 MB
attr->vpostVerLower = 0x280000; // from dmux
attr->vpostVerUpper = 0x260000;
return CELL_OK;
}
error_code cellVpostOpen(vm::cptr<CellVpostCfgParam> cfgParam, vm::cptr<CellVpostResource> resource, vm::ptr<u32> handle)
{
cellVpost.warning("cellVpostOpen(cfgParam=*0x%x, resource=*0x%x, handle=*0x%x)", cfgParam, resource, handle);
// TODO: check values
*handle = idm::make<VpostInstance>(cfgParam->outPicFmt == CELL_VPOST_PIC_FMT_OUT_RGBA_ILV);
return CELL_OK;
}
error_code cellVpostOpenEx(vm::cptr<CellVpostCfgParam> cfgParam, vm::cptr<CellVpostResourceEx> resource, vm::ptr<u32> handle)
{
cellVpost.warning("cellVpostOpenEx(cfgParam=*0x%x, resource=*0x%x, handle=*0x%x)", cfgParam, resource, handle);
// TODO: check values
*handle = idm::make<VpostInstance>(cfgParam->outPicFmt == CELL_VPOST_PIC_FMT_OUT_RGBA_ILV);
return CELL_OK;
}
error_code cellVpostClose(u32 handle)
{
cellVpost.warning("cellVpostClose(handle=0x%x)", handle);
const auto vpost = idm::get<VpostInstance>(handle);
if (!vpost)
{
return CELL_VPOST_ERROR_C_ARG_HDL_INVALID;
}
idm::remove<VpostInstance>(handle);
return CELL_OK;
}
error_code cellVpostExec(u32 handle, vm::cptr<u8> inPicBuff, vm::cptr<CellVpostCtrlParam> ctrlParam, vm::ptr<u8> outPicBuff, vm::ptr<CellVpostPictureInfo> picInfo)
{
cellVpost.trace("cellVpostExec(handle=0x%x, inPicBuff=*0x%x, ctrlParam=*0x%x, outPicBuff=*0x%x, picInfo=*0x%x)", handle, inPicBuff, ctrlParam, outPicBuff, picInfo);
const auto vpost = idm::get<VpostInstance>(handle);
if (!vpost)
{
return CELL_VPOST_ERROR_E_ARG_HDL_INVALID;
}
u32 w = ctrlParam->inWidth;
u32 h = ctrlParam->inHeight;
u32 ow = ctrlParam->outWidth;
u32 oh = ctrlParam->outHeight;
//ctrlParam->inWindow; // ignored
if (ctrlParam->inWindow.x) cellVpost.notice("*** inWindow.x = %d", ctrlParam->inWindow.x);
if (ctrlParam->inWindow.y) cellVpost.notice("*** inWindow.y = %d", ctrlParam->inWindow.y);
if (ctrlParam->inWindow.width != w) cellVpost.notice("*** inWindow.width = %d", ctrlParam->inWindow.width);
if (ctrlParam->inWindow.height != h) cellVpost.notice("*** inWindow.height = %d", ctrlParam->inWindow.height);
//ctrlParam->outWindow; // ignored
if (ctrlParam->outWindow.x) cellVpost.notice("*** outWindow.x = %d", ctrlParam->outWindow.x);
if (ctrlParam->outWindow.y) cellVpost.notice("*** outWindow.y = %d", ctrlParam->outWindow.y);
if (ctrlParam->outWindow.width != ow) cellVpost.notice("*** outWindow.width = %d", ctrlParam->outWindow.width);
if (ctrlParam->outWindow.height != oh) cellVpost.notice("*** outWindow.height = %d", ctrlParam->outWindow.height);
//ctrlParam->execType; // ignored
//ctrlParam->scalerType; // ignored
//ctrlParam->ipcType; // ignored
picInfo->inWidth = w; // copy
picInfo->inHeight = h; // copy
picInfo->inDepth = CELL_VPOST_PIC_DEPTH_8; // fixed
picInfo->inScanType = CELL_VPOST_SCAN_TYPE_P; // TODO
picInfo->inPicFmt = CELL_VPOST_PIC_FMT_IN_YUV420_PLANAR; // fixed
picInfo->inChromaPosType = ctrlParam->inChromaPosType; // copy
picInfo->inPicStruct = CELL_VPOST_PIC_STRUCT_PFRM; // TODO
picInfo->inQuantRange = ctrlParam->inQuantRange; // copy
picInfo->inColorMatrix = ctrlParam->inColorMatrix; // copy
picInfo->outWidth = ow; // copy
picInfo->outHeight = oh; // copy
picInfo->outDepth = CELL_VPOST_PIC_DEPTH_8; // fixed
picInfo->outScanType = CELL_VPOST_SCAN_TYPE_P; // TODO
picInfo->outPicFmt = CELL_VPOST_PIC_FMT_OUT_RGBA_ILV; // TODO
picInfo->outChromaPosType = ctrlParam->inChromaPosType; // ignored
picInfo->outPicStruct = picInfo->inPicStruct; // ignored
picInfo->outQuantRange = ctrlParam->inQuantRange; // ignored
picInfo->outColorMatrix = ctrlParam->inColorMatrix; // ignored
picInfo->userData = ctrlParam->userData; // copy
picInfo->reserved1 = 0;
picInfo->reserved2 = 0;
//u64 stamp0 = get_guest_system_time();
std::unique_ptr<u8[]> pA(new u8[w*h]);
memset(pA.get(), ctrlParam->outAlpha, w*h);
//u64 stamp1 = get_guest_system_time();
vpost->sws = sws_getCachedContext(vpost->sws, w, h, AV_PIX_FMT_YUVA420P, ow, oh, AV_PIX_FMT_RGBA, SWS_BILINEAR, nullptr, nullptr, nullptr);
//u64 stamp2 = get_guest_system_time();
const u8* in_data[4] = { &inPicBuff[0], &inPicBuff[w * h], &inPicBuff[w * h * 5 / 4], pA.get() };
int ws = w;
int in_line[4] = { ws, ws/2, ws/2, ws };
u8* out_data[4] = { outPicBuff.get_ptr(), nullptr, nullptr, nullptr };
int out_line[4] = { static_cast<int>(ow * 4), 0, 0, 0 };
sws_scale(vpost->sws, in_data, in_line, 0, h, out_data, out_line);
//ConLog.Write("cellVpostExec() perf (access=%d, getContext=%d, scale=%d, finalize=%d)",
//stamp1 - stamp0, stamp2 - stamp1, stamp3 - stamp2, get_guest_system_time() - stamp3);
return CELL_OK;
}
DECLARE(ppu_module_manager::cellVpost)("cellVpost", []()
{
REG_FUNC(cellVpost, cellVpostQueryAttr);
REG_FUNC(cellVpost, cellVpostOpen);
REG_FUNC(cellVpost, cellVpostOpenEx);
//REG_FUNC(cellVpost, cellVpostOpenExt); // 0x9f1795df
REG_FUNC(cellVpost, cellVpostClose);
REG_FUNC(cellVpost, cellVpostExec);
});
| 13,000
|
C++
|
.cpp
| 271
| 45.00738
| 165
| 0.733202
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| true
| false
| false
| true
| false
| false
|
5,249
|
cellDaisy.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellDaisy.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
#include "cellDaisy.h"
LOG_CHANNEL(cellDaisy);
template <>
void fmt_class_string<CellDaisyError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](CellDaisyError value)
{
switch (value)
{
STR_CASE(CELL_DAISY_ERROR_NO_BEGIN);
STR_CASE(CELL_DAISY_ERROR_INVALID_PORT_ATTACH);
STR_CASE(CELL_DAISY_ERROR_NOT_IMPLEMENTED);
STR_CASE(CELL_DAISY_ERROR_AGAIN);
STR_CASE(CELL_DAISY_ERROR_INVAL);
STR_CASE(CELL_DAISY_ERROR_PERM);
STR_CASE(CELL_DAISY_ERROR_BUSY);
STR_CASE(CELL_DAISY_ERROR_STAT);
}
return unknown;
});
}
// Temporarily
#ifndef _MSC_VER
#pragma GCC diagnostic ignored "-Wunused-parameter"
#endif
using LFQueue2 = struct CellDaisyLFQueue2;
using Lock = struct CellDaisyLock;
using ScatterGatherInterlock = struct CellDaisyScatterGatherInterlock;
using AtomicInterlock = volatile struct CellDaisyAtomicInterlock;
error_code cellDaisyLFQueue2GetPopPointer(vm::ptr<LFQueue2> queue, vm::ptr<s32> pPointer, u32 isBlocking)
{
cellDaisy.todo("cellDaisyLFQueue2GetPopPointer()");
return CELL_OK;
}
error_code cellDaisyLFQueue2CompletePopPointer(vm::ptr<LFQueue2> queue, s32 pointer, vm::ptr<s32(vm::ptr<void>, u32)> fpSendSignal, u32 isQueueFull)
{
cellDaisy.todo("cellDaisyLFQueue2CompletePopPointer()");
return CELL_OK;
}
void cellDaisyLFQueue2PushOpen(vm::ptr<LFQueue2> queue)
{
cellDaisy.todo("cellDaisyLFQueue2PushOpen()");
}
error_code cellDaisyLFQueue2PushClose(vm::ptr<LFQueue2> queue, vm::ptr<s32(vm::ptr<void>, u32)> fpSendSignal)
{
cellDaisy.todo("cellDaisyLFQueue2PushClose()");
return CELL_OK;
}
void cellDaisyLFQueue2PopOpen(vm::ptr<LFQueue2> queue)
{
cellDaisy.todo("cellDaisyLFQueue2PopOpen()");
}
error_code cellDaisyLFQueue2PopClose(vm::ptr<LFQueue2> queue, vm::ptr<s32(vm::ptr<void>, u32)> fpSendSignal)
{
cellDaisy.todo("cellDaisyLFQueue2PopClose()");
return CELL_OK;
}
error_code cellDaisyLFQueue2HasUnfinishedConsumer(vm::ptr<LFQueue2> queue, u32 isCancelled)
{
cellDaisy.todo("cellDaisyLFQueue2HasUnfinishedConsumer()");
return CELL_OK;
}
error_code cellDaisy_snprintf(vm::ptr<char> buffer, u32 count, vm::cptr<char> fmt, ppu_va_args_t fmt_args)
{
cellDaisy.todo("cellDaisy_snprintf()");
return CELL_OK;
}
error_code cellDaisyLock_initialize(vm::ptr<Lock> _this, u32 depth)
{
cellDaisy.todo("cellDaisyLock_initialize()");
return CELL_OK;
}
error_code cellDaisyLock_getNextHeadPointer(vm::ptr<Lock> _this)
{
cellDaisy.todo("cellDaisyLock_getNextHeadPointer()");
return CELL_OK;
}
error_code cellDaisyLock_getNextTailPointer(vm::ptr<Lock> _this)
{
cellDaisy.todo("cellDaisyLock_getNextTailPointer()");
return CELL_OK;
}
error_code cellDaisyLock_completeConsume(vm::ptr<Lock> _this, u32 pointer)
{
cellDaisy.todo("cellDaisyLock_completeConsume()");
return CELL_OK;
}
error_code cellDaisyLock_completeProduce(vm::ptr<Lock> _this, u32 pointer)
{
cellDaisy.todo("cellDaisyLock_completeProduce()");
return CELL_OK;
}
error_code cellDaisyLock_pushOpen(vm::ptr<Lock> _this)
{
cellDaisy.todo("cellDaisyLock_pushOpen()");
return CELL_OK;
}
error_code cellDaisyLock_pushClose(vm::ptr<Lock> _this)
{
cellDaisy.todo("cellDaisyLock_pushClose()");
return CELL_OK;
}
error_code cellDaisyLock_popOpen(vm::ptr<Lock> _this)
{
cellDaisy.todo("cellDaisyLock_popOpen()");
return CELL_OK;
}
error_code cellDaisyLock_popClose(vm::ptr<Lock> _this)
{
cellDaisy.todo("cellDaisyLock_popClose()");
return CELL_OK;
}
void cellDaisyScatterGatherInterlock_1(vm::ptr<ScatterGatherInterlock> _this, vm::ptr<AtomicInterlock> ea, u32 size, vm::ptr<void> eaSignal, vm::ptr<s32(vm::ptr<void>, u32)> fpSendSignal)
{
cellDaisy.todo("cellDaisyScatterGatherInterlock_1()");
}
void cellDaisyScatterGatherInterlock_2(vm::ptr<ScatterGatherInterlock> _this, u32 size, vm::ptr<u32> ids, u32 numSpus, u8 spup)
{
cellDaisy.todo("cellDaisyScatterGatherInterlock_2()");
}
void cellDaisyScatterGatherInterlock_9tor(vm::ptr<ScatterGatherInterlock> _this)
{
cellDaisy.todo("cellDaisyScatterGatherInterlock_9tor()");
}
error_code cellDaisyScatterGatherInterlock_probe(vm::ptr<ScatterGatherInterlock> _this, u32 isBlocking)
{
cellDaisy.todo("cellDaisyScatterGatherInterlock_probe()");
return CELL_OK;
}
error_code cellDaisyScatterGatherInterlock_release(vm::ptr<ScatterGatherInterlock> _this)
{
cellDaisy.todo("cellDaisyScatterGatherInterlock_release()");
return CELL_OK;
}
void cellDaisyScatterGatherInterlock_proceedSequenceNumber(vm::ptr<ScatterGatherInterlock> _this)
{
cellDaisy.todo("cellDaisyScatterGatherInterlock_proceedSequenceNumber()");
}
DECLARE(ppu_module_manager::cellDaisy)("cellDaisy", []()
{
REG_FNID(cellDaisy, "_ZN4cell5Daisy17LFQueue2PushCloseEPNS0_8LFQueue2EPFiPvjE", cellDaisyLFQueue2PushClose);
REG_FNID(cellDaisy, "_QN4cell5Daisy17LFQueue2PushCloseEPNS0_8LFQueue2EPFiPvjE", cellDaisyLFQueue2PushClose);
REG_FNID(cellDaisy, "_ZN4cell5Daisy21LFQueue2GetPopPointerEPNS0_8LFQueue2EPij", cellDaisyLFQueue2GetPopPointer);
REG_FNID(cellDaisy, "_QN4cell5Daisy21LFQueue2GetPopPointerEPNS0_8LFQueue2EPij", cellDaisyLFQueue2GetPopPointer);
REG_FNID(cellDaisy, "_ZN4cell5Daisy26LFQueue2CompletePopPointerEPNS0_8LFQueue2EiPFiPvjEj", cellDaisyLFQueue2CompletePopPointer);
REG_FNID(cellDaisy, "_QN4cell5Daisy26LFQueue2CompletePopPointerEPNS0_8LFQueue2EiPFiPvjEj", cellDaisyLFQueue2CompletePopPointer);
REG_FNID(cellDaisy, "_ZN4cell5Daisy29LFQueue2HasUnfinishedConsumerEPNS0_8LFQueue2Ej", cellDaisyLFQueue2HasUnfinishedConsumer);
REG_FNID(cellDaisy, "_QN4cell5Daisy29LFQueue2HasUnfinishedConsumerEPNS0_8LFQueue2Ej", cellDaisyLFQueue2HasUnfinishedConsumer);
REG_FNID(cellDaisy, "_ZN4cell5Daisy16LFQueue2PushOpenEPNS0_8LFQueue2E", cellDaisyLFQueue2PushOpen);
REG_FNID(cellDaisy, "_QN4cell5Daisy16LFQueue2PushOpenEPNS0_8LFQueue2E", cellDaisyLFQueue2PushOpen);
REG_FNID(cellDaisy, "_ZN4cell5Daisy16LFQueue2PopCloseEPNS0_8LFQueue2EPFiPvjE", cellDaisyLFQueue2PopClose);
REG_FNID(cellDaisy, "_QN4cell5Daisy16LFQueue2PopCloseEPNS0_8LFQueue2EPFiPvjE", cellDaisyLFQueue2PopClose);
REG_FNID(cellDaisy, "_ZN4cell5Daisy15LFQueue2PopOpenEPNS0_8LFQueue2E", cellDaisyLFQueue2PopOpen);
REG_FNID(cellDaisy, "_QN4cell5Daisy15LFQueue2PopOpenEPNS0_8LFQueue2E", cellDaisyLFQueue2PopOpen);
REG_FNID(cellDaisy, "_ZN4cell5Daisy9_snprintfEPcjPKcz", cellDaisy_snprintf);
REG_FNID(cellDaisy, "_QN4cell5Daisy9_snprintfEPcjPKcz", cellDaisy_snprintf);
REG_FNID(cellDaisy, "_ZN4cell5Daisy4Lock7popOpenEv", cellDaisyLock_popOpen);
REG_FNID(cellDaisy, "_QN4cell5Daisy4Lock7popOpenEv", cellDaisyLock_popOpen);
REG_FNID(cellDaisy, "_ZN4cell5Daisy4Lock18getNextHeadPointerEv", cellDaisyLock_getNextHeadPointer);
REG_FNID(cellDaisy, "_QN4cell5Daisy4Lock18getNextHeadPointerEv", cellDaisyLock_getNextHeadPointer);
REG_FNID(cellDaisy, "_ZN4cell5Daisy4Lock10initializeEj", cellDaisyLock_initialize);
REG_FNID(cellDaisy, "_QN4cell5Daisy4Lock10initializeEj", cellDaisyLock_initialize);
REG_FNID(cellDaisy, "_ZN4cell5Daisy4Lock15completeProduceEj", cellDaisyLock_completeProduce);
REG_FNID(cellDaisy, "_QN4cell5Daisy4Lock15completeProduceEj", cellDaisyLock_completeProduce);
REG_FNID(cellDaisy, "_ZN4cell5Daisy4Lock8popCloseEv", cellDaisyLock_popClose);
REG_FNID(cellDaisy, "_QN4cell5Daisy4Lock8popCloseEv", cellDaisyLock_popClose);
REG_FNID(cellDaisy, "_ZN4cell5Daisy4Lock18getNextTailPointerEv", cellDaisyLock_getNextTailPointer);
REG_FNID(cellDaisy, "_QN4cell5Daisy4Lock18getNextTailPointerEv", cellDaisyLock_getNextTailPointer);
REG_FNID(cellDaisy, "_ZN4cell5Daisy4Lock8pushOpenEv", cellDaisyLock_pushOpen);
REG_FNID(cellDaisy, "_QN4cell5Daisy4Lock8pushOpenEv", cellDaisyLock_pushOpen);
REG_FNID(cellDaisy, "_ZN4cell5Daisy4Lock9pushCloseEv", cellDaisyLock_pushClose);
REG_FNID(cellDaisy, "_QN4cell5Daisy4Lock9pushCloseEv", cellDaisyLock_pushClose);
REG_FNID(cellDaisy, "_ZN4cell5Daisy4Lock15completeConsumeEj", cellDaisyLock_completeConsume);
REG_FNID(cellDaisy, "_QN4cell5Daisy4Lock15completeConsumeEj", cellDaisyLock_completeConsume);
REG_FNID(cellDaisy, "_ZN4cell5Daisy22ScatterGatherInterlockC1EPVNS0_16_AtomicInterlockEjPjjh", cellDaisyScatterGatherInterlock_1);
REG_FNID(cellDaisy, "_QN4cell5Daisy22ScatterGatherInterlockC1EPVNS0_16_AtomicInterlockEjPjjh", cellDaisyScatterGatherInterlock_1);
REG_FNID(cellDaisy, "_ZN4cell5Daisy22ScatterGatherInterlockC2EPVNS0_16_AtomicInterlockEjPjjh", cellDaisyScatterGatherInterlock_1);
REG_FNID(cellDaisy, "_QN4cell5Daisy22ScatterGatherInterlockC2EPVNS0_16_AtomicInterlockEjPjjh", cellDaisyScatterGatherInterlock_1);
REG_FNID(cellDaisy, "_ZN4cell5Daisy22ScatterGatherInterlockC1EPVNS0_16_AtomicInterlockEjPvPFiS5_jE", cellDaisyScatterGatherInterlock_2);
REG_FNID(cellDaisy, "_QN4cell5Daisy22ScatterGatherInterlockC1EPVNS0_16_AtomicInterlockEjPvPFiS5_jE", cellDaisyScatterGatherInterlock_2);
REG_FNID(cellDaisy, "_QN4cell5Daisy22ScatterGatherInterlockC2EPVNS0_16_AtomicInterlockEjPvPFiS5_jE", cellDaisyScatterGatherInterlock_2);
REG_FNID(cellDaisy, "_ZN4cell5Daisy22ScatterGatherInterlockC2EPVNS0_16_AtomicInterlockEjPvPFiS5_jE", cellDaisyScatterGatherInterlock_2);
REG_FNID(cellDaisy, "_ZN4cell5Daisy22ScatterGatherInterlockD2Ev", cellDaisyScatterGatherInterlock_9tor);
REG_FNID(cellDaisy, "_QN4cell5Daisy22ScatterGatherInterlockD2Ev", cellDaisyScatterGatherInterlock_9tor);
REG_FNID(cellDaisy, "_ZN4cell5Daisy22ScatterGatherInterlockD1Ev", cellDaisyScatterGatherInterlock_9tor);
REG_FNID(cellDaisy, "_QN4cell5Daisy22ScatterGatherInterlockD1Ev", cellDaisyScatterGatherInterlock_9tor);
REG_FNID(cellDaisy, "_ZN4cell5Daisy22ScatterGatherInterlock7releaseEv", cellDaisyScatterGatherInterlock_release);
REG_FNID(cellDaisy, "_QN4cell5Daisy22ScatterGatherInterlock7releaseEv", cellDaisyScatterGatherInterlock_release);
REG_FNID(cellDaisy, "_ZN4cell5Daisy22ScatterGatherInterlock21proceedSequenceNumberEv", cellDaisyScatterGatherInterlock_proceedSequenceNumber);
REG_FNID(cellDaisy, "_QN4cell5Daisy22ScatterGatherInterlock21proceedSequenceNumberEv", cellDaisyScatterGatherInterlock_proceedSequenceNumber);
REG_FNID(cellDaisy, "_ZN4cell5Daisy22ScatterGatherInterlock5probeEj", cellDaisyScatterGatherInterlock_probe);
REG_FNID(cellDaisy, "_QN4cell5Daisy22ScatterGatherInterlock5probeEj", cellDaisyScatterGatherInterlock_probe);
});
| 10,220
|
C++
|
.cpp
| 195
| 50.589744
| 187
| 0.83707
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| true
| false
| false
| true
| false
| false
|
5,250
|
libad_async.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/libad_async.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
LOG_CHANNEL(libad_async);
error_code sceAdAsyncOpenContext()
{
UNIMPLEMENTED_FUNC(libad_async);
return CELL_OK;
}
error_code sceAdAsyncConnectContext()
{
UNIMPLEMENTED_FUNC(libad_async);
return CELL_OK;
}
error_code sceAdAsyncSpaceOpen()
{
UNIMPLEMENTED_FUNC(libad_async);
return CELL_OK;
}
error_code sceAdAsyncFlushReports()
{
UNIMPLEMENTED_FUNC(libad_async);
return CELL_OK;
}
error_code sceAdAsyncSpaceClose()
{
UNIMPLEMENTED_FUNC(libad_async);
return CELL_OK;
}
error_code sceAdAsyncCloseContext()
{
UNIMPLEMENTED_FUNC(libad_async);
return CELL_OK;
}
DECLARE(ppu_module_manager::libad_async)("libad_async", []()
{
REG_FUNC(libad_async, sceAdAsyncOpenContext);
REG_FUNC(libad_async, sceAdAsyncConnectContext);
REG_FUNC(libad_async, sceAdAsyncSpaceOpen);
REG_FUNC(libad_async, sceAdAsyncFlushReports);
REG_FUNC(libad_async, sceAdAsyncSpaceClose);
REG_FUNC(libad_async, sceAdAsyncCloseContext);
});
| 979
|
C++
|
.cpp
| 42
| 21.690476
| 60
| 0.80409
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| true
| false
| false
| true
| false
| false
|
5,251
|
cellDtcpIpUtility.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellDtcpIpUtility.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
LOG_CHANNEL(cellDtcpIpUtility);
error_code cellDtcpIpRead()
{
UNIMPLEMENTED_FUNC(cellDtcpIpUtility);
return CELL_OK;
}
error_code cellDtcpIpFinalize()
{
UNIMPLEMENTED_FUNC(cellDtcpIpUtility);
return CELL_OK;
}
error_code cellDtcpIpActivate()
{
UNIMPLEMENTED_FUNC(cellDtcpIpUtility);
return CELL_OK;
}
error_code cellDtcpIpOpen()
{
UNIMPLEMENTED_FUNC(cellDtcpIpUtility);
return CELL_OK;
}
error_code cellDtcpIpCheckActivation()
{
UNIMPLEMENTED_FUNC(cellDtcpIpUtility);
return CELL_OK;
}
error_code cellDtcpIpInitialize()
{
UNIMPLEMENTED_FUNC(cellDtcpIpUtility);
return CELL_OK;
}
error_code cellDtcpIpGetDecryptedData()
{
UNIMPLEMENTED_FUNC(cellDtcpIpUtility);
return CELL_OK;
}
error_code cellDtcpIpStopSequence()
{
UNIMPLEMENTED_FUNC(cellDtcpIpUtility);
return CELL_OK;
}
error_code cellDtcpIpSeek()
{
UNIMPLEMENTED_FUNC(cellDtcpIpUtility);
return CELL_OK;
}
error_code cellDtcpIpStartSequence()
{
UNIMPLEMENTED_FUNC(cellDtcpIpUtility);
return CELL_OK;
}
error_code cellDtcpIpSetEncryptedData()
{
UNIMPLEMENTED_FUNC(cellDtcpIpUtility);
return CELL_OK;
}
error_code cellDtcpIpClose()
{
UNIMPLEMENTED_FUNC(cellDtcpIpUtility);
return CELL_OK;
}
error_code cellDtcpIpSuspendActivationForDebug()
{
UNIMPLEMENTED_FUNC(cellDtcpIpUtility);
return CELL_OK;
}
DECLARE(ppu_module_manager::cellDtcpIpUtility)("cellDtcpIpUtility", []()
{
REG_FUNC(cellDtcpIpUtility, cellDtcpIpRead);
REG_FUNC(cellDtcpIpUtility, cellDtcpIpFinalize);
REG_FUNC(cellDtcpIpUtility, cellDtcpIpActivate);
REG_FUNC(cellDtcpIpUtility, cellDtcpIpOpen);
REG_FUNC(cellDtcpIpUtility, cellDtcpIpCheckActivation);
REG_FUNC(cellDtcpIpUtility, cellDtcpIpInitialize);
REG_FUNC(cellDtcpIpUtility, cellDtcpIpGetDecryptedData);
REG_FUNC(cellDtcpIpUtility, cellDtcpIpStopSequence);
REG_FUNC(cellDtcpIpUtility, cellDtcpIpSeek);
REG_FUNC(cellDtcpIpUtility, cellDtcpIpStartSequence);
REG_FUNC(cellDtcpIpUtility, cellDtcpIpSetEncryptedData);
REG_FUNC(cellDtcpIpUtility, cellDtcpIpClose);
REG_FUNC(cellDtcpIpUtility, cellDtcpIpSuspendActivationForDebug);
});
| 2,109
|
C++
|
.cpp
| 84
| 23.464286
| 72
| 0.840299
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| true
| false
| false
| true
| false
| false
|
5,252
|
libfs_utility_init.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/libfs_utility_init.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
LOG_CHANNEL(libfs_utility_init);
error_code fs_utility_init_1F3CD9F1()
{
libfs_utility_init.todo("fs_utility_init_1F3CD9F1()");
return CELL_OK;
}
error_code fs_utility_init_263172B8(u32 arg1)
{
libfs_utility_init.todo("fs_utility_init_263172B8(0x%0x)", arg1);
// arg1 usually 0x3 ??
// This method seems to call fsck on the various partitions, among other checks
// Negative numbers indicate an error
// Some positive numbers are deemed illegal, others (including 0) are accepted as valid
return CELL_OK;
}
error_code fs_utility_init_4E949DA4()
{
libfs_utility_init.todo("fs_utility_init_4E949DA4()");
return CELL_OK;
}
error_code fs_utility_init_665DF255()
{
libfs_utility_init.todo("fs_utility_init_665DF255()");
return CELL_OK;
}
error_code fs_utility_init_6B5896B0(vm::ptr<u64> dest)
{
libfs_utility_init.todo("fs_utility_init_6B5896B0(dest=*0x%0x)", dest);
if (!dest)
{
return CELL_EFAULT;
}
// This method writes the number of partitions to the address pointed to by dest
*dest = 2;
return CELL_OK;
}
error_code fs_utility_init_A9B04535(u32 arg1)
{
libfs_utility_init.todo("fs_utility_init_A9B04535(0x%0x)", arg1);
// This method seems to call fsck on the various partitions, among other checks
// Negative numbers indicate an error
// Some positive numbers are deemed illegal, others (including 0) are accepted as valid
return CELL_OK;
}
error_code fs_utility_init_E7563CE6()
{
libfs_utility_init.todo("fs_utility_init_E7563CE6()");
return CELL_OK;
}
error_code fs_utility_init_F691D443()
{
libfs_utility_init.todo("fs_utility_init_F691D443()");
return CELL_OK;
}
DECLARE(ppu_module_manager::libfs_utility_init)("fs_utility_init", []()
{
REG_FNID(fs_utility_init, 0x1F3CD9F1, fs_utility_init_1F3CD9F1);
REG_FNID(fs_utility_init, 0x263172B8, fs_utility_init_263172B8);
REG_FNID(fs_utility_init, 0x4E949DA4, fs_utility_init_4E949DA4);
REG_FNID(fs_utility_init, 0x665DF255, fs_utility_init_665DF255);
REG_FNID(fs_utility_init, 0x6B5896B0, fs_utility_init_6B5896B0);
REG_FNID(fs_utility_init, 0xA9B04535, fs_utility_init_A9B04535);
REG_FNID(fs_utility_init, 0xE7563CE6, fs_utility_init_E7563CE6);
REG_FNID(fs_utility_init, 0xF691D443, fs_utility_init_F691D443);
});
| 2,277
|
C++
|
.cpp
| 67
| 32.149254
| 88
| 0.762318
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| true
| false
| false
| true
| false
| false
|
5,253
|
cellNetAoi.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellNetAoi.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
LOG_CHANNEL(cellNetAoi);
error_code cellNetAoiDeletePeer()
{
UNIMPLEMENTED_FUNC(cellNetAoi);
return CELL_OK;
}
error_code cellNetAoiInit()
{
UNIMPLEMENTED_FUNC(cellNetAoi);
return CELL_OK;
}
error_code cellNetAoiGetPspTitleId()
{
UNIMPLEMENTED_FUNC(cellNetAoi);
return CELL_OK;
}
error_code cellNetAoiTerm()
{
UNIMPLEMENTED_FUNC(cellNetAoi);
return CELL_OK;
}
error_code cellNetAoiStop()
{
UNIMPLEMENTED_FUNC(cellNetAoi);
return CELL_OK;
}
error_code cellNetAoiGetRemotePeerInfo()
{
UNIMPLEMENTED_FUNC(cellNetAoi);
return CELL_OK;
}
error_code cellNetAoiStart()
{
UNIMPLEMENTED_FUNC(cellNetAoi);
return CELL_OK;
}
error_code cellNetAoiGetLocalInfo()
{
UNIMPLEMENTED_FUNC(cellNetAoi);
return CELL_OK;
}
error_code cellNetAoiAddPeer()
{
UNIMPLEMENTED_FUNC(cellNetAoi);
return CELL_OK;
}
DECLARE(ppu_module_manager::cellNetAoi)("cellNetAoi", []()
{
REG_FUNC(cellNetAoi, cellNetAoiDeletePeer);
REG_FUNC(cellNetAoi, cellNetAoiInit);
REG_FUNC(cellNetAoi, cellNetAoiGetPspTitleId);
REG_FUNC(cellNetAoi, cellNetAoiTerm);
REG_FUNC(cellNetAoi, cellNetAoiStop);
REG_FUNC(cellNetAoi, cellNetAoiGetRemotePeerInfo);
REG_FUNC(cellNetAoi, cellNetAoiStart);
REG_FUNC(cellNetAoi, cellNetAoiGetLocalInfo);
REG_FUNC(cellNetAoi, cellNetAoiAddPeer);
});
| 1,322
|
C++
|
.cpp
| 60
| 20.4
| 58
| 0.813749
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| true
| false
| false
| true
| false
| false
|
5,254
|
cellPad.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellPad.cpp
|
#include "stdafx.h"
#include "Emu/IdManager.h"
#include "Emu/system_config.h"
#include "Emu/Cell/PPUModule.h"
#include "Emu/Cell/lv2/sys_process.h"
#include "Emu/Cell/lv2/sys_sync.h"
#include "Emu/Io/pad_types.h"
#include "Emu/RSX/Overlays/overlay_debug_overlay.h"
#include "Input/pad_thread.h"
#include "Input/product_info.h"
#include "cellPad.h"
error_code sys_config_start(ppu_thread& ppu);
error_code sys_config_stop(ppu_thread& ppu);
extern bool is_input_allowed();
LOG_CHANNEL(cellPad);
template<>
void fmt_class_string<CellPadError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_PAD_ERROR_FATAL);
STR_CASE(CELL_PAD_ERROR_INVALID_PARAMETER);
STR_CASE(CELL_PAD_ERROR_ALREADY_INITIALIZED);
STR_CASE(CELL_PAD_ERROR_UNINITIALIZED);
STR_CASE(CELL_PAD_ERROR_RESOURCE_ALLOCATION_FAILED);
STR_CASE(CELL_PAD_ERROR_DATA_READ_FAILED);
STR_CASE(CELL_PAD_ERROR_NO_DEVICE);
STR_CASE(CELL_PAD_ERROR_UNSUPPORTED_GAMEPAD);
STR_CASE(CELL_PAD_ERROR_TOO_MANY_DEVICES);
STR_CASE(CELL_PAD_ERROR_EBUSY);
}
return unknown;
});
}
template<>
void fmt_class_string<CellPadFilterError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_PADFILTER_ERROR_INVALID_PARAMETER);
}
return unknown;
});
}
extern void sys_io_serialize(utils::serial& ar);
pad_info::pad_info(utils::serial& ar)
: max_connect(ar)
, port_setting(ar)
, reported_info(ar)
{
//reported_info = {};
sys_io_serialize(ar);
}
void pad_info::save(utils::serial& ar)
{
USING_SERIALIZATION_VERSION(sys_io);
ar(max_connect, port_setting, reported_info);
sys_io_serialize(ar);
}
void show_debug_overlay(const CellPadData& data, const Pad& pad, const pad_info& config)
{
const u32 setting = config.port_setting[pad.m_player_id];
const u16 d1 = data.button[CELL_PAD_BTN_OFFSET_DIGITAL1];
const u16 d2 = data.button[CELL_PAD_BTN_OFFSET_DIGITAL2];
std::string text = fmt::format(
"> Name: Raw Value Pressure\n"
">\n"
"> Len: %13d\n"
"> Digital: %5s %5s\n"
"> Press: %5s %5s\n"
"> Sensor: %5s %5s\n"
">\n"
"> Digital 1: 0x%04x 0x%04x\n"
"> Digital 2: 0x%04x 0x%04x\n"
">\n"
"> D-Pad Up: %5d %5d %5d\n"
"> D-Pad Down: %5d %5d %5d\n"
"> D-Pad Left: %5d %5d %5d\n"
"> D-Pad Right: %5d %5d %5d\n"
"> Cross: %5d %5d %5d\n"
"> Square: %5d %5d %5d\n"
"> Circle: %5d %5d %5d\n"
"> Triangle: %5d %5d %5d\n"
"> Start: %5d %5d\n"
"> Select: %5d %5d\n"
"> PS: %5d %5d\n"
"> L1: %5d %5d %5d\n"
"> L2: %5d %5d %5d\n"
"> L3: %5d %5d\n"
"> R1: %5d %5d %5d\n"
"> R2: %5d %5d %5d\n"
"> R3: %5d %5d\n"
"> LS X: %5d %5d\n"
"> LS Y: %5d %5d\n"
"> RS X: %5d %5d\n"
"> RS Y: %5d %5d\n"
">\n"
"> Sensor X: %5d %5d\n"
"> Sensor Y: %5d %5d\n"
"> Sensor Z: %5d %5d\n"
"> Sensor G: %5d %5d\n"
">\n"
"> PID: 0x%04x\n"
"> VID: 0x%04x\n"
"> Device Type: 0x%08x\n"
"> Class Type: 0x%08x\n"
,
data.len,
"on", data.len >= CELL_PAD_LEN_CHANGE_DEFAULT ? "on" : "off",
(setting & CELL_PAD_SETTING_PRESS_ON) ? "on" : "off", data.len >= CELL_PAD_LEN_CHANGE_PRESS_ON ? "on" : "off",
(setting & CELL_PAD_SETTING_SENSOR_ON) ? "on" : "off", data.len >= CELL_PAD_LEN_CHANGE_SENSOR_ON ? "on" : "off",
pad.m_digital_1, d1,
pad.m_digital_2, d2,
pad.m_press_up, !!(d1 & CELL_PAD_CTRL_UP), data.button[CELL_PAD_BTN_OFFSET_PRESS_UP],
pad.m_press_down, !!(d1 & CELL_PAD_CTRL_DOWN), data.button[CELL_PAD_BTN_OFFSET_PRESS_DOWN],
pad.m_press_left, !!(d1 & CELL_PAD_CTRL_LEFT), data.button[CELL_PAD_BTN_OFFSET_PRESS_LEFT],
pad.m_press_right, !!(d1 & CELL_PAD_CTRL_RIGHT), data.button[CELL_PAD_BTN_OFFSET_PRESS_RIGHT],
pad.m_press_cross, !!(d2 & CELL_PAD_CTRL_CROSS), data.button[CELL_PAD_BTN_OFFSET_PRESS_CROSS],
pad.m_press_square, !!(d2 & CELL_PAD_CTRL_SQUARE), data.button[CELL_PAD_BTN_OFFSET_PRESS_SQUARE],
pad.m_press_circle, !!(d2 & CELL_PAD_CTRL_CIRCLE), data.button[CELL_PAD_BTN_OFFSET_PRESS_CIRCLE],
pad.m_press_triangle, !!(d2 & CELL_PAD_CTRL_TRIANGLE), data.button[CELL_PAD_BTN_OFFSET_PRESS_TRIANGLE],
!!(pad.m_digital_1 & CELL_PAD_CTRL_START), !!(d1 & CELL_PAD_CTRL_START),
!!(pad.m_digital_1 & CELL_PAD_CTRL_SELECT), !!(d1 & CELL_PAD_CTRL_SELECT),
!!(pad.m_digital_1 & CELL_PAD_CTRL_PS), !!(d1 & CELL_PAD_CTRL_PS),
pad.m_press_L1, !!(d2 & CELL_PAD_CTRL_L1), data.button[CELL_PAD_BTN_OFFSET_PRESS_L1],
pad.m_press_L2, !!(d2 & CELL_PAD_CTRL_L2), data.button[CELL_PAD_BTN_OFFSET_PRESS_L2],
!!(pad.m_digital_1 & CELL_PAD_CTRL_L3), !!(d1 & CELL_PAD_CTRL_L3),
pad.m_press_R1, !!(d2 & CELL_PAD_CTRL_R1), data.button[CELL_PAD_BTN_OFFSET_PRESS_R1],
pad.m_press_R2, !!(d2 & CELL_PAD_CTRL_R2), data.button[CELL_PAD_BTN_OFFSET_PRESS_R2],
!!(pad.m_digital_1 & CELL_PAD_CTRL_R3), !!(d1 & CELL_PAD_CTRL_R3),
pad.m_analog_left_x, data.button[CELL_PAD_BTN_OFFSET_ANALOG_LEFT_X],
pad.m_analog_left_y, data.button[CELL_PAD_BTN_OFFSET_ANALOG_LEFT_Y],
pad.m_analog_right_x, data.button[CELL_PAD_BTN_OFFSET_ANALOG_RIGHT_X],
pad.m_analog_right_y, data.button[CELL_PAD_BTN_OFFSET_ANALOG_RIGHT_Y],
pad.m_sensor_x, data.button[CELL_PAD_BTN_OFFSET_SENSOR_X],
pad.m_sensor_y, data.button[CELL_PAD_BTN_OFFSET_SENSOR_Y],
pad.m_sensor_z, data.button[CELL_PAD_BTN_OFFSET_SENSOR_Z],
pad.m_sensor_g, data.button[CELL_PAD_BTN_OFFSET_SENSOR_G],
pad.m_product_id,
pad.m_vendor_id,
pad.m_device_type,
pad.m_class_type
);
rsx::overlays::set_debug_overlay_text(std::move(text));
}
extern void send_sys_io_connect_event(usz index, u32 state);
bool cellPad_NotifyStateChange(usz index, u64 /*state*/, bool locked, bool is_blocking = true)
{
auto info = g_fxo->try_get<pad_info>();
if (!info)
{
return true;
}
std::unique_lock lock(pad::g_pad_mutex, std::defer_lock);
if (locked)
{
if (is_blocking)
{
lock.lock();
}
else
{
if (!lock.try_lock())
{
return false;
}
}
}
if (index >= info->get_max_connect())
{
return true;
}
const auto handler = pad::get_current_handler();
const auto& pads = handler->GetPads();
const auto& pad = pads[index];
if (pad->is_fake_pad)
{
return true;
}
pad_data_internal& reported_info = info->reported_info[index];
const u32 old_status = reported_info.port_status;
// Ignore sent status for now, use the latest instead
// NOTE 1: The state's CONNECTED bit should currently be identical to the current
// m_port_status CONNECTED bit when called from our pad handlers.
// NOTE 2: Make sure to propagate all other status bits to the reported status.
const u32 new_status = pad->m_port_status;
if (~(old_status ^ new_status) & CELL_PAD_STATUS_CONNECTED)
{
// old and new have the same connection status
return true;
}
reported_info.port_status = new_status | CELL_PAD_STATUS_ASSIGN_CHANGES;
reported_info.device_capability = pad->m_device_capability;
reported_info.device_type = pad->m_device_type;
reported_info.pclass_type = pad->m_class_type;
reported_info.pclass_profile = pad->m_class_profile;
if (pad->m_vendor_id == 0 || pad->m_product_id == 0)
{
// Fallback to defaults
const std::vector<input::product_info> input_products = input::get_products_by_class(pad->m_class_type);
const input::product_info& product = ::at32(input_products, 0);
reported_info.vendor_id = product.vendor_id;
reported_info.product_id = product.product_id;
}
else
{
reported_info.vendor_id = pad->m_vendor_id;
reported_info.product_id = pad->m_product_id;
}
return true;
}
extern void pad_state_notify_state_change(usz index, u32 state)
{
send_sys_io_connect_event(index, state);
}
error_code cellPadInit(ppu_thread& ppu, u32 max_connect)
{
cellPad.warning("cellPadInit(max_connect=%d)", max_connect);
std::lock_guard lock(pad::g_pad_mutex);
auto& config = g_fxo->get<pad_info>();
if (config.max_connect)
return CELL_PAD_ERROR_ALREADY_INITIALIZED;
if (max_connect == 0 || max_connect > CELL_MAX_PADS)
return CELL_PAD_ERROR_INVALID_PARAMETER;
sys_config_start(ppu);
config.max_connect = max_connect;
config.port_setting.fill(CELL_PAD_SETTING_PRESS_OFF | CELL_PAD_SETTING_SENSOR_OFF);
config.reported_info = {};
const auto handler = pad::get_current_handler();
const auto& pads = handler->GetPads();
for (usz i = 0; i < config.get_max_connect(); ++i)
{
if (!pads[i]->is_fake_pad && (pads[i]->m_port_status & CELL_PAD_STATUS_CONNECTED))
{
send_sys_io_connect_event(i, CELL_PAD_STATUS_CONNECTED);
}
}
return CELL_OK;
}
error_code cellPadEnd(ppu_thread& ppu)
{
cellPad.notice("cellPadEnd()");
std::lock_guard lock(pad::g_pad_mutex);
auto& config = g_fxo->get<pad_info>();
if (!config.max_connect.exchange(0))
return CELL_PAD_ERROR_UNINITIALIZED;
sys_config_stop(ppu);
return CELL_OK;
}
void clear_pad_buffer(const std::shared_ptr<Pad>& pad)
{
if (!pad)
return;
// Set 'm_buffer_cleared' to force a resend of everything
// might as well also reset everything in our pad 'buffer' to nothing as well
pad->m_buffer_cleared = true;
pad->m_analog_left_x = pad->m_analog_left_y = pad->m_analog_right_x = pad->m_analog_right_y = 128;
pad->m_digital_1 = pad->m_digital_2 = 0;
pad->m_press_right = pad->m_press_left = pad->m_press_up = pad->m_press_down = 0;
pad->m_press_triangle = pad->m_press_circle = pad->m_press_cross = pad->m_press_square = 0;
pad->m_press_L1 = pad->m_press_L2 = pad->m_press_R1 = pad->m_press_R2 = 0;
// ~399 on sensor y is a level non moving controller
pad->m_sensor_y = 399;
pad->m_sensor_x = pad->m_sensor_z = pad->m_sensor_g = 512;
}
error_code cellPadClearBuf(u32 port_no)
{
cellPad.trace("cellPadClearBuf(port_no=%d)", port_no);
std::lock_guard lock(pad::g_pad_mutex);
auto& config = g_fxo->get<pad_info>();
if (!config.max_connect)
return CELL_PAD_ERROR_UNINITIALIZED;
if (port_no >= CELL_MAX_PADS)
return CELL_PAD_ERROR_INVALID_PARAMETER;
if (port_no >= config.get_max_connect())
return CELL_PAD_ERROR_NO_DEVICE;
const auto handler = pad::get_current_handler();
const auto& pads = handler->GetPads();
const auto& pad = pads[port_no];
if (pad->is_fake_pad || !config.is_reportedly_connected(port_no) || !(pad->m_port_status & CELL_PAD_STATUS_CONNECTED))
return not_an_error(CELL_PAD_ERROR_NO_DEVICE);
clear_pad_buffer(pad);
return CELL_OK;
}
void pad_get_data(u32 port_no, CellPadData* data, bool get_periph_data = false)
{
auto& config = g_fxo->get<pad_info>();
const auto handler = pad::get_current_handler();
const auto& pad = handler->GetPads()[port_no];
const PadInfo& rinfo = handler->GetInfo();
if (rinfo.system_info & CELL_PAD_INFO_INTERCEPTED)
{
data->len = CELL_PAD_LEN_NO_CHANGE;
return;
}
const u32 setting = config.port_setting[port_no];
bool btnChanged = false;
if (rinfo.ignore_input || !is_input_allowed())
{
// Needed for Hotline Miami and Ninja Gaiden Sigma after dialogs were closed and buttons are still pressed.
// Gran Turismo 6 would keep registering the Start button during OSK Dialogs if this wasn't cleared and if we'd return with len as CELL_PAD_LEN_NO_CHANGE.
clear_pad_buffer(pad);
}
else if (pad->ldd)
{
if (setting & CELL_PAD_SETTING_SENSOR_ON)
data->len = CELL_PAD_LEN_CHANGE_SENSOR_ON;
else
data->len = (setting & CELL_PAD_SETTING_PRESS_ON) ? CELL_PAD_LEN_CHANGE_PRESS_ON : CELL_PAD_LEN_CHANGE_DEFAULT;
std::memcpy(data->button, pad->ldd_data.button, data->len * sizeof(u16));
return;
}
else
{
const u16 d1Initial = pad->m_digital_1;
const u16 d2Initial = pad->m_digital_2;
// Check if this pad is configured as a skateboard which ignores sticks and pressure button values.
// Curiously it maps infrared on the press value of the face buttons for some reason.
const bool use_piggyback = pad->m_class_type == CELL_PAD_PCLASS_TYPE_SKATEBOARD;
const auto set_value = [&btnChanged, use_piggyback, &pad](u16& value, u16 new_value, bool force_processing = false, u16 old_max_value = 255, u16 new_max_value = 255)
{
if (use_piggyback)
{
if (!force_processing)
return;
// Some piggyback values need to be scaled down on emulated devices
if (old_max_value != new_max_value)
{
if (pad->m_class_type == CELL_PAD_PCLASS_TYPE_SKATEBOARD && pad->m_pad_handler != pad_handler::skateboard)
{
new_value = static_cast<u16>(new_max_value * std::clamp(new_value / static_cast<f32>(old_max_value), 0.0f, 1.0f));
}
}
}
if (value != new_value)
{
btnChanged = true;
value = new_value;
}
};
for (Button& button : pad->m_buttons)
{
// here we check btns, and set pad accordingly,
// if something changed, set btnChanged
switch (button.m_offset)
{
case CELL_PAD_BTN_OFFSET_DIGITAL1:
{
if (button.m_pressed)
pad->m_digital_1 |= button.m_outKeyCode;
else
pad->m_digital_1 &= ~button.m_outKeyCode;
switch (button.m_outKeyCode)
{
case CELL_PAD_CTRL_LEFT: set_value(pad->m_press_left, button.m_value); break;
case CELL_PAD_CTRL_DOWN: set_value(pad->m_press_down, button.m_value); break;
case CELL_PAD_CTRL_RIGHT: set_value(pad->m_press_right, button.m_value); break;
case CELL_PAD_CTRL_UP: set_value(pad->m_press_up, button.m_value); break;
// These arent pressure btns
case CELL_PAD_CTRL_R3:
case CELL_PAD_CTRL_L3:
case CELL_PAD_CTRL_START:
case CELL_PAD_CTRL_SELECT:
default: break;
}
break;
}
case CELL_PAD_BTN_OFFSET_DIGITAL2:
{
if (button.m_pressed)
pad->m_digital_2 |= button.m_outKeyCode;
else
pad->m_digital_2 &= ~button.m_outKeyCode;
switch (button.m_outKeyCode)
{
case CELL_PAD_CTRL_SQUARE: set_value(pad->m_press_square, button.m_value); break;
case CELL_PAD_CTRL_CROSS: set_value(pad->m_press_cross, button.m_value); break;
case CELL_PAD_CTRL_CIRCLE: set_value(pad->m_press_circle, button.m_value); break;
case CELL_PAD_CTRL_TRIANGLE: set_value(pad->m_press_triangle, button.m_value); break;
case CELL_PAD_CTRL_R1: set_value(pad->m_press_R1, button.m_value); break;
case CELL_PAD_CTRL_L1: set_value(pad->m_press_L1, button.m_value); break;
case CELL_PAD_CTRL_R2: set_value(pad->m_press_R2, button.m_value); break;
case CELL_PAD_CTRL_L2: set_value(pad->m_press_L2, button.m_value); break;
default: break;
}
break;
}
case CELL_PAD_BTN_OFFSET_PRESS_PIGGYBACK:
{
switch (button.m_outKeyCode)
{
case CELL_PAD_CTRL_PRESS_RIGHT: set_value(pad->m_press_right, button.m_value, true); break;
case CELL_PAD_CTRL_PRESS_LEFT: set_value(pad->m_press_left, button.m_value, true); break;
case CELL_PAD_CTRL_PRESS_UP: set_value(pad->m_press_up, button.m_value, true); break;
case CELL_PAD_CTRL_PRESS_DOWN: set_value(pad->m_press_down, button.m_value, true); break;
case CELL_PAD_CTRL_PRESS_TRIANGLE: set_value(pad->m_press_triangle, button.m_value, true, 255, 63); break; // Infrared on RIDE Skateboard
case CELL_PAD_CTRL_PRESS_CIRCLE: set_value(pad->m_press_circle, button.m_value, true, 255, 63); break; // Infrared on RIDE Skateboard
case CELL_PAD_CTRL_PRESS_CROSS: set_value(pad->m_press_cross, button.m_value, true, 255, 63); break; // Infrared on RIDE Skateboard
case CELL_PAD_CTRL_PRESS_SQUARE: set_value(pad->m_press_square, button.m_value, true, 255, 63); break; // Infrared on RIDE Skateboard
case CELL_PAD_CTRL_PRESS_L1: set_value(pad->m_press_L1, button.m_value, true); break;
case CELL_PAD_CTRL_PRESS_R1: set_value(pad->m_press_R1, button.m_value, true); break;
case CELL_PAD_CTRL_PRESS_L2: set_value(pad->m_press_L2, button.m_value, true); break;
case CELL_PAD_CTRL_PRESS_R2: set_value(pad->m_press_R2, button.m_value, true); break;
default: break;
}
break;
}
default:
break;
}
}
for (const AnalogStick& stick : pad->m_sticks)
{
switch (stick.m_offset)
{
case CELL_PAD_BTN_OFFSET_ANALOG_LEFT_X: set_value(pad->m_analog_left_x, stick.m_value); break;
case CELL_PAD_BTN_OFFSET_ANALOG_LEFT_Y: set_value(pad->m_analog_left_y, stick.m_value); break;
case CELL_PAD_BTN_OFFSET_ANALOG_RIGHT_X: set_value(pad->m_analog_right_x, stick.m_value); break;
case CELL_PAD_BTN_OFFSET_ANALOG_RIGHT_Y: set_value(pad->m_analog_right_y, stick.m_value); break;
default: break;
}
}
if (setting & CELL_PAD_SETTING_SENSOR_ON)
{
for (const AnalogSensor& sensor : pad->m_sensors)
{
switch (sensor.m_offset)
{
case CELL_PAD_BTN_OFFSET_SENSOR_X: set_value(pad->m_sensor_x, sensor.m_value, true); break;
case CELL_PAD_BTN_OFFSET_SENSOR_Y: set_value(pad->m_sensor_y, sensor.m_value, true); break;
case CELL_PAD_BTN_OFFSET_SENSOR_Z: set_value(pad->m_sensor_z, sensor.m_value, true); break;
case CELL_PAD_BTN_OFFSET_SENSOR_G: set_value(pad->m_sensor_g, sensor.m_value, true); break;
default: break;
}
}
}
if (d1Initial != pad->m_digital_1 || d2Initial != pad->m_digital_2)
{
btnChanged = true;
}
}
if (setting & CELL_PAD_SETTING_SENSOR_ON)
{
// report back new data every ~10 ms even if the input doesn't change
// this is observed behaviour when using a Dualshock 3 controller
static std::array<steady_clock::time_point, CELL_PAD_MAX_PORT_NUM> last_update = { };
const auto now = steady_clock::now();
if (btnChanged || pad->m_buffer_cleared || now - last_update[port_no] >= 10ms)
{
data->len = CELL_PAD_LEN_CHANGE_SENSOR_ON;
last_update[port_no] = now;
}
else
{
data->len = CELL_PAD_LEN_NO_CHANGE;
}
}
else if (btnChanged || pad->m_buffer_cleared)
{
// only give back valid data if a controller state changed
data->len = (setting & CELL_PAD_SETTING_PRESS_ON) ? CELL_PAD_LEN_CHANGE_PRESS_ON : CELL_PAD_LEN_CHANGE_DEFAULT;
}
else
{
// report no state changes
data->len = CELL_PAD_LEN_NO_CHANGE;
}
pad->m_buffer_cleared = false;
// only update parts of the output struct depending on the controller setting
if (data->len > CELL_PAD_LEN_NO_CHANGE)
{
data->button[0] = 0x0; // always 0
// bits 15-8 reserved, 7-4 = 0x7, 3-0: data->len/2;
data->button[1] = (0x7 << 4) | std::min(data->len / 2, 15);
data->button[CELL_PAD_BTN_OFFSET_DIGITAL1] = pad->m_digital_1;
data->button[CELL_PAD_BTN_OFFSET_DIGITAL2] = pad->m_digital_2;
data->button[CELL_PAD_BTN_OFFSET_ANALOG_RIGHT_X] = pad->m_analog_right_x;
data->button[CELL_PAD_BTN_OFFSET_ANALOG_RIGHT_Y] = pad->m_analog_right_y;
data->button[CELL_PAD_BTN_OFFSET_ANALOG_LEFT_X] = pad->m_analog_left_x;
data->button[CELL_PAD_BTN_OFFSET_ANALOG_LEFT_Y] = pad->m_analog_left_y;
if (setting & CELL_PAD_SETTING_PRESS_ON)
{
data->button[CELL_PAD_BTN_OFFSET_PRESS_RIGHT] = pad->m_press_right;
data->button[CELL_PAD_BTN_OFFSET_PRESS_LEFT] = pad->m_press_left;
data->button[CELL_PAD_BTN_OFFSET_PRESS_UP] = pad->m_press_up;
data->button[CELL_PAD_BTN_OFFSET_PRESS_DOWN] = pad->m_press_down;
data->button[CELL_PAD_BTN_OFFSET_PRESS_TRIANGLE] = pad->m_press_triangle;
data->button[CELL_PAD_BTN_OFFSET_PRESS_CIRCLE] = pad->m_press_circle;
data->button[CELL_PAD_BTN_OFFSET_PRESS_CROSS] = pad->m_press_cross;
data->button[CELL_PAD_BTN_OFFSET_PRESS_SQUARE] = pad->m_press_square;
data->button[CELL_PAD_BTN_OFFSET_PRESS_L1] = pad->m_press_L1;
data->button[CELL_PAD_BTN_OFFSET_PRESS_R1] = pad->m_press_R1;
data->button[CELL_PAD_BTN_OFFSET_PRESS_L2] = pad->m_press_L2;
data->button[CELL_PAD_BTN_OFFSET_PRESS_R2] = pad->m_press_R2;
}
else
{
// Clear area if setting is not used
constexpr u32 area_lengh = (CELL_PAD_LEN_CHANGE_PRESS_ON - CELL_PAD_LEN_CHANGE_DEFAULT) * sizeof(u16);
std::memset(&data->button[CELL_PAD_LEN_CHANGE_DEFAULT], 0, area_lengh);
}
if (data->len == CELL_PAD_LEN_CHANGE_SENSOR_ON)
{
data->button[CELL_PAD_BTN_OFFSET_SENSOR_X] = pad->m_sensor_x;
data->button[CELL_PAD_BTN_OFFSET_SENSOR_Y] = pad->m_sensor_y;
data->button[CELL_PAD_BTN_OFFSET_SENSOR_Z] = pad->m_sensor_z;
data->button[CELL_PAD_BTN_OFFSET_SENSOR_G] = pad->m_sensor_g;
}
}
if (!get_periph_data || data->len <= CELL_PAD_LEN_CHANGE_SENSOR_ON)
{
return;
}
const auto get_pressure_value = [setting](u16 val, u16 min, u16 max) -> u16
{
if (setting & CELL_PAD_SETTING_PRESS_ON)
{
return std::clamp(val, min, max);
}
if (val > 0)
{
return max;
}
return 0;
};
// TODO: support for 'unique' controllers, which goes in offsets 24+ in padData (CELL_PAD_PCLASS_BTN_OFFSET)
// TODO: update data->len accordingly
switch (pad->m_class_profile)
{
default:
case CELL_PAD_PCLASS_TYPE_STANDARD:
case CELL_PAD_PCLASS_TYPE_NAVIGATION:
case CELL_PAD_PCLASS_TYPE_SKATEBOARD:
{
break;
}
case CELL_PAD_PCLASS_TYPE_GUITAR:
{
data->button[CELL_PAD_PCLASS_BTN_OFFSET_GUITAR_FRET_1] = get_pressure_value(0, 0x0, 0xFF);
data->button[CELL_PAD_PCLASS_BTN_OFFSET_GUITAR_FRET_2] = get_pressure_value(0, 0x0, 0xFF);
data->button[CELL_PAD_PCLASS_BTN_OFFSET_GUITAR_FRET_3] = get_pressure_value(0, 0x0, 0xFF);
data->button[CELL_PAD_PCLASS_BTN_OFFSET_GUITAR_FRET_4] = get_pressure_value(0, 0x0, 0xFF);
data->button[CELL_PAD_PCLASS_BTN_OFFSET_GUITAR_FRET_5] = get_pressure_value(0, 0x0, 0xFF);
data->button[CELL_PAD_PCLASS_BTN_OFFSET_GUITAR_STRUM_UP] = get_pressure_value(0, 0x0, 0xFF);
data->button[CELL_PAD_PCLASS_BTN_OFFSET_GUITAR_STRUM_DOWN] = get_pressure_value(0, 0x0, 0xFF);
data->button[CELL_PAD_PCLASS_BTN_OFFSET_GUITAR_WHAMMYBAR] = 0x80; // 0x80 – 0xFF
data->button[CELL_PAD_PCLASS_BTN_OFFSET_GUITAR_FRET_H1] = get_pressure_value(0, 0x0, 0xFF);
data->button[CELL_PAD_PCLASS_BTN_OFFSET_GUITAR_FRET_H2] = get_pressure_value(0, 0x0, 0xFF);
data->button[CELL_PAD_PCLASS_BTN_OFFSET_GUITAR_FRET_H3] = get_pressure_value(0, 0x0, 0xFF);
data->button[CELL_PAD_PCLASS_BTN_OFFSET_GUITAR_FRET_H4] = get_pressure_value(0, 0x0, 0xFF);
data->button[CELL_PAD_PCLASS_BTN_OFFSET_GUITAR_FRET_H5] = get_pressure_value(0, 0x0, 0xFF);
data->button[CELL_PAD_PCLASS_BTN_OFFSET_GUITAR_5WAY_EFFECT] = 0x0019; // One of 5 values: 0x0019, 0x004C, 0x007F (or 0x0096), 0x00B2, 0x00E5 (or 0x00E2)
data->button[CELL_PAD_PCLASS_BTN_OFFSET_GUITAR_TILT_SENS] = get_pressure_value(0, 0x0, 0xFF);
break;
}
case CELL_PAD_PCLASS_TYPE_DRUM:
{
data->button[CELL_PAD_PCLASS_BTN_OFFSET_DRUM_SNARE] = get_pressure_value(0, 0x0, 0xFF);
data->button[CELL_PAD_PCLASS_BTN_OFFSET_DRUM_TOM] = get_pressure_value(0, 0x0, 0xFF);
data->button[CELL_PAD_PCLASS_BTN_OFFSET_DRUM_TOM2] = get_pressure_value(0, 0x0, 0xFF);
data->button[CELL_PAD_PCLASS_BTN_OFFSET_DRUM_TOM_FLOOR] = get_pressure_value(0, 0x0, 0xFF);
data->button[CELL_PAD_PCLASS_BTN_OFFSET_DRUM_KICK] = get_pressure_value(0, 0x0, 0xFF);
data->button[CELL_PAD_PCLASS_BTN_OFFSET_DRUM_CYM_HiHAT] = get_pressure_value(0, 0x0, 0xFF);
data->button[CELL_PAD_PCLASS_BTN_OFFSET_DRUM_CYM_CRASH] = get_pressure_value(0, 0x0, 0xFF);
data->button[CELL_PAD_PCLASS_BTN_OFFSET_DRUM_CYM_RIDE] = get_pressure_value(0, 0x0, 0xFF);
data->button[CELL_PAD_PCLASS_BTN_OFFSET_DRUM_KICK2] = get_pressure_value(0, 0x0, 0xFF);
break;
}
case CELL_PAD_PCLASS_TYPE_DJ:
{
// First deck
data->button[CELL_PAD_PCLASS_BTN_OFFSET_DJ_MIXER_ATTACK] = 0; // 0x0 or 0xFF
data->button[CELL_PAD_PCLASS_BTN_OFFSET_DJ_MIXER_CROSSFADER] = 0; // 0x0 - 0x3FF
data->button[CELL_PAD_PCLASS_BTN_OFFSET_DJ_MIXER_DSP_DIAL] = 0; // 0x0 - 0x3FF
data->button[CELL_PAD_PCLASS_BTN_OFFSET_DJ_DECK1_STREAM1] = 0; // 0x0 or 0xFF
data->button[CELL_PAD_PCLASS_BTN_OFFSET_DJ_DECK1_STREAM2] = 0; // 0x0 or 0xFF
data->button[CELL_PAD_PCLASS_BTN_OFFSET_DJ_DECK1_STREAM3] = 0; // 0x0 or 0xFF
data->button[CELL_PAD_PCLASS_BTN_OFFSET_DJ_DECK1_PLATTER] = 0x80; // 0x0 - 0xFF (neutral: 0x80)
// Second deck
data->button[CELL_PAD_PCLASS_BTN_OFFSET_DJ_DECK2_STREAM1] = 0; // 0x0 or 0xFF
data->button[CELL_PAD_PCLASS_BTN_OFFSET_DJ_DECK2_STREAM2] = 0; // 0x0 or 0xFF
data->button[CELL_PAD_PCLASS_BTN_OFFSET_DJ_DECK2_STREAM3] = 0; // 0x0 or 0xFF
data->button[CELL_PAD_PCLASS_BTN_OFFSET_DJ_DECK2_PLATTER] = 0x80; // 0x0 - 0xFF (neutral: 0x80)
break;
}
case CELL_PAD_PCLASS_TYPE_DANCEMAT:
{
data->button[CELL_PAD_PCLASS_BTN_OFFSET_DANCEMAT_CIRCLE] = 0; // 0x0 or 0xFF
data->button[CELL_PAD_PCLASS_BTN_OFFSET_DANCEMAT_CROSS] = 0; // 0x0 or 0xFF
data->button[CELL_PAD_PCLASS_BTN_OFFSET_DANCEMAT_TRIANGLE] = 0; // 0x0 or 0xFF
data->button[CELL_PAD_PCLASS_BTN_OFFSET_DANCEMAT_SQUARE] = 0; // 0x0 or 0xFF
data->button[CELL_PAD_PCLASS_BTN_OFFSET_DANCEMAT_RIGHT] = 0; // 0x0 or 0xFF
data->button[CELL_PAD_PCLASS_BTN_OFFSET_DANCEMAT_LEFT] = 0; // 0x0 or 0xFF
data->button[CELL_PAD_PCLASS_BTN_OFFSET_DANCEMAT_UP] = 0; // 0x0 or 0xFF
data->button[CELL_PAD_PCLASS_BTN_OFFSET_DANCEMAT_DOWN] = 0; // 0x0 or 0xFF
break;
}
}
}
error_code cellPadGetData(u32 port_no, vm::ptr<CellPadData> data)
{
cellPad.trace("cellPadGetData(port_no=%d, data=*0x%x)", port_no, data);
std::lock_guard lock(pad::g_pad_mutex);
auto& config = g_fxo->get<pad_info>();
if (!config.max_connect)
return CELL_PAD_ERROR_UNINITIALIZED;
if (port_no >= CELL_MAX_PADS || !data)
return CELL_PAD_ERROR_INVALID_PARAMETER;
if (port_no >= config.get_max_connect())
return CELL_PAD_ERROR_NO_DEVICE;
const auto handler = pad::get_current_handler();
const auto& pads = handler->GetPads();
const auto& pad = pads[port_no];
if (pad->is_fake_pad || !config.is_reportedly_connected(port_no) || !(pad->m_port_status & CELL_PAD_STATUS_CONNECTED))
return not_an_error(CELL_PAD_ERROR_NO_DEVICE);
pad_get_data(port_no, data.get_ptr());
if (g_cfg.io.debug_overlay && !g_cfg.video.overlay && port_no == 0)
{
show_debug_overlay(*data, *pad, config);
}
return CELL_OK;
}
error_code cellPadPeriphGetInfo(vm::ptr<CellPadPeriphInfo> info)
{
cellPad.trace("cellPadPeriphGetInfo(info=*0x%x)", info);
std::lock_guard lock(pad::g_pad_mutex);
auto& config = g_fxo->get<pad_info>();
if (!config.max_connect)
return CELL_PAD_ERROR_UNINITIALIZED;
if (!info)
return CELL_PAD_ERROR_INVALID_PARAMETER;
const auto handler = pad::get_current_handler();
const PadInfo& rinfo = handler->GetInfo();
std::memset(info.get_ptr(), 0, sizeof(CellPadPeriphInfo));
info->max_connect = config.max_connect;
info->system_info = rinfo.system_info;
u32 now_connect = 0;
for (u32 i = 0; i < config.get_max_connect(); ++i)
{
pad_data_internal& reported_info = config.reported_info[i];
info->port_status[i] = reported_info.port_status;
info->port_setting[i] = config.port_setting[i];
reported_info.port_status &= ~CELL_PAD_STATUS_ASSIGN_CHANGES;
if (~reported_info.port_status & CELL_PAD_STATUS_CONNECTED)
{
continue;
}
info->device_capability[i] = reported_info.device_capability;
info->device_type[i] = reported_info.device_type;
info->pclass_type[i] = reported_info.pclass_type;
info->pclass_profile[i] = reported_info.pclass_profile;
now_connect++;
}
info->now_connect = now_connect;
return CELL_OK;
}
error_code cellPadPeriphGetData(u32 port_no, vm::ptr<CellPadPeriphData> data)
{
cellPad.trace("cellPadPeriphGetData(port_no=%d, data=*0x%x)", port_no, data);
std::lock_guard lock(pad::g_pad_mutex);
auto& config = g_fxo->get<pad_info>();
if (!config.max_connect)
return CELL_PAD_ERROR_UNINITIALIZED;
// port_no can only be 0-6 in this function
if (port_no >= CELL_PAD_MAX_PORT_NUM || !data)
return CELL_PAD_ERROR_INVALID_PARAMETER;
if (port_no >= config.get_max_connect())
return CELL_PAD_ERROR_NO_DEVICE;
const auto handler = pad::get_current_handler();
const auto& pads = handler->GetPads();
const auto& pad = pads[port_no];
if (pad->is_fake_pad || !config.is_reportedly_connected(port_no) || !(pad->m_port_status & CELL_PAD_STATUS_CONNECTED))
return not_an_error(CELL_PAD_ERROR_NO_DEVICE);
pad_get_data(port_no, &data->cellpad_data, true);
data->pclass_type = pad->m_class_type;
data->pclass_profile = pad->m_class_profile;
return CELL_OK;
}
error_code cellPadGetRawData(u32 port_no, vm::ptr<CellPadData> data)
{
cellPad.todo("cellPadGetRawData(port_no=%d, data=*0x%x)", port_no, data);
std::lock_guard lock(pad::g_pad_mutex);
auto& config = g_fxo->get<pad_info>();
if (!config.max_connect)
return CELL_PAD_ERROR_UNINITIALIZED;
if (port_no >= CELL_MAX_PADS || !data)
return CELL_PAD_ERROR_INVALID_PARAMETER;
if (port_no >= config.get_max_connect())
return CELL_PAD_ERROR_NO_DEVICE;
const auto handler = pad::get_current_handler();
const auto& pads = handler->GetPads();
const auto& pad = pads[port_no];
if (pad->is_fake_pad || !config.is_reportedly_connected(port_no) || !(pad->m_port_status & CELL_PAD_STATUS_CONNECTED))
return not_an_error(CELL_PAD_ERROR_NO_DEVICE);
// ?
return CELL_OK;
}
error_code cellPadGetDataExtra(u32 port_no, vm::ptr<u32> device_type, vm::ptr<CellPadData> data)
{
cellPad.trace("cellPadGetDataExtra(port_no=%d, device_type=*0x%x, data=*0x%x)", port_no, device_type, data);
// TODO: This is used just to get data from a BD/CEC remote,
// but if the port isnt a remote, device type is set to CELL_PAD_DEV_TYPE_STANDARD and just regular cellPadGetData is returned
if (auto err = cellPadGetData(port_no, data))
{
return err;
}
if (device_type) // no error is returned on NULL
{
*device_type = CELL_PAD_DEV_TYPE_STANDARD;
}
// Set BD data
data->button[24] = 0x0;
data->button[25] = 0x0;
return CELL_OK;
}
error_code cellPadSetActDirect(u32 port_no, vm::ptr<CellPadActParam> param)
{
cellPad.trace("cellPadSetActDirect(port_no=%d, param=*0x%x)", port_no, param);
std::lock_guard lock(pad::g_pad_mutex);
auto& config = g_fxo->get<pad_info>();
if (!config.max_connect)
return CELL_PAD_ERROR_UNINITIALIZED;
if (port_no >= CELL_MAX_PADS || !param)
return CELL_PAD_ERROR_INVALID_PARAMETER;
// Note: signed check unlike the usual unsigned check
if (static_cast<s32>(g_ps3_process_info.sdk_ver) > 0x1FFFFF)
{
// make sure reserved bits are 0
for (int i = 0; i < 6; i++)
{
if (param->reserved[i])
return CELL_PAD_ERROR_INVALID_PARAMETER;
}
}
if (port_no >= config.get_max_connect())
return CELL_PAD_ERROR_NO_DEVICE;
const auto handler = pad::get_current_handler();
const auto& pads = handler->GetPads();
const auto& pad = pads[port_no];
if (pad->is_fake_pad || !config.is_reportedly_connected(port_no) || !(pad->m_port_status & CELL_PAD_STATUS_CONNECTED))
return not_an_error(CELL_PAD_ERROR_NO_DEVICE);
// TODO: find out if this is checked here or later or at all
if (!(pad->m_device_capability & CELL_PAD_CAPABILITY_ACTUATOR))
return CELL_PAD_ERROR_UNSUPPORTED_GAMEPAD;
handler->SetRumble(port_no, param->motor[1], param->motor[0] > 0);
return CELL_OK;
}
error_code cellPadGetInfo(vm::ptr<CellPadInfo> info)
{
cellPad.trace("cellPadGetInfo(info=*0x%x)", info);
std::lock_guard lock(pad::g_pad_mutex);
auto& config = g_fxo->get<pad_info>();
if (!config.max_connect)
return CELL_PAD_ERROR_UNINITIALIZED;
if (!info)
return CELL_PAD_ERROR_INVALID_PARAMETER;
std::memset(info.get_ptr(), 0, sizeof(CellPadInfo));
const auto handler = pad::get_current_handler();
const PadInfo& rinfo = handler->GetInfo();
info->max_connect = config.max_connect;
info->system_info = rinfo.system_info;
u32 now_connect = 0;
for (u32 i = 0; i < config.get_max_connect(); ++i)
{
pad_data_internal& reported_info = config.reported_info[i];
reported_info.port_status &= ~CELL_PAD_STATUS_ASSIGN_CHANGES; // TODO: should ASSIGN flags be cleared here?
info->status[i] = reported_info.port_status;
if (~reported_info.port_status & CELL_PAD_STATUS_CONNECTED)
{
continue;
}
info->vendor_id[i] = reported_info.vendor_id;
info->product_id[i] = reported_info.product_id;
now_connect++;
}
info->now_connect = now_connect;
return CELL_OK;
}
error_code cellPadGetInfo2(vm::ptr<CellPadInfo2> info)
{
cellPad.trace("cellPadGetInfo2(info=*0x%x)", info);
std::lock_guard lock(pad::g_pad_mutex);
auto& config = g_fxo->get<pad_info>();
if (!config.max_connect)
return CELL_PAD_ERROR_UNINITIALIZED;
if (!info)
return CELL_PAD_ERROR_INVALID_PARAMETER;
std::memset(info.get_ptr(), 0, sizeof(CellPadInfo2));
const auto handler = pad::get_current_handler();
const PadInfo& rinfo = handler->GetInfo();
info->max_connect = config.get_max_connect(); // Here it is forcibly clamped
info->system_info = rinfo.system_info;
u32 now_connect = 0;
const auto& pads = handler->GetPads();
for (u32 i = 0; i < config.get_max_connect(); ++i)
{
pad_data_internal& reported_info = config.reported_info[i];
info->port_status[i] = reported_info.port_status;
info->port_setting[i] = config.port_setting[i];
reported_info.port_status &= ~CELL_PAD_STATUS_ASSIGN_CHANGES;
if (~reported_info.port_status & CELL_PAD_STATUS_CONNECTED)
{
continue;
}
info->device_capability[i] = pads[i]->m_device_capability;
info->device_type[i] = pads[i]->m_device_type;
now_connect++;
}
info->now_connect = now_connect;
return CELL_OK;
}
error_code cellPadGetCapabilityInfo(u32 port_no, vm::ptr<CellPadCapabilityInfo> info)
{
cellPad.trace("cellPadGetCapabilityInfo(port_no=%d, data_addr:=0x%x)", port_no, info.addr());
std::lock_guard lock(pad::g_pad_mutex);
auto& config = g_fxo->get<pad_info>();
if (!config.max_connect)
return CELL_PAD_ERROR_UNINITIALIZED;
if (port_no >= CELL_MAX_PADS || !info)
return CELL_PAD_ERROR_INVALID_PARAMETER;
if (port_no >= config.get_max_connect())
return CELL_PAD_ERROR_NO_DEVICE;
const auto handler = pad::get_current_handler();
const auto& pads = handler->GetPads();
const auto& pad = pads[port_no];
if (pad->is_fake_pad || !config.is_reportedly_connected(port_no) || !(pad->m_port_status & CELL_PAD_STATUS_CONNECTED))
return not_an_error(CELL_PAD_ERROR_NO_DEVICE);
// Should return the same as device capability mask, psl1ght has it backwards in pad->h
memset(info->info, 0, CELL_PAD_MAX_CAPABILITY_INFO * sizeof(u32));
info->info[0] = pad->m_device_capability;
return CELL_OK;
}
error_code cellPadSetPortSetting(u32 port_no, u32 port_setting)
{
cellPad.trace("cellPadSetPortSetting(port_no=%d, port_setting=0x%x)", port_no, port_setting);
std::lock_guard lock(pad::g_pad_mutex);
auto& config = g_fxo->get<pad_info>();
if (!config.max_connect)
return CELL_PAD_ERROR_UNINITIALIZED;
if (port_no >= CELL_MAX_PADS)
return CELL_PAD_ERROR_INVALID_PARAMETER;
// CELL_PAD_ERROR_NO_DEVICE is not returned in this case.
if (port_no >= CELL_PAD_MAX_PORT_NUM)
return CELL_OK;
config.port_setting[port_no] = port_setting;
// can also return CELL_PAD_ERROR_UNSUPPORTED_GAMEPAD <- Update: seems to be just internal and ignored
return CELL_OK;
}
error_code cellPadInfoPressMode(u32 port_no)
{
cellPad.trace("cellPadInfoPressMode(port_no=%d)", port_no);
std::lock_guard lock(pad::g_pad_mutex);
auto& config = g_fxo->get<pad_info>();
if (!config.max_connect)
return CELL_PAD_ERROR_UNINITIALIZED;
if (port_no >= CELL_MAX_PADS)
return CELL_PAD_ERROR_INVALID_PARAMETER;
if (port_no >= config.get_max_connect())
return CELL_PAD_ERROR_NO_DEVICE;
const auto handler = pad::get_current_handler();
const auto& pads = handler->GetPads();
const auto& pad = pads[port_no];
if (pad->is_fake_pad || !config.is_reportedly_connected(port_no) || !(pad->m_port_status & CELL_PAD_STATUS_CONNECTED))
return not_an_error(CELL_PAD_ERROR_NO_DEVICE);
return not_an_error((pad->m_device_capability & CELL_PAD_CAPABILITY_PRESS_MODE) ? 1 : 0);
}
error_code cellPadInfoSensorMode(u32 port_no)
{
cellPad.trace("cellPadInfoSensorMode(port_no=%d)", port_no);
std::lock_guard lock(pad::g_pad_mutex);
auto& config = g_fxo->get<pad_info>();
if (!config.max_connect)
return CELL_PAD_ERROR_UNINITIALIZED;
if (port_no >= CELL_MAX_PADS)
return CELL_PAD_ERROR_INVALID_PARAMETER;
if (port_no >= config.get_max_connect())
return CELL_PAD_ERROR_NO_DEVICE;
const auto handler = pad::get_current_handler();
const auto& pads = handler->GetPads();
const auto& pad = pads[port_no];
if (pad->is_fake_pad || !config.is_reportedly_connected(port_no) || !(pad->m_port_status & CELL_PAD_STATUS_CONNECTED))
return not_an_error(CELL_PAD_ERROR_NO_DEVICE);
return not_an_error((pad->m_device_capability & CELL_PAD_CAPABILITY_SENSOR_MODE) ? 1 : 0);
}
error_code cellPadSetPressMode(u32 port_no, u32 mode)
{
cellPad.trace("cellPadSetPressMode(port_no=%d, mode=%d)", port_no, mode);
std::lock_guard lock(pad::g_pad_mutex);
auto& config = g_fxo->get<pad_info>();
if (!config.max_connect)
return CELL_PAD_ERROR_UNINITIALIZED;
if (port_no >= CELL_PAD_MAX_PORT_NUM)
return CELL_PAD_ERROR_INVALID_PARAMETER;
// CELL_PAD_ERROR_NO_DEVICE is not returned in this case.
if (port_no >= CELL_PAD_MAX_PORT_NUM)
return CELL_OK;
const auto handler = pad::get_current_handler();
const auto& pads = handler->GetPads();
const auto& pad = pads[port_no];
// TODO: find out if this is checked here or later or at all
if (!(pad->m_device_capability & CELL_PAD_CAPABILITY_PRESS_MODE))
return CELL_PAD_ERROR_UNSUPPORTED_GAMEPAD;
if (mode)
config.port_setting[port_no] |= CELL_PAD_SETTING_PRESS_ON;
else
config.port_setting[port_no] &= ~CELL_PAD_SETTING_PRESS_ON;
return CELL_OK;
}
error_code cellPadSetSensorMode(u32 port_no, u32 mode)
{
cellPad.trace("cellPadSetSensorMode(port_no=%d, mode=%d)", port_no, mode);
std::lock_guard lock(pad::g_pad_mutex);
auto& config = g_fxo->get<pad_info>();
if (!config.max_connect)
return CELL_PAD_ERROR_UNINITIALIZED;
if (port_no >= CELL_MAX_PADS)
return CELL_PAD_ERROR_INVALID_PARAMETER;
// CELL_PAD_ERROR_NO_DEVICE is not returned in this case.
if (port_no >= CELL_PAD_MAX_PORT_NUM)
return CELL_OK;
const auto handler = pad::get_current_handler();
const auto& pads = handler->GetPads();
const auto& pad = pads[port_no];
// TODO: find out if this is checked here or later or at all
if (!(pad->m_device_capability & CELL_PAD_CAPABILITY_SENSOR_MODE))
return CELL_PAD_ERROR_UNSUPPORTED_GAMEPAD;
if (mode)
config.port_setting[port_no] |= CELL_PAD_SETTING_SENSOR_ON;
else
config.port_setting[port_no] &= ~CELL_PAD_SETTING_SENSOR_ON;
return CELL_OK;
}
error_code cellPadLddRegisterController()
{
cellPad.warning("cellPadLddRegisterController()");
std::lock_guard lock(pad::g_pad_mutex);
auto& config = g_fxo->get<pad_info>();
if (!config.max_connect)
return CELL_PAD_ERROR_UNINITIALIZED;
const auto handler = pad::get_current_handler();
const s32 handle = handler->AddLddPad();
if (handle < 0)
return CELL_PAD_ERROR_TOO_MANY_DEVICES;
config.port_setting[handle] = 0;
cellPad_NotifyStateChange(handle, CELL_PAD_STATUS_CONNECTED, false);
return not_an_error(handle);
}
error_code cellPadLddDataInsert(s32 handle, vm::ptr<CellPadData> data)
{
cellPad.trace("cellPadLddDataInsert(handle=%d, data=*0x%x)", handle, data);
std::lock_guard lock(pad::g_pad_mutex);
auto& config = g_fxo->get<pad_info>();
if (!config.max_connect)
return CELL_PAD_ERROR_UNINITIALIZED;
const auto handler = pad::get_current_handler();
auto& pads = handler->GetPads();
if (handle < 0 || static_cast<u32>(handle) >= pads.size() || !data) // data == NULL stalls on decr
return CELL_PAD_ERROR_INVALID_PARAMETER;
if (!pads[handle]->ldd)
return CELL_PAD_ERROR_NO_DEVICE;
pads[handle]->ldd_data = *data;
return CELL_OK;
}
error_code cellPadLddGetPortNo(s32 handle)
{
cellPad.trace("cellPadLddGetPortNo(handle=%d)", handle);
std::lock_guard lock(pad::g_pad_mutex);
auto& config = g_fxo->get<pad_info>();
if (!config.max_connect)
return CELL_PAD_ERROR_UNINITIALIZED;
const auto handler = pad::get_current_handler();
auto& pads = handler->GetPads();
if (handle < 0 || static_cast<u32>(handle) >= pads.size())
return CELL_PAD_ERROR_INVALID_PARAMETER;
if (!pads[handle]->ldd)
return CELL_PAD_ERROR_FATAL; // might be incorrect
// Other possible return values: CELL_PAD_ERROR_EBUSY, CELL_EBUSY
return not_an_error(handle); // handle is port
}
error_code cellPadLddUnregisterController(s32 handle)
{
cellPad.warning("cellPadLddUnregisterController(handle=%d)", handle);
std::lock_guard lock(pad::g_pad_mutex);
auto& config = g_fxo->get<pad_info>();
if (!config.max_connect)
return CELL_PAD_ERROR_UNINITIALIZED;
const auto handler = pad::get_current_handler();
const auto& pads = handler->GetPads();
if (handle < 0 || static_cast<u32>(handle) >= pads.size())
return CELL_PAD_ERROR_INVALID_PARAMETER;
if (!pads[handle]->ldd)
return CELL_PAD_ERROR_NO_DEVICE;
handler->UnregisterLddPad(handle);
cellPad_NotifyStateChange(handle, CELL_PAD_STATUS_DISCONNECTED, false);
return CELL_OK;
}
error_code cellPadFilterIIRInit(vm::ptr<CellPadFilterIIRSos> pSos, s32 cutoff)
{
cellPad.todo("cellPadFilterIIRInit(pSos=*0x%x, cutoff=%d)", pSos, cutoff);
if (!pSos) // TODO: does this check for cutoff > 2 ?
{
return CELL_PADFILTER_ERROR_INVALID_PARAMETER;
}
return CELL_OK;
}
u32 cellPadFilterIIRFilter(vm::ptr<CellPadFilterIIRSos> pSos, u32 filterIn)
{
cellPad.todo("cellPadFilterIIRFilter(pSos=*0x%x, filterIn=%d)", pSos, filterIn);
// TODO: apply filter
return std::clamp(filterIn, 0u, 1023u);
}
s32 sys_io_3733EA3C(u32 port_no, vm::ptr<u32> device_type, vm::ptr<CellPadData> data)
{
// Used by the ps1 emulator built into the firmware
// Seems to call the same function that getdataextra does
cellPad.trace("sys_io_3733EA3C(port_no=%d, device_type=*0x%x, data=*0x%x)", port_no, device_type, data);
return cellPadGetDataExtra(port_no, device_type, data);
}
void cellPad_init()
{
REG_FUNC(sys_io, cellPadInit);
REG_FUNC(sys_io, cellPadEnd);
REG_FUNC(sys_io, cellPadClearBuf);
REG_FUNC(sys_io, cellPadGetData);
REG_FUNC(sys_io, cellPadGetRawData); //
REG_FUNC(sys_io, cellPadGetDataExtra);
REG_FUNC(sys_io, cellPadSetActDirect);
REG_FUNC(sys_io, cellPadGetInfo); //
REG_FUNC(sys_io, cellPadGetInfo2);
REG_FUNC(sys_io, cellPadPeriphGetInfo);
REG_FUNC(sys_io, cellPadPeriphGetData);
REG_FUNC(sys_io, cellPadSetPortSetting);
REG_FUNC(sys_io, cellPadInfoPressMode); //
REG_FUNC(sys_io, cellPadInfoSensorMode); //
REG_FUNC(sys_io, cellPadSetPressMode); //
REG_FUNC(sys_io, cellPadSetSensorMode); //
REG_FUNC(sys_io, cellPadGetCapabilityInfo); //
REG_FUNC(sys_io, cellPadLddRegisterController);
REG_FUNC(sys_io, cellPadLddDataInsert);
REG_FUNC(sys_io, cellPadLddGetPortNo);
REG_FUNC(sys_io, cellPadLddUnregisterController);
REG_FUNC(sys_io, cellPadFilterIIRInit);
REG_FUNC(sys_io, cellPadFilterIIRFilter);
REG_FNID(sys_io, 0x3733EA3C, sys_io_3733EA3C);
}
| 43,000
|
C++
|
.cpp
| 1,049
| 38.13918
| 167
| 0.695886
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
5,255
|
cellPamf.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellPamf.cpp
|
#include "stdafx.h"
#include "Emu/System.h"
#include "Emu/Cell/PPUModule.h"
#include <bitset>
#include "cellPamf.h"
const std::function<bool()> SQUEUE_ALWAYS_EXIT = []() { return true; };
const std::function<bool()> SQUEUE_NEVER_EXIT = []() { return false; };
bool squeue_test_exit()
{
return Emu.IsStopped();
}
LOG_CHANNEL(cellPamf);
template<>
void fmt_class_string<CellPamfError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_PAMF_ERROR_STREAM_NOT_FOUND);
STR_CASE(CELL_PAMF_ERROR_INVALID_PAMF);
STR_CASE(CELL_PAMF_ERROR_INVALID_ARG);
STR_CASE(CELL_PAMF_ERROR_UNKNOWN_TYPE);
STR_CASE(CELL_PAMF_ERROR_UNSUPPORTED_VERSION);
STR_CASE(CELL_PAMF_ERROR_UNKNOWN_STREAM);
STR_CASE(CELL_PAMF_ERROR_EP_NOT_FOUND);
STR_CASE(CELL_PAMF_ERROR_NOT_AVAILABLE);
}
return unknown;
});
}
error_code pamfVerifyMagicAndVersion(vm::cptr<PamfHeader> pAddr, vm::ptr<CellPamfReader> pSelf)
{
ensure(!!pAddr); // Not checked on LLE
if (pAddr->magic != std::bit_cast<be_t<u32>>("PAMF"_u32))
{
return CELL_PAMF_ERROR_UNKNOWN_TYPE;
}
if (pSelf)
{
pSelf->isPsmf = false;
}
be_t<u16> version;
if (pAddr->version == std::bit_cast<be_t<u32>>("0040"_u32))
{
version = 40;
}
else if (pAddr->version == std::bit_cast<be_t<u32>>("0041"_u32))
{
version = 41;
}
else
{
return CELL_PAMF_ERROR_UNSUPPORTED_VERSION;
}
if (pSelf)
{
pSelf->version = version;
}
return CELL_OK;
}
error_code pamfGetHeaderAndDataSize(vm::cptr<PamfHeader> pAddr, u64 fileSize, vm::ptr<u64> headerSize, vm::ptr<u64> dataSize)
{
ensure(!!pAddr); // Not checked on LLE
if (error_code ret = pamfVerifyMagicAndVersion(pAddr, vm::null); ret != CELL_OK)
{
return ret;
}
const u64 header_size = pAddr->header_size * 0x800ull;
const u64 data_size = pAddr->data_size * 0x800ull;
if (header_size == 0 || (fileSize != 0 && header_size + data_size != fileSize))
{
return CELL_PAMF_ERROR_INVALID_PAMF;
}
if (headerSize)
{
*headerSize = header_size;
}
if (dataSize)
{
*dataSize = data_size;
}
return CELL_OK;
}
error_code pamfTypeChannelToStream(u8 type, u8 ch, u8* stream_coding_type, u8* stream_id, u8* private_stream_id)
{
// This function breaks if ch is greater than 15, LLE doesn't check for this
ensure(ch < 16);
u8 _stream_coding_type;
u8 _stream_id;
u8 _private_stream_id;
switch (type)
{
case CELL_PAMF_STREAM_TYPE_AVC:
{
_stream_coding_type = PAMF_STREAM_CODING_TYPE_AVC;
_stream_id = 0xe0 | ch;
_private_stream_id = 0;
break;
}
case CELL_PAMF_STREAM_TYPE_M2V:
{
_stream_coding_type = PAMF_STREAM_CODING_TYPE_M2V;
_stream_id = 0xe0 | ch;
_private_stream_id = 0;
break;
}
case CELL_PAMF_STREAM_TYPE_ATRAC3PLUS:
{
_stream_coding_type = PAMF_STREAM_CODING_TYPE_ATRAC3PLUS;
_stream_id = 0xbd;
_private_stream_id = ch;
break;
}
case CELL_PAMF_STREAM_TYPE_PAMF_LPCM:
{
_stream_coding_type = PAMF_STREAM_CODING_TYPE_PAMF_LPCM;
_stream_id = 0xbd;
_private_stream_id = 0x40 | ch;
break;
}
case CELL_PAMF_STREAM_TYPE_AC3:
{
_stream_coding_type = PAMF_STREAM_CODING_TYPE_AC3;
_stream_id = 0xbd;
_private_stream_id = 0x30 | ch;
break;
}
case CELL_PAMF_STREAM_TYPE_USER_DATA:
{
_stream_coding_type = PAMF_STREAM_CODING_TYPE_USER_DATA;
_stream_id = 0xbd;
_private_stream_id = 0x20 | ch;
break;
}
case CELL_PAMF_STREAM_TYPE_PSMF_AVC:
{
_stream_coding_type = PAMF_STREAM_CODING_TYPE_PSMF;
_stream_id = 0xe0 | ch;
_private_stream_id = 0;
break;
}
case CELL_PAMF_STREAM_TYPE_PSMF_ATRAC3PLUS:
{
_stream_coding_type = PAMF_STREAM_CODING_TYPE_PSMF;
_stream_id = 0xbd;
_private_stream_id = ch;
break;
}
case CELL_PAMF_STREAM_TYPE_PSMF_LPCM:
{
_stream_coding_type = PAMF_STREAM_CODING_TYPE_PSMF;
_stream_id = 0xbd;
_private_stream_id = 0x10 | ch;
break;
}
case CELL_PAMF_STREAM_TYPE_PSMF_USER_DATA:
{
_stream_coding_type = PAMF_STREAM_CODING_TYPE_PSMF;
_stream_id = 0xbd;
_private_stream_id = 0x20 | ch;
break;
}
default:
{
cellPamf.error("pamfTypeChannelToStream(): unknown type %d", type);
return CELL_PAMF_ERROR_INVALID_ARG;
}
}
if (stream_coding_type)
{
*stream_coding_type = _stream_coding_type;
}
if (stream_id)
{
*stream_id = _stream_id;
}
if (private_stream_id)
{
*private_stream_id = _private_stream_id;
}
return CELL_OK;
}
error_code pamfStreamToTypeChannel(u8 stream_coding_type, u8 stream_id, u8 private_stream_id, vm::ptr<u8> type, vm::ptr<u8> ch)
{
u8 _type;
u8 _ch;
switch (stream_coding_type)
{
case PAMF_STREAM_CODING_TYPE_AVC:
_type = CELL_PAMF_STREAM_TYPE_AVC;
_ch = stream_id & 0x0f;
break;
case PAMF_STREAM_CODING_TYPE_M2V:
_type = CELL_PAMF_STREAM_TYPE_M2V;
_ch = stream_id & 0x0f;
break;
case PAMF_STREAM_CODING_TYPE_ATRAC3PLUS:
_type = CELL_PAMF_STREAM_TYPE_ATRAC3PLUS;
_ch = private_stream_id & 0x0f;
break;
case PAMF_STREAM_CODING_TYPE_PAMF_LPCM:
_type = CELL_PAMF_STREAM_TYPE_PAMF_LPCM;
_ch = private_stream_id & 0x0f;
break;
case PAMF_STREAM_CODING_TYPE_AC3:
_type = CELL_PAMF_STREAM_TYPE_AC3;
_ch = private_stream_id & 0x0f;
break;
case PAMF_STREAM_CODING_TYPE_USER_DATA:
_type = CELL_PAMF_STREAM_TYPE_USER_DATA;
_ch = private_stream_id & 0x0f;
break;
case PAMF_STREAM_CODING_TYPE_PSMF:
if ((stream_id & 0xf0) == 0xe0)
{
_type = CELL_PAMF_STREAM_TYPE_PSMF_AVC;
_ch = stream_id & 0x0f;
if (private_stream_id != 0)
{
return CELL_PAMF_ERROR_STREAM_NOT_FOUND;
}
}
else if (stream_id == 0xbd)
{
_ch = private_stream_id & 0x0f;
switch (private_stream_id & 0xf0)
{
case 0x00: _type = CELL_PAMF_STREAM_TYPE_PSMF_ATRAC3PLUS; break;
case 0x10: _type = CELL_PAMF_STREAM_TYPE_PSMF_LPCM; break;
case 0x20: _type = CELL_PAMF_STREAM_TYPE_PSMF_LPCM; break; // LLE doesn't use CELL_PAMF_STREAM_TYPE_PSMF_USER_DATA for some reason
default: return CELL_PAMF_ERROR_STREAM_NOT_FOUND;
}
}
else
{
return CELL_PAMF_ERROR_STREAM_NOT_FOUND;
}
break;
default:
cellPamf.error("pamfStreamToTypeChannel(): unknown stream_coding_type 0x%02x", stream_coding_type);
return CELL_PAMF_ERROR_STREAM_NOT_FOUND;
}
if (type)
{
*type = _type;
}
if (ch)
{
*ch = _ch;
}
return CELL_OK;
}
void pamfEpUnpack(vm::cptr<PamfEpHeader> ep_packed, vm::ptr<CellPamfEp> ep)
{
ensure(!!ep_packed && !!ep); // Not checked on LLE
ep->indexN = (ep_packed->value0 >> 14) + 1;
ep->nThRefPictureOffset = ((ep_packed->value0 & 0x1fff) * 0x800) + 0x800;
ep->pts.upper = ep_packed->pts_high;
ep->pts.lower = ep_packed->pts_low;
ep->rpnOffset = ep_packed->rpnOffset * 0x800ull;
}
void psmfEpUnpack(vm::cptr<PsmfEpHeader> ep_packed, vm::ptr<CellPamfEp> ep)
{
ensure(!!ep_packed && !!ep); // Not checked on LLE
ep->indexN = (ep_packed->value0 >> 14) + 1;
ep->nThRefPictureOffset = ((ep_packed->value0 & 0xffe) * 0x400) + 0x800;
ep->pts.upper = ep_packed->value0 & 1;
ep->pts.lower = ep_packed->pts_low;
ep->rpnOffset = ep_packed->rpnOffset * 0x800ull;
}
bool pamfIsSameStreamType(u8 type, u8 requested_type)
{
switch (requested_type)
{
case CELL_PAMF_STREAM_TYPE_VIDEO: return type == CELL_PAMF_STREAM_TYPE_AVC || type == CELL_PAMF_STREAM_TYPE_M2V;
case CELL_PAMF_STREAM_TYPE_AUDIO: return type == CELL_PAMF_STREAM_TYPE_ATRAC3PLUS || type == CELL_PAMF_STREAM_TYPE_AC3 || type == CELL_PAMF_STREAM_TYPE_PAMF_LPCM;
case CELL_PAMF_STREAM_TYPE_UNK: return type == CELL_PAMF_STREAM_TYPE_PAMF_LPCM || type == CELL_PAMF_STREAM_TYPE_PSMF_ATRAC3PLUS; // ??? no idea what this is for
default: return requested_type == type;
}
}
error_code pamfVerify(vm::cptr<PamfHeader> pAddr, u64 fileSize, vm::ptr<CellPamfReader> pSelf, u32 attribute)
{
ensure(!!pAddr); // Not checked on LLE
if (error_code ret = pamfVerifyMagicAndVersion(pAddr, pSelf); ret != CELL_OK)
{
return ret;
}
const u64 header_size = pAddr->header_size * 0x800ull;
const u64 data_size = pAddr->data_size * 0x800ull;
// Header size
if (header_size == 0)
{
return { CELL_PAMF_ERROR_INVALID_PAMF, "pamfVerify() failed: invalid header_size" };
}
if (pSelf)
{
pSelf->headerSize = header_size;
pSelf->dataSize = data_size;
}
// Data size
if (fileSize != 0 && header_size + data_size != fileSize)
{
return { CELL_PAMF_ERROR_INVALID_PAMF, "pamfVerify() failed: fileSize isn't equal header_size + data_size" };
}
const u32 psmf_marks_offset = pAddr->psmf_marks_offset;
const u32 psmf_marks_size = pAddr->psmf_marks_size;
const u32 unk_offset = pAddr->unk_offset;
const u32 unk_size = pAddr->unk_size;
// PsmfMarks
if (psmf_marks_offset == 0)
{
if (psmf_marks_size != 0)
{
return { CELL_PAMF_ERROR_INVALID_PAMF, "pamfVerify() failed: psmf_marks_offset is zero but psmf_marks_size is not zero" };
}
}
else
{
if (psmf_marks_size == 0)
{
return { CELL_PAMF_ERROR_INVALID_PAMF, "pamfVerify() failed: psmf_marks_offset is set but psmf_marks_size is zero" };
}
if (header_size < static_cast<u64>(psmf_marks_offset) + psmf_marks_size)
{
return { CELL_PAMF_ERROR_INVALID_PAMF, "pamfVerify() failed: header_size is less than psmf_marks_offset + psmf_marks_size" };
}
}
if (unk_offset == 0)
{
if (unk_size != 0)
{
return { CELL_PAMF_ERROR_INVALID_PAMF, "pamfVerify() failed: unk_offset is zero but unk_size is not zero" };
}
}
else
{
if (unk_size == 0)
{
return { CELL_PAMF_ERROR_INVALID_PAMF, "pamfVerify() failed: unk_offset is set but unk_size is zero" };
}
if (header_size < static_cast<u64>(unk_offset) + unk_size)
{
return { CELL_PAMF_ERROR_INVALID_PAMF, "pamfVerify() failed: header_size is less than unk_offset + unk_size" };
}
}
if (unk_offset < static_cast<u64>(psmf_marks_offset) + psmf_marks_size)
{
return { CELL_PAMF_ERROR_INVALID_PAMF, "pamfVerify() failed: unk_offset is less than psmf_marks_offset + psmf_marks_size" };
}
// Sequence Info
const u32 seq_info_size = pAddr->seq_info.size;
// Sequence info size
if (offsetof(PamfHeader, seq_info) + sizeof(u32) + seq_info_size > header_size)
{
return { CELL_PAMF_ERROR_INVALID_PAMF, "pamfVerify() failed: invalid seq_info_size" };
}
const u64 start_pts = static_cast<u64>(pAddr->seq_info.start_pts_high) << 32 | pAddr->seq_info.start_pts_low;
const u64 end_pts = static_cast<u64>(pAddr->seq_info.end_pts_high) << 32 | pAddr->seq_info.end_pts_low;
// Start and end presentation time stamps
if (end_pts > CODEC_TS_INVALID)
{
return { CELL_PAMF_ERROR_INVALID_PAMF, "pamfVerify() failed: invalid end_pts" };
}
if (start_pts >= end_pts)
{
return { CELL_PAMF_ERROR_INVALID_PAMF, "pamfVerify() failed: invalid start_pts" };
}
// Grouping period count
if (pAddr->seq_info.grouping_period_num != 1)
{
return { CELL_PAMF_ERROR_INVALID_PAMF, "pamfVerify() failed: invalid grouping_period_num" };
}
// Grouping Period
const u32 grouping_period_size = pAddr->seq_info.grouping_periods.size;
// Grouping period size
if (offsetof(PamfHeader, seq_info.grouping_periods) + sizeof(u32) + grouping_period_size > header_size)
{
return { CELL_PAMF_ERROR_INVALID_PAMF, "pamfVerify() failed: invalid grouping_period_size" };
}
const u64 grp_period_start_pts = static_cast<u64>(pAddr->seq_info.grouping_periods.start_pts_high) << 32 | pAddr->seq_info.grouping_periods.start_pts_low;
const u64 grp_period_end_pts = static_cast<u64>(pAddr->seq_info.grouping_periods.start_pts_high) << 32 | pAddr->seq_info.grouping_periods.end_pts_low; // LLE uses start_pts_high due to a bug
// Start and end presentation time stamps
if (grp_period_end_pts > CODEC_TS_INVALID)
{
return { CELL_PAMF_ERROR_INVALID_PAMF, "pamfVerify() failed: invalid grp_period_end_pts" };
}
if (grp_period_start_pts >= grp_period_end_pts)
{
return { CELL_PAMF_ERROR_INVALID_PAMF, "pamfVerify() failed: invalid grp_period_start_pts" };
}
if (grp_period_start_pts != start_pts)
{
return { CELL_PAMF_ERROR_INVALID_PAMF, "pamfVerify() failed: grp_period_start_pts not equal start_pts" };
}
// Group count
if (pAddr->seq_info.grouping_periods.group_num != 1)
{
return { CELL_PAMF_ERROR_INVALID_PAMF, "pamfVerify() failed: invalid group_num" };
}
// Group
const u32 group_size = pAddr->seq_info.grouping_periods.groups.size;
// StreamGroup size
if (offsetof(PamfHeader, seq_info.grouping_periods.groups) + sizeof(u32) + group_size > header_size)
{
return { CELL_PAMF_ERROR_INVALID_PAMF, "pamfVerify() failed: invalid group_size" };
}
const u8 stream_num = pAddr->seq_info.grouping_periods.groups.stream_num;
// Stream count
if (stream_num == 0)
{
return { CELL_PAMF_ERROR_INVALID_PAMF, "pamfVerify() failed: invalid stream_num" };
}
// Streams
const auto streams = &pAddr->seq_info.grouping_periods.groups.streams;
std::bitset<16> channels_used[6]{};
u32 end_of_streams_addr = 0;
u32 next_ep_table_addr = 0;
for (u8 stream_idx = 0; stream_idx < stream_num; stream_idx++)
{
vm::var<u8> type;
vm::var<u8> ch;
// Stream coding type and IDs
if (pamfStreamToTypeChannel(streams[stream_idx].stream_coding_type, streams[stream_idx].stream_id, streams[stream_idx].private_stream_id, type, ch) != CELL_OK)
{
return CELL_PAMF_ERROR_UNKNOWN_STREAM;
}
// Every channel may only be used once per type
if (channels_used[*type].test(*ch))
{
return { CELL_PAMF_ERROR_INVALID_PAMF, "pamfVerify() failed: invalid channel" };
}
// Mark channel as used
channels_used[*type].set(*ch);
const u32 ep_offset = streams[stream_idx].ep_offset;
const u32 ep_num = streams[stream_idx].ep_num;
// Entry point offset and number
if (ep_num == 0)
{
if (ep_offset != 0)
{
return { CELL_PAMF_ERROR_INVALID_PAMF, "pamfVerify() failed: ep_num is zero but ep_offset is not zero" };
}
}
else
{
if (ep_offset == 0)
{
return { CELL_PAMF_ERROR_INVALID_PAMF, "pamfVerify() failed: invalid ep_offset" };
}
if (ep_offset + ep_num * sizeof(PamfEpHeader) > header_size)
{
return { CELL_PAMF_ERROR_INVALID_PAMF, "pamfVerify() failed: invalid ep_num" };
}
}
// Entry points
// Skip if there are no entry points or if the minimum header attribute is set
if (ep_offset == 0 || attribute & CELL_PAMF_ATTRIBUTE_MINIMUM_HEADER)
{
continue;
}
const auto eps = vm::cptr<PamfEpHeader>::make(pAddr.addr() + ep_offset);
// Entry point tables must be sorted by the stream index to which they belong
// and there mustn't be any gaps between them
if (end_of_streams_addr == 0)
{
end_of_streams_addr = eps.addr();
next_ep_table_addr = end_of_streams_addr;
}
else if (next_ep_table_addr != eps.addr())
{
return { CELL_PAMF_ERROR_INVALID_PAMF, "pamfVerify() failed: invalid ep table address" };
}
u64 previous_rpn_offset = 0;
for (u32 ep_idx = 0; ep_idx < ep_num; ep_idx++)
{
const u64 pts = static_cast<u64>(eps[ep_idx].pts_high) << 32 | eps[ep_idx].pts_low;
// Entry point time stamp
if (pts > CODEC_TS_INVALID)
{
return { CELL_PAMF_ERROR_INVALID_PAMF, "pamfVerify() failed: invalid ep pts" };
}
const u64 rpn_offset = eps[ep_idx].rpnOffset * 0x800ull;
// Entry point rpnOffset
if (rpn_offset > data_size || rpn_offset < previous_rpn_offset)
{
return { CELL_PAMF_ERROR_INVALID_PAMF, "pamfVerify() failed: invalid rpn_offset" };
}
previous_rpn_offset = rpn_offset;
}
next_ep_table_addr += ep_num * sizeof(PamfEpHeader);
}
// This can overflow on LLE, the +4 is necessary on both sides and the left operand needs to be u32
if (group_size + 4 > grouping_period_size - offsetof(PamfGroupingPeriod, groups) + sizeof(u32)
|| grouping_period_size + 4 > seq_info_size - offsetof(PamfSequenceInfo, grouping_periods) + sizeof(u32))
{
return { CELL_PAMF_ERROR_INVALID_PAMF, "pamfVerify() failed: size mismatch" };
}
// Since multiple grouping periods/groups was never implemented, number of streams in SequenceInfo must be equal stream_num in Group
if (pAddr->seq_info.total_stream_num != stream_num)
{
return { CELL_PAMF_ERROR_INVALID_PAMF, "pamfVerify() failed: number of streams mismatch" };
}
// PsmfMarks
// This is probably useless since the official PAMF tools don't support PsmfMarks
if (end_of_streams_addr == 0)
{
if (psmf_marks_offset != 0)
{
end_of_streams_addr = pAddr.addr() + psmf_marks_offset;
}
else if (unk_offset != 0)
{
end_of_streams_addr = pAddr.addr() + unk_offset;
}
}
if (end_of_streams_addr != 0 && pAddr.addr() + offsetof(PamfHeader, seq_info.grouping_periods) + sizeof(u32) + grouping_period_size != end_of_streams_addr)
{
return { CELL_PAMF_ERROR_INVALID_PAMF, "pamfVerify() failed: invalid offset of ep tables or psmf marks" };
}
if (next_ep_table_addr != 0 && psmf_marks_offset == 0)
{
if (unk_offset != 0 && pAddr.addr() + unk_offset != next_ep_table_addr)
{
return { CELL_PAMF_ERROR_INVALID_PAMF, "pamfVerify() failed: invalid unk_offset" };
}
}
else if (next_ep_table_addr != 0 && pAddr.addr() + psmf_marks_offset != next_ep_table_addr)
{
return { CELL_PAMF_ERROR_INVALID_PAMF, "pamfVerify() failed: invalid psmf_marks_offset" };
}
else if (psmf_marks_offset != 0 && !(attribute & CELL_PAMF_ATTRIBUTE_MINIMUM_HEADER))
{
const u32 size = vm::read32(pAddr.addr() + psmf_marks_offset);
if (size + sizeof(u32) != psmf_marks_size)
{
return { CELL_PAMF_ERROR_INVALID_PAMF, "pamfVerify() failed: invalid psmf_marks_size" };
}
const u16 marks_num = vm::read16(pAddr.addr() + psmf_marks_offset + 6); // LLE uses the wrong offset (6 instead of 4)
if (sizeof(u16) + marks_num * 0x28 /*sizeof PsmfMark*/ != size)
{
return { CELL_PAMF_ERROR_INVALID_PAMF, "pamfVerify() failed: invalid marks_num" };
}
// There are more checks in LLE but due to the bug above these would never be executed
}
return CELL_OK;
}
error_code cellPamfGetStreamOffsetAndSize(vm::ptr<PamfHeader> pAddr, u64 fileSize, vm::ptr<u64> pOffset, vm::ptr<u64> pSize);
error_code cellPamfGetHeaderSize(vm::ptr<PamfHeader> pAddr, u64 fileSize, vm::ptr<u64> pSize)
{
cellPamf.notice("cellPamfGetHeaderSize(pAddr=*0x%x, fileSize=0x%llx, pSize=*0x%x)", pAddr, fileSize, pSize);
return cellPamfGetStreamOffsetAndSize(pAddr, fileSize, pSize, vm::null);
}
error_code cellPamfGetHeaderSize2(vm::ptr<PamfHeader> pAddr, u64 fileSize, u32 attribute, vm::ptr<u64> pSize)
{
cellPamf.notice("cellPamfGetHeaderSize2(pAddr=*0x%x, fileSize=0x%llx, attribute=0x%x, pSize=*0x%x)", pAddr, fileSize, attribute, pSize);
const vm::var<u64> header_size;
if (error_code ret = cellPamfGetStreamOffsetAndSize(pAddr, fileSize, header_size, vm::null); ret != CELL_OK)
{
return ret;
}
if (attribute & CELL_PAMF_ATTRIBUTE_MINIMUM_HEADER)
{
if (pAddr->magic != std::bit_cast<be_t<u32>>("PAMF"_u32)) // Already checked in cellPamfGetStreamOffsetAndSize(), should always evaluate to false at this point
{
return CELL_PAMF_ERROR_UNKNOWN_TYPE;
}
const u64 min_header_size = offsetof(PamfHeader, seq_info) + sizeof(u32) + pAddr->seq_info.size; // Size without EP tables
if (min_header_size > *header_size)
{
return CELL_PAMF_ERROR_INVALID_PAMF;
}
*header_size = min_header_size;
}
if (pSize)
{
*pSize = *header_size;
}
return CELL_OK;
}
error_code cellPamfGetStreamOffsetAndSize(vm::ptr<PamfHeader> pAddr, u64 fileSize, vm::ptr<u64> pOffset, vm::ptr<u64> pSize)
{
cellPamf.notice("cellPamfGetStreamOffsetAndSize(pAddr=*0x%x, fileSize=0x%llx, pOffset=*0x%x, pSize=*0x%x)", pAddr, fileSize, pOffset, pSize);
return pamfGetHeaderAndDataSize(pAddr, fileSize, pOffset, pSize);
}
error_code cellPamfVerify(vm::cptr<PamfHeader> pAddr, u64 fileSize)
{
cellPamf.notice("cellPamfVerify(pAddr=*0x%x, fileSize=0x%llx)", pAddr, fileSize);
return pamfVerify(pAddr, fileSize, vm::null, CELL_PAMF_ATTRIBUTE_VERIFY_ON);
}
error_code cellPamfReaderSetStreamWithIndex(vm::ptr<CellPamfReader> pSelf, u8 streamIndex);
error_code cellPamfReaderInitialize(vm::ptr<CellPamfReader> pSelf, vm::cptr<PamfHeader> pAddr, u64 fileSize, u32 attribute)
{
cellPamf.notice("cellPamfReaderInitialize(pSelf=*0x%x, pAddr=*0x%x, fileSize=0x%llx, attribute=0x%x)", pSelf, pAddr, fileSize, attribute);
ensure(!!pSelf); // Not checked on LLE
std::memset(pSelf.get_ptr(), 0, sizeof(CellPamfReader));
pSelf->attribute = attribute;
if (attribute & CELL_PAMF_ATTRIBUTE_VERIFY_ON)
{
if (error_code ret = pamfVerify(pAddr, fileSize, pSelf, attribute); ret != CELL_OK)
{
return ret;
}
}
pSelf->pamf.header = pAddr;
pSelf->pamf.sequenceInfo = pAddr.ptr(&PamfHeader::seq_info);
pSelf->currentGroupingPeriodIndex = -1;
pSelf->currentGroupIndex = -1;
pSelf->currentStreamIndex = -1;
if (pAddr->seq_info.grouping_period_num == 0)
{
return CELL_PAMF_ERROR_INVALID_PAMF;
}
pSelf->currentGroupingPeriodIndex = 0;
pSelf->pamf.currentGroupingPeriod = pSelf->pamf.sequenceInfo.ptr(&PamfSequenceInfo::grouping_periods);
if (pAddr->seq_info.grouping_periods.group_num != 0)
{
pSelf->currentGroupIndex = 0;
pSelf->pamf.currentGroup = pSelf->pamf.currentGroupingPeriod.ptr(&PamfGroupingPeriod::groups);
cellPamfReaderSetStreamWithIndex(pSelf, 0);
}
return CELL_OK;
}
error_code cellPamfReaderGetPresentationStartTime(vm::ptr<CellPamfReader> pSelf, vm::ptr<CellCodecTimeStamp> pTimeStamp)
{
cellPamf.notice("cellPamfReaderGetPresentationStartTime(pSelf=*0x%x, pTimeStamp=*0x%x)", pSelf, pTimeStamp);
// always returns CELL_OK
ensure(!!pSelf && !!pTimeStamp); // Not checked on LLE
if (pSelf->isPsmf)
{
pTimeStamp->upper = pSelf->psmf.sequenceInfo->start_pts_high;
pTimeStamp->lower = pSelf->psmf.sequenceInfo->start_pts_low;
}
else
{
pTimeStamp->upper = pSelf->pamf.sequenceInfo->start_pts_high;
pTimeStamp->lower = pSelf->pamf.sequenceInfo->start_pts_low;
}
return CELL_OK;
}
error_code cellPamfReaderGetPresentationEndTime(vm::ptr<CellPamfReader> pSelf, vm::ptr<CellCodecTimeStamp> pTimeStamp)
{
cellPamf.notice("cellPamfReaderGetPresentationEndTime(pSelf=*0x%x, pTimeStamp=*0x%x)", pSelf, pTimeStamp);
// always returns CELL_OK
ensure(!!pSelf && !!pTimeStamp); // Not checked on LLE
if (pSelf->isPsmf)
{
pTimeStamp->upper = pSelf->psmf.sequenceInfo->end_pts_high;
pTimeStamp->lower = pSelf->psmf.sequenceInfo->end_pts_low;
}
else
{
pTimeStamp->upper = pSelf->pamf.sequenceInfo->end_pts_high;
pTimeStamp->lower = pSelf->pamf.sequenceInfo->end_pts_low;
}
return CELL_OK;
}
u32 cellPamfReaderGetMuxRateBound(vm::ptr<CellPamfReader> pSelf)
{
cellPamf.notice("cellPamfReaderGetMuxRateBound(pSelf=*0x%x)", pSelf);
ensure(!!pSelf); // Not checked on LLE
if (pSelf->isPsmf)
{
return pSelf->psmf.sequenceInfo->mux_rate_bound & 0x003fffff;
}
return pSelf->pamf.sequenceInfo->mux_rate_bound & 0x003fffff;
}
u8 cellPamfReaderGetNumberOfStreams(vm::ptr<CellPamfReader> pSelf)
{
cellPamf.notice("cellPamfReaderGetNumberOfStreams(pSelf=*0x%x)", pSelf);
ensure(!!pSelf); // Not checked on LLE
return pSelf->pamf.currentGroup->stream_num;
}
u8 cellPamfReaderGetNumberOfSpecificStreams(vm::ptr<CellPamfReader> pSelf, u8 streamType)
{
cellPamf.notice("cellPamfReaderGetNumberOfSpecificStreams(pSelf=*0x%x, streamType=%d)", pSelf, streamType);
ensure(!!pSelf); // Not checked on LLE
const vm::var<u8> type;
u8 found = 0;
if (pSelf->isPsmf)
{
const auto streams = pSelf->psmf.currentGroup.ptr(&PsmfGroup::streams);
for (u8 i = 0; i < pSelf->psmf.currentGroup->stream_num; i++)
{
if (pamfStreamToTypeChannel(PAMF_STREAM_CODING_TYPE_PSMF, streams[i].stream_id, streams[i].private_stream_id, type, vm::null) == CELL_OK)
{
found += pamfIsSameStreamType(*type, streamType);
}
}
}
else
{
const auto streams = pSelf->pamf.currentGroup.ptr(&PamfGroup::streams);
for (u8 i = 0; i < pSelf->pamf.currentGroup->stream_num; i++)
{
if (pamfStreamToTypeChannel(streams[i].stream_coding_type, streams[i].stream_id, streams[i].private_stream_id, type, vm::null) == CELL_OK)
{
found += pamfIsSameStreamType(*type, streamType);
}
}
}
return found;
}
error_code cellPamfReaderSetStreamWithIndex(vm::ptr<CellPamfReader> pSelf, u8 streamIndex)
{
cellPamf.notice("cellPamfReaderSetStreamWithIndex(pSelf=*0x%x, streamIndex=%d)", pSelf, streamIndex);
ensure(!!pSelf); // Not checked on LLE
if (streamIndex >= pSelf->pamf.currentGroup->stream_num)
{
return CELL_PAMF_ERROR_INVALID_ARG;
}
pSelf->currentStreamIndex = streamIndex;
if (pSelf->isPsmf)
{
pSelf->psmf.currentStream = pSelf->psmf.currentGroup.ptr(&PsmfGroup::streams) + streamIndex;
}
else
{
pSelf->pamf.currentStream = pSelf->pamf.currentGroup.ptr(&PamfGroup::streams) + streamIndex;
}
return CELL_OK;
}
error_code cellPamfReaderSetStreamWithTypeAndChannel(vm::ptr<CellPamfReader> pSelf, u8 streamType, u8 ch)
{
cellPamf.notice("cellPamfReaderSetStreamWithTypeAndChannel(pSelf=*0x%x, streamType=%d, ch=%d)", pSelf, streamType, ch);
// This function is broken on LLE
ensure(!!pSelf); // Not checked on LLE
u8 stream_coding_type;
u8 stream_id;
u8 private_stream_id;
if (pamfTypeChannelToStream(streamType, ch, &stream_coding_type, &stream_id, &private_stream_id) != CELL_OK)
{
return CELL_PAMF_ERROR_INVALID_ARG;
}
const u8 stream_num = pSelf->pamf.currentGroup->stream_num;
u32 i = 0;
if (pSelf->isPsmf)
{
const auto streams = pSelf->psmf.currentGroup.ptr(&PsmfGroup::streams);
for (; i < stream_num; i++)
{
// LLE increments the index by 12 instead of 1
if (stream_coding_type == PAMF_STREAM_CODING_TYPE_PSMF && streams[i * 12].stream_id == stream_id && streams[i * 12].private_stream_id == private_stream_id)
{
break;
}
}
}
else
{
const auto streams = pSelf->pamf.currentGroup.ptr(&PamfGroup::streams);
for (; i < stream_num; i++)
{
// LLE increments the index by 0x10 instead of 1
if (streams[i * 0x10].stream_coding_type == stream_coding_type && streams[i * 0x10].stream_id == stream_id && streams[i * 0x10].private_stream_id == private_stream_id)
{
break;
}
}
}
if (i == stream_num)
{
i = CELL_PAMF_ERROR_STREAM_NOT_FOUND; // LLE writes the error code to the index
}
if (pSelf->currentStreamIndex != i)
{
pSelf->pamf.currentStream = pSelf->pamf.currentGroup.ptr(&PamfGroup::streams); // LLE always sets this to the first stream
pSelf->currentStreamIndex = i;
}
if (i == CELL_PAMF_ERROR_STREAM_NOT_FOUND)
{
return CELL_PAMF_ERROR_STREAM_NOT_FOUND;
}
return not_an_error(i);
}
error_code cellPamfReaderSetStreamWithTypeAndIndex(vm::ptr<CellPamfReader> pSelf, u8 streamType, u8 streamIndex)
{
cellPamf.notice("cellPamfReaderSetStreamWithTypeAndIndex(pSelf=*0x%x, streamType=%d, streamIndex=%d)", pSelf, streamType, streamIndex);
ensure(!!pSelf); // Not checked on LLE
const u8 stream_num = pSelf->pamf.currentGroup->stream_num;
if (streamIndex >= stream_num)
{
return CELL_PAMF_ERROR_INVALID_ARG;
}
const vm::var<u8> type;
u32 found = 0;
if (pSelf->isPsmf)
{
const auto streams = pSelf->psmf.currentGroup.ptr(&PsmfGroup::streams);
for (u8 i = 0; i < stream_num; i++)
{
if (pamfStreamToTypeChannel(PAMF_STREAM_CODING_TYPE_PSMF, streams[i].stream_id, streams[i].private_stream_id, type, vm::null) != CELL_OK)
{
continue;
}
found += *type == streamType;
if (found > streamIndex)
{
pSelf->currentStreamIndex = streamIndex; // LLE sets this to the index counting only streams of the requested type instead of the overall index
pSelf->psmf.currentStream = streams; // LLE always sets this to the first stream
return not_an_error(i);
}
}
}
else
{
const auto streams = pSelf->pamf.currentGroup.ptr(&PamfGroup::streams);
for (u8 i = 0; i < stream_num; i++)
{
if (pamfStreamToTypeChannel(streams[i].stream_coding_type, streams[i].stream_id, streams[i].private_stream_id, type, vm::null) != CELL_OK)
{
continue;
}
found += pamfIsSameStreamType(*type, streamType);
if (found > streamIndex)
{
pSelf->currentStreamIndex = i;
pSelf->pamf.currentStream = streams + i;
return not_an_error(i);
}
}
}
return CELL_PAMF_ERROR_STREAM_NOT_FOUND;
}
error_code cellPamfStreamTypeToEsFilterId(u8 type, u8 ch, vm::ptr<CellCodecEsFilterId> pEsFilterId)
{
cellPamf.notice("cellPamfStreamTypeToEsFilterId(type=%d, ch=%d, pEsFilterId=*0x%x)", type, ch, pEsFilterId);
if (!pEsFilterId)
{
return CELL_PAMF_ERROR_INVALID_ARG;
}
u8 stream_id = 0;
u8 private_stream_id = 0;
if (pamfTypeChannelToStream(type, ch, nullptr, &stream_id, &private_stream_id) != CELL_OK)
{
return CELL_PAMF_ERROR_INVALID_ARG;
}
pEsFilterId->filterIdMajor = stream_id;
pEsFilterId->filterIdMinor = private_stream_id;
pEsFilterId->supplementalInfo1 = type == CELL_PAMF_STREAM_TYPE_AVC;
pEsFilterId->supplementalInfo2 = 0;
return CELL_OK;
}
s32 cellPamfReaderGetStreamIndex(vm::ptr<CellPamfReader> pSelf)
{
cellPamf.notice("cellPamfReaderGetStreamIndex(pSelf=*0x%x)", pSelf);
ensure(!!pSelf); // Not checked on LLE
return pSelf->currentStreamIndex;
}
error_code cellPamfReaderGetStreamTypeAndChannel(vm::ptr<CellPamfReader> pSelf, vm::ptr<u8> pType, vm::ptr<u8> pCh)
{
cellPamf.notice("cellPamfReaderGetStreamTypeAndChannel(pSelf=*0x%x, pType=*0x%x, pCh=*0x%x", pSelf, pType, pCh);
ensure(!!pSelf); // Not checked on LLE
if (pSelf->isPsmf)
{
const auto stream = pSelf->psmf.currentStream;
return pamfStreamToTypeChannel(PAMF_STREAM_CODING_TYPE_PSMF, stream->stream_id, stream->private_stream_id, pType, pCh);
}
else
{
const auto stream = pSelf->pamf.currentStream;
return pamfStreamToTypeChannel(stream->stream_coding_type, stream->stream_id, stream->private_stream_id, pType, pCh);
}
}
error_code cellPamfReaderGetEsFilterId(vm::ptr<CellPamfReader> pSelf, vm::ptr<CellCodecEsFilterId> pEsFilterId)
{
cellPamf.notice("cellPamfReaderGetEsFilterId(pSelf=*0x%x, pEsFilterId=*0x%x)", pSelf, pEsFilterId);
// always returns CELL_OK
ensure(!!pSelf && !!pEsFilterId); // Not checked on LLE
if (pSelf->isPsmf)
{
pEsFilterId->filterIdMajor = pSelf->psmf.currentStream->stream_id;
pEsFilterId->filterIdMinor = pSelf->psmf.currentStream->private_stream_id;
pEsFilterId->supplementalInfo1 = 0;
}
else
{
pEsFilterId->filterIdMajor = pSelf->pamf.currentStream->stream_id;
pEsFilterId->filterIdMinor = pSelf->pamf.currentStream->private_stream_id;
pEsFilterId->supplementalInfo1 = pSelf->pamf.currentStream->stream_coding_type == PAMF_STREAM_CODING_TYPE_AVC;
}
pEsFilterId->supplementalInfo2 = 0;
return CELL_OK;
}
error_code cellPamfReaderGetStreamInfo(vm::ptr<CellPamfReader> pSelf, vm::ptr<void> pInfo, u32 size)
{
cellPamf.notice("cellPamfReaderGetStreamInfo(pSelf=*0x%x, pInfo=*0x%x, size=%d)", pSelf, pInfo, size);
ensure(!!pSelf); // Not checked on LLE
const auto& header = *pSelf->pamf.currentStream;
const auto& psmf_header = *pSelf->psmf.currentStream;
const vm::var<u8> type;
error_code ret;
if (pSelf->isPsmf)
{
ret = pamfStreamToTypeChannel(PAMF_STREAM_CODING_TYPE_PSMF, psmf_header.stream_id, psmf_header.private_stream_id, type, vm::null);
}
else
{
ret = pamfStreamToTypeChannel(header.stream_coding_type, header.stream_id, header.private_stream_id, type, vm::null);
}
if (ret != CELL_OK)
{
return CELL_PAMF_ERROR_INVALID_PAMF;
}
switch (*type)
{
case CELL_PAMF_STREAM_TYPE_AVC:
{
if (size < sizeof(CellPamfAvcInfo))
{
return CELL_PAMF_ERROR_INVALID_ARG;
}
auto info = vm::static_ptr_cast<CellPamfAvcInfo>(pInfo);
info->profileIdc = header.AVC.profileIdc;
info->levelIdc = header.AVC.levelIdc;
info->frameMbsOnlyFlag = (header.AVC.x2 & 0x80) >> 7;
info->videoSignalInfoFlag = (header.AVC.x2 & 0x40) >> 6;
info->frameRateInfo = (header.AVC.x2 & 0x0f) - 1;
info->aspectRatioIdc = header.AVC.aspectRatioIdc;
if (header.AVC.aspectRatioIdc == 0xff)
{
info->sarWidth = header.AVC.sarWidth;
info->sarHeight = header.AVC.sarHeight;
}
else
{
info->sarWidth = 0;
info->sarHeight = 0;
}
info->horizontalSize = (header.AVC.horizontalSize & u8{0xff}) * 16;
info->verticalSize = (header.AVC.verticalSize & u8{0xff}) * 16;
info->frameCropLeftOffset = header.AVC.frameCropLeftOffset;
info->frameCropRightOffset = header.AVC.frameCropRightOffset;
info->frameCropTopOffset = header.AVC.frameCropTopOffset;
info->frameCropBottomOffset = header.AVC.frameCropBottomOffset;
if (info->videoSignalInfoFlag)
{
info->videoFormat = header.AVC.x14 >> 5;
info->videoFullRangeFlag = (header.AVC.x14 & 0x10) >> 4;
info->colourPrimaries = header.AVC.colourPrimaries;
info->transferCharacteristics = header.AVC.transferCharacteristics;
info->matrixCoefficients = header.AVC.matrixCoefficients;
}
else
{
info->videoFormat = 0;
info->videoFullRangeFlag = 0;
info->colourPrimaries = 0;
info->transferCharacteristics = 0;
info->matrixCoefficients = 0;
}
info->entropyCodingModeFlag = (header.AVC.x18 & 0x80) >> 7;
info->deblockingFilterFlag = (header.AVC.x18 & 0x40) >> 6;
info->minNumSlicePerPictureIdc = (header.AVC.x18 & 0x30) >> 4;
info->nfwIdc = header.AVC.x18 & 0x03;
info->maxMeanBitrate = header.AVC.maxMeanBitrate;
cellPamf.notice("cellPamfReaderGetStreamInfo(): CELL_PAMF_STREAM_TYPE_AVC");
break;
}
case CELL_PAMF_STREAM_TYPE_M2V:
{
if (size < sizeof(CellPamfM2vInfo))
{
return CELL_PAMF_ERROR_INVALID_ARG;
}
auto info = vm::static_ptr_cast<CellPamfM2vInfo>(pInfo);
switch (header.M2V.x0)
{
case 0x44: info->profileAndLevelIndication = 3; break;
case 0x48: info->profileAndLevelIndication = 1; break;
default: info->profileAndLevelIndication = CELL_PAMF_M2V_UNKNOWN;
}
info->progressiveSequence = (header.M2V.x2 & 0x80) >> 7;
info->videoSignalInfoFlag = (header.M2V.x2 & 0x40) >> 6;
info->frameRateInfo = header.M2V.x2 & 0xf;
info->aspectRatioIdc = header.M2V.aspectRatioIdc;
if (header.M2V.aspectRatioIdc == 0xff)
{
info->sarWidth = header.M2V.sarWidth;
info->sarHeight = header.M2V.sarHeight;
}
else
{
info->sarWidth = 0;
info->sarHeight = 0;
}
info->horizontalSize = (header.M2V.horizontalSize & u8{0xff}) * 16;
info->verticalSize = (header.M2V.verticalSize & u8{0xff}) * 16;
info->horizontalSizeValue = header.M2V.horizontalSizeValue;
info->verticalSizeValue = header.M2V.verticalSizeValue;
if (info->videoSignalInfoFlag)
{
info->videoFormat = header.M2V.x14 >> 5;
info->videoFullRangeFlag = (header.M2V.x14 & 0x10) >> 4;
info->colourPrimaries = header.M2V.colourPrimaries;
info->transferCharacteristics = header.M2V.transferCharacteristics;
info->matrixCoefficients = header.M2V.matrixCoefficients;
}
else
{
info->videoFormat = 0;
info->videoFullRangeFlag = 0;
info->colourPrimaries = 0;
info->transferCharacteristics = 0;
info->matrixCoefficients = 0;
}
cellPamf.notice("cellPamfReaderGetStreamInfo(): CELL_PAMF_STREAM_TYPE_M2V");
break;
}
case CELL_PAMF_STREAM_TYPE_ATRAC3PLUS:
{
if (size < sizeof(CellPamfAtrac3plusInfo))
{
return CELL_PAMF_ERROR_INVALID_ARG;
}
auto info = vm::static_ptr_cast<CellPamfAtrac3plusInfo>(pInfo);
info->samplingFrequency = header.audio.freq & 0xf;
info->numberOfChannels = header.audio.channels & 0xf;
cellPamf.notice("cellPamfReaderGetStreamInfo(): CELL_PAMF_STREAM_TYPE_ATRAC3PLUS");
break;
}
case CELL_PAMF_STREAM_TYPE_PAMF_LPCM:
{
if (size < sizeof(CellPamfLpcmInfo))
{
return CELL_PAMF_ERROR_INVALID_ARG;
}
auto info = vm::static_ptr_cast<CellPamfLpcmInfo>(pInfo);
info->samplingFrequency = header.audio.freq & 0xf;
info->numberOfChannels = header.audio.channels & 0xf;
info->bitsPerSample = header.audio.bps >> 6;
cellPamf.notice("cellPamfReaderGetStreamInfo(): CELL_PAMF_STREAM_TYPE_PAMF_LPCM");
break;
}
case CELL_PAMF_STREAM_TYPE_AC3:
{
if (size < sizeof(CellPamfAc3Info))
{
return CELL_PAMF_ERROR_INVALID_ARG;
}
auto info = vm::static_ptr_cast<CellPamfAc3Info>(pInfo);
info->samplingFrequency = header.audio.freq & 0xf;
info->numberOfChannels = header.audio.channels & 0xf;
cellPamf.notice("cellPamfReaderGetStreamInfo(): CELL_PAMF_STREAM_TYPE_AC3");
break;
}
case CELL_PAMF_STREAM_TYPE_USER_DATA:
case CELL_PAMF_STREAM_TYPE_PSMF_USER_DATA:
{
cellPamf.error("cellPamfReaderGetStreamInfo(): invalid type CELL_PAMF_STREAM_TYPE_USER_DATA");
return CELL_PAMF_ERROR_INVALID_ARG;
}
case CELL_PAMF_STREAM_TYPE_PSMF_AVC:
{
if (size < 4)
{
return CELL_PAMF_ERROR_INVALID_ARG;
}
vm::static_ptr_cast<u16>(pInfo)[0] = psmf_header.video.horizontalSize * 0x10;
vm::static_ptr_cast<u16>(pInfo)[1] = psmf_header.video.verticalSize * 0x10;
cellPamf.notice("cellPamfReaderGetStreamInfo(): CELL_PAMF_STREAM_TYPE_PSMF_AVC");
break;
}
case CELL_PAMF_STREAM_TYPE_PSMF_ATRAC3PLUS:
case CELL_PAMF_STREAM_TYPE_PSMF_LPCM:
{
if (size < 2)
{
return CELL_PAMF_ERROR_INVALID_ARG;
}
vm::static_ptr_cast<u8>(pInfo)[0] = psmf_header.audio.channelConfiguration;
vm::static_ptr_cast<u8>(pInfo)[1] = psmf_header.audio.samplingFrequency & 0x0f;
cellPamf.notice("cellPamfReaderGetStreamInfo(): PSMF audio");
break;
}
default:
{
// invalid type or getting type/ch failed
cellPamf.error("cellPamfReaderGetStreamInfo(): invalid type %d", *type);
return CELL_PAMF_ERROR_INVALID_PAMF;
}
}
return CELL_OK;
}
u32 cellPamfReaderGetNumberOfEp(vm::ptr<CellPamfReader> pSelf)
{
cellPamf.notice("cellPamfReaderGetNumberOfEp(pSelf=*0x%x)", pSelf);
ensure(!!pSelf); // Not checked on LLE
return pSelf->isPsmf ? pSelf->psmf.currentStream->ep_num : pSelf->pamf.currentStream->ep_num;
}
error_code cellPamfReaderGetEpIteratorWithIndex(vm::ptr<CellPamfReader> pSelf, u32 epIndex, vm::ptr<CellPamfEpIterator> pIt)
{
cellPamf.notice("cellPamfReaderGetEpIteratorWithIndex(pSelf=*0x%x, epIndex=%d, pIt=*0x%x)", pSelf, epIndex, pIt);
ensure(!!pSelf && !!pIt); // Not checked on LLE
const u32 ep_num = cellPamfReaderGetNumberOfEp(pSelf);
if (epIndex >= ep_num)
{
return CELL_PAMF_ERROR_INVALID_ARG;
}
if (pSelf->attribute & CELL_PAMF_ATTRIBUTE_MINIMUM_HEADER)
{
return CELL_PAMF_ERROR_NOT_AVAILABLE;
}
pIt->isPamf = !pSelf->isPsmf;
pIt->index = epIndex;
pIt->num = ep_num;
pIt->pCur.set(pSelf->isPsmf ? pSelf->psmf.header.addr() + pSelf->psmf.currentStream->ep_offset + epIndex * sizeof(PsmfEpHeader)
: pSelf->pamf.header.addr() + pSelf->pamf.currentStream->ep_offset + epIndex * sizeof(PamfEpHeader));
return CELL_OK;
}
error_code cellPamfReaderGetEpIteratorWithTimeStamp(vm::ptr<CellPamfReader> pSelf, vm::ptr<CellCodecTimeStamp> pTimeStamp, vm::ptr<CellPamfEpIterator> pIt)
{
cellPamf.notice("cellPamfReaderGetEpIteratorWithTimeStamp(pSelf=*0x%x, pTimeStamp=*0x%x, pIt=*0x%x)", pSelf, pTimeStamp, pIt);
ensure(!!pSelf && !!pTimeStamp && !!pIt); // Not checked on LLE
if (pSelf->attribute & CELL_PAMF_ATTRIBUTE_MINIMUM_HEADER)
{
return CELL_PAMF_ERROR_NOT_AVAILABLE;
}
const u32 ep_num = cellPamfReaderGetNumberOfEp(pSelf);
pIt->num = ep_num;
pIt->isPamf = !pSelf->isPsmf;
if (ep_num == 0)
{
return CELL_PAMF_ERROR_EP_NOT_FOUND;
}
u32 i = ep_num - 1;
const u64 requested_time_stamp = std::bit_cast<be_t<u64>>(*pTimeStamp);
if (pSelf->isPsmf)
{
const auto eps = vm::cptr<PsmfEpHeader>::make(pSelf->psmf.header.addr() + pSelf->psmf.currentStream->ep_offset);
for (; i >= 1; i--) // always output eps[0] if no other suitable ep is found
{
const u64 time_stamp = (static_cast<u64>(eps[i].value0 & 1) << 32) | eps[i].pts_low;
if (time_stamp <= requested_time_stamp)
{
break;
}
}
pIt->pCur = eps + i;
}
else
{
const auto eps = vm::cptr<PamfEpHeader>::make(pSelf->pamf.header.addr() + pSelf->pamf.currentStream->ep_offset);
for (; i >= 1; i--) // always output eps[0] if no other suitable ep is found
{
const u64 time_stamp = (static_cast<u64>(eps[i].pts_high) << 32) | eps[i].pts_low;
if (time_stamp <= requested_time_stamp)
{
break;
}
}
pIt->pCur = eps + i;
}
pIt->index = i;
return CELL_OK;
}
error_code cellPamfEpIteratorGetEp(vm::ptr<CellPamfEpIterator> pIt, vm::ptr<CellPamfEp> pEp)
{
cellPamf.notice("cellPamfEpIteratorGetEp(pIt=*0x%x, pEp=*0x%x)", pIt, pEp);
// always returns CELL_OK
ensure(!!pIt); // Not checked on LLE
if (pIt->isPamf)
{
pamfEpUnpack(vm::static_ptr_cast<const PamfEpHeader>(pIt->pCur), pEp);
}
else
{
psmfEpUnpack(vm::static_ptr_cast<const PsmfEpHeader>(pIt->pCur), pEp);
}
return CELL_OK;
}
s32 cellPamfEpIteratorMove(vm::ptr<CellPamfEpIterator> pIt, s32 steps, vm::ptr<CellPamfEp> pEp)
{
cellPamf.notice("cellPamfEpIteratorMove(pIt=*0x%x, steps=%d, pEp=*0x%x)", pIt, steps, pEp);
ensure(!!pIt); // Not checked on LLE
u32 new_index = pIt->index + steps;
if (static_cast<s32>(new_index) < 0)
{
steps = -static_cast<s32>(pIt->index);
new_index = 0;
}
else if (new_index >= pIt->num)
{
steps = (pIt->num - pIt->index) - 1;
new_index = pIt->index + steps;
}
pIt->index = new_index;
if (pIt->isPamf)
{
pIt->pCur = vm::static_ptr_cast<const PamfEpHeader>(pIt->pCur) + steps;
if (pEp)
{
pamfEpUnpack(vm::static_ptr_cast<const PamfEpHeader>(pIt->pCur), pEp);
}
}
else
{
pIt->pCur = vm::static_ptr_cast<const PsmfEpHeader>(pIt->pCur) + steps;
if (pEp)
{
psmfEpUnpack(vm::static_ptr_cast<const PsmfEpHeader>(pIt->pCur), pEp);
}
}
return steps;
}
error_code cellPamfReaderGetEpWithTimeStamp(vm::ptr<CellPamfReader> pSelf, vm::ptr<CellCodecTimeStamp> pTimeStamp, vm::ptr<CellPamfEpUnk> pEp, u32 unk)
{
cellPamf.notice("cellPamfReaderGetEpWithTimeStamp(pSelf=*0x%x, pTimeStamp=*0x%x, pEp=*0x%x, unk=0x%x)", pSelf, pTimeStamp, pEp, unk);
// This function is broken on LLE
ensure(!!pSelf && !!pTimeStamp && !!pEp); // Not checked on LLE
if (pSelf->attribute & CELL_PAMF_ATTRIBUTE_MINIMUM_HEADER)
{
return CELL_PAMF_ERROR_NOT_AVAILABLE;
}
const u32 ep_num = cellPamfReaderGetNumberOfEp(pSelf);
u64 next_rpn_offset = pSelf->dataSize;
if (ep_num == 0)
{
return CELL_PAMF_ERROR_EP_NOT_FOUND;
}
u32 i = ep_num - 1;
const u64 requested_time_stamp = std::bit_cast<be_t<u64>>(*pTimeStamp);
if (pSelf->isPsmf)
{
const auto eps = vm::cptr<PsmfEpHeader>::make(pSelf->psmf.header.addr() + pSelf->psmf.currentStream->ep_offset);
for (; i >= 1; i--) // always output eps[0] if no other suitable ep is found
{
const u64 time_stamp = (static_cast<u64>(eps[i].value0 & 1) << 32) | eps[i].pts_low;
if (time_stamp <= requested_time_stamp)
{
break;
}
}
// LLE doesn't write the result to pEp
if (i < ep_num - 1)
{
next_rpn_offset = eps[i + 1].rpnOffset;
}
}
else
{
const auto eps = vm::cptr<PamfEpHeader>::make(pSelf->pamf.header.addr() + pSelf->pamf.currentStream->ep_offset);
for (; i >= 1; i--) // always output eps[0] if no other suitable ep is found
{
const u64 time_stamp = (static_cast<u64>(eps[i].pts_high) << 32) | eps[i].pts_low;
if (time_stamp <= requested_time_stamp)
{
break;
}
}
// LLE doesn't write the result to pEp
if (i < ep_num - 1)
{
next_rpn_offset = eps[i + 1].rpnOffset;
}
}
if (unk == sizeof(CellPamfEpUnk))
{
pEp->nextRpnOffset = next_rpn_offset;
}
return CELL_OK;
}
error_code cellPamfReaderGetEpWithIndex(vm::ptr<CellPamfReader> pSelf, u32 epIndex, vm::ptr<CellPamfEpUnk> pEp, u32 unk)
{
cellPamf.notice("cellPamfReaderGetEpWithIndex(pSelf=*0x%x, epIndex=%d, pEp=*0x%x, unk=0x%x)", pSelf, epIndex, pEp, unk);
ensure(!!pSelf && !!pEp); // Not checked on LLE
const u32 ep_num = cellPamfReaderGetNumberOfEp(pSelf);
u64 next_rpn_offset = pSelf->dataSize;
if (epIndex >= ep_num)
{
return CELL_PAMF_ERROR_INVALID_ARG;
}
if (pSelf->attribute & CELL_PAMF_ATTRIBUTE_MINIMUM_HEADER)
{
return CELL_PAMF_ERROR_NOT_AVAILABLE;
}
if (pSelf->isPsmf)
{
const auto ep = vm::cptr<PsmfEpHeader>::make(pSelf->psmf.header.addr() + pSelf->psmf.currentStream->ep_offset + epIndex * sizeof(PsmfEpHeader));
psmfEpUnpack(ep, pEp.ptr(&CellPamfEpUnk::ep));
if (epIndex < ep_num - 1)
{
next_rpn_offset = ep[1].rpnOffset * 0x800ull;
}
}
else
{
const auto ep = vm::cptr<PamfEpHeader>::make(pSelf->pamf.header.addr() + pSelf->pamf.currentStream->ep_offset + epIndex * sizeof(PamfEpHeader));
pamfEpUnpack(ep, pEp.ptr(&CellPamfEpUnk::ep));
if (epIndex < ep_num - 1)
{
next_rpn_offset = ep[1].rpnOffset * 0x800ull;
}
}
if (unk == sizeof(CellPamfEpUnk))
{
pEp->nextRpnOffset = next_rpn_offset;
}
return CELL_OK;
}
DECLARE(ppu_module_manager::cellPamf)("cellPamf", []()
{
REG_FUNC(cellPamf, cellPamfGetHeaderSize);
REG_FUNC(cellPamf, cellPamfGetHeaderSize2);
REG_FUNC(cellPamf, cellPamfGetStreamOffsetAndSize);
REG_FUNC(cellPamf, cellPamfVerify);
REG_FUNC(cellPamf, cellPamfReaderInitialize);
REG_FUNC(cellPamf, cellPamfReaderGetPresentationStartTime);
REG_FUNC(cellPamf, cellPamfReaderGetPresentationEndTime);
REG_FUNC(cellPamf, cellPamfReaderGetMuxRateBound);
REG_FUNC(cellPamf, cellPamfReaderGetNumberOfStreams);
REG_FUNC(cellPamf, cellPamfReaderGetNumberOfSpecificStreams);
REG_FUNC(cellPamf, cellPamfReaderSetStreamWithIndex);
REG_FUNC(cellPamf, cellPamfReaderSetStreamWithTypeAndChannel);
REG_FUNC(cellPamf, cellPamfReaderSetStreamWithTypeAndIndex);
REG_FUNC(cellPamf, cellPamfStreamTypeToEsFilterId);
REG_FUNC(cellPamf, cellPamfReaderGetStreamIndex);
REG_FUNC(cellPamf, cellPamfReaderGetStreamTypeAndChannel);
REG_FUNC(cellPamf, cellPamfReaderGetEsFilterId);
REG_FUNC(cellPamf, cellPamfReaderGetStreamInfo);
REG_FUNC(cellPamf, cellPamfReaderGetNumberOfEp);
REG_FUNC(cellPamf, cellPamfReaderGetEpIteratorWithIndex);
REG_FUNC(cellPamf, cellPamfReaderGetEpIteratorWithTimeStamp);
REG_FUNC(cellPamf, cellPamfEpIteratorGetEp);
REG_FUNC(cellPamf, cellPamfEpIteratorMove);
REG_FUNC(cellPamf, cellPamfReaderGetEpWithTimeStamp);
REG_FUNC(cellPamf, cellPamfReaderGetEpWithIndex);
});
| 45,824
|
C++
|
.cpp
| 1,328
| 31.740211
| 191
| 0.719601
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
5,256
|
cellVideoExport.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellVideoExport.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
#include "Emu/IdManager.h"
#include "Emu/VFS.h"
#include "Utilities/StrUtil.h"
#include "cellSysutil.h"
LOG_CHANNEL(cellVideoExport);
enum CellVideoExportUtilError : u32
{
CELL_VIDEO_EXPORT_UTIL_ERROR_BUSY = 0x8002ca01,
CELL_VIDEO_EXPORT_UTIL_ERROR_INTERNAL = 0x8002ca02,
CELL_VIDEO_EXPORT_UTIL_ERROR_PARAM = 0x8002ca03,
CELL_VIDEO_EXPORT_UTIL_ERROR_ACCESS_ERROR = 0x8002ca04,
CELL_VIDEO_EXPORT_UTIL_ERROR_DB_INTERNAL = 0x8002ca05,
CELL_VIDEO_EXPORT_UTIL_ERROR_DB_REGIST = 0x8002ca06,
CELL_VIDEO_EXPORT_UTIL_ERROR_SET_META = 0x8002ca07,
CELL_VIDEO_EXPORT_UTIL_ERROR_FLUSH_META = 0x8002ca08,
CELL_VIDEO_EXPORT_UTIL_ERROR_MOVE = 0x8002ca09,
CELL_VIDEO_EXPORT_UTIL_ERROR_INITIALIZE = 0x8002ca0a,
};
enum
{
CELL_VIDEO_EXPORT_UTIL_RET_OK = 0,
CELL_VIDEO_EXPORT_UTIL_RET_CANCEL = 1,
};
enum
{
CELL_VIDEO_EXPORT_UTIL_VERSION_CURRENT = 0,
CELL_VIDEO_EXPORT_UTIL_HDD_PATH_MAX = 1055,
CELL_VIDEO_EXPORT_UTIL_VIDEO_TITLE_MAX_LENGTH = 64,
CELL_VIDEO_EXPORT_UTIL_GAME_TITLE_MAX_LENGTH = 64,
CELL_VIDEO_EXPORT_UTIL_GAME_COMMENT_MAX_SIZE = 1024,
};
template<>
void fmt_class_string<CellVideoExportUtilError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_VIDEO_EXPORT_UTIL_ERROR_BUSY);
STR_CASE(CELL_VIDEO_EXPORT_UTIL_ERROR_INTERNAL);
STR_CASE(CELL_VIDEO_EXPORT_UTIL_ERROR_PARAM);
STR_CASE(CELL_VIDEO_EXPORT_UTIL_ERROR_ACCESS_ERROR);
STR_CASE(CELL_VIDEO_EXPORT_UTIL_ERROR_DB_INTERNAL);
STR_CASE(CELL_VIDEO_EXPORT_UTIL_ERROR_DB_REGIST);
STR_CASE(CELL_VIDEO_EXPORT_UTIL_ERROR_SET_META);
STR_CASE(CELL_VIDEO_EXPORT_UTIL_ERROR_FLUSH_META);
STR_CASE(CELL_VIDEO_EXPORT_UTIL_ERROR_MOVE);
STR_CASE(CELL_VIDEO_EXPORT_UTIL_ERROR_INITIALIZE);
}
return unknown;
});
}
struct CellVideoExportSetParam
{
vm::bptr<char> title;
vm::bptr<char> game_title;
vm::bptr<char> game_comment;
be_t<s32> editable;
vm::bptr<void> reserved2;
};
using CellVideoExportUtilFinishCallback = void(s32 result, vm::ptr<void> userdata);
struct video_export
{
atomic_t<s32> progress = 0; // 0x0-0xFFFF for 0-100%
};
bool check_movie_path(const std::string& file_path)
{
if (file_path.size() >= CELL_VIDEO_EXPORT_UTIL_HDD_PATH_MAX)
{
return false;
}
for (char c : file_path)
{
if (!((c >= 'a' && c <= 'z') ||
(c >= 'A' && c <= 'Z') ||
(c >= '0' && c <= '9') ||
c == '-' || c == '_' ||
c == '/' || c == '.'))
{
return false;
}
}
if (!file_path.starts_with("/dev_hdd0"sv) &&
!file_path.starts_with("/dev_bdvd"sv) &&
!file_path.starts_with("/dev_hdd1"sv))
{
return false;
}
if (file_path.find(".."sv) != umax)
{
return false;
}
return true;
}
std::string get_available_movie_path(const std::string& filename)
{
// TODO: Find out how to build this path properly. Apparently real hardware doesn't add a suffix,
// but just randomly puts each video into a separate 2-Letter subdirectory like /video/hd/ or /video/ee/
const std::string movie_dir = "/dev_hdd0/video/";
std::string dst_path = vfs::get(movie_dir + filename);
// Do not overwrite existing files. Add a suffix instead.
for (u32 i = 0; fs::exists(dst_path); i++)
{
const std::string suffix = fmt::format("_%d", i);
std::string new_filename = filename;
if (const usz pos = new_filename.find_last_of('.'); pos != std::string::npos)
{
new_filename.insert(pos, suffix);
}
else
{
new_filename.append(suffix);
}
dst_path = vfs::get(movie_dir + new_filename);
}
return dst_path;
}
error_code cellVideoExportInitialize2(u32 version, vm::ptr<CellVideoExportUtilFinishCallback> funcFinish, vm::ptr<void> userdata)
{
cellVideoExport.notice("cellVideoExportInitialize2(version=0x%x, funcFinish=*0x%x, userdata=*0x%x)", version, funcFinish, userdata);
if (version != CELL_VIDEO_EXPORT_UTIL_VERSION_CURRENT)
{
return CELL_VIDEO_EXPORT_UTIL_ERROR_PARAM;
}
if (!funcFinish)
{
return CELL_VIDEO_EXPORT_UTIL_ERROR_PARAM;
}
sysutil_register_cb([=](ppu_thread& ppu) -> s32
{
funcFinish(ppu, CELL_OK, userdata);
return CELL_OK;
});
return CELL_OK;
}
error_code cellVideoExportInitialize(u32 version, u32 container, vm::ptr<CellVideoExportUtilFinishCallback> funcFinish, vm::ptr<void> userdata)
{
cellVideoExport.notice("cellVideoExportInitialize(version=0x%x, container=0x%x, funcFinish=*0x%x, userdata=*0x%x)", version, container, funcFinish, userdata);
if (version != CELL_VIDEO_EXPORT_UTIL_VERSION_CURRENT)
{
return CELL_VIDEO_EXPORT_UTIL_ERROR_PARAM;
}
// Check container (same sub-function as cellVideoExportInitialize2, so we have to check this parameter anyway)
if (container != 0xfffffffe)
{
if (false) // invalid container or container size < 0x500000
{
return CELL_VIDEO_EXPORT_UTIL_ERROR_PARAM;
}
}
if (!funcFinish)
{
return CELL_VIDEO_EXPORT_UTIL_ERROR_PARAM;
}
sysutil_register_cb([=](ppu_thread& ppu) -> s32
{
funcFinish(ppu, CELL_OK, userdata);
return CELL_OK;
});
return CELL_OK;
}
error_code cellVideoExportProgress(vm::ptr<CellVideoExportUtilFinishCallback> funcFinish, vm::ptr<void> userdata)
{
cellVideoExport.todo("cellVideoExportProgress(funcFinish=*0x%x, userdata=*0x%x)", funcFinish, userdata);
if (!funcFinish)
{
return CELL_VIDEO_EXPORT_UTIL_ERROR_PARAM;
}
sysutil_register_cb([=](ppu_thread& ppu) -> s32
{
// Set the status as 0x0-0xFFFF (0-100%) depending on the copy status.
// Only the copy or move of the movie and metadata files is considered for the progress.
const auto& vexp = g_fxo->get<video_export>();
funcFinish(ppu, vexp.progress, userdata);
return CELL_OK;
});
return CELL_OK;
}
error_code cellVideoExportFromFileWithCopy(vm::cptr<char> srcHddDir, vm::cptr<char> srcHddFile, vm::ptr<CellVideoExportSetParam> param, vm::ptr<CellVideoExportUtilFinishCallback> funcFinish, vm::ptr<void> userdata)
{
cellVideoExport.todo("cellVideoExportFromFileWithCopy(srcHddDir=%s, srcHddFile=%s, param=*0x%x, funcFinish=*0x%x, userdata=*0x%x)", srcHddDir, srcHddFile, param, funcFinish, userdata);
if (!param || !funcFinish || !srcHddDir || !srcHddDir[0] || !srcHddFile || !srcHddFile[0])
{
return CELL_VIDEO_EXPORT_UTIL_ERROR_PARAM;
}
// TODO: check param members ?
cellVideoExport.notice("cellVideoExportFromFileWithCopy: param: title=%s, game_title=%s, game_comment=%s, editable=%d", param->title, param->game_title, param->game_comment, param->editable);
const std::string file_path = fmt::format("%s/%s", srcHddDir.get_ptr(), srcHddFile.get_ptr());
if (!check_movie_path(file_path))
{
return { CELL_VIDEO_EXPORT_UTIL_ERROR_PARAM, file_path };
}
std::string filename;
if (srcHddFile)
{
fmt::append(filename, "%s", srcHddFile.get_ptr());
}
if (filename.empty())
{
return { CELL_VIDEO_EXPORT_UTIL_ERROR_PARAM, "filename empty" };
}
sysutil_register_cb([=](ppu_thread& ppu) -> s32
{
auto& vexp = g_fxo->get<video_export>();
vexp.progress = 0; // 0%
const std::string src_path = vfs::get(file_path);
const std::string dst_path = get_available_movie_path(filename);
cellVideoExport.notice("Copying file from '%s' to '%s'", file_path, dst_path);
if (!fs::create_path(fs::get_parent_dir(dst_path)) || !fs::copy_file(src_path, dst_path, false))
{
// TODO: find out which error is used
cellVideoExport.error("Failed to copy file from '%s' to '%s' (%s)", src_path, dst_path, fs::g_tls_error);
funcFinish(ppu, CELL_VIDEO_EXPORT_UTIL_ERROR_MOVE, userdata);
return CELL_OK;
}
// TODO: write metadata file sometime in the far future
// const std::string metadata_file = dst_path + ".vmd";
// TODO: track progress during file copy
vexp.progress = 0xFFFF; // 100%
funcFinish(ppu, CELL_OK, userdata);
return CELL_OK;
});
return CELL_OK;
}
error_code cellVideoExportFromFile(vm::cptr<char> srcHddDir, vm::cptr<char> srcHddFile, vm::ptr<CellVideoExportSetParam> param, vm::ptr<CellVideoExportUtilFinishCallback> funcFinish, vm::ptr<void> userdata)
{
cellVideoExport.todo("cellVideoExportFromFile(srcHddDir=%s, srcHddFile=%s, param=*0x%x, funcFinish=*0x%x, userdata=*0x%x)", srcHddDir, srcHddFile, param, funcFinish, userdata);
if (!param || !funcFinish || !srcHddDir || !srcHddDir[0] || !srcHddFile || !srcHddFile[0])
{
return CELL_VIDEO_EXPORT_UTIL_ERROR_PARAM;
}
// TODO: check param members ?
cellVideoExport.notice("cellVideoExportFromFile: param: title=%s, game_title=%s, game_comment=%s, editable=%d", param->title, param->game_title, param->game_comment, param->editable);
const std::string file_path = fmt::format("%s/%s", srcHddDir.get_ptr(), srcHddFile.get_ptr());
if (!check_movie_path(file_path))
{
return { CELL_VIDEO_EXPORT_UTIL_ERROR_PARAM, file_path };
}
std::string filename;
if (srcHddFile)
{
fmt::append(filename, "%s", srcHddFile.get_ptr());
}
if (filename.empty())
{
return { CELL_VIDEO_EXPORT_UTIL_ERROR_PARAM, "filename empty" };
}
sysutil_register_cb([=](ppu_thread& ppu) -> s32
{
auto& vexp = g_fxo->get<video_export>();
vexp.progress = 0; // 0%
const std::string src_path = vfs::get(file_path);
const std::string dst_path = get_available_movie_path(filename);
cellVideoExport.notice("Copying file from '%s' to '%s'", file_path, dst_path);
if (!fs::create_path(fs::get_parent_dir(dst_path)) || !fs::copy_file(src_path, dst_path, false))
{
// TODO: find out which error is used
cellVideoExport.error("Failed to copy file from '%s' to '%s' (%s)", src_path, dst_path, fs::g_tls_error);
funcFinish(ppu, CELL_VIDEO_EXPORT_UTIL_ERROR_MOVE, userdata);
return CELL_OK;
}
if (!file_path.starts_with("/dev_bdvd"sv))
{
cellVideoExport.notice("Removing file '%s'", src_path);
if (!fs::remove_file(src_path))
{
// TODO: find out if an error is used here
cellVideoExport.error("Failed to remove file '%s' (%s)", src_path, fs::g_tls_error);
}
}
// TODO: write metadata file sometime in the far future
// const std::string metadata_file = dst_path + ".vmd";
// TODO: track progress during file copy
vexp.progress = 0xFFFF; // 100%
funcFinish(ppu, CELL_OK, userdata);
return CELL_OK;
});
return CELL_OK;
}
error_code cellVideoExportFinalize(vm::ptr<CellVideoExportUtilFinishCallback> funcFinish, vm::ptr<void> userdata)
{
cellVideoExport.notice("cellVideoExportFinalize(funcFinish=*0x%x, userdata=*0x%x)", funcFinish, userdata);
if (!funcFinish)
{
return CELL_VIDEO_EXPORT_UTIL_ERROR_PARAM;
}
sysutil_register_cb([=](ppu_thread& ppu) -> s32
{
funcFinish(ppu, CELL_OK, userdata);
return CELL_OK;
});
return CELL_OK;
}
DECLARE(ppu_module_manager::cellVideoExport)("cellVideoExportUtility", []()
{
REG_FUNC(cellVideoExportUtility, cellVideoExportProgress);
REG_FUNC(cellVideoExportUtility, cellVideoExportInitialize2);
REG_FUNC(cellVideoExportUtility, cellVideoExportInitialize);
REG_FUNC(cellVideoExportUtility, cellVideoExportFromFileWithCopy);
REG_FUNC(cellVideoExportUtility, cellVideoExportFromFile);
REG_FUNC(cellVideoExportUtility, cellVideoExportFinalize);
});
| 11,130
|
C++
|
.cpp
| 304
| 34.006579
| 214
| 0.717703
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
5,257
|
cellMusicDecode.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellMusicDecode.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
#include "Emu/Cell/lv2/sys_lwmutex.h"
#include "Emu/Cell/lv2/sys_lwcond.h"
#include "Emu/Cell/lv2/sys_spu.h"
#include "Emu/RSX/Overlays/overlay_media_list_dialog.h"
#include "Emu/VFS.h"
#include "cellMusicDecode.h"
#include "cellMusic.h"
#include "cellSearch.h"
#include "cellSpurs.h"
#include "cellSysutil.h"
#include "util/media_utils.h"
#include <deque>
LOG_CHANNEL(cellMusicDecode);
template<>
void fmt_class_string<CellMusicDecodeError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_MUSIC_DECODE_CANCELED);
STR_CASE(CELL_MUSIC_DECODE_DECODE_FINISHED);
STR_CASE(CELL_MUSIC_DECODE_ERROR_PARAM);
STR_CASE(CELL_MUSIC_DECODE_ERROR_BUSY);
STR_CASE(CELL_MUSIC_DECODE_ERROR_NO_ACTIVE_CONTENT);
STR_CASE(CELL_MUSIC_DECODE_ERROR_NO_MATCH_FOUND);
STR_CASE(CELL_MUSIC_DECODE_ERROR_INVALID_CONTEXT);
STR_CASE(CELL_MUSIC_DECODE_ERROR_DECODE_FAILURE);
STR_CASE(CELL_MUSIC_DECODE_ERROR_NO_MORE_CONTENT);
STR_CASE(CELL_MUSIC_DECODE_DIALOG_OPEN);
STR_CASE(CELL_MUSIC_DECODE_DIALOG_CLOSE);
STR_CASE(CELL_MUSIC_DECODE_ERROR_NO_LPCM_DATA);
STR_CASE(CELL_MUSIC_DECODE_NEXT_CONTENTS_READY);
STR_CASE(CELL_MUSIC_DECODE_ERROR_GENERIC);
}
return unknown;
});
}
struct music_decode
{
vm::ptr<CellMusicDecodeCallback> func{};
vm::ptr<void> userData{};
music_selection_context current_selection_context{};
s32 decode_status = CELL_MUSIC_DECODE_STATUS_DORMANT;
s32 decode_command = CELL_MUSIC_DECODE_CMD_STOP;
u64 read_pos = 0;
utils::audio_decoder decoder{};
shared_mutex mutex;
error_code set_decode_command(s32 command)
{
decode_command = command;
switch (command)
{
case CELL_MUSIC_DECODE_CMD_STOP:
{
decoder.stop();
decode_status = CELL_MUSIC_DECODE_STATUS_DORMANT;
break;
}
case CELL_MUSIC_DECODE_CMD_START:
{
decode_status = CELL_MUSIC_DECODE_STATUS_DECODING;
read_pos = 0;
// Decode data. The format of the decoded data is 48kHz, float 32bit, 2ch LPCM data interleaved in order from left to right.
cellMusicDecode.notice("set_decode_command(START): context: %s", current_selection_context.to_string());
music_selection_context context = current_selection_context;
for (usz i = 0; i < context.playlist.size(); i++)
{
context.playlist[i] = vfs::get(context.playlist[i]);
}
// TODO: set speed if small-memory decoding is used (music_decode2)
decoder.set_context(std::move(context));
decoder.set_swap_endianness(true);
decoder.decode();
break;
}
case CELL_MUSIC_DECODE_CMD_NEXT:
case CELL_MUSIC_DECODE_CMD_PREV:
{
decoder.stop();
if (decoder.set_next_index(command == CELL_MUSIC_DECODE_CMD_NEXT) == umax)
{
decode_status = CELL_MUSIC_DECODE_STATUS_DORMANT;
return CELL_MUSIC_DECODE_ERROR_NO_MORE_CONTENT;
}
decoder.decode();
break;
}
default:
{
fmt::throw_exception("Unknown decode command %d", command);
}
}
return CELL_OK;
}
error_code finalize()
{
decoder.stop();
decode_status = CELL_MUSIC_DECODE_STATUS_DORMANT;
decode_command = CELL_MUSIC_DECODE_CMD_STOP;
read_pos = 0;
return CELL_OK;
}
};
struct music_decode2 : music_decode
{
s32 speed = CELL_MUSIC_DECODE2_SPEED_MAX;
};
template <typename Music_Decode>
error_code cell_music_decode_select_contents()
{
auto& dec = g_fxo->get<Music_Decode>();
if (!dec.func)
return CELL_MUSIC_DECODE_ERROR_GENERIC;
const std::string vfs_dir_path = vfs::get("/dev_hdd0/music");
const std::string title = get_localized_string(localized_string_id::RSX_OVERLAYS_MEDIA_DIALOG_TITLE);
error_code error = rsx::overlays::show_media_list_dialog(rsx::overlays::media_list_dialog::media_type::audio, vfs_dir_path, title,
[&dec](s32 status, utils::media_info info)
{
sysutil_register_cb([&dec, info, status](ppu_thread& ppu) -> s32
{
std::lock_guard lock(dec.mutex);
const u32 result = status >= 0 ? u32{CELL_OK} : u32{CELL_MUSIC_DECODE_CANCELED};
if (result == CELL_OK)
{
music_selection_context context{};
context.set_playlist(info.path);
// TODO: context.repeat_mode = CELL_SEARCH_REPEATMODE_NONE;
// TODO: context.context_option = CELL_SEARCH_CONTEXTOPTION_NONE;
dec.current_selection_context = context;
dec.current_selection_context.create_playlist(music_selection_context::get_next_hash());
cellMusicDecode.success("Media list dialog: selected entry '%s'", context.playlist.front());
}
else
{
cellMusicDecode.warning("Media list dialog was canceled");
}
dec.func(ppu, CELL_MUSIC_DECODE_EVENT_SELECT_CONTENTS_RESULT, vm::addr_t(result), dec.userData);
return CELL_OK;
});
});
return error;
}
template <typename Music_Decode>
error_code cell_music_decode_read(vm::ptr<void> buf, vm::ptr<u32> startTime, u64 reqSize, vm::ptr<u64> readSize, vm::ptr<s32> position)
{
if (!buf || !startTime || !position || !reqSize || !readSize)
{
return CELL_MUSIC_DECODE_ERROR_PARAM;
}
*position = CELL_MUSIC_DECODE_POSITION_NONE;
*readSize = 0;
*startTime = 0;
auto& dec = g_fxo->get<Music_Decode>();
std::lock_guard lock(dec.mutex);
std::scoped_lock slock(dec.decoder.m_mtx);
if (dec.decoder.has_error)
{
return CELL_MUSIC_DECODE_ERROR_DECODE_FAILURE;
}
if (dec.decoder.m_size == 0)
{
return CELL_MUSIC_DECODE_ERROR_NO_LPCM_DATA;
}
const u64 size_left = dec.decoder.m_size - dec.read_pos;
if (dec.read_pos == 0)
{
cellMusicDecode.trace("cell_music_decode_read: position=CELL_MUSIC_DECODE_POSITION_START, read_pos=%d, reqSize=%d, m_size=%d", dec.read_pos, reqSize, dec.decoder.m_size.load());
*position = CELL_MUSIC_DECODE_POSITION_START;
}
else if (!dec.decoder.track_fully_decoded || size_left > reqSize) // track_fully_decoded is not guarded by a mutex, but since it is set to true after the decode, it should be fine.
{
cellMusicDecode.trace("cell_music_decode_read: position=CELL_MUSIC_DECODE_POSITION_MID, read_pos=%d, reqSize=%d, m_size=%d", dec.read_pos, reqSize, dec.decoder.m_size.load());
*position = CELL_MUSIC_DECODE_POSITION_MID;
}
else
{
if (dec.decoder.set_next_index(true) == umax)
{
cellMusicDecode.trace("cell_music_decode_read: position=CELL_MUSIC_DECODE_POSITION_END_LIST_END, read_pos=%d, reqSize=%d, m_size=%d", dec.read_pos, reqSize, dec.decoder.m_size.load());
*position = CELL_MUSIC_DECODE_POSITION_END_LIST_END;
}
else
{
cellMusicDecode.trace("cell_music_decode_read: position=CELL_MUSIC_DECODE_POSITION_END, read_pos=%d, reqSize=%d, m_size=%d", dec.read_pos, reqSize, dec.decoder.m_size.load());
*position = CELL_MUSIC_DECODE_POSITION_END;
}
}
const u64 size_to_read = std::min(reqSize, size_left);
*readSize = size_to_read;
if (size_to_read == 0)
{
return CELL_MUSIC_DECODE_ERROR_NO_LPCM_DATA; // TODO: speculative
}
std::memcpy(buf.get_ptr(), &dec.decoder.data[dec.read_pos], size_to_read);
if (size_to_read < reqSize)
{
// Set the rest of the buffer to zero to prevent loud pops at the end of the stream if the game ignores the readSize.
std::memset(vm::static_ptr_cast<u8>(buf).get_ptr() + size_to_read, 0, reqSize - size_to_read);
}
dec.read_pos += size_to_read;
s64 start_time_ms = 0;
if (!dec.decoder.timestamps_ms.empty())
{
start_time_ms = dec.decoder.timestamps_ms.front().second;
while (dec.decoder.timestamps_ms.size() > 1 && dec.read_pos >= ::at32(dec.decoder.timestamps_ms, 1).first)
{
dec.decoder.timestamps_ms.pop_front();
}
}
*startTime = static_cast<u32>(start_time_ms); // startTime is milliseconds
switch (*position)
{
case CELL_MUSIC_DECODE_POSITION_END_LIST_END:
{
// Reset the decoder and the decode status
ensure(dec.set_decode_command(CELL_MUSIC_DECODE_CMD_STOP) == CELL_OK);
dec.read_pos = 0;
break;
}
case CELL_MUSIC_DECODE_POSITION_END:
{
dec.read_pos = 0;
dec.decoder.clear();
dec.decoder.track_fully_consumed = 1;
dec.decoder.track_fully_consumed.notify_one();
break;
}
default:
{
break;
}
}
cellMusicDecode.trace("cell_music_decode_read(size_to_read=%d, samples=%d, start_time_ms=%d)", size_to_read, size_to_read / sizeof(u64), start_time_ms);
return CELL_OK;
}
error_code cellMusicDecodeInitialize(s32 mode, u32 container, s32 spuPriority, vm::ptr<CellMusicDecodeCallback> func, vm::ptr<void> userData)
{
cellMusicDecode.warning("cellMusicDecodeInitialize(mode=0x%x, container=0x%x, spuPriority=0x%x, func=*0x%x, userData=*0x%x)", mode, container, spuPriority, func, userData);
if (mode != CELL_MUSIC_DECODE2_MODE_NORMAL || (spuPriority - 0x10U > 0xef) || !func)
{
return CELL_MUSIC_DECODE_ERROR_PARAM;
}
auto& dec = g_fxo->get<music_decode>();
std::lock_guard lock(dec.mutex);
dec.func = func;
dec.userData = userData;
sysutil_register_cb([&dec](ppu_thread& ppu) -> s32
{
dec.func(ppu, CELL_MUSIC_DECODE_EVENT_INITIALIZE_RESULT, vm::addr_t(CELL_OK), dec.userData);
return CELL_OK;
});
return CELL_OK;
}
error_code cellMusicDecodeInitializeSystemWorkload(s32 mode, u32 container, vm::ptr<CellMusicDecodeCallback> func, vm::ptr<void> userData, s32 spuUsageRate, vm::ptr<CellSpurs> spurs, vm::cptr<u8> priority, vm::cptr<struct CellSpursSystemWorkloadAttribute> attr)
{
cellMusicDecode.warning("cellMusicDecodeInitializeSystemWorkload(mode=0x%x, container=0x%x, func=*0x%x, userData=*0x%x, spuUsageRate=0x%x, spurs=*0x%x, priority=*0x%x, attr=*0x%x)", mode, container, func, userData, spuUsageRate, spurs, priority, attr);
if (mode != CELL_MUSIC_DECODE2_MODE_NORMAL || !func || (spuUsageRate - 1U > 99) || !spurs || !priority)
{
return CELL_MUSIC_DECODE_ERROR_PARAM;
}
auto& dec = g_fxo->get<music_decode>();
std::lock_guard lock(dec.mutex);
dec.func = func;
dec.userData = userData;
sysutil_register_cb([&dec](ppu_thread& ppu) -> s32
{
dec.func(ppu, CELL_MUSIC_DECODE_EVENT_INITIALIZE_RESULT, vm::addr_t(CELL_OK), dec.userData);
return CELL_OK;
});
return CELL_OK;
}
error_code cellMusicDecodeFinalize()
{
cellMusicDecode.todo("cellMusicDecodeFinalize()");
auto& dec = g_fxo->get<music_decode>();
std::lock_guard lock(dec.mutex);
dec.finalize();
if (dec.func)
{
sysutil_register_cb([&dec](ppu_thread& ppu) -> s32
{
dec.func(ppu, CELL_MUSIC_DECODE_EVENT_FINALIZE_RESULT, vm::addr_t(CELL_OK), dec.userData);
return CELL_OK;
});
}
return CELL_OK;
}
error_code cellMusicDecodeSelectContents()
{
cellMusicDecode.todo("cellMusicDecodeSelectContents()");
return cell_music_decode_select_contents<music_decode>();
}
error_code cellMusicDecodeSetDecodeCommand(s32 command)
{
cellMusicDecode.warning("cellMusicDecodeSetDecodeCommand(command=0x%x)", command);
if (command < CELL_MUSIC_DECODE_CMD_STOP || command > CELL_MUSIC_DECODE_CMD_PREV)
{
return CELL_MUSIC_DECODE_ERROR_PARAM;
}
auto& dec = g_fxo->get<music_decode>();
std::lock_guard lock(dec.mutex);
if (!dec.func)
return CELL_MUSIC_DECODE_ERROR_GENERIC;
error_code result = CELL_OK;
{
std::scoped_lock slock(dec.decoder.m_mtx);
result = dec.set_decode_command(command);
}
sysutil_register_cb([&dec, result](ppu_thread& ppu) -> s32
{
dec.func(ppu, CELL_MUSIC_DECODE_EVENT_SET_DECODE_COMMAND_RESULT, vm::addr_t(s32{result}), dec.userData);
return CELL_OK;
});
return CELL_OK;
}
error_code cellMusicDecodeGetDecodeStatus(vm::ptr<s32> status)
{
cellMusicDecode.todo("cellMusicDecodeGetDecodeStatus(status=*0x%x)", status);
if (!status)
return CELL_MUSIC_DECODE_ERROR_PARAM;
auto& dec = g_fxo->get<music_decode>();
std::lock_guard lock(dec.mutex);
*status = dec.decode_status;
cellMusicDecode.notice("cellMusicDecodeGetDecodeStatus: status=%d", *status);
return CELL_OK;
}
error_code cellMusicDecodeRead(vm::ptr<void> buf, vm::ptr<u32> startTime, u64 reqSize, vm::ptr<u64> readSize, vm::ptr<s32> position)
{
cellMusicDecode.trace("cellMusicDecodeRead(buf=*0x%x, startTime=*0x%x, reqSize=0x%llx, readSize=*0x%x, position=*0x%x)", buf, startTime, reqSize, readSize, position);
return cell_music_decode_read<music_decode>(buf, startTime, reqSize, readSize, position);
}
error_code cellMusicDecodeGetSelectionContext(vm::ptr<CellMusicSelectionContext> context)
{
cellMusicDecode.todo("cellMusicDecodeGetSelectionContext(context=*0x%x)", context);
if (!context)
return CELL_MUSIC_DECODE_ERROR_PARAM;
auto& dec = g_fxo->get<music_decode>();
std::lock_guard lock(dec.mutex);
*context = dec.current_selection_context.get();
cellMusicDecode.warning("cellMusicDecodeGetSelectionContext: selection_context = %s", dec.current_selection_context.to_string());
return CELL_OK;
}
error_code cellMusicDecodeSetSelectionContext(vm::ptr<CellMusicSelectionContext> context)
{
cellMusicDecode.todo("cellMusicDecodeSetSelectionContext(context=*0x%x)", context);
if (!context)
return CELL_MUSIC_DECODE_ERROR_PARAM;
auto& dec = g_fxo->get<music_decode>();
std::lock_guard lock(dec.mutex);
if (!dec.func)
return CELL_MUSIC_DECODE_ERROR_GENERIC;
const bool result = dec.current_selection_context.set(*context);
if (result) cellMusicDecode.warning("cellMusicDecodeSetSelectionContext: new selection_context = %s", dec.current_selection_context.to_string());
else cellMusicDecode.error("cellMusicDecodeSetSelectionContext: failed. context = '%s'", music_selection_context::context_to_hex(*context));
sysutil_register_cb([&dec, result](ppu_thread& ppu) -> s32
{
const u32 status = result ? u32{CELL_OK} : u32{CELL_MUSIC_DECODE_ERROR_INVALID_CONTEXT};
dec.func(ppu, CELL_MUSIC_DECODE_EVENT_SET_SELECTION_CONTEXT_RESULT, vm::addr_t(status), dec.userData);
return CELL_OK;
});
return CELL_OK;
}
error_code cellMusicDecodeGetContentsId(vm::ptr<CellSearchContentId> contents_id)
{
cellMusicDecode.todo("cellMusicDecodeGetContentsId(contents_id=*0x%x)", contents_id);
if (!contents_id)
return CELL_MUSIC_DECODE_ERROR_PARAM;
// HACKY
auto& dec = g_fxo->get<music_decode>();
std::lock_guard lock(dec.mutex);
return dec.current_selection_context.find_content_id(contents_id);
}
error_code cellMusicDecodeInitialize2(s32 mode, u32 container, s32 spuPriority, vm::ptr<CellMusicDecode2Callback> func, vm::ptr<void> userData, s32 speed, s32 bufSize)
{
cellMusicDecode.warning("cellMusicDecodeInitialize2(mode=0x%x, container=0x%x, spuPriority=0x%x, func=*0x%x, userData=*0x%x, speed=0x%x, bufSize=0x%x)", mode, container, spuPriority, func, userData, speed, bufSize);
if (mode != CELL_MUSIC_DECODE2_MODE_NORMAL || (spuPriority - 0x10U > 0xef) ||
bufSize < CELL_MUSIC_DECODE2_MIN_BUFFER_SIZE || !func ||
(speed != CELL_MUSIC_DECODE2_SPEED_MAX && speed != CELL_MUSIC_DECODE2_SPEED_2))
{
return CELL_MUSIC_DECODE_ERROR_PARAM;
}
auto& dec = g_fxo->get<music_decode2>();
std::lock_guard lock(dec.mutex);
dec.func = func;
dec.userData = userData;
dec.speed = speed;
sysutil_register_cb([userData, &dec](ppu_thread& ppu) -> s32
{
dec.func(ppu, CELL_MUSIC_DECODE_EVENT_INITIALIZE_RESULT, vm::addr_t(CELL_OK), userData);
return CELL_OK;
});
return CELL_OK;
}
error_code cellMusicDecodeInitialize2SystemWorkload(s32 mode, u32 container, vm::ptr<CellMusicDecode2Callback> func, vm::ptr<void> userData, s32 spuUsageRate, s32 bufSize, vm::ptr<CellSpurs> spurs, vm::cptr<u8> priority, vm::cptr<CellSpursSystemWorkloadAttribute> attr)
{
cellMusicDecode.warning("cellMusicDecodeInitialize2SystemWorkload(mode=0x%x, container=0x%x, func=*0x%x, userData=*0x%x, spuUsageRate=0x%x, bufSize=0x%x, spurs=*0x%x, priority=*0x%x, attr=*0x%x)", mode, container, func, userData, spuUsageRate, bufSize, spurs, priority, attr);
if (mode != CELL_MUSIC_DECODE2_MODE_NORMAL || !func || (spuUsageRate - 1U > 99) ||
bufSize < CELL_MUSIC_DECODE2_MIN_BUFFER_SIZE || !spurs || !priority)
{
return CELL_MUSIC_DECODE_ERROR_PARAM;
}
auto& dec = g_fxo->get<music_decode2>();
std::lock_guard lock(dec.mutex);
dec.func = func;
dec.userData = userData;
sysutil_register_cb([&dec](ppu_thread& ppu) -> s32
{
dec.func(ppu, CELL_MUSIC_DECODE_EVENT_INITIALIZE_RESULT, vm::addr_t(CELL_OK), dec.userData);
return CELL_OK;
});
return CELL_OK;
}
error_code cellMusicDecodeFinalize2()
{
cellMusicDecode.todo("cellMusicDecodeFinalize2()");
auto& dec = g_fxo->get<music_decode2>();
std::lock_guard lock(dec.mutex);
dec.finalize();
if (dec.func)
{
sysutil_register_cb([&dec](ppu_thread& ppu) -> s32
{
dec.func(ppu, CELL_MUSIC_DECODE_EVENT_FINALIZE_RESULT, vm::addr_t(CELL_OK), dec.userData);
return CELL_OK;
});
}
return CELL_OK;
}
error_code cellMusicDecodeSelectContents2()
{
cellMusicDecode.todo("cellMusicDecodeSelectContents2()");
return cell_music_decode_select_contents<music_decode2>();
}
error_code cellMusicDecodeSetDecodeCommand2(s32 command)
{
cellMusicDecode.warning("cellMusicDecodeSetDecodeCommand2(command=0x%x)", command);
if (command < CELL_MUSIC_DECODE_CMD_STOP || command > CELL_MUSIC_DECODE_CMD_PREV)
{
return CELL_MUSIC_DECODE_ERROR_PARAM;
}
auto& dec = g_fxo->get<music_decode2>();
std::lock_guard lock(dec.mutex);
if (!dec.func)
return CELL_MUSIC_DECODE_ERROR_GENERIC;
error_code result = CELL_OK;
{
std::scoped_lock slock(dec.decoder.m_mtx);
result = dec.set_decode_command(command);
}
sysutil_register_cb([&dec, result](ppu_thread& ppu) -> s32
{
dec.func(ppu, CELL_MUSIC_DECODE_EVENT_SET_DECODE_COMMAND_RESULT, vm::addr_t(s32{result}), dec.userData);
return CELL_OK;
});
return CELL_OK;
}
error_code cellMusicDecodeGetDecodeStatus2(vm::ptr<s32> status)
{
cellMusicDecode.todo("cellMusicDecodeGetDecodeStatus2(status=*0x%x)", status);
if (!status)
return CELL_MUSIC_DECODE_ERROR_PARAM;
auto& dec = g_fxo->get<music_decode2>();
std::lock_guard lock(dec.mutex);
*status = dec.decode_status;
cellMusicDecode.notice("cellMusicDecodeGetDecodeStatus2: status=%d", *status);
return CELL_OK;
}
error_code cellMusicDecodeRead2(vm::ptr<void> buf, vm::ptr<u32> startTime, u64 reqSize, vm::ptr<u64> readSize, vm::ptr<s32> position)
{
cellMusicDecode.trace("cellMusicDecodeRead2(buf=*0x%x, startTime=*0x%x, reqSize=0x%llx, readSize=*0x%x, position=*0x%x)", buf, startTime, reqSize, readSize, position);
return cell_music_decode_read<music_decode2>(buf, startTime, reqSize, readSize, position);
}
error_code cellMusicDecodeGetSelectionContext2(vm::ptr<CellMusicSelectionContext> context)
{
cellMusicDecode.todo("cellMusicDecodeGetSelectionContext2(context=*0x%x)", context);
if (!context)
return CELL_MUSIC_DECODE_ERROR_PARAM;
auto& dec = g_fxo->get<music_decode2>();
std::lock_guard lock(dec.mutex);
*context = dec.current_selection_context.get();
cellMusicDecode.warning("cellMusicDecodeGetSelectionContext2: selection context = %s)", dec.current_selection_context.to_string());
return CELL_OK;
}
error_code cellMusicDecodeSetSelectionContext2(vm::ptr<CellMusicSelectionContext> context)
{
cellMusicDecode.todo("cellMusicDecodeSetSelectionContext2(context=*0x%x)", context);
if (!context)
return CELL_MUSIC_DECODE_ERROR_PARAM;
auto& dec = g_fxo->get<music_decode2>();
std::lock_guard lock(dec.mutex);
if (!dec.func)
return CELL_MUSIC_DECODE_ERROR_GENERIC;
const bool result = dec.current_selection_context.set(*context);
if (result) cellMusicDecode.warning("cellMusicDecodeSetSelectionContext2: new selection_context = %s", dec.current_selection_context.to_string());
else cellMusicDecode.error("cellMusicDecodeSetSelectionContext2: failed. context = '%s'", music_selection_context::context_to_hex(*context));
sysutil_register_cb([&dec, result](ppu_thread& ppu) -> s32
{
const u32 status = result ? u32{CELL_OK} : u32{CELL_MUSIC_DECODE_ERROR_INVALID_CONTEXT};
dec.func(ppu, CELL_MUSIC_DECODE_EVENT_SET_SELECTION_CONTEXT_RESULT, vm::addr_t(status), dec.userData);
return CELL_OK;
});
return CELL_OK;
}
error_code cellMusicDecodeGetContentsId2(vm::ptr<CellSearchContentId> contents_id)
{
cellMusicDecode.todo("cellMusicDecodeGetContentsId2(contents_id=*0x%x)", contents_id);
if (!contents_id)
return CELL_MUSIC_DECODE_ERROR_PARAM;
// HACKY
auto& dec = g_fxo->get<music_decode2>();
std::lock_guard lock(dec.mutex);
return dec.current_selection_context.find_content_id(contents_id);
}
DECLARE(ppu_module_manager::cellMusicDecode)("cellMusicDecodeUtility", []()
{
REG_FUNC(cellMusicDecodeUtility, cellMusicDecodeInitialize);
REG_FUNC(cellMusicDecodeUtility, cellMusicDecodeInitializeSystemWorkload);
REG_FUNC(cellMusicDecodeUtility, cellMusicDecodeFinalize);
REG_FUNC(cellMusicDecodeUtility, cellMusicDecodeSelectContents);
REG_FUNC(cellMusicDecodeUtility, cellMusicDecodeSetDecodeCommand);
REG_FUNC(cellMusicDecodeUtility, cellMusicDecodeGetDecodeStatus);
REG_FUNC(cellMusicDecodeUtility, cellMusicDecodeRead);
REG_FUNC(cellMusicDecodeUtility, cellMusicDecodeGetSelectionContext);
REG_FUNC(cellMusicDecodeUtility, cellMusicDecodeSetSelectionContext);
REG_FUNC(cellMusicDecodeUtility, cellMusicDecodeGetContentsId);
REG_FUNC(cellMusicDecodeUtility, cellMusicDecodeInitialize2);
REG_FUNC(cellMusicDecodeUtility, cellMusicDecodeInitialize2SystemWorkload);
REG_FUNC(cellMusicDecodeUtility, cellMusicDecodeFinalize2);
REG_FUNC(cellMusicDecodeUtility, cellMusicDecodeSelectContents2);
REG_FUNC(cellMusicDecodeUtility, cellMusicDecodeSetDecodeCommand2);
REG_FUNC(cellMusicDecodeUtility, cellMusicDecodeGetDecodeStatus2);
REG_FUNC(cellMusicDecodeUtility, cellMusicDecodeRead2);
REG_FUNC(cellMusicDecodeUtility, cellMusicDecodeGetSelectionContext2);
REG_FUNC(cellMusicDecodeUtility, cellMusicDecodeSetSelectionContext2);
REG_FUNC(cellMusicDecodeUtility, cellMusicDecodeGetContentsId2);
});
| 21,554
|
C++
|
.cpp
| 539
| 37.406308
| 277
| 0.749665
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
5,258
|
sysPrxForUser.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/sysPrxForUser.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
#include "Emu/Cell/timers.hpp"
#include "Emu/Cell/lv2/sys_mutex.h"
#include "Emu/Cell/lv2/sys_interrupt.h"
#include "Emu/Cell/lv2/sys_process.h"
#include "Emu/Cell/lv2/sys_ss.h"
#include "Emu/Cell/lv2/sys_tty.h"
#include "sysPrxForUser.h"
LOG_CHANNEL(sysPrxForUser);
vm::gvar<s32> sys_prx_version; // ???
vm::gvar<vm::ptr<void()>> g_ppu_atexitspawn;
vm::gvar<vm::ptr<void()>> g_ppu_at_Exitspawn;
extern vm::gvar<u32> g_ppu_exit_mutex;
u64 sys_time_get_system_time()
{
sysPrxForUser.trace("sys_time_get_system_time()");
return get_guest_system_time();
}
void sys_process_exit(ppu_thread& ppu, s32 status)
{
sysPrxForUser.warning("sys_process_exit(status=%d)", status);
sys_mutex_lock(ppu, *g_ppu_exit_mutex, 0);
// TODO (process atexit)
return _sys_process_exit(ppu, status, 0, 0);
}
void _sys_process_atexitspawn(vm::ptr<void()> func)
{
sysPrxForUser.warning("_sys_process_atexitspawn(0x%x)", func);
if (!*g_ppu_atexitspawn)
{
*g_ppu_atexitspawn = func;
}
}
void _sys_process_at_Exitspawn(vm::ptr<void()> func)
{
sysPrxForUser.warning("_sys_process_at_Exitspawn(0x%x)", func);
if (!*g_ppu_at_Exitspawn)
{
*g_ppu_at_Exitspawn = func;
}
}
s32 sys_process_is_stack(u32 p)
{
sysPrxForUser.trace("sys_process_is_stack(p=0x%x)", p);
// prx: compare high 4 bits with "0xD"
return (p >> 28) == 0xD;
}
error_code sys_process_get_paramsfo(vm::ptr<char> buffer)
{
sysPrxForUser.warning("sys_process_get_paramsfo(buffer=*0x%x)", buffer);
// prx: load some data (0x40 bytes) previously set by _sys_process_get_paramsfo syscall
return _sys_process_get_paramsfo(buffer);
}
error_code sys_get_random_number(vm::ptr<void> addr, u64 size)
{
sysPrxForUser.warning("sys_get_random_number(addr=*0x%x, size=%d)", addr, size);
if (size > RANDOM_NUMBER_MAX_SIZE)
{
return CELL_EINVAL;
}
switch (u32 rs = sys_ss_random_number_generator(2, addr, size))
{
case 0x80010501: return CELL_ENOMEM;
case 0x80010503: return CELL_EAGAIN;
case 0x80010509: return CELL_EINVAL;
default: if (rs) return CELL_EABORT;
}
return CELL_OK;
}
error_code console_getc()
{
sysPrxForUser.todo("console_getc()");
return CELL_OK;
}
void console_putc(ppu_thread& ppu, char ch)
{
sysPrxForUser.trace("console_putc(ch=0x%x)", ch);
sys_tty_write(ppu, 0, vm::var<char>(ch), 1, vm::var<u32>{});
}
error_code console_write(ppu_thread& ppu, vm::ptr<char> data, u32 len)
{
sysPrxForUser.trace("console_write(data=*0x%x, len=%d)", data, len);
sys_tty_write(ppu, 0, data, len, vm::var<u32>{});
return CELL_OK;
}
error_code cellGamePs1Emu_61CE2BCD()
{
UNIMPLEMENTED_FUNC(sysPrxForUser);
return CELL_OK;
}
error_code cellSysconfPs1emu_639ABBDE()
{
UNIMPLEMENTED_FUNC(sysPrxForUser);
return CELL_OK;
}
error_code cellSysconfPs1emu_6A12D11F()
{
UNIMPLEMENTED_FUNC(sysPrxForUser);
return CELL_OK;
}
error_code cellSysconfPs1emu_83E79A23()
{
UNIMPLEMENTED_FUNC(sysPrxForUser);
return CELL_OK;
}
error_code cellSysconfPs1emu_EFDDAF6C()
{
UNIMPLEMENTED_FUNC(sysPrxForUser);
return CELL_OK;
}
error_code sys_lv2coredump_D725F320()
{
sysPrxForUser.fatal("sys_lv2coredump_D725F320");
return CELL_OK;
}
error_code sys_get_bd_media_id()
{
UNIMPLEMENTED_FUNC(sysPrxForUser);
return CELL_OK;
}
error_code sys_get_console_id()
{
UNIMPLEMENTED_FUNC(sysPrxForUser);
return CELL_OK;
}
error_code sysPs2Disc_A84FD3C3()
{
UNIMPLEMENTED_FUNC(sysPrxForUser);
return CELL_OK;
}
error_code sysPs2Disc_BB7CD1AE()
{
UNIMPLEMENTED_FUNC(sysPrxForUser);
return CELL_OK;
}
extern void sysPrxForUser_sys_lwmutex_init(ppu_static_module*);
extern void sysPrxForUser_sys_lwcond_init(ppu_static_module*);
extern void sysPrxForUser_sys_ppu_thread_init();
extern void sysPrxForUser_sys_prx_init();
extern void sysPrxForUser_sys_heap_init();
extern void sysPrxForUser_sys_spinlock_init();
extern void sysPrxForUser_sys_mmapper_init();
extern void sysPrxForUser_sys_mempool_init();
extern void sysPrxForUser_sys_spu_init();
extern void sysPrxForUser_sys_game_init();
extern void sysPrxForUser_sys_libc_init();
extern void sysPrxForUser_sys_rsxaudio_init();
DECLARE(ppu_module_manager::sysPrxForUser)("sysPrxForUser", [](ppu_static_module* _this)
{
static ppu_static_module cellGamePs1Emu("cellGamePs1Emu", []()
{
REG_FNID(cellGamePs1Emu, 0x61CE2BCD, cellGamePs1Emu_61CE2BCD);
});
static ppu_static_module cellSysconfPs1emu("cellSysconfPs1emu", []()
{
REG_FNID(cellSysconfPs1emu, 0x639ABBDE, cellSysconfPs1emu_639ABBDE);
REG_FNID(cellSysconfPs1emu, 0x6A12D11F, cellSysconfPs1emu_6A12D11F);
REG_FNID(cellSysconfPs1emu, 0x83E79A23, cellSysconfPs1emu_83E79A23);
REG_FNID(cellSysconfPs1emu, 0xEFDDAF6C, cellSysconfPs1emu_EFDDAF6C);
});
static ppu_static_module sys_lv2coredump("sys_lv2coredump", []()
{
REG_FNID(sys_lv2coredump, 0xD725F320, sys_lv2coredump_D725F320);
});
static ppu_static_module sysBdMediaId("sysBdMediaId", []()
{
REG_FUNC(sysBdMediaId, sys_get_bd_media_id);
});
static ppu_static_module sysConsoleId("sysConsoleId", []()
{
REG_FUNC(sysConsoleId, sys_get_console_id);
});
static ppu_static_module sysPs2Disc("sysPs2Disc", []()
{
REG_FNID(sysPs2Disc, 0xA84FD3C3, sysPs2Disc_A84FD3C3);
REG_FNID(sysPs2Disc, 0xBB7CD1AE, sysPs2Disc_BB7CD1AE);
});
sysPrxForUser_sys_lwmutex_init(_this);
sysPrxForUser_sys_lwcond_init(_this);
sysPrxForUser_sys_ppu_thread_init();
sysPrxForUser_sys_prx_init();
sysPrxForUser_sys_heap_init();
sysPrxForUser_sys_spinlock_init();
sysPrxForUser_sys_mmapper_init();
sysPrxForUser_sys_mempool_init();
sysPrxForUser_sys_spu_init();
sysPrxForUser_sys_game_init();
sysPrxForUser_sys_libc_init();
sysPrxForUser_sys_rsxaudio_init();
REG_VAR(sysPrxForUser, sys_prx_version); // 0x7df066cf
REG_VAR(sysPrxForUser, g_ppu_atexitspawn).flag(MFF_HIDDEN);
REG_VAR(sysPrxForUser, g_ppu_at_Exitspawn).flag(MFF_HIDDEN);
REG_FUNC(sysPrxForUser, sys_time_get_system_time);
REG_FUNC(sysPrxForUser, sys_process_exit);
REG_FUNC(sysPrxForUser, _sys_process_atexitspawn);
REG_FUNC(sysPrxForUser, _sys_process_at_Exitspawn);
REG_FUNC(sysPrxForUser, sys_process_is_stack);
REG_FUNC(sysPrxForUser, sys_process_get_paramsfo); // 0xe75c40f2
REG_FUNC(sysPrxForUser, sys_get_random_number);
REG_FUNC(sysPrxForUser, console_getc);
REG_FUNC(sysPrxForUser, console_putc);
REG_FUNC(sysPrxForUser, console_write);
});
| 6,341
|
C++
|
.cpp
| 204
| 29.230392
| 88
| 0.76178
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| false
| false
|
5,259
|
cellJpgDec.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellJpgDec.cpp
|
#include "stdafx.h"
#include "Emu/VFS.h"
#include "Emu/IdManager.h"
#include "Emu/Cell/PPUModule.h"
// STB_IMAGE_IMPLEMENTATION is already defined in stb_image.cpp
#include <stb_image.h>
#include "Emu/Cell/lv2/sys_fs.h"
#include "cellJpgDec.h"
#include "util/asm.hpp"
LOG_CHANNEL(cellJpgDec);
// Temporarily
#ifndef _MSC_VER
#pragma GCC diagnostic ignored "-Wunused-parameter"
#endif
template <>
void fmt_class_string<CellJpgDecError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_JPGDEC_ERROR_HEADER);
STR_CASE(CELL_JPGDEC_ERROR_STREAM_FORMAT);
STR_CASE(CELL_JPGDEC_ERROR_ARG);
STR_CASE(CELL_JPGDEC_ERROR_SEQ);
STR_CASE(CELL_JPGDEC_ERROR_BUSY);
STR_CASE(CELL_JPGDEC_ERROR_FATAL);
STR_CASE(CELL_JPGDEC_ERROR_OPEN_FILE);
STR_CASE(CELL_JPGDEC_ERROR_SPU_UNSUPPORT);
STR_CASE(CELL_JPGDEC_ERROR_CB_PARAM);
}
return unknown;
});
}
error_code cellJpgDecCreate(u32 mainHandle, u32 threadInParam, u32 threadOutParam)
{
UNIMPLEMENTED_FUNC(cellJpgDec);
return CELL_OK;
}
error_code cellJpgDecExtCreate(u32 mainHandle, u32 threadInParam, u32 threadOutParam, u32 extThreadInParam, u32 extThreadOutParam)
{
UNIMPLEMENTED_FUNC(cellJpgDec);
return CELL_OK;
}
error_code cellJpgDecDestroy(u32 mainHandle)
{
UNIMPLEMENTED_FUNC(cellJpgDec);
return CELL_OK;
}
error_code cellJpgDecOpen(u32 mainHandle, vm::ptr<u32> subHandle, vm::ptr<CellJpgDecSrc> src, vm::ptr<CellJpgDecOpnInfo> openInfo)
{
cellJpgDec.warning("cellJpgDecOpen(mainHandle=0x%x, subHandle=*0x%x, src=*0x%x, openInfo=*0x%x)", mainHandle, subHandle, src, openInfo);
CellJpgDecSubHandle current_subHandle;
current_subHandle.fd = 0;
current_subHandle.src = *src;
switch (src->srcSelect)
{
case CELL_JPGDEC_BUFFER:
current_subHandle.fileSize = src->streamSize;
break;
case CELL_JPGDEC_FILE:
{
// Get file descriptor and size
const auto real_path = vfs::get(src->fileName.get_ptr());
fs::file file_s(real_path);
if (!file_s) return CELL_JPGDEC_ERROR_OPEN_FILE;
current_subHandle.fileSize = file_s.size();
current_subHandle.fd = idm::make<lv2_fs_object, lv2_file>(src->fileName.get_ptr(), std::move(file_s), 0, 0, real_path);
break;
}
default: break; // TODO
}
// From now, every u32 subHandle argument is a pointer to a CellJpgDecSubHandle struct.
*subHandle = idm::make<CellJpgDecSubHandle>(current_subHandle);
return CELL_OK;
}
error_code cellJpgDecExtOpen()
{
cellJpgDec.todo("cellJpgDecExtOpen()");
return CELL_OK;
}
error_code cellJpgDecClose(u32 mainHandle, u32 subHandle)
{
cellJpgDec.warning("cellJpgDecOpen(mainHandle=0x%x, subHandle=0x%x)", mainHandle, subHandle);
const auto subHandle_data = idm::get<CellJpgDecSubHandle>(subHandle);
if (!subHandle_data)
{
return CELL_JPGDEC_ERROR_FATAL;
}
idm::remove<lv2_fs_object, lv2_file>(subHandle_data->fd);
idm::remove<CellJpgDecSubHandle>(subHandle);
return CELL_OK;
}
error_code cellJpgDecReadHeader(u32 mainHandle, u32 subHandle, vm::ptr<CellJpgDecInfo> info)
{
cellJpgDec.trace("cellJpgDecReadHeader(mainHandle=0x%x, subHandle=0x%x, info=*0x%x)", mainHandle, subHandle, info);
const auto subHandle_data = idm::get<CellJpgDecSubHandle>(subHandle);
if (!subHandle_data)
{
return CELL_JPGDEC_ERROR_FATAL;
}
const u32& fd = subHandle_data->fd;
const u64& fileSize = subHandle_data->fileSize;
CellJpgDecInfo& current_info = subHandle_data->info;
// Write the header to buffer
std::unique_ptr<u8[]> buffer(new u8[fileSize]);
switch (subHandle_data->src.srcSelect)
{
case CELL_JPGDEC_BUFFER:
std::memcpy(buffer.get(), vm::base(subHandle_data->src.streamPtr), fileSize);
break;
case CELL_JPGDEC_FILE:
{
auto file = idm::get<lv2_fs_object, lv2_file>(fd);
file->file.seek(0);
file->file.read(buffer.get(), fileSize);
break;
}
default: break; // TODO
}
if (read_from_ptr<le_t<u32>>(buffer.get() + 0) != 0xE0FFD8FF || // Error: Not a valid SOI header
read_from_ptr<u32>(buffer.get() + 6) != "JFIF"_u32) // Error: Not a valid JFIF string
{
return CELL_JPGDEC_ERROR_HEADER;
}
u32 i = 4;
if(i >= fileSize)
return CELL_JPGDEC_ERROR_HEADER;
u16 block_length = buffer[i] * 0xFF + buffer[i+1];
while(true)
{
i += block_length; // Increase the file index to get to the next block
if (i >= fileSize || // Check to protect against segmentation faults
buffer[i] != 0xFF) // Check that we are truly at the start of another block
{
return CELL_JPGDEC_ERROR_HEADER;
}
if(buffer[i+1] == 0xC0)
break; // 0xFFC0 is the "Start of frame" marker which contains the file size
i += 2; // Skip the block marker
block_length = buffer[i] * 0xFF + buffer[i+1]; // Go to the next block
}
current_info.imageWidth = buffer[i+7]*0x100 + buffer[i+8];
current_info.imageHeight = buffer[i+5]*0x100 + buffer[i+6];
current_info.numComponents = 3; // Unimplemented
current_info.colorSpace = CELL_JPG_RGB;
*info = current_info;
return CELL_OK;
}
error_code cellJpgDecExtReadHeader()
{
cellJpgDec.todo("cellJpgDecExtReadHeader()");
return CELL_OK;
}
error_code cellJpgDecDecodeData(u32 mainHandle, u32 subHandle, vm::ptr<u8> data, vm::cptr<CellJpgDecDataCtrlParam> dataCtrlParam, vm::ptr<CellJpgDecDataOutInfo> dataOutInfo)
{
cellJpgDec.trace("cellJpgDecDecodeData(mainHandle=0x%x, subHandle=0x%x, data=*0x%x, dataCtrlParam=*0x%x, dataOutInfo=*0x%x)", mainHandle, subHandle, data, dataCtrlParam, dataOutInfo);
dataOutInfo->status = CELL_JPGDEC_DEC_STATUS_STOP;
const auto subHandle_data = idm::get<CellJpgDecSubHandle>(subHandle);
if (!subHandle_data)
{
return CELL_JPGDEC_ERROR_FATAL;
}
const u32& fd = subHandle_data->fd;
const u64& fileSize = subHandle_data->fileSize;
const CellJpgDecOutParam& current_outParam = subHandle_data->outParam;
//Copy the JPG file to a buffer
std::unique_ptr<u8[]> jpg(new u8[fileSize]);
switch (subHandle_data->src.srcSelect)
{
case CELL_JPGDEC_BUFFER:
std::memcpy(jpg.get(), vm::base(subHandle_data->src.streamPtr), fileSize);
break;
case CELL_JPGDEC_FILE:
{
auto file = idm::get<lv2_fs_object, lv2_file>(fd);
file->file.seek(0);
file->file.read(jpg.get(), fileSize);
break;
}
default: break; // TODO
}
//Decode JPG file. (TODO: Is there any faster alternative? Can we do it without external libraries?)
int width, height, actual_components;
auto image = std::unique_ptr<unsigned char,decltype(&::free)>
(
stbi_load_from_memory(jpg.get(), ::narrow<int>(fileSize), &width, &height, &actual_components, 4),
&::free
);
if (!image)
return CELL_JPGDEC_ERROR_STREAM_FORMAT;
const bool flip = current_outParam.outputMode == CELL_JPGDEC_BOTTOM_TO_TOP;
const int bytesPerLine = static_cast<int>(dataCtrlParam->outputBytesPerLine);
usz image_size = width * height;
switch(current_outParam.outputColorSpace)
{
case CELL_JPG_RGB:
case CELL_JPG_RGBA:
{
const char nComponents = current_outParam.outputColorSpace == CELL_JPG_RGBA ? 4 : 3;
image_size *= nComponents;
if (bytesPerLine > width * nComponents || flip) //check if we need padding
{
const int linesize = std::min(bytesPerLine, width * nComponents);
for (int i = 0; i < height; i++)
{
const int dstOffset = i * bytesPerLine;
const int srcOffset = width * nComponents * (flip ? height - i - 1 : i);
memcpy(&data[dstOffset], &image.get()[srcOffset], linesize);
}
}
else
{
memcpy(data.get_ptr(), image.get(), image_size);
}
}
break;
case CELL_JPG_ARGB:
{
const int nComponents = 4;
image_size *= nComponents;
if (bytesPerLine > width * nComponents || flip) //check if we need padding
{
//TODO: Find out if we can't do padding without an extra copy
const int linesize = std::min(bytesPerLine, width * nComponents);
const auto output = std::make_unique<char[]>(linesize);
for (int i = 0; i < height; i++)
{
const int dstOffset = i * bytesPerLine;
const int srcOffset = width * nComponents * (flip ? height - i - 1 : i);
for (int j = 0; j < linesize; j += nComponents)
{
output[j + 0] = image.get()[srcOffset + j + 3];
output[j + 1] = image.get()[srcOffset + j + 0];
output[j + 2] = image.get()[srcOffset + j + 1];
output[j + 3] = image.get()[srcOffset + j + 2];
}
std::memcpy(&data[dstOffset], output.get(), linesize);
}
}
else
{
const auto img = std::make_unique<uint[]>(image_size);
uint* source_current = reinterpret_cast<uint*>(image.get());
uint* dest_current = img.get();
for (uint i = 0; i < image_size / nComponents; i++)
{
uint val = *source_current;
*dest_current = (val >> 24) | (val << 8); // set alpha (A8) as leftmost byte
source_current++;
dest_current++;
}
std::memcpy(data.get_ptr(), img.get(), image_size);
}
}
break;
case CELL_JPG_GRAYSCALE:
case CELL_JPG_YCbCr:
case CELL_JPG_UPSAMPLE_ONLY:
case CELL_JPG_GRAYSCALE_TO_ALPHA_RGBA:
case CELL_JPG_GRAYSCALE_TO_ALPHA_ARGB:
cellJpgDec.error("cellJpgDecDecodeData: Unsupported color space (%d)", current_outParam.outputColorSpace);
break;
default:
return CELL_JPGDEC_ERROR_ARG;
}
dataOutInfo->status = CELL_JPGDEC_DEC_STATUS_FINISH;
if(dataCtrlParam->outputBytesPerLine)
dataOutInfo->outputLines = static_cast<u32>(image_size / dataCtrlParam->outputBytesPerLine);
return CELL_OK;
}
error_code cellJpgDecExtDecodeData()
{
cellJpgDec.todo("cellJpgDecExtDecodeData()");
return CELL_OK;
}
error_code cellJpgDecSetParameter(u32 mainHandle, u32 subHandle, vm::cptr<CellJpgDecInParam> inParam, vm::ptr<CellJpgDecOutParam> outParam)
{
cellJpgDec.trace("cellJpgDecSetParameter(mainHandle=0x%x, subHandle=0x%x, inParam=*0x%x, outParam=*0x%x)", mainHandle, subHandle, inParam, outParam);
const auto subHandle_data = idm::get<CellJpgDecSubHandle>(subHandle);
if (!subHandle_data)
{
return CELL_JPGDEC_ERROR_FATAL;
}
CellJpgDecInfo& current_info = subHandle_data->info;
CellJpgDecOutParam& current_outParam = subHandle_data->outParam;
current_outParam.outputWidthByte = (current_info.imageWidth * current_info.numComponents);
current_outParam.outputWidth = current_info.imageWidth;
current_outParam.outputHeight = current_info.imageHeight;
current_outParam.outputColorSpace = inParam->outputColorSpace;
switch (current_outParam.outputColorSpace)
{
case CELL_JPG_GRAYSCALE: current_outParam.outputComponents = 1; break;
case CELL_JPG_RGB:
case CELL_JPG_YCbCr: current_outParam.outputComponents = 3; break;
case CELL_JPG_UPSAMPLE_ONLY: current_outParam.outputComponents = current_info.numComponents; break;
case CELL_JPG_RGBA:
case CELL_JPG_ARGB:
case CELL_JPG_GRAYSCALE_TO_ALPHA_RGBA:
case CELL_JPG_GRAYSCALE_TO_ALPHA_ARGB: current_outParam.outputComponents = 4; break;
default: return CELL_JPGDEC_ERROR_ARG; // Not supported color space
}
current_outParam.outputMode = inParam->outputMode;
current_outParam.downScale = inParam->downScale;
current_outParam.useMemorySpace = 0; // Unimplemented
*outParam = current_outParam;
return CELL_OK;
}
error_code cellJpgDecExtSetParameter()
{
cellJpgDec.todo("cellJpgDecExtSetParameter()");
return CELL_OK;
}
DECLARE(ppu_module_manager::cellJpgDec)("cellJpgDec", []()
{
REG_FUNC(cellJpgDec, cellJpgDecCreate);
REG_FUNC(cellJpgDec, cellJpgDecExtCreate);
REG_FUNC(cellJpgDec, cellJpgDecOpen);
REG_FUNC(cellJpgDec, cellJpgDecReadHeader);
REG_FUNC(cellJpgDec, cellJpgDecSetParameter);
REG_FUNC(cellJpgDec, cellJpgDecDecodeData);
REG_FUNC(cellJpgDec, cellJpgDecClose);
REG_FUNC(cellJpgDec, cellJpgDecDestroy);
REG_FUNC(cellJpgDec, cellJpgDecExtOpen);
REG_FUNC(cellJpgDec, cellJpgDecExtReadHeader);
REG_FUNC(cellJpgDec, cellJpgDecExtSetParameter);
REG_FUNC(cellJpgDec, cellJpgDecExtDecodeData);
});
| 11,948
|
C++
|
.cpp
| 328
| 33.814024
| 184
| 0.722752
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| false
| false
|
5,260
|
cellSysCache.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellSysCache.cpp
|
#include "stdafx.h"
#include "Emu/System.h"
#include "Emu/system_utils.hpp"
#include "Emu/VFS.h"
#include "Emu/IdManager.h"
#include "Emu/Cell/PPUModule.h"
#include "Emu/Cell/lv2/sys_fs.h"
#include "cellSysutil.h"
#include "util/init_mutex.hpp"
#include "Utilities/StrUtil.h"
LOG_CHANNEL(cellSysutil);
template<>
void fmt_class_string<CellSysCacheError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_SYSCACHE_ERROR_ACCESS_ERROR);
STR_CASE(CELL_SYSCACHE_ERROR_INTERNAL);
STR_CASE(CELL_SYSCACHE_ERROR_NOTMOUNTED);
STR_CASE(CELL_SYSCACHE_ERROR_PARAM);
}
return unknown;
});
}
extern lv2_fs_mount_point g_mp_sys_dev_hdd1;
extern std::string get_syscache_state_corruption_indicator_file_path(std::string_view dir_path);
struct syscache_info
{
const std::string cache_root = rpcs3::utils::get_hdd1_dir() + "/caches/";
stx::init_mutex init;
std::string cache_id;
bool retain_caches = false;
syscache_info() noexcept
{
// Check if dev_hdd1 is mounted by parent process
if (!Emu.hdd1.empty())
{
const auto lock = init.init();
// Extract cache id from path
std::string_view id = Emu.hdd1;
id = id.substr(0, id.find_last_not_of(fs::delim) + 1);
id = id.substr(id.find_last_of(fs::delim) + 1);
cache_id = std::string{id};
if (!Emu.DeserialManager() && !fs::write_file<true>(get_syscache_state_corruption_indicator_file_path(Emu.hdd1), fs::write_new))
{
fmt::throw_exception("Failed to create HDD1 corruption indicator file! (path='%s', reason='%s')", Emu.hdd1, fs::g_tls_error);
}
cellSysutil.success("Retained cache from parent process: %s", Emu.hdd1);
return;
}
// Find existing cache at startup
const std::string prefix = Emu.GetTitleID() + '_';
for (auto&& entry : fs::dir(cache_root))
{
if (entry.is_directory && entry.name.starts_with(prefix))
{
cache_id = vfs::unescape(entry.name);
if (fs::is_file(get_syscache_state_corruption_indicator_file_path(cache_root + '/' + cache_id)))
{
// State is not complete
clear(true);
cache_id.clear();
continue;
}
cellSysutil.notice("Retained cache from past data: %s", cache_root + '/' + cache_id);
break;
}
}
}
void clear(bool remove_root, bool lock = false) const noexcept
{
// Clear cache
if (!vfs::host::remove_all(cache_root + cache_id, cache_root, &g_mp_sys_dev_hdd1, remove_root, lock))
{
cellSysutil.fatal("cellSysCache: failed to clear cache directory '%s%s' (%s)", cache_root, cache_id, fs::g_tls_error);
}
// Poison opened files in /dev_hdd1 to return CELL_EIO on access
if (remove_root)
{
idm::select<lv2_fs_object, lv2_file>([](u32 /*id*/, lv2_file& file)
{
if (file.file && file.mp->flags & lv2_mp_flag::cache)
{
file.lock = 2;
}
});
}
}
~syscache_info() noexcept
{
if (cache_id.empty())
{
return;
}
if (!retain_caches)
{
vfs::host::remove_all(cache_root + cache_id, cache_root, &g_mp_sys_dev_hdd1, true, false, true);
return;
}
idm::select<lv2_fs_object, lv2_file>([](u32 /*id*/, lv2_file& file)
{
if (file.file && file.mp->flags & lv2_mp_flag::cache && file.flags & CELL_FS_O_ACCMODE)
{
file.file.sync();
}
});
fs::remove_file(get_syscache_state_corruption_indicator_file_path(cache_root + cache_id));
}
};
extern std::string get_syscache_state_corruption_indicator_file_path(std::string_view dir_path)
{
constexpr std::u8string_view append_path = u8"/$hdd0_temp_state_indicator";
const std::string_view filename = reinterpret_cast<const char*>(append_path.data());
if (dir_path.empty())
{
return rpcs3::utils::get_hdd1_dir() + "/caches/" + ensure(g_fxo->try_get<syscache_info>())->cache_id + "/" + filename.data();
}
return std::string{dir_path} + filename.data();
}
extern void signal_system_cache_can_stay()
{
ensure(g_fxo->try_get<syscache_info>())->retain_caches = true;
}
error_code cellSysCacheClear()
{
cellSysutil.notice("cellSysCacheClear()");
auto& cache = g_fxo->get<syscache_info>();
const auto lock = cache.init.access();
if (!lock)
{
return CELL_SYSCACHE_ERROR_NOTMOUNTED;
}
// Clear existing cache
if (!cache.cache_id.empty())
{
std::lock_guard lock0(g_mp_sys_dev_hdd1.mutex);
cache.clear(false);
}
return not_an_error(CELL_SYSCACHE_RET_OK_CLEARED);
}
error_code cellSysCacheMount(vm::ptr<CellSysCacheParam> param)
{
cellSysutil.notice("cellSysCacheMount(param=*0x%x ('%s'))", param, param.ptr(&CellSysCacheParam::cacheId));
auto& cache = g_fxo->get<syscache_info>();
if (!param)
{
return CELL_SYSCACHE_ERROR_PARAM;
}
std::string cache_name;
ensure(vm::read_string(param.ptr(&CellSysCacheParam::cacheId).addr(), sizeof(param->cacheId), cache_name), "Access violation");
if (!cache_name.empty() && sysutil_check_name_string(cache_name.data(), 1, CELL_SYSCACHE_ID_SIZE) != 0)
{
return CELL_SYSCACHE_ERROR_PARAM;
}
// Full virtualized cache id (with title id included)
std::string cache_id = vfs::escape(Emu.GetTitleID() + '_' + cache_name);
// Full path to virtual cache root (/dev_hdd1)
std::string new_path = cache.cache_root + cache_id + '/';
// Set fixed VFS path
strcpy_trunc(param->getCachePath, "/dev_hdd1");
// Lock pseudo-mutex
const auto lock = cache.init.init_always([&]
{
});
std::lock_guard lock0(g_mp_sys_dev_hdd1.mutex);
// Check if can reuse existing cache (won't if cache id is an empty string or cache is damaged/incomplete)
if (!cache_name.empty() && cache_id == cache.cache_id)
{
// Isn't mounted yet on first call to cellSysCacheMount
if (vfs::mount("/dev_hdd1", new_path))
g_fxo->get<lv2_fs_mount_info_map>().add("/dev_hdd1", &g_mp_sys_dev_hdd1);
cellSysutil.success("Mounted existing cache at %s", new_path);
return not_an_error(CELL_SYSCACHE_RET_OK_RELAYED);
}
const bool can_create = cache.cache_id != cache_id || !cache.cache_id.empty();
if (!cache.cache_id.empty())
{
// Clear previous cache
cache.clear(true);
}
// Set new cache id
cache.cache_id = std::move(cache_id);
if (can_create)
{
const bool created = fs::create_dir(new_path);
if (!created)
{
if (fs::g_tls_error != fs::error::exist)
{
fmt::throw_exception("Failed to create HDD1 cache! (path='%s', reason='%s')", new_path, fs::g_tls_error);
}
// Clear new cache
cache.clear(false);
}
}
if (!fs::write_file<true>(get_syscache_state_corruption_indicator_file_path(new_path), fs::write_new))
{
fmt::throw_exception("Failed to create HDD1 corruption indicator file! (path='%s', reason='%s')", new_path, fs::g_tls_error);
}
if (vfs::mount("/dev_hdd1", new_path))
g_fxo->get<lv2_fs_mount_info_map>().add("/dev_hdd1", &g_mp_sys_dev_hdd1);
return not_an_error(CELL_SYSCACHE_RET_OK_CLEARED);
}
extern void cellSysutil_SysCache_init()
{
REG_FUNC(cellSysutil, cellSysCacheMount);
REG_FUNC(cellSysutil, cellSysCacheClear);
}
| 6,931
|
C++
|
.cpp
| 210
| 30.071429
| 131
| 0.687528
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
5,261
|
sys_lwmutex_.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/sys_lwmutex_.cpp
|
#include "stdafx.h"
#include "Emu/System.h"
#include "Emu/system_config.h"
#include "Emu/Cell/PPUModule.h"
#include "Emu/Cell/lv2/sys_lwmutex.h"
#include "Emu/Cell/lv2/sys_mutex.h"
#include "sysPrxForUser.h"
#include "util/asm.hpp"
LOG_CHANNEL(sysPrxForUser);
error_code sys_lwmutex_create(ppu_thread& ppu, vm::ptr<sys_lwmutex_t> lwmutex, vm::ptr<sys_lwmutex_attribute_t> attr)
{
sysPrxForUser.trace("sys_lwmutex_create(lwmutex=*0x%x, attr=*0x%x)", lwmutex, attr);
const u32 recursive = attr->recursive;
if (recursive != SYS_SYNC_RECURSIVE && recursive != SYS_SYNC_NOT_RECURSIVE)
{
sysPrxForUser.error("sys_lwmutex_create(): invalid recursive attribute (0x%x)", recursive);
return CELL_EINVAL;
}
const u32 protocol = attr->protocol;
switch (protocol)
{
case SYS_SYNC_FIFO: break;
case SYS_SYNC_RETRY: break;
case SYS_SYNC_PRIORITY: break;
default: sysPrxForUser.error("sys_lwmutex_create(): invalid protocol (0x%x)", protocol); return CELL_EINVAL;
}
vm::var<u32> out_id;
vm::var<sys_mutex_attribute_t> attrs;
attrs->protocol = protocol == SYS_SYNC_FIFO ? SYS_SYNC_FIFO : SYS_SYNC_PRIORITY;
attrs->recursive = attr->recursive;
attrs->pshared = SYS_SYNC_NOT_PROCESS_SHARED;
attrs->adaptive = SYS_SYNC_NOT_ADAPTIVE;
attrs->ipc_key = 0;
attrs->flags = 0;
attrs->name_u64 = attr->name_u64;
if (error_code res = g_cfg.core.hle_lwmutex ? sys_mutex_create(ppu, out_id, attrs) : _sys_lwmutex_create(ppu, out_id, protocol, lwmutex, 0x80000001, std::bit_cast<be_t<u64>>(attr->name_u64)))
{
return res;
}
lwmutex->lock_var.store({ lwmutex_free, 0 });
lwmutex->attribute = attr->recursive | attr->protocol;
lwmutex->recursive_count = 0;
lwmutex->sleep_queue = *out_id;
return CELL_OK;
}
error_code sys_lwmutex_destroy(ppu_thread& ppu, vm::ptr<sys_lwmutex_t> lwmutex)
{
sysPrxForUser.trace("sys_lwmutex_destroy(lwmutex=*0x%x)", lwmutex);
if (g_cfg.core.hle_lwmutex)
{
return sys_mutex_destroy(ppu, lwmutex->sleep_queue);
}
// check to prevent recursive locking in the next call
if (lwmutex->vars.owner.load() == ppu.id)
{
return CELL_EBUSY;
}
// attempt to lock the mutex
if (error_code res = sys_lwmutex_trylock(ppu, lwmutex))
{
return res;
}
// call the syscall
if (error_code res = _sys_lwmutex_destroy(ppu, lwmutex->sleep_queue))
{
// unlock the mutex if failed
sys_lwmutex_unlock(ppu, lwmutex);
return res;
}
// deleting succeeded
lwmutex->vars.owner.release(lwmutex_dead);
return CELL_OK;
}
error_code sys_lwmutex_lock(ppu_thread& ppu, vm::ptr<sys_lwmutex_t> lwmutex, u64 timeout)
{
sysPrxForUser.trace("sys_lwmutex_lock(lwmutex=*0x%x, timeout=0x%llx)", lwmutex, timeout);
if (g_cfg.core.hle_lwmutex)
{
return sys_mutex_lock(ppu, lwmutex->sleep_queue, timeout);
}
auto& sstate = *ppu.optional_savestate_state;
const bool aborted = sstate.try_read<bool>().second;
if (aborted)
{
// Restore timeout (SYS_SYNC_RETRY mode)
sstate(timeout);
}
const be_t<u32> tid(ppu.id);
// try to lock lightweight mutex
const be_t<u32> old_owner = lwmutex->vars.owner.compare_and_swap(lwmutex_free, tid);
if (old_owner == lwmutex_free)
{
// locking succeeded
return CELL_OK;
}
if (old_owner == tid)
{
// recursive locking
if ((lwmutex->attribute & SYS_SYNC_RECURSIVE) == 0u)
{
// if not recursive
return CELL_EDEADLK;
}
if (lwmutex->recursive_count == umax)
{
// if recursion limit reached
return CELL_EKRESOURCE;
}
// recursive locking succeeded
lwmutex->recursive_count++;
atomic_fence_acq_rel();
return CELL_OK;
}
if (old_owner == lwmutex_dead)
{
// invalid or deleted mutex
return CELL_EINVAL;
}
for (u32 i = 0; i < 10; i++)
{
busy_wait();
if (lwmutex->vars.owner.load() == lwmutex_free)
{
if (lwmutex->vars.owner.compare_and_swap_test(lwmutex_free, tid))
{
// locking succeeded
return CELL_OK;
}
}
}
// atomically increment waiter value using 64 bit op
if (!aborted)
{
lwmutex->all_info++;
}
if (lwmutex->vars.owner.compare_and_swap_test(lwmutex_free, tid))
{
// locking succeeded
--lwmutex->all_info;
return CELL_OK;
}
// lock using the syscall
const error_code res = _sys_lwmutex_lock(ppu, lwmutex->sleep_queue, timeout);
static_cast<void>(ppu.test_stopped());
if (ppu.state & cpu_flag::again)
{
sstate.pos = 0;
sstate(true, timeout); // Aborted
return {};
}
lwmutex->all_info--;
if (res == CELL_OK)
{
// locking succeeded
auto old = lwmutex->vars.owner.exchange(tid);
if (old != lwmutex_reserved)
{
fmt::throw_exception("Locking failed (lwmutex=*0x%x, owner=0x%x)", lwmutex, old);
}
return CELL_OK;
}
if (res + 0u == CELL_EBUSY && lwmutex->attribute & SYS_SYNC_RETRY)
{
while (true)
{
for (u32 i = 0; i < 10; i++)
{
busy_wait();
if (lwmutex->vars.owner.load() == lwmutex_free)
{
if (lwmutex->vars.owner.compare_and_swap_test(lwmutex_free, tid))
{
return CELL_OK;
}
}
}
lwmutex->all_info++;
if (lwmutex->vars.owner.compare_and_swap_test(lwmutex_free, tid))
{
lwmutex->all_info--;
return CELL_OK;
}
const u64 time0 = timeout ? get_guest_system_time() : 0;
const error_code res_ = _sys_lwmutex_lock(ppu, lwmutex->sleep_queue, timeout);
static_cast<void>(ppu.test_stopped());
if (ppu.state & cpu_flag::again)
{
sstate.pos = 0;
sstate(true, timeout); // Aborted
return {};
}
if (res_ == CELL_OK)
{
lwmutex->vars.owner.release(tid);
}
else if (timeout && res_ + 0u != CELL_ETIMEDOUT)
{
const u64 time_diff = get_guest_system_time() - time0;
if (timeout <= time_diff)
{
lwmutex->all_info--;
return not_an_error(CELL_ETIMEDOUT);
}
timeout -= time_diff;
}
lwmutex->all_info--;
if (res_ + 0u != CELL_EBUSY)
{
return res_;
}
}
}
return res;
}
error_code sys_lwmutex_trylock(ppu_thread& ppu, vm::ptr<sys_lwmutex_t> lwmutex)
{
sysPrxForUser.trace("sys_lwmutex_trylock(lwmutex=*0x%x)", lwmutex);
if (g_cfg.core.hle_lwmutex)
{
return sys_mutex_trylock(ppu, lwmutex->sleep_queue);
}
const be_t<u32> tid(ppu.id);
// try to lock lightweight mutex
const be_t<u32> old_owner = lwmutex->vars.owner.compare_and_swap(lwmutex_free, tid);
if (old_owner == lwmutex_free)
{
// locking succeeded
return CELL_OK;
}
if (old_owner == tid)
{
// recursive locking
if ((lwmutex->attribute & SYS_SYNC_RECURSIVE) == 0u)
{
// if not recursive
return CELL_EDEADLK;
}
if (lwmutex->recursive_count == umax)
{
// if recursion limit reached
return CELL_EKRESOURCE;
}
// recursive locking succeeded
lwmutex->recursive_count++;
atomic_fence_acq_rel();
return CELL_OK;
}
if (old_owner == lwmutex_dead)
{
// invalid or deleted mutex
return CELL_EINVAL;
}
if (old_owner == lwmutex_reserved)
{
// should be locked by the syscall
const error_code res = _sys_lwmutex_trylock(ppu, lwmutex->sleep_queue);
if (res == CELL_OK)
{
// locking succeeded
auto old = lwmutex->vars.owner.exchange(tid);
if (old != lwmutex_reserved)
{
fmt::throw_exception("Locking failed (lwmutex=*0x%x, owner=0x%x)", lwmutex, old);
}
}
return res;
}
// locked by another thread
return not_an_error(CELL_EBUSY);
}
error_code sys_lwmutex_unlock(ppu_thread& ppu, vm::ptr<sys_lwmutex_t> lwmutex)
{
sysPrxForUser.trace("sys_lwmutex_unlock(lwmutex=*0x%x)", lwmutex);
if (g_cfg.core.hle_lwmutex)
{
return sys_mutex_unlock(ppu, lwmutex->sleep_queue);
}
const be_t<u32> tid(ppu.id);
// check owner
if (lwmutex->vars.owner.load() != tid)
{
return CELL_EPERM;
}
if (lwmutex->recursive_count)
{
// recursive unlocking succeeded
lwmutex->recursive_count--;
return CELL_OK;
}
// ensure that waiter is zero
if (lwmutex->lock_var.compare_and_swap_test({ tid, 0 }, { lwmutex_free, 0 }))
{
// unlocking succeeded
return CELL_OK;
}
if (lwmutex->attribute & SYS_SYNC_RETRY)
{
lwmutex->vars.owner.release(lwmutex_free);
// Call the alternative syscall
if (_sys_lwmutex_unlock2(ppu, lwmutex->sleep_queue) + 0u == CELL_ESRCH)
{
return CELL_ESRCH;
}
return CELL_OK;
}
// set special value
lwmutex->vars.owner.release(lwmutex_reserved);
// call the syscall
if (_sys_lwmutex_unlock(ppu, lwmutex->sleep_queue) + 0u == CELL_ESRCH)
{
return CELL_ESRCH;
}
return CELL_OK;
}
void sysPrxForUser_sys_lwmutex_init(ppu_static_module* _this)
{
REG_FUNC(sysPrxForUser, sys_lwmutex_create);
REG_FUNC(sysPrxForUser, sys_lwmutex_destroy);
REG_FUNC(sysPrxForUser, sys_lwmutex_lock);
REG_FUNC(sysPrxForUser, sys_lwmutex_trylock);
REG_FUNC(sysPrxForUser, sys_lwmutex_unlock);
_this->add_init_func([](ppu_static_module*)
{
REINIT_FUNC(sys_lwmutex_create).flag(g_cfg.core.hle_lwmutex ? MFF_FORCED_HLE : MFF_PERFECT);
REINIT_FUNC(sys_lwmutex_destroy).flag(g_cfg.core.hle_lwmutex ? MFF_FORCED_HLE : MFF_PERFECT);
REINIT_FUNC(sys_lwmutex_lock).flag(g_cfg.core.hle_lwmutex ? MFF_FORCED_HLE : MFF_PERFECT);
REINIT_FUNC(sys_lwmutex_trylock).flag(g_cfg.core.hle_lwmutex ? MFF_FORCED_HLE : MFF_PERFECT);
REINIT_FUNC(sys_lwmutex_unlock).flag(g_cfg.core.hle_lwmutex ? MFF_FORCED_HLE : MFF_PERFECT);
});
}
| 9,208
|
C++
|
.cpp
| 330
| 24.951515
| 192
| 0.691774
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| false
| false
|
5,262
|
cellImeJp.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellImeJp.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
#include "Emu/Cell/lv2/sys_process.h"
#include "Emu/IdManager.h"
#include "cellImeJp.h"
LOG_CHANNEL(cellImeJp);
template <>
void fmt_class_string<CellImeJpError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_IMEJP_ERROR_ERR);
STR_CASE(CELL_IMEJP_ERROR_CONTEXT);
STR_CASE(CELL_IMEJP_ERROR_ALREADY_OPEN);
STR_CASE(CELL_IMEJP_ERROR_DIC_OPEN);
STR_CASE(CELL_IMEJP_ERROR_PARAM);
STR_CASE(CELL_IMEJP_ERROR_IME_ALREADY_IN_USE);
STR_CASE(CELL_IMEJP_ERROR_OTHER);
}
return unknown;
});
}
using sys_memory_container_t = u32;
const u32 ime_jp_address = 0xf0000000;
ime_jp_manager::ime_jp_manager()
{
if (static_cast<s32>(g_ps3_process_info.sdk_ver) < 0x360000) // firmware < 3.6.0
allowed_extensions = CELL_IMEJP_EXTENSIONCH_UD85TO94 | CELL_IMEJP_EXTENSIONCH_OUTJIS;
else
allowed_extensions = CELL_IMEJP_EXTENSIONCH_UD09TO15 | CELL_IMEJP_EXTENSIONCH_UD85TO94 | CELL_IMEJP_EXTENSIONCH_OUTJIS;
}
bool ime_jp_manager::addChar(u16 c)
{
if (!c || cursor >= (CELL_IMEJP_STRING_MAXLENGTH - 1ULL) || cursor > input_string.length())
return false;
std::u16string tmp;
tmp += c;
#if defined(__GNUG__) && !defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wrestrict"
#endif
input_string.insert(cursor, tmp);
#if defined(__GNUG__) && !defined(__clang__)
#pragma GCC diagnostic pop
#endif
const usz cursor_old = cursor;
const bool cursor_was_in_focus = cursor >= focus_begin && cursor <= (focus_begin + focus_length);
move_cursor(1);
if (cursor_was_in_focus)
{
// Add this char to the focus
move_focus_end(1, false);
}
else
{
// Let's just move the focus to the cursor, so that it contains the new char.
focus_begin = cursor_old;
focus_length = 1;
move_focus(0); // Sanitize focus
}
input_state = CELL_IMEJP_BEFORE_CONVERT;
return true;
}
bool ime_jp_manager::addString(vm::cptr<u16> str)
{
if (!str)
return false;
for (u32 i = 0; i < CELL_IMEJP_STRING_MAXLENGTH; i++)
{
if (!addChar(str[i]))
return false;
}
return true;
}
bool ime_jp_manager::backspaceWord()
{
return remove_character(false);
}
bool ime_jp_manager::deleteWord()
{
return remove_character(true);
}
bool ime_jp_manager::remove_character(bool forward)
{
if (!forward && !cursor)
{
return false;
}
const usz pos = forward ? cursor : (cursor - 1);
if (pos >= (CELL_IMEJP_STRING_MAXLENGTH - 1ULL) || pos >= input_string.length())
{
return false;
}
// Delete the character at the position
input_string.erase(pos, 1);
// Move cursor and focus
const bool deleted_part_of_focus = pos > focus_begin && pos <= (focus_begin + focus_length);
if (!forward)
{
move_cursor(-1);
}
if (deleted_part_of_focus)
{
move_focus_end(-1, false);
}
else if (focus_begin > pos)
{
move_focus(-1);
}
if (input_string.empty())
{
input_state = CELL_IMEJP_BEFORE_INPUT;
}
return true;
}
void ime_jp_manager::clear_input()
{
cursor = 0;
focus_begin = 0;
focus_length = 0;
input_string.clear();
converted_string.clear();
}
void ime_jp_manager::move_cursor(s8 amount)
{
cursor = std::max(0, std::min(static_cast<s32>(cursor) + amount, ::narrow<s32>(input_string.length())));
}
void ime_jp_manager::move_focus(s8 amount)
{
focus_begin = std::max(0, std::min(static_cast<s32>(focus_begin) + amount, ::narrow<s32>(input_string.length())));
move_focus_end(amount, false);
}
void ime_jp_manager::move_focus_end(s8 amount, bool wrap_around)
{
if (focus_begin >= input_string.length())
{
focus_length = 0;
return;
}
constexpr usz min_length = 1;
const usz max_length = input_string.length() - focus_begin;
if (amount > 0)
{
if (wrap_around && focus_length >= max_length)
{
focus_length = min_length;
}
else
{
focus_length += static_cast<usz>(amount);
}
}
else if (amount < 0)
{
if (wrap_around && focus_length <= min_length)
{
focus_length = max_length;
}
else
{
focus_length = std::max(0, static_cast<s32>(focus_length) + amount);
}
}
focus_length = std::max(min_length, std::min(max_length, focus_length));
}
std::vector<ime_jp_manager::candidate> ime_jp_manager::get_candidate_list() const
{
std::vector<candidate> candidates;
if (input_string.empty() || focus_length == 0 || focus_begin >= input_string.length())
return candidates;
// TODO: we just fake this with one candidate for now
candidates.push_back(candidate{
.text = get_focus_string(),
.offset = 0
});
return candidates;
}
std::u16string ime_jp_manager::get_focus_string() const
{
if (input_string.empty() || focus_length == 0 || focus_begin >= input_string.length())
return {};
return input_string.substr(focus_begin, focus_length);
}
static error_code cellImeJpOpen(sys_memory_container_t container_id, vm::ptr<CellImeJpHandle> hImeJpHandle, vm::cptr<CellImeJpAddDic> addDicPath)
{
cellImeJp.todo("cellImeJpOpen(container_id=*0x%x, hImeJpHandle=*0x%x, addDicPath=*0x%x)", container_id, hImeJpHandle, addDicPath);
if (!container_id || !hImeJpHandle)
{
return CELL_IMEJP_ERROR_PARAM;
}
auto& manager = g_fxo->get<ime_jp_manager>();
std::lock_guard lock(manager.mutex);
if (manager.is_initialized)
{
return CELL_IMEJP_ERROR_ALREADY_OPEN;
}
if (addDicPath && addDicPath->path[0])
{
cellImeJp.warning("cellImeJpOpen dictionary path = %s", addDicPath->path);
manager.dictionary_paths.emplace_back(addDicPath->path);
}
*hImeJpHandle = vm::cast(ime_jp_address);
manager.is_initialized = true;
return CELL_OK;
}
static error_code cellImeJpOpen2(sys_memory_container_t container_id, vm::ptr<CellImeJpHandle> hImeJpHandle, vm::cptr<CellImeJpAddDic> addDicPath)
{
cellImeJp.todo("cellImeJpOpen2(container_id=*0x%x, hImeJpHandle=*0x%x, addDicPath=*0x%x)", container_id, hImeJpHandle, addDicPath);
if (!container_id || !hImeJpHandle)
{
return CELL_IMEJP_ERROR_PARAM;
}
auto& manager = g_fxo->get<ime_jp_manager>();
std::lock_guard lock(manager.mutex);
if (manager.is_initialized)
{
return CELL_IMEJP_ERROR_ALREADY_OPEN;
}
if (addDicPath && addDicPath->path[0])
{
cellImeJp.warning("cellImeJpOpen2 dictionary path = %s", addDicPath->path);
manager.dictionary_paths.emplace_back(addDicPath->path);
}
*hImeJpHandle = vm::cast(ime_jp_address);
manager.is_initialized = true;
return CELL_OK;
}
static error_code cellImeJpOpen3(sys_memory_container_t container_id, vm::ptr<CellImeJpHandle> hImeJpHandle, vm::cpptr<CellImeJpAddDic> addDicPath)
{
cellImeJp.todo("cellImeJpOpen3(container_id=*0x%x, hImeJpHandle=*0x%x, addDicPath=*0x%x)", container_id, hImeJpHandle, addDicPath);
if (!container_id || !hImeJpHandle)
{
return CELL_IMEJP_ERROR_PARAM;
}
auto& manager = g_fxo->get<ime_jp_manager>();
std::lock_guard lock(manager.mutex);
if (manager.is_initialized)
{
return CELL_IMEJP_ERROR_ALREADY_OPEN;
}
if (addDicPath)
{
for (u32 i = 0; i < 4; i++)
{
if (addDicPath[i] && addDicPath[i]->path[0])
{
cellImeJp.warning("cellImeJpOpen3 dictionary %d path = %s", i, addDicPath[i]->path);
manager.dictionary_paths.emplace_back(addDicPath[i]->path);
}
}
}
*hImeJpHandle = vm::cast(ime_jp_address);
manager.is_initialized = true;
return CELL_OK;
}
static error_code cellImeJpOpenExt()
{
cellImeJp.todo("cellImeJpOpenExt()");
return CELL_OK;
}
static error_code cellImeJpClose(CellImeJpHandle hImeJpHandle)
{
cellImeJp.todo("cellImeJpClose(hImeJpHandle=*0x%x)", hImeJpHandle);
auto& manager = g_fxo->get<ime_jp_manager>();
std::lock_guard lock(manager.mutex);
if (!manager.is_initialized)
{
return CELL_IMEJP_ERROR_CONTEXT;
}
manager.input_state = CELL_IMEJP_BEFORE_INPUT;
manager.clear_input();
manager.confirmed_string.clear();
manager.is_initialized = false;
return CELL_OK;
}
static error_code cellImeJpSetKanaInputMode(CellImeJpHandle hImeJpHandle, s16 inputOption)
{
cellImeJp.todo("cellImeJpSetKanaInputMode(hImeJpHandle=*0x%x, inputOption=%d)", hImeJpHandle, inputOption);
auto& manager = g_fxo->get<ime_jp_manager>();
std::lock_guard lock(manager.mutex);
if (!manager.is_initialized)
{
return CELL_IMEJP_ERROR_CONTEXT;
}
if (manager.input_state != CELL_IMEJP_BEFORE_INPUT)
{
return CELL_IMEJP_ERROR_ERR;
}
manager.kana_input_mode = inputOption;
return CELL_OK;
}
static error_code cellImeJpSetInputCharType(CellImeJpHandle hImeJpHandle, s16 charTypeOption)
{
cellImeJp.todo("cellImeJpSetInputCharType(hImeJpHandle=*0x%x, charTypeOption=%d)", hImeJpHandle, charTypeOption);
auto& manager = g_fxo->get<ime_jp_manager>();
std::lock_guard lock(manager.mutex);
if (!manager.is_initialized)
{
return CELL_IMEJP_ERROR_CONTEXT;
}
manager.input_char_type = charTypeOption;
return CELL_OK;
}
static error_code cellImeJpSetFixInputMode(CellImeJpHandle hImeJpHandle, s16 fixInputMode)
{
cellImeJp.todo("cellImeJpSetFixInputMode(hImeJpHandle=*0x%x, fixInputMode=%d)", hImeJpHandle, fixInputMode);
auto& manager = g_fxo->get<ime_jp_manager>();
std::lock_guard lock(manager.mutex);
if (!manager.is_initialized)
{
return CELL_IMEJP_ERROR_CONTEXT;
}
manager.fix_input_mode = fixInputMode;
return CELL_OK;
}
static error_code cellImeJpAllowExtensionCharacters(CellImeJpHandle hImeJpHandle, s16 extensionCharacters)
{
cellImeJp.todo("cellImeJpSetFixInputMode(hImeJpHandle=*0x%x, extensionCharacters=%d)", hImeJpHandle, extensionCharacters);
auto& manager = g_fxo->get<ime_jp_manager>();
std::lock_guard lock(manager.mutex);
if (!manager.is_initialized)
{
return CELL_IMEJP_ERROR_CONTEXT;
}
if (manager.input_state != CELL_IMEJP_BEFORE_INPUT)
{
return CELL_IMEJP_ERROR_ERR;
}
manager.allowed_extensions = extensionCharacters;
return CELL_OK;
}
static error_code cellImeJpReset(CellImeJpHandle hImeJpHandle)
{
cellImeJp.todo("cellImeJpReset(hImeJpHandle=*0x%x)", hImeJpHandle);
auto& manager = g_fxo->get<ime_jp_manager>();
std::lock_guard lock(manager.mutex);
if (!manager.is_initialized)
{
return CELL_IMEJP_ERROR_CONTEXT;
}
manager.input_state = CELL_IMEJP_BEFORE_INPUT;
manager.clear_input();
manager.confirmed_string.clear();
return CELL_OK;
}
static error_code cellImeJpGetStatus(CellImeJpHandle hImeJpHandle, vm::ptr<s16> pInputStatus)
{
cellImeJp.warning("cellImeJpGetStatus(hImeJpHandle=*0x%x, pInputStatus=%d)", hImeJpHandle, pInputStatus);
if (!pInputStatus)
{
return CELL_IMEJP_ERROR_PARAM;
}
auto& manager = g_fxo->get<ime_jp_manager>();
std::lock_guard lock(manager.mutex);
if (!manager.is_initialized)
{
return CELL_IMEJP_ERROR_CONTEXT;
}
*pInputStatus = manager.input_state;
return CELL_OK;
}
static error_code cellImeJpEnterChar(CellImeJpHandle hImeJpHandle, u16 inputChar, vm::ptr<s16> pOutputStatus)
{
cellImeJp.todo("cellImeJpEnterChar(hImeJpHandle=*0x%x, inputChar=%d, pOutputStatus=%d)", hImeJpHandle, inputChar, pOutputStatus);
if (!pOutputStatus)
{
return CELL_IMEJP_ERROR_PARAM;
}
auto& manager = g_fxo->get<ime_jp_manager>();
std::lock_guard lock(manager.mutex);
if (!manager.is_initialized)
{
return CELL_IMEJP_ERROR_CONTEXT;
}
if (manager.input_state == CELL_IMEJP_MOVE_CLAUSE_GAP)
{
return CELL_IMEJP_ERROR_ERR;
}
manager.addChar(inputChar);
*pOutputStatus = CELL_IMEJP_RET_CONFIRMED;
return CELL_OK;
}
static error_code cellImeJpEnterCharExt(CellImeJpHandle hImeJpHandle, u16 inputChar, vm::ptr<s16> pOutputStatus)
{
cellImeJp.todo("cellImeJpEnterCharExt(hImeJpHandle=*0x%x, inputChar=%d, pOutputStatus=%d", hImeJpHandle, inputChar, pOutputStatus);
return cellImeJpEnterChar(hImeJpHandle, inputChar, pOutputStatus);
}
static error_code cellImeJpEnterString(CellImeJpHandle hImeJpHandle, vm::cptr<u16> pInputString, vm::ptr<s16> pOutputStatus)
{
cellImeJp.todo("cellImeJpEnterString(hImeJpHandle=*0x%x, pInputString=*0x%x, pOutputStatus=%d", hImeJpHandle, pInputString, pOutputStatus);
if (!pOutputStatus)
{
return CELL_IMEJP_ERROR_PARAM;
}
auto& manager = g_fxo->get<ime_jp_manager>();
std::lock_guard lock(manager.mutex);
if (!manager.is_initialized)
{
return CELL_IMEJP_ERROR_CONTEXT;
}
if (manager.input_state == CELL_IMEJP_MOVE_CLAUSE_GAP)
{
return CELL_IMEJP_ERROR_ERR;
}
manager.addString(pInputString);
*pOutputStatus = CELL_IMEJP_RET_CONFIRMED;
return CELL_OK;
}
static error_code cellImeJpEnterStringExt(CellImeJpHandle hImeJpHandle, vm::cptr<u16> pInputString, vm::ptr<s16> pOutputStatus)
{
cellImeJp.todo("cellImeJpEnterStringExt(hImeJpHandle=*0x%x, pInputString=*0x%x, pOutputStatus=%d", hImeJpHandle, pInputString, pOutputStatus);
return cellImeJpEnterString(hImeJpHandle, pInputString, pOutputStatus);
}
static error_code cellImeJpModeCaretRight(CellImeJpHandle hImeJpHandle)
{
cellImeJp.todo("cellImeJpModeCaretRight(hImeJpHandle=*0x%x)", hImeJpHandle);
auto& manager = g_fxo->get<ime_jp_manager>();
std::lock_guard lock(manager.mutex);
if (!manager.is_initialized)
{
return CELL_IMEJP_ERROR_CONTEXT;
}
if (manager.input_state != CELL_IMEJP_BEFORE_CONVERT)
{
return CELL_IMEJP_ERROR_ERR;
}
manager.move_cursor(1);
return CELL_OK;
}
static error_code cellImeJpModeCaretLeft(CellImeJpHandle hImeJpHandle)
{
cellImeJp.todo("cellImeJpModeCaretLeft(hImeJpHandle=*0x%x)", hImeJpHandle);
auto& manager = g_fxo->get<ime_jp_manager>();
std::lock_guard lock(manager.mutex);
if (!manager.is_initialized)
{
return CELL_IMEJP_ERROR_CONTEXT;
}
if (manager.input_state != CELL_IMEJP_BEFORE_CONVERT)
{
return CELL_IMEJP_ERROR_ERR;
}
manager.move_cursor(-1);
return CELL_OK;
}
static error_code cellImeJpBackspaceWord(CellImeJpHandle hImeJpHandle)
{
cellImeJp.todo("cellImeJpBackspaceWord(hImeJpHandle=*0x%x)", hImeJpHandle);
auto& manager = g_fxo->get<ime_jp_manager>();
std::lock_guard lock(manager.mutex);
if (!manager.is_initialized)
{
return CELL_IMEJP_ERROR_CONTEXT;
}
if (manager.input_state != CELL_IMEJP_BEFORE_CONVERT)
{
return CELL_IMEJP_ERROR_ERR;
}
manager.backspaceWord();
return CELL_OK;
}
static error_code cellImeJpDeleteWord(CellImeJpHandle hImeJpHandle)
{
cellImeJp.todo("cellImeJpDeleteWord(hImeJpHandle=*0x%x)", hImeJpHandle);
auto& manager = g_fxo->get<ime_jp_manager>();
std::lock_guard lock(manager.mutex);
if (!manager.is_initialized)
{
return CELL_IMEJP_ERROR_CONTEXT;
}
if (manager.input_state != CELL_IMEJP_BEFORE_CONVERT)
{
return CELL_IMEJP_ERROR_ERR;
}
manager.deleteWord();
return CELL_OK;
}
static error_code cellImeJpAllDeleteConvertString(CellImeJpHandle hImeJpHandle)
{
cellImeJp.todo("cellImeJpAllDeleteConvertString(hImeJpHandle=*0x%x)", hImeJpHandle);
auto& manager = g_fxo->get<ime_jp_manager>();
std::lock_guard lock(manager.mutex);
if (!manager.is_initialized)
{
return CELL_IMEJP_ERROR_CONTEXT;
}
if (manager.input_state == CELL_IMEJP_BEFORE_INPUT)
{
return CELL_IMEJP_ERROR_ERR;
}
manager.clear_input();
manager.input_state = CELL_IMEJP_BEFORE_INPUT;
return CELL_OK;
}
static error_code cellImeJpConvertForward(CellImeJpHandle hImeJpHandle)
{
cellImeJp.todo("cellImeJpConvertForward(hImeJpHandle=*0x%x)", hImeJpHandle);
auto& manager = g_fxo->get<ime_jp_manager>();
std::lock_guard lock(manager.mutex);
if (!manager.is_initialized)
{
return CELL_IMEJP_ERROR_CONTEXT;
}
if (manager.input_state == CELL_IMEJP_BEFORE_INPUT)
{
return CELL_IMEJP_ERROR_ERR;
}
manager.input_state = CELL_IMEJP_CANDIDATES;
return CELL_OK;
}
static error_code cellImeJpConvertBackward(CellImeJpHandle hImeJpHandle)
{
cellImeJp.todo("cellImeJpConvertBackward(hImeJpHandle=*0x%x)", hImeJpHandle);
auto& manager = g_fxo->get<ime_jp_manager>();
std::lock_guard lock(manager.mutex);
if (!manager.is_initialized)
{
return CELL_IMEJP_ERROR_CONTEXT;
}
if (manager.input_state == CELL_IMEJP_BEFORE_INPUT)
{
return CELL_IMEJP_ERROR_ERR;
}
manager.input_state = CELL_IMEJP_CANDIDATES;
return CELL_OK;
}
static error_code cellImeJpCurrentPartConfirm(CellImeJpHandle hImeJpHandle, s16 listItem)
{
cellImeJp.todo("cellImeJpCurrentPartConfirm(hImeJpHandle=*0x%x, listItem=%d)", hImeJpHandle, listItem);
auto& manager = g_fxo->get<ime_jp_manager>();
std::lock_guard lock(manager.mutex);
if (!manager.is_initialized)
{
return CELL_IMEJP_ERROR_CONTEXT;
}
if (manager.input_state == CELL_IMEJP_BEFORE_INPUT)
{
return CELL_IMEJP_ERROR_ERR;
}
return CELL_OK;
}
static error_code cellImeJpAllConfirm(CellImeJpHandle hImeJpHandle)
{
cellImeJp.todo("cellImeJpAllConfirm(hImeJpHandle=*0x%x)", hImeJpHandle);
auto& manager = g_fxo->get<ime_jp_manager>();
std::lock_guard lock(manager.mutex);
if (!manager.is_initialized)
{
return CELL_IMEJP_ERROR_CONTEXT;
}
if (manager.input_state == CELL_IMEJP_BEFORE_INPUT)
{
return CELL_IMEJP_ERROR_ERR;
}
// Use input_string for now
manager.confirmed_string = manager.input_string;
manager.clear_input();
manager.input_state = CELL_IMEJP_BEFORE_INPUT;
return CELL_OK;
}
static error_code cellImeJpAllConvertCancel(CellImeJpHandle hImeJpHandle)
{
cellImeJp.todo("cellImeJpAllConvertCancel(hImeJpHandle=*0x%x)", hImeJpHandle);
auto& manager = g_fxo->get<ime_jp_manager>();
std::lock_guard lock(manager.mutex);
if (!manager.is_initialized)
{
return CELL_IMEJP_ERROR_CONTEXT;
}
if (manager.input_state == CELL_IMEJP_BEFORE_INPUT || manager.input_state == CELL_IMEJP_BEFORE_CONVERT)
{
return CELL_IMEJP_ERROR_ERR;
}
manager.converted_string.clear();
manager.input_state = CELL_IMEJP_BEFORE_CONVERT;
return CELL_OK;
}
static error_code cellImeJpConvertCancel(CellImeJpHandle hImeJpHandle)
{
cellImeJp.todo("cellImeJpConvertCancel(hImeJpHandle=*0x%x)", hImeJpHandle);
auto& manager = g_fxo->get<ime_jp_manager>();
std::lock_guard lock(manager.mutex);
if (!manager.is_initialized)
{
return CELL_IMEJP_ERROR_CONTEXT;
}
if (manager.input_state == CELL_IMEJP_BEFORE_INPUT || manager.input_state == CELL_IMEJP_BEFORE_CONVERT)
{
return CELL_IMEJP_ERROR_ERR;
}
manager.converted_string.clear();
manager.input_state = CELL_IMEJP_BEFORE_CONVERT;
return CELL_OK;
}
static error_code cellImeJpExtendConvertArea(CellImeJpHandle hImeJpHandle)
{
cellImeJp.todo("cellImeJpExtendConvertArea(hImeJpHandle=*0x%x)", hImeJpHandle);
auto& manager = g_fxo->get<ime_jp_manager>();
std::lock_guard lock(manager.mutex);
if (!manager.is_initialized)
{
return CELL_IMEJP_ERROR_CONTEXT;
}
if (manager.input_state == CELL_IMEJP_BEFORE_INPUT || manager.input_state == CELL_IMEJP_BEFORE_CONVERT)
{
return CELL_IMEJP_ERROR_ERR;
}
// Move end of the focus by one. Wrap around if the focus end is already at the end of the input string.
manager.move_focus_end(1, true);
return CELL_OK;
}
static error_code cellImeJpShortenConvertArea(CellImeJpHandle hImeJpHandle)
{
cellImeJp.todo("cellImeJpShortenConvertArea(hImeJpHandle=*0x%x)", hImeJpHandle);
auto& manager = g_fxo->get<ime_jp_manager>();
std::lock_guard lock(manager.mutex);
if (!manager.is_initialized)
{
return CELL_IMEJP_ERROR_CONTEXT;
}
if (manager.input_state == CELL_IMEJP_BEFORE_INPUT || manager.input_state == CELL_IMEJP_BEFORE_CONVERT)
{
return CELL_IMEJP_ERROR_ERR;
}
// Move end of focus by one. Wrap around if the focus end is already at the beginning of the input string.
manager.move_focus_end(-1, true);
return CELL_OK;
}
static error_code cellImeJpTemporalConfirm(CellImeJpHandle hImeJpHandle, s16 selectIndex)
{
cellImeJp.todo("cellImeJpTemporalConfirm(hImeJpHandle=*0x%x, selectIndex=%d)", hImeJpHandle, selectIndex);
auto& manager = g_fxo->get<ime_jp_manager>();
std::lock_guard lock(manager.mutex);
if (!manager.is_initialized)
{
return CELL_IMEJP_ERROR_CONTEXT;
}
if (manager.input_state != CELL_IMEJP_CANDIDATES)
{
return CELL_IMEJP_ERROR_ERR;
}
return CELL_OK;
}
static error_code cellImeJpPostConvert(CellImeJpHandle hImeJpHandle, s16 postType)
{
cellImeJp.todo("cellImeJpPostConvert(hImeJpHandle=*0x%x, postType=%d)", hImeJpHandle, postType);
auto& manager = g_fxo->get<ime_jp_manager>();
std::lock_guard lock(manager.mutex);
if (!manager.is_initialized)
{
return CELL_IMEJP_ERROR_CONTEXT;
}
if (manager.input_state == CELL_IMEJP_BEFORE_INPUT)
{
return CELL_IMEJP_ERROR_ERR;
}
return CELL_OK;
}
static error_code cellImeJpMoveFocusClause(CellImeJpHandle hImeJpHandle, s16 moveType)
{
cellImeJp.todo("cellImeJpMoveFocusClause(hImeJpHandle=*0x%x, moveType=%d)", hImeJpHandle, moveType);
auto& manager = g_fxo->get<ime_jp_manager>();
std::lock_guard lock(manager.mutex);
if (!manager.is_initialized)
{
return CELL_IMEJP_ERROR_CONTEXT;
}
if (manager.input_state == CELL_IMEJP_BEFORE_INPUT || manager.input_state == CELL_IMEJP_BEFORE_CONVERT || manager.input_state == CELL_IMEJP_MOVE_CLAUSE_GAP)
{
return CELL_IMEJP_ERROR_ERR;
}
switch (moveType)
{
case CELL_IMEJP_FOCUS_NEXT:
manager.move_focus(1);
break;
case CELL_IMEJP_FOCUS_BEFORE:
manager.move_focus(-1);
break;
case CELL_IMEJP_FOCUS_TOP:
manager.move_focus(-1 * ::narrow<s8>(manager.input_string.length()));
break;
case CELL_IMEJP_FOCUS_END:
manager.move_focus(::narrow<s8>(manager.input_string.length()));
manager.move_focus(-1);
break;
default:
break;
}
manager.input_state = CELL_IMEJP_CONVERTING;
return CELL_OK;
}
static error_code cellImeJpGetFocusTop(CellImeJpHandle hImeJpHandle, vm::ptr<s16> pFocusTop)
{
cellImeJp.todo("cellImeJpGetFocusTop(hImeJpHandle=*0x%x, pFocusTop=*0x%x)", hImeJpHandle, pFocusTop);
if (!pFocusTop)
{
return CELL_IMEJP_ERROR_PARAM;
}
auto& manager = g_fxo->get<ime_jp_manager>();
std::lock_guard lock(manager.mutex);
if (!manager.is_initialized)
{
return CELL_IMEJP_ERROR_CONTEXT;
}
*pFocusTop = static_cast<u16>(manager.focus_begin * 2); // offset in bytes
return CELL_OK;
}
static error_code cellImeJpGetFocusLength(CellImeJpHandle hImeJpHandle, vm::ptr<s16> pFocusLength)
{
cellImeJp.todo("cellImeJpGetFocusLength(hImeJpHandle=*0x%x, pFocusLength=*0x%x)", hImeJpHandle, pFocusLength);
if (!pFocusLength)
{
return CELL_IMEJP_ERROR_PARAM;
}
auto& manager = g_fxo->get<ime_jp_manager>();
std::lock_guard lock(manager.mutex);
if (!manager.is_initialized)
{
return CELL_IMEJP_ERROR_CONTEXT;
}
*pFocusLength = ::narrow<s16>(manager.focus_length * 2); // offset in bytes
return CELL_OK;
}
static error_code cellImeJpGetConfirmYomiString(CellImeJpHandle hImeJpHandle, vm::ptr<u16> pYomiString)
{
cellImeJp.todo("cellImeJpGetConfirmYomiString(hImeJpHandle=*0x%x, pYomiString=*0x%x)", hImeJpHandle, pYomiString);
if (!pYomiString)
{
return CELL_IMEJP_ERROR_PARAM;
}
auto& manager = g_fxo->get<ime_jp_manager>();
std::lock_guard lock(manager.mutex);
if (!manager.is_initialized)
{
return CELL_IMEJP_ERROR_CONTEXT;
}
const usz max_len = std::min<usz>(CELL_IMEJP_STRING_MAXLENGTH - 1ULL, manager.confirmed_string.length());
for (u32 i = 0; i < max_len; i++)
{
pYomiString[i] = manager.confirmed_string[i];
}
for (u32 i = static_cast<u32>(max_len); i < CELL_IMEJP_STRING_MAXLENGTH; i++)
{
pYomiString[i] = 0;
}
return CELL_OK;
}
static error_code cellImeJpGetConfirmString(CellImeJpHandle hImeJpHandle, vm::ptr<u16> pConfirmString)
{
cellImeJp.todo("cellImeJpGetConfirmString(hImeJpHandle=*0x%x, pConfirmString=*0x%x)", hImeJpHandle, pConfirmString);
if (!pConfirmString)
{
return CELL_IMEJP_ERROR_PARAM;
}
auto& manager = g_fxo->get<ime_jp_manager>();
std::lock_guard lock(manager.mutex);
if (!manager.is_initialized)
{
return CELL_IMEJP_ERROR_CONTEXT;
}
const usz max_len = std::min<usz>(CELL_IMEJP_STRING_MAXLENGTH - 1ULL, manager.confirmed_string.length());
for (u32 i = 0; i < max_len; i++)
{
pConfirmString[i] = manager.confirmed_string[i];
}
for (u32 i = static_cast<u32>(max_len); i < CELL_IMEJP_STRING_MAXLENGTH; i++)
{
pConfirmString[i] = 0;
}
return CELL_OK;
}
static error_code cellImeJpGetConvertYomiString(CellImeJpHandle hImeJpHandle, vm::ptr<u16> pYomiString)
{
cellImeJp.todo("cellImeJpGetConvertYomiString(hImeJpHandle=*0x%x, pYomiString=*0x%x)", hImeJpHandle, pYomiString);
if (!pYomiString)
{
return CELL_IMEJP_ERROR_PARAM;
}
auto& manager = g_fxo->get<ime_jp_manager>();
std::lock_guard lock(manager.mutex);
if (!manager.is_initialized)
{
return CELL_IMEJP_ERROR_CONTEXT;
}
const usz max_len = std::min<usz>(CELL_IMEJP_STRING_MAXLENGTH - 1ULL, manager.input_string.length());
for (u32 i = 0; i < max_len; i++)
{
pYomiString[i] = manager.input_string[i];
}
for (u32 i = static_cast<u32>(max_len); i < CELL_IMEJP_STRING_MAXLENGTH; i++)
{
pYomiString[i] = 0;
}
return CELL_OK;
}
static error_code cellImeJpGetConvertString(CellImeJpHandle hImeJpHandle, vm::ptr<u16> pConvertString)
{
cellImeJp.warning("cellImeJpGetConvertString(hImeJpHandle=*0x%x, pConvertString=*0x%x)", hImeJpHandle, pConvertString);
if (!pConvertString)
{
return CELL_IMEJP_ERROR_PARAM;
}
auto& manager = g_fxo->get<ime_jp_manager>();
std::lock_guard lock(manager.mutex);
if (!manager.is_initialized)
{
return CELL_IMEJP_ERROR_CONTEXT;
}
const usz max_len = std::min<usz>(CELL_IMEJP_STRING_MAXLENGTH - 1ULL, manager.input_string.length());
for (u32 i = 0; i < max_len; i++)
{
pConvertString[i] = manager.input_string[i];
}
for (u32 i = static_cast<u32>(max_len); i < CELL_IMEJP_STRING_MAXLENGTH; i++)
{
pConvertString[i] = 0;
}
return CELL_OK;
}
static error_code cellImeJpGetCandidateListSize(CellImeJpHandle hImeJpHandle, vm::ptr<s16> pListSize)
{
cellImeJp.todo("cellImeJpGetCandidateListSize(hImeJpHandle=*0x%x, pListSize=*0x%x)", hImeJpHandle, pListSize);
if (!pListSize)
{
return CELL_IMEJP_ERROR_PARAM;
}
auto& manager = g_fxo->get<ime_jp_manager>();
std::lock_guard lock(manager.mutex);
if (!manager.is_initialized)
{
return CELL_IMEJP_ERROR_CONTEXT;
}
if (manager.input_state != CELL_IMEJP_CANDIDATES)
{
return CELL_IMEJP_ERROR_ERR;
}
// Add focus string size, including null terminator
const std::u16string focus_string = manager.get_focus_string();
usz size = sizeof(u16) * (focus_string.length() + 1);
// Add candidates, including null terminators and offsets
for (const ime_jp_manager::candidate& can : manager.get_candidate_list())
{
constexpr usz offset_size = sizeof(u16);
size += offset_size + (can.text.size() + 1) * sizeof(u16);
}
*pListSize = ::narrow<s16>(size);
return CELL_OK;
}
static error_code cellImeJpGetCandidateList(CellImeJpHandle hImeJpHandle, vm::ptr<s16> plistNum, vm::ptr<u16> pCandidateString)
{
cellImeJp.todo("cellImeJpGetCandidateList(hImeJpHandle=*0x%x, plistNum=*0x%x, pCandidateString=*0x%x)", hImeJpHandle, plistNum, pCandidateString);
if (!plistNum || !pCandidateString)
{
return CELL_IMEJP_ERROR_PARAM;
}
auto& manager = g_fxo->get<ime_jp_manager>();
std::lock_guard lock(manager.mutex);
if (!manager.is_initialized)
{
return CELL_IMEJP_ERROR_CONTEXT;
}
if (manager.input_state != CELL_IMEJP_CANDIDATES)
{
return CELL_IMEJP_ERROR_ERR;
}
// First, copy the focus string
u32 pos = 0;
const std::u16string focus_string = manager.get_focus_string();
for (u32 i = pos; i < focus_string.length(); i++)
{
pCandidateString[i] = focus_string[i];
}
pos += ::narrow<u32>(focus_string.length());
// Add null terminator
pCandidateString[pos++] = 0;
// Add list of candidates
const std::vector<ime_jp_manager::candidate> list = manager.get_candidate_list();
for (const ime_jp_manager::candidate& can : list)
{
// Copy the candidate
for (u32 i = pos; i < can.text.length(); i++)
{
pCandidateString[i] = can.text[i];
}
pos += ::narrow<u32>(can.text.length());
// Add null terminator
pCandidateString[pos++] = 0;
// Add offset
pCandidateString[pos++] = can.offset;
}
*plistNum = ::narrow<s16>(list.size());
return CELL_OK;
}
static error_code cellImeJpGetCandidateSelect(CellImeJpHandle hImeJpHandle, vm::ptr<s16> pIndex)
{
cellImeJp.todo("cellImeJpGetCandidateSelect(hImeJpHandle=*0x%x, pIndex=*0x%x)", hImeJpHandle, pIndex);
if (!pIndex)
{
return CELL_IMEJP_ERROR_PARAM;
}
auto& manager = g_fxo->get<ime_jp_manager>();
std::lock_guard lock(manager.mutex);
if (!manager.is_initialized)
{
return CELL_IMEJP_ERROR_CONTEXT;
}
if (manager.input_state != CELL_IMEJP_CANDIDATES)
{
return CELL_IMEJP_ERROR_ERR;
}
*pIndex = 0;
return CELL_OK;
}
static error_code cellImeJpGetPredictList(CellImeJpHandle hImeJpHandle, vm::ptr<s16> pYomiString, s32 itemNum, vm::ptr<s32> plistCount, vm::ptr<CellImeJpPredictItem> pPredictItem)
{
cellImeJp.todo("cellImeJpGetPredictList(hImeJpHandle=*0x%x, pYomiString=*0x%x, itemNum=%d, plistCount=*0x%x, pPredictItem=*0x%x)", hImeJpHandle, pYomiString, itemNum, plistCount, pPredictItem);
if (!pPredictItem || !plistCount)
{
return CELL_IMEJP_ERROR_PARAM;
}
auto& manager = g_fxo->get<ime_jp_manager>();
std::lock_guard lock(manager.mutex);
if (!manager.is_initialized)
{
return CELL_IMEJP_ERROR_CONTEXT;
}
*plistCount = 0;
return CELL_OK;
}
static error_code cellImeJpConfirmPrediction(CellImeJpHandle hImeJpHandle, vm::ptr<CellImeJpPredictItem> pPredictItem)
{
cellImeJp.todo("cellImeJpConfirmPrediction(hImeJpHandle=*0x%x, pPredictItem=*0x%x)", hImeJpHandle, pPredictItem);
if (!pPredictItem)
{
return CELL_IMEJP_ERROR_PARAM;
}
auto& manager = g_fxo->get<ime_jp_manager>();
std::lock_guard lock(manager.mutex);
if (!manager.is_initialized)
{
return CELL_IMEJP_ERROR_CONTEXT;
}
return CELL_OK;
}
DECLARE(ppu_module_manager::cellImeJp)("cellImeJpUtility", []()
{
REG_FUNC(cellImeJpUtility, cellImeJpOpen);
REG_FUNC(cellImeJpUtility, cellImeJpOpen2);
REG_FUNC(cellImeJpUtility, cellImeJpOpen3);
REG_FUNC(cellImeJpUtility, cellImeJpOpenExt);
REG_FUNC(cellImeJpUtility, cellImeJpClose);
REG_FUNC(cellImeJpUtility, cellImeJpSetKanaInputMode);
REG_FUNC(cellImeJpUtility, cellImeJpSetInputCharType);
REG_FUNC(cellImeJpUtility, cellImeJpSetFixInputMode);
REG_FUNC(cellImeJpUtility, cellImeJpAllowExtensionCharacters);
REG_FUNC(cellImeJpUtility, cellImeJpReset);
REG_FUNC(cellImeJpUtility, cellImeJpGetStatus);
REG_FUNC(cellImeJpUtility, cellImeJpEnterChar);
REG_FUNC(cellImeJpUtility, cellImeJpEnterCharExt);
REG_FUNC(cellImeJpUtility, cellImeJpEnterString);
REG_FUNC(cellImeJpUtility, cellImeJpEnterStringExt);
REG_FUNC(cellImeJpUtility, cellImeJpModeCaretRight);
REG_FUNC(cellImeJpUtility, cellImeJpModeCaretLeft);
REG_FUNC(cellImeJpUtility, cellImeJpBackspaceWord);
REG_FUNC(cellImeJpUtility, cellImeJpDeleteWord);
REG_FUNC(cellImeJpUtility, cellImeJpAllDeleteConvertString);
REG_FUNC(cellImeJpUtility, cellImeJpConvertForward);
REG_FUNC(cellImeJpUtility, cellImeJpConvertBackward);
REG_FUNC(cellImeJpUtility, cellImeJpCurrentPartConfirm);
REG_FUNC(cellImeJpUtility, cellImeJpAllConfirm);
REG_FUNC(cellImeJpUtility, cellImeJpConvertCancel);
REG_FUNC(cellImeJpUtility, cellImeJpAllConvertCancel);
REG_FUNC(cellImeJpUtility, cellImeJpExtendConvertArea);
REG_FUNC(cellImeJpUtility, cellImeJpShortenConvertArea);
REG_FUNC(cellImeJpUtility, cellImeJpTemporalConfirm);
REG_FUNC(cellImeJpUtility, cellImeJpPostConvert);
REG_FUNC(cellImeJpUtility, cellImeJpMoveFocusClause);
REG_FUNC(cellImeJpUtility, cellImeJpGetFocusTop);
REG_FUNC(cellImeJpUtility, cellImeJpGetFocusLength);
REG_FUNC(cellImeJpUtility, cellImeJpGetConfirmYomiString);
REG_FUNC(cellImeJpUtility, cellImeJpGetConfirmString);
REG_FUNC(cellImeJpUtility, cellImeJpGetConvertYomiString);
REG_FUNC(cellImeJpUtility, cellImeJpGetConvertString);
REG_FUNC(cellImeJpUtility, cellImeJpGetCandidateListSize);
REG_FUNC(cellImeJpUtility, cellImeJpGetCandidateList);
REG_FUNC(cellImeJpUtility, cellImeJpGetCandidateSelect);
REG_FUNC(cellImeJpUtility, cellImeJpGetPredictList);
REG_FUNC(cellImeJpUtility, cellImeJpConfirmPrediction);
});
| 31,763
|
C++
|
.cpp
| 992
| 29.704637
| 194
| 0.757746
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
5,263
|
libmedi.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/libmedi.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
LOG_CHANNEL(libmedi);
error_code cellMediatorCloseContext()
{
libmedi.todo("cellMediatorCloseContext");
return CELL_OK;
}
error_code cellMediatorCreateContext()
{
libmedi.todo("cellMediatorCreateContext");
return CELL_OK;
}
error_code cellMediatorFlushCache()
{
libmedi.todo("cellMediatorFlushCache");
return CELL_OK;
}
error_code cellMediatorGetProviderUrl()
{
libmedi.todo("cellMediatorGetProviderUrl");
return CELL_OK;
}
error_code cellMediatorGetSignatureLength()
{
libmedi.todo("cellMediatorGetSignatureLength");
return CELL_OK;
}
error_code cellMediatorGetStatus()
{
libmedi.todo("cellMediatorGetStatus");
return CELL_OK;
}
error_code cellMediatorGetUserInfo()
{
libmedi.todo("cellMediatorGetUserInfo");
return CELL_OK;
}
error_code cellMediatorPostReports()
{
libmedi.todo("cellMediatorPostReports");
return CELL_OK;
}
error_code cellMediatorReliablePostReports()
{
libmedi.todo("cellMediatorReliablePostReports");
return CELL_OK;
}
error_code cellMediatorSign()
{
libmedi.todo("cellMediatorSign");
return CELL_OK;
}
DECLARE(ppu_module_manager::libmedi)("libmedi", []()
{
REG_FUNC(libmedi, cellMediatorCloseContext);
REG_FUNC(libmedi, cellMediatorCreateContext);
REG_FUNC(libmedi, cellMediatorFlushCache);
REG_FUNC(libmedi, cellMediatorGetProviderUrl);
REG_FUNC(libmedi, cellMediatorGetSignatureLength);
REG_FUNC(libmedi, cellMediatorGetStatus);
REG_FUNC(libmedi, cellMediatorGetUserInfo);
REG_FUNC(libmedi, cellMediatorPostReports);
REG_FUNC(libmedi, cellMediatorReliablePostReports);
REG_FUNC(libmedi, cellMediatorSign);
});
| 1,629
|
C++
|
.cpp
| 66
| 23.030303
| 52
| 0.822581
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| true
| false
| false
| true
| false
| false
|
5,264
|
cellSysutilAp.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellSysutilAp.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
LOG_CHANNEL(cellSysutilAp);
// Return Codes
enum CellSysutilApError : u32
{
CELL_SYSUTIL_AP_ERROR_OUT_OF_MEMORY = 0x8002cd00,
CELL_SYSUTIL_AP_ERROR_FATAL = 0x8002cd01,
CELL_SYSUTIL_AP_ERROR_INVALID_VALUE = 0x8002cd02,
CELL_SYSUTIL_AP_ERROR_NOT_INITIALIZED = 0x8002cd03,
CELL_SYSUTIL_AP_ERROR_ZERO_REGISTERED = 0x8002cd13,
CELL_SYSUTIL_AP_ERROR_NETIF_DISABLED = 0x8002cd14,
CELL_SYSUTIL_AP_ERROR_NETIF_NO_CABLE = 0x8002cd15,
CELL_SYSUTIL_AP_ERROR_NETIF_CANNOT_CONNECT = 0x8002cd16,
};
template<>
void fmt_class_string<CellSysutilApError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_SYSUTIL_AP_ERROR_OUT_OF_MEMORY);
STR_CASE(CELL_SYSUTIL_AP_ERROR_FATAL);
STR_CASE(CELL_SYSUTIL_AP_ERROR_INVALID_VALUE);
STR_CASE(CELL_SYSUTIL_AP_ERROR_NOT_INITIALIZED);
STR_CASE(CELL_SYSUTIL_AP_ERROR_ZERO_REGISTERED);
STR_CASE(CELL_SYSUTIL_AP_ERROR_NETIF_DISABLED);
STR_CASE(CELL_SYSUTIL_AP_ERROR_NETIF_NO_CABLE);
STR_CASE(CELL_SYSUTIL_AP_ERROR_NETIF_CANNOT_CONNECT);
}
return unknown;
});
}
enum
{
CELL_SYSUTIL_AP_TITLE_ID_LEN = 9,
CELL_SYSUTIL_AP_SSID_LEN = 32,
CELL_SYSUTIL_AP_WPA_KEY_LEN = 64
};
struct CellSysutilApTitleId
{
char data[CELL_SYSUTIL_AP_TITLE_ID_LEN];
char padding[3];
};
struct CellSysutilApSsid
{
char data[CELL_SYSUTIL_AP_SSID_LEN + 1];
char padding[3];
};
struct CellSysutilApWpaKey
{
char data[CELL_SYSUTIL_AP_WPA_KEY_LEN + 1];
char padding[3];
};
struct CellSysutilApParam
{
be_t<s32> type;
be_t<s32> wlanFlag;
CellSysutilApTitleId titleId;
CellSysutilApSsid ssid;
CellSysutilApWpaKey wpakey;
};
s32 cellSysutilApGetRequiredMemSize()
{
cellSysutilAp.trace("cellSysutilApGetRequiredMemSize()");
return 1024*1024; // Return 1 MB as required size
}
error_code cellSysutilApOn(vm::ptr<CellSysutilApParam> pParam, u32 container)
{
cellSysutilAp.todo("cellSysutilApOn(pParam=*0x%x, container=0x%x)", pParam, container);
return CELL_OK;
}
error_code cellSysutilApOff()
{
cellSysutilAp.todo("cellSysutilApOff()");
return CELL_OK;
}
DECLARE(ppu_module_manager::cellSysutilAp)("cellSysutilAp", []()
{
REG_FUNC(cellSysutilAp, cellSysutilApGetRequiredMemSize);
REG_FUNC(cellSysutilAp, cellSysutilApOn);
REG_FUNC(cellSysutilAp, cellSysutilApOff);
});
| 2,395
|
C++
|
.cpp
| 84
| 26.547619
| 88
| 0.756969
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| true
| false
| false
| true
| false
| false
|
5,265
|
cellAtracMulti.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellAtracMulti.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
#include "cellAtracMulti.h"
LOG_CHANNEL(cellAtracMulti);
template <>
void fmt_class_string<CellAtracMultiError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](CellAtracMultiError value)
{
switch (value)
{
STR_CASE(CELL_ATRACMULTI_ERROR_API_FAIL);
STR_CASE(CELL_ATRACMULTI_ERROR_READSIZE_OVER_BUFFER);
STR_CASE(CELL_ATRACMULTI_ERROR_UNKNOWN_FORMAT);
STR_CASE(CELL_ATRACMULTI_ERROR_READSIZE_IS_TOO_SMALL);
STR_CASE(CELL_ATRACMULTI_ERROR_ILLEGAL_SAMPLING_RATE);
STR_CASE(CELL_ATRACMULTI_ERROR_ILLEGAL_DATA);
STR_CASE(CELL_ATRACMULTI_ERROR_NO_DECODER);
STR_CASE(CELL_ATRACMULTI_ERROR_UNSET_DATA);
STR_CASE(CELL_ATRACMULTI_ERROR_DECODER_WAS_CREATED);
STR_CASE(CELL_ATRACMULTI_ERROR_ALLDATA_WAS_DECODED);
STR_CASE(CELL_ATRACMULTI_ERROR_NODATA_IN_BUFFER);
STR_CASE(CELL_ATRACMULTI_ERROR_NOT_ALIGNED_OUT_BUFFER);
STR_CASE(CELL_ATRACMULTI_ERROR_NEED_SECOND_BUFFER);
STR_CASE(CELL_ATRACMULTI_ERROR_ALLDATA_IS_ONMEMORY);
STR_CASE(CELL_ATRACMULTI_ERROR_ADD_DATA_IS_TOO_BIG);
STR_CASE(CELL_ATRACMULTI_ERROR_NONEED_SECOND_BUFFER);
STR_CASE(CELL_ATRACMULTI_ERROR_UNSET_LOOP_NUM);
STR_CASE(CELL_ATRACMULTI_ERROR_ILLEGAL_SAMPLE);
STR_CASE(CELL_ATRACMULTI_ERROR_ILLEGAL_RESET_BYTE);
STR_CASE(CELL_ATRACMULTI_ERROR_ILLEGAL_PPU_THREAD_PRIORITY);
STR_CASE(CELL_ATRACMULTI_ERROR_ILLEGAL_SPU_THREAD_PRIORITY);
STR_CASE(CELL_ATRACMULTI_ERROR_API_PARAMETER);
}
return unknown;
});
}
error_code cellAtracMultiSetDataAndGetMemSize(vm::ptr<CellAtracMultiHandle> pHandle, vm::ptr<u8> pucBufferAddr, u32 uiReadByte, u32 uiBufferByte, u32 uiOutputChNum, vm::ptr<s32> piTrackArray, vm::ptr<u32> puiWorkMemByte)
{
cellAtracMulti.warning("cellAtracMultiSetDataAndGetMemSize(pHandle=*0x%x, pucBufferAddr=*0x%x, uiReadByte=0x%x, uiBufferByte=0x%x, uiOutputChNum=%d, piTrackArray=*0x%x, puiWorkMemByte=*0x%x)",
pHandle, pucBufferAddr, uiReadByte, uiBufferByte, uiOutputChNum, piTrackArray, puiWorkMemByte);
*puiWorkMemByte = 0x1000;
return CELL_OK;
}
error_code cellAtracMultiCreateDecoder(vm::ptr<CellAtracMultiHandle> pHandle, vm::ptr<u8> pucWorkMem, u32 uiPpuThreadPriority, u32 uiSpuThreadPriority)
{
cellAtracMulti.warning("cellAtracMultiCreateDecoder(pHandle=*0x%x, pucWorkMem=*0x%x, uiPpuThreadPriority=%d, uiSpuThreadPriority=%d)", pHandle, pucWorkMem, uiPpuThreadPriority, uiSpuThreadPriority);
std::memcpy(pHandle->ucWorkMem, pucWorkMem.get_ptr(), CELL_ATRACMULTI_HANDLE_SIZE);
return CELL_OK;
}
error_code cellAtracMultiCreateDecoderExt(vm::ptr<CellAtracMultiHandle> pHandle, vm::ptr<u8> pucWorkMem, u32 uiPpuThreadPriority, vm::ptr<CellAtracMultiExtRes> pExtRes)
{
cellAtracMulti.warning("cellAtracMultiCreateDecoderExt(pHandle=*0x%x, pucWorkMem=*0x%x, uiPpuThreadPriority=%d, pExtRes=*0x%x)", pHandle, pucWorkMem, uiPpuThreadPriority, pExtRes);
std::memcpy(pHandle->ucWorkMem, pucWorkMem.get_ptr(), CELL_ATRACMULTI_HANDLE_SIZE);
return CELL_OK;
}
error_code cellAtracMultiDeleteDecoder(vm::ptr<CellAtracMultiHandle> pHandle)
{
cellAtracMulti.warning("cellAtracMultiDeleteDecoder(pHandle=*0x%x)", pHandle);
return CELL_OK;
}
error_code cellAtracMultiDecode(vm::ptr<CellAtracMultiHandle> pHandle, vm::ptr<float> pfOutAddr, vm::ptr<u32> puiSamples, vm::ptr<u32> puiFinishflag, vm::ptr<s32> piRemainFrame)
{
cellAtracMulti.warning("cellAtracMultiDecode(pHandle=*0x%x, pfOutAddr=*0x%x, puiSamples=*0x%x, puiFinishFlag=*0x%x, piRemainFrame=*0x%x)", pHandle, pfOutAddr, puiSamples, puiFinishflag, piRemainFrame);
*puiSamples = 0;
*puiFinishflag = 1;
*piRemainFrame = CELL_ATRACMULTI_ALLDATA_IS_ON_MEMORY;
return CELL_OK;
}
error_code cellAtracMultiGetStreamDataInfo(vm::ptr<CellAtracMultiHandle> pHandle, vm::pptr<u8> ppucWritePointer, vm::ptr<u32> puiWritableByte, vm::ptr<u32> puiReadPosition)
{
cellAtracMulti.warning("cellAtracMultiGetStreamDataInfo(pHandle=*0x%x, ppucWritePointer=**0x%x, puiWritableByte=*0x%x, puiReadPosition=*0x%x)", pHandle, ppucWritePointer, puiWritableByte, puiReadPosition);
ppucWritePointer->set(pHandle.addr());
*puiWritableByte = 0x1000;
*puiReadPosition = 0;
return CELL_OK;
}
error_code cellAtracMultiAddStreamData(vm::ptr<CellAtracMultiHandle> pHandle, u32 uiAddByte)
{
cellAtracMulti.warning("cellAtracMultiAddStreamData(pHandle=*0x%x, uiAddByte=0x%x)", pHandle, uiAddByte);
return CELL_OK;
}
error_code cellAtracMultiGetRemainFrame(vm::ptr<CellAtracMultiHandle> pHandle, vm::ptr<s32> piRemainFrame)
{
cellAtracMulti.warning("cellAtracMultiGetRemainFrame(pHandle=*0x%x, piRemainFrame=*0x%x)", pHandle, piRemainFrame);
*piRemainFrame = CELL_ATRACMULTI_ALLDATA_IS_ON_MEMORY;
return CELL_OK;
}
error_code cellAtracMultiGetVacantSize(vm::ptr<CellAtracMultiHandle> pHandle, vm::ptr<u32> puiVacantSize)
{
cellAtracMulti.warning("cellAtracMultiGetVacantSize(pHandle=*0x%x, puiVacantSize=*0x%x)", pHandle, puiVacantSize);
*puiVacantSize = 0x1000;
return CELL_OK;
}
error_code cellAtracMultiIsSecondBufferNeeded(vm::ptr<CellAtracMultiHandle> pHandle)
{
cellAtracMulti.warning("cellAtracMultiIsSecondBufferNeeded(pHandle=*0x%x)", pHandle);
return not_an_error(0);
}
error_code cellAtracMultiGetSecondBufferInfo(vm::ptr<CellAtracMultiHandle> pHandle, vm::ptr<u32> puiReadPosition, vm::ptr<u32> puiDataByte)
{
cellAtracMulti.warning("cellAtracMultiGetSecondBufferInfo(pHandle=*0x%x, puiReadPosition=*0x%x, puiDataByte=*0x%x)", pHandle, puiReadPosition, puiDataByte);
*puiReadPosition = 0;
*puiDataByte = 0; // write to null block will occur
return CELL_OK;
}
error_code cellAtracMultiSetSecondBuffer(vm::ptr<CellAtracMultiHandle> pHandle, vm::ptr<u8> pucSecondBufferAddr, u32 uiSecondBufferByte)
{
cellAtracMulti.warning("cellAtracMultiSetSecondBuffer(pHandle=*0x%x, pucSecondBufferAddr=*0x%x, uiSecondBufferByte=0x%x)", pHandle, pucSecondBufferAddr, uiSecondBufferByte);
return CELL_OK;
}
error_code cellAtracMultiGetChannel(vm::ptr<CellAtracMultiHandle> pHandle, vm::ptr<u32> puiChannel)
{
cellAtracMulti.warning("cellAtracMultiGetChannel(pHandle=*0x%x, puiChannel=*0x%x)", pHandle, puiChannel);
*puiChannel = 2;
return CELL_OK;
}
error_code cellAtracMultiGetMaxSample(vm::ptr<CellAtracMultiHandle> pHandle, vm::ptr<u32> puiMaxSample)
{
cellAtracMulti.warning("cellAtracMultiGetMaxSample(pHandle=*0x%x, puiMaxSample=*0x%x)", pHandle, puiMaxSample);
*puiMaxSample = 512;
return CELL_OK;
}
error_code cellAtracMultiGetNextSample(vm::ptr<CellAtracMultiHandle> pHandle, vm::ptr<u32> puiNextSample)
{
cellAtracMulti.warning("cellAtracMultiGetNextSample(pHandle=*0x%x, puiNextSample=*0x%x)", pHandle, puiNextSample);
*puiNextSample = 0;
return CELL_OK;
}
error_code cellAtracMultiGetSoundInfo(vm::ptr<CellAtracMultiHandle> pHandle, vm::ptr<s32> piEndSample, vm::ptr<s32> piLoopStartSample, vm::ptr<s32> piLoopEndSample)
{
cellAtracMulti.warning("cellAtracMultiGetSoundInfo(pHandle=*0x%x, piEndSample=*0x%x, piLoopStartSample=*0x%x, piLoopEndSample=*0x%x)", pHandle, piEndSample, piLoopStartSample, piLoopEndSample);
*piEndSample = 0;
*piLoopStartSample = 0;
*piLoopEndSample = 0;
return CELL_OK;
}
error_code cellAtracMultiGetNextDecodePosition(vm::ptr<CellAtracMultiHandle> pHandle, vm::ptr<u32> puiSamplePosition)
{
cellAtracMulti.warning("cellAtracMultiGetNextDecodePosition(pHandle=*0x%x, puiSamplePosition=*0x%x)", pHandle, puiSamplePosition);
*puiSamplePosition = 0;
return CELL_ATRACMULTI_ERROR_ALLDATA_WAS_DECODED;
}
error_code cellAtracMultiGetBitrate(vm::ptr<CellAtracMultiHandle> pHandle, vm::ptr<u32> puiBitrate)
{
cellAtracMulti.warning("cellAtracMultiGetBitrate(pHandle=*0x%x, puiBitrate=*0x%x)", pHandle, puiBitrate);
*puiBitrate = 128;
return CELL_OK;
}
error_code cellAtracMultiGetTrackArray(vm::ptr<CellAtracMultiHandle> pHandle, vm::ptr<s32> piTrackArray)
{
cellAtracMulti.error("cellAtracMultiGetTrackArray(pHandle=*0x%x, piTrackArray=*0x%x)", pHandle, piTrackArray);
return CELL_OK;
}
error_code cellAtracMultiGetLoopInfo(vm::ptr<CellAtracMultiHandle> pHandle, vm::ptr<s32> piLoopNum, vm::ptr<u32> puiLoopStatus)
{
cellAtracMulti.warning("cellAtracMultiGetLoopInfo(pHandle=*0x%x, piLoopNum=*0x%x, puiLoopStatus=*0x%x)", pHandle, piLoopNum, puiLoopStatus);
*piLoopNum = 0;
*puiLoopStatus = 0;
return CELL_OK;
}
error_code cellAtracMultiSetLoopNum(vm::ptr<CellAtracMultiHandle> pHandle, s32 iLoopNum)
{
cellAtracMulti.warning("cellAtracMultiSetLoopNum(pHandle=*0x%x, iLoopNum=%d)", pHandle, iLoopNum);
return CELL_OK;
}
error_code cellAtracMultiGetBufferInfoForResetting(vm::ptr<CellAtracMultiHandle> pHandle, u32 uiSample, vm::ptr<CellAtracMultiBufferInfo> pBufferInfo)
{
cellAtracMulti.warning("cellAtracMultiGetBufferInfoForResetting(pHandle=*0x%x, uiSample=0x%x, pBufferInfo=*0x%x)", pHandle, uiSample, pBufferInfo);
pBufferInfo->pucWriteAddr.set(pHandle.addr());
pBufferInfo->uiWritableByte = 0x1000;
pBufferInfo->uiMinWriteByte = 0;
pBufferInfo->uiReadPosition = 0;
return CELL_OK;
}
error_code cellAtracMultiResetPlayPosition(vm::ptr<CellAtracMultiHandle> pHandle, u32 uiSample, u32 uiWriteByte, vm::ptr<s32> piTrackArray)
{
cellAtracMulti.warning("cellAtracMultiResetPlayPosition(pHandle=*0x%x, uiSample=0x%x, uiWriteByte=0x%x, piTrackArray=*0x%x)", pHandle, uiSample, uiWriteByte, piTrackArray);
return CELL_OK;
}
error_code cellAtracMultiGetInternalErrorInfo(vm::ptr<CellAtracMultiHandle> pHandle, vm::ptr<s32> piResult)
{
cellAtracMulti.warning("cellAtracMultiGetInternalErrorInfo(pHandle=*0x%x, piResult=*0x%x)", pHandle, piResult);
*piResult = 0;
return CELL_OK;
}
error_code cellAtracMultiGetSamplingRate()
{
UNIMPLEMENTED_FUNC(cellAtracMulti);
return CELL_OK;
}
DECLARE(ppu_module_manager::cellAtracMulti)("cellAtracMulti", []()
{
REG_FUNC(cellAtracMulti, cellAtracMultiSetDataAndGetMemSize);
REG_FUNC(cellAtracMulti, cellAtracMultiCreateDecoder);
REG_FUNC(cellAtracMulti, cellAtracMultiCreateDecoderExt);
REG_FUNC(cellAtracMulti, cellAtracMultiDeleteDecoder);
REG_FUNC(cellAtracMulti, cellAtracMultiDecode);
REG_FUNC(cellAtracMulti, cellAtracMultiGetStreamDataInfo);
REG_FUNC(cellAtracMulti, cellAtracMultiAddStreamData);
REG_FUNC(cellAtracMulti, cellAtracMultiGetRemainFrame);
REG_FUNC(cellAtracMulti, cellAtracMultiGetVacantSize);
REG_FUNC(cellAtracMulti, cellAtracMultiIsSecondBufferNeeded);
REG_FUNC(cellAtracMulti, cellAtracMultiGetSecondBufferInfo);
REG_FUNC(cellAtracMulti, cellAtracMultiSetSecondBuffer);
REG_FUNC(cellAtracMulti, cellAtracMultiGetChannel);
REG_FUNC(cellAtracMulti, cellAtracMultiGetMaxSample);
REG_FUNC(cellAtracMulti, cellAtracMultiGetNextSample);
REG_FUNC(cellAtracMulti, cellAtracMultiGetSoundInfo);
REG_FUNC(cellAtracMulti, cellAtracMultiGetNextDecodePosition);
REG_FUNC(cellAtracMulti, cellAtracMultiGetBitrate);
REG_FUNC(cellAtracMulti, cellAtracMultiGetTrackArray);
REG_FUNC(cellAtracMulti, cellAtracMultiGetLoopInfo);
REG_FUNC(cellAtracMulti, cellAtracMultiSetLoopNum);
REG_FUNC(cellAtracMulti, cellAtracMultiGetBufferInfoForResetting);
REG_FUNC(cellAtracMulti, cellAtracMultiResetPlayPosition);
REG_FUNC(cellAtracMulti, cellAtracMultiGetInternalErrorInfo);
REG_FUNC(cellAtracMulti, cellAtracMultiGetSamplingRate);
});
| 11,165
|
C++
|
.cpp
| 219
| 48.968037
| 220
| 0.815417
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| true
| false
| false
| true
| false
| false
|
5,266
|
cell_FreeType2.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cell_FreeType2.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
LOG_CHANNEL(cell_FreeType2);
// Functions
error_code cellFreeType2Ex()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Activate_Size()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Add_Default_Modules()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Add_Module()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Alloc()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Angle_Diff()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Atan2()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Attach_File()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Attach_Stream()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Bitmap_Convert()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Bitmap_Copy()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Bitmap_Done()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Bitmap_Embolden()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Bitmap_New()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FTC_CMapCache_Lookup()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FTC_CMapCache_New()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_CeilFix()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FTC_ImageCache_Lookup()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FTC_ImageCache_New()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FTC_Manager_Done()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FTC_Manager_LookupFace()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FTC_Manager_LookupSize()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FTC_Manager_New()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FTC_Manager_RemoveFaceID()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FTC_Node_Unref()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Cos()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FTC_SBitCache_Lookup()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FTC_SBitCache_New()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_DivFix()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Done_Face()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Done_FreeType()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Done_Glyph()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Done_Library()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Done_Size()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_FloorFix()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Free()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Get_BDF_Charset_ID()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Get_BDF_Property()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Get_Char_Index()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Get_Charmap_Index()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Get_CMap_Language_ID()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Get_First_Char()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Get_Glyph()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Get_Glyph_Name()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Get_Kerning()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Get_MM_Var()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Get_Module()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Get_Multi_Master()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Get_Name_Index()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Get_Next_Char()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Get_PFR_Advance()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Get_PFR_Kerning()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Get_PFR_Metrics()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Get_Postscript_Name()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Get_PS_Font_Info()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Get_PS_Font_Private()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Get_Renderer()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Get_Sfnt_Name()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Get_Sfnt_Name_Count()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Get_Sfnt_Table()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Get_SubGlyph_Info()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Get_Track_Kerning()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Get_TrueType_Engine_Type()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Get_X11_Font_Format()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Get_WinFNT_Header()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Glyph_Copy()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Glyph_Get_CBox()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_GlyphSlot_Own_Bitmap()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Glyph_Stroke()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Glyph_StrokeBorder()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Glyph_To_Bitmap()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Glyph_Transform()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Has_PS_Glyph_Names()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Init_FreeType()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Library_Version()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_List_Add()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_List_Finalize()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_List_Find()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_List_Insert()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_List_Iterate()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_List_Remove()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_List_Up()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Load_Char()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Load_Glyph()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Load_Sfnt_Table()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Matrix_Invert()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Matrix_Multiply()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_MulDiv()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_MulFix()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_New_Face()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_New_Library()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_New_Memory()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_New_Memory_Face()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_New_Size()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Open_Face()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_OpenType_Free()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_OpenType_Validate()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Outline_Check()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Outline_Copy()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Outline_Decompose()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Outline_Done()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Outline_Embolden()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Outline_Get_BBox()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Outline_Get_Bitmap()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Outline_Get_CBox()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Outline_GetInsideBorder()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Outline_Get_Orientation()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Outline_GetOutsideBorder()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Outline_New()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Outline_Render()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Outline_Reverse()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Outline_Transform()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Outline_Translate()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Realloc()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Remove_Module()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Render_Glyph()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Request_Size()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_RoundFix()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Select_Charmap()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Select_Size()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Set_Charmap()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Set_Char_Size()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Set_Debug_Hook()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Set_MM_Blend_Coordinates()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Set_MM_Design_Coordinates()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Set_Pixel_Sizes()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Set_Renderer()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Set_Transform()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Set_Var_Blend_Coordinates()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Set_Var_Design_Coordinates()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Sfnt_Table_Info()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Sin()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Stream_OpenGzip()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Stream_OpenLZW()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Stroker_BeginSubPath()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Stroker_ConicTo()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Stroker_CubicTo()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Stroker_Done()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Stroker_EndSubPath()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Stroker_Export()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Stroker_ExportBorder()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Stroker_GetBorderCounts()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Stroker_GetCounts()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Stroker_LineTo()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Stroker_New()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Stroker_ParseOutline()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Stroker_Rewind()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Stroker_Set()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Tan()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Vector_From_Polar()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Vector_Length()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Vector_Polarize()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Vector_Rotate()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Vector_Transform()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
error_code FT_Vector_Unit()
{
UNIMPLEMENTED_FUNC(cell_FreeType2);
return CELL_OK;
}
DECLARE(ppu_module_manager::cell_FreeType2)("cell_FreeType2", []()
{
REG_FUNC(cell_FreeType2, cellFreeType2Ex);
REG_FUNC(cell_FreeType2, FT_Activate_Size);
REG_FUNC(cell_FreeType2, FT_Add_Default_Modules);
REG_FUNC(cell_FreeType2, FT_Add_Module);
REG_FUNC(cell_FreeType2, FT_Alloc);
REG_FUNC(cell_FreeType2, FT_Angle_Diff);
REG_FUNC(cell_FreeType2, FT_Atan2);
REG_FUNC(cell_FreeType2, FT_Attach_File);
REG_FUNC(cell_FreeType2, FT_Attach_Stream);
REG_FUNC(cell_FreeType2, FT_Bitmap_Convert);
REG_FUNC(cell_FreeType2, FT_Bitmap_Copy);
REG_FUNC(cell_FreeType2, FT_Bitmap_Done);
REG_FUNC(cell_FreeType2, FT_Bitmap_Embolden);
REG_FUNC(cell_FreeType2, FT_Bitmap_New);
REG_FUNC(cell_FreeType2, FTC_CMapCache_Lookup);
REG_FUNC(cell_FreeType2, FTC_CMapCache_New);
REG_FUNC(cell_FreeType2, FT_CeilFix);
REG_FUNC(cell_FreeType2, FTC_ImageCache_Lookup);
REG_FUNC(cell_FreeType2, FTC_ImageCache_New);
REG_FUNC(cell_FreeType2, FTC_Manager_Done);
REG_FUNC(cell_FreeType2, FTC_Manager_LookupFace);
REG_FUNC(cell_FreeType2, FTC_Manager_LookupSize);
REG_FUNC(cell_FreeType2, FTC_Manager_New);
REG_FUNC(cell_FreeType2, FTC_Manager_RemoveFaceID);
REG_FUNC(cell_FreeType2, FTC_Node_Unref);
REG_FUNC(cell_FreeType2, FT_Cos);
REG_FUNC(cell_FreeType2, FTC_SBitCache_Lookup);
REG_FUNC(cell_FreeType2, FTC_SBitCache_New);
REG_FUNC(cell_FreeType2, FT_DivFix);
REG_FUNC(cell_FreeType2, FT_Done_Face);
REG_FUNC(cell_FreeType2, FT_Done_FreeType);
REG_FUNC(cell_FreeType2, FT_Done_Glyph);
REG_FUNC(cell_FreeType2, FT_Done_Library);
REG_FUNC(cell_FreeType2, FT_Done_Size);
REG_FUNC(cell_FreeType2, FT_FloorFix);
REG_FUNC(cell_FreeType2, FT_Free);
REG_FUNC(cell_FreeType2, FT_Get_BDF_Charset_ID);
REG_FUNC(cell_FreeType2, FT_Get_BDF_Property);
REG_FUNC(cell_FreeType2, FT_Get_Char_Index);
REG_FUNC(cell_FreeType2, FT_Get_Charmap_Index);
REG_FUNC(cell_FreeType2, FT_Get_CMap_Language_ID);
REG_FUNC(cell_FreeType2, FT_Get_First_Char);
REG_FUNC(cell_FreeType2, FT_Get_Glyph);
REG_FUNC(cell_FreeType2, FT_Get_Glyph_Name);
REG_FUNC(cell_FreeType2, FT_Get_Kerning);
REG_FUNC(cell_FreeType2, FT_Get_MM_Var);
REG_FUNC(cell_FreeType2, FT_Get_Module);
REG_FUNC(cell_FreeType2, FT_Get_Multi_Master);
REG_FUNC(cell_FreeType2, FT_Get_Name_Index);
REG_FUNC(cell_FreeType2, FT_Get_Next_Char);
REG_FUNC(cell_FreeType2, FT_Get_PFR_Advance);
REG_FUNC(cell_FreeType2, FT_Get_PFR_Kerning);
REG_FUNC(cell_FreeType2, FT_Get_PFR_Metrics);
REG_FUNC(cell_FreeType2, FT_Get_Postscript_Name);
REG_FUNC(cell_FreeType2, FT_Get_PS_Font_Info);
REG_FUNC(cell_FreeType2, FT_Get_PS_Font_Private);
REG_FUNC(cell_FreeType2, FT_Get_Renderer);
REG_FUNC(cell_FreeType2, FT_Get_Sfnt_Name);
REG_FUNC(cell_FreeType2, FT_Get_Sfnt_Name_Count);
REG_FUNC(cell_FreeType2, FT_Get_Sfnt_Table);
REG_FUNC(cell_FreeType2, FT_Get_SubGlyph_Info);
REG_FUNC(cell_FreeType2, FT_Get_Track_Kerning);
REG_FUNC(cell_FreeType2, FT_Get_TrueType_Engine_Type);
REG_FUNC(cell_FreeType2, FT_Get_WinFNT_Header);
REG_FUNC(cell_FreeType2, FT_Get_X11_Font_Format);
REG_FUNC(cell_FreeType2, FT_Glyph_Copy);
REG_FUNC(cell_FreeType2, FT_Glyph_Get_CBox);
REG_FUNC(cell_FreeType2, FT_GlyphSlot_Own_Bitmap);
REG_FUNC(cell_FreeType2, FT_Glyph_Stroke);
REG_FUNC(cell_FreeType2, FT_Glyph_StrokeBorder);
REG_FUNC(cell_FreeType2, FT_Glyph_To_Bitmap);
REG_FUNC(cell_FreeType2, FT_Glyph_Transform);
REG_FUNC(cell_FreeType2, FT_Has_PS_Glyph_Names);
REG_FUNC(cell_FreeType2, FT_Init_FreeType);
REG_FUNC(cell_FreeType2, FT_Library_Version);
REG_FUNC(cell_FreeType2, FT_List_Add);
REG_FUNC(cell_FreeType2, FT_List_Finalize);
REG_FUNC(cell_FreeType2, FT_List_Find);
REG_FUNC(cell_FreeType2, FT_List_Insert);
REG_FUNC(cell_FreeType2, FT_List_Iterate);
REG_FUNC(cell_FreeType2, FT_List_Remove);
REG_FUNC(cell_FreeType2, FT_List_Up);
REG_FUNC(cell_FreeType2, FT_Load_Char);
REG_FUNC(cell_FreeType2, FT_Load_Glyph);
REG_FUNC(cell_FreeType2, FT_Load_Sfnt_Table);
REG_FUNC(cell_FreeType2, FT_Matrix_Invert);
REG_FUNC(cell_FreeType2, FT_Matrix_Multiply);
REG_FUNC(cell_FreeType2, FT_MulDiv);
REG_FUNC(cell_FreeType2, FT_MulFix);
REG_FUNC(cell_FreeType2, FT_New_Face);
REG_FUNC(cell_FreeType2, FT_New_Library);
REG_FUNC(cell_FreeType2, FT_New_Memory);
REG_FUNC(cell_FreeType2, FT_New_Memory_Face);
REG_FUNC(cell_FreeType2, FT_New_Size);
REG_FUNC(cell_FreeType2, FT_Open_Face);
REG_FUNC(cell_FreeType2, FT_OpenType_Free);
REG_FUNC(cell_FreeType2, FT_OpenType_Validate);
REG_FUNC(cell_FreeType2, FT_Outline_Check);
REG_FUNC(cell_FreeType2, FT_Outline_Copy);
REG_FUNC(cell_FreeType2, FT_Outline_Decompose);
REG_FUNC(cell_FreeType2, FT_Outline_Done);
REG_FUNC(cell_FreeType2, FT_Outline_Embolden);
REG_FUNC(cell_FreeType2, FT_Outline_Get_BBox);
REG_FUNC(cell_FreeType2, FT_Outline_Get_Bitmap);
REG_FUNC(cell_FreeType2, FT_Outline_Get_CBox);
REG_FUNC(cell_FreeType2, FT_Outline_GetInsideBorder);
REG_FUNC(cell_FreeType2, FT_Outline_Get_Orientation);
REG_FUNC(cell_FreeType2, FT_Outline_GetOutsideBorder);
REG_FUNC(cell_FreeType2, FT_Outline_New);
REG_FUNC(cell_FreeType2, FT_Outline_Render);
REG_FUNC(cell_FreeType2, FT_Outline_Reverse);
REG_FUNC(cell_FreeType2, FT_Outline_Transform);
REG_FUNC(cell_FreeType2, FT_Outline_Translate);
REG_FUNC(cell_FreeType2, FT_Realloc);
REG_FUNC(cell_FreeType2, FT_Remove_Module);
REG_FUNC(cell_FreeType2, FT_Render_Glyph);
REG_FUNC(cell_FreeType2, FT_Request_Size);
REG_FUNC(cell_FreeType2, FT_RoundFix);
REG_FUNC(cell_FreeType2, FT_Select_Charmap);
REG_FUNC(cell_FreeType2, FT_Select_Size);
REG_FUNC(cell_FreeType2, FT_Set_Charmap);
REG_FUNC(cell_FreeType2, FT_Set_Char_Size);
REG_FUNC(cell_FreeType2, FT_Set_Debug_Hook);
REG_FUNC(cell_FreeType2, FT_Set_MM_Blend_Coordinates);
REG_FUNC(cell_FreeType2, FT_Set_MM_Design_Coordinates);
REG_FUNC(cell_FreeType2, FT_Set_Pixel_Sizes);
REG_FUNC(cell_FreeType2, FT_Set_Renderer);
REG_FUNC(cell_FreeType2, FT_Set_Transform);
REG_FUNC(cell_FreeType2, FT_Set_Var_Blend_Coordinates);
REG_FUNC(cell_FreeType2, FT_Set_Var_Design_Coordinates);
REG_FUNC(cell_FreeType2, FT_Sfnt_Table_Info);
REG_FUNC(cell_FreeType2, FT_Sin);
REG_FUNC(cell_FreeType2, FT_Stream_OpenGzip);
REG_FUNC(cell_FreeType2, FT_Stream_OpenLZW);
REG_FUNC(cell_FreeType2, FT_Stroker_BeginSubPath);
REG_FUNC(cell_FreeType2, FT_Stroker_ConicTo);
REG_FUNC(cell_FreeType2, FT_Stroker_CubicTo);
REG_FUNC(cell_FreeType2, FT_Stroker_Done);
REG_FUNC(cell_FreeType2, FT_Stroker_EndSubPath);
REG_FUNC(cell_FreeType2, FT_Stroker_Export);
REG_FUNC(cell_FreeType2, FT_Stroker_ExportBorder);
REG_FUNC(cell_FreeType2, FT_Stroker_GetBorderCounts);
REG_FUNC(cell_FreeType2, FT_Stroker_GetCounts);
REG_FUNC(cell_FreeType2, FT_Stroker_LineTo);
REG_FUNC(cell_FreeType2, FT_Stroker_New);
REG_FUNC(cell_FreeType2, FT_Stroker_ParseOutline);
REG_FUNC(cell_FreeType2, FT_Stroker_Rewind);
REG_FUNC(cell_FreeType2, FT_Stroker_Set);
REG_FUNC(cell_FreeType2, FT_Tan);
REG_FUNC(cell_FreeType2, FT_Vector_From_Polar);
REG_FUNC(cell_FreeType2, FT_Vector_Length);
REG_FUNC(cell_FreeType2, FT_Vector_Polarize);
REG_FUNC(cell_FreeType2, FT_Vector_Rotate);
REG_FUNC(cell_FreeType2, FT_Vector_Transform);
REG_FUNC(cell_FreeType2, FT_Vector_Unit);
});
| 21,193
|
C++
|
.cpp
| 937
| 20.951974
| 66
| 0.777828
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| true
| false
| false
| true
| false
| false
|
5,267
|
cellHttp.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellHttp.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
#include "Emu/IdManager.h"
#include "cellHttpUtil.h"
#include "cellHttp.h"
#include "cellSsl.h"
LOG_CHANNEL(cellHttp);
template<>
void fmt_class_string<CellHttpError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_HTTP_ERROR_ALREADY_INITIALIZED);
STR_CASE(CELL_HTTP_ERROR_NOT_INITIALIZED);
STR_CASE(CELL_HTTP_ERROR_NO_MEMORY);
STR_CASE(CELL_HTTP_ERROR_NO_BUFFER);
STR_CASE(CELL_HTTP_ERROR_NO_STRING);
STR_CASE(CELL_HTTP_ERROR_INSUFFICIENT);
STR_CASE(CELL_HTTP_ERROR_INVALID_URI);
STR_CASE(CELL_HTTP_ERROR_INVALID_HEADER);
STR_CASE(CELL_HTTP_ERROR_BAD_METHOD);
STR_CASE(CELL_HTTP_ERROR_BAD_CLIENT);
STR_CASE(CELL_HTTP_ERROR_BAD_TRANS);
STR_CASE(CELL_HTTP_ERROR_NO_CONNECTION);
STR_CASE(CELL_HTTP_ERROR_NO_REQUEST_SENT);
STR_CASE(CELL_HTTP_ERROR_ALREADY_BUILT);
STR_CASE(CELL_HTTP_ERROR_ALREADY_SENT);
STR_CASE(CELL_HTTP_ERROR_NO_HEADER);
STR_CASE(CELL_HTTP_ERROR_NO_CONTENT_LENGTH);
STR_CASE(CELL_HTTP_ERROR_TOO_MANY_REDIRECTS);
STR_CASE(CELL_HTTP_ERROR_TOO_MANY_AUTHS);
STR_CASE(CELL_HTTP_ERROR_TRANS_NO_CONNECTION);
STR_CASE(CELL_HTTP_ERROR_CB_FAILED);
STR_CASE(CELL_HTTP_ERROR_NOT_PIPED);
STR_CASE(CELL_HTTP_ERROR_OUT_OF_ORDER_PIPE);
STR_CASE(CELL_HTTP_ERROR_TRANS_ABORTED);
STR_CASE(CELL_HTTP_ERROR_BROKEN_PIPELINE);
STR_CASE(CELL_HTTP_ERROR_UNAVAILABLE);
STR_CASE(CELL_HTTP_ERROR_INVALID_VALUE);
STR_CASE(CELL_HTTP_ERROR_CANNOT_AUTHENTICATE);
STR_CASE(CELL_HTTP_ERROR_COOKIE_NOT_FOUND);
STR_CASE(CELL_HTTP_ERROR_COOKIE_INVALID_DOMAIN);
STR_CASE(CELL_HTTP_ERROR_CACHE_ALREADY_INITIALIZED);
STR_CASE(CELL_HTTP_ERROR_CACHE_NOT_INITIALIZED);
STR_CASE(CELL_HTTP_ERROR_LINE_EXCEEDS_MAX);
STR_CASE(CELL_HTTP_ERROR_REQUIRES_BASIC_AUTH);
STR_CASE(CELL_HTTP_ERROR_UNKNOWN);
STR_CASE(CELL_HTTP_ERROR_INTERNAL);
STR_CASE(CELL_HTTP_ERROR_NONREMOVABLE);
STR_CASE(CELL_HTTP_ERROR_BAD_CONN);
STR_CASE(CELL_HTTP_ERROR_BAD_MAN);
STR_CASE(CELL_HTTP_ERROR_NO_POOL);
STR_CASE(CELL_HTTP_ERROR_NO_REQUEST);
STR_CASE(CELL_HTTP_ERROR_LOCK_FAILED);
STR_CASE(CELL_HTTP_ERROR_INVALID_DATA);
STR_CASE(CELL_HTTP_ERROR_BROKEN_CHUNK);
STR_CASE(CELL_HTTP_ERROR_DECODE_SETUP);
STR_CASE(CELL_HTTP_ERROR_DECODE_STREAM);
STR_CASE(CELL_HTTP_ERROR_BROKEN_DECODE_STREAM);
STR_CASE(CELL_HTTP_ERROR_INVALID_DCACHE_PATH);
STR_CASE(CELL_HTTP_ERROR_DCACHE_ALREADY_INITIALIZED);
STR_CASE(CELL_HTTP_ERROR_DCACHE_NOT_INITIALIZED);
STR_CASE(CELL_HTTP_ERROR_TOO_MANY_DCACHE_ENTRY);
STR_CASE(CELL_HTTP_ERROR_DUP_DCACHE_ENTRY);
STR_CASE(CELL_HTTP_ERROR_WRITE_DCACHE);
STR_CASE(CELL_HTTP_ERROR_READ_DCACHE);
STR_CASE(CELL_HTTP_ERROR_CACHE_TOO_LARGE);
STR_CASE(CELL_HTTP_ERROR_INVALID_DCACHE_VERSION);
STR_CASE(CELL_HTTP_ERROR_DCACHE_FILE_BROKEN);
STR_CASE(CELL_HTTP_ERROR_DCACHE_EXCEEDS_MAX);
STR_CASE(CELL_HTTP_ERROR_DCACHE_BUSY);
STR_CASE(CELL_HTTP_ERROR_DCACHE_INDEX_BROKEN);
STR_CASE(CELL_HTTP_ERROR_INVALID_DCACHE_INDEX_NODE);
STR_CASE(CELL_HTTP_ERROR_DCACHE_FILE_INCONSISTENCY);
STR_CASE(CELL_HTTP_ERROR_DCACHE_URI_TOO_LONG);
STR_CASE(CELL_HTTP_ERROR_READ_DCACHE_EOF);
STR_CASE(CELL_HTTP_ERROR_END_OF_DCACHE_INDEX_NODE);
STR_CASE(CELL_HTTP_ERROR_NO_CACHE_MEMORY);
STR_CASE(CELL_HTTP_ERROR_DCACHE_BROKEN);
STR_CASE(CELL_HTTP_ERROR_DCACHE_TOO_MANY_WRITE);
STR_CASE(CELL_HTTP_ERROR_DCACHE_TOO_MANY_READ);
STR_CASE(CELL_HTTP_ERROR_DCACHE_FATAL);
STR_CASE(CELL_HTTP_ERROR_DCACHE_UNSUPPORTED_FEATURE);
STR_CASE(CELL_HTTP_ERROR_DCACHE_INDEX_IS_ALREADY_OPEN);
STR_CASE(CELL_HTTP_ERROR_DCACHE_INDEX_IS_OPENING);
STR_CASE(CELL_HTTP_ERROR_DCACHE_UNKNOWN);
STR_CASE(CELL_HTTP_ERROR_DCACHE_INDEX_IS_CLOSED);
STR_CASE(CELL_HTTP_ERROR_DCACHE_ABORTED);
STR_CASE(CELL_HTTP_ERROR_DCACHE_INDEX_IS_CLOSING);
STR_CASE(CELL_HTTP_ERROR_DCACHE_UNKNOWN_INDEX_STATE);
STR_CASE(CELL_HTTP_ERROR_NET_FIN);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_TIMEOUT);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_TIMEOUT);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_TIMEOUT);
}
return unknown;
});
}
template<>
void fmt_class_string<CellHttpsError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_HTTPS_ERROR_CERTIFICATE_LOAD);
STR_CASE(CELL_HTTPS_ERROR_BAD_MEMORY);
STR_CASE(CELL_HTTPS_ERROR_CONTEXT_CREATION);
STR_CASE(CELL_HTTPS_ERROR_CONNECTION_CREATION);
STR_CASE(CELL_HTTPS_ERROR_SOCKET_ASSOCIATION);
STR_CASE(CELL_HTTPS_ERROR_HANDSHAKE);
STR_CASE(CELL_HTTPS_ERROR_LOOKUP_CERTIFICATE);
STR_CASE(CELL_HTTPS_ERROR_NO_SSL);
STR_CASE(CELL_HTTPS_ERROR_KEY_LOAD);
STR_CASE(CELL_HTTPS_ERROR_CERT_KEY_MISMATCH);
STR_CASE(CELL_HTTPS_ERROR_KEY_NEEDS_CERT);
STR_CASE(CELL_HTTPS_ERROR_CERT_NEEDS_KEY);
STR_CASE(CELL_HTTPS_ERROR_RETRY_CONNECTION);
STR_CASE(CELL_HTTPS_ERROR_NET_SSL_CONNECT);
STR_CASE(CELL_HTTPS_ERROR_NET_SSL_SEND);
STR_CASE(CELL_HTTPS_ERROR_NET_SSL_RECV);
}
return unknown;
});
}
template<>
void fmt_class_string<CellHttpErrorNet>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_HTTP_ERROR_NET_RESOLVER_NETDB_INTERNAL);
STR_CASE(CELL_HTTP_ERROR_NET_RESOLVER_HOST_NOT_FOUND);
STR_CASE(CELL_HTTP_ERROR_NET_RESOLVER_TRY_AGAIN);
STR_CASE(CELL_HTTP_ERROR_NET_RESOLVER_NO_RECOVERY);
STR_CASE(CELL_HTTP_ERROR_NET_RESOLVER_NO_DATA);
//STR_CASE(CELL_HTTP_ERROR_NET_RESOLVER_NO_ADDRESS);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_EPERM);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_ENOENT);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_ESRCH);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_EINTR);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_EIO);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_ENXIO);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_E2BIG);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_ENOEXC);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_EBADF);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_ECHILD);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_EDEADLK);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_ENOMEM);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_EACCES);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_EFAULT);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_ENOTBLK);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_EBUSY);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_EEXIST);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_EXDEV);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_ENODEV);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_ENOTDIR);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_EISDIR);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_EINVAL);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_ENFILE);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_EMFILE);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_ENOTTY);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_ETXTBSY);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_EFBIG);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_ENOSPC);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_ESPIPE);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_EROFS);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_EMLINK);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_EPIPE);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_EDOM);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_ERANGE);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_EAGAIN);
//STR_CASE(CELL_HTTP_ERROR_NET_ABORT_EWOULDBLOCK);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_EINPROGRESS);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_EALREADY);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_ENOTSOCK);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_EDESTADDRREQ);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_EMSGSIZE);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_EPROTOTYPE);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_ENOPROTOOPT);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_EPROTONOSUPPORT);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_ESOCKTNOSUPPORT);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_EOPNOTSUPP);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_EPFNOSUPPORT);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_EAFNOSUPPORT);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_EADDRINUSE);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_EADDRNOTAVAIL);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_ENETDOWN);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_ENETUNREACH);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_ENETRESET);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_ECONNABORTED);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_ECONNRESET);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_ENOBUFS);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_EISCONN);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_ENOTCONN);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_ESHUTDOWN);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_ETOOMANYREFS);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_ETIMEDOUT);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_ECONNREFUSED);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_ELOOP);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_ENAMETOOLONG);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_EHOSTDOWN);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_EHOSTUNREACH);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_ENOTEMPTY);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_EPROCLIM);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_EUSERS);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_EDQUOT);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_ESTALE);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_EREMOTE);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_EBADRPC);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_ERPCMISMATCH);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_EPROGUNAVAIL);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_EPROGMISMATCH);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_EPROCUNAVAIL);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_ENOLCK);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_ENOSYS);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_EFTYPE);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_EAUTH);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_ENEEDAUTH);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_EIDRM);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_ENOMSG);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_EOVERFLOW);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_EILSEQ);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_ENOTSUP);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_ECANCELED);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_EBADMSG);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_ENODATA);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_ENOSR);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_ENOSTR);
STR_CASE(CELL_HTTP_ERROR_NET_ABORT_ETIME);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_EPERM);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_ENOENT);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_ESRCH);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_EINTR);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_EIO);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_ENXIO);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_E2BIG);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_ENOEXC);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_EBADF);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_ECHILD);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_EDEADLK);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_ENOMEM);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_EACCES);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_EFAULT);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_ENOTBLK);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_EBUSY);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_EEXIST);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_EXDEV);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_ENODEV);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_ENOTDIR);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_EISDIR);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_EINVAL);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_ENFILE);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_EMFILE);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_ENOTTY);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_ETXTBSY);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_EFBIG);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_ENOSPC);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_ESPIPE);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_EROFS);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_EMLINK);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_EPIPE);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_EDOM);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_ERANGE);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_EAGAIN);
//STR_CASE(CELL_HTTP_ERROR_NET_OPTION_EWOULDBLOCK);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_EINPROGRESS);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_EALREADY);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_ENOTSOCK);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_EDESTADDRREQ);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_EMSGSIZE);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_EPROTOTYPE);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_ENOPROTOOPT);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_EPROTONOSUPPORT);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_ESOCKTNOSUPPORT);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_EOPNOTSUPP);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_EPFNOSUPPORT);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_EAFNOSUPPORT);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_EADDRINUSE);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_EADDRNOTAVAIL);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_ENETDOWN);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_ENETUNREACH);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_ENETRESET);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_ECONNABORTED);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_ECONNRESET);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_ENOBUFS);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_EISCONN);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_ENOTCONN);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_ESHUTDOWN);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_ETOOMANYREFS);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_ETIMEDOUT);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_ECONNREFUSED);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_ELOOP);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_ENAMETOOLONG);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_EHOSTDOWN);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_EHOSTUNREACH);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_ENOTEMPTY);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_EPROCLIM);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_EUSERS);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_EDQUOT);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_ESTALE);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_EREMOTE);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_EBADRPC);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_ERPCMISMATCH);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_EPROGUNAVAIL);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_EPROGMISMATCH);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_EPROCUNAVAIL);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_ENOLCK);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_ENOSYS);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_EFTYPE);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_EAUTH);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_ENEEDAUTH);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_EIDRM);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_ENOMSG);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_EOVERFLOW);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_EILSEQ);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_ENOTSUP);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_ECANCELED);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_EBADMSG);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_ENODATA);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_ENOSR);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_ENOSTR);
STR_CASE(CELL_HTTP_ERROR_NET_OPTION_ETIME);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_EPERM);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_ENOENT);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_ESRCH);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_EINTR);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_EIO);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_ENXIO);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_E2BIG);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_ENOEXC);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_EBADF);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_ECHILD);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_EDEADLK);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_ENOMEM);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_EACCES);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_EFAULT);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_ENOTBLK);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_EBUSY);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_EEXIST);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_EXDEV);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_ENODEV);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_ENOTDIR);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_EISDIR);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_EINVAL);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_ENFILE);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_EMFILE);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_ENOTTY);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_ETXTBSY);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_EFBIG);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_ENOSPC);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_ESPIPE);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_EROFS);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_EMLINK);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_EPIPE);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_EDOM);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_ERANGE);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_EAGAIN);
//STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_EWOULDBLOCK);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_EINPROGRESS);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_EALREADY);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_ENOTSOCK);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_EDESTADDRREQ);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_EMSGSIZE);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_EPROTOTYPE);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_ENOPROTOOPT);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_EPROTONOSUPPORT);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_ESOCKTNOSUPPORT);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_EOPNOTSUPP);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_EPFNOSUPPORT);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_EAFNOSUPPORT);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_EADDRINUSE);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_EADDRNOTAVAIL);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_ENETDOWN);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_ENETUNREACH);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_ENETRESET);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_ECONNABORTED);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_ECONNRESET);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_ENOBUFS);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_EISCONN);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_ENOTCONN);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_ESHUTDOWN);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_ETOOMANYREFS);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_ETIMEDOUT);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_ECONNREFUSED);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_ELOOP);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_ENAMETOOLONG);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_EHOSTDOWN);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_EHOSTUNREACH);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_ENOTEMPTY);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_EPROCLIM);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_EUSERS);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_EDQUOT);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_ESTALE);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_EREMOTE);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_EBADRPC);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_ERPCMISMATCH);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_EPROGUNAVAIL);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_EPROGMISMATCH);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_EPROCUNAVAIL);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_ENOLCK);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_ENOSYS);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_EFTYPE);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_EAUTH);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_ENEEDAUTH);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_EIDRM);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_ENOMSG);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_EOVERFLOW);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_EILSEQ);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_ENOTSUP);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_ECANCELED);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_EBADMSG);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_ENODATA);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_ENOSR);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_ENOSTR);
STR_CASE(CELL_HTTP_ERROR_NET_SOCKET_ETIME);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_EPERM);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_ENOENT);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_ESRCH);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_EINTR);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_EIO);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_ENXIO);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_E2BIG);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_ENOEXC);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_EBADF);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_ECHILD);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_EDEADLK);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_ENOMEM);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_EACCES);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_EFAULT);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_ENOTBLK);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_EBUSY);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_EEXIST);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_EXDEV);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_ENODEV);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_ENOTDIR);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_EISDIR);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_EINVAL);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_ENFILE);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_EMFILE);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_ENOTTY);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_ETXTBSY);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_EFBIG);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_ENOSPC);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_ESPIPE);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_EROFS);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_EMLINK);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_EPIPE);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_EDOM);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_ERANGE);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_EAGAIN);
//STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_EWOULDBLOCK);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_EINPROGRESS);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_EALREADY);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_ENOTSOCK);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_EDESTADDRREQ);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_EMSGSIZE);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_EPROTOTYPE);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_ENOPROTOOPT);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_EPROTONOSUPPORT);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_ESOCKTNOSUPPORT);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_EOPNOTSUPP);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_EPFNOSUPPORT);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_EAFNOSUPPORT);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_EADDRINUSE);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_EADDRNOTAVAIL);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_ENETDOWN);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_ENETUNREACH);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_ENETRESET);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_ECONNABORTED);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_ECONNRESET);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_ENOBUFS);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_EISCONN);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_ENOTCONN);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_ESHUTDOWN);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_ETOOMANYREFS);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_ETIMEDOUT);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_ECONNREFUSED);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_ELOOP);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_ENAMETOOLONG);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_EHOSTDOWN);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_EHOSTUNREACH);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_ENOTEMPTY);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_EPROCLIM);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_EUSERS);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_EDQUOT);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_ESTALE);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_EREMOTE);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_EBADRPC);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_ERPCMISMATCH);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_EPROGUNAVAIL);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_EPROGMISMATCH);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_EPROCUNAVAIL);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_ENOLCK);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_ENOSYS);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_EFTYPE);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_EAUTH);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_ENEEDAUTH);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_EIDRM);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_ENOMSG);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_EOVERFLOW);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_EILSEQ);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_ENOTSUP);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_ECANCELED);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_EBADMSG);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_ENODATA);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_ENOSR);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_ENOSTR);
STR_CASE(CELL_HTTP_ERROR_NET_CONNECT_ETIME);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_EPERM);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_ENOENT);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_ESRCH);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_EINTR);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_EIO);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_ENXIO);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_E2BIG);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_ENOEXC);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_EBADF);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_ECHILD);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_EDEADLK);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_ENOMEM);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_EACCES);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_EFAULT);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_ENOTBLK);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_EBUSY);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_EEXIST);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_EXDEV);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_ENODEV);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_ENOTDIR);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_EISDIR);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_EINVAL);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_ENFILE);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_EMFILE);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_ENOTTY);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_ETXTBSY);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_EFBIG);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_ENOSPC);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_ESPIPE);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_EROFS);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_EMLINK);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_EPIPE);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_EDOM);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_ERANGE);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_EAGAIN);
//STR_CASE(CELL_HTTP_ERROR_NET_SEND_EWOULDBLOCK);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_EINPROGRESS);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_EALREADY);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_ENOTSOCK);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_EDESTADDRREQ);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_EMSGSIZE);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_EPROTOTYPE);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_ENOPROTOOPT);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_EPROTONOSUPPORT);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_ESOCKTNOSUPPORT);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_EOPNOTSUPP);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_EPFNOSUPPORT);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_EAFNOSUPPORT);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_EADDRINUSE);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_EADDRNOTAVAIL);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_ENETDOWN);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_ENETUNREACH);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_ENETRESET);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_ECONNABORTED);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_ECONNRESET);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_ENOBUFS);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_EISCONN);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_ENOTCONN);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_ESHUTDOWN);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_ETOOMANYREFS);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_ETIMEDOUT);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_ECONNREFUSED);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_ELOOP);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_ENAMETOOLONG);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_EHOSTDOWN);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_EHOSTUNREACH);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_ENOTEMPTY);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_EPROCLIM);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_EUSERS);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_EDQUOT);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_ESTALE);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_EREMOTE);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_EBADRPC);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_ERPCMISMATCH);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_EPROGUNAVAIL);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_EPROGMISMATCH);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_EPROCUNAVAIL);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_ENOLCK);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_ENOSYS);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_EFTYPE);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_EAUTH);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_ENEEDAUTH);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_EIDRM);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_ENOMSG);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_EOVERFLOW);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_EILSEQ);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_ENOTSUP);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_ECANCELED);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_EBADMSG);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_ENODATA);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_ENOSR);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_ENOSTR);
STR_CASE(CELL_HTTP_ERROR_NET_SEND_ETIME);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_EPERM);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_ENOENT);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_ESRCH);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_EINTR);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_EIO);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_ENXIO);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_E2BIG);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_ENOEXC);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_EBADF);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_ECHILD);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_EDEADLK);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_ENOMEM);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_EACCES);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_EFAULT);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_ENOTBLK);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_EBUSY);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_EEXIST);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_EXDEV);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_ENODEV);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_ENOTDIR);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_EISDIR);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_EINVAL);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_ENFILE);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_EMFILE);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_ENOTTY);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_ETXTBSY);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_EFBIG);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_ENOSPC);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_ESPIPE);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_EROFS);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_EMLINK);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_EPIPE);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_EDOM);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_ERANGE);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_EAGAIN);
//STR_CASE(CELL_HTTP_ERROR_NET_RECV_EWOULDBLOCK);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_EINPROGRESS);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_EALREADY);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_ENOTSOCK);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_EDESTADDRREQ);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_EMSGSIZE);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_EPROTOTYPE);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_ENOPROTOOPT);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_EPROTONOSUPPORT);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_ESOCKTNOSUPPORT);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_EOPNOTSUPP);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_EPFNOSUPPORT);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_EAFNOSUPPORT);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_EADDRINUSE);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_EADDRNOTAVAIL);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_ENETDOWN);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_ENETUNREACH);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_ENETRESET);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_ECONNABORTED);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_ECONNRESET);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_ENOBUFS);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_EISCONN);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_ENOTCONN);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_ESHUTDOWN);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_ETOOMANYREFS);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_ETIMEDOUT);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_ECONNREFUSED);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_ELOOP);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_ENAMETOOLONG);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_EHOSTDOWN);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_EHOSTUNREACH);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_ENOTEMPTY);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_EPROCLIM);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_EUSERS);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_EDQUOT);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_ESTALE);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_EREMOTE);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_EBADRPC);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_ERPCMISMATCH);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_EPROGUNAVAIL);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_EPROGMISMATCH);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_EPROCUNAVAIL);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_ENOLCK);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_ENOSYS);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_EFTYPE);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_EAUTH);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_ENEEDAUTH);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_EIDRM);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_ENOMSG);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_EOVERFLOW);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_EILSEQ);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_ENOTSUP);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_ECANCELED);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_EBADMSG);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_ENODATA);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_ENOSR);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_ENOSTR);
STR_CASE(CELL_HTTP_ERROR_NET_RECV_ETIME);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_EPERM);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_ENOENT);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_ESRCH);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_EINTR);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_EIO);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_ENXIO);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_E2BIG);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_ENOEXC);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_EBADF);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_ECHILD);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_EDEADLK);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_ENOMEM);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_EACCES);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_EFAULT);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_ENOTBLK);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_EBUSY);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_EEXIST);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_EXDEV);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_ENODEV);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_ENOTDIR);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_EISDIR);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_EINVAL);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_ENFILE);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_EMFILE);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_ENOTTY);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_ETXTBSY);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_EFBIG);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_ENOSPC);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_ESPIPE);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_EROFS);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_EMLINK);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_EPIPE);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_EDOM);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_ERANGE);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_EAGAIN);
//STR_CASE(CELL_HTTP_ERROR_NET_SELECT_EWOULDBLOCK);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_EINPROGRESS);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_EALREADY);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_ENOTSOCK);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_EDESTADDRREQ);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_EMSGSIZE);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_EPROTOTYPE);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_ENOPROTOOPT);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_EPROTONOSUPPORT);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_ESOCKTNOSUPPORT);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_EOPNOTSUPP);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_EPFNOSUPPORT);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_EAFNOSUPPORT);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_EADDRINUSE);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_EADDRNOTAVAIL);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_ENETDOWN);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_ENETUNREACH);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_ENETRESET);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_ECONNABORTED);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_ECONNRESET);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_ENOBUFS);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_EISCONN);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_ENOTCONN);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_ESHUTDOWN);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_ETOOMANYREFS);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_ETIMEDOUT);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_ECONNREFUSED);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_ELOOP);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_ENAMETOOLONG);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_EHOSTDOWN);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_EHOSTUNREACH);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_ENOTEMPTY);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_EPROCLIM);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_EUSERS);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_EDQUOT);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_ESTALE);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_EREMOTE);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_EBADRPC);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_ERPCMISMATCH);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_EPROGUNAVAIL);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_EPROGMISMATCH);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_EPROCUNAVAIL);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_ENOLCK);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_ENOSYS);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_EFTYPE);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_EAUTH);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_ENEEDAUTH);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_EIDRM);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_ENOMSG);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_EOVERFLOW);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_EILSEQ);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_ENOTSUP);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_ECANCELED);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_EBADMSG);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_ENODATA);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_ENOSR);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_ENOSTR);
STR_CASE(CELL_HTTP_ERROR_NET_SELECT_ETIME);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_EPERM);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_ENOENT);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_ESRCH);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_EINTR);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_EIO);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_ENXIO);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_E2BIG);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_ENOEXC);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_EBADF);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_ECHILD);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_EDEADLK);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_ENOMEM);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_EACCES);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_EFAULT);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_ENOTBLK);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_EBUSY);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_EEXIST);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_EXDEV);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_ENODEV);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_ENOTDIR);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_EISDIR);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_EINVAL);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_ENFILE);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_EMFILE);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_ENOTTY);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_ETXTBSY);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_EFBIG);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_ENOSPC);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_ESPIPE);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_EROFS);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_EMLINK);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_EPIPE);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_EDOM);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_ERANGE);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_EAGAIN);
//STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_EWOULDBLOCK);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_EINPROGRESS);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_EALREADY);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_ENOTSOCK);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_EDESTADDRREQ);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_EMSGSIZE);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_EPROTOTYPE);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_ENOPROTOOPT);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_EPROTONOSUPPORT);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_ESOCKTNOSUPPORT);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_EOPNOTSUPP);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_EPFNOSUPPORT);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_EAFNOSUPPORT);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_EADDRINUSE);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_EADDRNOTAVAIL);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_ENETDOWN);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_ENETUNREACH);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_ENETRESET);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_ECONNABORTED);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_ECONNRESET);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_ENOBUFS);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_EISCONN);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_ENOTCONN);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_ESHUTDOWN);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_ETOOMANYREFS);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_ETIMEDOUT);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_ECONNREFUSED);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_ELOOP);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_ENAMETOOLONG);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_EHOSTDOWN);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_EHOSTUNREACH);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_ENOTEMPTY);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_EPROCLIM);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_EUSERS);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_EDQUOT);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_ESTALE);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_EREMOTE);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_EBADRPC);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_ERPCMISMATCH);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_EPROGUNAVAIL);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_EPROGMISMATCH);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_EPROCUNAVAIL);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_ENOLCK);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_ENOSYS);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_EFTYPE);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_EAUTH);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_ENEEDAUTH);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_EIDRM);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_ENOMSG);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_EOVERFLOW);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_EILSEQ);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_ENOTSUP);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_ECANCELED);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_EBADMSG);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_ENODATA);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_ENOSR);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_ENOSTR);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_CONNECT_ETIME);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_EPERM);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_ENOENT);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_ESRCH);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_EINTR);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_EIO);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_ENXIO);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_E2BIG);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_ENOEXC);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_EBADF);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_ECHILD);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_EDEADLK);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_ENOMEM);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_EACCES);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_EFAULT);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_ENOTBLK);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_EBUSY);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_EEXIST);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_EXDEV);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_ENODEV);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_ENOTDIR);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_EISDIR);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_EINVAL);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_ENFILE);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_EMFILE);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_ENOTTY);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_ETXTBSY);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_EFBIG);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_ENOSPC);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_ESPIPE);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_EROFS);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_EMLINK);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_EPIPE);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_EDOM);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_ERANGE);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_EAGAIN);
//STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_EWOULDBLOCK);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_EINPROGRESS);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_EALREADY);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_ENOTSOCK);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_EDESTADDRREQ);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_EMSGSIZE);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_EPROTOTYPE);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_ENOPROTOOPT);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_EPROTONOSUPPORT);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_ESOCKTNOSUPPORT);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_EOPNOTSUPP);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_EPFNOSUPPORT);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_EAFNOSUPPORT);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_EADDRINUSE);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_EADDRNOTAVAIL);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_ENETDOWN);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_ENETUNREACH);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_ENETRESET);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_ECONNABORTED);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_ECONNRESET);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_ENOBUFS);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_EISCONN);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_ENOTCONN);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_ESHUTDOWN);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_ETOOMANYREFS);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_ETIMEDOUT);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_ECONNREFUSED);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_ELOOP);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_ENAMETOOLONG);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_EHOSTDOWN);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_EHOSTUNREACH);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_ENOTEMPTY);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_EPROCLIM);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_EUSERS);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_EDQUOT);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_ESTALE);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_EREMOTE);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_EBADRPC);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_ERPCMISMATCH);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_EPROGUNAVAIL);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_EPROGMISMATCH);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_EPROCUNAVAIL);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_ENOLCK);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_ENOSYS);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_EFTYPE);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_EAUTH);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_ENEEDAUTH);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_EIDRM);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_ENOMSG);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_EOVERFLOW);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_EILSEQ);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_ENOTSUP);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_ECANCELED);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_EBADMSG);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_ENODATA);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_ENOSR);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_ENOSTR);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_SEND_ETIME);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_EPERM);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_ENOENT);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_ESRCH);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_EINTR);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_EIO);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_ENXIO);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_E2BIG);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_ENOEXC);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_EBADF);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_ECHILD);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_EDEADLK);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_ENOMEM);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_EACCES);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_EFAULT);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_ENOTBLK);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_EBUSY);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_EEXIST);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_EXDEV);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_ENODEV);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_ENOTDIR);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_EISDIR);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_EINVAL);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_ENFILE);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_EMFILE);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_ENOTTY);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_ETXTBSY);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_EFBIG);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_ENOSPC);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_ESPIPE);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_EROFS);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_EMLINK);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_EPIPE);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_EDOM);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_ERANGE);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_EAGAIN);
//STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_EWOULDBLOCK);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_EINPROGRESS);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_EALREADY);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_ENOTSOCK);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_EDESTADDRREQ);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_EMSGSIZE);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_EPROTOTYPE);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_ENOPROTOOPT);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_EPROTONOSUPPORT);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_ESOCKTNOSUPPORT);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_EOPNOTSUPP);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_EPFNOSUPPORT);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_EAFNOSUPPORT);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_EADDRINUSE);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_EADDRNOTAVAIL);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_ENETDOWN);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_ENETUNREACH);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_ENETRESET);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_ECONNABORTED);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_ECONNRESET);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_ENOBUFS);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_EISCONN);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_ENOTCONN);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_ESHUTDOWN);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_ETOOMANYREFS);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_ETIMEDOUT);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_ECONNREFUSED);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_ELOOP);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_ENAMETOOLONG);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_EHOSTDOWN);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_EHOSTUNREACH);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_ENOTEMPTY);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_EPROCLIM);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_EUSERS);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_EDQUOT);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_ESTALE);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_EREMOTE);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_EBADRPC);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_ERPCMISMATCH);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_EPROGUNAVAIL);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_EPROGMISMATCH);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_EPROCUNAVAIL);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_ENOLCK);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_ENOSYS);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_EFTYPE);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_EAUTH);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_ENEEDAUTH);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_EIDRM);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_ENOMSG);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_EOVERFLOW);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_EILSEQ);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_ENOTSUP);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_ECANCELED);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_EBADMSG);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_ENODATA);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_ENOSR);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_ENOSTR);
STR_CASE(CELL_HTTP_ERROR_NET_SSL_RECV_ETIME);
}
return unknown;
});
}
error_code cellHttpAuthCacheExport(vm::ptr<u32> buf, u32 len, vm::ptr<u32> outsize)
{
cellHttp.todo("cellHttpAuthCacheExport(buf=*0x%x, len=%d, outsize=*0x%x)", buf, len, outsize);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (!buf)
{
if (!outsize)
{
return CELL_HTTP_ERROR_NO_BUFFER;
}
}
else
{
if (len < 9)
{
return CELL_HTTP_ERROR_INSUFFICIENT;
}
// TODO
}
[[maybe_unused]] u32 size = 0;
// TODO
if (outsize)
{
*outsize = 0;
}
return CELL_OK;
}
error_code cellHttpAuthCacheFlush()
{
cellHttp.todo("cellHttpAuthCacheFlush()");
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
return CELL_OK;
}
error_code cellHttpAuthCacheGetEntryMax(u32 unk_ptr)
{
cellHttp.todo("cellHttpAuthCacheGetEntryMax(unk_ptr=*0x%x)", unk_ptr);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (!unk_ptr)
{
return CELL_HTTP_ERROR_NO_BUFFER;
}
return CELL_OK;
}
error_code cellHttpAuthCacheImport(vm::ptr<char> unk1, u32 unk2)
{
cellHttp.todo("cellHttpAuthCacheImport(unk1=*0x%x, unk2=0x%x)", unk1, unk2);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (!unk1 || !unk2)
{
return CELL_HTTP_ERROR_NO_BUFFER;
}
if (unk2 < 9)
{
return CELL_HTTP_ERROR_INSUFFICIENT;
}
if (unk1[0] != '\x01')
{
return CELL_HTTP_ERROR_INVALID_DATA;
}
return CELL_OK;
}
error_code cellHttpAuthCacheSetEntryMax(u32 unk)
{
cellHttp.todo("cellHttpAuthCacheSetEntryMax(unk=0x%x)", unk);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
return CELL_OK;
}
error_code cellHttpInit(vm::ptr<void> pool, u32 poolSize)
{
cellHttp.notice("cellHttpInit(pool=*0x%x, poolSize=0x%x)", pool, poolSize);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (man.initialized)
{
return CELL_HTTP_ERROR_ALREADY_INITIALIZED;
}
if (!pool || !poolSize)
{
return CELL_HTTP_ERROR_NO_BUFFER;
}
man.initialized = true;
return CELL_OK;
}
error_code cellHttpEnd()
{
cellHttp.notice("cellHttpEnd()");
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
man.initialized = false;
return CELL_OK;
}
error_code cellHttpsInit(u32 caCertNum, vm::cptr<CellHttpsData> caList)
{
cellHttp.todo("cellHttpsInit(caCertNum=0x%x, caList=*0x%x)", caCertNum, caList);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (man.https_initialized)
{
return CELL_HTTP_ERROR_ALREADY_INITIALIZED;
}
man.https_initialized = true;
return CELL_OK;
}
error_code cellHttpsEnd()
{
cellHttp.todo("cellHttpsEnd()");
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.https_initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (!_cellSslIsInitd())
{
return CELL_SSL_ERROR_NOT_INITIALIZED;
}
man.https_initialized = false;
return CELL_OK;
}
error_code cellHttpSetProxy(vm::cptr<CellHttpUri> proxy)
{
cellHttp.todo("cellHttpSetProxy(proxy=*0x%x)", proxy);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (proxy)
{
if (!proxy->hostname || !proxy->hostname[0])
{
return CELL_HTTP_ERROR_INVALID_URI;
}
}
return CELL_OK;
}
error_code cellHttpGetCookie(vm::ptr<void> buf)
{
cellHttp.todo("cellHttpGetCookie(buf=*0x%x)", buf);
if (!buf)
{
return CELL_HTTP_ERROR_NO_BUFFER;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_COOKIE_NOT_FOUND;
}
return CELL_OK;
}
error_code cellHttpGetProxy(vm::ptr<CellHttpUri> proxy, vm::ptr<void> pool, u32 poolSize, vm::ptr<u32> required)
{
cellHttp.todo("cellHttpGetProxy(proxy=*0x%x, pool=*0x%x, poolSize=0x%x, required=*0x%x)", proxy, pool, poolSize, required);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
//if (todo)
//{
// return cellHttpUtilCopyUri(proxy, some CellHttpUri, pool, poolSize, required);
//}
if (required)
{
*required = 0;
}
return CELL_OK;
}
error_code cellHttpInitCookie(vm::ptr<void> pool, u32 poolSize)
{
cellHttp.todo("cellHttpInitCookie(pool=*0x%x, poolSize=0x%x)", pool, poolSize);
if (!pool || !poolSize)
{
return CELL_HTTP_ERROR_NO_BUFFER;
}
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (man.cookie_initialized)
{
return CELL_HTTP_ERROR_ALREADY_INITIALIZED;
}
man.cookie_initialized = true;
return CELL_OK;
}
error_code cellHttpEndCookie()
{
cellHttp.todo("cellHttpEndCookie()");
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.cookie_initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
man.cookie_initialized = false;
return CELL_OK;
}
error_code cellHttpAddCookieWithClientId(vm::cptr<CellHttpUri> uri, vm::cptr<char> cookie, CellHttpClientId clientId)
{
cellHttp.todo("cellHttpAddCookieWithClientId(uri=*0x%x, cookie=%s, clientId=0x%x)", uri, cookie, clientId);
if (!uri)
{
return CELL_HTTP_ERROR_NO_BUFFER;
}
if (!cookie || !uri->hostname || !uri->path)
{
return CELL_HTTP_ERROR_NO_STRING;
}
return CELL_OK;
}
error_code cellHttpSessionCookieFlush(CellHttpClientId clientId)
{
cellHttp.todo("cellHttpSessionCookieFlush(clientId=0x%x)", clientId);
return CELL_OK;
}
error_code cellHttpCookieExport(vm::ptr<void> buffer, u32 size, vm::ptr<u32> exportSize)
{
cellHttp.todo("cellHttpCookieExport(buffer=*0x%x, size=0x%x, exportSize=*0x%x)", buffer, size, exportSize);
if (buffer && size < 0x14)
{
return CELL_HTTP_ERROR_INSUFFICIENT;
}
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.cookie_initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
return CELL_OK;
}
error_code cellHttpCookieExportWithClientId(vm::ptr<void> buffer, u32 size, vm::ptr<u32> exportSize, CellHttpClientId clientId)
{
cellHttp.todo("cellHttpCookieExportWithClientId(buffer=*0x%x, size=0x%x, exportSize=*0x%x, clientId=0x%x)", buffer, size, exportSize, clientId);
if (buffer && size < 0x14)
{
return CELL_HTTP_ERROR_INSUFFICIENT;
}
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.cookie_initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
return CELL_OK;
}
error_code cellHttpCookieFlush()
{
cellHttp.todo("cellHttpCookieFlush()");
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.cookie_initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
return CELL_OK;
}
error_code cellHttpCookieImport(vm::cptr<void> buffer, u32 size)
{
cellHttp.todo("cellHttpCookieImport(buffer=*0x%x, size=0x%x)", buffer, size);
if (error_code error = cellHttpCookieFlush())
{
cellHttp.error("cellHttpCookieImport: cellHttpCookieFlush returned 0x%x", +error);
// No return
}
return CELL_OK;
}
error_code cellHttpCookieImportWithClientId(vm::cptr<void> buffer, u32 size, CellHttpClientId clientId)
{
cellHttp.todo("cellHttpCookieImportWithClientId(buffer=*0x%x, size=0x%x, clientId=0x%x)", buffer, size, clientId);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.cookie_initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
return CELL_OK;
}
error_code cellHttpClientSetCookieSendCallback(CellHttpClientId clientId, vm::ptr<CellHttpCookieSendCallback> cbfunc, vm::ptr<void> userArg)
{
cellHttp.todo("cellHttpClientSetCookieSendCallback(clientId=0x%x, cbfunc=*0x%x, userArg=*0x%x)", clientId, cbfunc, userArg);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
return CELL_OK;
}
error_code cellHttpClientSetCookieRecvCallback(CellHttpClientId clientId, vm::ptr<CellHttpsSslCallback> cbfunc, vm::ptr<void> userArg)
{
cellHttp.todo("cellHttpClientSetCookieRecvCallback(clientId=0x%x, cbfunc=*0x%x, userArg=*0x%x)", clientId, cbfunc, userArg);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
return CELL_OK;
}
error_code cellHttpCreateClient(vm::ptr<CellHttpClientId> clientId)
{
cellHttp.todo("cellHttpCreateClient(clientId=*0x%x)", clientId);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (!clientId)
{
return CELL_HTTP_ERROR_NO_BUFFER;
}
return CELL_OK;
}
error_code cellHttpDestroyClient(CellHttpClientId clientId)
{
cellHttp.todo("cellHttpDestroyClient(clientId=0x%x)", clientId);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
return CELL_OK;
}
error_code cellHttpClientSetAuthenticationCallback(CellHttpClientId clientId, vm::ptr<CellHttpAuthenticationCallback> cbfunc, vm::ptr<void> userArg)
{
cellHttp.todo("cellHttpClientSetAuthenticationCallback(clientId=0x%x, cbfunc=*0x%x, userArg=*0x%x)", clientId, cbfunc, userArg);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
return CELL_OK;
}
error_code cellHttpClientSetCacheStatus(CellHttpClientId clientId, b8 enable)
{
cellHttp.todo("cellHttpClientSetCacheStatus(clientId=0x%x, enable=%d)", clientId, enable);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
return CELL_OK;
}
error_code cellHttpClientSetTransactionStateCallback(CellHttpClientId clientId, vm::ptr<CellHttpTransactionStateCallback> cbfunc, vm::ptr<void> userArg)
{
cellHttp.todo("cellHttpClientSetTransactionStateCallback(clientId=0x%x, cbfunc=*0x%x, userArg=*0x%x)", clientId, cbfunc, userArg);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
return CELL_OK;
}
error_code cellHttpClientSetRedirectCallback(CellHttpClientId clientId, vm::ptr<CellHttpRedirectCallback> cbfunc, vm::ptr<void> userArg)
{
cellHttp.todo("cellHttpClientSetRedirectCallback(clientId=0x%x, cbfunc=*0x%x, userArg=*0x%x)", clientId, cbfunc, userArg);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
return CELL_OK;
}
error_code cellHttpClientSetProxy(CellHttpClientId clientId, vm::cptr<CellHttpUri> proxy)
{
cellHttp.todo("cellHttpClientSetProxy(clientId=0x%x, proxy=*0x%x)", clientId, proxy);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
if (proxy)
{
if (!proxy->hostname || !proxy->hostname[0])
{
return CELL_HTTP_ERROR_INVALID_URI;
}
}
return CELL_OK;
}
error_code cellHttpClientGetProxy(CellHttpClientId clientId, vm::ptr<CellHttpUri> proxy, vm::ptr<void> pool, u32 poolSize, vm::ptr<u32> required)
{
cellHttp.todo("cellHttpClientGetProxy(clientId=0x%x, proxy=*0x%x, pool=*0x%x, poolSize=0x%x, required=*0x%x)", clientId, proxy, pool, poolSize, required);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
return CELL_OK;
}
error_code cellHttpClientSetVersion(CellHttpClientId clientId, u32 major, u32 minor)
{
cellHttp.todo("cellHttpClientSetPipeline(clientId=0x%x, major=0x%x, minor=0x%x)", clientId, major, minor);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
return CELL_OK;
}
error_code cellHttpClientGetVersion(CellHttpClientId clientId, vm::ptr<u32> major, vm::ptr<u32> minor)
{
cellHttp.todo("cellHttpClientGetVersion(clientId=0x%x, major=*0x%x, minor=*0x%x)", clientId, major, minor);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
if (!major || !minor)
{
return CELL_HTTP_ERROR_NO_BUFFER;
}
return CELL_OK;
}
error_code cellHttpClientSetPipeline(CellHttpClientId clientId, b8 enable)
{
cellHttp.todo("cellHttpClientSetPipeline(clientId=0x%x, enable=%d)", clientId, enable);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
return CELL_OK;
}
error_code cellHttpClientGetPipeline(CellHttpClientId clientId, vm::ptr<b8> enable)
{
cellHttp.todo("cellHttpClientGetPipeline(clientId=0x%x, enable=*0x%x)", clientId, enable);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
if (!enable)
{
return CELL_HTTP_ERROR_NO_BUFFER;
}
return CELL_OK;
}
error_code cellHttpClientSetKeepAlive(CellHttpClientId clientId, b8 enable)
{
cellHttp.todo("cellHttpClientSetKeepAlive(clientId=0x%x, enable=%d)", clientId, enable);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
return CELL_OK;
}
error_code cellHttpClientGetKeepAlive(CellHttpClientId clientId, vm::ptr<b8> enable)
{
cellHttp.todo("cellHttpClientGetKeepAlive(clientId=0x%x, enable=*0x%x)", clientId, enable);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
if (!enable)
{
return CELL_HTTP_ERROR_NO_BUFFER;
}
return CELL_OK;
}
error_code cellHttpClientSetAutoRedirect(CellHttpClientId clientId, b8 enable)
{
cellHttp.todo("cellHttpClientSetAutoRedirect(clientId=0x%x, enable=%d)", clientId, enable);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
return CELL_OK;
}
error_code cellHttpClientGetAutoRedirect(CellHttpClientId clientId, vm::ptr<b8> enable)
{
cellHttp.todo("cellHttpClientGetAutoRedirect(clientId=0x%x, enable=*0x%x)", clientId, enable);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
if (!enable)
{
return CELL_HTTP_ERROR_NO_BUFFER;
}
return CELL_OK;
}
error_code cellHttpClientSetAutoAuthentication(CellHttpClientId clientId, b8 enable)
{
cellHttp.todo("cellHttpClientSetAutoAuthentication(clientId=0x%x, enable=%d)", clientId, enable);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
return CELL_OK;
}
error_code cellHttpClientGetAutoAuthentication(CellHttpClientId clientId, vm::ptr<b8> enable)
{
cellHttp.todo("cellHttpClientGetAutoAuthentication(clientId=0x%x, enable=*0x%x)", clientId, enable);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
if (!enable)
{
return CELL_HTTP_ERROR_NO_BUFFER;
}
return CELL_OK;
}
error_code cellHttpClientSetAuthenticationCacheStatus(CellHttpClientId clientId, b8 enable)
{
cellHttp.todo("cellHttpClientSetAuthenticationCacheStatus(clientId=0x%x, enable=%d)", clientId, enable);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
return CELL_OK;
}
error_code cellHttpClientGetAuthenticationCacheStatus(CellHttpClientId clientId, vm::ptr<b8> enable)
{
cellHttp.todo("cellHttpClientGetAuthenticationCacheStatus(clientId=0x%x, enable=*0x%x)", clientId, enable);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
if (!enable)
{
return CELL_HTTP_ERROR_NO_BUFFER;
}
return CELL_OK;
}
error_code cellHttpClientSetCookieStatus(CellHttpClientId clientId, b8 enable)
{
cellHttp.todo("cellHttpClientSetCookieStatus(clientId=0x%x, enable=%d)", clientId, enable);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
return CELL_OK;
}
error_code cellHttpClientGetCookieStatus(CellHttpClientId clientId, vm::ptr<b8> enable)
{
cellHttp.todo("cellHttpClientGetCookieStatus(clientId=0x%x, enable=*0x%x)", clientId, enable);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
if (!enable)
{
return CELL_HTTP_ERROR_NO_BUFFER;
}
return CELL_OK;
}
error_code cellHttpClientSetUserAgent(CellHttpClientId clientId, vm::cptr<char> userAgent)
{
cellHttp.todo("cellHttpClientSetUserAgent(clientId=0x%x, userAgent=%s)", clientId, userAgent);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
if (!userAgent)
{
return CELL_HTTP_ERROR_NO_BUFFER;
}
return CELL_OK;
}
error_code cellHttpClientGetUserAgent(CellHttpClientId clientId, vm::ptr<char> userAgent, u32 size, vm::ptr<u32> required)
{
cellHttp.todo("cellHttpClientGetUserAgent(clientId=0x%x, userAgent=*0x%x, size=%d, required=*0x%x)", clientId, size, userAgent, required);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
if (!userAgent || !size)
{
if (!required)
{
return CELL_HTTP_ERROR_NO_BUFFER;
}
}
return CELL_OK;
}
error_code cellHttpClientSetResponseBufferMax(CellHttpClientId clientId, u32 max)
{
cellHttp.todo("cellHttpClientSetResponseBufferMax(clientId=0x%x, max=%d)", clientId, max);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
if (max < 1500)
{
max = 1500;
}
return CELL_OK;
}
error_code cellHttpClientGetResponseBufferMax(CellHttpClientId clientId, vm::ptr<u32> max)
{
cellHttp.todo("cellHttpClientGetResponseBufferMax(clientId=0x%x, max=*0x%x)", clientId, max);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
if (!max)
{
return CELL_HTTP_ERROR_NO_BUFFER;
}
return CELL_OK;
}
error_code cellHttpClientCloseAllConnections(CellHttpClientId clientId)
{
cellHttp.todo("cellHttpClientCloseAllConnections(clientId=0x%x)", clientId);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
return CELL_OK;
}
error_code cellHttpClientCloseConnections(CellHttpClientId clientId, vm::cptr<CellHttpUri> uri)
{
cellHttp.todo("cellHttpClientCloseConnections(clientId=0x%x, uri=*0x%x)", clientId, uri);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
return CELL_OK;
}
error_code cellHttpClientPollConnections(CellHttpClientId clientId, vm::ptr<CellHttpTransId> transId, s64 usec)
{
cellHttp.todo("cellHttpClientPollConnections(clientId=0x%x, transId=*0x%x, usec=%d)", clientId, transId, usec);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
return CELL_OK;
}
error_code cellHttpClientSetConnectionStateCallback(CellHttpClientId clientId, vm::ptr<void> cbfunc, vm::ptr<void> userArg)
{
cellHttp.todo("cellHttpClientSetConnectionStateCallback(clientId=0x%x, cbfunc=*0x%x, userArg=*0x%x)", clientId, cbfunc, userArg);
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
return CELL_OK;
}
error_code cellHttpClientSetConnectionWaitStatus(CellHttpClientId clientId, b8 enable)
{
cellHttp.todo("cellHttpClientSetConnectionWaitStatus(clientId=0x%x, enable=%d)", clientId, enable);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
return CELL_OK;
}
error_code cellHttpClientGetConnectionWaitStatus(CellHttpClientId clientId, vm::ptr<b8> enable)
{
cellHttp.todo("cellHttpClientGetConnectionWaitStatus(clientId=0x%x, enable=*0x%x)", clientId, enable);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
if (!enable)
{
return CELL_HTTP_ERROR_NO_BUFFER;
}
return CELL_OK;
}
error_code cellHttpClientSetConnectionWaitTimeout(CellHttpClientId clientId, s64 usec)
{
cellHttp.todo("cellHttpClientSetConnectionWaitTimeout(clientId=0x%x, usec=%d)", clientId, usec);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
return CELL_OK;
}
error_code cellHttpClientGetConnectionWaitTimeout(CellHttpClientId clientId, vm::ptr<s64> usec)
{
cellHttp.todo("cellHttpClientGetConnectionWaitTimeout(clientId=0x%x, usec=*0x%x)", clientId, usec);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
if (!usec)
{
return CELL_HTTP_ERROR_NO_BUFFER;
}
return CELL_OK;
}
error_code cellHttpClientSetRecvTimeout(CellHttpClientId clientId, s64 usec)
{
cellHttp.todo("cellHttpClientSetRecvTimeout(clientId=0x%x, usec=%d)", clientId, usec);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
return CELL_OK;
}
error_code cellHttpClientGetRecvTimeout(CellHttpClientId clientId, vm::ptr<s64> usec)
{
cellHttp.todo("cellHttpClientGetRecvTimeout(clientId=0x%x, usec=*0x%x)", clientId, usec);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
if (!usec) // TODO
{
return CELL_HTTP_ERROR_NO_BUFFER;
}
return CELL_OK;
}
error_code cellHttpClientSetSendTimeout(CellHttpClientId clientId, s64 usec)
{
cellHttp.todo("cellHttpClientSetSendTimeout(clientId=0x%x, usec=%d)", clientId, usec);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
return CELL_OK;
}
error_code cellHttpClientGetSendTimeout(CellHttpClientId clientId, vm::ptr<s64> usec)
{
cellHttp.todo("cellHttpClientGetSendTimeout(clientId=0x%x, usec=*0x%x)", clientId, usec);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
if (!usec) // TODO
{
return CELL_HTTP_ERROR_NO_BUFFER;
}
return CELL_OK;
}
error_code cellHttpClientSetConnTimeout(CellHttpClientId clientId, s64 usec)
{
cellHttp.todo("cellHttpClientSetConnTimeout(clientId=0x%x, usec=%d)", clientId, usec);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
return CELL_OK;
}
error_code cellHttpClientGetConnTimeout(CellHttpClientId clientId, vm::ptr<s64> usec)
{
cellHttp.todo("cellHttpClientGetConnTimeout(clientId=0x%x, usec=*0x%x)", clientId, usec);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
if (!usec)
{
return CELL_HTTP_ERROR_NO_BUFFER;
}
return CELL_OK;
}
error_code cellHttpClientSetTotalPoolSize(CellHttpClientId clientId, u32 poolSize)
{
cellHttp.todo("cellHttpClientSetTotalPoolSize(clientId=0x%x, poolSize=%d)", clientId, poolSize);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
return CELL_OK;
}
error_code cellHttpClientGetTotalPoolSize(CellHttpClientId clientId, vm::ptr<u32> poolSize)
{
cellHttp.todo("cellHttpClientGetTotalPoolSize(clientId=0x%x, poolSize=*0x%x)", clientId, poolSize);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
if (!poolSize)
{
return CELL_HTTP_ERROR_NO_BUFFER;
}
return CELL_OK;
}
error_code cellHttpClientSetPerHostPoolSize(CellHttpClientId clientId, u32 poolSize)
{
cellHttp.todo("cellHttpClientSetPerHostPoolSize(clientId=0x%x, poolSize=%d)", clientId, poolSize);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
return CELL_OK;
}
error_code cellHttpClientGetPerHostPoolSize(CellHttpClientId clientId, vm::ptr<u32> poolSize)
{
cellHttp.todo("cellHttpClientGetPerHostPoolSize(clientId=0x%x, poolSize=*0x%x)", clientId, poolSize);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
if (!poolSize)
{
return CELL_HTTP_ERROR_NO_BUFFER;
}
return CELL_OK;
}
error_code cellHttpClientSetPerHostKeepAliveMax(CellHttpClientId clientId, u32 maxSize)
{
cellHttp.todo("cellHttpClientSetPerHostKeepAliveMax(clientId=0x%x, maxSize=%d)", clientId, maxSize);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
return CELL_OK;
}
error_code cellHttpClientGetPerHostKeepAliveMax(CellHttpClientId clientId, vm::ptr<u32> maxSize)
{
cellHttp.todo("cellHttpClientGetPerHostKeepAliveMax(clientId=0x%x, maxSize=*0x%x)", clientId, maxSize);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
if (!maxSize)
{
return CELL_HTTP_ERROR_NO_BUFFER;
}
return CELL_OK;
}
error_code cellHttpClientSetPerPipelineMax(CellHttpClientId clientId, u32 pipeMax)
{
cellHttp.todo("cellHttpClientSetPerPipelineMax(clientId=0x%x, pipeMax=%d)", clientId, pipeMax);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
return CELL_OK;
}
error_code cellHttpClientGetPerPipelineMax(CellHttpClientId clientId, vm::ptr<u32> pipeMax)
{
cellHttp.todo("cellHttpClientGetPerPipelineMax(clientId=0x%x, pipeMax=*0x%x)", clientId, pipeMax);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
if (!pipeMax)
{
return CELL_HTTP_ERROR_NO_BUFFER;
}
return CELL_OK;
}
error_code cellHttpClientSetRecvBufferSize(CellHttpClientId clientId, s32 size)
{
cellHttp.todo("cellHttpClientSetRecvBufferSize(clientId=0x%x, size=%d)", clientId, size);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
return CELL_OK;
}
error_code cellHttpClientGetRecvBufferSize(CellHttpClientId clientId, vm::ptr<s32> size)
{
cellHttp.todo("cellHttpClientGetRecvBufferSize(clientId=0x%x, size=*0x%x)", clientId, size);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
if (!size)
{
return CELL_HTTP_ERROR_NO_BUFFER;
}
return CELL_OK;
}
error_code cellHttpClientSetSendBufferSize(CellHttpClientId clientId, s32 size)
{
cellHttp.todo("cellHttpClientSetSendBufferSize(clientId=0x%x, size=%d)", clientId, size);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
return CELL_OK;
}
error_code cellHttpClientGetSendBufferSize(CellHttpClientId clientId, vm::ptr<s32> size)
{
cellHttp.todo("cellHttpClientGetSendBufferSize(clientId=0x%x, size=*0x%x)", clientId, size);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
if (!size)
{
return CELL_HTTP_ERROR_NO_BUFFER;
}
return CELL_OK;
}
error_code cellHttpClientGetAllHeaders(CellHttpClientId clientId, vm::pptr<CellHttpHeader> headers, vm::ptr<u32> items, vm::ptr<void> pool, u32 poolSize, vm::ptr<u32> required)
{
cellHttp.todo("cellHttpClientGetAllHeaders(clientId=0x%x, headers=*0x%x, items=*0x%x, pool=*0x%x, poolSize=0x%x, required=*0x%x)", clientId, headers, items, pool, poolSize, required);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
if ((!pool || !headers) && !required)
{
return CELL_HTTP_ERROR_NO_BUFFER;
}
return CELL_OK;
}
error_code cellHttpClientSetHeader(CellHttpClientId clientId, vm::cptr<CellHttpHeader> header)
{
cellHttp.todo("cellHttpClientSetHeader(clientId=0x%x, header=*0x%x)", clientId, header);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
if (!header)
{
return CELL_HTTP_ERROR_NO_BUFFER;
}
return CELL_OK;
}
error_code cellHttpClientGetHeader(CellHttpClientId clientId, vm::ptr<CellHttpHeader> header, vm::cptr<char> name, vm::ptr<void> pool, u32 poolSize, vm::ptr<u32> required)
{
cellHttp.todo("cellHttpClientGetHeader(clientId=0x%x, header=*0x%x, name=%s, pool=*0x%x, poolSize=0x%x, required=*0x%x)", clientId, header, name, pool, poolSize, required);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
if (!name)
{
return CELL_HTTP_ERROR_NO_STRING;
}
return CELL_OK;
}
error_code cellHttpClientAddHeader(CellHttpClientId clientId, vm::cptr<CellHttpHeader> header)
{
cellHttp.todo("cellHttpClientAddHeader(clientId=0x%x, header=*0x%x)", clientId, header);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
return CELL_OK;
}
error_code cellHttpClientDeleteHeader(CellHttpClientId clientId, vm::cptr<char> name)
{
cellHttp.todo("cellHttpClientDeleteHeader(clientId=0x%x, name=%s)", clientId, name);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
return CELL_OK;
}
error_code cellHttpClientSetSslCallback(CellHttpClientId clientId, vm::ptr<CellHttpsSslCallback> cbfunc, vm::ptr<void> userArg)
{
cellHttp.todo("cellHttpClientSetSslCallback(clientId=0x%x, cbfunc=*0x%x, userArg=*0x%x)", clientId, cbfunc, userArg);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
return CELL_OK;
}
error_code cellHttpClientSetSslClientCertificate(CellHttpClientId clientId, vm::cptr<CellHttpsData> cert, vm::cptr<CellHttpsData> privKey)
{
cellHttp.todo("cellHttpClientSetSslClientCertificate(clientId=0x%x, cert=*0x%x, privKey=*0x%x)", clientId, cert, privKey);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
if (!cert && privKey)
{
return CELL_HTTPS_ERROR_KEY_NEEDS_CERT;
}
if (cert && !privKey)
{
return CELL_HTTPS_ERROR_CERT_NEEDS_KEY;
}
return CELL_OK;
}
error_code cellHttpCreateTransaction(vm::ptr<CellHttpTransId> transId, CellHttpClientId clientId, vm::cptr<char> method, vm::cptr<CellHttpUri> uri)
{
cellHttp.todo("cellHttpCreateTransaction(transId=*0x%x, clientId=0x%x, method=%s, uri=*0x%x)", transId, clientId, method, uri);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
//if (error_code error = syscall_sys_memory_get_page_attribute(clientId))
//{
// return error;
//}
if (!uri || !uri->hostname || !uri->hostname[0])
{
return CELL_HTTP_ERROR_INVALID_URI;
}
return CELL_OK;
}
error_code cellHttpDestroyTransaction(CellHttpTransId transId)
{
cellHttp.todo("cellHttpDestroyTransaction(transId=0x%x)", transId);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_TRANS;
}
return CELL_OK;
}
error_code cellHttpTransactionGetUri(CellHttpTransId transId, vm::ptr<CellHttpUri> uri, vm::ptr<void> pool, u32 poolSize, vm::ptr<u32> required)
{
cellHttp.todo("cellHttpTransactionGetUri(transId=0x%x, uri=*0x%x, pool=*0x%x, poolSize=0x%x, required=*0x%x)", transId, uri, pool, poolSize, required);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_TRANS;
}
return CELL_OK;
}
error_code cellHttpTransactionSetUri(CellHttpTransId transId, vm::cptr<CellHttpUri> uri) // TODO: more params?
{
cellHttp.todo("cellHttpTransactionSetUri(transId=0x%x, uri=*0x%x)", transId, uri);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_TRANS;
}
if (!uri || !uri->hostname || !uri->hostname[0])
{
return CELL_HTTP_ERROR_INVALID_URI;
}
if (uri->scheme && false) // TODO
{
return CELL_HTTP_ERROR_INVALID_URI;
}
return CELL_OK;
}
error_code cellHttpTransactionCloseConnection(CellHttpTransId transId)
{
cellHttp.todo("cellHttpTransactionCloseConnection(transId=0x%x)", transId);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_TRANS;
}
return CELL_OK;
}
error_code cellHttpTransactionReleaseConnection(CellHttpTransId transId, vm::ptr<s32> sid)
{
cellHttp.todo("cellHttpTransactionReleaseConnection(transId=0x%x, sid=*0x%x)", transId, sid);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_TRANS;
}
if (!sid)
{
return CELL_HTTP_ERROR_NO_BUFFER;
}
return CELL_OK;
}
error_code cellHttpTransactionAbortConnection(CellHttpTransId transId)
{
cellHttp.todo("cellHttpTransactionAbortConnection(transId=0x%x)", transId);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_TRANS;
}
return CELL_OK;
}
error_code cellHttpSendRequest(CellHttpTransId transId, vm::cptr<char> buf, u32 size, vm::ptr<u32> sent)
{
cellHttp.todo("cellHttpSendRequest(transId=0x%x, buf=*0x%x, size=0x%x, sent=*0x%x)", transId, buf, size, sent);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_TRANS;
}
return CELL_OK;
}
error_code cellHttpRequestSetContentLength(CellHttpTransId transId, u64 totalSize)
{
cellHttp.todo("cellHttpRequestSetContentLength(transId=0x%x, totalSize=0x%x)", transId, totalSize);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_TRANS;
}
return CELL_OK;
}
error_code cellHttpRequestGetContentLength(CellHttpTransId transId, vm::ptr<u64> totalSize)
{
cellHttp.todo("cellHttpRequestGetContentLength(transId=0x%x, totalSize=*0x%x)", transId, totalSize);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_TRANS;
}
if (!totalSize)
{
return CELL_HTTP_ERROR_NO_BUFFER;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_NO_CONTENT_LENGTH;
}
return CELL_OK;
}
error_code cellHttpRequestSetChunkedTransferStatus(CellHttpTransId transId, b8 enable)
{
cellHttp.todo("cellHttpRequestSetChunkedTransferStatus(transId=0x%x, enable=%d)", transId, enable);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_TRANS;
}
return CELL_OK;
}
error_code cellHttpRequestGetChunkedTransferStatus(CellHttpTransId transId, vm::ptr<b8> enable)
{
cellHttp.todo("cellHttpRequestGetChunkedTransferStatus(transId=0x%x, enable=*0x%x)", transId, enable);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_TRANS;
}
if (!enable)
{
return CELL_HTTP_ERROR_NO_BUFFER;
}
return CELL_OK;
}
error_code cellHttpRequestGetAllHeaders(CellHttpTransId transId, vm::pptr<CellHttpHeader> headers, vm::ptr<u32> items, vm::ptr<void> pool, u32 poolSize, vm::ptr<u32> required)
{
cellHttp.todo("cellHttpRequestGetAllHeaders(transId=0x%x, headers=*0x%x, items=*0x%x, pool=*0x%x, poolSize=0x%x, required=*0x%x)", transId, headers, items, pool, poolSize, required);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_TRANS;
}
if (!required && (!pool || !headers))
{
return CELL_HTTP_ERROR_NO_BUFFER;
}
return CELL_OK;
}
error_code cellHttpRequestSetHeader(CellHttpTransId transId, vm::cptr<CellHttpHeader> header)
{
cellHttp.todo("cellHttpRequestSetHeader(transId=0x%x, header=*0x%x)", transId, header);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_TRANS;
}
if (!header)
{
return CELL_HTTP_ERROR_NO_BUFFER;
}
return CELL_OK;
}
error_code cellHttpRequestGetHeader(CellHttpTransId transId, vm::ptr<CellHttpHeader> header, vm::cptr<char> name, vm::ptr<void> pool, u32 poolSize, vm::ptr<u32> required)
{
cellHttp.todo("cellHttpRequestGetHeader(transId=0x%x, header=*0x%x, name=%s, pool=*0x%x, poolSize=0x%x, required=*0x%x)", transId, header, name, pool, poolSize, required);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_TRANS;
}
if (!name)
{
return CELL_HTTP_ERROR_NO_STRING;
}
return CELL_OK;
}
error_code cellHttpRequestAddHeader(CellHttpTransId transId, vm::cptr<CellHttpHeader> header)
{
cellHttp.todo("cellHttpRequestAddHeader(transId=0x%x, header=*0x%x)", transId, header);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_TRANS;
}
if (!header)
{
return CELL_HTTP_ERROR_NO_BUFFER;
}
return CELL_OK;
}
error_code cellHttpRequestDeleteHeader(CellHttpTransId transId, vm::cptr<char> name)
{
cellHttp.todo("cellHttpRequestDeleteHeader(transId=0x%x, name=%s)", transId, name);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_TRANS;
}
if (!name)
{
return CELL_HTTP_ERROR_NO_STRING;
}
return CELL_OK;
}
error_code cellHttpRecvResponse(CellHttpTransId transId, vm::ptr<char> buf, u32 size, vm::ptr<u32> recvd)
{
cellHttp.todo("cellHttpRecvResponse(transId=0x%x, buf=*0x%x, size=0x%x, recvd=*0x%x)", transId, buf, size, recvd);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_TRANS;
}
return CELL_OK;
}
error_code cellHttpResponseGetAllHeaders(CellHttpTransId transId, vm::pptr<CellHttpHeader> headers, vm::ptr<u32> items, vm::ptr<void> pool, u32 poolSize, vm::ptr<u32> required)
{
cellHttp.todo("cellHttpResponseGetAllHeaders(transId=0x%x, headers=*0x%x, items=*0x%x, pool=*0x%x, poolSize=0x%x, required=*0x%x)", transId, headers, items, pool, poolSize, required);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_TRANS;
}
if (!required && (!pool || !headers))
{
return CELL_HTTP_ERROR_NO_BUFFER;
}
return CELL_OK;
}
error_code cellHttpResponseGetHeader(CellHttpTransId transId, vm::ptr<CellHttpHeader> header, vm::cptr<char> name, vm::ptr<void> pool, u32 poolSize, vm::ptr<u32> required)
{
cellHttp.todo("cellHttpResponseGetHeader(transId=0x%x, header=*0x%x, name=%s, pool=*0x%x, poolSize=0x%x, required=*0x%x)", transId, header, name, pool, poolSize, required);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_TRANS;
}
if (!name)
{
return CELL_HTTP_ERROR_NO_STRING;
}
return CELL_OK;
}
error_code cellHttpResponseGetContentLength(CellHttpTransId transId, vm::ptr<u64> length)
{
cellHttp.todo("cellHttpResponseGetContentLength(transId=0x%x, length=*0x%x)", transId, length);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_TRANS;
}
if (!length)
{
return CELL_HTTP_ERROR_NO_BUFFER;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_NO_CONTENT_LENGTH;
}
return CELL_OK;
}
error_code cellHttpResponseGetStatusCode(CellHttpTransId transId, vm::ptr<s32> code)
{
cellHttp.todo("cellHttpResponseGetStatusCode(transId=0x%x, code=*0x%x)", transId, code);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_TRANS;
}
if (!code)
{
return CELL_HTTP_ERROR_NO_BUFFER;
}
return CELL_OK;
}
error_code cellHttpResponseGetStatusLine(CellHttpTransId transId, vm::ptr<CellHttpStatusLine> status, vm::ptr<void> pool, u32 poolSize, vm::ptr<u32> required)
{
cellHttp.todo("cellHttpResponseGetStatusLine(transId=0x%x, status=*0x%x, pool=*0x%x, poolSize=0x%x, required=*0x%x)", transId, status, pool, poolSize, required);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_TRANS;
}
return CELL_OK;
}
error_code cellHttpTransactionGetSslCipherName(CellHttpTransId transId, vm::ptr<char> name, u32 size, vm::ptr<u32> required)
{
cellHttp.todo("cellHttpTransactionGetSslCipherName(transId=0x%x, name=*0x%x, size=0x%x, required=*0x%x)", transId, name, size, required);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_TRANS;
}
return CELL_OK;
}
error_code cellHttpTransactionGetSslCipherId(CellHttpTransId transId, vm::ptr<s32> id)
{
cellHttp.todo("cellHttpTransactionGetSslCipherId(transId=0x%x, id=*0x%x)", transId, id);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_TRANS;
}
return CELL_OK;
}
error_code cellHttpTransactionGetSslCipherVersion(CellHttpTransId transId, vm::ptr<char> version, u32 size, vm::ptr<u32> required)
{
cellHttp.todo("cellHttpTransactionGetSslCipherVersion(transId=0x%x, version=*0x%x, size=0x%x, required=*0x%x)", transId, version, size, required);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_TRANS;
}
return CELL_OK;
}
error_code cellHttpTransactionGetSslCipherBits(CellHttpTransId transId, vm::ptr<s32> effectiveBits, vm::ptr<s32> algorithmBits)
{
cellHttp.todo("cellHttpTransactionGetSslCipherBits(transId=0x%x, effectiveBits=*0x%x, effectiveBits=*0x%x)", transId, effectiveBits, algorithmBits);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_TRANS;
}
return CELL_OK;
}
error_code cellHttpTransactionGetSslCipherString(CellHttpTransId transId, vm::ptr<char> buffer, u32 size)
{
cellHttp.todo("cellHttpTransactionGetSslCipherString(transId=0x%x, buffer=*0x%x, size=0x%x)", transId, buffer, size);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_TRANS;
}
return CELL_OK;
}
error_code cellHttpTransactionGetSslVersion(CellHttpTransId transId, vm::ptr<s32> version)
{
cellHttp.todo("cellHttpTransactionGetSslVersion(transId=0x%x, version=*0x%x)", transId, version);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_TRANS;
}
return CELL_OK;
}
error_code cellHttpTransactionGetSslId(CellHttpTransId transId, vm::pptr<void> id)
{
cellHttp.todo("cellHttpTransactionGetSslId(transId=0x%x, id=*0x%x)", transId, id);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_TRANS;
}
return CELL_OK;
}
error_code cellHttpClientSetSslVersion(CellHttpClientId clientId, s32 version)
{
cellHttp.todo("cellHttpClientSetSslVersion(clientId=0x%x, version=%d)", clientId, version);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
return CELL_OK;
}
error_code cellHttpClientGetSslVersion(CellHttpClientId clientId, vm::ptr<s32> version)
{
cellHttp.todo("cellHttpClientGetSslVersion(clientId=0x%x, version=*0x%x)", clientId, version);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
if (!version)
{
return CELL_HTTP_ERROR_NO_BUFFER;
}
return CELL_OK;
}
error_code cellHttpClientSetMinSslVersion(CellHttpClientId clientId, s32 version)
{
cellHttp.todo("cellHttpClientSetMinSslVersion(clientId=0x%x, version=%d)", clientId, version);
if (version != CELL_SSL_VERSION_TLS1)
{
if (version != CELL_SSL_VERSION_SSL3)
{
return CELL_HTTP_ERROR_INVALID_VALUE;
}
version = 2; // TODO: this can't be right, can it ?
}
return cellHttpClientSetSslVersion(clientId, version);
}
error_code cellHttpClientGetMinSslVersion(CellHttpClientId clientId, vm::ptr<s32> version)
{
cellHttp.todo("cellHttpClientGetMinSslVersion(clientId=0x%x, version=*0x%x)", clientId, version);
if (error_code error = cellHttpClientGetSslVersion(clientId, version))
{
return error;
}
if (*version == 2)
{
*version = CELL_SSL_VERSION_SSL3;
}
return CELL_OK;
}
error_code cellHttpClientSetSslIdDestroyCallback(CellHttpClientId clientId, vm::ptr<void> cbfunc, vm::ptr<void> userArg)
{
cellHttp.todo("cellHttpClientSetSslIdDestroyCallback(clientId=0x%x, cbfunc=*0x%x, userArg=*0x%x)", clientId, cbfunc, userArg);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.initialized)
{
return CELL_HTTP_ERROR_NOT_INITIALIZED;
}
if (false) // TODO
{
return CELL_HTTP_ERROR_BAD_CLIENT;
}
return CELL_OK;
}
error_code cellHttpFlushCache()
{
cellHttp.todo("cellHttpFlushCache()");
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.cache_initialized)
{
return CELL_HTTP_ERROR_CACHE_NOT_INITIALIZED;
}
return CELL_OK;
}
error_code cellHttpEndCache()
{
cellHttp.todo("cellHttpEndCache()");
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.cache_initialized)
{
return CELL_HTTP_ERROR_CACHE_NOT_INITIALIZED;
}
man.cache_initialized = false;
return CELL_OK;
}
error_code cellHttpInitCache(u32 unk)
{
cellHttp.todo("cellHttpInitCache(unk=0x%x)", unk);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (man.cache_initialized)
{
return CELL_HTTP_ERROR_CACHE_ALREADY_INITIALIZED;
}
man.cache_initialized = true;
return CELL_OK;
}
error_code cellHttpEndExternalCache()
{
cellHttp.todo("cellHttpEndExternalCache()");
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.ext_cache_initialized)
{
return CELL_HTTP_ERROR_CACHE_NOT_INITIALIZED;
}
man.ext_cache_initialized = false;
return CELL_OK;
}
error_code cellHttpInitExternalCache(vm::ptr<void> buf, u32 size)
{
cellHttp.todo("cellHttpInitExternalCache(buf=*0x%x, size=0x%x)", size);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (man.ext_cache_initialized)
{
return CELL_HTTP_ERROR_CACHE_ALREADY_INITIALIZED;
}
if (buf)
{
std::memset(buf.get_ptr(), 0, size);
}
if (size >= 512)
{
// TODO
}
man.ext_cache_initialized = true;
return CELL_OK;
}
error_code cellHttpFlushExternalCache()
{
cellHttp.todo("cellHttpFlushExternalCache()");
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.ext_cache_initialized)
{
return CELL_HTTP_ERROR_CACHE_NOT_INITIALIZED;
}
return CELL_OK;
}
error_code cellHttpGetCacheInfo(vm::ptr<void> buf)
{
cellHttp.todo("cellHttpGetCacheInfo(buf=*0x%x)", buf);
auto& man = g_fxo->get<http_manager>();
std::lock_guard lock(man.mtx);
if (!man.cache_initialized)
{
return CELL_HTTP_ERROR_CACHE_NOT_INITIALIZED;
}
return CELL_OK;
}
error_code cellHttpGetMemoryInfo(vm::ptr<u32> heapSize, vm::ptr<u32> param_2, vm::ptr<u32> param_3)
{
cellHttp.todo("cellHttpGetMemoryInfo(heapSize=*0x%x, param_2=*0x%x, param_3=*0x%x)", heapSize, param_2, param_3);
if (heapSize)
{
//*heapSize = _sys_heap_get_total_free_size();
}
if (!param_2 && !param_3)
{
return CELL_OK;
}
if (param_2)
{
*param_2 = *param_3;
}
//*param_3 = _sys_heap_get_mallinfo();
return CELL_OK;
}
DECLARE(ppu_module_manager::cellHttp)("cellHttp", []()
{
REG_FUNC(cellHttp, cellHttpAuthCacheExport);
REG_FUNC(cellHttp, cellHttpAuthCacheFlush);
REG_FUNC(cellHttp, cellHttpAuthCacheGetEntryMax);
REG_FUNC(cellHttp, cellHttpAuthCacheImport);
REG_FUNC(cellHttp, cellHttpAuthCacheSetEntryMax);
REG_FUNC(cellHttp, cellHttpInit);
REG_FUNC(cellHttp, cellHttpEnd);
REG_FUNC(cellHttp, cellHttpsInit);
REG_FUNC(cellHttp, cellHttpsEnd);
REG_FUNC(cellHttp, cellHttpSetProxy);
REG_FUNC(cellHttp, cellHttpGetCookie);
REG_FUNC(cellHttp, cellHttpGetProxy);
REG_FUNC(cellHttp, cellHttpInitCookie);
REG_FUNC(cellHttp, cellHttpEndCookie);
REG_FUNC(cellHttp, cellHttpAddCookieWithClientId);
REG_FUNC(cellHttp, cellHttpSessionCookieFlush);
REG_FUNC(cellHttp, cellHttpCookieExport);
REG_FUNC(cellHttp, cellHttpCookieExportWithClientId);
REG_FUNC(cellHttp, cellHttpCookieFlush);
REG_FUNC(cellHttp, cellHttpCookieImport);
REG_FUNC(cellHttp, cellHttpCookieImportWithClientId);
REG_FUNC(cellHttp, cellHttpClientSetCookieSendCallback);
REG_FUNC(cellHttp, cellHttpClientSetCookieRecvCallback);
REG_FUNC(cellHttp, cellHttpCreateClient);
REG_FUNC(cellHttp, cellHttpDestroyClient);
REG_FUNC(cellHttp, cellHttpClientSetAuthenticationCallback);
REG_FUNC(cellHttp, cellHttpClientSetTransactionStateCallback);
REG_FUNC(cellHttp, cellHttpClientSetRedirectCallback);
REG_FUNC(cellHttp, cellHttpClientSetCacheStatus);
REG_FUNC(cellHttp, cellHttpClientSetProxy);
REG_FUNC(cellHttp, cellHttpClientGetProxy);
REG_FUNC(cellHttp, cellHttpClientSetVersion);
REG_FUNC(cellHttp, cellHttpClientGetVersion);
REG_FUNC(cellHttp, cellHttpClientSetPipeline);
REG_FUNC(cellHttp, cellHttpClientGetPipeline);
REG_FUNC(cellHttp, cellHttpClientSetKeepAlive);
REG_FUNC(cellHttp, cellHttpClientGetKeepAlive);
REG_FUNC(cellHttp, cellHttpClientSetAutoRedirect);
REG_FUNC(cellHttp, cellHttpClientGetAutoRedirect);
REG_FUNC(cellHttp, cellHttpClientSetAutoAuthentication);
REG_FUNC(cellHttp, cellHttpClientGetAutoAuthentication);
REG_FUNC(cellHttp, cellHttpClientSetAuthenticationCacheStatus);
REG_FUNC(cellHttp, cellHttpClientGetAuthenticationCacheStatus);
REG_FUNC(cellHttp, cellHttpClientSetCookieStatus);
REG_FUNC(cellHttp, cellHttpClientGetCookieStatus);
REG_FUNC(cellHttp, cellHttpClientSetUserAgent);
REG_FUNC(cellHttp, cellHttpClientGetUserAgent);
REG_FUNC(cellHttp, cellHttpClientSetResponseBufferMax);
REG_FUNC(cellHttp, cellHttpClientGetResponseBufferMax);
REG_FUNC(cellHttp, cellHttpClientCloseAllConnections);
REG_FUNC(cellHttp, cellHttpClientCloseConnections);
REG_FUNC(cellHttp, cellHttpClientPollConnections);
REG_FUNC(cellHttp, cellHttpClientSetConnectionStateCallback);
REG_FUNC(cellHttp, cellHttpClientGetConnectionWaitStatus);
REG_FUNC(cellHttp, cellHttpClientSetConnectionWaitStatus);
REG_FUNC(cellHttp, cellHttpClientGetConnectionWaitTimeout);
REG_FUNC(cellHttp, cellHttpClientSetConnectionWaitTimeout);
REG_FUNC(cellHttp, cellHttpClientSetRecvTimeout);
REG_FUNC(cellHttp, cellHttpClientGetRecvTimeout);
REG_FUNC(cellHttp, cellHttpClientSetSendTimeout);
REG_FUNC(cellHttp, cellHttpClientGetSendTimeout);
REG_FUNC(cellHttp, cellHttpClientSetConnTimeout);
REG_FUNC(cellHttp, cellHttpClientGetConnTimeout);
REG_FUNC(cellHttp, cellHttpClientSetTotalPoolSize);
REG_FUNC(cellHttp, cellHttpClientGetTotalPoolSize);
REG_FUNC(cellHttp, cellHttpClientSetPerHostPoolSize);
REG_FUNC(cellHttp, cellHttpClientGetPerHostPoolSize);
REG_FUNC(cellHttp, cellHttpClientSetPerHostKeepAliveMax);
REG_FUNC(cellHttp, cellHttpClientGetPerHostKeepAliveMax);
REG_FUNC(cellHttp, cellHttpClientSetPerPipelineMax);
REG_FUNC(cellHttp, cellHttpClientGetPerPipelineMax);
REG_FUNC(cellHttp, cellHttpClientSetRecvBufferSize);
REG_FUNC(cellHttp, cellHttpClientGetRecvBufferSize);
REG_FUNC(cellHttp, cellHttpClientSetSendBufferSize);
REG_FUNC(cellHttp, cellHttpClientGetSendBufferSize);
REG_FUNC(cellHttp, cellHttpClientGetAllHeaders);
REG_FUNC(cellHttp, cellHttpClientSetHeader);
REG_FUNC(cellHttp, cellHttpClientGetHeader);
REG_FUNC(cellHttp, cellHttpClientAddHeader);
REG_FUNC(cellHttp, cellHttpClientDeleteHeader);
REG_FUNC(cellHttp, cellHttpClientSetSslCallback);
REG_FUNC(cellHttp, cellHttpClientSetSslClientCertificate);
REG_FUNC(cellHttp, cellHttpCreateTransaction);
REG_FUNC(cellHttp, cellHttpDestroyTransaction);
REG_FUNC(cellHttp, cellHttpTransactionGetUri);
REG_FUNC(cellHttp, cellHttpTransactionSetUri);
REG_FUNC(cellHttp, cellHttpTransactionCloseConnection);
REG_FUNC(cellHttp, cellHttpTransactionReleaseConnection);
REG_FUNC(cellHttp, cellHttpTransactionAbortConnection);
REG_FUNC(cellHttp, cellHttpSendRequest);
REG_FUNC(cellHttp, cellHttpRequestSetContentLength);
REG_FUNC(cellHttp, cellHttpRequestGetContentLength);
REG_FUNC(cellHttp, cellHttpRequestSetChunkedTransferStatus);
REG_FUNC(cellHttp, cellHttpRequestGetChunkedTransferStatus);
REG_FUNC(cellHttp, cellHttpRequestGetAllHeaders);
REG_FUNC(cellHttp, cellHttpRequestSetHeader);
REG_FUNC(cellHttp, cellHttpRequestGetHeader);
REG_FUNC(cellHttp, cellHttpRequestAddHeader);
REG_FUNC(cellHttp, cellHttpRequestDeleteHeader);
REG_FUNC(cellHttp, cellHttpRecvResponse);
REG_FUNC(cellHttp, cellHttpResponseGetAllHeaders);
REG_FUNC(cellHttp, cellHttpResponseGetHeader);
REG_FUNC(cellHttp, cellHttpResponseGetContentLength);
REG_FUNC(cellHttp, cellHttpResponseGetStatusCode);
REG_FUNC(cellHttp, cellHttpResponseGetStatusLine);
REG_FUNC(cellHttp, cellHttpTransactionGetSslCipherName);
REG_FUNC(cellHttp, cellHttpTransactionGetSslCipherId);
REG_FUNC(cellHttp, cellHttpTransactionGetSslCipherVersion);
REG_FUNC(cellHttp, cellHttpTransactionGetSslCipherBits);
REG_FUNC(cellHttp, cellHttpTransactionGetSslCipherString);
REG_FUNC(cellHttp, cellHttpTransactionGetSslVersion);
REG_FUNC(cellHttp, cellHttpTransactionGetSslId);
REG_FUNC(cellHttp, cellHttpClientSetMinSslVersion);
REG_FUNC(cellHttp, cellHttpClientGetMinSslVersion);
REG_FUNC(cellHttp, cellHttpClientSetSslVersion);
REG_FUNC(cellHttp, cellHttpClientGetSslVersion);
REG_FUNC(cellHttp, cellHttpClientSetSslIdDestroyCallback);
REG_FUNC(cellHttp, cellHttpFlushCache);
REG_FUNC(cellHttp, cellHttpEndCache);
REG_FUNC(cellHttp, cellHttpEndExternalCache);
REG_FUNC(cellHttp, cellHttpInitCache);
REG_FUNC(cellHttp, cellHttpGetCacheInfo);
REG_FUNC(cellHttp, cellHttpGetMemoryInfo);
});
DECLARE(ppu_module_manager::cellHttps)("cellHttps", []()
{
// cellHttps doesn't have functions (cellHttpsInit belongs to cellHttp, for example)
});
| 114,336
|
C++
|
.cpp
| 3,237
| 32.493358
| 184
| 0.750942
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
5,268
|
cellAdec.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellAdec.cpp
|
#include "stdafx.h"
#include "Emu/System.h"
#include "Emu/IdManager.h"
#include "Emu/Cell/PPUModule.h"
#include "Emu/Cell/lv2/sys_sync.h"
#include "util/media_utils.h"
#ifdef _MSC_VER
#pragma warning(push, 0)
#else
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wall"
#pragma GCC diagnostic ignored "-Wextra"
#pragma GCC diagnostic ignored "-Wold-style-cast"
#endif
extern "C"
{
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#ifndef AV_INPUT_BUFFER_PADDING_SIZE
#define AV_INPUT_BUFFER_PADDING_SIZE FF_INPUT_BUFFER_PADDING_SIZE
#endif
}
#ifdef _MSC_VER
#pragma warning(pop)
#else
#pragma GCC diagnostic pop
#endif
#include "cellPamf.h"
#include "cellAtracXdec.h"
#include "cellAdec.h"
#include <mutex>
extern std::mutex g_mutex_avcodec_open2;
LOG_CHANNEL(cellAdec);
template <>
void fmt_class_string<CellAdecError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](CellAdecError value)
{
switch (value)
{
STR_CASE(CELL_ADEC_ERROR_FATAL);
STR_CASE(CELL_ADEC_ERROR_SEQ);
STR_CASE(CELL_ADEC_ERROR_ARG);
STR_CASE(CELL_ADEC_ERROR_BUSY);
STR_CASE(CELL_ADEC_ERROR_EMPTY);
STR_CASE(CELL_ADEC_ERROR_CELP_BUSY);
STR_CASE(CELL_ADEC_ERROR_CELP_EMPTY);
STR_CASE(CELL_ADEC_ERROR_CELP_ARG);
STR_CASE(CELL_ADEC_ERROR_CELP_SEQ);
STR_CASE(CELL_ADEC_ERROR_CELP_CORE_FATAL);
STR_CASE(CELL_ADEC_ERROR_CELP_CORE_ARG);
STR_CASE(CELL_ADEC_ERROR_CELP_CORE_SEQ);
STR_CASE(CELL_ADEC_ERROR_CELP8_BUSY);
STR_CASE(CELL_ADEC_ERROR_CELP8_EMPTY);
STR_CASE(CELL_ADEC_ERROR_CELP8_ARG);
STR_CASE(CELL_ADEC_ERROR_CELP8_SEQ);
STR_CASE(CELL_ADEC_ERROR_CELP8_CORE_FATAL);
STR_CASE(CELL_ADEC_ERROR_CELP8_CORE_ARG);
STR_CASE(CELL_ADEC_ERROR_CELP8_CORE_SEQ);
STR_CASE(CELL_ADEC_ERROR_M4AAC_FATAL);
STR_CASE(CELL_ADEC_ERROR_M4AAC_SEQ);
STR_CASE(CELL_ADEC_ERROR_M4AAC_ARG);
STR_CASE(CELL_ADEC_ERROR_M4AAC_BUSY);
STR_CASE(CELL_ADEC_ERROR_M4AAC_EMPTY);
STR_CASE(CELL_ADEC_ERROR_M4AAC_BUFFER_OVERFLOW);
STR_CASE(CELL_ADEC_ERROR_M4AAC_END_OF_BITSTREAM);
STR_CASE(CELL_ADEC_ERROR_M4AAC_CH_CONFIG_INCONSISTENCY);
STR_CASE(CELL_ADEC_ERROR_M4AAC_NO_CH_DEFAULT_POS);
STR_CASE(CELL_ADEC_ERROR_M4AAC_INVALID_CH_POS);
STR_CASE(CELL_ADEC_ERROR_M4AAC_UNANTICIPATED_COUPLING_CH);
STR_CASE(CELL_ADEC_ERROR_M4AAC_INVALID_LAYER_ID);
STR_CASE(CELL_ADEC_ERROR_M4AAC_ADTS_SYNCWORD_ERROR);
STR_CASE(CELL_ADEC_ERROR_M4AAC_INVALID_ADTS_ID);
STR_CASE(CELL_ADEC_ERROR_M4AAC_CH_CHANGED);
STR_CASE(CELL_ADEC_ERROR_M4AAC_SAMPLING_FREQ_CHANGED);
STR_CASE(CELL_ADEC_ERROR_M4AAC_WRONG_SBR_CH);
STR_CASE(CELL_ADEC_ERROR_M4AAC_WRONG_SCALE_FACTOR);
STR_CASE(CELL_ADEC_ERROR_M4AAC_INVALID_BOOKS);
STR_CASE(CELL_ADEC_ERROR_M4AAC_INVALID_SECTION_DATA);
STR_CASE(CELL_ADEC_ERROR_M4AAC_PULSE_IS_NOT_LONG);
STR_CASE(CELL_ADEC_ERROR_M4AAC_GC_IS_NOT_SUPPORTED);
STR_CASE(CELL_ADEC_ERROR_M4AAC_INVALID_ELEMENT_ID);
STR_CASE(CELL_ADEC_ERROR_M4AAC_NO_CH_CONFIG);
STR_CASE(CELL_ADEC_ERROR_M4AAC_UNEXPECTED_OVERLAP_CRC);
STR_CASE(CELL_ADEC_ERROR_M4AAC_CRC_BUFFER_EXCEEDED);
STR_CASE(CELL_ADEC_ERROR_M4AAC_INVALID_CRC);
STR_CASE(CELL_ADEC_ERROR_M4AAC_BAD_WINDOW_CODE);
STR_CASE(CELL_ADEC_ERROR_M4AAC_INVALID_ADIF_HEADER_ID);
STR_CASE(CELL_ADEC_ERROR_M4AAC_NOT_SUPPORTED_PROFILE);
STR_CASE(CELL_ADEC_ERROR_M4AAC_PROG_NUMBER_NOT_FOUND);
STR_CASE(CELL_ADEC_ERROR_M4AAC_INVALID_SAMP_RATE_INDEX);
STR_CASE(CELL_ADEC_ERROR_M4AAC_UNANTICIPATED_CH_CONFIG);
STR_CASE(CELL_ADEC_ERROR_M4AAC_PULSE_OVERFLOWED);
STR_CASE(CELL_ADEC_ERROR_M4AAC_CAN_NOT_UNPACK_INDEX);
STR_CASE(CELL_ADEC_ERROR_M4AAC_DEINTERLEAVE_FAILED);
STR_CASE(CELL_ADEC_ERROR_M4AAC_CALC_BAND_OFFSET_FAILED);
STR_CASE(CELL_ADEC_ERROR_M4AAC_GET_SCALE_FACTOR_FAILED);
STR_CASE(CELL_ADEC_ERROR_M4AAC_GET_CC_GAIN_FAILED);
STR_CASE(CELL_ADEC_ERROR_M4AAC_MIX_COUPLING_CH_FAILED);
STR_CASE(CELL_ADEC_ERROR_M4AAC_GROUP_IS_INVALID);
STR_CASE(CELL_ADEC_ERROR_M4AAC_PREDICT_FAILED);
STR_CASE(CELL_ADEC_ERROR_M4AAC_INVALID_PREDICT_RESET_PATTERN);
STR_CASE(CELL_ADEC_ERROR_M4AAC_INVALID_TNS_FRAME_INFO);
STR_CASE(CELL_ADEC_ERROR_M4AAC_GET_MASK_FAILED);
STR_CASE(CELL_ADEC_ERROR_M4AAC_GET_GROUP_FAILED);
STR_CASE(CELL_ADEC_ERROR_M4AAC_GET_LPFLAG_FAILED);
STR_CASE(CELL_ADEC_ERROR_M4AAC_INVERSE_QUANTIZATION_FAILED);
STR_CASE(CELL_ADEC_ERROR_M4AAC_GET_CB_MAP_FAILED);
STR_CASE(CELL_ADEC_ERROR_M4AAC_GET_PULSE_FAILED);
STR_CASE(CELL_ADEC_ERROR_M4AAC_MONO_MIXDOWN_ELEMENT_IS_NOT_SUPPORTED);
STR_CASE(CELL_ADEC_ERROR_M4AAC_STEREO_MIXDOWN_ELEMENT_IS_NOT_SUPPORTED);
STR_CASE(CELL_ADEC_ERROR_M4AAC_SBR_CH_OVERFLOW);
STR_CASE(CELL_ADEC_ERROR_M4AAC_SBR_NOSYNCH);
STR_CASE(CELL_ADEC_ERROR_M4AAC_SBR_ILLEGAL_PROGRAM);
STR_CASE(CELL_ADEC_ERROR_M4AAC_SBR_ILLEGAL_TAG);
STR_CASE(CELL_ADEC_ERROR_M4AAC_SBR_ILLEGAL_CHN_CONFIG);
STR_CASE(CELL_ADEC_ERROR_M4AAC_SBR_ILLEGAL_SECTION);
STR_CASE(CELL_ADEC_ERROR_M4AAC_SBR_ILLEGAL_SCFACTORS);
STR_CASE(CELL_ADEC_ERROR_M4AAC_SBR_ILLEGAL_PULSE_DATA);
STR_CASE(CELL_ADEC_ERROR_M4AAC_SBR_MAIN_PROFILE_NOT_IMPLEMENTED);
STR_CASE(CELL_ADEC_ERROR_M4AAC_SBR_GC_NOT_IMPLEMENTED);
STR_CASE(CELL_ADEC_ERROR_M4AAC_SBR_ILLEGAL_PLUS_ELE_ID);
STR_CASE(CELL_ADEC_ERROR_M4AAC_SBR_CREATE_ERROR);
STR_CASE(CELL_ADEC_ERROR_M4AAC_SBR_NOT_INITIALIZED);
STR_CASE(CELL_ADEC_ERROR_M4AAC_SBR_INVALID_ENVELOPE);
STR_CASE(CELL_ADEC_ERROR_AC3_BUSY);
STR_CASE(CELL_ADEC_ERROR_AC3_EMPTY);
STR_CASE(CELL_ADEC_ERROR_AC3_PARAM);
STR_CASE(CELL_ADEC_ERROR_AC3_FRAME);
STR_CASE(CELL_ADEC_ERROR_AT3_OK); // CELL_ADEC_ERROR_AT3_OFFSET
STR_CASE(CELL_ADEC_ERROR_AT3_BUSY);
STR_CASE(CELL_ADEC_ERROR_AT3_EMPTY);
STR_CASE(CELL_ADEC_ERROR_AT3_ERROR);
STR_CASE(CELL_ADEC_ERROR_LPCM_FATAL);
STR_CASE(CELL_ADEC_ERROR_LPCM_SEQ);
STR_CASE(CELL_ADEC_ERROR_LPCM_ARG);
STR_CASE(CELL_ADEC_ERROR_LPCM_BUSY);
STR_CASE(CELL_ADEC_ERROR_LPCM_EMPTY);
STR_CASE(CELL_ADEC_ERROR_MP3_OK); // CELL_ADEC_ERROR_MP3_OFFSET
STR_CASE(CELL_ADEC_ERROR_MP3_BUSY);
STR_CASE(CELL_ADEC_ERROR_MP3_EMPTY);
STR_CASE(CELL_ADEC_ERROR_MP3_ERROR);
STR_CASE(CELL_ADEC_ERROR_MP3_LOST_SYNC);
STR_CASE(CELL_ADEC_ERROR_MP3_NOT_L3);
STR_CASE(CELL_ADEC_ERROR_MP3_BAD_BITRATE);
STR_CASE(CELL_ADEC_ERROR_MP3_BAD_SFREQ);
STR_CASE(CELL_ADEC_ERROR_MP3_BAD_EMPHASIS);
STR_CASE(CELL_ADEC_ERROR_MP3_BAD_BLKTYPE);
STR_CASE(CELL_ADEC_ERROR_MP3_BAD_VERSION);
STR_CASE(CELL_ADEC_ERROR_MP3_BAD_MODE);
STR_CASE(CELL_ADEC_ERROR_MP3_BAD_MODE_EXT);
STR_CASE(CELL_ADEC_ERROR_MP3_HUFFMAN_NUM);
STR_CASE(CELL_ADEC_ERROR_MP3_HUFFMAN_CASE_ID);
STR_CASE(CELL_ADEC_ERROR_MP3_SCALEFAC_COMPRESS);
STR_CASE(CELL_ADEC_ERROR_MP3_HGETBIT);
STR_CASE(CELL_ADEC_ERROR_MP3_FLOATING_EXCEPTION);
STR_CASE(CELL_ADEC_ERROR_MP3_ARRAY_OVERFLOW);
STR_CASE(CELL_ADEC_ERROR_MP3_STEREO_PROCESSING);
STR_CASE(CELL_ADEC_ERROR_MP3_JS_BOUND);
STR_CASE(CELL_ADEC_ERROR_MP3_PCMOUT);
STR_CASE(CELL_ADEC_ERROR_M2BC_FATAL);
STR_CASE(CELL_ADEC_ERROR_M2BC_SEQ);
STR_CASE(CELL_ADEC_ERROR_M2BC_ARG);
STR_CASE(CELL_ADEC_ERROR_M2BC_BUSY);
STR_CASE(CELL_ADEC_ERROR_M2BC_EMPTY);
STR_CASE(CELL_ADEC_ERROR_M2BC_SYNCF);
STR_CASE(CELL_ADEC_ERROR_M2BC_LAYER);
STR_CASE(CELL_ADEC_ERROR_M2BC_BITRATE);
STR_CASE(CELL_ADEC_ERROR_M2BC_SAMPLEFREQ);
STR_CASE(CELL_ADEC_ERROR_M2BC_VERSION);
STR_CASE(CELL_ADEC_ERROR_M2BC_MODE_EXT);
STR_CASE(CELL_ADEC_ERROR_M2BC_UNSUPPORT);
STR_CASE(CELL_ADEC_ERROR_M2BC_OPENBS_EX);
STR_CASE(CELL_ADEC_ERROR_M2BC_SYNCF_EX);
STR_CASE(CELL_ADEC_ERROR_M2BC_CRCGET_EX);
STR_CASE(CELL_ADEC_ERROR_M2BC_CRC_EX);
STR_CASE(CELL_ADEC_ERROR_M2BC_CRCGET);
STR_CASE(CELL_ADEC_ERROR_M2BC_CRC);
STR_CASE(CELL_ADEC_ERROR_M2BC_BITALLOC);
STR_CASE(CELL_ADEC_ERROR_M2BC_SCALE);
STR_CASE(CELL_ADEC_ERROR_M2BC_SAMPLE);
STR_CASE(CELL_ADEC_ERROR_M2BC_OPENBS);
STR_CASE(CELL_ADEC_ERROR_M2BC_MC_CRCGET);
STR_CASE(CELL_ADEC_ERROR_M2BC_MC_CRC);
STR_CASE(CELL_ADEC_ERROR_M2BC_MC_BITALLOC);
STR_CASE(CELL_ADEC_ERROR_M2BC_MC_SCALE);
STR_CASE(CELL_ADEC_ERROR_M2BC_MC_SAMPLE);
STR_CASE(CELL_ADEC_ERROR_M2BC_MC_HEADER);
STR_CASE(CELL_ADEC_ERROR_M2BC_MC_STATUS);
STR_CASE(CELL_ADEC_ERROR_M2BC_AG_CCRCGET);
STR_CASE(CELL_ADEC_ERROR_M2BC_AG_CRC);
STR_CASE(CELL_ADEC_ERROR_M2BC_AG_BITALLOC);
STR_CASE(CELL_ADEC_ERROR_M2BC_AG_SCALE);
STR_CASE(CELL_ADEC_ERROR_M2BC_AG_SAMPLE);
STR_CASE(CELL_ADEC_ERROR_M2BC_AG_STATUS);
}
return unknown;
});
}
class AudioDecoder : public ppu_thread
{
public:
squeue_t<AdecTask> job;
volatile bool is_closed = false;
volatile bool is_finished = false;
bool just_started = false;
bool just_finished = false;
const AVCodec* codec = nullptr;
#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(59, 0, 0)
const AVInputFormat* input_format = nullptr;
#else
AVInputFormat* input_format = nullptr;
#endif
AVCodecContext* ctx = nullptr;
AVFormatContext* fmt = nullptr;
u8* io_buf = nullptr;
struct AudioReader
{
u32 addr{};
u32 size{};
bool init{};
bool has_ats{};
} reader;
squeue_t<AdecFrame> frames;
const s32 type;
const u32 memAddr;
const u32 memSize;
const vm::ptr<CellAdecCbMsg> cbFunc;
const u32 cbArg;
u32 memBias = 0;
AdecTask task;
u64 last_pts{};
u64 first_pts{};
u32 ch_out{};
u32 ch_cfg{};
u32 frame_size{};
u32 sample_rate{};
bool use_ats_headers{};
AudioDecoder(s32 type, u32 addr, u32 size, vm::ptr<CellAdecCbMsg> func, u32 arg)
: ppu_thread({}, "", 0)
, type(type)
, memAddr(addr)
, memSize(size)
, cbFunc(func)
, cbArg(arg)
{
switch (type)
{
case CELL_ADEC_TYPE_ATRACX:
case CELL_ADEC_TYPE_ATRACX_2CH:
case CELL_ADEC_TYPE_ATRACX_6CH:
case CELL_ADEC_TYPE_ATRACX_8CH:
{
codec = avcodec_find_decoder(AV_CODEC_ID_ATRAC3P);
input_format = av_find_input_format("oma");
break;
}
case CELL_ADEC_TYPE_MP3:
{
codec = avcodec_find_decoder(AV_CODEC_ID_MP3);
input_format = av_find_input_format("mp3");
break;
}
default:
{
fmt::throw_exception("Unknown type (0x%x)", type);
}
}
if (!codec)
{
fmt::throw_exception("avcodec_find_decoder() failed");
}
if (!input_format)
{
fmt::throw_exception("av_find_input_format() failed");
}
fmt = avformat_alloc_context();
if (!fmt)
{
fmt::throw_exception("avformat_alloc_context() failed");
}
io_buf = static_cast<u8*>(av_malloc(4096));
fmt->pb = avio_alloc_context(io_buf, 256, 0, this, adecRead, nullptr, nullptr);
if (!fmt->pb)
{
fmt::throw_exception("avio_alloc_context() failed");
}
}
~AudioDecoder()
{
// TODO: check finalization
AdecFrame af;
while (frames.try_pop(af))
{
av_frame_unref(af.data);
av_frame_free(&af.data);
}
if (ctx)
{
avcodec_free_context(&ctx);
}
if (io_buf)
{
av_freep(&io_buf);
}
if (fmt)
{
if (fmt->pb) av_freep(&fmt->pb);
avformat_close_input(&fmt);
}
}
void non_task()
{
while (true)
{
if (Emu.IsStopped() || is_closed)
{
break;
}
if (!job.pop(task, &is_closed))
{
break;
}
switch (task.type)
{
case adecStartSeq:
{
// TODO: reset data
cellAdec.warning("adecStartSeq:");
reader.addr = 0;
reader.size = 0;
reader.init = false;
reader.has_ats = false;
just_started = true;
if (adecIsAtracX(type))
{
ch_cfg = task.at3p.channel_config;
ch_out = task.at3p.channels;
frame_size = task.at3p.frame_size;
sample_rate = task.at3p.sample_rate;
use_ats_headers = task.at3p.ats_header == 1;
}
break;
}
case adecEndSeq:
{
// TODO: finalize
cellAdec.warning("adecEndSeq:");
cbFunc(*this, id, CELL_ADEC_MSG_TYPE_SEQDONE, CELL_OK, cbArg);
lv2_obj::sleep(*this);
just_finished = true;
break;
}
case adecDecodeAu:
{
int err = 0;
reader.addr = task.au.addr;
reader.size = task.au.size;
reader.has_ats = use_ats_headers;
//cellAdec.notice("Audio AU: size = 0x%x, pts = 0x%llx", task.au.size, task.au.pts);
if (just_started)
{
first_pts = task.au.pts;
last_pts = task.au.pts;
if (adecIsAtracX(type)) last_pts -= 0x10000; // hack
}
AVPacket* packet = av_packet_alloc();
std::unique_ptr<AVPacket, decltype([](AVPacket* p)
{
av_packet_unref(p);
av_packet_free(&p);
})> packet_(packet);
if (just_started && just_finished)
{
avcodec_flush_buffers(ctx);
reader.init = true; // wrong
just_finished = false;
just_started = false;
}
else if (just_started) // deferred initialization
{
AVDictionary* opts = nullptr;
err = av_dict_set(&opts, "probesize", "96", 0);
if (err < 0)
{
fmt::throw_exception("av_dict_set(probesize, 96) failed (err=0x%x='%s')", err, utils::av_error_to_string(err));
}
err = avformat_open_input(&fmt, nullptr, input_format, &opts);
if (err || opts)
{
std::string dict_content;
if (opts)
{
AVDictionaryEntry* tag = nullptr;
while ((tag = av_dict_get(opts, "", tag, AV_DICT_IGNORE_SUFFIX)))
{
fmt::append(dict_content, "['%s': '%s']", tag->key, tag->value);
}
}
fmt::throw_exception("avformat_open_input() failed (err=0x%x='%s', opts=%s)", err, utils::av_error_to_string(err), dict_content);
}
//err = avformat_find_stream_info(fmt, NULL);
//if (err || !fmt->nb_streams)
//{
// fmt::throw_exception("avformat_find_stream_info() failed (err=0x%x='%s', nb_streams=%d)", err, utils::av_error_to_string(err), fmt->nb_streams);
//}
if (!avformat_new_stream(fmt, codec))
{
fmt::throw_exception("avformat_new_stream() failed");
}
//ctx = fmt->streams[0]->codec; // TODO: check data
opts = nullptr;
{
std::lock_guard lock(g_mutex_avcodec_open2);
// not multithread-safe (???)
err = avcodec_open2(ctx, codec, &opts);
}
if (err || opts)
{
std::string dict_content;
if (opts)
{
AVDictionaryEntry* tag = nullptr;
while ((tag = av_dict_get(opts, "", tag, AV_DICT_IGNORE_SUFFIX)))
{
fmt::append(dict_content, "['%s': '%s']", tag->key, tag->value);
}
}
fmt::throw_exception("avcodec_open2() failed (err=0x%x='%s', opts=%s)", err, utils::av_error_to_string(err), dict_content);
}
just_started = false;
}
while (true)
{
if (Emu.IsStopped() || is_closed)
{
if (Emu.IsStopped()) cellAdec.warning("adecDecodeAu: aborted");
break;
}
av_read_frame(fmt, packet);
struct AdecFrameHolder : AdecFrame
{
AdecFrameHolder()
{
data = av_frame_alloc();
}
~AdecFrameHolder()
{
if (data)
{
av_frame_unref(data);
av_frame_free(&data);
}
}
} frame;
if (!frame.data)
{
fmt::throw_exception("av_frame_alloc() failed");
}
int got_frame = 0;
int decode = 0; //avcodec_decode_audio4(ctx, frame.data, &got_frame, &au);
if (decode <= 0)
{
if (decode < 0)
{
cellAdec.error("adecDecodeAu: AU decoding error(0x%x)", decode);
}
if (!got_frame && reader.size == 0) break;
}
if (got_frame)
{
//u64 ts = av_frame_get_best_effort_timestamp(frame.data);
//if (ts != AV_NOPTS_VALUE)
//{
// frame.pts = ts/* - first_pts*/;
// last_pts = frame.pts;
//}
last_pts += frame.data->nb_samples * 90000ull / frame.data->sample_rate;
frame.pts = last_pts;
s32 nbps = av_get_bytes_per_sample(static_cast<AVSampleFormat>(frame.data->format));
switch (frame.data->format)
{
case AV_SAMPLE_FMT_FLTP: break;
case AV_SAMPLE_FMT_S16P: break;
default:
{
fmt::throw_exception("Unsupported frame format(%d)", frame.data->format);
}
}
frame.auAddr = task.au.addr;
frame.auSize = task.au.size;
frame.userdata = task.au.userdata;
frame.size = frame.data->nb_samples * frame.data->ch_layout.nb_channels * nbps;
//cellAdec.notice("got audio frame (pts=0x%llx, nb_samples=%d, ch=%d, sample_rate=%d, nbps=%d)",
//frame.pts, frame.data->nb_samples, frame.data->ch_layout.nb_channels, frame.data->sample_rate, nbps);
if (frames.push(frame, &is_closed))
{
frame.data = nullptr; // to prevent destruction
cbFunc(*this, id, CELL_ADEC_MSG_TYPE_PCMOUT, CELL_OK, cbArg);
lv2_obj::sleep(*this);
}
}
}
cbFunc(*this, id, CELL_ADEC_MSG_TYPE_AUDONE, task.au.auInfo_addr, cbArg);
lv2_obj::sleep(*this);
break;
}
case adecClose:
{
break;
}
default:
{
fmt::throw_exception("Unknown task(%d)", +task.type);
}
}
}
is_finished = true;
}
};
int adecRead(void* opaque, u8* buf, int buf_size)
{
AudioDecoder& adec = *static_cast<AudioDecoder*>(opaque);
int res = 0;
next:
if (adecIsAtracX(adec.type) && adec.reader.has_ats)
{
u8 code1 = vm::read8(adec.reader.addr + 2);
u8 code2 = vm::read8(adec.reader.addr + 3);
adec.ch_cfg = (code1 >> 2) & 0x7;
adec.frame_size = (((u32{code1} & 0x3) << 8) | code2) * 8 + 8;
adec.sample_rate = at3freq[code1 >> 5];
adec.reader.size -= 8;
adec.reader.addr += 8;
adec.reader.has_ats = false;
}
if (adecIsAtracX(adec.type) && !adec.reader.init)
{
OMAHeader oma(1 /* atrac3p id */, adec.sample_rate, adec.ch_cfg, adec.frame_size);
if (buf_size + 0u < sizeof(oma))
{
cellAdec.fatal("adecRead(): OMAHeader writing failed");
return 0;
}
memcpy(buf, &oma, sizeof(oma));
buf += sizeof(oma);
buf_size -= sizeof(oma);
res += sizeof(oma);
adec.reader.init = true;
}
if (adec.reader.size < static_cast<u32>(buf_size) /*&& !adec.just_started*/)
{
AdecTask task;
if (!adec.job.peek(task, 0, &adec.is_closed))
{
if (Emu.IsStopped()) cellAdec.warning("adecRawRead() aborted");
return 0;
}
switch (task.type)
{
case adecEndSeq:
case adecClose:
{
buf_size = adec.reader.size;
break;
}
case adecDecodeAu:
{
std::memcpy(buf, vm::base(adec.reader.addr), adec.reader.size);
buf += adec.reader.size;
buf_size -= adec.reader.size;
res += adec.reader.size;
adec.cbFunc(adec, adec.id, CELL_ADEC_MSG_TYPE_AUDONE, adec.task.au.auInfo_addr, adec.cbArg);
adec.job.pop(adec.task);
adec.reader.addr = adec.task.au.addr;
adec.reader.size = adec.task.au.size;
adec.reader.has_ats = adec.use_ats_headers;
//cellAdec.notice("Audio AU: size = 0x%x, pts = 0x%llx", adec.task.au.size, adec.task.au.pts);
break;
}
case adecStartSeq: // TODO ?
default:
{
cellAdec.fatal("adecRawRead(): unknown task (%d)", +task.type);
return -1;
}
}
goto next;
}
else if (adec.reader.size < static_cast<u32>(buf_size) && 0)
{
buf_size = adec.reader.size;
}
if (!buf_size)
{
return res;
}
std::memcpy(buf, vm::base(adec.reader.addr), buf_size);
adec.reader.addr += buf_size;
adec.reader.size -= buf_size;
return res + buf_size;
}
bool adecCheckType(s32 type)
{
switch (type)
{
case CELL_ADEC_TYPE_ATRACX: cellAdec.notice("adecCheckType(): ATRAC3plus"); break;
case CELL_ADEC_TYPE_ATRACX_2CH: cellAdec.notice("adecCheckType(): ATRAC3plus 2ch"); break;
case CELL_ADEC_TYPE_ATRACX_6CH: cellAdec.notice("adecCheckType(): ATRAC3plus 6ch"); break;
case CELL_ADEC_TYPE_ATRACX_8CH: cellAdec.notice("adecCheckType(): ATRAC3plus 8ch"); break;
case CELL_ADEC_TYPE_MP3: cellAdec.notice("adecCheckType(): MP3"); break;
case CELL_ADEC_TYPE_LPCM_PAMF:
case CELL_ADEC_TYPE_AC3:
case CELL_ADEC_TYPE_ATRAC3:
case CELL_ADEC_TYPE_MPEG_L2:
case CELL_ADEC_TYPE_CELP:
case CELL_ADEC_TYPE_M4AAC:
case CELL_ADEC_TYPE_CELP8:
{
cellAdec.fatal("Unimplemented audio codec type (%d)", type);
break;
}
default: return false;
}
return true;
}
error_code cellAdecQueryAttr(vm::ptr<CellAdecType> type, vm::ptr<CellAdecAttr> attr)
{
cellAdec.warning("cellAdecQueryAttr(type=*0x%x, attr=*0x%x)", type, attr);
if (!adecCheckType(type->audioCodecType))
{
return CELL_ADEC_ERROR_ARG;
}
// TODO: check values
attr->adecVerLower = 0x280000; // from dmux
attr->adecVerUpper = 0x260000;
attr->workMemSize = 256 * 1024; // 256 KB
return CELL_OK;
}
error_code cellAdecOpen(vm::ptr<CellAdecType> type, vm::ptr<CellAdecResource> res, vm::ptr<CellAdecCb> cb, vm::ptr<u32> handle)
{
cellAdec.warning("cellAdecOpen(type=*0x%x, res=*0x%x, cb=*0x%x, handle=*0x%x)", type, res, cb, handle);
if (!adecCheckType(type->audioCodecType))
{
return CELL_ADEC_ERROR_ARG;
}
fmt::throw_exception("cellAdec disabled, use LLE.");
}
error_code cellAdecOpenEx(vm::ptr<CellAdecType> type, vm::ptr<CellAdecResourceEx> res, vm::ptr<CellAdecCb> cb, vm::ptr<u32> handle)
{
cellAdec.warning("cellAdecOpenEx(type=*0x%x, res=*0x%x, cb=*0x%x, handle=*0x%x)", type, res, cb, handle);
if (!adecCheckType(type->audioCodecType))
{
return CELL_ADEC_ERROR_ARG;
}
fmt::throw_exception("cellAdec disabled, use LLE.");
}
error_code cellAdecOpenExt(vm::ptr<CellAdecType> type, vm::ptr<CellAdecResourceEx> res, vm::ptr<CellAdecCb> cb, vm::ptr<u32> handle)
{
cellAdec.warning("cellAdecOpenExt(type=*0x%x, res=*0x%x, cb=*0x%x, handle=*0x%x)", type, res, cb, handle);
return cellAdecOpenEx(type, res, cb, handle);
}
error_code cellAdecClose(u32 handle)
{
cellAdec.warning("cellAdecClose(handle=0x%x)", handle);
const auto adec = idm::get<AudioDecoder>(handle);
if (!adec)
{
return CELL_ADEC_ERROR_ARG;
}
adec->is_closed = true;
adec->job.try_push(AdecTask(adecClose));
while (!adec->is_finished)
{
thread_ctrl::wait_for(1000); // hack
}
if (!idm::remove_verify<ppu_thread>(handle, std::move(adec)))
{
// Removed by other thread beforehead
return CELL_ADEC_ERROR_ARG;
}
return CELL_OK;
}
error_code cellAdecStartSeq(u32 handle, u32 param)
{
cellAdec.warning("cellAdecStartSeq(handle=0x%x, param=*0x%x)", handle, param);
const auto adec = idm::get<AudioDecoder>(handle);
if (!adec)
{
return CELL_ADEC_ERROR_ARG;
}
AdecTask task(adecStartSeq);
switch (adec->type)
{
case CELL_ADEC_TYPE_ATRACX:
case CELL_ADEC_TYPE_ATRACX_2CH:
case CELL_ADEC_TYPE_ATRACX_6CH:
case CELL_ADEC_TYPE_ATRACX_8CH:
{
const auto atx = vm::cptr<CellAdecParamAtracX>::make(param);
task.at3p.sample_rate = atx->sampling_freq;
task.at3p.channel_config = atx->ch_config_idx;
task.at3p.channels = atx->nch_out;
task.at3p.frame_size = atx->nbytes;
task.at3p.extra_config = atx->extra_config_data;
task.at3p.output = atx->bw_pcm;
task.at3p.downmix = atx->downmix_flag;
task.at3p.ats_header = atx->au_includes_ats_hdr_flg;
cellAdec.todo("*** CellAdecParamAtracX: sr=%d, ch_cfg=%d(%d), frame_size=0x%x, extra=%u:%u:%u:%u, output=%d, downmix=%d, ats_header=%d",
task.at3p.sample_rate, task.at3p.channel_config, task.at3p.channels, task.at3p.frame_size,
task.at3p.extra_config[0], task.at3p.extra_config[1], task.at3p.extra_config[2], task.at3p.extra_config[3],
task.at3p.output, task.at3p.downmix, task.at3p.ats_header);
break;
}
case CELL_ADEC_TYPE_MP3:
{
const auto mp3 = vm::cptr<CellAdecParamMP3>::make(param);
cellAdec.todo("*** CellAdecParamMP3: bw_pcm=%d", mp3->bw_pcm);
break;
}
default:
{
cellAdec.fatal("cellAdecStartSeq(): Unimplemented audio codec type(%d)", adec->type);
return CELL_OK;
}
}
adec->job.push(task, &adec->is_closed);
return CELL_OK;
}
error_code cellAdecEndSeq(u32 handle)
{
cellAdec.warning("cellAdecEndSeq(handle=0x%x)", handle);
const auto adec = idm::get<AudioDecoder>(handle);
if (!adec)
{
return CELL_ADEC_ERROR_ARG;
}
adec->job.push(AdecTask(adecEndSeq), &adec->is_closed);
return CELL_OK;
}
error_code cellAdecDecodeAu(u32 handle, vm::ptr<CellAdecAuInfo> auInfo)
{
cellAdec.trace("cellAdecDecodeAu(handle=0x%x, auInfo=*0x%x)", handle, auInfo);
const auto adec = idm::get<AudioDecoder>(handle);
if (!adec)
{
return CELL_ADEC_ERROR_ARG;
}
AdecTask task(adecDecodeAu);
task.au.auInfo_addr = auInfo.addr();
task.au.addr = auInfo->startAddr.addr();
task.au.size = auInfo->size;
task.au.pts = (u64{auInfo->pts.upper} << 32) | u64{auInfo->pts.lower};
task.au.userdata = auInfo->userData;
//cellAdec.notice("cellAdecDecodeAu(): addr=0x%x, size=0x%x, pts=0x%llx", task.au.addr, task.au.size, task.au.pts);
adec->job.push(task, &adec->is_closed);
return CELL_OK;
}
error_code cellAdecGetPcm(u32 handle, vm::ptr<float> outBuffer)
{
cellAdec.trace("cellAdecGetPcm(handle=0x%x, outBuffer=*0x%x)", handle, outBuffer);
const auto adec = idm::get<AudioDecoder>(handle);
if (!adec)
{
return CELL_ADEC_ERROR_ARG;
}
AdecFrame af;
if (!adec->frames.try_pop(af))
{
//std::this_thread::sleep_for(1ms); // hack
return CELL_ADEC_ERROR_EMPTY;
}
std::unique_ptr<AVFrame, void(*)(AVFrame*)> frame(af.data, [](AVFrame* frame)
{
av_frame_unref(frame);
av_frame_free(&frame);
});
if (outBuffer)
{
// reverse byte order:
if (frame->format == AV_SAMPLE_FMT_FLTP && frame->ch_layout.nb_channels == 1)
{
float* in_f = reinterpret_cast<float*>(frame->extended_data[0]);
for (u32 i = 0; i < af.size / 4; i++)
{
outBuffer[i] = in_f[i];
}
}
else if (frame->format == AV_SAMPLE_FMT_FLTP && frame->ch_layout.nb_channels == 2)
{
float* in_f[2];
in_f[0] = reinterpret_cast<float*>(frame->extended_data[0]);
in_f[1] = reinterpret_cast<float*>(frame->extended_data[1]);
for (u32 i = 0; i < af.size / 8; i++)
{
outBuffer[i * 2 + 0] = in_f[0][i];
outBuffer[i * 2 + 1] = in_f[1][i];
}
}
else if (frame->format == AV_SAMPLE_FMT_FLTP && frame->ch_layout.nb_channels == 6)
{
float* in_f[6];
in_f[0] = reinterpret_cast<float*>(frame->extended_data[0]);
in_f[1] = reinterpret_cast<float*>(frame->extended_data[1]);
in_f[2] = reinterpret_cast<float*>(frame->extended_data[2]);
in_f[3] = reinterpret_cast<float*>(frame->extended_data[3]);
in_f[4] = reinterpret_cast<float*>(frame->extended_data[4]);
in_f[5] = reinterpret_cast<float*>(frame->extended_data[5]);
for (u32 i = 0; i < af.size / 24; i++)
{
outBuffer[i * 6 + 0] = in_f[0][i];
outBuffer[i * 6 + 1] = in_f[1][i];
outBuffer[i * 6 + 2] = in_f[2][i];
outBuffer[i * 6 + 3] = in_f[3][i];
outBuffer[i * 6 + 4] = in_f[4][i];
outBuffer[i * 6 + 5] = in_f[5][i];
}
}
else if (frame->format == AV_SAMPLE_FMT_FLTP && frame->ch_layout.nb_channels == 8)
{
float* in_f[8];
in_f[0] = reinterpret_cast<float*>(frame->extended_data[0]);
in_f[1] = reinterpret_cast<float*>(frame->extended_data[1]);
in_f[2] = reinterpret_cast<float*>(frame->extended_data[2]);
in_f[3] = reinterpret_cast<float*>(frame->extended_data[3]);
in_f[4] = reinterpret_cast<float*>(frame->extended_data[4]);
in_f[5] = reinterpret_cast<float*>(frame->extended_data[5]);
in_f[6] = reinterpret_cast<float*>(frame->extended_data[6]);
in_f[7] = reinterpret_cast<float*>(frame->extended_data[7]);
for (u32 i = 0; i < af.size / 24; i++)
{
outBuffer[i * 8 + 0] = in_f[0][i];
outBuffer[i * 8 + 1] = in_f[1][i];
outBuffer[i * 8 + 2] = in_f[2][i];
outBuffer[i * 8 + 3] = in_f[3][i];
outBuffer[i * 8 + 4] = in_f[4][i];
outBuffer[i * 8 + 5] = in_f[5][i];
outBuffer[i * 8 + 6] = in_f[6][i];
outBuffer[i * 8 + 7] = in_f[7][i];
}
}
else if (frame->format == AV_SAMPLE_FMT_S16P && frame->ch_layout.nb_channels == 1)
{
s16* in_i = reinterpret_cast<s16*>(frame->extended_data[0]);
for (u32 i = 0; i < af.size / 2; i++)
{
outBuffer[i] = in_i[i] / 32768.f;
}
}
else if (frame->format == AV_SAMPLE_FMT_S16P && frame->ch_layout.nb_channels == 2)
{
s16* in_i[2];
in_i[0] = reinterpret_cast<s16*>(frame->extended_data[0]);
in_i[1] = reinterpret_cast<s16*>(frame->extended_data[1]);
for (u32 i = 0; i < af.size / 4; i++)
{
outBuffer[i * 2 + 0] = in_i[0][i] / 32768.f;
outBuffer[i * 2 + 1] = in_i[1][i] / 32768.f;
}
}
else
{
fmt::throw_exception("Unsupported frame format (channels=%d, format=%d)", frame->ch_layout.nb_channels, frame->format);
}
}
return CELL_OK;
}
error_code cellAdecGetPcmItem(u32 handle, vm::pptr<CellAdecPcmItem> pcmItem)
{
cellAdec.trace("cellAdecGetPcmItem(handle=0x%x, pcmItem=**0x%x)", handle, pcmItem);
const auto adec = idm::get<AudioDecoder>(handle);
if (!adec)
{
return CELL_ADEC_ERROR_ARG;
}
AdecFrame af;
if (!adec->frames.try_peek(af))
{
//std::this_thread::sleep_for(1ms); // hack
return CELL_ADEC_ERROR_EMPTY;
}
AVFrame* frame = af.data;
const auto pcm = vm::ptr<CellAdecPcmItem>::make(adec->memAddr + adec->memBias);
adec->memBias += 512;
if (adec->memBias + 512 > adec->memSize)
{
adec->memBias = 0;
}
pcm->pcmHandle = 0; // ???
pcm->pcmAttr.bsiInfo_addr = pcm.addr() + u32{sizeof(CellAdecPcmItem)};
pcm->startAddr = 0x00000312; // invalid address (no output)
pcm->size = af.size;
pcm->status = CELL_OK;
pcm->auInfo.pts.lower = static_cast<u32>(af.pts);
pcm->auInfo.pts.upper = static_cast<u32>(af.pts >> 32);
pcm->auInfo.size = af.auSize;
pcm->auInfo.startAddr.set(af.auAddr);
pcm->auInfo.userData = af.userdata;
if (adecIsAtracX(adec->type))
{
auto atx = vm::ptr<CellAdecAtracXInfo>::make(pcm.addr() + u32{sizeof(CellAdecPcmItem)});
atx->samplingFreq = frame->sample_rate;
atx->nbytes = frame->nb_samples * u32{sizeof(float)};
switch (frame->ch_layout.nb_channels)
{
case 1:
case 2:
case 6:
{
atx->channelConfigIndex = frame->ch_layout.nb_channels;
break;
}
case 8:
{
atx->channelConfigIndex = 7;
break;
}
default:
{
cellAdec.fatal("cellAdecGetPcmItem(): unsupported channel count (%d)", frame->ch_layout.nb_channels);
break;
}
}
}
else if (adec->type == CELL_ADEC_TYPE_MP3)
{
auto mp3 = vm::ptr<CellAdecMP3Info>::make(pcm.addr() + u32{sizeof(CellAdecPcmItem)});
// TODO
memset(mp3.get_ptr(), 0, sizeof(CellAdecMP3Info));
}
*pcmItem = pcm;
return CELL_OK;
}
DECLARE(ppu_module_manager::cellAdec)("cellAdec", []()
{
static ppu_static_module cell_libac3dec("cell_libac3dec");
static ppu_static_module cellAtrac3dec("cellAtrac3dec");
static ppu_static_module cellCelpDec("cellCelpDec");
static ppu_static_module cellDTSdec("cellDTSdec");
static ppu_static_module cellM2AACdec("cellM2AACdec");
static ppu_static_module cellM2BCdec("cellM2BCdec");
static ppu_static_module cellM4AacDec("cellM4AacDec");
static ppu_static_module cellMP3dec("cellMP3dec");
static ppu_static_module cellTRHDdec("cellTRHDdec");
static ppu_static_module cellWMAdec("cellWMAdec");
static ppu_static_module cellDTSLBRdec("cellDTSLBRdec");
static ppu_static_module cellDDPdec("cellDDPdec");
static ppu_static_module cellM4AacDec2ch("cellM4AacDec2ch");
static ppu_static_module cellDTSHDdec("cellDTSHDdec");
static ppu_static_module cellMPL1dec("cellMPL1dec");
static ppu_static_module cellMP3Sdec("cellMP3Sdec");
static ppu_static_module cellM4AacDec2chmod("cellM4AacDec2chmod");
static ppu_static_module cellCelp8Dec("cellCelp8Dec");
static ppu_static_module cellWMAPROdec("cellWMAPROdec");
static ppu_static_module cellWMALSLdec("cellWMALSLdec");
static ppu_static_module cellDTSHDCOREdec("cellDTSHDCOREdec");
static ppu_static_module cellAtrac3multidec("cellAtrac3multidec");
REG_FUNC(cellAdec, cellAdecQueryAttr);
REG_FUNC(cellAdec, cellAdecOpen);
REG_FUNC(cellAdec, cellAdecOpenEx);
REG_FUNC(cellAdec, cellAdecOpenExt); // 0xdf982d2c
REG_FUNC(cellAdec, cellAdecClose);
REG_FUNC(cellAdec, cellAdecStartSeq);
REG_FUNC(cellAdec, cellAdecEndSeq);
REG_FUNC(cellAdec, cellAdecDecodeAu);
REG_FUNC(cellAdec, cellAdecGetPcm);
REG_FUNC(cellAdec, cellAdecGetPcmItem);
});
| 31,515
|
C++
|
.cpp
| 968
| 29.082645
| 152
| 0.684233
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| false
| false
|
5,269
|
cellFs.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellFs.cpp
|
#include "stdafx.h"
#include "Emu/VFS.h"
#include "Emu/IdManager.h"
#include "Emu/Cell/PPUModule.h"
#include "Emu/Cell/lv2/sys_fs.h"
#include "Emu/Cell/lv2/sys_sync.h"
#include "cellFs.h"
#include <mutex>
LOG_CHANNEL(cellFs);
error_code cellFsGetPath(ppu_thread& ppu, u32 fd, vm::ptr<char> out_path)
{
cellFs.trace("cellFsGetPath(fd=%d, out_path=*0x%x)", fd, out_path);
if (!out_path)
{
return CELL_EFAULT;
}
return sys_fs_test(ppu, 6, 0, vm::var<u32>{fd}, sizeof(u32), out_path, 0x420);
}
error_code cellFsOpen(ppu_thread& ppu, vm::cptr<char> path, s32 flags, vm::ptr<u32> fd, vm::cptr<void> arg, u64 size)
{
cellFs.trace("cellFsOpen(path=%s, flags=%#o, fd=*0x%x, arg=*0x%x, size=0x%llx)", path, flags, fd, arg, size);
if (!fd)
{
return CELL_EFAULT;
}
// TODO
return sys_fs_open(ppu, path, flags, fd, flags & CELL_FS_O_CREAT ? CELL_FS_S_IRUSR | CELL_FS_S_IWUSR : 0, arg, size);
}
error_code cellFsOpen2()
{
UNIMPLEMENTED_FUNC(cellFs);
return CELL_OK;
}
error_code cellFsSdataOpen(ppu_thread& ppu, vm::cptr<char> path, s32 flags, vm::ptr<u32> fd, vm::cptr<void> arg, u64 size)
{
cellFs.trace("cellFsSdataOpen(path=%s, flags=%#o, fd=*0x%x, arg=*0x%x, size=0x%llx)", path, flags, fd, arg, size);
if (flags != CELL_FS_O_RDONLY)
{
return CELL_EINVAL;
}
return cellFsOpen(ppu, path, CELL_FS_O_RDONLY, fd, vm::make_var<be_t<u32>[2]>({0x180, 0x10}), 8);
}
error_code cellFsRead(ppu_thread& ppu, u32 fd, vm::ptr<void> buf, u64 nbytes, vm::ptr<u64> nread)
{
cellFs.trace("cellFsRead(fd=0x%x, buf=0x%x, nbytes=0x%llx, nread=0x%x)", fd, buf, nbytes, nread);
return sys_fs_read(ppu, fd, buf, nbytes, nread ? nread : vm::var<u64>{});
}
error_code cellFsWrite(ppu_thread& ppu, u32 fd, vm::cptr<void> buf, u64 nbytes, vm::ptr<u64> nwrite)
{
cellFs.trace("cellFsWrite(fd=0x%x, buf=*0x%x, nbytes=0x%llx, nwrite=*0x%x)", fd, buf, nbytes, nwrite);
return sys_fs_write(ppu, fd, buf, nbytes, nwrite ? nwrite : vm::var<u64>{});
}
error_code cellFsClose(ppu_thread& ppu, u32 fd)
{
cellFs.trace("cellFsClose(fd=0x%x)", fd);
return sys_fs_close(ppu, fd);
}
error_code cellFsOpendir(ppu_thread& ppu, vm::cptr<char> path, vm::ptr<u32> fd)
{
cellFs.trace("cellFsOpendir(path=%s, fd=*0x%x)", path, fd);
if (!fd)
{
return CELL_EFAULT;
}
// TODO
return sys_fs_opendir(ppu, path, fd);
}
error_code cellFsReaddir(ppu_thread& ppu, u32 fd, vm::ptr<CellFsDirent> dir, vm::ptr<u64> nread)
{
cellFs.trace("cellFsReaddir(fd=0x%x, dir=*0x%x, nread=*0x%x)", fd, dir, nread);
if (!dir || !nread)
{
return CELL_EFAULT;
}
return sys_fs_readdir(ppu, fd, dir, nread);
}
error_code cellFsClosedir(ppu_thread& ppu, u32 fd)
{
cellFs.trace("cellFsClosedir(fd=0x%x)", fd);
return sys_fs_closedir(ppu, fd);
}
error_code cellFsStat(ppu_thread& ppu, vm::cptr<char> path, vm::ptr<CellFsStat> sb)
{
cellFs.trace("cellFsStat(path=%s, sb=*0x%x)", path, sb);
if (!sb)
{
return CELL_EFAULT;
}
// TODO
return sys_fs_stat(ppu, path, sb);
}
error_code cellFsFstat(ppu_thread& ppu, u32 fd, vm::ptr<CellFsStat> sb)
{
cellFs.trace("cellFsFstat(fd=0x%x, sb=*0x%x)", fd, sb);
return sys_fs_fstat(ppu, fd, sb);
}
error_code cellFsLink()
{
UNIMPLEMENTED_FUNC(cellFs);
return CELL_OK;
}
error_code cellFsMkdir(ppu_thread& ppu, vm::cptr<char> path, s32 mode)
{
cellFs.trace("cellFsMkdir(path=%s, mode=%#o)", path, mode);
// TODO
return sys_fs_mkdir(ppu, path, mode);
}
error_code cellFsRename(ppu_thread& ppu, vm::cptr<char> from, vm::cptr<char> to)
{
cellFs.trace("cellFsRename(from=%s, to=%s)", from, to);
// TODO
return sys_fs_rename(ppu, from, to);
}
error_code cellFsRmdir(ppu_thread& ppu, vm::cptr<char> path)
{
cellFs.trace("cellFsRmdir(path=%s)", path);
// TODO
return sys_fs_rmdir(ppu, path);
}
error_code cellFsUnlink(ppu_thread& ppu, vm::cptr<char> path)
{
cellFs.trace("cellFsUnlink(path=%s)", path);
// TODO
return sys_fs_unlink(ppu, path);
}
error_code cellFsUtime(ppu_thread& ppu, vm::cptr<char> path, vm::cptr<CellFsUtimbuf> timep)
{
cellFs.trace("cellFsUtime(path=%s, timep=*0x%x)", path, timep);
if (!timep)
{
return CELL_EFAULT;
}
// TODO
return sys_fs_utime(ppu, path, timep);
}
error_code cellFsAccess()
{
UNIMPLEMENTED_FUNC(cellFs);
return CELL_OK;
}
error_code cellFsFcntl()
{
UNIMPLEMENTED_FUNC(cellFs);
return CELL_OK;
}
error_code cellFsLseek(ppu_thread& ppu, u32 fd, s64 offset, u32 whence, vm::ptr<u64> pos)
{
cellFs.trace("cellFsLseek(fd=0x%x, offset=0x%llx, whence=0x%x, pos=*0x%x)", fd, offset, whence, pos);
if (!pos)
{
return CELL_EFAULT;
}
return sys_fs_lseek(ppu, fd, offset, whence, pos);
}
error_code cellFsFdatasync(ppu_thread& ppu, u32 fd)
{
cellFs.trace("cellFsFdatasync(fd=%d)", fd);
return sys_fs_fdatasync(ppu, fd);
}
error_code cellFsFsync(ppu_thread& ppu, u32 fd)
{
cellFs.trace("cellFsFsync(fd=%d)", fd);
return sys_fs_fsync(ppu, fd);
}
error_code cellFsFGetBlockSize(ppu_thread& ppu, u32 fd, vm::ptr<u64> sector_size, vm::ptr<u64> block_size)
{
cellFs.trace("cellFsFGetBlockSize(fd=0x%x, sector_size=*0x%x, block_size=*0x%x)", fd, sector_size, block_size);
if (!sector_size || !block_size)
{
return CELL_EFAULT;
}
return sys_fs_fget_block_size(ppu, fd, sector_size, block_size, vm::var<u64>{}, vm::var<s32>{});
}
error_code cellFsFGetBlockSize2()
{
UNIMPLEMENTED_FUNC(cellFs);
return CELL_OK;
}
error_code cellFsGetBlockSize(ppu_thread& ppu, vm::cptr<char> path, vm::ptr<u64> sector_size, vm::ptr<u64> block_size)
{
cellFs.trace("cellFsGetBlockSize(path=%s, sector_size=*0x%x, block_size=*0x%x)", path, sector_size, block_size);
if (!path || !sector_size || !block_size)
{
return CELL_EFAULT;
}
// TODO
return sys_fs_get_block_size(ppu, path, sector_size, block_size, vm::var<u64>{});
}
error_code cellFsGetBlockSize2()
{
UNIMPLEMENTED_FUNC(cellFs);
return CELL_OK;
}
error_code cellFsAclRead()
{
UNIMPLEMENTED_FUNC(cellFs);
return CELL_OK;
}
error_code cellFsAclWrite()
{
UNIMPLEMENTED_FUNC(cellFs);
return CELL_OK;
}
error_code cellFsLsnGetCDASize()
{
UNIMPLEMENTED_FUNC(cellFs);
return CELL_OK;
}
error_code cellFsLsnGetCDA()
{
UNIMPLEMENTED_FUNC(cellFs);
return CELL_OK;
}
error_code cellFsLsnLock()
{
UNIMPLEMENTED_FUNC(cellFs);
return CELL_OK;
}
error_code cellFsLsnUnlock()
{
UNIMPLEMENTED_FUNC(cellFs);
return CELL_OK;
}
error_code cellFsLsnRead()
{
UNIMPLEMENTED_FUNC(cellFs);
return CELL_OK;
}
error_code cellFsLsnRead2()
{
UNIMPLEMENTED_FUNC(cellFs);
return CELL_OK;
}
error_code cellFsTruncate(ppu_thread& ppu, vm::cptr<char> path, u64 size)
{
cellFs.trace("cellFsTruncate(path=%s, size=0x%llx)", path, size);
// TODO
return sys_fs_truncate(ppu, path, size);
}
error_code cellFsFtruncate(ppu_thread& ppu, u32 fd, u64 size)
{
cellFs.trace("cellFsFtruncate(fd=0x%x, size=0x%llx)", fd, size);
return sys_fs_ftruncate(ppu, fd, size);
}
error_code cellFsSymbolicLink()
{
UNIMPLEMENTED_FUNC(cellFs);
return CELL_OK;
}
error_code cellFsChmod(ppu_thread& ppu, vm::cptr<char> path, s32 mode)
{
cellFs.trace("cellFsChmod(path=%s, mode=%#o)", path, mode);
// TODO
return sys_fs_chmod(ppu, path, mode);
}
error_code cellFsChown()
{
UNIMPLEMENTED_FUNC(cellFs);
return CELL_OK;
}
error_code cellFsGetFreeSize(ppu_thread& ppu, vm::cptr<char> path, vm::ptr<u32> block_size, vm::ptr<u64> block_count)
{
cellFs.todo("cellFsGetFreeSize(path=%s, block_size=*0x%x, block_count=*0x%x)", path, block_size, block_count);
if (!path || !block_size || !block_count)
{
return CELL_EFAULT;
}
*block_size = 0;
*block_count = 0;
vm::var<lv2_file_c0000002> op;
op->_vtable = vm::cast(0xfae12000);
op->op = 0xC0000002;
op->out_code = 0x80010003;
op->path = path;
if (!std::strncmp(path.get_ptr(), "/dev_hdd0", 9))
{
sys_fs_fcntl(ppu, -1, 0xC0000002, op, sizeof(*op));
*block_count = op->out_block_count;
*block_size = op->out_block_size;
}
else
{
vm::var<u64> _block_size, avail;
if (auto err = sys_fs_disk_free(ppu, path, vm::var<u64>{}, avail))
{
if (err + 0u == CELL_EPERM)
{
return not_an_error(CELL_EINVAL);
}
return err;
}
if (!*avail)
{
return CELL_ENOTDIR;
}
if (auto err = cellFsGetBlockSize(ppu, path, vm::var<u64>{}, _block_size))
{
return err;
}
*block_count = *avail / *_block_size;
*block_size = ::narrow<u32>(*_block_size);
}
return CELL_OK;
}
error_code cellFsMappedAllocate()
{
UNIMPLEMENTED_FUNC(cellFs);
return CELL_OK;
}
error_code cellFsMappedFree()
{
UNIMPLEMENTED_FUNC(cellFs);
return CELL_OK;
}
error_code cellFsTruncate2()
{
UNIMPLEMENTED_FUNC(cellFs);
return CELL_OK;
}
error_code cellFsGetDirectoryEntries(ppu_thread& ppu, u32 fd, vm::ptr<CellFsDirectoryEntry> entries, u32 entries_size, vm::ptr<u32> data_count)
{
cellFs.trace("cellFsGetDirectoryEntries(fd=%d, entries=*0x%x, entries_size=0x%x, data_count=*0x%x)", fd, entries, entries_size, data_count);
if (!data_count || !entries)
{
return CELL_EFAULT;
}
if (fd - 3 > 252)
{
return CELL_EBADF;
}
vm::var<lv2_file_op_dir> op;
op->_vtable = vm::cast(0xfae12000); // Intentionally wrong (provide correct vtable if necessary)
op->op = 0xe0000012;
op->arg._code = 0;
op->arg._size = 0;
op->arg.ptr = entries;
op->arg.max = entries_size / sizeof(CellFsDirectoryEntry);
const s32 rc = sys_fs_fcntl(ppu, fd, 0xe0000012, op.ptr(&lv2_file_op_dir::arg), 0x10);
*data_count = op->arg._size;
if (!rc && op->arg._code)
{
return CellError(+op->arg._code);
}
return not_an_error(rc);
}
error_code cellFsReadWithOffset(ppu_thread& ppu, u32 fd, u64 offset, vm::ptr<void> buf, u64 buffer_size, vm::ptr<u64> nread)
{
cellFs.trace("cellFsReadWithOffset(fd=%d, offset=0x%llx, buf=*0x%x, buffer_size=0x%llx, nread=*0x%x)", fd, offset, buf, buffer_size, nread);
if (fd - 3 > 252)
{
if (nread) *nread = 0;
return CELL_EBADF;
}
vm::var<lv2_file_op_rw> arg;
arg->_vtable = vm::cast(0xfa8a0000); // Intentionally wrong (provide correct vtable if necessary)
arg->op = 0x8000000a;
arg->fd = fd;
arg->buf = buf;
arg->offset = offset;
arg->size = buffer_size;
const s32 rc = sys_fs_fcntl(ppu, fd, 0x8000000a, arg, arg.size());
// Write size read
if (nread)
{
*nread = rc && rc + 0u != CELL_EFSSPECIFIC ? 0 : arg->out_size.value();
}
if (!rc && arg->out_code)
{
return CellError(+arg->out_code);
}
return not_an_error(rc);
}
error_code cellFsWriteWithOffset(ppu_thread& ppu, u32 fd, u64 offset, vm::cptr<void> buf, u64 data_size, vm::ptr<u64> nwrite)
{
cellFs.trace("cellFsWriteWithOffset(fd=%d, offset=0x%llx, buf=*0x%x, data_size=0x%llx, nwrite=*0x%x)", fd, offset, buf, data_size, nwrite);
if (!buf)
{
if (nwrite) *nwrite = 0;
return CELL_EFAULT;
}
if (fd - 3 > 252)
{
if (nwrite) *nwrite = 0;
return CELL_EBADF;
}
vm::var<lv2_file_op_rw> arg;
arg->_vtable = vm::cast(0xfa8b0000); // Intentionally wrong (provide correct vtable if necessary)
arg->op = 0x8000000b;
arg->fd = fd;
arg->buf = vm::const_ptr_cast<void>(buf);
arg->offset = offset;
arg->size = data_size;
const s32 rc = sys_fs_fcntl(ppu, fd, 0x8000000b, arg, arg.size());
// Write size written
if (nwrite)
{
*nwrite = rc && rc + 0u != CELL_EFSSPECIFIC ? 0 : arg->out_size.value();
}
if (!rc && arg->out_code)
{
return CellError(+arg->out_code);
}
return not_an_error(rc);
}
error_code cellFsSdataOpenByFd(ppu_thread& ppu, u32 mself_fd, s32 flags, vm::ptr<u32> sdata_fd, u64 offset, vm::cptr<void> arg, u64 size)
{
cellFs.trace("cellFsSdataOpenByFd(mself_fd=0x%x, flags=%#o, sdata_fd=*0x%x, offset=0x%llx, arg=*0x%x, size=0x%llx)", mself_fd, flags, sdata_fd, offset, arg, size);
if (!sdata_fd)
{
return CELL_EFAULT;
}
*sdata_fd = -1;
if (mself_fd < 3 || mself_fd > 255)
{
return CELL_EBADF;
}
if (flags)
{
return CELL_EINVAL;
}
vm::var<lv2_file_op_09> ctrl;
ctrl->_vtable = vm::cast(0xfa880000); // Intentionally wrong (provide correct vtable if necessary)
ctrl->op = 0x80000009;
ctrl->fd = mself_fd;
ctrl->offset = offset;
ctrl->_vtabl2 = vm::cast(0xfa880020);
ctrl->arg1 = 0x180;
ctrl->arg2 = 0x10;
ctrl->arg_ptr = arg.addr();
ctrl->arg_size = u32(size);
if (const s32 rc = sys_fs_fcntl(ppu, mself_fd, 0x80000009, ctrl, 0x40))
{
return not_an_error(rc);
}
if (const s32 rc = ctrl->out_code)
{
return CellError(rc);
}
*sdata_fd = ctrl->out_fd;
return CELL_OK;
}
error_code cellFsSdataOpenWithVersion()
{
UNIMPLEMENTED_FUNC(cellFs);
return CELL_OK;
}
error_code cellFsSetAttribute()
{
UNIMPLEMENTED_FUNC(cellFs);
return CELL_OK;
}
error_code cellFsSetDefaultContainer(u32 id, u32 total_limit)
{
cellFs.todo("cellFsSetDefaultContainer(id=0x%x, total_limit=%u)", id, total_limit);
return CELL_OK;
}
error_code cellFsSetIoBuffer()
{
UNIMPLEMENTED_FUNC(cellFs);
return CELL_OK;
}
error_code cellFsSetIoBufferFromDefaultContainer(u32 fd, u32 buffer_size, u32 page_type)
{
cellFs.todo("cellFsSetIoBufferFromDefaultContainer(fd=%d, buffer_size=%d, page_type=%d)", fd, buffer_size, page_type);
const auto file = idm::get<lv2_fs_object, lv2_file>(fd);
if (!file)
{
return CELL_EBADF;
}
return CELL_OK;
}
error_code cellFsAllocateFileAreaWithInitialData()
{
UNIMPLEMENTED_FUNC(cellFs);
return CELL_OK;
}
error_code cellFsAllocateFileAreaByFdWithoutZeroFill()
{
UNIMPLEMENTED_FUNC(cellFs);
return CELL_OK;
}
error_code cellFsAllocateFileAreaByFdWithInitialData()
{
UNIMPLEMENTED_FUNC(cellFs);
return CELL_OK;
}
error_code cellFsAllocateFileAreaWithoutZeroFill(ppu_thread& ppu, vm::cptr<char> path, u64 size)
{
cellFs.trace("cellFsAllocateFileAreaWithoutZeroFill(path=%s, size=0x%llx)", path, size);
if (!path)
{
return CELL_EFAULT;
}
vm::var<lv2_file_e0000017> ctrl;
ctrl->size = ctrl.size();
ctrl->_x4 = 0x10;
ctrl->_x8 = 0x20;
ctrl->file_path = path;
ctrl->file_size = size;
ctrl->out_code = CELL_ENOSYS;
// TODO
if (s32 rc = sys_fs_fcntl(ppu, -1, 0xe0000017, ctrl, ctrl->size))
{
return not_an_error(rc);
}
if (s32 rc = ctrl->out_code)
{
return CellError(rc);
}
return CELL_OK;
}
error_code cellFsChangeFileSizeWithoutAllocation()
{
UNIMPLEMENTED_FUNC(cellFs);
return CELL_OK;
}
error_code cellFsChangeFileSizeByFdWithoutAllocation()
{
UNIMPLEMENTED_FUNC(cellFs);
return CELL_OK;
}
error_code cellFsSetDiscReadRetrySetting()
{
UNIMPLEMENTED_FUNC(cellFs);
return CELL_OK;
}
s32 cellFsStReadInit(u32 fd, vm::cptr<CellFsRingBuffer> ringbuf)
{
cellFs.todo("cellFsStReadInit(fd=%d, ringbuf=*0x%x)", fd, ringbuf);
if (ringbuf->copy & ~CELL_FS_ST_COPYLESS)
{
return CELL_EINVAL;
}
if (ringbuf->block_size & 0xfff) // check if a multiple of sector size
{
return CELL_EINVAL;
}
if (ringbuf->ringbuf_size % ringbuf->block_size) // check if a multiple of block_size
{
return CELL_EINVAL;
}
const auto file = idm::get<lv2_fs_object, lv2_file>(fd);
if (!file)
{
return CELL_EBADF;
}
if (file->flags & CELL_FS_O_WRONLY)
{
return CELL_EPERM;
}
// TODO
return CELL_OK;
}
s32 cellFsStReadFinish(u32 fd)
{
cellFs.todo("cellFsStReadFinish(fd=%d)", fd);
const auto file = idm::get<lv2_fs_object, lv2_file>(fd);
if (!file)
{
return CELL_EBADF; // ???
}
// TODO
return CELL_OK;
}
s32 cellFsStReadGetRingBuf(u32 fd, vm::ptr<CellFsRingBuffer> ringbuf)
{
cellFs.todo("cellFsStReadGetRingBuf(fd=%d, ringbuf=*0x%x)", fd, ringbuf);
const auto file = idm::get<lv2_fs_object, lv2_file>(fd);
if (!file)
{
return CELL_EBADF;
}
// TODO
return CELL_OK;
}
s32 cellFsStReadGetStatus(u32 fd, vm::ptr<u64> status)
{
cellFs.todo("cellFsStReadGetRingBuf(fd=%d, status=*0x%x)", fd, status);
const auto file = idm::get<lv2_fs_object, lv2_file>(fd);
if (!file)
{
return CELL_EBADF;
}
// TODO
return CELL_OK;
}
s32 cellFsStReadGetRegid(u32 fd, vm::ptr<u64> regid)
{
cellFs.todo("cellFsStReadGetRingBuf(fd=%d, regid=*0x%x)", fd, regid);
const auto file = idm::get<lv2_fs_object, lv2_file>(fd);
if (!file)
{
return CELL_EBADF;
}
// TODO
return CELL_OK;
}
s32 cellFsStReadStart(u32 fd, u64 offset, u64 size)
{
cellFs.todo("cellFsStReadStart(fd=%d, offset=0x%llx, size=0x%llx)", fd, offset, size);
const auto file = idm::get<lv2_fs_object, lv2_file>(fd);
if (!file)
{
return CELL_EBADF;
}
// TODO
return CELL_OK;
}
s32 cellFsStReadStop(u32 fd)
{
cellFs.todo("cellFsStReadStop(fd=%d)", fd);
const auto file = idm::get<lv2_fs_object, lv2_file>(fd);
if (!file)
{
return CELL_EBADF;
}
// TODO
return CELL_OK;
}
s32 cellFsStRead(u32 fd, vm::ptr<u8> buf, u64 size, vm::ptr<u64> rsize)
{
cellFs.todo("cellFsStRead(fd=%d, buf=*0x%x, size=0x%llx, rsize=*0x%x)", fd, buf, size, rsize);
const auto file = idm::get<lv2_fs_object, lv2_file>(fd);
if (!file)
{
return CELL_EBADF;
}
// TODO
return CELL_OK;
}
s32 cellFsStReadGetCurrentAddr(u32 fd, vm::ptr<u32> addr, vm::ptr<u64> size)
{
cellFs.todo("cellFsStReadGetCurrentAddr(fd=%d, addr=*0x%x, size=*0x%x)", fd, addr, size);
const auto file = idm::get<lv2_fs_object, lv2_file>(fd);
if (!file)
{
return CELL_EBADF;
}
// TODO
return CELL_OK;
}
s32 cellFsStReadPutCurrentAddr(u32 fd, vm::ptr<u8> addr, u64 size)
{
cellFs.todo("cellFsStReadPutCurrentAddr(fd=%d, addr=*0x%x, size=0x%llx)", fd, addr, size);
const auto file = idm::get<lv2_fs_object, lv2_file>(fd);
if (!file)
{
return CELL_EBADF;
}
// TODO
return CELL_OK;
}
s32 cellFsStReadWait(u32 fd, u64 size)
{
cellFs.todo("cellFsStReadWait(fd=%d, size=0x%llx)", fd, size);
const auto file = idm::get<lv2_fs_object, lv2_file>(fd);
if (!file)
{
return CELL_EBADF;
}
// TODO
return CELL_OK;
}
s32 cellFsStReadWaitCallback(u32 fd, u64 size, vm::ptr<void(s32 xfd, u64 xsize)> func)
{
cellFs.todo("cellFsStReadWaitCallback(fd=%d, size=0x%llx, func=*0x%x)", fd, size, func);
const auto file = idm::get<lv2_fs_object, lv2_file>(fd);
if (!file)
{
return CELL_EBADF;
}
// TODO
return CELL_OK;
}
using fs_aio_cb_t = vm::ptr<void(vm::ptr<CellFsAio> xaio, s32 error, s32 xid, u64 size)>;
struct fs_aio_thread : ppu_thread
{
using ppu_thread::ppu_thread;
void non_task()
{
while (cmd64 cmd = cmd_wait())
{
const u32 type = cmd.arg1<u32>();
const s32 xid = cmd.arg2<s32>();
const cmd64 cmd2 = cmd_get(1);
const auto aio = cmd2.arg1<vm::ptr<CellFsAio>>();
const auto func = cmd2.arg2<fs_aio_cb_t>();
cmd_pop(1);
s32 error = CELL_EBADF;
u64 result = 0;
const auto file = idm::get<lv2_fs_object, lv2_file>(aio->fd);
if (!file || (type == 1 && file->flags & CELL_FS_O_WRONLY) || (type == 2 && !(file->flags & CELL_FS_O_ACCMODE)))
{
}
else if (std::lock_guard lock(file->mp->mutex); file->file)
{
const auto old_pos = file->file.pos(); file->file.seek(aio->offset);
result = type == 2
? file->op_write(aio->buf, aio->size)
: file->op_read(aio->buf, aio->size);
file->file.seek(old_pos);
error = CELL_OK;
}
func(*this, aio, error, xid, result);
lv2_obj::sleep(*this);
}
}
};
struct fs_aio_manager
{
std::shared_ptr<fs_aio_thread> thread;
shared_mutex mutex;
};
s32 cellFsAioInit(vm::cptr<char> mount_point)
{
cellFs.warning("cellFsAioInit(mount_point=%s)", mount_point);
// TODO: create AIO thread (if not exists) for specified mount point
cellFs.fatal("cellFsAio disabled, use LLE.");
return CELL_OK;
}
s32 cellFsAioFinish(vm::cptr<char> mount_point)
{
cellFs.warning("cellFsAioFinish(mount_point=%s)", mount_point);
// TODO: delete existing AIO thread for specified mount point
return CELL_OK;
}
atomic_t<s32> g_fs_aio_id;
s32 cellFsAioRead(vm::ptr<CellFsAio> aio, vm::ptr<s32> id, fs_aio_cb_t func)
{
cellFs.warning("cellFsAioRead(aio=*0x%x, id=*0x%x, func=*0x%x)", aio, id, func);
// TODO: detect mount point and send AIO request to the AIO thread of this mount point
auto& m = g_fxo->get<fs_aio_manager>();
if (!m.thread)
{
return CELL_ENXIO;
}
const s32 xid = (*id = ++g_fs_aio_id);
m.thread->cmd_list
({
{ 1, xid },
{ aio, func },
});
return CELL_OK;
}
s32 cellFsAioWrite(vm::ptr<CellFsAio> aio, vm::ptr<s32> id, fs_aio_cb_t func)
{
cellFs.warning("cellFsAioWrite(aio=*0x%x, id=*0x%x, func=*0x%x)", aio, id, func);
// TODO: detect mount point and send AIO request to the AIO thread of this mount point
auto& m = g_fxo->get<fs_aio_manager>();
if (!m.thread)
{
return CELL_ENXIO;
}
const s32 xid = (*id = ++g_fs_aio_id);
m.thread->cmd_list
({
{ 2, xid },
{ aio, func },
});
return CELL_OK;
}
s32 cellFsAioCancel(s32 id)
{
cellFs.todo("cellFsAioCancel(id=%d) -> CELL_EINVAL", id);
// TODO: cancelled requests return CELL_ECANCELED through their own callbacks
return CELL_EINVAL;
}
s32 cellFsArcadeHddSerialNumber()
{
cellFs.todo("cellFsArcadeHddSerialNumber()");
return CELL_OK;
}
s32 cellFsRegisterConversionCallback()
{
cellFs.todo("cellFsRegisterConversionCallback()");
return CELL_OK;
}
s32 cellFsUnregisterL10nCallbacks()
{
cellFs.todo("cellFsUnregisterL10nCallbacks()");
return CELL_OK;
}
DECLARE(ppu_module_manager::cellFs)("sys_fs", []()
{
REG_FUNC(sys_fs, cellFsAccess);
REG_FUNC(sys_fs, cellFsAclRead);
REG_FUNC(sys_fs, cellFsAclWrite);
REG_FUNC(sys_fs, cellFsAioCancel);
REG_FUNC(sys_fs, cellFsAioFinish);
REG_FUNC(sys_fs, cellFsAioInit);
REG_FUNC(sys_fs, cellFsAioRead);
REG_FUNC(sys_fs, cellFsAioWrite);
REG_FUNC(sys_fs, cellFsAllocateFileAreaByFdWithInitialData);
REG_FUNC(sys_fs, cellFsAllocateFileAreaByFdWithoutZeroFill);
REG_FUNC(sys_fs, cellFsAllocateFileAreaWithInitialData);
REG_FUNC(sys_fs, cellFsAllocateFileAreaWithoutZeroFill);
REG_FUNC(sys_fs, cellFsArcadeHddSerialNumber);
REG_FUNC(sys_fs, cellFsChangeFileSizeByFdWithoutAllocation);
REG_FUNC(sys_fs, cellFsChangeFileSizeWithoutAllocation);
REG_FUNC(sys_fs, cellFsChmod);
REG_FUNC(sys_fs, cellFsChown);
REG_FUNC(sys_fs, cellFsClose).flag(MFF_PERFECT);
REG_FUNC(sys_fs, cellFsClosedir).flag(MFF_PERFECT);
REG_FUNC(sys_fs, cellFsFcntl);
REG_FUNC(sys_fs, cellFsFdatasync);
REG_FUNC(sys_fs, cellFsFGetBlockSize).flag(MFF_PERFECT);
REG_FUNC(sys_fs, cellFsFGetBlockSize2);
REG_FUNC(sys_fs, cellFsFstat).flags = MFF_PERFECT;
REG_FUNC(sys_fs, cellFsFsync);
REG_FUNC(sys_fs, cellFsFtruncate).flag(MFF_PERFECT);
REG_FUNC(sys_fs, cellFsGetBlockSize);
REG_FUNC(sys_fs, cellFsGetBlockSize2);
REG_FUNC(sys_fs, cellFsGetDirectoryEntries);
REG_FUNC(sys_fs, cellFsGetFreeSize);
REG_FUNC(sys_fs, cellFsGetPath);
REG_FUNC(sys_fs, cellFsLink);
REG_FUNC(sys_fs, cellFsLseek).flag(MFF_PERFECT);
REG_FUNC(sys_fs, cellFsLsnGetCDA);
REG_FUNC(sys_fs, cellFsLsnGetCDASize);
REG_FUNC(sys_fs, cellFsLsnLock);
REG_FUNC(sys_fs, cellFsLsnRead);
REG_FUNC(sys_fs, cellFsLsnRead2);
REG_FUNC(sys_fs, cellFsLsnUnlock);
REG_FUNC(sys_fs, cellFsMappedAllocate);
REG_FUNC(sys_fs, cellFsMappedFree);
REG_FUNC(sys_fs, cellFsMkdir);
REG_FUNC(sys_fs, cellFsOpen);
REG_FUNC(sys_fs, cellFsOpen2);
REG_FUNC(sys_fs, cellFsOpendir);
REG_FUNC(sys_fs, cellFsRead).flag(MFF_PERFECT);
REG_FUNC(sys_fs, cellFsReaddir).flag(MFF_PERFECT);
REG_FUNC(sys_fs, cellFsReadWithOffset);
REG_FUNC(sys_fs, cellFsRegisterConversionCallback);
REG_FUNC(sys_fs, cellFsRename);
REG_FUNC(sys_fs, cellFsRmdir);
REG_FUNC(sys_fs, cellFsSdataOpen);
REG_FUNC(sys_fs, cellFsSdataOpenByFd);
REG_FUNC(sys_fs, cellFsSdataOpenWithVersion);
REG_FUNC(sys_fs, cellFsSetAttribute);
REG_FUNC(sys_fs, cellFsSetDefaultContainer);
REG_FUNC(sys_fs, cellFsSetDiscReadRetrySetting);
REG_FUNC(sys_fs, cellFsSetIoBuffer);
REG_FUNC(sys_fs, cellFsSetIoBufferFromDefaultContainer);
REG_FUNC(sys_fs, cellFsStat);
REG_FUNC(sys_fs, cellFsStRead);
REG_FUNC(sys_fs, cellFsStReadFinish);
REG_FUNC(sys_fs, cellFsStReadGetCurrentAddr);
REG_FUNC(sys_fs, cellFsStReadGetRegid);
REG_FUNC(sys_fs, cellFsStReadGetRingBuf);
REG_FUNC(sys_fs, cellFsStReadGetStatus);
REG_FUNC(sys_fs, cellFsStReadInit);
REG_FUNC(sys_fs, cellFsStReadPutCurrentAddr);
REG_FUNC(sys_fs, cellFsStReadStart);
REG_FUNC(sys_fs, cellFsStReadStop);
REG_FUNC(sys_fs, cellFsStReadWait);
REG_FUNC(sys_fs, cellFsStReadWaitCallback);
REG_FUNC(sys_fs, cellFsSymbolicLink);
REG_FUNC(sys_fs, cellFsTruncate);
REG_FUNC(sys_fs, cellFsTruncate2);
REG_FUNC(sys_fs, cellFsUnlink);
REG_FUNC(sys_fs, cellFsUnregisterL10nCallbacks);
REG_FUNC(sys_fs, cellFsUtime);
REG_FUNC(sys_fs, cellFsWrite).flag(MFF_PERFECT);
REG_FUNC(sys_fs, cellFsWriteWithOffset);
});
| 24,263
|
C++
|
.cpp
| 865
| 25.892486
| 164
| 0.712323
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| false
| false
|
5,270
|
cellPngDec.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellPngDec.cpp
|
#include "stdafx.h"
#include "Emu/VFS.h"
#include "Emu/IdManager.h"
#include "Emu/Cell/PPUModule.h"
#include "Emu/Cell/lv2/sys_fs.h"
#include "png.h"
#include "cellPng.h"
#include "cellPngDec.h"
#if PNG_LIBPNG_VER_MAJOR >= 1 && (PNG_LIBPNG_VER_MINOR < 5 \
|| (PNG_LIBPNG_VER_MINOR == 5 && PNG_LIBPNG_VER_RELEASE < 7))
#define PNG_ERROR_ACTION_NONE 1
#define PNG_RGB_TO_GRAY_DEFAULT (-1)
#endif
#if PNG_LIBPNG_VER_MAJOR >= 1 && PNG_LIBPNG_VER_MINOR >= 5
typedef png_bytep iCCP_profile_type;
#else
typedef png_charp iCCP_profile_type;
#endif
// Temporarily
#ifndef _MSC_VER
#pragma GCC diagnostic ignored "-Wunused-parameter"
#endif
LOG_CHANNEL(cellPngDec);
template <>
void fmt_class_string<CellPngDecError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](CellPngDecError value)
{
switch (value)
{
STR_CASE(CELL_PNGDEC_ERROR_HEADER);
STR_CASE(CELL_PNGDEC_ERROR_STREAM_FORMAT);
STR_CASE(CELL_PNGDEC_ERROR_ARG);
STR_CASE(CELL_PNGDEC_ERROR_SEQ);
STR_CASE(CELL_PNGDEC_ERROR_BUSY);
STR_CASE(CELL_PNGDEC_ERROR_FATAL);
STR_CASE(CELL_PNGDEC_ERROR_OPEN_FILE);
STR_CASE(CELL_PNGDEC_ERROR_SPU_UNSUPPORT);
STR_CASE(CELL_PNGDEC_ERROR_SPU_ERROR);
STR_CASE(CELL_PNGDEC_ERROR_CB_PARAM);
}
return unknown;
});
}
// cellPngDec aliases to improve readability
using PPHandle = vm::pptr<PngHandle>;
using PHandle = vm::ptr<PngHandle>;
using PThreadInParam = vm::cptr<CellPngDecThreadInParam>;
using PThreadOutParam = vm::ptr<CellPngDecThreadOutParam>;
using PExtThreadInParam = vm::cptr<CellPngDecExtThreadInParam>;
using PExtThreadOutParam = vm::ptr<CellPngDecExtThreadOutParam>;
using PPStream = vm::pptr<PngStream>;
using PStream = vm::ptr<PngStream>;
using PSrc = vm::cptr<CellPngDecSrc>;
using POpenInfo = vm::ptr<CellPngDecOpnInfo>;
using POpenParam = vm::cptr<CellPngDecOpnParam>;
using PInfo = vm::ptr<CellPngDecInfo>;
using PExtInfo = vm::ptr<CellPngDecExtInfo>;
using PInParam = vm::cptr<CellPngDecInParam>;
using POutParam = vm::ptr<CellPngDecOutParam>;
using PExtInParam = vm::cptr<CellPngDecExtInParam>;
using PExtOutParam = vm::ptr<CellPngDecExtOutParam>;
using PDataControlParam = vm::cptr<CellPngDecDataCtrlParam>;
using PDataOutInfo = vm::ptr<CellPngDecDataOutInfo>;
using PCbControlDisp = vm::cptr<CellPngDecCbCtrlDisp>;
using PCbControlStream = vm::cptr<CellPngDecCbCtrlStrm>;
using PDispParam = vm::ptr<CellPngDecDispParam>;
// Custom read function for libpng, so we could decode images from a buffer
void pngDecReadBuffer(png_structp png_ptr, png_bytep out, png_size_t length)
{
// Get the IO pointer
png_voidp io_ptr = png_get_io_ptr(png_ptr);
// Check if obtaining of the IO pointer failed
if (!io_ptr)
{
cellPngDec.error("Failed to obtain the io_ptr failed.");
return;
}
// Cast the IO pointer to our custom structure
PngBuffer& buffer = *static_cast<PngBuffer*>(io_ptr);
// Read froma file or a buffer
if (buffer.file)
{
// Get the file
auto file = idm::get<lv2_fs_object, lv2_file>(buffer.fd);
// Read the data
file->file.read(out, length);
}
else
{
// Get the current data pointer, including the current cursor position
void* data = static_cast<u8*>(buffer.data.get_ptr()) + buffer.cursor;
// Copy the length of the current data pointer to the output
memcpy(out, data, length);
// Increment the cursor for the next time
buffer.cursor += length;
}
}
void pngDecRowCallback(png_structp png_ptr, png_bytep new_row, png_uint_32 row_num, int pass)
{
PngStream* stream = static_cast<PngStream*>(png_get_progressive_ptr(png_ptr));
if (!stream)
{
cellPngDec.error("Failed to obtain streamPtr in rowCallback.");
return;
}
// we have to check this everytime as this func can be called multiple times per row, and/or only once per row
if (stream->nextRow + stream->outputCounts == row_num)
stream->nextRow = row_num;
if (stream->ppuContext && (stream->nextRow == row_num || pass > 0))
{
if (pass > 0 )
{
stream->cbDispInfo->scanPassCount = pass;
stream->cbDispInfo->nextOutputStartY = row_num;
}
else {
stream->cbDispInfo->scanPassCount = 0;
stream->cbDispInfo->nextOutputStartY = 0;
}
stream->cbDispInfo->outputImage = stream->cbDispParam->nextOutputImage;
stream->cbCtrlDisp.cbCtrlDispFunc(*stream->ppuContext, stream->cbDispInfo, stream->cbDispParam, stream->cbCtrlDisp.cbCtrlDispArg);
stream->cbDispInfo->outputStartY = row_num;
}
u8* data;
if (pass > 0)
data = static_cast<u8*>(stream->cbDispParam->nextOutputImage.get_ptr());
else
data = static_cast<u8*>(stream->cbDispParam->nextOutputImage.get_ptr()) + ((row_num - stream->cbDispInfo->outputStartY) * stream->cbDispInfo->outputFrameWidthByte);
png_progressive_combine_row(png_ptr, data, new_row);
}
void pngDecInfoCallback(png_structp png_ptr, png_infop info)
{
PngStream* stream = static_cast<PngStream*>(png_get_progressive_ptr(png_ptr));
if (!stream)
{
cellPngDec.error("Failed to obtain streamPtr in rowCallback.");
return;
}
const usz remaining = png_process_data_pause(png_ptr, false);
stream->buffer->cursor += (stream->buffer->length - remaining);
}
void pngDecEndCallback(png_structp png_ptr, png_infop info)
{
PngStream* stream = static_cast<PngStream*>(png_get_progressive_ptr(png_ptr));
if (!stream)
{
cellPngDec.error("Failed to obtain streamPtr in endCallback.");
return;
}
stream->endOfFile = true;
}
// Custom error handler for libpng
[[noreturn]] void pngDecError(png_structp png_ptr, png_const_charp error_message)
{
cellPngDec.error("%s", error_message);
// we can't return here or libpng blows up
fmt::throw_exception("Fatal Error in libpng: %s", error_message);
}
// Custom warning handler for libpng
void pngDecWarning(png_structp png_ptr, png_const_charp error_message)
{
cellPngDec.warning("%s", error_message);
}
// Get the chunk information of the PNG file. IDAT is marked as existing, only after decoding or reading the header.
// Bits (if set indicates existence of the chunk):
// 0 - gAMA
// 1 - sBIT
// 2 - cHRM
// 3 - PLTE
// 4 - tRNS
// 5 - bKGD
// 6 - hIST
// 7 - pHYs
// 8 - oFFs
// 9 - tIME
// 10 - pCAL
// 11 - sRGB
// 12 - iCCP
// 13 - sPLT
// 14 - sCAL
// 15 - IDAT
// 16:30 - reserved
be_t<u32> pngDecGetChunkInformation(PngStream* stream, bool IDAT = false)
{
// The end result of the chunk information (bigger-endian)
be_t<u32> chunk_information = 0;
// Needed pointers for getting the chunk information
f64 gamma;
f64 red_x;
f64 red_y;
f64 green_x;
f64 green_y;
f64 blue_x;
f64 blue_y;
f64 white_x;
f64 white_y;
f64 width;
f64 height;
s32 intent;
s32 num_trans;
s32 num_palette;
s32 unit_type;
s32 type;
s32 nparams;
s32 compression_type;
s32 unit;
u16* hist;
png_uint_32 proflen;
iCCP_profile_type profile;
png_bytep trans_alpha;
png_charp units;
png_charp name;
png_charp purpose;
png_charpp params;
png_int_32 X0;
png_int_32 X1;
png_int_32 offset_x;
png_int_32 offset_y;
png_uint_32 res_x;
png_uint_32 res_y;
png_colorp palette;
png_color_8p sig_bit;
png_color_16p background;
png_color_16p trans_color;
png_sPLT_tp entries;
png_timep mod_time;
// Get chunk information and set the appropriate bits
if (png_get_gAMA(stream->png_ptr, stream->info_ptr, &gamma))
{
chunk_information |= 1 << 0; // gAMA
}
if (png_get_sBIT(stream->png_ptr, stream->info_ptr, &sig_bit))
{
chunk_information |= 1 << 1; // sBIT
}
if (png_get_cHRM(stream->png_ptr, stream->info_ptr, &white_x, &white_y, &red_x, &red_y, &green_x, &green_y, &blue_x, &blue_y))
{
chunk_information |= 1 << 2; // cHRM
}
if (png_get_PLTE(stream->png_ptr, stream->info_ptr, &palette, &num_palette))
{
chunk_information |= 1 << 3; // PLTE
}
if (png_get_tRNS(stream->png_ptr, stream->info_ptr, &trans_alpha, &num_trans, &trans_color))
{
chunk_information |= 1 << 4; // tRNS
}
if (png_get_bKGD(stream->png_ptr, stream->info_ptr, &background))
{
chunk_information |= 1 << 5; // bKGD
}
if (png_get_hIST(stream->png_ptr, stream->info_ptr, &hist))
{
chunk_information |= 1 << 6; // hIST
}
if (png_get_pHYs(stream->png_ptr, stream->info_ptr, &res_x, &res_y, &unit_type))
{
chunk_information |= 1 << 7; // pHYs
}
if (png_get_oFFs(stream->png_ptr, stream->info_ptr, &offset_x, &offset_y, &unit_type))
{
chunk_information |= 1 << 8; // oFFs
}
if (png_get_tIME(stream->png_ptr, stream->info_ptr, &mod_time))
{
chunk_information |= 1 << 9; // tIME
}
if (png_get_pCAL(stream->png_ptr, stream->info_ptr, &purpose, &X0, &X1, &type, &nparams, &units, ¶ms))
{
chunk_information |= 1 << 10; // pCAL
}
if (png_get_sRGB(stream->png_ptr, stream->info_ptr, &intent))
{
chunk_information |= 1 << 11; // sRGB
}
if (png_get_iCCP(stream->png_ptr, stream->info_ptr, &name, &compression_type, &profile, &proflen))
{
chunk_information |= 1 << 12; // iCCP
}
if (png_get_sPLT(stream->png_ptr, stream->info_ptr, &entries))
{
chunk_information |= 1 << 13; // sPLT
}
if (png_get_sCAL(stream->png_ptr, stream->info_ptr, &unit, &width, &height))
{
chunk_information |= 1 << 14; // sCAL
}
if (IDAT)
{
chunk_information |= 1 << 15; // IDAT
}
return chunk_information;
}
error_code pngDecCreate(ppu_thread& ppu, PPHandle png_handle, PThreadInParam thread_in_param, PThreadOutParam thread_out_param, PExtThreadInParam extra_thread_in_param = vm::null, PExtThreadOutParam extra_thread_out_param = vm::null)
{
// Check if partial image decoding is used
if (extra_thread_out_param)
{
fmt::throw_exception("Partial image decoding is not supported.");
}
// Allocate memory for the decoder handle
auto handle = vm::ptr<PngHandle>::make(thread_in_param->cbCtrlMallocFunc(ppu, sizeof(PngHandle), thread_in_param->cbCtrlMallocArg).addr());
// Check if the memory allocation for the handle failed
if (!handle)
{
cellPngDec.error("PNG decoder creation failed.");
return CELL_PNGDEC_ERROR_FATAL;
}
// Set the allocation functions in the handle
handle->malloc_ = thread_in_param->cbCtrlMallocFunc;
handle->malloc_arg = thread_in_param->cbCtrlMallocArg;
handle->free_ = thread_in_param->cbCtrlFreeFunc;
handle->free_arg = thread_in_param->cbCtrlFreeArg;
// Set handle pointer
*png_handle = handle;
// Set the version information
thread_out_param->pngCodecVersion = PNGDEC_CODEC_VERSION;
return CELL_OK;
}
error_code pngDecDestroy(ppu_thread& ppu, PHandle handle)
{
// Deallocate the decoder handle memory
if (handle->free_(ppu, handle, handle->free_arg) != 0)
{
cellPngDec.error("PNG decoder deallocation failed.");
return CELL_PNGDEC_ERROR_FATAL;
}
return CELL_OK;
}
error_code pngDecOpen(ppu_thread& ppu, PHandle handle, PPStream png_stream, PSrc source, POpenInfo open_info, PCbControlStream control_stream = vm::null, POpenParam open_param = vm::null)
{
// partial decoding only supported with buffer type
if (source->srcSelect != CELL_PNGDEC_BUFFER && control_stream)
{
cellPngDec.error("Attempted partial image decode with file.");
return CELL_PNGDEC_ERROR_STREAM_FORMAT;
}
// Allocate memory for the stream structure
auto stream = vm::ptr<PngStream>::make(handle->malloc_(ppu, sizeof(PngStream), handle->malloc_arg).addr());
// Check if the allocation of memory for the stream structure failed
if (!stream)
{
cellPngDec.error("PNG stream creation failed.");
return CELL_PNGDEC_ERROR_FATAL;
}
// Set memory info
open_info->initSpaceAllocated = sizeof(PngStream);
// Set the stream source to the source give by the game
stream->source = *source;
// Use virtual memory address as a handle
*png_stream = stream;
// Allocate memory for the PNG buffer for decoding
auto buffer = vm::ptr<PngBuffer>::make(handle->malloc_(ppu, sizeof(PngBuffer), handle->malloc_arg).addr());
// Check for if the buffer structure allocation failed
if (!buffer)
{
fmt::throw_exception("Memory allocation for the PNG buffer structure failed.");
}
// We might not be reading from a file stream
buffer->file = false;
// Set the buffer pointer in the stream structure, so we can later deallocate it
stream->buffer = buffer;
// Open the buffer/file and check the header
u8 header[8];
// Need to test it somewhere
if (stream->source.fileOffset != 0)
{
fmt::throw_exception("Non-0 file offset not supported.");
}
// Depending on the source type, get the first 8 bytes
if (source->srcSelect == CELL_PNGDEC_FILE)
{
const auto real_path = vfs::get(stream->source.fileName.get_ptr());
// Open a file stream
fs::file file_stream(real_path);
// Check if opening of the PNG file failed
if (!file_stream)
{
cellPngDec.error("Opening of PNG failed. (%s)", stream->source.fileName.get_ptr());
return CELL_PNGDEC_ERROR_OPEN_FILE;
}
// Read the header
if (file_stream.read(header, 8) != 8)
{
cellPngDec.error("PNG header is too small.");
return CELL_PNGDEC_ERROR_HEADER;
}
// Get the file descriptor
buffer->fd = idm::make<lv2_fs_object, lv2_file>(stream->source.fileName.get_ptr(), std::move(file_stream), 0, 0, real_path);
// Indicate that we need to read from a file stream
buffer->file = true;
}
else
{
// We can simply copy the first 8 bytes
memcpy(header, stream->source.streamPtr.get_ptr(), 8);
}
// Check if the header indicates a valid PNG file
if (png_sig_cmp(header, 0, 8))
{
cellPngDec.error("PNG signature is invalid.");
return CELL_PNGDEC_ERROR_HEADER;
}
// Create a libpng structure, also pass our custom error/warning functions
stream->png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, nullptr, pngDecError, pngDecWarning);
// Check if the creation of the structure failed
if (!stream->png_ptr)
{
cellPngDec.error("Creation of png_structp failed.");
return CELL_PNGDEC_ERROR_FATAL;
}
// Create a libpng info structure
stream->info_ptr = png_create_info_struct(stream->png_ptr);
// Check if the creation of the structure failed
if (!stream->info_ptr)
{
fmt::throw_exception("Creation of png_infop failed.");
}
// We must indicate, that we allocated more memory
open_info->initSpaceAllocated += u32{sizeof(PngBuffer)};
if (source->srcSelect == CELL_PNGDEC_BUFFER)
{
buffer->length = stream->source.streamSize;
buffer->data = stream->source.streamPtr;
buffer->cursor = 8;
}
// Set the custom read function for decoding
if (control_stream)
{
if (open_param && open_param->selectChunk != 0u)
fmt::throw_exception("Partial Decoding with selectChunk not supported yet.");
stream->cbCtrlStream.cbCtrlStrmArg = control_stream->cbCtrlStrmArg;
stream->cbCtrlStream.cbCtrlStrmFunc = control_stream->cbCtrlStrmFunc;
png_set_progressive_read_fn(stream->png_ptr, stream.get_ptr(), pngDecInfoCallback, pngDecRowCallback, pngDecEndCallback);
// push header tag to libpng to keep us in sync
png_process_data(stream->png_ptr, stream->info_ptr, header, 8);
}
else
{
png_set_read_fn(stream->png_ptr, buffer.get_ptr(), pngDecReadBuffer);
// We need to tell libpng, that we already read 8 bytes
png_set_sig_bytes(stream->png_ptr, 8);
}
return CELL_OK;
}
error_code pngDecClose(ppu_thread& ppu, PHandle handle, PStream stream)
{
// Remove the file descriptor, if a file descriptor was used for decoding
if (stream->buffer->file)
{
idm::remove<lv2_fs_object, lv2_file>(stream->buffer->fd);
}
// Deallocate the PNG buffer structure used to decode from memory, if we decoded from memory
if (stream->buffer)
{
if (handle->free_(ppu, stream->buffer, handle->free_arg) != 0)
{
cellPngDec.error("PNG buffer decoding structure deallocation failed.");
return CELL_PNGDEC_ERROR_FATAL;
}
}
// Free the memory allocated by libpng
png_destroy_read_struct(&stream->png_ptr, &stream->info_ptr, nullptr);
// Deallocate the stream memory
if (handle->free_(ppu, stream, handle->free_arg) != 0)
{
cellPngDec.error("PNG stream deallocation failed.");
return CELL_PNGDEC_ERROR_FATAL;
}
return CELL_OK;
}
void pngSetHeader(PngStream* stream)
{
stream->info.imageWidth = png_get_image_width(stream->png_ptr, stream->info_ptr);
stream->info.imageHeight = png_get_image_height(stream->png_ptr, stream->info_ptr);
stream->info.numComponents = png_get_channels(stream->png_ptr, stream->info_ptr);
stream->info.colorSpace = getPngDecColourType(png_get_color_type(stream->png_ptr, stream->info_ptr));
stream->info.bitDepth = png_get_bit_depth(stream->png_ptr, stream->info_ptr);
stream->info.interlaceMethod = png_get_interlace_type(stream->png_ptr, stream->info_ptr);
stream->info.chunkInformation = pngDecGetChunkInformation(stream);
}
error_code pngDecSetParameter(PStream stream, PInParam in_param, POutParam out_param, PExtInParam extra_in_param = vm::null, PExtOutParam extra_out_param = vm::null)
{
if (in_param->outputPackFlag == CELL_PNGDEC_1BYTE_PER_NPIXEL)
{
fmt::throw_exception("Packing not supported! (%d)", in_param->outputPackFlag);
}
// flag to keep unknown chunks
png_set_keep_unknown_chunks(stream->png_ptr, PNG_HANDLE_CHUNK_IF_SAFE, nullptr, 0);
// Scale 16 bit depth down to 8 bit depth.
if (stream->info.bitDepth == 16u && in_param->outputBitDepth == 8u)
{
// PS3 uses png_set_strip_16, since png_set_scale_16 wasn't available back then.
png_set_strip_16(stream->png_ptr);
}
// This shouldnt ever happen, but not sure what to do if it does, just want it logged for now
if (stream->info.bitDepth != 16u && in_param->outputBitDepth == 16u)
cellPngDec.error("Output depth of 16 with non input depth of 16 specified!");
if (in_param->commandPtr)
cellPngDec.warning("Ignoring CommandPtr.");
if (stream->info.colorSpace != in_param->outputColorSpace)
{
// check if we need to set alpha
const bool inputHasAlpha = cellPngColorSpaceHasAlpha(stream->info.colorSpace);
const bool outputWantsAlpha = cellPngColorSpaceHasAlpha(in_param->outputColorSpace);
if (outputWantsAlpha && !inputHasAlpha)
{
if (in_param->outputAlphaSelect == CELL_PNGDEC_FIX_ALPHA)
png_set_add_alpha(stream->png_ptr, in_param->outputColorAlpha, in_param->outputColorSpace == CELL_PNGDEC_ARGB ? PNG_FILLER_BEFORE : PNG_FILLER_AFTER);
else
{
// Check if we can steal the alpha from a trns block
if (png_get_valid(stream->png_ptr, stream->info_ptr, PNG_INFO_tRNS))
png_set_tRNS_to_alpha(stream->png_ptr);
// if not, just set default of 0xff
else
png_set_add_alpha(stream->png_ptr, 0xff, in_param->outputColorSpace == CELL_PNGDEC_ARGB ? PNG_FILLER_BEFORE : PNG_FILLER_AFTER);
}
}
else if (inputHasAlpha && !outputWantsAlpha)
png_set_strip_alpha(stream->png_ptr);
else if (in_param->outputColorSpace == CELL_PNGDEC_ARGB && stream->info.colorSpace == CELL_PNGDEC_RGBA)
png_set_swap_alpha(stream->png_ptr);
// Handle gray<->rgb colorspace conversions
// rgb output
if (in_param->outputColorSpace == CELL_PNGDEC_ARGB
|| in_param->outputColorSpace == CELL_PNGDEC_RGBA
|| in_param->outputColorSpace == CELL_PNGDEC_RGB)
{
if (stream->info.colorSpace == CELL_PNGDEC_PALETTE)
png_set_palette_to_rgb(stream->png_ptr);
if ((stream->info.colorSpace == CELL_PNGDEC_GRAYSCALE || stream->info.colorSpace == CELL_PNGDEC_GRAYSCALE_ALPHA)
&& stream->info.bitDepth < 8)
png_set_expand_gray_1_2_4_to_8(stream->png_ptr);
}
// grayscale output
else
{
if (stream->info.colorSpace == CELL_PNGDEC_ARGB
|| stream->info.colorSpace == CELL_PNGDEC_RGBA
|| stream->info.colorSpace == CELL_PNGDEC_RGB)
{
png_set_rgb_to_gray(stream->png_ptr, PNG_ERROR_ACTION_NONE, PNG_RGB_TO_GRAY_DEFAULT, PNG_RGB_TO_GRAY_DEFAULT);
}
else {
// not sure what to do here
cellPngDec.error("Grayscale / Palette to Grayscale / Palette conversion currently unsupported.");
}
}
}
stream->passes = png_set_interlace_handling(stream->png_ptr);
// Update the info structure
png_read_update_info(stream->png_ptr, stream->info_ptr);
stream->out_param.outputWidth = stream->info.imageWidth;
stream->out_param.outputHeight = stream->info.imageHeight;
stream->out_param.outputBitDepth = in_param->outputBitDepth;
stream->out_param.outputColorSpace = in_param->outputColorSpace;
stream->out_param.outputMode = in_param->outputMode;
stream->out_param.outputWidthByte = png_get_rowbytes(stream->png_ptr, stream->info_ptr);
stream->out_param.outputComponents = png_get_channels(stream->png_ptr, stream->info_ptr);
stream->packing = in_param->outputPackFlag;
// Set the memory usage. We currently don't actually allocate memory for libpng through the callbacks, due to libpng needing a lot more memory compared to PS3 variant.
stream->out_param.useMemorySpace = 0;
if (extra_in_param)
{
if (extra_in_param->bufferMode != CELL_PNGDEC_LINE_MODE)
{
cellPngDec.error("Invalid Buffermode specified.");
return CELL_PNGDEC_ERROR_ARG;
}
if (stream->passes > 1)
{
stream->outputCounts = 1;
}
else
stream->outputCounts = extra_in_param->outputCounts;
if (extra_out_param)
{
if (stream->outputCounts == 0)
extra_out_param->outputHeight = stream->out_param.outputHeight;
else
extra_out_param->outputHeight = std::min(stream->outputCounts, stream->out_param.outputHeight.value());
extra_out_param->outputWidthByte = stream->out_param.outputWidthByte;
}
}
*out_param = stream->out_param;
return CELL_OK;
}
error_code pngDecodeData(ppu_thread& ppu, PHandle handle, PStream stream, vm::ptr<u8> data, PDataControlParam data_control_param, PDataOutInfo data_out_info, PCbControlDisp cb_control_disp = vm::null, PDispParam disp_param = vm::null)
{
// Indicate, that the PNG decoding is stopped/failed. This is incase, we return an error code in the middle of decoding
data_out_info->status = CELL_PNGDEC_DEC_STATUS_STOP;
const u32 bytes_per_line = ::narrow<u32>(data_control_param->outputBytesPerLine);
// Log this for now
if (bytes_per_line < stream->out_param.outputWidthByte)
{
fmt::throw_exception("Bytes per line less than expected output! Got: %d, expected: %d", bytes_per_line, stream->out_param.outputWidthByte);
}
// partial decoding
if (cb_control_disp && stream->outputCounts > 0)
{
// get data from cb
auto streamInfo = vm::ptr<CellPngDecStrmInfo>::make(handle->malloc_(ppu, sizeof(CellPngDecStrmInfo), handle->malloc_arg).addr());
auto streamParam = vm::ptr<CellPngDecStrmParam>::make(handle->malloc_(ppu, sizeof(CellPngDecStrmParam), handle->malloc_arg).addr());
stream->cbDispInfo = vm::ptr<CellPngDecDispInfo>::make(handle->malloc_(ppu, sizeof(CellPngDecDispInfo), handle->malloc_arg).addr());
stream->cbDispParam = vm::ptr<CellPngDecDispParam>::make(handle->malloc_(ppu, sizeof(CellPngDecDispParam), handle->malloc_arg).addr());
auto freeMem = [&]()
{
handle->free_(ppu, streamInfo, handle->free_arg);
handle->free_(ppu, streamParam, handle->free_arg);
handle->free_(ppu, stream->cbDispInfo, handle->free_arg);
handle->free_(ppu, stream->cbDispParam, handle->free_arg);
};
// set things that won't change between callbacks
stream->cbDispInfo->outputFrameWidthByte = bytes_per_line;
stream->cbDispInfo->outputFrameHeight = stream->out_param.outputHeight;
stream->cbDispInfo->outputWidthByte = stream->out_param.outputWidthByte;
stream->cbDispInfo->outputBitDepth = stream->out_param.outputBitDepth;
stream->cbDispInfo->outputComponents = stream->out_param.outputComponents;
stream->cbDispInfo->outputHeight = stream->outputCounts;
stream->cbDispInfo->outputStartXByte = 0;
stream->cbDispInfo->outputStartY = 0;
stream->cbDispInfo->scanPassCount = 0;
stream->cbDispInfo->nextOutputStartY = 0;
stream->ppuContext = &ppu;
stream->nextRow = stream->cbDispInfo->outputHeight;
stream->cbCtrlDisp.cbCtrlDispArg = cb_control_disp->cbCtrlDispArg;
stream->cbCtrlDisp.cbCtrlDispFunc = cb_control_disp->cbCtrlDispFunc;
stream->cbDispParam->nextOutputImage = disp_param->nextOutputImage;
streamInfo->decodedStrmSize = ::narrow<u32>(stream->buffer->cursor);
// push the rest of the buffer we have
if (stream->buffer->length > stream->buffer->cursor)
{
u8* data = static_cast<u8*>(stream->buffer->data.get_ptr()) + stream->buffer->cursor;
png_process_data(stream->png_ptr, stream->info_ptr, data, stream->buffer->length - stream->buffer->cursor);
streamInfo->decodedStrmSize = ::narrow<u32>(stream->buffer->length);
}
// todo: commandPtr
// then just loop until the end, the callbacks should take care of the rest
while (stream->endOfFile != true)
{
stream->cbCtrlStream.cbCtrlStrmFunc(ppu, streamInfo, streamParam, stream->cbCtrlStream.cbCtrlStrmArg);
streamInfo->decodedStrmSize += streamParam->strmSize;
png_process_data(stream->png_ptr, stream->info_ptr, static_cast<u8*>(streamParam->strmPtr.get_ptr()), streamParam->strmSize);
}
freeMem();
}
else
{
// Check if the image needs to be flipped
const bool flip = stream->out_param.outputMode == CELL_PNGDEC_BOTTOM_TO_TOP;
// Decode the image
// todo: commandptr
{
for (u32 j = 0; j < stream->passes; j++)
{
for (u32 i = 0; i < stream->out_param.outputHeight; ++i)
{
const u32 line = flip ? stream->out_param.outputHeight - i - 1 : i;
png_read_row(stream->png_ptr, &data[line*bytes_per_line], nullptr);
}
}
png_read_end(stream->png_ptr, stream->info_ptr);
}
}
// Get the number of iTXt, tEXt and zTXt chunks
const s32 text_chunks = png_get_text(stream->png_ptr, stream->info_ptr, nullptr, nullptr);
// Set the chunk information and the previously obtained number of text chunks
data_out_info->numText = static_cast<u32>(text_chunks);
data_out_info->chunkInformation = pngDecGetChunkInformation(stream.get_ptr(), true);
png_unknown_chunkp unknowns;
const int num_unknowns = png_get_unknown_chunks(stream->png_ptr, stream->info_ptr, &unknowns);
data_out_info->numUnknownChunk = num_unknowns;
// Indicate that the decoding succeeded
data_out_info->status = CELL_PNGDEC_DEC_STATUS_FINISH;
return CELL_OK;
}
error_code cellPngDecCreate(ppu_thread& ppu, PPHandle handle, PThreadInParam threadInParam, PThreadOutParam threadOutParam)
{
cellPngDec.warning("cellPngDecCreate(handle=**0x%x, threadInParam=*0x%x, threadOutParam=*0x%x)", handle, threadInParam, threadOutParam);
return pngDecCreate(ppu, handle, threadInParam, threadOutParam);
}
error_code cellPngDecExtCreate(ppu_thread& ppu, PPHandle handle, PThreadInParam threadInParam, PThreadOutParam threadOutParam, PExtThreadInParam extThreadInParam, PExtThreadOutParam extThreadOutParam)
{
cellPngDec.warning("cellPngDecExtCreate(mainHandle=**0x%x, threadInParam=*0x%x, threadOutParam=*0x%x, extThreadInParam=*0x%x, extThreadOutParam=*0x%x)", handle, threadInParam, threadOutParam, extThreadInParam, extThreadOutParam);
return pngDecCreate(ppu, handle, threadInParam, threadOutParam, extThreadInParam, extThreadOutParam);
}
error_code cellPngDecDestroy(ppu_thread& ppu, PHandle handle)
{
cellPngDec.warning("cellPngDecDestroy(mainHandle=*0x%x)", handle);
return pngDecDestroy(ppu, handle);
}
error_code cellPngDecOpen(ppu_thread& ppu, PHandle handle, PPStream stream, PSrc src, POpenInfo openInfo)
{
cellPngDec.warning("cellPngDecOpen(handle=*0x%x, stream=**0x%x, src=*0x%x, openInfo=*0x%x)", handle, stream, src, openInfo);
return pngDecOpen(ppu, handle, stream, src, openInfo);
}
error_code cellPngDecExtOpen(ppu_thread& ppu, PHandle handle, PPStream stream, PSrc src, POpenInfo openInfo, PCbControlStream cbCtrlStrm, POpenParam opnParam)
{
cellPngDec.warning("cellPngDecExtOpen(handle=*0x%x, stream=**0x%x, src=*0x%x, openInfo=*0x%x, cbCtrlStrm=*0x%x, opnParam=*0x%x)", handle, stream, src, openInfo, cbCtrlStrm, opnParam);
return pngDecOpen(ppu, handle, stream, src, openInfo, cbCtrlStrm, opnParam);
}
error_code cellPngDecClose(ppu_thread& ppu, PHandle handle, PStream stream)
{
cellPngDec.warning("cellPngDecClose(handle=*0x%x, stream=*0x%x)", handle, stream);
return pngDecClose(ppu, handle, stream);
}
error_code cellPngDecReadHeader(PHandle handle, PStream stream, PInfo info)
{
cellPngDec.warning("cellPngDecReadHeader(handle=*0x%x, stream=*0x%x, info=*0x%x)", handle, stream, info);
// Read the header info
png_read_info(stream->png_ptr, stream->info_ptr);
pngSetHeader(stream.get_ptr());
// Set the pointer to stream info
*info = stream->info;
return CELL_OK;
}
error_code cellPngDecExtReadHeader(PHandle handle, PStream stream, PInfo info, PExtInfo extInfo)
{
cellPngDec.warning("cellPngDecExtReadHeader(handle=*0x%x, stream=*0x%x, info=*0x%x, extInfo=*0x%x)", handle, stream, info, extInfo);
// Set the reserved value to 0, if passed to the function. (Should this be arg error if they dont pass?)
if (extInfo)
{
extInfo->reserved = 0;
}
// lets push what we have so far
u8* data = static_cast<u8*>(stream->buffer->data.get_ptr()) + stream->buffer->cursor;
png_process_data(stream->png_ptr, stream->info_ptr, data, stream->buffer->length);
// lets hope we pushed enough for callback
pngSetHeader(stream.get_ptr());
// png doesnt allow empty image, so quick check for 0 verifys if we got the header
// not sure exactly what should happen if we dont have header, ask for more data with callback?
if (stream->info.imageWidth == 0u)
{
fmt::throw_exception("Invalid or not enough data sent to get header");
return CELL_PNGDEC_ERROR_HEADER;
}
// Set the pointer to stream info
*info = stream->info;
return CELL_OK;
}
error_code cellPngDecSetParameter(PHandle handle, PStream stream, PInParam inParam, POutParam outParam)
{
cellPngDec.warning("cellPngDecSetParameter(handle=*0x%x, stream=*0x%x, inParam=*0x%x, outParam=*0x%x)", handle, stream, inParam, outParam);
return pngDecSetParameter(stream, inParam, outParam);
}
error_code cellPngDecExtSetParameter(PHandle handle, PStream stream, PInParam inParam, POutParam outParam, PExtInParam extInParam, PExtOutParam extOutParam)
{
cellPngDec.warning("cellPngDecExtSetParameter(handle=*0x%x, stream=*0x%x, inParam=*0x%x, outParam=*0x%x, extInParam=*0x%x, extOutParam=*0x%x", handle, stream, inParam, outParam, extInParam, extOutParam);
return pngDecSetParameter(stream, inParam, outParam, extInParam, extOutParam);
}
error_code cellPngDecDecodeData(ppu_thread& ppu, PHandle handle, PStream stream, vm::ptr<u8> data, PDataControlParam dataCtrlParam, PDataOutInfo dataOutInfo)
{
cellPngDec.warning("cellPngDecDecodeData(handle=*0x%x, stream=*0x%x, data=*0x%x, dataCtrlParam=*0x%x, dataOutInfo=*0x%x)", handle, stream, data, dataCtrlParam, dataOutInfo);
return pngDecodeData(ppu, handle, stream, data, dataCtrlParam, dataOutInfo);
}
error_code cellPngDecExtDecodeData(ppu_thread& ppu, PHandle handle, PStream stream, vm::ptr<u8> data, PDataControlParam dataCtrlParam, PDataOutInfo dataOutInfo, PCbControlDisp cbCtrlDisp, PDispParam dispParam)
{
cellPngDec.warning("cellPngDecExtDecodeData(handle=*0x%x, stream=*0x%x, data=*0x%x, dataCtrlParam=*0x%x, dataOutInfo=*0x%x, cbCtrlDisp=*0x%x, dispParam=*0x%x)", handle, stream, data, dataCtrlParam, dataOutInfo, cbCtrlDisp, dispParam);
return pngDecodeData(ppu, handle, stream, data, dataCtrlParam, dataOutInfo, cbCtrlDisp, dispParam);
}
error_code cellPngDecGetUnknownChunks(PHandle handle, PStream stream, vm::pptr<CellPngUnknownChunk> unknownChunk, vm::ptr<u32> unknownChunkNumber)
{
cellPngDec.todo("cellPngDecGetUnknownChunks()");
return CELL_OK;
}
error_code cellPngDecGetpCAL(PHandle handle, PStream stream, vm::ptr<CellPngPCAL> pcal)
{
cellPngDec.todo("cellPngDecGetpCAL()");
return CELL_OK;
}
error_code cellPngDecGetcHRM(PHandle handle, PStream stream, vm::ptr<CellPngCHRM> chrm)
{
cellPngDec.todo("cellPngDecGetcHRM()");
return CELL_OK;
}
error_code cellPngDecGetsCAL(PHandle handle, PStream stream, vm::ptr<CellPngSCAL> scal)
{
cellPngDec.todo("cellPngDecGetsCAL()");
return CELL_OK;
}
error_code cellPngDecGetpHYs(PHandle handle, PStream stream, vm::ptr<CellPngPHYS> phys)
{
cellPngDec.todo("cellPngDecGetpHYs()");
return CELL_OK;
}
error_code cellPngDecGetoFFs(PHandle handle, PStream stream, vm::ptr<CellPngOFFS> offs)
{
cellPngDec.todo("cellPngDecGetoFFs()");
return CELL_OK;
}
error_code cellPngDecGetsPLT(PHandle handle, PStream stream, vm::ptr<CellPngSPLT> splt)
{
cellPngDec.todo("cellPngDecGetsPLT()");
return CELL_OK;
}
error_code cellPngDecGetbKGD(PHandle handle, PStream stream, vm::ptr<CellPngBKGD> bkgd)
{
cellPngDec.todo("cellPngDecGetbKGD()");
return CELL_OK;
}
error_code cellPngDecGettIME(PHandle handle, PStream stream, vm::ptr<CellPngTIME> time)
{
cellPngDec.todo("cellPngDecGettIME()");
return CELL_OK;
}
error_code cellPngDecGethIST(PHandle handle, PStream stream, vm::ptr<CellPngHIST> hist)
{
cellPngDec.todo("cellPngDecGethIST()");
return CELL_OK;
}
error_code cellPngDecGettRNS(PHandle handle, PStream stream, vm::ptr<CellPngTRNS> trns)
{
cellPngDec.todo("cellPngDecGettRNS()");
return CELL_OK;
}
error_code cellPngDecGetsBIT(PHandle handle, PStream stream, vm::ptr<CellPngSBIT> sbit)
{
cellPngDec.todo("cellPngDecGetsBIT()");
return CELL_OK;
}
error_code cellPngDecGetiCCP(PHandle handle, PStream stream, vm::ptr<CellPngICCP> iccp)
{
cellPngDec.todo("cellPngDecGetiCCP()");
return CELL_OK;
}
error_code cellPngDecGetsRGB(PHandle handle, PStream stream, vm::ptr<CellPngSRGB> srgb)
{
cellPngDec.todo("cellPngDecGetsRGB()");
return CELL_OK;
}
error_code cellPngDecGetgAMA(PHandle handle, PStream stream, vm::ptr<CellPngGAMA> gama)
{
cellPngDec.todo("cellPngDecGetgAMA()");
return CELL_OK;
}
error_code cellPngDecGetPLTE(PHandle handle, PStream stream, vm::ptr<CellPngPLTE> plte)
{
cellPngDec.todo("cellPngDecGetPLTE()");
return CELL_OK;
}
error_code cellPngDecGetTextChunk(PHandle handle, PStream stream, vm::ptr<u32> textInfoNum, vm::pptr<CellPngTextInfo> textInfo)
{
cellPngDec.todo("cellPngDecGetTextChunk()");
return CELL_OK;
}
DECLARE(ppu_module_manager::cellPngDec)("cellPngDec", []()
{
REG_FUNC(cellPngDec, cellPngDecGetUnknownChunks);
REG_FUNC(cellPngDec, cellPngDecClose);
REG_FUNC(cellPngDec, cellPngDecGetpCAL);
REG_FUNC(cellPngDec, cellPngDecGetcHRM);
REG_FUNC(cellPngDec, cellPngDecGetsCAL);
REG_FUNC(cellPngDec, cellPngDecGetpHYs);
REG_FUNC(cellPngDec, cellPngDecGetoFFs);
REG_FUNC(cellPngDec, cellPngDecGetsPLT);
REG_FUNC(cellPngDec, cellPngDecGetbKGD);
REG_FUNC(cellPngDec, cellPngDecGettIME);
REG_FUNC(cellPngDec, cellPngDecGethIST);
REG_FUNC(cellPngDec, cellPngDecGettRNS);
REG_FUNC(cellPngDec, cellPngDecGetsBIT);
REG_FUNC(cellPngDec, cellPngDecGetiCCP);
REG_FUNC(cellPngDec, cellPngDecGetsRGB);
REG_FUNC(cellPngDec, cellPngDecGetgAMA);
REG_FUNC(cellPngDec, cellPngDecGetPLTE);
REG_FUNC(cellPngDec, cellPngDecGetTextChunk);
REG_FUNC(cellPngDec, cellPngDecDestroy);
REG_FUNC(cellPngDec, cellPngDecCreate);
REG_FUNC(cellPngDec, cellPngDecExtCreate);
REG_FUNC(cellPngDec, cellPngDecExtSetParameter);
REG_FUNC(cellPngDec, cellPngDecSetParameter);
REG_FUNC(cellPngDec, cellPngDecExtReadHeader);
REG_FUNC(cellPngDec, cellPngDecReadHeader);
REG_FUNC(cellPngDec, cellPngDecExtOpen);
REG_FUNC(cellPngDec, cellPngDecOpen);
REG_FUNC(cellPngDec, cellPngDecExtDecodeData);
REG_FUNC(cellPngDec, cellPngDecDecodeData);
});
| 35,146
|
C++
|
.cpp
| 879
| 37.631399
| 235
| 0.74349
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| true
| false
| false
| true
| false
| false
|
5,271
|
cellPhotoDecode.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellPhotoDecode.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
#include "Emu/IdManager.h"
#include "Emu/VFS.h"
#include "Emu/System.h"
#include "cellSysutil.h"
LOG_CHANNEL(cellPhotoDecode);
// Return Codes
enum CellPhotoDecodeError : u32
{
CELL_PHOTO_DECODE_ERROR_BUSY = 0x8002c901,
CELL_PHOTO_DECODE_ERROR_INTERNAL = 0x8002c902,
CELL_PHOTO_DECODE_ERROR_PARAM = 0x8002c903,
CELL_PHOTO_DECODE_ERROR_ACCESS_ERROR = 0x8002c904,
CELL_PHOTO_DECODE_ERROR_INITIALIZE = 0x8002c905,
CELL_PHOTO_DECODE_ERROR_DECODE = 0x8002c906,
};
template<>
void fmt_class_string<CellPhotoDecodeError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_PHOTO_DECODE_ERROR_BUSY);
STR_CASE(CELL_PHOTO_DECODE_ERROR_INTERNAL);
STR_CASE(CELL_PHOTO_DECODE_ERROR_PARAM);
STR_CASE(CELL_PHOTO_DECODE_ERROR_ACCESS_ERROR);
STR_CASE(CELL_PHOTO_DECODE_ERROR_INITIALIZE);
STR_CASE(CELL_PHOTO_DECODE_ERROR_DECODE);
}
return unknown;
});
}
enum
{
CELL_PHOTO_DECODE_VERSION_CURRENT = 0
};
struct CellPhotoDecodeSetParam
{
vm::bptr<void> dstBuffer;
be_t<u16> width;
be_t<u16> height;
vm::bptr<void> reserved1;
vm::bptr<void> reserved2;
};
struct CellPhotoDecodeReturnParam
{
be_t<u16> width;
be_t<u16> height;
vm::bptr<void> reserved1;
vm::bptr<void> reserved2;
};
using CellPhotoDecodeFinishCallback = void(s32 result, vm::ptr<void> userdata);
error_code cellPhotoDecodeInitialize(u32 version, u32 container1, u32 container2, vm::ptr<CellPhotoDecodeFinishCallback> funcFinish, vm::ptr<void> userdata)
{
cellPhotoDecode.warning("cellPhotoDecodeInitialize(version=0x%x, container1=0x%x, container2=0x%x, funcFinish=*0x%x, userdata=*0x%x)", version, container1, container2, funcFinish, userdata);
if (version != CELL_PHOTO_DECODE_VERSION_CURRENT || !funcFinish)
{
return CELL_PHOTO_DECODE_ERROR_PARAM;
}
if (container1 != 0xffffffff && false) // TODO: size < 0x300000
{
return CELL_PHOTO_DECODE_ERROR_PARAM;
}
if (container2 != 0xffffffff && false) // TODO: size depends on image type, width and height
{
return CELL_PHOTO_DECODE_ERROR_PARAM;
}
sysutil_register_cb([=](ppu_thread& ppu) -> s32
{
funcFinish(ppu, CELL_OK, userdata);
return CELL_OK;
});
return CELL_OK;
}
error_code cellPhotoDecodeInitialize2(u32 version, u32 container2, vm::ptr<CellPhotoDecodeFinishCallback> funcFinish, vm::ptr<void> userdata)
{
cellPhotoDecode.warning("cellPhotoDecodeInitialize2(version=0x%x, container2=0x%x, funcFinish=*0x%x, userdata=*0x%x)", version, container2, funcFinish, userdata);
if (version != CELL_PHOTO_DECODE_VERSION_CURRENT || !funcFinish)
{
return CELL_PHOTO_DECODE_ERROR_PARAM;
}
if (container2 != 0xffffffff && false) // TODO: size depends on image type, width and height
{
return CELL_PHOTO_DECODE_ERROR_PARAM;
}
sysutil_register_cb([=](ppu_thread& ppu) -> s32
{
funcFinish(ppu, CELL_OK, userdata);
return CELL_OK;
});
return CELL_OK;
}
error_code cellPhotoDecodeFinalize(vm::ptr<CellPhotoDecodeFinishCallback> funcFinish, vm::ptr<void> userdata)
{
cellPhotoDecode.warning("cellPhotoDecodeFinalize(funcFinish=*0x%x, userdata=*0x%x)", funcFinish, userdata);
if (!funcFinish)
{
return CELL_PHOTO_DECODE_ERROR_PARAM;
}
sysutil_register_cb([=](ppu_thread& ppu) -> s32
{
funcFinish(ppu, CELL_OK, userdata);
return CELL_OK;
});
return CELL_OK;
}
error_code cellPhotoDecodeFromFile(vm::cptr<char> srcHddDir, vm::cptr<char> srcHddFile, vm::ptr<CellPhotoDecodeSetParam> set_param, vm::ptr<CellPhotoDecodeReturnParam> return_param)
{
cellPhotoDecode.warning("cellPhotoDecodeFromFile(srcHddDir=%s, srcHddFile=%s, set_param=*0x%x, return_param=*0x%x)", srcHddDir, srcHddFile, set_param, return_param);
if (!srcHddDir || !srcHddFile || !set_param || !return_param)
{
return CELL_PHOTO_DECODE_ERROR_PARAM;
}
*return_param = {};
const std::string vpath = fmt::format("%s/%s", srcHddDir.get_ptr(), srcHddFile.get_ptr());
const std::string path = vfs::get(vpath);
if (!vpath.starts_with("/dev_hdd0") && !vpath.starts_with("/dev_hdd1"))
{
cellPhotoDecode.error("Source '%s' is not inside dev_hdd0 or dev_hdd1", vpath);
return CELL_PHOTO_DECODE_ERROR_ACCESS_ERROR; // TODO: is this correct?
}
if (!fs::is_file(path))
{
cellPhotoDecode.error("Source '%s' is not a file (vfs='%s')", path, vpath);
return CELL_PHOTO_DECODE_ERROR_ACCESS_ERROR; // TODO: is this correct?
}
cellPhotoDecode.notice("About to decode '%s' (set_param: width=%d, height=%d, dstBuffer=*0x%x)", path, set_param->width, set_param->height, set_param->dstBuffer);
s32 width{};
s32 height{};
if (!Emu.GetCallbacks().get_scaled_image(path, set_param->width, set_param->height, width, height, static_cast<u8*>(set_param->dstBuffer.get_ptr()), false))
{
cellPhotoDecode.error("Failed to decode '%s'", path);
return CELL_PHOTO_DECODE_ERROR_DECODE;
}
return_param->width = width;
return_param->height = height;
return CELL_OK;
}
DECLARE(ppu_module_manager::cellPhotoDecode)("cellPhotoDecodeUtil", []()
{
REG_FUNC(cellPhotoDecodeUtil, cellPhotoDecodeInitialize);
REG_FUNC(cellPhotoDecodeUtil, cellPhotoDecodeInitialize2);
REG_FUNC(cellPhotoDecodeUtil, cellPhotoDecodeFinalize);
REG_FUNC(cellPhotoDecodeUtil, cellPhotoDecodeFromFile);
});
| 5,288
|
C++
|
.cpp
| 147
| 33.768707
| 191
| 0.746181
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
5,272
|
cellFiber.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellFiber.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
#include "cellFiber.h"
LOG_CHANNEL(cellFiber);
template <>
void fmt_class_string<CellFiberError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](CellFiberError value)
{
switch (value)
{
STR_CASE(CELL_FIBER_ERROR_AGAIN);
STR_CASE(CELL_FIBER_ERROR_INVAL);
STR_CASE(CELL_FIBER_ERROR_NOMEM);
STR_CASE(CELL_FIBER_ERROR_DEADLK);
STR_CASE(CELL_FIBER_ERROR_PERM);
STR_CASE(CELL_FIBER_ERROR_BUSY);
STR_CASE(CELL_FIBER_ERROR_ABORT);
STR_CASE(CELL_FIBER_ERROR_STAT);
STR_CASE(CELL_FIBER_ERROR_ALIGN);
STR_CASE(CELL_FIBER_ERROR_NULL_POINTER);
STR_CASE(CELL_FIBER_ERROR_NOSYSINIT);
}
return unknown;
});
}
error_code _cellFiberPpuInitialize()
{
cellFiber.todo("_cellFiberPpuInitialize()");
return CELL_OK;
}
error_code _cellFiberPpuSchedulerAttributeInitialize(vm::ptr<CellFiberPpuSchedulerAttribute> attr, u32 sdkVersion)
{
cellFiber.warning("_cellFiberPpuSchedulerAttributeInitialize(attr=*0x%x, sdkVersion=0x%x)", attr, sdkVersion);
if (!attr)
{
return CELL_FIBER_ERROR_NULL_POINTER;
}
if (!attr.aligned())
{
return CELL_FIBER_ERROR_ALIGN;
}
memset(attr.get_ptr(), 0, sizeof(CellFiberPpuSchedulerAttribute));
attr->autoCheckFlags = false;
attr->autoCheckFlagsIntervalUsec = 0;
attr->debuggerSupport = false;
return CELL_OK;
}
error_code cellFiberPpuInitializeScheduler(vm::ptr<CellFiberPpuScheduler> scheduler, vm::ptr<CellFiberPpuSchedulerAttribute> attr)
{
cellFiber.todo("cellFiberPpuInitializeScheduler(scheduler=*0x%x, attr=*0x%x)", scheduler, attr);
if (!scheduler)
{
return CELL_FIBER_ERROR_NULL_POINTER;
}
if (!scheduler.aligned())
{
return CELL_FIBER_ERROR_ALIGN;
}
return CELL_OK;
}
error_code cellFiberPpuFinalizeScheduler(vm::ptr<CellFiberPpuScheduler> scheduler)
{
cellFiber.todo("cellFiberPpuFinalizeScheduler(scheduler=*0x%x)", scheduler);
if (!scheduler)
{
return CELL_FIBER_ERROR_NULL_POINTER;
}
if (!scheduler.aligned())
{
return CELL_FIBER_ERROR_ALIGN;
}
return CELL_OK;
}
error_code cellFiberPpuRunFibers(vm::ptr<CellFiberPpuScheduler> scheduler)
{
cellFiber.todo("cellFiberPpuRunFibers(scheduler=*0x%x)", scheduler);
if (!scheduler)
{
return CELL_FIBER_ERROR_NULL_POINTER;
}
if (!scheduler.aligned())
{
return CELL_FIBER_ERROR_ALIGN;
}
return CELL_OK;
}
error_code cellFiberPpuCheckFlags(vm::ptr<CellFiberPpuScheduler> scheduler)
{
cellFiber.todo("cellFiberPpuCheckFlags(scheduler=*0x%x)", scheduler);
if (!scheduler)
{
return CELL_FIBER_ERROR_NULL_POINTER;
}
if (!scheduler.aligned())
{
return CELL_FIBER_ERROR_ALIGN;
}
return CELL_OK;
}
error_code cellFiberPpuHasRunnableFiber(vm::ptr<CellFiberPpuScheduler> scheduler, vm::ptr<b8> flag)
{
cellFiber.todo("cellFiberPpuHasRunnableFiber(scheduler=*0x%x, flag=*0x%x)", scheduler, flag);
if (!scheduler || !flag)
{
return CELL_FIBER_ERROR_NULL_POINTER;
}
if (!scheduler.aligned())
{
return CELL_FIBER_ERROR_ALIGN;
}
return CELL_OK;
}
error_code _cellFiberPpuAttributeInitialize(vm::ptr<CellFiberPpuAttribute> attr, u32 sdkVersion)
{
cellFiber.warning("_cellFiberPpuAttributeInitialize(attr=*0x%x, sdkVersion=0x%x)", attr, sdkVersion);
if (!attr)
{
return CELL_FIBER_ERROR_NULL_POINTER;
}
if (!attr.aligned())
{
return CELL_FIBER_ERROR_ALIGN;
}
memset(attr.get_ptr(), 0, sizeof(CellFiberPpuAttribute));
attr->onExitCallback = vm::null;
return CELL_OK;
}
error_code cellFiberPpuCreateFiber(vm::ptr<CellFiberPpuScheduler> scheduler, vm::ptr<CellFiberPpu> fiber, vm::ptr<CellFiberPpuEntry> entry, u64 arg, u32 priority, vm::ptr<void> eaStack, u32 sizeStack, vm::cptr<CellFiberPpuAttribute> attr)
{
cellFiber.todo("cellFiberPpuCreateFiber(scheduler=*0x%x, fiber=*0x%x, entry=*0x%x, arg=0x%x, priority=%d, eaStack=*0x%x, sizeStack=0x%x, attr=*0x%x)", scheduler, fiber, entry, arg, priority, eaStack, sizeStack, attr);
if (!scheduler || !fiber || !entry || !eaStack)
{
return CELL_FIBER_ERROR_NULL_POINTER;
}
if (!scheduler.aligned() || !fiber.aligned())
{
return CELL_FIBER_ERROR_ALIGN;
}
if (priority > 3)
{
return CELL_FIBER_ERROR_INVAL;
}
return CELL_OK;
}
error_code cellFiberPpuExit(s32 status)
{
cellFiber.todo("cellFiberPpuExit(status=%d)", status);
return CELL_OK;
}
error_code cellFiberPpuYield()
{
cellFiber.todo("cellFiberPpuYield()");
return CELL_OK;
}
error_code cellFiberPpuJoinFiber(vm::ptr<CellFiberPpu> fiber, vm::ptr<s32> status)
{
cellFiber.todo("cellFiberPpuJoinFiber(fiber=*0x%x, status=*0x%x)", fiber, status);
if (!fiber || !status)
{
return CELL_FIBER_ERROR_NULL_POINTER;
}
if (!fiber.aligned())
{
return CELL_FIBER_ERROR_ALIGN;
}
return CELL_OK;
}
vm::ptr<void> cellFiberPpuSelf()
{
cellFiber.trace("cellFiberPpuSelf() -> nullptr"); // TODO
// returns fiber structure (zero for simple PPU thread)
return vm::null;
}
error_code cellFiberPpuSendSignal(vm::ptr<CellFiberPpu> fiber, vm::ptr<u32> numWorker)
{
cellFiber.todo("cellFiberPpuSendSignal(fiber=*0x%x, numWorker=*0x%x)", fiber, numWorker);
if (!fiber)
{
return CELL_FIBER_ERROR_NULL_POINTER;
}
if (!fiber.aligned())
{
return CELL_FIBER_ERROR_ALIGN;
}
return CELL_OK;
}
error_code cellFiberPpuWaitSignal()
{
cellFiber.todo("cellFiberPpuWaitSignal()");
return CELL_OK;
}
error_code cellFiberPpuWaitFlag(vm::ptr<u32> eaFlag, b8 flagValue)
{
cellFiber.todo("cellFiberPpuWaitFlag(eaFlag=*0x%x, flagValue=%d)", eaFlag, flagValue);
if (!eaFlag)
{
return CELL_FIBER_ERROR_NULL_POINTER;
}
return CELL_OK;
}
error_code cellFiberPpuGetScheduler(vm::ptr<CellFiberPpu> fiber, vm::pptr<CellFiberPpuScheduler> pScheduler)
{
cellFiber.todo("cellFiberPpuGetScheduler(fiber=*0x%x, pScheduler=**0x%x)", fiber, pScheduler);
if (!fiber || !pScheduler)
{
return CELL_FIBER_ERROR_NULL_POINTER;
}
if (!fiber.aligned())
{
return CELL_FIBER_ERROR_ALIGN;
}
return CELL_OK;
}
error_code cellFiberPpuSetPriority(u32 priority)
{
cellFiber.todo("cellFiberPpuSetPriority(priority=%d)", priority);
if (priority > 3)
{
return CELL_FIBER_ERROR_INVAL;
}
return CELL_OK;
}
error_code cellFiberPpuCheckStackLimit()
{
cellFiber.todo("cellFiberPpuCheckStackLimit()");
return CELL_OK;
}
error_code _cellFiberPpuContextAttributeInitialize(vm::ptr<CellFiberPpuContextAttribute> attr, u32 sdkVersion)
{
cellFiber.warning("_cellFiberPpuContextAttributeInitialize(attr=*0x%x, sdkVersion=0x%x)", attr, sdkVersion);
if (!attr)
{
return CELL_FIBER_ERROR_NULL_POINTER;
}
if (!attr.aligned())
{
return CELL_FIBER_ERROR_ALIGN;
}
memset(attr.get_ptr(), 0, sizeof(CellFiberPpuContextAttribute));
attr->debuggerSupport = false;
return CELL_OK;
}
error_code cellFiberPpuContextInitialize(vm::ptr<CellFiberPpuContext> context, vm::ptr<CellFiberPpuContextEntry> entry, u64 arg, vm::ptr<void> eaStack, u32 sizeStack, vm::cptr<CellFiberPpuContextAttribute> attr)
{
cellFiber.todo("cellFiberPpuContextInitialize(context=*0x%x, entry=*0x%x, arg=0x%x, eaStack=*0x%x, sizeStack=0x%x, attr=*0x%x)", context, entry, arg, eaStack, sizeStack, attr);
if (!context || !entry || !eaStack)
{
return CELL_FIBER_ERROR_NULL_POINTER;
}
if (!context.aligned())
{
return CELL_FIBER_ERROR_ALIGN;
}
return CELL_OK;
}
error_code cellFiberPpuContextFinalize(vm::ptr<CellFiberPpuContext> context)
{
cellFiber.todo("cellFiberPpuContextFinalize(context=*0x%x)", context);
if (!context)
{
return CELL_FIBER_ERROR_NULL_POINTER;
}
if (!context.aligned())
{
return CELL_FIBER_ERROR_ALIGN;
}
return CELL_OK;
}
error_code cellFiberPpuContextRun(vm::ptr<CellFiberPpuContext> context, vm::ptr<s32> cause, vm::pptr<CellFiberPpuContext> fiberFrom, vm::cptr<CellFiberPpuContextExecutionOption> option)
{
cellFiber.todo("cellFiberPpuContextRun(context=*0x%x, cause=*0x%x, fiberFrom=**0x%x, option=*0x%x)", context, cause, fiberFrom, option);
if (!context || !cause)
{
return CELL_FIBER_ERROR_NULL_POINTER;
}
if (!context.aligned())
{
return CELL_FIBER_ERROR_ALIGN;
}
return CELL_OK;
}
error_code cellFiberPpuContextSwitch(vm::ptr<CellFiberPpuContext> context, vm::pptr<CellFiberPpuContext> fiberFrom, vm::cptr<CellFiberPpuContextExecutionOption> option)
{
cellFiber.todo("cellFiberPpuContextSwitch(context=*0x%x, fiberFrom=**0x%x, option=*0x%x)", context, fiberFrom, option);
if (!context)
{
return CELL_FIBER_ERROR_NULL_POINTER;
}
if (!context.aligned())
{
return CELL_FIBER_ERROR_ALIGN;
}
return CELL_OK;
}
vm::ptr<CellFiberPpuContext> cellFiberPpuContextSelf()
{
cellFiber.todo("cellFiberPpuContextSelf()");
return vm::null;
}
error_code cellFiberPpuContextReturnToThread(s32 cause)
{
cellFiber.todo("cellFiberPpuContextReturnToThread(cause=%d)", cause);
return CELL_OK;
}
error_code cellFiberPpuContextCheckStackLimit()
{
cellFiber.todo("cellFiberPpuContextCheckStackLimit()");
return CELL_OK;
}
error_code cellFiberPpuContextRunScheduler(vm::ptr<CellFiberPpuSchedulerCallback> scheduler, u64 arg0, u64 arg1, vm::ptr<s32> cause, vm::pptr<CellFiberPpuContext> fiberFrom, vm::cptr<CellFiberPpuContextExecutionOption> option)
{
cellFiber.todo("cellFiberPpuContextRunScheduler(scheduler=*0x%x, arg0=0x%x, arg1=0x%x, cause=*0x%x, fiberFrom=**0x%x, option=*0x%x)", scheduler, arg0, arg1, cause, fiberFrom, option);
if (!scheduler || !cause)
{
return CELL_FIBER_ERROR_NULL_POINTER;
}
return CELL_OK;
}
error_code cellFiberPpuContextEnterScheduler(vm::ptr<CellFiberPpuSchedulerCallback> scheduler, u64 arg0, u64 arg1, vm::pptr<CellFiberPpuContext> fiberFrom, vm::cptr<CellFiberPpuContextExecutionOption> option)
{
cellFiber.todo("cellFiberPpuContextEnterScheduler(scheduler=*0x%x, arg0=0x%x, arg1=0x%x, fiberFrom=**0x%x, option=*0x%x)", scheduler, arg0, arg1, fiberFrom, option);
if (!scheduler)
{
return CELL_FIBER_ERROR_NULL_POINTER;
}
return CELL_OK;
}
error_code cellFiberPpuSchedulerTraceInitialize(vm::ptr<CellFiberPpuScheduler> scheduler, vm::ptr<void> buffer, u32 size, u32 mode)
{
cellFiber.todo("cellFiberPpuSchedulerTraceInitialize(scheduler=*0x%x, buffer=*0x%x, size=0x%x, mode=0x%x)", scheduler, buffer, size, mode);
if (!scheduler || !buffer)
{
return CELL_FIBER_ERROR_NULL_POINTER;
}
if (!scheduler.aligned())
{
return CELL_FIBER_ERROR_ALIGN;
}
return CELL_OK;
}
error_code cellFiberPpuSchedulerTraceFinalize(vm::ptr<CellFiberPpuScheduler> scheduler)
{
cellFiber.todo("cellFiberPpuSchedulerTraceFinalize(scheduler=*0x%x)", scheduler);
if (!scheduler)
{
return CELL_FIBER_ERROR_NULL_POINTER;
}
if (!scheduler.aligned())
{
return CELL_FIBER_ERROR_ALIGN;
}
return CELL_OK;
}
error_code cellFiberPpuSchedulerTraceStart(vm::ptr<CellFiberPpuScheduler> scheduler)
{
cellFiber.todo("cellFiberPpuSchedulerTraceStart(scheduler=*0x%x)", scheduler);
if (!scheduler)
{
return CELL_FIBER_ERROR_NULL_POINTER;
}
if (!scheduler.aligned())
{
return CELL_FIBER_ERROR_ALIGN;
}
return CELL_OK;
}
error_code cellFiberPpuSchedulerTraceStop(vm::ptr<CellFiberPpuScheduler> scheduler)
{
cellFiber.todo("cellFiberPpuSchedulerTraceStop(scheduler=*0x%x)", scheduler);
if (!scheduler)
{
return CELL_FIBER_ERROR_NULL_POINTER;
}
if (!scheduler.aligned())
{
return CELL_FIBER_ERROR_ALIGN;
}
return CELL_OK;
}
error_code _cellFiberPpuUtilWorkerControlAttributeInitialize(vm::ptr<CellFiberPpuUtilWorkerControlAttribute> attr, u32 sdkVersion)
{
cellFiber.warning("_cellFiberPpuUtilWorkerControlAttributeInitialize(attr=*0x%x, sdkVersion=0x%x)", attr, sdkVersion);
if (!attr)
{
return CELL_FIBER_ERROR_NULL_POINTER;
}
if (!attr.aligned())
{
return CELL_FIBER_ERROR_ALIGN;
}
memset(attr.get_ptr(), 0, sizeof(CellFiberPpuUtilWorkerControlAttribute));
attr->scheduler.autoCheckFlags = false;
attr->scheduler.autoCheckFlagsIntervalUsec = 0;
attr->scheduler.debuggerSupport = false;
return CELL_OK;
}
error_code cellFiberPpuUtilWorkerControlRunFibers(vm::ptr<CellFiberPpuUtilWorkerControl> control)
{
cellFiber.todo("cellFiberPpuUtilWorkerControlRunFibers(control=*0x%x)", control);
if (!control)
{
return CELL_FIBER_ERROR_NULL_POINTER;
}
if (!control.aligned())
{
return CELL_FIBER_ERROR_ALIGN;
}
return CELL_OK;
}
error_code cellFiberPpuUtilWorkerControlInitialize(vm::ptr<CellFiberPpuUtilWorkerControl> control)
{
cellFiber.todo("cellFiberPpuUtilWorkerControlInitialize(control=*0x%x)", control);
if (!control)
{
return CELL_FIBER_ERROR_NULL_POINTER;
}
if (!control.aligned())
{
return CELL_FIBER_ERROR_ALIGN;
}
return CELL_OK;
}
error_code cellFiberPpuUtilWorkerControlSetPollingMode(vm::ptr<CellFiberPpuUtilWorkerControl> control, s32 mode, s32 timeout)
{
cellFiber.todo("cellFiberPpuUtilWorkerControlSetPollingMode(control=*0x%x, mode=%d, timeout=%d)", control, mode, timeout);
if (!control)
{
return CELL_FIBER_ERROR_NULL_POINTER;
}
if (!control.aligned())
{
return CELL_FIBER_ERROR_ALIGN;
}
return CELL_OK;
}
error_code cellFiberPpuUtilWorkerControlJoinFiber(vm::ptr<CellFiberPpuUtilWorkerControl> control, vm::ptr<CellFiberPpu> fiber, vm::ptr<s32> exitCode)
{
cellFiber.todo("cellFiberPpuUtilWorkerControlJoinFiber(control=*0x%x, fiber=*0x%x, exitCode=*0x%x)", control, fiber, exitCode);
if (!control)
{
return CELL_FIBER_ERROR_NULL_POINTER;
}
if (!control.aligned())
{
return CELL_FIBER_ERROR_ALIGN;
}
return CELL_OK;
}
error_code cellFiberPpuUtilWorkerControlDisconnectEventQueue()
{
cellFiber.todo("cellFiberPpuUtilWorkerControlDisconnectEventQueue()");
return CELL_OK;
}
error_code cellFiberPpuUtilWorkerControlSendSignal(vm::ptr<CellFiberPpu> fiber, vm::ptr<u32> numWorker)
{
cellFiber.todo("cellFiberPpuUtilWorkerControlSendSignal(fiber=*0x%x, numWorker=*0x%x)", fiber, numWorker);
if (!fiber)
{
return CELL_FIBER_ERROR_NULL_POINTER;
}
if (!fiber.aligned())
{
return CELL_FIBER_ERROR_ALIGN;
}
return CELL_OK;
}
error_code cellFiberPpuUtilWorkerControlConnectEventQueueToSpurs()
{
cellFiber.todo("cellFiberPpuUtilWorkerControlConnectEventQueueToSpurs()");
return CELL_OK;
}
error_code cellFiberPpuUtilWorkerControlFinalize(vm::ptr<CellFiberPpuUtilWorkerControl> control)
{
cellFiber.todo("cellFiberPpuUtilWorkerControlFinalize(control=*0x%x)", control);
if (!control)
{
return CELL_FIBER_ERROR_NULL_POINTER;
}
if (!control.aligned())
{
return CELL_FIBER_ERROR_ALIGN;
}
return CELL_OK;
}
error_code cellFiberPpuUtilWorkerControlWakeup(vm::ptr<CellFiberPpuUtilWorkerControl> control)
{
cellFiber.todo("cellFiberPpuUtilWorkerControlWakeup(control=*0x%x)", control);
if (!control)
{
return CELL_FIBER_ERROR_NULL_POINTER;
}
if (!control.aligned())
{
return CELL_FIBER_ERROR_ALIGN;
}
return CELL_OK;
}
error_code cellFiberPpuUtilWorkerControlCreateFiber(vm::ptr<CellFiberPpuUtilWorkerControl> control, vm::ptr<CellFiberPpu> fiber, vm::ptr<CellFiberPpuEntry> entry, u64 arg, u32 priority, vm::ptr<void> eaStack, u32 sizeStack, vm::cptr<CellFiberPpuAttribute> attr)
{
cellFiber.todo("cellFiberPpuUtilWorkerControlCreateFiber(control=*0x%x, fiber=*0x%x, entry=*0x%x, arg=0x%x, priority=%d, eaStack=*0x%x, sizeStack=0x%x, attr=*0x%x)", control, fiber, entry, arg, priority, eaStack, sizeStack, attr);
if (!control)
{
return CELL_FIBER_ERROR_NULL_POINTER;
}
if (!control.aligned())
{
return CELL_FIBER_ERROR_ALIGN;
}
return CELL_OK;
}
error_code cellFiberPpuUtilWorkerControlShutdown(vm::ptr<CellFiberPpuUtilWorkerControl> control)
{
cellFiber.todo("cellFiberPpuUtilWorkerControlShutdown(control=*0x%x)", control);
if (!control)
{
return CELL_FIBER_ERROR_NULL_POINTER;
}
if (!control.aligned())
{
return CELL_FIBER_ERROR_ALIGN;
}
return CELL_OK;
}
error_code cellFiberPpuUtilWorkerControlCheckFlags(vm::ptr<CellFiberPpuUtilWorkerControl> control, b8 wakingUp)
{
cellFiber.todo("cellFiberPpuUtilWorkerControlCheckFlags(control=*0x%x, wakingUp=%d)", control, wakingUp);
if (!control)
{
return CELL_FIBER_ERROR_NULL_POINTER;
}
if (!control.aligned())
{
return CELL_FIBER_ERROR_ALIGN;
}
return CELL_OK;
}
error_code cellFiberPpuUtilWorkerControlInitializeWithAttribute(vm::ptr<CellFiberPpuUtilWorkerControl> control, vm::ptr<CellFiberPpuUtilWorkerControlAttribute> attr)
{
cellFiber.todo("cellFiberPpuUtilWorkerControlInitializeWithAttribute(control=*0x%x, attr=*0x%x)", control, attr);
if (!control)
{
return CELL_FIBER_ERROR_NULL_POINTER;
}
if (!control.aligned())
{
return CELL_FIBER_ERROR_ALIGN;
}
return CELL_OK;
}
DECLARE(ppu_module_manager::cellFiber)("cellFiber", []()
{
REG_FUNC(cellFiber, _cellFiberPpuInitialize);
REG_FUNC(cellFiber, _cellFiberPpuSchedulerAttributeInitialize);
REG_FUNC(cellFiber, cellFiberPpuInitializeScheduler);
REG_FUNC(cellFiber, cellFiberPpuFinalizeScheduler);
REG_FUNC(cellFiber, cellFiberPpuRunFibers);
REG_FUNC(cellFiber, cellFiberPpuCheckFlags);
REG_FUNC(cellFiber, cellFiberPpuHasRunnableFiber);
REG_FUNC(cellFiber, _cellFiberPpuAttributeInitialize);
REG_FUNC(cellFiber, cellFiberPpuCreateFiber);
REG_FUNC(cellFiber, cellFiberPpuExit);
REG_FUNC(cellFiber, cellFiberPpuYield);
REG_FUNC(cellFiber, cellFiberPpuJoinFiber);
REG_FUNC(cellFiber, cellFiberPpuSelf);
REG_FUNC(cellFiber, cellFiberPpuSendSignal);
REG_FUNC(cellFiber, cellFiberPpuWaitSignal);
REG_FUNC(cellFiber, cellFiberPpuWaitFlag);
REG_FUNC(cellFiber, cellFiberPpuGetScheduler);
REG_FUNC(cellFiber, cellFiberPpuSetPriority);
REG_FUNC(cellFiber, cellFiberPpuCheckStackLimit);
REG_FUNC(cellFiber, _cellFiberPpuContextAttributeInitialize);
REG_FUNC(cellFiber, cellFiberPpuContextInitialize);
REG_FUNC(cellFiber, cellFiberPpuContextFinalize);
REG_FUNC(cellFiber, cellFiberPpuContextRun);
REG_FUNC(cellFiber, cellFiberPpuContextSwitch);
REG_FUNC(cellFiber, cellFiberPpuContextSelf);
REG_FUNC(cellFiber, cellFiberPpuContextReturnToThread);
REG_FUNC(cellFiber, cellFiberPpuContextCheckStackLimit);
REG_FUNC(cellFiber, cellFiberPpuContextRunScheduler);
REG_FUNC(cellFiber, cellFiberPpuContextEnterScheduler);
REG_FUNC(cellFiber, cellFiberPpuSchedulerTraceInitialize);
REG_FUNC(cellFiber, cellFiberPpuSchedulerTraceFinalize);
REG_FUNC(cellFiber, cellFiberPpuSchedulerTraceStart);
REG_FUNC(cellFiber, cellFiberPpuSchedulerTraceStop);
REG_FUNC(cellFiber, _cellFiberPpuUtilWorkerControlAttributeInitialize);
REG_FUNC(cellFiber, cellFiberPpuUtilWorkerControlRunFibers);
REG_FUNC(cellFiber, cellFiberPpuUtilWorkerControlInitialize);
REG_FUNC(cellFiber, cellFiberPpuUtilWorkerControlSetPollingMode);
REG_FUNC(cellFiber, cellFiberPpuUtilWorkerControlJoinFiber);
REG_FUNC(cellFiber, cellFiberPpuUtilWorkerControlDisconnectEventQueue);
REG_FUNC(cellFiber, cellFiberPpuUtilWorkerControlSendSignal);
REG_FUNC(cellFiber, cellFiberPpuUtilWorkerControlConnectEventQueueToSpurs);
REG_FUNC(cellFiber, cellFiberPpuUtilWorkerControlFinalize);
REG_FUNC(cellFiber, cellFiberPpuUtilWorkerControlWakeup);
REG_FUNC(cellFiber, cellFiberPpuUtilWorkerControlCreateFiber);
REG_FUNC(cellFiber, cellFiberPpuUtilWorkerControlShutdown);
REG_FUNC(cellFiber, cellFiberPpuUtilWorkerControlCheckFlags);
REG_FUNC(cellFiber, cellFiberPpuUtilWorkerControlInitializeWithAttribute);
});
| 19,127
|
C++
|
.cpp
| 600
| 29.676667
| 261
| 0.78789
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| true
| false
| false
| true
| false
| false
|
5,273
|
cellSpudll.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellSpudll.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
#include "cellSpudll.h"
LOG_CHANNEL(cellSpudll);
template<>
void fmt_class_string<CellSpudllError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_SPUDLL_ERROR_INVAL);
STR_CASE(CELL_SPUDLL_ERROR_STAT);
STR_CASE(CELL_SPUDLL_ERROR_ALIGN);
STR_CASE(CELL_SPUDLL_ERROR_NULL_POINTER);
STR_CASE(CELL_SPUDLL_ERROR_SRCH);
STR_CASE(CELL_SPUDLL_ERROR_UNDEF);
STR_CASE(CELL_SPUDLL_ERROR_FATAL);
}
return unknown;
});
}
error_code cellSpudllGetImageSize(vm::ptr<u32> psize, vm::cptr<void> so_elf, vm::cptr<CellSpudllHandleConfig> config)
{
cellSpudll.todo("cellSpudllGetImageSize(psize=*0x%x, so_elf=*0x%x, config=*0x%x)", psize, so_elf, config);
if (!psize || !so_elf)
{
return CELL_SPUDLL_ERROR_NULL_POINTER;
}
// todo
return CELL_OK;
}
error_code cellSpudllHandleConfigSetDefaultValues(vm::ptr<CellSpudllHandleConfig> config)
{
cellSpudll.trace("cellSpudllHandleConfigSetDefaultValues(config=*0x%x)", config);
if (!config)
{
return CELL_SPUDLL_ERROR_NULL_POINTER;
}
config->mode = 0;
config->dmaTag = 0;
config->numMaxReferred = 16;
config->numMaxDepend = 16;
config->unresolvedSymbolValueForFunc = vm::null;
config->unresolvedSymbolValueForObject = vm::null;
config->unresolvedSymbolValueForOther = vm::null;
std::memset(config->__reserved__, 0, sizeof(config->__reserved__));
return CELL_OK;
}
DECLARE(ppu_module_manager::cellSpudll)("cellSpudll", []()
{
REG_FUNC(cellSpudll, cellSpudllGetImageSize);
REG_FUNC(cellSpudll, cellSpudllHandleConfigSetDefaultValues).flag(MFF_PERFECT);
});
| 1,661
|
C++
|
.cpp
| 54
| 28.407407
| 117
| 0.752357
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| true
| false
| false
| true
| false
| false
|
5,274
|
cellMouse.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellMouse.cpp
|
#include "stdafx.h"
#include "Emu/IdManager.h"
#include "Emu/System.h"
#include "Emu/Cell/PPUModule.h"
#include "Emu/Io/MouseHandler.h"
#include "cellMouse.h"
error_code sys_config_start(ppu_thread& ppu);
error_code sys_config_stop(ppu_thread& ppu);
extern bool is_input_allowed();
LOG_CHANNEL(cellMouse);
template<>
void fmt_class_string<CellMouseError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_MOUSE_ERROR_FATAL);
STR_CASE(CELL_MOUSE_ERROR_INVALID_PARAMETER);
STR_CASE(CELL_MOUSE_ERROR_ALREADY_INITIALIZED);
STR_CASE(CELL_MOUSE_ERROR_UNINITIALIZED);
STR_CASE(CELL_MOUSE_ERROR_RESOURCE_ALLOCATION_FAILED);
STR_CASE(CELL_MOUSE_ERROR_DATA_READ_FAILED);
STR_CASE(CELL_MOUSE_ERROR_NO_DEVICE);
STR_CASE(CELL_MOUSE_ERROR_SYS_SETTING_FAILED);
}
return unknown;
});
}
error_code cellMouseInit(ppu_thread& ppu, u32 max_connect)
{
cellMouse.notice("cellMouseInit(max_connect=%d)", max_connect);
auto& handler = g_fxo->get<MouseHandlerBase>();
auto init = handler.init.init();
if (!init)
return CELL_MOUSE_ERROR_ALREADY_INITIALIZED;
if (max_connect == 0 || max_connect > CELL_MAX_MICE)
{
init.cancel();
return CELL_MOUSE_ERROR_INVALID_PARAMETER;
}
sys_config_start(ppu);
handler.Init(std::min(max_connect, 7u));
return CELL_OK;
}
error_code cellMouseClearBuf(u32 port_no)
{
cellMouse.trace("cellMouseClearBuf(port_no=%d)", port_no);
auto& handler = g_fxo->get<MouseHandlerBase>();
const auto init = handler.init.access();
if (!init)
return CELL_MOUSE_ERROR_UNINITIALIZED;
if (port_no >= CELL_MAX_MICE)
{
return CELL_MOUSE_ERROR_INVALID_PARAMETER;
}
const MouseInfo& current_info = handler.GetInfo();
if (port_no >= handler.GetMice().size() || current_info.status[port_no] != CELL_MOUSE_STATUS_CONNECTED)
{
return not_an_error(CELL_MOUSE_ERROR_NO_DEVICE);
}
handler.GetDataList(port_no).clear();
handler.GetTabletDataList(port_no).clear();
MouseRawData& raw_data = handler.GetRawData(port_no);
raw_data.len = 0;
for (int i = 0; i < CELL_MOUSE_MAX_CODES; i++)
{
raw_data.data[i] = 0;
}
return CELL_OK;
}
error_code cellMouseEnd(ppu_thread& ppu)
{
cellMouse.notice("cellMouseEnd()");
auto& handler = g_fxo->get<MouseHandlerBase>();
const auto init = handler.init.reset();
if (!init)
return CELL_MOUSE_ERROR_UNINITIALIZED;
// TODO
sys_config_stop(ppu);
return CELL_OK;
}
error_code cellMouseGetInfo(vm::ptr<CellMouseInfo> info)
{
cellMouse.trace("cellMouseGetInfo(info=*0x%x)", info);
auto& handler = g_fxo->get<MouseHandlerBase>();
const auto init = handler.init.access();
if (!init)
return CELL_MOUSE_ERROR_UNINITIALIZED;
if (!info)
{
return CELL_MOUSE_ERROR_INVALID_PARAMETER;
}
std::memset(info.get_ptr(), 0, info.size());
const MouseInfo& current_info = handler.GetInfo();
info->max_connect = current_info.max_connect;
info->now_connect = current_info.now_connect;
info->info = current_info.info;
for (u32 i = 0; i < CELL_MAX_MICE; i++)
{
info->vendor_id[i] = current_info.vendor_id[i];
info->product_id[i] = current_info.product_id[i];
info->status[i] = current_info.status[i];
}
return CELL_OK;
}
error_code cellMouseInfoTabletMode(u32 port_no, vm::ptr<CellMouseInfoTablet> info)
{
cellMouse.trace("cellMouseInfoTabletMode(port_no=%d, info=*0x%x)", port_no, info);
auto& handler = g_fxo->get<MouseHandlerBase>();
const auto init = handler.init.access();
if (!init)
return CELL_MOUSE_ERROR_UNINITIALIZED;
// only check for port_no here. Tests show that valid ports lead to ERROR_FATAL with disconnected devices regardless of info
if (port_no >= CELL_MAX_MICE)
{
return CELL_MOUSE_ERROR_INVALID_PARAMETER;
}
const MouseInfo& current_info = handler.GetInfo();
if (port_no >= handler.GetMice().size() || current_info.status[port_no] != CELL_MOUSE_STATUS_CONNECTED)
{
return CELL_MOUSE_ERROR_FATAL;
}
if (!info)
{
return CELL_EFAULT; // we don't get CELL_MOUSE_ERROR_INVALID_PARAMETER here :thonkang:
}
info->is_supported = current_info.tablet_is_supported[port_no];
info->mode = current_info.mode[port_no];
// TODO: decr returns CELL_ENOTSUP ... How should we handle this?
return CELL_OK;
}
error_code cellMouseGetData(u32 port_no, vm::ptr<CellMouseData> data)
{
cellMouse.trace("cellMouseGetData(port_no=%d, data=*0x%x)", port_no, data);
auto& handler = g_fxo->get<MouseHandlerBase>();
const auto init = handler.init.access();
if (!init)
return CELL_MOUSE_ERROR_UNINITIALIZED;
if (port_no >= CELL_MAX_MICE || !data)
{
return CELL_MOUSE_ERROR_INVALID_PARAMETER;
}
std::lock_guard lock(handler.mutex);
const MouseInfo& current_info = handler.GetInfo();
if (port_no >= handler.GetMice().size() || current_info.status[port_no] != CELL_MOUSE_STATUS_CONNECTED)
{
return not_an_error(CELL_MOUSE_ERROR_NO_DEVICE);
}
std::memset(data.get_ptr(), 0, data.size());
// TODO: check if (current_info.mode[port_no] != CELL_MOUSE_INFO_TABLET_MOUSE_MODE) has any impact
MouseDataList& data_list = handler.GetDataList(port_no);
if (data_list.empty() || current_info.is_null_handler || (current_info.info & CELL_MOUSE_INFO_INTERCEPTED) || !is_input_allowed())
{
data_list.clear();
return CELL_OK;
}
const MouseData current_data = data_list.front();
data->update = current_data.update;
data->buttons = current_data.buttons;
data->x_axis = current_data.x_axis;
data->y_axis = current_data.y_axis;
data->wheel = current_data.wheel;
data->tilt = current_data.tilt;
data_list.pop_front();
return CELL_OK;
}
error_code cellMouseGetDataList(u32 port_no, vm::ptr<CellMouseDataList> data)
{
cellMouse.trace("cellMouseGetDataList(port_no=%d, data=0x%x)", port_no, data);
auto& handler = g_fxo->get<MouseHandlerBase>();
const auto init = handler.init.access();
if (!init)
return CELL_MOUSE_ERROR_UNINITIALIZED;
if (port_no >= CELL_MAX_MICE || !data)
{
return CELL_MOUSE_ERROR_INVALID_PARAMETER;
}
std::lock_guard lock(handler.mutex);
const MouseInfo& current_info = handler.GetInfo();
if (port_no >= handler.GetMice().size() || current_info.status[port_no] != CELL_MOUSE_STATUS_CONNECTED)
{
return not_an_error(CELL_MOUSE_ERROR_NO_DEVICE);
}
std::memset(data.get_ptr(), 0, data.size());
// TODO: check if (current_info.mode[port_no] != CELL_MOUSE_INFO_TABLET_MOUSE_MODE) has any impact
MouseDataList& list = handler.GetDataList(port_no);
if (list.empty() || current_info.is_null_handler || (current_info.info & CELL_MOUSE_INFO_INTERCEPTED) || !is_input_allowed())
{
list.clear();
return CELL_OK;
}
data->list_num = std::min<u32>(CELL_MOUSE_MAX_DATA_LIST_NUM, static_cast<u32>(list.size()));
int i = 0;
for (auto it = list.begin(); it != list.end() && i < CELL_MOUSE_MAX_DATA_LIST_NUM; ++it, ++i)
{
data->list[i].update = it->update;
data->list[i].buttons = it->buttons;
data->list[i].x_axis = it->x_axis;
data->list[i].y_axis = it->y_axis;
data->list[i].wheel = it->wheel;
data->list[i].tilt = it->tilt;
}
list.clear();
return CELL_OK;
}
error_code cellMouseSetTabletMode(u32 port_no, u32 mode)
{
cellMouse.warning("cellMouseSetTabletMode(port_no=%d, mode=%d)", port_no, mode);
auto& handler = g_fxo->get<MouseHandlerBase>();
const auto init = handler.init.access();
if (!init)
return CELL_MOUSE_ERROR_UNINITIALIZED;
// only check for port_no here. Tests show that valid ports lead to ERROR_FATAL with disconnected devices regardless of info
if (port_no >= CELL_MAX_MICE)
{
return CELL_MOUSE_ERROR_INVALID_PARAMETER;
}
MouseInfo& current_info = handler.GetInfo();
if (port_no >= handler.GetMice().size() || current_info.status[port_no] != CELL_MOUSE_STATUS_CONNECTED)
{
return CELL_MOUSE_ERROR_FATAL;
}
if (mode != CELL_MOUSE_INFO_TABLET_MOUSE_MODE && mode != CELL_MOUSE_INFO_TABLET_TABLET_MODE)
{
return CELL_EINVAL; // lol... why not CELL_MOUSE_ERROR_INVALID_PARAMETER. Sony is drunk
}
current_info.mode[port_no] = mode;
// TODO: decr returns CELL_ENOTSUP ... How should we handle this?
return CELL_OK;
}
error_code cellMouseGetTabletDataList(u32 port_no, vm::ptr<CellMouseTabletDataList> data)
{
cellMouse.warning("cellMouseGetTabletDataList(port_no=%d, data=0x%x)", port_no, data);
auto& handler = g_fxo->get<MouseHandlerBase>();
const auto init = handler.init.access();
if (!init)
return CELL_MOUSE_ERROR_UNINITIALIZED;
if (port_no >= CELL_MAX_MICE || !data)
{
return CELL_MOUSE_ERROR_INVALID_PARAMETER;
}
const MouseInfo& current_info = handler.GetInfo();
if (port_no >= handler.GetMice().size() || current_info.status[port_no] != CELL_MOUSE_STATUS_CONNECTED)
{
return not_an_error(CELL_MOUSE_ERROR_NO_DEVICE);
}
std::memset(data.get_ptr(), 0, data.size());
// TODO: decr tests show that CELL_MOUSE_ERROR_DATA_READ_FAILED is returned when a mouse is connected
// TODO: check if (current_info.mode[port_no] != CELL_MOUSE_INFO_TABLET_TABLET_MODE) has any impact
MouseTabletDataList& list = handler.GetTabletDataList(port_no);
if (list.empty() || current_info.is_null_handler || (current_info.info & CELL_MOUSE_INFO_INTERCEPTED) || !is_input_allowed())
{
list.clear();
return CELL_OK;
}
data->list_num = std::min<u32>(CELL_MOUSE_MAX_DATA_LIST_NUM, static_cast<u32>(list.size()));
int i = 0;
for (auto it = list.begin(); it != list.end() && i < CELL_MOUSE_MAX_DATA_LIST_NUM; ++it, ++i)
{
data->list[i].len = it->len;
it->len = 0;
for (int k = 0; k < CELL_MOUSE_MAX_CODES; k++)
{
data->list[i].data[k] = it->data[k];
it->data[k] = 0;
}
}
list.clear();
return CELL_OK;
}
error_code cellMouseGetRawData(u32 port_no, vm::ptr<CellMouseRawData> data)
{
cellMouse.trace("cellMouseGetRawData(port_no=%d, data=*0x%x)", port_no, data);
auto& handler = g_fxo->get<MouseHandlerBase>();
const auto init = handler.init.access();
if (!init)
return CELL_MOUSE_ERROR_UNINITIALIZED;
if (port_no >= CELL_MAX_MICE || !data)
{
return CELL_MOUSE_ERROR_INVALID_PARAMETER;
}
const MouseInfo& current_info = handler.GetInfo();
if (port_no >= handler.GetMice().size() || current_info.status[port_no] != CELL_MOUSE_STATUS_CONNECTED)
{
return not_an_error(CELL_MOUSE_ERROR_NO_DEVICE);
}
std::memset(data.get_ptr(), 0, data.size());
// TODO: decr tests show that CELL_MOUSE_ERROR_DATA_READ_FAILED is returned when a mouse is connected
// TODO: check if (current_info.mode[port_no] != CELL_MOUSE_INFO_TABLET_MOUSE_MODE) has any impact
MouseRawData& current_data = handler.GetRawData(port_no);
if (current_info.is_null_handler || (current_info.info & CELL_MOUSE_INFO_INTERCEPTED) || !is_input_allowed())
{
current_data = {};
return CELL_OK;
}
data->len = current_data.len;
current_data.len = 0;
for (int i = 0; i < CELL_MOUSE_MAX_CODES; i++)
{
data->data[i] = current_data.data[i];
current_data.data[i] = 0;
}
return CELL_OK;
}
void cellMouse_init()
{
REG_FUNC(sys_io, cellMouseInit);
REG_FUNC(sys_io, cellMouseClearBuf);
REG_FUNC(sys_io, cellMouseEnd);
REG_FUNC(sys_io, cellMouseGetInfo);
REG_FUNC(sys_io, cellMouseInfoTabletMode);
REG_FUNC(sys_io, cellMouseGetData);
REG_FUNC(sys_io, cellMouseGetDataList);
REG_FUNC(sys_io, cellMouseSetTabletMode);
REG_FUNC(sys_io, cellMouseGetTabletDataList);
REG_FUNC(sys_io, cellMouseGetRawData);
}
| 11,311
|
C++
|
.cpp
| 318
| 33.084906
| 131
| 0.719043
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| false
| false
|
5,275
|
sys_libc.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/sys_libc.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
LOG_CHANNEL(sys_libc);
vm::ptr<void> sys_libc_memcpy(vm::ptr<void> dst, vm::cptr<void> src, u32 size)
{
sys_libc.trace("memcpy(dst=*0x%x, src=*0x%x, size=0x%x)", dst, src, size);
::memcpy(dst.get_ptr(), src.get_ptr(), size);
return dst;
}
vm::ptr<void> sys_libc_memset(vm::ptr<void> dst, s32 value, u32 size)
{
sys_libc.trace("memset(dst=*0x%x, value=0x%x, size=0x%x)", dst, value, size);
::memset(dst.get_ptr(), value, size);
return dst;
}
vm::ptr<void> sys_libc_memmove(vm::ptr<void> dst, vm::ptr<void> src, u32 size)
{
sys_libc.trace("memmove(dst=*0x%x, src=*0x%x, size=0x%x)", dst, src, size);
::memmove(dst.get_ptr(), src.get_ptr(), size);
return dst;
}
u32 sys_libc_memcmp(vm::ptr<void> buf1, vm::ptr<void> buf2, u32 size)
{
sys_libc.trace("memcmp(buf1=*0x%x, buf2=*0x%x, size=0x%x)", buf1, buf2, size);
return ::memcmp(buf1.get_ptr(), buf2.get_ptr(), size);
}
DECLARE(ppu_module_manager::sys_libc)("sys_libc", []()
{
REG_FNID(sys_libc, "memcpy", sys_libc_memcpy)/*.flag(MFF_FORCED_HLE)*/;
REG_FNID(sys_libc, "memset", sys_libc_memset);
REG_FNID(sys_libc, "memmove", sys_libc_memmove);
REG_FNID(sys_libc, "memcmp", sys_libc_memcmp);
});
| 1,219
|
C++
|
.cpp
| 33
| 35.212121
| 79
| 0.670348
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| true
| false
| false
| true
| false
| false
|
5,276
|
cellPesmUtility.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellPesmUtility.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
LOG_CHANNEL(cellPesmUtility);
error_code cellPesmCloseDevice()
{
UNIMPLEMENTED_FUNC(cellPesmUtility);
return CELL_OK;
}
error_code cellPesmEncryptSample()
{
UNIMPLEMENTED_FUNC(cellPesmUtility);
return CELL_OK;
}
error_code cellPesmEncryptSample2()
{
UNIMPLEMENTED_FUNC(cellPesmUtility);
return CELL_OK;
}
error_code cellPesmEndMovieRec()
{
UNIMPLEMENTED_FUNC(cellPesmUtility);
return CELL_OK;
}
error_code cellPesmFinalize()
{
UNIMPLEMENTED_FUNC(cellPesmUtility);
return CELL_OK;
}
error_code cellPesmFinalize2()
{
UNIMPLEMENTED_FUNC(cellPesmUtility);
return CELL_OK;
}
error_code cellPesmGetSinf()
{
UNIMPLEMENTED_FUNC(cellPesmUtility);
return CELL_OK;
}
error_code cellPesmInitEntry()
{
UNIMPLEMENTED_FUNC(cellPesmUtility);
return CELL_OK;
}
error_code cellPesmInitEntry2()
{
UNIMPLEMENTED_FUNC(cellPesmUtility);
return CELL_OK;
}
error_code cellPesmInitialize()
{
UNIMPLEMENTED_FUNC(cellPesmUtility);
return CELL_OK;
}
error_code cellPesmLoadAsync()
{
UNIMPLEMENTED_FUNC(cellPesmUtility);
return CELL_OK;
}
error_code cellPesmOpenDevice()
{
UNIMPLEMENTED_FUNC(cellPesmUtility);
return CELL_OK;
}
error_code cellPesmPrepareRec()
{
UNIMPLEMENTED_FUNC(cellPesmUtility);
return CELL_OK;
}
error_code cellPesmStartMovieRec()
{
UNIMPLEMENTED_FUNC(cellPesmUtility);
return CELL_OK;
}
error_code cellPesmUnloadAsync()
{
UNIMPLEMENTED_FUNC(cellPesmUtility);
return CELL_OK;
}
DECLARE(ppu_module_manager::cellPesmUtility)("cellPesmUtility", []()
{
REG_FUNC(cellPesmUtility, cellPesmInitialize);
REG_FUNC(cellPesmUtility, cellPesmFinalize);
REG_FUNC(cellPesmUtility, cellPesmLoadAsync);
REG_FUNC(cellPesmUtility, cellPesmOpenDevice);
REG_FUNC(cellPesmUtility, cellPesmEncryptSample);
REG_FUNC(cellPesmUtility, cellPesmUnloadAsync);
REG_FUNC(cellPesmUtility, cellPesmGetSinf);
REG_FUNC(cellPesmUtility, cellPesmStartMovieRec);
REG_FUNC(cellPesmUtility, cellPesmInitEntry);
REG_FUNC(cellPesmUtility, cellPesmEndMovieRec);
REG_FUNC(cellPesmUtility, cellPesmEncryptSample2);
REG_FUNC(cellPesmUtility, cellPesmFinalize2);
REG_FUNC(cellPesmUtility, cellPesmCloseDevice);
REG_FUNC(cellPesmUtility, cellPesmInitEntry2);
REG_FUNC(cellPesmUtility, cellPesmPrepareRec);
});
| 2,269
|
C++
|
.cpp
| 96
| 21.989583
| 68
| 0.830705
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| true
| false
| false
| true
| false
| false
|
5,277
|
cellCelp8Enc.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellCelp8Enc.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
#include "cellCelp8Enc.h"
LOG_CHANNEL(cellCelp8Enc);
template <>
void fmt_class_string<CellCelp8EncError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](CellCelp8EncError value)
{
switch (value)
{
STR_CASE(CELL_CELP8ENC_ERROR_FAILED);
STR_CASE(CELL_CELP8ENC_ERROR_SEQ);
STR_CASE(CELL_CELP8ENC_ERROR_ARG);
STR_CASE(CELL_CELP8ENC_ERROR_CORE_FAILED);
STR_CASE(CELL_CELP8ENC_ERROR_CORE_SEQ);
STR_CASE(CELL_CELP8ENC_ERROR_CORE_ARG);
}
return unknown;
});
}
error_code cellCelp8EncQueryAttr(vm::ptr<CellCelp8EncAttr> attr)
{
cellCelp8Enc.todo("cellCelp8EncQueryAttr(attr=*0x%x)", attr);
return CELL_OK;
}
error_code cellCelp8EncOpen(vm::ptr<CellCelp8EncResource> res, vm::pptr<void> handle)
{
cellCelp8Enc.todo("cellCelp8EncOpen(res=*0x%x, handle=*0x%x)", res, handle);
return CELL_OK;
}
error_code cellCelp8EncOpenEx(vm::ptr<CellCelp8EncResource> res, vm::pptr<void> handle)
{
cellCelp8Enc.todo("cellCelp8EncOpenEx(res=*0x%x, handle=*0x%x)", res, handle);
return CELL_OK;
}
error_code cellCelp8EncClose(vm::ptr<void> handle)
{
cellCelp8Enc.todo("cellCelp8EncClose(handle=*0x%x)", handle);
return CELL_OK;
}
error_code cellCelp8EncStart(vm::ptr<void> handle, vm::ptr<CellCelp8EncParam> param)
{
cellCelp8Enc.todo("cellCelp8EncStart(handle=*0x%x, param=*0x%x)", handle, param);
return CELL_OK;
}
error_code cellCelp8EncEnd(vm::ptr<void> handle)
{
cellCelp8Enc.todo("cellCelp8EncEnd(handle=*0x%x)", handle);
return CELL_OK;
}
error_code cellCelp8EncEncodeFrame(vm::ptr<void> handle, vm::ptr<CellCelp8EncPcmInfo> frameInfo)
{
cellCelp8Enc.todo("cellCelp8EncEncodeFrame(handle=*0x%x, frameInfo=*0x%x)", handle, frameInfo);
return CELL_OK;
}
error_code cellCelp8EncWaitForOutput(vm::ptr<void> handle)
{
cellCelp8Enc.todo("cellCelp8EncWaitForOutput(handle=*0x%x)", handle);
return CELL_OK;
}
error_code cellCelp8EncGetAu(vm::ptr<void> handle, vm::ptr<void> outBuffer, vm::ptr<CellCelp8EncAuInfo> auItem)
{
cellCelp8Enc.todo("cellCelp8EncGetAu(handle=*0x%x, outBuffer=*0x%x, auItem=*0x%x)", handle, outBuffer, auItem);
return CELL_OK;
}
DECLARE(ppu_module_manager::cellCelp8Enc)("cellCelp8Enc", []()
{
REG_FUNC(cellCelp8Enc, cellCelp8EncQueryAttr);
REG_FUNC(cellCelp8Enc, cellCelp8EncOpen);
REG_FUNC(cellCelp8Enc, cellCelp8EncOpenEx);
REG_FUNC(cellCelp8Enc, cellCelp8EncClose);
REG_FUNC(cellCelp8Enc, cellCelp8EncStart);
REG_FUNC(cellCelp8Enc, cellCelp8EncEnd);
REG_FUNC(cellCelp8Enc, cellCelp8EncEncodeFrame);
REG_FUNC(cellCelp8Enc, cellCelp8EncWaitForOutput);
REG_FUNC(cellCelp8Enc, cellCelp8EncGetAu);
});
| 2,627
|
C++
|
.cpp
| 78
| 31.858974
| 112
| 0.779487
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| true
| false
| false
| true
| false
| false
|
5,278
|
sys_libc_.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/sys_libc_.cpp
|
#include "stdafx.h"
#include "Emu/Cell/lv2/sys_tty.h"
#include "Emu/Cell/PPUModule.h"
#include "Utilities/cfmt.h"
LOG_CHANNEL(sysPrxForUser);
// cfmt implementation (TODO)
using qsortcmp = s32(vm::cptr<void> e1, vm::cptr<void> e2);
struct ps3_fmt_src
{
ppu_thread* ctx;
u32 g_count;
static bool test(usz)
{
return true;
}
template <typename T>
T get(usz index) const
{
const u32 i = static_cast<u32>(index) + g_count;
return ppu_gpr_cast<T>(i < 8 ? ctx->gpr[3 + i] : +*ctx->get_stack_arg(i));
}
void skip(usz extra)
{
g_count += static_cast<u32>(extra) + 1;
}
usz fmt_string(std::string& out, usz extra) const
{
const usz start = out.size();
out += vm::_ptr<const char>(get<u32>(extra));
return out.size() - start;
}
static usz type(usz)
{
return 0;
}
static constexpr usz size_char = 1;
static constexpr usz size_short = 2;
static constexpr usz size_int = 4;
static constexpr usz size_long = 4;
static constexpr usz size_llong = 8;
static constexpr usz size_size = 4;
static constexpr usz size_max = 8;
static constexpr usz size_diff = 4;
};
template <>
f64 ps3_fmt_src::get<f64>(usz index) const
{
return std::bit_cast<f64>(get<u64>(index));
}
static std::string ps3_fmt(ppu_thread& context, vm::cptr<char> fmt, u32 g_count)
{
std::string result;
cfmt_append(result, fmt.get_ptr(), ps3_fmt_src{&context, g_count});
return result;
}
static const std::array<s16, 129> s_ctype_table
{
0,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x408,
8, 8, 8, 8,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x18,
0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
0x42, 0x42, 0x42, 0x42, 0x42, 0x42,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
0x10, 0x10, 0x10, 0x10, 0x20,
};
s16 __sys_look_ctype_table(s32 ch)
{
sysPrxForUser.trace("__sys_look_ctype_table(ch=%d)", ch);
ensure(ch >= -1 && ch <= 127); // "__sys_look_ctype_table"
return s_ctype_table[ch + 1];
}
s32 _sys_tolower(s32 ch)
{
sysPrxForUser.trace("_sys_tolower(ch=%d)", ch);
ensure(ch >= -1 && ch <= 127); // "_sys_tolower"
return s_ctype_table[ch + 1] & 1 ? ch + 0x20 : ch;
}
s32 _sys_toupper(s32 ch)
{
sysPrxForUser.trace("_sys_toupper(ch=%d)", ch);
ensure(ch >= -1 && ch <= 127); // "_sys_toupper"
return s_ctype_table[ch + 1] & 2 ? ch - 0x20 : ch;
}
vm::ptr<void> _sys_memset(vm::ptr<void> dst, s32 value, u32 size)
{
sysPrxForUser.trace("_sys_memset(dst=*0x%x, value=%d, size=0x%x)", dst, value, size);
std::memset(dst.get_ptr(), value, size);
return dst;
}
vm::ptr<void> _sys_memcpy(vm::ptr<void> dst, vm::cptr<void> src, u32 size)
{
sysPrxForUser.trace("_sys_memcpy(dst=*0x%x, src=*0x%x, size=0x%x)", dst, src, size);
std::memcpy(dst.get_ptr(), src.get_ptr(), size);
return dst;
}
s32 _sys_memcmp(vm::cptr<u8> buf1, vm::cptr<u8> buf2, u32 size)
{
sysPrxForUser.trace("_sys_memcmp(buf1=*0x%x, buf2=*0x%x, size=%d)", buf1, buf2, size);
for (u32 i = 0; i < size; i++)
{
const u8 b1 = buf1[i], b2 = buf2[i];
if (b1 < b2)
{
return -1;
}
if (b1 > b2)
{
return 1;
}
}
return 0;
}
vm::ptr<u8> _sys_memchr(vm::ptr<u8> buf, u8 ch, s32 size)
{
sysPrxForUser.trace("_sys_memchr(buf=*0x%x, ch=0x%x, size=0x%x)", buf, ch, size);
if (!buf)
{
return vm::null;
}
while (size > 0)
{
if (*buf == ch)
{
return buf;
}
buf++;
size--;
}
return vm::null;
}
vm::ptr<void> _sys_memmove(vm::ptr<void> dst, vm::cptr<void> src, u32 size)
{
sysPrxForUser.trace("_sys_memmove(dst=*0x%x, src=*0x%x, size=%d)", dst, src, size);
std::memmove(dst.get_ptr(), src.get_ptr(), size);
return dst;
}
u32 _sys_strlen(vm::cptr<char> str)
{
sysPrxForUser.trace("_sys_strlen(str=%s)", str);
if (!str)
{
return 0;
}
for (u32 i = 0;; i++)
{
if (str[i] == '\0')
{
return i;
}
}
}
s32 _sys_strcmp(vm::cptr<char> str1, vm::cptr<char> str2)
{
sysPrxForUser.trace("_sys_strcmp(str1=%s, str2=%s)", str1, str2);
for (u32 i = 0;; i++)
{
const u8 ch1 = str1[i], ch2 = str2[i];
if (ch1 < ch2)
return -1;
if (ch1 > ch2)
return 1;
if (ch1 == '\0')
return 0;
}
}
s32 _sys_strncmp(vm::cptr<char> str1, vm::cptr<char> str2, u32 max)
{
sysPrxForUser.trace("_sys_strncmp(str1=%s, str2=%s, max=%d)", str1, str2, max);
for (u32 i = 0; i < max; i++)
{
const u8 ch1 = str1[i], ch2 = str2[i];
if (ch1 < ch2)
return -1;
if (ch1 > ch2)
return 1;
if (ch1 == '\0')
break;
}
return 0;
}
vm::ptr<char> _sys_strcat(vm::ptr<char> dst, vm::cptr<char> src)
{
sysPrxForUser.trace("_sys_strcat(dst=*0x%x %s, src=%s)", dst, dst, src);
auto str = dst;
while (*str)
{
str++;
}
for (u32 i = 0;; i++)
{
if (!(str[i] = src[i]))
{
return dst;
}
}
}
vm::cptr<char> _sys_strchr(vm::cptr<char> str, char ch)
{
sysPrxForUser.trace("_sys_strchr(str=%s, ch=%d)", str, ch);
for (u32 i = 0;; i++)
{
const char ch1 = str[i];
if (ch1 == ch)
return str + i;
if (ch1 == '\0')
return vm::null;
}
}
vm::ptr<char> _sys_strncat(vm::ptr<char> dst, vm::cptr<char> src, u32 max)
{
sysPrxForUser.trace("_sys_strncat(dst=*0x%x %s, src=%s, max=%u)", dst, dst, src, max);
auto str = dst;
while (*str)
{
str++;
}
for (u32 i = 0; i < max; i++)
{
if (!(str[i] = src[i]))
{
return dst;
}
}
str[max] = '\0';
return dst;
}
vm::ptr<char> _sys_strcpy(vm::ptr<char> dst, vm::cptr<char> src)
{
sysPrxForUser.trace("_sys_strcpy(dst=*0x%x, src=%s)", dst, src);
for (u32 i = 0;; i++)
{
if (!(dst[i] = src[i]))
{
return dst;
}
}
}
vm::ptr<char> _sys_strncpy(vm::ptr<char> dst, vm::cptr<char> src, s32 len)
{
sysPrxForUser.trace("_sys_strncpy(dst=*0x%x %s, src=%s, len=%d)", dst, dst, src, len);
if (!dst || !src)
{
return vm::null;
}
for (s32 i = 0; i < len; i++)
{
if (!(dst[i] = src[i]))
{
for (++i; i < len; i++)
{
dst[i] = '\0';
}
return dst;
}
}
return dst;
}
s32 _sys_strncasecmp(vm::cptr<char> str1, vm::cptr<char> str2, u32 n)
{
sysPrxForUser.trace("_sys_strncasecmp(str1=%s, str2=%s, n=%d)", str1, str2, n);
for (u32 i = 0; i < n; i++)
{
const int ch1 = _sys_tolower(str1[i]), ch2 = _sys_tolower(str2[i]);
if (ch1 < ch2)
return -1;
if (ch1 > ch2)
return 1;
if (ch1 == '\0')
break;
}
return 0;
}
vm::cptr<char> _sys_strrchr(vm::cptr<char> str, char ch)
{
sysPrxForUser.trace("_sys_strrchr(str=%s, ch=%d)", str, ch);
vm::cptr<char> res = vm::null;
for (u32 i = 0;; i++)
{
const char ch1 = str[i];
if (ch1 == ch)
res = str + i;
if (ch1 == '\0')
break;
}
return res;
}
u32 _sys_malloc(u32 size)
{
sysPrxForUser.warning("_sys_malloc(size=0x%x)", size);
return vm::alloc(size, vm::main);
}
u32 _sys_memalign(u32 align, u32 size)
{
sysPrxForUser.warning("_sys_memalign(align=0x%x, size=0x%x)", align, size);
return vm::alloc(size, vm::main, std::max<u32>(align, 0x10000));
}
error_code _sys_free(u32 addr)
{
sysPrxForUser.warning("_sys_free(addr=0x%x)", addr);
vm::dealloc(addr, vm::main);
return CELL_OK;
}
s32 _sys_snprintf(ppu_thread& ppu, vm::ptr<char> dst, u32 count, vm::cptr<char> fmt, ppu_va_args_t va_args)
{
sysPrxForUser.warning("_sys_snprintf(dst=*0x%x, count=%d, fmt=%s, ...)", dst, count, fmt);
std::string result = ps3_fmt(ppu, fmt, va_args.count);
if (!count)
{
return 0; // ???
}
else
{
count = static_cast<u32>(std::min<usz>(count - 1, result.size()));
std::memcpy(dst.get_ptr(), result.c_str(), count);
dst[count] = 0;
return count;
}
}
error_code _sys_printf(ppu_thread& ppu, vm::cptr<char> fmt, ppu_va_args_t va_args)
{
sysPrxForUser.warning("_sys_printf(fmt=%s, ...)", fmt);
const auto buf = vm::make_str(ps3_fmt(ppu, fmt, va_args.count));
sys_tty_write(ppu, 0, buf, buf.get_count() - 1, vm::var<u32>{});
return CELL_OK;
}
s32 _sys_sprintf(ppu_thread& ppu, vm::ptr<char> buffer, vm::cptr<char> fmt, ppu_va_args_t va_args)
{
sysPrxForUser.warning("_sys_sprintf(buffer=*0x%x, fmt=%s, ...)", buffer, fmt);
std::string result = ps3_fmt(ppu, fmt, va_args.count);
std::memcpy(buffer.get_ptr(), result.c_str(), result.size() + 1);
return static_cast<s32>(result.size());
}
error_code _sys_vprintf()
{
sysPrxForUser.todo("_sys_vprintf()");
return CELL_OK;
}
error_code _sys_vsnprintf()
{
sysPrxForUser.todo("_sys_vsnprintf()");
return CELL_OK;
}
error_code _sys_vsprintf()
{
sysPrxForUser.todo("_sys_vsprintf()");
return CELL_OK;
}
void _sys_qsort(vm::ptr<void> base, u32 nelem, u32 size, vm::ptr<qsortcmp> cmp)
{
sysPrxForUser.warning("_sys_qsort(base=*0x%x, nelem=%d, size=0x%x, cmp=*0x%x)", base, nelem, size, cmp);
static thread_local decltype(cmp) g_tls_cmp;
g_tls_cmp = cmp;
std::qsort(base.get_ptr(), nelem, size, [](const void* a, const void* b) -> s32
{
return g_tls_cmp(static_cast<ppu_thread&>(*get_current_cpu_thread()), vm::get_addr(a), vm::get_addr(b));
});
}
void sysPrxForUser_sys_libc_init()
{
REG_FUNC(sysPrxForUser, __sys_look_ctype_table);
REG_FUNC(sysPrxForUser, _sys_tolower);
REG_FUNC(sysPrxForUser, _sys_toupper);
REG_FUNC(sysPrxForUser, _sys_memset);
REG_FUNC(sysPrxForUser, _sys_memcpy);
REG_FUNC(sysPrxForUser, _sys_memcmp);
REG_FUNC(sysPrxForUser, _sys_memchr);
REG_FUNC(sysPrxForUser, _sys_memmove);
REG_FUNC(sysPrxForUser, _sys_strlen);
REG_FUNC(sysPrxForUser, _sys_strcmp);
REG_FUNC(sysPrxForUser, _sys_strncmp);
REG_FUNC(sysPrxForUser, _sys_strcat);
REG_FUNC(sysPrxForUser, _sys_strchr);
REG_FUNC(sysPrxForUser, _sys_strncat);
REG_FUNC(sysPrxForUser, _sys_strcpy);
REG_FUNC(sysPrxForUser, _sys_strncpy);
REG_FUNC(sysPrxForUser, _sys_strncasecmp);
REG_FUNC(sysPrxForUser, _sys_strrchr);
REG_FUNC(sysPrxForUser, _sys_malloc);
REG_FUNC(sysPrxForUser, _sys_memalign);
REG_FUNC(sysPrxForUser, _sys_free);
REG_FUNC(sysPrxForUser, _sys_snprintf);
REG_FUNC(sysPrxForUser, _sys_printf);
REG_FUNC(sysPrxForUser, _sys_sprintf);
REG_FUNC(sysPrxForUser, _sys_vprintf);
REG_FUNC(sysPrxForUser, _sys_vsnprintf);
REG_FUNC(sysPrxForUser, _sys_vsprintf);
REG_FUNC(sysPrxForUser, _sys_qsort);
}
| 10,306
|
C++
|
.cpp
| 395
| 23.802532
| 108
| 0.640592
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| true
| false
| false
| true
| false
| false
|
5,279
|
sceNpTrophy.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/sceNpTrophy.cpp
|
#include "stdafx.h"
#include "Emu/System.h"
#include "Emu/system_config.h"
#include "Emu/VFS.h"
#include "Emu/IdManager.h"
#include "Emu/Cell/PPUModule.h"
#include "Emu/Cell/Modules/cellMsgDialog.h"
#include "Utilities/rXml.h"
#include "Loader/TRP.h"
#include "Loader/TROPUSR.h"
#include "sceNp.h"
#include "sceNpTrophy.h"
#include "cellSysutil.h"
#include "Utilities/StrUtil.h"
#include "Emu/Cell/lv2/sys_event.h"
#include "Emu/Cell/lv2/sys_fs.h"
#include <algorithm>
#include <functional>
#include <shared_mutex>
#include "util/asm.hpp"
LOG_CHANNEL(sceNpTrophy);
TrophyNotificationBase::~TrophyNotificationBase()
{
}
struct trophy_context_t
{
static const u32 id_base = 1;
static const u32 id_step = 1;
static const u32 id_count = 4;
SAVESTATE_INIT_POS(42);
std::string trp_name;
std::unique_ptr<TROPUSRLoader> tropusr;
bool read_only = false;
trophy_context_t() = default;
trophy_context_t(utils::serial& ar)
: trp_name(ar.pop<std::string>())
{
std::string trophy_path = vfs::get(Emu.GetDir() + "TROPDIR/" + trp_name + "/TROPHY.TRP");
fs::file trp_stream(trophy_path);
if (!trp_stream)
{
// Fallback
trophy_path = vfs::get("/dev_bdvd/PS3_GAME/TROPDIR/" + trp_name + "/TROPHY.TRP");
trp_stream.open(trophy_path);
}
if (!ar.pop<bool>())
{
ar(read_only);
return;
}
ar(read_only);
if (!trp_stream && g_cfg.savestate.state_inspection_mode)
{
return;
}
const std::string trophyPath = "/dev_hdd0/home/" + Emu.GetUsr() + "/trophy/" + trp_name;
tropusr = std::make_unique<TROPUSRLoader>();
const std::string trophyUsrPath = trophyPath + "/TROPUSR.DAT";
const std::string trophyConfPath = trophyPath + "/TROPCONF.SFM";
ensure(tropusr->Load(trophyUsrPath, trophyConfPath).success);
}
void save(utils::serial& ar)
{
ar(trp_name, tropusr.operator bool(), read_only);
}
};
struct trophy_handle_t
{
static const u32 id_base = 1;
static const u32 id_step = 1;
static const u32 id_count = 4;
SAVESTATE_INIT_POS(43);
bool is_aborted = false;
trophy_handle_t() = default;
trophy_handle_t(utils::serial& ar)
: is_aborted(ar)
{
}
void save(utils::serial& ar)
{
ar(is_aborted);
}
};
struct sce_np_trophy_manager
{
shared_mutex mtx;
atomic_t<bool> is_initialized = false;
// Get context + check handle given
static std::pair<trophy_context_t*, SceNpTrophyError> get_context_ex(u32 context, u32 handle, bool test_writeable = false)
{
decltype(get_context_ex(0, 0)) res{};
auto& [ctxt, error] = res;
if (context < trophy_context_t::id_base ||
context >= trophy_context_t::id_base + trophy_context_t::id_count)
{
// Id was not in range of valid ids
error = SCE_NP_TROPHY_ERROR_INVALID_ARGUMENT;
return res;
}
ctxt = idm::check<trophy_context_t>(context);
if (!ctxt)
{
error = SCE_NP_TROPHY_ERROR_UNKNOWN_CONTEXT;
return res;
}
if (test_writeable && ctxt->read_only)
{
error = SCE_NP_TROPHY_ERROR_INVALID_CONTEXT;
return res;
}
if (handle < trophy_handle_t::id_base ||
handle >= trophy_handle_t::id_base + trophy_handle_t::id_count)
{
error = SCE_NP_TROPHY_ERROR_INVALID_ARGUMENT;
return res;
}
const auto hndl = idm::check<trophy_handle_t>(handle);
if (!hndl)
{
error = SCE_NP_TROPHY_ERROR_UNKNOWN_HANDLE;
return res;
}
else if (hndl->is_aborted)
{
error = SCE_NP_TROPHY_ERROR_ABORT;
return res;
}
return res;
}
SAVESTATE_INIT_POS(12);
sce_np_trophy_manager() = default;
sce_np_trophy_manager(utils::serial& ar)
: is_initialized(ar)
{
}
void save(utils::serial& ar)
{
ar(is_initialized);
if (is_initialized)
{
USING_SERIALIZATION_VERSION(sceNpTrophy);
}
}
};
template<>
void fmt_class_string<SceNpTrophyError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(SCE_NP_TROPHY_ERROR_ALREADY_INITIALIZED);
STR_CASE(SCE_NP_TROPHY_ERROR_NOT_INITIALIZED);
STR_CASE(SCE_NP_TROPHY_ERROR_NOT_SUPPORTED);
STR_CASE(SCE_NP_TROPHY_ERROR_CONTEXT_NOT_REGISTERED);
STR_CASE(SCE_NP_TROPHY_ERROR_OUT_OF_MEMORY);
STR_CASE(SCE_NP_TROPHY_ERROR_INVALID_ARGUMENT);
STR_CASE(SCE_NP_TROPHY_ERROR_EXCEEDS_MAX);
STR_CASE(SCE_NP_TROPHY_ERROR_INSUFFICIENT);
STR_CASE(SCE_NP_TROPHY_ERROR_UNKNOWN_CONTEXT);
STR_CASE(SCE_NP_TROPHY_ERROR_INVALID_FORMAT);
STR_CASE(SCE_NP_TROPHY_ERROR_BAD_RESPONSE);
STR_CASE(SCE_NP_TROPHY_ERROR_INVALID_GRADE);
STR_CASE(SCE_NP_TROPHY_ERROR_INVALID_CONTEXT);
STR_CASE(SCE_NP_TROPHY_ERROR_PROCESSING_ABORTED);
STR_CASE(SCE_NP_TROPHY_ERROR_ABORT);
STR_CASE(SCE_NP_TROPHY_ERROR_UNKNOWN_HANDLE);
STR_CASE(SCE_NP_TROPHY_ERROR_LOCKED);
STR_CASE(SCE_NP_TROPHY_ERROR_HIDDEN);
STR_CASE(SCE_NP_TROPHY_ERROR_CANNOT_UNLOCK_PLATINUM);
STR_CASE(SCE_NP_TROPHY_ERROR_ALREADY_UNLOCKED);
STR_CASE(SCE_NP_TROPHY_ERROR_INVALID_TYPE);
STR_CASE(SCE_NP_TROPHY_ERROR_INVALID_HANDLE);
STR_CASE(SCE_NP_TROPHY_ERROR_INVALID_NP_COMM_ID);
STR_CASE(SCE_NP_TROPHY_ERROR_UNKNOWN_NP_COMM_ID);
STR_CASE(SCE_NP_TROPHY_ERROR_DISC_IO);
STR_CASE(SCE_NP_TROPHY_ERROR_CONF_DOES_NOT_EXIST);
STR_CASE(SCE_NP_TROPHY_ERROR_UNSUPPORTED_FORMAT);
STR_CASE(SCE_NP_TROPHY_ERROR_ALREADY_INSTALLED);
STR_CASE(SCE_NP_TROPHY_ERROR_BROKEN_DATA);
STR_CASE(SCE_NP_TROPHY_ERROR_VERIFICATION_FAILURE);
STR_CASE(SCE_NP_TROPHY_ERROR_INVALID_TROPHY_ID);
STR_CASE(SCE_NP_TROPHY_ERROR_UNKNOWN_TROPHY_ID);
STR_CASE(SCE_NP_TROPHY_ERROR_UNKNOWN_TITLE);
STR_CASE(SCE_NP_TROPHY_ERROR_UNKNOWN_FILE);
STR_CASE(SCE_NP_TROPHY_ERROR_DISC_NOT_MOUNTED);
STR_CASE(SCE_NP_TROPHY_ERROR_SHUTDOWN);
STR_CASE(SCE_NP_TROPHY_ERROR_TITLE_ICON_NOT_FOUND);
STR_CASE(SCE_NP_TROPHY_ERROR_TROPHY_ICON_NOT_FOUND);
STR_CASE(SCE_NP_TROPHY_ERROR_INSUFFICIENT_DISK_SPACE);
STR_CASE(SCE_NP_TROPHY_ERROR_ILLEGAL_UPDATE);
STR_CASE(SCE_NP_TROPHY_ERROR_SAVEDATA_USER_DOES_NOT_MATCH);
STR_CASE(SCE_NP_TROPHY_ERROR_TROPHY_ID_DOES_NOT_EXIST);
STR_CASE(SCE_NP_TROPHY_ERROR_SERVICE_UNAVAILABLE);
STR_CASE(SCE_NP_TROPHY_ERROR_UNKNOWN);
}
return unknown;
});
}
template <>
void fmt_class_string<SceNpCommunicationSignature>::format(std::string& out, u64 arg)
{
const auto& sign = get_object(arg);
fmt::append(out, "%s", sign.data);
}
template <>
void fmt_class_string<SceNpCommunicationId>::format(std::string& out, u64 arg)
{
const auto& id = get_object(arg);
const u8 term = id.data[9];
fmt::append(out, "{ data='%s', term='%s' (0x%x), num=%d, dummy=%d }", id.data, std::isprint(term) ? fmt::format("%c", term) : "", term, id.num, id.dummy);
}
// Helpers
static error_code NpTrophyGetTrophyInfo(const trophy_context_t* ctxt, s32 trophyId, SceNpTrophyDetails* details, SceNpTrophyData* data);
static void show_trophy_notification(const trophy_context_t* ctxt, s32 trophyId)
{
// Get icon for the notification.
const std::string padded_trophy_id = fmt::format("%03u", trophyId);
const std::string trophy_icon_path = "/dev_hdd0/home/" + Emu.GetUsr() + "/trophy/" + ctxt->trp_name + "/TROP" + padded_trophy_id + ".PNG";
fs::file trophy_icon_file = fs::file(vfs::get(trophy_icon_path));
std::vector<uchar> trophy_icon_data;
trophy_icon_file.read(trophy_icon_data, trophy_icon_file.size());
SceNpTrophyDetails details{};
if (const auto ret = NpTrophyGetTrophyInfo(ctxt, trophyId, &details, nullptr))
{
sceNpTrophy.error("Failed to get info for trophy dialog. Error code 0x%x", +ret);
}
if (auto trophy_notification_dialog = Emu.GetCallbacks().get_trophy_notification_dialog())
{
trophy_notification_dialog->ShowTrophyNotification(details, trophy_icon_data);
}
}
// Functions
error_code sceNpTrophyInit(vm::ptr<void> pool, u32 poolSize, u32 containerId, u64 options)
{
sceNpTrophy.warning("sceNpTrophyInit(pool=*0x%x, poolSize=0x%x, containerId=0x%x, options=0x%llx)", pool, poolSize, containerId, options);
auto& trophy_manager = g_fxo->get<sce_np_trophy_manager>();
std::scoped_lock lock(trophy_manager.mtx);
if (trophy_manager.is_initialized)
{
return SCE_NP_TROPHY_ERROR_ALREADY_INITIALIZED;
}
if (options > 0)
{
return SCE_NP_TROPHY_ERROR_NOT_SUPPORTED;
}
trophy_manager.is_initialized = true;
return CELL_OK;
}
error_code sceNpTrophyTerm()
{
sceNpTrophy.warning("sceNpTrophyTerm()");
auto& trophy_manager = g_fxo->get<sce_np_trophy_manager>();
std::scoped_lock lock(trophy_manager.mtx);
if (!trophy_manager.is_initialized)
{
return SCE_NP_TROPHY_ERROR_NOT_INITIALIZED;
}
idm::clear<trophy_context_t>();
idm::clear<trophy_handle_t>();
trophy_manager.is_initialized = false;
return CELL_OK;
}
error_code sceNpTrophyCreateHandle(vm::ptr<u32> handle)
{
sceNpTrophy.warning("sceNpTrophyCreateHandle(handle=*0x%x)", handle);
auto& trophy_manager = g_fxo->get<sce_np_trophy_manager>();
std::scoped_lock lock(trophy_manager.mtx);
if (!trophy_manager.is_initialized)
{
return SCE_NP_TROPHY_ERROR_NOT_INITIALIZED;
}
if (!handle)
{
return SCE_NP_TROPHY_ERROR_INVALID_ARGUMENT;
}
const u32 id = idm::make<trophy_handle_t>();
if (!id)
{
return SCE_NP_TROPHY_ERROR_EXCEEDS_MAX;
}
*handle = id;
return CELL_OK;
}
error_code sceNpTrophyDestroyHandle(u32 handle)
{
sceNpTrophy.warning("sceNpTrophyDestroyHandle(handle=0x%x)", handle);
auto& trophy_manager = g_fxo->get<sce_np_trophy_manager>();
std::scoped_lock lock(trophy_manager.mtx);
// TODO: find out if this is checked
//if (!trophy_manager.is_initialized)
//{
// return SCE_NP_TROPHY_ERROR_NOT_INITIALIZED;
//}
if (handle < trophy_handle_t::id_base ||
handle >= trophy_handle_t::id_base + trophy_handle_t::id_count)
{
return SCE_NP_TROPHY_ERROR_INVALID_ARGUMENT;
}
if (!idm::remove<trophy_handle_t>(handle))
{
return SCE_NP_TROPHY_ERROR_UNKNOWN_HANDLE;
}
return CELL_OK;
}
error_code sceNpTrophyGetGameDetails()
{
UNIMPLEMENTED_FUNC(sceNpTrophy);
return CELL_OK;
}
error_code sceNpTrophyAbortHandle(u32 handle)
{
sceNpTrophy.todo("sceNpTrophyAbortHandle(handle=0x%x)", handle);
auto& trophy_manager = g_fxo->get<sce_np_trophy_manager>();
std::scoped_lock lock(trophy_manager.mtx);
// TODO: find out if this is checked
//if (!trophy_manager.is_initialized)
//{
// return SCE_NP_TROPHY_ERROR_NOT_INITIALIZED;
//}
if (handle < trophy_handle_t::id_base ||
handle >= trophy_handle_t::id_base + trophy_handle_t::id_count)
{
return SCE_NP_TROPHY_ERROR_INVALID_ARGUMENT;
}
const auto hndl = idm::check<trophy_handle_t>(handle);
if (!hndl)
{
return SCE_NP_TROPHY_ERROR_UNKNOWN_HANDLE;
}
// Once it is aborted it cannot be used anymore
// TODO: Implement function abortion process maybe? (depends if its actually make sense for some functions)
hndl->is_aborted = true;
return CELL_OK;
}
error_code sceNpTrophyCreateContext(vm::ptr<u32> context, vm::cptr<SceNpCommunicationId> commId, vm::cptr<SceNpCommunicationSignature> commSign, u64 options)
{
sceNpTrophy.warning("sceNpTrophyCreateContext(context=*0x%x, commId=*0x%x, commSign=*0x%x, options=0x%llx)", context, commId, commSign, options);
if (!commSign)
{
return SCE_NP_TROPHY_ERROR_INVALID_ARGUMENT;
}
sceNpTrophy.notice("sceNpTrophyCreateContext(): commSign = %s", *commSign);
auto& trophy_manager = g_fxo->get<sce_np_trophy_manager>();
std::scoped_lock lock(trophy_manager.mtx);
if (!trophy_manager.is_initialized)
{
return SCE_NP_TROPHY_ERROR_NOT_INITIALIZED;
}
if (!context || !commId)
{
return SCE_NP_TROPHY_ERROR_INVALID_ARGUMENT;
}
if (options > SCE_NP_TROPHY_OPTIONS_CREATE_CONTEXT_READ_ONLY)
{
return SCE_NP_TROPHY_ERROR_NOT_SUPPORTED;
}
sceNpTrophy.warning("sceNpTrophyCreateContext(): commId = %s", *commId);
// rough checks for further fmt::format call
const s32 comm_num = commId->num;
if (comm_num > 99)
{
return SCE_NP_TROPHY_ERROR_INVALID_NP_COMM_ID;
}
// NOTE: commId->term is unused in our code (at least until someone finds out if we need to account for it)
// Generate trophy context name, limited to 9 characters
// Read once for thread-safety reasons
std::string name_str(commId->data, 9);
// resize the name if it was shorter than expected
if (const auto pos = name_str.find_first_of('\0'); pos != std::string_view::npos)
{
name_str = name_str.substr(0, pos);
}
const SceNpCommunicationSignature commSign_data = *commSign;
if (read_from_ptr<be_t<u32>>(commSign_data.data, 0) != NP_TROPHY_COMM_SIGN_MAGIC)
{
return SCE_NP_TROPHY_ERROR_INVALID_NP_COMM_ID;
}
if (std::any_of(&commSign_data.data[6], &commSign_data.data[6] + 6, FN(x != '\0')))
{
// 6 padding bytes - must be 0
return SCE_NP_TROPHY_ERROR_INVALID_NP_COMM_ID;
}
if (read_from_ptr<be_t<u16>>(commSign_data.data, 4) != 0x100)
{
// Signifies version (1.00), although only one constant is allowed
return SCE_NP_TROPHY_ERROR_INVALID_NP_COMM_ID;
}
// append the commId number as "_xx"
std::string name = fmt::format("%s_%02d", name_str, comm_num);
// create trophy context
const auto ctxt = idm::make_ptr<trophy_context_t>();
if (!ctxt)
{
return SCE_NP_TROPHY_ERROR_EXCEEDS_MAX;
}
// set trophy context parameters (could be passed to constructor through make_ptr call)
ctxt->trp_name = std::move(name);
ctxt->read_only = !!(options & SCE_NP_TROPHY_OPTIONS_CREATE_CONTEXT_READ_ONLY);
*context = idm::last_id();
return CELL_OK;
}
error_code sceNpTrophyDestroyContext(u32 context)
{
sceNpTrophy.warning("sceNpTrophyDestroyContext(context=0x%x)", context);
auto& trophy_manager = g_fxo->get<sce_np_trophy_manager>();
std::scoped_lock lock(trophy_manager.mtx);
if (!trophy_manager.is_initialized)
{
return SCE_NP_TROPHY_ERROR_NOT_INITIALIZED;
}
if (context < trophy_context_t::id_base ||
context >= trophy_context_t::id_base + trophy_context_t::id_count)
{
return SCE_NP_TROPHY_ERROR_INVALID_ARGUMENT;
}
if (!idm::remove<trophy_context_t>(context))
{
return SCE_NP_TROPHY_ERROR_UNKNOWN_CONTEXT;
}
return CELL_OK;
}
error_code sceNpTrophyRegisterContext(ppu_thread& ppu, u32 context, u32 handle, vm::ptr<SceNpTrophyStatusCallback> statusCb, vm::ptr<void> arg, u64 options)
{
sceNpTrophy.warning("sceNpTrophyRegisterContext(context=0x%x, handle=0x%x, statusCb=*0x%x, arg=*0x%x, options=0x%llx)", context, handle, statusCb, arg, options);
auto& trophy_manager = g_fxo->get<sce_np_trophy_manager>();
std::shared_lock lock(trophy_manager.mtx);
if (!trophy_manager.is_initialized)
{
return SCE_NP_TROPHY_ERROR_NOT_INITIALIZED;
}
const auto [ctxt, error] = trophy_manager.get_context_ex(context, handle, true);
const auto handle_ptr = idm::get<trophy_handle_t>(handle);
if (error)
{
return error;
}
if (!statusCb)
{
return SCE_NP_TROPHY_ERROR_INVALID_ARGUMENT;
}
if (options > SCE_NP_TROPHY_OPTIONS_REGISTER_CONTEXT_SHOW_ERROR_EXIT)
{
return SCE_NP_TROPHY_ERROR_NOT_SUPPORTED;
}
const auto on_error = [options]()
{
if (!!(options & SCE_NP_TROPHY_OPTIONS_REGISTER_CONTEXT_SHOW_ERROR_EXIT))
{
static_cast<void>(open_exit_dialog("Error during trophy registration! The game will now be terminated.", true, msg_dialog_source::_sceNpTrophy));
}
};
// open trophy pack file
std::string trp_path = vfs::get(Emu.GetDir() + "TROPDIR/" + ctxt->trp_name + "/TROPHY.TRP");
fs::file stream(trp_path);
if (!stream && Emu.GetCat() == "GD")
{
sceNpTrophy.warning("sceNpTrophyRegisterContext failed to open trophy file from boot path: '%s' (%s)", trp_path, fs::g_tls_error);
trp_path = vfs::get("/dev_bdvd/PS3_GAME/TROPDIR/" + ctxt->trp_name + "/TROPHY.TRP");
stream.open(trp_path);
}
// check if exists and opened
if (!stream)
{
const std::string msg = fmt::format("Failed to open trophy file: '%s' (%s)", trp_path, fs::g_tls_error);
return {SCE_NP_TROPHY_ERROR_CONF_DOES_NOT_EXIST, msg};
}
// TODO:
// SCE_NP_TROPHY_STATUS_DATA_CORRUPT -> reinstall
// SCE_NP_TROPHY_STATUS_REQUIRES_UPDATE -> reinstall (for example if a patch has updates for the trophy data)
// SCE_NP_TROPHY_STATUS_CHANGES_DETECTED -> reinstall (only possible in dev mode)
const std::string trophyPath = "/dev_hdd0/home/" + Emu.GetUsr() + "/trophy/" + ctxt->trp_name;
const s32 trp_status = fs::is_dir(vfs::get(trophyPath)) ? SCE_NP_TROPHY_STATUS_INSTALLED : SCE_NP_TROPHY_STATUS_NOT_INSTALLED;
lock.unlock();
sceNpTrophy.notice("sceNpTrophyRegisterContext(): Callback is being called (trp_status=%u)", trp_status);
// "Ask permission" to install the trophy data.
// The callback is called once and then if it returns >= 0 the cb is called through events(coming from vsh) that are passed to the CB through cellSysutilCheckCallback
if (statusCb(ppu, context, trp_status, 0, 0, arg) < 0)
{
on_error();
return SCE_NP_TROPHY_ERROR_PROCESSING_ABORTED;
}
std::unique_lock lock2(trophy_manager.mtx);
// Rerun error checks, the callback could have changed stuff by calling sceNpTrophy functions internally
if (!trophy_manager.is_initialized)
{
on_error();
return SCE_NP_TROPHY_ERROR_NOT_INITIALIZED;
}
const auto [ctxt2, error2] = trophy_manager.get_context_ex(context, handle);
if (error2)
{
// Recheck for any errors, such as if AbortHandle was called
return error2;
}
// Paranoid checks: context/handler could have been destroyed and replaced with new ones with the same IDs
// Return an error for such cases
if (ctxt2 != ctxt)
{
on_error();
return SCE_NP_TROPHY_ERROR_UNKNOWN_CONTEXT;
}
if (handle_ptr.get() != idm::check<trophy_handle_t>(handle))
{
on_error();
return SCE_NP_TROPHY_ERROR_UNKNOWN_HANDLE;
}
TRPLoader trp(stream);
if (!trp.LoadHeader())
{
sceNpTrophy.error("sceNpTrophyRegisterContext(): Failed to load trophy config header");
on_error();
return SCE_NP_TROPHY_ERROR_ILLEGAL_UPDATE;
}
// Rename or discard certain entries based on the files found
const usz kTargetBufferLength = 31;
char target[kTargetBufferLength + 1]{};
strcpy_trunc(target, fmt::format("TROP_%02d.SFM", static_cast<s32>(g_cfg.sys.language)));
if (trp.ContainsEntry(target))
{
trp.RemoveEntry("TROPCONF.SFM");
trp.RemoveEntry("TROP.SFM");
trp.RenameEntry(target, "TROPCONF.SFM");
}
else if (trp.ContainsEntry("TROP.SFM"))
{
trp.RemoveEntry("TROPCONF.SFM");
trp.RenameEntry("TROP.SFM", "TROPCONF.SFM");
}
else if (!trp.ContainsEntry("TROPCONF.SFM"))
{
sceNpTrophy.error("sceNpTrophyRegisterContext(): Invalid/Incomplete trophy config");
on_error();
return SCE_NP_TROPHY_ERROR_ILLEGAL_UPDATE;
}
// Discard unnecessary TROP_XX.SFM files
for (s32 i = 0; i <= 18; i++)
{
strcpy_trunc(target, fmt::format("TROP_%02d.SFM", i));
if (i != g_cfg.sys.language)
{
trp.RemoveEntry(target);
}
}
if (!trp.Install(trophyPath))
{
sceNpTrophy.error("sceNpTrophyRegisterContext(): Failed to install trophy context '%s' (%s)", trophyPath, fs::g_tls_error);
on_error();
return SCE_NP_TROPHY_ERROR_ILLEGAL_UPDATE;
}
const auto& tropusr = ctxt->tropusr = std::make_unique<TROPUSRLoader>();
const std::string trophyUsrPath = trophyPath + "/TROPUSR.DAT";
const std::string trophyConfPath = trophyPath + "/TROPCONF.SFM";
ensure(tropusr->Load(trophyUsrPath, trophyConfPath).success);
// This emulates vsh sending the events and ensures that not 2 events are processed at once
const std::pair<u32, s32> statuses[] =
{
{ SCE_NP_TROPHY_STATUS_PROCESSING_SETUP, 3 },
{ SCE_NP_TROPHY_STATUS_PROCESSING_PROGRESS, ::narrow<s32>(tropusr->GetTrophiesCount()) - 1 },
{ SCE_NP_TROPHY_STATUS_PROCESSING_FINALIZE, 4 },
{ SCE_NP_TROPHY_STATUS_PROCESSING_COMPLETE, 0 }
};
lock2.unlock();
lv2_obj::sleep(ppu);
// Create a counter which is destroyed after the function ends
const auto queued = std::make_shared<atomic_t<u32>>(0);
std::weak_ptr<atomic_t<u32>> wkptr = queued;
for (auto status : statuses)
{
// One status max per cellSysutilCheckCallback call
*queued += status.second;
for (s32 completed = 0; completed <= status.second; completed++)
{
sysutil_register_cb([statusCb, status, context, completed, arg, wkptr](ppu_thread& cb_ppu) -> s32
{
// TODO: it is possible that we need to check the return value here as well.
statusCb(cb_ppu, context, status.first, completed, status.second, arg);
const auto queued = wkptr.lock();
if (queued && (*queued)-- == 1)
{
queued->notify_one();
}
return 0;
});
}
u64 current = get_system_time();
const u64 until = current + 300'000;
// If too much time passes just send the rest of the events anyway
for (u32 old_value; current < until && (old_value = *queued);
current = get_system_time())
{
thread_ctrl::wait_on(*queued, old_value, until - current);
if (ppu.is_stopped())
{
return {};
}
}
}
return CELL_OK;
}
error_code sceNpTrophyGetRequiredDiskSpace(u32 context, u32 handle, vm::ptr<u64> reqspace, u64 options)
{
sceNpTrophy.warning("sceNpTrophyGetRequiredDiskSpace(context=0x%x, handle=0x%x, reqspace=*0x%x, options=0x%llx)", context, handle, reqspace, options);
if (!reqspace)
{
return SCE_NP_TROPHY_ERROR_INVALID_ARGUMENT;
}
if (options > 0)
{
return SCE_NP_TROPHY_ERROR_NOT_SUPPORTED;
}
auto& trophy_manager = g_fxo->get<sce_np_trophy_manager>();
reader_lock lock(trophy_manager.mtx);
if (!trophy_manager.is_initialized)
{
return SCE_NP_TROPHY_ERROR_NOT_INITIALIZED;
}
const auto [ctxt, error] = trophy_manager.get_context_ex(context, handle);
if (error)
{
return error;
}
u64 space = 0;
if (!fs::is_dir(vfs::get("/dev_hdd0/home/" + Emu.GetUsr() + "/trophy/" + ctxt->trp_name)))
{
// open trophy pack file
std::string trophy_path = vfs::get(Emu.GetDir() + "TROPDIR/" + ctxt->trp_name + "/TROPHY.TRP");
fs::file stream(trophy_path);
if (!stream && Emu.GetCat() == "GD")
{
sceNpTrophy.warning("sceNpTrophyGetRequiredDiskSpace failed to open trophy file from boot path: '%s'", trophy_path);
trophy_path = vfs::get("/dev_bdvd/PS3_GAME/TROPDIR/" + ctxt->trp_name + "/TROPHY.TRP");
stream.open(trophy_path);
}
// check if exists and opened
if (!stream)
{
return {SCE_NP_TROPHY_ERROR_CONF_DOES_NOT_EXIST, trophy_path};
}
TRPLoader trp(stream);
if (trp.LoadHeader())
{
space = trp.GetRequiredSpace();
}
else
{
sceNpTrophy.error("sceNpTrophyGetRequiredDiskSpace(): Failed to load trophy header! (trp_name=%s)", ctxt->trp_name);
}
}
else
{
sceNpTrophy.warning("sceNpTrophyGetRequiredDiskSpace(): Trophy config is already installed (trp_name=%s)", ctxt->trp_name);
}
sceNpTrophy.warning("sceNpTrophyGetRequiredDiskSpace(): reqspace is 0x%llx", space);
*reqspace = space;
return CELL_OK;
}
error_code sceNpTrophySetSoundLevel(u32 context, u32 handle, u32 level, u64 options)
{
sceNpTrophy.todo("sceNpTrophySetSoundLevel(context=0x%x, handle=0x%x, level=%d, options=0x%llx)", context, handle, level, options);
if (level > 100 || level < 20)
{
return SCE_NP_TROPHY_ERROR_INVALID_ARGUMENT;
}
if (options > 0)
{
return SCE_NP_TROPHY_ERROR_NOT_SUPPORTED;
}
auto& trophy_manager = g_fxo->get<sce_np_trophy_manager>();
reader_lock lock(trophy_manager.mtx);
if (!trophy_manager.is_initialized)
{
return SCE_NP_TROPHY_ERROR_NOT_INITIALIZED;
}
const auto [ctxt, error] = trophy_manager.get_context_ex(context, handle);
if (error)
{
return error;
}
return CELL_OK;
}
error_code sceNpTrophyGetGameInfo(u32 context, u32 handle, vm::ptr<SceNpTrophyGameDetails> details, vm::ptr<SceNpTrophyGameData> data)
{
sceNpTrophy.warning("sceNpTrophyGetGameInfo(context=0x%x, handle=0x%x, details=*0x%x, data=*0x%x)", context, handle, details, data);
auto& trophy_manager = g_fxo->get<sce_np_trophy_manager>();
reader_lock lock(trophy_manager.mtx);
if (!trophy_manager.is_initialized)
{
return SCE_NP_TROPHY_ERROR_NOT_INITIALIZED;
}
const auto [ctxt, error] = trophy_manager.get_context_ex(context, handle);
if (error)
{
return error;
}
if (!ctxt->tropusr)
{
// TODO: May return SCE_NP_TROPHY_ERROR_UNKNOWN_TITLE for older sdk version
return SCE_NP_TROPHY_ERROR_CONTEXT_NOT_REGISTERED;
}
if (!details && !data)
{
return SCE_NP_TROPHY_ERROR_INVALID_ARGUMENT;
}
const std::string config_path = vfs::get("/dev_hdd0/home/" + Emu.GetUsr() + "/trophy/" + ctxt->trp_name + "/TROPCONF.SFM");
fs::file config(config_path);
if (!config)
{
return { SCE_NP_TROPHY_ERROR_CONF_DOES_NOT_EXIST, config_path };
}
if (details)
*details = {};
if (data)
*data = {};
trophy_xml_document doc{};
pugi::xml_parse_result res = doc.Read(config.to_string());
if (!res)
{
sceNpTrophy.error("sceNpTrophyGetGameInfo: Failed to read TROPCONF.SFM: %s", config_path);
// TODO: return some error
return CELL_OK;
}
std::shared_ptr<rXmlNode> trophy_base = doc.GetRoot();
if (!trophy_base)
{
sceNpTrophy.error("sceNpTrophyGetGameInfo: Failed to read TROPCONF.SFM (root is null): %s", config_path);
// TODO: return some error
return CELL_OK;
}
for (std::shared_ptr<rXmlNode> n = trophy_base->GetChildren(); n; n = n->GetNext())
{
const std::string n_name = n->GetName();
if (details)
{
if (n_name == "title-name")
{
strcpy_trunc(details->title, n->GetNodeContent());
continue;
}
else if (n_name == "title-detail")
{
strcpy_trunc(details->description, n->GetNodeContent());
continue;
}
}
if (n_name == "trophy")
{
if (details)
{
details->numTrophies++;
switch (n->GetAttribute("ttype")[0])
{
case 'B': details->numBronze++; break;
case 'S': details->numSilver++; break;
case 'G': details->numGold++; break;
case 'P': details->numPlatinum++; break;
}
}
if (data)
{
const u32 trophy_id = atoi(n->GetAttribute("id").c_str());
if (ctxt->tropusr->GetTrophyUnlockState(trophy_id))
{
data->unlockedTrophies++;
switch (n->GetAttribute("ttype")[0])
{
case 'B': data->unlockedBronze++; break;
case 'S': data->unlockedSilver++; break;
case 'G': data->unlockedGold++; break;
case 'P': data->unlockedPlatinum++; break;
default: break;
}
}
}
}
}
return CELL_OK;
}
error_code sceNpTrophyGetLatestTrophies()
{
UNIMPLEMENTED_FUNC(sceNpTrophy);
return CELL_OK;
}
error_code sceNpTrophyUnlockTrophy(ppu_thread& ppu, u32 context, u32 handle, s32 trophyId, vm::ptr<u32> platinumId)
{
sceNpTrophy.warning("sceNpTrophyUnlockTrophy(context=0x%x, handle=0x%x, trophyId=%d, platinumId=*0x%x)", context, handle, trophyId, platinumId);
auto& trophy_manager = g_fxo->get<sce_np_trophy_manager>();
reader_lock lock(trophy_manager.mtx);
if (!trophy_manager.is_initialized)
{
return SCE_NP_TROPHY_ERROR_NOT_INITIALIZED;
}
const auto [ctxt, error] = trophy_manager.get_context_ex(context, handle);
if (error)
{
return error;
}
if (!ctxt->tropusr)
{
// TODO: May return SCE_NP_TROPHY_ERROR_UNKNOWN_TITLE for older sdk version
return SCE_NP_TROPHY_ERROR_CONTEXT_NOT_REGISTERED;
}
if (trophyId < 0 || trophyId >= static_cast<s32>(ctxt->tropusr->GetTrophiesCount()))
{
return SCE_NP_TROPHY_ERROR_INVALID_TROPHY_ID;
}
if (ctxt->tropusr->GetTrophyGrade(trophyId) == SCE_NP_TROPHY_GRADE_PLATINUM)
{
return SCE_NP_TROPHY_ERROR_CANNOT_UNLOCK_PLATINUM;
}
if (ctxt->tropusr->GetTrophyUnlockState(trophyId))
{
return SCE_NP_TROPHY_ERROR_ALREADY_UNLOCKED;
}
vm::var<CellRtcTick> tick;
if (error_code error = cellRtcGetCurrentTick(ppu, tick))
{
sceNpTrophy.error("sceNpTrophyUnlockTrophy: Failed to get timestamp: 0x%x", +error);
}
if (ctxt->tropusr->UnlockTrophy(trophyId, tick->tick, tick->tick))
{
sceNpTrophy.notice("Trophy %d unlocked", trophyId);
}
// TODO: Make sure that unlocking platinum trophies is properly implemented and improve upon it
const std::string& config_path = vfs::get("/dev_hdd0/home/" + Emu.GetUsr() + "/trophy/" + ctxt->trp_name + "/TROPCONF.SFM");
const u32 unlocked_platinum_id = ctxt->tropusr->GetUnlockedPlatinumID(trophyId, config_path);
if (unlocked_platinum_id != SCE_NP_TROPHY_INVALID_TROPHY_ID)
{
sceNpTrophy.warning("sceNpTrophyUnlockTrophy: All requirements for unlocking the platinum trophy (ID = %d) were met.)", unlocked_platinum_id);
if (ctxt->tropusr->UnlockTrophy(unlocked_platinum_id, tick->tick, tick->tick))
{
sceNpTrophy.success("You unlocked a platinum trophy! Hooray!!!");
}
}
if (platinumId)
{
*platinumId = unlocked_platinum_id;
sceNpTrophy.warning("sceNpTrophyUnlockTrophy: platinumId was set to %d", unlocked_platinum_id);
}
const std::string trophyPath = "/dev_hdd0/home/" + Emu.GetUsr() + "/trophy/" + ctxt->trp_name + "/TROPUSR.DAT";
if (!ctxt->tropusr->Save(trophyPath))
{
sceNpTrophy.error("sceNpTrophyUnlockTrophy: failed to save '%s'", trophyPath);
}
if (g_cfg.misc.show_trophy_popups)
{
// Enqueue popup for the regular trophy
show_trophy_notification(ctxt, trophyId);
if (unlocked_platinum_id != SCE_NP_TROPHY_INVALID_TROPHY_ID)
{
// Enqueue popup for the holy platinum trophy
show_trophy_notification(ctxt, unlocked_platinum_id);
}
}
return CELL_OK;
}
error_code sceNpTrophyGetTrophyUnlockState(u32 context, u32 handle, vm::ptr<SceNpTrophyFlagArray> flags, vm::ptr<u32> count)
{
sceNpTrophy.warning("sceNpTrophyGetTrophyUnlockState(context=0x%x, handle=0x%x, flags=*0x%x, count=*0x%x)", context, handle, flags, count);
if (!flags || !count)
{
return SCE_NP_TROPHY_ERROR_INVALID_ARGUMENT;
}
auto& trophy_manager = g_fxo->get<sce_np_trophy_manager>();
reader_lock lock(trophy_manager.mtx);
if (!trophy_manager.is_initialized)
{
return SCE_NP_TROPHY_ERROR_NOT_INITIALIZED;
}
const auto [ctxt, error] = trophy_manager.get_context_ex(context, handle);
if (error)
{
return error;
}
TROPUSRLoader* tropusr = nullptr;
TROPUSRLoader local_tropusr{};
if (ctxt->read_only)
{
const std::string trophyPath = "/dev_hdd0/home/" + Emu.GetUsr() + "/trophy/" + ctxt->trp_name;
const std::string trophyUsrPath = trophyPath + "/TROPUSR.DAT";
const std::string trophyConfPath = trophyPath + "/TROPCONF.SFM";
if (local_tropusr.Load(trophyUsrPath, trophyConfPath).success)
{
tropusr = &local_tropusr;
}
else
{
// TODO: confirm
*count = 0;
*flags = {};
return CELL_OK;
}
}
else
{
if (!ctxt->tropusr)
{
// TODO: May return SCE_NP_TROPHY_ERROR_UNKNOWN_TITLE for older sdk version
return SCE_NP_TROPHY_ERROR_CONTEXT_NOT_REGISTERED;
}
tropusr = ctxt->tropusr.get();
}
ensure(tropusr);
const u32 count_ = tropusr->GetTrophiesCount();
*count = count_;
if (count_ > 128)
sceNpTrophy.error("sceNpTrophyGetTrophyUnlockState: More than 128 trophies detected!");
// Needs hw testing
*flags = {};
// Pack up to 128 bools in u32 flag_bits[4]
for (u32 id = 0; id < count_; id++)
{
if (tropusr->GetTrophyUnlockState(id))
flags->flag_bits[id / 32] |= 1 << (id % 32);
else
flags->flag_bits[id / 32] &= ~(1 << (id % 32));
}
return CELL_OK;
}
error_code sceNpTrophyGetTrophyDetails()
{
UNIMPLEMENTED_FUNC(sceNpTrophy);
return CELL_OK;
}
static error_code NpTrophyGetTrophyInfo(const trophy_context_t* ctxt, s32 trophyId, SceNpTrophyDetails* details, SceNpTrophyData* data)
{
if (!details && !data)
{
return SCE_NP_TROPHY_ERROR_INVALID_ARGUMENT;
}
if (!ctxt->tropusr)
{
// TODO: May return SCE_NP_TROPHY_ERROR_UNKNOWN_TITLE for older sdk version
return SCE_NP_TROPHY_ERROR_CONTEXT_NOT_REGISTERED;
}
const std::string config_path = vfs::get("/dev_hdd0/home/" + Emu.GetUsr() + "/trophy/" + ctxt->trp_name + "/TROPCONF.SFM");
fs::file config(config_path);
if (!config)
{
return { SCE_NP_TROPHY_ERROR_CONF_DOES_NOT_EXIST, config_path };
}
SceNpTrophyDetails tmp_details{};
SceNpTrophyData tmp_data{};
trophy_xml_document doc{};
pugi::xml_parse_result res = doc.Read(config.to_string());
if (!res)
{
sceNpTrophy.error("sceNpTrophyGetGameInfo: Failed to read TROPCONF.SFM: %s", config_path);
// TODO: return some error
}
auto trophy_base = doc.GetRoot();
if (!trophy_base)
{
sceNpTrophy.error("sceNpTrophyGetGameInfo: Failed to read TROPCONF.SFM (root is null): %s", config_path);
// TODO: return some error
}
bool found = false;
for (std::shared_ptr<rXmlNode> n = trophy_base ? trophy_base->GetChildren() : nullptr; n; n = n->GetNext())
{
if (n->GetName() == "trophy" && (trophyId == atoi(n->GetAttribute("id").c_str())))
{
found = true;
const bool hidden = n->GetAttribute("hidden")[0] == 'y';
const bool unlocked = !!ctxt->tropusr->GetTrophyUnlockState(trophyId);
if (hidden && !unlocked) // Trophy is hidden
{
return SCE_NP_TROPHY_ERROR_HIDDEN;
}
if (details)
{
tmp_details.trophyId = trophyId;
tmp_details.hidden = hidden;
switch (n->GetAttribute("ttype")[0])
{
case 'B': tmp_details.trophyGrade = SCE_NP_TROPHY_GRADE_BRONZE; break;
case 'S': tmp_details.trophyGrade = SCE_NP_TROPHY_GRADE_SILVER; break;
case 'G': tmp_details.trophyGrade = SCE_NP_TROPHY_GRADE_GOLD; break;
case 'P': tmp_details.trophyGrade = SCE_NP_TROPHY_GRADE_PLATINUM; break;
default: break;
}
for (std::shared_ptr<rXmlNode> n2 = n->GetChildren(); n2; n2 = n2->GetNext())
{
const std::string n2_name = n2->GetName();
if (n2_name == "name")
{
strcpy_trunc(tmp_details.name, n2->GetNodeContent());
}
else if (n2_name == "detail")
{
strcpy_trunc(tmp_details.description, n2->GetNodeContent());
}
}
}
if (data)
{
tmp_data.trophyId = trophyId;
tmp_data.unlocked = unlocked;
tmp_data.timestamp = ctxt->tropusr->GetTrophyTimestamp(trophyId);
}
break;
}
}
if (!found)
{
return SCE_NP_TROPHY_ERROR_INVALID_TROPHY_ID;
}
if (details)
{
*details = tmp_details;
}
if (data)
{
*data = tmp_data;
}
return CELL_OK;
}
error_code sceNpTrophyGetTrophyInfo(u32 context, u32 handle, s32 trophyId, vm::ptr<SceNpTrophyDetails> details, vm::ptr<SceNpTrophyData> data)
{
sceNpTrophy.warning("sceNpTrophyGetTrophyInfo(context=0x%x, handle=0x%x, trophyId=%d, details=*0x%x, data=*0x%x)", context, handle, trophyId, details, data);
if (trophyId < 0 || trophyId > 127) // max 128 trophies
{
return SCE_NP_TROPHY_ERROR_INVALID_TROPHY_ID;
}
auto& trophy_manager = g_fxo->get<sce_np_trophy_manager>();
reader_lock lock(trophy_manager.mtx);
if (!trophy_manager.is_initialized)
{
return SCE_NP_TROPHY_ERROR_NOT_INITIALIZED;
}
const auto [ctxt, error] = trophy_manager.get_context_ex(context, handle);
if (error)
{
return error;
}
return NpTrophyGetTrophyInfo(ctxt, trophyId, details ? details.get_ptr() : nullptr, data ? data.get_ptr() : nullptr);
}
error_code sceNpTrophyGetGameProgress(u32 context, u32 handle, vm::ptr<s32> percentage)
{
sceNpTrophy.warning("sceNpTrophyGetGameProgress(context=0x%x, handle=0x%x, percentage=*0x%x)", context, handle, percentage);
if (!percentage)
{
return SCE_NP_TROPHY_ERROR_INVALID_ARGUMENT;
}
auto& trophy_manager = g_fxo->get<sce_np_trophy_manager>();
reader_lock lock(trophy_manager.mtx);
if (!trophy_manager.is_initialized)
{
return SCE_NP_TROPHY_ERROR_NOT_INITIALIZED;
}
const auto [ctxt, error] = trophy_manager.get_context_ex(context, handle);
if (error)
{
return error;
}
if (!ctxt->tropusr)
{
// TODO: May return SCE_NP_TROPHY_ERROR_UNKNOWN_TITLE for older sdk version
return SCE_NP_TROPHY_ERROR_CONTEXT_NOT_REGISTERED;
}
const u32 unlocked = ctxt->tropusr->GetUnlockedTrophiesCount();
const u32 trp_count = ctxt->tropusr->GetTrophiesCount();
// Round result to nearest (TODO: Check 0 trophies)
*percentage = trp_count ? utils::rounded_div(unlocked * 100, trp_count) : 0;
if (trp_count == 0 || trp_count > 128)
{
sceNpTrophy.warning("sceNpTrophyGetGameProgress(): Trophies count may be invalid or untested (%d)", trp_count);
}
return CELL_OK;
}
error_code sceNpTrophyGetGameIcon(u32 context, u32 handle, vm::ptr<void> buffer, vm::ptr<u32> size)
{
sceNpTrophy.warning("sceNpTrophyGetGameIcon(context=0x%x, handle=0x%x, buffer=*0x%x, size=*0x%x)", context, handle, buffer, size);
auto& trophy_manager = g_fxo->get<sce_np_trophy_manager>();
reader_lock lock(trophy_manager.mtx);
if (!trophy_manager.is_initialized)
{
return SCE_NP_TROPHY_ERROR_NOT_INITIALIZED;
}
const auto [ctxt, error] = trophy_manager.get_context_ex(context, handle);
if (error)
{
return error;
}
if (!size)
{
return SCE_NP_TROPHY_ERROR_INVALID_ARGUMENT;
}
fs::file icon_file(vfs::get("/dev_hdd0/home/" + Emu.GetUsr() + "/trophy/" + ctxt->trp_name + "/ICON0.PNG"));
if (!icon_file)
{
return SCE_NP_TROPHY_ERROR_UNKNOWN_FILE;
}
const u32 icon_size = ::size32(icon_file);
if (buffer && *size >= icon_size)
{
lv2_file::op_read(icon_file, buffer, icon_size);
}
*size = icon_size;
return CELL_OK;
}
error_code sceNpTrophyGetUserInfo()
{
UNIMPLEMENTED_FUNC(sceNpTrophy);
return CELL_OK;
}
error_code sceNpTrophyGetTrophyIcon(u32 context, u32 handle, s32 trophyId, vm::ptr<void> buffer, vm::ptr<u32> size)
{
sceNpTrophy.warning("sceNpTrophyGetTrophyIcon(context=0x%x, handle=0x%x, trophyId=%d, buffer=*0x%x, size=*0x%x)", context, handle, trophyId, buffer, size);
auto& trophy_manager = g_fxo->get<sce_np_trophy_manager>();
reader_lock lock(trophy_manager.mtx);
if (!trophy_manager.is_initialized)
{
return SCE_NP_TROPHY_ERROR_NOT_INITIALIZED;
}
const auto [ctxt, error] = trophy_manager.get_context_ex(context, handle);
if (error)
{
return error;
}
if (!size)
{
return SCE_NP_TROPHY_ERROR_INVALID_ARGUMENT;
}
if (!ctxt->tropusr)
{
// TODO: May return SCE_NP_TROPHY_ERROR_UNKNOWN_TITLE for older sdk version
return SCE_NP_TROPHY_ERROR_CONTEXT_NOT_REGISTERED;
}
if (ctxt->tropusr->GetTrophiesCount() <= static_cast<u32>(trophyId))
{
return SCE_NP_TROPHY_ERROR_INVALID_TROPHY_ID;
}
if (!ctxt->tropusr->GetTrophyUnlockState(trophyId))
{
const std::string config_path = vfs::get("/dev_hdd0/home/" + Emu.GetUsr() + "/trophy/" + ctxt->trp_name + "/TROPCONF.SFM");
fs::file config(config_path);
if (config)
{
trophy_xml_document doc{};
pugi::xml_parse_result res = doc.Read(config.to_string());
if (!res)
{
sceNpTrophy.error("sceNpTrophyGetTrophyIcon: Failed to read TROPCONF.SFM: %s", config_path);
// TODO: return some error
}
auto trophy_base = doc.GetRoot();
if (!trophy_base)
{
sceNpTrophy.error("sceNpTrophyGetTrophyIcon: Failed to read TROPCONF.SFM (root is null): %s", config_path);
// TODO: return some error
}
for (std::shared_ptr<rXmlNode> n = trophy_base ? trophy_base->GetChildren() : nullptr; n; n = n->GetNext())
{
if (n->GetName() == "trophy" && trophyId == atoi(n->GetAttribute("id").c_str()) && n->GetAttribute("hidden")[0] == 'y')
{
return SCE_NP_TROPHY_ERROR_HIDDEN;
}
}
}
else
{
// TODO: Maybe return SCE_NP_TROPHY_ERROR_CONF_DOES_NOT_EXIST
}
return SCE_NP_TROPHY_ERROR_LOCKED;
}
fs::file icon_file(vfs::get("/dev_hdd0/home/" + Emu.GetUsr() + "/trophy/" + ctxt->trp_name + fmt::format("/TROP%03d.PNG", trophyId)));
if (!icon_file)
{
return SCE_NP_TROPHY_ERROR_UNKNOWN_FILE;
}
const u32 icon_size = ::size32(icon_file);
if (buffer && *size >= icon_size)
{
lv2_file::op_read(icon_file, buffer, icon_size);
}
*size = icon_size;
return CELL_OK;
}
DECLARE(ppu_module_manager::sceNpTrophy)("sceNpTrophy", []()
{
REG_FUNC(sceNpTrophy, sceNpTrophyGetGameProgress);
REG_FUNC(sceNpTrophy, sceNpTrophyRegisterContext);
REG_FUNC(sceNpTrophy, sceNpTrophyCreateHandle);
REG_FUNC(sceNpTrophy, sceNpTrophySetSoundLevel);
REG_FUNC(sceNpTrophy, sceNpTrophyGetRequiredDiskSpace);
REG_FUNC(sceNpTrophy, sceNpTrophyDestroyContext);
REG_FUNC(sceNpTrophy, sceNpTrophyInit);
REG_FUNC(sceNpTrophy, sceNpTrophyAbortHandle);
REG_FUNC(sceNpTrophy, sceNpTrophyGetGameInfo);
REG_FUNC(sceNpTrophy, sceNpTrophyDestroyHandle);
REG_FUNC(sceNpTrophy, sceNpTrophyGetGameDetails);
REG_FUNC(sceNpTrophy, sceNpTrophyUnlockTrophy);
REG_FUNC(sceNpTrophy, sceNpTrophyGetLatestTrophies);
REG_FUNC(sceNpTrophy, sceNpTrophyTerm);
REG_FUNC(sceNpTrophy, sceNpTrophyGetTrophyUnlockState);
REG_FUNC(sceNpTrophy, sceNpTrophyGetUserInfo);
REG_FUNC(sceNpTrophy, sceNpTrophyGetTrophyIcon);
REG_FUNC(sceNpTrophy, sceNpTrophyCreateContext);
REG_FUNC(sceNpTrophy, sceNpTrophyGetTrophyDetails);
REG_FUNC(sceNpTrophy, sceNpTrophyGetTrophyInfo);
REG_FUNC(sceNpTrophy, sceNpTrophyGetGameIcon);
});
| 40,249
|
C++
|
.cpp
| 1,202
| 30.723794
| 167
| 0.717207
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| false
| false
|
5,280
|
cellLibprof.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellLibprof.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
LOG_CHANNEL(cellLibprof);
error_code cellUserTraceInit()
{
UNIMPLEMENTED_FUNC(cellLibprof);
return CELL_OK;
}
error_code cellUserTraceRegister()
{
UNIMPLEMENTED_FUNC(cellLibprof);
return CELL_OK;
}
error_code cellUserTraceUnregister()
{
UNIMPLEMENTED_FUNC(cellLibprof);
return CELL_OK;
}
error_code cellUserTraceTerminate()
{
UNIMPLEMENTED_FUNC(cellLibprof);
return CELL_OK;
}
DECLARE(ppu_module_manager::cellLibprof)("cellLibprof", []()
{
REG_FUNC(cellLibprof, cellUserTraceInit);
REG_FUNC(cellLibprof, cellUserTraceRegister);
REG_FUNC(cellLibprof, cellUserTraceUnregister);
REG_FUNC(cellLibprof, cellUserTraceTerminate);
});
| 697
|
C++
|
.cpp
| 30
| 21.633333
| 60
| 0.813918
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| true
| false
| false
| true
| false
| false
|
5,281
|
cellOskDialog.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellOskDialog.cpp
|
#include "stdafx.h"
#include "Emu/System.h"
#include "Emu/system_config.h"
#include "Emu/Cell/PPUModule.h"
#include "Emu/Io/interception.h"
#include "Emu/Io/Keyboard.h"
#include "Emu/IdManager.h"
#include "Emu/RSX/Overlays/overlay_manager.h"
#include "Emu/RSX/Overlays/overlay_osk.h"
#include "cellSysutil.h"
#include "cellOskDialog.h"
#include "cellMsgDialog.h"
#include "cellImeJp.h"
#include <thread>
LOG_CHANNEL(cellOskDialog);
template<>
void fmt_class_string<CellOskDialogError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_OSKDIALOG_ERROR_IME_ALREADY_IN_USE);
STR_CASE(CELL_OSKDIALOG_ERROR_GET_SIZE_ERROR);
STR_CASE(CELL_OSKDIALOG_ERROR_UNKNOWN);
STR_CASE(CELL_OSKDIALOG_ERROR_PARAM);
}
return unknown;
});
}
template<>
void fmt_class_string<CellOskDialogContinuousMode>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto mode)
{
switch (mode)
{
STR_CASE(CELL_OSKDIALOG_CONTINUOUS_MODE_NONE);
STR_CASE(CELL_OSKDIALOG_CONTINUOUS_MODE_REMAIN_OPEN);
STR_CASE(CELL_OSKDIALOG_CONTINUOUS_MODE_HIDE);
STR_CASE(CELL_OSKDIALOG_CONTINUOUS_MODE_SHOW);
}
return unknown;
});
}
void osk_info::reset()
{
std::lock_guard lock(text_mtx);
dlg.reset();
valid_text = {};
use_separate_windows = false;
lock_ext_input_device = false;
device_mask = 0;
input_field_window_width = 0;
input_field_background_transparency = 1.0f;
input_field_layout_info = {};
input_panel_layout_info = {};
key_layout_options = CELL_OSKDIALOG_10KEY_PANEL;
initial_key_layout = CELL_OSKDIALOG_INITIAL_PANEL_LAYOUT_SYSTEM;
initial_input_device = CELL_OSKDIALOG_INPUT_DEVICE_PAD;
clipboard_enabled = false;
half_byte_kana_enabled = false;
supported_languages = 0;
dimmer_enabled = true;
base_color = OskDialogBase::color{ 0.2f, 0.2f, 0.2f, 1.0f };
pointer_enabled = false;
pointer_x = 0.0f;
pointer_y = 0.0f;
initial_scale = 1.0f;
layout = {};
osk_continuous_mode = CELL_OSKDIALOG_CONTINUOUS_MODE_NONE;
last_dialog_state = CELL_SYSUTIL_OSKDIALOG_UNLOADED;
osk_confirm_callback.store({});
osk_force_finish_callback.store({});
osk_hardware_keyboard_event_hook_callback.store({});
hook_event_mode.store(0);
}
// Align horizontally
u32 osk_info::get_aligned_x(u32 layout_mode)
{
// Let's prefer a centered alignment.
if (layout_mode & CELL_OSKDIALOG_LAYOUTMODE_X_ALIGN_CENTER)
{
return CELL_OSKDIALOG_LAYOUTMODE_X_ALIGN_CENTER;
}
if (layout_mode & CELL_OSKDIALOG_LAYOUTMODE_X_ALIGN_LEFT)
{
return CELL_OSKDIALOG_LAYOUTMODE_X_ALIGN_LEFT;
}
return CELL_OSKDIALOG_LAYOUTMODE_X_ALIGN_RIGHT;
}
// Align vertically
u32 osk_info::get_aligned_y(u32 layout_mode)
{
// Let's prefer a centered alignment.
if (layout_mode & CELL_OSKDIALOG_LAYOUTMODE_Y_ALIGN_CENTER)
{
return CELL_OSKDIALOG_LAYOUTMODE_Y_ALIGN_CENTER;
}
if (layout_mode & CELL_OSKDIALOG_LAYOUTMODE_Y_ALIGN_TOP)
{
return CELL_OSKDIALOG_LAYOUTMODE_Y_ALIGN_TOP;
}
return CELL_OSKDIALOG_LAYOUTMODE_Y_ALIGN_BOTTOM;
}
// TODO: don't use this function
std::shared_ptr<OskDialogBase> _get_osk_dialog(bool create)
{
auto& osk = g_fxo->get<osk_info>();
if (create)
{
const auto init = osk.init.init();
if (!init)
{
return nullptr;
}
if (auto manager = g_fxo->try_get<rsx::overlays::display_manager>())
{
std::shared_ptr<rsx::overlays::osk_dialog> dlg = std::make_shared<rsx::overlays::osk_dialog>();
osk.dlg = manager->add(dlg);
}
else
{
osk.dlg = Emu.GetCallbacks().get_osk_dialog();
}
return osk.dlg;
}
const auto init = osk.init.access();
if (!init)
{
return nullptr;
}
return osk.dlg;
}
extern bool close_osk_from_ps_button()
{
const auto osk = _get_osk_dialog(false);
if (!osk)
{
// The OSK is not open
return true;
}
osk_info& info = g_fxo->get<osk_info>();
// We can only close the osk in separate window mode when it is hidden (continuous_mode is set to CELL_OSKDIALOG_CONTINUOUS_MODE_HIDE)
if (!info.use_separate_windows || osk->continuous_mode != CELL_OSKDIALOG_CONTINUOUS_MODE_HIDE)
{
cellOskDialog.warning("close_osk_from_ps_button: can't close OSK (use_separate_windows=%d, continuous_mode=%s)", info.use_separate_windows.load(), osk->continuous_mode.load());
return false;
}
std::lock_guard lock(info.text_mtx);
if (auto cb = info.osk_force_finish_callback.load())
{
bool done = false;
bool close_osk = false;
sysutil_register_cb([&](ppu_thread& cb_ppu) -> s32
{
cellOskDialog.notice("osk_force_finish_callback()");
close_osk = cb(cb_ppu);
cellOskDialog.notice("osk_force_finish_callback returned %d", close_osk);
done = true;
return 0;
});
// wait for check callback
while (!done && !Emu.IsStopped())
{
std::this_thread::yield();
}
if (!close_osk)
{
// We are not allowed to close the OSK
cellOskDialog.warning("close_osk_from_ps_button: can't close OSK (osk_force_finish_callback returned false)");
return false;
}
}
// Forcefully terminate the OSK
cellOskDialog.warning("close_osk_from_ps_button: Terminating the OSK ...");
osk->Close(FAKE_CELL_OSKDIALOG_CLOSE_TERMINATE);
osk->state = OskDialogState::Closed;
cellOskDialog.notice("close_osk_from_ps_button: sending CELL_SYSUTIL_OSKDIALOG_FINISHED");
sysutil_send_system_cmd(CELL_SYSUTIL_OSKDIALOG_FINISHED, 0);
return true;
}
error_code cellOskDialogLoadAsync(u32 container, vm::ptr<CellOskDialogParam> dialogParam, vm::ptr<CellOskDialogInputFieldInfo> inputFieldInfo)
{
cellOskDialog.warning("cellOskDialogLoadAsync(container=0x%x, dialogParam=*0x%x, inputFieldInfo=*0x%x)", container, dialogParam, inputFieldInfo);
if (!dialogParam || !inputFieldInfo || !inputFieldInfo->message || !inputFieldInfo->init_text || inputFieldInfo->limit_length > CELL_OSKDIALOG_STRING_SIZE)
{
return CELL_OSKDIALOG_ERROR_PARAM;
}
cellOskDialog.notice("cellOskDialogLoadAsync: dialogParam={ allowOskPanelFlg=0x%x, prohibitFlgs=0x%x, firstViewPanel=%d, controlPoint=(%.2f,%.2f) }",
dialogParam->allowOskPanelFlg, dialogParam->prohibitFlgs, dialogParam->firstViewPanel, dialogParam->controlPoint.x, dialogParam->controlPoint.y);
auto osk = _get_osk_dialog(true);
// Can't open another dialog if this one is already open.
if (!osk || osk->state.load() != OskDialogState::Unloaded)
{
return CELL_SYSUTIL_ERROR_BUSY;
}
// Get the OSK options
auto& info = g_fxo->get<osk_info>();
u32 maxLength = (inputFieldInfo->limit_length >= CELL_OSKDIALOG_STRING_SIZE) ? 511 : u32{inputFieldInfo->limit_length};
const u32 prohibitFlgs = dialogParam->prohibitFlgs;
const u32 allowOskPanelFlg = dialogParam->allowOskPanelFlg;
const u32 firstViewPanel = dialogParam->firstViewPanel;
info.layout.x_offset = dialogParam->controlPoint.x;
info.layout.y_offset = dialogParam->controlPoint.y;
// Get init text and prepare return value
osk->osk_input_result = CELL_OSKDIALOG_INPUT_FIELD_RESULT_OK;
osk->osk_text = {};
// Also clear the info text just to be sure (it should be zeroed at this point anyway)
{
std::lock_guard lock(info.text_mtx);
info.valid_text = {};
}
if (inputFieldInfo->init_text)
{
for (u32 i = 0; (i < maxLength) && (inputFieldInfo->init_text[i] != 0); i++)
{
osk->osk_text[i] = inputFieldInfo->init_text[i];
}
}
// Get message to display above the input field
// Guarantees 0 terminated (+1). In praxis only 128 but for now lets display all of it
char16_t message[CELL_OSKDIALOG_STRING_SIZE + 1]{};
if (inputFieldInfo->message)
{
for (u32 i = 0; (i < CELL_OSKDIALOG_STRING_SIZE) && (inputFieldInfo->message[i] != 0); i++)
{
message[i] = inputFieldInfo->message[i];
}
}
osk->on_osk_close = [](s32 status)
{
cellOskDialog.notice("on_osk_close(status=%d)", status);
const auto osk = _get_osk_dialog(false);
if (!osk)
{
return;
}
osk->state = OskDialogState::Closed;
auto& info = g_fxo->get<osk_info>();
const bool keep_seperate_window_open = info.use_separate_windows.load() && (info.osk_continuous_mode.load() != CELL_OSKDIALOG_CONTINUOUS_MODE_NONE);
switch (status)
{
case CELL_OSKDIALOG_CLOSE_CONFIRM:
{
if (auto ccb = info.osk_confirm_callback.load())
{
std::vector<u16> string_to_send(CELL_OSKDIALOG_STRING_SIZE);
atomic_t<bool> done = false;
u32 i;
for (i = 0; i < CELL_OSKDIALOG_STRING_SIZE - 1; i++)
{
string_to_send[i] = osk->osk_text[i];
if (osk->osk_text[i] == 0) break;
}
sysutil_register_cb([&, length = i, string_to_send = std::move(string_to_send)](ppu_thread& cb_ppu) -> s32
{
vm::var<u16[], vm::page_allocator<>> string_var(CELL_OSKDIALOG_STRING_SIZE, string_to_send.data());
const u32 return_value = ccb(cb_ppu, string_var.begin(), static_cast<s32>(length));
cellOskDialog.warning("osk_confirm_callback return_value=%d", return_value);
for (u32 i = 0; i < CELL_OSKDIALOG_STRING_SIZE - 1; i++)
{
osk->osk_text[i] = string_var.begin()[i];
}
done = true;
return 0;
});
// wait for check callback
while (!done && !Emu.IsStopped())
{
std::this_thread::yield();
}
}
if (info.use_separate_windows.load() && osk->osk_text[0] == 0)
{
cellOskDialog.warning("on_osk_close: input result is CELL_OSKDIALOG_INPUT_FIELD_RESULT_NO_INPUT_TEXT");
osk->osk_input_result = CELL_OSKDIALOG_INPUT_FIELD_RESULT_NO_INPUT_TEXT;
}
else
{
osk->osk_input_result = CELL_OSKDIALOG_INPUT_FIELD_RESULT_OK;
}
break;
}
case CELL_OSKDIALOG_CLOSE_CANCEL:
{
osk->osk_input_result = CELL_OSKDIALOG_INPUT_FIELD_RESULT_CANCELED;
break;
}
case FAKE_CELL_OSKDIALOG_CLOSE_ABORT:
{
osk->osk_input_result = CELL_OSKDIALOG_INPUT_FIELD_RESULT_ABORT;
break;
}
default:
{
cellOskDialog.fatal("on_osk_close: Unknown status (%d)", status);
break;
}
}
// Send OSK status
if (keep_seperate_window_open)
{
switch (status)
{
case CELL_OSKDIALOG_CLOSE_CONFIRM:
{
info.last_dialog_state = CELL_SYSUTIL_OSKDIALOG_INPUT_ENTERED;
cellOskDialog.notice("on_osk_close: sending CELL_SYSUTIL_OSKDIALOG_INPUT_ENTERED");
sysutil_send_system_cmd(CELL_SYSUTIL_OSKDIALOG_INPUT_ENTERED, 0);
break;
}
case CELL_OSKDIALOG_CLOSE_CANCEL:
{
info.last_dialog_state = CELL_SYSUTIL_OSKDIALOG_INPUT_CANCELED;
cellOskDialog.notice("on_osk_close: sending CELL_SYSUTIL_OSKDIALOG_INPUT_CANCELED");
sysutil_send_system_cmd(CELL_SYSUTIL_OSKDIALOG_INPUT_CANCELED, 0);
break;
}
case FAKE_CELL_OSKDIALOG_CLOSE_ABORT:
{
// Handled in cellOskDialogAbort
break;
}
default:
{
cellOskDialog.fatal("on_osk_close: Unknown status (%d)", status);
break;
}
}
}
else if (status != FAKE_CELL_OSKDIALOG_CLOSE_ABORT) // Handled in cellOskDialogAbort
{
info.last_dialog_state = CELL_SYSUTIL_OSKDIALOG_FINISHED;
cellOskDialog.notice("on_osk_close: sending CELL_SYSUTIL_OSKDIALOG_FINISHED");
sysutil_send_system_cmd(CELL_SYSUTIL_OSKDIALOG_FINISHED, 0);
}
// The interception status of the continuous separate window is handled differently
if (!keep_seperate_window_open)
{
input::SetIntercepted(false);
}
};
// Set key callback
osk->on_osk_key_input_entered = [](CellOskDialogKeyMessage key_message)
{
auto& info = g_fxo->get<osk_info>();
std::lock_guard lock(info.text_mtx);
auto event_hook_callback = info.osk_hardware_keyboard_event_hook_callback.load();
cellOskDialog.notice("on_osk_key_input_entered: led=%d, mkey=%d, keycode=%d, hook_event_mode=%d, event_hook_callback=*0x%x", key_message.led, key_message.mkey, key_message.keycode, info.hook_event_mode.load(), event_hook_callback);
const auto osk = _get_osk_dialog(false);
if (!osk || !event_hook_callback)
{
// Nothing to do here
return;
}
bool is_hook_key = false;
switch (key_message.keycode)
{
case CELL_KEYC_NO_EVENT:
{
// Any shift/alt/ctrl key
is_hook_key = key_message.mkey > 0 && (info.hook_event_mode & CELL_OSKDIALOG_EVENT_HOOK_TYPE_ONLY_MODIFIER);
break;
}
case CELL_KEYC_E_ROLLOVER:
case CELL_KEYC_E_POSTFAIL:
case CELL_KEYC_E_UNDEF:
case CELL_KEYC_ESCAPE:
case CELL_KEYC_106_KANJI:
case CELL_KEYC_CAPS_LOCK:
case CELL_KEYC_F1:
case CELL_KEYC_F2:
case CELL_KEYC_F3:
case CELL_KEYC_F4:
case CELL_KEYC_F5:
case CELL_KEYC_F6:
case CELL_KEYC_F7:
case CELL_KEYC_F8:
case CELL_KEYC_F9:
case CELL_KEYC_F10:
case CELL_KEYC_F11:
case CELL_KEYC_F12:
case CELL_KEYC_PRINTSCREEN:
case CELL_KEYC_SCROLL_LOCK:
case CELL_KEYC_PAUSE:
case CELL_KEYC_INSERT:
case CELL_KEYC_HOME:
case CELL_KEYC_PAGE_UP:
case CELL_KEYC_DELETE:
case CELL_KEYC_END:
case CELL_KEYC_PAGE_DOWN:
case CELL_KEYC_RIGHT_ARROW:
case CELL_KEYC_LEFT_ARROW:
case CELL_KEYC_DOWN_ARROW:
case CELL_KEYC_UP_ARROW:
case CELL_KEYC_NUM_LOCK:
case CELL_KEYC_APPLICATION:
case CELL_KEYC_KANA:
case CELL_KEYC_HENKAN:
case CELL_KEYC_MUHENKAN:
{
// Any function key or other special key like Delete
is_hook_key = (info.hook_event_mode & CELL_OSKDIALOG_EVENT_HOOK_TYPE_FUNCTION_KEY);
break;
}
default:
{
// Any regular ascii key
is_hook_key = (info.hook_event_mode & CELL_OSKDIALOG_EVENT_HOOK_TYPE_ASCII_KEY);
break;
}
}
if (!is_hook_key)
{
cellOskDialog.notice("on_osk_key_input_entered: not a hook key: led=%d, mkey=%d, keycode=%d, hook_event_mode=%d", key_message.led, key_message.mkey, key_message.keycode, info.hook_event_mode.load());
return;
}
// The max size is 100 characters plus '\0'. Apparently this used to be 30 plus '\0' in older firmware.
constexpr u32 max_size = 101;
// TODO: Send unconfirmed string if there is one.
// As far as I understand, this is for example supposed to be the IME preview.
// So when you type in japanese, you get some word propositions which you can select and confirm.
// The "confirmed" string is basically everything you already wrote, while the "unconfirmed"
// string is the auto-completion part that you haven't accepted as proper word yet.
// The game expects you to send this "preview", or an empty string if there is none.
std::array<u16, max_size> string_to_send{};
sysutil_register_cb([key_message, string_to_send, event_hook_callback](ppu_thread& cb_ppu) -> s32
{
// Prepare callback variables
vm::var<CellOskDialogKeyMessage> keyMessage(key_message);
vm::var<u32> action(CELL_OSKDIALOG_CHANGE_NO_EVENT);
vm::var<u16[], vm::page_allocator<>> pActionInfo(::narrow<u32>(string_to_send.size()), string_to_send.data());
// Create helpers for logging
std::u16string utf16_string(reinterpret_cast<const char16_t*>(string_to_send.data()), string_to_send.size());
std::string utf8_string = utf16_to_ascii8(utf16_string);
cellOskDialog.notice("osk_hardware_keyboard_event_hook_callback(led=%d, mkey=%d, keycode=%d, action=%d, pActionInfo='%s')", keyMessage->led, keyMessage->mkey, keyMessage->keycode, *action, utf8_string);
// Call the hook function. The game reads and writes pActionInfo. We need to react based on the returned action.
const bool return_value = event_hook_callback(cb_ppu, keyMessage, action, pActionInfo);
ensure(action);
ensure(pActionInfo);
// Parse returned text for logging
utf16_string.clear();
for (u32 i = 0; i < max_size; i++)
{
const u16 code = pActionInfo[i];
if (!code) break;
utf16_string.push_back(code);
}
utf8_string = utf16_to_ascii8(utf16_string);
cellOskDialog.notice("osk_hardware_keyboard_event_hook_callback: return_value=%d, action=%d, pActionInfo='%s'", return_value, *action, utf8_string);
// Check if the hook function was successful
if (return_value)
{
const auto osk = _get_osk_dialog(false);
if (!osk)
{
cellOskDialog.error("osk_hardware_keyboard_event_hook_callback: osk is null");
return 0;
}
auto& info = g_fxo->get<osk_info>();
std::lock_guard lock(info.text_mtx);
switch (*action)
{
case CELL_OSKDIALOG_CHANGE_NO_EVENT:
case CELL_OSKDIALOG_CHANGE_EVENT_CANCEL:
{
// Do nothing
break;
}
case CELL_OSKDIALOG_CHANGE_WORDS_INPUT:
{
// TODO: Replace unconfirmed string.
cellOskDialog.todo("osk_hardware_keyboard_event_hook_callback: replace unconfirmed string with '%s'", utf8_string);
break;
}
case CELL_OSKDIALOG_CHANGE_WORDS_INSERT:
{
// TODO: Remove unconfirmed string
cellOskDialog.todo("osk_hardware_keyboard_event_hook_callback: remove unconfirmed string");
// Set confirmed string and reset unconfirmed string
cellOskDialog.notice("osk_hardware_keyboard_event_hook_callback: inserting string '%s'", utf8_string);
osk->Insert(utf16_string);
break;
}
case CELL_OSKDIALOG_CHANGE_WORDS_REPLACE_ALL:
{
// Replace confirmed string and remove unconfirmed string.
cellOskDialog.notice("osk_hardware_keyboard_event_hook_callback: replacing all strings with '%s'", utf8_string);
osk->SetText(utf16_string);
break;
}
default:
{
cellOskDialog.error("osk_hardware_keyboard_event_hook_callback returned invalid action (%d)", *action);
break;
}
}
}
return 0;
});
};
// Set device mask and event lock
osk->ignore_device_events = info.lock_ext_input_device.load();
osk->input_device = info.initial_input_device.load();
osk->continuous_mode = info.osk_continuous_mode.load();
if (info.use_separate_windows)
{
osk->pad_input_enabled = (info.device_mask != CELL_OSKDIALOG_DEVICE_MASK_PAD);
osk->mouse_input_enabled = (info.device_mask != CELL_OSKDIALOG_DEVICE_MASK_PAD);
}
input::SetIntercepted(osk->pad_input_enabled, osk->keyboard_input_enabled, osk->mouse_input_enabled);
cellOskDialog.notice("cellOskDialogLoadAsync: creating OSK dialog ...");
Emu.BlockingCallFromMainThread([=, &info]()
{
osk->Create({
.title = get_localized_string(localized_string_id::CELL_OSK_DIALOG_TITLE),
.message = message,
.init_text = osk->osk_text.data(),
.charlimit = maxLength,
.prohibit_flags = prohibitFlgs,
.panel_flag = allowOskPanelFlg,
.support_language = info.supported_languages,
.first_view_panel = firstViewPanel,
.layout = info.layout,
.input_layout = info.input_field_layout_info,
.panel_layout = info.input_panel_layout_info,
.input_field_window_width = info.input_field_window_width,
.input_field_background_transparency = info.input_field_background_transparency,
.initial_scale = info.initial_scale,
.base_color = info.base_color,
.dimmer_enabled = info.dimmer_enabled,
.use_separate_windows = info.use_separate_windows,
.intercept_input = false // We handle the interception manually based on the device mask
});
});
g_fxo->get<osk_info>().last_dialog_state = CELL_SYSUTIL_OSKDIALOG_LOADED;
if (info.use_separate_windows)
{
const bool visible = osk->continuous_mode != CELL_OSKDIALOG_CONTINUOUS_MODE_HIDE;
cellOskDialog.notice("cellOskDialogLoadAsync: sending CELL_SYSUTIL_OSKDIALOG_DISPLAY_CHANGED with %s", visible ? "CELL_OSKDIALOG_DISPLAY_STATUS_SHOW" : "CELL_OSKDIALOG_DISPLAY_STATUS_HIDE");
sysutil_send_system_cmd(CELL_SYSUTIL_OSKDIALOG_DISPLAY_CHANGED, visible ? CELL_OSKDIALOG_DISPLAY_STATUS_SHOW : CELL_OSKDIALOG_DISPLAY_STATUS_HIDE);
}
cellOskDialog.notice("cellOskDialogLoadAsync: sending CELL_SYSUTIL_OSKDIALOG_LOADED");
sysutil_send_system_cmd(CELL_SYSUTIL_OSKDIALOG_LOADED, 0);
cellOskDialog.notice("cellOskDialogLoadAsync: created OSK dialog");
return CELL_OK;
}
error_code cellOskDialogLoadAsyncExt()
{
cellOskDialog.todo("cellOskDialogLoadAsyncExt()");
return CELL_OK;
}
error_code getText(vm::ptr<CellOskDialogCallbackReturnParam> OutputInfo, bool is_unload)
{
if (!OutputInfo || OutputInfo->numCharsResultString < 0)
{
return CELL_OSKDIALOG_ERROR_PARAM;
}
const auto osk = _get_osk_dialog(false);
if (!osk)
{
return CELL_MSGDIALOG_ERROR_DIALOG_NOT_OPENED;
}
auto& info = g_fxo->get<osk_info>();
const bool keep_seperate_window_open = info.use_separate_windows.load() && (info.osk_continuous_mode.load() != CELL_OSKDIALOG_CONTINUOUS_MODE_NONE);
info.text_mtx.lock();
// Update text buffer if called from cellOskDialogUnloadAsync or if the user accepted the dialog during continuous seperate window mode.
if (is_unload || (keep_seperate_window_open && info.last_dialog_state == CELL_SYSUTIL_OSKDIALOG_INPUT_ENTERED))
{
for (s32 i = 0; i < CELL_OSKDIALOG_STRING_SIZE - 1; i++)
{
info.valid_text[i] = osk->osk_text[i];
}
}
if (is_unload)
{
OutputInfo->result = osk->osk_input_result.load();
}
else
{
if (info.valid_text[0] == 0)
{
OutputInfo->result = CELL_OSKDIALOG_INPUT_FIELD_RESULT_NO_INPUT_TEXT;
}
else
{
OutputInfo->result = CELL_OSKDIALOG_INPUT_FIELD_RESULT_OK;
}
}
const bool do_copy = OutputInfo->pResultString && (OutputInfo->result == CELL_OSKDIALOG_INPUT_FIELD_RESULT_OK || (is_unload && OutputInfo->result == CELL_OSKDIALOG_INPUT_FIELD_RESULT_NO_INPUT_TEXT));
for (s32 i = 0; do_copy && i < CELL_OSKDIALOG_STRING_SIZE - 1; i++)
{
if (i < OutputInfo->numCharsResultString)
{
OutputInfo->pResultString[i] = info.valid_text[i];
if (info.valid_text[i] == 0)
{
break;
}
}
else
{
OutputInfo->pResultString[i] = 0;
break;
}
}
info.text_mtx.unlock();
if (is_unload)
{
// Unload should be called last, so remove the dialog here
if (const auto reset_lock = info.init.reset())
{
info.reset();
}
if (keep_seperate_window_open)
{
cellOskDialog.notice("cellOskDialogUnloadAsync: terminating continuous overlay");
osk->Close(FAKE_CELL_OSKDIALOG_CLOSE_TERMINATE);
}
osk->state = OskDialogState::Unloaded;
cellOskDialog.notice("cellOskDialogUnloadAsync: sending CELL_SYSUTIL_OSKDIALOG_UNLOADED");
sysutil_send_system_cmd(CELL_SYSUTIL_OSKDIALOG_UNLOADED, 0);
}
else if (keep_seperate_window_open)
{
// Clear text buffer unless the dialog is still open during continuous seperate window mode.
switch (info.last_dialog_state)
{
case CELL_SYSUTIL_OSKDIALOG_FINISHED:
case CELL_SYSUTIL_OSKDIALOG_UNLOADED:
case CELL_SYSUTIL_OSKDIALOG_INPUT_CANCELED:
case CELL_SYSUTIL_OSKDIALOG_INPUT_ENTERED:
{
auto& info = g_fxo->get<osk_info>();
std::lock_guard lock(info.text_mtx);
info.valid_text = {};
osk->Clear(true);
break;
}
default:
break;
}
}
return CELL_OK;
}
error_code cellOskDialogUnloadAsync(vm::ptr<CellOskDialogCallbackReturnParam> OutputInfo)
{
cellOskDialog.warning("cellOskDialogUnloadAsync(OutputInfo=*0x%x)", OutputInfo);
return getText(OutputInfo, true);
}
error_code cellOskDialogGetSize(vm::ptr<u16> width, vm::ptr<u16> height, u32 /*CellOskDialogType*/ dialogType)
{
cellOskDialog.warning("cellOskDialogGetSize(width=*0x%x, height=*0x%x, dialogType=%d)", width, height, dialogType);
if (!width || !height)
{
return CELL_OSKDIALOG_ERROR_PARAM;
}
if (dialogType >= CELL_OSKDIALOG_TYPE_SEPARATE_SINGLELINE_TEXT_WINDOW)
{
*width = 0;
}
else
{
*width = 1;
}
*height = 1;
return CELL_OK;
}
error_code cellOskDialogAbort()
{
cellOskDialog.warning("cellOskDialogAbort()");
const auto osk = _get_osk_dialog(false);
if (!osk)
{
return CELL_MSGDIALOG_ERROR_DIALOG_NOT_OPENED;
}
const error_code result = osk->state.atomic_op([](OskDialogState& state) -> error_code
{
// Check for open dialog. In this case the dialog is "Open" if it was not unloaded before.
if (state == OskDialogState::Unloaded)
{
return CELL_MSGDIALOG_ERROR_DIALOG_NOT_OPENED;
}
state = OskDialogState::Abort;
return CELL_OK;
});
if (result == CELL_OK)
{
osk->osk_input_result = CELL_OSKDIALOG_INPUT_FIELD_RESULT_ABORT;
osk->Close(FAKE_CELL_OSKDIALOG_CLOSE_ABORT);
}
g_fxo->get<osk_info>().last_dialog_state = CELL_SYSUTIL_OSKDIALOG_FINISHED;
cellOskDialog.notice("cellOskDialogAbort: sending CELL_SYSUTIL_OSKDIALOG_FINISHED");
sysutil_send_system_cmd(CELL_SYSUTIL_OSKDIALOG_FINISHED, 0);
return CELL_OK;
}
error_code cellOskDialogSetDeviceMask(u32 deviceMask)
{
cellOskDialog.warning("cellOskDialogSetDeviceMask(deviceMask=0x%x)", deviceMask);
// TODO: It might also return an error if use_separate_windows is not enabled
if (deviceMask > CELL_OSKDIALOG_DEVICE_MASK_PAD)
{
return CELL_OSKDIALOG_ERROR_PARAM;
}
auto& info = g_fxo->get<osk_info>();
info.device_mask = deviceMask;
if (info.use_separate_windows)
{
if (const auto osk = _get_osk_dialog(false))
{
osk->pad_input_enabled = (deviceMask != CELL_OSKDIALOG_DEVICE_MASK_PAD);
osk->mouse_input_enabled = (deviceMask != CELL_OSKDIALOG_DEVICE_MASK_PAD);
input::SetIntercepted(osk->pad_input_enabled, osk->keyboard_input_enabled, osk->mouse_input_enabled);
}
}
return CELL_OK;
}
error_code cellOskDialogSetSeparateWindowOption(vm::ptr<CellOskDialogSeparateWindowOption> windowOption)
{
cellOskDialog.warning("cellOskDialogSetSeparateWindowOption(windowOption=*0x%x)", windowOption);
if (!windowOption ||
!windowOption->inputFieldLayoutInfo ||
!!windowOption->reserved ||
windowOption->continuousMode > CELL_OSKDIALOG_CONTINUOUS_MODE_SHOW ||
windowOption->deviceMask > CELL_OSKDIALOG_DEVICE_MASK_PAD)
{
return CELL_OSKDIALOG_ERROR_PARAM;
}
auto& osk = g_fxo->get<osk_info>();
osk.use_separate_windows = true;
osk.osk_continuous_mode = static_cast<CellOskDialogContinuousMode>(+windowOption->continuousMode);
osk.device_mask = windowOption->deviceMask;
osk.input_field_window_width = windowOption->inputFieldWindowWidth;
osk.input_field_background_transparency = std::clamp<f32>(windowOption->inputFieldBackgroundTrans, 0.0f, 1.0f);
// Choose proper alignments, since the devs didn't make them exclusive for some reason.
const auto aligned_layout = [](const CellOskDialogLayoutInfo& info) -> osk_window_layout
{
osk_window_layout res{};
res.layout_mode = info.layoutMode;
res.x_align = osk_info::get_aligned_x(res.layout_mode);
res.y_align = osk_info::get_aligned_y(res.layout_mode);
res.x_offset = info.position.x;
res.y_offset = info.position.y;
return res;
};
osk.input_field_layout_info = aligned_layout(*windowOption->inputFieldLayoutInfo);
// Panel layout is optional
if (windowOption->inputPanelLayoutInfo)
{
osk.input_panel_layout_info = aligned_layout(*windowOption->inputPanelLayoutInfo);
}
else
{
// Align to input field
osk.input_panel_layout_info = osk.input_field_layout_info;
}
cellOskDialog.warning("cellOskDialogSetSeparateWindowOption: use_separate_windows=true, continuous_mode=%s, device_mask=0x%x, input_field_window_width=%d, input_field_background_transparency=%.2f, input_field_layout_info=%s, input_panel_layout_info=%s)",
osk.osk_continuous_mode.load(), osk.device_mask.load(), osk.input_field_window_width.load(), osk.input_field_background_transparency.load(), osk.input_field_layout_info, osk.input_panel_layout_info);
return CELL_OK;
}
error_code cellOskDialogSetInitialInputDevice(u32 inputDevice)
{
cellOskDialog.warning("cellOskDialogSetInitialInputDevice(inputDevice=%d)", inputDevice);
if (inputDevice > CELL_OSKDIALOG_INPUT_DEVICE_KEYBOARD)
{
return CELL_OSKDIALOG_ERROR_PARAM;
}
g_fxo->get<osk_info>().initial_input_device = static_cast<CellOskDialogInputDevice>(inputDevice);
return CELL_OK;
}
error_code cellOskDialogSetInitialKeyLayout(u32 initialKeyLayout)
{
cellOskDialog.warning("cellOskDialogSetInitialKeyLayout(initialKeyLayout=%d)", initialKeyLayout);
if (initialKeyLayout > CELL_OSKDIALOG_INITIAL_PANEL_LAYOUT_FULLKEY)
{
return CELL_OSKDIALOG_ERROR_PARAM;
}
auto& osk = g_fxo->get<osk_info>();
if (osk.key_layout_options & initialKeyLayout)
{
osk.initial_key_layout = static_cast<CellOskDialogInitialKeyLayout>(initialKeyLayout);
}
return CELL_OK;
}
error_code cellOskDialogDisableDimmer()
{
cellOskDialog.warning("cellOskDialogDisableDimmer()");
g_fxo->get<osk_info>().dimmer_enabled = false;
return CELL_OK;
}
error_code cellOskDialogSetKeyLayoutOption(u32 option)
{
cellOskDialog.warning("cellOskDialogSetKeyLayoutOption(option=0x%x)", option);
if (option == 0 || option > 3) // CELL_OSKDIALOG_10KEY_PANEL OR CELL_OSKDIALOG_FULLKEY_PANEL
{
return CELL_OSKDIALOG_ERROR_PARAM;
}
g_fxo->get<osk_info>().key_layout_options = option;
return CELL_OK;
}
error_code cellOskDialogAddSupportLanguage(u32 supportLanguage)
{
cellOskDialog.warning("cellOskDialogAddSupportLanguage(supportLanguage=0x%x)", supportLanguage);
g_fxo->get<osk_info>().supported_languages = supportLanguage;
return CELL_OK;
}
error_code cellOskDialogSetLayoutMode(s32 layoutMode)
{
cellOskDialog.warning("cellOskDialogSetLayoutMode(layoutMode=0x%x)", layoutMode);
auto& osk = g_fxo->get<osk_info>();
osk.layout.layout_mode = layoutMode;
// Choose proper alignments, since the devs didn't make them exclusive for some reason.
osk.layout.x_align = osk_info::get_aligned_x(layoutMode);
osk.layout.y_align = osk_info::get_aligned_y(layoutMode);
return CELL_OK;
}
error_code cellOskDialogGetInputText(vm::ptr<CellOskDialogCallbackReturnParam> OutputInfo)
{
cellOskDialog.warning("cellOskDialogGetInputText(OutputInfo=*0x%x)", OutputInfo);
return getText(OutputInfo, false);
}
error_code register_keyboard_event_hook_callback(u16 hookEventMode, vm::ptr<cellOskDialogHardwareKeyboardEventHookCallback> pCallback)
{
cellOskDialog.warning("register_keyboard_event_hook_callback(hookEventMode=%u, pCallback=*0x%x)", hookEventMode, pCallback);
if (!pCallback)
{
return CELL_OSKDIALOG_ERROR_PARAM;
}
g_fxo->get<osk_info>().osk_hardware_keyboard_event_hook_callback = pCallback;
g_fxo->get<osk_info>().hook_event_mode = hookEventMode;
return CELL_OK;
}
error_code cellOskDialogExtRegisterKeyboardEventHookCallback(u16 hookEventMode, vm::ptr<cellOskDialogHardwareKeyboardEventHookCallback> pCallback)
{
cellOskDialog.warning("cellOskDialogExtRegisterKeyboardEventHookCallback(hookEventMode=%u, pCallback=*0x%x)", hookEventMode, pCallback);
if (hookEventMode == 0 || hookEventMode > (CELL_OSKDIALOG_EVENT_HOOK_TYPE_FUNCTION_KEY | CELL_OSKDIALOG_EVENT_HOOK_TYPE_ASCII_KEY))
{
return CELL_OSKDIALOG_ERROR_PARAM;
}
return register_keyboard_event_hook_callback(hookEventMode, pCallback);
}
error_code cellOskDialogExtRegisterKeyboardEventHookCallbackEx(u16 hookEventMode, vm::ptr<cellOskDialogHardwareKeyboardEventHookCallback> pCallback)
{
cellOskDialog.warning("cellOskDialogExtRegisterKeyboardEventHookCallbackEx(hookEventMode=%u, pCallback=*0x%x)", hookEventMode, pCallback);
if (hookEventMode == 0 || hookEventMode > (CELL_OSKDIALOG_EVENT_HOOK_TYPE_FUNCTION_KEY | CELL_OSKDIALOG_EVENT_HOOK_TYPE_ASCII_KEY | CELL_OSKDIALOG_EVENT_HOOK_TYPE_ONLY_MODIFIER))
{
return CELL_OSKDIALOG_ERROR_PARAM;
}
return register_keyboard_event_hook_callback(hookEventMode, pCallback);
}
error_code cellOskDialogExtAddJapaneseOptionDictionary(vm::cpptr<char> filePath)
{
cellOskDialog.todo("cellOskDialogExtAddJapaneseOptionDictionary(filePath=**0x%0x)", filePath);
std::vector<std::string> paths;
if (filePath)
{
for (u32 i = 0; i < 4; i++)
{
if (!filePath[i])
{
break;
}
std::array<char, CELL_IMEJP_DIC_PATH_MAXLENGTH + 1> path{};
std::memcpy(path.data(), filePath[i].get_ptr(), CELL_IMEJP_DIC_PATH_MAXLENGTH);
paths.push_back(path.data());
}
}
cellOskDialog.todo("cellOskDialogExtAddJapaneseOptionDictionary: got %d dictionaries:\n%s", paths.size(), fmt::merge(paths, "\n"));
return CELL_OK;
}
error_code cellOskDialogExtEnableClipboard()
{
cellOskDialog.todo("cellOskDialogExtEnableClipboard()");
g_fxo->get<osk_info>().clipboard_enabled = true;
// TODO: implement copy paste
return CELL_OK;
}
error_code cellOskDialogExtSendFinishMessage(u32 /*CellOskDialogFinishReason*/ finishReason)
{
cellOskDialog.warning("cellOskDialogExtSendFinishMessage(finishReason=%d)", finishReason);
const auto osk = _get_osk_dialog(false);
// Check for "Open" dialog.
if (!osk || osk->state.load() == OskDialogState::Unloaded)
{
return CELL_MSGDIALOG_ERROR_DIALOG_NOT_OPENED;
}
osk->Close(finishReason);
return CELL_OK;
}
error_code cellOskDialogExtAddOptionDictionary(vm::cpptr<CellOskDialogImeDictionaryInfo> dictionaryInfo)
{
cellOskDialog.todo("cellOskDialogExtAddOptionDictionary(dictionaryInfo=*0x%x)", dictionaryInfo);
if (!dictionaryInfo)
{
return CELL_OSKDIALOG_ERROR_PARAM;
}
std::vector<std::pair<u32, std::string>> paths; // language and path
for (u32 i = 0; i < 10; i++)
{
if (!dictionaryInfo[i] || !dictionaryInfo[i]->dictionaryPath)
{
break;
}
std::array<char, CELL_IMEJP_DIC_PATH_MAXLENGTH + 1> path{};
std::memcpy(path.data(), dictionaryInfo[i]->dictionaryPath.get_ptr(), CELL_IMEJP_DIC_PATH_MAXLENGTH);
paths.push_back({ dictionaryInfo[i]->targetLanguage, path.data() });
}
std::vector<std::string> msgs;
for (const auto& entry : paths)
{
msgs.push_back(fmt::format("languages=0x%x, path='%s'", entry.first, entry.second));
}
cellOskDialog.todo("cellOskDialogExtAddOptionDictionary: got %d dictionaries:\n%s", msgs.size(), fmt::merge(msgs, "\n"));
return CELL_OK;
}
error_code cellOskDialogExtSetInitialScale(f32 initialScale)
{
cellOskDialog.warning("cellOskDialogExtSetInitialScale(initialScale=%f)", initialScale);
if (initialScale < CELL_OSKDIALOG_SCALE_MIN || initialScale > CELL_OSKDIALOG_SCALE_MAX)
{
return CELL_OSKDIALOG_ERROR_PARAM;
}
g_fxo->get<osk_info>().initial_scale = initialScale;
return CELL_OK;
}
error_code cellOskDialogExtInputDeviceLock()
{
cellOskDialog.warning("cellOskDialogExtInputDeviceLock()");
g_fxo->get<osk_info>().lock_ext_input_device = true;
if (const auto osk = _get_osk_dialog(false))
{
osk->ignore_device_events = true;
}
return CELL_OK;
}
error_code cellOskDialogExtInputDeviceUnlock()
{
cellOskDialog.warning("cellOskDialogExtInputDeviceUnlock()");
g_fxo->get<osk_info>().lock_ext_input_device = false;
if (const auto osk = _get_osk_dialog(false))
{
osk->ignore_device_events = false;
}
return CELL_OK;
}
error_code cellOskDialogExtSetBaseColor(f32 red, f32 green, f32 blue, f32 alpha)
{
cellOskDialog.warning("cellOskDialogExtSetBaseColor(red=%f, blue=%f, green=%f, alpha=%f)", red, blue, green, alpha);
if (red < 0.0f || red > 1.0f || green < 0.0f || green > 1.0f || blue < 0.0f || blue > 1.0f || alpha < 0.0f || alpha > 1.0f)
{
return CELL_OSKDIALOG_ERROR_PARAM;
}
auto& osk = g_fxo->get<osk_info>();
osk.base_color = OskDialogBase::color{ red, green, blue, alpha };
return CELL_OK;
}
error_code cellOskDialogExtRegisterConfirmWordFilterCallback(vm::ptr<cellOskDialogConfirmWordFilterCallback> pCallback)
{
cellOskDialog.warning("cellOskDialogExtRegisterConfirmWordFilterCallback(pCallback=*0x%x)", pCallback);
if (!pCallback)
{
return CELL_OSKDIALOG_ERROR_PARAM;
}
g_fxo->get<osk_info>().osk_confirm_callback = pCallback;
return CELL_OK;
}
error_code cellOskDialogExtUpdateInputText()
{
cellOskDialog.todo("cellOskDialogExtUpdateInputText()");
// Usually, user input is only available when the dialog was accepted.
// This function seems to be called in order to copy the current text to an internal buffer.
// Afterwards, cellOskDialogGetInputText can be called to fetch the current text regardless of
// user confirmation, even if the dialog is still in use.
// TODO: error checks
const auto osk = _get_osk_dialog(false);
if (osk)
{
auto& info = g_fxo->get<osk_info>();
std::lock_guard lock(info.text_mtx);
for (s32 i = 0; i < CELL_OSKDIALOG_STRING_SIZE - 1; i++)
{
info.valid_text[i] = osk->osk_text[i];
}
}
return CELL_OK;
}
error_code cellOskDialogExtSetPointerEnable(b8 enable)
{
cellOskDialog.warning("cellOskDialogExtSetPointerEnable(enable=%d)", enable);
// TODO: While the pointer is already displayed in the osk overlay, it is not really useful right now.
// On real hardware, this may be used for actual PS Move or mouse input.
g_fxo->get<osk_info>().pointer_enabled = enable;
return CELL_OK;
}
error_code cellOskDialogExtUpdatePointerDisplayPos(vm::cptr<CellOskDialogPoint> pos)
{
cellOskDialog.warning("cellOskDialogExtUpdatePointerDisplayPos(pos=0x%x, posX=%f, posY=%f)", pos, pos->x, pos->y);
if (pos)
{
osk_info& osk = g_fxo->get<osk_info>();
osk.pointer_x = pos->x;
osk.pointer_y = pos->y;
}
return CELL_OK;
}
error_code cellOskDialogExtEnableHalfByteKana()
{
cellOskDialog.todo("cellOskDialogExtEnableHalfByteKana()");
g_fxo->get<osk_info>().half_byte_kana_enabled = true;
// TODO: use new value in osk
return CELL_OK;
}
error_code cellOskDialogExtDisableHalfByteKana()
{
cellOskDialog.todo("cellOskDialogExtDisableHalfByteKana()");
g_fxo->get<osk_info>().half_byte_kana_enabled = false;
// TODO: use new value in osk
return CELL_OK;
}
error_code cellOskDialogExtRegisterForceFinishCallback(vm::ptr<cellOskDialogForceFinishCallback> pCallback)
{
cellOskDialog.warning("cellOskDialogExtRegisterForceFinishCallback(pCallback=*0x%x)", pCallback);
if (!pCallback)
{
return CELL_OSKDIALOG_ERROR_PARAM;
}
osk_info& info = g_fxo->get<osk_info>();
std::lock_guard lock(info.text_mtx);
info.osk_force_finish_callback = pCallback;
// We use the force finish callback when the PS-Button is pressed and a System dialog shall be spawned while the OSK is loaded
// 1. Check if we are in any continuous mode and the dialog is hidden
// 2. If the above is true, call osk_force_finish_callback, deny the PS-Button press otherwise
// 3. Check the return value of osk_force_finish_callback.
// if false, ignore the PS-Button press,
// else close the dialog etc., send CELL_SYSUTIL_OSKDIALOG_FINISHED
return CELL_OK;
}
void cellSysutil_OskDialog_init()
{
REG_FUNC(cellSysutil, cellOskDialogLoadAsync);
REG_FUNC(cellSysutil, cellOskDialogLoadAsyncExt);
REG_FUNC(cellSysutil, cellOskDialogUnloadAsync);
REG_FUNC(cellSysutil, cellOskDialogGetSize);
REG_FUNC(cellSysutil, cellOskDialogAbort);
REG_FUNC(cellSysutil, cellOskDialogSetDeviceMask);
REG_FUNC(cellSysutil, cellOskDialogSetSeparateWindowOption);
REG_FUNC(cellSysutil, cellOskDialogSetInitialInputDevice);
REG_FUNC(cellSysutil, cellOskDialogSetInitialKeyLayout);
REG_FUNC(cellSysutil, cellOskDialogDisableDimmer);
REG_FUNC(cellSysutil, cellOskDialogSetKeyLayoutOption);
REG_FUNC(cellSysutil, cellOskDialogAddSupportLanguage);
REG_FUNC(cellSysutil, cellOskDialogSetLayoutMode);
REG_FUNC(cellSysutil, cellOskDialogGetInputText);
}
DECLARE(ppu_module_manager::cellOskDialog)("cellOskExtUtility", []()
{
REG_FUNC(cellOskExtUtility, cellOskDialogExtInputDeviceUnlock);
REG_FUNC(cellOskExtUtility, cellOskDialogExtRegisterKeyboardEventHookCallback);
REG_FUNC(cellOskExtUtility, cellOskDialogExtRegisterKeyboardEventHookCallbackEx);
REG_FUNC(cellOskExtUtility, cellOskDialogExtAddJapaneseOptionDictionary);
REG_FUNC(cellOskExtUtility, cellOskDialogExtEnableClipboard);
REG_FUNC(cellOskExtUtility, cellOskDialogExtSendFinishMessage);
REG_FUNC(cellOskExtUtility, cellOskDialogExtAddOptionDictionary);
REG_FUNC(cellOskExtUtility, cellOskDialogExtSetInitialScale);
REG_FUNC(cellOskExtUtility, cellOskDialogExtInputDeviceLock);
REG_FUNC(cellOskExtUtility, cellOskDialogExtSetBaseColor);
REG_FUNC(cellOskExtUtility, cellOskDialogExtRegisterConfirmWordFilterCallback);
REG_FUNC(cellOskExtUtility, cellOskDialogExtUpdateInputText);
REG_FUNC(cellOskExtUtility, cellOskDialogExtDisableHalfByteKana);
REG_FUNC(cellOskExtUtility, cellOskDialogExtSetPointerEnable);
REG_FUNC(cellOskExtUtility, cellOskDialogExtUpdatePointerDisplayPos);
REG_FUNC(cellOskExtUtility, cellOskDialogExtEnableHalfByteKana);
REG_FUNC(cellOskExtUtility, cellOskDialogExtRegisterForceFinishCallback);
});
| 39,630
|
C++
|
.cpp
| 1,075
| 33.973023
| 255
| 0.745562
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
5,282
|
cellPngEnc.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellPngEnc.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
#include "Emu/IdManager.h"
#include "cellPngEnc.h"
#include "png.h"
LOG_CHANNEL(cellPngEnc);
template <>
void fmt_class_string<CellPngEncError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](CellPngEncError value)
{
switch (value)
{
STR_CASE(CELL_PNGENC_ERROR_ARG);
STR_CASE(CELL_PNGENC_ERROR_SEQ);
STR_CASE(CELL_PNGENC_ERROR_BUSY);
STR_CASE(CELL_PNGENC_ERROR_EMPTY);
STR_CASE(CELL_PNGENC_ERROR_RESET);
STR_CASE(CELL_PNGENC_ERROR_FATAL);
STR_CASE(CELL_PNGENC_ERROR_STREAM_ABORT);
STR_CASE(CELL_PNGENC_ERROR_STREAM_SKIP);
STR_CASE(CELL_PNGENC_ERROR_STREAM_OVERFLOW);
STR_CASE(CELL_PNGENC_ERROR_STREAM_FILE_OPEN);
}
return unknown;
});
}
struct png_encoder
{
shared_mutex mutex;
CellPngEncConfig config{};
CellPngEncResource resource{};
CellPngEncResourceEx resourceEx{};
};
bool check_config(vm::cptr<CellPngEncConfig> config)
{
if (!config ||
config->maxWidth == 0u || config->maxWidth > 1000000u ||
config->maxHeight == 0u || config->maxHeight > 1000000u ||
(config->maxBitDepth != 8u && config->maxBitDepth != 16u) ||
static_cast<s32>(config->addMemSize) < 0 ||
config->exParamNum != 0u)
{
return false;
}
return true;
}
u32 get_mem_size(vm::cptr<CellPngEncConfig> config)
{
return config->addMemSize
+ (config->enableSpu ? 0x78200 : 0x47a00)
+ (config->maxBitDepth >> 1) * config->maxWidth * 7;
}
error_code cellPngEncQueryAttr(vm::cptr<CellPngEncConfig> config, vm::ptr<CellPngEncAttr> attr)
{
cellPngEnc.todo("cellPngEncQueryAttr(config=*0x%x, attr=*0x%x)", config, attr);
if (!attr || !check_config(config))
{
return CELL_PNGENC_ERROR_ARG;
}
const u32 memsize = get_mem_size(config);
attr->memSize = memsize + 0x1780;
attr->cmdQueueDepth = 4;
attr->versionLower = 0;
attr->versionUpper = 0x270000;
return CELL_OK;
}
error_code cellPngEncOpen(vm::cptr<CellPngEncConfig> config, vm::cptr<CellPngEncResource> resource, vm::ptr<u32> handle)
{
cellPngEnc.todo("cellPngEncOpen(config=*0x%x, resource=*0x%x, handle=0x%x)", config, resource, handle);
if (!handle || !check_config(config) ||
!resource || !resource->memAddr || !resource->memSize ||
resource->ppuThreadPriority < 0 || resource->ppuThreadPriority > 0xbff ||
resource->spuThreadPriority < 0 || resource->ppuThreadPriority > 0xff)
{
return CELL_PNGENC_ERROR_ARG;
}
const u32 required_memsize = get_mem_size(config);
if (resource->memSize < required_memsize + 0x1780U)
{
return CELL_PNGENC_ERROR_ARG;
}
auto& encoder = g_fxo->get<png_encoder>();
{
std::lock_guard lock(encoder.mutex);
encoder.config = *config;
encoder.resource = *resource;
}
return CELL_OK;
}
error_code cellPngEncOpenEx(vm::cptr<CellPngEncConfig> config, vm::cptr<CellPngEncResourceEx> resource, vm::ptr<u32> handle)
{
cellPngEnc.todo("cellPngEncOpenEx(config=*0x%x, resourceEx=*0x%x, handle=0x%x)", config, resource, handle);
if (!handle || !check_config(config) ||
!resource || !resource->memAddr || !resource->memSize ||
resource->ppuThreadPriority < 0 || resource->ppuThreadPriority > 0xbff ||
resource->priority[0] > 15 || resource->priority[1] > 15 ||
resource->priority[2] > 15 || resource->priority[3] > 15 ||
resource->priority[4] > 15 || resource->priority[5] > 15 ||
resource->priority[6] > 15 || resource->priority[7] > 15)
{
return CELL_PNGENC_ERROR_ARG;
}
const u32 required_memsize = get_mem_size(config);
if (resource->memSize < required_memsize + 0x1780U)
{
return CELL_PNGENC_ERROR_ARG;
}
auto& encoder = g_fxo->get<png_encoder>();
{
std::lock_guard lock(encoder.mutex);
encoder.config = *config;
encoder.resourceEx = *resource;
}
return CELL_OK;
}
error_code cellPngEncClose(u32 handle)
{
cellPngEnc.todo("cellPngEncClose(handle=0x%x)", handle);
if (!handle)
{
return CELL_PNGENC_ERROR_ARG;
}
return CELL_OK;
}
error_code cellPngEncWaitForInput(u32 handle, b8 block)
{
cellPngEnc.todo("cellPngEncWaitForInput(handle=0x%x, block=%d)", handle, block);
if (!handle)
{
return CELL_PNGENC_ERROR_ARG;
}
return CELL_OK;
}
error_code cellPngEncEncodePicture(u32 handle, vm::cptr<CellPngEncPicture> picture, vm::cptr<CellPngEncEncodeParam> encodeParam, vm::cptr<CellPngEncOutputParam> outputParam)
{
cellPngEnc.todo("cellPngEncEncodePicture(handle=0x%x, picture=*0x%x, encodeParam=*0x%x, outputParam=*0x%x)", handle, picture, encodeParam, outputParam);
if (!handle || !picture || !picture->width || !picture->height ||
(picture->packedPixel && picture->bitDepth >= 8) ||
!picture->pictureAddr || picture->colorSpace > CELL_PNGENC_COLOR_SPACE_ARGB)
{
return CELL_PNGENC_ERROR_ARG;
}
auto& encoder = g_fxo->get<png_encoder>();
{
std::lock_guard lock(encoder.mutex);
if (picture->width > encoder.config.maxWidth ||
picture->height > encoder.config.maxHeight ||
picture->bitDepth > encoder.config.maxBitDepth)
{
return CELL_PNGENC_ERROR_ARG;
}
}
return CELL_OK;
}
error_code cellPngEncWaitForOutput(u32 handle, vm::ptr<u32> streamInfoNum, b8 block)
{
cellPngEnc.todo("cellPngEncWaitForOutput(handle=0x%x, streamInfoNum=*0x%x, block=%d)", handle, streamInfoNum, block);
if (!handle || !streamInfoNum)
{
return CELL_PNGENC_ERROR_ARG;
}
return CELL_OK;
}
error_code cellPngEncGetStreamInfo(u32 handle, vm::ptr<CellPngEncStreamInfo> streamInfo)
{
cellPngEnc.todo("cellPngEncGetStreamInfo(handle=0x%x, streamInfo=*0x%x)", handle, streamInfo);
if (!handle || !streamInfo)
{
return CELL_PNGENC_ERROR_ARG;
}
return CELL_OK;
}
error_code cellPngEncReset(u32 handle)
{
cellPngEnc.todo("cellPngEncReset(handle=0x%x)", handle);
if (!handle)
{
return CELL_PNGENC_ERROR_ARG;
}
return CELL_OK;
}
DECLARE(ppu_module_manager::cellPngEnc)("cellPngEnc", []()
{
REG_FUNC(cellPngEnc, cellPngEncQueryAttr);
REG_FUNC(cellPngEnc, cellPngEncOpen);
REG_FUNC(cellPngEnc, cellPngEncOpenEx);
REG_FUNC(cellPngEnc, cellPngEncClose);
REG_FUNC(cellPngEnc, cellPngEncWaitForInput);
REG_FUNC(cellPngEnc, cellPngEncEncodePicture);
REG_FUNC(cellPngEnc, cellPngEncWaitForOutput);
REG_FUNC(cellPngEnc, cellPngEncGetStreamInfo);
REG_FUNC(cellPngEnc, cellPngEncReset);
});
| 6,183
|
C++
|
.cpp
| 194
| 29.582474
| 173
| 0.738896
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
5,283
|
cellKey2char.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellKey2char.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
#include "cellKb.h"
LOG_CHANNEL(cellKey2char);
// Return Codes
enum CellKey2CharError : u32
{
CELL_K2C_ERROR_FATAL = 0x80121301,
CELL_K2C_ERROR_INVALID_HANDLE = 0x80121302,
CELL_K2C_ERROR_INVALID_PARAMETER = 0x80121303,
CELL_K2C_ERROR_ALREADY_INITIALIZED = 0x80121304,
CELL_K2C_ERROR_UNINITIALIZED = 0x80121305,
CELL_K2C_ERROR_OTHER = 0x80121306,
};
// Modes
enum
{
CELL_KEY2CHAR_MODE_ENGLISH = 0,
CELL_KEY2CHAR_MODE_NATIVE = 1,
CELL_KEY2CHAR_MODE_NATIVE2 = 2
};
// Constants
enum
{
SCE_KEY2CHAR_HANDLE_SIZE = 128
};
struct CellKey2CharKeyData
{
be_t<u32> led;
be_t<u32> mkey;
be_t<u16> keycode;
};
struct CellKey2CharHandle
{
u8 data[SCE_KEY2CHAR_HANDLE_SIZE];
};
template<>
void fmt_class_string<CellKey2CharError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_K2C_ERROR_FATAL);
STR_CASE(CELL_K2C_ERROR_INVALID_HANDLE);
STR_CASE(CELL_K2C_ERROR_INVALID_PARAMETER);
STR_CASE(CELL_K2C_ERROR_ALREADY_INITIALIZED);
STR_CASE(CELL_K2C_ERROR_UNINITIALIZED);
STR_CASE(CELL_K2C_ERROR_OTHER);
}
return unknown;
});
}
error_code cellKey2CharOpen(vm::ptr<CellKey2CharHandle> handle)
{
cellKey2char.todo("cellKey2CharOpen(handle=*0x%x)", handle);
if (!handle)
return CELL_K2C_ERROR_INVALID_HANDLE;
if (handle->data[8] != 0)
return CELL_K2C_ERROR_ALREADY_INITIALIZED;
// TODO
return CELL_OK;
}
error_code cellKey2CharClose(vm::ptr<CellKey2CharHandle> handle)
{
cellKey2char.todo("cellKey2CharClose(handle=*0x%x)", handle);
if (!handle)
return CELL_K2C_ERROR_INVALID_HANDLE;
if (handle->data[8] == 0)
return CELL_K2C_ERROR_UNINITIALIZED;
// TODO
return CELL_OK;
}
error_code cellKey2CharGetChar(vm::ptr<CellKey2CharHandle> handle, vm::ptr<CellKey2CharKeyData> kdata, vm::pptr<u16> charCode, vm::ptr<u32> charNum, vm::ptr<b8> processed)
{
cellKey2char.todo("cellKey2CharGetChar(handle=*0x%x, kdata=*0x%x, charCode=**0x%x, charNum=*0x%x, processed=*0x%x)", handle, kdata, charCode, charNum, processed);
if (!handle)
return CELL_K2C_ERROR_INVALID_HANDLE;
if (handle->data[8] == 0)
return CELL_K2C_ERROR_UNINITIALIZED;
if (!charCode || !kdata || !kdata->keycode)
return CELL_K2C_ERROR_INVALID_PARAMETER;
if (handle->data[0] == 255)
{
if (false /* some check for CELL_OK */)
return CELL_K2C_ERROR_OTHER;
}
return CELL_OK;
}
error_code cellKey2CharSetMode(vm::ptr<CellKey2CharHandle> handle, s32 mode)
{
cellKey2char.todo("cellKey2CharSetMode(handle=*0x%x, mode=0x%x)", handle, mode);
if (!handle)
return CELL_K2C_ERROR_INVALID_HANDLE;
if (handle->data[8] == 0)
return CELL_K2C_ERROR_UNINITIALIZED;
if (mode > CELL_KEY2CHAR_MODE_NATIVE2)
return CELL_K2C_ERROR_INVALID_PARAMETER;
if (handle->data[0] == 255)
return CELL_K2C_ERROR_OTHER;
const s32 mapping = handle->data[1];
switch (mode)
{
case CELL_KEY2CHAR_MODE_ENGLISH:
// TODO: set mode to alphanumeric
break;
case CELL_KEY2CHAR_MODE_NATIVE:
switch (mapping)
{
case CELL_KB_MAPPING_106: // Japanese
// TODO: set mode to kana
break;
case CELL_KB_MAPPING_RUSSIAN_RUSSIA:
// TODO: set mode to Cyrillic
break;
case CELL_KB_MAPPING_KOREAN_KOREA:
// TODO: set mode to Hangul
break;
case CELL_KB_MAPPING_CHINESE_TRADITIONAL:
// TODO: set mode to Bopofomo
break;
default:
break;
}
break;
case CELL_KEY2CHAR_MODE_NATIVE2:
if (mapping == CELL_KB_MAPPING_CHINESE_TRADITIONAL)
{
// TODO: set mode to Cangjie
}
break;
default:
break; // Unreachable
}
return CELL_OK;
}
error_code cellKey2CharSetArrangement(vm::ptr<CellKey2CharHandle> handle, s32 arrange)
{
cellKey2char.todo("cellKey2CharSetArrangement(handle=*0x%x, arrange=0x%x)", handle, arrange);
if (!handle)
return CELL_K2C_ERROR_INVALID_HANDLE;
if (handle->data[8] == 0)
return CELL_K2C_ERROR_UNINITIALIZED;
if (arrange < CELL_KB_MAPPING_101 || arrange > CELL_KB_MAPPING_TURKISH_TURKEY)
return CELL_K2C_ERROR_INVALID_PARAMETER;
return CELL_OK;
}
DECLARE(ppu_module_manager::cellKey2char)("cellKey2char", []()
{
REG_FUNC(cellKey2char, cellKey2CharOpen);
REG_FUNC(cellKey2char, cellKey2CharClose);
REG_FUNC(cellKey2char, cellKey2CharGetChar);
REG_FUNC(cellKey2char, cellKey2CharSetMode);
REG_FUNC(cellKey2char, cellKey2CharSetArrangement);
});
| 4,393
|
C++
|
.cpp
| 155
| 25.935484
| 171
| 0.738333
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| true
| false
| false
| true
| false
| false
|
5,284
|
sys_prx_.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/sys_prx_.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
#include "Emu/Cell/lv2/sys_lwmutex.h"
#include "Emu/Cell/lv2/sys_prx.h"
#include "sysPrxForUser.h"
LOG_CHANNEL(sysPrxForUser);
extern vm::gvar<sys_lwmutex_t> g_ppu_prx_lwm;
// Convert the array of 32-bit pointers to 64-bit pointers using stack allocation
static auto convert_path_list(vm::cpptr<char> path_list, s32 count)
{
return vm::var<vm::cptr<char, u64>[]>(count, path_list.get_ptr());
}
// Execute start or stop module function
static void entryx(ppu_thread& ppu, vm::ptr<sys_prx_start_stop_module_option_t> opt, u32 args, vm::ptr<void> argp, vm::ptr<s32> res)
{
if (opt->entry2.addr() != umax)
{
*res = opt->entry2(ppu, opt->entry, args, argp);
return;
}
if (opt->entry.addr() != umax)
{
*res = opt->entry(ppu, args, argp);
return;
}
*res = 0;
}
error_code sys_prx_load_module(ppu_thread& ppu, vm::cptr<char> path, u64 flags, vm::ptr<sys_prx_load_module_option_t> pOpt)
{
sysPrxForUser.warning("sys_prx_load_module(path=%s, flags=0x%x, pOpt=*0x%x)", path, flags, pOpt);
sys_lwmutex_locker lock(ppu, g_ppu_prx_lwm);
return _sys_prx_load_module(ppu, path, flags, pOpt);
}
error_code sys_prx_load_module_by_fd(ppu_thread& ppu, s32 fd, u64 offset, u64 flags, vm::ptr<sys_prx_load_module_option_t> pOpt)
{
sysPrxForUser.warning("sys_prx_load_module_by_fd(fd=%d, offset=0x%x, flags=0x%x, pOpt=*0x%x)", fd, offset, flags, pOpt);
sys_lwmutex_locker lock(ppu, g_ppu_prx_lwm);
return _sys_prx_load_module_by_fd(ppu, fd, offset, flags, pOpt);
}
error_code sys_prx_load_module_on_memcontainer(ppu_thread& ppu, vm::cptr<char> path, u32 mem_ct, u64 flags, vm::ptr<sys_prx_load_module_option_t> pOpt)
{
sysPrxForUser.warning("sys_prx_load_module_on_memcontainer(path=%s, mem_ct=0x%x, flags=0x%x, pOpt=*0x%x)", path, mem_ct, flags, pOpt);
sys_lwmutex_locker lock(ppu, g_ppu_prx_lwm);
return _sys_prx_load_module_on_memcontainer(ppu, path, mem_ct, flags, pOpt);
}
error_code sys_prx_load_module_on_memcontainer_by_fd(ppu_thread& ppu, s32 fd, u64 offset, u32 mem_ct, u64 flags, vm::ptr<sys_prx_load_module_option_t> pOpt)
{
sysPrxForUser.warning("sys_prx_load_module_on_memcontainer_by_fd(fd=%d, offset=0x%x, mem_ct=0x%x, flags=0x%x, pOpt=*0x%x)", fd, offset, mem_ct, flags, pOpt);
sys_lwmutex_locker lock(ppu, g_ppu_prx_lwm);
return _sys_prx_load_module_on_memcontainer_by_fd(ppu, fd, offset, mem_ct, flags, pOpt);
}
error_code sys_prx_load_module_list(ppu_thread& ppu, s32 count, vm::cpptr<char> path_list, u64 flags, vm::ptr<sys_prx_load_module_option_t> pOpt, vm::ptr<u32> id_list)
{
sysPrxForUser.todo("sys_prx_load_module_list(count=%d, path_list=**0x%x, flags=0x%x, pOpt=*0x%x, id_list=*0x%x)", count, path_list, flags, pOpt, id_list);
sys_lwmutex_locker lock(ppu, g_ppu_prx_lwm);
return _sys_prx_load_module_list(ppu, count, convert_path_list(path_list, count), flags, pOpt, id_list);
}
error_code sys_prx_load_module_list_on_memcontainer(ppu_thread& ppu, s32 count, vm::cpptr<char> path_list, u32 mem_ct, u64 flags, vm::ptr<sys_prx_load_module_option_t> pOpt, vm::ptr<u32> id_list)
{
sysPrxForUser.todo("sys_prx_load_module_list_on_memcontainer(count=%d, path_list=**0x%x, mem_ct=0x%x, flags=0x%x, pOpt=*0x%x, id_list=*0x%x)", count, path_list, mem_ct, flags, pOpt, id_list);
sys_lwmutex_locker lock(ppu, g_ppu_prx_lwm);
return _sys_prx_load_module_list_on_memcontainer(ppu, count, convert_path_list(path_list, count), mem_ct, flags, pOpt, id_list);
}
error_code sys_prx_start_module(ppu_thread& ppu, u32 id, u32 args, vm::ptr<void> argp, vm::ptr<s32> result, u64 flags, vm::ptr<void> pOpt)
{
sysPrxForUser.warning("sys_prx_start_module(id=0x%x, args=%u, argp=*0x%x, result=*0x%x, flags=0x%x, pOpt=*0x%x)", id, args, argp, result, flags, pOpt);
if (!result)
{
return CELL_EINVAL;
}
sys_lwmutex_locker lock(ppu, g_ppu_prx_lwm);
vm::var<sys_prx_start_stop_module_option_t> opt;
opt->size = opt.size();
opt->cmd = 1;
opt->entry2.set(-1);
const error_code res = _sys_prx_start_module(ppu, id, flags, opt);
if (res < 0)
{
return res;
}
entryx(ppu, opt, args, argp, result);
opt->cmd = 2;
opt->res = *result;
_sys_prx_start_module(ppu, id, flags, opt);
return CELL_OK;
}
error_code sys_prx_stop_module(ppu_thread& ppu, u32 id, u32 args, vm::ptr<void> argp, vm::ptr<s32> result, u64 flags, vm::ptr<void> pOpt)
{
sysPrxForUser.warning("sys_prx_stop_module(id=0x%x, args=%u, argp=*0x%x, result=*0x%x, flags=0x%x, pOpt=*0x%x)", id, args, argp, result, flags, pOpt);
if (!result)
{
return CELL_EINVAL;
}
sys_lwmutex_locker lock(ppu, g_ppu_prx_lwm);
vm::var<sys_prx_start_stop_module_option_t> opt;
opt->size = opt.size();
opt->cmd = 1;
opt->entry2.set(-1);
const error_code res = _sys_prx_stop_module(ppu, id, flags, opt);
if (res < 0)
{
return res;
}
entryx(ppu, opt, args, argp, result);
opt->cmd = 2;
opt->res = *result;
_sys_prx_stop_module(ppu, id, flags, opt);
return CELL_OK;
}
error_code sys_prx_unload_module(ppu_thread& ppu, u32 id, u64 flags, vm::ptr<sys_prx_unload_module_option_t> pOpt)
{
sysPrxForUser.warning("sys_prx_unload_module(id=0x%x, flags=0x%x, pOpt=*0x%x)", id, flags, pOpt);
sys_lwmutex_locker lock(ppu, g_ppu_prx_lwm);
return _sys_prx_unload_module(ppu, id, flags, pOpt);
}
error_code sys_prx_register_library(ppu_thread& ppu, vm::ptr<void> lib_entry)
{
sysPrxForUser.warning("sys_prx_register_library(lib_entry=*0x%x)", lib_entry);
sys_lwmutex_locker lock(ppu, g_ppu_prx_lwm);
return _sys_prx_register_library(ppu, lib_entry);
}
error_code sys_prx_unregister_library(ppu_thread& ppu, vm::ptr<void> lib_entry)
{
sysPrxForUser.warning("sys_prx_unregister_library(lib_entry=*0x%x)", lib_entry);
sys_lwmutex_locker lock(ppu, g_ppu_prx_lwm);
return _sys_prx_unregister_library(ppu, lib_entry);
}
error_code sys_prx_get_module_list(ppu_thread& ppu, u64 flags, vm::ptr<sys_prx_get_module_list_t> info)
{
sysPrxForUser.trace("sys_prx_get_module_list(flags=0x%x, info=*0x%x)", flags, info);
if (!info || !info->idlist)
{
return CELL_EINVAL;
}
// Initialize params
vm::var<sys_prx_get_module_list_option_t> opt;
opt->size = opt.size();
opt->max = info->max;
opt->count = 0;
opt->idlist = info->idlist;
opt->unk = 0;
// Call the syscall
const s32 res = _sys_prx_get_module_list(ppu, 2, opt);
info->max = opt->max;
info->count = opt->count;
return not_an_error(res);
}
error_code sys_prx_get_module_info(ppu_thread& ppu, u32 id, u64 flags, vm::ptr<sys_prx_module_info_t> info)
{
sysPrxForUser.trace("sys_prx_get_module_info(id=0x%x, flags=0x%x, info=*0x%x)", id, flags, info);
if (!info)
{
return CELL_EINVAL;
}
// Initialize params
vm::var<sys_prx_module_info_option_t> opt;
opt->size = opt.size();
opt->info = info;
// Call the syscall
return _sys_prx_get_module_info(ppu, id, 0, opt);
}
error_code sys_prx_get_module_id_by_name(ppu_thread& ppu, vm::cptr<char> name, u64 flags, vm::ptr<sys_prx_get_module_id_by_name_option_t> pOpt)
{
sysPrxForUser.trace("sys_prx_get_module_id_by_name(name=%s, flags=0x%x, pOpt=*0x%x)", name, flags, pOpt);
if (flags || pOpt)
{
return CELL_EINVAL;
}
// Call the syscall
return _sys_prx_get_module_id_by_name(ppu, name, u64{0}, vm::null);
}
error_code sys_prx_get_module_id_by_address(ppu_thread& ppu, u32 addr)
{
sysPrxForUser.trace("sys_prx_get_module_id_by_address()");
// Call the syscall
return _sys_prx_get_module_id_by_address(ppu, addr);
}
error_code sys_prx_exitspawn_with_level()
{
sysPrxForUser.todo("sys_prx_exitspawn_with_level()");
return CELL_OK;
}
error_code sys_prx_get_my_module_id(ppu_thread& ppu_do_not_call, ppu_thread&, ppu_thread&, ppu_thread&) // Do not call directly
{
sysPrxForUser.trace("sys_prx_get_my_module_id()");
// Call the syscall using the LR
return _sys_prx_get_module_id_by_address(ppu_do_not_call, static_cast<u32>(ppu_do_not_call.lr));
}
void sysPrxForUser_sys_prx_init()
{
REG_FUNC(sysPrxForUser, sys_prx_load_module);
REG_FUNC(sysPrxForUser, sys_prx_load_module_by_fd);
REG_FUNC(sysPrxForUser, sys_prx_load_module_on_memcontainer);
REG_FUNC(sysPrxForUser, sys_prx_load_module_on_memcontainer_by_fd);
REG_FUNC(sysPrxForUser, sys_prx_load_module_list);
REG_FUNC(sysPrxForUser, sys_prx_load_module_list_on_memcontainer);
REG_FUNC(sysPrxForUser, sys_prx_start_module);
REG_FUNC(sysPrxForUser, sys_prx_stop_module);
REG_FUNC(sysPrxForUser, sys_prx_unload_module);
REG_FUNC(sysPrxForUser, sys_prx_register_library);
REG_FUNC(sysPrxForUser, sys_prx_unregister_library);
REG_FUNC(sysPrxForUser, sys_prx_get_module_list);
REG_FUNC(sysPrxForUser, sys_prx_get_module_info);
REG_FUNC(sysPrxForUser, sys_prx_get_module_id_by_name);
REG_FUNC(sysPrxForUser, sys_prx_get_module_id_by_address);
REG_FUNC(sysPrxForUser, sys_prx_exitspawn_with_level);
REG_FUNC(sysPrxForUser, sys_prx_get_my_module_id);
}
| 8,852
|
C++
|
.cpp
| 208
| 40.485577
| 195
| 0.714619
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| true
| false
| false
| true
| false
| false
|
5,285
|
sys_ppu_thread_.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/sys_ppu_thread_.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
#include "Emu/IdManager.h"
#include "Emu/Cell/lv2/sys_ppu_thread.h"
#include "Emu/Cell/lv2/sys_interrupt.h"
#include "Emu/Cell/lv2/sys_lwmutex.h"
#include "Emu/Cell/lv2/sys_mutex.h"
#include "sysPrxForUser.h"
LOG_CHANNEL(sysPrxForUser);
vm::gvar<sys_lwmutex_t> g_ppu_atexit_lwm;
vm::gvar<vm::ptr<void()>[8]> g_ppu_atexit;
vm::gvar<u32> g_ppu_exit_mutex; // sys_process_exit2 mutex
vm::gvar<u32> g_ppu_once_mutex;
vm::gvar<sys_lwmutex_t> g_ppu_prx_lwm;
static u32 s_tls_addr = 0; // TLS image address
static u32 s_tls_file = 0; // TLS image size
static u32 s_tls_zero = 0; // TLS zeroed area size (TLS mem size - TLS image size)
static u32 s_tls_size = 0; // Size of TLS area per thread
static u32 s_tls_area = 0; // Start of TLS memory area
static u32 s_tls_max = 0; // Max number of threads
static std::unique_ptr<atomic_t<bool>[]> s_tls_map; // I'd like to make it std::vector but it won't work
static u32 ppu_alloc_tls()
{
u32 addr = 0;
for (u32 i = 0; i < s_tls_max; i++)
{
if (!s_tls_map[i] && s_tls_map[i].exchange(true) == false)
{
// Default (small) TLS allocation
addr = s_tls_area + i * s_tls_size;
break;
}
}
if (!addr)
{
// Alternative (big) TLS allocation
addr = vm::alloc(s_tls_size, vm::main);
}
std::memset(vm::base(addr), 0, 0x30); // Clear system area (TODO)
std::memcpy(vm::base(addr + 0x30), vm::base(s_tls_addr), s_tls_file); // Copy TLS image
std::memset(vm::base(addr + 0x30 + s_tls_file), 0, s_tls_zero); // Clear the rest
return addr;
}
static void ppu_free_tls(u32 addr)
{
// Calculate TLS position
const u32 i = (addr - s_tls_area) / s_tls_size;
if (addr < s_tls_area || i >= s_tls_max || (addr - s_tls_area) % s_tls_size)
{
// Alternative TLS allocation detected
ensure(vm::dealloc(addr, vm::main));
return;
}
if (s_tls_map[i].exchange(false) == false)
{
sysPrxForUser.error("ppu_free_tls(0x%x): deallocation failed", addr);
return;
}
}
void sys_initialize_tls(ppu_thread& ppu, u64 main_thread_id, u32 tls_seg_addr, u32 tls_seg_size, u32 tls_mem_size)
{
sysPrxForUser.notice("sys_initialize_tls(thread_id=0x%llx, addr=*0x%x, size=0x%x, mem_size=0x%x)", main_thread_id, tls_seg_addr, tls_seg_size, tls_mem_size);
// Uninitialized TLS expected.
if (ppu.gpr[13] != 0) return;
// Initialize TLS memory
s_tls_addr = tls_seg_addr;
s_tls_file = tls_seg_size;
s_tls_zero = tls_mem_size - tls_seg_size;
s_tls_size = tls_mem_size + 0x30; // 0x30 is system area size
s_tls_area = vm::alloc(0x40000, vm::main) + 0x30;
s_tls_max = (0x40000 - 0x30) / s_tls_size;
s_tls_map = std::make_unique<atomic_t<bool>[]>(s_tls_max);
// Allocate TLS for main thread
ppu.gpr[13] = ppu_alloc_tls() + 0x7000 + 0x30;
sysPrxForUser.notice("TLS initialized (addr=0x%x, size=0x%x, max=0x%x)", s_tls_area - 0x30, s_tls_size, s_tls_max);
// TODO
g_spu_printf_agcb = vm::null;
g_spu_printf_dgcb = vm::null;
g_spu_printf_atcb = vm::null;
g_spu_printf_dtcb = vm::null;
vm::var<sys_lwmutex_attribute_t> lwa;
lwa->protocol = SYS_SYNC_PRIORITY;
lwa->recursive = SYS_SYNC_RECURSIVE;
lwa->name_u64 = "atexit!\0"_u64;
sys_lwmutex_create(ppu, g_ppu_atexit_lwm, lwa);
vm::var<sys_mutex_attribute_t> attr;
attr->protocol = SYS_SYNC_PRIORITY;
attr->recursive = SYS_SYNC_NOT_RECURSIVE;
attr->pshared = SYS_SYNC_NOT_PROCESS_SHARED;
attr->adaptive = SYS_SYNC_NOT_ADAPTIVE;
attr->ipc_key = 0;
attr->flags = 0;
attr->name_u64 = "_lv2ppu\0"_u64;
sys_mutex_create(ppu, g_ppu_once_mutex, attr);
attr->recursive = SYS_SYNC_RECURSIVE;
attr->name_u64 = "_lv2tls\0"_u64;
sys_mutex_create(ppu, g_ppu_exit_mutex, attr);
lwa->protocol = SYS_SYNC_PRIORITY;
lwa->recursive = SYS_SYNC_RECURSIVE;
lwa->name_u64 = "_lv2prx\0"_u64;
sys_lwmutex_create(ppu, g_ppu_prx_lwm, lwa);
// TODO: missing prx initialization
}
error_code sys_ppu_thread_create(ppu_thread& ppu, vm::ptr<u64> thread_id, u32 entry, u64 arg, s32 prio, u32 stacksize, u64 flags, vm::cptr<char> threadname)
{
ppu.state += cpu_flag::wait;
sysPrxForUser.warning("sys_ppu_thread_create(thread_id=*0x%x, entry=0x%x, arg=0x%llx, prio=%d, stacksize=0x%x, flags=0x%llx, threadname=%s)",
thread_id, entry, arg, prio, stacksize, flags, threadname);
// Allocate TLS
const u32 tls_addr = ppu_alloc_tls();
if (!tls_addr)
{
return CELL_ENOMEM;
}
// Call the syscall
if (error_code res = _sys_ppu_thread_create(ppu, thread_id, vm::make_var(ppu_thread_param_t{ vm::cast(entry), tls_addr + 0x7030 }), arg, 0, prio, stacksize, flags, threadname))
{
return res;
}
if (flags & SYS_PPU_THREAD_CREATE_INTERRUPT)
{
return CELL_OK;
}
// Run the thread
if (error_code res = sys_ppu_thread_start(ppu, static_cast<u32>(*thread_id)))
{
return res;
}
return CELL_OK;
}
error_code sys_ppu_thread_get_id(ppu_thread& ppu, vm::ptr<u64> thread_id)
{
sysPrxForUser.trace("sys_ppu_thread_get_id(thread_id=*0x%x)", thread_id);
*thread_id = ppu.id;
return CELL_OK;
}
void sys_ppu_thread_exit(ppu_thread& ppu, u64 val)
{
sysPrxForUser.trace("sys_ppu_thread_exit(val=0x%llx)", val);
// Call registered atexit functions
ensure(!sys_lwmutex_lock(ppu, g_ppu_atexit_lwm, 0));
for (auto ptr : *g_ppu_atexit)
{
if (ptr)
{
ptr(ppu);
}
}
ensure(!sys_lwmutex_unlock(ppu, g_ppu_atexit_lwm));
// Deallocate TLS
ppu_free_tls(vm::cast(ppu.gpr[13]) - 0x7030);
// Call the syscall
_sys_ppu_thread_exit(ppu, val);
}
error_code sys_ppu_thread_register_atexit(ppu_thread& ppu, vm::ptr<void()> func)
{
sysPrxForUser.notice("sys_ppu_thread_register_atexit(ptr=*0x%x)", func);
sys_lwmutex_locker lock(ppu, g_ppu_atexit_lwm);
for (auto ptr : *g_ppu_atexit)
{
if (ptr == func)
{
return CELL_EPERM;
}
}
for (auto& pf : *g_ppu_atexit)
{
if (!pf)
{
pf = func;
return CELL_OK;
}
}
return CELL_ENOMEM;
}
error_code sys_ppu_thread_unregister_atexit(ppu_thread& ppu, vm::ptr<void()> func)
{
sysPrxForUser.notice("sys_ppu_thread_unregister_atexit(ptr=*0x%x)", func);
sys_lwmutex_locker lock(ppu, g_ppu_atexit_lwm);
for (auto& pp : *g_ppu_atexit)
{
if (pp == func)
{
pp = vm::null;
return CELL_OK;
}
}
return CELL_ESRCH;
}
void sys_ppu_thread_once(ppu_thread& ppu, vm::ptr<s32> once_ctrl, vm::ptr<void()> init)
{
sysPrxForUser.notice("sys_ppu_thread_once(once_ctrl=*0x%x, init=*0x%x)", once_ctrl, init);
ensure(sys_mutex_lock(ppu, *g_ppu_once_mutex, 0) == CELL_OK);
if (*once_ctrl == SYS_PPU_THREAD_ONCE_INIT)
{
// Call init function using current thread context
init(ppu);
*once_ctrl = SYS_PPU_THREAD_DONE_INIT;
}
ensure(sys_mutex_unlock(ppu, *g_ppu_once_mutex) == CELL_OK);
}
error_code sys_interrupt_thread_disestablish(ppu_thread& ppu, u32 ih)
{
sysPrxForUser.trace("sys_interrupt_thread_disestablish(ih=0x%x)", ih);
// Recovered TLS pointer
vm::var<u64> r13;
// Call the syscall
if (error_code res = _sys_interrupt_thread_disestablish(ppu, ih, r13))
{
return res;
}
// Deallocate TLS
ppu_free_tls(vm::cast(*r13) - 0x7030);
return CELL_OK;
}
void sysPrxForUser_sys_ppu_thread_init()
{
// Private
REG_VAR(sysPrxForUser, g_ppu_atexit_lwm).flag(MFF_HIDDEN);
REG_VAR(sysPrxForUser, g_ppu_once_mutex).flag(MFF_HIDDEN);
REG_VAR(sysPrxForUser, g_ppu_atexit).flag(MFF_HIDDEN);
REG_VAR(sysPrxForUser, g_ppu_prx_lwm).flag(MFF_HIDDEN);
REG_VAR(sysPrxForUser, g_ppu_exit_mutex).flag(MFF_HIDDEN);
REG_FUNC(sysPrxForUser, sys_initialize_tls).args = {"main_thread_id", "tls_seg_addr", "tls_seg_size", "tls_mem_size"}; // Test
REG_FUNC(sysPrxForUser, sys_ppu_thread_create);
REG_FUNC(sysPrxForUser, sys_ppu_thread_get_id);
REG_FUNC(sysPrxForUser, sys_ppu_thread_exit);
REG_FUNC(sysPrxForUser, sys_ppu_thread_once);
REG_FUNC(sysPrxForUser, sys_ppu_thread_register_atexit);
REG_FUNC(sysPrxForUser, sys_ppu_thread_unregister_atexit);
REG_FUNC(sysPrxForUser, sys_interrupt_thread_disestablish);
}
| 7,894
|
C++
|
.cpp
| 232
| 31.801724
| 177
| 0.695201
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| true
| false
| false
| true
| false
| false
|
5,286
|
cellPrint.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellPrint.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
#include "cellSysutil.h"
LOG_CHANNEL(cellPrint);
// Error Codes
enum
{
CELL_PRINT_ERROR_INTERNAL = 0x8002c401,
CELL_PRINT_ERROR_NO_MEMORY = 0x8002c402,
CELL_PRINT_ERROR_PRINTER_NOT_FOUND = 0x8002c403,
CELL_PRINT_ERROR_INVALID_PARAM = 0x8002c404,
CELL_PRINT_ERROR_INVALID_FUNCTION = 0x8002c405,
CELL_PRINT_ERROR_NOT_SUPPORT = 0x8002c406,
CELL_PRINT_ERROR_OCCURRED = 0x8002c407,
CELL_PRINT_ERROR_CANCELED_BY_PRINTER = 0x8002c408,
};
struct CellPrintLoadParam
{
be_t<u32> mode;
u8 reserved[32];
};
struct CellPrintStatus
{
be_t<s32> status;
be_t<s32> errorStatus;
be_t<s32> continueEnabled;
u8 reserved[32];
};
using CellPrintCallback = void(s32 result, vm::ptr<void> userdata);
error_code cellSysutilPrintInit()
{
UNIMPLEMENTED_FUNC(cellPrint);
return CELL_OK;
}
error_code cellSysutilPrintShutdown()
{
UNIMPLEMENTED_FUNC(cellPrint);
return CELL_OK;
}
error_code cellPrintLoadAsync(vm::ptr<CellPrintCallback> function, vm::ptr<void> userdata, vm::cptr<CellPrintLoadParam> param, u32 container)
{
cellPrint.todo("cellPrintLoadAsync(function=*0x%x, userdata=*0x%x, param=*0x%x, container=0x%x)", function, userdata, param, container);
sysutil_register_cb([=](ppu_thread& ppu) -> s32
{
function(ppu, CELL_OK, userdata);
return CELL_OK;
});
return CELL_OK;
}
error_code cellPrintLoadAsync2(vm::ptr<CellPrintCallback> function, vm::ptr<void> userdata, vm::cptr<CellPrintLoadParam> param)
{
cellPrint.todo("cellPrintLoadAsync2(function=*0x%x, userdata=*0x%x, param=*0x%x)", function, userdata, param);
sysutil_register_cb([=](ppu_thread& ppu) -> s32
{
function(ppu, CELL_OK, userdata);
return CELL_OK;
});
return CELL_OK;
}
error_code cellPrintUnloadAsync(vm::ptr<CellPrintCallback> function, vm::ptr<void> userdata)
{
cellPrint.todo("cellPrintUnloadAsync(function=*0x%x, userdata=*0x%x)", function, userdata);
sysutil_register_cb([=](ppu_thread& ppu) -> s32
{
function(ppu, CELL_OK, userdata);
return CELL_OK;
});
return CELL_OK;
}
error_code cellPrintGetStatus(vm::ptr<CellPrintStatus> status)
{
cellPrint.todo("cellPrintGetStatus(status=*0x%x)", status);
return CELL_OK;
}
error_code cellPrintOpenConfig(vm::ptr<CellPrintCallback> function, vm::ptr<void> userdata)
{
cellPrint.todo("cellPrintOpenConfig(function=*0x%x, userdata=*0x%x)", function, userdata);
sysutil_register_cb([=](ppu_thread& ppu) -> s32
{
function(ppu, CELL_OK, userdata);
return CELL_OK;
});
return CELL_OK;
}
error_code cellPrintGetPrintableArea(vm::ptr<s32> pixelWidth, vm::ptr<s32> pixelHeight)
{
cellPrint.todo("cellPrintGetPrintableArea(pixelWidth=*0x%x, pixelHeight=*0x%x)", pixelWidth, pixelHeight);
return CELL_OK;
}
error_code cellPrintStartJob(s32 totalPage, s32 colorFormat)
{
cellPrint.todo("cellPrintStartJob(totalPage=0x%x, colorFormat=0x%x)", totalPage, colorFormat);
return CELL_OK;
}
error_code cellPrintEndJob()
{
cellPrint.todo("cellPrintEndJob()");
return CELL_OK;
}
error_code cellPrintCancelJob()
{
cellPrint.todo("cellPrintCancelJob()");
return CELL_OK;
}
error_code cellPrintStartPage()
{
cellPrint.todo("cellPrintStartPage()");
return CELL_OK;
}
error_code cellPrintEndPage()
{
cellPrint.todo("cellPrintEndPage()");
return CELL_OK;
}
error_code cellPrintSendBand(vm::cptr<u8> buff, s32 buffsize, vm::ptr<s32> sendsize)
{
cellPrint.todo("cellPrintSendBand(buff=*0x%x, buffsize=0x%x, sendsize=*0x%x)", buff, buffsize, sendsize);
return CELL_OK;
}
DECLARE(ppu_module_manager::cellPrint)("cellPrintUtility", []()
{
REG_FUNC(cellPrintUtility, cellSysutilPrintInit);
REG_FUNC(cellPrintUtility, cellSysutilPrintShutdown);
REG_FUNC(cellPrintUtility, cellPrintLoadAsync);
REG_FUNC(cellPrintUtility, cellPrintLoadAsync2);
REG_FUNC(cellPrintUtility, cellPrintUnloadAsync);
REG_FUNC(cellPrintUtility, cellPrintGetStatus);
REG_FUNC(cellPrintUtility, cellPrintOpenConfig);
REG_FUNC(cellPrintUtility, cellPrintGetPrintableArea);
REG_FUNC(cellPrintUtility, cellPrintStartJob);
REG_FUNC(cellPrintUtility, cellPrintEndJob);
REG_FUNC(cellPrintUtility, cellPrintCancelJob);
REG_FUNC(cellPrintUtility, cellPrintStartPage);
REG_FUNC(cellPrintUtility, cellPrintEndPage);
REG_FUNC(cellPrintUtility, cellPrintSendBand);
});
| 4,305
|
C++
|
.cpp
| 136
| 29.823529
| 141
| 0.771739
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| true
| false
| false
| true
| false
| false
|
5,287
|
sceNpMatchingInt.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/sceNpMatchingInt.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
#include "sceNp.h"
LOG_CHANNEL(sceNpMatchingInt);
error_code sceNpMatchingCancelRequest()
{
UNIMPLEMENTED_FUNC(sceNpMatchingInt);
return CELL_OK;
}
error_code sceNpMatchingGetRoomMemberList(u32 ctx_id, vm::ptr<SceNpRoomId> room_id, vm::ptr<u32> buflen, vm::ptr<void> buf)
{
sceNpMatchingInt.warning("sceNpMatchingGetRoomMemberList(ctx_id=%d, room_id=*0x%x, buflen=*0x%x, buf=*0x%x)", ctx_id, room_id, buflen, buf);
return matching_get_room_member_list(ctx_id, room_id, buflen, buf);
}
error_code sceNpMatchingJoinRoomWithoutGUI(u32 ctx_id, vm::ptr<SceNpRoomId> room_id, vm::ptr<SceNpMatchingGUIHandler> handler, vm::ptr<void> arg)
{
sceNpMatchingInt.warning("sceNpMatchingJoinRoomWithoutGUI(ctx_id=%d, room_id=*0x%x, handler=*0x%x, arg=*0x%x)", ctx_id, room_id, handler, arg);
return matching_join_room(ctx_id, room_id, handler, arg);
}
error_code OLD_sceNpMatchingJoinRoomGUI(u32 ctx_id, vm::ptr<SceNpRoomId> room_id, vm::ptr<SceNpMatchingGUIHandler> handler, vm::ptr<void> arg)
{
sceNpMatchingInt.warning("OLD_sceNpMatchingJoinRoomGUI(ctx_id=%d, room_id=*0x%x, handler=*0x%x, arg=*0x%x)", ctx_id, room_id, handler, arg);
return matching_join_room(ctx_id, room_id, handler, arg);
}
error_code OLD_sceNpMatchingSetRoomInfoNoLimit(u32 ctx_id, vm::ptr<SceNpLobbyId> lobby_id, vm::ptr<SceNpRoomId> room_id, vm::ptr<SceNpMatchingAttr> attr, vm::ptr<u32> req_id)
{
sceNpMatchingInt.warning("OLD_sceNpMatchingSetRoomInfoNoLimit(ctx_id=%d, lobby_id=*0x%x, room_id=*0x%x, attr=*0x%x, req_id=*0x%x)", ctx_id, lobby_id, room_id, attr, req_id);
return matching_set_room_info(ctx_id, lobby_id, room_id, attr, req_id, false);
}
error_code sceNpMatchingGetRoomListWithoutGUI(u32 ctx_id, vm::ptr<SceNpCommunicationId> communicationId, vm::ptr<SceNpMatchingReqRange> range, vm::ptr<SceNpMatchingSearchCondition> cond,
vm::ptr<SceNpMatchingAttr> attr, vm::ptr<SceNpMatchingGUIHandler> handler, vm::ptr<void> arg)
{
sceNpMatchingInt.warning("sceNpMatchingGetRoomListWithoutGUI(ctx_id=%d, communicationId=*0x%x, range=*0x%x, cond=*0x%x, attr=*0x%x, handler=*0x%x, arg=*0x%x)", ctx_id, communicationId, range, cond, attr, handler, arg);
return matching_get_room_list(ctx_id, communicationId, range, cond, attr, handler, arg, false);
}
error_code sceNpMatchingGetRoomListGUI(u32 ctx_id, vm::ptr<SceNpCommunicationId> communicationId, vm::ptr<SceNpMatchingReqRange> range, vm::ptr<SceNpMatchingSearchCondition> cond,
vm::ptr<SceNpMatchingAttr> attr, vm::ptr<SceNpMatchingGUIHandler> handler, vm::ptr<void> arg)
{
sceNpMatchingInt.warning("sceNpMatchingGetRoomListGUI(ctx_id=%d, communicationId=*0x%x, range=*0x%x, cond=*0x%x, attr=*0x%x, handler=*0x%x, arg=*0x%x)", ctx_id, communicationId, range, cond, attr, handler, arg);
return matching_get_room_list(ctx_id, communicationId, range, cond, attr, handler, arg, false);
}
error_code OLD_sceNpMatchingGetRoomInfoNoLimit(u32 ctx_id, vm::ptr<SceNpLobbyId> lobby_id, vm::ptr<SceNpRoomId> room_id, vm::ptr<SceNpMatchingAttr> attr, vm::ptr<u32> req_id)
{
sceNpMatchingInt.warning("OLD_sceNpMatchingGetRoomInfoNoLimit(ctx_id=%d, lobby_id=*0x%x, room_id=*0x%x, attr=*0x%x, req_id=*0x%x)", ctx_id, lobby_id, room_id, attr, req_id);
return matching_get_room_info(ctx_id, lobby_id, room_id, attr, req_id, false);
}
error_code sceNpMatchingCancelRequestGUI()
{
UNIMPLEMENTED_FUNC(sceNpMatchingInt);
return CELL_OK;
}
error_code sceNpMatchingSendRoomMessage()
{
UNIMPLEMENTED_FUNC(sceNpMatchingInt);
return CELL_OK;
}
error_code sceNpMatchingCreateRoomWithoutGUI(u32 ctx_id, vm::cptr<SceNpCommunicationId> communicationId, vm::cptr<SceNpMatchingAttr> attr, vm::ptr<SceNpMatchingGUIHandler> handler, vm::ptr<void> arg)
{
sceNpMatchingInt.warning("sceNpMatchingCreateRoomWithoutGUI(ctx_id=%d, communicationId=*0x%x, attr=*0x%x, handler=*0x%x, arg=*0x%x)", ctx_id, communicationId, attr, handler, arg);
return matching_create_room(ctx_id, communicationId, attr, handler, arg);
}
// This module has some conflicting function names with sceNp module, hence the REG_FNID
DECLARE(ppu_module_manager::sceNpMatchingInt)("sceNpMatchingInt", []()
{
REG_FUNC(sceNpMatchingInt, sceNpMatchingCancelRequest);
REG_FUNC(sceNpMatchingInt, sceNpMatchingGetRoomMemberList);
REG_FUNC(sceNpMatchingInt, sceNpMatchingJoinRoomWithoutGUI);
// REG_FUNC(sceNpMatchingInt, sceNpMatchingJoinRoomGUI);
REG_FNID(sceNpMatchingInt, "sceNpMatchingJoinRoomGUI", OLD_sceNpMatchingJoinRoomGUI);
// REG_FUNC(sceNpMatchingInt, sceNpMatchingSetRoomInfoNoLimit);
REG_FNID(sceNpMatchingInt, "sceNpMatchingSetRoomInfoNoLimit", OLD_sceNpMatchingSetRoomInfoNoLimit);
REG_FUNC(sceNpMatchingInt, sceNpMatchingGetRoomListWithoutGUI);
REG_FUNC(sceNpMatchingInt, sceNpMatchingGetRoomListGUI);
// REG_FUNC(sceNpMatchingInt, sceNpMatchingGetRoomInfoNoLimit);
REG_FNID(sceNpMatchingInt, "sceNpMatchingGetRoomInfoNoLimit", OLD_sceNpMatchingGetRoomInfoNoLimit);
REG_FUNC(sceNpMatchingInt, sceNpMatchingCancelRequestGUI);
REG_FUNC(sceNpMatchingInt, sceNpMatchingSendRoomMessage);
REG_FUNC(sceNpMatchingInt, sceNpMatchingCreateRoomWithoutGUI);
});
| 5,118
|
C++
|
.cpp
| 79
| 63.037975
| 219
| 0.789558
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
5,288
|
cellSpursSpu.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellSpursSpu.cpp
|
#include "stdafx.h"
#include "Loader/ELF.h"
#include "Emu/Memory/vm_reservation.h"
#include "Emu/Cell/SPUThread.h"
#include "Emu/Cell/SPURecompiler.h"
#include "Emu/Cell/lv2/sys_lwmutex.h"
#include "Emu/Cell/lv2/sys_lwcond.h"
#include "Emu/Cell/lv2/sys_spu.h"
#include "cellSpurs.h"
#include "util/asm.hpp"
#include "util/v128.hpp"
#include "util/simd.hpp"
LOG_CHANNEL(cellSpurs);
// Temporarily
#ifndef _MSC_VER
#pragma GCC diagnostic ignored "-Wunused-function"
#pragma GCC diagnostic ignored "-Wunused-parameter"
#endif
//----------------------------------------------------------------------------
// Function prototypes
//----------------------------------------------------------------------------
//
// SPURS utility functions
//
static void cellSpursModulePutTrace(CellSpursTracePacket* packet, u32 dmaTagId);
static u32 cellSpursModulePollStatus(spu_thread& spu, u32* status);
static void cellSpursModuleExit(spu_thread& spu);
static bool spursDma(spu_thread& spu, u32 cmd, u64 ea, u32 lsa, u32 size, u32 tag);
static u32 spursDmaGetCompletionStatus(spu_thread& spu, u32 tagMask);
static u32 spursDmaWaitForCompletion(spu_thread& spu, u32 tagMask, bool waitForAll = true);
static void spursHalt(spu_thread& spu);
//
// SPURS kernel functions
//
static bool spursKernel1SelectWorkload(spu_thread& spu);
static bool spursKernel2SelectWorkload(spu_thread& spu);
static void spursKernelDispatchWorkload(spu_thread& spu, u64 widAndPollStatus);
static bool spursKernelWorkloadExit(spu_thread& spu);
bool spursKernelEntry(spu_thread& spu);
//
// SPURS system workload functions
//
static bool spursSysServiceEntry(spu_thread& spu);
// TODO: Exit
static void spursSysServiceIdleHandler(spu_thread& spu, SpursKernelContext* ctxt);
static void spursSysServiceMain(spu_thread& spu, u32 pollStatus);
static void spursSysServiceProcessRequests(spu_thread& spu, SpursKernelContext* ctxt);
static void spursSysServiceActivateWorkload(spu_thread& spu, SpursKernelContext* ctxt);
// TODO: Deactivate workload
static void spursSysServiceUpdateShutdownCompletionEvents(spu_thread& spu, SpursKernelContext* ctxt, u32 wklShutdownBitSet);
static void spursSysServiceTraceSaveCount(spu_thread& spu, SpursKernelContext* ctxt);
static void spursSysServiceTraceUpdate(spu_thread& spu, SpursKernelContext* ctxt, u32 arg2, u32 arg3, u32 forceNotify);
// TODO: Deactivate trace
// TODO: System workload entry
static void spursSysServiceCleanupAfterSystemWorkload(spu_thread& spu, SpursKernelContext* ctxt);
//
// SPURS taskset policy module functions
//
static bool spursTasksetEntry(spu_thread& spu);
static bool spursTasksetSyscallEntry(spu_thread& spu);
static void spursTasksetResumeTask(spu_thread& spu);
static void spursTasksetStartTask(spu_thread& spu, CellSpursTaskArgument& taskArgs);
static s32 spursTasksetProcessRequest(spu_thread& spu, s32 request, u32* taskId, u32* isWaiting);
static void spursTasksetProcessPollStatus(spu_thread& spu, u32 pollStatus);
static bool spursTasksetPollStatus(spu_thread& spu);
static void spursTasksetExit(spu_thread& spu);
static void spursTasksetOnTaskExit(spu_thread& spu, u64 addr, u32 taskId, s32 exitCode, u64 args);
static s32 spursTasketSaveTaskContext(spu_thread& spu);
static void spursTasksetDispatch(spu_thread& spu);
static s32 spursTasksetProcessSyscall(spu_thread& spu, u32 syscallNum, u32 args);
static void spursTasksetInit(spu_thread& spu, u32 pollStatus);
static s32 spursTasksetLoadElf(spu_thread& spu, u32* entryPoint, u32* lowestLoadAddr, u64 elfAddr, bool skipWriteableSegments);
//
// SPURS jobchain policy module functions
//
bool spursJobChainEntry(spu_thread& spu);
void spursJobchainPopUrgentCommand(spu_thread& spu);
//----------------------------------------------------------------------------
// SPURS utility functions
//----------------------------------------------------------------------------
// Output trace information
void cellSpursModulePutTrace(CellSpursTracePacket* packet, u32 dmaTagId)
{
// TODO: Implement this
}
// Check for execution right requests
u32 cellSpursModulePollStatus(spu_thread& spu, u32* status)
{
auto ctxt = spu._ptr<SpursKernelContext>(0x100);
spu.gpr[3]._u32[3] = 1;
if (ctxt->spurs->flags1 & SF1_32_WORKLOADS)
{
spursKernel2SelectWorkload(spu);
}
else
{
spursKernel1SelectWorkload(spu);
}
auto result = spu.gpr[3]._u64[1];
if (status)
{
*status = static_cast<u32>(result);
}
u32 wklId = result >> 32;
return wklId == ctxt->wklCurrentId ? 0 : 1;
}
// Exit current workload
void cellSpursModuleExit(spu_thread& spu)
{
auto ctxt = spu._ptr<SpursKernelContext>(0x100);
spu.pc = ctxt->exitToKernelAddr;
// TODO: use g_escape for actual long jump
//throw SpursModuleExit();
}
// Execute a DMA operation
bool spursDma(spu_thread& spu, const spu_mfc_cmd& args)
{
spu.ch_mfc_cmd = args;
if (!spu.process_mfc_cmd())
{
spu_runtime::g_escape(&spu);
}
if (args.cmd == MFC_GETLLAR_CMD || args.cmd == MFC_PUTLLC_CMD || args.cmd == MFC_PUTLLUC_CMD)
{
return static_cast<u32>(spu.get_ch_value(MFC_RdAtomicStat)) != MFC_PUTLLC_FAILURE;
}
return true;
}
// Execute a DMA operation
bool spursDma(spu_thread& spu, u32 cmd, u64 ea, u32 lsa, u32 size, u32 tag)
{
return spursDma(spu, {MFC(cmd), static_cast<u8>(tag & 0x1f), static_cast<u16>(size & 0x7fff), lsa, static_cast<u32>(ea), static_cast<u32>(ea >> 32)});
}
// Get the status of DMA operations
u32 spursDmaGetCompletionStatus(spu_thread& spu, u32 tagMask)
{
spu.set_ch_value(MFC_WrTagMask, tagMask);
spu.set_ch_value(MFC_WrTagUpdate, MFC_TAG_UPDATE_IMMEDIATE);
return static_cast<u32>(spu.get_ch_value(MFC_RdTagStat));
}
// Wait for DMA operations to complete
u32 spursDmaWaitForCompletion(spu_thread& spu, u32 tagMask, bool waitForAll)
{
spu.set_ch_value(MFC_WrTagMask, tagMask);
spu.set_ch_value(MFC_WrTagUpdate, waitForAll ? MFC_TAG_UPDATE_ALL : MFC_TAG_UPDATE_ANY);
return static_cast<u32>(spu.get_ch_value(MFC_RdTagStat));
}
// Halt the SPU
void spursHalt(spu_thread& spu)
{
spu.halt();
}
void sys_spu_thread_exit(spu_thread& spu, s32 status)
{
// Cancel any pending status update requests
spu.set_ch_value(MFC_WrTagUpdate, 0);
while (spu.get_ch_count(MFC_RdTagStat) != 1);
spu.get_ch_value(MFC_RdTagStat);
// Wait for all pending DMA operations to complete
spu.set_ch_value(MFC_WrTagMask, 0xFFFFFFFF);
spu.set_ch_value(MFC_WrTagUpdate, MFC_TAG_UPDATE_ALL);
spu.get_ch_value(MFC_RdTagStat);
spu.set_ch_value(SPU_WrOutMbox, status);
spu.stop_and_signal(0x102);
}
void sys_spu_thread_group_exit(spu_thread& spu, s32 status)
{
// Cancel any pending status update requests
spu.set_ch_value(MFC_WrTagUpdate, 0);
while (spu.get_ch_count(MFC_RdTagStat) != 1);
spu.get_ch_value(MFC_RdTagStat);
// Wait for all pending DMA operations to complete
spu.set_ch_value(MFC_WrTagMask, 0xFFFFFFFF);
spu.set_ch_value(MFC_WrTagUpdate, MFC_TAG_UPDATE_ALL);
spu.get_ch_value(MFC_RdTagStat);
spu.set_ch_value(SPU_WrOutMbox, status);
spu.stop_and_signal(0x101);
}
s32 sys_spu_thread_send_event(spu_thread& spu, u8 spup, u32 data0, u32 data1)
{
if (spup > 0x3F)
{
return CELL_EINVAL;
}
if (spu.get_ch_count(SPU_RdInMbox))
{
return CELL_EBUSY;
}
spu.set_ch_value(SPU_WrOutMbox, data1);
spu.set_ch_value(SPU_WrOutIntrMbox, (spup << 24) | (data0 & 0x00FFFFFF));
return static_cast<u32>(spu.get_ch_value(SPU_RdInMbox));
}
s32 sys_spu_thread_switch_system_module(spu_thread& spu, u32 status)
{
if (spu.get_ch_count(SPU_RdInMbox))
{
return CELL_EBUSY;
}
u32 result;
// Cancel any pending status update requests
spu.set_ch_value(MFC_WrTagUpdate, 0);
while (spu.get_ch_count(MFC_RdTagStat) != 1);
spu.get_ch_value(MFC_RdTagStat);
// Wait for all pending DMA operations to complete
spu.set_ch_value(MFC_WrTagMask, 0xFFFFFFFF);
spu.set_ch_value(MFC_WrTagUpdate, MFC_TAG_UPDATE_ALL);
spu.get_ch_value(MFC_RdTagStat);
do
{
spu.set_ch_value(SPU_WrOutMbox, status);
spu.stop_and_signal(0x120);
result = static_cast<u32>(spu.get_ch_value(SPU_RdInMbox));
}
while (result == CELL_EBUSY);
return result;
}
//----------------------------------------------------------------------------
// SPURS kernel functions
//----------------------------------------------------------------------------
// Select a workload to run
bool spursKernel1SelectWorkload(spu_thread& spu)
{
const auto ctxt = spu._ptr<SpursKernelContext>(0x100);
// The first and only argument to this function is a boolean that is set to false if the function
// is called by the SPURS kernel and set to true if called by cellSpursModulePollStatus.
// If the first argument is true then the shared data is not updated with the result.
const auto isPoll = spu.gpr[3]._u32[3];
u32 wklSelectedId;
u32 pollStatus;
//vm::reservation_op(vm::cast(ctxt->spurs.addr()), 128, [&]()
{
// lock the first 0x80 bytes of spurs
auto spurs = ctxt->spurs.get_ptr();
// Calculate the contention (number of SPUs used) for each workload
u8 contention[CELL_SPURS_MAX_WORKLOAD];
u8 pendingContention[CELL_SPURS_MAX_WORKLOAD];
for (u32 i = 0; i < CELL_SPURS_MAX_WORKLOAD; i++)
{
contention[i] = spurs->wklCurrentContention[i] - ctxt->wklLocContention[i];
// If this is a poll request then the number of SPUs pending to context switch is also added to the contention presumably
// to prevent unnecessary jumps to the kernel
if (isPoll)
{
pendingContention[i] = spurs->wklPendingContention[i] - ctxt->wklLocPendingContention[i];
if (i != ctxt->wklCurrentId)
{
contention[i] += pendingContention[i];
}
}
}
wklSelectedId = CELL_SPURS_SYS_SERVICE_WORKLOAD_ID;
pollStatus = 0;
// The system service has the highest priority. Select the system service if
// the system service message bit for this SPU is set.
if (spurs->sysSrvMessage & (1 << ctxt->spuNum))
{
ctxt->spuIdling = 0;
if (!isPoll || ctxt->wklCurrentId == CELL_SPURS_SYS_SERVICE_WORKLOAD_ID)
{
// Clear the message bit
spurs->sysSrvMessage.raw() &= ~(1 << ctxt->spuNum);
}
}
else
{
// Caclulate the scheduling weight for each workload
u16 maxWeight = 0;
for (u32 i = 0; i < CELL_SPURS_MAX_WORKLOAD; i++)
{
u16 runnable = ctxt->wklRunnable1 & (0x8000 >> i);
u16 wklSignal = spurs->wklSignal1.load() & (0x8000 >> i);
u8 wklFlag = spurs->wklFlag.flag.load() == 0u ? spurs->wklFlagReceiver == i ? 1 : 0 : 0;
u8 readyCount = spurs->wklReadyCount1[i] > CELL_SPURS_MAX_SPU ? CELL_SPURS_MAX_SPU : spurs->wklReadyCount1[i].load();
u8 idleSpuCount = spurs->wklIdleSpuCountOrReadyCount2[i] > CELL_SPURS_MAX_SPU ? CELL_SPURS_MAX_SPU : spurs->wklIdleSpuCountOrReadyCount2[i].load();
u8 requestCount = readyCount + idleSpuCount;
// For a workload to be considered for scheduling:
// 1. Its priority must not be 0
// 2. The number of SPUs used by it must be less than the max contention for that workload
// 3. The workload should be in runnable state
// 4. The number of SPUs allocated to it must be less than the number of SPUs requested (i.e. readyCount)
// OR the workload must be signalled
// OR the workload flag is 0 and the workload is configured as the wokload flag receiver
if (runnable && ctxt->priority[i] != 0 && spurs->wklMaxContention[i] > contention[i])
{
if (wklFlag || wklSignal || (readyCount != 0 && requestCount > contention[i]))
{
// The scheduling weight of the workload is formed from the following parameters in decreasing order of priority:
// 1. Wokload signal set or workload flag or ready count > contention
// 2. Priority of the workload on the SPU
// 3. Is the workload the last selected workload
// 4. Minimum contention of the workload
// 5. Number of SPUs that are being used by the workload (lesser the number, more the weight)
// 6. Is the workload executable same as the currently loaded executable
// 7. The workload id (lesser the number, more the weight)
u16 weight = (wklFlag || wklSignal || (readyCount > contention[i])) ? 0x8000 : 0;
weight |= (ctxt->priority[i] & 0x7F) << 8; // TODO: was shifted << 16
weight |= i == ctxt->wklCurrentId ? 0x80 : 0x00;
weight |= (contention[i] > 0 && spurs->wklMinContention[i] > contention[i]) ? 0x40 : 0x00;
weight |= ((CELL_SPURS_MAX_SPU - contention[i]) & 0x0F) << 2;
weight |= ctxt->wklUniqueId[i] == ctxt->wklCurrentId ? 0x02 : 0x00;
weight |= 0x01;
// In case of a tie the lower numbered workload is chosen
if (weight > maxWeight)
{
wklSelectedId = i;
maxWeight = weight;
pollStatus = readyCount > contention[i] ? CELL_SPURS_MODULE_POLL_STATUS_READYCOUNT : 0;
pollStatus |= wklSignal ? CELL_SPURS_MODULE_POLL_STATUS_SIGNAL : 0;
pollStatus |= wklFlag ? CELL_SPURS_MODULE_POLL_STATUS_FLAG : 0;
}
}
}
}
// Not sure what this does. Possibly mark the SPU as idle/in use.
ctxt->spuIdling = wklSelectedId == CELL_SPURS_SYS_SERVICE_WORKLOAD_ID ? 1 : 0;
if (!isPoll || wklSelectedId == ctxt->wklCurrentId)
{
// Clear workload signal for the selected workload
spurs->wklSignal1.raw() &= ~(0x8000 >> wklSelectedId);
spurs->wklSignal2.raw() &= ~(0x80000000u >> wklSelectedId);
// If the selected workload is the wklFlag workload then pull the wklFlag to all 1s
if (wklSelectedId == spurs->wklFlagReceiver)
{
spurs->wklFlag.flag = -1;
}
}
}
if (!isPoll)
{
// Called by kernel
// Increment the contention for the selected workload
if (wklSelectedId != CELL_SPURS_SYS_SERVICE_WORKLOAD_ID)
{
contention[wklSelectedId]++;
}
for (u32 i = 0; i < CELL_SPURS_MAX_WORKLOAD; i++)
{
spurs->wklCurrentContention[i] = contention[i];
spurs->wklPendingContention[i] = spurs->wklPendingContention[i] - ctxt->wklLocPendingContention[i];
ctxt->wklLocContention[i] = 0;
ctxt->wklLocPendingContention[i] = 0;
}
if (wklSelectedId != CELL_SPURS_SYS_SERVICE_WORKLOAD_ID)
{
ctxt->wklLocContention[wklSelectedId] = 1;
}
ctxt->wklCurrentId = wklSelectedId;
}
else if (wklSelectedId != ctxt->wklCurrentId)
{
// Not called by kernel but a context switch is required
// Increment the pending contention for the selected workload
if (wklSelectedId != CELL_SPURS_SYS_SERVICE_WORKLOAD_ID)
{
pendingContention[wklSelectedId]++;
}
for (u32 i = 0; i < CELL_SPURS_MAX_WORKLOAD; i++)
{
spurs->wklPendingContention[i] = pendingContention[i];
ctxt->wklLocPendingContention[i] = 0;
}
if (wklSelectedId != CELL_SPURS_SYS_SERVICE_WORKLOAD_ID)
{
ctxt->wklLocPendingContention[wklSelectedId] = 1;
}
}
else
{
// Not called by kernel and no context switch is required
for (u32 i = 0; i < CELL_SPURS_MAX_WORKLOAD; i++)
{
spurs->wklPendingContention[i] = spurs->wklPendingContention[i] - ctxt->wklLocPendingContention[i];
ctxt->wklLocPendingContention[i] = 0;
}
}
std::memcpy(ctxt, spurs, 128);
}//);
u64 result = u64{wklSelectedId} << 32;
result |= pollStatus;
spu.gpr[3]._u64[1] = result;
return true;
}
// Select a workload to run
bool spursKernel2SelectWorkload(spu_thread& spu)
{
const auto ctxt = spu._ptr<SpursKernelContext>(0x100);
// The first and only argument to this function is a boolean that is set to false if the function
// is called by the SPURS kernel and set to true if called by cellSpursModulePollStatus.
// If the first argument is true then the shared data is not updated with the result.
const auto isPoll = spu.gpr[3]._u32[3];
u32 wklSelectedId;
u32 pollStatus;
//vm::reservation_op(vm::cast(ctxt->spurs.addr()), 128, [&]()
{
// lock the first 0x80 bytes of spurs
auto spurs = ctxt->spurs.get_ptr();
// Calculate the contention (number of SPUs used) for each workload
u8 contention[CELL_SPURS_MAX_WORKLOAD2];
u8 pendingContention[CELL_SPURS_MAX_WORKLOAD2];
for (u32 i = 0; i < CELL_SPURS_MAX_WORKLOAD2; i++)
{
contention[i] = spurs->wklCurrentContention[i & 0x0F] - ctxt->wklLocContention[i & 0x0F];
contention[i] = i + 0u < CELL_SPURS_MAX_WORKLOAD ? contention[i] & 0x0F : contention[i] >> 4;
// If this is a poll request then the number of SPUs pending to context switch is also added to the contention presumably
// to prevent unnecessary jumps to the kernel
if (isPoll)
{
pendingContention[i] = spurs->wklPendingContention[i & 0x0F] - ctxt->wklLocPendingContention[i & 0x0F];
pendingContention[i] = i + 0u < CELL_SPURS_MAX_WORKLOAD ? pendingContention[i] & 0x0F : pendingContention[i] >> 4;
if (i != ctxt->wklCurrentId)
{
contention[i] += pendingContention[i];
}
}
}
wklSelectedId = CELL_SPURS_SYS_SERVICE_WORKLOAD_ID;
pollStatus = 0;
// The system service has the highest priority. Select the system service if
// the system service message bit for this SPU is set.
if (spurs->sysSrvMessage & (1 << ctxt->spuNum))
{
// Not sure what this does. Possibly Mark the SPU as in use.
ctxt->spuIdling = 0;
if (!isPoll || ctxt->wklCurrentId == CELL_SPURS_SYS_SERVICE_WORKLOAD_ID)
{
// Clear the message bit
spurs->sysSrvMessage.raw() &= ~(1 << ctxt->spuNum);
}
}
else
{
// Caclulate the scheduling weight for each workload
u8 maxWeight = 0;
for (u32 i = 0; i < CELL_SPURS_MAX_WORKLOAD2; i++)
{
u32 j = i & 0x0f;
u16 runnable = i < CELL_SPURS_MAX_WORKLOAD ? ctxt->wklRunnable1 & (0x8000 >> j) : ctxt->wklRunnable2 & (0x8000 >> j);
u8 priority = i < CELL_SPURS_MAX_WORKLOAD ? ctxt->priority[j] & 0x0F : ctxt->priority[j] >> 4;
u8 maxContention = i < CELL_SPURS_MAX_WORKLOAD ? spurs->wklMaxContention[j] & 0x0F : spurs->wklMaxContention[j] >> 4;
u16 wklSignal = i < CELL_SPURS_MAX_WORKLOAD ? spurs->wklSignal1.load() & (0x8000 >> j) : spurs->wklSignal2.load() & (0x8000 >> j);
u8 wklFlag = spurs->wklFlag.flag.load() == 0u ? spurs->wklFlagReceiver == i ? 1 : 0 : 0;
u8 readyCount = i < CELL_SPURS_MAX_WORKLOAD ? spurs->wklReadyCount1[j] : spurs->wklIdleSpuCountOrReadyCount2[j];
// For a workload to be considered for scheduling:
// 1. Its priority must be greater than 0
// 2. The number of SPUs used by it must be less than the max contention for that workload
// 3. The workload should be in runnable state
// 4. The number of SPUs allocated to it must be less than the number of SPUs requested (i.e. readyCount)
// OR the workload must be signalled
// OR the workload flag is 0 and the workload is configured as the wokload receiver
if (runnable && priority > 0 && maxContention > contention[i])
{
if (wklFlag || wklSignal || readyCount > contention[i])
{
// The scheduling weight of the workload is equal to the priority of the workload for the SPU.
// The current workload is given a sligtly higher weight presumably to reduce the number of context switches.
// In case of a tie the lower numbered workload is chosen.
u8 weight = priority << 4;
if (ctxt->wklCurrentId == i)
{
weight |= 0x04;
}
if (weight > maxWeight)
{
wklSelectedId = i;
maxWeight = weight;
pollStatus = readyCount > contention[i] ? CELL_SPURS_MODULE_POLL_STATUS_READYCOUNT : 0;
pollStatus |= wklSignal ? CELL_SPURS_MODULE_POLL_STATUS_SIGNAL : 0;
pollStatus |= wklFlag ? CELL_SPURS_MODULE_POLL_STATUS_FLAG : 0;
}
}
}
}
// Not sure what this does. Possibly mark the SPU as idle/in use.
ctxt->spuIdling = wklSelectedId == CELL_SPURS_SYS_SERVICE_WORKLOAD_ID ? 1 : 0;
if (!isPoll || wklSelectedId == ctxt->wklCurrentId)
{
// Clear workload signal for the selected workload
spurs->wklSignal1.raw() &= ~(0x8000 >> wklSelectedId);
spurs->wklSignal2.raw() &= ~(0x80000000u >> wklSelectedId);
// If the selected workload is the wklFlag workload then pull the wklFlag to all 1s
if (wklSelectedId == spurs->wklFlagReceiver)
{
spurs->wklFlag.flag = -1;
}
}
}
if (!isPoll)
{
// Called by kernel
// Increment the contention for the selected workload
if (wklSelectedId != CELL_SPURS_SYS_SERVICE_WORKLOAD_ID)
{
contention[wklSelectedId]++;
}
for (u32 i = 0; i < (CELL_SPURS_MAX_WORKLOAD2 >> 1); i++)
{
spurs->wklCurrentContention[i] = contention[i] | (contention[i + 0x10] << 4);
spurs->wklPendingContention[i] = spurs->wklPendingContention[i] - ctxt->wklLocPendingContention[i];
ctxt->wklLocContention[i] = 0;
ctxt->wklLocPendingContention[i] = 0;
}
ctxt->wklLocContention[wklSelectedId & 0x0F] = wklSelectedId < CELL_SPURS_MAX_WORKLOAD ? 0x01 : wklSelectedId < CELL_SPURS_MAX_WORKLOAD2 ? 0x10 : 0;
ctxt->wklCurrentId = wklSelectedId;
}
else if (wklSelectedId != ctxt->wklCurrentId)
{
// Not called by kernel but a context switch is required
// Increment the pending contention for the selected workload
if (wklSelectedId != CELL_SPURS_SYS_SERVICE_WORKLOAD_ID)
{
pendingContention[wklSelectedId]++;
}
for (u32 i = 0; i < (CELL_SPURS_MAX_WORKLOAD2 >> 1); i++)
{
spurs->wklPendingContention[i] = pendingContention[i] | (pendingContention[i + 0x10] << 4);
ctxt->wklLocPendingContention[i] = 0;
}
ctxt->wklLocPendingContention[wklSelectedId & 0x0F] = wklSelectedId < CELL_SPURS_MAX_WORKLOAD ? 0x01 : wklSelectedId < CELL_SPURS_MAX_WORKLOAD2 ? 0x10 : 0;
}
else
{
// Not called by kernel and no context switch is required
for (u32 i = 0; i < CELL_SPURS_MAX_WORKLOAD; i++)
{
spurs->wklPendingContention[i] = spurs->wklPendingContention[i] - ctxt->wklLocPendingContention[i];
ctxt->wklLocPendingContention[i] = 0;
}
}
std::memcpy(ctxt, spurs, 128);
}//);
u64 result = u64{wklSelectedId} << 32;
result |= pollStatus;
spu.gpr[3]._u64[1] = result;
return true;
}
// SPURS kernel dispatch workload
void spursKernelDispatchWorkload(spu_thread& spu, u64 widAndPollStatus)
{
const auto ctxt = spu._ptr<SpursKernelContext>(0x100);
auto isKernel2 = ctxt->spurs->flags1 & SF1_32_WORKLOADS ? true : false;
auto pollStatus = static_cast<u32>(widAndPollStatus);
auto wid = static_cast<u32>(widAndPollStatus >> 32);
// DMA in the workload info for the selected workload
auto wklInfoOffset = wid < CELL_SPURS_MAX_WORKLOAD ? &ctxt->spurs->wklInfo1[wid] :
wid < CELL_SPURS_MAX_WORKLOAD2 && isKernel2 ? &ctxt->spurs->wklInfo2[wid & 0xf] :
&ctxt->spurs->wklInfoSysSrv;
const auto wklInfo = spu._ptr<CellSpurs::WorkloadInfo>(0x3FFE0);
std::memcpy(wklInfo, wklInfoOffset, 0x20);
// Load the workload to LS
if (ctxt->wklCurrentAddr != wklInfo->addr)
{
switch (wklInfo->addr.addr())
{
case SPURS_IMG_ADDR_SYS_SRV_WORKLOAD:
//spu.RegisterHleFunction(0xA00, spursSysServiceEntry);
break;
case SPURS_IMG_ADDR_TASKSET_PM:
//spu.RegisterHleFunction(0xA00, spursTasksetEntry);
break;
default:
std::memcpy(spu._ptr<void>(0xA00), wklInfo->addr.get_ptr(), wklInfo->size);
break;
}
ctxt->wklCurrentAddr = wklInfo->addr;
ctxt->wklCurrentUniqueId = wklInfo->uniqueId;
}
if (!isKernel2)
{
ctxt->moduleId[0] = 0;
ctxt->moduleId[1] = 0;
}
// Run workload
spu.gpr[0]._u32[3] = ctxt->exitToKernelAddr;
spu.gpr[1]._u32[3] = 0x3FFB0;
spu.gpr[3]._u32[3] = 0x100;
spu.gpr[4]._u64[1] = wklInfo->arg;
spu.gpr[5]._u32[3] = pollStatus;
spu.pc = 0xA00;
}
// SPURS kernel workload exit
bool spursKernelWorkloadExit(spu_thread& spu)
{
const auto ctxt = spu._ptr<SpursKernelContext>(0x100);
auto isKernel2 = ctxt->spurs->flags1 & SF1_32_WORKLOADS ? true : false;
// Select next workload to run
spu.gpr[3].clear();
if (isKernel2)
{
spursKernel2SelectWorkload(spu);
}
else
{
spursKernel1SelectWorkload(spu);
}
spursKernelDispatchWorkload(spu, spu.gpr[3]._u64[1]);
return false;
}
// SPURS kernel entry point
bool spursKernelEntry(spu_thread& spu)
{
const auto ctxt = spu._ptr<SpursKernelContext>(0x100);
memset(ctxt, 0, sizeof(SpursKernelContext));
// Save arguments
ctxt->spuNum = spu.gpr[3]._u32[3];
ctxt->spurs.set(spu.gpr[4]._u64[1]);
auto isKernel2 = ctxt->spurs->flags1 & SF1_32_WORKLOADS ? true : false;
// Initialise the SPURS context to its initial values
ctxt->dmaTagId = CELL_SPURS_KERNEL_DMA_TAG_ID;
ctxt->wklCurrentUniqueId = 0x20;
ctxt->wklCurrentId = CELL_SPURS_SYS_SERVICE_WORKLOAD_ID;
ctxt->exitToKernelAddr = isKernel2 ? CELL_SPURS_KERNEL2_EXIT_ADDR : CELL_SPURS_KERNEL1_EXIT_ADDR;
ctxt->selectWorkloadAddr = isKernel2 ? CELL_SPURS_KERNEL2_SELECT_WORKLOAD_ADDR : CELL_SPURS_KERNEL1_SELECT_WORKLOAD_ADDR;
if (!isKernel2)
{
ctxt->x1F0 = 0xF0020000;
ctxt->x200 = 0x20000;
ctxt->guid[0] = 0x423A3A02;
ctxt->guid[1] = 0x43F43A82;
ctxt->guid[2] = 0x43F26502;
ctxt->guid[3] = 0x420EB382;
}
else
{
ctxt->guid[0] = 0x43A08402;
ctxt->guid[1] = 0x43FB0A82;
ctxt->guid[2] = 0x435E9302;
ctxt->guid[3] = 0x43A3C982;
}
// Register SPURS kernel HLE functions
//spu.UnregisterHleFunctions(0, 0x40000/*LS_BOTTOM*/);
//spu.RegisterHleFunction(isKernel2 ? CELL_SPURS_KERNEL2_ENTRY_ADDR : CELL_SPURS_KERNEL1_ENTRY_ADDR, spursKernelEntry);
//spu.RegisterHleFunction(ctxt->exitToKernelAddr, spursKernelWorkloadExit);
//spu.RegisterHleFunction(ctxt->selectWorkloadAddr, isKernel2 ? spursKernel2SelectWorkload : spursKernel1SelectWorkload);
// Start the system service
spursKernelDispatchWorkload(spu, u64{CELL_SPURS_SYS_SERVICE_WORKLOAD_ID} << 32);
return false;
}
//----------------------------------------------------------------------------
// SPURS system workload functions
//----------------------------------------------------------------------------
// Entry point of the system service
bool spursSysServiceEntry(spu_thread& spu)
{
const auto ctxt = spu._ptr<SpursKernelContext>(spu.gpr[3]._u32[3]);
//auto arg = spu.gpr[4]._u64[1];
auto pollStatus = spu.gpr[5]._u32[3];
{
if (ctxt->wklCurrentId == CELL_SPURS_SYS_SERVICE_WORKLOAD_ID)
{
spursSysServiceMain(spu, pollStatus);
}
else
{
// TODO: If we reach here it means the current workload was preempted to start the
// system workload. Need to implement this.
}
cellSpursModuleExit(spu);
}
return false;
}
// Wait for an external event or exit the SPURS thread group if no workloads can be scheduled
void spursSysServiceIdleHandler(spu_thread& spu, SpursKernelContext* ctxt)
{
bool shouldExit;
while (true)
{
const auto spurs = spu._ptr<CellSpurs>(0x100);
//vm::reservation_acquire(ctxt->spurs.addr());
// Find the number of SPUs that are idling in this SPURS instance
u32 nIdlingSpus = 0;
for (u32 i = 0; i < 8; i++)
{
if (spurs->spuIdling & (1 << i))
{
nIdlingSpus++;
}
}
bool allSpusIdle = nIdlingSpus == spurs->nSpus ? true : false;
bool exitIfNoWork = spurs->flags1 & SF1_EXIT_IF_NO_WORK ? true : false;
shouldExit = allSpusIdle && exitIfNoWork;
// Check if any workloads can be scheduled
bool foundReadyWorkload = false;
if (spurs->sysSrvMessage & (1 << ctxt->spuNum))
{
foundReadyWorkload = true;
}
else
{
if (spurs->flags1 & SF1_32_WORKLOADS)
{
for (u32 i = 0; i < CELL_SPURS_MAX_WORKLOAD2; i++)
{
u32 j = i & 0x0F;
u16 runnable = i < CELL_SPURS_MAX_WORKLOAD ? ctxt->wklRunnable1 & (0x8000 >> j) : ctxt->wklRunnable2 & (0x8000 >> j);
u8 priority = i < CELL_SPURS_MAX_WORKLOAD ? ctxt->priority[j] & 0x0F : ctxt->priority[j] >> 4;
u8 maxContention = i < CELL_SPURS_MAX_WORKLOAD ? spurs->wklMaxContention[j] & 0x0F : spurs->wklMaxContention[j] >> 4;
u8 contention = i < CELL_SPURS_MAX_WORKLOAD ? spurs->wklCurrentContention[j] & 0x0F : spurs->wklCurrentContention[j] >> 4;
u16 wklSignal = i < CELL_SPURS_MAX_WORKLOAD ? spurs->wklSignal1.load() & (0x8000 >> j) : spurs->wklSignal2.load() & (0x8000 >> j);
u8 wklFlag = spurs->wklFlag.flag.load() == 0u ? spurs->wklFlagReceiver == i ? 1 : 0 : 0;
u8 readyCount = i < CELL_SPURS_MAX_WORKLOAD ? spurs->wklReadyCount1[j] : spurs->wklIdleSpuCountOrReadyCount2[j];
if (runnable && priority > 0 && maxContention > contention)
{
if (wklFlag || wklSignal || readyCount > contention)
{
foundReadyWorkload = true;
break;
}
}
}
}
else
{
for (u32 i = 0; i < CELL_SPURS_MAX_WORKLOAD; i++)
{
u16 runnable = ctxt->wklRunnable1 & (0x8000 >> i);
u16 wklSignal = spurs->wklSignal1.load() & (0x8000 >> i);
u8 wklFlag = spurs->wklFlag.flag.load() == 0u ? spurs->wklFlagReceiver == i ? 1 : 0 : 0;
u8 readyCount = spurs->wklReadyCount1[i] > CELL_SPURS_MAX_SPU ? CELL_SPURS_MAX_SPU : spurs->wklReadyCount1[i].load();
u8 idleSpuCount = spurs->wklIdleSpuCountOrReadyCount2[i] > CELL_SPURS_MAX_SPU ? CELL_SPURS_MAX_SPU : spurs->wklIdleSpuCountOrReadyCount2[i].load();
u8 requestCount = readyCount + idleSpuCount;
if (runnable && ctxt->priority[i] != 0 && spurs->wklMaxContention[i] > spurs->wklCurrentContention[i])
{
if (wklFlag || wklSignal || (readyCount != 0 && requestCount > spurs->wklCurrentContention[i]))
{
foundReadyWorkload = true;
break;
}
}
}
}
}
bool spuIdling = spurs->spuIdling & (1 << ctxt->spuNum) ? true : false;
if (foundReadyWorkload && shouldExit == false)
{
spurs->spuIdling &= ~(1 << ctxt->spuNum);
}
else
{
spurs->spuIdling |= 1 << ctxt->spuNum;
}
// If all SPUs are idling and the exit_if_no_work flag is set then the SPU thread group must exit. Otherwise wait for external events.
if (spuIdling && shouldExit == false && foundReadyWorkload == false)
{
// The system service blocks by making a reservation and waiting on the lock line reservation lost event.
thread_ctrl::wait_for(1000);
continue;
}
//if (vm::reservation_update(vm::cast(ctxt->spurs.addr()), spu._ptr<void>(0x100), 128) && (shouldExit || foundReadyWorkload))
{
break;
}
}
if (shouldExit)
{
// TODO: exit spu thread group
}
}
// Main function for the system service
void spursSysServiceMain(spu_thread& spu, u32 pollStatus)
{
const auto ctxt = spu._ptr<SpursKernelContext>(0x100);
if (!ctxt->spurs.aligned())
{
spu_log.error("spursSysServiceMain(): invalid spurs alignment");
spursHalt(spu);
}
// Initialise the system service if this is the first time its being started on this SPU
if (ctxt->sysSrvInitialised == 0)
{
ctxt->sysSrvInitialised = 1;
//vm::reservation_acquire(ctxt->spurs.addr());
//vm::reservation_op(ctxt->spurs.ptr(&CellSpurs::wklState1).addr(), [&]()
{
auto spurs = ctxt->spurs.get_ptr();
// Halt if already initialised
if (spurs->sysSrvOnSpu & (1 << ctxt->spuNum))
{
spu_log.error("spursSysServiceMain(): already initialized");
spursHalt(spu);
}
spurs->sysSrvOnSpu |= 1 << ctxt->spuNum;
std::memcpy(spu._ptr<void>(0x2D80), spurs->wklState1, 128);
}//);
ctxt->traceBuffer = 0;
ctxt->traceMsgCount = -1;
spursSysServiceTraceUpdate(spu, ctxt, 1, 1, 0);
spursSysServiceCleanupAfterSystemWorkload(spu, ctxt);
// Trace - SERVICE: INIT
CellSpursTracePacket pkt{};
pkt.header.tag = CELL_SPURS_TRACE_TAG_SERVICE;
pkt.data.service.incident = CELL_SPURS_TRACE_SERVICE_INIT;
cellSpursModulePutTrace(&pkt, ctxt->dmaTagId);
}
// Trace - START: Module='SYS '
CellSpursTracePacket pkt{};
pkt.header.tag = CELL_SPURS_TRACE_TAG_START;
std::memcpy(pkt.data.start._module, "SYS ", 4);
pkt.data.start.level = 1; // Policy module
pkt.data.start.ls = 0xA00 >> 2;
cellSpursModulePutTrace(&pkt, ctxt->dmaTagId);
while (true)
{
// Process requests for the system service
spursSysServiceProcessRequests(spu, ctxt);
poll:
if (cellSpursModulePollStatus(spu, nullptr))
{
// Trace - SERVICE: EXIT
CellSpursTracePacket pkt{};
pkt.header.tag = CELL_SPURS_TRACE_TAG_SERVICE;
pkt.data.service.incident = CELL_SPURS_TRACE_SERVICE_EXIT;
cellSpursModulePutTrace(&pkt, ctxt->dmaTagId);
// Trace - STOP: GUID
pkt = {};
pkt.header.tag = CELL_SPURS_TRACE_TAG_STOP;
pkt.data.stop = SPURS_GUID_SYS_WKL;
cellSpursModulePutTrace(&pkt, ctxt->dmaTagId);
//spursDmaWaitForCompletion(spu, 1 << ctxt->dmaTagId);
break;
}
// If we reach here it means that either there are more system service messages to be processed
// or there are no workloads that can be scheduled.
// If the SPU is not idling then process the remaining system service messages
if (ctxt->spuIdling == 0)
{
continue;
}
// If we reach here it means that the SPU is idling
// Trace - SERVICE: WAIT
CellSpursTracePacket pkt{};
pkt.header.tag = CELL_SPURS_TRACE_TAG_SERVICE;
pkt.data.service.incident = CELL_SPURS_TRACE_SERVICE_WAIT;
cellSpursModulePutTrace(&pkt, ctxt->dmaTagId);
spursSysServiceIdleHandler(spu, ctxt);
goto poll;
}
}
// Process any requests
void spursSysServiceProcessRequests(spu_thread& spu, SpursKernelContext* ctxt)
{
bool updateTrace = false;
bool updateWorkload = false;
bool terminate = false;
//vm::reservation_op(vm::cast(ctxt->spurs.addr() + OFFSET_32(CellSpurs, wklState1)), 128, [&]()
{
auto spurs = ctxt->spurs.get_ptr();
// Terminate request
if (spurs->sysSrvMsgTerminate & (1 << ctxt->spuNum))
{
spurs->sysSrvOnSpu &= ~(1 << ctxt->spuNum);
terminate = true;
}
// Update workload message
if (spurs->sysSrvMsgUpdateWorkload & (1 << ctxt->spuNum))
{
spurs->sysSrvMsgUpdateWorkload &= ~(1 << ctxt->spuNum);
updateWorkload = true;
}
// Update trace message
if (spurs->sysSrvTrace.load().sysSrvMsgUpdateTrace & (1 << ctxt->spuNum))
{
updateTrace = true;
}
std::memcpy(spu._ptr<void>(0x2D80), spurs->wklState1, 128);
}//);
// Process update workload message
if (updateWorkload)
{
spursSysServiceActivateWorkload(spu, ctxt);
}
// Process update trace message
if (updateTrace)
{
spursSysServiceTraceUpdate(spu, ctxt, 1, 0, 0);
}
// Process terminate request
if (terminate)
{
// TODO: Rest of the terminate processing
}
}
// Activate a workload
void spursSysServiceActivateWorkload(spu_thread& spu, SpursKernelContext* ctxt)
{
const auto spurs = spu._ptr<CellSpurs>(0x100);
std::memcpy(spu._ptr<void>(0x30000), ctxt->spurs->wklInfo1, 0x200);
if (spurs->flags1 & SF1_32_WORKLOADS)
{
std::memcpy(spu._ptr<void>(0x30200), ctxt->spurs->wklInfo2, 0x200);
}
u32 wklShutdownBitSet = 0;
ctxt->wklRunnable1 = 0;
ctxt->wklRunnable2 = 0;
for (u32 i = 0; i < CELL_SPURS_MAX_WORKLOAD; i++)
{
const auto wklInfo1 = spu._ptr<CellSpurs::WorkloadInfo>(0x30000);
// Copy the priority of the workload for this SPU and its unique id to the LS
ctxt->priority[i] = wklInfo1[i].priority[ctxt->spuNum] == 0 ? 0 : 0x10 - wklInfo1[i].priority[ctxt->spuNum];
ctxt->wklUniqueId[i] = wklInfo1[i].uniqueId;
if (spurs->flags1 & SF1_32_WORKLOADS)
{
const auto wklInfo2 = spu._ptr<CellSpurs::WorkloadInfo>(0x30200);
// Copy the priority of the workload for this SPU to the LS
if (wklInfo2[i].priority[ctxt->spuNum])
{
ctxt->priority[i] |= (0x10 - wklInfo2[i].priority[ctxt->spuNum]) << 4;
}
}
}
//vm::reservation_op(ctxt->spurs.ptr(&CellSpurs::wklState1).addr(), 128, [&]()
{
auto spurs = ctxt->spurs.get_ptr();
for (u32 i = 0; i < CELL_SPURS_MAX_WORKLOAD; i++)
{
// Update workload status and runnable flag based on the workload state
auto wklStatus = spurs->wklStatus1[i];
if (spurs->wklState1[i] == SPURS_WKL_STATE_RUNNABLE)
{
spurs->wklStatus1[i] |= 1 << ctxt->spuNum;
ctxt->wklRunnable1 |= 0x8000 >> i;
}
else
{
spurs->wklStatus1[i] &= ~(1 << ctxt->spuNum);
}
// If the workload is shutting down and if this is the last SPU from which it is being removed then
// add it to the shutdown bit set
if (spurs->wklState1[i] == SPURS_WKL_STATE_SHUTTING_DOWN)
{
if (((wklStatus & (1 << ctxt->spuNum)) != 0) && (spurs->wklStatus1[i] == 0))
{
spurs->wklState1[i] = SPURS_WKL_STATE_REMOVABLE;
wklShutdownBitSet |= 0x80000000u >> i;
}
}
if (spurs->flags1 & SF1_32_WORKLOADS)
{
// Update workload status and runnable flag based on the workload state
wklStatus = spurs->wklStatus2[i];
if (spurs->wklState2[i] == SPURS_WKL_STATE_RUNNABLE)
{
spurs->wklStatus2[i] |= 1 << ctxt->spuNum;
ctxt->wklRunnable2 |= 0x8000 >> i;
}
else
{
spurs->wklStatus2[i] &= ~(1 << ctxt->spuNum);
}
// If the workload is shutting down and if this is the last SPU from which it is being removed then
// add it to the shutdown bit set
if (spurs->wklState2[i] == SPURS_WKL_STATE_SHUTTING_DOWN)
{
if (((wklStatus & (1 << ctxt->spuNum)) != 0) && (spurs->wklStatus2[i] == 0))
{
spurs->wklState2[i] = SPURS_WKL_STATE_REMOVABLE;
wklShutdownBitSet |= 0x8000 >> i;
}
}
}
}
std::memcpy(spu._ptr<void>(0x2D80), spurs->wklState1, 128);
}//);
if (wklShutdownBitSet)
{
spursSysServiceUpdateShutdownCompletionEvents(spu, ctxt, wklShutdownBitSet);
}
}
// Update shutdown completion events
void spursSysServiceUpdateShutdownCompletionEvents(spu_thread& spu, SpursKernelContext* ctxt, u32 wklShutdownBitSet)
{
// Mark the workloads in wklShutdownBitSet as completed and also generate a bit set of the completed
// workloads that have a shutdown completion hook registered
u32 wklNotifyBitSet;
[[maybe_unused]] u8 spuPort;
//vm::reservation_op(ctxt->spurs.ptr(&CellSpurs::wklState1).addr(), 128, [&]()
{
auto spurs = ctxt->spurs.get_ptr();
wklNotifyBitSet = 0;
spuPort = spurs->spuPort;
for (u32 i = 0; i < CELL_SPURS_MAX_WORKLOAD; i++)
{
if (wklShutdownBitSet & (0x80000000u >> i))
{
spurs->wklEvent1[i] |= 0x01;
if (spurs->wklEvent1[i] & 0x02 || spurs->wklEvent1[i] & 0x10)
{
wklNotifyBitSet |= 0x80000000u >> i;
}
}
if (wklShutdownBitSet & (0x8000 >> i))
{
spurs->wklEvent2[i] |= 0x01;
if (spurs->wklEvent2[i] & 0x02 || spurs->wklEvent2[i] & 0x10)
{
wklNotifyBitSet |= 0x8000 >> i;
}
}
}
std::memcpy(spu._ptr<void>(0x2D80), spurs->wklState1, 128);
}//);
if (wklNotifyBitSet)
{
// TODO: sys_spu_thread_send_event(spuPort, 0, wklNotifyMask);
}
}
// Update the trace count for this SPU
void spursSysServiceTraceSaveCount(spu_thread& spu, SpursKernelContext* ctxt)
{
if (ctxt->traceBuffer)
{
auto traceInfo = vm::ptr<CellSpursTraceInfo>::make(vm::cast(ctxt->traceBuffer - (ctxt->spurs->traceStartIndex[ctxt->spuNum] << 4)));
traceInfo->count[ctxt->spuNum] = ctxt->traceMsgCount;
}
}
// Update trace control
void spursSysServiceTraceUpdate(spu_thread& spu, SpursKernelContext* ctxt, u32 arg2, u32 arg3, u32 forceNotify)
{
bool notify;
u8 sysSrvMsgUpdateTrace;
//vm::reservation_op(ctxt->spurs.ptr(&CellSpurs::wklState1).addr(), 128, [&]()
{
auto spurs = ctxt->spurs.get_ptr();
auto& trace = spurs->sysSrvTrace.raw();
sysSrvMsgUpdateTrace = trace.sysSrvMsgUpdateTrace;
trace.sysSrvMsgUpdateTrace &= ~(1 << ctxt->spuNum);
trace.sysSrvTraceInitialised &= ~(1 << ctxt->spuNum);
trace.sysSrvTraceInitialised |= arg2 << ctxt->spuNum;
notify = false;
if (((sysSrvMsgUpdateTrace & (1 << ctxt->spuNum)) != 0) && (spurs->sysSrvTrace.load().sysSrvMsgUpdateTrace == 0) && (spurs->sysSrvTrace.load().sysSrvNotifyUpdateTraceComplete != 0))
{
trace.sysSrvNotifyUpdateTraceComplete = 0;
notify = true;
}
if (forceNotify && spurs->sysSrvTrace.load().sysSrvNotifyUpdateTraceComplete != 0)
{
trace.sysSrvNotifyUpdateTraceComplete = 0;
notify = true;
}
std::memcpy(spu._ptr<void>(0x2D80), spurs->wklState1, 128);
}//);
// Get trace parameters from CellSpurs and store them in the LS
if (((sysSrvMsgUpdateTrace & (1 << ctxt->spuNum)) != 0) || (arg3 != 0))
{
//vm::reservation_acquire(ctxt->spurs.ptr(&CellSpurs::traceBuffer).addr());
auto spurs = spu._ptr<CellSpurs>(0x80 - offset32(&CellSpurs::traceBuffer));
if (ctxt->traceMsgCount != 0xffu || spurs->traceBuffer.addr() == 0u)
{
spursSysServiceTraceSaveCount(spu, ctxt);
}
else
{
const auto traceBuffer = spu._ptr<CellSpursTraceInfo>(0x2C00);
std::memcpy(traceBuffer, vm::base(vm::cast(spurs->traceBuffer.addr()) & -0x4), 0x80);
ctxt->traceMsgCount = traceBuffer->count[ctxt->spuNum];
}
ctxt->traceBuffer = spurs->traceBuffer.addr() + (spurs->traceStartIndex[ctxt->spuNum] << 4);
ctxt->traceMaxCount = spurs->traceStartIndex[1] - spurs->traceStartIndex[0];
if (ctxt->traceBuffer == 0u)
{
ctxt->traceMsgCount = 0u;
}
}
if (notify)
{
auto spurs = spu._ptr<CellSpurs>(0x2D80 - offset32(&CellSpurs::wklState1));
sys_spu_thread_send_event(spu, spurs->spuPort, 2, 0);
}
}
// Restore state after executing the system workload
void spursSysServiceCleanupAfterSystemWorkload(spu_thread& spu, SpursKernelContext* ctxt)
{
u8 wklId;
bool do_return = false;
//vm::reservation_op(ctxt->spurs.ptr(&CellSpurs::wklState1).addr(), 128, [&]()
{
auto spurs = ctxt->spurs.get_ptr();
if (spurs->sysSrvPreemptWklId[ctxt->spuNum] == 0xFF)
{
do_return = true;
return;
}
wklId = spurs->sysSrvPreemptWklId[ctxt->spuNum];
spurs->sysSrvPreemptWklId[ctxt->spuNum] = 0xFF;
std::memcpy(spu._ptr<void>(0x2D80), spurs->wklState1, 128);
}//);
if (do_return) return;
spursSysServiceActivateWorkload(spu, ctxt);
//vm::reservation_op(vm::cast(ctxt->spurs.addr()), 128, [&]()
{
auto spurs = ctxt->spurs.get_ptr();
if (wklId >= CELL_SPURS_MAX_WORKLOAD)
{
spurs->wklCurrentContention[wklId & 0x0F] -= 0x10;
spurs->wklReadyCount1[wklId & 0x0F].raw() -= 1;
}
else
{
spurs->wklCurrentContention[wklId & 0x0F] -= 0x01;
spurs->wklIdleSpuCountOrReadyCount2[wklId & 0x0F].raw() -= 1;
}
std::memcpy(spu._ptr<void>(0x100), spurs, 128);
}//);
// Set the current workload id to the id of the pre-empted workload since cellSpursModulePutTrace
// uses the current worload id to determine the workload to which the trace belongs
auto wklIdSaved = ctxt->wklCurrentId;
ctxt->wklCurrentId = wklId;
// Trace - STOP: GUID
CellSpursTracePacket pkt{};
pkt.header.tag = CELL_SPURS_TRACE_TAG_STOP;
pkt.data.stop = SPURS_GUID_SYS_WKL;
cellSpursModulePutTrace(&pkt, ctxt->dmaTagId);
ctxt->wklCurrentId = wklIdSaved;
}
//----------------------------------------------------------------------------
// SPURS taskset policy module functions
//----------------------------------------------------------------------------
enum SpursTasksetRequest
{
SPURS_TASKSET_REQUEST_POLL_SIGNAL = -1,
SPURS_TASKSET_REQUEST_DESTROY_TASK = 0,
SPURS_TASKSET_REQUEST_YIELD_TASK = 1,
SPURS_TASKSET_REQUEST_WAIT_SIGNAL = 2,
SPURS_TASKSET_REQUEST_POLL = 3,
SPURS_TASKSET_REQUEST_WAIT_WKL_FLAG = 4,
SPURS_TASKSET_REQUEST_SELECT_TASK = 5,
SPURS_TASKSET_REQUEST_RECV_WKL_FLAG = 6,
};
// Taskset PM entry point
bool spursTasksetEntry(spu_thread& spu)
{
auto ctxt = spu._ptr<SpursTasksetContext>(0x2700);
auto kernelCtxt = spu._ptr<SpursKernelContext>(spu.gpr[3]._u32[3]);
auto arg = spu.gpr[4]._u64[1];
auto pollStatus = spu.gpr[5]._u32[3];
// Initialise memory and save args
memset(ctxt, 0, sizeof(*ctxt));
ctxt->taskset.set(arg);
memcpy(ctxt->moduleId, "SPURSTASK MODULE", sizeof(ctxt->moduleId));
ctxt->kernelMgmtAddr = spu.gpr[3]._u32[3];
ctxt->syscallAddr = CELL_SPURS_TASKSET_PM_SYSCALL_ADDR;
ctxt->spuNum = kernelCtxt->spuNum;
ctxt->dmaTagId = kernelCtxt->dmaTagId;
ctxt->taskId = 0xFFFFFFFF;
// Register SPURS takset policy module HLE functions
//spu.UnregisterHleFunctions(CELL_SPURS_TASKSET_PM_ENTRY_ADDR, 0x40000/*LS_BOTTOM*/);
//spu.RegisterHleFunction(CELL_SPURS_TASKSET_PM_ENTRY_ADDR, spursTasksetEntry);
//spu.RegisterHleFunction(ctxt->syscallAddr, spursTasksetSyscallEntry);
{
// Initialise the taskset policy module
spursTasksetInit(spu, pollStatus);
// Dispatch
spursTasksetDispatch(spu);
}
return false;
}
// Entry point into the Taskset PM for task syscalls
bool spursTasksetSyscallEntry(spu_thread& spu)
{
auto ctxt = spu._ptr<SpursTasksetContext>(0x2700);
{
// Save task context
ctxt->savedContextLr = spu.gpr[0];
ctxt->savedContextSp = spu.gpr[1];
for (auto i = 0; i < 48; i++)
{
ctxt->savedContextR80ToR127[i] = spu.gpr[80 + i];
}
// Handle the syscall
spu.gpr[3]._u32[3] = spursTasksetProcessSyscall(spu, spu.gpr[3]._u32[3], spu.gpr[4]._u32[3]);
// Resume the previously executing task if the syscall did not cause a context switch
fmt::throw_exception("Broken (TODO)");
//if (spu.m_is_branch == false) {
// spursTasksetResumeTask(spu);
//}
}
return false;
}
// Resume a task
void spursTasksetResumeTask(spu_thread& spu)
{
auto ctxt = spu._ptr<SpursTasksetContext>(0x2700);
// Restore task context
spu.gpr[0] = ctxt->savedContextLr;
spu.gpr[1] = ctxt->savedContextSp;
for (auto i = 0; i < 48; i++)
{
spu.gpr[80 + i] = ctxt->savedContextR80ToR127[i];
}
spu.pc = spu.gpr[0]._u32[3];
}
// Start a task
void spursTasksetStartTask(spu_thread& spu, CellSpursTaskArgument& taskArgs)
{
auto ctxt = spu._ptr<SpursTasksetContext>(0x2700);
auto taskset = spu._ptr<CellSpursTaskset>(0x2700);
spu.gpr[2].clear();
spu.gpr[3] = v128::from64r(taskArgs._u64[0], taskArgs._u64[1]);
spu.gpr[4]._u64[1] = taskset->args;
spu.gpr[4]._u64[0] = taskset->spurs.addr();
for (auto i = 5; i < 128; i++)
{
spu.gpr[i].clear();
}
spu.pc = ctxt->savedContextLr.value()._u32[3];
}
// Process a request and update the state of the taskset
s32 spursTasksetProcessRequest(spu_thread& spu, s32 request, u32* taskId, u32* isWaiting)
{
auto kernelCtxt = spu._ptr<SpursKernelContext>(0x100);
auto ctxt = spu._ptr<SpursTasksetContext>(0x2700);
s32 rc = CELL_OK;
s32 numNewlyReadyTasks = 0;
//vm::reservation_op(vm::cast(ctxt->taskset.addr()), 128, [&]()
{
auto taskset = ctxt->taskset;
v128 waiting = vm::_ref<v128>(ctxt->taskset.addr() + ::offset32(&CellSpursTaskset::waiting));
v128 running = vm::_ref<v128>(ctxt->taskset.addr() + ::offset32(&CellSpursTaskset::running));
v128 ready = vm::_ref<v128>(ctxt->taskset.addr() + ::offset32(&CellSpursTaskset::ready));
v128 pready = vm::_ref<v128>(ctxt->taskset.addr() + ::offset32(&CellSpursTaskset::pending_ready));
v128 enabled = vm::_ref<v128>(ctxt->taskset.addr() + ::offset32(&CellSpursTaskset::enabled));
v128 signalled = vm::_ref<v128>(ctxt->taskset.addr() + ::offset32(&CellSpursTaskset::signalled));
// Verify taskset state is valid
if ((waiting & running) != v128{} || (ready & pready) != v128{} ||
(gv_andn(enabled, running | ready | pready | signalled | waiting) != v128{}))
{
spu_log.error("Invalid taskset state");
spursHalt(spu);
}
// Find the number of tasks that have become ready since the last iteration
{
v128 newlyReadyTasks = gv_andn(ready, signalled | pready);
numNewlyReadyTasks = utils::popcnt128(newlyReadyTasks._u);
}
v128 readyButNotRunning;
u8 selectedTaskId;
v128 signalled0 = (signalled & (ready | pready));
v128 ready0 = (signalled | ready | pready);
u128 ctxtTaskIdMask = u128{1} << +(~ctxt->taskId & 127);
switch (request)
{
case SPURS_TASKSET_REQUEST_POLL_SIGNAL:
{
rc = signalled0._u & ctxtTaskIdMask ? 1 : 0;
signalled0._u &= ~ctxtTaskIdMask;
break;
}
case SPURS_TASKSET_REQUEST_DESTROY_TASK:
{
numNewlyReadyTasks--;
running._u &= ~ctxtTaskIdMask;
enabled._u &= ~ctxtTaskIdMask;
signalled0._u &= ~ctxtTaskIdMask;
ready0._u &= ~ctxtTaskIdMask;
break;
}
case SPURS_TASKSET_REQUEST_YIELD_TASK:
{
running._u &= ~ctxtTaskIdMask;
waiting._u |= ctxtTaskIdMask;
break;
}
case SPURS_TASKSET_REQUEST_WAIT_SIGNAL:
{
if (!(signalled0._u & ctxtTaskIdMask))
{
numNewlyReadyTasks--;
running._u &= ~ctxtTaskIdMask;
waiting._u |= ctxtTaskIdMask;
signalled0._u &= ~ctxtTaskIdMask;
ready0._u &= ~ctxtTaskIdMask;
}
break;
}
case SPURS_TASKSET_REQUEST_POLL:
{
readyButNotRunning = gv_andn(running, ready0);
if (taskset->wkl_flag_wait_task < CELL_SPURS_MAX_TASK)
{
readyButNotRunning._u &= ~(u128{1} << (~taskset->wkl_flag_wait_task & 127));
}
rc = readyButNotRunning._u ? 1 : 0;
break;
}
case SPURS_TASKSET_REQUEST_WAIT_WKL_FLAG:
{
if (taskset->wkl_flag_wait_task == 0x81)
{
// A workload flag is already pending so consume it
taskset->wkl_flag_wait_task = 0x80;
rc = 0;
}
else if (taskset->wkl_flag_wait_task == 0x80)
{
// No tasks are waiting for the workload flag. Mark this task as waiting for the workload flag.
taskset->wkl_flag_wait_task = ctxt->taskId;
running._u &= ~ctxtTaskIdMask;
waiting._u |= ctxtTaskIdMask;
rc = 1;
numNewlyReadyTasks--;
}
else
{
// Another task is already waiting for the workload signal
rc = CELL_SPURS_TASK_ERROR_BUSY;
}
break;
}
case SPURS_TASKSET_REQUEST_SELECT_TASK:
{
readyButNotRunning = gv_andn(running, ready0);
if (taskset->wkl_flag_wait_task < CELL_SPURS_MAX_TASK)
{
readyButNotRunning._u &= ~(u128{1} << (~taskset->wkl_flag_wait_task & 127));
}
// Select a task from the readyButNotRunning set to run. Start from the task after the last scheduled task to ensure fairness.
for (selectedTaskId = taskset->last_scheduled_task + 1; selectedTaskId < 128; selectedTaskId++)
{
if (readyButNotRunning._u & (u128{1} << (~selectedTaskId & 127)))
{
break;
}
}
if (selectedTaskId == 128)
{
for (selectedTaskId = 0; selectedTaskId < taskset->last_scheduled_task + 1; selectedTaskId++)
{
if (readyButNotRunning._u & (u128{1} << (~selectedTaskId & 127)))
{
break;
}
}
if (selectedTaskId == taskset->last_scheduled_task + 1)
{
selectedTaskId = CELL_SPURS_MAX_TASK;
}
}
*taskId = selectedTaskId;
if (selectedTaskId != CELL_SPURS_MAX_TASK)
{
const u128 selectedTaskIdMask = u128{1} << (~selectedTaskId & 127);
*isWaiting = waiting._u & selectedTaskIdMask ? 1 : 0;
taskset->last_scheduled_task = selectedTaskId;
running._u |= selectedTaskIdMask;
waiting._u &= ~selectedTaskIdMask;
}
else
{
*isWaiting = waiting._u & (u128{1} << 127) ? 1 : 0;
}
break;
}
case SPURS_TASKSET_REQUEST_RECV_WKL_FLAG:
{
if (taskset->wkl_flag_wait_task < CELL_SPURS_MAX_TASK)
{
// There is a task waiting for the workload flag
taskset->wkl_flag_wait_task = 0x80;
rc = 1;
numNewlyReadyTasks++;
}
else
{
// No tasks are waiting for the workload flag
taskset->wkl_flag_wait_task = 0x81;
rc = 0;
}
break;
}
default:
spu_log.error("Unknown taskset request");
spursHalt(spu);
}
vm::_ref<v128>(ctxt->taskset.addr() + ::offset32(&CellSpursTaskset::waiting)) = waiting;
vm::_ref<v128>(ctxt->taskset.addr() + ::offset32(&CellSpursTaskset::running)) = running;
vm::_ref<v128>(ctxt->taskset.addr() + ::offset32(&CellSpursTaskset::ready)) = ready;
vm::_ref<v128>(ctxt->taskset.addr() + ::offset32(&CellSpursTaskset::pending_ready)) = v128{};
vm::_ref<v128>(ctxt->taskset.addr() + ::offset32(&CellSpursTaskset::enabled)) = enabled;
vm::_ref<v128>(ctxt->taskset.addr() + ::offset32(&CellSpursTaskset::signalled)) = signalled;
std::memcpy(spu._ptr<void>(0x2700), spu._ptr<void>(0x100), 128); // Copy data
}//);
// Increment the ready count of the workload by the number of tasks that have become ready
if (numNewlyReadyTasks)
{
auto spurs = kernelCtxt->spurs;
vm::light_op(spurs->readyCount(kernelCtxt->wklCurrentId), [&](atomic_t<u8>& val)
{
val.fetch_op([&](u8& val)
{
const s32 _new = val + numNewlyReadyTasks;
val = static_cast<u8>(std::clamp<s32>(_new, 0, 0xFF));
});
});
}
return rc;
}
// Process pollStatus received from the SPURS kernel
void spursTasksetProcessPollStatus(spu_thread& spu, u32 pollStatus)
{
if (pollStatus & CELL_SPURS_MODULE_POLL_STATUS_FLAG)
{
spursTasksetProcessRequest(spu, SPURS_TASKSET_REQUEST_RECV_WKL_FLAG, nullptr, nullptr);
}
}
// Check execution rights
bool spursTasksetPollStatus(spu_thread& spu)
{
u32 pollStatus;
if (cellSpursModulePollStatus(spu, &pollStatus))
{
return true;
}
spursTasksetProcessPollStatus(spu, pollStatus);
return false;
}
// Exit the Taskset PM
void spursTasksetExit(spu_thread& spu)
{
auto ctxt = spu._ptr<SpursTasksetContext>(0x2700);
// Trace - STOP
CellSpursTracePacket pkt{};
pkt.header.tag = 0x54; // Its not clear what this tag means exactly but it seems similar to CELL_SPURS_TRACE_TAG_STOP
pkt.data.stop = SPURS_GUID_TASKSET_PM;
cellSpursModulePutTrace(&pkt, ctxt->dmaTagId);
// Not sure why this check exists. Perhaps to check for memory corruption.
if (memcmp(ctxt->moduleId, "SPURSTASK MODULE", 16) != 0)
{
spu_log.error("spursTasksetExit(): memory corruption");
spursHalt(spu);
}
cellSpursModuleExit(spu);
}
// Invoked when a task exits
void spursTasksetOnTaskExit(spu_thread& spu, u64 addr, u32 taskId, s32 exitCode, u64 args)
{
auto ctxt = spu._ptr<SpursTasksetContext>(0x2700);
std::memcpy(spu._ptr<void>(0x10000), vm::base(addr & -0x80), (addr & 0x7F) << 11);
spu.gpr[3]._u64[1] = ctxt->taskset.addr();
spu.gpr[4]._u32[3] = taskId;
spu.gpr[5]._u32[3] = exitCode;
spu.gpr[6]._u64[1] = args;
spu.fast_call(0x10000);
}
// Save the context of a task
s32 spursTasketSaveTaskContext(spu_thread& spu)
{
auto ctxt = spu._ptr<SpursTasksetContext>(0x2700);
auto taskInfo = spu._ptr<CellSpursTaskset::TaskInfo>(0x2780);
//spursDmaWaitForCompletion(spu, 0xFFFFFFFF);
if (taskInfo->context_save_storage_and_alloc_ls_blocks == 0u)
{
return CELL_SPURS_TASK_ERROR_STAT;
}
u32 allocLsBlocks = static_cast<u32>(taskInfo->context_save_storage_and_alloc_ls_blocks & 0x7F);
v128 ls_pattern = v128::from64r(taskInfo->ls_pattern._u64[0], taskInfo->ls_pattern._u64[1]);
const u32 lsBlocks = utils::popcnt128(ls_pattern._u);
if (lsBlocks > allocLsBlocks)
{
return CELL_SPURS_TASK_ERROR_STAT;
}
// Make sure the stack is area is specified in the ls pattern
for (auto i = (ctxt->savedContextSp.value()._u32[3]) >> 11; i < 128; i++)
{
if (!(ls_pattern._u & (u128{1} << (i ^ 127))))
{
return CELL_SPURS_TASK_ERROR_STAT;
}
}
// Get the processor context
v128 r;
spu.fpscr.Read(r);
ctxt->savedContextFpscr = r;
ctxt->savedSpuWriteEventMask = static_cast<u32>(spu.get_ch_value(SPU_RdEventMask));
ctxt->savedWriteTagGroupQueryMask = static_cast<u32>(spu.get_ch_value(MFC_RdTagMask));
// Store the processor context
const u32 contextSaveStorage = vm::cast(taskInfo->context_save_storage_and_alloc_ls_blocks & -0x80);
std::memcpy(vm::base(contextSaveStorage), spu._ptr<void>(0x2C80), 0x380);
// Save LS context
for (auto i = 6; i < 128; i++)
{
if (ls_pattern._u & (u128{1} << (i ^ 127)))
{
// TODO: Combine DMA requests for consecutive blocks into a single request
std::memcpy(vm::base(contextSaveStorage + 0x400 + ((i - 6) << 11)), spu._ptr<void>(CELL_SPURS_TASK_TOP + ((i - 6) << 11)), 0x800);
}
}
//spursDmaWaitForCompletion(spu, 1 << ctxt->dmaTagId);
return CELL_OK;
}
// Taskset dispatcher
void spursTasksetDispatch(spu_thread& spu)
{
const auto ctxt = spu._ptr<SpursTasksetContext>(0x2700);
const auto taskset = spu._ptr<CellSpursTaskset>(0x2700);
u32 taskId;
u32 isWaiting;
spursTasksetProcessRequest(spu, SPURS_TASKSET_REQUEST_SELECT_TASK, &taskId, &isWaiting);
if (taskId >= CELL_SPURS_MAX_TASK)
{
spursTasksetExit(spu);
return;
}
ctxt->taskId = taskId;
// DMA in the task info for the selected task
const auto taskInfo = spu._ptr<CellSpursTaskset::TaskInfo>(0x2780);
std::memcpy(taskInfo, &ctxt->taskset->task_info[taskId], sizeof(CellSpursTaskset::TaskInfo));
auto elfAddr = taskInfo->elf.addr().value();
taskInfo->elf.set(taskInfo->elf.addr() & 0xFFFFFFFFFFFFFFF8);
// Trace - Task: Incident=dispatch
CellSpursTracePacket pkt{};
pkt.header.tag = CELL_SPURS_TRACE_TAG_TASK;
pkt.data.task.incident = CELL_SPURS_TRACE_TASK_DISPATCH;
pkt.data.task.taskId = taskId;
cellSpursModulePutTrace(&pkt, CELL_SPURS_KERNEL_DMA_TAG_ID);
if (isWaiting == 0)
{
// If we reach here it means that the task is being started and not being resumed
std::memset(spu._ptr<void>(CELL_SPURS_TASK_TOP), 0, CELL_SPURS_TASK_BOTTOM - CELL_SPURS_TASK_TOP);
ctxt->guidAddr = CELL_SPURS_TASK_TOP;
u32 entryPoint;
u32 lowestLoadAddr;
if (spursTasksetLoadElf(spu, &entryPoint, &lowestLoadAddr, taskInfo->elf.addr(), false) != CELL_OK)
{
spu_log.error("spursTaskLoadElf() failed");
spursHalt(spu);
}
//spursDmaWaitForCompletion(spu, 1 << ctxt->dmaTagId);
ctxt->savedContextLr = v128::from32r(entryPoint);
ctxt->guidAddr = lowestLoadAddr;
ctxt->tasksetMgmtAddr = 0x2700;
ctxt->x2FC0 = 0;
ctxt->taskExitCode = isWaiting;
ctxt->x2FD4 = elfAddr & 5; // TODO: Figure this out
if ((elfAddr & 5) == 1)
{
std::memcpy(spu._ptr<void>(0x2FC0), &vm::_ptr<CellSpursTaskset2>(vm::cast(ctxt->taskset.addr()))->task_exit_code[taskId], 0x10);
}
// Trace - GUID
pkt = {};
pkt.header.tag = CELL_SPURS_TRACE_TAG_GUID;
pkt.data.guid = 0; // TODO: Put GUID of taskId here
cellSpursModulePutTrace(&pkt, 0x1F);
if (elfAddr & 2)
{
// TODO: Figure this out
spu_runtime::g_escape(&spu);
}
spursTasksetStartTask(spu, taskInfo->args);
}
else
{
if (taskset->enable_clear_ls)
{
std::memset(spu._ptr<void>(CELL_SPURS_TASK_TOP), 0, CELL_SPURS_TASK_BOTTOM - CELL_SPURS_TASK_TOP);
}
// If the entire LS is saved then there is no need to load the ELF as it will be be saved in the context save area as well
v128 ls_pattern = v128::from64r(taskInfo->ls_pattern._u64[0], taskInfo->ls_pattern._u64[1]);
if (ls_pattern != v128::from64r(0x03FFFFFFFFFFFFFFull, 0xFFFFFFFFFFFFFFFFull))
{
// Load the ELF
u32 entryPoint;
if (spursTasksetLoadElf(spu, &entryPoint, nullptr, taskInfo->elf.addr(), true) != CELL_OK)
{
spu_log.error("spursTasksetLoadElf() failed");
spursHalt(spu);
}
}
// Load saved context from main memory to LS
const u32 contextSaveStorage = vm::cast(taskInfo->context_save_storage_and_alloc_ls_blocks & -0x80);
std::memcpy(spu._ptr<void>(0x2C80), vm::base(contextSaveStorage), 0x380);
for (auto i = 6; i < 128; i++)
{
if (ls_pattern._u & (u128{1} << (i ^ 127)))
{
// TODO: Combine DMA requests for consecutive blocks into a single request
std::memcpy(spu._ptr<void>(CELL_SPURS_TASK_TOP + ((i - 6) << 11)), vm::base(contextSaveStorage + 0x400 + ((i - 6) << 11)), 0x800);
}
}
//spursDmaWaitForCompletion(spu, 1 << ctxt->dmaTagId);
// Restore saved registers
spu.fpscr.Write(ctxt->savedContextFpscr.value());
spu.set_ch_value(MFC_WrTagMask, ctxt->savedWriteTagGroupQueryMask);
spu.set_ch_value(SPU_WrEventMask, ctxt->savedSpuWriteEventMask);
// Trace - GUID
pkt = {};
pkt.header.tag = CELL_SPURS_TRACE_TAG_GUID;
pkt.data.guid = 0; // TODO: Put GUID of taskId here
cellSpursModulePutTrace(&pkt, 0x1F);
if (elfAddr & 2)
{
// TODO: Figure this out
spu_runtime::g_escape(&spu);
}
spu.gpr[3].clear();
spursTasksetResumeTask(spu);
}
}
// Process a syscall request
s32 spursTasksetProcessSyscall(spu_thread& spu, u32 syscallNum, u32 args)
{
auto ctxt = spu._ptr<SpursTasksetContext>(0x2700);
auto taskset = spu._ptr<CellSpursTaskset>(0x2700);
// If the 0x10 bit is set in syscallNum then its the 2nd version of the
// syscall (e.g. cellSpursYield2 instead of cellSpursYield) and so don't wait
// for DMA completion
if ((syscallNum & 0x10) == 0)
{
//spursDmaWaitForCompletion(spu, 0xFFFFFFFF);
}
s32 rc = 0;
u32 incident = 0;
switch (syscallNum & 0x0F)
{
case CELL_SPURS_TASK_SYSCALL_EXIT:
if (ctxt->x2FD4 == 4u || (ctxt->x2FC0 & 0xffffffffu) != 0u)
{ // TODO: Figure this out
if (ctxt->x2FD4 != 4u)
{
spursTasksetProcessRequest(spu, SPURS_TASKSET_REQUEST_DESTROY_TASK, nullptr, nullptr);
}
const u64 addr = ctxt->x2FD4 == 4u ? +taskset->x78 : +ctxt->x2FC0;
const u64 args = ctxt->x2FD4 == 4u ? 0 : +ctxt->x2FC8;
spursTasksetOnTaskExit(spu, addr, ctxt->taskId, ctxt->taskExitCode, args);
}
incident = CELL_SPURS_TRACE_TASK_EXIT;
break;
case CELL_SPURS_TASK_SYSCALL_YIELD:
if (spursTasksetPollStatus(spu) || spursTasksetProcessRequest(spu, SPURS_TASKSET_REQUEST_POLL, nullptr, nullptr))
{
// If we reach here then it means that either another task can be scheduled or another workload can be scheduled
// Save the context of the current task
rc = spursTasketSaveTaskContext(spu);
if (rc == CELL_OK)
{
spursTasksetProcessRequest(spu, SPURS_TASKSET_REQUEST_YIELD_TASK, nullptr, nullptr);
incident = CELL_SPURS_TRACE_TASK_YIELD;
}
}
break;
case CELL_SPURS_TASK_SYSCALL_WAIT_SIGNAL:
if (spursTasksetProcessRequest(spu, SPURS_TASKSET_REQUEST_POLL_SIGNAL, nullptr, nullptr) == 0)
{
rc = spursTasketSaveTaskContext(spu);
if (rc == CELL_OK)
{
if (spursTasksetProcessRequest(spu, SPURS_TASKSET_REQUEST_WAIT_SIGNAL, nullptr, nullptr) == 0)
{
incident = CELL_SPURS_TRACE_TASK_WAIT;
}
}
}
break;
case CELL_SPURS_TASK_SYSCALL_POLL:
rc = spursTasksetPollStatus(spu) ? CELL_SPURS_TASK_POLL_FOUND_WORKLOAD : 0;
rc |= spursTasksetProcessRequest(spu, SPURS_TASKSET_REQUEST_POLL, nullptr, nullptr) ? CELL_SPURS_TASK_POLL_FOUND_TASK : 0;
break;
case CELL_SPURS_TASK_SYSCALL_RECV_WKL_FLAG:
if (args == 0)
{ // TODO: Figure this out
spu_log.error("args == 0");
//spursHalt(spu);
}
if (spursTasksetPollStatus(spu) || spursTasksetProcessRequest(spu, SPURS_TASKSET_REQUEST_WAIT_WKL_FLAG, nullptr, nullptr) != 1)
{
rc = spursTasketSaveTaskContext(spu);
if (rc == CELL_OK)
{
incident = CELL_SPURS_TRACE_TASK_WAIT;
}
}
break;
default:
rc = CELL_SPURS_TASK_ERROR_NOSYS;
break;
}
if (incident)
{
// Trace - TASK
CellSpursTracePacket pkt{};
pkt.header.tag = CELL_SPURS_TRACE_TAG_TASK;
pkt.data.task.incident = incident;
pkt.data.task.taskId = ctxt->taskId;
cellSpursModulePutTrace(&pkt, ctxt->dmaTagId);
// Clear the GUID of the task
std::memset(spu._ptr<void>(ctxt->guidAddr), 0, 0x10);
if (spursTasksetPollStatus(spu))
{
spursTasksetExit(spu);
}
else
{
spursTasksetDispatch(spu);
}
}
return rc;
}
// Initialise the Taskset PM
void spursTasksetInit(spu_thread& spu, u32 pollStatus)
{
auto ctxt = spu._ptr<SpursTasksetContext>(0x2700);
auto kernelCtxt = spu._ptr<SpursKernelContext>(0x100);
kernelCtxt->moduleId[0] = 'T';
kernelCtxt->moduleId[1] = 'K';
// Trace - START: Module='TKST'
CellSpursTracePacket pkt{};
pkt.header.tag = 0x52; // Its not clear what this tag means exactly but it seems similar to CELL_SPURS_TRACE_TAG_START
std::memcpy(pkt.data.start._module, "TKST", 4);
pkt.data.start.level = 2;
pkt.data.start.ls = 0xA00 >> 2;
cellSpursModulePutTrace(&pkt, ctxt->dmaTagId);
spursTasksetProcessPollStatus(spu, pollStatus);
}
// Load an ELF
s32 spursTasksetLoadElf(spu_thread& spu, u32* entryPoint, u32* lowestLoadAddr, u64 elfAddr, bool skipWriteableSegments)
{
if (elfAddr == 0 || (elfAddr & 0x0F) != 0)
{
return CELL_SPURS_TASK_ERROR_INVAL;
}
const spu_exec_object obj(fs::file(vm::base(vm::cast(elfAddr)), u32(0 - elfAddr)));
if (obj != elf_error::ok)
{
return CELL_SPURS_TASK_ERROR_NOEXEC;
}
u32 _lowestLoadAddr = CELL_SPURS_TASK_BOTTOM;
for (const auto& prog : obj.progs)
{
if (prog.p_paddr >= CELL_SPURS_TASK_BOTTOM)
{
break;
}
if (prog.p_type == 1u /* PT_LOAD */)
{
if (skipWriteableSegments == false || (prog.p_flags & 2u /*PF_W*/ ) == 0u)
{
if (prog.p_vaddr < CELL_SPURS_TASK_TOP || prog.p_vaddr + prog.p_memsz > CELL_SPURS_TASK_BOTTOM)
{
return CELL_SPURS_TASK_ERROR_FAULT;
}
_lowestLoadAddr > prog.p_vaddr ? _lowestLoadAddr = prog.p_vaddr : _lowestLoadAddr;
}
}
}
for (const auto& prog : obj.progs)
{
if (prog.p_paddr >= CELL_SPURS_TASK_BOTTOM) // ???
{
break;
}
if (prog.p_type == 1u)
{
if (skipWriteableSegments == false || (prog.p_flags & 2u) == 0u)
{
std::memcpy(spu._ptr<void>(prog.p_vaddr), prog.bin.data(), prog.p_filesz);
}
}
}
*entryPoint = obj.header.e_entry;
if (lowestLoadAddr) *lowestLoadAddr = _lowestLoadAddr;
return CELL_OK;
}
//----------------------------------------------------------------------------
// SPURS taskset policy module functions
//----------------------------------------------------------------------------
bool spursJobChainEntry(spu_thread& spu)
{
//const auto ctxt = spu._ptr<SpursJobChainContext>(0x4a00);
//auto kernelCtxt = spu._ptr<SpursKernelContext>(spu.gpr[3]._u32[3]);
//auto arg = spu.gpr[4]._u64[1];
//auto pollStatus = spu.gpr[5]._u32[3];
// TODO
return false;
}
void spursJobchainPopUrgentCommand(spu_thread& spu)
{
const auto ctxt = spu._ptr<SpursJobChainContext>(0x4a00);
const auto jc = vm::unsafe_ptr_cast<CellSpursJobChain_x00>(+ctxt->jobChain);
const bool alterQueue = ctxt->unkFlag0;
vm::reservation_op(spu, jc, [&](CellSpursJobChain_x00& op)
{
const auto ls = reinterpret_cast<CellSpursJobChain_x00*>(ctxt->tempAreaJobChain);
struct alignas(16) { v128 first, second; } data;
std::memcpy(&data, &op.urgentCmds, sizeof(op.urgentCmds));
if (!alterQueue)
{
// Read the queue, do not modify it
}
else
{
// Move FIFO queue contents one command up
data.first._u64[0] = data.first._u64[1];
data.first._u64[1] = data.second._u64[0];
data.second._u64[0] = data.second._u64[1];
data.second._u64[1] = 0;
}
// Writeback
std::memcpy(&ls->urgentCmds, &data, sizeof(op.urgentCmds));
std::memcpy(&ls->isHalted, &op.unk0[0], 1); // Maybe intended to set it to false
ls->unk5 = 0;
ls->sizeJobDescriptor = op.maxGrabbedJob;
std::memcpy(&op, ls, 128);
});
}
| 65,636
|
C++
|
.cpp
| 1,802
| 33.239179
| 183
| 0.693348
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| true
| false
| false
| true
| false
| false
|
5,289
|
sceNpPlus.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/sceNpPlus.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
LOG_CHANNEL(sceNpPlus);
error_code sceNpManagerIsSP()
{
sceNpPlus.warning("sceNpManagerIsSP()");
// TODO seems to be cut to 1 byte by pshome likely a bool but may be more.
return not_an_error(1);
}
DECLARE(ppu_module_manager::sceNpPlus)("sceNpPlus", []()
{
REG_FUNC(sceNpPlus, sceNpManagerIsSP);
});
| 360
|
C++
|
.cpp
| 13
| 26.076923
| 75
| 0.752187
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
5,290
|
libsnd3.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/libsnd3.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
#include "libsnd3.h"
LOG_CHANNEL(libsnd3);
template<>
void fmt_class_string<CellSnd3Error>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_SND3_ERROR_PARAM);
STR_CASE(CELL_SND3_ERROR_CREATE_MUTEX);
STR_CASE(CELL_SND3_ERROR_SYNTH);
STR_CASE(CELL_SND3_ERROR_ALREADY);
STR_CASE(CELL_SND3_ERROR_NOTINIT);
STR_CASE(CELL_SND3_ERROR_SMFFULL);
STR_CASE(CELL_SND3_ERROR_HD3ID);
STR_CASE(CELL_SND3_ERROR_SMF);
STR_CASE(CELL_SND3_ERROR_SMFCTX);
STR_CASE(CELL_SND3_ERROR_FORMAT);
STR_CASE(CELL_SND3_ERROR_SMFID);
STR_CASE(CELL_SND3_ERROR_SOUNDDATAFULL);
STR_CASE(CELL_SND3_ERROR_VOICENUM);
STR_CASE(CELL_SND3_ERROR_RESERVEDVOICE);
STR_CASE(CELL_SND3_ERROR_REQUESTQUEFULL);
STR_CASE(CELL_SND3_ERROR_OUTPUTMODE);
}
return unknown;
});
}
// Temporarily
#ifndef _MSC_VER
#pragma GCC diagnostic ignored "-Wunused-parameter"
#endif
error_code cellSnd3Init(u32 maxVoice, u32 samples, vm::ptr<CellSnd3RequestQueueCtx> queue)
{
UNIMPLEMENTED_FUNC(libsnd3);
return CELL_OK;
}
error_code cellSnd3Exit()
{
UNIMPLEMENTED_FUNC(libsnd3);
return CELL_OK;
}
u16 cellSnd3Note2Pitch(u16 center_note, u16 center_fine, u16 note, s16 fine)
{
libsnd3.todo("cellSnd3Note2Pitch()");
return 0;
}
u16 cellSnd3Pitch2Note(u16 center_note, u16 center_fine, u16 pitch)
{
libsnd3.todo("cellSnd3Pitch2Note()");
return 0;
}
error_code cellSnd3SetOutputMode(u32 mode)
{
UNIMPLEMENTED_FUNC(libsnd3);
return CELL_OK;
}
error_code cellSnd3Synthesis(vm::ptr<f32> pOutL, vm::ptr<f32> pOutR)
{
UNIMPLEMENTED_FUNC(libsnd3);
return CELL_OK;
}
error_code cellSnd3SynthesisEx(vm::ptr<f32> pOutL, vm::ptr<f32> pOutR, vm::ptr<f32> pOutRL, vm::ptr<f32> pOutRR)
{
UNIMPLEMENTED_FUNC(libsnd3);
return CELL_OK;
}
error_code cellSnd3BindSoundData(vm::ptr<CellSnd3DataCtx> snd3Ctx, vm::ptr<void> hd3, u32 synthMemOffset)
{
UNIMPLEMENTED_FUNC(libsnd3);
return CELL_OK;
}
error_code cellSnd3UnbindSoundData(u32 hd3ID)
{
UNIMPLEMENTED_FUNC(libsnd3);
return CELL_OK;
}
error_code cellSnd3NoteOnByTone(u32 hd3ID, u32 toneIndex, u32 note, u32 keyOnID, vm::ptr<CellSnd3KeyOnParam> keyOnParam)
{
libsnd3.todo("cellSnd3NoteOnByTone()");
return CELL_OK;
}
error_code cellSnd3KeyOnByTone(u32 hd3ID, u32 toneIndex, u32 pitch, u32 keyOnID, vm::ptr<CellSnd3KeyOnParam> keyOnParam)
{
libsnd3.todo("cellSnd3KeyOnByTone()");
return CELL_OK;
}
error_code cellSnd3VoiceNoteOnByTone(u32 hd3ID, u32 voiceNum, u32 toneIndex, u32 note, u32 keyOnID, vm::ptr<CellSnd3KeyOnParam> keyOnParam)
{
libsnd3.todo("cellSnd3VoiceNoteOnByTone()");
return CELL_OK;
}
error_code cellSnd3VoiceKeyOnByTone(u32 hd3ID, u32 voiceNum, u32 toneIndex, u32 pitch, u32 keyOnID, vm::ptr<CellSnd3KeyOnParam> keyOnParam)
{
libsnd3.todo("cellSnd3VoiceKeyOnByTone()");
return CELL_OK;
}
error_code cellSnd3VoiceSetReserveMode(u32 voiceNum, u32 reserveMode)
{
UNIMPLEMENTED_FUNC(libsnd3);
return CELL_OK;
}
error_code cellSnd3VoiceSetSustainHold(u32 voiceNum, u32 sustainHold)
{
UNIMPLEMENTED_FUNC(libsnd3);
return CELL_OK;
}
error_code cellSnd3VoiceKeyOff(u32 voiceNum)
{
UNIMPLEMENTED_FUNC(libsnd3);
return CELL_OK;
}
error_code cellSnd3VoiceSetPitch(u32 voiceNum, s32 addPitch)
{
UNIMPLEMENTED_FUNC(libsnd3);
return CELL_OK;
}
error_code cellSnd3VoiceSetVelocity(u32 voiceNum, u32 velocity)
{
UNIMPLEMENTED_FUNC(libsnd3);
return CELL_OK;
}
error_code cellSnd3VoiceSetPanpot(u32 voiceNum, u32 panpot)
{
UNIMPLEMENTED_FUNC(libsnd3);
return CELL_OK;
}
error_code cellSnd3VoiceSetPanpotEx(u32 voiceNum, u32 panpotEx)
{
UNIMPLEMENTED_FUNC(libsnd3);
return CELL_OK;
}
error_code cellSnd3VoiceSetPitchBend(u32 voiceNum, u32 bendValue)
{
UNIMPLEMENTED_FUNC(libsnd3);
return CELL_OK;
}
error_code cellSnd3VoiceAllKeyOff()
{
UNIMPLEMENTED_FUNC(libsnd3);
return CELL_OK;
}
error_code cellSnd3VoiceGetEnvelope(u32 voiceNum)
{
UNIMPLEMENTED_FUNC(libsnd3);
return CELL_OK;
}
error_code cellSnd3VoiceGetStatus(u32 voiceNum)
{
libsnd3.todo("cellSnd3VoiceGetStatus()");
return CELL_OK;
}
u32 cellSnd3KeyOffByID(u32 keyOnID)
{
UNIMPLEMENTED_FUNC(libsnd3);
return CELL_OK;
}
error_code cellSnd3GetVoice(u32 midiChannel, u32 keyOnID, vm::ptr<CellSnd3VoiceBitCtx> voiceBit)
{
UNIMPLEMENTED_FUNC(libsnd3);
return CELL_OK;
}
error_code cellSnd3GetVoiceByID(u32 ID, vm::ptr<CellSnd3VoiceBitCtx> voiceBit)
{
UNIMPLEMENTED_FUNC(libsnd3);
return CELL_OK;
}
error_code cellSnd3NoteOn(u32 hd3ID, u32 midiChannel, u32 midiProgram, u32 midiNote, u32 sustain, vm::ptr<CellSnd3KeyOnParam> keyOnParam, u32 keyOnID)
{
UNIMPLEMENTED_FUNC(libsnd3);
return CELL_OK;
}
error_code cellSnd3NoteOff(u32 midiChannel, u32 midiNote, u32 keyOnID)
{
UNIMPLEMENTED_FUNC(libsnd3);
return CELL_OK;
}
error_code cellSnd3SetSustainHold(u32 midiChannel, u32 sustainHold, u32 keyOnID)
{
UNIMPLEMENTED_FUNC(libsnd3);
return CELL_OK;
}
error_code cellSnd3SetEffectType(u16 effectType, s16 returnVol, u16 delay, u16 feedback)
{
UNIMPLEMENTED_FUNC(libsnd3);
return CELL_OK;
}
error_code cellSnd3SMFBind(vm::ptr<CellSnd3SmfCtx> smfCtx, vm::ptr<void> smf, u32 hd3ID)
{
libsnd3.todo("cellSnd3SMFBind()");
return CELL_OK;
}
error_code cellSnd3SMFUnbind(u32 smfID)
{
libsnd3.todo("cellSnd3SMFUnbind()");
return CELL_OK;
}
error_code cellSnd3SMFPlay(u32 smfID, u32 playVelocity, u32 playPan, u32 playCount)
{
UNIMPLEMENTED_FUNC(libsnd3);
return CELL_OK;
}
error_code cellSnd3SMFPlayEx(u32 smfID, u32 playVelocity, u32 playPan, u32 playPanEx, u32 playCount)
{
UNIMPLEMENTED_FUNC(libsnd3);
return CELL_OK;
}
error_code cellSnd3SMFPause(u32 smfID)
{
UNIMPLEMENTED_FUNC(libsnd3);
return CELL_OK;
}
error_code cellSnd3SMFResume(u32 smfID)
{
UNIMPLEMENTED_FUNC(libsnd3);
return CELL_OK;
}
error_code cellSnd3SMFStop(u32 smfID)
{
UNIMPLEMENTED_FUNC(libsnd3);
return CELL_OK;
}
error_code cellSnd3SMFAddTempo(u32 smfID, s32 addTempo)
{
UNIMPLEMENTED_FUNC(libsnd3);
return CELL_OK;
}
error_code cellSnd3SMFGetTempo(u32 smfID)
{
libsnd3.todo("cellSnd3SMFGetTempo()");
return CELL_OK;
}
error_code cellSnd3SMFSetPlayVelocity(u32 smfID, u32 playVelocity)
{
UNIMPLEMENTED_FUNC(libsnd3);
return CELL_OK;
}
error_code cellSnd3SMFGetPlayVelocity(u32 smfID)
{
libsnd3.todo("cellSnd3SMFGetPlayVelocity()");
return CELL_OK;
}
error_code cellSnd3SMFSetPlayPanpot(u32 smfID, u32 playPanpot)
{
UNIMPLEMENTED_FUNC(libsnd3);
return CELL_OK;
}
error_code cellSnd3SMFSetPlayPanpotEx(u32 smfID, u32 playPanpotEx)
{
UNIMPLEMENTED_FUNC(libsnd3);
return CELL_OK;
}
error_code cellSnd3SMFGetPlayPanpot(u32 smfID)
{
libsnd3.todo("cellSnd3SMFGetPlayPanpot()");
return CELL_OK;
}
error_code cellSnd3SMFGetPlayPanpotEx(u32 smfID)
{
libsnd3.todo("cellSnd3SMFGetPlayPanpotEx()");
return CELL_OK;
}
error_code cellSnd3SMFGetPlayStatus(u32 smfID)
{
libsnd3.todo("cellSnd3SMFGetPlayStatus()");
return CELL_OK;
}
error_code cellSnd3SMFSetPlayChannel(u32 smfID, u32 playChannelBit)
{
UNIMPLEMENTED_FUNC(libsnd3);
return CELL_OK;
}
error_code cellSnd3SMFGetPlayChannel(u32 smfID, vm::ptr<u32> playChannelBit)
{
libsnd3.todo("cellSnd3SMFGetPlayChannel()");
return CELL_OK;
}
error_code cellSnd3SMFGetKeyOnID(u32 smfID, u32 midiChannel, vm::ptr<u32> keyOnID)
{
UNIMPLEMENTED_FUNC(libsnd3);
return CELL_OK;
}
DECLARE(ppu_module_manager::libsnd3)("libsnd3", []()
{
REG_FUNC(libsnd3, cellSnd3Init);
REG_FUNC(libsnd3, cellSnd3Exit);
REG_FUNC(libsnd3, cellSnd3Note2Pitch);
REG_FUNC(libsnd3, cellSnd3Pitch2Note);
REG_FUNC(libsnd3, cellSnd3SetOutputMode);
REG_FUNC(libsnd3, cellSnd3Synthesis);
REG_FUNC(libsnd3, cellSnd3SynthesisEx);
REG_FUNC(libsnd3, cellSnd3BindSoundData);
REG_FUNC(libsnd3, cellSnd3UnbindSoundData);
REG_FUNC(libsnd3, cellSnd3NoteOnByTone);
REG_FUNC(libsnd3, cellSnd3KeyOnByTone);
REG_FUNC(libsnd3, cellSnd3VoiceNoteOnByTone);
REG_FUNC(libsnd3, cellSnd3VoiceKeyOnByTone);
REG_FUNC(libsnd3, cellSnd3VoiceSetReserveMode);
REG_FUNC(libsnd3, cellSnd3VoiceSetSustainHold);
REG_FUNC(libsnd3, cellSnd3VoiceKeyOff);
REG_FUNC(libsnd3, cellSnd3VoiceSetPitch);
REG_FUNC(libsnd3, cellSnd3VoiceSetVelocity);
REG_FUNC(libsnd3, cellSnd3VoiceSetPanpot);
REG_FUNC(libsnd3, cellSnd3VoiceSetPanpotEx);
REG_FUNC(libsnd3, cellSnd3VoiceSetPitchBend);
REG_FUNC(libsnd3, cellSnd3VoiceAllKeyOff);
REG_FUNC(libsnd3, cellSnd3VoiceGetEnvelope);
REG_FUNC(libsnd3, cellSnd3VoiceGetStatus);
REG_FUNC(libsnd3, cellSnd3KeyOffByID);
REG_FUNC(libsnd3, cellSnd3GetVoice);
REG_FUNC(libsnd3, cellSnd3GetVoiceByID);
REG_FUNC(libsnd3, cellSnd3NoteOn);
REG_FUNC(libsnd3, cellSnd3NoteOff);
REG_FUNC(libsnd3, cellSnd3SetSustainHold);
REG_FUNC(libsnd3, cellSnd3SetEffectType);
REG_FUNC(libsnd3, cellSnd3SMFBind);
REG_FUNC(libsnd3, cellSnd3SMFUnbind);
REG_FUNC(libsnd3, cellSnd3SMFPlay);
REG_FUNC(libsnd3, cellSnd3SMFPlayEx);
REG_FUNC(libsnd3, cellSnd3SMFPause);
REG_FUNC(libsnd3, cellSnd3SMFResume);
REG_FUNC(libsnd3, cellSnd3SMFStop);
REG_FUNC(libsnd3, cellSnd3SMFAddTempo);
REG_FUNC(libsnd3, cellSnd3SMFGetTempo);
REG_FUNC(libsnd3, cellSnd3SMFSetPlayVelocity);
REG_FUNC(libsnd3, cellSnd3SMFGetPlayVelocity);
REG_FUNC(libsnd3, cellSnd3SMFSetPlayPanpot);
REG_FUNC(libsnd3, cellSnd3SMFSetPlayPanpotEx);
REG_FUNC(libsnd3, cellSnd3SMFGetPlayPanpot);
REG_FUNC(libsnd3, cellSnd3SMFGetPlayPanpotEx);
REG_FUNC(libsnd3, cellSnd3SMFGetPlayStatus);
REG_FUNC(libsnd3, cellSnd3SMFSetPlayChannel);
REG_FUNC(libsnd3, cellSnd3SMFGetPlayChannel);
REG_FUNC(libsnd3, cellSnd3SMFGetKeyOnID);
});
| 9,499
|
C++
|
.cpp
| 338
| 26.316568
| 150
| 0.80547
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| true
| false
| false
| true
| false
| false
|
5,291
|
cellAvconfExt.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellAvconfExt.cpp
|
#include "stdafx.h"
#include "Emu/system_config.h"
#include "Emu/Cell/PPUModule.h"
#include "Emu/IdManager.h"
#include "Emu/RSX/rsx_utils.h"
#include "Utilities/StrUtil.h"
#include "cellMic.h"
#include "cellAudioIn.h"
#include "cellAudioOut.h"
#include "cellVideoOut.h"
#include <optional>
LOG_CHANNEL(cellAvconfExt);
template<>
void fmt_class_string<CellAudioInError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_AUDIO_IN_ERROR_NOT_IMPLEMENTED);
STR_CASE(CELL_AUDIO_IN_ERROR_ILLEGAL_CONFIGURATION);
STR_CASE(CELL_AUDIO_IN_ERROR_ILLEGAL_PARAMETER);
STR_CASE(CELL_AUDIO_IN_ERROR_PARAMETER_OUT_OF_RANGE);
STR_CASE(CELL_AUDIO_IN_ERROR_DEVICE_NOT_FOUND);
STR_CASE(CELL_AUDIO_IN_ERROR_UNSUPPORTED_AUDIO_IN);
STR_CASE(CELL_AUDIO_IN_ERROR_UNSUPPORTED_SOUND_MODE);
STR_CASE(CELL_AUDIO_IN_ERROR_CONDITION_BUSY);
}
return unknown;
});
}
struct avconf_manager
{
shared_mutex mutex;
std::vector<CellAudioInDeviceInfo> devices;
CellAudioInDeviceMode inDeviceMode = CELL_AUDIO_IN_SINGLE_DEVICE_MODE; // TODO: use somewhere
void copy_device_info(u32 num, vm::ptr<CellAudioInDeviceInfo> info) const;
std::optional<CellAudioInDeviceInfo> get_device_info(vm::cptr<char> name) const;
avconf_manager();
avconf_manager(const avconf_manager&) = delete;
avconf_manager& operator=(const avconf_manager&) = delete;
};
avconf_manager::avconf_manager()
{
u32 curindex = 0;
const std::vector<std::string> mic_list = fmt::split(g_cfg.audio.microphone_devices.to_string(), {"@@@"});
if (!mic_list.empty())
{
switch (g_cfg.audio.microphone_type)
{
case microphone_handler::standard:
for (u32 index = 0; index < mic_list.size(); index++)
{
devices.emplace_back();
devices[curindex].portType = CELL_AUDIO_IN_PORT_USB;
devices[curindex].availableModeCount = 1;
devices[curindex].state = CELL_AUDIO_IN_DEVICE_STATE_AVAILABLE;
devices[curindex].deviceId = 0xE11CC0DE + curindex;
devices[curindex].type = 0xC0DEE11C;
devices[curindex].availableModes[0].type = CELL_AUDIO_IN_CODING_TYPE_LPCM;
devices[curindex].availableModes[0].channel = CELL_AUDIO_IN_CHNUM_2;
devices[curindex].availableModes[0].fs = CELL_AUDIO_IN_FS_8KHZ | CELL_AUDIO_IN_FS_12KHZ | CELL_AUDIO_IN_FS_16KHZ | CELL_AUDIO_IN_FS_24KHZ | CELL_AUDIO_IN_FS_32KHZ | CELL_AUDIO_IN_FS_48KHZ;
devices[curindex].deviceNumber = curindex;
strcpy_trunc(devices[curindex].name, mic_list[index]);
curindex++;
}
break;
case microphone_handler::real_singstar:
case microphone_handler::singstar:
// Only one device for singstar device
devices.emplace_back();
devices[curindex].portType = CELL_AUDIO_IN_PORT_USB;
devices[curindex].availableModeCount = 1;
devices[curindex].state = CELL_AUDIO_IN_DEVICE_STATE_AVAILABLE;
devices[curindex].deviceId = 0x00000001;
devices[curindex].type = 0x14150000;
devices[curindex].availableModes[0].type = CELL_AUDIO_IN_CODING_TYPE_LPCM;
devices[curindex].availableModes[0].channel = CELL_AUDIO_IN_CHNUM_2;
devices[curindex].availableModes[0].fs = CELL_AUDIO_IN_FS_8KHZ | CELL_AUDIO_IN_FS_12KHZ | CELL_AUDIO_IN_FS_16KHZ | CELL_AUDIO_IN_FS_24KHZ | CELL_AUDIO_IN_FS_32KHZ | CELL_AUDIO_IN_FS_48KHZ;
devices[curindex].deviceNumber = curindex;
strcpy_trunc(devices[curindex].name, mic_list[0]);
curindex++;
break;
case microphone_handler::rocksmith:
devices.emplace_back();
devices[curindex].portType = CELL_AUDIO_IN_PORT_USB;
devices[curindex].availableModeCount = 1;
devices[curindex].state = CELL_AUDIO_IN_DEVICE_STATE_AVAILABLE;
devices[curindex].deviceId = 0x12BA00FF; // Specific to rocksmith usb input
devices[curindex].type = 0xC0DE73C4;
devices[curindex].availableModes[0].type = CELL_AUDIO_IN_CODING_TYPE_LPCM;
devices[curindex].availableModes[0].channel = CELL_AUDIO_IN_CHNUM_1;
devices[curindex].availableModes[0].fs = CELL_AUDIO_IN_FS_8KHZ | CELL_AUDIO_IN_FS_12KHZ | CELL_AUDIO_IN_FS_16KHZ | CELL_AUDIO_IN_FS_24KHZ | CELL_AUDIO_IN_FS_32KHZ | CELL_AUDIO_IN_FS_48KHZ;
devices[curindex].deviceNumber = curindex;
strcpy_trunc(devices[curindex].name, mic_list[0]);
curindex++;
break;
case microphone_handler::null:
default: break;
}
}
if (g_cfg.io.camera != camera_handler::null)
{
devices.emplace_back();
devices[curindex].portType = CELL_AUDIO_IN_PORT_USB;
devices[curindex].availableModeCount = 1;
devices[curindex].state = CELL_AUDIO_IN_DEVICE_STATE_AVAILABLE;
devices[curindex].deviceId = 0xDEADBEEF;
devices[curindex].type = 0xBEEFDEAD;
devices[curindex].availableModes[0].type = CELL_AUDIO_IN_CODING_TYPE_LPCM;
devices[curindex].availableModes[0].channel = CELL_AUDIO_IN_CHNUM_NONE;
devices[curindex].availableModes[0].fs = CELL_AUDIO_IN_FS_8KHZ | CELL_AUDIO_IN_FS_12KHZ | CELL_AUDIO_IN_FS_16KHZ | CELL_AUDIO_IN_FS_24KHZ | CELL_AUDIO_IN_FS_32KHZ | CELL_AUDIO_IN_FS_48KHZ;
devices[curindex].deviceNumber = curindex;
strcpy_trunc(devices[curindex].name, "USB Camera");
curindex++;
}
}
void avconf_manager::copy_device_info(u32 num, vm::ptr<CellAudioInDeviceInfo> info) const
{
memset(info.get_ptr(), 0, sizeof(CellAudioInDeviceInfo));
ensure(num < devices.size());
*info = devices[num];
}
std::optional<CellAudioInDeviceInfo> avconf_manager::get_device_info(vm::cptr<char> name) const
{
for (const CellAudioInDeviceInfo& device : devices)
{
if (strncmp(device.name, name.get_ptr(), sizeof(device.name)) == 0)
{
return device;
}
}
return std::nullopt;
}
error_code cellAudioOutUnregisterDevice(u32 deviceNumber)
{
cellAvconfExt.todo("cellAudioOutUnregisterDevice(deviceNumber=0x%x)", deviceNumber);
return CELL_OK;
}
error_code cellAudioOutGetDeviceInfo2(u32 deviceNumber, u32 deviceIndex, vm::ptr<CellAudioOutDeviceInfo2> info)
{
cellAvconfExt.todo("cellAudioOutGetDeviceInfo2(deviceNumber=0x%x, deviceIndex=0x%x, info=*0x%x)", deviceNumber, deviceIndex, info);
if (deviceIndex != 0 || !info)
{
return CELL_AUDIO_OUT_ERROR_ILLEGAL_PARAMETER;
}
return CELL_OK;
}
error_code cellVideoOutSetXVColor(u32 unk1, u32 unk2, u32 unk3)
{
cellAvconfExt.todo("cellVideoOutSetXVColor(unk1=0x%x, unk2=0x%x, unk3=0x%x)", unk1, unk2, unk3);
if (unk1 != 0)
{
return CELL_VIDEO_OUT_ERROR_NOT_IMPLEMENTED;
}
return CELL_OK;
}
error_code cellVideoOutSetupDisplay(u32 videoOut)
{
cellAvconfExt.todo("cellVideoOutSetupDisplay(videoOut=%d)", videoOut);
if (videoOut != CELL_VIDEO_OUT_SECONDARY)
{
return CELL_VIDEO_OUT_ERROR_UNSUPPORTED_VIDEO_OUT;
}
return CELL_OK;
}
error_code cellAudioInGetDeviceInfo(u32 deviceNumber, u32 deviceIndex, vm::ptr<CellAudioInDeviceInfo> info)
{
cellAvconfExt.trace("cellAudioInGetDeviceInfo(deviceNumber=0x%x, deviceIndex=0x%x, info=*0x%x)", deviceNumber, deviceIndex, info);
if (deviceIndex != 0 || !info)
{
return CELL_AUDIO_IN_ERROR_ILLEGAL_PARAMETER;
}
auto& av_manager = g_fxo->get<avconf_manager>();
std::lock_guard lock(av_manager.mutex);
if (deviceNumber >= av_manager.devices.size())
return CELL_AUDIO_OUT_ERROR_DEVICE_NOT_FOUND;
av_manager.copy_device_info(deviceNumber, info);
return CELL_OK;
}
error_code cellVideoOutConvertCursorColor(u32 videoOut, s32 displaybuffer_format, f32 gamma, s32 source_buffer_format, vm::ptr<void> src_addr, vm::ptr<u32> dest_addr, s32 num)
{
cellAvconfExt.todo("cellVideoOutConvertCursorColor(videoOut=%d, displaybuffer_format=0x%x, gamma=0x%x, source_buffer_format=0x%x, src_addr=*0x%x, dest_addr=*0x%x, num=0x%x)", videoOut,
displaybuffer_format, gamma, source_buffer_format, src_addr, dest_addr, num);
if (!dest_addr || num == 0)
{
return CELL_VIDEO_OUT_ERROR_ILLEGAL_PARAMETER;
}
if (displaybuffer_format > CELL_VIDEO_OUT_BUFFER_COLOR_FORMAT_R16G16B16X16_FLOAT || src_addr)
{
return CELL_VIDEO_OUT_ERROR_PARAMETER_OUT_OF_RANGE;
}
if (displaybuffer_format < CELL_VIDEO_OUT_BUFFER_COLOR_FORMAT_R16G16B16X16_FLOAT)
{
if (gamma < 0.8f || gamma > 1.2f)
{
return CELL_VIDEO_OUT_ERROR_PARAMETER_OUT_OF_RANGE;
}
}
error_code cellVideoOutGetConvertCursorColorInfo(vm::ptr<u8> rgbOutputRange); // Forward declaration
vm::var<u8> rgbOutputRange;
if (error_code error = cellVideoOutGetConvertCursorColorInfo(rgbOutputRange))
{
return error;
}
return CELL_OK;
}
error_code cellVideoOutGetGamma(u32 videoOut, vm::ptr<f32> gamma)
{
cellAvconfExt.warning("cellVideoOutGetGamma(videoOut=%d, gamma=*0x%x)", videoOut, gamma);
if (!gamma)
{
return CELL_VIDEO_OUT_ERROR_ILLEGAL_PARAMETER;
}
if (videoOut != CELL_VIDEO_OUT_PRIMARY)
{
return CELL_VIDEO_OUT_ERROR_UNSUPPORTED_VIDEO_OUT;
}
const auto& conf = g_fxo->get<rsx::avconf>();
*gamma = conf.gamma;
return CELL_OK;
}
error_code cellAudioInGetAvailableDeviceInfo(u32 count, vm::ptr<CellAudioInDeviceInfo> device_info)
{
cellAvconfExt.trace("cellAudioInGetAvailableDeviceInfo(count=%d, info=*0x%x)", count, device_info);
if (count > 16 || !device_info)
{
return CELL_AUDIO_IN_ERROR_ILLEGAL_PARAMETER;
}
auto& av_manager = g_fxo->get<avconf_manager>();
std::lock_guard lock(av_manager.mutex);
u32 num_devices_returned = std::min<u32>(count, ::size32(av_manager.devices));
for (u32 index = 0; index < num_devices_returned; index++)
{
av_manager.copy_device_info(index, device_info + index);
}
CellAudioInDeviceInfo disconnected_device{};
disconnected_device.state = CELL_AUDIO_OUT_DEVICE_STATE_UNAVAILABLE;
disconnected_device.deviceNumber = 0xff;
for (u32 index = num_devices_returned; index < count; index++)
{
device_info[index] = disconnected_device;
}
return not_an_error(num_devices_returned);
}
error_code cellAudioOutGetAvailableDeviceInfo(u32 count, vm::ptr<CellAudioOutDeviceInfo2> info)
{
cellAvconfExt.todo("cellAudioOutGetAvailableDeviceInfo(count=0x%x, info=*0x%x)", count, info);
if (count > 16 || !info)
{
return CELL_AUDIO_OUT_ERROR_ILLEGAL_PARAMETER;
}
return not_an_error(0); // number of available devices
}
error_code cellVideoOutSetGamma(u32 videoOut, f32 gamma)
{
cellAvconfExt.trace("cellVideoOutSetGamma(videoOut=%d, gamma=%f)", videoOut, gamma);
if (gamma < 0.8f || gamma > 1.2f)
{
return CELL_VIDEO_OUT_ERROR_PARAMETER_OUT_OF_RANGE;
}
if (videoOut != CELL_VIDEO_OUT_PRIMARY)
{
return CELL_VIDEO_OUT_ERROR_UNSUPPORTED_VIDEO_OUT;
}
auto& conf = g_fxo->get<rsx::avconf>();
conf.gamma = gamma;
return CELL_OK;
}
error_code cellAudioOutRegisterDevice(u64 deviceType, vm::cptr<char> name, vm::ptr<CellAudioOutRegistrationOption> option, vm::ptr<CellAudioOutDeviceConfiguration> config)
{
cellAvconfExt.todo("cellAudioOutRegisterDevice(deviceType=0x%llx, name=%s, option=*0x%x, config=*0x%x)", deviceType, name, option, config);
if (option || !name)
{
return CELL_AUDIO_IN_ERROR_ILLEGAL_PARAMETER; // Strange choice for an error
}
return not_an_error(0); // device number
}
error_code cellAudioOutSetDeviceMode(u32 deviceMode)
{
cellAvconfExt.todo("cellAudioOutSetDeviceMode(deviceMode=0x%x)", deviceMode);
if (deviceMode > CELL_AUDIO_OUT_MULTI_DEVICE_MODE_2)
{
return CELL_AUDIO_OUT_ERROR_ILLEGAL_PARAMETER;
}
return CELL_OK;
}
error_code cellAudioInSetDeviceMode(u32 deviceMode)
{
cellAvconfExt.todo("cellAudioInSetDeviceMode(deviceMode=0x%x)", deviceMode);
switch (deviceMode)
{
case CELL_AUDIO_IN_SINGLE_DEVICE_MODE:
case CELL_AUDIO_IN_MULTI_DEVICE_MODE:
case CELL_AUDIO_IN_MULTI_DEVICE_MODE_2:
case CELL_AUDIO_IN_MULTI_DEVICE_MODE_10:
break;
default:
return CELL_AUDIO_IN_ERROR_ILLEGAL_PARAMETER;
}
auto& av_manager = g_fxo->get<avconf_manager>();
std::lock_guard lock(av_manager.mutex);
av_manager.inDeviceMode = static_cast<CellAudioInDeviceMode>(deviceMode);
return CELL_OK;
}
error_code cellAudioInRegisterDevice(u64 deviceType, vm::cptr<char> name, vm::ptr<CellAudioInRegistrationOption> option, vm::ptr<CellAudioInDeviceConfiguration> config)
{
cellAvconfExt.todo("cellAudioInRegisterDevice(deviceType=0x%llx, name=%s, option=*0x%x, config=*0x%x)", deviceType, name, option, config);
// option must be null, volume can be 1 (soft) to 5 (loud) (raises question about check for volume = 0)
if (option || !config || !name || config->volume > 5)
{
return CELL_AUDIO_IN_ERROR_ILLEGAL_PARAMETER;
}
auto& av_manager = g_fxo->get<avconf_manager>();
const std::lock_guard lock(av_manager.mutex);
std::optional<CellAudioInDeviceInfo> info = av_manager.get_device_info(name);
if (!info || !memchr(info->name, '\0', sizeof(info->name)))
{
// TODO
return CELL_AUDIO_IN_ERROR_DEVICE_NOT_FOUND;
}
auto& mic_thr = g_fxo->get<mic_thread>();
const std::lock_guard mic_lock(mic_thr.mutex);
const u32 device_number = mic_thr.register_device(info->name);
return not_an_error(device_number);
}
error_code cellAudioInUnregisterDevice(u32 deviceNumber)
{
cellAvconfExt.todo("cellAudioInUnregisterDevice(deviceNumber=0x%x)", deviceNumber);
auto& mic_thr = g_fxo->get<mic_thread>();
const std::lock_guard lock(mic_thr.mutex);
mic_thr.unregister_device(deviceNumber);
return CELL_OK;
}
error_code cellVideoOutGetScreenSize(u32 videoOut, vm::ptr<f32> screenSize)
{
cellAvconfExt.warning("cellVideoOutGetScreenSize(videoOut=%d, screenSize=*0x%x)", videoOut, screenSize);
if (!screenSize)
{
return CELL_VIDEO_OUT_ERROR_ILLEGAL_PARAMETER;
}
if (videoOut != CELL_VIDEO_OUT_PRIMARY)
{
return CELL_VIDEO_OUT_ERROR_UNSUPPORTED_VIDEO_OUT;
}
if (g_cfg.video.stereo_render_mode != stereo_render_mode_options::disabled)
{
// Return Playstation 3D display value
// Some games call this function when 3D is enabled
*screenSize = 24.f;
return CELL_OK;
}
// TODO: Use virtual screen size
#ifdef _WIN32
// HDC screen = GetDC(NULL);
// float diagonal = roundf(sqrtf((powf(float(GetDeviceCaps(screen, HORZSIZE)), 2) + powf(float(GetDeviceCaps(screen, VERTSIZE)), 2))) * 0.0393f);
#else
// TODO: Linux implementation, without using wx
// float diagonal = roundf(sqrtf((powf(wxGetDisplaySizeMM().GetWidth(), 2) + powf(wxGetDisplaySizeMM().GetHeight(), 2))) * 0.0393f);
#endif
return CELL_VIDEO_OUT_ERROR_VALUE_IS_NOT_SET;
}
error_code cellVideoOutSetCopyControl(u32 videoOut, u32 control)
{
cellAvconfExt.todo("cellVideoOutSetCopyControl(videoOut=%d, control=0x%x)", videoOut, control);
if (control > CELL_VIDEO_OUT_COPY_CONTROL_COPY_NEVER)
{
return CELL_VIDEO_OUT_ERROR_ILLEGAL_PARAMETER;
}
return CELL_OK;
}
error_code cellVideoOutConfigure2()
{
cellAvconfExt.todo("cellVideoOutConfigure2()");
if (false) // TODO
{
return CELL_VIDEO_OUT_ERROR_ILLEGAL_PARAMETER;
}
if (false) // TODO
{
return CELL_VIDEO_OUT_ERROR_PARAMETER_OUT_OF_RANGE;
}
return CELL_OK;
}
error_code cellAudioOutGetConfiguration2()
{
cellAvconfExt.todo("cellAudioOutGetConfiguration2()");
if (false) // TODO
{
return CELL_AUDIO_OUT_ERROR_ILLEGAL_PARAMETER;
}
return CELL_OK;
}
error_code cellAudioOutConfigure2()
{
cellAvconfExt.todo("cellAudioOutConfigure2()");
if (false) // TODO
{
return CELL_AUDIO_OUT_ERROR_ILLEGAL_PARAMETER;
}
return CELL_OK;
}
error_code cellVideoOutGetResolutionAvailability2()
{
cellAvconfExt.todo("cellVideoOutGetResolutionAvailability2()");
return CELL_OK;
}
DECLARE(ppu_module_manager::cellAvconfExt)("cellSysutilAvconfExt", []()
{
REG_FUNC(cellSysutilAvconfExt, cellAudioOutUnregisterDevice);
REG_FUNC(cellSysutilAvconfExt, cellAudioOutGetDeviceInfo2);
REG_FUNC(cellSysutilAvconfExt, cellVideoOutSetXVColor);
REG_FUNC(cellSysutilAvconfExt, cellVideoOutSetupDisplay);
REG_FUNC(cellSysutilAvconfExt, cellAudioInGetDeviceInfo);
REG_FUNC(cellSysutilAvconfExt, cellVideoOutConvertCursorColor);
REG_FUNC(cellSysutilAvconfExt, cellVideoOutGetGamma);
REG_FUNC(cellSysutilAvconfExt, cellAudioInGetAvailableDeviceInfo);
REG_FUNC(cellSysutilAvconfExt, cellAudioOutGetAvailableDeviceInfo);
REG_FUNC(cellSysutilAvconfExt, cellVideoOutSetGamma);
REG_FUNC(cellSysutilAvconfExt, cellAudioOutRegisterDevice);
REG_FUNC(cellSysutilAvconfExt, cellAudioOutSetDeviceMode);
REG_FUNC(cellSysutilAvconfExt, cellAudioInSetDeviceMode);
REG_FUNC(cellSysutilAvconfExt, cellAudioInRegisterDevice);
REG_FUNC(cellSysutilAvconfExt, cellAudioInUnregisterDevice);
REG_FUNC(cellSysutilAvconfExt, cellVideoOutGetScreenSize);
REG_FUNC(cellSysutilAvconfExt, cellVideoOutSetCopyControl);
REG_FUNC(cellSysutilAvconfExt, cellVideoOutConfigure2);
REG_FUNC(cellSysutilAvconfExt, cellAudioOutGetConfiguration2);
REG_FUNC(cellSysutilAvconfExt, cellAudioOutConfigure2);
REG_FUNC(cellSysutilAvconfExt, cellVideoOutGetResolutionAvailability2);
});
| 16,923
|
C++
|
.cpp
| 431
| 36.802784
| 197
| 0.746841
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| false
| false
|
5,292
|
cellCelpEnc.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellCelpEnc.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
#include "cellCelpEnc.h"
LOG_CHANNEL(cellCelpEnc);
template <>
void fmt_class_string<CellCelpEncError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](CellCelpEncError value)
{
switch (value)
{
STR_CASE(CELL_CELPENC_ERROR_FAILED);
STR_CASE(CELL_CELPENC_ERROR_SEQ);
STR_CASE(CELL_CELPENC_ERROR_ARG);
STR_CASE(CELL_CELPENC_ERROR_CORE_FAILED);
STR_CASE(CELL_CELPENC_ERROR_CORE_SEQ);
STR_CASE(CELL_CELPENC_ERROR_CORE_ARG);
}
return unknown;
});
}
error_code cellCelpEncQueryAttr(vm::ptr<CellCelpEncAttr> attr)
{
cellCelpEnc.todo("cellCelpEncQueryAttr(attr=*0x%x)", attr);
return CELL_OK;
}
error_code cellCelpEncOpen(vm::ptr<CellCelpEncResource> res, vm::ptr<void> handle)
{
cellCelpEnc.todo("cellCelpEncOpen(res=*0x%x ,attr=*0x%x)", res, handle);
return CELL_OK;
}
error_code cellCelpEncOpenEx(vm::ptr<CellCelpEncResourceEx> res, vm::ptr<void> handle)
{
cellCelpEnc.todo("cellCelpEncOpenEx(res=*0x%x ,attr=*0x%x)", res, handle);
return CELL_OK;
}
error_code cellCelpEncOpenExt()
{
cellCelpEnc.todo("cellCelpEncOpenExt()");
return CELL_OK;
}
error_code cellCelpEncClose(vm::ptr<void> handle)
{
cellCelpEnc.todo("cellCelpEncClose(handle=*0x%x)", handle);
return CELL_OK;
}
error_code cellCelpEncStart(vm::ptr<void> handle, vm::ptr<CellCelpEncParam> param)
{
cellCelpEnc.todo("cellCelpEncStart(handle=*0x%x, attr=*0x%x)", handle, param);
return CELL_OK;
}
error_code cellCelpEncEnd(vm::ptr<void> handle)
{
cellCelpEnc.todo("cellCelpEncEnd(handle=*0x%x)", handle);
return CELL_OK;
}
error_code cellCelpEncEncodeFrame(vm::ptr<void> handle, vm::ptr<CellCelpEncPcmInfo> frameInfo)
{
cellCelpEnc.todo("cellCelpEncEncodeFrame(handle=*0x%x, frameInfo=*0x%x)", handle, frameInfo);
return CELL_OK;
}
error_code cellCelpEncWaitForOutput(vm::ptr<void> handle)
{
cellCelpEnc.todo("cellCelpEncWaitForOutput(handle=*0x%x)", handle);
return CELL_OK;
}
error_code cellCelpEncGetAu(vm::ptr<void> handle, vm::ptr<void> outBuffer, vm::ptr<CellCelpEncAuInfo> auItem)
{
cellCelpEnc.todo("cellCelpEncGetAu(handle=*0x%x, outBuffer=*0x%x, auItem=*0x%x)", handle, outBuffer, auItem);
return CELL_OK;
}
DECLARE(ppu_module_manager::cellCelpEnc)("cellCelpEnc", []()
{
REG_FUNC(cellCelpEnc, cellCelpEncQueryAttr);
REG_FUNC(cellCelpEnc, cellCelpEncOpen);
REG_FUNC(cellCelpEnc, cellCelpEncOpenEx);
REG_FUNC(cellCelpEnc, cellCelpEncOpenExt);
REG_FUNC(cellCelpEnc, cellCelpEncClose);
REG_FUNC(cellCelpEnc, cellCelpEncStart);
REG_FUNC(cellCelpEnc, cellCelpEncEnd);
REG_FUNC(cellCelpEnc, cellCelpEncEncodeFrame);
REG_FUNC(cellCelpEnc, cellCelpEncWaitForOutput);
REG_FUNC(cellCelpEnc, cellCelpEncGetAu);
});
| 2,700
|
C++
|
.cpp
| 84
| 30.333333
| 110
| 0.775087
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| true
| false
| false
| true
| false
| false
|
5,293
|
sys_io_.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/sys_io_.cpp
|
#include "stdafx.h"
#include "Emu/System.h"
#include "Emu/IdManager.h"
#include "Emu/Cell/PPUModule.h"
#include "Emu/Cell/lv2/sys_event.h"
#include "Emu/Cell/lv2/sys_ppu_thread.h"
#include "Emu/Cell/Modules/sysPrxForUser.h"
LOG_CHANNEL(sys_io);
extern void cellPad_init();
extern void cellKb_init();
extern void cellMouse_init();
struct libio_sys_config
{
shared_mutex mtx;
s32 init_ctr = 0;
u32 ppu_id = 0;
u32 queue_id = 0;
~libio_sys_config() noexcept
{
}
void save_or_load(utils::serial& ar)
{
ar(init_ctr, ppu_id, queue_id);
}
};
extern void sys_io_serialize(utils::serial& ar)
{
// Do not assign a serialization tag for now, call it from cellPad serialization
ensure(g_fxo->try_get<libio_sys_config>())->save_or_load(ar);
}
extern bool cellPad_NotifyStateChange(usz index, u64 state, bool lock = true, bool is_blocking = true);
void config_event_entry(ppu_thread& ppu)
{
ppu.state += cpu_flag::wait;
auto& cfg = *ensure(g_fxo->try_get<libio_sys_config>());
if (!ppu.loaded_from_savestate)
{
// Ensure awake
ppu.check_state();
}
const u32 queue_id = cfg.queue_id;
auto queue = idm::get<lv2_obj, lv2_event_queue>(queue_id);
while (queue && sys_event_queue_receive(ppu, queue_id, vm::null, 0) == CELL_OK)
{
if (ppu.is_stopped())
{
ppu.state += cpu_flag::again;
return;
}
// Some delay
thread_ctrl::wait_for(10000);
// Wakeup
ppu.check_state();
ppu.state += cpu_flag::wait;
const u64 arg1 = ppu.gpr[5];
const u64 arg2 = ppu.gpr[6];
const u64 arg3 = ppu.gpr[7];
// TODO: Reverse-engineer proper event system
if (arg1 == 1)
{
while (!cellPad_NotifyStateChange(arg2, arg3, false))
{
if (!queue->exists)
{
// Exit condition
queue = nullptr;
break;
}
thread_ctrl::wait_for(100);
}
}
}
sys_io.notice("config_event_entry(): Exited with the following error code: %s", CellError{static_cast<u32>(ppu.gpr[3])});
ppu_execute<&sys_ppu_thread_exit>(ppu, 0);
}
std::unique_lock<shared_mutex> lock_lv2_mutex_alike(shared_mutex& mtx, ppu_thread* ppu)
{
std::unique_lock<shared_mutex> lock(mtx, std::defer_lock);
while (!lock.try_lock())
{
if (ppu)
{
// Could not be acquired, put PPU to sleep
lv2_obj::sleep(*ppu);
}
// Wait for unlock without owning the lock
mtx.lock_unlock();
if (ppu)
{
// Awake, still not owning
ppu->check_state();
}
}
return lock;
}
extern void send_sys_io_connect_event(usz index, u32 state)
{
if (Emu.IsStarting() || Emu.IsReady())
{
cellPad_NotifyStateChange(index, state);
return;
}
auto& cfg = g_fxo->get<libio_sys_config>();
auto lock = lock_lv2_mutex_alike(cfg.mtx, cpu_thread::get_current<ppu_thread>());
if (cfg.init_ctr)
{
if (auto port = idm::get<lv2_obj, lv2_event_queue>(cfg.queue_id))
{
port->send(0, 1, index, state);
}
}
}
error_code sys_config_start(ppu_thread& ppu)
{
sys_io.warning("sys_config_start()");
auto& cfg = g_fxo->get<libio_sys_config>();
auto lock = lock_lv2_mutex_alike(cfg.mtx, &ppu);
if (cfg.init_ctr++ == 0)
{
// Run thread
vm::var<u64> _tid;
vm::var<u32> queue_id;
vm::var<char[]> _name = vm::make_str("_cfg_evt_hndlr");
vm::var<sys_event_queue_attribute_t> attr;
attr->protocol = SYS_SYNC_PRIORITY;
attr->type = SYS_PPU_QUEUE;
attr->name_u64 = 0;
ensure(CELL_OK == sys_event_queue_create(ppu, queue_id, attr, 0, 0x20));
ppu.check_state();
cfg.queue_id = *queue_id;
ensure(CELL_OK == ppu_execute<&sys_ppu_thread_create>(ppu, +_tid, g_fxo->get<ppu_function_manager>().func_addr(FIND_FUNC(config_event_entry)), 0, 512, 0x2000, SYS_PPU_THREAD_CREATE_JOINABLE, +_name));
ppu.check_state();
cfg.ppu_id = static_cast<u32>(*_tid);
}
return CELL_OK;
}
error_code sys_config_stop(ppu_thread& ppu)
{
sys_io.warning("sys_config_stop()");
auto& cfg = g_fxo->get<libio_sys_config>();
auto lock = lock_lv2_mutex_alike(cfg.mtx, &ppu);
if (cfg.init_ctr && cfg.init_ctr-- == 1)
{
ensure(CELL_OK == sys_event_queue_destroy(ppu, cfg.queue_id, SYS_EVENT_QUEUE_DESTROY_FORCE));
ppu.check_state();
ensure(CELL_OK == sys_ppu_thread_join(ppu, cfg.ppu_id, +vm::var<u64>{}));
}
else
{
// TODO: Unknown error
}
return CELL_OK;
}
error_code sys_config_add_service_listener()
{
sys_io.todo("sys_config_add_service_listener()");
return CELL_OK;
}
error_code sys_config_remove_service_listener()
{
sys_io.todo("sys_config_remove_service_listener()");
return CELL_OK;
}
error_code sys_config_register_io_error_handler()
{
sys_io.todo("sys_config_register_io_error_handler()");
return CELL_OK;
}
error_code sys_config_register_service()
{
sys_io.todo("sys_config_register_service()");
return CELL_OK;
}
error_code sys_config_unregister_io_error_handler()
{
sys_io.todo("sys_config_unregister_io_error_handler()");
return CELL_OK;
}
error_code sys_config_unregister_service()
{
sys_io.todo("sys_config_unregister_service()");
return CELL_OK;
}
DECLARE(ppu_module_manager::sys_io)("sys_io", []()
{
cellPad_init();
cellKb_init();
cellMouse_init();
REG_FUNC(sys_io, sys_config_start);
REG_FUNC(sys_io, sys_config_stop);
REG_FUNC(sys_io, sys_config_add_service_listener);
REG_FUNC(sys_io, sys_config_remove_service_listener);
REG_FUNC(sys_io, sys_config_register_io_error_handler);
REG_FUNC(sys_io, sys_config_register_service);
REG_FUNC(sys_io, sys_config_unregister_io_error_handler);
REG_FUNC(sys_io, sys_config_unregister_service);
REG_HIDDEN_FUNC(config_event_entry);
});
| 5,474
|
C++
|
.cpp
| 198
| 25.176768
| 202
| 0.693029
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
5,294
|
cellVideoPlayerUtility.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellVideoPlayerUtility.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
LOG_CHANNEL(cellVideoPlayerUtility);
error_code cellVideoPlayerInitialize()
{
UNIMPLEMENTED_FUNC(cellVideoPlayerUtility);
return CELL_OK;
}
error_code cellVideoPlayerSetStartPosition()
{
UNIMPLEMENTED_FUNC(cellVideoPlayerUtility);
return CELL_OK;
}
error_code cellVideoPlayerGetVolume()
{
UNIMPLEMENTED_FUNC(cellVideoPlayerUtility);
return CELL_OK;
}
error_code cellVideoPlayerFinalize()
{
UNIMPLEMENTED_FUNC(cellVideoPlayerUtility);
return CELL_OK;
}
error_code cellVideoPlayerSetStopPosition()
{
UNIMPLEMENTED_FUNC(cellVideoPlayerUtility);
return CELL_OK;
}
error_code cellVideoPlayerClose()
{
UNIMPLEMENTED_FUNC(cellVideoPlayerUtility);
return CELL_OK;
}
error_code cellVideoPlayerGetTransferPictureInfo()
{
UNIMPLEMENTED_FUNC(cellVideoPlayerUtility);
return CELL_OK;
}
error_code cellVideoPlayerSetDownloadPosition()
{
UNIMPLEMENTED_FUNC(cellVideoPlayerUtility);
return CELL_OK;
}
error_code cellVideoPlayerStartThumbnail()
{
UNIMPLEMENTED_FUNC(cellVideoPlayerUtility);
return CELL_OK;
}
error_code cellVideoPlayerEndThumbnail()
{
UNIMPLEMENTED_FUNC(cellVideoPlayerUtility);
return CELL_OK;
}
error_code cellVideoPlayerOpen()
{
UNIMPLEMENTED_FUNC(cellVideoPlayerUtility);
return CELL_OK;
}
error_code cellVideoPlayerSetVolume()
{
UNIMPLEMENTED_FUNC(cellVideoPlayerUtility);
return CELL_OK;
}
error_code cellVideoPlayerGetOutputStereoPicture()
{
UNIMPLEMENTED_FUNC(cellVideoPlayerUtility);
return CELL_OK;
}
error_code cellVideoPlayerGetPlaybackStatus()
{
UNIMPLEMENTED_FUNC(cellVideoPlayerUtility);
return CELL_OK;
}
error_code cellVideoPlayerSetTransferComplete()
{
UNIMPLEMENTED_FUNC(cellVideoPlayerUtility);
return CELL_OK;
}
error_code cellVideoPlayerGetOutputPicture()
{
UNIMPLEMENTED_FUNC(cellVideoPlayerUtility);
return CELL_OK;
}
error_code cellVideoPlayerPlaybackControl()
{
UNIMPLEMENTED_FUNC(cellVideoPlayerUtility);
return CELL_OK;
}
DECLARE(ppu_module_manager::cellVideoPlayerUtility)("cellVideoPlayerUtility", []()
{
REG_FUNC(cellVideoPlayerUtility, cellVideoPlayerInitialize);
REG_FUNC(cellVideoPlayerUtility, cellVideoPlayerSetStartPosition);
REG_FUNC(cellVideoPlayerUtility, cellVideoPlayerGetVolume);
REG_FUNC(cellVideoPlayerUtility, cellVideoPlayerFinalize);
REG_FUNC(cellVideoPlayerUtility, cellVideoPlayerSetStopPosition);
REG_FUNC(cellVideoPlayerUtility, cellVideoPlayerClose);
REG_FUNC(cellVideoPlayerUtility, cellVideoPlayerGetTransferPictureInfo);
REG_FUNC(cellVideoPlayerUtility, cellVideoPlayerSetDownloadPosition);
REG_FUNC(cellVideoPlayerUtility, cellVideoPlayerStartThumbnail);
REG_FUNC(cellVideoPlayerUtility, cellVideoPlayerEndThumbnail);
REG_FUNC(cellVideoPlayerUtility, cellVideoPlayerOpen);
REG_FUNC(cellVideoPlayerUtility, cellVideoPlayerSetVolume);
REG_FUNC(cellVideoPlayerUtility, cellVideoPlayerGetOutputStereoPicture);
REG_FUNC(cellVideoPlayerUtility, cellVideoPlayerGetPlaybackStatus);
REG_FUNC(cellVideoPlayerUtility, cellVideoPlayerSetTransferComplete);
REG_FUNC(cellVideoPlayerUtility, cellVideoPlayerGetOutputPicture);
REG_FUNC(cellVideoPlayerUtility, cellVideoPlayerPlaybackControl);
});
| 3,160
|
C++
|
.cpp
| 108
| 27.611111
| 82
| 0.86515
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| true
| false
| false
| true
| false
| false
|
5,295
|
cellOvis.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellOvis.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
#include "Emu/Cell/lv2/sys_spu.h"
LOG_CHANNEL(cellOvis);
// Return Codes
enum CellOvisError : u32
{
CELL_OVIS_ERROR_INVAL = 0x80410402,
CELL_OVIS_ERROR_ABORT = 0x8041040C,
CELL_OVIS_ERROR_ALIGN = 0x80410410,
};
template<>
void fmt_class_string<CellOvisError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_OVIS_ERROR_INVAL);
STR_CASE(CELL_OVIS_ERROR_ABORT);
STR_CASE(CELL_OVIS_ERROR_ALIGN);
}
return unknown;
});
}
error_code cellOvisGetOverlayTableSize(vm::cptr<char> elf)
{
cellOvis.todo("cellOvisGetOverlayTableSize(elf=%s)", elf);
return CELL_OK;
}
error_code cellOvisInitializeOverlayTable(vm::ptr<void> ea_ovly_table, vm::cptr<char> elf)
{
cellOvis.todo("cellOvisInitializeOverlayTable(ea_ovly_table=*0x%x, elf=%s)", ea_ovly_table, elf);
return CELL_OK;
}
void cellOvisFixSpuSegments(vm::ptr<sys_spu_image> image)
{
cellOvis.todo("cellOvisFixSpuSegments(image=*0x%x)", image);
}
void cellOvisInvalidateOverlappedSegments(vm::ptr<sys_spu_segment> segs, vm::ptr<int> nsegs)
{
cellOvis.todo("cellOvisInvalidateOverlappedSegments(segs=*0x%x, nsegs=*0x%x)", segs, nsegs);
}
DECLARE(ppu_module_manager::cellOvis)("cellOvis", []()
{
REG_FUNC(cellOvis, cellOvisGetOverlayTableSize);
REG_FUNC(cellOvis, cellOvisInitializeOverlayTable);
REG_FUNC(cellOvis, cellOvisFixSpuSegments);
REG_FUNC(cellOvis, cellOvisInvalidateOverlappedSegments);
});
| 1,495
|
C++
|
.cpp
| 50
| 28.02
| 98
| 0.76848
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| true
| false
| false
| true
| false
| false
|
5,296
|
cellSubDisplay.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellSubDisplay.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
#include "Emu/IdManager.h"
#include "cellSubDisplay.h"
LOG_CHANNEL(cellSubDisplay);
template<>
void fmt_class_string<CellSubDisplayError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_SUBDISPLAY_ERROR_OUT_OF_MEMORY);
STR_CASE(CELL_SUBDISPLAY_ERROR_FATAL);
STR_CASE(CELL_SUBDISPLAY_ERROR_NOT_FOUND);
STR_CASE(CELL_SUBDISPLAY_ERROR_INVALID_VALUE);
STR_CASE(CELL_SUBDISPLAY_ERROR_NOT_INITIALIZED);
STR_CASE(CELL_SUBDISPLAY_ERROR_NOT_SUPPORTED);
STR_CASE(CELL_SUBDISPLAY_ERROR_SET_SAMPLE);
STR_CASE(CELL_SUBDISPLAY_ERROR_AUDIOOUT_IS_BUSY);
STR_CASE(CELL_SUBDISPLAY_ERROR_ZERO_REGISTERED);
}
return unknown;
});
}
enum class sub_display_status : u32
{
uninitialized = 0,
stopped = 1,
started = 2
};
struct sub_display_manager
{
shared_mutex mutex;
sub_display_status status = sub_display_status::uninitialized;
CellSubDisplayParam param{};
vm::ptr<CellSubDisplayHandler> func = vm::null;
vm::ptr<void> userdata = vm::null;
// Video data
vm::ptr<void> video_buffer = vm::null;
u32 buf_size = 0;
// Audio data
bool audio_is_busy = false;
// Touch data
std::array<CellSubDisplayTouchInfo, CELL_SUBDISPLAY_TOUCH_MAX_TOUCH_INFO> touch_info{};
};
error_code check_param(CellSubDisplayParam* param)
{
if (!param ||
param->version < CELL_SUBDISPLAY_VERSION_0001 ||
param->version > CELL_SUBDISPLAY_VERSION_0003 ||
param->mode != CELL_SUBDISPLAY_MODE_REMOTEPLAY ||
param->nGroup != 1 ||
param->nPeer != 1 ||
param->audioParam.ch != 2 ||
param->audioParam.audioMode < CELL_SUBDISPLAY_AUDIO_MODE_SETDATA ||
param->audioParam.audioMode > CELL_SUBDISPLAY_AUDIO_MODE_CAPTURE)
{
return CELL_SUBDISPLAY_ERROR_INVALID_VALUE;
}
switch (param->videoParam.format)
{
case CELL_SUBDISPLAY_VIDEO_FORMAT_A8R8G8B8:
case CELL_SUBDISPLAY_VIDEO_FORMAT_R8G8B8A8:
{
if (param->version == CELL_SUBDISPLAY_VERSION_0003 ||
param->videoParam.width != 480 ||
param->videoParam.height != 272 ||
(param->videoParam.pitch != 1920 && param->videoParam.pitch != 2048) ||
param->videoParam.aspectRatio < CELL_SUBDISPLAY_VIDEO_ASPECT_RATIO_16_9 ||
param->videoParam.aspectRatio > CELL_SUBDISPLAY_VIDEO_ASPECT_RATIO_4_3 ||
param->videoParam.videoMode < CELL_SUBDISPLAY_VIDEO_MODE_SETDATA ||
param->videoParam.videoMode > CELL_SUBDISPLAY_VIDEO_MODE_CAPTURE)
{
return CELL_SUBDISPLAY_ERROR_INVALID_VALUE;
}
break;
}
case CELL_SUBDISPLAY_VIDEO_FORMAT_YUV420:
{
if (param->version != CELL_SUBDISPLAY_VERSION_0003 ||
param->videoParam.width != CELL_SUBDISPLAY_0003_WIDTH ||
param->videoParam.height != CELL_SUBDISPLAY_0003_HEIGHT ||
param->videoParam.pitch != CELL_SUBDISPLAY_0003_PITCH ||
param->videoParam.aspectRatio != CELL_SUBDISPLAY_VIDEO_ASPECT_RATIO_16_9 ||
param->videoParam.videoMode != CELL_SUBDISPLAY_VIDEO_MODE_SETDATA)
{
return CELL_SUBDISPLAY_ERROR_INVALID_VALUE;
}
break;
}
default:
{
return CELL_SUBDISPLAY_ERROR_INVALID_VALUE;
}
}
return CELL_OK;
}
error_code cellSubDisplayInit(vm::ptr<CellSubDisplayParam> pParam, vm::ptr<CellSubDisplayHandler> func, vm::ptr<void> userdata, u32 container)
{
cellSubDisplay.todo("cellSubDisplayInit(pParam=*0x%x, func=*0x%x, userdata=*0x%x, container=0x%x)", pParam, func, userdata, container);
auto& manager = g_fxo->get<sub_display_manager>();
std::lock_guard lock(manager.mutex);
if (manager.func)
{
return CELL_SUBDISPLAY_ERROR_NOT_INITIALIZED;
}
if (error_code error = check_param(pParam.get_ptr()))
{
return error;
}
if (!func)
{
return CELL_SUBDISPLAY_ERROR_INVALID_VALUE;
}
manager.param = *pParam;
manager.func = func;
manager.userdata = userdata;
if (true) // TODO
{
return CELL_SUBDISPLAY_ERROR_ZERO_REGISTERED;
}
return CELL_OK;
}
error_code cellSubDisplayEnd()
{
cellSubDisplay.todo("cellSubDisplayEnd()");
auto& manager = g_fxo->get<sub_display_manager>();
std::lock_guard lock(manager.mutex);
if (!manager.func)
{
return CELL_SUBDISPLAY_ERROR_NOT_INITIALIZED;
}
if (manager.status == sub_display_status::started)
{
// TODO:
// cellSubDisplayStop();
}
manager.param = {};
manager.func = vm::null;
manager.userdata = vm::null;
manager.status = sub_display_status::uninitialized;
return CELL_OK;
}
error_code cellSubDisplayGetRequiredMemory(vm::ptr<CellSubDisplayParam> pParam)
{
cellSubDisplay.warning("cellSubDisplayGetRequiredMemory(pParam=*0x%x)", pParam);
if (error_code error = check_param(pParam.get_ptr()))
{
return error;
}
switch (pParam->version)
{
case CELL_SUBDISPLAY_VERSION_0001: return not_an_error(CELL_SUBDISPLAY_0001_MEMORY_CONTAINER_SIZE);
case CELL_SUBDISPLAY_VERSION_0002: return not_an_error(CELL_SUBDISPLAY_0002_MEMORY_CONTAINER_SIZE);
case CELL_SUBDISPLAY_VERSION_0003: return not_an_error(CELL_SUBDISPLAY_0003_MEMORY_CONTAINER_SIZE);
default: break;
}
return CELL_SUBDISPLAY_ERROR_INVALID_VALUE;
}
error_code cellSubDisplayStart()
{
cellSubDisplay.todo("cellSubDisplayStart()");
auto& manager = g_fxo->get<sub_display_manager>();
std::lock_guard lock(manager.mutex);
if (manager.status == sub_display_status::uninitialized)
{
return CELL_SUBDISPLAY_ERROR_NOT_INITIALIZED;
}
manager.status = sub_display_status::started;
// TODO
return CELL_OK;
}
error_code cellSubDisplayStop()
{
cellSubDisplay.todo("cellSubDisplayStop()");
auto& manager = g_fxo->get<sub_display_manager>();
std::lock_guard lock(manager.mutex);
if (manager.status == sub_display_status::uninitialized)
{
return CELL_SUBDISPLAY_ERROR_NOT_INITIALIZED;
}
manager.status = sub_display_status::stopped;
// TODO
return CELL_OK;
}
error_code cellSubDisplayGetVideoBuffer(s32 groupId, vm::pptr<void> ppVideoBuf, vm::ptr<u32> pSize)
{
cellSubDisplay.todo("cellSubDisplayGetVideoBuffer(groupId=%d, ppVideoBuf=**0x%x, pSize=*0x%x)", groupId, ppVideoBuf, pSize);
auto& manager = g_fxo->get<sub_display_manager>();
std::lock_guard lock(manager.mutex);
if (manager.status == sub_display_status::uninitialized)
{
return CELL_SUBDISPLAY_ERROR_NOT_INITIALIZED;
}
if (groupId != 0 || !ppVideoBuf || !pSize)
{
return CELL_SUBDISPLAY_ERROR_INVALID_VALUE;
}
*pSize = manager.buf_size;
*ppVideoBuf = manager.video_buffer;
return CELL_OK;
}
error_code cellSubDisplayAudioOutBlocking(s32 groupId, vm::ptr<void> pvData, s32 samples)
{
cellSubDisplay.todo("cellSubDisplayAudioOutBlocking(groupId=%d, pvData=*0x%x, samples=%d)", groupId, pvData, samples);
auto& manager = g_fxo->get<sub_display_manager>();
std::lock_guard lock(manager.mutex);
if (manager.status == sub_display_status::uninitialized)
{
return CELL_SUBDISPLAY_ERROR_NOT_INITIALIZED;
}
if (groupId != 0 || samples < 0)
{
return CELL_SUBDISPLAY_ERROR_INVALID_VALUE;
}
if (samples % 1024)
{
return CELL_SUBDISPLAY_ERROR_SET_SAMPLE;
}
// TODO
return CELL_OK;
}
error_code cellSubDisplayAudioOutNonBlocking(s32 groupId, vm::ptr<void> pvData, s32 samples)
{
cellSubDisplay.todo("cellSubDisplayAudioOutNonBlocking(groupId=%d, pvData=*0x%x, samples=%d)", groupId, pvData, samples);
auto& manager = g_fxo->get<sub_display_manager>();
std::lock_guard lock(manager.mutex);
if (manager.status == sub_display_status::uninitialized)
{
return CELL_SUBDISPLAY_ERROR_NOT_INITIALIZED;
}
if (groupId != 0 || samples < 0)
{
return CELL_SUBDISPLAY_ERROR_INVALID_VALUE;
}
if (samples % 1024)
{
return CELL_SUBDISPLAY_ERROR_SET_SAMPLE;
}
if (manager.audio_is_busy)
{
return CELL_SUBDISPLAY_ERROR_AUDIOOUT_IS_BUSY;
}
// TODO: fetch audio async
// manager.audio_is_busy = true;
return CELL_OK;
}
error_code cellSubDisplayGetPeerNum(s32 groupId)
{
cellSubDisplay.todo("cellSubDisplayGetPeerNum(groupId=%d)", groupId);
auto& manager = g_fxo->get<sub_display_manager>();
std::lock_guard lock(manager.mutex);
if (manager.status == sub_display_status::uninitialized)
{
return CELL_SUBDISPLAY_ERROR_NOT_INITIALIZED;
}
if (groupId != 0)
{
return CELL_SUBDISPLAY_ERROR_INVALID_VALUE;
}
s32 peer_num = 0; // TODO
return not_an_error(peer_num);
}
error_code cellSubDisplayGetPeerList(s32 groupId, vm::ptr<CellSubDisplayPeerInfo> pInfo, vm::ptr<s32> pNum)
{
cellSubDisplay.todo("cellSubDisplayGetPeerList(groupId=%d, pInfo=*0x%x, pNum=*0x%x)", groupId, pInfo, pNum);
auto& manager = g_fxo->get<sub_display_manager>();
std::lock_guard lock(manager.mutex);
if (manager.status == sub_display_status::uninitialized)
{
return CELL_SUBDISPLAY_ERROR_NOT_INITIALIZED;
}
if (groupId != 0)
{
return CELL_OK;
}
if (!pInfo || !pNum || *pNum < 1)
{
return CELL_SUBDISPLAY_ERROR_INVALID_VALUE;
}
*pNum = 0;
// TODO
return CELL_OK;
}
error_code cellSubDisplayGetTouchInfo(s32 groupId, vm::ptr<CellSubDisplayTouchInfo> pTouchInfo, vm::ptr<s32> pNumTouchInfo)
{
cellSubDisplay.todo("cellSubDisplayGetTouchInfo(groupId=%d, pTouchInfo=*0x%x, pNumTouchInfo=*0x%x)", groupId, pTouchInfo, pNumTouchInfo);
if (groupId != 0 || !pNumTouchInfo || !pTouchInfo)
{
return CELL_SUBDISPLAY_ERROR_INVALID_VALUE;
}
auto& manager = g_fxo->get<sub_display_manager>();
std::lock_guard lock(manager.mutex);
if (manager.param.version != CELL_SUBDISPLAY_VERSION_0003)
{
return CELL_SUBDISPLAY_ERROR_NOT_SUPPORTED;
}
if (*pNumTouchInfo > CELL_SUBDISPLAY_TOUCH_MAX_TOUCH_INFO)
{
*pNumTouchInfo = CELL_SUBDISPLAY_TOUCH_MAX_TOUCH_INFO;
}
std::memcpy(pTouchInfo.get_ptr(), manager.touch_info.data(), *pNumTouchInfo * sizeof(CellSubDisplayTouchInfo));
return CELL_OK;
}
DECLARE(ppu_module_manager::cellSubDisplay)("cellSubDisplay", []()
{
// Initialization / Termination Functions
REG_FUNC(cellSubDisplay, cellSubDisplayInit);
REG_FUNC(cellSubDisplay, cellSubDisplayEnd);
REG_FUNC(cellSubDisplay, cellSubDisplayGetRequiredMemory);
REG_FUNC(cellSubDisplay, cellSubDisplayStart);
REG_FUNC(cellSubDisplay, cellSubDisplayStop);
// Data Setting Functions
REG_FUNC(cellSubDisplay, cellSubDisplayGetVideoBuffer);
REG_FUNC(cellSubDisplay, cellSubDisplayAudioOutBlocking);
REG_FUNC(cellSubDisplay, cellSubDisplayAudioOutNonBlocking);
// Peer Status Acquisition Functions
REG_FUNC(cellSubDisplay, cellSubDisplayGetPeerNum);
REG_FUNC(cellSubDisplay, cellSubDisplayGetPeerList);
//
REG_FUNC(cellSubDisplay, cellSubDisplayGetTouchInfo);
});
| 10,355
|
C++
|
.cpp
| 323
| 29.665635
| 142
| 0.756262
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
5,297
|
cellUserInfo.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellUserInfo.cpp
|
#include "stdafx.h"
#include "Emu/System.h"
#include "Emu/system_utils.hpp"
#include "Emu/VFS.h"
#include "Emu/IdManager.h"
#include "Emu/Cell/PPUModule.h"
#include "Emu/RSX/Overlays/overlay_manager.h"
#include "Emu/RSX/Overlays/overlay_user_list_dialog.h"
#include "cellUserInfo.h"
#include "Utilities/StrUtil.h"
#include "cellSysutil.h"
LOG_CHANNEL(cellUserInfo);
struct user_info_manager
{
atomic_t<bool> enable_overlay{false};
atomic_t<bool> dialog_opened{false};
};
std::string get_username(const u32 user_id)
{
std::string username;
if (const fs::file file{rpcs3::utils::get_hdd0_dir() + fmt::format("home/%08d/localusername", user_id)})
{
username = file.to_string();
username.resize(CELL_USERINFO_USERNAME_SIZE); // TODO: investigate
}
return username;
}
template<>
void fmt_class_string<CellUserInfoError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_USERINFO_ERROR_BUSY);
STR_CASE(CELL_USERINFO_ERROR_INTERNAL);
STR_CASE(CELL_USERINFO_ERROR_PARAM);
STR_CASE(CELL_USERINFO_ERROR_NOUSER);
}
return unknown;
});
}
template<>
void fmt_class_string<cell_user_callback_result>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_USERINFO_RET_OK);
STR_CASE(CELL_USERINFO_RET_CANCEL);
}
return unknown;
});
}
error_code cellUserInfoGetStat(u32 id, vm::ptr<CellUserInfoUserStat> stat)
{
cellUserInfo.warning("cellUserInfoGetStat(id=%d, stat=*0x%x)", id, stat);
if (id > CELL_SYSUTIL_USERID_MAX)
{
// ****** sysutil userinfo parameter error : 1 ******
return {CELL_USERINFO_ERROR_PARAM, "1"};
}
if (id == CELL_SYSUTIL_USERID_CURRENT)
{
// We want the int value, not the string.
id = Emu.GetUsrId();
}
const std::string path = vfs::get(fmt::format("/dev_hdd0/home/%08d/", id));
if (!fs::is_dir(path))
{
cellUserInfo.error("cellUserInfoGetStat(): CELL_USERINFO_ERROR_NOUSER. User %d doesn't exist. Did you delete the user folder?", id);
return CELL_USERINFO_ERROR_NOUSER;
}
const fs::file f(path + "localusername");
if (!f)
{
cellUserInfo.error("cellUserInfoGetStat(): CELL_USERINFO_ERROR_INTERNAL. Username for user %08u doesn't exist. Did you delete the username file?", id);
return CELL_USERINFO_ERROR_INTERNAL;
}
if (stat)
{
stat->id = id;
strcpy_trunc(stat->name, f.to_string());
}
return CELL_OK;
}
error_code cellUserInfoSelectUser_ListType(vm::ptr<CellUserInfoTypeSet> listType, vm::ptr<CellUserInfoFinishCallback> funcSelect, u32 container, vm::ptr<void> userdata)
{
cellUserInfo.warning("cellUserInfoSelectUser_ListType(listType=*0x%x, funcSelect=*0x%x, container=0x%x, userdata=*0x%x)", listType, funcSelect, container, userdata);
if (!listType || !funcSelect) // TODO: confirm
{
return CELL_USERINFO_ERROR_PARAM;
}
if (g_fxo->get<user_info_manager>().dialog_opened)
{
return CELL_USERINFO_ERROR_BUSY;
}
std::vector<u32> user_ids;
const std::string home_dir = rpcs3::utils::get_hdd0_dir() + "home";
for (const auto& user_folder : fs::dir(home_dir))
{
if (!user_folder.is_directory)
{
continue;
}
// Is the folder name exactly 8 all-numerical characters long?
const u32 user_id = rpcs3::utils::check_user(user_folder.name);
if (user_id == 0)
{
continue;
}
// Does the localusername file exist?
if (!fs::is_file(home_dir + "/" + user_folder.name + "/localusername"))
{
continue;
}
// TODO: maybe also restrict this to CELL_USERINFO_USER_MAX
if (listType->type != CELL_USERINFO_LISTTYPE_NOCURRENT || user_id != Emu.GetUsrId())
{
user_ids.push_back(user_id);
}
}
if (auto manager = g_fxo->try_get<rsx::overlays::display_manager>())
{
if (g_fxo->get<user_info_manager>().dialog_opened.exchange(true))
{
return CELL_USERINFO_ERROR_BUSY;
}
if (s32 ret = sysutil_send_system_cmd(CELL_SYSUTIL_DRAWING_BEGIN, 0); ret < 0)
{
g_fxo->get<user_info_manager>().dialog_opened = false;
return CELL_USERINFO_ERROR_BUSY;
}
const std::string title = listType->title.get_ptr();
const u32 focused = listType->focus;
cellUserInfo.warning("cellUserInfoSelectUser_ListType: opening user_list_dialog with: title='%s', focused=%d", title, focused);
const bool enable_overlay = g_fxo->get<user_info_manager>().enable_overlay;
const error_code result = manager->create<rsx::overlays::user_list_dialog>()->show(title, focused, user_ids, enable_overlay, [funcSelect, userdata](s32 status)
{
s32 callback_result = CELL_USERINFO_RET_CANCEL;
u32 selected_user_id = 0;
std::string selected_username;
if (status >= 0)
{
callback_result = CELL_USERINFO_RET_OK;
selected_user_id = static_cast<u32>(status);
selected_username = get_username(selected_user_id);
}
cellUserInfo.warning("cellUserInfoSelectUser_ListType: callback_result=%s, selected_user_id=%d, selected_username='%s'", callback_result, selected_user_id, selected_username);
g_fxo->get<user_info_manager>().dialog_opened = false;
sysutil_send_system_cmd(CELL_SYSUTIL_DRAWING_END, 0);
sysutil_register_cb([=](ppu_thread& ppu) -> s32
{
vm::var<CellUserInfoUserStat> selectUser;
if (status >= 0)
{
selectUser->id = selected_user_id;
strcpy_trunc(selectUser->name, selected_username);
}
funcSelect(ppu, callback_result, selectUser, userdata);
return CELL_OK;
});
});
return result;
}
cellUserInfo.error("User selection is only possible when the native user interface is enabled in the settings. The currently active user will be selected as a fallback.");
sysutil_register_cb([=](ppu_thread& ppu) -> s32
{
vm::var<CellUserInfoUserStat> selectUser;
selectUser->id = Emu.GetUsrId();
strcpy_trunc(selectUser->name, get_username(Emu.GetUsrId()));
funcSelect(ppu, CELL_USERINFO_RET_OK, selectUser, userdata);
return CELL_OK;
});
return CELL_OK;
}
error_code cellUserInfoSelectUser_SetList(vm::ptr<CellUserInfoListSet> setList, vm::ptr<CellUserInfoFinishCallback> funcSelect, u32 container, vm::ptr<void> userdata)
{
cellUserInfo.warning("cellUserInfoSelectUser_SetList(setList=*0x%x, funcSelect=*0x%x, container=0x%x, userdata=*0x%x)", setList, funcSelect, container, userdata);
if (!setList || !funcSelect) // TODO: confirm
{
return CELL_USERINFO_ERROR_PARAM;
}
if (g_fxo->get<user_info_manager>().dialog_opened)
{
return CELL_USERINFO_ERROR_BUSY;
}
std::vector<u32> user_ids;
for (usz i = 0; i < CELL_USERINFO_USER_MAX && i < setList->fixedListNum; i++)
{
if (const u32 id = setList->fixedList->userId[i])
{
user_ids.push_back(id);
}
}
if (user_ids.empty())
{
// TODO: Confirm. Also check if this is possible in cellUserInfoSelectUser_ListType.
cellUserInfo.error("cellUserInfoSelectUser_SetList: callback_result=%s", CELL_USERINFO_ERROR_NOUSER);
sysutil_register_cb([=](ppu_thread& ppu) -> s32
{
vm::var<CellUserInfoUserStat> selectUser;
funcSelect(ppu, CELL_USERINFO_ERROR_NOUSER, selectUser, userdata);
return CELL_OK;
});
return CELL_OK;
}
// TODO: does this function return an error if any (user_id > 0 && not_found) ?
if (auto manager = g_fxo->try_get<rsx::overlays::display_manager>())
{
if (g_fxo->get<user_info_manager>().dialog_opened.exchange(true))
{
return CELL_USERINFO_ERROR_BUSY;
}
if (s32 ret = sysutil_send_system_cmd(CELL_SYSUTIL_DRAWING_BEGIN, 0); ret < 0)
{
g_fxo->get<user_info_manager>().dialog_opened = false;
return CELL_USERINFO_ERROR_BUSY;
}
const std::string title = setList->title.get_ptr();
const u32 focused = setList->focus;
cellUserInfo.warning("cellUserInfoSelectUser_SetList: opening user_list_dialog with: title='%s', focused=%d", title, focused);
const bool enable_overlay = g_fxo->get<user_info_manager>().enable_overlay;
const error_code result = manager->create<rsx::overlays::user_list_dialog>()->show(title, focused, user_ids, enable_overlay, [funcSelect, userdata](s32 status)
{
s32 callback_result = CELL_USERINFO_RET_CANCEL;
u32 selected_user_id = 0;
std::string selected_username;
if (status >= 0)
{
callback_result = CELL_USERINFO_RET_OK;
selected_user_id = static_cast<u32>(status);
selected_username = get_username(selected_user_id);
}
cellUserInfo.warning("cellUserInfoSelectUser_SetList: callback_result=%s, selected_user_id=%d, selected_username='%s'", callback_result, selected_user_id, selected_username);
g_fxo->get<user_info_manager>().dialog_opened = false;
sysutil_send_system_cmd(CELL_SYSUTIL_DRAWING_END, 0);
sysutil_register_cb([=](ppu_thread& ppu) -> s32
{
vm::var<CellUserInfoUserStat> selectUser;
if (status >= 0)
{
selectUser->id = selected_user_id;
strcpy_trunc(selectUser->name, selected_username);
}
funcSelect(ppu, callback_result, selectUser, userdata);
return CELL_OK;
});
});
return result;
}
cellUserInfo.error("User selection is only possible when the native user interface is enabled in the settings. The currently active user will be selected as a fallback.");
sysutil_register_cb([=](ppu_thread& ppu) -> s32
{
vm::var<CellUserInfoUserStat> selectUser;
selectUser->id = Emu.GetUsrId();
strcpy_trunc(selectUser->name, get_username(Emu.GetUsrId()));
funcSelect(ppu, CELL_USERINFO_RET_OK, selectUser, userdata);
return CELL_OK;
});
return CELL_OK;
}
void cellUserInfoEnableOverlay(s32 enable)
{
cellUserInfo.notice("cellUserInfoEnableOverlay(enable=%d)", enable);
auto& manager = g_fxo->get<user_info_manager>();
manager.enable_overlay = enable != 0;
}
error_code cellUserInfoGetList(vm::ptr<u32> listNum, vm::ptr<CellUserInfoUserList> listBuf, vm::ptr<u32> currentUserId)
{
cellUserInfo.warning("cellUserInfoGetList(listNum=*0x%x, listBuf=*0x%x, currentUserId=*0x%x)", listNum, listBuf, currentUserId);
// If only listNum is NULL, an error will be returned
if (!listNum)
{
if (listBuf || !currentUserId)
{
return CELL_USERINFO_ERROR_PARAM;
}
}
const std::string home_dir = rpcs3::utils::get_hdd0_dir() + "home";
std::vector<u32> user_ids;
for (const auto& user_folder : fs::dir(home_dir))
{
if (!user_folder.is_directory)
{
continue;
}
// Is the folder name exactly 8 all-numerical characters long?
const u32 user_id = rpcs3::utils::check_user(user_folder.name);
if (user_id == 0)
{
continue;
}
// Does the localusername file exist?
if (!fs::is_file(home_dir + "/" + user_folder.name + "/localusername"))
{
continue;
}
if (user_ids.size() < CELL_USERINFO_USER_MAX)
{
user_ids.push_back(user_id);
}
else
{
cellUserInfo.warning("cellUserInfoGetList: Cannot add user %s. Too many users.", user_folder.name);
}
}
if (listNum)
{
*listNum = static_cast<u32>(user_ids.size());
}
if (listBuf)
{
for (usz i = 0; i < CELL_USERINFO_USER_MAX; i++)
{
if (i < user_ids.size())
{
listBuf->userId[i] = user_ids[i];
}
else
{
listBuf->userId[i] = 0;
}
}
}
if (currentUserId)
{
// We want the int value, not the string.
*currentUserId = Emu.GetUsrId();
}
return CELL_OK;
}
DECLARE(ppu_module_manager::cellUserInfo)("cellUserInfo", []()
{
REG_FUNC(cellUserInfo, cellUserInfoGetStat);
REG_FUNC(cellUserInfo, cellUserInfoSelectUser_ListType);
REG_FUNC(cellUserInfo, cellUserInfoSelectUser_SetList);
REG_FUNC(cellUserInfo, cellUserInfoEnableOverlay);
REG_FUNC(cellUserInfo, cellUserInfoGetList);
});
| 11,468
|
C++
|
.cpp
| 341
| 30.653959
| 178
| 0.71501
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| false
| false
|
5,298
|
cellSearch.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellSearch.cpp
|
#include "stdafx.h"
#include "Emu/VFS.h"
#include "Emu/IdManager.h"
#include "Emu/Cell/PPUModule.h"
#include "cellMusic.h"
#include "cellSysutil.h"
#include <string>
#include "cellSearch.h"
#include "Utilities/StrUtil.h"
#include "util/media_utils.h"
#include <random>
LOG_CHANNEL(cellSearch);
template<>
void fmt_class_string<CellSearchError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_SEARCH_CANCELED);
STR_CASE(CELL_SEARCH_ERROR_PARAM);
STR_CASE(CELL_SEARCH_ERROR_BUSY);
STR_CASE(CELL_SEARCH_ERROR_NO_MEMORY);
STR_CASE(CELL_SEARCH_ERROR_UNKNOWN_MODE);
STR_CASE(CELL_SEARCH_ERROR_ALREADY_INITIALIZED);
STR_CASE(CELL_SEARCH_ERROR_NOT_INITIALIZED);
STR_CASE(CELL_SEARCH_ERROR_FINALIZING);
STR_CASE(CELL_SEARCH_ERROR_NOT_SUPPORTED_SEARCH);
STR_CASE(CELL_SEARCH_ERROR_CONTENT_OBSOLETE);
STR_CASE(CELL_SEARCH_ERROR_CONTENT_NOT_FOUND);
STR_CASE(CELL_SEARCH_ERROR_NOT_LIST);
STR_CASE(CELL_SEARCH_ERROR_OUT_OF_RANGE);
STR_CASE(CELL_SEARCH_ERROR_INVALID_SEARCHID);
STR_CASE(CELL_SEARCH_ERROR_ALREADY_GOT_RESULT);
STR_CASE(CELL_SEARCH_ERROR_NOT_SUPPORTED_CONTEXT);
STR_CASE(CELL_SEARCH_ERROR_INVALID_CONTENTTYPE);
STR_CASE(CELL_SEARCH_ERROR_DRM);
STR_CASE(CELL_SEARCH_ERROR_TAG);
STR_CASE(CELL_SEARCH_ERROR_GENERIC);
}
return unknown;
});
}
enum class search_state
{
not_initialized = 0,
idle,
in_progress,
initializing,
canceling,
finalizing,
};
struct search_info
{
vm::ptr<CellSearchSystemCallback> func;
vm::ptr<void> userData;
atomic_t<search_state> state = search_state::not_initialized;
shared_mutex links_mutex;
struct link_data
{
std::string path;
bool is_dir = false;
};
std::unordered_map<std::string, link_data> content_links;
};
struct search_content_t
{
CellSearchContentType type = CELL_SEARCH_CONTENTTYPE_NONE;
CellSearchRepeatMode repeat_mode = CELL_SEARCH_REPEATMODE_NONE;
CellSearchContextOption context_option = CELL_SEARCH_CONTEXTOPTION_NONE;
CellSearchTimeInfo time_info;
CellSearchContentInfoPath infoPath;
union
{
CellSearchMusicInfo music;
CellSearchPhotoInfo photo;
CellSearchVideoInfo video;
CellSearchMusicListInfo music_list;
CellSearchPhotoListInfo photo_list;
CellSearchVideoListInfo video_list;
CellSearchVideoSceneInfo scene;
} data;
ENABLE_BITWISE_SERIALIZATION;
};
using content_id_type = std::pair<u64, std::shared_ptr<search_content_t>>;
struct content_id_map
{
std::unordered_map<u64, std::shared_ptr<search_content_t>> map;
shared_mutex mutex;
SAVESTATE_INIT_POS(36);
};
struct search_object_t
{
// TODO: Figured out the correct values to set here
static const u32 id_base = 1;
static const u32 id_step = 1;
static const u32 id_count = 1024; // TODO
SAVESTATE_INIT_POS(36.1);
std::vector<content_id_type> content_ids;
};
static const std::string link_base = "/dev_hdd0/.tmp/"; // WipEout HD does not like it if we return a path starting with "/.tmp", so let's use "/dev_hdd0"
error_code check_search_state(search_state state, search_state action)
{
switch (action)
{
case search_state::initializing:
switch (state)
{
case search_state::not_initialized:
break;
case search_state::initializing:
return CELL_SEARCH_ERROR_BUSY;
case search_state::finalizing:
return CELL_SEARCH_ERROR_FINALIZING;
default:
return CELL_SEARCH_ERROR_ALREADY_INITIALIZED;
}
break;
case search_state::finalizing:
switch (state)
{
case search_state::idle:
break;
case search_state::not_initialized:
return CELL_SEARCH_ERROR_NOT_INITIALIZED;
case search_state::finalizing:
return CELL_SEARCH_ERROR_FINALIZING;
case search_state::in_progress:
case search_state::initializing:
case search_state::canceling:
return CELL_SEARCH_ERROR_BUSY;
default:
return CELL_SEARCH_ERROR_GENERIC;
}
break;
case search_state::canceling:
switch (state)
{
case search_state::in_progress:
break;
case search_state::not_initialized:
case search_state::initializing:
return CELL_SEARCH_ERROR_NOT_INITIALIZED;
case search_state::finalizing:
return CELL_SEARCH_ERROR_FINALIZING;
case search_state::canceling:
return CELL_SEARCH_ERROR_BUSY;
case search_state::idle:
return CELL_SEARCH_ERROR_ALREADY_GOT_RESULT;
default:
return CELL_SEARCH_ERROR_GENERIC;
}
break;
case search_state::in_progress:
default:
switch (state)
{
case search_state::idle:
break;
case search_state::not_initialized:
case search_state::initializing:
return CELL_SEARCH_ERROR_NOT_INITIALIZED;
case search_state::finalizing:
return CELL_SEARCH_ERROR_FINALIZING;
case search_state::in_progress:
case search_state::canceling:
return CELL_SEARCH_ERROR_BUSY;
default:
return CELL_SEARCH_ERROR_GENERIC;
}
break;
}
return CELL_OK;
}
void populate_music_info(CellSearchMusicInfo& info, const utils::media_info& mi, const fs::dir_entry& item)
{
parse_metadata(info.artistName, mi, "artist", "Unknown Artist", CELL_SEARCH_TITLE_LEN_MAX);
parse_metadata(info.albumTitle, mi, "album", "Unknown Album", CELL_SEARCH_TITLE_LEN_MAX);
parse_metadata(info.genreName, mi, "genre", "Unknown Genre", CELL_SEARCH_TITLE_LEN_MAX);
parse_metadata(info.title, mi, "title", item.name.substr(0, item.name.find_last_of('.')), CELL_SEARCH_TITLE_LEN_MAX);
parse_metadata(info.diskNumber, mi, "disc", "1/1", sizeof(info.diskNumber) - 1);
// Special case: track is usually stored as e.g. 2/11
const std::string tmp = mi.get_metadata<std::string>("track", ""s);
s64 value{};
if (tmp.empty() || !try_to_int64(&value, tmp.substr(0, tmp.find('/')).c_str(), s32{smin}, s32{smax}))
{
value = -1;
}
info.trackNumber = static_cast<s32>(value);
info.size = item.size;
info.releasedYear = static_cast<s32>(mi.get_metadata<s64>("date", -1));
info.duration = mi.duration_us / 1000; // we need microseconds
info.samplingRate = mi.sample_rate;
info.bitrate = mi.audio_bitrate_bps;
info.quantizationBitrate = mi.audio_bitrate_bps; // TODO: Assumption, verify value
info.playCount = 0; // we do not track this for now
info.lastPlayedDate = -1; // we do not track this for now
info.importedDate = -1; // we do not track this for now
info.drmEncrypted = 0; // TODO: Needs to be 1 if it's encrypted
info.status = CELL_SEARCH_CONTENTSTATUS_AVAILABLE;
// Convert AVCodecID to CellSearchCodec
switch (mi.audio_av_codec_id)
{
case 86017: // AV_CODEC_ID_MP3
info.codec = CELL_SEARCH_CODEC_MP3;
break;
case 86018: // AV_CODEC_ID_AAC
info.codec = CELL_SEARCH_CODEC_AAC;
break;
case 86019: // AV_CODEC_ID_AC3
info.codec = CELL_SEARCH_CODEC_AC3;
break;
case 86023: // AV_CODEC_ID_WMAV1
case 86024: // AV_CODEC_ID_WMAV2
info.codec = CELL_SEARCH_CODEC_WMA;
break;
case 86047: // AV_CODEC_ID_ATRAC3
info.codec = CELL_SEARCH_CODEC_AT3;
break;
case 86055: // AV_CODEC_ID_ATRAC3P
info.codec = CELL_SEARCH_CODEC_AT3P;
break;
case 88078: // AV_CODEC_ID_ATRAC3AL
//case 88079: // AV_CODEC_ID_ATRAC3PAL TODO: supported ?
info.codec = CELL_SEARCH_CODEC_ATALL;
break;
// TODO: Find out if any of this works
//case 88069: // AV_CODEC_ID_DSD_LSBF
//case 88070: // AV_CODEC_ID_DSD_MSBF
//case 88071: // AV_CODEC_ID_DSD_LSBF_PLANAR
//case 88072: // AV_CODEC_ID_DSD_MSBF_PLANAR
// info.codec = CELL_SEARCH_CODEC_DSD;
// break;
//case ???:
// info.codec = CELL_SEARCH_CODEC_WAV;
// break;
default:
info.codec = CELL_SEARCH_CODEC_UNKNOWN;
info.status = CELL_SEARCH_CONTENTSTATUS_NOT_SUPPORTED;
break;
}
cellSearch.notice("CellSearchMusicInfo:, title=%s, albumTitle=%s, artistName=%s, genreName=%s, diskNumber=%s, "
"trackNumber=%d, duration=%d, size=%d, importedDate=%d, lastPlayedDate=%d, releasedYear=%d, bitrate=%d, "
"samplingRate=%d, quantizationBitrate=%d, playCount=%d, drmEncrypted=%d, codec=%d, status=%d",
info.title, info.albumTitle, info.artistName, info.genreName, info.diskNumber,
info.trackNumber, info.duration, info.size, info.importedDate, info.lastPlayedDate, info.releasedYear, info.bitrate,
info.samplingRate, info.quantizationBitrate, info.playCount, info.drmEncrypted, info.codec, info.status);
}
void populate_video_info(CellSearchVideoInfo& info, const utils::media_info& mi, const fs::dir_entry& item)
{
parse_metadata(info.albumTitle, mi, "album", "Unknown Album", CELL_SEARCH_TITLE_LEN_MAX);
parse_metadata(info.title, mi, "title", item.name.substr(0, item.name.find_last_of('.')), CELL_SEARCH_TITLE_LEN_MAX);
info.size = item.size;
info.duration = mi.duration_us / 1000; // we need microseconds
info.audioBitrate = mi.audio_bitrate_bps;
info.videoBitrate = mi.video_bitrate_bps;
info.playCount = 0; // we do not track this for now
info.importedDate = -1; // we do not track this for now
info.takenDate = -1; // we do not track this for now
info.drmEncrypted = 0; // TODO: Needs to be 1 if it's encrypted
info.status = CELL_SEARCH_CONTENTSTATUS_AVAILABLE;
// Convert Video AVCodecID to CellSearchCodec
switch (mi.video_av_codec_id)
{
case 1: // AV_CODEC_ID_MPEG1VIDEO
info.videoCodec = CELL_SEARCH_CODEC_MPEG1;
break;
case 2: // AV_CODEC_ID_MPEG2VIDEO
info.videoCodec = CELL_SEARCH_CODEC_MPEG2;
break;
case 12: // AV_CODEC_ID_MPEG4
info.videoCodec = CELL_SEARCH_CODEC_MPEG4;
break;
case 27: // AV_CODEC_ID_H264
info.videoCodec = CELL_SEARCH_CODEC_AVC;
break;
default:
info.videoCodec = CELL_SEARCH_CODEC_UNKNOWN;
info.status = CELL_SEARCH_CONTENTSTATUS_NOT_SUPPORTED;
break;
}
// Convert Audio AVCodecID to CellSearchCodec
switch (mi.audio_av_codec_id)
{
// Let's ignore this due to CELL_SEARCH_CODEC_MPEG1_LAYER3
//case 86017: // AV_CODEC_ID_MP3
// info.audioCodec = CELL_SEARCH_CODEC_MP3;
// break;
case 86018: // AV_CODEC_ID_AAC
info.audioCodec = CELL_SEARCH_CODEC_AAC;
break;
case 86019: // AV_CODEC_ID_AC3
info.audioCodec = CELL_SEARCH_CODEC_AC3;
break;
case 86023: // AV_CODEC_ID_WMAV1
case 86024: // AV_CODEC_ID_WMAV2
info.audioCodec = CELL_SEARCH_CODEC_WMA;
break;
case 86047: // AV_CODEC_ID_ATRAC3
info.audioCodec = CELL_SEARCH_CODEC_AT3;
break;
case 86055: // AV_CODEC_ID_ATRAC3P
info.audioCodec = CELL_SEARCH_CODEC_AT3P;
break;
case 88078: // AV_CODEC_ID_ATRAC3AL
//case 88079: // AV_CODEC_ID_ATRAC3PAL TODO: supported ?
info.audioCodec = CELL_SEARCH_CODEC_ATALL;
break;
// TODO: Find out if any of this works
//case 88069: // AV_CODEC_ID_DSD_LSBF
//case 88070: // AV_CODEC_ID_DSD_MSBF
//case 88071: // AV_CODEC_ID_DSD_LSBF_PLANAR
//case 88072: // AV_CODEC_ID_DSD_MSBF_PLANAR
// info.audioCodec = CELL_SEARCH_CODEC_DSD;
// break;
//case ???:
// info.audioCodec = CELL_SEARCH_CODEC_WAV;
// break;
case 86058: // AV_CODEC_ID_MP1
info.audioCodec = CELL_SEARCH_CODEC_MPEG1_LAYER1;
break;
case 86016: // AV_CODEC_ID_MP2
info.audioCodec = CELL_SEARCH_CODEC_MPEG1_LAYER2;
break;
case 86017: // AV_CODEC_ID_MP3
info.audioCodec = CELL_SEARCH_CODEC_MPEG1_LAYER3;
break;
//case ???:
// info.audioCodec = CELL_SEARCH_CODEC_MPEG2_LAYER1;
// break;
//case ???:
// info.audioCodec = CELL_SEARCH_CODEC_MPEG2_LAYER2;
// break;
//case ???:
// info.audioCodec = CELL_SEARCH_CODEC_MPEG2_LAYER3;
// break;
default:
info.audioCodec = CELL_SEARCH_CODEC_UNKNOWN;
info.status = CELL_SEARCH_CONTENTSTATUS_NOT_SUPPORTED;
break;
}
cellSearch.notice("CellSearchVideoInfo: title='%s', albumTitle='%s', duration=%d, size=%d, importedDate=%d, takenDate=%d, "
"videoBitrate=%d, audioBitrate=%d, playCount=%d, drmEncrypted=%d, videoCodec=%d, audioCodec=%d, status=%d",
info.title, info.albumTitle, info.duration, info.size, info.importedDate, info.takenDate,
info.videoBitrate, info.audioBitrate, info.playCount, info.drmEncrypted, info.videoCodec, info.audioCodec, info.status);
}
void populate_photo_info(CellSearchPhotoInfo& info, const utils::media_info& mi, const fs::dir_entry& item)
{
// TODO - Some kinda file photo analysis and assign the values as such
info.size = item.size;
info.importedDate = -1;
info.takenDate = -1;
info.width = mi.width;
info.height = mi.height;
info.orientation = mi.orientation;
info.status = CELL_SEARCH_CONTENTSTATUS_AVAILABLE;
strcpy_trunc(info.title, item.name.substr(0, item.name.find_last_of('.')));
strcpy_trunc(info.albumTitle, "ALBUM TITLE");
const std::string sub_type = fmt::to_lower(mi.sub_type);
if (sub_type == "jpg" || sub_type == "jpeg")
{
info.codec = CELL_SEARCH_CODEC_JPEG;
}
else if (sub_type == "png")
{
info.codec = CELL_SEARCH_CODEC_PNG;
}
else if (sub_type == "tif" || sub_type == "tiff")
{
info.codec = CELL_SEARCH_CODEC_TIFF;
}
else if (sub_type == "bmp")
{
info.codec = CELL_SEARCH_CODEC_BMP;
}
else if (sub_type == "gif")
{
info.codec = CELL_SEARCH_CODEC_GIF;
}
else if (sub_type == "mpo")
{
info.codec = CELL_SEARCH_CODEC_MPO;
}
else
{
info.codec = CELL_SEARCH_CODEC_UNKNOWN;
}
cellSearch.notice("CellSearchPhotoInfo: title='%s', albumTitle='%s', size=%d, width=%d, height=%d, orientation=%d, codec=%d, status=%d, importedDate=%d, takenDate=%d",
info.title, info.albumTitle, info.size, info.width, info.height, info.orientation, info.codec, info.status, info.importedDate, info.takenDate);
}
error_code cellSearchInitialize(CellSearchMode mode, u32 container, vm::ptr<CellSearchSystemCallback> func, vm::ptr<void> userData)
{
cellSearch.warning("cellSearchInitialize(mode=0x%x, container=0x%x, func=*0x%x, userData=*0x%x)", +mode, container, func, userData);
if (mode != CELL_SEARCH_MODE_NORMAL)
{
return CELL_SEARCH_ERROR_UNKNOWN_MODE;
}
if (!func)
{
return CELL_SEARCH_ERROR_PARAM;
}
auto& search = g_fxo->get<search_info>();
if (error_code error = check_search_state(search.state.compare_and_swap(search_state::not_initialized, search_state::initializing), search_state::initializing))
{
return error;
}
search.func = func;
search.userData = userData;
sysutil_register_cb([=, &search](ppu_thread& ppu) -> s32
{
search.state.store(search_state::idle);
func(ppu, CELL_SEARCH_EVENT_INITIALIZE_RESULT, CELL_OK, vm::null, userData);
return CELL_OK;
});
return CELL_OK;
}
error_code cellSearchFinalize()
{
cellSearch.todo("cellSearchFinalize()");
auto& search = g_fxo->get<search_info>();
if (error_code error = check_search_state(search.state.compare_and_swap(search_state::idle, search_state::finalizing), search_state::finalizing))
{
return error;
}
sysutil_register_cb([&search](ppu_thread& ppu) -> s32
{
{
std::lock_guard lock(search.links_mutex);
search.content_links.clear();
}
search.state.store(search_state::not_initialized);
search.func(ppu, CELL_SEARCH_EVENT_FINALIZE_RESULT, CELL_OK, vm::null, search.userData);
return CELL_OK;
});
return CELL_OK;
}
error_code cellSearchStartListSearch(CellSearchListSearchType type, CellSearchSortOrder sortOrder, vm::ptr<CellSearchId> outSearchId)
{
cellSearch.todo("cellSearchStartListSearch(type=0x%x, sortOrder=0x%x, outSearchId=*0x%x)", +type, +sortOrder, outSearchId);
if (!outSearchId)
{
return CELL_SEARCH_ERROR_PARAM;
}
// Reset values first
*outSearchId = 0;
const char* media_dir;
switch (type)
{
case CELL_SEARCH_LISTSEARCHTYPE_MUSIC_ALBUM:
case CELL_SEARCH_LISTSEARCHTYPE_MUSIC_GENRE:
case CELL_SEARCH_LISTSEARCHTYPE_MUSIC_ARTIST:
case CELL_SEARCH_LISTSEARCHTYPE_MUSIC_PLAYLIST:
media_dir = "music";
break;
case CELL_SEARCH_LISTSEARCHTYPE_PHOTO_YEAR:
case CELL_SEARCH_LISTSEARCHTYPE_PHOTO_MONTH:
case CELL_SEARCH_LISTSEARCHTYPE_PHOTO_ALBUM:
case CELL_SEARCH_LISTSEARCHTYPE_PHOTO_PLAYLIST:
media_dir = "photo";
break;
case CELL_SEARCH_LISTSEARCHTYPE_VIDEO_ALBUM:
media_dir = "video";
break;
case CELL_SEARCH_LISTSEARCHTYPE_NONE:
default:
return CELL_SEARCH_ERROR_PARAM;
}
if (sortOrder != CELL_SEARCH_SORTORDER_ASCENDING && sortOrder != CELL_SEARCH_SORTORDER_DESCENDING)
{
return CELL_SEARCH_ERROR_PARAM;
}
if (sortOrder != CELL_SEARCH_SORTORDER_ASCENDING)
{
return CELL_SEARCH_ERROR_NOT_SUPPORTED_SEARCH;
}
auto& search = g_fxo->get<search_info>();
if (error_code error = check_search_state(search.state.compare_and_swap(search_state::idle, search_state::in_progress), search_state::in_progress))
{
return error;
}
const u32 id = *outSearchId = idm::make<search_object_t>();
sysutil_register_cb([=, &content_map = g_fxo->get<content_id_map>(), &search](ppu_thread& ppu) -> s32
{
auto curr_search = idm::get<search_object_t>(id);
vm::var<CellSearchResultParam> resultParam;
resultParam->searchId = id;
resultParam->resultNum = 0; // Set again later
std::function<void(const std::string&)> searchInFolder = [&, type](const std::string& vpath)
{
// TODO: this is just a workaround. On a real PS3 the playlists seem to be stored in dev_hdd0/mms/db/metadata_db_hdd
std::vector<fs::dir_entry> dirs_sorted;
for (auto&& entry : fs::dir(vfs::get(vpath)))
{
entry.name = vfs::unescape(entry.name);
if (entry.is_directory)
{
if (entry.name == "." || entry.name == "..")
{
continue; // these dirs are not included in the dir list
}
dirs_sorted.push_back(entry);
}
}
// clang-format off
std::sort(dirs_sorted.begin(), dirs_sorted.end(), [&](const fs::dir_entry& a, const fs::dir_entry& b) -> bool
{
switch (sortOrder)
{
case CELL_SEARCH_SORTORDER_ASCENDING:
// Order alphabetically ascending
return a.name < b.name;
case CELL_SEARCH_SORTORDER_DESCENDING:
// Order alphabetically descending
return a.name > b.name;
default:
{
return false;
}
}
});
// clang-format on
for (auto&& item : dirs_sorted)
{
item.name = vfs::unescape(item.name);
if (item.name == "." || item.name == ".." || !item.is_directory)
{
continue;
}
const std::string item_path(vpath + "/" + item.name);
// Count files
u32 numOfItems = 0;
for (auto&& file : fs::dir(vfs::get(item_path)))
{
file.name = vfs::unescape(file.name);
if (file.name == "." || file.name == ".." || file.is_directory)
{
continue;
}
numOfItems++;
}
const u64 hash = std::hash<std::string>()(item_path);
auto found = content_map.map.find(hash);
if (found == content_map.map.end()) // content isn't yet being tracked
{
std::shared_ptr<search_content_t> curr_find = std::make_shared<search_content_t>();
if (item_path.length() > CELL_SEARCH_PATH_LEN_MAX)
{
// TODO: Create mapping which will be resolved to an actual hard link in VFS by cellSearchPrepareFile
cellSearch.warning("cellSearchStartListSearch(): Directory-Path \"%s\" is too long and will be omitted: %i", item_path, item_path.length());
continue;
// const size_t ext_offset = item.name.find_last_of('.');
// std::string link = link_base + std::to_string(hash) + item.name.substr(ext_offset);
// strcpy_trunc(curr_find->infoPath.contentPath, link);
// std::lock_guard lock(search.links_mutex);
// search.content_links.emplace(std::move(link), search_info::link_data{ .path = item_path, .is_dir = true });
}
else
{
strcpy_trunc(curr_find->infoPath.contentPath, item_path);
}
if (item.name.size() > CELL_SEARCH_TITLE_LEN_MAX)
{
item.name.resize(CELL_SEARCH_TITLE_LEN_MAX);
}
switch (type)
{
case CELL_SEARCH_LISTSEARCHTYPE_MUSIC_ALBUM:
case CELL_SEARCH_LISTSEARCHTYPE_MUSIC_GENRE:
case CELL_SEARCH_LISTSEARCHTYPE_MUSIC_ARTIST:
case CELL_SEARCH_LISTSEARCHTYPE_MUSIC_PLAYLIST:
{
curr_find->type = CELL_SEARCH_CONTENTTYPE_MUSICLIST;
CellSearchMusicListInfo& info = curr_find->data.music_list;
info.listType = type; // CellSearchListType matches CellSearchListSearchType
info.numOfItems = numOfItems;
info.duration = 0;
strcpy_trunc(info.title, item.name);
strcpy_trunc(info.artistName, "ARTIST NAME");
cellSearch.notice("CellSearchMusicListInfo: title='%s', artistName='%s', listType=%d, numOfItems=%d, duration=%d",
info.title, info.artistName, info.listType, info.numOfItems, info.duration);
break;
}
case CELL_SEARCH_LISTSEARCHTYPE_PHOTO_YEAR:
case CELL_SEARCH_LISTSEARCHTYPE_PHOTO_MONTH:
case CELL_SEARCH_LISTSEARCHTYPE_PHOTO_ALBUM:
case CELL_SEARCH_LISTSEARCHTYPE_PHOTO_PLAYLIST:
{
curr_find->type = CELL_SEARCH_CONTENTTYPE_PHOTOLIST;
CellSearchPhotoListInfo& info = curr_find->data.photo_list;
info.listType = type; // CellSearchListType matches CellSearchListSearchType
info.numOfItems = numOfItems;
strcpy_trunc(info.title, item.name);
cellSearch.notice("CellSearchPhotoListInfo: title='%s', listType=%d, numOfItems=%d",
info.title, info.listType, info.numOfItems);
break;
}
case CELL_SEARCH_LISTSEARCHTYPE_VIDEO_ALBUM:
{
curr_find->type = CELL_SEARCH_CONTENTTYPE_VIDEOLIST;
CellSearchVideoListInfo& info = curr_find->data.video_list;
info.listType = type; // CellSearchListType matches CellSearchListSearchType
info.numOfItems = numOfItems;
info.duration = 0;
strcpy_trunc(info.title, item.name);
cellSearch.notice("CellSearchVideoListInfo: title='%s', listType=%d, numOfItems=%d, duration=%d",
info.title, info.listType, info.numOfItems, info.duration);
break;
}
case CELL_SEARCH_LISTSEARCHTYPE_NONE:
default:
{
// Should be unreachable, because it is already handled in the main function
break;
}
}
content_map.map.emplace(hash, curr_find);
curr_search->content_ids.emplace_back(hash, curr_find); // place this file's "ID" into the list of found types
cellSearch.notice("cellSearchStartListSearch(): CellSearchId: 0x%x, Content ID: %08X, Path: \"%s\"", id, hash, item_path);
}
else // list is already stored and tracked
{
// TODO
// Perform checks to see if the identified list has been modified since last checked
// In which case, update the stored content's properties
// auto content_found = &content_map->at(content_id);
curr_search->content_ids.emplace_back(found->first, found->second);
cellSearch.notice("cellSearchStartListSearch(): Already tracked: CellSearchId: 0x%x, Content ID: %08X, Path: \"%s\"", id, hash, item_path);
}
}
};
searchInFolder(fmt::format("/dev_hdd0/%s", media_dir));
resultParam->resultNum = ::narrow<s32>(curr_search->content_ids.size());
search.state.store(search_state::idle);
search.func(ppu, CELL_SEARCH_EVENT_LISTSEARCH_RESULT, CELL_OK, vm::cast(resultParam.addr()), search.userData);
return CELL_OK;
});
return CELL_OK;
}
error_code cellSearchStartContentSearchInList(vm::cptr<CellSearchContentId> listId, CellSearchSortKey sortKey, CellSearchSortOrder sortOrder, vm::ptr<CellSearchId> outSearchId)
{
cellSearch.todo("cellSearchStartContentSearchInList(listId=*0x%x, sortKey=0x%x, sortOrder=0x%x, outSearchId=*0x%x)", listId, +sortKey, +sortOrder, outSearchId);
// Reset values first
if (outSearchId)
{
*outSearchId = 0;
}
if (!listId || !outSearchId)
{
return CELL_SEARCH_ERROR_PARAM;
}
switch (sortKey)
{
case CELL_SEARCH_SORTKEY_DEFAULT:
case CELL_SEARCH_SORTKEY_TITLE:
case CELL_SEARCH_SORTKEY_ALBUMTITLE:
case CELL_SEARCH_SORTKEY_GENRENAME:
case CELL_SEARCH_SORTKEY_ARTISTNAME:
case CELL_SEARCH_SORTKEY_IMPORTEDDATE:
case CELL_SEARCH_SORTKEY_TRACKNUMBER:
case CELL_SEARCH_SORTKEY_TAKENDATE:
case CELL_SEARCH_SORTKEY_USERDEFINED:
case CELL_SEARCH_SORTKEY_MODIFIEDDATE:
break;
case CELL_SEARCH_SORTKEY_NONE:
default:
return CELL_SEARCH_ERROR_PARAM;
}
if (sortOrder != CELL_SEARCH_SORTORDER_ASCENDING && sortOrder != CELL_SEARCH_SORTORDER_DESCENDING)
{
return CELL_SEARCH_ERROR_PARAM;
}
auto& search = g_fxo->get<search_info>();
if (error_code error = check_search_state(search.state.compare_and_swap(search_state::idle, search_state::in_progress), search_state::in_progress))
{
return error;
}
auto& content_map = g_fxo->get<content_id_map>();
auto found = content_map.map.find(*reinterpret_cast<const u64*>(listId->data));
if (found == content_map.map.end())
{
// content ID not found, perform a search first
return CELL_SEARCH_ERROR_CONTENT_NOT_FOUND;
}
CellSearchContentSearchType type = CELL_SEARCH_CONTENTSEARCHTYPE_NONE;
const auto& content_info = found->second;
switch (content_info->type)
{
case CELL_SEARCH_CONTENTTYPE_MUSICLIST:
type = CELL_SEARCH_CONTENTSEARCHTYPE_MUSIC_ALL;
break;
case CELL_SEARCH_CONTENTTYPE_PHOTOLIST:
type = CELL_SEARCH_CONTENTSEARCHTYPE_PHOTO_ALL;
break;
case CELL_SEARCH_CONTENTTYPE_VIDEOLIST:
type = CELL_SEARCH_CONTENTSEARCHTYPE_VIDEO_ALL;
break;
case CELL_SEARCH_CONTENTTYPE_MUSIC:
case CELL_SEARCH_CONTENTTYPE_PHOTO:
case CELL_SEARCH_CONTENTTYPE_VIDEO:
case CELL_SEARCH_CONTENTTYPE_SCENE:
case CELL_SEARCH_CONTENTTYPE_NONE:
default:
return CELL_SEARCH_ERROR_NOT_LIST;
}
const u32 id = *outSearchId = idm::make<search_object_t>();
sysutil_register_cb([=, list_path = std::string(content_info->infoPath.contentPath), &search, &content_map](ppu_thread& ppu) -> s32
{
auto curr_search = idm::get<search_object_t>(id);
vm::var<CellSearchResultParam> resultParam;
resultParam->searchId = id;
resultParam->resultNum = 0; // Set again later
std::function<void(const std::string&)> searchInFolder = [&, type](const std::string& vpath)
{
std::vector<fs::dir_entry> files_sorted;
for (auto&& entry : fs::dir(vfs::get(vpath)))
{
entry.name = vfs::unescape(entry.name);
if (entry.is_directory || entry.name == "." || entry.name == "..")
{
continue;
}
files_sorted.push_back(entry);
}
// clang-format off
std::sort(files_sorted.begin(), files_sorted.end(), [&](const fs::dir_entry& a, const fs::dir_entry& b) -> bool
{
switch (sortOrder)
{
case CELL_SEARCH_SORTORDER_ASCENDING:
// Order alphabetically ascending
return a.name < b.name;
case CELL_SEARCH_SORTORDER_DESCENDING:
// Order alphabetically descending
return a.name > b.name;
default:
{
return false;
}
}
});
// clang-format on
// TODO: Use sortKey (CellSearchSortKey) to allow for sorting by category
for (auto&& item : files_sorted)
{
// TODO
// Perform first check that file is of desired type. For example, don't wanna go
// identifying "AlbumArt.jpg" as an MP3. Hrm... Postpone this thought. Do games
// perform their own checks? DIVA ignores anything without the MP3 extension.
const std::string item_path(vpath + "/" + item.name);
const u64 hash = std::hash<std::string>()(item_path);
auto found = content_map.map.find(hash);
if (found == content_map.map.end()) // content isn't yet being tracked
{
std::shared_ptr<search_content_t> curr_find = std::make_shared<search_content_t>();
if (item_path.length() > CELL_SEARCH_PATH_LEN_MAX)
{
// Create mapping which will be resolved to an actual hard link in VFS by cellSearchPrepareFile
const size_t ext_offset = item.name.find_last_of('.');
std::string link = link_base + std::to_string(hash) + item.name.substr(ext_offset);
strcpy_trunc(curr_find->infoPath.contentPath, link);
std::lock_guard lock(search.links_mutex);
search.content_links.emplace(std::move(link), search_info::link_data{ .path = item_path, .is_dir = false });
}
else
{
strcpy_trunc(curr_find->infoPath.contentPath, item_path);
}
// TODO - curr_find.infoPath.thumbnailPath
switch (type)
{
case CELL_SEARCH_CONTENTSEARCHTYPE_MUSIC_ALL:
{
curr_find->type = CELL_SEARCH_CONTENTTYPE_MUSIC;
const std::string path = vfs::get(item_path);
const auto [success, mi] = utils::get_media_info(path, 1); // AVMEDIA_TYPE_AUDIO
if (!success)
{
continue;
}
populate_music_info(curr_find->data.music, mi, item);
break;
}
case CELL_SEARCH_CONTENTSEARCHTYPE_PHOTO_ALL:
{
curr_find->type = CELL_SEARCH_CONTENTTYPE_PHOTO;
populate_photo_info(curr_find->data.photo, {}, item);
break;
}
case CELL_SEARCH_CONTENTSEARCHTYPE_VIDEO_ALL:
{
curr_find->type = CELL_SEARCH_CONTENTTYPE_VIDEO;
const std::string path = vfs::get(item_path);
const auto [success, mi] = utils::get_media_info(path, 0); // AVMEDIA_TYPE_VIDEO
if (!success)
{
continue;
}
populate_video_info(curr_find->data.video, mi, item);
break;
}
case CELL_SEARCH_CONTENTSEARCHTYPE_NONE:
default:
{
// Should be unreachable, because it is already handled in the main function
break;
}
}
content_map.map.emplace(hash, curr_find);
curr_search->content_ids.emplace_back(hash, curr_find); // place this file's "ID" into the list of found types
cellSearch.notice("cellSearchStartContentSearchInList(): CellSearchId: 0x%x, Content ID: %08X, Path: \"%s\"", id, hash, item_path);
}
else // file is already stored and tracked
{
// TODO
// Perform checks to see if the identified file has been modified since last checked
// In which case, update the stored content's properties
// auto content_found = &content_map->at(content_id);
curr_search->content_ids.emplace_back(found->first, found->second);
cellSearch.notice("cellSearchStartContentSearchInList(): Already Tracked: CellSearchId: 0x%x, Content ID: %08X, Path: \"%s\"", id, hash, item_path);
}
}
};
searchInFolder(list_path);
resultParam->resultNum = ::narrow<s32>(curr_search->content_ids.size());
search.state.store(search_state::idle);
search.func(ppu, CELL_SEARCH_EVENT_CONTENTSEARCH_INLIST_RESULT, CELL_OK, vm::cast(resultParam.addr()), search.userData);
return CELL_OK;
});
return CELL_OK;
}
error_code cellSearchStartContentSearch(CellSearchContentSearchType type, CellSearchSortKey sortKey, CellSearchSortOrder sortOrder, vm::ptr<CellSearchId> outSearchId)
{
cellSearch.todo("cellSearchStartContentSearch(type=0x%x, sortKey=0x%x, sortOrder=0x%x, outSearchId=*0x%x)", +type, +sortKey, +sortOrder, outSearchId);
// Reset values first
if (outSearchId)
{
*outSearchId = 0;
}
if (!outSearchId)
{
return CELL_SEARCH_ERROR_PARAM;
}
switch (sortKey)
{
case CELL_SEARCH_SORTKEY_DEFAULT:
case CELL_SEARCH_SORTKEY_TITLE:
case CELL_SEARCH_SORTKEY_ALBUMTITLE:
case CELL_SEARCH_SORTKEY_GENRENAME:
case CELL_SEARCH_SORTKEY_ARTISTNAME:
case CELL_SEARCH_SORTKEY_IMPORTEDDATE:
case CELL_SEARCH_SORTKEY_TRACKNUMBER:
case CELL_SEARCH_SORTKEY_TAKENDATE:
case CELL_SEARCH_SORTKEY_USERDEFINED:
case CELL_SEARCH_SORTKEY_MODIFIEDDATE:
break;
case CELL_SEARCH_SORTKEY_NONE:
default:
return CELL_SEARCH_ERROR_PARAM;
}
if (sortOrder != CELL_SEARCH_SORTORDER_ASCENDING && sortOrder != CELL_SEARCH_SORTORDER_DESCENDING)
{
return CELL_SEARCH_ERROR_PARAM;
}
const char* media_dir;
switch (type)
{
case CELL_SEARCH_CONTENTSEARCHTYPE_MUSIC_ALL: media_dir = "music"; break;
case CELL_SEARCH_CONTENTSEARCHTYPE_PHOTO_ALL: media_dir = "photo"; break;
case CELL_SEARCH_CONTENTSEARCHTYPE_VIDEO_ALL: media_dir = "video"; break;
case CELL_SEARCH_CONTENTSEARCHTYPE_NONE:
default:
return CELL_SEARCH_ERROR_PARAM;
}
auto& search = g_fxo->get<search_info>();
if (error_code error = check_search_state(search.state.compare_and_swap(search_state::idle, search_state::in_progress), search_state::in_progress))
{
return error;
}
if (sortKey == CELL_SEARCH_SORTKEY_DEFAULT)
{
switch (type)
{
case CELL_SEARCH_CONTENTSEARCHTYPE_MUSIC_ALL: sortKey = CELL_SEARCH_SORTKEY_ARTISTNAME; break;
case CELL_SEARCH_CONTENTSEARCHTYPE_PHOTO_ALL: sortKey = CELL_SEARCH_SORTKEY_TAKENDATE; break;
case CELL_SEARCH_CONTENTSEARCHTYPE_VIDEO_ALL: sortKey = CELL_SEARCH_SORTKEY_TITLE; break;
default: break;
}
}
if (sortKey != CELL_SEARCH_SORTKEY_IMPORTEDDATE && sortKey != CELL_SEARCH_SORTKEY_MODIFIEDDATE)
{
switch (type)
{
case CELL_SEARCH_CONTENTSEARCHTYPE_MUSIC_ALL:
{
if (sortOrder != CELL_SEARCH_SORTORDER_ASCENDING)
{
return CELL_SEARCH_ERROR_NOT_SUPPORTED_SEARCH;
}
if (sortKey != CELL_SEARCH_SORTKEY_ARTISTNAME &&
sortKey != CELL_SEARCH_SORTKEY_ALBUMTITLE &&
sortKey != CELL_SEARCH_SORTKEY_GENRENAME &&
sortKey != CELL_SEARCH_SORTKEY_TITLE)
{
return CELL_SEARCH_ERROR_NOT_SUPPORTED_SEARCH;
}
break;
}
case CELL_SEARCH_CONTENTSEARCHTYPE_PHOTO_ALL:
{
if (sortKey != CELL_SEARCH_SORTKEY_TAKENDATE)
{
if (sortOrder != CELL_SEARCH_SORTORDER_ASCENDING || sortKey != CELL_SEARCH_SORTKEY_TITLE)
{
return CELL_SEARCH_ERROR_NOT_SUPPORTED_SEARCH;
}
}
break;
}
case CELL_SEARCH_CONTENTSEARCHTYPE_VIDEO_ALL:
{
if (sortOrder != CELL_SEARCH_SORTORDER_ASCENDING || sortKey != CELL_SEARCH_SORTKEY_TITLE)
{
return CELL_SEARCH_ERROR_NOT_SUPPORTED_SEARCH;
}
break;
}
default: break;
}
}
const u32 id = *outSearchId = idm::make<search_object_t>();
sysutil_register_cb([=, &content_map = g_fxo->get<content_id_map>(), &search](ppu_thread& ppu) -> s32
{
auto curr_search = idm::get<search_object_t>(id);
vm::var<CellSearchResultParam> resultParam;
resultParam->searchId = id;
resultParam->resultNum = 0; // Set again later
std::function<void(const std::string&, const std::string&)> searchInFolder = [&, type](const std::string& vpath, const std::string& prev)
{
const std::string relative_vpath = (!prev.empty() ? prev + "/" : "") + vpath;
for (auto&& item : fs::dir(vfs::get(relative_vpath)))
{
item.name = vfs::unescape(item.name);
if (item.name == "." || item.name == "..")
{
continue;
}
if (item.is_directory)
{
searchInFolder(item.name, relative_vpath);
continue;
}
// TODO
// Perform first check that file is of desired type. For example, don't wanna go
// identifying "AlbumArt.jpg" as an MP3. Hrm... Postpone this thought. Do games
// perform their own checks? DIVA ignores anything without the MP3 extension.
// TODO - Identify sorting method and insert the appropriate values where applicable
const std::string item_path(relative_vpath + "/" + item.name);
const u64 hash = std::hash<std::string>()(item_path);
auto found = content_map.map.find(hash);
if (found == content_map.map.end()) // content isn't yet being tracked
{
std::shared_ptr<search_content_t> curr_find = std::make_shared<search_content_t>();
if (item_path.length() > CELL_SEARCH_PATH_LEN_MAX)
{
// Create mapping which will be resolved to an actual hard link in VFS by cellSearchPrepareFile
const size_t ext_offset = item.name.find_last_of('.');
std::string link = link_base + std::to_string(hash) + item.name.substr(ext_offset);
strcpy_trunc(curr_find->infoPath.contentPath, link);
std::lock_guard lock(search.links_mutex);
search.content_links.emplace(std::move(link), search_info::link_data{ .path = item_path, .is_dir = false });
}
else
{
strcpy_trunc(curr_find->infoPath.contentPath, item_path);
}
// TODO - curr_find.infoPath.thumbnailPath
switch (type)
{
case CELL_SEARCH_CONTENTSEARCHTYPE_MUSIC_ALL:
{
curr_find->type = CELL_SEARCH_CONTENTTYPE_MUSIC;
const std::string path = vfs::get(item_path);
const auto [success, mi] = utils::get_media_info(path, 1); // AVMEDIA_TYPE_AUDIO
if (!success)
{
continue;
}
populate_music_info(curr_find->data.music, mi, item);
break;
}
case CELL_SEARCH_CONTENTSEARCHTYPE_PHOTO_ALL:
{
curr_find->type = CELL_SEARCH_CONTENTTYPE_PHOTO;
populate_photo_info(curr_find->data.photo, {}, item);
break;
}
case CELL_SEARCH_CONTENTSEARCHTYPE_VIDEO_ALL:
{
curr_find->type = CELL_SEARCH_CONTENTTYPE_VIDEO;
const std::string path = vfs::get(item_path);
const auto [success, mi] = utils::get_media_info(path, 0); // AVMEDIA_TYPE_VIDEO
if (!success)
{
continue;
}
populate_video_info(curr_find->data.video, mi, item);
break;
}
case CELL_SEARCH_CONTENTSEARCHTYPE_NONE:
default:
{
// Should be unreachable, because it is already handled in the main function
break;
}
}
content_map.map.emplace(hash, curr_find);
curr_search->content_ids.emplace_back(hash, curr_find); // place this file's "ID" into the list of found types
cellSearch.notice("cellSearchStartContentSearch(): CellSearchId: 0x%x, Content ID: %08X, Path: \"%s\"", id, hash, item_path);
}
else // file is already stored and tracked
{
// TODO
// Perform checks to see if the identified file has been modified since last checked
// In which case, update the stored content's properties
// auto content_found = &content_map->at(content_id);
curr_search->content_ids.emplace_back(found->first, found->second);
cellSearch.notice("cellSearchStartContentSearch(): Already Tracked: CellSearchId: 0x%x, Content ID: %08X, Path: \"%s\"", id, hash, item_path);
}
}
};
searchInFolder(fmt::format("/dev_hdd0/%s", media_dir), "");
resultParam->resultNum = ::narrow<s32>(curr_search->content_ids.size());
search.state.store(search_state::idle);
search.func(ppu, CELL_SEARCH_EVENT_CONTENTSEARCH_RESULT, CELL_OK, vm::cast(resultParam.addr()), search.userData);
return CELL_OK;
});
return CELL_OK;
}
error_code cellSearchStartSceneSearchInVideo(vm::cptr<CellSearchContentId> videoId, CellSearchSceneSearchType searchType, CellSearchSortOrder sortOrder, vm::ptr<CellSearchId> outSearchId)
{
cellSearch.todo("cellSearchStartSceneSearchInVideo(videoId=*0x%x, searchType=0x%x, sortOrder=0x%x, outSearchId=*0x%x)", videoId, +searchType, +sortOrder, outSearchId);
// Reset values first
if (outSearchId)
{
*outSearchId = 0;
}
if (!videoId || !outSearchId)
{
return CELL_SEARCH_ERROR_PARAM;
}
switch (searchType)
{
case CELL_SEARCH_SCENESEARCHTYPE_CHAPTER:
case CELL_SEARCH_SCENESEARCHTYPE_CLIP_HIGHLIGHT:
case CELL_SEARCH_SCENESEARCHTYPE_CLIP_USER:
case CELL_SEARCH_SCENESEARCHTYPE_CLIP:
case CELL_SEARCH_SCENESEARCHTYPE_ALL:
break;
case CELL_SEARCH_SCENESEARCHTYPE_NONE:
default:
return CELL_SEARCH_ERROR_PARAM;
}
if (sortOrder != CELL_SEARCH_SORTORDER_ASCENDING && sortOrder != CELL_SEARCH_SORTORDER_DESCENDING)
{
return CELL_SEARCH_ERROR_PARAM;
}
auto& search = g_fxo->get<search_info>();
if (error_code error = check_search_state(search.state.compare_and_swap(search_state::idle, search_state::in_progress), search_state::in_progress))
{
return error;
}
auto& content_map = g_fxo->get<content_id_map>();
auto found = content_map.map.find(*reinterpret_cast<const u64*>(videoId->data));
if (found == content_map.map.end())
{
// content ID not found, perform a search first
return CELL_SEARCH_ERROR_CONTENT_NOT_FOUND;
}
const auto& content_info = found->second;
if (content_info->type != CELL_SEARCH_CONTENTTYPE_VIDEO)
{
return CELL_SEARCH_ERROR_INVALID_CONTENTTYPE;
}
const u32 id = *outSearchId = idm::make<search_object_t>();
sysutil_register_cb([=, &search](ppu_thread& ppu) -> s32
{
vm::var<CellSearchResultParam> resultParam;
resultParam->searchId = id;
resultParam->resultNum = 0; // TODO
search.state.store(search_state::idle);
search.func(ppu, CELL_SEARCH_EVENT_SCENESEARCH_INVIDEO_RESULT, CELL_OK, vm::cast(resultParam.addr()), search.userData);
return CELL_OK;
});
return CELL_OK;
}
error_code cellSearchStartSceneSearch(CellSearchSceneSearchType searchType, vm::cptr<char> gameTitle, vm::cpptr<char> tags, u32 tagNum, CellSearchSortKey sortKey, CellSearchSortOrder sortOrder, vm::ptr<CellSearchId> outSearchId)
{
cellSearch.todo("cellSearchStartSceneSearch(searchType=0x%x, gameTitle=%s, tags=**0x%x, tagNum=0x%x, sortKey=0x%x, sortOrder=0x%x, outSearchId=*0x%x)", +searchType, gameTitle, tags, tagNum, +sortKey, +sortOrder, outSearchId);
// Reset values first
if (outSearchId)
{
*outSearchId = 0;
}
if (!gameTitle || !outSearchId)
{
return CELL_SEARCH_ERROR_PARAM;
}
switch (searchType)
{
case CELL_SEARCH_SCENESEARCHTYPE_CHAPTER:
case CELL_SEARCH_SCENESEARCHTYPE_CLIP_HIGHLIGHT:
case CELL_SEARCH_SCENESEARCHTYPE_CLIP_USER:
case CELL_SEARCH_SCENESEARCHTYPE_CLIP:
case CELL_SEARCH_SCENESEARCHTYPE_ALL:
break;
case CELL_SEARCH_SCENESEARCHTYPE_NONE:
default:
return CELL_SEARCH_ERROR_PARAM;
}
switch (sortKey)
{
case CELL_SEARCH_SORTKEY_DEFAULT:
case CELL_SEARCH_SORTKEY_TITLE:
case CELL_SEARCH_SORTKEY_ALBUMTITLE:
case CELL_SEARCH_SORTKEY_GENRENAME:
case CELL_SEARCH_SORTKEY_ARTISTNAME:
case CELL_SEARCH_SORTKEY_IMPORTEDDATE:
case CELL_SEARCH_SORTKEY_TRACKNUMBER:
case CELL_SEARCH_SORTKEY_TAKENDATE:
case CELL_SEARCH_SORTKEY_USERDEFINED:
case CELL_SEARCH_SORTKEY_MODIFIEDDATE:
break;
case CELL_SEARCH_SORTKEY_NONE:
default:
return CELL_SEARCH_ERROR_PARAM;
}
if (tagNum) // TODO: find out if this is the correct location for these checks
{
if (tagNum > CELL_SEARCH_TAG_NUM_MAX || !tags)
{
return CELL_SEARCH_ERROR_TAG;
}
for (u32 n = 0; n < tagNum; n++)
{
if (!tags[tagNum] || !memchr(&tags[tagNum], '\0', CELL_SEARCH_TAG_LEN_MAX))
{
return CELL_SEARCH_ERROR_TAG;
}
}
}
if (sortKey != CELL_SEARCH_SORTKEY_DEFAULT &&
sortKey != CELL_SEARCH_SORTKEY_IMPORTEDDATE &&
sortKey != CELL_SEARCH_SORTKEY_MODIFIEDDATE &&
(sortKey != CELL_SEARCH_SORTKEY_TITLE || sortOrder != CELL_SEARCH_SORTORDER_ASCENDING))
{
return CELL_SEARCH_ERROR_NOT_SUPPORTED_SEARCH;
}
auto& search = g_fxo->get<search_info>();
if (error_code error = check_search_state(search.state.compare_and_swap(search_state::idle, search_state::in_progress), search_state::in_progress))
{
return error;
}
const u32 id = *outSearchId = idm::make<search_object_t>();
sysutil_register_cb([=, &search](ppu_thread& ppu) -> s32
{
vm::var<CellSearchResultParam> resultParam;
resultParam->searchId = id;
resultParam->resultNum = 0; // TODO
search.state.store(search_state::idle);
search.func(ppu, CELL_SEARCH_EVENT_SCENESEARCH_RESULT, CELL_OK, vm::cast(resultParam.addr()), search.userData);
return CELL_OK;
});
return CELL_OK;
}
error_code cellSearchGetContentInfoByOffset(CellSearchId searchId, s32 offset, vm::ptr<void> infoBuffer, vm::ptr<CellSearchContentType> outContentType, vm::ptr<CellSearchContentId> outContentId)
{
cellSearch.warning("cellSearchGetContentInfoByOffset(searchId=0x%x, offset=0x%x, infoBuffer=*0x%x, outContentType=*0x%x, outContentId=*0x%x)", searchId, offset, infoBuffer, outContentType, outContentId);
// Reset values first
if (outContentType)
{
*outContentType = CELL_SEARCH_CONTENTTYPE_NONE;
}
if (infoBuffer)
{
std::memset(infoBuffer.get_ptr(), 0, CELL_SEARCH_CONTENT_BUFFER_SIZE_MAX);
}
if (outContentId)
{
std::memset(outContentId->data, 0, 4);
std::memset(outContentId->data + 4, -1, CELL_SEARCH_CONTENT_ID_SIZE - 4);
}
const auto searchObject = idm::get<search_object_t>(searchId);
if (!searchObject)
{
return CELL_SEARCH_ERROR_INVALID_SEARCHID;
}
if (!outContentType || (!outContentId && !infoBuffer))
{
return CELL_SEARCH_ERROR_PARAM;
}
if (error_code error = check_search_state(g_fxo->get<search_info>().state.load(), search_state::in_progress))
{
return error;
}
if (offset >= 0 && offset + 0u < searchObject->content_ids.size())
{
const auto& content_id = searchObject->content_ids[offset];
const auto& content_info = content_id.second;
switch (content_info->type)
{
case CELL_SEARCH_CONTENTTYPE_MUSIC:
if (infoBuffer) std::memcpy(infoBuffer.get_ptr(), &content_info->data.music, sizeof(content_info->data.music));
break;
case CELL_SEARCH_CONTENTTYPE_PHOTO:
if (infoBuffer) std::memcpy(infoBuffer.get_ptr(), &content_info->data.photo, sizeof(content_info->data.photo));
break;
case CELL_SEARCH_CONTENTTYPE_VIDEO:
if (infoBuffer) std::memcpy(infoBuffer.get_ptr(), &content_info->data.video, sizeof(content_info->data.photo));
break;
case CELL_SEARCH_CONTENTTYPE_MUSICLIST:
if (infoBuffer) std::memcpy(infoBuffer.get_ptr(), &content_info->data.music_list, sizeof(content_info->data.music_list));
break;
case CELL_SEARCH_CONTENTTYPE_PHOTOLIST:
if (infoBuffer) std::memcpy(infoBuffer.get_ptr(), &content_info->data.photo_list, sizeof(content_info->data.photo_list));
break;
case CELL_SEARCH_CONTENTTYPE_VIDEOLIST:
if (infoBuffer) std::memcpy(infoBuffer.get_ptr(), &content_info->data.video_list, sizeof(content_info->data.video_list));
break;
case CELL_SEARCH_CONTENTTYPE_SCENE:
if (infoBuffer) std::memcpy(infoBuffer.get_ptr(), &content_info->data.scene, sizeof(content_info->data.scene));
break;
default:
return CELL_SEARCH_ERROR_GENERIC;
}
const u128 content_id_128 = content_id.first;
*outContentType = content_info->type;
if (outContentId)
{
std::memcpy(outContentId->data, &content_id_128, CELL_SEARCH_CONTENT_ID_SIZE);
}
}
else // content ID not found, perform a search first
{
return CELL_SEARCH_ERROR_OUT_OF_RANGE;
}
return CELL_OK;
}
error_code cellSearchGetContentInfoByContentId(vm::cptr<CellSearchContentId> contentId, vm::ptr<void> infoBuffer, vm::ptr<CellSearchContentType> outContentType)
{
cellSearch.warning("cellSearchGetContentInfoByContentId(contentId=*0x%x, infoBuffer=*0x%x, outContentType=*0x%x)", contentId, infoBuffer, outContentType);
// Reset values first
if (outContentType)
{
*outContentType = CELL_SEARCH_CONTENTTYPE_NONE;
}
if (infoBuffer)
{
std::memset(infoBuffer.get_ptr(), 0, CELL_SEARCH_CONTENT_BUFFER_SIZE_MAX);
}
if (!outContentType || !contentId)
{
return CELL_SEARCH_ERROR_PARAM;
}
if (error_code error = check_search_state(g_fxo->get<search_info>().state.load(), search_state::in_progress))
{
return error;
}
auto& content_map = g_fxo->get<content_id_map>();
auto found = content_map.map.find(*reinterpret_cast<const u64*>(contentId->data));
if (found != content_map.map.end())
{
const auto& content_info = found->second;
switch (content_info->type)
{
case CELL_SEARCH_CONTENTTYPE_MUSIC:
if (infoBuffer) std::memcpy(infoBuffer.get_ptr(), &content_info->data.music, sizeof(content_info->data.music));
break;
case CELL_SEARCH_CONTENTTYPE_PHOTO:
if (infoBuffer) std::memcpy(infoBuffer.get_ptr(), &content_info->data.photo, sizeof(content_info->data.photo));
break;
case CELL_SEARCH_CONTENTTYPE_VIDEO:
if (infoBuffer) std::memcpy(infoBuffer.get_ptr(), &content_info->data.video, sizeof(content_info->data.photo));
break;
case CELL_SEARCH_CONTENTTYPE_MUSICLIST:
if (infoBuffer) std::memcpy(infoBuffer.get_ptr(), &content_info->data.music_list, sizeof(content_info->data.music_list));
break;
case CELL_SEARCH_CONTENTTYPE_PHOTOLIST:
if (infoBuffer) std::memcpy(infoBuffer.get_ptr(), &content_info->data.photo_list, sizeof(content_info->data.photo_list));
break;
case CELL_SEARCH_CONTENTTYPE_VIDEOLIST:
if (infoBuffer) std::memcpy(infoBuffer.get_ptr(), &content_info->data.video_list, sizeof(content_info->data.video_list));
break;
case CELL_SEARCH_CONTENTTYPE_SCENE:
if (infoBuffer) std::memcpy(infoBuffer.get_ptr(), &content_info->data.scene, sizeof(content_info->data.scene));
break;
default:
return CELL_SEARCH_ERROR_GENERIC;
}
*outContentType = content_info->type;
}
else // content ID not found, perform a search first
{
return CELL_SEARCH_ERROR_CONTENT_NOT_FOUND;
}
return CELL_OK;
}
error_code cellSearchGetOffsetByContentId(CellSearchId searchId, vm::cptr<CellSearchContentId> contentId, vm::ptr<s32> outOffset)
{
cellSearch.warning("cellSearchGetOffsetByContentId(searchId=0x%x, contentId=*0x%x, outOffset=*0x%x)", searchId, contentId, outOffset);
if (outOffset)
{
*outOffset = -1;
}
if (error_code error = check_search_state(g_fxo->get<search_info>().state.load(), search_state::in_progress))
{
return error;
}
const auto searchObject = idm::get<search_object_t>(searchId);
if (!searchObject)
{
return CELL_SEARCH_ERROR_INVALID_SEARCHID;
}
if (!outOffset || !contentId)
{
return CELL_SEARCH_ERROR_PARAM;
}
s32 i = 0;
const u64 content_hash = *reinterpret_cast<const u64*>(contentId->data);
for (auto& content_id : searchObject->content_ids)
{
if (content_id.first == content_hash)
{
*outOffset = i;
return CELL_OK;
}
++i;
}
return CELL_SEARCH_ERROR_CONTENT_NOT_FOUND;
}
error_code cellSearchGetContentIdByOffset(CellSearchId searchId, s32 offset, vm::ptr<CellSearchContentType> outContentType, vm::ptr<CellSearchContentId> outContentId, vm::ptr<CellSearchTimeInfo> outTimeInfo)
{
cellSearch.todo("cellSearchGetContentIdByOffset(searchId=0x%x, offset=0x%x, outContentType=*0x%x, outContentId=*0x%x, outTimeInfo=*0x%x)", searchId, offset, outContentType, outContentId, outTimeInfo);
// Reset values first
if (outTimeInfo)
{
outTimeInfo->modifiedDate = -1;
outTimeInfo->takenDate = -1;
outTimeInfo->importedDate = -1;
}
if (outContentType)
{
*outContentType = CELL_SEARCH_CONTENTTYPE_NONE;
}
if (outContentId)
{
std::memset(outContentId->data, 0, 4);
std::memset(outContentId->data + 4, -1, CELL_SEARCH_CONTENT_ID_SIZE - 4);
}
const auto searchObject = idm::get<search_object_t>(searchId);
if (!searchObject)
{
return CELL_SEARCH_ERROR_INVALID_SEARCHID;
}
if (!outContentType || !outContentId)
{
return CELL_SEARCH_ERROR_PARAM;
}
if (error_code error = check_search_state(g_fxo->get<search_info>().state.load(), search_state::in_progress))
{
return error;
}
if (offset >= 0 && offset + 0u < searchObject->content_ids.size())
{
auto& content_id = ::at32(searchObject->content_ids, offset);
const u128 content_id_128 = content_id.first;
*outContentType = content_id.second->type;
std::memcpy(outContentId->data, &content_id_128, CELL_SEARCH_CONTENT_ID_SIZE);
if (outTimeInfo)
{
std::memcpy(outTimeInfo.get_ptr(), &content_id.second->time_info, sizeof(content_id.second->time_info));
}
}
else // content ID not found, perform a search first
{
return CELL_SEARCH_ERROR_OUT_OF_RANGE;
}
return CELL_OK;
}
error_code cellSearchGetContentInfoGameComment(vm::cptr<CellSearchContentId> contentId, vm::ptr<char> gameComment)
{
cellSearch.todo("cellSearchGetContentInfoGameComment(contentId=*0x%x, gameComment=*0x%x)", contentId, gameComment);
// Reset values first
if (gameComment)
{
gameComment[0] = 0;
}
if (!contentId || !gameComment)
{
return CELL_SEARCH_ERROR_PARAM;
}
// TODO: find out if this check is correct
if (error_code error = check_search_state(g_fxo->get<search_info>().state.load(), search_state::in_progress))
{
return error;
}
auto& content_map = g_fxo->get<content_id_map>();
auto found = content_map.map.find(*reinterpret_cast<const u64*>(contentId->data));
if (found == content_map.map.end())
{
// content ID not found, perform a search first
return CELL_SEARCH_ERROR_CONTENT_NOT_FOUND;
}
const auto& content_info = found->second;
switch (content_info->type)
{
case CELL_SEARCH_CONTENTTYPE_MUSIC:
case CELL_SEARCH_CONTENTTYPE_PHOTO:
case CELL_SEARCH_CONTENTTYPE_VIDEO:
break;
default:
return CELL_SEARCH_ERROR_INVALID_CONTENTTYPE;
}
// TODO: retrieve gameComment
return CELL_OK;
}
error_code cellSearchGetMusicSelectionContext(CellSearchId searchId, vm::cptr<CellSearchContentId> contentId, CellSearchRepeatMode repeatMode, CellSearchContextOption option, vm::ptr<CellMusicSelectionContext> outContext)
{
cellSearch.todo("cellSearchGetMusicSelectionContext(searchId=0x%x, contentId=*0x%x, repeatMode=0x%x, option=0x%x, outContext=*0x%x)", searchId, contentId, +repeatMode, +option, outContext);
if (!outContext)
{
return CELL_SEARCH_ERROR_PARAM;
}
// Reset values first
std::memset(outContext->data, 0, 4);
const auto searchObject = idm::get<search_object_t>(searchId);
if (!searchObject)
{
return CELL_SEARCH_ERROR_INVALID_SEARCHID;
}
auto& search = g_fxo->get<search_info>();
// TODO: find out if this check is correct
if (error_code error = check_search_state(search.state.load(), search_state::in_progress))
{
return error;
}
if (searchObject->content_ids.empty())
{
return CELL_SEARCH_ERROR_CONTENT_NOT_FOUND;
}
music_selection_context context{};
// Use the first track in order to get info about this search
const auto& first_content_id = searchObject->content_ids[0];
const auto& first_content = first_content_id.second;
ensure(first_content);
const auto get_random_content = [&searchObject, &first_content]() -> std::shared_ptr<search_content_t>
{
if (searchObject->content_ids.size() == 1)
{
return first_content;
}
std::vector<content_id_type> result;
std::sample(searchObject->content_ids.begin(), searchObject->content_ids.end(), std::back_inserter(result), 1, std::mt19937{std::random_device{}()});
ensure(result.size() == 1);
std::shared_ptr<search_content_t> content = result[0].second;
ensure(!!content);
return content;
};
if (contentId)
{
// Try to find the specified content
const u64 content_hash = *reinterpret_cast<const u64*>(contentId->data);
auto content = std::find_if(searchObject->content_ids.begin(), searchObject->content_ids.end(), [&content_hash](const content_id_type& cid){ return cid.first == content_hash; });
if (content != searchObject->content_ids.cend() && content->second)
{
// Check if the type of the found content is correct
if (content->second->type != CELL_SEARCH_CONTENTTYPE_MUSIC)
{
return { CELL_SEARCH_ERROR_INVALID_CONTENTTYPE, "Type: %d, Expected: CELL_SEARCH_CONTENTTYPE_MUSIC"};
}
// Check if the type of the found content matches our search content type
if (content->second->type != first_content->type)
{
return { CELL_SEARCH_ERROR_NOT_SUPPORTED_CONTEXT, "Type: %d, Expected: %d", +content->second->type, +first_content->type };
}
// Use the found content
context.playlist.push_back(content->second->infoPath.contentPath);
cellSearch.notice("cellSearchGetMusicSelectionContext(): Hash=%08X, Assigning found track: Type=0x%x, Path=%s", content_hash, +content->second->type, context.playlist.back());
}
else if (first_content->type == CELL_SEARCH_CONTENTTYPE_MUSICLIST)
{
// Abort if we can't find the playlist.
return { CELL_SEARCH_ERROR_CONTENT_NOT_FOUND, "Type: CELL_SEARCH_CONTENTTYPE_MUSICLIST" };
}
else if (option == CELL_SEARCH_CONTEXTOPTION_SHUFFLE)
{
// Select random track
// TODO: whole playlist
std::shared_ptr<search_content_t> content = get_random_content();
context.playlist.push_back(content->infoPath.contentPath);
cellSearch.notice("cellSearchGetMusicSelectionContext(): Hash=%08X, Assigning random track: Type=0x%x, Path=%s", content_hash, +content->type, context.playlist.back());
}
else
{
// Select the first track by default
// TODO: whole playlist
context.playlist.push_back(first_content->infoPath.contentPath);
cellSearch.notice("cellSearchGetMusicSelectionContext(): Hash=%08X, Assigning first track: Type=0x%x, Path=%s", content_hash, +first_content->type, context.playlist.back());
}
}
else if (first_content->type == CELL_SEARCH_CONTENTTYPE_MUSICLIST)
{
// Abort if we don't have the necessary info to select a playlist.
return { CELL_SEARCH_ERROR_NOT_SUPPORTED_CONTEXT, "Type: CELL_SEARCH_CONTENTTYPE_MUSICLIST" };
}
else if (option == CELL_SEARCH_CONTEXTOPTION_SHUFFLE)
{
// Select random track
// TODO: whole playlist
std::shared_ptr<search_content_t> content = get_random_content();
context.playlist.push_back(content->infoPath.contentPath);
cellSearch.notice("cellSearchGetMusicSelectionContext(): Assigning random track: Type=0x%x, Path=%s", +content->type, context.playlist.back());
}
else
{
// Select the first track by default
// TODO: whole playlist
context.playlist.push_back(first_content->infoPath.contentPath);
cellSearch.notice("cellSearchGetMusicSelectionContext(): Assigning first track: Type=0x%x, Path=%s", +first_content->type, context.playlist.back());
}
context.content_type = first_content->type;
context.repeat_mode = repeatMode;
context.context_option = option;
// TODO: context.first_track = ?;
// Resolve hashed paths
for (std::string& track : context.playlist)
{
if (auto found = search.content_links.find(track); found != search.content_links.end())
{
track = found->second.path;
}
}
context.create_playlist(music_selection_context::get_next_hash());
*outContext = context.get();
cellSearch.success("cellSearchGetMusicSelectionContext: found selection context: %d", context.to_string());
return CELL_OK;
}
error_code cellSearchGetMusicSelectionContextOfSingleTrack(vm::cptr<CellSearchContentId> contentId, vm::ptr<CellMusicSelectionContext> outContext)
{
cellSearch.todo("cellSearchGetMusicSelectionContextOfSingleTrack(contentId=*0x%x, outContext=*0x%x)", contentId, outContext);
// Reset values first
if (outContext)
{
std::memset(outContext->data, 0, 4);
}
if (!contentId || !outContext)
{
return CELL_SEARCH_ERROR_PARAM;
}
auto& search = g_fxo->get<search_info>();
// TODO: find out if this check is correct
if (error_code error = check_search_state(search.state.load(), search_state::in_progress))
{
return error;
}
auto& content_map = g_fxo->get<content_id_map>();
auto found = content_map.map.find(*reinterpret_cast<const u64*>(contentId->data));
if (found == content_map.map.end())
{
// content ID not found, perform a search first
return CELL_SEARCH_ERROR_CONTENT_NOT_FOUND;
}
const auto& content_info = found->second;
if (content_info->type != CELL_SEARCH_CONTENTTYPE_MUSIC)
{
return CELL_SEARCH_ERROR_INVALID_CONTENTTYPE;
}
music_selection_context context{};
context.playlist.push_back(content_info->infoPath.contentPath);
context.repeat_mode = content_info->repeat_mode;
context.context_option = content_info->context_option;
// Resolve hashed paths
for (std::string& track : context.playlist)
{
if (auto found = search.content_links.find(track); found != search.content_links.end())
{
track = found->second.path;
}
}
context.create_playlist(music_selection_context::get_next_hash());
*outContext = context.get();
cellSearch.success("cellSearchGetMusicSelectionContextOfSingleTrack: found selection context: %s", context.to_string());
return CELL_OK;
}
error_code cellSearchGetContentInfoPath(vm::cptr<CellSearchContentId> contentId, vm::ptr<CellSearchContentInfoPath> infoPath)
{
cellSearch.todo("cellSearchGetContentInfoPath(contentId=*0x%x, infoPath=*0x%x)", contentId, infoPath);
// Reset values first
if (infoPath)
{
*infoPath = {};
}
if (!contentId || !infoPath)
{
return CELL_SEARCH_ERROR_PARAM;
}
if (error_code error = check_search_state(g_fxo->get<search_info>().state.load(), search_state::in_progress))
{
return error;
}
const u64 id = *reinterpret_cast<const u64*>(contentId->data);
auto& content_map = g_fxo->get<content_id_map>();
auto found = content_map.map.find(id);
if (found != content_map.map.end())
{
std::memcpy(infoPath.get_ptr(), &found->second->infoPath, sizeof(found->second->infoPath));
}
else
{
cellSearch.error("cellSearchGetContentInfoPath(): ID not found : 0x%08X", id);
return CELL_SEARCH_ERROR_CONTENT_NOT_FOUND;
}
cellSearch.success("contentId=%08X, contentPath=\"%s\"", id, infoPath->contentPath);
return CELL_OK;
}
error_code cellSearchGetContentInfoPathMovieThumb(vm::cptr<CellSearchContentId> contentId, vm::ptr<CellSearchContentInfoPathMovieThumb> infoMt)
{
cellSearch.todo("cellSearchGetContentInfoPathMovieThumb(contentId=*0x%x, infoMt=*0x%x)", contentId, infoMt);
// Reset values first
if (infoMt)
{
*infoMt = {};
}
if (!contentId || !infoMt)
{
return CELL_SEARCH_ERROR_PARAM;
}
// TODO: find out if this check is correct
if (error_code error = check_search_state(g_fxo->get<search_info>().state.load(), search_state::in_progress))
{
return error;
}
auto& content_map = g_fxo->get<content_id_map>();
auto found = content_map.map.find(*reinterpret_cast<const u64*>(contentId->data));
if (found == content_map.map.end())
{
// content ID not found, perform a search first
return CELL_SEARCH_ERROR_CONTENT_NOT_FOUND;
}
const auto& content_info = found->second;
if (content_info->type != CELL_SEARCH_CONTENTTYPE_VIDEO)
{
return CELL_SEARCH_ERROR_INVALID_CONTENTTYPE;
}
strcpy_trunc(infoMt->movieThumbnailPath, content_info->infoPath.thumbnailPath);
// TODO: set infoMt->movieThumbnailOption
return CELL_OK;
}
error_code cellSearchPrepareFile(vm::cptr<char> path)
{
cellSearch.todo("cellSearchPrepareFile(path=%s)", path);
if (!path)
{
return CELL_SEARCH_ERROR_PARAM;
}
auto& search = g_fxo->get<search_info>();
if (error_code error = check_search_state(search.state.load(), search_state::in_progress))
{
return error;
}
reader_lock lock(search.links_mutex);
auto found = search.content_links.find(path.get_ptr());
if (found != search.content_links.end())
{
vfs::mount(found->first, vfs::get(found->second.path), found->second.is_dir);
}
return CELL_OK;
}
error_code cellSearchGetContentInfoDeveloperData(vm::cptr<CellSearchContentId> contentId, vm::ptr<char> developerData)
{
cellSearch.todo("cellSearchGetContentInfoDeveloperData(contentId=*0x%x, developerData=*0x%x)", contentId, developerData);
// Reset values first
if (developerData)
{
developerData[0] = 0;
}
if (!contentId || !developerData)
{
return CELL_SEARCH_ERROR_PARAM;
}
// TODO: find out if this check is correct
if (error_code error = check_search_state(g_fxo->get<search_info>().state.load(), search_state::in_progress))
{
return error;
}
auto& content_map = g_fxo->get<content_id_map>();
auto found = content_map.map.find(*reinterpret_cast<const u64*>(contentId->data));
if (found == content_map.map.end())
{
// content ID not found, perform a search first
return CELL_SEARCH_ERROR_CONTENT_NOT_FOUND;
}
const auto& content_info = found->second;
switch (content_info->type)
{
case CELL_SEARCH_CONTENTTYPE_VIDEO:
case CELL_SEARCH_CONTENTTYPE_SCENE:
break;
default:
return CELL_SEARCH_ERROR_INVALID_CONTENTTYPE;
}
// TODO: retrieve developerData
return CELL_OK;
}
error_code cellSearchGetContentInfoSharable(vm::cptr<CellSearchContentId> contentId, vm::ptr<CellSearchSharableType> sharable)
{
cellSearch.todo("cellSearchGetContentInfoSharable(contentId=*0x%x, sharable=*0x%x)", contentId, sharable);
// Reset values first
if (sharable)
{
*sharable = CELL_SEARCH_SHARABLETYPE_PROHIBITED;
}
if (!contentId || !sharable)
{
return CELL_SEARCH_ERROR_PARAM;
}
// TODO: find out if this check is correct
if (error_code error = check_search_state(g_fxo->get<search_info>().state.load(), search_state::in_progress))
{
return error;
}
auto& content_map = g_fxo->get<content_id_map>();
auto found = content_map.map.find(*reinterpret_cast<const u64*>(contentId->data));
if (found == content_map.map.end())
{
// content ID not found, perform a search first
return CELL_SEARCH_ERROR_CONTENT_NOT_FOUND;
}
const auto& content_info = found->second;
if (content_info->type != CELL_SEARCH_CONTENTTYPE_VIDEO)
{
return CELL_SEARCH_ERROR_INVALID_CONTENTTYPE;
}
// TODO: retrieve sharable
*sharable = CELL_SEARCH_SHARABLETYPE_PROHIBITED;
return CELL_OK;
}
error_code cellSearchCancel(CellSearchId searchId)
{
cellSearch.todo("cellSearchCancel(searchId=0x%x)", searchId);
const auto searchObject = idm::get<search_object_t>(searchId);
if (!searchObject)
{
return CELL_SEARCH_ERROR_INVALID_SEARCHID;
}
if (error_code error = check_search_state(g_fxo->get<search_info>().state.load(), search_state::canceling))
{
return error;
}
// TODO
return CELL_OK;
}
error_code cellSearchEnd(CellSearchId searchId)
{
cellSearch.todo("cellSearchEnd(searchId=0x%x)", searchId);
if (!searchId) // This check has to come first
{
return CELL_SEARCH_ERROR_INVALID_SEARCHID;
}
if (error_code error = check_search_state(g_fxo->get<search_info>().state.load(), search_state::finalizing))
{
return error;
}
const auto searchObject = idm::get<search_object_t>(searchId);
if (!searchObject)
{
return CELL_SEARCH_ERROR_INVALID_SEARCHID;
}
idm::remove<search_object_t>(searchId);
return CELL_OK;
}
DECLARE(ppu_module_manager::cellSearch)("cellSearchUtility", []()
{
REG_FUNC(cellSearchUtility, cellSearchInitialize);
REG_FUNC(cellSearchUtility, cellSearchFinalize);
REG_FUNC(cellSearchUtility, cellSearchStartListSearch);
REG_FUNC(cellSearchUtility, cellSearchStartContentSearchInList);
REG_FUNC(cellSearchUtility, cellSearchStartContentSearch);
REG_FUNC(cellSearchUtility, cellSearchStartSceneSearchInVideo);
REG_FUNC(cellSearchUtility, cellSearchStartSceneSearch);
REG_FUNC(cellSearchUtility, cellSearchGetContentInfoByOffset);
REG_FUNC(cellSearchUtility, cellSearchGetContentInfoByContentId);
REG_FUNC(cellSearchUtility, cellSearchGetOffsetByContentId);
REG_FUNC(cellSearchUtility, cellSearchGetContentIdByOffset);
REG_FUNC(cellSearchUtility, cellSearchGetContentInfoGameComment);
REG_FUNC(cellSearchUtility, cellSearchGetMusicSelectionContext);
REG_FUNC(cellSearchUtility, cellSearchGetMusicSelectionContextOfSingleTrack);
REG_FUNC(cellSearchUtility, cellSearchGetContentInfoPath);
REG_FUNC(cellSearchUtility, cellSearchGetContentInfoPathMovieThumb);
REG_FUNC(cellSearchUtility, cellSearchPrepareFile);
REG_FUNC(cellSearchUtility, cellSearchGetContentInfoDeveloperData);
REG_FUNC(cellSearchUtility, cellSearchGetContentInfoSharable);
REG_FUNC(cellSearchUtility, cellSearchCancel);
REG_FUNC(cellSearchUtility, cellSearchEnd);
});
// Helper
error_code music_selection_context::find_content_id(vm::ptr<CellSearchContentId> contents_id)
{
if (!contents_id)
return CELL_MUSIC_ERROR_PARAM;
// Search for the content that matches our current selection
auto& content_map = g_fxo->get<content_id_map>();
std::shared_ptr<search_content_t> found_content;
u64 hash = 0;
for (const std::string& track : playlist)
{
if (content_type == CELL_SEARCH_CONTENTTYPE_MUSICLIST)
{
hash = std::hash<std::string>()(fs::get_parent_dir(track));
}
else
{
hash = std::hash<std::string>()(track);
}
if (auto found = content_map.map.find(hash); found != content_map.map.end())
{
found_content = found->second;
break;
}
}
if (found_content)
{
// TODO: check if the content type is correct
const u128 content_id_128 = hash;
std::memcpy(contents_id->data, &content_id_128, CELL_SEARCH_CONTENT_ID_SIZE);
cellSearch.warning("find_content_id: found existing content for %s (path control: '%s')", to_string(), found_content->infoPath.contentPath);
return CELL_OK;
}
// Try to find the content manually
auto& search = g_fxo->get<search_info>();
const std::string music_dir = "/dev_hdd0/music/";
const std::string vfs_music_dir = vfs::get(music_dir);
for (auto&& entry : fs::dir(vfs_music_dir))
{
entry.name = vfs::unescape(entry.name);
if (!entry.is_directory || entry.name == "." || entry.name == "..")
{
continue;
}
const std::string dir_path = music_dir + entry.name;
const std::string vfs_dir_path = vfs_music_dir + entry.name;
if (content_type == CELL_SEARCH_CONTENTTYPE_MUSICLIST)
{
const u64 dir_hash = std::hash<std::string>()(dir_path);
if (hash == dir_hash)
{
u32 num_of_items = 0;
for (auto&& file : fs::dir(vfs_dir_path))
{
file.name = vfs::unescape(file.name);
if (file.is_directory || file.name == "." || file.name == "..")
{
continue;
}
num_of_items++;
}
// TODO: check for actual content inside the directory
std::shared_ptr<search_content_t> curr_find = std::make_shared<search_content_t>();
curr_find->type = CELL_SEARCH_CONTENTTYPE_MUSICLIST;
curr_find->repeat_mode = repeat_mode;
curr_find->context_option = context_option;
if (dir_path.length() > CELL_SEARCH_PATH_LEN_MAX)
{
// Create mapping which will be resolved to an actual hard link in VFS by cellSearchPrepareFile
std::string link = link_base + std::to_string(hash) + entry.name;
strcpy_trunc(curr_find->infoPath.contentPath, link);
std::lock_guard lock(search.links_mutex);
search.content_links.emplace(std::move(link), search_info::link_data{ .path = dir_path, .is_dir = true });
}
else
{
strcpy_trunc(curr_find->infoPath.contentPath, dir_path);
}
CellSearchMusicListInfo& info = curr_find->data.music_list;
info.listType = CELL_SEARCH_LISTSEARCHTYPE_MUSIC_ALBUM;
info.numOfItems = num_of_items;
info.duration = 0;
strcpy_trunc(info.title, entry.name);
strcpy_trunc(info.artistName, "ARTIST NAME");
content_map.map.emplace(dir_hash, curr_find);
const u128 content_id_128 = dir_hash;
std::memcpy(contents_id->data, &content_id_128, CELL_SEARCH_CONTENT_ID_SIZE);
cellSearch.warning("find_content_id: found music list %s (path control: '%s')", to_string(), dir_path);
return CELL_OK;
}
continue;
}
// Search the subfolders. We assume all music is located in a depth of 2 (max_depth, root + 1 folder + file).
for (auto&& item : fs::dir(vfs_dir_path))
{
if (item.is_directory || item.name == "." || item.name == "..")
{
continue;
}
const std::string file_path = dir_path + "/" + item.name;
const u64 file_hash = std::hash<std::string>()(file_path);
if (hash == file_hash)
{
const auto [success, mi] = utils::get_media_info(vfs_dir_path + "/" + item.name, 1); // AVMEDIA_TYPE_AUDIO
if (!success)
{
continue;
}
std::shared_ptr<search_content_t> curr_find = std::make_shared<search_content_t>();
curr_find->type = CELL_SEARCH_CONTENTTYPE_MUSIC;
curr_find->repeat_mode = repeat_mode;
curr_find->context_option = context_option;
if (file_path.length() > CELL_SEARCH_PATH_LEN_MAX)
{
// Create mapping which will be resolved to an actual hard link in VFS by cellSearchPrepareFile
const size_t ext_offset = item.name.find_last_of('.');
std::string link = link_base + std::to_string(hash) + item.name.substr(ext_offset);
strcpy_trunc(curr_find->infoPath.contentPath, link);
std::lock_guard lock(search.links_mutex);
search.content_links.emplace(std::move(link), search_info::link_data{ .path = file_path, .is_dir = false });
}
else
{
strcpy_trunc(curr_find->infoPath.contentPath, file_path);
}
populate_music_info(curr_find->data.music, mi, item);
content_map.map.emplace(file_hash, curr_find);
const u128 content_id_128 = file_hash;
std::memcpy(contents_id->data, &content_id_128, CELL_SEARCH_CONTENT_ID_SIZE);
cellSearch.warning("find_content_id: found music track %s (path control: '%s')", to_string(), file_path);
return CELL_OK;
}
}
}
// content ID not found
return CELL_SEARCH_ERROR_CONTENT_NOT_FOUND;
}
| 71,072
|
C++
|
.cpp
| 1,941
| 33.309634
| 228
| 0.7227
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| false
| false
|
5,299
|
cellRtc.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellRtc.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
#include "cellRtc.h"
#include "Emu/Cell/lv2/sys_time.h"
#include "Emu/Cell/lv2/sys_memory.h"
#include "Emu/Cell/lv2/sys_ss.h"
LOG_CHANNEL(cellRtc);
template <>
void fmt_class_string<CellRtcError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_RTC_ERROR_NOT_INITIALIZED);
STR_CASE(CELL_RTC_ERROR_INVALID_POINTER);
STR_CASE(CELL_RTC_ERROR_INVALID_VALUE);
STR_CASE(CELL_RTC_ERROR_INVALID_ARG);
STR_CASE(CELL_RTC_ERROR_NOT_SUPPORTED);
STR_CASE(CELL_RTC_ERROR_NO_CLOCK);
STR_CASE(CELL_RTC_ERROR_BAD_PARSE);
STR_CASE(CELL_RTC_ERROR_INVALID_YEAR);
STR_CASE(CELL_RTC_ERROR_INVALID_MONTH);
STR_CASE(CELL_RTC_ERROR_INVALID_DAY);
STR_CASE(CELL_RTC_ERROR_INVALID_HOUR);
STR_CASE(CELL_RTC_ERROR_INVALID_MINUTE);
STR_CASE(CELL_RTC_ERROR_INVALID_SECOND);
STR_CASE(CELL_RTC_ERROR_INVALID_MICROSECOND);
}
return unknown;
});
}
static inline char ascii(u8 num)
{
return num + '0';
}
static inline s8 digit(char c)
{
return c - '0';
}
static bool is_leap_year(u32 year)
{
return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
}
error_code cellRtcGetCurrentTick(ppu_thread& ppu, vm::ptr<CellRtcTick> pTick)
{
cellRtc.trace("cellRtcGetCurrentTick(pTick=*0x%x)", pTick);
const vm::var<sys_page_attr_t> page_attr;
if (sys_memory_get_page_attribute(ppu, pTick.addr(), page_attr) != CELL_OK)
{
return CELL_RTC_ERROR_INVALID_POINTER;
}
vm::var<s64> sec;
vm::var<s64> nsec;
error_code ret = sys_time_get_current_time(sec, nsec);
if (ret < CELL_OK)
{
return ret;
}
pTick->tick = *nsec / 1000 + *sec * cellRtcGetTickResolution() + RTC_MAGIC_OFFSET;
return CELL_OK;
}
error_code cellRtcGetCurrentClock(ppu_thread& ppu, vm::ptr<CellRtcDateTime> pClock, s32 iTimeZone)
{
cellRtc.notice("cellRtcGetCurrentClock(pClock=*0x%x, iTimeZone=%d)", pClock, iTimeZone);
const vm::var<sys_page_attr_t> page_attr;
if (sys_memory_get_page_attribute(ppu, pClock.addr(), page_attr) != CELL_OK)
{
return CELL_RTC_ERROR_INVALID_POINTER;
}
vm::var<CellRtcTick> tick;
if (sys_memory_get_page_attribute(ppu, tick.addr(), page_attr) != CELL_OK)
{
return CELL_RTC_ERROR_INVALID_POINTER;
}
vm::var<s64> sec;
vm::var<s64> nsec;
error_code ret = sys_time_get_current_time(sec, nsec);
if (ret < CELL_OK)
{
return ret;
}
tick->tick = *nsec / 1000 + *sec * cellRtcGetTickResolution() + RTC_MAGIC_OFFSET;
cellRtcTickAddMinutes(ppu, tick, tick, iTimeZone);
cellRtcSetTick(ppu, pClock, tick);
return CELL_OK;
}
error_code cellRtcGetCurrentClockLocalTime(ppu_thread& ppu, vm::ptr<CellRtcDateTime> pClock)
{
cellRtc.trace("cellRtcGetCurrentClockLocalTime(pClock=*0x%x)", pClock);
const vm::var<sys_page_attr_t> page_attr;
if (sys_memory_get_page_attribute(ppu, pClock.addr(), page_attr) != CELL_OK)
{
return CELL_RTC_ERROR_INVALID_POINTER;
}
vm::var<s32> timezone;
vm::var<s32> summertime;
error_code ret = sys_time_get_timezone(timezone, summertime);
if (ret < CELL_OK)
{
return ret;
}
if (sys_memory_get_page_attribute(ppu, pClock.addr(), page_attr) != CELL_OK) // Should always evaluate to false, already checked above
{
return CELL_RTC_ERROR_INVALID_POINTER;
}
vm::var<CellRtcTick> tick;
if (sys_memory_get_page_attribute(ppu, tick.addr(), page_attr) != CELL_OK)
{
return CELL_RTC_ERROR_INVALID_POINTER;
}
vm::var<s64> sec;
vm::var<s64> nsec;
ret = sys_time_get_current_time(sec, nsec);
if (ret < CELL_OK)
{
return ret;
}
tick->tick = *nsec / 1000 + *sec * cellRtcGetTickResolution() + RTC_MAGIC_OFFSET;
cellRtcTickAddMinutes(ppu, tick, tick, *timezone + *summertime);
cellRtcSetTick(ppu, pClock, tick);
return CELL_OK;
}
error_code cellRtcFormatRfc2822(ppu_thread& ppu, vm::ptr<char> pszDateTime, vm::cptr<CellRtcTick> pUtc, s32 iTimeZone)
{
cellRtc.notice("cellRtcFormatRfc2822(pszDateTime=*0x%x, pUtc=*0x%x, iTimeZone=%d)", pszDateTime, pUtc, iTimeZone);
const vm::var<sys_page_attr_t> page_attr;
if (sys_memory_get_page_attribute(ppu, pszDateTime.addr(), page_attr) != CELL_OK)
{
return CELL_RTC_ERROR_INVALID_POINTER;
}
if (sys_memory_get_page_attribute(ppu, pUtc.addr(), page_attr) != CELL_OK)
{
return CELL_RTC_ERROR_INVALID_POINTER;
}
vm::var<CellRtcTick> rtc_tick;
if (!pUtc) // Should always evaluate to false, nullptr was already checked above
{
cellRtcGetCurrentTick(ppu, rtc_tick);
}
else
{
rtc_tick->tick = pUtc->tick;
}
vm::var<CellRtcDateTime> date_time;
cellRtcTickAddMinutes(ppu, rtc_tick, rtc_tick, iTimeZone);
cellRtcSetTick(ppu, date_time, rtc_tick);
error_code ret = cellRtcCheckValid(date_time);
if (ret != CELL_OK)
{
return ret;
}
s32 weekdayIdx = cellRtcGetDayOfWeek(date_time->year, date_time->month, date_time->day);
// Day name
pszDateTime[0] = std::toupper(WEEKDAY_NAMES[weekdayIdx][0]);
pszDateTime[1] = WEEKDAY_NAMES[weekdayIdx][1];
pszDateTime[2] = WEEKDAY_NAMES[weekdayIdx][2];
pszDateTime[3] = ',';
pszDateTime[4] = ' ';
// Day number
pszDateTime[5] = ascii(date_time->day / 10);
pszDateTime[6] = ascii(date_time->day % 10);
pszDateTime[7] = ' ';
// month name
pszDateTime[8] = std::toupper(MONTH_NAMES[date_time->month - 1][0]);
pszDateTime[9] = MONTH_NAMES[date_time->month - 1][1];
pszDateTime[10] = MONTH_NAMES[date_time->month - 1][2];
pszDateTime[0xb] = ' ';
// year
pszDateTime[0xc] = ascii(date_time->year / 1000);
pszDateTime[0xd] = ascii(date_time->year / 100 % 10);
pszDateTime[0xe] = ascii(date_time->year / 10 % 10);
pszDateTime[0xf] = ascii(date_time->year % 10);
pszDateTime[0x10] = ' ';
// Hours
pszDateTime[0x11] = ascii(date_time->hour / 10);
pszDateTime[0x12] = ascii(date_time->hour % 10);
pszDateTime[0x13] = ':';
// Minutes
pszDateTime[0x14] = ascii(date_time->minute / 10);
pszDateTime[0x15] = ascii(date_time->minute % 10);
pszDateTime[0x16] = ':';
// Seconds
pszDateTime[0x17] = ascii(date_time->second / 10);
pszDateTime[0x18] = ascii(date_time->second % 10);
pszDateTime[0x19] = ' ';
// Timezone -/+
if (iTimeZone < 0)
{
iTimeZone = -iTimeZone;
pszDateTime[0x1a] = '-';
}
else
{
pszDateTime[0x1a] = '+';
}
const u32 time_zone_hours = iTimeZone / 60 % 100;
const u32 time_zone_minutes = iTimeZone % 60;
pszDateTime[0x1b] = ascii(time_zone_hours / 10);
pszDateTime[0x1c] = ascii(time_zone_hours % 10);
pszDateTime[0x1d] = ascii(time_zone_minutes / 10);
pszDateTime[0x1e] = ascii(time_zone_minutes % 10);
pszDateTime[0x1f] = '\0';
return CELL_OK;
}
error_code cellRtcFormatRfc2822LocalTime(ppu_thread& ppu, vm::ptr<char> pszDateTime, vm::cptr<CellRtcTick> pUtc)
{
cellRtc.notice("cellRtcFormatRfc2822LocalTime(pszDateTime=*0x%x, pUtc=*0x%x)", pszDateTime, pUtc);
const vm::var<sys_page_attr_t> page_attr;
if (sys_memory_get_page_attribute(ppu, pszDateTime.addr(), page_attr) != CELL_OK)
{
return CELL_RTC_ERROR_INVALID_POINTER;
}
if (sys_memory_get_page_attribute(ppu, pUtc.addr(), page_attr) != CELL_OK)
{
return CELL_RTC_ERROR_INVALID_POINTER;
}
vm::var<s32> timezone;
vm::var<s32> summertime;
error_code ret = sys_time_get_timezone(timezone, summertime);
if (ret < CELL_OK)
{
return ret;
}
return cellRtcFormatRfc2822(ppu, pszDateTime, pUtc, *timezone + *summertime);
}
error_code cellRtcFormatRfc3339(ppu_thread& ppu, vm::ptr<char> pszDateTime, vm::cptr<CellRtcTick> pUtc, s32 iTimeZone)
{
cellRtc.notice("cellRtcFormatRfc3339(pszDateTime=*0x%x, pUtc=*0x%x, iTimeZone=%d)", pszDateTime, pUtc, iTimeZone);
const vm::var<sys_page_attr_t> page_attr;
if (sys_memory_get_page_attribute(ppu, pszDateTime.addr(), page_attr) != CELL_OK)
{
return CELL_RTC_ERROR_INVALID_POINTER;
}
if (sys_memory_get_page_attribute(ppu, pUtc.addr(), page_attr) != CELL_OK)
{
return CELL_RTC_ERROR_INVALID_POINTER;
}
vm::var<CellRtcTick> rtc_tick;
if (!pUtc) // Should always evaluate to false, nullptr was already checked above
{
cellRtcGetCurrentTick(ppu, rtc_tick);
}
else
{
rtc_tick->tick = pUtc->tick;
}
vm::var<CellRtcDateTime> date_time;
cellRtcTickAddMinutes(ppu, rtc_tick, rtc_tick, iTimeZone);
cellRtcSetTick(ppu, date_time, rtc_tick);
error_code ret = cellRtcCheckValid(date_time);
if (ret != CELL_OK)
{
return ret;
}
// Year - XXXX-04-13T10:56:31.35+66:40
pszDateTime[0x0] = ascii(date_time->year / 1000);
pszDateTime[0x1] = ascii(date_time->year / 100 % 10);
pszDateTime[0x2] = ascii(date_time->year / 10 % 10);
pszDateTime[0x3] = ascii(date_time->year % 10);
pszDateTime[0x4] = '-';
// Month - 2020-XX-13T10:56:31.35+66:40
pszDateTime[0x5] = ascii(date_time->month / 10);
pszDateTime[0x6] = ascii(date_time->month % 10);
pszDateTime[0x7] = '-';
// Day - 2020-04-XXT10:56:31.35+66:40
pszDateTime[0x8] = ascii(date_time->day / 10);
pszDateTime[0x9] = ascii(date_time->day % 10);
pszDateTime[0xa] = 'T';
// Hours - 2020-04-13TXX:56:31.35+66:40
pszDateTime[0xb] = ascii(date_time->hour / 10);
pszDateTime[0xc] = ascii(date_time->hour % 10);
pszDateTime[0xd] = ':';
// Minutes - 2020-04-13T10:XX:31.35+66:40
pszDateTime[0xe] = ascii(date_time->minute / 10);
pszDateTime[0xf] = ascii(date_time->minute % 10);
pszDateTime[0x10] = ':';
// Seconds - 2020-04-13T10:56:XX.35+66:40
pszDateTime[0x11] = ascii(date_time->second / 10);
pszDateTime[0x12] = ascii(date_time->second % 10);
pszDateTime[0x13] = '.';
// Hundredths of a second - 2020-04-13T10:56:31.XX+66:40
pszDateTime[0x14] = ascii(date_time->microsecond / 100'000);
pszDateTime[0x15] = ascii(date_time->microsecond / 10'000 % 10);
// Time zone - 'Z' for UTC
if (iTimeZone == 0)
{
pszDateTime[0x16] = 'Z';
pszDateTime[0x17] = '\0';
}
// Time zone - ±hh:mm
else
{
if (iTimeZone < 0)
{
iTimeZone = -iTimeZone;
pszDateTime[0x16] = '-';
}
else
{
pszDateTime[0x16] = '+';
}
const u32 time_zone_hours = iTimeZone / 60 % 100;
const u32 time_zone_minutes = iTimeZone % 60;
pszDateTime[0x17] = ascii(time_zone_hours / 10);
pszDateTime[0x18] = ascii(time_zone_hours % 10);
pszDateTime[0x19] = ':';
pszDateTime[0x1a] = ascii(time_zone_minutes / 10);
pszDateTime[0x1b] = ascii(time_zone_minutes % 10);
pszDateTime[0x1c] = '\0';
}
return CELL_OK;
}
error_code cellRtcFormatRfc3339LocalTime(ppu_thread& ppu, vm::ptr<char> pszDateTime, vm::cptr<CellRtcTick> pUtc)
{
cellRtc.notice("cellRtcFormatRfc3339LocalTime(pszDateTime=*0x%x, pUtc=*0x%x)", pszDateTime, pUtc);
const vm::var<sys_page_attr_t> page_attr;
if (sys_memory_get_page_attribute(ppu, pszDateTime.addr(), page_attr) != CELL_OK)
{
return CELL_RTC_ERROR_INVALID_POINTER;
}
if (sys_memory_get_page_attribute(ppu, pUtc.addr(), page_attr) != CELL_OK)
{
return CELL_RTC_ERROR_INVALID_POINTER;
}
vm::var<s32> timezone;
vm::var<s32> summertime;
error_code ret = sys_time_get_timezone(timezone, summertime);
if (ret < CELL_OK)
{
return ret;
}
return cellRtcFormatRfc3339(ppu, pszDateTime, pUtc, *timezone + *summertime);
}
u16 rtcParseComponent(vm::cptr<char> pszDateTime, u32& pos, char delimiter, const char* component_name)
{
if (delimiter != 0)
{
if (pszDateTime[pos] != delimiter)
{
cellRtc.error("rtcParseComponent(): failed to parse %s: invalid or missing delimiter", component_name);
return umax;
}
pos++;
}
if (!std::isdigit(pszDateTime[pos]))
{
cellRtc.error("rtcParseComponent(): failed to parse %s: ASCII value 0x%x at position %d is not a digit", component_name, pszDateTime[pos + 1], pos);
return umax;
}
u16 ret = digit(pszDateTime[pos]);
pos++;
if (std::isdigit(pszDateTime[pos]))
{
ret = ret * 10 + digit(pszDateTime[pos]);
pos++;
}
return ret;
}
template<usz size>
u8 rtcParseName(vm::cptr<char> pszDateTime, u32& pos, const std::array<std::string_view, size>& names, bool allow_short_name = true)
{
for (u8 name_idx = 0; name_idx < names.size(); name_idx++)
{
const u32 name_length = static_cast<u32>(names[name_idx].length());
u32 ch_idx = 0;
while (ch_idx < name_length && std::tolower(pszDateTime[pos + ch_idx]) == names[name_idx][ch_idx]) // Not case sensitive
{
ch_idx++;
}
if (ch_idx == name_length) // Full name matched
{
pos += name_length;
return name_idx;
}
if (allow_short_name && ch_idx >= 3) // Short name matched
{
pos += 3; // Only increment by 3, even if more letters were matched
return name_idx;
}
}
return size;
}
error_code rtcParseRfc2822(ppu_thread& ppu, vm::ptr<CellRtcTick> pUtc, vm::cptr<char> pszDateTime, u32 pos)
{
// Day: "X" or "XX"
const u16 day = rtcParseComponent(pszDateTime, pos, 0, "day");
if (day == umax)
{
return CELL_RTC_ERROR_BAD_PARSE;
}
// Mandatory space or hyphen
if (pszDateTime[pos] != ' ' && pszDateTime[pos] != '-')
{
return { CELL_RTC_ERROR_BAD_PARSE, "rtcParseRfc2822(): invalid or missing delimiter after day" };
}
pos++;
// Month: at least the first three letters
const u16 month = rtcParseName(pszDateTime, pos, MONTH_NAMES) + 1;
if (month > MONTH_NAMES.size()) // No match
{
return { CELL_RTC_ERROR_BAD_PARSE, "rtcParseRfc2822(): failed to parse month: string at position %d doesn't match any name", pos };
}
// Mandatory space or hyphen
if (pszDateTime[pos] != ' ' && pszDateTime[pos] != '-')
{
return { CELL_RTC_ERROR_BAD_PARSE, "rtcParseRfc2822(): invalid or missing delimiter after month" };
}
pos++;
// Year: "XX" or "XXXX"
u16 year = 0;
if (!std::isdigit(pszDateTime[pos]) ||
!std::isdigit(pszDateTime[pos + 1]))
{
return { CELL_RTC_ERROR_BAD_PARSE, "rtcParseRfc2822(): failed to parse year: one of the first two ASCII values 0x%x, 0x%x at position %d is not a digit",
pszDateTime[pos], pszDateTime[pos + 1], pos };
}
if (!std::isdigit(pszDateTime[pos + 2]) ||
!std::isdigit(pszDateTime[pos + 3]))
{
year = digit(pszDateTime[pos]) * 10 + digit(pszDateTime[pos + 1]);
year += (year < 50) ? 2000 : 1900;
pos += 2;
}
else
{
year = digit(pszDateTime[pos]) * 1000 + digit(pszDateTime[pos + 1]) * 100 + digit(pszDateTime[pos + 2]) * 10 + digit(pszDateTime[pos + 3]);
pos += 4;
}
// Hour: " X" or " XX"
const u16 hour = rtcParseComponent(pszDateTime, pos, ' ', "hour");
if (hour == umax)
{
return CELL_RTC_ERROR_BAD_PARSE;
}
if (hour > 25) // LLE uses 25
{
return { CELL_RTC_ERROR_BAD_PARSE, "rtcParseRfc2822(): failed to parse hour: hour greater than 25" };
}
// Minute: ":X" or ":XX"
const u16 minute = rtcParseComponent(pszDateTime, pos, ':', "minute");
if (minute == umax)
{
return CELL_RTC_ERROR_BAD_PARSE;
}
// Second, optional: ":X" or ":XX"
// The string can't end with '\0' here, there must a space before it
u16 second = 0;
if (pszDateTime[pos] != ' ')
{
second = rtcParseComponent(pszDateTime, pos, ':', "second");
if (second == umax)
{
return CELL_RTC_ERROR_BAD_PARSE;
}
}
else
{
// If there are no seconds in the string, time zone requires two preceding spaces to be properly parsed
pos++;
}
// Time zone, optional, error if there is no valid time zone after the space
s32 time_zone = 0;
if (pszDateTime[pos] == ' ')
{
pos++;
if (pszDateTime[pos] == '+' || pszDateTime[pos] == '-')
{
// "±hhmm"
if (std::isdigit(pszDateTime[pos + 1]) &&
std::isdigit(pszDateTime[pos + 2]) &&
std::isdigit(pszDateTime[pos + 3]) &&
std::isdigit(pszDateTime[pos + 4]))
{
const s32 time_zone_hhmm = digit(pszDateTime[pos + 1]) * 1000 + digit(pszDateTime[pos + 2]) * 100 + digit(pszDateTime[pos + 3]) * 10 + digit(pszDateTime[pos + 4]);
time_zone = time_zone_hhmm / 100 * 60 + time_zone_hhmm % 60; // LLE uses % 60 instead of % 100
}
else
{
// No error, LLE does this for some reason
time_zone = -1;
}
if (pszDateTime[pos] == '-')
{
time_zone = -time_zone;
}
}
else if (pszDateTime[pos] != 'U' && pszDateTime[pos + 1] != 'T') // Case sensitive, should be || but LLE uses &&
{
// "GMT", "EST", "EDT", etc.
const u32 time_zone_idx = rtcParseName(pszDateTime, pos, TIME_ZONE_NAMES, false);
if (time_zone_idx < TIME_ZONE_NAMES.size())
{
time_zone = TIME_ZONE_VALUES[time_zone_idx] * 30;
}
else
{
// Military time zones
// "A", "B", "C", ..., not case sensitive
// These are all off by one ("A" should be UTC+01:00, "B" should be UTC+02:00, etc.)
const char letter = std::toupper(pszDateTime[pos]);
if (letter >= 'A' && letter <= 'M' && letter != 'J')
{
time_zone = (letter - 'A') * 60;
}
else if (letter >= 'N' && letter <= 'Y')
{
time_zone = ('N' - letter) * 60;
}
else if (letter != 'Z')
{
return { CELL_RTC_ERROR_BAD_PARSE, "rtcParseRfc2822(): failed to parse time zone" };
}
}
}
}
const vm::var<CellRtcDateTime> date_time{{ year, month, day, hour, minute, second, 0 }};
cellRtcGetTick(ppu, date_time, pUtc);
cellRtcTickAddMinutes(ppu, pUtc, pUtc, -time_zone); // The time zone value needs to be subtracted
return CELL_OK;
}
error_code cellRtcParseRfc3339(ppu_thread& ppu, vm::ptr<CellRtcTick> pUtc, vm::cptr<char> pszDateTime);
/*
Takes a RFC2822 / RFC3339 / asctime String, and converts it to a CellRtcTick
*/
error_code cellRtcParseDateTime(ppu_thread& ppu, vm::ptr<CellRtcTick> pUtc, vm::cptr<char> pszDateTime)
{
cellRtc.notice("cellRtcParseDateTime(pUtc=*0x%x, pszDateTime=%s)", pUtc, pszDateTime);
const vm::var<sys_page_attr_t> page_attr;
if (sys_memory_get_page_attribute(ppu, pUtc.addr(), page_attr) != CELL_OK || sys_memory_get_page_attribute(ppu, pszDateTime.addr(), page_attr) != CELL_OK)
{
return CELL_RTC_ERROR_INVALID_POINTER;
}
u32 pos = 0;
while (std::isblank(pszDateTime[pos]))
{
pos++;
}
if (std::isdigit(pszDateTime[pos]) &&
std::isdigit(pszDateTime[pos + 1]) &&
std::isdigit(pszDateTime[pos + 2]) &&
std::isdigit(pszDateTime[pos + 3]))
{
return cellRtcParseRfc3339(ppu, pUtc, pszDateTime + pos);
}
// Day of the week: at least the first three letters
if (rtcParseName(pszDateTime, pos, WEEKDAY_NAMES) == WEEKDAY_NAMES.size()) // No match
{
return { CELL_RTC_ERROR_BAD_PARSE, "cellRtcParseDateTime(): failed to parse day of the week: string at position %d doesn't match any name", pos };
}
// Optional comma
if (pszDateTime[pos] == ',')
{
pos++;
}
// Skip spaces and tabs
while (std::isblank(pszDateTime[pos]))
{
pos++;
}
// Month: at least the first three letters
const u16 month = rtcParseName(pszDateTime, pos, MONTH_NAMES) + 1;
if (month > MONTH_NAMES.size()) // No match
{
cellRtc.notice("cellRtcParseDateTime(): string uses RFC 2822 format");
return rtcParseRfc2822(ppu, pUtc, pszDateTime, pos);
}
// Mandatory space
if (pszDateTime[pos] != ' ')
{
return { CELL_RTC_ERROR_BAD_PARSE, "cellRtcParseDateTime(): no space after month" };
}
pos++;
// Day: " X", "XX" or "X"
// There may be a second space before day
u16 day = 0;
if (pszDateTime[pos] == ' ')
{
pos++;
// Due to using a signed type instead of unsigned, LLE doesn't check if the char is less than '0'
if (pszDateTime[pos] > '9')
{
return { CELL_RTC_ERROR_BAD_PARSE, "cellRtcParseDateTime(): failed to parse day: ASCII value 0x%x at position %d is not a digit", pszDateTime[pos], pos };
}
if (pszDateTime[pos] < '0')
{
cellRtc.warning("cellRtcParseDateTime(): ASCII value 0x%x at position %d is not a digit", pszDateTime[pos], pos);
}
day = static_cast<u16>(pszDateTime[pos]) - '0'; // Needs to be sign extended first to match LLE for values from 0x80 to 0xb0
pos++;
}
else if (std::isdigit(pszDateTime[pos]))
{
day = digit(pszDateTime[pos]);
pos++;
if (std::isdigit(pszDateTime[pos]))
{
day = day * 10 + digit(pszDateTime[pos]);
pos++;
}
}
else
{
return { CELL_RTC_ERROR_BAD_PARSE, "cellRtcParseDateTime(): failed to parse day: ASCII value 0x%x at position %d is not a digit or space", pszDateTime[pos], pos };
}
// Hour: " X" or " XX"
const u16 hour = rtcParseComponent(pszDateTime, pos, ' ', "hour");
if (hour == umax)
{
return CELL_RTC_ERROR_BAD_PARSE;
}
// Minute: ":X" or ":XX"
const u16 minute = rtcParseComponent(pszDateTime, pos, ':', "minute");
if (minute == umax)
{
return CELL_RTC_ERROR_BAD_PARSE;
}
// Second: ":X" or ":XX"
const u16 second = rtcParseComponent(pszDateTime, pos, ':', "second");
if (second == umax)
{
return CELL_RTC_ERROR_BAD_PARSE;
}
// Mandatory space
if (pszDateTime[pos] != ' ')
{
return { CELL_RTC_ERROR_BAD_PARSE, "cellRtcParseDateTime(): no space after second" };
}
pos++;
// Year: XXXX
if (!std::isdigit(pszDateTime[pos]) ||
!std::isdigit(pszDateTime[pos + 1]) ||
!std::isdigit(pszDateTime[pos + 2]) ||
!std::isdigit(pszDateTime[pos + 3]))
{
return { CELL_RTC_ERROR_BAD_PARSE, "cellRtcParseDateTime(): failed to parse year: one of the ASCII values 0x%x, 0x%x, 0x%x, or 0x%x is not a digit",
pszDateTime[pos], pszDateTime[pos + 1], pszDateTime[pos + 2], pszDateTime[pos + 3] };
}
const u16 year = digit(pszDateTime[pos]) * 1000 + digit(pszDateTime[pos + 1]) * 100 + digit(pszDateTime[pos + 2]) * 10 + digit(pszDateTime[pos + 3]);
const vm::var<CellRtcDateTime> date_time{{ year, month, day, hour, minute, second, 0 }};
cellRtcGetTick(ppu, date_time, pUtc);
return CELL_OK;
}
// Rfc3339: 1995-12-03T13:23:00.00Z
error_code cellRtcParseRfc3339(ppu_thread& ppu, vm::ptr<CellRtcTick> pUtc, vm::cptr<char> pszDateTime)
{
cellRtc.notice("cellRtcParseRfc3339(pUtc=*0x%x, pszDateTime=%s)", pUtc, pszDateTime);
const vm::var<sys_page_attr_t> page_attr;
if (sys_memory_get_page_attribute(ppu, pUtc.addr(), page_attr) != CELL_OK)
{
return CELL_RTC_ERROR_INVALID_POINTER;
}
if (sys_memory_get_page_attribute(ppu, pszDateTime.addr(), page_attr) != CELL_OK)
{
return CELL_RTC_ERROR_INVALID_POINTER;
}
vm::var<CellRtcDateTime> date_time;
// Year: XXXX-12-03T13:23:00.00Z
if (std::isdigit(pszDateTime[0]) && std::isdigit(pszDateTime[1]) && std::isdigit(pszDateTime[2]) && std::isdigit(pszDateTime[3]))
{
date_time->year = digit(pszDateTime[0]) * 1000 + digit(pszDateTime[1]) * 100 + digit(pszDateTime[2]) * 10 + digit(pszDateTime[3]);
}
else
{
date_time->year = 0xffff;
}
if (pszDateTime[4] != '-')
{
return CELL_RTC_ERROR_INVALID_YEAR;
}
// Month: 1995-XX-03T13:23:00.00Z
if (std::isdigit(pszDateTime[5]) && std::isdigit(pszDateTime[6]))
{
date_time->month = digit(pszDateTime[5]) * 10 + digit(pszDateTime[6]);
}
else
{
date_time->month = 0xffff;
}
if (pszDateTime[7] != '-')
{
return CELL_RTC_ERROR_INVALID_MONTH;
}
// Day: 1995-12-XXT13:23:00.00Z
if (std::isdigit(pszDateTime[8]) && std::isdigit(pszDateTime[9]))
{
date_time->day = digit(pszDateTime[8]) * 10 + digit(pszDateTime[9]);
}
else
{
date_time->day = 0xffff;
}
if (pszDateTime[10] != 'T' && pszDateTime[10] != 't')
{
return CELL_RTC_ERROR_INVALID_DAY;
}
// Hour: 1995-12-03TXX:23:00.00Z
if (std::isdigit(pszDateTime[11]) && std::isdigit(pszDateTime[12]))
{
date_time->hour = digit(pszDateTime[11]) * 10 + digit(pszDateTime[12]);
}
else
{
date_time->hour = 0xffff;
}
if (pszDateTime[13] != ':')
{
return CELL_RTC_ERROR_INVALID_HOUR;
}
// Minute: 1995-12-03T13:XX:00.00Z
if (std::isdigit(pszDateTime[14]) && std::isdigit(pszDateTime[15]))
{
date_time->minute = digit(pszDateTime[14]) * 10 + digit(pszDateTime[15]);
}
else
{
date_time->minute = 0xffff;
}
if (pszDateTime[16] != ':')
{
return CELL_RTC_ERROR_INVALID_MINUTE;
}
// Second: 1995-12-03T13:23:XX.00Z
if (std::isdigit(pszDateTime[17]) && std::isdigit(pszDateTime[18]))
{
date_time->second = digit(pszDateTime[17]) * 10 + digit(pszDateTime[18]);
}
else
{
date_time->second = 0xffff;
}
// Microsecond: 1995-12-03T13:23:00.XXZ
date_time->microsecond = 0;
u32 pos = 19;
if (pszDateTime[pos] == '.')
{
u32 mul = 100000;
for (char c = pszDateTime[++pos]; std::isdigit(c); c = pszDateTime[++pos])
{
date_time->microsecond += digit(c) * mul;
mul /= 10;
}
}
const char sign = pszDateTime[pos];
if (sign != 'Z' && sign != 'z' && sign != '+' && sign != '-')
{
return CELL_RTC_ERROR_BAD_PARSE;
}
s64 minutes_to_add = 0;
// Time offset: 1995-12-03T13:23:00.00+02:30
if (sign == '+' || sign == '-')
{
if (!std::isdigit(pszDateTime[pos + 1]) ||
!std::isdigit(pszDateTime[pos + 2]) ||
pszDateTime[pos + 3] != ':' ||
!std::isdigit(pszDateTime[pos + 4]) ||
!std::isdigit(pszDateTime[pos + 5]))
{
return CELL_RTC_ERROR_BAD_PARSE;
}
// Time offset (hours): 1995-12-03T13:23:00.00+XX:30
const s32 hours = digit(pszDateTime[pos + 1]) * 10 + digit(pszDateTime[pos + 2]);
// Time offset (minutes): 1995-12-03T13:23:00.00+02:XX
const s32 minutes = digit(pszDateTime[pos + 4]) * 10 + digit(pszDateTime[pos + 5]);
minutes_to_add = hours * 60 + minutes;
if (sign == '+')
{
minutes_to_add = -minutes_to_add;
}
}
cellRtcGetTick(ppu, date_time, pUtc);
cellRtcTickAddMinutes(ppu, pUtc, pUtc, minutes_to_add);
return CELL_OK;
}
error_code cellRtcGetTick(ppu_thread& ppu, vm::cptr<CellRtcDateTime> pTime, vm::ptr<CellRtcTick> pTick)
{
cellRtc.trace("cellRtcGetTick(pTime=*0x%x, pTick=*0x%x)", pTime, pTick);
const vm::var<sys_page_attr_t> page_attr;
if (sys_memory_get_page_attribute(ppu, pTime.addr(), page_attr) != CELL_OK)
{
return CELL_RTC_ERROR_INVALID_POINTER;
}
if (sys_memory_get_page_attribute(ppu, pTick.addr(), page_attr) != CELL_OK)
{
return CELL_RTC_ERROR_INVALID_POINTER;
}
if (pTime->year >= 10000 || pTime->year == 0)
{
return CELL_RTC_ERROR_INVALID_VALUE;
}
pTick->tick = date_time_to_tick(*pTime);
return CELL_OK;
}
CellRtcDateTime tick_to_date_time(u64 tick)
{
const u32 microseconds = (tick % 1000000ULL);
const u16 seconds = (tick / (1000000ULL)) % 60;
const u16 minutes = (tick / (60ULL * 1000000ULL)) % 60;
const u16 hours = (tick / (60ULL * 60ULL * 1000000ULL)) % 24;
u32 days_tmp = static_cast<u32>(tick / (24ULL * 60ULL * 60ULL * 1000000ULL));
const u32 year_400 = days_tmp / DAYS_IN_400_YEARS;
days_tmp -= year_400 * DAYS_IN_400_YEARS;
const u32 year_within_400_interval = (
days_tmp
- days_tmp / (DAYS_IN_4_YEARS - 1)
+ days_tmp / DAYS_IN_100_YEARS
- days_tmp / (DAYS_IN_400_YEARS - 1)
) / 365;
days_tmp -= year_within_400_interval * 365 + year_within_400_interval / 4 - year_within_400_interval / 100 + year_within_400_interval / 400;
const u16 years = year_400 * 400 + year_within_400_interval + 1;
const auto& month_offset = is_leap_year(years) ? MONTH_OFFSET_LEAP : MONTH_OFFSET;
u32 month_approx = days_tmp / 29;
if (month_offset[month_approx] > days_tmp)
{
month_approx--;
}
const u16 months = month_approx + 1;
days_tmp = days_tmp - month_offset[month_approx];
CellRtcDateTime date_time{
.year = years,
.month = months,
.day = ::narrow<u16>(days_tmp + 1),
.hour = hours,
.minute = minutes,
.second = seconds,
.microsecond = microseconds
};
return date_time;
}
u64 date_time_to_tick(CellRtcDateTime date_time)
{
const u32 days_in_previous_years =
date_time.year * 365
+ (date_time.year + 3) / 4
- (date_time.year + 99) / 100
+ (date_time.year + 399) / 400
- 366;
// Not checked on LLE
if (date_time.month == 0u)
{
cellRtc.warning("date_time_to_tick(): month invalid, clamping to 1");
date_time.month = 1;
}
else if (date_time.month > 12u)
{
cellRtc.warning("date_time_to_tick(): month invalid, clamping to 12");
date_time.month = 12;
}
const u16 days_in_previous_months = is_leap_year(date_time.year) ? MONTH_OFFSET_LEAP[date_time.month - 1] : MONTH_OFFSET[date_time.month - 1];
const u32 days = days_in_previous_years + days_in_previous_months + date_time.day - 1;
u64 tick = date_time.microsecond
+ u64{date_time.second} * 1000000ULL
+ u64{date_time.minute} * 60ULL * 1000000ULL
+ u64{date_time.hour} * 60ULL * 60ULL * 1000000ULL
+ days * 24ULL * 60ULL * 60ULL * 1000000ULL;
return tick;
}
error_code cellRtcSetTick(ppu_thread& ppu, vm::ptr<CellRtcDateTime> pTime, vm::cptr<CellRtcTick> pTick)
{
cellRtc.trace("cellRtcSetTick(pTime=*0x%x, pTick=*0x%x)", pTime, pTick);
const vm::var<sys_page_attr_t> page_attr;
if (sys_memory_get_page_attribute(ppu, pTime.addr(), page_attr) != CELL_OK)
{
return CELL_RTC_ERROR_INVALID_POINTER;
}
if (sys_memory_get_page_attribute(ppu, pTick.addr(), page_attr) != CELL_OK)
{
return CELL_RTC_ERROR_INVALID_POINTER;
}
*pTime = tick_to_date_time(pTick->tick);
return CELL_OK;
}
error_code cellRtcTickAddTicks(ppu_thread& ppu, vm::ptr<CellRtcTick> pTick0, vm::cptr<CellRtcTick> pTick1, s64 lAdd)
{
cellRtc.trace("cellRtcTickAddTicks(pTick0=*0x%x, pTick1=*0x%x, lAdd=%lld)", pTick0, pTick1, lAdd);
const vm::var<sys_page_attr_t> page_attr;
if (sys_memory_get_page_attribute(ppu, pTick0.addr(), page_attr) != CELL_OK)
{
return CELL_RTC_ERROR_INVALID_POINTER;
}
if (sys_memory_get_page_attribute(ppu, pTick1.addr(), page_attr) != CELL_OK)
{
return CELL_RTC_ERROR_INVALID_POINTER;
}
pTick0->tick = pTick1->tick + lAdd;
return CELL_OK;
}
error_code cellRtcTickAddMicroseconds(ppu_thread& ppu, vm::ptr<CellRtcTick> pTick0, vm::cptr<CellRtcTick> pTick1, s64 lAdd)
{
cellRtc.trace("cellRtcTickAddMicroseconds(pTick0=*0x%x, pTick1=*0x%x, lAdd=%lld)", pTick0, pTick1, lAdd);
const vm::var<sys_page_attr_t> page_attr;
if (sys_memory_get_page_attribute(ppu, pTick0.addr(), page_attr) != CELL_OK)
{
return CELL_RTC_ERROR_INVALID_POINTER;
}
if (sys_memory_get_page_attribute(ppu, pTick1.addr(), page_attr) != CELL_OK)
{
return CELL_RTC_ERROR_INVALID_POINTER;
}
pTick0->tick = pTick1->tick + lAdd;
return CELL_OK;
}
error_code cellRtcTickAddSeconds(ppu_thread& ppu, vm::ptr<CellRtcTick> pTick0, vm::cptr<CellRtcTick> pTick1, s64 lAdd)
{
cellRtc.trace("cellRtcTickAddSeconds(pTick0=*0x%x, pTick1=*0x%x, lAdd=%lld)", pTick0, pTick1, lAdd);
const vm::var<sys_page_attr_t> page_attr;
if (sys_memory_get_page_attribute(ppu, pTick0.addr(), page_attr) != CELL_OK)
{
return CELL_RTC_ERROR_INVALID_POINTER;
}
if (sys_memory_get_page_attribute(ppu, pTick1.addr(), page_attr) != CELL_OK)
{
return CELL_RTC_ERROR_INVALID_POINTER;
}
pTick0->tick = pTick1->tick + lAdd * cellRtcGetTickResolution();
return CELL_OK;
}
error_code cellRtcTickAddMinutes(ppu_thread& ppu, vm::ptr<CellRtcTick> pTick0, vm::cptr<CellRtcTick> pTick1, s64 lAdd)
{
cellRtc.trace("cellRtcTickAddMinutes(pTick0=*0x%x, pTick1=*0x%x, lAdd=%lld)", pTick0, pTick1, lAdd);
const vm::var<sys_page_attr_t> page_attr;
if (sys_memory_get_page_attribute(ppu, pTick0.addr(), page_attr) != CELL_OK)
{
return CELL_RTC_ERROR_INVALID_POINTER;
}
if (sys_memory_get_page_attribute(ppu, pTick1.addr(), page_attr) != CELL_OK)
{
return CELL_RTC_ERROR_INVALID_POINTER;
}
pTick0->tick = pTick1->tick + lAdd * 60 * cellRtcGetTickResolution();
return CELL_OK;
}
error_code cellRtcTickAddHours(ppu_thread& ppu, vm::ptr<CellRtcTick> pTick0, vm::cptr<CellRtcTick> pTick1, s32 iAdd)
{
cellRtc.trace("cellRtcTickAddHours(pTick0=*0x%x, pTick1=*0x%x, iAdd=%d)", pTick0, pTick1, iAdd);
const vm::var<sys_page_attr_t> page_attr;
if (sys_memory_get_page_attribute(ppu, pTick0.addr(), page_attr) != CELL_OK)
{
return CELL_RTC_ERROR_INVALID_POINTER;
}
if (sys_memory_get_page_attribute(ppu, pTick1.addr(), page_attr) != CELL_OK)
{
return CELL_RTC_ERROR_INVALID_POINTER;
}
pTick0->tick = pTick1->tick + iAdd * 60ULL * 60ULL * cellRtcGetTickResolution();
return CELL_OK;
}
error_code cellRtcTickAddDays(ppu_thread& ppu, vm::ptr<CellRtcTick> pTick0, vm::cptr<CellRtcTick> pTick1, s32 iAdd)
{
cellRtc.trace("cellRtcTickAddDays(pTick0=*0x%x, pTick1=*0x%x, iAdd=%d)", pTick0, pTick1, iAdd);
const vm::var<sys_page_attr_t> page_attr;
if (sys_memory_get_page_attribute(ppu, pTick0.addr(), page_attr) != CELL_OK)
{
return CELL_RTC_ERROR_INVALID_POINTER;
}
if (sys_memory_get_page_attribute(ppu, pTick1.addr(), page_attr) != CELL_OK)
{
return CELL_RTC_ERROR_INVALID_POINTER;
}
pTick0->tick = pTick1->tick + iAdd * 60ULL * 60ULL * 24ULL * cellRtcGetTickResolution();
return CELL_OK;
}
error_code cellRtcTickAddWeeks(ppu_thread& ppu, vm::ptr<CellRtcTick> pTick0, vm::cptr<CellRtcTick> pTick1, s32 iAdd)
{
cellRtc.trace("cellRtcTickAddWeeks(pTick0=*0x%x, pTick1=*0x%x, iAdd=%d)", pTick0, pTick1, iAdd);
const vm::var<sys_page_attr_t> page_attr;
if (sys_memory_get_page_attribute(ppu, pTick0.addr(), page_attr) != CELL_OK)
{
return CELL_RTC_ERROR_INVALID_POINTER;
}
if (sys_memory_get_page_attribute(ppu, pTick1.addr(), page_attr) != CELL_OK)
{
return CELL_RTC_ERROR_INVALID_POINTER;
}
pTick0->tick = pTick1->tick + iAdd * 60ULL * 60ULL * 24ULL * 7ULL * cellRtcGetTickResolution();
return CELL_OK;
}
error_code cellRtcTickAddMonths(ppu_thread& ppu, vm::ptr<CellRtcTick> pTick0, vm::cptr<CellRtcTick> pTick1, s32 iAdd)
{
cellRtc.notice("cellRtcTickAddMonths(pTick0=*0x%x, pTick1=*0x%x, iAdd=%d)", pTick0, pTick1, iAdd);
const vm::var<sys_page_attr_t> page_attr;
if (sys_memory_get_page_attribute(ppu, pTick0.addr(), page_attr) != CELL_OK)
{
return CELL_RTC_ERROR_INVALID_POINTER;
}
if (sys_memory_get_page_attribute(ppu, pTick1.addr(), page_attr) != CELL_OK)
{
return CELL_RTC_ERROR_INVALID_POINTER;
}
vm::var<CellRtcDateTime> date_time;
cellRtcSetTick(ppu, date_time, pTick1);
const s32 total_months = date_time->year * 12 + date_time->month + iAdd - 1;
const u16 new_year = total_months / 12;
const u16 new_month = total_months - new_year * 12 + 1;
s32 month_days;
if (new_year == 0u || new_month < 1u || new_month > 12u)
{
month_days = CELL_RTC_ERROR_INVALID_ARG; // LLE writes the error to this variable
}
else
{
month_days = is_leap_year(new_year) ? DAYS_IN_MONTH_LEAP[new_month - 1] : DAYS_IN_MONTH[new_month - 1];
}
if (month_days < static_cast<s32>(date_time->day))
{
date_time->day = static_cast<u16>(month_days);
}
date_time->month = new_month;
date_time->year = new_year;
cellRtcGetTick(ppu, date_time, pTick0);
return CELL_OK;
}
error_code cellRtcTickAddYears(ppu_thread& ppu, vm::ptr<CellRtcTick> pTick0, vm::cptr<CellRtcTick> pTick1, s32 iAdd)
{
cellRtc.notice("cellRtcTickAddYears(pTick0=*0x%x, pTick1=*0x%x, iAdd=%d)", pTick0, pTick1, iAdd);
const vm::var<sys_page_attr_t> page_attr;
if (sys_memory_get_page_attribute(ppu, pTick0.addr(), page_attr) != CELL_OK)
{
return CELL_RTC_ERROR_INVALID_POINTER;
}
if (sys_memory_get_page_attribute(ppu, pTick1.addr(), page_attr) != CELL_OK)
{
return CELL_RTC_ERROR_INVALID_POINTER;
}
vm::var<CellRtcDateTime> date_time;
cellRtcSetTick(ppu, date_time, pTick1);
const u16 month = date_time->month;
const u16 new_year = date_time->year + iAdd;
s32 month_days;
if (new_year == 0u || month < 1u || month > 12u)
{
month_days = CELL_RTC_ERROR_INVALID_ARG; // LLE writes the error to this variable
}
else
{
month_days = is_leap_year(new_year) ? DAYS_IN_MONTH_LEAP[month - 1] : DAYS_IN_MONTH[month - 1];
}
if (month_days < static_cast<s32>(date_time->day))
{
date_time->day = static_cast<u16>(month_days);
}
date_time->year = new_year;
cellRtcGetTick(ppu, date_time, pTick0);
return CELL_OK;
}
error_code cellRtcConvertUtcToLocalTime(ppu_thread& ppu, vm::cptr<CellRtcTick> pUtc, vm::ptr<CellRtcTick> pLocalTime)
{
cellRtc.trace("cellRtcConvertUtcToLocalTime(pUtc=*0x%x, pLocalTime=*0x%x)", pUtc, pLocalTime);
vm::var<s32> timezone;
vm::var<s32> summertime;
error_code ret = sys_time_get_timezone(timezone, summertime);
if (-1 < ret)
{
ret = cellRtcTickAddMinutes(ppu, pLocalTime, pUtc, *timezone + *summertime);
}
return ret;
}
error_code cellRtcConvertLocalTimeToUtc(ppu_thread& ppu, vm::cptr<CellRtcTick> pLocalTime, vm::ptr<CellRtcTick> pUtc)
{
cellRtc.notice("cellRtcConvertLocalTimeToUtc(pLocalTime=*0x%x, pUtc=*0x%x)", pLocalTime, pUtc);
vm::var<s32> timezone;
vm::var<s32> summertime;
error_code ret = sys_time_get_timezone(timezone, summertime);
if (-1 < ret)
{
ret = cellRtcTickAddMinutes(ppu, pUtc, pLocalTime, -(*timezone + *summertime));
}
return ret;
}
error_code cellRtcGetCurrentSecureTick(ppu_thread& ppu, vm::ptr<CellRtcTick> tick)
{
cellRtc.notice("cellRtcGetCurrentSecureTick(tick=*0x%x)", tick);
const vm::var<sys_page_attr_t> page_attr;
if (sys_memory_get_page_attribute(ppu, tick.addr(), page_attr) != CELL_OK)
{
return CELL_RTC_ERROR_INVALID_POINTER;
}
tick->tick = RTC_SYSTEM_TIME_MIN;
const vm::var<u64> time{0};
const vm::var<u64> status{0};
error_code ret = sys_ss_secure_rtc(0x3002, 0, time.addr(), status.addr());
if (ret >= CELL_OK)
{
tick->tick += *time * cellRtcGetTickResolution();
}
else if (ret == static_cast<s32>(SYS_SS_RTC_ERROR_UNK))
{
switch (*status)
{
case 1: ret = CELL_RTC_ERROR_NO_CLOCK; break;
case 2: ret = CELL_RTC_ERROR_NOT_INITIALIZED; break;
case 4: ret = CELL_RTC_ERROR_INVALID_VALUE; break;
case 8: ret = CELL_RTC_ERROR_NO_CLOCK; break;
default: return ret;
}
}
return ret;
}
error_code cellRtcGetDosTime(ppu_thread& ppu, vm::cptr<CellRtcDateTime> pDateTime, vm::ptr<u32> puiDosTime)
{
cellRtc.notice("cellRtcGetDosTime(pDateTime=*0x%x, puiDosTime=*0x%x)", pDateTime, puiDosTime);
const vm::var<sys_page_attr_t> page_attr;
if (sys_memory_get_page_attribute(ppu, pDateTime.addr(), page_attr) != CELL_OK)
{
return CELL_RTC_ERROR_INVALID_POINTER;
}
if (sys_memory_get_page_attribute(ppu, puiDosTime.addr(), page_attr) != CELL_OK)
{
return CELL_RTC_ERROR_INVALID_POINTER;
}
if (pDateTime->year < 1980)
{
if (puiDosTime) // Should always evaluate to true, nullptr was already checked above
{
*puiDosTime = 0;
}
return -1;
}
if (pDateTime->year >= 2108)
{
if (puiDosTime) // Should always evaluate to true, nullptr was already checked above
{
*puiDosTime = 0xff9fbf7d; // kHighDosTime
}
return -1;
}
if (puiDosTime) // Should always evaluate to true, nullptr was already checked above
{
s32 year = ((pDateTime->year - 1980) & 0x7F) << 9;
s32 month = ((pDateTime->month) & 0xF) << 5;
s32 hour = ((pDateTime->hour) & 0x1F) << 11;
s32 minute = ((pDateTime->minute) & 0x3F) << 5;
s32 day = (pDateTime->day) & 0x1F;
s32 second = ((pDateTime->second) >> 1) & 0x1F;
s32 ymd = year | month | day;
s32 hms = hour | minute | second;
*puiDosTime = (ymd << 16) | hms;
}
return CELL_OK;
}
error_code cellRtcGetSystemTime(ppu_thread& ppu, vm::cptr<CellRtcDateTime> pDateTime, vm::ptr<s64> pTimeStamp)
{
cellRtc.notice("cellRtcGetSystemTime(pDateTime=*0x%x, pTimeStamp=*0x%x)", pDateTime, pTimeStamp);
const vm::var<sys_page_attr_t> page_attr;
if (sys_memory_get_page_attribute(ppu, pDateTime.addr(), page_attr) != CELL_OK)
{
return CELL_RTC_ERROR_INVALID_POINTER;
}
if (sys_memory_get_page_attribute(ppu, pTimeStamp.addr(), page_attr) != CELL_OK)
{
return CELL_RTC_ERROR_INVALID_POINTER;
}
vm::var<CellRtcTick> tick;
cellRtcGetTick(ppu, pDateTime, tick);
if (tick->tick < RTC_SYSTEM_TIME_MIN)
{
if (pTimeStamp) // Should always evaluate to true, nullptr was already checked above
{
*pTimeStamp = 0;
}
return CELL_RTC_ERROR_INVALID_VALUE;
}
if (tick->tick >= RTC_SYSTEM_TIME_MAX + cellRtcGetTickResolution())
{
if (pTimeStamp) // Should always evaluate to true, nullptr was already checked above
{
*pTimeStamp = (RTC_SYSTEM_TIME_MAX - RTC_SYSTEM_TIME_MIN) / cellRtcGetTickResolution();
}
return CELL_RTC_ERROR_INVALID_VALUE;
}
if (pTimeStamp) // Should always evaluate to true, nullptr was already checked above
{
*pTimeStamp = (tick->tick - RTC_SYSTEM_TIME_MIN) / cellRtcGetTickResolution();
}
return CELL_OK;
}
error_code cellRtcGetTime_t(ppu_thread& ppu, vm::cptr<CellRtcDateTime> pDateTime, vm::ptr<s64> piTime)
{
cellRtc.notice("cellRtcGetTime_t(pDateTime=*0x%x, piTime=*0x%x)", pDateTime, piTime);
const vm::var<sys_page_attr_t> page_attr;
if (sys_memory_get_page_attribute(ppu, pDateTime.addr(), page_attr) != CELL_OK)
{
return CELL_RTC_ERROR_INVALID_POINTER;
}
if (sys_memory_get_page_attribute(ppu, piTime.addr(), page_attr) != CELL_OK)
{
return CELL_RTC_ERROR_INVALID_POINTER;
}
vm::var<CellRtcTick> tick;
cellRtcGetTick(ppu, pDateTime, tick);
if (tick->tick < RTC_MAGIC_OFFSET)
{
if (piTime) // Should always evaluate to true, nullptr was already checked above
{
*piTime = 0;
}
return CELL_RTC_ERROR_INVALID_VALUE;
}
if (piTime) // Should always evaluate to true, nullptr was already checked above
{
*piTime = (tick->tick - RTC_MAGIC_OFFSET) / cellRtcGetTickResolution();
}
return CELL_OK;
}
error_code cellRtcGetWin32FileTime(ppu_thread& ppu, vm::cptr<CellRtcDateTime> pDateTime, vm::ptr<u64> pulWin32FileTime)
{
cellRtc.notice("cellRtcGetWin32FileTime(pDateTime=*0x%x, pulWin32FileTime=*0x%x)", pDateTime, pulWin32FileTime);
const vm::var<sys_page_attr_t> page_attr;
if (sys_memory_get_page_attribute(ppu, pDateTime.addr(), page_attr) != CELL_OK)
{
return CELL_RTC_ERROR_INVALID_POINTER;
}
if (sys_memory_get_page_attribute(ppu, pulWin32FileTime.addr(), page_attr) != CELL_OK)
{
return CELL_RTC_ERROR_INVALID_POINTER;
}
vm::var<CellRtcTick> tick;
cellRtcGetTick(ppu, pDateTime, tick);
if (tick->tick < RTC_FILETIME_OFFSET)
{
if (pulWin32FileTime) // Should always evaluate to true, nullptr was already checked above
{
*pulWin32FileTime = 0;
}
return CELL_RTC_ERROR_INVALID_VALUE;
}
if (pulWin32FileTime) // Should always evaluate to true, nullptr was already checked above
{
*pulWin32FileTime = (tick->tick - RTC_FILETIME_OFFSET) * 10;
}
return CELL_OK;
}
error_code cellRtcSetCurrentSecureTick(vm::ptr<CellRtcTick> pTick)
{
cellRtc.notice("cellRtcSetCurrentSecureTick(pTick=*0x%x)", pTick);
if (!pTick)
{
return CELL_RTC_ERROR_INVALID_POINTER;
}
if (pTick->tick > RTC_SYSTEM_TIME_MAX)
{
return CELL_RTC_ERROR_INVALID_VALUE;
}
return sys_ss_secure_rtc(0x3003, (pTick->tick - RTC_SYSTEM_TIME_MIN) / cellRtcGetTickResolution(), 0, 0);
}
error_code cellRtcSetCurrentTick(vm::cptr<CellRtcTick> pTick)
{
cellRtc.notice("cellRtcSetCurrentTick(pTick=*0x%x)", pTick);
if (!pTick)
{
return CELL_RTC_ERROR_INVALID_POINTER;
}
if (pTick->tick < RTC_MAGIC_OFFSET)
{
return CELL_RTC_ERROR_INVALID_VALUE;
}
const u64 unix_time = pTick->tick - RTC_MAGIC_OFFSET;
const error_code ret = sys_time_set_current_time(unix_time / cellRtcGetTickResolution(), unix_time % cellRtcGetTickResolution() * 1000);
return ret >= CELL_OK ? CELL_OK : ret;
}
error_code cellRtcSetConf(s64 unk1, s64 unk2, u32 timezone, u32 summertime)
{
cellRtc.notice("cellRtcSetConf(unk1=0x%x, unk2=0x%x, timezone=%d, summertime=%d)", unk1, unk2, timezone, summertime);
// Seems the first 2 args are ignored :|
return sys_time_set_timezone(timezone, summertime);
}
error_code cellRtcSetDosTime(ppu_thread& ppu, vm::ptr<CellRtcDateTime> pDateTime, u32 uiDosTime)
{
cellRtc.notice("cellRtcSetDosTime(pDateTime=*0x%x, uiDosTime=0x%x)", pDateTime, uiDosTime);
const vm::var<sys_page_attr_t> page_attr;
if (sys_memory_get_page_attribute(ppu, pDateTime.addr(), page_attr) != CELL_OK)
{
return CELL_RTC_ERROR_INVALID_POINTER;
}
s32 hms = uiDosTime & 0xffff;
s32 ymd = uiDosTime >> 16;
pDateTime->year = (ymd >> 9) + 1980;
pDateTime->month = (ymd >> 5) & 0xf;
pDateTime->day = ymd & 0x1f;
pDateTime->hour = (hms >> 11);
pDateTime->minute = (hms >> 5) & 0x3f;
pDateTime->second = (hms << 1) & 0x3e;
pDateTime->microsecond = 0;
return CELL_OK;
}
constexpr u32 cellRtcGetTickResolution()
{
// Amount of ticks in a second
return 1000000;
}
error_code cellRtcSetTime_t(ppu_thread& ppu, vm::ptr<CellRtcDateTime> pDateTime, u64 iTime)
{
cellRtc.notice("cellRtcSetTime_t(pDateTime=*0x%x, iTime=0x%llx)", pDateTime, iTime);
const vm::var<sys_page_attr_t> page_attr;
if (sys_memory_get_page_attribute(ppu, pDateTime.addr(), page_attr) != CELL_OK)
{
return CELL_RTC_ERROR_INVALID_POINTER;
}
vm::var<CellRtcTick> tick;
tick->tick = iTime * cellRtcGetTickResolution() + RTC_MAGIC_OFFSET;
cellRtcSetTick(ppu, pDateTime, tick);
return CELL_OK;
}
error_code cellRtcSetSystemTime(ppu_thread& ppu, vm::ptr<CellRtcDateTime> pDateTime, u64 iTime)
{
cellRtc.notice("cellRtcSetSystemTime(pDateTime=*0x%x, iTime=0x%llx)", pDateTime, iTime);
const vm::var<sys_page_attr_t> page_attr;
if (sys_memory_get_page_attribute(ppu, pDateTime.addr(), page_attr) != CELL_OK)
{
return CELL_RTC_ERROR_INVALID_POINTER;
}
vm::var<CellRtcTick> tick;
tick->tick = iTime * cellRtcGetTickResolution() + RTC_SYSTEM_TIME_MIN;
cellRtcSetTick(ppu, pDateTime, tick);
return CELL_OK;
}
error_code cellRtcSetWin32FileTime(ppu_thread& ppu, vm::ptr<CellRtcDateTime> pDateTime, u64 ulWin32FileTime)
{
cellRtc.notice("cellRtcSetWin32FileTime(pDateTime=*0x%x, ulWin32FileTime=0x%llx)", pDateTime, ulWin32FileTime);
const vm::var<sys_page_attr_t> page_attr;
if (sys_memory_get_page_attribute(ppu, pDateTime.addr(), page_attr) != CELL_OK)
{
return CELL_RTC_ERROR_INVALID_POINTER;
}
vm::var<CellRtcTick> tick;
tick->tick = ulWin32FileTime / 10 + RTC_FILETIME_OFFSET;
return cellRtcSetTick(ppu, pDateTime, tick);
}
error_code cellRtcIsLeapYear(s32 year)
{
cellRtc.notice("cellRtcIsLeapYear(year=%d)", year);
if (year < 1)
{
return CELL_RTC_ERROR_INVALID_ARG;
}
return not_an_error(is_leap_year(year));
}
error_code cellRtcGetDaysInMonth(s32 year, s32 month)
{
cellRtc.notice("cellRtcGetDaysInMonth(year=%d, month=%d)", year, month);
if ((year <= 0) || (month <= 0) || (month > 12))
{
return CELL_RTC_ERROR_INVALID_ARG;
}
return not_an_error(is_leap_year(year) ? DAYS_IN_MONTH_LEAP[month - 1] : DAYS_IN_MONTH[month - 1]);
}
s32 cellRtcGetDayOfWeek(s32 year, s32 month, s32 day)
{
cellRtc.trace("cellRtcGetDayOfWeek(year=%d, month=%d, day=%d)", year, month, day);
if (month == 1 || month == 2)
{
year--;
month += 12;
}
return ((month * 13 + 8) / 5 + year + year / 4 - year / 100 + year / 400 + day) % 7;
}
error_code cellRtcCheckValid(vm::cptr<CellRtcDateTime> pTime)
{
cellRtc.notice("cellRtcCheckValid(pTime=*0x%x)", pTime);
ensure(!!pTime); // Not checked on LLE
cellRtc.notice("cellRtcCheckValid year: %d, month: %d, day: %d, hour: %d, minute: %d, second: %d, microsecond: %d", pTime->year, pTime->month, pTime->day, pTime->hour, pTime->minute, pTime->second, pTime->microsecond);
if (pTime->year == 0 || pTime->year >= 10000)
{
return CELL_RTC_ERROR_INVALID_YEAR;
}
if (pTime->month < 1 || pTime->month > 12)
{
return CELL_RTC_ERROR_INVALID_MONTH;
}
const auto& days_in_month = is_leap_year(pTime->year) ? DAYS_IN_MONTH_LEAP : DAYS_IN_MONTH;
if (pTime->day == 0 || pTime->day > days_in_month[pTime->month - 1])
{
return CELL_RTC_ERROR_INVALID_DAY;
}
if (pTime->hour >= 24)
{
return CELL_RTC_ERROR_INVALID_HOUR;
}
if (pTime->minute >= 60)
{
return CELL_RTC_ERROR_INVALID_MINUTE;
}
if (pTime->second >= 60)
{
return CELL_RTC_ERROR_INVALID_SECOND;
}
if (pTime->microsecond >= cellRtcGetTickResolution())
{
return CELL_RTC_ERROR_INVALID_MICROSECOND;
}
return CELL_OK;
}
s32 cellRtcCompareTick(vm::cptr<CellRtcTick> pTick0, vm::cptr<CellRtcTick> pTick1)
{
cellRtc.notice("cellRtcCompareTick(pTick0=*0x%x, pTick1=*0x%x)", pTick0, pTick1);
ensure(!!pTick0 && !!pTick1); // Not checked on LLE
s32 ret = -1;
if (pTick1->tick <= pTick0->tick)
{
ret = pTick1->tick < pTick0->tick;
}
return ret;
}
DECLARE(ppu_module_manager::cellRtc)
("cellRtc", []() {
REG_FUNC(cellRtc, cellRtcGetCurrentTick);
REG_FUNC(cellRtc, cellRtcGetCurrentClock);
REG_FUNC(cellRtc, cellRtcGetCurrentClockLocalTime);
REG_FUNC(cellRtc, cellRtcFormatRfc2822);
REG_FUNC(cellRtc, cellRtcFormatRfc2822LocalTime);
REG_FUNC(cellRtc, cellRtcFormatRfc3339);
REG_FUNC(cellRtc, cellRtcFormatRfc3339LocalTime);
REG_FUNC(cellRtc, cellRtcParseDateTime);
REG_FUNC(cellRtc, cellRtcParseRfc3339);
REG_FUNC(cellRtc, cellRtcGetTick);
REG_FUNC(cellRtc, cellRtcSetTick);
REG_FUNC(cellRtc, cellRtcTickAddTicks);
REG_FUNC(cellRtc, cellRtcTickAddMicroseconds);
REG_FUNC(cellRtc, cellRtcTickAddSeconds);
REG_FUNC(cellRtc, cellRtcTickAddMinutes);
REG_FUNC(cellRtc, cellRtcTickAddHours);
REG_FUNC(cellRtc, cellRtcTickAddDays);
REG_FUNC(cellRtc, cellRtcTickAddWeeks);
REG_FUNC(cellRtc, cellRtcTickAddMonths);
REG_FUNC(cellRtc, cellRtcTickAddYears);
REG_FUNC(cellRtc, cellRtcConvertUtcToLocalTime);
REG_FUNC(cellRtc, cellRtcConvertLocalTimeToUtc);
REG_FUNC(cellRtc, cellRtcGetCurrentSecureTick);
REG_FUNC(cellRtc, cellRtcGetDosTime);
REG_FUNC(cellRtc, cellRtcGetTickResolution);
REG_FUNC(cellRtc, cellRtcGetSystemTime);
REG_FUNC(cellRtc, cellRtcGetTime_t);
REG_FUNC(cellRtc, cellRtcGetWin32FileTime);
REG_FUNC(cellRtc, cellRtcSetConf);
REG_FUNC(cellRtc, cellRtcSetCurrentSecureTick);
REG_FUNC(cellRtc, cellRtcSetCurrentTick);
REG_FUNC(cellRtc, cellRtcSetDosTime);
REG_FUNC(cellRtc, cellRtcSetTime_t);
REG_FUNC(cellRtc, cellRtcSetSystemTime);
REG_FUNC(cellRtc, cellRtcSetWin32FileTime);
REG_FUNC(cellRtc, cellRtcIsLeapYear);
REG_FUNC(cellRtc, cellRtcGetDaysInMonth);
REG_FUNC(cellRtc, cellRtcGetDayOfWeek);
REG_FUNC(cellRtc, cellRtcCheckValid);
REG_FUNC(cellRtc, cellRtcCompareTick);
});
| 49,289
|
C++
|
.cpp
| 1,446
| 31.540802
| 219
| 0.699462
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| false
| false
| false
|
5,300
|
cellJpgEnc.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellJpgEnc.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
#include "cellJpgEnc.h"
LOG_CHANNEL(cellJpgEnc);
template <>
void fmt_class_string<CellJpgEncError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_JPGENC_ERROR_ARG);
STR_CASE(CELL_JPGENC_ERROR_SEQ);
STR_CASE(CELL_JPGENC_ERROR_BUSY);
STR_CASE(CELL_JPGENC_ERROR_EMPTY);
STR_CASE(CELL_JPGENC_ERROR_RESET);
STR_CASE(CELL_JPGENC_ERROR_FATAL);
STR_CASE(CELL_JPGENC_ERROR_STREAM_ABORT);
STR_CASE(CELL_JPGENC_ERROR_STREAM_SKIP);
STR_CASE(CELL_JPGENC_ERROR_STREAM_OVERFLOW);
STR_CASE(CELL_JPGENC_ERROR_STREAM_FILE_OPEN);
}
return unknown;
});
}
s32 cellJpgEncQueryAttr()
{
UNIMPLEMENTED_FUNC(cellJpgEnc);
return CELL_OK;
}
s32 cellJpgEncOpen()
{
UNIMPLEMENTED_FUNC(cellJpgEnc);
return CELL_OK;
}
s32 cellJpgEncOpenEx()
{
UNIMPLEMENTED_FUNC(cellJpgEnc);
return CELL_OK;
}
s32 cellJpgEncClose()
{
UNIMPLEMENTED_FUNC(cellJpgEnc);
return CELL_OK;
}
s32 cellJpgEncWaitForInput()
{
UNIMPLEMENTED_FUNC(cellJpgEnc);
return CELL_OK;
}
s32 cellJpgEncEncodePicture()
{
UNIMPLEMENTED_FUNC(cellJpgEnc);
return CELL_OK;
}
s32 cellJpgEncEncodePicture2()
{
UNIMPLEMENTED_FUNC(cellJpgEnc);
return CELL_OK;
}
s32 cellJpgEncWaitForOutput()
{
UNIMPLEMENTED_FUNC(cellJpgEnc);
return CELL_OK;
}
s32 cellJpgEncGetStreamInfo()
{
UNIMPLEMENTED_FUNC(cellJpgEnc);
return CELL_OK;
}
s32 cellJpgEncReset()
{
UNIMPLEMENTED_FUNC(cellJpgEnc);
return CELL_OK;
}
DECLARE(ppu_module_manager::cellJpgEnc)("cellJpgEnc", []()
{
REG_FUNC(cellJpgEnc, cellJpgEncQueryAttr);
REG_FUNC(cellJpgEnc, cellJpgEncOpen);
REG_FUNC(cellJpgEnc, cellJpgEncOpenEx);
REG_FUNC(cellJpgEnc, cellJpgEncClose);
REG_FUNC(cellJpgEnc, cellJpgEncWaitForInput);
REG_FUNC(cellJpgEnc, cellJpgEncEncodePicture);
REG_FUNC(cellJpgEnc, cellJpgEncEncodePicture2);
REG_FUNC(cellJpgEnc, cellJpgEncWaitForOutput);
REG_FUNC(cellJpgEnc, cellJpgEncGetStreamInfo);
REG_FUNC(cellJpgEnc, cellJpgEncReset);
});
| 2,018
|
C++
|
.cpp
| 88
| 20.943182
| 73
| 0.786311
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| true
| false
| false
| true
| false
| false
|
5,301
|
cellUsbpspcm.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellUsbpspcm.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
LOG_CHANNEL(cellUsbPspcm);
// Return Codes
enum CellUsbpspcmError : u32
{
CELL_USBPSPCM_ERROR_NOT_INITIALIZED = 0x80110401,
CELL_USBPSPCM_ERROR_ALREADY = 0x80110402,
CELL_USBPSPCM_ERROR_INVALID = 0x80110403,
CELL_USBPSPCM_ERROR_NO_MEMORY = 0x80110404,
CELL_USBPSPCM_ERROR_BUSY = 0x80110405,
CELL_USBPSPCM_ERROR_INPROGRESS = 0x80110406,
CELL_USBPSPCM_ERROR_NO_SPACE = 0x80110407,
CELL_USBPSPCM_ERROR_CANCELED = 0x80110408,
CELL_USBPSPCM_ERROR_RESETTING = 0x80110409,
CELL_USBPSPCM_ERROR_RESET_END = 0x8011040A,
CELL_USBPSPCM_ERROR_CLOSED = 0x8011040B,
CELL_USBPSPCM_ERROR_NO_DATA = 0x8011040C,
};
template<>
void fmt_class_string<CellUsbpspcmError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_USBPSPCM_ERROR_NOT_INITIALIZED);
STR_CASE(CELL_USBPSPCM_ERROR_ALREADY);
STR_CASE(CELL_USBPSPCM_ERROR_INVALID);
STR_CASE(CELL_USBPSPCM_ERROR_NO_MEMORY);
STR_CASE(CELL_USBPSPCM_ERROR_BUSY);
STR_CASE(CELL_USBPSPCM_ERROR_INPROGRESS);
STR_CASE(CELL_USBPSPCM_ERROR_NO_SPACE);
STR_CASE(CELL_USBPSPCM_ERROR_CANCELED);
STR_CASE(CELL_USBPSPCM_ERROR_RESETTING);
STR_CASE(CELL_USBPSPCM_ERROR_RESET_END);
STR_CASE(CELL_USBPSPCM_ERROR_CLOSED);
STR_CASE(CELL_USBPSPCM_ERROR_NO_DATA);
}
return unknown;
});
}
error_code cellUsbPspcmInit()
{
UNIMPLEMENTED_FUNC(cellUsbPspcm);
return CELL_OK;
}
error_code cellUsbPspcmEnd()
{
UNIMPLEMENTED_FUNC(cellUsbPspcm);
return CELL_OK;
}
error_code cellUsbPspcmCalcPoolSize()
{
UNIMPLEMENTED_FUNC(cellUsbPspcm);
return CELL_OK;
}
error_code cellUsbPspcmRegister()
{
UNIMPLEMENTED_FUNC(cellUsbPspcm);
return CELL_OK;
}
error_code cellUsbPspcmUnregister()
{
UNIMPLEMENTED_FUNC(cellUsbPspcm);
return CELL_OK;
}
error_code cellUsbPspcmGetAddr()
{
UNIMPLEMENTED_FUNC(cellUsbPspcm);
return CELL_OK;
}
error_code cellUsbPspcmBind()
{
UNIMPLEMENTED_FUNC(cellUsbPspcm);
return CELL_OK;
}
error_code cellUsbPspcmBindAsync()
{
UNIMPLEMENTED_FUNC(cellUsbPspcm);
return CELL_OK;
}
error_code cellUsbPspcmWaitBindAsync()
{
UNIMPLEMENTED_FUNC(cellUsbPspcm);
return CELL_OK;
}
error_code cellUsbPspcmPollBindAsync()
{
UNIMPLEMENTED_FUNC(cellUsbPspcm);
return CELL_OK;
}
error_code cellUsbPspcmCancelBind()
{
UNIMPLEMENTED_FUNC(cellUsbPspcm);
return CELL_OK;
}
error_code cellUsbPspcmClose()
{
UNIMPLEMENTED_FUNC(cellUsbPspcm);
return CELL_OK;
}
error_code cellUsbPspcmSend()
{
UNIMPLEMENTED_FUNC(cellUsbPspcm);
return CELL_OK;
}
error_code cellUsbPspcmSendAsync()
{
UNIMPLEMENTED_FUNC(cellUsbPspcm);
return CELL_OK;
}
error_code cellUsbPspcmWaitSendAsync()
{
UNIMPLEMENTED_FUNC(cellUsbPspcm);
return CELL_OK;
}
error_code cellUsbPspcmPollSendAsync()
{
UNIMPLEMENTED_FUNC(cellUsbPspcm);
return CELL_OK;
}
error_code cellUsbPspcmRecv()
{
UNIMPLEMENTED_FUNC(cellUsbPspcm);
return CELL_OK;
}
error_code cellUsbPspcmRecvAsync()
{
UNIMPLEMENTED_FUNC(cellUsbPspcm);
return CELL_OK;
}
error_code cellUsbPspcmWaitRecvAsync()
{
UNIMPLEMENTED_FUNC(cellUsbPspcm);
return CELL_OK;
}
error_code cellUsbPspcmPollRecvAsync()
{
UNIMPLEMENTED_FUNC(cellUsbPspcm);
return CELL_OK;
}
error_code cellUsbPspcmReset()
{
UNIMPLEMENTED_FUNC(cellUsbPspcm);
return CELL_OK;
}
error_code cellUsbPspcmResetAsync()
{
UNIMPLEMENTED_FUNC(cellUsbPspcm);
return CELL_OK;
}
error_code cellUsbPspcmWaitResetAsync()
{
UNIMPLEMENTED_FUNC(cellUsbPspcm);
return CELL_OK;
}
error_code cellUsbPspcmPollResetAsync()
{
UNIMPLEMENTED_FUNC(cellUsbPspcm);
return CELL_OK;
}
error_code cellUsbPspcmWaitData()
{
UNIMPLEMENTED_FUNC(cellUsbPspcm);
return CELL_OK;
}
error_code cellUsbPspcmPollData()
{
UNIMPLEMENTED_FUNC(cellUsbPspcm);
return CELL_OK;
}
error_code cellUsbPspcmCancelWaitData()
{
UNIMPLEMENTED_FUNC(cellUsbPspcm);
return CELL_OK;
}
DECLARE(ppu_module_manager::cellUsbPspcm)("cellUsbPspcm", []()
{
REG_FUNC(cellUsbPspcm, cellUsbPspcmInit);
REG_FUNC(cellUsbPspcm, cellUsbPspcmEnd);
REG_FUNC(cellUsbPspcm, cellUsbPspcmCalcPoolSize);
REG_FUNC(cellUsbPspcm, cellUsbPspcmRegister);
REG_FUNC(cellUsbPspcm, cellUsbPspcmUnregister);
REG_FUNC(cellUsbPspcm, cellUsbPspcmGetAddr);
REG_FUNC(cellUsbPspcm, cellUsbPspcmBind);
REG_FUNC(cellUsbPspcm, cellUsbPspcmBindAsync);
REG_FUNC(cellUsbPspcm, cellUsbPspcmWaitBindAsync);
REG_FUNC(cellUsbPspcm, cellUsbPspcmPollBindAsync);
REG_FUNC(cellUsbPspcm, cellUsbPspcmCancelBind);
REG_FUNC(cellUsbPspcm, cellUsbPspcmClose);
REG_FUNC(cellUsbPspcm, cellUsbPspcmSend);
REG_FUNC(cellUsbPspcm, cellUsbPspcmSendAsync);
REG_FUNC(cellUsbPspcm, cellUsbPspcmWaitSendAsync);
REG_FUNC(cellUsbPspcm, cellUsbPspcmPollSendAsync);
REG_FUNC(cellUsbPspcm, cellUsbPspcmRecv);
REG_FUNC(cellUsbPspcm, cellUsbPspcmRecvAsync);
REG_FUNC(cellUsbPspcm, cellUsbPspcmWaitRecvAsync);
REG_FUNC(cellUsbPspcm, cellUsbPspcmPollRecvAsync);
REG_FUNC(cellUsbPspcm, cellUsbPspcmReset);
REG_FUNC(cellUsbPspcm, cellUsbPspcmResetAsync);
REG_FUNC(cellUsbPspcm, cellUsbPspcmWaitResetAsync);
REG_FUNC(cellUsbPspcm, cellUsbPspcmPollResetAsync);
REG_FUNC(cellUsbPspcm, cellUsbPspcmWaitData);
REG_FUNC(cellUsbPspcm, cellUsbPspcmPollData);
REG_FUNC(cellUsbPspcm, cellUsbPspcmCancelWaitData);
});
| 5,306
|
C++
|
.cpp
| 207
| 23.801932
| 75
| 0.802645
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| true
| false
| false
| true
| false
| false
|
5,302
|
sceNp2.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/sceNp2.cpp
|
#include "stdafx.h"
#include "Emu/Cell/PPUModule.h"
#include "Emu/IdManager.h"
#include "sceNp.h"
#include "sceNp2.h"
#include "Emu/NP/np_handler.h"
#include "Emu/NP/np_contexts.h"
#include "Emu/NP/np_helpers.h"
#include "cellSysutil.h"
LOG_CHANNEL(sceNp2);
template <>
void fmt_class_string<SceNpMatching2Error>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error) {
switch (error)
{
STR_CASE(SCE_NP_MATCHING2_ERROR_OUT_OF_MEMORY);
STR_CASE(SCE_NP_MATCHING2_ERROR_ALREADY_INITIALIZED);
STR_CASE(SCE_NP_MATCHING2_ERROR_NOT_INITIALIZED);
STR_CASE(SCE_NP_MATCHING2_ERROR_CONTEXT_MAX);
STR_CASE(SCE_NP_MATCHING2_ERROR_CONTEXT_ALREADY_EXISTS);
STR_CASE(SCE_NP_MATCHING2_ERROR_CONTEXT_NOT_FOUND);
STR_CASE(SCE_NP_MATCHING2_ERROR_CONTEXT_ALREADY_STARTED);
STR_CASE(SCE_NP_MATCHING2_ERROR_CONTEXT_NOT_STARTED);
STR_CASE(SCE_NP_MATCHING2_ERROR_SERVER_NOT_FOUND);
STR_CASE(SCE_NP_MATCHING2_ERROR_INVALID_ARGUMENT);
STR_CASE(SCE_NP_MATCHING2_ERROR_INVALID_CONTEXT_ID);
STR_CASE(SCE_NP_MATCHING2_ERROR_INVALID_SERVER_ID);
STR_CASE(SCE_NP_MATCHING2_ERROR_INVALID_WORLD_ID);
STR_CASE(SCE_NP_MATCHING2_ERROR_INVALID_LOBBY_ID);
STR_CASE(SCE_NP_MATCHING2_ERROR_INVALID_ROOM_ID);
STR_CASE(SCE_NP_MATCHING2_ERROR_INVALID_MEMBER_ID);
STR_CASE(SCE_NP_MATCHING2_ERROR_INVALID_ATTRIBUTE_ID);
STR_CASE(SCE_NP_MATCHING2_ERROR_INVALID_CASTTYPE);
STR_CASE(SCE_NP_MATCHING2_ERROR_INVALID_SORT_METHOD);
STR_CASE(SCE_NP_MATCHING2_ERROR_INVALID_MAX_SLOT);
STR_CASE(SCE_NP_MATCHING2_ERROR_INVALID_MATCHING_SPACE);
STR_CASE(SCE_NP_MATCHING2_ERROR_INVALID_BLOCK_KICK_FLAG);
STR_CASE(SCE_NP_MATCHING2_ERROR_INVALID_MESSAGE_TARGET);
STR_CASE(SCE_NP_MATCHING2_ERROR_RANGE_FILTER_MAX);
STR_CASE(SCE_NP_MATCHING2_ERROR_INSUFFICIENT_BUFFER);
STR_CASE(SCE_NP_MATCHING2_ERROR_DESTINATION_DISAPPEARED);
STR_CASE(SCE_NP_MATCHING2_ERROR_REQUEST_TIMEOUT);
STR_CASE(SCE_NP_MATCHING2_ERROR_INVALID_ALIGNMENT);
STR_CASE(SCE_NP_MATCHING2_ERROR_REQUEST_CB_QUEUE_OVERFLOW);
STR_CASE(SCE_NP_MATCHING2_ERROR_EVENT_CB_QUEUE_OVERFLOW);
STR_CASE(SCE_NP_MATCHING2_ERROR_MSG_CB_QUEUE_OVERFLOW);
STR_CASE(SCE_NP_MATCHING2_ERROR_CONNECTION_CLOSED_BY_SERVER);
STR_CASE(SCE_NP_MATCHING2_ERROR_SSL_VERIFY_FAILED);
STR_CASE(SCE_NP_MATCHING2_ERROR_SSL_HANDSHAKE);
STR_CASE(SCE_NP_MATCHING2_ERROR_SSL_SEND);
STR_CASE(SCE_NP_MATCHING2_ERROR_SSL_RECV);
STR_CASE(SCE_NP_MATCHING2_ERROR_JOINED_SESSION_MAX);
STR_CASE(SCE_NP_MATCHING2_ERROR_ALREADY_JOINED);
STR_CASE(SCE_NP_MATCHING2_ERROR_INVALID_SESSION_TYPE);
STR_CASE(SCE_NP_MATCHING2_ERROR_CLAN_LOBBY_NOT_EXIST);
STR_CASE(SCE_NP_MATCHING2_ERROR_NP_SIGNED_OUT);
STR_CASE(SCE_NP_MATCHING2_ERROR_CONTEXT_UNAVAILABLE);
STR_CASE(SCE_NP_MATCHING2_ERROR_SERVER_NOT_AVAILABLE);
STR_CASE(SCE_NP_MATCHING2_ERROR_NOT_ALLOWED);
STR_CASE(SCE_NP_MATCHING2_ERROR_ABORTED);
STR_CASE(SCE_NP_MATCHING2_ERROR_REQUEST_NOT_FOUND);
STR_CASE(SCE_NP_MATCHING2_ERROR_SESSION_DESTROYED);
STR_CASE(SCE_NP_MATCHING2_ERROR_CONTEXT_STOPPED);
STR_CASE(SCE_NP_MATCHING2_ERROR_INVALID_REQUEST_PARAMETER);
STR_CASE(SCE_NP_MATCHING2_ERROR_NOT_NP_SIGN_IN);
STR_CASE(SCE_NP_MATCHING2_ERROR_ROOM_NOT_FOUND);
STR_CASE(SCE_NP_MATCHING2_ERROR_ROOM_MEMBER_NOT_FOUND);
STR_CASE(SCE_NP_MATCHING2_ERROR_LOBBY_NOT_FOUND);
STR_CASE(SCE_NP_MATCHING2_ERROR_LOBBY_MEMBER_NOT_FOUND);
STR_CASE(SCE_NP_MATCHING2_ERROR_EVENT_DATA_NOT_FOUND);
STR_CASE(SCE_NP_MATCHING2_ERROR_KEEPALIVE_TIMEOUT);
STR_CASE(SCE_NP_MATCHING2_ERROR_TIMEOUT_TOO_SHORT);
STR_CASE(SCE_NP_MATCHING2_ERROR_TIMEDOUT);
STR_CASE(SCE_NP_MATCHING2_ERROR_CREATE_HEAP);
STR_CASE(SCE_NP_MATCHING2_ERROR_INVALID_ATTRIBUTE_SIZE);
STR_CASE(SCE_NP_MATCHING2_ERROR_CANNOT_ABORT);
STR_CASE(SCE_NP_MATCHING2_RESOLVER_ERROR_NO_DNS_SERVER);
STR_CASE(SCE_NP_MATCHING2_RESOLVER_ERROR_INVALID_PACKET);
STR_CASE(SCE_NP_MATCHING2_RESOLVER_ERROR_TIMEOUT);
STR_CASE(SCE_NP_MATCHING2_RESOLVER_ERROR_NO_RECORD);
STR_CASE(SCE_NP_MATCHING2_RESOLVER_ERROR_RES_PACKET_FORMAT);
STR_CASE(SCE_NP_MATCHING2_RESOLVER_ERROR_RES_SERVER_FAILURE);
STR_CASE(SCE_NP_MATCHING2_RESOLVER_ERROR_NO_HOST);
STR_CASE(SCE_NP_MATCHING2_RESOLVER_ERROR_RES_NOT_IMPLEMENTED);
STR_CASE(SCE_NP_MATCHING2_RESOLVER_ERROR_RES_SERVER_REFUSED);
STR_CASE(SCE_NP_MATCHING2_RESOLVER_ERROR_RESP_TRUNCATED);
STR_CASE(SCE_NP_MATCHING2_SERVER_ERROR_BAD_REQUEST);
STR_CASE(SCE_NP_MATCHING2_SERVER_ERROR_SERVICE_UNAVAILABLE);
STR_CASE(SCE_NP_MATCHING2_SERVER_ERROR_BUSY);
STR_CASE(SCE_NP_MATCHING2_SERVER_ERROR_END_OF_SERVICE);
STR_CASE(SCE_NP_MATCHING2_SERVER_ERROR_INTERNAL_SERVER_ERROR);
STR_CASE(SCE_NP_MATCHING2_SERVER_ERROR_PLAYER_BANNED);
STR_CASE(SCE_NP_MATCHING2_SERVER_ERROR_FORBIDDEN);
STR_CASE(SCE_NP_MATCHING2_SERVER_ERROR_BLOCKED);
STR_CASE(SCE_NP_MATCHING2_SERVER_ERROR_UNSUPPORTED_NP_ENV);
STR_CASE(SCE_NP_MATCHING2_SERVER_ERROR_INVALID_TICKET);
STR_CASE(SCE_NP_MATCHING2_SERVER_ERROR_INVALID_SIGNATURE);
STR_CASE(SCE_NP_MATCHING2_SERVER_ERROR_EXPIRED_TICKET);
STR_CASE(SCE_NP_MATCHING2_SERVER_ERROR_ENTITLEMENT_REQUIRED);
STR_CASE(SCE_NP_MATCHING2_SERVER_ERROR_NO_SUCH_CONTEXT);
STR_CASE(SCE_NP_MATCHING2_SERVER_ERROR_CLOSED);
STR_CASE(SCE_NP_MATCHING2_SERVER_ERROR_NO_SUCH_TITLE);
STR_CASE(SCE_NP_MATCHING2_SERVER_ERROR_NO_SUCH_WORLD);
STR_CASE(SCE_NP_MATCHING2_SERVER_ERROR_NO_SUCH_LOBBY);
STR_CASE(SCE_NP_MATCHING2_SERVER_ERROR_NO_SUCH_ROOM);
STR_CASE(SCE_NP_MATCHING2_SERVER_ERROR_NO_SUCH_LOBBY_INSTANCE);
STR_CASE(SCE_NP_MATCHING2_SERVER_ERROR_NO_SUCH_ROOM_INSTANCE);
STR_CASE(SCE_NP_MATCHING2_SERVER_ERROR_PASSWORD_MISMATCH);
STR_CASE(SCE_NP_MATCHING2_SERVER_ERROR_LOBBY_FULL);
STR_CASE(SCE_NP_MATCHING2_SERVER_ERROR_ROOM_FULL);
STR_CASE(SCE_NP_MATCHING2_SERVER_ERROR_GROUP_FULL);
STR_CASE(SCE_NP_MATCHING2_SERVER_ERROR_NO_SUCH_USER);
STR_CASE(SCE_NP_MATCHING2_SERVER_ERROR_TITLE_PASSPHRASE_MISMATCH);
STR_CASE(SCE_NP_MATCHING2_SERVER_ERROR_DUPLICATE_LOBBY);
STR_CASE(SCE_NP_MATCHING2_SERVER_ERROR_DUPLICATE_ROOM);
STR_CASE(SCE_NP_MATCHING2_SERVER_ERROR_NO_JOIN_GROUP_LABEL);
STR_CASE(SCE_NP_MATCHING2_SERVER_ERROR_NO_SUCH_GROUP);
STR_CASE(SCE_NP_MATCHING2_SERVER_ERROR_NO_PASSWORD);
STR_CASE(SCE_NP_MATCHING2_SERVER_ERROR_MAX_OVER_SLOT_GROUP);
STR_CASE(SCE_NP_MATCHING2_SERVER_ERROR_MAX_OVER_PASSWORD_MASK);
STR_CASE(SCE_NP_MATCHING2_SERVER_ERROR_DUPLICATE_GROUP_LABEL);
STR_CASE(SCE_NP_MATCHING2_SERVER_ERROR_REQUEST_OVERFLOW);
STR_CASE(SCE_NP_MATCHING2_SERVER_ERROR_ALREADY_JOINED);
STR_CASE(SCE_NP_MATCHING2_SERVER_ERROR_NAT_TYPE_MISMATCH);
STR_CASE(SCE_NP_MATCHING2_SERVER_ERROR_ROOM_INCONSISTENCY);
// STR_CASE(SCE_NP_MATCHING2_NET_ERRNO_BASE);
// STR_CASE(SCE_NP_MATCHING2_NET_H_ERRNO_BASE);
}
return unknown;
});
}
template <>
void fmt_class_string<SceNpOauthError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error) {
switch (error)
{
STR_CASE(SCE_NP_OAUTH_ERROR_UNKNOWN);
STR_CASE(SCE_NP_OAUTH_ERROR_ALREADY_INITIALIZED);
STR_CASE(SCE_NP_OAUTH_ERROR_NOT_INITIALIZED);
STR_CASE(SCE_NP_OAUTH_ERROR_INVALID_ARGUMENT);
STR_CASE(SCE_NP_OAUTH_ERROR_OUT_OF_MEMORY);
STR_CASE(SCE_NP_OAUTH_ERROR_OUT_OF_BUFFER);
STR_CASE(SCE_NP_OAUTH_ERROR_BAD_RESPONSE);
STR_CASE(SCE_NP_OAUTH_ERROR_ABORTED);
STR_CASE(SCE_NP_OAUTH_ERROR_SIGNED_OUT);
STR_CASE(SCE_NP_OAUTH_ERROR_REQUEST_NOT_FOUND);
STR_CASE(SCE_NP_OAUTH_ERROR_SSL_ERR_CN_CHECK);
STR_CASE(SCE_NP_OAUTH_ERROR_SSL_ERR_UNKNOWN_CA);
STR_CASE(SCE_NP_OAUTH_ERROR_SSL_ERR_NOT_AFTER_CHECK);
STR_CASE(SCE_NP_OAUTH_ERROR_SSL_ERR_NOT_BEFORE_CHECK);
STR_CASE(SCE_NP_OAUTH_ERROR_SSL_ERR_INVALID_CERT);
STR_CASE(SCE_NP_OAUTH_ERROR_SSL_ERR_INTERNAL);
STR_CASE(SCE_NP_OAUTH_ERROR_REQUEST_MAX);
STR_CASE(SCE_NP_OAUTH_SERVER_ERROR_BANNED_CONSOLE);
STR_CASE(SCE_NP_OAUTH_SERVER_ERROR_INVALID_LOGIN);
STR_CASE(SCE_NP_OAUTH_SERVER_ERROR_INACTIVE_ACCOUNT);
STR_CASE(SCE_NP_OAUTH_SERVER_ERROR_SUSPENDED_ACCOUNT);
STR_CASE(SCE_NP_OAUTH_SERVER_ERROR_SUSPENDED_DEVICE);
STR_CASE(SCE_NP_OAUTH_SERVER_ERROR_PASSWORD_EXPIRED);
STR_CASE(SCE_NP_OAUTH_SERVER_ERROR_TOSUA_MUST_BE_RE_ACCEPTED);
STR_CASE(SCE_NP_OAUTH_SERVER_ERROR_TOSUA_MUST_BE_RE_ACCEPTED_FOR_SUBACCOUNT);
STR_CASE(SCE_NP_OAUTH_SERVER_ERROR_BANNED_ACCOUNT);
STR_CASE(SCE_NP_OAUTH_SERVER_ERROR_SERVICE_END);
STR_CASE(SCE_NP_OAUTH_SERVER_ERROR_SERVICE_UNAVAILABLE);
}
return unknown;
});
}
error_code sceNpMatching2Init2(u32 stackSize, s32 priority, vm::ptr<SceNpMatching2UtilityInitParam> param);
error_code sceNpMatching2Term(ppu_thread& ppu);
error_code sceNpMatching2Term2();
error_code generic_match2_error_check(const named_thread<np::np_handler>& nph, SceNpMatching2ContextId ctxId, vm::cptr<void> reqParam)
{
if (!nph.is_NP2_Match2_init)
{
return SCE_NP_MATCHING2_ERROR_NOT_INITIALIZED;
}
if (!reqParam)
{
return SCE_NP_MATCHING2_ERROR_INVALID_ARGUMENT;
}
if (!ctxId)
{
return SCE_NP_MATCHING2_ERROR_INVALID_CONTEXT_ID;
}
if (!check_match2_context(ctxId))
{
return SCE_NP_MATCHING2_ERROR_CONTEXT_NOT_FOUND;
}
return CELL_OK;
}
error_code sceNp2Init(u32 poolsize, vm::ptr<void> poolptr)
{
sceNp2.warning("sceNp2Init(poolsize=0x%x, poolptr=*0x%x)", poolsize, poolptr);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
{
std::lock_guard lock(nph.mutex_status);
if (nph.is_NP2_init)
{
return SCE_NP_ERROR_ALREADY_INITIALIZED;
}
}
const u32 result = std::bit_cast<u32>(sceNpInit(poolsize, poolptr));
if (result && result != SCE_NP_ERROR_ALREADY_INITIALIZED)
{
return result;
}
nph.is_NP2_init = true;
return CELL_OK;
}
error_code sceNpMatching2Init(u32 stackSize, s32 priority)
{
sceNp2.todo("sceNpMatching2Init(stackSize=0x%x, priority=%d)", stackSize, priority);
return sceNpMatching2Init2(stackSize, priority, vm::null); // > SDK 2.4.0
}
error_code sceNpMatching2Init2(u32 stackSize, s32 priority, vm::ptr<SceNpMatching2UtilityInitParam> param)
{
sceNp2.warning("sceNpMatching2Init2(stackSize=0x%x, priority=%d, param=*0x%x)", stackSize, priority, param);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP2_init)
{
return SCE_NP_ERROR_NOT_INITIALIZED;
}
if (nph.is_NP2_Match2_init)
{
return SCE_NP_MATCHING2_ERROR_ALREADY_INITIALIZED;
}
// TODO:
// 1. Create an internal thread
// 2. Create heap area to be used by the NP matching 2 utility
// 3. Set maximum lengths for the event data queues in the system
nph.is_NP2_Match2_init = true;
return CELL_OK;
}
error_code sceNp2Term(ppu_thread& ppu)
{
sceNp2.warning("sceNp2Term()");
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
{
std::lock_guard lock(nph.mutex_status);
if (!nph.is_NP2_init)
{
return SCE_NP_ERROR_NOT_INITIALIZED;
}
}
// TODO: does this return on error_code ?
sceNpMatching2Term(ppu);
// cellSysutilUnregisterCallbackDispatcher();
sceNpTerm();
nph.is_NP2_init = false;
return CELL_OK;
}
error_code sceNpMatching2Term(ppu_thread&)
{
sceNp2.warning("sceNpMatching2Term()");
return sceNpMatching2Term2(); // > SDK 2.4.0
}
error_code sceNpMatching2Term2()
{
sceNp2.warning("sceNpMatching2Term2()");
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
{
std::lock_guard lock(nph.mutex_status);
if (!nph.is_NP2_init)
{
return SCE_NP_ERROR_NOT_INITIALIZED;
}
if (!nph.is_NP2_Match2_init)
{
return SCE_NP_MATCHING2_ERROR_NOT_INITIALIZED;
}
nph.is_NP2_Match2_init = false;
}
idm::clear<match2_ctx>();
auto& sigh = g_fxo->get<named_thread<signaling_handler>>();
sigh.clear_match2_ctx();
return CELL_OK;
}
error_code sceNpMatching2DestroyContext(SceNpMatching2ContextId ctxId)
{
sceNp2.warning("sceNpMatching2DestroyContext(ctxId=%d)", ctxId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP2_Match2_init)
{
return SCE_NP_MATCHING2_ERROR_NOT_INITIALIZED;
}
if (!destroy_match2_context(ctxId))
return SCE_NP_MATCHING2_ERROR_CONTEXT_NOT_FOUND;
auto& sigh = g_fxo->get<named_thread<signaling_handler>>();
sigh.remove_match2_ctx(ctxId);
return CELL_OK;
}
error_code sceNpMatching2LeaveLobby(
SceNpMatching2ContextId ctxId, vm::cptr<SceNpMatching2LeaveLobbyRequest> reqParam, vm::cptr<SceNpMatching2RequestOptParam> optParam, vm::ptr<SceNpMatching2RequestId> assignedReqId)
{
sceNp2.todo("sceNpMatching2LeaveLobby(ctxId=%d, reqParam=*0x%x, optParam=*0x%x, assignedReqId=*0x%x)", ctxId, reqParam, optParam, assignedReqId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (auto res = generic_match2_error_check(nph, ctxId, reqParam); res != CELL_OK)
{
return res;
}
return CELL_OK;
}
error_code sceNpMatching2RegisterLobbyMessageCallback(SceNpMatching2ContextId ctxId, vm::ptr<SceNpMatching2LobbyMessageCallback> cbFunc, vm::ptr<void> cbFuncArg)
{
sceNp2.todo("sceNpMatching2RegisterLobbyMessageCallback(ctxId=%d, cbFunc=*0x%x, cbFuncArg=*0x%x)", ctxId, cbFunc, cbFuncArg);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP2_Match2_init)
{
return SCE_NP_MATCHING2_ERROR_NOT_INITIALIZED;
}
return CELL_OK;
}
error_code sceNpMatching2GetWorldInfoList(
SceNpMatching2ContextId ctxId, vm::cptr<SceNpMatching2GetWorldInfoListRequest> reqParam, vm::cptr<SceNpMatching2RequestOptParam> optParam, vm::ptr<SceNpMatching2RequestId> assignedReqId)
{
sceNp2.warning("sceNpMatching2GetWorldInfoList(ctxId=%d, reqParam=*0x%x, optParam=*0x%x, assignedReqId=*0x%x)", ctxId, reqParam, optParam, assignedReqId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (auto res = generic_match2_error_check(nph, ctxId, reqParam); res != CELL_OK)
{
return res;
}
if (reqParam->serverId == 0)
{
return SCE_NP_MATCHING2_ERROR_INVALID_SERVER_ID;
}
const u32 request_id = nph.get_world_list(ctxId, optParam, reqParam->serverId);
if (assignedReqId)
{
*assignedReqId = request_id;
}
return CELL_OK;
}
error_code sceNpMatching2RegisterLobbyEventCallback(SceNpMatching2ContextId ctxId, vm::ptr<SceNpMatching2LobbyEventCallback> cbFunc, vm::ptr<void> cbFuncArg)
{
sceNp2.todo("sceNpMatching2RegisterLobbyEventCallback(ctxId=%d, cbFunc=*0x%x, cbFuncArg=*0x%x)", ctxId, cbFunc, cbFuncArg);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP2_Match2_init)
{
return SCE_NP_MATCHING2_ERROR_NOT_INITIALIZED;
}
return CELL_OK;
}
error_code sceNpMatching2GetLobbyMemberDataInternalList(SceNpMatching2ContextId ctxId, vm::cptr<SceNpMatching2GetLobbyMemberDataInternalListRequest> reqParam,
vm::cptr<SceNpMatching2RequestOptParam> optParam, vm::ptr<SceNpMatching2RequestId> assignedReqId)
{
sceNp2.todo("sceNpMatching2GetLobbyMemberDataInternalList(ctxId=%d, reqParam=*0x%x, optParam=*0x%x, assignedReqId=*0x%x)", ctxId, reqParam, optParam, assignedReqId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (auto res = generic_match2_error_check(nph, ctxId, reqParam); res != CELL_OK)
{
return res;
}
return CELL_OK;
}
error_code sceNpMatching2SearchRoom(
SceNpMatching2ContextId ctxId, vm::cptr<SceNpMatching2SearchRoomRequest> reqParam, vm::cptr<SceNpMatching2RequestOptParam> optParam, vm::ptr<SceNpMatching2RequestId> assignedReqId)
{
sceNp2.warning("sceNpMatching2SearchRoom(ctxId=%d, reqParam=*0x%x, optParam=*0x%x, assignedReqId=*0x%x)", ctxId, reqParam, optParam, assignedReqId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (auto res = generic_match2_error_check(nph, ctxId, reqParam); res != CELL_OK)
{
return res;
}
const u32 request_id = nph.search_room(ctxId, optParam, reqParam.get_ptr());
if (assignedReqId)
{
*assignedReqId = request_id;
}
return CELL_OK;
}
error_code sceNpMatching2SignalingGetConnectionStatus(
SceNpMatching2ContextId ctxId, SceNpMatching2RoomId roomId, SceNpMatching2RoomMemberId memberId, vm::ptr<s32> connStatus, vm::ptr<np_in_addr> peerAddr, vm::ptr<np_in_port_t> peerPort)
{
sceNp2.warning("sceNpMatching2SignalingGetConnectionStatus(ctxId=%d, roomId=%d, memberId=%d, connStatus=*0x%x, peerAddr=*0x%x, peerPort=*0x%x)", ctxId, roomId, memberId, connStatus, peerAddr, peerPort);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP2_Match2_init)
{
return SCE_NP_MATCHING2_ERROR_NOT_INITIALIZED;
}
if (!connStatus)
{
return SCE_NP_MATCHING2_ERROR_INVALID_ARGUMENT;
}
auto [res, npid] = nph.local_get_npid(roomId, memberId);
if (res)
{
*connStatus = SCE_NP_SIGNALING_CONN_STATUS_INACTIVE;
return res;
}
if (np::is_same_npid(nph.get_npid(), *npid))
{
*connStatus = SCE_NP_SIGNALING_CONN_STATUS_INACTIVE;
return SCE_NP_SIGNALING_ERROR_OWN_NP_ID;
}
auto& sigh = g_fxo->get<named_thread<signaling_handler>>();
auto conn_id = sigh.get_conn_id_from_npid(*npid);
if (!conn_id)
{
*connStatus = SCE_NP_SIGNALING_CONN_STATUS_INACTIVE;
return SCE_NP_SIGNALING_ERROR_CONN_NOT_FOUND;
}
const auto si = sigh.get_sig_infos(*conn_id);
if (!si)
{
*connStatus = SCE_NP_SIGNALING_CONN_STATUS_INACTIVE;
return SCE_NP_SIGNALING_ERROR_CONN_NOT_FOUND;
}
*connStatus = si->conn_status;
if (peerAddr)
{
(*peerAddr).np_s_addr = si->addr; // infos.addr is already BE
}
if (peerPort)
{
*peerPort = si->port;
}
return CELL_OK;
}
error_code sceNpMatching2SetUserInfo(
SceNpMatching2ContextId ctxId, vm::cptr<SceNpMatching2SetUserInfoRequest> reqParam, vm::cptr<SceNpMatching2RequestOptParam> optParam, vm::ptr<SceNpMatching2RequestId> assignedReqId)
{
sceNp2.warning("sceNpMatching2SetUserInfo(ctxId=%d, reqParam=*0x%x, optParam=*0x%x, assignedReqId=*0x%x)", ctxId, reqParam, optParam, assignedReqId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (auto res = generic_match2_error_check(nph, ctxId, reqParam); res != CELL_OK)
{
return res;
}
const u32 request_id = nph.set_userinfo(ctxId, optParam, reqParam.get_ptr());
if (assignedReqId)
{
*assignedReqId = request_id;
}
return CELL_OK;
}
error_code sceNpMatching2GetClanLobbyId(SceNpMatching2ContextId ctxId, SceNpClanId clanId, vm::ptr<SceNpMatching2LobbyId> lobbyId)
{
sceNp2.todo("sceNpMatching2GetClanLobbyId(ctxId=%d, clanId=%d, lobbyId=*0x%x)", ctxId, clanId, lobbyId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP2_Match2_init)
{
return SCE_NP_MATCHING2_ERROR_NOT_INITIALIZED;
}
return CELL_OK;
}
error_code sceNpMatching2GetLobbyMemberDataInternal(
SceNpMatching2ContextId ctxId, vm::cptr<SceNpMatching2GetLobbyMemberDataInternalRequest> reqParam, vm::cptr<SceNpMatching2RequestOptParam> optParam, vm::ptr<SceNpMatching2RequestId> assignedReqId)
{
sceNp2.todo("sceNpMatching2GetLobbyMemberDataInternal(ctxId=%d, reqParam=*0x%x, optParam=*0x%x, assignedReqId=*0x%x)", ctxId, reqParam, optParam, assignedReqId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (auto res = generic_match2_error_check(nph, ctxId, reqParam); res != CELL_OK)
{
return res;
}
return CELL_OK;
}
error_code sceNpMatching2ContextStart(SceNpMatching2ContextId ctxId)
{
sceNp2.warning("sceNpMatching2ContextStart(ctxId=%d)", ctxId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP2_Match2_init)
{
return SCE_NP_MATCHING2_ERROR_NOT_INITIALIZED;
}
const auto ctx = get_match2_context(ctxId);
if (!ctx)
return SCE_NP_MATCHING2_ERROR_CONTEXT_NOT_FOUND;
if (!ctx->started.compare_and_swap_test(0, 1))
return SCE_NP_MATCHING2_ERROR_CONTEXT_ALREADY_STARTED;
if (ctx->context_callback)
{
sysutil_register_cb([=, context_callback = ctx->context_callback, context_callback_param = ctx->context_callback_param](ppu_thread& cb_ppu) -> s32
{
context_callback(cb_ppu, ctxId, SCE_NP_MATCHING2_CONTEXT_EVENT_Start, SCE_NP_MATCHING2_EVENT_CAUSE_CONTEXT_ACTION, 0, context_callback_param);
return 0;
});
}
return CELL_OK;
}
error_code sceNpMatching2CreateServerContext(
SceNpMatching2ContextId ctxId, vm::cptr<SceNpMatching2CreateServerContextRequest> reqParam, vm::cptr<SceNpMatching2RequestOptParam> optParam, vm::ptr<SceNpMatching2RequestId> assignedReqId)
{
sceNp2.warning("sceNpMatching2CreateServerContext(ctxId=%d, reqParam=*0x%x, optParam=*0x%x, assignedReqId=*0x%x)", ctxId, reqParam, optParam, assignedReqId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (auto res = generic_match2_error_check(nph, ctxId, reqParam); res != CELL_OK)
{
return res;
}
if (reqParam->serverId == 0)
{
return SCE_NP_MATCHING2_ERROR_INVALID_SERVER_ID;
}
const u32 request_id = nph.create_server_context(ctxId, optParam, reqParam->serverId);
if (assignedReqId)
{
*assignedReqId = request_id;
}
return CELL_OK;
}
error_code sceNpMatching2GetMemoryInfo(vm::ptr<SceNpMatching2MemoryInfo> memInfo) // TODO
{
sceNp2.todo("sceNpMatching2GetMemoryInfo(memInfo=*0x%x)", memInfo);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP2_Match2_init)
{
return SCE_NP_MATCHING2_ERROR_NOT_INITIALIZED;
}
return CELL_OK;
}
error_code sceNpMatching2LeaveRoom(
SceNpMatching2ContextId ctxId, vm::cptr<SceNpMatching2LeaveRoomRequest> reqParam, vm::cptr<SceNpMatching2RequestOptParam> optParam, vm::ptr<SceNpMatching2RequestId> assignedReqId)
{
sceNp2.warning("sceNpMatching2LeaveRoom(ctxId=%d, reqParam=*0x%x, optParam=*0x%x, assignedReqId=*0x%x)", ctxId, reqParam, optParam, assignedReqId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (auto res = generic_match2_error_check(nph, ctxId, reqParam); res != CELL_OK)
{
return res;
}
const u32 request_id = nph.leave_room(ctxId, optParam, reqParam.get_ptr());
if (assignedReqId)
{
*assignedReqId = request_id;
}
return CELL_OK;
}
error_code sceNpMatching2SetRoomDataExternal(
SceNpMatching2ContextId ctxId, vm::cptr<SceNpMatching2SetRoomDataExternalRequest> reqParam, vm::cptr<SceNpMatching2RequestOptParam> optParam, vm::ptr<SceNpMatching2RequestId> assignedReqId)
{
sceNp2.warning("sceNpMatching2SetRoomDataExternal(ctxId=%d, reqParam=*0x%x, optParam=*0x%x, assignedReqId=*0x%x)", ctxId, reqParam, optParam, assignedReqId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (auto res = generic_match2_error_check(nph, ctxId, reqParam); res != CELL_OK)
{
return res;
}
const u32 request_id = nph.set_roomdata_external(ctxId, optParam, reqParam.get_ptr());
if (assignedReqId)
{
*assignedReqId = request_id;
}
return CELL_OK;
}
error_code sceNpMatching2SignalingGetConnectionInfo(
SceNpMatching2ContextId ctxId, SceNpMatching2RoomId roomId, SceNpMatching2RoomMemberId memberId, s32 code, vm::ptr<SceNpSignalingConnectionInfo> connInfo)
{
sceNp2.warning("sceNpMatching2SignalingGetConnectionInfo(ctxId=%d, roomId=%d, memberId=%d, code=%d, connInfo=*0x%x)", ctxId, roomId, memberId, code, connInfo);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP2_Match2_init)
{
return SCE_NP_MATCHING2_ERROR_NOT_INITIALIZED;
}
if (!connInfo)
{
return SCE_NP_MATCHING2_ERROR_INVALID_ARGUMENT;
}
auto [res, npid] = nph.local_get_npid(roomId, memberId);
if (res)
return res;
if (np::is_same_npid(nph.get_npid(), *npid))
return SCE_NP_SIGNALING_ERROR_OWN_NP_ID;
auto& sigh = g_fxo->get<named_thread<signaling_handler>>();
auto conn_id = sigh.get_conn_id_from_npid(*npid);
if (!conn_id)
return SCE_NP_SIGNALING_ERROR_CONN_NOT_FOUND;
const auto si = sigh.get_sig_infos(*conn_id);
if (!si)
return SCE_NP_SIGNALING_ERROR_CONN_NOT_FOUND;
switch (code)
{
case SCE_NP_SIGNALING_CONN_INFO_RTT:
{
connInfo->rtt = si->rtt;
sceNp2.warning("Returning a RTT of %d microseconds", connInfo->rtt);
break;
}
case SCE_NP_SIGNALING_CONN_INFO_BANDWIDTH:
{
connInfo->bandwidth = 100'000'000; // 100 MBPS HACK
break;
}
case SCE_NP_SIGNALING_CONN_INFO_PEER_NPID:
{
connInfo->npId = si->npid;
break;
}
case SCE_NP_SIGNALING_CONN_INFO_PEER_ADDRESS:
{
connInfo->address.port = std::bit_cast<u16, be_t<u16>>(si->port);
connInfo->address.addr.np_s_addr = si->addr;
break;
}
case SCE_NP_SIGNALING_CONN_INFO_MAPPED_ADDRESS:
{
connInfo->address.port = std::bit_cast<u16, be_t<u16>>(si->mapped_port);
connInfo->address.addr.np_s_addr = si->mapped_addr;
break;
}
case SCE_NP_SIGNALING_CONN_INFO_PACKET_LOSS:
{
connInfo->packet_loss = 0; // HACK
break;
}
default:
{
return SCE_NP_MATCHING2_ERROR_INVALID_ARGUMENT;
}
}
return CELL_OK;
}
error_code sceNpMatching2SendRoomMessage(
SceNpMatching2ContextId ctxId, vm::cptr<SceNpMatching2SendRoomMessageRequest> reqParam, vm::cptr<SceNpMatching2RequestOptParam> optParam, vm::ptr<SceNpMatching2RequestId> assignedReqId)
{
sceNp2.warning("sceNpMatching2SendRoomMessage(ctxId=%d, reqParam=*0x%x, optParam=*0x%x, assignedReqId=*0x%x)", ctxId, reqParam, optParam, assignedReqId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (auto res = generic_match2_error_check(nph, ctxId, reqParam); res != CELL_OK)
{
return res;
}
const u32 request_id = nph.send_room_message(ctxId, optParam, reqParam.get_ptr());
if (assignedReqId)
{
*assignedReqId = request_id;
}
return CELL_OK;
}
error_code sceNpMatching2JoinLobby(
SceNpMatching2ContextId ctxId, vm::cptr<SceNpMatching2JoinLobbyRequest> reqParam, vm::cptr<SceNpMatching2RequestOptParam> optParam, vm::ptr<SceNpMatching2RequestId> assignedReqId)
{
sceNp2.todo("sceNpMatching2JoinLobby(ctxId=%d, reqParam=*0x%x, optParam=*0x%x, assignedReqId=*0x%x)", ctxId, reqParam, optParam, assignedReqId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (auto res = generic_match2_error_check(nph, ctxId, reqParam); res != CELL_OK)
{
return res;
}
return CELL_OK;
}
error_code sceNpMatching2GetRoomMemberDataExternalList(SceNpMatching2ContextId ctxId, vm::cptr<SceNpMatching2GetRoomMemberDataExternalListRequest> reqParam,
vm::cptr<SceNpMatching2RequestOptParam> optParam, vm::ptr<SceNpMatching2RequestId> assignedReqId)
{
sceNp2.todo("sceNpMatching2GetRoomMemberDataExternalList(ctxId=%d, reqParam=*0x%x, optParam=*0x%x, assignedReqId=*0x%x)", ctxId, reqParam, optParam, assignedReqId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (auto res = generic_match2_error_check(nph, ctxId, reqParam); res != CELL_OK)
{
return res;
}
return CELL_OK;
}
error_code sceNpMatching2AbortRequest(SceNpMatching2ContextId ctxId, SceNpMatching2RequestId reqId)
{
sceNp2.warning("sceNpMatching2AbortRequest(ctxId=%d, reqId=%d)", ctxId, reqId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP2_Match2_init)
{
return SCE_NP_MATCHING2_ERROR_NOT_INITIALIZED;
}
if (!ctxId)
{
return SCE_NP_MATCHING2_ERROR_INVALID_CONTEXT_ID;
}
if (!check_match2_context(ctxId))
{
return SCE_NP_MATCHING2_ERROR_CONTEXT_NOT_FOUND;
}
if (!nph.abort_request(reqId))
return SCE_NP_MATCHING2_ERROR_REQUEST_NOT_FOUND;
return CELL_OK;
}
error_code sceNpMatching2GetServerInfo(
SceNpMatching2ContextId ctxId, vm::cptr<SceNpMatching2GetServerInfoRequest> reqParam, vm::cptr<SceNpMatching2RequestOptParam> optParam, vm::ptr<SceNpMatching2RequestId> assignedReqId)
{
sceNp2.warning("sceNpMatching2GetServerInfo(ctxId=%d, reqParam=*0x%x, optParam=*0x%x, assignedReqId=*0x%x)", ctxId, reqParam, optParam, assignedReqId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (auto res = generic_match2_error_check(nph, ctxId, reqParam); res != CELL_OK)
{
return res;
}
const u32 request_id = nph.get_server_status(ctxId, optParam, reqParam->serverId);
if (assignedReqId)
{
*assignedReqId = request_id;
}
return CELL_OK;
}
error_code sceNpMatching2GetEventData(SceNpMatching2ContextId ctxId, SceNpMatching2EventKey eventKey, vm::ptr<void> buf, u32 bufLen)
{
sceNp2.notice("sceNpMatching2GetEventData(ctxId=%d, eventKey=%d, buf=*0x%x, bufLen=%d)", ctxId, eventKey, buf, bufLen);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP2_Match2_init)
{
return SCE_NP_MATCHING2_ERROR_NOT_INITIALIZED;
}
if (!buf)
{
return SCE_NP_MATCHING2_ERROR_INVALID_ARGUMENT;
}
return not_an_error(nph.get_match2_event(eventKey, buf.addr(), bufLen));
}
error_code sceNpMatching2GetRoomSlotInfoLocal(SceNpMatching2ContextId ctxId, const SceNpMatching2RoomId roomId, vm::ptr<SceNpMatching2RoomSlotInfo> roomSlotInfo)
{
sceNp2.notice("sceNpMatching2GetRoomSlotInfoLocal(ctxId=%d, roomId=%d, roomSlotInfo=*0x%x)", ctxId, roomId, roomSlotInfo);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP2_Match2_init)
{
return SCE_NP_MATCHING2_ERROR_NOT_INITIALIZED;
}
if (!roomSlotInfo)
{
return SCE_NP_MATCHING2_ERROR_INVALID_ARGUMENT;
}
if (!ctxId)
{
return SCE_NP_MATCHING2_ERROR_INVALID_CONTEXT_ID;
}
if (!roomId)
{
return SCE_NP_MATCHING2_ERROR_INVALID_ROOM_ID;
}
if (!check_match2_context(ctxId))
{
return SCE_NP_MATCHING2_ERROR_CONTEXT_NOT_FOUND;
}
const auto [error, slots] = nph.local_get_room_slots(roomId);
if (error)
{
return error;
}
memcpy(roomSlotInfo.get_ptr(), &slots.value(), sizeof(SceNpMatching2RoomSlotInfo));
return CELL_OK;
}
error_code sceNpMatching2SendLobbyChatMessage(
SceNpMatching2ContextId ctxId, vm::cptr<SceNpMatching2SendLobbyChatMessageRequest> reqParam, vm::cptr<SceNpMatching2RequestOptParam> optParam, vm::ptr<SceNpMatching2RequestId> assignedReqId)
{
sceNp2.todo("sceNpMatching2SendLobbyChatMessage(ctxId=%d, reqParam=*0x%x, optParam=*0x%x, assignedReqId=*0x%x)", ctxId, reqParam, optParam, assignedReqId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (auto res = generic_match2_error_check(nph, ctxId, reqParam); res != CELL_OK)
{
return res;
}
return CELL_OK;
}
error_code sceNpMatching2AbortContextStart(SceNpMatching2ContextId ctxId)
{
sceNp2.todo("sceNpMatching2AbortContextStart(ctxId=%d)", ctxId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP2_Match2_init)
{
return SCE_NP_MATCHING2_ERROR_NOT_INITIALIZED;
}
return CELL_OK;
}
error_code sceNpMatching2GetRoomMemberIdListLocal(SceNpMatching2ContextId ctxId, SceNpMatching2RoomId roomId, s32 sortMethod, vm::ptr<SceNpMatching2RoomMemberId> memberId, u32 memberIdNum)
{
sceNp2.notice("sceNpMatching2GetRoomMemberIdListLocal(ctxId=%d, roomId=%d, sortMethod=%d, memberId=*0x%x, memberIdNum=%d)", ctxId, roomId, sortMethod, memberId, memberIdNum);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP2_Match2_init)
{
return SCE_NP_MATCHING2_ERROR_NOT_INITIALIZED;
}
if (!ctxId)
{
return SCE_NP_MATCHING2_ERROR_INVALID_CONTEXT_ID;
}
if (!roomId)
{
return SCE_NP_MATCHING2_ERROR_INVALID_ROOM_ID;
}
if (sortMethod != SCE_NP_MATCHING2_SORT_METHOD_JOIN_DATE && sortMethod != SCE_NP_MATCHING2_SORT_METHOD_SLOT_NUMBER)
{
return SCE_NP_MATCHING2_ERROR_INVALID_SORT_METHOD;
}
if (!check_match2_context(ctxId))
{
return SCE_NP_MATCHING2_ERROR_CONTEXT_NOT_FOUND;
}
const auto [error, vec_memberids] = nph.local_get_room_memberids(roomId, sortMethod);
if (error)
{
return error;
}
u32 num_members = std::min(memberIdNum, static_cast<u32>(vec_memberids.size()));
if (memberId)
{
for (u32 i = 0; i < num_members; i++)
{
memberId[i] = vec_memberids[i];
}
}
return not_an_error(num_members);
}
error_code sceNpMatching2JoinRoom(
SceNpMatching2ContextId ctxId, vm::cptr<SceNpMatching2JoinRoomRequest> reqParam, vm::cptr<SceNpMatching2RequestOptParam> optParam, vm::ptr<SceNpMatching2RequestId> assignedReqId)
{
sceNp2.warning("sceNpMatching2JoinRoom(ctxId=%d, reqParam=*0x%x, optParam=*0x%x, assignedReqId=*0x%x)", ctxId, reqParam, optParam, assignedReqId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (auto res = generic_match2_error_check(nph, ctxId, reqParam); res != CELL_OK)
{
return res;
}
const u32 request_id = nph.join_room(ctxId, optParam, reqParam.get_ptr());
if (assignedReqId)
{
*assignedReqId = request_id;
}
return CELL_OK;
}
error_code sceNpMatching2GetRoomMemberDataInternalLocal(SceNpMatching2ContextId ctxId, SceNpMatching2RoomId roomId, SceNpMatching2RoomMemberId memberId, vm::cptr<SceNpMatching2AttributeId> attrId,
u32 attrIdNum, vm::ptr<SceNpMatching2RoomMemberDataInternal> member, vm::ptr<char> buf, u32 bufLen)
{
sceNp2.warning("sceNpMatching2GetRoomMemberDataInternalLocal(ctxId=%d, roomId=%d, memberId=%d, attrId=*0x%x, attrIdNum=%d, member=*0x%x, buf=*0x%x, bufLen=%d)", ctxId, roomId, memberId, attrId,
attrIdNum, member, buf, bufLen);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP2_Match2_init)
{
return SCE_NP_MATCHING2_ERROR_NOT_INITIALIZED;
}
if (!ctxId)
{
return SCE_NP_MATCHING2_ERROR_INVALID_CONTEXT_ID;
}
if (!roomId)
{
return SCE_NP_MATCHING2_ERROR_INVALID_ROOM_ID;
}
if (!memberId)
{
return SCE_NP_MATCHING2_ERROR_INVALID_MEMBER_ID;
}
std::vector<SceNpMatching2AttributeId> binattrs_list;
for (u32 i = 0; i < attrIdNum; i++)
{
if (!attrId || attrId[i] < SCE_NP_MATCHING2_ROOMMEMBER_BIN_ATTR_INTERNAL_1_ID || attrId[i] >= SCE_NP_MATCHING2_USER_BIN_ATTR_1_ID)
{
return SCE_NP_MATCHING2_ERROR_INVALID_ATTRIBUTE_ID;
}
binattrs_list.push_back(attrId[i]);
}
if (!check_match2_context(ctxId))
{
return SCE_NP_MATCHING2_ERROR_CONTEXT_NOT_FOUND;
}
return nph.local_get_room_member_data(roomId, memberId, binattrs_list, member ? member.get_ptr() : nullptr, buf.addr(), bufLen, ctxId);
}
error_code sceNpMatching2GetCbQueueInfo(SceNpMatching2ContextId ctxId, vm::ptr<SceNpMatching2CbQueueInfo> queueInfo)
{
sceNp2.todo("sceNpMatching2GetCbQueueInfo(ctxId=%d, queueInfo=*0x%x)", ctxId, queueInfo);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP2_Match2_init)
{
return SCE_NP_MATCHING2_ERROR_NOT_INITIALIZED;
}
return CELL_OK;
}
error_code sceNpMatching2KickoutRoomMember(
SceNpMatching2ContextId ctxId, vm::cptr<SceNpMatching2KickoutRoomMemberRequest> reqParam, vm::cptr<SceNpMatching2RequestOptParam> optParam, vm::ptr<SceNpMatching2RequestId> assignedReqId)
{
sceNp2.todo("sceNpMatching2KickoutRoomMember(ctxId=%d, reqParam=*0x%x, optParam=*0x%x, assignedReqId=*0x%x)", ctxId, reqParam, optParam, assignedReqId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (auto res = generic_match2_error_check(nph, ctxId, reqParam); res != CELL_OK)
{
return res;
}
return CELL_OK;
}
error_code sceNpMatching2ContextStartAsync(SceNpMatching2ContextId ctxId, u32 timeout)
{
sceNp2.warning("sceNpMatching2ContextStartAsync(ctxId=%d, timeout=%d)", ctxId, timeout);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP2_Match2_init)
{
return SCE_NP_MATCHING2_ERROR_NOT_INITIALIZED;
}
if (!ctxId)
{
return SCE_NP_MATCHING2_ERROR_INVALID_CONTEXT_ID;
}
const auto ctx = get_match2_context(ctxId);
if (!ctx)
return SCE_NP_MATCHING2_ERROR_CONTEXT_NOT_FOUND;
if (!ctx->started.compare_and_swap_test(0, 1))
return SCE_NP_MATCHING2_ERROR_CONTEXT_ALREADY_STARTED;
if (ctx->context_callback)
{
sysutil_register_cb([=, context_callback = ctx->context_callback, context_callback_param = ctx->context_callback_param](ppu_thread& cb_ppu) -> s32
{
context_callback(cb_ppu, ctxId, SCE_NP_MATCHING2_CONTEXT_EVENT_Start, SCE_NP_MATCHING2_EVENT_CAUSE_CONTEXT_ACTION, 0, ctx->context_callback_param);
return 0;
});
}
return CELL_OK;
}
error_code sceNpMatching2SetSignalingOptParam(
SceNpMatching2ContextId ctxId, vm::cptr<SceNpMatching2SetSignalingOptParamRequest> reqParam, vm::cptr<SceNpMatching2RequestOptParam> optParam, vm::ptr<SceNpMatching2RequestId> assignedReqId)
{
sceNp2.todo("sceNpMatching2SetSignalingOptParam(ctxId=%d, reqParam=*0x%x, optParam=*0x%x, assignedReqId=*0x%x)", ctxId, reqParam, optParam, assignedReqId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (auto res = generic_match2_error_check(nph, ctxId, reqParam); res != CELL_OK)
{
return res;
}
return CELL_OK;
}
error_code sceNpMatching2RegisterContextCallback(SceNpMatching2ContextId ctxId, vm::ptr<SceNpMatching2ContextCallback> cbFunc, vm::ptr<void> cbFuncArg)
{
sceNp2.warning("sceNpMatching2RegisterContextCallback(ctxId=%d, cbFunc=*0x%x, cbFuncArg=*0x%x)", ctxId, cbFunc, cbFuncArg);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP2_Match2_init)
{
return SCE_NP_MATCHING2_ERROR_NOT_INITIALIZED;
}
if (!ctxId)
{
return SCE_NP_MATCHING2_ERROR_INVALID_CONTEXT_ID;
}
const auto ctx = get_match2_context(ctxId);
if (!ctx)
return SCE_NP_MATCHING2_ERROR_CONTEXT_NOT_FOUND;
ctx->context_callback = cbFunc;
ctx->context_callback_param = cbFuncArg;
return CELL_OK;
}
error_code sceNpMatching2SendRoomChatMessage(
SceNpMatching2ContextId ctxId, vm::cptr<SceNpMatching2SendRoomChatMessageRequest> reqParam, vm::cptr<SceNpMatching2RequestOptParam> optParam, vm::ptr<SceNpMatching2RequestId> assignedReqId)
{
sceNp2.todo("sceNpMatching2SendRoomChatMessage(ctxId=%d, reqParam=*0x%x, optParam=*0x%x, assignedReqId=*0x%x)", ctxId, reqParam, optParam, assignedReqId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (auto res = generic_match2_error_check(nph, ctxId, reqParam); res != CELL_OK)
{
return res;
}
return CELL_OK;
}
error_code sceNpMatching2SetRoomDataInternal(
SceNpMatching2ContextId ctxId, vm::cptr<SceNpMatching2SetRoomDataInternalRequest> reqParam, vm::cptr<SceNpMatching2RequestOptParam> optParam, vm::ptr<SceNpMatching2RequestId> assignedReqId)
{
sceNp2.warning("sceNpMatching2SetRoomDataInternal(ctxId=%d, reqParam=*0x%x, optParam=*0x%x, assignedReqId=*0x%x)", ctxId, reqParam, optParam, assignedReqId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (auto res = generic_match2_error_check(nph, ctxId, reqParam); res != CELL_OK)
{
return res;
}
const u32 request_id = nph.set_roomdata_internal(ctxId, optParam, reqParam.get_ptr());
if (assignedReqId)
{
*assignedReqId = request_id;
}
return CELL_OK;
}
error_code sceNpMatching2GetRoomDataInternal(
SceNpMatching2ContextId ctxId, vm::cptr<SceNpMatching2GetRoomDataInternalRequest> reqParam, vm::cptr<SceNpMatching2RequestOptParam> optParam, vm::ptr<SceNpMatching2RequestId> assignedReqId)
{
sceNp2.warning("sceNpMatching2GetRoomDataInternal(ctxId=%d, reqParam=*0x%x, optParam=*0x%x, assignedReqId=*0x%x)", ctxId, reqParam, optParam, assignedReqId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (auto res = generic_match2_error_check(nph, ctxId, reqParam); res != CELL_OK)
{
return res;
}
const u32 request_id = nph.get_roomdata_internal(ctxId, optParam, reqParam.get_ptr());
if (assignedReqId)
{
*assignedReqId = request_id;
}
return CELL_OK;
}
error_code sceNpMatching2SignalingGetPingInfo(
SceNpMatching2ContextId ctxId, vm::cptr<SceNpMatching2SignalingGetPingInfoRequest> reqParam, vm::cptr<SceNpMatching2RequestOptParam> optParam, vm::ptr<SceNpMatching2RequestId> assignedReqId)
{
sceNp2.warning("sceNpMatching2SignalingGetPingInfo(ctxId=%d, reqParam=*0x%x, optParam=*0x%x, assignedReqId=*0x%x)", ctxId, reqParam, optParam, assignedReqId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (auto res = generic_match2_error_check(nph, ctxId, reqParam); res != CELL_OK)
{
return res;
}
const u32 request_id = nph.get_ping_info(ctxId, optParam, reqParam.get_ptr());
if (assignedReqId)
{
*assignedReqId = request_id;
}
return CELL_OK;
}
error_code sceNpMatching2GetServerIdListLocal(SceNpMatching2ContextId ctxId, vm::ptr<SceNpMatching2ServerId> serverId, u32 serverIdNum)
{
sceNp2.notice("sceNpMatching2GetServerIdListLocal(ctxId=%d, serverId=*0x%x, serverIdNum=%d)", ctxId, serverId, serverIdNum);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP2_Match2_init)
{
return SCE_NP_MATCHING2_ERROR_NOT_INITIALIZED;
}
if (!check_match2_context(ctxId))
{
return SCE_NP_MATCHING2_ERROR_CONTEXT_NOT_FOUND;
}
const auto slist = nph.get_match2_server_list(ctxId);
u32 num_servs = std::min(static_cast<u32>(slist.size()), serverIdNum);
if (serverId)
{
for (u32 i = 0; i < num_servs; i++)
{
serverId[i] = slist[i];
}
}
return not_an_error(static_cast<s32>(slist.size()));
}
error_code sceNpUtilBuildCdnUrl(vm::cptr<char> url, vm::ptr<char> buf, u32 bufSize, vm::ptr<u32> required, vm::ptr<void> option)
{
sceNp2.todo("sceNpUtilBuildCdnUrl(url=%s, buf=*0x%x, bufSize=%d, required=*0x%x, option=*0x%x)", url, buf, bufSize, required, option);
if (!url || option) // option check at least until fw 4.71
{
// TODO: check url for '?'
return SCE_NP_UTIL_ERROR_INVALID_ARGUMENT;
}
//if (offline)
//{
// return SCE_NP_ERROR_OFFLINE;
//}
return CELL_OK;
}
error_code sceNpMatching2GrantRoomOwner(
SceNpMatching2ContextId ctxId, vm::cptr<SceNpMatching2GrantRoomOwnerRequest> reqParam, vm::cptr<SceNpMatching2RequestOptParam> optParam, vm::ptr<SceNpMatching2RequestId> assignedReqId)
{
sceNp2.todo("sceNpMatching2GrantRoomOwner(ctxId=%d, reqParam=*0x%x, optParam=*0x%x, assignedReqId=*0x%x)", ctxId, reqParam, optParam, assignedReqId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (auto res = generic_match2_error_check(nph, ctxId, reqParam); res != CELL_OK)
{
return res;
}
return CELL_OK;
}
error_code sceNpMatching2CreateContext(
vm::cptr<SceNpId> npId, vm::cptr<SceNpCommunicationId> commId, vm::cptr<SceNpCommunicationPassphrase> passPhrase, vm::ptr<SceNpMatching2ContextId> ctxId, s32 option)
{
sceNp2.warning("sceNpMatching2CreateContext(npId=*0x%x, commId=*0x%x(%s), passPhrase=*0x%x, ctxId=*0x%x, option=%d)", npId, commId, commId ? commId->data : "", passPhrase, ctxId, option);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP2_Match2_init)
{
return SCE_NP_MATCHING2_ERROR_NOT_INITIALIZED;
}
if (!npId || !commId || !passPhrase || !ctxId)
{
return SCE_NP_MATCHING2_ERROR_INVALID_ARGUMENT;
}
if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE)
{
return SCE_NP_MATCHING2_ERROR_NOT_NP_SIGN_IN;
}
*ctxId = create_match2_context(commId, passPhrase, option);
return CELL_OK;
}
error_code sceNpMatching2GetSignalingOptParamLocal(SceNpMatching2ContextId ctxId, SceNpMatching2RoomId roomId, vm::ptr<SceNpMatching2SignalingOptParam> signalingOptParam)
{
sceNp2.todo("sceNpMatching2GetSignalingOptParamLocal(ctxId=%d, roomId=%d, signalingOptParam=*0x%x)", ctxId, roomId, signalingOptParam);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP2_Match2_init)
{
return SCE_NP_MATCHING2_ERROR_NOT_INITIALIZED;
}
return CELL_OK;
}
error_code sceNpMatching2RegisterSignalingCallback(SceNpMatching2ContextId ctxId, vm::ptr<SceNpMatching2SignalingCallback> cbFunc, vm::ptr<void> cbFuncArg)
{
sceNp2.notice("sceNpMatching2RegisterSignalingCallback(ctxId=%d, cbFunc=*0x%x, cbFuncArg=*0x%x)", ctxId, cbFunc, cbFuncArg);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP2_Match2_init)
{
return SCE_NP_MATCHING2_ERROR_NOT_INITIALIZED;
}
auto ctx = get_match2_context(ctxId);
if (!ctx)
{
return SCE_NP_MATCHING2_ERROR_CONTEXT_NOT_FOUND;
}
std::lock_guard lock(ctx->mutex);
ctx->signaling_cb = cbFunc;
ctx->signaling_cb_arg = cbFuncArg;
auto& sigh = g_fxo->get<named_thread<signaling_handler>>();
sigh.add_match2_ctx(ctxId);
return CELL_OK;
}
error_code sceNpMatching2ClearEventData(SceNpMatching2ContextId ctxId, SceNpMatching2EventKey eventKey)
{
sceNp2.todo("sceNpMatching2ClearEventData(ctxId=%d, eventKey=%d)", ctxId, eventKey);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP2_Match2_init)
{
return SCE_NP_MATCHING2_ERROR_NOT_INITIALIZED;
}
return CELL_OK;
}
error_code sceNpMatching2GetUserInfoList(
SceNpMatching2ContextId ctxId, vm::cptr<SceNpMatching2GetUserInfoListRequest> reqParam, vm::cptr<SceNpMatching2RequestOptParam> optParam, vm::ptr<SceNpMatching2RequestId> assignedReqId)
{
sceNp2.todo("sceNpMatching2GetUserInfoList(ctxId=%d, reqParam=*0x%x, optParam=*0x%x, assignedReqId=*0x%x)", ctxId, reqParam, optParam, assignedReqId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (auto res = generic_match2_error_check(nph, ctxId, reqParam); res != CELL_OK)
{
return res;
}
return CELL_OK;
}
error_code sceNpMatching2GetRoomMemberDataInternal(
SceNpMatching2ContextId ctxId, vm::cptr<SceNpMatching2GetRoomMemberDataInternalRequest> reqParam, vm::cptr<SceNpMatching2RequestOptParam> optParam, vm::ptr<SceNpMatching2RequestId> assignedReqId)
{
sceNp2.warning("sceNpMatching2GetRoomMemberDataInternal(ctxId=%d, reqParam=*0x%x, optParam=*0x%x, assignedReqId=*0x%x)", ctxId, reqParam, optParam, assignedReqId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (auto res = generic_match2_error_check(nph, ctxId, reqParam); res != CELL_OK)
{
return res;
}
const u32 request_id = nph.get_roommemberdata_internal(ctxId, optParam, reqParam.get_ptr());
if (assignedReqId)
{
*assignedReqId = request_id;
}
return CELL_OK;
}
error_code sceNpMatching2SetRoomMemberDataInternal(
SceNpMatching2ContextId ctxId, vm::cptr<SceNpMatching2SetRoomMemberDataInternalRequest> reqParam, vm::cptr<SceNpMatching2RequestOptParam> optParam, vm::ptr<SceNpMatching2RequestId> assignedReqId)
{
sceNp2.warning("sceNpMatching2SetRoomMemberDataInternal(ctxId=%d, reqParam=*0x%x, optParam=*0x%x, assignedReqId=*0x%x)", ctxId, reqParam, optParam, assignedReqId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (auto res = generic_match2_error_check(nph, ctxId, reqParam); res != CELL_OK)
{
return res;
}
const u32 request_id = nph.set_roommemberdata_internal(ctxId, optParam, reqParam.get_ptr());
if (assignedReqId)
{
*assignedReqId = request_id;
}
return CELL_OK;
}
error_code sceNpMatching2JoinProhibitiveRoom(
SceNpMatching2ContextId ctxId, vm::cptr<SceNpMatching2JoinProhibitiveRoomRequest> reqParam, vm::cptr<SceNpMatching2RequestOptParam> optParam, vm::ptr<SceNpMatching2RequestId> assignedReqId)
{
sceNp2.warning("sceNpMatching2JoinProhibitiveRoom(ctxId=%d, reqParam=*0x%x, optParam=*0x%x, assignedReqId=*0x%x)", ctxId, reqParam, optParam, assignedReqId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (auto res = generic_match2_error_check(nph, ctxId, reqParam); res != CELL_OK)
{
return res;
}
// TODO: add blocked users
const u32 request_id = nph.join_room(ctxId, optParam, &reqParam->joinParam);
if (assignedReqId)
{
*assignedReqId = request_id;
}
return CELL_OK;
}
error_code sceNpMatching2SignalingSetCtxOpt(SceNpMatching2ContextId ctxId, s32 optname, s32 optval)
{
sceNp2.todo("sceNpMatching2SignalingSetCtxOpt(ctxId=%d, optname=%d, optval=%d)", ctxId, optname, optval);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP2_Match2_init)
{
return SCE_NP_MATCHING2_ERROR_NOT_INITIALIZED;
}
return CELL_OK;
}
error_code sceNpMatching2DeleteServerContext(
SceNpMatching2ContextId ctxId, vm::cptr<SceNpMatching2DeleteServerContextRequest> reqParam, vm::cptr<SceNpMatching2RequestOptParam> optParam, vm::ptr<SceNpMatching2RequestId> assignedReqId)
{
sceNp2.warning("sceNpMatching2DeleteServerContext(ctxId=%d, reqParam=*0x%x, optParam=*0x%x, assignedReqId=*0x%x)", ctxId, reqParam, optParam, assignedReqId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (auto res = generic_match2_error_check(nph, ctxId, reqParam); res != CELL_OK)
{
return res;
}
if (reqParam->serverId == 0)
{
return SCE_NP_MATCHING2_ERROR_INVALID_SERVER_ID;
}
const u32 request_id = nph.delete_server_context(ctxId, optParam, reqParam->serverId);
if (assignedReqId)
{
*assignedReqId = request_id;
}
return CELL_OK;
}
error_code sceNpMatching2SetDefaultRequestOptParam(SceNpMatching2ContextId ctxId, vm::cptr<SceNpMatching2RequestOptParam> optParam)
{
sceNp2.warning("sceNpMatching2SetDefaultRequestOptParam(ctxId=%d, optParam=*0x%x)", ctxId, optParam);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP2_Match2_init)
{
return SCE_NP_MATCHING2_ERROR_NOT_INITIALIZED;
}
if (!optParam)
{
return SCE_NP_MATCHING2_ERROR_INVALID_ARGUMENT;
}
const auto ctx = get_match2_context(ctxId);
if (!ctx)
return SCE_NP_MATCHING2_ERROR_INVALID_CONTEXT_ID;
memcpy(&ctx->default_match2_optparam, optParam.get_ptr(), sizeof(SceNpMatching2RequestOptParam));
return CELL_OK;
}
error_code sceNpMatching2RegisterRoomEventCallback(SceNpMatching2ContextId ctxId, vm::ptr<SceNpMatching2RoomEventCallback> cbFunc, vm::ptr<void> cbFuncArg)
{
sceNp2.warning("sceNpMatching2RegisterRoomEventCallback(ctxId=%d, cbFunc=*0x%x, cbFuncArg=*0x%x)", ctxId, cbFunc, cbFuncArg);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP2_Match2_init)
{
return SCE_NP_MATCHING2_ERROR_NOT_INITIALIZED;
}
nph.room_event_cb = cbFunc;
nph.room_event_cb_ctx = ctxId;
nph.room_event_cb_arg = cbFuncArg;
return CELL_OK;
}
error_code sceNpMatching2GetRoomPasswordLocal(SceNpMatching2ContextId ctxId, SceNpMatching2RoomId roomId, vm::ptr<b8> withPassword, vm::ptr<SceNpMatching2SessionPassword> roomPassword)
{
sceNp2.notice("sceNpMatching2GetRoomPasswordLocal(ctxId=%d, roomId=%d, withPassword=*0x%x, roomPassword=*0x%x)", ctxId, roomId, withPassword, roomPassword);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP2_Match2_init)
{
return SCE_NP_MATCHING2_ERROR_NOT_INITIALIZED;
}
if (!ctxId)
{
return SCE_NP_MATCHING2_ERROR_INVALID_CONTEXT_ID;
}
if (!roomId)
{
return SCE_NP_MATCHING2_ERROR_INVALID_ROOM_ID;
}
if (!check_match2_context(ctxId))
{
return SCE_NP_MATCHING2_ERROR_CONTEXT_NOT_FOUND;
}
const auto [error, password] = nph.local_get_room_password(roomId);
if (error)
{
return error;
}
if (password)
{
if (withPassword) *withPassword = true;
if (roomPassword)
{
std::memcpy(roomPassword.get_ptr(), &*password, sizeof(SceNpMatching2SessionPassword));
}
}
else
{
if (withPassword) *withPassword = false;
}
return CELL_OK;
}
error_code sceNpMatching2GetRoomDataExternalList(
SceNpMatching2ContextId ctxId, vm::cptr<SceNpMatching2GetRoomDataExternalListRequest> reqParam, vm::cptr<SceNpMatching2RequestOptParam> optParam, vm::ptr<SceNpMatching2RequestId> assignedReqId)
{
sceNp2.warning("sceNpMatching2GetRoomDataExternalList(ctxId=%d, reqParam=*0x%x, optParam=*0x%x, assignedReqId=*0x%x)", ctxId, reqParam, optParam, assignedReqId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (auto res = generic_match2_error_check(nph, ctxId, reqParam); res != CELL_OK)
{
return res;
}
const u32 request_id = nph.get_roomdata_external_list(ctxId, optParam, reqParam.get_ptr());
if (assignedReqId)
{
*assignedReqId = request_id;
}
return CELL_OK;
}
error_code sceNpMatching2CreateJoinRoom(
SceNpMatching2ContextId ctxId, vm::cptr<SceNpMatching2CreateJoinRoomRequest> reqParam, vm::cptr<SceNpMatching2RequestOptParam> optParam, vm::ptr<SceNpMatching2RequestId> assignedReqId)
{
sceNp2.warning("sceNpMatching2CreateJoinRoom(ctxId=%d, reqParam=*0x%x, optParam=*0x%x, assignedReqId=*0x%x)", ctxId, reqParam, optParam, assignedReqId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (auto res = generic_match2_error_check(nph, ctxId, reqParam); res != CELL_OK)
{
return res;
}
const u32 request_id = nph.create_join_room(ctxId, optParam, reqParam.get_ptr());
if (assignedReqId)
{
*assignedReqId = request_id;
}
return CELL_OK;
}
error_code sceNpMatching2SignalingGetCtxOpt(SceNpMatching2ContextId ctxId, s32 optname, vm::ptr<s32> optval)
{
sceNp2.todo("sceNpMatching2SignalingGetCtxOpt(ctxId=%d, optname=%d, optval=*0x%x)", ctxId, optname, optval);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP2_Match2_init)
{
return SCE_NP_MATCHING2_ERROR_NOT_INITIALIZED;
}
return CELL_OK;
}
error_code sceNpMatching2GetLobbyInfoList(
SceNpMatching2ContextId ctxId, vm::cptr<SceNpMatching2GetLobbyInfoListRequest> reqParam, vm::cptr<SceNpMatching2RequestOptParam> optParam, vm::ptr<SceNpMatching2RequestId> assignedReqId)
{
sceNp2.todo("sceNpMatching2GetLobbyInfoList(ctxId=%d, reqParam=*0x%x, optParam=*0x%x, assignedReqId=*0x%x)", ctxId, reqParam, optParam, assignedReqId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (auto res = generic_match2_error_check(nph, ctxId, reqParam); res != CELL_OK)
{
return res;
}
const u32 request_id = nph.get_lobby_info_list(ctxId, optParam, reqParam.get_ptr());
if (assignedReqId)
{
*assignedReqId = request_id;
}
return CELL_OK;
}
error_code sceNpMatching2GetLobbyMemberIdListLocal(
SceNpMatching2ContextId ctxId, SceNpMatching2LobbyId lobbyId, vm::ptr<SceNpMatching2LobbyMemberId> memberId, u32 memberIdNum, vm::ptr<SceNpMatching2LobbyMemberId> me)
{
sceNp2.todo("sceNpMatching2GetLobbyMemberIdListLocal(ctxId=%d, lobbyId=%d, memberId=*0x%x, memberIdNum=%d, me=*0x%x)", ctxId, lobbyId, memberId, memberIdNum, me);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP2_Match2_init)
{
return SCE_NP_MATCHING2_ERROR_NOT_INITIALIZED;
}
return CELL_OK;
}
error_code sceNpMatching2SendLobbyInvitation(
SceNpMatching2ContextId ctxId, vm::cptr<SceNpMatching2SendLobbyInvitationRequest> reqParam, vm::cptr<SceNpMatching2RequestOptParam> optParam, vm::ptr<SceNpMatching2RequestId> assignedReqId)
{
sceNp2.todo("sceNpMatching2SendLobbyInvitation(ctxId=%d, reqParam=*0x%x, optParam=*0x%x, assignedReqId=*0x%x)", ctxId, reqParam, optParam, assignedReqId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (auto res = generic_match2_error_check(nph, ctxId, reqParam); res != CELL_OK)
{
return res;
}
return CELL_OK;
}
error_code sceNpMatching2ContextStop(SceNpMatching2ContextId ctxId)
{
sceNp2.warning("sceNpMatching2ContextStop(ctxId=%d)", ctxId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP2_Match2_init)
{
return SCE_NP_MATCHING2_ERROR_NOT_INITIALIZED;
}
const auto ctx = get_match2_context(ctxId);
if (!ctx)
return SCE_NP_MATCHING2_ERROR_INVALID_CONTEXT_ID;
if (!ctx->started.compare_and_swap_test(1, 0))
return SCE_NP_MATCHING2_ERROR_CONTEXT_NOT_STARTED;
if (ctx->context_callback)
{
sysutil_register_cb([=, context_callback = ctx->context_callback, context_callback_param = ctx->context_callback_param](ppu_thread& cb_ppu) -> s32
{
context_callback(cb_ppu, ctxId, SCE_NP_MATCHING2_CONTEXT_EVENT_Stop, SCE_NP_MATCHING2_EVENT_CAUSE_CONTEXT_ACTION, 0, context_callback_param);
return 0;
});
}
return CELL_OK;
}
error_code sceNpMatching2SetLobbyMemberDataInternal(
SceNpMatching2ContextId ctxId, vm::cptr<SceNpMatching2SetLobbyMemberDataInternalRequest> reqParam, vm::cptr<SceNpMatching2RequestOptParam> optParam, vm::ptr<SceNpMatching2RequestId> assignedReqId)
{
sceNp2.todo("sceNpMatching2SetLobbyMemberDataInternal(ctxId=%d, reqParam=*0x%x, optParam=*0x%x, assignedReqId=*0x%x)", ctxId, reqParam, optParam, assignedReqId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (auto res = generic_match2_error_check(nph, ctxId, reqParam); res != CELL_OK)
{
return res;
}
return CELL_OK;
}
error_code sceNpMatching2RegisterRoomMessageCallback(SceNpMatching2ContextId ctxId, vm::ptr<SceNpMatching2RoomMessageCallback> cbFunc, vm::ptr<void> cbFuncArg)
{
sceNp2.warning("sceNpMatching2RegisterRoomMessageCallback(ctxId=%d, cbFunc=*0x%x, cbFuncArg=*0x%x)", ctxId, cbFunc, cbFuncArg);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP2_Match2_init)
{
return SCE_NP_MATCHING2_ERROR_NOT_INITIALIZED;
}
nph.room_msg_cb = cbFunc;
nph.room_msg_cb_ctx = ctxId;
nph.room_msg_cb_arg = cbFuncArg;
return CELL_OK;
}
error_code sceNpMatching2SignalingCancelPeerNetInfo(SceNpMatching2ContextId ctxId, SceNpMatching2SignalingRequestId reqId)
{
sceNp2.todo("sceNpMatching2SignalingCancelPeerNetInfo(ctxId=%d, reqId=%d)", ctxId, reqId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP2_Match2_init)
{
return SCE_NP_MATCHING2_ERROR_NOT_INITIALIZED;
}
return CELL_OK;
}
error_code sceNpMatching2SignalingGetLocalNetInfo(vm::ptr<SceNpMatching2SignalingNetInfo> netinfo)
{
sceNp2.warning("sceNpMatching2SignalingGetLocalNetInfo(netinfo=*0x%x)", netinfo);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP2_Match2_init)
{
return SCE_NP_MATCHING2_ERROR_NOT_INITIALIZED;
}
if (!netinfo || netinfo->size != sizeof(SceNpMatching2SignalingNetInfo))
{
return SCE_NP_MATCHING2_ERROR_INVALID_ARGUMENT;
}
netinfo->localAddr = nph.get_local_ip_addr();
netinfo->mappedAddr = nph.get_public_ip_addr();
// Pure speculation below
netinfo->natStatus = SCE_NP_SIGNALING_NETINFO_NAT_STATUS_TYPE2;
return CELL_OK;
}
error_code sceNpMatching2SignalingGetPeerNetInfo(SceNpMatching2ContextId ctxId, SceNpMatching2RoomId roomId, SceNpMatching2RoomMemberId roomMemberId, vm::ptr<SceNpMatching2SignalingRequestId> reqId)
{
sceNp2.todo("sceNpMatching2SignalingGetPeerNetInfo(ctxId=%d, roomId=%d, roomMemberId=%d, reqId=*0x%x)", ctxId, roomId, roomMemberId, reqId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP2_Match2_init)
{
return SCE_NP_MATCHING2_ERROR_NOT_INITIALIZED;
}
if (!reqId)
{
return SCE_NP_MATCHING2_ERROR_INVALID_ARGUMENT;
}
return CELL_OK;
}
error_code sceNpMatching2SignalingGetPeerNetInfoResult(SceNpMatching2ContextId ctxId, SceNpMatching2SignalingRequestId reqId, vm::ptr<SceNpMatching2SignalingNetInfo> netinfo)
{
sceNp2.todo("sceNpMatching2SignalingGetPeerNetInfoResult(ctxId=%d, reqId=%d, netinfo=*0x%x)", ctxId, reqId, netinfo);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP2_Match2_init)
{
return SCE_NP_MATCHING2_ERROR_NOT_INITIALIZED;
}
if (!netinfo || netinfo->size != sizeof(SceNpMatching2SignalingNetInfo))
{
return SCE_NP_MATCHING2_ERROR_INVALID_ARGUMENT;
}
return CELL_OK;
}
error_code sceNpAuthOAuthInit()
{
sceNp2.todo("sceNpAuthOAuthInit()");
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (nph.is_NP_Auth_init)
{
return SCE_NP_OAUTH_ERROR_ALREADY_INITIALIZED;
}
nph.is_NP_Auth_init = true;
return CELL_OK;
}
error_code sceNpAuthOAuthTerm()
{
sceNp2.todo("sceNpAuthOAuthTerm()");
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
// TODO: check if this might throw SCE_NP_OAUTH_ERROR_NOT_INITIALIZED
nph.is_NP_Auth_init = false;
return CELL_OK;
}
error_code sceNpAuthCreateOAuthRequest()
{
sceNp2.todo("sceNpAuthCreateOAuthRequest()");
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Auth_init)
{
return SCE_NP_OAUTH_ERROR_NOT_INITIALIZED;
}
return CELL_OK;
}
error_code sceNpAuthDeleteOAuthRequest(SceNpAuthOAuthRequestId reqId)
{
sceNp2.todo("sceNpAuthDeleteOAuthRequest(reqId=%d)", reqId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Auth_init)
{
return SCE_NP_OAUTH_ERROR_NOT_INITIALIZED;
}
return CELL_OK;
}
error_code sceNpAuthAbortOAuthRequest(SceNpAuthOAuthRequestId reqId)
{
sceNp2.todo("sceNpAuthAbortOAuthRequest(reqId=%d)", reqId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Auth_init)
{
return SCE_NP_OAUTH_ERROR_NOT_INITIALIZED;
}
return CELL_OK;
}
error_code sceNpAuthGetAuthorizationCode(SceNpAuthOAuthRequestId reqId, vm::cptr<SceNpAuthGetAuthorizationCodeParameter> param, vm::ptr<SceNpAuthorizationCode> authCode, vm::ptr<s32> issuerId)
{
sceNp2.todo("sceNpAuthGetAuthorizationCode(reqId=%d, param=*0x%x, authCode=*0x%x, issuerId=%d)", reqId, param, authCode, issuerId);
auto& nph = g_fxo->get<named_thread<np::np_handler>>();
if (!nph.is_NP_Auth_init)
{
return SCE_NP_OAUTH_ERROR_NOT_INITIALIZED;
}
return CELL_OK;
}
error_code sceNpAuthGetAuthorizationCode2()
{
UNIMPLEMENTED_FUNC(sceNp2);
return CELL_OK;
}
DECLARE(ppu_module_manager::sceNp2)
("sceNp2", []() {
REG_FUNC(sceNp2, sceNpMatching2DestroyContext);
REG_FUNC(sceNp2, sceNpMatching2LeaveLobby);
REG_FUNC(sceNp2, sceNpMatching2RegisterLobbyMessageCallback);
REG_FUNC(sceNp2, sceNpMatching2GetWorldInfoList);
REG_FUNC(sceNp2, sceNpMatching2RegisterLobbyEventCallback);
REG_FUNC(sceNp2, sceNpMatching2GetLobbyMemberDataInternalList);
REG_FUNC(sceNp2, sceNpMatching2SearchRoom);
REG_FUNC(sceNp2, sceNpMatching2SignalingGetConnectionStatus);
REG_FUNC(sceNp2, sceNpMatching2SetUserInfo);
REG_FUNC(sceNp2, sceNpMatching2GetClanLobbyId);
REG_FUNC(sceNp2, sceNpMatching2GetLobbyMemberDataInternal);
REG_FUNC(sceNp2, sceNpMatching2ContextStart);
REG_FUNC(sceNp2, sceNpMatching2CreateServerContext);
REG_FUNC(sceNp2, sceNpMatching2GetMemoryInfo);
REG_FUNC(sceNp2, sceNpMatching2LeaveRoom);
REG_FUNC(sceNp2, sceNpMatching2SetRoomDataExternal);
REG_FUNC(sceNp2, sceNpMatching2Term2);
REG_FUNC(sceNp2, sceNpMatching2SignalingGetConnectionInfo);
REG_FUNC(sceNp2, sceNpMatching2SendRoomMessage);
REG_FUNC(sceNp2, sceNpMatching2JoinLobby);
REG_FUNC(sceNp2, sceNpMatching2GetRoomMemberDataExternalList);
REG_FUNC(sceNp2, sceNpMatching2AbortRequest);
REG_FUNC(sceNp2, sceNpMatching2Term);
REG_FUNC(sceNp2, sceNpMatching2GetServerInfo);
REG_FUNC(sceNp2, sceNpMatching2GetEventData);
REG_FUNC(sceNp2, sceNpMatching2GetRoomSlotInfoLocal);
REG_FUNC(sceNp2, sceNpMatching2SendLobbyChatMessage);
REG_FUNC(sceNp2, sceNpMatching2Init);
REG_FUNC(sceNp2, sceNp2Init);
REG_FUNC(sceNp2, sceNpMatching2AbortContextStart);
REG_FUNC(sceNp2, sceNpMatching2GetRoomMemberIdListLocal);
REG_FUNC(sceNp2, sceNpMatching2JoinRoom);
REG_FUNC(sceNp2, sceNpMatching2GetRoomMemberDataInternalLocal);
REG_FUNC(sceNp2, sceNpMatching2GetCbQueueInfo);
REG_FUNC(sceNp2, sceNpMatching2KickoutRoomMember);
REG_FUNC(sceNp2, sceNpMatching2ContextStartAsync);
REG_FUNC(sceNp2, sceNpMatching2SetSignalingOptParam);
REG_FUNC(sceNp2, sceNpMatching2RegisterContextCallback);
REG_FUNC(sceNp2, sceNpMatching2SendRoomChatMessage);
REG_FUNC(sceNp2, sceNpMatching2SetRoomDataInternal);
REG_FUNC(sceNp2, sceNpMatching2GetRoomDataInternal);
REG_FUNC(sceNp2, sceNpMatching2SignalingGetPingInfo);
REG_FUNC(sceNp2, sceNpMatching2GetServerIdListLocal);
REG_FUNC(sceNp2, sceNpUtilBuildCdnUrl);
REG_FUNC(sceNp2, sceNpMatching2GrantRoomOwner);
REG_FUNC(sceNp2, sceNpMatching2CreateContext);
REG_FUNC(sceNp2, sceNpMatching2GetSignalingOptParamLocal);
REG_FUNC(sceNp2, sceNpMatching2RegisterSignalingCallback);
REG_FUNC(sceNp2, sceNpMatching2ClearEventData);
REG_FUNC(sceNp2, sceNp2Term);
REG_FUNC(sceNp2, sceNpMatching2GetUserInfoList);
REG_FUNC(sceNp2, sceNpMatching2GetRoomMemberDataInternal);
REG_FUNC(sceNp2, sceNpMatching2SetRoomMemberDataInternal);
REG_FUNC(sceNp2, sceNpMatching2JoinProhibitiveRoom);
REG_FUNC(sceNp2, sceNpMatching2SignalingSetCtxOpt);
REG_FUNC(sceNp2, sceNpMatching2DeleteServerContext);
REG_FUNC(sceNp2, sceNpMatching2SetDefaultRequestOptParam);
REG_FUNC(sceNp2, sceNpMatching2RegisterRoomEventCallback);
REG_FUNC(sceNp2, sceNpMatching2GetRoomPasswordLocal);
REG_FUNC(sceNp2, sceNpMatching2GetRoomDataExternalList);
REG_FUNC(sceNp2, sceNpMatching2CreateJoinRoom);
REG_FUNC(sceNp2, sceNpMatching2SignalingGetCtxOpt);
REG_FUNC(sceNp2, sceNpMatching2GetLobbyInfoList);
REG_FUNC(sceNp2, sceNpMatching2GetLobbyMemberIdListLocal);
REG_FUNC(sceNp2, sceNpMatching2SendLobbyInvitation);
REG_FUNC(sceNp2, sceNpMatching2ContextStop);
REG_FUNC(sceNp2, sceNpMatching2Init2);
REG_FUNC(sceNp2, sceNpMatching2SetLobbyMemberDataInternal);
REG_FUNC(sceNp2, sceNpMatching2RegisterRoomMessageCallback);
REG_FUNC(sceNp2, sceNpMatching2SignalingCancelPeerNetInfo);
REG_FUNC(sceNp2, sceNpMatching2SignalingGetLocalNetInfo);
REG_FUNC(sceNp2, sceNpMatching2SignalingGetPeerNetInfo);
REG_FUNC(sceNp2, sceNpMatching2SignalingGetPeerNetInfoResult);
REG_FUNC(sceNp2, sceNpAuthOAuthInit);
REG_FUNC(sceNp2, sceNpAuthOAuthTerm);
REG_FUNC(sceNp2, sceNpAuthCreateOAuthRequest);
REG_FUNC(sceNp2, sceNpAuthDeleteOAuthRequest);
REG_FUNC(sceNp2, sceNpAuthAbortOAuthRequest);
REG_FUNC(sceNp2, sceNpAuthGetAuthorizationCode);
REG_FUNC(sceNp2, sceNpAuthGetAuthorizationCode2);
});
| 64,065
|
C++
|
.cpp
| 1,577
| 38.088776
| 203
| 0.768859
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| false
| false
|
5,303
|
cellGcmSys.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellGcmSys.cpp
|
#include "stdafx.h"
#include "Emu/IdManager.h"
#include "Emu/Cell/PPUModule.h"
#include "Emu/Memory/vm.h"
#include "Emu/Cell/lv2/sys_ppu_thread.h"
#include "Emu/Cell/lv2/sys_rsx.h"
#include "Emu/RSX/RSXThread.h"
#include "cellGcmSys.h"
#include "sysPrxForUser.h"
#include "util/asm.hpp"
LOG_CHANNEL(cellGcmSys);
template<>
void fmt_class_string<CellGcmError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_GCM_ERROR_FAILURE);
STR_CASE(CELL_GCM_ERROR_NO_IO_PAGE_TABLE);
STR_CASE(CELL_GCM_ERROR_INVALID_ENUM);
STR_CASE(CELL_GCM_ERROR_INVALID_VALUE);
STR_CASE(CELL_GCM_ERROR_INVALID_ALIGNMENT);
STR_CASE(CELL_GCM_ERROR_ADDRESS_OVERWRAP);
}
return unknown;
});
}
namespace rsx
{
u32 make_command(vm::bptr<u32>& dst, u32 start_register, std::initializer_list<any32> values)
{
*dst++ = start_register << 2 | static_cast<u32>(values.size()) << 18;
for (const any32& cmd : values)
{
*dst++ = cmd.as<u32>();
}
return u32{sizeof(u32)} * (static_cast<u32>(values.size()) + 1);
}
u32 make_jump(vm::bptr<u32>& dst, u32 offset)
{
*dst++ = RSX_METHOD_OLD_JUMP_CMD | offset;
return sizeof(u32);
}
}
extern s32 cellGcmCallback(ppu_thread& ppu, vm::ptr<CellGcmContextData> context, u32 count);
const u32 tiled_pitches[] = {
0x00000000, 0x00000200, 0x00000300, 0x00000400,
0x00000500, 0x00000600, 0x00000700, 0x00000800,
0x00000A00, 0x00000C00, 0x00000D00, 0x00000E00,
0x00001000, 0x00001400, 0x00001800, 0x00001A00,
0x00001C00, 0x00002000, 0x00002800, 0x00003000,
0x00003400, 0x00003800, 0x00004000, 0x00005000,
0x00006000, 0x00006800, 0x00007000, 0x00008000,
0x0000A000, 0x0000C000, 0x0000D000, 0x0000E000,
0x00010000
};
// Auxiliary functions
/*
* Get usable local memory size for a specific game SDK version
* Example: For 0x00446000 (FW 4.46) we get a localSize of 0x0F900000 (249MB)
*/
u32 gcmGetLocalMemorySize(u32 sdk_version)
{
if (sdk_version >= 0x00220000)
{
return 0x0F900000; // 249MB
}
if (sdk_version >= 0x00200000)
{
return 0x0F200000; // 242MB
}
if (sdk_version >= 0x00190000)
{
return 0x0EA00000; // 234MB
}
if (sdk_version >= 0x00180000)
{
return 0x0E800000; // 232MB
}
return 0x0E000000; // 224MB
}
error_code gcmMapEaIoAddress(ppu_thread& ppu, u32 ea, u32 io, u32 size, bool is_strict);
u32 gcmIoOffsetToAddress(u32 ioOffset)
{
const u32 upper12Bits = g_fxo->get<gcm_config>().offsetTable.eaAddress[ioOffset >> 20];
if (upper12Bits > 0xBFF)
{
return 0;
}
return (upper12Bits << 20) | (ioOffset & 0xFFFFF);
}
void InitOffsetTable()
{
auto& cfg = g_fxo->get<gcm_config>();
const u32 addr = vm::alloc((3072 + 512) * sizeof(u16), vm::main);
cfg.offsetTable.ioAddress.set(addr);
cfg.offsetTable.eaAddress.set(addr + (3072 * sizeof(u16)));
std::memset(vm::base(addr), 0xFF, (3072 + 512) * sizeof(u16));
}
//----------------------------------------------------------------------------
// Data Retrieval
//----------------------------------------------------------------------------
u32 cellGcmGetLabelAddress(u8 index)
{
cellGcmSys.trace("cellGcmGetLabelAddress(index=%d)", index);
return rsx::get_current_renderer()->label_addr + 0x10 * index;
}
vm::ptr<CellGcmReportData> cellGcmGetReportDataAddressLocation(u32 index, u32 location)
{
cellGcmSys.warning("cellGcmGetReportDataAddressLocation(index=%d, location=%d)", index, location);
if (location == CELL_GCM_LOCATION_MAIN)
{
if (index >= 1024 * 1024)
{
cellGcmSys.error("cellGcmGetReportDataAddressLocation: Wrong main index (%d)", index);
}
return vm::cast(gcmIoOffsetToAddress(0x0e000000 + index * 0x10));
}
// Anything else is Local
if (index >= 2048)
{
cellGcmSys.error("cellGcmGetReportDataAddressLocation: Wrong local index (%d)", index);
}
return vm::cast(rsx::get_current_renderer()->label_addr + ::offset32(&RsxReports::report) + index * 0x10);
}
u64 cellGcmGetTimeStamp(u32 index)
{
cellGcmSys.trace("cellGcmGetTimeStamp(index=%d)", index);
if (index >= 2048)
{
cellGcmSys.error("cellGcmGetTimeStamp: Wrong local index (%d)", index);
}
const u32 address = rsx::get_current_renderer()->label_addr + ::offset32(&RsxReports::report) + index * 0x10;
return *vm::get_super_ptr<u64>(address);
}
u32 cellGcmGetCurrentField()
{
cellGcmSys.todo("cellGcmGetCurrentField()");
return 0;
}
u32 cellGcmGetNotifyDataAddress(u32 index)
{
cellGcmSys.warning("cellGcmGetNotifyDataAddress(index=%d)", index);
// If entry not in use, return NULL
u16 entry = g_fxo->get<gcm_config>().offsetTable.eaAddress[241];
if (entry == 0xFFFF) {
return 0;
}
return (entry << 20) + (index * 0x40);
}
/*
* Get base address of local report data area
*/
vm::ptr<CellGcmReportData> _cellGcmFunc12()
{
return vm::ptr<CellGcmReportData>::make(rsx::get_current_renderer()->label_addr + ::offset32(&RsxReports::report)); // TODO
}
u32 cellGcmGetReport(u32 type, u32 index)
{
cellGcmSys.warning("cellGcmGetReport(type=%d, index=%d)", type, index);
if (index >= 2048)
{
cellGcmSys.error("cellGcmGetReport: Wrong local index (%d)", index);
}
if (type < 1 || type > 5) {
return -1;
}
vm::ptr<CellGcmReportData> local_reports = _cellGcmFunc12();
return local_reports[index].value;
}
u32 cellGcmGetReportDataAddress(u32 index)
{
cellGcmSys.warning("cellGcmGetReportDataAddress(index=%d)", index);
if (index >= 2048)
{
cellGcmSys.error("cellGcmGetReportDataAddress: Wrong local index (%d)", index);
}
return rsx::get_current_renderer()->label_addr + ::offset32(&RsxReports::report) + index * 0x10;
}
u32 cellGcmGetReportDataLocation(u32 index, u32 location)
{
cellGcmSys.warning("cellGcmGetReportDataLocation(index=%d, location=%d)", index, location);
vm::ptr<CellGcmReportData> report = cellGcmGetReportDataAddressLocation(index, location);
return report->value;
}
u64 cellGcmGetTimeStampLocation(u32 index, u32 location)
{
cellGcmSys.warning("cellGcmGetTimeStampLocation(index=%d, location=%d)", index, location);
// NOTE: No error checkings
return cellGcmGetReportDataAddressLocation(index, location)->timer;
}
//----------------------------------------------------------------------------
// Command Buffer Control
//----------------------------------------------------------------------------
u32 cellGcmGetControlRegister()
{
cellGcmSys.trace("cellGcmGetControlRegister()");
return g_fxo->get<gcm_config>().gcm_info.control_addr;
}
u32 cellGcmGetDefaultCommandWordSize()
{
cellGcmSys.trace("cellGcmGetDefaultCommandWordSize()");
return g_fxo->get<gcm_config>().gcm_info.command_size;
}
u32 cellGcmGetDefaultSegmentWordSize()
{
cellGcmSys.trace("cellGcmGetDefaultSegmentWordSize()");
return g_fxo->get<gcm_config>().gcm_info.segment_size;
}
error_code cellGcmInitDefaultFifoMode(s32 mode)
{
cellGcmSys.warning("cellGcmInitDefaultFifoMode(mode=%d)", mode);
return CELL_OK;
}
error_code cellGcmSetDefaultFifoSize(u32 bufferSize, u32 segmentSize)
{
cellGcmSys.warning("cellGcmSetDefaultFifoSize(bufferSize=0x%x, segmentSize=0x%x)", bufferSize, segmentSize);
return CELL_OK;
}
//----------------------------------------------------------------------------
// Hardware Resource Management
//----------------------------------------------------------------------------
error_code cellGcmBindTile(u8 index)
{
cellGcmSys.warning("cellGcmBindTile(index=%d)", index);
if (index >= rsx::limits::tiles_count)
{
return CELL_GCM_ERROR_INVALID_VALUE;
}
rsx::get_current_renderer()->tiles[index].bound = true;
return CELL_OK;
}
error_code cellGcmBindZcull(u8 index, u32 offset, u32 width, u32 height, u32 cullStart, u32 zFormat, u32 aaFormat, u32 zCullDir, u32 zCullFormat, u32 sFunc, u32 sRef, u32 sMask)
{
cellGcmSys.warning("cellGcmBindZcull(index=%d, offset=0x%x, width=%d, height=%d, cullStart=0x%x, zFormat=0x%x, aaFormat=0x%x, zCullDir=0x%x, zCullFormat=0x%x, sFunc=0x%x, sRef=0x%x, sMask=0x%x)",
index, offset, width, height, cullStart, zFormat, aaFormat, zCullDir, zCullFormat, sFunc, sRef, sMask);
auto& gcm_cfg = g_fxo->get<gcm_config>();
GcmZcullInfo zcull{};
zcull.offset = offset;
zcull.width = width;
zcull.height = height;
zcull.cullStart = cullStart;
zcull.zFormat = zFormat;
zcull.aaFormat = aaFormat;
zcull.zcullDir = zCullDir;
zcull.zcullFormat = zCullFormat;
zcull.sFunc = sFunc;
zcull.sRef = sRef;
zcull.sMask = sMask;
zcull.bound = true;
const auto gcm_zcull = zcull.pack();
std::lock_guard lock(gcm_cfg.gcmio_mutex);
if (auto err = sys_rsx_context_attribute(0x5555'5555, 0x301, index, u64{gcm_zcull.region} << 32 | gcm_zcull.size, u64{gcm_zcull.start} << 32 | gcm_zcull.offset, u64{gcm_zcull.status0} << 32 | gcm_zcull.status1))
{
return err;
}
vm::_ptr<CellGcmZcullInfo>(gcm_cfg.zculls_addr)[index] = gcm_zcull;
return CELL_OK;
}
void cellGcmGetConfiguration(vm::ptr<CellGcmConfig> config)
{
cellGcmSys.trace("cellGcmGetConfiguration(config=*0x%x)", config);
*config = g_fxo->get<gcm_config>().current_config;
}
u32 cellGcmGetFlipStatus()
{
u32 status = rsx::get_current_renderer()->flip_status;
cellGcmSys.trace("cellGcmGetFlipStatus() -> %d", status);
return status;
}
error_code cellGcmGetFlipStatus2()
{
UNIMPLEMENTED_FUNC(cellGcmSys);
return CELL_OK;
}
u32 cellGcmGetTiledPitchSize(u32 size)
{
cellGcmSys.trace("cellGcmGetTiledPitchSize(size=%d)", size);
for (usz i = 0; i < std::size(tiled_pitches) - 1; i++) {
if (tiled_pitches[i] < size && size <= tiled_pitches[i + 1]) {
return tiled_pitches[i + 1];
}
}
return 0;
}
void _cellGcmFunc1()
{
cellGcmSys.todo("_cellGcmFunc1()");
return;
}
void _cellGcmFunc15(vm::ptr<CellGcmContextData> context)
{
cellGcmSys.todo("_cellGcmFunc15(context=*0x%x)", context);
return;
}
u32 g_defaultCommandBufferBegin, g_defaultCommandBufferFragmentCount;
// Called by cellGcmInit
error_code _cellGcmInitBody(ppu_thread& ppu, vm::pptr<CellGcmContextData> context, u32 cmdSize, u32 ioSize, u32 ioAddress)
{
cellGcmSys.warning("_cellGcmInitBody(context=**0x%x, cmdSize=0x%x, ioSize=0x%x, ioAddress=0x%x)", context, cmdSize, ioSize, ioAddress);
auto& gcm_cfg = g_fxo->get<gcm_config>();
std::lock_guard lock(gcm_cfg.gcmio_mutex);
gcm_cfg.current_config.ioAddress = 0;
gcm_cfg.current_config.localAddress = 0;
gcm_cfg.local_size = 0;
gcm_cfg.local_addr = 0;
//if (!gcm_cfg.local_size && !gcm_cfg.local_addr)
{
gcm_cfg.local_size = 0xf900000; // TODO: Get sdk_version in _cellGcmFunc15 and pass it to gcmGetLocalMemorySize
gcm_cfg.local_addr = rsx::constants::local_mem_base;
vm::falloc(gcm_cfg.local_addr, gcm_cfg.local_size, vm::video);
}
cellGcmSys.warning("*** local memory(addr=0x%x, size=0x%x)", gcm_cfg.local_addr, gcm_cfg.local_size);
InitOffsetTable();
const auto render = rsx::get_current_renderer();
if (gcm_cfg.system_mode == CELL_GCM_SYSTEM_MODE_IOMAP_512MB)
{
cellGcmSys.warning("cellGcmInit(): 512MB io address space used");
render->main_mem_size = 0x20000000;
}
else
{
cellGcmSys.warning("cellGcmInit(): 256MB io address space used");
render->main_mem_size = 0x10000000;
}
render->isHLE = true;
render->local_mem_size = gcm_cfg.local_size;
ensure(sys_rsx_device_map(ppu, vm::var<u64>{}, vm::null, 0x8) == CELL_OK);
ensure(sys_rsx_context_allocate(ppu, vm::var<u32>{}, vm::var<u64>{}, vm::var<u64>{}, vm::var<u64>{}, 0, gcm_cfg.system_mode) == CELL_OK);
if (gcmMapEaIoAddress(ppu, ioAddress, 0, ioSize, false) != CELL_OK)
{
return CELL_GCM_ERROR_FAILURE;
}
gcm_cfg.current_config.ioSize = ioSize;
gcm_cfg.current_config.ioAddress = ioAddress;
gcm_cfg.current_config.localSize = gcm_cfg.local_size;
gcm_cfg.current_config.localAddress = gcm_cfg.local_addr;
gcm_cfg.current_config.memoryFrequency = 650000000;
gcm_cfg.current_config.coreFrequency = 500000000;
const u32 rsx_ctxaddr = render->device_addr;
ensure(rsx_ctxaddr);
g_defaultCommandBufferBegin = ioAddress;
g_defaultCommandBufferFragmentCount = cmdSize / (32 * 1024);
gcm_cfg.gcm_info.context_addr = rsx_ctxaddr;
gcm_cfg.gcm_info.control_addr = render->dma_address;
gcm_cfg.current_context.begin.set(g_defaultCommandBufferBegin + 4096); // 4 kb reserved at the beginning
gcm_cfg.current_context.end.set(g_defaultCommandBufferBegin + 32 * 1024 - 4); // 4b at the end for jump
gcm_cfg.current_context.current = gcm_cfg.current_context.begin;
gcm_cfg.current_context.callback.set(g_fxo->get<ppu_function_manager>().func_addr(FIND_FUNC(cellGcmCallback)));
gcm_cfg.ctxt_addr = context.addr();
gcm_cfg.gcm_buffers.set(vm::alloc(sizeof(CellGcmDisplayInfo) * 8, vm::main));
gcm_cfg.zculls_addr = vm::alloc(sizeof(CellGcmZcullInfo) * 8, vm::main);
gcm_cfg.tiles_addr = vm::alloc(sizeof(CellGcmTileInfo) * 15, vm::main);
vm::_ref<CellGcmContextData>(gcm_cfg.gcm_info.context_addr) = gcm_cfg.current_context;
context->set(gcm_cfg.gcm_info.context_addr);
// 0x40 is to offset CellGcmControl from RsxDmaControl
gcm_cfg.gcm_info.control_addr += 0x40;
vm::var<u64> _tid;
vm::var<char[]> _name = vm::make_str("_gcm_intr_thread");
ppu_execute<&sys_ppu_thread_create>(ppu, +_tid, 0x10000, 0, 1, 0x4000, SYS_PPU_THREAD_CREATE_INTERRUPT, +_name);
render->intr_thread = idm::get<named_thread<ppu_thread>>(static_cast<u32>(*_tid));
render->intr_thread->state -= cpu_flag::stop;
thread_ctrl::notify(*render->intr_thread);
return CELL_OK;
}
void cellGcmResetFlipStatus()
{
cellGcmSys.trace("cellGcmResetFlipStatus()");
rsx::get_current_renderer()->flip_status = CELL_GCM_DISPLAY_FLIP_STATUS_WAITING;
}
error_code cellGcmResetFlipStatus2()
{
UNIMPLEMENTED_FUNC(cellGcmSys);
return CELL_OK;
}
void cellGcmSetDebugOutputLevel(s32 level)
{
cellGcmSys.warning("cellGcmSetDebugOutputLevel(level=%d)", level);
switch (level)
{
case CELL_GCM_DEBUG_LEVEL0:
case CELL_GCM_DEBUG_LEVEL1:
case CELL_GCM_DEBUG_LEVEL2:
rsx::get_current_renderer()->debug_level = level;
break;
default:
break;
}
}
error_code cellGcmSetDisplayBuffer(u8 id, u32 offset, u32 pitch, u32 width, u32 height)
{
cellGcmSys.trace("cellGcmSetDisplayBuffer(id=0x%x, offset=0x%x, pitch=%d, width=%d, height=%d)", id, offset, width ? pitch / width : pitch, width, height);
auto& gcm_cfg = g_fxo->get<gcm_config>();
if (id > 7)
{
return CELL_GCM_ERROR_FAILURE;
}
const auto render = rsx::get_current_renderer();
auto buffers = render->display_buffers;
buffers[id].offset = offset;
buffers[id].pitch = pitch;
buffers[id].width = width;
buffers[id].height = height;
gcm_cfg.gcm_buffers[id].offset = offset;
gcm_cfg.gcm_buffers[id].pitch = pitch;
gcm_cfg.gcm_buffers[id].width = width;
gcm_cfg.gcm_buffers[id].height = height;
if (id + 1u > render->display_buffers_count)
{
render->display_buffers_count = id + 1;
}
return CELL_OK;
}
void cellGcmSetFlipHandler(vm::ptr<void(u32)> handler)
{
cellGcmSys.warning("cellGcmSetFlipHandler(handler=*0x%x)", handler);
if (const auto rsx = rsx::get_current_renderer(); rsx->is_initialized)
{
rsx->flip_handler = handler;
}
}
error_code cellGcmSetFlipHandler2()
{
UNIMPLEMENTED_FUNC(cellGcmSys);
return CELL_OK;
}
void cellGcmSetFlipMode(u32 mode)
{
cellGcmSys.warning("cellGcmSetFlipMode(mode=%d)", mode);
rsx::get_current_renderer()->requested_vsync.store(mode == CELL_GCM_DISPLAY_VSYNC);
}
error_code cellGcmSetFlipMode2()
{
UNIMPLEMENTED_FUNC(cellGcmSys);
return CELL_OK;
}
void cellGcmSetFlipStatus()
{
cellGcmSys.warning("cellGcmSetFlipStatus()");
rsx::get_current_renderer()->flip_status = CELL_GCM_DISPLAY_FLIP_STATUS_DONE;
}
error_code cellGcmSetFlipStatus2()
{
UNIMPLEMENTED_FUNC(cellGcmSys);
return CELL_OK;
}
template <bool old_api = false, typename ret_type = std::conditional_t<old_api, s32, error_code>>
ret_type gcmSetPrepareFlip(ppu_thread& ppu, vm::ptr<CellGcmContextData> ctxt, u32 id)
{
auto& gcm_cfg = g_fxo->get<gcm_config>();
if (id > 7)
{
return CELL_GCM_ERROR_FAILURE;
}
if (!old_api && ctxt->current + 2 >= ctxt->end)
{
if (s32 res = ctxt->callback(ppu, ctxt, 8 /* ??? */))
{
cellGcmSys.error("cellGcmSetPrepareFlip: callback failed (0x%08x)", res);
return static_cast<ret_type>(not_an_error(res));
}
}
const u32 cmd_size = rsx::make_command(ctxt->current, GCM_FLIP_COMMAND, { id });
if (!old_api && ctxt.addr() == gcm_cfg.gcm_info.context_addr)
{
vm::_ref<CellGcmControl>(gcm_cfg.gcm_info.control_addr).put += cmd_size;
}
return static_cast<ret_type>(not_an_error(id));
}
error_code cellGcmSetPrepareFlip(ppu_thread& ppu, vm::ptr<CellGcmContextData> ctxt, u32 id)
{
cellGcmSys.trace("cellGcmSetPrepareFlip(ctxt=*0x%x, id=0x%x)", ctxt, id);
return gcmSetPrepareFlip(ppu, ctxt, id);
}
error_code cellGcmSetFlip(ppu_thread& ppu, vm::ptr<CellGcmContextData> ctxt, u32 id)
{
cellGcmSys.trace("cellGcmSetFlip(ctxt=*0x%x, id=0x%x)", ctxt, id);
if (auto res = gcmSetPrepareFlip(ppu, ctxt, id); res < 0)
{
return CELL_GCM_ERROR_FAILURE;
}
return CELL_OK;
}
void cellGcmSetSecondVFrequency(u32 freq)
{
cellGcmSys.warning("cellGcmSetSecondVFrequency(level=%d)", freq);
switch (freq)
{
case CELL_GCM_DISPLAY_FREQUENCY_59_94HZ:
break;
case CELL_GCM_DISPLAY_FREQUENCY_SCANOUT:
cellGcmSys.todo("Unimplemented display frequency: Scanout");
break;
case CELL_GCM_DISPLAY_FREQUENCY_DISABLE:
cellGcmSys.todo("Unimplemented display frequency: Disabled");
break;
default:
cellGcmSys.error("Improper display frequency specified!");
break;
}
}
error_code cellGcmSetTileInfo(u8 index, u8 location, u32 offset, u32 size, u32 pitch, u8 comp, u16 base, u8 bank)
{
cellGcmSys.warning("cellGcmSetTileInfo(index=%d, location=%d, offset=%d, size=%d, pitch=%d, comp=%d, base=%d, bank=%d)",
index, location, offset, size, pitch, comp, base, bank);
auto& gcm_cfg = g_fxo->get<gcm_config>();
if (index >= rsx::limits::tiles_count || base >= 2048 || bank >= 4)
{
return CELL_GCM_ERROR_INVALID_VALUE;
}
if (offset & 0xffff || size & 0xffff || pitch & 0xff)
{
return CELL_GCM_ERROR_INVALID_ALIGNMENT;
}
if (location >= 2 || (comp != 0 && (comp < 7 || comp > 12)))
{
return CELL_GCM_ERROR_INVALID_ENUM;
}
if (comp)
{
cellGcmSys.error("cellGcmSetTileInfo: bad compression mode! (%d)", comp);
}
const auto render = rsx::get_current_renderer();
auto& tile = render->tiles[index];
tile.location = location;
tile.offset = offset;
tile.size = size;
tile.pitch = pitch;
tile.comp = comp;
tile.base = base;
tile.bank = bank;
vm::_ptr<CellGcmTileInfo>(gcm_cfg.tiles_addr)[index] = tile.pack();
return CELL_OK;
}
void cellGcmSetUserHandler(vm::ptr<void(u32)> handler)
{
cellGcmSys.warning("cellGcmSetUserHandler(handler=*0x%x)", handler);
if (const auto rsx = rsx::get_current_renderer(); rsx->is_initialized)
{
rsx->user_handler = handler;
}
}
void cellGcmSetUserCommand(ppu_thread& ppu, vm::ptr<CellGcmContextData> ctxt, u32 cause)
{
cellGcmSys.trace("cellGcmSetUserCommand(ctxt=*0x%x, cause=0x%x)", ctxt, cause);
if (ctxt->current + 2 >= ctxt->end)
{
if (s32 res = ctxt->callback(ppu, ctxt, 8 /* ??? */))
{
cellGcmSys.error("cellGcmSetUserCommand(): callback failed (0x%08x)", res);
return;
}
}
rsx::make_command(ctxt->current, GCM_SET_USER_COMMAND, { cause });
}
void cellGcmSetVBlankHandler(vm::ptr<void(u32)> handler)
{
cellGcmSys.warning("cellGcmSetVBlankHandler(handler=*0x%x)", handler);
if (const auto rsx = rsx::get_current_renderer(); rsx->is_initialized)
{
rsx->vblank_handler = handler;
}
}
void cellGcmSetWaitFlip(ppu_thread& ppu, vm::ptr<CellGcmContextData> ctxt)
{
cellGcmSys.trace("cellGcmSetWaitFlip(ctxt=*0x%x)", ctxt);
if (ctxt->current + 2 >= ctxt->end)
{
if (s32 res = ctxt->callback(ppu, ctxt, 8 /* ??? */))
{
cellGcmSys.error("cellGcmSetWaitFlip(): callback failed (0x%08x)", res);
return;
}
}
rsx::make_command(ctxt->current, NV406E_SEMAPHORE_OFFSET, { 0x10u, 0 });
}
void cellGcmSetWaitFlipUnsafe(vm::ptr<CellGcmContextData> ctxt)
{
cellGcmSys.trace("cellGcmSetWaitFlipUnsafe(ctxt=*0x%x)", ctxt);
rsx::make_command(ctxt->current, NV406E_SEMAPHORE_OFFSET, { 0x10u, 0 });
}
void cellGcmSetZcull(u8 index, u32 offset, u32 width, u32 height, u32 cullStart, u32 zFormat, u32 aaFormat, u32 zCullDir, u32 zCullFormat, u32 sFunc, u32 sRef, u32 sMask)
{
cellGcmSys.warning("cellGcmSetZcull(index=%d, offset=0x%x, width=%d, height=%d, cullStart=0x%x, zFormat=0x%x, aaFormat=0x%x, zCullDir=0x%x, zCullFormat=0x%x, sFunc=0x%x, sRef=0x%x, sMask=0x%x)",
index, offset, width, height, cullStart, zFormat, aaFormat, zCullDir, zCullFormat, sFunc, sRef, sMask);
auto& gcm_cfg = g_fxo->get<gcm_config>();
GcmZcullInfo zcull{};
zcull.offset = offset;
zcull.width = width;
zcull.height = height;
zcull.cullStart = cullStart;
zcull.zFormat = zFormat;
zcull.aaFormat = aaFormat;
zcull.zcullDir = zCullDir;
zcull.zcullFormat = zCullFormat;
zcull.sFunc = sFunc;
zcull.sRef = sRef;
zcull.sMask = sMask;
zcull.bound = true;
const auto gcm_zcull = zcull.pack();
// The second difference between BindZcull and this function (second is no return value) is that this function is not thread-safe
// But take care anyway
std::lock_guard lock(gcm_cfg.gcmio_mutex);
if (!sys_rsx_context_attribute(0x5555'5555, 0x301, index, u64{gcm_zcull.region} << 32 | gcm_zcull.size, u64{gcm_zcull.start} << 32 | gcm_zcull.offset, u64{gcm_zcull.status0} << 32 | gcm_zcull.status1))
{
vm::_ptr<CellGcmZcullInfo>(gcm_cfg.zculls_addr)[index] = gcm_zcull;
}
}
error_code cellGcmUnbindTile(u8 index)
{
cellGcmSys.warning("cellGcmUnbindTile(index=%d)", index);
if (index >= rsx::limits::tiles_count)
{
return CELL_GCM_ERROR_INVALID_VALUE;
}
rsx::get_current_renderer()->tiles[index].bound = false;
return CELL_OK;
}
error_code cellGcmUnbindZcull(u8 index)
{
cellGcmSys.warning("cellGcmUnbindZcull(index=%d)", index);
if (index >= 8)
{
return CELL_GCM_ERROR_INVALID_VALUE;
}
rsx::get_current_renderer()->zculls[index].bound = false;
return CELL_OK;
}
u32 cellGcmGetTileInfo()
{
cellGcmSys.warning("cellGcmGetTileInfo()");
return g_fxo->get<gcm_config>().tiles_addr;
}
u32 cellGcmGetZcullInfo()
{
cellGcmSys.warning("cellGcmGetZcullInfo()");
return g_fxo->get<gcm_config>().zculls_addr;
}
u32 cellGcmGetDisplayInfo()
{
cellGcmSys.warning("cellGcmGetDisplayInfo()");
return g_fxo->get<gcm_config>().gcm_buffers.addr();
}
error_code cellGcmGetCurrentDisplayBufferId(vm::ptr<u8> id)
{
cellGcmSys.warning("cellGcmGetCurrentDisplayBufferId(id=*0x%x)", id);
*id = ::narrow<u8>(rsx::get_current_renderer()->current_display_buffer);
return CELL_OK;
}
void cellGcmSetInvalidateTile(u8 index)
{
cellGcmSys.todo("cellGcmSetInvalidateTile(index=%d)", index);
}
error_code cellGcmTerminate()
{
// The firmware just return CELL_OK as well
return CELL_OK;
}
error_code cellGcmDumpGraphicsError()
{
cellGcmSys.todo("cellGcmDumpGraphicsError()");
return CELL_OK;
}
s32 cellGcmGetDisplayBufferByFlipIndex(u32 qid)
{
cellGcmSys.todo("cellGcmGetDisplayBufferByFlipIndex(qid=%d)", qid);
return -1; // Invalid id, todo
}
u64 cellGcmGetLastFlipTime()
{
cellGcmSys.trace("cellGcmGetLastFlipTime()");
return rsx::get_current_renderer()->last_guest_flip_timestamp;
}
error_code cellGcmGetLastFlipTime2()
{
UNIMPLEMENTED_FUNC(cellGcmSys);
return CELL_OK;
}
u64 cellGcmGetLastSecondVTime()
{
cellGcmSys.todo("cellGcmGetLastSecondVTime()");
return CELL_OK;
}
u64 cellGcmGetVBlankCount()
{
cellGcmSys.trace("cellGcmGetVBlankCount()");
return rsx::get_current_renderer()->vblank_count;
}
error_code cellGcmGetVBlankCount2()
{
UNIMPLEMENTED_FUNC(cellGcmSys);
return CELL_OK;
}
error_code cellGcmSysGetLastVBlankTime()
{
cellGcmSys.todo("cellGcmSysGetLastVBlankTime()");
return CELL_OK;
}
error_code cellGcmInitSystemMode(u64 mode)
{
cellGcmSys.trace("cellGcmInitSystemMode(mode=0x%x)", mode);
g_fxo->get<gcm_config>().system_mode = mode;
return CELL_OK;
}
error_code cellGcmSetFlipImmediate(u8 id)
{
cellGcmSys.todo("cellGcmSetFlipImmediate(id=0x%x)", id);
if (id > 7)
{
return CELL_GCM_ERROR_FAILURE;
}
cellGcmSetFlipMode(id);
return CELL_OK;
}
error_code cellGcmSetFlipImmediate2()
{
UNIMPLEMENTED_FUNC(cellGcmSys);
return CELL_OK;
}
void cellGcmSetGraphicsHandler(vm::ptr<void(u32)> handler)
{
cellGcmSys.todo("cellGcmSetGraphicsHandler(handler=*0x%x)", handler);
}
void cellGcmSetQueueHandler(vm::ptr<void(u32)> handler)
{
cellGcmSys.warning("cellGcmSetQueueHandler(handler=*0x%x)", handler);
if (const auto rsx = rsx::get_current_renderer(); rsx->is_initialized)
{
rsx->queue_handler = handler;
}
}
error_code cellGcmSetSecondVHandler(vm::ptr<void(u32)> handler)
{
cellGcmSys.todo("cellGcmSetSecondVHandler(handler=0x%x)", handler);
return CELL_OK;
}
void cellGcmSetVBlankFrequency(u32 freq)
{
cellGcmSys.todo("cellGcmSetVBlankFrequency(freq=%d)", freq);
}
error_code cellGcmSortRemapEaIoAddress()
{
cellGcmSys.todo("cellGcmSortRemapEaIoAddress()");
return CELL_OK;
}
//----------------------------------------------------------------------------
// Memory Mapping
//----------------------------------------------------------------------------
error_code cellGcmAddressToOffset(u32 address, vm::ptr<u32> offset)
{
cellGcmSys.trace("cellGcmAddressToOffset(address=0x%x, offset=*0x%x)", address, offset);
auto& gcm_cfg = g_fxo->get<gcm_config>();
u32 result;
// Test if address is within local memory
if (const u32 offs = address - gcm_cfg.local_addr; offs < gcm_cfg.local_size)
{
result = offs;
}
// Address in main memory else check
else
{
const u32 upper12Bits = gcm_cfg.offsetTable.ioAddress[address >> 20];
// If the address is mapped in IO
if (upper12Bits << 20 < rsx::get_current_renderer()->main_mem_size)
{
result = (upper12Bits << 20) | (address & 0xFFFFF);
}
else
{
return CELL_GCM_ERROR_FAILURE;
}
}
*offset = result;
return CELL_OK;
}
u32 cellGcmGetMaxIoMapSize()
{
cellGcmSys.trace("cellGcmGetMaxIoMapSize()");
return rsx::get_current_renderer()->main_mem_size - g_fxo->get<gcm_config>().reserved_size;
}
void cellGcmGetOffsetTable(vm::ptr<CellGcmOffsetTable> table)
{
cellGcmSys.trace("cellGcmGetOffsetTable(table=*0x%x)", table);
auto& gcm_cfg = g_fxo->get<gcm_config>();
table->ioAddress = gcm_cfg.offsetTable.ioAddress;
table->eaAddress = gcm_cfg.offsetTable.eaAddress;
}
error_code cellGcmIoOffsetToAddress(u32 ioOffset, vm::ptr<u32> address)
{
cellGcmSys.trace("cellGcmIoOffsetToAddress(ioOffset=0x%x, address=*0x%x)", ioOffset, address);
const u32 addr = gcmIoOffsetToAddress(ioOffset);
if (!addr)
{
return CELL_GCM_ERROR_FAILURE;
}
*address = addr;
return CELL_OK;
}
error_code gcmMapEaIoAddress(ppu_thread& ppu, u32 ea, u32 io, u32 size, bool is_strict)
{
if (!size || (ea & 0xFFFFF) || (io & 0xFFFFF) || (size & 0xFFFFF))
{
return CELL_GCM_ERROR_FAILURE;
}
if (auto error = sys_rsx_context_iomap(ppu, 0x55555555, io, ea, size, 0xe000000000000800ull | (u64{is_strict} << 60)))
{
return error;
}
// Assume lock is acquired
auto& gcm_cfg = g_fxo->get<gcm_config>();
ea >>= 20, io >>= 20, size >>= 20;
// Fill the offset table
for (u32 i = 0; i < size; i++)
{
gcm_cfg.offsetTable.ioAddress[ea + i] = io + i;
gcm_cfg.offsetTable.eaAddress[io + i] = ea + i;
}
gcm_cfg.IoMapTable[ea] = size;
return CELL_OK;
}
error_code cellGcmMapEaIoAddress(ppu_thread& ppu, u32 ea, u32 io, u32 size)
{
cellGcmSys.warning("cellGcmMapEaIoAddress(ea=0x%x, io=0x%x, size=0x%x)", ea, io, size);
auto& gcm_cfg = g_fxo->get<gcm_config>();
std::lock_guard lock(gcm_cfg.gcmio_mutex);
return gcmMapEaIoAddress(ppu, ea, io, size, false);
}
error_code cellGcmMapEaIoAddressWithFlags(ppu_thread& ppu, u32 ea, u32 io, u32 size, u32 flags)
{
cellGcmSys.warning("cellGcmMapEaIoAddressWithFlags(ea=0x%x, io=0x%x, size=0x%x, flags=0x%x)", ea, io, size, flags);
ensure(flags == CELL_GCM_IOMAP_FLAG_STRICT_ORDERING);
auto& gcm_cfg = g_fxo->get<gcm_config>();
std::lock_guard lock(gcm_cfg.gcmio_mutex);
return gcmMapEaIoAddress(ppu, ea, io, size, true);
}
error_code cellGcmMapLocalMemory(vm::ptr<u32> address, vm::ptr<u32> size)
{
cellGcmSys.warning("cellGcmMapLocalMemory(address=*0x%x, size=*0x%x)", address, size);
auto& gcm_cfg = g_fxo->get<gcm_config>();
std::lock_guard lock(gcm_cfg.gcmio_mutex);
if (!gcm_cfg.local_addr && !gcm_cfg.local_size && vm::falloc(gcm_cfg.local_addr = rsx::constants::local_mem_base, gcm_cfg.local_size = 0xf900000 /* TODO */, vm::video))
{
*address = gcm_cfg.local_addr;
*size = gcm_cfg.local_size;
return CELL_OK;
}
return CELL_GCM_ERROR_FAILURE;
}
error_code cellGcmMapMainMemory(ppu_thread& ppu, u32 ea, u32 size, vm::ptr<u32> offset)
{
cellGcmSys.warning("cellGcmMapMainMemory(ea=0x%x, size=0x%x, offset=*0x%x)", ea, size, offset);
if (!size || (ea & 0xFFFFF) || (size & 0xFFFFF)) return CELL_GCM_ERROR_FAILURE;
auto& gcm_cfg = g_fxo->get<gcm_config>();
std::lock_guard lock(gcm_cfg.gcmio_mutex);
// Use the offset table to find the next free io address
for (u32 io = 0, end = (rsx::get_current_renderer()->main_mem_size - gcm_cfg.reserved_size) >> 20, unmap_count = 1; io < end; unmap_count++)
{
if (gcm_cfg.offsetTable.eaAddress[io + unmap_count - 1] > 0xBFF)
{
if (unmap_count >= (size >> 20))
{
io <<= 20;
if (auto error = gcmMapEaIoAddress(ppu, ea, io, size, false))
{
return error;
}
*offset = io;
return CELL_OK;
}
}
else
{
io += unmap_count;
unmap_count = 0;
}
}
return CELL_GCM_ERROR_NO_IO_PAGE_TABLE;
}
error_code cellGcmReserveIoMapSize(u32 size)
{
cellGcmSys.trace("cellGcmReserveIoMapSize(size=0x%x)", size);
if (size & 0xFFFFF)
{
return CELL_GCM_ERROR_INVALID_ALIGNMENT;
}
auto& gcm_cfg = g_fxo->get<gcm_config>();
std::lock_guard lock(gcm_cfg.gcmio_mutex);
if (size > cellGcmGetMaxIoMapSize())
{
return CELL_GCM_ERROR_INVALID_VALUE;
}
gcm_cfg.reserved_size += size;
return CELL_OK;
}
error_code GcmUnmapIoAddress(ppu_thread& ppu, gcm_config& gcm_cfg, u32 io)
{
if (u32 ea = gcm_cfg.offsetTable.eaAddress[io >>= 20], size = gcm_cfg.IoMapTable[ea]; size)
{
if (auto error = sys_rsx_context_iounmap(ppu, 0x55555555, io << 20, size << 20))
{
return error;
}
for (u32 i = 0; i < size; i++)
{
gcm_cfg.offsetTable.ioAddress[ea + i] = 0xFFFF;
gcm_cfg.offsetTable.eaAddress[io + i] = 0xFFFF;
}
gcm_cfg.IoMapTable[ea] = 0;
return CELL_OK;
}
return CELL_GCM_ERROR_FAILURE;
}
error_code cellGcmUnmapEaIoAddress(ppu_thread& ppu, u32 ea)
{
cellGcmSys.warning("cellGcmUnmapEaIoAddress(ea=0x%x)", ea);
// Ignores lower bits
ea >>= 20;
if (ea > 0xBFF)
{
return CELL_GCM_ERROR_FAILURE;
}
auto& gcm_cfg = g_fxo->get<gcm_config>();
std::lock_guard lock(gcm_cfg.gcmio_mutex);
if (const u32 io = gcm_cfg.offsetTable.ioAddress[ea] << 20;
io < rsx::get_current_renderer()->main_mem_size)
{
return GcmUnmapIoAddress(ppu, gcm_cfg, io);
}
return CELL_GCM_ERROR_FAILURE;
}
error_code cellGcmUnmapIoAddress(ppu_thread& ppu, u32 io)
{
cellGcmSys.warning("cellGcmUnmapIoAddress(io=0x%x)", io);
auto& gcm_cfg = g_fxo->get<gcm_config>();
std::lock_guard lock(gcm_cfg.gcmio_mutex);
return GcmUnmapIoAddress(ppu, gcm_cfg, io);
}
error_code cellGcmUnreserveIoMapSize(u32 size)
{
cellGcmSys.trace("cellGcmUnreserveIoMapSize(size=0x%x)", size);
if (size & 0xFFFFF)
{
return CELL_GCM_ERROR_INVALID_ALIGNMENT;
}
auto& gcm_cfg = g_fxo->get<gcm_config>();
std::lock_guard lock(gcm_cfg.gcmio_mutex);
if (size > gcm_cfg.reserved_size)
{
return CELL_GCM_ERROR_INVALID_VALUE;
}
gcm_cfg.reserved_size -= size;
return CELL_OK;
}
//----------------------------------------------------------------------------
// Cursor Functions
//----------------------------------------------------------------------------
error_code cellGcmInitCursor()
{
cellGcmSys.todo("cellGcmInitCursor()");
return CELL_OK;
}
error_code cellGcmSetCursorPosition(s32 x, s32 y)
{
cellGcmSys.todo("cellGcmSetCursorPosition(x=%d, y=%d)", x, y);
return CELL_OK;
}
error_code cellGcmSetCursorDisable()
{
cellGcmSys.todo("cellGcmSetCursorDisable()");
return CELL_OK;
}
error_code cellGcmUpdateCursor()
{
cellGcmSys.todo("cellGcmUpdateCursor()");
return CELL_OK;
}
error_code cellGcmSetCursorEnable()
{
cellGcmSys.todo("cellGcmSetCursorEnable()");
return CELL_OK;
}
error_code cellGcmSetCursorImageOffset(u32 offset)
{
cellGcmSys.todo("cellGcmSetCursorImageOffset(offset=0x%x)", offset);
return CELL_OK;
}
//------------------------------------------------------------------------
// Functions for Maintaining Compatibility
//------------------------------------------------------------------------
void cellGcmSetDefaultCommandBuffer()
{
cellGcmSys.warning("cellGcmSetDefaultCommandBuffer()");
auto& gcm_cfg = g_fxo->get<gcm_config>();
vm::write32(gcm_cfg.ctxt_addr, gcm_cfg.gcm_info.context_addr);
}
error_code cellGcmSetDefaultCommandBufferAndSegmentWordSize(u32 bufferSize, u32 segmentSize)
{
cellGcmSys.warning("cellGcmSetDefaultCommandBufferAndSegmentWordSize(bufferSize=0x%x, segmentSize=0x%x)", bufferSize, segmentSize);
auto& gcm_cfg = g_fxo->get<gcm_config>();
const auto& put = vm::_ref<CellGcmControl>(gcm_cfg.gcm_info.control_addr).put;
const auto& get = vm::_ref<CellGcmControl>(gcm_cfg.gcm_info.control_addr).get;
if (put != 0x1000 || get != 0x1000 || bufferSize < segmentSize * 2 || segmentSize >= 0x80000000)
{
return CELL_GCM_ERROR_FAILURE;
}
gcm_cfg.gcm_info.command_size = bufferSize;
gcm_cfg.gcm_info.segment_size = segmentSize;
return CELL_OK;
}
//------------------------------------------------------------------------
// Other
//------------------------------------------------------------------------
void _cellGcmSetFlipCommand(ppu_thread& ppu, vm::ptr<CellGcmContextData> ctx, u32 id)
{
cellGcmSys.trace("cellGcmSetFlipCommand(ctx=*0x%x, id=0x%x)", ctx, id);
if (auto error = gcmSetPrepareFlip<true>(ppu, ctx, id); error < 0)
{
// TODO: On actual fw this function doesn't have error checks at all
cellGcmSys.error("cellGcmSetFlipCommand(): gcmSetPrepareFlip failed with %s", CellGcmError{error + 0u});
}
}
error_code _cellGcmSetFlipCommand2()
{
UNIMPLEMENTED_FUNC(cellGcmSys);
return CELL_OK;
}
void _cellGcmSetFlipCommandWithWaitLabel(ppu_thread& ppu, vm::ptr<CellGcmContextData> ctx, u32 id, u32 label_index, u32 label_value)
{
cellGcmSys.warning("cellGcmSetFlipCommandWithWaitLabel(ctx=*0x%x, id=0x%x, label_index=0x%x, label_value=0x%x)", ctx, id, label_index, label_value);
rsx::make_command(ctx->current, NV406E_SEMAPHORE_OFFSET, { label_index * 0x10, label_value });
if (auto error = gcmSetPrepareFlip<true>(ppu, ctx, id); error < 0)
{
// TODO: On actual fw this function doesn't have error checks at all
cellGcmSys.error("cellGcmSetFlipCommandWithWaitLabel(): gcmSetPrepareFlip failed with %s", CellGcmError{error + 0u});
}
}
error_code cellGcmSetTile(u8 index, u8 location, u32 offset, u32 size, u32 pitch, u8 comp, u16 base, u8 bank)
{
cellGcmSys.warning("cellGcmSetTile(index=%d, location=%d, offset=%d, size=%d, pitch=%d, comp=%d, base=%d, bank=%d)",
index, location, offset, size, pitch, comp, base, bank);
auto& gcm_cfg = g_fxo->get<gcm_config>();
// Copied form cellGcmSetTileInfo
if (index >= rsx::limits::tiles_count || base >= 2048 || bank >= 4)
{
return CELL_GCM_ERROR_INVALID_VALUE;
}
if (offset & 0xffff || size & 0xffff || pitch & 0xff)
{
return CELL_GCM_ERROR_INVALID_ALIGNMENT;
}
if (location >= 2 || (comp != 0 && (comp < 7 || comp > 12)))
{
return CELL_GCM_ERROR_INVALID_ENUM;
}
if (comp)
{
cellGcmSys.error("cellGcmSetTile: bad compression mode! (%d)", comp);
}
const auto render = rsx::get_current_renderer();
auto& tile = render->tiles[index];
tile.location = location;
tile.offset = offset;
tile.size = size;
tile.pitch = pitch;
tile.comp = comp;
tile.base = base;
tile.bank = bank;
tile.bound = (pitch > 0);
vm::_ptr<CellGcmTileInfo>(gcm_cfg.tiles_addr)[index] = tile.pack();
return CELL_OK;
}
error_code _cellGcmFunc2()
{
cellGcmSys.todo("_cellGcmFunc2()");
return CELL_OK;
}
error_code _cellGcmFunc3()
{
cellGcmSys.todo("_cellGcmFunc3()");
return CELL_OK;
}
error_code _cellGcmFunc4()
{
cellGcmSys.todo("_cellGcmFunc4()");
return CELL_OK;
}
error_code _cellGcmFunc13()
{
cellGcmSys.todo("_cellGcmFunc13()");
return CELL_OK;
}
error_code _cellGcmFunc38()
{
cellGcmSys.todo("_cellGcmFunc38()");
return CELL_OK;
}
error_code cellGcmGpadGetStatus(vm::ptr<u32> status)
{
cellGcmSys.todo("cellGcmGpadGetStatus(status=*0x%x)", status);
return CELL_OK;
}
error_code cellGcmGpadNotifyCaptureSurface(vm::ptr<CellGcmSurface> surface)
{
cellGcmSys.todo("cellGcmGpadNotifyCaptureSurface(surface=*0x%x)", surface);
return CELL_OK;
}
error_code cellGcmGpadCaptureSnapshot(u32 num)
{
cellGcmSys.todo("cellGcmGpadCaptureSnapshot(num=%d)", num);
return CELL_OK;
}
//----------------------------------------------------------------------------
/**
* Using current to determine what is the next useable command buffer.
* Caller may wait for RSX not to use the command buffer.
*/
static std::pair<u32, u32> getNextCommandBufferBeginEnd(u32 current)
{
u32 currentRange = (current - g_defaultCommandBufferBegin) / (32 * 1024);
if (currentRange >= g_defaultCommandBufferFragmentCount - 1)
return std::make_pair(g_defaultCommandBufferBegin + 4096, g_defaultCommandBufferBegin + 32 * 1024 - 4);
return std::make_pair(g_defaultCommandBufferBegin + (currentRange + 1) * 32 * 1024,
g_defaultCommandBufferBegin + (currentRange + 2) * 32 * 1024 - 4);
}
static u32 getOffsetFromAddress(u32 address)
{
const u32 upper = g_fxo->get<gcm_config>().offsetTable.ioAddress[address >> 20]; // 12 bits
ensure(upper != 0xFFFF);
return (upper << 20) | (address & 0xFFFFF);
}
/**
* Returns true if getPos is a valid position in command buffer and not between
* bufferBegin and bufferEnd which are absolute memory address
*/
static bool isInCommandBufferExcept(u32 getPos, u32 bufferBegin, u32 bufferEnd)
{
// Is outside of default command buffer :
// It's in a call/return statement
// Conservatively return false here
if (getPos < getOffsetFromAddress(g_defaultCommandBufferBegin + 4096) &&
getPos > getOffsetFromAddress(g_defaultCommandBufferBegin + g_defaultCommandBufferFragmentCount * 32 * 1024))
return false;
if (getPos >= getOffsetFromAddress(bufferBegin) &&
getPos <= getOffsetFromAddress(bufferEnd))
return false;
return true;
}
s32 cellGcmCallback(ppu_thread& ppu, vm::ptr<CellGcmContextData> context, u32 count)
{
cellGcmSys.trace("cellGcmCallback(context=*0x%x, count=0x%x)", context, count);
auto& gcm_cfg = g_fxo->get<gcm_config>();
auto& ctrl = vm::_ref<CellGcmControl>(gcm_cfg.gcm_info.control_addr);
// Flush command buffer (ie allow RSX to read up to context->current)
ctrl.put.exchange(getOffsetFromAddress(context->current.addr()));
std::pair<u32, u32> newCommandBuffer = getNextCommandBufferBeginEnd(context->current.addr());
u32 offset = getOffsetFromAddress(newCommandBuffer.first);
// Write jump instruction
*context->current = RSX_METHOD_OLD_JUMP_CMD | offset;
// Update current command buffer
context->begin.set(newCommandBuffer.first);
context->current.set(newCommandBuffer.first);
context->end.set(newCommandBuffer.second);
// Wait for rsx to "release" the new command buffer
while (true)
{
u32 getPos = ctrl.get.load();
if (isInCommandBufferExcept(getPos, newCommandBuffer.first, newCommandBuffer.second))
break;
if (ppu.test_stopped())
{
return 0;
}
busy_wait();
}
return CELL_OK;
}
//----------------------------------------------------------------------------
DECLARE(ppu_module_manager::cellGcmSys)("cellGcmSys", []()
{
// Data Retrieval
REG_FUNC(cellGcmSys, cellGcmGetCurrentField);
REG_FUNC(cellGcmSys, cellGcmGetLabelAddress);
REG_FUNC(cellGcmSys, cellGcmGetNotifyDataAddress);
REG_FUNC(cellGcmSys, _cellGcmFunc12);
REG_FUNC(cellGcmSys, cellGcmGetReport);
REG_FUNC(cellGcmSys, cellGcmGetReportDataAddress);
REG_FUNC(cellGcmSys, cellGcmGetReportDataAddressLocation);
REG_FUNC(cellGcmSys, cellGcmGetReportDataLocation);
REG_FUNC(cellGcmSys, cellGcmGetTimeStamp).flag(MFF_FORCED_HLE); // HLE-ing this allows for optimizations around reports
REG_FUNC(cellGcmSys, cellGcmGetTimeStampLocation);
// Command Buffer Control
REG_FUNC(cellGcmSys, cellGcmGetControlRegister);
REG_FUNC(cellGcmSys, cellGcmGetDefaultCommandWordSize);
REG_FUNC(cellGcmSys, cellGcmGetDefaultSegmentWordSize);
REG_FUNC(cellGcmSys, cellGcmInitDefaultFifoMode);
REG_FUNC(cellGcmSys, cellGcmSetDefaultFifoSize);
// Hardware Resource Management
REG_FUNC(cellGcmSys, cellGcmBindTile);
REG_FUNC(cellGcmSys, cellGcmBindZcull);
REG_FUNC(cellGcmSys, cellGcmDumpGraphicsError);
REG_FUNC(cellGcmSys, cellGcmGetConfiguration);
REG_FUNC(cellGcmSys, cellGcmGetDisplayBufferByFlipIndex);
REG_FUNC(cellGcmSys, cellGcmGetFlipStatus);
REG_FUNC(cellGcmSys, cellGcmGetFlipStatus2);
REG_FUNC(cellGcmSys, cellGcmGetLastFlipTime);
REG_FUNC(cellGcmSys, cellGcmGetLastFlipTime2);
REG_FUNC(cellGcmSys, cellGcmGetLastSecondVTime);
REG_FUNC(cellGcmSys, cellGcmGetTiledPitchSize);
REG_FUNC(cellGcmSys, cellGcmGetVBlankCount);
REG_FUNC(cellGcmSys, cellGcmGetVBlankCount2);
REG_FUNC(cellGcmSys, cellGcmSysGetLastVBlankTime);
REG_FUNC(cellGcmSys, _cellGcmFunc1);
REG_FUNC(cellGcmSys, _cellGcmFunc15);
REG_FUNC(cellGcmSys, _cellGcmInitBody);
REG_FUNC(cellGcmSys, cellGcmInitSystemMode);
REG_FUNC(cellGcmSys, cellGcmResetFlipStatus);
REG_FUNC(cellGcmSys, cellGcmResetFlipStatus2);
REG_FUNC(cellGcmSys, cellGcmSetDebugOutputLevel);
REG_FUNC(cellGcmSys, cellGcmSetDisplayBuffer);
REG_FUNC(cellGcmSys, cellGcmSetFlip); //
REG_FUNC(cellGcmSys, cellGcmSetFlipHandler);
REG_FUNC(cellGcmSys, cellGcmSetFlipHandler2);
REG_FUNC(cellGcmSys, cellGcmSetFlipImmediate);
REG_FUNC(cellGcmSys, cellGcmSetFlipImmediate2);
REG_FUNC(cellGcmSys, cellGcmSetFlipMode);
REG_FUNC(cellGcmSys, cellGcmSetFlipMode2);
REG_FUNC(cellGcmSys, cellGcmSetFlipStatus);
REG_FUNC(cellGcmSys, cellGcmSetFlipStatus2);
REG_FUNC(cellGcmSys, cellGcmSetGraphicsHandler);
REG_FUNC(cellGcmSys, cellGcmSetPrepareFlip);
REG_FUNC(cellGcmSys, cellGcmSetQueueHandler);
REG_FUNC(cellGcmSys, cellGcmSetSecondVFrequency);
REG_FUNC(cellGcmSys, cellGcmSetSecondVHandler);
REG_FUNC(cellGcmSys, cellGcmSetTileInfo);
REG_FUNC(cellGcmSys, cellGcmSetUserHandler);
REG_FUNC(cellGcmSys, cellGcmSetUserCommand); //
REG_FUNC(cellGcmSys, cellGcmSetVBlankFrequency);
REG_FUNC(cellGcmSys, cellGcmSetVBlankHandler);
REG_FUNC(cellGcmSys, cellGcmSetWaitFlip); //
REG_FUNC(cellGcmSys, cellGcmSetWaitFlipUnsafe); //
REG_FUNC(cellGcmSys, cellGcmSetZcull);
REG_FUNC(cellGcmSys, cellGcmSortRemapEaIoAddress);
REG_FUNC(cellGcmSys, cellGcmUnbindTile);
REG_FUNC(cellGcmSys, cellGcmUnbindZcull);
REG_FUNC(cellGcmSys, cellGcmGetTileInfo);
REG_FUNC(cellGcmSys, cellGcmGetZcullInfo);
REG_FUNC(cellGcmSys, cellGcmGetDisplayInfo);
REG_FUNC(cellGcmSys, cellGcmGetCurrentDisplayBufferId);
REG_FUNC(cellGcmSys, cellGcmSetInvalidateTile);
REG_FUNC(cellGcmSys, cellGcmTerminate);
// Memory Mapping
REG_FUNC(cellGcmSys, cellGcmAddressToOffset);
REG_FUNC(cellGcmSys, cellGcmGetMaxIoMapSize);
REG_FUNC(cellGcmSys, cellGcmGetOffsetTable);
REG_FUNC(cellGcmSys, cellGcmIoOffsetToAddress);
REG_FUNC(cellGcmSys, cellGcmMapEaIoAddress);
REG_FUNC(cellGcmSys, cellGcmMapEaIoAddressWithFlags);
REG_FUNC(cellGcmSys, cellGcmMapLocalMemory);
REG_FUNC(cellGcmSys, cellGcmMapMainMemory);
REG_FUNC(cellGcmSys, cellGcmReserveIoMapSize);
REG_FUNC(cellGcmSys, cellGcmUnmapEaIoAddress);
REG_FUNC(cellGcmSys, cellGcmUnmapIoAddress);
REG_FUNC(cellGcmSys, cellGcmUnreserveIoMapSize);
// Cursor
REG_FUNC(cellGcmSys, cellGcmInitCursor);
REG_FUNC(cellGcmSys, cellGcmSetCursorEnable);
REG_FUNC(cellGcmSys, cellGcmSetCursorDisable);
REG_FUNC(cellGcmSys, cellGcmSetCursorImageOffset);
REG_FUNC(cellGcmSys, cellGcmSetCursorPosition);
REG_FUNC(cellGcmSys, cellGcmUpdateCursor);
// Functions for Maintaining Compatibility
REG_FUNC(cellGcmSys, cellGcmSetDefaultCommandBuffer);
REG_FUNC(cellGcmSys, cellGcmSetDefaultCommandBufferAndSegmentWordSize);
// Other
REG_FUNC(cellGcmSys, _cellGcmSetFlipCommand);
REG_FUNC(cellGcmSys, _cellGcmSetFlipCommand2);
REG_FUNC(cellGcmSys, _cellGcmSetFlipCommandWithWaitLabel);
REG_FUNC(cellGcmSys, cellGcmSetTile);
REG_FUNC(cellGcmSys, _cellGcmFunc2);
REG_FUNC(cellGcmSys, _cellGcmFunc3);
REG_FUNC(cellGcmSys, _cellGcmFunc4);
REG_FUNC(cellGcmSys, _cellGcmFunc13);
REG_FUNC(cellGcmSys, _cellGcmFunc38);
// GPAD
REG_FUNC(cellGcmSys, cellGcmGpadGetStatus);
REG_FUNC(cellGcmSys, cellGcmGpadNotifyCaptureSurface);
REG_FUNC(cellGcmSys, cellGcmGpadCaptureSnapshot);
// Special
REG_HIDDEN_FUNC(cellGcmCallback);
});
| 44,675
|
C++
|
.cpp
| 1,291
| 32.488768
| 212
| 0.728696
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| false
| false
|
5,304
|
cellRudp.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/cellRudp.cpp
|
#include "stdafx.h"
#include "Emu/IdManager.h"
#include "Emu/Cell/PPUModule.h"
#include "cellRudp.h"
LOG_CHANNEL(cellRudp);
template <>
void fmt_class_string<CellRudpError>::format(std::string& out, u64 arg)
{
format_enum(out, arg, [](auto error)
{
switch (error)
{
STR_CASE(CELL_RUDP_ERROR_NOT_INITIALIZED);
STR_CASE(CELL_RUDP_ERROR_ALREADY_INITIALIZED);
STR_CASE(CELL_RUDP_ERROR_INVALID_CONTEXT_ID);
STR_CASE(CELL_RUDP_ERROR_INVALID_ARGUMENT);
STR_CASE(CELL_RUDP_ERROR_INVALID_OPTION);
STR_CASE(CELL_RUDP_ERROR_INVALID_MUXMODE);
STR_CASE(CELL_RUDP_ERROR_MEMORY);
STR_CASE(CELL_RUDP_ERROR_INTERNAL);
STR_CASE(CELL_RUDP_ERROR_CONN_RESET);
STR_CASE(CELL_RUDP_ERROR_CONN_REFUSED);
STR_CASE(CELL_RUDP_ERROR_CONN_TIMEOUT);
STR_CASE(CELL_RUDP_ERROR_CONN_VERSION_MISMATCH);
STR_CASE(CELL_RUDP_ERROR_CONN_TRANSPORT_TYPE_MISMATCH);
STR_CASE(CELL_RUDP_ERROR_QUALITY_LEVEL_MISMATCH);
STR_CASE(CELL_RUDP_ERROR_THREAD);
STR_CASE(CELL_RUDP_ERROR_THREAD_IN_USE);
STR_CASE(CELL_RUDP_ERROR_NOT_ACCEPTABLE);
STR_CASE(CELL_RUDP_ERROR_MSG_TOO_LARGE);
STR_CASE(CELL_RUDP_ERROR_NOT_BOUND);
STR_CASE(CELL_RUDP_ERROR_CANCELLED);
STR_CASE(CELL_RUDP_ERROR_INVALID_VPORT);
STR_CASE(CELL_RUDP_ERROR_WOULDBLOCK);
STR_CASE(CELL_RUDP_ERROR_VPORT_IN_USE);
STR_CASE(CELL_RUDP_ERROR_VPORT_EXHAUSTED);
STR_CASE(CELL_RUDP_ERROR_INVALID_SOCKET);
STR_CASE(CELL_RUDP_ERROR_BUFFER_TOO_SMALL);
STR_CASE(CELL_RUDP_ERROR_MSG_MALFORMED);
STR_CASE(CELL_RUDP_ERROR_ADDR_IN_USE);
STR_CASE(CELL_RUDP_ERROR_ALREADY_BOUND);
STR_CASE(CELL_RUDP_ERROR_ALREADY_EXISTS);
STR_CASE(CELL_RUDP_ERROR_INVALID_POLL_ID);
STR_CASE(CELL_RUDP_ERROR_TOO_MANY_CONTEXTS);
STR_CASE(CELL_RUDP_ERROR_IN_PROGRESS);
STR_CASE(CELL_RUDP_ERROR_NO_EVENT_HANDLER);
STR_CASE(CELL_RUDP_ERROR_PAYLOAD_TOO_LARGE);
STR_CASE(CELL_RUDP_ERROR_END_OF_DATA);
STR_CASE(CELL_RUDP_ERROR_ALREADY_ESTABLISHED);
STR_CASE(CELL_RUDP_ERROR_KEEP_ALIVE_FAILURE);
}
return unknown;
});
}
struct rudp_info
{
// allocator functions
std::function<vm::ptr<void>(ppu_thread& ppu, u32 size)> malloc;
std::function<void(ppu_thread& ppu, vm::ptr<void> ptr)> free;
// event handler function
vm::ptr<CellRudpEventHandler> handler = vm::null;
vm::ptr<void> handler_arg{};
shared_mutex mutex;
};
error_code cellRudpInit(vm::ptr<CellRudpAllocator> allocator)
{
cellRudp.warning("cellRudpInit(allocator=*0x%x)", allocator);
auto& rudp = g_fxo->get<rudp_info>();
if (rudp.malloc)
{
return CELL_RUDP_ERROR_ALREADY_INITIALIZED;
}
if (allocator)
{
rudp.malloc = allocator->app_malloc;
rudp.free = allocator->app_free;
}
else
{
rudp.malloc = [](ppu_thread&, u32 size)
{
return vm::ptr<void>::make(vm::alloc(size, vm::main));
};
rudp.free = [](ppu_thread&, vm::ptr<void> ptr)
{
if (!vm::dealloc(ptr.addr(), vm::main))
{
fmt::throw_exception("Memory deallocation failed (ptr=0x%x)", ptr);
}
};
}
return CELL_OK;
}
error_code cellRudpEnd()
{
cellRudp.warning("cellRudpEnd()");
auto& rudp = g_fxo->get<rudp_info>();
if (!rudp.malloc)
{
return CELL_RUDP_ERROR_NOT_INITIALIZED;
}
rudp.malloc = nullptr;
rudp.free = nullptr;
rudp.handler = vm::null;
return CELL_OK;
}
error_code cellRudpEnableInternalIOThread()
{
UNIMPLEMENTED_FUNC(cellRudp);
return CELL_OK;
}
error_code cellRudpSetEventHandler(vm::ptr<CellRudpEventHandler> handler, vm::ptr<void> arg)
{
cellRudp.todo("cellRudpSetEventHandler(handler=*0x%x, arg=*0x%x)", handler, arg);
auto& rudp = g_fxo->get<rudp_info>();
if (!rudp.malloc)
{
return CELL_RUDP_ERROR_NOT_INITIALIZED;
}
rudp.handler = handler;
rudp.handler_arg = arg;
return CELL_OK;
}
error_code cellRudpSetMaxSegmentSize(u16 mss)
{
cellRudp.todo("cellRudpSetMaxSegmentSize(mss=%d)", mss);
return CELL_OK;
}
error_code cellRudpGetMaxSegmentSize()
{
UNIMPLEMENTED_FUNC(cellRudp);
return CELL_OK;
}
error_code cellRudpCreateContext()
{
UNIMPLEMENTED_FUNC(cellRudp);
return CELL_OK;
}
error_code cellRudpSetOption()
{
UNIMPLEMENTED_FUNC(cellRudp);
return CELL_OK;
}
error_code cellRudpGetOption()
{
UNIMPLEMENTED_FUNC(cellRudp);
return CELL_OK;
}
error_code cellRudpGetContextStatus()
{
UNIMPLEMENTED_FUNC(cellRudp);
return CELL_OK;
}
error_code cellRudpGetStatus()
{
UNIMPLEMENTED_FUNC(cellRudp);
return CELL_OK;
}
error_code cellRudpGetLocalInfo()
{
UNIMPLEMENTED_FUNC(cellRudp);
return CELL_OK;
}
error_code cellRudpGetRemoteInfo()
{
UNIMPLEMENTED_FUNC(cellRudp);
return CELL_OK;
}
error_code cellRudpAccept()
{
UNIMPLEMENTED_FUNC(cellRudp);
return CELL_OK;
}
error_code cellRudpBind()
{
UNIMPLEMENTED_FUNC(cellRudp);
return CELL_OK;
}
error_code cellRudpListen()
{
UNIMPLEMENTED_FUNC(cellRudp);
return CELL_OK;
}
error_code cellRudpInitiate()
{
UNIMPLEMENTED_FUNC(cellRudp);
return CELL_OK;
}
error_code cellRudpActivate()
{
UNIMPLEMENTED_FUNC(cellRudp);
return CELL_OK;
}
error_code cellRudpTerminate()
{
UNIMPLEMENTED_FUNC(cellRudp);
return CELL_OK;
}
error_code cellRudpRead()
{
UNIMPLEMENTED_FUNC(cellRudp);
return CELL_OK;
}
error_code cellRudpWrite()
{
UNIMPLEMENTED_FUNC(cellRudp);
return CELL_OK;
}
error_code cellRudpGetSizeReadable()
{
UNIMPLEMENTED_FUNC(cellRudp);
return CELL_OK;
}
error_code cellRudpGetSizeWritable()
{
UNIMPLEMENTED_FUNC(cellRudp);
return CELL_OK;
}
error_code cellRudpFlush()
{
UNIMPLEMENTED_FUNC(cellRudp);
return CELL_OK;
}
error_code cellRudpPollCreate()
{
UNIMPLEMENTED_FUNC(cellRudp);
return CELL_OK;
}
error_code cellRudpPollDestroy()
{
UNIMPLEMENTED_FUNC(cellRudp);
return CELL_OK;
}
error_code cellRudpPollControl()
{
UNIMPLEMENTED_FUNC(cellRudp);
return CELL_OK;
}
error_code cellRudpPollWait()
{
UNIMPLEMENTED_FUNC(cellRudp);
return CELL_OK;
}
error_code cellRudpPollCancel()
{
UNIMPLEMENTED_FUNC(cellRudp);
return CELL_OK;
}
error_code cellRudpNetReceived()
{
UNIMPLEMENTED_FUNC(cellRudp);
return CELL_OK;
}
error_code cellRudpProcessEvents()
{
UNIMPLEMENTED_FUNC(cellRudp);
return CELL_OK;
}
DECLARE(ppu_module_manager::cellRudp)("cellRudp", []()
{
REG_FUNC(cellRudp, cellRudpInit);
REG_FUNC(cellRudp, cellRudpEnd);
REG_FUNC(cellRudp, cellRudpEnableInternalIOThread);
REG_FUNC(cellRudp, cellRudpSetEventHandler);
REG_FUNC(cellRudp, cellRudpSetMaxSegmentSize);
REG_FUNC(cellRudp, cellRudpGetMaxSegmentSize);
REG_FUNC(cellRudp, cellRudpCreateContext);
REG_FUNC(cellRudp, cellRudpSetOption);
REG_FUNC(cellRudp, cellRudpGetOption);
REG_FUNC(cellRudp, cellRudpGetContextStatus);
REG_FUNC(cellRudp, cellRudpGetStatus);
REG_FUNC(cellRudp, cellRudpGetLocalInfo);
REG_FUNC(cellRudp, cellRudpGetRemoteInfo);
REG_FUNC(cellRudp, cellRudpAccept);
REG_FUNC(cellRudp, cellRudpBind);
REG_FUNC(cellRudp, cellRudpListen);
REG_FUNC(cellRudp, cellRudpInitiate);
REG_FUNC(cellRudp, cellRudpActivate);
REG_FUNC(cellRudp, cellRudpTerminate);
REG_FUNC(cellRudp, cellRudpRead);
REG_FUNC(cellRudp, cellRudpWrite);
REG_FUNC(cellRudp, cellRudpGetSizeReadable);
REG_FUNC(cellRudp, cellRudpGetSizeWritable);
REG_FUNC(cellRudp, cellRudpFlush);
REG_FUNC(cellRudp, cellRudpPollCreate);
REG_FUNC(cellRudp, cellRudpPollDestroy);
REG_FUNC(cellRudp, cellRudpPollControl);
REG_FUNC(cellRudp, cellRudpPollWait);
REG_FUNC(cellRudp, cellRudpPollCancel);
REG_FUNC(cellRudp, cellRudpNetReceived);
REG_FUNC(cellRudp, cellRudpProcessEvents);
});
| 7,385
|
C++
|
.cpp
| 292
| 23.113014
| 92
| 0.76887
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| true
| false
| false
| true
| false
| false
|
5,305
|
sys_mempool.cpp
|
RPCS3_rpcs3/rpcs3/Emu/Cell/Modules/sys_mempool.cpp
|
#include "stdafx.h"
#include "Utilities/StrUtil.h"
#include "Emu/Cell/PPUModule.h"
#include "Emu/Cell/lv2/sys_mutex.h"
#include "Emu/Cell/lv2/sys_cond.h"
#include "sysPrxForUser.h"
LOG_CHANNEL(sysPrxForUser);
using sys_mempool_t = u32;
struct memory_pool_t
{
static const u32 id_base = 1;
static const u32 id_step = 1;
static const u32 id_count = 1023;
SAVESTATE_INIT_POS(21);
u32 mutexid;
u32 condid;
vm::ptr<void> chunk;
u64 chunk_size;
u64 block_size;
u64 ralignment;
std::vector<vm::ptr<void>> free_blocks;
};
error_code sys_mempool_create(ppu_thread& ppu, vm::ptr<sys_mempool_t> mempool, vm::ptr<void> chunk, const u64 chunk_size, const u64 block_size, const u64 ralignment)
{
sysPrxForUser.warning("sys_mempool_create(mempool=*0x%x, chunk=*0x%x, chunk_size=%d, block_size=%d, ralignment=%d)", mempool, chunk, chunk_size, block_size, ralignment);
if (block_size > chunk_size)
{
return CELL_EINVAL;
}
u64 alignment = ralignment;
if (ralignment == 0 || ralignment == 2)
{
alignment = 4;
}
// Check if alignment is power of two
if ((alignment & (alignment - 1)) != 0)
{
return CELL_EINVAL;
}
// Test chunk address aligment
if (!chunk.aligned(8))
{
return CELL_EINVAL;
}
auto id = idm::make<memory_pool_t>();
*mempool = id;
auto memory_pool = idm::get<memory_pool_t>(id);
memory_pool->chunk = chunk;
memory_pool->chunk_size = chunk_size;
memory_pool->block_size = block_size;
memory_pool->ralignment = alignment;
// TODO: check blocks alignment wrt ralignment
u64 num_blocks = chunk_size / block_size;
memory_pool->free_blocks.resize(num_blocks);
for (u32 i = 0; i < num_blocks; ++i)
{
memory_pool->free_blocks[i] = vm::ptr<void>::make(chunk.addr() + i * static_cast<u32>(block_size));
}
// Create synchronization variables
vm::var<u32> mutexid;
vm::var<sys_mutex_attribute_t> attr;
attr->protocol = SYS_SYNC_PRIORITY;
attr->recursive = SYS_SYNC_NOT_RECURSIVE;
attr->pshared = SYS_SYNC_NOT_PROCESS_SHARED;
attr->adaptive = SYS_SYNC_NOT_ADAPTIVE;
attr->ipc_key = 0; // No idea what this is
attr->flags = 0; // Also no idea what this is.
strcpy_trunc(attr->name, "mp_m" + std::to_string(*mempool));
error_code ret = sys_mutex_create(ppu, mutexid, attr);
if (ret != 0)
{ // TODO: Better exception handling.
fmt::throw_exception("mempool %x failed to create mutex", mempool);
}
memory_pool->mutexid = *mutexid;
vm::var<u32> condid;
vm::var<sys_cond_attribute_t> condAttr;
condAttr->pshared = SYS_SYNC_NOT_PROCESS_SHARED;
condAttr->flags = 0; // No idea what this is
condAttr->ipc_key = 0; // Also no idea what this is
strcpy_trunc(condAttr->name, "mp_c" + std::to_string(*mempool));
ret = sys_cond_create(ppu, condid, *mutexid, condAttr);
if (ret != CELL_OK)
{ // TODO: Better exception handling.
fmt::throw_exception("mempool %x failed to create condition variable", mempool);
}
memory_pool->condid = *condid;
return CELL_OK;
}
void sys_mempool_destroy(ppu_thread& ppu, sys_mempool_t mempool)
{
sysPrxForUser.warning("sys_mempool_destroy(mempool=%d)", mempool);
auto memory_pool = idm::get<memory_pool_t>(mempool);
if (memory_pool)
{
u32 condid = memory_pool->condid;
u32 mutexid = memory_pool->mutexid;
sys_mutex_lock(ppu, memory_pool->mutexid, 0);
idm::remove_verify<memory_pool_t>(mempool, std::move(memory_pool));
sys_mutex_unlock(ppu, mutexid);
sys_mutex_destroy(ppu, mutexid);
sys_cond_destroy(ppu, condid);
}
else
{
sysPrxForUser.error("Trying to destroy an already destroyed mempool=%d", mempool);
}
}
error_code sys_mempool_free_block(ppu_thread& ppu, sys_mempool_t mempool, vm::ptr<void> block)
{
sysPrxForUser.warning("sys_mempool_free_block(mempool=%d, block=*0x%x)", mempool, block);
auto memory_pool = idm::get<memory_pool_t>(mempool);
if (!memory_pool)
{
return CELL_EINVAL;
}
sys_mutex_lock(ppu, memory_pool->mutexid, 0);
// Cannot free a block not belonging to this memory pool
if (block.addr() > memory_pool->chunk.addr() + memory_pool->chunk_size)
{
sys_mutex_unlock(ppu, memory_pool->mutexid);
return CELL_EINVAL;
}
memory_pool->free_blocks.push_back(block);
sys_cond_signal(ppu, memory_pool->condid);
sys_mutex_unlock(ppu, memory_pool->mutexid);
return CELL_OK;
}
u64 sys_mempool_get_count(ppu_thread& ppu, sys_mempool_t mempool)
{
sysPrxForUser.warning("sys_mempool_get_count(mempool=%d)", mempool);
auto memory_pool = idm::get<memory_pool_t>(mempool);
if (!memory_pool)
{
return CELL_EINVAL;
}
sys_mutex_lock(ppu, memory_pool->mutexid, 0);
u64 ret = memory_pool->free_blocks.size();
sys_mutex_unlock(ppu, memory_pool->mutexid);
return ret;
}
vm::ptr<void> sys_mempool_allocate_block(ppu_thread& ppu, sys_mempool_t mempool)
{
sysPrxForUser.warning("sys_mempool_allocate_block(mempool=%d)", mempool);
auto memory_pool = idm::get<memory_pool_t>(mempool);
if (!memory_pool)
{ // if the memory pool gets deleted-- is null, clearly it's impossible to allocate memory.
return vm::null;
}
sys_mutex_lock(ppu, memory_pool->mutexid, 0);
while (memory_pool->free_blocks.empty()) // while is to guard against spurious wakeups
{
sys_cond_wait(ppu, memory_pool->condid, 0);
memory_pool = idm::get<memory_pool_t>(mempool);
if (!memory_pool) // in case spurious wake up was from delete, don't die by accessing a freed pool.
{ // No need to unlock as if the pool is freed, the lock was freed as well.
return vm::null;
}
}
auto block_ptr = memory_pool->free_blocks.back();
memory_pool->free_blocks.pop_back();
sys_mutex_unlock(ppu, memory_pool->mutexid);
return block_ptr;
}
vm::ptr<void> sys_mempool_try_allocate_block(ppu_thread& ppu, sys_mempool_t mempool)
{
sysPrxForUser.warning("sys_mempool_try_allocate_block(mempool=%d)", mempool);
auto memory_pool = idm::get<memory_pool_t>(mempool);
if (!memory_pool || memory_pool->free_blocks.empty())
{
return vm::null;
}
sys_mutex_lock(ppu, memory_pool->mutexid, 0);
auto block_ptr = memory_pool->free_blocks.back();
memory_pool->free_blocks.pop_back();
sys_mutex_unlock(ppu, memory_pool->mutexid);
return block_ptr;
}
void sysPrxForUser_sys_mempool_init()
{
REG_FUNC(sysPrxForUser, sys_mempool_allocate_block);
REG_FUNC(sysPrxForUser, sys_mempool_create);
REG_FUNC(sysPrxForUser, sys_mempool_destroy);
REG_FUNC(sysPrxForUser, sys_mempool_free_block);
REG_FUNC(sysPrxForUser, sys_mempool_get_count);
REG_FUNC(sysPrxForUser, sys_mempool_try_allocate_block);
}
| 6,436
|
C++
|
.cpp
| 186
| 32.397849
| 170
| 0.723582
|
RPCS3/rpcs3
| 15,204
| 1,895
| 1,021
|
GPL-2.0
|
9/20/2024, 9:26:25 PM (Europe/Amsterdam)
| false
| false
| false
| false
| false
| true
| false
| false
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.