More memory access cleanup

This commit is contained in:
Henrik Rydgård committed 2026-08-11 10:28:48 +02:00
1 parent d8edeb7649
commit 138f02217c
3 files changed
+32 -27

No files matched your search

+11 -11
View File
@@ -2031,8 +2031,8 @@ static u32 sceIoDevctl(const char *name, int cmd, u32 argAddr, int argLen, u32 o
switch (cmd) {
case EMULATOR_DEVCTL__GET_HAS_DISPLAY:
if (Memory::IsValidAddress(outPtr))
Memory::Write_U32(PSP_CoreParameter().headLess ? 0 : 1, outPtr);
if (Memory::IsValidRange(outPtr, 4))
Memory::WriteUnchecked_U32(PSP_CoreParameter().headLess ? 0 : 1, outPtr);
return hleLogDebug(Log::sceIo, 0);
case EMULATOR_DEVCTL__SEND_OUTPUT:
if (Memory::IsValidRange(argAddr, argLen)) {
@@ -2044,8 +2044,8 @@ static u32 sceIoDevctl(const char *name, int cmd, u32 argAddr, int argLen, u32 o
}
return hleNoLog(0);
case EMULATOR_DEVCTL__IS_EMULATOR:
if (Memory::IsValidAddress(outPtr))
Memory::Write_U32(1, outPtr);
if (Memory::IsValidRange(outPtr, 4))
Memory::WriteUnchecked_U32(1, outPtr);
return hleLogDebug(Log::sceIo, 0);
case EMULATOR_DEVCTL__VERIFY_STATE:
// Note that this is async, and makes sure the save state matches up.
@@ -2071,7 +2071,7 @@ static u32 sceIoDevctl(const char *name, int cmd, u32 argAddr, int argLen, u32 o
return hleLogDebug(Log::sceIo, 0);
case EMULATOR_DEVCTL__GET_ASPECT_RATIO:
// NOTE: This currently only works correctly in landscape mode!
if (Memory::IsValidAddress(outPtr)) {
if (Memory::IsValidRange(outPtr, 4)) {
// TODO: Share code with CalculateDisplayOutputRect to take a few more things into account.
// I have a planned further refactoring.
float ar;
@@ -2080,26 +2080,26 @@ static u32 sceIoDevctl(const char *name, int cmd, u32 argAddr, int argLen, u32 o
} else {
ar = g_Config.displayLayoutLandscape.fDisplayAspectRatio * (480.0f / 272.0f);
}
Memory::Write_Float(ar, outPtr);
Memory::WriteUnchecked_Float(ar, outPtr);
}
return hleLogDebug(Log::sceIo, 0);
case EMULATOR_DEVCTL__GET_SCALE:
// NOTE: This currently only works correctly in landscape mode!
if (Memory::IsValidAddress(outPtr)) {
if (Memory::IsValidRange(outPtr, 4)) {
// TODO: Maybe do something more sophisticated taking the longest side and screen rotation
// into account, etc.
float scale = (float)g_display.dp_xres * g_Config.displayLayoutLandscape.fDisplayScale / 480.0f;
Memory::Write_Float(scale, outPtr);
Memory::WriteUnchecked_Float(scale, outPtr);
}
return hleLogDebug(Log::sceIo, 0);
case EMULATOR_DEVCTL__GET_AXIS:
if (Memory::IsValidAddress(outPtr) && (argAddr >= 0 && argAddr < JOYSTICK_AXIS_MAX)) {
Memory::Write_Float(HLEPlugins::PluginDataAxis[argAddr], outPtr);
if (Memory::IsValidRange(outPtr, 4) && (argAddr >= 0 && argAddr < JOYSTICK_AXIS_MAX)) {
Memory::WriteUnchecked_Float(HLEPlugins::PluginDataAxis[argAddr], outPtr);
}
return hleLogDebug(Log::sceIo, 0);
case EMULATOR_DEVCTL__GET_VKEY:
if (Memory::IsValidAddress(outPtr) && (argAddr >= 0 && argAddr < NKCODE_MAX)) {
Memory::Write_U8(HLEPlugins::GetKey(argAddr), outPtr);
Memory::WriteUnchecked_U8(HLEPlugins::GetKey(argAddr), outPtr);
}
return hleLogDebug(Log::sceIo, 0);
}
-7
View File
@@ -247,13 +247,6 @@ void Write_U16(const u16 data, const u32 address);
void Write_U32(const u32 data, const u32 address);
void Write_U64(const u64 data, const u32 address);
inline void Write_Float(float f, u32 address)
{
u32 u;
memcpy(&u, &f, sizeof(float));
Write_U32(u, address);
}
u8* GetPointerWrite(const u32 address);
const u8* GetPointer(const u32 address);
+21 -9
View File
@@ -84,29 +84,41 @@ static void DrawBuiltInEditPopup(const BuiltIn &builtIn, const u32 address) {
case BuiltInType::Bool:
case BuiltInType::Char:
case BuiltInType::Int8:
Memory::Write_U8(0, address);
if (Memory::IsValidAddress(address)) {
Memory::WriteUnchecked_U8(0, address);
}
break;
case BuiltInType::Int16:
Memory::Write_U16(0, address);
if (Memory::IsValidRange(address, 2)) {
Memory::WriteUnchecked_U16(0, address);
}
break;
case BuiltInType::Int32:
Memory::Write_U32(0, address);
if (Memory::IsValidRange(address, 4)) {
Memory::WriteUnchecked_U32(0, address);
}
break;
case BuiltInType::Int64:
Memory::Write_U64(0, address);
if (Memory::IsValidRange(address, 8)) {
Memory::WriteUnchecked_U64(0, address);
}
break;
case BuiltInType::Float:
Memory::Write_Float(0, address);
if (Memory::IsValidRange(address, 4)) {
Memory::WriteUnchecked_Float(0, address);
}
break;
default:
break;
}
}
void *data = Memory::GetPointerWriteUnchecked(address);
if (builtIn.hexFormat) {
ImGui::DragScalar("Value (hex)", builtIn.imGuiType, data, 0.2f, nullptr, nullptr, builtIn.hexFormat);
if (Memory::IsValidRange(address, 8)) {
void *data = Memory::GetPointerWriteUnchecked(address);
if (builtIn.hexFormat) {
ImGui::DragScalar("Value (hex)", builtIn.imGuiType, data, 0.2f, nullptr, nullptr, builtIn.hexFormat);
}
ImGui::DragScalar("Value", builtIn.imGuiType, data, 0.2f);
}
ImGui::DragScalar("Value", builtIn.imGuiType, data, 0.2f);
ImGui::EndPopup();
}
}