Merge pull request #12678 from JosJuice/no-getpointer-part-2

HW: Remove calls to GetPointer
This commit is contained in:
Admiral H. Curtiss 2024-04-04 21:43:57 +02:00 committed by GitHub
commit 4312840a4b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 36 additions and 40 deletions

View File

@ -150,14 +150,14 @@ struct EffectiveAddressSpaceAccessors : Accessors
return false; return false;
} }
u8* page_ptr = memory.GetPointer(*page_physical_address); std::size_t chunk_size = std::min<std::size_t>(0x1000 - offset, needle_size);
u8* page_ptr = memory.GetPointerForRange(*page_physical_address + offset, chunk_size);
if (page_ptr == nullptr) if (page_ptr == nullptr)
{ {
return false; return false;
} }
std::size_t chunk_size = std::min<std::size_t>(0x1000 - offset, needle_size); if (memcmp(needle_start, page_ptr, chunk_size) != 0)
if (memcmp(needle_start, page_ptr + offset, chunk_size) != 0)
{ {
return false; return false;
} }

View File

@ -430,7 +430,7 @@ void DSPManager::UpdateAudioDMA()
// external audio fifo in the emulator, to be mixed with the disc // external audio fifo in the emulator, to be mixed with the disc
// streaming output. // streaming output.
auto& memory = m_system.GetMemory(); auto& memory = m_system.GetMemory();
void* address = memory.GetPointer(m_audio_dma.current_source_address); void* address = memory.GetPointerForRange(m_audio_dma.current_source_address, 32);
AudioCommon::SendAIBuffer(m_system, reinterpret_cast<short*>(address), 8); AudioCommon::SendAIBuffer(m_system, reinterpret_cast<short*>(address), 8);
if (m_audio_dma.remaining_blocks_count != 0) if (m_audio_dma.remaining_blocks_count != 0)

View File

@ -190,8 +190,9 @@ void UCodeInterface::PrepareBootUCode(u32 mail)
if (Config::Get(Config::MAIN_DUMP_UCODE)) if (Config::Get(Config::MAIN_DUMP_UCODE))
{ {
DSP::DumpDSPCode(memory.GetPointer(m_next_ucode.iram_mram_addr), m_next_ucode.iram_size, const u8* pointer =
ector_crc); memory.GetPointerForRange(m_next_ucode.iram_mram_addr, m_next_ucode.iram_size);
DSP::DumpDSPCode(pointer, m_next_ucode.iram_size, ector_crc);
} }
DEBUG_LOG_FMT(DSPHLE, "PrepareBootUCode {:#010x}", ector_crc); DEBUG_LOG_FMT(DSPHLE, "PrepareBootUCode {:#010x}", ector_crc);

View File

@ -76,7 +76,7 @@ void CodeLoaded(DSPCore& dsp, u32 addr, size_t size)
{ {
auto& system = Core::System::GetInstance(); auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory(); auto& memory = system.GetMemory();
CodeLoaded(dsp, memory.GetPointer(addr), size); CodeLoaded(dsp, memory.GetPointerForRange(addr, size), size);
} }
void CodeLoaded(DSPCore& dsp, const u8* ptr, size_t size) void CodeLoaded(DSPCore& dsp, const u8* ptr, size_t size)

View File

