Skip to content

Commit

Permalink
Merge pull request #1475 from nicolasnoble/pcdrv-fixes
Browse files Browse the repository at this point in the history
Various pcdrv fixes
  • Loading branch information
nicolasnoble authored Nov 28, 2023
2 parents 51804c5 + 837ac3d commit 4cd6149
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 22 deletions.
8 changes: 1 addition & 7 deletions src/core/psxinterpreter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1613,14 +1613,8 @@ inline void InterpretedCPU::execBlock() {
(*this.*func)(code);

m_currentDelayedLoad ^= 1;
flushCurrentDelayedLoad();
auto &delayedLoad = m_delayedLoadInfo[m_currentDelayedLoad];
if (delayedLoad.active) {
uint32_t reg = m_regs.GPR.r[delayedLoad.index];
reg &= delayedLoad.mask;
reg |= delayedLoad.value;
m_regs.GPR.r[delayedLoad.index] = reg;
delayedLoad.active = false;
}
bool fromLink = false;
if (delayedLoad.pcActive) {
m_regs.pc = delayedLoad.pcValue;
Expand Down
40 changes: 29 additions & 11 deletions src/core/r3000a.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ void PCSX::R3000Acpu::exception(uint32_t code, bool bd, bool cop0) {
uint32_t code = (memFile->readAt<uint32_t>(m_regs.pc) >> 6) & 0xfffff;
auto& regs = m_regs.GPR.n;
uint16_t fd = 0;
m_currentDelayedLoad ^= 1;
flushCurrentDelayedLoad();
m_currentDelayedLoad ^= 1;
flushCurrentDelayedLoad();
switch (code) {
case 0x101: { // PCinit
closeAllPCdrvFiles();
Expand Down Expand Up @@ -161,6 +165,7 @@ void PCSX::R3000Acpu::exception(uint32_t code, bool bd, bool cop0) {
regs.v0 = -1;
regs.v1 = -1;
} else {
(*file)->close();
regs.v0 = 0;
regs.v1 = 0;
delete &*file;
Expand All @@ -170,36 +175,38 @@ void PCSX::R3000Acpu::exception(uint32_t code, bool bd, bool cop0) {
return;
}
case 0x105: { // PCread
auto file = m_pcdrvFiles.find(m_regs.GPR.n.a1);
if (file == m_pcdrvFiles.end()) {
auto filei = m_pcdrvFiles.find(m_regs.GPR.n.a1);
if (filei == m_pcdrvFiles.end()) {
regs.v0 = -1;
regs.v1 = -1;
m_regs.pc += 4;
return;
}
if ((*file)->failed() || (*file)->eof()) {
IO<File> file = *filei;
if (file->failed() || file->eof()) {
regs.v0 = -1;
regs.v1 = -1;
m_regs.pc += 4;
return;
}
auto slice = (*file)->read(regs.a2);
auto slice = file->read(regs.a2);
regs.v0 = 0;
regs.v1 = slice.size();
memFile->writeAt(std::move(slice), regs.a3);
m_regs.pc += 4;
return;
}
case 0x106: { // PCwrite
auto file = m_pcdrvFiles.find(m_regs.GPR.n.a1);
if (file == m_pcdrvFiles.end()) {
auto filei = m_pcdrvFiles.find(m_regs.GPR.n.a1);
if (filei == m_pcdrvFiles.end()) {
regs.v0 = -1;
regs.v1 = -1;
m_regs.pc += 4;
return;
}
IO<File> file = *filei;
auto slice = memFile->readAt(regs.a2, regs.a3);
if ((regs.v1 = (*file)->write(slice.data(), slice.size())) < 0) {
if ((regs.v1 = file->write(slice.data(), slice.size())) < 0) {
regs.v0 = -1;
} else {
regs.v0 = 0;
Expand All @@ -208,13 +215,14 @@ void PCSX::R3000Acpu::exception(uint32_t code, bool bd, bool cop0) {
return;
}
case 0x107: { // PClseek
auto file = m_pcdrvFiles.find(m_regs.GPR.n.a0);
if (file == m_pcdrvFiles.end()) {
auto filei = m_pcdrvFiles.find(m_regs.GPR.n.a0);
if (filei == m_pcdrvFiles.end()) {
regs.v0 = -1;
regs.v1 = -1;
m_regs.pc += 4;
return;
}
IO<File> file = *filei;
int wheel;
switch (regs.a3) {
case 0:
Expand All @@ -232,10 +240,20 @@ void PCSX::R3000Acpu::exception(uint32_t code, bool bd, bool cop0) {
m_regs.pc += 4;
return;
}
auto ret = (*file)->writable() ? (*file)->wSeek(regs.a2, wheel) : (*file)->rSeek(regs.a2, wheel);
ssize_t ret = file->rSeek(regs.a2, wheel);
if (ret < 0) {
regs.v0 = -1;
regs.v1 = ret;
m_regs.pc += 4;
return;
}
if (file->writable()) {
file->wSeek(regs.a2, wheel);
}

if (ret >= 0) {
regs.v0 = 0;
regs.v1 = (*file)->writable() ? (*file)->wTell() : (*file)->rTell();
regs.v1 = file->rTell();
} else {
regs.v0 = -1;
regs.v1 = ret;
Expand Down
20 changes: 16 additions & 4 deletions src/core/r3000a.h
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,16 @@ class R3000Acpu {
delayedLoad.pcValue = value;
delayedLoad.fromLink = fromLink;
}
void flushCurrentDelayedLoad() {
auto &delayedLoad = m_delayedLoadInfo[m_currentDelayedLoad];
if (delayedLoad.active) {
uint32_t reg = m_regs.GPR.r[delayedLoad.index];
reg &= delayedLoad.mask;
reg |= delayedLoad.value;
m_regs.GPR.r[delayedLoad.index] = reg;
delayedLoad.active = false;
}
}

protected:
R3000Acpu(const std::string &name) : m_name(name) {}
Expand Down Expand Up @@ -456,8 +466,8 @@ Formula One 2001
uint32_t pcOffset = pc & 0xffffff;
uint32_t pcCache = pc & 0xfff;

uint8_t * iAddr = m_regs.iCacheAddr;
uint8_t * iCode = m_regs.iCacheCode;
uint8_t *iAddr = m_regs.iCacheAddr;
uint8_t *iCode = m_regs.iCacheCode;

// cached - RAM
if (pcBank == 0x00 || pcBank == 0x80) {
Expand Down Expand Up @@ -504,8 +514,10 @@ Formula One 2001
PCdrvFile(const std::filesystem::path &filename) : IO<File>(new PosixFile(filename)) {}
PCdrvFile(const std::filesystem::path &filename, FileOps::ReadWrite)
: IO<File>(new PosixFile(filename, FileOps::READWRITE)) {}
PCdrvFile(const std::filesystem::path &filename, FileOps::Truncate) : IO<File>(new PosixFile(filename, FileOps::TRUNCATE)) {}
PCdrvFile(const std::filesystem::path &filename, FileOps::Create) : IO<File>(new PosixFile(filename, FileOps::CREATE)) {}
PCdrvFile(const std::filesystem::path &filename, FileOps::Truncate)
: IO<File>(new PosixFile(filename, FileOps::TRUNCATE)) {}
PCdrvFile(const std::filesystem::path &filename, FileOps::Create)
: IO<File>(new PosixFile(filename, FileOps::CREATE)) {}
virtual ~PCdrvFile() = default;
std::string m_relativeFilename;
};
Expand Down

0 comments on commit 4cd6149

Please sign in to comment.