Feature/runtime ecosystem refactor (#107)

* feat: remove memory and pad from stub section

* feat: add support for resume entry targets in CodeGenerator (this allow jumps in address outside function)
feat: refactor entry point discovery one more try to reduce big generated file

* feat: optmizations for release build

* feat: remove unused  file

* feat: added some test cases for code gen

* feat: added log macro and remove win specific code

* feat: refactor runtime folder structure
feat: added reset sound driver RPC state and compatibility layout
feat: rename and added new test
feat: update RPC calls to use defined constants
feat: added more PSMC(16, 32)
feat: change cd read to try find the asset ignoring case sensitive
fix: fix some render problems
feat: add logs on pad
feat: added more RPC handles

* feat: added game override for code veronica

* feat: apply vita patch

* feat: flags to disable build

* feat: fix merges
feat: break a lot of tests

* feat: better throw error on empty cd path
feat: remove recompiler unusde function
feat: apply missing patch

* feat: gamedp is now part of lib
feat: missing file

* feat: small cleanup

* feat: missing vita changes

* feat: fix more merge

* feat: fix tests

* feat: last missing feature

* feat: added missing import

* feat: rename test local functions

* feat: init syscall on ps2 list

* feat: added DMA helpers

* feat: faster builds
feat: more implement for darkcloud

* feat: back missing file

* feat: added missing includes

* feat: remove test

* feat: missing include

* feat: read register funtion

* feat: build  fix

* feat: force  exit on detach thread
This commit is contained in:
Ranieri
2026-04-04 23:09:56 -03:00
committed by GitHub
parent 553a9027d8
commit 93e221feaa
137 changed files with 26594 additions and 15314 deletions
+51 -19
View File
@@ -1,4 +1,6 @@
#include "ps2_memory.h"
#include "runtime/ps2_memory.h"
#include "ps2_log.h"
#include <atomic>
#include <iostream>
#include <cstring>
#include <stdexcept>
@@ -167,6 +169,10 @@ bool PS2Memory::initialize(size_t ramSize)
m_gsWriteCount.store(0, std::memory_order_relaxed);
m_vifWriteCount.store(0, std::memory_order_relaxed);
m_codeRegions.clear();
m_path3Masked = false;
m_path3MaskedFifo.clear();
m_vif1PendingPath2ImageQwc = 0u;
m_vif1PendingPath2DirectHl = false;
try
{
@@ -195,6 +201,8 @@ bool PS2Memory::initialize(size_t ramSize)
memset(&gs_regs, 0, sizeof(gs_regs));
gs_regs.dispfb1 = (0ULL << 0) | (10ULL << 9) | (0ULL << 15) | (0ULL << 32) | (0ULL << 43);
gs_regs.display1 = (0ULL << 0) | (0ULL << 12) | (0ULL << 23) | (0ULL << 27) | (639ULL << 32) | (447ULL << 44);
gs_regs.dispfb2 = gs_regs.dispfb1;
gs_regs.display2 = gs_regs.display1;
// Allocate GS VRAM (4MB)
m_gsVRAM = new uint8_t[PS2_GS_VRAM_SIZE];
@@ -702,17 +710,13 @@ bool PS2Memory::writeIORegister(uint32_t address, uint32_t value)
{
if (address == 0x10002010)
{
m_ioRegisters[address] = value & ~(1u << 31);
if (value & (1u << 30))
{
m_ioRegisters[0x10002000] = 0;
m_ioRegisters[0x10002010] = 0;
m_ioRegisters[0x10002020] = 0;
m_ioRegisters[0x10002030] = 0;
}
else
{
m_ioRegisters[address] = value & ~(1u << 31);
}
}
else
{
@@ -747,10 +751,12 @@ bool PS2Memory::writeIORegister(uint32_t address, uint32_t value)
switch (address)
{
case 0x10003C10u: // VIF1_FBRST
case 0x10003C10u: // VIF1_FBRST
if (value & 0x1u) // RST
{
std::memset(&vif1_regs, 0, sizeof(vif1_regs));
m_vif1PendingPath2ImageQwc = 0u;
m_vif1PendingPath2DirectHl = false;
}
if (value & 0x8u) // STC
{
@@ -862,15 +868,8 @@ bool PS2Memory::writeIORegister(uint32_t address, uint32_t value)
const uint64_t bytes64 = static_cast<uint64_t>(qwCount) * 16ull;
uint32_t bytes = (bytes64 > 0xFFFFFFFFull) ? 0xFFFFFFFFu : static_cast<uint32_t>(bytes64);
const bool scratch = isScratchpad(srcAddr);
uint32_t src = 0;
try
{
src = translateAddress(srcAddr);
}
catch (...)
{
return;
}
uint32_t src = 0;
src = translateAddress(srcAddr);
const uint8_t *base2;
uint32_t maxSz2;
if (scratch)
@@ -892,10 +891,27 @@ bool PS2Memory::writeIORegister(uint32_t address, uint32_t value)
chainBuf.insert(chainBuf.end(), base2 + src, base2 + src + bytes);
};
auto appendCompactVif1TagData = [&](uint32_t localTagAddr, uint32_t qwCount)
{
uint32_t tagPhys = 0u;
const bool tagScratch = isScratchpad(localTagAddr);
tagPhys = translateAddress(localTagAddr);
const uint8_t *localBase = tagScratch ? m_scratchpad : m_rdram;
const uint32_t localMax = tagScratch ? PS2_SCRATCHPAD_SIZE : PS2_RAM_SIZE;
if (tagPhys + 16u > localMax)
return;
// VIF1 packet helpers embed 8 bytes of VIF stream in the DMAtag's upper half.
chainBuf.insert(chainBuf.end(), localBase + tagPhys + 8u, localBase + tagPhys + 16u);
appendData(localTagAddr + 16u, qwCount);
};
int tagsProcessed = 0;
while (tagsProcessed < kMaxChainTags)
{
const uint32_t currentTagAddr = tagAddr;
const bool tagInSPR = isScratchpad(tagAddr);
uint32_t physTag = 0;
try
@@ -998,7 +1014,15 @@ bool PS2Memory::writeIORegister(uint32_t address, uint32_t value)
}
if (hasPayload)
appendData(dataAddr, tagQwc);
{
const bool compactVif1LocalPayload =
(channelBase == 0x10009000u) &&
(id == 1u || id == 2u || id == 5u || id == 6u || id == 7u);
if (compactVif1LocalPayload)
appendCompactVif1TagData(currentTagAddr, tagQwc);
else
appendData(dataAddr, tagQwc);
}
if (irq && tieEnabled)
endChain = true;
if (endChain)
@@ -1019,10 +1043,18 @@ bool PS2Memory::writeIORegister(uint32_t address, uint32_t value)
pt.qwc = 0;
pt.chainData = std::move(chainBuf);
if (channelBase == 0x1000A000)
{
m_pendingGifTransfers.push_back(std::move(pt));
}
else if (channelBase == 0x10009000)
{
m_pendingVif1Transfers.push_back(std::move(pt));
}
}
// else if (channelBase == 0x10009000u)
// {
// }
}
else if (qwc > 0)
{
@@ -1367,7 +1399,7 @@ void PS2Memory::registerCodeRegion(uint32_t start, uint32_t end)
region.modified.resize(sizeInWords, false);
m_codeRegions.push_back(region);
std::cout << "Registered code region: " << std::hex << start << " - " << end << std::dec << std::endl;
RUNTIME_LOG("Registered code region: " << std::hex << start << " - " << end << std::dec);
}
bool PS2Memory::isAddressInRegion(uint32_t address, const CodeRegion &region)
@@ -1413,7 +1445,7 @@ void PS2Memory::markModified(uint32_t address, uint32_t size)
if (bitIndex < region.modified.size())
{
region.modified[bitIndex] = true;
std::cout << "Marked code at " << std::hex << addr << std::dec << " as modified" << std::endl;
RUNTIME_LOG("Marked code at " << std::hex << addr << std::dec << " as modified");
}
}
}