@ -231,7 +231,7 @@ void CEXIETHERNET::DMAWrite(u32 addr, u32 size)
transfer.address == BBA_WRTXFIFOD) transfer.address == BBA_WRTXFIFOD)
{ {
auto& memory = m_system.GetMemory(); auto& memory = m_system.GetMemory();
DirectFIFOWrite(memory.GetPointer(addr), size); DirectFIFOWrite(memory.GetPointerForRange(addr, size), size);
} }
else else
{ {

View File

@ -525,7 +525,7 @@ void CEXIMemoryCard::DoState(PointerWrap& p)
void CEXIMemoryCard::DMARead(u32 addr, u32 size) void CEXIMemoryCard::DMARead(u32 addr, u32 size)
{ {
auto& memory = m_system.GetMemory(); auto& memory = m_system.GetMemory();
m_memory_card->Read(m_address, size, memory.GetPointer(addr)); m_memory_card->Read(m_address, size, memory.GetPointerForRange(addr, size));
if ((m_address + size) % Memcard::BLOCK_SIZE == 0) if ((m_address + size) % Memcard::BLOCK_SIZE == 0)
{ {
@ -543,7 +543,7 @@ void CEXIMemoryCard::DMARead(u32 addr, u32 size)
void CEXIMemoryCard::DMAWrite(u32 addr, u32 size) void CEXIMemoryCard::DMAWrite(u32 addr, u32 size)
{ {
auto& memory = m_system.GetMemory(); auto& memory = m_system.GetMemory();
m_memory_card->Write(m_address, size, memory.GetPointer(addr)); m_memory_card->Write(m_address, size, memory.GetPointerForRange(addr, size));
if (((m_address + size) % Memcard::BLOCK_SIZE) == 0) if (((m_address + size) % Memcard::BLOCK_SIZE) == 0)
{ {

View File

@ -127,7 +127,7 @@ void CEXIModem::DMAWrite(u32 addr, u32 size)
else else
{ {
auto& memory = m_system.GetMemory(); auto& memory = m_system.GetMemory();
HandleWriteModemTransfer(memory.GetPointer(addr), size); HandleWriteModemTransfer(memory.GetPointerForRange(addr, size), size);
} }
} }
@ -195,7 +195,7 @@ void CEXIModem::DMARead(u32 addr, u32 size)
else else
{ {
auto& memory = m_system.GetMemory(); auto& memory = m_system.GetMemory();
HandleReadModemTransfer(memory.GetPointer(addr), size); HandleReadModemTransfer(memory.GetPointerForRange(addr, size), size);
} }
} }

View File

@ -90,24 +90,18 @@ void GPFifoManager::UpdateGatherPipe()
size_t pipe_count = GetGatherPipeCount(); size_t pipe_count = GetGatherPipeCount();
size_t processed; size_t processed;
u8* cur_mem = memory.GetPointer(processor_interface.m_fifo_cpu_write_pointer);
for (processed = 0; pipe_count >= GATHER_PIPE_SIZE; processed += GATHER_PIPE_SIZE) for (processed = 0; pipe_count >= GATHER_PIPE_SIZE; processed += GATHER_PIPE_SIZE)
{ {
// copy the GatherPipe // copy the GatherPipe
memcpy(cur_mem, m_gather_pipe + processed, GATHER_PIPE_SIZE); memory.CopyToEmu(processor_interface.m_fifo_cpu_write_pointer, m_gather_pipe + processed,
GATHER_PIPE_SIZE);
pipe_count -= GATHER_PIPE_SIZE; pipe_count -= GATHER_PIPE_SIZE;
// increase the CPUWritePointer // increase the CPUWritePointer
if (processor_interface.m_fifo_cpu_write_pointer == processor_interface.m_fifo_cpu_end) if (processor_interface.m_fifo_cpu_write_pointer == processor_interface.m_fifo_cpu_end)
{
processor_interface.m_fifo_cpu_write_pointer = processor_interface.m_fifo_cpu_base; processor_interface.m_fifo_cpu_write_pointer = processor_interface.m_fifo_cpu_base;
cur_mem = memory.GetPointer(processor_interface.m_fifo_cpu_write_pointer);
}
else else
{
cur_mem += GATHER_PIPE_SIZE;
processor_interface.m_fifo_cpu_write_pointer += GATHER_PIPE_SIZE; processor_interface.m_fifo_cpu_write_pointer += GATHER_PIPE_SIZE;
}
system.GetCommandProcessor().GatherPipeBursted(); system.GetCommandProcessor().GatherPipeBursted();
} }

View File

@ -462,18 +462,28 @@ void MemoryManager::Memset(u32 address, u8 value, size_t size)
std::string MemoryManager::GetString(u32 em_address, size_t size) std::string MemoryManager::GetString(u32 em_address, size_t size)
{ {
const char* ptr = reinterpret_cast<const char*>(GetPointer(em_address)); std::string result;
if (ptr == nullptr)
return "";
if (size == 0) // Null terminated string. if (size == 0) // Null terminated string.
{ {
return std::string(ptr); while (true)
{
const u8 value = Read_U8(em_address);
if (value == 0)
break;
result.push_back(value);
++em_address;
}
return result;
} }
else // Fixed size string, potentially null terminated or null padded. else // Fixed size string, potentially null terminated or null padded.
{ {
size_t length = strnlen(ptr, size); result.resize(size);
return std::string(ptr, length); CopyFromEmu(result.data(), em_address, size);
size_t length = strnlen(result.data(), size);
result.resize(length);
return result;
} }
} }

View File

@ -831,7 +831,7 @@ static void ReadMemory(const Core::CPUThreadGuard& guard)
auto& system = Core::System::GetInstance(); auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory(); auto& memory = system.GetMemory();
u8* data = memory.GetPointer(addr); u8* data = memory.GetPointerForRange(addr, len);
Mem2hex(reply, data, len); Mem2hex(reply, data, len);
reply[len * 2] = '\0'; reply[len * 2] = '\0';
SendReply((char*)reply); SendReply((char*)reply);
@ -858,7 +858,7 @@ static void WriteMemory(const Core::CPUThreadGuard& guard)
auto& system = Core::System::GetInstance(); auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory(); auto& memory = system.GetMemory();
u8* dst = memory.GetPointer(addr); u8* dst = memory.GetPointerForRange(addr, len);
Hex2mem(dst, s_cmd_bfr + i + 1, len); Hex2mem(dst, s_cmd_bfr + i + 1, len);
SendReply("OK"); SendReply("OK");
} }

View File

@ -1044,18 +1044,11 @@ void MMU::DMA_LCToMemory(const u32 mem_address, const u32 cache_address, const u
} }
const u8* src = m_memory.GetL1Cache() + (cache_address & 0x3FFFF); const u8* src = m_memory.GetL1Cache() + (cache_address & 0x3FFFF);
u8* dst = m_memory.GetPointer(mem_address); m_memory.CopyToEmu(mem_address, src, 32 * num_blocks);
if (dst == nullptr)
return;
memcpy(dst, src, 32 * num_blocks);
} }
void MMU::DMA_MemoryToLC(const u32 cache_address, const u32 mem_address, const u32 num_blocks) void MMU::DMA_MemoryToLC(const u32 cache_address, const u32 mem_address, const u32 num_blocks)
{ {
const u8* src = m_memory.GetPointer(mem_address);
u8* dst = m_memory.GetL1Cache() + (cache_address & 0x3FFFF);
// No known game uses this; here for completeness. // No known game uses this; here for completeness.
// TODO: Refactor. // TODO: Refactor.
if ((mem_address & 0x0F000000) == 0x08000000) if ((mem_address & 0x0F000000) == 0x08000000)
@ -1081,10 +1074,8 @@ void MMU::DMA_MemoryToLC(const u32 cache_address, const u32 mem_address, const u
return; return;
} }
if (src == nullptr) u8* dst = m_memory.GetL1Cache() + (cache_address & 0x3FFFF);
return; m_memory.CopyFromEmu(dst, mem_address, 32 * num_blocks);
memcpy(dst, src, 32 * num_blocks);
} }
static bool TranslateBatAddress(const BatTable& bat_table, u32* address, bool* wi) static bool TranslateBatAddress(const BatTable& bat_table, u32* address, bool* wi)