Skip to content

Commit

Permalink
Implement at32() util
Browse files Browse the repository at this point in the history
Works like .at() but uses source location for "exception".
  • Loading branch information
Nekotekina committed Sep 26, 2022
1 parent 2655255 commit 6ff6a49
Show file tree
Hide file tree
Showing 62 changed files with 474 additions and 454 deletions.
8 changes: 4 additions & 4 deletions Utilities/bin_patch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ std::basic_string<u32> patch_engine::apply(const std::string& name, u8* dst, u32
}

std::basic_string<u32> applied_total;
const auto& container = m_map.at(name);
const auto& container = ::at32(m_map, name);
const auto& serial = Emu.GetTitleID();
const auto& app_version = Emu.GetAppVersion();

Expand Down Expand Up @@ -975,7 +975,7 @@ std::basic_string<u32> patch_engine::apply(const std::string& name, u8* dst, u32
continue;
}

const auto& app_versions = serials.at(found_serial);
const auto& app_versions = ::at32(serials, found_serial);
std::string found_app_version;

if (app_versions.find(app_version) != app_versions.end())
Expand All @@ -988,7 +988,7 @@ std::basic_string<u32> patch_engine::apply(const std::string& name, u8* dst, u32
is_all_versions = true;
}

if (!found_app_version.empty() && app_versions.at(found_app_version))
if (!found_app_version.empty() && ::at32(app_versions, found_app_version))
{
// This patch is enabled
if (is_all_serials)
Expand Down Expand Up @@ -1073,7 +1073,7 @@ void patch_engine::unload(const std::string& name)
return;
}

const auto& container = m_map.at(name);
const auto& container = ::at32(m_map, name);

for (const auto& [description, patch] : container.patch_info_map)
{
Expand Down
4 changes: 2 additions & 2 deletions rpcs3/Emu/Audio/AudioBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ std::pair<AudioChannelCnt, AudioChannelCnt> AudioBackend::get_channel_count_and_
audio_out_configuration& audio_out_cfg = g_fxo->get<audio_out_configuration>();
std::lock_guard lock(audio_out_cfg.mtx);
ensure(device_index < audio_out_cfg.out.size());
const audio_out_configuration::audio_out& out = audio_out_cfg.out.at(device_index);
const audio_out_configuration::audio_out& out = ::at32(audio_out_cfg.out, device_index);
return out.get_channel_count_and_downmixer();
}

Expand All @@ -120,7 +120,7 @@ AudioChannelCnt AudioBackend::get_max_channel_count(u32 device_index)
audio_out_configuration& audio_out_cfg = g_fxo->get<audio_out_configuration>();
std::lock_guard lock(audio_out_cfg.mtx);
ensure(device_index < audio_out_cfg.out.size());
const audio_out_configuration::audio_out& out = audio_out_cfg.out.at(device_index);
const audio_out_configuration::audio_out& out = ::at32(audio_out_cfg.out, device_index);

AudioChannelCnt count = AudioChannelCnt::STEREO;

Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/Cell/Modules/StaticHLE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ bool statichle_handler::check_against_patterns(vm::cptr<u8>& data, u32 size, u32
return false;
}

const auto sfunc = &smodule->functions.at(pat.fnid);
const auto sfunc = &::at32(smodule->functions, pat.fnid);
const u32 target = g_fxo->get<ppu_function_manager>().func_addr(sfunc->index) + 4;

// write stub
Expand Down
34 changes: 17 additions & 17 deletions rpcs3/Emu/Cell/Modules/cellAudioOut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ void fmt_class_string<CellAudioOutError>::format(std::string& out, u64 arg)

audio_out_configuration::audio_out_configuration()
{
audio_out& primary_output = out.at(CELL_AUDIO_OUT_PRIMARY);
audio_out& secondary_output = out.at(CELL_AUDIO_OUT_SECONDARY);
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;
Expand All @@ -58,8 +58,8 @@ audio_out_configuration::audio_out_configuration()

const auto add_sound_mode = [&](u32 index, u8 type, u8 channel, u8 fs, u32 layout, bool supported)
{
audio_out& output = out.at(index);
bool& selected = initial_mode_selected.at(index);
audio_out& output = ::at32(out, index);
bool& selected = ::at32(initial_mode_selected, index);

CellAudioOutSoundMode mode{};
mode.type = type;
Expand Down Expand Up @@ -103,7 +103,7 @@ audio_out_configuration::audio_out_configuration()
{
// 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);

Expand Down Expand Up @@ -161,8 +161,8 @@ audio_out_configuration::audio_out_configuration()
// 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() && initial_mode_selected.at(CELL_AUDIO_OUT_PRIMARY));
ensure(!secondary_modes.empty() && initial_mode_selected.at(CELL_AUDIO_OUT_SECONDARY));
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)
{
Expand Down Expand Up @@ -238,7 +238,7 @@ error_code cellAudioOutGetSoundAvailability(u32 audioOut, u32 type, u32 fs, u32
// 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 = cfg.out.at(audioOut);
const audio_out_configuration::audio_out& out = ::at32(cfg.out, audioOut);

for (const CellAudioOutSoundMode& mode : out.sound_modes)
{
Expand All @@ -265,7 +265,7 @@ error_code cellAudioOutGetSoundAvailability2(u32 audioOut, u32 type, u32 fs, u32
// 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 = cfg.out.at(audioOut);
const audio_out_configuration::audio_out& out = ::at32(cfg.out, audioOut);

for (const CellAudioOutSoundMode& mode : out.sound_modes)
{
Expand Down Expand Up @@ -319,7 +319,7 @@ error_code cellAudioOutGetState(u32 audioOut, u32 deviceIndex, vm::ptr<CellAudio
{
audio_out_configuration& cfg = g_fxo->get<audio_out_configuration>();
std::lock_guard lock(cfg.mtx);
const audio_out_configuration::audio_out& out = cfg.out.at(audioOut);
const audio_out_configuration::audio_out& out = ::at32(cfg.out, audioOut);

_state.state = out.state;
_state.encoder = out.encoder;
Expand Down Expand Up @@ -360,7 +360,7 @@ error_code cellAudioOutConfigure(u32 audioOut, vm::ptr<CellAudioOutConfiguration
{
std::lock_guard lock(cfg.mtx);

audio_out_configuration::audio_out& out = cfg.out.at(audioOut);
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.

Expand Down Expand Up @@ -406,15 +406,15 @@ error_code cellAudioOutConfigure(u32 audioOut, vm::ptr<CellAudioOutConfiguration
audio_out_configuration& cfg = g_fxo->get<audio_out_configuration>();
{
std::lock_guard lock(cfg.mtx);
cfg.out.at(audioOut).state = CELL_AUDIO_OUT_OUTPUT_STATE_DISABLED;
::at32(cfg.out, audioOut).state = CELL_AUDIO_OUT_OUTPUT_STATE_DISABLED;
}

audio::configure_audio(true);
audio::configure_rsxaudio();

{
std::lock_guard lock(cfg.mtx);
cfg.out.at(audioOut).state = CELL_AUDIO_OUT_OUTPUT_STATE_ENABLED;
::at32(cfg.out, audioOut).state = CELL_AUDIO_OUT_OUTPUT_STATE_ENABLED;
}
};

Expand Down Expand Up @@ -455,7 +455,7 @@ error_code cellAudioOutGetConfiguration(u32 audioOut, vm::ptr<CellAudioOutConfig
audio_out_configuration& cfg = g_fxo->get<audio_out_configuration>();
std::lock_guard lock(cfg.mtx);

const audio_out_configuration::audio_out& out = cfg.out.at(audioOut);
const audio_out_configuration::audio_out& out = ::at32(cfg.out, audioOut);

// Return the active config.
CellAudioOutConfiguration _config{};
Expand Down Expand Up @@ -516,7 +516,7 @@ error_code cellAudioOutGetDeviceInfo(u32 audioOut, u32 deviceIndex, vm::ptr<Cell
audio_out_configuration& cfg = g_fxo->get<audio_out_configuration>();
std::lock_guard lock(cfg.mtx);
ensure(audioOut < cfg.out.size());
const audio_out_configuration::audio_out& out = cfg.out.at(audioOut);
const audio_out_configuration::audio_out& out = ::at32(cfg.out, audioOut);
ensure(out.sound_modes.size() <= 16);

CellAudioOutDeviceInfo _info{};
Expand All @@ -528,7 +528,7 @@ error_code cellAudioOutGetDeviceInfo(u32 audioOut, u32 deviceIndex, vm::ptr<Cell

for (usz i = 0; i < out.sound_modes.size(); i++)
{
_info.availableModes[i] = out.sound_modes.at(i);
_info.availableModes[i] = ::at32(out.sound_modes, i);
}

*info = _info;
Expand Down Expand Up @@ -557,7 +557,7 @@ error_code cellAudioOutSetCopyControl(u32 audioOut, u32 control)
audio_out_configuration& cfg = g_fxo->get<audio_out_configuration>();
std::lock_guard lock(cfg.mtx);

cfg.out.at(audioOut).copy_control = control;
::at32(cfg.out, audioOut).copy_control = control;

return CELL_OK;
}
Expand Down
18 changes: 9 additions & 9 deletions rpcs3/Emu/Cell/Modules/cellGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,13 +418,13 @@ error_code cellHddGameCheck(ppu_thread& ppu, u32 version, vm::cptr<char> dirName
const psf::registry psf = psf::load_object(fs::file(local_dir +"/PARAM.SFO"));

// Some following fields may be zero in old FW 1.00 version PARAM.SFO
if (psf.contains("PARENTAL_LEVEL")) get->getParam.parentalLevel = psf.at("PARENTAL_LEVEL").as_integer();
if (psf.contains("ATTRIBUTE")) get->getParam.attribute = psf.at("ATTRIBUTE").as_integer();
if (psf.contains("RESOLUTION")) get->getParam.resolution = psf.at("RESOLUTION").as_integer();
if (psf.contains("SOUND_FORMAT")) get->getParam.soundFormat = psf.at("SOUND_FORMAT").as_integer();
if (psf.contains("TITLE")) strcpy_trunc(get->getParam.title, psf.at("TITLE").as_string());
if (psf.contains("APP_VER")) strcpy_trunc(get->getParam.dataVersion, psf.at("APP_VER").as_string());
if (psf.contains("TITLE_ID")) strcpy_trunc(get->getParam.titleId, psf.at("TITLE_ID").as_string());
if (psf.contains("PARENTAL_LEVEL")) get->getParam.parentalLevel = ::at32(psf, "PARENTAL_LEVEL").as_integer();
if (psf.contains("ATTRIBUTE")) get->getParam.attribute = ::at32(psf, "ATTRIBUTE").as_integer();
if (psf.contains("RESOLUTION")) get->getParam.resolution = ::at32(psf, "RESOLUTION").as_integer();
if (psf.contains("SOUND_FORMAT")) get->getParam.soundFormat = ::at32(psf, "SOUND_FORMAT").as_integer();
if (psf.contains("TITLE")) strcpy_trunc(get->getParam.title, ::at32(psf, "TITLE").as_string());
if (psf.contains("APP_VER")) strcpy_trunc(get->getParam.dataVersion, ::at32(psf, "APP_VER").as_string());
if (psf.contains("TITLE_ID")) strcpy_trunc(get->getParam.titleId, ::at32(psf, "TITLE_ID").as_string());

for (u32 i = 0; i < CELL_HDDGAME_SYSP_LANGUAGE_NUM; i++)
{
Expand Down Expand Up @@ -1710,8 +1710,8 @@ error_code cellDiscGameGetBootDiscInfo(vm::ptr<CellDiscGameSystemFileParam> getP

const psf::registry psf = psf::load_object(fs::file(vfs::get(dir + "/PARAM.SFO")));

if (psf.contains("PARENTAL_LEVEL")) getParam->parentalLevel = psf.at("PARENTAL_LEVEL").as_integer();
if (psf.contains("TITLE_ID")) strcpy_trunc(getParam->titleId, psf.at("TITLE_ID").as_string());
if (psf.contains("PARENTAL_LEVEL")) getParam->parentalLevel = ::at32(psf, "PARENTAL_LEVEL").as_integer();
if (psf.contains("TITLE_ID")) strcpy_trunc(getParam->titleId, ::at32(psf, "TITLE_ID").as_string());

return CELL_OK;
}
Expand Down
16 changes: 8 additions & 8 deletions rpcs3/Emu/Cell/Modules/cellGem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ struct gem_config_data
break;
}

gem_controller& controller = controllers.at(gem_num);
gem_controller& controller = ::at32(controllers, gem_num);
controller = {};
controller.sphere_rgb = gem_color::get_default_color(gem_num);

Expand Down Expand Up @@ -563,7 +563,7 @@ static void ds3_input_to_pad(const u32 port_no, be_t<u16>& digital_buttons, be_t
std::lock_guard lock(pad::g_pad_mutex);

const auto handler = pad::get_current_handler();
const auto& pad = handler->GetPads().at(port_no);
const auto& pad = ::at32(handler->GetPads(), port_no);

if (!(pad->m_port_status & CELL_PAD_STATUS_CONNECTED))
{
Expand Down Expand Up @@ -656,7 +656,7 @@ static void ds3_pos_to_gem_image_state(const u32 port_no, const gem_config::gem_
std::lock_guard lock(pad::g_pad_mutex);

const auto handler = pad::get_current_handler();
const auto& pad = handler->GetPads().at(port_no);
const auto& pad = ::at32(handler->GetPads(), port_no);

if (!(pad->m_port_status & CELL_PAD_STATUS_CONNECTED))
{
Expand All @@ -679,7 +679,7 @@ static void ds3_pos_to_gem_state(const u32 port_no, const gem_config::gem_contro
std::lock_guard lock(pad::g_pad_mutex);

const auto handler = pad::get_current_handler();
const auto& pad = handler->GetPads().at(port_no);
const auto& pad = ::at32(handler->GetPads(), port_no);

if (!(pad->m_port_status & CELL_PAD_STATUS_CONNECTED))
{
Expand Down Expand Up @@ -712,7 +712,7 @@ static void ds3_input_to_ext(const u32 port_no, const gem_config::gem_controller
std::lock_guard lock(pad::g_pad_mutex);

const auto handler = pad::get_current_handler();
const auto& pad = handler->GetPads().at(port_no);
const auto& pad = ::at32(handler->GetPads(), port_no);

if (!(pad->m_port_status & CELL_PAD_STATUS_CONNECTED))
{
Expand Down Expand Up @@ -769,7 +769,7 @@ static bool mouse_input_to_pad(const u32 mouse_no, be_t<u16>& digital_buttons, b
return false;
}

const auto& mouse_data = handler.GetMice().at(mouse_no);
const auto& mouse_data = ::at32(handler.GetMice(), mouse_no);
const auto is_pressed = [&mouse_data](MouseButtonCodes button) -> bool { return !!(mouse_data.buttons & button); };

digital_buttons = 0;
Expand Down Expand Up @@ -822,7 +822,7 @@ static void mouse_pos_to_gem_image_state(const u32 mouse_no, const gem_config::g
return;
}

const auto& mouse = handler.GetMice().at(mouse_no);
const auto& mouse = ::at32(handler.GetMice(), mouse_no);

pos_to_gem_image_state(mouse_no, controller, gem_image_state, mouse.x_pos, mouse.y_pos, mouse.x_max, mouse.y_max);
}
Expand All @@ -846,7 +846,7 @@ static void mouse_pos_to_gem_state(const u32 mouse_no, const gem_config::gem_con
return;
}

const auto& mouse = handler.GetMice().at(mouse_no);
const auto& mouse = ::at32(handler.GetMice(), mouse_no);

pos_to_gem_state(mouse_no, controller, gem_state, mouse.x_pos, mouse.y_pos, mouse.x_max, mouse.y_max);
}
Expand Down
Loading

0 comments on commit 6ff6a49

Please sign in to comment.